@tsed/react-formio 1.10.11 → 1.10.14

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/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@tsed/react-formio",
3
- "version": "1.10.11",
3
+ "version": "1.10.14",
4
+ "description": "Provide a react formio wrapper. Written in TypeScript.",
4
5
  "main": "dist/index.js",
5
6
  "module": "dist/index.modern.js",
6
7
  "source": "src/index.ts",
@@ -13,23 +14,23 @@
13
14
  "prettier": "prettier '{src,test}/**/*.{ts,tsx}' --write"
14
15
  },
15
16
  "dependencies": {
16
- "@tsed/redux-utils": "1.10.11",
17
+ "@tsed/redux-utils": "1.10.14",
17
18
  "eventemitter2": "^6.4.3",
18
19
  "prop-types": "^15.7.2"
19
20
  },
20
21
  "peerDependencies": {
21
- "choices.js": "^9.0.1",
22
- "formiojs": "^4.12.7",
23
- "lodash": "4.17.20",
24
- "prop-types": "^15.7.2",
25
- "react": "^16.14.0",
26
- "react-is": "^17.0.1",
27
- "react-table": "^7.6.3",
28
- "tooltip.js": "^1.3.3"
22
+ "choices.js": ">=9.0.1",
23
+ "formiojs": ">=4.0.0",
24
+ "lodash": ">=4.17.20",
25
+ "prop-types": ">=15.7.2",
26
+ "react": ">=16.14.0",
27
+ "react-dom": ">=16.14.0",
28
+ "react-table": ">=7.6.3",
29
+ "tooltip.js": ">=1.3.3"
29
30
  },
30
31
  "devDependencies": {
31
- "@tsed/tailwind": "1.10.11",
32
- "@tsed/tailwind-formio": "1.10.11",
32
+ "@tsed/tailwind": "1.10.14",
33
+ "@tsed/tailwind-formio": "1.10.14",
33
34
  "eslint-plugin-jsx-a11y": "^6.5.1"
34
35
  },
35
36
  "repository": "https://github.com/TypedProject/tsed-formio",
package/readme.md CHANGED
@@ -64,7 +64,7 @@ npm install formiojs choices.js --save // Install formiojs since it is a peerDep
64
64
 
65
65
  ## Usage
66
66
 
67
- ```typescript
67
+ ```tsx
68
68
  import React from "react";
69
69
  import {FormBuilder} from "@tsed/react-formio";
70
70
 
@@ -88,47 +88,78 @@ The form component is the primary component of the system. It is what takes the
88
88
 
89
89
  #### Props
90
90
 
