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