@encatch/ws-react 0.1.0-beta.31 → 0.2.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EncatchPreview.d.ts +5 -0
- package/dist/index.es.js +147 -133
- package/dist/index.umd.js +4 -4
- package/dist/types.d.ts +2 -0
- package/package.json +3 -3
package/dist/EncatchPreview.d.ts
CHANGED
|
@@ -30,6 +30,11 @@ interface EncatchPreviewProps {
|
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
32
|
onFormEvent?: OnFormEventHandler;
|
|
33
|
+
/**
|
|
34
|
+
* Pre-filled question answers. Keys are questionIds, values are the answers.
|
|
35
|
+
* Sent to the iframe via sdk:prefillResponses whenever the value changes or the iframe becomes ready.
|
|
36
|
+
*/
|
|
37
|
+
prefillResponses?: Record<string, unknown>;
|
|
33
38
|
}
|
|
34
39
|
export declare const EncatchPreview: React.FC<EncatchPreviewProps>;
|
|
35
40
|
export {};
|
package/dist/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
var
|
|
1
|
+
import G, { useRef as W, useEffect as I, useCallback as z } from "react";
|
|
2
|
+
var Y = { exports: {} }, j = {};
|
|
3
3
|
/**
|
|
4
4
|
* @license React
|
|
5
5
|
* react-jsx-runtime.production.js
|
|
@@ -9,10 +9,10 @@ var N = { exports: {} }, C = {};
|
|
|
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
|
|
12
|
+
var K;
|
|
13
13
|
function ae() {
|
|
14
|
-
if (
|
|
15
|
-
|
|
14
|
+
if (K) return j;
|
|
15
|
+
K = 1;
|
|
16
16
|
var c = Symbol.for("react.transitional.element"), r = Symbol.for("react.fragment");
|
|
17
17
|
function n(a, s, u) {
|
|
18
18
|
var m = null;
|
|
@@ -29,9 +29,9 @@ function ae() {
|
|
|
29
29
|
props: u
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
return
|
|
32
|
+
return j.Fragment = r, j.jsx = n, j.jsxs = n, j;
|
|
33
33
|
}
|
|
34
|
-
var
|
|
34
|
+
var N = {};
|
|
35
35
|
/**
|
|
36
36
|
* @license React
|
|
37
37
|
* react-jsx-runtime.development.js
|
|
@@ -41,44 +41,44 @@ var O = {};
|
|
|
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
|
|
44
|
+
var ee;
|
|
45
45
|
function se() {
|
|
46
|
-
return
|
|
46
|
+
return ee || (ee = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
47
47
|
function c(e) {
|
|
48
48
|
if (e == null) return null;
|
|
49
49
|
if (typeof e == "function")
|
|
50
|
-
return e.$$typeof ===
|
|
50
|
+
return e.$$typeof === O ? null : e.displayName || e.name || null;
|
|
51
51
|
if (typeof e == "string") return e;
|
|
52
52
|
switch (e) {
|
|
53
|
-
case
|
|
53
|
+
case A:
|
|
54
54
|
return "Fragment";
|
|
55
|
-
case
|
|
55
|
+
case L:
|
|
56
56
|
return "Profiler";
|
|
57
|
-
case
|
|
57
|
+
case P:
|
|
58
58
|
return "StrictMode";
|
|
59
|
-
case
|
|
59
|
+
case $:
|
|
60
60
|
return "Suspense";
|
|
61
|
-
case
|
|
61
|
+
case x:
|
|
62
62
|
return "SuspenseList";
|
|
63
|
-
case
|
|
63
|
+
case E:
|
|
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 f:
|
|
71
71
|
return "Portal";
|
|
72
|
-
case
|
|
72
|
+
case d:
|
|
73
73
|
return (e.displayName || "Context") + ".Provider";
|
|
74
|
-
case
|
|
74
|
+
case i:
|
|
75
75
|
return (e._context.displayName || "Context") + ".Consumer";
|
|
76
|
-
case
|
|
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
|
|
79
|
+
case D:
|
|
80
80
|
return t = e.displayName || null, t !== null ? t : c(e.type) || "Memo";
|
|
81
|
-
case
|
|
81
|
+
case M:
|
|
82
82
|
t = e._payload, e = e._init;
|
|
83
83
|
try {
|
|
84
84
|
return c(e(t));
|
|
@@ -99,8 +99,8 @@ function se() {
|
|
|
99
99
|
}
|
|
100
100
|
if (t) {
|
|
101
101
|
t = console;
|
|
102
|
-
var
|
|
103
|
-
return
|
|
102
|
+
var l = t.error, b = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
103
|
+
return l.call(
|
|
104
104
|
t,
|
|
105
105
|
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
106
106
|
b
|
|
@@ -108,8 +108,8 @@ function se() {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
function a(e) {
|
|
111
|
-
if (e ===
|
|
112
|
-
if (typeof e == "object" && e !== null && e.$$typeof ===
|
|
111
|
+
if (e === A) return "<>";
|
|
112
|
+
if (typeof e == "object" && e !== null && e.$$typeof === M)
|
|
113
113
|
return "<...>";
|
|
114
114
|
try {
|
|
115
115
|
var t = c(e);
|
|
@@ -119,45 +119,45 @@ function se() {
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
function s() {
|
|
122
|
-
var e =
|
|
122
|
+
var e = y.A;
|
|
123
123
|
return e === null ? null : e.getOwner();
|
|
124
124
|
}
|
|
125
125
|
function u() {
|
|
126
126
|
return Error("react-stack-top-frame");
|
|
127
127
|
}
|
|
128
128
|
function m(e) {
|
|
129
|
-
if (
|
|
129
|
+
if (o.call(e, "key")) {
|
|
130
130
|
var t = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
131
131
|
if (t && t.isReactWarning) return !1;
|
|
132
132
|
}
|
|
133
133
|
return e.key !== void 0;
|
|
134
134
|
}
|
|
135
135
|
function w(e, t) {
|
|
136
|
-
function
|
|
137
|
-
|
|
136
|
+
function l() {
|
|
137
|
+
B || (B = !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
|
t
|
|
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
147
|
function v() {
|
|
148
148
|
var e = c(this.type);
|
|
149
|
-
return
|
|
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
|
|
154
|
-
return
|
|
155
|
-
$$typeof:
|
|
153
|
+
function _(e, t, l, b, R, g, U, J) {
|
|
154
|
+
return l = g.ref, e = {
|
|
155
|
+
$$typeof: T,
|
|
156
156
|
type: e,
|
|
157
157
|
key: t,
|
|
158
158
|
props: g,
|
|
159
|
-
_owner:
|
|
160
|
-
}, (
|
|
159
|
+
_owner: R
|
|
160
|
+
}, (l !== void 0 ? l : null) !== null ? Object.defineProperty(e, "ref", {
|
|
161
161
|
enumerable: !1,
|
|
162
162
|
get: v
|
|
163
163
|
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
@@ -174,33 +174,33 @@ function se() {
|
|
|
174
174
|
configurable: !1,
|
|
175
175
|
enumerable: !1,
|
|
176
176
|
writable: !0,
|
|
177
|
-
value:
|
|
177
|
+
value: U
|
|
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
|
|
185
|
+
function h(e, t, l, b, R, g, U, J) {
|
|
186
186
|
var p = t.children;
|
|
187
187
|
if (p !== void 0)
|
|
188
188
|
if (b)
|
|
189
189
|
if (ne(p)) {
|
|
190
190
|
for (b = 0; b < p.length; b++)
|
|
191
|
-
|
|
191
|
+
S(p[b]);
|
|
192
192
|
Object.freeze && Object.freeze(p);
|
|
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 (
|
|
197
|
+
else S(p);
|
|
198
|
+
if (o.call(t, "key")) {
|
|
199
199
|
p = c(e);
|
|
200
|
-
var
|
|
200
|
+
var C = Object.keys(t).filter(function(oe) {
|
|
201
201
|
return oe !== "key";
|
|
202
202
|
});
|
|
203
|
-
b = 0 <
|
|
203
|
+
b = 0 < C.length ? "{key: someKey, " + C.join(": ..., ") + ": ...}" : "{key: someKey}", Z[p + b] || (C = 0 < C.length ? "{" + C.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,74 +209,74 @@ 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
|
+
C,
|
|
213
213
|
p
|
|
214
|
-
),
|
|
214
|
+
), Z[p + b] = !0);
|
|
215
215
|
}
|
|
216
|
-
if (p = null,
|
|
217
|
-
|
|
218
|
-
for (var
|
|
219
|
-
|
|
220
|
-
} else
|
|
216
|
+
if (p = null, l !== void 0 && (n(l), p = "" + l), m(t) && (n(t.key), p = "" + t.key), "key" in t) {
|
|
217
|
+
l = {};
|
|
218
|
+
for (var V in t)
|
|
219
|
+
V !== "key" && (l[V] = t[V]);
|
|
220
|
+
} else l = t;
|
|
221
221
|
return p && w(
|
|
222
|
-
|
|
222
|
+
l,
|
|
223
223
|
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
224
|
-
),
|
|
224
|
+
), _(
|
|
225
225
|
e,
|
|
226
226
|
p,
|
|
227
227
|
g,
|
|
228
|
-
|
|
228
|
+
R,
|
|
229
229
|
s(),
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
230
|
+
l,
|
|
231
|
+
U,
|
|
232
|
+
J
|
|
233
233
|
);
|
|
234
234
|
}
|
|
235
|
-
function
|
|
236
|
-
typeof e == "object" && e !== null && e.$$typeof ===
|
|
235
|
+
function S(e) {
|
|
236
|
+
typeof e == "object" && e !== null && e.$$typeof === T && e._store && (e._store.validated = 1);
|
|
237
237
|
}
|
|
238
|
-
var
|
|
238
|
+
var k = G, T = Symbol.for("react.transitional.element"), f = Symbol.for("react.portal"), A = Symbol.for("react.fragment"), P = Symbol.for("react.strict_mode"), L = Symbol.for("react.profiler"), i = 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"), D = Symbol.for("react.memo"), M = Symbol.for("react.lazy"), E = Symbol.for("react.activity"), O = Symbol.for("react.client.reference"), y = k.__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
|
+
k = {
|
|
242
242
|
react_stack_bottom_frame: function(e) {
|
|
243
243
|
return e();
|
|
244
244
|
}
|
|
245
245
|
};
|
|
246
|
-
var
|
|
247
|
-
|
|
246
|
+
var B, Q = {}, X = k.react_stack_bottom_frame.bind(
|
|
247
|
+
k,
|
|
248
248
|
u
|
|
249
|
-
)(),
|
|
250
|
-
|
|
251
|
-
var g = 1e4 >
|
|
252
|
-
return
|
|
249
|
+
)(), H = q(a(u)), Z = {};
|
|
250
|
+
N.Fragment = A, N.jsx = function(e, t, l, b, R) {
|
|
251
|
+
var g = 1e4 > y.recentlyCreatedOwnerStacks++;
|
|
252
|
+
return h(
|
|
253
253
|
e,
|
|
254
254
|
t,
|
|
255
|
-
|
|
255
|
+
l,
|
|
256
256
|
!1,
|
|
257
257
|
b,
|
|
258
|
-
|
|
259
|
-
g ? Error("react-stack-top-frame") :
|
|
260
|
-
g ?
|
|
258
|
+
R,
|
|
259
|
+
g ? Error("react-stack-top-frame") : X,
|
|
260
|
+
g ? q(a(e)) : H
|
|
261
261
|
);
|
|
262
|
-
},
|
|
263
|
-
var g = 1e4 >
|
|
264
|
-
return
|
|
262
|
+
}, N.jsxs = function(e, t, l, b, R) {
|
|
263
|
+
var g = 1e4 > y.recentlyCreatedOwnerStacks++;
|
|
264
|
+
return h(
|
|
265
265
|
e,
|
|
266
266
|
t,
|
|
267
|
-
|
|
267
|
+
l,
|
|
268
268
|
!0,
|
|
269
269
|
b,
|
|
270
|
-
|
|
271
|
-
g ? Error("react-stack-top-frame") :
|
|
272
|
-
g ?
|
|
270
|
+
R,
|
|
271
|
+
g ? Error("react-stack-top-frame") : X,
|
|
272
|
+
g ? q(a(e)) : H
|
|
273
273
|
);
|
|
274
274
|
};
|
|
275
|
-
})()),
|
|
275
|
+
})()), N;
|
|
276
276
|
}
|
|
277
|
-
var
|
|
277
|
+
var re;
|
|
278
278
|
function ie() {
|
|
279
|
-
return
|
|
279
|
+
return re || (re = 1, process.env.NODE_ENV === "production" ? Y.exports = ae() : Y.exports = se()), Y.exports;
|
|
280
280
|
}
|
|
281
281
|
var ce = ie();
|
|
282
282
|
const fe = ({
|
|
@@ -285,58 +285,72 @@ const fe = ({
|
|
|
285
285
|
formId: n,
|
|
286
286
|
scale: a = 100,
|
|
287
287
|
instanceId: s,
|
|
288
|
-
onFormEvent: u
|
|
288
|
+
onFormEvent: u,
|
|
289
|
+
prefillResponses: m
|
|
289
290
|
}) => {
|
|
290
|
-
const
|
|
291
|
-
}),
|
|
292
|
-
|
|
291
|
+
const w = !!(c && r), v = n ?? c?.formId ?? s ?? "preview", _ = G.useRef(null), h = G.useRef(null), S = W(!1), k = W(() => {
|
|
292
|
+
}), T = W(m);
|
|
293
|
+
I(() => {
|
|
294
|
+
T.current = m;
|
|
295
|
+
}, [m]);
|
|
296
|
+
const f = W({});
|
|
297
|
+
I(() => {
|
|
293
298
|
if (!u) return;
|
|
294
299
|
u({
|
|
295
300
|
onSubmit: (d) => {
|
|
296
|
-
|
|
301
|
+
f.current.onSubmit = d;
|
|
297
302
|
},
|
|
298
303
|
onShow: (d) => {
|
|
299
|
-
|
|
304
|
+
f.current.onShow = d;
|
|
300
305
|
},
|
|
301
306
|
onClose: (d) => {
|
|
302
|
-
|
|
307
|
+
f.current.onClose = d;
|
|
303
308
|
},
|
|
304
309
|
onSectionChange: (d) => {
|
|
305
|
-
|
|
310
|
+
f.current.onSectionChange = d;
|
|
306
311
|
},
|
|
307
312
|
onQuestionAnswered: (d) => {
|
|
308
|
-
|
|
313
|
+
f.current.onQuestionAnswered = d;
|
|
309
314
|
},
|
|
310
315
|
onError: (d) => {
|
|
311
|
-
|
|
316
|
+
f.current.onError = d;
|
|
312
317
|
}
|
|
313
318
|
});
|
|
314
319
|
}, [u]);
|
|
315
|
-
const
|
|
320
|
+
const A = z(() => {
|
|
316
321
|
if (!h.current?.contentWindow || !c) return;
|
|
317
|
-
const
|
|
322
|
+
const i = { formId: v, scale: a, ...c };
|
|
318
323
|
h.current.contentWindow.postMessage(
|
|
319
|
-
{ type: "sdk:formConfig", data:
|
|
324
|
+
{ type: "sdk:formConfig", data: i },
|
|
320
325
|
"*"
|
|
321
326
|
);
|
|
322
|
-
}, [c,
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
327
|
+
}, [c, v, a]);
|
|
328
|
+
k.current = A;
|
|
329
|
+
const P = z((i) => {
|
|
330
|
+
!h.current?.contentWindow || !Object.keys(i).length || h.current.contentWindow.postMessage(
|
|
331
|
+
{ type: "sdk:prefillResponses", data: { responses: i } },
|
|
332
|
+
"*"
|
|
333
|
+
);
|
|
334
|
+
}, []);
|
|
335
|
+
I(() => {
|
|
336
|
+
!w || !S.current || k.current();
|
|
337
|
+
}, [w, c, A]), I(() => {
|
|
338
|
+
!m || !S.current || P(m);
|
|
339
|
+
}, [m, P]);
|
|
340
|
+
const L = z((i) => {
|
|
341
|
+
i.style.border = "none", i.style.width = "100%", i.style.height = "100%";
|
|
328
342
|
}, []);
|
|
329
|
-
return
|
|
330
|
-
if (!
|
|
331
|
-
const
|
|
332
|
-
|
|
333
|
-
const d = document.createElement("iframe"),
|
|
334
|
-
|
|
335
|
-
const
|
|
343
|
+
return I(() => {
|
|
344
|
+
if (!w || !_.current || !c || !r) return;
|
|
345
|
+
const i = document.createElement("div");
|
|
346
|
+
i.className = "encatch-preview-inner", i.style.width = "100%", i.style.height = "100%", i.style.display = "flex", i.style.flexDirection = "column", i.style.justifyContent = "flex-end", i.style.overflow = "auto";
|
|
347
|
+
const d = document.createElement("iframe"), F = new URL(r, window.location.origin), $ = c?.isFullScreen ? "shareable" : "in-app", x = new URL(`${F.pathname}/${$}`, F.origin);
|
|
348
|
+
x.searchParams.set("formId", v), x.searchParams.set("_t", String(Date.now())), d.src = x.toString(), d.title = "Encatch form", L(d), h.current = d, i.appendChild(d), _.current.appendChild(i);
|
|
349
|
+
const D = (M) => {
|
|
336
350
|
const E = M.data;
|
|
337
351
|
if (!E || typeof E != "object" || !E.type) return;
|
|
338
|
-
let
|
|
339
|
-
switch (
|
|
352
|
+
let O = E.type, y = E.formId, o = E.data;
|
|
353
|
+
switch (O.startsWith("encatch:") && (O = O.replace("encatch:", ""), y = E.payload?.feedbackConfigurationId, o = E.payload), O) {
|
|
340
354
|
case "form:resize":
|
|
341
355
|
h.current && o && typeof o.height == "number" && (h.current.style.height = `${o.height}px`);
|
|
342
356
|
break;
|
|
@@ -344,16 +358,16 @@ const fe = ({
|
|
|
344
358
|
h.current && o?.active && (h.current.style.height = "100%");
|
|
345
359
|
break;
|
|
346
360
|
case "form:ready":
|
|
347
|
-
|
|
361
|
+
S.current = !0, k.current(), T.current && Object.keys(T.current).length && P(T.current);
|
|
348
362
|
break;
|
|
349
363
|
case "form:close":
|
|
350
|
-
|
|
364
|
+
f.current.onClose?.({ timestamp: Date.now() });
|
|
351
365
|
break;
|
|
352
366
|
case "form:complete":
|
|
353
|
-
|
|
367
|
+
f.current.onClose?.({ timestamp: Date.now() });
|
|
354
368
|
break;
|
|
355
369
|
case "form:submit":
|
|
356
|
-
o &&
|
|
370
|
+
o && f.current.onSubmit && f.current.onSubmit({
|
|
357
371
|
feedbackConfigurationId: o.feedbackConfigurationId,
|
|
358
372
|
feedbackIdentifier: o.feedbackIdentifier,
|
|
359
373
|
response: o.response,
|
|
@@ -362,30 +376,30 @@ const fe = ({
|
|
|
362
376
|
});
|
|
363
377
|
break;
|
|
364
378
|
case "form:show":
|
|
365
|
-
o &&
|
|
379
|
+
o && f.current.onShow && f.current.onShow({
|
|
366
380
|
feedbackConfigurationId: o.feedbackConfigurationId,
|
|
367
381
|
feedbackIdentifier: o.feedbackIdentifier,
|
|
368
382
|
timestamp: Date.now()
|
|
369
383
|
});
|
|
370
384
|
break;
|
|
371
385
|
case "form:started":
|
|
372
|
-
o &&
|
|
386
|
+
o && f.current.onShow && f.current.onShow({
|
|
373
387
|
feedbackConfigurationId: o.feedbackConfigurationId,
|
|
374
388
|
feedbackIdentifier: o.feedbackIdentifier,
|
|
375
389
|
timestamp: Date.now()
|
|
376
390
|
});
|
|
377
391
|
break;
|
|
378
392
|
case "form:section:change":
|
|
379
|
-
o &&
|
|
380
|
-
feedbackConfigurationId: o.feedbackConfigurationId ??
|
|
393
|
+
o && f.current.onSectionChange && f.current.onSectionChange({
|
|
394
|
+
feedbackConfigurationId: o.feedbackConfigurationId ?? y ?? "",
|
|
381
395
|
sectionIndex: o.sectionIndex,
|
|
382
396
|
sectionId: o.sectionId,
|
|
383
397
|
timestamp: Date.now()
|
|
384
398
|
});
|
|
385
399
|
break;
|
|
386
400
|
case "form:answered":
|
|
387
|
-
o &&
|
|
388
|
-
feedbackConfigurationId: o.feedbackConfigurationId ??
|
|
401
|
+
o && f.current.onQuestionAnswered && f.current.onQuestionAnswered({
|
|
402
|
+
feedbackConfigurationId: o.feedbackConfigurationId ?? y ?? "",
|
|
389
403
|
questionId: o.questionId,
|
|
390
404
|
questionType: o.questionType,
|
|
391
405
|
answer: o.answer,
|
|
@@ -393,8 +407,8 @@ const fe = ({
|
|
|
393
407
|
});
|
|
394
408
|
break;
|
|
395
409
|
case "form:error":
|
|
396
|
-
o &&
|
|
397
|
-
feedbackConfigurationId: o.feedbackConfigurationId ??
|
|
410
|
+
o && f.current.onError && f.current.onError({
|
|
411
|
+
feedbackConfigurationId: o.feedbackConfigurationId ?? y ?? "",
|
|
398
412
|
questionId: o.questionId,
|
|
399
413
|
error: o.error ?? "Unknown error",
|
|
400
414
|
timestamp: Date.now()
|
|
@@ -402,15 +416,15 @@ const fe = ({
|
|
|
402
416
|
break;
|
|
403
417
|
}
|
|
404
418
|
};
|
|
405
|
-
return window.addEventListener("message",
|
|
406
|
-
window.removeEventListener("message",
|
|
419
|
+
return window.addEventListener("message", D), () => {
|
|
420
|
+
window.removeEventListener("message", D), S.current = !1, i.parentNode && i.parentNode.removeChild(i), h.current = null;
|
|
407
421
|
};
|
|
408
|
-
}, [
|
|
422
|
+
}, [w, r, v]), /* @__PURE__ */ ce.jsx(
|
|
409
423
|
"div",
|
|
410
424
|
{
|
|
411
|
-
ref:
|
|
425
|
+
ref: _,
|
|
412
426
|
title: "encatchPreview1",
|
|
413
|
-
style:
|
|
427
|
+
style: w ? {
|
|
414
428
|
width: "100%",
|
|
415
429
|
height: "100%"
|
|
416
430
|
} : void 0
|
|
@@ -456,8 +470,8 @@ class ue extends EventTarget {
|
|
|
456
470
|
};
|
|
457
471
|
this.subscriptions.has(r) || this.subscriptions.set(r, []), this.subscriptions.get(r).push(u);
|
|
458
472
|
const m = (w) => {
|
|
459
|
-
const v = w,
|
|
460
|
-
this.matchesFilter(
|
|
473
|
+
const v = w, _ = this.getFormIdFromPayload(v.detail);
|
|
474
|
+
this.matchesFilter(_, a?.formId) && (n(v.detail), a?.once && typeof window < "u" && window.removeEventListener(r, m));
|
|
461
475
|
};
|
|
462
476
|
return typeof window < "u" && window.addEventListener(r, m), () => {
|
|
463
477
|
this.unsubscribe(s), typeof window < "u" && window.removeEventListener(r, m);
|
|
@@ -525,16 +539,16 @@ class ue extends EventTarget {
|
|
|
525
539
|
}));
|
|
526
540
|
}
|
|
527
541
|
}
|
|
528
|
-
const
|
|
542
|
+
const te = new ue();
|
|
529
543
|
function de(c, r, n) {
|
|
530
|
-
|
|
544
|
+
I(() => te.subscribe(
|
|
531
545
|
c,
|
|
532
546
|
r,
|
|
533
547
|
n
|
|
534
548
|
), [c, n?.formId, r]);
|
|
535
549
|
}
|
|
536
550
|
function me(c, r) {
|
|
537
|
-
|
|
551
|
+
I(() => te.subscribeAll(c, r), [r?.formId, c]);
|
|
538
552
|
}
|
|
539
553
|
export {
|
|
540
554
|
fe as EncatchPreview,
|
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(k,
|
|
1
|
+
(function(k,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],d):(k=typeof globalThis<"u"?globalThis:k||self,d(k.WsReact={},k.React))})(this,(function(k,d){"use strict";var D={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
|
|
9
|
+
*/var z;function re(){if(z)return x;z=1;var c=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function n(s,a,u){var b=null;if(u!==void 0&&(b=""+u),a.key!==void 0&&(b=""+a.key),"key"in a){u={};for(var h in a)h!=="key"&&(u[h]=a[h])}else u=a;return a=u.ref,{$$typeof:c,type:s,key:b,ref:a!==void 0?a:null,props:u}}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
|
|
17
|
+
*/var G;function te(){return G||(G=1,process.env.NODE_ENV!=="production"&&(function(){function c(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 L: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 l:return"Portal";case m:return(e.displayName||"Context")+".Provider";case i:return(e._context.displayName||"Context")+".Consumer";case M:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case W:return t=e.displayName||null,t!==null?t:c(e.type)||"Memo";case Y:t=e._payload,e=e._init;try{return c(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 f=t.error,p=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return f.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===Y)return"<...>";try{var t=c(e);return t?"<"+t+">":"<...>"}catch{return"<...>"}}function a(){var e=R.A;return e===null?null:e.getOwner()}function u(){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 f(){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))}f.isReactWarning=!0,Object.defineProperty(e,"key",{get:f,configurable:!0})}function y(){var e=c(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,f,p,S,v,U,J){return f=v.ref,e={$$typeof:A,type:e,key:t,props:v,_owner:S},(f!==void 0?f: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,f,p,S,v,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=c(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,
|
|
22
|
+
<%s key={someKey} {...props} />`,p,w,P,w),ee[w+p]=!0)}if(w=null,f!==void 0&&(n(f),w=""+f),b(t)&&(n(t.key),w=""+t.key),"key"in t){f={};for(var V in t)V!=="key"&&(f[V]=t[V])}else f=t;return w&&h(f,typeof e=="function"?e.displayName||e.name||"Unknown":e),T(e,w,v,S,a(),f,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"),l=Symbol.for("react.portal"),C=Symbol.for("react.fragment"),N=Symbol.for("react.strict_mode"),L=Symbol.for("react.profiler"),i=Symbol.for("react.consumer"),m=Symbol.for("react.context"),M=Symbol.for("react.forward_ref"),$=Symbol.for("react.suspense"),F=Symbol.for("react.suspense_list"),W=Symbol.for("react.memo"),Y=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(_,u)(),K=q(s(u)),ee={};j.Fragment=C,j.jsx=function(e,t,f,p,S){var v=1e4>R.recentlyCreatedOwnerStacks++;return E(e,t,f,!1,p,S,v?Error("react-stack-top-frame"):Z,v?q(s(e)):K)},j.jsxs=function(e,t,f,p,S){var v=1e4>R.recentlyCreatedOwnerStacks++;return E(e,t,f,!0,p,S,v?Error("react-stack-top-frame"):Z,v?q(s(e)):K)}})()),j}var B;function ne(){return B||(B=1,process.env.NODE_ENV==="production"?D.exports=re():D.exports=te()),D.exports}var oe=ne();const se=({formConfig:c,formPageUrl:r,formId:n,scale:s=100,instanceId:a,onFormEvent:u,prefillResponses:b})=>{const h=!!(c&&r),y=n??c?.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 l=d.useRef({});d.useEffect(()=>{if(!u)return;u({onSubmit:m=>{l.current.onSubmit=m},onShow:m=>{l.current.onShow=m},onClose:m=>{l.current.onClose=m},onSectionChange:m=>{l.current.onSectionChange=m},onQuestionAnswered:m=>{l.current.onQuestionAnswered=m},onError:m=>{l.current.onError=m}})},[u]);const C=d.useCallback(()=>{if(!E.current?.contentWindow||!c)return;const i={formId:y,scale:s,...c};E.current.contentWindow.postMessage({type:"sdk:formConfig",data:i},"*")},[c,y,s]);_.current=C;const N=d.useCallback(i=>{!E.current?.contentWindow||!Object.keys(i).length||E.current.contentWindow.postMessage({type:"sdk:prefillResponses",data:{responses:i}},"*")},[]);d.useEffect(()=>{!h||!I.current||_.current()},[h,c,C]),d.useEffect(()=>{!b||!I.current||N(b)},[b,N]);const L=d.useCallback(i=>{i.style.border="none",i.style.width="100%",i.style.height="100%"},[]);return d.useEffect(()=>{if(!h||!T.current||!c||!r)return;const i=document.createElement("div");i.className="encatch-preview-inner",i.style.width="100%",i.style.height="100%",i.style.display="flex",i.style.flexDirection="column",i.style.justifyContent="flex-end",i.style.overflow="auto";const m=document.createElement("iframe"),M=new URL(r,window.location.origin),$=c?.isFullScreen?"shareable":"in-app",F=new URL(`${M.pathname}/${$}`,M.origin);F.searchParams.set("formId",y),F.searchParams.set("_t",String(Date.now())),m.src=F.toString(),m.title="Encatch form",L(m),E.current=m,i.appendChild(m),T.current.appendChild(i);const W=Y=>{const g=Y.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":l.current.onClose?.({timestamp:Date.now()});break;case"form:complete":l.current.onClose?.({timestamp:Date.now()});break;case"form:submit":o&&l.current.onSubmit&&l.current.onSubmit({feedbackConfigurationId:o.feedbackConfigurationId,feedbackIdentifier:o.feedbackIdentifier,response:o.response,isPartialSubmit:o.isPartialSubmit,timestamp:Date.now()});break;case"form:show":o&&l.current.onShow&&l.current.onShow({feedbackConfigurationId:o.feedbackConfigurationId,feedbackIdentifier:o.feedbackIdentifier,timestamp:Date.now()});break;case"form:started":o&&l.current.onShow&&l.current.onShow({feedbackConfigurationId:o.feedbackConfigurationId,feedbackIdentifier:o.feedbackIdentifier,timestamp:Date.now()});break;case"form:section:change":o&&l.current.onSectionChange&&l.current.onSectionChange({feedbackConfigurationId:o.feedbackConfigurationId??R??"",sectionIndex:o.sectionIndex,sectionId:o.sectionId,timestamp:Date.now()});break;case"form:answered":o&&l.current.onQuestionAnswered&&l.current.onQuestionAnswered({feedbackConfigurationId:o.feedbackConfigurationId??R??"",questionId:o.questionId,questionType:o.questionType,answer:o.answer,timestamp:Date.now()});break;case"form:error":o&&l.current.onError&&l.current.onError({feedbackConfigurationId:o.feedbackConfigurationId??R??"",questionId:o.questionId,error:o.error??"Unknown error",timestamp:Date.now()});break}};return window.addEventListener("message",W),()=>{window.removeEventListener("message",W),I.current=!1,i.parentNode&&i.parentNode.removeChild(i),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"),u={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(u);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(u=>u.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"],a=[];return s.forEach(u=>{const b=this.subscribe(u,h=>r(u,h),n);a.push(b)}),()=>{a.forEach(u=>u())}}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(c,r,n){d.useEffect(()=>Q.subscribe(c,r,n),[c,n?.formId,r])}function ce(c,r){d.useEffect(()=>Q.subscribeAll(c,r),[r?.formId,c])}k.EncatchPreview=se,k.useEncatchFormEvent=ie,k.useEncatchFormEventAll=ce,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/types.d.ts
CHANGED
|
@@ -152,4 +152,6 @@ export interface EncatchPreviewIframeModeProps {
|
|
|
152
152
|
formConfig: EncatchFormConfig;
|
|
153
153
|
formPageUrl: string;
|
|
154
154
|
formId?: string;
|
|
155
|
+
/** Pre-filled question answers sent to the iframe via sdk:prefillResponses. */
|
|
156
|
+
prefillResponses?: Record<string, unknown>;
|
|
155
157
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@encatch/ws-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-beta.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.umd.js",
|
|
6
6
|
"module": "./dist/index.es.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"react-dom": "^19.1.1"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@encatch/
|
|
24
|
-
"@encatch/
|
|
23
|
+
"@encatch/schema": "1.1.0",
|
|
24
|
+
"@encatch/event-publisher": "1.0.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@eslint/js": "^9.36.0",
|