@jskit-ai/shell-web 0.1.251 → 0.1.253

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 (49) hide show
  1. package/README.md +5 -79
  2. package/fixtures/adaptive-shell/src/main.js +6 -3
  3. package/package.json +6 -7
  4. package/patterns/application-shell/example/src/pages/home/index.vue +15 -5
  5. package/patterns/application-shell/example/tests/e2e/adaptive-shell.spec.ts +1 -1
  6. package/src/architecture/cli.js +1 -33
  7. package/src/architecture/inspectVueArchitecture.js +1 -400
  8. package/src/client/asyncModuleRecovery/runtime.js +116 -0
  9. package/src/client/components/ShellLayout.vue +18 -288
  10. package/src/client/components/ShellMenuLinkItem.vue +3 -21
  11. package/src/client/components/ShellOutlet.vue +2 -24
  12. package/src/client/components/ShellRouteTransition.vue +16 -114
  13. package/src/client/components/ShellSurfaceAwareMenuLinkItem.vue +5 -100
  14. package/src/client/components/ShellTabLinkItem.vue +5 -101
  15. package/src/client/composables/useShellNavigationLink.js +85 -0
  16. package/src/client/composables/useShellPullToRefresh.js +260 -0
  17. package/src/client/error/index.js +1 -1
  18. package/src/client/error/inject.js +4 -1
  19. package/src/client/error/policy.js +4 -13
  20. package/src/client/error/presenters.js +4 -9
  21. package/src/client/error/store.js +1 -1
  22. package/src/client/navigation/linkResolver.js +5 -27
  23. package/src/client/navigation/usePaths.js +1 -21
  24. package/src/client/placement/index.js +2 -0
  25. package/src/client/placement/inject.js +4 -1
  26. package/src/client/placement/runtime.js +2 -4
  27. package/src/client/placement/surfaceContext.js +11 -8
  28. package/src/client/placement/validators.js +18 -65
  29. package/src/client/providers/ShellWebClientProvider.js +100 -356
  30. package/src/client/requestRecovery/runtime.js +29 -77
  31. package/src/client/runtime/bootstrapRuntime.js +5 -4
  32. package/src/client/runtime/refreshRuntime.js +122 -0
  33. package/src/client/support/gestureTargets.js +26 -0
  34. package/src/client/support/menuLinkTarget.js +35 -19
  35. package/src/client/support/routeParams.js +26 -0
  36. package/src/client/support/routeSwipeGesture.js +88 -0
  37. package/src/client/support/routeTransitionKey.js +1 -3
  38. package/src/client/support/shellLayoutClass.js +32 -0
  39. package/test/bootstrapRuntime.test.js +98 -0
  40. package/test/errorActions.test.js +2 -1
  41. package/test/errorRuntime.test.js +30 -0
  42. package/test/linkResolver.test.js +23 -1
  43. package/test/menuLinkTarget.test.js +77 -0
  44. package/test/routeSwipeGesture.test.js +49 -0
  45. package/test/settingsPlacementContract.test.js +16 -6
  46. package/test/shellGestureSupport.test.js +46 -0
  47. package/test/surfaceContext.test.js +53 -0
  48. package/test/useShellPullToRefresh.test.js +123 -0
  49. package/test/architecture.test.js +0 -154
@@ -6,26 +6,19 @@ import {
6
6
  resolveSurfaceDefinitionFromPlacementContext,
7
7
  resolveSurfaceRootPathFromPlacementContext
8
8
  } from "../placement/surfaceContext.js";
9
-
10
- function normalizeParamsMap(params = null) {
11
- if (!params || typeof params !== "object" || Array.isArray(params)) {
12
- return {};
13
- }
14
- return params;
15
- }
9
+ import { normalizeRouteParams } from "../support/routeParams.js";
16
10
 
17
11
  function materializeSurfaceRouteBase(routeBaseTemplate = "/", { params = {}, strictParams = true, surface = "" } = {}) {
18
- const normalizedParams = normalizeParamsMap(params);
12
+ const normalizedParams = normalizeRouteParams(params);
19
13
  const missingParams = new Set();
20
14
  const outputPath = String(routeBaseTemplate || "/").replace(/:([A-Za-z0-9_]+)/g, (_full, rawName) => {
21
15
  const paramName = String(rawName || "").trim();
22
16
  const paramValue = normalizedParams[paramName];
23
- const normalizedValue = String(paramValue ?? "").trim();
24
- if (!normalizedValue) {
17
+ if (!paramValue) {
25
18
  missingParams.add(paramName);
26
19
  return `:${paramName}`;
27
20
  }
28
- return encodeURIComponent(normalizedValue);
21
+ return encodeURIComponent(paramValue);
29
22
  });
30
23
 
31
24
  if (strictParams && missingParams.size > 0) {
@@ -94,23 +87,8 @@ function useShellLinkResolver({ surface = "" } = {}) {
94
87
  });
95
88
  }
96
89
 
97
- function toSurface(relativePath = "/", options = {}) {
98
- return resolve(relativePath, options);
99
- }
100
-
101
- function toWorkspace(relativePath = "/", options = {}) {
102
- return resolve(relativePath, options);
103
- }
104
-
105
- function toAuto(relativePath = "/", options = {}) {
106
- return resolve(relativePath, options);
107
- }
108
-
109
90
  return Object.freeze({
110
- resolve,
111
- toSurface,
112
- toWorkspace,
113
- toAuto
91
+ resolve
114
92
  });
115
93
  }
