@legalplace/wizardx-core 4.42.10-nightly.20251125160329 → 4.42.10-nightly.20251125160911

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/App.js CHANGED
@@ -77,7 +77,7 @@ class WizardXCore extends React.Component {
77
77
  getStore().dispatch(resetStateAction());
78
78
  }
79
79
  render() {
80
- return (_jsxs(Provider, { store: getStore(), children: [_jsx("h1", { children: "IAM APP" }), _jsx(ConnectedRouter, { history: getHistory(), children: _jsxs(Switch, { children: [_jsx(Route, { path: "/p/:path", component: PluginRoute }), _jsx(Route, { path: getConfig().router.smartscriptPath, exact: true, strict: true, component: SmartScriptComponent }), _jsx(Route, { path: getConfig().router.wizardInstancePath, component: ViewComponent }), _jsx(Route, { path: getConfig().router.wizardPath, component: ViewComponent }), !window.location.href.includes("smartscript") && (_jsx(Route, { component: RedirectHandler }))] }) })] }));
80
+ return (_jsx(Provider, { store: getStore(), children: _jsx(ConnectedRouter, { history: getHistory(), children: _jsxs(Switch, { children: [_jsx(Route, { path: "/p/:path", component: PluginRoute }), _jsx(Route, { path: getConfig().router.smartscriptPath, exact: true, strict: true, component: SmartScriptComponent }), _jsx(Route, { path: getConfig().router.wizardInstancePath, component: ViewComponent }), _jsx(Route, { path: getConfig().router.wizardPath, component: ViewComponent }), !window.location.href.includes("smartscript") && (_jsx(Route, { component: RedirectHandler }))] }) }) }));
81
81
  }
82
82
  }
83
83
  export default WizardXCore;
@@ -18,7 +18,7 @@ export type ReplaceFragmentPropsType = {
18
18
  };
19
19
  export declare const ReplaceFragment: ({ replacerName, fragmentName, children, }: ReplaceFragmentPropsType) => import("react/jsx-runtime").JSX.Element;
20
20
  export declare function registerReplacer(replacerName: string, Replacer: ReactComponent<any>): void;
21
- export declare function loadPlugins(plugins?: Record<string, () => Promise<IPlugin>>): Promise<any>;
21
+ export declare function loadPlugins(plugins?: Record<string, (() => Promise<IPlugin>) | Promise<IPlugin> | IPlugin>): Promise<any>;
22
22
  export declare function getPluginsReducers(): Record<string, Reducer<Record<string, any>, any>>;
23
23
  export declare function getPluginsAdditionalRoutes(): IPluginConfig[];
24
24
  export declare function getPluginsSagas(): Saga[];
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
2
  import React from "react";
3
3
  import { getStore } from "./redux/store";
4
4
  let pluginsStoreReducers = {};
