@fluixi/core 1.0.0-alpha.82 → 1.0.0-alpha.84
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/cdn/core.global.js +2 -1
- package/dist/cli/generate.cjs +4117 -292
- package/dist/cli/generate.mjs +4122 -292
- package/dist/cli/index.cjs +4117 -292
- package/dist/cli/index.mjs +4122 -292
- package/dist/cli/run.cjs +63 -1
- package/dist/cli/run.mjs +39 -1
- package/dist/src/cdn/chunk-VNLCQBFQ.mjs +747 -0
- package/dist/src/cdn/core.cjs +1279 -1
- package/dist/src/cdn/core.d.ts +3 -3
- package/dist/src/cdn/core.js +3 -3
- package/dist/src/cdn/core.mjs +642 -1
- package/dist/src/cdn/router-WMN2AA7E.mjs +66 -0
- package/dist/src/index.cjs +1201 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -11
- package/dist/src/index.mjs +1313 -1
- package/dist/src/jsx-dev-runtime.cjs +26 -1
- package/dist/src/jsx-dev-runtime.mjs +24 -1
- package/dist/src/jsx-runtime.cjs +26 -1
- package/dist/src/jsx-runtime.js +0 -9
- package/dist/src/jsx-runtime.mjs +24 -1
- package/dist/src/lib/client/chunk-2C2KDDQV.mjs +133 -0
- package/dist/src/lib/client/index.cjs +870 -1
- package/dist/src/lib/client/index.d.ts +10 -14
- package/dist/src/lib/client/index.d.ts.map +1 -1
- package/dist/src/lib/client/index.js +36 -21
- package/dist/src/lib/client/index.mjs +222 -1
- package/dist/src/lib/client/router-X526HSWQ.mjs +548 -0
- package/dist/src/lib/context/context.cjs +118 -1
- package/dist/src/lib/context/context.d.ts +20 -38
- package/dist/src/lib/context/context.d.ts.map +1 -1
- package/dist/src/lib/context/context.js +10 -47
- package/dist/src/lib/context/context.mjs +99 -1
- package/dist/src/lib/context/index.cjs +120 -1
- package/dist/src/lib/context/index.mjs +99 -1
- package/dist/src/lib/control-flow.cjs +35 -1
- package/dist/src/lib/control-flow.mjs +25 -1
- package/dist/src/lib/core.cjs +1200 -1
- package/dist/src/lib/core.d.ts +0 -2
- package/dist/src/lib/core.d.ts.map +1 -1
- package/dist/src/lib/core.js +14 -48
- package/dist/src/lib/core.mjs +1313 -1
- package/dist/src/lib/env/index.cjs +60 -1
- package/dist/src/lib/env/index.d.ts +7 -8
- package/dist/src/lib/env/index.d.ts.map +1 -1
- package/dist/src/lib/env/index.js +14 -9
- package/dist/src/lib/env/index.mjs +39 -1
- package/dist/src/lib/i18n/index.cjs +108 -1
- package/dist/src/lib/i18n/index.d.ts +31 -10
- package/dist/src/lib/i18n/index.d.ts.map +1 -1
- package/dist/src/lib/i18n/index.js +31 -10
- package/dist/src/lib/i18n/index.mjs +88 -1
- package/dist/src/lib/index.cjs +633 -1
- package/dist/src/lib/index.d.ts +0 -2
- package/dist/src/lib/index.d.ts.map +1 -1
- package/dist/src/lib/index.js +5 -11
- package/dist/src/lib/index.mjs +721 -1
- package/dist/src/lib/isomorphic.cjs +85 -1
- package/dist/src/lib/isomorphic.d.ts +41 -8
- package/dist/src/lib/isomorphic.d.ts.map +1 -1
- package/dist/src/lib/isomorphic.js +38 -5
- package/dist/src/lib/isomorphic.mjs +64 -1
- package/dist/src/lib/jsx-runtime/index.cjs +21 -1
- package/dist/src/lib/jsx-runtime/index.d.ts +1 -1
- package/dist/src/lib/jsx-runtime/index.js +1 -11
- package/dist/src/lib/jsx-runtime/index.mjs +4 -1
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.cjs +21 -1
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.mjs +4 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.cjs +302 -8
- package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts +15 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts.map +1 -1
- package/dist/src/lib/plugins/fluixi-routes-plugin.js +19 -5
- package/dist/src/lib/plugins/fluixi-routes-plugin.mjs +271 -8
- package/dist/src/lib/plugins/index.cjs +311 -8
- package/dist/src/lib/plugins/index.mjs +279 -8
- package/dist/src/lib/plugins/route-codegen.cjs +73 -8
- package/dist/src/lib/plugins/route-codegen.d.ts +0 -1
- package/dist/src/lib/plugins/route-codegen.d.ts.map +1 -1
- package/dist/src/lib/plugins/route-codegen.js +4 -5
- package/dist/src/lib/plugins/route-codegen.mjs +52 -8
- package/dist/src/lib/plugins/route-scanner.cjs +189 -1
- package/dist/src/lib/plugins/route-scanner.d.ts +1 -2
- package/dist/src/lib/plugins/route-scanner.d.ts.map +1 -1
- package/dist/src/lib/plugins/route-scanner.js +7 -8
- package/dist/src/lib/plugins/route-scanner.mjs +158 -1
- package/dist/src/lib/plugins/vite.cjs +27 -1
- package/dist/src/lib/plugins/vite.mjs +6 -1
- package/dist/src/lib/render/await.cjs +38 -1
- package/dist/src/lib/render/await.d.ts +18 -0
- package/dist/src/lib/render/await.d.ts.map +1 -1
- package/dist/src/lib/render/await.js +20 -2
- package/dist/src/lib/render/await.mjs +17 -1
- package/dist/src/lib/render/component.cjs +221 -1
- package/dist/src/lib/render/component.d.ts +3 -44
- package/dist/src/lib/render/component.d.ts.map +1 -1
- package/dist/src/lib/render/component.js +32 -59
- package/dist/src/lib/render/component.mjs +214 -1
- package/dist/src/lib/render/deferred.cjs +175 -1
- package/dist/src/lib/render/deferred.d.ts.map +1 -1
- package/dist/src/lib/render/deferred.js +8 -8
- package/dist/src/lib/render/deferred.mjs +158 -1
- package/dist/src/lib/render/index.cjs +573 -1
- package/dist/src/lib/render/index.d.ts +3 -17
- package/dist/src/lib/render/index.d.ts.map +1 -1
- package/dist/src/lib/render/index.js +12 -26
- package/dist/src/lib/render/index.mjs +590 -1
- package/dist/src/lib/render/lazy.cjs +67 -1
- package/dist/src/lib/render/lazy.d.ts +22 -1
- package/dist/src/lib/render/lazy.d.ts.map +1 -1
- package/dist/src/lib/render/lazy.js +47 -8
- package/dist/src/lib/render/lazy.mjs +50 -1
- package/dist/src/lib/render/suspense.cjs +141 -1
- package/dist/src/lib/render/suspense.d.ts +40 -0
- package/dist/src/lib/render/suspense.d.ts.map +1 -1
- package/dist/src/lib/render/suspense.js +47 -7
- package/dist/src/lib/render/suspense.mjs +136 -1
- package/dist/src/lib/render/versions.cjs +35 -1
- package/dist/src/lib/render/versions.js +6 -6
- package/dist/src/lib/render/versions.mjs +14 -1
- package/dist/src/lib/router/data.cjs +230 -1
- package/dist/src/lib/router/data.d.ts +1 -13
- package/dist/src/lib/router/data.d.ts.map +1 -1
- package/dist/src/lib/router/data.js +1 -13
- package/dist/src/lib/router/data.mjs +214 -1
- package/dist/src/lib/router/index.cjs +627 -1
- package/dist/src/lib/router/index.d.ts +62 -10
- package/dist/src/lib/router/index.d.ts.map +1 -1
- package/dist/src/lib/router/index.js +90 -39
- package/dist/src/lib/router/index.mjs +639 -1
- package/dist/src/lib/server/hydration.cjs +169 -1
- package/dist/src/lib/server/hydration.d.ts +15 -55
- package/dist/src/lib/server/hydration.d.ts.map +1 -1
- package/dist/src/lib/server/hydration.js +23 -62
- package/dist/src/lib/server/hydration.mjs +148 -1
- package/dist/src/lib/server/index.cjs +401 -11
- package/dist/src/lib/server/index.d.ts +30 -6
- package/dist/src/lib/server/index.d.ts.map +1 -1
- package/dist/src/lib/server/index.js +34 -11
- package/dist/src/lib/server/index.mjs +379 -11
- package/dist/src/lib/server/reactive.cjs +197 -1
- package/dist/src/lib/server/reactive.d.ts +18 -77
- package/dist/src/lib/server/reactive.d.ts.map +1 -1
- package/dist/src/lib/server/reactive.js +19 -78
- package/dist/src/lib/server/reactive.mjs +176 -1
- package/dist/src/lib/theme/index.cjs +110 -1
- package/dist/src/lib/theme/index.d.ts +19 -4
- package/dist/src/lib/theme/index.d.ts.map +1 -1
- package/dist/src/lib/theme/index.js +17 -2
- package/dist/src/lib/theme/index.mjs +89 -1
- package/dist/src/lib/utils/index.cjs +209 -1
- package/dist/src/lib/utils/index.d.ts +0 -93
- package/dist/src/lib/utils/index.d.ts.map +1 -1
- package/dist/src/lib/utils/index.js +0 -93
- package/dist/src/lib/utils/index.mjs +188 -1
- package/dist/src/routes.cjs +37 -1
- package/dist/src/routes.d.ts +1 -1
- package/dist/src/routes.js +2 -2
- package/dist/src/routes.mjs +17 -1
- package/dist/src/server.cjs +400 -11
- package/dist/src/server.d.ts +0 -1
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/server.js +0 -1
- package/dist/src/server.mjs +377 -11
- package/dist/src/utils.cjs +21 -1
- package/dist/src/utils.d.ts +1 -1
- package/dist/src/utils.js +1 -1
- package/dist/src/utils.mjs +4 -1
- package/dist/src/version.generated.cjs +26 -1
- package/dist/src/version.generated.d.ts +1 -1
- package/dist/src/version.generated.js +2 -2
- package/dist/src/version.generated.mjs +5 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +17 -16
- package/src/index.ts +2 -14
- package/dist/src/cdn/chunk-RN7C7HNS.mjs +0 -1
- package/dist/src/cdn/router-QB3W43UQ.mjs +0 -1
- package/dist/src/lib/client/chunk-FT22BLCQ.mjs +0 -1
- package/dist/src/lib/client/router-IH7JYMRU.mjs +0 -1
|
@@ -28,7 +28,7 @@ export interface ProviderProps<Child> {
|
|
|
28
28
|
children?: Child extends Record<any, any> ? PickChildren<Child> : never;
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
* Lazy-safe form
|
|
31
|
+
* Lazy-safe form: pass the component's `props` so `children` is read through a
|
|
32
32
|
* getter (inside the stamped scope), never materialised early. This is the
|
|
33
33
|
* recommended way to wrap an <Outlet/>.
|
|
34
34
|
*
|
|
@@ -40,10 +40,25 @@ export declare function createProvider<T>(context: Context<T>, value: T | Access
|
|
|
40
40
|
children?: any;
|
|
41
41
|
}): ComponentChild;
|
|
42
42
|
/**
|
|
43
|
-
* @deprecated Eager form
|
|
43
|
+
* @deprecated Eager form: `{ context, value, children }` reads `children` before
|
|
44
44
|
* the context is stamped (see warnEagerProvider). Use `createProvider(context,
|
|
45
45
|
* value, props)` or `<Context.Provider>` instead.
|
|
46
46
|
*/
|
|
47
|
+
/**
|
|
48
|
+
* Provide a context value to a subtree, without writing the `Provider` tag.
|
|
49
|
+
*
|
|
50
|
+
* Takes either a `Context` from `createContext` or a provider component, so it works for
|
|
51
|
+
* both shapes the context API hands back. `value` may be an accessor, in which case
|
|
52
|
+
* descendants see it change.
|
|
53
|
+
*
|
|
54
|
+
* Reach for the `Provider` tag in markup; this is for providing a value from code, such as
|
|
55
|
+
* a wrapper that supplies context around children it was handed.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* createProvider(ThemeContext, 'dark', { children: () => renderPage() });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
47
62
|
export declare function createProvider<T, S = Children>(props: ContextProvider<T, S>): ComponentChild;
|
|
48
63
|
/**
|
|
49
64
|
* Creates a context with a provider component
|
|
@@ -51,10 +66,6 @@ export declare function createProvider<T, S = Children>(props: ContextProvider<T
|
|
|
51
66
|
* Returns both the context and a convenience component that combines
|
|
52
67
|
* context creation with the provider.
|
|
53
68
|
*
|
|
54
|
-
* @template T - Type of the context value
|
|
55
|
-
* @param {T} defaultValue - Default value for the context
|
|
56
|
-
* @returns {[Context<T>, (props: { value: T | Accessor<T>; children: TemplateResult | TemplateResult[] }) => TemplateResult]} Context and provider component
|
|
57
|
-
*
|
|
58
69
|
* @example
|
|
59
70
|
* ```typescript
|
|
60
71
|
* import { createContextWithProvider } from '@fluixi/core/context';
|
|
@@ -92,10 +103,6 @@ export declare function createContextWithProvider<T, U>(defaultValue: T): [Conte
|
|
|
92
103
|
*
|
|
93
104
|
* Utility function to avoid deeply nested Provider components.
|
|
94
105
|
*
|
|
95
|
-
* @param {Array<[Context<any>, any]>} contexts - Array of [context, value] tuples
|
|
96
|
-
* @param {TemplateResult | TemplateResult[]} children - Children to render
|
|
97
|
-
* @returns {TemplateResult} Nested providers with children
|
|
98
|
-
*
|
|
99
106
|
* @example
|
|
100
107
|
* ```typescript
|
|
101
108
|
* import { composeProviders, createContext } from '@fluixi/core/context';
|
|
@@ -130,10 +137,6 @@ export declare function composeProviders(contexts: Array<[Context<any>, any]>, c
|
|
|
130
137
|
*
|
|
131
138
|
* Alternative to useContext hook, useful for rendering props patterns.
|
|
132
139
|
*
|
|
133
|
-
* @template T - Type of the context value
|
|
134
|
-
* @param {Context<T>} context - Context to consume
|
|
135
|
-
* @returns {(props: { children: (value: T) => TemplateResult }) => TemplateResult} Consumer component
|
|
136
|
-
*
|
|
137
140
|
* @example
|
|
138
141
|
* ```typescript
|
|
139
142
|
* import { createContext, createConsumer } from '@fluixi/core/context';
|
|
@@ -165,11 +168,6 @@ export declare function createConsumer<T>(context: Context<T>): (props: {
|
|
|
165
168
|
*
|
|
166
169
|
* Useful for creating context-based stores or services.
|
|
167
170
|
*
|
|
168
|
-
* @template T - Type of the context value
|
|
169
|
-
* @param {Context<T>} context - Context to use
|
|
170
|
-
* @param {() => T} factory - Factory function to create the context value
|
|
171
|
-
* @returns {T} Context value
|
|
172
|
-
*
|
|
173
171
|
* @example
|
|
174
172
|
* ```typescript
|
|
175
173
|
* import { createContext, useProvide, Provider } from '@fluixi/core/context';
|
|
@@ -211,10 +209,6 @@ export declare function useProvide<T>(context: Context<T>, factory: () => T): T;
|
|
|
211
209
|
/**
|
|
212
210
|
* Creates a scoped context that only exists within a specific component tree
|
|
213
211
|
*
|
|
214
|
-
* @template T - Type of the context value
|
|
215
|
-
* @param {T} defaultValue - Default value for the context
|
|
216
|
-
* @returns {Context<T>} Scoped context object
|
|
217
|
-
*
|
|
218
212
|
* @example
|
|
219
213
|
* ```typescript
|
|
220
214
|
* import { createContext } from '@fluixi/core/context';
|
|
@@ -226,13 +220,9 @@ export declare function useProvide<T>(context: Context<T>, factory: () => T): T;
|
|
|
226
220
|
/**
|
|
227
221
|
* Create a context for sharing state across component tree
|
|
228
222
|
*
|
|
229
|
-
*
|
|
223
|
+
* Context is lookup-based, works on server and client
|
|
230
224
|
* Supports nested contexts and complex values
|
|
231
225
|
*
|
|
232
|
-
* @template T - Context value type
|
|
233
|
-
* @param {T} defaultValue - Default value
|
|
234
|
-
* @returns {Context<T>} Context object with Provider
|
|
235
|
-
*
|
|
236
226
|
* @example
|
|
237
227
|
* ```typescript
|
|
238
228
|
* // Simple context
|
|
@@ -260,10 +250,6 @@ export declare function useProvide<T>(context: Context<T>, factory: () => T): T;
|
|
|
260
250
|
/**
|
|
261
251
|
* Creates a scoped context that only exists within a specific component tree
|
|
262
252
|
*
|
|
263
|
-
* @template T - Type of the context value
|
|
264
|
-
* @param {T} defaultValue - Default value for the context
|
|
265
|
-
* @returns {Context<T>} Scoped context object
|
|
266
|
-
*
|
|
267
253
|
* @example
|
|
268
254
|
* ```typescript
|
|
269
255
|
* import { createContext } from '@fluixi/core';
|
|
@@ -295,7 +281,7 @@ export declare function useProvide<T>(context: Context<T>, factory: () => T): T;
|
|
|
295
281
|
* `
|
|
296
282
|
* ```
|
|
297
283
|
*/
|
|
298
|
-
export declare function createContext<T>(defaultValue?: T): {
|
|
284
|
+
export declare function createContext<T>(defaultValue?: T, name?: string): {
|
|
299
285
|
id: symbol;
|
|
300
286
|
Provider: (props: {
|
|
301
287
|
value: T;
|
|
@@ -307,11 +293,7 @@ export declare function createContext<T>(defaultValue?: T): {
|
|
|
307
293
|
/**
|
|
308
294
|
* Use context value from nearest Provider
|
|
309
295
|
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
* @template T - Context value type
|
|
313
|
-
* @param {Context} context - Context to use
|
|
314
|
-
* @returns {T} Context value
|
|
296
|
+
* Lookup-based, no subscriptions on server
|
|
315
297
|
*
|
|
316
298
|
* @example
|
|
317
299
|
* ```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/lib/context/context.ts"],"names":[],"mappings":"AAKA,OAAO,EAAc,KAAK,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAE9E,OAAO,EACL,QAAQ,EACR,OAAO,EAER,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/lib/context/context.ts"],"names":[],"mappings":"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"}
|
|
@@ -10,10 +10,6 @@ import { readChildren, } from '@fluixi/reactive/signal';
|
|
|
10
10
|
*
|
|
11
11
|
* This wraps @fluixi/reactive's Provider for use with Lit templates.
|
|
12
12
|
*
|
|
13
|
-
* @template T - Type of the context value
|
|
14
|
-
* @param {ContextProvider<T>} props - Component props
|
|
15
|
-
* @returns {TemplateResult} Rendered children with context
|
|
16
|
-
*
|
|
17
13
|
* @example
|
|
18
14
|
* ```typescript
|
|
19
15
|
* import { createContext, Provider } from '@fluixi/core/context';
|
|
@@ -80,9 +76,9 @@ function warnEagerProvider() {
|
|
|
80
76
|
'routed <Outlet/> that has siblings inside the provider renders detached and its ' +
|
|
81
77
|
'descendants see no context under SSR. Use the lazy form instead:\n' +
|
|
82
78
|
' createProvider(Context, value, props) // children stays a getter\n' +
|
|
83
|
-
' // or JSX: <Context.Provider value={
|
|
79
|
+
' // or JSX: <Context.Provider value={...}>{props.children}</Context.Provider>');
|
|
84
80
|
}
|
|
85
|
-
// Returns the Provider's rendered output, not a component
|
|
81
|
+
// Returns the Provider's rendered output, not a component, it was annotated
|
|
86
82
|
// `Component<T>`, which made `<MyProvider>` fail as a JSX element.
|
|
87
83
|
export function createProvider(a, value, childProps) {
|
|
88
84
|
// Distinguish the two overloads: a Context (from createContext) exposes `.Provider`,
|
|
@@ -98,7 +94,7 @@ export function createProvider(a, value, childProps) {
|
|
|
98
94
|
// Always read children through a getter so they render INSIDE the stamped scope.
|
|
99
95
|
// For the lazy form `childProps.children` is still a getter here (untouched); for
|
|
100
96
|
// the eager form the caller already materialised it, so this can only mitigate,
|
|
101
|
-
// not fully fix
|
|
97
|
+
// not fully fix: hence the deprecation warning above.
|
|
102
98
|
const sourceProps = isLazyForm ? childProps : a;
|
|
103
99
|
return context.Provider({
|
|
104
100
|
value: resolvedValue,
|
|
@@ -118,10 +114,6 @@ export function createProvider(a, value, childProps) {
|
|
|
118
114
|
* Returns both the context and a convenience component that combines
|
|
119
115
|
* context creation with the provider.
|
|
120
116
|
*
|
|
121
|
-
* @template T - Type of the context value
|
|
122
|
-
* @param {T} defaultValue - Default value for the context
|
|
123
|
-
* @returns {[Context<T>, (props: { value: T | Accessor<T>; children: TemplateResult | TemplateResult[] }) => TemplateResult]} Context and provider component
|
|
124
|
-
*
|
|
125
117
|
* @example
|
|
126
118
|
* ```typescript
|
|
127
119
|
* import { createContextWithProvider } from '@fluixi/core/context';
|
|
@@ -167,10 +159,6 @@ export function createContextWithProvider(defaultValue) {
|
|
|
167
159
|
*
|
|
168
160
|
* Utility function to avoid deeply nested Provider components.
|
|
169
161
|
*
|
|
170
|
-
* @param {Array<[Context<any>, any]>} contexts - Array of [context, value] tuples
|
|
171
|
-
* @param {TemplateResult | TemplateResult[]} children - Children to render
|
|
172
|
-
* @returns {TemplateResult} Nested providers with children
|
|
173
|
-
*
|
|
174
162
|
* @example
|
|
175
163
|
* ```typescript
|
|
176
164
|
* import { composeProviders, createContext } from '@fluixi/core/context';
|
|
@@ -216,10 +204,6 @@ export function composeProviders(contexts, children) {
|
|
|
216
204
|
*
|
|
217
205
|
* Alternative to useContext hook, useful for rendering props patterns.
|
|
218
206
|
*
|
|
219
|
-
* @template T - Type of the context value
|
|
220
|
-
* @param {Context<T>} context - Context to consume
|
|
221
|
-
* @returns {(props: { children: (value: T) => TemplateResult }) => TemplateResult} Consumer component
|
|
222
|
-
*
|
|
223
207
|
* @example
|
|
224
208
|
* ```typescript
|
|
225
209
|
* import { createContext, createConsumer } from '@fluixi/core/context';
|
|
@@ -254,11 +238,6 @@ export function createConsumer(context) {
|
|
|
254
238
|
*
|
|
255
239
|
* Useful for creating context-based stores or services.
|
|
256
240
|
*
|
|
257
|
-
* @template T - Type of the context value
|
|
258
|
-
* @param {Context<T>} context - Context to use
|
|
259
|
-
* @param {() => T} factory - Factory function to create the context value
|
|
260
|
-
* @returns {T} Context value
|
|
261
|
-
*
|
|
262
241
|
* @example
|
|
263
242
|
* ```typescript
|
|
264
243
|
* import { createContext, useProvide, Provider } from '@fluixi/core/context';
|
|
@@ -308,10 +287,6 @@ export function useProvide(context, factory) {
|
|
|
308
287
|
/**
|
|
309
288
|
* Creates a scoped context that only exists within a specific component tree
|
|
310
289
|
*
|
|
311
|
-
* @template T - Type of the context value
|
|
312
|
-
* @param {T} defaultValue - Default value for the context
|
|
313
|
-
* @returns {Context<T>} Scoped context object
|
|
314
|
-
*
|
|
315
290
|
* @example
|
|
316
291
|
* ```typescript
|
|
317
292
|
* import { createContext } from '@fluixi/core/context';
|
|
@@ -332,13 +307,9 @@ export function useProvide(context, factory) {
|
|
|
332
307
|
/**
|
|
333
308
|
* Create a context for sharing state across component tree
|
|
334
309
|
*
|
|
335
|
-
*
|
|
310
|
+
* Context is lookup-based, works on server and client
|
|
336
311
|
* Supports nested contexts and complex values
|
|
337
312
|
*
|
|
338
|
-
* @template T - Context value type
|
|
339
|
-
* @param {T} defaultValue - Default value
|
|
340
|
-
* @returns {Context<T>} Context object with Provider
|
|
341
|
-
*
|
|
342
313
|
* @example
|
|
343
314
|
* ```typescript
|
|
344
315
|
* // Simple context
|
|
@@ -366,10 +337,6 @@ export function useProvide(context, factory) {
|
|
|
366
337
|
/**
|
|
367
338
|
* Creates a scoped context that only exists within a specific component tree
|
|
368
339
|
*
|
|
369
|
-
* @template T - Type of the context value
|
|
370
|
-
* @param {T} defaultValue - Default value for the context
|
|
371
|
-
* @returns {Context<T>} Scoped context object
|
|
372
|
-
*
|
|
373
340
|
* @example
|
|
374
341
|
* ```typescript
|
|
375
342
|
* import { createContext } from '@fluixi/core';
|
|
@@ -401,16 +368,16 @@ export function useProvide(context, factory) {
|
|
|
401
368
|
* `
|
|
402
369
|
* ```
|
|
403
370
|
*/
|
|
404
|
-
export function createContext(defaultValue) {
|
|
405
|
-
const context = createReactiveContext(defaultValue);
|
|
371
|
+
export function createContext(defaultValue, name) {
|
|
372
|
+
const context = createReactiveContext(defaultValue, name);
|
|
406
373
|
// Wrap Provider to work with both JSX and Lit-html
|
|
407
374
|
const Provider = (props) => {
|
|
408
375
|
if (props.debug === true) {
|
|
409
376
|
}
|
|
410
377
|
// Pass children LAZILY (a getter). The reactive Provider reads children inside
|
|
411
|
-
// its render effect,
|
|
378
|
+
// its render effect, after stamping the context on the owner. Reading
|
|
412
379
|
// props.children here (e.g. `children: props.children`) evaluates the imperative
|
|
413
|
-
// `get children()` getter eagerly, so the children
|
|
380
|
+
// `get children()` getter eagerly, so the children, and any <Outlet/> in them,
|
|
414
381
|
// render before the context is available.
|
|
415
382
|
return context.Provider({
|
|
416
383
|
value: props.value,
|
|
@@ -434,11 +401,7 @@ export function createContext(defaultValue) {
|
|
|
434
401
|
/**
|
|
435
402
|
* Use context value from nearest Provider
|
|
436
403
|
*
|
|
437
|
-
*
|
|
438
|
-
*
|
|
439
|
-
* @template T - Context value type
|
|
440
|
-
* @param {Context} context - Context to use
|
|
441
|
-
* @returns {T} Context value
|
|
404
|
+
* Lookup-based, no subscriptions on server
|
|
442
405
|
*
|
|
443
406
|
* @example
|
|
444
407
|
* ```typescript
|
|
@@ -456,7 +419,7 @@ export function createContext(defaultValue) {
|
|
|
456
419
|
* ```
|
|
457
420
|
*/
|
|
458
421
|
export function useContext(context) {
|
|
459
|
-
// Use reactive context lookup
|
|
422
|
+
// Use reactive context lookup: walks up Owner chain
|
|
460
423
|
const value = useReactiveContext(context);
|
|
461
424
|
return value !== undefined ? value : context.defaultValue;
|
|
462
425
|
}
|
|
@@ -1 +1,99 @@
|
|
|
1
|
-
|
|
1
|
+
// src/lib/context/context.ts
|
|
2
|
+
import { asProvider } from "@fluixi/dom";
|
|
3
|
+
import { createContext as createReactiveContext, useContext as useReactiveContext } from "@fluixi/reactive/signal";
|
|
4
|
+
import {
|
|
5
|
+
readChildren
|
|
6
|
+
} from "@fluixi/reactive/signal";
|
|
7
|
+
var _warnedEagerProvider = false;
|
|
8
|
+
function warnEagerProvider() {
|
|
9
|
+
if (_warnedEagerProvider) return;
|
|
10
|
+
_warnedEagerProvider = true;
|
|
11
|
+
if (typeof process !== "undefined" && true) return;
|
|
12
|
+
console.warn(
|
|
13
|
+
"[fluixi] createProvider({ context, value, children }) reads `children` eagerly: the object literal materialises `children` BEFORE the context is stamped, so a routed <Outlet/> that has siblings inside the provider renders detached and its descendants see no context under SSR. Use the lazy form instead:\n createProvider(Context, value, props) // children stays a getter\n // or JSX: <Context.Provider value={...}>{props.children}</Context.Provider>"
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
function createProvider(a, value, childProps) {
|
|
17
|
+
const isLazyForm = !!a?.Provider;
|
|
18
|
+
const context = isLazyForm ? a : a.context;
|
|
19
|
+
const rawValue = isLazyForm ? value : a.value;
|
|
20
|
+
const debug = isLazyForm ? false : a.debug ?? false;
|
|
21
|
+
if (!isLazyForm) warnEagerProvider();
|
|
22
|
+
const resolvedValue = typeof rawValue === "function" ? rawValue() : rawValue;
|
|
23
|
+
const sourceProps = isLazyForm ? childProps : a;
|
|
24
|
+
return context.Provider({
|
|
25
|
+
value: resolvedValue,
|
|
26
|
+
get children() {
|
|
27
|
+
return sourceProps?.children;
|
|
28
|
+
},
|
|
29
|
+
debug
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function createContextWithProvider(defaultValue) {
|
|
33
|
+
const context = createContext(defaultValue);
|
|
34
|
+
const provider = (props) => {
|
|
35
|
+
return createProvider(context, props.value, props);
|
|
36
|
+
};
|
|
37
|
+
return [context, provider];
|
|
38
|
+
}
|
|
39
|
+
function composeProviders(contexts, children) {
|
|
40
|
+
if (contexts.length === 0) {
|
|
41
|
+
return readChildren(() => children);
|
|
42
|
+
}
|
|
43
|
+
const [context, value] = contexts[0];
|
|
44
|
+
const remaining = contexts.slice(1);
|
|
45
|
+
return createProvider(context, value, {
|
|
46
|
+
get children() {
|
|
47
|
+
return composeProviders(remaining, children);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function createConsumer(context) {
|
|
52
|
+
return (props) => {
|
|
53
|
+
const value = useContext(context);
|
|
54
|
+
return props.children(value);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function useProvide(context, factory) {
|
|
58
|
+
const existing = useContext(context);
|
|
59
|
+
if (existing === context.defaultValue) {
|
|
60
|
+
return factory();
|
|
61
|
+
}
|
|
62
|
+
return existing;
|
|
63
|
+
}
|
|
64
|
+
function createContext(defaultValue, name) {
|
|
65
|
+
const context = createReactiveContext(defaultValue, name);
|
|
66
|
+
const Provider = (props) => {
|
|
67
|
+
if (props.debug === true) {
|
|
68
|
+
}
|
|
69
|
+
return context.Provider({
|
|
70
|
+
value: props.value,
|
|
71
|
+
get children() {
|
|
72
|
+
return props.children;
|
|
73
|
+
},
|
|
74
|
+
debug: props.debug
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
if (typeof Symbol !== "undefined" && Symbol.for) {
|
|
78
|
+
Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
|
|
79
|
+
}
|
|
80
|
+
Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
|
|
81
|
+
return {
|
|
82
|
+
id: context.id,
|
|
83
|
+
Provider: asProvider(Provider),
|
|
84
|
+
defaultValue
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function useContext(context) {
|
|
88
|
+
const value = useReactiveContext(context);
|
|
89
|
+
return value !== void 0 ? value : context.defaultValue;
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
composeProviders,
|
|
93
|
+
createConsumer,
|
|
94
|
+
createContext,
|
|
95
|
+
createContextWithProvider,
|
|
96
|
+
createProvider,
|
|
97
|
+
useContext,
|
|
98
|
+
useProvide
|
|
99
|
+
};
|
|
@@ -1 +1,120 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/context/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
composeProviders: () => composeProviders,
|
|
24
|
+
createConsumer: () => createConsumer,
|
|
25
|
+
createContext: () => createContext,
|
|
26
|
+
createContextWithProvider: () => createContextWithProvider,
|
|
27
|
+
createProvider: () => createProvider,
|
|
28
|
+
useContext: () => useContext,
|
|
29
|
+
useProvide: () => useProvide
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(index_exports);
|
|
32
|
+
|
|
33
|
+
// src/lib/context/context.ts
|
|
34
|
+
var import_dom = require("@fluixi/dom");
|
|
35
|
+
var import_signal = require("@fluixi/reactive/signal");
|
|
36
|
+
var import_signal2 = require("@fluixi/reactive/signal");
|
|
37
|
+
var _warnedEagerProvider = false;
|
|
38
|
+
function warnEagerProvider() {
|
|
39
|
+
if (_warnedEagerProvider) return;
|
|
40
|
+
_warnedEagerProvider = true;
|
|
41
|
+
if (typeof process !== "undefined" && true) return;
|
|
42
|
+
console.warn(
|
|
43
|
+
"[fluixi] createProvider({ context, value, children }) reads `children` eagerly: the object literal materialises `children` BEFORE the context is stamped, so a routed <Outlet/> that has siblings inside the provider renders detached and its descendants see no context under SSR. Use the lazy form instead:\n createProvider(Context, value, props) // children stays a getter\n // or JSX: <Context.Provider value={...}>{props.children}</Context.Provider>"
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
function createProvider(a, value, childProps) {
|
|
47
|
+
const isLazyForm = !!a?.Provider;
|
|
48
|
+
const context = isLazyForm ? a : a.context;
|
|
49
|
+
const rawValue = isLazyForm ? value : a.value;
|
|
50
|
+
const debug = isLazyForm ? false : a.debug ?? false;
|
|
51
|
+
if (!isLazyForm) warnEagerProvider();
|
|
52
|
+
const resolvedValue = typeof rawValue === "function" ? rawValue() : rawValue;
|
|
53
|
+
const sourceProps = isLazyForm ? childProps : a;
|
|
54
|
+
return context.Provider({
|
|
55
|
+
value: resolvedValue,
|
|
56
|
+
get children() {
|
|
57
|
+
return sourceProps?.children;
|
|
58
|
+
},
|
|
59
|
+
debug
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function createContextWithProvider(defaultValue) {
|
|
63
|
+
const context = createContext(defaultValue);
|
|
64
|
+
const provider = (props) => {
|
|
65
|
+
return createProvider(context, props.value, props);
|
|
66
|
+
};
|
|
67
|
+
return [context, provider];
|
|
68
|
+
}
|
|
69
|
+
function composeProviders(contexts, children) {
|
|
70
|
+
if (contexts.length === 0) {
|
|
71
|
+
return (0, import_signal2.readChildren)(() => children);
|
|
72
|
+
}
|
|
73
|
+
const [context, value] = contexts[0];
|
|
74
|
+
const remaining = contexts.slice(1);
|
|
75
|
+
return createProvider(context, value, {
|
|
76
|
+
get children() {
|
|
77
|
+
return composeProviders(remaining, children);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function createConsumer(context) {
|
|
82
|
+
return (props) => {
|
|
83
|
+
const value = useContext(context);
|
|
84
|
+
return props.children(value);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function useProvide(context, factory) {
|
|
88
|
+
const existing = useContext(context);
|
|
89
|
+
if (existing === context.defaultValue) {
|
|
90
|
+
return factory();
|
|
91
|
+
}
|
|
92
|
+
return existing;
|
|
93
|
+
}
|
|
94
|
+
function createContext(defaultValue, name) {
|
|
95
|
+
const context = (0, import_signal.createContext)(defaultValue, name);
|
|
96
|
+
const Provider = (props) => {
|
|
97
|
+
if (props.debug === true) {
|
|
98
|
+
}
|
|
99
|
+
return context.Provider({
|
|
100
|
+
value: props.value,
|
|
101
|
+
get children() {
|
|
102
|
+
return props.children;
|
|
103
|
+
},
|
|
104
|
+
debug: props.debug
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
if (typeof Symbol !== "undefined" && Symbol.for) {
|
|
108
|
+
Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
|
|
109
|
+
}
|
|
110
|
+
Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
|
|
111
|
+
return {
|
|
112
|
+
id: context.id,
|
|
113
|
+
Provider: (0, import_dom.asProvider)(Provider),
|
|
114
|
+
defaultValue
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function useContext(context) {
|
|
118
|
+
const value = (0, import_signal.useContext)(context);
|
|
119
|
+
return value !== void 0 ? value : context.defaultValue;
|
|
120
|
+
}
|
|
@@ -1 +1,99 @@
|
|
|
1
|
-
|
|
1
|
+
// src/lib/context/context.ts
|
|
2
|
+
import { asProvider } from "@fluixi/dom";
|
|
3
|
+
import { createContext as createReactiveContext, useContext as useReactiveContext } from "@fluixi/reactive/signal";
|
|
4
|
+
import {
|
|
5
|
+
readChildren
|
|
6
|
+
} from "@fluixi/reactive/signal";
|
|
7
|
+
var _warnedEagerProvider = false;
|
|
8
|
+
function warnEagerProvider() {
|
|
9
|
+
if (_warnedEagerProvider) return;
|
|
10
|
+
_warnedEagerProvider = true;
|
|
11
|
+
if (typeof process !== "undefined" && true) return;
|
|
12
|
+
console.warn(
|
|
13
|
+
"[fluixi] createProvider({ context, value, children }) reads `children` eagerly: the object literal materialises `children` BEFORE the context is stamped, so a routed <Outlet/> that has siblings inside the provider renders detached and its descendants see no context under SSR. Use the lazy form instead:\n createProvider(Context, value, props) // children stays a getter\n // or JSX: <Context.Provider value={...}>{props.children}</Context.Provider>"
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
function createProvider(a, value, childProps) {
|
|
17
|
+
const isLazyForm = !!a?.Provider;
|
|
18
|
+
const context = isLazyForm ? a : a.context;
|
|
19
|
+
const rawValue = isLazyForm ? value : a.value;
|
|
20
|
+
const debug = isLazyForm ? false : a.debug ?? false;
|
|
21
|
+
if (!isLazyForm) warnEagerProvider();
|
|
22
|
+
const resolvedValue = typeof rawValue === "function" ? rawValue() : rawValue;
|
|
23
|
+
const sourceProps = isLazyForm ? childProps : a;
|
|
24
|
+
return context.Provider({
|
|
25
|
+
value: resolvedValue,
|
|
26
|
+
get children() {
|
|
27
|
+
return sourceProps?.children;
|
|
28
|
+
},
|
|
29
|
+
debug
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function createContextWithProvider(defaultValue) {
|
|
33
|
+
const context = createContext(defaultValue);
|
|
34
|
+
const provider = (props) => {
|
|
35
|
+
return createProvider(context, props.value, props);
|
|
36
|
+
};
|
|
37
|
+
return [context, provider];
|
|
38
|
+
}
|
|
39
|
+
function composeProviders(contexts, children) {
|
|
40
|
+
if (contexts.length === 0) {
|
|
41
|
+
return readChildren(() => children);
|
|
42
|
+
}
|
|
43
|
+
const [context, value] = contexts[0];
|
|
44
|
+
const remaining = contexts.slice(1);
|
|
45
|
+
return createProvider(context, value, {
|
|
46
|
+
get children() {
|
|
47
|
+
return composeProviders(remaining, children);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function createConsumer(context) {
|
|
52
|
+
return (props) => {
|
|
53
|
+
const value = useContext(context);
|
|
54
|
+
return props.children(value);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function useProvide(context, factory) {
|
|
58
|
+
const existing = useContext(context);
|
|
59
|
+
if (existing === context.defaultValue) {
|
|
60
|
+
return factory();
|
|
61
|
+
}
|
|
62
|
+
return existing;
|
|
63
|
+
}
|
|
64
|
+
function createContext(defaultValue, name) {
|
|
65
|
+
const context = createReactiveContext(defaultValue, name);
|
|
66
|
+
const Provider = (props) => {
|
|
67
|
+
if (props.debug === true) {
|
|
68
|
+
}
|
|
69
|
+
return context.Provider({
|
|
70
|
+
value: props.value,
|
|
71
|
+
get children() {
|
|
72
|
+
return props.children;
|
|
73
|
+
},
|
|
74
|
+
debug: props.debug
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
if (typeof Symbol !== "undefined" && Symbol.for) {
|
|
78
|
+
Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
|
|
79
|
+
}
|
|
80
|
+
Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
|
|
81
|
+
return {
|
|
82
|
+
id: context.id,
|
|
83
|
+
Provider: asProvider(Provider),
|
|
84
|
+
defaultValue
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function useContext(context) {
|
|
88
|
+
const value = useReactiveContext(context);
|
|
89
|
+
return value !== void 0 ? value : context.defaultValue;
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
composeProviders,
|
|
93
|
+
createConsumer,
|
|
94
|
+
createContext,
|
|
95
|
+
createContextWithProvider,
|
|
96
|
+
createProvider,
|
|
97
|
+
useContext,
|
|
98
|
+
useProvide
|
|
99
|
+
};
|
|
@@ -1 +1,35 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/control-flow.ts
|
|
21
|
+
var control_flow_exports = {};
|
|
22
|
+
__export(control_flow_exports, {
|
|
23
|
+
ClientOnly: () => import_dom.ClientOnly,
|
|
24
|
+
Dynamic: () => import_dom.Dynamic,
|
|
25
|
+
ErrorBoundary: () => import_dom.ErrorBoundary,
|
|
26
|
+
For: () => import_dom.For,
|
|
27
|
+
Index: () => import_dom.Index,
|
|
28
|
+
Match: () => import_dom.Match,
|
|
29
|
+
NoSsr: () => import_dom.NoSsr,
|
|
30
|
+
Portal: () => import_dom.Portal,
|
|
31
|
+
Show: () => import_dom.Show,
|
|
32
|
+
Switch: () => import_dom.Switch
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(control_flow_exports);
|
|
35
|
+
var import_dom = require("@fluixi/dom");
|