@jskit-ai/shell-web 0.2.14 → 0.2.16

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
+ - The shell's client provider starts loading the app's `src/placementTopology.js`, `src/placement.js` and `src/error.js` together instead of each after the one before; it still reads, checks and applies them in the same order, and each is still optional. Measured on the accounts starter with 60 ms of latency per request: the three arrived by 851 ms instead of 935 ms (721-790, 799-865 and 869-935 ms before, 718-851 ms together after), and the bootstrap request that follows them started 82 ms sooner.
6
+ - After Up or the browser's Back, the shell's attempts to focus the element that opened the page left (every 100 ms for up to 1.5 s, until the page draws it) stop at the next navigation and when focus has moved since they started. Before, they outlived both: a Back then a Forward within 1.5 s could focus a matching link or tab on the next page and take the caret from a field someone was typing in. Focus that only fell back to the page body, as when the left page's element goes away, still gets the opener.
5
7
  - `ShellErrorHost`'s snackbar no longer covers the actions it reports on: it showed at the bottom end for 5 seconds over Save and the FAB, so a second Save waited it out. It is centred at the bottom on compact windows and starts at the content's start edge on wider ones, at most half the content's width, clear of end-aligned FABs and form actions; Vuetify keeps it above the navigation bar and a FAB that takes layout room (`<v-fab app layout>`). On a phone a form's Save is the app bar's primary action (`ShellPageAction primary`), which it never covers.
6
8
  - `ShellSectionTabLinkItem` (new, `@jskit-ai/shell-web/client/components/ShellSectionTabLinkItem`) is a page's section tab (`page.section-nav`): a Material 3 primary tab, 48dp (64dp with the placement's icon above the label), its label in title-small, the active one's label `primary` over a 3dp indicator under its content with rounded top corners, `aria-current="page"`. The starter registers it as `local.main.ui.section-tab-link-item`, and the page-and-placement pattern's Reports tabs use it in a row of their own over an `outline-variant` divider. `ShellTabLinkItem` styles itself as a navigation bar destination (its 64x32 indicator, full height, no padding, 5.5rem label) only inside `ShellLayout`'s navigation bar, which now gives its outlet the "bar" presentation; placed anywhere else, as in a page's section tabs, it draws a `ShellSectionTabLinkItem`, instead of squashed 64dp pills with clipped labels.
7
9
  - Navigation needs two destinations: with one (Home alone) `ShellLayout` draws no navigation bar, rail, drawer or menu control, as a surface with none already had none. The destinations are counted across the bar and the drawer, so a phone's one drawer destination beside the bar's (Settings beside Home) keeps its drawer; the layout's own `menu` slot keeps one too, and the surface identity (a workspace switcher) keeps the drawer beside any navigation. `shellLayoutHasNavigationBar()` joins `shellLayoutHasDrawer()`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/shell-web",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -46,14 +46,14 @@
46
46
  "./locales/en.json": "./locales/en.json"
47
47
  },
48
48
  "dependencies": {
49
- "@jskit-ai/architecture-inspector": "0.1.9"
49
+ "@jskit-ai/architecture-inspector": "0.1.11"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@jskit-ai/material-web": "0.1.3",
53
53
  "@vue/compiler-sfc": "3.5.44"
54
54
  },
