@legalplace/wizardx-core 4.43.21 → 4.44.1

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.
@@ -92,22 +92,24 @@ const SmartScriptComponent = ({ inpiActivities = [] }) => {
92
92
  window.triggerListeners = (type, id, inputs) => __awaiter(void 0, void 0, void 0, function* () {
93
93
  const hooks = SmartScriptStore.hooks[type === "option" ? "options" : "variables"];
94
94
  const listeners = hooks[id];
95
- if (Array.isArray(listeners)) {
95
+ if (Array.isArray(listeners) && listeners.length > 0) {
96
96
  SmartScriptStore.inputs = inputs;
97
- const promises = listeners.map((_cb) => __awaiter(void 0, void 0, void 0, function* () {
98
- try {
99
- if (typeof _cb === "function") {
97
+ const validListeners = listeners.filter((_cb) => typeof _cb === "function");
98
+ if (validListeners.length > 0) {
99
+ const promises = validListeners.map((_cb) => __awaiter(void 0, void 0, void 0, function* () {
100
+ try {
100
101
  return yield _cb();
101
102
  }
102
- console.warn("Invalid listener detected:", _cb);
103
- return Promise.resolve();
104
- }
105
- catch (e) {
106
- console.error("SmartScript (triggerListener) error:", e.message);
107
- return Promise.resolve();
108
- }
109
- }));
110
- yield Promise.all(promises);
103
+ catch (e) {
104
+ console.error("SmartScript (triggerListener) error:", e.message);
105
+ return Promise.resolve();
106
+ }
107
+ }));
108
+ yield Promise.all(promises);
109
+ }
110
+ else if (listeners.length > 0) {
111
+ console.warn("All listeners are invalid for", type, id);
112
+ }
111
113
  }
112
114
  return SmartScriptStore.grabActions();
113
115
  });
@@ -127,9 +127,13 @@ SmartScriptStore.updateVariableInput = (id, value, index = 0) => {
127
127
  return;
128
128
  }
129
129
  if (((_a = SmartScriptStore.inputs.variables[id]) === null || _a === void 0 ? void 0 : _a[indexValue]) !== value) {
130
- if (typeof SmartScriptStore.inputs.variables[id] === "undefined")
131
- SmartScriptStore.inputs.variables[id] = [];
132
- SmartScriptStore.inputs.variables[id][indexValue] = value;
130
+ const currentArray = SmartScriptStore.inputs.variables[id] || [];
131
+ const newArray = [
132
+ ...currentArray.slice(0, indexValue),
133
+ value,
134
+ ...currentArray.slice(indexValue + 1),
135
+ ];
136
+ SmartScriptStore.inputs.variables[id] = newArray;
133
137
  SmartScriptStore.actionsQueue.push(updateVariableAction(id, value, indexValue));
134
138
  }
135
139
  };
@@ -141,9 +145,13 @@ SmartScriptStore.updateOptionInput = (id, value, index = 0) => {
141
145
  return;
142
146
  }
143
147
  if (((_b = (_a = SmartScriptStore.inputs) === null || _a === void 0 ? void 0 : _a.options[id]) === null || _b === void 0 ? void 0 : _b[indexValue]) !== value) {
144
- if (typeof SmartScriptStore.inputs.options[id] === "undefined")
145
- SmartScriptStore.inputs.options[id] = [];
146
- SmartScriptStore.inputs.options[id][indexValue] = value;
148
+ const currentArray = SmartScriptStore.inputs.options[id] || [];
149
+ const newArray = [
150
+ ...currentArray.slice(0, indexValue),
151
+ value,
152
+ ...currentArray.slice(indexValue + 1),
153
+ ];
154
+ SmartScriptStore.inputs.options[id] = newArray;
147
155
  SmartScriptStore.actionsQueue.push(updateOptionAction(id, value, indexValue));
148
156
  }
149
157
  };
@@ -7,7 +7,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import cloneDeep from "lodash/cloneDeep";
11
10
  import { generatePath } from "react-router-dom";
12
11
  import { getConfig } from "../../config";
13
12
  import { INIT_INPUTS, ADD_MULTIPLE_OCCURENCY, DELETE_MULTIPLE_OCCURENCY, UPDATE_OPTION_INPUT, UPDATE_VARIABLE_INPUT, } from "../constants/inputs";
@@ -30,10 +29,10 @@ const watchEnableSmartScript = (mpi, next, action) => {
30
29
  iframe = document.createElement("iframe");
31
30
  iframe.id = "lp-smartscript";
32
31
  iframe.setAttribute("style", "position: absolute; width:0; height:0; border:0;");
33
- const state = mpi.getState();
34
- const permalink = getConfig().permalink || state.app.meta.permalink || "";
35
- const prefix = getConfig().prefix || state.app.meta.prefix || "";
36
- const uniqid = getConfig().uniqid || state.app.instance.uniqid || "";
32
+ const { app } = mpi.getState();
33
+ const permalink = getConfig().permalink || app.meta.permalink || "";
34
+ const prefix = getConfig().prefix || app.meta.prefix || "";
35
+ const uniqid = getConfig().uniqid || app.instance.uniqid || "";
37
36
  const { modelVersion } = new PathReader(mpi.getState());
38
37
  if (getConfig().router.smartscriptPath) {
39
38
  const path = generatePath(getConfig().router.smartscriptPath, {
@@ -57,7 +56,10 @@ const watchEnableSmartScript = (mpi, next, action) => {
57
56
  mpi.dispatch(_action);
58
57
  });
59
58
  }
60
- }, cloneDeep(mpi.getState().inputs), isNewInstance);
59
+ }, {
60
+ variables: Object.assign({}, mpi.getState().inputs.variables),
61
+ options: Object.assign({}, mpi.getState().inputs.options),
62
+ }, isNewInstance);
61
63
  }
