@crewlethq/ui 0.100.2 → 0.102.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/AgentHandoffPanel/index.js +6 -6
- package/dist/AppShell/index.js +3 -3
- package/dist/ArrangeList/index.js +1 -1
- package/dist/ArtifactBar/index.js +1 -1
- package/dist/ArtifactCard/index.js +2 -2
- package/dist/AuthLayout/index.js +1 -1
- package/dist/AvatarPicker/index.js +3 -3
- package/dist/BriefCard/index.js +1 -1
- package/dist/CharacterPicker/index.js +2 -2
- package/dist/Combobox/index.js +2 -2
- package/dist/CommandPalette/index.js +4 -4
- package/dist/CommentThread/index.js +6 -6
- package/dist/Composer/index.js +2 -2
- package/dist/DataGrid/DataGrid.d.ts +145 -41
- package/dist/DataGrid/index.d.ts +2 -2
- package/dist/DataGrid/index.js +7 -5
- package/dist/DataGrid/parts.d.ts +163 -0
- package/dist/{DataGrid-SAHEL4SN.css → DataGrid-YNLCEH3E.css} +228 -19
- package/dist/DataTable/index.js +4 -4
- package/dist/DataView/index.js +6 -6
- package/dist/DatasetSource/index.js +1 -1
- package/dist/DeepWorkCard/index.js +1 -1
- package/dist/DocTabsEditor/index.js +4 -4
- package/dist/EditingStatus/index.js +2 -2
- package/dist/EntityList/index.js +1 -1
- package/dist/InlineEditor/index.js +3 -3
- package/dist/KeyValueRows/index.js +3 -3
- package/dist/ListInput/index.js +4 -4
- package/dist/OpenInAppCard/index.js +1 -1
- package/dist/OrgTable/OrgTable.d.ts +5 -20
- package/dist/OrgTable/index.js +10 -3
- package/dist/{OrgTable-XYHEFI5X.css → OrgTable-5NXRECVP.css} +29 -9
- package/dist/PeekRail/index.js +2 -2
- package/dist/PrincipalPicker/index.js +3 -3
- package/dist/ProposalCard/index.js +3 -3
- package/dist/RailList/index.js +3 -2
- package/dist/RefusalCard/index.js +1 -1
- package/dist/RelatedRow/index.js +3 -2
- package/dist/ResultTableCard/index.js +1 -1
- package/dist/RichEditor/index.js +1 -1
- package/dist/SetupWizard/index.js +1 -1
- package/dist/ShareDialog/index.js +2 -2
- package/dist/SheetColumnEditor/index.js +5 -5
- package/dist/SheetGrid/index.js +3 -3
- package/dist/SlideFilmstrip/index.js +2 -2
- package/dist/StatusCard/index.js +1 -1
- package/dist/Switcher/index.js +4 -4
- package/dist/TableCells/TableCells.d.ts +10 -2
- package/dist/TableCells/index.js +4 -3
- package/dist/Text/index.js +2 -1
- package/dist/ThreadSummary/index.js +1 -1
- package/dist/TimeRangePicker/index.js +4 -4
- package/dist/TimeWindowPicker/index.js +4 -4
- package/dist/TreeGrid/TreeGrid.d.ts +143 -12
- package/dist/TreeGrid/index.d.ts +1 -1
- package/dist/TreeGrid/index.js +15 -2
- package/dist/{TreeGrid-H3GHMKZX.css → TreeGrid-XZCH5WCC.css} +232 -2
- package/dist/ValueField/index.js +3 -3
- package/dist/{chunk-G44KKOMB.js → chunk-2LLMUJFB.js} +1 -1
- package/dist/{chunk-BK4KUIAZ.js → chunk-AP6JSZGT.js} +12 -4
- package/dist/chunk-BZUBONYA.js +557 -0
- package/dist/{chunk-PCXMJZTE.js → chunk-DBH7ORCH.js} +1 -1
- package/dist/{chunk-MKTHLT4E.js → chunk-EMXUREKE.js} +1 -1
- package/dist/{chunk-CL3FWLDO.js → chunk-HI47TXSW.js} +1 -1
- package/dist/{chunk-PXYDEDNN.js → chunk-J3QFTG4B.js} +1 -1
- package/dist/{chunk-G6QKJGQQ.js → chunk-L72GPZ56.js} +1 -1
- package/dist/{chunk-HYVYYODN.js → chunk-M6EVTMTK.js} +1 -1
- package/dist/chunk-MO5YV3XV.js +899 -0
- package/dist/{chunk-XQWWA2LG.js → chunk-PAJAGGSE.js} +19 -51
- package/dist/{chunk-NHQ7O4DG.js → chunk-PF6X74C5.js} +3 -3
- package/dist/{chunk-SBVTOIFP.js → chunk-PMO6W5NE.js} +2 -2
- package/dist/chunk-WSIJDWUG.js +10 -0
- package/dist/{chunk-O5CEG7TQ.js → chunk-XLMURU75.js} +1 -6
- package/dist/{chunk-V3QWPHY4.js → chunk-XRKBPNX4.js} +1 -1
- package/dist/generated/index.js +77 -77
- package/dist/index.js +77 -77
- package/dist/styles.css +492 -33
- package/dist/utils/titleIfCut.d.ts +18 -0
- package/package.json +3 -3
- package/dist/chunk-CCNAGB3F.js +0 -591
- package/dist/chunk-CTQZK5J3.js +0 -8
- package/dist/chunk-ERESJG6C.js +0 -353
- package/dist/{Editor-XRI2NOO5.js → Editor-YHHCK5SJ.js} +2 -2
- package/dist/{chunk-NRMF2PKX.js → chunk-3Z2BSKS5.js} +1 -1
- package/dist/{chunk-6IAW2ZIE.js → chunk-5KJOG5YP.js} +2 -2
- package/dist/{chunk-HBHKMFAH.js → chunk-7L6JJ7VJ.js} +1 -1
- package/dist/{chunk-HEXH3HQJ.js → chunk-A5ISYHW7.js} +2 -2
- package/dist/{chunk-CRRW4UGJ.js → chunk-AC255TMQ.js} +1 -1
- package/dist/{chunk-YPXXDYTR.js → chunk-AP6SM6BL.js} +1 -1
- package/dist/{chunk-QCCWXOKK.js → chunk-DK7CXQFY.js} +1 -1
- package/dist/{chunk-GCKHZMWG.js → chunk-E23AXDKL.js} +1 -1
- package/dist/{chunk-V6CVW6PF.js → chunk-GA773IOZ.js} +1 -1
- package/dist/{chunk-TXQ6FZJL.js → chunk-HU5PAZMU.js} +1 -1
- package/dist/{chunk-CTHZHMVG.js → chunk-IA3NL54W.js} +1 -1
- package/dist/{chunk-3JE6YIG5.js → chunk-JZADK2FT.js} +2 -2
- package/dist/{chunk-S4JRQJEP.js → chunk-LNQSNXGJ.js} +1 -1
- package/dist/{chunk-HR5O6PSR.js → chunk-MTKHMGJH.js} +1 -1
- package/dist/{chunk-NIZRR2NN.js → chunk-OAKECTYH.js} +1 -1
- package/dist/{chunk-I2GJLUU3.js → chunk-OU6ZSWEJ.js} +1 -1
- package/dist/{chunk-LNXL22Y7.js → chunk-RSI6EJSH.js} +1 -1
- package/dist/{chunk-BGRYFVSK.js → chunk-XHQ2JJCB.js} +1 -1
- package/dist/{chunk-CQAR3F33.js → chunk-XLVWSNW3.js} +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Puts the element's whole words on its title while they are cut, and takes
|
|
3
|
+
* the title off while they fit. One line is cut across (`inline`), a clamp
|
|
4
|
+
* down (`block`). The words are read from the element itself, so a run of
|
|
5
|
+
* marked-up text (a mono id inside the line) reads as it is shown, with its
|
|
6
|
+
* white space collapsed as the line collapses it.
|
|
7
|
+
*
|
|
8
|
+
* MEASURED WHEN THE POINTER ARRIVES, the only moment a title is read, so it
|
|
9
|
+
* never goes stale after a resize or a new value, and a table of a thousand
|
|
10
|
+
* cut cells costs nothing until one is hovered. One helper for every element
|
|
11
|
+
* the kit cuts with an ellipsis (`Text`, the table cells, a grid's heads), so
|
|
12
|
+
* no cut is drawn without its words on hover.
|
|
13
|
+
*/
|
|
14
|
+
export declare function titleIfCut(element: HTMLElement, axis?: 'inline' | 'block'): void;
|
|
15
|
+
/** `onMouseEnter` for a one-line cut: see [titleIfCut]. */
|
|
16
|
+
export declare const titleWhenCut: (event: {
|
|
17
|
+
currentTarget: HTMLElement;
|
|
18
|
+
}) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crewlethq/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.102.0",
|
|
4
4
|
"description": "Crewlet shared React components built on @crewlethq/tokens and @crewlethq/icons.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"clean": "rm -rf dist src/generated"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@crewlethq/icons": "0.
|
|
46
|
-
"@crewlethq/tokens": "0.
|
|
45
|
+
"@crewlethq/icons": "0.102.0",
|
|
46
|
+
"@crewlethq/tokens": "0.102.0",
|
|
47
47
|
"prosemirror-commands": "1.7.2",
|
|
48
48
|
"prosemirror-gapcursor": "1.4.1",
|
|
49
49
|
"prosemirror-history": "1.5.1",
|
package/dist/chunk-CCNAGB3F.js
DELETED
|
@@ -1,591 +0,0 @@
|
|
|
1
|
-
import { tableTrack, SHRINK_SHARE } from './chunk-CTQZK5J3.js';
|
|
2
|
-
import { useMediaMatch } from './chunk-YJQXESOJ.js';
|
|
3
|
-
import { Checkbox } from './chunk-M6G7XLLP.js';
|
|
4
|
-
import { EmptyState } from './chunk-PPUR46MK.js';
|
|
5
|
-
import { Button } from './chunk-6KUOHUY5.js';
|
|
6
|
-
import { VisuallyHidden } from './chunk-UT6CW3C7.js';
|
|
7
|
-
import { cx } from './chunk-ODEQTPFM.js';
|
|
8
|
-
import './DataGrid-SAHEL4SN.css';
|
|
9
|
-
import { useId, useRef, useState, useMemo, useCallback, useLayoutEffect, useImperativeHandle, useSyncExternalStore, useEffect } from 'react';
|
|
10
|
-
import { breakpoint } from '@crewlethq/tokens';
|
|
11
|
-
import { ArrowDownGlyph, ArrowUpGlyph, ArrowUpDownGlyph } from '@crewlethq/icons/glyphs';
|
|
12
|
-
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
13
|
-
|
|
14
|
-
var DATA_GRID_ICON_TRACK = "calc(var(--size-target-min) + var(--spacing-3) * 2)";
|
|
15
|
-
function alignOf(column) {
|
|
16
|
-
return column.align ?? (column.icon ? "center" : "left");
|
|
17
|
-
}
|
|
18
|
-
function columnChoicesOf(columns) {
|
|
19
|
-
return columns.map((column) => ({
|
|
20
|
-
key: column.key,
|
|
21
|
-
label: headerWord(column) || column.label || column.key,
|
|
22
|
-
optional: column.optional
|
|
23
|
-
}));
|
|
24
|
-
}
|
|
25
|
-
function ChooserList({ label, items, onToggle }) {
|
|
26
|
-
const headingId = useId();
|
|
27
|
-
if (items.length === 0) return null;
|
|
28
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
29
|
-
/* @__PURE__ */ jsx("div", { className: "crewlet-column-chooser__label", id: headingId, children: label }),
|
|
30
|
-
/* @__PURE__ */ jsx("div", { className: "crewlet-column-chooser__choices", role: "group", "aria-labelledby": headingId, children: items.map((item) => /* @__PURE__ */ jsxs("label", { className: "crewlet-column-chooser__choice", children: [
|
|
31
|
-
/* @__PURE__ */ jsx("input", { type: "checkbox", checked: item.checked, onChange: () => onToggle(item.key) }),
|
|
32
|
-
/* @__PURE__ */ jsx("span", { children: item.label })
|
|
33
|
-
] }, item.key)) })
|
|
34
|
-
] });
|
|
35
|
-
}
|
|
36
|
-
function ColumnChooser({ choices, value, onChange, label = "Columns" }) {
|
|
37
|
-
const chosen = new Set(value ? value.split(",").filter(Boolean) : []);
|
|
38
|
-
const isOn = (choice) => chosen.size === 0 ? !choice.optional : chosen.has(choice.key);
|
|
39
|
-
return /* @__PURE__ */ jsx(
|
|
40
|
-
ChooserList,
|
|
41
|
-
{
|
|
42
|
-
label,
|
|
43
|
-
items: choices.map((choice) => ({ key: choice.key, label: choice.label, checked: isOn(choice) })),
|
|
44
|
-
onToggle: (key) => {
|
|
45
|
-
const next = new Set(choices.filter(isOn).map((c) => c.key));
|
|
46
|
-
if (next.has(key)) next.delete(key);
|
|
47
|
-
else next.add(key);
|
|
48
|
-
onChange(
|
|
49
|
-
choices.filter((c) => next.has(c.key)).map((c) => c.key).join(",")
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
var LABELS = {
|
|
56
|
-
hiddenToFit: (names) => `Hidden to fit: ${names}`,
|
|
57
|
-
loadMore: "Load more",
|
|
58
|
-
showEveryColumn: "Show every column",
|
|
59
|
-
and: "and",
|
|
60
|
-
selectAll: "Select every row"
|
|
61
|
-
};
|
|
62
|
-
var SELECT_COLUMN = "crewlet-select";
|
|
63
|
-
function parseGridSort(raw) {
|
|
64
|
-
if (!raw) return null;
|
|
65
|
-
return raw.startsWith("-") ? { key: raw.slice(1), desc: true } : { key: raw, desc: false };
|
|
66
|
-
}
|
|
67
|
-
function nextGridSort(column, sort, defaultSort = "") {
|
|
68
|
-
const chosen = sort === defaultSort ? "" : sort;
|
|
69
|
-
const current2 = parseGridSort(chosen || defaultSort);
|
|
70
|
-
let next;
|
|
71
|
-
if (current2?.key !== column) next = column;
|
|
72
|
-
else if (!current2.desc) next = `-${column}`;
|
|
73
|
-
else next = chosen ? "" : column;
|
|
74
|
-
return next === defaultSort ? "" : next;
|
|
75
|
-
}
|
|
76
|
-
function headerWord(column) {
|
|
77
|
-
return typeof column.header === "string" ? column.header : "";
|
|
78
|
-
}
|
|
79
|
-
function bandRows(band) {
|
|
80
|
-
return band.bands ? band.bands.flatMap(bandRows) : band.rows;
|
|
81
|
-
}
|
|
82
|
-
function compare(a, b) {
|
|
83
|
-
if (typeof a === "number" && typeof b === "number") {
|
|
84
|
-
if (Number.isNaN(a)) return Number.isNaN(b) ? 0 : 1;
|
|
85
|
-
if (Number.isNaN(b)) return -1;
|
|
86
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
87
|
-
}
|
|
88
|
-
return String(a).localeCompare(String(b), void 0, { numeric: true, sensitivity: "base" });
|
|
89
|
-
}
|
|
90
|
-
var SQUEEZE_SAMPLE_ROWS = 12;
|
|
91
|
-
var NO_DROPS = [];
|
|
92
|
-
var NO_FIT = { set: "", width: 0, dropped: NO_DROPS };
|
|
93
|
-
function fitGridColumns({
|
|
94
|
-
fit,
|
|
95
|
-
width,
|
|
96
|
-
overflows,
|
|
97
|
-
stack = false,
|
|
98
|
-
visible
|
|
99
|
-
}) {
|
|
100
|
-
if ((fit.dropped.length > 0 || fit.stacked) && width > fit.width) {
|
|
101
|
-
return { set: fit.set, width, dropped: NO_DROPS };
|
|
102
|
-
}
|
|
103
|
-
if (fit.stacked) return null;
|
|
104
|
-
if (overflows || stack) {
|
|
105
|
-
let next;
|
|
106
|
-
for (const c of visible) {
|
|
107
|
-
if (c.drop === void 0) continue;
|
|
108
|
-
if (!next || c.drop < next.drop) next = c;
|
|
109
|
-
}
|
|
110
|
-
if (next) return { set: fit.set, width, dropped: [...fit.dropped, next.key] };
|
|
111
|
-
if (stack) return { set: fit.set, width, dropped: fit.dropped, stacked: true };
|
|
112
|
-
}
|
|
113
|
-
if (width !== fit.width && (fit.dropped.length > 0 || fit.width === 0)) {
|
|
114
|
-
return { ...fit, width };
|
|
115
|
-
}
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
function overflowing(wrap) {
|
|
119
|
-
const last = wrap.querySelector(":scope > .crewlet-data-grid__head")?.lastElementChild;
|
|
120
|
-
if (!last) return false;
|
|
121
|
-
const inner = wrap.getBoundingClientRect().left + wrap.clientLeft + wrap.clientWidth;
|
|
122
|
-
return last.getBoundingClientRect().right > inner + 0.5;
|
|
123
|
-
}
|
|
124
|
-
function squeezed(wrap, visible, leading = 0) {
|
|
125
|
-
const heads = wrap.querySelector(":scope > .crewlet-data-grid__head")?.children;
|
|
126
|
-
if (!heads) return null;
|
|
127
|
-
const cap = wrap.clientWidth * SHRINK_SHARE - 1;
|
|
128
|
-
const rows = [...wrap.querySelectorAll(":scope > .crewlet-data-grid__body .crewlet-data-grid__row")].slice(
|
|
129
|
-
0,
|
|
130
|
-
SQUEEZE_SAMPLE_ROWS
|
|
131
|
-
);
|
|
132
|
-
let headCut = false;
|
|
133
|
-
for (let i = 0; i < visible.length; i++) {
|
|
134
|
-
const column = visible[i];
|
|
135
|
-
if (!column.shrink || column.width || column.icon) continue;
|
|
136
|
-
const head = heads[i + leading];
|
|
137
|
-
if (!head || head.getBoundingClientRect().width >= cap) continue;
|
|
138
|
-
if (cutShort(head)) headCut = true;
|
|
139
|
-
for (const row of rows) {
|
|
140
|
-
const cell = row.querySelectorAll(":scope > .crewlet-data-grid__cell")[i + leading];
|
|
141
|
-
if (cell && cutShort(cell)) return "values";
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return headCut ? "heads" : null;
|
|
145
|
-
}
|
|
146
|
-
function cutShort(el) {
|
|
147
|
-
for (const node of [el, ...el.querySelectorAll("*")]) {
|
|
148
|
-
const box = node;
|
|
149
|
-
if (box.clientWidth > 1 && box.scrollWidth > box.clientWidth + 1) return true;
|
|
150
|
-
}
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
function droppedNames(columns, dropped, and) {
|
|
154
|
-
const names = dropped.map((key) => {
|
|
155
|
-
const c = columns.find((col) => col.key === key);
|
|
156
|
-
return c && (headerWord(c) || c.label) || key;
|
|
157
|
-
});
|
|
158
|
-
return names.length <= 1 ? names[0] ?? "" : `${names.slice(0, -1).join(", ")} ${and} ${names[names.length - 1]}`;
|
|
159
|
-
}
|
|
160
|
-
function DataGrid({
|
|
161
|
-
rows,
|
|
162
|
-
bands,
|
|
163
|
-
columns,
|
|
164
|
-
rowKey,
|
|
165
|
-
onRowActivate,
|
|
166
|
-
rowHref,
|
|
167
|
-
isSelected,
|
|
168
|
-
selection,
|
|
169
|
-
isFailed,
|
|
170
|
-
sort: sortRaw = "",
|
|
171
|
-
defaultSort = "",
|
|
172
|
-
onSortChange,
|
|
173
|
-
serverSorted = false,
|
|
174
|
-
cols: colsRaw = "",
|
|
175
|
-
onColsChange,
|
|
176
|
-
empty,
|
|
177
|
-
footer,
|
|
178
|
-
onLoadMore,
|
|
179
|
-
loadedNote,
|
|
180
|
-
phoneRows = "labelled",
|
|
181
|
-
flush = false,
|
|
182
|
-
handleRef,
|
|
183
|
-
onPointerDown,
|
|
184
|
-
labels,
|
|
185
|
-
"aria-label": ariaLabel,
|
|
186
|
-
"aria-labelledby": ariaLabelledby,
|
|
187
|
-
className
|
|
188
|
-
}) {
|
|
189
|
-
const text = { ...LABELS, ...labels };
|
|
190
|
-
const sort = parseGridSort(sortRaw || defaultSort);
|
|
191
|
-
const body = useRef(null);
|
|
192
|
-
const [cursor, setCursor] = useState(-1);
|
|
193
|
-
const gridId = useId();
|
|
194
|
-
const shownColumns = useMemo(() => {
|
|
195
|
-
const asked = colsRaw.split(",").map((c) => c.trim()).filter(Boolean);
|
|
196
|
-
if (asked.length === 0) return columns.filter((c) => !c.optional);
|
|
197
|
-
const byKey = new Map(columns.map((c) => [c.key, c]));
|
|
198
|
-
const picked = asked.map((key) => byKey.get(key)).filter((c) => !!c);
|
|
199
|
-
return picked.length > 0 ? picked : columns.filter((c) => !c.optional);
|
|
200
|
-
}, [columns, colsRaw]);
|
|
201
|
-
const [wrap, setWrap] = useState(null);
|
|
202
|
-
const phone = useMediaMatch(`(width < ${breakpoint.phone})`);
|
|
203
|
-
const shownKeys = shownColumns.map((c) => c.key).join(",");
|
|
204
|
-
const [fit, setFit] = useState(NO_FIT);
|
|
205
|
-
const stacked = phone || fit.set === shownKeys && Boolean(fit.stacked);
|
|
206
|
-
const dropped = !stacked && fit.set === shownKeys ? fit.dropped : NO_DROPS;
|
|
207
|
-
const visibleColumns = useMemo(
|
|
208
|
-
() => dropped.length === 0 ? shownColumns : shownColumns.filter((c) => !dropped.includes(c.key)),
|
|
209
|
-
[shownColumns, dropped]
|
|
210
|
-
);
|
|
211
|
-
const sortRows = useCallback(
|
|
212
|
-
(input) => {
|
|
213
|
-
if (!sort || serverSorted) return input;
|
|
214
|
-
const column = columns.find((c) => c.key === sort.key);
|
|
215
|
-
if (!column?.sortValue) return input;
|
|
216
|
-
const get = column.sortValue;
|
|
217
|
-
return [...input].sort((a, b) => {
|
|
218
|
-
const av = get(a);
|
|
219
|
-
const bv = get(b);
|
|
220
|
-
if (av == null && bv == null) return 0;
|
|
221
|
-
if (av == null) return 1;
|
|
222
|
-
if (bv == null) return -1;
|
|
223
|
-
const cmp = compare(av, bv);
|
|
224
|
-
return sort.desc ? -cmp : cmp;
|
|
225
|
-
});
|
|
226
|
-
},
|
|
227
|
-
[columns, sort, serverSorted]
|
|
228
|
-
);
|
|
229
|
-
const flat = useMemo(() => {
|
|
230
|
-
const walk = (band) => band.bands ? band.bands.flatMap(walk) : sortRows(band.rows);
|
|
231
|
-
if (bands) return bands.flatMap(walk);
|
|
232
|
-
return sortRows(rows ?? []);
|
|
233
|
-
}, [bands, rows, sortRows]);
|
|
234
|
-
const anchor = useRef(null);
|
|
235
|
-
const pickable = useMemo(
|
|
236
|
-
() => selection ? flat.filter((row) => selection.isSelectable?.(row) ?? true) : [],
|
|
237
|
-
[flat, selection]
|
|
238
|
-
);
|
|
239
|
-
const pickedCount = selection ? pickable.filter((row) => selection.selected.has(rowKey(row))).length : 0;
|
|
240
|
-
const allPicked = pickable.length > 0 && pickedCount === pickable.length;
|
|
241
|
-
const pick = (row, on, range) => {
|
|
242
|
-
if (!selection) return;
|
|
243
|
-
const key = rowKey(row);
|
|
244
|
-
const next = new Set(selection.selected);
|
|
245
|
-
const to = flat.findIndex((r) => rowKey(r) === key);
|
|
246
|
-
const from = range && anchor.current !== null ? flat.findIndex((r) => rowKey(r) === anchor.current) : -1;
|
|
247
|
-
const span = from >= 0 && to >= 0 ? flat.slice(Math.min(from, to), Math.max(from, to) + 1) : [row];
|
|
248
|
-
for (const r of span) {
|
|
249
|
-
if (selection.isSelectable?.(r) === false) continue;
|
|
250
|
-
if (on) next.add(rowKey(r));
|
|
251
|
-
else next.delete(rowKey(r));
|
|
252
|
-
}
|
|
253
|
-
anchor.current = key;
|
|
254
|
-
selection.onChange(next);
|
|
255
|
-
};
|
|
256
|
-
const pickAll = () => {
|
|
257
|
-
if (!selection) return;
|
|
258
|
-
const next = new Set(selection.selected);
|
|
259
|
-
for (const row of pickable) {
|
|
260
|
-
if (allPicked) next.delete(rowKey(row));
|
|
261
|
-
else next.add(rowKey(row));
|
|
262
|
-
}
|
|
263
|
-
anchor.current = null;
|
|
264
|
-
selection.onChange(next);
|
|
265
|
-
};
|
|
266
|
-
const selectColumn = selection ? {
|
|
267
|
-
key: SELECT_COLUMN,
|
|
268
|
-
header: /* @__PURE__ */ jsx(
|
|
269
|
-
Checkbox,
|
|
270
|
-
{
|
|
271
|
-
hideLabel: true,
|
|
272
|
-
label: text.selectAll,
|
|
273
|
-
checked: allPicked,
|
|
274
|
-
indeterminate: pickedCount > 0 && !allPicked,
|
|
275
|
-
disabled: pickable.length === 0,
|
|
276
|
-
onChange: pickAll
|
|
277
|
-
}
|
|
278
|
-
),
|
|
279
|
-
cell: (row) => (
|
|
280
|
-
// ABOVE THE ROW'S LINK, so the press lands on the box.
|
|
281
|
-
/* @__PURE__ */ jsx("span", { className: "crewlet-data-grid__select", "data-above-row": true, children: /* @__PURE__ */ jsx(
|
|
282
|
-
Checkbox,
|
|
283
|
-
{
|
|
284
|
-
hideLabel: true,
|
|
285
|
-
label: selection.rowLabel(row),
|
|
286
|
-
checked: selection.selected.has(rowKey(row)),
|
|
287
|
-
disabled: selection.isSelectable?.(row) === false,
|
|
288
|
-
onChange: (event) => pick(row, event.target.checked, event.nativeEvent.shiftKey === true)
|
|
289
|
-
}
|
|
290
|
-
) })
|
|
291
|
-
),
|
|
292
|
-
action: true,
|
|
293
|
-
phoneLead: true,
|
|
294
|
-
width: DATA_GRID_ICON_TRACK
|
|
295
|
-
} : null;
|
|
296
|
-
const drawnColumns = selectColumn ? [selectColumn, ...visibleColumns] : visibleColumns;
|
|
297
|
-
const leading = drawnColumns.length - visibleColumns.length;
|
|
298
|
-
const [boxWidth, setBoxWidth] = useState(0);
|
|
299
|
-
useLayoutEffect(() => {
|
|
300
|
-
if (!wrap || typeof ResizeObserver !== "function") return;
|
|
301
|
-
const watch2 = new ResizeObserver(() => setBoxWidth(wrap.clientWidth));
|
|
302
|
-
watch2.observe(wrap);
|
|
303
|
-
return () => watch2.disconnect();
|
|
304
|
-
}, [wrap]);
|
|
305
|
-
useLayoutEffect(() => {
|
|
306
|
-
const el = wrap;
|
|
307
|
-
if (!el || phone) return;
|
|
308
|
-
const current2 = fit.set === shownKeys ? fit : { ...NO_FIT, set: shownKeys };
|
|
309
|
-
const overrun = !current2.stacked && overflowing(el);
|
|
310
|
-
const squeeze = current2.stacked ? null : squeezed(el, visibleColumns, leading);
|
|
311
|
-
const next = fitGridColumns({
|
|
312
|
-
fit: current2,
|
|
313
|
-
width: el.clientWidth,
|
|
314
|
-
overflows: overrun || squeeze !== null,
|
|
315
|
-
stack: overrun || squeeze === "values",
|
|
316
|
-
visible: visibleColumns
|
|
317
|
-
});
|
|
318
|
-
if (next !== null) setFit(next);
|
|
319
|
-
}, [wrap, phone, fit, shownKeys, visibleColumns, leading, flat, boxWidth]);
|
|
320
|
-
useImperativeHandle(
|
|
321
|
-
handleRef,
|
|
322
|
-
() => ({
|
|
323
|
-
step: (by) => setCursor((at) => {
|
|
324
|
-
const next = Math.max(0, Math.min(flat.length - 1, at + by));
|
|
325
|
-
body.current?.querySelector(`[data-row-index="${next}"]`)?.scrollIntoView({ block: "nearest" });
|
|
326
|
-
return next;
|
|
327
|
-
}),
|
|
328
|
-
// THE ROW'S OWN WAY IN, from the keyboard: its handler where it has
|
|
329
|
-
// one, else its link, followed as a click on it would be (with the
|
|
330
|
-
// keys held, so a modified Enter opens it elsewhere as a modified
|
|
331
|
-
// click does). A grid of links only had no Enter at all.
|
|
332
|
-
activate: (event) => {
|
|
333
|
-
const row = flat[cursor];
|
|
334
|
-
if (row === void 0) return false;
|
|
335
|
-
if (onRowActivate) {
|
|
336
|
-
onRowActivate(row, event);
|
|
337
|
-
return true;
|
|
338
|
-
}
|
|
339
|
-
const link = body.current?.querySelector(
|
|
340
|
-
`[data-row-index="${cursor}"] > .crewlet-data-grid__cell > a.crewlet-data-grid__row-link`
|
|
341
|
-
);
|
|
342
|
-
if (!link) return false;
|
|
343
|
-
link.dispatchEvent(
|
|
344
|
-
new MouseEvent("click", {
|
|
345
|
-
bubbles: true,
|
|
346
|
-
cancelable: true,
|
|
347
|
-
metaKey: event.metaKey,
|
|
348
|
-
ctrlKey: event.ctrlKey,
|
|
349
|
-
shiftKey: event.shiftKey,
|
|
350
|
-
altKey: event.altKey
|
|
351
|
-
})
|
|
352
|
-
);
|
|
353
|
-
return true;
|
|
354
|
-
},
|
|
355
|
-
rowCount: () => flat.length
|
|
356
|
-
}),
|
|
357
|
-
[flat, cursor, onRowActivate]
|
|
358
|
-
);
|
|
359
|
-
function headerClick(column) {
|
|
360
|
-
if (!column.sortValue || !onSortChange) return;
|
|
361
|
-
onSortChange(nextGridSort(column.key, sortRaw, defaultSort));
|
|
362
|
-
}
|
|
363
|
-
const template = drawnColumns.map((c) => tableTrack({ ...c, width: c.width ?? (c.icon ? DATA_GRID_ICON_TRACK : void 0) })).join(" ");
|
|
364
|
-
if (flat.length === 0 && !bands?.length && empty) {
|
|
365
|
-
return /* @__PURE__ */ jsx("div", { className: cx("crewlet-data-grid", className), "data-flush": flush || void 0, children: /* @__PURE__ */ jsx(
|
|
366
|
-
EmptyState,
|
|
367
|
-
{
|
|
368
|
-
size: "compact",
|
|
369
|
-
icon: empty.icon,
|
|
370
|
-
title: empty.title,
|
|
371
|
-
description: empty.hint,
|
|
372
|
-
action: empty.action
|
|
373
|
-
}
|
|
374
|
-
) });
|
|
375
|
-
}
|
|
376
|
-
let index = -1;
|
|
377
|
-
function renderRow(row) {
|
|
378
|
-
index += 1;
|
|
379
|
-
const at = index;
|
|
380
|
-
const link = rowHref?.(row);
|
|
381
|
-
const marked = Boolean(isSelected?.(row));
|
|
382
|
-
const picked = Boolean(selection?.selected.has(rowKey(row)));
|
|
383
|
-
const rowId = `${gridId}-row-${at}`;
|
|
384
|
-
const overlay = link !== void 0 ? (
|
|
385
|
-
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
|
386
|
-
/* @__PURE__ */ jsx(
|
|
387
|
-
"a",
|
|
388
|
-
{
|
|
389
|
-
className: "crewlet-data-grid__row-link",
|
|
390
|
-
href: link,
|
|
391
|
-
"aria-labelledby": rowId,
|
|
392
|
-
"aria-current": marked ? "true" : void 0,
|
|
393
|
-
onClick: (e) => onRowActivate?.(row, e)
|
|
394
|
-
}
|
|
395
|
-
)
|
|
396
|
-
) : onRowActivate ? /* @__PURE__ */ jsx(
|
|
397
|
-
"button",
|
|
398
|
-
{
|
|
399
|
-
type: "button",
|
|
400
|
-
className: "crewlet-data-grid__row-link",
|
|
401
|
-
"aria-labelledby": rowId,
|
|
402
|
-
"aria-current": marked ? "true" : void 0,
|
|
403
|
-
onClick: (e) => onRowActivate(row, e)
|
|
404
|
-
}
|
|
405
|
-
) : null;
|
|
406
|
-
const inner = drawnColumns.map((column, i) => /* @__PURE__ */ jsxs(
|
|
407
|
-
"span",
|
|
408
|
-
{
|
|
409
|
-
role: "cell",
|
|
410
|
-
className: cx(
|
|
411
|
-
"crewlet-data-grid__cell",
|
|
412
|
-
alignOf(column) !== "left" && `crewlet-data-grid__cell--${alignOf(column)}`,
|
|
413
|
-
column.icon && "crewlet-data-grid__cell--icon",
|
|
414
|
-
column.shrink && "crewlet-data-grid__cell--shrink",
|
|
415
|
-
column.action && "crewlet-data-grid__cell--action"
|
|
416
|
-
),
|
|
417
|
-
"data-lead": column.phoneLead || void 0,
|
|
418
|
-
"data-phone-omit": column.phoneOmit || void 0,
|
|
419
|
-
"data-label": column.action ? void 0 : headerWord(column) || column.label || void 0,
|
|
420
|
-
children: [
|
|
421
|
-
i === 0 ? overlay : null,
|
|
422
|
-
column.cell(row)
|
|
423
|
-
]
|
|
424
|
-
},
|
|
425
|
-
column.key
|
|
426
|
-
));
|
|
427
|
-
return /* @__PURE__ */ jsx(
|
|
428
|
-
"div",
|
|
429
|
-
{
|
|
430
|
-
id: rowId,
|
|
431
|
-
role: "row",
|
|
432
|
-
className: cx(
|
|
433
|
-
"crewlet-data-grid__row",
|
|
434
|
-
marked && "crewlet-data-grid__row--selected",
|
|
435
|
-
picked && "crewlet-data-grid__row--picked",
|
|
436
|
-
isFailed?.(row) && "crewlet-data-grid__row--failed",
|
|
437
|
-
cursor === at && "crewlet-data-grid__row--cursor"
|
|
438
|
-
),
|
|
439
|
-
"data-row-index": at,
|
|
440
|
-
"aria-current": overlay === null && marked ? "true" : void 0,
|
|
441
|
-
children: inner
|
|
442
|
-
},
|
|
443
|
-
rowKey(row)
|
|
444
|
-
);
|
|
445
|
-
}
|
|
446
|
-
function renderBand(band) {
|
|
447
|
-
const loaded = bandRows(band).length;
|
|
448
|
-
return (
|
|
449
|
-
// A BAND IS ROWS OF THE TABLE: its head and its foot are rows of one
|
|
450
|
-
// cell each across every column, and its own box is layout alone.
|
|
451
|
-
/* @__PURE__ */ jsxs("div", { className: "crewlet-data-grid__band", role: "none", children: [
|
|
452
|
-
/* @__PURE__ */ jsx("div", { className: "crewlet-data-grid__band-head", role: "row", children: /* @__PURE__ */ jsxs("span", { className: "crewlet-data-grid__band-cell", role: "rowheader", "aria-colspan": drawnColumns.length, children: [
|
|
453
|
-
band.mark,
|
|
454
|
-
/* @__PURE__ */ jsx("span", { className: "crewlet-data-grid__truncate", children: band.label }),
|
|
455
|
-
/* @__PURE__ */ jsx("span", { className: "crewlet-data-grid__band-count", children: band.total != null && band.total !== loaded ? `${loaded} of ${band.total}` : loaded })
|
|
456
|
-
] }) }),
|
|
457
|
-
band.bands ? band.bands.map((sub) => renderBand(sub)) : sortRows(band.rows).map(renderRow),
|
|
458
|
-
band.footer && /* @__PURE__ */ jsx("div", { className: "crewlet-data-grid__band-foot", role: "row", children: /* @__PURE__ */ jsx("span", { className: "crewlet-data-grid__band-cell", role: "cell", "aria-colspan": drawnColumns.length, children: band.footer }) })
|
|
459
|
-
] }, band.key)
|
|
460
|
-
);
|
|
461
|
-
}
|
|
462
|
-
return /* @__PURE__ */ jsxs(
|
|
463
|
-
"div",
|
|
464
|
-
{
|
|
465
|
-
ref: setWrap,
|
|
466
|
-
role: "table",
|
|
467
|
-
"aria-label": ariaLabel,
|
|
468
|
-
"aria-labelledby": ariaLabelledby,
|
|
469
|
-
className: cx("crewlet-data-grid", className),
|
|
470
|
-
"data-phone-rows": phoneRows === "compact" ? "compact" : void 0,
|
|
471
|
-
"data-stacked": stacked || void 0,
|
|
472
|
-
"data-flush": flush || void 0,
|
|
473
|
-
style: { gridTemplateColumns: template },
|
|
474
|
-
onPointerDown,
|
|
475
|
-
children: [
|
|
476
|
-
/* @__PURE__ */ jsx("div", { className: "crewlet-data-grid__head", role: "row", children: drawnColumns.map((column) => {
|
|
477
|
-
const sorted = sort?.key === column.key;
|
|
478
|
-
const sortable = Boolean(column.sortValue && onSortChange);
|
|
479
|
-
const headClass = cx(
|
|
480
|
-
"crewlet-data-grid__th",
|
|
481
|
-
alignOf(column) !== "left" && `crewlet-data-grid__th--${alignOf(column)}`,
|
|
482
|
-
column.icon && "crewlet-data-grid__th--icon",
|
|
483
|
-
column.shrink && "crewlet-data-grid__th--shrink",
|
|
484
|
-
sorted && "crewlet-data-grid__th--sorted",
|
|
485
|
-
!sortable && "crewlet-data-grid__th--plain"
|
|
486
|
-
);
|
|
487
|
-
const worded = column.header !== "" && column.header !== null && column.header !== void 0;
|
|
488
|
-
const label = worded ? /* @__PURE__ */ jsx("span", { className: "crewlet-data-grid__truncate", children: column.header }) : null;
|
|
489
|
-
const arrow = sorted ? sort?.desc ? /* @__PURE__ */ jsx(ArrowDownGlyph, { size: "xs" }) : /* @__PURE__ */ jsx(ArrowUpGlyph, { size: "xs" }) : sortable ? /* @__PURE__ */ jsx(ArrowUpDownGlyph, { size: "xs" }) : null;
|
|
490
|
-
const ariaSort = sorted ? sort?.desc ? "descending" : "ascending" : void 0;
|
|
491
|
-
const mark = arrow && /* @__PURE__ */ jsx("span", { className: "crewlet-data-grid__sort-mark", "aria-hidden": "true", children: arrow });
|
|
492
|
-
if (!sortable) {
|
|
493
|
-
const named = !headerWord(column) && !column.action ? column.label : void 0;
|
|
494
|
-
return (
|
|
495
|
-
// THE ORDER IN FORCE IS SAID on a head that cannot change it too:
|
|
496
|
-
// a grid sorted by its default, with nothing to press.
|
|
497
|
-
/* @__PURE__ */ jsxs("div", { className: headClass, role: "columnheader", title: named, "aria-sort": ariaSort, children: [
|
|
498
|
-
label,
|
|
499
|
-
mark,
|
|
500
|
-
named && /* @__PURE__ */ jsx(VisuallyHidden, { children: named })
|
|
501
|
-
] }, column.key)
|
|
502
|
-
);
|
|
503
|
-
}
|
|
504
|
-
return /* @__PURE__ */ jsx(
|
|
505
|
-
"div",
|
|
506
|
-
{
|
|
507
|
-
className: headClass,
|
|
508
|
-
role: "columnheader",
|
|
509
|
-
"aria-sort": ariaSort,
|
|
510
|
-
children: /* @__PURE__ */ jsxs(
|
|
511
|
-
"button",
|
|
512
|
-
{
|
|
513
|
-
type: "button",
|
|
514
|
-
className: "crewlet-data-grid__sort",
|
|
515
|
-
onClick: () => headerClick(column),
|
|
516
|
-
"aria-label": headerWord(column) ? void 0 : column.label,
|
|
517
|
-
children: [
|
|
518
|
-
label,
|
|
519
|
-
mark
|
|
520
|
-
]
|
|
521
|
-
}
|
|
522
|
-
)
|
|
523
|
-
},
|
|
524
|
-
column.key
|
|
525
|
-
);
|
|
526
|
-
}) }),
|
|
527
|
-
/* @__PURE__ */ jsx("div", { className: "crewlet-data-grid__body", role: "rowgroup", ref: body, children: bands ? bands.map((band) => renderBand(band)) : sortRows(rows ?? []).map(renderRow) }),
|
|
528
|
-
(footer || onLoadMore || loadedNote || dropped.length > 0) && /* @__PURE__ */ jsxs("div", { className: "crewlet-data-grid__foot", children: [
|
|
529
|
-
footer,
|
|
530
|
-
/* @__PURE__ */ jsx("span", { className: "crewlet-data-grid__foot-spacer", "aria-hidden": "true" }),
|
|
531
|
-
dropped.length > 0 && /* @__PURE__ */ jsx("span", { className: "crewlet-data-grid__note", children: text.hiddenToFit(droppedNames(shownColumns, dropped, text.and)) }),
|
|
532
|
-
loadedNote && /* @__PURE__ */ jsx("span", { className: "crewlet-data-grid__note", children: loadedNote }),
|
|
533
|
-
onLoadMore && /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", onClick: onLoadMore, children: text.loadMore })
|
|
534
|
-
] }),
|
|
535
|
-
colsRaw && onColsChange && /* @__PURE__ */ jsx("button", { type: "button", className: "crewlet-data-grid__cols-reset", onClick: () => onColsChange(""), children: text.showEveryColumn })
|
|
536
|
-
]
|
|
537
|
-
}
|
|
538
|
-
);
|
|
539
|
-
}
|
|
540
|
-
var drivable = [];
|
|
541
|
-
var touched = null;
|
|
542
|
-
var revision = 0;
|
|
543
|
-
var watchers = /* @__PURE__ */ new Set();
|
|
544
|
-
function announce() {
|
|
545
|
-
revision += 1;
|
|
546
|
-
for (const watcher of watchers) watcher();
|
|
547
|
-
}
|
|
548
|
-
function watch(watcher) {
|
|
549
|
-
watchers.add(watcher);
|
|
550
|
-
return () => {
|
|
551
|
-
watchers.delete(watcher);
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
function current() {
|
|
555
|
-
return revision;
|
|
556
|
-
}
|
|
557
|
-
function isDriving(id) {
|
|
558
|
-
if (touched !== null) return touched === id;
|
|
559
|
-
return drivable[0] === id;
|
|
560
|
-
}
|
|
561
|
-
function countDataGridRows(rows, bands) {
|
|
562
|
-
const inBand = (band) => band.bands ? band.bands.reduce((n, sub) => n + inBand(sub), 0) : band.rows.length;
|
|
563
|
-
return bands ? bands.reduce((n, band) => n + inBand(band), 0) : rows?.length ?? 0;
|
|
564
|
-
}
|
|
565
|
-
function useDataGridDriving(drivableNow) {
|
|
566
|
-
const id = useId();
|
|
567
|
-
useSyncExternalStore(watch, current, current);
|
|
568
|
-
useEffect(() => {
|
|
569
|
-
if (!drivableNow) return void 0;
|
|
570
|
-
drivable.push(id);
|
|
571
|
-
announce();
|
|
572
|
-
return () => {
|
|
573
|
-
const at = drivable.indexOf(id);
|
|
574
|
-
if (at >= 0) drivable.splice(at, 1);
|
|
575
|
-
if (touched === id) touched = null;
|
|
576
|
-
announce();
|
|
577
|
-
};
|
|
578
|
-
}, [id, drivableNow]);
|
|
579
|
-
const claim = useCallback(() => {
|
|
580
|
-
if (touched === id) return;
|
|
581
|
-
touched = id;
|
|
582
|
-
announce();
|
|
583
|
-
}, [id]);
|
|
584
|
-
return { driving: drivableNow && isDriving(id), claim };
|
|
585
|
-
}
|
|
586
|
-
function useAnyDataGridDriving() {
|
|
587
|
-
useSyncExternalStore(watch, current, current);
|
|
588
|
-
return drivable.length > 0;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
export { ChooserList, ColumnChooser, DATA_GRID_ICON_TRACK, DataGrid, columnChoicesOf, countDataGridRows, fitGridColumns, nextGridSort, parseGridSort, useAnyDataGridDriving, useDataGridDriving };
|
package/dist/chunk-CTQZK5J3.js
DELETED