@fluixi/core 1.0.0-alpha.53
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/LICENSE +21 -0
- package/README.md +611 -0
- package/dist/cdn/core.global.js +3 -0
- package/dist/cli/generate.cjs +1814 -0
- package/dist/cli/generate.d.ts +7 -0
- package/dist/cli/generate.d.ts.map +1 -0
- package/dist/cli/generate.js +2580 -0
- package/dist/cli/generate.mjs +1814 -0
- package/dist/cli/index.cjs +1814 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +2580 -0
- package/dist/cli/index.mjs +1814 -0
- package/dist/cli/run.cjs +2 -0
- package/dist/cli/run.d.ts +3 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +62 -0
- package/dist/cli/run.mjs +2 -0
- package/dist/fluixi.d.ts +5 -0
- package/dist/src/cdn/chunk-PFM5O5UE.mjs +1 -0
- package/dist/src/cdn/core.cjs +1 -0
- package/dist/src/cdn/core.d.ts +16 -0
- package/dist/src/cdn/core.d.ts.map +1 -0
- package/dist/src/cdn/core.js +15 -0
- package/dist/src/cdn/core.mjs +1 -0
- package/dist/src/cdn/router-next-WNWCFVC2.mjs +1 -0
- package/dist/src/index.cjs +1 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +26 -0
- package/dist/src/index.mjs +1 -0
- package/dist/src/jsx-dev-runtime.cjs +1 -0
- package/dist/src/jsx-dev-runtime.d.ts +2 -0
- package/dist/src/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/src/jsx-dev-runtime.js +1 -0
- package/dist/src/jsx-dev-runtime.mjs +1 -0
- package/dist/src/jsx-runtime.cjs +1 -0
- package/dist/src/jsx-runtime.d.ts +7 -0
- package/dist/src/jsx-runtime.d.ts.map +1 -0
- package/dist/src/jsx-runtime.js +17 -0
- package/dist/src/jsx-runtime.mjs +1 -0
- package/dist/src/lib/client/chunk-D3VTWVNJ.mjs +1 -0
- package/dist/src/lib/client/index.cjs +1 -0
- package/dist/src/lib/client/index.d.ts +54 -0
- package/dist/src/lib/client/index.d.ts.map +1 -0
- package/dist/src/lib/client/index.js +142 -0
- package/dist/src/lib/client/index.mjs +1 -0
- package/dist/src/lib/client/router-next-UYIYMRJL.mjs +1 -0
- package/dist/src/lib/context/context.cjs +1 -0
- package/dist/src/lib/context/context.d.ts +337 -0
- package/dist/src/lib/context/context.d.ts.map +1 -0
- package/dist/src/lib/context/context.js +462 -0
- package/dist/src/lib/context/context.mjs +1 -0
- package/dist/src/lib/context/index.cjs +1 -0
- package/dist/src/lib/context/index.d.ts +3 -0
- package/dist/src/lib/context/index.d.ts.map +1 -0
- package/dist/src/lib/context/index.js +5 -0
- package/dist/src/lib/context/index.mjs +1 -0
- package/dist/src/lib/control-flow.cjs +1 -0
- package/dist/src/lib/control-flow.d.ts +4 -0
- package/dist/src/lib/control-flow.d.ts.map +1 -0
- package/dist/src/lib/control-flow.js +1 -0
- package/dist/src/lib/control-flow.mjs +1 -0
- package/dist/src/lib/core.cjs +1 -0
- package/dist/src/lib/core.d.ts +90 -0
- package/dist/src/lib/core.d.ts.map +1 -0
- package/dist/src/lib/core.js +181 -0
- package/dist/src/lib/core.mjs +1 -0
- package/dist/src/lib/directives/lit.cjs +1 -0
- package/dist/src/lib/directives/lit.d.ts +2 -0
- package/dist/src/lib/directives/lit.d.ts.map +1 -0
- package/dist/src/lib/directives/lit.js +31 -0
- package/dist/src/lib/directives/lit.mjs +0 -0
- package/dist/src/lib/env/index.cjs +1 -0
- package/dist/src/lib/env/index.d.ts +39 -0
- package/dist/src/lib/env/index.d.ts.map +1 -0
- package/dist/src/lib/env/index.js +50 -0
- package/dist/src/lib/env/index.mjs +1 -0
- package/dist/src/lib/i18n/index.cjs +1 -0
- package/dist/src/lib/i18n/index.d.ts +79 -0
- package/dist/src/lib/i18n/index.d.ts.map +1 -0
- package/dist/src/lib/i18n/index.js +127 -0
- package/dist/src/lib/i18n/index.mjs +1 -0
- package/dist/src/lib/index.cjs +1 -0
- package/dist/src/lib/index.d.ts +83 -0
- package/dist/src/lib/index.d.ts.map +1 -0
- package/dist/src/lib/index.js +147 -0
- package/dist/src/lib/index.mjs +1 -0
- package/dist/src/lib/isomorphic.cjs +1 -0
- package/dist/src/lib/isomorphic.d.ts +69 -0
- package/dist/src/lib/isomorphic.d.ts.map +1 -0
- package/dist/src/lib/isomorphic.js +92 -0
- package/dist/src/lib/isomorphic.mjs +1 -0
- package/dist/src/lib/jsx-runtime/index.cjs +1 -0
- package/dist/src/lib/jsx-runtime/index.d.ts +13 -0
- package/dist/src/lib/jsx-runtime/index.d.ts.map +1 -0
- package/dist/src/lib/jsx-runtime/index.js +23 -0
- package/dist/src/lib/jsx-runtime/index.mjs +1 -0
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.cjs +1 -0
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.d.ts +2 -0
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.js +1 -0
- package/dist/src/lib/jsx-runtime/jsx-dev-runtime.mjs +1 -0
- package/dist/src/lib/plugins/fluixi-routes-plugin.cjs +13 -0
- package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts +21 -0
- package/dist/src/lib/plugins/fluixi-routes-plugin.d.ts.map +1 -0
- package/dist/src/lib/plugins/fluixi-routes-plugin.js +102 -0
- package/dist/src/lib/plugins/fluixi-routes-plugin.mjs +13 -0
- package/dist/src/lib/plugins/index.cjs +13 -0
- package/dist/src/lib/plugins/index.d.ts +4 -0
- package/dist/src/lib/plugins/index.d.ts.map +1 -0
- package/dist/src/lib/plugins/index.js +3 -0
- package/dist/src/lib/plugins/index.mjs +13 -0
- package/dist/src/lib/plugins/route-codegen.cjs +8 -0
- package/dist/src/lib/plugins/route-codegen.d.ts +13 -0
- package/dist/src/lib/plugins/route-codegen.d.ts.map +1 -0
- package/dist/src/lib/plugins/route-codegen.js +81 -0
- package/dist/src/lib/plugins/route-codegen.mjs +8 -0
- package/dist/src/lib/plugins/route-scanner.cjs +1 -0
- package/dist/src/lib/plugins/route-scanner.d.ts +39 -0
- package/dist/src/lib/plugins/route-scanner.d.ts.map +1 -0
- package/dist/src/lib/plugins/route-scanner.js +216 -0
- package/dist/src/lib/plugins/route-scanner.mjs +1 -0
- package/dist/src/lib/plugins/vite.cjs +1 -0
- package/dist/src/lib/plugins/vite.d.ts +3 -0
- package/dist/src/lib/plugins/vite.d.ts.map +1 -0
- package/dist/src/lib/plugins/vite.js +1 -0
- package/dist/src/lib/plugins/vite.mjs +1 -0
- package/dist/src/lib/render/component.cjs +1 -0
- package/dist/src/lib/render/component.d.ts +328 -0
- package/dist/src/lib/render/component.d.ts.map +1 -0
- package/dist/src/lib/render/component.js +520 -0
- package/dist/src/lib/render/component.mjs +1 -0
- package/dist/src/lib/render/index.cjs +1 -0
- package/dist/src/lib/render/index.d.ts +113 -0
- package/dist/src/lib/render/index.d.ts.map +1 -0
- package/dist/src/lib/render/index.js +201 -0
- package/dist/src/lib/render/index.mjs +1 -0
- package/dist/src/lib/render/lazy.cjs +1 -0
- package/dist/src/lib/render/lazy.d.ts +28 -0
- package/dist/src/lib/render/lazy.d.ts.map +1 -0
- package/dist/src/lib/render/lazy.js +62 -0
- package/dist/src/lib/render/lazy.mjs +1 -0
- package/dist/src/lib/render/suspense.cjs +1 -0
- package/dist/src/lib/render/suspense.d.ts +25 -0
- package/dist/src/lib/render/suspense.d.ts.map +1 -0
- package/dist/src/lib/render/suspense.js +139 -0
- package/dist/src/lib/render/suspense.mjs +1 -0
- package/dist/src/lib/router-next/data.cjs +1 -0
- package/dist/src/lib/router-next/data.d.ts +101 -0
- package/dist/src/lib/router-next/data.d.ts.map +1 -0
- package/dist/src/lib/router-next/data.js +179 -0
- package/dist/src/lib/router-next/data.mjs +1 -0
- package/dist/src/lib/router-next/index.cjs +1 -0
- package/dist/src/lib/router-next/index.d.ts +156 -0
- package/dist/src/lib/router-next/index.d.ts.map +1 -0
- package/dist/src/lib/router-next/index.js +464 -0
- package/dist/src/lib/router-next/index.mjs +1 -0
- package/dist/src/lib/server/hydration.cjs +1 -0
- package/dist/src/lib/server/hydration.d.ts +238 -0
- package/dist/src/lib/server/hydration.d.ts.map +1 -0
- package/dist/src/lib/server/hydration.js +384 -0
- package/dist/src/lib/server/hydration.mjs +1 -0
- package/dist/src/lib/server/index.cjs +16 -0
- package/dist/src/lib/server/index.d.ts +91 -0
- package/dist/src/lib/server/index.d.ts.map +1 -0
- package/dist/src/lib/server/index.js +141 -0
- package/dist/src/lib/server/index.mjs +16 -0
- package/dist/src/lib/server/reactive.cjs +1 -0
- package/dist/src/lib/server/reactive.d.ts +298 -0
- package/dist/src/lib/server/reactive.d.ts.map +1 -0
- package/dist/src/lib/server/reactive.js +472 -0
- package/dist/src/lib/server/reactive.mjs +1 -0
- package/dist/src/lib/theme/index.cjs +1 -0
- package/dist/src/lib/theme/index.d.ts +51 -0
- package/dist/src/lib/theme/index.d.ts.map +1 -0
- package/dist/src/lib/theme/index.js +79 -0
- package/dist/src/lib/theme/index.mjs +1 -0
- package/dist/src/lib/utils/index.cjs +1 -0
- package/dist/src/lib/utils/index.d.ts +379 -0
- package/dist/src/lib/utils/index.d.ts.map +1 -0
- package/dist/src/lib/utils/index.js +527 -0
- package/dist/src/lib/utils/index.mjs +1 -0
- package/dist/src/rx.cjs +1 -0
- package/dist/src/rx.d.ts +2 -0
- package/dist/src/rx.d.ts.map +1 -0
- package/dist/src/rx.js +101 -0
- package/dist/src/rx.mjs +0 -0
- package/dist/src/server.cjs +16 -0
- package/dist/src/server.d.ts +64 -0
- package/dist/src/server.d.ts.map +1 -0
- package/dist/src/server.js +63 -0
- package/dist/src/server.mjs +16 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +128 -0
- package/src/index.ts +31 -0
- package/types/fluixi.d.ts +5 -0
- package/types/vinxi.d.ts +50 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Client-Side Rendering Entry Point for Fluixi
|
|
3
|
+
* @module @fluixi/core/client
|
|
4
|
+
*
|
|
5
|
+
* Implements client-side mounting and hydration logic using @fluixi/dom runtime.
|
|
6
|
+
* Supports both JSX and Lit HTML.
|
|
7
|
+
*/
|
|
8
|
+
// import {
|
|
9
|
+
// cleanupHydration,
|
|
10
|
+
// deserializeHydrationData,
|
|
11
|
+
// } from '../server/hydration.js';
|
|
12
|
+
import { render as domRender, hydrate as domHydrate, } from '@fluixi/dom';
|
|
13
|
+
import { deserializeHydrationData, setHydrating, cleanupHydration, } from '../server/hydration.js';
|
|
14
|
+
import { render } from '../render/index.js';
|
|
15
|
+
import { ensureIntegration } from '../render/component.js';
|
|
16
|
+
import { createHead, setActiveHead, mountHead, stripHeadMarker } from '@fluixi/head';
|
|
17
|
+
ensureIntegration('client index');
|
|
18
|
+
// Register Lit support in @fluixi/dom
|
|
19
|
+
// This allows JSX/DOM engine to render Lit TemplateResults
|
|
20
|
+
// registerLitRender(litRenderFn);
|
|
21
|
+
// Connect the reactive system (signals, effects, batch) to the DOM runtime.
|
|
22
|
+
// Without this, createRenderEffect in @fluixi/dom is a one-shot call that never
|
|
23
|
+
// re-runs when signals change — breaking all JSX reactive updates.
|
|
24
|
+
// ensureIntegration();
|
|
25
|
+
/**
|
|
26
|
+
* Mount application to DOM (Client-side Rendering)
|
|
27
|
+
*
|
|
28
|
+
* @param App Root component function
|
|
29
|
+
* @param container DOM element to mount into
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { mount } from '@fluixi/core/client';
|
|
34
|
+
* import App from './App';
|
|
35
|
+
*
|
|
36
|
+
* mount(() => App(), document.getElementById('root'));
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function mount(App, container) {
|
|
40
|
+
if (!container) {
|
|
41
|
+
throw new Error('Container element not found for mount()');
|
|
42
|
+
}
|
|
43
|
+
// Use @fluixi/dom render which handles reactivity and supports Lit via registration
|
|
44
|
+
domRender(() => App(), container);
|
|
45
|
+
}
|
|
46
|
+
export { hydrate } from '@fluixi/dom';
|
|
47
|
+
/**
|
|
48
|
+
* Standard entry point for client-side rendering or hydration.
|
|
49
|
+
*
|
|
50
|
+
* Auto-detects whether to hydrate (if server-rendered HTML is present)
|
|
51
|
+
* or do a full client render.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* // entry-client.ts
|
|
56
|
+
* import { startClient } from '@fluixi/core/client';
|
|
57
|
+
* import App from './app';
|
|
58
|
+
*
|
|
59
|
+
* startClient(App);
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export async function startClient(App, options = {}) {
|
|
63
|
+
const container = typeof options.root === 'string'
|
|
64
|
+
? document.querySelector(options.root)
|
|
65
|
+
: options.root ?? document.querySelector('#app');
|
|
66
|
+
if (!container) {
|
|
67
|
+
throw new Error(`[Fluixi] Mount container not found: ${options.root ?? '#app'}`);
|
|
68
|
+
}
|
|
69
|
+
// Hydrate when explicitly requested (`{ hydrate: true }`), when the server emits the
|
|
70
|
+
// `__FLUIXI_HYDRATION__` marker, or — with a route tree in hand — when the mount root already
|
|
71
|
+
// holds server-rendered content. A non-empty root means SSR/SSG ran, so reuse that DOM instead
|
|
72
|
+
// of clearing and re-rendering (which flashes). Auto-hydration is gated on `routes` because
|
|
73
|
+
// hydrating an app with async lazy file-routes is only safe once those chunks are preloaded
|
|
74
|
+
// (below) — without the route tree we can't preload, so we fall back to the render() path. A
|
|
75
|
+
// client-only app mounts into an empty `<div id="root">` (firstElementChild null) → client render.
|
|
76
|
+
const hasServerDom = !!document.getElementById('__FLUIXI_HYDRATION__') ||
|
|
77
|
+
(!!options.routes && container.firstElementChild != null);
|
|
78
|
+
const shouldHydrate = options.hydrate ?? hasServerDom;
|
|
79
|
+
// Active head registry for this document — seo()/useHead() during the app render register here;
|
|
80
|
+
// mountHead reconciles it into <head> after mount (reusing server tags by key) and keeps it live.
|
|
81
|
+
const head = createHead();
|
|
82
|
+
setActiveHead(head);
|
|
83
|
+
// Drop a stray `<!--fh:…-->` head-transport comment if the server left one in the mount root
|
|
84
|
+
// (streaming / custom servers that don't lift it into <head>). It would otherwise be the cursor's
|
|
85
|
+
// first node and strand hydration — rebuilding the whole tree as a duplicate. Harmless no-op when
|
|
86
|
+
// the server already extracted it (the supported adapter/prerender/dev paths do).
|
|
87
|
+
stripHeadMarker(container);
|
|
88
|
+
if (shouldHydrate) {
|
|
89
|
+
// Preload the lazy chunk(s) for the current route so they resolve synchronously during the
|
|
90
|
+
// hydration render — the lazy boundary then adopts the server DOM in place instead of
|
|
91
|
+
// resolving a tick later and rebuilding a duplicate. Dynamic import keeps the router out of
|
|
92
|
+
// client-only bundles that never pass `routes`.
|
|
93
|
+
if (options.routes && options.routes.length) {
|
|
94
|
+
const { preloadRoutes } = await import('../router-next/index.js');
|
|
95
|
+
await preloadRoutes(options.routes, window.location.pathname);
|
|
96
|
+
}
|
|
97
|
+
deserializeHydrationData();
|
|
98
|
+
setHydrating(true);
|
|
99
|
+
domHydrate(() => App(), container);
|
|
100
|
+
// Handlers are now wired (delegated $$listeners attach during the hydration
|
|
101
|
+
// render) — replay any events the user fired before hydration.
|
|
102
|
+
replayEvents();
|
|
103
|
+
setTimeout(() => {
|
|
104
|
+
setHydrating(false);
|
|
105
|
+
cleanupHydration();
|
|
106
|
+
}, 100);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
render(() => App(), container);
|
|
110
|
+
}
|
|
111
|
+
mountHead(head);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Replay events captured before hydration by the server's eventCaptureScript
|
|
115
|
+
* (window.__FX_REPLAY__). Hydration REUSES the server DOM, so each recorded target
|
|
116
|
+
* is still live — re-dispatch a synthetic event on it so the app's delegated
|
|
117
|
+
* handlers fire. Discrete events only (click/input/change/submit/keydown). No-op
|
|
118
|
+
* when the capture script wasn't emitted (no queue).
|
|
119
|
+
*/
|
|
120
|
+
function replayEvents() {
|
|
121
|
+
if (typeof window === 'undefined')
|
|
122
|
+
return;
|
|
123
|
+
const w = window;
|
|
124
|
+
if (typeof w.__FX_REPLAY_STOP__ === 'function')
|
|
125
|
+
w.__FX_REPLAY_STOP__();
|
|
126
|
+
const queue = w.__FX_REPLAY__;
|
|
127
|
+
w.__FX_REPLAY__ = undefined;
|
|
128
|
+
w.__FX_REPLAY_STOP__ = undefined;
|
|
129
|
+
if (!Array.isArray(queue) || queue.length === 0)
|
|
130
|
+
return;
|
|
131
|
+
for (const rec of queue) {
|
|
132
|
+
const target = rec && rec.target;
|
|
133
|
+
// Skip targets dropped by a hydration mismatch (recreated, not reconnected).
|
|
134
|
+
if (!target || target.isConnected === false || typeof target.dispatchEvent !== 'function')
|
|
135
|
+
continue;
|
|
136
|
+
const type = rec.type;
|
|
137
|
+
const ev = type === 'click'
|
|
138
|
+
? new MouseEvent(type, { bubbles: true, cancelable: true })
|
|
139
|
+
: new Event(type, { bubbles: true, cancelable: true });
|
|
140
|
+
target.dispatchEvent(ev);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as f,e as y,f as m,h as c}from"./chunk-D3VTWVNJ.mjs";import{render as j,hydrate as I}from"@fluixi/dom";import{createRoot as H}from"@fluixi/reactive/signal";import{isDOMNode as Ce,delegateEvents as v,registerLitRender as M,insert as D}from"@fluixi/dom";import{createSignal as E,createMemo as C,createEffect as U,createRenderEffect as g,isSignal as l,useContext as L,createContext as x,createSuspenseBoundary as k,provideSuspense as b}from"@fluixi/reactive/signal";import{asSuspense as P,isComponent as R,createComponent as A,runWithoutHydration as F}from"@fluixi/dom";function h(t){return!!(t&&typeof t=="object"&&typeof t.then=="function"||t instanceof Promise)}var O=x();function d(t){return A(T,t)}function T(t){let e=k(),r=L(O),o=r?r.register(e.inFallback):void 0;function s(n){return n==null||typeof n=="boolean"?null:typeof n=="function"&&R(n)&&!l(n)?n():n}let i=F(()=>s(t.fallback??null)),a=b(e,()=>t.children);b(e,()=>{g(()=>{let n=a;if(Array.isArray(n))for(let u of n)typeof u=="function"&&l(u)&&u();else typeof n=="function"&&l(n)&&n()})});let[w,_]=E(void 0),p=h(a);return p&&(e.increment(),a.then(n=>{_(()=>n),e.decrement()},()=>e.decrement())),C(()=>(o?o.showFallback():e.inFallback())?i:p?w():a)}P(d);Object.defineProperty(d,"__suspense",{value:!0,enumerable:!0});typeof window<"u"&&import("lit").then(t=>M(t.render));var $=typeof window>"u";function S(t,e,r={}){if(c("render"),v(["click","input","change","submit"]),$)throw new Error("render() is for client-side only. Use renderToString() on server.");if(!e)throw new Error("Container element is required");let o;return H(s=>{o=s;let i=typeof t=="function"?t():t;e.textContent="",e.setAttribute("fluixi-js","v1"),D(e,()=>i)}),()=>{o&&(o(),o=void 0)}}import{createHead as N,setActiveHead as X,mountHead as Y,stripHeadMarker as z}from"@fluixi/head";import{hydrate as $e}from"@fluixi/dom";c("client index");function He(t,e){if(!e)throw new Error("Container element not found for mount()");j(()=>t(),e)}async function ve(t,e={}){let r=typeof e.root=="string"?document.querySelector(e.root):e.root??document.querySelector("#app");if(!r)throw new Error(`[Fluixi] Mount container not found: ${e.root??"#app"}`);let o=!!document.getElementById("__FLUIXI_HYDRATION__")||!!e.routes&&r.firstElementChild!=null,s=e.hydrate??o,i=N();if(X(i),z(r),s){if(e.routes&&e.routes.length){let{preloadRoutes:a}=await import("./router-next-UYIYMRJL.mjs");await a(e.routes,window.location.pathname)}y(),f(!0),I(()=>t(),r),q(),setTimeout(()=>{f(!1),m()},100)}else S(()=>t(),r);Y(i)}function q(){if(typeof window>"u")return;let t=window;typeof t.__FX_REPLAY_STOP__=="function"&&t.__FX_REPLAY_STOP__();let e=t.__FX_REPLAY__;if(t.__FX_REPLAY__=void 0,t.__FX_REPLAY_STOP__=void 0,!(!Array.isArray(e)||e.length===0))for(let r of e){let o=r&&r.target;if(!o||o.isConnected===!1||typeof o.dispatchEvent!="function")continue;let s=r.type,i=s==="click"?new MouseEvent(s,{bubbles:!0,cancelable:!0}):new Event(s,{bubbles:!0,cancelable:!0});o.dispatchEvent(i)}}export{$e as hydrate,He as mount,ve as startClient};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as w,c as O,d as L,g as D,h as k,i as B}from"./chunk-D3VTWVNJ.mjs";import{createSignal as P,createMemo as d,createResource as re,createEffect as A,getOwner as oe,onCleanup as b,untrack as R}from"@fluixi/reactive/signal";import{insert as x,createComponent as F,createNativeElement as g,setAttribute as u}from"@fluixi/dom";import{createContext as T,useContext as y}from"@fluixi/reactive/signal";import{get as ae}from"@fluixi/utils/object";import{deepEqual as se}from"@fluixi/utils/compare";import{createRouter as ie,createBrowserHistory as ce,matchRoutes as ue,matchPath as de}from"@fluixi/router";import{createMemoryHistory as tt,createBrowserHistory as nt,matchRoutes as rt,matchPath as ot}from"@fluixi/router";import{createResource as W,createSignal as N}from"@fluixi/reactive/signal";import{asProvider as I}from"@fluixi/dom";import{createContext as J,useContext as Te}from"@fluixi/reactive/signal";import{readChildren as Pe}from"@fluixi/reactive/signal";k("index");function M(e){let n=J(e),t=o=>(o.debug,n.Provider({value:o.value,get children(){return o.children},debug:o.debug}));return typeof Symbol<"u"&&Symbol.for&&(t.$$typeof=Symbol.for("react.provider")),t.$$typeof=Symbol.for("react.provider"),{id:n.id,Provider:I(t),defaultValue:e}}var m=new Map,p=new Map;function G(e,n){return async(...t)=>{let o=n+":"+JSON.stringify(t);if(w()||typeof window<"u"){let a=L(o);if(a!==void 0)return a}if(m.has(o))return m.get(o);if(p.has(o))return p.get(o);let r=Promise.resolve(e(...t)).then(a=>(m.set(o,a),p.delete(o),D()&&O(o,a),a),a=>{throw p.delete(o),a});return p.set(o,r),r}}var[ke,X]=N(0),Q=new Set;function Y(e){let n=typeof e=="string"?t=>t.startsWith(e):e;for(let t of m.keys())n(t)&&(m.delete(t),Q.add(t));X(t=>t+1)}function Z(e,n){let[t]=W(n||(()=>!0),e);return t}var C=new Map;function V(e){return C.has(e)||C.set(e,N(void 0)),C.get(e)}function E(e,n){let t=n||e.name||"action",o=async r=>{let[,a]=V(t),s=()=>a(void 0),i=()=>o(r);a({input:r,pending:!0,clear:s,retry:i});try{let c=await e(r);return a({input:r,result:c,pending:!1,clear:s,retry:i}),c}catch(c){throw a({input:r,error:c,pending:!1,clear:s,retry:i}),c}};return o.url=t,o.with=r=>E((...a)=>e(r,...a),n),o}function ee(e){let[n]=V(e.url);return n}function te(e){return e}var ne=M(),Me=ne.Provider;import{runWithOwner as ct}from"@fluixi/reactive/signal";var v=T(),K=T(),U=T(),H=T();function le(e,n,t){let o,r=e.route.data;if(typeof r=="function"){let h=!1;b(()=>{h=!0});let $=oe(),[z]=re(()=>r({params:t.params,location:t.location},$,()=>h));o=z}let a=()=>H.Provider({value:o,get children(){return U.Provider({value:e.params,get children(){return K.Provider({value:{depth:n,...t},get children(){return F(e.component,{})}})}})}});if(!o)return a();let s=o,i=()=>s.loading,[c,l]=P(R(()=>!i()));return A(()=>l(!i())),d(()=>c()?a():null)}function j(e){let n=e.depth+1,[t,o]=P(R(()=>e.matched()[n]?.component));return A(()=>{let r=e.matched()[n]?.component;o(()=>r)}),d(()=>{if(!t())return e.notFound?e.notFound():null;let a=R(()=>e.matched())[n];return le(a,n,{matched:e.matched,params:e.params,location:e.location})})}function fe(e){return e==null?ye():typeof e=="function"?F(e,{}):e}function ye(){let e=g("div");u(e,"class","fx-not-found"),u(e,"role","main"),u(e,"style","min-height:60vh;display:grid;place-content:center;gap:.25rem;text-align:center;font-family:system-ui,-apple-system,sans-serif");let n=g("h1");u(n,"style","margin:0;font-size:2.5rem;font-weight:700"),x(n,"404");let t=g("p");return u(t,"style","margin:0;opacity:.7"),x(t,"This page could not be found."),e.appendChild(n),e.appendChild(t),e}function je(e){let n=e.history??ce(),t=ie({routes:e.routes,base:e.base,history:n}),[o,r]=P(t.state()),a=t.subscribe(r);b(()=>{a(),t.destroy()});let s=d(()=>(o().match?.matched??[]).filter(h=>h.component)),i={router:t,location:d(()=>o().location),params:d(()=>o().match?.params??{})},c={depth:-1,matched:s,params:i.params,location:i.location,notFound:()=>fe(e.notFound)},l;return v.Provider({value:i,get children(){return l??=j(c)}})}function qe(){let e=y(K);return e?j(e):null}function _e(e){let n=y(v);if(!n||typeof window>"u")return null;let t=!1;return b(()=>t=!0),queueMicrotask(()=>{t||n.router.navigate(e.to,{replace:e.replace!==!1})}),null}var pe={router:{navigate:()=>{}},location:()=>({pathname:"",search:"",hash:"",query:{}}),params:()=>({})};function S(){let e=y(v);if(e)return e;if(typeof window>"u")return pe;throw new Error("[router-next] useRouter must be used within <Router>")}function q(){let e=S().params;return d(()=>e(),{},{equals:(n,t)=>JSON.stringify(n)===JSON.stringify(t)})}function $e(){return y(U)??{}}function ze(e){let n=q();return d(()=>n()[e])}function Be(e,n){let t=q();return d(()=>e(t()),void 0,n?{equals:n}:void 0)}function Ie(e){let n=_();return d(()=>de(typeof e=="function"?e():e,n.pathname))}function Je(){let e=_(),n=me();return[d(()=>e.query),(r,a)=>{let s=new URLSearchParams(e.search);for(let[c,l]of Object.entries(r))l===null?s.delete(c):s.set(c,l);let i=s.toString();n(e.pathname+(i?`?${i}`:""),a)}]}function We(e,n){let t=(o,r)=>se(o,r);return n!==void 0?d(()=>ae(e(),n),void 0,{equals:t}):d(e,void 0,{equals:t})}function _(){let{location:e}=S();return new Proxy({},{get:(n,t)=>e()[t],has:(n,t)=>t in e(),ownKeys:()=>Reflect.ownKeys(e()),getOwnPropertyDescriptor:(n,t)=>Object.getOwnPropertyDescriptor(e(),t)})}function me(){let{router:e}=S();return(n,t)=>e.navigate(n,t)}function Ge(){return y(H)??(()=>{})}var f=e=>typeof e=="function"?e():e;function ge(e){let n=y(v),t=typeof document>"u",o=()=>n?.router.navigate(f(e.href)??"",{replace:f(e.replace)}),r=g("a");if(u(r,"href",f(e.href)??""),e.slot&&u(r,"slot",f(e.slot)),typeof r.addEventListener=="function")r.addEventListener("click",s=>{s.metaKey||s.ctrlKey||s.shiftKey||s.altKey||(s.preventDefault(),o())});else{let s=f(e.className??e.class)??"";s&&u(r,"class",s)}typeof r.addEventListener=="function"&&A(()=>{let s=f(e.href)??"";r.setAttribute("href",s);let i=f(e.className??e.class)??"",c=f(e.activeClass)??"",l=f(e.active)??n?.location().pathname===s;r.className=[i,l?c:""].filter(Boolean).join(" ")});let a=e.children;return a!=null&&x(r,a),r}var Xe=ge;function Qe(e){let n=e.action,t=e.className??e.class,o=n.url??"",r=g("form");u(r,"method","post"),o&&u(r,"action",o),t&&u(r,"class",t);for(let[s,i]of Object.entries(e))s==="action"||s==="children"||s==="class"||s==="className"||i!=null&&typeof i!="function"&&u(r,s,String(i));typeof r.addEventListener=="function"&&r.addEventListener("submit",s=>{s.preventDefault();let i={};new FormData(r).forEach((c,l)=>{i[l]=c}),Promise.resolve(n(i)).catch(()=>{})});let a=e.children;return a!=null&&x(r,a),r}async function Ye(e,n){let t=ue(e,n);if(!t)return;let o=[];for(let r of t.matched){let a=r.component;a&&typeof a.preload=="function"&&o.push(a.preload())}await Promise.all(o)}export{Xe as A,Qe as Form,ge as Link,qe as Outlet,_e as Redirect,je as Router,E as action,G as cache,Z as createAsync,nt as createBrowserHistory,tt as createMemoryHistory,B as lazy,ot as matchPath,rt as matchRoutes,Ye as preloadRoutes,Y as revalidate,ct as runWithOwner,We as select,te as useAction,$e as useLevelParams,_ as useLocation,Ie as useMatch,me as useNavigate,ze as useParam,Be as useParamSelector,q as useParams,Ge as useRouteData,S as useRouter,Je as useSearchParams,ee as useSubmission};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var u=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var E=(e,n)=>{for(var t in n)u(e,t,{get:n[t],enumerable:!0})},S=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of b(n))!P.call(e,i)&&i!==t&&u(e,i,{get:()=>n[i],enumerable:!(o=g(n,i))||o.enumerable});return e};var O=e=>S(u({},"__esModule",{value:!0}),e);var V={};E(V,{composeProviders:()=>y,createConsumer:()=>k,createContext:()=>T,createContextWithProvider:()=>A,createProvider:()=>d,useContext:()=>l,useProvide:()=>U});module.exports=O(V);var v=require("@fluixi/dom"),a=require("@fluixi/reactive/signal"),x=require("@fluixi/reactive/signal");var c=require("@fluixi/dom"),r=require("@fluixi/reactive/signal");function f(e){(0,c.registerCreateComponent)(w)}function w(e,n){return R(e,n)}function R(e,n){let t=typeof e=="function"?(0,r.untrack)(()=>e(n)):e;if(t!=null&&(typeof t=="function"||typeof t=="object")&&!(0,r.isSignal)(t)){try{t.$name=e.name}catch{}return(0,c.asComponent)(t)}return t}f("index");var p=!1;function L(){p||(p=!0,!(typeof process<"u")&&console.warn("[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>"))}function d(e,n,t){let o=!!e?.Provider,i=o?e:e.context,s=o?n:e.value,C=o?!1:e.debug??!1;o||L();let m=typeof s=="function"?s():s,h=o?t:e;return i.Provider({value:m,get children(){return h?.children},debug:C})}function A(e){let n=T(e);return[n,o=>d(n,o.value,o)]}function y(e,n){if(e.length===0)return(0,x.readChildren)(()=>n);let[t,o]=e[0],i=e.slice(1);return d(t,o,{get children(){return y(i,n)}})}function k(e){return n=>{let t=l(e);return n.children(t)}}function U(e,n){let t=l(e);return t===e.defaultValue?n():t}function T(e){let n=(0,a.createContext)(e),t=o=>(o.debug,n.Provider({value:o.value,get children(){return o.children},debug:o.debug}));return typeof Symbol<"u"&&Symbol.for&&(t.$$typeof=Symbol.for("react.provider")),t.$$typeof=Symbol.for("react.provider"),{id:n.id,Provider:(0,v.asProvider)(t),defaultValue:e}}function l(e){let n=(0,a.useContext)(e);return n!==void 0?n:e.defaultValue}
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import { type Component } from '@fluixi/dom';
|
|
2
|
+
import { Accessor, Context } from '@fluixi/reactive/signal';
|
|
3
|
+
type C = Component | Component[];
|
|
4
|
+
interface Children {
|
|
5
|
+
(): C;
|
|
6
|
+
(...args: any[]): C;
|
|
7
|
+
}
|
|
8
|
+
type PickChildren<T> = T extends Record<any, any> ? 'children' extends keyof T ? T['children'] : never : never;
|
|
9
|
+
export interface ContextProvider<T, S> {
|
|
10
|
+
/**
|
|
11
|
+
* Context to provide
|
|
12
|
+
*/
|
|
13
|
+
context: Context<T>;
|
|
14
|
+
/**
|
|
15
|
+
* Value to provide
|
|
16
|
+
*/
|
|
17
|
+
value: T | Accessor<T>;
|
|
18
|
+
/**
|
|
19
|
+
* Children components that can access this context
|
|
20
|
+
*/
|
|
21
|
+
debug?: boolean;
|
|
22
|
+
children?: (S extends Record<any, any> ? PickChildren<S> : never) | S;
|
|
23
|
+
}
|
|
24
|
+
export interface ProviderProps<Child> {
|
|
25
|
+
/**
|
|
26
|
+
* Children components that can access this context
|
|
27
|
+
*/
|
|
28
|
+
children?: Child extends Record<any, any> ? PickChildren<Child> : never;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Lazy-safe form — pass the component's `props` so `children` is read through a
|
|
32
|
+
* getter (inside the stamped scope), never materialised early. This is the
|
|
33
|
+
* recommended way to wrap an <Outlet/>.
|
|
34
|
+
*
|
|
35
|
+
* function ThemeProvider(props) {
|
|
36
|
+
* return createProvider(ThemeContext, theme, props);
|
|
37
|
+
* }
|
|
38
|
+
*/
|
|
39
|
+
export declare function createProvider<T>(context: Context<T>, value: T | Accessor<T>, props: {
|
|
40
|
+
children?: any;
|
|
41
|
+
}): Component<T>;
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated Eager form — `{ context, value, children }` reads `children` before
|
|
44
|
+
* the context is stamped (see warnEagerProvider). Use `createProvider(context,
|
|
45
|
+
* value, props)` or `<Context.Provider>` instead.
|
|
46
|
+
*/
|
|
47
|
+
export declare function createProvider<T, S = Children>(props: ContextProvider<T, S>): Component<T>;
|
|
48
|
+
/**
|
|
49
|
+
* Creates a context with a provider component
|
|
50
|
+
*
|
|
51
|
+
* Returns both the context and a convenience component that combines
|
|
52
|
+
* context creation with the provider.
|
|
53
|
+
*
|
|
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
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* import { createContextWithProvider } from '@fluixi/core/context';
|
|
61
|
+
* import { createSignal } from '@fluixi/reactive';
|
|
62
|
+
* import { html } from 'lit';
|
|
63
|
+
*
|
|
64
|
+
* const [ThemeContext, ThemeProvider] = createContextWithProvider({
|
|
65
|
+
* primaryColor: '#007bff'
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* class App extends FluixiElement {
|
|
69
|
+
* private [theme] = createSignal({ primaryColor: '#28a745' });
|
|
70
|
+
*
|
|
71
|
+
* view() {
|
|
72
|
+
* return html`
|
|
73
|
+
* ${ThemeProvider({
|
|
74
|
+
* value: this.theme(),
|
|
75
|
+
* children: html`<div><themed-button></themed-button></div>`
|
|
76
|
+
* })}
|
|
77
|
+
* `;
|
|
78
|
+
* }
|
|
79
|
+
* }
|
|
80
|
+
*
|
|
81
|
+
* class ThemedButton extends FluixiElement {
|
|
82
|
+
* view() {
|
|
83
|
+
* const theme = useContext(ThemeContext);
|
|
84
|
+
* return html`<button style="color: ${theme.primaryColor}">Click</button>`;
|
|
85
|
+
* }
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function createContextWithProvider<T, U>(defaultValue: T): [Context<T>, (props: Omit<ContextProvider<T, U>, 'context'>) => Component<T>];
|
|
90
|
+
/**
|
|
91
|
+
* Creates multiple context providers in a nested structure
|
|
92
|
+
*
|
|
93
|
+
* Utility function to avoid deeply nested Provider components.
|
|
94
|
+
*
|
|
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
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* import { composeProviders, createContext } from '@fluixi/core/context';
|
|
102
|
+
* import { createSignal } from '@fluixi/reactive';
|
|
103
|
+
* import { html } from 'lit';
|
|
104
|
+
*
|
|
105
|
+
* const ThemeContext = createContext({ dark: false });
|
|
106
|
+
* const UserContext = createContext<User | null>(null);
|
|
107
|
+
* const LocaleContext = createContext('en');
|
|
108
|
+
*
|
|
109
|
+
* class App extends FluixiElement {
|
|
110
|
+
* private [theme] = createSignal({ dark: true });
|
|
111
|
+
* private [user] = createSignal<User | null>({ id: 1, name: 'Alice' });
|
|
112
|
+
* private [locale] = createSignal('fr');
|
|
113
|
+
*
|
|
114
|
+
* view() {
|
|
115
|
+
* return composeProviders(
|
|
116
|
+
* [
|
|
117
|
+
* [ThemeContext, this.theme()],
|
|
118
|
+
* [UserContext, this.user()],
|
|
119
|
+
* [LocaleContext, this.locale()]
|
|
120
|
+
* ],
|
|
121
|
+
* html`<app-dashboard></app-dashboard>`
|
|
122
|
+
* );
|
|
123
|
+
* }
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare function composeProviders(contexts: Array<[Context<any>, any]>, children: Children): Component;
|
|
128
|
+
/**
|
|
129
|
+
* Creates a context consumer component
|
|
130
|
+
*
|
|
131
|
+
* Alternative to useContext hook, useful for rendering props patterns.
|
|
132
|
+
*
|
|
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
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* import { createContext, createConsumer } from '@fluixi/core/context';
|
|
140
|
+
* import { html } from 'lit';
|
|
141
|
+
*
|
|
142
|
+
* const ThemeContext = createContext({ primaryColor: '#007bff' });
|
|
143
|
+
* const ThemeConsumer = createConsumer(ThemeContext);
|
|
144
|
+
*
|
|
145
|
+
* class MyComponent extends FluixiElement {
|
|
146
|
+
* view() {
|
|
147
|
+
* return html`
|
|
148
|
+
* ${ThemeConsumer({
|
|
149
|
+
* children: (theme) => html`
|
|
150
|
+
* <div style="color: ${theme.primaryColor}">
|
|
151
|
+
* Themed content
|
|
152
|
+
* </div>
|
|
153
|
+
* `
|
|
154
|
+
* })}
|
|
155
|
+
* `;
|
|
156
|
+
* }
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare function createConsumer<T>(context: Context<T>): (props: {
|
|
161
|
+
children: (value: T) => Component;
|
|
162
|
+
}) => Component;
|
|
163
|
+
/**
|
|
164
|
+
* Hook to provide and consume a context in one component
|
|
165
|
+
*
|
|
166
|
+
* Useful for creating context-based stores or services.
|
|
167
|
+
*
|
|
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
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* import { createContext, useProvide, Provider } from '@fluixi/core/context';
|
|
176
|
+
* import { createSignal } from '@fluixi/reactive';
|
|
177
|
+
* import { html } from 'lit';
|
|
178
|
+
*
|
|
179
|
+
* interface Counter {
|
|
180
|
+
* count: number;
|
|
181
|
+
* increment: () => void;
|
|
182
|
+
* }
|
|
183
|
+
*
|
|
184
|
+
* const CounterContext = createContext<Counter>({
|
|
185
|
+
* count: 0,
|
|
186
|
+
* increment: () => {}
|
|
187
|
+
* });
|
|
188
|
+
*
|
|
189
|
+
* class CounterProvider extends FluixiElement {
|
|
190
|
+
* view() {
|
|
191
|
+
* const counter = useProvide(CounterContext, () => {
|
|
192
|
+
* const [count, setCount] = createSignal(0);
|
|
193
|
+
* return {
|
|
194
|
+
* count: count(),
|
|
195
|
+
* increment: () => setCount(count() + 1)
|
|
196
|
+
* };
|
|
197
|
+
* });
|
|
198
|
+
*
|
|
199
|
+
* return html`
|
|
200
|
+
* ${Provider({
|
|
201
|
+
* context: CounterContext,
|
|
202
|
+
* value: counter,
|
|
203
|
+
* children: html`<slot></slot>`
|
|
204
|
+
* })}
|
|
205
|
+
* `;
|
|
206
|
+
* }
|
|
207
|
+
* }
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
export declare function useProvide<T>(context: Context<T>, factory: () => T): T;
|
|
211
|
+
/**
|
|
212
|
+
* Creates a scoped context that only exists within a specific component tree
|
|
213
|
+
*
|
|
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
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* import { createContext } from '@fluixi/core/context';
|
|
221
|
+
*
|
|
222
|
+
* // This context won't leak to parent or sibling components
|
|
223
|
+
* const LocalContext = createContext({ data: 'local' });
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
/**
|
|
227
|
+
* Create a context for sharing state across component tree
|
|
228
|
+
*
|
|
229
|
+
* Section 9: Context is lookup-based, works on server and client
|
|
230
|
+
* Supports nested contexts and complex values
|
|
231
|
+
*
|
|
232
|
+
* @template T - Context value type
|
|
233
|
+
* @param {T} defaultValue - Default value
|
|
234
|
+
* @returns {Context<T>} Context object with Provider
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```typescript
|
|
238
|
+
* // Simple context
|
|
239
|
+
* const ThemeContext = createContext('light');
|
|
240
|
+
*
|
|
241
|
+
* // Complex context with object
|
|
242
|
+
* const AppContext = createContext({
|
|
243
|
+
* theme: 'light',
|
|
244
|
+
* toggleTheme: () => {}
|
|
245
|
+
* });
|
|
246
|
+
*
|
|
247
|
+
* // Usage in JSX
|
|
248
|
+
* <ThemeContext.Provider value="dark">
|
|
249
|
+
* <Child />
|
|
250
|
+
* </ThemeContext.Provider>
|
|
251
|
+
*
|
|
252
|
+
* // Usage in Lit-html
|
|
253
|
+
* html`
|
|
254
|
+
* <${ThemeContext.Provider} value=${{ theme: 'dark', toggleTheme }}>
|
|
255
|
+
* <${Child} />
|
|
256
|
+
* </${ThemeContext.Provider}>
|
|
257
|
+
* `
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
/**
|
|
261
|
+
* Creates a scoped context that only exists within a specific component tree
|
|
262
|
+
*
|
|
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
|
+
* @example
|
|
268
|
+
* ```typescript
|
|
269
|
+
* import { createContext } from '@fluixi/core';
|
|
270
|
+
*
|
|
271
|
+
* // This context won't leak to parent or sibling components
|
|
272
|
+
* const LocalContext = createContext({ data: 'local' });
|
|
273
|
+
* ```
|
|
274
|
+
* @example
|
|
275
|
+
* ```typescript
|
|
276
|
+
* // Simple context
|
|
277
|
+
* const ThemeContext = createContext('light');
|
|
278
|
+
*
|
|
279
|
+
* // Complex context with object
|
|
280
|
+
* const AppContext = createContext({
|
|
281
|
+
* theme: 'light',
|
|
282
|
+
* toggleTheme: () => {}
|
|
283
|
+
* });
|
|
284
|
+
*
|
|
285
|
+
* // Usage in JSX
|
|
286
|
+
* <ThemeContext.Provider value="dark">
|
|
287
|
+
* <Child />
|
|
288
|
+
* </ThemeContext.Provider>
|
|
289
|
+
*
|
|
290
|
+
* // Usage in Lit-html
|
|
291
|
+
* html`
|
|
292
|
+
* <${ThemeContext.Provider} value=${{ theme: 'dark', toggleTheme }}>
|
|
293
|
+
* <${Child} />
|
|
294
|
+
* </${ThemeContext.Provider}>
|
|
295
|
+
* `
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
298
|
+
export declare function createContext<T>(defaultValue?: T): {
|
|
299
|
+
id: symbol;
|
|
300
|
+
Provider: (props: {
|
|
301
|
+
value: T;
|
|
302
|
+
children?: any;
|
|
303
|
+
debug?: boolean;
|
|
304
|
+
}) => any;
|
|
305
|
+
defaultValue: T;
|
|
306
|
+
};
|
|
307
|
+
/**
|
|
308
|
+
* Use context value from nearest Provider
|
|
309
|
+
*
|
|
310
|
+
* Section 9: Lookup-based, no subscriptions on server
|
|
311
|
+
*
|
|
312
|
+
* @template T - Context value type
|
|
313
|
+
* @param {Context} context - Context to use
|
|
314
|
+
* @returns {T} Context value
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* ```typescript
|
|
318
|
+
* const Child = () => {
|
|
319
|
+
* const theme = useContext(ThemeContext);
|
|
320
|
+
* const { theme: currentTheme, toggleTheme } = useContext(AppContext);
|
|
321
|
+
*
|
|
322
|
+
* return html`
|
|
323
|
+
* <div>
|
|
324
|
+
* <p>Theme: ${currentTheme}</p>
|
|
325
|
+
* <button @click=${toggleTheme}>Toggle</button>
|
|
326
|
+
* </div>
|
|
327
|
+
* `;
|
|
328
|
+
* };
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
export declare function useContext<T>(context: {
|
|
332
|
+
id: symbol;
|
|
333
|
+
defaultValue: T;
|
|
334
|
+
[key: string]: any;
|
|
335
|
+
}): T;
|
|
336
|
+
export type { Context };
|
|
337
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/lib/context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