tadabut 0.1.0 → 0.2.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Anas Youssef El Mahdad
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Anas Youssef El Mahdad
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -192,36 +192,141 @@ A few things to know:
192
192
 
193
193
  Tadabut doesn't ship any CSS. Everything it creates gets these classes, so you can style it however you want:
194
194
 
195
- | Class | Used on |
196
- | -------------------- | ----------------------------------------- |
197
- | `tdb-input` | every input |
198
- | `tdb-input-text` | text inputs |
199
- | `tdb-input-number` | number inputs |
200
- | `tdb-input-date` | date inputs |
201
- | `tdb-input-checkbox` | checkboxes |
202
- | `tdb-input-select` | selects |
203
- | `tdb-error` | a field's error message, under its input |
204
- | `tdb-save-error` | the error under a row that failed to save |
205
- | `tdb-row-saving` | a row while it's being saved |
206
- | `tdb-actions` | the column with the buttons, header too |
207
- | `tdb-button` | every button |
208
- | `tdb-button-edit` | the Edit button |
209
- | `tdb-button-save` | the Save button |
210
- | `tdb-button-cancel` | the Cancel button |
211
-
212
- To use Bootstrap, Tailwind or anything else, put your classes in `className`. They get added next to the `tdb-` ones.
195
+ | Class | Used on |
196
+ | ------------------------ | ------------------------------------------------- |
197
+ | `tdb-input` | every input |
198
+ | `tdb-input-text` | text inputs |
199
+ | `tdb-input-number` | number inputs |
200
+ | `tdb-input-date` | date inputs |
201
+ | `tdb-input-checkbox` | checkboxes |
202
+ | `tdb-input-select` | selects |
203
+ | `tdb-error` | a field's error message, under its input |
204
+ | `tdb-save-error` | the line (`<tr>`) under a row that failed to save |
205
+ | `tdb-save-error-message` | the message inside that line |
206
+ | `tdb-row-editing` | a row while it's being edited |
207
+ | `tdb-row-saving` | a row while it's being saved |
208
+ | `tdb-actions` | the column with the buttons, header too |
209
+ | `tdb-button` | every button |
210
+ | `tdb-button-edit` | the Edit button |
211
+ | `tdb-button-save` | the Save button |
212
+ | `tdb-button-cancel` | the Cancel button |
213
+
214
+ To use Bootstrap, Tailwind or anything else, add your own classes. They always go next to the `tdb-` ones, never instead of them. There are two places:
215
+
216
+ - `className` on an editor, for its input.
217
+ - `classNames` on the table, for the `<table>` and the buttons.
213
218
 
214
219
  ```ts
215
- // Bootstrap
216
- { prop: 'name', title: 'Name', editor: { type: 'text', className: 'form-control' } }
220
+ const table = new Tadabut(container, {
221
+ data: employees,
222
+ rowId: 'id',
223
+ columns: [
224
+ { prop: 'id', title: 'ID' },
225
+ {
226
+ prop: 'name',
227
+ title: 'Name',
228
+ editor: { type: 'text', className: 'w-full rounded border px-2 py-1' },
229
+ },
230
+ ],
231
+ classNames: {
232
+ table: 'w-full text-sm',
233
+ button: 'rounded px-2 py-1',
234
+ save: 'bg-blue-600 text-white',
235
+ },
236
+ });
237
+ ```
238
+
239
+ | `classNames` key | Added to |
240
+ | ---------------- | --------------------------------- |
241
+ | `table` | the `<table>` |
242
+ | `button` | the Edit, Save and Cancel buttons |
243
+ | `edit` | the Edit button only |
244
+ | `save` | the Save button only |
245
+ | `cancel` | the Cancel button only |
246
+
247
+ All of them are optional. Tadabut doesn't know any CSS framework: it adds the classes you give it, and nothing else. If you use Tailwind: it only keeps classes it finds in your own files. Classes in your column config count, so they work.
248
+
249
+ DataTables' own parts (the search box, the page size, the paging buttons) are styled by the DataTables package you install: `datatables.net-dt` for the default look, `datatables.net-bs5` for Bootstrap 5, and so on.
250
+
251
+ #### With Bootstrap 5
252
+
253
+ Install the Bootstrap version of DataTables instead of `datatables.net-dt`, and Bootstrap itself:
254
+
255
+ ```sh
256
+ pnpm add tadabut datatables.net-bs5 bootstrap
257
+ ```
217
258
 
