You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor: extract managers from GridLayout god object
Split the 1387-line GridLayout class into a coordinator (~526 lines)
plus three focused manager classes:
- BackgroundManager: background image lifecycle, template evaluation
- OverlayManager: overlay DOM, state-driven activation, tester panel
- SectionConfigManager: section CRUD, YAML editor modal
Also extracted static CSS to grid-styles.ts (~451 lines), added shared
constants.ts for CSS class names/IDs, removed 8 pass-through wrapper
methods, and added 56 new manager tests (215 total, up from 159).
`GridLayout` extends `LitElement` directly (no base class).
86
+
`GridLayout` extends `LitElement` directly (no base class). It coordinates three managers that own distinct subsystems.
75
87
76
-
### `grid.ts`
88
+
### `grid.ts` (coordinator)
77
89
-**CSS Grid rendering**: Applies `grid-template-areas/columns/rows` from `layout` config
78
-
-**Section management**: Creates/destroys `hui-section` wrappers; maintains `_sectionsCache`; auto-saves new sections to lovelace config
79
-
-**Jinja template evaluation**: Calls pure functions from `template.ts` for `{{ states() }}`, `{{ state_attr() }}`, `{% if %}` in `custom_css`; tracks entities in `_trackedEntities`; debounced via `requestAnimationFrame`
80
-
-**Background images**: Fixed positioning, blur, opacity, template support
81
-
-**Kiosk mode**: `layout.kiosk: true` makes `#root` fixed-position, filling viewport below HA header; edit-mode offset adjusts for tab bar
-**Edit mode UI**: Section labels with grid-area name; loose-cards container
85
96
-**`_updateSectionsLovelace()`**: Pushes fresh `lovelace` AND fresh `config` to each `hui-section`
86
97
98
+
### `grid-styles.ts`
99
+
Static CSS for the component (~450 lines). Includes section containers, YAML editor modal, overlay animations, and overlay tester panel styling.
100
+
101
+
### Managers
102
+
-**`BackgroundManager`**: Owns background image lifecycle — creates a fixed-position div on `document.body`, handles template evaluation for dynamic URLs, manages blur/opacity. State: `_lastBackgroundImage`, `_bgElementId`.
103
+
-**`OverlayManager`**: Owns overlay DOM elements, state-driven activation/deactivation, animation triggering, and the edit-mode test panel. State: `_overlayStates`, `_dialogObserver`.
104
+
-**`SectionConfigManager`**: Owns section config CRUD (create/update/delete sections in lovelace config), auto-creation of missing sections for grid areas, and the YAML editor modal. State: `_savingConfig`.
105
+
87
106
### Extracted utility modules (pure functions, testable without DOM)
-**`constants.ts`**: Shared CSS class names, element IDs, data attributes, and selectors
92
112
93
113
### `patches/hui-view-editor.ts`
94
114
Adds `sections-grid-layout` to the view type dropdown. Guard flag `_sectionsGridLayoutPatched` prevents double-patching when layout-card is also loaded.
@@ -101,11 +121,13 @@ Preserves `view_layout` when the card element editor saves changes.
101
121
## Code Conventions
102
122
103
123
- Private methods/props: `_` prefix
104
-
- Constants: `UPPER_SNAKE_CASE`
124
+
- Constants: `UPPER_SNAKE_CASE` (in `constants.ts`)
105
125
-`@property()` for external props, `@state()` for internal state
106
126
- Clean up observers in `disconnectedCallback()`
107
127
- Debounce heavy ops with `requestAnimationFrame`
108
128
- Lit 3 only
129
+
- Manager classes are instantiated in `firstUpdated()` and cleaned up in `disconnectedCallback()`
130
+
- CSS class names used in JS should reference constants from `constants.ts`
109
131
110
132
---
111
133
@@ -124,11 +146,16 @@ Preserves `view_layout` when the card element editor saves changes.
0 commit comments