@ayasofyazilim/ui 0.0.0
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/__mocks__/canvas.ts +8 -0
- package/components.json +21 -0
- package/eslint.config.js +4 -0
- package/jest-environment.js +37 -0
- package/jest.config.ts +47 -0
- package/jest.setup.ts +69 -0
- package/package.json +124 -0
- package/postcss.config.mjs +6 -0
- package/src/aria/index.tsx +1 -0
- package/src/aria/number-field.tsx +41 -0
- package/src/components/.gitkeep +0 -0
- package/src/components/accordion.tsx +66 -0
- package/src/components/alert-dialog.tsx +157 -0
- package/src/components/alert.tsx +70 -0
- package/src/components/aspect-ratio.tsx +11 -0
- package/src/components/avatar.tsx +53 -0
- package/src/components/badge.tsx +67 -0
- package/src/components/breadcrumb.tsx +109 -0
- package/src/components/button-group.tsx +83 -0
- package/src/components/button.tsx +68 -0
- package/src/components/calendar.tsx +219 -0
- package/src/components/card.tsx +92 -0
- package/src/components/carousel.tsx +241 -0
- package/src/components/chart.tsx +363 -0
- package/src/components/checkbox.tsx +32 -0
- package/src/components/collapsible.tsx +33 -0
- package/src/components/command.tsx +184 -0
- package/src/components/context-menu.tsx +252 -0
- package/src/components/dialog.tsx +144 -0
- package/src/components/drawer.tsx +135 -0
- package/src/components/dropdown-menu.tsx +258 -0
- package/src/components/empty.tsx +100 -0
- package/src/components/field.tsx +248 -0
- package/src/components/form.tsx +169 -0
- package/src/components/hover-card.tsx +44 -0
- package/src/components/input-group.tsx +170 -0
- package/src/components/input-otp.tsx +77 -0
- package/src/components/input.tsx +21 -0
- package/src/components/item.tsx +193 -0
- package/src/components/kbd.tsx +28 -0
- package/src/components/label.tsx +24 -0
- package/src/components/menubar.tsx +276 -0
- package/src/components/navigation-menu.tsx +168 -0
- package/src/components/pagination.tsx +130 -0
- package/src/components/popover.tsx +88 -0
- package/src/components/progress.tsx +31 -0
- package/src/components/radio-group.tsx +45 -0
- package/src/components/resizable.tsx +56 -0
- package/src/components/scroll-area.tsx +58 -0
- package/src/components/select.tsx +189 -0
- package/src/components/separator.tsx +28 -0
- package/src/components/sheet.tsx +140 -0
- package/src/components/sidebar.tsx +862 -0
- package/src/components/skeleton.tsx +13 -0
- package/src/components/slider.tsx +63 -0
- package/src/components/sonner.tsx +40 -0
- package/src/components/spinner.tsx +16 -0
- package/src/components/stepper.tsx +291 -0
- package/src/components/switch.tsx +31 -0
- package/src/components/table.tsx +133 -0
- package/src/components/tabs.tsx +66 -0
- package/src/components/textarea.tsx +18 -0
- package/src/components/toggle-group.tsx +83 -0
- package/src/components/toggle.tsx +47 -0
- package/src/components/tooltip.tsx +66 -0
- package/src/custom/action-button.tsx +48 -0
- package/src/custom/async-select.tsx +287 -0
- package/src/custom/awesome-not-found.tsx +116 -0
- package/src/custom/charts/area-chart.tsx +147 -0
- package/src/custom/charts/bar-chart.tsx +233 -0
- package/src/custom/charts/chart-card.tsx +103 -0
- package/src/custom/charts/index.tsx +16 -0
- package/src/custom/charts/pie-chart.tsx +168 -0
- package/src/custom/charts/radar-chart.tsx +126 -0
- package/src/custom/checkbox-tree.tsx +100 -0
- package/src/custom/combobox.tsx +296 -0
- package/src/custom/confirm-dialog.tsx +102 -0
- package/src/custom/country-selector.tsx +204 -0
- package/src/custom/date-picker/calendar-rac.tsx +109 -0
- package/src/custom/date-picker/datefield-rac.tsx +84 -0
- package/src/custom/date-picker/index.tsx +273 -0
- package/src/custom/date-picker/types/index.ts +4 -0
- package/src/custom/date-picker/utils/index.ts +42 -0
- package/src/custom/date-picker-old.tsx +50 -0
- package/src/custom/date-tooltip.tsx +98 -0
- package/src/custom/document-scanner/consts.ts +5 -0
- package/src/custom/document-scanner/corner-adjustment/action-buttons.tsx +33 -0
- package/src/custom/document-scanner/corner-adjustment/corner-handle.tsx +43 -0
- package/src/custom/document-scanner/corner-adjustment/hooks/use-corner-drag.ts +85 -0
- package/src/custom/document-scanner/corner-adjustment/index.tsx +125 -0
- package/src/custom/document-scanner/corner-adjustment/types.ts +53 -0
- package/src/custom/document-scanner/corner-adjustment/utils/clip-path.ts +22 -0
- package/src/custom/document-scanner/corner-adjustment/zoom-magnifier.tsx +115 -0
- package/src/custom/document-scanner/hooks/use-document-capture.ts +81 -0
- package/src/custom/document-scanner/hooks/use-document-scanner.ts +80 -0
- package/src/custom/document-scanner/hooks/use-perspective-crop.ts +38 -0
- package/src/custom/document-scanner/index.tsx +255 -0
- package/src/custom/document-scanner/lib.ts +407 -0
- package/src/custom/document-scanner/types.ts +205 -0
- package/src/custom/document-scanner/utils/perspective-correction.ts +139 -0
- package/src/custom/document-viewer/controllers.tsx +98 -0
- package/src/custom/document-viewer/index.tsx +43 -0
- package/src/custom/document-viewer/renderers/image.tsx +37 -0
- package/src/custom/document-viewer/renderers/index.tsx +2 -0
- package/src/custom/document-viewer/renderers/pdf.tsx +105 -0
- package/src/custom/email-input/domains.json +159 -0
- package/src/custom/email-input/email.tsx +229 -0
- package/src/custom/email-input/index.tsx +4 -0
- package/src/custom/email-input/types.ts +104 -0
- package/src/custom/file-uploader.tsx +541 -0
- package/src/custom/filter-component/fields/async-select.tsx +33 -0
- package/src/custom/filter-component/fields/date.tsx +60 -0
- package/src/custom/filter-component/fields/multi-select.tsx +30 -0
- package/src/custom/filter-component/index.tsx +217 -0
- package/src/custom/image-canvas.tsx +260 -0
- package/src/custom/json-editor.tsx +22 -0
- package/src/custom/master-data-grid/components/dialogs/column-settings-dialog.tsx +100 -0
- package/src/custom/master-data-grid/components/dialogs/index.ts +1 -0
- package/src/custom/master-data-grid/components/filters/client-filter.tsx +368 -0
- package/src/custom/master-data-grid/components/filters/filter-input.tsx +256 -0
- package/src/custom/master-data-grid/components/filters/index.ts +3 -0
- package/src/custom/master-data-grid/components/filters/inline-column-filter.tsx +233 -0
- package/src/custom/master-data-grid/components/filters/multi-filter-dialog.tsx +90 -0
- package/src/custom/master-data-grid/components/filters/server-filter.tsx +255 -0
- package/src/custom/master-data-grid/components/master-data-grid.tsx +472 -0
- package/src/custom/master-data-grid/components/pagination/index.ts +1 -0
- package/src/custom/master-data-grid/components/pagination/pagination.tsx +178 -0
- package/src/custom/master-data-grid/components/table/cell-renderer.tsx +634 -0
- package/src/custom/master-data-grid/components/table/header-cell.tsx +162 -0
- package/src/custom/master-data-grid/components/table/index.ts +4 -0
- package/src/custom/master-data-grid/components/table/table-body-renderer.tsx +113 -0
- package/src/custom/master-data-grid/components/table/virtual-body.tsx +138 -0
- package/src/custom/master-data-grid/components/toolbar/index.ts +1 -0
- package/src/custom/master-data-grid/components/toolbar/toolbar.tsx +314 -0
- package/src/custom/master-data-grid/hooks/index.ts +3 -0
- package/src/custom/master-data-grid/hooks/use-columns.tsx +332 -0
- package/src/custom/master-data-grid/hooks/use-editing.ts +106 -0
- package/src/custom/master-data-grid/hooks/use-table-state-reducer.ts +157 -0
- package/src/custom/master-data-grid/hooks/use-table-state.ts +31 -0
- package/src/custom/master-data-grid/index.ts +16 -0
- package/src/custom/master-data-grid/types.ts +466 -0
- package/src/custom/master-data-grid/utils/column-generator.tsx +306 -0
- package/src/custom/master-data-grid/utils/export-utils.ts +67 -0
- package/src/custom/master-data-grid/utils/filter-fns.ts +290 -0
- package/src/custom/master-data-grid/utils/index.ts +8 -0
- package/src/custom/master-data-grid/utils/pinning-utils.ts +88 -0
- package/src/custom/master-data-grid/utils/translation-utils.ts +42 -0
- package/src/custom/multi-select.tsx +432 -0
- package/src/custom/password-input.tsx +194 -0
- package/src/custom/phone-input.tsx +172 -0
- package/src/custom/schema-form/custom/index.tsx +1 -0
- package/src/custom/schema-form/custom/label.tsx +53 -0
- package/src/custom/schema-form/fields/base-input-field.tsx +82 -0
- package/src/custom/schema-form/fields/field.tsx +67 -0
- package/src/custom/schema-form/fields/index.tsx +5 -0
- package/src/custom/schema-form/fields/object.tsx +12 -0
- package/src/custom/schema-form/fields/table-array/array-field-item.tsx +90 -0
- package/src/custom/schema-form/fields/table-array/array-field-template.tsx +115 -0
- package/src/custom/schema-form/index.tsx +259 -0
- package/src/custom/schema-form/templates/description.tsx +20 -0
- package/src/custom/schema-form/templates/index.tsx +2 -0
- package/src/custom/schema-form/templates/submit.tsx +32 -0
- package/src/custom/schema-form/types.ts +64 -0
- package/src/custom/schema-form/utils/index.ts +4 -0
- package/src/custom/schema-form/utils/schema-dependency.ts +655 -0
- package/src/custom/schema-form/utils/schemas.ts +289 -0
- package/src/custom/schema-form/utils/validation.ts +23 -0
- package/src/custom/schema-form/widgets/boolean.tsx +77 -0
- package/src/custom/schema-form/widgets/combobox.tsx +274 -0
- package/src/custom/schema-form/widgets/date.tsx +59 -0
- package/src/custom/schema-form/widgets/email.tsx +34 -0
- package/src/custom/schema-form/widgets/index.tsx +10 -0
- package/src/custom/schema-form/widgets/password.tsx +40 -0
- package/src/custom/schema-form/widgets/phone.tsx +40 -0
- package/src/custom/schema-form/widgets/select.tsx +105 -0
- package/src/custom/schema-form/widgets/selectable.tsx +25 -0
- package/src/custom/schema-form/widgets/string-array.tsx +296 -0
- package/src/custom/schema-form/widgets/url.tsx +56 -0
- package/src/custom/section-layout-v2.tsx +212 -0
- package/src/custom/select-tabs.tsx +109 -0
- package/src/custom/selectable.tsx +316 -0
- package/src/custom/stepper.tsx +236 -0
- package/src/custom/tab-layout.tsx +213 -0
- package/src/custom/tanstack-table/fields/index.tsx +12 -0
- package/src/custom/tanstack-table/fields/tanstack-table-action-dialogs.tsx +89 -0
- package/src/custom/tanstack-table/fields/tanstack-table-column-header.tsx +66 -0
- package/src/custom/tanstack-table/fields/tanstack-table-filter-date.tsx +180 -0
- package/src/custom/tanstack-table/fields/tanstack-table-filter-faceted.tsx +158 -0
- package/src/custom/tanstack-table/fields/tanstack-table-filter-text.tsx +76 -0
- package/src/custom/tanstack-table/fields/tanstack-table-pagination.tsx +136 -0
- package/src/custom/tanstack-table/fields/tanstack-table-plain-table.tsx +142 -0
- package/src/custom/tanstack-table/fields/tanstack-table-row-actions-confirmation.tsx +77 -0
- package/src/custom/tanstack-table/fields/tanstack-table-row-actions-custom-dialog.tsx +87 -0
- package/src/custom/tanstack-table/fields/tanstack-table-row-actions.tsx +151 -0
- package/src/custom/tanstack-table/fields/tanstack-table-table-actions-custom-dialog.tsx +88 -0
- package/src/custom/tanstack-table/fields/tanstack-table-table-actions-schemaform-dialog.tsx +47 -0
- package/src/custom/tanstack-table/fields/tanstack-table-toolbar.tsx +143 -0
- package/src/custom/tanstack-table/fields/tanstack-table-view-options.tsx +171 -0
- package/src/custom/tanstack-table/index.tsx +244 -0
- package/src/custom/tanstack-table/types/index.ts +328 -0
- package/src/custom/tanstack-table/utils/cell-with-actions.tsx +21 -0
- package/src/custom/tanstack-table/utils/column-names.ts +26 -0
- package/src/custom/tanstack-table/utils/columns-by-row-data.tsx +312 -0
- package/src/custom/tanstack-table/utils/editable-columns-by-row-data.tsx +219 -0
- package/src/custom/tanstack-table/utils/faceted-boolean-options.tsx +22 -0
- package/src/custom/tanstack-table/utils/index.tsx +10 -0
- package/src/custom/tanstack-table/utils/pinning-styles.ts +57 -0
- package/src/custom/tanstack-table/utils/table.tsx +83 -0
- package/src/custom/tanstack-table/utils/test-conditions.ts +17 -0
- package/src/custom/timeline.tsx +208 -0
- package/src/custom/tree.tsx +200 -0
- package/src/custom/tscanify/browser.ts +66 -0
- package/src/custom/tscanify/index.ts +51 -0
- package/src/custom/tscanify/tscanify-browser.ts +522 -0
- package/src/custom/tscanify/tscanify.ts +262 -0
- package/src/custom/tscanify/types.ts +22 -0
- package/src/custom/webcam.tsx +737 -0
- package/src/hooks/.gitkeep +0 -0
- package/src/hooks/use-callback-ref.ts +27 -0
- package/src/hooks/use-controllable-state.ts +67 -0
- package/src/hooks/use-debounce.ts +19 -0
- package/src/hooks/use-is-visible.ts +23 -0
- package/src/hooks/use-media-query.ts +21 -0
- package/src/hooks/use-mobile.ts +21 -0
- package/src/hooks/use-on-window-resize.ts +15 -0
- package/src/hooks/use-scroll.tsx +22 -0
- package/src/lib/utils.ts +61 -0
- package/src/lib/zod.ts +2 -0
- package/src/styles/core.css +57 -0
- package/src/styles/globals.css +130 -0
- package/src/test/email-input.test.tsx +217 -0
- package/src/test/password-input.test.tsx +92 -0
- package/src/test/select-tabs.test.tsx +302 -0
- package/src/test/selectable.test.tsx +1093 -0
- package/tsconfig.json +13 -0
- package/tsconfig.lint.json +8 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { useCallback, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
export interface UseEditingProps<TData> {
|
|
4
|
+
data: TData[];
|
|
5
|
+
getRowId?: (row: TData, index: number) => string;
|
|
6
|
+
onDataChange?: (data: TData[]) => void;
|
|
7
|
+
editingRows: Record<string, Record<string, unknown>>;
|
|
8
|
+
setEditingRows: (
|
|
9
|
+
updater: (
|
|
10
|
+
prev: Record<string, Record<string, unknown>>
|
|
11
|
+
) => Record<string, Record<string, unknown>>
|
|
12
|
+
) => void;
|
|
13
|
+
editing?: {
|
|
14
|
+
isRowEditable?: (row: TData) => boolean;
|
|
15
|
+
onRowSave?: (row: TData, changes: Partial<TData>) => void | Promise<void>;
|
|
16
|
+
onRowCancel?: (row: TData) => void;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface UseEditingReturn<TData> {
|
|
21
|
+
editingRowsRef: React.RefObject<Record<string, Record<string, unknown>>>;
|
|
22
|
+
startEditingRow: (rowId: string, row: TData) => void;
|
|
23
|
+
cancelEditingRow: (rowId: string, row: TData) => void;
|
|
24
|
+
saveEditingRow: (rowId: string, row: TData) => Promise<void>;
|
|
25
|
+
updateCellValue: (rowId: string, columnId: string, value: unknown) => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function useEditing<TData>({
|
|
29
|
+
data,
|
|
30
|
+
getRowId,
|
|
31
|
+
onDataChange,
|
|
32
|
+
editingRows,
|
|
33
|
+
setEditingRows,
|
|
34
|
+
editing,
|
|
35
|
+
}: UseEditingProps<TData>): UseEditingReturn<TData> {
|
|
36
|
+
const editingRowsRef = useRef<Record<string, Record<string, unknown>>>({});
|
|
37
|
+
editingRowsRef.current = editingRows;
|
|
38
|
+
|
|
39
|
+
const startEditingRow = useCallback(
|
|
40
|
+
(rowId: string, row: TData) => {
|
|
41
|
+
if (editing?.isRowEditable && !editing.isRowEditable(row)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
setEditingRows((prev) => ({ ...prev, [rowId]: {} }));
|
|
45
|
+
},
|
|
46
|
+
[editing, setEditingRows]
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const cancelEditingRow = useCallback(
|
|
50
|
+
(rowId: string, row: TData) => {
|
|
51
|
+
setEditingRows((prev) => {
|
|
52
|
+
const { [rowId]: removed, ...rest } = prev;
|
|
53
|
+
return rest;
|
|
54
|
+
});
|
|
55
|
+
editing?.onRowCancel?.(row);
|
|
56
|
+
},
|
|
57
|
+
[editing, setEditingRows]
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const saveEditingRow = useCallback(
|
|
61
|
+
async (rowId: string, row: TData) => {
|
|
62
|
+
const changes = editingRowsRef.current[rowId] || {};
|
|
63
|
+
const typedChanges = changes as Partial<TData>;
|
|
64
|
+
|
|
65
|
+
if (editing?.onRowSave) {
|
|
66
|
+
await editing.onRowSave(row, typedChanges);
|
|
67
|
+
}
|
|
68
|
+
if (onDataChange && Object.keys(changes).length > 0) {
|
|
69
|
+
const updatedData = data.map((item) => {
|
|
70
|
+
const itemId = getRowId
|
|
71
|
+
? getRowId(item, data.indexOf(item))
|
|
72
|
+
: String(data.indexOf(item));
|
|
73
|
+
return itemId === rowId ? { ...item, ...typedChanges } : item;
|
|
74
|
+
});
|
|
75
|
+
onDataChange(updatedData);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
setEditingRows((prev) => {
|
|
79
|
+
const { [rowId]: removed, ...rest } = prev;
|
|
80
|
+
return rest;
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
[data, onDataChange, getRowId, editing, setEditingRows]
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const updateCellValue = useCallback(
|
|
87
|
+
(rowId: string, columnId: string, value: unknown) => {
|
|
88
|
+
setEditingRows((prev) => ({
|
|
89
|
+
...prev,
|
|
90
|
+
[rowId]: {
|
|
91
|
+
...prev[rowId],
|
|
92
|
+
[columnId]: value,
|
|
93
|
+
},
|
|
94
|
+
}));
|
|
95
|
+
},
|
|
96
|
+
[setEditingRows]
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
editingRowsRef,
|
|
101
|
+
startEditingRow,
|
|
102
|
+
cancelEditingRow,
|
|
103
|
+
saveEditingRow,
|
|
104
|
+
updateCellValue,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ColumnFiltersState,
|
|
3
|
+
ColumnPinningState,
|
|
4
|
+
RowSelectionState,
|
|
5
|
+
SortingState,
|
|
6
|
+
VisibilityState,
|
|
7
|
+
} from "@tanstack/react-table";
|
|
8
|
+
import { useReducer } from "react";
|
|
9
|
+
import type { MasterDataGridConfig, TableState } from "../types";
|
|
10
|
+
|
|
11
|
+
type TableStateAction =
|
|
12
|
+
| { type: "SET_SORTING"; payload: SortingState }
|
|
13
|
+
| { type: "SET_COLUMN_FILTERS"; payload: ColumnFiltersState }
|
|
14
|
+
| { type: "SET_COLUMN_VISIBILITY"; payload: VisibilityState }
|
|
15
|
+
| { type: "SET_ROW_SELECTION"; payload: RowSelectionState }
|
|
16
|
+
| { type: "SET_COLUMN_PINNING"; payload: ColumnPinningState }
|
|
17
|
+
| { type: "SET_GROUPING"; payload: string[] }
|
|
18
|
+
| { type: "SET_EXPANDED"; payload: Record<string, boolean> | true }
|
|
19
|
+
| {
|
|
20
|
+
type: "SET_PAGINATION";
|
|
21
|
+
payload: { pageIndex: number; pageSize: number };
|
|
22
|
+
}
|
|
23
|
+
| {
|
|
24
|
+
type: "UPDATE_EDITING_ROWS";
|
|
25
|
+
payload:
|
|
26
|
+
| Record<string, Record<string, unknown>>
|
|
27
|
+
| ((
|
|
28
|
+
prev: Record<string, Record<string, unknown>>
|
|
29
|
+
) => Record<string, Record<string, unknown>>);
|
|
30
|
+
}
|
|
31
|
+
| { type: "RESET"; payload: TableState };
|
|
32
|
+
|
|
33
|
+
function tableStateReducer(
|
|
34
|
+
state: TableState,
|
|
35
|
+
action: TableStateAction
|
|
36
|
+
): TableState {
|
|
37
|
+
switch (action.type) {
|
|
38
|
+
case "SET_SORTING":
|
|
39
|
+
return { ...state, sorting: action.payload };
|
|
40
|
+
case "SET_COLUMN_FILTERS":
|
|
41
|
+
return { ...state, columnFilters: action.payload };
|
|
42
|
+
case "SET_COLUMN_VISIBILITY":
|
|
43
|
+
return { ...state, columnVisibility: action.payload };
|
|
44
|
+
case "SET_ROW_SELECTION":
|
|
45
|
+
return { ...state, rowSelection: action.payload };
|
|
46
|
+
case "SET_COLUMN_PINNING":
|
|
47
|
+
return { ...state, columnPinning: action.payload };
|
|
48
|
+
case "SET_GROUPING":
|
|
49
|
+
return { ...state, grouping: action.payload };
|
|
50
|
+
case "SET_EXPANDED":
|
|
51
|
+
return { ...state, expanded: action.payload };
|
|
52
|
+
case "SET_PAGINATION":
|
|
53
|
+
return { ...state, pagination: action.payload };
|
|
54
|
+
case "UPDATE_EDITING_ROWS":
|
|
55
|
+
return {
|
|
56
|
+
...state,
|
|
57
|
+
editingRows:
|
|
58
|
+
typeof action.payload === "function"
|
|
59
|
+
? action.payload(state.editingRows || {})
|
|
60
|
+
: action.payload,
|
|
61
|
+
};
|
|
62
|
+
case "RESET":
|
|
63
|
+
return action.payload;
|
|
64
|
+
default:
|
|
65
|
+
return state;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function initializeColumnVisibility<TData>(
|
|
70
|
+
config: MasterDataGridConfig<TData>
|
|
71
|
+
): VisibilityState {
|
|
72
|
+
if (!config.columnVisibility) {
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (config.columnVisibility.mode === "hide") {
|
|
77
|
+
return Object.fromEntries(
|
|
78
|
+
config.columnVisibility.columns.map((id) => [String(id), false])
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (config.columnVisibility.mode === "show") {
|
|
83
|
+
const allColumnIds: string[] = [
|
|
84
|
+
...(config.columns?.map((c) => c.id) || []),
|
|
85
|
+
...(config.schema ? Object.keys(config.schema.properties || {}) : []),
|
|
86
|
+
];
|
|
87
|
+
return Object.fromEntries(
|
|
88
|
+
allColumnIds.map((id) => [
|
|
89
|
+
String(id),
|
|
90
|
+
config.columnVisibility!.columns.map(String).includes(String(id)),
|
|
91
|
+
])
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return {};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function createInitialState<TData>(
|
|
99
|
+
config: MasterDataGridConfig<TData>,
|
|
100
|
+
pageSize: number
|
|
101
|
+
): TableState {
|
|
102
|
+
return {
|
|
103
|
+
sorting: [],
|
|
104
|
+
columnFilters: [],
|
|
105
|
+
columnVisibility: initializeColumnVisibility(config),
|
|
106
|
+
rowSelection: {},
|
|
107
|
+
columnPinning: config.pinning || {},
|
|
108
|
+
grouping: config.grouping?.groupBy || [],
|
|
109
|
+
expanded: config.grouping?.expanded || {},
|
|
110
|
+
pagination: {
|
|
111
|
+
pageIndex: 0,
|
|
112
|
+
pageSize,
|
|
113
|
+
},
|
|
114
|
+
editingRows: {},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function useTableStateReducer<TData>(
|
|
119
|
+
config: MasterDataGridConfig<TData>,
|
|
120
|
+
pageSize: number
|
|
121
|
+
) {
|
|
122
|
+
const [tableState, dispatch] = useReducer(tableStateReducer, undefined, () =>
|
|
123
|
+
createInitialState(config, pageSize)
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
tableState,
|
|
128
|
+
setSorting: (payload: SortingState) =>
|
|
129
|
+
dispatch({ type: "SET_SORTING", payload }),
|
|
130
|
+
setColumnFilters: (payload: ColumnFiltersState) =>
|
|
131
|
+
dispatch({ type: "SET_COLUMN_FILTERS", payload }),
|
|
132
|
+
setColumnVisibility: (payload: VisibilityState) =>
|
|
133
|
+
dispatch({ type: "SET_COLUMN_VISIBILITY", payload }),
|
|
134
|
+
setRowSelection: (payload: RowSelectionState) =>
|
|
135
|
+
dispatch({ type: "SET_ROW_SELECTION", payload }),
|
|
136
|
+
setColumnPinning: (payload: ColumnPinningState) =>
|
|
137
|
+
dispatch({ type: "SET_COLUMN_PINNING", payload }),
|
|
138
|
+
setGrouping: (payload: string[]) =>
|
|
139
|
+
dispatch({ type: "SET_GROUPING", payload }),
|
|
140
|
+
setExpanded: (payload: Record<string, boolean> | true) =>
|
|
141
|
+
dispatch({ type: "SET_EXPANDED", payload }),
|
|
142
|
+
setPagination: (payload: { pageIndex: number; pageSize: number }) =>
|
|
143
|
+
dispatch({ type: "SET_PAGINATION", payload }),
|
|
144
|
+
updateEditingRows: (
|
|
145
|
+
payload:
|
|
146
|
+
| Record<string, Record<string, unknown>>
|
|
147
|
+
| ((
|
|
148
|
+
prev: Record<string, Record<string, unknown>>
|
|
149
|
+
) => Record<string, Record<string, unknown>>)
|
|
150
|
+
) => dispatch({ type: "UPDATE_EDITING_ROWS", payload }),
|
|
151
|
+
resetToDefaults: () =>
|
|
152
|
+
dispatch({
|
|
153
|
+
type: "RESET",
|
|
154
|
+
payload: createInitialState(config, pageSize),
|
|
155
|
+
}),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import type { TableState } from "../types";
|
|
3
|
+
|
|
4
|
+
interface UseTableStateOptions {
|
|
5
|
+
pageSize?: number;
|
|
6
|
+
groupBy?: string[];
|
|
7
|
+
expanded?: Record<string, boolean>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function useTableState(options: UseTableStateOptions = {}) {
|
|
11
|
+
const { pageSize = 10, groupBy = [], expanded = {} } = options;
|
|
12
|
+
|
|
13
|
+
const [tableState, setTableState] = useState<TableState>(() => {
|
|
14
|
+
return {
|
|
15
|
+
sorting: [],
|
|
16
|
+
columnFilters: [],
|
|
17
|
+
columnVisibility: {},
|
|
18
|
+
rowSelection: {},
|
|
19
|
+
columnPinning: { left: [], right: [] },
|
|
20
|
+
grouping: groupBy,
|
|
21
|
+
expanded,
|
|
22
|
+
pagination: {
|
|
23
|
+
pageIndex: 0,
|
|
24
|
+
pageSize,
|
|
25
|
+
},
|
|
26
|
+
editingRows: {},
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return [tableState, setTableState] as const;
|
|
31
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { MasterDataGrid } from "./components/master-data-grid";
|
|
2
|
+
export type {
|
|
3
|
+
MasterDataGridProps,
|
|
4
|
+
MasterDataGridConfig,
|
|
5
|
+
JSONSchema,
|
|
6
|
+
JSONSchemaProperty,
|
|
7
|
+
ColumnConfig,
|
|
8
|
+
RowAction,
|
|
9
|
+
TableAction,
|
|
10
|
+
FilterOperator,
|
|
11
|
+
SelectionConfig,
|
|
12
|
+
VirtualizationConfig,
|
|
13
|
+
GroupingConfig,
|
|
14
|
+
PinningConfig,
|
|
15
|
+
ExportConfig,
|
|
16
|
+
} from "./types";
|