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