218
- // Tailwind
219
- { prop: 'name', title: 'Name', editor: { type: 'text', className: 'w-full rounded border px-2 py-1' } }
259
+ Import them once:
260
+
261
+ ```ts
262
+ import 'bootstrap/dist/css/bootstrap.min.css';
263
+ import 'datatables.net-bs5';
264
+ import 'datatables.net-bs5/css';
220
265
  ```
221
266
 
222
- If you use Tailwind: it only keeps classes it finds in your own files. Classes in your column config count, so they work.
267
+ Then give the editors and the table Bootstrap's classes:
268
+
269
+ ```ts
270
+ const columns: Column<Employee>[] = [
271
+ { prop: 'id', title: 'ID' },
272
+ {
273
+ prop: 'name',
274
+ title: 'Name',
275
+ editor: { type: 'text', className: 'form-control form-control-sm' },
276
+ },
277
+ {
278
+ prop: 'countryId',
279
+ title: 'Country',
280
+ editor: {
281
+ type: 'select',
282
+ className: 'form-select form-select-sm',
283
+ options: [
284
+ { value: 1, label: 'Morocco' },
285
+ { value: 2, label: 'France' },
286
+ ],
287
+ },
288
+ },
289
+ { prop: 'active', title: 'Active', editor: { type: 'checkbox', className: 'form-check-input' } },
290
+ ];
291
+
292
+ const table = new Tadabut(container, {
293
+ data: employees,
294
+ rowId: 'id',
295
+ columns,
296
+ classNames: {
297
+ table: 'table table-striped table-hover align-middle',
298
+ button: 'btn btn-sm',
299
+ edit: 'btn-outline-primary',
300
+ save: 'btn-primary',
301
+ cancel: 'btn-outline-secondary',
302
+ },
303
+ });
304
+ ```
305
+
306
+ Error messages and the rows being edited need a few lines of your own CSS:
307
+
308
+ ```css
309
+ /* Errors in Bootstrap's red. Use the message's class, not the row's:
310
+ Bootstrap sets a color on every table cell. */
311
+ .tdb-error,
312
+ .tdb-save-error-message {
313
+ color: var(--bs-form-invalid-color);
314
+ font-size: 0.875em;
315
+ }
316
+
317
+ /* While editing, line the inputs up at the top, so an error under one
318
+ input doesn't move the others. */
319
+ .table > tbody > tr.tdb-row-editing > td {
320
+ vertical-align: top;
321
+ }
322
+
323
+ .tdb-row-saving {
324
+ opacity: 0.5;
325
+ }
326
+ ```
223
327
 
224
- The table itself is styled by the DataTables package you install: `datatables.net-dt` for the default look, `datatables.net-bs5` for Bootstrap 5, and so on.
328
+ > [!TIP]
329
+ > Each DataTables styling package needs one exact version of `datatables.net`. Don't add `datatables.net` yourself next to it. If you have to, use the same version as the styling package. Two different versions means two copies of DataTables: the table works, but the Bootstrap look doesn't show up on the search box and the paging buttons.
225
330
 
226
331
  ### Custom editors
227
332
 
