gyosjs 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/gyos.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * GyosJS v0.5.0
2
+ * GyosJS v0.5.1
3
3
  * (c) 2026
4
4
  * @license MIT
5
5
  */
@@ -4547,6 +4547,79 @@ function getScopeVersion(target) {
4547
4547
  return scopeVersionMap.get(target);
4548
4548
  }
4549
4549
 
4550
+ /** Keep the longest already-ordered run of rows connected; move only the rest. */
4551
+ function placeKeyedRows(placeholder, rows) {
4552
+ const parent = placeholder.parentNode;
4553
+ if (!parent || rows.length === 0)
4554
+ return;
4555
+ const managed = new Set(rows);
4556
+ const positions = new Map();
4557
+ let boundary = placeholder.nextSibling;
4558
+ while (boundary && managed.has(boundary)) {
4559
+ positions.set(boundary, positions.size);
4560
+ boundary = boundary.nextSibling;
4561
+ }
4562
+ const active = placeholder.ownerDocument.activeElement;
4563
+ const ownsFocus = !!active && rows.some((row) => row === active || row.contains(active));
4564
+ const selection = ownsFocus && (active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement)
4565
+ ? { start: active.selectionStart, end: active.selectionEnd, direction: active.selectionDirection }
4566
+ : null;
4567
+ if (positions.size !== rows.length) {
4568
+ // Leaving transition nodes, foreign siblings or externally detached rows:
4569
+ // preserve the established contiguous-after-placeholder placement contract.
4570
+ let previous = placeholder;
4571
+ for (const row of rows) {
4572
+ if (row !== previous.nextSibling)
4573
+ parent.insertBefore(row, previous.nextSibling);
4574
+ previous = row;
4575
+ }
4576
+ }
4577
+ else {
4578
+ const order = rows.map((row) => positions.get(row));
4579
+ let sorted = true;
4580
+ for (let i = 1; i < order.length; i++)
4581
+ if (order[i] < order[i - 1]) {
4582
+ sorted = false;
4583
+ break;
4584
+ }
4585
+ if (sorted)
4586
+ return;
4587
+ // Patience sorting: indices of a longest increasing subsequence, O(n log n).
4588
+ const tails = [], predecessors = new Array(order.length).fill(-1);
4589
+ for (let i = 0; i < order.length; i++) {
4590
+ let low = 0, high = tails.length;
4591
+ while (low < high) {
4592
+ const middle = (low + high) >>> 1;
4593
+ if (order[tails[middle]] < order[i])
4594
+ low = middle + 1;
4595
+ else
4596
+ high = middle;
4597
+ }
4598
+ if (low > 0)
4599
+ predecessors[i] = tails[low - 1];
4600
+ tails[low] = i;
4601
+ }
4602
+ const retained = new Set();
4603
+ for (let i = tails[tails.length - 1]; i >= 0; i = predecessors[i])
4604
+ retained.add(i);
4605
+ for (let i = rows.length - 1; i >= 0; i--) {
4606
+ const row = rows[i];
4607
+ if (!retained.has(i) && row.nextSibling !== boundary)
4608
+ parent.insertBefore(row, boundary);
4609
+ boundary = row;
4610
+ }
4611
+ }
4612
+ // insertBefore can blur a moved input. Restore only a surviving owned focus,
4613
+ // and never steal focus assigned to another control by application callbacks.
4614
+ const document = placeholder.ownerDocument;
4615
+ if (ownsFocus && active.isConnected && document.activeElement === document.body) {
4616
+ active.focus({ preventScroll: true });
4617
+ if (selection?.start != null && selection.end != null) {
4618
+ active.setSelectionRange(selection.start, selection.end, selection.direction || undefined);
4619
+ }
4620
+ }
4621
+ }
4622
+
4550
4623
  /**
4551
4624
  * Structural Directives (*if, *for)
4552
4625
  * Single-pass parser for conditional and list rendering with transitions
@@ -4727,6 +4800,7 @@ function processForWithKeys(placeholder, template, list, itemVar, keyExpr, curre
4727
4800
  });
4728
4801
  // Add/reorder items immediately (parallel with remove animations)
4729
4802
  let lastPlacedNode = placeholder;
4803
+ const rows = [];
4730
4804
  orderedKeys.forEach((key) => {
4731
4805
  const newItemData = newItemsMap.get(key);
4732
4806
  const { index } = newItemData;
@@ -4778,13 +4852,10 @@ function processForWithKeys(placeholder, template, list, itemVar, keyExpr, curre
4778
4852
  });
4779
4853
  }
4780
4854
  }
4781
- // Place each managed row directly after the previous row. This does not
4782
- // depend on formatting whitespace or unrelated sibling nodes.
4783
- if (itemElement !== lastPlacedNode.nextSibling) {
4784
- placeholder.parentNode?.insertBefore(itemElement, lastPlacedNode.nextSibling);
4785
- }
4855
+ rows.push(itemElement);
4786
4856
  lastPlacedNode = itemElement;
4787
4857
  });
4858
+ placeKeyedRows(placeholder, rows);
4788
4859
  }
4789
4860
  /**
4790
4861
  * Process *for without keys (simple re-render)
@@ -8886,7 +8957,7 @@ const Gyos = {
8886
8957
  portalCreate,
8887
8958
  portalDestroy,
8888
8959
  setCspNonce,
8889
- version: '0.5.0'
8960
+ version: '0.5.1'
8890
8961
  };
8891
8962
 
8892
8963
  setExpressionRuntime(standardExpressionRuntime);