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

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
@@ -35,40 +35,36 @@ yarn add @encatch/ws-react
35
35
 
36
36
  ### EncatchPreview
37
37
 
38
- The main component for rendering Encatch forms in your React application.
38
+ The main component for rendering Encatch forms in an iframe. Provide `formConfig` and `formPageUrl` (e.g. your shareable app route) to render the form.
39
39
 
40
40
  ```tsx
41
41
  import { EncatchPreview } from '@encatch/ws-react';
42
42
 
43
43
  function App() {
44
- const formData = {
45
- theme: 'default',
46
- currentMode: 'light',
47
- currentLanguage: 'en',
48
- questions: [],
49
- questionLanguages: [],
50
- otherConfigurationProperties: {},
44
+ const formConfig = {
45
+ questionnaireFields: { questions: {}, sections: [], selectedLanguages: [], translations: {} },
46
+ appearanceProperties: { themes: {}, featureSettings: {} },
51
47
  welcomeScreenProperties: {},
52
48
  endScreenProperties: {},
53
- translations: {},
54
- sections: [],
55
- themeSettings: null,
56
- onClose: () => console.log('Form closed'),
57
- onSectionChange: (index) => console.log('Section changed:', index),
58
- apiKey: 'your-api-key',
59
- hostUrl: 'https://api.encatch.com',
60
- feedbackConfigId: 'your-config-id',
61
- identifier: 'user-identifier',
49
+ otherConfigurationProperties: {},
50
+ feedbackConfigurationId: 'your-config-id',
51
+ feedbackIdentifier: 'user-identifier',
62
52
  };
63
53
 
64
54
  return (
65
- <EncatchPreview
66
- formData={formData}
67
- cssLink="https://your-styles.css"
68
- scale={100}
69
- persistMode="none"
70
- instanceId="unique-form-id"
71
- />
55
+ <div style={{ width: '100%', height: '500px' }}>
56
+ <EncatchPreview
57
+ formConfig={formConfig}
58
+ formPageUrl="https://your-shareable-app.com/s/encatch-preview-form"
59
+ iframeWidth="100%"
60
+ iframeHeight="100%"
61
+ scale={100}
62
+ formId="unique-form-id"
63
+ onFormEvent={(formEvent) => {
64
+ formEvent.onSubmit((data) => console.log('Submitted', data));
65
+ }}
66
+ />
67
+ </div>
72
68
  );
73
69
  }
74
70
  ```
