@openmrs/esm-routes 7.0.1-pre.3258 → 7.0.1-pre.3273

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.
@@ -1,3 +1,3 @@
1
- [0] Successfully compiled: 9 files with swc (159.68ms)
1
+ [0] Successfully compiled: 9 files with swc (143.68ms)
2
2
  [0] swc --strip-leading-paths src -d dist exited with code 0
3
3
  [1] tsc --project tsconfig.build.json exited with code 0
@@ -1,4 +1,4 @@
1
- import { type FeatureFlagDefinition, type ExtensionDefinition, type ModalDefinition, type WorkspaceDefinition, type WorkspaceGroupDefinition } from '@openmrs/esm-globals';
1
+ import { type FeatureFlagDefinition, type ExtensionDefinition, type ModalDefinition, type WorkspaceDefinition, type WorkspaceGroupDefinition, type WorkspaceGroupDefinition2, type WorkspaceDefinition2, type WorkspaceWindowDefinition2 } from '@openmrs/esm-globals';
2
2
  /**
3
3
  * This function registers an extension definition with the framework and will
4
4
  * attach the extension to any configured slots.
@@ -28,6 +28,9 @@ export declare function tryRegisterWorkspace(appName: string, workspace: Workspa
28
28
  * @param workspace An object that describes the workspace, derived from `routes.json`
29
29
  */
30
30
  export declare function tryRegisterWorkspaceGroup(appName: string, workspaceGroup: WorkspaceGroupDefinition): void;
31
+ export declare function tryRegisterWorkspaceGroups2(appName: string, workspaceGroupDefs: Array<WorkspaceGroupDefinition2>): void;
32
+ export declare function tryRegisterWorkspace2(appName: string, workspaceDefs: Array<WorkspaceDefinition2>): void;
33
+ export declare function tryRegisterWorkspaceWindows2(appName: string, workspaceWindowDefs: Array<WorkspaceWindowDefinition2>): void;
31
34
  /**
32
35
  * This function registers a feature flag definition with the framework.
33
36
  *
@@ -1,4 +1,4 @@
1
- import { attach, registerExtension, registerModal, registerWorkspace, registerWorkspaceGroup } from "@openmrs/esm-extensions";
1
+ import { attach, registerExtension, registerModal, registerWorkspace, registerWorkspaceGroup, registerWorkspaceGroups2, registerWorkspaces2, registerWorkspaceWindows2 } from "@openmrs/esm-extensions";
2
2
  import { registerFeatureFlag } from "@openmrs/esm-feature-flags";
3
3
  import { loadLifeCycles } from "./load-lifecycles.js";
4
4
  /**
@@ -128,6 +128,15 @@ To fix this, ensure that you define the "name" field inside the workspace defini
128
128
  members: workspaceGroup.members ?? []
129
129
  });
130
130
  }
131
+ export function tryRegisterWorkspaceGroups2(appName, workspaceGroupDefs) {
132
+ registerWorkspaceGroups2(workspaceGroupDefs);
133
+ }
134
+ export function tryRegisterWorkspace2(appName, workspaceDefs) {
135
+ registerWorkspaces2(appName, workspaceDefs);
136
+ }
137
+ export function tryRegisterWorkspaceWindows2(appName, workspaceWindowDefs) {
138
+ registerWorkspaceWindows2(appName, workspaceWindowDefs);
139
+ }
131
140
  /**
132
141
  * This function registers a feature flag definition with the framework.
133
142
  *
@@ -11,10 +11,7 @@ import { type OpenmrsAppRoutes } from '@openmrs/esm-globals';
11
11
  export declare function registerApp(appName: string, routes: OpenmrsAppRoutes): void;
12
12
  /**
13
13
  * This is called by the app shell once all route entries have been processed.
14
- * This actually registers the pages with the application. This function is
15
- * necessary to ensure that pages are rendered in the DOM according to their
16
- * order definition, especially because certain pages _must_ be first in the DOM.
17
- *
18
- * Each page is rendered into a div with an appropriate name.
14
+ * This registers the pages with the application, and creates the root div
15
+ * for each page in the DOM element specified by the page's containerDomId.
19
16
  */
20
17
  export declare function finishRegisteringAllApps(): void;
@@ -2,7 +2,7 @@ import { pathToActiveWhen, registerApplication } from "single-spa";
2
2
  import { registerModuleWithConfigSystem } from "@openmrs/esm-config";
