@getforma/core 0.3.0 → 0.6.1
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 +201 -13
- package/dist/{chunk-KX5WRZH7.js → chunk-DPSAVBCP.js} +3 -4
- package/dist/chunk-DPSAVBCP.js.map +1 -0
- package/dist/{chunk-FPSLC62A.cjs → chunk-KH3F5NRU.cjs} +2 -4
- package/dist/chunk-KH3F5NRU.cjs.map +1 -0
- package/dist/{chunk-VKKPX4YU.js → chunk-TKGUHASG.js} +79 -19
- package/dist/chunk-TKGUHASG.js.map +1 -0
- package/dist/{chunk-VP5EOGM5.cjs → chunk-YSKF3VRA.cjs} +87 -26
- package/dist/chunk-YSKF3VRA.cjs.map +1 -0
- package/dist/forma-runtime-csp.js +2 -0
- package/dist/forma-runtime.js +2 -0
- package/dist/formajs-runtime-hardened.global.js +1 -1
- package/dist/formajs-runtime-hardened.global.js.map +1 -1
- package/dist/formajs-runtime.global.js +1 -1
- package/dist/formajs-runtime.global.js.map +1 -1
- package/dist/formajs.global.js +1 -1
- package/dist/formajs.global.js.map +1 -1
- package/dist/index.cjs +154 -96
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +83 -35
- package/dist/index.d.ts +83 -35
- package/dist/index.js +99 -40
- package/dist/index.js.map +1 -1
- package/dist/runtime-hardened.cjs +224 -60
- package/dist/runtime-hardened.cjs.map +1 -1
- package/dist/runtime-hardened.d.cts +86 -0
- package/dist/runtime-hardened.d.ts +86 -0
- package/dist/runtime-hardened.js +225 -61
- package/dist/runtime-hardened.js.map +1 -1
- package/dist/runtime.cjs +248 -83
- package/dist/runtime.cjs.map +1 -1
- package/dist/runtime.js +226 -61
- package/dist/runtime.js.map +1 -1
- package/dist/ssr/index.cjs +69 -73
- package/dist/ssr/index.cjs.map +1 -1
- package/dist/ssr/index.d.cts +4 -0
- package/dist/ssr/index.d.ts +4 -0
- package/dist/ssr/index.js +69 -73
- package/dist/ssr/index.js.map +1 -1
- package/dist/tc39-compat.cjs +3 -3
- package/dist/tc39-compat.js +1 -1
- package/package.json +24 -3
- package/dist/chunk-FPSLC62A.cjs.map +0 -1
- package/dist/chunk-KX5WRZH7.js.map +0 -1
- package/dist/chunk-VKKPX4YU.js.map +0 -1
- package/dist/chunk-VP5EOGM5.cjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkKH3F5NRU_cjs = require('./chunk-KH3F5NRU.cjs');
|
|
4
4
|
var alienSignals = require('alien-signals');
|
|
5
5
|
|
|
6
6
|
// src/reactive/root.ts
|
|
@@ -23,7 +23,7 @@ function createRoot(fn) {
|
|
|
23
23
|
return fn(dispose);
|
|
24
24
|
} finally {
|
|
25
25
|
currentRoot = rootStack.pop() ?? null;
|
|
26
|
-
if (rootStack.length === 0
|
|
26
|
+
if (rootStack.length === 0) {
|
|
27
27
|
rootStack.length = 0;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
@@ -229,7 +229,7 @@ function createEffect(fn) {
|
|
|
229
229
|
}
|
|
230
230
|
|
|
231
231
|
// src/reactive/memo.ts
|
|
232
|
-
var createMemo =
|
|
232
|
+
var createMemo = chunkKH3F5NRU_cjs.createComputed;
|
|
233
233
|
function batch(fn) {
|
|
234
234
|
alienSignals.startBatch();
|
|
235
235
|
try {
|
|
@@ -271,7 +271,7 @@ function createRef(initialValue) {
|
|
|
271
271
|
|
|
272
272
|
// src/reactive/reducer.ts
|
|
273
273
|
function createReducer(reducer, initialState) {
|
|
274
|
-
const [state, setState] =
|
|
274
|
+
const [state, setState] = chunkKH3F5NRU_cjs.createSignal(initialState);
|
|
275
275
|
const dispatch = (action) => {
|
|
276
276
|
setState((prev) => reducer(prev, action));
|
|
277
277
|
};
|
|
@@ -294,9 +294,9 @@ function getSuspenseContext() {
|
|
|
294
294
|
|
|
295
295
|
// src/reactive/resource.ts
|
|
296
296
|
function createResource(source, fetcher, options) {
|
|
297
|
-
const [data, setData] =
|
|
298
|
-
const [loading, setLoading] =
|
|
299
|
-
const [error, setError] =
|
|
297
|
+
const [data, setData] = chunkKH3F5NRU_cjs.createSignal(options?.initialValue);
|
|
298
|
+
const [loading, setLoading] = chunkKH3F5NRU_cjs.createSignal(false);
|
|
299
|
+
const [error, setError] = chunkKH3F5NRU_cjs.createSignal(void 0);
|
|
300
300
|
const suspenseCtx = getSuspenseContext();
|
|
301
301
|
let abortController = null;
|
|
302
302
|
let fetchVersion = 0;
|
|
@@ -564,8 +564,47 @@ function handleEvent(el, key, value2) {
|
|
|
564
564
|
);
|
|
565
565
|
}
|
|
566
566
|
function handleInnerHTML(el, _key, value2) {
|
|
567
|
-
|
|
568
|
-
|
|
567
|
+
if (typeof value2 === "function") {
|
|
568
|
+
internalEffect(() => {
|
|
569
|
+
const resolved = value2();
|
|
570
|
+
if (resolved == null) {
|
|
571
|
+
el.innerHTML = "";
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
if (typeof resolved !== "object" || !("__html" in resolved)) {
|
|
575
|
+
throw new TypeError(
|
|
576
|
+
"dangerouslySetInnerHTML: expected { __html: string }, got " + typeof resolved
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
const html = resolved.__html;
|
|
580
|
+
if (typeof html !== "string") {
|
|
581
|
+
throw new TypeError(
|
|
582
|
+
"dangerouslySetInnerHTML: __html must be a string, got " + typeof html
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
const cache = getCache(el);
|
|
586
|
+
if (cache["innerHTML"] === html) return;
|
|
587
|
+
cache["innerHTML"] = html;
|
|
588
|
+
el.innerHTML = html;
|
|
589
|
+
});
|
|
590
|
+
} else {
|
|
591
|
+
if (value2 == null) {
|
|
592
|
+
el.innerHTML = "";
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
if (typeof value2 !== "object" || !("__html" in value2)) {
|
|
596
|
+
throw new TypeError(
|
|
597
|
+
"dangerouslySetInnerHTML: expected { __html: string }, got " + typeof value2
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
const html = value2.__html;
|
|
601
|
+
if (typeof html !== "string") {
|
|
602
|
+
throw new TypeError(
|
|
603
|
+
"dangerouslySetInnerHTML: __html must be a string, got " + typeof html
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
el.innerHTML = html;
|
|
607
|
+
}
|
|
569
608
|
}
|
|
570
609
|
function handleXLink(el, key, value2) {
|
|
571
610
|
const localName = key.slice(6);
|
|
@@ -687,7 +726,18 @@ function applyStaticProp(el, key, value2) {
|
|
|
687
726
|
return;
|
|
688
727
|
}
|
|
689
728
|
if (key === "dangerouslySetInnerHTML") {
|
|
690
|
-
|
|
729
|
+
if (typeof value2 !== "object" || !("__html" in value2)) {
|
|
730
|
+
throw new TypeError(
|
|
731
|
+
"dangerouslySetInnerHTML: expected { __html: string }, got " + typeof value2
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
const html = value2.__html;
|
|
735
|
+
if (typeof html !== "string") {
|
|
736
|
+
throw new TypeError(
|
|
737
|
+
"dangerouslySetInnerHTML: __html must be a string, got " + typeof html
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
el.innerHTML = html;
|
|
691
741
|
return;
|
|
692
742
|
}
|
|
693
743
|
if (key.charCodeAt(0) === 120 && key.startsWith("xlink:")) {
|
|
@@ -758,6 +808,10 @@ function appendChild(parent, child) {
|
|
|
758
808
|
}
|
|
759
809
|
}
|
|
760
810
|
function h(tag, props, ...children) {
|
|
811
|
+
if (typeof tag === "function" && tag !== Fragment) {
|
|
812
|
+
const mergedProps = { ...props ?? {}, children };
|
|
813
|
+
return tag(mergedProps);
|
|
814
|
+
}
|
|
761
815
|
if (tag === Fragment) {
|
|
762
816
|
const frag = document.createDocumentFragment();
|
|
763
817
|
for (const child of children) {
|
|
@@ -845,10 +899,10 @@ function createShow(when, thenFn, elseFn) {
|
|
|
845
899
|
let currentNode = null;
|
|
846
900
|
let lastTruthy = null;
|
|
847
901
|
let currentDispose = null;
|
|
848
|
-
const DEBUG_LABEL = thenFn.toString().slice(0, 60);
|
|
849
902
|
const showDispose = internalEffect(() => {
|
|
850
903
|
const truthy = !!when();
|
|
851
904
|
const DEBUG = typeof globalThis.__FORMA_DEBUG__ !== "undefined";
|
|
905
|
+
const DEBUG_LABEL = DEBUG ? thenFn.toString().slice(0, 60) : "";
|
|
852
906
|
if (truthy === lastTruthy) {
|
|
853
907
|
if (DEBUG) console.log("[forma:show] skip (same)", truthy, DEBUG_LABEL);
|
|
854
908
|
return;
|
|
@@ -900,18 +954,19 @@ function createShow(when, thenFn, elseFn) {
|
|
|
900
954
|
}
|
|
901
955
|
|
|
902
956
|
// src/dom/hydrate.ts
|
|
957
|
+
var ABORT_SYM2 = /* @__PURE__ */ Symbol.for("forma-abort");
|
|
903
958
|
var hydrating = false;
|
|
904
959
|
function setHydrating(value2) {
|
|
905
960
|
hydrating = value2;
|
|
906
961
|
}
|
|
907
962
|
function isDescriptor(v) {
|
|
908
|
-
return v != null && typeof v === "object" && v.type === "element";
|
|
963
|
+
return v != null && typeof v === "object" && "type" in v && v.type === "element";
|
|
909
964
|
}
|
|
910
965
|
function isShowDescriptor(v) {
|
|
911
|
-
return v != null && typeof v === "object" && v.type === "show";
|
|
966
|
+
return v != null && typeof v === "object" && "type" in v && v.type === "show";
|
|
912
967
|
}
|
|
913
968
|
function isListDescriptor(v) {
|
|
914
|
-
return v != null && typeof v === "object" && v.type === "list";
|
|
969
|
+
return v != null && typeof v === "object" && "type" in v && v.type === "list";
|
|
915
970
|
}
|
|
916
971
|
function applyDynamicProps(el, props) {
|
|
917
972
|
if (!props) return;
|
|
@@ -919,7 +974,12 @@ function applyDynamicProps(el, props) {
|
|
|
919
974
|
const value2 = props[key];
|
|
920
975
|
if (typeof value2 !== "function") continue;
|
|
921
976
|
if (key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && key.length > 2) {
|
|
922
|
-
el
|
|
977
|
+
let ac = el[ABORT_SYM2];
|
|
978
|
+
if (!ac) {
|
|
979
|
+
ac = new AbortController();
|
|
980
|
+
el[ABORT_SYM2] = ac;
|
|
981
|
+
}
|
|
982
|
+
el.addEventListener(key.slice(2).toLowerCase(), value2, { signal: ac.signal });
|
|
923
983
|
continue;
|
|
924
984
|
}
|
|
925
985
|
const fn = value2;
|
|
@@ -1089,7 +1149,7 @@ function adoptBranchContent(desc, regionStart, regionEnd) {
|
|
|
1089
1149
|
}
|
|
1090
1150
|
function adoptNode(desc, ssrEl) {
|
|
1091
1151
|
if (!ssrEl || ssrEl.tagName !== desc.tag.toUpperCase()) {
|
|
1092
|
-
console.warn(`Hydration mismatch: expected <${desc.tag}>, got <${ssrEl?.tagName?.toLowerCase() ?? "nothing"}>`);
|
|
1152
|
+
if (__DEV__) console.warn(`Hydration mismatch: expected <${desc.tag}>, got <${ssrEl?.tagName?.toLowerCase() ?? "nothing"}>`);
|
|
1093
1153
|
const fresh = descriptorToElement(desc);
|
|
1094
1154
|
if (ssrEl) ssrEl.replaceWith(fresh);
|
|
1095
1155
|
return;
|
|
@@ -1191,7 +1251,7 @@ function adoptNode(desc, ssrEl) {
|
|
|
1191
1251
|
const prevHydrating = hydrating;
|
|
1192
1252
|
hydrating = false;
|
|
1193
1253
|
try {
|
|
1194
|
-
const [getIndex] =
|
|
1254
|
+
const [getIndex] = chunkKH3F5NRU_cjs.createSignal(i);
|
|
1195
1255
|
const fresh = listRenderFn(item, getIndex);
|
|
1196
1256
|
end.parentNode.insertBefore(fresh, end);
|
|
1197
1257
|
adoptedNodes.push(fresh);
|
|
@@ -1223,7 +1283,7 @@ function adoptNode(desc, ssrEl) {
|
|
|
1223
1283
|
for (let i = 0; i < adoptedItems.length; i++) {
|
|
1224
1284
|
const item = adoptedItems[i];
|
|
1225
1285
|
const key = listKeyFn(item);
|
|
1226
|
-
const [getIndex, setIndex] =
|
|
1286
|
+
const [getIndex, setIndex] = chunkKH3F5NRU_cjs.createSignal(i);
|
|
1227
1287
|
cache.set(key, {
|
|
1228
1288
|
element: adoptedNodes[i],
|
|
1229
1289
|
item,
|
|
@@ -1248,7 +1308,7 @@ function adoptNode(desc, ssrEl) {
|
|
|
1248
1308
|
hydrating = false;
|
|
1249
1309
|
try {
|
|
1250
1310
|
const key = listKeyFn(item);
|
|
1251
|
-
const [getIndex, setIndex] =
|
|
1311
|
+
const [getIndex, setIndex] = chunkKH3F5NRU_cjs.createSignal(0);
|
|
1252
1312
|
const element = untrack(() => listRenderFn(item, getIndex));
|
|
1253
1313
|
cache.set(key, { element, item, getIndex, setIndex });
|
|
1254
1314
|
return element;
|
|
@@ -1421,11 +1481,11 @@ function longestIncreasingSubsequence(arr) {
|
|
|
1421
1481
|
return result;
|
|
1422
1482
|
}
|
|
1423
1483
|
var SMALL_LIST_THRESHOLD = 32;
|
|
1424
|
-
var
|
|
1484
|
+
var ABORT_SYM3 = /* @__PURE__ */ Symbol.for("forma-abort");
|
|
1425
1485
|
var CACHE_SYM2 = /* @__PURE__ */ Symbol.for("forma-attr-cache");
|
|
1426
1486
|
var DYNAMIC_CHILD_SYM2 = /* @__PURE__ */ Symbol.for("forma-dynamic-child");
|
|
1427
1487
|
function canPatchStaticElement(target, source) {
|
|
1428
|
-
return target instanceof HTMLElement && source instanceof HTMLElement && target.tagName === source.tagName && !target[
|
|
1488
|
+
return target instanceof HTMLElement && source instanceof HTMLElement && target.tagName === source.tagName && !target[ABORT_SYM3] && !target[CACHE_SYM2] && !target[DYNAMIC_CHILD_SYM2] && !source[ABORT_SYM3] && !source[CACHE_SYM2] && !source[DYNAMIC_CHILD_SYM2];
|
|
1429
1489
|
}
|
|
1430
1490
|
function patchStaticElement(target, source) {
|
|
1431
1491
|
const sourceAttrNames = /* @__PURE__ */ new Set();
|
|
@@ -1709,7 +1769,7 @@ function createList(items, keyFn, renderFn, options) {
|
|
|
1709
1769
|
if (cached.item === item) return;
|
|
1710
1770
|
cached.item = item;
|
|
1711
1771
|
if (!(node instanceof HTMLElement)) return;
|
|
1712
|
-
if (node[
|
|
1772
|
+
if (node[ABORT_SYM3] || node[CACHE_SYM2] || node[DYNAMIC_CHILD_SYM2]) {
|
|
1713
1773
|
return;
|
|
1714
1774
|
}
|
|
1715
1775
|
const next = untrack(() => renderFn(item, cached.getIndex));
|
|
@@ -1731,7 +1791,7 @@ function createList(items, keyFn, renderFn, options) {
|
|
|
1731
1791
|
// createFn: create element + cache entry
|
|
1732
1792
|
(item) => {
|
|
1733
1793
|
const key = keyFn(item);
|
|
1734
|
-
const [getIndex, setIndex] =
|
|
1794
|
+
const [getIndex, setIndex] = chunkKH3F5NRU_cjs.createSignal(0);
|
|
1735
1795
|
const element = untrack(() => renderFn(item, getIndex));
|
|
1736
1796
|
cache.set(key, { element, item, getIndex, setIndex });
|
|
1737
1797
|
return element;
|
|
@@ -1757,6 +1817,7 @@ function createList(items, keyFn, renderFn, options) {
|
|
|
1757
1817
|
}
|
|
1758
1818
|
|
|
1759
1819
|
exports.Fragment = Fragment;
|
|
1820
|
+
exports.__DEV__ = __DEV__;
|
|
1760
1821
|
exports.batch = batch;
|
|
1761
1822
|
exports.cleanup = cleanup;
|
|
1762
1823
|
exports.createEffect = createEffect;
|
|
@@ -1771,13 +1832,13 @@ exports.fragment = fragment;
|
|
|
1771
1832
|
exports.h = h;
|
|
1772
1833
|
exports.hydrateIsland = hydrateIsland;
|
|
1773
1834
|
exports.internalEffect = internalEffect;
|
|
1774
|
-
exports.longestIncreasingSubsequence = longestIncreasingSubsequence;
|
|
1775
1835
|
exports.on = on;
|
|
1776
1836
|
exports.onCleanup = onCleanup;
|
|
1777
1837
|
exports.onError = onError;
|
|
1778
1838
|
exports.popSuspenseContext = popSuspenseContext;
|
|
1779
1839
|
exports.pushSuspenseContext = pushSuspenseContext;
|
|
1780
1840
|
exports.reconcileList = reconcileList;
|
|
1841
|
+
exports.reportError = reportError;
|
|
1781
1842
|
exports.untrack = untrack;
|
|
1782
|
-
//# sourceMappingURL=chunk-
|
|
1783
|
-
//# sourceMappingURL=chunk-
|
|
1843
|
+
//# sourceMappingURL=chunk-YSKF3VRA.cjs.map
|
|
1844
|
+
//# sourceMappingURL=chunk-YSKF3VRA.cjs.map
|