@tsed/react-formio 3.0.0-alpha.11 → 3.0.0-alpha.13

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 (228) hide show
  1. package/dist/all.d.ts +0 -0
  2. package/dist/all.js +38 -0
  3. package/dist/all.js.map +1 -0
  4. package/dist/atoms/icon/Icon.js.map +1 -1
  5. package/dist/chunks/_commonjsHelpers.js +30 -3
  6. package/dist/chunks/_commonjsHelpers.js.map +1 -1
  7. package/dist/chunks/index.js +33 -30
  8. package/dist/chunks/index.js.map +1 -1
  9. package/dist/chunks/index.module.js +16 -16
  10. package/dist/chunks/index.module.js.map +1 -1
  11. package/dist/chunks/index2.js +56953 -0
  12. package/dist/chunks/index2.js.map +1 -0
  13. package/dist/chunks/react-select-animated.esm.js +1204 -1101
  14. package/dist/chunks/react-select-animated.esm.js.map +1 -1
  15. package/dist/contexts/FormioContext.d.ts +20 -0
  16. package/dist/contexts/FormioContext.js +40 -0
  17. package/dist/contexts/FormioContext.js.map +1 -0
  18. package/dist/hooks/keyboard.constants.js.map +1 -1
  19. package/dist/hooks/useFormioContext.d.ts +10 -0
  20. package/dist/hooks/useFormioContext.js +12 -0
  21. package/dist/hooks/useFormioContext.js.map +1 -0
  22. package/dist/hooks/useI18n.d.ts +4 -0
  23. package/dist/hooks/useI18n.js +9 -0
  24. package/dist/hooks/useI18n.js.map +1 -0
  25. package/dist/hooks/useKeyboardControls.js.map +1 -1
  26. package/dist/hooks/useTooltip.js.map +1 -1
  27. package/dist/index.d.ts +1 -6
  28. package/dist/index.js +18 -13
  29. package/dist/index.js.map +1 -1
  30. package/dist/interfaces/ComponentType.d.ts +6 -2
  31. package/dist/interfaces/FormBuilderOptions.d.ts +7 -0
  32. package/dist/interfaces/FormBuilderOptions.js +2 -0
  33. package/dist/interfaces/FormBuilderOptions.js.map +1 -0
  34. package/dist/interfaces/FormOptions.d.ts +6 -13
  35. package/dist/interfaces/FormType.d.ts +4 -11
  36. package/dist/interfaces/SubmissionType.d.ts +5 -10
  37. package/dist/interfaces/index.d.ts +1 -0
  38. package/dist/molecules/alert/Alert.js.map +1 -1
  39. package/dist/molecules/button/Button.js +17 -20
  40. package/dist/molecules/button/Button.js.map +1 -1
  41. package/dist/molecules/card/Card.js.map +1 -1
  42. package/dist/molecules/forms/form-control/FormControl.js.map +1 -1
  43. package/dist/molecules/forms/input-tags/InputTags.js.map +1 -1
  44. package/dist/molecules/forms/input-tags/components/ChoicesTags.d.ts +19 -19
  45. package/dist/molecules/forms/input-tags/components/ChoicesTags.js +32 -32
  46. package/dist/molecules/forms/input-tags/components/ChoicesTags.js.map +1 -1
  47. package/dist/molecules/forms/input-tags/components/ReactTags.js +289 -300
  48. package/dist/molecules/forms/input-tags/components/ReactTags.js.map +1 -1
  49. package/dist/molecules/forms/input-text/InputText.js +3 -3
  50. package/dist/molecules/forms/input-text/InputText.js.map +1 -1
  51. package/dist/molecules/forms/select/Select.js.map +1 -1
  52. package/dist/molecules/forms/select/components/ChoicesSelect.js +71 -73
  53. package/dist/molecules/forms/select/components/ChoicesSelect.js.map +1 -1
  54. package/dist/molecules/forms/select/components/HtmlSelect.js.map +1 -1
  55. package/dist/molecules/forms/select/components/ReactSelect.js +13 -14
  56. package/dist/molecules/forms/select/components/ReactSelect.js.map +1 -1
  57. package/dist/molecules/forms/select/components/choices.template.js +2340 -2257
  58. package/dist/molecules/forms/select/components/choices.template.js.map +1 -1
  59. package/dist/molecules/forms/select/hooks/useOptions.js.map +1 -1
  60. package/dist/molecules/loader/Loader.js.map +1 -1
  61. package/dist/molecules/modal/Modal.js +23 -24
  62. package/dist/molecules/modal/Modal.js.map +1 -1
  63. package/dist/molecules/pagination/Pagination.d.ts +2 -1
  64. package/dist/molecules/pagination/Pagination.js +29 -29
  65. package/dist/molecules/pagination/Pagination.js.map +1 -1
  66. package/dist/molecules/pagination/PaginationButton.js.map +1 -1
  67. package/dist/molecules/pagination/utils/getPageNumbers.js.map +1 -1
  68. package/dist/molecules/table/Table.js +35 -41
  69. package/dist/molecules/table/Table.js.map +1 -1
  70. package/dist/molecules/table/components/DefaultArrowSort.js.map +1 -1
  71. package/dist/molecules/table/components/DefaultCell.js.map +1 -1
  72. package/dist/molecules/table/components/DefaultCellFooter.js.map +1 -1
  73. package/dist/molecules/table/components/DefaultCellHeader.js.map +1 -1
  74. package/dist/molecules/table/components/DefaultCellOperations.js +10 -10
  75. package/dist/molecules/table/components/DefaultCellOperations.js.map +1 -1
  76. package/dist/molecules/table/components/DefaultFilter.js.map +1 -1
  77. package/dist/molecules/table/components/DefaultOperationButton.js +1 -1
  78. package/dist/molecules/table/components/DefaultOperationButton.js.map +1 -1
  79. package/dist/molecules/table/filters/RangeFilter.js +23 -24
  80. package/dist/molecules/table/filters/RangeFilter.js.map +1 -1
  81. package/dist/molecules/table/filters/SelectFilter.js +11 -13
  82. package/dist/molecules/table/filters/SelectFilter.js.map +1 -1
  83. package/dist/molecules/table/filters/TextFieldFilter.js.map +1 -1
  84. package/dist/molecules/table/hooks/useTable.d.ts +3 -3
  85. package/dist/molecules/table/hooks/useTable.js +17 -16
  86. package/dist/molecules/table/hooks/useTable.js.map +1 -1
  87. package/dist/molecules/table/hooks/useUniqValues.js.map +1 -1
  88. package/dist/molecules/table/utils/mapFormToColumns.js +21 -22
  89. package/dist/molecules/table/utils/mapFormToColumns.js.map +1 -1
  90. package/dist/molecules/tabs/Tab.js +36 -37
  91. package/dist/molecules/tabs/Tab.js.map +1 -1
  92. package/dist/molecules/tabs/TabList.js +9 -10
  93. package/dist/molecules/tabs/TabList.js.map +1 -1
  94. package/dist/molecules/tabs/TabPanel.js.map +1 -1
  95. package/dist/molecules/tabs/Tabs.js.map +1 -1
  96. package/dist/molecules/tabs/TabsBody.js.map +1 -1
  97. package/dist/molecules/tabs/TabsLegacy.d.ts +3 -2
  98. package/dist/molecules/tabs/TabsLegacy.js +30 -30
  99. package/dist/molecules/tabs/TabsLegacy.js.map +1 -1
  100. package/dist/molecules/tabs/context/TabControl.js.map +1 -1
  101. package/dist/molecules/tabs/hooks/tabControl.js.map +1 -1
  102. package/dist/organisms/form/Form.js.map +1 -1
  103. package/dist/organisms/form/access/FormAccess.js +41 -41
  104. package/dist/organisms/form/access/FormAccess.js.map +1 -1
  105. package/dist/organisms/form/access/FormAccess.schema.js +1 -0
  106. package/dist/organisms/form/access/FormAccess.schema.js.map +1 -1
  107. package/dist/organisms/form/access/FormAccess.utils.js +2 -2
  108. package/dist/organisms/form/access/FormAccess.utils.js.map +1 -1
  109. package/dist/organisms/form/actions/FormAction.js +15 -13
  110. package/dist/organisms/form/actions/FormAction.js.map +1 -1
  111. package/dist/organisms/form/builder/FormBuilder.js.map +1 -1
  112. package/dist/organisms/form/builder/FormEdit.d.ts +4 -3
  113. package/dist/organisms/form/builder/FormEdit.js +36 -36
  114. package/dist/organisms/form/builder/FormEdit.js.map +1 -1
  115. package/dist/organisms/form/builder/FormEdit.reducer.js.map +1 -1
  116. package/dist/organisms/form/builder/FormEditCtas.d.ts +2 -2
  117. package/dist/organisms/form/builder/FormEditCtas.js +36 -35
  118. package/dist/organisms/form/builder/FormEditCtas.js.map +1 -1
  119. package/dist/organisms/form/builder/FormParameters.js.map +1 -1
  120. package/dist/organisms/form/builder/useFormBuilder.d.ts +4 -4
  121. package/dist/organisms/form/builder/useFormBuilder.js +36 -33
  122. package/dist/organisms/form/builder/useFormBuilder.js.map +1 -1
  123. package/dist/organisms/form/builder/useFormEdit.d.ts +1 -1
  124. package/dist/organisms/form/builder/useFormEdit.js +17 -17
  125. package/dist/organisms/form/builder/useFormEdit.js.map +1 -1
  126. package/dist/organisms/form/exports/FormExport.d.ts +3 -2
  127. package/dist/organisms/form/exports/FormExport.js +23 -22
  128. package/dist/organisms/form/exports/FormExport.js.map +1 -1
  129. package/dist/organisms/form/preview/FormPreview.d.ts +3 -3
  130. package/dist/organisms/form/preview/FormPreview.js +5 -4
  131. package/dist/organisms/form/preview/FormPreview.js.map +1 -1
  132. package/dist/organisms/form/settings/FormSettings.js +28 -28
  133. package/dist/organisms/form/settings/FormSettings.js.map +1 -1
  134. package/dist/organisms/form/settings/FormSettings.schema.js.map +1 -1
  135. package/dist/organisms/form/settings/FormSettings.utils.js.map +1 -1
  136. package/dist/organisms/form/useForm.d.ts +2 -1
  137. package/dist/organisms/form/useForm.js +664 -661
  138. package/dist/organisms/form/useForm.js.map +1 -1
  139. package/dist/organisms/modal/RemoveModal.js +16 -17
  140. package/dist/organisms/modal/RemoveModal.js.map +1 -1
  141. package/dist/organisms/table/actions/ActionsTable.d.ts +2 -1
  142. package/dist/organisms/table/actions/ActionsTable.js +10 -9
  143. package/dist/organisms/table/actions/ActionsTable.js.map +1 -1
  144. package/dist/organisms/table/forms/FormsTable.d.ts +1 -1
  145. package/dist/organisms/table/forms/FormsTable.js +9 -8
  146. package/dist/organisms/table/forms/FormsTable.js.map +1 -1
  147. package/dist/organisms/table/forms/components/FormsCell.js +10 -10
  148. package/dist/organisms/table/forms/components/FormsCell.js.map +1 -1
  149. package/dist/organisms/table/submissions/SubmissionsTable.js.map +1 -1
  150. package/dist/organisms/views/FormViews.d.ts +3 -3
  151. package/dist/organisms/views/FormViews.js +47 -46
  152. package/dist/organisms/views/FormViews.js.map +1 -1
  153. package/dist/registries/components.js.map +1 -1
  154. package/dist/utils/getEventValue.js.map +1 -1
  155. package/dist/utils/iconClass.js +4 -5
  156. package/dist/utils/iconClass.js.map +1 -1
  157. package/dist/utils/mapPagination.js.map +1 -1
  158. package/dist/utils/stopPropagationWrapper.js.map +1 -1
  159. package/package.json +7 -7
  160. package/src/all.ts +34 -0
  161. package/src/atoms/icon/Icon.stories.tsx +1 -1
  162. package/src/contexts/FormioContext.tsx +96 -0
  163. package/src/hooks/useFormioContext.ts +13 -0
  164. package/src/hooks/useI18n.ts +9 -0
  165. package/src/index.ts +17 -13
  166. package/src/interfaces/ComponentType.ts +2 -2
  167. package/src/interfaces/FormBuilderOptions.ts +9 -0
  168. package/src/interfaces/FormOptions.ts +7 -13
  169. package/src/interfaces/FormType.ts +5 -11
  170. package/src/interfaces/SubmissionType.ts +9 -8
  171. package/src/interfaces/index.ts +1 -0
  172. package/src/molecules/button/Button.stories.tsx +1 -1
  173. package/src/molecules/forms/form-control/FormControl.spec.tsx +5 -2
  174. package/src/molecules/forms/form-control/FormControl.stories.tsx +1 -1
  175. package/src/molecules/forms/input-tags/components/ChoicesTags.stories.tsx +1 -1
  176. package/src/molecules/forms/input-tags/components/ChoicesTags.tsx +4 -4
  177. package/src/molecules/forms/input-tags/components/ReactTags.stories.tsx +1 -1
  178. package/src/molecules/forms/input-text/InputText.stories.tsx +2 -2
  179. package/src/molecules/forms/select/components/ChoicesSelect.stories.tsx +2 -2
  180. package/src/molecules/forms/select/components/ChoicesSelect.tsx +2 -2
  181. package/src/molecules/forms/select/components/HtmlSelect.stories.tsx +2 -2
  182. package/src/molecules/forms/select/components/ReactSelect.stories.tsx +2 -2
  183. package/src/molecules/loader/Loader.stories.tsx +1 -1
  184. package/src/molecules/modal/Modal.stories.tsx +1 -1
  185. package/src/molecules/pagination/Pagination.stories.tsx +1 -1
  186. package/src/molecules/pagination/Pagination.tsx +10 -10
  187. package/src/molecules/table/Table.stories.tsx +8 -8
  188. package/src/molecules/table/Table.tsx +1 -1
  189. package/src/molecules/table/filters/SelectFilter.tsx +1 -1
  190. package/src/molecules/table/hooks/useTable.tsx +7 -6
  191. package/src/molecules/table/utils/mapFormToColumns.tsx +6 -5
  192. package/src/molecules/tabs/Tabs.stories.tsx +2 -2
  193. package/src/molecules/tabs/TabsLegacy.stories.tsx +2 -2
  194. package/src/molecules/tabs/TabsLegacy.tsx +5 -3
  195. package/src/organisms/form/Form.stories.tsx +98 -118
  196. package/src/organisms/form/access/FormAccess.schema.ts +1 -0
  197. package/src/organisms/form/access/FormAccess.stories.tsx +5 -3
  198. package/src/organisms/form/actions/FormAction.stories.tsx +6 -2
  199. package/src/organisms/form/actions/FormAction.tsx +2 -2
  200. package/src/organisms/form/builder/FormBuilder.stories.tsx +4 -1
  201. package/src/organisms/form/builder/FormEdit.stories.tsx +11 -7
  202. package/src/organisms/form/builder/FormEdit.tsx +6 -6
  203. package/src/organisms/form/builder/FormEditCtas.tsx +10 -10
  204. package/src/organisms/form/builder/useFormBuilder.ts +12 -7
  205. package/src/organisms/form/exports/FormExport.stories.tsx +9 -12
  206. package/src/organisms/form/exports/FormExport.tsx +12 -9
  207. package/src/organisms/form/preview/FormPreview.stories.tsx +7 -10
  208. package/src/organisms/form/preview/FormPreview.tsx +7 -5
  209. package/src/organisms/form/settings/FormSettings.component.spec.tsx +3 -1
  210. package/src/organisms/form/settings/FormSettings.stories.tsx +1 -1
  211. package/src/organisms/form/settings/FormSettings.tsx +6 -6
  212. package/src/organisms/form/useForm.ts +2 -3
  213. package/src/organisms/modal/RemoveModal.stories.tsx +1 -1
  214. package/src/organisms/table/actions/ActionsTable.stories.tsx +2 -2
  215. package/src/organisms/table/actions/ActionsTable.tsx +7 -5
  216. package/src/organisms/table/forms/FormsTable.tsx +6 -5
  217. package/src/organisms/table/submissions/SubmissionsTable.stories.tsx +11 -14
  218. package/src/organisms/views/FormViews.stories.tsx +14 -17
  219. package/src/organisms/views/FormViews.tsx +18 -16
  220. package/src/utils/iconClass.ts +1 -3
  221. package/vite.config.mts +2 -2
  222. package/dist/typings.d.js +0 -2
  223. package/dist/typings.d.js.map +0 -1
  224. package/src/typings.d.ts +0 -3
  225. package/tsconfig.app.json +0 -11
  226. package/tsconfig.json +0 -21
  227. package/tsconfig.node.json +0 -13
  228. package/tsconfig.spec.json +0 -14
