@fictjs/runtime 0.2.1 → 0.2.3
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 +2 -0
- package/dist/advanced.d.ts +2 -0
- package/dist/advanced.js +3 -3
- package/dist/{chunk-MWI3USXB.cjs → chunk-2U6M3LKS.cjs} +122 -113
- package/dist/chunk-2U6M3LKS.cjs.map +1 -0
- package/dist/{chunk-VVNMIER7.js → chunk-3WD7QD5G.js} +2 -2
- package/dist/{chunk-7EAEROZ5.cjs → chunk-5YTFFAVU.cjs} +7 -7
- package/dist/{chunk-7EAEROZ5.cjs.map → chunk-5YTFFAVU.cjs.map} +1 -1
- package/dist/{chunk-7TPCESQS.js → chunk-UHXUEGQH.js} +2 -2
- package/dist/{chunk-Z5WRKD7Y.cjs → chunk-W525IQWC.cjs} +16 -16
- package/dist/{chunk-Z5WRKD7Y.cjs.map → chunk-W525IQWC.cjs.map} +1 -1
- package/dist/{chunk-FOLRR3NZ.js → chunk-YVDWXY44.js} +122 -113
- package/dist/chunk-YVDWXY44.js.map +1 -0
- package/dist/index.cjs +38 -38
- package/dist/index.dev.js +121 -112
- package/dist/index.dev.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/internal.cjs +34 -34
- package/dist/internal.js +2 -2
- package/package.json +1 -1
- package/src/cycle-guard.ts +113 -104
- package/src/dom.ts +4 -1
- package/dist/chunk-FOLRR3NZ.js.map +0 -1
- package/dist/chunk-MWI3USXB.cjs.map +0 -1
- /package/dist/{chunk-VVNMIER7.js.map → chunk-3WD7QD5G.js.map} +0 -0
- /package/dist/{chunk-7TPCESQS.js.map → chunk-UHXUEGQH.js.map} +0 -0
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunk2U6M3LKScjs = require('./chunk-2U6M3LKS.cjs');
|
|
8
8
|
|
|
9
9
|
// src/scope.ts
|
|
10
10
|
function createScope() {
|
|
@@ -17,17 +17,17 @@ function createScope() {
|
|
|
17
17
|
};
|
|
18
18
|
const run = (fn) => {
|
|
19
19
|
stop();
|
|
20
|
-
const { dispose: rootDispose, value } =
|
|
20
|
+
const { dispose: rootDispose, value } = _chunk2U6M3LKScjs.createRoot.call(void 0, fn, { inherit: true });
|
|
21
21
|
dispose = rootDispose;
|
|
22
22
|
return value;
|
|
23
23
|
};
|
|
24
|
-
|
|
24
|
+
_chunk2U6M3LKScjs.registerRootCleanup.call(void 0, stop);
|
|
25
25
|
return { run, stop };
|
|
26
26
|
}
|
|
27
27
|
function runInScope(flag, fn) {
|
|
28
28
|
const scope = createScope();
|
|
29
|
-
const evaluate = () =>
|
|
30
|
-
|
|
29
|
+
const evaluate = () => _chunk2U6M3LKScjs.isReactive.call(void 0, flag) ? flag() : !!flag;
|
|
30
|
+
_chunk2U6M3LKScjs.createEffect.call(void 0, () => {
|
|
31
31
|
const enabled = evaluate();
|
|
32
32
|
if (enabled) {
|
|
33
33
|
scope.run(fn);
|
|
@@ -35,11 +35,11 @@ function runInScope(flag, fn) {
|
|
|
35
35
|
scope.stop();
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
|
-
|
|
38
|
+
_chunk2U6M3LKScjs.onCleanup.call(void 0, scope.stop);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
exports.createScope = createScope; exports.runInScope = runInScope;
|
|
45
|
-
//# sourceMappingURL=chunk-
|
|
45
|
+
//# sourceMappingURL=chunk-5YTFFAVU.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/fict/fict/packages/runtime/dist/chunk-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/fict/fict/packages/runtime/dist/chunk-5YTFFAVU.cjs","../src/scope.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACF,wDAA6B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.cjs","sourcesContent":[null,"import { isReactive, type MaybeReactive } from './binding'\nimport { createEffect } from './effect'\nimport { createRoot, onCleanup, registerRootCleanup } from './lifecycle'\n\nexport { effectScope } from './signal'\n\nexport interface ReactiveScope {\n run<T>(fn: () => T): T\n stop(): void\n}\n\n/**\n * Create an explicit reactive scope that can contain effects/memos and be stopped manually.\n * The scope registers with the current root for cleanup.\n */\nexport function createScope(): ReactiveScope {\n let dispose: (() => void) | null = null\n\n const stop = () => {\n if (dispose) {\n dispose()\n dispose = null\n }\n }\n\n const run = <T>(fn: () => T): T => {\n stop()\n const { dispose: rootDispose, value } = createRoot(fn, { inherit: true })\n dispose = rootDispose\n return value\n }\n\n registerRootCleanup(stop)\n return { run, stop }\n}\n\n/**\n * Run a block of reactive code inside a managed scope that follows a boolean flag.\n * When the flag turns false, the scope is disposed and all contained effects/memos are cleaned up.\n */\nexport function runInScope(flag: MaybeReactive<boolean>, fn: () => void): void {\n const scope = createScope()\n const evaluate = () => (isReactive(flag) ? (flag as () => boolean)() : !!flag)\n\n createEffect(() => {\n const enabled = evaluate()\n if (enabled) {\n scope.run(fn)\n } else {\n scope.stop()\n }\n })\n\n onCleanup(scope.stop)\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
isReactive,
|
|
5
5
|
onCleanup,
|
|
6
6
|
registerRootCleanup
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-YVDWXY44.js";
|
|
8
8
|
|
|
9
9
|
// src/scope.ts
|
|
10
10
|
function createScope() {
|
|
@@ -42,4 +42,4 @@ export {
|
|
|
42
42
|
createScope,
|
|
43
43
|
runInScope
|
|
44
44
|
};
|
|
45
|
-
//# sourceMappingURL=chunk-
|
|
45
|
+
//# sourceMappingURL=chunk-UHXUEGQH.js.map
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunk2U6M3LKScjs = require('./chunk-2U6M3LKS.cjs');
|
|
14
14
|
|
|
15
15
|
// src/context.ts
|
|
16
16
|
var contextStorage = /* @__PURE__ */ new WeakMap();
|
|
@@ -30,8 +30,8 @@ function createContext(defaultValue) {
|
|
|
30
30
|
Provider: null
|
|
31
31
|
};
|
|
32
32
|
context.Provider = function Provider(props) {
|
|
33
|
-
const hostRoot =
|
|
34
|
-
const providerRoot =
|
|
33
|
+
const hostRoot = _chunk2U6M3LKScjs.getCurrentRoot.call(void 0, );
|
|
34
|
+
const providerRoot = _chunk2U6M3LKScjs.createRootContext.call(void 0, hostRoot);
|
|
35
35
|
const contextMap = getContextMap(providerRoot);
|
|
36
36
|
contextMap.set(id, props.value);
|
|
37
37
|
const fragment = document.createDocumentFragment();
|
|
@@ -45,32 +45,32 @@ function createContext(defaultValue) {
|
|
|
45
45
|
cleanup = void 0;
|
|
46
46
|
}
|
|
47
47
|
if (activeNodes.length) {
|
|
48
|
-
|
|
48
|
+
_chunk2U6M3LKScjs.removeNodes.call(void 0, activeNodes);
|
|
49
49
|
activeNodes = [];
|
|
50
50
|
}
|
|
51
51
|
if (children == null || children === false) {
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
|
-
const prev =
|
|
54
|
+
const prev = _chunk2U6M3LKScjs.pushRoot.call(void 0, providerRoot);
|
|
55
55
|
let nodes = [];
|
|
56
56
|
try {
|
|
57
|
-
const output =
|
|
58
|
-
nodes =
|
|
57
|
+
const output = _chunk2U6M3LKScjs.createElement.call(void 0, children);
|
|
58
|
+
nodes = _chunk2U6M3LKScjs.toNodeArray.call(void 0, output);
|
|
59
59
|
const parentNode = marker.parentNode;
|
|
60
60
|
if (parentNode) {
|
|
61
|
-
|
|
61
|
+
_chunk2U6M3LKScjs.insertNodesBefore.call(void 0, parentNode, nodes, marker);
|
|
62
62
|
}
|
|
63
63
|
} finally {
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
_chunk2U6M3LKScjs.popRoot.call(void 0, prev);
|
|
65
|
+
_chunk2U6M3LKScjs.flushOnMount.call(void 0, providerRoot);
|
|
66
66
|
}
|
|
67
67
|
cleanup = () => {
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
_chunk2U6M3LKScjs.destroyRoot.call(void 0, providerRoot);
|
|
69
|
+
_chunk2U6M3LKScjs.removeNodes.call(void 0, nodes);
|
|
70
70
|
};
|
|
71
71
|
activeNodes = nodes;
|
|
72
72
|
};
|
|
73
|
-
|
|
73
|
+
_chunk2U6M3LKScjs.createRenderEffect.call(void 0, () => {
|
|
74
74
|
contextMap.set(id, props.value);
|
|
75
75
|
renderChildren(props.children);
|
|
76
76
|
});
|
|
@@ -79,7 +79,7 @@ function createContext(defaultValue) {
|
|
|
79
79
|
return context;
|
|
80
80
|
}
|
|
81
81
|
function useContext(context) {
|
|
82
|
-
let root =
|
|
82
|
+
let root = _chunk2U6M3LKScjs.getCurrentRoot.call(void 0, );
|
|
83
83
|
while (root) {
|
|
84
84
|
const contextMap = contextStorage.get(root);
|
|
85
85
|
if (contextMap && contextMap.has(context.id)) {
|
|
@@ -90,7 +90,7 @@ function useContext(context) {
|
|
|
90
90
|
return context.defaultValue;
|
|
91
91
|
}
|
|
92
92
|
function hasContext(context) {
|
|
93
|
-
let root =
|
|
93
|
+
let root = _chunk2U6M3LKScjs.getCurrentRoot.call(void 0, );
|
|
94
94
|
while (root) {
|
|
95
95
|
const contextMap = contextStorage.get(root);
|
|
96
96
|
if (contextMap && contextMap.has(context.id)) {
|
|
@@ -106,4 +106,4 @@ function hasContext(context) {
|
|
|
106
106
|
|
|
107
107
|
|
|
108
108
|
exports.createContext = createContext; exports.useContext = useContext; exports.hasContext = hasContext;
|
|
109
|
-
//# sourceMappingURL=chunk-
|
|
109
|
+
//# sourceMappingURL=chunk-W525IQWC.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/fict/fict/packages/runtime/dist/chunk-Z5WRKD7Y.cjs","../src/context.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA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AAA,CAAc,OAAA,EAAwB;AACpD,EAAA,IAAI,KAAA,EAAO,8CAAA,CAAe;AAG1B,EAAA,MAAA,CAAO,IAAA,EAAM;AACX,IAAA,MAAM,WAAA,EAAa,cAAA,CAAe,GAAA,CAAI,IAAI,CAAA;AAC1C,IAAA,GAAA,CAAI,WAAA,GAAc,UAAA,CAAW,GAAA,CAAI,OAAA,CAAQ,EAAE,CAAA,EAAG;AAC5C,MAAA,OAAO,UAAA,CAAW,GAAA,CAAI,OAAA,CAAQ,EAAE,CAAA;AAAA,IAClC;AACA,IAAA,KAAA,EAAO,IAAA,CAAK,MAAA;AAAA,EACd;AAGA,EAAA,OAAO,OAAA,CAAQ,YAAA;AACjB;AAqBO,SAAS,UAAA,CAAc,OAAA,EAA8B;AAC1D,EAAA,IAAI,KAAA,EAAO,8CAAA,CAAe;AAE1B,EAAA,MAAA,CAAO,IAAA,EAAM;AACX,IAAA,MAAM,WAAA,EAAa,cAAA,CAAe,GAAA,CAAI,IAAI,CAAA;AAC1C,IAAA,GAAA,CAAI,WAAA,GAAc,UAAA,CAAW,GAAA,CAAI,OAAA,CAAQ,EAAE,CAAA,EAAG;AAC5C,MAAA,OAAO,IAAA;AAAA,IACT;AACA,IAAA,KAAA,EAAO,IAAA,CAAK,MAAA;AAAA,EACd;AAEA,EAAA,OAAO,KAAA;AACT;ADrMA;AACA;AACE;AACA;AACA;AACF,wGAAC","file":"/home/runner/work/fict/fict/packages/runtime/dist/chunk-Z5WRKD7Y.cjs","sourcesContent":[null,"/**\n * @fileoverview Context API for Fict\n *\n * Provides a way to pass data through the component tree without having to pass\n * props down manually at every level. Context is designed for:\n *\n * - SSR isolation (different request = different context values)\n * - Multi-instance support (multiple app roots with different values)\n * - Subtree scoping (override values in specific parts of the tree)\n *\n * ## Design Principles\n *\n * 1. **Reuses existing RootContext hierarchy** - Uses parent chain for value lookup,\n * consistent with handleError/handleSuspend mechanisms.\n *\n * 2. **Zero extra root creation overhead** - Provider doesn't create new root,\n * only mounts value on current root.\n *\n * 3. **Auto-aligned with insert/suspense boundaries** - Because they create child\n * roots that inherit parent, context values propagate correctly.\n *\n * ## Usage\n *\n * ```tsx\n * // Create context with default value\n * const ThemeContext = createContext<'light' | 'dark'>('light')\n *\n * // Provide value to subtree\n * function App() {\n * return (\n * <ThemeContext.Provider value=\"dark\">\n * <ThemedComponent />\n * </ThemeContext.Provider>\n * )\n * }\n *\n * // Consume value\n * function ThemedComponent() {\n * const theme = useContext(ThemeContext)\n * return <div class={theme}>...</div>\n * }\n * ```\n *\n * @module\n */\n\nimport { createElement } from './dom'\nimport { createRenderEffect } from './effect'\nimport {\n createRootContext,\n destroyRoot,\n flushOnMount,\n getCurrentRoot,\n popRoot,\n pushRoot,\n type RootContext,\n} from './lifecycle'\nimport { insertNodesBefore, removeNodes, toNodeArray } from './node-ops'\nimport type { BaseProps, FictNode } from './types'\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Context object created by createContext.\n * Contains the Provider component and serves as a key for context lookup.\n */\nexport interface Context<T> {\n /** Unique identifier for this context */\n readonly id: symbol\n /** Default value when no provider is found */\n readonly defaultValue: T\n /** Provider component for supplying context values */\n Provider: ContextProvider<T>\n /** Display name for debugging */\n displayName?: string\n}\n\n/**\n * Props for the Context Provider component\n */\nexport interface ProviderProps<T> extends BaseProps {\n /** The value to provide to the subtree */\n value: T\n}\n\n/**\n * Provider component type\n */\nexport type ContextProvider<T> = (props: ProviderProps<T>) => FictNode\n\n// ============================================================================\n// Internal Context Storage\n// ============================================================================\n\n/**\n * WeakMap to store context values per RootContext.\n * Using WeakMap ensures proper garbage collection when roots are destroyed.\n */\nconst contextStorage = new WeakMap<RootContext, Map<symbol, unknown>>()\n\n/**\n * Get the context map for a root, creating it if needed\n */\nfunction getContextMap(root: RootContext): Map<symbol, unknown> {\n let map = contextStorage.get(root)\n if (!map) {\n map = new Map()\n contextStorage.set(root, map)\n }\n return map\n}\n\n// ============================================================================\n// Context API\n// ============================================================================\n\n/**\n * Creates a new context with the given default value.\n *\n * Context provides a way to pass values through the component tree without\n * explicit props drilling. It's especially useful for:\n *\n * - Theme data\n * - Locale/i18n settings\n * - Authentication state\n * - Feature flags\n * - Any data that many components at different nesting levels need\n *\n * @param defaultValue - The value to use when no Provider is found above in the tree\n * @returns A context object with a Provider component\n *\n * @example\n * ```tsx\n * // Create a theme context\n * const ThemeContext = createContext<'light' | 'dark'>('light')\n *\n * // Use the provider\n * function App() {\n * return (\n * <ThemeContext.Provider value=\"dark\">\n * <Content />\n * </ThemeContext.Provider>\n * )\n * }\n *\n * // Consume the context\n * function Content() {\n * const theme = useContext(ThemeContext)\n * return <div class={`theme-${theme}`}>Hello</div>\n * }\n * ```\n */\nexport function createContext<T>(defaultValue: T): Context<T> {\n const id = Symbol('fict.context')\n\n const context: Context<T> = {\n id,\n defaultValue,\n Provider: null as unknown as ContextProvider<T>,\n }\n\n // Create the Provider component\n context.Provider = function Provider(props: ProviderProps<T>): FictNode {\n const hostRoot = getCurrentRoot()\n\n // Create a child root for the provider's subtree\n // This establishes the provider boundary - children will look up from here\n const providerRoot = createRootContext(hostRoot)\n\n // Store the context value on this root\n const contextMap = getContextMap(providerRoot)\n contextMap.set(id, props.value)\n\n // Create DOM structure\n const fragment = document.createDocumentFragment()\n const marker = document.createComment('fict:ctx')\n fragment.appendChild(marker)\n\n let cleanup: (() => void) | undefined\n let activeNodes: Node[] = []\n\n const renderChildren = (children: FictNode) => {\n // Cleanup previous render\n if (cleanup) {\n cleanup()\n cleanup = undefined\n }\n if (activeNodes.length) {\n removeNodes(activeNodes)\n activeNodes = []\n }\n\n if (children == null || children === false) {\n return\n }\n\n const prev = pushRoot(providerRoot)\n let nodes: Node[] = []\n try {\n const output = createElement(children)\n nodes = toNodeArray(output)\n const parentNode = marker.parentNode as (ParentNode & Node) | null\n if (parentNode) {\n insertNodesBefore(parentNode, nodes, marker)\n }\n } finally {\n popRoot(prev)\n flushOnMount(providerRoot)\n }\n\n cleanup = () => {\n destroyRoot(providerRoot)\n removeNodes(nodes)\n }\n activeNodes = nodes\n }\n\n // Initial render\n createRenderEffect(() => {\n // Update context value on re-render (if value prop changes reactively)\n contextMap.set(id, props.value)\n renderChildren(props.children)\n })\n\n return fragment\n }\n\n return context\n}\n\n/**\n * Reads the current value of a context.\n *\n * useContext looks up through the RootContext parent chain to find the\n * nearest Provider for this context. If no Provider is found, returns\n * the context's default value.\n *\n * @param context - The context object created by createContext\n * @returns The current context value\n *\n * @example\n * ```tsx\n * const ThemeContext = createContext('light')\n *\n * function ThemedButton() {\n * const theme = useContext(ThemeContext)\n * return <button class={theme === 'dark' ? 'btn-dark' : 'btn-light'}>Click</button>\n * }\n * ```\n */\nexport function useContext<T>(context: Context<T>): T {\n let root = getCurrentRoot()\n\n // Walk up the parent chain looking for the context value\n while (root) {\n const contextMap = contextStorage.get(root)\n if (contextMap && contextMap.has(context.id)) {\n return contextMap.get(context.id) as T\n }\n root = root.parent\n }\n\n // No provider found, return default value\n return context.defaultValue\n}\n\n/**\n * Checks if a context value is currently provided in the tree.\n *\n * Useful for conditional behavior when a provider may or may not exist.\n *\n * @param context - The context object to check\n * @returns true if a Provider exists above in the tree\n *\n * @example\n * ```tsx\n * function OptionalTheme() {\n * if (hasContext(ThemeContext)) {\n * const theme = useContext(ThemeContext)\n * return <div class={theme}>Themed content</div>\n * }\n * return <div>Default content</div>\n * }\n * ```\n */\nexport function hasContext<T>(context: Context<T>): boolean {\n let root = getCurrentRoot()\n\n while (root) {\n const contextMap = contextStorage.get(root)\n if (contextMap && contextMap.has(context.id)) {\n return true\n }\n root = root.parent\n }\n\n return false\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/fict/fict/packages/runtime/dist/chunk-W525IQWC.cjs","../src/context.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACsFA,IAAM,eAAA,kBAAiB,IAAI,OAAA,CAA2C,CAAA;A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M,WAAA,EAAa,cAAA,CAAe,GAAA,CAAI,IAAI,CAAA;AAC1C,IAAA,GAAA,CAAI,WAAA,GAAc,UAAA,CAAW,GAAA,CAAI,OAAA,CAAQ,EAAE,CAAA,EAAG;AAC5C,MAAA,OAAO,UAAA,CAAW,GAAA,CAAI,OAAA,CAAQ,EAAE,CAAA;AAAA,IAClC;AACA,IAAA,KAAA,EAAO,IAAA,CAAK,MAAA;AAAA,EACd;AAGA,EAAA,OAAO,OAAA,CAAQ,YAAA;AACjB;AAqBO,SAAS,UAAA,CAAc,OAAA,EAA8B;AAC1D,EAAA,IAAI,KAAA,EAAO,8CAAA,CAAe;AAE1B,EAAA,MAAA,CAAO,IAAA,EAAM;AACX,IAAA,MAAM,WAAA,EAAa,cAAA,CAAe,GAAA,CAAI,IAAI,CAAA;AAC1C,IAAA,GAAA,CAAI,WAAA,GAAc,UAAA,CAAW,GAAA,CAAI,OAAA,CAAQ,EAAE,CAAA,EAAG;AAC5C,MAAA,OAAO,IAAA;AAAA,IACT;AACA,IAAA,KAAA,EAAO,IAAA,CAAK,MAAA;AAAA,EACd;AAEA,EAAA,OAAO,KAAA;AACT;ADrMA;AACA;AACE;AACA;AACA;AACF,wGAAC","file":"/home/runner/work/fict/fict/packages/runtime/dist/chunk-W525IQWC.cjs","sourcesContent":[null,"/**\n * @fileoverview Context API for Fict\n *\n * Provides a way to pass data through the component tree without having to pass\n * props down manually at every level. Context is designed for:\n *\n * - SSR isolation (different request = different context values)\n * - Multi-instance support (multiple app roots with different values)\n * - Subtree scoping (override values in specific parts of the tree)\n *\n * ## Design Principles\n *\n * 1. **Reuses existing RootContext hierarchy** - Uses parent chain for value lookup,\n * consistent with handleError/handleSuspend mechanisms.\n *\n * 2. **Zero extra root creation overhead** - Provider doesn't create new root,\n * only mounts value on current root.\n *\n * 3. **Auto-aligned with insert/suspense boundaries** - Because they create child\n * roots that inherit parent, context values propagate correctly.\n *\n * ## Usage\n *\n * ```tsx\n * // Create context with default value\n * const ThemeContext = createContext<'light' | 'dark'>('light')\n *\n * // Provide value to subtree\n * function App() {\n * return (\n * <ThemeContext.Provider value=\"dark\">\n * <ThemedComponent />\n * </ThemeContext.Provider>\n * )\n * }\n *\n * // Consume value\n * function ThemedComponent() {\n * const theme = useContext(ThemeContext)\n * return <div class={theme}>...</div>\n * }\n * ```\n *\n * @module\n */\n\nimport { createElement } from './dom'\nimport { createRenderEffect } from './effect'\nimport {\n createRootContext,\n destroyRoot,\n flushOnMount,\n getCurrentRoot,\n popRoot,\n pushRoot,\n type RootContext,\n} from './lifecycle'\nimport { insertNodesBefore, removeNodes, toNodeArray } from './node-ops'\nimport type { BaseProps, FictNode } from './types'\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Context object created by createContext.\n * Contains the Provider component and serves as a key for context lookup.\n */\nexport interface Context<T> {\n /** Unique identifier for this context */\n readonly id: symbol\n /** Default value when no provider is found */\n readonly defaultValue: T\n /** Provider component for supplying context values */\n Provider: ContextProvider<T>\n /** Display name for debugging */\n displayName?: string\n}\n\n/**\n * Props for the Context Provider component\n */\nexport interface ProviderProps<T> extends BaseProps {\n /** The value to provide to the subtree */\n value: T\n}\n\n/**\n * Provider component type\n */\nexport type ContextProvider<T> = (props: ProviderProps<T>) => FictNode\n\n// ============================================================================\n// Internal Context Storage\n// ============================================================================\n\n/**\n * WeakMap to store context values per RootContext.\n * Using WeakMap ensures proper garbage collection when roots are destroyed.\n */\nconst contextStorage = new WeakMap<RootContext, Map<symbol, unknown>>()\n\n/**\n * Get the context map for a root, creating it if needed\n */\nfunction getContextMap(root: RootContext): Map<symbol, unknown> {\n let map = contextStorage.get(root)\n if (!map) {\n map = new Map()\n contextStorage.set(root, map)\n }\n return map\n}\n\n// ============================================================================\n// Context API\n// ============================================================================\n\n/**\n * Creates a new context with the given default value.\n *\n * Context provides a way to pass values through the component tree without\n * explicit props drilling. It's especially useful for:\n *\n * - Theme data\n * - Locale/i18n settings\n * - Authentication state\n * - Feature flags\n * - Any data that many components at different nesting levels need\n *\n * @param defaultValue - The value to use when no Provider is found above in the tree\n * @returns A context object with a Provider component\n *\n * @example\n * ```tsx\n * // Create a theme context\n * const ThemeContext = createContext<'light' | 'dark'>('light')\n *\n * // Use the provider\n * function App() {\n * return (\n * <ThemeContext.Provider value=\"dark\">\n * <Content />\n * </ThemeContext.Provider>\n * )\n * }\n *\n * // Consume the context\n * function Content() {\n * const theme = useContext(ThemeContext)\n * return <div class={`theme-${theme}`}>Hello</div>\n * }\n * ```\n */\nexport function createContext<T>(defaultValue: T): Context<T> {\n const id = Symbol('fict.context')\n\n const context: Context<T> = {\n id,\n defaultValue,\n Provider: null as unknown as ContextProvider<T>,\n }\n\n // Create the Provider component\n context.Provider = function Provider(props: ProviderProps<T>): FictNode {\n const hostRoot = getCurrentRoot()\n\n // Create a child root for the provider's subtree\n // This establishes the provider boundary - children will look up from here\n const providerRoot = createRootContext(hostRoot)\n\n // Store the context value on this root\n const contextMap = getContextMap(providerRoot)\n contextMap.set(id, props.value)\n\n // Create DOM structure\n const fragment = document.createDocumentFragment()\n const marker = document.createComment('fict:ctx')\n fragment.appendChild(marker)\n\n let cleanup: (() => void) | undefined\n let activeNodes: Node[] = []\n\n const renderChildren = (children: FictNode) => {\n // Cleanup previous render\n if (cleanup) {\n cleanup()\n cleanup = undefined\n }\n if (activeNodes.length) {\n removeNodes(activeNodes)\n activeNodes = []\n }\n\n if (children == null || children === false) {\n return\n }\n\n const prev = pushRoot(providerRoot)\n let nodes: Node[] = []\n try {\n const output = createElement(children)\n nodes = toNodeArray(output)\n const parentNode = marker.parentNode as (ParentNode & Node) | null\n if (parentNode) {\n insertNodesBefore(parentNode, nodes, marker)\n }\n } finally {\n popRoot(prev)\n flushOnMount(providerRoot)\n }\n\n cleanup = () => {\n destroyRoot(providerRoot)\n removeNodes(nodes)\n }\n activeNodes = nodes\n }\n\n // Initial render\n createRenderEffect(() => {\n // Update context value on re-render (if value prop changes reactively)\n contextMap.set(id, props.value)\n renderChildren(props.children)\n })\n\n return fragment\n }\n\n return context\n}\n\n/**\n * Reads the current value of a context.\n *\n * useContext looks up through the RootContext parent chain to find the\n * nearest Provider for this context. If no Provider is found, returns\n * the context's default value.\n *\n * @param context - The context object created by createContext\n * @returns The current context value\n *\n * @example\n * ```tsx\n * const ThemeContext = createContext('light')\n *\n * function ThemedButton() {\n * const theme = useContext(ThemeContext)\n * return <button class={theme === 'dark' ? 'btn-dark' : 'btn-light'}>Click</button>\n * }\n * ```\n */\nexport function useContext<T>(context: Context<T>): T {\n let root = getCurrentRoot()\n\n // Walk up the parent chain looking for the context value\n while (root) {\n const contextMap = contextStorage.get(root)\n if (contextMap && contextMap.has(context.id)) {\n return contextMap.get(context.id) as T\n }\n root = root.parent\n }\n\n // No provider found, return default value\n return context.defaultValue\n}\n\n/**\n * Checks if a context value is currently provided in the tree.\n *\n * Useful for conditional behavior when a provider may or may not exist.\n *\n * @param context - The context object to check\n * @returns true if a Provider exists above in the tree\n *\n * @example\n * ```tsx\n * function OptionalTheme() {\n * if (hasContext(ThemeContext)) {\n * const theme = useContext(ThemeContext)\n * return <div class={theme}>Themed content</div>\n * }\n * return <div>Default content</div>\n * }\n * ```\n */\nexport function hasContext<T>(context: Context<T>): boolean {\n let root = getCurrentRoot()\n\n while (root) {\n const contextMap = contextStorage.get(root)\n if (contextMap && contextMap.has(context.id)) {\n return true\n }\n root = root.parent\n }\n\n return false\n}\n"]}
|
|
@@ -400,110 +400,117 @@ var endFlushGuard = () => {
|
|
|
400
400
|
var enterRootGuard = () => true;
|
|
401
401
|
var exitRootGuard = () => {
|
|
402
402
|
};
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
effectRunsThisFlush = 0;
|
|
457
|
-
};
|
|
458
|
-
enterRootGuard = (root) => {
|
|
459
|
-
const depth = (rootDepth.get(root) ?? 0) + 1;
|
|
460
|
-
if (depth > options.maxRootReentrantDepth) {
|
|
461
|
-
const message = `[fict] cycle protection triggered: root-reentry`;
|
|
462
|
-
if (options.devMode) {
|
|
463
|
-
throw new Error(message);
|
|
464
|
-
}
|
|
465
|
-
if (!rootWarned) {
|
|
466
|
-
rootWarned = true;
|
|
467
|
-
console.warn(message, { depth });
|
|
468
|
-
}
|
|
469
|
-
return false;
|
|
470
|
-
}
|
|
471
|
-
rootDepth.set(root, depth);
|
|
472
|
-
return true;
|
|
473
|
-
};
|
|
474
|
-
exitRootGuard = (root) => {
|
|
475
|
-
const depth = rootDepth.get(root);
|
|
476
|
-
if (depth === void 0) return;
|
|
477
|
-
if (depth <= 1) {
|
|
478
|
-
rootDepth.delete(root);
|
|
479
|
-
} else {
|
|
480
|
-
rootDepth.set(root, depth - 1);
|
|
403
|
+
var defaultOptions = {
|
|
404
|
+
enabled: isDev2,
|
|
405
|
+
maxFlushCyclesPerMicrotask: 1e4,
|
|
406
|
+
maxEffectRunsPerFlush: 2e4,
|
|
407
|
+
windowSize: 5,
|
|
408
|
+
highUsageRatio: 0.8,
|
|
409
|
+
maxRootReentrantDepth: 10,
|
|
410
|
+
enableWindowWarning: true,
|
|
411
|
+
devMode: false
|
|
412
|
+
};
|
|
413
|
+
var enabled = defaultOptions.enabled;
|
|
414
|
+
var options = {
|
|
415
|
+
...defaultOptions
|
|
416
|
+
};
|
|
417
|
+
var effectRunsThisFlush = 0;
|
|
418
|
+
var windowUsage = [];
|
|
419
|
+
var rootDepth = /* @__PURE__ */ new WeakMap();
|
|
420
|
+
var flushWarned = false;
|
|
421
|
+
var rootWarned = false;
|
|
422
|
+
var windowWarned = false;
|
|
423
|
+
setCycleProtectionOptions = (opts) => {
|
|
424
|
+
if (typeof opts.enabled === "boolean") {
|
|
425
|
+
enabled = opts.enabled;
|
|
426
|
+
}
|
|
427
|
+
options = { ...options, ...opts };
|
|
428
|
+
};
|
|
429
|
+
resetCycleProtectionStateForTests = () => {
|
|
430
|
+
options = { ...defaultOptions };
|
|
431
|
+
enabled = defaultOptions.enabled;
|
|
432
|
+
effectRunsThisFlush = 0;
|
|
433
|
+
windowUsage = [];
|
|
434
|
+
rootDepth = /* @__PURE__ */ new WeakMap();
|
|
435
|
+
flushWarned = false;
|
|
436
|
+
rootWarned = false;
|
|
437
|
+
windowWarned = false;
|
|
438
|
+
};
|
|
439
|
+
beginFlushGuard = () => {
|
|
440
|
+
if (!enabled) return;
|
|
441
|
+
effectRunsThisFlush = 0;
|
|
442
|
+
flushWarned = false;
|
|
443
|
+
windowWarned = false;
|
|
444
|
+
};
|
|
445
|
+
beforeEffectRunGuard = () => {
|
|
446
|
+
if (!enabled) return true;
|
|
447
|
+
const next = ++effectRunsThisFlush;
|
|
448
|
+
if (next > options.maxFlushCyclesPerMicrotask || next > options.maxEffectRunsPerFlush) {
|
|
449
|
+
const message = `[fict] cycle protection triggered: flush-budget-exceeded`;
|
|
450
|
+
if (options.devMode) {
|
|
451
|
+
throw new Error(message);
|
|
452
|
+
}
|
|
453
|
+
if (!flushWarned) {
|
|
454
|
+
flushWarned = true;
|
|
455
|
+
console.warn(message, { effectRuns: next });
|
|
481
456
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
return true;
|
|
460
|
+
};
|
|
461
|
+
endFlushGuard = () => {
|
|
462
|
+
if (!enabled) return;
|
|
463
|
+
recordWindowUsage(effectRunsThisFlush, options.maxFlushCyclesPerMicrotask);
|
|
464
|
+
effectRunsThisFlush = 0;
|
|
465
|
+
};
|
|
466
|
+
enterRootGuard = (root) => {
|
|
467
|
+
if (!enabled) return true;
|
|
468
|
+
const depth = (rootDepth.get(root) ?? 0) + 1;
|
|
469
|
+
if (depth > options.maxRootReentrantDepth) {
|
|
470
|
+
const message = `[fict] cycle protection triggered: root-reentry`;
|
|
471
|
+
if (options.devMode) {
|
|
472
|
+
throw new Error(message);
|
|
473
|
+
}
|
|
474
|
+
if (!rootWarned) {
|
|
475
|
+
rootWarned = true;
|
|
476
|
+
console.warn(message, { depth });
|
|
499
477
|
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
rootDepth.set(root, depth);
|
|
481
|
+
return true;
|
|
482
|
+
};
|
|
483
|
+
exitRootGuard = (root) => {
|
|
484
|
+
if (!enabled) return;
|
|
485
|
+
const depth = rootDepth.get(root);
|
|
486
|
+
if (depth === void 0) return;
|
|
487
|
+
if (depth <= 1) {
|
|
488
|
+
rootDepth.delete(root);
|
|
489
|
+
} else {
|
|
490
|
+
rootDepth.set(root, depth - 1);
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
var recordWindowUsage = (used, budget) => {
|
|
494
|
+
if (!options.enableWindowWarning) return;
|
|
495
|
+
const entry = { used, budget };
|
|
496
|
+
windowUsage.push(entry);
|
|
497
|
+
if (windowUsage.length > options.windowSize) {
|
|
498
|
+
windowUsage.shift();
|
|
499
|
+
}
|
|
500
|
+
if (windowWarned) return;
|
|
501
|
+
if (windowUsage.length >= options.windowSize && windowUsage.every((item) => item.budget > 0 && item.used / item.budget >= options.highUsageRatio)) {
|
|
502
|
+
windowWarned = true;
|
|
503
|
+
reportCycle("high-usage-window", {
|
|
504
|
+
windowSize: options.windowSize,
|
|
505
|
+
ratio: options.highUsageRatio
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
var reportCycle = (reason, detail = void 0) => {
|
|
510
|
+
const hook = getDevtoolsHook();
|
|
511
|
+
hook?.cycleDetected?.(detail ? { reason, detail } : { reason });
|
|
512
|
+
console.warn(`[fict] cycle protection triggered: ${reason}`, detail ?? "");
|
|
513
|
+
};
|
|
507
514
|
|
|
508
515
|
// src/lifecycle.ts
|
|
509
516
|
var isDev3 = true ? false : typeof process === "undefined" || process.env?.NODE_ENV !== "production";
|
|
@@ -587,8 +594,8 @@ function destroyRoot(root) {
|
|
|
587
594
|
globalSuspenseHandlers.delete(root);
|
|
588
595
|
}
|
|
589
596
|
}
|
|
590
|
-
function createRoot(fn,
|
|
591
|
-
const parent =
|
|
597
|
+
function createRoot(fn, options2) {
|
|
598
|
+
const parent = options2?.inherit ? currentRoot : void 0;
|
|
592
599
|
const root = createRootContext(parent);
|
|
593
600
|
const prev = pushRoot(root);
|
|
594
601
|
let value;
|
|
@@ -2275,11 +2282,11 @@ function addEventListener(node, name, handler, delegate) {
|
|
|
2275
2282
|
node.addEventListener(name, handler);
|
|
2276
2283
|
}
|
|
2277
2284
|
}
|
|
2278
|
-
function bindEvent(el, eventName, handler,
|
|
2285
|
+
function bindEvent(el, eventName, handler, options2) {
|
|
2279
2286
|
if (handler == null) return () => {
|
|
2280
2287
|
};
|
|
2281
2288
|
const rootRef = getCurrentRoot();
|
|
2282
|
-
const shouldDelegate =
|
|
2289
|
+
const shouldDelegate = options2 == null && DelegatedEvents.has(eventName);
|
|
2283
2290
|
if (shouldDelegate) {
|
|
2284
2291
|
const key = `$$${eventName}`;
|
|
2285
2292
|
delegateEvents([eventName]);
|
|
@@ -2310,8 +2317,8 @@ function bindEvent(el, eventName, handler, options) {
|
|
|
2310
2317
|
throw err;
|
|
2311
2318
|
}
|
|
2312
2319
|
};
|
|
2313
|
-
el.addEventListener(eventName, wrapped,
|
|
2314
|
-
const cleanup = () => el.removeEventListener(eventName, wrapped,
|
|
2320
|
+
el.addEventListener(eventName, wrapped, options2);
|
|
2321
|
+
const cleanup = () => el.removeEventListener(eventName, wrapped, options2);
|
|
2315
2322
|
registerRootCleanup(cleanup);
|
|
2316
2323
|
return cleanup;
|
|
2317
2324
|
}
|
|
@@ -2875,12 +2882,12 @@ function mergeProps(...sources) {
|
|
|
2875
2882
|
}
|
|
2876
2883
|
});
|
|
2877
2884
|
}
|
|
2878
|
-
function prop(getter,
|
|
2885
|
+
function prop(getter, options2) {
|
|
2879
2886
|
if (isPropGetter(getter)) {
|
|
2880
2887
|
return getter;
|
|
2881
2888
|
}
|
|
2882
2889
|
const fn = getter;
|
|
2883
|
-
const unwrap2 =
|
|
2890
|
+
const unwrap2 = options2?.unwrap !== false;
|
|
2884
2891
|
return __fictProp(
|
|
2885
2892
|
createMemo(() => {
|
|
2886
2893
|
const value = fn();
|
|
@@ -3282,8 +3289,10 @@ var setProperty = (el, key, value) => {
|
|
|
3282
3289
|
el[key] = value;
|
|
3283
3290
|
};
|
|
3284
3291
|
var setInnerHTML = (el, _key, value) => {
|
|
3285
|
-
;
|
|
3286
|
-
|
|
3292
|
+
const next = value == null ? "" : String(value);
|
|
3293
|
+
const node = el;
|
|
3294
|
+
if (node.innerHTML === next) return;
|
|
3295
|
+
node.innerHTML = next;
|
|
3287
3296
|
};
|
|
3288
3297
|
var setBoolAttribute = (el, key, value) => {
|
|
3289
3298
|
if (value) {
|
|
@@ -3393,4 +3402,4 @@ export {
|
|
|
3393
3402
|
createElement,
|
|
3394
3403
|
template
|
|
3395
3404
|
};
|
|
3396
|
-
//# sourceMappingURL=chunk-
|
|
3405
|
+
//# sourceMappingURL=chunk-YVDWXY44.js.map
|