@crewlethq/ui 0.100.1 → 0.101.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 +5 -5
- 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/ChatDay/index.js +1 -1
- package/dist/{ChatDay-E3FF5HWF.css → ChatDay-CTX2VI6P.css} +2 -0
- package/dist/ChatThread/index.js +1 -1
- 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/ContrastBadge/index.js +2 -2
- package/dist/ContrastHelp/index.js +3 -3
- package/dist/DataGrid/DataGrid.d.ts +127 -41
- package/dist/DataGrid/index.d.ts +1 -1
- package/dist/DataGrid/index.js +7 -5
- package/dist/DataGrid/parts.d.ts +163 -0
- package/dist/{DataGrid-SAHEL4SN.css → DataGrid-ERDIPEWV.css} +205 -16
- package/dist/DataTable/index.js +4 -4
- package/dist/DataView/index.js +7 -7
- package/dist/DatasetSource/index.js +1 -1
- package/dist/DeepWorkCard/index.js +1 -1
- package/dist/DocTabsEditor/index.js +2 -2
- 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/LogoSlot/index.js +3 -3
- 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/PrincipalPicker/index.js +3 -3
- package/dist/ProposalCard/index.js +3 -3
- package/dist/RailList/index.js +4 -3
- 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 +2 -2
- package/dist/ShareDialog/index.js +3 -3
- package/dist/SheetColumnEditor/index.js +5 -5
- package/dist/SheetGrid/index.js +3 -3
- 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-ONHYFU7D.js → chunk-AGJBHLPE.js} +1 -1
- package/dist/{chunk-BK4KUIAZ.js → chunk-AP6JSZGT.js} +12 -4
- package/dist/chunk-FL5DTFF3.js +557 -0
- package/dist/{chunk-L72GPZ56.js → chunk-G6QKJGQQ.js} +1 -1
- package/dist/{chunk-CL3FWLDO.js → chunk-HI47TXSW.js} +1 -1
- package/dist/{chunk-M6EVTMTK.js → chunk-HYVYYODN.js} +1 -1
- package/dist/{chunk-XQWWA2LG.js → chunk-IQO6YDEM.js} +19 -51
- package/dist/{chunk-HTCNTCBE.js → chunk-KMMRKMBQ.js} +1 -1
- package/dist/chunk-LIRXQOTR.js +892 -0
- package/dist/{chunk-CQIODINH.js → chunk-M2DHVN6T.js} +1 -1
- package/dist/{chunk-EMXUREKE.js → chunk-MKTHLT4E.js} +1 -1
- package/dist/{chunk-PF6X74C5.js → chunk-NHQ7O4DG.js} +3 -3
- package/dist/{chunk-DBH7ORCH.js → chunk-PCXMJZTE.js} +1 -1
- package/dist/{chunk-J3QFTG4B.js → chunk-PXYDEDNN.js} +1 -1
- package/dist/{chunk-PMO6W5NE.js → chunk-SBVTOIFP.js} +2 -2
- package/dist/{chunk-3NCIQO2P.js → chunk-U5Y335HH.js} +8 -4
- package/dist/{chunk-XRKBPNX4.js → chunk-V3QWPHY4.js} +1 -1
- package/dist/chunk-WSIJDWUG.js +10 -0
- package/dist/{chunk-O5CEG7TQ.js → chunk-XLMURU75.js} +1 -6
- package/dist/generated/index.js +90 -90
- package/dist/index.js +90 -90
- package/dist/styles.css +472 -31
- package/dist/utils/titleIfCut.d.ts +18 -0
- package/package.json +3 -3
- package/dist/chunk-CTQZK5J3.js +0 -8
- package/dist/chunk-ERESJG6C.js +0 -353
- package/dist/chunk-Z346ESBB.js +0 -591
- package/dist/{Editor-YHHCK5SJ.js → Editor-XRI2NOO5.js} +2 -2
- package/dist/{chunk-JZADK2FT.js → chunk-3JE6YIG5.js} +2 -2
- package/dist/{chunk-5KJOG5YP.js → chunk-6IAW2ZIE.js} +2 -2
- package/dist/{chunk-XLVWSNW3.js → chunk-CQAR3F33.js} +1 -1
- package/dist/{chunk-AC255TMQ.js → chunk-CRRW4UGJ.js} +1 -1
- package/dist/{chunk-IA3NL54W.js → chunk-CTHZHMVG.js} +1 -1
- package/dist/{chunk-MTKHMGJH.js → chunk-HR5O6PSR.js} +1 -1
- package/dist/{chunk-OU6ZSWEJ.js → chunk-I2GJLUU3.js} +1 -1
- package/dist/{chunk-7L6JJ7VJ.js → chunk-K2GVWTHA.js} +1 -1
- package/dist/{chunk-RSI6EJSH.js → chunk-LNXL22Y7.js} +1 -1
- package/dist/{chunk-NGRSGJM3.js → chunk-MFZBLJYF.js} +1 -1
- package/dist/{chunk-OAKECTYH.js → chunk-NIZRR2NN.js} +1 -1
- package/dist/{chunk-3Z2BSKS5.js → chunk-NRMF2PKX.js} +1 -1
- package/dist/{chunk-DK7CXQFY.js → chunk-QCCWXOKK.js} +1 -1
- package/dist/{chunk-LNQSNXGJ.js → chunk-S4JRQJEP.js} +1 -1
- package/dist/{chunk-HU5PAZMU.js → chunk-TXQ6FZJL.js} +1 -1
- package/dist/{chunk-GA773IOZ.js → chunk-V6CVW6PF.js} +1 -1
- package/dist/{chunk-EW4ULFHK.js → chunk-WTJU7MAG.js} +1 -1
|
@@ -0,0 +1,892 @@
|
|
|
1
|
+
import { titleWhenCut, titleIfCut } from './chunk-WSIJDWUG.js';
|
|
2
|
+
import { useReorder } from './chunk-BVML4UVB.js';
|
|
3
|
+
import { useMediaMatch } from './chunk-YJQXESOJ.js';
|
|
4
|
+
import { Skeleton } from './chunk-I4IUX3JF.js';
|
|
5
|
+
import { Checkbox } from './chunk-M6G7XLLP.js';
|
|
6
|
+
import { EmptyState } from './chunk-PPUR46MK.js';
|
|
7
|
+
import { Button } from './chunk-6KUOHUY5.js';
|
|
8
|
+
import { IconButton } from './chunk-WDLAAZFZ.js';
|
|
9
|
+
import { VisuallyHidden } from './chunk-UT6CW3C7.js';
|
|
10
|
+
import { cx } from './chunk-ODEQTPFM.js';
|
|
11
|
+
import './DataGrid-ERDIPEWV.css';
|
|
12
|
+
import { useId, useRef, useState, useMemo, useCallback, useLayoutEffect, useImperativeHandle, useSyncExternalStore, useEffect, Fragment as Fragment$1 } from 'react';
|
|
13
|
+
import { breakpoint } from '@crewlethq/tokens';
|
|
14
|
+
import { ArrowDownGlyph, ArrowUpGlyph, ArrowUpDownGlyph, GripVerticalGlyph, ChevronRightGlyph } from '@crewlethq/icons/glyphs';
|
|
15
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
16
|
+
|
|
17
|
+
// src/utils/tableTrack.ts
|
|
18
|
+
var SHRINK_SHARE = 0.2;
|
|
19
|
+
function tableTrack({ width, shrink, floor }) {
|
|
20
|
+
if (width) return width;
|
|
21
|
+
return shrink ? `fit-content(${SHRINK_SHARE * 100}%)` : `minmax(${floor ?? 0}, 1fr)`;
|
|
22
|
+
}
|
|
23
|
+
var GRID_ICON_TRACK = "calc(var(--size-target-min) + var(--spacing-3) * 2)";
|
|
24
|
+
function alignOf(column) {
|
|
25
|
+
return column.align ?? (column.icon ? "center" : "left");
|
|
26
|
+
}
|
|
27
|
+
function headerWord(column) {
|
|
28
|
+
return typeof column.header === "string" ? column.header : "";
|
|
29
|
+
}
|
|
30
|
+
function columnName(column) {
|
|
31
|
+
return headerWord(column) || column.label || column.key;
|
|
32
|
+
}
|
|
33
|
+
function parseGridSort(raw) {
|
|
34
|
+
if (!raw) return null;
|
|
35
|
+
return raw.startsWith("-") ? { key: raw.slice(1), desc: true } : { key: raw, desc: false };
|
|
36
|
+
}
|
|
37
|
+
function nextGridSort(column, sort, defaultSort = "") {
|
|
38
|
+
const chosen = sort === defaultSort ? "" : sort;
|
|
39
|
+
const current2 = parseGridSort(chosen || defaultSort);
|
|
40
|
+
let next;
|
|
41
|
+
if (current2?.key !== column) next = column;
|
|
42
|
+
else if (!current2.desc) next = `-${column}`;
|
|
43
|
+
else next = chosen ? "" : column;
|
|
44
|
+
return next === defaultSort ? "" : next;
|
|
45
|
+
}
|
|
46
|
+
function compare(a, b) {
|
|
47
|
+
if (typeof a === "number" && typeof b === "number") {
|
|
48
|
+
if (Number.isNaN(a)) return Number.isNaN(b) ? 0 : 1;
|
|
49
|
+
if (Number.isNaN(b)) return -1;
|
|
50
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
51
|
+
}
|
|
52
|
+
return String(a).localeCompare(String(b), void 0, { numeric: true, sensitivity: "base" });
|
|
53
|
+
}
|
|
54
|
+
function sortByValue(items, get, desc) {
|
|
55
|
+
return [...items].sort((a, b) => {
|
|
56
|
+
const av = get(a);
|
|
57
|
+
const bv = get(b);
|
|
58
|
+
if (av == null && bv == null) return 0;
|
|
59
|
+
if (av == null) return 1;
|
|
60
|
+
if (bv == null) return -1;
|
|
61
|
+
const cmp = compare(av, bv);
|
|
62
|
+
return desc ? -cmp : cmp;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
var GRID_FOOT_LABELS = {
|
|
66
|
+
hiddenToFit: (names) => `Hidden to fit: ${names}`,
|
|
67
|
+
loadMore: "Load more",
|
|
68
|
+
showEveryColumn: "Show every column",
|
|
69
|
+
and: "and"
|
|
70
|
+
};
|
|
71
|
+
function droppedNames(columns, dropped, and) {
|
|
72
|
+
const names = dropped.map((key) => {
|
|
73
|
+
const c = columns.find((col) => col.key === key);
|
|
74
|
+
return c ? columnName(c) : key;
|
|
75
|
+
});
|
|
76
|
+
return names.length <= 1 ? names[0] ?? "" : `${names.slice(0, -1).join(", ")} ${and} ${names[names.length - 1]}`;
|
|
77
|
+
}
|
|
78
|
+
function GridHeadCell({ column, sort, sortable, onSort, hidden = false, colIndex }) {
|
|
79
|
+
const align = alignOf(column);
|
|
80
|
+
const sorted = sort?.key === column.key;
|
|
81
|
+
const headClass = cx(
|
|
82
|
+
"crewlet-data-grid__th",
|
|
83
|
+
align !== "left" && `crewlet-data-grid__th--${align}`,
|
|
84
|
+
column.icon && "crewlet-data-grid__th--icon",
|
|
85
|
+
column.shrink && "crewlet-data-grid__th--shrink",
|
|
86
|
+
sorted && "crewlet-data-grid__th--sorted",
|
|
87
|
+
!sortable && "crewlet-data-grid__th--plain"
|
|
88
|
+
);
|
|
89
|
+
const worded = column.header !== "" && column.header !== null && column.header !== void 0;
|
|
90
|
+
const label = !worded ? null : hidden ? /* @__PURE__ */ jsx(VisuallyHidden, { children: column.header }) : /* @__PURE__ */ jsx("span", { className: "crewlet-data-grid__truncate", onMouseEnter: titleWhenCut, children: column.header });
|
|
91
|
+
const arrow = sorted ? sort?.desc ? /* @__PURE__ */ jsx(ArrowDownGlyph, { size: "xs" }) : /* @__PURE__ */ jsx(ArrowUpGlyph, { size: "xs" }) : sortable ? /* @__PURE__ */ jsx(ArrowUpDownGlyph, { size: "xs" }) : null;
|
|
92
|
+
const ariaSort = sorted ? sort?.desc ? "descending" : "ascending" : void 0;
|
|
93
|
+
const mark = arrow && /* @__PURE__ */ jsx("span", { className: "crewlet-data-grid__sort-mark", "aria-hidden": "true", children: arrow });
|
|
94
|
+
if (!sortable) {
|
|
95
|
+
const named = !headerWord(column) && !column.action ? column.label : void 0;
|
|
96
|
+
return /* @__PURE__ */ jsxs("div", { className: headClass, role: "columnheader", "aria-colindex": colIndex, title: named, "aria-sort": ariaSort, children: [
|
|
97
|
+
label,
|
|
98
|
+
mark,
|
|
99
|
+
named && /* @__PURE__ */ jsx(VisuallyHidden, { children: named })
|
|
100
|
+
] });
|
|
101
|
+
}
|
|
102
|
+
return /* @__PURE__ */ jsx("div", { className: headClass, role: "columnheader", "aria-colindex": colIndex, "aria-sort": ariaSort, children: /* @__PURE__ */ jsxs(
|
|
103
|
+
"button",
|
|
104
|
+
{
|
|
105
|
+
type: "button",
|
|
106
|
+
className: "crewlet-data-grid__sort",
|
|
107
|
+
onClick: onSort,
|
|
108
|
+
"aria-label": headerWord(column) ? void 0 : column.label,
|
|
109
|
+
children: [
|
|
110
|
+
label,
|
|
111
|
+
mark
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
) });
|
|
115
|
+
}
|
|
116
|
+
function GridFoot({ footer, dropped, loadedNote, onLoadMore, onReset, labels, columns }) {
|
|
117
|
+
const shows = Boolean(footer) || Boolean(onLoadMore) || Boolean(loadedNote) || dropped !== "";
|
|
118
|
+
if (!shows && !onReset) return null;
|
|
119
|
+
const table = columns !== void 0;
|
|
120
|
+
const cell = (className, children) => table ? /* @__PURE__ */ jsx("div", { role: "cell", "aria-colspan": columns, className, children }) : /* @__PURE__ */ jsx("div", { className, children });
|
|
121
|
+
return /* @__PURE__ */ jsxs("div", { role: table ? "rowgroup" : void 0, className: "crewlet-data-grid__foot-group", children: [
|
|
122
|
+
shows && /* @__PURE__ */ jsx("div", { role: table ? "row" : void 0, className: "crewlet-data-grid__foot", children: cell(
|
|
123
|
+
"crewlet-data-grid__foot-cell",
|
|
124
|
+
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
125
|
+
footer,
|
|
126
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-data-grid__foot-spacer", "aria-hidden": "true" }),
|
|
127
|
+
dropped !== "" && /* @__PURE__ */ jsx("span", { className: "crewlet-data-grid__note", children: labels.hiddenToFit(dropped) }),
|
|
128
|
+
loadedNote && /* @__PURE__ */ jsx("span", { className: "crewlet-data-grid__note", children: loadedNote }),
|
|
129
|
+
onLoadMore && /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", onClick: onLoadMore, children: labels.loadMore })
|
|
130
|
+
] })
|
|
131
|
+
) }),
|
|
132
|
+
onReset && /* @__PURE__ */ jsx("div", { role: table ? "row" : void 0, className: "crewlet-data-grid__reset", children: cell(
|
|
133
|
+
"crewlet-data-grid__reset-cell",
|
|
134
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "crewlet-data-grid__cols-reset", onClick: onReset, children: labels.showEveryColumn })
|
|
135
|
+
) })
|
|
136
|
+
] });
|
|
137
|
+
}
|
|
138
|
+
var CUT = ".crewlet-data-grid__truncate, .crewlet-table-cell__truncate, .crewlet-text--truncate";
|
|
139
|
+
function titleBeneath(link, x, y) {
|
|
140
|
+
const row = link.closest('[role="row"]');
|
|
141
|
+
if (!row || typeof document.elementsFromPoint !== "function") return null;
|
|
142
|
+
const under = document.elementsFromPoint(x, y).find((el) => el !== link && row.contains(el) && el !== row);
|
|
143
|
+
if (!under) return null;
|
|
144
|
+
const titled = under.closest("[title]");
|
|
145
|
+
const own = titled && row.contains(titled) && titled !== row ? titled : null;
|
|
146
|
+
if (own && !own.matches(CUT)) return own.getAttribute("title");
|
|
147
|
+
const cut = under.closest(CUT);
|
|
148
|
+
if (cut && row.contains(cut)) {
|
|
149
|
+
titleIfCut(cut);
|
|
150
|
+
return cut.getAttribute("title");
|
|
151
|
+
}
|
|
152
|
+
return own?.getAttribute("title") ?? null;
|
|
153
|
+
}
|
|
154
|
+
var rowLinkTitle = {
|
|
155
|
+
onMouseMove: (event) => {
|
|
156
|
+
const title = titleBeneath(event.currentTarget, event.clientX, event.clientY);
|
|
157
|
+
if (title) event.currentTarget.setAttribute("title", title);
|
|
158
|
+
else event.currentTarget.removeAttribute("title");
|
|
159
|
+
},
|
|
160
|
+
onMouseLeave: (event) => event.currentTarget.removeAttribute("title")
|
|
161
|
+
};
|
|
162
|
+
var SQUEEZE_SAMPLE_ROWS = 12;
|
|
163
|
+
function overrunning(box, head) {
|
|
164
|
+
const last = head?.lastElementChild;
|
|
165
|
+
if (!last) return false;
|
|
166
|
+
const inner = box.getBoundingClientRect().left + box.clientLeft + box.clientWidth;
|
|
167
|
+
return last.getBoundingClientRect().right > inner + 0.5;
|
|
168
|
+
}
|
|
169
|
+
function cutShort(el) {
|
|
170
|
+
for (const node of [el, ...el.querySelectorAll("*")]) {
|
|
171
|
+
const box = node;
|
|
172
|
+
if (box.clientWidth > 1 && box.scrollWidth > box.clientWidth + 1) return true;
|
|
173
|
+
}
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
function squeezedCells(width, heads, rows, cellsOf, visible, leading = 0) {
|
|
177
|
+
const cap = width * SHRINK_SHARE - 1;
|
|
178
|
+
const sample = rows.slice(0, SQUEEZE_SAMPLE_ROWS);
|
|
179
|
+
let headCut = false;
|
|
180
|
+
for (let i = 0; i < visible.length; i++) {
|
|
181
|
+
const column = visible[i];
|
|
182
|
+
if (!column.shrink || column.width || column.icon) continue;
|
|
183
|
+
const head = heads[i + leading];
|
|
184
|
+
if (!head || head.getBoundingClientRect().width >= cap) continue;
|
|
185
|
+
if (cutShort(head)) headCut = true;
|
|
186
|
+
for (const row of sample) {
|
|
187
|
+
const cell = cellsOf(row)[i + leading];
|
|
188
|
+
if (cell && cutShort(cell)) return "values";
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return headCut ? "heads" : null;
|
|
192
|
+
}
|
|
193
|
+
var DATA_GRID_ICON_TRACK = GRID_ICON_TRACK;
|
|
194
|
+
function sortsBy(column) {
|
|
195
|
+
return column.sortable ?? column.sortValue !== void 0;
|
|
196
|
+
}
|
|
197
|
+
function columnChoicesOf(columns) {
|
|
198
|
+
return columns.map((column) => ({
|
|
199
|
+
key: column.key,
|
|
200
|
+
label: headerWord(column) || column.label || column.key,
|
|
201
|
+
optional: column.optional
|
|
202
|
+
}));
|
|
203
|
+
}
|
|
204
|
+
function ChooserList({ label, items, onToggle }) {
|
|
205
|
+
const headingId = useId();
|
|
206
|
+
if (items.length === 0) return null;
|
|
207
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
208
|
+
/* @__PURE__ */ jsx("div", { className: "crewlet-column-chooser__label", id: headingId, children: label }),
|
|
209
|
+
/* @__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: [
|
|
210
|
+
/* @__PURE__ */ jsx("input", { type: "checkbox", checked: item.checked, onChange: () => onToggle(item.key) }),
|
|
211
|
+
/* @__PURE__ */ jsx("span", { children: item.label })
|
|
212
|
+
] }, item.key)) })
|
|
213
|
+
] });
|
|
214
|
+
}
|
|
215
|
+
function ColumnChooser({ choices, value, onChange, label = "Columns" }) {
|
|
216
|
+
const chosen = new Set(value ? value.split(",").filter(Boolean) : []);
|
|
217
|
+
const isOn = (choice) => chosen.size === 0 ? !choice.optional : chosen.has(choice.key);
|
|
218
|
+
return /* @__PURE__ */ jsx(
|
|
219
|
+
ChooserList,
|
|
220
|
+
{
|
|
221
|
+
label,
|
|
222
|
+
items: choices.map((choice) => ({ key: choice.key, label: choice.label, checked: isOn(choice) })),
|
|
223
|
+
onToggle: (key) => {
|
|
224
|
+
const next = new Set(choices.filter(isOn).map((c) => c.key));
|
|
225
|
+
if (next.has(key)) next.delete(key);
|
|
226
|
+
else next.add(key);
|
|
227
|
+
onChange(
|
|
228
|
+
choices.filter((c) => next.has(c.key)).map((c) => c.key).join(",")
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
var LABELS = {
|
|
235
|
+
...GRID_FOOT_LABELS,
|
|
236
|
+
selectAll: "Select every row",
|
|
237
|
+
ordinal: "#"
|
|
238
|
+
};
|
|
239
|
+
var SELECT_COLUMN = "crewlet-select";
|
|
240
|
+
var REORDER_COLUMN = "crewlet-reorder";
|
|
241
|
+
var ORDINAL_COLUMN = "crewlet-ordinal";
|
|
242
|
+
var EXPAND_COLUMN = "crewlet-expand";
|
|
243
|
+
var LOADING_ROWS = 3;
|
|
244
|
+
var NO_KEYS = [];
|
|
245
|
+
function movedKey(before, after) {
|
|
246
|
+
let at = 0;
|
|
247
|
+
while (at < before.length && before[at] === after[at]) at += 1;
|
|
248
|
+
if (at >= before.length) return null;
|
|
249
|
+
const without = (keys, key2) => keys.filter((k) => k !== key2).join("\0");
|
|
250
|
+
const key = without(before, before[at]) === without(after, before[at]) ? before[at] : after[at];
|
|
251
|
+
const to = after.indexOf(key);
|
|
252
|
+
return { key, before: after[to + 1] ?? null };
|
|
253
|
+
}
|
|
254
|
+
function bandRows(band) {
|
|
255
|
+
return band.bands ? band.bands.flatMap(bandRows) : band.rows;
|
|
256
|
+
}
|
|
257
|
+
var NO_DROPS = [];
|
|
258
|
+
var NO_FIT = { set: "", width: 0, dropped: NO_DROPS };
|
|
259
|
+
function fitGridColumns({
|
|
260
|
+
fit,
|
|
261
|
+
width,
|
|
262
|
+
overflows,
|
|
263
|
+
stack = false,
|
|
264
|
+
visible
|
|
265
|
+
}) {
|
|
266
|
+
if ((fit.dropped.length > 0 || fit.stacked) && width > fit.width) {
|
|
267
|
+
return { set: fit.set, width, dropped: NO_DROPS };
|
|
268
|
+
}
|
|
269
|
+
if (fit.stacked) return null;
|
|
270
|
+
if (overflows || stack) {
|
|
271
|
+
let next;
|
|
272
|
+
for (const c of visible) {
|
|
273
|
+
if (c.drop === void 0) continue;
|
|
274
|
+
if (!next || c.drop < next.drop) next = c;
|
|
275
|
+
}
|
|
276
|
+
if (next) return { set: fit.set, width, dropped: [...fit.dropped, next.key] };
|
|
277
|
+
if (stack) return { set: fit.set, width, dropped: fit.dropped, stacked: true };
|
|
278
|
+
}
|
|
279
|
+
if (width !== fit.width && (fit.dropped.length > 0 || fit.width === 0)) {
|
|
280
|
+
return { ...fit, width };
|
|
281
|
+
}
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
function squeezed(wrap, visible, leading = 0) {
|
|
285
|
+
const head = wrap.querySelector(":scope > .crewlet-data-grid__head");
|
|
286
|
+
if (!head) return null;
|
|
287
|
+
const rows = [...wrap.querySelectorAll(":scope > .crewlet-data-grid__body .crewlet-data-grid__row")];
|
|
288
|
+
return squeezedCells(
|
|
289
|
+
wrap.clientWidth,
|
|
290
|
+
[...head.children],
|
|
291
|
+
rows,
|
|
292
|
+
(row) => [...row.querySelectorAll(":scope > .crewlet-data-grid__cell")],
|
|
293
|
+
visible,
|
|
294
|
+
leading
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
function DataGrid({
|
|
298
|
+
rows,
|
|
299
|
+
bands,
|
|
300
|
+
columns,
|
|
301
|
+
rowKey,
|
|
302
|
+
onRowActivate,
|
|
303
|
+
rowHref,
|
|
304
|
+
isSelected,
|
|
305
|
+
selection,
|
|
306
|
+
isFailed,
|
|
307
|
+
rowTone,
|
|
308
|
+
expansion,
|
|
309
|
+
rowAccessory,
|
|
310
|
+
reorder,
|
|
311
|
+
ordinal = false,
|
|
312
|
+
summaryRows,
|
|
313
|
+
density = "default",
|
|
314
|
+
loading = false,
|
|
315
|
+
loadingRows = LOADING_ROWS,
|
|
316
|
+
sort: sortRaw = "",
|
|
317
|
+
defaultSort = "",
|
|
318
|
+
onSortChange,
|
|
319
|
+
serverSorted = false,
|
|
320
|
+
cols: colsRaw = "",
|
|
321
|
+
onColsChange,
|
|
322
|
+
empty,
|
|
323
|
+
footer,
|
|
324
|
+
onLoadMore,
|
|
325
|
+
loadedNote,
|
|
326
|
+
phoneRows = "labelled",
|
|
327
|
+
flush = false,
|
|
328
|
+
handleRef,
|
|
329
|
+
onPointerDown,
|
|
330
|
+
labels,
|
|
331
|
+
"aria-label": ariaLabel,
|
|
332
|
+
"aria-labelledby": ariaLabelledby,
|
|
333
|
+
className
|
|
334
|
+
}) {
|
|
335
|
+
const text = { ...LABELS, ...labels };
|
|
336
|
+
const ordered = reorder !== void 0 && !bands;
|
|
337
|
+
const sort = ordered ? null : parseGridSort(sortRaw || defaultSort);
|
|
338
|
+
const body = useRef(null);
|
|
339
|
+
const [cursor, setCursor] = useState(-1);
|
|
340
|
+
const gridId = useId();
|
|
341
|
+
const shownColumns = useMemo(() => {
|
|
342
|
+
const asked = colsRaw.split(",").map((c) => c.trim()).filter(Boolean);
|
|
343
|
+
if (asked.length === 0) return columns.filter((c) => !c.optional);
|
|
344
|
+
const byKey = new Map(columns.map((c) => [c.key, c]));
|
|
345
|
+
const picked = asked.map((key) => byKey.get(key)).filter((c) => !!c);
|
|
346
|
+
return picked.length > 0 ? picked : columns.filter((c) => !c.optional);
|
|
347
|
+
}, [columns, colsRaw]);
|
|
348
|
+
const [wrap, setWrap] = useState(null);
|
|
349
|
+
const phone = useMediaMatch(`(width < ${breakpoint.phone})`);
|
|
350
|
+
const shownKeys = shownColumns.map((c) => c.key).join(",");
|
|
351
|
+
const [fit, setFit] = useState(NO_FIT);
|
|
352
|
+
const stacked = phone || fit.set === shownKeys && Boolean(fit.stacked);
|
|
353
|
+
const dropped = !stacked && fit.set === shownKeys ? fit.dropped : NO_DROPS;
|
|
354
|
+
const visibleColumns = useMemo(
|
|
355
|
+
() => dropped.length === 0 ? shownColumns : shownColumns.filter((c) => !dropped.includes(c.key)),
|
|
356
|
+
[shownColumns, dropped]
|
|
357
|
+
);
|
|
358
|
+
const sortRows = useCallback(
|
|
359
|
+
(input) => {
|
|
360
|
+
if (!sort || serverSorted) return input;
|
|
361
|
+
const get = columns.find((c) => c.key === sort.key)?.sortValue;
|
|
362
|
+
return get ? sortByValue(input, get, sort.desc) : input;
|
|
363
|
+
},
|
|
364
|
+
[columns, sort, serverSorted]
|
|
365
|
+
);
|
|
366
|
+
const keyList = ordered ? (rows ?? []).map(rowKey) : NO_KEYS;
|
|
367
|
+
const keyText = keyList.join("\0");
|
|
368
|
+
const reorderKeys = useMemo(() => keyList, [keyText]);
|
|
369
|
+
const onMove = reorder?.onMove;
|
|
370
|
+
const onReorder = useCallback(
|
|
371
|
+
(next) => {
|
|
372
|
+
const move = movedKey(reorderKeys, next);
|
|
373
|
+
if (move) onMove?.(move.key, move.before);
|
|
374
|
+
},
|
|
375
|
+
[reorderKeys, onMove]
|
|
376
|
+
);
|
|
377
|
+
const reorderBy = useReorder({
|
|
378
|
+
keys: reorderKeys,
|
|
379
|
+
onReorder,
|
|
380
|
+
nameOf: (key) => {
|
|
381
|
+
const row = (rows ?? []).find((r) => rowKey(r) === key);
|
|
382
|
+
return row !== void 0 && reorder ? reorder.rowName(row) : key;
|
|
383
|
+
},
|
|
384
|
+
labels: reorder?.labels
|
|
385
|
+
});
|
|
386
|
+
const flat = useMemo(() => {
|
|
387
|
+
if (ordered) {
|
|
388
|
+
const byKey = new Map((rows ?? []).map((row) => [rowKey(row), row]));
|
|
389
|
+
return reorderBy.order.map((key) => byKey.get(key)).filter((row) => row !== void 0);
|
|
390
|
+
}
|
|
391
|
+
const walk = (band) => band.bands ? band.bands.flatMap(walk) : sortRows(band.rows);
|
|
392
|
+
if (bands) return bands.flatMap(walk);
|
|
393
|
+
return sortRows(rows ?? []);
|
|
394
|
+
}, [ordered, reorderBy.order, bands, rows, rowKey, sortRows]);
|
|
395
|
+
const anchor = useRef(null);
|
|
396
|
+
const pickable = useMemo(
|
|
397
|
+
() => selection ? flat.filter((row) => selection.isSelectable?.(row) ?? true) : [],
|
|
398
|
+
[flat, selection]
|
|
399
|
+
);
|
|
400
|
+
const pickedCount = selection ? pickable.filter((row) => selection.selected.has(rowKey(row))).length : 0;
|
|
401
|
+
const allPicked = pickable.length > 0 && pickedCount === pickable.length;
|
|
402
|
+
const pick = (row, on, range) => {
|
|
403
|
+
if (!selection) return;
|
|
404
|
+
const key = rowKey(row);
|
|
405
|
+
const next = new Set(selection.selected);
|
|
406
|
+
const to = flat.findIndex((r) => rowKey(r) === key);
|
|
407
|
+
const from = range && anchor.current !== null ? flat.findIndex((r) => rowKey(r) === anchor.current) : -1;
|
|
408
|
+
const span = from >= 0 && to >= 0 ? flat.slice(Math.min(from, to), Math.max(from, to) + 1) : [row];
|
|
409
|
+
for (const r of span) {
|
|
410
|
+
if (selection.isSelectable?.(r) === false) continue;
|
|
411
|
+
if (on) next.add(rowKey(r));
|
|
412
|
+
else next.delete(rowKey(r));
|
|
413
|
+
}
|
|
414
|
+
anchor.current = key;
|
|
415
|
+
selection.onChange(next);
|
|
416
|
+
};
|
|
417
|
+
const pickAll = () => {
|
|
418
|
+
if (!selection) return;
|
|
419
|
+
const next = new Set(selection.selected);
|
|
420
|
+
for (const row of pickable) {
|
|
421
|
+
if (allPicked) next.delete(rowKey(row));
|
|
422
|
+
else next.add(rowKey(row));
|
|
423
|
+
}
|
|
424
|
+
anchor.current = null;
|
|
425
|
+
selection.onChange(next);
|
|
426
|
+
};
|
|
427
|
+
const position = useMemo(() => new Map(flat.map((row, at) => [rowKey(row), at + 1])), [flat, rowKey]);
|
|
428
|
+
const leadingColumns = [];
|
|
429
|
+
if (selection) {
|
|
430
|
+
leadingColumns.push({
|
|
431
|
+
key: SELECT_COLUMN,
|
|
432
|
+
header: /* @__PURE__ */ jsx(
|
|
433
|
+
Checkbox,
|
|
434
|
+
{
|
|
435
|
+
hideLabel: true,
|
|
436
|
+
label: text.selectAll,
|
|
437
|
+
checked: allPicked,
|
|
438
|
+
indeterminate: pickedCount > 0 && !allPicked,
|
|
439
|
+
disabled: pickable.length === 0,
|
|
440
|
+
onChange: pickAll
|
|
441
|
+
}
|
|
442
|
+
),
|
|
443
|
+
cell: (row) => (
|
|
444
|
+
// ABOVE THE ROW'S LINK, so the press lands on the box.
|
|
445
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-data-grid__select", "data-above-row": true, children: /* @__PURE__ */ jsx(
|
|
446
|
+
Checkbox,
|
|
447
|
+
{
|
|
448
|
+
hideLabel: true,
|
|
449
|
+
label: selection.rowLabel(row),
|
|
450
|
+
checked: selection.selected.has(rowKey(row)),
|
|
451
|
+
disabled: selection.isSelectable?.(row) === false,
|
|
452
|
+
onChange: (event) => pick(row, event.target.checked, event.nativeEvent.shiftKey === true)
|
|
453
|
+
}
|
|
454
|
+
) })
|
|
455
|
+
),
|
|
456
|
+
action: true,
|
|
457
|
+
phoneLead: true,
|
|
458
|
+
width: DATA_GRID_ICON_TRACK
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
if (ordered && reorder) {
|
|
462
|
+
leadingColumns.push({
|
|
463
|
+
key: REORDER_COLUMN,
|
|
464
|
+
// THE HANDLES' INSTRUCTION, which every handle is described by, held in
|
|
465
|
+
// their column's head: the table owns rows and cells and nothing else.
|
|
466
|
+
header: /* @__PURE__ */ jsx(VisuallyHidden, { id: reorderBy.hintId, children: reorderBy.hint }),
|
|
467
|
+
cell: (row) => {
|
|
468
|
+
const key = rowKey(row);
|
|
469
|
+
const { "aria-label": name, ...handle } = reorderBy.handleProps(key);
|
|
470
|
+
const fixed = reorder.canMove?.(row) === false || reorder.pendingKey === key;
|
|
471
|
+
return /* @__PURE__ */ jsx(
|
|
472
|
+
IconButton,
|
|
473
|
+
{
|
|
474
|
+
size: "sm",
|
|
475
|
+
variant: "ghost",
|
|
476
|
+
className: "crewlet-data-grid__handle",
|
|
477
|
+
label: name,
|
|
478
|
+
icon: /* @__PURE__ */ jsx(GripVerticalGlyph, { size: "md" }),
|
|
479
|
+
...fixed ? { disabled: true } : handle
|
|
480
|
+
}
|
|
481
|
+
);
|
|
482
|
+
},
|
|
483
|
+
action: true,
|
|
484
|
+
phoneLead: true,
|
|
485
|
+
width: DATA_GRID_ICON_TRACK
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
if (ordinal) {
|
|
489
|
+
leadingColumns.push({
|
|
490
|
+
key: ORDINAL_COLUMN,
|
|
491
|
+
header: text.ordinal,
|
|
492
|
+
align: "right",
|
|
493
|
+
shrink: true,
|
|
494
|
+
cell: (row) => position.get(rowKey(row)) ?? null
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
if (expansion) {
|
|
498
|
+
leadingColumns.push({
|
|
499
|
+
key: EXPAND_COLUMN,
|
|
500
|
+
header: "",
|
|
501
|
+
cell: (row) => {
|
|
502
|
+
if (expansion.canExpand?.(row) === false) return null;
|
|
503
|
+
const open = expansion.isExpanded(row);
|
|
504
|
+
return /* @__PURE__ */ jsx("span", { className: "crewlet-data-grid__expander", "data-open": open ? "" : void 0, children: /* @__PURE__ */ jsx(
|
|
505
|
+
IconButton,
|
|
506
|
+
{
|
|
507
|
+
size: "sm",
|
|
508
|
+
variant: "ghost",
|
|
509
|
+
label: expansion.label(row, open),
|
|
510
|
+
icon: /* @__PURE__ */ jsx(ChevronRightGlyph, {}),
|
|
511
|
+
"aria-expanded": open,
|
|
512
|
+
"aria-controls": open ? detailId(row) : void 0,
|
|
513
|
+
onClick: () => expansion.onToggle(row)
|
|
514
|
+
}
|
|
515
|
+
) });
|
|
516
|
+
},
|
|
517
|
+
action: true,
|
|
518
|
+
phoneLead: true,
|
|
519
|
+
width: DATA_GRID_ICON_TRACK
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
const drawnColumns = leadingColumns.length > 0 ? [...leadingColumns, ...visibleColumns] : visibleColumns;
|
|
523
|
+
const leading = leadingColumns.length;
|
|
524
|
+
const [boxWidth, setBoxWidth] = useState(0);
|
|
525
|
+
useLayoutEffect(() => {
|
|
526
|
+
if (!wrap || typeof ResizeObserver !== "function") return;
|
|
527
|
+
const watch2 = new ResizeObserver(() => setBoxWidth(wrap.clientWidth));
|
|
528
|
+
watch2.observe(wrap);
|
|
529
|
+
return () => watch2.disconnect();
|
|
530
|
+
}, [wrap]);
|
|
531
|
+
useLayoutEffect(() => {
|
|
532
|
+
const el = wrap;
|
|
533
|
+
if (!el || phone) return;
|
|
534
|
+
const current2 = fit.set === shownKeys ? fit : { ...NO_FIT, set: shownKeys };
|
|
535
|
+
const overrun = !current2.stacked && overrunning(el, el.querySelector(":scope > .crewlet-data-grid__head"));
|
|
536
|
+
const squeeze = current2.stacked ? null : squeezed(el, visibleColumns, leading);
|
|
537
|
+
const next = fitGridColumns({
|
|
538
|
+
fit: current2,
|
|
539
|
+
width: el.clientWidth,
|
|
540
|
+
overflows: overrun || squeeze !== null,
|
|
541
|
+
stack: overrun || squeeze === "values",
|
|
542
|
+
visible: visibleColumns
|
|
543
|
+
});
|
|
544
|
+
if (next !== null) setFit(next);
|
|
545
|
+
}, [wrap, phone, fit, shownKeys, visibleColumns, leading, flat, boxWidth]);
|
|
546
|
+
useImperativeHandle(
|
|
547
|
+
handleRef,
|
|
548
|
+
() => ({
|
|
549
|
+
step: (by) => setCursor((at) => {
|
|
550
|
+
const next = Math.max(0, Math.min(flat.length - 1, at + by));
|
|
551
|
+
body.current?.querySelector(`[data-row-index="${next}"]`)?.scrollIntoView({ block: "nearest" });
|
|
552
|
+
return next;
|
|
553
|
+
}),
|
|
554
|
+
// THE ROW'S OWN WAY IN, from the keyboard: its handler where it has
|
|
555
|
+
// one, else its link, followed as a click on it would be (with the
|
|
556
|
+
// keys held, so a modified Enter opens it elsewhere as a modified
|
|
557
|
+
// click does). A grid of links only had no Enter at all.
|
|
558
|
+
activate: (event) => {
|
|
559
|
+
const row = flat[cursor];
|
|
560
|
+
if (row === void 0) return false;
|
|
561
|
+
if (onRowActivate) {
|
|
562
|
+
onRowActivate(row, event);
|
|
563
|
+
return true;
|
|
564
|
+
}
|
|
565
|
+
const link = body.current?.querySelector(
|
|
566
|
+
`[data-row-index="${cursor}"] > .crewlet-data-grid__cell > a.crewlet-data-grid__row-link`
|
|
567
|
+
);
|
|
568
|
+
if (!link) return false;
|
|
569
|
+
link.dispatchEvent(
|
|
570
|
+
new MouseEvent("click", {
|
|
571
|
+
bubbles: true,
|
|
572
|
+
cancelable: true,
|
|
573
|
+
metaKey: event.metaKey,
|
|
574
|
+
ctrlKey: event.ctrlKey,
|
|
575
|
+
shiftKey: event.shiftKey,
|
|
576
|
+
altKey: event.altKey
|
|
577
|
+
})
|
|
578
|
+
);
|
|
579
|
+
return true;
|
|
580
|
+
},
|
|
581
|
+
rowCount: () => flat.length
|
|
582
|
+
}),
|
|
583
|
+
[flat, cursor, onRowActivate]
|
|
584
|
+
);
|
|
585
|
+
function headerClick(column) {
|
|
586
|
+
if (!sortsBy(column) || !onSortChange) return;
|
|
587
|
+
onSortChange(nextGridSort(column.key, sortRaw, defaultSort));
|
|
588
|
+
}
|
|
589
|
+
const template = drawnColumns.map((c) => tableTrack({ ...c, width: c.width ?? (c.icon ? DATA_GRID_ICON_TRACK : void 0) })).join(" ");
|
|
590
|
+
const placeholders = loading && flat.length === 0 && !bands?.length;
|
|
591
|
+
if (flat.length === 0 && !bands?.length && !summaryRows?.length && empty && !placeholders) {
|
|
592
|
+
return /* @__PURE__ */ jsx("div", { className: cx("crewlet-data-grid", className), "data-flush": flush || void 0, children: /* @__PURE__ */ jsx(
|
|
593
|
+
EmptyState,
|
|
594
|
+
{
|
|
595
|
+
size: "compact",
|
|
596
|
+
icon: empty.icon,
|
|
597
|
+
title: empty.title,
|
|
598
|
+
description: empty.hint,
|
|
599
|
+
action: empty.action
|
|
600
|
+
}
|
|
601
|
+
) });
|
|
602
|
+
}
|
|
603
|
+
function detailId(row) {
|
|
604
|
+
return `${gridId}-detail-${rowKey(row)}`;
|
|
605
|
+
}
|
|
606
|
+
function subRow(kind, id, content, tone) {
|
|
607
|
+
return /* @__PURE__ */ jsx(
|
|
608
|
+
"div",
|
|
609
|
+
{
|
|
610
|
+
id,
|
|
611
|
+
role: "row",
|
|
612
|
+
className: cx("crewlet-data-grid__subrow", `crewlet-data-grid__subrow--${kind}`),
|
|
613
|
+
"data-tone": tone,
|
|
614
|
+
children: /* @__PURE__ */ jsx(
|
|
615
|
+
"div",
|
|
616
|
+
{
|
|
617
|
+
role: "cell",
|
|
618
|
+
"aria-colspan": drawnColumns.length,
|
|
619
|
+
className: "crewlet-data-grid__subrow-cell",
|
|
620
|
+
"data-first": leading === 0 || void 0,
|
|
621
|
+
style: { gridColumn: `${leading + 1} / -1` },
|
|
622
|
+
children: content
|
|
623
|
+
}
|
|
624
|
+
)
|
|
625
|
+
},
|
|
626
|
+
id
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
function renderCell(column, value, first, title) {
|
|
630
|
+
const align = alignOf(column);
|
|
631
|
+
return /* @__PURE__ */ jsxs(
|
|
632
|
+
"span",
|
|
633
|
+
{
|
|
634
|
+
role: "cell",
|
|
635
|
+
className: cx(
|
|
636
|
+
"crewlet-data-grid__cell",
|
|
637
|
+
align !== "left" && `crewlet-data-grid__cell--${align}`,
|
|
638
|
+
column.icon && "crewlet-data-grid__cell--icon",
|
|
639
|
+
column.shrink && "crewlet-data-grid__cell--shrink",
|
|
640
|
+
column.action && "crewlet-data-grid__cell--action",
|
|
641
|
+
column.overflow === "wrap" && "crewlet-data-grid__cell--wrap"
|
|
642
|
+
),
|
|
643
|
+
title,
|
|
644
|
+
"data-lead": column.phoneLead || void 0,
|
|
645
|
+
"data-phone-omit": column.phoneOmit || void 0,
|
|
646
|
+
"data-label": column.action ? void 0 : headerWord(column) || column.label || void 0,
|
|
647
|
+
children: [
|
|
648
|
+
first,
|
|
649
|
+
column.overflow === "truncate" && value !== null && value !== void 0 && value !== false ? (
|
|
650
|
+
// A CUT VALUE IS STILL READ WHOLE: its words on hover while it is cut.
|
|
651
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-data-grid__truncate", onMouseEnter: title === void 0 ? titleWhenCut : void 0, children: value })
|
|
652
|
+
) : value
|
|
653
|
+
]
|
|
654
|
+
},
|
|
655
|
+
column.key
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
let index = -1;
|
|
659
|
+
function renderRow(row) {
|
|
660
|
+
index += 1;
|
|
661
|
+
const at = index;
|
|
662
|
+
const key = rowKey(row);
|
|
663
|
+
const link = rowHref?.(row);
|
|
664
|
+
const marked = Boolean(isSelected?.(row));
|
|
665
|
+
const picked = Boolean(selection?.selected.has(key));
|
|
666
|
+
const tone = rowTone?.(row) ?? (isFailed?.(row) ? "danger" : void 0);
|
|
667
|
+
const rowId = `${gridId}-row-${at}`;
|
|
668
|
+
const accessory = rowAccessory?.(row);
|
|
669
|
+
const hasAccessory = accessory !== null && accessory !== void 0 && accessory !== false;
|
|
670
|
+
const open = Boolean(expansion?.isExpanded(row) && expansion.canExpand?.(row) !== false);
|
|
671
|
+
const pending = ordered && reorder?.pendingKey === key;
|
|
672
|
+
const described = hasAccessory ? `${rowId}-accessory` : void 0;
|
|
673
|
+
const overlay = link !== void 0 ? (
|
|
674
|
+
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
|
675
|
+
/* @__PURE__ */ jsx(
|
|
676
|
+
"a",
|
|
677
|
+
{
|
|
678
|
+
className: "crewlet-data-grid__row-link",
|
|
679
|
+
href: link,
|
|
680
|
+
"aria-labelledby": rowId,
|
|
681
|
+
"aria-describedby": described,
|
|
682
|
+
"aria-current": marked ? "true" : void 0,
|
|
683
|
+
onClick: (e) => onRowActivate?.(row, e),
|
|
684
|
+
...rowLinkTitle
|
|
685
|
+
}
|
|
686
|
+
)
|
|
687
|
+
) : onRowActivate ? /* @__PURE__ */ jsx(
|
|
688
|
+
"button",
|
|
689
|
+
{
|
|
690
|
+
type: "button",
|
|
691
|
+
className: "crewlet-data-grid__row-link",
|
|
692
|
+
"aria-labelledby": rowId,
|
|
693
|
+
"aria-describedby": described,
|
|
694
|
+
"aria-current": marked ? "true" : void 0,
|
|
695
|
+
onClick: (e) => onRowActivate(row, e),
|
|
696
|
+
...rowLinkTitle
|
|
697
|
+
}
|
|
698
|
+
) : null;
|
|
699
|
+
const inner = drawnColumns.map(
|
|
700
|
+
(column, i) => renderCell(column, column.cell(row), i === 0 ? overlay : null, column.title?.(row))
|
|
701
|
+
);
|
|
702
|
+
const item = ordered ? reorderBy.itemProps(key) : void 0;
|
|
703
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
704
|
+
/* @__PURE__ */ jsx(
|
|
705
|
+
"div",
|
|
706
|
+
{
|
|
707
|
+
...item,
|
|
708
|
+
id: rowId,
|
|
709
|
+
role: "row",
|
|
710
|
+
className: cx(
|
|
711
|
+
"crewlet-data-grid__row",
|
|
712
|
+
marked && "crewlet-data-grid__row--selected",
|
|
713
|
+
picked && "crewlet-data-grid__row--picked",
|
|
714
|
+
tone === "danger" && "crewlet-data-grid__row--failed",
|
|
715
|
+
cursor === at && "crewlet-data-grid__row--cursor"
|
|
716
|
+
),
|
|
717
|
+
"data-row-index": at,
|
|
718
|
+
"data-tone": tone,
|
|
719
|
+
"data-continued": hasAccessory || open || void 0,
|
|
720
|
+
"data-pending": pending || void 0,
|
|
721
|
+
"aria-busy": pending || void 0,
|
|
722
|
+
"aria-current": overlay === null && marked ? "true" : void 0,
|
|
723
|
+
children: inner
|
|
724
|
+
}
|
|
725
|
+
),
|
|
726
|
+
hasAccessory && subRow("accessory", `${rowId}-accessory`, accessory, tone),
|
|
727
|
+
open && expansion && subRow("detail", detailId(row), expansion.render(row), tone)
|
|
728
|
+
] }, key);
|
|
729
|
+
}
|
|
730
|
+
function renderSummary(summary) {
|
|
731
|
+
const first = visibleColumns[0]?.key;
|
|
732
|
+
return /* @__PURE__ */ jsx(
|
|
733
|
+
"div",
|
|
734
|
+
{
|
|
735
|
+
role: "row",
|
|
736
|
+
className: "crewlet-data-grid__row crewlet-data-grid__row--summary",
|
|
737
|
+
"data-position": summary.position ?? "bottom",
|
|
738
|
+
children: drawnColumns.map((column, i) => {
|
|
739
|
+
if (i < leading) return renderCell(column, null, null, void 0);
|
|
740
|
+
const own = summary.cells[column.key];
|
|
741
|
+
const value = own === void 0 && column.key === first ? summary.label : own;
|
|
742
|
+
return renderCell(column, value ?? null, null, void 0);
|
|
743
|
+
})
|
|
744
|
+
},
|
|
745
|
+
`summary-${summary.key}`
|
|
746
|
+
);
|
|
747
|
+
}
|
|
748
|
+
function renderBand(band) {
|
|
749
|
+
const loaded = bandRows(band).length;
|
|
750
|
+
return (
|
|
751
|
+
// A BAND IS ROWS OF THE TABLE: its head and its foot are rows of one
|
|
752
|
+
// cell each across every column, and its own box is layout alone.
|
|
753
|
+
/* @__PURE__ */ jsxs("div", { className: "crewlet-data-grid__band", role: "none", children: [
|
|
754
|
+
/* @__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: [
|
|
755
|
+
band.mark,
|
|
756
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-data-grid__truncate", onMouseEnter: titleWhenCut, children: band.label }),
|
|
757
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-data-grid__band-count", children: band.total != null && band.total !== loaded ? `${loaded} of ${band.total}` : loaded })
|
|
758
|
+
] }) }),
|
|
759
|
+
band.bands ? band.bands.map((sub) => renderBand(sub)) : sortRows(band.rows).map(renderRow),
|
|
760
|
+
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 }) })
|
|
761
|
+
] }, band.key)
|
|
762
|
+
);
|
|
763
|
+
}
|
|
764
|
+
function renderPlaceholder(at) {
|
|
765
|
+
return /* @__PURE__ */ jsx(
|
|
766
|
+
"div",
|
|
767
|
+
{
|
|
768
|
+
role: "row",
|
|
769
|
+
"aria-hidden": "true",
|
|
770
|
+
className: "crewlet-data-grid__row crewlet-data-grid__row--loading",
|
|
771
|
+
children: drawnColumns.map(
|
|
772
|
+
(column) => renderCell(
|
|
773
|
+
column,
|
|
774
|
+
column.action || column.icon ? null : /* @__PURE__ */ jsx(Skeleton, { variant: "text", rows: 1 }),
|
|
775
|
+
null,
|
|
776
|
+
void 0
|
|
777
|
+
)
|
|
778
|
+
)
|
|
779
|
+
},
|
|
780
|
+
`loading-${at}`
|
|
781
|
+
);
|
|
782
|
+
}
|
|
783
|
+
const top = summaryRows?.filter((s) => s.position === "top") ?? [];
|
|
784
|
+
const bottom = summaryRows?.filter((s) => s.position !== "top") ?? [];
|
|
785
|
+
return /* @__PURE__ */ jsxs(
|
|
786
|
+
"div",
|
|
787
|
+
{
|
|
788
|
+
ref: setWrap,
|
|
789
|
+
role: "table",
|
|
790
|
+
"aria-label": ariaLabel,
|
|
791
|
+
"aria-labelledby": ariaLabelledby,
|
|
792
|
+
"aria-busy": loading || void 0,
|
|
793
|
+
className: cx("crewlet-data-grid", className),
|
|
794
|
+
"data-phone-rows": phoneRows === "compact" ? "compact" : void 0,
|
|
795
|
+
"data-stacked": stacked || void 0,
|
|
796
|
+
"data-flush": flush || void 0,
|
|
797
|
+
"data-density": density === "compact" ? "compact" : void 0,
|
|
798
|
+
style: { gridTemplateColumns: template },
|
|
799
|
+
onPointerDown,
|
|
800
|
+
children: [
|
|
801
|
+
/* @__PURE__ */ jsx("div", { className: "crewlet-data-grid__head", role: "row", children: drawnColumns.map((column) => /* @__PURE__ */ jsx(
|
|
802
|
+
GridHeadCell,
|
|
803
|
+
{
|
|
804
|
+
column,
|
|
805
|
+
sort,
|
|
806
|
+
sortable: !ordered && sortsBy(column) && onSortChange !== void 0,
|
|
807
|
+
onSort: () => headerClick(column)
|
|
808
|
+
},
|
|
809
|
+
column.key
|
|
810
|
+
)) }),
|
|
811
|
+
/* @__PURE__ */ jsxs(
|
|
812
|
+
"div",
|
|
813
|
+
{
|
|
814
|
+
className: "crewlet-data-grid__body",
|
|
815
|
+
role: "rowgroup",
|
|
816
|
+
ref: body,
|
|
817
|
+
...ordered ? reorderBy.containerProps : void 0,
|
|
818
|
+
children: [
|
|
819
|
+
top.map(renderSummary),
|
|
820
|
+
placeholders ? Array.from({ length: Math.max(1, loadingRows) }, (_, at) => renderPlaceholder(at)) : ordered ? flat.map(renderRow) : bands ? bands.map((band) => renderBand(band)) : sortRows(rows ?? []).map(renderRow),
|
|
821
|
+
bottom.map(renderSummary)
|
|
822
|
+
]
|
|
823
|
+
}
|
|
824
|
+
),
|
|
825
|
+
/* @__PURE__ */ jsx(
|
|
826
|
+
GridFoot,
|
|
827
|
+
{
|
|
828
|
+
columns: drawnColumns.length,
|
|
829
|
+
footer,
|
|
830
|
+
dropped: droppedNames(shownColumns, dropped, text.and),
|
|
831
|
+
loadedNote,
|
|
832
|
+
onLoadMore,
|
|
833
|
+
onReset: colsRaw && onColsChange ? () => onColsChange("") : void 0,
|
|
834
|
+
labels: text
|
|
835
|
+
}
|
|
836
|
+
)
|
|
837
|
+
]
|
|
838
|
+
}
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
var drivable = [];
|
|
842
|
+
var touched = null;
|
|
843
|
+
var revision = 0;
|
|
844
|
+
var watchers = /* @__PURE__ */ new Set();
|
|
845
|
+
function announce() {
|
|
846
|
+
revision += 1;
|
|
847
|
+
for (const watcher of watchers) watcher();
|
|
848
|
+
}
|
|
849
|
+
function watch(watcher) {
|
|
850
|
+
watchers.add(watcher);
|
|
851
|
+
return () => {
|
|
852
|
+
watchers.delete(watcher);
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
function current() {
|
|
856
|
+
return revision;
|
|
857
|
+
}
|
|
858
|
+
function isDriving(id) {
|
|
859
|
+
if (touched !== null) return touched === id;
|
|
860
|
+
return drivable[0] === id;
|
|
861
|
+
}
|
|
862
|
+
function countDataGridRows(rows, bands) {
|
|
863
|
+
const inBand = (band) => band.bands ? band.bands.reduce((n, sub) => n + inBand(sub), 0) : band.rows.length;
|
|
864
|
+
return bands ? bands.reduce((n, band) => n + inBand(band), 0) : rows?.length ?? 0;
|
|
865
|
+
}
|
|
866
|
+
function useDataGridDriving(drivableNow) {
|
|
867
|
+
const id = useId();
|
|
868
|
+
useSyncExternalStore(watch, current, current);
|
|
869
|
+
useEffect(() => {
|
|
870
|
+
if (!drivableNow) return void 0;
|
|
871
|
+
drivable.push(id);
|
|
872
|
+
announce();
|
|
873
|
+
return () => {
|
|
874
|
+
const at = drivable.indexOf(id);
|
|
875
|
+
if (at >= 0) drivable.splice(at, 1);
|
|
876
|
+
if (touched === id) touched = null;
|
|
877
|
+
announce();
|
|
878
|
+
};
|
|
879
|
+
}, [id, drivableNow]);
|
|
880
|
+
const claim = useCallback(() => {
|
|
881
|
+
if (touched === id) return;
|
|
882
|
+
touched = id;
|
|
883
|
+
announce();
|
|
884
|
+
}, [id]);
|
|
885
|
+
return { driving: drivableNow && isDriving(id), claim };
|
|
886
|
+
}
|
|
887
|
+
function useAnyDataGridDriving() {
|
|
888
|
+
useSyncExternalStore(watch, current, current);
|
|
889
|
+
return drivable.length > 0;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
export { ChooserList, ColumnChooser, DATA_GRID_ICON_TRACK, DataGrid, GRID_FOOT_LABELS, GRID_ICON_TRACK, GridFoot, GridHeadCell, alignOf, columnChoicesOf, countDataGridRows, droppedNames, fitGridColumns, headerWord, nextGridSort, overrunning, parseGridSort, rowLinkTitle, sortByValue, squeezedCells, tableTrack, useAnyDataGridDriving, useDataGridDriving };
|