@alulore/kumiko 0.18.3 → 0.19.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.
Files changed (147) hide show
  1. package/dist/dialog/ask.d.ts +7 -0
  2. package/dist/dialog/ask.js +8 -0
  3. package/dist/dialog/dialog-content.d.ts +23 -0
  4. package/dist/dialog/dialog-content.js +15 -0
  5. package/dist/dialog/dialog-entry.d.ts +14 -0
  6. package/dist/dialog/dialog-entry.js +111 -0
  7. package/dist/dialog/dialog-labels.d.ts +23 -0
  8. package/dist/dialog/dialog-labels.js +16 -0
  9. package/dist/dialog/dialog-store.d.ts +139 -0
  10. package/dist/dialog/dialog-store.js +296 -0
  11. package/dist/dialog/dialog.css +36 -0
  12. package/dist/dialog/dialog.d.ts +0 -3
  13. package/dist/dialog/dialog.js +0 -6
  14. package/dist/dialog/index.d.ts +8 -2
  15. package/dist/dialog/index.js +7 -2
  16. package/dist/dialog/leave-guard.d.ts +24 -0
  17. package/dist/dialog/leave-guard.js +98 -0
  18. package/dist/dialog/nest.d.ts +14 -0
  19. package/dist/dialog/nest.js +26 -0
  20. package/dist/dialog/open-dialog.d.ts +16 -0
  21. package/dist/dialog/open-dialog.js +13 -0
  22. package/dist/dialog/overlay-host.d.ts +27 -0
  23. package/dist/dialog/overlay-host.js +47 -0
  24. package/dist/dialog/question-dialog.d.ts +21 -0
  25. package/dist/dialog/question-dialog.js +78 -0
  26. package/dist/drawer/drawer.css +18 -16
  27. package/dist/menu/menu.css +21 -17
  28. package/dist/otp-input/otp-input.css +38 -37
  29. package/dist/page/index.d.ts +8 -0
  30. package/dist/page/index.js +8 -0
  31. package/dist/page/page-action.d.ts +26 -0
  32. package/dist/page/page-action.js +23 -0
  33. package/dist/page/page-actions.d.ts +10 -0
  34. package/dist/page/page-actions.js +66 -0
  35. package/dist/page/page-back.d.ts +11 -0
  36. package/dist/page/page-back.js +17 -0
  37. package/dist/page/page-breadcrumbs.d.ts +21 -0
  38. package/dist/page/page-breadcrumbs.js +60 -0
  39. package/dist/page/page-context.d.ts +5 -0
  40. package/dist/page/page-context.js +13 -0
  41. package/dist/page/page-fit.d.ts +26 -0
  42. package/dist/page/page-fit.js +36 -0
  43. package/dist/page/page-header.d.ts +26 -0
  44. package/dist/page/page-header.js +16 -0
  45. package/dist/page/page-icons.d.ts +4 -0
  46. package/dist/page/page-icons.js +13 -0
  47. package/dist/page/page-labels.d.ts +12 -0
  48. package/dist/page/page-labels.js +6 -0
  49. package/dist/page/page-section.d.ts +14 -0
  50. package/dist/page/page-section.js +9 -0
  51. package/dist/page/page.css +422 -0
  52. package/dist/page/page.d.ts +16 -0
  53. package/dist/page/page.js +12 -0
  54. package/dist/page/use-measured-fit.d.ts +22 -0
  55. package/dist/page/use-measured-fit.js +75 -0
  56. package/dist/page/use-stuck.d.ts +7 -0
  57. package/dist/page/use-stuck.js +31 -0
  58. package/dist/pagination/index.d.ts +3 -0
  59. package/dist/pagination/index.js +3 -0
  60. package/dist/pagination/pagination-extras.d.ts +28 -0
  61. package/dist/pagination/pagination-extras.js +42 -0
  62. package/dist/pagination/pagination-fit.d.ts +15 -0
  63. package/dist/pagination/pagination-fit.js +52 -0
  64. package/dist/pagination/pagination-icons.d.ts +4 -0
  65. package/dist/pagination/pagination-icons.js +16 -0
  66. package/dist/pagination/pagination-labels.d.ts +23 -0
  67. package/dist/pagination/pagination-labels.js +14 -0
  68. package/dist/pagination/pagination-math.d.ts +7 -0
  69. package/dist/pagination/pagination-math.js +24 -0
  70. package/dist/pagination/pagination-motion.d.ts +6 -0
  71. package/dist/pagination/pagination-motion.js +71 -0
  72. package/dist/pagination/pagination.css +455 -0
  73. package/dist/pagination/pagination.d.ts +59 -0
  74. package/dist/pagination/pagination.js +77 -0
  75. package/dist/select/select.css +6 -10
  76. package/dist/server-render.test.js +49 -0
  77. package/dist/sidebar/app-shell.d.ts +54 -0
  78. package/dist/sidebar/app-shell.js +28 -0
  79. package/dist/sidebar/index.d.ts +9 -0
  80. package/dist/sidebar/index.js +8 -0
  81. package/dist/sidebar/shell-context.d.ts +30 -0
  82. package/dist/sidebar/shell-context.js +20 -0
  83. package/dist/sidebar/shell-sheet.d.ts +7 -0
  84. package/dist/sidebar/shell-sheet.js +12 -0
  85. package/dist/sidebar/shell-top-bar.d.ts +8 -0
  86. package/dist/sidebar/shell-top-bar.js +25 -0
  87. package/dist/sidebar/sidebar-body.d.ts +5 -0
  88. package/dist/sidebar/sidebar-body.js +37 -0
  89. package/dist/sidebar/sidebar-icons.d.ts +4 -0
  90. package/dist/sidebar/sidebar-icons.js +13 -0
  91. package/dist/sidebar/sidebar-item.d.ts +26 -0
  92. package/dist/sidebar/sidebar-item.js +68 -0
  93. package/dist/sidebar/sidebar-labels.d.ts +14 -0
  94. package/dist/sidebar/sidebar-labels.js +7 -0
  95. package/dist/sidebar/sidebar-marker.d.ts +12 -0
  96. package/dist/sidebar/sidebar-marker.js +77 -0
  97. package/dist/sidebar/sidebar-storage.d.ts +18 -0
  98. package/dist/sidebar/sidebar-storage.js +27 -0
  99. package/dist/sidebar/sidebar-toggle.d.ts +7 -0
  100. package/dist/sidebar/sidebar-toggle.js +18 -0
  101. package/dist/sidebar/sidebar.css +587 -0
  102. package/dist/sidebar/sidebar.d.ts +19 -0
  103. package/dist/sidebar/sidebar.js +31 -0
  104. package/dist/sidebar/use-collapsed.d.ts +13 -0
  105. package/dist/sidebar/use-collapsed.js +20 -0
  106. package/dist/sidebar/use-narrow.d.ts +4 -0
  107. package/dist/sidebar/use-narrow.js +18 -0
  108. package/dist/sidebar/use-shell-focus.d.ts +8 -0
  109. package/dist/sidebar/use-shell-focus.js +30 -0
  110. package/dist/sidebar/use-shell-shortcut.d.ts +4 -0
  111. package/dist/sidebar/use-shell-shortcut.js +32 -0
  112. package/dist/sidebar/use-shell-state.d.ts +18 -0
  113. package/dist/sidebar/use-shell-state.js +47 -0
  114. package/dist/slider/slider.css +9 -6
  115. package/dist/smooth-caret/caret-geometry.js +10 -4
  116. package/dist/table/data-table-props.d.ts +96 -0
  117. package/dist/table/data-table-props.js +1 -0
  118. package/dist/table/data-table.d.ts +7 -0
  119. package/dist/table/data-table.js +59 -0
  120. package/dist/table/index.d.ts +7 -0
  121. package/dist/table/index.js +5 -0
  122. package/dist/table/table-actions.d.ts +9 -0
  123. package/dist/table/table-actions.js +24 -0
  124. package/dist/table/table-builder.d.ts +60 -0
  125. package/dist/table/table-builder.js +99 -0
  126. package/dist/table/table-cells.d.ts +19 -0
  127. package/dist/table/table-cells.js +67 -0
  128. package/dist/table/table-columns.d.ts +38 -0
  129. package/dist/table/table-columns.js +119 -0
  130. package/dist/table/table-icons.d.ts +3 -0
  131. package/dist/table/table-icons.js +8 -0
  132. package/dist/table/table-labels.d.ts +24 -0
  133. package/dist/table/table-labels.js +17 -0
  134. package/dist/table/table-model.d.ts +28 -0
  135. package/dist/table/table-model.js +69 -0
  136. package/dist/table/table-sections.d.ts +25 -0
  137. package/dist/table/table-sections.js +79 -0
  138. package/dist/table/table-state.d.ts +42 -0
  139. package/dist/table/table-state.js +81 -0
  140. package/dist/table/table-types.d.ts +86 -0
  141. package/dist/table/table-types.js +1 -0
  142. package/dist/table/table.css +919 -0
  143. package/dist/table/use-table-view.d.ts +30 -0
  144. package/dist/table/use-table-view.js +147 -0
  145. package/dist/toast/index.d.ts +1 -2
  146. package/dist/toast/index.js +1 -2
  147. package/package.json +44 -1
