@encatch/ws-react 0.0.50-beta.4 → 0.0.50-beta.6
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/README.md +0 -4
- package/dist/EncatchPreview.d.ts +1 -5
- package/dist/index.es.js +227 -236
- package/dist/index.umd.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -56,8 +56,6 @@ function App() {
|
|
|
56
56
|
<EncatchPreview
|
|
57
57
|
formConfig={formConfig}
|
|
58
58
|
formPageUrl="https://your-shareable-app.com/s/encatch-preview-form"
|
|
59
|
-
iframeWidth="100%"
|
|
60
|
-
iframeHeight="100%"
|
|
61
59
|
scale={100}
|
|
62
60
|
formId="unique-form-id"
|
|
63
61
|
onFormEvent={(formEvent) => {
|
|
@@ -76,8 +74,6 @@ function App() {
|
|
|
76
74
|
| `formConfig` | `EncatchFormConfig` | Yes* | - | Form configuration for the iframe. Required with formPageUrl to render. |
|
|
77
75
|
| `formPageUrl` | `string` | Yes* | - | URL of the iframe form page (e.g. shareable app route). Required with formConfig to render. |
|
|
78
76
|
| `formId` | `string` | No | from formConfig or "preview" | Form id for URL and message payloads. |
|
|
79
|
-
| `iframeWidth` | `string` | No | `"100%"` | Container width as percentage (e.g. "100%", "80%"). |
|
|
80
|
-
| `iframeHeight` | `string` | No | `"100%"` | Container height as percentage (e.g. "100%", "80%"). |
|
|
81
77
|
| `scale` | `number` | No | `100` | Visual scale of iframe content, 1–100. Applied via CSS transform. |
|
|
82
78
|
| `instanceId` | `string` | No | - | Unique identifier for filtering events. |
|
|
83
79
|
| `onFormEvent` | `OnFormEventHandler` | No | - | Event handler builder function. |
|
package/dist/EncatchPreview.d.ts
CHANGED
|
@@ -7,11 +7,7 @@ interface EncatchPreviewProps {
|
|
|
7
7
|
formPageUrl?: string;
|
|
8
8
|
/** Optional form id for iframe URL query and message payloads. Defaults to formConfig.formId or "preview". */
|
|
9
9
|
formId?: string;
|
|
10
|
-
/**
|
|
11
|
-
iframeWidth?: string;
|
|
12
|
-
/** Iframe container height as a percentage string (e.g. "100%", "80%"). Default "100%". */
|
|
13
|
-
iframeHeight?: string;
|
|
14
|
-
/** Visual scale of the iframe content, 1–100. Applied via CSS transform. Default 100. */
|
|
10
|
+
/** Visual scale of the iframe content (e.g. 1–100). Passed to the iframe in config and applied inside the form; no transform on the iframe. Default 100. */
|
|
15
11
|
scale?: number;
|
|
16
12
|
instanceId?: string;
|
|
17
13
|
/**
|
package/dist/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
var
|
|
1
|
+
import $, { useRef as q, useEffect as O, useCallback as X } from "react";
|
|
2
|
+
var j = { exports: {} }, A = {};
|
|
3
3
|
/**
|
|
4
4
|
* @license React
|
|
5
5
|
* react-jsx-runtime.production.js
|
|
@@ -9,29 +9,29 @@ var D = { exports: {} }, j = {};
|
|
|
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
|
|
13
|
-
function
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
var
|
|
17
|
-
function n(
|
|
18
|
-
var
|
|
19
|
-
if (c !== void 0 && (
|
|
12
|
+
var H;
|
|
13
|
+
function ae() {
|
|
14
|
+
if (H) return A;
|
|
15
|
+
H = 1;
|
|
16
|
+
var f = Symbol.for("react.transitional.element"), r = Symbol.for("react.fragment");
|
|
17
|
+
function n(o, s, c) {
|
|
18
|
+
var m = null;
|
|
19
|
+
if (c !== void 0 && (m = "" + c), s.key !== void 0 && (m = "" + s.key), "key" in s) {
|
|
20
20
|
c = {};
|
|
21
|
-
for (var w in
|
|
22
|
-
w !== "key" && (c[w] =
|
|
23
|
-
} else c =
|
|
24
|
-
return
|
|
25
|
-
$$typeof:
|
|
26
|
-
type:
|
|
27
|
-
key:
|
|
28
|
-
ref:
|
|
21
|
+
for (var w in s)
|
|
22
|
+
w !== "key" && (c[w] = s[w]);
|
|
23
|
+
} else c = s;
|
|
24
|
+
return s = c.ref, {
|
|
25
|
+
$$typeof: f,
|
|
26
|
+
type: o,
|
|
27
|
+
key: m,
|
|
28
|
+
ref: s !== void 0 ? s : null,
|
|
29
29
|
props: c
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
return
|
|
32
|
+
return A.Fragment = r, A.jsx = n, A.jsxs = n, A;
|
|
33
33
|
}
|
|
34
|
-
var
|
|
34
|
+
var C = {};
|
|
35
35
|
/**
|
|
36
36
|
* @license React
|
|
37
37
|
* react-jsx-runtime.development.js
|
|
@@ -41,47 +41,47 @@ var N = {};
|
|
|
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
|
|
45
|
-
function
|
|
46
|
-
return
|
|
47
|
-
function
|
|
44
|
+
var Z;
|
|
45
|
+
function se() {
|
|
46
|
+
return Z || (Z = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
47
|
+
function f(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 P:
|
|
56
56
|
return "Profiler";
|
|
57
|
-
case
|
|
57
|
+
case d:
|
|
58
58
|
return "StrictMode";
|
|
59
|
-
case
|
|
59
|
+
case _:
|
|
60
60
|
return "Suspense";
|
|
61
|
-
case
|
|
61
|
+
case T:
|
|
62
62
|
return "SuspenseList";
|
|
63
|
-
case
|
|
63
|
+
case re:
|
|
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 N:
|
|
71
71
|
return "Portal";
|
|
72
|
-
case
|
|
72
|
+
case F:
|
|
73
73
|
return (e.displayName || "Context") + ".Provider";
|
|
74
|
-
case
|
|
74
|
+
case x:
|
|
75
75
|
return (e._context.displayName || "Context") + ".Consumer";
|
|
76
|
-
case
|
|
76
|
+
case h:
|
|
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 a:
|
|
80
|
+
return t = e.displayName || null, t !== null ? t : f(e.type) || "Memo";
|
|
81
|
+
case J:
|
|
82
82
|
t = e._payload, e = e._init;
|
|
83
83
|
try {
|
|
84
|
-
return
|
|
84
|
+
return f(e(t));
|
|
85
85
|
} catch {
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -99,33 +99,33 @@ function ae() {
|
|
|
99
99
|
}
|
|
100
100
|
if (t) {
|
|
101
101
|
t = console;
|
|
102
|
-
var
|
|
103
|
-
return
|
|
102
|
+
var u = t.error, b = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
103
|
+
return u.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
|
|
107
107
|
), r(e);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
function
|
|
111
|
-
if (e ===
|
|
112
|
-
if (typeof e == "object" && e !== null && e.$$typeof ===
|
|
110
|
+
function o(e) {
|
|
111
|
+
if (e === l) return "<>";
|
|
112
|
+
if (typeof e == "object" && e !== null && e.$$typeof === J)
|
|
113
113
|
return "<...>";
|
|
114
114
|
try {
|
|
115
|
-
var t =
|
|
115
|
+
var t = f(e);
|
|
116
116
|
return t ? "<" + t + ">" : "<...>";
|
|
117
117
|
} catch {
|
|
118
118
|
return "<...>";
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
function
|
|
122
|
-
var e =
|
|
121
|
+
function s() {
|
|
122
|
+
var e = D.A;
|
|
123
123
|
return e === null ? null : e.getOwner();
|
|
124
124
|
}
|
|
125
125
|
function c() {
|
|
126
126
|
return Error("react-stack-top-frame");
|
|
127
127
|
}
|
|
128
|
-
function
|
|
128
|
+
function m(e) {
|
|
129
129
|
if (U.call(e, "key")) {
|
|
130
130
|
var t = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
131
131
|
if (t && t.isReactWarning) return !1;
|
|
@@ -133,33 +133,33 @@ function ae() {
|
|
|
133
133
|
return e.key !== void 0;
|
|
134
134
|
}
|
|
135
135
|
function w(e, t) {
|
|
136
|
-
function
|
|
137
|
-
|
|
136
|
+
function u() {
|
|
137
|
+
V || (V = !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
|
+
u.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
143
|
+
get: u,
|
|
144
144
|
configurable: !0
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
|
-
function
|
|
148
|
-
var e =
|
|
149
|
-
return
|
|
147
|
+
function v() {
|
|
148
|
+
var e = f(this.type);
|
|
149
|
+
return z[e] || (z[e] = !0, console.error(
|
|
150
150
|
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
151
151
|
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
152
152
|
}
|
|
153
|
-
function
|
|
154
|
-
return
|
|
153
|
+
function g(e, t, u, b, k, E, Y, W) {
|
|
154
|
+
return u = E.ref, e = {
|
|
155
155
|
$$typeof: I,
|
|
156
156
|
type: e,
|
|
157
157
|
key: t,
|
|
158
|
-
props:
|
|
159
|
-
_owner:
|
|
160
|
-
}, (
|
|
158
|
+
props: E,
|
|
159
|
+
_owner: k
|
|
160
|
+
}, (u !== void 0 ? u : null) !== null ? Object.defineProperty(e, "ref", {
|
|
161
161
|
enumerable: !1,
|
|
162
|
-
get:
|
|
162
|
+
get: v
|
|
163
163
|
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
164
164
|
configurable: !1,
|
|
165
165
|
enumerable: !1,
|
|
@@ -174,248 +174,239 @@ function ae() {
|
|
|
174
174
|
configurable: !1,
|
|
175
175
|
enumerable: !1,
|
|
176
176
|
writable: !0,
|
|
177
|
-
value:
|
|
177
|
+
value: Y
|
|
178
178
|
}), Object.defineProperty(e, "_debugTask", {
|
|
179
179
|
configurable: !1,
|
|
180
180
|
enumerable: !1,
|
|
181
181
|
writable: !0,
|
|
182
|
-
value:
|
|
182
|
+
value: W
|
|
183
183
|
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
184
184
|
}
|
|
185
|
-
function
|
|
186
|
-
var
|
|
187
|
-
if (
|
|
188
|
-
if (
|
|
189
|
-
if (ne(
|
|
190
|
-
for (
|
|
191
|
-
|
|
192
|
-
Object.freeze && Object.freeze(
|
|
185
|
+
function R(e, t, u, b, k, E, Y, W) {
|
|
186
|
+
var p = t.children;
|
|
187
|
+
if (p !== void 0)
|
|
188
|
+
if (b)
|
|
189
|
+
if (ne(p)) {
|
|
190
|
+
for (b = 0; b < p.length; b++)
|
|
191
|
+
y(p[b]);
|
|
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
|
|
197
|
+
else y(p);
|
|
198
198
|
if (U.call(t, "key")) {
|
|
199
|
-
|
|
200
|
-
var
|
|
199
|
+
p = f(e);
|
|
200
|
+
var S = Object.keys(t).filter(function(oe) {
|
|
201
201
|
return oe !== "key";
|
|
202
202
|
});
|
|
203
|
-
|
|
203
|
+
b = 0 < S.length ? "{key: someKey, " + S.join(": ..., ") + ": ...}" : "{key: someKey}", Q[p + b] || (S = 0 < S.length ? "{" + S.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
204
204
|
`A props object containing a "key" prop is being spread into JSX:
|
|
205
205
|
let props = %s;
|
|
206
206
|
<%s {...props} />
|
|
207
207
|
React keys must be passed directly to JSX without using spread:
|
|
208
208
|
let props = %s;
|
|
209
209
|
<%s key={someKey} {...props} />`,
|
|
210
|
-
m,
|
|
211
210
|
b,
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
211
|
+
p,
|
|
212
|
+
S,
|
|
213
|
+
p
|
|
214
|
+
), Q[p + b] = !0);
|
|
215
215
|
}
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
for (var
|
|
219
|
-
|
|
220
|
-
} else
|
|
221
|
-
return
|
|
222
|
-
|
|
216
|
+
if (p = null, u !== void 0 && (n(u), p = "" + u), m(t) && (n(t.key), p = "" + t.key), "key" in t) {
|
|
217
|
+
u = {};
|
|
218
|
+
for (var L in t)
|
|
219
|
+
L !== "key" && (u[L] = t[L]);
|
|
220
|
+
} else u = t;
|
|
221
|
+
return p && w(
|
|
222
|
+
u,
|
|
223
223
|
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
224
|
-
),
|
|
224
|
+
), g(
|
|
225
225
|
e,
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
226
|
+
p,
|
|
227
|
+
E,
|
|
228
|
+
k,
|
|
229
|
+
s(),
|
|
230
|
+
u,
|
|
231
|
+
Y,
|
|
232
|
+
W
|
|
233
233
|
);
|
|
234
234
|
}
|
|
235
|
-
function
|
|
235
|
+
function y(e) {
|
|
236
236
|
typeof e == "object" && e !== null && e.$$typeof === I && e._store && (e._store.validated = 1);
|
|
237
237
|
}
|
|
238
|
-
var
|
|
238
|
+
var i = $, I = Symbol.for("react.transitional.element"), N = Symbol.for("react.portal"), l = Symbol.for("react.fragment"), d = Symbol.for("react.strict_mode"), P = Symbol.for("react.profiler"), x = Symbol.for("react.consumer"), F = Symbol.for("react.context"), h = Symbol.for("react.forward_ref"), _ = Symbol.for("react.suspense"), T = Symbol.for("react.suspense_list"), a = Symbol.for("react.memo"), J = Symbol.for("react.lazy"), re = Symbol.for("react.activity"), te = Symbol.for("react.client.reference"), D = i.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, U = Object.prototype.hasOwnProperty, ne = Array.isArray, M = console.createTask ? console.createTask : function() {
|
|
239
239
|
return null;
|
|
240
240
|
};
|
|
241
|
-
|
|
241
|
+
i = {
|
|
242
242
|
react_stack_bottom_frame: function(e) {
|
|
243
243
|
return e();
|
|
244
244
|
}
|
|
245
245
|
};
|
|
246
|
-
var
|
|
247
|
-
|
|
246
|
+
var V, z = {}, G = i.react_stack_bottom_frame.bind(
|
|
247
|
+
i,
|
|
248
248
|
c
|
|
249
|
-
)(),
|
|
250
|
-
|
|
251
|
-
var
|
|
252
|
-
return
|
|
249
|
+
)(), B = M(o(c)), Q = {};
|
|
250
|
+
C.Fragment = l, C.jsx = function(e, t, u, b, k) {
|
|
251
|
+
var E = 1e4 > D.recentlyCreatedOwnerStacks++;
|
|
252
|
+
return R(
|
|
253
253
|
e,
|
|
254
254
|
t,
|
|
255
|
-
|
|
255
|
+
u,
|
|
256
256
|
!1,
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
257
|
+
b,
|
|
258
|
+
k,
|
|
259
|
+
E ? Error("react-stack-top-frame") : G,
|
|
260
|
+
E ? M(o(e)) : B
|
|
261
261
|
);
|
|
262
|
-
},
|
|
263
|
-
var
|
|
264
|
-
return
|
|
262
|
+
}, C.jsxs = function(e, t, u, b, k) {
|
|
263
|
+
var E = 1e4 > D.recentlyCreatedOwnerStacks++;
|
|
264
|
+
return R(
|
|
265
265
|
e,
|
|
266
266
|
t,
|
|
267
|
-
|
|
267
|
+
u,
|
|
268
268
|
!0,
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
269
|
+
b,
|
|
270
|
+
k,
|
|
271
|
+
E ? Error("react-stack-top-frame") : G,
|
|
272
|
+
E ? M(o(e)) : B
|
|
273
273
|
);
|
|
274
274
|
};
|
|
275
|
-
})()),
|
|
275
|
+
})()), C;
|
|
276
276
|
}
|
|
277
|
-
var
|
|
277
|
+
var K;
|
|
278
278
|
function ie() {
|
|
279
|
-
return
|
|
279
|
+
return K || (K = 1, process.env.NODE_ENV === "production" ? j.exports = ae() : j.exports = se()), j.exports;
|
|
280
280
|
}
|
|
281
281
|
var ce = ie();
|
|
282
|
-
const
|
|
283
|
-
formConfig:
|
|
282
|
+
const le = ({
|
|
283
|
+
formConfig: f,
|
|
284
284
|
formPageUrl: r,
|
|
285
285
|
formId: n,
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
instanceId: p,
|
|
290
|
-
onFormEvent: w
|
|
286
|
+
scale: o = 100,
|
|
287
|
+
instanceId: s,
|
|
288
|
+
onFormEvent: c
|
|
291
289
|
}) => {
|
|
292
|
-
const
|
|
293
|
-
}),
|
|
294
|
-
|
|
295
|
-
if (!
|
|
296
|
-
|
|
290
|
+
const m = !!(f && r), w = n ?? f?.formId ?? s ?? "preview", v = $.useRef(null), g = $.useRef(null), R = q(!1), y = q(() => {
|
|
291
|
+
}), i = q({});
|
|
292
|
+
O(() => {
|
|
293
|
+
if (!c) return;
|
|
294
|
+
c({
|
|
297
295
|
onSubmit: (d) => {
|
|
298
|
-
|
|
296
|
+
i.current.onSubmit = d;
|
|
299
297
|
},
|
|
300
298
|
onShow: (d) => {
|
|
301
|
-
|
|
299
|
+
i.current.onShow = d;
|
|
302
300
|
},
|
|
303
301
|
onClose: (d) => {
|
|
304
|
-
|
|
302
|
+
i.current.onClose = d;
|
|
305
303
|
},
|
|
306
304
|
onSectionChange: (d) => {
|
|
307
|
-
|
|
305
|
+
i.current.onSectionChange = d;
|
|
308
306
|
},
|
|
309
307
|
onQuestionAnswered: (d) => {
|
|
310
|
-
|
|
308
|
+
i.current.onQuestionAnswered = d;
|
|
311
309
|
},
|
|
312
310
|
onError: (d) => {
|
|
313
|
-
|
|
311
|
+
i.current.onError = d;
|
|
314
312
|
}
|
|
315
313
|
});
|
|
316
|
-
}, [
|
|
317
|
-
const
|
|
318
|
-
if (!
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
{ type: "sdk:formConfig", data:
|
|
314
|
+
}, [c]);
|
|
315
|
+
const I = X(() => {
|
|
316
|
+
if (!g.current?.contentWindow || !f) return;
|
|
317
|
+
const l = { formId: w, scale: o, ...f };
|
|
318
|
+
g.current.contentWindow.postMessage(
|
|
319
|
+
{ type: "sdk:formConfig", data: l },
|
|
322
320
|
"*"
|
|
323
321
|
);
|
|
324
|
-
}, [
|
|
325
|
-
|
|
326
|
-
!
|
|
327
|
-
}, [
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
k.searchParams.set("formId", R), d.src = k.toString(), d.title = "Encatch form", x(d, c), v.current = d, u.appendChild(d), S.current.appendChild(u);
|
|
343
|
-
const F = (M) => {
|
|
344
|
-
const E = M.data;
|
|
345
|
-
if (!E || typeof E != "object" || !E.type) return;
|
|
346
|
-
let O = E.type, T = E.formId, o = E.data;
|
|
347
|
-
switch (O.startsWith("encatch:") && (O = O.replace("encatch:", ""), T = E.payload?.feedbackConfigurationId, o = E.payload), O) {
|
|
322
|
+
}, [f, w, o]);
|
|
323
|
+
y.current = I, O(() => {
|
|
324
|
+
!m || !R.current || y.current();
|
|
325
|
+
}, [m, f, I]);
|
|
326
|
+
const N = X((l) => {
|
|
327
|
+
l.style.border = "none", l.style.width = "100%", l.style.height = "100%";
|
|
328
|
+
}, []);
|
|
329
|
+
return O(() => {
|
|
330
|
+
if (!m || !v.current || !f || !r) return;
|
|
331
|
+
const l = document.createElement("div");
|
|
332
|
+
l.style.width = "100%", l.style.height = "100%", l.style.overflow = "hidden";
|
|
333
|
+
const d = document.createElement("iframe"), P = new URL(r, window.location.origin);
|
|
334
|
+
P.searchParams.set("formId", w), d.src = P.toString(), d.title = "Encatch form", N(d), g.current = d, l.appendChild(d), v.current.appendChild(l);
|
|
335
|
+
const x = (F) => {
|
|
336
|
+
const h = F.data;
|
|
337
|
+
if (!h || typeof h != "object" || !h.type) return;
|
|
338
|
+
let _ = h.type, T = h.formId, a = h.data;
|
|
339
|
+
switch (_.startsWith("encatch:") && (_ = _.replace("encatch:", ""), T = h.payload?.feedbackConfigurationId, a = h.payload), _) {
|
|
348
340
|
case "form:ready":
|
|
349
|
-
|
|
341
|
+
R.current = !0, y.current();
|
|
350
342
|
break;
|
|
351
343
|
case "form:close":
|
|
352
|
-
|
|
344
|
+
i.current.onClose?.({ timestamp: Date.now() });
|
|
353
345
|
break;
|
|
354
346
|
case "form:complete":
|
|
355
|
-
|
|
347
|
+
i.current.onClose?.({ timestamp: Date.now() });
|
|
356
348
|
break;
|
|
357
349
|
case "form:submit":
|
|
358
|
-
|
|
359
|
-
feedbackConfigurationId:
|
|
360
|
-
feedbackIdentifier:
|
|
361
|
-
response:
|
|
362
|
-
isPartialSubmit:
|
|
350
|
+
a && i.current.onSubmit && i.current.onSubmit({
|
|
351
|
+
feedbackConfigurationId: a.feedbackConfigurationId,
|
|
352
|
+
feedbackIdentifier: a.feedbackIdentifier,
|
|
353
|
+
response: a.response,
|
|
354
|
+
isPartialSubmit: a.isPartialSubmit,
|
|
363
355
|
timestamp: Date.now()
|
|
364
356
|
});
|
|
365
357
|
break;
|
|
366
358
|
case "form:show":
|
|
367
|
-
|
|
368
|
-
feedbackConfigurationId:
|
|
369
|
-
feedbackIdentifier:
|
|
359
|
+
a && i.current.onShow && i.current.onShow({
|
|
360
|
+
feedbackConfigurationId: a.feedbackConfigurationId,
|
|
361
|
+
feedbackIdentifier: a.feedbackIdentifier,
|
|
370
362
|
timestamp: Date.now()
|
|
371
363
|
});
|
|
372
364
|
break;
|
|
373
365
|
case "form:started":
|
|
374
|
-
|
|
375
|
-
feedbackConfigurationId:
|
|
376
|
-
feedbackIdentifier:
|
|
366
|
+
a && i.current.onShow && i.current.onShow({
|
|
367
|
+
feedbackConfigurationId: a.feedbackConfigurationId,
|
|
368
|
+
feedbackIdentifier: a.feedbackIdentifier,
|
|
377
369
|
timestamp: Date.now()
|
|
378
370
|
});
|
|
379
371
|
break;
|
|
380
372
|
case "form:section:change":
|
|
381
|
-
|
|
382
|
-
feedbackConfigurationId:
|
|
383
|
-
sectionIndex:
|
|
384
|
-
sectionId:
|
|
373
|
+
a && i.current.onSectionChange && i.current.onSectionChange({
|
|
374
|
+
feedbackConfigurationId: a.feedbackConfigurationId ?? T ?? "",
|
|
375
|
+
sectionIndex: a.sectionIndex,
|
|
376
|
+
sectionId: a.sectionId,
|
|
385
377
|
timestamp: Date.now()
|
|
386
378
|
});
|
|
387
379
|
break;
|
|
388
380
|
case "form:question:answered":
|
|
389
|
-
|
|
390
|
-
feedbackConfigurationId:
|
|
391
|
-
questionId:
|
|
392
|
-
questionType:
|
|
393
|
-
answer:
|
|
381
|
+
a && i.current.onQuestionAnswered && i.current.onQuestionAnswered({
|
|
382
|
+
feedbackConfigurationId: a.feedbackConfigurationId ?? T ?? "",
|
|
383
|
+
questionId: a.questionId,
|
|
384
|
+
questionType: a.questionType,
|
|
385
|
+
answer: a.answer,
|
|
394
386
|
timestamp: Date.now()
|
|
395
387
|
});
|
|
396
388
|
break;
|
|
397
389
|
case "form:error":
|
|
398
|
-
|
|
399
|
-
feedbackConfigurationId:
|
|
400
|
-
questionId:
|
|
401
|
-
error:
|
|
390
|
+
a && i.current.onError && i.current.onError({
|
|
391
|
+
feedbackConfigurationId: a.feedbackConfigurationId ?? T ?? "",
|
|
392
|
+
questionId: a.questionId,
|
|
393
|
+
error: a.error ?? "Unknown error",
|
|
402
394
|
timestamp: Date.now()
|
|
403
395
|
});
|
|
404
396
|
break;
|
|
405
397
|
}
|
|
406
398
|
};
|
|
407
|
-
return window.addEventListener("message",
|
|
408
|
-
window.removeEventListener("message",
|
|
399
|
+
return window.addEventListener("message", x), () => {
|
|
400
|
+
window.removeEventListener("message", x), R.current = !1, l.parentNode && l.parentNode.removeChild(l), g.current = null;
|
|
409
401
|
};
|
|
410
|
-
}, [
|
|
402
|
+
}, [m, r, w]), /* @__PURE__ */ ce.jsx(
|
|
411
403
|
"div",
|
|
412
404
|
{
|
|
413
|
-
ref:
|
|
405
|
+
ref: v,
|
|
414
406
|
title: "encatchPreview1",
|
|
415
|
-
style:
|
|
416
|
-
width:
|
|
417
|
-
height:
|
|
418
|
-
minHeight: 400
|
|
407
|
+
style: m ? {
|
|
408
|
+
width: "100%",
|
|
409
|
+
height: "100%"
|
|
419
410
|
} : void 0
|
|
420
411
|
}
|
|
421
412
|
);
|
|
@@ -438,42 +429,42 @@ class ue extends EventTarget {
|
|
|
438
429
|
/**
|
|
439
430
|
* Publish an event to all matching subscribers
|
|
440
431
|
*/
|
|
441
|
-
publish(r, n,
|
|
432
|
+
publish(r, n, o) {
|
|
442
433
|
typeof window < "u" && window.dispatchEvent(
|
|
443
434
|
new CustomEvent(r, {
|
|
444
435
|
detail: n,
|
|
445
436
|
bubbles: !0
|
|
446
437
|
})
|
|
447
|
-
),
|
|
438
|
+
), o?.usePostMessage !== !1 && this.sendPostMessage(r, n);
|
|
448
439
|
}
|
|
449
440
|
/**
|
|
450
441
|
* Subscribe to form events with optional form ID filtering
|
|
451
442
|
*/
|
|
452
|
-
subscribe(r, n,
|
|
453
|
-
const
|
|
443
|
+
subscribe(r, n, o) {
|
|
444
|
+
const s = Symbol("subscription"), c = {
|
|
454
445
|
eventType: r,
|
|
455
446
|
handler: n,
|
|
456
|
-
filter:
|
|
457
|
-
id:
|
|
458
|
-
once:
|
|
447
|
+
filter: o?.formId,
|
|
448
|
+
id: s,
|
|
449
|
+
once: o?.once
|
|
459
450
|
};
|
|
460
451
|
this.subscriptions.has(r) || this.subscriptions.set(r, []), this.subscriptions.get(r).push(c);
|
|
461
|
-
const
|
|
462
|
-
const
|
|
463
|
-
this.matchesFilter(
|
|
452
|
+
const m = (w) => {
|
|
453
|
+
const v = w, g = this.getFormIdFromPayload(v.detail);
|
|
454
|
+
this.matchesFilter(g, o?.formId) && (n(v.detail), o?.once && typeof window < "u" && window.removeEventListener(r, m));
|
|
464
455
|
};
|
|
465
|
-
return typeof window < "u" && window.addEventListener(r,
|
|
466
|
-
this.unsubscribe(
|
|
456
|
+
return typeof window < "u" && window.addEventListener(r, m), () => {
|
|
457
|
+
this.unsubscribe(s), typeof window < "u" && window.removeEventListener(r, m);
|
|
467
458
|
};
|
|
468
459
|
}
|
|
469
460
|
/**
|
|
470
461
|
* Unsubscribe by subscription ID
|
|
471
462
|
*/
|
|
472
463
|
unsubscribe(r) {
|
|
473
|
-
for (const [n,
|
|
474
|
-
const
|
|
475
|
-
if (
|
|
476
|
-
|
|
464
|
+
for (const [n, o] of this.subscriptions.entries()) {
|
|
465
|
+
const s = o.findIndex((c) => c.id === r);
|
|
466
|
+
if (s !== -1) {
|
|
467
|
+
o.splice(s, 1), o.length === 0 && this.subscriptions.delete(n);
|
|
477
468
|
break;
|
|
478
469
|
}
|
|
479
470
|
}
|
|
@@ -482,7 +473,7 @@ class ue extends EventTarget {
|
|
|
482
473
|
* Subscribe to all form events with optional filtering
|
|
483
474
|
*/
|
|
484
475
|
subscribeAll(r, n) {
|
|
485
|
-
const
|
|
476
|
+
const o = [
|
|
486
477
|
"form:show",
|
|
487
478
|
"form:started",
|
|
488
479
|
"form:submit",
|
|
@@ -490,23 +481,23 @@ class ue extends EventTarget {
|
|
|
490
481
|
"form:section:change",
|
|
491
482
|
"form:question:answered",
|
|
492
483
|
"form:error"
|
|
493
|
-
],
|
|
494
|
-
return
|
|
495
|
-
const
|
|
484
|
+
], s = [];
|
|
485
|
+
return o.forEach((c) => {
|
|
486
|
+
const m = this.subscribe(
|
|
496
487
|
c,
|
|
497
488
|
(w) => r(c, w),
|
|
498
489
|
n
|
|
499
490
|
);
|
|
500
|
-
|
|
491
|
+
s.push(m);
|
|
501
492
|
}), () => {
|
|
502
|
-
|
|
493
|
+
s.forEach((c) => c());
|
|
503
494
|
};
|
|
504
495
|
}
|
|
505
496
|
/**
|
|
506
497
|
* Get active subscriptions count (for debugging)
|
|
507
498
|
*/
|
|
508
499
|
getSubscriptionCount(r) {
|
|
509
|
-
return r ? this.subscriptions.get(r)?.length || 0 : Array.from(this.subscriptions.values()).reduce((n,
|
|
500
|
+
return r ? this.subscriptions.get(r)?.length || 0 : Array.from(this.subscriptions.values()).reduce((n, o) => n + o.length, 0);
|
|
510
501
|
}
|
|
511
502
|
/**
|
|
512
503
|
* Clear all subscriptions for an event type (or all events)
|
|
@@ -515,32 +506,32 @@ class ue extends EventTarget {
|
|
|
515
506
|
r ? this.subscriptions.delete(r) : this.subscriptions.clear();
|
|
516
507
|
}
|
|
517
508
|
sendPostMessage(r, n) {
|
|
518
|
-
const
|
|
509
|
+
const o = {
|
|
519
510
|
type: `encatch:${r}`,
|
|
520
511
|
payload: n,
|
|
521
512
|
source: "encatch-form-engine"
|
|
522
513
|
};
|
|
523
|
-
window.parent && window.parent !== window && window.parent.postMessage(
|
|
524
|
-
|
|
514
|
+
window.parent && window.parent !== window && window.parent.postMessage(o, this.targetOrigin), document.querySelectorAll("iframe").forEach((s) => {
|
|
515
|
+
s.contentWindow && s.contentWindow.postMessage(o, this.targetOrigin);
|
|
525
516
|
}), typeof window.ReactNativeWebView < "u" && window.ReactNativeWebView.postMessage(JSON.stringify({
|
|
526
517
|
action: r.replace("form:", ""),
|
|
527
518
|
data: JSON.stringify(n)
|
|
528
519
|
}));
|
|
529
520
|
}
|
|
530
521
|
}
|
|
531
|
-
const
|
|
532
|
-
function de(
|
|
533
|
-
|
|
534
|
-
|
|
522
|
+
const ee = new ue();
|
|
523
|
+
function de(f, r, n) {
|
|
524
|
+
O(() => ee.subscribe(
|
|
525
|
+
f,
|
|
535
526
|
r,
|
|
536
527
|
n
|
|
537
|
-
), [
|
|
528
|
+
), [f, n?.formId, r]);
|
|
538
529
|
}
|
|
539
|
-
function me(
|
|
540
|
-
|
|
530
|
+
function me(f, r) {
|
|
531
|
+
O(() => ee.subscribeAll(f, r), [r?.formId, f]);
|
|
541
532
|
}
|
|
542
533
|
export {
|
|
543
|
-
|
|
534
|
+
le as EncatchPreview,
|
|
544
535
|
de as useEncatchFormEvent,
|
|
545
536
|
me as useEncatchFormEventAll
|
|
546
537
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(g,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],m):(g=typeof globalThis<"u"?globalThis:g||self,m(g.WsReact={},g.React))})(this,(function(g,m){"use strict";var j={exports:{}},C={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var $;function K(){if($)return C;$=1;var f=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function n(o,a,c){var b=null;if(c!==void 0&&(b=""+c),a.key!==void 0&&(b=""+a.key),"key"in a){c={};for(var h in a)h!=="key"&&(c[h]=a[h])}else c=a;return a=c.ref,{$$typeof:f,type:o,key:b,ref:a!==void 0?a:null,props:c}}return C.Fragment=r,C.jsx=n,C.jsxs=n,C}var O={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
17
|
+
*/var J;function ee(){return J||(J=1,process.env.NODE_ENV!=="production"&&(function(){function f(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===ce?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case l:return"Fragment";case x:return"Profiler";case d:return"StrictMode";case S:return"Suspense";case I:return"SuspenseList";case ie:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case F:return"Portal";case M:return(e.displayName||"Context")+".Provider";case N:return(e._context.displayName||"Context")+".Consumer";case E:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case s:return t=e.displayName||null,t!==null?t:f(e.type)||"Memo";case z:t=e._payload,e=e._init;try{return f(e(t))}catch{}}return null}function r(e){return""+e}function n(e){try{r(e);var t=!1}catch{t=!0}if(t){t=console;var u=t.error,p=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return u.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",p),r(e)}}function o(e){if(e===l)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===z)return"<...>";try{var t=f(e);return t?"<"+t+">":"<...>"}catch{return"<...>"}}function a(){var e=D.A;return e===null?null:e.getOwner()}function c(){return Error("react-stack-top-frame")}function b(e){if(G.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function h(e,t){function u(){B||(B=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}u.isReactWarning=!0,Object.defineProperty(e,"key",{get:u,configurable:!0})}function k(){var e=f(this.type);return Q[e]||(Q[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function y(e,t,u,p,R,v,W,q){return u=v.ref,e={$$typeof:P,type:e,key:t,props:v,_owner:R},(u!==void 0?u:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:k}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:W}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:q}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function _(e,t,u,p,R,v,W,q){var w=t.children;if(w!==void 0)if(p)if(ue(w)){for(p=0;p<w.length;p++)T(w[p]);Object.freeze&&Object.freeze(w)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else T(w);if(G.call(t,"key")){w=f(e);var A=Object.keys(t).filter(function(fe){return fe!=="key"});p=0<A.length?"{key: someKey, "+A.join(": ..., ")+": ...}":"{key: someKey}",Z[w+p]||(A=0<A.length?"{"+A.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
18
18
|
let props = %s;
|
|
19
19
|
<%s {...props} />
|
|
20
20
|
React keys must be passed directly to JSX without using spread:
|
|
21
21
|
let props = %s;
|
|
22
|
-
<%s key={someKey} {...props} />`,
|
|
22
|
+
<%s key={someKey} {...props} />`,p,w,A,w),Z[w+p]=!0)}if(w=null,u!==void 0&&(n(u),w=""+u),b(t)&&(n(t.key),w=""+t.key),"key"in t){u={};for(var L in t)L!=="key"&&(u[L]=t[L])}else u=t;return w&&h(u,typeof e=="function"?e.displayName||e.name||"Unknown":e),y(e,w,v,R,a(),u,W,q)}function T(e){typeof e=="object"&&e!==null&&e.$$typeof===P&&e._store&&(e._store.validated=1)}var i=m,P=Symbol.for("react.transitional.element"),F=Symbol.for("react.portal"),l=Symbol.for("react.fragment"),d=Symbol.for("react.strict_mode"),x=Symbol.for("react.profiler"),N=Symbol.for("react.consumer"),M=Symbol.for("react.context"),E=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),I=Symbol.for("react.suspense_list"),s=Symbol.for("react.memo"),z=Symbol.for("react.lazy"),ie=Symbol.for("react.activity"),ce=Symbol.for("react.client.reference"),D=i.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,G=Object.prototype.hasOwnProperty,ue=Array.isArray,Y=console.createTask?console.createTask:function(){return null};i={react_stack_bottom_frame:function(e){return e()}};var B,Q={},X=i.react_stack_bottom_frame.bind(i,c)(),H=Y(o(c)),Z={};O.Fragment=l,O.jsx=function(e,t,u,p,R){var v=1e4>D.recentlyCreatedOwnerStacks++;return _(e,t,u,!1,p,R,v?Error("react-stack-top-frame"):X,v?Y(o(e)):H)},O.jsxs=function(e,t,u,p,R){var v=1e4>D.recentlyCreatedOwnerStacks++;return _(e,t,u,!0,p,R,v?Error("react-stack-top-frame"):X,v?Y(o(e)):H)}})()),O}var U;function re(){return U||(U=1,process.env.NODE_ENV==="production"?j.exports=K():j.exports=ee()),j.exports}var te=re();const ne=({formConfig:f,formPageUrl:r,formId:n,scale:o=100,instanceId:a,onFormEvent:c})=>{const b=!!(f&&r),h=n??f?.formId??a??"preview",k=m.useRef(null),y=m.useRef(null),_=m.useRef(!1),T=m.useRef(()=>{}),i=m.useRef({});m.useEffect(()=>{if(!c)return;c({onSubmit:d=>{i.current.onSubmit=d},onShow:d=>{i.current.onShow=d},onClose:d=>{i.current.onClose=d},onSectionChange:d=>{i.current.onSectionChange=d},onQuestionAnswered:d=>{i.current.onQuestionAnswered=d},onError:d=>{i.current.onError=d}})},[c]);const P=m.useCallback(()=>{if(!y.current?.contentWindow||!f)return;const l={formId:h,scale:o,...f};y.current.contentWindow.postMessage({type:"sdk:formConfig",data:l},"*")},[f,h,o]);T.current=P,m.useEffect(()=>{!b||!_.current||T.current()},[b,f,P]);const F=m.useCallback(l=>{l.style.border="none",l.style.width="100%",l.style.height="100%"},[]);return m.useEffect(()=>{if(!b||!k.current||!f||!r)return;const l=document.createElement("div");l.style.width="100%",l.style.height="100%",l.style.overflow="hidden";const d=document.createElement("iframe"),x=new URL(r,window.location.origin);x.searchParams.set("formId",h),d.src=x.toString(),d.title="Encatch form",F(d),y.current=d,l.appendChild(d),k.current.appendChild(l);const N=M=>{const E=M.data;if(!E||typeof E!="object"||!E.type)return;let S=E.type,I=E.formId,s=E.data;switch(S.startsWith("encatch:")&&(S=S.replace("encatch:",""),I=E.payload?.feedbackConfigurationId,s=E.payload),S){case"form:ready":_.current=!0,T.current();break;case"form:close":i.current.onClose?.({timestamp:Date.now()});break;case"form:complete":i.current.onClose?.({timestamp:Date.now()});break;case"form:submit":s&&i.current.onSubmit&&i.current.onSubmit({feedbackConfigurationId:s.feedbackConfigurationId,feedbackIdentifier:s.feedbackIdentifier,response:s.response,isPartialSubmit:s.isPartialSubmit,timestamp:Date.now()});break;case"form:show":s&&i.current.onShow&&i.current.onShow({feedbackConfigurationId:s.feedbackConfigurationId,feedbackIdentifier:s.feedbackIdentifier,timestamp:Date.now()});break;case"form:started":s&&i.current.onShow&&i.current.onShow({feedbackConfigurationId:s.feedbackConfigurationId,feedbackIdentifier:s.feedbackIdentifier,timestamp:Date.now()});break;case"form:section:change":s&&i.current.onSectionChange&&i.current.onSectionChange({feedbackConfigurationId:s.feedbackConfigurationId??I??"",sectionIndex:s.sectionIndex,sectionId:s.sectionId,timestamp:Date.now()});break;case"form:question:answered":s&&i.current.onQuestionAnswered&&i.current.onQuestionAnswered({feedbackConfigurationId:s.feedbackConfigurationId??I??"",questionId:s.questionId,questionType:s.questionType,answer:s.answer,timestamp:Date.now()});break;case"form:error":s&&i.current.onError&&i.current.onError({feedbackConfigurationId:s.feedbackConfigurationId??I??"",questionId:s.questionId,error:s.error??"Unknown error",timestamp:Date.now()});break}};return window.addEventListener("message",N),()=>{window.removeEventListener("message",N),_.current=!1,l.parentNode&&l.parentNode.removeChild(l),y.current=null}},[b,r,h]),te.jsx("div",{ref:k,title:"encatchPreview1",style:b?{width:"100%",height:"100%"}:void 0})};class oe extends EventTarget{subscriptions=new Map;targetOrigin="*";matchesFilter(r,n){return!n||n==="*"||n===null||n===void 0?!0:typeof n=="string"?r===n:Array.isArray(n)?n.includes(r||""):typeof n=="function"?n(r||""):!1}getFormIdFromPayload(r){return r?.feedbackConfigurationId}publish(r,n,o){typeof window<"u"&&window.dispatchEvent(new CustomEvent(r,{detail:n,bubbles:!0})),o?.usePostMessage!==!1&&this.sendPostMessage(r,n)}subscribe(r,n,o){const a=Symbol("subscription"),c={eventType:r,handler:n,filter:o?.formId,id:a,once:o?.once};this.subscriptions.has(r)||this.subscriptions.set(r,[]),this.subscriptions.get(r).push(c);const b=h=>{const k=h,y=this.getFormIdFromPayload(k.detail);this.matchesFilter(y,o?.formId)&&(n(k.detail),o?.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,o]of this.subscriptions.entries()){const a=o.findIndex(c=>c.id===r);if(a!==-1){o.splice(a,1),o.length===0&&this.subscriptions.delete(n);break}}}subscribeAll(r,n){const o=["form:show","form:started","form:submit","form:close","form:section:change","form:question:answered","form:error"],a=[];return o.forEach(c=>{const b=this.subscribe(c,h=>r(c,h),n);a.push(b)}),()=>{a.forEach(c=>c())}}getSubscriptionCount(r){return r?this.subscriptions.get(r)?.length||0:Array.from(this.subscriptions.values()).reduce((n,o)=>n+o.length,0)}clearSubscriptions(r){r?this.subscriptions.delete(r):this.subscriptions.clear()}sendPostMessage(r,n){const o={type:`encatch:${r}`,payload:n,source:"encatch-form-engine"};window.parent&&window.parent!==window&&window.parent.postMessage(o,this.targetOrigin),document.querySelectorAll("iframe").forEach(a=>{a.contentWindow&&a.contentWindow.postMessage(o,this.targetOrigin)}),typeof window.ReactNativeWebView<"u"&&window.ReactNativeWebView.postMessage(JSON.stringify({action:r.replace("form:",""),data:JSON.stringify(n)}))}}const V=new oe;function se(f,r,n){m.useEffect(()=>V.subscribe(f,r,n),[f,n?.formId,r])}function ae(f,r){m.useEffect(()=>V.subscribeAll(f,r),[r?.formId,f])}g.EncatchPreview=ne,g.useEncatchFormEvent=se,g.useEncatchFormEventAll=ae,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
|