@fluixi/core 1.0.0-alpha.83 → 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 +17 -6
- package/dist/src/lib/client/index.d.ts.map +1 -1
- package/dist/src/lib/client/index.js +26 -19
- 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 +19 -37
- package/dist/src/lib/context/context.d.ts.map +1 -1
- package/dist/src/lib/context/context.js +8 -45
- 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 +5 -5
- package/dist/src/lib/env/index.js +5 -5
- 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 +23 -55
- package/dist/src/lib/render/component.mjs +214 -1
- package/dist/src/lib/render/deferred.cjs +175 -1
- package/dist/src/lib/render/deferred.js +5 -5
- 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 +8 -22
- 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 +26 -5
- 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 +46 -6
- 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 +0 -12
- 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 +85 -33
- 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-55BT3H6E.mjs +0 -1
- package/dist/src/cdn/router-5JJZBK4E.mjs +0 -1
- package/dist/src/lib/client/chunk-SM4WHBOP.mjs +0 -1
- package/dist/src/lib/client/router-IBD4WPQT.mjs +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview Client-Side Rendering for Fluixi
|
|
3
2
|
* @module @fluixi/core/render
|
|
4
3
|
*
|
|
5
4
|
* Client-side rendering:
|
|
@@ -13,22 +12,17 @@ import { createRoot } from '@fluixi/reactive/signal';
|
|
|
13
12
|
import { stampVersions, warnOnVersionSkew } from './versions.js';
|
|
14
13
|
import { isDOMNode, delegateEvents, insert, } from '@fluixi/dom';
|
|
15
14
|
// ============================================================================
|
|
16
|
-
//
|
|
15
|
+
// RENDERING (CLIENT)
|
|
17
16
|
// ============================================================================
|
|
18
17
|
/**
|
|
19
18
|
* Render a component into a DOM element
|
|
20
19
|
*
|
|
21
|
-
*
|
|
20
|
+
* On the client:
|
|
22
21
|
* - Real DOM (no Virtual DOM)
|
|
23
22
|
* - Fine-grained mutation (no reconciliation)
|
|
24
23
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* @param {() => any} code - Component or function to render
|
|
29
|
-
* @param {HTMLElement} container - Target DOM element
|
|
30
|
-
* @param {RenderOptions} options - Render options
|
|
31
|
-
* @returns {() => void} Dispose function
|
|
24
|
+
* Component executes once during render
|
|
25
|
+
* Creates reactive owner (root)
|
|
32
26
|
*
|
|
33
27
|
* @example
|
|
34
28
|
* ```typescript
|
|
@@ -55,11 +49,11 @@ export function render(code, container, options = {}) {
|
|
|
55
49
|
// domRender(code, container)
|
|
56
50
|
createRoot((dispose) => {
|
|
57
51
|
disposer = dispose;
|
|
58
|
-
//
|
|
52
|
+
// Execute code function once. Providers run here with Owner = root
|
|
59
53
|
// so "also stamp" in createProvider sets context on root.contexts, making
|
|
60
54
|
// it reachable from every render effect created by insert() below.
|
|
61
55
|
const result = typeof code === 'function' ? code() : code;
|
|
62
|
-
//
|
|
56
|
+
// Insert into real DOM using the same root as code() so that
|
|
63
57
|
// render effects share the Owner chain with Provider context nodes.
|
|
64
58
|
// Using domRender() would create a second createRoot, severing the chain.
|
|
65
59
|
container.textContent = '';
|
|
@@ -68,8 +62,8 @@ export function render(code, container, options = {}) {
|
|
|
68
62
|
stampVersions(container);
|
|
69
63
|
warnOnVersionSkew();
|
|
70
64
|
// Wrap the (already-computed) result in a STABLE thunk so insert() creates a
|
|
71
|
-
// top-level render effect. Without this, a static array result
|
|
72
|
-
// imperative backend's `[createMemo(() => createComponent(App)), " "]
|
|
65
|
+
// top-level render effect. Without this, a static array result: e.g. the
|
|
66
|
+
// imperative backend's `[createMemo(() => createComponent(App)), " "]`: is
|
|
73
67
|
// flattened ONCE with no enclosing effect, so the nested memos are read
|
|
74
68
|
// untracked and reactive boundaries deep in the tree (Suspense fallback ->
|
|
75
69
|
// content, Outlet, Show/For) never update. The thunk returns the same result
|
|
@@ -99,11 +93,6 @@ function isLitTemplateResult(value) {
|
|
|
99
93
|
/**
|
|
100
94
|
* Render into a different part of the DOM tree
|
|
101
95
|
*
|
|
102
|
-
* @param {() => any} code - Component to render
|
|
103
|
-
* @param {HTMLElement} target - Target element (outside current tree)
|
|
104
|
-
* @param {RenderOptions} options - Render options
|
|
105
|
-
* @returns {() => void} Dispose function
|
|
106
|
-
*
|
|
107
96
|
* @example
|
|
108
97
|
* ```typescript
|
|
109
98
|
* import { portal } from '@fluixi/core';
|
|
@@ -133,9 +122,6 @@ export function portal(code, target, options = {}) {
|
|
|
133
122
|
// ============================================================================
|
|
134
123
|
/**
|
|
135
124
|
* Check if a value can be rendered
|
|
136
|
-
*
|
|
137
|
-
* @param {any} value - Value to check
|
|
138
|
-
* @returns {boolean} True if renderable
|
|
139
125
|
*/
|
|
140
126
|
export function isRenderable(value) {
|
|
141
127
|
if (value == null)
|
|
@@ -1 +1,590 @@
|
|
|
1
|
-
|
|
1
|
+
// src/lib/render/index.ts
|
|
2
|
+
import { isServer as isServer3 } from "@fluixi/dom";
|
|
3
|
+
import { createRoot as createRoot2 } from "@fluixi/reactive/signal";
|
|
4
|
+
|
|
5
|
+
// src/lib/render/versions.ts
|
|
6
|
+
import { registerCoreVersion } from "@fluixi/dom";
|
|
7
|
+
|
|
8
|
+
// src/version.generated.ts
|
|
9
|
+
var VERSION = "1.0.0-alpha.84";
|
|
10
|
+
|
|
11
|
+
// src/lib/render/versions.ts
|
|
12
|
+
import { stampVersions, warnOnVersionSkew, versions } from "@fluixi/dom";
|
|
13
|
+
registerCoreVersion(VERSION);
|
|
14
|
+
|
|
15
|
+
// src/lib/render/index.ts
|
|
16
|
+
import {
|
|
17
|
+
isDOMNode,
|
|
18
|
+
delegateEvents,
|
|
19
|
+
insert
|
|
20
|
+
} from "@fluixi/dom";
|
|
21
|
+
|
|
22
|
+
// src/lib/render/component.ts
|
|
23
|
+
import { isServer } from "@fluixi/dom";
|
|
24
|
+
import {
|
|
25
|
+
createComponent as domCreateComponent,
|
|
26
|
+
asComponent
|
|
27
|
+
} from "@fluixi/dom";
|
|
28
|
+
import {
|
|
29
|
+
untrack,
|
|
30
|
+
onCleanup,
|
|
31
|
+
getOwner,
|
|
32
|
+
createEffect,
|
|
33
|
+
createMemo,
|
|
34
|
+
createSignal,
|
|
35
|
+
isSignal,
|
|
36
|
+
batch,
|
|
37
|
+
runWithOwner,
|
|
38
|
+
isOwnerDisposed
|
|
39
|
+
} from "@fluixi/reactive/signal";
|
|
40
|
+
var sharedConfig = {
|
|
41
|
+
context: null,
|
|
42
|
+
owner: null
|
|
43
|
+
};
|
|
44
|
+
function getSharedConfig() {
|
|
45
|
+
return sharedConfig;
|
|
46
|
+
}
|
|
47
|
+
var DEV = typeof process !== "undefined" && false;
|
|
48
|
+
var _LIFECYCLE = /* @__PURE__ */ Symbol.for("fluixi-lifecycle");
|
|
49
|
+
function getOwnerLifecycle() {
|
|
50
|
+
const owner = getOwner();
|
|
51
|
+
if (!owner) return null;
|
|
52
|
+
if (!owner[_LIFECYCLE]) {
|
|
53
|
+
const lc = { mounts: [], effects: [], scheduled: false };
|
|
54
|
+
owner[_LIFECYCLE] = lc;
|
|
55
|
+
}
|
|
56
|
+
return owner[_LIFECYCLE];
|
|
57
|
+
}
|
|
58
|
+
function scheduleLifecycleFlush(lc) {
|
|
59
|
+
if (lc.scheduled) return;
|
|
60
|
+
if (isServer()) {
|
|
61
|
+
lc.mounts = [];
|
|
62
|
+
lc.effects = [];
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
lc.scheduled = true;
|
|
66
|
+
const owner = getOwner();
|
|
67
|
+
queueMicrotask(() => {
|
|
68
|
+
if (isOwnerDisposed(owner)) {
|
|
69
|
+
lc.mounts = [];
|
|
70
|
+
lc.effects = [];
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
runWithOwner(owner, () => {
|
|
74
|
+
for (const cb of lc.mounts) {
|
|
75
|
+
try {
|
|
76
|
+
const cleanup = cb();
|
|
77
|
+
if (typeof cleanup === "function") {
|
|
78
|
+
onCleanup(cleanup);
|
|
79
|
+
}
|
|
80
|
+
} catch (e) {
|
|
81
|
+
console.error("Error in onMount callback:", e);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
for (const cb of lc.effects) {
|
|
85
|
+
let cleanup;
|
|
86
|
+
createEffect(() => {
|
|
87
|
+
if (cleanup) cleanup();
|
|
88
|
+
cleanup = cb();
|
|
89
|
+
});
|
|
90
|
+
onCleanup(() => {
|
|
91
|
+
if (cleanup) cleanup();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
lc.mounts = [];
|
|
95
|
+
lc.effects = [];
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function createComponent(Comp, props) {
|
|
100
|
+
return domCreateComponent(Comp, props);
|
|
101
|
+
}
|
|
102
|
+
function $component(value, props) {
|
|
103
|
+
const component = typeof value === "function" ? untrack(() => value(props)) : value;
|
|
104
|
+
const nameable = component != null && (typeof component === "function" || typeof component === "object");
|
|
105
|
+
if (nameable) {
|
|
106
|
+
try {
|
|
107
|
+
component["$name"] = value.name;
|
|
108
|
+
} catch {
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (nameable && !isSignal(component)) {
|
|
112
|
+
return asComponent(component);
|
|
113
|
+
}
|
|
114
|
+
return component;
|
|
115
|
+
}
|
|
116
|
+
function onMount(fn, reactive = true) {
|
|
117
|
+
if (isServer()) return;
|
|
118
|
+
const lc = getOwnerLifecycle();
|
|
119
|
+
if (lc) {
|
|
120
|
+
if (!reactive) {
|
|
121
|
+
if (!lc.scheduled) {
|
|
122
|
+
fn();
|
|
123
|
+
}
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
lc.mounts.push(fn);
|
|
127
|
+
scheduleLifecycleFlush(lc);
|
|
128
|
+
} else {
|
|
129
|
+
if (!reactive) {
|
|
130
|
+
fn();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
createEffect(() => {
|
|
134
|
+
const cleanup = untrack(fn);
|
|
135
|
+
if (typeof cleanup === "function") {
|
|
136
|
+
onCleanup(cleanup);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function onUnmount(fn) {
|
|
142
|
+
onCleanup(fn);
|
|
143
|
+
}
|
|
144
|
+
function useEffect(callback) {
|
|
145
|
+
const lc = getOwnerLifecycle();
|
|
146
|
+
if (lc) {
|
|
147
|
+
lc.effects.push(callback);
|
|
148
|
+
scheduleLifecycleFlush(lc);
|
|
149
|
+
} else {
|
|
150
|
+
let cleanup;
|
|
151
|
+
createEffect(() => {
|
|
152
|
+
if (cleanup) cleanup();
|
|
153
|
+
cleanup = callback();
|
|
154
|
+
});
|
|
155
|
+
onCleanup(() => {
|
|
156
|
+
if (cleanup) cleanup();
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function useMemo(fn) {
|
|
161
|
+
return createMemo(fn);
|
|
162
|
+
}
|
|
163
|
+
function useRef(initialValue) {
|
|
164
|
+
const ref = { current: initialValue };
|
|
165
|
+
onCleanup(() => {
|
|
166
|
+
ref.current = null;
|
|
167
|
+
});
|
|
168
|
+
return ref;
|
|
169
|
+
}
|
|
170
|
+
function useReducer(reducer, initialState) {
|
|
171
|
+
const [state, setState] = createSignal(initialState);
|
|
172
|
+
const dispatch = (action) => {
|
|
173
|
+
setState(reducer(state(), action));
|
|
174
|
+
};
|
|
175
|
+
return [state, dispatch];
|
|
176
|
+
}
|
|
177
|
+
function useEventListener(target, event, handler, options) {
|
|
178
|
+
useEffect(() => {
|
|
179
|
+
const element = target && "current" in target ? target.current : target;
|
|
180
|
+
if (!element) return;
|
|
181
|
+
element.addEventListener(event, handler, options);
|
|
182
|
+
return () => {
|
|
183
|
+
element.removeEventListener(event, handler, options);
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
function useCallback(callback) {
|
|
188
|
+
return callback;
|
|
189
|
+
}
|
|
190
|
+
function isDev() {
|
|
191
|
+
return DEV;
|
|
192
|
+
}
|
|
193
|
+
function devOnly(fn) {
|
|
194
|
+
if (DEV) {
|
|
195
|
+
fn();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// src/lib/render/suspense.ts
|
|
200
|
+
import {
|
|
201
|
+
createSignal as createSignal2,
|
|
202
|
+
createMemo as createMemo2,
|
|
203
|
+
createEffect as createEffect2,
|
|
204
|
+
createRenderEffect as createRenderEffect2,
|
|
205
|
+
isSignal as isSignal2,
|
|
206
|
+
readChildren,
|
|
207
|
+
useContext as useContext2,
|
|
208
|
+
createContext as createContext2,
|
|
209
|
+
createSuspenseBoundary,
|
|
210
|
+
provideSuspense
|
|
211
|
+
} from "@fluixi/reactive/signal";
|
|
212
|
+
import {
|
|
213
|
+
asSuspense,
|
|
214
|
+
isComponent,
|
|
215
|
+
createComponent as createComponent2,
|
|
216
|
+
runWithoutHydration
|
|
217
|
+
} from "@fluixi/dom";
|
|
218
|
+
function isNode(value) {
|
|
219
|
+
if (typeof window === "undefined") return false;
|
|
220
|
+
if (typeof Node === "function" && value instanceof Node) return true;
|
|
221
|
+
return !!(value && typeof value === "object" && typeof value.nodeType === "number");
|
|
222
|
+
}
|
|
223
|
+
function isLitResult(value) {
|
|
224
|
+
if (!value || typeof value !== "object") return false;
|
|
225
|
+
return !!(typeof value["_$litType$"] !== "undefined" || typeof value["_$litDirective$"] !== "undefined" || Array.isArray(value.strings) && Array.isArray(value.values));
|
|
226
|
+
}
|
|
227
|
+
function isPromise(value) {
|
|
228
|
+
return !!(value && typeof value === "object" && typeof value.then === "function" || value instanceof Promise);
|
|
229
|
+
}
|
|
230
|
+
function isJSXElement(value) {
|
|
231
|
+
return !!(value && typeof value === "object" && "type" in value && "props" in value);
|
|
232
|
+
}
|
|
233
|
+
var SuspenseListContext = createContext2(void 0, "suspense-list");
|
|
234
|
+
function Suspense(props) {
|
|
235
|
+
return createComponent2(SuspenseImpl, props);
|
|
236
|
+
}
|
|
237
|
+
function SuspenseImpl(props) {
|
|
238
|
+
const boundary = createSuspenseBoundary();
|
|
239
|
+
const listCtx = useContext2(SuspenseListContext);
|
|
240
|
+
const listState = listCtx ? listCtx.register(boundary.inFallback) : void 0;
|
|
241
|
+
function instantiateOnce(val) {
|
|
242
|
+
if (val == null || typeof val === "boolean") return null;
|
|
243
|
+
if (typeof val === "function" && isComponent(val) && !isSignal2(val)) return val();
|
|
244
|
+
return val;
|
|
245
|
+
}
|
|
246
|
+
const fallback = runWithoutHydration(() => instantiateOnce(props.fallback ?? null));
|
|
247
|
+
const children = provideSuspense(boundary, () => readChildren(() => props.children));
|
|
248
|
+
const track = (value, depth) => {
|
|
249
|
+
if (depth > 8) return;
|
|
250
|
+
if (Array.isArray(value)) {
|
|
251
|
+
for (const x of value) track(x, depth + 1);
|
|
252
|
+
} else if (typeof value === "function" && isSignal2(value)) {
|
|
253
|
+
track(value(), depth + 1);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
provideSuspense(boundary, () => {
|
|
257
|
+
createRenderEffect2(() => track(children, 0));
|
|
258
|
+
});
|
|
259
|
+
const [resolved, setResolved] = createSignal2(void 0);
|
|
260
|
+
const childIsPromise = isPromise(children);
|
|
261
|
+
if (childIsPromise) {
|
|
262
|
+
boundary.increment();
|
|
263
|
+
children.then(
|
|
264
|
+
(v) => {
|
|
265
|
+
setResolved(() => v);
|
|
266
|
+
boundary.decrement();
|
|
267
|
+
},
|
|
268
|
+
() => boundary.decrement()
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
return createMemo2(() => {
|
|
272
|
+
const showFallback = listState ? listState.showFallback() : boundary.inFallback();
|
|
273
|
+
if (showFallback) return fallback;
|
|
274
|
+
if (childIsPromise) return resolved();
|
|
275
|
+
return children;
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
function SuspenseList(props) {
|
|
279
|
+
return createComponent2(SuspenseListImpl, props);
|
|
280
|
+
}
|
|
281
|
+
function SuspenseListImpl(props) {
|
|
282
|
+
const { revealOrder = "together", tail } = props;
|
|
283
|
+
const registrations = [];
|
|
284
|
+
function coordinateReveal() {
|
|
285
|
+
if (revealOrder === "together") {
|
|
286
|
+
const allResolved = registrations.every((r) => !r.inFallback());
|
|
287
|
+
registrations.forEach((r) => {
|
|
288
|
+
r.setShowContent(allResolved);
|
|
289
|
+
r.setShowFallback(!allResolved);
|
|
290
|
+
});
|
|
291
|
+
} else {
|
|
292
|
+
const items = revealOrder === "backwards" ? [...registrations].reverse() : registrations;
|
|
293
|
+
let blocked = false;
|
|
294
|
+
for (const r of items) {
|
|
295
|
+
if (blocked || r.inFallback()) {
|
|
296
|
+
blocked = true;
|
|
297
|
+
r.setShowContent(false);
|
|
298
|
+
r.setShowFallback(tail !== "hidden");
|
|
299
|
+
} else {
|
|
300
|
+
r.setShowContent(true);
|
|
301
|
+
r.setShowFallback(false);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
const coordinator = {
|
|
307
|
+
register: (inFallback) => {
|
|
308
|
+
const [showContent, setShowContent] = createSignal2(true);
|
|
309
|
+
const [showFallback, setShowFallback] = createSignal2(false);
|
|
310
|
+
registrations.push({ inFallback, setShowContent, setShowFallback });
|
|
311
|
+
createEffect2(() => {
|
|
312
|
+
inFallback();
|
|
313
|
+
coordinateReveal();
|
|
314
|
+
});
|
|
315
|
+
return { showContent, showFallback };
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
return SuspenseListContext.Provider({
|
|
319
|
+
value: coordinator,
|
|
320
|
+
children: props.children
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
asSuspense(Suspense);
|
|
324
|
+
Object.defineProperty(Suspense, "__suspense", { value: true, enumerable: true });
|
|
325
|
+
|
|
326
|
+
// src/lib/render/lazy.ts
|
|
327
|
+
import { createComponent as createComponent3 } from "@fluixi/dom";
|
|
328
|
+
import {
|
|
329
|
+
untrack as untrack2,
|
|
330
|
+
createMemo as createMemo3,
|
|
331
|
+
createResource as createResource2
|
|
332
|
+
} from "@fluixi/reactive/signal";
|
|
333
|
+
function fromChunk(value) {
|
|
334
|
+
if (value != null && (typeof value === "object" || typeof value === "function")) {
|
|
335
|
+
try {
|
|
336
|
+
value["$lazy"] = true;
|
|
337
|
+
} catch {
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return value;
|
|
341
|
+
}
|
|
342
|
+
function lazy(loader, options) {
|
|
343
|
+
let resolved;
|
|
344
|
+
let promise;
|
|
345
|
+
let component;
|
|
346
|
+
function load() {
|
|
347
|
+
if (!promise) {
|
|
348
|
+
promise = loader().then((mod) => resolved = mod.default);
|
|
349
|
+
}
|
|
350
|
+
return promise;
|
|
351
|
+
}
|
|
352
|
+
if (options?.preload) load();
|
|
353
|
+
const LazyWrapper = ((props) => {
|
|
354
|
+
if (resolved) {
|
|
355
|
+
const C = resolved;
|
|
356
|
+
return fromChunk(untrack2(() => C(props)));
|
|
357
|
+
}
|
|
358
|
+
if (!component) {
|
|
359
|
+
const [resource] = createResource2(() => load(), { transport: false });
|
|
360
|
+
component = resource;
|
|
361
|
+
if (resource.error) throw resource.error;
|
|
362
|
+
}
|
|
363
|
+
return createMemo3(() => {
|
|
364
|
+
const C = component();
|
|
365
|
+
return C ? fromChunk(createComponent3(C, props)) : void 0;
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
LazyWrapper.preload = () => load().then(() => void 0);
|
|
369
|
+
LazyWrapper.$lazy = true;
|
|
370
|
+
LazyWrapper.loader = loader;
|
|
371
|
+
return LazyWrapper;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// src/lib/render/deferred.ts
|
|
375
|
+
import { isServer as isServer2 } from "@fluixi/dom";
|
|
376
|
+
import { createMemo as createMemo4, createSignal as createSignal3 } from "@fluixi/reactive/signal";
|
|
377
|
+
import { observeIntersection } from "@fluixi/dom/utils";
|
|
378
|
+
function deferred(loader, options) {
|
|
379
|
+
const exportName = options.export ?? "default";
|
|
380
|
+
const Lazy = lazy(
|
|
381
|
+
() => loader().then((mod) => {
|
|
382
|
+
const component = mod[exportName];
|
|
383
|
+
if (typeof component !== "function") {
|
|
384
|
+
throw new Error(
|
|
385
|
+
`deferred(): module has no '${exportName}' export (got ${typeof component}).`
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
return { default: component };
|
|
389
|
+
}),
|
|
390
|
+
{ fallback: options.fallback }
|
|
391
|
+
);
|
|
392
|
+
function Deferred(props) {
|
|
393
|
+
if (options.strategy.kind === "never") return isServer2() ? Lazy(props) : null;
|
|
394
|
+
if (isServer2() || options.strategy.kind === "eager") return Lazy(props);
|
|
395
|
+
const [ready, setReady] = createSignal3(false);
|
|
396
|
+
const start = () => {
|
|
397
|
+
void Lazy.preload().then(() => setReady(true));
|
|
398
|
+
};
|
|
399
|
+
const anchor = options.strategy.kind === "visible" ? createAnchor() : void 0;
|
|
400
|
+
schedule(options.strategy, start, anchor);
|
|
401
|
+
return createMemo4(() => ready() ? Lazy(props) : anchor ?? options.fallback ?? null, void 0, {
|
|
402
|
+
name: "deferred"
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
Deferred.preload = Lazy.preload;
|
|
406
|
+
return Deferred;
|
|
407
|
+
}
|
|
408
|
+
function createAnchor() {
|
|
409
|
+
const el = document.createElement("span");
|
|
410
|
+
el.setAttribute("data-fx-load", "visible");
|
|
411
|
+
el.style.display = "block";
|
|
412
|
+
return el;
|
|
413
|
+
}
|
|
414
|
+
function schedule(strategy, start, anchor) {
|
|
415
|
+
let fired = false;
|
|
416
|
+
const once = () => {
|
|
417
|
+
if (fired) return;
|
|
418
|
+
fired = true;
|
|
419
|
+
start();
|
|
420
|
+
};
|
|
421
|
+
switch (strategy.kind) {
|
|
422
|
+
case "idle": {
|
|
423
|
+
const ric = globalThis.requestIdleCallback;
|
|
424
|
+
if (ric) ric(once);
|
|
425
|
+
else setTimeout(once, 1);
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
case "visible": {
|
|
429
|
+
if (!anchor || typeof IntersectionObserver === "undefined") {
|
|
430
|
+
once();
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
const stop = observeIntersection(
|
|
434
|
+
anchor,
|
|
435
|
+
(isIntersecting) => {
|
|
436
|
+
if (!isIntersecting) return;
|
|
437
|
+
stop();
|
|
438
|
+
once();
|
|
439
|
+
},
|
|
440
|
+
{ rootMargin: strategy.rootMargin ?? "0px" }
|
|
441
|
+
);
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
case "interaction": {
|
|
445
|
+
const handler = () => {
|
|
446
|
+
for (const event of strategy.events) {
|
|
447
|
+
document.removeEventListener(event, handler, true);
|
|
448
|
+
}
|
|
449
|
+
once();
|
|
450
|
+
};
|
|
451
|
+
for (const event of strategy.events) {
|
|
452
|
+
document.addEventListener(event, handler, { capture: true, passive: true });
|
|
453
|
+
}
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
case "media": {
|
|
457
|
+
if (typeof matchMedia === "undefined") {
|
|
458
|
+
once();
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
const query = matchMedia(strategy.query);
|
|
462
|
+
if (query.matches) {
|
|
463
|
+
once();
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
const onChange = (e) => {
|
|
467
|
+
if (!e.matches) return;
|
|
468
|
+
query.removeEventListener("change", onChange);
|
|
469
|
+
once();
|
|
470
|
+
};
|
|
471
|
+
query.addEventListener("change", onChange);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
/* c8 ignore next 3 */
|
|
475
|
+
default:
|
|
476
|
+
once();
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// src/lib/render/await.ts
|
|
481
|
+
import { createResource as createResource3 } from "@fluixi/reactive/signal";
|
|
482
|
+
function Await(props) {
|
|
483
|
+
const fetcher = () => {
|
|
484
|
+
const v = props.value;
|
|
485
|
+
return typeof v === "function" ? v() : v;
|
|
486
|
+
};
|
|
487
|
+
const [data] = createResource3(fetcher);
|
|
488
|
+
return () => {
|
|
489
|
+
if (data.loading) return props.fallback;
|
|
490
|
+
const child = props.children;
|
|
491
|
+
return typeof child === "function" ? child(data()) : child;
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// src/lib/render/index.ts
|
|
496
|
+
function render(code, container, options = {}) {
|
|
497
|
+
delegateEvents(["click", "input", "change", "submit"]);
|
|
498
|
+
if (isServer3()) {
|
|
499
|
+
throw new Error(
|
|
500
|
+
"render() is for client-side only. Use renderToString() on server."
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
if (!container) {
|
|
504
|
+
throw new Error("Container element is required");
|
|
505
|
+
}
|
|
506
|
+
let disposer;
|
|
507
|
+
createRoot2((dispose) => {
|
|
508
|
+
disposer = dispose;
|
|
509
|
+
const result = typeof code === "function" ? code() : code;
|
|
510
|
+
container.textContent = "";
|
|
511
|
+
stampVersions(container);
|
|
512
|
+
warnOnVersionSkew();
|
|
513
|
+
insert(container, () => result);
|
|
514
|
+
});
|
|
515
|
+
return () => {
|
|
516
|
+
if (disposer) {
|
|
517
|
+
disposer();
|
|
518
|
+
disposer = void 0;
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
function isLitTemplateResult(value) {
|
|
523
|
+
return value && typeof value === "object" && (value["_$litType$"] !== void 0 || value["_$litDirective$"] !== void 0);
|
|
524
|
+
}
|
|
525
|
+
function portal(code, target, options = {}) {
|
|
526
|
+
const container = document.createElement("div");
|
|
527
|
+
container.setAttribute("data-portal", "true");
|
|
528
|
+
target.appendChild(container);
|
|
529
|
+
const dispose = render(code, container, options);
|
|
530
|
+
return () => {
|
|
531
|
+
dispose();
|
|
532
|
+
if (target.contains(container)) {
|
|
533
|
+
target.removeChild(container);
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
function isRenderable(value) {
|
|
538
|
+
if (value == null) return true;
|
|
539
|
+
if (typeof value === "function") return true;
|
|
540
|
+
if (isDOMNode(value)) return true;
|
|
541
|
+
if (isLitTemplateResult(value)) return true;
|
|
542
|
+
if (Array.isArray(value)) return true;
|
|
543
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
544
|
+
return true;
|
|
545
|
+
}
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
function initDelegation() {
|
|
549
|
+
if (isServer3()) return;
|
|
550
|
+
delegateEvents(["click", "input", "change", "submit"]);
|
|
551
|
+
}
|
|
552
|
+
function cleanupDelegation() {
|
|
553
|
+
if (isServer3()) return;
|
|
554
|
+
}
|
|
555
|
+
export {
|
|
556
|
+
$component,
|
|
557
|
+
Await,
|
|
558
|
+
DEV,
|
|
559
|
+
Suspense,
|
|
560
|
+
SuspenseList,
|
|
561
|
+
batch,
|
|
562
|
+
cleanupDelegation,
|
|
563
|
+
createComponent,
|
|
564
|
+
createEffect,
|
|
565
|
+
createMemo,
|
|
566
|
+
deferred,
|
|
567
|
+
devOnly,
|
|
568
|
+
getOwner,
|
|
569
|
+
getSharedConfig,
|
|
570
|
+
initDelegation,
|
|
571
|
+
isDev,
|
|
572
|
+
isJSXElement,
|
|
573
|
+
isLitResult,
|
|
574
|
+
isNode,
|
|
575
|
+
isPromise,
|
|
576
|
+
isRenderable,
|
|
577
|
+
lazy,
|
|
578
|
+
onCleanup,
|
|
579
|
+
onMount,
|
|
580
|
+
onUnmount,
|
|
581
|
+
portal,
|
|
582
|
+
render,
|
|
583
|
+
runWithOwner,
|
|
584
|
+
useCallback,
|
|
585
|
+
useEffect,
|
|
586
|
+
useEventListener,
|
|
587
|
+
useMemo,
|
|
588
|
+
useReducer,
|
|
589
|
+
useRef
|
|
590
|
+
};
|