@alulore/kumiko 0.20.2 → 0.21.1
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/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/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 +37 -11
- 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 +4 -2
- package/dist/smooth-caret/top-layer.d.ts +2 -0
- package/dist/smooth-caret/top-layer.js +6 -0
- 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
|
@@ -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.1",
|
|
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": {
|