@fictjs/runtime 0.0.15 → 0.2.0
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/advanced.cjs +8 -8
- package/dist/advanced.d.cts +3 -3
- package/dist/advanced.d.ts +3 -3
- package/dist/advanced.js +3 -3
- package/dist/{chunk-GJTYOFMO.cjs → chunk-527QSKFM.cjs} +16 -16
- package/dist/{chunk-GJTYOFMO.cjs.map → chunk-527QSKFM.cjs.map} +1 -1
- package/dist/{chunk-RY4WDS6R.js → chunk-5KXEEQUO.js} +115 -20
- package/dist/chunk-5KXEEQUO.js.map +1 -0
- package/dist/{chunk-624QY53A.cjs → chunk-BSUMPMKX.cjs} +7 -7
- package/dist/chunk-BSUMPMKX.cjs.map +1 -0
- package/dist/{chunk-IUZXKAAY.js → chunk-FG3M7EBL.js} +2 -2
- package/dist/{chunk-PMF6MWEV.cjs → chunk-J74L7UYP.cjs} +128 -33
- package/dist/chunk-J74L7UYP.cjs.map +1 -0
- package/dist/{chunk-F3AIYQB7.js → chunk-QV5GOCR5.js} +3 -3
- package/dist/chunk-QV5GOCR5.js.map +1 -0
- package/dist/{context-B7UYnfzM.d.ts → context-4woHo7-L.d.ts} +1 -1
- package/dist/{context-UXySaqI_.d.cts → context-9gFXOdJl.d.cts} +1 -1
- package/dist/{effect-Auji1rz9.d.cts → effect-ClARNUCc.d.cts} +23 -2
- package/dist/{effect-Auji1rz9.d.ts → effect-ClARNUCc.d.ts} +23 -2
- package/dist/index.cjs +51 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.dev.js +96 -28
- package/dist/index.dev.js.map +1 -1
- package/dist/index.js +10 -13
- package/dist/index.js.map +1 -1
- package/dist/internal.cjs +44 -35
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +9 -4
- package/dist/internal.d.ts +9 -4
- package/dist/internal.js +12 -3
- package/dist/internal.js.map +1 -1
- package/dist/jsx-runtime.d.cts +671 -0
- package/dist/jsx-runtime.d.ts +671 -0
- package/dist/{props-ES0Ag_Wd.d.ts → props-CBwuh35e.d.cts} +13 -6
- package/dist/{props-CrOMYbLv.d.cts → props-DAyeRPwH.d.ts} +13 -6
- package/dist/{scope-S6eAzBJZ.d.ts → scope-DvgMquEy.d.ts} +1 -1
- package/dist/{scope-DKYzWfTn.d.cts → scope-xmdo6lVU.d.cts} +1 -1
- package/package.json +1 -1
- package/src/binding.ts +62 -8
- package/src/constants.ts +2 -3
- package/src/dev-entry.ts +22 -0
- package/src/effect.ts +9 -2
- package/src/lifecycle.ts +24 -6
- package/src/list-helpers.ts +14 -3
- package/src/props.ts +29 -3
- package/src/scope.ts +1 -1
- package/src/signal.ts +43 -4
- package/src/suspense.ts +17 -13
- package/dist/chunk-624QY53A.cjs.map +0 -1
- package/dist/chunk-F3AIYQB7.js.map +0 -1
- package/dist/chunk-PMF6MWEV.cjs.map +0 -1
- package/dist/chunk-RY4WDS6R.js.map +0 -1
- /package/dist/{chunk-IUZXKAAY.js.map → chunk-FG3M7EBL.js.map} +0 -0
package/dist/index.dev.js
CHANGED
|
@@ -132,8 +132,8 @@ var currentRoot;
|
|
|
132
132
|
var currentEffectCleanups;
|
|
133
133
|
var globalErrorHandlers = /* @__PURE__ */ new WeakMap();
|
|
134
134
|
var globalSuspenseHandlers = /* @__PURE__ */ new WeakMap();
|
|
135
|
-
function createRootContext(parent
|
|
136
|
-
return { parent, cleanups: [], destroyCallbacks: [] };
|
|
135
|
+
function createRootContext(parent) {
|
|
136
|
+
return { parent, cleanups: [], destroyCallbacks: [], suspended: false };
|
|
137
137
|
}
|
|
138
138
|
function pushRoot(root) {
|
|
139
139
|
if (!enterRootGuard(root)) {
|
|
@@ -208,8 +208,9 @@ function destroyRoot(root) {
|
|
|
208
208
|
globalSuspenseHandlers.delete(root);
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
|
-
function createRoot(fn) {
|
|
212
|
-
const
|
|
211
|
+
function createRoot(fn, options) {
|
|
212
|
+
const parent = options?.inherit ? currentRoot : void 0;
|
|
213
|
+
const root = createRootContext(parent);
|
|
213
214
|
const prev = pushRoot(root);
|
|
214
215
|
let value;
|
|
215
216
|
try {
|
|
@@ -334,13 +335,17 @@ function handleError(err, info, startRoot) {
|
|
|
334
335
|
}
|
|
335
336
|
function handleSuspend(token, startRoot) {
|
|
336
337
|
let root = startRoot ?? currentRoot;
|
|
338
|
+
const originRoot = root;
|
|
337
339
|
while (root) {
|
|
338
340
|
const handlers = root.suspenseHandlers;
|
|
339
341
|
if (handlers && handlers.length) {
|
|
340
342
|
for (let i = handlers.length - 1; i >= 0; i--) {
|
|
341
343
|
const handler = handlers[i];
|
|
342
344
|
const handled = handler(token);
|
|
343
|
-
if (handled !== false)
|
|
345
|
+
if (handled !== false) {
|
|
346
|
+
if (originRoot) originRoot.suspended = true;
|
|
347
|
+
return true;
|
|
348
|
+
}
|
|
344
349
|
}
|
|
345
350
|
}
|
|
346
351
|
root = root.parent;
|
|
@@ -350,7 +355,10 @@ function handleSuspend(token, startRoot) {
|
|
|
350
355
|
for (let i = globalForRoot.length - 1; i >= 0; i--) {
|
|
351
356
|
const handler = globalForRoot[i];
|
|
352
357
|
const handled = handler(token);
|
|
353
|
-
if (handled !== false)
|
|
358
|
+
if (handled !== false) {
|
|
359
|
+
if (originRoot) originRoot.suspended = true;
|
|
360
|
+
return true;
|
|
361
|
+
}
|
|
354
362
|
}
|
|
355
363
|
}
|
|
356
364
|
return false;
|
|
@@ -674,7 +682,25 @@ function runEffect(e) {
|
|
|
674
682
|
inCleanup = false;
|
|
675
683
|
}
|
|
676
684
|
}
|
|
677
|
-
|
|
685
|
+
let isDirty = false;
|
|
686
|
+
try {
|
|
687
|
+
isDirty = checkDirty(e.deps, e);
|
|
688
|
+
} catch (err) {
|
|
689
|
+
if (handleSuspend(err, e.root)) {
|
|
690
|
+
if (e.flags !== 0) {
|
|
691
|
+
e.flags = Watching;
|
|
692
|
+
}
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
if (handleError(err, { source: "effect" }, e.root)) {
|
|
696
|
+
if (e.flags !== 0) {
|
|
697
|
+
e.flags = Watching;
|
|
698
|
+
}
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
throw err;
|
|
702
|
+
}
|
|
703
|
+
if (isDirty) {
|
|
678
704
|
++cycle;
|
|
679
705
|
effectRunDevtools(e);
|
|
680
706
|
e.depsTail = void 0;
|
|
@@ -851,7 +877,7 @@ function computedOper() {
|
|
|
851
877
|
if (activeSub !== void 0) link(this, activeSub, cycle);
|
|
852
878
|
return this.value;
|
|
853
879
|
}
|
|
854
|
-
function effectWithCleanup(fn, cleanupRunner) {
|
|
880
|
+
function effectWithCleanup(fn, cleanupRunner, root) {
|
|
855
881
|
const e = {
|
|
856
882
|
fn,
|
|
857
883
|
subs: void 0,
|
|
@@ -862,6 +888,10 @@ function effectWithCleanup(fn, cleanupRunner) {
|
|
|
862
888
|
runCleanup: cleanupRunner,
|
|
863
889
|
__id: void 0
|
|
864
890
|
};
|
|
891
|
+
const resolvedRoot = root ?? getCurrentRoot();
|
|
892
|
+
if (resolvedRoot) {
|
|
893
|
+
e.root = resolvedRoot;
|
|
894
|
+
}
|
|
865
895
|
registerEffectDevtools(e);
|
|
866
896
|
const prevSub = activeSub;
|
|
867
897
|
if (prevSub !== void 0) link(e, prevSub, 0);
|
|
@@ -919,6 +949,18 @@ function untrack(fn) {
|
|
|
919
949
|
activeSub = prev;
|
|
920
950
|
}
|
|
921
951
|
}
|
|
952
|
+
function isSignal(fn) {
|
|
953
|
+
return typeof fn === "function" && fn[SIGNAL_MARKER] === true;
|
|
954
|
+
}
|
|
955
|
+
function isComputed(fn) {
|
|
956
|
+
return typeof fn === "function" && fn[COMPUTED_MARKER] === true;
|
|
957
|
+
}
|
|
958
|
+
function isEffect(fn) {
|
|
959
|
+
return typeof fn === "function" && fn[EFFECT_MARKER] === true;
|
|
960
|
+
}
|
|
961
|
+
function isEffectScope(fn) {
|
|
962
|
+
return typeof fn === "function" && fn[EFFECT_SCOPE_MARKER] === true;
|
|
963
|
+
}
|
|
922
964
|
function setTransitionContext(value) {
|
|
923
965
|
const prev = isInTransition;
|
|
924
966
|
isInTransition = value;
|
|
@@ -985,6 +1027,9 @@ function createEffect(fn) {
|
|
|
985
1027
|
bucket.push(maybeCleanup);
|
|
986
1028
|
}
|
|
987
1029
|
} catch (err) {
|
|
1030
|
+
if (handleSuspend(err, rootForError)) {
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
988
1033
|
if (handleError(err, { source: "effect" }, rootForError)) {
|
|
989
1034
|
return;
|
|
990
1035
|
}
|
|
@@ -993,7 +1038,7 @@ function createEffect(fn) {
|
|
|
993
1038
|
});
|
|
994
1039
|
cleanups = bucket;
|
|
995
1040
|
};
|
|
996
|
-
const disposeEffect = effectWithCleanup(run, doCleanup);
|
|
1041
|
+
const disposeEffect = effectWithCleanup(run, doCleanup, rootForError);
|
|
997
1042
|
const teardown = () => {
|
|
998
1043
|
runCleanupList(cleanups);
|
|
999
1044
|
disposeEffect();
|
|
@@ -1017,6 +1062,9 @@ function createRenderEffect(fn) {
|
|
|
1017
1062
|
cleanup = maybeCleanup;
|
|
1018
1063
|
}
|
|
1019
1064
|
} catch (err) {
|
|
1065
|
+
if (handleSuspend(err, rootForError)) {
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1020
1068
|
const handled = handleError(err, { source: "effect" }, rootForError);
|
|
1021
1069
|
if (handled) {
|
|
1022
1070
|
return;
|
|
@@ -1024,7 +1072,7 @@ function createRenderEffect(fn) {
|
|
|
1024
1072
|
throw err;
|
|
1025
1073
|
}
|
|
1026
1074
|
};
|
|
1027
|
-
const disposeEffect = effectWithCleanup(run, doCleanup);
|
|
1075
|
+
const disposeEffect = effectWithCleanup(run, doCleanup, rootForError);
|
|
1028
1076
|
const teardown = () => {
|
|
1029
1077
|
if (cleanup) {
|
|
1030
1078
|
cleanup();
|
|
@@ -1301,8 +1349,7 @@ function getPropAlias(prop2, tagName) {
|
|
|
1301
1349
|
return a;
|
|
1302
1350
|
}
|
|
1303
1351
|
var $$EVENTS = "_$FICT_DELEGATE";
|
|
1304
|
-
var
|
|
1305
|
-
var DelegatedEvents = new Set(delegatedEvents);
|
|
1352
|
+
var DelegatedEvents = new Set(DelegatedEventNames);
|
|
1306
1353
|
var svgElements = isDev4 ? [
|
|
1307
1354
|
"altGlyph",
|
|
1308
1355
|
"altGlyphDef",
|
|
@@ -1612,7 +1659,10 @@ function removeNodes(nodes) {
|
|
|
1612
1659
|
// src/binding.ts
|
|
1613
1660
|
var isDev5 = true ? true : typeof process === "undefined" || process.env?.NODE_ENV !== "production";
|
|
1614
1661
|
function isReactive(value) {
|
|
1615
|
-
|
|
1662
|
+
if (typeof value !== "function") return false;
|
|
1663
|
+
if (isSignal(value) || isComputed(value)) return true;
|
|
1664
|
+
if (isEffect(value) || isEffectScope(value)) return false;
|
|
1665
|
+
return value.length === 0;
|
|
1616
1666
|
}
|
|
1617
1667
|
function callEventHandler(handler, event, node, data) {
|
|
1618
1668
|
if (!handler) return;
|
|
@@ -1907,7 +1957,8 @@ function bindEvent(el, eventName, handler, options) {
|
|
|
1907
1957
|
if (handler == null) return () => {
|
|
1908
1958
|
};
|
|
1909
1959
|
const rootRef = getCurrentRoot();
|
|
1910
|
-
|
|
1960
|
+
const shouldDelegate = options == null && DelegatedEvents.has(eventName);
|
|
1961
|
+
if (shouldDelegate) {
|
|
1911
1962
|
const key = `$$${eventName}`;
|
|
1912
1963
|
delegateEvents([eventName]);
|
|
1913
1964
|
const resolveHandler = isReactive(handler) ? handler : () => handler;
|
|
@@ -2026,17 +2077,27 @@ function __fictPopContext() {
|
|
|
2026
2077
|
}
|
|
2027
2078
|
|
|
2028
2079
|
// src/props.ts
|
|
2080
|
+
var PROP_GETTER_MARKER = Symbol.for("fict:prop-getter");
|
|
2029
2081
|
var propGetters = /* @__PURE__ */ new WeakSet();
|
|
2030
2082
|
var rawToProxy = /* @__PURE__ */ new WeakMap();
|
|
2031
2083
|
var proxyToRaw = /* @__PURE__ */ new WeakMap();
|
|
2032
2084
|
function __fictProp(getter) {
|
|
2033
2085
|
if (typeof getter === "function" && getter.length === 0) {
|
|
2034
2086
|
propGetters.add(getter);
|
|
2087
|
+
if (Object.isExtensible(getter)) {
|
|
2088
|
+
try {
|
|
2089
|
+
;
|
|
2090
|
+
getter[PROP_GETTER_MARKER] = true;
|
|
2091
|
+
} catch {
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2035
2094
|
}
|
|
2036
2095
|
return getter;
|
|
2037
2096
|
}
|
|
2038
2097
|
function isPropGetter(value) {
|
|
2039
|
-
|
|
2098
|
+
if (typeof value !== "function") return false;
|
|
2099
|
+
const fn = value;
|
|
2100
|
+
return propGetters.has(fn) || fn[PROP_GETTER_MARKER] === true;
|
|
2040
2101
|
}
|
|
2041
2102
|
function createPropsProxy(props) {
|
|
2042
2103
|
if (!props || typeof props !== "object") {
|
|
@@ -2150,11 +2211,21 @@ function mergeProps(...sources) {
|
|
|
2150
2211
|
}
|
|
2151
2212
|
});
|
|
2152
2213
|
}
|
|
2153
|
-
function prop(getter) {
|
|
2214
|
+
function prop(getter, options) {
|
|
2154
2215
|
if (isPropGetter(getter)) {
|
|
2155
2216
|
return getter;
|
|
2156
2217
|
}
|
|
2157
|
-
|
|
2218
|
+
const fn = getter;
|
|
2219
|
+
const unwrap = options?.unwrap !== false;
|
|
2220
|
+
return __fictProp(
|
|
2221
|
+
createMemo(() => {
|
|
2222
|
+
const value = fn();
|
|
2223
|
+
if (unwrap && isPropGetter(value)) {
|
|
2224
|
+
return value();
|
|
2225
|
+
}
|
|
2226
|
+
return value;
|
|
2227
|
+
})
|
|
2228
|
+
);
|
|
2158
2229
|
}
|
|
2159
2230
|
|
|
2160
2231
|
// src/dom.ts
|
|
@@ -2666,10 +2737,6 @@ function Suspense(props) {
|
|
|
2666
2737
|
let epoch = 0;
|
|
2667
2738
|
const hostRoot = getCurrentRoot();
|
|
2668
2739
|
const toFallback = (err) => typeof props.fallback === "function" ? props.fallback(err) : props.fallback;
|
|
2669
|
-
const switchView = (view) => {
|
|
2670
|
-
currentView(view);
|
|
2671
|
-
renderView(view);
|
|
2672
|
-
};
|
|
2673
2740
|
const renderView = (view) => {
|
|
2674
2741
|
if (cleanup) {
|
|
2675
2742
|
cleanup();
|
|
@@ -2688,7 +2755,7 @@ function Suspense(props) {
|
|
|
2688
2755
|
try {
|
|
2689
2756
|
const output = createElement(view);
|
|
2690
2757
|
nodes = toNodeArray(output);
|
|
2691
|
-
const suspendedAttempt = nodes.length > 0 && nodes.every((node) => node instanceof Comment && node.data === "fict:suspend");
|
|
2758
|
+
const suspendedAttempt = root.suspended || nodes.length > 0 && nodes.every((node) => node instanceof Comment && node.data === "fict:suspend");
|
|
2692
2759
|
if (suspendedAttempt) {
|
|
2693
2760
|
popRoot(prev);
|
|
2694
2761
|
destroyRoot(root);
|
|
@@ -2729,7 +2796,8 @@ function Suspense(props) {
|
|
|
2729
2796
|
registerSuspenseHandler((token) => {
|
|
2730
2797
|
const tokenEpoch = epoch;
|
|
2731
2798
|
pending(pending() + 1);
|
|
2732
|
-
|
|
2799
|
+
currentView(toFallback());
|
|
2800
|
+
renderView(toFallback());
|
|
2733
2801
|
const thenable = token.then ? token : isThenable(token) ? token : null;
|
|
2734
2802
|
if (thenable) {
|
|
2735
2803
|
thenable.then(
|
|
@@ -2740,7 +2808,8 @@ function Suspense(props) {
|
|
|
2740
2808
|
const newPending = Math.max(0, pending() - 1);
|
|
2741
2809
|
pending(newPending);
|
|
2742
2810
|
if (newPending === 0) {
|
|
2743
|
-
|
|
2811
|
+
currentView(props.children ?? null);
|
|
2812
|
+
renderView(props.children ?? null);
|
|
2744
2813
|
onResolveMaybe();
|
|
2745
2814
|
}
|
|
2746
2815
|
},
|
|
@@ -2760,9 +2829,7 @@ function Suspense(props) {
|
|
|
2760
2829
|
}
|
|
2761
2830
|
return false;
|
|
2762
2831
|
});
|
|
2763
|
-
|
|
2764
|
-
renderView(currentView());
|
|
2765
|
-
});
|
|
2832
|
+
renderView(props.children ?? null);
|
|
2766
2833
|
if (props.resetKeys !== void 0) {
|
|
2767
2834
|
const isGetter = typeof props.resetKeys === "function" && props.resetKeys.length === 0;
|
|
2768
2835
|
const getter = isGetter ? props.resetKeys : void 0;
|
|
@@ -2773,7 +2840,8 @@ function Suspense(props) {
|
|
|
2773
2840
|
prev = next;
|
|
2774
2841
|
epoch++;
|
|
2775
2842
|
pending(0);
|
|
2776
|
-
|
|
2843
|
+
currentView(props.children ?? null);
|
|
2844
|
+
renderView(props.children ?? null);
|
|
2777
2845
|
}
|
|
2778
2846
|
});
|
|
2779
2847
|
}
|