@@ -549,7 +654,7 @@ export default function Employees() {
549
654
  - [x] Row editing: save, cancel, validation errors
550
655
  - [x] Chained selects
551
656
  - [x] Show labels instead of raw values in cells
552
- - [ ] First release (0.1.0)
657
+ - [x] First release (0.1.0)
553
658
  - [ ] Keyboard navigation, translations, theming
554
659
 
555
660
  Later: adding and deleting rows, popup editing, changing many rows in one go, server-side mode, Vue and jQuery adapters.
@@ -375,6 +375,35 @@ type EditingOptions = {
375
375
  */
376
376
  readonly button?: boolean;
377
377
  };
378
+ /**
379
+ * Your own CSS classes for the table and its buttons, like Bootstrap's or
380
+ * Tailwind's.
381
+ *
382
+ * They are added next to the `tdb-` classes, never instead of them, so CSS
383
+ * that targets `tdb-` classes keeps working.
384
+ *
385
+ * @example
386
+ * // Bootstrap 5
387
+ * {
388
+ * table: 'table table-striped table-hover',
389
+ * button: 'btn btn-sm',
390
+ * edit: 'btn-outline-primary',
391
+ * save: 'btn-primary',
392
+ * cancel: 'btn-outline-secondary',
393
+ * }
394
+ */
395
+ type TableClassNames = {
396
+ /** Added to the `<table>`. */
397
+ readonly table?: string;
398
+ /** Added to the Edit, Save and Cancel buttons. */
399
+ readonly button?: string;
400
+ /** Added to the Edit button only. */
401
+ readonly edit?: string;
402
+ /** Added to the Save button only. */
403
+ readonly save?: string;
404
+ /** Added to the Cancel button only. */
405
+ readonly cancel?: string;
406
+ };
378
407
  /**
379
408
  * Options for creating a Tadabut table.
380
409
  *
@@ -394,6 +423,8 @@ type TadabutOptions<Row extends object> = {
394
423
  readonly rowId?: keyof Row & string;
395
424
  /** How rows are edited. Only used when a column has an `editor`. */
396
425
  readonly editing?: EditingOptions;
426
+ /** Your CSS classes for the table and the buttons, like Bootstrap's. */
427
+ readonly classNames?: TableClassNames;
397
428
  /**
398
429
  * Called when a row is saved, after every field passed validation.
399
430
  * It can be async.
@@ -430,6 +461,8 @@ declare class Tadabut<Row extends object> {
430
461
  private readonly columns;
431
462
  /** The `editing` option, with its defaults filled in. */
432
463
  private readonly editing;
464
+ /** The user's extra classes. `{}` when there are none. */
465
+ private readonly classNames;
433
466
  private readonly onSave;
434
467
  /** Whether the table has the actions column, with the Edit buttons. */
435
468
  private readonly hasActions;
@@ -529,8 +562,12 @@ declare class Tadabut<Row extends object> {
529
562
  */
530
563
  private setSaving;
531
564
  /**
532
- * Shows a save error on its own line under the row, with the
533
- * `tdb-save-error` class.
565
+ * Shows a save error on its own line under the row. The line (a `<tr>`)
566
+ * gets `tdb-save-error`, and the message inside it gets
567
+ * `tdb-save-error-message`.
568
+ *
569
+ * The message needs its own class: frameworks like Bootstrap set a color
570
+ * on every table cell, which hides a color set on the `<tr>`.
534
571
  *
535
572
  * The message is set as text, never as HTML: it often comes from a server,
536
573
  * and HTML in it could run code in the page.
@@ -563,4 +600,4 @@ declare class Tadabut<Row extends object> {
563
600
  */
564
601
  private readonly onKeyDown;
565
602
  }
566
- export { EditorContext as _, Column as a, TextEditor as c, SelectOption as d, SelectOptionsLoader as f, CheckboxEditor as g, CustomEditor as h, TadabutOptions as i, OptionsContext as l, DateEditor as m, EditingOptions as n, ValidationOptions as o, NumberEditor as p, SaveContext as r, EditorFor as s, Tadabut as t, SelectEditor as u, EditorInstance as v };
603
+ export { CheckboxEditor as _, TadabutOptions as a, EditorFor as c, SelectEditor as d, SelectOption as f, CustomEditor as g, DateEditor as h, TableClassNames as i, TextEditor as l, NumberEditor as m, EditingOptions as n, Column as o, SelectOptionsLoader as p, SaveContext as r, ValidationOptions as s, Tadabut as t, OptionsContext as u, EditorContext as v, EditorInstance as y };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as EditorContext, a as Column, c as TextEditor, d as SelectOption, f as SelectOptionsLoader, g as CheckboxEditor, h as CustomEditor, i as TadabutOptions, l as OptionsContext, m as DateEditor, n as EditingOptions, o as ValidationOptions, p as NumberEditor, r as SaveContext, s as EditorFor, t as Tadabut, u as SelectEditor, v as EditorInstance } from "./index-BJkz6K5r.js";
2
- export { type CheckboxEditor, type Column, type CustomEditor, type DateEditor, type EditingOptions, type EditorContext, type EditorFor, type EditorInstance, type NumberEditor, type OptionsContext, type SaveContext, type SelectEditor, type SelectOption, type SelectOptionsLoader, Tadabut, type TadabutOptions, type TextEditor, type ValidationOptions };
1
+ import { _ as CheckboxEditor, a as TadabutOptions, c as EditorFor, d as SelectEditor, f as SelectOption, g as CustomEditor, h as DateEditor, i as TableClassNames, l as TextEditor, m as NumberEditor, n as EditingOptions, o as Column, p as SelectOptionsLoader, r as SaveContext, s as ValidationOptions, t as Tadabut, u as OptionsContext, v as EditorContext, y as EditorInstance } from "./index-D2g9_Fd9.js";
2
+ export { type CheckboxEditor, type Column, type CustomEditor, type DateEditor, type EditingOptions, type EditorContext, type EditorFor, type EditorInstance, type NumberEditor, type OptionsContext, type SaveContext, type SelectEditor, type SelectOption, type SelectOptionsLoader, type TableClassNames, Tadabut, type TadabutOptions, type TextEditor, type ValidationOptions };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { t as Tadabut } from "./src-bibmHRHk.js";
1
+ export { t as Tadabut } from "./src-C4vgw-1w.js";
package/dist/react.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { i as TadabutOptions, t as Tadabut$1 } from "./index-BJkz6K5r.js";
1
+ import { a as TadabutOptions, t as Tadabut$1 } from "./index-D2g9_Fd9.js";
2
2
  import { ReactElement, Ref } from "react";
