@encatch/ws-react 0.2.1-beta.2 → 0.2.1-beta.3
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 +133 -122
- package/dist/index.umd.js +4 -4
- package/dist/types.d.ts +9 -0
- package/package.json +2 -2
package/dist/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import G, { useRef as
|
|
2
|
-
var
|
|
1
|
+
import G, { useRef as L, useEffect as T, useCallback as z } from "react";
|
|
2
|
+
var W = { exports: {} }, j = {};
|
|
3
3
|
/**
|
|
4
4
|
* @license React
|
|
5
5
|
* react-jsx-runtime.production.js
|
|
@@ -13,20 +13,20 @@ var K;
|
|
|
13
13
|
function ae() {
|
|
14
14
|
if (K) return j;
|
|
15
15
|
K = 1;
|
|
16
|
-
var
|
|
17
|
-
function n(a, s,
|
|
16
|
+
var u = Symbol.for("react.transitional.element"), r = Symbol.for("react.fragment");
|
|
17
|
+
function n(a, s, f) {
|
|
18
18
|
var m = null;
|
|
19
|
-
if (
|
|
20
|
-
|
|
19
|
+
if (f !== void 0 && (m = "" + f), s.key !== void 0 && (m = "" + s.key), "key" in s) {
|
|
20
|
+
f = {};
|
|
21
21
|
for (var w in s)
|
|
22
|
-
w !== "key" && (
|
|
23
|
-
} else
|
|
24
|
-
return s =
|
|
25
|
-
$$typeof:
|
|
22
|
+
w !== "key" && (f[w] = s[w]);
|
|
23
|
+
} else f = s;
|
|
24
|
+
return s = f.ref, {
|
|
25
|
+
$$typeof: u,
|
|
26
26
|
type: a,
|
|
27
27
|
key: m,
|
|
28
28
|
ref: s !== void 0 ? s : null,
|
|
29
|
-
props:
|
|
29
|
+
props: f
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
return j.Fragment = r, j.jsx = n, j.jsxs = n, j;
|
|
@@ -44,15 +44,15 @@ var N = {};
|
|
|
44
44
|
var ee;
|
|
45
45
|
function se() {
|
|
46
46
|
return ee || (ee = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
47
|
-
function
|
|
47
|
+
function u(e) {
|
|
48
48
|
if (e == null) return null;
|
|
49
49
|
if (typeof e == "function")
|
|
50
|
-
return e.$$typeof ===
|
|
50
|
+
return e.$$typeof === C ? null : e.displayName || e.name || null;
|
|
51
51
|
if (typeof e == "string") return e;
|
|
52
52
|
switch (e) {
|
|
53
53
|
case A:
|
|
54
54
|
return "Fragment";
|
|
55
|
-
case
|
|
55
|
+
case Y:
|
|
56
56
|
return "Profiler";
|
|
57
57
|
case P:
|
|
58
58
|
return "StrictMode";
|
|
@@ -67,21 +67,21 @@ function se() {
|
|
|
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 d:
|
|
73
73
|
return (e.displayName || "Context") + ".Provider";
|
|
74
|
-
case
|
|
74
|
+
case c:
|
|
75
75
|
return (e._context.displayName || "Context") + ".Consumer";
|
|
76
76
|
case F:
|
|
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 D:
|
|
80
|
-
return t = e.displayName || null, t !== null ? t : c(e.type) || "Memo";
|
|
81
79
|
case M:
|
|
80
|
+
return t = e.displayName || null, t !== null ? t : u(e.type) || "Memo";
|
|
81
|
+
case D:
|
|
82
82
|
t = e._payload, e = e._init;
|
|
83
83
|
try {
|
|
84
|
-
return
|
|
84
|
+
return u(e(t));
|
|
85
85
|
} catch {
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -109,20 +109,20 @@ function se() {
|
|
|
109
109
|
}
|
|
110
110
|
function a(e) {
|
|
111
111
|
if (e === A) return "<>";
|
|
112
|
-
if (typeof e == "object" && e !== null && e.$$typeof ===
|
|
112
|
+
if (typeof e == "object" && e !== null && e.$$typeof === D)
|
|
113
113
|
return "<...>";
|
|
114
114
|
try {
|
|
115
|
-
var t =
|
|
115
|
+
var t = u(e);
|
|
116
116
|
return t ? "<" + t + ">" : "<...>";
|
|
117
117
|
} catch {
|
|
118
118
|
return "<...>";
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
function s() {
|
|
122
|
-
var e =
|
|
122
|
+
var e = v.A;
|
|
123
123
|
return e === null ? null : e.getOwner();
|
|
124
124
|
}
|
|
125
|
-
function
|
|
125
|
+
function f() {
|
|
126
126
|
return Error("react-stack-top-frame");
|
|
127
127
|
}
|
|
128
128
|
function m(e) {
|
|
@@ -144,22 +144,22 @@ function se() {
|
|
|
144
144
|
configurable: !0
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
|
-
function
|
|
148
|
-
var e =
|
|
147
|
+
function k() {
|
|
148
|
+
var e = u(this.type);
|
|
149
149
|
return Q[e] || (Q[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 _(e, t, l, b,
|
|
153
|
+
function _(e, t, l, b, y, g, U, J) {
|
|
154
154
|
return l = g.ref, e = {
|
|
155
|
-
$$typeof:
|
|
155
|
+
$$typeof: I,
|
|
156
156
|
type: e,
|
|
157
157
|
key: t,
|
|
158
158
|
props: g,
|
|
159
|
-
_owner:
|
|
159
|
+
_owner: y
|
|
160
160
|
}, (l !== void 0 ? l : null) !== null ? Object.defineProperty(e, "ref", {
|
|
161
161
|
enumerable: !1,
|
|
162
|
-
get:
|
|
162
|
+
get: k
|
|
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,
|
|
@@ -182,7 +182,7 @@ function se() {
|
|
|
182
182
|
value: J
|
|
183
183
|
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
184
184
|
}
|
|
185
|
-
function h(e, t, l, b,
|
|
185
|
+
function h(e, t, l, b, y, g, U, J) {
|
|
186
186
|
var p = t.children;
|
|
187
187
|
if (p !== void 0)
|
|
188
188
|
if (b)
|
|
@@ -196,11 +196,11 @@ function se() {
|
|
|
196
196
|
);
|
|
197
197
|
else S(p);
|
|
198
198
|
if (o.call(t, "key")) {
|
|
199
|
-
p =
|
|
200
|
-
var
|
|
199
|
+
p = u(e);
|
|
200
|
+
var O = Object.keys(t).filter(function(oe) {
|
|
201
201
|
return oe !== "key";
|
|
202
202
|
});
|
|
203
|
-
b = 0 <
|
|
203
|
+
b = 0 < O.length ? "{key: someKey, " + O.join(": ..., ") + ": ...}" : "{key: someKey}", Z[p + b] || (O = 0 < O.length ? "{" + O.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} />
|
|
@@ -209,7 +209,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
209
209
|
<%s key={someKey} {...props} />`,
|
|
210
210
|
b,
|
|
211
211
|
p,
|
|
212
|
-
|
|
212
|
+
O,
|
|
213
213
|
p
|
|
214
214
|
), Z[p + b] = !0);
|
|
215
215
|
}
|
|
@@ -225,7 +225,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
225
225
|
e,
|
|
226
226
|
p,
|
|
227
227
|
g,
|
|
228
|
-
|
|
228
|
+
y,
|
|
229
229
|
s(),
|
|
230
230
|
l,
|
|
231
231
|
U,
|
|
@@ -233,41 +233,41 @@ React keys must be passed directly to JSX without using spread:
|
|
|
233
233
|
);
|
|
234
234
|
}
|
|
235
235
|
function S(e) {
|
|
236
|
-
typeof e == "object" && e !== null && e.$$typeof ===
|
|
236
|
+
typeof e == "object" && e !== null && e.$$typeof === I && e._store && (e._store.validated = 1);
|
|
237
237
|
}
|
|
238
|
-
var
|
|
238
|
+
var R = G, I = Symbol.for("react.transitional.element"), i = Symbol.for("react.portal"), A = Symbol.for("react.fragment"), P = Symbol.for("react.strict_mode"), Y = Symbol.for("react.profiler"), c = Symbol.for("react.consumer"), d = Symbol.for("react.context"), F = Symbol.for("react.forward_ref"), $ = Symbol.for("react.suspense"), x = Symbol.for("react.suspense_list"), M = Symbol.for("react.memo"), D = Symbol.for("react.lazy"), E = Symbol.for("react.activity"), C = Symbol.for("react.client.reference"), v = R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, o = Object.prototype.hasOwnProperty, ne = Array.isArray, q = console.createTask ? console.createTask : function() {
|
|
239
239
|
return null;
|
|
240
240
|
};
|
|
241
|
-
|
|
241
|
+
R = {
|
|
242
242
|
react_stack_bottom_frame: function(e) {
|
|
243
243
|
return e();
|
|
244
244
|
}
|
|
245
245
|
};
|
|
246
|
-
var B, Q = {}, X =
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
)(), H = q(a(
|
|
250
|
-
N.Fragment = A, N.jsx = function(e, t, l, b,
|
|
251
|
-
var g = 1e4 >
|
|
246
|
+
var B, Q = {}, X = R.react_stack_bottom_frame.bind(
|
|
247
|
+
R,
|
|
248
|
+
f
|
|
249
|
+
)(), H = q(a(f)), Z = {};
|
|
250
|
+
N.Fragment = A, N.jsx = function(e, t, l, b, y) {
|
|
251
|
+
var g = 1e4 > v.recentlyCreatedOwnerStacks++;
|
|
252
252
|
return h(
|
|
253
253
|
e,
|
|
254
254
|
t,
|
|
255
255
|
l,
|
|
256
256
|
!1,
|
|
257
257
|
b,
|
|
258
|
-
|
|
258
|
+
y,
|
|
259
259
|
g ? Error("react-stack-top-frame") : X,
|
|
260
260
|
g ? q(a(e)) : H
|
|
261
261
|
);
|
|
262
|
-
}, N.jsxs = function(e, t, l, b,
|
|
263
|
-
var g = 1e4 >
|
|
262
|
+
}, N.jsxs = function(e, t, l, b, y) {
|
|
263
|
+
var g = 1e4 > v.recentlyCreatedOwnerStacks++;
|
|
264
264
|
return h(
|
|
265
265
|
e,
|
|
266
266
|
t,
|
|
267
267
|
l,
|
|
268
268
|
!0,
|
|
269
269
|
b,
|
|
270
|
-
|
|
270
|
+
y,
|
|
271
271
|
g ? Error("react-stack-top-frame") : X,
|
|
272
272
|
g ? q(a(e)) : H
|
|
273
273
|
);
|
|
@@ -276,81 +276,84 @@ React keys must be passed directly to JSX without using spread:
|
|
|
276
276
|
}
|
|
277
277
|
var re;
|
|
278
278
|
function ie() {
|
|
279
|
-
return re || (re = 1, process.env.NODE_ENV === "production" ?
|
|
279
|
+
return re || (re = 1, process.env.NODE_ENV === "production" ? W.exports = ae() : W.exports = se()), W.exports;
|
|
280
280
|
}
|
|
281
281
|
var ce = ie();
|
|
282
|
-
const
|
|
283
|
-
formConfig:
|
|
282
|
+
const le = ({
|
|
283
|
+
formConfig: u,
|
|
284
284
|
formPageUrl: r,
|
|
285
285
|
formId: n,
|
|
286
286
|
scale: a = 100,
|
|
287
287
|
instanceId: s,
|
|
288
|
-
onFormEvent:
|
|
288
|
+
onFormEvent: f,
|
|
289
289
|
prefillResponses: m
|
|
290
290
|
}) => {
|
|
291
|
-
const w = !!(
|
|
292
|
-
}),
|
|
293
|
-
|
|
294
|
-
|
|
291
|
+
const w = !!(u && r), k = n ?? u?.formId ?? s ?? "preview", _ = G.useRef(null), h = G.useRef(null), S = L(!1), R = L(() => {
|
|
292
|
+
}), I = L(m);
|
|
293
|
+
T(() => {
|
|
294
|
+
I.current = m;
|
|
295
295
|
}, [m]);
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
if (!
|
|
299
|
-
|
|
296
|
+
const i = L({});
|
|
297
|
+
T(() => {
|
|
298
|
+
if (!f) return;
|
|
299
|
+
f({
|
|
300
300
|
onSubmit: (d) => {
|
|
301
|
-
|
|
301
|
+
i.current.onSubmit = d;
|
|
302
302
|
},
|
|
303
303
|
onShow: (d) => {
|
|
304
|
-
|
|
304
|
+
i.current.onShow = d;
|
|
305
305
|
},
|
|
306
306
|
onClose: (d) => {
|
|
307
|
-
|
|
307
|
+
i.current.onClose = d;
|
|
308
308
|
},
|
|
309
309
|
onSectionChange: (d) => {
|
|
310
|
-
|
|
310
|
+
i.current.onSectionChange = d;
|
|
311
311
|
},
|
|
312
312
|
onQuestionAnswered: (d) => {
|
|
313
|
-
|
|
313
|
+
i.current.onQuestionAnswered = d;
|
|
314
314
|
},
|
|
315
315
|
onError: (d) => {
|
|
316
|
-
|
|
316
|
+
i.current.onError = d;
|
|
317
|
+
},
|
|
318
|
+
onRemindMeLater: (d) => {
|
|
319
|
+
i.current.onRemindMeLater = d;
|
|
317
320
|
}
|
|
318
321
|
});
|
|
319
|
-
}, [
|
|
322
|
+
}, [f]);
|
|
320
323
|
const A = z(() => {
|
|
321
|
-
if (!h.current?.contentWindow || !
|
|
322
|
-
const
|
|
324
|
+
if (!h.current?.contentWindow || !u) return;
|
|
325
|
+
const c = { formId: k, scale: a, ...u };
|
|
323
326
|
h.current.contentWindow.postMessage(
|
|
324
|
-
{ type: "sdk:formConfig", data:
|
|
327
|
+
{ type: "sdk:formConfig", data: c },
|
|
325
328
|
"*"
|
|
326
329
|
);
|
|
327
|
-
}, [
|
|
328
|
-
|
|
329
|
-
const P = z((
|
|
330
|
-
!h.current?.contentWindow || !Object.keys(
|
|
331
|
-
{ type: "sdk:prefillResponses", data: { responses:
|
|
330
|
+
}, [u, k, a]);
|
|
331
|
+
R.current = A;
|
|
332
|
+
const P = z((c) => {
|
|
333
|
+
!h.current?.contentWindow || !Object.keys(c).length || h.current.contentWindow.postMessage(
|
|
334
|
+
{ type: "sdk:prefillResponses", data: { responses: c } },
|
|
332
335
|
"*"
|
|
333
336
|
);
|
|
334
337
|
}, []);
|
|
335
|
-
|
|
336
|
-
!w || !S.current ||
|
|
337
|
-
}, [w,
|
|
338
|
+
T(() => {
|
|
339
|
+
!w || !S.current || R.current();
|
|
340
|
+
}, [w, u, A]), T(() => {
|
|
338
341
|
!m || !S.current || P(m);
|
|
339
342
|
}, [m, P]);
|
|
340
|
-
const
|
|
341
|
-
|
|
343
|
+
const Y = z((c) => {
|
|
344
|
+
c.style.border = "none", c.style.width = "100%", c.style.height = "100%";
|
|
342
345
|
}, []);
|
|
343
|
-
return
|
|
344
|
-
if (!w || !_.current || !
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
const d = document.createElement("iframe"), F = new URL(r, window.location.origin), $ =
|
|
348
|
-
x.searchParams.set("formId",
|
|
349
|
-
const
|
|
350
|
-
const E =
|
|
346
|
+
return T(() => {
|
|
347
|
+
if (!w || !_.current || !u || !r) return;
|
|
348
|
+
const c = document.createElement("div");
|
|
349
|
+
c.className = "encatch-preview-inner", c.style.width = "100%", c.style.height = "100%", c.style.display = "flex", c.style.flexDirection = "column", c.style.justifyContent = "flex-end", c.style.overflow = "auto";
|
|
350
|
+
const d = document.createElement("iframe"), F = new URL(r, window.location.origin), $ = u?.isFullScreen ? "shareable" : "in-app", x = new URL(`${F.pathname}/${$}`, F.origin);
|
|
351
|
+
x.searchParams.set("formId", k), x.searchParams.set("_t", String(Date.now())), d.src = x.toString(), d.title = "Encatch form", Y(d), h.current = d, c.appendChild(d), _.current.appendChild(c);
|
|
352
|
+
const M = (D) => {
|
|
353
|
+
const E = D.data;
|
|
351
354
|
if (!E || typeof E != "object" || !E.type) return;
|
|
352
|
-
let
|
|
353
|
-
switch (
|
|
355
|
+
let C = E.type, v = E.formId, o = E.data;
|
|
356
|
+
switch (C.startsWith("encatch:") && (C = C.replace("encatch:", ""), v = E.payload?.feedbackConfigurationId, o = E.payload), C) {
|
|
354
357
|
case "form:resize":
|
|
355
358
|
h.current && o && typeof o.height == "number" && (h.current.style.height = `${o.height}px`);
|
|
356
359
|
break;
|
|
@@ -358,16 +361,16 @@ const fe = ({
|
|
|
358
361
|
h.current && o?.active && (h.current.style.height = "100%");
|
|
359
362
|
break;
|
|
360
363
|
case "form:ready":
|
|
361
|
-
S.current = !0,
|
|
364
|
+
S.current = !0, R.current(), I.current && Object.keys(I.current).length && P(I.current);
|
|
362
365
|
break;
|
|
363
366
|
case "form:close":
|
|
364
|
-
|
|
367
|
+
i.current.onClose?.({ timestamp: Date.now() });
|
|
365
368
|
break;
|
|
366
369
|
case "form:complete":
|
|
367
|
-
|
|
370
|
+
i.current.onClose?.({ timestamp: Date.now() });
|
|
368
371
|
break;
|
|
369
372
|
case "form:submit":
|
|
370
|
-
o &&
|
|
373
|
+
o && i.current.onSubmit && i.current.onSubmit({
|
|
371
374
|
feedbackConfigurationId: o.feedbackConfigurationId,
|
|
372
375
|
feedbackIdentifier: o.feedbackIdentifier,
|
|
373
376
|
response: o.response,
|
|
@@ -376,30 +379,30 @@ const fe = ({
|
|
|
376
379
|
});
|
|
377
380
|
break;
|
|
378
381
|
case "form:show":
|
|
379
|
-
o &&
|
|
382
|
+
o && i.current.onShow && i.current.onShow({
|
|
380
383
|
feedbackConfigurationId: o.feedbackConfigurationId,
|
|
381
384
|
feedbackIdentifier: o.feedbackIdentifier,
|
|
382
385
|
timestamp: Date.now()
|
|
383
386
|
});
|
|
384
387
|
break;
|
|
385
388
|
case "form:started":
|
|
386
|
-
o &&
|
|
389
|
+
o && i.current.onShow && i.current.onShow({
|
|
387
390
|
feedbackConfigurationId: o.feedbackConfigurationId,
|
|
388
391
|
feedbackIdentifier: o.feedbackIdentifier,
|
|
389
392
|
timestamp: Date.now()
|
|
390
393
|
});
|
|
391
394
|
break;
|
|
392
395
|
case "form:section:change":
|
|
393
|
-
o &&
|
|
394
|
-
feedbackConfigurationId: o.feedbackConfigurationId ??
|
|
396
|
+
o && i.current.onSectionChange && i.current.onSectionChange({
|
|
397
|
+
feedbackConfigurationId: o.feedbackConfigurationId ?? v ?? "",
|
|
395
398
|
sectionIndex: o.sectionIndex,
|
|
396
399
|
sectionId: o.sectionId,
|
|
397
400
|
timestamp: Date.now()
|
|
398
401
|
});
|
|
399
402
|
break;
|
|
400
403
|
case "form:answered":
|
|
401
|
-
o &&
|
|
402
|
-
feedbackConfigurationId: o.feedbackConfigurationId ??
|
|
404
|
+
o && i.current.onQuestionAnswered && i.current.onQuestionAnswered({
|
|
405
|
+
feedbackConfigurationId: o.feedbackConfigurationId ?? v ?? "",
|
|
403
406
|
questionId: o.questionId,
|
|
404
407
|
questionType: o.questionType,
|
|
405
408
|
answer: o.answer,
|
|
@@ -407,19 +410,26 @@ const fe = ({
|
|
|
407
410
|
});
|
|
408
411
|
break;
|
|
409
412
|
case "form:error":
|
|
410
|
-
o &&
|
|
411
|
-
feedbackConfigurationId: o.feedbackConfigurationId ??
|
|
413
|
+
o && i.current.onError && i.current.onError({
|
|
414
|
+
feedbackConfigurationId: o.feedbackConfigurationId ?? v ?? "",
|
|
412
415
|
questionId: o.questionId,
|
|
413
416
|
error: o.error ?? "Unknown error",
|
|
414
417
|
timestamp: Date.now()
|
|
415
418
|
});
|
|
416
419
|
break;
|
|
420
|
+
case "form:remindmelater":
|
|
421
|
+
i.current.onRemindMeLater?.({
|
|
422
|
+
feedbackConfigurationId: o?.feedbackConfigurationId ?? v ?? "",
|
|
423
|
+
feedbackIdentifier: o?.feedbackIdentifier,
|
|
424
|
+
timestamp: Date.now()
|
|
425
|
+
});
|
|
426
|
+
break;
|
|
417
427
|
}
|
|
418
428
|
};
|
|
419
|
-
return window.addEventListener("message",
|
|
420
|
-
window.removeEventListener("message",
|
|
429
|
+
return window.addEventListener("message", M), () => {
|
|
430
|
+
window.removeEventListener("message", M), S.current = !1, c.parentNode && c.parentNode.removeChild(c), h.current = null;
|
|
421
431
|
};
|
|
422
|
-
}, [w, r,
|
|
432
|
+
}, [w, r, k]), /* @__PURE__ */ ce.jsx(
|
|
423
433
|
"div",
|
|
424
434
|
{
|
|
425
435
|
ref: _,
|
|
@@ -461,17 +471,17 @@ class ue extends EventTarget {
|
|
|
461
471
|
* Subscribe to form events with optional form ID filtering
|
|
462
472
|
*/
|
|
463
473
|
subscribe(r, n, a) {
|
|
464
|
-
const s = Symbol("subscription"),
|
|
474
|
+
const s = Symbol("subscription"), f = {
|
|
465
475
|
eventType: r,
|
|
466
476
|
handler: n,
|
|
467
477
|
filter: a?.formId,
|
|
468
478
|
id: s,
|
|
469
479
|
once: a?.once
|
|
470
480
|
};
|
|
471
|
-
this.subscriptions.has(r) || this.subscriptions.set(r, []), this.subscriptions.get(r).push(
|
|
481
|
+
this.subscriptions.has(r) || this.subscriptions.set(r, []), this.subscriptions.get(r).push(f);
|
|
472
482
|
const m = (w) => {
|
|
473
|
-
const
|
|
474
|
-
this.matchesFilter(_, a?.formId) && (n(
|
|
483
|
+
const k = w, _ = this.getFormIdFromPayload(k.detail);
|
|
484
|
+
this.matchesFilter(_, a?.formId) && (n(k.detail), a?.once && typeof window < "u" && window.removeEventListener(r, m));
|
|
475
485
|
};
|
|
476
486
|
return typeof window < "u" && window.addEventListener(r, m), () => {
|
|
477
487
|
this.unsubscribe(s), typeof window < "u" && window.removeEventListener(r, m);
|
|
@@ -482,7 +492,7 @@ class ue extends EventTarget {
|
|
|
482
492
|
*/
|
|
483
493
|
unsubscribe(r) {
|
|
484
494
|
for (const [n, a] of this.subscriptions.entries()) {
|
|
485
|
-
const s = a.findIndex((
|
|
495
|
+
const s = a.findIndex((f) => f.id === r);
|
|
486
496
|
if (s !== -1) {
|
|
487
497
|
a.splice(s, 1), a.length === 0 && this.subscriptions.delete(n);
|
|
488
498
|
break;
|
|
@@ -500,17 +510,18 @@ class ue extends EventTarget {
|
|
|
500
510
|
"form:close",
|
|
501
511
|
"form:section:change",
|
|
502
512
|
"form:answered",
|
|
503
|
-
"form:error"
|
|
513
|
+
"form:error",
|
|
514
|
+
"form:remindmelater"
|
|
504
515
|
], s = [];
|
|
505
|
-
return a.forEach((
|
|
516
|
+
return a.forEach((f) => {
|
|
506
517
|
const m = this.subscribe(
|
|
507
|
-
|
|
508
|
-
(w) => r(
|
|
518
|
+
f,
|
|
519
|
+
(w) => r(f, w),
|
|
509
520
|
n
|
|
510
521
|
);
|
|
511
522
|
s.push(m);
|
|
512
523
|
}), () => {
|
|
513
|
-
s.forEach((
|
|
524
|
+
s.forEach((f) => f());
|
|
514
525
|
};
|
|
515
526
|
}
|
|
516
527
|
/**
|
|
@@ -540,18 +551,18 @@ class ue extends EventTarget {
|
|
|
540
551
|
}
|
|
541
552
|
}
|
|
542
553
|
const te = new ue();
|
|
543
|
-
function de(
|
|
544
|
-
|
|
545
|
-
|
|
554
|
+
function de(u, r, n) {
|
|
555
|
+
T(() => te.subscribe(
|
|
556
|
+
u,
|
|
546
557
|
r,
|
|
547
558
|
n
|
|
548
|
-
), [
|
|
559
|
+
), [u, n?.formId, r]);
|
|
549
560
|
}
|
|
550
|
-
function me(
|
|
551
|
-
|
|
561
|
+
function me(u, r) {
|
|
562
|
+
T(() => te.subscribeAll(u, r), [r?.formId, u]);
|
|
552
563
|
}
|
|
553
564
|
export {
|
|
554
|
-
|
|
565
|
+
le as EncatchPreview,
|
|
555
566
|
de as useEncatchFormEvent,
|
|
556
567
|
me as useEncatchFormEventAll
|
|
557
568
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(v,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],d):(v=typeof globalThis<"u"?globalThis:v||self,d(v.WsReact={},v.React))})(this,(function(v,d){"use strict";var M={exports:{}},x={};/**
|
|
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 z;function re(){if(z)return x;z=1;var
|
|
9
|
+
*/var z;function re(){if(z)return x;z=1;var u=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function n(s,a,f){var b=null;if(f!==void 0&&(b=""+f),a.key!==void 0&&(b=""+a.key),"key"in a){f={};for(var h in a)h!=="key"&&(f[h]=a[h])}else f=a;return a=f.ref,{$$typeof:u,type:s,key:b,ref:a!==void 0?a:null,props:f}}return x.Fragment=r,x.jsx=n,x.jsxs=n,x}var j={};/**
|
|
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 G;function te(){return G||(G=1,process.env.NODE_ENV!=="production"&&(function(){function
|
|
17
|
+
*/var G;function te(){return G||(G=1,process.env.NODE_ENV!=="production"&&(function(){function u(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===O?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case C:return"Fragment";case Y:return"Profiler";case N:return"StrictMode";case $:return"Suspense";case F:return"SuspenseList";case g: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 i:return"Portal";case m:return(e.displayName||"Context")+".Provider";case c:return(e._context.displayName||"Context")+".Consumer";case D:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case L:return t=e.displayName||null,t!==null?t:u(e.type)||"Memo";case W:t=e._payload,e=e._init;try{return u(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 l=t.error,p=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return l.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===C)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===W)return"<...>";try{var t=u(e);return t?"<"+t+">":"<...>"}catch{return"<...>"}}function a(){var e=R.A;return e===null?null:e.getOwner()}function f(){return Error("react-stack-top-frame")}function b(e){if(o.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 l(){X||(X=!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))}l.isReactWarning=!0,Object.defineProperty(e,"key",{get:l,configurable:!0})}function y(){var e=u(this.type);return H[e]||(H[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 T(e,t,l,p,S,k,U,J){return l=k.ref,e={$$typeof:A,type:e,key:t,props:k,_owner:S},(l!==void 0?l: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:U}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:J}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function E(e,t,l,p,S,k,U,J){var w=t.children;if(w!==void 0)if(p)if(ue(w)){for(p=0;p<w.length;p++)I(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 I(w);if(o.call(t,"key")){w=u(e);var P=Object.keys(t).filter(function(fe){return fe!=="key"});p=0<P.length?"{key: someKey, "+P.join(": ..., ")+": ...}":"{key: someKey}",ee[w+p]||(P=0<P.length?"{"+P.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,P,w),ee[w+p]=!0)}if(w=null,
|
|
22
|
+
<%s key={someKey} {...props} />`,p,w,P,w),ee[w+p]=!0)}if(w=null,l!==void 0&&(n(l),w=""+l),b(t)&&(n(t.key),w=""+t.key),"key"in t){l={};for(var V in t)V!=="key"&&(l[V]=t[V])}else l=t;return w&&h(l,typeof e=="function"?e.displayName||e.name||"Unknown":e),T(e,w,k,S,a(),l,U,J)}function I(e){typeof e=="object"&&e!==null&&e.$$typeof===A&&e._store&&(e._store.validated=1)}var _=d,A=Symbol.for("react.transitional.element"),i=Symbol.for("react.portal"),C=Symbol.for("react.fragment"),N=Symbol.for("react.strict_mode"),Y=Symbol.for("react.profiler"),c=Symbol.for("react.consumer"),m=Symbol.for("react.context"),D=Symbol.for("react.forward_ref"),$=Symbol.for("react.suspense"),F=Symbol.for("react.suspense_list"),L=Symbol.for("react.memo"),W=Symbol.for("react.lazy"),g=Symbol.for("react.activity"),O=Symbol.for("react.client.reference"),R=_.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,o=Object.prototype.hasOwnProperty,ue=Array.isArray,q=console.createTask?console.createTask:function(){return null};_={react_stack_bottom_frame:function(e){return e()}};var X,H={},Z=_.react_stack_bottom_frame.bind(_,f)(),K=q(s(f)),ee={};j.Fragment=C,j.jsx=function(e,t,l,p,S){var k=1e4>R.recentlyCreatedOwnerStacks++;return E(e,t,l,!1,p,S,k?Error("react-stack-top-frame"):Z,k?q(s(e)):K)},j.jsxs=function(e,t,l,p,S){var k=1e4>R.recentlyCreatedOwnerStacks++;return E(e,t,l,!0,p,S,k?Error("react-stack-top-frame"):Z,k?q(s(e)):K)}})()),j}var B;function ne(){return B||(B=1,process.env.NODE_ENV==="production"?M.exports=re():M.exports=te()),M.exports}var oe=ne();const se=({formConfig:u,formPageUrl:r,formId:n,scale:s=100,instanceId:a,onFormEvent:f,prefillResponses:b})=>{const h=!!(u&&r),y=n??u?.formId??a??"preview",T=d.useRef(null),E=d.useRef(null),I=d.useRef(!1),_=d.useRef(()=>{}),A=d.useRef(b);d.useEffect(()=>{A.current=b},[b]);const i=d.useRef({});d.useEffect(()=>{if(!f)return;f({onSubmit:m=>{i.current.onSubmit=m},onShow:m=>{i.current.onShow=m},onClose:m=>{i.current.onClose=m},onSectionChange:m=>{i.current.onSectionChange=m},onQuestionAnswered:m=>{i.current.onQuestionAnswered=m},onError:m=>{i.current.onError=m},onRemindMeLater:m=>{i.current.onRemindMeLater=m}})},[f]);const C=d.useCallback(()=>{if(!E.current?.contentWindow||!u)return;const c={formId:y,scale:s,...u};E.current.contentWindow.postMessage({type:"sdk:formConfig",data:c},"*")},[u,y,s]);_.current=C;const N=d.useCallback(c=>{!E.current?.contentWindow||!Object.keys(c).length||E.current.contentWindow.postMessage({type:"sdk:prefillResponses",data:{responses:c}},"*")},[]);d.useEffect(()=>{!h||!I.current||_.current()},[h,u,C]),d.useEffect(()=>{!b||!I.current||N(b)},[b,N]);const Y=d.useCallback(c=>{c.style.border="none",c.style.width="100%",c.style.height="100%"},[]);return d.useEffect(()=>{if(!h||!T.current||!u||!r)return;const c=document.createElement("div");c.className="encatch-preview-inner",c.style.width="100%",c.style.height="100%",c.style.display="flex",c.style.flexDirection="column",c.style.justifyContent="flex-end",c.style.overflow="auto";const m=document.createElement("iframe"),D=new URL(r,window.location.origin),$=u?.isFullScreen?"shareable":"in-app",F=new URL(`${D.pathname}/${$}`,D.origin);F.searchParams.set("formId",y),F.searchParams.set("_t",String(Date.now())),m.src=F.toString(),m.title="Encatch form",Y(m),E.current=m,c.appendChild(m),T.current.appendChild(c);const L=W=>{const g=W.data;if(!g||typeof g!="object"||!g.type)return;let O=g.type,R=g.formId,o=g.data;switch(O.startsWith("encatch:")&&(O=O.replace("encatch:",""),R=g.payload?.feedbackConfigurationId,o=g.payload),O){case"form:resize":E.current&&o&&typeof o.height=="number"&&(E.current.style.height=`${o.height}px`);break;case"form:fullscreen":E.current&&o?.active&&(E.current.style.height="100%");break;case"form:ready":I.current=!0,_.current(),A.current&&Object.keys(A.current).length&&N(A.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??R??"",sectionIndex:o.sectionIndex,sectionId:o.sectionId,timestamp:Date.now()});break;case"form:answered":o&&i.current.onQuestionAnswered&&i.current.onQuestionAnswered({feedbackConfigurationId:o.feedbackConfigurationId??R??"",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??R??"",questionId:o.questionId,error:o.error??"Unknown error",timestamp:Date.now()});break;case"form:remindmelater":i.current.onRemindMeLater?.({feedbackConfigurationId:o?.feedbackConfigurationId??R??"",feedbackIdentifier:o?.feedbackIdentifier,timestamp:Date.now()});break}};return window.addEventListener("message",L),()=>{window.removeEventListener("message",L),I.current=!1,c.parentNode&&c.parentNode.removeChild(c),E.current=null}},[h,r,y]),oe.jsx("div",{ref:T,title:"encatchPreview1",style:h?{width:"100%",height:"100%"}:void 0})};class ae 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"),f={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(f);const b=h=>{const y=h,T=this.getFormIdFromPayload(y.detail);this.matchesFilter(T,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(f=>f.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:answered","form:error","form:remindmelater"],a=[];return s.forEach(f=>{const b=this.subscribe(f,h=>r(f,h),n);a.push(b)}),()=>{a.forEach(f=>f())}}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 Q=new ae;function ie(u,r,n){d.useEffect(()=>Q.subscribe(u,r,n),[u,n?.formId,r])}function ce(u,r){d.useEffect(()=>Q.subscribeAll(u,r),[r?.formId,u])}v.EncatchPreview=se,v.useEncatchFormEvent=ie,v.useEncatchFormEventAll=ce,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/types.d.ts
CHANGED
|
@@ -81,6 +81,10 @@ export type OnQuestionAnsweredCallback = (payload: FormEventPayload['form:answer
|
|
|
81
81
|
* Callback function for form error events
|
|
82
82
|
*/
|
|
83
83
|
export type OnErrorCallback = (payload: FormEventPayload['form:error']) => void;
|
|
84
|
+
/**
|
|
85
|
+
* Callback function for remind me later events
|
|
86
|
+
*/
|
|
87
|
+
export type OnRemindMeLaterCallback = (payload: FormEventPayload['form:remindmelater']) => void;
|
|
84
88
|
/**
|
|
85
89
|
* Form Event Builder - provides methods to register callbacks for different form events
|
|
86
90
|
*
|
|
@@ -138,6 +142,11 @@ export interface FormEventBuilder {
|
|
|
138
142
|
* @param callback - Function to call when an error occurs
|
|
139
143
|
*/
|
|
140
144
|
onError: (callback: OnErrorCallback) => void;
|
|
145
|
+
/**
|
|
146
|
+
* Register a callback for when the user clicks Remind Me Later on the welcome screen
|
|
147
|
+
* @param callback - Function to call when the remind me later button is clicked
|
|
148
|
+
*/
|
|
149
|
+
onRemindMeLater: (callback: OnRemindMeLaterCallback) => void;
|
|
141
150
|
}
|
|
142
151
|
/**
|
|
143
152
|
* Function type for the onFormEvent prop
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@encatch/ws-react",
|
|
3
|
-
"version": "0.2.1-beta.
|
|
3
|
+
"version": "0.2.1-beta.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.umd.js",
|
|
6
6
|
"module": "./dist/index.es.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@encatch/schema": "1.2.0-beta.2",
|
|
24
|
-
"@encatch/event-publisher": "1.0.
|
|
24
|
+
"@encatch/event-publisher": "1.0.2-beta.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@eslint/js": "^9.36.0",
|