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.csp.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
  */
@@ -11170,6 +11170,79 @@
11170
11170
  return scopeVersionMap.get(target);
11171
11171
  }
11172
11172
 
11173
+ /** Keep the longest already-ordered run of rows connected; move only the rest. */
11174
+ function placeKeyedRows(placeholder, rows) {
11175
+ const parent = placeholder.parentNode;
11176
+ if (!parent || rows.length === 0)
11177
+ return;
11178
+ const managed = new Set(rows);
11179
+ const positions = new Map();
11180
+ let boundary = placeholder.nextSibling;
11181
+ while (boundary && managed.has(boundary)) {
11182
+ positions.set(boundary, positions.size);
11183
+ boundary = boundary.nextSibling;
11184
+ }
11185
+ const active = placeholder.ownerDocument.activeElement;
11186
+ const ownsFocus = !!active && rows.some((row) => row === active || row.contains(active));
11187
+ const selection = ownsFocus && (active instanceof HTMLInputElement || active instanceof HTMLTextAreaElement)
11188
+ ? { start: active.selectionStart, end: active.selectionEnd, direction: active.selectionDirection }
11189
+ : null;
11190
+ if (positions.size !== rows.length) {
11191
+ // Leaving transition nodes, foreign siblings or externally detached rows:
11192
+ // preserve the established contiguous-after-placeholder placement contract.
11193
+ let previous = placeholder;
11194
+ for (const row of rows) {
11195
+ if (row !== previous.nextSibling)
11196
+ parent.insertBefore(row, previous.nextSibling);
11197
+ previous = row;
11198
+ }
11199
+ }
11200
+ else {
11201
+ const order = rows.map((row) => positions.get(row));
11202
+ let sorted = true;
11203
+ for (let i = 1; i < order.length; i++)
11204
+ if (order[i] < order[i - 1]) {
11205
+ sorted = false;
11206
+ break;
11207
+ }
11208
+ if (sorted)
11209
+ return;
11210
+ // Patience sorting: indices of a longest increasing subsequence, O(n log n).
11211
+ const tails = [], predecessors = new Array(order.length).fill(-1);
11212
+ for (let i = 0; i < order.length; i++) {
11213
+ let low = 0, high = tails.length;
11214
+ while (low < high) {
11215
+ const middle = (low + high) >>> 1;
11216
+ if (order[tails[middle]] < order[i])
11217
+ low = middle + 1;
11218
+ else
11219
+ high = middle;
11220
+ }
11221
+ if (low > 0)
11222
+ predecessors[i] = tails[low - 1];
11223
+ tails[low] = i;
11224
+ }
11225
+ const retained = new Set();
11226
+ for (let i = tails[tails.length - 1]; i >= 0; i = predecessors[i])
11227
+ retained.add(i);
11228
+ for (let i = rows.length - 1; i >= 0; i--) {
11229
+ const row = rows[i];
11230
+ if (!retained.has(i) && row.nextSibling !== boundary)
11231
+ parent.insertBefore(row, boundary);
11232
+ boundary = row;
11233
+ }
11234
+ }
11235
+ // insertBefore can blur a moved input. Restore only a surviving owned focus,
11236
+ // and never steal focus assigned to another control by application callbacks.
11237
+ const document = placeholder.ownerDocument;
11238
+ if (ownsFocus && active.isConnected && document.activeElement === document.body) {
11239
+ active.focus({ preventScroll: true });
11240
+ if (selection?.start != null && selection.end != null) {
11241
+ active.setSelectionRange(selection.start, selection.end, selection.direction || undefined);
11242
+ }
11243
+ }
11244
+ }
11245
+
11173
11246
  /**
11174
11247
  * Structural Directives (*if, *for)
11175
11248
  * Single-pass parser for conditional and list rendering with transitions
@@ -11350,6 +11423,7 @@
11350
11423
  });
11351
11424
  // Add/reorder items immediately (parallel with remove animations)
11352
11425
  let lastPlacedNode = placeholder;
11426
+ const rows = [];
11353
11427
  orderedKeys.forEach((key) => {
11354
11428
  const newItemData = newItemsMap.get(key);
11355
11429
  const { index } = newItemData;
@@ -11401,13 +11475,10 @@
11401
11475
  });
11402
11476
  }
11403
11477
  }
11404
- // Place each managed row directly after the previous row. This does not
11405
- // depend on formatting whitespace or unrelated sibling nodes.
11406
- if (itemElement !== lastPlacedNode.nextSibling) {
11407
- placeholder.parentNode?.insertBefore(itemElement, lastPlacedNode.nextSibling);
11408
- }
11478
+ rows.push(itemElement);
11409
11479
  lastPlacedNode = itemElement;
11410
11480
  });
11481
+ placeKeyedRows(placeholder, rows);
11411
11482
  }
11412
11483
  /**
11413
11484
  * Process *for without keys (simple re-render)
@@ -15509,7 +15580,7 @@
15509
15580
  portalCreate,
15510
15581
  portalDestroy,
15511
15582
  setCspNonce,
15512
- version: '0.5.0'
15583
+ version: '0.5.1'
15513
15584
  };
15514
15585
 
15515
15586
  setExpressionRuntime(cspExpressionRuntime);