@openmrs/esm-extensions 3.1.15-pre.757 → 3.1.15-pre.769
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/dist/openmrs-esm-extensions.js +1 -1
- package/dist/openmrs-esm-extensions.js.map +1 -1
- package/package.json +5 -5
- package/src/extensions.ts +209 -173
- package/src/index.ts +1 -9
- package/src/render.ts +2 -6
- package/src/store.ts +39 -72
package/src/store.ts
CHANGED
|
@@ -2,9 +2,8 @@ import isEqual from "lodash-es/isEqual";
|
|
|
2
2
|
import {
|
|
3
3
|
configExtensionStore,
|
|
4
4
|
ConfigExtensionStoreElement,
|
|
5
|
-
ExtensionSlotConfigObject,
|
|
6
5
|
} from "@openmrs/esm-config";
|
|
7
|
-
import { createGlobalStore
|
|
6
|
+
import { createGlobalStore } from "@openmrs/esm-state";
|
|
8
7
|
|
|
9
8
|
export interface ExtensionMeta {
|
|
10
9
|
[_: string]: any;
|
|
@@ -32,114 +31,82 @@ export interface ExtensionInstance {
|
|
|
32
31
|
id: string;
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
export interface
|
|
34
|
+
export interface ExtensionStore {
|
|
36
35
|
/** Slots indexed by name */
|
|
37
36
|
slots: Record<string, ExtensionSlotInfo>;
|
|
38
37
|
/** Extensions indexed by name */
|
|
39
38
|
extensions: Record<string, ExtensionInfo>;
|
|
40
39
|
}
|
|
41
40
|
|
|
41
|
+
export interface ExtensionSlotInstance {
|
|
42
|
+
/**
|
|
43
|
+
* A set of additional extension IDs which have been added to to this slot despite not being
|
|
44
|
+
* explicitly `attach`ed to it.
|
|
45
|
+
* An example may be an extension which is added to the slot via the configuration.
|
|
46
|
+
*/
|
|
47
|
+
addedIds: Array<string>;
|
|
48
|
+
/**
|
|
49
|
+
* A set of extension IDs which have been removed/hidden from this slot, even though they have
|
|
50
|
+
* previously been `attach`ed/added to it.
|
|
51
|
+
* An example may be an extension which is removed from the slot via the configuration.
|
|
52
|
+
*/
|
|
53
|
+
removedIds: Array<string>;
|
|
54
|
+
/**
|
|
55
|
+
* A set allowing explicit ordering of the `assignedIds`.
|
|
56
|
+
*/
|
|
57
|
+
idOrder: Array<string>;
|
|
58
|
+
}
|
|
59
|
+
|
|
42
60
|
export interface ExtensionSlotInfo {
|
|
43
61
|
/**
|
|
44
|
-
* The
|
|
45
|
-
* hasn't been registered yet (but it has been attached or assigned to
|
|
46
|
-
* an extension.
|
|
62
|
+
* The name under which the extension slot has been registered.
|
|
47
63
|
*/
|
|
48
|
-
moduleName?: string;
|
|
49
|
-
/** The name under which the extension slot has been registered. */
|
|
50
64
|
name: string;
|
|
51
65
|
/**
|
|
52
|
-
* The
|
|
66
|
+
* The mapping of modules / extension slot instances where the extension slot has been used.
|
|
67
|
+
*/
|
|
68
|
+
instances: Record<string, ExtensionSlotInstance>;
|
|
69
|
+
/**
|
|
70
|
+
* The set of extension IDs which have been attached to this slot.
|
|
71
|
+
* This is essentially a complete history of `attach` calls to this specific slot.
|
|
53
72
|
* However, not all of these extension IDs should be rendered.
|
|
54
73
|
* `assignedIds` is the set defining those.
|
|
55
74
|
*/
|
|
56
75
|
attachedIds: Array<string>;
|
|
57
|
-
/** The configuration provided for this extension slot. `null` if not yet loaded. */
|
|
58
|
-
config: ExtensionSlotConfigObject | null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface ExtensionStore {
|
|
62
|
-
slots: Record<string, ExtensionSlotState>;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface ExtensionSlotState {
|
|
66
|
-
moduleName: string;
|
|
67
|
-
assignedExtensions: Array<AssignedExtension>;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export interface AssignedExtension {
|
|
71
|
-
id: string;
|
|
72
|
-
name: string;
|
|
73
|
-
meta: ExtensionMeta;
|
|
74
|
-
online?: boolean | object;
|
|
75
|
-
offline?: boolean | object;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
export
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
78
|
+
export const extensionStore = createGlobalStore<ExtensionStore>("extensions", {
|
|
79
|
+
slots: {},
|
|
80
|
+
extensions: {},
|
|
81
|
+
});
|
|
83
82
|
|
|
84
|
-
const extensionInternalStore = createGlobalStore<ExtensionInternalStore>(
|
|
85
|
-
"extensionsInternal",
|
|
86
|
-
{
|
|
87
|
-
slots: {},
|
|
88
|
-
extensions: {},
|
|
89
|
-
}
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* This gets the extension system's internal store. It is subject
|
|
94
|
-
* to change radically and without warning. It should not be used
|
|
95
|
-
* outside esm-core.
|
|
96
|
-
* @internal
|
|
97
|
-
*/
|
|
98
|
-
export const getExtensionInternalStore = () =>
|
|
99
|
-
getGlobalStore<ExtensionInternalStore>("extensionsInternal", {
|
|
100
|
-
slots: {},
|
|
101
|
-
extensions: {},
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
/** @internal */
|
|
105
83
|
export type MaybeAsync<T> = T | Promise<T>;
|
|
106
84
|
|
|
107
85
|
let storeUpdates: Promise<void> = Promise.resolve();
|
|
108
86
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
updater: (state: ExtensionInternalStore) => MaybeAsync<ExtensionInternalStore>
|
|
87
|
+
export function updateExtensionStore(
|
|
88
|
+
updater: (state: ExtensionStore) => MaybeAsync<ExtensionStore>
|
|
112
89
|
) {
|
|
113
90
|
storeUpdates = storeUpdates.then(async () => {
|
|
114
|
-
const state =
|
|
91
|
+
const state = extensionStore.getState();
|
|
115
92
|
const newState = await updater(state);
|
|
116
93
|
|
|
117
94
|
if (newState !== state) {
|
|
118
|
-
|
|
95
|
+
extensionStore.setState(newState);
|
|
119
96
|
}
|
|
120
97
|
});
|
|
121
98
|
}
|
|
122
99
|
|
|
123
|
-
/**
|
|
124
|
-
* This returns a [store](https://github.com/developit/unistore#store)
|
|
125
|
-
* that modules can use to get information about the state of the
|
|
126
|
-
* extension system.
|
|
127
|
-
*/
|
|
128
|
-
export const getExtensionStore = () =>
|
|
129
|
-
getGlobalStore<ExtensionStore>("extensions", {
|
|
130
|
-
slots: {},
|
|
131
|
-
});
|
|
132
|
-
|
|
133
100
|
/**
|
|
134
101
|
* esm-config maintains its own store of the extension information it needs
|
|
135
102
|
* to generate extension configs. We keep it updated based on what's in
|
|
136
103
|
* `extensionStore`.
|
|
137
104
|
*/
|
|
138
105
|
|
|
139
|
-
updateConfigExtensionStore(
|
|
140
|
-
|
|
106
|
+
updateConfigExtensionStore(extensionStore.getState());
|
|
107
|
+
extensionStore.subscribe(updateConfigExtensionStore);
|
|
141
108
|
|
|
142
|
-
function updateConfigExtensionStore(extensionState:
|
|
109
|
+
function updateConfigExtensionStore(extensionState: ExtensionStore) {
|
|
143
110
|
const configExtensionRecords: Array<ConfigExtensionStoreElement> = [];
|
|
144
111
|
|
|
145
112
|
for (let extensionInfo of Object.values(extensionState.extensions)) {
|