3
3
  import { getFeatureFlag } from "@openmrs/esm-feature-flags";
4
4
  import { routeRegex } from "./helpers.js";
5
- import { tryRegisterExtension, tryRegisterFeatureFlag, tryRegisterModal, tryRegisterWorkspace, tryRegisterWorkspaceGroup } from "./components.js";
5
+ import { tryRegisterExtension, tryRegisterFeatureFlag, tryRegisterModal, tryRegisterWorkspace, tryRegisterWorkspace2, tryRegisterWorkspaceGroup, tryRegisterWorkspaceGroups2, tryRegisterWorkspaceWindows2 } from "./components.js";
6
6
  import { loadLifeCycles } from "./load-lifecycles.js";
7
7
  // this is the global holder of all pages registered in the app
8
8
  const pages = [];
@@ -73,11 +73,13 @@ const pages = [];
73
73
  const availableWorkspaces = routes.workspaces ?? [];
74
74
  const availableWorkspaceGroups = routes.workspaceGroups ?? [];
75
75
  const availableFeatureFlags = routes.featureFlags ?? [];
76
+ const availableWorkspaceGroups2 = routes.workspaceGroups2 ?? [];
77
+ const availableWorkspaceWindows2 = routes.workspaceWindows2 ?? [];
78
+ const availableWorkspaces2 = routes.workspaces2 ?? [];
76
79
  routes.pages?.forEach((p)=>{
77
80
  if (p && typeof p === 'object' && Object.hasOwn(p, 'component') && (Object.hasOwn(p, 'route') || Object.hasOwn(p, 'routeRegex') || Object.hasOwn(p, 'routes'))) {
78
81
  pages.push({
79
82
  ...p,
80
- order: p.order ?? Number.MAX_SAFE_INTEGER,
81
83
  appName
82
84
  });
83
85
  } else {
@@ -112,6 +114,9 @@ const pages = [];
112
114
  console.warn(`A workspace group for ${appName} could not be registered as it does not appear to have the required properties`, workspaceGroup);
113
115
  }
114
116
  });
