tadabut 0.5.0 → 0.6.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/dist/react.d.ts CHANGED
@@ -1,20 +1,35 @@
1
- import { c as TadabutOptions, r as Tadabut$1 } from "./index-KmSXRJlI.js";
1
+ /**
2
+ * The React component.
3
+ *
4
+ * @packageDocumentation
5
+ * @module tadabut/react
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * import { Tadabut } from 'tadabut/react';
10
+ *
11
+ * <Tadabut data={employees} columns={columns} rowId='id' />
12
+ * ```
13
+ */
14
+ import { l as TadabutOptions, r as Tadabut$1 } from "./index-C_77p8Jv.js";
2
15
  import { ReactElement, Ref } from "react";
3
16
  /** What the `ref` gets. No `setData`: change the `data` prop instead. */
4
- export type TadabutHandle<Row extends object> = Pick<Tadabut$1<Row>, "edit" | "save" | "cancel" | "delete" | "isEditing" | "add" | "isAdding" | "saveNew" | "cancelNew">;
17
+ export type TadabutHandle<Row extends object> = Pick<Tadabut$1<Row>, "edit" | "save" | "cancel" | "delete" | "isEditing" | "add" | "isAdding" | "saveNew" | "cancelNew" | "getSelected" | "isSelected" | "select" | "deselect" | "clearSelection">;
5
18
  /** The core options, plus `ref`. */
6
19
  export type TadabutProps<Row extends object> = TadabutOptions<Row> & {
7
20
  /**
8
21
  * Gives you the same methods as the core table: `edit`, `save`, `cancel`,
9
- * `delete`, `add`, `saveNew`, `cancelNew`, `isEditing` and `isAdding`.
22
+ * `delete`, `add`, `saveNew`, `cancelNew`, `isEditing`, `isAdding`,
23
+ * `getSelected`, `isSelected`, `select`, `deselect` and `clearSelection`.
10
24
  */
11
25
  readonly ref?: Ref<TadabutHandle<Row>>;
12
26
  };
13
27
  /**
14
28
  * New `data` updates the table in place. Changing `columns`, `rowId`,
15
- * `dataTables`, `texts` or `totalRows` rebuilds it (and closes open rows), so
16
- * keep the objects stable with a constant or `useMemo`. `editing`,
17
- * `classNames`, `onSave`, `onAdd`, `onDelete` and `confirmDelete` can be
18
- * inline: they're compared by value or read through a ref.
29
+ * `dataTables`, `texts`, `totalRows` or `selection` rebuilds it (and closes
30
+ * open rows, and clears the selection), so keep the objects stable with a
31
+ * constant or `useMemo`. `editing`, `selection`, `classNames` and every `on…`
32
+ * callback (and `confirmDelete`) can be inline: they're compared by value or
33
+ * read through a ref.
19
34
  */
20
- export declare function Tadabut<Row extends object>({ data, columns, rowId, editing, classNames, dataTables, texts, totalRows, onSave, onAdd, onDelete, confirmDelete, ref }: TadabutProps<Row>): ReactElement;
35
+ export declare function Tadabut<Row extends object>({ data, columns, rowId, editing, classNames, dataTables, texts, totalRows, selection, onSelect, onSave, onAdd, onDelete, confirmDelete, onEditStart, onSaved, onAdded, onDeleted, onRowClick, onRowDoubleClick, ref }: TadabutProps<Row>): ReactElement;
package/dist/react.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as Tadabut$1 } from "./src-CBK3xu9-.js";
1
+ import { n as Tadabut$1 } from "./src-BxdYoViF.js";
2
2
  import { useEffect, useImperativeHandle, useRef } from "react";
3
3
  import { jsx } from "react/jsx-runtime";
4
4
  // src/react/index.tsx
@@ -17,12 +17,13 @@ import { jsx } from "react/jsx-runtime";
17
17
  */
