Skip to content

Commit d2689b4

Browse files
committed
docs: Enhance JSDoc for atomic moves and focus preservation (#8615)
1 parent b47b9d5 commit d2689b4

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/container/Base.mjs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,19 @@ class Container extends Component {
618618
}
619619

620620
/**
621-
* Inserts an item or array of items at a specific index
621+
* Inserts an item or array of items at a specific index.
622+
*
623+
* **Atomic Moves:**
624+
* If the `item` is an existing `Neo.component.Base` instance that already has a parent container
625+
* within the same browser window, this method performs an **atomic move**.
626+
* 1. The item is silently removed from its old parent (without triggering a DOM removal).
627+
* 2. The item is inserted into this container.
628+
* 3. This container updates, sending an `insertNode` delta.
629+
* 4. The `DeltaUpdates` system detects the existing DOM node and moves it physically, preserving
630+
* DOM state such as focus, input values, and iframe content.
631+
*
622632
* @param {Number} index
623-
* @param {Array|Object} item
633+
* @param {Array|Object|Neo.component.Base} item
624634
* @param {Boolean} [silent=false]
625635
* @param {Boolean} [removeFromPreviousParent=true]
626636
* @returns {Neo.component.Base|Neo.component.Base[]}

src/main/DeltaUpdates.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,11 @@ class DeltaUpdates extends Base {
430430
* It performs a direct sibling swap when an element is immediately followed by its target position,
431431
* which is necessary to prevent attempting to replace a node with itself.
432432
*
433+
* **Focus Preservation:**
434+
* In WebKit/Blink browsers (Chrome, Safari), reparenting a focused element causes it to lose focus.
435+
* This method detects if the moved node contains the active element and automatically restores focus
436+
* immediately after the move operation to ensure a seamless user experience.
437+
*
433438
* @param {Object} delta
434439
* @param {String} delta.id The ID of the DOM node to move.
435440
* @param {Number} delta.index The physical index at which to insert the node within the target parent's childNodes.

src/worker/App.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,10 @@ class App extends Base {
500500

501501
/**
502502
* Moves a component to a new parent container via remote method access.
503+
* This operation is **atomic** and state-preserving when moving within the same browser window.
504+
* It relies on `Neo.container.Base.insert` to handle the silent removal from the old parent,
505+
* ensuring that the DOM node is physically moved rather than destroyed and recreated.
506+
*
503507
* @param {Object} data
504508
* @param {String} data.id The id of the component to move.
505509
* @param {String} data.parentId The id of the new parent container.

0 commit comments

Comments
 (0)