@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.
Files changed (135) hide show
  1. package/.eslintignore +13 -0
  2. package/.eslintrc.js +7 -0
  3. package/coverage.json +6 -0
  4. package/dist/components/form/form.stories.d.ts +25 -0
  5. package/dist/components/form/useForm.hook.d.ts +7 -3
  6. package/dist/components/form-control/formControl.component.d.ts +2 -2
  7. package/dist/components/form-control/formControl.component.spec.d.ts +1 -0
  8. package/dist/components/form-control/formControl.stories.d.ts +57 -0
  9. package/dist/components/index.d.ts +4 -2
  10. package/dist/components/table/components/defaultCellHeader.component.d.ts +1 -1
  11. package/dist/components/table/index.d.ts +1 -1
  12. package/dist/index.d.ts +3 -3
  13. package/dist/index.js +7929 -7904
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.modern.js +7366 -7339
  16. package/dist/index.modern.js.map +1 -1
  17. package/dist/stores/actions/index.d.ts +1 -1
  18. package/dist/stores/auth/index.d.ts +4 -4
  19. package/dist/stores/index.d.ts +2 -2
  20. package/jest.config.js +6 -1
  21. package/package.json +7 -4
  22. package/src/components/actions-table/actionsTable.component.spec.tsx +11 -11
  23. package/src/components/actions-table/actionsTable.component.tsx +8 -9
  24. package/src/components/actions-table/actionsTable.stories.tsx +1 -0
  25. package/src/components/alert/alert.component.spec.tsx +21 -19
  26. package/src/components/alert/alert.stories.tsx +1 -0
  27. package/src/components/card/card.component.spec.tsx +5 -4
  28. package/src/components/card/card.stories.tsx +1 -0
  29. package/src/components/form/form.component.spec.tsx +7 -6
  30. package/src/components/form/form.component.tsx +2 -1
  31. package/src/components/form/form.stories.tsx +118 -76
  32. package/src/components/form/useForm.hook.ts +47 -22
  33. package/src/components/form-access/formAccess.component.tsx +2 -1
  34. package/src/components/form-access/formAccess.schema.ts +1 -0
  35. package/src/components/form-access/formAccess.stories.tsx +1 -0
  36. package/src/components/form-access/formAccess.utils.ts +9 -8
  37. package/src/components/form-action/formAction.component.tsx +4 -3
  38. package/src/components/form-action/formAction.stories.tsx +225 -227
  39. package/src/components/form-builder/formBuilder.component.tsx +1 -0
  40. package/src/components/form-builder/formBuilder.stories.tsx +1 -0
  41. package/src/components/form-control/formControl.component.spec.tsx +76 -0
  42. package/src/components/form-control/formControl.component.tsx +15 -7
  43. package/src/components/form-control/formControl.stories.tsx +65 -0
  44. package/src/components/form-edit/formCtas.component.tsx +25 -26
  45. package/src/components/form-edit/formEdit.component.tsx +1 -0
  46. package/src/components/form-edit/formEdit.reducer.ts +1 -0
  47. package/src/components/form-edit/formEdit.stories.tsx +1 -0
  48. package/src/components/form-edit/formParameters.component.tsx +1 -0
  49. package/src/components/form-edit/useFormEdit.hook.ts +1 -0
  50. package/src/components/form-settings/formSettings.component.spec.tsx +7 -6
  51. package/src/components/form-settings/formSettings.component.tsx +12 -14
  52. package/src/components/form-settings/formSettings.stories.tsx +1 -0
  53. package/src/components/form-settings/formSettings.utils.ts +1 -0
  54. package/src/components/forms-table/components/formCell.component.tsx +1 -0
  55. package/src/components/forms-table/formsTable.component.tsx +23 -25
  56. package/src/components/forms-table/formsTable.stories.tsx +1 -0
  57. package/src/components/index.ts +4 -2
  58. package/src/components/input-tags/inputTags.component.tsx +5 -4
  59. package/src/components/input-tags/inputTags.stories.tsx +1 -0
  60. package/src/components/input-text/inputText.component.spec.tsx +12 -11
  61. package/src/components/input-text/inputText.component.tsx +1 -0
  62. package/src/components/input-text/inputText.stories.tsx +1 -0
  63. package/src/components/loader/loader.component.spec.tsx +6 -5
  64. package/src/components/loader/loader.component.tsx +1 -0
  65. package/src/components/loader/loader.stories.tsx +1 -0
  66. package/src/components/modal/modal.component.spec.tsx +36 -33
  67. package/src/components/modal/modal.component.tsx +1 -1
  68. package/src/components/modal/modal.stories.tsx +1 -0
  69. package/src/components/modal/removeModal.component.tsx +1 -0
  70. package/src/components/pagination/pagination.component.spec.tsx +24 -21
  71. package/src/components/pagination/pagination.component.tsx +1 -0
  72. package/src/components/pagination/pagination.stories.tsx +1 -0
  73. package/src/components/react-component/reactComponent.component.tsx +3 -2
  74. package/src/components/select/select.component.spec.tsx +17 -18
  75. package/src/components/select/select.component.tsx +1 -0
  76. package/src/components/select/select.stories.tsx +1 -0
  77. package/src/components/submissions-table/submissionsTable.component.tsx +6 -5
  78. package/src/components/submissions-table/submissionsTable.stories.tsx +1 -0
  79. package/src/components/table/components/defaultArrowSort.component.tsx +1 -0
  80. package/src/components/table/components/defaultCellHeader.component.tsx +1 -1
  81. package/src/components/table/components/defaultCellOperations.component.tsx +1 -0
  82. package/src/components/table/components/defaultOperationButton.component.tsx +1 -0
  83. package/src/components/table/filters/defaultColumnFilter.component.spec.tsx +5 -3
  84. package/src/components/table/filters/defaultColumnFilter.component.tsx +1 -0
  85. package/src/components/table/filters/selectColumnFilter.component.spec.tsx +9 -7
  86. package/src/components/table/filters/selectColumnFilter.component.tsx +1 -0
  87. package/src/components/table/index.ts +1 -1
  88. package/src/components/table/table.component.tsx +45 -58
  89. package/src/components/table/table.stories.tsx +2 -1
  90. package/src/components/table/utils/mapFormToColumns.tsx +2 -1
  91. package/src/components/table/utils/useOperations.hook.tsx +1 -0
  92. package/src/components/tabs/tabs.component.spec.tsx +6 -5
  93. package/src/components/tabs/tabs.component.stories.tsx +1 -0
  94. package/src/components/tabs/tabs.component.tsx +10 -4
  95. package/src/index.ts +3 -5
  96. package/src/interfaces/Operation.ts +1 -0
  97. package/src/stores/action/action.actions.spec.ts +1 -0
  98. package/src/stores/action/action.actions.ts +1 -0
  99. package/src/stores/action/action.reducers.ts +1 -1
  100. package/src/stores/action-info/action-info.actions.spec.ts +1 -0
  101. package/src/stores/action-info/action-info.actions.ts +2 -1
  102. package/src/stores/action-info/action-info.reducers.ts +2 -1
  103. package/src/stores/action-info/action-info.selectors.ts +2 -1
  104. package/src/stores/actions/actions.actions.spec.ts +1 -0
  105. package/src/stores/actions/actions.actions.ts +1 -0
  106. package/src/stores/actions/actions.reducers.ts +1 -0
  107. package/src/stores/actions/index.ts +1 -1
  108. package/src/stores/auth/auth.actions.ts +1 -0
  109. package/src/stores/auth/auth.reducers.ts +1 -0
  110. package/src/stores/auth/auth.selectors.ts +1 -0
  111. package/src/stores/auth/auth.utils.tsx +2 -1
  112. package/src/stores/auth/getAccess.action.spec.ts +1 -0
  113. package/src/stores/auth/getAccess.action.ts +1 -0
  114. package/src/stores/auth/getProjectAccess.action.ts +1 -0
  115. package/src/stores/auth/index.ts +4 -4
  116. package/src/stores/auth/initAuth.action.spec.ts +1 -0
  117. package/src/stores/auth/initAuth.action.ts +1 -0
  118. package/src/stores/auth/logout.action.spec.ts +2 -1
  119. package/src/stores/auth/logout.action.ts +1 -0
  120. package/src/stores/auth/setUser.action.spec.ts +1 -0
  121. package/src/stores/auth/setUser.action.ts +1 -0
  122. package/src/stores/form/form.actions.spec.ts +1 -0
  123. package/src/stores/form/form.actions.ts +1 -0
  124. package/src/stores/form/form.reducers.ts +1 -0
  125. package/src/stores/forms/forms.actions.spec.ts +1 -0
  126. package/src/stores/forms/forms.actions.ts +1 -0
  127. package/src/stores/forms/forms.reducers.ts +1 -0
  128. package/src/stores/index.ts +3 -2
  129. package/src/stores/root/root.selectors.ts +1 -1
  130. package/src/stores/submission/submission.actions.spec.ts +1 -0
  131. package/src/stores/submission/submission.actions.ts +1 -0
  132. package/src/stores/submission/submission.reducers.ts +1 -0
  133. package/src/stores/submissions/submissions.actions.spec.ts +1 -0
  134. package/src/stores/submissions/submissions.actions.ts +1 -0
  135. 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