@@ -0,0 +1,96 @@
1
+ import { Formio as ImportedFormio } from "@formio/js";
2
+ import { createContext, useEffect, useState } from "react";
3
+
4
+ type BaseConfigurationArgs = {
5
+ baseUrl?: string;
6
+ projectUrl?: string;
7
+ Formio?: typeof ImportedFormio;
8
+ };
9
+
10
+ const useBaseConfiguration = ({ baseUrl, projectUrl, Formio }: BaseConfigurationArgs) => {
11
+ if (!Formio) {
12
+ if (baseUrl) {
13
+ ImportedFormio.setBaseUrl(baseUrl);
14
+ }
15
+ if (projectUrl) {
16
+ ImportedFormio.setProjectUrl(projectUrl);
17
+ }
18
+ return {
19
+ Formio: ImportedFormio,
20
+ baseUrl: ImportedFormio.baseUrl,
21
+ projectUrl: ImportedFormio.projectUrl
22
+ };
23
+ }
24
+
25
+ if (baseUrl) {
26
+ Formio.setBaseUrl(baseUrl);
27
+ }
28
+ if (projectUrl) {
29
+ Formio.setProjectUrl(projectUrl);
30
+ }
31
+
32
+ return {
33
+ Formio,
34
+ baseUrl: Formio.baseUrl,
35
+ projectUrl: Formio.projectUrl
36
+ };
37
+ };
38
+
39
+ const useAuthentication = ({ Formio }: { Formio: typeof ImportedFormio }) => {
40
+ const [token, setToken] = useState(Formio.getToken() || null);
41
+ const [isAuthenticated, setIsAuthenticated] = useState(!!token);
42
+
43
+ useEffect(() => {
44
+ const handleUserEvent = async (user: unknown) => {
45
+ if (user) {
46
+ setToken(Formio.getToken());
47
+ setIsAuthenticated(true);
48
+ } else if (isAuthenticated) {
49
+ await Formio.logout();
50
+ setToken(null);
51
+ setIsAuthenticated(false);
52
+ }
53
+ };
54
+
55
+ const handleStaleToken = async () => {
56
+ if (isAuthenticated) {
57
+ const user = await Formio.currentUser();
58
+ if (!user) {
59
+ setToken(null);
60
+ setIsAuthenticated(false);
61
+ }
62
+ }
63
+ };
64
+
65
+ Formio.events.on("formio.user", handleUserEvent);
66
+ handleStaleToken();
67
+
68
+ return () => {
69
+ Formio.events.off("formio.user", handleUserEvent);
70
+ };
71
+ }, [isAuthenticated, Formio]);
72
+
73
+ const logout = async () => {
74
+ await Formio.logout();
75
+ setToken(null);
76
+ setIsAuthenticated(false);
77
+ };
78
+
79
+ return { token, setToken, isAuthenticated, logout };
80
+ };
81
+
82
+ export const FormioContext = createContext<(ReturnType<typeof useBaseConfiguration> & ReturnType<typeof useAuthentication>) | null>(null);
83
+
84
+ export function FormioProvider({
85
+ children,
86
+ baseUrl,
87
+ projectUrl,
88
+ Formio
89
+ }: {
90
+ children: React.ReactNode;
91
+ } & BaseConfigurationArgs) {
92
+ const baseConfig = useBaseConfiguration({ baseUrl, projectUrl, Formio });
93
+ const auth = useAuthentication({ Formio: baseConfig.Formio });
94
+ const formio = { ...baseConfig, ...auth };
95
+ return <FormioContext.Provider value={formio}>{children}</FormioContext.Provider>;
96
+ }
@@ -0,0 +1,13 @@
1
+ import { useContext } from "react";
2
+
3
+ import { FormioContext } from "../contexts/FormioContext";
4
+
5
+ export function useFormioContext() {
6
+ const context = useContext(FormioContext);
7
+
8
+ if (!context) {
9
+ throw new Error("useFormioContext must be used within a FormioProvider component.");
10
+ }
11
+
12
+ return context;
13
+ }
@@ -0,0 +1,9 @@
1
+ import type { FormOptions } from "../interfaces/index.js";
2
+
3
+ export function useI18n(labels?: FormOptions["i18n"]) {
4
+ return {
5
+ t: (key: string, defaultValue: string = key) => {
6
+ return labels?.[key] || defaultValue;
7
+ }
8
+ };
9
+ }
package/src/index.ts CHANGED
@@ -1,15 +1,19 @@
1
- import Webform from "formiojs/Webform";
2
- import WebformBuilder from "formiojs/WebformBuilder";
3
- import Wizard from "formiojs/Wizard";
4
- import WizardBuilder from "formiojs/WizardBuilder";
5
-
1
+ export * from "./interfaces";
6
2
  export {
3
+ Builders,
4
+ Components,
5
+ DefaultEvaluator,
6
+ Displays,
7
+ EventEmitter,
8
+ Form,
9
+ FormBuilder,
10
+ Formio,
11
+ Licenses,
12
+ Providers,
13
+ registerModule,
14
+ Templates,
15
+ useModule,
16
+ Utils,
7
17
  Webform,
8
- WebformBuilder,
9
- Wizard,
10
- WizardBuilder
11
- // editFormUtils,
12
- };
13
-
14
- export * from "./interfaces";
15
- export { Components, Formio, Templates, Utils } from "formiojs";
18
+ Widgets
19
+ } from "@formio/js";
@@ -1,3 +1,3 @@
1
- import { ExtendedComponentSchema } from "formiojs";
1
+ import type { Component } from "@formio/core";
2
2
 
