@legalplace/wizardx-core 4.26.1 → 4.27.0

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.
@@ -23,7 +23,7 @@ declare global {
23
23
  hideVariable: typeof SmartScriptStore.hideVariable;
24
24
  displayVariable: typeof SmartScriptStore.displayVariable;
25
25
  moment: typeof moment;
26
- triggerListeners: (type: "option" | "variable", id: number, inputs: StateType.Inputs) => Action[];
26
+ triggerListeners: (type: "option" | "variable", id: number, inputs: StateType.Inputs) => Promise<Action[]>;
27
27
  initTriggers: (callback: TInitTriggersCallback, inputs: StateType.Inputs, newInstance: boolean) => void;
28
28
  }
29
29
  }
@@ -1,3 +1,12 @@
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
+ };
1
10
  import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
11
  import { useEffect, useState } from "react";
3
12
  import { useParams } from "react-router-dom";
@@ -78,20 +87,28 @@ const SmartScriptComponent = ({ inpiActivities = [] }) => {
78
87
  setIsNewInstance(newInstance);
79
88
  }
80
89
  };
81
- window.triggerListeners = (type, id, inputs) => {
90
+ window.triggerListeners = (type, id, inputs) => __awaiter(void 0, void 0, void 0, function* () {
82
91
  const hooks = SmartScriptStore.hooks[type === "option" ? "options" : "variables"];
83
92
  const listeners = hooks[id];
84
93
  if (Array.isArray(listeners)) {
85
94
  SmartScriptStore.inputs = inputs;
86
- try {
87
- listeners.forEach((_cb) => _cb());
88
- }
89
- catch (e) {
90
- console.error("SmartScript (onInit) error: ", e.message);
91
- }
95
+ const promises = listeners.map((_cb) => __awaiter(void 0, void 0, void 0, function* () {
96
+ try {
97
+ if (typeof _cb === "function") {
98
+ return yield _cb();
99
+ }
100
+ console.warn("Invalid listener detected:", _cb);
101
+ return Promise.resolve();
102
+ }
103
+ catch (e) {
104
+ console.error("SmartScript (triggerListener) error:", e.message);
105
+ return Promise.resolve();
106
+ }
107
+ }));
108
+ yield Promise.all(promises);
92
109
  }
93
110
  return SmartScriptStore.grabActions();
94
- };
111
+ });
95
112
  return _jsx(_Fragment, { children: smartScriptLoaded ? "SmartScript" : "Loading..." }, void 0);
96
113
  };
97
114
  const mapStateToProps = () => {
@@ -1,3 +1,12 @@
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
+ };
1
10
  import cloneDeep from "lodash/cloneDeep";
2
11
  import { generatePath } from "react-router-dom";
3
12
  import { getConfig } from "../../config";
@@ -60,14 +69,14 @@ const watchResetState = (mpi, next, action) => {
60
69
  iframe = null;
61
70
  }
62
71
  };
63
- const watchUpdateOptionInput = (mpi, next, action) => {
72
+ const watchUpdateOptionInput = (mpi, next, action) => __awaiter(void 0, void 0, void 0, function* () {
64
73
  var _a;
65
74
  next(action);
66
75
  const state = mpi.getState();
67
76
  const { id } = action;
68
77
  if (state.smartscript.triggers.options.includes(id)) {
69
78
  try {
70
- const actions = (_a = iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.triggerListeners("option", id, cloneDeep(state.inputs));
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)));
71
80
  if (Array.isArray(actions)) {
72
81
  actions.forEach((_action) => {
73
82
  mpi.dispatch(_action);
@@ -78,15 +87,15 @@ const watchUpdateOptionInput = (mpi, next, action) => {
78
87
  console.error(e);
79
88
  }
80
89
  }
81
- };
82
- const watchUpdateVariableInput = (mpi, next, action) => {
83
- var _a;
90
+ });
91
+ const watchUpdateVariableInput = (mpi, next, action) => __awaiter(void 0, void 0, void 0, function* () {
92
+ var _b;
84
93
  next(action);
85
94
  const state = mpi.getState();
86
95
  const { id } = action;
87
96
  if (state.smartscript.triggers.variables.includes(id)) {
88
97
  try {
89
- const actions = (_a = iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow) === null || _a === void 0 ? void 0 : _a.triggerListeners("variable", id, cloneDeep(state.inputs));
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)));
90
99
  if (Array.isArray(actions)) {
91
100
  actions.forEach((_action) => {
92
101
  mpi.dispatch(_action);
@@ -97,7 +106,7 @@ const watchUpdateVariableInput = (mpi, next, action) => {
97
106
  console.error(e);
98
107
  }
99
108
  }
100
- };
109
+ });
101
110
  const watchInitInputs = (mpi, next, action) => {
102
111
  next(action);
103
112
  if (!iframe)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@legalplace/wizardx-core",
3
- "version": "4.26.1",
3
+ "version": "4.27.0",
4
4
  "author": "Moncef Hammou (moncef@legalplace.fr)",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -96,5 +96,5 @@
96
96
  "*.test.ts",
97
97
  "*.test.tsx"
98
98
  ],
99
- "gitHead": "c6215c882221999cb8ce1e05e509630cd848dbdd"
99
+ "gitHead": "521fbebb31160e723413bf902804e3349eb38531"
100
100
  }