@encatch/ws-react 0.0.16 → 0.0.17
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/EncatchPreview.d.ts +23 -0
- package/dist/index.d.ts +3 -0
- package/dist/types.d.ts +87 -0
- package/dist/useEncatchFormEvent.d.ts +50 -0
- package/dist/{web-form-engine-core.umd-CRoRxNVp.js → web-form-engine-core.umd-C-N-KDM0.js} +6492 -6426
- package/dist/ws-react.es.js +363 -159
- package/dist/ws-react.umd.js +22 -22
- package/package.json +5 -4
package/dist/ws-react.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
var k = { exports: {} },
|
|
1
|
+
import N, { useState as U, useRef as oe, useEffect as S, useCallback as se } from "react";
|
|
2
|
+
var k = { exports: {} }, y = {};
|
|
3
3
|
/**
|
|
4
4
|
* @license React
|
|
5
5
|
* react-jsx-runtime.production.js
|
|
@@ -9,29 +9,29 @@ var k = { exports: {} }, h = {};
|
|
|
9
9
|
* This source code is licensed under the MIT license found in the
|
|
10
10
|
* LICENSE file in the root directory of this source tree.
|
|
11
11
|
*/
|
|
12
|
-
var
|
|
13
|
-
function
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
var t = Symbol.for("react.transitional.element"),
|
|
17
|
-
function
|
|
12
|
+
var V;
|
|
13
|
+
function ie() {
|
|
14
|
+
if (V) return y;
|
|
15
|
+
V = 1;
|
|
16
|
+
var t = Symbol.for("react.transitional.element"), r = Symbol.for("react.fragment");
|
|
17
|
+
function n(u, s, c) {
|
|
18
18
|
var m = null;
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
for (var
|
|
22
|
-
|
|
23
|
-
} else
|
|
24
|
-
return
|
|
19
|
+
if (c !== void 0 && (m = "" + c), s.key !== void 0 && (m = "" + s.key), "key" in s) {
|
|
20
|
+
c = {};
|
|
21
|
+
for (var p in s)
|
|
22
|
+
p !== "key" && (c[p] = s[p]);
|
|
23
|
+
} else c = s;
|
|
24
|
+
return s = c.ref, {
|
|
25
25
|
$$typeof: t,
|
|
26
|
-
type:
|
|
26
|
+
type: u,
|
|
27
27
|
key: m,
|
|
28
|
-
ref:
|
|
29
|
-
props:
|
|
28
|
+
ref: s !== void 0 ? s : null,
|
|
29
|
+
props: c
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
return
|
|
32
|
+
return y.Fragment = r, y.jsx = n, y.jsxs = n, y;
|
|
33
33
|
}
|
|
34
|
-
var
|
|
34
|
+
var A = {};
|
|
35
35
|
/**
|
|
36
36
|
* @license React
|
|
37
37
|
* react-jsx-runtime.development.js
|
|
@@ -41,125 +41,125 @@ var g = {};
|
|
|
41
41
|
* This source code is licensed under the MIT license found in the
|
|
42
42
|
* LICENSE file in the root directory of this source tree.
|
|
43
43
|
*/
|
|
44
|
-
var
|
|
45
|
-
function
|
|
46
|
-
return
|
|
44
|
+
var J;
|
|
45
|
+
function ue() {
|
|
46
|
+
return J || (J = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
47
47
|
function t(e) {
|
|
48
48
|
if (e == null) return null;
|
|
49
49
|
if (typeof e == "function")
|
|
50
|
-
return e.$$typeof ===
|
|
50
|
+
return e.$$typeof === re ? null : e.displayName || e.name || null;
|
|
51
51
|
if (typeof e == "string") return e;
|
|
52
52
|
switch (e) {
|
|
53
|
-
case
|
|
53
|
+
case f:
|
|
54
54
|
return "Fragment";
|
|
55
|
-
case
|
|
55
|
+
case Q:
|
|
56
56
|
return "Profiler";
|
|
57
|
-
case
|
|
57
|
+
case G:
|
|
58
58
|
return "StrictMode";
|
|
59
59
|
case Z:
|
|
60
60
|
return "Suspense";
|
|
61
|
-
case
|
|
61
|
+
case K:
|
|
62
62
|
return "SuspenseList";
|
|
63
|
-
case
|
|
63
|
+
case ee:
|
|
64
64
|
return "Activity";
|
|
65
65
|
}
|
|
66
66
|
if (typeof e == "object")
|
|
67
67
|
switch (typeof e.tag == "number" && console.error(
|
|
68
68
|
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
69
69
|
), e.$$typeof) {
|
|
70
|
-
case
|
|
70
|
+
case i:
|
|
71
71
|
return "Portal";
|
|
72
72
|
case B:
|
|
73
73
|
return (e.displayName || "Context") + ".Provider";
|
|
74
74
|
case X:
|
|
75
75
|
return (e._context.displayName || "Context") + ".Consumer";
|
|
76
76
|
case H:
|
|
77
|
-
var
|
|
78
|
-
return e = e.displayName, e || (e =
|
|
79
|
-
case
|
|
80
|
-
return
|
|
81
|
-
case
|
|
82
|
-
|
|
77
|
+
var o = e.render;
|
|
78
|
+
return e = e.displayName, e || (e = o.displayName || o.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
79
|
+
case D:
|
|
80
|
+
return o = e.displayName || null, o !== null ? o : t(e.type) || "Memo";
|
|
81
|
+
case F:
|
|
82
|
+
o = e._payload, e = e._init;
|
|
83
83
|
try {
|
|
84
|
-
return t(e(
|
|
84
|
+
return t(e(o));
|
|
85
85
|
} catch {
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
return null;
|
|
89
89
|
}
|
|
90
|
-
function
|
|
90
|
+
function r(e) {
|
|
91
91
|
return "" + e;
|
|
92
92
|
}
|
|
93
|
-
function
|
|
93
|
+
function n(e) {
|
|
94
94
|
try {
|
|
95
|
-
|
|
96
|
-
var
|
|
95
|
+
r(e);
|
|
96
|
+
var o = !1;
|
|
97
97
|
} catch {
|
|
98
|
-
|
|
98
|
+
o = !0;
|
|
99
99
|
}
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
var
|
|
103
|
-
return
|
|
104
|
-
|
|
100
|
+
if (o) {
|
|
101
|
+
o = console;
|
|
102
|
+
var l = o.error, d = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
103
|
+
return l.call(
|
|
104
|
+
o,
|
|
105
105
|
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
106
|
-
|
|
107
|
-
),
|
|
106
|
+
d
|
|
107
|
+
), r(e);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
function
|
|
111
|
-
if (e ===
|
|
112
|
-
if (typeof e == "object" && e !== null && e.$$typeof ===
|
|
110
|
+
function u(e) {
|
|
111
|
+
if (e === f) return "<>";
|
|
112
|
+
if (typeof e == "object" && e !== null && e.$$typeof === F)
|
|
113
113
|
return "<...>";
|
|
114
114
|
try {
|
|
115
|
-
var
|
|
116
|
-
return
|
|
115
|
+
var o = t(e);
|
|
116
|
+
return o ? "<" + o + ">" : "<...>";
|
|
117
117
|
} catch {
|
|
118
118
|
return "<...>";
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
function
|
|
122
|
-
var e =
|
|
121
|
+
function s() {
|
|
122
|
+
var e = C.A;
|
|
123
123
|
return e === null ? null : e.getOwner();
|
|
124
124
|
}
|
|
125
|
-
function
|
|
125
|
+
function c() {
|
|
126
126
|
return Error("react-stack-top-frame");
|
|
127
127
|
}
|
|
128
128
|
function m(e) {
|
|
129
|
-
if (
|
|
130
|
-
var
|
|
131
|
-
if (
|
|
129
|
+
if (L.call(e, "key")) {
|
|
130
|
+
var o = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
131
|
+
if (o && o.isReactWarning) return !1;
|
|
132
132
|
}
|
|
133
133
|
return e.key !== void 0;
|
|
134
134
|
}
|
|
135
|
-
function
|
|
136
|
-
function
|
|
137
|
-
|
|
135
|
+
function p(e, o) {
|
|
136
|
+
function l() {
|
|
137
|
+
M || (M = !0, console.error(
|
|
138
138
|
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
139
|
-
|
|
139
|
+
o
|
|
140
140
|
));
|
|
141
141
|
}
|
|
142
|
-
|
|
143
|
-
get:
|
|
142
|
+
l.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
143
|
+
get: l,
|
|
144
144
|
configurable: !0
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
|
-
function
|
|
147
|
+
function R() {
|
|
148
148
|
var e = t(this.type);
|
|
149
149
|
return Y[e] || (Y[e] = !0, console.error(
|
|
150
150
|
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
151
151
|
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
152
152
|
}
|
|
153
|
-
function
|
|
154
|
-
return
|
|
155
|
-
$$typeof:
|
|
153
|
+
function P(e, o, l, d, g, h, x, j) {
|
|
154
|
+
return l = h.ref, e = {
|
|
155
|
+
$$typeof: T,
|
|
156
156
|
type: e,
|
|
157
|
-
key:
|
|
158
|
-
props:
|
|
159
|
-
_owner:
|
|
160
|
-
}, (
|
|
157
|
+
key: o,
|
|
158
|
+
props: h,
|
|
159
|
+
_owner: g
|
|
160
|
+
}, (l !== void 0 ? l : null) !== null ? Object.defineProperty(e, "ref", {
|
|
161
161
|
enumerable: !1,
|
|
162
|
-
get:
|
|
162
|
+
get: R
|
|
163
163
|
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
164
164
|
configurable: !1,
|
|
165
165
|
enumerable: !1,
|
|
@@ -174,150 +174,354 @@ function ae() {
|
|
|
174
174
|
configurable: !1,
|
|
175
175
|
enumerable: !1,
|
|
176
176
|
writable: !0,
|
|
177
|
-
value:
|
|
177
|
+
value: x
|
|
178
178
|
}), Object.defineProperty(e, "_debugTask", {
|
|
179
179
|
configurable: !1,
|
|
180
180
|
enumerable: !1,
|
|
181
181
|
writable: !0,
|
|
182
|
-
value:
|
|
182
|
+
value: j
|
|
183
183
|
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
184
184
|
}
|
|
185
|
-
function
|
|
186
|
-
var
|
|
187
|
-
if (
|
|
188
|
-
if (
|
|
189
|
-
if (
|
|
190
|
-
for (
|
|
191
|
-
|
|
192
|
-
Object.freeze && Object.freeze(
|
|
185
|
+
function E(e, o, l, d, g, h, x, j) {
|
|
186
|
+
var b = o.children;
|
|
187
|
+
if (b !== void 0)
|
|
188
|
+
if (d)
|
|
189
|
+
if (ne(b)) {
|
|
190
|
+
for (d = 0; d < b.length; d++)
|
|
191
|
+
v(b[d]);
|
|
192
|
+
Object.freeze && Object.freeze(b);
|
|
193
193
|
} else
|
|
194
194
|
console.error(
|
|
195
195
|
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
196
196
|
);
|
|
197
|
-
else
|
|
198
|
-
if (
|
|
199
|
-
|
|
200
|
-
var _ = Object.keys(
|
|
197
|
+
else v(b);
|
|
198
|
+
if (L.call(o, "key")) {
|
|
199
|
+
b = t(e);
|
|
200
|
+
var _ = Object.keys(o).filter(function(te) {
|
|
201
201
|
return te !== "key";
|
|
202
202
|
});
|
|
203
|
-
|
|
203
|
+
d = 0 < _.length ? "{key: someKey, " + _.join(": ..., ") + ": ...}" : "{key: someKey}", q[b + d] || (_ = 0 < _.length ? "{" + _.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
204
204
|
`A props object containing a "key" prop is being spread into JSX:
|
|
205
205
|
let props = %s;
|
|
206
206
|
<%s {...props} />
|
|
207
207
|
React keys must be passed directly to JSX without using spread:
|
|
208
208
|
let props = %s;
|
|
209
209
|
<%s key={someKey} {...props} />`,
|
|
210
|
-
|
|
211
|
-
|
|
210
|
+
d,
|
|
211
|
+
b,
|
|
212
212
|
_,
|
|
213
|
-
|
|
214
|
-
),
|
|
213
|
+
b
|
|
214
|
+
), q[b + d] = !0);
|
|
215
215
|
}
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
for (var
|
|
219
|
-
|
|
220
|
-
} else
|
|
221
|
-
return
|
|
222
|
-
|
|
216
|
+
if (b = null, l !== void 0 && (n(l), b = "" + l), m(o) && (n(o.key), b = "" + o.key), "key" in o) {
|
|
217
|
+
l = {};
|
|
218
|
+
for (var I in o)
|
|
219
|
+
I !== "key" && (l[I] = o[I]);
|
|
220
|
+
} else l = o;
|
|
221
|
+
return b && p(
|
|
222
|
+
l,
|
|
223
223
|
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
224
|
-
),
|
|
224
|
+
), P(
|
|
225
225
|
e,
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
226
|
+
b,
|
|
227
|
+
h,
|
|
228
|
+
g,
|
|
229
|
+
s(),
|
|
230
|
+
l,
|
|
231
|
+
x,
|
|
232
|
+
j
|
|
233
233
|
);
|
|
234
234
|
}
|
|
235
|
-
function
|
|
236
|
-
typeof e == "object" && e !== null && e.$$typeof ===
|
|
235
|
+
function v(e) {
|
|
236
|
+
typeof e == "object" && e !== null && e.$$typeof === T && e._store && (e._store.validated = 1);
|
|
237
237
|
}
|
|
238
|
-
var
|
|
238
|
+
var a = N, T = Symbol.for("react.transitional.element"), i = Symbol.for("react.portal"), f = Symbol.for("react.fragment"), G = Symbol.for("react.strict_mode"), Q = Symbol.for("react.profiler"), X = Symbol.for("react.consumer"), B = Symbol.for("react.context"), H = Symbol.for("react.forward_ref"), Z = Symbol.for("react.suspense"), K = Symbol.for("react.suspense_list"), D = Symbol.for("react.memo"), F = Symbol.for("react.lazy"), ee = Symbol.for("react.activity"), re = Symbol.for("react.client.reference"), C = a.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, L = Object.prototype.hasOwnProperty, ne = Array.isArray, O = console.createTask ? console.createTask : function() {
|
|
239
239
|
return null;
|
|
240
240
|
};
|
|
241
|
-
|
|
241
|
+
a = {
|
|
242
242
|
react_stack_bottom_frame: function(e) {
|
|
243
243
|
return e();
|
|
244
244
|
}
|
|
245
245
|
};
|
|
246
|
-
var
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
)(),
|
|
250
|
-
|
|
251
|
-
var
|
|
252
|
-
return
|
|
246
|
+
var M, Y = {}, $ = a.react_stack_bottom_frame.bind(
|
|
247
|
+
a,
|
|
248
|
+
c
|
|
249
|
+
)(), W = O(u(c)), q = {};
|
|
250
|
+
A.Fragment = f, A.jsx = function(e, o, l, d, g) {
|
|
251
|
+
var h = 1e4 > C.recentlyCreatedOwnerStacks++;
|
|
252
|
+
return E(
|
|
253
253
|
e,
|
|
254
|
-
r,
|
|
255
254
|
o,
|
|
255
|
+
l,
|
|
256
256
|
!1,
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
257
|
+
d,
|
|
258
|
+
g,
|
|
259
|
+
h ? Error("react-stack-top-frame") : $,
|
|
260
|
+
h ? O(u(e)) : W
|
|
261
261
|
);
|
|
262
|
-
},
|
|
263
|
-
var
|
|
264
|
-
return
|
|
262
|
+
}, A.jsxs = function(e, o, l, d, g) {
|
|
263
|
+
var h = 1e4 > C.recentlyCreatedOwnerStacks++;
|
|
264
|
+
return E(
|
|
265
265
|
e,
|
|
266
|
-
r,
|
|
267
266
|
o,
|
|
267
|
+
l,
|
|
268
268
|
!0,
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
269
|
+
d,
|
|
270
|
+
g,
|
|
271
|
+
h ? Error("react-stack-top-frame") : $,
|
|
272
|
+
h ? O(u(e)) : W
|
|
273
273
|
);
|
|
274
274
|
};
|
|
275
|
-
})()),
|
|
275
|
+
})()), A;
|
|
276
276
|
}
|
|
277
|
-
var
|
|
278
|
-
function
|
|
279
|
-
return
|
|
277
|
+
var z;
|
|
278
|
+
function ce() {
|
|
279
|
+
return z || (z = 1, process.env.NODE_ENV === "production" ? k.exports = ie() : k.exports = ue()), k.exports;
|
|
280
|
+
}
|
|
281
|
+
var ae = ce();
|
|
282
|
+
class le extends EventTarget {
|
|
283
|
+
subscriptions = /* @__PURE__ */ new Map();
|
|
284
|
+
targetOrigin = "*";
|
|
285
|
+
/**
|
|
286
|
+
* Check if a form ID matches the filter
|
|
287
|
+
*/
|
|
288
|
+
matchesFilter(r, n) {
|
|
289
|
+
return !n || n === "*" || n === null || n === void 0 ? !0 : typeof n == "string" ? r === n : Array.isArray(n) ? n.includes(r || "") : typeof n == "function" ? n(r || "") : !1;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Get form ID from payload
|
|
293
|
+
*/
|
|
294
|
+
getFormIdFromPayload(r) {
|
|
295
|
+
return r?.feedbackConfigurationId;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Publish an event to all matching subscribers
|
|
299
|
+
*/
|
|
300
|
+
publish(r, n, u) {
|
|
301
|
+
const s = this.getFormIdFromPayload(n);
|
|
302
|
+
console.log(`[FormEventPublisher] 📢 Publishing "${r}"`, {
|
|
303
|
+
formId: s,
|
|
304
|
+
payload: n
|
|
305
|
+
}), typeof window < "u" && (window.dispatchEvent(
|
|
306
|
+
new CustomEvent(r, {
|
|
307
|
+
detail: n,
|
|
308
|
+
bubbles: !0
|
|
309
|
+
})
|
|
310
|
+
), console.log("[FormEventPublisher] ✅ Event dispatched on window")), u?.usePostMessage !== !1 && this.sendPostMessage(r, n);
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Subscribe to form events with optional form ID filtering
|
|
314
|
+
*/
|
|
315
|
+
subscribe(r, n, u) {
|
|
316
|
+
const s = Symbol("subscription"), c = {
|
|
317
|
+
eventType: r,
|
|
318
|
+
handler: n,
|
|
319
|
+
filter: u?.formId,
|
|
320
|
+
id: s,
|
|
321
|
+
once: u?.once
|
|
322
|
+
};
|
|
323
|
+
this.subscriptions.has(r) || this.subscriptions.set(r, []), this.subscriptions.get(r).push(c), console.log(`[FormEventPublisher] Subscribed to "${r}"`, {
|
|
324
|
+
formId: u?.formId,
|
|
325
|
+
once: u?.once,
|
|
326
|
+
totalSubscriptions: this.subscriptions.get(r).length
|
|
327
|
+
});
|
|
328
|
+
const m = (p) => {
|
|
329
|
+
const R = p, P = this.getFormIdFromPayload(R.detail);
|
|
330
|
+
this.matchesFilter(P, u?.formId) && (n(R.detail), u?.once && typeof window < "u" && window.removeEventListener(r, m));
|
|
331
|
+
};
|
|
332
|
+
return typeof window < "u" && window.addEventListener(r, m), () => {
|
|
333
|
+
console.log(`[FormEventPublisher] Unsubscribed from "${r}"`, {
|
|
334
|
+
formId: u?.formId,
|
|
335
|
+
remainingSubscriptions: (this.subscriptions.get(r)?.length || 1) - 1
|
|
336
|
+
}), this.unsubscribe(s), typeof window < "u" && window.removeEventListener(r, m);
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Unsubscribe by subscription ID
|
|
341
|
+
*/
|
|
342
|
+
unsubscribe(r) {
|
|
343
|
+
for (const [n, u] of this.subscriptions.entries()) {
|
|
344
|
+
const s = u.findIndex((c) => c.id === r);
|
|
345
|
+
if (s !== -1) {
|
|
346
|
+
u.splice(s, 1), u.length === 0 && this.subscriptions.delete(n);
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Subscribe to all form events with optional filtering
|
|
353
|
+
*/
|
|
354
|
+
subscribeAll(r, n) {
|
|
355
|
+
console.log("[FormEventPublisher] Subscribing to ALL events", {
|
|
356
|
+
formId: n?.formId,
|
|
357
|
+
once: n?.once
|
|
358
|
+
});
|
|
359
|
+
const u = [
|
|
360
|
+
"form:view",
|
|
361
|
+
"form:submit",
|
|
362
|
+
"form:close",
|
|
363
|
+
"form:section:change",
|
|
364
|
+
"form:question:answered",
|
|
365
|
+
"form:error"
|
|
366
|
+
], s = [];
|
|
367
|
+
return u.forEach((c) => {
|
|
368
|
+
const m = this.subscribe(
|
|
369
|
+
c,
|
|
370
|
+
(p) => r(c, p),
|
|
371
|
+
n
|
|
372
|
+
);
|
|
373
|
+
s.push(m);
|
|
374
|
+
}), () => {
|
|
375
|
+
console.log("[FormEventPublisher] Unsubscribing from ALL events", {
|
|
376
|
+
formId: n?.formId
|
|
377
|
+
}), s.forEach((c) => c());
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Get active subscriptions count (for debugging)
|
|
382
|
+
*/
|
|
383
|
+
getSubscriptionCount(r) {
|
|
384
|
+
return r ? this.subscriptions.get(r)?.length || 0 : Array.from(this.subscriptions.values()).reduce((n, u) => n + u.length, 0);
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Clear all subscriptions for an event type (or all events)
|
|
388
|
+
*/
|
|
389
|
+
clearSubscriptions(r) {
|
|
390
|
+
r ? this.subscriptions.delete(r) : this.subscriptions.clear();
|
|
391
|
+
}
|
|
392
|
+
sendPostMessage(r, n) {
|
|
393
|
+
const u = {
|
|
394
|
+
type: `encatch:${r}`,
|
|
395
|
+
payload: n,
|
|
396
|
+
source: "encatch-form-engine"
|
|
397
|
+
};
|
|
398
|
+
window.parent && window.parent !== window && window.parent.postMessage(u, this.targetOrigin), document.querySelectorAll("iframe").forEach((s) => {
|
|
399
|
+
s.contentWindow && s.contentWindow.postMessage(u, this.targetOrigin);
|
|
400
|
+
}), typeof window.ReactNativeWebView < "u" && window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
401
|
+
action: r.replace("form:", ""),
|
|
402
|
+
data: JSON.stringify(n)
|
|
403
|
+
}));
|
|
404
|
+
}
|
|
280
405
|
}
|
|
281
|
-
|
|
282
|
-
|
|
406
|
+
console.log("[FormEventPublisher] Creating singleton instance");
|
|
407
|
+
const w = new le();
|
|
408
|
+
typeof window < "u" && import("./web-form-engine-core.umd-C-N-KDM0.js").then((t) => t.w).then(({ EncatchAppElement: t }) => {
|
|
283
409
|
try {
|
|
284
410
|
customElements.get("encatch-app") || customElements.define("encatch-app", t);
|
|
285
|
-
} catch (
|
|
286
|
-
console.debug("Custom element registration:",
|
|
411
|
+
} catch (r) {
|
|
412
|
+
console.debug("Custom element registration:", r);
|
|
287
413
|
}
|
|
288
414
|
});
|
|
289
|
-
const
|
|
415
|
+
const de = ({
|
|
290
416
|
formData: t,
|
|
291
|
-
cssLink:
|
|
292
|
-
scale:
|
|
293
|
-
persistMode:
|
|
417
|
+
cssLink: r,
|
|
418
|
+
scale: n = 100,
|
|
419
|
+
persistMode: u = "none",
|
|
420
|
+
instanceId: s,
|
|
421
|
+
onFormEvent: c
|
|
294
422
|
}) => {
|
|
295
|
-
const [
|
|
423
|
+
const [m, p] = U(!1), [R, P] = U(!0), E = N.useRef(null), v = N.useRef(
|
|
296
424
|
null
|
|
297
|
-
);
|
|
298
|
-
|
|
425
|
+
), a = oe({});
|
|
426
|
+
S(() => {
|
|
427
|
+
if (!c) return;
|
|
428
|
+
c({
|
|
429
|
+
onSubmit: (f) => {
|
|
430
|
+
a.current.onSubmit = f;
|
|
431
|
+
},
|
|
432
|
+
onView: (f) => {
|
|
433
|
+
a.current.onView = f;
|
|
434
|
+
},
|
|
435
|
+
onClose: (f) => {
|
|
436
|
+
a.current.onClose = f;
|
|
437
|
+
},
|
|
438
|
+
onSectionChange: (f) => {
|
|
439
|
+
a.current.onSectionChange = f;
|
|
440
|
+
},
|
|
441
|
+
onQuestionAnswered: (f) => {
|
|
442
|
+
a.current.onQuestionAnswered = f;
|
|
443
|
+
},
|
|
444
|
+
onError: (f) => {
|
|
445
|
+
a.current.onError = f;
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
}, [c]), S(() => {
|
|
449
|
+
if (!s) return;
|
|
450
|
+
const i = [];
|
|
451
|
+
return a.current.onSubmit && i.push(
|
|
452
|
+
w.subscribe(
|
|
453
|
+
"form:submit",
|
|
454
|
+
a.current.onSubmit,
|
|
455
|
+
{ formId: s }
|
|
456
|
+
)
|
|
457
|
+
), a.current.onView && i.push(
|
|
458
|
+
w.subscribe(
|
|
459
|
+
"form:view",
|
|
460
|
+
a.current.onView,
|
|
461
|
+
{ formId: s }
|
|
462
|
+
)
|
|
463
|
+
), a.current.onClose && i.push(
|
|
464
|
+
w.subscribe(
|
|
465
|
+
"form:close",
|
|
466
|
+
a.current.onClose,
|
|
467
|
+
{ formId: s }
|
|
468
|
+
)
|
|
469
|
+
), a.current.onSectionChange && i.push(
|
|
470
|
+
w.subscribe(
|
|
471
|
+
"form:section:change",
|
|
472
|
+
a.current.onSectionChange,
|
|
473
|
+
{ formId: s }
|
|
474
|
+
)
|
|
475
|
+
), a.current.onQuestionAnswered && i.push(
|
|
476
|
+
w.subscribe(
|
|
477
|
+
"form:question:answered",
|
|
478
|
+
a.current.onQuestionAnswered,
|
|
479
|
+
{ formId: s }
|
|
480
|
+
)
|
|
481
|
+
), a.current.onError && i.push(
|
|
482
|
+
w.subscribe(
|
|
483
|
+
"form:error",
|
|
484
|
+
a.current.onError,
|
|
485
|
+
{ formId: s }
|
|
486
|
+
)
|
|
487
|
+
), () => {
|
|
488
|
+
i.forEach((f) => f());
|
|
489
|
+
};
|
|
490
|
+
}, [s]), S(() => {
|
|
299
491
|
(() => {
|
|
300
492
|
try {
|
|
301
493
|
return t ? !0 : (console.warn("[EncatchPreview] formData is not defined"), !1);
|
|
302
|
-
} catch (
|
|
303
|
-
return console.error("[EncatchPreview] Error during data validation:",
|
|
494
|
+
} catch (f) {
|
|
495
|
+
return console.error("[EncatchPreview] Error during data validation:", f), !1;
|
|
304
496
|
}
|
|
305
|
-
})() ?
|
|
497
|
+
})() ? p(!0) : console.warn(
|
|
306
498
|
"[EncatchPreview] Data validation failed, retrying in 100ms..."
|
|
307
499
|
);
|
|
308
500
|
}, [t]);
|
|
309
|
-
const T =
|
|
310
|
-
t.onClose && t.onClose(),
|
|
501
|
+
const T = se(() => {
|
|
502
|
+
t.onClose && t.onClose(), P(!1);
|
|
311
503
|
}, [t.onClose]);
|
|
312
|
-
return
|
|
313
|
-
if (!
|
|
504
|
+
return S(() => {
|
|
505
|
+
if (!m || !E.current)
|
|
314
506
|
return;
|
|
315
|
-
const
|
|
316
|
-
return
|
|
317
|
-
|
|
507
|
+
const i = document.createElement("encatch-app");
|
|
508
|
+
return i.theme = t.theme, i.currentMode = t.currentMode, i.currentLanguage = t.currentLanguage, i.questions = t.questions, i.questionLanguages = t.questionLanguages, i.otherConfigurationProperties = t.otherConfigurationProperties, i.welcomeScreenProperties = t.welcomeScreenProperties, i.endScreenProperties = t.endScreenProperties, i.translations = t.translations, i.sections = t.sections, i.themeSettings = t.themeSettings, i.onClose = T, i.onSectionChange = t.onSectionChange, i.apiKey = t.apiKey, i.hostUrl = t.hostUrl, i.feedbackConfigId = t.feedbackConfigId, i.identifier = t.identifier, i.cssLink = r, i.scale = n, i.persistMode = u, s && (i.instanceId = s), v.current = i, E.current.appendChild(i), () => {
|
|
509
|
+
E.current && v.current && E.current.removeChild(v.current), v.current = null;
|
|
318
510
|
};
|
|
319
|
-
}, [
|
|
511
|
+
}, [m, t, r, n, T, u, s]), R ? /* @__PURE__ */ ae.jsx("div", { ref: E }) : null;
|
|
320
512
|
};
|
|
513
|
+
function be(t, r, n) {
|
|
514
|
+
S(() => w.subscribe(
|
|
515
|
+
t,
|
|
516
|
+
r,
|
|
517
|
+
n
|
|
518
|
+
), [t, n?.formId, r]);
|
|
519
|
+
}
|
|
520
|
+
function me(t, r) {
|
|
521
|
+
S(() => w.subscribeAll(t, r), [r?.formId, t]);
|
|
522
|
+
}
|
|
321
523
|
export {
|
|
322
|
-
|
|
524
|
+
de as EncatchPreview,
|
|
525
|
+
be as useEncatchFormEvent,
|
|
526
|
+
me as useEncatchFormEventAll
|
|
323
527
|
};
|