@fictjs/runtime 0.0.3 → 0.0.5
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/README.md +1 -1
- package/dist/index.cjs +761 -707
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +889 -858
- package/dist/index.d.ts +889 -858
- package/dist/index.dev.js +765 -710
- package/dist/index.dev.js.map +1 -1
- package/dist/index.js +758 -708
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.d.cts +671 -0
- package/dist/jsx-dev-runtime.d.ts +671 -0
- package/dist/slim.cjs +119 -37
- package/dist/slim.cjs.map +1 -1
- package/dist/slim.d.cts +31 -4
- package/dist/slim.d.ts +31 -4
- package/dist/slim.js +117 -38
- package/dist/slim.js.map +1 -1
- package/package.json +2 -2
- package/src/binding.ts +49 -31
- package/src/index.ts +3 -0
- package/src/scope.ts +55 -0
- package/src/slim.ts +1 -0
package/dist/slim.cjs
CHANGED
|
@@ -101,6 +101,7 @@ function reportCycle(reason, detail = void 0) {
|
|
|
101
101
|
|
|
102
102
|
// src/lifecycle.ts
|
|
103
103
|
var currentRoot;
|
|
104
|
+
var currentEffectCleanups;
|
|
104
105
|
var globalErrorHandlers = /* @__PURE__ */ new WeakMap();
|
|
105
106
|
var globalSuspenseHandlers = /* @__PURE__ */ new WeakMap();
|
|
106
107
|
function createRootContext(parent = currentRoot) {
|
|
@@ -130,6 +131,9 @@ function onDestroy(fn) {
|
|
|
130
131
|
}
|
|
131
132
|
runLifecycle(fn);
|
|
132
133
|
}
|
|
134
|
+
function onCleanup(fn) {
|
|
135
|
+
registerEffectCleanup(fn);
|
|
136
|
+
}
|
|
133
137
|
function flushOnMount(root) {
|
|
134
138
|
const cbs = root.onMountCallbacks;
|
|
135
139
|
if (!cbs || cbs.length === 0) return;
|
|
@@ -168,10 +172,35 @@ function destroyRoot(root) {
|
|
|
168
172
|
globalSuspenseHandlers.delete(root);
|
|
169
173
|
}
|
|
170
174
|
}
|
|
175
|
+
function createRoot(fn) {
|
|
176
|
+
const root = createRootContext();
|
|
177
|
+
const prev = pushRoot(root);
|
|
178
|
+
let value;
|
|
179
|
+
try {
|
|
180
|
+
value = fn();
|
|
181
|
+
} finally {
|
|
182
|
+
popRoot(prev);
|
|
183
|
+
}
|
|
184
|
+
flushOnMount(root);
|
|
185
|
+
return {
|
|
186
|
+
dispose: () => destroyRoot(root),
|
|
187
|
+
value
|
|
188
|
+
};
|
|
189
|
+
}
|
|
171
190
|
function withEffectCleanups(bucket, fn) {
|
|
191
|
+
const prev = currentEffectCleanups;
|
|
192
|
+
currentEffectCleanups = bucket;
|
|
172
193
|
try {
|
|
173
194
|
return fn();
|
|
174
195
|
} finally {
|
|
196
|
+
currentEffectCleanups = prev;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function registerEffectCleanup(fn) {
|
|
200
|
+
if (currentEffectCleanups) {
|
|
201
|
+
currentEffectCleanups.push(fn);
|
|
202
|
+
} else {
|
|
203
|
+
registerRootCleanup(fn);
|
|
175
204
|
}
|
|
176
205
|
}
|
|
177
206
|
function runCleanupList(list) {
|
|
@@ -720,6 +749,21 @@ function effect(fn) {
|
|
|
720
749
|
function effectOper() {
|
|
721
750
|
disposeNode(this);
|
|
722
751
|
}
|
|
752
|
+
function effectScope(fn) {
|
|
753
|
+
const e = { deps: void 0, depsTail: void 0, subs: void 0, subsTail: void 0, flags: 0 };
|
|
754
|
+
const prevSub = activeSub;
|
|
755
|
+
if (prevSub !== void 0) link(e, prevSub, 0);
|
|
756
|
+
activeSub = e;
|
|
757
|
+
try {
|
|
758
|
+
fn();
|
|
759
|
+
} finally {
|
|
760
|
+
activeSub = prevSub;
|
|
761
|
+
}
|
|
762
|
+
return effectScopeOper.bind(e);
|
|
763
|
+
}
|
|
764
|
+
function effectScopeOper() {
|
|
765
|
+
disposeNode(this);
|
|
766
|
+
}
|
|
723
767
|
function batch(fn) {
|
|
724
768
|
++batchDepth;
|
|
725
769
|
try {
|
|
@@ -863,14 +907,6 @@ function createRenderEffect(fn) {
|
|
|
863
907
|
return teardown;
|
|
864
908
|
}
|
|
865
909
|
|
|
866
|
-
// src/scheduler.ts
|
|
867
|
-
function batch2(fn) {
|
|
868
|
-
return batch(fn);
|
|
869
|
-
}
|
|
870
|
-
function untrack2(fn) {
|
|
871
|
-
return untrack(fn);
|
|
872
|
-
}
|
|
873
|
-
|
|
874
910
|
// src/constants.ts
|
|
875
911
|
var booleans = [
|
|
876
912
|
"allowfullscreen",
|
|
@@ -1313,6 +1349,27 @@ function removeNodes(nodes) {
|
|
|
1313
1349
|
function isReactive(value) {
|
|
1314
1350
|
return typeof value === "function" && value.length === 0;
|
|
1315
1351
|
}
|
|
1352
|
+
function callEventHandler(handler, event, node, data) {
|
|
1353
|
+
if (!handler) return;
|
|
1354
|
+
const context = node ?? event.currentTarget ?? void 0;
|
|
1355
|
+
const invoke = (fn) => {
|
|
1356
|
+
if (typeof fn === "function") {
|
|
1357
|
+
const result = data === void 0 ? fn.call(context, event) : fn.call(context, data, event);
|
|
1358
|
+
if (typeof result === "function" && result !== fn) {
|
|
1359
|
+
if (data === void 0) {
|
|
1360
|
+
result.call(context, event);
|
|
1361
|
+
} else {
|
|
1362
|
+
result.call(context, data, event);
|
|
1363
|
+
}
|
|
1364
|
+
} else if (result && typeof result.handleEvent === "function") {
|
|
1365
|
+
result.handleEvent.call(result, event);
|
|
1366
|
+
}
|
|
1367
|
+
} else if (fn && typeof fn.handleEvent === "function") {
|
|
1368
|
+
fn.handleEvent.call(fn, event);
|
|
1369
|
+
}
|
|
1370
|
+
};
|
|
1371
|
+
invoke(handler);
|
|
1372
|
+
}
|
|
1316
1373
|
var PRIMITIVE_PROXY = Symbol("fict:primitive-proxy");
|
|
1317
1374
|
var PRIMITIVE_PROXY_RAW_VALUE = Symbol("fict:primitive-proxy:raw-value");
|
|
1318
1375
|
function createValueProxy(read) {
|
|
@@ -1799,14 +1856,10 @@ function globalEventHandler(e) {
|
|
|
1799
1856
|
const hasData = rawData !== void 0;
|
|
1800
1857
|
const resolvedNodeData = hasData ? resolveData(rawData) : void 0;
|
|
1801
1858
|
if (typeof handler === "function") {
|
|
1802
|
-
|
|
1803
|
-
handler.call(node, resolvedNodeData, e);
|
|
1804
|
-
} else {
|
|
1805
|
-
handler.call(node, e);
|
|
1806
|
-
}
|
|
1859
|
+
callEventHandler(handler, e, node, hasData ? resolvedNodeData : void 0);
|
|
1807
1860
|
} else if (Array.isArray(handler)) {
|
|
1808
1861
|
const tupleData = resolveData(handler[1]);
|
|
1809
|
-
handler[0]
|
|
1862
|
+
callEventHandler(handler[0], e, node, tupleData);
|
|
1810
1863
|
}
|
|
1811
1864
|
if (e.cancelBubble) return false;
|
|
1812
1865
|
}
|
|
@@ -1854,23 +1907,15 @@ function bindEvent(el, eventName, handler, options2) {
|
|
|
1854
1907
|
if (DelegatedEvents.has(eventName) && !options2) {
|
|
1855
1908
|
const key = `$$${eventName}`;
|
|
1856
1909
|
delegateEvents([eventName]);
|
|
1857
|
-
const createWrapped = (resolve) => {
|
|
1858
|
-
const wrapped2 = function(...args) {
|
|
1859
|
-
try {
|
|
1860
|
-
const fn = resolve();
|
|
1861
|
-
if (typeof fn === "function") {
|
|
1862
|
-
return fn.apply(this, args);
|
|
1863
|
-
} else if (fn && typeof fn.handleEvent === "function") {
|
|
1864
|
-
return fn.handleEvent.apply(fn, args);
|
|
1865
|
-
}
|
|
1866
|
-
} catch (err) {
|
|
1867
|
-
handleError(err, { source: "event", eventName }, rootRef);
|
|
1868
|
-
}
|
|
1869
|
-
};
|
|
1870
|
-
return wrapped2;
|
|
1871
|
-
};
|
|
1872
1910
|
const resolveHandler = isReactive(handler) ? handler : () => handler;
|
|
1873
|
-
el[key] =
|
|
1911
|
+
el[key] = function(...args) {
|
|
1912
|
+
try {
|
|
1913
|
+
const fn = resolveHandler();
|
|
1914
|
+
callEventHandler(fn, args[0], el);
|
|
1915
|
+
} catch (err) {
|
|
1916
|
+
handleError(err, { source: "event", eventName }, rootRef);
|
|
1917
|
+
}
|
|
1918
|
+
};
|
|
1874
1919
|
return () => {
|
|
1875
1920
|
el[key] = void 0;
|
|
1876
1921
|
};
|
|
@@ -1879,13 +1924,7 @@ function bindEvent(el, eventName, handler, options2) {
|
|
|
1879
1924
|
const wrapped = (event) => {
|
|
1880
1925
|
try {
|
|
1881
1926
|
const resolved = getHandler();
|
|
1882
|
-
|
|
1883
|
-
;
|
|
1884
|
-
resolved(event);
|
|
1885
|
-
} else if (resolved && typeof resolved.handleEvent === "function") {
|
|
1886
|
-
;
|
|
1887
|
-
resolved.handleEvent(event);
|
|
1888
|
-
}
|
|
1927
|
+
callEventHandler(resolved, event, el);
|
|
1889
1928
|
} catch (err) {
|
|
1890
1929
|
if (handleError(err, { source: "event", eventName }, rootRef)) {
|
|
1891
1930
|
return;
|
|
@@ -2344,6 +2383,46 @@ function bumpBlockVersion(block) {
|
|
|
2344
2383
|
block.version(block.version() + 1);
|
|
2345
2384
|
}
|
|
2346
2385
|
|
|
2386
|
+
// src/scope.ts
|
|
2387
|
+
function createScope() {
|
|
2388
|
+
let dispose = null;
|
|
2389
|
+
const stop = () => {
|
|
2390
|
+
if (dispose) {
|
|
2391
|
+
dispose();
|
|
2392
|
+
dispose = null;
|
|
2393
|
+
}
|
|
2394
|
+
};
|
|
2395
|
+
const run = (fn) => {
|
|
2396
|
+
stop();
|
|
2397
|
+
const { dispose: rootDispose, value } = createRoot(fn);
|
|
2398
|
+
dispose = rootDispose;
|
|
2399
|
+
return value;
|
|
2400
|
+
};
|
|
2401
|
+
registerRootCleanup(stop);
|
|
2402
|
+
return { run, stop };
|
|
2403
|
+
}
|
|
2404
|
+
function runInScope(flag, fn) {
|
|
2405
|
+
const scope = createScope();
|
|
2406
|
+
const evaluate = () => isReactive(flag) ? flag() : !!flag;
|
|
2407
|
+
createEffect(() => {
|
|
2408
|
+
const enabled = evaluate();
|
|
2409
|
+
if (enabled) {
|
|
2410
|
+
scope.run(fn);
|
|
2411
|
+
} else {
|
|
2412
|
+
scope.stop();
|
|
2413
|
+
}
|
|
2414
|
+
});
|
|
2415
|
+
onCleanup(scope.stop);
|
|
2416
|
+
}
|
|
2417
|
+
|
|
2418
|
+
// src/scheduler.ts
|
|
2419
|
+
function batch2(fn) {
|
|
2420
|
+
return batch(fn);
|
|
2421
|
+
}
|
|
2422
|
+
function untrack2(fn) {
|
|
2423
|
+
return untrack(fn);
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2347
2426
|
// src/hooks.ts
|
|
2348
2427
|
var ctxStack = [];
|
|
2349
2428
|
function __fictUseContext() {
|
|
@@ -3363,10 +3442,12 @@ exports.createList = createList;
|
|
|
3363
3442
|
exports.createMemo = createMemo;
|
|
3364
3443
|
exports.createPropsProxy = createPropsProxy;
|
|
3365
3444
|
exports.createRenderEffect = createRenderEffect;
|
|
3445
|
+
exports.createScope = createScope;
|
|
3366
3446
|
exports.createSelector = createSelector;
|
|
3367
3447
|
exports.createSignal = signal;
|
|
3368
3448
|
exports.delegateEvents = delegateEvents;
|
|
3369
3449
|
exports.destroyMarkerBlock = destroyMarkerBlock;
|
|
3450
|
+
exports.effectScope = effectScope;
|
|
3370
3451
|
exports.getFirstNodeAfter = getFirstNodeAfter;
|
|
3371
3452
|
exports.insert = insert;
|
|
3372
3453
|
exports.insertNodesBefore = insertNodesBefore;
|
|
@@ -3376,6 +3457,7 @@ exports.onDestroy = onDestroy;
|
|
|
3376
3457
|
exports.prop = __fictProp;
|
|
3377
3458
|
exports.removeNodes = removeNodes;
|
|
3378
3459
|
exports.render = render;
|
|
3460
|
+
exports.runInScope = runInScope;
|
|
3379
3461
|
exports.template = template;
|
|
3380
3462
|
exports.toNodeArray = toNodeArray;
|
|
3381
3463
|
exports.untrack = untrack2;
|