116
94
 
@@ -4,6 +4,7 @@ import { resolveScopedApiBasePath } from "@jskit-ai/kernel/shared/surface";
4
4
  import { resolveSurfaceDefinitionFromPlacementContext } from "../placement/index.js";
5
5
  import { useShellLinkResolver } from "./linkResolver.js";
6
6
  import { useSurfaceRouteContext } from "./useSurfaceRouteContext.js";
7
+ import { normalizeRouteParams } from "../support/routeParams.js";
7
8
 
8
9
  function normalizePathSuffix(value = "") {
9
10
  const raw = normalizeText(unref(value));
@@ -32,27 +33,6 @@ function resolveDefaultSurfaceIdFromPlacementContext(placementContext = null) {
32
33
  return resolveSurfaceId(placementContext?.surfaceConfig?.defaultSurfaceId, "");
33
34
  }
34
35
 
35
- function normalizeRouteParams(params = null) {
36
- if (!params || typeof params !== "object" || Array.isArray(params)) {
37
- return {};
38
- }
39
-
40
- const output = {};
41
- for (const [rawKey, rawValue] of Object.entries(params)) {
42
- const key = normalizeText(rawKey);
43
- if (!key) {
44
- continue;
45
- }
46
-
47
- const value = Array.isArray(rawValue) ? rawValue[0] : rawValue;
48
- const normalizedValue = normalizeText(value);
49
- if (normalizedValue) {
50
- output[key] = normalizedValue;
51
- }
52
- }
53
- return output;
54
- }
55
-
56
36
  function resolveRouteParams(baseParams = {}, overrideParams = null) {
57
37
  return {
58
38
  ...normalizeRouteParams(baseParams),
@@ -8,6 +8,7 @@ export {
8
8
  } from "./validators.js";
9
9
 
10
10
  export {
11
+ SHELL_WEB_PLACEMENT_RUNTIME_KEY,
11
12
  useWebPlacementContext
12
13
  } from "./inject.js";
13
14
 
@@ -17,6 +18,7 @@ export {
17
18
 
18
19
  export {
19
20
  readPlacementSurfaceConfig,
21
+ resolveAllowedOriginsFromPlacementContext,
20
22
  resolveSurfaceDefinitionFromPlacementContext,
21
23
  joinSurfacePath,
22
24
  resolveSurfaceIdFromPlacementPathname,
@@ -5,6 +5,8 @@ import {
5
5
  shallowRef
6
6
  } from "vue";
7
7
 
8
+ const SHELL_WEB_PLACEMENT_RUNTIME_KEY = "jskit.shell-web.runtime.web-placement.client";
9
+
8
10
  const EMPTY_WEB_PLACEMENT_RUNTIME = Object.freeze({
9
11
  getContext() {
10
12
  return Object.freeze({});
@@ -36,7 +38,7 @@ const EMPTY_WEB_PLACEMENT_CONTEXT = Object.freeze({
36
38
  });
37
39
 
38
40
  function useWebPlacementRuntime({ required = false } = {}) {
39
- const runtime = inject("jskit.shell-web.runtime.web-placement.client", null);
41
+ const runtime = inject(SHELL_WEB_PLACEMENT_RUNTIME_KEY, null);
40
42
  if (runtime && typeof runtime.getPlacements === "function") {
41
43
  return runtime;
42
44
  }
@@ -96,6 +98,7 @@ function useWebPlacementContext({ required = false } = {}) {
96
98
  }
97
99
 
98
100
  export {
101
+ SHELL_WEB_PLACEMENT_RUNTIME_KEY,
99
102
  EMPTY_WEB_PLACEMENT_RUNTIME,
100
103
  EMPTY_WEB_PLACEMENT_CONTEXT,
101
104
  useWebPlacementRuntime,
@@ -2,6 +2,7 @@ import { DEFAULT_DEBUG_DEPTH, explodePayload } from "./debug.js";
2
2
  import { createListenerSubscription } from "@jskit-ai/kernel/shared/support/listenerSet";
3
3
  import { isRecord } from "@jskit-ai/kernel/shared/support/normalize";
4
4
  import {
5
+ WEB_PLACEMENT_SURFACE_ANY,
5
6
  normalizePlacementLayoutClass,
6
7
  normalizePlacementTopologyDefinition
7
8
  } from "@jskit-ai/kernel/shared/support/shellLayoutTargets";
@@ -24,7 +25,6 @@ function ensureArray(value) {
24
25
 
25
26
  const PLACEMENT_DEBUG_PREFIX = "[placement-debug]";
26
27
  const PLACEMENT_DEBUG_FLAG = "__JSKIT_PLACEMENT_DEBUG__";
27
- const WEB_PLACEMENT_SURFACE_ANY = "*";
28
28
  const NOOP = () => {};
29
29
 
30
30
  function isPlacementDebugEnabled() {
@@ -480,9 +480,7 @@ function createWebPlacementRuntime({ components, contextContributors = [], logge
480
480
  if (!renderablePlacement) {
481
481
  continue;
482
482
  }
483
- const placementSurfaces = Array.isArray(renderablePlacement.surfaces)
484
- ? renderablePlacement.surfaces
485
- : [WEB_PLACEMENT_SURFACE_ANY];
483
+ const placementSurfaces = renderablePlacement.surfaces;
486
484
 
487
485
  if (!matchesSurface(placementSurfaces, normalizedSurface)) {
488
486
  debugLog("getPlacements:skip-surfaces", {
@@ -7,6 +7,7 @@ import {
7
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
+ import { resolveAllowedOriginsFromSurfaceDefinitions } from "@jskit-ai/kernel/shared/support/returnToPath";
10
11
 
11
12
  const EMPTY_SURFACE_CONFIG = Object.freeze({
12
13
  tenancyMode: "",
@@ -119,6 +120,14 @@ function readPlacementSurfaceConfig(contextValue = null) {
119
120
  return normalizeSurfaceConfig(contextRecord.surfaceConfig);
120
121
  }
121
122
 
123
+ // Origins a return-to URL may point at: this page plus every surface origin.
124
+ function resolveAllowedOriginsFromPlacementContext(contextValue = null) {
125
+ const seedOrigins = typeof window === "object" && window?.location?.origin ? [window.location.origin] : [];
126
+ return resolveAllowedOriginsFromSurfaceDefinitions(readPlacementSurfaceConfig(contextValue).surfacesById, {
127
+ seedOrigins
128
+ });
129
+ }
130
+
122
131
  function resolveSurfaceDefinitionFromPlacementContext(contextValue = null, surfaceId = "") {
123
132
  const surfaceConfig = readPlacementSurfaceConfig(contextValue);
124
133
  const normalizedSurfaceId = normalizeSurfaceId(surfaceId);
@@ -253,14 +262,7 @@ function createPlacementSurfacePathHelpers(surfaceConfig = EMPTY_SURFACE_CONFIG)
253
262
 
254
263
  return createSurfacePathHelpers({
255
264
  defaultSurfaceId: resolvedDefaultSurfaceId,
256
- normalizeSurfaceId,
257
- resolveSurfaceRouteBase(surfaceId) {
258
- const normalizedSurfaceId = normalizeSurfaceId(surfaceId);
259
- return String(surfacesById[normalizedSurfaceId]?.routeBase || "/").trim() || "/";
260
- },
261
- listSurfaceDefinitions() {
262
- return Object.values(surfacesById);
263
- }
265
+ surfaceDefinitions: Object.values(surfacesById)
264
266
  });
265
267
  }
266
268
 
@@ -280,6 +282,7 @@ export {
280
282
  EMPTY_SURFACE_CONFIG,
281
283
  buildSurfaceConfigContext,
282
284
  readPlacementSurfaceConfig,
285
+ resolveAllowedOriginsFromPlacementContext,
283
286
  resolveSurfaceDefinitionFromPlacementContext,
284
287
  joinSurfacePath,
285
288
  resolveSurfaceIdFromPlacementPathname,
@@ -1,13 +1,13 @@
1
1
  import { isRecord, normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
2
2
  import {
3
+ WEB_PLACEMENT_SURFACE_ANY,
3
4
  normalizePlacementKind,
5
+ normalizePlacementSurfaceId,
6
+ normalizePlacementSurfaces as normalizeKernelPlacementSurfaces,
4
7
  normalizePlacementTopologyDefinition,
5
- normalizeSemanticPlacementId,
6
8
  resolvePlacementTargetReference
7
9
  } from "@jskit-ai/kernel/shared/support/shellLayoutTargets";
8
10
 
9
- const WEB_PLACEMENT_SURFACE_ANY = "*";
10
-
11
11
  function isRenderableComponent(value) {
12
12
  if (typeof value === "function") {
13
13
  return true;
@@ -16,41 +16,16 @@ function isRenderableComponent(value) {
16
16
  }
17
17
 
18
18
  function normalizeSurface(value) {
19
- const normalized = normalizeText(value).toLowerCase();
20
- if (!normalized) {
21
- return WEB_PLACEMENT_SURFACE_ANY;
22
- }
23
- if (normalized === WEB_PLACEMENT_SURFACE_ANY) {
24
- return WEB_PLACEMENT_SURFACE_ANY;
25
- }
26
- return normalized;
27
- }
28
-
29
- function isValidSurfaceIdToken(value = "") {
30
- return /^[a-z0-9]+(?:[._-][a-z0-9]+)*$/.test(value);
19
+ return normalizeText(value).toLowerCase() || WEB_PLACEMENT_SURFACE_ANY;
31
20
  }
32
21
 
33
22
  function normalizePlacementSurface(value, { strict = false, source = "placement" } = {}) {
34
- const normalized = normalizeText(value).toLowerCase();
35
- if (!normalized) {
36
- if (strict) {
37
- throw new TypeError(`${source} requires surface id or "*".`);
38
- }
39
- return "";
40
- }
41
-
42
- if (normalized === WEB_PLACEMENT_SURFACE_ANY) {
43
- return WEB_PLACEMENT_SURFACE_ANY;
44
- }
45
-
46
- if (isValidSurfaceIdToken(normalized)) {
47
- return normalized;
48
- }
49
-
50
- if (strict) {
51
- throw new TypeError(`${source} surface "${normalized}" is invalid.`);
23
+ const surface = normalizePlacementSurfaceId(value);
24
+ if (!surface && strict) {
25
+ const normalized = normalizeText(value).toLowerCase();
26
+ throw new TypeError(normalized ? `${source} surface "${normalized}" is invalid.` : `${source} requires surface id or "*".`);
52
27
  }
53
- return "";
28
+ return surface;
54
29
  }
55
30
 
56
31
  function toInteger(value, fallback = 1000) {
@@ -74,36 +49,16 @@ function normalizePlacementTarget(value, { strict = false, source = "placement"
74
49
  }
75
50
 
76
51
  function normalizePlacementSurfaces(value, { strict = false, source = "placement" } = {}) {
77
- const candidates = Array.isArray(value) ? value : value === undefined || value === null ? [] : [value];
78
- if (candidates.length < 1) {
79
- return Object.freeze([WEB_PLACEMENT_SURFACE_ANY]);
80
- }
81
-
82
- const normalized = [];
83
- const seen = new Set();
84
- for (const candidate of candidates) {
85
- const surface = normalizePlacementSurface(candidate, {
86
- strict,
87
- source
88
- });
89
- if (!surface || seen.has(surface)) {
90
- continue;
91
- }
92
- if (surface === WEB_PLACEMENT_SURFACE_ANY) {
93
- return Object.freeze([WEB_PLACEMENT_SURFACE_ANY]);
94
- }
95
- seen.add(surface);
96
- normalized.push(surface);
97
- }
98
-
99
- if (normalized.length < 1) {
100
- if (strict) {
101
- throw new TypeError(`${source} requires at least one valid surface id.`);
52
+ if (strict) {
53
+ // Strict callers fail on the first invalid surface the kernel would otherwise drop; "*" ends the list.
54
+ const candidates = Array.isArray(value) ? value : value === undefined || value === null ? [] : [value];
55
+ for (const candidate of candidates) {
56
+ if (normalizePlacementSurface(candidate, { strict, source }) === WEB_PLACEMENT_SURFACE_ANY) {
57
+ break;
58
+ }
102
59
  }
103
- return Object.freeze([WEB_PLACEMENT_SURFACE_ANY]);
104
60
  }
105
-
106
- return Object.freeze(normalized);
61
+ return normalizeKernelPlacementSurfaces(value);
107
62
  }
108
63
 
109
64
  function normalizePlacementDefinition(value, { strict = false, source = "placement" } = {}) {
@@ -186,7 +141,6 @@ function definePlacementTopology(value = {}) {
186
141
  }
187
142
 
188
143
  export {
189
- isRecord,
190
144
  isRenderableComponent,
191
145
  normalizeSurface,
192
146
  normalizePlacementSurface,
@@ -194,6 +148,5 @@ export {
194
148
  normalizePlacementSurfaces,
195
149
  normalizePlacementDefinition,
196
150
  definePlacement,
197
- definePlacementTopology,
198
- normalizeSemanticPlacementId
151
+ definePlacementTopology
199
152
  };