@legalplace/wizardx-core 4.42.10-nightly.20251125115613 → 4.42.10-nightly.20251125123510

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.
@@ -17,9 +17,11 @@ export interface WizardCoreProps {
17
17
  routing?: IWizardCoreRouterProps;
18
18
  }
19
19
  declare class WizardCore extends React.Component<WizardCoreProps> {
20
+ private storeInitialized;
20
21
  constructor(props: WizardCoreProps);
21
22
  componentDidMount(): void;
22
23
  componentWillUnmount(): void;
23
- render(): import("react/jsx-runtime").JSX.Element;
24
+ private initializeStore;
25
+ render(): import("react/jsx-runtime").JSX.Element | null;
24
26
  }
25
27
  export default WizardCore;
@@ -18,7 +18,6 @@ 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
20
  const getRouteComponent = (pathname, params) => {
21
- const config = getConfig();
22
21
  if (pathname.startsWith("/p/")) {
23
22
  const pluginPath = params.path || pathname.replace("/p/", "");
24
23
  return {
@@ -40,18 +39,55 @@ const RedirectHandler = ({ navigate, }) => {
40
39
  React.useEffect(() => {
41
40
  const matchedPartner = Object.keys(externalPartnerRedirectUrl).find((partner) => window.location.origin.toLowerCase().includes(partner));
42
41
  if (matchedPartner) {
43
- window.location.href = externalPartnerRedirectUrl[matchedPartner];
42
+ navigate === null || navigate === void 0 ? void 0 : navigate(externalPartnerRedirectUrl[matchedPartner]);
44
43
  }
45
44
  else {
46
- window.location.href = NOT_FOUND_PAGE_LINK;
45
+ navigate === null || navigate === void 0 ? void 0 : navigate(NOT_FOUND_PAGE_LINK);
47
46
  }
48
- }, []);
47
+ }, [navigate]);
49
48
  return null;
50
49
  };
51
50
  class WizardCore extends React.Component {
52
51
  constructor(props) {
53
- var _a;
54
52
  super(props);
53
+ this.storeInitialized = false;
54
+ this.initializeStore(props);
55
+ }
56
+ componentDidMount() {
57
+ if (!this.storeInitialized) {
58
+ this.initializeStore(this.props);
59
+ }
60
+ setTimeout(() => {
61
+ try {
62
+ const { dispatch, getState } = getStore();
63
+ const state = getState();
64
+ let parent = null;
65
+ window.addEventListener("message", ({ data, source }) => {
66
+ if (parent === null || data.from === "BO") {
67
+ parent = source;
68
+ }
69
+ if (data.from && data.from === "BO") {
70
+ const { variables } = data;
71
+ autoSave(variables, getStore());
72
+ }
73
+ });
74
+ dispatch(callInitDataSmartscriptAction());
75
+ if (!PathReader.isSmartScriptPath()) {
76
+ dispatch(fetchModelPrerequisitesAction(getConfig().permalink || state.app.meta.permalink, getConfig().prefix || state.app.meta.prefix || ""));
77
+ }
78
+ }
79
+ catch (error) {
80
+ console.error("Error during component mount:", error);
81
+ }
82
+ }, 0);
83
+ }
84
+ componentWillUnmount() {
85
+ getStore().dispatch(resetStateAction());
86
+ }
87
+ initializeStore(props) {
88
+ var _a;
89
+ if (this.storeInitialized)
90
+ return;
55
91
  clearPlugins();
56
92
  const historyType = typeof props.historyType === "string" ? props.historyType : "browser";
57
93
  const params = Object.assign(Object.assign({}, Globals), { loadTheme: props.loadTheme, loadPlugin: props.loadPlugin });
@@ -72,48 +108,41 @@ class WizardCore extends React.Component {
72
108
  updateConfig(props.wizardParams);
73
109
  if (props.preloadTheme && ((_a = props.wizardParams) === null || _a === void 0 ? void 0 : _a.theme.name))
74
110
  preloadTheme(props.wizardParams.theme.name);
75
- createAppStore(historyType);
76
- }
77
- componentDidMount() {
78
- const { dispatch, getState } = getStore();
79
- const state = getState();
80
- let parent = null;
81
- window.addEventListener("message", ({ data, source }) => {
82
- if (parent === null || data.from === "BO") {
83
- parent = source;
84
- }
85
- if (data.from && data.from === "BO") {
86
- const { variables } = data;
87
- autoSave(variables, getStore());
88
- }
89
- });
90
- dispatch(callInitDataSmartscriptAction());
91
- if (!PathReader.isSmartScriptPath()) {
92
- dispatch(fetchModelPrerequisitesAction(getConfig().permalink || state.app.meta.permalink, getConfig().prefix || state.app.meta.prefix || ""));
111
+ try {
112
+ createAppStore(historyType);
113
+ this.storeInitialized = true;
114
+ }
115
+ catch (error) {
116
+ console.error("Failed to initialize store:", error);
93
117
  }
94
- }
95
- componentWillUnmount() {
96
- getStore().dispatch(resetStateAction());
97
118
  }
98
119
  render() {
120
+ if (!this.storeInitialized) {
121
+ return null;
122
+ }
99
123
  const { routerAdapter, routing } = this.props;
100
- if (routing) {
101
- const { pathname, params, navigate } = routing;
102
- const routeMatch = getRouteComponent(pathname, params);
103
- if (routeMatch) {
104
- const RouteComponent = routeMatch.component;
105
- return (_jsx(Provider, { store: getStore(), children: _jsx(RouteComponent, Object.assign({}, (routeMatch.props || {}))) }));
124
+ try {
125
+ const store = getStore();
126
+ if (routing) {
127
+ const { pathname, params, navigate } = routing;
128
+ const routeMatch = getRouteComponent(pathname, params);
129
+ if (routeMatch) {
130
+ const RouteComponent = routeMatch.component;
131
+ return (_jsx(Provider, { store: store, children: _jsx(RouteComponent, Object.assign({}, (routeMatch.props || {}))) }));
132
+ }
133
+ return (_jsx(Provider, { store: store, children: _jsx(RedirectHandler, { navigate: navigate }) }));
106
134
  }
107
- return (_jsx(Provider, { store: getStore(), children: _jsx(RedirectHandler, { navigate: navigate }) }));
135
+ if (routerAdapter) {
136
+ return (_jsx(Provider, { store: store, children: _jsx(RouterProvider, { adapter: routerAdapter, children: _jsx(WizardCoreContent, {}) }) }));
137
+ }
138
+ console.warn("WizardCore: No routing mechanism provided. Pass either 'routerAdapter' or 'routing' props.");
139
+ return (_jsx(Provider, { store: store, children: _jsx("div", { children: "No routing configured" }) }));
108
140
  }
109
- if (routerAdapter) {
110
- return (_jsx(Provider, { store: getStore(), children: _jsx(RouterProvider, { adapter: routerAdapter, children: _jsx(WizardCoreContent, {}) }) }));
141
+ catch (error) {
142
+ console.error("Error rendering WizardCore:", error);
143
+ return _jsx("div", { children: "Error initializing wizard. Check console for details." });
111
144
  }
112
- console.warn("WizardCore: No routing mechanism provided. Pass either 'routerAdapter' or 'routing' props.");
113
- return (_jsx(Provider, { store: getStore(), children: _jsx("div", { children: "No routing configured" }) }));
114
145
  }
115
146
  }
116
- const WizardCoreContent = () => {
117
- return _jsx(ViewComponent, {});
118
- };
147
+ const WizardCoreContent = () => (_jsx(ViewComponent, {}));
119
148
  export default WizardCore;
@@ -1,6 +1,8 @@
1
1
  import type { Store } from "redux";
2
2
  import type { StateType } from "../types/State.type";
3
- export declare const createAppStore: (historyType?: "browser" | "memory") => void;
3
+ export declare const createAppStore: (historyType?: "browser" | "memory") => Store<StateType, any> & {
4
+ dispatch: unknown;
5
+ };
4
6
  export declare const getStore: (throwIfDoesNotExist?: boolean) => Store<StateType, any> & {
5
7
  dispatch: unknown;
6
8
  };
@@ -28,7 +28,7 @@ let store;
28
28
  export const createAppStore = (historyType = "browser") => {
29
29
  if (store !== undefined) {
30
30
  createHistory(historyType);
31
- return;
31
+ return store;
32
32
  }
33
33
  const history = createHistory(historyType);
34
34
  const wizardxReducers = combineReducers({
@@ -50,6 +50,7 @@ export const createAppStore = (historyType = "browser") => {
50
50
  store = createStore(wizardxReducers, middlewares);
51
51
  sagasRunner(sagaMiddleware);
52
52
  subscribeListeners(store);
53
+ return store;
53
54
  };
54
55
  export const getStore = (throwIfDoesNotExist = true) => {
55
56
  if (store === undefined && throwIfDoesNotExist)
@@ -21,12 +21,10 @@ export const createNextJSAdapter = (router, pathname, searchParams, params) => {
21
21
  }, [params]);
22
22
  return {
23
23
  useParams: () => normalizedParams,
24
- useNavigate: () => {
25
- return (path) => {
26
- if (router === null || router === void 0 ? void 0 : router.push) {
27
- router.push(path);
28
- }
29
- };
24
+ useNavigate: () => (path) => {
25
+ if (router === null || router === void 0 ? void 0 : router.push) {
26
+ router.push(path);
27
+ }
30
28
  },
31
29
  useLocation: () => ({
32
30
  pathname,
@@ -1,19 +1,16 @@
1
- import { useParams as useParamsRR, useHistory, useLocation as useLocationRR, } from "react-router-dom";
2
- import { Link as LinkRR } from "react-router-dom";
3
- export const createReactRouterAdapter = () => {
4
- return {
5
- useParams: () => useParamsRR(),
6
- useNavigate: () => {
7
- const history = useHistory();
8
- return (path) => history.push(path);
9
- },
10
- useLocation: () => {
11
- const location = useLocationRR();
12
- return {
13
- pathname: location.pathname,
14
- search: location.search,
15
- };
16
- },
17
- Link: LinkRR,
18
- };
19
- };
1
+ import { useParams as useParamsRR, useHistory, useLocation as useLocationRR, Link as LinkRR, } from "react-router-dom";
2
+ export const createReactRouterAdapter = () => ({
3
+ useParams: () => useParamsRR(),
4
+ useNavigate: () => {
5
+ const history = useHistory();
6
+ return (path) => history.push(path);
7
+ },
8
+ useLocation: () => {
9
+ const location = useLocationRR();
10
+ return {
11
+ pathname: location.pathname,
12
+ search: location.search,
13
+ };
14
+ },
15
+ Link: LinkRR,
16
+ });
@@ -1,9 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { createContext, useContext } from "react";
3
3
  const RouterContext = createContext(null);
4
- export const RouterProvider = ({ adapter, children, }) => {
5
- return (_jsx(RouterContext.Provider, { value: adapter, children: children }));
6
- };
4
+ export const RouterProvider = ({ adapter, children, }) => (_jsx(RouterContext.Provider, { value: adapter, children: children }));
7
5
  export const useRouterAdapter = () => {
8
6
  const adapter = useContext(RouterContext);
9
7
  if (!adapter) {
@@ -1,4 +1,4 @@
1
1
  export * from "./types";
2
2
  export * from "./context";
3
3
  export { createReactRouterAdapter } from "./adapters/reactRouter.adapter";
4
- export { createNextJSAdapter, useNextJSAdapter } from "./adapters/nextjs.adapter";
4
+ export { createNextJSAdapter, useNextJSAdapter, } from "./adapters/nextjs.adapter";
@@ -1,4 +1,4 @@
1
1
  export * from "./types";
2
2
  export * from "./context";
3
3
  export { createReactRouterAdapter } from "./adapters/reactRouter.adapter";
4
- export { createNextJSAdapter, useNextJSAdapter } from "./adapters/nextjs.adapter";
4
+ export { createNextJSAdapter, useNextJSAdapter, } from "./adapters/nextjs.adapter";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/wizardx-core",
3
- "version": "4.42.10-nightly.20251125115613",
3
+ "version": "4.42.10-nightly.20251125123510",
4
4
  "author": "Moncef Hammou (moncef@legalplace.fr)",
5
5
  "license": "MIT",
6
6
  "files": [