55
55
  "peerDependencies": {
56
- "@jskit-ai/kernel": "0.2.11",
56
+ "@jskit-ai/kernel": "0.2.13",
57
57
  "pinia": "^4.0.3",
58
58
  "vue": "^3.5.44",
59
59
  "vue-router": "^5.3.1",
@@ -209,13 +209,16 @@ function createShellNavigationRuntime({ router }) {
209
209
  return null;
210
210
  }
211
211
 
212
- // After Up or Back, focus the element that opened the page left, or else the page title.
212
+ // After Up or Back, focus the element that opened the page left, or else the page title. The next navigation
213
+ // cancels it (handleBeforeEach), and so does focus moved since it was scheduled: a person already typing in a field
214
+ // keeps the caret there.
213
215
  function scheduleFocus(leftPath) {
214
216
  clearFocusTimer();
215
217
  const windowRef = pageWindow();
216
218
  if (!windowRef) {
217
219
  return;
218
220
  }
221
+ const focusedWhenScheduled = pageDocument()?.activeElement || null;
219
222
  let attempts = 0;
220
223
  const tryFocus = () => {
221
224
  focusTimer = null;
@@ -223,6 +226,10 @@ function createShellNavigationRuntime({ router }) {
223
226
  if (!documentRef) {
224
227
  return;
225
228
  }
229
+ const focused = documentRef.activeElement;
230
+ if (focused && focused !== documentRef.body && focused !== focusedWhenScheduled) {
231
+ return;
232
+ }
226
233
  const opener = findOpener(documentRef, leftPath);
227
234
  if (opener) {
228
235
  opener.focus({ preventScroll: true });
@@ -239,6 +246,7 @@ function createShellNavigationRuntime({ router }) {
239
246
  }
240
247
 
241
248
  function handleBeforeEach(to, from) {
249
+ clearFocusTimer();
242
250
  if (pending && !pending.redirected && pending.fallback && to.redirectedFrom && sameLocation(to.redirectedFrom.fullPath, pending.target)) {
243
251
  // The trail's page now redirects (no access, workspace left): go to the declared parent instead.
244
252
  pending = {
@@ -106,9 +106,24 @@ async function loadAppModule({
106
106
  return fallback;
107
107
  }
108
108
 
109
- function loadAppPlacementDefinitions(logger, asyncModuleRecoveryRuntime) {
109
+ // Starts the app's optional modules downloading together, so boot waits for the slowest one instead of each in
110
+ // turn; each is still read, checked and applied in order. A missing module is expected, so each import gets a
111
+ // handler at once and its failure is read where it is awaited.
112
+ function importAppModules() {
113
+ const imports = {
114
+ placements: import("/src/placement.js"),
115
+ placementTopology: import("/src/placementTopology.js"),
116
+ errorConfig: import("/src/error.js")
117
+ };
118
+ for (const pending of Object.values(imports)) {
119
+ pending.catch(() => {});
120
+ }
121
+ return imports;
122
+ }
123
+
124
+ function loadAppPlacementDefinitions(logger, asyncModuleRecoveryRuntime, pendingImport) {
110
125
  return loadAppModule({
111
- importModule: () => import("/src/placement.js"),
126
+ importModule: () => pendingImport,
112
127
  specifier: APP_PLACEMENT_MODULE_SPECIFIER,
113
128
  label: t("jskit.shell.recovery.placementConfigLabel"),
114
129
  resolve(exported) {
@@ -123,9 +138,9 @@ function loadAppPlacementDefinitions(logger, asyncModuleRecoveryRuntime) {
123
138
  });
124
139
  }
125
140
 
126
- function loadAppPlacementTopology(logger, asyncModuleRecoveryRuntime) {
141
+ function loadAppPlacementTopology(logger, asyncModuleRecoveryRuntime, pendingImport) {
127
142
  return loadAppModule({
128
- importModule: () => import("/src/placementTopology.js"),
143
+ importModule: () => pendingImport,
129
144
  specifier: APP_PLACEMENT_TOPOLOGY_MODULE_SPECIFIER,
130
145
  label: t("jskit.shell.recovery.placementTopologyLabel"),
131
146
  resolve: (exported) => resolveAppPlacementTopologyExport(exported, logger),
@@ -168,9 +183,9 @@ function createErrorConfigToolkit(errorRuntime) {
168
183
  });
169
184
  }
170
185
 
171
- function loadAppErrorConfig(logger, errorRuntime, asyncModuleRecoveryRuntime) {
186
+ function loadAppErrorConfig(logger, errorRuntime, asyncModuleRecoveryRuntime, pendingImport) {
172
187
  return loadAppModule({
173
- importModule: () => import("/src/error.js"),
188
+ importModule: () => pendingImport,
174
189
  specifier: APP_ERROR_MODULE_SPECIFIER,
175
190
  label: t("jskit.shell.recovery.errorConfigLabel"),
176
191
  async resolve(exported) {
@@ -353,9 +368,10 @@ const ShellWebClientProvider = defineProvider({
353
368
  // Before the router's first navigation, so the trail starts with the page the tab opened on.
354
369
  navigationRuntime.install();
355
370
 
356
- const placementTopology = await loadAppPlacementTopology(logger, asyncModuleRecoveryRuntime);
371
+ const appModules = importAppModules();
372
+ const placementTopology = await loadAppPlacementTopology(logger, asyncModuleRecoveryRuntime, appModules.placementTopology);
357
373
  placementRuntime.replacePlacementTopology(placementTopology, { source: APP_PLACEMENT_TOPOLOGY_MODULE_SPECIFIER });
358
- const placements = await loadAppPlacementDefinitions(logger, asyncModuleRecoveryRuntime);
374
+ const placements = await loadAppPlacementDefinitions(logger, asyncModuleRecoveryRuntime, appModules.placements);
359
375
  placementRuntime.replacePlacements(placements, { source: APP_PLACEMENT_MODULE_SPECIFIER });
360
376
  const appConfig = getClientAppConfig();
361
377
  const surfaceConfig = buildSurfaceConfigContext(surfaceRuntime, {
@@ -371,7 +387,7 @@ const ShellWebClientProvider = defineProvider({
371
387
  }
372
388
  );
373
389
 
374
- const errorConfig = await loadAppErrorConfig(logger, errorRuntime, asyncModuleRecoveryRuntime);
390
+ const errorConfig = await loadAppErrorConfig(logger, errorRuntime, asyncModuleRecoveryRuntime, appModules.errorConfig);
375
391
  errorRuntime.configure(errorConfig);
376
392
  requestRecoveryRuntime.install();
377
393
  // After the app's error configuration, so the offer follows its policy.
@@ -179,3 +179,94 @@ test("pages in a route folder are different pages, so a new page opens at the to
179
179
  delete globalThis.window;
180
180
  }
181
181
  });
182
+
183
+ // After Up, the runtime retries focusing the opener of the page left until the page draws it. Those retries end at the
184
+ // next navigation and when focus has moved since they were scheduled, so they never take the caret from a field
185
+ // someone is typing in (a Back then Forward within the retry window used to focus a matching tab on the next page).
186
+ test("Up's opener focus retries stop at the next navigation and when focus has moved", async () => {
187
+ const router = browserLikeRouter(routes);
188
+ const timers = new Map();
189
+ let nextTimer = 1;
190
+ globalThis.window.setTimeout = (callback) => {
191
+ timers.set(nextTimer, callback);
192
+ return nextTimer++;
193
+ };
194
+ globalThis.window.clearTimeout = (id) => {
195
+ timers.delete(id);
196
+ };
197
+ // One round runs the timers due now (one focus attempt); every round runs until none is left.
198
+ const runRound = () => {
199
+ const due = [...timers];
200
+ timers.clear();
201
+ for (const [, callback] of due) {
202
+ callback();
203
+ }
204
+ };
205
+ const runEveryRound = () => {
206
+ for (let round = 0; round < 20 && timers.size > 0; round += 1) {
207
+ runRound();
208
+ }
209
+ };
210
+ const focused = [];
211
+ const element = (name) => ({ name, focus: () => focused.push(name) });
212
+ const body = element("body");
213
+ const upButton = element("up");
214
+ const searchBox = element("search");
215
+ let openerDrawn = false;
216
+ const opener = { ...element("opener"), getClientRects: () => (openerDrawn ? [{}] : []) };
217
+ globalThis.document = {
218
+ body,
219
+ activeElement: body,
220
+ querySelectorAll: () => [opener],
221
+ getElementById: () => element("title")
222
+ };
223
+ const runtime = createShellNavigationRuntime({ router });
224
+ runtime.install();
225
+ runtime.attachShell();
226
+ const openFormAndGoUp = async () => {
227
+ await router.push("/home/actions");
228
+ await router.push("/home/actions/new");
229
+ focused.length = 0;
230
+ openerDrawn = false;
231
+ globalThis.document.activeElement = upButton;
232
+ await runtime.up("/home/actions");
233
+ assert.equal(router.currentRoute.value.fullPath, "/home/actions");
234
+ };
235
+ try {
236
+ // Unchanged: focus still on Up, the page draws its opener on a later attempt, and the opener gets focus.
237
+ await openFormAndGoUp();
238
+ runRound();
239
+ assert.deepEqual(focused, [], "no opener drawn yet");
240
+ openerDrawn = true;
241
+ runRound();
242
+ assert.deepEqual(focused, ["opener"]);
243
+
244
+ // A navigation before the opener is drawn cancels the retries.
245
+ await openFormAndGoUp();
246
+ runRound();
247
+ assert.equal(timers.size, 1, "a retry is waiting");
248
+ await router.push("/home/actions/new");
249
+ openerDrawn = true;
250
+ runEveryRound();
251
+ assert.deepEqual(focused, [], "the next page's matching element is not focused");
252
+
253
+ // Focus moved to a field since Up: the retries give up instead of taking it.
254
+ await openFormAndGoUp();
255
+ runRound();
256
+ globalThis.document.activeElement = searchBox;
257
+ openerDrawn = true;
258
+ runEveryRound();
259
+ assert.deepEqual(focused, [], "the field keeps focus");
260
+
261
+ // Focus that only fell back to the body (the left page's element went away) does not stop it.
262
+ await openFormAndGoUp();
263
+ globalThis.document.activeElement = body;
264
+ openerDrawn = true;
265
+ runRound();
266
+ assert.deepEqual(focused, ["opener"]);
267
+ } finally {
268
+ runtime.dispose();
269
+ delete globalThis.window;
270
+ delete globalThis.document;
271
+ }
272
+ });