Add a new config saveScrollPosition (default true) to Neo.component.Abstract.
Goal:
Automatically preserve the scroll position of a component's DOM nodes when they are unmounted and re-mounted (e.g., in Card layout or when moving components between windows).
Implementation Details:
This feature was implemented by treating scrollTop and scrollLeft as top-level properties of the VNode structure, elevating them to first-class citizens alongside id and childNodes. This architectural choice provides cleaner access and semantic correctness (they are DOM properties, not HTML attributes).
Changes:
- Architecture: Adopted a top-level property approach for scroll state on VNode objects.
src/vdom/VNode.mjs: Enhanced constructor to accept and document top-level scrollTop and scrollLeft properties.
src/vdom/Helper.mjs:
- Updated
createVnode to pass these properties through to the VNode instance.
- Updated
compareAttributes to detect changes in these top-level properties and include them in the delta updates.
src/main/DeltaUpdates.mjs: Updated updateNode to handle these new delta keys by applying them directly to the DOM node properties (e.g., node.scrollTop = value).
src/component/Abstract.mjs:
- Added
saveScrollPosition config (default true).
- Added
onScrollCapture method to update the persistent vnode state (in App worker) without triggering re-renders.
src/component/Base.mjs: Overridden onScrollCapture to also keep the persistent _vdom structure in sync for class-based components.
src/functional/component/Base.mjs: Overridden syncVdomIds to hydrate the ephemeral vdom with scrollTop and scrollLeft values from the persistent vnode state during functional component re-renders.
src/manager/DomEvent.mjs: Enhanced fire() to intercept scroll events and trigger onScrollCapture on the target component before processing standard listeners.
Note:
Current implementation handles live DOM updates (capturing scroll) and VDOM/VNode synchronization. However, re-mounting (restoring scroll position on node insertion) is NOT yet handled. This is a follow-up item that requires updates to specific renderers/mount adapters to ensure nodes are created/inserted with the correct scroll properties.
Add a new config
saveScrollPosition(defaulttrue) toNeo.component.Abstract.Goal: Automatically preserve the scroll position of a component's DOM nodes when they are unmounted and re-mounted (e.g., in
Cardlayout or when moving components between windows).Implementation Details:
This feature was implemented by treating
scrollTopandscrollLeftas top-level properties of the VNode structure, elevating them to first-class citizens alongsideidandchildNodes. This architectural choice provides cleaner access and semantic correctness (they are DOM properties, not HTML attributes).Changes:
src/vdom/VNode.mjs: Enhanced constructor to accept and document top-levelscrollTopandscrollLeftproperties.src/vdom/Helper.mjs:createVnodeto pass these properties through to the VNode instance.compareAttributesto detect changes in these top-level properties and include them in the delta updates.src/main/DeltaUpdates.mjs: UpdatedupdateNodeto handle these new delta keys by applying them directly to the DOM node properties (e.g.,node.scrollTop = value).src/component/Abstract.mjs:saveScrollPositionconfig (defaulttrue).onScrollCapturemethod to update the persistentvnodestate (in App worker) without triggering re-renders.src/component/Base.mjs: OverriddenonScrollCaptureto also keep the persistent_vdomstructure in sync for class-based components.src/functional/component/Base.mjs: OverriddensyncVdomIdsto hydrate the ephemeralvdomwithscrollTopandscrollLeftvalues from the persistentvnodestate during functional component re-renders.src/manager/DomEvent.mjs: Enhancedfire()to interceptscrollevents and triggeronScrollCaptureon the target component before processing standard listeners.Note: Current implementation handles live DOM updates (capturing scroll) and VDOM/VNode synchronization. However, re-mounting (restoring scroll position on node insertion) is NOT yet handled. This is a follow-up item that requires updates to specific renderers/mount adapters to ensure nodes are created/inserted with the correct scroll properties.