@jskit-ai/shell-web 0.2.3 → 0.2.5
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/fixtures/adaptive-shell/src/main.js +4 -2
- package/package.json +10 -4
- package/patterns/page-and-placement/example/src/placementTopology.js +1 -0
- package/src/client/asyncModuleRecovery/index.js +1 -0
- package/src/client/asyncModuleRecovery/inject.js +30 -18
- package/src/client/asyncModuleRecovery/runtime.js +20 -24
- package/src/client/bootstrap/bootstrapPayloadHandlerRegistry.js +13 -6
- package/src/client/browser.js +56 -0
- package/src/client/clientUpdate/runtime.js +28 -18
- package/src/client/components/ShellErrorHost.vue +19 -219
- package/src/client/components/ShellLayout.vue +19 -227
- package/src/client/components/ShellOutlet.vue +16 -53
- package/src/client/components/ShellRouteTransition.vue +2 -291
- package/src/client/composables/shellLayoutDrawerPreference.js +15 -8
- package/src/client/composables/useShellDrawer.js +194 -0
- package/src/client/composables/useShellErrorHost.js +171 -0
- package/src/client/composables/useShellLayoutState.js +10 -20
- package/src/client/composables/useShellNavigationLink.js +6 -6
- package/src/client/composables/useShellPullToRefresh.js +15 -19
- package/src/client/composables/useShellRouteTransition.js +218 -0
- package/src/client/error/index.js +1 -1
- package/src/client/error/inject.js +36 -48
- package/src/client/error/normalize.js +2 -3
- package/src/client/error/policy.js +9 -0
- package/src/client/error/presentation.js +67 -0
- package/src/client/error/presentationDefaults.js +2 -2
- package/src/client/error/presenters.js +44 -19
- package/src/client/error/runtime.js +30 -28
- package/src/client/error/store.js +4 -0
- package/src/client/navigation/linkResolver.js +6 -2
- package/src/client/navigation/usePaths.js +11 -8
- package/src/client/navigation/useSurfaceRouteContext.js +3 -3
- package/src/client/placement/debug.js +2 -2
- package/src/client/placement/index.js +1 -0
- package/src/client/placement/inject.js +49 -46
- package/src/client/placement/pathname.js +3 -9
- package/src/client/placement/runtime.js +13 -39
- package/src/client/placement/surfaceContext.js +14 -33
- package/src/client/placement/validators.js +6 -1
- package/src/client/providers/ShellWebClientProvider.js +17 -38
- package/src/client/providers/appModuleLoadFailure.js +1 -1
- package/src/client/requestRecovery/index.js +1 -0
- package/src/client/requestRecovery/inject.js +29 -17
- package/src/client/requestRecovery/runtime.js +40 -87
- package/src/client/runtime/bootstrapRuntime.js +20 -35
- package/src/client/runtime/refreshRuntime.js +30 -22
- package/src/client/stores/useShellErrorPresentationStore.js +5 -19
- package/src/client/support/drawerWidth.js +39 -0
- package/src/client/support/gestureTargets.js +4 -2
- package/src/client/support/menuLinkTarget.js +1 -1
- package/src/client/support/navigationLinkKeyboard.js +1 -1
- package/src/client/support/primaryNavigation.js +93 -0
- package/src/client/support/routeSwipeGesture.js +13 -3
- package/src/client/support/shellLayoutClass.js +4 -6
- package/src/client/types.js +38 -0
- package/test/asyncModuleRecoveryInject.test.js +13 -18
- package/test/bootstrapRuntime.test.js +3 -1
- package/test/browser.test.js +51 -0
- package/test/clientUpdate.test.js +12 -1
- package/test/drawerWidth.test.js +64 -0
- package/test/errorActions.test.js +10 -3
- package/test/errorPresentation.test.js +51 -0
- package/test/errorRuntime.test.js +21 -10
- package/test/placementInject.test.js +60 -0
- package/test/placementRuntime.test.js +12 -9
- package/test/primaryNavigation.test.js +75 -0
- package/test/provider.test.js +18 -4
- package/test/requestRecovery.test.js +13 -18
- package/test/settingsPlacementContract.test.js +15 -11
- package/test/support/mountComposable.js +90 -0
- package/test/translation.test.js +4 -2
- package/test/useShellDrawer.test.js +213 -0
- package/test/useShellErrorHost.test.js +149 -0
- package/test/useShellRouteTransition.test.js +129 -0
|
@@ -72,6 +72,10 @@ function resolveShellLinkPath({
|
|
|
72
72
|
return resolveLinkPath(nextSurfaceBasePath, nextRelativePath);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* @param {object} [options]
|
|
77
|
+
* @param {import("vue").MaybeRef<string>} [options.surface] The surface a link resolves on, unless it names its own.
|
|
78
|
+
*/
|
|
75
79
|
function useShellLinkResolver({ surface = "" } = {}) {
|
|
76
80
|
const { context: placementContext } = useWebPlacementContext();
|
|
77
81
|
|
|
@@ -87,9 +91,9 @@ function useShellLinkResolver({ surface = "" } = {}) {
|
|
|
87
91
|
});
|
|
88
92
|
}
|
|
89
93
|
|
|
90
|
-
return
|
|
94
|
+
return {
|
|
91
95
|
resolve
|
|
92
|
-
}
|
|
96
|
+
};
|
|
93
97
|
}
|
|
94
98
|
|
|
95
99
|
export { resolveShellLinkPath, useShellLinkResolver };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { computed, unref } from "vue";
|
|
2
|
-
import { normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
|
|
2
|
+
import { normalizeObject, normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
|
|
3
3
|
import { resolveScopedApiBasePath } from "@jskit-ai/kernel/shared/surface";
|
|
4
4
|
import { resolveSurfaceDefinitionFromPlacementContext } from "../placement/index.js";
|
|
5
5
|
import { useShellLinkResolver } from "./linkResolver.js";
|
|
@@ -40,13 +40,16 @@ function resolveRouteParams(baseParams = {}, overrideParams = null) {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
/**
|
|
44
|
+
* @param {object} [options]
|
|
45
|
+
* @param {import("../types.js").SurfaceRouteContext} [options.routeContext]
|
|
46
|
+
*/
|
|
47
|
+
function usePaths({ routeContext = useSurfaceRouteContext() } = {}) {
|
|
45
48
|
const shellLinkResolver = useShellLinkResolver();
|
|
46
|
-
const routeParams = computed(() => normalizeRouteParams(routeContext.route
|
|
49
|
+
const routeParams = computed(() => normalizeRouteParams(routeContext.route.params));
|
|
47
50
|
|
|
48
51
|
function page(relativePath = "/", options = {}) {
|
|
49
|
-
const source =
|
|
52
|
+
const source = normalizeObject(options);
|
|
50
53
|
const surface =
|
|
51
54
|
resolveSurfaceId(source.surface, routeContext.currentSurfaceId.value) ||
|
|
52
55
|
resolveDefaultSurfaceIdFromPlacementContext(routeContext.placementContext.value);
|
|
@@ -63,7 +66,7 @@ function usePaths({ routeContext: sourceRouteContext = null } = {}) {
|
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
function api(relativePath = "", options = {}) {
|
|
66
|
-
const source =
|
|
69
|
+
const source = normalizeObject(options);
|
|
67
70
|
const surface =
|
|
68
71
|
resolveSurfaceId(source.surface, routeContext.currentSurfaceId.value) ||
|
|
69
72
|
resolveDefaultSurfaceIdFromPlacementContext(routeContext.placementContext.value);
|
|
@@ -86,14 +89,14 @@ function usePaths({ routeContext: sourceRouteContext = null } = {}) {
|
|
|
86
89
|
});
|
|
87
90
|
}
|
|
88
91
|
|
|
89
|
-
return
|
|
92
|
+
return {
|
|
90
93
|
route: routeContext.route,
|
|
91
94
|
placementContext: routeContext.placementContext,
|
|
92
95
|
currentSurfaceId: routeContext.currentSurfaceId,
|
|
93
96
|
routeParams,
|
|
94
97
|
page,
|
|
95
98
|
api
|
|
96
|
-
}
|
|
99
|
+
};
|
|
97
100
|
}
|
|
98
101
|
|
|
99
102
|
export { usePaths };
|
|
@@ -9,18 +9,18 @@ import {
|
|
|
9
9
|
function useSurfaceRouteContext() {
|
|
10
10
|
const route = useRoute();
|
|
11
11
|
const { context: placementContext, mergeContext: mergePlacementContext } = useWebPlacementContext();
|
|
12
|
-
const routePath = computed(() => resolveRuntimePathname(route
|
|
12
|
+
const routePath = computed(() => resolveRuntimePathname(route.path));
|
|
13
13
|
const currentSurfaceId = computed(() =>
|
|
14
14
|
resolveSurfaceIdFromPlacementPathname(placementContext.value, routePath.value)
|
|
15
15
|
);
|
|
16
16
|
|
|
17
|
-
return
|
|
17
|
+
return {
|
|
18
18
|
route,
|
|
19
19
|
routePath,
|
|
20
20
|
placementContext,
|
|
21
21
|
mergePlacementContext,
|
|
22
22
|
currentSurfaceId
|
|
23
|
-
}
|
|
23
|
+
};
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export { useSurfaceRouteContext };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const DEFAULT_DEBUG_DEPTH = 4;
|
|
2
2
|
|
|
3
3
|
function describeFunction(fn) {
|
|
4
|
-
return `[Function ${fn
|
|
4
|
+
return `[Function ${fn.name || "anonymous"}]`;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
function describeSymbol(value) {
|
|
8
|
-
return value
|
|
8
|
+
return value.toString();
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
function explodePayload(value, depth = DEFAULT_DEBUG_DEPTH) {
|
|
@@ -2,18 +2,25 @@ import {
|
|
|
2
2
|
inject,
|
|
3
3
|
onBeforeUnmount,
|
|
4
4
|
onMounted,
|
|
5
|
+
ref,
|
|
5
6
|
shallowRef
|
|
6
7
|
} from "vue";
|
|
7
8
|
|
|
8
9
|
const SHELL_WEB_PLACEMENT_RUNTIME_KEY = "jskit.shell-web.runtime.web-placement.client";
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
/**
|
|
12
|
+
* The placement runtime of an application without shell-web's provider: nothing is placed.
|
|
13
|
+
* @type {any}
|
|
14
|
+
*/
|
|
15
|
+
const NO_WEB_PLACEMENT_RUNTIME = Object.freeze({
|
|
16
|
+
replacePlacements() {},
|
|
17
|
+
replacePlacementTopology() {},
|
|
14
18
|
getPlacements() {
|
|
15
19
|
return Object.freeze([]);
|
|
16
20
|
},
|
|
21
|
+
getContext() {
|
|
22
|
+
return Object.freeze({});
|
|
23
|
+
},
|
|
17
24
|
setContext() {
|
|
18
25
|
return Object.freeze({});
|
|
19
26
|
},
|
|
@@ -25,55 +32,37 @@ const EMPTY_WEB_PLACEMENT_RUNTIME = Object.freeze({
|
|
|
25
32
|
}
|
|
26
33
|
});
|
|
27
34
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
replaceContext() {
|
|
36
|
-
return EMPTY_WEB_PLACEMENT_CONTEXT_REF.value;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
function useWebPlacementRuntime({ required = false } = {}) {
|
|
41
|
-
const runtime = inject(SHELL_WEB_PLACEMENT_RUNTIME_KEY, null);
|
|
42
|
-
if (runtime && typeof runtime.getPlacements === "function") {
|
|
43
|
-
return runtime;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (required) {
|
|
47
|
-
throw new Error("Web placement runtime is not available in Vue injection context.");
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return EMPTY_WEB_PLACEMENT_RUNTIME;
|
|
35
|
+
/**
|
|
36
|
+
* The shell's placement runtime, or `NO_WEB_PLACEMENT_RUNTIME` in an application without shell-web's provider.
|
|
37
|
+
* @returns {import("../types.js").WebPlacementRuntime}
|
|
38
|
+
*/
|
|
39
|
+
function useWebPlacementRuntime() {
|
|
40
|
+
return inject(SHELL_WEB_PLACEMENT_RUNTIME_KEY, NO_WEB_PLACEMENT_RUNTIME);
|
|
51
41
|
}
|
|
52
42
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (runtime === EMPTY_WEB_PLACEMENT_RUNTIME) {
|
|
56
|
-
return EMPTY_WEB_PLACEMENT_CONTEXT;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const context = shallowRef(runtime.getContext());
|
|
43
|
+
// Runs the listener on every placement change while the component is mounted.
|
|
44
|
+
function followWebPlacementRuntime(runtime, listener) {
|
|
60
45
|
let unsubscribe = null;
|
|
61
46
|
|
|
62
47
|
onMounted(() => {
|
|
63
|
-
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
unsubscribe = runtime.subscribe(() => {
|
|
67
|
-
context.value = runtime.getContext();
|
|
68
|
-
});
|
|
48
|
+
unsubscribe = runtime.subscribe(listener);
|
|
69
49
|
});
|
|
70
50
|
|
|
71
51
|
onBeforeUnmount(() => {
|
|
72
|
-
if (
|
|
52
|
+
if (unsubscribe) {
|
|
73
53
|
unsubscribe();
|
|
74
54
|
unsubscribe = null;
|
|
75
55
|
}
|
|
76
56
|
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function useWebPlacementContext() {
|
|
60
|
+
const runtime = useWebPlacementRuntime();
|
|
61
|
+
const context = shallowRef(runtime.getContext());
|
|
62
|
+
|
|
63
|
+
followWebPlacementRuntime(runtime, () => {
|
|
64
|
+
context.value = runtime.getContext();
|
|
65
|
+
});
|
|
77
66
|
|
|
78
67
|
function mergeContext(value = {}, source = "component") {
|
|
79
68
|
context.value = runtime.setContext(value, {
|
|
@@ -90,17 +79,31 @@ function useWebPlacementContext({ required = false } = {}) {
|
|
|
90
79
|
return context.value;
|
|
91
80
|
}
|
|
92
81
|
|
|
93
|
-
return
|
|
82
|
+
return {
|
|
94
83
|
context,
|
|
95
84
|
mergeContext,
|
|
96
85
|
replaceContext
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The runtime's revision, for a computed that must read its placements again when they change.
|
|
91
|
+
* @param {import("../types.js").WebPlacementRuntime} runtime
|
|
92
|
+
*/
|
|
93
|
+
function useWebPlacementRevision(runtime) {
|
|
94
|
+
const revision = ref(runtime.getRevision());
|
|
95
|
+
|
|
96
|
+
followWebPlacementRuntime(runtime, (event) => {
|
|
97
|
+
revision.value = event.revision;
|
|
97
98
|
});
|
|
99
|
+
|
|
100
|
+
return revision;
|
|
98
101
|
}
|
|
99
102
|
|
|
100
103
|
export {
|
|
104
|
+
NO_WEB_PLACEMENT_RUNTIME,
|
|
101
105
|
SHELL_WEB_PLACEMENT_RUNTIME_KEY,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
useWebPlacementRuntime
|
|
105
|
-
useWebPlacementContext
|
|
106
|
+
useWebPlacementContext,
|
|
107
|
+
useWebPlacementRevision,
|
|
108
|
+
useWebPlacementRuntime
|
|
106
109
|
};
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
+
import { pagePathname } from "../browser.js";
|
|
2
|
+
|
|
1
3
|
function resolveRuntimePathname(candidate = "") {
|
|
2
4
|
const explicitPathname = String(candidate || "").trim();
|
|
3
|
-
|
|
4
|
-
return explicitPathname;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
if (typeof window === "object" && window?.location?.pathname) {
|
|
8
|
-
return String(window.location.pathname || "").trim() || "/";
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return "/";
|
|
5
|
+
return explicitPathname || pagePathname() || "/";
|
|
12
6
|
}
|
|
13
7
|
|
|
14
8
|
export { resolveRuntimePathname };
|
|
@@ -25,13 +25,8 @@ function ensureArray(value) {
|
|
|
25
25
|
|
|
26
26
|
const PLACEMENT_DEBUG_PREFIX = "[placement-debug]";
|
|
27
27
|
const PLACEMENT_DEBUG_FLAG = "__JSKIT_PLACEMENT_DEBUG__";
|
|
28
|
-
const NOOP = () => {};
|
|
29
28
|
|
|
30
29
|
function isPlacementDebugEnabled() {
|
|
31
|
-
if (typeof globalThis !== "object" || !globalThis) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
30
|
return globalThis[PLACEMENT_DEBUG_FLAG] === true;
|
|
36
31
|
}
|
|
37
32
|
|
|
@@ -49,24 +44,6 @@ function debugLog(message, payload = null) {
|
|
|
49
44
|
console.log(`${PLACEMENT_DEBUG_PREFIX} ${message}\n${rendered}`);
|
|
50
45
|
}
|
|
51
46
|
|
|
52
|
-
function createRuntimeLogger(logger) {
|
|
53
|
-
const runtimeLogger = isRecord(logger) ? logger : {};
|
|
54
|
-
let warn = NOOP;
|
|
55
|
-
let error = NOOP;
|
|
56
|
-
|
|
57
|
-
if (typeof runtimeLogger.warn === "function") {
|
|
58
|
-
warn = runtimeLogger.warn.bind(runtimeLogger);
|
|
59
|
-
}
|
|
60
|
-
if (typeof runtimeLogger.error === "function") {
|
|
61
|
-
error = runtimeLogger.error.bind(runtimeLogger);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return Object.freeze({
|
|
65
|
-
warn,
|
|
66
|
-
error
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
47
|
function normalizePlacementList(placements, context = {}) {
|
|
71
48
|
const normalized = [];
|
|
72
49
|
|
|
@@ -300,10 +277,6 @@ function resolvePlacementComponent(
|
|
|
300
277
|
}
|
|
301
278
|
|
|
302
279
|
function shouldIncludePlacement(placement, placementContext, logger) {
|
|
303
|
-
if (typeof placement.when !== "function") {
|
|
304
|
-
return true;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
280
|
try {
|
|
308
281
|
return placement.when(Object.freeze({ ...placementContext })) === true;
|
|
309
282
|
} catch (error) {
|
|
@@ -318,12 +291,13 @@ function shouldIncludePlacement(placement, placementContext, logger) {
|
|
|
318
291
|
}
|
|
319
292
|
}
|
|
320
293
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
294
|
+
/**
|
|
295
|
+
* @param {object} options
|
|
296
|
+
* @param {Pick<import("@jskit-ai/kernel/client/types").ClientComponents, "has" | "get">} options.components
|
|
297
|
+
* @param {Function[]} [options.contextContributors]
|
|
298
|
+
* @param {import("@jskit-ai/kernel/client/types").ClientLogger} options.logger
|
|
299
|
+
*/
|
|
300
|
+
function createWebPlacementRuntime({ components, contextContributors = [], logger }) {
|
|
327
301
|
const missingTokens = new Set();
|
|
328
302
|
const invalidComponentTokens = new Set();
|
|
329
303
|
const failedTokens = new Set();
|
|
@@ -349,7 +323,7 @@ function createWebPlacementRuntime({ components, contextContributors = [], logge
|
|
|
349
323
|
})
|
|
350
324
|
);
|
|
351
325
|
} catch (error) {
|
|
352
|
-
|
|
326
|
+
logger.warn(
|
|
353
327
|
{
|
|
354
328
|
error: String(error?.message || error || "unknown error")
|
|
355
329
|
},
|
|
@@ -432,10 +406,10 @@ function createWebPlacementRuntime({ components, contextContributors = [], logge
|
|
|
432
406
|
const normalizedSurface = normalizeSurface(surface);
|
|
433
407
|
const normalizedLayoutClass =
|
|
434
408
|
normalizePlacementLayoutClass(layoutClass) ||
|
|
435
|
-
normalizePlacementLayoutClass(sharedContext
|
|
409
|
+
normalizePlacementLayoutClass(sharedContext.layoutClass) ||
|
|
436
410
|
"compact";
|
|
437
411
|
const baseContext = isRecord(context) ? { ...context } : {};
|
|
438
|
-
const contextFromRuntime =
|
|
412
|
+
const contextFromRuntime = sharedContext;
|
|
439
413
|
const contextFromContributors = resolveContextContributors(
|
|
440
414
|
contextContributors,
|
|
441
415
|
{
|
|
@@ -447,7 +421,7 @@ function createWebPlacementRuntime({ components, contextContributors = [], logge
|
|
|
447
421
|
...baseContext
|
|
448
422
|
}
|
|
449
423
|
},
|
|
450
|
-
|
|
424
|
+
logger
|
|
451
425
|
);
|
|
452
426
|
const placementContext = {
|
|
453
427
|
...contextFromContributors,
|
|
@@ -490,7 +464,7 @@ function createWebPlacementRuntime({ components, contextContributors = [], logge
|
|
|
490
464
|
});
|
|
491
465
|
continue;
|
|
492
466
|
}
|
|
493
|
-
if (!shouldIncludePlacement(renderablePlacement, placementContext,
|
|
467
|
+
if (!shouldIncludePlacement(renderablePlacement, placementContext, logger)) {
|
|
494
468
|
debugLog("getPlacements:skip-when", {
|
|
495
469
|
placementId: renderablePlacement.id
|
|
496
470
|
});
|
|
@@ -500,7 +474,7 @@ function createWebPlacementRuntime({ components, contextContributors = [], logge
|
|
|
500
474
|
const component = resolvePlacementComponent(
|
|
501
475
|
components,
|
|
502
476
|
renderablePlacement,
|
|
503
|
-
|
|
477
|
+
logger,
|
|
504
478
|
missingTokens,
|
|
505
479
|
invalidComponentTokens,
|
|
506
480
|
failedTokens
|
|
@@ -8,6 +8,7 @@ import { isRecord } from "@jskit-ai/kernel/shared/support/normalize";
|
|
|
8
8
|
import { normalizePathname } from "@jskit-ai/kernel/shared/surface/paths";
|
|
9
9
|
import { isExternalLinkTarget, splitPathQueryHash } from "@jskit-ai/kernel/shared/support/linkPath";
|
|
10
10
|
import { resolveAllowedOriginsFromSurfaceDefinitions } from "@jskit-ai/kernel/shared/support/returnToPath";
|
|
11
|
+
import { pageOrigin } from "../browser.js";
|
|
11
12
|
|
|
12
13
|
const EMPTY_SURFACE_CONFIG = Object.freeze({
|
|
13
14
|
tenancyMode: "",
|
|
@@ -83,22 +84,14 @@ function normalizeSurfaceConfig(surfaceConfig = {}) {
|
|
|
83
84
|
});
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const surfaceDefinitions =
|
|
95
|
-
typeof surfaceRuntime.listSurfaceDefinitions === "function" ? surfaceRuntime.listSurfaceDefinitions() : [];
|
|
87
|
+
/**
|
|
88
|
+
* @param {import("@jskit-ai/kernel/client/types").ClientSurfaceRuntime} surfaceRuntime
|
|
89
|
+
* @param {object} [options]
|
|
90
|
+
* @param {string} [options.tenancyMode]
|
|
91
|
+
*/
|
|
92
|
+
function buildSurfaceConfigContext(surfaceRuntime, { tenancyMode = "" } = {}) {
|
|
96
93
|
const surfacesById = {};
|
|
97
|
-
for (const definition of
|
|
98
|
-
if (!isRecord(definition)) {
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
|
|
94
|
+
for (const definition of surfaceRuntime.listSurfaceDefinitions()) {
|
|
102
95
|
const surfaceId = normalizeSurfaceId(definition.id);
|
|
103
96
|
if (!surfaceId) {
|
|
104
97
|
continue;
|
|
@@ -107,10 +100,9 @@ function buildSurfaceConfigContext(surfaceRuntime = null, { tenancyMode = "" } =
|
|
|
107
100
|
}
|
|
108
101
|
|
|
109
102
|
return normalizeSurfaceConfig({
|
|
110
|
-
tenancyMode:
|
|
103
|
+
tenancyMode: String(tenancyMode || "").trim().toLowerCase(),
|
|
111
104
|
defaultSurfaceId: surfaceRuntime.DEFAULT_SURFACE_ID,
|
|
112
|
-
enabledSurfaceIds:
|
|
113
|
-
typeof surfaceRuntime.listEnabledSurfaceIds === "function" ? surfaceRuntime.listEnabledSurfaceIds() : [],
|
|
105
|
+
enabledSurfaceIds: surfaceRuntime.listEnabledSurfaceIds(),
|
|
114
106
|
surfacesById
|
|
115
107
|
});
|
|
116
108
|
}
|
|
@@ -122,9 +114,9 @@ function readPlacementSurfaceConfig(contextValue = null) {
|
|
|
122
114
|
|
|
123
115
|
// Origins a return-to URL may point at: this page plus every surface origin.
|
|
124
116
|
function resolveAllowedOriginsFromPlacementContext(contextValue = null) {
|
|
125
|
-
const
|
|
117
|
+
const origin = pageOrigin();
|
|
126
118
|
return resolveAllowedOriginsFromSurfaceDefinitions(readPlacementSurfaceConfig(contextValue).surfacesById, {
|
|
127
|
-
seedOrigins
|
|
119
|
+
seedOrigins: origin ? [origin] : []
|
|
128
120
|
});
|
|
129
121
|
}
|
|
130
122
|
|
|
@@ -182,16 +174,7 @@ function normalizeSurfaceOrigin(originValue = "") {
|
|
|
182
174
|
}
|
|
183
175
|
|
|
184
176
|
function resolveRuntimeOrigin(currentOrigin = "") {
|
|
185
|
-
|
|
186
|
-
if (normalizedCurrentOrigin) {
|
|
187
|
-
return normalizedCurrentOrigin;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (typeof window === "object" && window?.location?.origin) {
|
|
191
|
-
return normalizeSurfaceOrigin(window.location.origin);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return "";
|
|
177
|
+
return normalizeSurfaceOrigin(currentOrigin) || normalizeSurfaceOrigin(pageOrigin());
|
|
195
178
|
}
|
|
196
179
|
|
|
197
180
|
function resolveSurfaceNavigationTargetFromPlacementContext(
|
|
@@ -268,9 +251,7 @@ function createPlacementSurfacePathHelpers(surfaceConfig = EMPTY_SURFACE_CONFIG)
|
|
|
268
251
|
|
|
269
252
|
function resolveSurfaceIdFromPlacementPathname(contextValue = null, pathname = "") {
|
|
270
253
|
const surfaceConfig = readPlacementSurfaceConfig(contextValue);
|
|
271
|
-
const normalizedPathname =
|
|
272
|
-
normalizePathname(pathname) ||
|
|
273
|
-
(typeof window === "object" && window?.location?.pathname ? normalizePathname(window.location.pathname) : "/");
|
|
254
|
+
const normalizedPathname = normalizePathname(pathname);
|
|
274
255
|
const pathHelpers = createPlacementSurfacePathHelpers(surfaceConfig);
|
|
275
256
|
if (!pathHelpers) {
|
|
276
257
|
return "";
|
|
@@ -8,6 +8,11 @@ import {
|
|
|
8
8
|
resolvePlacementTargetReference
|
|
9
9
|
} from "@jskit-ai/kernel/shared/support/shellLayoutTargets";
|
|
10
10
|
|
|
11
|
+
// A placement that appears only sometimes supplies its own when().
|
|
12
|
+
function placeAlways() {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
|
|
11
16
|
function isRenderableComponent(value) {
|
|
12
17
|
if (typeof value === "function") {
|
|
13
18
|
return true;
|
|
@@ -105,7 +110,7 @@ function normalizePlacementDefinition(value, { strict = false, source = "placeme
|
|
|
105
110
|
}
|
|
106
111
|
|
|
107
112
|
const props = isRecord(value.props) ? { ...value.props } : {};
|
|
108
|
-
const when =
|
|
113
|
+
const when = value.when || placeAlways;
|
|
109
114
|
const surfaces = normalizePlacementSurfaces(value.surfaces, {
|
|
110
115
|
strict,
|
|
111
116
|
source: `${source} "${id}"`
|
|
@@ -17,9 +17,9 @@ import {
|
|
|
17
17
|
createShellRequestRecoveryRuntime
|
|
18
18
|
} from "../requestRecovery/runtime.js";
|
|
19
19
|
import {
|
|
20
|
-
isRecord
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
isRecord,
|
|
21
|
+
normalizeObject
|
|
22
|
+
} from "@jskit-ai/kernel/shared/support/normalize";
|
|
23
23
|
import {
|
|
24
24
|
createDefaultErrorPolicy
|
|
25
25
|
} from "../error/policy.js";
|
|
@@ -67,11 +67,11 @@ async function loadAppModule({
|
|
|
67
67
|
loadFailureMessage,
|
|
68
68
|
fallback,
|
|
69
69
|
logger,
|
|
70
|
-
asyncModuleRecoveryRuntime
|
|
70
|
+
asyncModuleRecoveryRuntime
|
|
71
71
|
}) {
|
|
72
72
|
try {
|
|
73
73
|
const moduleNamespace = await importModule();
|
|
74
|
-
const exported = moduleNamespace
|
|
74
|
+
const exported = moduleNamespace.default;
|
|
75
75
|
const resolved = await resolve(exported);
|
|
76
76
|
if (resolved !== undefined) {
|
|
77
77
|
return resolved;
|
|
@@ -102,7 +102,7 @@ async function loadAppModule({
|
|
|
102
102
|
return fallback;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
function loadAppPlacementDefinitions(logger, asyncModuleRecoveryRuntime
|
|
105
|
+
function loadAppPlacementDefinitions(logger, asyncModuleRecoveryRuntime) {
|
|
106
106
|
return loadAppModule({
|
|
107
107
|
importModule: () => import("/src/placement.js"),
|
|
108
108
|
specifier: APP_PLACEMENT_MODULE_SPECIFIER,
|
|
@@ -119,7 +119,7 @@ function loadAppPlacementDefinitions(logger, asyncModuleRecoveryRuntime = null)
|
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
function loadAppPlacementTopology(logger, asyncModuleRecoveryRuntime
|
|
122
|
+
function loadAppPlacementTopology(logger, asyncModuleRecoveryRuntime) {
|
|
123
123
|
return loadAppModule({
|
|
124
124
|
importModule: () => import("/src/placementTopology.js"),
|
|
125
125
|
specifier: APP_PLACEMENT_TOPOLOGY_MODULE_SPECIFIER,
|
|
@@ -164,7 +164,7 @@ function createErrorConfigToolkit(errorRuntime) {
|
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
function loadAppErrorConfig(logger, errorRuntime, asyncModuleRecoveryRuntime
|
|
167
|
+
function loadAppErrorConfig(logger, errorRuntime, asyncModuleRecoveryRuntime) {
|
|
168
168
|
return loadAppModule({
|
|
169
169
|
importModule: () => import("/src/error.js"),
|
|
170
170
|
specifier: APP_ERROR_MODULE_SPECIFIER,
|
|
@@ -183,11 +183,7 @@ function loadAppErrorConfig(logger, errorRuntime, asyncModuleRecoveryRuntime = n
|
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
function installVueErrorBridge(vueApp, errorRuntime, logger) {
|
|
186
|
-
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const previousHandler = typeof vueApp.config.errorHandler === "function" ? vueApp.config.errorHandler : null;
|
|
186
|
+
const previousHandler = vueApp.config.errorHandler;
|
|
191
187
|
|
|
192
188
|
vueApp.config.errorHandler = (error, instance, info) => {
|
|
193
189
|
try {
|
|
@@ -218,10 +214,6 @@ function installVueErrorBridge(vueApp, errorRuntime, logger) {
|
|
|
218
214
|
}
|
|
219
215
|
|
|
220
216
|
function installRouterErrorBridge(router, errorRuntime, logger) {
|
|
221
|
-
if (!router || typeof router.onError !== "function") {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
217
|
router.onError((error) => {
|
|
226
218
|
if (isDynamicImportError(error)) {
|
|
227
219
|
return;
|
|
@@ -253,7 +245,7 @@ const ShellWebClientProvider = defineProvider({
|
|
|
253
245
|
id: "shell.web.client",
|
|
254
246
|
requires: {
|
|
255
247
|
components: "client.components",
|
|
256
|
-
|
|
248
|
+
logger: "client.logger",
|
|
257
249
|
pinia: "client.pinia",
|
|
258
250
|
queryClient: "client.query",
|
|
259
251
|
router: "client.router",
|
|
@@ -266,23 +258,21 @@ const ShellWebClientProvider = defineProvider({
|
|
|
266
258
|
provides: {
|
|
267
259
|
shell: "client.shell"
|
|
268
260
|
},
|
|
269
|
-
setup({ components,
|
|
270
|
-
const logger = createSharedProviderLogger(loggerInput);
|
|
261
|
+
setup({ components, logger, queryClient, router }) {
|
|
271
262
|
const bootstrapHandlers = createBootstrapPayloadHandlerRegistry();
|
|
272
263
|
bootstrapHandlers.register(
|
|
273
264
|
Object.freeze({
|
|
274
265
|
handlerId: "shell.web.bootstrap.surface-access",
|
|
275
266
|
order: 0,
|
|
276
|
-
applyBootstrapPayload({ payload
|
|
267
|
+
applyBootstrapPayload({ payload, placementRuntime, source }) {
|
|
277
268
|
placementRuntime.setContext(
|
|
278
269
|
{
|
|
279
|
-
surfaceAccess:
|
|
280
|
-
payload?.surfaceAccess && typeof payload.surfaceAccess === "object" ? payload.surfaceAccess : {}
|
|
270
|
+
surfaceAccess: normalizeObject(normalizeObject(payload).surfaceAccess)
|
|
281
271
|
},
|
|
282
272
|
{ source }
|
|
283
273
|
);
|
|
284
274
|
},
|
|
285
|
-
handleBootstrapError({ error, placementRuntime, source }
|
|
275
|
+
handleBootstrapError({ error, placementRuntime, source }) {
|
|
286
276
|
if (resolveBootstrapErrorStatusCode(error) !== 401) {
|
|
287
277
|
return;
|
|
288
278
|
}
|
|
@@ -341,8 +331,7 @@ const ShellWebClientProvider = defineProvider({
|
|
|
341
331
|
})
|
|
342
332
|
};
|
|
343
333
|
},
|
|
344
|
-
async boot({
|
|
345
|
-
const logger = createSharedProviderLogger(loggerInput);
|
|
334
|
+
async boot({ logger, pinia, realtime, router, surfaceRuntime, vueApp }, { outputs }) {
|
|
346
335
|
const {
|
|
347
336
|
asyncModuleRecovery: asyncModuleRecoveryRuntime,
|
|
348
337
|
bootstrap: bootstrapRuntime,
|
|
@@ -361,16 +350,12 @@ const ShellWebClientProvider = defineProvider({
|
|
|
361
350
|
placementRuntime.replacePlacements(placements, { source: APP_PLACEMENT_MODULE_SPECIFIER });
|
|
362
351
|
const appConfig = getClientAppConfig();
|
|
363
352
|
const surfaceConfig = buildSurfaceConfigContext(surfaceRuntime, {
|
|
364
|
-
tenancyMode: appConfig
|
|
353
|
+
tenancyMode: appConfig.tenancyMode
|
|
365
354
|
});
|
|
366
|
-
const surfaceAccessPolicies =
|
|
367
|
-
appConfig?.surfaceAccessPolicies && typeof appConfig.surfaceAccessPolicies === "object"
|
|
368
|
-
? appConfig.surfaceAccessPolicies
|
|
369
|
-
: {};
|
|
370
355
|
placementRuntime.setContext(
|
|
371
356
|
{
|
|
372
357
|
surfaceConfig,
|
|
373
|
-
surfaceAccessPolicies
|
|
358
|
+
surfaceAccessPolicies: normalizeObject(appConfig.surfaceAccessPolicies)
|
|
374
359
|
},
|
|
375
360
|
{
|
|
376
361
|
source: "shell-web.surface-config"
|
|
@@ -385,12 +370,6 @@ const ShellWebClientProvider = defineProvider({
|
|
|
385
370
|
|
|
386
371
|
await bootstrapRuntime.initialize();
|
|
387
372
|
|
|
388
|
-
if (!vueApp || typeof vueApp.provide !== "function" || typeof vueApp.use !== "function") {
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
if (!pinia) {
|
|
392
|
-
throw new Error("ShellWebClientProvider requires Pinia installed in the client app.");
|
|
393
|
-
}
|
|
394
373
|
useShellErrorPresentationStore(pinia).attachRuntimeStore(errorPresentationStore);
|
|
395
374
|
|
|
396
375
|
vueApp.provide(SHELL_WEB_PLACEMENT_RUNTIME_KEY, placementRuntime);
|
|
@@ -17,7 +17,7 @@ function isMissingDynamicModule(error, moduleSpecifier) {
|
|
|
17
17
|
function notifyDynamicImportFailure(asyncModuleRecoveryRuntime, error, {
|
|
18
18
|
label = t("jskit.shell.recovery.appModuleLabel")
|
|
19
19
|
} = {}) {
|
|
20
|
-
if (!isDynamicImportError(error)
|
|
20
|
+
if (!isDynamicImportError(error)) {
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
|