3
3
  /**
4
4
  * What a `ref` on the `Tadabut` component gets: the core's editing methods.
@@ -26,12 +26,14 @@ export type TadabutProps<Row extends object> = TadabutOptions<Row> & {
26
26
  *
27
27
  * - New `data` updates the table in place: sorting, search and the current
28
28
  * page are kept.
29
- * - New `columns`, `rowId`, `editing.mode` or `editing.button` rebuild the
30
- * table, and any row being edited is lost. Define `columns` outside the
31
- * component, or with `useMemo`.
29
+ * - New `columns`, `rowId`, `editing.mode`, `editing.button` or `classNames`
30
+ * values rebuild the table, and any row being edited is lost. Define
31
+ * `columns` outside the component, or with `useMemo`.
32
+ * - `editing` and `classNames` can be new objects on every render: only a
33
+ * change in their values rebuilds the table.
32
34
  * - `onSave` can be a new function on every render. The table always calls
33
35
  * the latest one, without being rebuilt.
34
36
  *
35
37
  * @typeParam Row - The shape of one row. Usually worked out from `data`.
36
38
  */
37
- export declare function Tadabut<Row extends object>({ data, columns, rowId, editing, onSave, ref }: TadabutProps<Row>): ReactElement;
39
+ export declare function Tadabut<Row extends object>({ data, columns, rowId, editing, classNames, onSave, ref }: TadabutProps<Row>): ReactElement;
package/dist/react.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as Tadabut$1 } from "./src-bibmHRHk.js";
1
+ import { t as Tadabut$1 } from "./src-C4vgw-1w.js";
2
2
  import { useEffect, useImperativeHandle, useRef } from "react";
3
3
  import { jsx } from "react/jsx-runtime";
4
4
  // src/react/index.tsx
@@ -20,15 +20,17 @@ import { jsx } from "react/jsx-runtime";
20
20
  *
21
21
  * - New `data` updates the table in place: sorting, search and the current
22
22
  * page are kept.
23
- * - New `columns`, `rowId`, `editing.mode` or `editing.button` rebuild the
24
- * table, and any row being edited is lost. Define `columns` outside the
25
- * component, or with `useMemo`.
23
+ * - New `columns`, `rowId`, `editing.mode`, `editing.button` or `classNames`
24
+ * values rebuild the table, and any row being edited is lost. Define
25
+ * `columns` outside the component, or with `useMemo`.
26
+ * - `editing` and `classNames` can be new objects on every render: only a
27
+ * change in their values rebuilds the table.
26
28
  * - `onSave` can be a new function on every render. The table always calls