@@ -77,12 +73,14 @@ function App() {
77
73
 
78
74
  | Prop | Type | Required | Default | Description |
79
75
  |------|------|----------|---------|-------------|
80
- | `formData` | `object` | Yes | - | Form configuration object |
81
- | `cssLink` | `string` | Yes | - | URL to the form's CSS stylesheet |
82
- | `scale` | `number` | No | `100` | Scale factor for the form (percentage) |
83
- | `persistMode` | `"retain" \| "reset" \| "none"` | No | `"none"` | Form state persistence mode |
84
- | `instanceId` | `string` | No | - | Unique identifier for filtering events |
85
- | `onFormEvent` | `OnFormEventHandler` | No | - | Event handler builder function |
76
+ | `formConfig` | `EncatchFormConfig` | Yes* | - | Form configuration for the iframe. Required with formPageUrl to render. |
77
+ | `formPageUrl` | `string` | Yes* | - | URL of the iframe form page (e.g. shareable app route). Required with formConfig to render. |
78
+ | `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
+ | `scale` | `number` | No | `100` | Visual scale of iframe content, 1–100. Applied via CSS transform. |
82
+ | `instanceId` | `string` | No | - | Unique identifier for filtering events. |
83
+ | `onFormEvent` | `OnFormEventHandler` | No | - | Event handler builder function. |
86
84
 
87
85
  ### Event Handling with onFormEvent
88
86
 
@@ -126,8 +124,8 @@ function App() {
126
124
 
127
125
  return (
128
126
  <EncatchPreview
129
- formData={formData}
130
- cssLink="https://your-styles.css"
127
+ formConfig={formConfig}
128
+ formPageUrl="https://your-shareable-app.com/s/encatch-preview-form"
131
129
  instanceId="my-form"
132
130
  onFormEvent={handleFormEvents}
133
131
  />
@@ -254,14 +252,14 @@ function MultiFormApp() {
254
252
  return (
255
253
  <>
256
254
  <EncatchPreview
257
- formData={surveyFormData}
258
- cssLink="https://styles.css"
255
+ formConfig={surveyFormConfig}
256
+ formPageUrl="https://your-shareable-app.com/s/encatch-preview-form"
259
257
  instanceId="survey-form"
260
258
  />
261
259
 
262
260
  <EncatchPreview
263
- formData={feedbackFormData}
264
- cssLink="https://styles.css"
261
+ formConfig={feedbackFormConfig}
262
+ formPageUrl="https://your-shareable-app.com/s/encatch-preview-form"
265
263
  instanceId="feedback-form"
266
264
  />
267
265
  </>
@@ -1,66 +1,18 @@
1
- import { AppProps, Section } from "@encatch/schema";
2
1
  import React from "react";
3
2
  import type { EncatchFormConfig, OnFormEventHandler } from "./types";
4
- declare module "react" {
5
- namespace JSX {
6
- interface IntrinsicElements {
7
- "encatch-app": React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> & {
8
- theme?: AppProps["theme"];
9
- currentMode?: "light" | "dark";
10
- currentLanguage?: AppProps["currentLanguage"];
11
- questions?: AppProps["questions"];
12
- questionLanguages?: AppProps["questionLanguages"];
13
- otherConfigurationProperties?: AppProps["otherConfigurationProperties"];
14
- welcomeScreenProperties?: AppProps["welcomeScreenProperties"];
15
- endScreenProperties?: AppProps["endScreenProperties"];
16
- translations?: AppProps["translations"];
17
- sections?: Section[];
18
- themeSettings?: AppProps["themeSettings"] | null;
19
- onClose?: () => void;
20
- onSectionChange?: (index: number) => void;
21
- apiKey?: string;
22
- hostUrl?: string;
23
- feedbackConfigId?: string;
24
- identifier?: string;
25
- cssLink?: string;
26
- scale?: number;
27
- persistMode?: "retain" | "reset" | "none";
28
- instanceId?: string;
29
- };
30
- }
31
- }
32
- }
33
- interface EncatchPreviewFormData {
34
- theme: AppProps["theme"];
35
- currentMode: "light" | "dark";
36
- currentLanguage: AppProps["currentLanguage"];
37
- questions: AppProps["questions"];
38
- questionLanguages: AppProps["questionLanguages"];
39
- otherConfigurationProperties: AppProps["otherConfigurationProperties"];
40
- welcomeScreenProperties: AppProps["welcomeScreenProperties"];
41
- endScreenProperties: AppProps["endScreenProperties"];
42
- translations: AppProps["translations"];
43
- sections: Section[];
44
- themeSettings: AppProps["themeSettings"] | null;
45
- onClose: () => void;
46
- onSectionChange: (index: number) => void;
47
- apiKey: string;
48
- hostUrl: string;
49
- feedbackConfigId: string;
50
- identifier: string;
51
- }
52
3
  interface EncatchPreviewProps {
53
- /** Required for inline mode (same-document rendering). Omit when using formConfig + formPageUrl. */
54
- formData?: EncatchPreviewFormData;
55
- /** Full form config for iframe mode. Use with formPageUrl. */
4
+ /** Form config for the iframe. Required together with formPageUrl to render. */
56
5
  formConfig?: EncatchFormConfig;
57
- /** URL of the iframe form page (e.g. shareable origin + /encatch-preview-form). Use with formConfig. */
6
+ /** URL of the iframe form page (e.g. shareable origin + /encatch-preview-form). Required together with formConfig to render. */
58
7
  formPageUrl?: string;
59
8
  /** Optional form id for iframe URL query and message payloads. Defaults to formConfig.formId or "preview". */
60
9
  formId?: string;
61
- cssLink?: 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. */
62
15
  scale?: number;
63
- persistMode?: "retain" | "reset" | "none";
64
16
  instanceId?: string;
65
17
  /**
66
18
  * Callback function that receives a FormEventBuilder to register event handlers
package/dist/index.es.js CHANGED
@@ -1,5 +1,5 @@
1
- import U, { useState as ee, useRef as B, useEffect as y, useCallback as re } from "react";
2
- var $ = { exports: {} }, M = {};
1
+ import V, { useRef as J, useEffect as P, useCallback as H } from "react";
2
+ var D = { exports: {} }, j = {};
3
3
  /**
4
4
  * @license React
5
5
  * react-jsx-runtime.production.js
@@ -9,29 +9,29 @@ var $ = { exports: {} }, M = {};
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 te;
13
- function ie() {
14
- if (te) return M;
15
- te = 1;
16
- var o = Symbol.for("react.transitional.element"), r = Symbol.for("react.fragment");
17
- function n(u, c, f) {
18
- var w = null;
19
- if (f !== void 0 && (w = "" + f), c.key !== void 0 && (w = "" + c.key), "key" in c) {
20
- f = {};
21
- for (var d in c)
22
- d !== "key" && (f[d] = c[d]);
23
- } else f = c;
24
- return c = f.ref, {
25
- $$typeof: o,
26
- type: u,
27
- key: w,
28
- ref: c !== void 0 ? c : null,
29
- props: f
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) {
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,
29
+ props: c
30
30
  };
31
31
  }
32
- return M.Fragment = r, M.jsx = n, M.jsxs = n, M;
32
+ return j.Fragment = r, j.jsx = n, j.jsxs = n, j;
33
33
  }
34
- var F = {};
34
+ var N = {};
35
35
  /**
36
36
  * @license React
37
37
  * react-jsx-runtime.development.js
@@ -41,47 +41,47 @@ var F = {};
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 ne;
44
+ var K;
45
45
  function ae() {
46
- return ne || (ne = 1, process.env.NODE_ENV !== "production" && (function() {
47
- function o(e) {
46
+ return K || (K = 1, process.env.NODE_ENV !== "production" && (function() {
47
+ function i(e) {
48
48
  if (e == null) return null;
49
49
  if (typeof e == "function")
50
- return e.$$typeof === V ? null : e.displayName || e.name || null;
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 g:
53
+ case A:
54
54
  return "Fragment";
55
- case k:
55
+ case u:
56
56
  return "Profiler";
57
- case A:
57
+ case x:
58
58
  return "StrictMode";
59
- case L:
59
+ case M:
60
60
  return "Suspense";
61
- case Y:
61
+ case E:
62
62
  return "SuspenseList";
63
- case W:
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 J:
70
+ case f:
71
71
  return "Portal";
72
- case N:
72
+ case k:
73
73
  return (e.displayName || "Context") + ".Provider";
74
- case j:
74
+ case d:
75
75
  return (e._context.displayName || "Context") + ".Consumer";
76
- case i:
77
- var s = e.render;
78
- return e = e.displayName, e || (e = s.displayName || s.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
79
- case t:
80
- return s = e.displayName || null, s !== null ? s : o(e.type) || "Memo";
81
- case b:
82
- s = e._payload, e = e._init;
76
+ case F:
77
+ var t = e.render;
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:
82
+ t = e._payload, e = e._init;
83
83
  try {
84
- return o(e(s));
84
+ return i(e(t));
85
85
  } catch {
86
86
  }
87
87
  }
@@ -93,50 +93,50 @@ function ae() {
93
93
  function n(e) {
94
94
  try {
95
95
  r(e);
96
- var s = !1;
96
+ var t = !1;
97
97
  } catch {
98
- s = !0;
98
+ t = !0;
99
99
  }
100
- if (s) {
101
- s = console;
102
- var l = s.error, m = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
100
+ if (t) {
101
+ t = console;
102
+ var l = t.error, m = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
103
103
  return l.call(
104
- s,
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
  m
107
107
  ), r(e);
108
108
  }
109
109
  }
110
- function u(e) {
111
- if (e === g) return "<>";
112
- if (typeof e == "object" && e !== null && e.$$typeof === b)
110
+ function s(e) {
111
+ if (e === A) return "<>";
112
+ if (typeof e == "object" && e !== null && e.$$typeof === T)
113
113
  return "<...>";
114
114
  try {
115
- var s = o(e);
116
- return s ? "<" + s + ">" : "<...>";
115
+ var t = i(e);
116
+ return t ? "<" + t + ">" : "<...>";
117
117
  } catch {
118
118
  return "<...>";
119
119
  }
120
120
  }
121
- function c() {
122
- var e = E.A;
121
+ function a() {
122
+ var e = Y.A;
123
123
  return e === null ? null : e.getOwner();
124
124
  }
125
- function f() {
125
+ function c() {
126
126
  return Error("react-stack-top-frame");
127
127
  }
128
- function w(e) {
129
- if (I.call(e, "key")) {
130
- var s = Object.getOwnPropertyDescriptor(e, "key").get;
131
- if (s && s.isReactWarning) return !1;
128
+ function p(e) {
129
+ if (U.call(e, "key")) {
130
+ var t = Object.getOwnPropertyDescriptor(e, "key").get;
131
+ if (t && t.isReactWarning) return !1;
132
132
  }
133
133
  return e.key !== void 0;
134
134
  }
135
- function d(e, s) {
135
+ function w(e, t) {
136
136
  function l() {
137
- X || (X = !0, console.error(
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
- s
139
+ t
140
140
  ));
141
141
  }
142
142
  l.isReactWarning = !0, Object.defineProperty(e, "key", {
@@ -144,22 +144,22 @@ function ae() {
144
144
  configurable: !0
145
145
  });
146
146
  }
147
- function R() {
148
- var e = o(this.type);
149
- return H[e] || (H[e] = !0, console.error(
147
+ function h() {
148
+ var e = i(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, s, l, m, S, v, z, Q) {
153
+ function R(e, t, l, m, _, v, $, L) {
154
154
  return l = v.ref, e = {
155
- $$typeof: q,
155
+ $$typeof: I,
156
156
  type: e,
157
- key: s,
157
+ key: t,
158
158
  props: v,
159
- _owner: S
159
+ _owner: _
160
160
  }, (l !== void 0 ? l : null) !== null ? Object.defineProperty(e, "ref", {
161
161
  enumerable: !1,
162
- get: R
162
+ get: h
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,33 +174,33 @@ function ae() {
174
174
  configurable: !1,
175
175
  enumerable: !1,
176
176
  writable: !0,
177
- value: z
177
+ value: $
178
178
  }), Object.defineProperty(e, "_debugTask", {
179
179
  configurable: !1,
180
180
  enumerable: !1,
181
181
  writable: !0,
182
- value: Q
182
+ value: L
183
183
  }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
184
184
  }
185
- function C(e, s, l, m, S, v, z, Q) {
186
- var p = s.children;
187
- if (p !== void 0)
185
+ function S(e, t, l, m, _, v, $, L) {
186
+ var b = t.children;
187
+ if (b !== void 0)
188
188
  if (m)
189
- if (P(p)) {
190
- for (m = 0; m < p.length; m++)
191
- x(p[m]);
192
- Object.freeze && Object.freeze(p);
189
+ if (ne(b)) {
190
+ for (m = 0; m < b.length; m++)
191
+ g(b[m]);
192
+ Object.freeze && Object.freeze(b);
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 x(p);
198
- if (I.call(s, "key")) {
199
- p = o(e);
200
- var O = Object.keys(s).filter(function(se) {
201
- return se !== "key";
197
+ else g(b);
198
+ if (U.call(t, "key")) {
199
+ b = i(e);
200
+ var C = Object.keys(t).filter(function(oe) {
201
+ return oe !== "key";
202
202
  });
203
- m = 0 < O.length ? "{key: someKey, " + O.join(": ..., ") + ": ...}" : "{key: someKey}", K[p + m] || (O = 0 < O.length ? "{" + O.join(": ..., ") + ": ...}" : "{}", console.error(
203
+ m = 0 < C.length ? "{key: someKey, " + C.join(": ..., ") + ": ...}" : "{key: someKey}", X[b + m] || (C = 0 < C.length ? "{" + C.join(": ..., ") + ": ...}" : "{}", console.error(
204
204
  `A props object containing a "key" prop is being spread into JSX:
205
205
  let props = %s;
206
206
  <%s {...props} />
@@ -208,78 +208,218 @@ React keys must be passed directly to JSX without using spread:
208
208
  let props = %s;
209
209
  <%s key={someKey} {...props} />`,
210
210
  m,
211
- p,
212
- O,
213
- p
214
- ), K[p + m] = !0);
211
+ b,
212
+ C,
213
+ b
214
+ ), X[b + m] = !0);
215
215
  }
216
- if (p = null, l !== void 0 && (n(l), p = "" + l), w(s) && (n(s.key), p = "" + s.key), "key" in s) {
216
+ if (b = null, l !== void 0 && (n(l), b = "" + l), p(t) && (n(t.key), b = "" + t.key), "key" in t) {
217
217
  l = {};
218
- for (var G in s)
219
- G !== "key" && (l[G] = s[G]);
220
- } else l = s;
221
- return p && d(
218
+ for (var q in t)
219
+ q !== "key" && (l[q] = t[q]);
220
+ } else l = t;
221
+ return b && w(
222
222
  l,
223
223
  typeof e == "function" ? e.displayName || e.name || "Unknown" : e
224
- ), h(
224
+ ), R(
225
225
  e,
226
- p,
226
+ b,
227
227
  v,
228
- S,
229
- c(),
228
+ _,
229
+ a(),
230
230
  l,
231
- z,
232
- Q
231
+ $,
232
+ L
233
233
  );
234
234
  }
235
- function x(e) {
236
- typeof e == "object" && e !== null && e.$$typeof === q && e._store && (e._store.validated = 1);
235
+ function g(e) {
236
+ typeof e == "object" && e !== null && e.$$typeof === I && e._store && (e._store.validated = 1);
237
237
  }
238
- var T = U, q = Symbol.for("react.transitional.element"), J = Symbol.for("react.portal"), g = Symbol.for("react.fragment"), A = Symbol.for("react.strict_mode"), k = Symbol.for("react.profiler"), j = Symbol.for("react.consumer"), N = Symbol.for("react.context"), i = Symbol.for("react.forward_ref"), L = Symbol.for("react.suspense"), Y = Symbol.for("react.suspense_list"), t = Symbol.for("react.memo"), b = Symbol.for("react.lazy"), W = Symbol.for("react.activity"), V = Symbol.for("react.client.reference"), E = T.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, I = Object.prototype.hasOwnProperty, P = Array.isArray, a = console.createTask ? console.createTask : function() {
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() {
239
239
  return null;
240
240
  };
241
- T = {
241
+ y = {
242
242
  react_stack_bottom_frame: function(e) {
243
243
  return e();
244
244
  }
245
245
  };
246
- var X, H = {}, D = T.react_stack_bottom_frame.bind(
247
- T,
248
- f
249
- )(), Z = a(u(f)), K = {};
250
- F.Fragment = g, F.jsx = function(e, s, l, m, S) {
251
- var v = 1e4 > E.recentlyCreatedOwnerStacks++;
252
- return C(
246
+ var z, G = {}, B = y.react_stack_bottom_frame.bind(
247
+ y,
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(
253
253
  e,
254
- s,
254
+ t,
255
255
  l,
256
256
  !1,
257
257
  m,
258
- S,
259
- v ? Error("react-stack-top-frame") : D,
260
- v ? a(u(e)) : Z
258
+ _,
259
+ v ? Error("react-stack-top-frame") : B,
260
+ v ? W(s(e)) : Q
261
261
  );
262
- }, F.jsxs = function(e, s, l, m, S) {
263
- var v = 1e4 > E.recentlyCreatedOwnerStacks++;
264
- return C(
262
+ }, N.jsxs = function(e, t, l, m, _) {
263
+ var v = 1e4 > Y.recentlyCreatedOwnerStacks++;
264
+ return S(
265
265
  e,
266
- s,
266
+ t,
267
267
  l,
268
268
  !0,
269
269
  m,
270
- S,
271
- v ? Error("react-stack-top-frame") : D,
272
- v ? a(u(e)) : Z
270
+ _,
271
+ v ? Error("react-stack-top-frame") : B,
272
+ v ? W(s(e)) : Q
273
273
  );
274
274
  };
275
- })()), F;
275
+ })()), N;
276
276
  }
277
- var oe;
278
- function ce() {
279
- return oe || (oe = 1, process.env.NODE_ENV === "production" ? $.exports = ie() : $.exports = ae()), $.exports;
277
+ var ee;
278
+ function ie() {
279
+ return ee || (ee = 1, process.env.NODE_ENV === "production" ? D.exports = se() : D.exports = ae()), D.exports;
280
280
  }
281
- var ue = ce();
282
- class le extends EventTarget {
281
+ var ce = ie();
282
+ const fe = ({
283
+ formConfig: i,
284
+ formPageUrl: r,
285
+ formId: n,
286
+ iframeWidth: s = "100%",
287
+ iframeHeight: a = "100%",
288
+ scale: c = 100,
289
+ instanceId: p,
290
+ onFormEvent: w
291
+ }) => {
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({
297
+ onSubmit: (d) => {
298
+ f.current.onSubmit = d;
299
+ },
300
+ onShow: (d) => {
301
+ f.current.onShow = d;
302
+ },
303
+ onClose: (d) => {
304
+ f.current.onClose = d;
305
+ },
306
+ onSectionChange: (d) => {
307
+ f.current.onSectionChange = d;
308
+ },
309
+ onQuestionAnswered: (d) => {
310
+ f.current.onQuestionAnswered = d;
311
+ },
312
+ onError: (d) => {
313
+ f.current.onError = d;
314
+ }
315
+ });
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 },
322
+ "*"
323
+ );
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;
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) {
348
+ case "form:ready":
349
+ y.current = !0, I.current();
350
+ break;
351
+ case "form:close":
352
+ f.current.onClose?.({ timestamp: Date.now() });
353
+ break;
354
+ case "form:complete":
355
+ f.current.onClose?.({ timestamp: Date.now() });
356
+ break;
357
+ case "form:submit":
358
+ o && f.current.onSubmit && f.current.onSubmit({
359
+ feedbackConfigurationId: o.feedbackConfigurationId,
360
+ feedbackIdentifier: o.feedbackIdentifier,
361
+ response: o.response,
362
+ isPartialSubmit: o.isPartialSubmit,
363
+ timestamp: Date.now()
364
+ });
365
+ break;
366
+ case "form:show":
367
+ o && f.current.onShow && f.current.onShow({
368
+ feedbackConfigurationId: o.feedbackConfigurationId,
369
+ feedbackIdentifier: o.feedbackIdentifier,
370
+ timestamp: Date.now()
371
+ });
372
+ break;
373
+ case "form:started":
374
+ o && f.current.onShow && f.current.onShow({
375
+ feedbackConfigurationId: o.feedbackConfigurationId,
376
+ feedbackIdentifier: o.feedbackIdentifier,
377
+ timestamp: Date.now()
378
+ });
379
+ break;
380
+ case "form:section:change":
381
+ o && f.current.onSectionChange && f.current.onSectionChange({
382
+ feedbackConfigurationId: o.feedbackConfigurationId ?? T ?? "",
383
+ sectionIndex: o.sectionIndex,
384
+ sectionId: o.sectionId,
385
+ timestamp: Date.now()
386
+ });
387
+ break;
388
+ case "form:question:answered":
389
+ o && f.current.onQuestionAnswered && f.current.onQuestionAnswered({
390
+ feedbackConfigurationId: o.feedbackConfigurationId ?? T ?? "",
391
+ questionId: o.questionId,
392
+ questionType: o.questionType,
393
+ answer: o.answer,
394
+ timestamp: Date.now()
395
+ });
396
+ break;
397
+ case "form:error":
398
+ o && f.current.onError && f.current.onError({
399
+ feedbackConfigurationId: o.feedbackConfigurationId ?? T ?? "",
400
+ questionId: o.questionId,
401
+ error: o.error ?? "Unknown error",
402
+ timestamp: Date.now()
403
+ });
404
+ break;
405
+ }
406
+ };
407
+ return window.addEventListener("message", F), () => {
408
+ window.removeEventListener("message", F), y.current = !1, u.parentNode && u.parentNode.removeChild(u), g.current = null;
409
+ };
410
+ }, [h, r, R]), /* @__PURE__ */ ce.jsx(
411
+ "div",
412
+ {
413
+ ref: S,
414
+ title: "encatchPreview1",
415
+ style: h ? {
416
+ width: s ?? "100%",
417
+ height: a ?? "100%"
418
+ } : void 0
419
+ }
420
+ );
421
+ };
422
+ class ue extends EventTarget {
283
423
  subscriptions = /* @__PURE__ */ new Map();
284
424
  targetOrigin = "*";
285
425
  /**
@@ -297,42 +437,42 @@ class le extends EventTarget {
297
437
  /**
298
438
  * Publish an event to all matching subscribers
299
439
  */
300
- publish(r, n, u) {
440
+ publish(r, n, s) {
301
441
  typeof window < "u" && window.dispatchEvent(
302
442
  new CustomEvent(r, {
303
443
  detail: n,
304
444
  bubbles: !0
305
445
  })
306
- ), u?.usePostMessage !== !1 && this.sendPostMessage(r, n);
446
+ ), s?.usePostMessage !== !1 && this.sendPostMessage(r, n);
307
447
  }
308
448
  /**
309
449
  * Subscribe to form events with optional form ID filtering
310
450
  */
311
- subscribe(r, n, u) {
312
- const c = Symbol("subscription"), f = {
451
+ subscribe(r, n, s) {
452
+ const a = Symbol("subscription"), c = {
313
453
  eventType: r,
314
454
  handler: n,
315
- filter: u?.formId,
316
- id: c,
317
- once: u?.once
455
+ filter: s?.formId,
456
+ id: a,
457
+ once: s?.once
318
458
  };
319
- this.subscriptions.has(r) || this.subscriptions.set(r, []), this.subscriptions.get(r).push(f);
320
- const w = (d) => {
321
- const R = d, h = this.getFormIdFromPayload(R.detail);
322
- this.matchesFilter(h, u?.formId) && (n(R.detail), u?.once && typeof window < "u" && window.removeEventListener(r, w));
459
+ 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));
323
463
  };
324
- return typeof window < "u" && window.addEventListener(r, w), () => {
325
- this.unsubscribe(c), typeof window < "u" && window.removeEventListener(r, w);
464
+ return typeof window < "u" && window.addEventListener(r, p), () => {
465
+ this.unsubscribe(a), typeof window < "u" && window.removeEventListener(r, p);
326
466
  };
327
467
  }
328
468
  /**
329
469
  * Unsubscribe by subscription ID
330
470
  */
331
471
  unsubscribe(r) {
332
- for (const [n, u] of this.subscriptions.entries()) {
333
- const c = u.findIndex((f) => f.id === r);
334
- if (c !== -1) {
335
- u.splice(c, 1), u.length === 0 && this.subscriptions.delete(n);
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);
336
476
  break;
337
477
  }
338
478
  }
@@ -341,7 +481,7 @@ class le extends EventTarget {
341
481
  * Subscribe to all form events with optional filtering
342
482
  */
343
483
  subscribeAll(r, n) {
344
- const u = [
484
+ const s = [
345
485
  "form:show",
346
486
  "form:started",
347
487
  "form:submit",
@@ -349,23 +489,23 @@ class le extends EventTarget {
349
489
  "form:section:change",
350
490
  "form:question:answered",
351
491
  "form:error"
352
- ], c = [];
353
- return u.forEach((f) => {
354
- const w = this.subscribe(
355
- f,
356
- (d) => r(f, d),
492
+ ], a = [];
493
+ return s.forEach((c) => {
494
+ const p = this.subscribe(
495
+ c,
496
+ (w) => r(c, w),
357
497
  n
358
498
  );
359
- c.push(w);
499
+ a.push(p);
360
500
  }), () => {
361
- c.forEach((f) => f());
501
+ a.forEach((c) => c());
362
502
  };
363
503
  }
364
504
  /**
365
505
  * Get active subscriptions count (for debugging)
366
506
  */
367
507
  getSubscriptionCount(r) {
368
- return r ? this.subscriptions.get(r)?.length || 0 : Array.from(this.subscriptions.values()).reduce((n, u) => n + u.length, 0);
508
+ return r ? this.subscriptions.get(r)?.length || 0 : Array.from(this.subscriptions.values()).reduce((n, s) => n + s.length, 0);
369
509
  }
370
510
  /**
371
511
  * Clear all subscriptions for an event type (or all events)
@@ -374,241 +514,32 @@ class le extends EventTarget {
374
514
  r ? this.subscriptions.delete(r) : this.subscriptions.clear();
375
515
  }
376
516
  sendPostMessage(r, n) {
377
- const u = {
517
+ const s = {
378
518
  type: `encatch:${r}`,
379
519
  payload: n,
380
520
  source: "encatch-form-engine"
381
521
  };
382
- window.parent && window.parent !== window && window.parent.postMessage(u, this.targetOrigin), document.querySelectorAll("iframe").forEach((c) => {
383
- c.contentWindow && c.contentWindow.postMessage(u, this.targetOrigin);
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);
384
524
  }), typeof window.ReactNativeWebView < "u" && window.ReactNativeWebView.postMessage(JSON.stringify({
385
525
  action: r.replace("form:", ""),
386
526
  data: JSON.stringify(n)
387
527
  }));
388
528
  }
389
529
  }
390
- const _ = new le(), de = ({
391
- formData: o,
392
- formConfig: r,
393
- formPageUrl: n,
394
- formId: u,
395
- cssLink: c,
396
- scale: f = 100,
397
- persistMode: w = "none",
398
- instanceId: d,
399
- onFormEvent: R
400
- }) => {
401
- const h = !!(r && n), C = u ?? r?.formId ?? d ?? "preview", [x, T] = ee(!1), [q, J] = ee(!0), g = U.useRef(null), A = U.useRef(
402
- null
403
- ), k = U.useRef(null), j = B(!1), N = B(() => {
404
- }), i = B({});
405
- y(() => {
406
- if (!R) return;
407
- R({
408
- onSubmit: (b) => {
409
- i.current.onSubmit = b;
410
- },
411
- onShow: (b) => {
412
- i.current.onShow = b;
413
- },
414
- onClose: (b) => {
415
- i.current.onClose = b;
416
- },
417
- onSectionChange: (b) => {
418
- i.current.onSectionChange = b;
419
- },
420
- onQuestionAnswered: (b) => {
421
- i.current.onQuestionAnswered = b;
422
- },
423
- onError: (b) => {
424
- i.current.onError = b;
425
- }
426
- });
427
- }, [R]);
428
- const L = re(() => {
429
- if (!k.current?.contentWindow || !r) return;
430
- const t = { formId: C, ...r };
431
- k.current.contentWindow.postMessage(
432
- { type: "sdk:formConfig", data: t },
433
- "*"
434
- );
435
- }, [r, C]);
436
- N.current = L, y(() => {
437
- !h || !j.current || N.current();
438
- }, [h, r, L]), y(() => {
439
- if (!h || !g.current) return;
440
- const t = document.createElement("iframe"), b = new URL(n, window.location.origin);
441
- b.searchParams.set("formId", C), t.src = b.toString(), t.title = "Encatch form", t.style.width = "100%", t.style.height = "100%", t.style.border = "none", k.current = t, g.current.appendChild(t);
442
- const W = (V) => {
443
- const E = V.data;
444
- if (!E || typeof E != "object" || !E.type) return;
445
- let I = E.type, P = E.formId, a = E.data;
446
- switch (I.startsWith("encatch:") && (I = I.replace("encatch:", ""), P = E.payload?.feedbackConfigurationId, a = E.payload), I) {
447
- case "form:ready":
448
- j.current = !0, N.current();
449
- break;
450
- case "form:close":
451
- i.current.onClose?.({ timestamp: Date.now() });
452
- break;
453
- case "form:complete":
454
- i.current.onClose?.({ timestamp: Date.now() });
455
- break;
456
- case "form:submit":
457
- a && i.current.onSubmit && i.current.onSubmit({
458
- feedbackConfigurationId: a.feedbackConfigurationId,
459
- feedbackIdentifier: a.feedbackIdentifier,
460
- response: a.response,
461
- isPartialSubmit: a.isPartialSubmit,
462
- timestamp: Date.now()
463
- });
464
- break;
465
- case "form:show":
466
- a && i.current.onShow && i.current.onShow({
467
- feedbackConfigurationId: a.feedbackConfigurationId,
468
- feedbackIdentifier: a.feedbackIdentifier,
469
- timestamp: Date.now()
470
- });
471
- break;
472
- case "form:started":
473
- a && i.current.onShow && i.current.onShow({
474
- feedbackConfigurationId: a.feedbackConfigurationId,
475
- feedbackIdentifier: a.feedbackIdentifier,
476
- timestamp: Date.now()
477
- });
478
- break;
479
- case "form:section:change":
480
- a && i.current.onSectionChange && i.current.onSectionChange({
481
- feedbackConfigurationId: a.feedbackConfigurationId ?? P ?? "",
482
- sectionIndex: a.sectionIndex,
483
- sectionId: a.sectionId,
484
- timestamp: Date.now()
485
- });
486
- break;
487
- case "form:question:answered":
488
- a && i.current.onQuestionAnswered && i.current.onQuestionAnswered({
489
- feedbackConfigurationId: a.feedbackConfigurationId ?? P ?? "",
490
- questionId: a.questionId,
491
- questionType: a.questionType,
492
- answer: a.answer,
493
- timestamp: Date.now()
494
- });
495
- break;
496
- case "form:error":
497
- a && i.current.onError && i.current.onError({
498
- feedbackConfigurationId: a.feedbackConfigurationId ?? P ?? "",
499
- questionId: a.questionId,
500
- error: a.error ?? "Unknown error",
501
- timestamp: Date.now()
502
- });
503
- break;
504
- }
505
- };
506
- return window.addEventListener("message", W), () => {
507
- if (window.removeEventListener("message", W), j.current = !1, g.current && k.current)
508
- try {
509
- g.current.removeChild(k.current);
510
- } catch {
511
- }
512
- k.current = null;
513
- };
514
- }, [h, n, C]), y(() => {
515
- if (h || !d) return;
516
- const t = [];
517
- return i.current.onSubmit && t.push(
518
- _.subscribe(
519
- "form:submit",
520
- i.current.onSubmit,
521
- { formId: d }
522
- )
523
- ), i.current.onShow && t.push(
524
- _.subscribe(
525
- "form:show",
526
- i.current.onShow,
527
- { formId: d }
528
- )
529
- ), i.current.onClose && t.push(
530
- _.subscribe(
531
- "form:close",
532
- i.current.onClose,
533
- { formId: d }
534
- )
535
- ), i.current.onSectionChange && t.push(
536
- _.subscribe(
537
- "form:section:change",
538
- i.current.onSectionChange,
539
- { formId: d }
540
- )
541
- ), i.current.onQuestionAnswered && t.push(
542
- _.subscribe(
543
- "form:question:answered",
544
- i.current.onQuestionAnswered,
545
- { formId: d }
546
- )
547
- ), i.current.onError && t.push(
548
- _.subscribe(
549
- "form:error",
550
- i.current.onError,
551
- { formId: d }
552
- )
553
- ), () => t.forEach((b) => b());
554
- }, [h, d]), y(() => {
555
- if (h) {
556
- T(!1);
557
- return;
558
- }
559
- try {
560
- if (!o) {
561
- console.warn("[EncatchPreview] formData is not defined (inline mode)");
562
- return;
563
- }
564
- T(!0);
565
- } catch (t) {
566
- console.error("[EncatchPreview] Error during data validation:", t);
567
- }
568
- }, [h, o]);
569
- const Y = re(() => {
570
- o?.onClose && o.onClose(), J(!1);
571
- }, [o?.onClose]);
572
- return y(() => {
573
- if (h || !x || !g.current || !o) return;
574
- const t = document.createElement("encatch-app");
575
- return t.theme = o.theme, t.currentMode = o.currentMode, t.currentLanguage = o.currentLanguage, t.questions = o.questions, t.questionLanguages = o.questionLanguages, t.otherConfigurationProperties = o.otherConfigurationProperties, t.welcomeScreenProperties = o.welcomeScreenProperties, t.endScreenProperties = o.endScreenProperties, t.translations = o.translations, t.sections = o.sections, t.themeSettings = o.themeSettings, t.onClose = Y, t.onSectionChange = o.onSectionChange, t.apiKey = o.apiKey, t.hostUrl = o.hostUrl, t.feedbackConfigId = o.feedbackConfigId, t.identifier = o.identifier, c && (t.cssLink = c), t.scale = f, t.persistMode = w, d && (t.instanceId = d), A.current = t, g.current.appendChild(t), () => {
576
- if (g.current && A.current)
577
- try {
578
- g.current.removeChild(A.current);
579
- } catch {
580
- }
581
- A.current = null;
582
- };
583
- }, [
584
- h,
585
- x,
586
- o,
587
- c,
588
- f,
589
- Y,
590
- w,
591
- d
592
- ]), q ? /* @__PURE__ */ ue.jsx(
593
- "div",
594
- {
595
- ref: g,
596
- style: h ? { width: "100%", height: "100%", minHeight: 400 } : void 0
597
- }
598
- ) : null;
599
- };
600
- function be(o, r, n) {
601
- y(() => _.subscribe(
602
- o,
530
+ const re = new ue();
531
+ function de(i, r, n) {
532
+ P(() => re.subscribe(
533
+ i,
603
534
  r,
604
535
  n
605
- ), [o, n?.formId, r]);
536
+ ), [i, n?.formId, r]);
606
537
  }
607
- function me(o, r) {
608
- y(() => _.subscribeAll(o, r), [r?.formId, o]);
538
+ function me(i, r) {
539
+ P(() => re.subscribeAll(i, r), [r?.formId, i]);
609
540
  }
610
541
  export {
611
- de as EncatchPreview,
612
- be as useEncatchFormEvent,
542
+ fe as EncatchPreview,
543
+ de as useEncatchFormEvent,
613
544
  me as useEncatchFormEventAll
614
545
  };
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(S,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],f):(S=typeof globalThis<"u"?globalThis:S||self,f(S.WsReact={},S.React))})(this,(function(S,f){"use strict";var L={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 M={exports:{}},x={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.js
4
4
  *
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var B;function ne(){if(B)return x;B=1;var o=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function t(a,c,d){var E=null;if(d!==void 0&&(E=""+d),c.key!==void 0&&(E=""+c.key),"key"in c){d={};for(var b in c)b!=="key"&&(d[b]=c[b])}else d=c;return c=d.ref,{$$typeof:o,type:a,key:E,ref:c!==void 0?c:null,props:d}}return x.Fragment=r,x.jsx=t,x.jsxs=t,x}var N={};/**
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={};/**
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 X;function te(){return X||(X=1,process.env.NODE_ENV!=="production"&&(function(){function o(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===V?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case g:return"Fragment";case _:return"Profiler";case A:return"StrictMode";case W:return"Suspense";case $:return"SuspenseList";case U: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 J:return"Portal";case q:return(e.displayName||"Context")+".Provider";case F:return(e._context.displayName||"Context")+".Consumer";case i:var s=e.render;return e=e.displayName,e||(e=s.displayName||s.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case n:return s=e.displayName||null,s!==null?s:o(e.type)||"Memo";case m:s=e._payload,e=e._init;try{return o(e(s))}catch{}}return null}function r(e){return""+e}function t(e){try{r(e);var s=!1}catch{s=!0}if(s){s=console;var l=s.error,p=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return l.call(s,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",p),r(e)}}function a(e){if(e===g)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===m)return"<...>";try{var s=o(e);return s?"<"+s+">":"<...>"}catch{return"<...>"}}function c(){var e=v.A;return e===null?null:e.getOwner()}function d(){return Error("react-stack-top-frame")}function E(e){if(P.call(e,"key")){var s=Object.getOwnPropertyDescriptor(e,"key").get;if(s&&s.isReactWarning)return!1}return e.key!==void 0}function b(e,s){function l(){D||(D=!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)",s))}l.isReactWarning=!0,Object.defineProperty(e,"key",{get:l,configurable:!0})}function R(){var e=o(this.type);return Z[e]||(Z[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 w(e,s,l,p,T,k,z,Q){return l=k.ref,e={$$typeof:Y,type:e,key:s,props:k,_owner:T},(l!==void 0?l:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:R}):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:z}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:Q}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function C(e,s,l,p,T,k,z,Q){var h=s.children;if(h!==void 0)if(p)if(O(h)){for(p=0;p<h.length;p++)M(h[p]);Object.freeze&&Object.freeze(h)}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 M(h);if(P.call(s,"key")){h=o(e);var j=Object.keys(s).filter(function(fe){return fe!=="key"});p=0<j.length?"{key: someKey, "+j.join(": ..., ")+": ...}":"{key: someKey}",re[h+p]||(j=0<j.length?"{"+j.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
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:
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,h,j,h),re[h+p]=!0)}if(h=null,l!==void 0&&(t(l),h=""+l),E(s)&&(t(s.key),h=""+s.key),"key"in s){l={};for(var G in s)G!=="key"&&(l[G]=s[G])}else l=s;return h&&b(l,typeof e=="function"?e.displayName||e.name||"Unknown":e),w(e,h,k,T,c(),l,z,Q)}function M(e){typeof e=="object"&&e!==null&&e.$$typeof===Y&&e._store&&(e._store.validated=1)}var I=f,Y=Symbol.for("react.transitional.element"),J=Symbol.for("react.portal"),g=Symbol.for("react.fragment"),A=Symbol.for("react.strict_mode"),_=Symbol.for("react.profiler"),F=Symbol.for("react.consumer"),q=Symbol.for("react.context"),i=Symbol.for("react.forward_ref"),W=Symbol.for("react.suspense"),$=Symbol.for("react.suspense_list"),n=Symbol.for("react.memo"),m=Symbol.for("react.lazy"),U=Symbol.for("react.activity"),V=Symbol.for("react.client.reference"),v=I.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,P=Object.prototype.hasOwnProperty,O=Array.isArray,u=console.createTask?console.createTask:function(){return null};I={react_stack_bottom_frame:function(e){return e()}};var D,Z={},K=I.react_stack_bottom_frame.bind(I,d)(),ee=u(a(d)),re={};N.Fragment=g,N.jsx=function(e,s,l,p,T){var k=1e4>v.recentlyCreatedOwnerStacks++;return C(e,s,l,!1,p,T,k?Error("react-stack-top-frame"):K,k?u(a(e)):ee)},N.jsxs=function(e,s,l,p,T){var k=1e4>v.recentlyCreatedOwnerStacks++;return C(e,s,l,!0,p,T,k?Error("react-stack-top-frame"):K,k?u(a(e)):ee)}})()),N}var H;function oe(){return H||(H=1,process.env.NODE_ENV==="production"?L.exports=ne():L.exports=te()),L.exports}var se=oe();class ie extends EventTarget{subscriptions=new Map;targetOrigin="*";matchesFilter(r,t){return!t||t==="*"||t===null||t===void 0?!0:typeof t=="string"?r===t:Array.isArray(t)?t.includes(r||""):typeof t=="function"?t(r||""):!1}getFormIdFromPayload(r){return r?.feedbackConfigurationId}publish(r,t,a){typeof window<"u"&&window.dispatchEvent(new CustomEvent(r,{detail:t,bubbles:!0})),a?.usePostMessage!==!1&&this.sendPostMessage(r,t)}subscribe(r,t,a){const c=Symbol("subscription"),d={eventType:r,handler:t,filter:a?.formId,id:c,once:a?.once};this.subscriptions.has(r)||this.subscriptions.set(r,[]),this.subscriptions.get(r).push(d);const E=b=>{const R=b,w=this.getFormIdFromPayload(R.detail);this.matchesFilter(w,a?.formId)&&(t(R.detail),a?.once&&typeof window<"u"&&window.removeEventListener(r,E))};return typeof window<"u"&&window.addEventListener(r,E),()=>{this.unsubscribe(c),typeof window<"u"&&window.removeEventListener(r,E)}}unsubscribe(r){for(const[t,a]of this.subscriptions.entries()){const c=a.findIndex(d=>d.id===r);if(c!==-1){a.splice(c,1),a.length===0&&this.subscriptions.delete(t);break}}}subscribeAll(r,t){const a=["form:show","form:started","form:submit","form:close","form:section:change","form:question:answered","form:error"],c=[];return a.forEach(d=>{const E=this.subscribe(d,b=>r(d,b),t);c.push(E)}),()=>{c.forEach(d=>d())}}getSubscriptionCount(r){return r?this.subscriptions.get(r)?.length||0:Array.from(this.subscriptions.values()).reduce((t,a)=>t+a.length,0)}clearSubscriptions(r){r?this.subscriptions.delete(r):this.subscriptions.clear()}sendPostMessage(r,t){const a={type:`encatch:${r}`,payload:t,source:"encatch-form-engine"};window.parent&&window.parent!==window&&window.parent.postMessage(a,this.targetOrigin),document.querySelectorAll("iframe").forEach(c=>{c.contentWindow&&c.contentWindow.postMessage(a,this.targetOrigin)}),typeof window.ReactNativeWebView<"u"&&window.ReactNativeWebView.postMessage(JSON.stringify({action:r.replace("form:",""),data:JSON.stringify(t)}))}}const y=new ie,ue=({formData:o,formConfig:r,formPageUrl:t,formId:a,cssLink:c,scale:d=100,persistMode:E="none",instanceId:b,onFormEvent:R})=>{const w=!!(r&&t),C=a??r?.formId??b??"preview",[M,I]=f.useState(!1),[Y,J]=f.useState(!0),g=f.useRef(null),A=f.useRef(null),_=f.useRef(null),F=f.useRef(!1),q=f.useRef(()=>{}),i=f.useRef({});f.useEffect(()=>{if(!R)return;R({onSubmit:m=>{i.current.onSubmit=m},onShow:m=>{i.current.onShow=m},onClose:m=>{i.current.onClose=m},onSectionChange:m=>{i.current.onSectionChange=m},onQuestionAnswered:m=>{i.current.onQuestionAnswered=m},onError:m=>{i.current.onError=m}})},[R]);const W=f.useCallback(()=>{if(!_.current?.contentWindow||!r)return;const n={formId:C,...r};_.current.contentWindow.postMessage({type:"sdk:formConfig",data:n},"*")},[r,C]);q.current=W,f.useEffect(()=>{!w||!F.current||q.current()},[w,r,W]),f.useEffect(()=>{if(!w||!g.current)return;const n=document.createElement("iframe"),m=new URL(t,window.location.origin);m.searchParams.set("formId",C),n.src=m.toString(),n.title="Encatch form",n.style.width="100%",n.style.height="100%",n.style.border="none",_.current=n,g.current.appendChild(n);const U=V=>{const v=V.data;if(!v||typeof v!="object"||!v.type)return;let P=v.type,O=v.formId,u=v.data;switch(P.startsWith("encatch:")&&(P=P.replace("encatch:",""),O=v.payload?.feedbackConfigurationId,u=v.payload),P){case"form:ready":F.current=!0,q.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":u&&i.current.onSubmit&&i.current.onSubmit({feedbackConfigurationId:u.feedbackConfigurationId,feedbackIdentifier:u.feedbackIdentifier,response:u.response,isPartialSubmit:u.isPartialSubmit,timestamp:Date.now()});break;case"form:show":u&&i.current.onShow&&i.current.onShow({feedbackConfigurationId:u.feedbackConfigurationId,feedbackIdentifier:u.feedbackIdentifier,timestamp:Date.now()});break;case"form:started":u&&i.current.onShow&&i.current.onShow({feedbackConfigurationId:u.feedbackConfigurationId,feedbackIdentifier:u.feedbackIdentifier,timestamp:Date.now()});break;case"form:section:change":u&&i.current.onSectionChange&&i.current.onSectionChange({feedbackConfigurationId:u.feedbackConfigurationId??O??"",sectionIndex:u.sectionIndex,sectionId:u.sectionId,timestamp:Date.now()});break;case"form:question:answered":u&&i.current.onQuestionAnswered&&i.current.onQuestionAnswered({feedbackConfigurationId:u.feedbackConfigurationId??O??"",questionId:u.questionId,questionType:u.questionType,answer:u.answer,timestamp:Date.now()});break;case"form:error":u&&i.current.onError&&i.current.onError({feedbackConfigurationId:u.feedbackConfigurationId??O??"",questionId:u.questionId,error:u.error??"Unknown error",timestamp:Date.now()});break}};return window.addEventListener("message",U),()=>{if(window.removeEventListener("message",U),F.current=!1,g.current&&_.current)try{g.current.removeChild(_.current)}catch{}_.current=null}},[w,t,C]),f.useEffect(()=>{if(w||!b)return;const n=[];return i.current.onSubmit&&n.push(y.subscribe("form:submit",i.current.onSubmit,{formId:b})),i.current.onShow&&n.push(y.subscribe("form:show",i.current.onShow,{formId:b})),i.current.onClose&&n.push(y.subscribe("form:close",i.current.onClose,{formId:b})),i.current.onSectionChange&&n.push(y.subscribe("form:section:change",i.current.onSectionChange,{formId:b})),i.current.onQuestionAnswered&&n.push(y.subscribe("form:question:answered",i.current.onQuestionAnswered,{formId:b})),i.current.onError&&n.push(y.subscribe("form:error",i.current.onError,{formId:b})),()=>n.forEach(m=>m())},[w,b]),f.useEffect(()=>{if(w){I(!1);return}try{if(!o){console.warn("[EncatchPreview] formData is not defined (inline mode)");return}I(!0)}catch(n){console.error("[EncatchPreview] Error during data validation:",n)}},[w,o]);const $=f.useCallback(()=>{o?.onClose&&o.onClose(),J(!1)},[o?.onClose]);return f.useEffect(()=>{if(w||!M||!g.current||!o)return;const n=document.createElement("encatch-app");return n.theme=o.theme,n.currentMode=o.currentMode,n.currentLanguage=o.currentLanguage,n.questions=o.questions,n.questionLanguages=o.questionLanguages,n.otherConfigurationProperties=o.otherConfigurationProperties,n.welcomeScreenProperties=o.welcomeScreenProperties,n.endScreenProperties=o.endScreenProperties,n.translations=o.translations,n.sections=o.sections,n.themeSettings=o.themeSettings,n.onClose=$,n.onSectionChange=o.onSectionChange,n.apiKey=o.apiKey,n.hostUrl=o.hostUrl,n.feedbackConfigId=o.feedbackConfigId,n.identifier=o.identifier,c&&(n.cssLink=c),n.scale=d,n.persistMode=E,b&&(n.instanceId=b),A.current=n,g.current.appendChild(n),()=>{if(g.current&&A.current)try{g.current.removeChild(A.current)}catch{}A.current=null}},[w,M,o,c,d,$,E,b]),Y?se.jsx("div",{ref:g,style:w?{width:"100%",height:"100%",minHeight:400}:void 0}):null};function ce(o,r,t){f.useEffect(()=>y.subscribe(o,r,t),[o,t?.formId,r])}function ae(o,r){f.useEffect(()=>y.subscribeAll(o,r),[r?.formId,o])}S.EncatchPreview=ue,S.useEncatchFormEvent=ce,S.useEncatchFormEventAll=ae,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})}));
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"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@encatch/ws-react",
3
- "version": "0.0.50-beta.3",
3
+ "version": "0.0.50-beta.5",
4
4
  "type": "module",
5
5
  "main": "./dist/index.umd.js",
6
6
  "module": "./dist/index.es.js",