@vuu-ui/vuu-table-extras 5.0.0-alpha.2 → 5.0.0-alpha.3
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/package.json +13 -13
- package/src/bulk-edit-dialog/useBulkEditDialog.js +93 -0
- package/src/editable-table/EditableTable.css.js +41 -0
- package/src/editable-table/EditableTable.js +176 -0
- package/src/editable-table/EditableTableLayout.js +61 -0
- package/src/index.js +4 -0
- package/src/table-editor/TableEditorContext.js +9 -0
- package/src/table-editor/TableEditorControls.js +86 -0
- package/src/table-editor/TableEditorForm.js +142 -0
- package/src/table-editor/TableEditorLayout.css.js +16 -0
- package/src/table-editor/TableEditorLayout.js +30 -0
- package/src/table-editor/TableEditorProvider.js +434 -0
- package/src/table-editor/TableEditorTable.js +112 -0
- package/src/table-editor/index.js +5 -0
- package/types/bulk-edit-dialog/useBulkEditDialog.d.ts +27 -0
- package/types/editable-table/EditableTable.d.ts +178 -0
- package/types/editable-table/EditableTableLayout.d.ts +41 -0
- package/types/index.d.ts +4 -0
- package/types/inline-add-row/useInlineAddRow.d.ts +1 -0
- package/types/table-editor/TableEditorContext.d.ts +100 -0
- package/types/table-editor/TableEditorControls.d.ts +43 -0
- package/types/table-editor/TableEditorForm.d.ts +58 -0
- package/types/table-editor/TableEditorLayout.d.ts +10 -0
- package/types/table-editor/TableEditorProvider.d.ts +57 -0
- package/types/table-editor/TableEditorTable.d.ts +24 -0
- package/types/table-editor/index.d.ts +5 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import type { EditableTableHookProps, EditFormValidator } from "@vuu-ui/vuu-data-editing";
|
|
2
|
+
import type { DataSource, DataValueDescriptor } from "@vuu-ui/vuu-data-types";
|
|
3
|
+
import type { TableProps } from "@vuu-ui/vuu-table";
|
|
4
|
+
import type { DataRow, TableConfig } from "@vuu-ui/vuu-table-types";
|
|
5
|
+
import type { CSSProperties, ReactNode } from "react";
|
|
6
|
+
import { type TableEditorCreateStrategy, type TableEditorEditModel, type TableEditorEditStrategy, type TableEditorMode, type TableEditorPanelVisibility } from "../table-editor";
|
|
7
|
+
/** `create` is only used with a create form. */
|
|
8
|
+
export type EditableTableMode = TableEditorMode;
|
|
9
|
+
/**
|
|
10
|
+
* - `session`: edits are staged in a session table and applied on Save, or
|
|
11
|
+
* discarded on Cancel.
|
|
12
|
+
* - `direct`: each committed edit is sent straight to `dataSource`. There
|
|
13
|
+
* is no Save or Cancel.
|
|
14
|
+
*/
|
|
15
|
+
export type EditableTableEditModel = TableEditorEditModel;
|
|
16
|
+
/**
|
|
17
|
+
* - `inline`: cells are edited in the table.
|
|
18
|
+
* - `form`: the selected row is edited in a form in a side panel.
|
|
19
|
+
*/
|
|
20
|
+
export type EditableTableEditStrategy = TableEditorEditStrategy;
|
|
21
|
+
/**
|
|
22
|
+
* - `inline`: new rows are added in the table (`showInlineAddRow`).
|
|
23
|
+
* - `form`: new rows are added with a form in a side panel.
|
|
24
|
+
*/
|
|
25
|
+
export type EditableTableCreateStrategy = TableEditorCreateStrategy;
|
|
26
|
+
/**
|
|
27
|
+
* - `on-select`: the side panel opens when a row is selected (or New is
|
|
28
|
+
* clicked) and closes when the selection is cleared or the panel's close
|
|
29
|
+
* button is clicked.
|
|
30
|
+
* - `always`: the side panel is always visible, showing a placeholder when
|
|
31
|
+
* no row is selected.
|
|
32
|
+
*/
|
|
33
|
+
export type EditableTablePanelVisibility = TableEditorPanelVisibility;
|
|
34
|
+
export type EditableTableField = DataValueDescriptor;
|
|
35
|
+
type Never<T> = {
|
|
36
|
+
[K in keyof T]?: never;
|
|
37
|
+
};
|
|
38
|
+
/** Props for every strategy and model. */
|
|
39
|
+
export interface EditableTableBaseProps extends Pick<EditableTableHookProps, "deleteMode" | "editSessionApi" | "onError" | "rowDefaults"> {
|
|
40
|
+
className?: string;
|
|
41
|
+
/** Asked before unsaved changes are discarded. See `useConfirmDiscard`. */
|
|
42
|
+
confirmCancel?: () => boolean | Promise<boolean>;
|
|
43
|
+
/** The source (view) dataSource. */
|
|
44
|
+
dataSource: DataSource;
|
|
45
|
+
/**
|
|
46
|
+
* Uncontrolled initial mode. Defaults to `edit` (always editable) for
|
|
47
|
+
* inline direct editing, otherwise to `view`.
|
|
48
|
+
*/
|
|
49
|
+
defaultMode?: EditableTableMode;
|
|
50
|
+
/** Controlled mode. Pair with `onModeChange`. */
|
|
51
|
+
mode?: EditableTableMode;
|
|
52
|
+
/** Called once changes, or a new row, have been discarded. */
|
|
53
|
+
onCancelled?: () => void;
|
|
54
|
+
onModeChange?: (mode: EditableTableMode) => void;
|
|
55
|
+
/** Called once changes, or a new row, have been saved. */
|
|
56
|
+
onSaved?: () => void;
|
|
57
|
+
/** With a side panel. @default "on-select" */
|
|
58
|
+
panelVisibility?: EditableTablePanelVisibility;
|
|
59
|
+
style?: CSSProperties;
|
|
60
|
+
/** Suffix appended to built-in test ids (`edit-table`, `toggle-edit` …). */
|
|
61
|
+
testId?: string;
|
|
62
|
+
}
|
|
63
|
+
/** Inline session editing only. */
|
|
64
|
+
export interface EditableTableSessionOnlyProps {
|
|
65
|
+
/**
|
|
66
|
+
* Show a checkbox column and a Delete button in edit mode, so selected
|
|
67
|
+
* rows can be deleted. Rows already marked for deletion cannot be selected.
|
|
68
|
+
*/
|
|
69
|
+
allowDelete?: boolean;
|
|
70
|
+
/** Rows copied into the edit session. @default "All" */
|
|
71
|
+
copyOption?: EditableTableHookProps["copyOption"];
|
|
72
|
+
}
|
|
73
|
+
/** Inline session editing, default layout only. */
|
|
74
|
+
export interface EditableTableSessionLayoutProps {
|
|
75
|
+
/** @default "Save" */
|
|
76
|
+
saveLabel?: string;
|
|
77
|
+
/** Show an inline row, above the column headers, for adding new rows. */
|
|
78
|
+
showInlineAddRow?: boolean;
|
|
79
|
+
/** Add a column with an undo button for edited rows. */
|
|
80
|
+
undoColumn?: boolean;
|
|
81
|
+
}
|
|
82
|
+
/** Inline editing, default layout only. */
|
|
83
|
+
export interface EditableTableInlineLayoutProps {
|
|
84
|
+
/**
|
|
85
|
+
* Show a View/Edit toggle above the table. Defaults to true for session
|
|
86
|
+
* editing and false (always editable) for direct editing.
|
|
87
|
+
*/
|
|
88
|
+
showEditModeToggle?: boolean;
|
|
89
|
+
}
|
|
90
|
+
/** Form editing, default layout only. */
|
|
91
|
+
export interface EditableTableFormLayoutProps {
|
|
92
|
+
/** Show a New button and a form for adding rows. @default true */
|
|
93
|
+
allowCreate?: boolean;
|
|
94
|
+
/** Fields for the edit form, in tab order. Generated when omitted. */
|
|
95
|
+
fields?: readonly EditableTableField[];
|
|
96
|
+
/** Title shown in the side panel header for the selected row. */
|
|
97
|
+
formTitle?: string | ((dataRow: DataRow) => string);
|
|
98
|
+
/** @default "Select a row to see its details" */
|
|
99
|
+
placeholder?: string;
|
|
100
|
+
/** Validates the edit form. */
|
|
101
|
+
validate?: EditFormValidator;
|
|
102
|
+
}
|
|
103
|
+
/** With a create form, default layout only. */
|
|
104
|
+
export interface EditableTableCreateLayoutProps {
|
|
105
|
+
/** Fields for the create form. Defaults to `fields`, or generated. */
|
|
106
|
+
createFields?: readonly EditableTableField[];
|
|
107
|
+
/** @default "New" */
|
|
108
|
+
createTitle?: string;
|
|
109
|
+
/** Applied to the SidePanel, e.g. to set `--saltSidePanel-width`. */
|
|
110
|
+
panelClassName?: string;
|
|
111
|
+
/** Validates the create form. Defaults to `validate`. */
|
|
112
|
+
validateCreate?: EditFormValidator;
|
|
113
|
+
}
|
|
114
|
+
/** The default layout. Other `Table` props are passed to the table. */
|
|
115
|
+
export interface EditableTableDefaultLayoutProps extends Omit<TableProps, "children" | "className" | "config" | "customHeader" | "dataSource" | "isRowSelectable" | "onError" | "selectionModel" | "style"> {
|
|
116
|
+
children?: undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Table config. Per-column `editable` and `editor` (on each column's
|
|
119
|
+
* `DataValueDescriptor`) control what can be edited, and how.
|
|
120
|
+
*/
|
|
121
|
+
config: TableConfig;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Your own layout: compose `TableEditorTable`, `EditableTableFooter`,
|
|
125
|
+
* `TableEditorToolbar`, `EditableTableMain`, `EditableTablePanel`,
|
|
126
|
+
* `TableEditorForm`, `TableEditorCreateForm` etc.
|
|
127
|
+
*/
|
|
128
|
+
export interface EditableTableComposedProps {
|
|
129
|
+
children: ReactNode;
|
|
130
|
+
config?: never;
|
|
131
|
+
}
|
|
132
|
+
type SessionModel = {
|
|
133
|
+
editModel?: "session";
|
|
134
|
+
};
|
|
135
|
+
type DirectModel = {
|
|
136
|
+
editModel: "direct";
|
|
137
|
+
} & Never<EditableTableSessionOnlyProps & EditableTableSessionLayoutProps>;
|
|
138
|
+
type InlineStrategy = {
|
|
139
|
+
createStrategy?: "inline";
|
|
140
|
+
editStrategy?: "inline";
|
|
141
|
+
} & Never<EditableTableFormLayoutProps & EditableTableCreateLayoutProps>;
|
|
142
|
+
type InlineWithCreateForm = {
|
|
143
|
+
createStrategy: "form";
|
|
144
|
+
editStrategy?: "inline";
|
|
145
|
+
} & Never<EditableTableFormLayoutProps & Pick<EditableTableSessionLayoutProps, "showInlineAddRow">>;
|
|
146
|
+
type FormStrategy = {
|
|
147
|
+
createStrategy?: "form";
|
|
148
|
+
editStrategy: "form";
|
|
149
|
+
} & Never<EditableTableSessionOnlyProps & EditableTableSessionLayoutProps & EditableTableInlineLayoutProps>;
|
|
150
|
+
type Layout = EditableTableComposedProps | (EditableTableDefaultLayoutProps & EditableTableSessionLayoutProps & EditableTableInlineLayoutProps & EditableTableFormLayoutProps & EditableTableCreateLayoutProps);
|
|
151
|
+
export type EditableTableProps = EditableTableBaseProps & EditableTableSessionOnlyProps & (SessionModel | DirectModel) & (InlineStrategy | InlineWithCreateForm | FormStrategy) & Layout;
|
|
152
|
+
/**
|
|
153
|
+
* A Table with editing. All the wiring (edit session, editable columns, row
|
|
154
|
+
* styling, forms, Save/Cancel/Delete buttons, the inline add row) is
|
|
155
|
+
* handled internally.
|
|
156
|
+
*
|
|
157
|
+
* - `editStrategy="inline"` (the default): cells are edited in the table.
|
|
158
|
+
* `createStrategy="form"` adds new rows with a form in a side panel.
|
|
159
|
+
* - `editStrategy="form"`: selecting a row shows it in a form in a side
|
|
160
|
+
* panel; Edit makes it editable and New shows a form for a new row.
|
|
161
|
+
*
|
|
162
|
+
* - `editModel="session"` (the default): edits are staged in an edit
|
|
163
|
+
* session and applied when the user saves.
|
|
164
|
+
* - `editModel="direct"`: each committed edit is sent straight to
|
|
165
|
+
* `dataSource`. There is no Save or Cancel.
|
|
166
|
+
*
|
|
167
|
+
* What can be edited, and how, comes from the server schema and each
|
|
168
|
+
* column's `editable` and `editor`. Forms are generated from the schema
|
|
169
|
+
* unless you pass `fields` or compose your own.
|
|
170
|
+
*
|
|
171
|
+
* Renders a flex container that fills its parent (a row, with the side
|
|
172
|
+
* panel, when there is one). Without `children` it renders a default
|
|
173
|
+
* layout. Otherwise it holds `children`: compose `TableEditorTable`,
|
|
174
|
+
* `EditableTableFooter`, `EditableTableMain`, `EditableTablePanel`,
|
|
175
|
+
* `TableEditorForm` etc. Read the state with `useTableEditor`.
|
|
176
|
+
*/
|
|
177
|
+
export declare const EditableTable: (props: EditableTableProps) => import("react").JSX.Element;
|
|
178
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type SidePanelHeaderProps, type SidePanelProps } from "@salt-ds/core";
|
|
2
|
+
import { type HTMLAttributes } from "react";
|
|
3
|
+
export interface EditableTableFooterProps extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
/** @default "Save" */
|
|
5
|
+
saveLabel?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The footer of an `EditableTable`. Shows Save and Cancel (and Delete)
|
|
9
|
+
* while a session is being edited, and `children` otherwise. `children`
|
|
10
|
+
* default to the row count. With direct editing there is nothing to save,
|
|
11
|
+
* so it always shows `children`.
|
|
12
|
+
*/
|
|
13
|
+
export declare const EditableTableFooter: ({ children, saveLabel, ...htmlAttributes }: EditableTableFooterProps) => import("react").JSX.Element;
|
|
14
|
+
export type EditableTableMainProps = HTMLAttributes<HTMLDivElement>;
|
|
15
|
+
/**
|
|
16
|
+
* With a side panel (`editStrategy="form"` or `createStrategy="form"`): a
|
|
17
|
+
* flex column that fills the space beside the `EditableTablePanel`. Holds a
|
|
18
|
+
* `TableEditorTable` and whatever headers, toolbars or footers belong with
|
|
19
|
+
* it.
|
|
20
|
+
*/
|
|
21
|
+
export declare const EditableTableMain: import("react").ForwardRefExoticComponent<EditableTableMainProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
22
|
+
export type EditableTablePanelProps = Omit<SidePanelProps, "position">;
|
|
23
|
+
/**
|
|
24
|
+
* The Salt `SidePanel`, on the right, that holds the form. `EditableTable`
|
|
25
|
+
* opens and closes it. Use with `editStrategy="form"` or
|
|
26
|
+
* `createStrategy="form"`. Compose `SidePanelHeader` and `SidePanelContent`.
|
|
27
|
+
*/
|
|
28
|
+
export declare const EditableTablePanel: import("react").ForwardRefExoticComponent<Omit<EditableTablePanelProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
29
|
+
export interface EditableTablePanelHeaderProps extends SidePanelHeaderProps {
|
|
30
|
+
/**
|
|
31
|
+
* Render a close button after the children. It is hidden while the panel
|
|
32
|
+
* can't be closed, i.e. while editing. Defaults to true.
|
|
33
|
+
*/
|
|
34
|
+
canClose?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The Salt `SidePanelHeader` of a `EditableTablePanel`. Its first child
|
|
38
|
+
* fills the available width; a close button follows unless `canClose` is
|
|
39
|
+
* false.
|
|
40
|
+
*/
|
|
41
|
+
export declare const EditableTablePanelHeader: import("react").ForwardRefExoticComponent<Omit<EditableTablePanelHeaderProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
package/types/index.d.ts
CHANGED
|
@@ -23,3 +23,7 @@ export { TabbedTableSettingsAction } from "./tabbed-table-config-panel/TabbedTab
|
|
|
23
23
|
export { TableFooter, TableFooterTray } from "./table-footer/TableFooter";
|
|
24
24
|
export { TableProvider, useTableContext } from "./table-provider/TableProvider";
|
|
25
25
|
export { defaultTableSettingsPermissions, TableSettingsPanel, type TableDisplayAttributeChangeHandler, } from "./table-settings-panel/TableSettingsPanel";
|
|
26
|
+
export { type BulkEditDialogHookProps, useBulkEditDialog, } from "./bulk-edit-dialog/useBulkEditDialog";
|
|
27
|
+
export { EditableTable, type EditableTableBaseProps, type EditableTableComposedProps, type EditableTableCreateLayoutProps, type EditableTableCreateStrategy, type EditableTableDefaultLayoutProps, type EditableTableEditModel, type EditableTableEditStrategy, type EditableTableField, type EditableTableFormLayoutProps, type EditableTableInlineLayoutProps, type EditableTableMode, type EditableTablePanelVisibility, type EditableTableProps, type EditableTableSessionLayoutProps, type EditableTableSessionOnlyProps, } from "./editable-table/EditableTable";
|
|
28
|
+
export { EditableTableFooter, type EditableTableFooterProps, EditableTableMain, type EditableTableMainProps, EditableTablePanel, EditableTablePanelHeader, type EditableTablePanelHeaderProps, type EditableTablePanelProps, } from "./editable-table/EditableTableLayout";
|
|
29
|
+
export * from "./table-editor";
|
|
@@ -7,6 +7,7 @@ export declare const useInlineAddRow: ({ columns }: UseInlineAddRowProps) => {
|
|
|
7
7
|
dataRow: DataRow;
|
|
8
8
|
draftRevision: number;
|
|
9
9
|
inlineAddColumns: {
|
|
10
|
+
editor?: import("@vuu-ui/vuu-data-types").DataValueEditor;
|
|
10
11
|
editableBulk?: import("@vuu-ui/vuu-data-types").BulkEdit;
|
|
11
12
|
name: string;
|
|
12
13
|
required?: boolean;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { EditFormHookProps, EditFormValues, EditSession, useEditableTable } from "@vuu-ui/vuu-data-editing";
|
|
2
|
+
import type { DataSource, DataValueDescriptor } from "@vuu-ui/vuu-data-types";
|
|
3
|
+
import type { DataRow } from "@vuu-ui/vuu-table-types";
|
|
4
|
+
/**
|
|
5
|
+
* How existing rows are edited.
|
|
6
|
+
* - `inline`: in the table's cells.
|
|
7
|
+
* - `form`: the selected row is edited in a form, in a side panel.
|
|
8
|
+
*/
|
|
9
|
+
export type TableEditorEditStrategy = "inline" | "form";
|
|
10
|
+
/**
|
|
11
|
+
* How rows are added.
|
|
12
|
+
* - `inline`: with inline editing, in the inline add row (session only).
|
|
13
|
+
* - `form`: in a form, in a side panel. Always `form` with
|
|
14
|
+
* `editStrategy="form"`.
|
|
15
|
+
*/
|
|
16
|
+
export type TableEditorCreateStrategy = "inline" | "form";
|
|
17
|
+
/**
|
|
18
|
+
* - `session`: edits are staged in an edit session and applied on Save, or
|
|
19
|
+
* discarded on Cancel.
|
|
20
|
+
* - `direct`: each committed edit is validated, then sent straight to the
|
|
21
|
+
* source table. There is no Save or Cancel.
|
|
22
|
+
*/
|
|
23
|
+
export type TableEditorEditModel = "session" | "direct";
|
|
24
|
+
/** `create` is only used with a create form. */
|
|
25
|
+
export type TableEditorMode = "view" | "edit" | "create";
|
|
26
|
+
/**
|
|
27
|
+
* With a side panel (form editing, or a create form).
|
|
28
|
+
* - `on-select`: the side panel opens when a row is selected (or a new row is
|
|
29
|
+
* started) and closes when the selection is cleared or the panel is closed.
|
|
30
|
+
* - `always`: the side panel is always open.
|
|
31
|
+
*/
|
|
32
|
+
export type TableEditorPanelVisibility = "on-select" | "always";
|
|
33
|
+
/** State and actions of the enclosing `EditableTable`. */
|
|
34
|
+
export interface TableEditorState {
|
|
35
|
+
/**
|
|
36
|
+
* Whether the side panel can be closed. False while editing and when
|
|
37
|
+
* `panelVisibility` is `always`.
|
|
38
|
+
*/
|
|
39
|
+
canClosePanel: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Leaves edit (or create) mode, discarding changes. Asks `confirmCancel`
|
|
42
|
+
* first when there are unsaved changes. With direct editing, edits are
|
|
43
|
+
* already committed, so this just makes the table read-only.
|
|
44
|
+
*/
|
|
45
|
+
cancel: () => Promise<void>;
|
|
46
|
+
/** Whether a new row can be started now, e.g. with `TableEditorNewButton`. */
|
|
47
|
+
canCreate: boolean;
|
|
48
|
+
createStrategy: TableEditorCreateStrategy;
|
|
49
|
+
/** The dataSource passed to the provider. */
|
|
50
|
+
dataSource: DataSource;
|
|
51
|
+
editModel: TableEditorEditModel;
|
|
52
|
+
editStrategy: TableEditorEditStrategy;
|
|
53
|
+
/** True in edit and create modes. */
|
|
54
|
+
isEditing: boolean;
|
|
55
|
+
mode: TableEditorMode;
|
|
56
|
+
/** Whether the side panel is open. */
|
|
57
|
+
panelOpen: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Form editing: a snapshot of the selected row, updated with the saved
|
|
60
|
+
* values after a successful save.
|
|
61
|
+
*/
|
|
62
|
+
selectedRow?: DataRow;
|
|
63
|
+
/** Ignored when closing while `canClosePanel` is false. */
|
|
64
|
+
setPanelOpen: (open: boolean) => void;
|
|
65
|
+
/** With a create form: shows an empty form for adding a row. */
|
|
66
|
+
startCreate: () => void;
|
|
67
|
+
/** Enters edit mode. Form editing needs a selected row. */
|
|
68
|
+
startEdit: () => void;
|
|
69
|
+
}
|
|
70
|
+
/** Registered by the mounted form, so `cancel` can route through it. */
|
|
71
|
+
export interface TableEditorFormHandle {
|
|
72
|
+
cancel: () => Promise<void> | void;
|
|
73
|
+
getValues: () => EditFormValues;
|
|
74
|
+
isDirty: boolean;
|
|
75
|
+
}
|
|
76
|
+
export interface TableEditorContextValue extends TableEditorState {
|
|
77
|
+
allowDelete: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* The columns of the `TableEditorTable`, registered by it. Generated forms
|
|
80
|
+
* take labels, editors etc from them.
|
|
81
|
+
*/
|
|
82
|
+
columns?: readonly DataValueDescriptor[];
|
|
83
|
+
confirmCancel?: () => boolean | Promise<boolean>;
|
|
84
|
+
createKey: number;
|
|
85
|
+
formHandleRef: {
|
|
86
|
+
current: TableEditorFormHandle | undefined;
|
|
87
|
+
};
|
|
88
|
+
formSessionProps?: Pick<EditFormHookProps, "deleteMode" | "editSessionApi" | "onError" | "rowDefaults">;
|
|
89
|
+
onCreateDone: (saved?: boolean) => void;
|
|
90
|
+
onEditCancelled: () => void;
|
|
91
|
+
onEditSaved: (values?: EditFormValues) => void;
|
|
92
|
+
onSelect: (dataRow: DataRow | null) => void;
|
|
93
|
+
setColumns: (columns: readonly DataValueDescriptor[] | undefined) => void;
|
|
94
|
+
editSession?: EditSession;
|
|
95
|
+
editableTable?: ReturnType<typeof useEditableTable>;
|
|
96
|
+
}
|
|
97
|
+
export declare const TableEditorContext: import("react").Context<TableEditorContextValue | undefined>;
|
|
98
|
+
export declare const useTableEditorContext: (componentName: string) => TableEditorContextValue;
|
|
99
|
+
/** State and actions of the enclosing `EditableTable`. */
|
|
100
|
+
export declare const useTableEditor: () => TableEditorState;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type ButtonProps, type ToggleButtonGroupProps } from "@salt-ds/core";
|
|
2
|
+
export interface TableEditorButtonsProps {
|
|
3
|
+
hideCancel?: boolean;
|
|
4
|
+
/** @default "Save", or "Create" for a new row */
|
|
5
|
+
saveLabel?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Save and Cancel (and, for inline editing with `allowDelete`, Delete)
|
|
9
|
+
* buttons for the enclosing `EditableTable`. Disabled outside edit mode.
|
|
10
|
+
* Within a form, they are the form's buttons: render them within the
|
|
11
|
+
* `children` of `TableEditorForm` (which then omits its own buttons), or
|
|
12
|
+
* within `TableEditorCreateForm` with `showButtons={false}`. Renders nothing
|
|
13
|
+
* for inline direct editing, which has nothing to save.
|
|
14
|
+
*/
|
|
15
|
+
export declare const TableEditorButtons: ({ hideCancel, saveLabel, }: TableEditorButtonsProps) => import("react").JSX.Element | null;
|
|
16
|
+
export interface TableEditorModeToggleProps extends Omit<ToggleButtonGroupProps, "children" | "onChange" | "value"> {
|
|
17
|
+
/** Suffix appended to the `toggle-view` and `toggle-edit` test ids. */
|
|
18
|
+
testId?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* View/Edit toggle for the enclosing `EditableTable`. Switching to View
|
|
22
|
+
* discards changes, asking `confirmCancel` first. It is disabled while a row
|
|
23
|
+
* is being created and, when editing in a form, until a row is selected.
|
|
24
|
+
*/
|
|
25
|
+
export declare const TableEditorModeToggle: ({ "aria-label": ariaLabel, disabled, testId, ...props }: TableEditorModeToggleProps) => import("react").JSX.Element;
|
|
26
|
+
export type TableEditorEditButtonProps = Omit<ButtonProps, "onClick">;
|
|
27
|
+
/**
|
|
28
|
+
* Form editing: makes the selected row's form editable. Disabled while
|
|
29
|
+
* editing and when no row is selected.
|
|
30
|
+
*/
|
|
31
|
+
export declare const TableEditorEditButton: import("react").ForwardRefExoticComponent<TableEditorEditButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
32
|
+
export type TableEditorNewButtonProps = Omit<ButtonProps, "onClick">;
|
|
33
|
+
/**
|
|
34
|
+
* Starts a new row, shown in `TableEditorCreateForm`, with
|
|
35
|
+
* `editStrategy="form"` or `createStrategy="form"`. Disabled while a new row
|
|
36
|
+
* can't be started: while editing in a form, or while already creating.
|
|
37
|
+
*/
|
|
38
|
+
export declare const TableEditorNewButton: import("react").ForwardRefExoticComponent<TableEditorNewButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
39
|
+
/**
|
|
40
|
+
* A Salt `SidePanelCloseButton` that is only rendered while the side panel
|
|
41
|
+
* can be closed, i.e. not while editing.
|
|
42
|
+
*/
|
|
43
|
+
export declare const TableEditorPanelCloseButton: import("react").ForwardRefExoticComponent<ButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type CreateRowFormProps, type EditFormProps } from "@vuu-ui/vuu-data-editing";
|
|
2
|
+
import type { DataValueDescriptor } from "@vuu-ui/vuu-data-types";
|
|
3
|
+
import { type ReactNode } from "react";
|
|
4
|
+
/**
|
|
5
|
+
* Form editing: describes a field, overlaid on its schema column (and table
|
|
6
|
+
* column). The control is chosen from its `editor` and `serverDataType`.
|
|
7
|
+
*/
|
|
8
|
+
export type TableEditorField = DataValueDescriptor;
|
|
9
|
+
type ProviderOwnedProps = "confirmCancel" | "dataSource" | "deleteMode" | "editSessionApi" | "onError" | "rowDefaults";
|
|
10
|
+
export interface TableEditorFormProps extends Omit<EditFormProps, ProviderOwnedProps | "children" | "columns" | "dataRow" | "editModel" | "editSession" | "isEditMode" | "mode" | "requiredColumns"> {
|
|
11
|
+
/**
|
|
12
|
+
* The form's content: `EditField`s (which need no `dataRow`), custom
|
|
13
|
+
* editors, tabs, `EditFormButtons` etc. Read the selected row with
|
|
14
|
+
* `useTableEditor`. Defaults to an `EditField` per entry in `fields`.
|
|
15
|
+
*/
|
|
16
|
+
children?: ReactNode;
|
|
17
|
+
/**
|
|
18
|
+
* Fields for the default form content, in tab order. Without `fields` or
|
|
19
|
+
* `children`, a field is generated for each schema column.
|
|
20
|
+
*/
|
|
21
|
+
fields?: readonly TableEditorField[];
|
|
22
|
+
/**
|
|
23
|
+
* Render the built-in Save and Cancel buttons. When you compose the form's
|
|
24
|
+
* content as `children`, render `TableEditorButtons` where you want them.
|
|
25
|
+
* @default true without `children`, false with them
|
|
26
|
+
*/
|
|
27
|
+
showButtons?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Form editing: the selected row of the enclosing `EditableTable`, read-only
|
|
31
|
+
* in view mode and editable in edit mode. Renders nothing in create mode
|
|
32
|
+
* (see `TableEditorCreateForm`) and when no row is selected (see
|
|
33
|
+
* `TableEditorPlaceholder`).
|
|
34
|
+
*
|
|
35
|
+
* Without `children` or `fields`, the form is generated: a field per schema
|
|
36
|
+
* column, labelled and edited as the table's columns are.
|
|
37
|
+
*
|
|
38
|
+
* With `editModel="direct"`, each field is validated and sent as it is
|
|
39
|
+
* committed. Done returns the form to read-only.
|
|
40
|
+
*/
|
|
41
|
+
export declare const TableEditorForm: ({ children, className, fields, onCancelled, onSaved, showButtons, validate, ...formProps }: TableEditorFormProps) => import("react").JSX.Element | null;
|
|
42
|
+
export interface TableEditorCreateFormProps extends Omit<CreateRowFormProps, ProviderOwnedProps | "editSession"> {
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A form for adding a row, shown in create mode (see
|
|
46
|
+
* `TableEditorNewButton`), with `editStrategy="form"` or
|
|
47
|
+
* `createStrategy="form"`. Renders an `EditField` per entry in `fields`,
|
|
48
|
+
* followed by `children`. Custom editors in `children` stage values with
|
|
49
|
+
* `setValue` from `useEditFormContext`.
|
|
50
|
+
*
|
|
51
|
+
* Without `children` or `fields`, a field is generated for each schema
|
|
52
|
+
* column that can be set on a new row.
|
|
53
|
+
*
|
|
54
|
+
* With inline session editing the row is added to the table's edit
|
|
55
|
+
* session (the button reads Add), and saved with the rest of the session.
|
|
56
|
+
*/
|
|
57
|
+
export declare const TableEditorCreateForm: ({ children, className, fields, onCancelled, onSaved, ...formProps }: TableEditorCreateFormProps) => import("react").JSX.Element | null;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HTMLAttributes } from "react";
|
|
2
|
+
export type TableEditorToolbarProps = HTMLAttributes<HTMLDivElement>;
|
|
3
|
+
/** A row of controls, e.g. `TableEditorModeToggle` or `TableEditorNewButton`. */
|
|
4
|
+
export declare const TableEditorToolbar: ({ className, ...htmlAttributes }: TableEditorToolbarProps) => import("react").JSX.Element;
|
|
5
|
+
export type TableEditorPlaceholderProps = HTMLAttributes<HTMLDivElement>;
|
|
6
|
+
/**
|
|
7
|
+
* Form editing: renders `children` while no row is selected (and no row is
|
|
8
|
+
* being created), typically alongside `TableEditorForm` in the side panel.
|
|
9
|
+
*/
|
|
10
|
+
export declare const TableEditorPlaceholder: ({ className, ...htmlAttributes }: TableEditorPlaceholderProps) => import("react").JSX.Element | null;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type EditableTableHookProps } from "@vuu-ui/vuu-data-editing";
|
|
2
|
+
import type { DataSource } from "@vuu-ui/vuu-data-types";
|
|
3
|
+
import { type ReactNode } from "react";
|
|
4
|
+
import { type TableEditorCreateStrategy, type TableEditorEditModel, type TableEditorEditStrategy, type TableEditorMode, type TableEditorPanelVisibility } from "./TableEditorContext";
|
|
5
|
+
export interface TableEditorProviderProps extends Pick<EditableTableHookProps, "deleteMode" | "editSessionApi" | "onError" | "rowDefaults"> {
|
|
6
|
+
/**
|
|
7
|
+
* Inline session editing: show a checkbox column, and a Delete button in
|
|
8
|
+
* `TableEditorButtons`, so selected rows can be deleted.
|
|
9
|
+
*/
|
|
10
|
+
allowDelete?: boolean;
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
/** Asked before changes are discarded. See `useConfirmDiscard`. */
|
|
13
|
+
confirmCancel?: () => boolean | Promise<boolean>;
|
|
14
|
+
/** Inline session editing: rows copied into the edit session. @default "All" */
|
|
15
|
+
copyOption?: EditableTableHookProps["copyOption"];
|
|
16
|
+
/**
|
|
17
|
+
* How rows are added. Always `form` with `editStrategy="form"`.
|
|
18
|
+
* @default "inline"
|
|
19
|
+
*/
|
|
20
|
+
createStrategy?: TableEditorCreateStrategy;
|
|
21
|
+
dataSource: DataSource;
|
|
22
|
+
/** Uncontrolled initial mode. @default "view" */
|
|
23
|
+
defaultMode?: TableEditorMode;
|
|
24
|
+
/** @default "session" */
|
|
25
|
+
editModel?: TableEditorEditModel;
|
|
26
|
+
/** @default "inline" */
|
|
27
|
+
editStrategy?: TableEditorEditStrategy;
|
|
28
|
+
/** Controlled mode. Pair with `onModeChange`. */
|
|
29
|
+
mode?: TableEditorMode;
|
|
30
|
+
/** Called once changes have been discarded. */
|
|
31
|
+
onCancelled?: () => void;
|
|
32
|
+
onModeChange?: (mode: TableEditorMode) => void;
|
|
33
|
+
/** Called once changes (or a new row) have been saved. */
|
|
34
|
+
onSaved?: () => void;
|
|
35
|
+
/** Form editing: when the side panel is open. @default "on-select" */
|
|
36
|
+
panelVisibility?: TableEditorPanelVisibility;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Internal: the provider behind `EditableTable`. Owns the editing state
|
|
40
|
+
* shared by the `TableEditor` components: the mode (view, edit or create),
|
|
41
|
+
* the edit session and, with a side panel, the selected row and the panel.
|
|
42
|
+
* Lay out `TableEditorTable`, `TableEditorForm`, `TableEditorButtons` etc
|
|
43
|
+
* anywhere inside it; read its state with `useTableEditor`.
|
|
44
|
+
*
|
|
45
|
+
* - `editStrategy="inline"`: cells are edited in `TableEditorTable`. With
|
|
46
|
+
* `editModel="session"` edits are staged in a session table and applied
|
|
47
|
+
* on Save; with `editModel="direct"` each edit is sent straight to
|
|
48
|
+
* `dataSource`. With `createStrategy="form"`, new rows are added in
|
|
49
|
+
* `TableEditorCreateForm`.
|
|
50
|
+
* - `editStrategy="form"`: selecting a row in `TableEditorTable` shows it in
|
|
51
|
+
* `TableEditorForm`. Row selection is locked, and the panel cannot be
|
|
52
|
+
* closed, while the form is being edited.
|
|
53
|
+
*
|
|
54
|
+
* A Salt `SidePanelProvider` is provided, so a `SidePanel` placed inside
|
|
55
|
+
* opens and closes with the form.
|
|
56
|
+
*/
|
|
57
|
+
export declare const TableEditorProvider: ({ createStrategy, editModel, editStrategy, ...props }: TableEditorProviderProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type EditableColumnsHookProps } from "@vuu-ui/vuu-data-editing";
|
|
2
|
+
import { type TableProps } from "@vuu-ui/vuu-table";
|
|
3
|
+
export interface TableEditorTableProps extends Omit<TableProps, "customHeader" | "dataSource" | "isRowSelectable" | "selectionModel">, Partial<Pick<EditableColumnsHookProps, "undoColumn">> {
|
|
4
|
+
/**
|
|
5
|
+
* Session table editing: show a row, above the column headers, for adding
|
|
6
|
+
* rows.
|
|
7
|
+
*/
|
|
8
|
+
showInlineAddRow?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The Table of the enclosing `EditableTable`, bound to its dataSource and
|
|
12
|
+
* mode. Its `config.columns` are also used by generated forms, for labels,
|
|
13
|
+
* editors etc.
|
|
14
|
+
*
|
|
15
|
+
* - Inline session editing: cells become editable in edit mode, edited,
|
|
16
|
+
* added and deleted rows are styled, and rows can be checked for deletion
|
|
17
|
+
* when `allowDelete` is set on the provider.
|
|
18
|
+
* - Inline direct editing: cells are editable in edit mode, and each edit is
|
|
19
|
+
* sent straight to the dataSource. `showInlineAddRow` and `undoColumn`
|
|
20
|
+
* are ignored.
|
|
21
|
+
* - Form editing: single selection, which selects the row shown in
|
|
22
|
+
* `TableEditorForm`. Selection is locked while the form is being edited.
|
|
23
|
+
*/
|
|
24
|
+
export declare const TableEditorTable: (props: TableEditorTableProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { type TableEditorCreateStrategy, type TableEditorEditModel, type TableEditorEditStrategy, type TableEditorMode, type TableEditorPanelVisibility, type TableEditorState, useTableEditor, } from "./TableEditorContext";
|
|
2
|
+
export { TableEditorButtons, type TableEditorButtonsProps, TableEditorEditButton, type TableEditorEditButtonProps, TableEditorModeToggle, type TableEditorModeToggleProps, TableEditorNewButton, type TableEditorNewButtonProps, TableEditorPanelCloseButton, } from "./TableEditorControls";
|
|
3
|
+
export { type TableEditorCreateFormProps, type TableEditorField, TableEditorCreateForm, TableEditorForm, type TableEditorFormProps, } from "./TableEditorForm";
|
|
4
|
+
export { TableEditorPlaceholder, type TableEditorPlaceholderProps, TableEditorToolbar, type TableEditorToolbarProps, } from "./TableEditorLayout";
|
|
5
|
+
export { TableEditorTable, type TableEditorTableProps, } from "./TableEditorTable";
|