@tsed/react-formio 3.0.0-alpha.10 → 3.0.0-alpha.12
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/atoms/icon/Icon.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/react-select-animated.esm.js +1204 -1101
- package/dist/chunks/react-select-animated.esm.js.map +1 -1
- package/dist/hooks/keyboard.constants.d.ts +38 -0
- package/dist/hooks/keyboard.constants.js +7 -0
- package/dist/hooks/keyboard.constants.js.map +1 -0
- package/dist/hooks/useKeyboardControls.d.ts +12 -0
- package/dist/hooks/useKeyboardControls.js +35 -0
- package/dist/hooks/useKeyboardControls.js.map +1 -0
- package/dist/hooks/useTooltip.js.map +1 -1
- package/dist/interfaces/Operation.d.ts +12 -2
- package/dist/molecules/alert/Alert.js.map +1 -1
- package/dist/molecules/button/Button.d.ts +18 -5
- package/dist/molecules/button/Button.js +22 -26
- package/dist/molecules/button/Button.js.map +1 -1
- package/dist/molecules/card/Card.js +7 -5
- 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 +14 -14
- package/dist/molecules/forms/input-tags/InputTags.js.map +1 -1
- package/dist/molecules/forms/input-tags/components/ChoicesTags.js +26 -26
- 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.js +19 -19
- 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.d.ts +11 -3
- package/dist/molecules/table/Table.js +31 -32
- 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.d.ts +12 -4
- package/dist/molecules/table/components/DefaultCellOperations.js +13 -7
- 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.d.ts +12 -4
- 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 +12 -4
- package/dist/molecules/table/hooks/useTable.js +7 -7
- 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 +20 -21
- package/dist/molecules/table/utils/mapFormToColumns.js.map +1 -1
- package/dist/molecules/tabs/Tab.d.ts +13 -0
- package/dist/molecules/tabs/Tab.js +66 -0
- package/dist/molecules/tabs/Tab.js.map +1 -0
- package/dist/molecules/tabs/TabList.d.ts +2 -0
- package/dist/molecules/tabs/TabList.js +23 -0
- package/dist/molecules/tabs/TabList.js.map +1 -0
- package/dist/molecules/tabs/TabPanel.d.ts +9 -0
- package/dist/molecules/tabs/TabPanel.js +27 -0
- package/dist/molecules/tabs/TabPanel.js.map +1 -0
- package/dist/molecules/tabs/Tabs.d.ts +4 -16
- package/dist/molecules/tabs/Tabs.js +7 -67
- package/dist/molecules/tabs/Tabs.js.map +1 -1
- package/dist/molecules/tabs/TabsBody.d.ts +1 -0
- package/dist/molecules/tabs/TabsBody.js +10 -0
- package/dist/molecules/tabs/TabsBody.js.map +1 -0
- package/dist/molecules/tabs/TabsLegacy.d.ts +17 -0
- package/dist/molecules/tabs/TabsLegacy.js +49 -0
- package/dist/molecules/tabs/TabsLegacy.js.map +1 -0
- package/dist/molecules/tabs/all.d.ts +5 -0
- package/dist/molecules/tabs/all.js +13 -0
- package/dist/molecules/tabs/all.js.map +1 -0
- package/dist/molecules/tabs/context/TabControl.d.ts +52 -0
- package/dist/molecules/tabs/context/TabControl.js +85 -0
- package/dist/molecules/tabs/context/TabControl.js.map +1 -0
- package/dist/molecules/tabs/hooks/tabControl.d.ts +44 -0
- package/dist/molecules/tabs/hooks/tabControl.js +34 -0
- package/dist/molecules/tabs/hooks/tabControl.js.map +1 -0
- 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.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/{action → actions}/FormAction.js +7 -8
- package/dist/organisms/form/actions/FormAction.js.map +1 -0
- package/dist/organisms/form/builder/FormBuilder.js.map +1 -1
- package/dist/organisms/form/builder/FormEdit.d.ts +3 -1
- package/dist/organisms/form/builder/FormEdit.js +38 -35
- 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.js +34 -34
- 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.js +41 -38
- package/dist/organisms/form/builder/useFormBuilder.js.map +1 -1
- package/dist/organisms/form/builder/useFormEdit.js +1 -1
- package/dist/organisms/form/builder/useFormEdit.js.map +1 -1
- package/dist/organisms/form/exports/FormExport.d.ts +5 -0
- package/dist/organisms/form/exports/FormExport.js +55 -0
- package/dist/organisms/form/exports/FormExport.js.map +1 -0
- package/dist/organisms/form/preview/FormPreview.d.ts +6 -0
- package/dist/organisms/form/preview/FormPreview.js +11 -0
- package/dist/organisms/form/preview/FormPreview.js.map +1 -0
- package/dist/organisms/form/settings/FormSettings.js +24 -24
- 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.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.js.map +1 -1
- package/dist/organisms/table/forms/FormsTable.js.map +1 -1
- package/dist/organisms/table/forms/components/FormsCell.js.map +1 -1
- package/dist/organisms/table/submissions/SubmissionsTable.d.ts +11 -3
- package/dist/organisms/table/submissions/SubmissionsTable.js +4 -1
- package/dist/organisms/table/submissions/SubmissionsTable.js.map +1 -1
- package/dist/organisms/views/FormViews.d.ts +24 -0
- package/dist/organisms/views/FormViews.js +96 -0
- package/dist/organisms/views/FormViews.js.map +1 -0
- package/dist/registries/components.js.map +1 -1
- package/dist/utils/getEventValue.js.map +1 -1
- 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/atoms/icon/Icon.stories.tsx +1 -1
- package/src/hooks/keyboard.constants.ts +40 -0
- package/src/hooks/useKeyboardControls.spec.tsx +208 -0
- package/src/hooks/useKeyboardControls.ts +84 -0
- package/src/interfaces/Operation.ts +9 -3
- package/src/molecules/button/Button.stories.tsx +1 -1
- package/src/molecules/button/Button.tsx +43 -24
- package/src/molecules/card/Card.tsx +4 -0
- package/src/molecules/forms/form-control/FormControl.stories.tsx +1 -1
- package/src/molecules/forms/input-tags/InputTags.tsx +1 -1
- package/src/molecules/forms/input-tags/components/ChoicesTags.stories.tsx +1 -1
- 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/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 -8
- package/src/molecules/pagination/Pagination.tsx +0 -1
- package/src/molecules/table/Table.stories.tsx +36 -3
- package/src/molecules/table/Table.tsx +12 -6
- package/src/molecules/table/components/DefaultCellOperations.tsx +13 -7
- package/src/molecules/table/components/DefaultOperationButton.tsx +5 -4
- package/src/molecules/table/filters/SelectFilter.tsx +1 -1
- package/src/molecules/table/hooks/useTable.tsx +5 -5
- package/src/molecules/tabs/Tab.tsx +106 -0
- package/src/molecules/tabs/TabList.tsx +37 -0
- package/src/molecules/tabs/TabPanel.tsx +37 -0
- package/src/molecules/tabs/Tabs.spec.tsx +126 -73
- package/src/molecules/tabs/Tabs.stories.tsx +298 -65
- package/src/molecules/tabs/Tabs.tsx +10 -81
- package/src/molecules/tabs/TabsBody.tsx +11 -0
- package/src/molecules/tabs/TabsLegacy.stories.tsx +103 -0
- package/src/molecules/tabs/TabsLegacy.tsx +84 -0
- package/src/molecules/tabs/all.ts +5 -0
- package/src/molecules/tabs/context/TabControl.tsx +166 -0
- package/src/molecules/tabs/hooks/tabControl.spec.tsx +388 -0
- package/src/molecules/tabs/hooks/tabControl.ts +52 -0
- package/src/organisms/__fixtures__/form-firstname.fixture.json +1 -0
- package/src/organisms/__fixtures__/form.fixture.json +1 -0
- package/src/organisms/form/Form.stories.tsx +94 -118
- package/src/organisms/form/access/FormAccess.stories.tsx +2 -2
- package/src/organisms/form/actions/FormAction.stories.tsx +422 -0
- package/src/organisms/form/builder/FormBuilder.stories.tsx +4 -1
- package/src/organisms/form/builder/FormEdit.stories.tsx +1 -1
- package/src/organisms/form/builder/FormEdit.tsx +7 -1
- package/src/organisms/form/builder/useFormBuilder.ts +5 -1
- package/src/organisms/form/builder/useFormEdit.ts +1 -1
- package/src/organisms/form/exports/FormExport.stories.tsx +71 -0
- package/src/organisms/form/exports/FormExport.tsx +58 -0
- package/src/organisms/form/preview/FormPreview.stories.tsx +61 -0
- package/src/organisms/form/preview/FormPreview.tsx +21 -0
- package/src/organisms/modal/RemoveModal.stories.tsx +1 -1
- package/src/organisms/table/actions/ActionsTable.stories.tsx +38 -36
- package/src/organisms/table/submissions/SubmissionsTable.stories.tsx +103 -57
- package/src/organisms/table/submissions/SubmissionsTable.tsx +10 -4
- package/src/organisms/views/FormViews.stories.tsx +224 -0
- package/src/organisms/views/FormViews.tsx +146 -0
- package/vite.config.mts +2 -2
- package/dist/organisms/form/action/FormAction.js.map +0 -1
- package/src/organisms/form/action/FormAction.stories.tsx +0 -364
- package/tsconfig.app.json +0 -11
- package/tsconfig.json +0 -21
- package/tsconfig.node.json +0 -13
- package/tsconfig.spec.json +0 -14
- /package/dist/organisms/form/{action → actions}/FormAction.d.ts +0 -0
- /package/src/organisms/form/{action → actions}/FormAction.tsx +0 -0
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import { FormType, SubmissionType } from '../../../interfaces';
|
|
1
|
+
import { FormType, JSON, SubmissionType } from '../../../interfaces';
|
|
2
2
|
import { TableProps } from '../../../molecules/table/Table';
|
|
3
|
-
export type SubmissionsTableProps
|
|
3
|
+
export type SubmissionsTableProps<Data extends {
|
|
4
|
+
[key: string]: JSON;
|
|
5
|
+
} = {
|
|
6
|
+
[key: string]: JSON;
|
|
7
|
+
}> = Omit<TableProps<SubmissionType<Data>>, "columns"> & {
|
|
4
8
|
form?: FormType;
|
|
5
9
|
};
|
|
6
|
-
export declare function SubmissionsTable
|
|
10
|
+
export declare function SubmissionsTable<Data extends {
|
|
11
|
+
[key: string]: JSON;
|
|
12
|
+
} = {
|
|
13
|
+
[key: string]: JSON;
|
|
14
|
+
}>({ form, ...props }: SubmissionsTableProps<Data>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { jsx as n } from "react/jsx-runtime";
|
|
2
2
|
import { Table as s } from "../../../molecules/table/Table.js";
|
|
3
3
|
import { mapFormToColumns as t } from "../../../molecules/table/utils/mapFormToColumns.js";
|
|
4
|
-
function e({
|
|
4
|
+
function e({
|
|
5
|
+
form: o,
|
|
6
|
+
...m
|
|
7
|
+
}) {
|
|
5
8
|
const r = o && t(o);
|
|
6
9
|
return /* @__PURE__ */ n(s, { ...m, columns: r });
|
|
7
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubmissionsTable.js","sources":["../../../../src/organisms/table/submissions/SubmissionsTable.tsx"],"sourcesContent":["import type { FormType, SubmissionType } from \"../../../interfaces\";\nimport { Table, type TableProps } from \"../../../molecules/table/Table\";\nimport { mapFormToColumns } from \"../../../molecules/table/utils/mapFormToColumns.js\";\n\nexport type SubmissionsTableProps = Omit
|
|
1
|
+
{"version":3,"file":"SubmissionsTable.js","sources":["../../../../src/organisms/table/submissions/SubmissionsTable.tsx"],"sourcesContent":["import type { FormType, JSON, SubmissionType } from \"../../../interfaces\";\nimport { Table, type TableProps } from \"../../../molecules/table/Table\";\nimport { mapFormToColumns } from \"../../../molecules/table/utils/mapFormToColumns.js\";\n\nexport type SubmissionsTableProps<Data extends { [key: string]: JSON } = { [key: string]: JSON }> = Omit<\n TableProps<SubmissionType<Data>>,\n \"columns\"\n> & {\n form?: FormType;\n};\n\nexport function SubmissionsTable<Data extends { [key: string]: JSON } = { [key: string]: JSON }>({\n form,\n ...props\n}: SubmissionsTableProps<Data>) {\n const columns: any[] | undefined = form && mapFormToColumns(form);\n\n return <Table {...(props as any)} columns={columns!} />;\n}\n"],"names":["SubmissionsTable","form","props","columns","mapFormToColumns","jsx","Table"],"mappings":";;;AAWO,SAASA,EAAiF;AAAA,EAC/F,MAAAC;AAAA,EACA,GAAGC;AACL,GAAgC;AAC9B,QAAMC,IAA6BF,KAAQG,EAAiBH,CAAI;AAEhE,SAAO,gBAAAI,EAACC,GAAA,EAAO,GAAIJ,GAAe,SAAAC,EAAA,CAAmB;AACvD;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { JSON, PermissionsResolver } from '../../interfaces/index.js';
|
|
2
|
+
import { FormAccessProps } from '../form/access/FormAccess.js';
|
|
3
|
+
import { FormEditProps } from '../form/builder/FormEdit.js';
|
|
4
|
+
import { ActionsTableProps } from '../table/actions/ActionsTable.js';
|
|
5
|
+
import { SubmissionsTableProps } from '../table/submissions/SubmissionsTable.js';
|
|
6
|
+
export type FormViewsProps<Data extends {
|
|
7
|
+
[key: string]: JSON;
|
|
8
|
+
} = {
|
|
9
|
+
[key: string]: JSON;
|
|
10
|
+
}> = {
|
|
11
|
+
form: FormEditProps["form"];
|
|
12
|
+
submissions: SubmissionsTableProps<Data>["data"];
|
|
13
|
+
availableActions: ActionsTableProps["availableActions"];
|
|
14
|
+
actions: ActionsTableProps["data"];
|
|
15
|
+
roles?: FormAccessProps["roles"];
|
|
16
|
+
i18n?: (key: string) => string;
|
|
17
|
+
onAction: () => void;
|
|
18
|
+
permissionsResolver?: PermissionsResolver<Data>;
|
|
19
|
+
};
|
|
20
|
+
export declare function FormViews<Data extends {
|
|
21
|
+
[key: string]: JSON;
|
|
22
|
+
} = {
|
|
23
|
+
[key: string]: JSON;
|
|
24
|
+
}>({ form, roles, availableActions, actions, permissionsResolver, submissions, i18n }: FormViewsProps<Data>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { jsxs as c, jsx as o } from "react/jsx-runtime";
|
|
2
|
+
import { getComponent as i } from "../../registries/components.js";
|
|
3
|
+
import { FormAccess as v } from "../form/access/FormAccess.js";
|
|
4
|
+
import { FormEdit as f } from "../form/builder/FormEdit.js";
|
|
5
|
+
import { FormExport as g } from "../form/exports/FormExport.js";
|
|
6
|
+
import { FormPreview as w } from "../form/preview/FormPreview.js";
|
|
7
|
+
import { FormSettings as y } from "../form/settings/FormSettings.js";
|
|
8
|
+
import { ActionsTable as E } from "../table/actions/ActionsTable.js";
|
|
9
|
+
import { SubmissionsTable as F } from "../table/submissions/SubmissionsTable.js";
|
|
10
|
+
function N(t) {
|
|
11
|
+
return [
|
|
12
|
+
{
|
|
13
|
+
title: "Edit",
|
|
14
|
+
action: "submission:edit",
|
|
15
|
+
alias: "row",
|
|
16
|
+
icon: "edit",
|
|
17
|
+
permissionsResolver: t
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
action: "submission:delete",
|
|
21
|
+
icon: "trash",
|
|
22
|
+
buttonType: "danger",
|
|
23
|
+
permissionsResolver: t
|
|
24
|
+
}
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
function x(t) {
|
|
28
|
+
return [
|
|
29
|
+
{
|
|
30
|
+
title: "Edit",
|
|
31
|
+
action: "action:edit",
|
|
32
|
+
alias: "row",
|
|
33
|
+
icon: "edit",
|
|
34
|
+
permissionsResolver: t
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
action: "action:delete",
|
|
38
|
+
icon: "trash",
|
|
39
|
+
buttonType: "danger",
|
|
40
|
+
permissionsResolver: t
|
|
41
|
+
}
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
function D({
|
|
45
|
+
form: t,
|
|
46
|
+
roles: l,
|
|
47
|
+
availableActions: d,
|
|
48
|
+
actions: b,
|
|
49
|
+
permissionsResolver: s,
|
|
50
|
+
submissions: p,
|
|
51
|
+
i18n: e = (n) => n
|
|
52
|
+
}) {
|
|
53
|
+
const n = i("Tabs"), u = i("TabList"), r = i("Tab"), m = i("TabsBody"), a = i("TabPanel"), h = N(s), T = x(s);
|
|
54
|
+
return /* @__PURE__ */ c(n, { children: [
|
|
55
|
+
/* @__PURE__ */ c(u, { children: [
|
|
56
|
+
/* @__PURE__ */ o(r, { value: 0, icon: "edit", children: e("Edit") }),
|
|
57
|
+
/* @__PURE__ */ o(r, { value: 1, icon: "data", children: e("Data") }),
|
|
58
|
+
/* @__PURE__ */ o(r, { value: 2, icon: "test-tube", children: e("Preview") }),
|
|
59
|
+
/* @__PURE__ */ o(r, { value: 3, icon: "paper-plane", children: e("Actions") }),
|
|
60
|
+
/* @__PURE__ */ o(r, { value: 4, icon: "lock", children: e("Access") }),
|
|
61
|
+
/* @__PURE__ */ o(r, { value: 5, icon: "download", children: e("Export") }),
|
|
62
|
+
/* @__PURE__ */ o(r, { value: 6, icon: "cog", children: e("Settings") })
|
|
63
|
+
] }),
|
|
64
|
+
/* @__PURE__ */ c(m, { children: [
|
|
65
|
+
/* @__PURE__ */ o(a, { value: 0, className: "p-3 border-l-1 border-b-1 border-r-1 border-gray-300", children: /* @__PURE__ */ o(f, { form: t, options: { i18n: e } }) }),
|
|
66
|
+
/* @__PURE__ */ o(a, { value: 1, children: /* @__PURE__ */ o(
|
|
67
|
+
F,
|
|
68
|
+
{
|
|
69
|
+
className: "border-top-0",
|
|
70
|
+
form: t,
|
|
71
|
+
data: p,
|
|
72
|
+
i18n: e,
|
|
73
|
+
operations: h
|
|
74
|
+
}
|
|
75
|
+
) }),
|
|
76
|
+
/* @__PURE__ */ o(a, { value: 2, children: /* @__PURE__ */ o(w, { form: t, i18n: e }) }),
|
|
77
|
+
/* @__PURE__ */ o(a, { value: 3, children: /* @__PURE__ */ o(
|
|
78
|
+
E,
|
|
79
|
+
{
|
|
80
|
+
className: "border-top-0",
|
|
81
|
+
availableActions: d,
|
|
82
|
+
data: b,
|
|
83
|
+
operations: T,
|
|
84
|
+
i18n: e
|
|
85
|
+
}
|
|
86
|
+
) }),
|
|
87
|
+
/* @__PURE__ */ o(a, { value: 4, className: "pt-3", children: /* @__PURE__ */ o(v, { form: t, roles: l, options: { i18n: e } }) }),
|
|
88
|
+
/* @__PURE__ */ o(a, { value: 5, className: "pt-3", children: /* @__PURE__ */ o(g, { i18n: e }) }),
|
|
89
|
+
/* @__PURE__ */ o(a, { value: 6, className: "p-3 border-l-1 border-b-1 border-r-1 border-gray-300", children: /* @__PURE__ */ o(y, { form: t, options: {} }) })
|
|
90
|
+
] })
|
|
91
|
+
] });
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
D as FormViews
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=FormViews.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormViews.js","sources":["../../../src/organisms/views/FormViews.tsx"],"sourcesContent":["import type { FormType, JSON, PermissionsResolver } from \"../../interfaces/index.js\";\nimport type { Tab as DefaultTab } from \"../../molecules/tabs/Tab.js\";\nimport type { TabList as DefaultTabList } from \"../../molecules/tabs/TabList.js\";\nimport type { TabPanel as DefaultTabPanel } from \"../../molecules/tabs/TabPanel.js\";\nimport type { Tabs as DefaultTabs } from \"../../molecules/tabs/Tabs.js\";\nimport type { TabsBody as DefaultTabsBody } from \"../../molecules/tabs/TabsBody.js\";\nimport { getComponent } from \"../../registries/components.js\";\nimport { FormAccess, type FormAccessProps } from \"../form/access/FormAccess.js\";\nimport { FormEdit, type FormEditProps } from \"../form/builder/FormEdit.js\";\nimport { FormExport } from \"../form/exports/FormExport.js\";\nimport { FormPreview } from \"../form/preview/FormPreview.js\";\nimport { FormSettings } from \"../form/settings/FormSettings.js\";\nimport { ActionsTable, type ActionsTableProps } from \"../table/actions/ActionsTable.js\";\nimport { SubmissionsTable, type SubmissionsTableProps } from \"../table/submissions/SubmissionsTable.js\";\n\nexport type FormViewsProps<Data extends { [key: string]: JSON } = { [key: string]: JSON }> = {\n form: FormEditProps[\"form\"];\n submissions: SubmissionsTableProps<Data>[\"data\"];\n availableActions: ActionsTableProps[\"availableActions\"];\n actions: ActionsTableProps[\"data\"];\n roles?: FormAccessProps[\"roles\"];\n i18n?: (key: string) => string;\n onAction: () => void;\n permissionsResolver?: PermissionsResolver<Data>;\n};\n\nfunction useSubmissionsOperations<Data extends { [key: string]: JSON } = { [key: string]: JSON }>(\n permissionsResolver?: PermissionsResolver<Data>\n) {\n return [\n {\n title: \"Edit\",\n action: \"submission:edit\",\n alias: \"row\",\n icon: \"edit\",\n permissionsResolver\n },\n {\n action: \"submission:delete\",\n icon: \"trash\",\n buttonType: \"danger\",\n permissionsResolver\n }\n ] as SubmissionsTableProps<Data>[\"operations\"];\n}\n\nfunction useActionsOperations<Data extends { [key: string]: JSON } = { [key: string]: JSON }>(\n permissionsResolver?: PermissionsResolver<Data>\n) {\n return [\n {\n title: \"Edit\",\n action: \"action:edit\",\n alias: \"row\",\n icon: \"edit\",\n permissionsResolver\n },\n {\n action: \"action:delete\",\n icon: \"trash\",\n buttonType: \"danger\",\n permissionsResolver\n }\n ] as SubmissionsTableProps<Data>[\"operations\"];\n}\n\nexport function FormViews<Data extends { [key: string]: JSON } = { [key: string]: JSON }>({\n form,\n roles,\n availableActions,\n actions,\n permissionsResolver,\n submissions,\n i18n = (f) => f\n}: FormViewsProps<Data>) {\n const Tabs = getComponent<typeof DefaultTabs>(\"Tabs\");\n const TabList = getComponent<typeof DefaultTabList>(\"TabList\");\n const Tab = getComponent<typeof DefaultTab>(\"Tab\");\n const TabsBody = getComponent<typeof DefaultTabsBody>(\"TabsBody\");\n const TabPanel = getComponent<typeof DefaultTabPanel>(\"TabPanel\");\n const submissionsOperations = useSubmissionsOperations<Data>(permissionsResolver);\n const actionsOperations = useActionsOperations<any>(permissionsResolver);\n\n return (\n <Tabs>\n <TabList>\n <Tab value={0} icon='edit'>\n {i18n(\"Edit\")}\n </Tab>\n <Tab value={1} icon='data'>\n {i18n(\"Data\")}\n </Tab>\n <Tab value={2} icon='test-tube'>\n {i18n(\"Preview\")}\n </Tab>\n <Tab value={3} icon='paper-plane'>\n {i18n(\"Actions\")}\n </Tab>\n <Tab value={4} icon='lock'>\n {i18n(\"Access\")}\n </Tab>\n <Tab value={5} icon='download'>\n {i18n(\"Export\")}\n </Tab>\n <Tab value={6} icon='cog'>\n {i18n(\"Settings\")}\n </Tab>\n </TabList>\n <TabsBody>\n <TabPanel value={0} className='p-3 border-l-1 border-b-1 border-r-1 border-gray-300'>\n <FormEdit form={form} options={{ i18n }} />\n </TabPanel>\n <TabPanel value={1}>\n <SubmissionsTable<Data>\n className={\"border-top-0\"}\n form={form as FormType}\n data={submissions}\n i18n={i18n}\n operations={submissionsOperations}\n />\n </TabPanel>\n <TabPanel value={2}>\n <FormPreview form={form as FormType} i18n={i18n} />\n </TabPanel>\n <TabPanel value={3}>\n <ActionsTable\n className={\"border-top-0\"}\n availableActions={availableActions}\n data={actions}\n operations={actionsOperations as any}\n i18n={i18n}\n />\n </TabPanel>\n <TabPanel value={4} className='pt-3'>\n <FormAccess form={form as FormType} roles={roles} options={{ i18n }} />\n </TabPanel>\n <TabPanel value={5} className='pt-3'>\n <FormExport i18n={i18n} />\n </TabPanel>\n <TabPanel value={6} className='p-3 border-l-1 border-b-1 border-r-1 border-gray-300'>\n <FormSettings form={form as FormType} options={{}} />\n </TabPanel>\n </TabsBody>\n </Tabs>\n );\n}\n"],"names":["useSubmissionsOperations","permissionsResolver","useActionsOperations","FormViews","form","roles","availableActions","actions","submissions","i18n","f","Tabs","getComponent","TabList","Tab","TabsBody","TabPanel","submissionsOperations","actionsOperations","jsxs","jsx","FormEdit","SubmissionsTable","FormPreview","ActionsTable","FormAccess","FormExport","FormSettings"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sources":["../../src/registries/components.ts"],"sourcesContent":["export const components = new Map<string, unknown>();\n\nexport function registerComponent(type: string, component: unknown) {\n components.set(type, component);\n}\n\nexport function getComponent<Cmp>(type: string | string[]): Cmp {\n if (Array.isArray(type)) {\n for (const t of type) {\n if (components.has(t)) {\n return components.get(t) as unknown as Cmp;\n }\n }\n }\n\n const result = components.get(type as string) as unknown as Cmp;\n\n if (!result) {\n console.warn(`Missing component for ${type}`);\n }\n\n return result;\n}\n"],"names":["components","registerComponent","type","component","getComponent","t","result"],"mappings":"
|
|
1
|
+
{"version":3,"file":"components.js","sources":["../../src/registries/components.ts"],"sourcesContent":["export const components = new Map<string, unknown>();\n\nexport function registerComponent(type: string, component: unknown) {\n components.set(type, component);\n}\n\nexport function getComponent<Cmp>(type: string | string[]): Cmp {\n if (Array.isArray(type)) {\n for (const t of type) {\n if (components.has(t)) {\n return components.get(t) as unknown as Cmp;\n }\n }\n }\n\n const result = components.get(type as string) as unknown as Cmp;\n\n if (!result) {\n console.warn(`Missing component for ${type}`);\n }\n\n return result;\n}\n"],"names":["components","registerComponent","type","component","getComponent","t","result"],"mappings":"AAAO,MAAMA,wBAAiB,IAAA;AAEvB,SAASC,EAAkBC,GAAcC,GAAoB;AAClE,EAAAH,EAAW,IAAIE,GAAMC,CAAS;AAChC;AAEO,SAASC,EAAkBF,GAA8B;AAC9D,MAAI,MAAM,QAAQA,CAAI;AACpB,eAAWG,KAAKH;AACd,UAAIF,EAAW,IAAIK,CAAC;AAClB,eAAOL,EAAW,IAAIK,CAAC;AAAA;AAK7B,QAAMC,IAASN,EAAW,IAAIE,CAAc;AAE5C,SAAKI,KACH,QAAQ,KAAK,yBAAyBJ,CAAI,EAAE,GAGvCI;AACT;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEventValue.js","sources":["../../src/utils/getEventValue.ts"],"sourcesContent":["export function getEventValue(event: any) {\n const { target } = event;\n\n if (event.target.multiple && event.target.selectedOptions) {\n return Array.from(event.target.selectedOptions, (option: any) => option.value);\n }\n\n return target.type === \"checkbox\" ? target.checked : target.value;\n}\n"],"names":["getEventValue","event","target","option"],"mappings":"AAAO,SAASA,EAAcC,GAAY;
|
|
1
|
+
{"version":3,"file":"getEventValue.js","sources":["../../src/utils/getEventValue.ts"],"sourcesContent":["export function getEventValue(event: any) {\n const { target } = event;\n\n if (event.target.multiple && event.target.selectedOptions) {\n return Array.from(event.target.selectedOptions, (option: any) => option.value);\n }\n\n return target.type === \"checkbox\" ? target.checked : target.value;\n}\n"],"names":["getEventValue","event","target","option"],"mappings":"AAAO,SAASA,EAAcC,GAAY;AACxC,QAAM,EAAE,QAAAC,MAAWD;AAEnB,SAAIA,EAAM,OAAO,YAAYA,EAAM,OAAO,kBACjC,MAAM,KAAKA,EAAM,OAAO,iBAAiB,CAACE,MAAgBA,EAAO,KAAK,IAGxED,EAAO,SAAS,aAAaA,EAAO,UAAUA,EAAO;AAC9D;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iconClass.js","sources":["../../src/utils/iconClass.ts"],"sourcesContent":["import * as formio from \"formiojs\";\n\nconst { Templates } = formio;\n\nexport function iconClass(iconset: string | undefined, name: string, spinning?: boolean): string {\n return Templates.current.iconClass(iconset || Templates.current.defaultIconset, name, spinning);\n}\n"],"names":["Templates","formio","iconClass","iconset","name","spinning"],"mappings":";AAEA,MAAM,EAAE,WAAAA,
|
|
1
|
+
{"version":3,"file":"iconClass.js","sources":["../../src/utils/iconClass.ts"],"sourcesContent":["import * as formio from \"formiojs\";\n\nconst { Templates } = formio;\n\nexport function iconClass(iconset: string | undefined, name: string, spinning?: boolean): string {\n return Templates.current.iconClass(iconset || Templates.current.defaultIconset, name, spinning);\n}\n"],"names":["Templates","formio","iconClass","iconset","name","spinning"],"mappings":";AAEA,MAAM,EAAE,WAAAA,MAAcC;AAEf,SAASC,EAAUC,GAA6BC,GAAcC,GAA4B;AAC/F,SAAOL,EAAU,QAAQ,UAAUG,KAAWH,EAAU,QAAQ,gBAAgBI,GAAMC,CAAQ;AAChG;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapPagination.js","sources":["../../src/utils/mapPagination.ts"],"sourcesContent":["export function mapPagination({ skip, limit, serverCount, length }: any = {}): any {\n skip = skip || 0;\n limit = limit || 10;\n serverCount = serverCount || length;\n\n return {\n pageIndex: Math.floor(skip / limit),\n pageSize: limit,\n pageCount: Math.ceil(serverCount / limit)\n };\n}\n"],"names":["mapPagination","skip","limit","serverCount","length"],"mappings":"
|
|
1
|
+
{"version":3,"file":"mapPagination.js","sources":["../../src/utils/mapPagination.ts"],"sourcesContent":["export function mapPagination({ skip, limit, serverCount, length }: any = {}): any {\n skip = skip || 0;\n limit = limit || 10;\n serverCount = serverCount || length;\n\n return {\n pageIndex: Math.floor(skip / limit),\n pageSize: limit,\n pageCount: Math.ceil(serverCount / limit)\n };\n}\n"],"names":["mapPagination","skip","limit","serverCount","length"],"mappings":"AAAO,SAASA,EAAc,EAAE,MAAAC,GAAM,OAAAC,GAAO,aAAAC,GAAa,QAAAC,EAAA,IAAgB,IAAS;AACjF,SAAAH,IAAOA,KAAQ,GACfC,IAAQA,KAAS,IACjBC,IAAcA,KAAeC,GAEtB;AAAA,IACL,WAAW,KAAK,MAAMH,IAAOC,CAAK;AAAA,IAClC,UAAUA;AAAA,IACV,WAAW,KAAK,KAAKC,IAAcD,CAAK;AAAA,EAAA;AAE5C;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stopPropagationWrapper.js","sources":["../../src/utils/stopPropagationWrapper.ts"],"sourcesContent":["export const stopPropagationWrapper = (fn: Function) => (event: any) => {\n event.stopPropagation();\n fn();\n};\n"],"names":["stopPropagationWrapper","fn","event"],"mappings":"AAAO,MAAMA,IAAyB,CAACC,MAAiB,CAACC,MAAe;AACtE,EAAAA,EAAM,
|
|
1
|
+
{"version":3,"file":"stopPropagationWrapper.js","sources":["../../src/utils/stopPropagationWrapper.ts"],"sourcesContent":["export const stopPropagationWrapper = (fn: Function) => (event: any) => {\n event.stopPropagation();\n fn();\n};\n"],"names":["stopPropagationWrapper","fn","event"],"mappings":"AAAO,MAAMA,IAAyB,CAACC,MAAiB,CAACC,MAAe;AACtE,EAAAA,EAAM,gBAAA,GACND,EAAA;AACF;"}
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/react-formio",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.12",
|
|
4
4
|
"description": "Provide a react formio wrapper. Written in TypeScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.modern.js",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
10
|
"tsed-source": "./src/index.ts",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
12
|
"default": "./dist/index.js"
|
|
13
13
|
},
|
|
14
14
|
"./*": {
|
|
15
|
-
"types": "./dist/*.d.ts",
|
|
16
15
|
"tsed-source": "./src/*",
|
|
16
|
+
"types": "./dist/*.d.ts",
|
|
17
17
|
"default": "./dist/*.js"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@tanstack/react-table": ">=8.20.6",
|
|
47
|
-
"@tsed/tailwind-formio": "3.0.0-alpha.
|
|
48
|
-
"@tsed/typescript": "3.0.0-alpha.
|
|
47
|
+
"@tsed/tailwind-formio": "3.0.0-alpha.12",
|
|
48
|
+
"@tsed/typescript": "3.0.0-alpha.12",
|
|
49
49
|
"microbundle": "0.13.0",
|
|
50
|
-
"vite": "
|
|
51
|
-
"vitest": "2.
|
|
50
|
+
"vite": "7.1.5",
|
|
51
|
+
"vitest": "3.2.4"
|
|
52
52
|
},
|
|
53
53
|
"repository": "https://github.com/tsedio/tsed-formio",
|
|
54
54
|
"bugs": {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const enum CODE {
|
|
2
|
+
ENTER = "Enter",
|
|
3
|
+
ESCAPE = "Escape",
|
|
4
|
+
ARROW_LEFT = "ArrowLeft",
|
|
5
|
+
ARROW_UP = "ArrowUp",
|
|
6
|
+
ARROW_RIGHT = "ArrowRight",
|
|
7
|
+
ARROW_DOWN = "ArrowDown",
|
|
8
|
+
SPACE = "Space",
|
|
9
|
+
END = "End",
|
|
10
|
+
HOME = "Home"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const enum KEY {
|
|
14
|
+
ENTER = "Enter",
|
|
15
|
+
ESCAPE = "Escape",
|
|
16
|
+
ARROW_LEFT = "ArrowLeft",
|
|
17
|
+
ARROW_UP = "ArrowUp",
|
|
18
|
+
ARROW_RIGHT = "ArrowRight",
|
|
19
|
+
ARROW_DOWN = "ArrowDown",
|
|
20
|
+
END = "End",
|
|
21
|
+
HOME = "Home",
|
|
22
|
+
SPACE = " ",
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated
|
|
25
|
+
* Used by old browers, see https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values#whitespace_keys
|
|
26
|
+
*/
|
|
27
|
+
SPACEBAR = "Spacebar"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const enum KEY_CODE {
|
|
31
|
+
ENTER = 13,
|
|
32
|
+
ESCAPE = 27,
|
|
33
|
+
ARROW_LEFT = 37,
|
|
34
|
+
ARROW_UP = 38,
|
|
35
|
+
ARROW_RIGHT = 39,
|
|
36
|
+
ARROW_DOWN = 40,
|
|
37
|
+
SPACE = 32,
|
|
38
|
+
END = 35,
|
|
39
|
+
HOME = 36
|
|
40
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { userEvent } from "@testing-library/user-event";
|
|
3
|
+
|
|
4
|
+
import { useKeyboardControls } from "./useKeyboardControls";
|
|
5
|
+
|
|
6
|
+
describe("useKeyboardControls()", () => {
|
|
7
|
+
const activate = vi.fn();
|
|
8
|
+
const start = vi.fn();
|
|
9
|
+
const end = vi.fn();
|
|
10
|
+
const up = vi.fn();
|
|
11
|
+
const down = vi.fn();
|
|
12
|
+
const left = vi.fn();
|
|
13
|
+
const right = vi.fn();
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
vi.clearAllMocks();
|
|
17
|
+
});
|
|
18
|
+
const Test = () => {
|
|
19
|
+
const handle = useKeyboardControls({ activate, start, end, up, down, left, right });
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div tabIndex={0} role='button' onKeyDown={handle}>
|
|
23
|
+
Test
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
describe("on Enter", () => {
|
|
29
|
+
it('call the "activate" callback', async () => {
|
|
30
|
+
render(<Test />);
|
|
31
|
+
|
|
32
|
+
const button = screen.getByRole("button");
|
|
33
|
+
button.focus();
|
|
34
|
+
|
|
35
|
+
await userEvent.keyboard("[Enter]{Enter}");
|
|
36
|
+
|
|
37
|
+
expect(activate).toHaveBeenCalledTimes(2);
|
|
38
|
+
expect(start).not.toHaveBeenCalled();
|
|
39
|
+
expect(end).not.toHaveBeenCalled();
|
|
40
|
+
expect(up).not.toHaveBeenCalled();
|
|
41
|
+
expect(down).not.toHaveBeenCalled();
|
|
42
|
+
expect(left).not.toHaveBeenCalled();
|
|
43
|
+
expect(right).not.toHaveBeenCalled();
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("on Spacebar", () => {
|
|
48
|
+
it('call the "activate" callback', async () => {
|
|
49
|
+
render(<Test />);
|
|
50
|
+
|
|
51
|
+
const button = screen.getByRole("button");
|
|
52
|
+
button.focus();
|
|
53
|
+
|
|
54
|
+
await userEvent.keyboard("[Space]{ }{Spacebar}");
|
|
55
|
+
|
|
56
|
+
expect(activate).toHaveBeenCalledTimes(3);
|
|
57
|
+
expect(start).not.toHaveBeenCalled();
|
|
58
|
+
expect(end).not.toHaveBeenCalled();
|
|
59
|
+
expect(up).not.toHaveBeenCalled();
|
|
60
|
+
expect(down).not.toHaveBeenCalled();
|
|
61
|
+
expect(left).not.toHaveBeenCalled();
|
|
62
|
+
expect(right).not.toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe("on Home", () => {
|
|
67
|
+
it('call the "start" callback', async () => {
|
|
68
|
+
render(<Test />);
|
|
69
|
+
|
|
70
|
+
const button = screen.getByRole("button");
|
|
71
|
+
button.focus();
|
|
72
|
+
|
|
73
|
+
await userEvent.keyboard("[Home]");
|
|
74
|
+
|
|
75
|
+
expect(activate).not.toHaveBeenCalled();
|
|
76
|
+
expect(start).toHaveBeenCalledTimes(1);
|
|
77
|
+
expect(end).not.toHaveBeenCalled();
|
|
78
|
+
expect(up).not.toHaveBeenCalled();
|
|
79
|
+
expect(down).not.toHaveBeenCalled();
|
|
80
|
+
expect(left).not.toHaveBeenCalled();
|
|
81
|
+
expect(right).not.toHaveBeenCalled();
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe("on End", () => {
|
|
86
|
+
it('call the "end" callback', async () => {
|
|
87
|
+
render(<Test />);
|
|
88
|
+
|
|
89
|
+
const button = screen.getByRole("button");
|
|
90
|
+
button.focus();
|
|
91
|
+
|
|
92
|
+
await userEvent.keyboard("[End]");
|
|
93
|
+
|
|
94
|
+
expect(activate).not.toHaveBeenCalled();
|
|
95
|
+
expect(start).not.toHaveBeenCalled();
|
|
96
|
+
expect(end).toHaveBeenCalledTimes(1);
|
|
97
|
+
expect(up).not.toHaveBeenCalled();
|
|
98
|
+
expect(down).not.toHaveBeenCalled();
|
|
99
|
+
expect(left).not.toHaveBeenCalled();
|
|
100
|
+
expect(right).not.toHaveBeenCalled();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe("on Arrow Up", () => {
|
|
105
|
+
it('call the "up" callback', async () => {
|
|
106
|
+
render(<Test />);
|
|
107
|
+
|
|
108
|
+
const button = screen.getByRole("button");
|
|
109
|
+
button.focus();
|
|
110
|
+
|
|
111
|
+
await userEvent.keyboard("[ArrowUp]");
|
|
112
|
+
|
|
113
|
+
expect(activate).not.toHaveBeenCalled();
|
|
114
|
+
expect(start).not.toHaveBeenCalled();
|
|
115
|
+
expect(end).not.toHaveBeenCalled();
|
|
116
|
+
expect(up).toHaveBeenCalledTimes(1);
|
|
117
|
+
expect(down).not.toHaveBeenCalled();
|
|
118
|
+
expect(left).not.toHaveBeenCalled();
|
|
119
|
+
expect(right).not.toHaveBeenCalled();
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe("on Arrow Down", () => {
|
|
124
|
+
it('call the "down" callback', async () => {
|
|
125
|
+
render(<Test />);
|
|
126
|
+
|
|
127
|
+
const button = screen.getByRole("button");
|
|
128
|
+
button.focus();
|
|
129
|
+
|
|
130
|
+
await userEvent.keyboard("[ArrowDown]");
|
|
131
|
+
|
|
132
|
+
expect(activate).not.toHaveBeenCalled();
|
|
133
|
+
expect(start).not.toHaveBeenCalled();
|
|
134
|
+
expect(end).not.toHaveBeenCalled();
|
|
135
|
+
expect(up).not.toHaveBeenCalled();
|
|
136
|
+
expect(down).toHaveBeenCalledTimes(1);
|
|
137
|
+
expect(left).not.toHaveBeenCalled();
|
|
138
|
+
expect(right).not.toHaveBeenCalled();
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
describe("on Arrow Left", () => {
|
|
143
|
+
it('call the "left" callback', async () => {
|
|
144
|
+
render(<Test />);
|
|
145
|
+
|
|
146
|
+
const button = screen.getByRole("button");
|
|
147
|
+
button.focus();
|
|
148
|
+
|
|
149
|
+
await userEvent.keyboard("[ArrowLeft]");
|
|
150
|
+
|
|
151
|
+
expect(activate).not.toHaveBeenCalled();
|
|
152
|
+
expect(start).not.toHaveBeenCalled();
|
|
153
|
+
expect(end).not.toHaveBeenCalled();
|
|
154
|
+
expect(up).not.toHaveBeenCalled();
|
|
155
|
+
expect(down).not.toHaveBeenCalled();
|
|
156
|
+
expect(left).toHaveBeenCalledTimes(1);
|
|
157
|
+
expect(right).not.toHaveBeenCalled();
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
describe("on Arrow Right", () => {
|
|
162
|
+
it('call the "right" callback', async () => {
|
|
163
|
+
render(<Test />);
|
|
164
|
+
|
|
165
|
+
const button = screen.getByRole("button");
|
|
166
|
+
button.focus();
|
|
167
|
+
|
|
168
|
+
await userEvent.keyboard("[ArrowRight]");
|
|
169
|
+
|
|
170
|
+
expect(activate).not.toHaveBeenCalled();
|
|
171
|
+
expect(start).not.toHaveBeenCalled();
|
|
172
|
+
expect(end).not.toHaveBeenCalled();
|
|
173
|
+
expect(up).not.toHaveBeenCalled();
|
|
174
|
+
expect(down).not.toHaveBeenCalled();
|
|
175
|
+
expect(left).not.toHaveBeenCalled();
|
|
176
|
+
expect(right).toHaveBeenCalledTimes(1);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
describe("without any callback", () => {
|
|
181
|
+
it("does nothing", async () => {
|
|
182
|
+
const Test = () => {
|
|
183
|
+
const handle = useKeyboardControls({ activate });
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<div tabIndex={0} role='button' onKeyDown={handle}>
|
|
187
|
+
Test
|
|
188
|
+
</div>
|
|
189
|
+
);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
render(<Test />);
|
|
193
|
+
|
|
194
|
+
const button = screen.getByRole("button");
|
|
195
|
+
button.focus();
|
|
196
|
+
|
|
197
|
+
await userEvent.keyboard("[ArrowUp][ArrowUp][ArrowDown][ArrowDown][ArrowLeft][ArrowRight][ArrowLeft][ArrowRight]{b}{a}[Enter]");
|
|
198
|
+
|
|
199
|
+
expect(activate).toHaveBeenCalledTimes(1);
|
|
200
|
+
expect(start).not.toHaveBeenCalled();
|
|
201
|
+
expect(end).not.toHaveBeenCalled();
|
|
202
|
+
expect(up).not.toHaveBeenCalled();
|
|
203
|
+
expect(down).not.toHaveBeenCalled();
|
|
204
|
+
expect(left).not.toHaveBeenCalled();
|
|
205
|
+
expect(right).not.toHaveBeenCalledTimes(1);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { type KeyboardEvent, useCallback } from "react";
|
|
4
|
+
|
|
5
|
+
import { CODE, KEY } from "./keyboard.constants";
|
|
6
|
+
|
|
7
|
+
interface Options {
|
|
8
|
+
up?: VoidFunction;
|
|
9
|
+
down?: VoidFunction;
|
|
10
|
+
left?: VoidFunction;
|
|
11
|
+
right?: VoidFunction;
|
|
12
|
+
start?: VoidFunction;
|
|
13
|
+
end?: VoidFunction;
|
|
14
|
+
activate?: VoidFunction;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const isActivateKey = (event: KeyboardEvent<HTMLDivElement | HTMLButtonElement>) => {
|
|
18
|
+
return (
|
|
19
|
+
event.key === KEY.ENTER ||
|
|
20
|
+
event.key === KEY.SPACE ||
|
|
21
|
+
event.key === KEY.SPACEBAR ||
|
|
22
|
+
event.code === CODE.ENTER ||
|
|
23
|
+
event.code === CODE.SPACE
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const voidFn = () => {};
|
|
28
|
+
|
|
29
|
+
export const useKeyboardControls = ({
|
|
30
|
+
up = voidFn,
|
|
31
|
+
down = voidFn,
|
|
32
|
+
left = voidFn,
|
|
33
|
+
right = voidFn,
|
|
34
|
+
start = voidFn,
|
|
35
|
+
end = voidFn,
|
|
36
|
+
activate = voidFn
|
|
37
|
+
}: Options) => {
|
|
38
|
+
const handleKeyDown = useCallback(
|
|
39
|
+
(event: KeyboardEvent<HTMLDivElement | HTMLButtonElement>) => {
|
|
40
|
+
if (isActivateKey(event)) {
|
|
41
|
+
return activate();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (event.code === CODE.HOME) {
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
|
|
47
|
+
return start();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (event.code === CODE.END) {
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
|
|
53
|
+
return end();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (event.code === CODE.ARROW_UP) {
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
|
|
59
|
+
return up();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (event.code === CODE.ARROW_DOWN) {
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
|
|
65
|
+
return down();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (event.code === CODE.ARROW_RIGHT) {
|
|
69
|
+
event.preventDefault();
|
|
70
|
+
|
|
71
|
+
return right();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (event.code === CODE.ARROW_LEFT) {
|
|
75
|
+
event.preventDefault();
|
|
76
|
+
|
|
77
|
+
return left();
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
[activate, down, end, left, right, start, up]
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
return handleKeyDown;
|
|
84
|
+
};
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
|
|
3
3
|
import type { OperationButtonProps } from "../molecules/table/components/DefaultOperationButton.js";
|
|
4
|
+
import type { JSON } from "./SubmissionType.js";
|
|
4
5
|
|
|
5
|
-
export type
|
|
6
|
-
// export type OnClickOperation<Data = any> = (data: Data, operation: Operation) => void;
|
|
6
|
+
export type CellMetadata = Record<string, unknown>;
|
|
7
7
|
|
|
8
|
-
export
|
|
8
|
+
export type PermissionsResolver<Data extends { [key: string]: JSON } = { [key: string]: JSON }> = (
|
|
9
|
+
data: Data,
|
|
10
|
+
metadata: CellMetadata,
|
|
11
|
+
operation: Operation<Data>
|
|
12
|
+
) => void;
|
|
13
|
+
|
|
14
|
+
export interface Operation<Data extends { [key: string]: JSON } = { [key: string]: JSON }> {
|
|
9
15
|
/**
|
|
10
16
|
* Action identifier
|
|
11
17
|
*/
|