3
- export type ComponentType = ExtendedComponentSchema;
3
+ export type ComponentType = Omit<Component, "components"> & { components?: ComponentType[] } & { title?: string } & Record<string, unknown>;
@@ -0,0 +1,9 @@
1
+ import { FormBuilder } from "@formio/js";
2
+
3
+ import type { FormOptions } from "./FormOptions.js";
4
+
5
+ export type FormBuilderOptions = FormBuilder["options"] & {
6
+ template?: string;
7
+ iconset?: string;
8
+ i18n?: FormOptions["i18n"];
9
+ };
@@ -1,14 +1,8 @@
1
- import type { EventEmitter2 } from "eventemitter2";
1
+ import { EventEmitter, Form } from "@formio/js";
2
2
 
3
- export interface FormOptions {
4
- iconset?: string;
5
- readOnly?: boolean;
6
- noAlerts?: boolean;
7
- i18n?: (f: string) => string;
8
- template?: string;
9
- saveDraft?: boolean;
10
- events?: EventEmitter2;
11
- hooks?: {
12
- customValidation?: Function;
13
- };
14
- }
3
+ import type { FormType } from "./FormType.js";
4
+
5
+ export type FormOptions = Form["options"] & {
6
+ events?: EventEmitter;
7
+ currentForm?: FormType;
8
+ };
@@ -1,13 +1,7 @@
1
- import type { ComponentType } from "./ComponentType";
1
+ import type { Form } from "@formio/core";
2
2
 
