@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.
Files changed (74) hide show
  1. package/fixtures/adaptive-shell/src/main.js +4 -2
  2. package/package.json +10 -4
  3. package/patterns/page-and-placement/example/src/placementTopology.js +1 -0
  4. package/src/client/asyncModuleRecovery/index.js +1 -0
  5. package/src/client/asyncModuleRecovery/inject.js +30 -18
  6. package/src/client/asyncModuleRecovery/runtime.js +20 -24
  7. package/src/client/bootstrap/bootstrapPayloadHandlerRegistry.js +13 -6
  8. package/src/client/browser.js +56 -0
  9. package/src/client/clientUpdate/runtime.js +28 -18
  10. package/src/client/components/ShellErrorHost.vue +19 -219
  11. package/src/client/components/ShellLayout.vue +19 -227
  12. package/src/client/components/ShellOutlet.vue +16 -53
  13. package/src/client/components/ShellRouteTransition.vue +2 -291
  14. package/src/client/composables/shellLayoutDrawerPreference.js +15 -8
  15. package/src/client/composables/useShellDrawer.js +194 -0
  16. package/src/client/composables/useShellErrorHost.js +171 -0
  17. package/src/client/composables/useShellLayoutState.js +10 -20
  18. package/src/client/composables/useShellNavigationLink.js +6 -6
  19. package/src/client/composables/useShellPullToRefresh.js +15 -19
  20. package/src/client/composables/useShellRouteTransition.js +218 -0
  21. package/src/client/error/index.js +1 -1
  22. package/src/client/error/inject.js +36 -48
  23. package/src/client/error/normalize.js +2 -3
  24. package/src/client/error/policy.js +9 -0
  25. package/src/client/error/presentation.js +67 -0
  26. package/src/client/error/presentationDefaults.js +2 -2
  27. package/src/client/error/presenters.js +44 -19
  28. package/src/client/error/runtime.js +30 -28
  29. package/src/client/error/store.js +4 -0
  30. package/src/client/navigation/linkResolver.js +6 -2
  31. package/src/client/navigation/usePaths.js +11 -8
  32. package/src/client/navigation/useSurfaceRouteContext.js +3 -3
  33. package/src/client/placement/debug.js +2 -2
  34. package/src/client/placement/index.js +1 -0
  35. package/src/client/placement/inject.js +49 -46
  36. package/src/client/placement/pathname.js +3 -9
  37. package/src/client/placement/runtime.js +13 -39
  38. package/src/client/placement/surfaceContext.js +14 -33
  39. package/src/client/placement/validators.js +6 -1
  40. package/src/client/providers/ShellWebClientProvider.js +17 -38
  41. package/src/client/providers/appModuleLoadFailure.js +1 -1
  42. package/src/client/requestRecovery/index.js +1 -0
  43. package/src/client/requestRecovery/inject.js +29 -17
  44. package/src/client/requestRecovery/runtime.js +40 -87
  45. package/src/client/runtime/bootstrapRuntime.js +20 -35
  46. package/src/client/runtime/refreshRuntime.js +30 -22
  47. package/src/client/stores/useShellErrorPresentationStore.js +5 -19
  48. package/src/client/support/drawerWidth.js +39 -0
  49. package/src/client/support/gestureTargets.js +4 -2
  50. package/src/client/support/menuLinkTarget.js +1 -1
  51. package/src/client/support/navigationLinkKeyboard.js +1 -1
  52. package/src/client/support/primaryNavigation.js +93 -0
  53. package/src/client/support/routeSwipeGesture.js +13 -3
  54. package/src/client/support/shellLayoutClass.js +4 -6
  55. package/src/client/types.js +38 -0
  56. package/test/asyncModuleRecoveryInject.test.js +13 -18
  57. package/test/bootstrapRuntime.test.js +3 -1
  58. package/test/browser.test.js +51 -0
  59. package/test/clientUpdate.test.js +12 -1
  60. package/test/drawerWidth.test.js +64 -0
  61. package/test/errorActions.test.js +10 -3
  62. package/test/errorPresentation.test.js +51 -0
  63. package/test/errorRuntime.test.js +21 -10
  64. package/test/placementInject.test.js +60 -0
  65. package/test/placementRuntime.test.js +12 -9
  66. package/test/primaryNavigation.test.js +75 -0
  67. package/test/provider.test.js +18 -4
  68. package/test/requestRecovery.test.js +13 -18
  69. package/test/settingsPlacementContract.test.js +15 -11
  70. package/test/support/mountComposable.js +90 -0
  71. package/test/translation.test.js +4 -2
  72. package/test/useShellDrawer.test.js +213 -0
  73. package/test/useShellErrorHost.test.js +149 -0
  74. package/test/useShellRouteTransition.test.js +129 -0