- import {callLast} from "../../utils/callLast";
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: any;
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: Form) => void;
59
+ onFormReady?: (formio: any) => void;
57
60
  }
58
61
 
59
- function useDebounce(event: string, callback: any, events: Map<string, any>) {
62
+ function useEvent(event: string, callback: any, events: Map<string, any>) {
60
63
  useEffect(() => {
61
- callback && events.set(event, callLast(callback, 100));
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
- useDebounce("onChange", funcs.onChange, events.current);
79
-
80
- return {events, emit, hasEvent};
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
- if (isEqual(get(submission, "data"), args[0].data)) {
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,4 +1,5 @@
1
1
  import { ExtendedComponentSchema } from "formiojs";
2
+
2
3
  import { FormSchema } from "../../interfaces/FormSchema";
3
4
 
4
5
  export function getRoleComponent({ label, key, description, choices, data }: any): ExtendedComponentSchema {
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+
2
3
  import { FormAccess } from "./formAccess.component";
3
4
 
4
5
  export default {
@@ -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
- import {FormSchema, Submission} from "../../interfaces";
6
- import {RoleSchema} from "../../interfaces/RoleSchema";
7
- import {getAccessPermissionForm, getSubmissionPermissionForm} from "./formAccess.schema";
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, useMemo } from "react";
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 } = useMemo(() => {
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
- }, [props.submission, actionInfo.settingsForm]);
47
+ })();
47
48
 
48
49
  return (
49
50
  <div>