@vuu-ui/vuu-data-editing 4.0.0-alpha.2 → 4.0.0-alpha.21

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.
@@ -0,0 +1,28 @@
1
+ import type { RpcResult, VuuRowDataItemType } from "@vuu-ui/vuu-protocol-types";
2
+ export type TableEditSessionEvents = {
3
+ cellEditChanged: (key: string, columnName: string) => void;
4
+ };
5
+ /**
6
+ * The subset of edit session behaviour consumed by Table and its cells.
7
+ * Implemented by EditSession (edits staged in a session table, committed or
8
+ * discarded at end of session) and DirectEditSession (edits applied directly
9
+ * to the source table).
10
+ */
11
+ export interface TableEditSession {
12
+ /**
13
+ * True while a staged edit session is in progress. Always false for
14
+ * DirectEditSession.
15
+ */
16
+ readonly inEditMode: boolean;
17
+ commit(key: string, columnName: string, originalValue: VuuRowDataItemType, typedValue: string | number | boolean, isValid: boolean): Promise<RpcResult>;
18
+ /**
19
+ * Invoked when user abandons an in-progress cell edit, restoring the value
20
+ * the cell held before editing began. Values that have only been typed, not
21
+ * committed, have never been sent to the server, so nothing is sent here.
22
+ * Any invalid edit previously recorded for the cell is discarded.
23
+ */
24
+ cancel(key: string, columnName: string, restoredValue: VuuRowDataItemType): Promise<RpcResult>;
25
+ isCellEdited(key: string, columnName: string): boolean;
26
+ on<E extends keyof TableEditSessionEvents>(event: E, listener: TableEditSessionEvents[E]): void;
27
+ removeListener<E extends keyof TableEditSessionEvents>(event: E, listener: TableEditSessionEvents[E]): void;
28
+ }
@@ -9,4 +9,4 @@ export declare const getUndoButtonContent: (componentProps?: UndoCellRendererCom
9
9
  text: string | undefined;
10
10
  };
11
11
  export declare const getUndoTooltipContent: (action: unknown) => "Undo delete row" | "Undo insert row" | "Undo row edits" | undefined;
