@cratis/scene.react 4.13.0 → 4.14.0
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/cjs/core/coreComponents.js +1 -1
- package/dist/cjs/index.js +12 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/navigation/SceneNavigationContext.js.map +1 -1
- package/dist/cjs/navigation/SceneNavigationHost.js +19 -44
- package/dist/cjs/navigation/SceneNavigationHost.js.map +1 -1
- package/dist/cjs/navigation/createBrowserSceneHistory.js +39 -0
- package/dist/cjs/navigation/createBrowserSceneHistory.js.map +1 -0
- package/dist/cjs/navigation/createMemorySceneHistory.js +53 -0
- package/dist/cjs/navigation/createMemorySceneHistory.js.map +1 -0
- package/dist/cjs/navigation/matchSceneRoute.js +43 -0
- package/dist/cjs/navigation/matchSceneRoute.js.map +1 -0
- package/dist/cjs/navigation/resolveDestination.js +1 -0
- package/dist/cjs/navigation/resolveDestination.js.map +1 -1
- package/dist/cjs/navigation/sceneRoutesFrom.js +37 -0
- package/dist/cjs/navigation/sceneRoutesFrom.js.map +1 -0
- package/dist/cjs/navigation/useSceneHistoryNavigation.js +112 -0
- package/dist/cjs/navigation/useSceneHistoryNavigation.js.map +1 -0
- package/dist/esm/core/coreComponents.js +1 -1
- package/dist/esm/index.js +6 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/navigation/DestinationResolution.d.ts +1 -0
- package/dist/esm/navigation/DestinationResolution.d.ts.map +1 -1
- package/dist/esm/navigation/DialogResult.d.ts +5 -0
- package/dist/esm/navigation/DialogResult.d.ts.map +1 -0
- package/dist/esm/navigation/DialogResult.js +2 -0
- package/dist/esm/navigation/DialogResult.js.map +1 -0
- package/dist/esm/navigation/SceneHistory.d.ts +10 -0
- package/dist/esm/navigation/SceneHistory.d.ts.map +1 -0
- package/dist/esm/navigation/SceneHistory.js +2 -0
- package/dist/esm/navigation/SceneHistory.js.map +1 -0
- package/dist/esm/navigation/SceneNavigationContext.d.ts +6 -1
- package/dist/esm/navigation/SceneNavigationContext.d.ts.map +1 -1
- package/dist/esm/navigation/SceneNavigationContext.js.map +1 -1
- package/dist/esm/navigation/SceneNavigationHost.d.ts +7 -2
- package/dist/esm/navigation/SceneNavigationHost.d.ts.map +1 -1
- package/dist/esm/navigation/SceneNavigationHost.js +20 -45
- package/dist/esm/navigation/SceneNavigationHost.js.map +1 -1
- package/dist/esm/navigation/SceneNavigationState.d.ts +8 -0
- package/dist/esm/navigation/SceneNavigationState.d.ts.map +1 -0
- package/dist/esm/navigation/SceneNavigationState.js +2 -0
- package/dist/esm/navigation/SceneNavigationState.js.map +1 -0
- package/dist/esm/navigation/SceneRoute.d.ts +6 -0
- package/dist/esm/navigation/SceneRoute.d.ts.map +1 -0
- package/dist/esm/navigation/SceneRoute.js +2 -0
- package/dist/esm/navigation/SceneRoute.js.map +1 -0
- package/dist/esm/navigation/createBrowserSceneHistory.d.ts +4 -0
- package/dist/esm/navigation/createBrowserSceneHistory.d.ts.map +1 -0
- package/dist/esm/navigation/createBrowserSceneHistory.js +37 -0
- package/dist/esm/navigation/createBrowserSceneHistory.js.map +1 -0
- package/dist/esm/navigation/createMemorySceneHistory.d.ts +7 -0
- package/dist/esm/navigation/createMemorySceneHistory.d.ts.map +1 -0
- package/dist/esm/navigation/createMemorySceneHistory.js +51 -0
- package/dist/esm/navigation/createMemorySceneHistory.js.map +1 -0
- package/dist/esm/navigation/index.d.ts +10 -1
- package/dist/esm/navigation/index.d.ts.map +1 -1
- package/dist/esm/navigation/index.js +10 -1
- package/dist/esm/navigation/index.js.map +1 -1
- package/dist/esm/navigation/matchSceneRoute.d.ts +7 -0
- package/dist/esm/navigation/matchSceneRoute.d.ts.map +1 -0
- package/dist/esm/navigation/matchSceneRoute.js +41 -0
- package/dist/esm/navigation/matchSceneRoute.js.map +1 -0
- package/dist/esm/navigation/resolveDestination.d.ts.map +1 -1
- package/dist/esm/navigation/resolveDestination.js +1 -0
- package/dist/esm/navigation/resolveDestination.js.map +1 -1
- package/dist/esm/navigation/sceneRoutesFrom.d.ts +4 -0
- package/dist/esm/navigation/sceneRoutesFrom.d.ts.map +1 -0
- package/dist/esm/navigation/sceneRoutesFrom.js +35 -0
- package/dist/esm/navigation/sceneRoutesFrom.js.map +1 -0
- package/dist/esm/navigation/useSceneHistoryNavigation.d.ts +6 -0
- package/dist/esm/navigation/useSceneHistoryNavigation.d.ts.map +1 -0
- package/dist/esm/navigation/useSceneHistoryNavigation.js +110 -0
- package/dist/esm/navigation/useSceneHistoryNavigation.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/navigation/DestinationResolution.ts +3 -0
- package/navigation/DialogResult.ts +8 -0
- package/navigation/SceneHistory.ts +24 -0
- package/navigation/SceneNavigationContext.tsx +16 -1
- package/navigation/SceneNavigationHost.tsx +30 -40
- package/navigation/SceneNavigationState.ts +19 -0
- package/navigation/SceneRoute.ts +12 -0
- package/navigation/createBrowserSceneHistory.ts +40 -0
- package/navigation/createMemorySceneHistory.ts +44 -0
- package/navigation/index.ts +10 -1
- package/navigation/matchSceneRoute.ts +45 -0
- package/navigation/resolveDestination.ts +1 -0
- package/navigation/sceneRoutesFrom.ts +24 -0
- package/navigation/useSceneHistoryNavigation.ts +80 -0
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DestinationResolution.d.ts","sourceRoot":"","sources":["../../../navigation/DestinationResolution.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,WAAW,qBAAqB;IAClC,IAAI,EAAE,eAAe,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"DestinationResolution.d.ts","sourceRoot":"","sources":["../../../navigation/DestinationResolution.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,WAAW,qBAAqB;IAClC,IAAI,EAAE,eAAe,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,MAAM,EAAE,UAAU,GAAG,YAAY,GAAG,cAAc,CAAC;IACnD,WAAW,EAAE,MAAM,EAAE,CAAC;CACzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DialogResult.d.ts","sourceRoot":"","sources":["../../../navigation/DialogResult.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,YAAY;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DialogResult.js","sourceRoot":"","sources":["../../../navigation/DialogResult.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SceneNavigationState } from './SceneNavigationState';
|
|
2
|
+
export interface SceneHistory {
|
|
3
|
+
location(): string | undefined;
|
|
4
|
+
state(): SceneNavigationState | undefined;
|
|
5
|
+
push(state: SceneNavigationState): void;
|
|
6
|
+
replace(state: SceneNavigationState): void;
|
|
7
|
+
back(): void;
|
|
8
|
+
listen(listener: (url: string | undefined, state: SceneNavigationState | undefined) => void): () => void;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=SceneHistory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SceneHistory.d.ts","sourceRoot":"","sources":["../../../navigation/SceneHistory.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAO9D,MAAM,WAAW,YAAY;IAEzB,QAAQ,IAAI,MAAM,GAAG,SAAS,CAAC;IAG/B,KAAK,IAAI,oBAAoB,GAAG,SAAS,CAAC;IAE1C,IAAI,CAAC,KAAK,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACxC,OAAO,CAAC,KAAK,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAC3C,IAAI,IAAI,IAAI,CAAC;IAGb,MAAM,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,oBAAoB,GAAG,SAAS,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CAC5G"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SceneHistory.js","sourceRoot":"","sources":["../../../navigation/SceneHistory.ts"],"names":[],"mappings":""}
|
|
@@ -2,14 +2,19 @@ import { ReactNode } from 'react';
|
|
|
2
2
|
import { BindingScope } from '@cratis/scene.engine';
|
|
3
3
|
import { DestinationReference } from '@cratis/scene.model';
|
|
4
4
|
import { DestinationResolution } from './DestinationResolution';
|
|
5
|
+
import { DialogResult } from './DialogResult';
|
|
5
6
|
export interface SceneNavigationContextValue {
|
|
6
7
|
currentScreen: string;
|
|
7
8
|
currentUrl?: string;
|
|
8
9
|
currentOutlet?: string;
|
|
9
10
|
currentDialog?: string;
|
|
11
|
+
currentParameters: Record<string, string>;
|
|
12
|
+
dialogResult?: DialogResult;
|
|
13
|
+
unresolvedUrl?: string;
|
|
10
14
|
bindingScope: BindingScope;
|
|
11
15
|
navigate(destination: DestinationReference): DestinationResolution;
|
|
12
|
-
closeDialog(): void;
|
|
16
|
+
closeDialog(result?: unknown): void;
|
|
17
|
+
back(): void;
|
|
13
18
|
}
|
|
14
19
|
export interface SceneNavigationProviderProps {
|
|
15
20
|
value: SceneNavigationContextValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SceneNavigationContext.d.ts","sourceRoot":"","sources":["../../../navigation/SceneNavigationContext.tsx"],"names":[],"mappings":"AAGA,O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,wBAAgB,kBAAkB,IAAI,2BAA2B,CAIhE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SceneNavigationContext.js","sources":["../../../navigation/SceneNavigationContext.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ReactNode, createContext, useContext } from 'react';\nimport { BindingScope } from '@cratis/scene.engine';\nimport { DestinationReference } from '@cratis/scene.model';\nimport { DestinationResolution } from './DestinationResolution';\n\nexport interface SceneNavigationContextValue {\n currentScreen: string;\n currentUrl?: string;\n currentOutlet?: string;\n currentDialog?: string;\n bindingScope: BindingScope;\n navigate(destination: DestinationReference): DestinationResolution;\n closeDialog(): void;\n}\n\nconst Context = createContext<SceneNavigationContextValue | undefined>(undefined);\n\nexport interface SceneNavigationProviderProps {\n value: SceneNavigationContextValue;\n children: ReactNode;\n}\n\nexport function SceneNavigationProvider({ value, children }: SceneNavigationProviderProps) {\n return <Context.Provider value={value}>{children}</Context.Provider>;\n}\n\nexport function useSceneNavigation(): SceneNavigationContextValue {\n const context = useContext(Context);\n if (!context) throw new Error('No Scene navigation context is available.');\n return context;\n}\n"],"names":["Context","createContext","undefined","SceneNavigationProvider","value","children","_jsx","Provider","useSceneNavigation","context","useContext","Error"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"SceneNavigationContext.js","sources":["../../../navigation/SceneNavigationContext.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ReactNode, createContext, useContext } from 'react';\nimport { BindingScope } from '@cratis/scene.engine';\nimport { DestinationReference } from '@cratis/scene.model';\nimport { DestinationResolution } from './DestinationResolution';\nimport { DialogResult } from './DialogResult';\n\nexport interface SceneNavigationContextValue {\n currentScreen: string;\n currentUrl?: string;\n currentOutlet?: string;\n currentDialog?: string;\n\n /** The route parameters of the current entry - from the destination that opened it, or the deep link. */\n currentParameters: Record<string, string>;\n\n /** What the last dialog returned when it closed. */\n dialogResult?: DialogResult;\n\n /** A deep link that matched no route; the host fell back to its initial screen. */\n unresolvedUrl?: string;\n bindingScope: BindingScope;\n navigate(destination: DestinationReference): DestinationResolution;\n\n /** Closes the open dialog, returning to the entry that opened it, and records its result. */\n closeDialog(result?: unknown): void;\n\n /** Goes back one history entry. */\n back(): void;\n}\n\nconst Context = createContext<SceneNavigationContextValue | undefined>(undefined);\n\nexport interface SceneNavigationProviderProps {\n value: SceneNavigationContextValue;\n children: ReactNode;\n}\n\nexport function SceneNavigationProvider({ value, children }: SceneNavigationProviderProps) {\n return <Context.Provider value={value}>{children}</Context.Provider>;\n}\n\nexport function useSceneNavigation(): SceneNavigationContextValue {\n const context = useContext(Context);\n if (!context) throw new Error('No Scene navigation context is available.');\n return context;\n}\n"],"names":["Context","createContext","undefined","SceneNavigationProvider","value","children","_jsx","Provider","useSceneNavigation","context","useContext","Error"],"mappings":";;;AAiCA,MAAMA,wBAAUC,aAAAA,CAAuDC,SAAAA,CAAAA;AAOhE,SAASC,uBAAAA,CAAwB,EAAEC,KAAK,EAAEC,QAAQ,EAAgC,EAAA;IACrF,qBAAOC,GAAA,CAACN,QAAQO,QAAQ,EAAA;QAACH,KAAAA,EAAOA,KAAAA;AAAQC,QAAAA,QAAAA,EAAAA;;AAC5C;AAEO,SAASG,kBAAAA,GAAAA;AACZ,IAAA,MAAMC,UAAUC,UAAAA,CAAWV,OAAAA,CAAAA;AAC3B,IAAA,IAAI,CAACS,OAAAA,EAAS,MAAM,IAAIE,KAAAA,CAAM,2CAAA,CAAA;IAC9B,OAAOF,OAAAA;AACX;;"}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { BindingScope } from '@cratis/scene.engine';
|
|
2
|
-
import { SceneElement } from '@cratis/scene.model';
|
|
2
|
+
import { DestinationReference, SceneElement } from '@cratis/scene.model';
|
|
3
3
|
import { ComponentRegistry } from '../renderer';
|
|
4
|
+
import { SceneHistory } from './SceneHistory';
|
|
5
|
+
import { SceneRoute } from './SceneRoute';
|
|
4
6
|
export interface SceneNavigationHostProps {
|
|
5
7
|
screens: Record<string, SceneElement>;
|
|
6
8
|
dialogs?: Record<string, SceneElement>;
|
|
7
9
|
initialScreen: string;
|
|
8
10
|
registry: ComponentRegistry;
|
|
9
11
|
bindingScope?: BindingScope;
|
|
12
|
+
history?: SceneHistory;
|
|
13
|
+
destinations?: DestinationReference[];
|
|
14
|
+
routes?: SceneRoute[];
|
|
10
15
|
}
|
|
11
|
-
export declare function SceneNavigationHost({ screens, dialogs, initialScreen, registry, bindingScope }: SceneNavigationHostProps): import("react").JSX.Element;
|
|
16
|
+
export declare function SceneNavigationHost({ screens, dialogs, initialScreen, registry, bindingScope, history, destinations, routes }: SceneNavigationHostProps): import("react").JSX.Element;
|
|
12
17
|
//# sourceMappingURL=SceneNavigationHost.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SceneNavigationHost.d.ts","sourceRoot":"","sources":["../../../navigation/SceneNavigationHost.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,
|
|
1
|
+
{"version":3,"file":"SceneNavigationHost.d.ts","sourceRoot":"","sources":["../../../navigation/SceneNavigationHost.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI1C,MAAM,WAAW,wBAAwB;IACrC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACvC,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,YAAY,CAAC,EAAE,YAAY,CAAC;IAM5B,OAAO,CAAC,EAAE,YAAY,CAAC;IAGvB,YAAY,CAAC,EAAE,oBAAoB,EAAE,CAAC;IAGtC,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC;CACzB;AAOD,wBAAgB,mBAAmB,CAAC,EAAE,OAAO,EAAE,OAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,YAAiB,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,wBAAwB,+BAgBjK"}
|
|
@@ -1,58 +1,31 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
-
import { useState,
|
|
3
|
-
import { DestinationKind } from '@cratis/scene.model';
|
|
2
|
+
import { useState, useMemo } from 'react';
|
|
4
3
|
import { SceneElementView } from '../SceneElementView.js';
|
|
4
|
+
import { createMemorySceneHistory } from './createMemorySceneHistory.js';
|
|
5
5
|
import { SceneNavigationProvider } from './SceneNavigationContext.js';
|
|
6
|
-
import {
|
|
6
|
+
import { sceneRoutesFrom } from './sceneRoutesFrom.js';
|
|
7
|
+
import { useSceneHistoryNavigation } from './useSceneHistoryNavigation.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Executes Scene destinations against an in-memory rendered hierarchy: screen routes replace outlets,
|
|
10
|
-
* dialog destinations render dialog content
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const [
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (resolution.kind === DestinationKind.Dialog) {
|
|
19
|
-
setCurrentDialog(resolution.dialog);
|
|
20
|
-
return resolution;
|
|
21
|
-
}
|
|
22
|
-
if (resolution.kind !== DestinationKind.External) {
|
|
23
|
-
setCurrentScreen(destination.screen ?? destination.slice ?? currentScreen);
|
|
24
|
-
setCurrentOutlet(resolution.outlet);
|
|
25
|
-
}
|
|
26
|
-
setCurrentUrl(resolution.url);
|
|
27
|
-
return resolution;
|
|
28
|
-
}, [
|
|
29
|
-
bindingScope,
|
|
30
|
-
currentScreen
|
|
11
|
+
* dialog destinations render dialog content over the screen that opened them, and external destinations
|
|
12
|
+
* only report their resolved action. Every navigation is a history entry.
|
|
13
|
+
*/ function SceneNavigationHost({ screens, dialogs = {}, initialScreen, registry, bindingScope = {}, history, destinations, routes }) {
|
|
14
|
+
const [memoryHistory] = useState(()=>createMemorySceneHistory());
|
|
15
|
+
const routeTable = useMemo(()=>routes ?? sceneRoutesFrom(Object.keys(screens), destinations), [
|
|
16
|
+
destinations,
|
|
17
|
+
routes,
|
|
18
|
+
screens
|
|
31
19
|
]);
|
|
32
|
-
const value =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
currentOutlet,
|
|
36
|
-
currentDialog,
|
|
37
|
-
bindingScope,
|
|
38
|
-
navigate,
|
|
39
|
-
closeDialog: ()=>setCurrentDialog(undefined)
|
|
40
|
-
}), [
|
|
41
|
-
bindingScope,
|
|
42
|
-
currentDialog,
|
|
43
|
-
currentOutlet,
|
|
44
|
-
currentScreen,
|
|
45
|
-
currentUrl,
|
|
46
|
-
navigate
|
|
47
|
-
]);
|
|
48
|
-
const screen = screens[currentScreen];
|
|
49
|
-
const dialog = currentDialog ? dialogs[currentDialog] : undefined;
|
|
20
|
+
const value = useSceneHistoryNavigation(history ?? memoryHistory, routeTable, initialScreen, bindingScope);
|
|
21
|
+
const screen = screens[value.currentScreen];
|
|
22
|
+
const dialog = value.currentDialog ? dialogs[value.currentDialog] : undefined;
|
|
50
23
|
return /*#__PURE__*/ jsxs(SceneNavigationProvider, {
|
|
51
24
|
value: value,
|
|
52
25
|
children: [
|
|
53
26
|
/*#__PURE__*/ jsx("div", {
|
|
54
|
-
"data-scene-outlet": currentOutlet ?? 'primary',
|
|
55
|
-
"data-scene-url": currentUrl,
|
|
27
|
+
"data-scene-outlet": value.currentOutlet ?? 'primary',
|
|
28
|
+
"data-scene-url": value.currentUrl,
|
|
56
29
|
children: screen && /*#__PURE__*/ jsx(SceneElementView, {
|
|
57
30
|
element: screen,
|
|
58
31
|
registry: registry,
|
|
@@ -63,7 +36,9 @@ import { resolveDestination } from './resolveDestination.js';
|
|
|
63
36
|
}),
|
|
64
37
|
dialog && /*#__PURE__*/ jsx("div", {
|
|
65
38
|
role: "dialog",
|
|
66
|
-
"
|
|
39
|
+
"aria-modal": "true",
|
|
40
|
+
"aria-label": value.currentDialog,
|
|
41
|
+
"data-scene-dialog": value.currentDialog,
|
|
67
42
|
children: /*#__PURE__*/ jsx(SceneElementView, {
|
|
68
43
|
element: dialog,
|
|
69
44
|
registry: registry,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SceneNavigationHost.js","sources":["../../../navigation/SceneNavigationHost.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport {
|
|
1
|
+
{"version":3,"file":"SceneNavigationHost.js","sources":["../../../navigation/SceneNavigationHost.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { useMemo, useState } from 'react';\nimport { BindingScope } from '@cratis/scene.engine';\nimport { DestinationReference, SceneElement } from '@cratis/scene.model';\nimport { SceneElementView } from '../SceneElementView';\nimport { ComponentRegistry } from '../renderer';\nimport { createMemorySceneHistory } from './createMemorySceneHistory';\nimport { SceneHistory } from './SceneHistory';\nimport { SceneNavigationProvider } from './SceneNavigationContext';\nimport { SceneRoute } from './SceneRoute';\nimport { sceneRoutesFrom } from './sceneRoutesFrom';\nimport { useSceneHistoryNavigation } from './useSceneHistoryNavigation';\n\nexport interface SceneNavigationHostProps {\n screens: Record<string, SceneElement>;\n dialogs?: Record<string, SceneElement>;\n initialScreen: string;\n registry: ComponentRegistry;\n bindingScope?: BindingScope;\n\n /**\n * Where entries are recorded. `createBrowserSceneHistory()` drives the address bar, so deep links,\n * refresh and back/forward work; the default is an in-memory history for embedded hosts.\n */\n history?: SceneHistory;\n\n /** The destinations the application navigates to, so their route overrides can be deep linked. */\n destinations?: DestinationReference[];\n\n /** An explicit route table, used instead of the one derived from `screens` and `destinations`. */\n routes?: SceneRoute[];\n}\n\n/**\n * Executes Scene destinations against an in-memory rendered hierarchy: screen routes replace outlets,\n * dialog destinations render dialog content over the screen that opened them, and external destinations\n * only report their resolved action. Every navigation is a history entry.\n */\nexport function SceneNavigationHost({ screens, dialogs = {}, initialScreen, registry, bindingScope = {}, history, destinations, routes }: SceneNavigationHostProps) {\n const [memoryHistory] = useState(() => createMemorySceneHistory());\n const routeTable = useMemo(() => routes ?? sceneRoutesFrom(Object.keys(screens), destinations), [destinations, routes, screens]);\n const value = useSceneHistoryNavigation(history ?? memoryHistory, routeTable, initialScreen, bindingScope);\n\n const screen = screens[value.currentScreen];\n const dialog = value.currentDialog ? dialogs[value.currentDialog] : undefined;\n\n return <SceneNavigationProvider value={value}>\n <div data-scene-outlet={value.currentOutlet ?? 'primary'} data-scene-url={value.currentUrl}>\n {screen && <SceneElementView element={screen} registry={registry} dataContext={bindingScope.dataContext} queryResults={bindingScope.queryResults} componentOutputs={bindingScope.componentOutputs} />}\n </div>\n {dialog && <div role='dialog' aria-modal='true' aria-label={value.currentDialog} data-scene-dialog={value.currentDialog}>\n <SceneElementView element={dialog} registry={registry} dataContext={bindingScope.dataContext} queryResults={bindingScope.queryResults} componentOutputs={bindingScope.componentOutputs} />\n </div>}\n </SceneNavigationProvider>;\n}\n"],"names":["SceneNavigationHost","screens","dialogs","initialScreen","registry","bindingScope","history","destinations","routes","memoryHistory","useState","createMemorySceneHistory","routeTable","useMemo","sceneRoutesFrom","Object","keys","value","useSceneHistoryNavigation","screen","currentScreen","dialog","currentDialog","undefined","_jsxs","SceneNavigationProvider","_jsx","div","data-scene-outlet","currentOutlet","data-scene-url","currentUrl","SceneElementView","element","dataContext","queryResults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W;AAAEC,oBAAAA,YAAAA,EAAc9B,aAAa8B,YAAY;AAAEC,oBAAAA,gBAAAA,EAAkB/B,aAAa+B;;;AAEpLf,YAAAA,MAAAA,kBAAUK,GAAA,CAACC,KAAAA,EAAAA;gBAAIU,IAAAA,EAAK,QAAA;gBAASC,YAAAA,EAAW,MAAA;AAAOC,gBAAAA,YAAAA,EAAYtB,MAAMK,aAAa;AAAEkB,gBAAAA,mBAAAA,EAAmBvB,MAAMK,aAAa;AACnH,gBAAA,QAAA,gBAAAI,GAAA,CAACM,gBAAAA,EAAAA;oBAAiBC,OAAAA,EAASZ,MAAAA;oBAAQjB,QAAAA,EAAUA,QAAAA;AAAU8B,oBAAAA,WAAAA,EAAa7B,aAAa6B,WAAW;AAAEC,oBAAAA,YAAAA,EAAc9B,aAAa8B,YAAY;AAAEC,oBAAAA,gBAAAA,EAAkB/B,aAAa+B;;;;;AAGlL;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SceneNavigationState.d.ts","sourceRoot":"","sources":["../../../navigation/SceneNavigationState.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,oBAAoB;IACjC,MAAM,EAAE,MAAM,CAAC;IAGf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SceneNavigationState.js","sourceRoot":"","sources":["../../../navigation/SceneNavigationState.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SceneRoute.d.ts","sourceRoot":"","sources":["../../../navigation/SceneRoute.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,UAAU;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SceneRoute.js","sourceRoot":"","sources":["../../../navigation/SceneRoute.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SceneHistory } from './SceneHistory';
|
|
2
|
+
export type SceneBrowserWindow = Pick<Window, 'history' | 'location' | 'addEventListener' | 'removeEventListener'>;
|
|
3
|
+
export declare function createBrowserSceneHistory(browser?: SceneBrowserWindow, basePath?: string): SceneHistory;
|
|
4
|
+
//# sourceMappingURL=createBrowserSceneHistory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBrowserSceneHistory.d.ts","sourceRoot":"","sources":["../../../navigation/createBrowserSceneHistory.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI9C,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,kBAAkB,GAAG,qBAAqB,CAAC,CAAC;AASnH,wBAAgB,yBAAyB,CAAC,OAAO,GAAE,kBAA2B,EAAE,QAAQ,SAAM,GAAG,YAAY,CAuB5G"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
const stateKey = 'sceneNavigation';
|
|
4
|
+
/**
|
|
5
|
+
* A history backed by the browser's `history` API under a base path such as `/app/`. Entries carry their
|
|
6
|
+
* navigation state, so back and forward restore the screen, outlet, parameters and dialog without
|
|
7
|
+
* re-resolving; an entry without state - a typed or bookmarked URL - is reported by URL alone.
|
|
8
|
+
*/ function createBrowserSceneHistory(browser = window, basePath = '/') {
|
|
9
|
+
const base = basePath.endsWith('/') ? basePath : `${basePath}/`;
|
|
10
|
+
const href = (url)=>`${base}${url ?? ''}`;
|
|
11
|
+
const location = ()=>{
|
|
12
|
+
const current = `${browser.location.pathname}${browser.location.search}`;
|
|
13
|
+
if (!current.startsWith(base)) return undefined;
|
|
14
|
+
const relative = current.substring(base.length);
|
|
15
|
+
return relative.length ? relative : undefined;
|
|
16
|
+
};
|
|
17
|
+
const stored = (value)=>value?.[stateKey];
|
|
18
|
+
return {
|
|
19
|
+
location,
|
|
20
|
+
state: ()=>stored(browser.history.state),
|
|
21
|
+
push: (state)=>browser.history.pushState({
|
|
22
|
+
[stateKey]: state
|
|
23
|
+
}, '', href(state.url)),
|
|
24
|
+
replace: (state)=>browser.history.replaceState({
|
|
25
|
+
[stateKey]: state
|
|
26
|
+
}, '', href(state.url)),
|
|
27
|
+
back: ()=>browser.history.back(),
|
|
28
|
+
listen: (listener)=>{
|
|
29
|
+
const onPopState = (event)=>listener(location(), stored(event.state));
|
|
30
|
+
browser.addEventListener('popstate', onPopState);
|
|
31
|
+
return ()=>browser.removeEventListener('popstate', onPopState);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { createBrowserSceneHistory };
|
|
37
|
+
//# sourceMappingURL=createBrowserSceneHistory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBrowserSceneHistory.js","sources":["../../../navigation/createBrowserSceneHistory.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { SceneHistory } from './SceneHistory';\nimport { SceneNavigationState } from './SceneNavigationState';\n\n/** The part of `window` the browser history needs, so a host can pass its own frame's window. */\nexport type SceneBrowserWindow = Pick<Window, 'history' | 'location' | 'addEventListener' | 'removeEventListener'>;\n\nconst stateKey = 'sceneNavigation';\n\n/**\n * A history backed by the browser's `history` API under a base path such as `/app/`. Entries carry their\n * navigation state, so back and forward restore the screen, outlet, parameters and dialog without\n * re-resolving; an entry without state - a typed or bookmarked URL - is reported by URL alone.\n */\nexport function createBrowserSceneHistory(browser: SceneBrowserWindow = window, basePath = '/'): SceneHistory {\n const base = basePath.endsWith('/') ? basePath : `${basePath}/`;\n const href = (url: string | undefined) => `${base}${url ?? ''}`;\n const location = () => {\n const current = `${browser.location.pathname}${browser.location.search}`;\n if (!current.startsWith(base)) return undefined;\n const relative = current.substring(base.length);\n return relative.length ? relative : undefined;\n };\n const stored = (value: unknown) => (value as Record<string, SceneNavigationState> | null)?.[stateKey];\n\n return {\n location,\n state: () => stored(browser.history.state),\n push: state => browser.history.pushState({ [stateKey]: state }, '', href(state.url)),\n replace: state => browser.history.replaceState({ [stateKey]: state }, '', href(state.url)),\n back: () => browser.history.back(),\n listen: listener => {\n const onPopState = (event: PopStateEvent) => listener(location(), stored(event.state));\n browser.addEventListener('popstate', onPopState);\n return () => browser.removeEventListener('popstate', onPopState);\n },\n };\n}\n"],"names":["stateKey","createBrowserSceneHistory","browser","window","basePath","base","endsWith","href","url","location","current","pathname","search","startsWith","undefined","relative","substring","length","stored","value","state","history","push","pushState","replace","replaceState","back","listen","listener","onPopState","event","addEventListener","removeEventListener"],"mappings":"AAAA;AACA;AAQA,MAAMA,QAAAA,GAAW,iBAAA;AAEjB;;;;AAIC,IACM,SAASC,yBAAAA,CAA0BC,UAA8BC,MAAM,EAAEC,WAAW,GAAG,EAAA;IAC1F,MAAMC,IAAAA,GAAOD,SAASE,QAAQ,CAAC,OAAOF,QAAAA,GAAW,CAAA,EAAGA,QAAAA,CAAS,CAAC,CAAC;AAC/D,IAAA,MAAMG,OAAO,CAACC,GAAAA,GAA4B,CAAA,EAAGH,IAAAA,CAAAA,EAAOG,OAAO,EAAA,CAAA,CAAI;AAC/D,IAAA,MAAMC,QAAAA,GAAW,IAAA;QACb,MAAMC,OAAAA,GAAU,CAAA,EAAGR,OAAAA,CAAQO,QAAQ,CAACE,QAAQ,CAAA,EAAGT,OAAAA,CAAQO,QAAQ,CAACG,MAAM,CAAA,CAAE;AACxE,QAAA,IAAI,CAACF,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
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SceneHistory } from './SceneHistory';
|
|
2
|
+
import { SceneNavigationState } from './SceneNavigationState';
|
|
3
|
+
export declare function createMemorySceneHistory(initialUrl?: string): SceneHistory & {
|
|
4
|
+
forward(): void;
|
|
5
|
+
entries(): SceneNavigationState[];
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=createMemorySceneHistory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMemorySceneHistory.d.ts","sourceRoot":"","sources":["../../../navigation/createMemorySceneHistory.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAO9D,wBAAgB,wBAAwB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,YAAY,GAAG;IAAE,OAAO,IAAI,IAAI,CAAC;IAAC,OAAO,IAAI,oBAAoB,EAAE,CAAA;CAAE,CAgCnI"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
/**
|
|
4
|
+
* A history kept in memory with the same push, replace and back semantics as the browser's: pushing
|
|
5
|
+
* discards any forward entries, and going back notifies listeners. `forward` is exposed for hosts and specs
|
|
6
|
+
* that drive the stack themselves.
|
|
7
|
+
*/ function createMemorySceneHistory(initialUrl) {
|
|
8
|
+
const entries = [
|
|
9
|
+
{
|
|
10
|
+
url: initialUrl
|
|
11
|
+
}
|
|
12
|
+
];
|
|
13
|
+
let index = 0;
|
|
14
|
+
const listeners = new Set();
|
|
15
|
+
const notify = ()=>listeners.forEach((listener)=>listener(entries[index].url, entries[index].state));
|
|
16
|
+
return {
|
|
17
|
+
location: ()=>entries[index].url,
|
|
18
|
+
state: ()=>entries[index].state,
|
|
19
|
+
push: (state)=>{
|
|
20
|
+
entries.splice(index + 1, entries.length, {
|
|
21
|
+
url: state.url,
|
|
22
|
+
state
|
|
23
|
+
});
|
|
24
|
+
index = entries.length - 1;
|
|
25
|
+
},
|
|
26
|
+
replace: (state)=>{
|
|
27
|
+
entries[index] = {
|
|
28
|
+
url: state.url,
|
|
29
|
+
state
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
back: ()=>{
|
|
33
|
+
if (index === 0) return;
|
|
34
|
+
index--;
|
|
35
|
+
notify();
|
|
36
|
+
},
|
|
37
|
+
forward: ()=>{
|
|
38
|
+
if (index === entries.length - 1) return;
|
|
39
|
+
index++;
|
|
40
|
+
notify();
|
|
41
|
+
},
|
|
42
|
+
entries: ()=>entries.map((entry)=>entry.state).filter((state)=>state !== undefined),
|
|
43
|
+
listen: (listener)=>{
|
|
44
|
+
listeners.add(listener);
|
|
45
|
+
return ()=>listeners.delete(listener);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { createMemorySceneHistory };
|
|
51
|
+
//# sourceMappingURL=createMemorySceneHistory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMemorySceneHistory.js","sources":["../../../navigation/createMemorySceneHistory.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { SceneHistory } from './SceneHistory';\nimport { SceneNavigationState } from './SceneNavigationState';\n\n/**\n * A history kept in memory with the same push, replace and back semantics as the browser's: pushing\n * discards any forward entries, and going back notifies listeners. `forward` is exposed for hosts and specs\n * that drive the stack themselves.\n */\nexport function createMemorySceneHistory(initialUrl?: string): SceneHistory & { forward(): void; entries(): SceneNavigationState[] } {\n const entries: { url?: string; state?: SceneNavigationState }[] = [{ url: initialUrl }];\n let index = 0;\n const listeners = new Set<(url: string | undefined, state: SceneNavigationState | undefined) => void>();\n const notify = () => listeners.forEach(listener => listener(entries[index].url, entries[index].state));\n\n return {\n location: () => entries[index].url,\n state: () => entries[index].state,\n push: state => {\n entries.splice(index + 1, entries.length, { url: state.url, state });\n index = entries.length - 1;\n },\n replace: state => {\n entries[index] = { url: state.url, state };\n },\n back: () => {\n if (index === 0) return;\n index--;\n notify();\n },\n forward: () => {\n if (index === entries.length - 1) return;\n index++;\n notify();\n },\n entries: () => entries.map(entry => entry.state).filter((state): state is SceneNavigationState => state !== undefined),\n listen: listener => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n };\n}\n"],"names":["createMemorySceneHistory","initialUrl","entries","url","index","listeners","Set","notify","forEach","listener","state","location","push","splice","length","replace","back","forward","map","entry","filter","undefined","listen","add","delete"],"mappings":"AAAA;AACA;AAKA;;;;IAKO,SAASA,wBAAAA,CAAyBC,UAAmB,EAAA;AACxD,IAAA,MAAMC,OAAAA,GAA4D;AAAC,QAAA;YAAEC,GAAAA,EAAKF;AAAW;AAAE,KAAA;AACvF,IAAA,IAAIG,KAAAA,GAAQ,CAAA;AACZ,IAAA,MAAMC,YAAY,IAAIC,GAAAA,EAAAA;AACtB,IAAA,MAAMC,SAAS,IAAMF,SAAAA,CAAUG,OAAO,CAACC,CAAAA,WAAYA,QAAAA,CAASP,OAAO,CAACE,KAAAA,CAAM,CAACD,GAAG,EAAED,OAAO,CAACE,KAAAA,CAAM,CAACM,KAAK,CAAA,CAAA;IAEpG,OAAO;AACHC,QAAAA,QAAAA,EAAU,IAAMT,OAAO,CAACE,KAAAA,CAAM,CAACD,GAAG;AAClCO,QAAAA,KAAAA,EAAO,IAAMR,OAAO,CAACE,KAAAA,CAAM,CAACM,KAAK;AACjCE,QAAAA,IAAAA,EAAMF,CAAAA,KAAAA,GAAAA;AACFR,YAAAA,OAAAA,CAAQW,MAAM,CAACT,KAAAA,GAAQ,CAAA,EAAGF,OAAAA,CAAQY,MAAM,EAAE;AAAEX,gBAAAA,GAAAA,EAAKO,MAAMP,GAAG;AAAEO,gBAAAA;AAAM,aAAA,CAAA;YAClEN,KAAAA,GAAQF,OAAAA,CAAQY,MAAM,GAAG,CAAA;AAC7B,QAAA,CAAA;AACAC,QAAAA,OAAAA,EAASL,CAAAA,KAAAA,GAAAA;YACLR,OAAO,CAACE,MAAM,GAAG;AAAED,gBAAAA,GAAAA,EAAKO,MAAMP,GAAG;AAAEO,gBAAAA;AAAM,aAAA;AAC7C,QAAA,CAAA;QACAM,IAAAA,EAAM,IAAA;AACF,YAAA,IAAIZ,UAAU,CAAA,EAAG;AACjBA,YAAAA,KAAAA,EAAAA;AACAG,YAAAA,MAAAA,EAAAA;AACJ,QAAA,CAAA;QACAU,OAAAA,EAAS,IAAA;AACL,YAAA,IAAIb,KAAAA,KAAUF,OAAAA,CAAQY,MAAM,GAAG,CAAA,EAAG;AAClCV,YAAAA,KAAAA,EAAAA;AACAG,YAAAA,MAAAA,EAAAA;AACJ,QAAA,CAAA;AACAL,QAAAA,OAAAA,EAAS,IAAMA,OAAAA,CAAQgB,GAAG,CAACC,CAAAA,KAAAA,GAASA,KAAAA,CAAMT,KAAK,CAAA,CAAEU,MAAM,CAAC,CAACV,QAAyCA,KAAAA,KAAUW,SAAAA,CAAAA;AAC5GC,QAAAA,MAAAA,EAAQb,CAAAA,QAAAA,GAAAA;AACJJ,YAAAA,SAAAA,CAAUkB,GAAG,CAACd,QAAAA,CAAAA;YACd,OAAO,IAAMJ,SAAAA,CAAUmB,MAAM,CAACf,QAAAA,CAAAA;AAClC,QAAA;AACJ,KAAA;AACJ;;"}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
export * from './DestinationResolution';
|
|
2
|
+
export * from './DialogResult';
|
|
3
|
+
export * from './SceneHistory';
|
|
2
4
|
export * from './SceneNavigationContext';
|
|
3
5
|
export * from './SceneNavigationHost';
|
|
4
|
-
export * from './
|
|
6
|
+
export * from './SceneNavigationState';
|
|
7
|
+
export * from './SceneRoute';
|
|
8
|
+
export * from './createBrowserSceneHistory';
|
|
9
|
+
export * from './createMemorySceneHistory';
|
|
5
10
|
export * from './diagnoseRenderedNavigation';
|
|
6
11
|
export * from './identityRoute';
|
|
12
|
+
export * from './matchSceneRoute';
|
|
7
13
|
export * from './navigationRouteKey';
|
|
14
|
+
export * from './resolveDestination';
|
|
15
|
+
export * from './sceneRoutesFrom';
|
|
16
|
+
export * from './useSceneHistoryNavigation';
|
|
8
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../navigation/index.ts"],"names":[],"mappings":"AAGA,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../navigation/index.ts"],"names":[],"mappings":"AAGA,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC"}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
export * from './DestinationResolution';
|
|
2
|
+
export * from './DialogResult';
|
|
3
|
+
export * from './SceneHistory';
|
|
2
4
|
export * from './SceneNavigationContext';
|
|
3
5
|
export * from './SceneNavigationHost';
|
|
4
|
-
export * from './
|
|
6
|
+
export * from './SceneNavigationState';
|
|
7
|
+
export * from './SceneRoute';
|
|
8
|
+
export * from './createBrowserSceneHistory';
|
|
9
|
+
export * from './createMemorySceneHistory';
|
|
5
10
|
export * from './diagnoseRenderedNavigation';
|
|
6
11
|
export * from './identityRoute';
|
|
12
|
+
export * from './matchSceneRoute';
|
|
7
13
|
export * from './navigationRouteKey';
|
|
14
|
+
export * from './resolveDestination';
|
|
15
|
+
export * from './sceneRoutesFrom';
|
|
16
|
+
export * from './useSceneHistoryNavigation';
|
|
8
17
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../navigation/index.ts"],"names":[],"mappings":"AAGA,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../navigation/index.ts"],"names":[],"mappings":"AAGA,cAAc,yBAAyB,CAAC;AACxC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SceneRoute } from './SceneRoute';
|
|
2
|
+
export interface SceneRouteMatch {
|
|
3
|
+
route: SceneRoute;
|
|
4
|
+
parameters: Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
export declare function matchSceneRoute(url: string, routes: SceneRoute[]): SceneRouteMatch | undefined;
|
|
7
|
+
//# sourceMappingURL=matchSceneRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchSceneRoute.d.ts","sourceRoot":"","sources":["../../../navigation/matchSceneRoute.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,MAAM,WAAW,eAAe;IAC5B,KAAK,EAAE,UAAU,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC;AAOD,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,eAAe,GAAG,SAAS,CAwB9F"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
/**
|
|
4
|
+
* Matches a URL - as a deep link, a refresh or a typed address delivers it - against route templates.
|
|
5
|
+
* `{name}` segments capture path parameters; the query string adds the rest. Literal segments win over
|
|
6
|
+
* parameters, so `orders/new` beats `orders/{orderId}`, and routes are otherwise tried in the given order.
|
|
7
|
+
*/ function matchSceneRoute(url, routes) {
|
|
8
|
+
const [path, query = ''] = url.split('?', 2);
|
|
9
|
+
const segments = path.split('/').filter((segment)=>segment.length > 0).map(decodeURIComponent);
|
|
10
|
+
const queryParameters = Object.fromEntries(new URLSearchParams(query));
|
|
11
|
+
const candidates = routes.map((route, order)=>({
|
|
12
|
+
route,
|
|
13
|
+
order,
|
|
14
|
+
template: route.route.split('/').filter((segment)=>segment.length > 0)
|
|
15
|
+
})).filter((candidate)=>candidate.template.length === segments.length).sort((left, right)=>literalCount(right.template) - literalCount(left.template) || left.order - right.order);
|
|
16
|
+
for (const { route, template } of candidates){
|
|
17
|
+
const parameters = {};
|
|
18
|
+
const matches = template.every((part, index)=>{
|
|
19
|
+
const name = /^\{([^}]+)\}$/.exec(part)?.[1];
|
|
20
|
+
if (name) {
|
|
21
|
+
parameters[name] = segments[index];
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return part === segments[index];
|
|
25
|
+
});
|
|
26
|
+
if (matches) return {
|
|
27
|
+
route,
|
|
28
|
+
parameters: {
|
|
29
|
+
...queryParameters,
|
|
30
|
+
...parameters
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
function literalCount(template) {
|
|
37
|
+
return template.filter((part)=>!/^\{[^}]+\}$/.test(part)).length;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { matchSceneRoute };
|
|
41
|
+
//# sourceMappingURL=matchSceneRoute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchSceneRoute.js","sources":["../../../navigation/matchSceneRoute.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { SceneRoute } from './SceneRoute';\n\n/** A URL matched to the route that opens it. */\nexport interface SceneRouteMatch {\n route: SceneRoute;\n parameters: Record<string, string>;\n}\n\n/**\n * Matches a URL - as a deep link, a refresh or a typed address delivers it - against route templates.\n * `{name}` segments capture path parameters; the query string adds the rest. Literal segments win over\n * parameters, so `orders/new` beats `orders/{orderId}`, and routes are otherwise tried in the given order.\n */\nexport function matchSceneRoute(url: string, routes: SceneRoute[]): SceneRouteMatch | undefined {\n const [path, query = ''] = url.split('?', 2);\n const segments = path.split('/').filter(segment => segment.length > 0).map(decodeURIComponent);\n const queryParameters = Object.fromEntries(new URLSearchParams(query));\n\n const candidates = routes\n .map((route, order) => ({ route, order, template: route.route.split('/').filter(segment => segment.length > 0) }))\n .filter(candidate => candidate.template.length === segments.length)\n .sort((left, right) => literalCount(right.template) - literalCount(left.template) || left.order - right.order);\n\n for (const { route, template } of candidates) {\n const parameters: Record<string, string> = {};\n const matches = template.every((part, index) => {\n const name = /^\\{([^}]+)\\}$/.exec(part)?.[1];\n if (name) {\n parameters[name] = segments[index];\n return true;\n }\n return part === segments[index];\n });\n if (matches) return { route, parameters: { ...queryParameters, ...parameters } };\n }\n\n return undefined;\n}\n\nfunction literalCount(template: string[]): number {\n return template.filter(part => !/^\\{[^}]+\\}$/.test(part)).length;\n}\n"],"names":["matchSceneRoute","url","routes","path","query","split","segments","filter","segment","length","map","decodeURIComponent","queryParameters","Object","fromEntries","URLSearchParams","candidates","route","order","template","candidate","sort","left","right","literalCount","parameters","matches","every","part","index","name","exec","undefined","test"],"mappings":"AAAA;AACA;AAUA;;;;AAIC,IACM,SAASA,eAAAA,CAAgBC,GAAW,EAAEC,MAAoB,EAAA;IAC7D,MAAM,CAACC,MAAMC,KAAAA,GAAQ,EAAE,CAAC,GAAGH,GAAAA,CAAII,KAAK,CAAC,GAAA,EAAK,CAAA,CAAA;AAC1C,IAAA,MAAMC,QAAAA,GAAWH,IAAAA,CAAKE,KAAK,CAAC,KAAKE,MAAM,CAACC,CAAAA,OAAAA,GAAWA,OAAAA,CAAQC,MAAM,GAAG,CAAA,CAAA,CAAGC,GAAG,CAACC,kBAAAA,CAAAA;AAC3E,IAAA,MAAMC,eAAAA,GAAkBC,MAAAA,CAAOC,WAAW,CAAC,IAAIC,eAAAA,CAAgBX,KAAAA,CAAAA,CAAAA;AAE/D,IAAA,MAAMY,aAAad,MAAAA,CACdQ,GAAG,CAAC,CAACO,KAAAA,EAAOC,SAAW;AAAED,YAAAA,KAAAA;AAAOC,YAAAA,KAAAA;AAAOC,YAAAA,QAAAA,EAAUF,KAAAA,CAAMA,KAAK,CAACZ,KAAK,CAAC,GAAA,CAAA,CAAKE,MAAM,CAACC,CAAAA,OAAAA,GAAWA,OAAAA,CAAQC,MAAM,GAAG,CAAA;AAAG,SAAA,CAAA,CAAA,CAC9GF,MAAM,CAACa,CAAAA,SAAAA,GAAaA,SAAAA,CAAUD,QAAQ,CAACV,MAAM,KAAKH,QAAAA,CAASG,MAAM,EACjEY,IAAI,CAAC,CAACC,IAAAA,EAAMC,KAAAA,GAAUC,YAAAA,CAAaD,KA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B,EAAE,MAAM,yBAAyB,CAAC;AAMhE,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,oBAAoB,EAAE,KAAK,GAAE,YAAiB,GAAG,qBAAqB,
|
|
1
|
+
{"version":3,"file":"resolveDestination.d.ts","sourceRoot":"","sources":["../../../navigation/resolveDestination.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAA4B,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAmB,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAMhE,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,oBAAoB,EAAE,KAAK,GAAE,YAAiB,GAAG,qBAAqB,CAkBrH"}
|
|
@@ -21,6 +21,7 @@ import { identityRoute } from './identityRoute.js';
|
|
|
21
21
|
url,
|
|
22
22
|
outlet: destination.outlet,
|
|
23
23
|
dialog: destination.dialog,
|
|
24
|
+
parameters: Object.fromEntries(parameters),
|
|
24
25
|
action: kind === DestinationKind.Dialog ? 'openDialog' : kind === DestinationKind.External ? 'openExternal' : 'navigate',
|
|
25
26
|
diagnostics
|
|
26
27
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveDestination.js","sources":["../../../navigation/resolveDestination.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { BindingScope, resolveBindingExpression } from '@cratis/scene.engine';\nimport { DestinationKind, DestinationReference } from '@cratis/scene.model';\nimport { DestinationResolution } from './DestinationResolution';\nimport { identityRoute } from './identityRoute';\n\n/**\n * Resolves a destination into a renderer-neutral navigation action, deep link and target outlet/dialog.\n */\nexport function resolveDestination(destination: DestinationReference, scope: BindingScope = {}): DestinationResolution {\n const diagnostics: string[] = [];\n const kind = destination.kind ?? (destination.dialog ? DestinationKind.Dialog : DestinationKind.Outlet);\n const parameters = Object.entries(destination.routeParameterBindings ?? {})\n .map(([name, binding]) => [name, String(resolveBindingExpression(binding, scope) ?? '')] as const);\n const base = destination.route ?? identityRoute(destination);\n if (!base && kind !== DestinationKind.Dialog) diagnostics.push('Destination has no routeable screen, stable identity or route.');\n\n const url = base ? appendParameters(base, parameters) : undefined;\n return {\n kind,\n url,\n outlet: destination.outlet,\n dialog: destination.dialog,\n action: kind === DestinationKind.Dialog ? 'openDialog' : kind === DestinationKind.External ? 'openExternal' : 'navigate',\n diagnostics,\n };\n}\n\nfunction appendParameters(route: string, parameters: readonly (readonly [string, string])[]): string {\n if (!parameters.length) return route;\n let replaced = route;\n const unused: string[] = [];\n for (const [name, value] of parameters) {\n const marker = `{${name}}`;\n if (replaced.includes(marker)) {\n replaced = replaced.split(marker).join(encodeURIComponent(value));\n } else {\n unused.push(`${encodeURIComponent(name)}=${encodeURIComponent(value)}`);\n }\n }\n\n return unused.length ? `${replaced}?${unused.join('&')}` : replaced;\n}\n"],"names":["resolveDestination","destination","scope","diagnostics","kind","dialog","DestinationKind","Dialog","Outlet","parameters","Object","entries","routeParameterBindings","map","name","binding","String","resolveBindingExpression","base","route","identityRoute","push","url","appendParameters","undefined","outlet","action","External","length","replaced","unused","value","marker","includes","split","join","encodeURIComponent"],"mappings":";;;;AAAA;AACA;AAOA;;AAEC,IACM,SAASA,kBAAAA,CAAmBC,WAAiC,EAAEC,KAAAA,GAAsB,EAAE,EAAA;AAC1F,IAAA,MAAMC,cAAwB,EAAE;AAChC,IAAA,MAAMC,IAAAA,GAAOH,WAAAA,CAAYG,IAAI,KAAKH,WAAAA,CAAYI,MAAM,GAAGC,eAAAA,CAAgBC,MAAM,GAAGD,eAAAA,CAAgBE,MAAM,CAAD;AACrG,IAAA,MAAMC,UAAAA,GAAaC,MAAAA,CAAOC,OAAO,CAACV,YAAYW,sBAAsB,IAAI,EAAC,CAAA,CACpEC,GAAG,CAAC,CAAC,CAACC,IAAAA,EAAMC,QAAQ,GAAK;AAACD,YAAAA,IAAAA;YAAME,MAAAA,CAAOC,wBAAAA,CAAyBF,SAASb,KAAAA,CAAAA,IAAU,EAAA;AAAI,SAAA,CAAA;AAC5F,IAAA,MAAMgB,IAAAA,GAAOjB,WAAAA,CAAYkB,KAAK,IAAIC,aAAAA,CAAcnB,WAAAA,CAAAA;IAChD,IAAI,CAACiB,QAAQd,IAAAA,KAASE,eAAAA,CAAgBC,MAAM,EAAEJ,WAAAA,CAAYkB,IAAI,CAAC,gEAAA,CAAA;AAE/D,IAAA,MAAMC,GAAAA,GAAMJ,IAAAA,GAAOK,gBAAAA,CAAiBL,IAAAA,EAAMT,UAAAA,CAAAA,GAAce,SAAAA;IACxD,OAAO;AACHpB,QAAAA,IAAAA;AACAkB,QAAAA,GAAAA;AACAG,QAAAA,MAAAA,EAAQxB,YAAYwB,MAAM;AAC1BpB,QAAAA,MAAAA,EAAQJ,YAAYI,MAAM;
|
|
1
|
+
{"version":3,"file":"resolveDestination.js","sources":["../../../navigation/resolveDestination.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { BindingScope, resolveBindingExpression } from '@cratis/scene.engine';\nimport { DestinationKind, DestinationReference } from '@cratis/scene.model';\nimport { DestinationResolution } from './DestinationResolution';\nimport { identityRoute } from './identityRoute';\n\n/**\n * Resolves a destination into a renderer-neutral navigation action, deep link and target outlet/dialog.\n */\nexport function resolveDestination(destination: DestinationReference, scope: BindingScope = {}): DestinationResolution {\n const diagnostics: string[] = [];\n const kind = destination.kind ?? (destination.dialog ? DestinationKind.Dialog : DestinationKind.Outlet);\n const parameters = Object.entries(destination.routeParameterBindings ?? {})\n .map(([name, binding]) => [name, String(resolveBindingExpression(binding, scope) ?? '')] as const);\n const base = destination.route ?? identityRoute(destination);\n if (!base && kind !== DestinationKind.Dialog) diagnostics.push('Destination has no routeable screen, stable identity or route.');\n\n const url = base ? appendParameters(base, parameters) : undefined;\n return {\n kind,\n url,\n outlet: destination.outlet,\n dialog: destination.dialog,\n parameters: Object.fromEntries(parameters),\n action: kind === DestinationKind.Dialog ? 'openDialog' : kind === DestinationKind.External ? 'openExternal' : 'navigate',\n diagnostics,\n };\n}\n\nfunction appendParameters(route: string, parameters: readonly (readonly [string, string])[]): string {\n if (!parameters.length) return route;\n let replaced = route;\n const unused: string[] = [];\n for (const [name, value] of parameters) {\n const marker = `{${name}}`;\n if (replaced.includes(marker)) {\n replaced = replaced.split(marker).join(encodeURIComponent(value));\n } else {\n unused.push(`${encodeURIComponent(name)}=${encodeURIComponent(value)}`);\n }\n }\n\n return unused.length ? `${replaced}?${unused.join('&')}` : replaced;\n}\n"],"names":["resolveDestination","destination","scope","diagnostics","kind","dialog","DestinationKind","Dialog","Outlet","parameters","Object","entries","routeParameterBindings","map","name","binding","String","resolveBindingExpression","base","route","identityRoute","push","url","appendParameters","undefined","outlet","fromEntries","action","External","length","replaced","unused","value","marker","includes","split","join","encodeURIComponent"],"mappings":";;;;AAAA;AACA;AAOA;;AAEC,IACM,SAASA,kBAAAA,CAAmBC,WAAiC,EAAEC,KAAAA,GAAsB,EAAE,EAAA;AAC1F,IAAA,MAAMC,cAAwB,EAAE;AAChC,IAAA,MAAMC,IAAAA,GAAOH,WAAAA,CAAYG,IAAI,KAAKH,WAAAA,CAAYI,MAAM,GAAGC,eAAAA,CAAgBC,MAAM,GAAGD,eAAAA,CAAgBE,MAAM,CAAD;AACrG,IAAA,MAAMC,UAAAA,GAAaC,MAAAA,CAAOC,OAAO,CAACV,YAAYW,sBAAsB,IAAI,EAAC,CAAA,CACpEC,GAAG,CAAC,CAAC,CAACC,IAAAA,EAAMC,QAAQ,GAAK;AAACD,YAAAA,IAAAA;YAAME,MAAAA,CAAOC,wBAAAA,CAAyBF,SAASb,KAAAA,CAAAA,IAAU,EAAA;AAAI,SAAA,CAAA;AAC5F,IAAA,MAAMgB,IAAAA,GAAOjB,WAAAA,CAAYkB,KAAK,IAAIC,aAAAA,CAAcnB,WAAAA,CAAAA;IAChD,IAAI,CAACiB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