@openmrs/esm-app-shell 5.3.3-pre.1231 → 5.3.3-pre.1247
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/.turbo/turbo-build.log +98 -98
- package/dist/9c276181fc6599f8.js.map +1 -0
- package/dist/d81faa62d5818f52.js.map +1 -0
- package/dist/index.html +1 -1
- package/dist/{openmrs.954886865de0b85a.js → openmrs.6213811dbd70a295.js} +2 -2
- package/dist/openmrs.6213811dbd70a295.js.map +1 -0
- package/dist/openmrs.c9c4fe7ea57e9920.css.map +1 -1
- package/dist/service-worker.js +1 -1
- package/dist/service-worker.js.map +1 -1
- package/lib/{3975decbab0164f3.js → 9b51c0739002f900.js} +1 -1
- package/lib/{f29978db163aaa3d.js → c074b9133e91fad3.js} +5 -5
- package/lib/esm-devtools-app/68.js.map +1 -1
- package/lib/esm-devtools-app/889.js +1 -1
- package/lib/esm-devtools-app/988.js.map +1 -1
- package/lib/esm-devtools-app/main.js +1 -1
- package/lib/esm-devtools-app/main.js.map +1 -1
- package/lib/esm-devtools-app/openmrs-esm-devtools-app.js +1 -1
- package/lib/esm-devtools-app/openmrs-esm-devtools-app.js.buildmanifest.json +5 -5
- package/lib/esm-devtools-app/routes.json +1 -1
- package/lib/esm-implementer-tools-app/426.js.map +1 -1
- package/lib/esm-implementer-tools-app/560.js +1 -1
- package/lib/esm-implementer-tools-app/560.js.map +1 -1
- package/lib/esm-implementer-tools-app/587.js.map +1 -1
- package/lib/esm-implementer-tools-app/727.js +1 -1
- package/lib/esm-implementer-tools-app/727.js.map +1 -1
- package/lib/esm-implementer-tools-app/main.js +1 -1
- package/lib/esm-implementer-tools-app/main.js.map +1 -1
- package/lib/esm-implementer-tools-app/openmrs-esm-implementer-tools-app.js +1 -1
- package/lib/esm-implementer-tools-app/openmrs-esm-implementer-tools-app.js.buildmanifest.json +13 -13
- package/lib/esm-implementer-tools-app/routes.json +1 -1
- package/lib/esm-login-app/370.js +1 -1
- package/lib/esm-login-app/370.js.map +1 -1
- package/lib/esm-login-app/main.js +1 -1
- package/lib/esm-login-app/main.js.map +1 -1
- package/lib/esm-login-app/openmrs-esm-login-app.js +1 -1
- package/lib/esm-login-app/openmrs-esm-login-app.js.buildmanifest.json +8 -8
- package/lib/esm-login-app/routes.json +1 -1
- package/lib/esm-offline-tools-app/102.js +1 -1
- package/lib/esm-offline-tools-app/102.js.map +1 -1
- package/lib/esm-offline-tools-app/main.js +1 -1
- package/lib/esm-offline-tools-app/main.js.map +1 -1
- package/lib/esm-offline-tools-app/openmrs-esm-offline-tools-app.js +1 -1
- package/lib/esm-offline-tools-app/openmrs-esm-offline-tools-app.js.buildmanifest.json +8 -8
- package/lib/esm-offline-tools-app/routes.json +1 -1
- package/lib/esm-primary-navigation-app/735.js +1 -1
- package/lib/esm-primary-navigation-app/735.js.map +1 -1
- package/lib/esm-primary-navigation-app/main.js +1 -1
- package/lib/esm-primary-navigation-app/main.js.map +1 -1
- package/lib/esm-primary-navigation-app/openmrs-esm-primary-navigation-app.js +1 -1
- package/lib/esm-primary-navigation-app/openmrs-esm-primary-navigation-app.js.buildmanifest.json +8 -8
- package/lib/esm-primary-navigation-app/routes.json +1 -1
- package/lib/index.html +1 -1
- package/lib/openmrs.js +135 -135
- package/lib/service-worker.js +9 -9
- package/package.json +3 -3
- package/src/apps.ts +32 -72
- package/src/declarations.d.ts +3 -6
- package/src/helpers.ts +2 -4
- package/src/index.ts +13 -15
- package/src/locale.ts +24 -34
- package/src/run.ts +53 -87
- package/src/service-worker/caching.ts +14 -22
- package/src/service-worker/constants.ts +8 -13
- package/src/service-worker/http-header-utils.ts +5 -15
- package/src/service-worker/import-map-utils.ts +14 -25
- package/src/service-worker/index.ts +8 -8
- package/src/service-worker/message.ts +9 -15
- package/src/service-worker/routing.ts +23 -50
- package/src/service-worker/storage.ts +5 -5
- package/src/service-worker/types.ts +1 -1
- package/src/ui/breadcrumbs.tsx +14 -29
- package/src/ui/index.ts +6 -6
- package/tools/helpers.js +3 -7
- package/webpack.config.js +95 -117
- package/dist/966c4dfec919951f.js.map +0 -1
- package/dist/fca8d09359d3b887.js.map +0 -1
- package/dist/openmrs.954886865de0b85a.js.map +0 -1
- /package/dist/{fca8d09359d3b887.js → 9c276181fc6599f8.js} +0 -0
- /package/dist/{966c4dfec919951f.js → d81faa62d5818f52.js} +0 -0
- /package/dist/{openmrs.954886865de0b85a.js.LICENSE.txt → openmrs.6213811dbd70a295.js.LICENSE.txt} +0 -0
|
@@ -1,36 +1,29 @@
|
|
|
1
|
-
import { RouteHandlerCallbackOptions } from
|
|
2
|
-
import { registerRoute } from
|
|
3
|
-
import { getOrCreateDefaultRouter } from
|
|
4
|
-
import { validMethods } from
|
|
5
|
-
import { CacheOnly, NetworkFirst, NetworkOnly } from
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
omrsCacheName,
|
|
9
|
-
omrsOfflineCachingStrategyHttpHeaderName,
|
|
10
|
-
} from "./constants";
|
|
11
|
-
import { ServiceWorkerDb } from "./storage";
|
|
1
|
+
import { RouteHandlerCallbackOptions } from 'workbox-core';
|
|
2
|
+
import { registerRoute } from 'workbox-routing';
|
|
3
|
+
import { getOrCreateDefaultRouter } from 'workbox-routing/utils/getOrCreateDefaultRouter';
|
|
4
|
+
import { validMethods } from 'workbox-routing/utils/constants';
|
|
5
|
+
import { CacheOnly, NetworkFirst, NetworkOnly } from 'workbox-strategies';
|
|
6
|
+
import { indexUrl, omrsCacheName, omrsOfflineCachingStrategyHttpHeaderName } from './constants';
|
|
7
|
+
import { ServiceWorkerDb } from './storage';
|
|
12
8
|
import {
|
|
13
9
|
getOmrsHeader,
|
|
14
10
|
parseOmrsOfflineResponseBodyHeader,
|
|
15
11
|
parseOmrsOfflineResponseStatusHeader,
|
|
16
|
-
} from
|
|
17
|
-
import type { OmrsOfflineCachingStrategy } from
|
|
18
|
-
import uniq from
|
|
12
|
+
} from './http-header-utils';
|
|
13
|
+
import type { OmrsOfflineCachingStrategy } from '@openmrs/esm-offline';
|
|
14
|
+
import uniq from 'lodash-es/uniq';
|
|
19
15
|
|
|
20
16
|
const networkOnly = new NetworkOnly();
|
|
21
17
|
const cacheOnly = new CacheOnly({ cacheName: omrsCacheName });
|
|
22
18
|
const networkFirst = new NetworkFirst({ cacheName: omrsCacheName });
|
|
23
19
|
|
|
24
|
-
const defaultStrategy: OmrsOfflineCachingStrategy =
|
|
25
|
-
"network-only-or-cache-only";
|
|
20
|
+
const defaultStrategy: OmrsOfflineCachingStrategy = 'network-only-or-cache-only';
|
|
26
21
|
const knownStrategyHandlers: Record<
|
|
27
22
|
OmrsOfflineCachingStrategy,
|
|
28
23
|
(options: RouteHandlerCallbackOptions) => Promise<Response>
|
|
29
24
|
> = {
|
|
30
|
-
[
|
|
31
|
-
[
|
|
32
|
-
options: RouteHandlerCallbackOptions
|
|
33
|
-
) => {
|
|
25
|
+
['network-first']: (options) => networkFirst.handle(options),
|
|
26
|
+
['network-only-or-cache-only']: async (options: RouteHandlerCallbackOptions) => {
|
|
34
27
|
try {
|
|
35
28
|
return await networkOnly.handle(options);
|
|
36
29
|
} catch (e) {
|
|
@@ -47,10 +40,7 @@ export function registerAllOmrsRoutes() {
|
|
|
47
40
|
// to the SPA's index (which should always be precached).
|
|
48
41
|
// This ensures that the page loads correctly when a new navigation occurs to pages
|
|
49
42
|
// like `/openmrs/spa/anything/nested`.
|
|
50
|
-
registerRoute(
|
|
51
|
-
({ request }) => request.mode === "navigate",
|
|
52
|
-
navigationHandler
|
|
53
|
-
);
|
|
43
|
+
registerRoute(({ request }) => request.mode === 'navigate', navigationHandler);
|
|
54
44
|
|
|
55
45
|
// Fallback routing behavior.
|
|
56
46
|
// Checks if a dynamic route registration exists and, if so, handles it using a Network First approach.
|
|
@@ -77,22 +67,13 @@ async function navigationHandler(options: RouteHandlerCallbackOptions) {
|
|
|
77
67
|
|
|
78
68
|
async function defaultHandler(options: RouteHandlerCallbackOptions) {
|
|
79
69
|
const { request } = options;
|
|
80
|
-
const handlerKey =
|
|
81
|
-
|
|
82
|
-
? await getHandlerKey(options)
|
|
83
|
-
: defaultStrategy;
|
|
84
|
-
const handler =
|
|
85
|
-
knownStrategyHandlers[handlerKey] ?? knownStrategyHandlers[defaultStrategy];
|
|
70
|
+
const handlerKey = options.request.method === 'GET' ? await getHandlerKey(options) : defaultStrategy;
|
|
71
|
+
const handler = knownStrategyHandlers[handlerKey] ?? knownStrategyHandlers[defaultStrategy];
|
|
86
72
|
|
|
87
73
|
try {
|
|
88
74
|
return await handler(options);
|
|
89
75
|
} catch (e) {
|
|
90
|
-
console.warn(
|
|
91
|
-
"[SW] Could not handle the request to %s (using handler %s).",
|
|
92
|
-
request.url,
|
|
93
|
-
handlerKey,
|
|
94
|
-
e
|
|
95
|
-
);
|
|
76
|
+
console.warn('[SW] Could not handle the request to %s (using handler %s).', request.url, handlerKey, e);
|
|
96
77
|
|
|
97
78
|
return new Response(parseOmrsOfflineResponseBodyHeader(request.headers), {
|
|
98
79
|
status: parseOmrsOfflineResponseStatusHeader(request.headers),
|
|
@@ -101,10 +82,7 @@ async function defaultHandler(options: RouteHandlerCallbackOptions) {
|
|
|
101
82
|
}
|
|
102
83
|
|
|
103
84
|
async function getHandlerKey({ request }: RouteHandlerCallbackOptions) {
|
|
104
|
-
return (
|
|
105
|
-
getHandlerKeyFromHeaders(request.headers) ??
|
|
106
|
-
(await getHandlerKeyFromDynamicRouteRegistrations(request.url))
|
|
107
|
-
);
|
|
85
|
+
return getHandlerKeyFromHeaders(request.headers) ?? (await getHandlerKeyFromDynamicRouteRegistrations(request.url));
|
|
108
86
|
}
|
|
109
87
|
|
|
110
88
|
function getHandlerKeyFromHeaders(headers: Headers) {
|
|
@@ -113,12 +91,11 @@ function getHandlerKeyFromHeaders(headers: Headers) {
|
|
|
113
91
|
|
|
114
92
|
async function getHandlerKeyFromDynamicRouteRegistrations(url: string) {
|
|
115
93
|
const db = new ServiceWorkerDb();
|
|
116
|
-
const allDynamicRouteRegistrations =
|
|
117
|
-
await db.dynamicRouteRegistrations.toArray();
|
|
94
|
+
const allDynamicRouteRegistrations = await db.dynamicRouteRegistrations.toArray();
|
|
118
95
|
const strategies = uniq(
|
|
119
96
|
allDynamicRouteRegistrations
|
|
120
97
|
.filter((route) => new RegExp(route.pattern).test(url))
|
|
121
|
-
.map((route) => route.strategy ??
|
|
98
|
+
.map((route) => route.strategy ?? 'network-first'),
|
|
122
99
|
);
|
|
123
100
|
|
|
124
101
|
if (strategies.length <= 1) {
|
|
@@ -126,15 +103,11 @@ async function getHandlerKeyFromDynamicRouteRegistrations(url: string) {
|
|
|
126
103
|
} else {
|
|
127
104
|
// Multiple routes can match the URL (multiple RegExps can match).
|
|
128
105
|
// In that case, prioritize the available strategies. When in doubt, cache the resource again.
|
|
129
|
-
const priorities: Array<OmrsOfflineCachingStrategy> = [
|
|
130
|
-
"network-first",
|
|
131
|
-
"network-only-or-cache-only",
|
|
132
|
-
];
|
|
106
|
+
const priorities: Array<OmrsOfflineCachingStrategy> = ['network-first', 'network-only-or-cache-only'];
|
|
133
107
|
|
|
134
108
|
return (
|
|
135
|
-
priorities.find((prioritizedStrategy) =>
|
|
136
|
-
|
|
137
|
-
) ?? defaultStrategy
|
|
109
|
+
priorities.find((prioritizedStrategy) => strategies.some((strategy) => strategy === prioritizedStrategy)) ??
|
|
110
|
+
defaultStrategy
|
|
138
111
|
);
|
|
139
112
|
}
|
|
140
113
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { OmrsOfflineCachingStrategy } from
|
|
2
|
-
import Dexie, { Table } from
|
|
1
|
+
import type { OmrsOfflineCachingStrategy } from '@openmrs/esm-offline';
|
|
2
|
+
import Dexie, { Table } from 'dexie';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Contains information about dynamic route registrations.
|
|
@@ -28,9 +28,9 @@ export class ServiceWorkerDb extends Dexie {
|
|
|
28
28
|
dynamicRouteRegistrations: Table<DynamicRouteRegistration, number>;
|
|
29
29
|
|
|
30
30
|
constructor() {
|
|
31
|
-
super(
|
|
32
|
-
this.version(1).stores({ dynamicRouteRegistrations:
|
|
31
|
+
super('ServiceWorker');
|
|
32
|
+
this.version(1).stores({ dynamicRouteRegistrations: '++,&pattern' });
|
|
33
33
|
|
|
34
|
-
this.dynamicRouteRegistrations = this.table(
|
|
34
|
+
this.dynamicRouteRegistrations = this.table('dynamicRouteRegistrations');
|
|
35
35
|
}
|
|
36
36
|
}
|
package/src/ui/breadcrumbs.tsx
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import React, { useEffect, useState } from
|
|
2
|
-
import { Breadcrumb, BreadcrumbItem, InlineLoading } from
|
|
3
|
-
import {
|
|
4
|
-
getBreadcrumbsFor,
|
|
5
|
-
ConfigurableLink,
|
|
6
|
-
BreadcrumbRegistration,
|
|
7
|
-
} from "@openmrs/esm-framework";
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { Breadcrumb, BreadcrumbItem, InlineLoading } from '@carbon/react';
|
|
3
|
+
import { getBreadcrumbsFor, ConfigurableLink, BreadcrumbRegistration } from '@openmrs/esm-framework';
|
|
8
4
|
|
|
9
5
|
function getPath(path: string, params: Array<string>) {
|
|
10
6
|
const parts = [...params];
|
|
@@ -18,11 +14,11 @@ function getParams(path: string, matcher: RegExp) {
|
|
|
18
14
|
const [, ...params] = match;
|
|
19
15
|
return params;
|
|
20
16
|
} else {
|
|
21
|
-
const segments = path.split(
|
|
17
|
+
const segments = path.split('/');
|
|
22
18
|
segments.pop();
|
|
23
19
|
|
|
24
20
|
if (segments.length > 1) {
|
|
25
|
-
const newPath = segments.join(
|
|
21
|
+
const newPath = segments.join('/');
|
|
26
22
|
return getParams(newPath, matcher);
|
|
27
23
|
}
|
|
28
24
|
}
|
|
@@ -35,17 +31,12 @@ interface CustomBreadcrumbItemProps {
|
|
|
35
31
|
params: any;
|
|
36
32
|
}
|
|
37
33
|
|
|
38
|
-
export const CustomBreadcrumbItem: React.FC<CustomBreadcrumbItemProps> = ({
|
|
39
|
-
|
|
40
|
-
params,
|
|
41
|
-
}) => {
|
|
42
|
-
const [title, setTitle] = useState("");
|
|
34
|
+
export const CustomBreadcrumbItem: React.FC<CustomBreadcrumbItemProps> = ({ breadcrumbRegistration, params }) => {
|
|
35
|
+
const [title, setTitle] = useState('');
|
|
43
36
|
|
|
44
37
|
useEffect(() => {
|
|
45
|
-
if (typeof breadcrumbRegistration.settings.title ===
|
|
46
|
-
Promise.resolve(breadcrumbRegistration.settings.title(params)).then(
|
|
47
|
-
(res) => setTitle(res)
|
|
48
|
-
);
|
|
38
|
+
if (typeof breadcrumbRegistration.settings.title === 'function') {
|
|
39
|
+
Promise.resolve(breadcrumbRegistration.settings.title(params)).then((res) => setTitle(res));
|
|
49
40
|
} else {
|
|
50
41
|
setTitle(breadcrumbRegistration.settings.title);
|
|
51
42
|
}
|
|
@@ -53,9 +44,7 @@ export const CustomBreadcrumbItem: React.FC<CustomBreadcrumbItemProps> = ({
|
|
|
53
44
|
|
|
54
45
|
return (
|
|
55
46
|
<BreadcrumbItem key={breadcrumbRegistration.settings.path}>
|
|
56
|
-
<ConfigurableLink
|
|
57
|
-
to={getPath(breadcrumbRegistration.settings.path, params)}
|
|
58
|
-
>
|
|
47
|
+
<ConfigurableLink to={getPath(breadcrumbRegistration.settings.path, params)}>
|
|
59
48
|
{title ? title : <InlineLoading />}
|
|
60
49
|
</ConfigurableLink>
|
|
61
50
|
</BreadcrumbItem>
|
|
@@ -70,8 +59,8 @@ export const Breadcrumbs: React.FC = () => {
|
|
|
70
59
|
|
|
71
60
|
useEffect(() => {
|
|
72
61
|
const handler = () => setPath(location.pathname);
|
|
73
|
-
window.addEventListener(
|
|
74
|
-
return () => window.removeEventListener(
|
|
62
|
+
window.addEventListener('popstate', handler);
|
|
63
|
+
return () => window.removeEventListener('popstate', handler);
|
|
75
64
|
}, []);
|
|
76
65
|
|
|
77
66
|
if (breadcrumbs.length > 4) {
|
|
@@ -79,7 +68,7 @@ export const Breadcrumbs: React.FC = () => {
|
|
|
79
68
|
...breadcrumbs[1],
|
|
80
69
|
settings: {
|
|
81
70
|
...breadcrumbs[1].settings,
|
|
82
|
-
title:
|
|
71
|
+
title: '...',
|
|
83
72
|
},
|
|
84
73
|
});
|
|
85
74
|
}
|
|
@@ -87,11 +76,7 @@ export const Breadcrumbs: React.FC = () => {
|
|
|
87
76
|
return (
|
|
88
77
|
<Breadcrumb className="breadcrumbs-container">
|
|
89
78
|
{breadcrumbs.map((bc, index) => (
|
|
90
|
-
<CustomBreadcrumbItem
|
|
91
|
-
key={`breadcrumb-item-${index}`}
|
|
92
|
-
breadcrumbRegistration={bc}
|
|
93
|
-
params={params}
|
|
94
|
-
/>
|
|
79
|
+
<CustomBreadcrumbItem key={`breadcrumb-item-${index}`} breadcrumbRegistration={bc} params={params} />
|
|
95
80
|
))}
|
|
96
81
|
</Breadcrumb>
|
|
97
82
|
);
|
package/src/ui/index.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { getAsyncLifecycle } from
|
|
1
|
+
import { getAsyncLifecycle } from '@openmrs/esm-framework';
|
|
2
2
|
|
|
3
|
-
export const appName =
|
|
3
|
+
export const appName = '@openmrs/esm-app-shell';
|
|
4
4
|
|
|
5
5
|
export function getCoreExtensions() {
|
|
6
6
|
const options = {
|
|
7
|
-
featureName:
|
|
7
|
+
featureName: 'app-shell',
|
|
8
8
|
moduleName: appName,
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
return [
|
|
12
12
|
{
|
|
13
|
-
name:
|
|
14
|
-
slot:
|
|
15
|
-
load: getAsyncLifecycle(() => import(
|
|
13
|
+
name: 'breadcrumbs-widget',
|
|
14
|
+
slot: 'breadcrumbs-slot',
|
|
15
|
+
load: getAsyncLifecycle(() => import('./breadcrumbs'), options),
|
|
16
16
|
online: true,
|
|
17
17
|
offline: true,
|
|
18
18
|
},
|
package/tools/helpers.js
CHANGED
|
@@ -6,9 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
exports.removeTrailingSlash = (path) => {
|
|
8
8
|
const i = path.length - 1;
|
|
9
|
-
return path[i] ===
|
|
10
|
-
? exports.removeTrailingSlash(path.substr(0, i))
|
|
11
|
-
: path;
|
|
9
|
+
return path[i] === '/' ? exports.removeTrailingSlash(path.substr(0, i)) : path;
|
|
12
10
|
};
|
|
13
11
|
|
|
14
12
|
/**
|
|
@@ -18,13 +16,11 @@ exports.removeTrailingSlash = (path) => {
|
|
|
18
16
|
* @returns {string} The number as a string, padded to two places
|
|
19
17
|
*/
|
|
20
18
|
const padToTwoDigits = (num) => {
|
|
21
|
-
return num.toString().padStart(2,
|
|
19
|
+
return num.toString().padStart(2, '0');
|
|
22
20
|
};
|
|
23
21
|
|
|
24
22
|
exports.getTimestamp = () => {
|
|
25
23
|
const today = new Date();
|
|
26
24
|
const dd = padToTwoDigits;
|
|
27
|
-
return `${today.getFullYear()}${dd(today.getMonth() + 1)}${dd(
|
|
28
|
-
today.getDate()
|
|
29
|
-
)}`;
|
|
25
|
+
return `${today.getFullYear()}${dd(today.getMonth() + 1)}${dd(today.getDate())}`;
|
|
30
26
|
};
|