12
- export declare const UndoCellRenderer: ({ column, dataRow, }: TableCellRendererProps) => import("react").JSX.Element | null;
12
+ export declare const UndoCellRenderer: ({ column, dataRow, }: TableCellRendererProps) => import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,21 @@
1
+ import type { DataRow } from "@vuu-ui/vuu-table-types";
2
+ import type { VuuTable } from "@vuu-ui/vuu-protocol-types";
3
+ import { type OptionMap } from "../lookup-values/useLookupValues";
4
+ import "./EditField.css";
5
+ export type TextFieldType = "email" | "password";
6
+ export type EditFieldType = "checkbox" | "dropdown" | TextFieldType;
7
+ export interface EditFieldProps {
8
+ dataRow: DataRow;
9
+ deferNewRow?: boolean;
10
+ label: string;
11
+ name: string;
12
+ readOnly?: boolean;
13
+ required?: boolean;
14
+ type?: EditFieldType;
15
+ }
16
+ export interface DropdownEditFieldProps extends EditFieldProps {
17
+ type: "dropdown";
18
+ optionMap: OptionMap;
19
+ table: VuuTable;
20
+ }
21
+ export declare const EditField: ({ dataRow, deferNewRow, label, name, readOnly, required, type, ...options }: EditFieldProps | DropdownEditFieldProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,26 @@
1
+ import type { VuuRowDataItemType } from "@vuu-ui/vuu-protocol-types";
2
+ import type { RuntimeColumnDescriptor, TableCellEditHandler } from "@vuu-ui/vuu-table-types";
3
+ import { type ChangeEventHandler, type FocusEventHandler, type KeyboardEvent, type SyntheticEvent } from "react";
4
+ import type { LookupOption } from "../lookup-values/useLookupValues";
5
+ import type { TextFieldType } from "./EditField";
6
+ export interface EditFieldHookProps<T extends VuuRowDataItemType = VuuRowDataItemType> {
7
+ column: Pick<RuntimeColumnDescriptor, "clientSideEditValidationCheck" | "label" | "name">;
8
+ value?: T;
9
+ onEdit?: TableCellEditHandler;
10
+ textType?: TextFieldType;
11
+ type?: "string" | "number" | "boolean";
12
+ }
13
+ export declare const useEditField: <T extends string | number | boolean = string>({ column, value, onEdit, textType, type, }: EditFieldHookProps<T>) => {
14
+ editing: boolean;
15
+ inputProps: {
16
+ onBlur: FocusEventHandler<HTMLElement>;
17
+ onFocus: FocusEventHandler<HTMLElement>;
18
+ type: TextFieldType | undefined;
19
+ };
20
+ onKeyDown: (evt: KeyboardEvent<HTMLElement>) => Promise<void>;
21
+ previousValue: string | undefined;
22
+ value: string;
23
+ warningMessage: string | undefined;
24
+ onChange: ChangeEventHandler<HTMLInputElement>;
25
+ onDropdownSelectionChange: (_evt: SyntheticEvent, [selectedOption]: LookupOption[]) => void;
26
+ };
@@ -2,4 +2,4 @@ import type { DataRow, RuntimeColumnDescriptor } from "@vuu-ui/vuu-table-types";
2
2
  export { isInlineEditingSession } from "@vuu-ui/vuu-utils";
3
3
  export declare const isEditRowReadOnly: (dataRow: DataRow) => boolean;
4
4
  export declare const withDataRowEditErrors: <T extends DataRow>(dataRow: T, errors: Record<string, string>) => T;
5
- export declare const getVuuEditMessage: (dataRow: DataRow, column: RuntimeColumnDescriptor, originalValue: string) => string | import("react").JSX.Element | undefined;
5
+ export declare const getVuuEditMessage: (dataRow: DataRow, column: RuntimeColumnDescriptor, originalValue: string) => string | import("react/jsx-runtime").JSX.Element | undefined;
package/types/index.d.ts CHANGED
@@ -1,10 +1,17 @@
1
- export { DataEditingProvider, useEditSession } from "./DataEditingProvider";
1
+ export { DataEditingProvider, useEditSession, useTableEditSession, } from "./DataEditingProvider";
2
+ export { DirectEditSession, type DirectEditSessionConstructorProps, } from "./DirectEditSession";
3
+ export type { TableEditSession, TableEditSessionEvents, } from "./TableEditSession";
2
4
  export { useCellEdited } from "./useCellEdited";
5
+ export { useEditState } from "./useEditState";
3
6
  export { getVuuEditMessage, isInlineEditingSession, isEditRowReadOnly, withDataRowEditErrors, } from "./edit-utils";
4
7
  export { EditButtons, type EditButtonProps } from "./EditButtons";
8
+ export { EditField, type DropdownEditFieldProps, type EditFieldProps, type EditFieldType, type TextFieldType, } from "./edit-field/EditField";
9
+ export { useEditField, type EditFieldHookProps, } from "./edit-field/useEditField";
5
10
  export { EditModeProvider, useEditMode, type EditModeContextProps, } from "./EditModeProvider";
6
- export { EditError, EditSession, SupersededEditError, type EditActionType, type EditLifecycle, type EditSessionConstructorProps, type NewRowState, type EditState, type RowDefaultDataItemValues, } from "./EditSession";
11
+ export { EditError, EditSession, SupersededEditError, type AddRowResultData, type EditActionType, type EditCommitOptions, type EditLifecycle, type EditSessionConstructorProps, type EditSessionValue, type NewRowState, type EditState, type RowDefaultDataItemValues, } from "./EditSession";
7
12
  export { StaleUpdateError } from "@vuu-ui/vuu-utils";
13
+ export { lookupOptionsFromRows, useLookupValues, type LookupOption, type LookupValuedHookProps, type OptionMap, } from "./lookup-values/useLookupValues";
14
+ export { useEditable, type EditableHookProps } from "./useEditable";
8
15
  export { EDIT_ACTION_ROW_CLASS_NAME_GENERATOR, editActionRowClassNameGenerator, } from "./editActionRowClassNameGenerator";
9
16
  export { getUndoButtonContent, getUndoTooltipContent, UNDO_CELL_RENDERER, UndoCellRenderer, type UndoCellRendererComponentProps, } from "./UndoCellRenderer";
10
17
  export { useEditableTable, type EditableTableHookProps, type EditMode, } from "./useEditableTable";
@@ -0,0 +1,19 @@
1
+ import type { DataSourceRow } from "@vuu-ui/vuu-data-types";
2
+ import type { VuuTable } from "@vuu-ui/vuu-protocol-types";
3
+ export type LookupOption = {
4
+ label: string;
5
+ metadata?: Record<string, string>;
6
+ value: number | string;
7
+ };
8
+ export type OptionMap = {
9
+ additionalFields?: readonly string[];
10
+ label: string;
11
+ value: string;
12
+ };
13
+ export interface LookupValuedHookProps {
14
+ enabled: boolean;
15
+ optionMap?: OptionMap;
16
+ table?: VuuTable;
17
+ }
18
+ export declare const lookupOptionsFromRows: (columns: string[], rows: DataSourceRow[], optionMap: OptionMap) => LookupOption[];
19
+ export declare const useLookupValues: ({ enabled, optionMap, table, }: LookupValuedHookProps) => LookupOption[];
@@ -1,2 +1,2 @@
1
- import type { EditSession } from "./EditSession";
2
- export declare const useCellEdited: (editSession: EditSession | undefined, key: string, columnName: string) => boolean;
1
+ import type { TableEditSession } from "./TableEditSession";
2
+ export declare const useCellEdited: (editSession: TableEditSession | undefined, key: string, columnName: string) => boolean;
@@ -0,0 +1,2 @@
1
+ import type { EditSession, EditState } from "./EditSession";
2
+ export declare function useEditState(editSession: EditSession | undefined): EditState;
@@ -0,0 +1,13 @@
1
+ import type { CopyOption, DataSource } from "@vuu-ui/vuu-data-types";
2
+ import { EditSession } from "./EditSession";
3
+ export interface EditableHookProps {
4
+ copyOption?: CopyOption;
5
+ dataSource: DataSource;
6
+ onCancel: () => void;
7
+ onSave: () => void;
8
+ }
9
+ export declare const useEditable: ({ copyOption, dataSource, onCancel, onSave, }: EditableHookProps) => {
10
+ editSession: EditSession;
11
+ onCancel: () => Promise<void>;
12
+ onSave: (force?: boolean) => Promise<void>;
13
+ };
@@ -1,5 +1,6 @@
1
1
  import type { CopyOption, DataSource, DeleteRowMode } from "@vuu-ui/vuu-data-types";
2
2
  import type { VuuTable } from "@vuu-ui/vuu-protocol-types";
3
+ import type { DataRow } from "@vuu-ui/vuu-table-types";
3
4
  import { EditSession, type EditActionType, type EditLifecycle, type EditSessionApi, type RowDefaultDataItemValues } from "./EditSession";
4
5
  export type EditMode = "edit" | "view";
5
6
  export interface EditableTableHookProps {
@@ -38,6 +39,7 @@ export declare const useEditableTable: ({ columns, dataSource: dataSourceProp, d
38
39
  onDelete: () => Promise<void>;
39
40
  onSave: (force?: boolean) => Promise<void>;
40
41
  onUndoRowChange: (key: string, action: EditActionType) => undefined;
42
+ isRowSelectable: ((dataRow: DataRow) => boolean) | undefined;
41
43
  rowClassNameGenerators: string[] | undefined;
42
44
  sessionDataSource: import("@vuu-ui/vuu-data-types").DataSourceBase<import("@vuu-ui/vuu-data-types").DataSourceRowWithBigint> | undefined;
43
45
  sourceDataSource: DataSource;