27
29
  * the latest one, without being rebuilt.
28
30
  *
29
31
  * @typeParam Row - The shape of one row. Usually worked out from `data`.
30
32
  */
31
- function Tadabut({ data, columns, rowId, editing, onSave, ref }) {
33
+ function Tadabut({ data, columns, rowId, editing, classNames, onSave, ref }) {
32
34
  /** The empty `<div>` React renders. The core builds the table inside it. */
33
35
  const containerRef = useRef(null);
34
36
  /**
@@ -49,6 +51,11 @@ function Tadabut({ data, columns, rowId, editing, onSave, ref }) {
49
51
  const onSaveRef = useRef(onSave);
50
52
  const mode = editing?.mode;
51
53
  const button = editing?.button;
54
+ const tableClass = classNames?.table;
55
+ const buttonClass = classNames?.button;
56
+ const editClass = classNames?.edit;
57
+ const saveClass = classNames?.save;
58
+ const cancelClass = classNames?.cancel;
52
59
  useEffect(() => {
53
60
  const container = containerRef.current;
54
61
  if (!container) return;
@@ -60,6 +67,13 @@ function Tadabut({ data, columns, rowId, editing, onSave, ref }) {
60
67
  mode,
61
68
  button
62
69
  },
70
+ classNames: {
71
+ table: tableClass,
72
+ button: buttonClass,
73
+ edit: editClass,
74
+ save: saveClass,
75
+ cancel: cancelClass
76
+ },
63
77
  onSave: (row, context) => onSaveRef.current?.(row, context)
64
78
  });
65
79
  tableRef.current = table;
@@ -71,7 +85,12 @@ function Tadabut({ data, columns, rowId, editing, onSave, ref }) {
71
85
  columns,
72
86
  rowId,
73
87
  mode,
74
- button
88
+ button,
89
+ tableClass,
90
+ buttonClass,
91
+ editClass,
92
+ saveClass,
93
+ cancelClass
75
94
  ]);
76
95
  useEffect(() => {
77
96
  dataRef.current = data;
@@ -1,4 +1,28 @@
1
1
  import DataTable from "datatables.net";
2
+ // src/editors/classes.ts
3
+ /**
4
+ * Turns class lists like `'btn btn-sm '` into single classes, like
5
+ * `['btn', 'btn-sm']`.
6
+ *
7
+ * Internal. Each list can hold several classes separated by any spaces.
8
+ * `undefined` lists and empty pieces are skipped, because
9
+ * `classList.add('')` throws.
10
+ *
11
+ * @param lists The class lists, in order. `undefined` is allowed, so
12
+ * optional options can be passed as they are.
13
+ */
14
+ function splitClasses(...lists) {
15
+ return lists.flatMap((list) => list?.split(/\s+/).filter(Boolean) ?? []);
16
+ }
17
+ /**
18
+ * Adds Tadabut's own classes and the user's `className` to an element.
19
+ *
20
+ * Internal. `className` can hold several classes separated by any spaces,
21
+ * like `'border rounded'`.
22
+ */
23
+ function addClasses(element, ownClasses, className) {
24
+ element.classList.add(...ownClasses, ...splitClasses(className));
25
+ }
2
26
  // src/columns/escape.ts
3
27
  /** The characters that mean something in HTML, and what replaces them. */
4
28
  const entities = {
@@ -23,17 +47,24 @@ function escapeHtml(text) {
23
47
  * The last column, with the Edit button. When a row is being edited, its
24
48
  * cell holds Save and Cancel instead.
25
49
  *
26
- * The HTML is a string because it is our own fixed text, never user data,
27
- * so nothing in it can run code.
50
+ * DataTables wants the button as an HTML string. The user's classes go
51
+ * inside that string, so they are escaped: a class like `x" onclick="…`
52
+ * stays a (strange) class, and can't close the attribute and add code.
28
53
  */
29
- const actionsColumn = {
30
- title: "",
31
- data: null,
32
- className: "tdb-actions",
33
- orderable: false,
34
- searchable: false,
35
- defaultContent: "<button type=\"button\" class=\"tdb-button tdb-button-edit\" data-tdb-action=\"edit\">Edit</button>"
36
- };
54
+ function actionsColumn(classNames) {
55
+ return {
56
+ title: "",
57
+ data: null,
58
+ className: "tdb-actions",
59
+ orderable: false,
60
+ searchable: false,
61
+ defaultContent: `<button type="button" class="${escapeHtml([
62
+ "tdb-button",
63
+ "tdb-button-edit",
64
+ ...splitClasses(classNames.button, classNames.edit)
65
+ ].join(" "))}" data-tdb-action="edit">Edit</button>`
66
+ };
67
+ }
37
68
  /**
38
69
  * Turns Tadabut columns into DataTables column settings.
39
70
  *
@@ -44,8 +75,9 @@ const actionsColumn = {
44
75
  * @param withActions Adds the actions column at the end. It must stay last:
45
76
  * the user's columns keep their positions, and Tadabut finds cells by
46
77
  * position.
78
+ * @param classNames The user's classes. Only the Edit button uses them here.
47
79
  */
48
- function toDataTables(columns, withActions) {
80
+ function toDataTables(columns, withActions, classNames) {
49
81
  const converted = columns.map((column) => {
50
82
  const label = labelOf(column);
51
83
  return {
@@ -60,7 +92,7 @@ function toDataTables(columns, withActions) {
60
92
  }
61
93
  };
62
94
  });
63
- return withActions ? [...converted, { ...actionsColumn }] : converted;
95
+ return withActions ? [...converted, actionsColumn(classNames)] : converted;
64
96
  }
65
97
  /**
66
98
  * Picks how a column's value becomes text: its own `render`, else the label
@@ -79,18 +111,6 @@ function labelOf(column) {
79
111
  function asText(value) {
80
112
  return value === null || value === void 0 ? "" : String(value);
81
113
  }
82
- // src/editors/classes.ts
83
- /**
84
- * Adds Tadabut's own classes and the user's `className` to an element.
85
- *
86
- * Internal. `className` can hold several classes separated by any spaces,
87
- * like `'border rounded'`. Empty pieces are skipped, because
88
- * `classList.add('')` throws.
89
- */
90
- function addClasses(element, ownClasses, className) {
91
- const userClasses = className?.split(/\s+/).filter(Boolean) ?? [];
92
- element.classList.add(...ownClasses, ...userClasses);
93
- }
94
114
  // src/editors/checkbox.ts
95
115
  /**
96
116
  * Creates a live checkbox editor.
@@ -657,6 +677,8 @@ var Tadabut = class {
657
677
  columns;
658
678
  /** The `editing` option, with its defaults filled in. */
659
679
  editing;
680
+ /** The user's extra classes. `{}` when there are none. */
681
+ classNames;
660
682
  onSave;
661
683
  /** Whether the table has the actions column, with the Edit buttons. */
662
684
  hasActions;
@@ -684,11 +706,13 @@ var Tadabut = class {
684
706
  };
685
707
  this.hasActions = this.hasEditor && this.editing.button;
686
708
  this.onSave = options.onSave;
709
+ this.classNames = options.classNames ?? {};
687
710
  this.tableEl = document.createElement("table");
711
+ addClasses(this.tableEl, [], this.classNames.table);
688
712
  container.appendChild(this.tableEl);
689
713
  this.dataTable = new DataTable(this.tableEl, {
690
714
  data: [...options.data],
691
- columns: toDataTables(options.columns, this.hasActions)
715
+ columns: toDataTables(options.columns, this.hasActions, this.classNames)
692
716
  });
693
717
  if (this.hasActions) this.tableEl.addEventListener("click", this.onClick);
694
718
  if (this.hasEditor) this.tableEl.addEventListener("keydown", this.onKeyDown);
@@ -735,7 +759,8 @@ var Tadabut = class {
735
759
  }
736
760
  });
737
761
  this.sessions.set(id, new EditSession(row.data(), cells));
738
- if (this.hasActions) this.dataTable.cell(rowIndex, this.columns.length).node().replaceChildren(actionButton("save", "Save"), actionButton("cancel", "Cancel"));
762
+ row.node()?.classList.add("tdb-row-editing");
763
+ if (this.hasActions) this.dataTable.cell(rowIndex, this.columns.length).node().replaceChildren(actionButton("save", "Save", splitClasses(this.classNames.button, this.classNames.save)), actionButton("cancel", "Cancel", splitClasses(this.classNames.button, this.classNames.cancel)));
739
764
  return true;
740
765
  }
741
766
  /**
@@ -751,6 +776,7 @@ var Tadabut = class {
751
776
  session.destroy();
752
777
  this.sessions.delete(id);
753
778
  this.clearSaveError(id);
779
+ this.findRow(id)?.node()?.classList.remove("tdb-row-editing");
754
780
  this.findRow(id)?.invalidate("data").draw(false);
755
781
  }
756
782
  /**
@@ -809,6 +835,7 @@ var Tadabut = class {
809
835
  session.destroy();
810
836
  this.sessions.delete(id);
811
837
  this.findRow(id)?.data({ ...saved }).draw(false);
838
+ this.findRow(id)?.node()?.classList.remove("tdb-row-editing");
812
839
  this.setSaving(id, false);
813
840
  return true;
814
841
  }
@@ -858,14 +885,19 @@ var Tadabut = class {
858
885
  }
859
886
  }
860
887
  /**
861
- * Shows a save error on its own line under the row, with the
862
- * `tdb-save-error` class.
888
+ * Shows a save error on its own line under the row. The line (a `<tr>`)
889
+ * gets `tdb-save-error`, and the message inside it gets
890
+ * `tdb-save-error-message`.
891
+ *
892
+ * The message needs its own class: frameworks like Bootstrap set a color
893
+ * on every table cell, which hides a color set on the `<tr>`.
863
894
  *
864
895
  * The message is set as text, never as HTML: it often comes from a server,
865
896
  * and HTML in it could run code in the page.
866
897
  */
867
898
  showSaveError(id, message) {
868
899
  const error = document.createElement("div");
900
+ error.className = "tdb-save-error-message";
869
901
  error.textContent = message;
870
902
  this.findRow(id)?.child(error, "tdb-save-error").show();
871
903
  }
@@ -936,11 +968,13 @@ var Tadabut = class {
936
968
  *
937
969
  * Built with `createElement`, not an HTML string, so a label can never be
938
970
  * read as HTML, even once labels can be translated.
971
+ *
972
+ * @param extra The user's classes from `classNames`, already split.
939
973
  */
940
- function actionButton(action, label) {
974
+ function actionButton(action, label, extra) {
941
975
  const button = document.createElement("button");
942
976
  button.type = "button";
943
- button.className = `tdb-button tdb-button-${action}`;
977
+ button.classList.add("tdb-button", `tdb-button-${action}`, ...extra);
944
978
  button.dataset.tdbAction = action;
945
979
  button.textContent = label;
946
980
  return button;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tadabut",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Typed wrapper for DataTables with row editing, rich inputs and chained selects.",
5
5
  "keywords": [
6
6
  "datatables",
@@ -42,14 +42,16 @@
42
42
  "@biomejs/biome": "2.5.15",
43
43
  "@types/react": "^19.3.0",
44
44
  "@types/react-dom": "^19.3.0",
45
- "@vitejs/plugin-react": "^6.1.2",
46
- "datatables.net": "^3.1.4",
47
- "datatables.net-dt": "^3.1.4",
45
+ "@vitejs/plugin-react": "^6.2.1",
46
+ "bootstrap": "^5.3.8",
47
+ "datatables.net": "^3.1.5",
48
+ "datatables.net-bs5": "^3.1.5",
49
+ "datatables.net-dt": "^3.1.5",
48
50
  "jsdom": "^30.1.3",
49
51
  "publint": "^0.3.25",
50
52
  "react": "^19.3.1",
51
53
  "react-dom": "^19.3.1",
52
- "tsdown": "^0.23.3",
54
+ "tsdown": "^0.23.4",
53
55
  "typescript": "^7.0.2",
54
56
  "vite": "^8.3.5",
55
57
  "vitest": "^5.0.5"