@tsed/react-formio 1.13.3 → 1.13.6
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/dist/components/form/form.stories.d.ts +25 -0
- package/dist/components/form/useForm.hook.d.ts +7 -3
- package/dist/components/index.d.ts +2 -0
- package/dist/index.js +36 -13
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +43 -22
- package/dist/index.modern.js.map +1 -1
- package/package.json +6 -6
- package/src/components/form/form.stories.tsx +58 -1
- package/src/components/form/useForm.hook.ts +35 -11
- package/src/components/index.ts +2 -0
- package/src/components/table/components/defaultCell.component.tsx +1 -1
- package/src/index.ts +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/react-formio",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.6",
|
|
4
4
|
"description": "Provide a react formio wrapper. Written in TypeScript.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.modern.js",
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
"lint:fix": "yarn lint --fix",
|
|
11
11
|
"test": "cross-env NODE_ENV=test jest --coverage",
|
|
12
12
|
"test:coverage:update": "write-coverage",
|
|
13
|
-
"build": "microbundle --no-compress --format modern,cjs --jsx React.createElement",
|
|
14
|
-
"watch": "microbundle watch --no-compress --format modern,cjs --jsx React.createElement"
|
|
13
|
+
"build": "microbundle --no-compress --format modern,cjs --jsx React.createElement --jsxFragment React.Fragment --globals react/jsx-runtime=jsx",
|
|
14
|
+
"watch": "microbundle watch --no-compress --format modern,cjs --jsx React.createElement --jsxFragment React.Fragment --globals react/jsx-runtime=jsx"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@tsed/redux-utils": "1.13.
|
|
17
|
+
"@tsed/redux-utils": "1.13.6",
|
|
18
18
|
"eventemitter2": "^6.4.3",
|
|
19
19
|
"prop-types": "^15.7.2"
|
|
20
20
|
},
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"tooltip.js": ">=1.3.3"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tsed/tailwind": "1.13.
|
|
33
|
-
"@tsed/tailwind-formio": "1.13.
|
|
32
|
+
"@tsed/tailwind": "1.13.6",
|
|
33
|
+
"@tsed/tailwind-formio": "1.13.6"
|
|
34
34
|
},
|
|
35
35
|
"repository": "https://github.com/TypedProject/tsed-formio",
|
|
36
36
|
"bugs": {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useState } from "react";
|
|
2
2
|
|
|
3
3
|
import { Submission } from "../../interfaces";
|
|
4
4
|
import form from "../__fixtures__/form.fixture.json";
|
|
@@ -189,3 +189,60 @@ ReadOnly.args = {
|
|
|
189
189
|
readonly: true,
|
|
190
190
|
form
|
|
191
191
|
};
|
|
192
|
+
|
|
193
|
+
export const OnChange = (args: any) => {
|
|
194
|
+
const [data, setForm] = useState<any>(() => {});
|
|
195
|
+
const props = wrap(args);
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
<Form
|
|
199
|
+
{...props}
|
|
200
|
+
options={{ template: "tailwind", iconset: "bx", readOnly: args.readOnly }}
|
|
201
|
+
form={args.form}
|
|
202
|
+
submission={{ data }}
|
|
203
|
+
onChange={(changedSubmission) => {
|
|
204
|
+
setForm(changedSubmission.data);
|
|
205
|
+
}}
|
|
206
|
+
/>
|
|
207
|
+
);
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
OnChange.args = {
|
|
211
|
+
form: {
|
|
212
|
+
type: "form",
|
|
213
|
+
display: "form",
|
|
214
|
+
tags: [],
|
|
215
|
+
components: [
|
|
216
|
+
{
|
|
217
|
+
label: "First name",
|
|
218
|
+
widget: {
|
|
219
|
+
type: "input"
|
|
220
|
+
},
|
|
221
|
+
errorLabel: "",
|
|
222
|
+
key: "firstName",
|
|
223
|
+
inputType: "text",
|
|
224
|
+
type: "textfield",
|
|
225
|
+
id: "eqb1o4r",
|
|
226
|
+
defaultValue: "",
|
|
227
|
+
validate: {
|
|
228
|
+
required: true
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
label: "Last name",
|
|
233
|
+
widget: {
|
|
234
|
+
type: "input"
|
|
235
|
+
},
|
|
236
|
+
errorLabel: "",
|
|
237
|
+
key: "lastName",
|
|
238
|
+
inputType: "text",
|
|
239
|
+
type: "textfield",
|
|
240
|
+
id: "eqb1o4r",
|
|
241
|
+
defaultValue: "",
|
|
242
|
+
validate: {
|
|
243
|
+
required: true
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
]
|
|
247
|
+
}
|
|
248
|
+
};
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { ExtendedComponentSchema, Form } from "formiojs";
|
|
2
|
-
import { get } from "lodash";
|
|
3
2
|
import cloneDeep from "lodash/cloneDeep";
|
|
4
3
|
import isEqual from "lodash/isEqual";
|
|
5
4
|
import { useEffect, useRef } from "react";
|
|
6
5
|
|
|
7
6
|
import { FormOptions, FormSchema, Submission } from "../../interfaces";
|
|
8
|
-
import { callLast } from "../../utils/callLast";
|
|
9
7
|
|
|
10
8
|
export interface ChangedSubmission<T = any> extends Submission<T> {
|
|
11
|
-
changed:
|
|
9
|
+
changed: {
|
|
10
|
+
component: ExtendedComponentSchema;
|
|
11
|
+
instance: any;
|
|
12
|
+
value: any;
|
|
13
|
+
} & Record<string, any>;
|
|
12
14
|
isValid: boolean;
|
|
13
15
|
}
|
|
14
16
|
|
|
@@ -54,12 +56,14 @@ export interface UseFormHookProps<Data = any> extends Record<string, any> {
|
|
|
54
56
|
onFocus?: Function;
|
|
55
57
|
onBlur?: Function;
|
|
56
58
|
onInitialized?: Function;
|
|
57
|
-
onFormReady?: (formio:
|
|
59
|
+
onFormReady?: (formio: any) => void;
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
function
|
|
62
|
+
function useEvent(event: string, callback: any, events: Map<string, any>) {
|
|
61
63
|
useEffect(() => {
|
|
62
|
-
|
|
64
|
+
if (callback) {
|
|
65
|
+
events.set(event, callback);
|
|
66
|
+
}
|
|
63
67
|
}, [callback, event, events]);
|
|
64
68
|
}
|
|
65
69
|
|
|
@@ -69,6 +73,7 @@ function useEvents(funcs: any) {
|
|
|
69
73
|
const hasEvent = (event: string) => {
|
|
70
74
|
return funcs.hasOwnProperty(event) && typeof funcs[event] === "function";
|
|
71
75
|
};
|
|
76
|
+
|
|
72
77
|
const emit = (event: string, ...args: any[]) => {
|
|
73
78
|
if (hasEvent(event)) {
|
|
74
79
|
const fn = events.current.has(event) ? events.current.get(event) : funcs[event];
|
|
@@ -76,7 +81,24 @@ function useEvents(funcs: any) {
|
|
|
76
81
|
}
|
|
77
82
|
};
|
|
78
83
|
|
|
79
|
-
|
|
84
|
+
useEvent("onBlur", funcs["onBlur"], events.current);
|
|
85
|
+
useEvent("onPrevPage", funcs["onPrevPage"], events.current);
|
|
86
|
+
useEvent("onNextPage", funcs["onNextPage"], events.current);
|
|
87
|
+
useEvent("onCancel", funcs["onCancel"], events.current);
|
|
88
|
+
useEvent("onChange", funcs["onChange"], events.current);
|
|
89
|
+
useEvent("onCustomEvent", funcs["onCustomEvent"], events.current);
|
|
90
|
+
useEvent("onComponentChange", funcs["onComponentChange"], events.current);
|
|
91
|
+
useEvent("onSubmit", funcs["onSubmit"], events.current);
|
|
92
|
+
useEvent("onAsyncSubmit", funcs["onAsyncSubmit"], events.current);
|
|
93
|
+
useEvent("onSubmitDone", funcs["onSubmitDone"], events.current);
|
|
94
|
+
useEvent("onFormLoad", funcs["onFormLoad"], events.current);
|
|
95
|
+
useEvent("onError", funcs["onError"], events.current);
|
|
96
|
+
useEvent("onRender", funcs["onRender"], events.current);
|
|
97
|
+
useEvent("onAttach", funcs["onAttach"], events.current);
|
|
98
|
+
useEvent("onBuild", funcs["onBuild"], events.current);
|
|
99
|
+
useEvent("onFocus", funcs["onFocus"], events.current);
|
|
100
|
+
useEvent("onBlur", funcs["onBlur"], events.current);
|
|
101
|
+
useEvent("onInitialized", funcs["onInitialized"], events.current);
|
|
80
102
|
|
|
81
103
|
return { events, emit, hasEvent };
|
|
82
104
|
}
|
|
@@ -121,10 +143,8 @@ export function useForm<Data = any>(props: UseFormHookProps<Data>) {
|
|
|
121
143
|
if (event.startsWith("formio.")) {
|
|
122
144
|
const eventName = `on${event.charAt(7).toUpperCase()}${event.slice(8)}`;
|
|
123
145
|
|
|
124
|
-
if (eventName === "onChange") {
|
|
125
|
-
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
146
|
+
if (eventName === "onChange" && !args[0].changed) {
|
|
147
|
+
return;
|
|
128
148
|
}
|
|
129
149
|
|
|
130
150
|
emit(eventName, ...args, instance.current);
|
|
@@ -148,6 +168,10 @@ export function useForm<Data = any>(props: UseFormHookProps<Data>) {
|
|
|
148
168
|
useEffect(() => {
|
|
149
169
|
if (instance.current) {
|
|
150
170
|
instance.current.ready.then((formio: any) => {
|
|
171
|
+
if (isEqual(formio.submission.data, submission?.data)) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
151
175
|
submission && (formio.submission = cloneDeep(submission));
|
|
152
176
|
});
|
|
153
177
|
}
|
package/src/components/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./actions-table/actionsTable.component";
|
|
|
2
2
|
export * from "./alert/alert.component";
|
|
3
3
|
export * from "./card/card.component";
|
|
4
4
|
export * from "./form/form.component";
|
|
5
|
+
export * from "./form/useForm.hook";
|
|
5
6
|
export * from "./form-access/formAccess.component";
|
|
6
7
|
export * from "./form-action/formAction.component";
|
|
7
8
|
export * from "./form-builder/formBuilder.component";
|
|
@@ -9,6 +10,7 @@ export * from "./form-control/formControl.component";
|
|
|
9
10
|
export * from "./form-edit/formCtas.component";
|
|
10
11
|
export * from "./form-edit/formEdit.component";
|
|
11
12
|
export * from "./form-edit/formParameters.component";
|
|
13
|
+
export * from "./form-edit/useFormEdit.hook";
|
|
12
14
|
export * from "./form-settings/formSettings.component";
|
|
13
15
|
export * from "./forms-table/formsTable.component";
|
|
14
16
|
export * from "./input-tags/inputTags.component";
|