@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,639 @@
|
|
|
1
|
-
|
|
1
|
+
/*! @fluixi/core v1.0.0-alpha.84 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
|
+
|
|
3
|
+
// src/lib/router/index.ts
|
|
4
|
+
import {
|
|
5
|
+
createSignal as createSignal2,
|
|
6
|
+
createMemo as createMemo2,
|
|
7
|
+
createResource as createResource3,
|
|
8
|
+
createEffect,
|
|
9
|
+
getOwner,
|
|
10
|
+
onCleanup,
|
|
11
|
+
untrack as untrack2
|
|
12
|
+
} from "@fluixi/reactive/signal";
|
|
13
|
+
import {
|
|
14
|
+
insert,
|
|
15
|
+
createComponent as createComponent2,
|
|
16
|
+
createNativeElement,
|
|
17
|
+
setAttribute
|
|
18
|
+
} from "@fluixi/dom";
|
|
19
|
+
import { createContext as createContext2, useContext as useContext2 } from "@fluixi/reactive/signal";
|
|
20
|
+
import { get } from "@fluixi/utils/object";
|
|
21
|
+
import { deepEqual } from "@fluixi/utils/compare";
|
|
22
|
+
import {
|
|
23
|
+
createRouter as createCoreRouter,
|
|
24
|
+
createBrowserHistory,
|
|
25
|
+
matchRoutes,
|
|
26
|
+
matchPath
|
|
27
|
+
} from "@fluixi/router";
|
|
28
|
+
import {
|
|
29
|
+
createMemoryHistory,
|
|
30
|
+
createBrowserHistory as createBrowserHistory2,
|
|
31
|
+
matchRoutes as matchRoutes2,
|
|
32
|
+
matchPath as matchPath2
|
|
33
|
+
} from "@fluixi/router";
|
|
34
|
+
|
|
35
|
+
// src/lib/router/data.ts
|
|
36
|
+
import {
|
|
37
|
+
createResource,
|
|
38
|
+
createSignal
|
|
39
|
+
} from "@fluixi/reactive/signal";
|
|
40
|
+
|
|
41
|
+
// src/lib/server/hydration.ts
|
|
42
|
+
import { isServer as domIsServer } from "@fluixi/dom";
|
|
43
|
+
var hydrating = false;
|
|
44
|
+
var hydrationDataMap = /* @__PURE__ */ new Map();
|
|
45
|
+
function isHydrating() {
|
|
46
|
+
return hydrating;
|
|
47
|
+
}
|
|
48
|
+
function setHydrationData(key, data) {
|
|
49
|
+
hydrationDataMap.set(key, data);
|
|
50
|
+
}
|
|
51
|
+
function getHydrationData(key) {
|
|
52
|
+
return hydrationDataMap.get(key);
|
|
53
|
+
}
|
|
54
|
+
function clearHydrationData() {
|
|
55
|
+
hydrationDataMap.clear();
|
|
56
|
+
}
|
|
57
|
+
function cleanupHydration() {
|
|
58
|
+
if (typeof window === "undefined") {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const script = document.getElementById("__FLUIXI_HYDRATION__");
|
|
62
|
+
if (script) {
|
|
63
|
+
script.remove();
|
|
64
|
+
}
|
|
65
|
+
const walker = document.createTreeWalker(
|
|
66
|
+
document.body,
|
|
67
|
+
NodeFilter.SHOW_COMMENT,
|
|
68
|
+
null
|
|
69
|
+
);
|
|
70
|
+
const comments = [];
|
|
71
|
+
let node;
|
|
72
|
+
while (node = walker.nextNode()) {
|
|
73
|
+
const comment = node;
|
|
74
|
+
const text = comment.nodeValue || "";
|
|
75
|
+
if (text.startsWith("#") || text.startsWith("/")) {
|
|
76
|
+
comments.push(comment);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
comments.forEach((comment) => comment.remove());
|
|
80
|
+
clearHydrationData();
|
|
81
|
+
}
|
|
82
|
+
if (typeof window !== "undefined") {
|
|
83
|
+
window.addEventListener("load", () => {
|
|
84
|
+
setTimeout(cleanupHydration, 100);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function isServerEnvironment() {
|
|
88
|
+
return domIsServer();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/lib/context/context.ts
|
|
92
|
+
import { asProvider } from "@fluixi/dom";
|
|
93
|
+
import { createContext as createReactiveContext, useContext as useReactiveContext } from "@fluixi/reactive/signal";
|
|
94
|
+
import {
|
|
95
|
+
readChildren
|
|
96
|
+
} from "@fluixi/reactive/signal";
|
|
97
|
+
function createContext(defaultValue, name) {
|
|
98
|
+
const context = createReactiveContext(defaultValue, name);
|
|
99
|
+
const Provider = (props) => {
|
|
100
|
+
if (props.debug === true) {
|
|
101
|
+
}
|
|
102
|
+
return context.Provider({
|
|
103
|
+
value: props.value,
|
|
104
|
+
get children() {
|
|
105
|
+
return props.children;
|
|
106
|
+
},
|
|
107
|
+
debug: props.debug
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
if (typeof Symbol !== "undefined" && Symbol.for) {
|
|
111
|
+
Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
|
|
112
|
+
}
|
|
113
|
+
Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
|
|
114
|
+
return {
|
|
115
|
+
id: context.id,
|
|
116
|
+
Provider: asProvider(Provider),
|
|
117
|
+
defaultValue
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/lib/router/data.ts
|
|
122
|
+
var globalCache = /* @__PURE__ */ new Map();
|
|
123
|
+
var inflightRequests = /* @__PURE__ */ new Map();
|
|
124
|
+
function cache(fn, name) {
|
|
125
|
+
return async (...args) => {
|
|
126
|
+
const key = name + ":" + JSON.stringify(args);
|
|
127
|
+
if (isHydrating() || typeof window !== "undefined") {
|
|
128
|
+
const hydrated = getHydrationData(key);
|
|
129
|
+
if (hydrated !== void 0) {
|
|
130
|
+
return hydrated;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (globalCache.has(key)) {
|
|
134
|
+
return globalCache.get(key);
|
|
135
|
+
}
|
|
136
|
+
if (inflightRequests.has(key)) {
|
|
137
|
+
return inflightRequests.get(key);
|
|
138
|
+
}
|
|
139
|
+
const promise = Promise.resolve(fn(...args)).then(
|
|
140
|
+
(val) => {
|
|
141
|
+
globalCache.set(key, val);
|
|
142
|
+
inflightRequests.delete(key);
|
|
143
|
+
if (isServerEnvironment()) {
|
|
144
|
+
setHydrationData(key, val);
|
|
145
|
+
}
|
|
146
|
+
return val;
|
|
147
|
+
},
|
|
148
|
+
(err) => {
|
|
149
|
+
inflightRequests.delete(key);
|
|
150
|
+
throw err;
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
inflightRequests.set(key, promise);
|
|
154
|
+
return promise;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
var [revalidationVersion, setRevalidationVersion] = createSignal(0);
|
|
158
|
+
var revalidationKeys = /* @__PURE__ */ new Set();
|
|
159
|
+
function revalidate(key) {
|
|
160
|
+
const predicate = typeof key === "string" ? (k) => k.startsWith(key) : key;
|
|
161
|
+
for (const k of globalCache.keys()) {
|
|
162
|
+
if (predicate(k)) {
|
|
163
|
+
globalCache.delete(k);
|
|
164
|
+
revalidationKeys.add(k);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
setRevalidationVersion((v) => v + 1);
|
|
168
|
+
}
|
|
169
|
+
function createAsync(fetcher, source) {
|
|
170
|
+
const [data] = createResource(source || (() => true), fetcher);
|
|
171
|
+
return data;
|
|
172
|
+
}
|
|
173
|
+
var submissionState = /* @__PURE__ */ new Map();
|
|
174
|
+
function getSubmissionSignal(url) {
|
|
175
|
+
if (!submissionState.has(url)) {
|
|
176
|
+
submissionState.set(
|
|
177
|
+
url,
|
|
178
|
+
createSignal(void 0)
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
return submissionState.get(url);
|
|
182
|
+
}
|
|
183
|
+
function action(fn, name) {
|
|
184
|
+
const actionUrl = name || fn.name || "action";
|
|
185
|
+
const submit = async (input) => {
|
|
186
|
+
const [, setSubmission] = getSubmissionSignal(actionUrl);
|
|
187
|
+
const clear = () => setSubmission(void 0);
|
|
188
|
+
const retry = () => submit(input);
|
|
189
|
+
setSubmission({
|
|
190
|
+
input,
|
|
191
|
+
// Approximate type for tracking
|
|
192
|
+
pending: true,
|
|
193
|
+
clear,
|
|
194
|
+
retry
|
|
195
|
+
});
|
|
196
|
+
try {
|
|
197
|
+
const result = await fn(input);
|
|
198
|
+
setSubmission({
|
|
199
|
+
input,
|
|
200
|
+
result,
|
|
201
|
+
pending: false,
|
|
202
|
+
clear,
|
|
203
|
+
retry
|
|
204
|
+
});
|
|
205
|
+
return result;
|
|
206
|
+
} catch (error) {
|
|
207
|
+
setSubmission({
|
|
208
|
+
input,
|
|
209
|
+
error,
|
|
210
|
+
pending: false,
|
|
211
|
+
clear,
|
|
212
|
+
retry
|
|
213
|
+
});
|
|
214
|
+
throw error;
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
submit.url = actionUrl;
|
|
218
|
+
submit.with = (args) => action((...a) => fn(args, ...a), name);
|
|
219
|
+
return submit;
|
|
220
|
+
}
|
|
221
|
+
function useSubmission(actionFn) {
|
|
222
|
+
const [submission] = getSubmissionSignal(actionFn.url);
|
|
223
|
+
return submission;
|
|
224
|
+
}
|
|
225
|
+
function useAction(actionFn) {
|
|
226
|
+
return actionFn;
|
|
227
|
+
}
|
|
228
|
+
var RouteDataContext = createContext(void 0, "route-data");
|
|
229
|
+
var RouteDataProvider = RouteDataContext.Provider;
|
|
230
|
+
|
|
231
|
+
// src/lib/render/lazy.ts
|
|
232
|
+
import { createComponent } from "@fluixi/dom";
|
|
233
|
+
import {
|
|
234
|
+
untrack,
|
|
235
|
+
createMemo,
|
|
236
|
+
createResource as createResource2
|
|
237
|
+
} from "@fluixi/reactive/signal";
|
|
238
|
+
function fromChunk(value) {
|
|
239
|
+
if (value != null && (typeof value === "object" || typeof value === "function")) {
|
|
240
|
+
try {
|
|
241
|
+
value["$lazy"] = true;
|
|
242
|
+
} catch {
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return value;
|
|
246
|
+
}
|
|
247
|
+
function lazy(loader, options) {
|
|
248
|
+
let resolved;
|
|
249
|
+
let promise;
|
|
250
|
+
let component;
|
|
251
|
+
function load() {
|
|
252
|
+
if (!promise) {
|
|
253
|
+
promise = loader().then((mod) => resolved = mod.default);
|
|
254
|
+
}
|
|
255
|
+
return promise;
|
|
256
|
+
}
|
|
257
|
+
if (options?.preload) load();
|
|
258
|
+
const LazyWrapper = ((props) => {
|
|
259
|
+
if (resolved) {
|
|
260
|
+
const C = resolved;
|
|
261
|
+
return fromChunk(untrack(() => C(props)));
|
|
262
|
+
}
|
|
263
|
+
if (!component) {
|
|
264
|
+
const [resource] = createResource2(() => load(), { transport: false });
|
|
265
|
+
component = resource;
|
|
266
|
+
if (resource.error) throw resource.error;
|
|
267
|
+
}
|
|
268
|
+
return createMemo(() => {
|
|
269
|
+
const C = component();
|
|
270
|
+
return C ? fromChunk(createComponent(C, props)) : void 0;
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
LazyWrapper.preload = () => load().then(() => void 0);
|
|
274
|
+
LazyWrapper.$lazy = true;
|
|
275
|
+
LazyWrapper.loader = loader;
|
|
276
|
+
return LazyWrapper;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// src/lib/router/index.ts
|
|
280
|
+
import { runWithOwner } from "@fluixi/reactive/signal";
|
|
281
|
+
var RouterContext = createContext2(void 0, "router");
|
|
282
|
+
var OutletContext = createContext2(void 0, "outlet");
|
|
283
|
+
var LevelParamsContext = createContext2(void 0, "route-params");
|
|
284
|
+
var RouteDataContext2 = createContext2(void 0, "route-data");
|
|
285
|
+
function renderLayer(m, depth, base) {
|
|
286
|
+
let data;
|
|
287
|
+
const loader = m.route.data;
|
|
288
|
+
if (typeof loader === "function") {
|
|
289
|
+
let cancelled = false;
|
|
290
|
+
onCleanup(() => {
|
|
291
|
+
cancelled = true;
|
|
292
|
+
});
|
|
293
|
+
const owner = getOwner();
|
|
294
|
+
const [resource] = createResource3(
|
|
295
|
+
() => loader({ params: base.params, location: base.location }, owner, () => cancelled)
|
|
296
|
+
);
|
|
297
|
+
data = resource;
|
|
298
|
+
}
|
|
299
|
+
const buildPage = () => RouteDataContext2.Provider({
|
|
300
|
+
value: data,
|
|
301
|
+
get children() {
|
|
302
|
+
return LevelParamsContext.Provider({
|
|
303
|
+
value: m.params,
|
|
304
|
+
get children() {
|
|
305
|
+
return OutletContext.Provider({
|
|
306
|
+
value: { depth, ...base },
|
|
307
|
+
get children() {
|
|
308
|
+
return createComponent2(m.component, {});
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
if (!data) return buildPage();
|
|
316
|
+
const res = data;
|
|
317
|
+
const isLoading = () => res.loading;
|
|
318
|
+
const [ready, setReady] = createSignal2(untrack2(() => !isLoading()));
|
|
319
|
+
createEffect(() => setReady(!isLoading()));
|
|
320
|
+
return createMemo2(() => ready() ? buildPage() : null);
|
|
321
|
+
}
|
|
322
|
+
function renderChild(ctx) {
|
|
323
|
+
const childIdx = ctx.depth + 1;
|
|
324
|
+
const [childComp, setChildComp] = createSignal2(
|
|
325
|
+
untrack2(() => ctx.matched()[childIdx]?.component)
|
|
326
|
+
);
|
|
327
|
+
createEffect(() => {
|
|
328
|
+
const c = ctx.matched()[childIdx]?.component;
|
|
329
|
+
setChildComp(() => c);
|
|
330
|
+
});
|
|
331
|
+
return createMemo2(() => {
|
|
332
|
+
const component = childComp();
|
|
333
|
+
if (!component) {
|
|
334
|
+
return ctx.notFound ? ctx.notFound() : null;
|
|
335
|
+
}
|
|
336
|
+
const m = untrack2(() => ctx.matched())[childIdx];
|
|
337
|
+
return renderLayer(m, childIdx, {
|
|
338
|
+
matched: ctx.matched,
|
|
339
|
+
params: ctx.params,
|
|
340
|
+
location: ctx.location
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
function renderNotFound(notFound) {
|
|
345
|
+
if (notFound == null) return buildDefaultNotFound();
|
|
346
|
+
return typeof notFound === "function" ? createComponent2(notFound, {}) : notFound;
|
|
347
|
+
}
|
|
348
|
+
function buildDefaultNotFound() {
|
|
349
|
+
const el = createNativeElement("div");
|
|
350
|
+
setAttribute(el, "class", "fx-not-found");
|
|
351
|
+
setAttribute(el, "role", "main");
|
|
352
|
+
setAttribute(
|
|
353
|
+
el,
|
|
354
|
+
"style",
|
|
355
|
+
"min-height:60vh;display:grid;place-content:center;gap:.25rem;text-align:center;font-family:system-ui,-apple-system,sans-serif"
|
|
356
|
+
);
|
|
357
|
+
const h1 = createNativeElement("h1");
|
|
358
|
+
setAttribute(h1, "style", "margin:0;font-size:2.5rem;font-weight:700");
|
|
359
|
+
insert(h1, "404");
|
|
360
|
+
const p = createNativeElement("p");
|
|
361
|
+
setAttribute(p, "style", "margin:0;opacity:.7");
|
|
362
|
+
insert(p, "This page could not be found.");
|
|
363
|
+
el.appendChild(h1);
|
|
364
|
+
el.appendChild(p);
|
|
365
|
+
return el;
|
|
366
|
+
}
|
|
367
|
+
function Router(props) {
|
|
368
|
+
const history = props.history ?? createBrowserHistory();
|
|
369
|
+
const router = createCoreRouter({
|
|
370
|
+
routes: props.routes,
|
|
371
|
+
base: props.base,
|
|
372
|
+
history
|
|
373
|
+
});
|
|
374
|
+
const [state, setState] = createSignal2(router.state());
|
|
375
|
+
const unsub = router.subscribe(setState);
|
|
376
|
+
onCleanup(() => {
|
|
377
|
+
unsub();
|
|
378
|
+
router.destroy();
|
|
379
|
+
});
|
|
380
|
+
const matched = createMemo2(
|
|
381
|
+
() => (state().match?.matched ?? []).filter((m) => m.component)
|
|
382
|
+
);
|
|
383
|
+
const ctx = {
|
|
384
|
+
router,
|
|
385
|
+
location: createMemo2(() => state().location),
|
|
386
|
+
params: createMemo2(() => state().match?.params ?? {})
|
|
387
|
+
};
|
|
388
|
+
const root = {
|
|
389
|
+
depth: -1,
|
|
390
|
+
matched,
|
|
391
|
+
params: ctx.params,
|
|
392
|
+
location: ctx.location,
|
|
393
|
+
// Only the root carries this: renderChild shows it when the URL matched nothing.
|
|
394
|
+
notFound: () => renderNotFound(props.notFound)
|
|
395
|
+
};
|
|
396
|
+
let rootView;
|
|
397
|
+
return RouterContext.Provider({
|
|
398
|
+
value: ctx,
|
|
399
|
+
get children() {
|
|
400
|
+
return rootView ??= renderChild(root);
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
function Outlet() {
|
|
405
|
+
const ctx = useContext2(OutletContext);
|
|
406
|
+
if (!ctx) return null;
|
|
407
|
+
return renderChild(ctx);
|
|
408
|
+
}
|
|
409
|
+
function Redirect(props) {
|
|
410
|
+
const ctx = useContext2(RouterContext);
|
|
411
|
+
if (ctx && typeof window !== "undefined") {
|
|
412
|
+
let cancelled = false;
|
|
413
|
+
onCleanup(() => cancelled = true);
|
|
414
|
+
queueMicrotask(() => {
|
|
415
|
+
if (!cancelled) ctx.router.navigate(props.to, { replace: props.replace !== false });
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
var _ssrRouterStub = {
|
|
421
|
+
router: { navigate: () => {
|
|
422
|
+
} },
|
|
423
|
+
location: () => ({ pathname: "", search: "", hash: "", query: {} }),
|
|
424
|
+
params: () => ({})
|
|
425
|
+
};
|
|
426
|
+
function useRouter() {
|
|
427
|
+
const ctx = useContext2(RouterContext);
|
|
428
|
+
if (ctx) return ctx;
|
|
429
|
+
if (typeof window === "undefined") return _ssrRouterStub;
|
|
430
|
+
throw new Error("[router] useRouter must be used within <Router>");
|
|
431
|
+
}
|
|
432
|
+
function useParams() {
|
|
433
|
+
const params = useRouter().params;
|
|
434
|
+
return createMemo2(() => params(), {}, {
|
|
435
|
+
equals: (a, b) => JSON.stringify(a) === JSON.stringify(b)
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
function useLevelParams() {
|
|
439
|
+
return useContext2(LevelParamsContext) ?? {};
|
|
440
|
+
}
|
|
441
|
+
function useParam(key) {
|
|
442
|
+
const params = useParams();
|
|
443
|
+
return createMemo2(() => params()[key]);
|
|
444
|
+
}
|
|
445
|
+
function useParamSelector(selector, equals) {
|
|
446
|
+
const params = useParams();
|
|
447
|
+
return createMemo2(
|
|
448
|
+
() => selector(params()),
|
|
449
|
+
void 0,
|
|
450
|
+
equals ? { equals } : void 0
|
|
451
|
+
);
|
|
452
|
+
}
|
|
453
|
+
function useMatch(path) {
|
|
454
|
+
const location = useLocation();
|
|
455
|
+
return createMemo2(
|
|
456
|
+
() => matchPath(typeof path === "function" ? path() : path, location.pathname)
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
function useSearchParams() {
|
|
460
|
+
const location = useLocation();
|
|
461
|
+
const navigate = useNavigate();
|
|
462
|
+
const params = createMemo2(() => location.query);
|
|
463
|
+
const setParams = (next, options) => {
|
|
464
|
+
const current = new URLSearchParams(location.search);
|
|
465
|
+
for (const [k, v] of Object.entries(next)) {
|
|
466
|
+
if (v === null) current.delete(k);
|
|
467
|
+
else current.set(k, v);
|
|
468
|
+
}
|
|
469
|
+
const search = current.toString();
|
|
470
|
+
navigate(location.pathname + (search ? `?${search}` : ""), options);
|
|
471
|
+
};
|
|
472
|
+
return [params, setParams];
|
|
473
|
+
}
|
|
474
|
+
function select(source, key) {
|
|
475
|
+
const equals = (a, b) => deepEqual(a, b);
|
|
476
|
+
if (key !== void 0) {
|
|
477
|
+
return createMemo2(
|
|
478
|
+
() => get(source(), key),
|
|
479
|
+
void 0,
|
|
480
|
+
{ equals }
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
return createMemo2(source, void 0, { equals });
|
|
484
|
+
}
|
|
485
|
+
function useLocation() {
|
|
486
|
+
const { location } = useRouter();
|
|
487
|
+
return new Proxy({}, {
|
|
488
|
+
get: (_t, key) => location()[key],
|
|
489
|
+
has: (_t, key) => key in location(),
|
|
490
|
+
ownKeys: () => Reflect.ownKeys(location()),
|
|
491
|
+
getOwnPropertyDescriptor: (_t, key) => Object.getOwnPropertyDescriptor(location(), key)
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
function useLinkNavigation(options = {}) {
|
|
495
|
+
const ctx = useContext2(RouterContext);
|
|
496
|
+
return (event) => {
|
|
497
|
+
if (!ctx || event.defaultPrevented || event.button !== 0) return;
|
|
498
|
+
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
|
499
|
+
const target = event.target;
|
|
500
|
+
const anchor = target?.closest?.("a");
|
|
501
|
+
if (!anchor || !anchor.getAttribute("href")) return;
|
|
502
|
+
if (anchor.target && anchor.target !== "_self") return;
|
|
503
|
+
if (anchor.hasAttribute("download")) return;
|
|
504
|
+
if (/(^|\s)external(\s|$)/.test(anchor.getAttribute("rel") ?? "")) return;
|
|
505
|
+
const url = new URL(anchor.href);
|
|
506
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return;
|
|
507
|
+
if (url.origin !== window.location.origin) return;
|
|
508
|
+
if (url.hash && url.pathname === window.location.pathname && url.search === window.location.search) return;
|
|
509
|
+
if (options.shouldNavigate && !options.shouldNavigate(url, anchor)) return;
|
|
510
|
+
event.preventDefault();
|
|
511
|
+
ctx.router.navigate(url.pathname + url.search + url.hash, { replace: options.replace });
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
function useNavigate() {
|
|
515
|
+
const { router } = useRouter();
|
|
516
|
+
return (to, options) => router.navigate(to, options);
|
|
517
|
+
}
|
|
518
|
+
function useRouteData() {
|
|
519
|
+
const acc = useContext2(RouteDataContext2);
|
|
520
|
+
return acc ?? (() => void 0);
|
|
521
|
+
}
|
|
522
|
+
var read = (v) => typeof v === "function" ? v() : v;
|
|
523
|
+
var LINK_OWN_PROPS = /* @__PURE__ */ new Set([
|
|
524
|
+
"href",
|
|
525
|
+
"slot",
|
|
526
|
+
"class",
|
|
527
|
+
"className",
|
|
528
|
+
"active",
|
|
529
|
+
"activeClass",
|
|
530
|
+
"replace",
|
|
531
|
+
"children"
|
|
532
|
+
]);
|
|
533
|
+
function Link(props) {
|
|
534
|
+
const ctx = useContext2(RouterContext);
|
|
535
|
+
const navigate = () => ctx?.router.navigate(read(props.href) ?? "", { replace: read(props.replace) });
|
|
536
|
+
const a = createNativeElement("a");
|
|
537
|
+
setAttribute(a, "href", read(props.href) ?? "");
|
|
538
|
+
if (props.slot) setAttribute(a, "slot", read(props.slot));
|
|
539
|
+
for (const k of Object.keys(props)) {
|
|
540
|
+
if (LINK_OWN_PROPS.has(k)) continue;
|
|
541
|
+
const v = props[k];
|
|
542
|
+
if (v != null && typeof v !== "function") setAttribute(a, k, String(v));
|
|
543
|
+
}
|
|
544
|
+
if (typeof a.addEventListener === "function") {
|
|
545
|
+
a.addEventListener("click", (e) => {
|
|
546
|
+
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
|
|
547
|
+
e.preventDefault();
|
|
548
|
+
navigate();
|
|
549
|
+
});
|
|
550
|
+
} else {
|
|
551
|
+
const base = read(props.className ?? props.class) ?? "";
|
|
552
|
+
if (base) setAttribute(a, "class", base);
|
|
553
|
+
}
|
|
554
|
+
if (typeof a.addEventListener === "function") {
|
|
555
|
+
createEffect(() => {
|
|
556
|
+
const href = read(props.href) ?? "";
|
|
557
|
+
a.setAttribute("href", href);
|
|
558
|
+
const base = read(props.className ?? props.class) ?? "";
|
|
559
|
+
const activeClass = read(props.activeClass) ?? "";
|
|
560
|
+
const active = read(props.active) ?? ctx?.location().pathname === href;
|
|
561
|
+
a.className = [base, active ? activeClass : ""].filter(Boolean).join(" ");
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
const linkChildren = props.children;
|
|
565
|
+
if (linkChildren != null) insert(a, linkChildren);
|
|
566
|
+
return a;
|
|
567
|
+
}
|
|
568
|
+
var A = Link;
|
|
569
|
+
function Form(props) {
|
|
570
|
+
const action2 = props.action;
|
|
571
|
+
const cls = props.className ?? props.class;
|
|
572
|
+
const url = action2.url ?? "";
|
|
573
|
+
const form = createNativeElement("form");
|
|
574
|
+
setAttribute(form, "method", "post");
|
|
575
|
+
if (url) setAttribute(form, "action", url);
|
|
576
|
+
if (cls) setAttribute(form, "class", cls);
|
|
577
|
+
for (const k of Object.keys(props)) {
|
|
578
|
+
if (k === "action" || k === "children" || k === "class" || k === "className") continue;
|
|
579
|
+
const v = props[k];
|
|
580
|
+
if (v != null && typeof v !== "function") setAttribute(form, k, String(v));
|
|
581
|
+
}
|
|
582
|
+
if (typeof form.addEventListener === "function") {
|
|
583
|
+
form.addEventListener("submit", (e) => {
|
|
584
|
+
e.preventDefault();
|
|
585
|
+
const data = {};
|
|
586
|
+
new FormData(form).forEach((v, k) => {
|
|
587
|
+
data[k] = v;
|
|
588
|
+
});
|
|
589
|
+
Promise.resolve(action2(data)).catch(() => {
|
|
590
|
+
});
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
const children = props.children;
|
|
594
|
+
if (children != null) insert(form, children);
|
|
595
|
+
return form;
|
|
596
|
+
}
|
|
597
|
+
async function preloadRoutes(routes, pathname) {
|
|
598
|
+
const match = matchRoutes(routes, pathname);
|
|
599
|
+
if (!match) return;
|
|
600
|
+
const loads = [];
|
|
601
|
+
for (const m of match.matched) {
|
|
602
|
+
const c = m.component;
|
|
603
|
+
if (c && typeof c.preload === "function") loads.push(c.preload());
|
|
604
|
+
}
|
|
605
|
+
await Promise.all(loads);
|
|
606
|
+
}
|
|
607
|
+
export {
|
|
608
|
+
A,
|
|
609
|
+
Form,
|
|
610
|
+
Link,
|
|
611
|
+
Outlet,
|
|
612
|
+
Redirect,
|
|
613
|
+
Router,
|
|
614
|
+
action,
|
|
615
|
+
cache,
|
|
616
|
+
createAsync,
|
|
617
|
+
createBrowserHistory2 as createBrowserHistory,
|
|
618
|
+
createMemoryHistory,
|
|
619
|
+
lazy,
|
|
620
|
+
matchPath2 as matchPath,
|
|
621
|
+
matchRoutes2 as matchRoutes,
|
|
622
|
+
preloadRoutes,
|
|
623
|
+
revalidate,
|
|
624
|
+
runWithOwner,
|
|
625
|
+
select,
|
|
626
|
+
useAction,
|
|
627
|
+
useLevelParams,
|
|
628
|
+
useLinkNavigation,
|
|
629
|
+
useLocation,
|
|
630
|
+
useMatch,
|
|
631
|
+
useNavigate,
|
|
632
|
+
useParam,
|
|
633
|
+
useParamSelector,
|
|
634
|
+
useParams,
|
|
635
|
+
useRouteData,
|
|
636
|
+
useRouter,
|
|
637
|
+
useSearchParams,
|
|
638
|
+
useSubmission
|
|
639
|
+
};
|