@@ -0,0 +1,218 @@
1
+ import {
2
+ computed,
3
+ onBeforeUnmount,
4
+ onMounted,
5
+ ref,
6
+ watch
7
+ } from "vue";
8
+ import { useRoute, useRouter } from "vue-router";
9
+ import { useDisplay } from "vuetify";
10
+ import {
11
+ useWebPlacementContext,
12
+ useWebPlacementRevision,
13
+ useWebPlacementRuntime
14
+ } from "../placement/inject.js";
15
+ import { resolveRuntimePathname } from "../placement/pathname.js";
16
+ import {
17
+ readPlacementSurfaceConfig,
18
+ resolveSurfaceIdFromPlacementPathname
19
+ } from "../placement/surfaceContext.js";
20
+ import {
21
+ normalizeComparablePathname,
22
+ resolveActivePrimaryNavigationIndex,
23
+ resolvePrimaryNavigationEntries
24
+ } from "../support/primaryNavigation.js";
25
+ import { resolveShellRouteTransitionKey } from "../support/routeTransitionKey.js";
26
+ import { createRouteSwipeGesture } from "../support/routeSwipeGesture.js";
27
+ import { isPrimaryTouchPointer, isShellGestureIgnoredTarget } from "../support/gestureTargets.js";
28
+ import { resolveShellLayoutClass } from "../support/shellLayoutClass.js";
29
+
30
+ /**
31
+ * Compact-layout route motion and swipes between primary navigation destinations.
32
+ * @param {object} props
33
+ * @param {boolean} props.enabled
34
+ * @param {string} props.target The outlet whose placements are the destinations.
35
+ * @param {string} props.semanticTarget
36
+ * @param {boolean} props.swipeEnabled
37
+ */
38
+ function useShellRouteTransition(props) {
39
+ const route = useRoute();
40
+ const router = useRouter();
41
+ const display = useDisplay();
42
+ const placementRuntime = useWebPlacementRuntime();
43
+ const { context: placementContext } = useWebPlacementContext();
44
+ const revision = useWebPlacementRevision(placementRuntime);
45
+ const transitionDirection = ref("none");
46
+ const swipeGesture = createRouteSwipeGesture();
47
+ let stopSwipeClassWatch = null;
48
+
49
+ onMounted(() => {
50
+ window.addEventListener("pointerdown", handlePointerDown, { capture: true, passive: true });
51
+ window.addEventListener("pointermove", handlePointerMove, { capture: true, passive: false });
52
+ window.addEventListener("pointerup", handlePointerEnd, { capture: true, passive: true });
53
+ window.addEventListener("pointercancel", handlePointerCancel, { capture: true, passive: true });
54
+
55
+ stopSwipeClassWatch = watch(
56
+ swipeNavigationEnabled,
57
+ (enabled) => {
58
+ document.documentElement.classList.toggle("shell-route-swipe-enabled", enabled);
59
+ },
60
+ { immediate: true }
61
+ );
62
+ });
63
+
64
+ onBeforeUnmount(() => {
65
+ if (stopSwipeClassWatch) {
66
+ stopSwipeClassWatch();
67
+ stopSwipeClassWatch = null;
68
+ }
69
+ document.documentElement.classList.remove("shell-route-swipe-enabled");
70
+ window.removeEventListener("pointerdown", handlePointerDown, { capture: true });
71
+ window.removeEventListener("pointermove", handlePointerMove, { capture: true });
72
+ window.removeEventListener("pointerup", handlePointerEnd, { capture: true });
73
+ window.removeEventListener("pointercancel", handlePointerCancel, { capture: true });
74
+ });
75
+
76
+ const resolvedLayoutClass = computed(() => resolveShellLayoutClass(display.name.value));
77
+
78
+ const currentPathname = computed(() => normalizeComparablePathname(resolveRuntimePathname(route.path)));
79
+
80
+ const currentSurfaceId = computed(() => {
81
+ const contextValue = placementContext.value;
82
+ const surfaceFromPathname = resolveSurfaceIdFromPlacementPathname(contextValue, currentPathname.value);
83
+ if (surfaceFromPathname) {
84
+ return surfaceFromPathname;
85
+ }
86
+
87
+ const surfaceConfig = readPlacementSurfaceConfig(contextValue);
88
+ return surfaceConfig.defaultSurfaceId || "*";
89
+ });
90
+
91
+ const primaryNavEntries = computed(() => {
92
+ void revision.value;
93
+
94
+ const placements = placementRuntime.getPlacements({
95
+ surface: currentSurfaceId.value,
96
+ target: props.target,
97
+ layoutClass: "compact"
98
+ });
99
+ return resolvePrimaryNavigationEntries(placements, {
100
+ semanticTarget: props.semanticTarget,
101
+ currentSurfaceId: currentSurfaceId.value,
102
+ placementContext: placementContext.value,
103
+ routeParams: route.params
104
+ });
105
+ });
106
+
107
+ const activePrimaryNavIndex = computed(() =>
108
+ resolveActivePrimaryNavigationIndex(currentPathname.value, primaryNavEntries.value)
109
+ );
110
+
111
+ watch(
112
+ activePrimaryNavIndex,
113
+ (nextIndex, previousIndex) => {
114
+ if (
115
+ !Number.isInteger(previousIndex) ||
116
+ previousIndex < 0 ||
117
+ nextIndex < 0 ||
118
+ nextIndex === previousIndex
119
+ ) {
120
+ transitionDirection.value = "none";
121
+ return;
122
+ }
123
+
124
+ transitionDirection.value = nextIndex > previousIndex ? "forward" : "reverse";
125
+ },
126
+ { flush: "sync" }
127
+ );
128
+
129
+ const routeTransitionName = computed(() => {
130
+ if (!props.enabled || resolvedLayoutClass.value !== "compact") {
131
+ return "";
132
+ }
133
+ if (transitionDirection.value === "forward") {
134
+ return "shell-route-slide-forward";
135
+ }
136
+ if (transitionDirection.value === "reverse") {
137
+ return "shell-route-slide-reverse";
138
+ }
139
+ return "";
140
+ });
141
+
142
+ // Animation can change with viewport geometry; pane identity changes only with
143
+ // navigation. Resizing must not recreate the routed form or lose focus.
144
+ const routeTransitionKey = ref("");
145
+ watch(
146
+ [() => normalizeComparablePathname(route.path), currentSurfaceId],
147
+ ([routePathKey, surfaceId]) => {
148
+ routeTransitionKey.value = resolveShellRouteTransitionKey({
149
+ routePathKey,
150
+ routeTransitionName: routeTransitionName.value,
151
+ surfaceId
152
+ });
153
+ },
154
+ { immediate: true, flush: "sync" }
155
+ );
156
+
157
+ const swipeNavigationEnabled = computed(() =>
158
+ Boolean(
159
+ props.enabled &&
160
+ props.swipeEnabled &&
161
+ resolvedLayoutClass.value === "compact" &&
162
+ primaryNavEntries.value.length > 1 &&
163
+ activePrimaryNavIndex.value >= 0
164
+ )
165
+ );
166
+
167
+ function handlePointerDown(event) {
168
+ if (!swipeNavigationEnabled.value || !isPrimaryTouchPointer(event) || isShellGestureIgnoredTarget(event.target)) {
169
+ swipeGesture.reset();
170
+ return;
171
+ }
172
+
173
+ swipeGesture.start(event);
174
+ try {
175
+ event.target.setPointerCapture(event.pointerId);
176
+ } catch {
177
+ // Synthetic test events and some embedded webviews may not expose an active pointer.
178
+ }
179
+ }
180
+
181
+ function handlePointerMove(event) {
182
+ const { claim, offset } = swipeGesture.move(event);
183
+ if (claim) {
184
+ event.preventDefault();
185
+ }
186
+ if (offset) {
187
+ navigateBySwipe(offset);
188
+ }
189
+ }
190
+
191
+ function handlePointerEnd(event) {
192
+ const offset = swipeGesture.end(event);
193
+ if (offset && swipeNavigationEnabled.value) {
194
+ navigateBySwipe(offset);
195
+ }
196
+ }
197
+
198
+ function handlePointerCancel(event) {
199
+ swipeGesture.cancel(event);
200
+ }
201
+
202
+ function navigateBySwipe(offset = 0) {
203
+ const currentIndex = activePrimaryNavIndex.value;
204
+ const nextEntry = primaryNavEntries.value[currentIndex + offset];
205
+ if (!nextEntry?.href || normalizeComparablePathname(nextEntry.href) === currentPathname.value) {
206
+ return;
207
+ }
208
+
209
+ void router.push(nextEntry.href).catch(() => {});
210
+ }
211
+
212
+ return {
213
+ routeTransitionKey,
214
+ routeTransitionName
215
+ };
216
+ }
217
+
218
+ export { useShellRouteTransition };
@@ -1,3 +1,3 @@
1
1
  export { createDefaultErrorPolicy } from "./policy.js";
