@farm.js/react 0.1.0-beta.20 → 0.1.0-beta.22

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.
@@ -11,8 +11,14 @@ var React__default = /*#__PURE__*/_interopDefault(React);
11
11
 
12
12
  // src/iterable.ts
13
13
  var oneShotSnapshots = /* @__PURE__ */ new WeakMap();
14
+ var arrayIterator = Array.prototype[Symbol.iterator];
14
15
  function materializeIterable(source) {
15
16
  if (source == null) return [];
17
+ if (Array.isArray(source) && Object.getPrototypeOf(source) === Array.prototype && source[Symbol.iterator] === arrayIterator) {
18
+ const items2 = [];
19
+ for (let index = 0; index < source.length; index += 1) items2.push(source[index]);
20
+ return items2;
21
+ }
16
22
  const iterator = source[Symbol.iterator]();
17
23
  const oneShot = iterator === source && (typeof source === "object" || typeof source === "function");
18
24
  if (oneShot) {
@@ -1586,7 +1592,9 @@ function getCompilerHmrRegistry() {
1586
1592
  return registry;
1587
1593
  }
1588
1594
  function renderTextValue(value) {
1589
- if (Array.isArray(value)) return value.map(renderTextValue).join("");
1595
+ if (Array.isArray(value)) {
1596
+ return value.length === 1 ? renderTextValue(value[0]) : value.map(renderTextValue).join("");
1597
+ }
1590
1598
  if (value === null || value === void 0 || typeof value === "boolean") return "";
1591
1599
  return String(value);
1592
1600
  }
@@ -1713,8 +1721,11 @@ function updateSelectValue(element, value) {
1713
1721
  }
1714
1722
  if (fallback) fallback.selected = true;
1715
1723
  }
1724
+ function compilerAttributeName(name) {
1725
+ return name === "className" ? "class" : name === "htmlFor" ? "for" : name;
1726
+ }
1716
1727
  function updateAttribute(element, name, value) {
1717
- const attributeName = name === "className" ? "class" : name === "htmlFor" ? "for" : name;
1728
+ const attributeName = compilerAttributeName(name);
1718
1729
  const stringifiesBoolean = attributeName.startsWith("data-") || attributeName.startsWith("aria-");
1719
1730
  if (name === "value" && (isInputElement(element) || isTextAreaElement(element))) {
1720
1731
  const nextValue = value === null || value === void 0 ? "" : String(value);
@@ -1967,7 +1978,10 @@ function hasUnsafeCompilerFallbackKeys(descriptor) {
1967
1978
  }
1968
1979
  function findCompilerHostTarget(root, path) {
1969
1980
  let current = root;
1970
- for (const index of path) current = current?.children[index] || null;
1981
+ for (const index of path) {
1982
+ current = current && current.firstElementChild;
1983
+ for (let step = 0; step < index && current; step += 1) current = current.nextElementSibling;
1984
+ }
1971
1985
  return current;
1972
1986
  }
1973
1987
  var UNSET_STATIC_RANGE_BINDING = /* @__PURE__ */ Symbol("unset static range binding");
@@ -2502,9 +2516,64 @@ function normalizedKeyedRowBindingValue(binding, value) {
2502
2516
  return binding.kind === "text" ? renderTextValue(value) : value;
2503
2517
  }
2504
2518
  function readKeyedRowBindingValues(props, item, index) {
2505
- return props.bindings.map(
2506
- (binding) => normalizedKeyedRowBindingValue(binding, binding.read(item, index))
2507
- );
2519
+ const values = [];
2520
+ for (const binding of props.bindings) {
2521
+ values.push(normalizedKeyedRowBindingValue(binding, binding.read(item, index)));
2522
+ }
2523
+ return values;
2524
+ }
2525
+ var KEYED_ROW_TEMPLATES = /* @__PURE__ */ new WeakMap();
2526
+ function createKeyedRowInstance(props, document, key, item, index) {
2527
+ const template = props.cloneRows && KEYED_ROW_TEMPLATES.get(props);
2528
+ const element = template ? template.cloneNode(true) : createCompilerHostElement(document, props.create(item, index));
2529
+ const instance = {
2530
+ key,
2531
+ element,
2532
+ values: readKeyedRowBindingValues(props, item, index),
2533
+ item,
2534
+ index,
2535
+ conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
2536
+ };
2537
+ if (props.cloneRows) {
2538
+ const targets = [];
2539
+ let found = true;
2540
+ for (const binding of props.bindings) {
2541
+ const target = findCompilerHostTarget(element, binding.path);
2542
+ found && (found = target !== null);
2543
+ targets.push(target);
2544
+ }
2545
+ if (found) instance.targets = targets;
2546
+ if (template) {
2547
+ for (let bindingIndex = 0; bindingIndex < targets.length; bindingIndex += 1) {
2548
+ commitKeyedRowBinding(
2549
+ props.bindings[bindingIndex],
2550
+ instance,
2551
+ bindingIndex,
2552
+ instance.values[bindingIndex],
2553
+ targets[bindingIndex]
2554
+ );
2555
+ }
2556
+ } else {
2557
+ const skeleton = keyedRowTemplate(props, element, targets);
2558
+ if (skeleton) KEYED_ROW_TEMPLATES.set(props, skeleton);
2559
+ }
2560
+ }
2561
+ return instance;
2562
+ }
2563
+ function keyedRowTemplate(props, element, targets) {
2564
+ for (let bindingIndex = 0; bindingIndex < props.bindings.length; bindingIndex += 1) {
2565
+ const binding = props.bindings[bindingIndex];
2566
+ const target = targets[bindingIndex];
2567
+ if (!target || binding.kind === "style") return void 0;
2568
+ if (binding.kind === "attribute" && !target.hasAttribute(compilerAttributeName(binding.name))) {
2569
+ return void 0;
2570
+ }
2571
+ }
2572
+ const template = element.cloneNode(true);
2573
+ for (const binding of props.bindings) {
2574
+ if (binding.kind === "text") findCompilerHostTarget(template, binding.path).textContent = "";
2575
+ }
2576
+ return template;
2508
2577
  }
2509
2578
  function applyKeyedRowBindings(props, instance, item, index) {
2510
2579
  if (props.bindings.length < 2) {
@@ -2516,10 +2585,7 @@ function applyKeyedRowBindings(props, instance, item, index) {
2516
2585
  for (let bindingIndex = 0; bindingIndex < props.bindings.length; bindingIndex += 1) {
2517
2586
  if (Object.is(instance.values[bindingIndex], nextValues[bindingIndex])) continue;
2518
2587
  targets || (targets = []);
2519
- targets[bindingIndex] = findCompilerHostTarget(
2520
- instance.element,
2521
- props.bindings[bindingIndex].path
2522
- );
2588
+ targets[bindingIndex] = keyedRowBindingTarget(props, instance, bindingIndex);
2523
2589
  }
2524
2590
  if (!targets) return;
2525
2591
  for (let bindingIndex = 0; bindingIndex < props.bindings.length; bindingIndex += 1) {
@@ -2538,14 +2604,22 @@ function applyKeyedRowBinding(props, instance, item, index, bindingIndex) {
2538
2604
  const binding = props.bindings[bindingIndex];
2539
2605
  const value = normalizedKeyedRowBindingValue(binding, binding.read(item, index));
2540
2606
  if (Object.is(instance.values[bindingIndex], value)) return;
2541
- const target = findCompilerHostTarget(instance.element, binding.path);
2607
+ const target = keyedRowBindingTarget(props, instance, bindingIndex);
2542
2608
  commitKeyedRowBinding(binding, instance, bindingIndex, value, target);
2543
2609
  }
2610
+ function keyedRowBindingTarget(props, instance, bindingIndex) {
2611
+ return instance.targets?.[bindingIndex] || findCompilerHostTarget(instance.element, props.bindings[bindingIndex].path);
2612
+ }
2544
2613
  function commitKeyedRowBinding(binding, instance, bindingIndex, value, target) {
2545
2614
  instance.values[bindingIndex] = value;
2546
2615
  if (!target) return;
2547
2616
  if (binding.kind === "text") {
2548
- target.textContent = value;
2617
+ const text = target.firstChild;
2618
+ if (value && text && text === target.lastChild && text.nodeType === 3) {
2619
+ text.data = value;
2620
+ } else {
2621
+ target.textContent = value;
2622
+ }
2549
2623
  } else if (binding.kind === "style" && binding.name) {
2550
2624
  updateStyle(target, binding.name, value);
2551
2625
  } else if (binding.kind === "attribute" && binding.name) {
@@ -2557,28 +2631,29 @@ function prepareKeyedRowBindingUpdate(props, instance, item, index, bindingIndex
2557
2631
  const rawValue = binding.read(item, index);
2558
2632
  const value = normalizedKeyedRowBindingValue(binding, rawValue);
2559
2633
  if (Object.is(instance.values[bindingIndex], value)) return null;
2560
- const target = findCompilerHostTarget(instance.element, binding.path);
2634
+ const target = keyedRowBindingTarget(props, instance, bindingIndex);
2561
2635
  if (!target || binding.kind !== "text" && !binding.name) return void 0;
2562
2636
  return [bindingIndex, target, value];
2563
2637
  }
2564
2638
  function prepareKeyedRowBindingUpdates(props, instance, item, index) {
2565
- const updates = [];
2639
+ let updates;
2566
2640
  for (let bindingIndex = 0; bindingIndex < props.bindings.length; bindingIndex += 1) {
2567
2641
  const update = prepareKeyedRowBindingUpdate(props, instance, item, index, bindingIndex);
2568
2642
  if (update === void 0) return void 0;
2569
- if (update) updates.push(update);
2643
+ if (update) (updates || (updates = [])).push(update);
2570
2644
  }
2571
- return updates;
2645
+ return updates || NO_KEYED_ROW_BINDING_UPDATES;
2572
2646
  }
2647
+ var NO_KEYED_ROW_BINDING_UPDATES = [];
2573
2648
  function applyPreparedKeyedRowBindingUpdates(props, instance, updates) {
2574
2649
  for (const [bindingIndex, target, value] of updates) {
2575
2650
  commitKeyedRowBinding(props.bindings[bindingIndex], instance, bindingIndex, value, target);
2576
2651
  }
2577
2652
  }
2578
- function prepareKeyedRowBindingSetUpdates(props, instances, rows) {
2653
+ function prepareKeyedRowBindingSetUpdates(props, instances, rows, ordered) {
2579
2654
  const preparedUpdates = [];
2580
2655
  for (let index = 0; index < rows.items.length; index += 1) {
2581
- const instance = instances.get(rows.keys[index]);
2656
+ const instance = ordered ? ordered[index] : instances.get(rows.keys[index]);
2582
2657
  if (!instance) return void 0;
2583
2658
  const updates = prepareKeyedRowBindingUpdates(props, instance, rows.items[index], index);
2584
2659
  if (!updates) return void 0;
@@ -2998,6 +3073,24 @@ var CompilerNestedConditionalRanges = class {
2998
3073
  this.staticValues.length = 0;
2999
3074
  }
3000
3075
  };
3076
+ function reconcileStableNestedKeyedRows(range, previous, rows) {
3077
+ if (rows.keys.length !== previous.size) return void 0;
3078
+ let index = 0;
3079
+ for (const key of previous.keys()) {
3080
+ if (rows.keys[index++] !== key) return void 0;
3081
+ }
3082
+ index = 0;
3083
+ for (const existing of previous.values()) {
3084
+ const item = rows.items[index];
3085
+ const descriptor = range.create(item, index);
3086
+ if (!existing.scope?.update(descriptor)) return false;
3087
+ applyKeyedRowBindings(range, existing, item, index);
3088
+ existing.item = item;
3089
+ existing.index = index;
3090
+ index += 1;
3091
+ }
3092
+ return true;
3093
+ }
3001
3094
  var CompilerNestedKeyedRanges = class {
3002
3095
  constructor(owner, root, host, block, onFallback) {
3003
3096
  this.owner = owner;
@@ -3171,6 +3264,8 @@ var CompilerNestedKeyedRanges = class {
3171
3264
  reconcileRange(rangeIndex, rows) {
3172
3265
  const range = this.block.ranges[rangeIndex];
3173
3266
  const previous = this.instances[rangeIndex];
3267
+ const stable = reconcileStableNestedKeyedRows(range, previous, rows);
3268
+ if (stable !== void 0) return stable;
3174
3269
  const oldIndices = /* @__PURE__ */ new Map();
3175
3270
  [...previous.keys()].forEach((key, index) => oldIndices.set(key, index));
3176
3271
  const nextKeys = new Set(rows.keys);
@@ -3211,7 +3306,7 @@ var CompilerNestedKeyedRanges = class {
3211
3306
  let anchor = this.anchorAfter(rangeIndex);
3212
3307
  for (let index = nextInstances.length - 1; index >= 0; index -= 1) {
3213
3308
  const instance = nextInstances[index];
3214
- if (sequence[index] < 0 || !stablePositions.has(index) && instance.element.nextSibling !== anchor) {
3309
+ if (sequence[index] < 0 || !stablePositions[index] && instance.element.nextSibling !== anchor) {
3215
3310
  this.root.insertBefore(instance.element, anchor);
3216
3311
  }
3217
3312
  anchor = instance.element;
@@ -3529,6 +3624,8 @@ var CompilerNestedMixedRanges = class {
3529
3624
  const instance = this.instances[rangeIndex];
3530
3625
  if (instance.kind !== "keyed") return false;
3531
3626
  const previous = instance.value;
3627
+ const stable = reconcileStableNestedKeyedRows(range, previous, rows);
3628
+ if (stable !== void 0) return stable;
3532
3629
  const oldIndices = /* @__PURE__ */ new Map();
3533
3630
  [...previous.keys()].forEach((key, index) => oldIndices.set(key, index));
3534
3631
  const nextKeys = new Set(rows.keys);
@@ -3576,7 +3673,7 @@ var CompilerNestedMixedRanges = class {
3576
3673
  let anchor = this.anchorAfter(rangeIndex);
3577
3674
  for (let index = nextInstances.length - 1; index >= 0; index -= 1) {
3578
3675
  const row = nextInstances[index];
3579
- if (sequence[index] < 0 || !stablePositions.has(index) && row.element.nextSibling !== anchor) {
3676
+ if (sequence[index] < 0 || !stablePositions[index] && row.element.nextSibling !== anchor) {
3580
3677
  this.root.insertBefore(row.element, anchor);
3581
3678
  }
3582
3679
  anchor = row.element;
@@ -4238,7 +4335,7 @@ function createConditionalRangesBlockComponent(owner) {
4238
4335
  }
4239
4336
  function longestIncreasingSubsequencePositions(sequence) {
4240
4337
  const tails = [];
4241
- const previous = Array.from({ length: sequence.length }, () => -1);
4338
+ const previous = new Int32Array(sequence.length).fill(-1);
4242
4339
  for (let index = 0; index < sequence.length; index += 1) {
4243
4340
  if (sequence[index] < 0) continue;
4244
4341
  let low = 0;
@@ -4251,10 +4348,10 @@ function longestIncreasingSubsequencePositions(sequence) {
4251
4348
  if (low > 0) previous[index] = tails[low - 1];
4252
4349
  tails[low] = index;
4253
4350
  }
4254
- const positions = /* @__PURE__ */ new Set();
4351
+ const positions = new Uint8Array(sequence.length);
4255
4352
  let cursor = tails.at(-1) ?? -1;
4256
4353
  while (cursor >= 0) {
4257
- positions.add(cursor);
4354
+ positions[cursor] = 1;
4258
4355
  cursor = previous[cursor];
4259
4356
  }
4260
4357
  return positions;
@@ -4267,15 +4364,13 @@ function reorderCompilerKeyedRows(root, instances, sequence, anchor) {
4267
4364
  if (sequence[index] < 0) {
4268
4365
  let start = index;
4269
4366
  while (start > 0 && sequence[start - 1] < 0) start -= 1;
4270
- const fragment = root.ownerDocument.createDocumentFragment();
4271
4367
  for (let itemIndex = start; itemIndex <= index; itemIndex += 1) {
4272
- fragment.append(instances[itemIndex].element);
4368
+ root.insertBefore(instances[itemIndex].element, anchor);
4273
4369
  }
4274
- root.insertBefore(fragment, anchor);
4275
4370
  anchor = instances[start].element;
4276
4371
  index = start;
4277
4372
  } else {
4278
- if (!stablePositions.has(index) && instance.element.nextSibling !== anchor) {
4373
+ if (!stablePositions[index] && instance.element.nextSibling !== anchor) {
4279
4374
  root.insertBefore(instance.element, anchor);
4280
4375
  }
4281
4376
  anchor = instance.element;
@@ -4543,15 +4638,13 @@ function reconcileCompilerKeyedArrayAppend(props, dirtyState, collectionToken, i
4543
4638
  const item = finalValue[index];
4544
4639
  const key = keyedRowIdentity(props.rowKey(item, index));
4545
4640
  if (nextInstances.has(key)) return void 0;
4546
- const descriptor = props.create(item, index);
4547
- const instance = {
4641
+ const instance = createKeyedRowInstance(
4642
+ props,
4643
+ root.ownerDocument,
4548
4644
  key,
4549
- element: createCompilerHostElement(root.ownerDocument, descriptor),
4550
- values: readKeyedRowBindingValues(props, item, index),
4551
4645
  item,
4552
- index,
4553
- conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
4554
- };
4646
+ index
4647
+ );
4555
4648
  appended.push(instance);
4556
4649
  nextInstances.set(key, instance);
4557
4650
  }
@@ -4608,15 +4701,7 @@ function reconcileCompilerKeyedArrayStructuralAppend(props, dirtyState, collecti
4608
4701
  const key = keyedRowIdentity(props.rowKey(item, index));
4609
4702
  if (knownKeys.has(key)) return void 0;
4610
4703
  knownKeys.add(key);
4611
- const descriptor = props.create(item, index);
4612
- appended.push({
4613
- key,
4614
- element: createCompilerHostElement(root.ownerDocument, descriptor),
4615
- values: readKeyedRowBindingValues(props, item, index),
4616
- item,
4617
- index,
4618
- conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
4619
- });
4704
+ appended.push(createKeyedRowInstance(props, root.ownerDocument, key, item, index));
4620
4705
  }
4621
4706
  } catch {
4622
4707
  return void 0;
@@ -4717,15 +4802,7 @@ function reconcileCompilerKeyedArrayStructuralAppendMap(props, dirtyState, colle
4717
4802
  const key = keyedRowIdentity(props.rowKey(item, index));
4718
4803
  if (instances.has(key) || appendedKeys.has(key)) return void 0;
4719
4804
  appendedKeys.add(key);
4720
- const descriptor = props.create(item, index);
4721
- appended.push({
4722
- key,
4723
- element: createCompilerHostElement(root.ownerDocument, descriptor),
4724
- values: readKeyedRowBindingValues(props, item, index),
4725
- item,
4726
- index,
4727
- conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
4728
- });
4805
+ appended.push(createKeyedRowInstance(props, root.ownerDocument, key, item, index));
4729
4806
  }
4730
4807
  } catch {
4731
4808
  return void 0;
@@ -4823,15 +4900,7 @@ function reconcileCompilerKeyedArrayRollingWindow(props, dirtyState, collectionT
4823
4900
  const key = keyedRowIdentity(props.rowKey(item, index));
4824
4901
  if (knownKeys.has(key)) return void 0;
4825
4902
  knownKeys.add(key);
4826
- const descriptor = props.create(item, index);
4827
- incoming.push({
4828
- key,
4829
- element: createCompilerHostElement(root.ownerDocument, descriptor),
4830
- values: readKeyedRowBindingValues(props, item, index),
4831
- item,
4832
- index,
4833
- conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
4834
- });
4903
+ incoming.push(createKeyedRowInstance(props, root.ownerDocument, key, item, index));
4835
4904
  }
4836
4905
  } catch {
4837
4906
  return void 0;
@@ -4902,15 +4971,7 @@ function reconcileCompilerKeyedArrayMappedRollingWindow(props, dirtyState, colle
4902
4971
  const key = keyedRowIdentity(props.rowKey(item, index));
4903
4972
  if (instances.has(key) || incomingKeys.has(key)) return void 0;
4904
4973
  incomingKeys.add(key);
4905
- const descriptor = props.create(item, index);
4906
- incoming.push({
4907
- key,
4908
- element: createCompilerHostElement(root.ownerDocument, descriptor),
4909
- values: readKeyedRowBindingValues(props, item, index),
4910
- item,
4911
- index,
4912
- conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
4913
- });
4974
+ incoming.push(createKeyedRowInstance(props, root.ownerDocument, key, item, index));
4914
4975
  }
4915
4976
  } catch {
4916
4977
  return void 0;
@@ -4989,15 +5050,7 @@ function reconcileCompilerKeyedArrayPosition(props, dirtyState, collectionToken,
4989
5050
  if (instances.has(key)) return void 0;
4990
5051
  let inserted;
4991
5052
  try {
4992
- const descriptor = props.create(item, update.position);
4993
- inserted = {
4994
- key,
4995
- element: createCompilerHostElement(root.ownerDocument, descriptor),
4996
- values: readKeyedRowBindingValues(props, item, update.position),
4997
- item,
4998
- index: update.position,
4999
- conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
5000
- };
5053
+ inserted = createKeyedRowInstance(props, root.ownerDocument, key, item, update.position);
5001
5054
  } catch {
5002
5055
  return void 0;
5003
5056
  }
@@ -5021,15 +5074,7 @@ function reconcileCompilerKeyedArrayPosition(props, dirtyState, collectionToken,
5021
5074
  if (instances.has(key)) return void 0;
5022
5075
  let replacement;
5023
5076
  try {
5024
- const descriptor = props.create(item, update.position);
5025
- replacement = {
5026
- key,
5027
- element: createCompilerHostElement(root.ownerDocument, descriptor),
5028
- values: readKeyedRowBindingValues(props, item, update.position),
5029
- item,
5030
- index: update.position,
5031
- conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
5032
- };
5077
+ replacement = createKeyedRowInstance(props, root.ownerDocument, key, item, update.position);
5033
5078
  } catch {
5034
5079
  return void 0;
5035
5080
  }
@@ -5072,15 +5117,7 @@ function reconcileCompilerKeyedArrayBatchInsert(props, dirtyState, collectionTok
5072
5117
  const key = keyedRowIdentity(props.rowKey(item, index));
5073
5118
  if (instances.has(key) || incomingKeys.has(key)) return void 0;
5074
5119
  incomingKeys.add(key);
5075
- const descriptor = props.create(item, index);
5076
- incoming.push({
5077
- key,
5078
- element: createCompilerHostElement(root.ownerDocument, descriptor),
5079
- values: readKeyedRowBindingValues(props, item, index),
5080
- item,
5081
- index,
5082
- conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
5083
- });
5120
+ incoming.push(createKeyedRowInstance(props, root.ownerDocument, key, item, index));
5084
5121
  }
5085
5122
  } catch {
5086
5123
  return void 0;
@@ -5166,15 +5203,7 @@ function prepareCompilerKeyedArrayWindow(props, instances, previousInstances, ro
5166
5203
  continue;
5167
5204
  }
5168
5205
  if (instances.has(key)) return void 0;
5169
- const descriptor = props.create(item, index);
5170
- nextWindow.push({
5171
- key,
5172
- element: createCompilerHostElement(root.ownerDocument, descriptor),
5173
- values: readKeyedRowBindingValues(props, item, index),
5174
- item,
5175
- index,
5176
- conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
5177
- });
5206
+ nextWindow.push(createKeyedRowInstance(props, root.ownerDocument, key, item, index));
5178
5207
  sequence.push(-1);
5179
5208
  preparedBindings.push(void 0);
5180
5209
  }
@@ -5304,20 +5333,12 @@ function reconcileCompilerKeyedArrayWindowReplace(props, dirtyState, collectionT
5304
5333
  if (instances.has(key) || incomingKeys2.has(key)) return void 0;
5305
5334
  incomingKeys2.add(key);
5306
5335
  replacesRows = true;
5307
- const descriptor = props.create(item, index);
5308
5336
  prepared2.push([
5309
5337
  index,
5310
5338
  instance,
5311
5339
  item,
5312
5340
  void 0,
5313
- {
5314
- key,
5315
- element: createCompilerHostElement(root.ownerDocument, descriptor),
5316
- values: readKeyedRowBindingValues(props, item, index),
5317
- item,
5318
- index,
5319
- conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
5320
- }
5341
+ createKeyedRowInstance(props, root.ownerDocument, key, item, index)
5321
5342
  ]);
5322
5343
  continue;
5323
5344
  }
@@ -5655,15 +5676,7 @@ function reconcileCompilerKeyedArrayPrepend(props, dirtyState, collectionToken,
5655
5676
  const key = keyedRowIdentity(props.rowKey(item, index));
5656
5677
  if (instances.has(key) || incomingKeys.has(key)) return void 0;
5657
5678
  incomingKeys.add(key);
5658
- const descriptor = props.create(item, index);
5659
- prepended.push({
5660
- key,
5661
- element: createCompilerHostElement(root.ownerDocument, descriptor),
5662
- values: readKeyedRowBindingValues(props, item, index),
5663
- item,
5664
- index,
5665
- conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
5666
- });
5679
+ prepended.push(createKeyedRowInstance(props, root.ownerDocument, key, item, index));
5667
5680
  }
5668
5681
  } catch {
5669
5682
  return void 0;
@@ -5721,15 +5734,7 @@ function reconcileCompilerKeyedArrayStructuralPrepend(props, dirtyState, collect
5721
5734
  const key = keyedRowIdentity(props.rowKey(item, index));
5722
5735
  if (knownKeys.has(key)) return void 0;
5723
5736
  knownKeys.add(key);
5724
- const descriptor = props.create(item, index);
5725
- prepended.push({
5726
- key,
5727
- element: createCompilerHostElement(root.ownerDocument, descriptor),
5728
- values: readKeyedRowBindingValues(props, item, index),
5729
- item,
5730
- index,
5731
- conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
5732
- });
5737
+ prepended.push(createKeyedRowInstance(props, root.ownerDocument, key, item, index));
5733
5738
  }
5734
5739
  } catch {
5735
5740
  return void 0;
@@ -5840,15 +5845,7 @@ function reconcileCompilerKeyedArrayStructuralPrependMap(props, dirtyState, coll
5840
5845
  const key = keyedRowIdentity(props.rowKey(item, index));
5841
5846
  if (knownKeys.has(key)) return void 0;
5842
5847
  knownKeys.add(key);
5843
- const descriptor = props.create(item, index);
5844
- prepended.push({
5845
- key,
5846
- element: createCompilerHostElement(root.ownerDocument, descriptor),
5847
- values: readKeyedRowBindingValues(props, item, index),
5848
- item,
5849
- index,
5850
- conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
5851
- });
5848
+ prepended.push(createKeyedRowInstance(props, root.ownerDocument, key, item, index));
5852
5849
  }
5853
5850
  } catch {
5854
5851
  return void 0;
@@ -5900,7 +5897,7 @@ function reconcileCompilerKeyedArrayFilter(props, dirtyState, collectionToken, i
5900
5897
  return void 0;
5901
5898
  }
5902
5899
  const dependencies = props.dependencies || props.structureDependencies;
5903
- const relevantDirty = (dependencies || []).filter((index) => dirtyState.has(index));
5900
+ const relevantDirty = (dependencies || []).filter((index2) => dirtyState.has(index2));
5904
5901
  if (relevantDirty.length !== 1 || relevantDirty[0] !== collectionDependency) {
5905
5902
  return void 0;
5906
5903
  }
@@ -5912,31 +5909,34 @@ function reconcileCompilerKeyedArrayFilter(props, dirtyState, collectionToken, i
5912
5909
  );
5913
5910
  if (!survivorResult || !Array.isArray(finalValue)) return void 0;
5914
5911
  const { indices: survivorIndices, keysStable } = survivorResult;
5915
- const previousInstances = [...instances.values()];
5916
- const survivors = [];
5912
+ const removed = [];
5913
+ let cursor = 0;
5914
+ let sourceIndex = 0;
5917
5915
  try {
5918
- for (let index = 0; index < survivorIndices.length; index += 1) {
5919
- const sourceIndex = survivorIndices[index];
5920
- const instance = previousInstances[sourceIndex];
5921
- const item = finalValue[index];
5922
- if (!instance || instance.index !== sourceIndex || !Object.is(instance.item, item) || !keysStable && keyedRowIdentity(props.rowKey(item, index)) !== instance.key) {
5923
- return void 0;
5916
+ for (const instance of instances.values()) {
5917
+ if (survivorIndices[cursor] !== sourceIndex) {
5918
+ removed.push(instance);
5919
+ } else {
5920
+ const item = finalValue[cursor];
5921
+ if (instance.index !== sourceIndex || !Object.is(instance.item, item) || !keysStable && keyedRowIdentity(props.rowKey(item, cursor)) !== instance.key) {
5922
+ return void 0;
5923
+ }
5924
+ cursor += 1;
5924
5925
  }
5925
- survivors.push(instance);
5926
+ sourceIndex += 1;
5926
5927
  }
5927
5928
  } catch {
5928
5929
  return void 0;
5929
5930
  }
5930
- const survivorSet = new Set(survivorIndices);
5931
- for (let index = 0; index < previousInstances.length; index += 1) {
5932
- if (survivorSet.has(index)) continue;
5933
- previousInstances[index].scope?.cleanup();
5934
- previousInstances[index].element.remove();
5935
- }
5936
- for (let index = 0; index < survivors.length; index += 1) {
5937
- survivors[index].index = index;
5931
+ if (cursor !== survivorIndices.length) return void 0;
5932
+ for (const instance of removed) {
5933
+ instance.scope?.cleanup();
5934
+ instance.element.remove();
5935
+ instances.delete(instance.key);
5938
5936
  }
5939
- return keyedRowInstancesByKey(survivors);
5937
+ let index = 0;
5938
+ for (const instance of instances.values()) instance.index = index++;
5939
+ return instances;
5940
5940
  }
5941
5941
  function createKeyedRowConditionalRuntime() {
5942
5942
  class FarmKeyedRowConditional extends React__default.default.Component {
@@ -5981,9 +5981,42 @@ function createKeyedRowConditionalRuntime() {
5981
5981
  }
5982
5982
  FarmKeyedRowConditional.displayName = "FarmCompiledKeyedRowConditional";
5983
5983
  return {
5984
- Component: FarmKeyedRowConditional,
5984
+ element: (props) => React__default.default.createElement(FarmKeyedRowConditional, {
5985
+ key: `${props.rowKey}:${props.id}`,
5986
+ ...props
5987
+ }),
5985
5988
  readValues: readKeyedRowConditionalValues,
5986
- changed: keyedRowConditionalChanged
5989
+ changed: keyedRowConditionalChanged,
5990
+ owner: (listeners) => ({
5991
+ subscribe(key, id, refresh) {
5992
+ let row = listeners.get(key);
5993
+ if (!row) {
5994
+ row = /* @__PURE__ */ new Map();
5995
+ listeners.set(key, row);
5996
+ }
5997
+ row.set(id, refresh);
5998
+ return () => {
5999
+ const current = listeners.get(key);
6000
+ if (current?.get(id) !== refresh) return;
6001
+ current.delete(id);
6002
+ if (current.size === 0) listeners.delete(key);
6003
+ };
6004
+ }
6005
+ }),
6006
+ notify(listeners, changes, afterCommit) {
6007
+ let pending = changes.length;
6008
+ const committed = () => {
6009
+ pending -= 1;
6010
+ if (pending === 0) afterCommit?.();
6011
+ };
6012
+ reactDom.flushSync(() => {
6013
+ for (const change of changes) {
6014
+ const refresh = listeners.get(change.key)?.get(change.id);
6015
+ if (refresh) refresh(change.item, change.index, committed);
6016
+ else committed();
6017
+ }
6018
+ });
6019
+ }
5987
6020
  };
5988
6021
  }
5989
6022
  function createKeyedRowHostRuntime() {
@@ -6009,14 +6042,15 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6009
6042
  this.currentProps = this.props;
6010
6043
  this.definitionVersion = owner.getDefinitionVersion?.();
6011
6044
  this.instances = /* @__PURE__ */ new Map();
6045
+ this.reactElements = [];
6012
6046
  this.keyedTargets = options.keyedTargets?.(this.props);
6013
6047
  this.renderVersion = 0;
6014
6048
  this.eventHandlers = /* @__PURE__ */ new Map();
6015
6049
  this.conditionalListeners = /* @__PURE__ */ new Map();
6016
6050
  this.instancesByElement = /* @__PURE__ */ new WeakMap();
6017
- this.conditionalOwner = {
6018
- subscribe: (key, id, refresh) => this.subscribeToRowConditional(key, id, refresh)
6019
- };
6051
+ // False after a rebuild without delegated events left surviving rows unindexed.
6052
+ this.elementIndexComplete = true;
6053
+ this.conditionalOwner = options.conditionals?.owner(this.conditionalListeners);
6020
6054
  this.captureRoot = (root) => {
6021
6055
  this.root = root;
6022
6056
  };
@@ -6068,14 +6102,10 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6068
6102
  }
6069
6103
  };
6070
6104
  this.rowConditional = (item, index, conditionalId, render) => {
6071
- if (this.state.fallback) return render(item, index);
6072
- const key = keyedRowIdentity(this.currentProps.rowKey(item, index));
6073
- const Conditional = options.conditionals?.Component;
6074
- if (!Conditional) return render(item, index);
6075
- return React__default.default.createElement(Conditional, {
6076
- key: `${key}:${conditionalId}`,
6105
+ if (this.state.fallback || !options.conditionals) return render(item, index);
6106
+ return options.conditionals.element({
6077
6107
  owner: this.conditionalOwner,
6078
- rowKey: key,
6108
+ rowKey: keyedRowIdentity(this.currentProps.rowKey(item, index)),
6079
6109
  id: conditionalId,
6080
6110
  renderVersion: this.renderVersion,
6081
6111
  item,
@@ -6125,7 +6155,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6125
6155
  );
6126
6156
  if (positionedInstances) {
6127
6157
  if (positionedInstances !== this.instances) {
6128
- this.instances = new Map(positionedInstances);
6158
+ this.instances = positionedInstances;
6129
6159
  this.rebuildElementIndex(this.instances);
6130
6160
  this.pruneEventHandlers();
6131
6161
  this.pruneConditionalListeners();
@@ -6167,8 +6197,10 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6167
6197
  this.instances = rollingWindowInstances instanceof Map ? rollingWindowInstances : new Map(rollingWindowInstances);
6168
6198
  if (delta) {
6169
6199
  COMPILER_KEYED_ROLLING_WINDOW_DELTAS.delete(rollingWindowInstances);
6170
- for (const instance of delta.added) {
6171
- this.instancesByElement.set(instance.element, instance);
6200
+ if (this.usesDelegatedEvents()) {
6201
+ for (const instance of delta.added) {
6202
+ this.instancesByElement.set(instance.element, instance);
6203
+ }
6172
6204
  }
6173
6205
  for (const key of delta.removedKeys) {
6174
6206
  this.eventHandlers.delete(key);
@@ -6192,7 +6224,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6192
6224
  );
6193
6225
  if (filteredInstances) {
6194
6226
  this.instances = filteredInstances;
6195
- this.rebuildElementIndex(this.instances);
6227
+ if (!this.elementIndexComplete) this.rebuildElementIndex(this.instances);
6196
6228
  this.pruneEventHandlers();
6197
6229
  this.pruneConditionalListeners();
6198
6230
  this.commitCurrentCollection(dirtyState);
@@ -6208,7 +6240,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6208
6240
  this.hasReactOwnedRows()
6209
6241
  );
6210
6242
  if (prependedInstances) {
6211
- this.instances = new Map(prependedInstances);
6243
+ this.instances = prependedInstances;
6212
6244
  this.rebuildElementIndex(this.instances);
6213
6245
  this.commitCurrentCollection(dirtyState);
6214
6246
  afterCommit?.();
@@ -6221,9 +6253,29 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6221
6253
  }
6222
6254
  readRows(props) {
6223
6255
  const items = materializeIterable(props.items());
6224
- const keys = items.map((item, index) => keyedRowIdentity(props.rowKey(item, index)));
6225
- if (new Set(keys).size !== keys.length) return null;
6226
- return { items, keys };
6256
+ const keys = [];
6257
+ const committedSize = this.instances.size;
6258
+ let prefix = 0;
6259
+ const committed = this.instances.keys();
6260
+ for (let index = 0; index < items.length; index += 1) {
6261
+ const key = keyedRowIdentity(props.rowKey(items[index], index));
6262
+ keys.push(key);
6263
+ if (prefix === index && index < committedSize && committed.next().value === key) {
6264
+ prefix += 1;
6265
+ }
6266
+ }
6267
+ if (prefix === committedSize && keys.length === committedSize) return { items, keys };
6268
+ if (prefix === committedSize && committedSize > 0) {
6269
+ const tail = /* @__PURE__ */ new Set();
6270
+ for (let index = committedSize; index < keys.length; index += 1) {
6271
+ const key = keys[index];
6272
+ if (this.instances.has(key) || tail.has(key)) return null;
6273
+ tail.add(key);
6274
+ }
6275
+ return { items, keys, appended: true };
6276
+ }
6277
+ const keySet = new Set(keys);
6278
+ return keySet.size === keys.length ? { items, keys, keySet } : null;
6227
6279
  }
6228
6280
  usesDelegatedEvents(props = this.currentProps) {
6229
6281
  return Boolean(
@@ -6232,6 +6284,8 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6232
6284
  }
6233
6285
  rebuildElementIndex(instances) {
6234
6286
  this.instancesByElement = /* @__PURE__ */ new WeakMap();
6287
+ this.elementIndexComplete = this.usesDelegatedEvents();
6288
+ if (!this.elementIndexComplete) return;
6235
6289
  for (const instance of instances.values()) {
6236
6290
  this.instancesByElement.set(instance.element, instance);
6237
6291
  }
@@ -6273,20 +6327,6 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6273
6327
  })
6274
6328
  );
6275
6329
  }
6276
- subscribeToRowConditional(key, id, refresh) {
6277
- let listeners = this.conditionalListeners.get(key);
6278
- if (!listeners) {
6279
- listeners = /* @__PURE__ */ new Map();
6280
- this.conditionalListeners.set(key, listeners);
6281
- }
6282
- listeners.set(id, refresh);
6283
- return () => {
6284
- const current = this.conditionalListeners.get(key);
6285
- if (current?.get(id) !== refresh) return;
6286
- current.delete(id);
6287
- if (current.size === 0) this.conditionalListeners.delete(key);
6288
- };
6289
- }
6290
6330
  hasReactOwnedRows(props = this.currentProps) {
6291
6331
  return Boolean(
6292
6332
  props.conditionals?.length || props.events?.length && !this.usesDelegatedEvents(props)
@@ -6366,6 +6406,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6366
6406
  }
6367
6407
  this.cleanupHostScopes();
6368
6408
  this.instances = instances;
6409
+ this.reactElements = elements;
6369
6410
  this.rebuildElementIndex(instances);
6370
6411
  this.pruneEventHandlers();
6371
6412
  this.pruneConditionalListeners();
@@ -6404,22 +6445,8 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6404
6445
  });
6405
6446
  }
6406
6447
  notifyConditionalChanges(changes, afterCommit) {
6407
- if (changes.length === 0) {
6408
- afterCommit?.();
6409
- return;
6410
- }
6411
- let pending = changes.length;
6412
- const committed = () => {
6413
- pending -= 1;
6414
- if (pending === 0) afterCommit?.();
6415
- };
6416
- reactDom.flushSync(() => {
6417
- for (const change of changes) {
6418
- const refresh = this.conditionalListeners.get(change.key)?.get(change.id);
6419
- if (refresh) refresh(change.item, change.index, committed);
6420
- else committed();
6421
- }
6422
- });
6448
+ if (changes.length === 0) afterCommit?.();
6449
+ else options.conditionals.notify(this.conditionalListeners, changes, afterCommit);
6423
6450
  }
6424
6451
  refreshDirtyBindings(dirtyState, afterCommit) {
6425
6452
  if (!this.mounted || !this.root || this.state.fallback || this.hasReactOwnedRows() || this.currentProps.hostBlocks || !this.currentProps.structureDependencies || this.currentProps.structureDependencies.some((dependency) => dirtyState.has(dependency)) || this.currentProps.bindings.some((binding) => binding.dependencies === void 0)) {
@@ -6500,7 +6527,8 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6500
6527
  index += 1;
6501
6528
  }
6502
6529
  const shouldPrepareBindings = rows.items.length > 1 && this.currentProps.bindings.length > 0 && !this.currentProps.hostBlocks;
6503
- const preparedBindings = shouldPrepareBindings ? prepareKeyedRowBindingSetUpdates(this.currentProps, this.instances, rows) : void 0;
6530
+ const ordered = [...this.instances.values()];
6531
+ const preparedBindings = shouldPrepareBindings ? prepareKeyedRowBindingSetUpdates(this.currentProps, this.instances, rows, ordered) : void 0;
6504
6532
  if (shouldPrepareBindings && !preparedBindings) {
6505
6533
  this.activateFallback(afterCommit);
6506
6534
  return true;
@@ -6508,8 +6536,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6508
6536
  const conditionalChanges = [];
6509
6537
  for (index = 0; index < rows.items.length; index += 1) {
6510
6538
  const key = rows.keys[index];
6511
- const existing = this.instances.get(key);
6512
- if (!existing) return false;
6539
+ const existing = ordered[index];
6513
6540
  if (this.currentProps.hostBlocks) {
6514
6541
  const descriptor = this.currentProps.create(rows.items[index], index);
6515
6542
  if (!existing.scope?.update(descriptor)) {
@@ -6546,6 +6573,39 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6546
6573
  this.notifyConditionalChanges(conditionalChanges, afterCommit);
6547
6574
  return true;
6548
6575
  }
6576
+ // Keys are the committed keys plus new ones: patch every existing row like
6577
+ // the complete path does, then create and append only the new rows.
6578
+ reconcileAppendedRows(rows, afterCommit, dirtyState) {
6579
+ const root = this.root;
6580
+ let index = 0;
6581
+ for (const existing of this.instances.values()) {
6582
+ applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
6583
+ existing.item = rows.items[index];
6584
+ existing.index = index;
6585
+ index += 1;
6586
+ }
6587
+ const appended = [];
6588
+ for (; index < rows.items.length; index += 1) {
6589
+ appended.push(
6590
+ createKeyedRowInstance(
6591
+ this.currentProps,
6592
+ root.ownerDocument,
6593
+ rows.keys[index],
6594
+ rows.items[index],
6595
+ index
6596
+ )
6597
+ );
6598
+ }
6599
+ const indexElements = this.elementIndexComplete && this.usesDelegatedEvents();
6600
+ for (const instance of appended) {
6601
+ root.appendChild(instance.element);
6602
+ this.instances.set(instance.key, instance);
6603
+ if (indexElements) this.instancesByElement.set(instance.element, instance);
6604
+ }
6605
+ if (!indexElements) this.rebuildElementIndex(this.instances);
6606
+ this.commitCurrentCollection(dirtyState);
6607
+ afterCommit?.();
6608
+ }
6549
6609
  reconcileRemovals(rows, afterCommit, dirtyState) {
6550
6610
  if (this.hasReactOwnedRows() || rows.keys.length >= this.instances.size) return false;
6551
6611
  const removed = [];
@@ -6648,6 +6708,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6648
6708
  this.root.replaceChildren();
6649
6709
  this.instances = /* @__PURE__ */ new Map();
6650
6710
  this.instancesByElement = /* @__PURE__ */ new WeakMap();
6711
+ this.elementIndexComplete = true;
6651
6712
  this.eventHandlers.clear();
6652
6713
  this.conditionalListeners.clear();
6653
6714
  this.commitCurrentCollection(dirtyState);
@@ -6656,7 +6717,11 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6656
6717
  }
6657
6718
  if (this.reconcileStableRows(rows, afterCommit, dirtyState)) return;
6658
6719
  if (this.reconcileRemovals(rows, afterCommit, dirtyState)) return;
6659
- const nextKeys = new Set(rows.keys);
6720
+ if (rows.appended && !this.currentProps.hostBlocks) {
6721
+ this.reconcileAppendedRows(rows, afterCommit, dirtyState);
6722
+ return;
6723
+ }
6724
+ const nextKeys = rows.keySet ?? new Set(rows.keys);
6660
6725
  const hasSurvivingRows = rows.keys.some((key) => this.instances.has(key));
6661
6726
  const preparedBindings = nextKeys.size < this.instances.size && this.currentProps.bindings.length > 0 && !this.currentProps.hostBlocks && rows.keys.every((key) => this.instances.has(key)) ? prepareKeyedRowBindingSetUpdates(this.currentProps, this.instances, rows) : null;
6662
6727
  if (preparedBindings === void 0) {
@@ -6665,7 +6730,8 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6665
6730
  }
6666
6731
  const oldIndices = /* @__PURE__ */ new Map();
6667
6732
  if (hasSurvivingRows) {
6668
- [...this.instances].forEach(([key], index) => oldIndices.set(key, index));
6733
+ let oldIndex = 0;
6734
+ for (const key of this.instances.keys()) oldIndices.set(key, oldIndex++);
6669
6735
  }
6670
6736
  for (const [key, instance] of this.instances) {
6671
6737
  if (!nextKeys.has(key)) {
@@ -6673,7 +6739,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6673
6739
  if (hasSurvivingRows) instance.element.remove();
6674
6740
  }
6675
6741
  }
6676
- const sequence = hasSurvivingRows ? rows.keys.map((key) => oldIndices.get(key) ?? -1) : rows.keys.map(() => -1);
6742
+ const sequence = hasSurvivingRows ? rows.keys.map((key) => oldIndices.get(key) ?? -1) : [];
6677
6743
  const nextInstances = [];
6678
6744
  const conditionalChanges = [];
6679
6745
  for (let index = 0; index < rows.items.length; index += 1) {
@@ -6717,10 +6783,26 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6717
6783
  nextInstances.push(existing);
6718
6784
  continue;
6719
6785
  }
6786
+ if (!this.currentProps.hostBlocks) {
6787
+ const instance = createKeyedRowInstance(
6788
+ this.currentProps,
6789
+ this.root.ownerDocument,
6790
+ key,
6791
+ rows.items[index],
6792
+ index
6793
+ );
6794
+ instance.conditionalValues = this.readConditionalValues(
6795
+ this.currentProps,
6796
+ rows.items[index],
6797
+ index
6798
+ );
6799
+ nextInstances.push(instance);
6800
+ continue;
6801
+ }
6720
6802
  const descriptor = this.currentProps.create(rows.items[index], index);
6721
6803
  const element = createCompilerHostElement(this.root.ownerDocument, descriptor);
6722
6804
  const scope = this.mountRowHostScope(element, descriptor);
6723
- if (this.currentProps.hostBlocks && !scope) {
6805
+ if (!scope) {
6724
6806
  for (const instance of nextInstances) {
6725
6807
  if (!this.instances.has(instance.key)) instance.scope?.cleanup();
6726
6808
  }
@@ -6742,14 +6824,21 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6742
6824
  });
6743
6825
  }
6744
6826
  if (!hasSurvivingRows) {
6745
- const fragment = this.root.ownerDocument.createDocumentFragment();
6746
- for (const instance of nextInstances) fragment.append(instance.element);
6747
- this.root.replaceChildren(fragment);
6827
+ this.root.replaceChildren();
6828
+ for (const instance of nextInstances) this.root.appendChild(instance.element);
6748
6829
  } else {
6749
6830
  reorderCompilerKeyedRows(this.root, nextInstances, sequence, null);
6750
6831
  }
6751
6832
  this.instances = keyedRowInstancesByKey(nextInstances);
6752
- this.rebuildElementIndex(this.instances);
6833
+ if (hasSurvivingRows && this.elementIndexComplete && this.usesDelegatedEvents()) {
6834
+ for (let index = 0; index < nextInstances.length; index += 1) {
6835
+ if (sequence[index] < 0) {
6836
+ this.instancesByElement.set(nextInstances[index].element, nextInstances[index]);
6837
+ }
6838
+ }
6839
+ } else {
6840
+ this.rebuildElementIndex(this.instances);
6841
+ }
6753
6842
  this.pruneEventHandlers();
6754
6843
  this.pruneConditionalListeners();
6755
6844
  this.commitCurrentCollection(dirtyState);
@@ -6787,6 +6876,10 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6787
6876
  }
6788
6877
  if (nextState.fallback || this.state.fallback) return true;
6789
6878
  if (definitionChanged || wasReactOwned || willBeReactOwned) {
6879
+ const elements = this.root?.children;
6880
+ if (elements && (elements.length !== this.reactElements.length || this.reactElements.some((element, index) => element !== elements[index]))) {
6881
+ this.fallbackVersion += 1;
6882
+ }
6790
6883
  this.eventHandlers.clear();
6791
6884
  return true;
6792
6885
  }
@@ -6815,8 +6908,10 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6815
6908
  this.id = void 0;
6816
6909
  this.cleanupHostScopes();
6817
6910
  this.instances.clear();
6911
+ this.reactElements = [];
6818
6912
  this.keyedTargets?.clear();
6819
6913
  this.instancesByElement = /* @__PURE__ */ new WeakMap();
6914
+ this.elementIndexComplete = true;
6820
6915
  this.eventHandlers.clear();
6821
6916
  this.conditionalListeners.clear();
6822
6917
  }
@@ -6830,7 +6925,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6830
6925
  }
6831
6926
  return React__default.default.cloneElement(container, {
6832
6927
  ...this.delegatedContainerProps(container),
6833
- key: this.state.fallback ? `react-${this.fallbackVersion}` : "compiled",
6928
+ key: `${this.state.fallback ? "react" : "compiled"}-${this.fallbackVersion}`,
6834
6929
  ref: this.captureRoot
6835
6930
  });
6836
6931
  }
@@ -6968,25 +7063,16 @@ function createKeyedRangesBlockComponent(owner) {
6968
7063
  nextInstances.push(existing);
6969
7064
  continue;
6970
7065
  }
6971
- const element = createCompilerHostElement(
6972
- this.root.ownerDocument,
6973
- range.create(rows.items[index], index)
7066
+ nextInstances.push(
7067
+ createKeyedRowInstance(range, this.root.ownerDocument, key, rows.items[index], index)
6974
7068
  );
6975
- nextInstances.push({
6976
- key,
6977
- element,
6978
- values: readKeyedRowBindingValues(range, rows.items[index], index),
6979
- item: rows.items[index],
6980
- index,
6981
- conditionalValues: /* @__PURE__ */ new Map()
6982
- });
6983
7069
  }
6984
7070
  let anchor = this.anchorAfter(rangeIndex);
6985
7071
  for (let index = nextInstances.length - 1; index >= 0; index -= 1) {
6986
7072
  const instance = nextInstances[index];
6987
7073
  if (sequence[index] < 0) {
6988
7074
  this.root.insertBefore(instance.element, anchor);
6989
- } else if (!stablePositions.has(index) && instance.element.nextSibling !== anchor) {
7075
+ } else if (!stablePositions[index] && instance.element.nextSibling !== anchor) {
6990
7076
  this.root.insertBefore(instance.element, anchor);
6991
7077
  }
6992
7078
  anchor = instance.element;