@encatch/ws-react 0.0.15 → 0.0.17
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 +14 -66
- package/dist/EncatchPreview.d.ts +23 -0
- package/dist/index.d.ts +3 -0
- package/dist/types.d.ts +87 -0
- package/dist/useEncatchFormEvent.d.ts +50 -0
- package/dist/{web-form-engine-core.umd-B1xHitkx.js → web-form-engine-core.umd-C-N-KDM0.js} +6493 -6427
- package/dist/ws-react.es.js +363 -159
- package/dist/ws-react.umd.js +22 -22
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -1,73 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @encatch/ws-react
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
React wrapper for Encatch web form engine. This package provides a React component to easily integrate Encatch forms into your React applications.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
### Purpose
|
|
6
|
+
Helpful when you want to manually open feedback (static forms) in your react application.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
|
8
|
+
## Resources
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
- **Website**: [https://encatch.com](https://encatch.com)
|
|
11
|
+
- **Documentation**: [https://encatch.com/docs](https://encatch.com/docs)
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
## Installation
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
globalIgnores(['dist']),
|
|
21
|
-
{
|
|
22
|
-
files: ['**/*.{ts,tsx}'],
|
|
23
|
-
extends: [
|
|
24
|
-
// Other configs...
|
|
25
|
-
|
|
26
|
-
// Remove tseslint.configs.recommended and replace with this
|
|
27
|
-
tseslint.configs.recommendedTypeChecked,
|
|
28
|
-
// Alternatively, use this for stricter rules
|
|
29
|
-
tseslint.configs.strictTypeChecked,
|
|
30
|
-
// Optionally, add this for stylistic rules
|
|
31
|
-
tseslint.configs.stylisticTypeChecked,
|
|
32
|
-
|
|
33
|
-
// Other configs...
|
|
34
|
-
],
|
|
35
|
-
languageOptions: {
|
|
36
|
-
parserOptions: {
|
|
37
|
-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
38
|
-
tsconfigRootDir: import.meta.dirname,
|
|
39
|
-
},
|
|
40
|
-
// other options...
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
])
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
|
47
|
-
|
|
48
|
-
```js
|
|
49
|
-
// eslint.config.js
|
|
50
|
-
import reactX from 'eslint-plugin-react-x'
|
|
51
|
-
import reactDom from 'eslint-plugin-react-dom'
|
|
52
|
-
|
|
53
|
-
export default defineConfig([
|
|
54
|
-
globalIgnores(['dist']),
|
|
55
|
-
{
|
|
56
|
-
files: ['**/*.{ts,tsx}'],
|
|
57
|
-
extends: [
|
|
58
|
-
// Other configs...
|
|
59
|
-
// Enable lint rules for React
|
|
60
|
-
reactX.configs['recommended-typescript'],
|
|
61
|
-
// Enable lint rules for React DOM
|
|
62
|
-
reactDom.configs.recommended,
|
|
63
|
-
],
|
|
64
|
-
languageOptions: {
|
|
65
|
-
parserOptions: {
|
|
66
|
-
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
67
|
-
tsconfigRootDir: import.meta.dirname,
|
|
68
|
-
},
|
|
69
|
-
// other options...
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
])
|
|
15
|
+
```bash
|
|
16
|
+
npm install @encatch/ws-react
|
|
17
|
+
# or
|
|
18
|
+
pnpm add @encatch/ws-react
|
|
19
|
+
# or
|
|
20
|
+
yarn add @encatch/ws-react
|
|
73
21
|
```
|
package/dist/EncatchPreview.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AppProps, Section } from "@encatch/schema";
|
|
2
2
|
import React from "react";
|
|
3
|
+
import type { OnFormEventHandler } from "./types";
|
|
3
4
|
declare module "react" {
|
|
4
5
|
namespace JSX {
|
|
5
6
|
interface IntrinsicElements {
|
|
@@ -24,6 +25,7 @@ declare module "react" {
|
|
|
24
25
|
cssLink?: string;
|
|
25
26
|
scale?: number;
|
|
26
27
|
persistMode?: "retain" | "reset" | "none";
|
|
28
|
+
instanceId?: string;
|
|
27
29
|
};
|
|
28
30
|
}
|
|
29
31
|
}
|
|
@@ -51,6 +53,27 @@ interface EncatchPreviewProps {
|
|
|
51
53
|
cssLink: string;
|
|
52
54
|
scale?: number;
|
|
53
55
|
persistMode?: "retain" | "reset" | "none";
|
|
56
|
+
instanceId?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Callback function that receives a FormEventBuilder to register event handlers
|
|
59
|
+
* Events are automatically filtered to only this form instance
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```tsx
|
|
63
|
+
* const handleFormEvents = (formEvent) => {
|
|
64
|
+
* formEvent.onSubmit((data) => {
|
|
65
|
+
* console.log('Form submitted:', data);
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* formEvent.onQuestionAnswered((data) => {
|
|
69
|
+
* console.log('Question answered:', data.questionId, data.answer);
|
|
70
|
+
* });
|
|
71
|
+
* };
|
|
72
|
+
*
|
|
73
|
+
* <EncatchPreview onFormEvent={handleFormEvents} {...props} />
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
onFormEvent?: OnFormEventHandler;
|
|
54
77
|
}
|
|
55
78
|
export declare const EncatchPreview: React.FC<EncatchPreviewProps>;
|
|
56
79
|
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
1
|
export { EncatchPreview } from "./EncatchPreview";
|
|
2
|
+
export { useEncatchFormEvent, useEncatchFormEventAll } from "./useEncatchFormEvent";
|
|
3
|
+
export type { FormEventType, FormEventPayload, SubscriptionOptions, FormIdFilter, } from "./useEncatchFormEvent";
|
|
4
|
+
export type { FormEventBuilder, OnFormEventHandler, OnSubmitCallback, OnViewCallback, OnCloseCallback, OnSectionChangeCallback, OnQuestionAnsweredCallback, OnErrorCallback, } from "./types";
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { FormEventPayload } from '@encatch/event-publisher';
|
|
2
|
+
/**
|
|
3
|
+
* Callback function for form submit events
|
|
4
|
+
*/
|
|
5
|
+
export type OnSubmitCallback = (payload: FormEventPayload['form:submit']) => void;
|
|
6
|
+
/**
|
|
7
|
+
* Callback function for form view events
|
|
8
|
+
*/
|
|
9
|
+
export type OnViewCallback = (payload: FormEventPayload['form:view']) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Callback function for form close events
|
|
12
|
+
*/
|
|
13
|
+
export type OnCloseCallback = (payload: FormEventPayload['form:close']) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Callback function for section change events
|
|
16
|
+
*/
|
|
17
|
+
export type OnSectionChangeCallback = (payload: FormEventPayload['form:section:change']) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Callback function for question answered events
|
|
20
|
+
*/
|
|
21
|
+
export type OnQuestionAnsweredCallback = (payload: FormEventPayload['form:question:answered']) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Callback function for form error events
|
|
24
|
+
*/
|
|
25
|
+
export type OnErrorCallback = (payload: FormEventPayload['form:error']) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Form Event Builder - provides methods to register callbacks for different form events
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* const handleFormEvents = (formEvent) => {
|
|
32
|
+
* formEvent.onSubmit((data) => {
|
|
33
|
+
* console.log('Form submitted:', data);
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* formEvent.onQuestionAnswered((data) => {
|
|
37
|
+
* console.log('Question answered:', data.questionId, data.answer);
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* formEvent.onSectionChange((data) => {
|
|
41
|
+
* console.log('Section changed to:', data.sectionIndex);
|
|
42
|
+
* });
|
|
43
|
+
* };
|
|
44
|
+
*
|
|
45
|
+
* <EncatchPreview
|
|
46
|
+
* instanceId="form-1"
|
|
47
|
+
* onFormEvent={handleFormEvents}
|
|
48
|
+
* {...otherProps}
|
|
49
|
+
* />
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export interface FormEventBuilder {
|
|
53
|
+
/**
|
|
54
|
+
* Register a callback for form submission
|
|
55
|
+
* @param callback - Function to call when form is submitted
|
|
56
|
+
*/
|
|
57
|
+
onSubmit: (callback: OnSubmitCallback) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Register a callback for when form is viewed/opened
|
|
60
|
+
* @param callback - Function to call when form is viewed
|
|
61
|
+
*/
|
|
62
|
+
onView: (callback: OnViewCallback) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Register a callback for when form is closed
|
|
65
|
+
* @param callback - Function to call when form is closed
|
|
66
|
+
*/
|
|
67
|
+
onClose: (callback: OnCloseCallback) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Register a callback for section changes
|
|
70
|
+
* @param callback - Function to call when user navigates between sections
|
|
71
|
+
*/
|
|
72
|
+
onSectionChange: (callback: OnSectionChangeCallback) => void;
|
|
73
|
+
/**
|
|
74
|
+
* Register a callback for when questions are answered
|
|
75
|
+
* @param callback - Function to call when a question is answered
|
|
76
|
+
*/
|
|
77
|
+
onQuestionAnswered: (callback: OnQuestionAnsweredCallback) => void;
|
|
78
|
+
/**
|
|
79
|
+
* Register a callback for form errors
|
|
80
|
+
* @param callback - Function to call when an error occurs
|
|
81
|
+
*/
|
|
82
|
+
onError: (callback: OnErrorCallback) => void;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Function type for the onFormEvent prop
|
|
86
|
+
*/
|
|
87
|
+
export type OnFormEventHandler = (formEvent: FormEventBuilder) => void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type FormEventType, type FormEventPayload, type SubscriptionOptions } from '@encatch/event-publisher';
|
|
2
|
+
/**
|
|
3
|
+
* React hook for subscribing to form events from the event publisher.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```tsx
|
|
7
|
+
* // Subscribe to all form submit events
|
|
8
|
+
* useEncatchFormEvent('form:submit', (payload) => {
|
|
9
|
+
* console.log('Form submitted:', payload);
|
|
10
|
+
* });
|
|
11
|
+
*
|
|
12
|
+
* // Subscribe to events from a specific form instance
|
|
13
|
+
* useEncatchFormEvent('form:submit', (payload) => {
|
|
14
|
+
* console.log('Specific form submitted:', payload);
|
|
15
|
+
* }, { formId: 'my-form-instance-1' });
|
|
16
|
+
*
|
|
17
|
+
* // Subscribe once
|
|
18
|
+
* useEncatchFormEvent('form:view', (payload) => {
|
|
19
|
+
* console.log('Form viewed:', payload);
|
|
20
|
+
* }, { formId: 'my-form-instance-1', once: true });
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @param eventType - The type of event to subscribe to
|
|
24
|
+
* @param handler - Callback function to handle the event
|
|
25
|
+
* @param options - Subscription options (formId filter, once flag)
|
|
26
|
+
* @returns void - Cleanup is handled automatically on unmount
|
|
27
|
+
*/
|
|
28
|
+
export declare function useEncatchFormEvent<T extends FormEventType>(eventType: T, handler: (payload: FormEventPayload[T]) => void, options?: SubscriptionOptions): void;
|
|
29
|
+
/**
|
|
30
|
+
* React hook for subscribing to all form events.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* // Subscribe to all events from all forms
|
|
35
|
+
* useEncatchFormEventAll((eventType, payload) => {
|
|
36
|
+
* console.log(`Event ${eventType}:`, payload);
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* // Subscribe to all events from a specific form instance
|
|
40
|
+
* useEncatchFormEventAll((eventType, payload) => {
|
|
41
|
+
* console.log(`Event ${eventType} from form:`, payload);
|
|
42
|
+
* }, { formId: 'my-form-instance-1' });
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @param handler - Callback function to handle all events
|
|
46
|
+
* @param options - Subscription options (formId filter, once flag)
|
|
47
|
+
* @returns void - Cleanup is handled automatically on unmount
|
|
48
|
+
*/
|
|
49
|
+
export declare function useEncatchFormEventAll(handler: (eventType: FormEventType, payload: any) => void, options?: SubscriptionOptions): void;
|
|
50
|
+
export type { FormEventType, FormEventPayload, SubscriptionOptions, FormIdFilter } from '@encatch/event-publisher';
|