2
- export { SHELL_WEB_ERROR_RUNTIME_KEY, useShellWebErrorRuntime } from "./inject.js";
2
+ export { NO_SHELL_WEB_ERROR_RUNTIME, SHELL_WEB_ERROR_RUNTIME_KEY, useShellWebErrorRuntime } from "./inject.js";
3
3
  export { useShellErrorPresentationStore } from "../stores/useShellErrorPresentationStore.js";
@@ -1,10 +1,26 @@
1
- import {
2
- inject
3
- } from "vue";
1
+ import { inject } from "vue";
2
+ import { normalizeErrorEvent } from "./runtime.js";
4
3
 
5
4
  const SHELL_WEB_ERROR_RUNTIME_KEY = "jskit.shell-web.runtime.web-error.client";
6
5
 
7
- const EMPTY_ERROR_RUNTIME = Object.freeze({
6
+ function throwUnavailable() {
7
+ throw new Error("Shell web error runtime is not available.");
8
+ }
9
+
10
+ function emptySnapshot() {
11
+ return Object.freeze({
12
+ presenterIds: Object.freeze([]),
13
+ appDefaultPresenterId: "",
14
+ moduleDefaultPresenterId: "",
15
+ resolvedDefaultPresenterId: ""
16
+ });
17
+ }
18
+
19
+ /**
20
+ * The error runtime of an application without shell-web's provider: a report is skipped and nothing can be set up.
21
+ * @type {any}
22
+ */
23
+ const NO_SHELL_WEB_ERROR_RUNTIME = Object.freeze({
8
24
  report() {
9
25
  return Object.freeze({
10
26
  skipped: true,
@@ -14,57 +30,29 @@ const EMPTY_ERROR_RUNTIME = Object.freeze({
14
30
  dismiss() {
15
31
  return 0;
16
32
  },
17
- configure() {
18
- return Object.freeze({
19
- presenterIds: Object.freeze([]),
20
- appDefaultPresenterId: "",
21
- moduleDefaultPresenterId: "",
22
- resolvedDefaultPresenterId: ""
23
- });
24
- },
25
- registerPresenter() {
26
- throw new Error("Shell web error runtime is not available.");
27
- },
28
- registerPresenters() {
29
- throw new Error("Shell web error runtime is not available.");
30
- },
31
- setPolicy() {
32
- throw new Error("Shell web error runtime is not available.");
33
- },
34
- setAppDefaultPresenterId() {
35
- throw new Error("Shell web error runtime is not available.");
36
- },
37
- assertBootReady() {
38
- throw new Error("Shell web error runtime is not available.");
39
- },
40
- getSnapshot() {
41
- return Object.freeze({
42
- presenterIds: Object.freeze([]),
43
- appDefaultPresenterId: "",
44
- moduleDefaultPresenterId: "",
45
- resolvedDefaultPresenterId: ""
46
- });
47
- },
33
+ configure: emptySnapshot,
34
+ registerPresenter: throwUnavailable,
35
+ registerPresenters: throwUnavailable,
36
+ setPolicy: throwUnavailable,
37
+ setAppDefaultPresenterId: throwUnavailable,
38
+ assertBootReady: throwUnavailable,
39
+ getSnapshot: emptySnapshot,
48
40
  subscribe() {
49
41
  return () => {};
50
- }
42
+ },
43
+ normalizeErrorEvent
51
44
  });
52
45
 
53
- function useShellWebErrorRuntime({ required = false } = {}) {
54
- const runtime = inject(SHELL_WEB_ERROR_RUNTIME_KEY, null);
55
- if (runtime && typeof runtime.report === "function") {
56
- return runtime;
57
- }
58
-
59
- if (required) {
60
- throw new Error("Shell web error runtime is not available in Vue injection context.");
61
- }
62
-
63
- return EMPTY_ERROR_RUNTIME;
46
+ /**
47
+ * The shell's error runtime, or `NO_SHELL_WEB_ERROR_RUNTIME` in an application without shell-web's provider.
48
+ * @returns {import("../types.js").ShellErrorRuntime}
49
+ */
50
+ function useShellWebErrorRuntime() {
51
+ return inject(SHELL_WEB_ERROR_RUNTIME_KEY, NO_SHELL_WEB_ERROR_RUNTIME);
64
52
  }
65
53
 
66
54
  export {
55
+ NO_SHELL_WEB_ERROR_RUNTIME,
67
56
  SHELL_WEB_ERROR_RUNTIME_KEY,
68
- EMPTY_ERROR_RUNTIME,
69
57
  useShellWebErrorRuntime
70
58
  };
@@ -67,14 +67,13 @@ function normalizeAction(value) {
67
67
  }
68
68
 
69
69
  const label = normalizeText(source.label);
70
- const handler = typeof source.handler === "function" ? source.handler : null;
71
- if (!label || !handler) {
70
+ if (!label || !source.handler) {
72
71
  return null;
73
72
  }
74
73
 
75
74
  return Object.freeze({
76
75
  label,
77
- handler,
76
+ handler: source.handler,
78
77
  dismissOnRun: source.dismissOnRun !== false
79
78
  });
80
79
  }
@@ -4,6 +4,15 @@ import {
4
4
  normalizeSeverity
5
5
  } from "./normalize.js";
6
6
 
7
+ /**
8
+ * @param {object} [options]
9
+ * @param {string} [options.defaultChannel]
10
+ * @param {string} [options.resourceLoadChannel]
11
+ * @param {string} [options.actionFeedbackChannel]
12
+ * @param {string} [options.appRecoverableChannel]
13
+ * @param {string} [options.blockingChannel]
14
+ * @param {string} [options.defaultSeverity]
15
+ */
7
16
  function createDefaultErrorPolicy({
8
17
  defaultChannel = "snackbar",
9
18
  resourceLoadChannel = "silent",
@@ -0,0 +1,67 @@
1
+ import { mdiAlertOutline, mdiCheckCircleOutline, mdiInformationOutline } from "@mdi/js";
2
+
3
+ function resolveSeverityColor(severity = "error") {
4
+ const normalized = String(severity || "error").trim().toLowerCase();
5
+ if (normalized === "info") {
6
+ return "info";
7
+ }
8
+ if (normalized === "success") {
9
+ return "success";
10
+ }
11
+ if (normalized === "warning") {
12
+ return "warning";
13
+ }
14
+ return "error";
15
+ }
16
+
17
+ function resolveSeverityIcon(severity = "error") {
18
+ const normalized = String(severity || "error").trim().toLowerCase();
19
+ if (normalized === "info") {
20
+ return mdiInformationOutline;
21
+ }
22
+ if (normalized === "success") {
23
+ return mdiCheckCircleOutline;
24
+ }
25
+ return mdiAlertOutline;
26
+ }
27
+
28
+ function resolveTimeout(entry) {
29
+ if (!entry) {
30
+ return -1;
31
+ }
32
+ if (entry.persist) {
33
+ return -1;
34
+ }
35
+ return 5000;
36
+ }
37
+
38
+ function actionsFor(entry) {
39
+ return entry ? [entry.action, ...entry.additionalActions].filter(Boolean) : [];
40
+ }
41
+
42
+ // Banners float just below a top app bar. A surface without one (sign-in pages)
43
+ // has nothing to float under, so the banners join the page flow above the
44
+ // content instead of covering it.
45
+ function resolveBannerPlacement(rect) {
46
+ const top = Number(rect.top) || 0;
47
+ if (top <= 0) {
48
+ return { inline: true, style: undefined };
49
+ }
50
+
51
+ return {
52
+ inline: false,
53
+ style: {
54
+ top: `calc(env(safe-area-inset-top, 0px) + ${top}px)`,
55
+ left: `${Number(rect.left) || 0}px`,
56
+ right: `${Number(rect.right) || 0}px`
57
+ }
58
+ };
59
+ }
60
+
61
+ export {
62
+ actionsFor,
63
+ resolveBannerPlacement,
64
+ resolveSeverityColor,
65
+ resolveSeverityIcon,
66
+ resolveTimeout
67
+ };
@@ -7,7 +7,7 @@ const EMPTY_PRESENTATION_STATE = Object.freeze({
7
7
  })
8
8
  });
9
9
 
10
- const EMPTY_PRESENTATION_STORE = Object.freeze({
10
+ const NO_PRESENTATION_STORE = Object.freeze({
11
11
  getState() {
12
12
  return EMPTY_PRESENTATION_STATE;
13
13
  },
@@ -27,5 +27,5 @@ const EMPTY_PRESENTATION_STORE = Object.freeze({
27
27
 
28
28
  export {
29
29
  EMPTY_PRESENTATION_STATE,
30
- EMPTY_PRESENTATION_STORE
30
+ NO_PRESENTATION_STORE
31
31
  };
@@ -1,10 +1,16 @@
1
1
  import { normalizeText } from "./normalize.js";
2
2
 
3
+ /**
4
+ * @param {object} options
5
+ * @param {string} options.id
6
+ * @param {string} options.channel
7
+ * @param {import("../types.js").ShellErrorPresentationStore} options.store
8
+ */
3
9
  function createStoreBackedPresenter({
4
10
  id,
5
11
  channel,
6
12
  store
7
- } = {}) {
13
+ }) {
8
14
  const normalizedId = normalizeText(id);
9
15
  const normalizedChannel = normalizeText(channel).toLowerCase();
10
16
  if (!normalizedId) {
@@ -13,28 +19,35 @@ function createStoreBackedPresenter({
13
19
  if (!normalizedChannel) {
14
20
  throw new Error(`createStoreBackedPresenter("${normalizedId}") requires channel.`);
15
21
  }
16
- if (!store || typeof store.present !== "function" || typeof store.dismiss !== "function") {
17
- throw new Error(`createStoreBackedPresenter("${normalizedId}") requires a presentation store.`);
22
+
23
+ function supports(requestedChannel = "") {
24
+ return String(requestedChannel || "").trim().toLowerCase() === normalizedChannel;
25
+ }
26
+
27
+ function present(payload = {}) {
28
+ return store.present(normalizedChannel, {
29
+ ...payload,
30
+ presenterId: normalizedId
31
+ });
32
+ }
33
+
34
+ function dismiss(presentationId = "") {
35
+ return store.dismiss(normalizedChannel, String(presentationId || ""));
18
36
  }
19
37
 
20
38
  return Object.freeze({
21
39
  id: normalizedId,
22
- supports(requestedChannel = "") {
23
- return String(requestedChannel || "").trim().toLowerCase() === normalizedChannel;
24
- },
25
- present(payload = {}) {
26
- return store.present(normalizedChannel, {
27
- ...payload,
28
- presenterId: normalizedId
29
- });
30
- },
31
- dismiss(presentationId = "") {
32
- return store.dismiss(normalizedChannel, String(presentationId || ""));
33
- }
40
+ supports,
41
+ present,
42
+ dismiss
34
43
  });
35
44
  }
36
45
 
37
- function createMaterialSnackbarPresenter({ store } = {}) {
46
+ /**
47
+ * @param {object} options
48
+ * @param {import("../types.js").ShellErrorPresentationStore} options.store
49
+ */
50
+ function createMaterialSnackbarPresenter({ store }) {
38
51
  return createStoreBackedPresenter({
39
52
  id: "material.snackbar",
40
53
  channel: "snackbar",
@@ -42,7 +55,11 @@ function createMaterialSnackbarPresenter({ store } = {}) {
42
55
  });
43
56
  }
44
57
 
45
- function createMaterialBannerPresenter({ store } = {}) {
58
+ /**
59
+ * @param {object} options
60
+ * @param {import("../types.js").ShellErrorPresentationStore} options.store
61
+ */
62
+ function createMaterialBannerPresenter({ store }) {
46
63
  return createStoreBackedPresenter({
47
64
  id: "material.banner",
48
65
  channel: "banner",
@@ -50,7 +67,11 @@ function createMaterialBannerPresenter({ store } = {}) {
50
67
  });
51
68
  }
52
69
 
53
- function createMaterialDialogPresenter({ store } = {}) {
70
+ /**
71
+ * @param {object} options
72
+ * @param {import("../types.js").ShellErrorPresentationStore} options.store
73
+ */
74
+ function createMaterialDialogPresenter({ store }) {
54
75
  return createStoreBackedPresenter({
55
76
  id: "material.dialog",
56
77
  channel: "dialog",
@@ -58,7 +79,11 @@ function createMaterialDialogPresenter({ store } = {}) {
58
79
  });
59
80
  }
60
81
 
61
- function createDefaultMaterialErrorPresenters({ store } = {}) {
82
+ /**
83
+ * @param {object} options
84
+ * @param {import("../types.js").ShellErrorPresentationStore} options.store
85
+ */
86
+ function createDefaultMaterialErrorPresenters({ store }) {
62
87
  return Object.freeze([
63
88
  createMaterialSnackbarPresenter({ store }),
64
89
  createMaterialBannerPresenter({ store }),
@@ -14,14 +14,6 @@ import { useJskitText } from "../i18n.js";
14
14
 
15
15
  const { t } = useJskitText();
16
16
 
17
- function createRuntimeLogger(logger = null) {
18
- const source = isRecord(logger) ? logger : null;
19
- return Object.freeze({
20
- warn: typeof source?.warn === "function" ? source.warn.bind(source) : () => {},
21
- error: typeof source?.error === "function" ? source.error.bind(source) : () => {}
22
- });
23
- }
24
-
25
17
  function freezeParams(params) {
26
18
  return Object.freeze(isRecord(params) ? { ...params } : {});
27
19
  }
@@ -107,38 +99,51 @@ function normalizePolicyDecision(policyDecision = {}, event = {}) {
107
99
  });
108
100
  }
109
101
 
110
- function normalizePresenter(candidate = {}) {
111
- const source = isRecord(candidate) ? candidate : {};
102
+ // A presenter that is limited to some channels, or can take back what it showed, supplies these.
103
+ function supportsEveryChannel() {
104
+ return true;
105
+ }
106
+
107
+ function dismissNothing() {
108
+ return 0;
109
+ }
110
+
111
+ function normalizePresenter(source) {
112
112
  const id = normalizeText(source.id);
113
113
  if (!id) {
114
114
  throw new Error("Error presenter requires id.");
115
115
  }
116
116
 
117
- if (typeof source.present !== "function") {
118
- throw new Error(`Error presenter "${id}" requires present(payload).`);
119
- }
120
-
117
+ const supports = source.supports || supportsEveryChannel;
118
+ const dismiss = source.dismiss || dismissNothing;
121
119
  return Object.freeze({
122
120
  id,
123
- supports: typeof source.supports === "function" ? source.supports.bind(source) : () => true,
121
+ supports: supports.bind(source),
124
122
  present: source.present.bind(source),
125
- dismiss: typeof source.dismiss === "function" ? source.dismiss.bind(source) : null
123
+ dismiss: dismiss.bind(source)
126
124
  });
127
125
  }
128
126
 
127
+ /**
128
+ * @param {object} options
129
+ * @param {object[]} [options.presenters]
130
+ * @param {Function} [options.policy]
131
+ * @param {string} [options.defaultPresenterId]
132
+ * @param {string} [options.moduleDefaultPresenterId]
133
+ * @param {import("@jskit-ai/kernel/client/types").ClientLogger} options.logger
134
+ */
129
135
  function createErrorRuntime({
130
136
  presenters = [],
131
- policy = null,
137
+ policy = createDefaultErrorPolicy(),
132
138
  defaultPresenterId = "",
133
139
  moduleDefaultPresenterId = "",
134
- logger = null
135
- } = {}) {
136
- const runtimeLogger = createRuntimeLogger(logger);
140
+ logger
141
+ }) {
137
142
  const byPresenterId = new Map();
138
143
  const listeners = new Set();
139
144
  const subscribe = createListenerSubscription(listeners);
140
145
  const dedupeWindowByKey = new Map();
141
- let activePolicy = typeof policy === "function" ? policy : createDefaultErrorPolicy();
146
+ let activePolicy = policy;
142
147
  let activeAppDefaultPresenterId = normalizeText(defaultPresenterId);
143
148
  const activeModuleDefaultPresenterId = normalizeText(moduleDefaultPresenterId);
144
149
 
@@ -212,7 +217,7 @@ function createErrorRuntime({
212
217
  try {
213
218
  listener(payload);
214
219
  } catch (error) {
215
- runtimeLogger.warn(
220
+ logger.warn(
216
221
  {
217
222
  error: String(error?.message || error || "unknown error")
218
223
  },
@@ -241,7 +246,7 @@ function createErrorRuntime({
241
246
 
242
247
  const defaultPresenterId = resolveDefaultPresenterId();
243
248
  const defaultPresenter = byPresenterId.get(defaultPresenterId);
244
- if (defaultPresenter?.supports(decision.channel)) {
249
+ if (defaultPresenter.supports(decision.channel)) {
245
250
  return defaultPresenter;
246
251
  }
247
252
 
@@ -286,7 +291,7 @@ function createErrorRuntime({
286
291
  })
287
292
  );
288
293
  } catch (error) {
289
- runtimeLogger.error(
294
+ logger.error(
290
295
  {
291
296
  source: event.source,
292
297
  error: String(error?.message || error || "unknown error")
@@ -367,7 +372,7 @@ function createErrorRuntime({
367
372
 
368
373
  if (presenterId) {
369
374
  const presenter = byPresenterId.get(presenterId);
370
- if (!presenter || typeof presenter.dismiss !== "function") {
375
+ if (!presenter) {
371
376
  return 0;
372
377
  }
373
378
  return Number(presenter.dismiss(normalizedPresentationId) || 0);
@@ -375,9 +380,6 @@ function createErrorRuntime({
375
380
 
376
381
  let total = 0;
377
382
  for (const presenter of byPresenterId.values()) {
378
- if (typeof presenter.dismiss !== "function") {
379
- continue;
380
- }
381
383
  total += Number(presenter.dismiss(normalizedPresentationId) || 0);
382
384
  }
383
385
  return total;
@@ -43,6 +43,10 @@ function cloneEntry(entry = {}) {
43
43
  });
44
44
  }
45
45
 
46
+ /**
47
+ * @param {object} [options]
48
+ * @param {() => number} [options.now]
49
+ */
46
50
  function createErrorPresentationStore({
47
51
  now = () => Date.now()
48
52
  } = {}) {