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.auto.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
  */
@@ -4521,6 +4521,79 @@
4521
4521
  return scopeVersionMap.get(target);
4522
4522
  }
4523
4523
 
4524
+ /** Keep the longest already-ordered run of rows connected; move only the rest. */
4525
+ function placeKeyedRows(placeholder, rows) {
4526
+ const parent = placeholder.parentNode;
4527
+ if (!parent || rows.length === 0)
4528
+ return;
4529
+ const managed = new Set(rows);
4530
+ const positions = new Map();
4531
+ let boundary = placeholder.nextSibling;
4532
+ while (boundary && managed.has(boundary)) {
4533
+ positions.set(boundary, positions.size);
4534
+ boundary = boundary.nextSibling;
4535
+ }
4536
+ const active = placeholder.ownerDocument.activeElement;
4537
+ const ownsFocus = !!active && rows.some((row) => row === active || row.contains(active));
4538
+ const selection = ownsFocus && (active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement)
4539
+ ? { start: active.selectionStart, end: active.selectionEnd, direction: active.selectionDirection }
4540
+ : null;
4541
+ if (positions.size !== rows.length) {
4542
+ // Leaving transition nodes, foreign siblings or externally detached rows:
4543
+ // preserve the established contiguous-after-placeholder placement contract.
4544
+ let previous = placeholder;
4545
+ for (const row of rows) {
4546
+ if (row !== previous.nextSibling)
4547
+ parent.insertBefore(row, previous.nextSibling);
4548
+ previous = row;
4549
+ }
4550
+ }
4551
+ else {
4552
+ const order = rows.map((row) => positions.get(row));
4553
+ let sorted = true;
4554
+ for (let i = 1; i < order.length; i++)
4555
+ if (order[i] < order[i - 1]) {
4556
+ sorted = false;
4557
+ break;
4558
+ }
4559
+ if (sorted)
4560
+ return;
4561
+ // Patience sorting: indices of a longest increasing subsequence, O(n log n).
4562
+ const tails = [], predecessors = new Array(order.length).fill(-1);
4563
+ for (let i = 0; i < order.length; i++) {
4564
+ let low = 0, high = tails.length;
4565
+ while (low < high) {
4566
+ const middle = (low + high) >>> 1;
4567
+ if (order[tails[middle]] < order[i])
4568
+ low = middle + 1;
4569
+ else
4570
+ high = middle;
4571
+ }
4572
+ if (low > 0)
4573
+ predecessors[i] = tails[low - 1];
4574
+ tails[low] = i;
4575
+ }
4576
+ const retained = new Set();
4577
+ for (let i = tails[tails.length - 1]; i >= 0; i = predecessors[i])
4578
+ retained.add(i);
4579
+ for (let i = rows.length - 1; i >= 0; i--) {
4580
+ const row = rows[i];
4581
+ if (!retained.has(i) && row.nextSibling !== boundary)
4582
+ parent.insertBefore(row, boundary);
4583
+ boundary = row;
4584
+ }
4585
+ }
4586
+ // insertBefore can blur a moved input. Restore only a surviving owned focus,
4587
+ // and never steal focus assigned to another control by application callbacks.
4588
+ const document = placeholder.ownerDocument;
4589
+ if (ownsFocus && active.isConnected && document.activeElement === document.body) {
4590
+ active.focus({ preventScroll: true });
4591
+ if (selection?.start != null && selection.end != null) {
4592
+ active.setSelectionRange(selection.start, selection.end, selection.direction || undefined);
4593
+ }
4594
+ }
4595
+ }
4596
+
4524
4597
  /**
4525
4598
  * Structural Directives (*if, *for)
4526
4599
  * Single-pass parser for conditional and list rendering with transitions
@@ -4701,6 +4774,7 @@
4701
4774
  });
4702
4775
  // Add/reorder items immediately (parallel with remove animations)
4703
4776
  let lastPlacedNode = placeholder;
4777
+ const rows = [];
4704
4778
  orderedKeys.forEach((key) => {
4705
4779
  const newItemData = newItemsMap.get(key);
4706
4780
  const { index } = newItemData;
@@ -4752,13 +4826,10 @@
4752
4826
  });
4753
4827
  }
4754
4828
  }
4755
- // Place each managed row directly after the previous row. This does not
4756
- // depend on formatting whitespace or unrelated sibling nodes.
4757
- if (itemElement !== lastPlacedNode.nextSibling) {
4758
- placeholder.parentNode?.insertBefore(itemElement, lastPlacedNode.nextSibling);
4759
- }
4829
+ rows.push(itemElement);
4760
4830
  lastPlacedNode = itemElement;
4761
4831
  });
4832
+ placeKeyedRows(placeholder, rows);
4762
4833
  }
4763
4834
  /**
4764
4835
  * Process *for without keys (simple re-render)
@@ -8860,7 +8931,7 @@
8860
8931
  portalCreate,
8861
8932
  portalDestroy,
8862
8933
  setCspNonce,
8863
- version: '0.5.0'
8934
+ version: '0.5.1'
8864
8935
  };
8865
8936
 
8866
8937
  const standardExpressionRuntime = {