117
+ tryRegisterWorkspaceGroups2(appName, availableWorkspaceGroups2);
118
+ tryRegisterWorkspaceWindows2(appName, availableWorkspaceWindows2);
119
+ tryRegisterWorkspace2(appName, availableWorkspaces2);
115
120
  availableFeatureFlags.forEach((featureFlag)=>{
116
121
  if (featureFlag && typeof featureFlag === 'object' && Object.hasOwn(featureFlag, 'flagName')) {
117
122
  tryRegisterFeatureFlag(appName, featureFlag);
@@ -123,22 +128,18 @@ const pages = [];
123
128
  }
124
129
  /**
125
130
  * This is called by the app shell once all route entries have been processed.
126
- * This actually registers the pages with the application. This function is
127
- * necessary to ensure that pages are rendered in the DOM according to their
128
- * order definition, especially because certain pages _must_ be first in the DOM.
129
- *
130
- * Each page is rendered into a div with an appropriate name.
131
+ * This registers the pages with the application, and creates the root div
132
+ * for each page in the DOM element specified by the page's containerDomId.
131
133
  */ export function finishRegisteringAllApps() {
132
134
  pages.sort((a, b)=>{
133
- let sort = a.order - b.order;
134
- if (sort != 0) {
135
- return sort;
136
- }
137
135
  return a.appName.localeCompare(b.appName, 'en');
138
136
  });
139
- // Create a div for each page. This ensures their DOM order.
137
+ // Create a div for each page, unless the DOM already contains the div with
138
+ // the expected id for the page to be mounted on. See:
139
+ // https://single-spa.js.org/docs/configuration/#two-registered-applications-simultaneously
140
+ // The div is put inside the DOM element specified by the page's containerDomId.
140
141
  // If we don't do this, Single-SPA 5 will create the DOM element only once
141
- // the page becomes active, which makes it impossible to guarantee order.
142
+ // the page becomes active, at the end of <body>.
142
143
  let appIndices = new Map();
143
144
  for (let page of pages){
144
145
  if (!appIndices.has(page.appName)) {
@@ -148,9 +149,16 @@ const pages = [];
148
149
  }
149
150
  const index = appIndices.get(page.appName);
150
151
  const name = `${page.appName}-page-${index}`;
151
- const div = document.createElement('div');
152
- div.id = `single-spa-application:${name}`;
153
- document.body.appendChild(div);
152
+ const containerDomId = page.containerDomId ?? 'omrs-apps-container';
153
+ const containerDiv = document.getElementById(containerDomId);
154
+ const appDomRootId = `single-spa-application:${name}`;
155
+ if (containerDiv) {
156
+ const div = document.createElement('div');
157
+ div.id = appDomRootId;
158
+ containerDiv?.appendChild(div);
159
+ } else {
160
+ throw new Error(`${page.appName} ${page.component} cannot be mounted to "${containerDomId}"; DOM element does not exist.`);
161
+ }
154
162
  tryRegisterPage(name, page);
155
163
  }
156
164
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-routes",
3
- "version": "7.0.1-pre.3258",
3
+ "version": "7.0.1-pre.3273",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Utilities for working with the routes registry",
6
6
  "type": "module",
@@ -54,12 +54,12 @@
54
54
  "single-spa": "6.x"
55
55
  },
56
56
  "devDependencies": {
57
- "@openmrs/esm-config": "7.0.1-pre.3258",
58
- "@openmrs/esm-dynamic-loading": "7.0.1-pre.3258",
59
- "@openmrs/esm-extensions": "7.0.1-pre.3258",
60
- "@openmrs/esm-feature-flags": "7.0.1-pre.3258",
61
- "@openmrs/esm-globals": "7.0.1-pre.3258",
62
- "@openmrs/esm-utils": "7.0.1-pre.3258",
57
+ "@openmrs/esm-config": "7.0.1-pre.3273",
58
+ "@openmrs/esm-dynamic-loading": "7.0.1-pre.3273",
59
+ "@openmrs/esm-extensions": "7.0.1-pre.3273",
60
+ "@openmrs/esm-feature-flags": "7.0.1-pre.3273",
61
+ "@openmrs/esm-globals": "7.0.1-pre.3273",
62
+ "@openmrs/esm-utils": "7.0.1-pre.3273",
63
63
  "@swc/cli": "^0.7.7",
64
64
  "@swc/core": "^1.11.29",
65
65
  "concurrently": "^9.1.2",
@@ -4,6 +4,9 @@ import {
4
4
  registerModal,
5
5
  registerWorkspace,
6
6
  registerWorkspaceGroup,
7
+ registerWorkspaceGroups2,
8
+ registerWorkspaces2,
9
+ registerWorkspaceWindows2,
7
10
  } from '@openmrs/esm-extensions';
8
11
  import {
9
12
  type FeatureFlagDefinition,
@@ -11,6 +14,9 @@ import {
11
14
  type ModalDefinition,
12
15
  type WorkspaceDefinition,
13
16
  type WorkspaceGroupDefinition,
17
+ type WorkspaceGroupDefinition2,
18
+ type WorkspaceDefinition2,
19
+ type WorkspaceWindowDefinition2,
14
20
  } from '@openmrs/esm-globals';
15
21
  import { registerFeatureFlag } from '@openmrs/esm-feature-flags';
16
22
  import { loadLifeCycles } from './load-lifecycles';
@@ -183,6 +189,18 @@ To fix this, ensure that you define the "name" field inside the workspace defini
183
189
  });
184
190
  }
185
191
 
192
+ export function tryRegisterWorkspaceGroups2(appName: string, workspaceGroupDefs: Array<WorkspaceGroupDefinition2>) {
193
+ registerWorkspaceGroups2(workspaceGroupDefs);
194
+ }
195
+
196
+ export function tryRegisterWorkspace2(appName: string, workspaceDefs: Array<WorkspaceDefinition2>) {
197
+ registerWorkspaces2(appName, workspaceDefs);
198
+ }
199
+
200
+ export function tryRegisterWorkspaceWindows2(appName: string, workspaceWindowDefs: Array<WorkspaceWindowDefinition2>) {
201
+ registerWorkspaceWindows2(appName, workspaceWindowDefs);
202
+ }
203
+
186
204
  /**
187
205
  * This function registers a feature flag definition with the framework.
188
206
  *
@@ -17,7 +17,10 @@ import {
17
17
  tryRegisterFeatureFlag,
18
18
  tryRegisterModal,
19
19
  tryRegisterWorkspace,
20
+ tryRegisterWorkspace2,
20
21
  tryRegisterWorkspaceGroup,
22
+ tryRegisterWorkspaceGroups2,
23
+ tryRegisterWorkspaceWindows2,
21
24
  } from './components';
22
25
  import { loadLifeCycles } from './load-lifecycles';
23
26
 
@@ -102,6 +105,9 @@ export function registerApp(appName: string, routes: OpenmrsAppRoutes) {
102
105
  const availableWorkspaces: Array<WorkspaceDefinition> = routes.workspaces ?? [];
103
106
  const availableWorkspaceGroups: Array<WorkspaceGroupDefinition> = routes.workspaceGroups ?? [];
104
107
  const availableFeatureFlags: Array<FeatureFlagDefinition> = routes.featureFlags ?? [];
108
+ const availableWorkspaceGroups2 = routes.workspaceGroups2 ?? [];
109
+ const availableWorkspaceWindows2 = routes.workspaceWindows2 ?? [];
110
+ const availableWorkspaces2 = routes.workspaces2 ?? [];
105
111
 
106
112
  routes.pages?.forEach((p) => {
107
113
  if (
@@ -112,7 +118,6 @@ export function registerApp(appName: string, routes: OpenmrsAppRoutes) {
112
118
  ) {
113
119
  pages.push({
114
120
  ...p,
115
- order: p.order ?? Number.MAX_SAFE_INTEGER,
116
121
  appName,
117
122
  });
118
123
  } else {
@@ -171,6 +176,9 @@ export function registerApp(appName: string, routes: OpenmrsAppRoutes) {
171
176
  );
172
177
  }
173
178
  });
179
+ tryRegisterWorkspaceGroups2(appName, availableWorkspaceGroups2);
180
+ tryRegisterWorkspaceWindows2(appName, availableWorkspaceWindows2);
181
+ tryRegisterWorkspace2(appName, availableWorkspaces2);
174
182
 
175
183
  availableFeatureFlags.forEach((featureFlag) => {
176
184
  if (featureFlag && typeof featureFlag === 'object' && Object.hasOwn(featureFlag, 'flagName')) {
@@ -187,24 +195,20 @@ export function registerApp(appName: string, routes: OpenmrsAppRoutes) {
187
195
 
188
196
  /**
189
197
  * This is called by the app shell once all route entries have been processed.
190
- * This actually registers the pages with the application. This function is
191
- * necessary to ensure that pages are rendered in the DOM according to their
192
- * order definition, especially because certain pages _must_ be first in the DOM.
193
- *
194
- * Each page is rendered into a div with an appropriate name.
198
+ * This registers the pages with the application, and creates the root div
199
+ * for each page in the DOM element specified by the page's containerDomId.
195
200
  */
196
201
  export function finishRegisteringAllApps() {
197
202
  pages.sort((a, b) => {
198
- let sort = a.order - b.order;
199
- if (sort != 0) {
200
- return sort;
201
- }
202
203
  return a.appName.localeCompare(b.appName, 'en');
203
204
  });
204
205
 
205
- // Create a div for each page. This ensures their DOM order.
206
+ // Create a div for each page, unless the DOM already contains the div with
207
+ // the expected id for the page to be mounted on. See:
208
+ // https://single-spa.js.org/docs/configuration/#two-registered-applications-simultaneously
209
+ // The div is put inside the DOM element specified by the page's containerDomId.
206
210
  // If we don't do this, Single-SPA 5 will create the DOM element only once
207
- // the page becomes active, which makes it impossible to guarantee order.
211
+ // the page becomes active, at the end of <body>.
208
212
  let appIndices = new Map();
209
213
  for (let page of pages) {
210
214
  if (!appIndices.has(page.appName)) {
@@ -215,9 +219,19 @@ export function finishRegisteringAllApps() {
215
219
  const index = appIndices.get(page.appName);
216
220
 
217
221
  const name = `${page.appName}-page-${index}`;
218
- const div = document.createElement('div');
219
- div.id = `single-spa-application:${name}`;
220
- document.body.appendChild(div);
222
+ const containerDomId = page.containerDomId ?? 'omrs-apps-container';
223
+ const containerDiv = document.getElementById(containerDomId);
224
+ const appDomRootId = `single-spa-application:${name}`;
225
+
226
+ if (containerDiv) {
227
+ const div = document.createElement('div');
228
+ div.id = appDomRootId;
229
+ containerDiv?.appendChild(div);
230
+ } else {
231
+ throw new Error(
232
+ `${page.appName} ${page.component} cannot be mounted to "${containerDomId}"; DOM element does not exist.`,
233
+ );
234
+ }
221
235
  tryRegisterPage(name, page);
222
236
  }
223
237
  }