@askrjs/askr 0.3.1 → 0.4.1
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/CHANGELOG.md +898 -1
- package/README.md +61 -29
- package/capabilities.json +19 -9
- package/dist/actions/index.js +56 -12
- package/dist/benchmark.js +10 -15
- package/dist/boot/index.d.ts +3 -2
- package/dist/boot/index.js +1 -1
- package/dist/boot-C5HnQZio.js +4032 -0
- package/dist/browser-activity-2r5gA1Cb.js +222 -0
- package/dist/components/index.d.ts +8 -1
- package/dist/components/index.js +1 -43
- package/dist/{aria-hKjThHcp.js → compose-ref-ccRU59BM.js} +48 -5
- package/dist/control/index.d.ts +2 -0
- package/dist/control/index.js +1 -1
- package/dist/control-hr3B0QaD.js +211 -0
- package/dist/core.d.ts +5 -9
- package/dist/csp-nonce-D-XM_uuJ.js +35 -0
- package/dist/data/index.js +3 -3
- package/dist/{data-2edW0jhF.js → data-BsnOUpQ6.js} +294 -95
- package/dist/data-runtime-i-RD0Ffm.js +242 -0
- package/dist/{deferred-CbgNhf67.js → deferred-nGZglpj6.js} +42 -20
- package/dist/domains/actions.d.ts +8 -3
- package/dist/domains/component.d.ts +1 -107
- package/dist/domains/context.d.ts +0 -15
- package/dist/domains/control.d.ts +36 -249
- package/dist/domains/data.d.ts +31 -13
- package/dist/domains/diagnostics.d.ts +1 -2
- package/dist/domains/lifecycle.d.ts +2 -5
- package/dist/domains/refs.d.ts +0 -2
- package/dist/domains/routing.d.ts +43 -8
- package/dist/domains/scheduler.d.ts +1 -76
- package/dist/domains/server.d.ts +5 -2
- package/dist/domains/state.d.ts +2 -5
- package/dist/domains/telemetry.d.ts +0 -2
- package/dist/elements.d.ts +214 -51
- package/dist/error-boundary-ChXoIFVl.js +293 -0
- package/dist/foundations/icon/index.d.ts +0 -58
- package/dist/foundations/icon/index.js +2 -2
- package/dist/foundations/index.js +2 -1
- package/dist/foundations/interactions/index.js +1 -1
- package/dist/foundations/state/index.d.ts +3 -3
- package/dist/foundations/state/index.js +5 -3
- package/dist/foundations/structures/index.js +2 -1
- package/dist/foundations/utilities/index.d.ts +2 -0
- package/dist/foundations/utilities/index.js +1 -2
- package/dist/fx/index.d.ts +31 -58
- package/dist/fx/index.js +313 -195
- package/dist/hooks-kjLigwDJ.js +202 -0
- package/dist/index.d.ts +11 -74
- package/dist/index.js +8 -447
- package/dist/instance-DL-YKrj6.js +992 -0
- package/dist/{interactions-CTeACdT_.js → interactions-BAa2xuJ-.js} +3 -2
- package/dist/jsx-dev-runtime.d.ts +41 -18
- package/dist/jsx-dev-runtime.js +1 -6
- package/dist/{jsx-runtime-CPJXAOBF.js → jsx-runtime-C4idqHY0.js} +18 -7
- package/dist/jsx-runtime.js +1 -1
- package/dist/jsx.d.ts +61 -37
- package/dist/{manifest-D1P3UNWV.js → manifest-BNupb86f.js} +3 -3
- package/dist/{navigate-prC5V8XV.js → navigate-DsfO12hB.js} +468 -85
- package/dist/navigation.d.ts +12 -3
- package/dist/peer-types.d.ts +8 -0
- package/dist/portal-LYf4cbHd.js +349 -0
- package/dist/promise-Dz8iIHAm.js +16 -0
- package/dist/query-registry-tzSiVrV_.js +325 -0
- package/dist/readable-DFWOsTac.js +21 -0
- package/dist/{render-context-B7ohlh6t.js → render-context-DGHnEveC.js} +27 -11
- package/dist/render-sync-CUxvoVab.js +1256 -0
- package/dist/resolution-CF1BqHLm.js +1258 -0
- package/dist/resource-BhcaFqdB.js +377 -0
- package/dist/resources/index.d.ts +21 -11
- package/dist/resources/index.js +65 -266
- package/dist/router/index.d.ts +14 -5
- package/dist/router/index.js +22 -53
- package/dist/scope-ila_zaId.js +55 -0
- package/dist/{shared-kU8yvryp.js → shared-O2ZnmYAf.js} +1 -7
- package/dist/{snapshot-source-An4iKajG.js → snapshot-Cjx4N988.js} +6 -1
- package/dist/ssg/index.d.ts +1 -2
- package/dist/ssg/index.js +43 -22
- package/dist/ssr/index.d.ts +26 -28
- package/dist/ssr/index.js +4 -4
- package/dist/{ssr-CiNm6Vzl.js → ssr-9LOx_bEu.js} +133 -122
- package/dist/ssr-DPfdcq0e.js +229 -0
- package/dist/state-i9D4EtY6.js +250 -0
- package/dist/structures-CkehlOT3.js +231 -0
- package/dist/testing/index.d.ts +8 -4
- package/dist/testing/index.js +29 -34
- package/dist/url-C9xMpMMv.js +185 -0
- package/dist/utilities.d.ts +48 -2
- package/dist/verify-hydration-D_cyn1OX.js +152 -0
- package/package.json +19 -9
- package/dist/access-CEA2pOry.js +0 -1046
- package/dist/activity-oy2YFTFF.js +0 -201
- package/dist/boot-DLplW9h4.js +0 -1104
- package/dist/capabilities-Bbf0mlp9.js +0 -42
- package/dist/compose-ref-v0qGlHoN.js +0 -26
- package/dist/control-BR_mrX__.js +0 -173
- package/dist/control-C-ApnFs1.js +0 -20
- package/dist/csp-nonce-BfFWcd0w.js +0 -173
- package/dist/data-runtime-CxoY98lX.js +0 -149
- package/dist/default-portal-runtime-DvMvWJVp.js +0 -20
- package/dist/dom-renderer.d.ts +0 -77
- package/dist/domains/renderer.d.ts +0 -127
- package/dist/eager-control.d.ts +0 -8
- package/dist/effect-C3Zsc1k6.js +0 -292
- package/dist/for-state-BDykeOJL.js +0 -1753
- package/dist/instance-VAFYVJOa.js +0 -1027
- package/dist/notify-DxxuDPeY.js +0 -266
- package/dist/portal-w3oQ6oQU.js +0 -29
- package/dist/query-registry-LrYpQsDJ.js +0 -83
- package/dist/render-resolved-BC0W7_5b.js +0 -1123
- package/dist/renderer-CT0HeY58.js +0 -8623
- package/dist/resolution-3DskUkjG.js +0 -577
- package/dist/resource-18-sFRl9.js +0 -344
- package/dist/route-matching-CUzZ31gT.js +0 -551
- package/dist/router-internal-7nuNEHfG.js +0 -36
- package/dist/scope-Cq_iYbTR.js +0 -403
- package/dist/selector-BSPVkjKP.js +0 -311
- package/dist/ssr-EPjwJH5R.js +0 -29
- package/dist/state-BXJfudq1.js +0 -91
- package/dist/structures-CjEzfj4h.js +0 -654
- package/dist/timer-C7uqnJVt.js +0 -85
- package/dist/verify-hydration-ikaxotf7.js +0 -27
- package/dist/vnode-D24p6IW2.js +0 -7
package/dist/resources/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { S as queueTask } from "../instance-DL-YKrj6.js";
|
|
2
|
+
import { c as onCommit, i as currentComponent, n as createSource, o as hookSlot, s as notify, u as readSource } from "../hooks-kjLigwDJ.js";
|
|
3
|
+
import { a as routeActive, c as watch, i as on, n as windowFocused, o as task, r as capture, s as timer, t as documentVisible } from "../browser-activity-2r5gA1Cb.js";
|
|
4
|
+
import { t as resource } from "../resource-BhcaFqdB.js";
|
|
5
|
+
//#region src/core/api/stream.ts
|
|
6
|
+
/**
|
|
7
|
+
* stream(): a component-owned async iterable. It connects after the render
|
|
8
|
+
* that declared it commits, publishes each value to the components that read
|
|
9
|
+
* its snapshot, and disconnects with the component.
|
|
10
|
+
*/
|
|
10
11
|
function toError(value) {
|
|
11
12
|
return value instanceof Error ? value : new Error(String(value));
|
|
12
13
|
}
|
|
@@ -15,9 +16,7 @@ function depsEqual(left, right) {
|
|
|
15
16
|
}
|
|
16
17
|
function publish(slot) {
|
|
17
18
|
if (slot.disposed) return;
|
|
18
|
-
|
|
19
|
-
slot.owner?.notifyUpdate?.();
|
|
20
|
-
} catch {}
|
|
19
|
+
notify(slot.readers);
|
|
21
20
|
}
|
|
22
21
|
function setStartingState(slot) {
|
|
23
22
|
const retained = slot.hasValue;
|
|
@@ -29,9 +28,9 @@ function setStartingState(slot) {
|
|
|
29
28
|
function returnIterator(generation) {
|
|
30
29
|
if (generation.returned || !generation.iterator) return;
|
|
31
30
|
generation.returned = true;
|
|
32
|
-
const returnMethod = generation.iterator.return;
|
|
33
|
-
if (typeof returnMethod !== "function") return;
|
|
34
31
|
try {
|
|
32
|
+
const returnMethod = generation.iterator.return;
|
|
33
|
+
if (typeof returnMethod !== "function") return;
|
|
35
34
|
Promise.resolve(returnMethod.call(generation.iterator)).catch(() => {});
|
|
36
35
|
} catch {}
|
|
37
36
|
}
|
|
@@ -75,9 +74,22 @@ async function consume(slot, generation, iterable) {
|
|
|
75
74
|
publish(slot);
|
|
76
75
|
}
|
|
77
76
|
}
|
|
77
|
+
function failGeneration(slot, generation, error) {
|
|
78
|
+
if (!isCurrent(slot, generation)) return;
|
|
79
|
+
stopGeneration(generation);
|
|
80
|
+
if (slot.disposed || slot.current !== generation || slot.generation !== generation.id) return;
|
|
81
|
+
slot.current = null;
|
|
82
|
+
slot.snapshot.status = "error";
|
|
83
|
+
slot.snapshot.pending = false;
|
|
84
|
+
slot.snapshot.stale = slot.hasValue;
|
|
85
|
+
slot.snapshot.error = toError(error);
|
|
86
|
+
publish(slot);
|
|
87
|
+
}
|
|
78
88
|
function startSlot(slot) {
|
|
79
89
|
if (!slot.activated || slot.disposed) return;
|
|
80
|
-
|
|
90
|
+
const previous = slot.current;
|
|
91
|
+
stopGeneration(previous);
|
|
92
|
+
if (slot.disposed || slot.current !== previous) return;
|
|
81
93
|
slot.explicitlyClosed = false;
|
|
82
94
|
setStartingState(slot);
|
|
83
95
|
publish(slot);
|
|
@@ -93,38 +105,28 @@ function startSlot(slot) {
|
|
|
93
105
|
try {
|
|
94
106
|
result = slot.source({ signal: generation.controller.signal });
|
|
95
107
|
} catch (error) {
|
|
96
|
-
|
|
97
|
-
slot.current = null;
|
|
98
|
-
slot.snapshot.status = "error";
|
|
99
|
-
slot.snapshot.pending = false;
|
|
100
|
-
slot.snapshot.stale = slot.hasValue;
|
|
101
|
-
slot.snapshot.error = toError(error);
|
|
102
|
-
publish(slot);
|
|
108
|
+
failGeneration(slot, generation, error);
|
|
103
109
|
return;
|
|
104
110
|
}
|
|
105
111
|
Promise.resolve(result).then((iterable) => consume(slot, generation, iterable)).catch((error) => {
|
|
106
|
-
|
|
107
|
-
slot.current = null;
|
|
108
|
-
slot.snapshot.status = "error";
|
|
109
|
-
slot.snapshot.pending = false;
|
|
110
|
-
slot.snapshot.stale = slot.hasValue;
|
|
111
|
-
slot.snapshot.error = toError(error);
|
|
112
|
-
publish(slot);
|
|
112
|
+
failGeneration(slot, generation, error);
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
function queueStart(slot) {
|
|
116
116
|
if (slot.startQueued || slot.disposed || slot.explicitlyClosed) return;
|
|
117
117
|
slot.startQueued = true;
|
|
118
|
-
|
|
118
|
+
queueTask(() => {
|
|
119
119
|
slot.startQueued = false;
|
|
120
|
-
if (!slot.owner
|
|
120
|
+
if (!slot.owner || slot.owner.disposed || slot.explicitlyClosed) return;
|
|
121
121
|
startSlot(slot);
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
function closeSlot(slot) {
|
|
125
125
|
if (slot.disposed) return;
|
|
126
126
|
slot.explicitlyClosed = true;
|
|
127
|
-
|
|
127
|
+
const previous = slot.current;
|
|
128
|
+
stopGeneration(previous);
|
|
129
|
+
if (slot.disposed || slot.current !== previous || !slot.explicitlyClosed) return;
|
|
128
130
|
slot.current = null;
|
|
129
131
|
slot.snapshot.status = "closed";
|
|
130
132
|
slot.snapshot.pending = false;
|
|
@@ -149,9 +151,7 @@ function createSlot(source, options) {
|
|
|
149
151
|
const slot = {
|
|
150
152
|
kind: "stream",
|
|
151
153
|
source,
|
|
152
|
-
pendingSource: source,
|
|
153
154
|
deps: (options.deps ?? []).slice(),
|
|
154
|
-
pendingDeps: (options.deps ?? []).slice(),
|
|
155
155
|
snapshot,
|
|
156
156
|
generation: 0,
|
|
157
157
|
current: null,
|
|
@@ -161,7 +161,8 @@ function createSlot(source, options) {
|
|
|
161
161
|
hasValue: Object.prototype.hasOwnProperty.call(options, "initialValue"),
|
|
162
162
|
cleanupRegistered: false,
|
|
163
163
|
startQueued: false,
|
|
164
|
-
owner: null
|
|
164
|
+
owner: null,
|
|
165
|
+
readers: createSource()
|
|
165
166
|
};
|
|
166
167
|
snapshot.restart = () => {
|
|
167
168
|
if (slot.disposed) return;
|
|
@@ -179,247 +180,45 @@ function disposeSlot(slot) {
|
|
|
179
180
|
stopGeneration(slot.current);
|
|
180
181
|
slot.current = null;
|
|
181
182
|
slot.owner = null;
|
|
182
|
-
if (slot.activated && false);
|
|
183
183
|
slot.activated = false;
|
|
184
184
|
}
|
|
185
|
-
function
|
|
186
|
-
const
|
|
185
|
+
function requireStreamOwner() {
|
|
186
|
+
const instance = currentComponent();
|
|
187
|
+
if (!instance) throw new Error("[Askr] stream() must be called during component render inside an app.");
|
|
188
|
+
return instance;
|
|
189
|
+
}
|
|
190
|
+
function commitSlot(instance, slot, source, deps) {
|
|
191
|
+
const depsChanged = !depsEqual(slot.deps, deps);
|
|
187
192
|
const firstCommit = !slot.activated;
|
|
188
|
-
const wasRunning = slot.current !== null;
|
|
189
193
|
slot.owner = instance;
|
|
190
|
-
slot.source =
|
|
191
|
-
slot.deps =
|
|
194
|
+
slot.source = source;
|
|
195
|
+
slot.deps = deps;
|
|
192
196
|
if (firstCommit) slot.activated = true;
|
|
193
197
|
if (!slot.cleanupRegistered) {
|
|
194
198
|
slot.cleanupRegistered = true;
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
if (!slot.explicitlyClosed && (firstCommit || depsChanged && wasRunning)) queueStart(slot);
|
|
198
|
-
}
|
|
199
|
-
function getStreamSlot(instance, index, source, options) {
|
|
200
|
-
const slots = instance.lifecycleSlots ??= [];
|
|
201
|
-
const existing = slots[index];
|
|
202
|
-
if (existing) {
|
|
203
|
-
if (existing.kind !== "stream") throw new Error(`stream() lifecycle order violation: slot ${index} already belongs to ${existing.kind ?? "another primitive"}(). Keep lifecycle primitives in a stable top-level order.`);
|
|
204
|
-
return existing;
|
|
205
|
-
}
|
|
206
|
-
const slot = createSlot(source, options);
|
|
207
|
-
slots[index] = slot;
|
|
208
|
-
return slot;
|
|
209
|
-
}
|
|
210
|
-
/** Subscribe to a streaming data source for the current component's lifetime, with auto reconnect/cleanup. */
|
|
211
|
-
function stream(source, options = {}) {
|
|
212
|
-
const instance = getCurrentComponentInstance();
|
|
213
|
-
if (!instance) return createSnapshot(options);
|
|
214
|
-
const slot = getStreamSlot(instance, claimHookIndex(instance, "stream"), source, options);
|
|
215
|
-
slot.pendingSource = source;
|
|
216
|
-
slot.pendingDeps = (options.deps ?? []).slice();
|
|
217
|
-
if (!instance.ssr) registerCommitOperation(() => commitSlot(instance, slot));
|
|
218
|
-
return slot.snapshot;
|
|
219
|
-
}
|
|
220
|
-
//#endregion
|
|
221
|
-
//#region src/runtime/lifecycle/listener.ts
|
|
222
|
-
function normalizeListenerOptions(options) {
|
|
223
|
-
if (options === void 0 || typeof options === "boolean") return options;
|
|
224
|
-
return {
|
|
225
|
-
...options.capture !== void 0 ? { capture: options.capture } : {},
|
|
226
|
-
...options.once !== void 0 ? { once: options.once } : {},
|
|
227
|
-
...options.passive !== void 0 ? { passive: options.passive } : {},
|
|
228
|
-
...options.signal !== void 0 ? { signal: options.signal } : {}
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
function listenerOptionsEqual(a, b) {
|
|
232
|
-
if (a === b) return true;
|
|
233
|
-
if (typeof a === "boolean" || typeof b === "boolean") return a === b;
|
|
234
|
-
if (!a || !b) return a === b;
|
|
235
|
-
return a.capture === b.capture && a.once === b.once && a.passive === b.passive && a.signal === b.signal;
|
|
236
|
-
}
|
|
237
|
-
function detachListenerSlot(slot) {
|
|
238
|
-
if (!slot.attached || !slot.target) return;
|
|
239
|
-
slot.target.removeEventListener(slot.event, slot.listener, slot.options);
|
|
240
|
-
slot.attached = false;
|
|
241
|
-
}
|
|
242
|
-
function commitListenerSlot(instance, slot) {
|
|
243
|
-
slot.handler = slot.pendingHandler;
|
|
244
|
-
const resolvedTarget = resolveListenerTarget(slot.pendingTarget);
|
|
245
|
-
if (!slot.attached || slot.target !== resolvedTarget || slot.event !== slot.pendingEvent || !listenerOptionsEqual(slot.options, slot.pendingOptions)) {
|
|
246
|
-
detachListenerSlot(slot);
|
|
247
|
-
slot.target = resolvedTarget;
|
|
248
|
-
slot.event = slot.pendingEvent;
|
|
249
|
-
slot.options = slot.pendingOptions;
|
|
250
|
-
if (slot.target) {
|
|
251
|
-
slot.target.addEventListener(slot.event, slot.listener, slot.options);
|
|
252
|
-
slot.attached = true;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
if (!slot.cleanupRegistered) {
|
|
256
|
-
slot.cleanupRegistered = true;
|
|
257
|
-
ownCleanup(instance.owner, () => {
|
|
258
|
-
detachListenerSlot(slot);
|
|
259
|
-
slot.cleanupRegistered = false;
|
|
260
|
-
});
|
|
199
|
+
instance.onCleanup(() => disposeSlot(slot));
|
|
261
200
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
function
|
|
265
|
-
const instance =
|
|
266
|
-
if (
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
kind: "listener",
|
|
272
|
-
target: null,
|
|
273
|
-
event,
|
|
274
|
-
handler,
|
|
275
|
-
listener: ((evt) => {
|
|
276
|
-
createdSlot.handler.call(createdSlot.target, evt);
|
|
277
|
-
}),
|
|
278
|
-
options: void 0,
|
|
279
|
-
pendingTarget: target,
|
|
280
|
-
pendingEvent: event,
|
|
281
|
-
pendingHandler: handler,
|
|
282
|
-
pendingOptions: normalizedOptions,
|
|
283
|
-
attached: false,
|
|
284
|
-
cleanupRegistered: false
|
|
285
|
-
};
|
|
286
|
-
return createdSlot;
|
|
287
|
-
});
|
|
288
|
-
slot.pendingTarget = target;
|
|
289
|
-
slot.pendingEvent = event;
|
|
290
|
-
slot.pendingHandler = handler;
|
|
291
|
-
slot.pendingOptions = normalizedOptions;
|
|
292
|
-
registerCommitOperation(() => {
|
|
293
|
-
commitListenerSlot(instance, slot);
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
//#endregion
|
|
297
|
-
//#region src/runtime/lifecycle/task.ts
|
|
298
|
-
/** Runs an owned task after commit. */
|
|
299
|
-
function task(fn) {
|
|
300
|
-
const instance = getCurrentComponentInstance();
|
|
301
|
-
if (!instance) return;
|
|
302
|
-
const index = claimHookIndex(instance, "task");
|
|
303
|
-
const slot = getComponentLifecycleSlot(instance, index, "task", () => ({
|
|
304
|
-
kind: "task",
|
|
305
|
-
started: false,
|
|
306
|
-
task: fn
|
|
307
|
-
}));
|
|
308
|
-
if (!slot.started) {
|
|
309
|
-
slot.task = fn;
|
|
310
|
-
registerCommitOperation(async () => {
|
|
311
|
-
if (slot.started) return;
|
|
312
|
-
slot.started = true;
|
|
313
|
-
return await slot.task();
|
|
201
|
+
if (!slot.explicitlyClosed && (firstCommit || depsChanged)) queueStart(slot);
|
|
202
|
+
}
|
|
203
|
+
function stream(sourceOrGetter, connectOrOptions, drivenOptions) {
|
|
204
|
+
const instance = requireStreamOwner();
|
|
205
|
+
if (typeof connectOrOptions === "function") {
|
|
206
|
+
const value = sourceOrGetter();
|
|
207
|
+
return createStream(instance, (context) => connectOrOptions(value, context), {
|
|
208
|
+
...drivenOptions,
|
|
209
|
+
deps: [value]
|
|
314
210
|
});
|
|
315
211
|
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
* const snapshot = capture(() => someState());
|
|
325
|
-
* Promise.resolve().then(() => { use(snapshot()); });
|
|
326
|
-
*/
|
|
327
|
-
function capture(fn) {
|
|
328
|
-
const value = fn();
|
|
329
|
-
return () => value;
|
|
330
|
-
}
|
|
331
|
-
//#endregion
|
|
332
|
-
//#region src/runtime/lifecycle/watch.ts
|
|
333
|
-
function watchValuesEqual(previous, next) {
|
|
334
|
-
if (previous.length !== next.length) return false;
|
|
335
|
-
for (let index = 0; index < previous.length; index += 1) if (!Object.is(previous[index], next[index])) return false;
|
|
336
|
-
return true;
|
|
337
|
-
}
|
|
338
|
-
function stopWatchGeneration(slot) {
|
|
339
|
-
const controller = slot.controller;
|
|
340
|
-
slot.controller = null;
|
|
341
|
-
if (controller && !controller.signal.aborted) controller.abort();
|
|
342
|
-
const cleanup = slot.cleanup;
|
|
343
|
-
slot.cleanup = null;
|
|
344
|
-
cleanup?.();
|
|
345
|
-
}
|
|
346
|
-
function stopWatchSlot(slot) {
|
|
347
|
-
stopWatchGeneration(slot);
|
|
348
|
-
slot.effect?.cleanup();
|
|
349
|
-
slot.effect = null;
|
|
350
|
-
}
|
|
351
|
-
function reportWatchError(instance, error) {
|
|
352
|
-
if (!routeComponentErrorToBoundary(instance, error)) throw error;
|
|
353
|
-
}
|
|
354
|
-
function commitWatchSlot(instance, slot) {
|
|
355
|
-
slot.callback = slot.pendingCallback;
|
|
356
|
-
slot.sources = slot.pendingSources;
|
|
357
|
-
const compute = () => {
|
|
358
|
-
const values = slot.sources.map((source) => source());
|
|
359
|
-
return values.length === 1 ? values[0] : values;
|
|
360
|
-
};
|
|
361
|
-
const observe = (value, previous) => {
|
|
362
|
-
stopWatchGeneration(slot);
|
|
363
|
-
const controller = new AbortController();
|
|
364
|
-
slot.controller = controller;
|
|
365
|
-
const initial = !slot.hasObserved;
|
|
366
|
-
slot.hasObserved = true;
|
|
367
|
-
let result;
|
|
368
|
-
try {
|
|
369
|
-
result = slot.callback(value, {
|
|
370
|
-
initial,
|
|
371
|
-
previous,
|
|
372
|
-
signal: controller.signal
|
|
373
|
-
});
|
|
374
|
-
} catch (error) {
|
|
375
|
-
reportWatchError(instance, error);
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
if (typeof result === "function") {
|
|
379
|
-
slot.cleanup = result;
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
if (result && typeof result.then === "function") Promise.resolve(result).catch((error) => {
|
|
383
|
-
if (!controller.signal.aborted) reportWatchError(instance, error);
|
|
384
|
-
});
|
|
385
|
-
};
|
|
386
|
-
if (!slot.effect) slot.effect = createFineGrainedEffect({
|
|
387
|
-
lane: "post",
|
|
388
|
-
compute,
|
|
389
|
-
commit: observe,
|
|
390
|
-
equals: (previous, next) => Array.isArray(previous) && Array.isArray(next) ? watchValuesEqual(previous, next) : Object.is(previous, next),
|
|
391
|
-
onError: (error) => reportWatchError(instance, error)
|
|
392
|
-
});
|
|
393
|
-
else slot.effect.updateCompute(compute);
|
|
394
|
-
if (!slot.cleanupRegistered) {
|
|
395
|
-
slot.cleanupRegistered = true;
|
|
396
|
-
ownCleanup(instance.owner, () => {
|
|
397
|
-
stopWatchSlot(slot);
|
|
398
|
-
slot.cleanupRegistered = false;
|
|
399
|
-
});
|
|
212
|
+
return createStream(instance, sourceOrGetter, connectOrOptions ?? {});
|
|
213
|
+
}
|
|
214
|
+
function createStream(instance, source, options) {
|
|
215
|
+
const slot = hookSlot(instance, "stream", () => createSlot(source, options));
|
|
216
|
+
readSource(slot.readers);
|
|
217
|
+
if (!instance.server) {
|
|
218
|
+
const deps = (options.deps ?? []).slice();
|
|
219
|
+
onCommit(instance, () => commitSlot(instance, slot, source, deps));
|
|
400
220
|
}
|
|
401
|
-
|
|
402
|
-
function watch(sourceOrSources, callback) {
|
|
403
|
-
const instance = getCurrentComponentInstance();
|
|
404
|
-
if (!instance) return;
|
|
405
|
-
const index = claimHookIndex(instance, "watch");
|
|
406
|
-
const sources = Array.isArray(sourceOrSources) ? sourceOrSources : [sourceOrSources];
|
|
407
|
-
const slot = getComponentLifecycleSlot(instance, index, "watch", () => ({
|
|
408
|
-
kind: "watch",
|
|
409
|
-
sources,
|
|
410
|
-
pendingSources: sources,
|
|
411
|
-
callback,
|
|
412
|
-
pendingCallback: callback,
|
|
413
|
-
effect: null,
|
|
414
|
-
controller: null,
|
|
415
|
-
cleanup: null,
|
|
416
|
-
cleanupRegistered: false,
|
|
417
|
-
hasObserved: false
|
|
418
|
-
}));
|
|
419
|
-
slot.pendingSources = sources;
|
|
420
|
-
slot.pendingCallback = callback;
|
|
421
|
-
if (instance.ssr) return;
|
|
422
|
-
registerCommitOperation(() => commitWatchSlot(instance, slot));
|
|
221
|
+
return slot.snapshot;
|
|
423
222
|
}
|
|
424
223
|
//#endregion
|
|
425
|
-
export { capture, documentVisible,
|
|
224
|
+
export { capture, documentVisible, on, resource, routeActive, stream, task, timer, watch, windowFocused };
|
package/dist/router/index.d.ts
CHANGED
|
@@ -60,8 +60,8 @@ import {
|
|
|
60
60
|
AuthContext as AuthContext$1,
|
|
61
61
|
AuthRequirement,
|
|
62
62
|
AuthRequirement as AuthRequirement$1,
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
ObjectSchema,
|
|
64
|
+
} from '../peer-types.js';
|
|
65
65
|
/** A single query-string value accepted by {@link updateRouteQuery}. */
|
|
66
66
|
type RouteQueryParamValue = string | number | boolean | null | undefined;
|
|
67
67
|
/** A query-string value, or an array of them for a repeated param. */
|
|
@@ -222,6 +222,11 @@ declare function resolveRouteRequest(
|
|
|
222
222
|
target: string,
|
|
223
223
|
options: RouteRequestOptions
|
|
224
224
|
): RouteRequestResult | Promise<RouteRequestResult>;
|
|
225
|
+
/** Match a path against a route registry without resolving route policies or loading data. */
|
|
226
|
+
declare function matchRoute(
|
|
227
|
+
pathname: string,
|
|
228
|
+
options: { registry: RouteRegistry }
|
|
229
|
+
): RouteMatch | null;
|
|
225
230
|
/**
|
|
226
231
|
* Run `definition` to declare routes (via `route`/`page`/`group`/`fallback`)
|
|
227
232
|
* and build a {@link RouteRegistry} to pass to `createSPA`/`hydrateSPA`.
|
|
@@ -268,7 +273,7 @@ declare function lazyRouteData<TModule, TData = TModule>(
|
|
|
268
273
|
declare function Outlet(): JSXElement;
|
|
269
274
|
/** Which environment a route's data loader ran (or failed) in. */
|
|
270
275
|
type RouteDataLoadPhase = 'client' | 'server' | 'ssg';
|
|
271
|
-
/**
|
|
276
|
+
/** Rejection of a `lazyRouteData()` loader whose import or `select` failed; wraps the original `cause`. */
|
|
272
277
|
declare class RouteDataLoadError extends Error {
|
|
273
278
|
readonly route: string;
|
|
274
279
|
readonly phase: RouteDataLoadPhase;
|
|
@@ -277,9 +282,12 @@ declare class RouteDataLoadError extends Error {
|
|
|
277
282
|
}
|
|
278
283
|
/** Policy decision: allow the route to render. */
|
|
279
284
|
declare function allow(): AccessAllowDecision;
|
|
280
|
-
/**
|
|
285
|
+
/**
|
|
286
|
+
* Policy decision: redirect the visitor to `to`. A string is a logical path
|
|
287
|
+
* that gains the registry `basePath`; a `to()` destination is used as-is.
|
|
288
|
+
*/
|
|
281
289
|
declare function redirect(
|
|
282
|
-
to: string,
|
|
290
|
+
to: string | RouteDestination,
|
|
283
291
|
init?: {
|
|
284
292
|
status?: AccessRedirectStatus;
|
|
285
293
|
replace?: boolean;
|
|
@@ -514,6 +522,7 @@ export {
|
|
|
514
522
|
isDeferred,
|
|
515
523
|
lazy,
|
|
516
524
|
lazyRouteData,
|
|
525
|
+
matchRoute,
|
|
517
526
|
navigate,
|
|
518
527
|
notFound,
|
|
519
528
|
onRouteChange,
|
package/dist/router/index.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import { n as
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
5
|
-
import { n as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { t as applyInteractionPolicy } from "../interactions-CTeACdT_.js";
|
|
1
|
+
import { n as jsx } from "../jsx-runtime-C4idqHY0.js";
|
|
2
|
+
import { C as currentRoute, a as nextHistoryIndex, b as syncRegisteredRouteSnapshot, c as reconcileRouteMeta, f as saveScrollPosition, g as parseTargetUrl, h as getWindowHref, i as commitHistoryIndex, l as resolveRouteMeta, m as getRegisteredAppsSnapshot, n as navigate, p as getCurrentHref, r as navigateToPublicHref, u as serializeRouteMeta, v as setCurrentRouteLocation, w as onRouteChange, x as toDocumentUrl, y as syncAppRegistrationLocation } from "../navigate-DsfO12hB.js";
|
|
3
|
+
import { f as defer, p as isDeferred } from "../query-registry-tzSiVrV_.js";
|
|
4
|
+
import { M as getActiveRouteBasePath, a as resolveRouteRequest, at as lazyRouteData, b as addLogicalRouteBasePath, c as forbidden, ct as encodePathSegment, d as unauthorized, et as Outlet, f as currentAuth, it as lazy, l as notFound, o as allow, ot as RouteDataLoadError, s as deny, u as redirect, v as matchRoute, x as addRouteBasePath } from "../resolution-CF1BqHLm.js";
|
|
5
|
+
import { n as createRouteRegistry } from "../manifest-BNupb86f.js";
|
|
6
|
+
import { a as group, c as route, i as fallback, n as resolveDeferredValues, o as index, r as routeData, s as page, t as Resolve } from "../deferred-nGZglpj6.js";
|
|
7
|
+
import { a as isSafeHref, r as assertPathHrefStaysOnOrigin } from "../url-C9xMpMMv.js";
|
|
8
|
+
import { o as mergeProps } from "../compose-ref-ccRU59BM.js";
|
|
9
|
+
import { t as applyInteractionPolicy } from "../interactions-BAa2xuJ-.js";
|
|
11
10
|
//#region src/router/route-query.ts
|
|
12
11
|
function getRouteQueryHistoryMode(options) {
|
|
13
12
|
if (options.history) return options.history;
|
|
@@ -34,56 +33,26 @@ function applyRouteQueryUpdates(searchParams, updates) {
|
|
|
34
33
|
}
|
|
35
34
|
function updateRouteQuery(updates, options = {}) {
|
|
36
35
|
if (typeof window === "undefined") return;
|
|
37
|
-
const url = parseTargetUrl(
|
|
36
|
+
const url = parseTargetUrl("");
|
|
37
|
+
url.hash = window.location.hash;
|
|
38
38
|
applyRouteQueryUpdates(url.searchParams, updates);
|
|
39
39
|
const href = `${url.pathname}${url.search}${url.hash}`;
|
|
40
40
|
if (href === getWindowHref()) return;
|
|
41
41
|
const historyMode = getRouteQueryHistoryMode(options);
|
|
42
42
|
if (historyMode === "push") saveScrollPosition(getCurrentHref());
|
|
43
43
|
const state = window.history.state && typeof window.history.state === "object" ? window.history.state : {};
|
|
44
|
+
const historyIndex = nextHistoryIndex(historyMode);
|
|
44
45
|
window.history[historyMode === "replace" ? "replaceState" : "pushState"]({
|
|
45
46
|
...state,
|
|
46
|
-
path: href
|
|
47
|
-
|
|
47
|
+
path: href,
|
|
48
|
+
askrIndex: historyIndex
|
|
49
|
+
}, "", toDocumentUrl(href));
|
|
50
|
+
commitHistoryIndex(historyIndex);
|
|
48
51
|
setCurrentRouteLocation(url.pathname, href);
|
|
49
52
|
for (const app of getRegisteredAppsSnapshot()) syncAppRegistrationLocation(app, url.pathname, href);
|
|
50
53
|
syncRegisteredRouteSnapshot();
|
|
51
54
|
}
|
|
52
55
|
//#endregion
|
|
53
|
-
//#region src/router/policy.ts
|
|
54
|
-
/** Policy decision: allow the route to render. */
|
|
55
|
-
function allow() {
|
|
56
|
-
return { kind: "allow" };
|
|
57
|
-
}
|
|
58
|
-
/** Policy decision: redirect the visitor to `to`. */
|
|
59
|
-
function redirect(to, init = {}) {
|
|
60
|
-
return {
|
|
61
|
-
kind: "redirect",
|
|
62
|
-
to,
|
|
63
|
-
...init.status ? { status: init.status } : {},
|
|
64
|
-
...init.replace !== void 0 ? { replace: init.replace } : {}
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
/** Policy decision: deny the request with the given HTTP status. */
|
|
68
|
-
function deny(status) {
|
|
69
|
-
return {
|
|
70
|
-
kind: "deny",
|
|
71
|
-
status
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
/** Policy decision: deny with 401 Unauthorized. */
|
|
75
|
-
function unauthorized() {
|
|
76
|
-
return deny(401);
|
|
77
|
-
}
|
|
78
|
-
/** Policy decision: deny with 403 Forbidden. */
|
|
79
|
-
function forbidden() {
|
|
80
|
-
return deny(403);
|
|
81
|
-
}
|
|
82
|
-
/** Policy decision: deny with 404 Not Found. */
|
|
83
|
-
function notFound() {
|
|
84
|
-
return deny(404);
|
|
85
|
-
}
|
|
86
|
-
//#endregion
|
|
87
56
|
//#region src/router/destination.ts
|
|
88
57
|
function routeParameterName(segment) {
|
|
89
58
|
if (segment === "*") return {
|
|
@@ -101,7 +70,7 @@ function routeParameterName(segment) {
|
|
|
101
70
|
};
|
|
102
71
|
}
|
|
103
72
|
function encodeParameter(value, splat) {
|
|
104
|
-
return splat ? value.split("/").map(
|
|
73
|
+
return splat ? value.split("/").map(encodePathSegment).join("/") : encodePathSegment(value);
|
|
105
74
|
}
|
|
106
75
|
function buildPath(route, params) {
|
|
107
76
|
return route.path.split("/").map((segment) => {
|
|
@@ -176,18 +145,18 @@ function isSameOriginNavigableHref(href) {
|
|
|
176
145
|
* - Composable via mergeProps
|
|
177
146
|
*/
|
|
178
147
|
function Link({ href: suppliedHref, to, class: className, children, rel, target, "aria-current": ariaCurrent, "aria-label": ariaLabel, onPress, onClick, ...rest }) {
|
|
179
|
-
const
|
|
180
|
-
const href = supplied ? addRouteBasePath(supplied, getActiveRouteBasePath()) : supplied;
|
|
148
|
+
const href = to?.href ?? (suppliedHref ? addLogicalRouteBasePath(suppliedHref, getActiveRouteBasePath()) : suppliedHref);
|
|
181
149
|
if (!href) throw new Error("Link requires href or to.");
|
|
182
150
|
if (!isSafeHref(href)) throw new TypeError("Link href uses an unsafe URL scheme.");
|
|
151
|
+
assertPathHrefStaysOnOrigin(href);
|
|
183
152
|
const handleNavigation = (e) => {
|
|
184
153
|
if (e.defaultPrevented) return;
|
|
185
154
|
const event = e;
|
|
186
155
|
if ((event.button ?? 0) !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return;
|
|
187
|
-
if (target || !isSameOriginNavigableHref(href)) return;
|
|
156
|
+
if (target && target.toLowerCase() !== "_self" || !isSameOriginNavigableHref(href)) return;
|
|
188
157
|
if (rest.download !== void 0) return;
|
|
189
158
|
event.preventDefault();
|
|
190
|
-
|
|
159
|
+
navigateToPublicHref(href);
|
|
191
160
|
};
|
|
192
161
|
const interaction = applyInteractionPolicy({
|
|
193
162
|
isNative: true,
|
|
@@ -215,4 +184,4 @@ function Link({ href: suppliedHref, to, class: className, children, rel, target,
|
|
|
215
184
|
});
|
|
216
185
|
}
|
|
217
186
|
//#endregion
|
|
218
|
-
export { Link, Outlet, Resolve, RouteDataLoadError, allow, createRouteRegistry, currentAuth, currentRoute, defer, deny, fallback, forbidden, group, index, isDeferred, lazy, lazyRouteData, navigate, notFound, onRouteChange, page, reconcileRouteMeta, redirect, resolveDeferredValues, resolveRouteMeta, resolveRouteRequest, route, routeData, serializeRouteMeta, to, unauthorized, updateRouteQuery };
|
|
187
|
+
export { Link, Outlet, Resolve, RouteDataLoadError, allow, createRouteRegistry, currentAuth, currentRoute, defer, deny, fallback, forbidden, group, index, isDeferred, lazy, lazyRouteData, matchRoute, navigate, notFound, onRouteChange, page, reconcileRouteMeta, redirect, resolveDeferredValues, resolveRouteMeta, resolveRouteRequest, route, routeData, serializeRouteMeta, to, unauthorized, updateRouteQuery };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { M as getOwner } from "./instance-DL-YKrj6.js";
|
|
2
|
+
import { n as Fragment, t as ELEMENT_TYPE } from "./jsx-DRS-qjiN.js";
|
|
3
|
+
import { i as currentComponent } from "./hooks-kjLigwDJ.js";
|
|
4
|
+
//#region src/core/api/scope.ts
|
|
5
|
+
/**
|
|
6
|
+
* Lexical scopes. A scope's provider is a component that records its value
|
|
7
|
+
* on its own lifetime; `readScope()` finds the nearest provider by walking up
|
|
8
|
+
* the owner tree from the code that is running.
|
|
9
|
+
*/
|
|
10
|
+
function ScopeProvider(props) {
|
|
11
|
+
currentComponent()?.provide(props.scopeKey, props.value);
|
|
12
|
+
if (typeof Node !== "undefined" && props.children instanceof Node) return null;
|
|
13
|
+
return {
|
|
14
|
+
$$typeof: ELEMENT_TYPE,
|
|
15
|
+
type: Fragment,
|
|
16
|
+
props: { children: props.children },
|
|
17
|
+
key: null
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** Create a scope whose value defaults to `defaultValue`. */
|
|
21
|
+
function defineScope(defaultValue) {
|
|
22
|
+
const key = Symbol("AskrScope");
|
|
23
|
+
const scope = (props) => ({
|
|
24
|
+
$$typeof: ELEMENT_TYPE,
|
|
25
|
+
type: ScopeProvider,
|
|
26
|
+
props: {
|
|
27
|
+
scopeKey: key,
|
|
28
|
+
value: props.value,
|
|
29
|
+
children: props.children
|
|
30
|
+
},
|
|
31
|
+
key: null
|
|
32
|
+
});
|
|
33
|
+
return Object.assign(scope, {
|
|
34
|
+
key,
|
|
35
|
+
defaultValue
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const NOT_FOUND = Symbol("not-found");
|
|
39
|
+
/** Whether `readScope()` can run here (inside a render or owned callback). */
|
|
40
|
+
function isScopeReadable() {
|
|
41
|
+
return getOwner() !== null;
|
|
42
|
+
}
|
|
43
|
+
/** Read the nearest provided value of `scope`, or its default. */
|
|
44
|
+
function readScope(scope) {
|
|
45
|
+
const owner = getOwner();
|
|
46
|
+
if (!owner) throw new Error("readScope() can only be called during component render or async resource execution. Ensure you are calling this from inside your component or resource function.");
|
|
47
|
+
const value = lookup(owner, scope.key);
|
|
48
|
+
return value === NOT_FOUND ? scope.defaultValue : value;
|
|
49
|
+
}
|
|
50
|
+
function lookup(owner, key) {
|
|
51
|
+
for (let o = owner; o; o = o.parent) if (o.context?.has(key)) return o.context.get(key);
|
|
52
|
+
return NOT_FOUND;
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { isScopeReadable as n, readScope as r, defineScope as t };
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import { t as notifyReadableSource } from "./notify-DxxuDPeY.js";
|
|
2
1
|
//#region src/data/shared.ts
|
|
3
|
-
function createReadableSource() {
|
|
4
|
-
return (() => void 0);
|
|
5
|
-
}
|
|
6
|
-
/** Re-exported so data cells keep their existing name for the shared fan-out. */
|
|
7
|
-
const notifySource = notifyReadableSource;
|
|
8
2
|
function isAbortError(error, signal) {
|
|
9
3
|
return signal.aborted || error instanceof Error && error.name === "AbortError" || typeof DOMException !== "undefined" && error instanceof DOMException && error.name === "AbortError";
|
|
10
4
|
}
|
|
@@ -21,4 +15,4 @@ function normalizeAsyncDataError(error, fallbackMessage) {
|
|
|
21
15
|
return new Error(error == null ? fallbackMessage : String(error));
|
|
22
16
|
}
|
|
23
17
|
//#endregion
|
|
24
|
-
export { normalizeAsyncDataError as
|
|
18
|
+
export { normalizeAsyncDataError as i, isCurrentAsyncGeneration as n, isCurrentAsyncOperation as r, isAbortError as t };
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
//#region src/
|
|
1
|
+
//#region src/core/api/snapshot.ts
|
|
2
|
+
/**
|
|
3
|
+
* The brand that marks an async snapshot (`resource()`, queries) so
|
|
4
|
+
* `derive(source, map)` can wait for it to settle. The symbol is global so
|
|
5
|
+
* every copy of the package agrees on it.
|
|
6
|
+
*/
|
|
2
7
|
const SNAPSHOT_SOURCE_BRAND = Symbol.for("__ASKR_SNAPSHOT_SOURCE__");
|
|
3
8
|
function brandSnapshotSource(value) {
|
|
4
9
|
Object.defineProperty(value, SNAPSHOT_SOURCE_BRAND, {
|