@legalplace/wizardx-core 4.42.10-nightly.20251126153634 → 4.42.10-nightly.20251126173006
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/PluginLoader.d.ts
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import type {
|
|
2
|
+
import type { LoadableComponent } from "@loadable/component";
|
|
3
|
+
import type { Action, Reducer } from "redux";
|
|
3
4
|
import type { Saga } from "redux-saga";
|
|
4
|
-
|
|
5
|
+
declare let pluginsStoreReducers: Record<string, Reducer<Record<string, any>, any>>;
|
|
6
|
+
declare const pluginsStoreSagas: Record<string, Saga[]>;
|
|
7
|
+
export type PluginAppStatesRegisterFunction = (currentAppStates: string[]) => string[];
|
|
8
|
+
export type PluginsPageAppStatesType = Record<string, string>;
|
|
9
|
+
export type actionOverrideFunction = (action: Action) => Action;
|
|
10
|
+
export interface IPluginsAppStatesComponents {
|
|
11
|
+
[key: string]: LoadableComponent<any>;
|
|
12
|
+
}
|
|
13
|
+
export interface PluginsAppStatesDeclarations {
|
|
14
|
+
register: PluginAppStatesRegisterFunction;
|
|
15
|
+
pageAppState: PluginsPageAppStatesType;
|
|
16
|
+
components: IPluginsAppStatesComponents;
|
|
17
|
+
additionalRoutes?: Record<string, ReactComponent<any>>[];
|
|
18
|
+
}
|
|
19
|
+
declare let PluginsPageAppStates: PluginsPageAppStatesType;
|
|
5
20
|
type TPluginLoader = React.FC<PluginLoaderProps>;
|
|
6
21
|
export interface PluginLoaderProps {
|
|
7
22
|
anchor: string[];
|
|
@@ -16,16 +31,20 @@ export type ReplaceFragmentPropsType = {
|
|
|
16
31
|
fragmentName?: string;
|
|
17
32
|
children?: React.ReactNode;
|
|
18
33
|
};
|
|
19
|
-
export declare const ReplaceFragment:
|
|
34
|
+
export declare const ReplaceFragment: React.FC<ReplaceFragmentPropsType>;
|
|
20
35
|
export declare function registerReplacer(replacerName: string, Replacer: ReactComponent<any>): void;
|
|
21
|
-
export declare
|
|
36
|
+
export declare const registerPluginsAppStates: PluginAppStatesRegisterFunction;
|
|
37
|
+
export declare const loadPluginComponent: (name: string) => LoadableComponent<any> | undefined;
|
|
38
|
+
export declare const pluginPageAppState: (page: string) => string | false;
|
|
39
|
+
export declare const getPluginsPageAppStates: () => Readonly<typeof PluginsPageAppStates>;
|
|
40
|
+
export declare const getPluginsStoreReducers: () => Readonly<typeof pluginsStoreReducers>;
|
|
41
|
+
export declare const getPluginsStoreSagas: () => Readonly<typeof pluginsStoreSagas>;
|
|
42
|
+
export declare function RunActionAnchor(anchor: string, ...args: any[]): void;
|
|
43
|
+
export declare function RunOverrideActionAnchor(action: Action): Action<any>;
|
|
44
|
+
export declare const loadPlugins: (plugins?: Record<string, string>) => Promise<void>;
|
|
45
|
+
export declare const pluginsLoaded: () => boolean;
|
|
46
|
+
export declare const getPluginsAdditionalRoutes: () => Record<string, ReactComponent<any>>;
|
|
22
47
|
export declare function getPluginsReducers(): Record<string, Reducer<Record<string, any>, any>>;
|
|
23
|
-
export declare function
|
|
24
|
-
export declare
|
|
25
|
-
export declare function clearPlugins(): void;
|
|
26
|
-
export declare const RunActionAnchor: () => void;
|
|
27
|
-
export declare const RunOverrideActionAnchor: () => void;
|
|
28
|
-
export declare const registerPluginsAppStates: (appStates: any) => any;
|
|
29
|
-
export declare const getPluginsStoreReducers: typeof getPluginsReducers;
|
|
30
|
-
export declare const getPluginsStoreSagas: typeof getPluginsSagas;
|
|
48
|
+
export declare function getPluginsSagas(): Record<string, Saga[]>;
|
|
49
|
+
export declare const clearPlugins: () => void;
|
|
31
50
|
export {};
|
package/dist/PluginLoader.js
CHANGED
|
@@ -1,209 +1,262 @@
|
|
|
1
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
11
|
import React from "react";
|
|
3
12
|
import { getStore } from "./redux/store";
|
|
13
|
+
import { getHistory } from "./redux/routerHistory";
|
|
14
|
+
import { getConfig } from "./config";
|
|
4
15
|
import Globals from "./Globals";
|
|
16
|
+
import { INIT_PLUGINS } from "./redux/constants/app";
|
|
17
|
+
let globalAnchors = {};
|
|
18
|
+
let reduxAnchors = {};
|
|
19
|
+
let actionOverrideAnchor = {};
|
|
20
|
+
let replacers = {};
|
|
5
21
|
let pluginsStoreReducers = {};
|
|
6
|
-
|
|
7
|
-
|
|
22
|
+
const pluginsStoreSagas = {};
|
|
23
|
+
let cache = {};
|
|
24
|
+
let pluginsLoadingDone = false;
|
|
25
|
+
let PluginsAppStatesRegistrers = [];
|
|
26
|
+
let PluginsPageAppStates = {};
|
|
27
|
+
let PluginsAppStatesComponents = {};
|
|
28
|
+
let PluginAdditionRoutes = {};
|
|
8
29
|
export const PluginLoader = (props) => {
|
|
9
30
|
const { anchor } = props;
|
|
10
|
-
const
|
|
31
|
+
const anchorsList = !Array.isArray(anchor) ? [anchor] : anchor;
|
|
11
32
|
let Plugins = [];
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
33
|
+
for (let i = 0; i < anchorsList.length; i += 1) {
|
|
34
|
+
const currentAnchor = anchorsList[i];
|
|
35
|
+
if (Object.prototype.hasOwnProperty.call(globalAnchors, currentAnchor) &&
|
|
36
|
+
globalAnchors[currentAnchor].length > 0) {
|
|
37
|
+
const currentPlugins = globalAnchors[currentAnchor];
|
|
38
|
+
Plugins = [
|
|
39
|
+
...Plugins,
|
|
40
|
+
...currentPlugins.map((Plugin) => (_jsx(React.Suspense, { fallback: null, children: _jsx(Plugin, Object.assign({}, props.props)) }, `lpwp-${currentAnchor}-${Math.random()}`))),
|
|
41
|
+
];
|
|
21
42
|
}
|
|
22
|
-
return true;
|
|
23
|
-
});
|
|
24
|
-
if (matchedPlugins.length > 0) {
|
|
25
|
-
Plugins = matchedPlugins.map((p, i) => (_jsx(p.component, Object.assign({}, (props.props || {})), i)));
|
|
26
43
|
}
|
|
27
|
-
|
|
44
|
+
if (Plugins.length > 0) {
|
|
45
|
+
return _jsx(_Fragment, { children: Plugins });
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
28
48
|
};
|
|
29
49
|
export function replaceComponent(replacerName, OriginalComponent, componentName) {
|
|
50
|
+
const displayName = componentName ||
|
|
51
|
+
OriginalComponent.displayName ||
|
|
52
|
+
OriginalComponent.name ||
|
|
53
|
+
"Component";
|
|
54
|
+
const anchorsList = !Array.isArray(replacerName)
|
|
55
|
+
? [replacerName]
|
|
56
|
+
: replacerName;
|
|
30
57
|
let Replacer = null;
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
if (replacers[r])
|
|
35
|
-
Replacer = r;
|
|
36
|
-
});
|
|
58
|
+
const cacheKey = anchorsList.reduce((a, b) => a + b) + OriginalComponent.toString();
|
|
59
|
+
if (Object.prototype.hasOwnProperty.call(cache, cacheKey)) {
|
|
60
|
+
return cache[cacheKey];
|
|
37
61
|
}
|
|
38
|
-
|
|
39
|
-
|
|
62
|
+
for (let i = 0; i < anchorsList.length; i += 1) {
|
|
63
|
+
const currentAnchor = anchorsList[i];
|
|
64
|
+
if (Object.prototype.hasOwnProperty.call(replacers, currentAnchor)) {
|
|
65
|
+
Replacer = currentAnchor;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
40
68
|
}
|
|
69
|
+
let FinalComponent;
|
|
41
70
|
if (Replacer !== null) {
|
|
42
|
-
const BaseComponent = (props) => (
|
|
71
|
+
const BaseComponent = (props) => React.createElement(OriginalComponent, props, props.children);
|
|
43
72
|
const FinalReplacedComponent = replacers[Replacer].reduce((PreviousReplacer, CurrentReplacer) => {
|
|
44
73
|
const ReplacedComponent = (props) => (_jsx(React.Suspense, { fallback: null, children: _jsx(CurrentReplacer, Object.assign({}, props, { OriginalComponent: PreviousReplacer, children: props.children })) }));
|
|
45
74
|
return ReplacedComponent;
|
|
46
75
|
}, BaseComponent);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
76
|
+
FinalComponent = FinalReplacedComponent;
|
|
77
|
+
FinalComponent.displayName = `replacedComponent(${displayName})`;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
FinalComponent = OriginalComponent;
|
|
81
|
+
FinalComponent.displayName = `originalComponent(${displayName})`;
|
|
51
82
|
}
|
|
52
|
-
|
|
83
|
+
cache[cacheKey] = React.memo(FinalComponent);
|
|
84
|
+
return cache[cacheKey];
|
|
53
85
|
}
|
|
54
86
|
export const ReplaceFragment = ({ replacerName, fragmentName, children, }) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (replacers[r])
|
|
59
|
-
Replacer = r;
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
else if (replacers[replacerName]) {
|
|
63
|
-
Replacer = replacerName;
|
|
64
|
-
}
|
|
65
|
-
if (Replacer !== null) {
|
|
66
|
-
const Fragment = (props) => _jsx(_Fragment, { children: props.children });
|
|
67
|
-
const FinalReplacedComponent = replacers[Replacer].reduce((PreviousReplacer, CurrentReplacer) => {
|
|
68
|
-
const ReplacedComponent = (props) => (_jsx(React.Suspense, { fallback: null, children: _jsx(CurrentReplacer, Object.assign({}, props, { OriginalComponent: PreviousReplacer, children: props.children })) }));
|
|
69
|
-
return ReplacedComponent;
|
|
70
|
-
}, Fragment);
|
|
71
|
-
if (fragmentName) {
|
|
72
|
-
FinalReplacedComponent.displayName = `Replaced(${fragmentName})`;
|
|
73
|
-
}
|
|
74
|
-
return _jsx(FinalReplacedComponent, { children: children });
|
|
75
|
-
}
|
|
76
|
-
return _jsx(_Fragment, { children: children });
|
|
87
|
+
const Fragment = () => _jsx(_Fragment, { children: children });
|
|
88
|
+
const FinalFragment = replaceComponent(replacerName, Fragment, `Fragment::${fragmentName}`);
|
|
89
|
+
return _jsx(FinalFragment, {});
|
|
77
90
|
};
|
|
78
91
|
export function registerReplacer(replacerName, Replacer) {
|
|
79
92
|
if (!replacers[replacerName])
|
|
80
93
|
replacers[replacerName] = [];
|
|
81
94
|
replacers[replacerName].push(Replacer);
|
|
82
95
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
96
|
+
const pluginAppStates = (declaration) => {
|
|
97
|
+
PluginsAppStatesRegistrers.push(declaration.register);
|
|
98
|
+
if (typeof declaration.pageAppState === "object")
|
|
99
|
+
Object.keys(declaration.pageAppState).forEach((appState) => {
|
|
100
|
+
if (typeof declaration.pageAppState[appState] === "string") {
|
|
101
|
+
const page = declaration.pageAppState[appState];
|
|
102
|
+
if (Object.prototype.hasOwnProperty.call(PluginsPageAppStates, appState)) {
|
|
103
|
+
throw new Error(`Plugins AppState "${appState}" already declared.`);
|
|
104
|
+
}
|
|
105
|
+
const samePageAppStates = Object.keys(PluginsPageAppStates).filter((currentAppState) => PluginsPageAppStates[currentAppState] === page);
|
|
106
|
+
if (samePageAppStates.length > 0)
|
|
107
|
+
throw new Error(`Plugins AppState page "${page}" already declared.`);
|
|
108
|
+
PluginsPageAppStates[appState] = page;
|
|
95
109
|
}
|
|
96
|
-
|
|
97
|
-
|
|
110
|
+
});
|
|
111
|
+
Object.keys(declaration.components).forEach((appState) => {
|
|
112
|
+
if (Object.prototype.hasOwnProperty.call(declaration, appState) === true)
|
|
113
|
+
throw new Error(`Plugin's appState ${appState} already declared previously`);
|
|
114
|
+
PluginsAppStatesComponents[appState] = declaration.components[appState];
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
export const registerPluginsAppStates = (currentAppStates) => {
|
|
118
|
+
let appStates = [...currentAppStates];
|
|
119
|
+
PluginsAppStatesRegistrers.forEach((register) => {
|
|
120
|
+
appStates = register(appStates);
|
|
121
|
+
});
|
|
122
|
+
return appStates;
|
|
123
|
+
};
|
|
124
|
+
export const loadPluginComponent = (name) => {
|
|
125
|
+
if (Object.prototype.hasOwnProperty.call(PluginsAppStatesComponents, name) ===
|
|
126
|
+
false) {
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
return PluginsAppStatesComponents[name];
|
|
130
|
+
};
|
|
131
|
+
export const pluginPageAppState = (page) => {
|
|
132
|
+
const appStates = Object.keys(PluginsPageAppStates).filter((appState) => PluginsPageAppStates[appState] === page);
|
|
133
|
+
if (appStates.length === 1)
|
|
134
|
+
return appStates[0];
|
|
135
|
+
if (appStates.length > 1)
|
|
136
|
+
throw new Error("Found multipled appStates when checking for plugins page name");
|
|
137
|
+
return false;
|
|
138
|
+
};
|
|
139
|
+
export const getPluginsPageAppStates = () => PluginsPageAppStates;
|
|
140
|
+
export const getPluginsStoreReducers = () => pluginsStoreReducers;
|
|
141
|
+
export const getPluginsStoreSagas = () => pluginsStoreSagas;
|
|
142
|
+
export function RunActionAnchor(anchor, ...args) {
|
|
143
|
+
if (Object.prototype.hasOwnProperty.call(reduxAnchors, anchor) &&
|
|
144
|
+
reduxAnchors[anchor].length > 0) {
|
|
145
|
+
reduxAnchors[anchor].forEach((currentFn) => {
|
|
146
|
+
currentFn.call(null, ...args);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export function RunOverrideActionAnchor(action) {
|
|
151
|
+
let overridedAction = action;
|
|
152
|
+
if (Object.prototype.hasOwnProperty.call(actionOverrideAnchor, action.type) &&
|
|
153
|
+
actionOverrideAnchor[action.type].length > 0) {
|
|
154
|
+
actionOverrideAnchor[action.type].forEach((currentFn) => {
|
|
155
|
+
overridedAction = currentFn.call(null, overridedAction);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return overridedAction;
|
|
159
|
+
}
|
|
160
|
+
const loadPluginFiles = (pluginsList) => __awaiter(void 0, void 0, void 0, function* () {
|
|
161
|
+
const plugins = Object.keys(pluginsList);
|
|
162
|
+
const pluginModules = yield Promise.all(plugins.map((plugin) => Globals.loadPlugin(plugin)));
|
|
163
|
+
plugins.forEach((plugin, index) => {
|
|
164
|
+
const pluginModule = pluginModules[index];
|
|
165
|
+
const anchors = pluginModule.default;
|
|
166
|
+
const { loader } = pluginModule;
|
|
167
|
+
if (loader !== undefined) {
|
|
168
|
+
loader(getStore().dispatch, getHistory(), getConfig());
|
|
169
|
+
}
|
|
170
|
+
Object.keys(anchors).forEach((anchor) => {
|
|
171
|
+
if (anchor === "replace") {
|
|
172
|
+
Object.keys(anchors[anchor]).forEach((replacer) => {
|
|
173
|
+
if (!Object.prototype.hasOwnProperty.call(replacers, replacer)) {
|
|
174
|
+
replacers[replacer] = [];
|
|
175
|
+
}
|
|
176
|
+
replacers[replacer].push(anchors[anchor][replacer]);
|
|
177
|
+
});
|
|
98
178
|
return;
|
|
99
179
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
pluginPromise = Promise.resolve(pluginValue());
|
|
180
|
+
if (anchor === "appstates") {
|
|
181
|
+
pluginAppStates(anchors.appstates);
|
|
104
182
|
}
|
|
105
|
-
|
|
106
|
-
|
|
183
|
+
if (anchor === "redux") {
|
|
184
|
+
Object.keys(anchors[anchor]).forEach((action) => {
|
|
185
|
+
if (reduxAnchors[action] === undefined)
|
|
186
|
+
reduxAnchors[action] = [];
|
|
187
|
+
reduxAnchors[action].push(anchors[anchor][action]);
|
|
188
|
+
});
|
|
107
189
|
return;
|
|
108
190
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
console.warn(`Plugin "${key}" has invalid format, skipping...`);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
promises.push(pluginPromise.then((plugin) => {
|
|
121
|
-
if (!plugin)
|
|
191
|
+
if (anchor === "actionOverride") {
|
|
192
|
+
Object.keys(anchors[anchor]).forEach((action) => {
|
|
193
|
+
if (actionOverrideAnchor[action] === undefined)
|
|
194
|
+
actionOverrideAnchor[action] = [];
|
|
195
|
+
actionOverrideAnchor[action].push(anchors[anchor][action]);
|
|
196
|
+
});
|
|
122
197
|
return;
|
|
123
|
-
if (plugin.redux) {
|
|
124
|
-
pluginsStoreReducers = Object.assign(Object.assign({}, pluginsStoreReducers), { [key]: plugin.redux.reducer });
|
|
125
|
-
pluginsSagas = [...pluginsSagas, ...plugin.redux.sagas];
|
|
126
|
-
}
|
|
127
|
-
if (plugin.reduxStore) {
|
|
128
|
-
pluginsStoreReducers = Object.assign(Object.assign({}, pluginsStoreReducers), { [key]: plugin.reduxStore.reducer });
|
|
129
|
-
if (plugin.reduxStore.sagas) {
|
|
130
|
-
pluginsSagas = [...pluginsSagas, ...plugin.reduxStore.sagas];
|
|
131
|
-
}
|
|
132
198
|
}
|
|
133
|
-
if (
|
|
134
|
-
Object.keys(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
199
|
+
if (anchor === "additionalRoutes") {
|
|
200
|
+
Object.keys(anchors[anchor]).forEach((route) => {
|
|
201
|
+
PluginAdditionRoutes[anchors[anchor][route].path] =
|
|
202
|
+
anchors[anchor][route].component;
|
|
138
203
|
});
|
|
204
|
+
return;
|
|
139
205
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
configs.push(...plugin.config);
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
Object.keys(plugin).forEach((prop) => {
|
|
146
|
-
if (["redux", "reduxStore", "replace", "config", "appstates", "actionOverride", "additionalRoutes", "paginationAfterNext"].includes(prop)) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
const value = plugin[prop];
|
|
150
|
-
if (value && (typeof value === "function" || (typeof value === "object" && (value.$$typeof || value._payload)))) {
|
|
151
|
-
configs.push({
|
|
152
|
-
anchor: [prop],
|
|
153
|
-
component: value,
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
});
|
|
206
|
+
if (anchor === "reduxStore" && anchors[anchor].reducer) {
|
|
207
|
+
pluginsStoreReducers[plugin] = anchors[anchor].reducer;
|
|
157
208
|
}
|
|
158
|
-
if (
|
|
159
|
-
|
|
160
|
-
const existingConfig = currentState.config || [];
|
|
161
|
-
store.dispatch({
|
|
162
|
-
type: "@@PLUGIN/ADD_CONFIG",
|
|
163
|
-
payload: {
|
|
164
|
-
config: [...existingConfig, ...configs],
|
|
165
|
-
},
|
|
166
|
-
});
|
|
209
|
+
if (anchor === "reduxStore" && anchors[anchor].sagas) {
|
|
210
|
+
pluginsStoreSagas[plugin] = anchors[anchor].sagas;
|
|
167
211
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
212
|
+
if (!Object.prototype.hasOwnProperty.call(globalAnchors, anchor))
|
|
213
|
+
globalAnchors[anchor] = [];
|
|
214
|
+
globalAnchors[anchor].push(anchors[anchor]);
|
|
215
|
+
});
|
|
216
|
+
if (anchors.redux && anchors.redux.reducer) {
|
|
217
|
+
pluginsStoreReducers[plugin] = anchors.redux.reducer;
|
|
218
|
+
}
|
|
219
|
+
if (anchors.redux && anchors.redux.sagas) {
|
|
220
|
+
pluginsStoreSagas[plugin] = anchors.redux.sagas;
|
|
221
|
+
}
|
|
222
|
+
if (typeof anchors.onLoad === "function")
|
|
223
|
+
anchors.onLoad();
|
|
171
224
|
});
|
|
172
|
-
|
|
173
|
-
|
|
225
|
+
if (Object.keys(pluginsStoreReducers).length > 0 ||
|
|
226
|
+
Object.keys(pluginsStoreSagas).length > 0) {
|
|
227
|
+
getStore().dispatch({ type: INIT_PLUGINS });
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
export const loadPlugins = (plugins) => __awaiter(void 0, void 0, void 0, function* () {
|
|
231
|
+
let pluginsList;
|
|
232
|
+
if (!plugins)
|
|
233
|
+
pluginsList = getConfig().plugins;
|
|
234
|
+
else
|
|
235
|
+
pluginsList = plugins;
|
|
236
|
+
if (pluginsList === undefined) {
|
|
237
|
+
pluginsList = getConfig().plugins;
|
|
238
|
+
}
|
|
239
|
+
yield loadPluginFiles(pluginsList);
|
|
240
|
+
pluginsLoadingDone = true;
|
|
241
|
+
});
|
|
242
|
+
export const pluginsLoaded = () => pluginsLoadingDone;
|
|
243
|
+
export const getPluginsAdditionalRoutes = () => PluginAdditionRoutes;
|
|
174
244
|
export function getPluginsReducers() {
|
|
175
245
|
return pluginsStoreReducers;
|
|
176
246
|
}
|
|
177
|
-
export function getPluginsAdditionalRoutes() {
|
|
178
|
-
const routes = [];
|
|
179
|
-
const plugins = getStore().getState().pluginsStore;
|
|
180
|
-
if ((plugins === null || plugins === void 0 ? void 0 : plugins.config) && Array.isArray(plugins.config)) {
|
|
181
|
-
plugins.config.forEach((p) => {
|
|
182
|
-
if (p.anchor[0] === "routes") {
|
|
183
|
-
routes.push(p);
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
return routes;
|
|
188
|
-
}
|
|
189
247
|
export function getPluginsSagas() {
|
|
190
|
-
return
|
|
248
|
+
return pluginsStoreSagas;
|
|
191
249
|
}
|
|
192
|
-
export
|
|
250
|
+
export const clearPlugins = () => {
|
|
251
|
+
globalAnchors = {};
|
|
252
|
+
reduxAnchors = {};
|
|
253
|
+
actionOverrideAnchor = {};
|
|
254
|
+
replacers = {};
|
|
255
|
+
PluginsAppStatesRegistrers = [];
|
|
256
|
+
PluginsPageAppStates = {};
|
|
257
|
+
PluginsAppStatesComponents = {};
|
|
258
|
+
PluginAdditionRoutes = {};
|
|
259
|
+
cache = {};
|
|
260
|
+
pluginsLoadingDone = false;
|
|
193
261
|
pluginsStoreReducers = {};
|
|
194
|
-
|
|
195
|
-
const store = getStore(false);
|
|
196
|
-
if (store) {
|
|
197
|
-
store.dispatch({
|
|
198
|
-
type: "@@PLUGIN/ADD_CONFIG",
|
|
199
|
-
payload: {
|
|
200
|
-
config: [],
|
|
201
|
-
},
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
export const RunActionAnchor = () => { };
|
|
206
|
-
export const RunOverrideActionAnchor = () => { };
|
|
207
|
-
export const registerPluginsAppStates = (appStates) => appStates || [];
|
|
208
|
-
export const getPluginsStoreReducers = getPluginsReducers;
|
|
209
|
-
export const getPluginsStoreSagas = getPluginsSagas;
|
|
262
|
+
};
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import { RunActionAnchor, RunOverrideActionAnchor } from "../../PluginLoader";
|
|
1
2
|
const pluginsHookMiddleware = (mpi) => (next) => (action) => {
|
|
2
|
-
|
|
3
|
+
const overridedAction = RunOverrideActionAnchor(action);
|
|
4
|
+
const result = next(overridedAction);
|
|
5
|
+
RunActionAnchor(overridedAction.type, overridedAction, mpi.getState());
|
|
6
|
+
return result;
|
|
3
7
|
};
|
|
4
8
|
export default pluginsHookMiddleware;
|