@@ -8,6 +8,9 @@ export const PluginLoader = (props) => {
8
8
  const { anchor } = props;
9
9
  const plugins = getStore().getState().pluginsStore;
10
10
  let Plugins = [];
11
+ if (!plugins || !plugins.config || !Array.isArray(plugins.config)) {
12
+ return _jsx(_Fragment, {});
13
+ }
11
14
  const matchedPlugins = plugins.config.filter((p) => {
12
15
  if (p.anchor.length !== anchor.length)
13
16
  return false;
@@ -83,16 +86,44 @@ export function loadPlugins(plugins) {
83
86
  }
84
87
  const store = getStore();
85
88
  Object.keys(plugins).forEach((key) => {
86
- const pluginLoader = plugins[key];
87
- if (typeof pluginLoader !== "function") {
88
- console.warn(`Plugin "${key}" loader is not a function, skipping...`);
89
+ const pluginValue = plugins[key];
90
+ let pluginPromise;
91
+ if (typeof pluginValue === "function") {
92
+ try {
93
+ pluginPromise = Promise.resolve(pluginValue());
94
+ }
95
+ catch (error) {
96
+ console.error(`Failed to execute plugin "${key}" loader:`, error);
97
+ return;
98
+ }
99
+ }
100
+ else if (pluginValue && typeof pluginValue === "object" && "then" in pluginValue) {
101
+ pluginPromise = pluginValue;
102
+ }
103
+ else if (pluginValue && typeof pluginValue === "object") {
104
+ pluginPromise = Promise.resolve(pluginValue);
105
+ }
106
+ else {
107
+ console.warn(`Plugin "${key}" has invalid format, skipping...`);
89
108
  return;
90
109
  }
91
- promises.push(pluginLoader().then((plugin) => {
110
+ promises.push(pluginPromise.then((plugin) => {
111
+ if (!plugin)
112
+ return;
92
113
  if (plugin.redux) {
93
114
  pluginsStoreReducers = Object.assign(Object.assign({}, pluginsStoreReducers), { [key]: plugin.redux.reducer });
94
115
  pluginsSagas = [...pluginsSagas, ...plugin.redux.sagas];
95
116
  }
117
+ if (plugin.config && Array.isArray(plugin.config)) {
118
+ const currentState = store.getState().pluginsStore;
119
+ const existingConfig = currentState.config || [];
120
+ store.dispatch({
121
+ type: "@@PLUGIN/ADD_CONFIG",
122
+ payload: {
123
+ config: [...existingConfig, ...plugin.config],
124
+ },
125
+ });
126
+ }
96
127
  }).catch((error) => {
97
128
  console.error(`Failed to load plugin "${key}":`, error);
98
129
  }));
@@ -105,11 +136,13 @@ export function getPluginsReducers() {
105
136
  export function getPluginsAdditionalRoutes() {
106
137
  const routes = [];
107
138
  const plugins = getStore().getState().pluginsStore;
108
- plugins.config.forEach((p) => {
109
- if (p.anchor[0] === "routes") {
110
- routes.push(p);
111
- }
112
- });
139
+ if ((plugins === null || plugins === void 0 ? void 0 : plugins.config) && Array.isArray(plugins.config)) {
140
+ plugins.config.forEach((p) => {
141
+ if (p.anchor[0] === "routes") {
142
+ routes.push(p);
143
+ }
144
+ });
145
+ }
113
146
  return routes;
114
147
  }
115
148
  export function getPluginsSagas() {
@@ -118,6 +151,15 @@ export function getPluginsSagas() {
118
151
  export function clearPlugins() {
119
152
  pluginsStoreReducers = {};
120
153
  pluginsSagas = [];
154
+ const store = getStore(false);
155
+ if (store) {
156
+ store.dispatch({
157
+ type: "@@PLUGIN/ADD_CONFIG",
158
+ payload: {
159
+ config: [],
160
+ },
161
+ });
162
+ }
121
163
  }
122
164
  export const RunActionAnchor = () => { };
123
165
  export const RunOverrideActionAnchor = () => { };
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from "react";
3
3
  import { Provider } from "react-redux";
4
4
  import { getStore, createAppStore } from "./redux/store";
@@ -17,6 +17,7 @@ import { externalPartnerRedirectUrl } from "./helpers/redirectionConfig";
17
17
  import { autoSave } from "./helpers/autosave.helper";
18
18
  import { NOT_FOUND_PAGE_LINK } from "./constants/links.constant";
19
19
  import { RouterProvider } from "./routing/context";
20
+ import { RouterSync } from "./routing/RouterSync";
20
21
  const getRouteComponent = (pathname, params) => {
21
22
  if (pathname.startsWith("/p/")) {
22
23
  const pluginPath = params.path || pathname.replace("/p/", "");
@@ -134,7 +135,7 @@ class WizardCore extends React.Component {
134
135
  return (_jsx(Provider, { store: store, children: _jsx(RedirectHandler, { navigate: navigate }) }));
135
136
  }
136
137
  if (routerAdapter) {
137
- return (_jsx(Provider, { store: store, children: _jsx(RouterProvider, { adapter: routerAdapter, children: _jsx(WizardCoreContent, {}) }) }));
138
+ return (_jsx(Provider, { store: store, children: _jsxs(RouterProvider, { adapter: routerAdapter, children: [_jsx(RouterSync, {}), _jsx(WizardCoreContent, {})] }) }));
138
139
  }
139
140
  console.warn("WizardCore: No routing mechanism provided. Pass either 'routerAdapter' or 'routing' props.");
140
141
  return (_jsx(Provider, { store: store, children: _jsx("div", { children: "No routing configured" }) }));
@@ -1,8 +1,14 @@
1
1
  import { getPluginsStoreReducers } from "../../PluginLoader";
2
2
  import { RESET_STATE } from "../constants/app";
3
- export const pluginsStoreReducer = (state = {}, action) => {
3
+ const initialState = {
4
+ config: [],
5
+ };
6
+ export const pluginsStoreReducer = (state = initialState, action) => {
4
7
  if (action.type === RESET_STATE)
5
- return {};
8
+ return initialState;
9
+ if (action.type === "@@PLUGIN/ADD_CONFIG") {
10
+ return Object.assign(Object.assign({}, state), { config: action.payload.config });
11
+ }
6
12
  const pluginsStoreReducers = getPluginsStoreReducers();
7
13
  const plugins = Object.keys(pluginsStoreReducers);
8
14
  const newState = Object.assign({}, state);
@@ -0,0 +1 @@
1
+ export declare const RouterSync: () => null;
@@ -0,0 +1,12 @@
1
+ import { useEffect } from "react";
2
+ import { useDispatch } from "react-redux";
3
+ import { useLocation } from "./context";
4
+ import { push } from "connected-react-router";
5
+ export const RouterSync = () => {
6
+ const location = useLocation();
7
+ const dispatch = useDispatch();
8
+ useEffect(() => {
9
+ dispatch(push(location.pathname + location.search));
10
+ }, [location.pathname, location.search, dispatch]);
11
+ return null;
12
+ };
@@ -271,5 +271,6 @@ export interface SmartScriptType {
271
271
  data?: object;
272
272
  }
273
273
  export interface PluginsStoreType {
274
- [key: string]: Record<string, any>;
274
+ config?: any[];
275
+ [key: string]: any;
275
276
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/wizardx-core",
3
- "version": "4.42.10-nightly.20251125160329",
3
+ "version": "4.42.10-nightly.20251125160911",
4
4
  "author": "Moncef Hammou (moncef@legalplace.fr)",
5
5
  "license": "MIT",
6
6
  "files": [