@@ -0,0 +1,8 @@
1
+ import { type RefObject } from "react";
2
+ /**
3
+ * In hide mode the part a person pressed disappears when the sidebar slides in or out, so focus would fall to the
4
+ * page. This hands it on: out of a sidebar that hides to the menu button, and from the menu button into the sidebar
5
+ * that comes back. Anything else keeps its focus where it is.
6
+ * Call the returned function before the change, and pass `collapsed` for the effect that moves it afterwards.
7
+ */
8
+ export declare function useShellFocus(shell: RefObject<HTMLElement | null>, collapsed: boolean): (next: boolean) => void;
@@ -0,0 +1,30 @@
1
+ import { useEffect, useRef } from "react";
2
+ const heirs = {
3
+ menu: "[data-sidebar-menu]",
4
+ sidebar: '[data-slot="sidebar"] :is(a[href], button)'
5
+ };
6
+ /**
7
+ * In hide mode the part a person pressed disappears when the sidebar slides in or out, so focus would fall to the
8
+ * page. This hands it on: out of a sidebar that hides to the menu button, and from the menu button into the sidebar
9
+ * that comes back. Anything else keeps its focus where it is.
10
+ * Call the returned function before the change, and pass `collapsed` for the effect that moves it afterwards.
11
+ */
12
+ export function useShellFocus(shell, collapsed) {
13
+ const heir = useRef(null);
14
+ useEffect(() => {
15
+ const target = heir.current;
16
+ heir.current = null;
17
+ if (target) {
18
+ shell.current?.querySelector(heirs[target])?.focus();
19
+ }
20
+ }, [collapsed, shell]);
21
+ return (next) => {
22
+ const active = document.activeElement;
23
+ if (next && active?.closest('[data-slot="sidebar"]')) {
24
+ heir.current = "menu";
25
+ }
26
+ else if (!next && active?.matches("[data-sidebar-menu]")) {
27
+ heir.current = "sidebar";
28
+ }
29
+ };
30
+ }
@@ -0,0 +1,4 @@
1
+ /** Whether a key press would land in something a person types into. */
2
+ export declare function isTyping(element: Element | null): boolean;
3
+ /** Runs `run` on the shortcut, unless it is turned off (`false`) or the focus is in a field. */
4
+ export declare function useShellShortcut(keys: string | false, run: () => void): void;
@@ -0,0 +1,32 @@
1
+ import { useShortcut } from "@ui-sdk/react/shortcuts";
2
+ const notText = new Set([
3
+ "button",
4
+ "checkbox",
5
+ "color",
6
+ "file",
7
+ "image",
8
+ "radio",
9
+ "range",
10
+ "reset",
11
+ "submit"
12
+ ]);
13
+ /** Whether a key press would land in something a person types into. */
14
+ export function isTyping(element) {
15
+ if (!(element instanceof HTMLElement)) {
16
+ return false;
17
+ }
18
+ if (element.isContentEditable || element instanceof HTMLTextAreaElement) {
19
+ return true;
20
+ }
21
+ if (element instanceof HTMLInputElement) {
22
+ return !notText.has(element.type);
23
+ }
24
+ return element instanceof HTMLSelectElement;
25
+ }
26
+ /** Runs `run` on the shortcut, unless it is turned off (`false`) or the focus is in a field. */
27
+ export function useShellShortcut(keys, run) {
28
+ useShortcut(keys === false ? null : keys, run, {
29
+ description: "Toggle the sidebar",
30
+ when: () => !isTyping(document.activeElement)
31
+ });
32
+ }
@@ -0,0 +1,18 @@
1
+ import { type RefObject } from "react";
2
+ import type { SidebarCollapse, AppShellState } from "./shell-context";
3
+ import type { SidebarStorage } from "./sidebar-storage";
4
+ import { type SidebarNarrowAt } from "./use-narrow";
5
+ export interface ShellStateOptions {
6
+ collapse: SidebarCollapse;
7
+ collapsed: boolean | undefined;
8
+ defaultCollapsed: boolean | undefined;
9
+ onCollapsedChange: ((collapsed: boolean) => void) | undefined;
10
+ storage: SidebarStorage | undefined;
11
+ shortcut: string | false;
12
+ narrowAt: SidebarNarrowAt;
13
+ }
14
+ /**
15
+ * Everything the shell holds: whether the sidebar is collapsed (the app's, or its own), whether the window is
16
+ * narrow, and whether the phone drawer is open, which only a narrow window can have.
17
+ */
18
+ export declare function useShellState(options: ShellStateOptions, root: RefObject<HTMLElement | null>): AppShellState;
@@ -0,0 +1,47 @@
1
+ import { useEffect, useState } from "react";
2
+ import { useCollapsed } from "./use-collapsed";
3
+ import { useNarrow } from "./use-narrow";
4
+ import { useShellFocus } from "./use-shell-focus";
5
+ import { useShellShortcut } from "./use-shell-shortcut";
6
+ /**
7
+ * Everything the shell holds: whether the sidebar is collapsed (the app's, or its own), whether the window is
8
+ * narrow, and whether the phone drawer is open, which only a narrow window can have.
9
+ */
10
+ export function useShellState(options, root) {
11
+ const { collapse, shortcut } = options;
12
+ const narrow = useNarrow(options.narrowAt);
13
+ const [collapsed, change] = useCollapsed(options);
14
+ const [menu, setMenu] = useState(false);
15
+ const keepFocus = useShellFocus(root, collapsed);
16
+ useEffect(() => {
17
+ if (!narrow) {
18
+ setMenu(false);
19
+ }
20
+ }, [narrow]);
21
+ const setCollapsed = (next) => {
22
+ if (collapse === "hide" && !narrow) {
23
+ keepFocus(next);
24
+ }
25
+ change(next);
26
+ };
27
+ const toggle = () => {
28
+ setCollapsed(!collapsed);
29
+ };
30
+ useShellShortcut(shortcut, () => {
31
+ if (narrow) {
32
+ setMenu(!menu);
33
+ }
34
+ else {
35
+ toggle();
36
+ }
37
+ });
38
+ return {
39
+ collapsed,
40
+ setCollapsed,
41
+ toggle,
42
+ rail: collapse === "rail" && collapsed && !narrow,
43
+ narrow,
44
+ menuOpen: narrow && menu,
45
+ setMenuOpen: setMenu
46
+ };
47
+ }
@@ -179,17 +179,20 @@
179
179
  border: var(--kumiko-slider-thumb-border-width) solid var(--kumiko-slider-thumb-border);
