@encatch/ws-react 0.1.0-beta.28 → 0.1.0-beta.29
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/iframe-messages.d.ts +1 -1
- package/dist/index.es.js +130 -130
- package/dist/index.umd.js +3 -3
- package/package.json +3 -3
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
/** Message types sent from parent (EncatchPreview) to iframe */
|
|
7
7
|
export type SDKMessageType = "sdk:formConfig" | "sdk:theme" | "sdk:locale" | "sdk:resetData" | "sdk:prefillResponses" | "sdk:refineTextResponse" | "sdk:submitPartialBeforeDismiss";
|
|
8
8
|
/** Message types sent from iframe to parent */
|
|
9
|
-
export type FormMessageType = "form:ready" | "form:submit" | "form:complete" | "form:close" | "form:error" | "form:resize" | "form:themeData" | "form:refineTextRequest" | "form:readyToDismiss";
|
|
9
|
+
export type FormMessageType = "form:ready" | "form:submit" | "form:complete" | "form:close" | "form:error" | "form:resize" | "form:fullscreen" | "form:themeData" | "form:refineTextRequest" | "form:readyToDismiss";
|
|
10
10
|
/** Event-publisher messages (prefixed with encatch:) from iframe to parent */
|
|
11
11
|
export type EncatchFormEventType = "encatch:form:show" | "encatch:form:started" | "encatch:form:section:change" | "encatch:form:answered";
|
|
12
12
|
export interface SDKMessage {
|
package/dist/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
var
|
|
1
|
+
import J, { useRef as U, useEffect as P, useCallback as H } from "react";
|
|
2
|
+
var N = { exports: {} }, C = {};
|
|
3
3
|
/**
|
|
4
4
|
* @license React
|
|
5
5
|
* react-jsx-runtime.production.js
|
|
@@ -9,24 +9,24 @@ var j = { 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 Z;
|
|
13
13
|
function ae() {
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
var
|
|
17
|
-
function n(a, s,
|
|
14
|
+
if (Z) return C;
|
|
15
|
+
Z = 1;
|
|
16
|
+
var c = Symbol.for("react.transitional.element"), r = Symbol.for("react.fragment");
|
|
17
|
+
function n(a, s, u) {
|
|
18
18
|
var m = null;
|
|
19
|
-
if (
|
|
20
|
-
|
|
19
|
+
if (u !== void 0 && (m = "" + u), s.key !== void 0 && (m = "" + s.key), "key" in s) {
|
|
20
|
+
u = {};
|
|
21
21
|
for (var w in s)
|
|
22
|
-
w !== "key" && (
|
|
23
|
-
} else
|
|
24
|
-
return s =
|
|
25
|
-
$$typeof:
|
|
22
|
+
w !== "key" && (u[w] = s[w]);
|
|
23
|
+
} else u = s;
|
|
24
|
+
return s = u.ref, {
|
|
25
|
+
$$typeof: c,
|
|
26
26
|
type: a,
|
|
27
27
|
key: m,
|
|
28
28
|
ref: s !== void 0 ? s : null,
|
|
29
|
-
props:
|
|
29
|
+
props: u
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
return C.Fragment = r, C.jsx = n, C.jsxs = n, C;
|
|
@@ -41,47 +41,47 @@ 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 K;
|
|
45
45
|
function se() {
|
|
46
|
-
return
|
|
47
|
-
function
|
|
46
|
+
return K || (K = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
47
|
+
function c(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 l:
|
|
54
54
|
return "Fragment";
|
|
55
|
-
case
|
|
55
|
+
case x:
|
|
56
56
|
return "Profiler";
|
|
57
57
|
case d:
|
|
58
58
|
return "StrictMode";
|
|
59
|
-
case
|
|
59
|
+
case M:
|
|
60
60
|
return "Suspense";
|
|
61
|
-
case
|
|
61
|
+
case E:
|
|
62
62
|
return "SuspenseList";
|
|
63
|
-
case
|
|
63
|
+
case o:
|
|
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 N:
|
|
71
|
-
return "Portal";
|
|
72
70
|
case F:
|
|
71
|
+
return "Portal";
|
|
72
|
+
case A:
|
|
73
73
|
return (e.displayName || "Context") + ".Provider";
|
|
74
|
-
case
|
|
74
|
+
case D:
|
|
75
75
|
return (e._context.displayName || "Context") + ".Consumer";
|
|
76
|
-
case
|
|
76
|
+
case j:
|
|
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 :
|
|
81
|
-
case
|
|
79
|
+
case S:
|
|
80
|
+
return t = e.displayName || null, t !== null ? t : c(e.type) || "Memo";
|
|
81
|
+
case R:
|
|
82
82
|
t = e._payload, e = e._init;
|
|
83
83
|
try {
|
|
84
|
-
return
|
|
84
|
+
return c(e(t));
|
|
85
85
|
} catch {
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -99,8 +99,8 @@ function se() {
|
|
|
99
99
|
}
|
|
100
100
|
if (t) {
|
|
101
101
|
t = console;
|
|
102
|
-
var
|
|
103
|
-
return
|
|
102
|
+
var f = t.error, b = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
103
|
+
return f.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,56 +108,56 @@ 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 === l) return "<>";
|
|
112
|
+
if (typeof e == "object" && e !== null && e.$$typeof === R)
|
|
113
113
|
return "<...>";
|
|
114
114
|
try {
|
|
115
|
-
var t =
|
|
115
|
+
var t = c(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 = Y.A;
|
|
123
123
|
return e === null ? null : e.getOwner();
|
|
124
124
|
}
|
|
125
|
-
function
|
|
125
|
+
function u() {
|
|
126
126
|
return Error("react-stack-top-frame");
|
|
127
127
|
}
|
|
128
128
|
function m(e) {
|
|
129
|
-
if (
|
|
129
|
+
if (V.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 f() {
|
|
137
|
+
z || (z = !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
|
+
f.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
143
|
+
get: f,
|
|
144
144
|
configurable: !0
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
147
|
function v() {
|
|
148
|
-
var e =
|
|
149
|
-
return
|
|
148
|
+
var e = c(this.type);
|
|
149
|
+
return G[e] || (G[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 h(e, t,
|
|
154
|
-
return
|
|
153
|
+
function h(e, t, f, b, k, g, W, $) {
|
|
154
|
+
return f = g.ref, e = {
|
|
155
155
|
$$typeof: I,
|
|
156
156
|
type: e,
|
|
157
157
|
key: t,
|
|
158
158
|
props: g,
|
|
159
159
|
_owner: k
|
|
160
|
-
}, (
|
|
160
|
+
}, (f !== void 0 ? f : 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: W
|
|
178
178
|
}), Object.defineProperty(e, "_debugTask", {
|
|
179
179
|
configurable: !1,
|
|
180
180
|
enumerable: !1,
|
|
181
181
|
writable: !0,
|
|
182
|
-
value:
|
|
182
|
+
value: $
|
|
183
183
|
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
184
184
|
}
|
|
185
|
-
function
|
|
185
|
+
function y(e, t, f, b, k, g, W, $) {
|
|
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
|
+
_(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 (
|
|
199
|
-
p =
|
|
197
|
+
else _(p);
|
|
198
|
+
if (V.call(t, "key")) {
|
|
199
|
+
p = c(e);
|
|
200
200
|
var T = Object.keys(t).filter(function(oe) {
|
|
201
201
|
return oe !== "key";
|
|
202
202
|
});
|
|
203
|
-
b = 0 < T.length ? "{key: someKey, " + T.join(": ..., ") + ": ...}" : "{key: someKey}",
|
|
203
|
+
b = 0 < T.length ? "{key: someKey, " + T.join(": ..., ") + ": ...}" : "{key: someKey}", X[p + b] || (T = 0 < T.length ? "{" + T.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} />
|
|
@@ -211,15 +211,15 @@ React keys must be passed directly to JSX without using spread:
|
|
|
211
211
|
p,
|
|
212
212
|
T,
|
|
213
213
|
p
|
|
214
|
-
),
|
|
214
|
+
), X[p + b] = !0);
|
|
215
215
|
}
|
|
216
|
-
if (p = null,
|
|
217
|
-
|
|
218
|
-
for (var
|
|
219
|
-
|
|
220
|
-
} else
|
|
216
|
+
if (p = null, f !== void 0 && (n(f), p = "" + f), m(t) && (n(t.key), p = "" + t.key), "key" in t) {
|
|
217
|
+
f = {};
|
|
218
|
+
for (var q in t)
|
|
219
|
+
q !== "key" && (f[q] = t[q]);
|
|
220
|
+
} else f = t;
|
|
221
221
|
return p && w(
|
|
222
|
-
|
|
222
|
+
f,
|
|
223
223
|
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
224
224
|
), h(
|
|
225
225
|
e,
|
|
@@ -227,15 +227,15 @@ React keys must be passed directly to JSX without using spread:
|
|
|
227
227
|
g,
|
|
228
228
|
k,
|
|
229
229
|
s(),
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
230
|
+
f,
|
|
231
|
+
W,
|
|
232
|
+
$
|
|
233
233
|
);
|
|
234
234
|
}
|
|
235
|
-
function
|
|
235
|
+
function _(e) {
|
|
236
236
|
typeof e == "object" && e !== null && e.$$typeof === I && e._store && (e._store.validated = 1);
|
|
237
237
|
}
|
|
238
|
-
var i =
|
|
238
|
+
var i = J, I = Symbol.for("react.transitional.element"), F = Symbol.for("react.portal"), l = Symbol.for("react.fragment"), d = Symbol.for("react.strict_mode"), x = Symbol.for("react.profiler"), D = Symbol.for("react.consumer"), A = Symbol.for("react.context"), j = Symbol.for("react.forward_ref"), M = Symbol.for("react.suspense"), E = Symbol.for("react.suspense_list"), S = Symbol.for("react.memo"), R = Symbol.for("react.lazy"), o = Symbol.for("react.activity"), te = Symbol.for("react.client.reference"), Y = i.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, V = Object.prototype.hasOwnProperty, ne = Array.isArray, L = console.createTask ? console.createTask : function() {
|
|
239
239
|
return null;
|
|
240
240
|
};
|
|
241
241
|
i = {
|
|
@@ -243,55 +243,55 @@ React keys must be passed directly to JSX without using spread:
|
|
|
243
243
|
return e();
|
|
244
244
|
}
|
|
245
245
|
};
|
|
246
|
-
var
|
|
246
|
+
var z, G = {}, B = i.react_stack_bottom_frame.bind(
|
|
247
247
|
i,
|
|
248
|
-
|
|
249
|
-
)(),
|
|
250
|
-
O.Fragment =
|
|
251
|
-
var g = 1e4 >
|
|
252
|
-
return
|
|
248
|
+
u
|
|
249
|
+
)(), Q = L(a(u)), X = {};
|
|
250
|
+
O.Fragment = l, O.jsx = function(e, t, f, b, k) {
|
|
251
|
+
var g = 1e4 > Y.recentlyCreatedOwnerStacks++;
|
|
252
|
+
return y(
|
|
253
253
|
e,
|
|
254
254
|
t,
|
|
255
|
-
|
|
255
|
+
f,
|
|
256
256
|
!1,
|
|
257
257
|
b,
|
|
258
258
|
k,
|
|
259
|
-
g ? Error("react-stack-top-frame") :
|
|
260
|
-
g ?
|
|
259
|
+
g ? Error("react-stack-top-frame") : B,
|
|
260
|
+
g ? L(a(e)) : Q
|
|
261
261
|
);
|
|
262
|
-
}, O.jsxs = function(e, t,
|
|
263
|
-
var g = 1e4 >
|
|
264
|
-
return
|
|
262
|
+
}, O.jsxs = function(e, t, f, b, k) {
|
|
263
|
+
var g = 1e4 > Y.recentlyCreatedOwnerStacks++;
|
|
264
|
+
return y(
|
|
265
265
|
e,
|
|
266
266
|
t,
|
|
267
|
-
|
|
267
|
+
f,
|
|
268
268
|
!0,
|
|
269
269
|
b,
|
|
270
270
|
k,
|
|
271
|
-
g ? Error("react-stack-top-frame") :
|
|
272
|
-
g ?
|
|
271
|
+
g ? Error("react-stack-top-frame") : B,
|
|
272
|
+
g ? L(a(e)) : Q
|
|
273
273
|
);
|
|
274
274
|
};
|
|
275
275
|
})()), O;
|
|
276
276
|
}
|
|
277
|
-
var
|
|
277
|
+
var ee;
|
|
278
278
|
function ie() {
|
|
279
|
-
return
|
|
279
|
+
return ee || (ee = 1, process.env.NODE_ENV === "production" ? N.exports = ae() : N.exports = se()), N.exports;
|
|
280
280
|
}
|
|
281
281
|
var ce = ie();
|
|
282
282
|
const fe = ({
|
|
283
|
-
formConfig:
|
|
283
|
+
formConfig: c,
|
|
284
284
|
formPageUrl: r,
|
|
285
285
|
formId: n,
|
|
286
286
|
scale: a = 100,
|
|
287
287
|
instanceId: s,
|
|
288
|
-
onFormEvent:
|
|
288
|
+
onFormEvent: u
|
|
289
289
|
}) => {
|
|
290
|
-
const m = !!(
|
|
291
|
-
}), i =
|
|
290
|
+
const m = !!(c && r), w = n ?? c?.formId ?? s ?? "preview", v = J.useRef(null), h = J.useRef(null), y = U(!1), _ = U(() => {
|
|
291
|
+
}), i = U({});
|
|
292
292
|
P(() => {
|
|
293
|
-
if (!
|
|
294
|
-
|
|
293
|
+
if (!u) return;
|
|
294
|
+
u({
|
|
295
295
|
onSubmit: (d) => {
|
|
296
296
|
i.current.onSubmit = d;
|
|
297
297
|
},
|
|
@@ -311,32 +311,32 @@ const fe = ({
|
|
|
311
311
|
i.current.onError = d;
|
|
312
312
|
}
|
|
313
313
|
});
|
|
314
|
-
}, [
|
|
315
|
-
const I =
|
|
316
|
-
if (!h.current?.contentWindow || !
|
|
317
|
-
const
|
|
314
|
+
}, [u]);
|
|
315
|
+
const I = H(() => {
|
|
316
|
+
if (!h.current?.contentWindow || !c) return;
|
|
317
|
+
const l = { formId: w, scale: a, ...c };
|
|
318
318
|
h.current.contentWindow.postMessage(
|
|
319
|
-
{ type: "sdk:formConfig", data:
|
|
319
|
+
{ type: "sdk:formConfig", data: l },
|
|
320
320
|
"*"
|
|
321
321
|
);
|
|
322
|
-
}, [
|
|
323
|
-
|
|
324
|
-
!m || !
|
|
325
|
-
}, [m,
|
|
326
|
-
const
|
|
327
|
-
|
|
322
|
+
}, [c, w, a]);
|
|
323
|
+
_.current = I, P(() => {
|
|
324
|
+
!m || !y.current || _.current();
|
|
325
|
+
}, [m, c, I]);
|
|
326
|
+
const F = H((l) => {
|
|
327
|
+
l.style.border = "none", l.style.width = "100%", l.style.height = "100%";
|
|
328
328
|
}, []);
|
|
329
329
|
return P(() => {
|
|
330
|
-
if (!m || !v.current || !
|
|
331
|
-
const
|
|
332
|
-
|
|
333
|
-
const d = document.createElement("iframe"),
|
|
334
|
-
A.searchParams.set("formId", w), A.searchParams.set("_t", String(Date.now())), d.src = A.toString(), d.title = "Encatch form",
|
|
335
|
-
const
|
|
336
|
-
const E =
|
|
330
|
+
if (!m || !v.current || !c || !r) return;
|
|
331
|
+
const l = document.createElement("div");
|
|
332
|
+
l.className = "encatch-preview-inner", 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";
|
|
333
|
+
const d = document.createElement("iframe"), x = new URL(r, window.location.origin), D = c?.isFullScreen ? "shareable" : "in-app", A = new URL(`${x.pathname}/${D}`, x.origin);
|
|
334
|
+
A.searchParams.set("formId", w), A.searchParams.set("_t", String(Date.now())), d.src = A.toString(), d.title = "Encatch form", F(d), h.current = d, l.appendChild(d), v.current.appendChild(l);
|
|
335
|
+
const j = (M) => {
|
|
336
|
+
const E = M.data;
|
|
337
337
|
if (!E || typeof E != "object" || !E.type) return;
|
|
338
|
-
let
|
|
339
|
-
switch (
|
|
338
|
+
let S = E.type, R = E.formId, o = E.data;
|
|
339
|
+
switch (S.startsWith("encatch:") && (S = S.replace("encatch:", ""), R = E.payload?.feedbackConfigurationId, o = E.payload), S) {
|
|
340
340
|
case "form:resize":
|
|
341
341
|
h.current && o && typeof o.height == "number" && (h.current.style.height = `${o.height}px`);
|
|
342
342
|
break;
|
|
@@ -344,7 +344,7 @@ const fe = ({
|
|
|
344
344
|
h.current && o?.active && (h.current.style.height = "100%");
|
|
345
345
|
break;
|
|
346
346
|
case "form:ready":
|
|
347
|
-
|
|
347
|
+
y.current = !0, _.current();
|
|
348
348
|
break;
|
|
349
349
|
case "form:close":
|
|
350
350
|
i.current.onClose?.({ timestamp: Date.now() });
|
|
@@ -377,7 +377,7 @@ const fe = ({
|
|
|
377
377
|
break;
|
|
378
378
|
case "form:section:change":
|
|
379
379
|
o && i.current.onSectionChange && i.current.onSectionChange({
|
|
380
|
-
feedbackConfigurationId: o.feedbackConfigurationId ??
|
|
380
|
+
feedbackConfigurationId: o.feedbackConfigurationId ?? R ?? "",
|
|
381
381
|
sectionIndex: o.sectionIndex,
|
|
382
382
|
sectionId: o.sectionId,
|
|
383
383
|
timestamp: Date.now()
|
|
@@ -385,7 +385,7 @@ const fe = ({
|
|
|
385
385
|
break;
|
|
386
386
|
case "form:answered":
|
|
387
387
|
o && i.current.onQuestionAnswered && i.current.onQuestionAnswered({
|
|
388
|
-
feedbackConfigurationId: o.feedbackConfigurationId ??
|
|
388
|
+
feedbackConfigurationId: o.feedbackConfigurationId ?? R ?? "",
|
|
389
389
|
questionId: o.questionId,
|
|
390
390
|
questionType: o.questionType,
|
|
391
391
|
answer: o.answer,
|
|
@@ -394,7 +394,7 @@ const fe = ({
|
|
|
394
394
|
break;
|
|
395
395
|
case "form:error":
|
|
396
396
|
o && i.current.onError && i.current.onError({
|
|
397
|
-
feedbackConfigurationId: o.feedbackConfigurationId ??
|
|
397
|
+
feedbackConfigurationId: o.feedbackConfigurationId ?? R ?? "",
|
|
398
398
|
questionId: o.questionId,
|
|
399
399
|
error: o.error ?? "Unknown error",
|
|
400
400
|
timestamp: Date.now()
|
|
@@ -402,8 +402,8 @@ const fe = ({
|
|
|
402
402
|
break;
|
|
403
403
|
}
|
|
404
404
|
};
|
|
405
|
-
return window.addEventListener("message",
|
|
406
|
-
window.removeEventListener("message",
|
|
405
|
+
return window.addEventListener("message", j), () => {
|
|
406
|
+
window.removeEventListener("message", j), y.current = !1, l.parentNode && l.parentNode.removeChild(l), h.current = null;
|
|
407
407
|
};
|
|
408
408
|
}, [m, r, w]), /* @__PURE__ */ ce.jsx(
|
|
409
409
|
"div",
|
|
@@ -447,14 +447,14 @@ class ue extends EventTarget {
|
|
|
447
447
|
* Subscribe to form events with optional form ID filtering
|
|
448
448
|
*/
|
|
449
449
|
subscribe(r, n, a) {
|
|
450
|
-
const s = Symbol("subscription"),
|
|
450
|
+
const s = Symbol("subscription"), u = {
|
|
451
451
|
eventType: r,
|
|
452
452
|
handler: n,
|
|
453
453
|
filter: a?.formId,
|
|
454
454
|
id: s,
|
|
455
455
|
once: a?.once
|
|
456
456
|
};
|
|
457
|
-
this.subscriptions.has(r) || this.subscriptions.set(r, []), this.subscriptions.get(r).push(
|
|
457
|
+
this.subscriptions.has(r) || this.subscriptions.set(r, []), this.subscriptions.get(r).push(u);
|
|
458
458
|
const m = (w) => {
|
|
459
459
|
const v = w, h = this.getFormIdFromPayload(v.detail);
|
|
460
460
|
this.matchesFilter(h, a?.formId) && (n(v.detail), a?.once && typeof window < "u" && window.removeEventListener(r, m));
|
|
@@ -468,7 +468,7 @@ class ue extends EventTarget {
|
|
|
468
468
|
*/
|
|
469
469
|
unsubscribe(r) {
|
|
470
470
|
for (const [n, a] of this.subscriptions.entries()) {
|
|
471
|
-
const s = a.findIndex((
|
|
471
|
+
const s = a.findIndex((u) => u.id === r);
|
|
472
472
|
if (s !== -1) {
|
|
473
473
|
a.splice(s, 1), a.length === 0 && this.subscriptions.delete(n);
|
|
474
474
|
break;
|
|
@@ -488,15 +488,15 @@ class ue extends EventTarget {
|
|
|
488
488
|
"form:answered",
|
|
489
489
|
"form:error"
|
|
490
490
|
], s = [];
|
|
491
|
-
return a.forEach((
|
|
491
|
+
return a.forEach((u) => {
|
|
492
492
|
const m = this.subscribe(
|
|
493
|
-
|
|
494
|
-
(w) => r(
|
|
493
|
+
u,
|
|
494
|
+
(w) => r(u, w),
|
|
495
495
|
n
|
|
496
496
|
);
|
|
497
497
|
s.push(m);
|
|
498
498
|
}), () => {
|
|
499
|
-
s.forEach((
|
|
499
|
+
s.forEach((u) => u());
|
|
500
500
|
};
|
|
501
501
|
}
|
|
502
502
|
/**
|
|
@@ -525,16 +525,16 @@ class ue extends EventTarget {
|
|
|
525
525
|
}));
|
|
526
526
|
}
|
|
527
527
|
}
|
|
528
|
-
const
|
|
529
|
-
function de(
|
|
530
|
-
P(() =>
|
|
531
|
-
|
|
528
|
+
const re = new ue();
|
|
529
|
+
function de(c, r, n) {
|
|
530
|
+
P(() => re.subscribe(
|
|
531
|
+
c,
|
|
532
532
|
r,
|
|
533
533
|
n
|
|
534
|
-
), [
|
|
534
|
+
), [c, n?.formId, r]);
|
|
535
535
|
}
|
|
536
|
-
function me(
|
|
537
|
-
P(() =>
|
|
536
|
+
function me(c, r) {
|
|
537
|
+
P(() => re.subscribeAll(c, r), [r?.formId, c]);
|
|
538
538
|
}
|
|
539
539
|
export {
|
|
540
540
|
fe as EncatchPreview,
|
package/dist/index.umd.js
CHANGED
|
@@ -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 J;function ee(){if(J)return C;J=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 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
|
|
17
|
+
*/var V;function re(){return V||(V=1,process.env.NODE_ENV!=="production"&&(function(){function c(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 f:return"Fragment";case N:return"Profiler";case d:return"StrictMode";case Y:return"Suspense";case v:return"SuspenseList";case o: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 D:return"Portal";case x:return(e.displayName||"Context")+".Provider";case M:return(e._context.displayName||"Context")+".Consumer";case F:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case I:return t=e.displayName||null,t!==null?t:c(e.type)||"Memo";case _: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 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===f)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===_)return"<...>";try{var t=c(e);return t?"<"+t+">":"<...>"}catch{return"<...>"}}function a(){var e=W.A;return e===null?null:e.getOwner()}function u(){return Error("react-stack-top-frame")}function b(e){if(B.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(){Q||(Q=!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=c(this.type);return X[e]||(X[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,l,p,R,g,$,q){return l=g.ref,e={$$typeof:P,type:e,key:t,props:g,_owner:R},(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:$}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:q}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function S(e,t,l,p,R,g,$,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(B.call(t,"key")){w=c(e);var A=Object.keys(t).filter(function(fe){return fe!=="key"});p=0<A.length?"{key: someKey, "+A.join(": ..., ")+": ...}":"{key: someKey}",K[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),
|
|
22
|
+
<%s key={someKey} {...props} />`,p,w,A,w),K[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 U in t)U!=="key"&&(l[U]=t[U])}else l=t;return w&&h(l,typeof e=="function"?e.displayName||e.name||"Unknown":e),E(e,w,g,R,a(),l,$,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"),D=Symbol.for("react.portal"),f=Symbol.for("react.fragment"),d=Symbol.for("react.strict_mode"),N=Symbol.for("react.profiler"),M=Symbol.for("react.consumer"),x=Symbol.for("react.context"),F=Symbol.for("react.forward_ref"),Y=Symbol.for("react.suspense"),v=Symbol.for("react.suspense_list"),I=Symbol.for("react.memo"),_=Symbol.for("react.lazy"),o=Symbol.for("react.activity"),ce=Symbol.for("react.client.reference"),W=i.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,B=Object.prototype.hasOwnProperty,ue=Array.isArray,L=console.createTask?console.createTask:function(){return null};i={react_stack_bottom_frame:function(e){return e()}};var Q,X={},H=i.react_stack_bottom_frame.bind(i,u)(),Z=L(s(u)),K={};O.Fragment=f,O.jsx=function(e,t,l,p,R){var g=1e4>W.recentlyCreatedOwnerStacks++;return S(e,t,l,!1,p,R,g?Error("react-stack-top-frame"):H,g?L(s(e)):Z)},O.jsxs=function(e,t,l,p,R){var g=1e4>W.recentlyCreatedOwnerStacks++;return S(e,t,l,!0,p,R,g?Error("react-stack-top-frame"):H,g?L(s(e)):Z)}})()),O}var z;function te(){return z||(z=1,process.env.NODE_ENV==="production"?j.exports=ee():j.exports=re()),j.exports}var ne=te();const oe=({formConfig:c,formPageUrl:r,formId:n,scale:s=100,instanceId:a,onFormEvent:u})=>{const b=!!(c&&r),h=n??c?.formId??a??"preview",y=m.useRef(null),E=m.useRef(null),S=m.useRef(!1),T=m.useRef(()=>{}),i=m.useRef({});m.useEffect(()=>{if(!u)return;u({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}})},[u]);const P=m.useCallback(()=>{if(!E.current?.contentWindow||!c)return;const f={formId:h,scale:s,...c};E.current.contentWindow.postMessage({type:"sdk:formConfig",data:f},"*")},[c,h,s]);T.current=P,m.useEffect(()=>{!b||!S.current||T.current()},[b,c,P]);const D=m.useCallback(f=>{f.style.border="none",f.style.width="100%",f.style.height="100%"},[]);return m.useEffect(()=>{if(!b||!y.current||!c||!r)return;const f=document.createElement("div");f.className="encatch-preview-inner",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";const d=document.createElement("iframe"),N=new URL(r,window.location.origin),M=c?.isFullScreen?"shareable":"in-app",x=new URL(`${N.pathname}/${M}`,N.origin);x.searchParams.set("formId",h),x.searchParams.set("_t",String(Date.now())),d.src=x.toString(),d.title="Encatch form",D(d),E.current=d,f.appendChild(d),y.current.appendChild(f);const F=Y=>{const v=Y.data;if(!v||typeof v!="object"||!v.type)return;let I=v.type,_=v.formId,o=v.data;switch(I.startsWith("encatch:")&&(I=I.replace("encatch:",""),_=v.payload?.feedbackConfigurationId,o=v.payload),I){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":S.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??_??"",sectionIndex:o.sectionIndex,sectionId:o.sectionId,timestamp:Date.now()});break;case"form:answered":o&&i.current.onQuestionAnswered&&i.current.onQuestionAnswered({feedbackConfigurationId:o.feedbackConfigurationId??_??"",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??_??"",questionId:o.questionId,error:o.error??"Unknown error",timestamp:Date.now()});break}};return window.addEventListener("message",F),()=>{window.removeEventListener("message",F),S.current=!1,f.parentNode&&f.parentNode.removeChild(f),E.current=null}},[b,r,h]),ne.jsx("div",{ref:y,title:"encatchPreview1",style:b?{width:"100%",height:"100%"}:void 0})};class se 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,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(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 G=new se;function ae(c,r,n){m.useEffect(()=>G.subscribe(c,r,n),[c,n?.formId,r])}function ie(c,r){m.useEffect(()=>G.subscribeAll(c,r),[r?.formId,c])}k.EncatchPreview=oe,k.useEncatchFormEvent=ae,k.useEncatchFormEventAll=ie,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@encatch/ws-react",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.29",
|
|
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/schema": "1.1.0-beta.
|
|
24
|
-
"@encatch/event-publisher": "1.0.0-beta.
|
|
23
|
+
"@encatch/schema": "1.1.0-beta.15",
|
|
24
|
+
"@encatch/event-publisher": "1.0.0-beta.5"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@eslint/js": "^9.36.0",
|