@encatch/ws-react 0.0.50-beta.6 → 0.0.50-beta.8
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/index.es.js +100 -97
- package/dist/index.umd.js +4 -4
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -13,8 +13,8 @@ var H;
|
|
|
13
13
|
function ae() {
|
|
14
14
|
if (H) return A;
|
|
15
15
|
H = 1;
|
|
16
|
-
var
|
|
17
|
-
function n(
|
|
16
|
+
var l = Symbol.for("react.transitional.element"), r = Symbol.for("react.fragment");
|
|
17
|
+
function n(a, s, c) {
|
|
18
18
|
var m = null;
|
|
19
19
|
if (c !== void 0 && (m = "" + c), s.key !== void 0 && (m = "" + s.key), "key" in s) {
|
|
20
20
|
c = {};
|
|
@@ -22,8 +22,8 @@ function ae() {
|
|
|
22
22
|
w !== "key" && (c[w] = s[w]);
|
|
23
23
|
} else c = s;
|
|
24
24
|
return s = c.ref, {
|
|
25
|
-
$$typeof:
|
|
26
|
-
type:
|
|
25
|
+
$$typeof: l,
|
|
26
|
+
type: a,
|
|
27
27
|
key: m,
|
|
28
28
|
ref: s !== void 0 ? s : null,
|
|
29
29
|
props: c
|
|
@@ -44,13 +44,13 @@ var C = {};
|
|
|
44
44
|
var Z;
|
|
45
45
|
function se() {
|
|
46
46
|
return Z || (Z = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
47
|
-
function
|
|
47
|
+
function l(e) {
|
|
48
48
|
if (e == null) return null;
|
|
49
49
|
if (typeof e == "function")
|
|
50
50
|
return e.$$typeof === te ? 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
55
|
case P:
|
|
56
56
|
return "Profiler";
|
|
@@ -73,15 +73,15 @@ function se() {
|
|
|
73
73
|
return (e.displayName || "Context") + ".Provider";
|
|
74
74
|
case x:
|
|
75
75
|
return (e._context.displayName || "Context") + ".Consumer";
|
|
76
|
-
case
|
|
76
|
+
case E:
|
|
77
77
|
var t = e.render;
|
|
78
78
|
return e = e.displayName, e || (e = t.displayName || t.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
79
|
-
case
|
|
80
|
-
return t = e.displayName || null, t !== null ? t :
|
|
79
|
+
case o:
|
|
80
|
+
return t = e.displayName || null, t !== null ? t : l(e.type) || "Memo";
|
|
81
81
|
case J:
|
|
82
82
|
t = e._payload, e = e._init;
|
|
83
83
|
try {
|
|
84
|
-
return
|
|
84
|
+
return l(e(t));
|
|
85
85
|
} catch {
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -107,12 +107,12 @@ function se() {
|
|
|
107
107
|
), r(e);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
function
|
|
111
|
-
if (e ===
|
|
110
|
+
function a(e) {
|
|
111
|
+
if (e === f) return "<>";
|
|
112
112
|
if (typeof e == "object" && e !== null && e.$$typeof === J)
|
|
113
113
|
return "<...>";
|
|
114
114
|
try {
|
|
115
|
-
var t =
|
|
115
|
+
var t = l(e);
|
|
116
116
|
return t ? "<" + t + ">" : "<...>";
|
|
117
117
|
} catch {
|
|
118
118
|
return "<...>";
|
|
@@ -145,17 +145,17 @@ function se() {
|
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
147
|
function v() {
|
|
148
|
-
var e =
|
|
148
|
+
var e = l(this.type);
|
|
149
149
|
return z[e] || (z[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 u =
|
|
153
|
+
function h(e, t, u, b, k, g, Y, W) {
|
|
154
|
+
return u = g.ref, e = {
|
|
155
155
|
$$typeof: I,
|
|
156
156
|
type: e,
|
|
157
157
|
key: t,
|
|
158
|
-
props:
|
|
158
|
+
props: g,
|
|
159
159
|
_owner: k
|
|
160
160
|
}, (u !== void 0 ? u : null) !== null ? Object.defineProperty(e, "ref", {
|
|
161
161
|
enumerable: !1,
|
|
@@ -182,7 +182,7 @@ function se() {
|
|
|
182
182
|
value: W
|
|
183
183
|
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
184
184
|
}
|
|
185
|
-
function R(e, t, u, b, k,
|
|
185
|
+
function R(e, t, u, b, k, g, Y, W) {
|
|
186
186
|
var p = t.children;
|
|
187
187
|
if (p !== void 0)
|
|
188
188
|
if (b)
|
|
@@ -196,7 +196,7 @@ function se() {
|
|
|
196
196
|
);
|
|
197
197
|
else y(p);
|
|
198
198
|
if (U.call(t, "key")) {
|
|
199
|
-
p =
|
|
199
|
+
p = l(e);
|
|
200
200
|
var S = Object.keys(t).filter(function(oe) {
|
|
201
201
|
return oe !== "key";
|
|
202
202
|
});
|
|
@@ -221,10 +221,10 @@ React keys must be passed directly to JSX without using spread:
|
|
|
221
221
|
return p && w(
|
|
222
222
|
u,
|
|
223
223
|
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
224
|
-
),
|
|
224
|
+
), h(
|
|
225
225
|
e,
|
|
226
226
|
p,
|
|
227
|
-
|
|
227
|
+
g,
|
|
228
228
|
k,
|
|
229
229
|
s(),
|
|
230
230
|
u,
|
|
@@ -235,7 +235,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
235
235
|
function y(e) {
|
|
236
236
|
typeof e == "object" && e !== null && e.$$typeof === I && e._store && (e._store.validated = 1);
|
|
237
237
|
}
|
|
238
|
-
var i = $, I = Symbol.for("react.transitional.element"), N = Symbol.for("react.portal"),
|
|
238
|
+
var i = $, I = Symbol.for("react.transitional.element"), N = Symbol.for("react.portal"), f = Symbol.for("react.fragment"), d = Symbol.for("react.strict_mode"), P = Symbol.for("react.profiler"), x = Symbol.for("react.consumer"), F = Symbol.for("react.context"), E = Symbol.for("react.forward_ref"), _ = Symbol.for("react.suspense"), T = Symbol.for("react.suspense_list"), o = Symbol.for("react.memo"), J = Symbol.for("react.lazy"), re = Symbol.for("react.activity"), te = Symbol.for("react.client.reference"), D = i.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, U = Object.prototype.hasOwnProperty, ne = Array.isArray, M = console.createTask ? console.createTask : function() {
|
|
239
239
|
return null;
|
|
240
240
|
};
|
|
241
241
|
i = {
|
|
@@ -246,9 +246,9 @@ React keys must be passed directly to JSX without using spread:
|
|
|
246
246
|
var V, z = {}, G = i.react_stack_bottom_frame.bind(
|
|
247
247
|
i,
|
|
248
248
|
c
|
|
249
|
-
)(), B = M(
|
|
250
|
-
C.Fragment =
|
|
251
|
-
var
|
|
249
|
+
)(), B = M(a(c)), Q = {};
|
|
250
|
+
C.Fragment = f, C.jsx = function(e, t, u, b, k) {
|
|
251
|
+
var g = 1e4 > D.recentlyCreatedOwnerStacks++;
|
|
252
252
|
return R(
|
|
253
253
|
e,
|
|
254
254
|
t,
|
|
@@ -256,11 +256,11 @@ React keys must be passed directly to JSX without using spread:
|
|
|
256
256
|
!1,
|
|
257
257
|
b,
|
|
258
258
|
k,
|
|
259
|
-
|
|
260
|
-
|
|
259
|
+
g ? Error("react-stack-top-frame") : G,
|
|
260
|
+
g ? M(a(e)) : B
|
|
261
261
|
);
|
|
262
262
|
}, C.jsxs = function(e, t, u, b, k) {
|
|
263
|
-
var
|
|
263
|
+
var g = 1e4 > D.recentlyCreatedOwnerStacks++;
|
|
264
264
|
return R(
|
|
265
265
|
e,
|
|
266
266
|
t,
|
|
@@ -268,8 +268,8 @@ React keys must be passed directly to JSX without using spread:
|
|
|
268
268
|
!0,
|
|
269
269
|
b,
|
|
270
270
|
k,
|
|
271
|
-
|
|
272
|
-
|
|
271
|
+
g ? Error("react-stack-top-frame") : G,
|
|
272
|
+
g ? M(a(e)) : B
|
|
273
273
|
);
|
|
274
274
|
};
|
|
275
275
|
})()), C;
|
|
@@ -279,15 +279,15 @@ function ie() {
|
|
|
279
279
|
return K || (K = 1, process.env.NODE_ENV === "production" ? j.exports = ae() : j.exports = se()), j.exports;
|
|
280
280
|
}
|
|
281
281
|
var ce = ie();
|
|
282
|
-
const
|
|
283
|
-
formConfig:
|
|
282
|
+
const fe = ({
|
|
283
|
+
formConfig: l,
|
|
284
284
|
formPageUrl: r,
|
|
285
285
|
formId: n,
|
|
286
|
-
scale:
|
|
286
|
+
scale: a = 100,
|
|
287
287
|
instanceId: s,
|
|
288
288
|
onFormEvent: c
|
|
289
289
|
}) => {
|
|
290
|
-
const m = !!(
|
|
290
|
+
const m = !!(l && r), w = n ?? l?.formId ?? s ?? "preview", v = $.useRef(null), h = $.useRef(null), R = q(!1), y = q(() => {
|
|
291
291
|
}), i = q({});
|
|
292
292
|
O(() => {
|
|
293
293
|
if (!c) return;
|
|
@@ -313,30 +313,33 @@ const le = ({
|
|
|
313
313
|
});
|
|
314
314
|
}, [c]);
|
|
315
315
|
const I = X(() => {
|
|
316
|
-
if (!
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
{ type: "sdk:formConfig", data:
|
|
316
|
+
if (!h.current?.contentWindow || !l) return;
|
|
317
|
+
const f = { formId: w, scale: a, ...l };
|
|
318
|
+
h.current.contentWindow.postMessage(
|
|
319
|
+
{ type: "sdk:formConfig", data: f },
|
|
320
320
|
"*"
|
|
321
321
|
);
|
|
322
|
-
}, [
|
|
322
|
+
}, [l, w, a]);
|
|
323
323
|
y.current = I, O(() => {
|
|
324
324
|
!m || !R.current || y.current();
|
|
325
|
-
}, [m,
|
|
326
|
-
const N = X((
|
|
327
|
-
|
|
325
|
+
}, [m, l, I]);
|
|
326
|
+
const N = X((f) => {
|
|
327
|
+
f.style.border = "none", f.style.width = "100%", f.style.height = "100%";
|
|
328
328
|
}, []);
|
|
329
329
|
return O(() => {
|
|
330
|
-
if (!m || !v.current || !
|
|
331
|
-
const
|
|
332
|
-
|
|
330
|
+
if (!m || !v.current || !l || !r) return;
|
|
331
|
+
const f = document.createElement("div");
|
|
332
|
+
f.style.width = "100%", f.style.height = "100%", f.style.display = "flex", f.style.flexDirection = "column", f.style.justifyContent = "flex-end", f.style.overflow = "auto";
|
|
333
333
|
const d = document.createElement("iframe"), P = new URL(r, window.location.origin);
|
|
334
|
-
P.searchParams.set("formId", w), d.src = P.toString(), d.title = "Encatch form", N(d),
|
|
334
|
+
P.searchParams.set("formId", w), d.src = P.toString(), d.title = "Encatch form", N(d), h.current = d, f.appendChild(d), v.current.appendChild(f);
|
|
335
335
|
const x = (F) => {
|
|
336
|
-
const
|
|
337
|
-
if (!
|
|
338
|
-
let _ =
|
|
339
|
-
switch (_.startsWith("encatch:") && (_ = _.replace("encatch:", ""), T =
|
|
336
|
+
const E = F.data;
|
|
337
|
+
if (!E || typeof E != "object" || !E.type) return;
|
|
338
|
+
let _ = E.type, T = E.formId, o = E.data;
|
|
339
|
+
switch (_.startsWith("encatch:") && (_ = _.replace("encatch:", ""), T = E.payload?.feedbackConfigurationId, o = E.payload), _) {
|
|
340
|
+
case "form:resize":
|
|
341
|
+
h.current && o && typeof o.height == "number" && (h.current.style.height = `${o.height}px`);
|
|
342
|
+
break;
|
|
340
343
|
case "form:ready":
|
|
341
344
|
R.current = !0, y.current();
|
|
342
345
|
break;
|
|
@@ -347,57 +350,57 @@ const le = ({
|
|
|
347
350
|
i.current.onClose?.({ timestamp: Date.now() });
|
|
348
351
|
break;
|
|
349
352
|
case "form:submit":
|
|
350
|
-
|
|
351
|
-
feedbackConfigurationId:
|
|
352
|
-
feedbackIdentifier:
|
|
353
|
-
response:
|
|
354
|
-
isPartialSubmit:
|
|
353
|
+
o && i.current.onSubmit && i.current.onSubmit({
|
|
354
|
+
feedbackConfigurationId: o.feedbackConfigurationId,
|
|
355
|
+
feedbackIdentifier: o.feedbackIdentifier,
|
|
356
|
+
response: o.response,
|
|
357
|
+
isPartialSubmit: o.isPartialSubmit,
|
|
355
358
|
timestamp: Date.now()
|
|
356
359
|
});
|
|
357
360
|
break;
|
|
358
361
|
case "form:show":
|
|
359
|
-
|
|
360
|
-
feedbackConfigurationId:
|
|
361
|
-
feedbackIdentifier:
|
|
362
|
+
o && i.current.onShow && i.current.onShow({
|
|
363
|
+
feedbackConfigurationId: o.feedbackConfigurationId,
|
|
364
|
+
feedbackIdentifier: o.feedbackIdentifier,
|
|
362
365
|
timestamp: Date.now()
|
|
363
366
|
});
|
|
364
367
|
break;
|
|
365
368
|
case "form:started":
|
|
366
|
-
|
|
367
|
-
feedbackConfigurationId:
|
|
368
|
-
feedbackIdentifier:
|
|
369
|
+
o && i.current.onShow && i.current.onShow({
|
|
370
|
+
feedbackConfigurationId: o.feedbackConfigurationId,
|
|
371
|
+
feedbackIdentifier: o.feedbackIdentifier,
|
|
369
372
|
timestamp: Date.now()
|
|
370
373
|
});
|
|
371
374
|
break;
|
|
372
375
|
case "form:section:change":
|
|
373
|
-
|
|
374
|
-
feedbackConfigurationId:
|
|
375
|
-
sectionIndex:
|
|
376
|
-
sectionId:
|
|
376
|
+
o && i.current.onSectionChange && i.current.onSectionChange({
|
|
377
|
+
feedbackConfigurationId: o.feedbackConfigurationId ?? T ?? "",
|
|
378
|
+
sectionIndex: o.sectionIndex,
|
|
379
|
+
sectionId: o.sectionId,
|
|
377
380
|
timestamp: Date.now()
|
|
378
381
|
});
|
|
379
382
|
break;
|
|
380
383
|
case "form:question:answered":
|
|
381
|
-
|
|
382
|
-
feedbackConfigurationId:
|
|
383
|
-
questionId:
|
|
384
|
-
questionType:
|
|
385
|
-
answer:
|
|
384
|
+
o && i.current.onQuestionAnswered && i.current.onQuestionAnswered({
|
|
385
|
+
feedbackConfigurationId: o.feedbackConfigurationId ?? T ?? "",
|
|
386
|
+
questionId: o.questionId,
|
|
387
|
+
questionType: o.questionType,
|
|
388
|
+
answer: o.answer,
|
|
386
389
|
timestamp: Date.now()
|
|
387
390
|
});
|
|
388
391
|
break;
|
|
389
392
|
case "form:error":
|
|
390
|
-
|
|
391
|
-
feedbackConfigurationId:
|
|
392
|
-
questionId:
|
|
393
|
-
error:
|
|
393
|
+
o && i.current.onError && i.current.onError({
|
|
394
|
+
feedbackConfigurationId: o.feedbackConfigurationId ?? T ?? "",
|
|
395
|
+
questionId: o.questionId,
|
|
396
|
+
error: o.error ?? "Unknown error",
|
|
394
397
|
timestamp: Date.now()
|
|
395
398
|
});
|
|
396
399
|
break;
|
|
397
400
|
}
|
|
398
401
|
};
|
|
399
402
|
return window.addEventListener("message", x), () => {
|
|
400
|
-
window.removeEventListener("message", x), R.current = !1,
|
|
403
|
+
window.removeEventListener("message", x), R.current = !1, f.parentNode && f.parentNode.removeChild(f), h.current = null;
|
|
401
404
|
};
|
|
402
405
|
}, [m, r, w]), /* @__PURE__ */ ce.jsx(
|
|
403
406
|
"div",
|
|
@@ -429,29 +432,29 @@ class ue extends EventTarget {
|
|
|
429
432
|
/**
|
|
430
433
|
* Publish an event to all matching subscribers
|
|
431
434
|
*/
|
|
432
|
-
publish(r, n,
|
|
435
|
+
publish(r, n, a) {
|
|
433
436
|
typeof window < "u" && window.dispatchEvent(
|
|
434
437
|
new CustomEvent(r, {
|
|
435
438
|
detail: n,
|
|
436
439
|
bubbles: !0
|
|
437
440
|
})
|
|
438
|
-
),
|
|
441
|
+
), a?.usePostMessage !== !1 && this.sendPostMessage(r, n);
|
|
439
442
|
}
|
|
440
443
|
/**
|
|
441
444
|
* Subscribe to form events with optional form ID filtering
|
|
442
445
|
*/
|
|
443
|
-
subscribe(r, n,
|
|
446
|
+
subscribe(r, n, a) {
|
|
444
447
|
const s = Symbol("subscription"), c = {
|
|
445
448
|
eventType: r,
|
|
446
449
|
handler: n,
|
|
447
|
-
filter:
|
|
450
|
+
filter: a?.formId,
|
|
448
451
|
id: s,
|
|
449
|
-
once:
|
|
452
|
+
once: a?.once
|
|
450
453
|
};
|
|
451
454
|
this.subscriptions.has(r) || this.subscriptions.set(r, []), this.subscriptions.get(r).push(c);
|
|
452
455
|
const m = (w) => {
|
|
453
|
-
const v = w,
|
|
454
|
-
this.matchesFilter(
|
|
456
|
+
const v = w, h = this.getFormIdFromPayload(v.detail);
|
|
457
|
+
this.matchesFilter(h, a?.formId) && (n(v.detail), a?.once && typeof window < "u" && window.removeEventListener(r, m));
|
|
455
458
|
};
|
|
456
459
|
return typeof window < "u" && window.addEventListener(r, m), () => {
|
|
457
460
|
this.unsubscribe(s), typeof window < "u" && window.removeEventListener(r, m);
|
|
@@ -461,10 +464,10 @@ class ue extends EventTarget {
|
|
|
461
464
|
* Unsubscribe by subscription ID
|
|
462
465
|
*/
|
|
463
466
|
unsubscribe(r) {
|
|
464
|
-
for (const [n,
|
|
465
|
-
const s =
|
|
467
|
+
for (const [n, a] of this.subscriptions.entries()) {
|
|
468
|
+
const s = a.findIndex((c) => c.id === r);
|
|
466
469
|
if (s !== -1) {
|
|
467
|
-
|
|
470
|
+
a.splice(s, 1), a.length === 0 && this.subscriptions.delete(n);
|
|
468
471
|
break;
|
|
469
472
|
}
|
|
470
473
|
}
|
|
@@ -473,7 +476,7 @@ class ue extends EventTarget {
|
|
|
473
476
|
* Subscribe to all form events with optional filtering
|
|
474
477
|
*/
|
|
475
478
|
subscribeAll(r, n) {
|
|
476
|
-
const
|
|
479
|
+
const a = [
|
|
477
480
|
"form:show",
|
|
478
481
|
"form:started",
|
|
479
482
|
"form:submit",
|
|
@@ -482,7 +485,7 @@ class ue extends EventTarget {
|
|
|
482
485
|
"form:question:answered",
|
|
483
486
|
"form:error"
|
|
484
487
|
], s = [];
|
|
485
|
-
return
|
|
488
|
+
return a.forEach((c) => {
|
|
486
489
|
const m = this.subscribe(
|
|
487
490
|
c,
|
|
488
491
|
(w) => r(c, w),
|
|
@@ -497,7 +500,7 @@ class ue extends EventTarget {
|
|
|
497
500
|
* Get active subscriptions count (for debugging)
|
|
498
501
|
*/
|
|
499
502
|
getSubscriptionCount(r) {
|
|
500
|
-
return r ? this.subscriptions.get(r)?.length || 0 : Array.from(this.subscriptions.values()).reduce((n,
|
|
503
|
+
return r ? this.subscriptions.get(r)?.length || 0 : Array.from(this.subscriptions.values()).reduce((n, a) => n + a.length, 0);
|
|
501
504
|
}
|
|
502
505
|
/**
|
|
503
506
|
* Clear all subscriptions for an event type (or all events)
|
|
@@ -506,13 +509,13 @@ class ue extends EventTarget {
|
|
|
506
509
|
r ? this.subscriptions.delete(r) : this.subscriptions.clear();
|
|
507
510
|
}
|
|
508
511
|
sendPostMessage(r, n) {
|
|
509
|
-
const
|
|
512
|
+
const a = {
|
|
510
513
|
type: `encatch:${r}`,
|
|
511
514
|
payload: n,
|
|
512
515
|
source: "encatch-form-engine"
|
|
513
516
|
};
|
|
514
|
-
window.parent && window.parent !== window && window.parent.postMessage(
|
|
515
|
-
s.contentWindow && s.contentWindow.postMessage(
|
|
517
|
+
window.parent && window.parent !== window && window.parent.postMessage(a, this.targetOrigin), document.querySelectorAll("iframe").forEach((s) => {
|
|
518
|
+
s.contentWindow && s.contentWindow.postMessage(a, this.targetOrigin);
|
|
516
519
|
}), typeof window.ReactNativeWebView < "u" && window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
517
520
|
action: r.replace("form:", ""),
|
|
518
521
|
data: JSON.stringify(n)
|
|
@@ -520,18 +523,18 @@ class ue extends EventTarget {
|
|
|
520
523
|
}
|
|
521
524
|
}
|
|
522
525
|
const ee = new ue();
|
|
523
|
-
function de(
|
|
526
|
+
function de(l, r, n) {
|
|
524
527
|
O(() => ee.subscribe(
|
|
525
|
-
|
|
528
|
+
l,
|
|
526
529
|
r,
|
|
527
530
|
n
|
|
528
|
-
), [
|
|
531
|
+
), [l, n?.formId, r]);
|
|
529
532
|
}
|
|
530
|
-
function me(
|
|
531
|
-
O(() => ee.subscribeAll(
|
|
533
|
+
function me(l, r) {
|
|
534
|
+
O(() => ee.subscribeAll(l, r), [r?.formId, l]);
|
|
532
535
|
}
|
|
533
536
|
export {
|
|
534
|
-
|
|
537
|
+
fe as EncatchPreview,
|
|
535
538
|
de as useEncatchFormEvent,
|
|
536
539
|
me as useEncatchFormEventAll
|
|
537
540
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(k,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],m):(k=typeof globalThis<"u"?globalThis:k||self,m(k.WsReact={},k.React))})(this,(function(k,m){"use strict";var x={exports:{}},C={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var $;function K(){if($)return C;$=1;var f=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function n(
|
|
9
|
+
*/var $;function K(){if($)return C;$=1;var f=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function n(s,a,c){var b=null;if(c!==void 0&&(b=""+c),a.key!==void 0&&(b=""+a.key),"key"in a){c={};for(var h in a)h!=="key"&&(c[h]=a[h])}else c=a;return a=c.ref,{$$typeof:f,type:s,key:b,ref:a!==void 0?a:null,props:c}}return C.Fragment=r,C.jsx=n,C.jsxs=n,C}var O={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var J;function ee(){return J||(J=1,process.env.NODE_ENV!=="production"&&(function(){function f(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===ce?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case l:return"Fragment";case
|
|
17
|
+
*/var J;function ee(){return J||(J=1,process.env.NODE_ENV!=="production"&&(function(){function f(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===ce?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case l:return"Fragment";case j:return"Profiler";case d:return"StrictMode";case S:return"Suspense";case I:return"SuspenseList";case ie:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case F:return"Portal";case D:return(e.displayName||"Context")+".Provider";case N:return(e._context.displayName||"Context")+".Consumer";case v:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case o:return t=e.displayName||null,t!==null?t:f(e.type)||"Memo";case z:t=e._payload,e=e._init;try{return f(e(t))}catch{}}return null}function r(e){return""+e}function n(e){try{r(e);var t=!1}catch{t=!0}if(t){t=console;var u=t.error,p=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return u.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",p),r(e)}}function s(e){if(e===l)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===z)return"<...>";try{var t=f(e);return t?"<"+t+">":"<...>"}catch{return"<...>"}}function a(){var e=M.A;return e===null?null:e.getOwner()}function c(){return Error("react-stack-top-frame")}function b(e){if(G.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function h(e,t){function u(){B||(B=!0,console.error("%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)",t))}u.isReactWarning=!0,Object.defineProperty(e,"key",{get:u,configurable:!0})}function y(){var e=f(this.type);return Q[e]||(Q[e]=!0,console.error("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.")),e=this.props.ref,e!==void 0?e:null}function E(e,t,u,p,R,g,W,q){return u=g.ref,e={$$typeof:P,type:e,key:t,props:g,_owner:R},(u!==void 0?u:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:y}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:W}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:q}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function _(e,t,u,p,R,g,W,q){var w=t.children;if(w!==void 0)if(p)if(ue(w)){for(p=0;p<w.length;p++)T(w[p]);Object.freeze&&Object.freeze(w)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else T(w);if(G.call(t,"key")){w=f(e);var A=Object.keys(t).filter(function(fe){return fe!=="key"});p=0<A.length?"{key: someKey, "+A.join(": ..., ")+": ...}":"{key: someKey}",Z[w+p]||(A=0<A.length?"{"+A.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
18
18
|
let props = %s;
|
|
19
19
|
<%s {...props} />
|
|
20
20
|
React keys must be passed directly to JSX without using spread:
|
|
21
21
|
let props = %s;
|
|
22
|
-
<%s key={someKey} {...props} />`,p,w,A,w),Z[w+p]=!0)}if(w=null,u!==void 0&&(n(u),w=""+u),b(t)&&(n(t.key),w=""+t.key),"key"in t){u={};for(var L in t)L!=="key"&&(u[L]=t[L])}else u=t;return w&&h(u,typeof e=="function"?e.displayName||e.name||"Unknown":e),
|
|
22
|
+
<%s key={someKey} {...props} />`,p,w,A,w),Z[w+p]=!0)}if(w=null,u!==void 0&&(n(u),w=""+u),b(t)&&(n(t.key),w=""+t.key),"key"in t){u={};for(var L in t)L!=="key"&&(u[L]=t[L])}else u=t;return w&&h(u,typeof e=="function"?e.displayName||e.name||"Unknown":e),E(e,w,g,R,a(),u,W,q)}function T(e){typeof e=="object"&&e!==null&&e.$$typeof===P&&e._store&&(e._store.validated=1)}var i=m,P=Symbol.for("react.transitional.element"),F=Symbol.for("react.portal"),l=Symbol.for("react.fragment"),d=Symbol.for("react.strict_mode"),j=Symbol.for("react.profiler"),N=Symbol.for("react.consumer"),D=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),I=Symbol.for("react.suspense_list"),o=Symbol.for("react.memo"),z=Symbol.for("react.lazy"),ie=Symbol.for("react.activity"),ce=Symbol.for("react.client.reference"),M=i.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,G=Object.prototype.hasOwnProperty,ue=Array.isArray,Y=console.createTask?console.createTask:function(){return null};i={react_stack_bottom_frame:function(e){return e()}};var B,Q={},X=i.react_stack_bottom_frame.bind(i,c)(),H=Y(s(c)),Z={};O.Fragment=l,O.jsx=function(e,t,u,p,R){var g=1e4>M.recentlyCreatedOwnerStacks++;return _(e,t,u,!1,p,R,g?Error("react-stack-top-frame"):X,g?Y(s(e)):H)},O.jsxs=function(e,t,u,p,R){var g=1e4>M.recentlyCreatedOwnerStacks++;return _(e,t,u,!0,p,R,g?Error("react-stack-top-frame"):X,g?Y(s(e)):H)}})()),O}var U;function re(){return U||(U=1,process.env.NODE_ENV==="production"?x.exports=K():x.exports=ee()),x.exports}var te=re();const ne=({formConfig:f,formPageUrl:r,formId:n,scale:s=100,instanceId:a,onFormEvent:c})=>{const b=!!(f&&r),h=n??f?.formId??a??"preview",y=m.useRef(null),E=m.useRef(null),_=m.useRef(!1),T=m.useRef(()=>{}),i=m.useRef({});m.useEffect(()=>{if(!c)return;c({onSubmit:d=>{i.current.onSubmit=d},onShow:d=>{i.current.onShow=d},onClose:d=>{i.current.onClose=d},onSectionChange:d=>{i.current.onSectionChange=d},onQuestionAnswered:d=>{i.current.onQuestionAnswered=d},onError:d=>{i.current.onError=d}})},[c]);const P=m.useCallback(()=>{if(!E.current?.contentWindow||!f)return;const l={formId:h,scale:s,...f};E.current.contentWindow.postMessage({type:"sdk:formConfig",data:l},"*")},[f,h,s]);T.current=P,m.useEffect(()=>{!b||!_.current||T.current()},[b,f,P]);const F=m.useCallback(l=>{l.style.border="none",l.style.width="100%",l.style.height="100%"},[]);return m.useEffect(()=>{if(!b||!y.current||!f||!r)return;const l=document.createElement("div");l.style.width="100%",l.style.height="100%",l.style.display="flex",l.style.flexDirection="column",l.style.justifyContent="flex-end",l.style.overflow="auto";const d=document.createElement("iframe"),j=new URL(r,window.location.origin);j.searchParams.set("formId",h),d.src=j.toString(),d.title="Encatch form",F(d),E.current=d,l.appendChild(d),y.current.appendChild(l);const N=D=>{const v=D.data;if(!v||typeof v!="object"||!v.type)return;let S=v.type,I=v.formId,o=v.data;switch(S.startsWith("encatch:")&&(S=S.replace("encatch:",""),I=v.payload?.feedbackConfigurationId,o=v.payload),S){case"form:resize":E.current&&o&&typeof o.height=="number"&&(E.current.style.height=`${o.height}px`);break;case"form:ready":_.current=!0,T.current();break;case"form:close":i.current.onClose?.({timestamp:Date.now()});break;case"form:complete":i.current.onClose?.({timestamp:Date.now()});break;case"form:submit":o&&i.current.onSubmit&&i.current.onSubmit({feedbackConfigurationId:o.feedbackConfigurationId,feedbackIdentifier:o.feedbackIdentifier,response:o.response,isPartialSubmit:o.isPartialSubmit,timestamp:Date.now()});break;case"form:show":o&&i.current.onShow&&i.current.onShow({feedbackConfigurationId:o.feedbackConfigurationId,feedbackIdentifier:o.feedbackIdentifier,timestamp:Date.now()});break;case"form:started":o&&i.current.onShow&&i.current.onShow({feedbackConfigurationId:o.feedbackConfigurationId,feedbackIdentifier:o.feedbackIdentifier,timestamp:Date.now()});break;case"form:section:change":o&&i.current.onSectionChange&&i.current.onSectionChange({feedbackConfigurationId:o.feedbackConfigurationId??I??"",sectionIndex:o.sectionIndex,sectionId:o.sectionId,timestamp:Date.now()});break;case"form:question:answered":o&&i.current.onQuestionAnswered&&i.current.onQuestionAnswered({feedbackConfigurationId:o.feedbackConfigurationId??I??"",questionId:o.questionId,questionType:o.questionType,answer:o.answer,timestamp:Date.now()});break;case"form:error":o&&i.current.onError&&i.current.onError({feedbackConfigurationId:o.feedbackConfigurationId??I??"",questionId:o.questionId,error:o.error??"Unknown error",timestamp:Date.now()});break}};return window.addEventListener("message",N),()=>{window.removeEventListener("message",N),_.current=!1,l.parentNode&&l.parentNode.removeChild(l),E.current=null}},[b,r,h]),te.jsx("div",{ref:y,title:"encatchPreview1",style:b?{width:"100%",height:"100%"}:void 0})};class oe extends EventTarget{subscriptions=new Map;targetOrigin="*";matchesFilter(r,n){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}getFormIdFromPayload(r){return r?.feedbackConfigurationId}publish(r,n,s){typeof window<"u"&&window.dispatchEvent(new CustomEvent(r,{detail:n,bubbles:!0})),s?.usePostMessage!==!1&&this.sendPostMessage(r,n)}subscribe(r,n,s){const a=Symbol("subscription"),c={eventType:r,handler:n,filter:s?.formId,id:a,once:s?.once};this.subscriptions.has(r)||this.subscriptions.set(r,[]),this.subscriptions.get(r).push(c);const b=h=>{const y=h,E=this.getFormIdFromPayload(y.detail);this.matchesFilter(E,s?.formId)&&(n(y.detail),s?.once&&typeof window<"u"&&window.removeEventListener(r,b))};return typeof window<"u"&&window.addEventListener(r,b),()=>{this.unsubscribe(a),typeof window<"u"&&window.removeEventListener(r,b)}}unsubscribe(r){for(const[n,s]of this.subscriptions.entries()){const a=s.findIndex(c=>c.id===r);if(a!==-1){s.splice(a,1),s.length===0&&this.subscriptions.delete(n);break}}}subscribeAll(r,n){const s=["form:show","form:started","form:submit","form:close","form:section:change","form:question:answered","form:error"],a=[];return s.forEach(c=>{const b=this.subscribe(c,h=>r(c,h),n);a.push(b)}),()=>{a.forEach(c=>c())}}getSubscriptionCount(r){return r?this.subscriptions.get(r)?.length||0:Array.from(this.subscriptions.values()).reduce((n,s)=>n+s.length,0)}clearSubscriptions(r){r?this.subscriptions.delete(r):this.subscriptions.clear()}sendPostMessage(r,n){const s={type:`encatch:${r}`,payload:n,source:"encatch-form-engine"};window.parent&&window.parent!==window&&window.parent.postMessage(s,this.targetOrigin),document.querySelectorAll("iframe").forEach(a=>{a.contentWindow&&a.contentWindow.postMessage(s,this.targetOrigin)}),typeof window.ReactNativeWebView<"u"&&window.ReactNativeWebView.postMessage(JSON.stringify({action:r.replace("form:",""),data:JSON.stringify(n)}))}}const V=new oe;function se(f,r,n){m.useEffect(()=>V.subscribe(f,r,n),[f,n?.formId,r])}function ae(f,r){m.useEffect(()=>V.subscribeAll(f,r),[r?.formId,f])}k.EncatchPreview=ne,k.useEncatchFormEvent=se,k.useEncatchFormEventAll=ae,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})}));
|