@tsed/react-formio 1.13.3 → 1.13.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/react-formio",
3
- "version": "1.13.3",
3
+ "version": "1.13.4",
4
4
  "description": "Provide a react formio wrapper. Written in TypeScript.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.modern.js",
@@ -14,7 +14,7 @@
14
14
  "watch": "microbundle watch --no-compress --format modern,cjs --jsx React.createElement"
15
15
  },
16
16
  "dependencies": {
17
- "@tsed/redux-utils": "1.13.3",
17
+ "@tsed/redux-utils": "1.13.4",
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.3",
33
- "@tsed/tailwind-formio": "1.13.3"
32
+ "@tsed/tailwind": "1.13.4",
33
+ "@tsed/tailwind-formio": "1.13.4"
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
+ };
@@ -8,7 +8,11 @@ import { FormOptions, FormSchema, Submission } from "../../interfaces";
8
8
  import { callLast } from "../../utils/callLast";
9
9
 
10
10
  export interface ChangedSubmission<T = any> extends Submission<T> {
11
- changed: any;
11
+ changed: {
12
+ component: ExtendedComponentSchema;
13
+ instance: Form;
14
+ value: any;
15
+ } & Record<string, any>;
12
16
  isValid: boolean;
13
17
  }
14
18
 
@@ -57,9 +61,14 @@ export interface UseFormHookProps<Data = any> extends Record<string, any> {
57
61
  onFormReady?: (formio: Form) => void;
58
62
  }
59
63
 
60
- function useDebounce(event: string, callback: any, events: Map<string, any>) {
64
+ function useEvent(event: string, callback: any, events: Map<string, any>) {
61
65
  useEffect(() => {
62
- callback && events.set(event, callLast(callback, 100));
66
+ if (callback) {
67
+ // if (event === "onChange") {
68
+ // callback = callLast(callback, 200);
69
+ // }
70
+ events.set(event, callback);
71
+ }
63
72
  }, [callback, event, events]);
64
73
  }
65
74
 
@@ -69,6 +78,7 @@ function useEvents(funcs: any) {
69
78
  const hasEvent = (event: string) => {
70
79
  return funcs.hasOwnProperty(event) && typeof funcs[event] === "function";
71
80
  };
81
+
72
82
  const emit = (event: string, ...args: any[]) => {
73
83
  if (hasEvent(event)) {
74
84
  const fn = events.current.has(event) ? events.current.get(event) : funcs[event];
@@ -76,7 +86,24 @@ function useEvents(funcs: any) {
76
86
  }
77
87
  };
78
88
 
79
- useDebounce("onChange", funcs.onChange, events.current);
89
+ useEvent("onBlur", funcs["onBlur"], events.current);
90
+ useEvent("onPrevPage", funcs["onPrevPage"], events.current);
91
+ useEvent("onNextPage", funcs["onNextPage"], events.current);
92
+ useEvent("onCancel", funcs["onCancel"], events.current);
93
+ useEvent("onChange", funcs["onChange"], events.current);
94
+ useEvent("onCustomEvent", funcs["onCustomEvent"], events.current);
95
+ useEvent("onComponentChange", funcs["onComponentChange"], events.current);
96
+ useEvent("onSubmit", funcs["onSubmit"], events.current);
97
+ useEvent("onAsyncSubmit", funcs["onAsyncSubmit"], events.current);
98
+ useEvent("onSubmitDone", funcs["onSubmitDone"], events.current);
99
+ useEvent("onFormLoad", funcs["onFormLoad"], events.current);
100
+ useEvent("onError", funcs["onError"], events.current);
101
+ useEvent("onRender", funcs["onRender"], events.current);
102
+ useEvent("onAttach", funcs["onAttach"], events.current);
103
+ useEvent("onBuild", funcs["onBuild"], events.current);
104
+ useEvent("onFocus", funcs["onFocus"], events.current);
105
+ useEvent("onBlur", funcs["onBlur"], events.current);
106
+ useEvent("onInitialized", funcs["onInitialized"], events.current);
80
107
 
81
108
  return { events, emit, hasEvent };
82
109
  }
@@ -121,10 +148,8 @@ export function useForm<Data = any>(props: UseFormHookProps<Data>) {
121
148
  if (event.startsWith("formio.")) {
122
149
  const eventName = `on${event.charAt(7).toUpperCase()}${event.slice(8)}`;
123
150
 
124
- if (eventName === "onChange") {
125
- if (isEqual(get(submission, "data"), args[0].data)) {
126
- return;
127
- }
151
+ if (eventName === "onChange" && !args[0].changed) {
152
+ return;
128
153
  }
129
154
 
130
155
  emit(eventName, ...args, instance.current);
@@ -148,6 +173,10 @@ export function useForm<Data = any>(props: UseFormHookProps<Data>) {
148
173
  useEffect(() => {
149
174
  if (instance.current) {
150
175
  instance.current.ready.then((formio: any) => {
176
+ if (isEqual(formio.submission.data, submission?.data)) {
177
+ return;
178
+ }
179
+
151
180
  submission && (formio.submission = cloneDeep(submission));
152
181
  });
153
182
  }