18
18
  /**
19
19
  * New `data` updates the table in place. Changing `columns`, `rowId`,
20
- * `dataTables`, `texts` or `totalRows` rebuilds it (and closes open rows), so
21
- * keep the objects stable with a constant or `useMemo`. `editing`,
22
- * `classNames`, `onSave`, `onAdd`, `onDelete` and `confirmDelete` can be
23
- * inline: they're compared by value or read through a ref.
20
+ * `dataTables`, `texts`, `totalRows` or `selection` rebuilds it (and closes
21
+ * open rows, and clears the selection), so keep the objects stable with a
22
+ * constant or `useMemo`. `editing`, `selection`, `classNames` and every `on…`
23
+ * callback (and `confirmDelete`) can be inline: they're compared by value or
24
+ * read through a ref.
24
25
  */
25
- function Tadabut({ data, columns, rowId, editing, classNames, dataTables, texts, totalRows, onSave, onAdd, onDelete, confirmDelete, ref }) {
26
+ function Tadabut({ data, columns, rowId, editing, classNames, dataTables, texts, totalRows, selection, onSelect, onSave, onAdd, onDelete, confirmDelete, onEditStart, onSaved, onAdded, onDeleted, onRowClick, onRowDoubleClick, ref }) {
26
27
  /** The `<div>` the core builds the table in. */
27
28
  const containerRef = useRef(null);
28
29
  /** The core table. `null` before the first build and after unmount. */
@@ -37,8 +38,23 @@ function Tadabut({ data, columns, rowId, editing, classNames, dataTables, texts,
37
38
  const onDeleteRef = useRef(onDelete);
38
39
  /** The latest `confirmDelete`, so a new one doesn't rebuild the table. */
39
40
  const confirmDeleteRef = useRef(confirmDelete);
41
+ /** The latest `onSelect`, so a new one doesn't rebuild the table. */
42
+ const onSelectRef = useRef(onSelect);
43
+ /** The latest `onEditStart`, so a new one doesn't rebuild the table. */
44
+ const onEditStartRef = useRef(onEditStart);
45
+ /** The latest `onSaved`, so a new one doesn't rebuild the table. */
46
+ const onSavedRef = useRef(onSaved);
47
+ /** The latest `onAdded`, so a new one doesn't rebuild the table. */
48
+ const onAddedRef = useRef(onAdded);
49
+ /** The latest `onDeleted`, so a new one doesn't rebuild the table. */
50
+ const onDeletedRef = useRef(onDeleted);
51
+ /** The latest `onRowClick`, so a new one doesn't rebuild the table. */
52
+ const onRowClickRef = useRef(onRowClick);
53
+ /** The latest `onRowDoubleClick`, so a new one doesn't rebuild the table. */
54
+ const onRowDoubleClickRef = useRef(onRowDoubleClick);
40
55
  const mode = editing?.mode;
41
56
  const button = editing?.button;
57
+ const doubleClick = editing?.doubleClick;
42
58
  const tableClass = classNames?.table;
43
59
  const buttonClass = classNames?.button;
44
60
  const editClass = classNames?.edit;
@@ -47,6 +63,9 @@ function Tadabut({ data, columns, rowId, editing, classNames, dataTables, texts,
47
63
  const deleteClass = classNames?.delete;
48
64
  const confirmClass = classNames?.confirm;
49
65
  const keepClass = classNames?.keep;
66
+ const selectClass = classNames?.select;
67
+ const selectionOn = Boolean(selection);
68
+ const checkAll = typeof selection === "object" ? selection.checkAll : void 0;
50
69
  const hasDelete = onDelete !== void 0;
51
70
  const confirmWith = confirmDelete === false ? "never" : confirmDelete === void 0 ? "inline" : "function";
52
71
  useEffect(() => {
@@ -64,11 +83,13 @@ function Tadabut({ data, columns, rowId, editing, classNames, dataTables, texts,
64
83
  rowId,
65
84
  editing: {
66
85
  mode,
67
- button
86
+ button,
87
+ doubleClick
68
88
  },
69
89
  dataTables,
70
90
  texts,
71
91
  totalRows,
92
+ selection: selectionOn && { checkAll },
72
93
  classNames: {
73
94
  table: tableClass,
74
95
  button: buttonClass,
@@ -77,12 +98,20 @@ function Tadabut({ data, columns, rowId, editing, classNames, dataTables, texts,
77
98
  cancel: cancelClass,
78
99
  delete: deleteClass,
79
100
  confirm: confirmClass,
80
- keep: keepClass
101
+ keep: keepClass,
102
+ select: selectClass
81
103
  },
82
104
  onSave: (row, context) => onSaveRef.current?.(row, context),
83
105
  onAdd: (row) => onAddRef.current?.(row),
84
106
  onDelete: hasDelete ? (row) => onDeleteRef.current?.(row) : void 0,
85
- confirmDelete: confirm
107
+ confirmDelete: confirm,
108
+ onSelect: (rows) => onSelectRef.current?.(rows),
109
+ onEditStart: (row) => onEditStartRef.current?.(row),
110
+ onSaved: (row, context) => onSavedRef.current?.(row, context),
111
+ onAdded: (row) => onAddedRef.current?.(row),
112
+ onDeleted: (row) => onDeletedRef.current?.(row),
113
+ onRowClick: (row, event) => onRowClickRef.current?.(row, event),
114
+ onRowDoubleClick: (row, event) => onRowDoubleClickRef.current?.(row, event)
86
115
  });
87
116
  tableRef.current = table;
88
117
  return () => {
@@ -97,6 +126,7 @@ function Tadabut({ data, columns, rowId, editing, classNames, dataTables, texts,
97
126
  totalRows,
98
127
  mode,
99
128
  button,
129
+ doubleClick,
100
130
  tableClass,
101
131
  buttonClass,
102
132
  editClass,
@@ -105,6 +135,9 @@ function Tadabut({ data, columns, rowId, editing, classNames, dataTables, texts,
105
135
  deleteClass,
106
136
  confirmClass,
107
137
  keepClass,
138
+ selectClass,
139
+ selectionOn,
140
+ checkAll,
108
141
  hasDelete,
109
142
  confirmWith
110
143
  ]);
@@ -117,6 +150,13 @@ function Tadabut({ data, columns, rowId, editing, classNames, dataTables, texts,
117
150
  onAddRef.current = onAdd;
118
151
  onDeleteRef.current = onDelete;
119
152
  confirmDeleteRef.current = confirmDelete;
153
+ onSelectRef.current = onSelect;
154
+ onEditStartRef.current = onEditStart;
155
+ onSavedRef.current = onSaved;
156
+ onAddedRef.current = onAdded;
157
+ onDeletedRef.current = onDeleted;
158
+ onRowClickRef.current = onRowClick;
159
+ onRowDoubleClickRef.current = onRowDoubleClick;
120
160
  });
121
161
  useImperativeHandle(ref, () => ({
122
162
  edit: (id) => tableRef.current?.edit(id) ?? false,
@@ -127,7 +167,12 @@ function Tadabut({ data, columns, rowId, editing, classNames, dataTables, texts,
127
167
  isAdding: () => tableRef.current?.isAdding() ?? false,
128
168
  saveNew: () => tableRef.current?.saveNew() ?? Promise.resolve(false),
129
169
  cancelNew: () => tableRef.current?.cancelNew(),
130
- isEditing: (id) => tableRef.current?.isEditing(id) ?? false
170
+ isEditing: (id) => tableRef.current?.isEditing(id) ?? false,
171
+ getSelected: () => tableRef.current?.getSelected() ?? [],
172
+ isSelected: (id) => tableRef.current?.isSelected(id) ?? false,
173
+ select: (ids) => tableRef.current?.select(ids),
174
+ deselect: (ids) => tableRef.current?.deselect(ids),
175
+ clearSelection: () => tableRef.current?.clearSelection()
131
176
  }), []);
132
177
  return /* @__PURE__ */ jsx("div", { ref: containerRef });
133
178
  }