@encatch/ws-react 0.0.15 → 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.
@@ -1,5 +1,5 @@
1
- import C, { useState as $, useEffect as U, useCallback as ne } from "react";
2
- var k = { exports: {} }, h = {};
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 q;
13
- function oe() {
14
- if (q) return h;
15
- q = 1;
16
- var t = Symbol.for("react.transitional.element"), l = Symbol.for("react.fragment");
17
- function f(d, c, u) {
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 (u !== void 0 && (m = "" + u), c.key !== void 0 && (m = "" + c.key), "key" in c) {
20
- u = {};
21
- for (var R in c)
22
- R !== "key" && (u[R] = c[R]);
23
- } else u = c;
24
- return c = u.ref, {
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: d,
26
+ type: u,
27
27
  key: m,
28
- ref: c !== void 0 ? c : null,
29
- props: u
28
+ ref: s !== void 0 ? s : null,
29
+ props: c
30
30
  };
31
31
  }
32
- return h.Fragment = l, h.jsx = f, h.jsxs = f, h;
32
+ return y.Fragment = r, y.jsx = n, y.jsxs = n, y;
33
33
  }
34
- var g = {};
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 W;
45
- function ae() {
46
- return W || (W = 1, process.env.NODE_ENV !== "production" && (function() {
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 === ee ? null : e.displayName || e.name || null;
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 P:
53
+ case f:
54
54
  return "Fragment";
55
- case G:
55
+ case Q:
56
56
  return "Profiler";
57
- case V:
57
+ case G:
58
58
  return "StrictMode";
59
59
  case Z:
60
60
  return "Suspense";
61
- case Q:
61
+ case K:
62
62
  return "SuspenseList";
63
- case D:
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 z:
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 r = e.render;
78
- return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
79
- case K:
80
- return r = e.displayName || null, r !== null ? r : t(e.type) || "Memo";
81
- case x:
82
- r = e._payload, e = e._init;
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(r));
84
+ return t(e(o));
85
85
  } catch {
86
86
  }
87
87
  }
88
88
  return null;
89
89
  }
90
- function l(e) {
90
+ function r(e) {
91
91
  return "" + e;
92
92
  }
93
- function f(e) {
93
+ function n(e) {
94
94
  try {
95
- l(e);
96
- var r = !1;
95
+ r(e);
96
+ var o = !1;
97
97
  } catch {
98
- r = !0;
98
+ o = !0;
99
99
  }
100
- if (r) {
101
- r = console;
102
- var o = r.error, a = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
103
- return o.call(
104
- r,
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
- a
107
- ), l(e);
106
+ d
107
+ ), r(e);
108
108
  }
109
109
  }
110
- function d(e) {
111
- if (e === P) return "<>";
112
- if (typeof e == "object" && e !== null && e.$$typeof === x)
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 r = t(e);
116
- return r ? "<" + r + ">" : "<...>";
115
+ var o = t(e);
116
+ return o ? "<" + o + ">" : "<...>";
117
117
  } catch {
118
118
  return "<...>";
119
119
  }
120
120
  }