91
- | Name | Type | Default | Description |
92
- |---|---|---|---|
93
- | `src` | url | | The url of the form definition. This is commonly from a form.io server. When using src, the form will automatically submit the data to that url as well. |
94
- | `url` | url | | The url of the form definition. The form will not be loaded from this url and the submission will not be saved here either. This is used for file upload, oauth and other components or actions that need to know where the server is. Use this in connection with `form` |
95
- | `form` | object | | Instead of loading a form from the `src` url, you can preload the form definition and pass it in with the `form` prop. You should also set `url` if you are using any advanced components like file upload or oauth. |
96
- | `submission` | object | | Submission data to fill the form. You can either load a previous submission or create a submission with some pre-filled data. If you do not provide a submissions the form will initialize an empty submission using default values from the form. |
97
- | `options` | object | | an options object that can pass options to the formio.js Form that is rendered. You can set options such as `readOnly`, `noAlerts` or `hide`. There are [many options to be found in the formio.js library](https://github.com/formio/formio.js/wiki/Form-Renderer#options). |
91
+ | Name | Type | Default | Description |
92
+ |--------------|--------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
93
+ | `src` | url | | The url of the form definition. This is commonly from a form.io server. When using src, the form will automatically submit the data to that url as well. |
94
+ | `url` | url | | The url of the form definition. The form will not be loaded from this url and the submission will not be saved here either. This is used for file upload, oauth and other components or actions that need to know where the server is. Use this in connection with `form` |
95
+ | `form` | object | | Instead of loading a form from the `src` url, you can preload the form definition and pass it in with the `form` prop. You should also set `url` if you are using any advanced components like file upload or oauth. |
96
+ | `submission` | object | | Submission data to fill the form. You can either load a previous submission or create a submission with some pre-filled data. If you do not provide a submissions the form will initialize an empty submission using default values from the form. |
97
+ | `options` | object | | an options object that can pass options to the formio.js Form that is rendered. You can set options such as `readOnly`, `noAlerts` or `hide`. There are [many options to be found in the formio.js library](https://github.com/formio/formio.js/wiki/Form-Renderer#options). |
98
98
 
99
99
  #### Event Props
100
100
 
101
101
  You can respond to various events in the form. Simply pass in a prop with a function for one of these events.
102
102
 
103
- | Name | Parameters | Description |
104
- |---|---|---|
105
- | `onSubmit` | `submission`: object | When the submit button is pressed and the submission has started. If `src` is not provided, this will be the final submit event.|
106
- | `onSubmitDone` | `submission`: object | When the submission has successfully been made to the server. This will only fire if `src` is set. |
107
- | `onChange` | `submission`: object, `submission.changed`: object of what changed, `submission.isValid`: boolean - if the submission passes validations. | A value in the submission has changed. |
108
- | `onError` | `errors`: array or string or boolean | Called when an error occurs during submission such as a validation issue. |
109
- | `onRender` | | Triggers when the form is finished rendering. |
110
- | `onCustomEvent` | { `type`: string - event type, `component`: object - triggering component, `data`: object - data for component, `event`: string - raw event } | Event that is triggered from a button configured with "Event" type. |
111
- | `onPrevPage` | { `page`: integer - new page number, `submission`: object - submission data } | Triggered for wizards when "Previous" button is pressed |
112
- | `onNextPage` | { `page`: integer - new page number, `submission`: object - submission data } | Triggered for wizards when "Next" button is pressed |
113
- | `onFormReady` | `formInstance`: Webform/Wizard - form class instance | Called when the form gets ready state |
103
+ | Name | Parameters | Description |
104
+ |-----------------|-----------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|
105
+ | `onSubmit` | `submission`: object | When the submit button is pressed and the submission has started. If `src` is not provided, this will be the final submit event. |
106
+ | `onSubmitDone` | `submission`: object | When the submission has successfully been made to the server. This will only fire if `src` is set. |
107
+ | `onChange` | `submission`: object, `submission.changed`: object of what changed, `submission.isValid`: boolean - if the submission passes validations. | A value in the submission has changed. |
108
+ | `onError` | `errors`: array or string or boolean | Called when an error occurs during submission such as a validation issue. |
109
+ | `onRender` | | Triggers when the form is finished rendering. |
110
+ | `onCustomEvent` | { `type`: string - event type, `component`: object - triggering component, `data`: object - data for component, `event`: string - raw event } | Event that is triggered from a button configured with "Event" type. |
111
+ | `onPrevPage` | { `page`: integer - new page number, `submission`: object - submission data } | Triggered for wizards when "Previous" button is pressed |
112
+ | `onNextPage` | { `page`: integer - new page number, `submission`: object - submission data } | Triggered for wizards when "Next" button is pressed |
113
+ | `onFormReady` | `formInstance`: Webform/Wizard - form class instance | Called when the form gets ready state |
114
114
 
115
115
  #### Example
116
116
 
117
+ ##### With src/url
118
+
117
119
  Give `Form` a `src` property and render:
118
120
 
119
- ```javascript
121
+ ```tsx
120
122
  import React from 'react';
121
123
  import ReactDOM from 'react-dom';
122
124
  import {Form} from '@tsed/react-formio';
123
- ```
124
125
 
125
- ```javascript
126
126
  ReactDOM.render(
127
127
  <Form src="https://example.form.io/example" onSubmit={console.log} />
128
128
  , document.getElementById('example')
129
129
  );
130
130
  ```
131
131
 
132
+ ##### With form
133
+
134
+ Give `Form` a `src` property and render:
135
+
136
+ ```tsx
137
+ import React from 'react';
138
+ import ReactDOM from 'react-dom';
139
+ import {Form} from '@tsed/react-formio';
140
+
141
+ interface MyFormData {
142
+ title: string;
143
+ }
144
+
145
+ const form = {
146
+ display: 'form',
147
+ components: [
148
+ {
149
+ key: 'title',
150
+ type: 'textfield'
151
+ }
152
+ ]
153
+ }
154
+
155
+ ReactDOM.render(
156
+ <Form<MyFormData> form={form} onSubmit={(submission) => {
157
+ console.log(submission)
158
+ }} />
159
+ , document.getElementById('example')
160
+ );
161
+ ```
162
+
132
163
  ### FormBuilder
133
164
 
134
165
  The [FormBuilder]([FormsTable](https://formio.tsed.io/?path=/story/reactformio-formbuilder--sandbox)) class can be used
@@ -141,31 +172,29 @@ the [FormEdit](https://formio.tsed.io/?path=/story/reactformio-formedit--sandbox
141
172
 
142
173
  #### Props
143
174
 
144
- | Name | Type | Default | Description |
145
- |---|---|---|---|
146
- | `form` | object | | This is the form definition object. It should at least have a `display` property set to form, wizard or pdf. |
147
- | `options` | object | | an options object that can pass options to the formio.js Form that is rendered. There are many options to be found in the formio.js library. |
175
+ | Name | Type | Default | Description |
176
+ |-----------|--------|---------|----------------------------------------------------------------------------------------------------------------------------------------------|
177
+ | `form` | object | | This is the form definition object. It should at least have a `display` property set to form, wizard or pdf. |
178
+ | `options` | object | | an options object that can pass options to the formio.js Form that is rendered. There are many options to be found in the formio.js library. |
148
179
 
149
180
  #### Event Props
150
181
 
151
- | Name | Parameters | Description |
152
- |---|---|---|
153
- | `onChange` | `schema`: object | Triggered any time the form definition changes |
154
- | `onEditComponent` | `component`: object | Triggered when the component settings dialog is opened |
155
- | `onSaveComponent` | `component`: object | Triggered when the component settings dialog is saved and closed |
156
- | `onCancelComponent` | `component`: object | Triggered when the component settings dialog is cancelled |
157
- | `onDeleteComponent` | `component`: object | Triggered when a component is removed from the form |
158
- | `onUpdateComponent` | `component`: object | Triggered when a component is added or moved in the form |
182
+ | Name | Parameters | Description |
183
+ |---------------------|---------------------|------------------------------------------------------------------|
184
+ | `onChange` | `schema`: object | Triggered any time the form definition changes |
185
+ | `onEditComponent` | `component`: object | Triggered when the component settings dialog is opened |
186
+ | `onSaveComponent` | `component`: object | Triggered when the component settings dialog is saved and closed |
187
+ | `onCancelComponent` | `component`: object | Triggered when the component settings dialog is cancelled |
188
+ | `onDeleteComponent` | `component`: object | Triggered when a component is removed from the form |
189
+ | `onUpdateComponent` | `component`: object | Triggered when a component is added or moved in the form |
159
190
 
160
191
  #### Example
161
192
 
162
- ```javascript
193
+ ```tsx
163
194
  import React from 'react';
164
195
  import ReactDOM from 'react-dom';
165
196
  import {FormBuilder} from '@tsed/react-formio';
166
- ```
167
197
 
168
- ```javascript
169
198
  ReactDOM.render(
170
199
  <FormBuilder form={{display: 'form'}} onChange={(schema) => console.log(schema)} />
171
200
  , document.getElementById('builder')
@@ -179,17 +208,17 @@ the [FormBuilder]([FormsTable](https://formio.tsed.io/?path=/story/reactformio-f
179
208
 
180
209
  #### Props
181
210
 
182
- | Name | Type | Default | Description |
183
- |---|---|---|---|
184
- | `form` | object | {display: 'form' \| 'wizard'} | The form definition of the exiting form that is to be modified. |
185
- | `options` | object | {} | The options to be passed to FormBuilder |
186
- | `saveText` | string | '' | The string that will be displayed in the save-button |
211
+ | Name | Type | Default | Description |
212
+ |------------|--------|--------------------|------------------------------------------------------|
213
+ | `form` | object | {display: 'form' \ | 'wizard'} | The form definition of the exiting form that is to be modified. |
214
+ | `options` | object | {} | The options to be passed to FormBuilder |
215
+ | `saveText` | string | '' | The string that will be displayed in the save-button |
187
216
 
188
217
  #### Event Props
189
218
 
190
- | Name | Parameters | Description |
191
- |---|---|---|
192
- | `onSubmit` | form | Called when the save button is pressed. Will pass the form definition to the callback. |
219
+ | Name | Parameters | Description |
220
+ |------------|------------|----------------------------------------------------------------------------------------|
221
+ | `onSubmit` | form | Called when the save button is pressed. Will pass the form definition to the callback. |
193
222
 
194
223
  ### FormsTable
195
224
 
@@ -197,9 +226,9 @@ The [FormsTable](https://formio.tsed.io/?path=/story/reactformio-formstable--san
197
226
 
198
227
  #### Props
199
228
 
200
- | Name | Type | Default | Description |
201
- |---|---|---|---|
202
- | `data` | array of forms | [] | A list of forms to be rendered in the grid.
229
+ | Name | Type | Default | Description |
230
+ |--------|----------------|---------|---------------------------------------------|
231
+ | `data` | array of forms | [] | A list of forms to be rendered in the grid. |
203
232
 
204
233
  ### SubmissionsTable
205
234
 
@@ -207,10 +236,10 @@ The submisison grid will render a list of submissions and allow clicking on one
207
236
 
208
237
  #### Props
209
238
 
210
- | Name | Type | Default | Description |
211
- |---|---|---|---|
212
- | `data` | array of submissions | [] | A list of submissions to be rendered in the grid. |
213
- | `form` | object | {} | The form definition for the submissions. This is used to render the submissions. |
239
+ | Name | Type | Default | Description |
240
+ |--------|----------------------|---------|----------------------------------------------------------------------------------|
241
+ | `data` | array of submissions | [] | A list of submissions to be rendered in the grid. |
242
+ | `form` | object | {} | The form definition for the submissions. This is used to render the submissions. |
214
243
 
215
244
  ## Redux
216
245
 
@@ -297,6 +326,3 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
297
326
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
298
327
 
299
328
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
300
-
301
- [travis]: https://travis-ci.org/
302
-
@@ -1,61 +1,17 @@
1
1
  import AllComponents from "formiojs/components";
2
- import Components from "formiojs/components/Components";
2
+ import { Components } from "formiojs";
3
3
  import PropTypes from "prop-types";
4
4
  import React from "react";
5
- import { FormOptions, FormSchema, Submission } from "../../interfaces";
6
- import { useForm } from "./useForm.hook";
5
+ import { useForm, UseFormHookProps } from "./useForm.hook";
7
6
 
8
7
  Components.setComponents(AllComponents);
9
8
 
10
- export interface ChangedSubmission<T = any> extends Submission<T> {
11
- changed: any;
12
- isValid: boolean;
13
- }
14
-
15
- export interface FormProps {
9
+ export interface FormProps<Data = any> extends UseFormHookProps<Data> {
16
10
  name?: string;
17
11
  /**
18
12
  *
19
13
  */
20
14
  className?: string;
21
- /**
22
- *
23
- */
24
- src?: string;
25
- /**
26
- * url to fetch form
27
- */
28
- url?: string;
29
- /**
30
- * Raw form object
31
- */
32
- form: Partial<FormSchema>;
33
- /**
34
- * Data submission
35
- */
36
- submission?: Submission;
37
- /**
38
- * Configuration option
39
- */
40
- options?: FormOptions;
41
- onPrevPage?: Function;
42
- onNextPage?: Function;
43
- onCancel?: Function;
44
- onChange?: (submission: ChangedSubmission) => void;
45
- onCustomEvent?: Function;
46
- onComponentChange?: Function;
47
- onSubmit?: Function;
48
- onSubmitDone?: Function;
49
- onFormLoad?: Function;
50
- onError?: Function;
51
- onRender?: Function;
52
- onAttach?: Function;
53
- onBuild?: Function;
54
- onFocus?: Function;
55
- onBlur?: Function;
56
- onInitialized?: Function;
57
- onFormReady?: (formio: any) => void;
58
- formioform?: any;
59
15
  }
60
16
 
61
17
  export function Form(props: Partial<FormProps>) {
@@ -1,15 +1,69 @@
1
- import FormioForm from "formiojs/Form";
1
+ import { ExtendedComponentSchema, Form } from "formiojs";
2
2
  import { get } from "lodash";
3
3
  import cloneDeep from "lodash/cloneDeep";
4
4
  import isEqual from "lodash/isEqual";
5
5
  import { useEffect, useRef } from "react";
6
6
  import { callLast } from "../../utils/callLast";
7
-
8
- export const useForm = (props: any): any => {
7
+ import { FormOptions, FormSchema, Submission } from "../../interfaces";
8
+
9
+ export interface ChangedSubmission<T = any> extends Submission<T> {
10
+ changed: any;
11
+ isValid: boolean;
12
+ }
13
+
14
+ export interface FormPageChangeProps<Data = any> {
15
+ page: number;
16
+ submission: Submission<Data>;
17
+ }
18
+
19
+ export interface UseFormHookProps<Data = any> extends Record<string, any> {
20
+ src?: string;
21
+ /**
22
+ * url to fetch form
23
+ */
24
+ url?: string;
25
+ /**
26
+ * Raw form object
27
+ */
28
+ form?: Partial<FormSchema>;
29
+ /**
30
+ * Configuration option
31
+ */
32
+ options?: FormOptions;
33
+ /**
34
+ * Data submission
35
+ */
36
+ submission?: Submission<Data>;
37
+ onPrevPage?: (obj: FormPageChangeProps<Data>) => void;
38
+ onNextPage?: (obj: FormPageChangeProps<Data>) => void;
39
+ onCancel?: Function;
40
+ onChange?: (submission: ChangedSubmission) => void;
41
+ onCustomEvent?: (obj: {
42
+ type: string;
43
+ event: string;
44
+ component: ExtendedComponentSchema;
45
+ data: any;
46
+ }) => void;
47
+ onComponentChange?: (component: ExtendedComponentSchema) => void;
48
+ onSubmit?: (submission: Submission<Data>) => void;
49
+ onSubmitDone?: (submission: Submission<Data>) => void;
50
+ onFormLoad?: Function;
51
+ onError?: (errors: any) => void;
52
+ onRender?: () => void;
53
+ onAttach?: Function;
54
+ onBuild?: Function;
55
+ onFocus?: Function;
56
+ onBlur?: Function;
57
+ onInitialized?: Function;
58
+ onFormReady?: (formio: Form) => void;
59
+ formioform?: any;
60
+ }
61
+
62
+ export function useForm<Data = any>(props: UseFormHookProps<Data>) {
9
63
  const { src, form, options = {}, submission, url, ...funcs } = props;
10
64
  const element = useRef<any>();
11
65
  const isLoaded = useRef<boolean>();
12
- const instance = useRef<any>();
66
+ const instance = useRef<Form>();
13
67
  const events = useRef<Map<string, any>>(new Map());
14
68
 
15
69
  const createWebForm = (srcOrForm: any, options: any) => {
@@ -19,7 +73,7 @@ export const useForm = (props: any): any => {
19
73
 
20
74
  if (!instance.current) {
21
75
  isLoaded.current = false;
22
- instance.current = new FormioForm(element.current, srcOrForm, options);
76
+ instance.current = new Form(element.current, srcOrForm, options);
23
77
 
24
78
  instance.current.onAny((event: string, ...args: any[]): void => {
25
79
  if (!instance.current) {
@@ -88,7 +142,7 @@ export const useForm = (props: any): any => {
88
142
  if (src) {
89
143
  if (instance.current) {
90
144
  isLoaded.current = false;
91
- instance.current.destroy(true);
145
+ (instance.current as any).destroy(true);
92
146
  }
93
147
 
94
148
  createWebForm(src, options);
@@ -102,7 +156,7 @@ export const useForm = (props: any): any => {
102
156
 
103
157
  return () => {
104
158
  isLoaded.current = false;
105
- instance.current && instance.current.destroy(true);
159
+ instance.current && (instance.current as any).destroy(true);
106
160
  };
107
161
  }, []);
108
162
 
@@ -118,4 +172,4 @@ export const useForm = (props: any): any => {
118
172
  return {
119
173
  element
120
174
  };
121
- };
175
+ }
@@ -9,7 +9,7 @@ import React, {
9
9
  } from "react";
10
10
  import { FormOptions, FormSchema, Submission } from "../../interfaces";
11
11
  import { Card } from "../card/card.component";
12
- import { ChangedSubmission, Form } from "../form/form.component";
12
+ import { Form } from "../form/form.component";
13
13
  import {
14
14
  AccessRoles,
15
15
  dataAccessToSubmissions,
@@ -20,6 +20,7 @@ import {
20
20
  submissionsToDataAccess,
21
21
  updateSubmissions
22
22
  } from "./formAccess.utils";
23
+ import { ChangedSubmission } from "../form/useForm.hook";
23
24
 
24
25
  export interface FormAccessProps {
25
26
  form: Partial<FormSchema>;
@@ -38,7 +38,7 @@ function mapSettingsForm({ action, ...settingsForm }: any): any {
38
38
  export interface FormActionProps {
39
39
  actionInfo: Partial<ActionSchema>;
40
40
  submission?: Partial<Submission>;
41
- onSubmit?: Function;
41
+ onSubmit?: (submission: Submission<ActionSchema>) => void;
42
42
  options: FormOptions;
43
43
  }
44
44
 
@@ -1,20 +1,14 @@
1
1
  import PropTypes from "prop-types";
2
2
  import React from "react";
3
- import { FormOptions, FormSchema } from "../../interfaces";
3
+ import { FormOptions } from "../../interfaces/FormOptions";
4
4
  import { FormBuilder } from "../form-builder/formBuilder.component";
5
5
  import { FormEditCTAs } from "./formCtas.component";
6
6
  import { FormParameters } from "./formParameters.component";
7
- import { useForm } from "./useForm.hook";
7
+ import { useFormEdit, UseFormEditHookProps } from "./useFormEdit.hook";
8
8
 
9
- export interface FormEditProps extends Record<string, unknown> {
10
- form?: Partial<FormSchema>;
11
- options?: FormOptions;
12
- typeChoices?: { label: string; value: any }[];
13
- displayChoices?: { label: string; value: any }[];
14
- enableTags?: boolean;
15
- onSubmit?: (form: FormSchema) => void;
16
- onCopy?: (form: FormSchema) => void;
9
+ export interface FormEditProps extends UseFormEditHookProps {
17
10
  builder?: any;
11
+ options?: FormOptions;
18
12
  }
19
13
 
20
14
  export function FormEdit(props: FormEditProps) {
@@ -30,7 +24,7 @@ export function FormEdit(props: FormEditProps) {
30
24
  reset,
31
25
  onSubmit,
32
26
  onCopy
33
- } = useForm(props);
27
+ } = useFormEdit(props);
34
28
  const { options = {}, builder } = props;
35
29
 
36
30
  return (
@@ -2,22 +2,16 @@ import { useEffect, useReducer } from "react";
2
2
  import { FormSchema } from "../../interfaces/FormSchema";
3
3
  import { createInitialState, hasChanged, reducer } from "./formEdit.reducer";
4
4
 
5
- export interface UseFormHookProps {
6
- form: Partial<FormSchema>;
7
- redo: Function;
8
- undo: Function;
9
- reset: Function;
10
- hasChanged: boolean;
11
- isValid: boolean;
12
- hasUndo: boolean;
13
- hasRedo: boolean;
14
- onSubmit: () => void;
15
- onCopy: () => void;
16
- formChange: (newForm: Partial<FormSchema>) => void;
17
- setChange: (path: string, value: any) => void;
5
+ export interface UseFormEditHookProps extends Record<string, unknown> {
6
+ form?: Partial<FormSchema>;
7
+ typeChoices?: { label: string; value: any }[];
8
+ displayChoices?: { label: string; value: any }[];
9
+ enableTags?: boolean;
10
+ onSubmit?: (form: Partial<FormSchema>) => void;
11
+ onCopy?: (form: Partial<FormSchema>) => void;
18
12
  }
19
13
 
20
- export function useForm(props: any): UseFormHookProps {
14
+ export function useFormEdit(props: UseFormEditHookProps) {
21
15
  const [{ current, future, past }, dispatchFormAction] = useReducer(
22
16
  reducer,
23
17
  createInitialState(props)
@@ -1,7 +1,7 @@
1
1
  import React, { useCallback, useEffect, useState } from "react";
2
2
  import { FormOptions, FormSchema } from "../../interfaces";
3
3
  import { getFormSettingsSchema } from "./formSettings.schema";
4
- import { ChangedSubmission, Form } from "../form/form.component";
4
+ import { Form } from "../form/form.component";
5
5
  import {
6
6
  FormSettingsSchema,
7
7
  formSettingsToSubmission,
@@ -9,6 +9,7 @@ import {
9
9
  } from "./formSettings.utils";
10
10
  import isEqual from "lodash/isEqual";
11
11
  import noop from "lodash/noop";
12
+ import { ChangedSubmission } from "../form/useForm.hook";
12
13
 
13
14
  export interface FormSettingsProps {
14
15
  form: Partial<FormSchema>;
@@ -1,16 +0,0 @@
1
- import { FormSchema } from "../../interfaces/FormSchema";
2
- export interface UseFormHookProps {
3
- form: Partial<FormSchema>;
4
- redo: Function;
5
- undo: Function;
6
- reset: Function;
7
- hasChanged: boolean;
8
- isValid: boolean;
9
- hasUndo: boolean;
10
- hasRedo: boolean;
11
- onSubmit: () => void;
12
- onCopy: () => void;
13
- formChange: (newForm: Partial<FormSchema>) => void;
14
- setChange: (path: string, value: any) => void;
15
- }
16
- export declare function useForm(props: any): UseFormHookProps;