@encatch/ws-react 0.1.0-beta.22 → 0.1.0-beta.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.es.js +26 -26
- package/dist/index.umd.js +3 -3
- package/package.json +2 -2
package/dist/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import q, { useRef as $, useEffect as
|
|
2
|
-
var j = { exports: {} },
|
|
1
|
+
import q, { useRef as $, useEffect as P, useCallback as X } from "react";
|
|
2
|
+
var j = { exports: {} }, C = {};
|
|
3
3
|
/**
|
|
4
4
|
* @license React
|
|
5
5
|
* react-jsx-runtime.production.js
|
|
@@ -11,7 +11,7 @@ var j = { exports: {} }, A = {};
|
|
|
11
11
|
*/
|
|
12
12
|
var H;
|
|
13
13
|
function ae() {
|
|
14
|
-
if (H) return
|
|
14
|
+
if (H) return C;
|
|
15
15
|
H = 1;
|
|
16
16
|
var f = Symbol.for("react.transitional.element"), r = Symbol.for("react.fragment");
|
|
17
17
|
function n(a, s, c) {
|
|
@@ -29,9 +29,9 @@ function ae() {
|
|
|
29
29
|
props: c
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
return
|
|
32
|
+
return C.Fragment = r, C.jsx = n, C.jsxs = n, C;
|
|
33
33
|
}
|
|
34
|
-
var
|
|
34
|
+
var O = {};
|
|
35
35
|
/**
|
|
36
36
|
* @license React
|
|
37
37
|
* react-jsx-runtime.development.js
|
|
@@ -52,13 +52,13 @@ function se() {
|
|
|
52
52
|
switch (e) {
|
|
53
53
|
case u:
|
|
54
54
|
return "Fragment";
|
|
55
|
-
case
|
|
55
|
+
case A:
|
|
56
56
|
return "Profiler";
|
|
57
57
|
case d:
|
|
58
58
|
return "StrictMode";
|
|
59
59
|
case _:
|
|
60
60
|
return "Suspense";
|
|
61
|
-
case
|
|
61
|
+
case S:
|
|
62
62
|
return "SuspenseList";
|
|
63
63
|
case re:
|
|
64
64
|
return "Activity";
|
|
@@ -197,10 +197,10 @@ function se() {
|
|
|
197
197
|
else y(p);
|
|
198
198
|
if (U.call(t, "key")) {
|
|
199
199
|
p = f(e);
|
|
200
|
-
var
|
|
200
|
+
var T = Object.keys(t).filter(function(oe) {
|
|
201
201
|
return oe !== "key";
|
|
202
202
|
});
|
|
203
|
-
b = 0 <
|
|
203
|
+
b = 0 < T.length ? "{key: someKey, " + T.join(": ..., ") + ": ...}" : "{key: someKey}", Q[p + b] || (T = 0 < T.length ? "{" + T.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
204
204
|
`A props object containing a "key" prop is being spread into JSX:
|
|
205
205
|
let props = %s;
|
|
206
206
|
<%s {...props} />
|
|
@@ -209,7 +209,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
209
209
|
<%s key={someKey} {...props} />`,
|
|
210
210
|
b,
|
|
211
211
|
p,
|
|
212
|
-
|
|
212
|
+
T,
|
|
213
213
|
p
|
|
214
214
|
), Q[p + b] = !0);
|
|
215
215
|
}
|
|
@@ -235,7 +235,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
235
235
|
function y(e) {
|
|
236
236
|
typeof e == "object" && e !== null && e.$$typeof === I && e._store && (e._store.validated = 1);
|
|
237
237
|
}
|
|
238
|
-
var i = q, I = Symbol.for("react.transitional.element"), N = Symbol.for("react.portal"), u = Symbol.for("react.fragment"), d = Symbol.for("react.strict_mode"),
|
|
238
|
+
var i = q, I = Symbol.for("react.transitional.element"), N = Symbol.for("react.portal"), u = Symbol.for("react.fragment"), d = Symbol.for("react.strict_mode"), A = Symbol.for("react.profiler"), x = Symbol.for("react.consumer"), F = Symbol.for("react.context"), E = Symbol.for("react.forward_ref"), _ = Symbol.for("react.suspense"), S = Symbol.for("react.suspense_list"), o = Symbol.for("react.memo"), J = Symbol.for("react.lazy"), re = Symbol.for("react.activity"), te = Symbol.for("react.client.reference"), D = i.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, U = Object.prototype.hasOwnProperty, ne = Array.isArray, M = console.createTask ? console.createTask : function() {
|
|
239
239
|
return null;
|
|
240
240
|
};
|
|
241
241
|
i = {
|
|
@@ -247,7 +247,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
247
247
|
i,
|
|
248
248
|
c
|
|
249
249
|
)(), B = M(a(c)), Q = {};
|
|
250
|
-
|
|
250
|
+
O.Fragment = u, O.jsx = function(e, t, l, b, k) {
|
|
251
251
|
var g = 1e4 > D.recentlyCreatedOwnerStacks++;
|
|
252
252
|
return R(
|
|
253
253
|
e,
|
|
@@ -259,7 +259,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
259
259
|
g ? Error("react-stack-top-frame") : G,
|
|
260
260
|
g ? M(a(e)) : B
|
|
261
261
|
);
|
|
262
|
-
},
|
|
262
|
+
}, O.jsxs = function(e, t, l, b, k) {
|
|
263
263
|
var g = 1e4 > D.recentlyCreatedOwnerStacks++;
|
|
264
264
|
return R(
|
|
265
265
|
e,
|
|
@@ -272,7 +272,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
272
272
|
g ? M(a(e)) : B
|
|
273
273
|
);
|
|
274
274
|
};
|
|
275
|
-
})()),
|
|
275
|
+
})()), O;
|
|
276
276
|
}
|
|
277
277
|
var K;
|
|
278
278
|
function ie() {
|
|
@@ -289,7 +289,7 @@ const fe = ({
|
|
|
289
289
|
}) => {
|
|
290
290
|
const m = !!(f && r), w = n ?? f?.formId ?? s ?? "preview", v = q.useRef(null), h = q.useRef(null), R = $(!1), y = $(() => {
|
|
291
291
|
}), i = $({});
|
|
292
|
-
|
|
292
|
+
P(() => {
|
|
293
293
|
if (!c) return;
|
|
294
294
|
c({
|
|
295
295
|
onSubmit: (d) => {
|
|
@@ -320,23 +320,23 @@ const fe = ({
|
|
|
320
320
|
"*"
|
|
321
321
|
);
|
|
322
322
|
}, [f, w, a]);
|
|
323
|
-
y.current = I,
|
|
323
|
+
y.current = I, P(() => {
|
|
324
324
|
!m || !R.current || y.current();
|
|
325
325
|
}, [m, f, I]);
|
|
326
326
|
const N = X((u) => {
|
|
327
327
|
u.style.border = "none", u.style.width = "100%", u.style.height = "100%";
|
|
328
328
|
}, []);
|
|
329
|
-
return
|
|
329
|
+
return P(() => {
|
|
330
330
|
if (!m || !v.current || !f || !r) return;
|
|
331
331
|
const u = document.createElement("div");
|
|
332
332
|
u.className = "encatch-preview-inner", u.style.width = "100%", u.style.height = "100%", u.style.display = "flex", u.style.flexDirection = "column", u.style.justifyContent = "flex-end", u.style.overflow = "auto";
|
|
333
|
-
const d = document.createElement("iframe"),
|
|
334
|
-
|
|
333
|
+
const d = document.createElement("iframe"), A = new URL(r, window.location.origin);
|
|
334
|
+
A.searchParams.set("formId", w), A.searchParams.set("_t", String(Date.now())), d.src = A.toString(), d.title = "Encatch form", N(d), h.current = d, u.appendChild(d), v.current.appendChild(u);
|
|
335
335
|
const x = (F) => {
|
|
336
336
|
const E = F.data;
|
|
337
337
|
if (!E || typeof E != "object" || !E.type) return;
|
|
338
|
-
let _ = E.type,
|
|
339
|
-
switch (_.startsWith("encatch:") && (_ = _.replace("encatch:", ""),
|
|
338
|
+
let _ = E.type, S = E.formId, o = E.data;
|
|
339
|
+
switch (_.startsWith("encatch:") && (_ = _.replace("encatch:", ""), S = E.payload?.feedbackConfigurationId, o = E.payload), _) {
|
|
340
340
|
case "form:resize":
|
|
341
341
|
h.current && o && typeof o.height == "number" && (h.current.style.height = `${o.height}px`);
|
|
342
342
|
break;
|
|
@@ -374,7 +374,7 @@ const fe = ({
|
|
|
374
374
|
break;
|
|
375
375
|
case "form:section:change":
|
|
376
376
|
o && i.current.onSectionChange && i.current.onSectionChange({
|
|
377
|
-
feedbackConfigurationId: o.feedbackConfigurationId ??
|
|
377
|
+
feedbackConfigurationId: o.feedbackConfigurationId ?? S ?? "",
|
|
378
378
|
sectionIndex: o.sectionIndex,
|
|
379
379
|
sectionId: o.sectionId,
|
|
380
380
|
timestamp: Date.now()
|
|
@@ -382,7 +382,7 @@ const fe = ({
|
|
|
382
382
|
break;
|
|
383
383
|
case "form:answered":
|
|
384
384
|
o && i.current.onQuestionAnswered && i.current.onQuestionAnswered({
|
|
385
|
-
feedbackConfigurationId: o.feedbackConfigurationId ??
|
|
385
|
+
feedbackConfigurationId: o.feedbackConfigurationId ?? S ?? "",
|
|
386
386
|
questionId: o.questionId,
|
|
387
387
|
questionType: o.questionType,
|
|
388
388
|
answer: o.answer,
|
|
@@ -391,7 +391,7 @@ const fe = ({
|
|
|
391
391
|
break;
|
|
392
392
|
case "form:error":
|
|
393
393
|
o && i.current.onError && i.current.onError({
|
|
394
|
-
feedbackConfigurationId: o.feedbackConfigurationId ??
|
|
394
|
+
feedbackConfigurationId: o.feedbackConfigurationId ?? S ?? "",
|
|
395
395
|
questionId: o.questionId,
|
|
396
396
|
error: o.error ?? "Unknown error",
|
|
397
397
|
timestamp: Date.now()
|
|
@@ -524,14 +524,14 @@ class ue extends EventTarget {
|
|
|
524
524
|
}
|
|
525
525
|
const ee = new ue();
|
|
526
526
|
function de(f, r, n) {
|
|
527
|
-
|
|
527
|
+
P(() => ee.subscribe(
|
|
528
528
|
f,
|
|
529
529
|
r,
|
|
530
530
|
n
|
|
531
531
|
), [f, n?.formId, r]);
|
|
532
532
|
}
|
|
533
533
|
function me(f, r) {
|
|
534
|
-
|
|
534
|
+
P(() => ee.subscribeAll(f, r), [r?.formId, f]);
|
|
535
535
|
}
|
|
536
536
|
export {
|
|
537
537
|
fe as EncatchPreview,
|
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(k,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],m):(k=typeof globalThis<"u"?globalThis:k||self,m(k.WsReact={},k.React))})(this,(function(k,m){"use strict";var
|
|
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={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.js
|
|
4
4
|
*
|
|
@@ -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 J;function ee(){return J||(J=1,process.env.NODE_ENV!=="production"&&(function(){function l(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 u:return"Fragment";case
|
|
17
|
+
*/var J;function ee(){return J||(J=1,process.env.NODE_ENV!=="production"&&(function(){function l(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 u:return"Fragment";case x:return"Profiler";case d:return"StrictMode";case S:return"Suspense";case I:return"SuspenseList";case ie:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case F:return"Portal";case D:return(e.displayName||"Context")+".Provider";case N:return(e._context.displayName||"Context")+".Consumer";case v:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case o:return t=e.displayName||null,t!==null?t:l(e.type)||"Memo";case z:t=e._payload,e=e._init;try{return l(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===u)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===z)return"<...>";try{var t=l(e);return t?"<"+t+">":"<...>"}catch{return"<...>"}}function a(){var e=M.A;return e===null?null:e.getOwner()}function c(){return Error("react-stack-top-frame")}function b(e){if(G.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return e.key!==void 0}function h(e,t){function f(){B||(B=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}f.isReactWarning=!0,Object.defineProperty(e,"key",{get:f,configurable:!0})}function y(){var e=l(this.type);return Q[e]||(Q[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function E(e,t,f,p,R,g,W,L){return f=g.ref,e={$$typeof:P,type:e,key:t,props:g,_owner:R},(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:W}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:L}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function _(e,t,f,p,R,g,W,L){var w=t.children;if(w!==void 0)if(p)if(ue(w)){for(p=0;p<w.length;p++)T(w[p]);Object.freeze&&Object.freeze(w)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else T(w);if(G.call(t,"key")){w=l(e);var A=Object.keys(t).filter(function(fe){return fe!=="key"});p=0<A.length?"{key: someKey, "+A.join(": ..., ")+": ...}":"{key: someKey}",Z[w+p]||(A=0<A.length?"{"+A.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
18
18
|
let props = %s;
|
|
19
19
|
<%s {...props} />
|
|
20
20
|
React keys must be passed directly to JSX without using spread:
|
|
21
21
|
let props = %s;
|
|
22
|
-
<%s key={someKey} {...props} />`,p,w,A,w),Z[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 $ in t)$!=="key"&&(f[$]=t[$])}else f=t;return w&&h(f,typeof e=="function"?e.displayName||e.name||"Unknown":e),E(e,w,g,R,a(),f,W,L)}function T(e){typeof e=="object"&&e!==null&&e.$$typeof===P&&e._store&&(e._store.validated=1)}var i=m,P=Symbol.for("react.transitional.element"),F=Symbol.for("react.portal"),u=Symbol.for("react.fragment"),d=Symbol.for("react.strict_mode"),
|
|
22
|
+
<%s key={someKey} {...props} />`,p,w,A,w),Z[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 $ in t)$!=="key"&&(f[$]=t[$])}else f=t;return w&&h(f,typeof e=="function"?e.displayName||e.name||"Unknown":e),E(e,w,g,R,a(),f,W,L)}function T(e){typeof e=="object"&&e!==null&&e.$$typeof===P&&e._store&&(e._store.validated=1)}var i=m,P=Symbol.for("react.transitional.element"),F=Symbol.for("react.portal"),u=Symbol.for("react.fragment"),d=Symbol.for("react.strict_mode"),x=Symbol.for("react.profiler"),N=Symbol.for("react.consumer"),D=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),I=Symbol.for("react.suspense_list"),o=Symbol.for("react.memo"),z=Symbol.for("react.lazy"),ie=Symbol.for("react.activity"),ce=Symbol.for("react.client.reference"),M=i.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,G=Object.prototype.hasOwnProperty,ue=Array.isArray,Y=console.createTask?console.createTask:function(){return null};i={react_stack_bottom_frame:function(e){return e()}};var B,Q={},X=i.react_stack_bottom_frame.bind(i,c)(),H=Y(s(c)),Z={};O.Fragment=u,O.jsx=function(e,t,f,p,R){var g=1e4>M.recentlyCreatedOwnerStacks++;return _(e,t,f,!1,p,R,g?Error("react-stack-top-frame"):X,g?Y(s(e)):H)},O.jsxs=function(e,t,f,p,R){var g=1e4>M.recentlyCreatedOwnerStacks++;return _(e,t,f,!0,p,R,g?Error("react-stack-top-frame"):X,g?Y(s(e)):H)}})()),O}var U;function re(){return U||(U=1,process.env.NODE_ENV==="production"?j.exports=K():j.exports=ee()),j.exports}var te=re();const ne=({formConfig:l,formPageUrl:r,formId:n,scale:s=100,instanceId:a,onFormEvent:c})=>{const b=!!(l&&r),h=n??l?.formId??a??"preview",y=m.useRef(null),E=m.useRef(null),_=m.useRef(!1),T=m.useRef(()=>{}),i=m.useRef({});m.useEffect(()=>{if(!c)return;c({onSubmit:d=>{i.current.onSubmit=d},onShow:d=>{i.current.onShow=d},onClose:d=>{i.current.onClose=d},onSectionChange:d=>{i.current.onSectionChange=d},onQuestionAnswered:d=>{i.current.onQuestionAnswered=d},onError:d=>{i.current.onError=d}})},[c]);const P=m.useCallback(()=>{if(!E.current?.contentWindow||!l)return;const u={formId:h,scale:s,...l};E.current.contentWindow.postMessage({type:"sdk:formConfig",data:u},"*")},[l,h,s]);T.current=P,m.useEffect(()=>{!b||!_.current||T.current()},[b,l,P]);const F=m.useCallback(u=>{u.style.border="none",u.style.width="100%",u.style.height="100%"},[]);return m.useEffect(()=>{if(!b||!y.current||!l||!r)return;const u=document.createElement("div");u.className="encatch-preview-inner",u.style.width="100%",u.style.height="100%",u.style.display="flex",u.style.flexDirection="column",u.style.justifyContent="flex-end",u.style.overflow="auto";const d=document.createElement("iframe"),x=new URL(r,window.location.origin);x.searchParams.set("formId",h),x.searchParams.set("_t",String(Date.now())),d.src=x.toString(),d.title="Encatch form",F(d),E.current=d,u.appendChild(d),y.current.appendChild(u);const N=D=>{const v=D.data;if(!v||typeof v!="object"||!v.type)return;let S=v.type,I=v.formId,o=v.data;switch(S.startsWith("encatch:")&&(S=S.replace("encatch:",""),I=v.payload?.feedbackConfigurationId,o=v.payload),S){case"form:resize":E.current&&o&&typeof o.height=="number"&&(E.current.style.height=`${o.height}px`);break;case"form:ready":_.current=!0,T.current();break;case"form:close":i.current.onClose?.({timestamp:Date.now()});break;case"form:complete":i.current.onClose?.({timestamp:Date.now()});break;case"form:submit":o&&i.current.onSubmit&&i.current.onSubmit({feedbackConfigurationId:o.feedbackConfigurationId,feedbackIdentifier:o.feedbackIdentifier,response:o.response,isPartialSubmit:o.isPartialSubmit,timestamp:Date.now()});break;case"form:show":o&&i.current.onShow&&i.current.onShow({feedbackConfigurationId:o.feedbackConfigurationId,feedbackIdentifier:o.feedbackIdentifier,timestamp:Date.now()});break;case"form:started":o&&i.current.onShow&&i.current.onShow({feedbackConfigurationId:o.feedbackConfigurationId,feedbackIdentifier:o.feedbackIdentifier,timestamp:Date.now()});break;case"form:section:change":o&&i.current.onSectionChange&&i.current.onSectionChange({feedbackConfigurationId:o.feedbackConfigurationId??I??"",sectionIndex:o.sectionIndex,sectionId:o.sectionId,timestamp:Date.now()});break;case"form:answered":o&&i.current.onQuestionAnswered&&i.current.onQuestionAnswered({feedbackConfigurationId:o.feedbackConfigurationId??I??"",questionId:o.questionId,questionType:o.questionType,answer:o.answer,timestamp:Date.now()});break;case"form:error":o&&i.current.onError&&i.current.onError({feedbackConfigurationId:o.feedbackConfigurationId??I??"",questionId:o.questionId,error:o.error??"Unknown error",timestamp:Date.now()});break}};return window.addEventListener("message",N),()=>{window.removeEventListener("message",N),_.current=!1,u.parentNode&&u.parentNode.removeChild(u),E.current=null}},[b,r,h]),te.jsx("div",{ref:y,title:"encatchPreview1",style:b?{width:"100%",height:"100%"}:void 0})};class oe extends EventTarget{subscriptions=new Map;targetOrigin="*";matchesFilter(r,n){return!n||n==="*"||n===null||n===void 0?!0:typeof n=="string"?r===n:Array.isArray(n)?n.includes(r||""):typeof n=="function"?n(r||""):!1}getFormIdFromPayload(r){return r?.feedbackConfigurationId}publish(r,n,s){typeof window<"u"&&window.dispatchEvent(new CustomEvent(r,{detail:n,bubbles:!0})),s?.usePostMessage!==!1&&this.sendPostMessage(r,n)}subscribe(r,n,s){const a=Symbol("subscription"),c={eventType:r,handler:n,filter:s?.formId,id:a,once:s?.once};this.subscriptions.has(r)||this.subscriptions.set(r,[]),this.subscriptions.get(r).push(c);const b=h=>{const y=h,E=this.getFormIdFromPayload(y.detail);this.matchesFilter(E,s?.formId)&&(n(y.detail),s?.once&&typeof window<"u"&&window.removeEventListener(r,b))};return typeof window<"u"&&window.addEventListener(r,b),()=>{this.unsubscribe(a),typeof window<"u"&&window.removeEventListener(r,b)}}unsubscribe(r){for(const[n,s]of this.subscriptions.entries()){const a=s.findIndex(c=>c.id===r);if(a!==-1){s.splice(a,1),s.length===0&&this.subscriptions.delete(n);break}}}subscribeAll(r,n){const s=["form:show","form:started","form:submit","form:close","form:section:change","form:answered","form:error"],a=[];return s.forEach(c=>{const b=this.subscribe(c,h=>r(c,h),n);a.push(b)}),()=>{a.forEach(c=>c())}}getSubscriptionCount(r){return r?this.subscriptions.get(r)?.length||0:Array.from(this.subscriptions.values()).reduce((n,s)=>n+s.length,0)}clearSubscriptions(r){r?this.subscriptions.delete(r):this.subscriptions.clear()}sendPostMessage(r,n){const s={type:`encatch:${r}`,payload:n,source:"encatch-form-engine"};window.parent&&window.parent!==window&&window.parent.postMessage(s,this.targetOrigin),document.querySelectorAll("iframe").forEach(a=>{a.contentWindow&&a.contentWindow.postMessage(s,this.targetOrigin)}),typeof window.ReactNativeWebView<"u"&&window.ReactNativeWebView.postMessage(JSON.stringify({action:r.replace("form:",""),data:JSON.stringify(n)}))}}const V=new oe;function se(l,r,n){m.useEffect(()=>V.subscribe(l,r,n),[l,n?.formId,r])}function ae(l,r){m.useEffect(()=>V.subscribeAll(l,r),[r?.formId,l])}k.EncatchPreview=ne,k.useEncatchFormEvent=se,k.useEncatchFormEventAll=ae,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@encatch/ws-react",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.24",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.umd.js",
|
|
6
6
|
"module": "./dist/index.es.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"react-dom": "^19.1.1"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@encatch/schema": "1.1.0-beta.
|
|
23
|
+
"@encatch/schema": "1.1.0-beta.12",
|
|
24
24
|
"@encatch/event-publisher": "1.0.0-beta.4"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|