@tsed/react-formio 1.13.2 → 1.13.5
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/.eslintignore +13 -0
- package/.eslintrc.js +7 -0
- package/coverage.json +6 -0
- package/dist/components/form/form.stories.d.ts +25 -0
- package/dist/components/form/useForm.hook.d.ts +7 -3
- package/dist/components/form-control/formControl.component.d.ts +2 -2
- package/dist/components/form-control/formControl.component.spec.d.ts +1 -0
- package/dist/components/form-control/formControl.stories.d.ts +57 -0
- package/dist/components/index.d.ts +4 -2
- package/dist/components/table/components/defaultCellHeader.component.d.ts +1 -1
- package/dist/components/table/index.d.ts +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +7929 -7904
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +7366 -7339
- package/dist/index.modern.js.map +1 -1
- package/dist/stores/actions/index.d.ts +1 -1
- package/dist/stores/auth/index.d.ts +4 -4
- package/dist/stores/index.d.ts +2 -2
- package/jest.config.js +6 -1
- package/package.json +7 -4
- package/src/components/actions-table/actionsTable.component.spec.tsx +11 -11
- package/src/components/actions-table/actionsTable.component.tsx +8 -9
- package/src/components/actions-table/actionsTable.stories.tsx +1 -0
- package/src/components/alert/alert.component.spec.tsx +21 -19
- package/src/components/alert/alert.stories.tsx +1 -0
- package/src/components/card/card.component.spec.tsx +5 -4
- package/src/components/card/card.stories.tsx +1 -0
- package/src/components/form/form.component.spec.tsx +7 -6
- package/src/components/form/form.component.tsx +2 -1
- package/src/components/form/form.stories.tsx +118 -76
- package/src/components/form/useForm.hook.ts +47 -22
- package/src/components/form-access/formAccess.component.tsx +2 -1
- package/src/components/form-access/formAccess.schema.ts +1 -0
- package/src/components/form-access/formAccess.stories.tsx +1 -0
- package/src/components/form-access/formAccess.utils.ts +9 -8
- package/src/components/form-action/formAction.component.tsx +4 -3
- package/src/components/form-action/formAction.stories.tsx +225 -227
- package/src/components/form-builder/formBuilder.component.tsx +1 -0
- package/src/components/form-builder/formBuilder.stories.tsx +1 -0
- package/src/components/form-control/formControl.component.spec.tsx +76 -0
- package/src/components/form-control/formControl.component.tsx +15 -7
- package/src/components/form-control/formControl.stories.tsx +65 -0
- package/src/components/form-edit/formCtas.component.tsx +25 -26
- package/src/components/form-edit/formEdit.component.tsx +1 -0
- package/src/components/form-edit/formEdit.reducer.ts +1 -0
- package/src/components/form-edit/formEdit.stories.tsx +1 -0
- package/src/components/form-edit/formParameters.component.tsx +1 -0
- package/src/components/form-edit/useFormEdit.hook.ts +1 -0
- package/src/components/form-settings/formSettings.component.spec.tsx +7 -6
- package/src/components/form-settings/formSettings.component.tsx +12 -14
- package/src/components/form-settings/formSettings.stories.tsx +1 -0
- package/src/components/form-settings/formSettings.utils.ts +1 -0
- package/src/components/forms-table/components/formCell.component.tsx +1 -0
- package/src/components/forms-table/formsTable.component.tsx +23 -25
- package/src/components/forms-table/formsTable.stories.tsx +1 -0
- package/src/components/index.ts +4 -2
- package/src/components/input-tags/inputTags.component.tsx +5 -4
- package/src/components/input-tags/inputTags.stories.tsx +1 -0
- package/src/components/input-text/inputText.component.spec.tsx +12 -11
- package/src/components/input-text/inputText.component.tsx +1 -0
- package/src/components/input-text/inputText.stories.tsx +1 -0
- package/src/components/loader/loader.component.spec.tsx +6 -5
- package/src/components/loader/loader.component.tsx +1 -0
- package/src/components/loader/loader.stories.tsx +1 -0
- package/src/components/modal/modal.component.spec.tsx +36 -33
- package/src/components/modal/modal.component.tsx +1 -1
- package/src/components/modal/modal.stories.tsx +1 -0
- package/src/components/modal/removeModal.component.tsx +1 -0
- package/src/components/pagination/pagination.component.spec.tsx +24 -21
- package/src/components/pagination/pagination.component.tsx +1 -0
- package/src/components/pagination/pagination.stories.tsx +1 -0
- package/src/components/react-component/reactComponent.component.tsx +3 -2
- package/src/components/select/select.component.spec.tsx +17 -18
- package/src/components/select/select.component.tsx +1 -0
- package/src/components/select/select.stories.tsx +1 -0
- package/src/components/submissions-table/submissionsTable.component.tsx +6 -5
- package/src/components/submissions-table/submissionsTable.stories.tsx +1 -0
- package/src/components/table/components/defaultArrowSort.component.tsx +1 -0
- package/src/components/table/components/defaultCellHeader.component.tsx +1 -1
- package/src/components/table/components/defaultCellOperations.component.tsx +1 -0
- package/src/components/table/components/defaultOperationButton.component.tsx +1 -0
- package/src/components/table/filters/defaultColumnFilter.component.spec.tsx +5 -3
- package/src/components/table/filters/defaultColumnFilter.component.tsx +1 -0
- package/src/components/table/filters/selectColumnFilter.component.spec.tsx +9 -7
- package/src/components/table/filters/selectColumnFilter.component.tsx +1 -0
- package/src/components/table/index.ts +1 -1
- package/src/components/table/table.component.tsx +45 -58
- package/src/components/table/table.stories.tsx +2 -1
- package/src/components/table/utils/mapFormToColumns.tsx +2 -1
- package/src/components/table/utils/useOperations.hook.tsx +1 -0
- package/src/components/tabs/tabs.component.spec.tsx +6 -5
- package/src/components/tabs/tabs.component.stories.tsx +1 -0
- package/src/components/tabs/tabs.component.tsx +10 -4
- package/src/index.ts +3 -5
- package/src/interfaces/Operation.ts +1 -0
- package/src/stores/action/action.actions.spec.ts +1 -0
- package/src/stores/action/action.actions.ts +1 -0
- package/src/stores/action/action.reducers.ts +1 -1
- package/src/stores/action-info/action-info.actions.spec.ts +1 -0
- package/src/stores/action-info/action-info.actions.ts +2 -1
- package/src/stores/action-info/action-info.reducers.ts +2 -1
- package/src/stores/action-info/action-info.selectors.ts +2 -1
- package/src/stores/actions/actions.actions.spec.ts +1 -0
- package/src/stores/actions/actions.actions.ts +1 -0
- package/src/stores/actions/actions.reducers.ts +1 -0
- package/src/stores/actions/index.ts +1 -1
- package/src/stores/auth/auth.actions.ts +1 -0
- package/src/stores/auth/auth.reducers.ts +1 -0
- package/src/stores/auth/auth.selectors.ts +1 -0
- package/src/stores/auth/auth.utils.tsx +2 -1
- package/src/stores/auth/getAccess.action.spec.ts +1 -0
- package/src/stores/auth/getAccess.action.ts +1 -0
- package/src/stores/auth/getProjectAccess.action.ts +1 -0
- package/src/stores/auth/index.ts +4 -4
- package/src/stores/auth/initAuth.action.spec.ts +1 -0
- package/src/stores/auth/initAuth.action.ts +1 -0
- package/src/stores/auth/logout.action.spec.ts +2 -1
- package/src/stores/auth/logout.action.ts +1 -0
- package/src/stores/auth/setUser.action.spec.ts +1 -0
- package/src/stores/auth/setUser.action.ts +1 -0
- package/src/stores/form/form.actions.spec.ts +1 -0
- package/src/stores/form/form.actions.ts +1 -0
- package/src/stores/form/form.reducers.ts +1 -0
- package/src/stores/forms/forms.actions.spec.ts +1 -0
- package/src/stores/forms/forms.actions.ts +1 -0
- package/src/stores/forms/forms.reducers.ts +1 -0
- package/src/stores/index.ts +3 -2
- package/src/stores/root/root.selectors.ts +1 -1
- package/src/stores/submission/submission.actions.spec.ts +1 -0
- package/src/stores/submission/submission.actions.ts +1 -0
- package/src/stores/submission/submission.reducers.ts +1 -0
- package/src/stores/submissions/submissions.actions.spec.ts +1 -0
- package/src/stores/submissions/submissions.actions.ts +1 -0
- package/src/stores/submissions/submissions.reducers.ts +1 -0
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import {ExtendedComponentSchema, Form} from "formiojs";
|
|
2
|
-
import {get} from "lodash";
|
|
1
|
+
import { ExtendedComponentSchema, Form } from "formiojs";
|
|
3
2
|
import cloneDeep from "lodash/cloneDeep";
|
|
4
3
|
import isEqual from "lodash/isEqual";
|
|
5
|
-
import {useEffect, useRef} from "react";
|
|
6
|
-
|
|
7
|
-
import {FormOptions, FormSchema, Submission} from "../../interfaces";
|
|
4
|
+
import { useEffect, useRef } from "react";
|
|
5
|
+
|
|
6
|
+
import { FormOptions, FormSchema, Submission } from "../../interfaces";
|
|
8
7
|
|
|
9
8
|
export interface ChangedSubmission<T = any> extends Submission<T> {
|
|
10
|
-
changed:
|
|
9
|
+
changed: {
|
|
10
|
+
component: ExtendedComponentSchema;
|
|
11
|
+
instance: any;
|
|
12
|
+
value: any;
|
|
13
|
+
} & Record<string, any>;
|
|
11
14
|
isValid: boolean;
|
|
12
15
|
}
|
|
13
16
|
|
|
@@ -53,12 +56,14 @@ export interface UseFormHookProps<Data = any> extends Record<string, any> {
|
|
|
53
56
|
onFocus?: Function;
|
|
54
57
|
onBlur?: Function;
|
|
55
58
|
onInitialized?: Function;
|
|
56
|
-
onFormReady?: (formio:
|
|
59
|
+
onFormReady?: (formio: any) => void;
|
|
57
60
|
}
|
|
58
61
|
|
|
59
|
-
function
|
|
62
|
+
function useEvent(event: string, callback: any, events: Map<string, any>) {
|
|
60
63
|
useEffect(() => {
|
|
61
|
-
|
|
64
|
+
if (callback) {
|
|
65
|
+
events.set(event, callback);
|
|
66
|
+
}
|
|
62
67
|
}, [callback, event, events]);
|
|
63
68
|
}
|
|
64
69
|
|
|
@@ -66,26 +71,44 @@ function useEvents(funcs: any) {
|
|
|
66
71
|
const events = useRef<Map<string, any>>(new Map());
|
|
67
72
|
|
|
68
73
|
const hasEvent = (event: string) => {
|
|
69
|
-
return funcs.hasOwnProperty(event) && typeof funcs[event] === "function"
|
|
70
|
-
}
|
|
74
|
+
return funcs.hasOwnProperty(event) && typeof funcs[event] === "function";
|
|
75
|
+
};
|
|
76
|
+
|
|
71
77
|
const emit = (event: string, ...args: any[]) => {
|
|
72
78
|
if (hasEvent(event)) {
|
|
73
|
-
const fn = events.current.has(event) ? events.current.get(event) : funcs[event]
|
|
79
|
+
const fn = events.current.has(event) ? events.current.get(event) : funcs[event];
|
|
74
80
|
return fn(...args);
|
|
75
81
|
}
|
|
76
82
|
};
|
|
77
83
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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);
|
|
102
|
+
|
|
103
|
+
return { events, emit, hasEvent };
|
|
81
104
|
}
|
|
82
105
|
|
|
83
106
|
export function useForm<Data = any>(props: UseFormHookProps<Data>) {
|
|
84
|
-
const {src, form, options = {}, submission, url, ...funcs} = props;
|
|
107
|
+
const { src, form, options = {}, submission, url, ...funcs } = props;
|
|
85
108
|
const element = useRef<any>();
|
|
86
109
|
const isLoaded = useRef<boolean>();
|
|
87
110
|
const instance = useRef<Form>();
|
|
88
|
-
const {emit, hasEvent} = useEvents(funcs);
|
|
111
|
+
const { emit, hasEvent } = useEvents(funcs);
|
|
89
112
|
|
|
90
113
|
async function customValidation(submission: Submission, callback: (err: Error | null) => void) {
|
|
91
114
|
if (hasEvent("onAsyncSubmit")) {
|
|
@@ -120,13 +143,11 @@ export function useForm<Data = any>(props: UseFormHookProps<Data>) {
|
|
|
120
143
|
if (event.startsWith("formio.")) {
|
|
121
144
|
const eventName = `on${event.charAt(7).toUpperCase()}${event.slice(8)}`;
|
|
122
145
|
|
|
123
|
-
if (eventName === "onChange") {
|
|
124
|
-
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
146
|
+
if (eventName === "onChange" && !args[0].changed) {
|
|
147
|
+
return;
|
|
127
148
|
}
|
|
128
149
|
|
|
129
|
-
emit(eventName, ...args, instance.current)
|
|
150
|
+
emit(eventName, ...args, instance.current);
|
|
130
151
|
}
|
|
131
152
|
});
|
|
132
153
|
|
|
@@ -147,6 +168,10 @@ export function useForm<Data = any>(props: UseFormHookProps<Data>) {
|
|
|
147
168
|
useEffect(() => {
|
|
148
169
|
if (instance.current) {
|
|
149
170
|
instance.current.ready.then((formio: any) => {
|
|
171
|
+
if (isEqual(formio.submission.data, submission?.data)) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
150
175
|
submission && (formio.submission = cloneDeep(submission));
|
|
151
176
|
});
|
|
152
177
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import PropTypes from "prop-types";
|
|
2
2
|
import React, { PropsWithChildren, ReactElement, useCallback, useEffect, useMemo, useState } from "react";
|
|
3
|
+
|
|
3
4
|
import { FormOptions, FormSchema, Submission } from "../../interfaces";
|
|
4
5
|
import { Card } from "../card/card.component";
|
|
5
6
|
import { Form } from "../form/form.component";
|
|
7
|
+
import { ChangedSubmission } from "../form/useForm.hook";
|
|
6
8
|
import {
|
|
7
9
|
AccessRoles,
|
|
8
10
|
dataAccessToSubmissions,
|
|
@@ -13,7 +15,6 @@ import {
|
|
|
13
15
|
submissionsToDataAccess,
|
|
14
16
|
updateSubmissions
|
|
15
17
|
} from "./formAccess.utils";
|
|
16
|
-
import { ChangedSubmission } from "../form/useForm.hook";
|
|
17
18
|
|
|
18
19
|
export interface FormAccessProps {
|
|
19
20
|
form: Partial<FormSchema>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {ExtendedComponentSchema} from "formiojs";
|
|
1
|
+
import { ExtendedComponentSchema } from "formiojs";
|
|
2
2
|
import cloneDeep from "lodash/cloneDeep";
|
|
3
3
|
import isEqual from "lodash/isEqual";
|
|
4
4
|
import noop from "lodash/noop";
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
|
|
6
|
+
import { FormSchema, Submission } from "../../interfaces";
|
|
7
|
+
import { RoleSchema } from "../../interfaces/RoleSchema";
|
|
8
|
+
import { getAccessPermissionForm, getSubmissionPermissionForm } from "./formAccess.schema";
|
|
8
9
|
|
|
9
10
|
export interface Choice {
|
|
10
11
|
label: string;
|
|
@@ -69,8 +70,8 @@ function hashToAccess(data: AccessRoles) {
|
|
|
69
70
|
|
|
70
71
|
export function getFormAccess(roles: RoleSchema[]): FormAccessSchema {
|
|
71
72
|
const choices = rolesToChoices(roles);
|
|
72
|
-
const access = getAccessPermissionForm({choices});
|
|
73
|
-
const submissionAccess = getSubmissionPermissionForm({choices});
|
|
73
|
+
const access = getAccessPermissionForm({ choices });
|
|
74
|
+
const submissionAccess = getSubmissionPermissionForm({ choices });
|
|
74
75
|
|
|
75
76
|
return {
|
|
76
77
|
access,
|
|
@@ -79,7 +80,7 @@ export function getFormAccess(roles: RoleSchema[]): FormAccessSchema {
|
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
export function dataAccessToSubmissions(form: Partial<FormSchema>, formAccess: FormAccessSchema): SubmissionAccess {
|
|
82
|
-
const getKeys = (components: ExtendedComponentSchema[]) => components.map(({key}) => key);
|
|
83
|
+
const getKeys = (components: ExtendedComponentSchema[]) => components.map(({ key }) => key);
|
|
83
84
|
|
|
84
85
|
return {
|
|
85
86
|
access: {
|
|
@@ -107,7 +108,7 @@ export function updateSubmissions(type: string, submission: Submission<AccessRol
|
|
|
107
108
|
if (shouldUpdate(type, submission, submissions)) {
|
|
108
109
|
submissions = {
|
|
109
110
|
...submissions,
|
|
110
|
-
[type]: {data: submission.data}
|
|
111
|
+
[type]: { data: submission.data }
|
|
111
112
|
};
|
|
112
113
|
cb(submissions);
|
|
113
114
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import FormioUtils from "formiojs/utils";
|
|
2
|
-
import React, { PropsWithChildren, ReactElement
|
|
2
|
+
import React, { PropsWithChildren, ReactElement } from "react";
|
|
3
|
+
|
|
3
4
|
import { ActionDefaultsSchema, ActionSchema, FormOptions, Submission } from "../../interfaces";
|
|
4
5
|
import { Form } from "../form/form.component";
|
|
5
6
|
|
|
@@ -38,12 +39,12 @@ export interface FormActionProps {
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
export function FormAction({ actionInfo, children, onSubmit, options, ...props }: PropsWithChildren<FormActionProps>): ReactElement {
|
|
41
|
-
const { form, submission } =
|
|
42
|
+
const { form, submission } = (() => {
|
|
42
43
|
const submission = mapData(props.submission || {}, actionInfo.defaults!);
|
|
43
44
|
const form = mapSettingsForm(actionInfo.settingsForm);
|
|
44
45
|
|
|
45
46
|
return { form, submission: { data: submission } };
|
|
46
|
-
}
|
|
47
|
+
})();
|
|
47
48
|
|
|
48
49
|
return (
|
|
49
50
|
<div>
|