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