@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.
- package/fixtures/adaptive-shell/src/main.js +4 -2
- 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 +20 -24
- 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 +30 -28
- 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 +13 -39
- package/src/client/placement/surfaceContext.js +14 -33
- package/src/client/placement/validators.js +6 -1
- package/src/client/providers/ShellWebClientProvider.js +17 -38
- 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 +40 -87
- package/src/client/runtime/bootstrapRuntime.js +20 -35
- package/src/client/runtime/refreshRuntime.js +30 -22
- 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/bootstrapRuntime.test.js +3 -1
- 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 +10 -3
- package/test/errorPresentation.test.js +51 -0
- package/test/errorRuntime.test.js +21 -10
- package/test/placementInject.test.js +60 -0
- package/test/placementRuntime.test.js +12 -9
- 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 +15 -11
- package/test/support/mountComposable.js +90 -0
- package/test/translation.test.js +4 -2
- package/test/useShellDrawer.test.js +213 -0
- package/test/useShellErrorHost.test.js +149 -0
- package/test/useShellRouteTransition.test.js +129 -0
|
@@ -1,30 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
inject
|
|
4
|
-
} from "vue";
|
|
1
|
+
import { inject } from "vue";
|
|
2
|
+
import { isRecoverableRequestError } from "./runtime.js";
|
|
5
3
|
|
|
6
4
|
const SHELL_REQUEST_RECOVERY_RUNTIME_KEY =
|
|
7
5
|
"jskit.shell-web.runtime.web-request-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").ShellRequestRecoveryRuntime}
|
|
10
|
+
*/
|
|
11
|
+
const NO_SHELL_REQUEST_RECOVERY_RUNTIME = Object.freeze({
|
|
12
|
+
dismiss() {
|
|
13
|
+
return 0;
|
|
14
|
+
},
|
|
15
|
+
dispose() {},
|
|
16
|
+
install() {
|
|
17
|
+
return Object.freeze({
|
|
18
|
+
dispose() {}
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
isRecoverableRequestError,
|
|
22
|
+
async reload() {
|
|
23
|
+
return false;
|
|
24
|
+
},
|
|
25
|
+
report() {
|
|
19
26
|
return null;
|
|
20
27
|
}
|
|
28
|
+
});
|
|
21
29
|
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
/**
|
|
31
|
+
* The shell's request recovery, or `NO_SHELL_REQUEST_RECOVERY_RUNTIME` in an application without shell-web's provider.
|
|
32
|
+
* @returns {import("../types.js").ShellRequestRecoveryRuntime}
|
|
33
|
+
*/
|
|
34
|
+
function useShellRequestRecoveryRuntime() {
|
|
35
|
+
return inject(SHELL_REQUEST_RECOVERY_RUNTIME_KEY, NO_SHELL_REQUEST_RECOVERY_RUNTIME);
|
|
24
36
|
}
|
|
25
37
|
|
|
26
38
|
export {
|
|
39
|
+
NO_SHELL_REQUEST_RECOVERY_RUNTIME,
|
|
27
40
|
SHELL_REQUEST_RECOVERY_RUNTIME_KEY,
|
|
28
|
-
isShellRequestRecoveryRuntime,
|
|
29
41
|
useShellRequestRecoveryRuntime
|
|
30
42
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { guardedReloadApp } from "@jskit-ai/kernel/client/asyncModuleRecovery";
|
|
2
2
|
import { isRecord, normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
|
|
3
|
-
import { createProviderLogger as createSharedProviderLogger } from "@jskit-ai/kernel/shared/support/providerLogger";
|
|
4
3
|
import { useJskitText } from "../i18n.js";
|
|
5
4
|
|
|
6
5
|
const { t, text } = useJskitText();
|
|
@@ -115,18 +114,8 @@ function requestRecoveryMessage(error = null, {
|
|
|
115
114
|
return t("jskit.shell.recovery.unreachable", { label: requestLabel });
|
|
116
115
|
}
|
|
117
116
|
|
|
118
|
-
function
|
|
119
|
-
|
|
120
|
-
return query.meta;
|
|
121
|
-
}
|
|
122
|
-
if (isRecord(query?.options?.meta)) {
|
|
123
|
-
return query.options.meta;
|
|
124
|
-
}
|
|
125
|
-
return {};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function readQueryRecoveryMeta(query = null) {
|
|
129
|
-
const meta = resolveQueryMeta(query);
|
|
117
|
+
function readQueryRecoveryMeta(query) {
|
|
118
|
+
const meta = isRecord(query.meta) ? query.meta : {};
|
|
130
119
|
const jskitMeta = isRecord(meta.jskit) ? meta.jskit : {};
|
|
131
120
|
const dedupeWindowMs = jskitMeta.requestRecoveryDedupeWindowMs;
|
|
132
121
|
|
|
@@ -140,18 +129,8 @@ function readQueryRecoveryMeta(query = null) {
|
|
|
140
129
|
});
|
|
141
130
|
}
|
|
142
131
|
|
|
143
|
-
function
|
|
144
|
-
|
|
145
|
-
return Boolean(query.isActive());
|
|
146
|
-
}
|
|
147
|
-
if (typeof query?.getObserversCount === "function") {
|
|
148
|
-
return Number(query.getObserversCount()) > 0;
|
|
149
|
-
}
|
|
150
|
-
return true;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function recoverableQueryError(query = null) {
|
|
154
|
-
const state = isRecord(query?.state) ? query.state : {};
|
|
132
|
+
function recoverableQueryError(query) {
|
|
133
|
+
const { state } = query;
|
|
155
134
|
if (state.status !== "error" || state.fetchStatus !== "idle") {
|
|
156
135
|
return null;
|
|
157
136
|
}
|
|
@@ -160,12 +139,8 @@ function recoverableQueryError(query = null) {
|
|
|
160
139
|
return isRecoverableRequestError(error) ? error : null;
|
|
161
140
|
}
|
|
162
141
|
|
|
163
|
-
function createQueryRetry(queryClient, query
|
|
164
|
-
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const queryKey = query?.queryKey;
|
|
142
|
+
function createQueryRetry(queryClient, query) {
|
|
143
|
+
const { queryKey } = query;
|
|
169
144
|
if (!Array.isArray(queryKey)) {
|
|
170
145
|
return null;
|
|
171
146
|
}
|
|
@@ -183,16 +158,16 @@ function createQueryRetry(queryClient, query = null) {
|
|
|
183
158
|
);
|
|
184
159
|
}
|
|
185
160
|
|
|
186
|
-
function resolveQueryHash(query
|
|
187
|
-
const explicitHash = normalizeText(query
|
|
161
|
+
function resolveQueryHash(query) {
|
|
162
|
+
const explicitHash = normalizeText(query.queryHash);
|
|
188
163
|
if (explicitHash) {
|
|
189
164
|
return explicitHash;
|
|
190
165
|
}
|
|
191
166
|
|
|
192
167
|
try {
|
|
193
|
-
return normalizeText(JSON.stringify(query
|
|
168
|
+
return normalizeText(JSON.stringify(query.queryKey || []));
|
|
194
169
|
} catch {
|
|
195
|
-
return normalizeText(String(query
|
|
170
|
+
return normalizeText(String(query.queryKey || ""));
|
|
196
171
|
}
|
|
197
172
|
}
|
|
198
173
|
|
|
@@ -200,17 +175,8 @@ function installRecoverableQueryObserver({
|
|
|
200
175
|
queryClient,
|
|
201
176
|
runtime,
|
|
202
177
|
logger
|
|
203
|
-
}
|
|
204
|
-
const queryCache =
|
|
205
|
-
queryClient && typeof queryClient.getQueryCache === "function"
|
|
206
|
-
? queryClient.getQueryCache()
|
|
207
|
-
: null;
|
|
208
|
-
if (!queryCache || typeof queryCache.subscribe !== "function") {
|
|
209
|
-
return Object.freeze({
|
|
210
|
-
dispose() {}
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
178
|
+
}) {
|
|
179
|
+
const queryCache = queryClient.getQueryCache();
|
|
214
180
|
const reportedErrorUpdateByQueryHash = new Map();
|
|
215
181
|
|
|
216
182
|
function dismissReportedQueryRecovery(queryHash = "") {
|
|
@@ -220,7 +186,7 @@ function installRecoverableQueryObserver({
|
|
|
220
186
|
}
|
|
221
187
|
|
|
222
188
|
reportedErrorUpdateByQueryHash.delete(queryHash);
|
|
223
|
-
if (reported.presentationId
|
|
189
|
+
if (reported.presentationId) {
|
|
224
190
|
runtime.dismiss(reported.presentationId, {
|
|
225
191
|
presenterId: reported.presenterId
|
|
226
192
|
});
|
|
@@ -233,14 +199,13 @@ function installRecoverableQueryObserver({
|
|
|
233
199
|
}
|
|
234
200
|
}
|
|
235
201
|
|
|
236
|
-
function inspectQuery(query
|
|
202
|
+
function inspectQuery(query) {
|
|
237
203
|
const queryHash = resolveQueryHash(query);
|
|
238
204
|
const recoveryMeta = readQueryRecoveryMeta(query);
|
|
239
205
|
if (
|
|
240
|
-
!query ||
|
|
241
206
|
recoveryMeta.disabled ||
|
|
242
207
|
!SAFE_REQUEST_RECOVERY_METHODS.has(recoveryMeta.method) ||
|
|
243
|
-
!
|
|
208
|
+
!query.isActive()
|
|
244
209
|
) {
|
|
245
210
|
if (queryHash) {
|
|
246
211
|
dismissReportedQueryRecovery(queryHash);
|
|
@@ -256,7 +221,7 @@ function installRecoverableQueryObserver({
|
|
|
256
221
|
return;
|
|
257
222
|
}
|
|
258
223
|
|
|
259
|
-
const errorUpdateCount = Number(query
|
|
224
|
+
const errorUpdateCount = Number(query.state.errorUpdateCount || 0);
|
|
260
225
|
const reportKey = `${errorUpdateCount}:${errorMessage(error)}`;
|
|
261
226
|
const reported = reportedErrorUpdateByQueryHash.get(queryHash);
|
|
262
227
|
if (reported?.reportKey === reportKey) {
|
|
@@ -268,7 +233,7 @@ function installRecoverableQueryObserver({
|
|
|
268
233
|
label: recoveryMeta.label,
|
|
269
234
|
retry: createQueryRetry(queryClient, query),
|
|
270
235
|
source: recoveryMeta.source,
|
|
271
|
-
stale: query
|
|
236
|
+
stale: query.state.data !== undefined,
|
|
272
237
|
dedupeKey: recoveryMeta.dedupeKey || `shell-web.request-recovery.query.${queryHash}.${errorUpdateCount}`,
|
|
273
238
|
...(dedupeWindowMs !== null ? { dedupeWindowMs } : {})
|
|
274
239
|
});
|
|
@@ -286,10 +251,8 @@ function installRecoverableQueryObserver({
|
|
|
286
251
|
}
|
|
287
252
|
|
|
288
253
|
try {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
inspectQuery(query);
|
|
292
|
-
}
|
|
254
|
+
for (const query of queryCache.getAll()) {
|
|
255
|
+
inspectQuery(query);
|
|
293
256
|
}
|
|
294
257
|
} catch (error) {
|
|
295
258
|
logger.warn(
|
|
@@ -300,9 +263,9 @@ function installRecoverableQueryObserver({
|
|
|
300
263
|
);
|
|
301
264
|
}
|
|
302
265
|
|
|
303
|
-
const unsubscribe = queryCache.subscribe((event
|
|
266
|
+
const unsubscribe = queryCache.subscribe((event) => {
|
|
304
267
|
try {
|
|
305
|
-
inspectQuery(event
|
|
268
|
+
inspectQuery(event.query);
|
|
306
269
|
} catch (error) {
|
|
307
270
|
logger.warn(
|
|
308
271
|
{
|
|
@@ -316,19 +279,22 @@ function installRecoverableQueryObserver({
|
|
|
316
279
|
return Object.freeze({
|
|
317
280
|
dispose() {
|
|
318
281
|
dismissReportedQueryRecoveries();
|
|
319
|
-
|
|
320
|
-
unsubscribe();
|
|
321
|
-
}
|
|
282
|
+
unsubscribe();
|
|
322
283
|
}
|
|
323
284
|
});
|
|
324
285
|
}
|
|
325
286
|
|
|
287
|
+
/**
|
|
288
|
+
* @param {object} options
|
|
289
|
+
* @param {import("@jskit-ai/kernel/client/types").ClientQueryClient} options.queryClient
|
|
290
|
+
* @param {import("../types.js").ShellErrorRuntime} options.errorRuntime
|
|
291
|
+
* @param {import("@jskit-ai/kernel/client/types").ClientLogger} options.logger
|
|
292
|
+
*/
|
|
326
293
|
function createShellRequestRecoveryRuntime({
|
|
327
|
-
queryClient
|
|
328
|
-
errorRuntime
|
|
329
|
-
logger
|
|
330
|
-
}
|
|
331
|
-
const runtimeLogger = createSharedProviderLogger(logger);
|
|
294
|
+
queryClient,
|
|
295
|
+
errorRuntime,
|
|
296
|
+
logger
|
|
297
|
+
}) {
|
|
332
298
|
let installedQueryObserver = null;
|
|
333
299
|
let reloadAttempt = 0;
|
|
334
300
|
|
|
@@ -385,9 +351,6 @@ function createShellRequestRecoveryRuntime({
|
|
|
385
351
|
}
|
|
386
352
|
|
|
387
353
|
function dismiss(presentationId = "", options = {}) {
|
|
388
|
-
if (!errorRuntime || typeof errorRuntime.dismiss !== "function") {
|
|
389
|
-
return 0;
|
|
390
|
-
}
|
|
391
354
|
return errorRuntime.dismiss(presentationId, options);
|
|
392
355
|
}
|
|
393
356
|
|
|
@@ -397,20 +360,8 @@ function createShellRequestRecoveryRuntime({
|
|
|
397
360
|
}
|
|
398
361
|
|
|
399
362
|
const source = normalizeText(options.source, { fallback: "shell-web.request-recovery" });
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
{
|
|
403
|
-
source,
|
|
404
|
-
error: errorMessage(error) || "unknown error"
|
|
405
|
-
},
|
|
406
|
-
"Shell request recovery could not report because the shell error runtime is unavailable."
|
|
407
|
-
);
|
|
408
|
-
return null;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
const retry = typeof options.retry === "function" ? options.retry : null;
|
|
412
|
-
const action = retry
|
|
413
|
-
? retryAction(options, retry)
|
|
363
|
+
const action = options.retry
|
|
364
|
+
? retryAction(options, options.retry)
|
|
414
365
|
: options.reload === true
|
|
415
366
|
? reloadAction(options)
|
|
416
367
|
: null;
|
|
@@ -429,7 +380,7 @@ function createShellRequestRecoveryRuntime({
|
|
|
429
380
|
action
|
|
430
381
|
});
|
|
431
382
|
} catch (reportError) {
|
|
432
|
-
|
|
383
|
+
logger.error(
|
|
433
384
|
{
|
|
434
385
|
source,
|
|
435
386
|
error: errorMessage(reportError) || "unknown error"
|
|
@@ -448,14 +399,16 @@ function createShellRequestRecoveryRuntime({
|
|
|
448
399
|
installedQueryObserver = installRecoverableQueryObserver({
|
|
449
400
|
queryClient,
|
|
450
401
|
runtime: api,
|
|
451
|
-
logger
|
|
402
|
+
logger
|
|
452
403
|
});
|
|
453
404
|
return installedQueryObserver;
|
|
454
405
|
}
|
|
455
406
|
|
|
456
407
|
function dispose() {
|
|
457
|
-
installedQueryObserver
|
|
458
|
-
|
|
408
|
+
if (installedQueryObserver) {
|
|
409
|
+
installedQueryObserver.dispose();
|
|
410
|
+
installedQueryObserver = null;
|
|
411
|
+
}
|
|
459
412
|
}
|
|
460
413
|
|
|
461
414
|
const api = Object.freeze({
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { normalizeObject } from "@jskit-ai/kernel/shared/support/normalize";
|
|
2
|
+
import { BOOTSTRAP_PATH } from "@jskit-ai/kernel/shared/surface/paths";
|
|
2
3
|
import { useJskitText } from "../i18n.js";
|
|
3
4
|
|
|
4
5
|
const { t } = useJskitText();
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function normalizeObject(value) {
|
|
9
|
-
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function buildBootstrapUrl({ path = DEFAULT_BOOTSTRAP_PATH, query = {} } = {}) {
|
|
13
|
-
const normalizedPath = String(path || DEFAULT_BOOTSTRAP_PATH).trim() || DEFAULT_BOOTSTRAP_PATH;
|
|
7
|
+
function buildBootstrapUrl({ path = BOOTSTRAP_PATH, query = {} } = {}) {
|
|
8
|
+
const normalizedPath = String(path || BOOTSTRAP_PATH).trim() || BOOTSTRAP_PATH;
|
|
14
9
|
const params = new URLSearchParams();
|
|
15
10
|
|
|
16
11
|
for (const [key, value] of Object.entries(normalizeObject(query))) {
|
|
@@ -33,23 +28,25 @@ function normalizeBootstrapResponseError(response, url) {
|
|
|
33
28
|
return error;
|
|
34
29
|
}
|
|
35
30
|
|
|
31
|
+
/**
|
|
32
|
+
* @param {object} options
|
|
33
|
+
* @param {import("../types.js").BootstrapPayloadHandlerRegistry} options.handlers
|
|
34
|
+
* @param {import("../types.js").WebPlacementRuntime} options.placementRuntime
|
|
35
|
+
* @param {import("../types.js").ShellRequestRecoveryRuntime} options.requestRecoveryRuntime
|
|
36
|
+
* @param {import("@jskit-ai/kernel/client/types").ClientRouter} options.router
|
|
37
|
+
* @param {import("@jskit-ai/kernel/client/types").ClientLogger} options.logger
|
|
38
|
+
* @param {typeof fetch} [options.fetchImplementation]
|
|
39
|
+
* @param {string} [options.bootstrapPath]
|
|
40
|
+
*/
|
|
36
41
|
function createShellBootstrapRuntime({
|
|
37
42
|
handlers,
|
|
38
43
|
placementRuntime,
|
|
39
|
-
requestRecoveryRuntime
|
|
40
|
-
router
|
|
44
|
+
requestRecoveryRuntime,
|
|
45
|
+
router,
|
|
41
46
|
logger,
|
|
42
47
|
fetchImplementation = globalThis.fetch,
|
|
43
|
-
bootstrapPath =
|
|
44
|
-
}
|
|
45
|
-
if (!handlers || typeof handlers.list !== "function") {
|
|
46
|
-
throw new Error("createShellBootstrapRuntime requires a bootstrap handler registry.");
|
|
47
|
-
}
|
|
48
|
-
if (!placementRuntime || typeof placementRuntime.setContext !== "function") {
|
|
49
|
-
throw new Error("createShellBootstrapRuntime requires a placement runtime.");
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const runtimeLogger = createProviderLogger(logger);
|
|
48
|
+
bootstrapPath = BOOTSTRAP_PATH
|
|
49
|
+
}) {
|
|
53
50
|
let initialized = false;
|
|
54
51
|
let refreshQueue = Promise.resolve();
|
|
55
52
|
|
|
@@ -62,10 +59,6 @@ function createShellBootstrapRuntime({
|
|
|
62
59
|
};
|
|
63
60
|
|
|
64
61
|
for (const handler of payloadHandlers) {
|
|
65
|
-
if (typeof handler.resolveBootstrapRequest !== "function") {
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
62
|
const contribution = normalizeObject(
|
|
70
63
|
await handler.resolveBootstrapRequest({
|
|
71
64
|
router,
|
|
@@ -122,10 +115,6 @@ function createShellBootstrapRuntime({
|
|
|
122
115
|
const source = `shell-web.bootstrap.${String(reason || "manual").trim() || "manual"}`;
|
|
123
116
|
|
|
124
117
|
for (const handler of payloadHandlers) {
|
|
125
|
-
if (typeof handler.handleBootstrapError !== "function") {
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
118
|
await handler.handleBootstrapError({
|
|
130
119
|
router,
|
|
131
120
|
placementRuntime,
|
|
@@ -138,10 +127,6 @@ function createShellBootstrapRuntime({
|
|
|
138
127
|
}
|
|
139
128
|
|
|
140
129
|
async function performRefresh(reason = "manual") {
|
|
141
|
-
if (typeof fetchImplementation !== "function") {
|
|
142
|
-
throw new Error("Bootstrap payload fetch requires a fetch implementation.");
|
|
143
|
-
}
|
|
144
|
-
|
|
145
130
|
let request = Object.freeze({ path: bootstrapPath, query: Object.freeze({}), meta: Object.freeze({}) });
|
|
146
131
|
|
|
147
132
|
try {
|
|
@@ -163,13 +148,13 @@ function createShellBootstrapRuntime({
|
|
|
163
148
|
return await applyBootstrapPayload(payload, reason, request);
|
|
164
149
|
} catch (error) {
|
|
165
150
|
await applyBootstrapError(error, reason, request);
|
|
166
|
-
requestRecoveryRuntime
|
|
151
|
+
requestRecoveryRuntime.report(error, {
|
|
167
152
|
label: t("jskit.shell.recovery.appDataLabel"),
|
|
168
153
|
retry: () => refresh(reason),
|
|
169
154
|
source: "shell-web.bootstrap",
|
|
170
155
|
dedupeKey: `shell-web.bootstrap.${String(reason || "manual").trim() || "manual"}.request-failed`
|
|
171
156
|
});
|
|
172
|
-
|
|
157
|
+
logger.warn(
|
|
173
158
|
{
|
|
174
159
|
reason,
|
|
175
160
|
error: String(error?.message || error || "unknown error")
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import { isRecord } from "@jskit-ai/kernel/shared/support";
|
|
2
|
-
import { createProviderLogger as createSharedProviderLogger } from "@jskit-ai/kernel/shared/support/providerLogger";
|
|
3
2
|
import { useJskitText } from "../i18n.js";
|
|
4
3
|
|
|
5
4
|
const { t } = useJskitText();
|
|
6
5
|
|
|
7
6
|
const SHELL_WEB_REFRESH_RUNTIME_KEY = "jskit.shell-web.runtime.web-refresh.client";
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The refresh of an application without shell-web's provider: nothing refreshes, so pull-to-refresh never starts.
|
|
10
|
+
* @type {any}
|
|
11
|
+
*/
|
|
12
|
+
const NO_SHELL_WEB_REFRESH_RUNTIME = Object.freeze({
|
|
13
|
+
async refresh(reason = "manual") {
|
|
14
|
+
return Object.freeze({
|
|
15
|
+
reason,
|
|
16
|
+
bootstrapRefreshed: false,
|
|
17
|
+
queriesRefetched: false
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
function isPullRefreshQuery(query) {
|
|
23
|
+
const meta = isRecord(query.meta) ? query.meta : {};
|
|
11
24
|
if (meta.jskitRefresh === "pull") {
|
|
12
25
|
return true;
|
|
13
26
|
}
|
|
@@ -19,29 +32,27 @@ function isPullRefreshQuery(query = null) {
|
|
|
19
32
|
return jskitMeta.refreshOnPull !== false;
|
|
20
33
|
}
|
|
21
34
|
|
|
35
|
+
/**
|
|
36
|
+
* @param {object} options
|
|
37
|
+
* @param {import("../types.js").ShellBootstrapRuntime} options.bootstrapRuntime
|
|
38
|
+
* @param {import("@jskit-ai/kernel/client/types").ClientQueryClient} options.queryClient
|
|
39
|
+
* @param {import("../types.js").ShellErrorRuntime} options.errorRuntime
|
|
40
|
+
* @param {import("@jskit-ai/kernel/client/types").ClientLogger} options.logger
|
|
41
|
+
*/
|
|
22
42
|
function createShellRefreshRuntime({
|
|
23
|
-
bootstrapRuntime
|
|
24
|
-
queryClient
|
|
25
|
-
errorRuntime
|
|
26
|
-
logger
|
|
27
|
-
}
|
|
28
|
-
const runtimeLogger = createSharedProviderLogger(logger);
|
|
43
|
+
bootstrapRuntime,
|
|
44
|
+
queryClient,
|
|
45
|
+
errorRuntime,
|
|
46
|
+
logger
|
|
47
|
+
}) {
|
|
29
48
|
let refreshQueue = Promise.resolve(null);
|
|
30
49
|
|
|
31
50
|
async function refreshBootstrap(reason) {
|
|
32
|
-
if (!bootstrapRuntime || typeof bootstrapRuntime.refresh !== "function") {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
51
|
await bootstrapRuntime.refresh(reason);
|
|
37
52
|
return true;
|
|
38
53
|
}
|
|
39
54
|
|
|
40
55
|
async function refetchPullQueries() {
|
|
41
|
-
if (!queryClient || typeof queryClient.refetchQueries !== "function") {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
56
|
await queryClient.refetchQueries(
|
|
46
57
|
{
|
|
47
58
|
type: "active",
|
|
@@ -55,17 +66,13 @@ function createShellRefreshRuntime({
|
|
|
55
66
|
}
|
|
56
67
|
|
|
57
68
|
function reportRefreshFailure(error) {
|
|
58
|
-
|
|
69
|
+
logger.warn(
|
|
59
70
|
{
|
|
60
71
|
error: String(error?.message || error || "unknown error")
|
|
61
72
|
},
|
|
62
73
|
"Shell refresh failed."
|
|
63
74
|
);
|
|
64
75
|
|
|
65
|
-
if (!errorRuntime || typeof errorRuntime.report !== "function") {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
76
|
errorRuntime.report({
|
|
70
77
|
source: "shell-web.refresh",
|
|
71
78
|
message: t("jskit.shell.recovery.refreshFailed"),
|
|
@@ -120,6 +127,7 @@ function createShellRefreshRuntime({
|
|
|
120
127
|
}
|
|
121
128
|
|
|
122
129
|
export {
|
|
130
|
+
NO_SHELL_WEB_REFRESH_RUNTIME,
|
|
123
131
|
SHELL_WEB_REFRESH_RUNTIME_KEY,
|
|
124
132
|
createShellRefreshRuntime
|
|
125
133
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { computed, markRaw, shallowRef } from "vue";
|
|
2
2
|
import { defineStore } from "pinia";
|
|
3
|
-
import { EMPTY_PRESENTATION_STATE,
|
|
3
|
+
import { EMPTY_PRESENTATION_STATE, NO_PRESENTATION_STORE } from "../error/presentationDefaults.js";
|
|
4
4
|
|
|
5
5
|
function normalizePresentationState(nextState) {
|
|
6
6
|
if (!nextState || typeof nextState !== "object") {
|
|
@@ -10,19 +10,8 @@ function normalizePresentationState(nextState) {
|
|
|
10
10
|
return nextState;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
function isPresentationRuntimeStore(value) {
|
|
14
|
-
return Boolean(
|
|
15
|
-
value &&
|
|
16
|
-
typeof value.getState === "function" &&
|
|
17
|
-
typeof value.subscribe === "function" &&
|
|
18
|
-
typeof value.present === "function" &&
|
|
19
|
-
typeof value.dismiss === "function" &&
|
|
20
|
-
typeof value.clear === "function"
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
13
|
export const useShellErrorPresentationStore = defineStore("jskit.shell-web.error-presentation", () => {
|
|
25
|
-
const runtimeStore = shallowRef(markRaw(
|
|
14
|
+
const runtimeStore = shallowRef(markRaw(NO_PRESENTATION_STORE));
|
|
26
15
|
const presentationState = shallowRef(EMPTY_PRESENTATION_STATE);
|
|
27
16
|
let unsubscribe = null;
|
|
28
17
|
|
|
@@ -32,17 +21,14 @@ export const useShellErrorPresentationStore = defineStore("jskit.shell-web.error
|
|
|
32
21
|
}
|
|
33
22
|
|
|
34
23
|
function detachRuntimeStore() {
|
|
35
|
-
if (
|
|
24
|
+
if (unsubscribe) {
|
|
36
25
|
unsubscribe();
|
|
37
26
|
unsubscribe = null;
|
|
38
27
|
}
|
|
39
28
|
}
|
|
40
29
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
throw new TypeError("useShellErrorPresentationStore.attachRuntimeStore requires an error presentation store.");
|
|
44
|
-
}
|
|
45
|
-
|
|
30
|
+
/** @param {import("../types.js").ShellErrorPresentationStore} nextRuntimeStore */
|
|
31
|
+
function attachRuntimeStore(nextRuntimeStore) {
|
|
46
32
|
if (runtimeStore.value === nextRuntimeStore) {
|
|
47
33
|
setPresentationState(nextRuntimeStore.getState());
|
|
48
34
|
return runtimeStore.value;
|
|
@@ -78,12 +78,51 @@ function resolveContentAwareDrawerWidth(
|
|
|
78
78
|
return clampNumber(Math.ceil(requiredWidth * 4) / 4, minimum, maximum);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
function measureRenderedText(element) {
|
|
82
|
+
const range = document.createRange();
|
|
83
|
+
range.selectNodeContents(element);
|
|
84
|
+
return range.getBoundingClientRect();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// The width the drawer's rendered labels need, from where each one starts on the drawer's inline axis.
|
|
88
|
+
function measureDrawerContentWidth(drawerElement, navigationItemSpacing) {
|
|
89
|
+
const drawerRect = drawerElement.getBoundingClientRect();
|
|
90
|
+
const drawerStyle = window.getComputedStyle(drawerElement);
|
|
91
|
+
const rightToLeft = drawerStyle.direction === "rtl";
|
|
92
|
+
const endBorderWidth = Number.parseFloat(
|
|
93
|
+
rightToLeft ? drawerStyle.borderLeftWidth : drawerStyle.borderRightWidth
|
|
94
|
+
) || 0;
|
|
95
|
+
const measurements = [];
|
|
96
|
+
|
|
97
|
+
for (const label of drawerElement.querySelectorAll(".v-list-item-title")) {
|
|
98
|
+
const labelStyle = window.getComputedStyle(label);
|
|
99
|
+
if (labelStyle.display === "none" || labelStyle.visibility === "hidden") {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const textRect = measureRenderedText(label);
|
|
103
|
+
if (!textRect || textRect.width <= 0) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
measurements.push({
|
|
107
|
+
logicalStart: rightToLeft
|
|
108
|
+
? drawerRect.right - textRect.right
|
|
109
|
+
: textRect.left - drawerRect.left,
|
|
110
|
+
textWidth: textRect.width
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return resolveContentAwareDrawerWidth(measurements, {
|
|
115
|
+
endGap: navigationItemSpacing + endBorderWidth
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
81
119
|
export {
|
|
82
120
|
DEFAULT_SHELL_DRAWER_WIDTH,
|
|
83
121
|
DEFAULT_SHELL_NAVIGATION_ITEM_SPACING,
|
|
84
122
|
DEFAULT_SHELL_RAIL_WIDTH,
|
|
85
123
|
MAXIMUM_SHELL_DRAWER_WIDTH,
|
|
86
124
|
MINIMUM_SHELL_DRAWER_WIDTH,
|
|
125
|
+
measureDrawerContentWidth,
|
|
87
126
|
normalizeShellDrawerWidth,
|
|
88
127
|
normalizeShellNavigationItemSpacing,
|
|
89
128
|
normalizeShellRailWidth,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { closestElement } from "../browser.js";
|
|
2
|
+
|
|
1
3
|
const SHELL_GESTURE_IGNORED_SELECTORS = Object.freeze([
|
|
2
4
|
"a",
|
|
3
5
|
"button",
|
|
@@ -14,13 +16,13 @@ const SHELL_GESTURE_IGNORED_SELECTORS = Object.freeze([
|
|
|
14
16
|
|
|
15
17
|
// Shell gestures follow touch and pen contact, never a mouse drag.
|
|
16
18
|
function isPrimaryTouchPointer(event) {
|
|
17
|
-
return event
|
|
19
|
+
return event.isPrimary !== false && event.button === 0 && event.pointerType !== "mouse";
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
// Interactive controls keep their own gestures; the shell does not start one on them.
|
|
21
23
|
function isShellGestureIgnoredTarget(target, { extraSelectors = [] } = {}) {
|
|
22
24
|
const selectors = [...SHELL_GESTURE_IGNORED_SELECTORS, ...extraSelectors].join(",");
|
|
23
|
-
return Boolean(target
|
|
25
|
+
return Boolean(closestElement(target, selectors));
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
export { isPrimaryTouchPointer, isShellGestureIgnoredTarget };
|