@encatch/ws-react 0.1.0-beta.31 → 0.2.0-beta.0

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