@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 +1,573 @@
|
|
|
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/render/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
$component: () => $component,
|
|
24
|
+
Await: () => Await,
|
|
25
|
+
DEV: () => DEV,
|
|
26
|
+
Suspense: () => Suspense,
|
|
27
|
+
SuspenseList: () => SuspenseList,
|
|
28
|
+
batch: () => import_signal.batch,
|
|
29
|
+
cleanupDelegation: () => cleanupDelegation,
|
|
30
|
+
createComponent: () => createComponent,
|
|
31
|
+
createEffect: () => import_signal.createEffect,
|
|
32
|
+
createMemo: () => import_signal.createMemo,
|
|
33
|
+
deferred: () => deferred,
|
|
34
|
+
devOnly: () => devOnly,
|
|
35
|
+
getOwner: () => import_signal.getOwner,
|
|
36
|
+
getSharedConfig: () => getSharedConfig,
|
|
37
|
+
initDelegation: () => initDelegation,
|
|
38
|
+
isDev: () => isDev,
|
|
39
|
+
isJSXElement: () => isJSXElement,
|
|
40
|
+
isLitResult: () => isLitResult,
|
|
41
|
+
isNode: () => isNode,
|
|
42
|
+
isPromise: () => isPromise,
|
|
43
|
+
isRenderable: () => isRenderable,
|
|
44
|
+
lazy: () => lazy,
|
|
45
|
+
onCleanup: () => import_signal.onCleanup,
|
|
46
|
+
onMount: () => onMount,
|
|
47
|
+
onUnmount: () => onUnmount,
|
|
48
|
+
portal: () => portal,
|
|
49
|
+
render: () => render,
|
|
50
|
+
runWithOwner: () => import_signal.runWithOwner,
|
|
51
|
+
useCallback: () => useCallback,
|
|
52
|
+
useEffect: () => useEffect,
|
|
53
|
+
useEventListener: () => useEventListener,
|
|
54
|
+
useMemo: () => useMemo,
|
|
55
|
+
useReducer: () => useReducer,
|
|
56
|
+
useRef: () => useRef
|
|
57
|
+
});
|
|
58
|
+
module.exports = __toCommonJS(index_exports);
|
|
59
|
+
var import_dom8 = require("@fluixi/dom");
|
|
60
|
+
var import_signal6 = require("@fluixi/reactive/signal");
|
|
61
|
+
|
|
62
|
+
// src/lib/render/versions.ts
|
|
63
|
+
var import_dom = require("@fluixi/dom");
|
|
64
|
+
|
|
65
|
+
// src/version.generated.ts
|
|
66
|
+
var VERSION = "1.0.0-alpha.84";
|
|
67
|
+
|
|
68
|
+
// src/lib/render/versions.ts
|
|
69
|
+
var import_dom2 = require("@fluixi/dom");
|
|
70
|
+
(0, import_dom.registerCoreVersion)(VERSION);
|
|
71
|
+
|
|
72
|
+
// src/lib/render/index.ts
|
|
73
|
+
var import_dom9 = require("@fluixi/dom");
|
|
74
|
+
|
|
75
|
+
// src/lib/render/component.ts
|
|
76
|
+
var import_dom3 = require("@fluixi/dom");
|
|
77
|
+
var import_dom4 = require("@fluixi/dom");
|
|
78
|
+
var import_signal = require("@fluixi/reactive/signal");
|
|
79
|
+
var sharedConfig = {
|
|
80
|
+
context: null,
|
|
81
|
+
owner: null
|
|
82
|
+
};
|
|
83
|
+
function getSharedConfig() {
|
|
84
|
+
return sharedConfig;
|
|
85
|
+
}
|
|
86
|
+
var DEV = typeof process !== "undefined" && false;
|
|
87
|
+
var _LIFECYCLE = /* @__PURE__ */ Symbol.for("fluixi-lifecycle");
|
|
88
|
+
function getOwnerLifecycle() {
|
|
89
|
+
const owner = (0, import_signal.getOwner)();
|
|
90
|
+
if (!owner) return null;
|
|
91
|
+
if (!owner[_LIFECYCLE]) {
|
|
92
|
+
const lc = { mounts: [], effects: [], scheduled: false };
|
|
93
|
+
owner[_LIFECYCLE] = lc;
|
|
94
|
+
}
|
|
95
|
+
return owner[_LIFECYCLE];
|
|
96
|
+
}
|
|
97
|
+
function scheduleLifecycleFlush(lc) {
|
|
98
|
+
if (lc.scheduled) return;
|
|
99
|
+
if ((0, import_dom3.isServer)()) {
|
|
100
|
+
lc.mounts = [];
|
|
101
|
+
lc.effects = [];
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
lc.scheduled = true;
|
|
105
|
+
const owner = (0, import_signal.getOwner)();
|
|
106
|
+
queueMicrotask(() => {
|
|
107
|
+
if ((0, import_signal.isOwnerDisposed)(owner)) {
|
|
108
|
+
lc.mounts = [];
|
|
109
|
+
lc.effects = [];
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
(0, import_signal.runWithOwner)(owner, () => {
|
|
113
|
+
for (const cb of lc.mounts) {
|
|
114
|
+
try {
|
|
115
|
+
const cleanup = cb();
|
|
116
|
+
if (typeof cleanup === "function") {
|
|
117
|
+
(0, import_signal.onCleanup)(cleanup);
|
|
118
|
+
}
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.error("Error in onMount callback:", e);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
for (const cb of lc.effects) {
|
|
124
|
+
let cleanup;
|
|
125
|
+
(0, import_signal.createEffect)(() => {
|
|
126
|
+
if (cleanup) cleanup();
|
|
127
|
+
cleanup = cb();
|
|
128
|
+
});
|
|
129
|
+
(0, import_signal.onCleanup)(() => {
|
|
130
|
+
if (cleanup) cleanup();
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
lc.mounts = [];
|
|
134
|
+
lc.effects = [];
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function createComponent(Comp, props) {
|
|
139
|
+
return (0, import_dom4.createComponent)(Comp, props);
|
|
140
|
+
}
|
|
141
|
+
function $component(value, props) {
|
|
142
|
+
const component = typeof value === "function" ? (0, import_signal.untrack)(() => value(props)) : value;
|
|
143
|
+
const nameable = component != null && (typeof component === "function" || typeof component === "object");
|
|
144
|
+
if (nameable) {
|
|
145
|
+
try {
|
|
146
|
+
component["$name"] = value.name;
|
|
147
|
+
} catch {
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (nameable && !(0, import_signal.isSignal)(component)) {
|
|
151
|
+
return (0, import_dom4.asComponent)(component);
|
|
152
|
+
}
|
|
153
|
+
return component;
|
|
154
|
+
}
|
|
155
|
+
function onMount(fn, reactive = true) {
|
|
156
|
+
if ((0, import_dom3.isServer)()) return;
|
|
157
|
+
const lc = getOwnerLifecycle();
|
|
158
|
+
if (lc) {
|
|
159
|
+
if (!reactive) {
|
|
160
|
+
if (!lc.scheduled) {
|
|
161
|
+
fn();
|
|
162
|
+
}
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
lc.mounts.push(fn);
|
|
166
|
+
scheduleLifecycleFlush(lc);
|
|
167
|
+
} else {
|
|
168
|
+
if (!reactive) {
|
|
169
|
+
fn();
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
(0, import_signal.createEffect)(() => {
|
|
173
|
+
const cleanup = (0, import_signal.untrack)(fn);
|
|
174
|
+
if (typeof cleanup === "function") {
|
|
175
|
+
(0, import_signal.onCleanup)(cleanup);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function onUnmount(fn) {
|
|
181
|
+
(0, import_signal.onCleanup)(fn);
|
|
182
|
+
}
|
|
183
|
+
function useEffect(callback) {
|
|
184
|
+
const lc = getOwnerLifecycle();
|
|
185
|
+
if (lc) {
|
|
186
|
+
lc.effects.push(callback);
|
|
187
|
+
scheduleLifecycleFlush(lc);
|
|
188
|
+
} else {
|
|
189
|
+
let cleanup;
|
|
190
|
+
(0, import_signal.createEffect)(() => {
|
|
191
|
+
if (cleanup) cleanup();
|
|
192
|
+
cleanup = callback();
|
|
193
|
+
});
|
|
194
|
+
(0, import_signal.onCleanup)(() => {
|
|
195
|
+
if (cleanup) cleanup();
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function useMemo(fn) {
|
|
200
|
+
return (0, import_signal.createMemo)(fn);
|
|
201
|
+
}
|
|
202
|
+
function useRef(initialValue) {
|
|
203
|
+
const ref = { current: initialValue };
|
|
204
|
+
(0, import_signal.onCleanup)(() => {
|
|
205
|
+
ref.current = null;
|
|
206
|
+
});
|
|
207
|
+
return ref;
|
|
208
|
+
}
|
|
209
|
+
function useReducer(reducer, initialState) {
|
|
210
|
+
const [state, setState] = (0, import_signal.createSignal)(initialState);
|
|
211
|
+
const dispatch = (action) => {
|
|
212
|
+
setState(reducer(state(), action));
|
|
213
|
+
};
|
|
214
|
+
return [state, dispatch];
|
|
215
|
+
}
|
|
216
|
+
function useEventListener(target, event, handler, options) {
|
|
217
|
+
useEffect(() => {
|
|
218
|
+
const element = target && "current" in target ? target.current : target;
|
|
219
|
+
if (!element) return;
|
|
220
|
+
element.addEventListener(event, handler, options);
|
|
221
|
+
return () => {
|
|
222
|
+
element.removeEventListener(event, handler, options);
|
|
223
|
+
};
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
function useCallback(callback) {
|
|
227
|
+
return callback;
|
|
228
|
+
}
|
|
229
|
+
function isDev() {
|
|
230
|
+
return DEV;
|
|
231
|
+
}
|
|
232
|
+
function devOnly(fn) {
|
|
233
|
+
if (DEV) {
|
|
234
|
+
fn();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// src/lib/render/suspense.ts
|
|
239
|
+
var import_signal2 = require("@fluixi/reactive/signal");
|
|
240
|
+
var import_dom5 = require("@fluixi/dom");
|
|
241
|
+
function isNode(value) {
|
|
242
|
+
if (typeof window === "undefined") return false;
|
|
243
|
+
if (typeof Node === "function" && value instanceof Node) return true;
|
|
244
|
+
return !!(value && typeof value === "object" && typeof value.nodeType === "number");
|
|
245
|
+
}
|
|
246
|
+
function isLitResult(value) {
|
|
247
|
+
if (!value || typeof value !== "object") return false;
|
|
248
|
+
return !!(typeof value["_$litType$"] !== "undefined" || typeof value["_$litDirective$"] !== "undefined" || Array.isArray(value.strings) && Array.isArray(value.values));
|
|
249
|
+
}
|
|
250
|
+
function isPromise(value) {
|
|
251
|
+
return !!(value && typeof value === "object" && typeof value.then === "function" || value instanceof Promise);
|
|
252
|
+
}
|
|
253
|
+
function isJSXElement(value) {
|
|
254
|
+
return !!(value && typeof value === "object" && "type" in value && "props" in value);
|
|
255
|
+
}
|
|
256
|
+
var SuspenseListContext = (0, import_signal2.createContext)(void 0, "suspense-list");
|
|
257
|
+
function Suspense(props) {
|
|
258
|
+
return (0, import_dom5.createComponent)(SuspenseImpl, props);
|
|
259
|
+
}
|
|
260
|
+
function SuspenseImpl(props) {
|
|
261
|
+
const boundary = (0, import_signal2.createSuspenseBoundary)();
|
|
262
|
+
const listCtx = (0, import_signal2.useContext)(SuspenseListContext);
|
|
263
|
+
const listState = listCtx ? listCtx.register(boundary.inFallback) : void 0;
|
|
264
|
+
function instantiateOnce(val) {
|
|
265
|
+
if (val == null || typeof val === "boolean") return null;
|
|
266
|
+
if (typeof val === "function" && (0, import_dom5.isComponent)(val) && !(0, import_signal2.isSignal)(val)) return val();
|
|
267
|
+
return val;
|
|
268
|
+
}
|
|
269
|
+
const fallback = (0, import_dom5.runWithoutHydration)(() => instantiateOnce(props.fallback ?? null));
|
|
270
|
+
const children = (0, import_signal2.provideSuspense)(boundary, () => (0, import_signal2.readChildren)(() => props.children));
|
|
271
|
+
const track = (value, depth) => {
|
|
272
|
+
if (depth > 8) return;
|
|
273
|
+
if (Array.isArray(value)) {
|
|
274
|
+
for (const x of value) track(x, depth + 1);
|
|
275
|
+
} else if (typeof value === "function" && (0, import_signal2.isSignal)(value)) {
|
|
276
|
+
track(value(), depth + 1);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
(0, import_signal2.provideSuspense)(boundary, () => {
|
|
280
|
+
(0, import_signal2.createRenderEffect)(() => track(children, 0));
|
|
281
|
+
});
|
|
282
|
+
const [resolved, setResolved] = (0, import_signal2.createSignal)(void 0);
|
|
283
|
+
const childIsPromise = isPromise(children);
|
|
284
|
+
if (childIsPromise) {
|
|
285
|
+
boundary.increment();
|
|
286
|
+
children.then(
|
|
287
|
+
(v) => {
|
|
288
|
+
setResolved(() => v);
|
|
289
|
+
boundary.decrement();
|
|
290
|
+
},
|
|
291
|
+
() => boundary.decrement()
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
return (0, import_signal2.createMemo)(() => {
|
|
295
|
+
const showFallback = listState ? listState.showFallback() : boundary.inFallback();
|
|
296
|
+
if (showFallback) return fallback;
|
|
297
|
+
if (childIsPromise) return resolved();
|
|
298
|
+
return children;
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
function SuspenseList(props) {
|
|
302
|
+
return (0, import_dom5.createComponent)(SuspenseListImpl, props);
|
|
303
|
+
}
|
|
304
|
+
function SuspenseListImpl(props) {
|
|
305
|
+
const { revealOrder = "together", tail } = props;
|
|
306
|
+
const registrations = [];
|
|
307
|
+
function coordinateReveal() {
|
|
308
|
+
if (revealOrder === "together") {
|
|
309
|
+
const allResolved = registrations.every((r) => !r.inFallback());
|
|
310
|
+
registrations.forEach((r) => {
|
|
311
|
+
r.setShowContent(allResolved);
|
|
312
|
+
r.setShowFallback(!allResolved);
|
|
313
|
+
});
|
|
314
|
+
} else {
|
|
315
|
+
const items = revealOrder === "backwards" ? [...registrations].reverse() : registrations;
|
|
316
|
+
let blocked = false;
|
|
317
|
+
for (const r of items) {
|
|
318
|
+
if (blocked || r.inFallback()) {
|
|
319
|
+
blocked = true;
|
|
320
|
+
r.setShowContent(false);
|
|
321
|
+
r.setShowFallback(tail !== "hidden");
|
|
322
|
+
} else {
|
|
323
|
+
r.setShowContent(true);
|
|
324
|
+
r.setShowFallback(false);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const coordinator = {
|
|
330
|
+
register: (inFallback) => {
|
|
331
|
+
const [showContent, setShowContent] = (0, import_signal2.createSignal)(true);
|
|
332
|
+
const [showFallback, setShowFallback] = (0, import_signal2.createSignal)(false);
|
|
333
|
+
registrations.push({ inFallback, setShowContent, setShowFallback });
|
|
334
|
+
(0, import_signal2.createEffect)(() => {
|
|
335
|
+
inFallback();
|
|
336
|
+
coordinateReveal();
|
|
337
|
+
});
|
|
338
|
+
return { showContent, showFallback };
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
return SuspenseListContext.Provider({
|
|
342
|
+
value: coordinator,
|
|
343
|
+
children: props.children
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
(0, import_dom5.asSuspense)(Suspense);
|
|
347
|
+
Object.defineProperty(Suspense, "__suspense", { value: true, enumerable: true });
|
|
348
|
+
|
|
349
|
+
// src/lib/render/lazy.ts
|
|
350
|
+
var import_dom6 = require("@fluixi/dom");
|
|
351
|
+
var import_signal3 = require("@fluixi/reactive/signal");
|
|
352
|
+
function fromChunk(value) {
|
|
353
|
+
if (value != null && (typeof value === "object" || typeof value === "function")) {
|
|
354
|
+
try {
|
|
355
|
+
value["$lazy"] = true;
|
|
356
|
+
} catch {
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return value;
|
|
360
|
+
}
|
|
361
|
+
function lazy(loader, options) {
|
|
362
|
+
let resolved;
|
|
363
|
+
let promise;
|
|
364
|
+
let component;
|
|
365
|
+
function load() {
|
|
366
|
+
if (!promise) {
|
|
367
|
+
promise = loader().then((mod) => resolved = mod.default);
|
|
368
|
+
}
|
|
369
|
+
return promise;
|
|
370
|
+
}
|
|
371
|
+
if (options?.preload) load();
|
|
372
|
+
const LazyWrapper = ((props) => {
|
|
373
|
+
if (resolved) {
|
|
374
|
+
const C = resolved;
|
|
375
|
+
return fromChunk((0, import_signal3.untrack)(() => C(props)));
|
|
376
|
+
}
|
|
377
|
+
if (!component) {
|
|
378
|
+
const [resource] = (0, import_signal3.createResource)(() => load(), { transport: false });
|
|
379
|
+
component = resource;
|
|
380
|
+
if (resource.error) throw resource.error;
|
|
381
|
+
}
|
|
382
|
+
return (0, import_signal3.createMemo)(() => {
|
|
383
|
+
const C = component();
|
|
384
|
+
return C ? fromChunk((0, import_dom6.createComponent)(C, props)) : void 0;
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
LazyWrapper.preload = () => load().then(() => void 0);
|
|
388
|
+
LazyWrapper.$lazy = true;
|
|
389
|
+
LazyWrapper.loader = loader;
|
|
390
|
+
return LazyWrapper;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// src/lib/render/deferred.ts
|
|
394
|
+
var import_dom7 = require("@fluixi/dom");
|
|
395
|
+
var import_signal4 = require("@fluixi/reactive/signal");
|
|
396
|
+
var import_utils = require("@fluixi/dom/utils");
|
|
397
|
+
function deferred(loader, options) {
|
|
398
|
+
const exportName = options.export ?? "default";
|
|
399
|
+
const Lazy = lazy(
|
|
400
|
+
() => loader().then((mod) => {
|
|
401
|
+
const component = mod[exportName];
|
|
402
|
+
if (typeof component !== "function") {
|
|
403
|
+
throw new Error(
|
|
404
|
+
`deferred(): module has no '${exportName}' export (got ${typeof component}).`
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
return { default: component };
|
|
408
|
+
}),
|
|
409
|
+
{ fallback: options.fallback }
|
|
410
|
+
);
|
|
411
|
+
function Deferred(props) {
|
|
412
|
+
if (options.strategy.kind === "never") return (0, import_dom7.isServer)() ? Lazy(props) : null;
|
|
413
|
+
if ((0, import_dom7.isServer)() || options.strategy.kind === "eager") return Lazy(props);
|
|
414
|
+
const [ready, setReady] = (0, import_signal4.createSignal)(false);
|
|
415
|
+
const start = () => {
|
|
416
|
+
void Lazy.preload().then(() => setReady(true));
|
|
417
|
+
};
|
|
418
|
+
const anchor = options.strategy.kind === "visible" ? createAnchor() : void 0;
|
|
419
|
+
schedule(options.strategy, start, anchor);
|
|
420
|
+
return (0, import_signal4.createMemo)(() => ready() ? Lazy(props) : anchor ?? options.fallback ?? null, void 0, {
|
|
421
|
+
name: "deferred"
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
Deferred.preload = Lazy.preload;
|
|
425
|
+
return Deferred;
|
|
426
|
+
}
|
|
427
|
+
function createAnchor() {
|
|
428
|
+
const el = document.createElement("span");
|
|
429
|
+
el.setAttribute("data-fx-load", "visible");
|
|
430
|
+
el.style.display = "block";
|
|
431
|
+
return el;
|
|
432
|
+
}
|
|
433
|
+
function schedule(strategy, start, anchor) {
|
|
434
|
+
let fired = false;
|
|
435
|
+
const once = () => {
|
|
436
|
+
if (fired) return;
|
|
437
|
+
fired = true;
|
|
438
|
+
start();
|
|
439
|
+
};
|
|
440
|
+
switch (strategy.kind) {
|
|
441
|
+
case "idle": {
|
|
442
|
+
const ric = globalThis.requestIdleCallback;
|
|
443
|
+
if (ric) ric(once);
|
|
444
|
+
else setTimeout(once, 1);
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
case "visible": {
|
|
448
|
+
if (!anchor || typeof IntersectionObserver === "undefined") {
|
|
449
|
+
once();
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
const stop = (0, import_utils.observeIntersection)(
|
|
453
|
+
anchor,
|
|
454
|
+
(isIntersecting) => {
|
|
455
|
+
if (!isIntersecting) return;
|
|
456
|
+
stop();
|
|
457
|
+
once();
|
|
458
|
+
},
|
|
459
|
+
{ rootMargin: strategy.rootMargin ?? "0px" }
|
|
460
|
+
);
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
case "interaction": {
|
|
464
|
+
const handler = () => {
|
|
465
|
+
for (const event of strategy.events) {
|
|
466
|
+
document.removeEventListener(event, handler, true);
|
|
467
|
+
}
|
|
468
|
+
once();
|
|
469
|
+
};
|
|
470
|
+
for (const event of strategy.events) {
|
|
471
|
+
document.addEventListener(event, handler, { capture: true, passive: true });
|
|
472
|
+
}
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
case "media": {
|
|
476
|
+
if (typeof matchMedia === "undefined") {
|
|
477
|
+
once();
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
const query = matchMedia(strategy.query);
|
|
481
|
+
if (query.matches) {
|
|
482
|
+
once();
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
const onChange = (e) => {
|
|
486
|
+
if (!e.matches) return;
|
|
487
|
+
query.removeEventListener("change", onChange);
|
|
488
|
+
once();
|
|
489
|
+
};
|
|
490
|
+
query.addEventListener("change", onChange);
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
/* c8 ignore next 3 */
|
|
494
|
+
default:
|
|
495
|
+
once();
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// src/lib/render/await.ts
|
|
500
|
+
var import_signal5 = require("@fluixi/reactive/signal");
|
|
501
|
+
function Await(props) {
|
|
502
|
+
const fetcher = () => {
|
|
503
|
+
const v = props.value;
|
|
504
|
+
return typeof v === "function" ? v() : v;
|
|
505
|
+
};
|
|
506
|
+
const [data] = (0, import_signal5.createResource)(fetcher);
|
|
507
|
+
return () => {
|
|
508
|
+
if (data.loading) return props.fallback;
|
|
509
|
+
const child = props.children;
|
|
510
|
+
return typeof child === "function" ? child(data()) : child;
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// src/lib/render/index.ts
|
|
515
|
+
function render(code, container, options = {}) {
|
|
516
|
+
(0, import_dom9.delegateEvents)(["click", "input", "change", "submit"]);
|
|
517
|
+
if ((0, import_dom8.isServer)()) {
|
|
518
|
+
throw new Error(
|
|
519
|
+
"render() is for client-side only. Use renderToString() on server."
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
if (!container) {
|
|
523
|
+
throw new Error("Container element is required");
|
|
524
|
+
}
|
|
525
|
+
let disposer;
|
|
526
|
+
(0, import_signal6.createRoot)((dispose) => {
|
|
527
|
+
disposer = dispose;
|
|
528
|
+
const result = typeof code === "function" ? code() : code;
|
|
529
|
+
container.textContent = "";
|
|
530
|
+
(0, import_dom2.stampVersions)(container);
|
|
531
|
+
(0, import_dom2.warnOnVersionSkew)();
|
|
532
|
+
(0, import_dom9.insert)(container, () => result);
|
|
533
|
+
});
|
|
534
|
+
return () => {
|
|
535
|
+
if (disposer) {
|
|
536
|
+
disposer();
|
|
537
|
+
disposer = void 0;
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
function isLitTemplateResult(value) {
|
|
542
|
+
return value && typeof value === "object" && (value["_$litType$"] !== void 0 || value["_$litDirective$"] !== void 0);
|
|
543
|
+
}
|
|
544
|
+
function portal(code, target, options = {}) {
|
|
545
|
+
const container = document.createElement("div");
|
|
546
|
+
container.setAttribute("data-portal", "true");
|
|
547
|
+
target.appendChild(container);
|
|
548
|
+
const dispose = render(code, container, options);
|
|
549
|
+
return () => {
|
|
550
|
+
dispose();
|
|
551
|
+
if (target.contains(container)) {
|
|
552
|
+
target.removeChild(container);
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
function isRenderable(value) {
|
|
557
|
+
if (value == null) return true;
|
|
558
|
+
if (typeof value === "function") return true;
|
|
559
|
+
if ((0, import_dom9.isDOMNode)(value)) return true;
|
|
560
|
+
if (isLitTemplateResult(value)) return true;
|
|
561
|
+
if (Array.isArray(value)) return true;
|
|
562
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
563
|
+
return true;
|
|
564
|
+
}
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
function initDelegation() {
|
|
568
|
+
if ((0, import_dom8.isServer)()) return;
|
|
569
|
+
(0, import_dom9.delegateEvents)(["click", "input", "change", "submit"]);
|
|
570
|
+
}
|
|
571
|
+
function cleanupDelegation() {
|
|
572
|
+
if ((0, import_dom8.isServer)()) return;
|
|
573
|
+
}
|
|
@@ -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:
|
|
@@ -28,17 +27,12 @@ export interface RenderOptions {
|
|
|
28
27
|
/**
|
|
29
28
|
* Render a component into a DOM element
|
|
30
29
|
*
|
|
31
|
-
*
|
|
30
|
+
* On the client:
|
|
32
31
|
* - Real DOM (no Virtual DOM)
|
|
33
32
|
* - Fine-grained mutation (no reconciliation)
|
|
34
33
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* @param {() => any} code - Component or function to render
|
|
39
|
-
* @param {HTMLElement} container - Target DOM element
|
|
40
|
-
* @param {RenderOptions} options - Render options
|
|
41
|
-
* @returns {() => void} Dispose function
|
|
34
|
+
* Component executes once during render
|
|
35
|
+
* Creates reactive owner (root)
|
|
42
36
|
*
|
|
43
37
|
* @example
|
|
44
38
|
* ```typescript
|
|
@@ -57,11 +51,6 @@ export declare function render(code: () => any, container: HTMLElement, options?
|
|
|
57
51
|
/**
|
|
58
52
|
* Render into a different part of the DOM tree
|
|
59
53
|
*
|
|
60
|
-
* @param {() => any} code - Component to render
|
|
61
|
-
* @param {HTMLElement} target - Target element (outside current tree)
|
|
62
|
-
* @param {RenderOptions} options - Render options
|
|
63
|
-
* @returns {() => void} Dispose function
|
|
64
|
-
*
|
|
65
54
|
* @example
|
|
66
55
|
* ```typescript
|
|
67
56
|
* import { portal } from '@fluixi/core';
|
|
@@ -77,9 +66,6 @@ export declare function render(code: () => any, container: HTMLElement, options?
|
|
|
77
66
|
export declare function portal(code: () => any, target: HTMLElement, options?: RenderOptions): () => void;
|
|
78
67
|
/**
|
|
79
68
|
* Check if a value can be rendered
|
|
80
|
-
*
|
|
81
|
-
* @param {any} value - Value to check
|
|
82
|
-
* @returns {boolean} True if renderable
|
|
83
69
|
*/
|
|
84
70
|
export declare function isRenderable(value: any): boolean;
|
|
85
71
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/render/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/render/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAoBH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,MAAM,CAAC,EAAE,IAAI,CAAC;IAEd;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAMD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,MAAM,CACpB,IAAI,EAAE,MAAM,GAAG,EACf,SAAS,EAAE,WAAW,EACtB,OAAO,GAAE,aAAkB,GAC1B,MAAM,IAAI,CA8CZ;AAmBD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CACpB,IAAI,EAAE,MAAM,GAAG,EACf,MAAM,EAAE,WAAW,EACnB,OAAO,GAAE,aAAkB,GAC1B,MAAM,IAAI,CAaZ;AAMD;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAchD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAGrC;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAGxC;AAOD,OAAO,EACL,eAAe,EACf,OAAO,EACP,SAAS,EACT,SAAS,EACT,MAAM,EACN,UAAU,EACV,OAAO,EACP,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,KAAK,EACL,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,KAAK,EACL,OAAO,EACP,GAAG,EACH,eAAe,EACf,UAAU,GACX,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,QAAQ,EACR,YAAY,EAEZ,KAAK,aAAa,EAClB,KAAK,iBAAiB,EAEtB,MAAM,EACN,WAAW,EACX,SAAS,EACT,YAAY,GACb,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAC9B,YAAY,EAAC,WAAW,EAAE,aAAa,EAAC,MAAM,WAAW,CAAA;AACzD,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAA;AACtC,YAAY,EAAC,eAAe,EAAE,YAAY,EAAC,MAAM,eAAe,CAAA;AAEhE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,YAAY,EACV,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,SAAS,GACV,MAAM,gBAAgB,CAAC"}
|