@estjs/template 0.0.17-beta.6 → 0.0.17
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/template.cjs +2 -2
- package/dist/template.d.cts +2 -0
- package/dist/template.d.ts +2 -0
- package/dist/template.dev.cjs +462 -175
- package/dist/template.dev.cjs.map +1 -1
- package/dist/template.dev.js +463 -176
- package/dist/template.dev.js.map +1 -1
- package/dist/template.js +2 -2
- package/package.json +5 -5
package/dist/template.dev.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getActiveScope, runWithScope, onCleanup, __objRest, createScope, disposeScope, __async } from './chunk-PYFF2HI3.dev.js';
|
|
2
2
|
import { normalizeClassName, SPREAD_NAME, isObject, warn, startsWith, isSpecialBooleanAttr, isBooleanAttr, includeBooleanAttr, isSymbol, isString, isArray, kebabCase, camelCase, capitalize, HYDRATION_ANCHOR_ATTR, isBrowser, error, isPromise, isFunction, isOn, coerceArray, isNumber } from '@estjs/shared';
|
|
3
|
-
import { effect, shallowReactive, isSignal, isComputed, isReactive, signal } from '@estjs/signals';
|
|
3
|
+
import { effect, shallowReactive, isSignal, isComputed, isReactive, signal, untrack } from '@estjs/signals';
|
|
4
4
|
|
|
5
5
|
var REF_KEY = "ref";
|
|
6
6
|
var KEY_PROP = "key";
|
|
@@ -14,6 +14,24 @@ var FOR_COMPONENT = /* @__PURE__ */ Symbol("For Component" );
|
|
|
14
14
|
var TRANSITION_COMPONENT = /* @__PURE__ */ Symbol("Transition Component" );
|
|
15
15
|
var TRANSITION_GROUP_COMPONENT = /* @__PURE__ */ Symbol("TransitionGroup Component" );
|
|
16
16
|
var DANGEROUS_DATA_MIME_RE = /^data:\s*(?:text\/html|text\/xml|application\/xhtml\+xml|image\/svg\+xml|application\/xml)/;
|
|
17
|
+
var BOOLEAN_PROPERTY_ALIASES = {
|
|
18
|
+
allowfullscreen: "allowFullscreen",
|
|
19
|
+
formnovalidate: "formNoValidate",
|
|
20
|
+
ismap: "isMap",
|
|
21
|
+
nomodule: "noModule",
|
|
22
|
+
novalidate: "noValidate",
|
|
23
|
+
readonly: "readOnly"
|
|
24
|
+
};
|
|
25
|
+
function syncBooleanProperty(el, key, value) {
|
|
26
|
+
var _a2;
|
|
27
|
+
if (el.namespaceURI === SVG_NAMESPACE) return;
|
|
28
|
+
const prop = (_a2 = BOOLEAN_PROPERTY_ALIASES[key.toLowerCase()]) != null ? _a2 : key;
|
|
29
|
+
if (!(prop in el) || typeof el[prop] !== "boolean") return;
|
|
30
|
+
try {
|
|
31
|
+
el[prop] = value;
|
|
32
|
+
} catch (e) {
|
|
33
|
+
}
|
|
34
|
+
}
|
|
17
35
|
function isUnsafeUrl(value) {
|
|
18
36
|
const v = value.replaceAll(/[\u0000-\u0020]+/g, "").toLowerCase();
|
|
19
37
|
if (startsWith(v, "javascript:") || startsWith(v, "vbscript:")) {
|
|
@@ -90,14 +108,19 @@ function patchAttr(el, key, prev, next2) {
|
|
|
90
108
|
} else {
|
|
91
109
|
el.removeAttribute(key);
|
|
92
110
|
}
|
|
111
|
+
if (isBoolean || lowerKey === "indeterminate") {
|
|
112
|
+
syncBooleanProperty(el, key, false);
|
|
113
|
+
}
|
|
93
114
|
return;
|
|
94
115
|
}
|
|
95
116
|
if (isBoolean) {
|
|
96
|
-
|
|
117
|
+
const included = includeBooleanAttr(next2);
|
|
118
|
+
if (included) {
|
|
97
119
|
el.setAttribute(key, "");
|
|
98
120
|
} else {
|
|
99
121
|
el.removeAttribute(key);
|
|
100
122
|
}
|
|
123
|
+
syncBooleanProperty(el, key, included);
|
|
101
124
|
return;
|
|
102
125
|
}
|
|
103
126
|
const attrValue = isSymbol(next2) ? String(next2) : next2;
|
|
@@ -326,19 +349,31 @@ function endHydration() {
|
|
|
326
349
|
_teleportTargetStarts.clear();
|
|
327
350
|
}
|
|
328
351
|
function claimHydratedNodes(parent, expected, before) {
|
|
329
|
-
var _a2, _b;
|
|
352
|
+
var _a2, _b, _c;
|
|
330
353
|
if (!_isHydrating || before && before.parentNode !== parent) return null;
|
|
331
354
|
if (expected.length === 0) return [];
|
|
332
355
|
const claimed = new Array(expected.length);
|
|
333
356
|
let cursor = before ? before.previousSibling : parent.lastChild;
|
|
334
357
|
for (let i = expected.length - 1; i >= 0; i--) {
|
|
335
|
-
if (!cursor) return null;
|
|
336
358
|
const expectedNode = expected[i];
|
|
337
359
|
const expectedType = expectedNode.nodeType;
|
|
338
360
|
if (expectedType === Node.TEXT_NODE) {
|
|
339
361
|
const expectedText = (_a2 = expectedNode.textContent) != null ? _a2 : "";
|
|
340
|
-
if (
|
|
341
|
-
|
|
362
|
+
if (expectedText === "") {
|
|
363
|
+
if ((cursor == null ? void 0 : cursor.nodeType) === Node.TEXT_NODE && ((_b = cursor.textContent) != null ? _b : "") === "") {
|
|
364
|
+
claimed[i] = cursor;
|
|
365
|
+
cursor = cursor.previousSibling;
|
|
366
|
+
} else {
|
|
367
|
+
const emptyNode = document.createTextNode("");
|
|
368
|
+
const anchor = i + 1 < expected.length ? claimed[i + 1] : before != null ? before : null;
|
|
369
|
+
parent.insertBefore(emptyNode, anchor);
|
|
370
|
+
claimed[i] = emptyNode;
|
|
371
|
+
}
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
if (!cursor) return null;
|
|
375
|
+
if (cursor.nodeType !== Node.TEXT_NODE) return null;
|
|
376
|
+
const existingText = (_c = cursor.textContent) != null ? _c : "";
|
|
342
377
|
if (existingText === expectedText) {
|
|
343
378
|
claimed[i] = cursor;
|
|
344
379
|
cursor = cursor.previousSibling;
|
|
@@ -354,6 +389,7 @@ function claimHydratedNodes(parent, expected, before) {
|
|
|
354
389
|
cursor = prefixNode;
|
|
355
390
|
continue;
|
|
356
391
|
}
|
|
392
|
+
if (!cursor) return null;
|
|
357
393
|
if (cursor.nodeType !== expectedType) return null;
|
|
358
394
|
if (expectedType === Node.ELEMENT_NODE) {
|
|
359
395
|
if (cursor.tagName !== expectedNode.tagName) return null;
|
|
@@ -661,6 +697,8 @@ function insert(parent, nodeFactory, before) {
|
|
|
661
697
|
const effectRunner = effect(() => {
|
|
662
698
|
const executeUpdate = () => {
|
|
663
699
|
const rawNodes = isFunction(nodeFactory) ? nodeFactory() : nodeFactory;
|
|
700
|
+
const rawType = typeof rawNodes;
|
|
701
|
+
const canPatchText = rawNodes == null || rawType === "string" || rawType === "number" || rawType === "boolean" || rawType === "symbol";
|
|
664
702
|
const nodes = resolveNodes(rawNodes);
|
|
665
703
|
if (isFirstRun && isHydrating() && nodes.every((node) => node instanceof Node && node.parentNode === parent)) {
|
|
666
704
|
renderedNodes = nodes;
|
|
@@ -675,6 +713,13 @@ function insert(parent, nodeFactory, before) {
|
|
|
675
713
|
return;
|
|
676
714
|
}
|
|
677
715
|
}
|
|
716
|
+
if (canPatchText && renderedNodes.length === 1 && nodes.length === 1 && renderedNodes[0].nodeType === Node.TEXT_NODE && nodes[0].nodeType === Node.TEXT_NODE) {
|
|
717
|
+
const current = renderedNodes[0];
|
|
718
|
+
const nextText = nodes[0].textContent;
|
|
719
|
+
if (current.textContent !== nextText) current.textContent = nextText;
|
|
720
|
+
isFirstRun = false;
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
678
723
|
renderedNodes = reconcileArrays(parent, renderedNodes, nodes, before);
|
|
679
724
|
isFirstRun = false;
|
|
680
725
|
};
|
|
@@ -721,7 +766,7 @@ function addEvent(el, event, handler, options) {
|
|
|
721
766
|
const selector = options.delegate;
|
|
722
767
|
const wrappedHandler = (e) => {
|
|
723
768
|
const target = e.target;
|
|
724
|
-
if (target.
|
|
769
|
+
if (target.closest(selector)) {
|
|
725
770
|
handler.call(el, e);
|
|
726
771
|
}
|
|
727
772
|
};
|
|
@@ -822,17 +867,18 @@ function triggerUpdateHooks(scope) {
|
|
|
822
867
|
|
|
823
868
|
// src/component.ts
|
|
824
869
|
function syncDescriptors(target, source, pruneMissing = false) {
|
|
825
|
-
|
|
870
|
+
const sourceKeys = Reflect.ownKeys(source);
|
|
871
|
+
for (const key of sourceKeys) {
|
|
826
872
|
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
827
873
|
}
|
|
828
874
|
if (pruneMissing) {
|
|
829
|
-
const sourceKeySet = new Set(
|
|
830
|
-
for (const key of
|
|
875
|
+
const sourceKeySet = new Set(sourceKeys);
|
|
876
|
+
for (const key of Reflect.ownKeys(target)) {
|
|
831
877
|
if (!sourceKeySet.has(key)) delete target[key];
|
|
832
878
|
}
|
|
833
879
|
}
|
|
834
880
|
}
|
|
835
|
-
function
|
|
881
|
+
function readDescriptorValue(source, key) {
|
|
836
882
|
const descriptor = Object.getOwnPropertyDescriptor(source, key);
|
|
837
883
|
return descriptor.get ? descriptor.get.call(source) : descriptor.value;
|
|
838
884
|
}
|
|
@@ -851,9 +897,9 @@ var Component = class {
|
|
|
851
897
|
this.parentNode = void 0;
|
|
852
898
|
this.rootEventCleanups = [];
|
|
853
899
|
this.parentScope = getActiveScope();
|
|
854
|
-
const
|
|
855
|
-
syncDescriptors(
|
|
856
|
-
this.reactiveProps = shallowReactive(
|
|
900
|
+
const reactiveProps = /* @__PURE__ */ Object.create(null);
|
|
901
|
+
syncDescriptors(reactiveProps, props);
|
|
902
|
+
this.reactiveProps = shallowReactive(reactiveProps);
|
|
857
903
|
}
|
|
858
904
|
/**
|
|
859
905
|
* Mount the component into `parentNode` (optionally before `beforeNode`).
|
|
@@ -901,14 +947,14 @@ var Component = class {
|
|
|
901
947
|
*/
|
|
902
948
|
update(props) {
|
|
903
949
|
this.props = props;
|
|
904
|
-
const scope = this.scope;
|
|
905
|
-
if (!scope || scope.isDestroyed) return;
|
|
906
950
|
syncDescriptors(
|
|
907
951
|
this.reactiveProps,
|
|
908
952
|
props != null ? props : {},
|
|
909
953
|
/* pruneMissing */
|
|
910
954
|
true
|
|
911
955
|
);
|
|
956
|
+
const scope = this.scope;
|
|
957
|
+
if (!scope || scope.isDestroyed) return;
|
|
912
958
|
this.syncSpecialProps(props);
|
|
913
959
|
triggerUpdateHooks(scope);
|
|
914
960
|
}
|
|
@@ -920,7 +966,10 @@ var Component = class {
|
|
|
920
966
|
if (!this.parentNode) return;
|
|
921
967
|
const parent = this.parentNode;
|
|
922
968
|
const before = this.beforeNode;
|
|
969
|
+
const savedProps = /* @__PURE__ */ Object.create(null);
|
|
970
|
+
syncDescriptors(savedProps, this.reactiveProps);
|
|
923
971
|
this.destroy();
|
|
972
|
+
syncDescriptors(this.reactiveProps, savedProps);
|
|
924
973
|
this.mount(parent, before);
|
|
925
974
|
}
|
|
926
975
|
/**
|
|
@@ -937,7 +986,7 @@ var Component = class {
|
|
|
937
986
|
this.renderedNodes = [];
|
|
938
987
|
this.firstChild = void 0;
|
|
939
988
|
this.parentNode = void 0;
|
|
940
|
-
for (const key of
|
|
989
|
+
for (const key of Reflect.ownKeys(this.reactiveProps)) {
|
|
941
990
|
delete this.reactiveProps[key];
|
|
942
991
|
}
|
|
943
992
|
this.state = 0 /* INITIAL */;
|
|
@@ -950,38 +999,51 @@ var Component = class {
|
|
|
950
999
|
*/
|
|
951
1000
|
syncSpecialProps(props) {
|
|
952
1001
|
if (!props) return;
|
|
953
|
-
const
|
|
954
|
-
if (
|
|
1002
|
+
const roots = this.getRootElements();
|
|
1003
|
+
if (roots.length === 0) return;
|
|
1004
|
+
const refRoot = roots[0];
|
|
955
1005
|
this.releaseSpecialProps();
|
|
956
|
-
for (const key of
|
|
1006
|
+
for (const key of Reflect.ownKeys(props)) {
|
|
1007
|
+
if (!isString(key)) continue;
|
|
957
1008
|
if (key === REF_KEY) {
|
|
958
|
-
const value =
|
|
959
|
-
this.rootRefCleanup = this.bindRootRef(value,
|
|
1009
|
+
const value = readDescriptorValue(props, key);
|
|
1010
|
+
this.rootRefCleanup = this.bindRootRef(value, refRoot);
|
|
960
1011
|
continue;
|
|
961
1012
|
}
|
|
962
1013
|
if (isOn(key)) {
|
|
963
|
-
const value =
|
|
1014
|
+
const value = readDescriptorValue(props, key);
|
|
964
1015
|
if (!isFunction(value)) continue;
|
|
965
1016
|
const eventName = key.slice(2).toLowerCase();
|
|
966
|
-
const
|
|
967
|
-
|
|
968
|
-
const prev = target[slot];
|
|
969
|
-
if (isFunction(prev)) {
|
|
970
|
-
target[slot] = value;
|
|
971
|
-
this.rootEventCleanups.push(() => {
|
|
972
|
-
if (target[slot] === value) target[slot] = prev;
|
|
973
|
-
});
|
|
974
|
-
continue;
|
|
1017
|
+
for (const root of roots) {
|
|
1018
|
+
this.bindRootEvent(root, eventName, value);
|
|
975
1019
|
}
|
|
976
|
-
const fn = value;
|
|
977
|
-
const handler = (event) => {
|
|
978
|
-
if (target.disabled) return;
|
|
979
|
-
fn.call(target, event);
|
|
980
|
-
};
|
|
981
|
-
this.rootEventCleanups.push(addEvent(target, eventName, handler));
|
|
982
1020
|
}
|
|
983
1021
|
}
|
|
984
1022
|
}
|
|
1023
|
+
getRootElements() {
|
|
1024
|
+
const roots = [];
|
|
1025
|
+
for (const node of this.renderedNodes) {
|
|
1026
|
+
if (node instanceof Element) roots.push(node);
|
|
1027
|
+
}
|
|
1028
|
+
return roots;
|
|
1029
|
+
}
|
|
1030
|
+
bindRootEvent(target, eventName, handler) {
|
|
1031
|
+
const slot = `_$${eventName}`;
|
|
1032
|
+
const prev = target[slot];
|
|
1033
|
+
if (isFunction(prev)) {
|
|
1034
|
+
target[slot] = handler;
|
|
1035
|
+
this.rootEventCleanups.push(() => {
|
|
1036
|
+
if (target[slot] === handler) target[slot] = prev;
|
|
1037
|
+
});
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
this.rootEventCleanups.push(
|
|
1041
|
+
addEvent(target, eventName, (event) => {
|
|
1042
|
+
if (target.disabled) return;
|
|
1043
|
+
handler.call(target, event);
|
|
1044
|
+
})
|
|
1045
|
+
);
|
|
1046
|
+
}
|
|
985
1047
|
/**
|
|
986
1048
|
* Remove all listeners/ref bindings currently attached to the root element.
|
|
987
1049
|
*/
|
|
@@ -1172,7 +1234,9 @@ function eventHandler(e) {
|
|
|
1172
1234
|
return true;
|
|
1173
1235
|
};
|
|
1174
1236
|
const walkUpTree = () => {
|
|
1175
|
-
while (handleNode() && (node = node._$host || node.parentNode || node.host))
|
|
1237
|
+
while (handleNode() && (node = node._$host || node.parentNode || node.host)) {
|
|
1238
|
+
if (node === oriCurrentTarget) break;
|
|
1239
|
+
}
|
|
1176
1240
|
};
|
|
1177
1241
|
Object.defineProperty(e, "currentTarget", {
|
|
1178
1242
|
configurable: true,
|
|
@@ -1183,26 +1247,30 @@ function eventHandler(e) {
|
|
|
1183
1247
|
return node || document;
|
|
1184
1248
|
}
|
|
1185
1249
|
});
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1250
|
+
try {
|
|
1251
|
+
if (e.composedPath) {
|
|
1252
|
+
const path = e.composedPath();
|
|
1253
|
+
reTargetEvent(e, path[0]);
|
|
1254
|
+
for (let i = 0; i < path.length - 2; i++) {
|
|
1255
|
+
node = path[i];
|
|
1256
|
+
if (!handleNode()) break;
|
|
1257
|
+
if (node._$host) {
|
|
1258
|
+
node = node._$host;
|
|
1259
|
+
walkUpTree();
|
|
1260
|
+
break;
|
|
1261
|
+
}
|
|
1262
|
+
if (node.parentNode === oriCurrentTarget) {
|
|
1263
|
+
break;
|
|
1264
|
+
}
|
|
1199
1265
|
}
|
|
1200
|
-
}
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1266
|
+
} else walkUpTree();
|
|
1267
|
+
} finally {
|
|
1268
|
+
reTargetEvent(e, oriTarget);
|
|
1269
|
+
}
|
|
1203
1270
|
}
|
|
1204
1271
|
var $EVENTS = /* @__PURE__ */ Symbol("_$EVENTS");
|
|
1205
1272
|
function delegateEvents(eventNames, document2 = globalThis.document) {
|
|
1273
|
+
if (!document2) return;
|
|
1206
1274
|
const docWithEvents = document2;
|
|
1207
1275
|
const eventSet = docWithEvents[$EVENTS] || (docWithEvents[$EVENTS] = /* @__PURE__ */ new Set());
|
|
1208
1276
|
for (const name of eventNames) {
|
|
@@ -1213,6 +1281,7 @@ function delegateEvents(eventNames, document2 = globalThis.document) {
|
|
|
1213
1281
|
}
|
|
1214
1282
|
}
|
|
1215
1283
|
function clearDelegatedEvents(document2 = globalThis.document) {
|
|
1284
|
+
if (!document2) return;
|
|
1216
1285
|
const docWithEvents = document2;
|
|
1217
1286
|
const eventSet = docWithEvents[$EVENTS];
|
|
1218
1287
|
if (eventSet) {
|
|
@@ -1235,6 +1304,7 @@ var EMPTY_FILES = (() => {
|
|
|
1235
1304
|
if (typeof DataTransfer !== "undefined") return new DataTransfer().files;
|
|
1236
1305
|
return [];
|
|
1237
1306
|
})();
|
|
1307
|
+
var checkboxArraySnapshots = /* @__PURE__ */ new WeakMap();
|
|
1238
1308
|
function writeValue(el, v) {
|
|
1239
1309
|
const target = el;
|
|
1240
1310
|
const next2 = v == null ? "" : String(v);
|
|
@@ -1351,11 +1421,16 @@ function bindElement(node, prop, getter, setter, modifiers = {}) {
|
|
|
1351
1421
|
const getModel = isFunction(getter) ? getter : () => getter;
|
|
1352
1422
|
const cast = shouldCast ? (v) => applyModifiers(v, trim, toNum) : IDENTITY;
|
|
1353
1423
|
const computeNext = checkboxArray ? (raw) => {
|
|
1424
|
+
var _a2;
|
|
1354
1425
|
const current = getModel();
|
|
1355
|
-
if (!isArray(current))
|
|
1426
|
+
if (!isArray(current)) {
|
|
1427
|
+
return cast(raw);
|
|
1428
|
+
}
|
|
1356
1429
|
const own = node.value;
|
|
1357
|
-
const
|
|
1430
|
+
const source = (_a2 = checkboxArraySnapshots.get(current)) != null ? _a2 : current;
|
|
1431
|
+
const next2 = source.filter((item) => String(item) !== own);
|
|
1358
1432
|
if (raw) next2.push(own);
|
|
1433
|
+
checkboxArraySnapshots.set(current, next2);
|
|
1359
1434
|
return next2;
|
|
1360
1435
|
} : cast;
|
|
1361
1436
|
let composing = false;
|
|
@@ -1382,6 +1457,9 @@ function bindElement(node, prop, getter, setter, modifiers = {}) {
|
|
|
1382
1457
|
}
|
|
1383
1458
|
const runner = effect(() => {
|
|
1384
1459
|
const value = getModel();
|
|
1460
|
+
if (checkboxArray) {
|
|
1461
|
+
if (isArray(value)) checkboxArraySnapshots.set(value, [...value]);
|
|
1462
|
+
}
|
|
1385
1463
|
if (ime && composing) return;
|
|
1386
1464
|
if (ime && !lazy && isFocused(node) && Object.is(cast(read(node)), value)) return;
|
|
1387
1465
|
write(node, value);
|
|
@@ -1392,7 +1470,7 @@ function bindElement(node, prop, getter, setter, modifiers = {}) {
|
|
|
1392
1470
|
}
|
|
1393
1471
|
function unwrapSlotValue(raw) {
|
|
1394
1472
|
let v = raw;
|
|
1395
|
-
if (
|
|
1473
|
+
if (isArray(v) && v.length === 1) v = v[0];
|
|
1396
1474
|
return isFunction(v) ? v() : v;
|
|
1397
1475
|
}
|
|
1398
1476
|
function useChildren(props) {
|
|
@@ -1473,7 +1551,9 @@ function Portal(props) {
|
|
|
1473
1551
|
if (children == null) return placeholder;
|
|
1474
1552
|
const parentScope = getActiveScope();
|
|
1475
1553
|
let innerScope = null;
|
|
1554
|
+
let disposed = false;
|
|
1476
1555
|
const mountAt = (parent, before) => {
|
|
1556
|
+
if (disposed || (parentScope == null ? void 0 : parentScope.isDestroyed)) return;
|
|
1477
1557
|
innerScope = createScope(parentScope);
|
|
1478
1558
|
runWithScope(innerScope, () => {
|
|
1479
1559
|
insert(parent, () => children, before);
|
|
@@ -1486,6 +1566,7 @@ function Portal(props) {
|
|
|
1486
1566
|
}
|
|
1487
1567
|
};
|
|
1488
1568
|
const apply = (disabled, target) => {
|
|
1569
|
+
if (disposed) return;
|
|
1489
1570
|
teardown();
|
|
1490
1571
|
if (disabled) {
|
|
1491
1572
|
const parent = placeholder.parentNode;
|
|
@@ -1518,11 +1599,13 @@ function Portal(props) {
|
|
|
1518
1599
|
return;
|
|
1519
1600
|
}
|
|
1520
1601
|
queueMicrotask(() => {
|
|
1602
|
+
if (disposed) return;
|
|
1521
1603
|
if (!placeholder.parentNode) return;
|
|
1522
1604
|
apply(evalDisabled(props), resolveTarget(props));
|
|
1523
1605
|
});
|
|
1524
1606
|
});
|
|
1525
1607
|
onCleanup(() => {
|
|
1608
|
+
disposed = true;
|
|
1526
1609
|
effectRunner.stop();
|
|
1527
1610
|
teardown();
|
|
1528
1611
|
});
|
|
@@ -1568,12 +1651,15 @@ function resolveNodeValue(value) {
|
|
|
1568
1651
|
if (isSignal(current) || isComputed(current)) {
|
|
1569
1652
|
return resolveNodeValue(current.value);
|
|
1570
1653
|
}
|
|
1571
|
-
if (
|
|
1654
|
+
if (isArray(current)) {
|
|
1572
1655
|
return current.map((item) => resolveNodeValue(item));
|
|
1573
1656
|
}
|
|
1574
1657
|
return current;
|
|
1575
1658
|
}
|
|
1576
1659
|
var SuspenseContext = /* @__PURE__ */ Symbol("SuspenseContext");
|
|
1660
|
+
function isAbortError(error4) {
|
|
1661
|
+
return !!error4 && typeof error4 === "object" && error4.name === "AbortError";
|
|
1662
|
+
}
|
|
1577
1663
|
function Suspense(props) {
|
|
1578
1664
|
var _a2;
|
|
1579
1665
|
if (!isBrowser()) {
|
|
@@ -1587,10 +1673,14 @@ function Suspense(props) {
|
|
|
1587
1673
|
let mounted = true;
|
|
1588
1674
|
let pending = 0;
|
|
1589
1675
|
let mounting = false;
|
|
1676
|
+
let boundaryVersion = 0;
|
|
1677
|
+
let currentChildren = null;
|
|
1590
1678
|
let contentScope = null;
|
|
1591
1679
|
let parked = null;
|
|
1592
1680
|
let fallbackScope = null;
|
|
1593
1681
|
let resolved = null;
|
|
1682
|
+
let hasResolved = false;
|
|
1683
|
+
let manualReleases = [];
|
|
1594
1684
|
const parkContent = () => {
|
|
1595
1685
|
const off = document.createDocumentFragment();
|
|
1596
1686
|
while (end.previousSibling && end.previousSibling !== start) {
|
|
@@ -1620,14 +1710,35 @@ function Suspense(props) {
|
|
|
1620
1710
|
disposeScope(fallbackScope);
|
|
1621
1711
|
fallbackScope = null;
|
|
1622
1712
|
};
|
|
1623
|
-
const
|
|
1713
|
+
const disposeContent = () => {
|
|
1714
|
+
if (contentScope) {
|
|
1715
|
+
disposeScope(contentScope);
|
|
1716
|
+
contentScope = null;
|
|
1717
|
+
}
|
|
1718
|
+
if (parked) {
|
|
1719
|
+
while (parked.firstChild) parked.firstChild.remove();
|
|
1720
|
+
parked = null;
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1723
|
+
const mountContent = (children) => {
|
|
1724
|
+
const scope = createScope(owner);
|
|
1624
1725
|
mounting = true;
|
|
1625
|
-
contentScope =
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1726
|
+
contentScope = scope;
|
|
1727
|
+
try {
|
|
1728
|
+
runWithScope(scope, () => {
|
|
1729
|
+
var _a3;
|
|
1730
|
+
insert((_a3 = end.parentNode) != null ? _a3 : frag, () => resolveNodeValue(children), end);
|
|
1731
|
+
});
|
|
1732
|
+
} catch (error4) {
|
|
1733
|
+
if (contentScope === scope) contentScope = null;
|
|
1734
|
+
disposeScope(scope);
|
|
1735
|
+
pending = 0;
|
|
1736
|
+
manualReleases = [];
|
|
1737
|
+
boundaryVersion++;
|
|
1738
|
+
throw error4;
|
|
1739
|
+
} finally {
|
|
1740
|
+
mounting = false;
|
|
1741
|
+
}
|
|
1631
1742
|
if (pending && !parked) {
|
|
1632
1743
|
parkContent();
|
|
1633
1744
|
mountFallback();
|
|
@@ -1641,53 +1752,89 @@ function Suspense(props) {
|
|
|
1641
1752
|
};
|
|
1642
1753
|
const showContent = () => {
|
|
1643
1754
|
if (!parked) return;
|
|
1644
|
-
const hasSyncChildren =
|
|
1645
|
-
if (contentScope == null &&
|
|
1755
|
+
const hasSyncChildren = currentChildren != null && !isPromise(currentChildren);
|
|
1756
|
+
if (contentScope == null && !hasResolved && !hasSyncChildren) return;
|
|
1646
1757
|
disposeFallback();
|
|
1647
1758
|
restoreContent();
|
|
1648
1759
|
if (!contentScope) {
|
|
1649
|
-
if (
|
|
1760
|
+
if (hasResolved) {
|
|
1650
1761
|
mountContent(resolved);
|
|
1651
1762
|
} else if (hasSyncChildren) {
|
|
1652
|
-
mountContent(
|
|
1763
|
+
mountContent(currentChildren);
|
|
1653
1764
|
}
|
|
1654
1765
|
}
|
|
1655
1766
|
};
|
|
1656
|
-
const
|
|
1767
|
+
const addPending = (version = boundaryVersion) => {
|
|
1768
|
+
pending++;
|
|
1769
|
+
showFallback();
|
|
1770
|
+
const release = (() => {
|
|
1771
|
+
if (!release.active) return;
|
|
1772
|
+
release.active = false;
|
|
1773
|
+
if (!mounted || version !== boundaryVersion) return;
|
|
1774
|
+
if (--pending === 0) showContent();
|
|
1775
|
+
});
|
|
1776
|
+
release.active = true;
|
|
1777
|
+
return release;
|
|
1778
|
+
};
|
|
1779
|
+
const settle = (release) => {
|
|
1657
1780
|
if (!mounted) return;
|
|
1658
|
-
|
|
1781
|
+
release();
|
|
1782
|
+
};
|
|
1783
|
+
const dequeueManualRelease = () => {
|
|
1784
|
+
while (manualReleases.length > 0) {
|
|
1785
|
+
const release = manualReleases.shift();
|
|
1786
|
+
if (release.active) return release;
|
|
1787
|
+
}
|
|
1788
|
+
return void 0;
|
|
1659
1789
|
};
|
|
1660
1790
|
const ctx = {
|
|
1661
1791
|
register: (promise) => {
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1792
|
+
const release = addPending();
|
|
1793
|
+
promise.then(
|
|
1794
|
+
() => settle(release),
|
|
1795
|
+
(error4) => {
|
|
1796
|
+
if (!isAbortError(error4)) warn("[Suspense] Resource failed:", error4);
|
|
1797
|
+
settle(release);
|
|
1798
|
+
}
|
|
1799
|
+
);
|
|
1800
|
+
return release;
|
|
1668
1801
|
},
|
|
1669
1802
|
increment: () => {
|
|
1670
|
-
|
|
1671
|
-
|
|
1803
|
+
const release = addPending();
|
|
1804
|
+
manualReleases.push(release);
|
|
1805
|
+
return release;
|
|
1672
1806
|
},
|
|
1673
1807
|
decrement: () => {
|
|
1674
|
-
|
|
1675
|
-
if (
|
|
1808
|
+
const release = dequeueManualRelease();
|
|
1809
|
+
if (release) settle(release);
|
|
1676
1810
|
}
|
|
1677
1811
|
};
|
|
1678
1812
|
provide(SuspenseContext, ctx);
|
|
1679
|
-
const
|
|
1680
|
-
|
|
1681
|
-
children
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1813
|
+
const renderChildren = (children) => {
|
|
1814
|
+
const version = ++boundaryVersion;
|
|
1815
|
+
currentChildren = children != null ? children : null;
|
|
1816
|
+
pending = 0;
|
|
1817
|
+
resolved = null;
|
|
1818
|
+
hasResolved = false;
|
|
1819
|
+
manualReleases = [];
|
|
1820
|
+
disposeContent();
|
|
1821
|
+
disposeFallback();
|
|
1822
|
+
if (isPromise(children)) {
|
|
1823
|
+
children.then((value) => {
|
|
1824
|
+
if (!mounted || version !== boundaryVersion) return;
|
|
1825
|
+
resolved = value;
|
|
1826
|
+
hasResolved = true;
|
|
1827
|
+
}).catch(() => {
|
|
1828
|
+
});
|
|
1829
|
+
ctx.register(children);
|
|
1830
|
+
} else if (children != null) {
|
|
1831
|
+
mountContent(children);
|
|
1832
|
+
} else if (props.fallback != null) {
|
|
1833
|
+
showFallback();
|
|
1834
|
+
}
|
|
1835
|
+
};
|
|
1836
|
+
renderChildren(props.children);
|
|
1837
|
+
onUpdate(() => renderChildren(props.children));
|
|
1691
1838
|
onCleanup(() => {
|
|
1692
1839
|
mounted = false;
|
|
1693
1840
|
pending = 0;
|
|
@@ -1705,6 +1852,9 @@ Suspense[SUSPENSE_COMPONENT] = true;
|
|
|
1705
1852
|
function isSuspense(node) {
|
|
1706
1853
|
return !!node && !!node[SUSPENSE_COMPONENT];
|
|
1707
1854
|
}
|
|
1855
|
+
function isAbortError2(error4) {
|
|
1856
|
+
return !!error4 && typeof error4 === "object" && error4.name === "AbortError";
|
|
1857
|
+
}
|
|
1708
1858
|
function createResource(fetcher, options) {
|
|
1709
1859
|
const value = signal(options == null ? void 0 : options.initialValue);
|
|
1710
1860
|
const loading = signal(true);
|
|
@@ -1739,7 +1889,7 @@ function createResource(fetcher, options) {
|
|
|
1739
1889
|
}
|
|
1740
1890
|
} catch (error_) {
|
|
1741
1891
|
if (id !== fetchId) return;
|
|
1742
|
-
if (error_
|
|
1892
|
+
if (isAbortError2(error_)) {
|
|
1743
1893
|
loading.value = false;
|
|
1744
1894
|
return;
|
|
1745
1895
|
}
|
|
@@ -1794,17 +1944,26 @@ function defineServerAsyncComponent(loader, ssr) {
|
|
|
1794
1944
|
function defineClientAsyncComponent(loader, options) {
|
|
1795
1945
|
const { loading, error: errorComp, delay = 200, timeout, onError } = options;
|
|
1796
1946
|
let component = null;
|
|
1797
|
-
let
|
|
1947
|
+
let loadError = null;
|
|
1798
1948
|
let status = "pending";
|
|
1799
1949
|
let loadPromise = null;
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1950
|
+
let loadId = 0;
|
|
1951
|
+
const currentLoad = (id) => id !== loadId ? loadPromise != null ? loadPromise : void 0 : void 0;
|
|
1952
|
+
const load = (forceId) => {
|
|
1953
|
+
if (loadPromise && forceId === void 0) return loadPromise;
|
|
1954
|
+
const id = forceId != null ? forceId : ++loadId;
|
|
1955
|
+
loadPromise = loader().then((mod) => {
|
|
1956
|
+
if (id !== loadId) return currentLoad(id);
|
|
1957
|
+
component = resolveModule(mod);
|
|
1958
|
+
status = "resolved";
|
|
1959
|
+
}).catch((error_) => {
|
|
1960
|
+
if (id !== loadId) return currentLoad(id);
|
|
1961
|
+
loadError = error_ instanceof Error ? error_ : new Error(String(error_));
|
|
1962
|
+
status = "errored";
|
|
1963
|
+
loadPromise = null;
|
|
1964
|
+
});
|
|
1965
|
+
return loadPromise;
|
|
1966
|
+
};
|
|
1808
1967
|
load();
|
|
1809
1968
|
function AsyncWrapper(props) {
|
|
1810
1969
|
var _a2;
|
|
@@ -1816,6 +1975,7 @@ function defineClientAsyncComponent(loader, options) {
|
|
|
1816
1975
|
let viewScope = null;
|
|
1817
1976
|
let delayTimer = null;
|
|
1818
1977
|
let timeoutTimer = null;
|
|
1978
|
+
let instanceRetryId = 0;
|
|
1819
1979
|
const clearTimers = () => {
|
|
1820
1980
|
if (delayTimer != null) clearTimeout(delayTimer);
|
|
1821
1981
|
if (timeoutTimer != null) clearTimeout(timeoutTimer);
|
|
@@ -1845,28 +2005,34 @@ function defineClientAsyncComponent(loader, options) {
|
|
|
1845
2005
|
end.remove();
|
|
1846
2006
|
});
|
|
1847
2007
|
const retryWith = (retryProps) => () => {
|
|
2008
|
+
if (!alive) return;
|
|
2009
|
+
const retryLoadId = ++loadId;
|
|
1848
2010
|
loadPromise = null;
|
|
1849
2011
|
status = "pending";
|
|
1850
|
-
|
|
2012
|
+
loadError = null;
|
|
2013
|
+
instanceRetryId++;
|
|
2014
|
+
const capturedRetry = instanceRetryId;
|
|
1851
2015
|
if (loading) render(loading);
|
|
1852
|
-
load().then(() =>
|
|
2016
|
+
load(retryLoadId).then(() => {
|
|
2017
|
+
if (alive && capturedRetry === instanceRetryId) settle(retryProps);
|
|
2018
|
+
});
|
|
1853
2019
|
};
|
|
1854
2020
|
const settle = (renderProps) => {
|
|
1855
2021
|
if (!alive) return;
|
|
1856
2022
|
clearTimers();
|
|
1857
2023
|
if (status === "resolved" && component) {
|
|
1858
2024
|
render(component, renderProps);
|
|
1859
|
-
} else if (status === "errored" &&
|
|
1860
|
-
if (errorComp) render(errorComp, { error:
|
|
1861
|
-
if (onError) onError(
|
|
2025
|
+
} else if (status === "errored" && loadError) {
|
|
2026
|
+
if (errorComp) render(errorComp, { error: loadError, retry: retryWith(renderProps) });
|
|
2027
|
+
if (onError) onError(loadError, retryWith(renderProps));
|
|
1862
2028
|
}
|
|
1863
2029
|
};
|
|
1864
2030
|
if (status === "resolved" && component) {
|
|
1865
2031
|
render(component, props);
|
|
1866
2032
|
return frag;
|
|
1867
2033
|
}
|
|
1868
|
-
if (status === "errored" &&
|
|
1869
|
-
if (errorComp) render(errorComp, { error:
|
|
2034
|
+
if (status === "errored" && loadError) {
|
|
2035
|
+
if (errorComp) render(errorComp, { error: loadError, retry: retryWith(props) });
|
|
1870
2036
|
return frag;
|
|
1871
2037
|
}
|
|
1872
2038
|
const pending = load().then(() => settle(props));
|
|
@@ -1881,10 +2047,9 @@ function defineClientAsyncComponent(loader, options) {
|
|
|
1881
2047
|
if (timeout != null) {
|
|
1882
2048
|
timeoutTimer = setTimeout(() => {
|
|
1883
2049
|
if (!alive || status !== "pending") return;
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
if (
|
|
1887
|
-
if (onError) onError(error4, retryWith(props));
|
|
2050
|
+
const err = new Error(`[defineAsyncComponent] Timeout after ${timeout}ms`);
|
|
2051
|
+
if (errorComp) render(errorComp, { error: err, retry: retryWith(props) });
|
|
2052
|
+
if (onError) onError(err, retryWith(props));
|
|
1888
2053
|
}, timeout);
|
|
1889
2054
|
}
|
|
1890
2055
|
return frag;
|
|
@@ -1903,9 +2068,11 @@ function For(props) {
|
|
|
1903
2068
|
fragment.appendChild(marker);
|
|
1904
2069
|
let entries = [];
|
|
1905
2070
|
let fallbackNodes = [];
|
|
2071
|
+
let fallbackScope = null;
|
|
2072
|
+
const ownerScope = getActiveScope();
|
|
1906
2073
|
const keyFn = props.key;
|
|
1907
2074
|
const raw = props.children;
|
|
1908
|
-
const renderFn =
|
|
2075
|
+
const renderFn = isArray(raw) && raw.length === 1 && isFunction(raw[0]) ? raw[0] : props.children;
|
|
1909
2076
|
if (!isFunction(renderFn)) {
|
|
1910
2077
|
throw new TypeError("<For> requires `children` to be a function (item, index) => Node");
|
|
1911
2078
|
}
|
|
@@ -1917,9 +2084,31 @@ function For(props) {
|
|
|
1917
2084
|
return input != null ? input : [];
|
|
1918
2085
|
};
|
|
1919
2086
|
const getKey = (item, index) => keyFn ? keyFn(item, index) : item;
|
|
2087
|
+
const formatKeyForWarning = (key) => {
|
|
2088
|
+
if (typeof key === "string") return JSON.stringify(key);
|
|
2089
|
+
return String(key);
|
|
2090
|
+
};
|
|
2091
|
+
const getKeys = (items) => {
|
|
2092
|
+
const keys = new Array(items.length);
|
|
2093
|
+
{
|
|
2094
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2095
|
+
for (const [i, item] of items.entries()) {
|
|
2096
|
+
const key = getKey(item, i);
|
|
2097
|
+
keys[i] = key;
|
|
2098
|
+
if (seen.has(key)) {
|
|
2099
|
+
warn(
|
|
2100
|
+
`[For] duplicate key ${formatKeyForWarning(key)} detected. Duplicate keys may cause rows to remount or lose state.`
|
|
2101
|
+
);
|
|
2102
|
+
} else {
|
|
2103
|
+
seen.add(key);
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
return keys;
|
|
2107
|
+
}
|
|
2108
|
+
};
|
|
1920
2109
|
const mountValue = (value, parent, before) => {
|
|
1921
2110
|
if (value == null || value === false) return [];
|
|
1922
|
-
if (
|
|
2111
|
+
if (isArray(value)) {
|
|
1923
2112
|
const nodes = [];
|
|
1924
2113
|
for (const child2 of value) nodes.push(...mountValue(child2, parent, before));
|
|
1925
2114
|
return nodes;
|
|
@@ -1933,17 +2122,30 @@ function For(props) {
|
|
|
1933
2122
|
return [node];
|
|
1934
2123
|
};
|
|
1935
2124
|
const mountFallback = (parent, before) => {
|
|
2125
|
+
var _a2;
|
|
1936
2126
|
if (!props.fallback) return;
|
|
1937
|
-
|
|
1938
|
-
|
|
2127
|
+
fallbackScope = createScope((_a2 = getActiveScope()) != null ? _a2 : ownerScope);
|
|
2128
|
+
try {
|
|
2129
|
+
runWithScope(fallbackScope, () => {
|
|
2130
|
+
fallbackNodes = mountValue(props.fallback(), parent, before);
|
|
2131
|
+
});
|
|
2132
|
+
} catch (error4) {
|
|
2133
|
+
disposeScope(fallbackScope);
|
|
2134
|
+
fallbackScope = null;
|
|
2135
|
+
fallbackNodes = [];
|
|
2136
|
+
throw error4;
|
|
2137
|
+
}
|
|
1939
2138
|
};
|
|
1940
2139
|
const clearFallback = () => {
|
|
2140
|
+
if (fallbackScope) {
|
|
2141
|
+
disposeScope(fallbackScope);
|
|
2142
|
+
fallbackScope = null;
|
|
2143
|
+
}
|
|
1941
2144
|
for (const node of fallbackNodes) {
|
|
1942
2145
|
removeNode(node);
|
|
1943
2146
|
}
|
|
1944
2147
|
fallbackNodes = [];
|
|
1945
2148
|
};
|
|
1946
|
-
const ownerScope = getActiveScope();
|
|
1947
2149
|
const renderItem = (item, index, parent, before, key = getKey(item, index)) => {
|
|
1948
2150
|
var _a2;
|
|
1949
2151
|
const parentScope = (_a2 = getActiveScope()) != null ? _a2 : ownerScope;
|
|
@@ -1975,10 +2177,9 @@ function For(props) {
|
|
|
1975
2177
|
mountFallback(fragment, marker);
|
|
1976
2178
|
} else {
|
|
1977
2179
|
entries = new Array(newItems.length);
|
|
1978
|
-
|
|
1979
|
-
for (const newItem of newItems) {
|
|
1980
|
-
entries[
|
|
1981
|
-
idx++;
|
|
2180
|
+
const newKeys = getKeys(newItems);
|
|
2181
|
+
for (const [i, newItem] of newItems.entries()) {
|
|
2182
|
+
entries[i] = renderItem(newItem, i, fragment, marker, newKeys[i]);
|
|
1982
2183
|
}
|
|
1983
2184
|
}
|
|
1984
2185
|
return;
|
|
@@ -2004,10 +2205,13 @@ function For(props) {
|
|
|
2004
2205
|
}
|
|
2005
2206
|
entries = new Array(newLen);
|
|
2006
2207
|
const batchFragment2 = document.createDocumentFragment();
|
|
2208
|
+
const newKeys2 = getKeys(newItems);
|
|
2007
2209
|
for (let i = 0; i < newLen; i++) {
|
|
2008
|
-
entries[i] = renderItem(newItems[i], i, batchFragment2, null);
|
|
2210
|
+
entries[i] = renderItem(newItems[i], i, batchFragment2, null, newKeys2[i]);
|
|
2009
2211
|
}
|
|
2010
|
-
|
|
2212
|
+
untrack(() => {
|
|
2213
|
+
parent.insertBefore(batchFragment2, marker);
|
|
2214
|
+
});
|
|
2011
2215
|
return;
|
|
2012
2216
|
}
|
|
2013
2217
|
const oldKeyMap = /* @__PURE__ */ new Map();
|
|
@@ -2024,10 +2228,7 @@ function For(props) {
|
|
|
2024
2228
|
const newIndexToOldIndex = new Int32Array(newLen);
|
|
2025
2229
|
let moved = false;
|
|
2026
2230
|
let maxOldSeen = 0;
|
|
2027
|
-
const newKeys =
|
|
2028
|
-
for (let i = 0; i < newLen; i++) {
|
|
2029
|
-
newKeys[i] = getKey(newItems[i], i);
|
|
2030
|
-
}
|
|
2231
|
+
const newKeys = getKeys(newItems);
|
|
2031
2232
|
for (let i = 0; i < newLen; i++) {
|
|
2032
2233
|
const item = newItems[i];
|
|
2033
2234
|
const key = newKeys[i];
|
|
@@ -2042,7 +2243,7 @@ function For(props) {
|
|
|
2042
2243
|
else maxOldSeen = oldIndex;
|
|
2043
2244
|
} else {
|
|
2044
2245
|
if (!batchFragment) batchFragment = document.createDocumentFragment();
|
|
2045
|
-
disposeItem(reused);
|
|
2246
|
+
untrack(() => disposeItem(reused));
|
|
2046
2247
|
newEntries[i] = renderItem(item, i, batchFragment, null, key);
|
|
2047
2248
|
}
|
|
2048
2249
|
} else {
|
|
@@ -2053,28 +2254,30 @@ function For(props) {
|
|
|
2053
2254
|
for (const list of oldKeyMap.values()) {
|
|
2054
2255
|
for (const [entry] of list) toRemove.push(entry);
|
|
2055
2256
|
}
|
|
2056
|
-
for (const entry of toRemove) disposeItem(entry);
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2257
|
+
for (const entry of toRemove) untrack(() => disposeItem(entry));
|
|
2258
|
+
untrack(() => {
|
|
2259
|
+
const lis = moved ? getSequence(newIndexToOldIndex) : [];
|
|
2260
|
+
let lisCursor = lis.length - 1;
|
|
2261
|
+
let nextNode = marker;
|
|
2262
|
+
for (let i = newLen - 1; i >= 0; i--) {
|
|
2263
|
+
const entry = newEntries[i];
|
|
2264
|
+
const nodes = entry.nodes;
|
|
2265
|
+
const isFresh = newIndexToOldIndex[i] === 0;
|
|
2266
|
+
const inLis = !isFresh && moved && lisCursor >= 0 && i === lis[lisCursor];
|
|
2267
|
+
if (inLis) {
|
|
2268
|
+
lisCursor--;
|
|
2269
|
+
for (let j = nodes.length - 1; j >= 0; j--) nextNode = nodes[j];
|
|
2270
|
+
continue;
|
|
2271
|
+
}
|
|
2272
|
+
for (let j = nodes.length - 1; j >= 0; j--) {
|
|
2273
|
+
const node = nodes[j];
|
|
2274
|
+
if (node.nextSibling !== nextNode) {
|
|
2275
|
+
parent.insertBefore(node, nextNode);
|
|
2276
|
+
}
|
|
2277
|
+
nextNode = node;
|
|
2074
2278
|
}
|
|
2075
|
-
nextNode = node;
|
|
2076
2279
|
}
|
|
2077
|
-
}
|
|
2280
|
+
});
|
|
2078
2281
|
entries = newEntries;
|
|
2079
2282
|
}
|
|
2080
2283
|
onCleanup(() => {
|
|
@@ -2137,21 +2340,40 @@ function addClass(el, cls) {
|
|
|
2137
2340
|
function removeClass(el, cls) {
|
|
2138
2341
|
for (const c of cls.split(/\s+/)) if (c) el.classList.remove(c);
|
|
2139
2342
|
}
|
|
2140
|
-
function
|
|
2141
|
-
|
|
2343
|
+
function nextFrameCancellable(cb) {
|
|
2344
|
+
let cancelled = false;
|
|
2345
|
+
let innerId = null;
|
|
2346
|
+
const outerId = requestAnimationFrame(() => {
|
|
2347
|
+
if (cancelled) return;
|
|
2348
|
+
innerId = requestAnimationFrame(cb);
|
|
2349
|
+
});
|
|
2350
|
+
return () => {
|
|
2351
|
+
cancelled = true;
|
|
2352
|
+
cancelAnimationFrame(outerId);
|
|
2353
|
+
if (innerId != null) cancelAnimationFrame(innerId);
|
|
2354
|
+
};
|
|
2142
2355
|
}
|
|
2143
2356
|
function forceReflow(el) {
|
|
2144
2357
|
void el.offsetHeight;
|
|
2145
2358
|
}
|
|
2146
2359
|
function whenTransitionEnds(el, type, explicit, resolve2) {
|
|
2147
2360
|
if (explicit != null) {
|
|
2148
|
-
|
|
2149
|
-
|
|
2361
|
+
let done2 = false;
|
|
2362
|
+
const timer2 = setTimeout(() => {
|
|
2363
|
+
if (done2) return;
|
|
2364
|
+
done2 = true;
|
|
2365
|
+
resolve2();
|
|
2366
|
+
}, explicit);
|
|
2367
|
+
return () => {
|
|
2368
|
+
done2 = true;
|
|
2369
|
+
clearTimeout(timer2);
|
|
2370
|
+
};
|
|
2150
2371
|
}
|
|
2151
2372
|
const info = getTransitionInfo(el, type);
|
|
2152
2373
|
if (!info) {
|
|
2153
2374
|
resolve2();
|
|
2154
|
-
return
|
|
2375
|
+
return () => {
|
|
2376
|
+
};
|
|
2155
2377
|
}
|
|
2156
2378
|
let done = false;
|
|
2157
2379
|
const finish = () => {
|
|
@@ -2161,9 +2383,18 @@ function whenTransitionEnds(el, type, explicit, resolve2) {
|
|
|
2161
2383
|
el.removeEventListener(info.event, onEnd);
|
|
2162
2384
|
resolve2();
|
|
2163
2385
|
};
|
|
2164
|
-
const onEnd = () =>
|
|
2386
|
+
const onEnd = (event) => {
|
|
2387
|
+
if (event.target !== el) return;
|
|
2388
|
+
finish();
|
|
2389
|
+
};
|
|
2165
2390
|
el.addEventListener(info.event, onEnd);
|
|
2166
2391
|
const timer = setTimeout(finish, info.timeout + 1);
|
|
2392
|
+
return () => {
|
|
2393
|
+
if (done) return;
|
|
2394
|
+
done = true;
|
|
2395
|
+
clearTimeout(timer);
|
|
2396
|
+
el.removeEventListener(info.event, onEnd);
|
|
2397
|
+
};
|
|
2167
2398
|
}
|
|
2168
2399
|
function resolveDuration(d, dir) {
|
|
2169
2400
|
if (d == null) return null;
|
|
@@ -2172,7 +2403,7 @@ function resolveDuration(d, dir) {
|
|
|
2172
2403
|
}
|
|
2173
2404
|
function validateSlot(value) {
|
|
2174
2405
|
if (value == null || value === false) return null;
|
|
2175
|
-
if (
|
|
2406
|
+
if (isArray(value)) {
|
|
2176
2407
|
{
|
|
2177
2408
|
throw new Error(
|
|
2178
2409
|
"[essor] <Transition> expects a single root child. Use <TransitionGroup> for multiple children."
|
|
@@ -2218,8 +2449,26 @@ function Transition(props) {
|
|
|
2218
2449
|
let hasPending = false;
|
|
2219
2450
|
let scheduled = false;
|
|
2220
2451
|
let disposed = false;
|
|
2452
|
+
let cancelEnterWait = null;
|
|
2453
|
+
let cancelLeaveWait = null;
|
|
2454
|
+
const stopEnterWait = () => {
|
|
2455
|
+
cancelEnterWait == null ? void 0 : cancelEnterWait();
|
|
2456
|
+
cancelEnterWait = null;
|
|
2457
|
+
};
|
|
2458
|
+
const stopLeaveWait = () => {
|
|
2459
|
+
cancelLeaveWait == null ? void 0 : cancelLeaveWait();
|
|
2460
|
+
cancelLeaveWait = null;
|
|
2461
|
+
};
|
|
2221
2462
|
const enter = (el, phase) => {
|
|
2222
2463
|
var _a2;
|
|
2464
|
+
stopEnterWait();
|
|
2465
|
+
let cancelWait = null;
|
|
2466
|
+
const stopWait = () => {
|
|
2467
|
+
cancelWait == null ? void 0 : cancelWait();
|
|
2468
|
+
cancelWait = null;
|
|
2469
|
+
if (cancelEnterWait === stopWait) cancelEnterWait = null;
|
|
2470
|
+
};
|
|
2471
|
+
cancelEnterWait = stopWait;
|
|
2223
2472
|
const prevLeave = el[LEAVE_CB];
|
|
2224
2473
|
if (prevLeave) prevLeave(true);
|
|
2225
2474
|
state = "entering";
|
|
@@ -2236,6 +2485,7 @@ function Transition(props) {
|
|
|
2236
2485
|
var _a3, _b;
|
|
2237
2486
|
if (called) return;
|
|
2238
2487
|
called = true;
|
|
2488
|
+
stopWait();
|
|
2239
2489
|
el[ENTER_CB] = void 0;
|
|
2240
2490
|
if (useCss) {
|
|
2241
2491
|
removeClass(el, fromCls);
|
|
@@ -2250,7 +2500,8 @@ function Transition(props) {
|
|
|
2250
2500
|
}
|
|
2251
2501
|
};
|
|
2252
2502
|
el[ENTER_CB] = done;
|
|
2253
|
-
|
|
2503
|
+
cancelWait = nextFrameCancellable(() => {
|
|
2504
|
+
cancelWait = null;
|
|
2254
2505
|
if (called) return;
|
|
2255
2506
|
if (useCss) {
|
|
2256
2507
|
removeClass(el, fromCls);
|
|
@@ -2260,7 +2511,10 @@ function Transition(props) {
|
|
|
2260
2511
|
props.onEnter(el, () => done(false));
|
|
2261
2512
|
} else if (useCss) {
|
|
2262
2513
|
const explicit = resolveDuration(props.duration, "enter");
|
|
2263
|
-
whenTransitionEnds(el, props.type, explicit, () =>
|
|
2514
|
+
cancelWait = whenTransitionEnds(el, props.type, explicit, () => {
|
|
2515
|
+
cancelWait = null;
|
|
2516
|
+
done(false);
|
|
2517
|
+
});
|
|
2264
2518
|
} else {
|
|
2265
2519
|
done(false);
|
|
2266
2520
|
}
|
|
@@ -2268,6 +2522,14 @@ function Transition(props) {
|
|
|
2268
2522
|
};
|
|
2269
2523
|
const leave = (el, after) => {
|
|
2270
2524
|
var _a2;
|
|
2525
|
+
stopLeaveWait();
|
|
2526
|
+
let cancelWait = null;
|
|
2527
|
+
const stopWait = () => {
|
|
2528
|
+
cancelWait == null ? void 0 : cancelWait();
|
|
2529
|
+
cancelWait = null;
|
|
2530
|
+
if (cancelLeaveWait === stopWait) cancelLeaveWait = null;
|
|
2531
|
+
};
|
|
2532
|
+
cancelLeaveWait = stopWait;
|
|
2271
2533
|
const prevEnter = el[ENTER_CB];
|
|
2272
2534
|
if (prevEnter) {
|
|
2273
2535
|
prevEnter(true);
|
|
@@ -2284,6 +2546,7 @@ function Transition(props) {
|
|
|
2284
2546
|
var _a3, _b;
|
|
2285
2547
|
if (called) return;
|
|
2286
2548
|
called = true;
|
|
2549
|
+
stopWait();
|
|
2287
2550
|
el[LEAVE_CB] = void 0;
|
|
2288
2551
|
if (useCss) {
|
|
2289
2552
|
removeClass(el, classes.leaveFrom);
|
|
@@ -2305,7 +2568,8 @@ function Transition(props) {
|
|
|
2305
2568
|
done(false);
|
|
2306
2569
|
return;
|
|
2307
2570
|
}
|
|
2308
|
-
|
|
2571
|
+
cancelWait = nextFrameCancellable(() => {
|
|
2572
|
+
cancelWait = null;
|
|
2309
2573
|
if (called) return;
|
|
2310
2574
|
if (useCss) {
|
|
2311
2575
|
removeClass(el, classes.leaveFrom);
|
|
@@ -2314,7 +2578,10 @@ function Transition(props) {
|
|
|
2314
2578
|
if (props.onLeave) {
|
|
2315
2579
|
props.onLeave(el, () => done(false));
|
|
2316
2580
|
} else if (useCss) {
|
|
2317
|
-
whenTransitionEnds(el, props.type, explicit, () =>
|
|
2581
|
+
cancelWait = whenTransitionEnds(el, props.type, explicit, () => {
|
|
2582
|
+
cancelWait = null;
|
|
2583
|
+
done(false);
|
|
2584
|
+
});
|
|
2318
2585
|
} else {
|
|
2319
2586
|
done(false);
|
|
2320
2587
|
}
|
|
@@ -2389,6 +2656,8 @@ function Transition(props) {
|
|
|
2389
2656
|
});
|
|
2390
2657
|
onCleanup(() => {
|
|
2391
2658
|
disposed = true;
|
|
2659
|
+
stopEnterWait();
|
|
2660
|
+
stopLeaveWait();
|
|
2392
2661
|
effectRunner.stop();
|
|
2393
2662
|
for (const el of [currentEl, leavingEl]) {
|
|
2394
2663
|
if (!el) continue;
|
|
@@ -2410,7 +2679,7 @@ function isTransition(node) {
|
|
|
2410
2679
|
}
|
|
2411
2680
|
function resolveItemElement(raw, parent) {
|
|
2412
2681
|
if (raw == null || raw === false) return { el: null, comp: null };
|
|
2413
|
-
if (
|
|
2682
|
+
if (isArray(raw) && raw.length === 1) {
|
|
2414
2683
|
return resolveItemElement(raw[0], parent);
|
|
2415
2684
|
}
|
|
2416
2685
|
if (isFunction(raw)) {
|
|
@@ -2465,7 +2734,7 @@ function TransitionGroup(props) {
|
|
|
2465
2734
|
const moveClass = (_c = props.moveClass) != null ? _c : `${(_b = props.name) != null ? _b : "v"}-move`;
|
|
2466
2735
|
const keyFn = props.key;
|
|
2467
2736
|
const rawChildren = props.children;
|
|
2468
|
-
const childrenFn =
|
|
2737
|
+
const childrenFn = isArray(rawChildren) && rawChildren.length === 1 && isFunction(rawChildren[0]) ? rawChildren[0] : props.children;
|
|
2469
2738
|
if (!isFunction(childrenFn) || !isFunction(keyFn)) {
|
|
2470
2739
|
throw new TypeError(
|
|
2471
2740
|
"<TransitionGroup> requires `children: (item, index) => Node` and `key: (item, index) => unknown`"
|
|
@@ -2516,9 +2785,12 @@ function TransitionGroup(props) {
|
|
|
2516
2785
|
if (entry.el.parentNode === wrapper) wrapper.removeChild(entry.el);
|
|
2517
2786
|
};
|
|
2518
2787
|
const disposeEntry = (entry) => {
|
|
2519
|
-
var _a3, _b2;
|
|
2788
|
+
var _a3, _b2, _c2, _d, _e;
|
|
2520
2789
|
(_a3 = entry.cancelEnter) == null ? void 0 : _a3.call(entry, true);
|
|
2521
2790
|
(_b2 = entry.cancelLeave) == null ? void 0 : _b2.call(entry, true);
|
|
2791
|
+
(_c2 = entry.cancelEnterWait) == null ? void 0 : _c2.call(entry);
|
|
2792
|
+
(_d = entry.cancelLeaveWait) == null ? void 0 : _d.call(entry);
|
|
2793
|
+
(_e = entry.cancelMoveWait) == null ? void 0 : _e.call(entry);
|
|
2522
2794
|
if (entry.comp) entry.comp.destroy();
|
|
2523
2795
|
detachEntryDom(entry);
|
|
2524
2796
|
disposeScope(entry.scope);
|
|
@@ -2537,23 +2809,26 @@ function TransitionGroup(props) {
|
|
|
2537
2809
|
addClass(el, classes.enterActive);
|
|
2538
2810
|
let called = false;
|
|
2539
2811
|
const done = (cancelled) => {
|
|
2540
|
-
var _a4, _b3;
|
|
2812
|
+
var _a4, _b3, _c3;
|
|
2541
2813
|
if (called) return;
|
|
2542
2814
|
called = true;
|
|
2543
2815
|
entry.cancelEnter = void 0;
|
|
2816
|
+
(_a4 = entry.cancelEnterWait) == null ? void 0 : _a4.call(entry);
|
|
2817
|
+
entry.cancelEnterWait = void 0;
|
|
2544
2818
|
removeClass(el, classes.enterFrom);
|
|
2545
2819
|
removeClass(el, classes.enterActive);
|
|
2546
2820
|
removeClass(el, classes.enterTo);
|
|
2547
2821
|
if (cancelled) {
|
|
2548
|
-
(
|
|
2822
|
+
(_b3 = props.onEnterCancelled) == null ? void 0 : _b3.call(props, el);
|
|
2549
2823
|
} else {
|
|
2550
2824
|
entry.state = "present";
|
|
2551
|
-
(
|
|
2825
|
+
(_c3 = props.onAfterEnter) == null ? void 0 : _c3.call(props, el);
|
|
2552
2826
|
}
|
|
2553
2827
|
};
|
|
2554
2828
|
entry.cancelEnter = done;
|
|
2555
2829
|
entry.state = "entering";
|
|
2556
|
-
|
|
2830
|
+
entry.cancelEnterWait = nextFrameCancellable(() => {
|
|
2831
|
+
entry.cancelEnterWait = void 0;
|
|
2557
2832
|
if (called) return;
|
|
2558
2833
|
removeClass(el, classes.enterFrom);
|
|
2559
2834
|
addClass(el, classes.enterTo);
|
|
@@ -2561,7 +2836,10 @@ function TransitionGroup(props) {
|
|
|
2561
2836
|
props.onEnter(el, () => done(false));
|
|
2562
2837
|
} else {
|
|
2563
2838
|
const explicit = resolveDuration(props.duration, "enter");
|
|
2564
|
-
whenTransitionEnds(el, props.type, explicit, () =>
|
|
2839
|
+
entry.cancelEnterWait = whenTransitionEnds(el, props.type, explicit, () => {
|
|
2840
|
+
entry.cancelEnterWait = void 0;
|
|
2841
|
+
done(false);
|
|
2842
|
+
});
|
|
2565
2843
|
}
|
|
2566
2844
|
});
|
|
2567
2845
|
};
|
|
@@ -2593,17 +2871,19 @@ function TransitionGroup(props) {
|
|
|
2593
2871
|
addClass(el, classes.leaveActive);
|
|
2594
2872
|
let called = false;
|
|
2595
2873
|
const done = (cancelled) => {
|
|
2596
|
-
var _a4, _b3;
|
|
2874
|
+
var _a4, _b3, _c2;
|
|
2597
2875
|
if (called) return;
|
|
2598
2876
|
called = true;
|
|
2599
2877
|
entry.cancelLeave = void 0;
|
|
2878
|
+
(_a4 = entry.cancelLeaveWait) == null ? void 0 : _a4.call(entry);
|
|
2879
|
+
entry.cancelLeaveWait = void 0;
|
|
2600
2880
|
removeClass(el, classes.leaveFrom);
|
|
2601
2881
|
removeClass(el, classes.leaveActive);
|
|
2602
2882
|
removeClass(el, classes.leaveTo);
|
|
2603
2883
|
if (cancelled) {
|
|
2604
2884
|
if (entry.savedStyles) restoreStyles(el, entry.savedStyles);
|
|
2605
2885
|
entry.savedStyles = void 0;
|
|
2606
|
-
(
|
|
2886
|
+
(_b3 = props.onLeaveCancelled) == null ? void 0 : _b3.call(props, el);
|
|
2607
2887
|
return;
|
|
2608
2888
|
}
|
|
2609
2889
|
if (entry.savedStyles) restoreStyles(el, entry.savedStyles);
|
|
@@ -2611,10 +2891,11 @@ function TransitionGroup(props) {
|
|
|
2611
2891
|
detachEntryDom(entry);
|
|
2612
2892
|
disposeScope(entry.scope);
|
|
2613
2893
|
if (entry.comp) entry.comp.destroy();
|
|
2614
|
-
(
|
|
2894
|
+
(_c2 = props.onAfterLeave) == null ? void 0 : _c2.call(props, el);
|
|
2615
2895
|
};
|
|
2616
2896
|
entry.cancelLeave = done;
|
|
2617
|
-
|
|
2897
|
+
entry.cancelLeaveWait = nextFrameCancellable(() => {
|
|
2898
|
+
entry.cancelLeaveWait = void 0;
|
|
2618
2899
|
if (called) return;
|
|
2619
2900
|
removeClass(el, classes.leaveFrom);
|
|
2620
2901
|
addClass(el, classes.leaveTo);
|
|
@@ -2622,11 +2903,15 @@ function TransitionGroup(props) {
|
|
|
2622
2903
|
props.onLeave(el, () => done(false));
|
|
2623
2904
|
} else {
|
|
2624
2905
|
const explicit = resolveDuration(props.duration, "leave");
|
|
2625
|
-
whenTransitionEnds(el, props.type, explicit, () =>
|
|
2906
|
+
entry.cancelLeaveWait = whenTransitionEnds(el, props.type, explicit, () => {
|
|
2907
|
+
entry.cancelLeaveWait = void 0;
|
|
2908
|
+
done(false);
|
|
2909
|
+
});
|
|
2626
2910
|
}
|
|
2627
2911
|
});
|
|
2628
2912
|
};
|
|
2629
2913
|
const runMove = (entry, prevRect) => {
|
|
2914
|
+
var _a3;
|
|
2630
2915
|
if (!useCss || entry.state !== "present") return;
|
|
2631
2916
|
const el = entry.el;
|
|
2632
2917
|
const newRect = el.getBoundingClientRect();
|
|
@@ -2642,7 +2927,9 @@ function TransitionGroup(props) {
|
|
|
2642
2927
|
el.style.transform = savedTransform;
|
|
2643
2928
|
el.style.transitionDuration = savedTransition;
|
|
2644
2929
|
const explicit = resolveDuration(props.duration, "enter");
|
|
2645
|
-
|
|
2930
|
+
(_a3 = entry.cancelMoveWait) == null ? void 0 : _a3.call(entry);
|
|
2931
|
+
entry.cancelMoveWait = whenTransitionEnds(el, props.type, explicit, () => {
|
|
2932
|
+
entry.cancelMoveWait = void 0;
|
|
2646
2933
|
removeClass(el, moveClass);
|
|
2647
2934
|
});
|
|
2648
2935
|
};
|