Commit 7389a43
committed
refactor(template-builder): encapsulate interact.js inside ElementRenderer
Each component now owns exactly its own responsibilities:
ElementRenderer
- Imports interact.js and sets up its own interactable in did-insert
- Tears it down in will-destroy (no parent involvement)
- Emits @onmove(uuid, {x,y}) when a drag ends
- Emits @onresize(uuid, {x,y,width,height}) when a resize ends
- Emits @onselect(element) when tapped
- Reads @canvasWidth/@canvasHeight for boundary clamping
- Reads @zoom at event time (no closure staleness)
- Reads rotation from el.dataset.rotation (written by _applyTransform)
so the applyTransform closure never holds a stale element reference
Canvas
- Removed: interact.js import, _interactables map, setupElement,
teardownElement, _setupInteract, didInsertCanvas, willDestroyCanvas
- Owns only: canvas dimensions/style, selectedUuid tracking,
handleSelectElement, handleDeselectAll
- Passes @canvasWidth/@canvasHeight/@zoom to each ElementRenderer
- Forwards @onMoveElement → @onmove, @onResizeElement → @onresize
TemplateBuilder
- Added resizeElement action (separate from moveElement)
- moveElement: drag-end only, syncs {x,y}
- resizeElement: resize-end only, syncs {x,y,width,height}
- Both are silent in-place mutations (no re-render, no undo entry)
- Removed @onUpdateElement from canvas wiring (canvas never needed it)
This eliminates the entire class of bugs caused by the parent managing
child DOM lifecycle: no more interact.js destruction on property updates,
no stale closure references, no need for data-attribute workarounds.1 parent 446ca53 commit 7389a43
File tree
6 files changed
+271
-404
lines changed- addon/components
- template-builder
6 files changed
+271
-404
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
262 | | - | |
263 | | - | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
264 | 266 | | |
265 | 267 | | |
266 | | - | |
| 268 | + | |
267 | 269 | | |
268 | 270 | | |
269 | | - | |
270 | | - | |
271 | | - | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
272 | 285 | | |
273 | 286 | | |
274 | 287 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
2 | 4 | | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
6 | | - | |
7 | | - | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | 11 | | |
18 | 12 | | |
19 | 13 | | |
20 | 14 | | |
21 | | - | |
22 | 15 | | |
23 | | - | |
24 | | - | |
25 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
26 | 21 | | |
27 | 22 | | |
28 | 23 | | |
0 commit comments