Implement a robust "Manual DOM Delta" strategy to enable dragging of live components without losing state.
Problem:
Dragging components typically involves moving them in the VDOM tree, which triggers a destroy/create cycle for the underlying DOM node. This breaks stateful elements like OffscreenCanvas or Iframe that rely on a persistent DOM instance.
Solution:
DragZone: Update createDragProxy to use Neo.applyDeltas for a manual move operation.
- Instead of modifying the owner's
items config (VDOM), we manually move the component's DOM node into the DragProxy.
- We manually insert a placeholder
vnode (fetched via Neo.vdom.Helper) into the owner's DOM to maintain the layout gap.
- Configured
DragProxyContainer with parentComponent: me.owner to maintain logical linkage for event bubbling.
- Ensured
neo-draggable class is on the proxy config to support event delegation.
SortZone: Update onDragEnd to perform a manual restoration.
- Before calling
moveTo (which syncs the VDOM), we manually move the component's DOM node back to its correct visual position in the owner and remove the placeholder node.
- This ensures the VDOM update sees a DOM structure that matches its expectation, preventing a destructive reconciliation.
- Corrected
fromIndex calculation to use me.dragComponent (live reference) instead of proxy items.
- Updated
updateItem to handle the placeholder (mapped index -1) and redirect updates appropriately.
Changed Files:
src/draggable/DragZone.mjs
src/draggable/container/SortZone.mjs
Implement a robust "Manual DOM Delta" strategy to enable dragging of live components without losing state.
Problem: Dragging components typically involves moving them in the VDOM tree, which triggers a destroy/create cycle for the underlying DOM node. This breaks stateful elements like
OffscreenCanvasorIframethat rely on a persistent DOM instance.Solution:
DragZone: Update
createDragProxyto useNeo.applyDeltasfor a manual move operation.itemsconfig (VDOM), we manually move the component's DOM node into the DragProxy.vnode(fetched viaNeo.vdom.Helper) into the owner's DOM to maintain the layout gap.DragProxyContainerwithparentComponent: me.ownerto maintain logical linkage for event bubbling.neo-draggableclass is on the proxy config to support event delegation.SortZone: Update
onDragEndto perform a manual restoration.moveTo(which syncs the VDOM), we manually move the component's DOM node back to its correct visual position in the owner and remove the placeholder node.fromIndexcalculation to useme.dragComponent(live reference) instead of proxy items.updateItemto handle the placeholder (mapped index -1) and redirect updates appropriately.Changed Files:
src/draggable/DragZone.mjssrc/draggable/container/SortZone.mjs