3
- export type FormType = {
4
- _id?: string;
5
- title?: string;
6
- name?: string;
7
- machineName?: string;
3
+ import type { ComponentType } from "./ComponentType.js";
4
+
5
+ export type FormType = Omit<Form, "components"> & {
8
6
  components: ComponentType[];
9
- tags?: string[];
10
- action?: string;
11
- properties?: Record<string, any>;
12
- [key: string]: any;
13
- };
7
+ } & Record<string, unknown>;
@@ -1,18 +1,19 @@
1
- import type { ComponentType } from "./ComponentType";
1
+ import type { Component, Submission } from "@formio/core";
2
2
 
3
3
  export type JSON = unknown | string | number | boolean | null | undefined | JSON[] | { [key: string]: JSON };
4
4
 
5
- export interface SubmissionType<Data extends { [key: string]: JSON } = { [key: string]: JSON }> extends Record<string, JSON> {
6
- _id?: string;
5
+ export type SubmissionType<Data extends { [key: string]: JSON } = { [key: string]: JSON }> = Omit<Partial<Submission>, "data"> & {
7
6
  data: Data;
8
- metadata?: { [key: string]: JSON };
9
- state?: string;
10
- }
7
+ };
11
8
 
12
- export interface ChangedSubmission<Data extends { [key: string]: JSON } = { [key: string]: JSON }> extends SubmissionType<Data> {
9
+ export interface ChangedSubmission<
10
+ Data extends { [key: string]: JSON } = {
11
+ [key: string]: JSON;
12
+ }
13
+ > extends SubmissionType<Data> {
13
14
  data: Data;
14
15
  changed?: {
15
- component: ComponentType;
16
+ component: Component;
16
17
  instance: any;
17
18
  value: unknown;
18
19
  } & Record<string, JSON>;
@@ -1,6 +1,7 @@
1
1
  export * from "./ActionType";
2
2
  export * from "./ColumnIdentifier";
3
3
  export * from "./ComponentType";
4
+ export * from "./FormBuilderOptions";
4
5
  export * from "./FormOptions";
5
6
  export * from "./FormType";
6
7
  export * from "./Operation";
@@ -1,4 +1,4 @@
1
- import { Meta, StoryObj } from "@storybook/react";
1
+ import { Meta, StoryObj } from "@storybook/react-vite";
2
2
 
3
3
  import { Icon } from "../../atoms/icon/Icon";
4
4
  import { Button, BUTTON_VARIANTS } from "./Button";
@@ -1,9 +1,12 @@
1
+ import { Formio } from "@formio/js";
1
2
  import { render, screen } from "@testing-library/react";
2
3
 
3
4
  import { iconClass } from "../../../utils/iconClass";
4
5
  import { FormControl } from "./FormControl";
5
6
  import { Sandbox } from "./FormControl.stories";
6
7
 
8
+ Formio.setProjectUrl("https://api.form.io");
9
+
7
10
  describe("form-control", () => {
8
11
  it("should display form control component", () => {
9
12
  render(<FormControl {...Sandbox.args} name='test' />);
@@ -34,7 +37,7 @@ describe("form-control", () => {
34
37
  });
35
38
 
36
39
  it("should display prefix", () => {
37
- const fontAwsomeCalendarIcon = "fa fa-calendar";
40
+ const fontAwsomeCalendarIcon = "bi bi-calendar";
38
41
  const prefix = (<i className={iconClass(undefined, "calendar")} />) as JSX.Element;
39
42
  render(<FormControl {...Sandbox.args} name='testPrefix' before={prefix} />);
40
43
 
@@ -48,7 +51,7 @@ describe("form-control", () => {
48
51
  });
49
52
 
50
53
  it("should display suffix", () => {
51
- const fontAwsomeCalendarIcon = "fa fa-calendar";
54
+ const fontAwsomeCalendarIcon = "bi bi-calendar";
52
55
  const suffix = (<i className={iconClass(undefined, "calendar")} />) as JSX.Element;
53
56
  render(<FormControl {...Sandbox.args} name='testSuffix' after={suffix} />);
54
57
 
@@ -1,4 +1,4 @@
1
- import { Meta, StoryObj } from "@storybook/react";
1
+ import { Meta, StoryObj } from "@storybook/react-vite";
2
2
 
3
3
  import { iconClass } from "../../../utils/iconClass";
4
4
  import { FormControl } from "./FormControl";
@@ -1,6 +1,6 @@
1
1
  import "../all";
2
2
 
3
- import type { Meta, StoryObj } from "@storybook/react";
3
+ import type { Meta, StoryObj } from "@storybook/react-vite";
4
4
 
5
5
  import { iconClass } from "../../../../utils/iconClass";
6
6
  import { useValue } from "../../../__fixtures__/useValue.hook";
@@ -37,12 +37,12 @@ export function useChoiceTags<Data = string>(props: InputTagsProps<Data>) {
37
37
 
38
38
  instanceRef.current = instance;
39
39
 
40
- instance.passedElement.element.addEventListener("addItem", (event: { detail: { value: unknown } }) => {
41
- onAdd(event.detail.value as Data);
40
+ instance.passedElement.element.addEventListener("addItem", (event) => {
41
+ onAdd((event.target as any).value as Data);
42
42
  });
43
43
 
44
- instance.passedElement.element.addEventListener("removeItem", (event: { detail: { value: unknown } }) => {
45
- onDelete(event.detail.value as Data);
44
+ instance.passedElement.element.addEventListener("removeItem", (event) => {
45
+ onDelete((event.target as any).value as Data);
46
46
  });
47
47
  }
48
48
 
@@ -1,6 +1,6 @@
1
1
  import "../all";
2
2
 
3
- import type { Meta, StoryObj } from "@storybook/react";
3
+ import type { Meta, StoryObj } from "@storybook/react-vite";
4
4
  import { type CreatableProps } from "react-select/creatable";
5
5
 
6
6
  import { iconClass } from "../../../../utils/iconClass";
@@ -1,5 +1,5 @@
1
- import type { Meta, StoryObj } from "@storybook/react";
2
- import { expect, userEvent, within } from "@storybook/test";
1
+ import type { Meta, StoryObj } from "@storybook/react-vite";
2
+ import { expect, userEvent, within } from "storybook/test";
3
3
 
4
4
  import { iconClass } from "../../../utils/iconClass";
5
5
  import { useValue } from "../../__fixtures__/useValue.hook";
@@ -1,7 +1,7 @@
1
1
  import "./ChoicesSelect";
2
2
 
3
- import { Meta, StoryObj } from "@storybook/react";
4
- import { fn } from "@storybook/test";
3
+ import { Meta, StoryObj } from "@storybook/react-vite";
4
+ import { fn } from "storybook/test";
5
5
 
6
6
  import { iconClass } from "../../../../utils/iconClass";
7
7
  import { useValue } from "../../../__fixtures__/useValue.hook";
@@ -66,9 +66,9 @@ export function useChoices({
66
66
  if (choicesRef.current) {
67
67
  if (multiple) {
68
68
  choicesRef.current.clearStore();
69
- choicesRef.current.setChoices(opts, "value", "label", true);
69
+ choicesRef.current.setChoices(opts as any, "value", "label", true);
70
70
  } else {
71
- choicesRef.current.setChoices(opts, "value", "label", true);
71
+ choicesRef.current.setChoices(opts as any, "value", "label", true);
72
72
  }
73
73
  }
74
74
  }, [opts]);
@@ -1,7 +1,7 @@
1
1
  import "./HtmlSelect";
2
2
 
3
- import { Meta, StoryObj } from "@storybook/react";
4
- import { expect, fn, userEvent, within } from "@storybook/test";
3
+ import { Meta, StoryObj } from "@storybook/react-vite";
4
+ import { expect, fn, userEvent, within } from "storybook/test";
5
5
 
6
6
  import { iconClass } from "../../../../utils/iconClass";
7
7
  import { useValue } from "../../../__fixtures__/useValue.hook";
@@ -1,7 +1,7 @@
1
1
  import "../all";
2
2
 
3
- import { Meta, StoryObj } from "@storybook/react";
4
- import { fn } from "@storybook/test";
3
+ import { Meta, StoryObj } from "@storybook/react-vite";
4
+ import { fn } from "storybook/test";
5
5
 
6
6
  import { iconClass } from "../../../../utils/iconClass";
7
7
  import { useValue } from "../../../__fixtures__/useValue.hook";
@@ -1,4 +1,4 @@
1
- import type { Meta, StoryObj } from "@storybook/react";
1
+ import type { Meta, StoryObj } from "@storybook/react-vite";
2
2
  import tailwind from "@tsed/tailwind-formio";
3
3
 
4
4
  import { Loader } from "./Loader";
@@ -1,4 +1,4 @@
1
- import { Meta, StoryObj } from "@storybook/react";
1
+ import { Meta, StoryObj } from "@storybook/react-vite";
2
2
 
3
3
  import { Modal, ModalProps, useModal } from "./Modal";
4
4
 
@@ -1,6 +1,6 @@
1
1
  import "../forms/select/all";
2
2
 
3
- import { Meta, StoryObj } from "@storybook/react";
3
+ import { Meta, StoryObj } from "@storybook/react-vite";
4
4
  import { useEffect, useState } from "react";
5
5
 
6
6
  import { Pagination } from "./all";
@@ -1,5 +1,7 @@
1
1
  import classnames from "classnames";
2
2
 
3
+ import { useI18n } from "../../hooks/useI18n.js";
4
+ import type { FormOptions } from "../../interfaces/index.js";
3
5
  import { getComponent, registerComponent } from "../../registries/components";
4
6
  import type { Select as DefaultSelect } from "../forms/select/Select";
5
7
  import type { PaginationButton as DefaultPaginationButton } from "./PaginationButton";
@@ -16,8 +18,7 @@ export interface PaginationProps {
16
18
  pageSize: number;
17
19
  rowCount?: number;
18
20
  layout?: "html5" | "react" | "choicesjs";
19
- i18n?: (f: string) => string;
20
-
21
+ i18n?: FormOptions["i18n"];
21
22
  onPageIndexChange: (pageIndex: number) => void;
22
23
  onClickPreviousPage: () => void;
23
24
  onClickNextPage: () => void;
@@ -38,9 +39,9 @@ export function Pagination(props: PaginationProps) {
38
39
  pageOptions,
39
40
  pageSize,
40
41
  onPageSizeChange,
41
- rowCount,
42
- i18n = (f: string) => f
42
+ rowCount
43
43
  } = props;
44
+ const { t } = useI18n(props.i18n);
44
45
 
45
46
  const pageNumbers = getPageNumbers({
46
47
  currentPage: pageIndex,
@@ -57,7 +58,7 @@ export function Pagination(props: PaginationProps) {
57
58
  <ul className='pagination mb-3 mr-3'>
58
59
  <li className={classnames("page-item", !canPreviousPage && "disabled")}>
59
60
  <PaginationButton tabIndex={-1} disabled={!canPreviousPage} onClick={() => onClickPreviousPage()}>
60
- {i18n("Previous")}
61
+ {t("Previous")}
61
62
  </PaginationButton>
62
63
  </li>
63
64
 
@@ -82,7 +83,7 @@ export function Pagination(props: PaginationProps) {
82
83
 
83
84
  <li className={classnames("page-item", !canNextPage && "disabled")}>
84
85
  <PaginationButton tabIndex={pageNumbers.length} disabled={!canNextPage} onClick={() => onClickNextPage()}>
85
- {i18n("Next")}
86
+ {t("Next")}
86
87
  </PaginationButton>
87
88
  </li>
88
89
  </ul>
@@ -95,15 +96,14 @@ export function Pagination(props: PaginationProps) {
95
96
  multiple={false}
96
97
  layout={props.layout}
97
98
  onChange={(_, value) => {
98
- console.log("On page change", value);
99
99
  onPageSizeChange(+value);
100
100
  }}
101
101
  />
102
- <span className={"ml-3"}>{i18n("items per page")}</span>
102
+ <span className={"ml-3"}>{t("items per page")}</span>
103
103
  </li>
104
104
  {pageOptions && (
105
105
  <li className={"mb-3 mr-3 flex items-center"}>
106
- <span>{i18n("Page")}&nbsp;</span>
106
+ <span>{t("Page")}&nbsp;</span>
107
107
  <strong>
108
108
  {pageIndex + 1} of {pageOptions.length}
109
109
  </strong>
@@ -111,7 +111,7 @@ export function Pagination(props: PaginationProps) {
111
111
  )}
112
112
  {rowCount !== undefined && (
113
113
  <li className={"mb-3 flex items-center"} data-testid='pagination-total-items'>
114
- {i18n("Total")}: <strong className='mx-1'>{new Intl.NumberFormat(undefined).format(rowCount)}</strong> {i18n("items")}
114
+ {t("Total")}: <strong className='mx-1'>{new Intl.NumberFormat(undefined).format(rowCount)}</strong> {t("items")}
115
115
  </li>
116
116
  )}
117
117
  </nav>
@@ -1,7 +1,7 @@
1
1
  import "./all";
2
2
 
3
- import type { Meta, StoryObj } from "@storybook/react";
4
- import { expect, fn, userEvent, waitFor, within } from "@storybook/test";
3
+ import type { Meta, StoryObj } from "@storybook/react-vite";
4
+ import { expect, fn, userEvent, waitFor, within } from "storybook/test";
5
5
 
6
6
  import { SubmissionType } from "../../interfaces";
7
7
  import FormType from "../__fixtures__/form-schema.json";
@@ -73,7 +73,7 @@ type Story = StoryObj<typeof Table<ProductSubmission>>;
73
73
 
74
74
  export const Usage: Story = {
75
75
  args: {
76
- data: formSubmissions as ProductSubmission[],
76
+ data: formSubmissions as unknown as ProductSubmission[],
77
77
  columns: mapFormToColumns(FormType as any),
78
78
  operations: [
79
79
  {
@@ -93,7 +93,7 @@ export const Usage: Story = {
93
93
  }
94
94
  }
95
95
  ],
96
- i18n: (f: string) => f,
96
+ i18n: {},
97
97
  onClick: fn(),
98
98
  onChange: fn()
99
99
  },
@@ -182,7 +182,7 @@ export const Usage: Story = {
182
182
 
183
183
  export const WithFilters: Story = {
184
184
  args: {
185
- data: formSubmissions as ProductSubmission[],
185
+ data: formSubmissions as unknown as ProductSubmission[],
186
186
  columns: mapFormToColumns(FormType as any, [
187
187
  {
188
188
  accessorKey: "data.id",
@@ -212,14 +212,14 @@ export const WithFilters: Story = {
212
212
  }
213
213
  }
214
214
  ],
215
- i18n: (f: string) => f,
215
+ i18n: {},
216
216
  onClick: fn()
217
217
  }
218
218
  };
219
219
 
220
220
  export const WithCustomCell: Story = {
221
221
  args: {
222
- data: formSubmissions as ProductSubmission[],
222
+ data: formSubmissions as unknown as ProductSubmission[],
223
223
  columns: mapFormToColumns<ProductSubmission>(FormType as any, [
224
224
  {
225
225
  accessorKey: "data.id",
@@ -299,7 +299,7 @@ export const WithCustomCell: Story = {
299
299
  }
300
300
  }
301
301
  ],
302
- i18n: (f: string) => f,
302
+ i18n: {},
303
303
  onClick: fn()
304
304
  }
305
305
  };
@@ -90,7 +90,7 @@ export function Table<Data extends { [key: string]: JSON } = { [key: string]: JS
90
90
  pageIndex={pagination.pageIndex}
91
91
  pageSize={pagination.pageSize}
92
92
  pageSizes={props.pageSizes}
93
- i18n={i18n}
93
+ i18n={props.i18n}
94
94
  pageCount={tableInstance.getPageCount()}
95
95
  rowCount={props.rowCount}
96
96
  onPageIndexChange={(page) => tableInstance.setPageIndex(page)}
@@ -9,7 +9,7 @@ export function SelectFilter<Data = any>({ header, options }: FilterProps<Data,
9
9
  const Select = getComponent<typeof DefaultSelect>("Select");
10
10
  const columnFilterValue = header.column.getFilterValue();
11
11
  const uniqValues = useUniqValues<Data>({ header, filterVariant: "text" });
12
- console.log(uniqValues);
12
+
13
13
  const opts =
14
14
  options.layout === "choicesjs"
15
15
  ? {
@@ -12,7 +12,8 @@ import {
12
12
  } from "@tanstack/react-table";
13
13
  import { useEffect } from "react";
14
14
 
15
- import { type JSON, Operation } from "../../../interfaces";
15
+ import { useI18n } from "../../../hooks/useI18n.js";
16
+ import { type FormOptions, type JSON, Operation } from "../../../interfaces";
16
17
  import { getComponent } from "../../../registries/components";
17
18
  import type { DefaultCellOperations } from "../components/DefaultCellOperations";
18
19
 
@@ -20,7 +21,7 @@ export interface UseTableProps<Data extends { [key: string]: JSON } = { [key: st
20
21
  extends Omit<TableOptions<Data>, "getCoreRowModel" | "onClick"> {
21
22
  operations: Operation<Data>[];
22
23
  metadata?: Record<string, unknown>;
23
- i18n?: (i18n: string) => string;
24
+ i18n?: FormOptions["i18n"];
24
25
  onClick?: (data: any, operation: Operation<Data>) => void;
25
26
  manualFaceted?: boolean;
26
27
  onChange?: (query: TableState) => void;
@@ -29,7 +30,7 @@ export interface UseTableProps<Data extends { [key: string]: JSON } = { [key: st
29
30
 
30
31
  export function useTable<Data extends { [key: string]: JSON } = { [key: string]: JSON }>(props: UseTableProps<Data>) {
31
32
  const Operations = getComponent<typeof DefaultCellOperations<Data>>("CellOperations");
32
- const i18n = props.i18n || ((f: string) => f);
33
+ const { t } = useI18n(props.i18n);
33
34
 
34
35
  // const [pagination, setPagination] = useState({
35
36
  // pageIndex: 0, //initial page index
@@ -40,9 +41,9 @@ export function useTable<Data extends { [key: string]: JSON } = { [key: string]:
40
41
  ? ([
41
42
  {
42
43
  id: "operations",
43
- header: i18n("Operations"),
44
+ header: t("Operations"),
44
45
  cell: (info) => (
45
- <Operations info={info} operations={props.operations} metadata={props.metadata} onClick={props.onClick} i18n={i18n} />
46
+ <Operations info={info} operations={props.operations} metadata={props.metadata} onClick={props.onClick} i18n={t} />
46
47
  )
47
48
  }
48
49
  ] satisfies ColumnDef<Data>[])
@@ -69,7 +70,7 @@ export function useTable<Data extends { [key: string]: JSON } = { [key: string]:
69
70
  }, [columnFilters, sorting, pagination, columnOrder, columnPinning, columnSizing, columnSizingInfo, columnVisibility, globalFilter]);
70
71
 
71
72
  return {
72
- i18n,
73
+ i18n: t,
73
74
  tableInstance
74
75
  };
75
76
  }
@@ -1,7 +1,7 @@
1
1
  import "../interfaces/extends";
2
2
 
3
+ import { Components } from "@formio/js";
3
4
  import { ColumnDef, ColumnDefResolved, createColumnHelper } from "@tanstack/react-table";
4
- import { Components } from "formiojs";
5
5
  import cloneDeep from "lodash/cloneDeep";
6
6
  import get from "lodash/get";
7
7
 
@@ -25,14 +25,15 @@ export function mapFormToColumns<Data = any>(form: FormType, columns: ColumnDefR
25
25
  const columnsFromComponents = form.components
26
26
  .flatMap((component) => {
27
27
  if (component.type === "tabs") {
28
- return component.components.flatMap((subComponent: ComponentType) => subComponent.components);
28
+ return component.components?.flatMap((subComponent: ComponentType) => subComponent.components);
29
29
  }
30
30
 
31
31
  return [component];
32
32
  })
33
- .filter((component) => component.tableView)
34
- .map((component: ComponentType) => {
35
- const cmp: any = Components.create(component, {}, null, true);
33
+ .filter((component) => component?.tableView)
34
+ .map((c) => {
35
+ const component = c as ComponentType;
36
+ const cmp: any = Components.create(component, {}, null);
36
37
 
37
38
  const columnIndex = columnsToKeep.findIndex(({ accessorKey }) => {
38
39
  return accessorKey === `data.${component.key}`;