@askrjs/askr 0.0.52 → 0.0.53
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/README.md +5 -1
- package/dist/{runtime/scheduler.js → access-Bg4RJNC8.js} +182 -9
- package/dist/actions/index.d.ts +2 -0
- package/dist/actions/index.js +103 -0
- package/dist/{common/attr-names.js → attr-names-CjhzmHOn.js} +1 -1
- package/dist/benchmark.d.ts +6 -2
- package/dist/benchmark.js +63 -11
- package/dist/boot/index.d.ts +61 -2
- package/dist/boot/index.js +1 -203
- package/dist/boot-j2KoN6ss.js +647 -0
- package/dist/cleanup-COv77su2.js +487 -0
- package/dist/component-internal-B3z7GXlD.js +614 -0
- package/dist/component-lifecycle-CO4hXlP4.js +357 -0
- package/dist/{runtime/component-scope.js → component-scope-CC3cojX9.js} +8 -1
- package/dist/component-scope-CvPba6O6.d.ts +12 -0
- package/dist/components/index.d.ts +17 -2
- package/dist/components/index.js +39 -1
- package/dist/compose-ref-Cc_YkUpM.js +92 -0
- package/dist/{foundations/utilities/compose-ref.d.ts → compose-ref-Cizq72-x.d.ts} +1 -1
- package/dist/control/index.d.ts +1 -3
- package/dist/control/index.js +1 -3
- package/dist/control-BQvNVfAd.d.ts +436 -0
- package/dist/control-BYyLTFyw.js +165 -0
- package/dist/control-Bf4Wkdvv.d.ts +9 -0
- package/dist/{common/control.js → control-DhFRTIoE.js} +1 -1
- package/dist/data/index.d.ts +2 -6
- package/dist/data/index.js +4 -5
- package/dist/data-DnxnDxD-.js +559 -0
- package/dist/{data/data-runtime.js → data-runtime-SJ1BSUvk.js} +32 -31
- package/dist/deferred-lKE8uR0z.js +386 -0
- package/dist/{runtime/effect.js → effect-BwnIvLah.js} +4 -4
- package/dist/fastlane-Dw8SOBr9.js +343 -0
- package/dist/for-internal-BKf_Tnv1.js +1563 -0
- package/dist/foundations/icon/index.d.ts +68 -2
- package/dist/foundations/icon/index.js +85 -1
- package/dist/foundations/index.d.ts +2 -5
- package/dist/foundations/index.js +2 -5
- package/dist/foundations/interactions/index.d.ts +264 -6
- package/dist/foundations/interactions/index.js +1 -6
- package/dist/foundations/state/index.d.ts +32 -1
- package/dist/foundations/state/index.js +78 -1
- package/dist/foundations/structures/index.d.ts +2 -7
- package/dist/foundations/structures/index.js +2 -7
- package/dist/foundations/utilities/index.d.ts +2 -6
- package/dist/foundations/utilities/index.js +2 -5
- package/dist/fx/index.d.ts +190 -3
- package/dist/fx/index.js +454 -4
- package/dist/index-31Uoz_NS.d.ts +239 -0
- package/dist/index-Bki2rqcr.d.ts +233 -0
- package/dist/index-BnU0NPwM.d.ts +101 -0
- package/dist/index-D73jgYx1.d.ts +48 -0
- package/dist/{runtime/runtime.d.ts → index-R2JJIbM-.d.ts} +31 -8
- package/dist/index-SJXJkssx.d.ts +44 -0
- package/dist/index.d.ts +8 -13
- package/dist/index.js +150 -15
- package/dist/interactions-w7gQN4ha.js +280 -0
- package/dist/{data/invalidation-listeners.js → invalidation-listeners-Des3AHYs.js} +1 -1
- package/dist/{common/props.d.ts → jsx-CP0gmYwJ.d.ts} +17 -5
- package/dist/{common/jsx.js → jsx-CUpRxrLH.js} +1 -1
- package/dist/jsx-dev-runtime.d.ts +2 -4
- package/dist/jsx-dev-runtime.js +7 -5
- package/dist/jsx-runtime-92bV2hSa.d.ts +34 -0
- package/dist/jsx-runtime-BVVgDSdq.d.ts +1 -0
- package/dist/jsx-runtime.d.ts +2 -35
- package/dist/jsx-runtime.js +11 -5
- package/dist/{runtime/lifecycle-operations.js → lifecycle-operations-D9va7GOU.js} +4 -5
- package/dist/navigate-BVDCzOuB.d.ts +34 -0
- package/dist/navigate-CmPLSXyw.js +1449 -0
- package/dist/{runtime/portal.js → portal-CyU3Ucf2.js} +33 -36
- package/dist/query-registry-CQIT4mXr.js +73 -0
- package/dist/{common/render-context.js → render-context-Clw3rFiO.js} +14 -6
- package/dist/renderer-DzPjeLby.js +6197 -0
- package/dist/{runtime/resource-operation.js → resource-operation-CEzfpnDk.js} +118 -15
- package/dist/resources/index.d.ts +42 -3
- package/dist/resources/index.js +3 -4
- package/dist/{common/route-activity.js → route-activity-CNJfpwx-.js} +1 -1
- package/dist/route-matching-vJpvLVbX.js +515 -0
- package/dist/router/index.d.ts +166 -14
- package/dist/router/index.js +150 -12
- package/dist/{common/router.d.ts → router-CeYvjj5_.d.ts} +72 -28
- package/dist/{common/router-internal.js → router-internal-BC0w1_xk.js} +1 -1
- package/dist/{runtime/scheduler.d.ts → scheduler-CmLO4Dfm.d.ts} +1 -3
- package/dist/{runtime/selector.js → selector-DafVYzV4.js} +34 -11
- package/dist/{runtime/snapshot-source.js → snapshot-source-BB42xgwb.js} +1 -1
- package/dist/ssg/index.d.ts +252 -4
- package/dist/ssg/index.js +857 -1
- package/dist/ssr/index.d.ts +225 -8
- package/dist/ssr/index.js +3 -6
- package/dist/{common/ssr.js → ssr-CbQO5xd3.js} +1 -1
- package/dist/ssr-D3t80Rc0.js +1413 -0
- package/dist/{runtime/state.js → state-DPl8lffD.js} +3 -5
- package/dist/structures-DUB3HchX.js +221 -0
- package/dist/testing/index.d.ts +3 -2
- package/dist/testing/index.js +2 -5
- package/dist/{jsx/types.d.ts → types-DnQVG4ZY.d.ts} +2 -5
- package/dist/{foundations/utilities/use-id.js → utilities-C_CGX4Dz.js} +1 -1
- package/dist/{ssr/verify-hydration.js → verify-hydration-io9ahUeq.js} +2 -2
- package/dist/{common/vnode.js → vnode-CGMJYPMB.js} +2 -2
- package/package.json +12 -7
- package/dist/bench/components/benchmark-row.d.ts +0 -20
- package/dist/bench/components/benchmark-row.js +0 -40
- package/dist/bench/components/benchmark-table.js +0 -23
- package/dist/bin/askr-ssg.d.ts +0 -27
- package/dist/bin/askr-ssg.js +0 -186
- package/dist/boot/hydration.js +0 -139
- package/dist/boot/root-lifecycle.d.ts +0 -18
- package/dist/boot/root-lifecycle.js +0 -209
- package/dist/boot/route-startup.js +0 -54
- package/dist/boot/types.d.ts +0 -61
- package/dist/common/component.d.ts +0 -18
- package/dist/common/control.d.ts +0 -12
- package/dist/common/dom-range.d.ts +0 -13
- package/dist/common/env.js +0 -41
- package/dist/common/error-boundary.d.ts +0 -15
- package/dist/common/invariant.js +0 -15
- package/dist/common/jsx.d.ts +0 -22
- package/dist/common/logger.js +0 -34
- package/dist/common/promise.js +0 -6
- package/dist/common/ssr-errors.d.ts +0 -10
- package/dist/common/ssr-errors.js +0 -14
- package/dist/common/ssr.d.ts +0 -41
- package/dist/common/vnode.d.ts +0 -21
- package/dist/components/error-boundary.d.ts +0 -14
- package/dist/components/error-boundary.js +0 -41
- package/dist/components/link.d.ts +0 -68
- package/dist/components/link.js +0 -74
- package/dist/control/case.d.ts +0 -18
- package/dist/control/case.js +0 -68
- package/dist/control/for.d.ts +0 -23
- package/dist/control/for.js +0 -61
- package/dist/control/shared.d.ts +0 -8
- package/dist/control/shared.js +0 -18
- package/dist/control/show.d.ts +0 -14
- package/dist/control/show.js +0 -32
- package/dist/data/data-runtime.d.ts +0 -27
- package/dist/data/invalidation.d.ts +0 -8
- package/dist/data/invalidation.js +0 -25
- package/dist/data/mutation-cell.d.ts +0 -27
- package/dist/data/mutation-cell.js +0 -133
- package/dist/data/query-cell.d.ts +0 -47
- package/dist/data/query-cell.js +0 -324
- package/dist/data/query-key.js +0 -40
- package/dist/data/shared.js +0 -20
- package/dist/data/testing.js +0 -2
- package/dist/data/types.d.ts +0 -160
- package/dist/foundations/icon/icon.d.ts +0 -52
- package/dist/foundations/icon/icon.js +0 -86
- package/dist/foundations/icon/icon.types.d.ts +0 -21
- package/dist/foundations/interactions/dismissable.d.ts +0 -71
- package/dist/foundations/interactions/dismissable.js +0 -24
- package/dist/foundations/interactions/focusable.d.ts +0 -21
- package/dist/foundations/interactions/focusable.js +0 -16
- package/dist/foundations/interactions/hoverable.d.ts +0 -25
- package/dist/foundations/interactions/hoverable.js +0 -13
- package/dist/foundations/interactions/interaction-policy.d.ts +0 -49
- package/dist/foundations/interactions/interaction-policy.js +0 -120
- package/dist/foundations/interactions/pressable.d.ts +0 -60
- package/dist/foundations/interactions/pressable.js +0 -49
- package/dist/foundations/interactions/roving-focus.d.ts +0 -51
- package/dist/foundations/interactions/roving-focus.js +0 -69
- package/dist/foundations/state/controllable.d.ts +0 -32
- package/dist/foundations/state/controllable.js +0 -80
- package/dist/foundations/structures/collection.d.ts +0 -51
- package/dist/foundations/structures/collection.js +0 -49
- package/dist/foundations/structures/layer.d.ts +0 -80
- package/dist/foundations/structures/layer.js +0 -79
- package/dist/foundations/structures/layout.d.ts +0 -32
- package/dist/foundations/structures/layout.js +0 -11
- package/dist/foundations/structures/portal.d.ts +0 -2
- package/dist/foundations/structures/portal.js +0 -3
- package/dist/foundations/structures/presence.d.ts +0 -36
- package/dist/foundations/structures/presence.js +0 -37
- package/dist/foundations/structures/slot.d.ts +0 -34
- package/dist/foundations/structures/slot.js +0 -39
- package/dist/foundations/utilities/aria.d.ts +0 -15
- package/dist/foundations/utilities/aria.js +0 -15
- package/dist/foundations/utilities/compose-handlers.d.ts +0 -36
- package/dist/foundations/utilities/compose-handlers.js +0 -18
- package/dist/foundations/utilities/compose-ref.js +0 -16
- package/dist/foundations/utilities/event-types.d.ts +0 -19
- package/dist/foundations/utilities/merge-props.d.ts +0 -4
- package/dist/foundations/utilities/merge-props.js +0 -47
- package/dist/foundations/utilities/use-id.d.ts +0 -31
- package/dist/fx/fx.d.ts +0 -32
- package/dist/fx/fx.js +0 -211
- package/dist/fx/noop.js +0 -7
- package/dist/fx/timing.d.ts +0 -158
- package/dist/fx/timing.js +0 -241
- package/dist/jsx/index.d.ts +0 -2
- package/dist/jsx/index.js +0 -4
- package/dist/jsx/types.js +0 -2
- package/dist/jsx/utils.d.ts +0 -4
- package/dist/jsx/utils.js +0 -17
- package/dist/jsx-runtime2.d.ts +0 -3
- package/dist/jsx-runtime2.js +0 -4
- package/dist/renderer/attributes.js +0 -254
- package/dist/renderer/boundaries.js +0 -142
- package/dist/renderer/boundary-materialization.js +0 -72
- package/dist/renderer/boundary-range-adoption.js +0 -76
- package/dist/renderer/boundary-range-sync.js +0 -101
- package/dist/renderer/boundary-state.js +0 -50
- package/dist/renderer/child-shape.js +0 -83
- package/dist/renderer/children-fastpath.js +0 -149
- package/dist/renderer/children.js +0 -158
- package/dist/renderer/cleanup.js +0 -267
- package/dist/renderer/component-host-cleanup.js +0 -143
- package/dist/renderer/component-host-instances.js +0 -116
- package/dist/renderer/component-host-replacement.js +0 -105
- package/dist/renderer/component-host-results.js +0 -138
- package/dist/renderer/component-host.js +0 -172
- package/dist/renderer/dom-host.js +0 -11
- package/dist/renderer/dom-internal.js +0 -243
- package/dist/renderer/dom-range.js +0 -161
- package/dist/renderer/dom.js +0 -11
- package/dist/renderer/element-children.js +0 -359
- package/dist/renderer/env.js +0 -2
- package/dist/renderer/error-boundary-dom.js +0 -86
- package/dist/renderer/evaluate-dom-range.js +0 -84
- package/dist/renderer/evaluate-reconcile.js +0 -257
- package/dist/renderer/evaluate.js +0 -95
- package/dist/renderer/fastpath.js +0 -142
- package/dist/renderer/for-commit-dom-map.js +0 -71
- package/dist/renderer/for-commit-removal.js +0 -27
- package/dist/renderer/for-commit-reorder.js +0 -87
- package/dist/renderer/for-commit.js +0 -442
- package/dist/renderer/hydration-boundaries.js +0 -60
- package/dist/renderer/hydration-listener-transaction.js +0 -49
- package/dist/renderer/index.js +0 -39
- package/dist/renderer/intrinsic-blueprint-analysis.js +0 -202
- package/dist/renderer/intrinsic-blueprint-bindings.js +0 -152
- package/dist/renderer/intrinsic-blueprint-materialization.js +0 -100
- package/dist/renderer/intrinsic-blueprint.js +0 -30
- package/dist/renderer/intrinsic-hydration-adoption.js +0 -66
- package/dist/renderer/keyed-children.js +0 -26
- package/dist/renderer/keyed.js +0 -167
- package/dist/renderer/namespaces.js +0 -21
- package/dist/renderer/prop-bindings.js +0 -315
- package/dist/renderer/reactive-child-dom.js +0 -139
- package/dist/renderer/reactive-child-sources.js +0 -182
- package/dist/renderer/reactive-children.js +0 -303
- package/dist/renderer/reconcile-commit.js +0 -36
- package/dist/renderer/reconcile-fastpaths.js +0 -100
- package/dist/renderer/reconcile-resolution.js +0 -163
- package/dist/renderer/reconcile.js +0 -37
- package/dist/renderer/retained-element-rollback.js +0 -288
- package/dist/renderer/stable-patch.js +0 -80
- package/dist/renderer/static-reuse.js +0 -94
- package/dist/renderer/types.js +0 -2
- package/dist/renderer/utils.js +0 -265
- package/dist/router/access.js +0 -34
- package/dist/router/activity.d.ts +0 -9
- package/dist/router/activity.js +0 -85
- package/dist/router/authoring.d.ts +0 -21
- package/dist/router/authoring.js +0 -196
- package/dist/router/internal-types.d.ts +0 -30
- package/dist/router/lazy.d.ts +0 -18
- package/dist/router/lazy.js +0 -50
- package/dist/router/manifest.d.ts +0 -9
- package/dist/router/manifest.js +0 -47
- package/dist/router/match.js +0 -120
- package/dist/router/navigate.d.ts +0 -10
- package/dist/router/navigate.js +0 -73
- package/dist/router/navigation-registry.d.ts +0 -31
- package/dist/router/navigation-registry.js +0 -103
- package/dist/router/navigation-scroll.d.ts +0 -13
- package/dist/router/navigation-scroll.js +0 -91
- package/dist/router/navigation-targets.d.ts +0 -30
- package/dist/router/navigation-targets.js +0 -634
- package/dist/router/policy.d.ts +0 -27
- package/dist/router/policy.js +0 -130
- package/dist/router/rendering.d.ts +0 -9
- package/dist/router/rendering.js +0 -47
- package/dist/router/resolution.d.ts +0 -3
- package/dist/router/resolution.js +0 -84
- package/dist/router/route-context.js +0 -77
- package/dist/router/route-matching.d.ts +0 -19
- package/dist/router/route-matching.js +0 -173
- package/dist/router/route-query.d.ts +0 -16
- package/dist/router/route-query.js +0 -45
- package/dist/router/route.d.ts +0 -8
- package/dist/router/route.js +0 -10
- package/dist/router/store.d.ts +0 -49
- package/dist/router/store.js +0 -169
- package/dist/router/testing.js +0 -4
- package/dist/runtime/access.d.ts +0 -19
- package/dist/runtime/access.js +0 -43
- package/dist/runtime/child-scope.d.ts +0 -41
- package/dist/runtime/child-scope.js +0 -134
- package/dist/runtime/component-cleanup.d.ts +0 -15
- package/dist/runtime/component-cleanup.js +0 -68
- package/dist/runtime/component-commit.js +0 -167
- package/dist/runtime/component-facade.d.ts +0 -5
- package/dist/runtime/component-facade.js +0 -6
- package/dist/runtime/component-internal.d.ts +0 -105
- package/dist/runtime/component-internal.js +0 -237
- package/dist/runtime/component-lifecycle.d.ts +0 -10
- package/dist/runtime/component-lifecycle.js +0 -33
- package/dist/runtime/component-scope.d.ts +0 -54
- package/dist/runtime/component.d.ts +0 -5
- package/dist/runtime/component.js +0 -6
- package/dist/runtime/context.d.ts +0 -72
- package/dist/runtime/context.js +0 -236
- package/dist/runtime/control.d.ts +0 -62
- package/dist/runtime/control.js +0 -239
- package/dist/runtime/derive.d.ts +0 -16
- package/dist/runtime/derive.js +0 -140
- package/dist/runtime/dev-namespace.d.ts +0 -30
- package/dist/runtime/dev-namespace.js +0 -64
- package/dist/runtime/effect.d.ts +0 -35
- package/dist/runtime/error-boundary.d.ts +0 -4
- package/dist/runtime/error-boundary.js +0 -29
- package/dist/runtime/events.d.ts +0 -58
- package/dist/runtime/events.js +0 -201
- package/dist/runtime/execution-model.d.ts +0 -6
- package/dist/runtime/execution-model.js +0 -13
- package/dist/runtime/fastlane.d.ts +0 -33
- package/dist/runtime/fastlane.js +0 -173
- package/dist/runtime/for-bench.d.ts +0 -40
- package/dist/runtime/for-bench.js +0 -13
- package/dist/runtime/for-internal.d.ts +0 -106
- package/dist/runtime/for-internal.js +0 -285
- package/dist/runtime/for-reconcile.d.ts +0 -7
- package/dist/runtime/for-reconcile.js +0 -442
- package/dist/runtime/for-scopes.d.ts +0 -26
- package/dist/runtime/for-scopes.js +0 -280
- package/dist/runtime/for-signals.d.ts +0 -39
- package/dist/runtime/for-signals.js +0 -213
- package/dist/runtime/for-types.d.ts +0 -8
- package/dist/runtime/for.d.ts +0 -4
- package/dist/runtime/for.js +0 -5
- package/dist/runtime/index.d.ts +0 -24
- package/dist/runtime/index.js +0 -33
- package/dist/runtime/lifecycle-batch.d.ts +0 -59
- package/dist/runtime/lifecycle-batch.js +0 -178
- package/dist/runtime/lifecycle-operation-settlement.d.ts +0 -5
- package/dist/runtime/lifecycle-operation-settlement.js +0 -51
- package/dist/runtime/lifecycle-operations.d.ts +0 -30
- package/dist/runtime/operations.d.ts +0 -3
- package/dist/runtime/operations.js +0 -3
- package/dist/runtime/perf-metrics.d.ts +0 -27
- package/dist/runtime/perf-metrics.js +0 -6
- package/dist/runtime/portal.d.ts +0 -21
- package/dist/runtime/readable.d.ts +0 -34
- package/dist/runtime/readable.js +0 -183
- package/dist/runtime/resource-cell.js +0 -112
- package/dist/runtime/resource-operation.d.ts +0 -12
- package/dist/runtime/runtime.js +0 -57
- package/dist/runtime/selector-store.js +0 -22
- package/dist/runtime/selector.d.ts +0 -10
- package/dist/runtime/snapshot-source.d.ts +0 -9
- package/dist/runtime/state.d.ts +0 -54
- package/dist/ssg/batch-render.js +0 -101
- package/dist/ssg/create-static-gen.d.ts +0 -66
- package/dist/ssg/create-static-gen.js +0 -250
- package/dist/ssg/generate-metadata.js +0 -92
- package/dist/ssg/generation-plan.js +0 -68
- package/dist/ssg/incremental-manifest.js +0 -54
- package/dist/ssg/resolve-ssg-data.js +0 -103
- package/dist/ssg/route-utils.js +0 -22
- package/dist/ssg/static-routes.js +0 -100
- package/dist/ssg/types.d.ts +0 -188
- package/dist/ssg/write-static-files.js +0 -77
- package/dist/ssr/attrs.js +0 -92
- package/dist/ssr/boundaries.js +0 -124
- package/dist/ssr/component-runtime.js +0 -85
- package/dist/ssr/context.d.ts +0 -49
- package/dist/ssr/context.js +0 -89
- package/dist/ssr/errors.d.ts +0 -9
- package/dist/ssr/errors.js +0 -12
- package/dist/ssr/escape.js +0 -191
- package/dist/ssr/hydration-data.js +0 -8
- package/dist/ssr/hydration-verify.d.ts +0 -11
- package/dist/ssr/hydration-verify.js +0 -171
- package/dist/ssr/index-internal.d.ts +0 -14
- package/dist/ssr/index-internal.js +0 -17
- package/dist/ssr/render-keys.js +0 -14
- package/dist/ssr/render-resolved.d.ts +0 -19
- package/dist/ssr/render-resolved.js +0 -33
- package/dist/ssr/render-sync.d.ts +0 -20
- package/dist/ssr/render-sync.js +0 -283
- package/dist/ssr/route-policy-resolution.js +0 -76
- package/dist/ssr/route-render.d.ts +0 -76
- package/dist/ssr/route-render.js +0 -118
- package/dist/ssr/sink.d.ts +0 -25
- package/dist/ssr/sink.js +0 -84
- package/dist/ssr/types.d.ts +0 -22
package/dist/router/policy.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { isPromiseLike } from "../common/promise.js";
|
|
2
|
-
//#region src/router/policy.ts
|
|
3
|
-
const ROUTE_AUTH_OPTIONS = Symbol.for("__ASKR_ROUTE_AUTH_OPTIONS__");
|
|
4
|
-
const BUILT_IN_ROUTE_POLICY = Symbol.for("__ASKR_BUILT_IN_ROUTE_POLICY__");
|
|
5
|
-
function allow() {
|
|
6
|
-
return { kind: "allow" };
|
|
7
|
-
}
|
|
8
|
-
function redirect(to, init = {}) {
|
|
9
|
-
return {
|
|
10
|
-
kind: "redirect",
|
|
11
|
-
to,
|
|
12
|
-
...init.status ? { status: init.status } : {},
|
|
13
|
-
...init.replace !== void 0 ? { replace: init.replace } : {}
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
function deny(status) {
|
|
17
|
-
return {
|
|
18
|
-
kind: "deny",
|
|
19
|
-
status
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function unauthorized() {
|
|
23
|
-
return deny(401);
|
|
24
|
-
}
|
|
25
|
-
function forbidden() {
|
|
26
|
-
return deny(403);
|
|
27
|
-
}
|
|
28
|
-
function notFound() {
|
|
29
|
-
return deny(404);
|
|
30
|
-
}
|
|
31
|
-
function withRouteAuthOptions(context, auth) {
|
|
32
|
-
const internal = context;
|
|
33
|
-
if (!auth) {
|
|
34
|
-
delete internal[ROUTE_AUTH_OPTIONS];
|
|
35
|
-
return context;
|
|
36
|
-
}
|
|
37
|
-
internal[ROUTE_AUTH_OPTIONS] = auth;
|
|
38
|
-
return context;
|
|
39
|
-
}
|
|
40
|
-
function getRouteAuthOptions(context) {
|
|
41
|
-
return context[ROUTE_AUTH_OPTIONS];
|
|
42
|
-
}
|
|
43
|
-
function assertRouteAuthOptions(context) {
|
|
44
|
-
const auth = getRouteAuthOptions(context);
|
|
45
|
-
if (!auth?.resolve) throw new Error("Built-in auth policies require router auth configuration. Provide `auth` to registerRoutes(...), createSPA(...), hydrateSPA(...), or SSR route resolution.");
|
|
46
|
-
return auth;
|
|
47
|
-
}
|
|
48
|
-
function markBuiltInRoutePolicy(policy, metadata) {
|
|
49
|
-
Object.defineProperty(policy, BUILT_IN_ROUTE_POLICY, {
|
|
50
|
-
value: Object.freeze({ ...metadata }),
|
|
51
|
-
enumerable: false,
|
|
52
|
-
configurable: false
|
|
53
|
-
});
|
|
54
|
-
return policy;
|
|
55
|
-
}
|
|
56
|
-
function _getBuiltInRoutePolicy(policy) {
|
|
57
|
-
return policy[BUILT_IN_ROUTE_POLICY] ?? null;
|
|
58
|
-
}
|
|
59
|
-
function resolvePathSetting(value, fallback, context) {
|
|
60
|
-
if (!value) return fallback;
|
|
61
|
-
if (typeof value === "function") return value(context);
|
|
62
|
-
return value;
|
|
63
|
-
}
|
|
64
|
-
function appendNextTarget(path, href) {
|
|
65
|
-
const resolved = new URL(path, "http://localhost");
|
|
66
|
-
resolved.searchParams.set("next", href);
|
|
67
|
-
return `${resolved.pathname}${resolved.search}${resolved.hash}`;
|
|
68
|
-
}
|
|
69
|
-
function collectStringValues(value) {
|
|
70
|
-
if (typeof value === "string") return [value];
|
|
71
|
-
if (Array.isArray(value)) return value.filter((entry) => typeof entry === "string");
|
|
72
|
-
if (value instanceof Set) return Array.from(value).filter((entry) => typeof entry === "string");
|
|
73
|
-
return [];
|
|
74
|
-
}
|
|
75
|
-
function defaultHasRole(user, role) {
|
|
76
|
-
if (!user || typeof user !== "object") return false;
|
|
77
|
-
return collectStringValues(user.roles).includes(role);
|
|
78
|
-
}
|
|
79
|
-
function defaultHasPermission(user, permission) {
|
|
80
|
-
if (!user || typeof user !== "object") return false;
|
|
81
|
-
return collectStringValues(user.permissions).includes(permission);
|
|
82
|
-
}
|
|
83
|
-
function resolveUnauthenticatedRedirect(context) {
|
|
84
|
-
const loginPath = resolvePathSetting(assertRouteAuthOptions(context).loginPath, "/login", context);
|
|
85
|
-
if (isPromiseLike(loginPath)) return Promise.resolve(loginPath).then((nextPath) => redirect(appendNextTarget(nextPath, context.href), { replace: context.mode === "spa" }));
|
|
86
|
-
return redirect(appendNextTarget(loginPath, context.href), { replace: context.mode === "spa" });
|
|
87
|
-
}
|
|
88
|
-
function resolveAuthenticatedRedirect(context) {
|
|
89
|
-
const target = resolvePathSetting(assertRouteAuthOptions(context).guestRedirectTo, "/", context);
|
|
90
|
-
if (isPromiseLike(target)) return Promise.resolve(target).then((nextTarget) => redirect(nextTarget, { replace: true }));
|
|
91
|
-
return redirect(target, { replace: true });
|
|
92
|
-
}
|
|
93
|
-
function requireAuth() {
|
|
94
|
-
return markBuiltInRoutePolicy((context) => {
|
|
95
|
-
if (context.session) return allow();
|
|
96
|
-
return resolveUnauthenticatedRedirect(context);
|
|
97
|
-
}, { kind: "auth" });
|
|
98
|
-
}
|
|
99
|
-
function requireGuest() {
|
|
100
|
-
return markBuiltInRoutePolicy((context) => {
|
|
101
|
-
if (!context.session) return allow();
|
|
102
|
-
return resolveAuthenticatedRedirect(context);
|
|
103
|
-
}, { kind: "guest" });
|
|
104
|
-
}
|
|
105
|
-
function requireRole(role) {
|
|
106
|
-
return markBuiltInRoutePolicy((context) => {
|
|
107
|
-
if (!context.user) return resolveUnauthenticatedRedirect(context);
|
|
108
|
-
const auth = assertRouteAuthOptions(context);
|
|
109
|
-
const hasRole = auth.hasRole ? auth.hasRole(context.user, role, context) : defaultHasRole(context.user, role);
|
|
110
|
-
if (isPromiseLike(hasRole)) return Promise.resolve(hasRole).then((next) => next ? allow() : forbidden());
|
|
111
|
-
return hasRole ? allow() : forbidden();
|
|
112
|
-
}, {
|
|
113
|
-
kind: "role",
|
|
114
|
-
value: role
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
function requirePermission(permission) {
|
|
118
|
-
return markBuiltInRoutePolicy((context) => {
|
|
119
|
-
if (!context.user) return resolveUnauthenticatedRedirect(context);
|
|
120
|
-
const auth = assertRouteAuthOptions(context);
|
|
121
|
-
const hasPermission = auth.hasPermission ? auth.hasPermission(context.user, permission, context) : defaultHasPermission(context.user, permission);
|
|
122
|
-
if (isPromiseLike(hasPermission)) return Promise.resolve(hasPermission).then((next) => next ? allow() : forbidden());
|
|
123
|
-
return hasPermission ? allow() : forbidden();
|
|
124
|
-
}, {
|
|
125
|
-
kind: "permission",
|
|
126
|
-
value: permission
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
//#endregion
|
|
130
|
-
export { _getBuiltInRoutePolicy, allow, deny, forbidden, notFound, redirect, requireAuth, requireGuest, requirePermission, requireRole, unauthorized, withRouteAuthOptions };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { JSXElement } from "../common/jsx.js";
|
|
2
|
-
import { LayoutScopeRecord, PageScopeRecord, RouteComponent, RouteHandler, RouteRecord } from "../common/router.js";
|
|
3
|
-
|
|
4
|
-
//#region src/router/rendering.d.ts
|
|
5
|
-
declare function Outlet(): JSXElement;
|
|
6
|
-
declare function createRouteHandler(component: RouteComponent, pageChain: readonly PageScopeRecord[], layoutChain: readonly LayoutScopeRecord[], deferComponents?: boolean): RouteHandler;
|
|
7
|
-
declare function getRenderHandler(record: RouteRecord): RouteHandler;
|
|
8
|
-
//#endregion
|
|
9
|
-
export { Outlet };
|
package/dist/router/rendering.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { ELEMENT_TYPE, Fragment } from "../common/jsx.js";
|
|
2
|
-
import { defineContext, readContext } from "../runtime/context.js";
|
|
3
|
-
import "../runtime/index.js";
|
|
4
|
-
import { ROUTE_ROOT_COMPONENT } from "../common/router-internal.js";
|
|
5
|
-
//#region src/router/rendering.ts
|
|
6
|
-
const outletContext = defineContext(null);
|
|
7
|
-
function Outlet() {
|
|
8
|
-
return {
|
|
9
|
-
$$typeof: ELEMENT_TYPE,
|
|
10
|
-
type: Fragment,
|
|
11
|
-
props: { children: readContext(outletContext) },
|
|
12
|
-
key: null
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
function applyPageChain(pageChain, params, content, deferComponents = false) {
|
|
16
|
-
let nextContent = content;
|
|
17
|
-
for (let i = pageChain.length - 1; i >= 0; i--) nextContent = outletContext.Scope({
|
|
18
|
-
value: nextContent,
|
|
19
|
-
children: deferComponents ? createRouteComponentVNode(pageChain[i].component, params) : pageChain[i].component(params)
|
|
20
|
-
});
|
|
21
|
-
return nextContent;
|
|
22
|
-
}
|
|
23
|
-
function createRouteComponentVNode(component, params, routeRoot = false) {
|
|
24
|
-
return {
|
|
25
|
-
$$typeof: ELEMENT_TYPE,
|
|
26
|
-
type: component,
|
|
27
|
-
props: params,
|
|
28
|
-
key: null,
|
|
29
|
-
...routeRoot ? { [ROUTE_ROOT_COMPONENT]: true } : {}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function createRouteHandler(component, pageChain, layoutChain, deferComponents = false) {
|
|
33
|
-
return (params) => {
|
|
34
|
-
let content = deferComponents ? createRouteComponentVNode(component, params, true) : component(params);
|
|
35
|
-
content = applyPageChain(pageChain, params, content, deferComponents);
|
|
36
|
-
for (let i = layoutChain.length - 1; i >= 0; i--) {
|
|
37
|
-
const layout = layoutChain[i].component;
|
|
38
|
-
content = layout({ children: content });
|
|
39
|
-
}
|
|
40
|
-
return content;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function getRenderHandler(record) {
|
|
44
|
-
return record.renderHandler ?? createRouteHandler(record.component, record.pageChain, record.layoutChain, true);
|
|
45
|
-
}
|
|
46
|
-
//#endregion
|
|
47
|
-
export { Outlet, createRouteHandler, getRenderHandler };
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { isPromiseLike } from "../common/promise.js";
|
|
2
|
-
import { getActiveRenderContext } from "../common/render-context.js";
|
|
3
|
-
import { compileNodePolicies } from "./access.js";
|
|
4
|
-
import { getRenderHandler } from "./rendering.js";
|
|
5
|
-
import { getActiveRouteAuthOptions, getRouteRecords } from "./store.js";
|
|
6
|
-
import { buildRouteContext, buildRouteContextBase } from "./route-context.js";
|
|
7
|
-
import { computeMatchesFromRoutes, computeRouteActivityMatches, getMatchingRouteRecord, resolveRouteFromRoutes } from "./route-matching.js";
|
|
8
|
-
//#region src/router/resolution.ts
|
|
9
|
-
function getRoutePolicies(options) {
|
|
10
|
-
if (!options) return [];
|
|
11
|
-
if (options.policies?.length) return options.policies;
|
|
12
|
-
return compileNodePolicies(options);
|
|
13
|
-
}
|
|
14
|
-
function getDefaultRouteMode() {
|
|
15
|
-
if (typeof window !== "undefined") return "spa";
|
|
16
|
-
return "ssr";
|
|
17
|
-
}
|
|
18
|
-
function createRenderDataAwareHandler(handler, data) {
|
|
19
|
-
return (params, context) => {
|
|
20
|
-
const renderContext = getActiveRenderContext();
|
|
21
|
-
if (renderContext) renderContext.renderData = data ?? null;
|
|
22
|
-
return handler(params, context);
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
function buildRenderResult(record, params, mode) {
|
|
26
|
-
const renderHandler = getRenderHandler(record);
|
|
27
|
-
const loader = mode === "ssr" ? record.options?.loader : void 0;
|
|
28
|
-
if (loader) {
|
|
29
|
-
const loaded = loader({ params });
|
|
30
|
-
const finalize = (data) => ({
|
|
31
|
-
kind: "render",
|
|
32
|
-
handler: createRenderDataAwareHandler(renderHandler, data),
|
|
33
|
-
params
|
|
34
|
-
});
|
|
35
|
-
if (isPromiseLike(loaded)) return Promise.resolve(loaded).then((data) => finalize(data));
|
|
36
|
-
return finalize(loaded);
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
kind: "render",
|
|
40
|
-
handler: renderHandler,
|
|
41
|
-
params
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
function continueRoutePolicies(policies, context, record, params, startIndex = 0) {
|
|
45
|
-
for (let index = startIndex; index < policies.length; index += 1) {
|
|
46
|
-
const policyResult = policies[index](context);
|
|
47
|
-
if (isPromiseLike(policyResult)) return Promise.resolve(policyResult).then((next) => {
|
|
48
|
-
if (next.kind !== "allow") return next;
|
|
49
|
-
return continueRoutePolicies(policies, context, record, params, index + 1);
|
|
50
|
-
});
|
|
51
|
-
if (policyResult.kind !== "allow") return policyResult;
|
|
52
|
-
}
|
|
53
|
-
return buildRenderResult(record, params, context.mode);
|
|
54
|
-
}
|
|
55
|
-
function resolveRouteRequest(target, options = {}) {
|
|
56
|
-
const match = getMatchingRouteRecord(target, options.manifest?.records ?? getRouteRecords());
|
|
57
|
-
if (!match) return null;
|
|
58
|
-
const { record, params } = match;
|
|
59
|
-
const policies = getRoutePolicies(record.options);
|
|
60
|
-
const mode = options.mode ?? getDefaultRouteMode();
|
|
61
|
-
if (policies.length === 0) return buildRenderResult(record, params, mode);
|
|
62
|
-
const signal = options.signal ?? getActiveRenderContext()?.signal ?? new AbortController().signal;
|
|
63
|
-
const auth = getActiveRouteAuthOptions(options.auth ?? options.manifest?.auth);
|
|
64
|
-
const baseContext = buildRouteContextBase(target, params, {
|
|
65
|
-
mode,
|
|
66
|
-
signal
|
|
67
|
-
});
|
|
68
|
-
const finalize = (authState) => continueRoutePolicies(policies, buildRouteContext(target, params, {
|
|
69
|
-
mode,
|
|
70
|
-
signal,
|
|
71
|
-
auth,
|
|
72
|
-
session: authState.session,
|
|
73
|
-
user: authState.user
|
|
74
|
-
}), record, params);
|
|
75
|
-
if (!auth?.resolve) return finalize({
|
|
76
|
-
session: null,
|
|
77
|
-
user: null
|
|
78
|
-
});
|
|
79
|
-
const authState = auth.resolve(baseContext);
|
|
80
|
-
if (isPromiseLike(authState)) return Promise.resolve(authState).then((next) => finalize(next));
|
|
81
|
-
return finalize(authState);
|
|
82
|
-
}
|
|
83
|
-
//#endregion
|
|
84
|
-
export { computeMatchesFromRoutes, computeRouteActivityMatches, resolveRouteFromRoutes, resolveRouteRequest };
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { withRouteAuthOptions } from "./policy.js";
|
|
2
|
-
//#region src/router/route-context.ts
|
|
3
|
-
function parseLocation(url) {
|
|
4
|
-
try {
|
|
5
|
-
const parsedUrl = new URL(url, "http://localhost");
|
|
6
|
-
return {
|
|
7
|
-
pathname: parsedUrl.pathname,
|
|
8
|
-
search: parsedUrl.search,
|
|
9
|
-
hash: parsedUrl.hash
|
|
10
|
-
};
|
|
11
|
-
} catch {
|
|
12
|
-
return {
|
|
13
|
-
pathname: "/",
|
|
14
|
-
search: "",
|
|
15
|
-
hash: ""
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
function deepFreeze(obj) {
|
|
20
|
-
if (obj && typeof obj === "object" && !Object.isFrozen(obj)) {
|
|
21
|
-
Object.freeze(obj);
|
|
22
|
-
for (const key of Object.keys(obj)) {
|
|
23
|
-
const value = obj[key];
|
|
24
|
-
if (value && typeof value === "object") deepFreeze(value);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return obj;
|
|
28
|
-
}
|
|
29
|
-
function makeQuery(search) {
|
|
30
|
-
const searchParams = new URLSearchParams(search || "");
|
|
31
|
-
const mapping = /* @__PURE__ */ new Map();
|
|
32
|
-
for (const [key, value] of searchParams.entries()) {
|
|
33
|
-
const existing = mapping.get(key);
|
|
34
|
-
if (existing) existing.push(value);
|
|
35
|
-
else mapping.set(key, [value]);
|
|
36
|
-
}
|
|
37
|
-
return deepFreeze({
|
|
38
|
-
get(key) {
|
|
39
|
-
const values = mapping.get(key);
|
|
40
|
-
return values ? values[0] : null;
|
|
41
|
-
},
|
|
42
|
-
getAll(key) {
|
|
43
|
-
const values = mapping.get(key);
|
|
44
|
-
return values ? [...values] : [];
|
|
45
|
-
},
|
|
46
|
-
has(key) {
|
|
47
|
-
return mapping.has(key);
|
|
48
|
-
},
|
|
49
|
-
toJSON() {
|
|
50
|
-
const output = {};
|
|
51
|
-
for (const [key, values] of mapping.entries()) output[key] = values.length > 1 ? [...values] : values[0];
|
|
52
|
-
return output;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
function buildRouteContextBase(target, params, options) {
|
|
57
|
-
const parsed = parseLocation(target);
|
|
58
|
-
const href = `${parsed.pathname}${parsed.search}${parsed.hash}`;
|
|
59
|
-
return {
|
|
60
|
-
mode: options.mode,
|
|
61
|
-
params,
|
|
62
|
-
pathname: parsed.pathname,
|
|
63
|
-
search: parsed.search,
|
|
64
|
-
hash: parsed.hash,
|
|
65
|
-
href,
|
|
66
|
-
signal: options.signal
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
function buildRouteContext(target, params, options) {
|
|
70
|
-
return withRouteAuthOptions({
|
|
71
|
-
...buildRouteContextBase(target, params, options),
|
|
72
|
-
session: options.session ?? null,
|
|
73
|
-
user: options.user ?? null
|
|
74
|
-
}, options.auth);
|
|
75
|
-
}
|
|
76
|
-
//#endregion
|
|
77
|
-
export { buildRouteContext, buildRouteContextBase, deepFreeze, makeQuery, parseLocation };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ResolvedRoute, Route, RouteManifest, RouteMatch, RouteRecord } from "../common/router.js";
|
|
2
|
-
|
|
3
|
-
//#region src/router/route-matching.d.ts
|
|
4
|
-
declare function getMatchingRouteRecord(target: string, routeRecords: readonly RouteRecord[]): {
|
|
5
|
-
record: RouteRecord;
|
|
6
|
-
params: Record<string, string>;
|
|
7
|
-
} | null;
|
|
8
|
-
declare function computeMatchesFromRoutes(pathname: string, routesList: readonly Route[]): RouteMatch[];
|
|
9
|
-
declare function computeMatchesFromRouteRecords(pathname: string, routeRecords: readonly RouteRecord[]): RouteMatch[];
|
|
10
|
-
declare function computeRouteActivityMatches(pathname: string, options?: {
|
|
11
|
-
manifest?: RouteManifest;
|
|
12
|
-
routes?: readonly Route[];
|
|
13
|
-
}): RouteMatch[];
|
|
14
|
-
declare function resolveRoute(pathname: string): ResolvedRoute | null;
|
|
15
|
-
declare function resolveRouteFromRoutes(pathname: string, routeList: readonly Route[]): ResolvedRoute | null;
|
|
16
|
-
declare function _resolveRouteMatchFromRoutes(pathname: string, routeList: readonly Route[]): {
|
|
17
|
-
route: Route;
|
|
18
|
-
params: Record<string, string>;
|
|
19
|
-
} | null;
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { computeRank, matchSegments, parseSegments, splitPathSegments } from "./match.js";
|
|
2
|
-
import { getActiveRoutes, getRouteRecords, isRouteStoreRoutes } from "./store.js";
|
|
3
|
-
import { deepFreeze, parseLocation } from "./route-context.js";
|
|
4
|
-
//#region src/router/route-matching.ts
|
|
5
|
-
const routeSegsCache = /* @__PURE__ */ new WeakMap();
|
|
6
|
-
const routeRankCache = /* @__PURE__ */ new WeakMap();
|
|
7
|
-
const sortedListCache = /* @__PURE__ */ new WeakMap();
|
|
8
|
-
function cachedSegs(route) {
|
|
9
|
-
let segments = routeSegsCache.get(route);
|
|
10
|
-
if (!segments) {
|
|
11
|
-
segments = parseSegments(route.path);
|
|
12
|
-
routeSegsCache.set(route, segments);
|
|
13
|
-
}
|
|
14
|
-
return segments;
|
|
15
|
-
}
|
|
16
|
-
function cachedRank(route) {
|
|
17
|
-
let rank = routeRankCache.get(route);
|
|
18
|
-
if (rank === void 0) {
|
|
19
|
-
rank = computeRank(cachedSegs(route));
|
|
20
|
-
routeRankCache.set(route, rank);
|
|
21
|
-
}
|
|
22
|
-
return rank;
|
|
23
|
-
}
|
|
24
|
-
function cachedSortedList(routeList) {
|
|
25
|
-
let sorted = sortedListCache.get(routeList);
|
|
26
|
-
if (!sorted) {
|
|
27
|
-
sorted = [...routeList].sort((a, b) => cachedRank(b) - cachedRank(a));
|
|
28
|
-
sortedListCache.set(routeList, sorted);
|
|
29
|
-
}
|
|
30
|
-
return sorted;
|
|
31
|
-
}
|
|
32
|
-
function matchFallbackPrefix(pathname, fallbackPrefix) {
|
|
33
|
-
const normalizedPath = pathname.endsWith("/") && pathname !== "/" ? pathname.slice(0, -1) : pathname;
|
|
34
|
-
const normalizedPrefix = fallbackPrefix.endsWith("/") && fallbackPrefix !== "/" ? fallbackPrefix.slice(0, -1) : fallbackPrefix;
|
|
35
|
-
if (normalizedPrefix === "/") {
|
|
36
|
-
const urlParts = splitPathSegments(normalizedPath);
|
|
37
|
-
return { "*": urlParts.length === 0 ? "/" : urlParts.length === 1 ? urlParts[0] : "/" + urlParts.join("/") };
|
|
38
|
-
}
|
|
39
|
-
if (normalizedPath !== normalizedPrefix && !normalizedPath.startsWith(`${normalizedPrefix}/`)) return null;
|
|
40
|
-
const remainderParts = splitPathSegments(normalizedPath === normalizedPrefix ? "/" : normalizedPath.slice(normalizedPrefix.length));
|
|
41
|
-
return { "*": remainderParts.length === 0 ? "/" : remainderParts.length === 1 ? remainderParts[0] : "/" + remainderParts.join("/") };
|
|
42
|
-
}
|
|
43
|
-
function findBestResolvedRouteFromRoutes(pathname, routeList) {
|
|
44
|
-
const normalized = pathname.endsWith("/") && pathname !== "/" ? pathname.slice(0, -1) : pathname;
|
|
45
|
-
const urlParts = splitPathSegments(normalized);
|
|
46
|
-
const sorted = cachedSortedList(routeList);
|
|
47
|
-
let bestRoute = null;
|
|
48
|
-
let bestParams = {};
|
|
49
|
-
let bestRank = -Infinity;
|
|
50
|
-
for (const route of sorted) {
|
|
51
|
-
if (route.fallbackPrefix) continue;
|
|
52
|
-
const rank = cachedRank(route);
|
|
53
|
-
if (rank < bestRank) break;
|
|
54
|
-
if (bestRoute !== null && rank === bestRank) continue;
|
|
55
|
-
const params = matchSegments(urlParts, cachedSegs(route));
|
|
56
|
-
if (params !== null) {
|
|
57
|
-
bestRoute = route;
|
|
58
|
-
bestParams = params;
|
|
59
|
-
bestRank = rank;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (bestRoute !== null) return {
|
|
63
|
-
route: bestRoute,
|
|
64
|
-
params: bestParams
|
|
65
|
-
};
|
|
66
|
-
let bestFallback = null;
|
|
67
|
-
let bestFallbackParams = null;
|
|
68
|
-
let bestPrefixLength = -1;
|
|
69
|
-
for (const route of routeList) {
|
|
70
|
-
const internalRoute = route;
|
|
71
|
-
if (!internalRoute.fallbackPrefix) continue;
|
|
72
|
-
const params = matchFallbackPrefix(normalized, internalRoute.fallbackPrefix);
|
|
73
|
-
if (params === null) continue;
|
|
74
|
-
if (internalRoute.fallbackPrefix.length > bestPrefixLength) {
|
|
75
|
-
bestFallback = internalRoute;
|
|
76
|
-
bestFallbackParams = params;
|
|
77
|
-
bestPrefixLength = internalRoute.fallbackPrefix.length;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return bestFallback && bestFallbackParams ? {
|
|
81
|
-
route: bestFallback,
|
|
82
|
-
params: bestFallbackParams
|
|
83
|
-
} : null;
|
|
84
|
-
}
|
|
85
|
-
function findBestScopedFallbackRecord(pathname, routeRecords) {
|
|
86
|
-
let bestRecord = null;
|
|
87
|
-
let bestParams = null;
|
|
88
|
-
let bestPrefixLength = -1;
|
|
89
|
-
for (const routeRecord of routeRecords) {
|
|
90
|
-
const record = routeRecord;
|
|
91
|
-
if (!record.fallbackPrefix) continue;
|
|
92
|
-
const params = matchFallbackPrefix(pathname, record.fallbackPrefix);
|
|
93
|
-
if (params === null) continue;
|
|
94
|
-
if (record.fallbackPrefix.length > bestPrefixLength) {
|
|
95
|
-
bestRecord = record;
|
|
96
|
-
bestParams = params;
|
|
97
|
-
bestPrefixLength = record.fallbackPrefix.length;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return bestRecord && bestParams ? {
|
|
101
|
-
record: bestRecord,
|
|
102
|
-
params: bestParams
|
|
103
|
-
} : null;
|
|
104
|
-
}
|
|
105
|
-
function getMatchingRouteRecord(target, routeRecords) {
|
|
106
|
-
const location = parseLocation(target);
|
|
107
|
-
const normalized = location.pathname.endsWith("/") && location.pathname !== "/" ? location.pathname.slice(0, -1) : location.pathname;
|
|
108
|
-
const urlParts = splitPathSegments(normalized);
|
|
109
|
-
for (const record of routeRecords) {
|
|
110
|
-
if (record.fallbackPrefix) continue;
|
|
111
|
-
const params = matchSegments(urlParts, record.segments);
|
|
112
|
-
if (params !== null) return {
|
|
113
|
-
record,
|
|
114
|
-
params
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
return findBestScopedFallbackRecord(normalized, routeRecords);
|
|
118
|
-
}
|
|
119
|
-
function computeMatchesFromRoutes(pathname, routesList) {
|
|
120
|
-
const bestMatch = isRouteStoreRoutes(routesList) ? getMatchingRouteRecord(pathname, getRouteRecords()) : findBestResolvedRouteFromRoutes(pathname, routesList);
|
|
121
|
-
if (!bestMatch) return [];
|
|
122
|
-
return [{
|
|
123
|
-
path: "route" in bestMatch ? bestMatch.route.path : bestMatch.record.path,
|
|
124
|
-
params: deepFreeze({ ...bestMatch.params }),
|
|
125
|
-
name: "route" in bestMatch ? bestMatch.route.name : void 0,
|
|
126
|
-
namespace: "route" in bestMatch ? bestMatch.route.namespace : bestMatch.record.options.namespace
|
|
127
|
-
}];
|
|
128
|
-
}
|
|
129
|
-
function computeMatchesFromRouteRecords(pathname, routeRecords) {
|
|
130
|
-
const bestMatch = getMatchingRouteRecord(pathname, routeRecords);
|
|
131
|
-
if (!bestMatch) return [];
|
|
132
|
-
return [{
|
|
133
|
-
path: bestMatch.record.path,
|
|
134
|
-
params: deepFreeze({ ...bestMatch.params }),
|
|
135
|
-
namespace: bestMatch.record.options.namespace
|
|
136
|
-
}];
|
|
137
|
-
}
|
|
138
|
-
function computeRouteActivityMatches(pathname, options = {}) {
|
|
139
|
-
if (options.manifest) return computeMatchesFromRouteRecords(pathname, options.manifest.records);
|
|
140
|
-
if (options.routes) return computeMatchesFromRoutes(pathname, options.routes);
|
|
141
|
-
return computeMatchesFromRoutes(pathname, getActiveRoutes());
|
|
142
|
-
}
|
|
143
|
-
function resolveRoute(pathname) {
|
|
144
|
-
const normalized = pathname.endsWith("/") && pathname !== "/" ? pathname.slice(0, -1) : pathname;
|
|
145
|
-
const urlParts = splitPathSegments(normalized);
|
|
146
|
-
const records = getRouteRecords();
|
|
147
|
-
for (const record of records) {
|
|
148
|
-
if (record.fallbackPrefix) continue;
|
|
149
|
-
const params = matchSegments(urlParts, record.segments);
|
|
150
|
-
if (params !== null) return {
|
|
151
|
-
handler: record.handler,
|
|
152
|
-
params
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
const fallbackMatch = findBestScopedFallbackRecord(normalized, records);
|
|
156
|
-
return fallbackMatch ? {
|
|
157
|
-
handler: fallbackMatch.record.handler,
|
|
158
|
-
params: fallbackMatch.params
|
|
159
|
-
} : null;
|
|
160
|
-
}
|
|
161
|
-
function resolveRouteFromRoutes(pathname, routeList) {
|
|
162
|
-
if (isRouteStoreRoutes(routeList)) return resolveRoute(pathname);
|
|
163
|
-
const match = findBestResolvedRouteFromRoutes(pathname, routeList);
|
|
164
|
-
return match ? {
|
|
165
|
-
handler: match.route.handler,
|
|
166
|
-
params: match.params
|
|
167
|
-
} : null;
|
|
168
|
-
}
|
|
169
|
-
function _resolveRouteMatchFromRoutes(pathname, routeList) {
|
|
170
|
-
return findBestResolvedRouteFromRoutes(pathname, routeList);
|
|
171
|
-
}
|
|
172
|
-
//#endregion
|
|
173
|
-
export { _resolveRouteMatchFromRoutes, computeMatchesFromRouteRecords, computeMatchesFromRoutes, computeRouteActivityMatches, getMatchingRouteRecord, resolveRoute, resolveRouteFromRoutes };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
//#region src/router/route-query.d.ts
|
|
2
|
-
type RouteQueryParamValue = string | number | boolean | null | undefined;
|
|
3
|
-
type RouteQueryParamInput = RouteQueryParamValue | readonly RouteQueryParamValue[];
|
|
4
|
-
type RouteQueryUpdates = Record<string, RouteQueryParamInput>;
|
|
5
|
-
type RouteQueryUpdater = (searchParams: URLSearchParams) => void;
|
|
6
|
-
type UpdateRouteQueryOptions = {
|
|
7
|
-
/**
|
|
8
|
-
* Defaults to replace so high-frequency controls such as search inputs do not
|
|
9
|
-
* create one browser-history entry per character.
|
|
10
|
-
*/
|
|
11
|
-
history?: 'push' | 'replace';
|
|
12
|
-
replace?: boolean;
|
|
13
|
-
};
|
|
14
|
-
declare function updateRouteQuery(updates: RouteQueryUpdates | RouteQueryUpdater, options?: UpdateRouteQueryOptions): void;
|
|
15
|
-
//#endregion
|
|
16
|
-
export { RouteQueryParamInput, RouteQueryParamValue, RouteQueryUpdater, RouteQueryUpdates, UpdateRouteQueryOptions, updateRouteQuery };
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { getCurrentHref, getRegisteredAppsSnapshot, getWindowHref, parseTargetUrl, setCurrentRouteLocation, syncAppRegistrationLocation, syncRegisteredRouteSnapshot } from "./navigation-registry.js";
|
|
2
|
-
import { saveScrollPosition } from "./navigation-scroll.js";
|
|
3
|
-
//#region src/router/route-query.ts
|
|
4
|
-
function getRouteQueryHistoryMode(options) {
|
|
5
|
-
if (options.history) return options.history;
|
|
6
|
-
return options.replace === false ? "push" : "replace";
|
|
7
|
-
}
|
|
8
|
-
function setRouteQueryValue(searchParams, key, value) {
|
|
9
|
-
searchParams.delete(key);
|
|
10
|
-
if (Array.isArray(value)) {
|
|
11
|
-
for (const entry of value) {
|
|
12
|
-
if (entry === null || entry === void 0) continue;
|
|
13
|
-
searchParams.append(key, String(entry));
|
|
14
|
-
}
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
if (value === null || value === void 0) return;
|
|
18
|
-
searchParams.set(key, String(value));
|
|
19
|
-
}
|
|
20
|
-
function applyRouteQueryUpdates(searchParams, updates) {
|
|
21
|
-
if (typeof updates === "function") {
|
|
22
|
-
updates(searchParams);
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
for (const [key, value] of Object.entries(updates)) setRouteQueryValue(searchParams, key, value);
|
|
26
|
-
}
|
|
27
|
-
function updateRouteQuery(updates, options = {}) {
|
|
28
|
-
if (typeof window === "undefined") return;
|
|
29
|
-
const url = parseTargetUrl(getWindowHref());
|
|
30
|
-
applyRouteQueryUpdates(url.searchParams, updates);
|
|
31
|
-
const href = `${url.pathname}${url.search}${url.hash}`;
|
|
32
|
-
if (href === getWindowHref()) return;
|
|
33
|
-
const historyMode = getRouteQueryHistoryMode(options);
|
|
34
|
-
if (historyMode === "push") saveScrollPosition(getCurrentHref());
|
|
35
|
-
const state = window.history.state && typeof window.history.state === "object" ? window.history.state : {};
|
|
36
|
-
window.history[historyMode === "replace" ? "replaceState" : "pushState"]({
|
|
37
|
-
...state,
|
|
38
|
-
path: href
|
|
39
|
-
}, "", href);
|
|
40
|
-
setCurrentRouteLocation(url.pathname, href);
|
|
41
|
-
for (const app of getRegisteredAppsSnapshot()) syncAppRegistrationLocation(app, url.pathname, href);
|
|
42
|
-
syncRegisteredRouteSnapshot();
|
|
43
|
-
}
|
|
44
|
-
//#endregion
|
|
45
|
-
export { updateRouteQuery };
|
package/dist/router/route.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { AccessDecision, AccessDenyDecision, AccessRedirectDecision, GroupHelperOptions, LayoutScopeRecord, PageHelperOptions, PageScopeRecord, ParsedSegment, RegisterRoutesOptions, ResolvedRoute, Route, RouteAuthOptions, RouteComponent, RouteContext, RouteDefinition, RouteHandler, RouteManifest, RouteMatch, RouteOptions, RouteParams, RoutePathParams, RoutePolicy, RouteQuery, RouteRecord, RouteRegistry, RouteRenderResult, RouteRequestOptions, RouteRequestResult, RouteSnapshot } from "../common/router.js";
|
|
2
|
-
import { fallback, group, index, page, registerRoutes, route } from "./authoring.js";
|
|
3
|
-
import { currentRoute } from "./activity.js";
|
|
4
|
-
import { clearRoutes, createRouteRegistry, getManifest } from "./manifest.js";
|
|
5
|
-
import { getRoutes } from "./store.js";
|
|
6
|
-
import { lazy } from "./lazy.js";
|
|
7
|
-
import { Outlet } from "./rendering.js";
|
|
8
|
-
export { Outlet, clearRoutes, createRouteRegistry, currentRoute, fallback, getManifest, getRoutes, group, index, lazy, page, registerRoutes, route };
|
package/dist/router/route.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { _getBuiltInRoutePolicy } from "./policy.js";
|
|
2
|
-
import { Outlet } from "./rendering.js";
|
|
3
|
-
import { _setActiveRouteAuthOptions, getRoutes, hasRegisteredRoutes, lockRouteRegistration } from "./store.js";
|
|
4
|
-
import { fallback, group, index, page, registerRoutes, route } from "./authoring.js";
|
|
5
|
-
import { computeRouteActivityMatches, resolveRouteFromRoutes } from "./route-matching.js";
|
|
6
|
-
import { resolveRouteRequest } from "./resolution.js";
|
|
7
|
-
import { currentRoute, setServerLocation, syncCurrentRouteSnapshot } from "./activity.js";
|
|
8
|
-
import { _drainLazy, _snapshotLazy, _snapshotRouteSourceLazy, lazy } from "./lazy.js";
|
|
9
|
-
import { _applyManifest, clearRoutes, createRouteRegistry, getManifest } from "./manifest.js";
|
|
10
|
-
export { Outlet, _applyManifest, _drainLazy, _getBuiltInRoutePolicy, _setActiveRouteAuthOptions, _snapshotLazy, _snapshotRouteSourceLazy, clearRoutes, computeRouteActivityMatches, createRouteRegistry, currentRoute, fallback, getManifest, getRoutes, group, hasRegisteredRoutes, index, lazy, lockRouteRegistration, page, registerRoutes, resolveRouteFromRoutes, resolveRouteRequest, route, setServerLocation, syncCurrentRouteSnapshot };
|