@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
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Register this package's version with the DOM runtime, which owns the stamping.
|
|
3
3
|
*
|
|
4
|
-
* It used to be owned here, and stamped only by core's `render
|
|
5
|
-
* the DOM any other way (`startClient`
|
|
4
|
+
* It used to be owned here, and stamped only by core's `render`, so an app that reached
|
|
5
|
+
* the DOM any other way (`startClient` -> `hydrate` -> the dom runtime's `render`) got no
|
|
6
6
|
* version attributes at all. Every SSR app is in that position, including the docs site.
|
|
7
7
|
*
|
|
8
8
|
* The stamping therefore moved down to `@fluixi/dom`, which both paths pass through. The
|
|
9
|
-
* core version cannot be imported from there
|
|
10
|
-
* a cycle
|
|
9
|
+
* core version cannot be imported from there: core depends on dom, and reversing that is
|
|
10
|
+
* a cycle, so it is pushed down instead, on import.
|
|
11
11
|
*
|
|
12
12
|
* Read from a generated constant rather than `package.json`: bundlers and ESM resolvers
|
|
13
13
|
* treat a manifest import inconsistently, and it would pull the whole file into the bundle
|
|
@@ -16,6 +16,6 @@
|
|
|
16
16
|
import { registerCoreVersion } from '@fluixi/dom';
|
|
17
17
|
import { VERSION as CORE } from '../../version.generated.js';
|
|
18
18
|
registerCoreVersion(CORE);
|
|
19
|
-
// Re-exported so existing importers keep working, and so core's own `render
|
|
20
|
-
// not delegate to the dom runtime's `render
|
|
19
|
+
// Re-exported so existing importers keep working, and so core's own `render`, which does
|
|
20
|
+
// not delegate to the dom runtime's `render`: can still stamp.
|
|
21
21
|
export { stampVersions, warnOnVersionSkew, versions } from '@fluixi/dom';
|
|
@@ -1 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
// src/lib/render/versions.ts
|
|
2
|
+
import { registerCoreVersion } from "@fluixi/dom";
|
|
3
|
+
|
|
4
|
+
// src/version.generated.ts
|
|
5
|
+
var VERSION = "1.0.0-alpha.84";
|
|
6
|
+
|
|
7
|
+
// src/lib/render/versions.ts
|
|
8
|
+
import { stampVersions, warnOnVersionSkew, versions } from "@fluixi/dom";
|
|
9
|
+
registerCoreVersion(VERSION);
|
|
10
|
+
export {
|
|
11
|
+
stampVersions,
|
|
12
|
+
versions,
|
|
13
|
+
warnOnVersionSkew
|
|
14
|
+
};
|
|
@@ -1 +1,230 @@
|
|
|
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/router/data.ts
|
|
21
|
+
var data_exports = {};
|
|
22
|
+
__export(data_exports, {
|
|
23
|
+
RouteDataContext: () => RouteDataContext,
|
|
24
|
+
RouteDataProvider: () => RouteDataProvider,
|
|
25
|
+
action: () => action,
|
|
26
|
+
cache: () => cache,
|
|
27
|
+
createAsync: () => createAsync,
|
|
28
|
+
revalidate: () => revalidate,
|
|
29
|
+
useAction: () => useAction,
|
|
30
|
+
useRouteData: () => useRouteData,
|
|
31
|
+
useSubmission: () => useSubmission
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(data_exports);
|
|
34
|
+
var import_signal3 = require("@fluixi/reactive/signal");
|
|
35
|
+
|
|
36
|
+
// src/lib/server/hydration.ts
|
|
37
|
+
var import_dom = require("@fluixi/dom");
|
|
38
|
+
var hydrating = false;
|
|
39
|
+
var hydrationDataMap = /* @__PURE__ */ new Map();
|
|
40
|
+
function isHydrating() {
|
|
41
|
+
return hydrating;
|
|
42
|
+
}
|
|
43
|
+
function setHydrationData(key, data) {
|
|
44
|
+
hydrationDataMap.set(key, data);
|
|
45
|
+
}
|
|
46
|
+
function getHydrationData(key) {
|
|
47
|
+
return hydrationDataMap.get(key);
|
|
48
|
+
}
|
|
49
|
+
function clearHydrationData() {
|
|
50
|
+
hydrationDataMap.clear();
|
|
51
|
+
}
|
|
52
|
+
function cleanupHydration() {
|
|
53
|
+
if (typeof window === "undefined") {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const script = document.getElementById("__FLUIXI_HYDRATION__");
|
|
57
|
+
if (script) {
|
|
58
|
+
script.remove();
|
|
59
|
+
}
|
|
60
|
+
const walker = document.createTreeWalker(
|
|
61
|
+
document.body,
|
|
62
|
+
NodeFilter.SHOW_COMMENT,
|
|
63
|
+
null
|
|
64
|
+
);
|
|
65
|
+
const comments = [];
|
|
66
|
+
let node;
|
|
67
|
+
while (node = walker.nextNode()) {
|
|
68
|
+
const comment = node;
|
|
69
|
+
const text = comment.nodeValue || "";
|
|
70
|
+
if (text.startsWith("#") || text.startsWith("/")) {
|
|
71
|
+
comments.push(comment);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
comments.forEach((comment) => comment.remove());
|
|
75
|
+
clearHydrationData();
|
|
76
|
+
}
|
|
77
|
+
if (typeof window !== "undefined") {
|
|
78
|
+
window.addEventListener("load", () => {
|
|
79
|
+
setTimeout(cleanupHydration, 100);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function isServerEnvironment() {
|
|
83
|
+
return (0, import_dom.isServer)();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/lib/context/context.ts
|
|
87
|
+
var import_dom2 = require("@fluixi/dom");
|
|
88
|
+
var import_signal = require("@fluixi/reactive/signal");
|
|
89
|
+
var import_signal2 = require("@fluixi/reactive/signal");
|
|
90
|
+
function createContext(defaultValue, name) {
|
|
91
|
+
const context = (0, import_signal.createContext)(defaultValue, name);
|
|
92
|
+
const Provider = (props) => {
|
|
93
|
+
if (props.debug === true) {
|
|
94
|
+
}
|
|
95
|
+
return context.Provider({
|
|
96
|
+
value: props.value,
|
|
97
|
+
get children() {
|
|
98
|
+
return props.children;
|
|
99
|
+
},
|
|
100
|
+
debug: props.debug
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
if (typeof Symbol !== "undefined" && Symbol.for) {
|
|
104
|
+
Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
|
|
105
|
+
}
|
|
106
|
+
Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
|
|
107
|
+
return {
|
|
108
|
+
id: context.id,
|
|
109
|
+
Provider: (0, import_dom2.asProvider)(Provider),
|
|
110
|
+
defaultValue
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function useContext(context) {
|
|
114
|
+
const value = (0, import_signal.useContext)(context);
|
|
115
|
+
return value !== void 0 ? value : context.defaultValue;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/lib/router/data.ts
|
|
119
|
+
var globalCache = /* @__PURE__ */ new Map();
|
|
120
|
+
var inflightRequests = /* @__PURE__ */ new Map();
|
|
121
|
+
function cache(fn, name) {
|
|
122
|
+
return async (...args) => {
|
|
123
|
+
const key = name + ":" + JSON.stringify(args);
|
|
124
|
+
if (isHydrating() || typeof window !== "undefined") {
|
|
125
|
+
const hydrated = getHydrationData(key);
|
|
126
|
+
if (hydrated !== void 0) {
|
|
127
|
+
return hydrated;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (globalCache.has(key)) {
|
|
131
|
+
return globalCache.get(key);
|
|
132
|
+
}
|
|
133
|
+
if (inflightRequests.has(key)) {
|
|
134
|
+
return inflightRequests.get(key);
|
|
135
|
+
}
|
|
136
|
+
const promise = Promise.resolve(fn(...args)).then(
|
|
137
|
+
(val) => {
|
|
138
|
+
globalCache.set(key, val);
|
|
139
|
+
inflightRequests.delete(key);
|
|
140
|
+
if (isServerEnvironment()) {
|
|
141
|
+
setHydrationData(key, val);
|
|
142
|
+
}
|
|
143
|
+
return val;
|
|
144
|
+
},
|
|
145
|
+
(err) => {
|
|
146
|
+
inflightRequests.delete(key);
|
|
147
|
+
throw err;
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
inflightRequests.set(key, promise);
|
|
151
|
+
return promise;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
var [revalidationVersion, setRevalidationVersion] = (0, import_signal3.createSignal)(0);
|
|
155
|
+
var revalidationKeys = /* @__PURE__ */ new Set();
|
|
156
|
+
function revalidate(key) {
|
|
157
|
+
const predicate = typeof key === "string" ? (k) => k.startsWith(key) : key;
|
|
158
|
+
for (const k of globalCache.keys()) {
|
|
159
|
+
if (predicate(k)) {
|
|
160
|
+
globalCache.delete(k);
|
|
161
|
+
revalidationKeys.add(k);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
setRevalidationVersion((v) => v + 1);
|
|
165
|
+
}
|
|
166
|
+
function createAsync(fetcher, source) {
|
|
167
|
+
const [data] = (0, import_signal3.createResource)(source || (() => true), fetcher);
|
|
168
|
+
return data;
|
|
169
|
+
}
|
|
170
|
+
var submissionState = /* @__PURE__ */ new Map();
|
|
171
|
+
function getSubmissionSignal(url) {
|
|
172
|
+
if (!submissionState.has(url)) {
|
|
173
|
+
submissionState.set(
|
|
174
|
+
url,
|
|
175
|
+
(0, import_signal3.createSignal)(void 0)
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
return submissionState.get(url);
|
|
179
|
+
}
|
|
180
|
+
function action(fn, name) {
|
|
181
|
+
const actionUrl = name || fn.name || "action";
|
|
182
|
+
const submit = async (input) => {
|
|
183
|
+
const [, setSubmission] = getSubmissionSignal(actionUrl);
|
|
184
|
+
const clear = () => setSubmission(void 0);
|
|
185
|
+
const retry = () => submit(input);
|
|
186
|
+
setSubmission({
|
|
187
|
+
input,
|
|
188
|
+
// Approximate type for tracking
|
|
189
|
+
pending: true,
|
|
190
|
+
clear,
|
|
191
|
+
retry
|
|
192
|
+
});
|
|
193
|
+
try {
|
|
194
|
+
const result = await fn(input);
|
|
195
|
+
setSubmission({
|
|
196
|
+
input,
|
|
197
|
+
result,
|
|
198
|
+
pending: false,
|
|
199
|
+
clear,
|
|
200
|
+
retry
|
|
201
|
+
});
|
|
202
|
+
return result;
|
|
203
|
+
} catch (error) {
|
|
204
|
+
setSubmission({
|
|
205
|
+
input,
|
|
206
|
+
error,
|
|
207
|
+
pending: false,
|
|
208
|
+
clear,
|
|
209
|
+
retry
|
|
210
|
+
});
|
|
211
|
+
throw error;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
submit.url = actionUrl;
|
|
215
|
+
submit.with = (args) => action((...a) => fn(args, ...a), name);
|
|
216
|
+
return submit;
|
|
217
|
+
}
|
|
218
|
+
function useSubmission(actionFn) {
|
|
219
|
+
const [submission] = getSubmissionSignal(actionFn.url);
|
|
220
|
+
return submission;
|
|
221
|
+
}
|
|
222
|
+
function useAction(actionFn) {
|
|
223
|
+
return actionFn;
|
|
224
|
+
}
|
|
225
|
+
var RouteDataContext = createContext(void 0, "route-data");
|
|
226
|
+
var RouteDataProvider = RouteDataContext.Provider;
|
|
227
|
+
function useRouteData() {
|
|
228
|
+
const ctx = useContext(RouteDataContext);
|
|
229
|
+
return typeof ctx === "function" ? ctx : () => ctx;
|
|
230
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview Data fetching and caching primitives for Fluixi Router
|
|
3
2
|
* @module @fluixi/core/router/data
|
|
4
3
|
*/
|
|
5
4
|
import { type Accessor, Resource } from '@fluixi/reactive/signal';
|
|
@@ -24,30 +23,19 @@ export interface Submission<T, Args extends any[]> {
|
|
|
24
23
|
* - Deduplication
|
|
25
24
|
* - Hydration (Server -> Client)
|
|
26
25
|
* - Revalidation
|
|
27
|
-
*
|
|
28
|
-
* @param fn Async function to cache
|
|
29
|
-
* @param name Unique name for the cache key
|
|
30
26
|
*/
|
|
31
27
|
export declare function cache<T, Args extends any[]>(fn: (...args: Args) => Promise<T> | T, name: string): (...args: Args) => Promise<T>;
|
|
32
28
|
/**
|
|
33
29
|
* Revalidate a cache key. Clears the memory cache and triggers
|
|
34
30
|
* reactive invalidation so resources using createAsync re-fetch.
|
|
35
|
-
*
|
|
36
|
-
* @param key Key prefix string or predicate function to match cache keys
|
|
37
31
|
*/
|
|
38
32
|
export declare function revalidate(key: string | ((key: string) => boolean)): void;
|
|
39
33
|
/**
|
|
40
34
|
* Create an async resource from a promise or cache function
|
|
41
|
-
*
|
|
42
|
-
* @param fetcher Function that returns a promise
|
|
43
|
-
* @param source Dependency signal (optional)
|
|
44
35
|
*/
|
|
45
36
|
export declare function createAsync<T, S extends any = true>(fetcher: (source: S) => Promise<T> | T, source?: () => S): Resource<S>;
|
|
46
37
|
/**
|
|
47
38
|
* Create a server action
|
|
48
|
-
*
|
|
49
|
-
* @param fn Function to execute (server-side)
|
|
50
|
-
* @param name Action name
|
|
51
39
|
*/
|
|
52
40
|
export declare function action<T, Args extends any[]>(fn: (...args: Args) => Promise<T> | T, name?: string): Action<T, Args>;
|
|
53
41
|
/**
|
|
@@ -60,7 +48,7 @@ export declare function useSubmission<T, Args extends any[]>(actionFn: Action<T,
|
|
|
60
48
|
export declare function useAction<T, Args extends any[]>(actionFn: Action<T, Args>): (...args: Args) => Promise<T>;
|
|
61
49
|
export interface RouteDataArgs {
|
|
62
50
|
/**
|
|
63
|
-
* Route params
|
|
51
|
+
* Route params, either a reactive signal accessor (when called from the
|
|
64
52
|
* router's createRoot during layout creation) or a plain snapshot object
|
|
65
53
|
* (legacy / manual usage). Always normalise with:
|
|
66
54
|
* `const getParams = typeof args.params === 'function' ? args.params : () => args.params;`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../../src/lib/router/data.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../../src/lib/router/data.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAGL,KAAK,QAAQ,EAEb,QAAQ,EACT,MAAM,yBAAyB,CAAC;AAejC,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,IAAI,SAAS,GAAG,EAAE,IAAI,CAC3C,GAAG,IAAI,EAAE,IAAI,KACV,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;AAEhC,MAAM,WAAW,MAAM,CAAC,CAAC,EAAE,IAAI,SAAS,GAAG,EAAE;IAE3C,CAAC,GAAG,IAAI,E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-
* @fileoverview Data fetching and caching primitives for Fluixi Router
|
|
3
2
|
* @module @fluixi/core/router/data
|
|
4
3
|
*/
|
|
5
4
|
import { createResource, createSignal } from '@fluixi/reactive/signal';
|
|
@@ -17,9 +16,6 @@ const inflightRequests = new Map();
|
|
|
17
16
|
* - Deduplication
|
|
18
17
|
* - Hydration (Server -> Client)
|
|
19
18
|
* - Revalidation
|
|
20
|
-
*
|
|
21
|
-
* @param fn Async function to cache
|
|
22
|
-
* @param name Unique name for the cache key
|
|
23
19
|
*/
|
|
24
20
|
export function cache(fn, name) {
|
|
25
21
|
return async (...args) => {
|
|
@@ -65,8 +61,6 @@ const revalidationKeys = new Set();
|
|
|
65
61
|
/**
|
|
66
62
|
* Revalidate a cache key. Clears the memory cache and triggers
|
|
67
63
|
* reactive invalidation so resources using createAsync re-fetch.
|
|
68
|
-
*
|
|
69
|
-
* @param key Key prefix string or predicate function to match cache keys
|
|
70
64
|
*/
|
|
71
65
|
export function revalidate(key) {
|
|
72
66
|
const predicate = typeof key === 'string' ? (k) => k.startsWith(key) : key;
|
|
@@ -84,9 +78,6 @@ export function revalidate(key) {
|
|
|
84
78
|
// ============================================================================
|
|
85
79
|
/**
|
|
86
80
|
* Create an async resource from a promise or cache function
|
|
87
|
-
*
|
|
88
|
-
* @param fetcher Function that returns a promise
|
|
89
|
-
* @param source Dependency signal (optional)
|
|
90
81
|
*/
|
|
91
82
|
export function createAsync(fetcher, source) {
|
|
92
83
|
const [data] = createResource(source || (() => true), fetcher);
|
|
@@ -105,9 +96,6 @@ function getSubmissionSignal(url) {
|
|
|
105
96
|
}
|
|
106
97
|
/**
|
|
107
98
|
* Create a server action
|
|
108
|
-
*
|
|
109
|
-
* @param fn Function to execute (server-side)
|
|
110
|
-
* @param name Action name
|
|
111
99
|
*/
|
|
112
100
|
export function action(fn, name) {
|
|
113
101
|
const actionUrl = name || fn.name || 'action';
|
|
@@ -163,7 +151,7 @@ export function useSubmission(actionFn) {
|
|
|
163
151
|
export function useAction(actionFn) {
|
|
164
152
|
return actionFn;
|
|
165
153
|
}
|
|
166
|
-
export const RouteDataContext = createContext();
|
|
154
|
+
export const RouteDataContext = createContext(undefined, 'route-data');
|
|
167
155
|
export const RouteDataProvider = RouteDataContext.Provider;
|
|
168
156
|
/**
|
|
169
157
|
* Access the data returned by the nearest ancestor route's `routeData` export.
|
|
@@ -1 +1,214 @@
|
|
|
1
|
-
|
|
1
|
+
// src/lib/router/data.ts
|
|
2
|
+
import {
|
|
3
|
+
createResource,
|
|
4
|
+
createSignal
|
|
5
|
+
} from "@fluixi/reactive/signal";
|
|
6
|
+
|
|
7
|
+
// src/lib/server/hydration.ts
|
|
8
|
+
import { isServer as domIsServer } from "@fluixi/dom";
|
|
9
|
+
var hydrating = false;
|
|
10
|
+
var hydrationDataMap = /* @__PURE__ */ new Map();
|
|
11
|
+
function isHydrating() {
|
|
12
|
+
return hydrating;
|
|
13
|
+
}
|
|
14
|
+
function setHydrationData(key, data) {
|
|
15
|
+
hydrationDataMap.set(key, data);
|
|
16
|
+
}
|
|
17
|
+
function getHydrationData(key) {
|
|
18
|
+
return hydrationDataMap.get(key);
|
|
19
|
+
}
|
|
20
|
+
function clearHydrationData() {
|
|
21
|
+
hydrationDataMap.clear();
|
|
22
|
+
}
|
|
23
|
+
function cleanupHydration() {
|
|
24
|
+
if (typeof window === "undefined") {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const script = document.getElementById("__FLUIXI_HYDRATION__");
|
|
28
|
+
if (script) {
|
|
29
|
+
script.remove();
|
|
30
|
+
}
|
|
31
|
+
const walker = document.createTreeWalker(
|
|
32
|
+
document.body,
|
|
33
|
+
NodeFilter.SHOW_COMMENT,
|
|
34
|
+
null
|
|
35
|
+
);
|
|
36
|
+
const comments = [];
|
|
37
|
+
let node;
|
|
38
|
+
while (node = walker.nextNode()) {
|
|
39
|
+
const comment = node;
|
|
40
|
+
const text = comment.nodeValue || "";
|
|
41
|
+
if (text.startsWith("#") || text.startsWith("/")) {
|
|
42
|
+
comments.push(comment);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
comments.forEach((comment) => comment.remove());
|
|
46
|
+
clearHydrationData();
|
|
47
|
+
}
|
|
48
|
+
if (typeof window !== "undefined") {
|
|
49
|
+
window.addEventListener("load", () => {
|
|
50
|
+
setTimeout(cleanupHydration, 100);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function isServerEnvironment() {
|
|
54
|
+
return domIsServer();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/lib/context/context.ts
|
|
58
|
+
import { asProvider } from "@fluixi/dom";
|
|
59
|
+
import { createContext as createReactiveContext, useContext as useReactiveContext } from "@fluixi/reactive/signal";
|
|
60
|
+
import {
|
|
61
|
+
readChildren
|
|
62
|
+
} from "@fluixi/reactive/signal";
|
|
63
|
+
function createContext(defaultValue, name) {
|
|
64
|
+
const context = createReactiveContext(defaultValue, name);
|
|
65
|
+
const Provider = (props) => {
|
|
66
|
+
if (props.debug === true) {
|
|
67
|
+
}
|
|
68
|
+
return context.Provider({
|
|
69
|
+
value: props.value,
|
|
70
|
+
get children() {
|
|
71
|
+
return props.children;
|
|
72
|
+
},
|
|
73
|
+
debug: props.debug
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
if (typeof Symbol !== "undefined" && Symbol.for) {
|
|
77
|
+
Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
|
|
78
|
+
}
|
|
79
|
+
Provider.$$typeof = /* @__PURE__ */ Symbol.for("react.provider");
|
|
80
|
+
return {
|
|
81
|
+
id: context.id,
|
|
82
|
+
Provider: asProvider(Provider),
|
|
83
|
+
defaultValue
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function useContext(context) {
|
|
87
|
+
const value = useReactiveContext(context);
|
|
88
|
+
return value !== void 0 ? value : context.defaultValue;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/lib/router/data.ts
|
|
92
|
+
var globalCache = /* @__PURE__ */ new Map();
|
|
93
|
+
var inflightRequests = /* @__PURE__ */ new Map();
|
|
94
|
+
function cache(fn, name) {
|
|
95
|
+
return async (...args) => {
|
|
96
|
+
const key = name + ":" + JSON.stringify(args);
|
|
97
|
+
if (isHydrating() || typeof window !== "undefined") {
|
|
98
|
+
const hydrated = getHydrationData(key);
|
|
99
|
+
if (hydrated !== void 0) {
|
|
100
|
+
return hydrated;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (globalCache.has(key)) {
|
|
104
|
+
return globalCache.get(key);
|
|
105
|
+
}
|
|
106
|
+
if (inflightRequests.has(key)) {
|
|
107
|
+
return inflightRequests.get(key);
|
|
108
|
+
}
|
|
109
|
+
const promise = Promise.resolve(fn(...args)).then(
|
|
110
|
+
(val) => {
|
|
111
|
+
globalCache.set(key, val);
|
|
112
|
+
inflightRequests.delete(key);
|
|
113
|
+
if (isServerEnvironment()) {
|
|
114
|
+
setHydrationData(key, val);
|
|
115
|
+
}
|
|
116
|
+
return val;
|
|
117
|
+
},
|
|
118
|
+
(err) => {
|
|
119
|
+
inflightRequests.delete(key);
|
|
120
|
+
throw err;
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
inflightRequests.set(key, promise);
|
|
124
|
+
return promise;
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
var [revalidationVersion, setRevalidationVersion] = createSignal(0);
|
|
128
|
+
var revalidationKeys = /* @__PURE__ */ new Set();
|
|
129
|
+
function revalidate(key) {
|
|
130
|
+
const predicate = typeof key === "string" ? (k) => k.startsWith(key) : key;
|
|
131
|
+
for (const k of globalCache.keys()) {
|
|
132
|
+
if (predicate(k)) {
|
|
133
|
+
globalCache.delete(k);
|
|
134
|
+
revalidationKeys.add(k);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
setRevalidationVersion((v) => v + 1);
|
|
138
|
+
}
|
|
139
|
+
function createAsync(fetcher, source) {
|
|
140
|
+
const [data] = createResource(source || (() => true), fetcher);
|
|
141
|
+
return data;
|
|
142
|
+
}
|
|
143
|
+
var submissionState = /* @__PURE__ */ new Map();
|
|
144
|
+
function getSubmissionSignal(url) {
|
|
145
|
+
if (!submissionState.has(url)) {
|
|
146
|
+
submissionState.set(
|
|
147
|
+
url,
|
|
148
|
+
createSignal(void 0)
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
return submissionState.get(url);
|
|
152
|
+
}
|
|
153
|
+
function action(fn, name) {
|
|
154
|
+
const actionUrl = name || fn.name || "action";
|
|
155
|
+
const submit = async (input) => {
|
|
156
|
+
const [, setSubmission] = getSubmissionSignal(actionUrl);
|
|
157
|
+
const clear = () => setSubmission(void 0);
|
|
158
|
+
const retry = () => submit(input);
|
|
159
|
+
setSubmission({
|
|
160
|
+
input,
|
|
161
|
+
// Approximate type for tracking
|
|
162
|
+
pending: true,
|
|
163
|
+
clear,
|
|
164
|
+
retry
|
|
165
|
+
});
|
|
166
|
+
try {
|
|
167
|
+
const result = await fn(input);
|
|
168
|
+
setSubmission({
|
|
169
|
+
input,
|
|
170
|
+
result,
|
|
171
|
+
pending: false,
|
|
172
|
+
clear,
|
|
173
|
+
retry
|
|
174
|
+
});
|
|
175
|
+
return result;
|
|
176
|
+
} catch (error) {
|
|
177
|
+
setSubmission({
|
|
178
|
+
input,
|
|
179
|
+
error,
|
|
180
|
+
pending: false,
|
|
181
|
+
clear,
|
|
182
|
+
retry
|
|
183
|
+
});
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
submit.url = actionUrl;
|
|
188
|
+
submit.with = (args) => action((...a) => fn(args, ...a), name);
|
|
189
|
+
return submit;
|
|
190
|
+
}
|
|
191
|
+
function useSubmission(actionFn) {
|
|
192
|
+
const [submission] = getSubmissionSignal(actionFn.url);
|
|
193
|
+
return submission;
|
|
194
|
+
}
|
|
195
|
+
function useAction(actionFn) {
|
|
196
|
+
return actionFn;
|
|
197
|
+
}
|
|
198
|
+
var RouteDataContext = createContext(void 0, "route-data");
|
|
199
|
+
var RouteDataProvider = RouteDataContext.Provider;
|
|
200
|
+
function useRouteData() {
|
|
201
|
+
const ctx = useContext(RouteDataContext);
|
|
202
|
+
return typeof ctx === "function" ? ctx : () => ctx;
|
|
203
|
+
}
|
|
204
|
+
export {
|
|
205
|
+
RouteDataContext,
|
|
206
|
+
RouteDataProvider,
|
|
207
|
+
action,
|
|
208
|
+
cache,
|
|
209
|
+
createAsync,
|
|
210
|
+
revalidate,
|
|
211
|
+
useAction,
|
|
212
|
+
useRouteData,
|
|
213
|
+
useSubmission
|
|
214
|
+
};
|