@jskit-ai/shell-web 0.2.4 → 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/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 +14 -22
- 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 +20 -17
- 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 +4 -16
- package/src/client/placement/surfaceContext.js +14 -33
- package/src/client/placement/validators.js +6 -1
- package/src/client/providers/ShellWebClientProvider.js +14 -32
- 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 +33 -84
- package/src/client/runtime/bootstrapRuntime.js +10 -32
- package/src/client/runtime/refreshRuntime.js +24 -21
- 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/browser.test.js +51 -0
- package/test/clientUpdate.test.js +12 -1
- package/test/drawerWidth.test.js +64 -0
- package/test/errorActions.test.js +7 -2
- package/test/errorPresentation.test.js +51 -0
- package/test/placementInject.test.js +60 -0
- 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 +12 -8
- package/test/support/mountComposable.js +90 -0
- package/test/useShellDrawer.test.js +213 -0
- package/test/useShellErrorHost.test.js +149 -0
- package/test/useShellRouteTransition.test.js +129 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/shell-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test --test-concurrency=1"
|
|
@@ -25,19 +25,20 @@
|
|
|
25
25
|
"./client/components/ShellTabLinkItem": "./src/client/components/ShellTabLinkItem.vue",
|
|
26
26
|
"./client/composables/useShellLayoutState": "./src/client/composables/useShellLayoutState.js",
|
|
27
27
|
"./client/providers/ShellWebClientProvider": "./src/client/providers/ShellWebClientProvider.js",
|
|
28
|
+
"./client/types": "./src/client/types.js",
|
|
28
29
|
"./test/adaptiveShellSmoke": "./src/test/adaptiveShellSmoke.js",
|
|
29
30
|
"./architecture": "./src/architecture/inspectVueArchitecture.js",
|
|
30
31
|
"./locales/en.json": "./locales/en.json"
|
|
31
32
|
},
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"@jskit-ai/architecture-inspector": "0.1.
|
|
34
|
+
"@jskit-ai/architecture-inspector": "0.1.3",
|
|
34
35
|
"@mdi/js": "^7.4.47"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"@vue/compiler-sfc": "3.5.44"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
|
-
"@jskit-ai/kernel": "0.2.
|
|
41
|
+
"@jskit-ai/kernel": "0.2.5",
|
|
41
42
|
"pinia": "^4.0.3",
|
|
42
43
|
"vue": "^3.5.44",
|
|
43
44
|
"vue-router": "^5.3.1",
|
|
@@ -77,7 +78,8 @@
|
|
|
77
78
|
"@jskit-ai/shell-web/client/navigation/linkResolver",
|
|
78
79
|
"@jskit-ai/shell-web/client/navigation/usePaths",
|
|
79
80
|
"@jskit-ai/shell-web/client/navigation/useSurfaceRouteContext",
|
|
80
|
-
"@jskit-ai/shell-web/client/composables/useShellLayoutState"
|
|
81
|
+
"@jskit-ai/shell-web/client/composables/useShellLayoutState",
|
|
82
|
+
"@jskit-ai/shell-web/client/types"
|
|
81
83
|
],
|
|
82
84
|
"exclude": [
|
|
83
85
|
"@jskit-ai/shell-web/client"
|
|
@@ -115,6 +117,10 @@
|
|
|
115
117
|
"subpath": "./client/bootstrap",
|
|
116
118
|
"summary": "Exports the shared client bootstrap handler registry used to extend /api/bootstrap handling."
|
|
117
119
|
},
|
|
120
|
+
{
|
|
121
|
+
"subpath": "./client/types",
|
|
122
|
+
"summary": "Declares the shell runtimes' types for the packages that receive them."
|
|
123
|
+
},
|
|
118
124
|
{
|
|
119
125
|
"subpath": "./test/adaptiveShellSmoke",
|
|
120
126
|
"summary": "Exports reusable Playwright smoke coverage for generated adaptive shell layouts."
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const placements = [];
|
|
2
2
|
|
|
3
|
+
// readable-check: allow duplicate-helper - safety invariant: an application copies each pattern example on its own, so importing this from another example would break the copy
|
|
3
4
|
function addPlacementTopology(value = {}) {
|
|
4
5
|
placements.push(value);
|
|
5
6
|
}
|
|
@@ -1,30 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
inject
|
|
4
|
-
} from "vue";
|
|
1
|
+
import { inject } from "vue";
|
|
2
|
+
import { createAsyncModuleRecoveryState } from "@jskit-ai/kernel/client/asyncModuleRecovery";
|
|
5
3
|
|
|
6
4
|
const SHELL_ASYNC_MODULE_RECOVERY_RUNTIME_KEY =
|
|
7
5
|
"jskit.shell-web.runtime.web-async-module-recovery.client";
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The recovery of an application without shell-web's provider: nothing is reported and nothing reloads.
|
|
9
|
+
* @type {import("../types.js").ShellAsyncModuleRecoveryRuntime}
|
|
10
|
+
*/
|
|
11
|
+
const NO_SHELL_ASYNC_MODULE_RECOVERY_RUNTIME = Object.freeze({
|
|
12
|
+
dispose() {},
|
|
13
|
+
install() {
|
|
14
|
+
return Object.freeze({
|
|
15
|
+
dispose() {}
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
notify() {
|
|
19
19
|
return null;
|
|
20
|
-
}
|
|
20
|
+
},
|
|
21
|
+
async reload() {
|
|
22
|
+
return false;
|
|
23
|
+
},
|
|
24
|
+
report() {
|
|
25
|
+
return null;
|
|
26
|
+
},
|
|
27
|
+
state: Object.freeze(createAsyncModuleRecoveryState())
|
|
28
|
+
});
|
|
21
29
|
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
/**
|
|
31
|
+
* The shell's module recovery, or `NO_SHELL_ASYNC_MODULE_RECOVERY_RUNTIME` in an application without shell-web's provider.
|
|
32
|
+
* @returns {import("../types.js").ShellAsyncModuleRecoveryRuntime}
|
|
33
|
+
*/
|
|
34
|
+
function useShellAsyncModuleRecoveryRuntime() {
|
|
35
|
+
return inject(SHELL_ASYNC_MODULE_RECOVERY_RUNTIME_KEY, NO_SHELL_ASYNC_MODULE_RECOVERY_RUNTIME);
|
|
24
36
|
}
|
|
25
37
|
|
|
26
38
|
export {
|
|
39
|
+
NO_SHELL_ASYNC_MODULE_RECOVERY_RUNTIME,
|
|
27
40
|
SHELL_ASYNC_MODULE_RECOVERY_RUNTIME_KEY,
|
|
28
|
-
isShellAsyncModuleRecoveryRuntime,
|
|
29
41
|
useShellAsyncModuleRecoveryRuntime
|
|
30
42
|
};
|
|
@@ -12,41 +12,31 @@ const { t } = useJskitText();
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* @param {object} options
|
|
15
|
-
* @param {
|
|
16
|
-
* @param {
|
|
17
|
-
* @param {import("@jskit-ai/kernel/
|
|
15
|
+
* @param {import("@jskit-ai/kernel/client/types").ClientRouter} options.router
|
|
16
|
+
* @param {import("../types.js").ShellErrorRuntime} options.errorRuntime
|
|
17
|
+
* @param {import("@jskit-ai/kernel/client/types").ClientLogger} options.logger
|
|
18
18
|
*/
|
|
19
19
|
function createShellAsyncModuleRecoveryRuntime({
|
|
20
|
-
router
|
|
21
|
-
errorRuntime
|
|
20
|
+
router,
|
|
21
|
+
errorRuntime,
|
|
22
22
|
logger
|
|
23
23
|
}) {
|
|
24
24
|
const state = createAsyncModuleRecoveryState();
|
|
25
25
|
let installedRecovery = null;
|
|
26
26
|
|
|
27
27
|
function report(nextState = state) {
|
|
28
|
-
if (!errorRuntime || typeof errorRuntime.report !== "function") {
|
|
29
|
-
logger.warn(
|
|
30
|
-
{
|
|
31
|
-
label: String(nextState?.label || "")
|
|
32
|
-
},
|
|
33
|
-
"Async module recovery could not report because the shell error runtime is unavailable."
|
|
34
|
-
);
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
28
|
try {
|
|
39
29
|
return errorRuntime.report({
|
|
40
30
|
source: "shell-web.async-module-recovery",
|
|
41
|
-
message: String(nextState
|
|
31
|
+
message: String(nextState.message || t("jskit.shell.recovery.moduleFailed")),
|
|
42
32
|
// The kernel's sentence for this failure, so the whole message is translated.
|
|
43
|
-
...(nextState
|
|
33
|
+
...(nextState.message && nextState.messageCode
|
|
44
34
|
? { messageCode: nextState.messageCode, messageParams: nextState.messageParams }
|
|
45
35
|
: {}),
|
|
46
|
-
cause: nextState
|
|
36
|
+
cause: nextState.error || null,
|
|
47
37
|
intent: "app-recoverable",
|
|
48
38
|
severity: "warning",
|
|
49
|
-
dedupeKey: `shell-web.async-module-recovery.${Number(nextState
|
|
39
|
+
dedupeKey: `shell-web.async-module-recovery.${Number(nextState.attempt || 0)}`,
|
|
50
40
|
action: {
|
|
51
41
|
label: t("jskit.shell.actions.reload"),
|
|
52
42
|
dismissOnRun: true,
|
|
@@ -58,7 +48,7 @@ function createShellAsyncModuleRecoveryRuntime({
|
|
|
58
48
|
} catch (error) {
|
|
59
49
|
logger.error(
|
|
60
50
|
{
|
|
61
|
-
label: String(nextState
|
|
51
|
+
label: String(nextState.label || ""),
|
|
62
52
|
error: String(error?.message || error || "unknown error")
|
|
63
53
|
},
|
|
64
54
|
"Async module recovery could not report through the shell error runtime."
|
|
@@ -108,8 +98,10 @@ function createShellAsyncModuleRecoveryRuntime({
|
|
|
108
98
|
}
|
|
109
99
|
|
|
110
100
|
function dispose() {
|
|
111
|
-
installedRecovery
|
|
112
|
-
|
|
101
|
+
if (installedRecovery) {
|
|
102
|
+
installedRecovery.dispose();
|
|
103
|
+
installedRecovery = null;
|
|
104
|
+
}
|
|
113
105
|
}
|
|
114
106
|
|
|
115
107
|
return Object.freeze({
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
+
// A handler that shapes the request or answers failures supplies these; every other handler has them too.
|
|
2
|
+
function contributeNoBootstrapRequest() {
|
|
3
|
+
return {};
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
function ignoreBootstrapError() {}
|
|
7
|
+
|
|
1
8
|
function normalizeBootstrapPayloadHandler(entry) {
|
|
2
9
|
if (typeof entry === "function") {
|
|
3
10
|
return Object.freeze({
|
|
4
11
|
handlerId: String(entry.name || "anonymous"),
|
|
5
12
|
order: 0,
|
|
6
|
-
applyBootstrapPayload: entry
|
|
13
|
+
applyBootstrapPayload: entry,
|
|
14
|
+
resolveBootstrapRequest: contributeNoBootstrapRequest,
|
|
15
|
+
handleBootstrapError: ignoreBootstrapError
|
|
7
16
|
});
|
|
8
17
|
}
|
|
9
18
|
|
|
10
|
-
if (!entry || typeof entry !== "object" || typeof entry.applyBootstrapPayload !== "function") {
|
|
11
|
-
throw new TypeError("Bootstrap payload handlers require applyBootstrapPayload().");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
19
|
const handlerId = String(entry.handlerId || "").trim();
|
|
15
20
|
if (!handlerId) {
|
|
16
21
|
throw new TypeError("Bootstrap payload handlers require handlerId.");
|
|
@@ -19,7 +24,9 @@ function normalizeBootstrapPayloadHandler(entry) {
|
|
|
19
24
|
return Object.freeze({
|
|
20
25
|
...entry,
|
|
21
26
|
handlerId,
|
|
22
|
-
order: Number.isFinite(entry.order) ? Number(entry.order) : 0
|
|
27
|
+
order: Number.isFinite(entry.order) ? Number(entry.order) : 0,
|
|
28
|
+
resolveBootstrapRequest: entry.resolveBootstrapRequest || contributeNoBootstrapRequest,
|
|
29
|
+
handleBootstrapError: entry.handleBootstrapError || ignoreBootstrapError
|
|
23
30
|
});
|
|
24
31
|
}
|
|
25
32
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What shell-web reads from the browser, each probe written once. Outside a browser, as in a test, there is no window
|
|
3
|
+
* and no document.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** The page's window; null outside a browser. */
|
|
7
|
+
function pageWindow() {
|
|
8
|
+
return typeof window !== "undefined" ? window : null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** The page's document; null outside a browser. */
|
|
12
|
+
function pageDocument() {
|
|
13
|
+
return typeof document !== "undefined" ? document : null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The page's path; empty outside a browser. */
|
|
17
|
+
function pagePathname() {
|
|
18
|
+
return String(pageWindow()?.location?.pathname || "").trim();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The page's origin; empty outside a browser. */
|
|
22
|
+
function pageOrigin() {
|
|
23
|
+
return String(pageWindow()?.location?.origin || "");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The page's title; empty outside a browser. */
|
|
27
|
+
function pageTitle() {
|
|
28
|
+
return String(pageDocument()?.title || "");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The viewport's width; 0 outside a browser. */
|
|
32
|
+
function pageViewportWidth() {
|
|
33
|
+
return Number(pageWindow()?.innerWidth || 0);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The page's local storage; null outside a browser. */
|
|
37
|
+
function pageStorage() {
|
|
38
|
+
return pageWindow()?.localStorage || null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The nearest element matching the selectors, from an event's target. */
|
|
42
|
+
function closestElement(target, selectors) {
|
|
43
|
+
// readable-check: allow optional-call - platform object: an event's target may be the window or a text node, which have no closest()
|
|
44
|
+
return target?.closest?.(selectors) || null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
closestElement,
|
|
49
|
+
pageDocument,
|
|
50
|
+
pageOrigin,
|
|
51
|
+
pagePathname,
|
|
52
|
+
pageStorage,
|
|
53
|
+
pageTitle,
|
|
54
|
+
pageViewportWidth,
|
|
55
|
+
pageWindow
|
|
56
|
+
};
|
|
@@ -1,26 +1,32 @@
|
|
|
1
1
|
import { pageClientBuildId } from "@jskit-ai/kernel/shared/support/clientBuild";
|
|
2
2
|
import { normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
|
|
3
|
+
import { pageTitle } from "../browser.js";
|
|
3
4
|
import { useJskitText } from "../i18n.js";
|
|
4
5
|
|
|
5
6
|
const { t } = useJskitText();
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
// may change the tab title later.
|
|
9
|
-
function loadedAppName(documentObject = globalThis.document) {
|
|
10
|
-
return normalizeText(documentObject?.title);
|
|
11
|
-
}
|
|
8
|
+
function stopNothing() {}
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Offers a reload when the server serves a different client build from the one
|
|
12
|
+
* this page runs, as it does after an update. It never reloads by itself: the
|
|
13
|
+
* person may be in the middle of something. Reload returns to the same address.
|
|
14
|
+
* The title the page loaded with (index.html's <title>) names the app; screens
|
|
15
|
+
* may change the tab title later.
|
|
16
|
+
* @param {object} options
|
|
17
|
+
* @param {import("../types.js").ShellErrorRuntime} options.errorRuntime
|
|
18
|
+
* @param {() => unknown} options.reload
|
|
19
|
+
* @param {string} [options.pageBuildId]
|
|
20
|
+
* @param {string} [options.appName]
|
|
21
|
+
*/
|
|
16
22
|
function createShellClientUpdateRuntime({
|
|
17
23
|
errorRuntime,
|
|
18
24
|
reload,
|
|
19
25
|
pageBuildId = pageClientBuildId(),
|
|
20
|
-
appName =
|
|
21
|
-
}
|
|
26
|
+
appName = normalizeText(pageTitle())
|
|
27
|
+
}) {
|
|
22
28
|
let offer = null;
|
|
23
|
-
let stopWatching =
|
|
29
|
+
let stopWatching = stopNothing;
|
|
24
30
|
|
|
25
31
|
function withdraw() {
|
|
26
32
|
if (offer?.presentationId) {
|
|
@@ -48,7 +54,7 @@ function createShellClientUpdateRuntime({
|
|
|
48
54
|
}
|
|
49
55
|
}
|
|
50
56
|
});
|
|
51
|
-
offer = { buildId: servedBuildId, presentationId: normalizeText(result
|
|
57
|
+
offer = { buildId: servedBuildId, presentationId: normalizeText(result.presentationId) };
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
// One offer per served build: a reconnection to the same build does not
|
|
@@ -64,16 +70,20 @@ function createShellClientUpdateRuntime({
|
|
|
64
70
|
}
|
|
65
71
|
}
|
|
66
72
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
/**
|
|
74
|
+
* @param {import("../types.js").ShellRealtime} [realtime] The optional client.realtime capability, which names the
|
|
75
|
+
* server's build on every connection.
|
|
76
|
+
*/
|
|
77
|
+
function watch(realtime) {
|
|
70
78
|
dispose();
|
|
71
|
-
|
|
79
|
+
if (realtime) {
|
|
80
|
+
stopWatching = realtime.onServedClientBuild(check);
|
|
81
|
+
}
|
|
72
82
|
}
|
|
73
83
|
|
|
74
84
|
function dispose() {
|
|
75
|
-
stopWatching
|
|
76
|
-
stopWatching =
|
|
85
|
+
stopWatching();
|
|
86
|
+
stopWatching = stopNothing;
|
|
77
87
|
}
|
|
78
88
|
|
|
79
89
|
return Object.freeze({
|
|
@@ -1,229 +1,29 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import {
|
|
3
|
-
import { useLayout } from "vuetify";
|
|
4
|
-
import { mdiAlertOutline, mdiCheckCircleOutline, mdiInformationOutline } from "@mdi/js";
|
|
2
|
+
import { useShellErrorHost } from "../composables/useShellErrorHost.js";
|
|
5
3
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
actionsFor,
|
|
5
|
+
resolveSeverityColor,
|
|
6
|
+
resolveSeverityIcon,
|
|
7
|
+
resolveTimeout
|
|
8
|
+
} from "../error/presentation.js";
|
|
9
9
|
import { useJskitText } from "../i18n.js";
|
|
10
10
|
|
|
11
|
-
const runtime = useShellWebErrorRuntime();
|
|
12
11
|
// Entries keep the server's code and params, so an API error shows in the
|
|
13
12
|
// user's language; anything else shows as reported.
|
|
14
13
|
const { t, text, serverMessage } = useJskitText();
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Banners float just below a top app bar. A surface without one (sign-in pages)
|
|
32
|
-
// has nothing to float under, so the banners join the page flow above the
|
|
33
|
-
// content instead of covering it, and publish their height so full-viewport
|
|
34
|
-
// surfaces can start below them.
|
|
35
|
-
const BANNER_INLINE_HEIGHT_PROPERTY = "--shell-error-banners-inline-height";
|
|
36
|
-
const bannersElement = ref(null);
|
|
37
|
-
const bannerPlacement = computed(() => {
|
|
38
|
-
const rect = layoutRect?.value || {};
|
|
39
|
-
const top = Number(rect.top) || 0;
|
|
40
|
-
if (top <= 0) {
|
|
41
|
-
return { inline: true, style: undefined };
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
inline: false,
|
|
46
|
-
style: {
|
|
47
|
-
top: `calc(env(safe-area-inset-top, 0px) + ${top}px)`,
|
|
48
|
-
left: `${Number(rect.left) || 0}px`,
|
|
49
|
-
right: `${Number(rect.right) || 0}px`
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
let bannerResizeObserver = null;
|
|
54
|
-
|
|
55
|
-
function publishInlineBannerHeight(height = 0) {
|
|
56
|
-
const rootStyle = globalThis.document?.documentElement?.style;
|
|
57
|
-
if (!rootStyle) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (height > 0) {
|
|
61
|
-
rootStyle.setProperty(BANNER_INLINE_HEIGHT_PROPERTY, `${Math.ceil(height)}px`);
|
|
62
|
-
} else {
|
|
63
|
-
rootStyle.removeProperty(BANNER_INLINE_HEIGHT_PROPERTY);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function stopObservingBanners() {
|
|
68
|
-
bannerResizeObserver?.disconnect();
|
|
69
|
-
bannerResizeObserver = null;
|
|
70
|
-
publishInlineBannerHeight(0);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
watch(
|
|
74
|
-
[bannersElement, () => bannerPlacement.value.inline],
|
|
75
|
-
([element, inline]) => {
|
|
76
|
-
stopObservingBanners();
|
|
77
|
-
if (!element || !inline || typeof globalThis.ResizeObserver !== "function") {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
bannerResizeObserver = new globalThis.ResizeObserver(() => {
|
|
81
|
-
publishInlineBannerHeight(element.getBoundingClientRect().height);
|
|
82
|
-
});
|
|
83
|
-
bannerResizeObserver.observe(element);
|
|
84
|
-
publishInlineBannerHeight(element.getBoundingClientRect().height);
|
|
85
|
-
},
|
|
86
|
-
{ flush: "post" }
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
onBeforeUnmount(stopObservingBanners);
|
|
90
|
-
const snackbarOpen = ref(false);
|
|
91
|
-
|
|
92
|
-
function isSameSnackbarEntry(left = null, right = null) {
|
|
93
|
-
return Boolean(left?.id && right?.id && left.id === right.id);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function hasSnackbarEntry(entry = null) {
|
|
97
|
-
if (!entry?.id) {
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return snackbarEntries.value.some((candidate) => isSameSnackbarEntry(candidate, entry));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function openNextSnackbarEntry() {
|
|
105
|
-
const nextEntry = snackbarEntries.value[0] || null;
|
|
106
|
-
if (!nextEntry) {
|
|
107
|
-
displayedSnackbarEntry.value = null;
|
|
108
|
-
snackbarOpen.value = false;
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
displayedSnackbarEntry.value = nextEntry;
|
|
113
|
-
snackbarOpen.value = true;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
watch(
|
|
117
|
-
snackbarEntries,
|
|
118
|
-
(entries) => {
|
|
119
|
-
const currentEntry = displayedSnackbarEntry.value;
|
|
120
|
-
if (!currentEntry) {
|
|
121
|
-
openNextSnackbarEntry();
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const matchingEntry = entries.find((entry) => isSameSnackbarEntry(entry, currentEntry)) || null;
|
|
126
|
-
if (matchingEntry) {
|
|
127
|
-
displayedSnackbarEntry.value = matchingEntry;
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
snackbarOpen.value = false;
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
immediate: true
|
|
135
|
-
}
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
function resolveSeverityColor(severity = "error") {
|
|
139
|
-
const normalized = String(severity || "error").trim().toLowerCase();
|
|
140
|
-
if (normalized === "info") {
|
|
141
|
-
return "info";
|
|
142
|
-
}
|
|
143
|
-
if (normalized === "success") {
|
|
144
|
-
return "success";
|
|
145
|
-
}
|
|
146
|
-
if (normalized === "warning") {
|
|
147
|
-
return "warning";
|
|
148
|
-
}
|
|
149
|
-
return "error";
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function resolveSeverityIcon(severity = "error") {
|
|
153
|
-
const normalized = String(severity || "error").trim().toLowerCase();
|
|
154
|
-
if (normalized === "info") {
|
|
155
|
-
return mdiInformationOutline;
|
|
156
|
-
}
|
|
157
|
-
if (normalized === "success") {
|
|
158
|
-
return mdiCheckCircleOutline;
|
|
159
|
-
}
|
|
160
|
-
return mdiAlertOutline;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function resolveTimeout(entry) {
|
|
164
|
-
if (!entry) {
|
|
165
|
-
return -1;
|
|
166
|
-
}
|
|
167
|
-
if (entry.persist) {
|
|
168
|
-
return -1;
|
|
169
|
-
}
|
|
170
|
-
return 5000;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function dismiss(entry) {
|
|
174
|
-
if (!entry || !entry.channel || !entry.id) {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
store.dismiss(entry.channel, entry.id);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function actionsFor(entry) {
|
|
182
|
-
return entry ? [entry.action, ...entry.additionalActions].filter(Boolean) : [];
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
async function runAction(entry, action) {
|
|
186
|
-
if (!entry || typeof action?.handler !== "function") {
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
try {
|
|
191
|
-
await action.handler(entry);
|
|
192
|
-
} catch (error) {
|
|
193
|
-
runtime.report({
|
|
194
|
-
source: "shell-web.error-host.action",
|
|
195
|
-
message: t("jskit.shell.error.actionFailed"),
|
|
196
|
-
cause: error,
|
|
197
|
-
intent: "blocking",
|
|
198
|
-
severity: "error"
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (action.dismissOnRun !== false) {
|
|
203
|
-
dismiss(entry);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function onSnackbarModelValue(nextValue) {
|
|
208
|
-
if (nextValue === false && displayedSnackbarEntry.value) {
|
|
209
|
-
snackbarOpen.value = false;
|
|
210
|
-
dismiss(displayedSnackbarEntry.value);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function onDialogModelValue(nextValue) {
|
|
215
|
-
if (nextValue === false && dialogEntry.value && dialogEntry.value.persist !== true) {
|
|
216
|
-
dismiss(dialogEntry.value);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
function onSnackbarAfterLeave() {
|
|
221
|
-
if (hasSnackbarEntry(displayedSnackbarEntry.value)) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
openNextSnackbarEntry();
|
|
226
|
-
}
|
|
14
|
+
const {
|
|
15
|
+
bannerEntries,
|
|
16
|
+
bannerPlacement,
|
|
17
|
+
bannersElement,
|
|
18
|
+
dialogEntry,
|
|
19
|
+
dismiss,
|
|
20
|
+
displayedSnackbarEntry,
|
|
21
|
+
onDialogModelValue,
|
|
22
|
+
onSnackbarAfterLeave,
|
|
23
|
+
onSnackbarModelValue,
|
|
24
|
+
runAction,
|
|
25
|
+
snackbarOpen
|
|
26
|
+
} = useShellErrorHost();
|
|
227
27
|
</script>
|
|
228
28
|
|
|
229
29
|
<template>
|