121
- function c() {
122
- var e = S.A;
121
+ function s() {
122
+ var e = C.A;
123
123
  return e === null ? null : e.getOwner();
124
124
  }
125
- function u() {
125
+ function c() {
126
126
  return Error("react-stack-top-frame");
127
127
  }
128
128
  function m(e) {
129
- if (N.call(e, "key")) {
130
- var r = Object.getOwnPropertyDescriptor(e, "key").get;
131
- if (r && r.isReactWarning) return !1;
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 R(e, r) {
136
- function o() {
137
- I || (I = !0, console.error(
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
- r
139
+ o
140
140
  ));
141
141
  }
142
- o.isReactWarning = !0, Object.defineProperty(e, "key", {
143
- get: o,
142
+ l.isReactWarning = !0, Object.defineProperty(e, "key", {
143
+ get: l,
144
144
  configurable: !0
145
145
  });
146
146
  }
147
- function p() {
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 v(e, r, o, a, E, i, O, A) {
154
- return o = i.ref, e = {
155
- $$typeof: j,
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: r,
158
- props: i,
159
- _owner: E
160
- }, (o !== void 0 ? o : null) !== null ? Object.defineProperty(e, "ref", {
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: p
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: O
177
+ value: x
178
178
  }), Object.defineProperty(e, "_debugTask", {
179
179
  configurable: !1,
180
180
  enumerable: !1,
181
181
  writable: !0,
182
- value: A
182
+ value: j
183
183
  }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
184
184
  }
185
- function T(e, r, o, a, E, i, O, A) {
186
- var s = r.children;
187
- if (s !== void 0)
188
- if (a)
189
- if (re(s)) {
190
- for (a = 0; a < s.length; a++)
191
- n(s[a]);
192
- Object.freeze && Object.freeze(s);
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 n(s);
198
- if (N.call(r, "key")) {
199
- s = t(e);
200
- var _ = Object.keys(r).filter(function(te) {
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
- a = 0 < _.length ? "{key: someKey, " + _.join(": ..., ") + ": ...}" : "{key: someKey}", F[s + a] || (_ = 0 < _.length ? "{" + _.join(": ..., ") + ": ...}" : "{}", console.error(
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
- a,
211
- s,
210
+ d,
211
+ b,
212
212
  _,
213
- s
214
- ), F[s + a] = !0);
213
+ b
214
+ ), q[b + d] = !0);
215
215
  }
216
- if (s = null, o !== void 0 && (f(o), s = "" + o), m(r) && (f(r.key), s = "" + r.key), "key" in r) {
217
- o = {};
218
- for (var y in r)
219
- y !== "key" && (o[y] = r[y]);
220
- } else o = r;
221
- return s && R(
222
- o,
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
- ), v(
224
+ ), P(
225
225
  e,
226
- s,
227
- i,
228
- E,
229
- c(),
230
- o,
231
- O,
232
- A
226
+ b,
227
+ h,
228
+ g,
229
+ s(),
230
+ l,
231
+ x,
232
+ j
233
233
  );
234
234
  }
235
- function n(e) {
236
- typeof e == "object" && e !== null && e.$$typeof === j && e._store && (e._store.validated = 1);
235
+ function v(e) {
236
+ typeof e == "object" && e !== null && e.$$typeof === T && e._store && (e._store.validated = 1);
237
237
  }
238
- var b = C, j = Symbol.for("react.transitional.element"), z = Symbol.for("react.portal"), P = Symbol.for("react.fragment"), V = Symbol.for("react.strict_mode"), G = 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"), Q = Symbol.for("react.suspense_list"), K = Symbol.for("react.memo"), x = Symbol.for("react.lazy"), D = Symbol.for("react.activity"), ee = Symbol.for("react.client.reference"), S = b.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, N = Object.prototype.hasOwnProperty, re = Array.isArray, w = console.createTask ? console.createTask : function() {
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
- b = {
241
+ a = {
242
242
  react_stack_bottom_frame: function(e) {
243
243
  return e();
244
244
  }
245
245
  };
246
- var I, Y = {}, L = b.react_stack_bottom_frame.bind(
247
- b,
248
- u
249
- )(), M = w(d(u)), F = {};
250
- g.Fragment = P, g.jsx = function(e, r, o, a, E) {
251
- var i = 1e4 > S.recentlyCreatedOwnerStacks++;
252
- return T(
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
- a,
258
- E,
259
- i ? Error("react-stack-top-frame") : L,
260
- i ? w(d(e)) : M
257
+ d,
258
+ g,
259
+ h ? Error("react-stack-top-frame") : $,
260
+ h ? O(u(e)) : W
261
261
  );
262
- }, g.jsxs = function(e, r, o, a, E) {
263
- var i = 1e4 > S.recentlyCreatedOwnerStacks++;
264
- return T(
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
- a,
270
- E,
271
- i ? Error("react-stack-top-frame") : L,
272
- i ? w(d(e)) : M
269
+ d,
270
+ g,
271
+ h ? Error("react-stack-top-frame") : $,
272
+ h ? O(u(e)) : W
273
273
  );
274
274
  };
275
- })()), g;
275
+ })()), A;
276
276
  }
277
- var J;
278
- function se() {
279
- return J || (J = 1, process.env.NODE_ENV === "production" ? k.exports = oe() : k.exports = ae()), k.exports;
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
- var ce = se();
282
- typeof window < "u" && import("./web-form-engine-core.umd-B1xHitkx.js").then((t) => t.w).then(({ EncatchAppElement: t }) => {
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 (l) {
286
- console.debug("Custom element registration:", l);
411
+ } catch (r) {
412
+ console.debug("Custom element registration:", r);
287
413
  }
288
414
  });
289
- const ie = ({
415
+ const de = ({
290
416
  formData: t,
291
- cssLink: l,
292
- scale: f = 100,
293
- persistMode: d = "none"
417
+ cssLink: r,
418
+ scale: n = 100,
419
+ persistMode: u = "none",
420
+ instanceId: s,
421
+ onFormEvent: c
294
422
  }) => {
295
- const [c, u] = $(!1), [m, R] = $(!0), p = C.useRef(null), v = C.useRef(
423
+ const [m, p] = U(!1), [R, P] = U(!0), E = N.useRef(null), v = N.useRef(
296
424
  null
297
- );
298
- U(() => {
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 (b) {
303
- return console.error("[EncatchPreview] Error during data validation:", b), !1;
494
+ } catch (f) {
495
+ return console.error("[EncatchPreview] Error during data validation:", f), !1;
304
496
  }
305
- })() ? u(!0) : console.warn(
497
+ })() ? p(!0) : console.warn(
306
498
  "[EncatchPreview] Data validation failed, retrying in 100ms..."
307
499
  );
308
500
  }, [t]);
309
- const T = ne(() => {
310
- t.onClose && t.onClose(), R(!1);
501
+ const T = se(() => {
502
+ t.onClose && t.onClose(), P(!1);
311
503
  }, [t.onClose]);
312
- return U(() => {
313
- if (!c || !p.current)
504
+ return S(() => {
505
+ if (!m || !E.current)
314
506
  return;
315
- const n = document.createElement("encatch-app");
316
- return n.theme = t.theme, n.currentMode = t.currentMode, n.currentLanguage = t.currentLanguage, n.questions = t.questions, n.questionLanguages = t.questionLanguages, n.otherConfigurationProperties = t.otherConfigurationProperties, n.welcomeScreenProperties = t.welcomeScreenProperties, n.endScreenProperties = t.endScreenProperties, n.translations = t.translations, n.sections = t.sections, n.themeSettings = t.themeSettings, n.onClose = T, n.onSectionChange = t.onSectionChange, n.apiKey = t.apiKey, n.hostUrl = t.hostUrl, n.feedbackConfigId = t.feedbackConfigId, n.identifier = t.identifier, n.cssLink = l, n.scale = f, n.persistMode = d, v.current = n, p.current.appendChild(n), () => {
317
- p.current && v.current && p.current.removeChild(v.current), v.current = null;
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
- }, [c, t, l, f, T, d]), m ? /* @__PURE__ */ ce.jsx("div", { ref: p }) : null;
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
- ie as EncatchPreview
524
+ de as EncatchPreview,
525
+ be as useEncatchFormEvent,
526
+ me as useEncatchFormEventAll
323
527
  };