@encatch/ws-react 0.0.49 → 0.0.50-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.
- package/README.md +7 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +43 -42
- package/dist/index.umd.js +3 -3
- package/dist/types.d.ts +5 -5
- package/dist/useEncatchFormEvent.d.ts +2 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -97,9 +97,9 @@ function App() {
|
|
|
97
97
|
console.log('Form submitted:', data);
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
-
// Called when form is
|
|
101
|
-
formEvent.
|
|
102
|
-
console.log('Form
|
|
100
|
+
// Called when form is shown/displayed
|
|
101
|
+
formEvent.onShow((data) => {
|
|
102
|
+
console.log('Form shown:', data);
|
|
103
103
|
});
|
|
104
104
|
|
|
105
105
|
// Called when form is closed
|
|
@@ -155,8 +155,8 @@ function MyComponent() {
|
|
|
155
155
|
}, { formId: 'my-form-instance-1' });
|
|
156
156
|
|
|
157
157
|
// Subscribe once (unsubscribe after first event)
|
|
158
|
-
useEncatchFormEvent('form:
|
|
159
|
-
console.log('Form
|
|
158
|
+
useEncatchFormEvent('form:show', (payload) => {
|
|
159
|
+
console.log('Form shown:', payload);
|
|
160
160
|
}, { formId: 'my-form-instance-1', once: true });
|
|
161
161
|
|
|
162
162
|
return <div>Your component</div>;
|
|
@@ -166,7 +166,7 @@ function MyComponent() {
|
|
|
166
166
|
#### Available Event Types
|
|
167
167
|
|
|
168
168
|
- `form:submit` - Form submission event
|
|
169
|
-
- `form:
|
|
169
|
+
- `form:show` - Form shown/displayed event
|
|
170
170
|
- `form:close` - Form closed event
|
|
171
171
|
- `form:section:change` - Section navigation event
|
|
172
172
|
- `form:question:answered` - Question answered event
|
|
@@ -207,7 +207,7 @@ import type {
|
|
|
207
207
|
FormEventBuilder,
|
|
208
208
|
OnFormEventHandler,
|
|
209
209
|
OnSubmitCallback,
|
|
210
|
-
|
|
210
|
+
OnShowCallback,
|
|
211
211
|
OnCloseCallback,
|
|
212
212
|
OnSectionChangeCallback,
|
|
213
213
|
OnQuestionAnsweredCallback,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { EncatchPreview } from "./EncatchPreview";
|
|
2
2
|
export { useEncatchFormEvent, useEncatchFormEventAll } from "./useEncatchFormEvent";
|
|
3
3
|
export type { FormEventType, FormEventPayload, SubscriptionOptions, FormIdFilter, } from "./useEncatchFormEvent";
|
|
4
|
-
export type { FormEventBuilder, OnFormEventHandler, OnSubmitCallback,
|
|
4
|
+
export type { FormEventBuilder, OnFormEventHandler, OnSubmitCallback, OnShowCallback, OnCloseCallback, OnSectionChangeCallback, OnQuestionAnsweredCallback, OnErrorCallback, } from "./types";
|
package/dist/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import I, { useState as
|
|
1
|
+
import I, { useState as U, useRef as oe, useEffect as S, useCallback as se } from "react";
|
|
2
2
|
var A = { exports: {} }, P = {};
|
|
3
3
|
/**
|
|
4
4
|
* @license React
|
|
@@ -9,10 +9,10 @@ var A = { exports: {} }, P = {};
|
|
|
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
|
|
12
|
+
var J;
|
|
13
13
|
function ie() {
|
|
14
|
-
if (
|
|
15
|
-
|
|
14
|
+
if (J) return P;
|
|
15
|
+
J = 1;
|
|
16
16
|
var o = Symbol.for("react.transitional.element"), r = Symbol.for("react.fragment");
|
|
17
17
|
function t(u, s, c) {
|
|
18
18
|
var m = null;
|
|
@@ -41,9 +41,9 @@ var k = {};
|
|
|
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
|
|
44
|
+
var V;
|
|
45
45
|
function ue() {
|
|
46
|
-
return
|
|
46
|
+
return V || (V = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
47
47
|
function o(e) {
|
|
48
48
|
if (e == null) return null;
|
|
49
49
|
if (typeof e == "function")
|
|
@@ -150,12 +150,12 @@ function ue() {
|
|
|
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 T(e, n, l, d, w,
|
|
154
|
-
return l =
|
|
153
|
+
function T(e, n, l, d, w, h, x, j) {
|
|
154
|
+
return l = h.ref, e = {
|
|
155
155
|
$$typeof: y,
|
|
156
156
|
type: e,
|
|
157
157
|
key: n,
|
|
158
|
-
props:
|
|
158
|
+
props: h,
|
|
159
159
|
_owner: w
|
|
160
160
|
}, (l !== void 0 ? l : null) !== null ? Object.defineProperty(e, "ref", {
|
|
161
161
|
enumerable: !1,
|
|
@@ -182,19 +182,19 @@ function ue() {
|
|
|
182
182
|
value: j
|
|
183
183
|
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
184
184
|
}
|
|
185
|
-
function
|
|
185
|
+
function E(e, n, l, d, w, h, x, j) {
|
|
186
186
|
var b = n.children;
|
|
187
187
|
if (b !== void 0)
|
|
188
188
|
if (d)
|
|
189
189
|
if (te(b)) {
|
|
190
190
|
for (d = 0; d < b.length; d++)
|
|
191
|
-
|
|
191
|
+
v(b[d]);
|
|
192
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
|
|
197
|
+
else v(b);
|
|
198
198
|
if (F.call(n, "key")) {
|
|
199
199
|
b = o(e);
|
|
200
200
|
var _ = Object.keys(n).filter(function(ne) {
|
|
@@ -224,7 +224,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
224
224
|
), T(
|
|
225
225
|
e,
|
|
226
226
|
b,
|
|
227
|
-
|
|
227
|
+
h,
|
|
228
228
|
w,
|
|
229
229
|
s(),
|
|
230
230
|
l,
|
|
@@ -232,7 +232,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
232
232
|
j
|
|
233
233
|
);
|
|
234
234
|
}
|
|
235
|
-
function
|
|
235
|
+
function v(e) {
|
|
236
236
|
typeof e == "object" && e !== null && e.$$typeof === y && e._store && (e._store.validated = 1);
|
|
237
237
|
}
|
|
238
238
|
var a = I, y = Symbol.for("react.transitional.element"), i = Symbol.for("react.portal"), f = Symbol.for("react.fragment"), G = Symbol.for("react.strict_mode"), Q = Symbol.for("react.profiler"), X = Symbol.for("react.consumer"), B = Symbol.for("react.context"), H = Symbol.for("react.forward_ref"), Z = Symbol.for("react.suspense"), K = Symbol.for("react.suspense_list"), D = Symbol.for("react.memo"), M = Symbol.for("react.lazy"), ee = Symbol.for("react.activity"), re = Symbol.for("react.client.reference"), C = a.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, F = Object.prototype.hasOwnProperty, te = Array.isArray, O = console.createTask ? console.createTask : function() {
|
|
@@ -248,28 +248,28 @@ React keys must be passed directly to JSX without using spread:
|
|
|
248
248
|
c
|
|
249
249
|
)(), $ = O(u(c)), q = {};
|
|
250
250
|
k.Fragment = f, k.jsx = function(e, n, l, d, w) {
|
|
251
|
-
var
|
|
252
|
-
return
|
|
251
|
+
var h = 1e4 > C.recentlyCreatedOwnerStacks++;
|
|
252
|
+
return E(
|
|
253
253
|
e,
|
|
254
254
|
n,
|
|
255
255
|
l,
|
|
256
256
|
!1,
|
|
257
257
|
d,
|
|
258
258
|
w,
|
|
259
|
-
|
|
260
|
-
|
|
259
|
+
h ? Error("react-stack-top-frame") : W,
|
|
260
|
+
h ? O(u(e)) : $
|
|
261
261
|
);
|
|
262
262
|
}, k.jsxs = function(e, n, l, d, w) {
|
|
263
|
-
var
|
|
264
|
-
return
|
|
263
|
+
var h = 1e4 > C.recentlyCreatedOwnerStacks++;
|
|
264
|
+
return E(
|
|
265
265
|
e,
|
|
266
266
|
n,
|
|
267
267
|
l,
|
|
268
268
|
!0,
|
|
269
269
|
d,
|
|
270
270
|
w,
|
|
271
|
-
|
|
272
|
-
|
|
271
|
+
h ? Error("react-stack-top-frame") : W,
|
|
272
|
+
h ? O(u(e)) : $
|
|
273
273
|
);
|
|
274
274
|
};
|
|
275
275
|
})()), k;
|
|
@@ -342,7 +342,8 @@ class le extends EventTarget {
|
|
|
342
342
|
*/
|
|
343
343
|
subscribeAll(r, t) {
|
|
344
344
|
const u = [
|
|
345
|
-
"form:
|
|
345
|
+
"form:show",
|
|
346
|
+
"form:started",
|
|
346
347
|
"form:submit",
|
|
347
348
|
"form:close",
|
|
348
349
|
"form:section:change",
|
|
@@ -386,7 +387,7 @@ class le extends EventTarget {
|
|
|
386
387
|
}));
|
|
387
388
|
}
|
|
388
389
|
}
|
|
389
|
-
const
|
|
390
|
+
const g = new le(), de = ({
|
|
390
391
|
formData: o,
|
|
391
392
|
cssLink: r,
|
|
392
393
|
scale: t = 100,
|
|
@@ -394,7 +395,7 @@ const v = new le(), de = ({
|
|
|
394
395
|
instanceId: s,
|
|
395
396
|
onFormEvent: c
|
|
396
397
|
}) => {
|
|
397
|
-
const [m, p] =
|
|
398
|
+
const [m, p] = U(!1), [R, T] = U(!0), E = I.useRef(null), v = I.useRef(
|
|
398
399
|
null
|
|
399
400
|
), a = oe({});
|
|
400
401
|
S(() => {
|
|
@@ -403,8 +404,8 @@ const v = new le(), de = ({
|
|
|
403
404
|
onSubmit: (f) => {
|
|
404
405
|
a.current.onSubmit = f;
|
|
405
406
|
},
|
|
406
|
-
|
|
407
|
-
a.current.
|
|
407
|
+
onShow: (f) => {
|
|
408
|
+
a.current.onShow = f;
|
|
408
409
|
},
|
|
409
410
|
onClose: (f) => {
|
|
410
411
|
a.current.onClose = f;
|
|
@@ -423,37 +424,37 @@ const v = new le(), de = ({
|
|
|
423
424
|
if (!s) return;
|
|
424
425
|
const i = [];
|
|
425
426
|
return a.current.onSubmit && i.push(
|
|
426
|
-
|
|
427
|
+
g.subscribe(
|
|
427
428
|
"form:submit",
|
|
428
429
|
a.current.onSubmit,
|
|
429
430
|
{ formId: s }
|
|
430
431
|
)
|
|
431
|
-
), a.current.
|
|
432
|
-
|
|
433
|
-
"form:
|
|
434
|
-
a.current.
|
|
432
|
+
), a.current.onShow && i.push(
|
|
433
|
+
g.subscribe(
|
|
434
|
+
"form:show",
|
|
435
|
+
a.current.onShow,
|
|
435
436
|
{ formId: s }
|
|
436
437
|
)
|
|
437
438
|
), a.current.onClose && i.push(
|
|
438
|
-
|
|
439
|
+
g.subscribe(
|
|
439
440
|
"form:close",
|
|
440
441
|
a.current.onClose,
|
|
441
442
|
{ formId: s }
|
|
442
443
|
)
|
|
443
444
|
), a.current.onSectionChange && i.push(
|
|
444
|
-
|
|
445
|
+
g.subscribe(
|
|
445
446
|
"form:section:change",
|
|
446
447
|
a.current.onSectionChange,
|
|
447
448
|
{ formId: s }
|
|
448
449
|
)
|
|
449
450
|
), a.current.onQuestionAnswered && i.push(
|
|
450
|
-
|
|
451
|
+
g.subscribe(
|
|
451
452
|
"form:question:answered",
|
|
452
453
|
a.current.onQuestionAnswered,
|
|
453
454
|
{ formId: s }
|
|
454
455
|
)
|
|
455
456
|
), a.current.onError && i.push(
|
|
456
|
-
|
|
457
|
+
g.subscribe(
|
|
457
458
|
"form:error",
|
|
458
459
|
a.current.onError,
|
|
459
460
|
{ formId: s }
|
|
@@ -476,23 +477,23 @@ const v = new le(), de = ({
|
|
|
476
477
|
o.onClose && o.onClose(), T(!1);
|
|
477
478
|
}, [o.onClose]);
|
|
478
479
|
return S(() => {
|
|
479
|
-
if (!m || !
|
|
480
|
+
if (!m || !E.current)
|
|
480
481
|
return;
|
|
481
482
|
const i = document.createElement("encatch-app");
|
|
482
|
-
return i.theme = o.theme, i.currentMode = o.currentMode, i.currentLanguage = o.currentLanguage, i.questions = o.questions, i.questionLanguages = o.questionLanguages, i.otherConfigurationProperties = o.otherConfigurationProperties, i.welcomeScreenProperties = o.welcomeScreenProperties, i.endScreenProperties = o.endScreenProperties, i.translations = o.translations, i.sections = o.sections, i.themeSettings = o.themeSettings, i.onClose = y, i.onSectionChange = o.onSectionChange, i.apiKey = o.apiKey, i.hostUrl = o.hostUrl, i.feedbackConfigId = o.feedbackConfigId, i.identifier = o.identifier, r && (i.cssLink = r), i.scale = t, i.persistMode = u, s && (i.instanceId = s),
|
|
483
|
-
|
|
483
|
+
return i.theme = o.theme, i.currentMode = o.currentMode, i.currentLanguage = o.currentLanguage, i.questions = o.questions, i.questionLanguages = o.questionLanguages, i.otherConfigurationProperties = o.otherConfigurationProperties, i.welcomeScreenProperties = o.welcomeScreenProperties, i.endScreenProperties = o.endScreenProperties, i.translations = o.translations, i.sections = o.sections, i.themeSettings = o.themeSettings, i.onClose = y, i.onSectionChange = o.onSectionChange, i.apiKey = o.apiKey, i.hostUrl = o.hostUrl, i.feedbackConfigId = o.feedbackConfigId, i.identifier = o.identifier, r && (i.cssLink = r), i.scale = t, i.persistMode = u, s && (i.instanceId = s), v.current = i, E.current.appendChild(i), () => {
|
|
484
|
+
E.current && v.current && E.current.removeChild(v.current), v.current = null;
|
|
484
485
|
};
|
|
485
|
-
}, [m, o, r, t, y, u, s]), R ? /* @__PURE__ */ ae.jsx("div", { ref:
|
|
486
|
+
}, [m, o, r, t, y, u, s]), R ? /* @__PURE__ */ ae.jsx("div", { ref: E }) : null;
|
|
486
487
|
};
|
|
487
488
|
function be(o, r, t) {
|
|
488
|
-
S(() =>
|
|
489
|
+
S(() => g.subscribe(
|
|
489
490
|
o,
|
|
490
491
|
r,
|
|
491
492
|
t
|
|
492
493
|
), [o, t?.formId, r]);
|
|
493
494
|
}
|
|
494
495
|
function me(o, r) {
|
|
495
|
-
S(() =>
|
|
496
|
+
S(() => g.subscribeAll(o, r), [r?.formId, o]);
|
|
496
497
|
}
|
|
497
498
|
export {
|
|
498
499
|
de as EncatchPreview,
|
package/dist/index.umd.js
CHANGED
|
@@ -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 M;function z(){if(M)return y;M=1;var o=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function
|
|
9
|
+
*/var M;function z(){if(M)return y;M=1;var o=Symbol.for("react.transitional.element"),r=Symbol.for("react.fragment");function t(u,s,c){var E=null;if(c!==void 0&&(E=""+c),s.key!==void 0&&(E=""+s.key),"key"in s){c={};for(var h in s)h!=="key"&&(c[h]=s[h])}else c=s;return s=c.ref,{$$typeof:o,type:u,key:E,ref:s!==void 0?s:null,props:c}}return y.Fragment=r,y.jsx=t,y.jsxs=t,y}var P={};/**
|
|
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 F;function G(){return F||(F=1,process.env.NODE_ENV!=="production"&&(function(){function o(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 ee:return"Profiler";case D:return"StrictMode";case oe:return"Suspense";case se:return"SuspenseList";case ue: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 i:return"Portal";case
|
|
17
|
+
*/var F;function G(){return F||(F=1,process.env.NODE_ENV!=="production"&&(function(){function o(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 ee:return"Profiler";case D:return"StrictMode";case oe:return"Suspense";case se:return"SuspenseList";case ue: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 i:return"Portal";case te:return(e.displayName||"Context")+".Provider";case re:return(e._context.displayName||"Context")+".Consumer";case ne:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case ie:return n=e.displayName||null,n!==null?n:o(e.type)||"Memo";case L:n=e._payload,e=e._init;try{return o(e(n))}catch{}}return null}function r(e){return""+e}function t(e){try{r(e);var n=!1}catch{n=!0}if(n){n=console;var l=n.error,b=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return l.call(n,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",b),r(e)}}function u(e){if(e===f)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===L)return"<...>";try{var n=o(e);return n?"<"+n+">":"<...>"}catch{return"<...>"}}function s(){var e=O.A;return e===null?null:e.getOwner()}function c(){return Error("react-stack-top-frame")}function E(e){if(W.call(e,"key")){var n=Object.getOwnPropertyDescriptor(e,"key").get;if(n&&n.isReactWarning)return!1}return e.key!==void 0}function h(e,n){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)",n))}l.isReactWarning=!0,Object.defineProperty(e,"key",{get:l,configurable:!0})}function R(){var e=o(this.type);return $[e]||($[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 A(e,n,l,b,S,p,x,N){return l=p.ref,e={$$typeof:k,type:e,key:n,props:p,_owner:S},(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:x}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:N}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function g(e,n,l,b,S,p,x,N){var m=n.children;if(m!==void 0)if(b)if(ae(m)){for(b=0;b<m.length;b++)_(m[b]);Object.freeze&&Object.freeze(m)}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);if(W.call(n,"key")){m=o(e);var T=Object.keys(n).filter(function(le){return le!=="key"});b=0<T.length?"{key: someKey, "+T.join(": ..., ")+": ...}":"{key: someKey}",V[m+b]||(T=0<T.length?"{"+T.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
18
18
|
let props = %s;
|
|
19
19
|
<%s {...props} />
|
|
20
20
|
React keys must be passed directly to JSX without using spread:
|
|
21
21
|
let props = %s;
|
|
22
|
-
<%s key={someKey} {...props} />`,b,m,T,m),
|
|
22
|
+
<%s key={someKey} {...props} />`,b,m,T,m),V[m+b]=!0)}if(m=null,l!==void 0&&(t(l),m=""+l),E(n)&&(t(n.key),m=""+n.key),"key"in n){l={};for(var I in n)I!=="key"&&(l[I]=n[I])}else l=n;return m&&h(l,typeof e=="function"?e.displayName||e.name||"Unknown":e),A(e,m,p,S,s(),l,x,N)}function _(e){typeof e=="object"&&e!==null&&e.$$typeof===k&&e._store&&(e._store.validated=1)}var a=d,k=Symbol.for("react.transitional.element"),i=Symbol.for("react.portal"),f=Symbol.for("react.fragment"),D=Symbol.for("react.strict_mode"),ee=Symbol.for("react.profiler"),re=Symbol.for("react.consumer"),te=Symbol.for("react.context"),ne=Symbol.for("react.forward_ref"),oe=Symbol.for("react.suspense"),se=Symbol.for("react.suspense_list"),ie=Symbol.for("react.memo"),L=Symbol.for("react.lazy"),ue=Symbol.for("react.activity"),ce=Symbol.for("react.client.reference"),O=a.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,W=Object.prototype.hasOwnProperty,ae=Array.isArray,j=console.createTask?console.createTask:function(){return null};a={react_stack_bottom_frame:function(e){return e()}};var q,$={},U=a.react_stack_bottom_frame.bind(a,c)(),J=j(u(c)),V={};P.Fragment=f,P.jsx=function(e,n,l,b,S){var p=1e4>O.recentlyCreatedOwnerStacks++;return g(e,n,l,!1,b,S,p?Error("react-stack-top-frame"):U,p?j(u(e)):J)},P.jsxs=function(e,n,l,b,S){var p=1e4>O.recentlyCreatedOwnerStacks++;return g(e,n,l,!0,b,S,p?Error("react-stack-top-frame"):U,p?j(u(e)):J)}})()),P}var Y;function Q(){return Y||(Y=1,process.env.NODE_ENV==="production"?C.exports=z():C.exports=G()),C.exports}var X=Q();class B 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,u){typeof window<"u"&&window.dispatchEvent(new CustomEvent(r,{detail:t,bubbles:!0})),u?.usePostMessage!==!1&&this.sendPostMessage(r,t)}subscribe(r,t,u){const s=Symbol("subscription"),c={eventType:r,handler:t,filter:u?.formId,id:s,once:u?.once};this.subscriptions.has(r)||this.subscriptions.set(r,[]),this.subscriptions.get(r).push(c);const E=h=>{const R=h,A=this.getFormIdFromPayload(R.detail);this.matchesFilter(A,u?.formId)&&(t(R.detail),u?.once&&typeof window<"u"&&window.removeEventListener(r,E))};return typeof window<"u"&&window.addEventListener(r,E),()=>{this.unsubscribe(s),typeof window<"u"&&window.removeEventListener(r,E)}}unsubscribe(r){for(const[t,u]of this.subscriptions.entries()){const s=u.findIndex(c=>c.id===r);if(s!==-1){u.splice(s,1),u.length===0&&this.subscriptions.delete(t);break}}}subscribeAll(r,t){const u=["form:show","form:started","form:submit","form:close","form:section:change","form:question:answered","form:error"],s=[];return u.forEach(c=>{const E=this.subscribe(c,h=>r(c,h),t);s.push(E)}),()=>{s.forEach(c=>c())}}getSubscriptionCount(r){return r?this.subscriptions.get(r)?.length||0:Array.from(this.subscriptions.values()).reduce((t,u)=>t+u.length,0)}clearSubscriptions(r){r?this.subscriptions.delete(r):this.subscriptions.clear()}sendPostMessage(r,t){const u={type:`encatch:${r}`,payload:t,source:"encatch-form-engine"};window.parent&&window.parent!==window&&window.parent.postMessage(u,this.targetOrigin),document.querySelectorAll("iframe").forEach(s=>{s.contentWindow&&s.contentWindow.postMessage(u,this.targetOrigin)}),typeof window.ReactNativeWebView<"u"&&window.ReactNativeWebView.postMessage(JSON.stringify({action:r.replace("form:",""),data:JSON.stringify(t)}))}}const v=new B,H=({formData:o,cssLink:r,scale:t=100,persistMode:u="none",instanceId:s,onFormEvent:c})=>{const[E,h]=d.useState(!1),[R,A]=d.useState(!0),g=d.useRef(null),_=d.useRef(null),a=d.useRef({});d.useEffect(()=>{if(!c)return;c({onSubmit:f=>{a.current.onSubmit=f},onShow:f=>{a.current.onShow=f},onClose:f=>{a.current.onClose=f},onSectionChange:f=>{a.current.onSectionChange=f},onQuestionAnswered:f=>{a.current.onQuestionAnswered=f},onError:f=>{a.current.onError=f}})},[c]),d.useEffect(()=>{if(!s)return;const i=[];return a.current.onSubmit&&i.push(v.subscribe("form:submit",a.current.onSubmit,{formId:s})),a.current.onShow&&i.push(v.subscribe("form:show",a.current.onShow,{formId:s})),a.current.onClose&&i.push(v.subscribe("form:close",a.current.onClose,{formId:s})),a.current.onSectionChange&&i.push(v.subscribe("form:section:change",a.current.onSectionChange,{formId:s})),a.current.onQuestionAnswered&&i.push(v.subscribe("form:question:answered",a.current.onQuestionAnswered,{formId:s})),a.current.onError&&i.push(v.subscribe("form:error",a.current.onError,{formId:s})),()=>{i.forEach(f=>f())}},[s]),d.useEffect(()=>{(()=>{try{return o?!0:(console.warn("[EncatchPreview] formData is not defined"),!1)}catch(f){return console.error("[EncatchPreview] Error during data validation:",f),!1}})()?h(!0):console.warn("[EncatchPreview] Data validation failed, retrying in 100ms...")},[o]);const k=d.useCallback(()=>{o.onClose&&o.onClose(),A(!1)},[o.onClose]);return d.useEffect(()=>{if(!E||!g.current)return;const i=document.createElement("encatch-app");return i.theme=o.theme,i.currentMode=o.currentMode,i.currentLanguage=o.currentLanguage,i.questions=o.questions,i.questionLanguages=o.questionLanguages,i.otherConfigurationProperties=o.otherConfigurationProperties,i.welcomeScreenProperties=o.welcomeScreenProperties,i.endScreenProperties=o.endScreenProperties,i.translations=o.translations,i.sections=o.sections,i.themeSettings=o.themeSettings,i.onClose=k,i.onSectionChange=o.onSectionChange,i.apiKey=o.apiKey,i.hostUrl=o.hostUrl,i.feedbackConfigId=o.feedbackConfigId,i.identifier=o.identifier,r&&(i.cssLink=r),i.scale=t,i.persistMode=u,s&&(i.instanceId=s),_.current=i,g.current.appendChild(i),()=>{g.current&&_.current&&g.current.removeChild(_.current),_.current=null}},[E,o,r,t,k,u,s]),R?X.jsx("div",{ref:g}):null};function Z(o,r,t){d.useEffect(()=>v.subscribe(o,r,t),[o,t?.formId,r])}function K(o,r){d.useEffect(()=>v.subscribeAll(o,r),[r?.formId,o])}w.EncatchPreview=H,w.useEncatchFormEvent=Z,w.useEncatchFormEventAll=K,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/types.d.ts
CHANGED
|
@@ -4,9 +4,9 @@ import type { FormEventPayload } from '@encatch/event-publisher';
|
|
|
4
4
|
*/
|
|
5
5
|
export type OnSubmitCallback = (payload: FormEventPayload['form:submit']) => void;
|
|
6
6
|
/**
|
|
7
|
-
* Callback function for form
|
|
7
|
+
* Callback function for form show events
|
|
8
8
|
*/
|
|
9
|
-
export type
|
|
9
|
+
export type OnShowCallback = (payload: FormEventPayload['form:show']) => void;
|
|
10
10
|
/**
|
|
11
11
|
* Callback function for form close events
|
|
12
12
|
*/
|
|
@@ -56,10 +56,10 @@ export interface FormEventBuilder {
|
|
|
56
56
|
*/
|
|
57
57
|
onSubmit: (callback: OnSubmitCallback) => void;
|
|
58
58
|
/**
|
|
59
|
-
* Register a callback for when form is
|
|
60
|
-
* @param callback - Function to call when form is
|
|
59
|
+
* Register a callback for when form is shown/displayed
|
|
60
|
+
* @param callback - Function to call when form is shown
|
|
61
61
|
*/
|
|
62
|
-
|
|
62
|
+
onShow: (callback: OnShowCallback) => void;
|
|
63
63
|
/**
|
|
64
64
|
* Register a callback for when form is closed
|
|
65
65
|
* @param callback - Function to call when form is closed
|
|
@@ -15,8 +15,8 @@ import { type FormEventType, type FormEventPayload, type SubscriptionOptions } f
|
|
|
15
15
|
* }, { formId: 'my-form-instance-1' });
|
|
16
16
|
*
|
|
17
17
|
* // Subscribe once
|
|
18
|
-
* useEncatchFormEvent('form:
|
|
19
|
-
* console.log('Form
|
|
18
|
+
* useEncatchFormEvent('form:show', (payload) => {
|
|
19
|
+
* console.log('Form shown:', payload);
|
|
20
20
|
* }, { formId: 'my-form-instance-1', once: true });
|
|
21
21
|
* ```
|
|
22
22
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@encatch/ws-react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.50-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/schema": "0.
|
|
24
|
-
"@encatch/event-publisher": "0.0.
|
|
23
|
+
"@encatch/schema": "1.0.0-beta.0",
|
|
24
|
+
"@encatch/event-publisher": "1.0.0-beta.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@eslint/js": "^9.36.0",
|