@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.
- package/dist/all.d.ts +0 -0
- package/dist/all.js +38 -0
- package/dist/all.js.map +1 -0
- package/dist/atoms/icon/Icon.js.map +1 -1
- package/dist/chunks/_commonjsHelpers.js +30 -3
- package/dist/chunks/_commonjsHelpers.js.map +1 -1
- package/dist/chunks/index.js +33 -30
- package/dist/chunks/index.js.map +1 -1
- package/dist/chunks/index.module.js +16 -16
- package/dist/chunks/index.module.js.map +1 -1
- package/dist/chunks/index2.js +56953 -0
- package/dist/chunks/index2.js.map +1 -0
- package/dist/chunks/react-select-animated.esm.js +1204 -1101
- package/dist/chunks/react-select-animated.esm.js.map +1 -1
- package/dist/contexts/FormioContext.d.ts +20 -0
- package/dist/contexts/FormioContext.js +40 -0
- package/dist/contexts/FormioContext.js.map +1 -0
- package/dist/hooks/keyboard.constants.js.map +1 -1
- package/dist/hooks/useFormioContext.d.ts +10 -0
- package/dist/hooks/useFormioContext.js +12 -0
- package/dist/hooks/useFormioContext.js.map +1 -0
- package/dist/hooks/useI18n.d.ts +4 -0
- package/dist/hooks/useI18n.js +9 -0
- package/dist/hooks/useI18n.js.map +1 -0
- package/dist/hooks/useKeyboardControls.js.map +1 -1
- package/dist/hooks/useTooltip.js.map +1 -1
- package/dist/index.d.ts +1 -6
- package/dist/index.js +18 -13
- package/dist/index.js.map +1 -1
- package/dist/interfaces/ComponentType.d.ts +6 -2
- package/dist/interfaces/FormBuilderOptions.d.ts +7 -0
- package/dist/interfaces/FormBuilderOptions.js +2 -0
- package/dist/interfaces/FormBuilderOptions.js.map +1 -0
- package/dist/interfaces/FormOptions.d.ts +6 -13
- package/dist/interfaces/FormType.d.ts +4 -11
- package/dist/interfaces/SubmissionType.d.ts +5 -10
- package/dist/interfaces/index.d.ts +1 -0
- package/dist/molecules/alert/Alert.js.map +1 -1
- package/dist/molecules/button/Button.js +17 -20
- package/dist/molecules/button/Button.js.map +1 -1
- package/dist/molecules/card/Card.js.map +1 -1
- package/dist/molecules/forms/form-control/FormControl.js.map +1 -1
- package/dist/molecules/forms/input-tags/InputTags.js.map +1 -1
- package/dist/molecules/forms/input-tags/components/ChoicesTags.d.ts +19 -19
- package/dist/molecules/forms/input-tags/components/ChoicesTags.js +32 -32
- package/dist/molecules/forms/input-tags/components/ChoicesTags.js.map +1 -1
- package/dist/molecules/forms/input-tags/components/ReactTags.js +289 -300
- package/dist/molecules/forms/input-tags/components/ReactTags.js.map +1 -1
- package/dist/molecules/forms/input-text/InputText.js +3 -3
- package/dist/molecules/forms/input-text/InputText.js.map +1 -1
- package/dist/molecules/forms/select/Select.js.map +1 -1
- package/dist/molecules/forms/select/components/ChoicesSelect.js +71 -73
- package/dist/molecules/forms/select/components/ChoicesSelect.js.map +1 -1
- package/dist/molecules/forms/select/components/HtmlSelect.js.map +1 -1
- package/dist/molecules/forms/select/components/ReactSelect.js +13 -14
- package/dist/molecules/forms/select/components/ReactSelect.js.map +1 -1
- package/dist/molecules/forms/select/components/choices.template.js +2340 -2257
- package/dist/molecules/forms/select/components/choices.template.js.map +1 -1
- package/dist/molecules/forms/select/hooks/useOptions.js.map +1 -1
- package/dist/molecules/loader/Loader.js.map +1 -1
- package/dist/molecules/modal/Modal.js +23 -24
- package/dist/molecules/modal/Modal.js.map +1 -1
- package/dist/molecules/pagination/Pagination.d.ts +2 -1
- package/dist/molecules/pagination/Pagination.js +29 -29
- package/dist/molecules/pagination/Pagination.js.map +1 -1
- package/dist/molecules/pagination/PaginationButton.js.map +1 -1
- package/dist/molecules/pagination/utils/getPageNumbers.js.map +1 -1
- package/dist/molecules/table/Table.js +35 -41
- package/dist/molecules/table/Table.js.map +1 -1
- package/dist/molecules/table/components/DefaultArrowSort.js.map +1 -1
- package/dist/molecules/table/components/DefaultCell.js.map +1 -1
- package/dist/molecules/table/components/DefaultCellFooter.js.map +1 -1
- package/dist/molecules/table/components/DefaultCellHeader.js.map +1 -1
- package/dist/molecules/table/components/DefaultCellOperations.js +10 -10
- package/dist/molecules/table/components/DefaultCellOperations.js.map +1 -1
- package/dist/molecules/table/components/DefaultFilter.js.map +1 -1
- package/dist/molecules/table/components/DefaultOperationButton.js +1 -1
- package/dist/molecules/table/components/DefaultOperationButton.js.map +1 -1
- package/dist/molecules/table/filters/RangeFilter.js +23 -24
- package/dist/molecules/table/filters/RangeFilter.js.map +1 -1
- package/dist/molecules/table/filters/SelectFilter.js +11 -13
- package/dist/molecules/table/filters/SelectFilter.js.map +1 -1
- package/dist/molecules/table/filters/TextFieldFilter.js.map +1 -1
- package/dist/molecules/table/hooks/useTable.d.ts +3 -3
- package/dist/molecules/table/hooks/useTable.js +17 -16
- package/dist/molecules/table/hooks/useTable.js.map +1 -1
- package/dist/molecules/table/hooks/useUniqValues.js.map +1 -1
- package/dist/molecules/table/utils/mapFormToColumns.js +21 -22
- package/dist/molecules/table/utils/mapFormToColumns.js.map +1 -1
- package/dist/molecules/tabs/Tab.js +36 -37
- package/dist/molecules/tabs/Tab.js.map +1 -1
- package/dist/molecules/tabs/TabList.js +9 -10
- package/dist/molecules/tabs/TabList.js.map +1 -1
- package/dist/molecules/tabs/TabPanel.js.map +1 -1
- package/dist/molecules/tabs/Tabs.js.map +1 -1
- package/dist/molecules/tabs/TabsBody.js.map +1 -1
- package/dist/molecules/tabs/TabsLegacy.d.ts +3 -2
- package/dist/molecules/tabs/TabsLegacy.js +30 -30
- package/dist/molecules/tabs/TabsLegacy.js.map +1 -1
- package/dist/molecules/tabs/context/TabControl.js.map +1 -1
- package/dist/molecules/tabs/hooks/tabControl.js.map +1 -1
- package/dist/organisms/form/Form.js.map +1 -1
- package/dist/organisms/form/access/FormAccess.js +41 -41
- package/dist/organisms/form/access/FormAccess.js.map +1 -1
- package/dist/organisms/form/access/FormAccess.schema.js +1 -0
- package/dist/organisms/form/access/FormAccess.schema.js.map +1 -1
- package/dist/organisms/form/access/FormAccess.utils.js +2 -2
- package/dist/organisms/form/access/FormAccess.utils.js.map +1 -1
- package/dist/organisms/form/actions/FormAction.js +15 -13
- package/dist/organisms/form/actions/FormAction.js.map +1 -1
- package/dist/organisms/form/builder/FormBuilder.js.map +1 -1
- package/dist/organisms/form/builder/FormEdit.d.ts +4 -3
- package/dist/organisms/form/builder/FormEdit.js +36 -36
- package/dist/organisms/form/builder/FormEdit.js.map +1 -1
- package/dist/organisms/form/builder/FormEdit.reducer.js.map +1 -1
- package/dist/organisms/form/builder/FormEditCtas.d.ts +2 -2
- package/dist/organisms/form/builder/FormEditCtas.js +36 -35
- package/dist/organisms/form/builder/FormEditCtas.js.map +1 -1
- package/dist/organisms/form/builder/FormParameters.js.map +1 -1
- package/dist/organisms/form/builder/useFormBuilder.d.ts +4 -4
- package/dist/organisms/form/builder/useFormBuilder.js +36 -33
- package/dist/organisms/form/builder/useFormBuilder.js.map +1 -1
- package/dist/organisms/form/builder/useFormEdit.d.ts +1 -1
- package/dist/organisms/form/builder/useFormEdit.js +17 -17
- package/dist/organisms/form/builder/useFormEdit.js.map +1 -1
- package/dist/organisms/form/exports/FormExport.d.ts +3 -2
- package/dist/organisms/form/exports/FormExport.js +23 -22
- package/dist/organisms/form/exports/FormExport.js.map +1 -1
- package/dist/organisms/form/preview/FormPreview.d.ts +3 -3
- package/dist/organisms/form/preview/FormPreview.js +5 -4
- package/dist/organisms/form/preview/FormPreview.js.map +1 -1
- package/dist/organisms/form/settings/FormSettings.js +28 -28
- package/dist/organisms/form/settings/FormSettings.js.map +1 -1
- package/dist/organisms/form/settings/FormSettings.schema.js.map +1 -1
- package/dist/organisms/form/settings/FormSettings.utils.js.map +1 -1
- package/dist/organisms/form/useForm.d.ts +2 -1
- package/dist/organisms/form/useForm.js +664 -661
- package/dist/organisms/form/useForm.js.map +1 -1
- package/dist/organisms/modal/RemoveModal.js +16 -17
- package/dist/organisms/modal/RemoveModal.js.map +1 -1
- package/dist/organisms/table/actions/ActionsTable.d.ts +2 -1
- package/dist/organisms/table/actions/ActionsTable.js +10 -9
- package/dist/organisms/table/actions/ActionsTable.js.map +1 -1
- package/dist/organisms/table/forms/FormsTable.d.ts +1 -1
- package/dist/organisms/table/forms/FormsTable.js +9 -8
- package/dist/organisms/table/forms/FormsTable.js.map +1 -1
- package/dist/organisms/table/forms/components/FormsCell.js +10 -10
- package/dist/organisms/table/forms/components/FormsCell.js.map +1 -1
- package/dist/organisms/table/submissions/SubmissionsTable.js.map +1 -1
- package/dist/organisms/views/FormViews.d.ts +3 -3
- package/dist/organisms/views/FormViews.js +47 -46
- package/dist/organisms/views/FormViews.js.map +1 -1
- package/dist/registries/components.js.map +1 -1
- package/dist/utils/getEventValue.js.map +1 -1
- package/dist/utils/iconClass.js +4 -5
- package/dist/utils/iconClass.js.map +1 -1
- package/dist/utils/mapPagination.js.map +1 -1
- package/dist/utils/stopPropagationWrapper.js.map +1 -1
- package/package.json +7 -7
- package/src/all.ts +34 -0
- package/src/atoms/icon/Icon.stories.tsx +1 -1
- package/src/contexts/FormioContext.tsx +96 -0
- package/src/hooks/useFormioContext.ts +13 -0
- package/src/hooks/useI18n.ts +9 -0
- package/src/index.ts +17 -13
- package/src/interfaces/ComponentType.ts +2 -2
- package/src/interfaces/FormBuilderOptions.ts +9 -0
- package/src/interfaces/FormOptions.ts +7 -13
- package/src/interfaces/FormType.ts +5 -11
- package/src/interfaces/SubmissionType.ts +9 -8
- package/src/interfaces/index.ts +1 -0
- package/src/molecules/button/Button.stories.tsx +1 -1
- package/src/molecules/forms/form-control/FormControl.spec.tsx +5 -2
- package/src/molecules/forms/form-control/FormControl.stories.tsx +1 -1
- package/src/molecules/forms/input-tags/components/ChoicesTags.stories.tsx +1 -1
- package/src/molecules/forms/input-tags/components/ChoicesTags.tsx +4 -4
- package/src/molecules/forms/input-tags/components/ReactTags.stories.tsx +1 -1
- package/src/molecules/forms/input-text/InputText.stories.tsx +2 -2
- package/src/molecules/forms/select/components/ChoicesSelect.stories.tsx +2 -2
- package/src/molecules/forms/select/components/ChoicesSelect.tsx +2 -2
- package/src/molecules/forms/select/components/HtmlSelect.stories.tsx +2 -2
- package/src/molecules/forms/select/components/ReactSelect.stories.tsx +2 -2
- package/src/molecules/loader/Loader.stories.tsx +1 -1
- package/src/molecules/modal/Modal.stories.tsx +1 -1
- package/src/molecules/pagination/Pagination.stories.tsx +1 -1
- package/src/molecules/pagination/Pagination.tsx +10 -10
- package/src/molecules/table/Table.stories.tsx +8 -8
- package/src/molecules/table/Table.tsx +1 -1
- package/src/molecules/table/filters/SelectFilter.tsx +1 -1
- package/src/molecules/table/hooks/useTable.tsx +7 -6
- package/src/molecules/table/utils/mapFormToColumns.tsx +6 -5
- package/src/molecules/tabs/Tabs.stories.tsx +2 -2
- package/src/molecules/tabs/TabsLegacy.stories.tsx +2 -2
- package/src/molecules/tabs/TabsLegacy.tsx +5 -3
- package/src/organisms/form/Form.stories.tsx +98 -118
- package/src/organisms/form/access/FormAccess.schema.ts +1 -0
- package/src/organisms/form/access/FormAccess.stories.tsx +5 -3
- package/src/organisms/form/actions/FormAction.stories.tsx +6 -2
- package/src/organisms/form/actions/FormAction.tsx +2 -2
- package/src/organisms/form/builder/FormBuilder.stories.tsx +4 -1
- package/src/organisms/form/builder/FormEdit.stories.tsx +11 -7
- package/src/organisms/form/builder/FormEdit.tsx +6 -6
- package/src/organisms/form/builder/FormEditCtas.tsx +10 -10
- package/src/organisms/form/builder/useFormBuilder.ts +12 -7
- package/src/organisms/form/exports/FormExport.stories.tsx +9 -12
- package/src/organisms/form/exports/FormExport.tsx +12 -9
- package/src/organisms/form/preview/FormPreview.stories.tsx +7 -10
- package/src/organisms/form/preview/FormPreview.tsx +7 -5
- package/src/organisms/form/settings/FormSettings.component.spec.tsx +3 -1
- package/src/organisms/form/settings/FormSettings.stories.tsx +1 -1
- package/src/organisms/form/settings/FormSettings.tsx +6 -6
- package/src/organisms/form/useForm.ts +2 -3
- package/src/organisms/modal/RemoveModal.stories.tsx +1 -1
- package/src/organisms/table/actions/ActionsTable.stories.tsx +2 -2
- package/src/organisms/table/actions/ActionsTable.tsx +7 -5
- package/src/organisms/table/forms/FormsTable.tsx +6 -5
- package/src/organisms/table/submissions/SubmissionsTable.stories.tsx +11 -14
- package/src/organisms/views/FormViews.stories.tsx +14 -17
- package/src/organisms/views/FormViews.tsx +18 -16
- package/src/utils/iconClass.ts +1 -3
- package/vite.config.mts +2 -2
- package/dist/typings.d.js +0 -2
- package/dist/typings.d.js.map +0 -1
- package/src/typings.d.ts +0 -3
- package/tsconfig.app.json +0 -11
- package/tsconfig.json +0 -21
- package/tsconfig.node.json +0 -13
- 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
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
9
|
-
|
|
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 {
|
|
1
|
+
import type { Component } from "@formio/core";
|
|
2
2
|
|
|
3
|
-
export type ComponentType =
|
|
3
|
+
export type ComponentType = Omit<Component, "components"> & { components?: ComponentType[] } & { title?: string } & Record<string, unknown>;
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EventEmitter, Form } from "@formio/js";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 {
|
|
1
|
+
import type { Form } from "@formio/core";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
10
|
-
action?: string;
|
|
11
|
-
properties?: Record<string, any>;
|
|
12
|
-
[key: string]: any;
|
|
13
|
-
};
|
|
7
|
+
} & Record<string, unknown>;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import type {
|
|
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
|
|
6
|
-
_id?: string;
|
|
5
|
+
export type SubmissionType<Data extends { [key: string]: JSON } = { [key: string]: JSON }> = Omit<Partial<Submission>, "data"> & {
|
|
7
6
|
data: Data;
|
|
8
|
-
|
|
9
|
-
state?: string;
|
|
10
|
-
}
|
|
7
|
+
};
|
|
11
8
|
|
|
12
|
-
export interface ChangedSubmission<
|
|
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:
|
|
16
|
+
component: Component;
|
|
16
17
|
instance: any;
|
|
17
18
|
value: unknown;
|
|
18
19
|
} & Record<string, JSON>;
|
package/src/interfaces/index.ts
CHANGED
|
@@ -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 = "
|
|
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 = "
|
|
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
|
|
|
@@ -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
|
|
41
|
-
onAdd(event.
|
|
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
|
|
45
|
-
onDelete(event.
|
|
44
|
+
instance.passedElement.element.addEventListener("removeItem", (event) => {
|
|
45
|
+
onDelete((event.target as any).value as Data);
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
-
import { expect, userEvent, within } from "
|
|
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 "
|
|
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 "
|
|
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 "
|
|
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,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?:
|
|
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
|
-
{
|
|
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
|
-
{
|
|
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"}>{
|
|
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>{
|
|
106
|
+
<span>{t("Page")} </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
|
-
{
|
|
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 "
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
-
|
|
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 {
|
|
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?:
|
|
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
|
|
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:
|
|
44
|
+
header: t("Operations"),
|
|
44
45
|
cell: (info) => (
|
|
45
|
-
<Operations info={info} operations={props.operations} metadata={props.metadata} onClick={props.onClick} 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
|
|
28
|
+
return component.components?.flatMap((subComponent: ComponentType) => subComponent.components);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
return [component];
|
|
32
32
|
})
|
|
33
|
-
.filter((component) => component
|
|
34
|
-
.map((
|
|
35
|
-
const
|
|
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}`;
|