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.
@@ -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
  */
@@ -11164,6 +11164,79 @@ function getScopeVersion(target) {
11164
11164
  return scopeVersionMap.get(target);
11165
11165
  }
11166
11166
 
11167
+ /** Keep the longest already-ordered run of rows connected; move only the rest. */
11168
+ function placeKeyedRows(placeholder, rows) {
11169
+ const parent = placeholder.parentNode;
11170
+ if (!parent || rows.length === 0)
11171
+ return;
11172
+ const managed = new Set(rows);
11173
+ const positions = new Map();
11174
+ let boundary = placeholder.nextSibling;
11175
+ while (boundary && managed.has(boundary)) {
11176
+ positions.set(boundary, positions.size);
11177
+ boundary = boundary.nextSibling;
11178
+ }
11179
+ const active = placeholder.ownerDocument.activeElement;
11180
+ const ownsFocus = !!active && rows.some((row) => row === active || row.contains(active));
11181
+ const selection = ownsFocus && (active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement)
11182
+ ? { start: active.selectionStart, end: active.selectionEnd, direction: active.selectionDirection }
11183
+ : null;
11184
+ if (positions.size !== rows.length) {
11185
+ // Leaving transition nodes, foreign siblings or externally detached rows:
11186
+ // preserve the established contiguous-after-placeholder placement contract.
11187
+ let previous = placeholder;
11188
+ for (const row of rows) {
11189
+ if (row !== previous.nextSibling)
11190
+ parent.insertBefore(row, previous.nextSibling);
11191
+ previous = row;
11192
+ }
11193
+ }
11194
+ else {
11195
+ const order = rows.map((row) => positions.get(row));
11196
+ let sorted = true;
11197
+ for (let i = 1; i < order.length; i++)
11198
+ if (order[i] < order[i - 1]) {
11199
+ sorted = false;
11200
+ break;
11201
+ }
11202
+ if (sorted)
11203
+ return;
11204
+ // Patience sorting: indices of a longest increasing subsequence, O(n log n).
11205
+ const tails = [], predecessors = new Array(order.length).fill(-1);
11206
+ for (let i = 0; i < order.length; i++) {
11207
+ let low = 0, high = tails.length;
11208
+ while (low < high) {
11209
+ const middle = (low + high) >>> 1;
11210
+ if (order[tails[middle]] < order[i])
11211
+ low = middle + 1;
11212
+ else
11213
+ high = middle;
11214
+ }
11215
+ if (low > 0)
11216
+ predecessors[i] = tails[low - 1];
11217
+ tails[low] = i;
11218
+ }
11219
+ const retained = new Set();
11220
+ for (let i = tails[tails.length - 1]; i >= 0; i = predecessors[i])
11221
+ retained.add(i);
11222
+ for (let i = rows.length - 1; i >= 0; i--) {
11223
+ const row = rows[i];
11224
+ if (!retained.has(i) && row.nextSibling !== boundary)
11225
+ parent.insertBefore(row, boundary);
11226
+ boundary = row;
11227
+ }
11228
+ }
11229
+ // insertBefore can blur a moved input. Restore only a surviving owned focus,
11230
+ // and never steal focus assigned to another control by application callbacks.
11231
+ const document = placeholder.ownerDocument;
11232
+ if (ownsFocus && active.isConnected && document.activeElement === document.body) {
11233
+ active.focus({ preventScroll: true });
11234
+ if (selection?.start != null && selection.end != null) {
11235
+ active.setSelectionRange(selection.start, selection.end, selection.direction || undefined);
11236
+ }
11237
+ }
11238
+ }
11239
+
11167
11240
  /**
11168
11241
  * Structural Directives (*if, *for)
11169
11242
  * Single-pass parser for conditional and list rendering with transitions
@@ -11344,6 +11417,7 @@ function processForWithKeys(placeholder, template, list, itemVar, keyExpr, curre
11344
11417
  });
11345
11418
  // Add/reorder items immediately (parallel with remove animations)
11346
11419
  let lastPlacedNode = placeholder;
11420
+ const rows = [];
11347
11421
  orderedKeys.forEach((key) => {
11348
11422
  const newItemData = newItemsMap.get(key);
11349
11423
  const { index } = newItemData;
@@ -11395,13 +11469,10 @@ function processForWithKeys(placeholder, template, list, itemVar, keyExpr, curre
11395
11469
  });
11396
11470
  }
11397
11471
  }
11398
- // Place each managed row directly after the previous row. This does not
11399
- // depend on formatting whitespace or unrelated sibling nodes.
11400
- if (itemElement !== lastPlacedNode.nextSibling) {
11401
- placeholder.parentNode?.insertBefore(itemElement, lastPlacedNode.nextSibling);
11402
- }
11472
+ rows.push(itemElement);
11403
11473
  lastPlacedNode = itemElement;
11404
11474
  });
11475
+ placeKeyedRows(placeholder, rows);
11405
11476
  }
11406
11477
  /**
11407
11478
  * Process *for without keys (simple re-render)
@@ -15503,7 +15574,7 @@ const Gyos = {
15503
15574
  portalCreate,
15504
15575
  portalDestroy,
15505
15576
  setCspNonce,
15506
- version: '0.5.0'
15577
+ version: '0.5.1'
15507
15578
  };
15508
15579
 
15509
15580
  setExpressionRuntime(cspExpressionRuntime);