@fluixi/core 1.0.0-alpha.83 → 1.0.0-alpha.85
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-MDJLC3PE.mjs +830 -0
- package/dist/src/cdn/core.cjs +1365 -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-JYFZP3EZ.mjs +70 -0
- package/dist/src/index.cjs +1280 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -11
- package/dist/src/index.mjs +1393 -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-7IUN2FLI.mjs +133 -0
- package/dist/src/lib/client/index.cjs +956 -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-NOFEMOEH.mjs +631 -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 +1279 -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 +1393 -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 +709 -1
- package/dist/src/lib/router/index.d.ts +78 -23
- package/dist/src/lib/router/index.d.ts.map +1 -1
- package/dist/src/lib/router/index.js +161 -37
- package/dist/src/lib/router/index.mjs +722 -1
- package/dist/src/lib/router/transition.cjs +75 -0
- package/dist/src/lib/router/transition.d.ts +81 -0
- package/dist/src/lib/router/transition.d.ts.map +1 -0
- package/dist/src/lib/router/transition.js +136 -0
- package/dist/src/lib/router/transition.mjs +54 -0
- 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,221 @@
|
|
|
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/component.ts
|
|
21
|
+
var component_exports = {};
|
|
22
|
+
__export(component_exports, {
|
|
23
|
+
$component: () => $component,
|
|
24
|
+
DEV: () => DEV,
|
|
25
|
+
batch: () => import_signal.batch,
|
|
26
|
+
createComponent: () => createComponent,
|
|
27
|
+
createEffect: () => import_signal.createEffect,
|
|
28
|
+
createMemo: () => import_signal.createMemo,
|
|
29
|
+
devOnly: () => devOnly,
|
|
30
|
+
ensureIntegration: () => ensureIntegration,
|
|
31
|
+
getContextOwner: () => getContextOwner,
|
|
32
|
+
getOwner: () => import_signal.getOwner,
|
|
33
|
+
getSharedConfig: () => getSharedConfig,
|
|
34
|
+
hasLifecycleContext: () => hasLifecycleContext,
|
|
35
|
+
isDev: () => isDev,
|
|
36
|
+
onCleanup: () => import_signal.onCleanup,
|
|
37
|
+
onMount: () => onMount,
|
|
38
|
+
onUnmount: () => onUnmount,
|
|
39
|
+
runWithOwner: () => import_signal.runWithOwner,
|
|
40
|
+
setOwner: () => setOwner,
|
|
41
|
+
useCallback: () => useCallback,
|
|
42
|
+
useEffect: () => useEffect,
|
|
43
|
+
useEventListener: () => useEventListener,
|
|
44
|
+
useMemo: () => useMemo,
|
|
45
|
+
useReducer: () => useReducer,
|
|
46
|
+
useRef: () => useRef
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(component_exports);
|
|
49
|
+
var import_dom = require("@fluixi/dom");
|
|
50
|
+
var import_dom2 = require("@fluixi/dom");
|
|
51
|
+
var import_signal = require("@fluixi/reactive/signal");
|
|
52
|
+
var sharedConfig = {
|
|
53
|
+
context: null,
|
|
54
|
+
owner: null
|
|
55
|
+
};
|
|
56
|
+
function getSharedConfig() {
|
|
57
|
+
return sharedConfig;
|
|
58
|
+
}
|
|
59
|
+
function setOwner(owner) {
|
|
60
|
+
sharedConfig.owner = owner;
|
|
61
|
+
sharedConfig.context = owner;
|
|
62
|
+
}
|
|
63
|
+
function getContextOwner() {
|
|
64
|
+
return sharedConfig.context || sharedConfig.owner;
|
|
65
|
+
}
|
|
66
|
+
var DEV = typeof process !== "undefined" && false;
|
|
67
|
+
var _LIFECYCLE = /* @__PURE__ */ Symbol.for("fluixi-lifecycle");
|
|
68
|
+
function getOwnerLifecycle() {
|
|
69
|
+
const owner = (0, import_signal.getOwner)();
|
|
70
|
+
if (!owner) return null;
|
|
71
|
+
if (!owner[_LIFECYCLE]) {
|
|
72
|
+
const lc = { mounts: [], effects: [], scheduled: false };
|
|
73
|
+
owner[_LIFECYCLE] = lc;
|
|
74
|
+
}
|
|
75
|
+
return owner[_LIFECYCLE];
|
|
76
|
+
}
|
|
77
|
+
function scheduleLifecycleFlush(lc) {
|
|
78
|
+
if (lc.scheduled) return;
|
|
79
|
+
if ((0, import_dom.isServer)()) {
|
|
80
|
+
lc.mounts = [];
|
|
81
|
+
lc.effects = [];
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
lc.scheduled = true;
|
|
85
|
+
const owner = (0, import_signal.getOwner)();
|
|
86
|
+
queueMicrotask(() => {
|
|
87
|
+
if ((0, import_signal.isOwnerDisposed)(owner)) {
|
|
88
|
+
lc.mounts = [];
|
|
89
|
+
lc.effects = [];
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
(0, import_signal.runWithOwner)(owner, () => {
|
|
93
|
+
for (const cb of lc.mounts) {
|
|
94
|
+
try {
|
|
95
|
+
const cleanup = cb();
|
|
96
|
+
if (typeof cleanup === "function") {
|
|
97
|
+
(0, import_signal.onCleanup)(cleanup);
|
|
98
|
+
}
|
|
99
|
+
} catch (e) {
|
|
100
|
+
console.error("Error in onMount callback:", e);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
for (const cb of lc.effects) {
|
|
104
|
+
let cleanup;
|
|
105
|
+
(0, import_signal.createEffect)(() => {
|
|
106
|
+
if (cleanup) cleanup();
|
|
107
|
+
cleanup = cb();
|
|
108
|
+
});
|
|
109
|
+
(0, import_signal.onCleanup)(() => {
|
|
110
|
+
if (cleanup) cleanup();
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
lc.mounts = [];
|
|
114
|
+
lc.effects = [];
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function ensureIntegration(_from) {
|
|
119
|
+
}
|
|
120
|
+
function createComponent(Comp, props) {
|
|
121
|
+
return (0, import_dom2.createComponent)(Comp, props);
|
|
122
|
+
}
|
|
123
|
+
function $component(value, props) {
|
|
124
|
+
const component = typeof value === "function" ? (0, import_signal.untrack)(() => value(props)) : value;
|
|
125
|
+
const nameable = component != null && (typeof component === "function" || typeof component === "object");
|
|
126
|
+
if (nameable) {
|
|
127
|
+
try {
|
|
128
|
+
component["$name"] = value.name;
|
|
129
|
+
} catch {
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (nameable && !(0, import_signal.isSignal)(component)) {
|
|
133
|
+
return (0, import_dom2.asComponent)(component);
|
|
134
|
+
}
|
|
135
|
+
return component;
|
|
136
|
+
}
|
|
137
|
+
function onMount(fn, reactive = true) {
|
|
138
|
+
if ((0, import_dom.isServer)()) return;
|
|
139
|
+
const lc = getOwnerLifecycle();
|
|
140
|
+
if (lc) {
|
|
141
|
+
if (!reactive) {
|
|
142
|
+
if (!lc.scheduled) {
|
|
143
|
+
fn();
|
|
144
|
+
}
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
lc.mounts.push(fn);
|
|
148
|
+
scheduleLifecycleFlush(lc);
|
|
149
|
+
} else {
|
|
150
|
+
if (!reactive) {
|
|
151
|
+
fn();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
(0, import_signal.createEffect)(() => {
|
|
155
|
+
const cleanup = (0, import_signal.untrack)(fn);
|
|
156
|
+
if (typeof cleanup === "function") {
|
|
157
|
+
(0, import_signal.onCleanup)(cleanup);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function onUnmount(fn) {
|
|
163
|
+
(0, import_signal.onCleanup)(fn);
|
|
164
|
+
}
|
|
165
|
+
function useEffect(callback) {
|
|
166
|
+
const lc = getOwnerLifecycle();
|
|
167
|
+
if (lc) {
|
|
168
|
+
lc.effects.push(callback);
|
|
169
|
+
scheduleLifecycleFlush(lc);
|
|
170
|
+
} else {
|
|
171
|
+
let cleanup;
|
|
172
|
+
(0, import_signal.createEffect)(() => {
|
|
173
|
+
if (cleanup) cleanup();
|
|
174
|
+
cleanup = callback();
|
|
175
|
+
});
|
|
176
|
+
(0, import_signal.onCleanup)(() => {
|
|
177
|
+
if (cleanup) cleanup();
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function useMemo(fn) {
|
|
182
|
+
return (0, import_signal.createMemo)(fn);
|
|
183
|
+
}
|
|
184
|
+
function useRef(initialValue) {
|
|
185
|
+
const ref = { current: initialValue };
|
|
186
|
+
(0, import_signal.onCleanup)(() => {
|
|
187
|
+
ref.current = null;
|
|
188
|
+
});
|
|
189
|
+
return ref;
|
|
190
|
+
}
|
|
191
|
+
function useReducer(reducer, initialState) {
|
|
192
|
+
const [state, setState] = (0, import_signal.createSignal)(initialState);
|
|
193
|
+
const dispatch = (action) => {
|
|
194
|
+
setState(reducer(state(), action));
|
|
195
|
+
};
|
|
196
|
+
return [state, dispatch];
|
|
197
|
+
}
|
|
198
|
+
function useEventListener(target, event, handler, options) {
|
|
199
|
+
useEffect(() => {
|
|
200
|
+
const element = target && "current" in target ? target.current : target;
|
|
201
|
+
if (!element) return;
|
|
202
|
+
element.addEventListener(event, handler, options);
|
|
203
|
+
return () => {
|
|
204
|
+
element.removeEventListener(event, handler, options);
|
|
205
|
+
};
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
function useCallback(callback) {
|
|
209
|
+
return callback;
|
|
210
|
+
}
|
|
211
|
+
function hasLifecycleContext() {
|
|
212
|
+
return (0, import_signal.getOwner)() !== null;
|
|
213
|
+
}
|
|
214
|
+
function isDev() {
|
|
215
|
+
return DEV;
|
|
216
|
+
}
|
|
217
|
+
function devOnly(fn) {
|
|
218
|
+
if (DEV) {
|
|
219
|
+
fn();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Component creation for Fluixi. Component-creation logic only
|
|
2
|
+
* Component creation for Fluixi. Component-creation logic only: context lives in
|
|
3
3
|
* the reactive system, rendering in render/index.ts, and SSR in server/.
|
|
4
4
|
*/
|
|
5
5
|
import { CreateComponentReturnType } from '@fluixi/dom';
|
|
@@ -43,7 +43,7 @@ export interface RefObject<T> {
|
|
|
43
43
|
* The runtime creates components itself now, so nothing has to be registered for
|
|
44
44
|
* it to work and this does nothing. It stays because callers exist, and because
|
|
45
45
|
* `registerCreateComponent` is still the way to install a different component
|
|
46
|
-
* model
|
|
46
|
+
* model: pass your own implementation there and the runtime uses it instead.
|
|
47
47
|
*
|
|
48
48
|
* Do not register a function that calls the runtime's own `createComponent`: it
|
|
49
49
|
* consults the slot first, so that recurses.
|
|
@@ -54,11 +54,6 @@ export declare function ensureIntegration(_from?: string): void;
|
|
|
54
54
|
* captures its output, keeps children lazy, propagates context (via sharedConfig), and
|
|
55
55
|
* attaches cleanup. Components execute once and never re-execute.
|
|
56
56
|
*
|
|
57
|
-
* @template P - Props type
|
|
58
|
-
* @param {Component<P>} Comp - Component function
|
|
59
|
-
* @param {P} props - Component props
|
|
60
|
-
* @returns {any} Component output
|
|
61
|
-
*
|
|
62
57
|
* @example
|
|
63
58
|
* ```typescript
|
|
64
59
|
* const MyComponent = (props: { name: string }) => {
|
|
@@ -77,8 +72,6 @@ export declare function $component<T extends (props?: any) => any, U = any>(valu
|
|
|
77
72
|
* The effect runs once after the reactive graph is established,
|
|
78
73
|
* tied to the current Owner for automatic cleanup.
|
|
79
74
|
*
|
|
80
|
-
* @param {LifecycleCallback} fn - Mount callback
|
|
81
|
-
*
|
|
82
75
|
* @example
|
|
83
76
|
* ```typescript
|
|
84
77
|
* const MyComponent = () => {
|
|
@@ -98,8 +91,6 @@ export declare function onMount(fn: LifecycleCallback, reactive?: boolean): void
|
|
|
98
91
|
* SolidJS-aligned: directly delegates to onCleanup which registers
|
|
99
92
|
* with the current reactive Owner for automatic disposal.
|
|
100
93
|
*
|
|
101
|
-
* @param {() => void} fn - Unmount callback
|
|
102
|
-
*
|
|
103
94
|
* @example
|
|
104
95
|
* ```typescript
|
|
105
96
|
* const MyComponent = () => {
|
|
@@ -115,9 +106,7 @@ export declare function onUnmount(fn: () => void): void;
|
|
|
115
106
|
/**
|
|
116
107
|
* Register a cleanup function
|
|
117
108
|
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* @param {() => void} fn - Cleanup function
|
|
109
|
+
* Component constructs reactive graph including cleanup
|
|
121
110
|
*
|
|
122
111
|
* @example
|
|
123
112
|
* ```typescript
|
|
@@ -137,8 +126,6 @@ export { onCleanup };
|
|
|
137
126
|
* Effects run when their dependencies change
|
|
138
127
|
* On server, effects run once
|
|
139
128
|
*
|
|
140
|
-
* @param {(v?: any) => any} fn - Effect function
|
|
141
|
-
*
|
|
142
129
|
* @example
|
|
143
130
|
* ```typescript
|
|
144
131
|
* const MyComponent = () => {
|
|
@@ -156,10 +143,6 @@ export declare function useEffect(callback: () => void | (() => void)): void;
|
|
|
156
143
|
/**
|
|
157
144
|
* Create a memoized computed value
|
|
158
145
|
*
|
|
159
|
-
* @template T
|
|
160
|
-
* @param {() => T} fn - Computation function
|
|
161
|
-
* @returns {() => T} Memoized accessor
|
|
162
|
-
*
|
|
163
146
|
* @example
|
|
164
147
|
* ```typescript
|
|
165
148
|
* const MyComponent = () => {
|
|
@@ -177,10 +160,6 @@ export declare function useMemo<T>(fn: () => T): () => T;
|
|
|
177
160
|
* Refs persist across component re-renders (though components only run once)
|
|
178
161
|
* Useful for storing DOM references and mutable values
|
|
179
162
|
*
|
|
180
|
-
* @template T
|
|
181
|
-
* @param {T} initialValue - Initial value
|
|
182
|
-
* @returns {RefObject<T>} Ref object
|
|
183
|
-
*
|
|
184
163
|
* @example
|
|
185
164
|
* ```typescript
|
|
186
165
|
* const MyComponent = () => {
|
|
@@ -198,12 +177,6 @@ export declare function useRef<T>(initialValue: T): RefObject<T>;
|
|
|
198
177
|
/**
|
|
199
178
|
* Create a reducer for state management
|
|
200
179
|
*
|
|
201
|
-
* @template S - State type
|
|
202
|
-
* @template A - Action type
|
|
203
|
-
* @param {(state: S, action: A) => S} reducer - Reducer function
|
|
204
|
-
* @param {S} initialState - Initial state
|
|
205
|
-
* @returns {[() => S, (action: A) => void]} State accessor and dispatch function
|
|
206
|
-
*
|
|
207
180
|
* @example
|
|
208
181
|
* ```typescript
|
|
209
182
|
* type Action = { type: 'increment' } | { type: 'decrement' };
|
|
@@ -231,12 +204,6 @@ export declare function useReducer<S, A>(reducer: (state: S, action: A) => S, in
|
|
|
231
204
|
/**
|
|
232
205
|
* Attach an event listener with automatic cleanup
|
|
233
206
|
*
|
|
234
|
-
* @template K - Event type key
|
|
235
|
-
* @param {EventTarget | RefObject<EventTarget | null>} target - Event target or ref
|
|
236
|
-
* @param {K} event - Event name
|
|
237
|
-
* @param {(event: Event) => void} handler - Event handler
|
|
238
|
-
* @param {AddEventListenerOptions} options - Event listener options
|
|
239
|
-
*
|
|
240
207
|
* @example
|
|
241
208
|
* ```typescript
|
|
242
209
|
* const MyComponent = () => {
|
|
@@ -261,10 +228,6 @@ export declare function useEventListener<K extends keyof WindowEventMap>(target:
|
|
|
261
228
|
* In Fluixi, components only run once, so this is mostly for
|
|
262
229
|
* API compatibility and explicit intent
|
|
263
230
|
*
|
|
264
|
-
* @template T
|
|
265
|
-
* @param {T} callback - Callback function
|
|
266
|
-
* @returns {T} Callback function
|
|
267
|
-
*
|
|
268
231
|
* @example
|
|
269
232
|
* ```typescript
|
|
270
233
|
* const MyComponent = () => {
|
|
@@ -310,8 +273,6 @@ export declare function hasLifecycleContext(): boolean;
|
|
|
310
273
|
/**
|
|
311
274
|
* Check if in development mode
|
|
312
275
|
*
|
|
313
|
-
* @returns {boolean} True if in development mode
|
|
314
|
-
*
|
|
315
276
|
* @example
|
|
316
277
|
* ```typescript
|
|
317
278
|
* if (isDev()) {
|
|
@@ -323,8 +284,6 @@ export declare function isDev(): boolean;
|
|
|
323
284
|
/**
|
|
324
285
|
* Development-only code execution
|
|
325
286
|
*
|
|
326
|
-
* @param {() => void} fn - Function to run in dev mode
|
|
327
|
-
*
|
|
328
287
|
* @example
|
|
329
288
|
* ```typescript
|
|
330
289
|
* devOnly(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../../src/lib/render/component.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAIL,yBAAyB,EAC1B,MAAM,aAAa,CAAC;AACrB,OAAO,EAEL,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,UAAU,EAGV,KAAK,EAEL,YAAY,EASb,MAAM,yBAAyB,CAAC;AAKjC,KAAK,KAAK,GAAG,GAAG,CAAC;AAMjB,UAAU,YAAY;IACpB,OAAO,EAAE,KAAK,GAAG,IAAI,CAAC;IACtB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAOD;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAE9C;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,CAGlD;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,KAAK,GAAG,IAAI,CAE9C;AAMD;;GAEG;AACH,eAAO,MAAM,GAAG,SAC2D,CAAC;AAM5E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
|
2
|
+
* Component creation for Fluixi. Component-creation logic only: context lives in
|
|
3
3
|
* the reactive system, rendering in render/index.ts, and SSR in server/.
|
|
4
4
|
*/
|
|
5
5
|
import { isServer } from '@fluixi/dom';
|
|
@@ -48,7 +48,7 @@ export const DEV = typeof process !== 'undefined' && process.env?.NODE_ENV === '
|
|
|
48
48
|
// 1. All onMount callbacks run first
|
|
49
49
|
// 2. Then all useEffect callbacks are created as reactive effects
|
|
50
50
|
// This works regardless of whether the component goes through $component,
|
|
51
|
-
// the JSX runtime, or is called directly
|
|
51
|
+
// the JSX runtime, or is called directly, as long as there's an Owner.
|
|
52
52
|
const _LIFECYCLE = Symbol.for('fluixi-lifecycle');
|
|
53
53
|
/**
|
|
54
54
|
* Get or create a lifecycle bucket on the current Owner.
|
|
@@ -66,7 +66,7 @@ function getOwnerLifecycle() {
|
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
68
|
* Schedule a microtask to flush the lifecycle for the current Owner.
|
|
69
|
-
* Only schedules once per Owner
|
|
69
|
+
* Only schedules once per Owner: subsequent calls are no-ops.
|
|
70
70
|
*/
|
|
71
71
|
function scheduleLifecycleFlush(lc) {
|
|
72
72
|
if (lc.scheduled)
|
|
@@ -84,7 +84,7 @@ function scheduleLifecycleFlush(lc) {
|
|
|
84
84
|
queueMicrotask(() => {
|
|
85
85
|
// The scope may have been torn down before this microtask ran (e.g. a <Portal>
|
|
86
86
|
// inside a <Show> that closed synchronously). Running mount/effect callbacks on a
|
|
87
|
-
// dead owner would re-attach listeners/effects whose cleanup never fires
|
|
87
|
+
// dead owner would re-attach listeners/effects whose cleanup never fires, a leak.
|
|
88
88
|
// Match Solid: an unmounted component's onMount simply does not run.
|
|
89
89
|
if (isOwnerDisposed(owner)) {
|
|
90
90
|
lc.mounts = [];
|
|
@@ -127,7 +127,7 @@ function scheduleLifecycleFlush(lc) {
|
|
|
127
127
|
* The runtime creates components itself now, so nothing has to be registered for
|
|
128
128
|
* it to work and this does nothing. It stays because callers exist, and because
|
|
129
129
|
* `registerCreateComponent` is still the way to install a different component
|
|
130
|
-
* model
|
|
130
|
+
* model: pass your own implementation there and the runtime uses it instead.
|
|
131
131
|
*
|
|
132
132
|
* Do not register a function that calls the runtime's own `createComponent`: it
|
|
133
133
|
* consults the slot first, so that recurses.
|
|
@@ -138,11 +138,6 @@ export function ensureIntegration(_from) { }
|
|
|
138
138
|
* captures its output, keeps children lazy, propagates context (via sharedConfig), and
|
|
139
139
|
* attaches cleanup. Components execute once and never re-execute.
|
|
140
140
|
*
|
|
141
|
-
* @template P - Props type
|
|
142
|
-
* @param {Component<P>} Comp - Component function
|
|
143
|
-
* @param {P} props - Component props
|
|
144
|
-
* @returns {any} Component output
|
|
145
|
-
*
|
|
146
141
|
* @example
|
|
147
142
|
* ```typescript
|
|
148
143
|
* const MyComponent = (props: { name: string }) => {
|
|
@@ -152,17 +147,6 @@ export function ensureIntegration(_from) { }
|
|
|
152
147
|
* const result = createComponent(MyComponent, { name: 'World' });
|
|
153
148
|
* ```
|
|
154
149
|
*/
|
|
155
|
-
// export function $component<T, U = any>(value: T, props?: U) {
|
|
156
|
-
// const component = () => (typeof value === 'function' && props) ?(value as any)(props) : value;
|
|
157
|
-
// Object.defineProperty(component, '__fluixi', {
|
|
158
|
-
// enumerable: true,
|
|
159
|
-
// configurable: true,
|
|
160
|
-
// value: true,
|
|
161
|
-
// });
|
|
162
|
-
// // (component as any).$COMPONENT = true;
|
|
163
|
-
// return asComponent(component) as C<T, U>;
|
|
164
|
-
// }
|
|
165
|
-
//
|
|
166
150
|
export function createComponent(Comp, props) {
|
|
167
151
|
return domCreateComponent(Comp, props);
|
|
168
152
|
}
|
|
@@ -180,7 +164,7 @@ export function $component(value, props) {
|
|
|
180
164
|
const component = (typeof value === 'function')
|
|
181
165
|
? untrack(() => value(props))
|
|
182
166
|
: value;
|
|
183
|
-
// Only stamp $name and $COMPONENT on functions/objects
|
|
167
|
+
// Only stamp $name and $COMPONENT on functions/objects: primitives (strings, numbers)
|
|
184
168
|
// cannot have properties added in strict mode and would throw TypeError.
|
|
185
169
|
// Also skip stamping reactive values (signals/memos) with $COMPONENT so the DOM
|
|
186
170
|
// runtime doesn't misidentify them as static component thunks and cache them.
|
|
@@ -210,8 +194,6 @@ export function $component(value, props) {
|
|
|
210
194
|
* The effect runs once after the reactive graph is established,
|
|
211
195
|
* tied to the current Owner for automatic cleanup.
|
|
212
196
|
*
|
|
213
|
-
* @param {LifecycleCallback} fn - Mount callback
|
|
214
|
-
*
|
|
215
197
|
* @example
|
|
216
198
|
* ```typescript
|
|
217
199
|
* const MyComponent = () => {
|
|
@@ -235,7 +217,7 @@ export function onMount(fn, reactive = true) {
|
|
|
235
217
|
}
|
|
236
218
|
return;
|
|
237
219
|
}
|
|
238
|
-
// Attach to Owner
|
|
220
|
+
// Attach to Owner: will run before useEffect callbacks in the flush.
|
|
239
221
|
lc.mounts.push(fn);
|
|
240
222
|
scheduleLifecycleFlush(lc);
|
|
241
223
|
}
|
|
@@ -259,8 +241,6 @@ export function onMount(fn, reactive = true) {
|
|
|
259
241
|
* SolidJS-aligned: directly delegates to onCleanup which registers
|
|
260
242
|
* with the current reactive Owner for automatic disposal.
|
|
261
243
|
*
|
|
262
|
-
* @param {() => void} fn - Unmount callback
|
|
263
|
-
*
|
|
264
244
|
* @example
|
|
265
245
|
* ```typescript
|
|
266
246
|
* const MyComponent = () => {
|
|
@@ -278,9 +258,7 @@ export function onUnmount(fn) {
|
|
|
278
258
|
/**
|
|
279
259
|
* Register a cleanup function
|
|
280
260
|
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
* @param {() => void} fn - Cleanup function
|
|
261
|
+
* Component constructs reactive graph including cleanup
|
|
284
262
|
*
|
|
285
263
|
* @example
|
|
286
264
|
* ```typescript
|
|
@@ -303,8 +281,6 @@ export { onCleanup };
|
|
|
303
281
|
* Effects run when their dependencies change
|
|
304
282
|
* On server, effects run once
|
|
305
283
|
*
|
|
306
|
-
* @param {(v?: any) => any} fn - Effect function
|
|
307
|
-
*
|
|
308
284
|
* @example
|
|
309
285
|
* ```typescript
|
|
310
286
|
* const MyComponent = () => {
|
|
@@ -321,7 +297,7 @@ export { onCleanup };
|
|
|
321
297
|
export function useEffect(callback) {
|
|
322
298
|
const lc = getOwnerLifecycle();
|
|
323
299
|
if (lc) {
|
|
324
|
-
// Attach to the Owner
|
|
300
|
+
// Attach to the Owner: created as an effect after all onMount callbacks.
|
|
325
301
|
lc.effects.push(callback);
|
|
326
302
|
scheduleLifecycleFlush(lc);
|
|
327
303
|
}
|
|
@@ -342,10 +318,6 @@ export function useEffect(callback) {
|
|
|
342
318
|
/**
|
|
343
319
|
* Create a memoized computed value
|
|
344
320
|
*
|
|
345
|
-
* @template T
|
|
346
|
-
* @param {() => T} fn - Computation function
|
|
347
|
-
* @returns {() => T} Memoized accessor
|
|
348
|
-
*
|
|
349
321
|
* @example
|
|
350
322
|
* ```typescript
|
|
351
323
|
* const MyComponent = () => {
|
|
@@ -367,10 +339,6 @@ export function useMemo(fn) {
|
|
|
367
339
|
* Refs persist across component re-renders (though components only run once)
|
|
368
340
|
* Useful for storing DOM references and mutable values
|
|
369
341
|
*
|
|
370
|
-
* @template T
|
|
371
|
-
* @param {T} initialValue - Initial value
|
|
372
|
-
* @returns {RefObject<T>} Ref object
|
|
373
|
-
*
|
|
374
342
|
* @example
|
|
375
343
|
* ```typescript
|
|
376
344
|
* const MyComponent = () => {
|
|
@@ -395,12 +363,6 @@ export function useRef(initialValue) {
|
|
|
395
363
|
/**
|
|
396
364
|
* Create a reducer for state management
|
|
397
365
|
*
|
|
398
|
-
* @template S - State type
|
|
399
|
-
* @template A - Action type
|
|
400
|
-
* @param {(state: S, action: A) => S} reducer - Reducer function
|
|
401
|
-
* @param {S} initialState - Initial state
|
|
402
|
-
* @returns {[() => S, (action: A) => void]} State accessor and dispatch function
|
|
403
|
-
*
|
|
404
366
|
* @example
|
|
405
367
|
* ```typescript
|
|
406
368
|
* type Action = { type: 'increment' } | { type: 'decrement' };
|
|
@@ -431,6 +393,20 @@ export function useReducer(reducer, initialState) {
|
|
|
431
393
|
};
|
|
432
394
|
return [state, dispatch];
|
|
433
395
|
}
|
|
396
|
+
/**
|
|
397
|
+
* Attach a listener for as long as the current owner lives.
|
|
398
|
+
*
|
|
399
|
+
* Runs through `useEffect`, so the removal it returns is called on disposal and before
|
|
400
|
+
* any re-run. Nothing has to be undone by hand. `target` may be a ref, read when the
|
|
401
|
+
* listener is attached rather than when this is called, so it works for an element the
|
|
402
|
+
* template has not created yet.
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```ts
|
|
406
|
+
* useEventListener(window, 'resize', () => setWidth(window.innerWidth));
|
|
407
|
+
* useEventListener(dialogRef, 'keydown', onKey, { capture: true });
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
434
410
|
export function useEventListener(target, event, handler, options) {
|
|
435
411
|
useEffect(() => {
|
|
436
412
|
// Resolve target from ref or direct value
|
|
@@ -453,10 +429,6 @@ export function useEventListener(target, event, handler, options) {
|
|
|
453
429
|
* In Fluixi, components only run once, so this is mostly for
|
|
454
430
|
* API compatibility and explicit intent
|
|
455
431
|
*
|
|
456
|
-
* @template T
|
|
457
|
-
* @param {T} callback - Callback function
|
|
458
|
-
* @returns {T} Callback function
|
|
459
|
-
*
|
|
460
432
|
* @example
|
|
461
433
|
* ```typescript
|
|
462
434
|
* const MyComponent = () => {
|
|
@@ -514,8 +486,6 @@ export function hasLifecycleContext() {
|
|
|
514
486
|
/**
|
|
515
487
|
* Check if in development mode
|
|
516
488
|
*
|
|
517
|
-
* @returns {boolean} True if in development mode
|
|
518
|
-
*
|
|
519
489
|
* @example
|
|
520
490
|
* ```typescript
|
|
521
491
|
* if (isDev()) {
|
|
@@ -530,8 +500,6 @@ export function isDev() {
|
|
|
530
500
|
/**
|
|
531
501
|
* Development-only code execution
|
|
532
502
|
*
|
|
533
|
-
* @param {() => void} fn - Function to run in dev mode
|
|
534
|
-
*
|
|
535
503
|
* @example
|
|
536
504
|
* ```typescript
|
|
537
505
|
* devOnly(() => {
|