@fictjs/runtime 0.1.0 → 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-Q4EN6BXV.cjs → chunk-527QSKFM.cjs} +16 -16
- package/dist/{chunk-Q4EN6BXV.cjs.map → chunk-527QSKFM.cjs.map} +1 -1
- package/dist/{chunk-BWZFJXUI.js → chunk-5KXEEQUO.js} +84 -10
- package/dist/chunk-5KXEEQUO.js.map +1 -0
- package/dist/{chunk-YQ4IB7NC.cjs → chunk-BSUMPMKX.cjs} +7 -7
- package/dist/{chunk-YQ4IB7NC.cjs.map → chunk-BSUMPMKX.cjs.map} +1 -1
- package/dist/{chunk-V62XZLDU.js → chunk-FG3M7EBL.js} +2 -2
- package/dist/{chunk-7WAGAQLT.cjs → chunk-J74L7UYP.cjs} +84 -10
- package/dist/chunk-J74L7UYP.cjs.map +1 -0
- package/dist/{chunk-CF3OHML2.js → chunk-QV5GOCR5.js} +2 -2
- 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 +66 -19
- 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 +34 -34
- package/dist/internal.d.cts +4 -4
- package/dist/internal.d.ts +4 -4
- package/dist/internal.js +2 -2
- package/dist/jsx-runtime.d.cts +671 -0
- package/dist/jsx-runtime.d.ts +671 -0
- package/dist/{props-BfmSLuyp.d.cts → props-CBwuh35e.d.cts} +4 -4
- package/dist/{props-BBi8Tkks.d.ts → props-DAyeRPwH.d.ts} +4 -4
- 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 +58 -5
- package/src/effect.ts +9 -2
- package/src/lifecycle.ts +13 -3
- package/src/signal.ts +43 -4
- package/src/suspense.ts +17 -13
- package/dist/chunk-7WAGAQLT.cjs.map +0 -1
- package/dist/chunk-BWZFJXUI.js.map +0 -1
- /package/dist/{chunk-V62XZLDU.js.map → chunk-FG3M7EBL.js.map} +0 -0
- /package/dist/{chunk-CF3OHML2.js.map → chunk-QV5GOCR5.js.map} +0 -0
package/dist/advanced.cjs
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunk527QSKFMcjs = require('./chunk-527QSKFM.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkBSUMPMKXcjs = require('./chunk-BSUMPMKX.cjs');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
@@ -23,13 +23,13 @@ var _chunkYQ4IB7NCcjs = require('./chunk-YQ4IB7NC.cjs');
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
var
|
|
26
|
+
var _chunkJ74L7UYPcjs = require('./chunk-J74L7UYP.cjs');
|
|
27
27
|
|
|
28
28
|
// src/versioned-signal.ts
|
|
29
29
|
function createVersionedSignal(initialValue, options) {
|
|
30
30
|
const equals = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.equals]), () => ( Object.is));
|
|
31
|
-
const value =
|
|
32
|
-
const version =
|
|
31
|
+
const value = _chunkJ74L7UYPcjs.signal.call(void 0, initialValue);
|
|
32
|
+
const version = _chunkJ74L7UYPcjs.signal.call(void 0, 0);
|
|
33
33
|
const bumpVersion = () => {
|
|
34
34
|
const next = version() + 1;
|
|
35
35
|
version(next);
|
|
@@ -50,8 +50,8 @@ function createVersionedSignal(initialValue, options) {
|
|
|
50
50
|
force: () => {
|
|
51
51
|
bumpVersion();
|
|
52
52
|
},
|
|
53
|
-
peekVersion: () =>
|
|
54
|
-
peekValue: () =>
|
|
53
|
+
peekVersion: () => _chunkJ74L7UYPcjs.untrack.call(void 0, () => version()),
|
|
54
|
+
peekValue: () => _chunkJ74L7UYPcjs.untrack.call(void 0, () => value())
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -75,5 +75,5 @@ function createVersionedSignal(initialValue, options) {
|
|
|
75
75
|
|
|
76
76
|
|
|
77
77
|
|
|
78
|
-
exports.createAttributeBinding =
|
|
78
|
+
exports.createAttributeBinding = _chunkJ74L7UYPcjs.createAttributeBinding; exports.createChildBinding = _chunkJ74L7UYPcjs.createChildBinding; exports.createClassBinding = _chunkJ74L7UYPcjs.createClassBinding; exports.createContext = _chunk527QSKFMcjs.createContext; exports.createRenderEffect = _chunkJ74L7UYPcjs.createRenderEffect; exports.createScope = _chunkBSUMPMKXcjs.createScope; exports.createSelector = _chunkJ74L7UYPcjs.createSelector; exports.createShow = _chunkJ74L7UYPcjs.createShow; exports.createSignal = _chunkJ74L7UYPcjs.signal; exports.createStyleBinding = _chunkJ74L7UYPcjs.createStyleBinding; exports.createTextBinding = _chunkJ74L7UYPcjs.createTextBinding; exports.createVersionedSignal = createVersionedSignal; exports.effectScope = _chunkJ74L7UYPcjs.effectScope; exports.getDevtoolsHook = _chunkJ74L7UYPcjs.getDevtoolsHook; exports.hasContext = _chunk527QSKFMcjs.hasContext; exports.isReactive = _chunkJ74L7UYPcjs.isReactive; exports.runInScope = _chunkBSUMPMKXcjs.runInScope; exports.setCycleProtectionOptions = _chunkJ74L7UYPcjs.setCycleProtectionOptions; exports.unwrap = _chunkJ74L7UYPcjs.unwrap; exports.useContext = _chunk527QSKFMcjs.useContext;
|
|
79
79
|
//# sourceMappingURL=advanced.cjs.map
|
package/dist/advanced.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { R as ReactiveScope, S as Signal, c as createScope, a as createSelector, s as createSignal, e as effectScope, r as runInScope } from './scope-
|
|
2
|
-
export { b as createAttributeBinding, a as createChildBinding, e as createClassBinding, g as createRenderEffect, f as createShow, d as createStyleBinding, c as createTextBinding, i as isReactive, u as unwrap } from './effect-
|
|
3
|
-
export { C as Context, P as ProviderProps, c as createContext, h as hasContext, u as useContext } from './context-
|
|
1
|
+
export { R as ReactiveScope, S as Signal, c as createScope, a as createSelector, s as createSignal, e as effectScope, r as runInScope } from './scope-xmdo6lVU.cjs';
|
|
2
|
+
export { b as createAttributeBinding, a as createChildBinding, e as createClassBinding, g as createRenderEffect, f as createShow, d as createStyleBinding, c as createTextBinding, i as isReactive, u as unwrap } from './effect-ClARNUCc.cjs';
|
|
3
|
+
export { C as Context, P as ProviderProps, c as createContext, h as hasContext, u as useContext } from './context-9gFXOdJl.cjs';
|
|
4
4
|
|
|
5
5
|
interface VersionedSignalOptions<T> {
|
|
6
6
|
equals?: (prev: T, next: T) => boolean;
|
package/dist/advanced.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { R as ReactiveScope, S as Signal, c as createScope, a as createSelector, s as createSignal, e as effectScope, r as runInScope } from './scope-
|
|
2
|
-
export { b as createAttributeBinding, a as createChildBinding, e as createClassBinding, g as createRenderEffect, f as createShow, d as createStyleBinding, c as createTextBinding, i as isReactive, u as unwrap } from './effect-
|
|
3
|
-
export { C as Context, P as ProviderProps, c as createContext, h as hasContext, u as useContext } from './context-
|
|
1
|
+
export { R as ReactiveScope, S as Signal, c as createScope, a as createSelector, s as createSignal, e as effectScope, r as runInScope } from './scope-DvgMquEy.js';
|
|
2
|
+
export { b as createAttributeBinding, a as createChildBinding, e as createClassBinding, g as createRenderEffect, f as createShow, d as createStyleBinding, c as createTextBinding, i as isReactive, u as unwrap } from './effect-ClARNUCc.js';
|
|
3
|
+
export { C as Context, P as ProviderProps, c as createContext, h as hasContext, u as useContext } from './context-4woHo7-L.js';
|
|
4
4
|
|
|
5
5
|
interface VersionedSignalOptions<T> {
|
|
6
6
|
equals?: (prev: T, next: T) => boolean;
|
package/dist/advanced.js
CHANGED
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
createContext,
|
|
3
3
|
hasContext,
|
|
4
4
|
useContext
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-FG3M7EBL.js";
|
|
6
6
|
import {
|
|
7
7
|
createScope,
|
|
8
8
|
runInScope
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-QV5GOCR5.js";
|
|
10
10
|
import {
|
|
11
11
|
createAttributeBinding,
|
|
12
12
|
createChildBinding,
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
signal,
|
|
24
24
|
untrack,
|
|
25
25
|
unwrap
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-5KXEEQUO.js";
|
|
27
27
|
|
|
28
28
|
// src/versioned-signal.ts
|
|
29
29
|
function createVersionedSignal(initialValue, options) {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunkJ74L7UYPcjs = require('./chunk-J74L7UYP.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 = _chunkJ74L7UYPcjs.getCurrentRoot.call(void 0, );
|
|
34
|
+
const providerRoot = _chunkJ74L7UYPcjs.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
|
+
_chunkJ74L7UYPcjs.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 = _chunkJ74L7UYPcjs.pushRoot.call(void 0, providerRoot);
|
|
55
55
|
let nodes = [];
|
|
56
56
|
try {
|
|
57
|
-
const output =
|
|
58
|
-
nodes =
|
|
57
|
+
const output = _chunkJ74L7UYPcjs.createElement.call(void 0, children);
|
|
58
|
+
nodes = _chunkJ74L7UYPcjs.toNodeArray.call(void 0, output);
|
|
59
59
|
const parentNode = marker.parentNode;
|
|
60
60
|
if (parentNode) {
|
|
61
|
-
|
|
61
|
+
_chunkJ74L7UYPcjs.insertNodesBefore.call(void 0, parentNode, nodes, marker);
|
|
62
62
|
}
|
|
63
63
|
} finally {
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
_chunkJ74L7UYPcjs.popRoot.call(void 0, prev);
|
|
65
|
+
_chunkJ74L7UYPcjs.flushOnMount.call(void 0, providerRoot);
|
|
66
66
|
}
|
|
67
67
|
cleanup = () => {
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
_chunkJ74L7UYPcjs.destroyRoot.call(void 0, providerRoot);
|
|
69
|
+
_chunkJ74L7UYPcjs.removeNodes.call(void 0, nodes);
|
|
70
70
|
};
|
|
71
71
|
activeNodes = nodes;
|
|
72
72
|
};
|
|
73
|
-
|
|
73
|
+
_chunkJ74L7UYPcjs.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 = _chunkJ74L7UYPcjs.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 = _chunkJ74L7UYPcjs.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-527QSKFM.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/fict/fict/packages/runtime/dist/chunk-Q4EN6BXV.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;AAKtE,SAAS,aAAA,CAAc,IAAA,EAAyC;AAC9D,EAAA,IAAI,IAAA,EAAM,cAAA,CAAe,GAAA,CAAI,IAAI,CAAA;AACjC,EAAA,GAAA,CAAI,CAAC,GAAA,EAAK;AACR,IAAA,IAAA,kBAAM,I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W,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-Q4EN6BXV.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 {\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 { createRenderEffect } from './effect'\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-527QSKFM.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;AAKtE,SAAS,aAAA,CAAc,IAAA,EAAyC;AAC9D,EAAA,IAAI,IAAA,EAAM,cAAA,CAAe,GAAA,CAAI,IAAI,CAAA;AACjC,EAAA,GAAA,CAAI,CAAC,GAAA,EAAK;AACR,IAAA,IAAA,kBAAM,IAAI,GAAA,CAAI,CAAA;AACd,IAAA,cAAA,CAAe,GAAA,CAAI,IAAA,EAAM,GAAG,CAAA;AAAA,EAC9B;AACA,EAAA,OAAO,GAAA;AAC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,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-527QSKFM.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 {\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 { createRenderEffect } from './effect'\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"]}
|
|
@@ -512,7 +512,7 @@ var currentEffectCleanups;
|
|
|
512
512
|
var globalErrorHandlers = /* @__PURE__ */ new WeakMap();
|
|
513
513
|
var globalSuspenseHandlers = /* @__PURE__ */ new WeakMap();
|
|
514
514
|
function createRootContext(parent) {
|
|
515
|
-
return { parent, cleanups: [], destroyCallbacks: [] };
|
|
515
|
+
return { parent, cleanups: [], destroyCallbacks: [], suspended: false };
|
|
516
516
|
}
|
|
517
517
|
function pushRoot(root) {
|
|
518
518
|
if (!enterRootGuard(root)) {
|
|
@@ -714,13 +714,17 @@ function handleError(err, info, startRoot) {
|
|
|
714
714
|
}
|
|
715
715
|
function handleSuspend(token, startRoot) {
|
|
716
716
|
let root = startRoot ?? currentRoot;
|
|
717
|
+
const originRoot = root;
|
|
717
718
|
while (root) {
|
|
718
719
|
const handlers = root.suspenseHandlers;
|
|
719
720
|
if (handlers && handlers.length) {
|
|
720
721
|
for (let i = handlers.length - 1; i >= 0; i--) {
|
|
721
722
|
const handler = handlers[i];
|
|
722
723
|
const handled = handler(token);
|
|
723
|
-
if (handled !== false)
|
|
724
|
+
if (handled !== false) {
|
|
725
|
+
if (originRoot) originRoot.suspended = true;
|
|
726
|
+
return true;
|
|
727
|
+
}
|
|
724
728
|
}
|
|
725
729
|
}
|
|
726
730
|
root = root.parent;
|
|
@@ -730,7 +734,10 @@ function handleSuspend(token, startRoot) {
|
|
|
730
734
|
for (let i = globalForRoot.length - 1; i >= 0; i--) {
|
|
731
735
|
const handler = globalForRoot[i];
|
|
732
736
|
const handled = handler(token);
|
|
733
|
-
if (handled !== false)
|
|
737
|
+
if (handled !== false) {
|
|
738
|
+
if (originRoot) originRoot.suspended = true;
|
|
739
|
+
return true;
|
|
740
|
+
}
|
|
734
741
|
}
|
|
735
742
|
}
|
|
736
743
|
return false;
|
|
@@ -1054,7 +1061,25 @@ function runEffect(e) {
|
|
|
1054
1061
|
inCleanup = false;
|
|
1055
1062
|
}
|
|
1056
1063
|
}
|
|
1057
|
-
|
|
1064
|
+
let isDirty = false;
|
|
1065
|
+
try {
|
|
1066
|
+
isDirty = checkDirty(e.deps, e);
|
|
1067
|
+
} catch (err) {
|
|
1068
|
+
if (handleSuspend(err, e.root)) {
|
|
1069
|
+
if (e.flags !== 0) {
|
|
1070
|
+
e.flags = Watching;
|
|
1071
|
+
}
|
|
1072
|
+
return;
|
|
1073
|
+
}
|
|
1074
|
+
if (handleError(err, { source: "effect" }, e.root)) {
|
|
1075
|
+
if (e.flags !== 0) {
|
|
1076
|
+
e.flags = Watching;
|
|
1077
|
+
}
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
1080
|
+
throw err;
|
|
1081
|
+
}
|
|
1082
|
+
if (isDirty) {
|
|
1058
1083
|
++cycle;
|
|
1059
1084
|
effectRunDevtools(e);
|
|
1060
1085
|
e.depsTail = void 0;
|
|
@@ -1241,6 +1266,10 @@ function effect(fn) {
|
|
|
1241
1266
|
flags: WatchingRunning,
|
|
1242
1267
|
__id: void 0
|
|
1243
1268
|
};
|
|
1269
|
+
const root = getCurrentRoot();
|
|
1270
|
+
if (root) {
|
|
1271
|
+
e.root = root;
|
|
1272
|
+
}
|
|
1244
1273
|
registerEffectDevtools(e);
|
|
1245
1274
|
const prevSub = activeSub;
|
|
1246
1275
|
if (prevSub !== void 0) link(e, prevSub, 0);
|
|
@@ -1256,7 +1285,7 @@ function effect(fn) {
|
|
|
1256
1285
|
disposer[EFFECT_MARKER] = true;
|
|
1257
1286
|
return disposer;
|
|
1258
1287
|
}
|
|
1259
|
-
function effectWithCleanup(fn, cleanupRunner) {
|
|
1288
|
+
function effectWithCleanup(fn, cleanupRunner, root) {
|
|
1260
1289
|
const e = {
|
|
1261
1290
|
fn,
|
|
1262
1291
|
subs: void 0,
|
|
@@ -1267,6 +1296,10 @@ function effectWithCleanup(fn, cleanupRunner) {
|
|
|
1267
1296
|
runCleanup: cleanupRunner,
|
|
1268
1297
|
__id: void 0
|
|
1269
1298
|
};
|
|
1299
|
+
const resolvedRoot = root ?? getCurrentRoot();
|
|
1300
|
+
if (resolvedRoot) {
|
|
1301
|
+
e.root = resolvedRoot;
|
|
1302
|
+
}
|
|
1270
1303
|
registerEffectDevtools(e);
|
|
1271
1304
|
const prevSub = activeSub;
|
|
1272
1305
|
if (prevSub !== void 0) link(e, prevSub, 0);
|
|
@@ -1341,6 +1374,18 @@ function untrack(fn) {
|
|
|
1341
1374
|
activeSub = prev;
|
|
1342
1375
|
}
|
|
1343
1376
|
}
|
|
1377
|
+
function isSignal(fn) {
|
|
1378
|
+
return typeof fn === "function" && fn[SIGNAL_MARKER] === true;
|
|
1379
|
+
}
|
|
1380
|
+
function isComputed(fn) {
|
|
1381
|
+
return typeof fn === "function" && fn[COMPUTED_MARKER] === true;
|
|
1382
|
+
}
|
|
1383
|
+
function isEffect(fn) {
|
|
1384
|
+
return typeof fn === "function" && fn[EFFECT_MARKER] === true;
|
|
1385
|
+
}
|
|
1386
|
+
function isEffectScope(fn) {
|
|
1387
|
+
return typeof fn === "function" && fn[EFFECT_SCOPE_MARKER] === true;
|
|
1388
|
+
}
|
|
1344
1389
|
function setTransitionContext(value) {
|
|
1345
1390
|
const prev = isInTransition;
|
|
1346
1391
|
isInTransition = value;
|
|
@@ -1428,6 +1473,9 @@ function createEffect(fn) {
|
|
|
1428
1473
|
bucket.push(maybeCleanup);
|
|
1429
1474
|
}
|
|
1430
1475
|
} catch (err) {
|
|
1476
|
+
if (handleSuspend(err, rootForError)) {
|
|
1477
|
+
return;
|
|
1478
|
+
}
|
|
1431
1479
|
if (handleError(err, { source: "effect" }, rootForError)) {
|
|
1432
1480
|
return;
|
|
1433
1481
|
}
|
|
@@ -1436,7 +1484,7 @@ function createEffect(fn) {
|
|
|
1436
1484
|
});
|
|
1437
1485
|
cleanups = bucket;
|
|
1438
1486
|
};
|
|
1439
|
-
const disposeEffect = effectWithCleanup(run, doCleanup);
|
|
1487
|
+
const disposeEffect = effectWithCleanup(run, doCleanup, rootForError);
|
|
1440
1488
|
const teardown = () => {
|
|
1441
1489
|
runCleanupList(cleanups);
|
|
1442
1490
|
disposeEffect();
|
|
@@ -1460,6 +1508,9 @@ function createRenderEffect(fn) {
|
|
|
1460
1508
|
cleanup = maybeCleanup;
|
|
1461
1509
|
}
|
|
1462
1510
|
} catch (err) {
|
|
1511
|
+
if (handleSuspend(err, rootForError)) {
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1463
1514
|
const handled = handleError(err, { source: "effect" }, rootForError);
|
|
1464
1515
|
if (handled) {
|
|
1465
1516
|
return;
|
|
@@ -1467,7 +1518,7 @@ function createRenderEffect(fn) {
|
|
|
1467
1518
|
throw err;
|
|
1468
1519
|
}
|
|
1469
1520
|
};
|
|
1470
|
-
const disposeEffect = effectWithCleanup(run, doCleanup);
|
|
1521
|
+
const disposeEffect = effectWithCleanup(run, doCleanup, rootForError);
|
|
1471
1522
|
const teardown = () => {
|
|
1472
1523
|
if (cleanup) {
|
|
1473
1524
|
cleanup();
|
|
@@ -1674,7 +1725,10 @@ function untrack2(fn) {
|
|
|
1674
1725
|
// src/binding.ts
|
|
1675
1726
|
var isDev5 = true ? false : typeof process === "undefined" || process.env?.NODE_ENV !== "production";
|
|
1676
1727
|
function isReactive(value) {
|
|
1677
|
-
|
|
1728
|
+
if (typeof value !== "function") return false;
|
|
1729
|
+
if (isSignal(value) || isComputed(value)) return true;
|
|
1730
|
+
if (isEffect(value) || isEffectScope(value)) return false;
|
|
1731
|
+
return value.length === 0;
|
|
1678
1732
|
}
|
|
1679
1733
|
function unwrap(value) {
|
|
1680
1734
|
return isReactive(value) ? value() : value;
|
|
@@ -1980,6 +2034,7 @@ function insert(parent, getValue, markerOrCreateElement, createElementFn) {
|
|
|
1980
2034
|
const root = createRootContext(hostRoot);
|
|
1981
2035
|
const prev = pushRoot(root);
|
|
1982
2036
|
let nodes = [];
|
|
2037
|
+
let handledError = false;
|
|
1983
2038
|
try {
|
|
1984
2039
|
let newNode;
|
|
1985
2040
|
if (value instanceof Node) {
|
|
@@ -2002,12 +2057,31 @@ function insert(parent, getValue, markerOrCreateElement, createElementFn) {
|
|
|
2002
2057
|
newNode = createFn ? createFn(value) : document.createTextNode(String(value));
|
|
2003
2058
|
}
|
|
2004
2059
|
nodes = toNodeArray(newNode);
|
|
2060
|
+
if (root.suspended) {
|
|
2061
|
+
handledError = true;
|
|
2062
|
+
destroyRoot(root);
|
|
2063
|
+
return;
|
|
2064
|
+
}
|
|
2005
2065
|
if (parentNode) {
|
|
2006
2066
|
insertNodesBefore(parentNode, nodes, marker);
|
|
2007
2067
|
}
|
|
2068
|
+
} catch (err) {
|
|
2069
|
+
if (handleSuspend(err, root)) {
|
|
2070
|
+
handledError = true;
|
|
2071
|
+
destroyRoot(root);
|
|
2072
|
+
return;
|
|
2073
|
+
}
|
|
2074
|
+
if (handleError(err, { source: "renderChild" }, root)) {
|
|
2075
|
+
handledError = true;
|
|
2076
|
+
destroyRoot(root);
|
|
2077
|
+
return;
|
|
2078
|
+
}
|
|
2079
|
+
throw err;
|
|
2008
2080
|
} finally {
|
|
2009
2081
|
popRoot(prev);
|
|
2010
|
-
|
|
2082
|
+
if (!handledError) {
|
|
2083
|
+
flushOnMount(root);
|
|
2084
|
+
}
|
|
2011
2085
|
}
|
|
2012
2086
|
currentRoot2 = root;
|
|
2013
2087
|
currentNodes = nodes;
|
|
@@ -3319,4 +3393,4 @@ export {
|
|
|
3319
3393
|
createElement,
|
|
3320
3394
|
template
|
|
3321
3395
|
};
|
|
3322
|
-
//# sourceMappingURL=chunk-
|
|
3396
|
+
//# sourceMappingURL=chunk-5KXEEQUO.js.map
|