|
|
@ -3,7 +3,6 @@ import {
|
|
|
|
EACH_IS_ANIMATED,
|
|
|
|
EACH_IS_ANIMATED,
|
|
|
|
EACH_IS_CONTROLLED,
|
|
|
|
EACH_IS_CONTROLLED,
|
|
|
|
EACH_IS_IMMUTABLE,
|
|
|
|
EACH_IS_IMMUTABLE,
|
|
|
|
EACH_IS_PROXIED,
|
|
|
|
|
|
|
|
EACH_ITEM_REACTIVE,
|
|
|
|
EACH_ITEM_REACTIVE,
|
|
|
|
EACH_KEYED
|
|
|
|
EACH_KEYED
|
|
|
|
} from '../../constants.js';
|
|
|
|
} from '../../constants.js';
|
|
|
@ -21,6 +20,7 @@ import { empty } from './render.js';
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
destroy_signal,
|
|
|
|
destroy_signal,
|
|
|
|
execute_effect,
|
|
|
|
execute_effect,
|
|
|
|
|
|
|
|
is_lazy_property,
|
|
|
|
lazy_property,
|
|
|
|
lazy_property,
|
|
|
|
mutable_source,
|
|
|
|
mutable_source,
|
|
|
|
push_destroy_fn,
|
|
|
|
push_destroy_fn,
|
|
|
@ -36,6 +36,8 @@ const NEW_BLOCK = -1;
|
|
|
|
const MOVED_BLOCK = 99999999;
|
|
|
|
const MOVED_BLOCK = 99999999;
|
|
|
|
const LIS_BLOCK = -2;
|
|
|
|
const LIS_BLOCK = -2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function no_op() {}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @template V
|
|
|
|
* @template V
|
|
|
|
* @param {Element | Comment} anchor_node
|
|
|
|
* @param {Element | Comment} anchor_node
|
|
|
@ -128,6 +130,8 @@ function each(anchor_node, collection, flags, key_fn, render_fn, fallback_fn, re
|
|
|
|
: Array.from(maybe_array);
|
|
|
|
: Array.from(maybe_array);
|
|
|
|
if (key_fn !== null) {
|
|
|
|
if (key_fn !== null) {
|
|
|
|
keys = array.map(key_fn);
|
|
|
|
keys = array.map(key_fn);
|
|
|
|
|
|
|
|
} else if ((flags & EACH_KEYED) === 0) {
|
|
|
|
|
|
|
|
array.map(no_op);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const length = array.length;
|
|
|
|
const length = array.length;
|
|
|
|
if (fallback_fn !== null) {
|
|
|
|
if (fallback_fn !== null) {
|
|
|
@ -245,7 +249,6 @@ function reconcile_indexed_array(
|
|
|
|
|
|
|
|
|
|
|
|
if (is_proxied_array) {
|
|
|
|
if (is_proxied_array) {
|
|
|
|
flags &= ~EACH_ITEM_REACTIVE;
|
|
|
|
flags &= ~EACH_ITEM_REACTIVE;
|
|
|
|
flags |= EACH_IS_PROXIED;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {number | void} */
|
|
|
|
/** @type {number | void} */
|
|
|
@ -282,7 +285,7 @@ function reconcile_indexed_array(
|
|
|
|
var hydrating_node = current_hydration_fragment[0];
|
|
|
|
var hydrating_node = current_hydration_fragment[0];
|
|
|
|
for (; index < length; index++) {
|
|
|
|
for (; index < length; index++) {
|
|
|
|
// Hydrate block
|
|
|
|
// Hydrate block
|
|
|
|
item = array[index];
|
|
|
|
item = is_proxied_array ? lazy_property(array, index) : array[index];
|
|
|
|
var fragment = /** @type {Array<Text | Comment | Element>} */ (
|
|
|
|
var fragment = /** @type {Array<Text | Comment | Element>} */ (
|
|
|
|
get_hydration_fragment(hydrating_node)
|
|
|
|
get_hydration_fragment(hydrating_node)
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -290,15 +293,15 @@ function reconcile_indexed_array(
|
|
|
|
hydrating_node = /** @type {Node} */ (
|
|
|
|
hydrating_node = /** @type {Node} */ (
|
|
|
|
/** @type {Node} */ (/** @type {Node} */ (fragment.at(-1)).nextSibling).nextSibling
|
|
|
|
/** @type {Node} */ (/** @type {Node} */ (fragment.at(-1)).nextSibling).nextSibling
|
|
|
|
);
|
|
|
|
);
|
|
|
|
block = each_item_block(array, item, null, index, render_fn, flags);
|
|
|
|
block = each_item_block(item, null, index, render_fn, flags);
|
|
|
|
b_blocks[index] = block;
|
|
|
|
b_blocks[index] = block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
for (; index < length; index++) {
|
|
|
|
for (; index < length; index++) {
|
|
|
|
if (index >= a) {
|
|
|
|
if (index >= a) {
|
|
|
|
// Add block
|
|
|
|
// Add block
|
|
|
|
item = array[index];
|
|
|
|
item = is_proxied_array ? lazy_property(array, index) : array[index];
|
|
|
|
block = each_item_block(array, item, null, index, render_fn, flags);
|
|
|
|
block = each_item_block(item, null, index, render_fn, flags);
|
|
|
|
b_blocks[index] = block;
|
|
|
|
b_blocks[index] = block;
|
|
|
|
insert_each_item_block(block, dom, is_controlled, null);
|
|
|
|
insert_each_item_block(block, dom, is_controlled, null);
|
|
|
|
} else if (index >= b) {
|
|
|
|
} else if (index >= b) {
|
|
|
@ -353,7 +356,6 @@ function reconcile_tracked_array(
|
|
|
|
|
|
|
|
|
|
|
|
if (is_proxied_array) {
|
|
|
|
if (is_proxied_array) {
|
|
|
|
flags &= ~EACH_ITEM_REACTIVE;
|
|
|
|
flags &= ~EACH_ITEM_REACTIVE;
|
|
|
|
flags |= EACH_IS_PROXIED;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {number | void} */
|
|
|
|
/** @type {number | void} */
|
|
|
@ -406,7 +408,7 @@ function reconcile_tracked_array(
|
|
|
|
hydrating_node = /** @type {Node} */ (
|
|
|
|
hydrating_node = /** @type {Node} */ (
|
|
|
|
/** @type {Node} */ ((fragment.at(-1) || hydrating_node).nextSibling).nextSibling
|
|
|
|
/** @type {Node} */ ((fragment.at(-1) || hydrating_node).nextSibling).nextSibling
|
|
|
|
);
|
|
|
|
);
|
|
|
|
block = each_item_block(array, item, key, idx, render_fn, flags);
|
|
|
|
block = each_item_block(item, key, idx, render_fn, flags);
|
|
|
|
b_blocks[idx] = block;
|
|
|
|
b_blocks[idx] = block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (a === 0) {
|
|
|
|
} else if (a === 0) {
|
|
|
@ -415,7 +417,7 @@ function reconcile_tracked_array(
|
|
|
|
idx = b_end - --b;
|
|
|
|
idx = b_end - --b;
|
|
|
|
item = array[idx];
|
|
|
|
item = array[idx];
|
|
|
|
key = is_computed_key ? keys[idx] : item;
|
|
|
|
key = is_computed_key ? keys[idx] : item;
|
|
|
|
block = each_item_block(array, item, key, idx, render_fn, flags);
|
|
|
|
block = each_item_block(item, key, idx, render_fn, flags);
|
|
|
|
b_blocks[idx] = block;
|
|
|
|
b_blocks[idx] = block;
|
|
|
|
insert_each_item_block(block, dom, is_controlled, null);
|
|
|
|
insert_each_item_block(block, dom, is_controlled, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -463,7 +465,7 @@ function reconcile_tracked_array(
|
|
|
|
while (b_end >= start) {
|
|
|
|
while (b_end >= start) {
|
|
|
|
item = array[b_end];
|
|
|
|
item = array[b_end];
|
|
|
|
key = is_computed_key ? keys[b_end] : item;
|
|
|
|
key = is_computed_key ? keys[b_end] : item;
|
|
|
|
block = each_item_block(array, item, key, b_end, render_fn, flags);
|
|
|
|
block = each_item_block(item, key, b_end, render_fn, flags);
|
|
|
|
b_blocks[b_end--] = block;
|
|
|
|
b_blocks[b_end--] = block;
|
|
|
|
sibling = insert_each_item_block(block, dom, is_controlled, sibling);
|
|
|
|
sibling = insert_each_item_block(block, dom, is_controlled, sibling);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -525,7 +527,7 @@ function reconcile_tracked_array(
|
|
|
|
item = array[b_end];
|
|
|
|
item = array[b_end];
|
|
|
|
if (should_create) {
|
|
|
|
if (should_create) {
|
|
|
|
key = is_computed_key ? keys[b_end] : item;
|
|
|
|
key = is_computed_key ? keys[b_end] : item;
|
|
|
|
block = each_item_block(array, item, key, b_end, render_fn, flags);
|
|
|
|
block = each_item_block(item, key, b_end, render_fn, flags);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
block = b_blocks[b_end];
|
|
|
|
block = b_blocks[b_end];
|
|
|
|
if (!is_animated && should_update_block) {
|
|
|
|
if (!is_animated && should_update_block) {
|
|
|
@ -708,6 +710,8 @@ function get_first_element(block) {
|
|
|
|
function update_each_item_block(block, item, index, type) {
|
|
|
|
function update_each_item_block(block, item, index, type) {
|
|
|
|
if ((type & EACH_ITEM_REACTIVE) !== 0) {
|
|
|
|
if ((type & EACH_ITEM_REACTIVE) !== 0) {
|
|
|
|
set_signal_value(block.v, item);
|
|
|
|
set_signal_value(block.v, item);
|
|
|
|
|
|
|
|
} else if (is_lazy_property(block.v)) {
|
|
|
|
|
|
|
|
block.v.o[block.v.p] = item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const transitions = block.s;
|
|
|
|
const transitions = block.s;
|
|
|
|
const index_is_reactive = (type & EACH_INDEX_REACTIVE) !== 0;
|
|
|
|
const index_is_reactive = (type & EACH_INDEX_REACTIVE) !== 0;
|
|
|
@ -764,21 +768,19 @@ export function destroy_each_item_block(
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @template V
|
|
|
|
* @template V
|
|
|
|
* @param {V[]} array
|
|
|
|
* @template O
|
|
|
|
* @param {V} item
|
|
|
|
* @template P
|
|
|
|
|
|
|
|
* @param {V | import('./types.js').LazyProperty<O, P>} item
|
|
|
|
* @param {unknown} key
|
|
|
|
* @param {unknown} key
|
|
|
|
* @param {number} index
|
|
|
|
* @param {number} index
|
|
|
|
* @param {(anchor: null, item: V, index: number | import('./types.js').Signal<number>) => void} render_fn
|
|
|
|
* @param {(anchor: null, item: V, index: number | import('./types.js').Signal<number>) => void} render_fn
|
|
|
|
* @param {number} flags
|
|
|
|
* @param {number} flags
|
|
|
|
* @returns {import('./types.js').EachItemBlock}
|
|
|
|
* @returns {import('./types.js').EachItemBlock}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
function each_item_block(array, item, key, index, render_fn, flags) {
|
|
|
|
function each_item_block(item, key, index, render_fn, flags) {
|
|
|
|
const each_item_not_reactive = (flags & EACH_ITEM_REACTIVE) === 0;
|
|
|
|
const each_item_not_reactive = (flags & EACH_ITEM_REACTIVE) === 0;
|
|
|
|
|
|
|
|
|
|
|
|
const item_value =
|
|
|
|
const item_value = each_item_not_reactive
|
|
|
|
(flags & EACH_IS_PROXIED) !== 0 && (flags & EACH_KEYED) === 0
|
|
|
|
|
|
|
|
? lazy_property(array, index)
|
|
|
|
|
|
|
|
: each_item_not_reactive
|
|
|
|
|
|
|
|
? item
|
|
|
|
? item
|
|
|
|
: (flags & EACH_IS_IMMUTABLE) === 0
|
|
|
|
: (flags & EACH_IS_IMMUTABLE) === 0
|
|
|
|
? mutable_source(item)
|
|
|
|
? mutable_source(item)
|
|
|
|