62
64
  });
63
65
  document.body.append(iframe);
@@ -72,40 +74,52 @@ const watchResetState = (mpi, next, action) => {
72
74
  const watchUpdateOptionInput = (mpi, next, action) => __awaiter(void 0, void 0, void 0, function* () {
73
75
  var _a;
74
76
  next(action);
75
- const state = mpi.getState();
77
+ if (!iframe)
78
+ return;
76
79
  const { id } = action;
77
- if (state.smartscript.triggers.options.includes(id)) {
78
- try {
79
- const actions = yield ((_a = iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.triggerListeners("option", id, cloneDeep(state.inputs)));
80
- if (Array.isArray(actions)) {
81
- actions.forEach((_action) => {
82
- mpi.dispatch(_action);
83
- });
84
- }
85
- }
86
- catch (e) {
87
- console.error(e);
80
+ const { smartscript, inputs } = mpi.getState();
81
+ if (!smartscript.triggers.options.includes(id))
82
+ return;
83
+ try {
84
+ const inputsCopy = {
85
+ variables: Object.assign({}, inputs.variables),
86
+ options: Object.assign({}, inputs.options),
87
+ };
88
+ const actions = yield ((_a = iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.triggerListeners("option", id, inputsCopy));
89
+ if (Array.isArray(actions) && actions.length > 0) {
90
+ actions.forEach((_action) => {
91
+ mpi.dispatch(_action);
92
+ });
88
93
  }
89
94
  }
95
+ catch (e) {
96
+ console.error(e);
97
+ }
90
98
  });
91
99
  const watchUpdateVariableInput = (mpi, next, action) => __awaiter(void 0, void 0, void 0, function* () {
92
100
  var _b;
93
101
  next(action);
94
- const state = mpi.getState();
102
+ if (!iframe)
103
+ return;
95
104
  const { id } = action;
96
- if (state.smartscript.triggers.variables.includes(id)) {
97
- try {
98
- const actions = yield ((_b = iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow) === null || _b === void 0 ? void 0 : _b.triggerListeners("variable", id, cloneDeep(state.inputs)));
99
- if (Array.isArray(actions)) {
100
- actions.forEach((_action) => {
101
- mpi.dispatch(_action);
102
- });
103
- }
104
- }
105
- catch (e) {
106
- console.error(e);
105
+ const { smartscript, inputs } = mpi.getState();
106
+ if (!smartscript.triggers.variables.includes(id))
107
+ return;
108
+ try {
109
+ const inputsCopy = {
110
+ variables: Object.assign({}, inputs.variables),
111
+ options: Object.assign({}, inputs.options),
112
+ };
113
+ const actions = yield ((_b = iframe.contentWindow) === null || _b === void 0 ? void 0 : _b.triggerListeners("variable", id, inputsCopy));
114
+ if (Array.isArray(actions) && actions.length > 0) {
115
+ actions.forEach((_action) => {
116
+ mpi.dispatch(_action);
117
+ });
107
118
  }
108
119
  }
120
+ catch (e) {
121
+ console.error(e);
122
+ }
109
123
  });
110
124
  const watchInitInputs = (mpi, next, action) => {
111
125
  next(action);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/wizardx-core",
3
- "version": "4.43.21",
3
+ "version": "4.44.1",
4
4
  "author": "Moncef Hammou (moncef@legalplace.fr)",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -21,14 +21,14 @@
21
21
  "dependencies": {
22
22
  "@appnest/masonry-layout": "^2.0.8",
23
23
  "@cryptography/sha1": "^0.2.0",
24
- "@legalplace/data-gouv": "^1.6.110",
24
+ "@legalplace/data-gouv": "^1.6.111",
25
25
  "@legalplace/lp-events": "1.14.0",
26
26
  "@legalplace/lplogic": "2.3.1",
27
27
  "@legalplace/model-healthcheck": "^1.1.5",
28
28
  "@legalplace/pappers": "^1.2.4",
29
- "@legalplace/referencesparser": "^3.1.88",
29
+ "@legalplace/referencesparser": "^3.1.89",
30
30
  "@legalplace/storybook": "2.364.5",
31
- "@legalplace/typeorm-constants": "^3.78.1",
31
+ "@legalplace/typeorm-constants": "^3.78.2",
32
32
  "@loadable/component": "^5.15.0",
33
33
  "@redux-saga/core": "^1.1.3",
34
34
  "axios": "^0.24.0",
@@ -60,9 +60,9 @@
60
60
  "devDependencies": {
61
61
  "@legalplace/data-gouv": "^1.6.30",
62
62
  "@legalplace/eslint-config": "^2.3.0",
63
- "@legalplace/models-v3-types": "^5.15.6",
63
+ "@legalplace/models-v3-types": "^5.15.7",
64
64
  "@legalplace/prettier-config": "^2.1.3",
65
- "@legalplace/typeorm-entities": "^5.70.2",
65
+ "@legalplace/typeorm-entities": "^5.70.3",
66
66
  "@swc-node/jest": "^1.3.2",
67
67
  "@swc/core": "^1.2.93",
68
68
  "@swc/jest": "^0.2.4",
@@ -100,5 +100,5 @@
100
100
  "*.test.ts",
101
101
  "*.test.tsx"
102
102
  ],
103
- "gitHead": "5cc767158904200aa83ab73d18ddafbe589390a8"
103
+ "gitHead": "189616303921c6b82ce703e7792b250ec34244c2"
104
104
  }