@encatch/ws-react 0.0.50-beta.5 → 0.0.50-beta.7

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