@lenso/primitives 0.6.0 → 0.8.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/README.md +5 -0
- package/dist/command/command.d.ts +25 -0
- package/dist/command/index.d.ts +16 -0
- package/dist/command/index.js +76 -0
- package/dist/data-grid/index.d.ts +117 -0
- package/dist/data-grid/index.js +178 -0
- package/dist/resize-handle/index.js +1 -2
- package/dist/sidebar/index.js +2 -3
- package/package.json +28 -20
package/README.md
CHANGED
|
@@ -27,3 +27,8 @@ export function AppShell() {
|
|
|
27
27
|
Use `@lenso/ui/sidebar` when you want the Lenso UI visual adapter. The registry also includes an editable Sidebar Recipe for Consumers that need structural ownership.
|
|
28
28
|
|
|
29
29
|
Source and browser tests live under `packages/primitives/src/sidebar`. See the repository [architecture guide](../../docs/architecture.md) for the dependency boundary and the [contributing guide](../../CONTRIBUTING.md) for changes and release verification.
|
|
30
|
+
|
|
31
|
+
## Command
|
|
32
|
+
|
|
33
|
+
`@lenso/primitives/command` provides unstyled command filtering, navigation and execution.
|
|
34
|
+
Use `@lenso/ui/command` for the styled Lenso component.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
2
|
+
import { type RefAttributes } from "react";
|
|
3
|
+
export type CommandRootProps<Value> = Omit<Autocomplete.Root.Props<Value>, "inline" | "open" | "defaultOpen" | "onOpenChange" | "mode" | "filter" | "items" | "filteredItems"> & {
|
|
4
|
+
items?: readonly Value[];
|
|
5
|
+
filteredItems?: readonly Value[];
|
|
6
|
+
filter?: Autocomplete.Root.Props<Value>["filter"] | false;
|
|
7
|
+
};
|
|
8
|
+
/** An inline command list. Compose with Dialog when an overlay is needed. */
|
|
9
|
+
export declare function CommandRoot<Value>({ value, defaultValue, onValueChange, filter, autoHighlight, keepHighlight, readOnly, ...props }: CommandRootProps<Value>): import("react").JSX.Element;
|
|
10
|
+
export type CommandItemProps<Value = string> = Omit<Autocomplete.Item.Props, "value" | "onSelect"> & RefAttributes<HTMLDivElement> & {
|
|
11
|
+
value: Value;
|
|
12
|
+
onSelect?: (value: Value) => void;
|
|
13
|
+
};
|
|
14
|
+
export declare function CommandItem<Value = string>({ value, onClick, onSelect, ...props }: CommandItemProps<Value>): import("react").JSX.Element;
|
|
15
|
+
export type CommandInputProps = Autocomplete.Input.Props;
|
|
16
|
+
export declare function CommandInput({ onKeyDown, ...props }: CommandInputProps): import("react").JSX.Element;
|
|
17
|
+
export declare const CommandList: typeof Autocomplete.List;
|
|
18
|
+
export declare const CommandEmpty: typeof Autocomplete.Empty;
|
|
19
|
+
export declare const CommandGroup: typeof Autocomplete.Group;
|
|
20
|
+
export declare const CommandGroupLabel: typeof Autocomplete.GroupLabel;
|
|
21
|
+
export declare const CommandSeparator: typeof Autocomplete.Separator;
|
|
22
|
+
export declare const CommandCollection: typeof Autocomplete.Collection;
|
|
23
|
+
export declare const CommandStatus: typeof Autocomplete.Status;
|
|
24
|
+
export declare const CommandClear: typeof Autocomplete.Clear;
|
|
25
|
+
export declare const useCommandFilter: typeof Autocomplete.useFilter;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CommandRoot, CommandInput, CommandList, CommandItem, CommandEmpty, CommandGroup, CommandGroupLabel, CommandSeparator, CommandCollection, CommandStatus, CommandClear, useCommandFilter } from "./command.js";
|
|
2
|
+
export declare const Command: typeof CommandRoot & {
|
|
3
|
+
Root: typeof CommandRoot;
|
|
4
|
+
Input: typeof CommandInput;
|
|
5
|
+
List: typeof CommandList;
|
|
6
|
+
Item: typeof CommandItem;
|
|
7
|
+
Empty: typeof CommandEmpty;
|
|
8
|
+
Group: typeof CommandGroup;
|
|
9
|
+
GroupLabel: typeof CommandGroupLabel;
|
|
10
|
+
Separator: typeof CommandSeparator;
|
|
11
|
+
Collection: typeof CommandCollection;
|
|
12
|
+
Status: typeof CommandStatus;
|
|
13
|
+
Clear: typeof CommandClear;
|
|
14
|
+
useFilter: typeof useCommandFilter;
|
|
15
|
+
};
|
|
16
|
+
export * from "./command.js";
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Autocomplete } from "@base-ui/react/autocomplete";
|
|
3
|
+
import { createContext, useContext, useState } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/command/command.tsx
|
|
6
|
+
const CommandReadOnly = createContext(false);
|
|
7
|
+
/** An inline command list. Compose with Dialog when an overlay is needed. */
|
|
8
|
+
function CommandRoot({ value, defaultValue = "", onValueChange, filter, autoHighlight = "always", keepHighlight = true, readOnly = false, ...props }) {
|
|
9
|
+
const [query, setQuery] = useState(defaultValue);
|
|
10
|
+
return /* @__PURE__ */ jsx(CommandReadOnly, {
|
|
11
|
+
value: readOnly,
|
|
12
|
+
children: /* @__PURE__ */ jsx(Autocomplete.Root, {
|
|
13
|
+
...props,
|
|
14
|
+
readOnly,
|
|
15
|
+
inline: true,
|
|
16
|
+
open: true,
|
|
17
|
+
autoHighlight,
|
|
18
|
+
keepHighlight,
|
|
19
|
+
filter: filter === false ? null : filter,
|
|
20
|
+
value: value ?? query,
|
|
21
|
+
onValueChange: (next, details) => {
|
|
22
|
+
if (details.reason === "item-press") {
|
|
23
|
+
details.cancel();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
onValueChange?.(next, details);
|
|
27
|
+
if (!details.isCanceled) setQuery(next);
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function CommandItem({ value, onClick, onSelect, ...props }) {
|
|
33
|
+
const readOnly = useContext(CommandReadOnly);
|
|
34
|
+
return /* @__PURE__ */ jsx(Autocomplete.Item, {
|
|
35
|
+
...props,
|
|
36
|
+
value,
|
|
37
|
+
onClick: (event) => {
|
|
38
|
+
onClick?.(event);
|
|
39
|
+
if (!readOnly && !event.defaultPrevented && !event.baseUIHandlerPrevented) onSelect?.(value);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function CommandInput({ onKeyDown, ...props }) {
|
|
44
|
+
return /* @__PURE__ */ jsx(Autocomplete.Input, {
|
|
45
|
+
...props,
|
|
46
|
+
onKeyDown: (event) => {
|
|
47
|
+
onKeyDown?.(event);
|
|
48
|
+
if (event.nativeEvent.isComposing || event.nativeEvent.keyCode === 229) event.preventBaseUIHandler();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const CommandList = Autocomplete.List;
|
|
53
|
+
const CommandEmpty = Autocomplete.Empty;
|
|
54
|
+
const CommandGroup = Autocomplete.Group;
|
|
55
|
+
const CommandGroupLabel = Autocomplete.GroupLabel;
|
|
56
|
+
const CommandSeparator = Autocomplete.Separator;
|
|
57
|
+
const CommandCollection = Autocomplete.Collection;
|
|
58
|
+
const CommandStatus = Autocomplete.Status;
|
|
59
|
+
const CommandClear = Autocomplete.Clear;
|
|
60
|
+
const useCommandFilter = Autocomplete.useFilter;
|
|
61
|
+
// src/command/index.ts
|
|
62
|
+
const Command = Object.assign(CommandRoot, {
|
|
63
|
+
Root: CommandRoot,
|
|
64
|
+
Input: CommandInput,
|
|
65
|
+
List: CommandList,
|
|
66
|
+
Item: CommandItem,
|
|
67
|
+
Empty: CommandEmpty,
|
|
68
|
+
Group: CommandGroup,
|
|
69
|
+
GroupLabel: CommandGroupLabel,
|
|
70
|
+
Separator: CommandSeparator,
|
|
71
|
+
Collection: CommandCollection,
|
|
72
|
+
Status: CommandStatus,
|
|
73
|
+
Clear: CommandClear,
|
|
74
|
+
useFilter: useCommandFilter
|
|
75
|
+
});
|
|
76
|
+
export { Command, CommandClear, CommandCollection, CommandEmpty, CommandGroup, CommandGroupLabel, CommandInput, CommandItem, CommandList, CommandRoot, CommandSeparator, CommandStatus, useCommandFilter };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { type ColumnDef, type CellSelectionState, type RowData, type ReactTable, type SortingState, type TableOptions } from "@tanstack/react-table";
|
|
2
|
+
export type DataGridValue = string | number | boolean | null;
|
|
3
|
+
export type DataGridEditReason = "edit" | "paste" | "fill" | "programmatic";
|
|
4
|
+
export interface DataGridCellChange<TRow> {
|
|
5
|
+
rowId: string;
|
|
6
|
+
rowIndex: number;
|
|
7
|
+
columnId: string;
|
|
8
|
+
previousValue: DataGridValue;
|
|
9
|
+
value: DataGridValue;
|
|
10
|
+
previousRow: TRow;
|
|
11
|
+
row: TRow;
|
|
12
|
+
reason: DataGridEditReason;
|
|
13
|
+
}
|
|
14
|
+
export interface DataGridRowChange<TRow> {
|
|
15
|
+
rowId: string;
|
|
16
|
+
rowIndex: number;
|
|
17
|
+
previousRow: TRow;
|
|
18
|
+
row: TRow;
|
|
19
|
+
changes: readonly DataGridCellChange<TRow>[];
|
|
20
|
+
reason: DataGridEditReason;
|
|
21
|
+
}
|
|
22
|
+
export interface DataGridColumn<TRow extends RowData, TValidationData = unknown> {
|
|
23
|
+
id: string;
|
|
24
|
+
header: string;
|
|
25
|
+
getValue: (row: TRow) => DataGridValue;
|
|
26
|
+
setValue?: (row: TRow, value: DataGridValue) => TRow;
|
|
27
|
+
parse?: (input: string, row: TRow) => DataGridValue;
|
|
28
|
+
validate?: (value: DataGridValue, row: TRow, context: DataGridValidationContext<TRow, TValidationData>) => string | null;
|
|
29
|
+
editable?: boolean | ((row: TRow) => boolean);
|
|
30
|
+
sortable?: boolean;
|
|
31
|
+
width?: number;
|
|
32
|
+
minWidth?: number;
|
|
33
|
+
maxWidth?: number;
|
|
34
|
+
pinned?: boolean;
|
|
35
|
+
onCellEditComplete?: (change: DataGridCellChange<TRow>) => void;
|
|
36
|
+
tableColumn?: Omit<Partial<ColumnDef<typeof dataGridFeatures, TRow, unknown>>, "id" | "header" | "accessorFn">;
|
|
37
|
+
}
|
|
38
|
+
export interface DataGridEdit {
|
|
39
|
+
rowId: string;
|
|
40
|
+
columnId: string;
|
|
41
|
+
value: DataGridValue;
|
|
42
|
+
}
|
|
43
|
+
export interface DataGridCellEvent<TRow> {
|
|
44
|
+
rowId: string;
|
|
45
|
+
columnId: string;
|
|
46
|
+
onEditComplete: (change: DataGridCellChange<TRow>) => void;
|
|
47
|
+
}
|
|
48
|
+
export type DataGridCommitResult<TRow> = {
|
|
49
|
+
ok: true;
|
|
50
|
+
changes: readonly DataGridCellChange<TRow>[];
|
|
51
|
+
} | {
|
|
52
|
+
ok: false;
|
|
53
|
+
error: string;
|
|
54
|
+
edit: DataGridEdit;
|
|
55
|
+
};
|
|
56
|
+
export interface UseDataGridOptions<TRow extends RowData, TValidationData = unknown> {
|
|
57
|
+
rows: readonly TRow[];
|
|
58
|
+
columns: readonly DataGridColumn<TRow, TValidationData>[];
|
|
59
|
+
getRowId: (row: TRow) => string;
|
|
60
|
+
readOnly?: boolean;
|
|
61
|
+
rowSelection?: boolean;
|
|
62
|
+
cellSelection?: boolean;
|
|
63
|
+
sorting?: boolean;
|
|
64
|
+
onRowsChange?: (rows: TRow[], changes: readonly DataGridCellChange<TRow>[]) => void;
|
|
65
|
+
onCellEditComplete?: (change: DataGridCellChange<TRow>) => void;
|
|
66
|
+
cellEvents?: readonly DataGridCellEvent<TRow>[];
|
|
67
|
+
onRowEditComplete?: (change: DataGridRowChange<TRow>) => void;
|
|
68
|
+
onRowSelectionChange?: (rowIds: ReadonlySet<string>) => void;
|
|
69
|
+
onCellSelectionChange?: (ranges: CellSelectionState) => void;
|
|
70
|
+
onSortingChange?: (sorting: SortingState) => void;
|
|
71
|
+
validationData?: TValidationData;
|
|
72
|
+
tableOptions?: DataGridTableOptions<TRow>;
|
|
73
|
+
}
|
|
74
|
+
export declare const dataGridFeatures: {
|
|
75
|
+
cellSelectionFeature: import("@tanstack/react-table").TableFeature;
|
|
76
|
+
columnSizingFeature: import("@tanstack/react-table").TableFeature;
|
|
77
|
+
columnResizingFeature: import("@tanstack/react-table").TableFeature;
|
|
78
|
+
rowSelectionFeature: import("@tanstack/react-table").TableFeature;
|
|
79
|
+
rowSortingFeature: import("@tanstack/react-table").TableFeature;
|
|
80
|
+
sortedRowModel: (table: import("@tanstack/react-table").Table<any, any>) => () => import("@tanstack/react-table").RowModel<any, any>;
|
|
81
|
+
sortFns: {
|
|
82
|
+
alphanumeric: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
83
|
+
basic: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
84
|
+
datetime: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
85
|
+
text: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
export type DataGridTable<TRow extends RowData> = ReactTable<typeof dataGridFeatures, TRow>;
|
|
89
|
+
export type DataGridTableOptions<TRow extends RowData> = Partial<Omit<TableOptions<typeof dataGridFeatures, TRow>, "features" | "columns" | "data" | "getRowId">>;
|
|
90
|
+
export interface DataGridValidationContext<TRow extends RowData, TValidationData = unknown> {
|
|
91
|
+
rowId: string;
|
|
92
|
+
rowIndex: number;
|
|
93
|
+
columnId: string;
|
|
94
|
+
rows: readonly TRow[];
|
|
95
|
+
originalRows: readonly TRow[];
|
|
96
|
+
changes: readonly DataGridCellChange<TRow>[];
|
|
97
|
+
reason: DataGridEditReason;
|
|
98
|
+
data: TValidationData | undefined;
|
|
99
|
+
table: DataGridTable<TRow>;
|
|
100
|
+
}
|
|
101
|
+
export declare function useDataGrid<TRow extends RowData, TValidationData = unknown>({ rows, columns, getRowId, readOnly, rowSelection, cellSelection, sorting, onRowsChange, onCellEditComplete, cellEvents, onRowEditComplete, onRowSelectionChange, onCellSelectionChange, onSortingChange, validationData, tableOptions, }: UseDataGridOptions<TRow, TValidationData>): {
|
|
102
|
+
table: ReactTable<{
|
|
103
|
+
cellSelectionFeature: import("@tanstack/react-table").TableFeature;
|
|
104
|
+
columnSizingFeature: import("@tanstack/react-table").TableFeature;
|
|
105
|
+
columnResizingFeature: import("@tanstack/react-table").TableFeature;
|
|
106
|
+
rowSelectionFeature: import("@tanstack/react-table").TableFeature;
|
|
107
|
+
rowSortingFeature: import("@tanstack/react-table").TableFeature;
|
|
108
|
+
sortedRowModel: (table: import("@tanstack/react-table").Table<any, any>) => () => import("@tanstack/react-table").RowModel<any, any>;
|
|
109
|
+
sortFns: {
|
|
110
|
+
alphanumeric: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
111
|
+
basic: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
112
|
+
datetime: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
113
|
+
text: import("@tanstack/react-table").CreatedSortFn<any, any>;
|
|
114
|
+
};
|
|
115
|
+
}, TRow, import("@tanstack/react-table").TableState_CellSelection & import("@tanstack/react-table").TableState_ColumnResizing & import("@tanstack/react-table").TableState_ColumnSizing & import("@tanstack/react-table").TableState_RowSelection & import("@tanstack/react-table").TableState_RowSorting>;
|
|
116
|
+
commitCells: (edits: readonly DataGridEdit[], reason?: DataGridEditReason) => DataGridCommitResult<TRow>;
|
|
117
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cellSelectionFeature, columnResizingFeature, columnSizingFeature, createSortedRowModel, functionalUpdate, makeStateUpdater, rowSelectionFeature, rowSortingFeature, sortFn_alphanumeric, sortFn_basic, sortFn_datetime, sortFn_text, tableFeatures, useTable } from "@tanstack/react-table";
|
|
4
|
+
// src/data-grid/index.tsx
|
|
5
|
+
const dataGridFeatures = tableFeatures({
|
|
6
|
+
cellSelectionFeature,
|
|
7
|
+
columnSizingFeature,
|
|
8
|
+
columnResizingFeature,
|
|
9
|
+
rowSelectionFeature,
|
|
10
|
+
rowSortingFeature,
|
|
11
|
+
sortedRowModel: createSortedRowModel(),
|
|
12
|
+
sortFns: {
|
|
13
|
+
alphanumeric: sortFn_alphanumeric,
|
|
14
|
+
basic: sortFn_basic,
|
|
15
|
+
datetime: sortFn_datetime,
|
|
16
|
+
text: sortFn_text
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
function useDataGrid({ rows, columns, getRowId, readOnly = false, rowSelection = true, cellSelection = true, sorting = true, onRowsChange, onCellEditComplete, cellEvents, onRowEditComplete, onRowSelectionChange, onCellSelectionChange, onSortingChange, validationData, tableOptions }) {
|
|
20
|
+
const tableColumns = React.useMemo(() => columns.map((column) => ({
|
|
21
|
+
id: column.id,
|
|
22
|
+
header: column.header,
|
|
23
|
+
accessorFn: column.getValue,
|
|
24
|
+
enableSorting: sorting && column.sortable !== false,
|
|
25
|
+
enableCellSelection: cellSelection,
|
|
26
|
+
size: column.width ?? 180,
|
|
27
|
+
minSize: column.minWidth ?? 80,
|
|
28
|
+
maxSize: column.maxWidth ?? 1200,
|
|
29
|
+
...column.tableColumn
|
|
30
|
+
})), [
|
|
31
|
+
cellSelection,
|
|
32
|
+
columns,
|
|
33
|
+
sorting
|
|
34
|
+
]);
|
|
35
|
+
const table = useTable({
|
|
36
|
+
features: dataGridFeatures,
|
|
37
|
+
columns: tableColumns,
|
|
38
|
+
data: rows,
|
|
39
|
+
getRowId,
|
|
40
|
+
enableRowSelection: rowSelection,
|
|
41
|
+
enableCellSelection: cellSelection,
|
|
42
|
+
enableCellSelectionDrag: cellSelection,
|
|
43
|
+
autoResetCellSelection: false,
|
|
44
|
+
enableSorting: sorting,
|
|
45
|
+
...tableOptions,
|
|
46
|
+
onRowSelectionChange: (updater) => {
|
|
47
|
+
const next = functionalUpdate(updater, table.state.rowSelection);
|
|
48
|
+
(tableOptions?.onRowSelectionChange ?? makeStateUpdater("rowSelection", table))(updater);
|
|
49
|
+
onRowSelectionChange?.(new Set(Object.keys(next).filter((id) => next[id])));
|
|
50
|
+
},
|
|
51
|
+
onCellSelectionChange: (updater) => {
|
|
52
|
+
const next = functionalUpdate(updater, table.state.cellSelection);
|
|
53
|
+
(tableOptions?.onCellSelectionChange ?? makeStateUpdater("cellSelection", table))(updater);
|
|
54
|
+
onCellSelectionChange?.(next);
|
|
55
|
+
},
|
|
56
|
+
onSortingChange: (updater) => {
|
|
57
|
+
const next = functionalUpdate(updater, table.state.sorting);
|
|
58
|
+
(tableOptions?.onSortingChange ?? makeStateUpdater("sorting", table))(updater);
|
|
59
|
+
onSortingChange?.(next);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
table,
|
|
64
|
+
commitCells: React.useCallback((edits, reason = "edit") => {
|
|
65
|
+
if (edits.length === 0) return {
|
|
66
|
+
ok: true,
|
|
67
|
+
changes: []
|
|
68
|
+
};
|
|
69
|
+
if (readOnly || !onRowsChange) return {
|
|
70
|
+
ok: false,
|
|
71
|
+
error: "This grid is read-only",
|
|
72
|
+
edit: edits[0]
|
|
73
|
+
};
|
|
74
|
+
const nextRows = [...rows];
|
|
75
|
+
const rowIndexById = new Map(rows.map((row, index) => [getRowId(row), index]));
|
|
76
|
+
const columnById = new Map(columns.map((column) => [column.id, column]));
|
|
77
|
+
const changes = [];
|
|
78
|
+
const uniqueEdits = /* @__PURE__ */ new Map();
|
|
79
|
+
for (const edit of edits) uniqueEdits.set(JSON.stringify([edit.rowId, edit.columnId]), edit);
|
|
80
|
+
for (const edit of uniqueEdits.values()) {
|
|
81
|
+
const rowIndex = rowIndexById.get(edit.rowId);
|
|
82
|
+
const column = columnById.get(edit.columnId);
|
|
83
|
+
if (rowIndex === void 0 || !column) return {
|
|
84
|
+
ok: false,
|
|
85
|
+
error: "Unknown row or column",
|
|
86
|
+
edit
|
|
87
|
+
};
|
|
88
|
+
const row = nextRows[rowIndex];
|
|
89
|
+
if (!(column.setValue && (typeof column.editable === "function" ? column.editable(row) : column.editable !== false))) return {
|
|
90
|
+
ok: false,
|
|
91
|
+
error: "This cell is read-only",
|
|
92
|
+
edit
|
|
93
|
+
};
|
|
94
|
+
const previousValue = column.getValue(row);
|
|
95
|
+
const value = edit.value;
|
|
96
|
+
if (Object.is(previousValue, value)) continue;
|
|
97
|
+
const updatedRow = column.setValue(row, value);
|
|
98
|
+
nextRows[rowIndex] = updatedRow;
|
|
99
|
+
changes.push({
|
|
100
|
+
rowId: edit.rowId,
|
|
101
|
+
rowIndex,
|
|
102
|
+
columnId: column.id,
|
|
103
|
+
previousValue,
|
|
104
|
+
value,
|
|
105
|
+
previousRow: row,
|
|
106
|
+
row: updatedRow,
|
|
107
|
+
reason
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (changes.length === 0) return {
|
|
111
|
+
ok: true,
|
|
112
|
+
changes
|
|
113
|
+
};
|
|
114
|
+
for (const change of changes) {
|
|
115
|
+
const validationError = columnById.get(change.columnId).validate?.(change.value, nextRows[change.rowIndex], {
|
|
116
|
+
rowId: change.rowId,
|
|
117
|
+
rowIndex: change.rowIndex,
|
|
118
|
+
columnId: change.columnId,
|
|
119
|
+
rows: nextRows,
|
|
120
|
+
originalRows: rows,
|
|
121
|
+
changes,
|
|
122
|
+
reason,
|
|
123
|
+
data: validationData,
|
|
124
|
+
table
|
|
125
|
+
});
|
|
126
|
+
if (validationError) return {
|
|
127
|
+
ok: false,
|
|
128
|
+
error: validationError,
|
|
129
|
+
edit: {
|
|
130
|
+
rowId: change.rowId,
|
|
131
|
+
columnId: change.columnId,
|
|
132
|
+
value: change.value
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
onRowsChange(nextRows, changes);
|
|
137
|
+
for (const change of changes) {
|
|
138
|
+
onCellEditComplete?.(change);
|
|
139
|
+
columnById.get(change.columnId)?.onCellEditComplete?.(change);
|
|
140
|
+
for (const event of cellEvents ?? []) if (event.rowId === change.rowId && event.columnId === change.columnId) event.onEditComplete(change);
|
|
141
|
+
}
|
|
142
|
+
const changedRows = /* @__PURE__ */ new Map();
|
|
143
|
+
for (const change of changes) {
|
|
144
|
+
const rowChanges = changedRows.get(change.rowId) ?? [];
|
|
145
|
+
rowChanges.push(change);
|
|
146
|
+
changedRows.set(change.rowId, rowChanges);
|
|
147
|
+
}
|
|
148
|
+
for (const [rowId, rowChanges] of changedRows) {
|
|
149
|
+
const first = rowChanges[0];
|
|
150
|
+
const last = rowChanges[rowChanges.length - 1];
|
|
151
|
+
onRowEditComplete?.({
|
|
152
|
+
rowId,
|
|
153
|
+
rowIndex: first.rowIndex,
|
|
154
|
+
previousRow: first.previousRow,
|
|
155
|
+
row: last.row,
|
|
156
|
+
changes: rowChanges,
|
|
157
|
+
reason
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
ok: true,
|
|
162
|
+
changes
|
|
163
|
+
};
|
|
164
|
+
}, [
|
|
165
|
+
cellEvents,
|
|
166
|
+
columns,
|
|
167
|
+
getRowId,
|
|
168
|
+
onCellEditComplete,
|
|
169
|
+
onRowEditComplete,
|
|
170
|
+
onRowsChange,
|
|
171
|
+
readOnly,
|
|
172
|
+
rows,
|
|
173
|
+
table,
|
|
174
|
+
validationData
|
|
175
|
+
])
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
export { dataGridFeatures, useDataGrid };
|
|
@@ -3,7 +3,7 @@ import * as React from "react";
|
|
|
3
3
|
import * as stylex from "@stylexjs/stylex";
|
|
4
4
|
import { mergeProps } from "@base-ui/react/merge-props";
|
|
5
5
|
import { useRender } from "@base-ui/react/use-render";
|
|
6
|
-
|
|
6
|
+
// src/resize-handle/index.tsx
|
|
7
7
|
function clamp(value, min, max) {
|
|
8
8
|
return Math.min(max, Math.max(min, value));
|
|
9
9
|
}
|
|
@@ -176,5 +176,4 @@ function ResizeHandle({ disabled = false, inverted = false, max, min, onCollapse
|
|
|
176
176
|
}
|
|
177
177
|
});
|
|
178
178
|
}
|
|
179
|
-
//#endregion
|
|
180
179
|
export { ResizeHandle };
|
package/dist/sidebar/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import * as React from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
4
|
import { mergeProps } from "@base-ui/react/merge-props";
|
|
4
5
|
import { useRender } from "@base-ui/react/use-render";
|
|
5
6
|
import { Button } from "@base-ui/react/button";
|
|
6
|
-
|
|
7
|
-
//#region src/sidebar/index.tsx
|
|
7
|
+
// src/sidebar/index.tsx
|
|
8
8
|
const SidebarContext = React.createContext(null);
|
|
9
9
|
const SidebarGroupContext = React.createContext(null);
|
|
10
10
|
function useSidebarController(part) {
|
|
@@ -298,5 +298,4 @@ const Sidebar = {
|
|
|
298
298
|
Submenu: SidebarSubmenu,
|
|
299
299
|
Trigger: SidebarTrigger
|
|
300
300
|
};
|
|
301
|
-
//#endregion
|
|
302
301
|
export { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarHeader, SidebarInset, SidebarItem, SidebarMenu, SidebarMenuItem, SidebarPanel, SidebarProvider, SidebarRail, SidebarRoot, SidebarSubmenu, SidebarTrigger };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenso/primitives",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Headless product primitives for Lenso UI.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"dist",
|
|
13
|
+
"LICENSE",
|
|
13
14
|
"README.md"
|
|
14
15
|
],
|
|
15
16
|
"type": "module",
|
|
@@ -18,37 +19,44 @@
|
|
|
18
19
|
"types": "./dist/resize-handle/index.d.ts",
|
|
19
20
|
"import": "./dist/resize-handle/index.js"
|
|
20
21
|
},
|
|
22
|
+
"./data-grid": {
|
|
23
|
+
"types": "./dist/data-grid/index.d.ts",
|
|
24
|
+
"import": "./dist/data-grid/index.js"
|
|
25
|
+
},
|
|
21
26
|
"./sidebar": {
|
|
22
27
|
"types": "./dist/sidebar/index.d.ts",
|
|
23
28
|
"import": "./dist/sidebar/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./command": {
|
|
31
|
+
"types": "./dist/command/index.d.ts",
|
|
32
|
+
"import": "./dist/command/index.js"
|
|
24
33
|
}
|
|
25
34
|
},
|
|
26
35
|
"publishConfig": {
|
|
27
36
|
"access": "public"
|
|
28
37
|
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsdown --config tsdown.config.ts && tsc -p tsconfig.build.json --declaration --emitDeclarationOnly --noEmit false --outDir dist",
|
|
40
|
+
"test": "bun test --preload ../../tests/setup/dom.ts src",
|
|
41
|
+
"typecheck": "bun check --no-script --noEmit"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@tanstack/react-table": "9.3.1"
|
|
45
|
+
},
|
|
29
46
|
"devDependencies": {
|
|
30
|
-
"@base-ui/react": "1.
|
|
31
|
-
"@stylexjs/stylex": "0.19.
|
|
32
|
-
"@
|
|
33
|
-
"@types/react": "19.
|
|
34
|
-
"@
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"tsdown": "0.22.14",
|
|
40
|
-
"typescript": "7.0.2",
|
|
41
|
-
"vitest": "4.1.10",
|
|
42
|
-
"vitest-browser-react": "2.2.0"
|
|
47
|
+
"@base-ui/react": "1.9.0",
|
|
48
|
+
"@stylexjs/stylex": "0.19.1",
|
|
49
|
+
"@types/bun": "1.4.4",
|
|
50
|
+
"@types/react": "19.3.0",
|
|
51
|
+
"@types/react-dom": "19.3.0",
|
|
52
|
+
"react": "19.3.1",
|
|
53
|
+
"react-dom": "19.3.1",
|
|
54
|
+
"tsdown": "0.23.7",
|
|
55
|
+
"typescript": "7.0.2"
|
|
43
56
|
},
|
|
44
57
|
"peerDependencies": {
|
|
45
58
|
"@base-ui/react": ">=1.7.0 <2.0.0",
|
|
46
59
|
"@stylexjs/stylex": ">=0.19.0 <1.0.0",
|
|
47
60
|
"react": ">=19.2.0 <20.0.0"
|
|
48
|
-
},
|
|
49
|
-
"scripts": {
|
|
50
|
-
"build": "tsdown --config tsdown.config.ts && tsc -p tsconfig.build.json --declaration --emitDeclarationOnly --noEmit false --outDir dist",
|
|
51
|
-
"test": "vitest run --config vitest.config.ts",
|
|
52
|
-
"typecheck": "tsc --noEmit"
|
|
53
61
|
}
|
|
54
|
-
}
|
|
62
|
+
}
|