180
180
  border-radius: 999px;
181
181
  background: var(--kumiko-slider-thumb-bg);
182
+ outline: var(--_slider-ring, none);
183
+ outline-offset: 2px;
182
184
  transition:
183
185
  background-color var(--kumiko-fade-duration) var(--kumiko-fade-ease),
184
186
  scale var(--kumiko-press-duration) var(--kumiko-press-ease);
185
187
  }
186
188
 
187
- /* The ring is for the keyboard: a press with a mouse, pen or finger sets data-pointer, and the next key press clears it. */
188
- [data-slot="slider"]:not([data-pointer])
189
- [data-slot="slider-thumb"]:has(:focus-visible)
190
- [data-slot="slider-thumb-face"] {
191
- outline: 2px solid var(--kumiko-slider-focus-ring);
192
- outline-offset: 2px;
189
+ /*
190
+ * The ring is for the keyboard: a press with a mouse, pen or finger sets data-pointer, and the next key press
191
+ * clears it. The thumb passes it to its face as a property, since a :has() before a combinator would restyle
192
+ * the whole page on every change.
193
+ */
194
+ [data-slot="slider"]:not([data-pointer]) [data-slot="slider-thumb"]:has(:focus-visible) {
195
+ --_slider-ring: 2px solid var(--kumiko-slider-focus-ring);
193
196
  }
194
197
 
195
198
  [data-slot="slider-thumb"][data-dragging] [data-slot="slider-thumb-face"] {
@@ -88,10 +88,16 @@ function fillMirror(field, style) {
88
88
  for (const property of MIRRORED_PROPERTIES) {
89
89
  host.style.setProperty(property, style.getPropertyValue(property));
90
90
  }
91
- const scrollbar = Math.max(0, field.offsetWidth -
92
- field.clientWidth -
93
- pixels(style.borderLeftWidth) -
94
- pixels(style.borderRightWidth));
91
+ /*
92
+ * Only a textarea can show a scrollbar. Edge 157 leaves an input's padding out of its clientWidth; read as a
93
+ * scrollbar, it narrowed the mirror, so centred and right-to-left text measured from the wrong edge.
94
+ */
95
+ const scrollbar = field instanceof HTMLTextAreaElement
96
+ ? Math.max(0, field.offsetWidth -
97
+ field.clientWidth -
98
+ pixels(style.borderLeftWidth) -
99
+ pixels(style.borderRightWidth))
100
+ : 0;
95
101
  host.style.borderStyle = "solid";
96
102
  host.style.borderColor = "transparent";
97
103
  host.style.boxSizing = "border-box";
@@ -0,0 +1,96 @@
1
+ import type { ReactNode } from "react";
2
+ import type { TableLabels } from "./table-labels";
3
+ import type { RowLink, SortRule, TableBreakpoint, TableChange, TableColumn, TableDensity, TableLook, TableNarrow, TableState } from "./table-types";
4
+ export interface SearchOptions {
5
+ /** The search field's accessible name. @defaultValue the `search` word */
6
+ label?: string;
7
+ }
8
+ export interface PagingOptions {
9
+ /** @defaultValue the first of `pageSizes`, or 20 */
10
+ pageSize?: number;
11
+ /** The page sizes to choose from. With it, a "Rows per page" select appears. */
12
+ pageSizes?: readonly number[];
13
+ }
14
+ export interface SortOptions {
15
+ /** The sort it starts with. @defaultValue none */
16
+ initial?: SortRule[];
17
+ /** Whether sorting another column keeps the earlier sorts after it. @defaultValue false */
18
+ multi?: boolean;
19
+ }
20
+ export interface SelectionOptions<Row> {
21
+ /** What the selection bar shows beside the count, given the selected rows. */
22
+ actions?: (rows: Row[]) => ReactNode;
23
+ }
24
+ export interface LoadingOptions {
25
+ /** How many placeholder rows show. @defaultValue 5 */
26
+ rows?: number;
27
+ }
28
+ export interface ServerSideOptions {
29
+ /** How many rows there are in all, across pages. */
30
+ rowCount: number;
31
+ }
32
+ export interface DataTableProps<Row extends object> {
33
+ /** The rows. With `serverSide`, the page shown. */
34
+ data: readonly Row[];
35
+ columns: readonly TableColumn<Row>[];
36
+ /** The table's accessible name, for its caption and its scroll region. */
37
+ label: string;
38
+ /** A row's id, for selection and keys. @defaultValue the row's `id`, when it is a string or number */
39
+ rowId?: (row: Row) => string;
40
+ /** A row's name, for "Select X" and "Actions for X". @defaultValue the text of the link column, or of the first column */
41
+ rowName?: (row: Row) => string;
42
+ /** Renders the app's own link around a row's content in the link column, such as a router's. */
43
+ rowLink?: RowLink<Row>;
44
+ /** The column that holds the link or button. @defaultValue the first data column */
45
+ rowLinkColumn?: string;
46
+ /** Makes each row a button that calls this, in the link column. */
47
+ onRowPress?: (row: Row) => void;
48
+ /** Adds a search field. @defaultValue false */
49
+ search?: boolean | SearchOptions;
50
+ /** @defaultValue `{ pageSize: 20 }` */
51
+ paging?: false | PagingOptions;
52
+ sort?: SortOptions;
53
+ /** Adds a checkbox to each row and a bar for what is selected. @defaultValue false */
54
+ selection?: boolean | SelectionOptions<Row>;
55
+ /** Shows placeholder rows. @defaultValue false */
56
+ loading?: boolean | LoadingOptions;
57
+ /** Shown when there are no rows at all. @defaultValue the `empty` word */
58
+ empty?: ReactNode;
59
+ /**
60
+ * How the table looks. Without it, `data-kumiko-table="striped"`, `"framed"` or `"plain"` on any container picks.
61
+ * @defaultValue "lines"
62
+ */
63
+ look?: TableLook;
64
+ /**
65
+ * Without it, `data-kumiko-table="compact"` on any container picks.
66
+ * @defaultValue "comfortable"
67
+ */
68
+ density?: TableDensity;
69
+ /**
70
+ * What happens below `narrowAt`. Without it, `data-kumiko-table="cards"` on any container picks.
71
+ * @defaultValue "scroll"
72
+ */
73
+ narrow?: TableNarrow;
74
+ /**
75
+ * The container width below which the table turns narrow: 30, 40 or 50rem. Without it,
76
+ * `data-kumiko-table="narrow-sm"` or `"narrow-lg"` on any container picks.
77
+ * @defaultValue "md"
78
+ */
79
+ narrowAt?: TableBreakpoint;
80
+ /** Keeps the header in view while the rows scroll in the table's own box. Without it, `data-kumiko-table="sticky"` picks. @defaultValue false */
81
+ stickyHeader?: boolean;
82
+ /** Replaces any of the English words. */
83
+ labels?: Partial<TableLabels>;
84
+ /** The locale numbers and dates are written in and text is sorted by. @defaultValue the page's */
85
+ locale?: string;
86
+ /** The state it starts with, when uncontrolled. */
87
+ defaultState?: Partial<TableState>;
88
+ /** Controls the state. Pass `onStateChange` with it. */
89
+ state?: TableState;
90
+ onStateChange?: (state: TableState, change: TableChange) => void;
91
+ /**
92
+ * Leaves sorting, searching and paging to the app: the table shows `data` as the current page and reports
93
+ * every change.
94
+ */
95
+ serverSide?: ServerSideOptions;
96
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { DataTableProps } from "./data-table-props";
2
+ /**
3
+ * A data table over TanStack Table, drawn with Kumiko's look: sorting, search, paging, row selection, loading
4
+ * rows and row actions. Every row is one link (or button) with a single tab stop, and the whole row can be
5
+ * clicked. Below `narrowAt` the table scrolls with its first column pinned, or turns each row into a card.
6
+ */
7
+ export declare function DataTable<Row extends object>(props: DataTableProps<Row>): React.JSX.Element;
@@ -0,0 +1,59 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId } from "react";
3
+ import { Pagination } from "../pagination";
4
+ import { Body, Header, Toolbar } from "./table-sections";
5
+ import { useTableView } from "./use-table-view";
6
+ /** The last column that stays on narrow screens, which holds the hidden copy of the row link. */
7
+ function overlayColumnId(props, view) {
8
+ if (!props.rowLink && !props.onRowPress) {
9
+ return undefined;
10
+ }
11
+ const high = props.columns.filter((column) => column.priority === "high");
12
+ return high.at(-1)?.id ?? view.linkColumnId;
13
+ }
14
+ function PagingBar({ props, view }) {
15
+ const { paging } = view;
16
+ if (!paging || view.body === "empty") {
17
+ return null;
18
+ }
19
+ return (_jsx("div", { "data-slot": "table-footer", children: _jsx(Pagination, { total: view.total, page: view.page, onPageChange: (page) => {
20
+ view.dispatch({ type: "page", page });
21
+ }, pageSize: view.state.pageSize, pageSizes: paging.pageSizes, onPageSizeChange: (size) => {
22
+ view.dispatch({ type: "pageSize", size });
23
+ }, range: true, labels: view.words.paging, disabled: Boolean(props.loading), locale: props.locale }) }));
24
+ }
25
+ function searchOf(props, view) {
26
+ if (!props.search) {
27
+ return undefined;
28
+ }
29
+ const label = typeof props.search === "object" ? props.search.label : undefined;
30
+ return { label: label ?? view.words.search };
31
+ }
32
+ function selectionOf(props, view) {
33
+ if (!props.selection) {
34
+ return undefined;
35
+ }
36
+ const actions = typeof props.selection === "object" ? props.selection.actions : undefined;
37
+ return { actions: actions?.(view.selectedRows) };
38
+ }
39
+ /**
40
+ * A data table over TanStack Table, drawn with Kumiko's look: sorting, search, paging, row selection, loading
41
+ * rows and row actions. Every row is one link (or button) with a single tab stop, and the whole row can be
42
+ * clicked. Below `narrowAt` the table scrolls with its first column pinned, or turns each row into a card.
43
+ */
44
+ export function DataTable(props) {
45
+ const captionId = useId();
46
+ const view = useTableView(props);
47
+ const selection = selectionOf(props, view);
48
+ const context = {
49
+ view,
50
+ columns: props.columns,
51
+ locale: props.locale,
52
+ selection: selection !== undefined,
53
+ selected: new Set(view.state.selected),
54
+ rowLink: props.rowLink,
55
+ onRowPress: props.onRowPress,
56
+ overlayId: overlayColumnId(props, view)
57
+ };
58
+ return (_jsxs("div", { "data-slot": "table", "data-look": props.look, "data-density": props.density, "data-narrow": props.narrow, "data-narrow-at": props.narrowAt, "data-sticky": props.stickyHeader === undefined ? undefined : String(props.stickyHeader), children: [_jsx(Toolbar, { view: view, search: searchOf(props, view), selection: selection }), _jsx("div", { "data-slot": "table-scroll", role: "region", "aria-labelledby": captionId, tabIndex: 0, children: _jsxs("table", { role: "table", "aria-busy": view.body === "loading" || undefined, children: [_jsx("caption", { id: captionId, "data-slot": "table-visually-hidden", children: props.label }), _jsx(Header, { columns: props.columns, view: view, selection: selection !== undefined }), _jsx(Body, { context: context, empty: props.empty })] }) }), _jsx(PagingBar, { props: props, view: view })] }));
59
+ }
@@ -0,0 +1,7 @@
1
+ export { DataTable } from "./data-table";
2
+ export type { DataTableProps, LoadingOptions, PagingOptions, SearchOptions, SelectionOptions, ServerSideOptions, SortOptions } from "./data-table-props";
3
+ export { createTable, TableBuilder, type TableLookOptions, type TableStateOptions } from "./table-builder";
4
+ export { actionsColumn, column, compareSortValues, dateColumn, Missing, numberColumn, type Accessor, type ActionsColumn, type ActionsOptions } from "./table-columns";
5
+ export { tableLabels, type TableLabels } from "./table-labels";
6
+ export { nextState, type TableEvent } from "./table-state";
7
+ export type { ActionsLook, ActionTone, CellContext, ColumnOptions, ColumnPriority, RowLink, SortRule, SortValue, TableAction, TableAlign, TableBody, TableBreakpoint, TableChange, TableColumn, TableDensity, TableLook, TableNarrow, TableState } from "./table-types";
@@ -0,0 +1,5 @@
1
+ export { DataTable } from "./data-table";
2
+ export { createTable, TableBuilder } from "./table-builder";
3
+ export { actionsColumn, column, compareSortValues, dateColumn, Missing, numberColumn } from "./table-columns";
4
+ export { tableLabels } from "./table-labels";
5
+ export { nextState } from "./table-state";
@@ -0,0 +1,9 @@
1
+ import type { ActionsColumn } from "./table-columns";
2
+ import type { TableLabels } from "./table-labels";
3
+ /** A row's actions: an icon button with a tooltip for each, or one menu. No actions draws nothing. */
4
+ export declare function RowActions<Row>({ column, row, name, words }: {
5
+ column: ActionsColumn<Row>;
6
+ row: Row;
7
+ name: string;
8
+ words: TableLabels;
9
+ }): React.JSX.Element | null;
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button } from "../button";
3
+ import { Menu, MenuContent, MenuItem, MenuItemIcon, MenuTrigger } from "../menu";
4
+ import { Tooltip, TooltipContent, TooltipTrigger } from "../tooltip";
5
+ import { MoreIcon } from "./table-icons";
6
+ function InlineAction({ action }) {
7
+ return (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(Button, { variant: action.tone === "danger" ? "destructive-ghost" : "ghost", size: "sm", icon: true, "aria-label": action.label, disabled: action.disabled, "data-part": "action", "data-tone": action.tone, onClick: action.onPress }), children: action.icon ?? action.label }), _jsx(TooltipContent, { children: action.label })] }));
8
+ }
9
+ function ActionsMenu({ actions, label }) {
10
+ return (_jsxs(Menu, { onAction: (value) => {
11
+ actions.find((action) => action.id === value)?.onPress();
12
+ }, children: [_jsx(MenuTrigger, { render: _jsx(Button, { variant: "ghost", size: "sm", icon: true, "aria-label": label, "data-part": "action" }), children: _jsx(MoreIcon, {}) }), _jsx(MenuContent, { align: "end", children: actions.map((action) => (_jsxs(MenuItem, { value: action.id, destructive: action.tone === "danger", disabled: action.disabled, children: [action.icon && _jsx(MenuItemIcon, { children: action.icon }), action.label] }, action.id))) })] }));
13
+ }
14
+ /** A row's actions: an icon button with a tooltip for each, or one menu. No actions draws nothing. */
15
+ export function RowActions({ column, row, name, words }) {
16
+ const actions = column.actions(row);
17
+ if (actions.length === 0) {
18
+ return null;
19
+ }
20
+ if (column.look === "menu") {
21
+ return _jsx(ActionsMenu, { actions: actions, label: words.rowActions(name) });
22
+ }
23
+ return (_jsx("span", { "data-slot": "table-actions", children: actions.map((action) => (_jsx(InlineAction, { action: action }, action.id))) }));
24
+ }
@@ -0,0 +1,60 @@
1
+ import type { ReactNode } from "react";
2
+ import type { PagingOptions, SearchOptions, SelectionOptions, SortOptions } from "./data-table-props";
3
+ import { dateColumn, numberColumn, type ActionsOptions, type Accessor } from "./table-columns";
4
+ import type { TableLabels } from "./table-labels";
5
+ import type { ColumnOptions, RowLink, TableAction, TableBreakpoint, TableChange, TableDensity, TableLook, TableNarrow, TableState } from "./table-types";
6
+ type NumberOptions<Row> = Parameters<typeof numberColumn<Row>>[3];
7
+ type DateOptions<Row> = Parameters<typeof dateColumn<Row>>[3];
8
+ type DateRead<Row> = Parameters<typeof dateColumn<Row>>[2];
9
+ export interface TableLookOptions {
10
+ look?: TableLook;
11
+ density?: TableDensity;
12
+ narrow?: TableNarrow;
13
+ narrowAt?: TableBreakpoint;
14
+ stickyHeader?: boolean;
15
+ }
16
+ export interface TableStateOptions {
17
+ /** Controls the state. */
18
+ value?: TableState;
19
+ /** The state it starts with, when uncontrolled. */
20
+ defaultValue?: Partial<TableState>;
21
+ onValueChange?: (state: TableState, change: TableChange) => void;
22
+ serverSide?: {
23
+ rowCount: number;
24
+ };
25
+ }
26
+ /**
27
+ * A table built one call at a time. It is mutable and every method returns it, so `if (x) builder.column(...)`
28
+ * works. It only collects props: `build` hands them to `DataTable`.
29
+ */
30
+ export declare class TableBuilder<Row extends object> {
31
+ #private;
32
+ data(data: readonly Row[]): this;
33
+ rowId(rowId: (row: Row) => string): this;
34
+ rowName(rowName: (row: Row) => string): this;
35
+ column<Value>(id: string, label: string, read: Accessor<Row, Value>, options?: ColumnOptions<Row, Value>): this;
36
+ number(id: string, label: string, read: Accessor<Row, number | null | undefined>, options?: NumberOptions<Row>): this;
37
+ date(id: string, label: string, read: DateRead<Row>, options?: DateOptions<Row>): this;
38
+ actions(actions: (row: Row) => TableAction[], options?: ActionsOptions): this;
39
+ rowLink(link: RowLink<Row>, options?: {
40
+ column?: string;
41
+ }): this;
42
+ onRowPress(onRowPress: (row: Row) => void): this;
43
+ search(options?: SearchOptions): this;
44
+ paging(paging: PagingOptions | false): this;
45
+ sort(sort: SortOptions): this;
46
+ select(options?: SelectionOptions<Row>): this;
47
+ loading(loading: boolean, options?: {
48
+ rows?: number;
49
+ }): this;
50
+ empty(empty: ReactNode): this;
51
+ look(options: TableLookOptions): this;
52
+ labels(labels: Partial<TableLabels>): this;
53
+ locale(locale: string): this;
54
+ label(label: string): this;
55
+ state(options: TableStateOptions): this;
56
+ build(): React.JSX.Element;
57
+ }
58
+ /** Starts a table for rows of one type. The builder only collects props; `DataTable` does the work. */
59
+ export declare function createTable<Row extends object>(): TableBuilder<Row>;
60
+ export {};
@@ -0,0 +1,99 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { DataTable } from "./data-table";
3
+ import { actionsColumn, column, dateColumn, numberColumn } from "./table-columns";
4
+ /** Duplicate ids would make two columns share a sort, a search and a key. */
5
+ function addColumn(columns, added) {
6
+ if (columns.some((existing) => existing.id === added.id)) {
7
+ throw new Error(`createTable: there are two columns with the id "${added.id}".`);
8
+ }
9
+ columns.push(added);
10
+ }
11
+ /**
12
+ * A table built one call at a time. It is mutable and every method returns it, so `if (x) builder.column(...)`
13
+ * works. It only collects props: `build` hands them to `DataTable`.
14
+ */
15
+ export class TableBuilder {
16
+ #columns = [];
17
+ #props = {};
18
+ #set(patch) {
19
+ this.#props = { ...this.#props, ...patch };
20
+ return this;
21
+ }
22
+ data(data) {
23
+ return this.#set({ data });
24
+ }
25
+ rowId(rowId) {
26
+ return this.#set({ rowId });
27
+ }
28
+ rowName(rowName) {
29
+ return this.#set({ rowName });
30
+ }
31
+ column(id, label, read, options) {
32
+ addColumn(this.#columns, column(id, label, read, options));
33
+ return this;
34
+ }
35
+ number(id, label, read, options) {
36
+ addColumn(this.#columns, numberColumn(id, label, read, options));
37
+ return this;
38
+ }
39
+ date(id, label, read, options) {
40
+ addColumn(this.#columns, dateColumn(id, label, read, options));
41
+ return this;
42
+ }
43
+ actions(actions, options) {
44
+ addColumn(this.#columns, actionsColumn(actions, options));
45
+ return this;
46
+ }
47
+ rowLink(link, options) {
48
+ return this.#set({ rowLink: link, rowLinkColumn: options?.column });
49
+ }
50
+ onRowPress(onRowPress) {
51
+ return this.#set({ onRowPress });
52
+ }
53
+ search(options) {
54
+ return this.#set({ search: options ?? true });
55
+ }
56
+ paging(paging) {
57
+ return this.#set({ paging });
58
+ }
59
+ sort(sort) {
60
+ return this.#set({ sort });
61
+ }
62
+ select(options) {
63
+ return this.#set({ selection: options ?? true });
64
+ }
65
+ loading(loading, options) {
66
+ return this.#set({ loading: loading && options ? options : loading });
67
+ }
68
+ empty(empty) {
69
+ return this.#set({ empty });
70
+ }
71
+ look(options) {
72
+ return this.#set(options);
73
+ }
74
+ labels(labels) {
75
+ return this.#set({ labels });
76
+ }
77
+ locale(locale) {
78
+ return this.#set({ locale });
79
+ }
80
+ label(label) {
81
+ return this.#set({ label });
82
+ }
83
+ state(options) {
84
+ return this.#set({
85
+ state: options.value,
86
+ defaultState: options.defaultValue,
87
+ onStateChange: options.onValueChange,
88
+ serverSide: options.serverSide
89
+ });
90
+ }
91
+ build() {
92
+ const { data = [], label = "", ...rest } = this.#props;
93
+ return _jsx(DataTable, { ...rest, data: data, label: label, columns: [...this.#columns] });
94
+ }
95
+ }
96
+ /** Starts a table for rows of one type. The builder only collects props; `DataTable` does the work. */
97
+ export function createTable() {
98
+ return new TableBuilder();
99
+ }
@@ -0,0 +1,19 @@
1
+ import type { RowLink, TableColumn } from "./table-types";
2
+ import type { PageRow, TableView } from "./use-table-view";
3
+ /** What every row needs besides its own data. */
4
+ export interface RowContext<Row extends object> {
5
+ view: TableView<Row>;
6
+ columns: readonly TableColumn<Row>[];
7
+ locale: string | undefined;
8
+ selection: boolean;
9
+ selected: ReadonlySet<string>;
10
+ rowLink: RowLink<Row> | undefined;
11
+ onRowPress: ((row: Row) => void) | undefined;
12
+ /** The column that holds the hidden copy of the link, which covers the whole row. */
13
+ overlayId: string | undefined;
14
+ }
15
+ /** A body row: the selection box, then a cell for each column. */
16
+ export declare function BodyRow<Row extends object>({ context, item }: {
17
+ context: RowContext<Row>;
18
+ item: PageRow<Row>;
19
+ }): React.JSX.Element;