@alulore/kumiko 0.20.1 → 0.21.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/avatar/avatar.js +1 -1
- package/dist/badge/badge.css +41 -3
- package/dist/badge/badge.js +11 -4
- package/dist/board/board-slots.js +2 -1
- package/dist/board/scrollbar-gutter.js +26 -2
- package/dist/button/button.css +21 -7
- package/dist/card/card.css +3 -2
- package/dist/card/item-card.d.ts +1 -1
- package/dist/card/item-card.js +3 -2
- package/dist/chip/chip.css +6 -10
- package/dist/chip/chip.js +1 -1
- package/dist/form/error-line.js +4 -3
- package/dist/input/input.css +99 -114
- package/dist/list-row/list-row-motion.js +29 -10
- package/dist/media-viewer/gesture-press.d.ts +1 -0
- package/dist/media-viewer/gesture-press.js +12 -0
- package/dist/media-viewer/media-slide.d.ts +3 -1
- package/dist/media-viewer/media-slide.js +3 -2
- package/dist/media-viewer/media-viewer.css +5 -1
- package/dist/media-viewer/media-viewer.js +41 -23
- package/dist/media-viewer/stage-rect.d.ts +16 -0
- package/dist/media-viewer/stage-rect.js +56 -0
- package/dist/media-viewer/view-gesture.d.ts +1 -2
- package/dist/media-viewer/view-gesture.js +39 -44
- package/dist/media-viewer/viewer-chrome.d.ts +2 -1
- package/dist/media-viewer/viewer-chrome.js +3 -1
- package/dist/media-viewer/viewer-motion.d.ts +1 -0
- package/dist/media-viewer/viewer-motion.js +20 -7
- package/dist/media-viewer/zoom-pan.d.ts +1 -0
- package/dist/media-viewer/zoom-pan.js +3 -0
- package/dist/media-viewer/zoom-store.d.ts +8 -0
- package/dist/media-viewer/zoom-store.js +30 -0
- package/dist/menu/menu.js +6 -3
- package/dist/menu/point-menu.js +32 -12
- package/dist/motion/flip.js +33 -20
- package/dist/page/page-actions.js +2 -1
- package/dist/page/page-breadcrumbs.js +2 -1
- package/dist/page/use-measured-fit.d.ts +5 -0
- package/dist/page/use-measured-fit.js +47 -5
- package/dist/page/use-stuck.js +12 -2
- package/dist/pagination/pagination-fit.d.ts +3 -1
- package/dist/pagination/pagination-fit.js +4 -3
- package/dist/pagination/pagination-motion.js +18 -11
- package/dist/pagination/pagination.css +50 -6
- package/dist/pagination/pagination.js +20 -3
- package/dist/progress/progress.css +3 -2
- package/dist/progress/progress.js +15 -3
- package/dist/select/select-labels.d.ts +2 -0
- package/dist/select/select-labels.js +5 -1
- package/dist/select/select.css +7 -11
- package/dist/select/select.d.ts +1 -1
- package/dist/select/select.js +12 -6
- package/dist/shortcuts/hints.js +10 -4
- package/dist/shortcuts/provider.d.ts +4 -2
- package/dist/shortcuts/provider.js +14 -17
- package/dist/skeleton/skeleton.css +22 -9
- package/dist/slider/slider-feel.js +18 -6
- package/dist/slider/slider.css +9 -10
- package/dist/slider/slider.js +13 -10
- package/dist/smooth-caret/caret-controller.js +18 -6
- package/dist/smooth-caret/caret-geometry.js +18 -7
- package/dist/smooth-caret/caret-glide.js +3 -2
- package/dist/smooth-caret/remote-carets.js +20 -3
- package/dist/smooth-caret/smooth-caret.css +1 -1
- package/dist/switch/switch-gesture.d.ts +4 -4
- package/dist/switch/switch-gesture.js +52 -14
- package/dist/switch/switch.css +12 -13
- package/dist/switch/switch.d.ts +2 -1
- package/dist/switch/switch.js +4 -6
- package/dist/table/data-table.js +32 -12
- package/dist/table/table-cells.d.ts +20 -8
- package/dist/table/table-cells.js +18 -20
- package/dist/table/table-model.d.ts +0 -2
- package/dist/table/table-model.js +15 -9
- package/dist/table/table-search.d.ts +12 -0
- package/dist/table/table-search.js +34 -0
- package/dist/table/table-sections.d.ts +3 -2
- package/dist/table/table-sections.js +16 -13
- package/dist/table/table.css +2 -14
- package/dist/table/use-latest.d.ts +6 -0
- package/dist/table/use-latest.js +22 -0
- package/dist/table/use-table-view.js +36 -24
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
2
|
import { type RowContext } from "./table-cells";
|
|
3
3
|
import type { TableColumn } from "./table-types";
|
|
4
4
|
import type { TableView } from "./use-table-view";
|
|
@@ -9,7 +9,8 @@ export declare function Header<Row extends object>({ columns, view, selection }:
|
|
|
9
9
|
selection: boolean;
|
|
10
10
|
}): React.JSX.Element;
|
|
11
11
|
/** The body. It comes from one decision: placeholders, the empty message, no results, or the rows. */
|
|
12
|
-
export declare function Body<Row extends object>({ context, empty }: {
|
|
12
|
+
export declare function Body<Row extends object>({ view, context, empty }: {
|
|
13
|
+
view: TableView<Row>;
|
|
13
14
|
context: RowContext<Row>;
|
|
14
15
|
empty: ReactNode;
|
|
15
16
|
}): React.JSX.Element;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from "react";
|
|
2
3
|
import { Button } from "../button";
|
|
3
4
|
import { Checkbox } from "../checkbox";
|
|
4
5
|
import { EmptyState } from "../empty-state";
|
|
@@ -16,7 +17,7 @@ function ariaSort(rule) {
|
|
|
16
17
|
function HeaderCell({ column, view }) {
|
|
17
18
|
const rule = view.state.sort.find((item) => item.id === column.id);
|
|
18
19
|
const actions = isActionsColumn(column);
|
|
19
|
-
return (_jsxs("th", { role: "columnheader", scope: "col", "aria-sort": ariaSort(rule), "data-align": column.align, "data-priority": column.priority, "data-kind": actions ? "actions" : undefined, style: { inlineSize: column.width }, children: [column.sortable && (_jsxs("button", { type: "button", "data-slot": "table-sort", onClick: () => {
|
|
20
|
+
return (_jsxs("th", { role: "columnheader", scope: "col", "aria-sort": ariaSort(rule), "data-align": column.align, "data-priority": column.priority, "data-kind": actions ? "actions" : undefined, "data-sortable": column.sortable || undefined, style: { inlineSize: column.width }, children: [column.sortable && (_jsxs("button", { type: "button", "data-slot": "table-sort", onClick: () => {
|
|
20
21
|
view.dispatch({ type: "sort", id: column.id });
|
|
21
22
|
}, children: [_jsx("span", { children: column.label }), _jsx(SortIcon, {})] })), !column.sortable && !actions && column.label, actions && _jsx("span", { "data-slot": "table-visually-hidden", children: view.words.actions })] }));
|
|
22
23
|
}
|
|
@@ -38,14 +39,23 @@ export function Header({ columns, view, selection }) {
|
|
|
38
39
|
}
|
|
39
40
|
const skeletonWidths = ["70%", "55%", "85%", "45%", "65%"];
|
|
40
41
|
function SkeletonRows({ columns, view, selection }) {
|
|
41
|
-
return (_jsx(_Fragment, { children: Array.from({ length: view.loadingRows }, (_, index) => (_jsxs("tr", { role: "row", "data-slot": "table-skeleton-row", children: [selection && _jsx("td", { role: "cell", "data-kind": "select" }), columns.map((column, at) => (_jsxs("td", { role: "cell", "data-priority": column.priority, "data-align": column.align,
|
|
42
|
+
return (_jsx(_Fragment, { children: Array.from({ length: view.loadingRows }, (_, index) => (_jsxs("tr", { role: "row", "data-slot": "table-skeleton-row", children: [selection && _jsx("td", { role: "cell", "data-kind": "select" }), columns.map((column, at) => (_jsxs("td", { role: "cell", "data-priority": column.priority, "data-align": column.align, children: [index === 0 && at === 0 && (_jsx("span", { "data-slot": "table-visually-hidden", children: view.words.loading })), !isActionsColumn(column) && (_jsx(Skeleton, { shape: "text", width: skeletonWidths[(index + at) % skeletonWidths.length] }))] }, column.id)))] }, index))) }));
|
|
42
43
|
}
|
|
43
44
|
function MessageRow({ span, children }) {
|
|
44
45
|
return (_jsx("tr", { role: "row", "data-slot": "table-message-row", children: _jsx("td", { role: "cell", colSpan: span, "data-slot": "table-message", children: children }) }));
|
|
45
46
|
}
|
|
47
|
+
function NoResults({ view }) {
|
|
48
|
+
return (_jsx(EmptyState, { size: "inline", kind: "no-results", title: view.words.noResults, description: null, labels: { clear: view.words.clearSearch }, onClear: (event) => {
|
|
49
|
+
// The Clear button goes away with the empty state, so focus moves to the search box.
|
|
50
|
+
const table = event.currentTarget.closest('[data-slot="table"]');
|
|
51
|
+
view.dispatch({ type: "search", text: "" });
|
|
52
|
+
table?.querySelector('[data-slot="table-toolbar"] input')?.focus();
|
|
53
|
+
} }));
|
|
54
|
+
}
|
|
46
55
|
/** The body. It comes from one decision: placeholders, the empty message, no results, or the rows. */
|
|
47
|
-
export function Body({ context, empty }) {
|
|
48
|
-
const {
|
|
56
|
+
export function Body({ view, context, empty }) {
|
|
57
|
+
const { columns, selection } = context;
|
|
58
|
+
const chosen = useMemo(() => new Set(view.state.selected), [view.state.selected]);
|
|
49
59
|
const span = columns.length + (selection ? 1 : 0);
|
|
50
60
|
let content;
|
|
51
61
|
switch (view.body) {
|
|
@@ -56,17 +66,10 @@ export function Body({ context, empty }) {
|
|
|
56
66
|
content = (_jsx(MessageRow, { span: span, children: empty ?? _jsx(EmptyState, { size: "inline", kind: "empty", title: view.words.empty }) }));
|
|
57
67
|
break;
|
|
58
68
|
case "no-results":
|
|
59
|
-
content = (_jsx(MessageRow, { span: span, children: _jsx(
|
|
60
|
-
// The Clear button goes away with the empty state, so focus moves to the search box.
|
|
61
|
-
const table = event.currentTarget.closest('[data-slot="table"]');
|
|
62
|
-
view.dispatch({ type: "search", text: "" });
|
|
63
|
-
table
|
|
64
|
-
?.querySelector('[data-slot="table-toolbar"] input')
|
|
65
|
-
?.focus();
|
|
66
|
-
} }) }));
|
|
69
|
+
content = (_jsx(MessageRow, { span: span, children: _jsx(NoResults, { view: view }) }));
|
|
67
70
|
break;
|
|
68
71
|
case "rows":
|
|
69
|
-
content = view.pageRows.map((item) => (_jsx(BodyRow, { context: context, item: item }, item.id)));
|
|
72
|
+
content = view.pageRows.map((item) => (_jsx(BodyRow, { context: context, row: item.row, id: item.id, name: view.rowName(item.row), selected: chosen.has(item.id) }, item.id)));
|
|
70
73
|
break;
|
|
71
74
|
}
|
|
72
75
|
return _jsx("tbody", { role: "rowgroup", children: content });
|
package/dist/table/table.css
CHANGED
|
@@ -239,7 +239,7 @@
|
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
/* Header buttons: the whole header cell is the target. */
|
|
242
|
-
:where([data-slot="table"] th
|
|
242
|
+
:where([data-slot="table"] th[data-sortable]) {
|
|
243
243
|
padding: 0;
|
|
244
244
|
}
|
|
245
245
|
|
|
@@ -379,7 +379,7 @@
|
|
|
379
379
|
--_row-bg: var(--kumiko-table-row-selected-hover-bg);
|
|
380
380
|
}
|
|
381
381
|
|
|
382
|
-
:where([data-slot="table"] th
|
|
382
|
+
:where([data-slot="table"] th[data-sortable]:hover) {
|
|
383
383
|
color: var(--kumiko-table-fg);
|
|
384
384
|
}
|
|
385
385
|
|
|
@@ -579,10 +579,6 @@
|
|
|
579
579
|
text-align: start;
|
|
580
580
|
}
|
|
581
581
|
|
|
582
|
-
& [data-card-label="off"] > [data-slot="table-cell-label"] {
|
|
583
|
-
display: none;
|
|
584
|
-
}
|
|
585
|
-
|
|
586
582
|
& [data-slot="table-cell-value"] {
|
|
587
583
|
min-inline-size: 0;
|
|
588
584
|
margin-inline-start: auto;
|
|
@@ -736,10 +732,6 @@
|
|
|
736
732
|
text-align: start;
|
|
737
733
|
}
|
|
738
734
|
|
|
739
|
-
& [data-card-label="off"] > [data-slot="table-cell-label"] {
|
|
740
|
-
display: none;
|
|
741
|
-
}
|
|
742
|
-
|
|
743
735
|
& [data-slot="table-cell-value"] {
|
|
744
736
|
min-inline-size: 0;
|
|
745
737
|
margin-inline-start: auto;
|
|
@@ -891,10 +883,6 @@
|
|
|
891
883
|
text-align: start;
|
|
892
884
|
}
|
|
893
885
|
|
|
894
|
-
& [data-card-label="off"] > [data-slot="table-cell-label"] {
|
|
895
|
-
display: none;
|
|
896
|
-
}
|
|
897
|
-
|
|
898
886
|
& [data-slot="table-cell-value"] {
|
|
899
887
|
min-inline-size: 0;
|
|
900
888
|
margin-inline-start: auto;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** A function that never changes identity and always calls the latest `fn`, so memoised children needn't re-render. */
|
|
2
|
+
export declare function useLatestCallback<Args extends unknown[], Result>(fn: (...args: Args) => Result): (...args: Args) => Result;
|
|
3
|
+
/** Whether two objects hold the same entries. */
|
|
4
|
+
export declare function sameEntries(first: object, second: object): boolean;
|
|
5
|
+
/** The first value of this shape: a later one with the same entries gives back the first, so it can sit in a dependency list. */
|
|
6
|
+
export declare function useShallowStable<Value extends object>(value: Value): Value;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useCallback, useRef } from "react";
|
|
2
|
+
/** A function that never changes identity and always calls the latest `fn`, so memoised children needn't re-render. */
|
|
3
|
+
export function useLatestCallback(fn) {
|
|
4
|
+
const latest = useRef(fn);
|
|
5
|
+
latest.current = fn;
|
|
6
|
+
return useCallback((...args) => latest.current(...args), []);
|
|
7
|
+
}
|
|
8
|
+
/** Whether two objects hold the same entries. */
|
|
9
|
+
export function sameEntries(first, second) {
|
|
10
|
+
const before = Object.entries(first);
|
|
11
|
+
const after = Object.entries(second);
|
|
12
|
+
return (before.length === after.length &&
|
|
13
|
+
after.every(([key, entry]) => Object.is(Reflect.get(first, key), entry)));
|
|
14
|
+
}
|
|
15
|
+
/** The first value of this shape: a later one with the same entries gives back the first, so it can sit in a dependency list. */
|
|
16
|
+
export function useShallowStable(value) {
|
|
17
|
+
const held = useRef(value);
|
|
18
|
+
if (held.current !== value && !sameEntries(held.current, value)) {
|
|
19
|
+
held.current = value;
|
|
20
|
+
}
|
|
21
|
+
return held.current;
|
|
22
|
+
}
|
|
@@ -4,6 +4,7 @@ import { isActionsColumn } from "./table-columns";
|
|
|
4
4
|
import { tableLabels } from "./table-labels";
|
|
5
5
|
import { useTableModel } from "./table-model";
|
|
6
6
|
import { bodyOf, changeOf, nextState, pageSelection, shownPage } from "./table-state";
|
|
7
|
+
import { useLatestCallback, useShallowStable } from "./use-latest";
|
|
7
8
|
function defaultRowId(row) {
|
|
8
9
|
if ("id" in row && (typeof row.id === "string" || typeof row.id === "number")) {
|
|
9
10
|
return String(row.id);
|
|
@@ -91,48 +92,59 @@ function usePaged(props, state, rowId) {
|
|
|
91
92
|
const size = paging ? state.pageSize : Number.POSITIVE_INFINITY;
|
|
92
93
|
const pageCount = paging ? Math.max(1, Math.ceil(total / size)) : 1;
|
|
93
94
|
const page = shownPage(state.page, pageCount);
|
|
94
|
-
const
|
|
95
|
-
const pageRows =
|
|
95
|
+
const whole = serverSide !== undefined || !paging;
|
|
96
|
+
const pageRows = useMemo(() => {
|
|
97
|
+
const slice = whole ? rows : rows.slice((page - 1) * size, page * size);
|
|
98
|
+
return slice.map((row) => ({ id: row.id, row: row.original }));
|
|
99
|
+
}, [rows, whole, page, size]);
|
|
96
100
|
return { paging, total, pageCount, page, pageRows };
|
|
97
101
|
}
|
|
98
102
|
/** The selected rows: with the whole list known, only ids still in it; with `serverSide`, those on this page. */
|
|
99
|
-
function
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
return {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
103
|
+
function useSelected(props, state, pageRows, rowId) {
|
|
104
|
+
const { data } = props;
|
|
105
|
+
const serverSide = props.serverSide !== undefined;
|
|
106
|
+
const { selected } = state;
|
|
107
|
+
return useMemo(() => {
|
|
108
|
+
const chosen = new Set(selected);
|
|
109
|
+
const known = serverSide ? pageRows.map((item) => item.row) : data;
|
|
110
|
+
const selectedRows = known.filter((row) => chosen.has(rowId(row)));
|
|
111
|
+
return {
|
|
112
|
+
selectedRows,
|
|
113
|
+
selectedCount: serverSide ? selected.length : selectedRows.length,
|
|
114
|
+
pageSelected: pageSelection(selected, pageRows.map((item) => item.id))
|
|
115
|
+
};
|
|
116
|
+
}, [data, serverSide, selected, pageRows, rowId]);
|
|
108
117
|
}
|
|
109
118
|
/** Works out what the table shows: the page's rows, the counts, the selection and the body. */
|
|
110
119
|
export function useTableView(props) {
|
|
111
|
-
const words = { ...tableLabels, ...props.labels };
|
|
120
|
+
const words = useShallowStable({ ...tableLabels, ...props.labels });
|
|
112
121
|
const format = useFormat(props.locale);
|
|
113
122
|
const { state, dispatch } = useTableState(props);
|
|
114
|
-
const rowId = props.rowId ?? defaultRowId;
|
|
115
|
-
const dataColumns = props.columns.filter((column) => !isActionsColumn(column));
|
|
123
|
+
const rowId = useLatestCallback(props.rowId ?? defaultRowId);
|
|
124
|
+
const dataColumns = useMemo(() => props.columns.filter((column) => !isActionsColumn(column)), [props.columns]);
|
|
116
125
|
const paged = usePaged(props, state, rowId);
|
|
117
126
|
const linkColumnId = props.rowLink || props.onRowPress ? (props.rowLinkColumn ?? dataColumns[0]?.id) : undefined;
|
|
118
127
|
const nameColumn = dataColumns.find((column) => column.id === linkColumnId) ?? dataColumns[0];
|
|
119
128
|
useSearchAnnouncement(state.search, paged.total, (count) => {
|
|
120
129
|
announce(words.results(format(count)));
|
|
121
130
|
});
|
|
131
|
+
const stableDispatch = useLatestCallback((event) => {
|
|
132
|
+
const next = dispatch(event);
|
|
133
|
+
const rule = event.type === "sort" ? next.sort[0] : undefined;
|
|
134
|
+
const sorted = dataColumns.find((column) => column.id === rule?.id);
|
|
135
|
+
if (rule && sorted) {
|
|
136
|
+
announce(words.sorted(sorted.label, rule.desc, format(paged.total)));
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
const rowName = useLatestCallback((row) => props.rowName?.(row) ?? nameColumn?.text(row) ?? rowId(row));
|
|
140
|
+
const selected = useSelected(props, state, paged.pageRows, rowId);
|
|
122
141
|
return {
|
|
123
142
|
...paged,
|
|
124
|
-
...
|
|
143
|
+
...selected,
|
|
125
144
|
words,
|
|
126
145
|
format,
|
|
127
146
|
state,
|
|
128
|
-
dispatch:
|
|
129
|
-
const next = dispatch(event);
|
|
130
|
-
const rule = event.type === "sort" ? next.sort[0] : undefined;
|
|
131
|
-
const sorted = dataColumns.find((column) => column.id === rule?.id);
|
|
132
|
-
if (rule && sorted) {
|
|
133
|
-
announce(words.sorted(sorted.label, rule.desc, format(paged.total)));
|
|
134
|
-
}
|
|
135
|
-
},
|
|
147
|
+
dispatch: stableDispatch,
|
|
136
148
|
dataColumns,
|
|
137
149
|
body: bodyOf({
|
|
138
150
|
loading: Boolean(props.loading),
|
|
@@ -140,7 +152,7 @@ export function useTableView(props) {
|
|
|
140
152
|
searching: state.search.trim() !== "",
|
|
141
153
|
shown: paged.pageRows.length
|
|
142
154
|
}),
|
|
143
|
-
rowName
|
|
155
|
+
rowName,
|
|
144
156
|
linkColumnId,
|
|
145
157
|
loadingRows: loadingRowsOf(props.loading)
|
|
146
158
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alulore/kumiko",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Polished, cozy React components with gentle motion, built on ui-sdk. Every look and behaviour can be switched with props and CSS tokens.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|