@jskit-ai/shell-web 0.2.22 → 0.2.24

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/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - Menu and tab links, and the navigation bar's swipe destinations, take the current surface's params from the URL when the route declares none, as on the not-found route that catches any path: on `/w/acme/no-such-page` a link to the workspace surface goes to `/w/acme/...`. They threw "Missing required surface route params" on every render instead, so a workspace surface's not-found page showed that error in an alert, drew its drawer without destinations and logged the error again each time the shell redrew. The route's own params still win, and a link to a surface whose params neither the route nor the URL holds still throws.
6
+ - `shell.bootstrap.refresh()` runs one bootstrap request at a time and keeps at most one more waiting: everyone who asks while one waits shares it, and it reads the route and the handlers' request only when it starts. Each call used to queue its own request, so a burst of N realtime events or auth state reads fetched and applied the whole bootstrap N times in a row; it now does so at most twice.
5
7
  - The navigation bar's destinations (`ShellTabLinkItem`) are plain `v-btn`s with an icon and a label, drawn by `@jskit-ai/material-web`'s `material.css` as every `v-bottom-navigation` is: their icon is 24dp in the 64x32 indicator (it was 19dp), and `.tab-link-item__indicator` is gone (the indicator is the icon's own box, `.tab-link-item .v-icon`).
6
8
  - On compact windows the top app bar moves only the top-right items it has no room for into its overflow menu: the items stay while they fit beside the whole page title, and those that don't follow the page actions into the menu, farthest from the corner first. The item nearest the corner (the account avatar) still stays unless the page's primary action takes its place, and medium and wider windows are unchanged. The bar used to decide by the window's size class alone, so a short title and three small icons went into the menu. It measures the title and its items as drawn, and again when the bar's content changes (a new title, an item's count, a page action), when the window is resized and when fonts load. Each top-right item now renders once and moves between the bar and the menu as the same component, and the menu keeps it mounted while it is closed: an item that does more than draw a button (a live count, a panel, a floating button it teleports above the navigation bar) existed only while the menu was open on a phone, and was created anew each time it moved. `ShellPageActionsTarget` keeps its `#menu` slot mounted while the menu is closed and takes `menu-items` (default true), false while the slot holds nothing to show. `ShellLayout` sizes the title's `h1` to its text, up to the room it has.
7
9
  - `ShellLayout`'s drawer fits its labels and identity by default (what `drawerWidth="content"` did), instead of Material 3's fixed 360dp, so an app no longer wraps `ShellLayout` to get a narrow drawer. It stays within 120-360dp and, as a modal drawer, leaves 56dp of the page beside it. `drawerWidth="material"` gives Material 3's full 360dp (narrowed on a small window, as before), a number still fixes the width and `"content"` still fits it. `runAdaptiveShellSmokeCase` reads the drawer's width again while it settles, and accepts a fitted drawer at its 120dp minimum or one its identity widens past the labels.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/shell-web",
3
- "version": "0.2.22",
3
+ "version": "0.2.24",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -60,6 +60,7 @@ function useShellNavigationLink(props) {
60
60
  to: props.to,
61
61
  surface: props.surface,
62
62
  currentSurfaceId,
63
+ currentPathname: route.path,
63
64
  placementContext: placementContext.value,
64
65
  scopedSuffix: props.scopedSuffix,
65
66
  unscopedSuffix: props.unscopedSuffix,
@@ -99,6 +99,7 @@ function useShellRouteTransition(props) {
99
99
  return resolvePrimaryNavigationEntries(placements, {
100
100
  semanticTarget: props.semanticTarget,
101
101
  currentSurfaceId: currentSurfaceId.value,
102
+ currentPathname: currentPathname.value,
102
103
  placementContext: placementContext.value,
103
104
  routeParams: route.params
104
105
  });
@@ -156,6 +156,40 @@ function resolveSurfacePathFromPlacementContext(contextValue = null, surfaceId =
156
156
  return joinSurfacePath(surfaceDefinition?.routeBase, pathname);
157
157
  }
158
158
 
159
+ function decodePathSegment(segment = "") {
160
+ try {
161
+ return decodeURIComponent(segment);
162
+ } catch {
163
+ return segment;
164
+ }
165
+ }
166
+
167
+ // The params a surface's route base names, read from a pathname on that surface, decoded as a route's params are:
168
+ // "/w/:workspaceSlug/admin" reads { workspaceSlug: "acme" } from "/w/acme/admin/jobs". Empty when the pathname is
169
+ // not on the surface.
170
+ function resolveSurfaceRouteParamsFromPlacementPathname(contextValue = null, surfaceId = "", pathname = "") {
171
+ const surfaceDefinition = resolveSurfaceDefinitionFromPlacementContext(contextValue, surfaceId);
172
+ if (!surfaceDefinition) {
173
+ return {};
174
+ }
175
+
176
+ const routeBaseSegments = normalizePathname(surfaceDefinition.routeBase).split("/").filter(Boolean);
177
+ const pathSegments = normalizePathname(pathname).split("/").filter(Boolean);
178
+ const params = {};
179
+ for (const [index, routeBaseSegment] of routeBaseSegments.entries()) {
180
+ const pathSegment = pathSegments[index];
181
+ if (!pathSegment) {
182
+ return {};
183
+ }
184
+ if (routeBaseSegment.startsWith(":") && routeBaseSegment.length > 1) {
185
+ params[routeBaseSegment.slice(1)] = decodePathSegment(pathSegment);
186
+ } else if (routeBaseSegment !== pathSegment) {
187
+ return {};
188
+ }
189
+ }
190
+ return params;
191
+ }
192
+
159
193
  function normalizeSurfaceOrigin(originValue = "") {
160
194
  const rawOrigin = String(originValue || "").trim();
161
195
  if (!rawOrigin) {
@@ -269,6 +303,7 @@ export {
269
303
  resolveSurfaceIdFromPlacementPathname,
270
304
  resolveSurfaceRootPathFromPlacementContext,
271
305
  resolveSurfacePathFromPlacementContext,
306
+ resolveSurfaceRouteParamsFromPlacementPathname,
272
307
  normalizeSurfaceOrigin,
273
308
  resolveSurfaceNavigationTargetFromPlacementContext
274
309
  };
@@ -48,7 +48,8 @@ function createShellBootstrapRuntime({
48
48
  bootstrapPath = BOOTSTRAP_PATH
49
49
  }) {
50
50
  let initialized = false;
51
- let refreshQueue = Promise.resolve();
51
+ let runningRefresh = null;
52
+ let pendingRefresh = null;
52
53
 
53
54
  async function resolveBootstrapRequest(reason = "manual") {
54
55
  const payloadHandlers = handlers.list();
@@ -165,9 +166,27 @@ function createShellBootstrapRuntime({
165
166
  }
166
167
  }
167
168
 
169
+ function startRefresh(reason) {
170
+ runningRefresh = performRefresh(reason).finally(() => {
171
+ runningRefresh = null;
172
+ });
173
+ return runningRefresh;
174
+ }
175
+
176
+ // One refresh runs and at most one waits: everyone asking while one waits
177
+ // shares it, since it resolves its request only when it starts.
168
178
  function refresh(reason = "manual") {
169
- refreshQueue = refreshQueue.catch(() => null).then(() => performRefresh(reason));
170
- return refreshQueue;
179
+ if (pendingRefresh) {
180
+ return pendingRefresh;
181
+ }
182
+ if (!runningRefresh) {
183
+ return startRefresh(reason);
184
+ }
185
+ pendingRefresh = runningRefresh.catch(() => null).then(() => {
186
+ pendingRefresh = null;
187
+ return startRefresh(reason);
188
+ });
189
+ return pendingRefresh;
171
190
  }
172
191
 
173
192
  async function initialize() {
@@ -2,7 +2,8 @@ import { normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
2
2
  import { resolveShellLinkPath } from "../navigation/linkResolver.js";
3
3
  import {
4
4
  resolveSurfaceDefinitionFromPlacementContext,
5
- resolveSurfaceNavigationTargetFromPlacementContext
5
+ resolveSurfaceNavigationTargetFromPlacementContext,
6
+ resolveSurfaceRouteParamsFromPlacementPathname
6
7
  } from "../placement/surfaceContext.js";
7
8
 
8
9
  function normalizeMenuLinkPathname(pathname = "") {
@@ -62,6 +63,7 @@ function resolveMenuLinkTarget({
62
63
  to = "",
63
64
  surface = "",
64
65
  currentSurfaceId = "",
66
+ currentPathname = "",
65
67
  placementContext = null,
66
68
  scopedSuffix = "/",
67
69
  unscopedSuffix = "/",
@@ -72,10 +74,16 @@ function resolveMenuLinkTarget({
72
74
  return explicitTarget;
73
75
  }
74
76
 
77
+ // The route's params, over those the current surface's route base names in the pathname: a route that declares
78
+ // none, like the not-found route that catches any path, still has them in its URL.
79
+ const params = {
80
+ ...resolveSurfaceRouteParamsFromPlacementPathname(placementContext, currentSurfaceId, currentPathname),
81
+ ...routeParams
82
+ };
75
83
  const targetSurfaceId = resolveMenuLinkSurfaceId(surface, currentSurfaceId);
76
84
  const scopedRouteRequired = surfaceRequiresWorkspaceFromPlacementContext(placementContext, targetSurfaceId);
77
85
  const suffixTemplate = normalizeText(scopedRouteRequired ? scopedSuffix : unscopedSuffix) || "/";
78
- const interpolatedSuffix = interpolateBracketParams(suffixTemplate, routeParams);
86
+ const interpolatedSuffix = interpolateBracketParams(suffixTemplate, params);
79
87
  if (!targetSurfaceId || !interpolatedSuffix || interpolatedSuffix.includes("[")) {
80
88
  return "";
81
89
  }
@@ -84,7 +92,7 @@ function resolveMenuLinkTarget({
84
92
  context: placementContext,
85
93
  surface: targetSurfaceId,
86
94
  relativePath: interpolatedSuffix,
87
- params: routeParams,
95
+ params,
88
96
  strictParams: true
89
97
  }));
90
98
  }
@@ -37,6 +37,7 @@ function pathMatchesNavigationEntry(pathname = "", entry = {}) {
37
37
  function resolvePrimaryNavigationEntries(placements, {
38
38
  semanticTarget,
39
39
  currentSurfaceId,
40
+ currentPathname = "",
40
41
  placementContext,
41
42
  routeParams
42
43
  }) {
@@ -48,6 +49,7 @@ function resolvePrimaryNavigationEntries(placements, {
48
49
  to: entryProps.to,
49
50
  surface: entryProps.surface,
50
51
  currentSurfaceId,
52
+ currentPathname,
51
53
  placementContext,
52
54
  scopedSuffix: entryProps.scopedSuffix,
53
55
  unscopedSuffix: entryProps.unscopedSuffix,
@@ -234,3 +234,58 @@ test("shell bootstrap runtime queue recovers after a refresh rejects", async ()
234
234
  await assert.rejects(runtime.refresh("manual"), /error handler failed/);
235
235
  assert.deepEqual(await runtime.refresh("manual"), { recovered: true });
236
236
  });
237
+
238
+ test("shell bootstrap runtime runs one refresh and lets every later caller share one waiting refresh", async () => {
239
+ const handlers = createBootstrapPayloadHandlerRegistry();
240
+ const placementRuntime = createPlacementRuntime({ step: "first" });
241
+ const appliedReasons = [];
242
+ handlers.register(Object.freeze({
243
+ handlerId: "test.bootstrap.coalesce",
244
+ order: 0,
245
+ resolveBootstrapRequest({ placementRuntime: runtimePlacement }) {
246
+ return { query: { step: runtimePlacement.getContext().step } };
247
+ },
248
+ applyBootstrapPayload({ reason }) {
249
+ appliedReasons.push(reason);
250
+ },
251
+ handleBootstrapError() {}
252
+ }));
253
+ const fetched = [];
254
+ let releaseFirst = () => {};
255
+ const firstHeld = new Promise((resolve) => {
256
+ releaseFirst = resolve;
257
+ });
258
+ const runtime = createShellBootstrapRuntime({
259
+ handlers,
260
+ placementRuntime,
261
+ logger: silentLogger,
262
+ fetchImplementation: async (url) => {
263
+ fetched.push(url);
264
+ if (fetched.length === 1) {
265
+ await firstHeld;
266
+ }
267
+ return {
268
+ ok: true,
269
+ async json() {
270
+ return { url };
271
+ }
272
+ };
273
+ }
274
+ });
275
+
276
+ const first = runtime.refresh("init");
277
+ const waiting = [runtime.refresh("auth.state"), runtime.refresh("realtime"), runtime.refresh("route")];
278
+ await new Promise((resolve) => setTimeout(resolve, 0));
279
+ placementRuntime.setContext({ step: "second" });
280
+ releaseFirst();
281
+
282
+ assert.deepEqual(await first, { url: "/api/bootstrap?step=first" });
283
+ for (const result of await Promise.all(waiting)) {
284
+ assert.deepEqual(result, { url: "/api/bootstrap?step=second" });
285
+ }
286
+ assert.deepEqual(fetched, ["/api/bootstrap?step=first", "/api/bootstrap?step=second"]);
287
+ assert.deepEqual(appliedReasons, ["init", "auth.state"]);
288
+
289
+ assert.deepEqual(await runtime.refresh("manual"), { url: "/api/bootstrap?step=second" });
290
+ assert.equal(fetched.length, 3);
291
+ });
@@ -1,6 +1,11 @@
1
1
  import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
+ import { reactive } from "vue";
4
+ import { routeLocationKey } from "vue-router";
5
+ import { useShellNavigationLink } from "../src/client/composables/useShellNavigationLink.js";
6
+ import { SHELL_WEB_PLACEMENT_RUNTIME_KEY } from "../src/client/placement/inject.js";
3
7
  import { resolveMenuLinkTarget } from "../src/client/support/menuLinkTarget.js";
8
+ import { mountComposable } from "./support/mountComposable.js";
4
9
 
5
10
  function createPlacementContext() {
6
11
  return {
@@ -75,3 +80,78 @@ test("menu link target still requires surface params when it must build the path
75
80
  /Missing required surface route params/
76
81
  );
77
82
  });
83
+
84
+ test("menu link target reads the current surface's params from the pathname when the route declares none", () => {
85
+ const placementContext = createPlacementContext();
86
+ // The not-found route catches any path, so its only param is the path itself.
87
+ assert.equal(
88
+ resolveMenuLinkTarget({
89
+ surface: "app",
90
+ currentSurfaceId: "app",
91
+ currentPathname: "/w/acme/no-such-page",
92
+ placementContext,
93
+ scopedSuffix: "/projects",
94
+ routeParams: { pathMatch: ["w", "acme", "no-such-page"] }
95
+ }),
96
+ "/w/acme/projects"
97
+ );
98
+ assert.equal(
99
+ resolveMenuLinkTarget({
100
+ surface: "app",
101
+ currentSurfaceId: "app",
102
+ currentPathname: "/w/caf%C3%A9%20bar/no-such-page",
103
+ placementContext,
104
+ scopedSuffix: "/projects",
105
+ routeParams: {}
106
+ }),
107
+ "/w/caf%C3%A9%20bar/projects"
108
+ );
109
+ // The route's own params still win.
110
+ assert.equal(
111
+ resolveMenuLinkTarget({
112
+ surface: "app",
113
+ currentSurfaceId: "app",
114
+ currentPathname: "/w/acme/projects",
115
+ placementContext,
116
+ scopedSuffix: "/projects",
117
+ routeParams: { workspaceSlug: "beta" }
118
+ }),
119
+ "/w/beta/projects"
120
+ );
121
+ // A pathname on another surface names no params of this one.
122
+ assert.throws(
123
+ () => resolveMenuLinkTarget({
124
+ surface: "app",
125
+ currentSurfaceId: "home",
126
+ currentPathname: "/home/no-such-page",
127
+ placementContext,
128
+ scopedSuffix: "/projects",
129
+ routeParams: {}
130
+ }),
131
+ /Missing required surface route params for "app": workspaceSlug/
132
+ );
133
+ });
134
+
135
+ test("a shell menu link on the not-found route of a workspace surface links into that workspace", () => {
136
+ const route = reactive({
137
+ path: "/w/acme/no-such-page",
138
+ params: { pathMatch: ["w", "acme", "no-such-page"] }
139
+ });
140
+ const placementRuntime = {
141
+ getContext: () => createPlacementContext(),
142
+ getRevision: () => 1,
143
+ subscribe: () => () => {}
144
+ };
145
+ const { app, result } = mountComposable(
146
+ () => useShellNavigationLink({ label: "Projects", surface: "app", scopedSuffix: "/projects", unscopedSuffix: "/projects" }),
147
+ {
148
+ provide: [
149
+ [routeLocationKey, route],
150
+ [SHELL_WEB_PLACEMENT_RUNTIME_KEY, placementRuntime]
151
+ ]
152
+ }
153
+ );
154
+
155
+ assert.equal(result.resolvedTarget.value.href, "/w/acme/projects");
156
+ app.unmount();
157
+ });
@@ -59,6 +59,29 @@ test("primary navigation keeps the target's same-origin destinations in placemen
59
59
  ]);
60
60
  });
61
61
 
62
+ test("primary navigation on a route without surface params reads them from the current pathname", () => {
63
+ const placementContext = {
64
+ surfaceConfig: {
65
+ defaultSurfaceId: "app",
66
+ enabledSurfaceIds: ["app"],
67
+ surfacesById: {
68
+ app: { id: "app", pagesRoot: "w/[workspaceSlug]", routeBase: "/w/:workspaceSlug", enabled: true, requiresWorkspace: true }
69
+ }
70
+ }
71
+ };
72
+ const entries = resolvePrimaryNavigationEntries([
73
+ placement("contacts", { surface: "app", scopedSuffix: "/contacts", unscopedSuffix: "/contacts" })
74
+ ], {
75
+ semanticTarget: "shell.primary-nav",
76
+ currentSurfaceId: "app",
77
+ currentPathname: "/w/acme/no-such-page",
78
+ placementContext,
79
+ routeParams: { pathMatch: ["w", "acme", "no-such-page"] }
80
+ });
81
+
82
+ assert.deepEqual(entries.map((entry) => [entry.id, entry.href]), [["contacts", "/w/acme/contacts"]]);
83
+ });
84
+
62
85
  test("the active destination is the closest path match", () => {
63
86
  const entries = [
64
87
  { index: 0, pathname: "/home", exact: false },