@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,557 @@
|
|
|
1
|
+
import { useTreeState, treeExpandable, treeLevel, treePosInSet, treeSetSize, treeItemAction, treePrevious, treeNext, treeStep } from './chunk-MY374UUD.js';
|
|
2
|
+
import { GRID_FOOT_LABELS, parseGridSort, overrunning, squeezedCells, fitGridColumns, tableTrack, GRID_ICON_TRACK, GridHeadCell, alignOf, rowLinkTitle, headerWord, GridFoot, droppedNames, nextGridSort, sortByValue } from './chunk-LIRXQOTR.js';
|
|
3
|
+
import { LayerNodeBridge } from './chunk-X4HBZSXA.js';
|
|
4
|
+
import { useMediaMatch } from './chunk-YJQXESOJ.js';
|
|
5
|
+
import { Checkbox } from './chunk-M6G7XLLP.js';
|
|
6
|
+
import { EmptyState } from './chunk-PPUR46MK.js';
|
|
7
|
+
import { IconButton } from './chunk-WDLAAZFZ.js';
|
|
8
|
+
import { LayerHost, LAYER_REPOSITION_EVENT } from './chunk-FIX72ZEC.js';
|
|
9
|
+
import { focusables } from './chunk-TUEM2XIW.js';
|
|
10
|
+
import { cx } from './chunk-ODEQTPFM.js';
|
|
11
|
+
import './TreeGrid-XZCH5WCC.css';
|
|
12
|
+
import { useRef, useState, useLayoutEffect, useEffect, useMemo, useCallback, useImperativeHandle } from 'react';
|
|
13
|
+
import { breakpoint } from '@crewlethq/tokens';
|
|
14
|
+
import { ChevronRightGlyph } from '@crewlethq/icons/glyphs';
|
|
15
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
16
|
+
|
|
17
|
+
var LABELS = {
|
|
18
|
+
...GRID_FOOT_LABELS,
|
|
19
|
+
expand: (label) => `Expand ${label}`,
|
|
20
|
+
collapse: (label) => `Collapse ${label}`
|
|
21
|
+
};
|
|
22
|
+
var NO_DROPS = [];
|
|
23
|
+
var NO_FIT = { set: "", width: 0, dropped: NO_DROPS };
|
|
24
|
+
function sortsBy(column) {
|
|
25
|
+
return !column.action && (column.sortable ?? column.sortValue !== void 0);
|
|
26
|
+
}
|
|
27
|
+
function sortTreeLevels(forest, get, desc, pinned = () => false) {
|
|
28
|
+
const level = (nodes) => {
|
|
29
|
+
const rows = nodes.filter((node) => !pinned(node.id));
|
|
30
|
+
const pins = nodes.filter((node) => pinned(node.id));
|
|
31
|
+
return [...sortByValue(rows, (node) => get(node.id), desc), ...pins].map(
|
|
32
|
+
(node) => node.children && node.children.length > 0 ? { ...node, children: level(node.children) } : node
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
return level(forest);
|
|
36
|
+
}
|
|
37
|
+
function orderOf(forest) {
|
|
38
|
+
const ids = [];
|
|
39
|
+
const walk = (node) => {
|
|
40
|
+
ids.push(node.id);
|
|
41
|
+
node.children?.forEach(walk);
|
|
42
|
+
};
|
|
43
|
+
forest.forEach(walk);
|
|
44
|
+
return ids.join("\0");
|
|
45
|
+
}
|
|
46
|
+
function controlIn(cell) {
|
|
47
|
+
return focusables(cell).find((el) => !el.closest('[aria-hidden="true"]')) ?? null;
|
|
48
|
+
}
|
|
49
|
+
var TEXT_INPUTS = /* @__PURE__ */ new Set(["text", "search", "url", "email", "tel", "password", "number"]);
|
|
50
|
+
function caretKey(target, key) {
|
|
51
|
+
const lines = target instanceof HTMLTextAreaElement || target.isContentEditable;
|
|
52
|
+
const field = lines || target instanceof HTMLInputElement && TEXT_INPUTS.has(target.type);
|
|
53
|
+
if (!field) return false;
|
|
54
|
+
if (key === "ArrowLeft" || key === "ArrowRight" || key === "Home" || key === "End") return true;
|
|
55
|
+
return lines && (key === "ArrowUp" || key === "ArrowDown");
|
|
56
|
+
}
|
|
57
|
+
function TreeGrid({
|
|
58
|
+
label,
|
|
59
|
+
columns,
|
|
60
|
+
rows: forest,
|
|
61
|
+
renderCell,
|
|
62
|
+
renderIndent,
|
|
63
|
+
cellHasControl,
|
|
64
|
+
onRowKey,
|
|
65
|
+
onRowKeyDown,
|
|
66
|
+
hasRowMenu,
|
|
67
|
+
addRow,
|
|
68
|
+
selectedId = null,
|
|
69
|
+
onSelect,
|
|
70
|
+
selection,
|
|
71
|
+
rowHref,
|
|
72
|
+
isFailed,
|
|
73
|
+
readOnly,
|
|
74
|
+
defaultExpanded,
|
|
75
|
+
expanded: held,
|
|
76
|
+
onExpandedChange,
|
|
77
|
+
sort: sortRaw = "",
|
|
78
|
+
defaultSort = "",
|
|
79
|
+
onSortChange,
|
|
80
|
+
serverSorted = false,
|
|
81
|
+
cols: colsRaw = "",
|
|
82
|
+
onColsChange,
|
|
83
|
+
empty,
|
|
84
|
+
footer,
|
|
85
|
+
loadedNote,
|
|
86
|
+
onLoadMore,
|
|
87
|
+
phoneRows,
|
|
88
|
+
flush = false,
|
|
89
|
+
headless = false,
|
|
90
|
+
layout = "scroll",
|
|
91
|
+
onWidthChange,
|
|
92
|
+
labels,
|
|
93
|
+
ref,
|
|
94
|
+
className
|
|
95
|
+
}) {
|
|
96
|
+
const text = { ...LABELS, ...labels };
|
|
97
|
+
const frame = useRef(null);
|
|
98
|
+
const gridEl = useRef(null);
|
|
99
|
+
const [width, setWidth] = useState(0);
|
|
100
|
+
const reportWidth = useRef(onWidthChange);
|
|
101
|
+
reportWidth.current = onWidthChange;
|
|
102
|
+
const measures = onWidthChange !== void 0 || phoneRows !== void 0 || columns.some((one) => one.hideBelow !== void 0 || one.drop !== void 0);
|
|
103
|
+
useLayoutEffect(() => {
|
|
104
|
+
const el = frame.current;
|
|
105
|
+
if (!measures || !el) return;
|
|
106
|
+
const read = (next) => setWidth(Math.round(next));
|
|
107
|
+
read(el.getBoundingClientRect().width);
|
|
108
|
+
if (typeof ResizeObserver !== "function") return;
|
|
109
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
110
|
+
if (entry) read(entry.contentRect.width);
|
|
111
|
+
});
|
|
112
|
+
observer.observe(el);
|
|
113
|
+
return () => observer.disconnect();
|
|
114
|
+
}, [measures]);
|
|
115
|
+
useEffect(() => {
|
|
116
|
+
if (width > 0) reportWidth.current?.(width);
|
|
117
|
+
}, [width]);
|
|
118
|
+
const shownColumns = useMemo(() => {
|
|
119
|
+
const asked = colsRaw.split(",").map((c) => c.trim()).filter(Boolean);
|
|
120
|
+
const byKey = new Map(columns.map((c) => [c.key, c]));
|
|
121
|
+
const picked = asked.map((key) => byKey.get(key)).filter((c) => !!c);
|
|
122
|
+
const set = picked.length > 0 ? picked : columns.filter((c) => !c.optional);
|
|
123
|
+
return set.filter((one) => one.hideBelow === void 0 || width <= 0 || width >= one.hideBelow);
|
|
124
|
+
}, [columns, colsRaw, width]);
|
|
125
|
+
const phone = useMediaMatch(`(width < ${breakpoint.phone})`);
|
|
126
|
+
const shownKeys = `${shownColumns.map((c) => c.key).join(",")}${phone ? "|phone" : ""}`;
|
|
127
|
+
const [fit, setFit] = useState(NO_FIT);
|
|
128
|
+
const stacked = phoneRows !== void 0 && (phone || fit.set === shownKeys && Boolean(fit.stacked));
|
|
129
|
+
const dropped = !stacked && fit.set === shownKeys ? fit.dropped : NO_DROPS;
|
|
130
|
+
const drawn = useMemo(
|
|
131
|
+
() => dropped.length === 0 ? shownColumns : shownColumns.filter((c) => !dropped.includes(c.key)),
|
|
132
|
+
[shownColumns, dropped]
|
|
133
|
+
);
|
|
134
|
+
const sort = parseGridSort(sortRaw || defaultSort);
|
|
135
|
+
const sortValue = sort && !serverSorted ? columns.find((c) => c.key === sort.key)?.sortValue : void 0;
|
|
136
|
+
const pinned = (id) => addRow?.(id) != null;
|
|
137
|
+
const sortedNow = sortValue && sort ? sortTreeLevels(forest, sortValue, sort.desc, pinned) : forest;
|
|
138
|
+
const drawnOrder = sortValue ? orderOf(sortedNow) : "";
|
|
139
|
+
const sorted = useMemo(() => sortedNow, [forest, drawnOrder]);
|
|
140
|
+
const tree = useTreeState(sorted, selectedId, { defaultExpanded, expanded: held, onExpandedChange });
|
|
141
|
+
const { model, expanded, rows, active, setActive, toggle } = tree;
|
|
142
|
+
const [column, setColumn] = useState(null);
|
|
143
|
+
const [menuFor, setMenuFor] = useState(null);
|
|
144
|
+
const current = useRef({ addRow, onSelect });
|
|
145
|
+
current.current = { addRow, onSelect };
|
|
146
|
+
const isAddRow = (id) => current.current.addRow?.(id) ?? null;
|
|
147
|
+
useLayoutEffect(() => {
|
|
148
|
+
const el = gridEl.current;
|
|
149
|
+
if (!el || width <= 0 || phone && phoneRows !== void 0) return;
|
|
150
|
+
if (!drawn.some((one) => one.drop !== void 0) && phoneRows === void 0 && fit.set === shownKeys) return;
|
|
151
|
+
const current2 = fit.set === shownKeys ? fit : { ...NO_FIT, set: shownKeys };
|
|
152
|
+
const head = el.querySelector(':scope > .crewlet-tree-grid__head > [role="row"]');
|
|
153
|
+
const overrun = !current2.stacked && overrunning(el, head);
|
|
154
|
+
const squeeze = current2.stacked ? null : squeezedCells(
|
|
155
|
+
el.clientWidth,
|
|
156
|
+
head ? [...head.children] : [],
|
|
157
|
+
[
|
|
158
|
+
...el.querySelectorAll(
|
|
159
|
+
':scope > .crewlet-tree-grid__body > [role="row"]:not(.crewlet-tree-grid__row--add)'
|
|
160
|
+
)
|
|
161
|
+
],
|
|
162
|
+
(row) => [...row.children],
|
|
163
|
+
drawn
|
|
164
|
+
);
|
|
165
|
+
const next = fitGridColumns({
|
|
166
|
+
fit: current2,
|
|
167
|
+
width: el.clientWidth,
|
|
168
|
+
overflows: overrun || squeeze !== null,
|
|
169
|
+
stack: phoneRows !== void 0 && (overrun || squeeze === "values"),
|
|
170
|
+
visible: drawn
|
|
171
|
+
});
|
|
172
|
+
if (next !== null) setFit(next);
|
|
173
|
+
}, [phone, fit, shownKeys, drawn, rows, width, phoneRows]);
|
|
174
|
+
const rowEls = useRef(/* @__PURE__ */ new Map());
|
|
175
|
+
const refs = useRef(/* @__PURE__ */ new Map());
|
|
176
|
+
const rowRef = (id) => {
|
|
177
|
+
let callback = refs.current.get(id);
|
|
178
|
+
if (!callback) {
|
|
179
|
+
callback = (el) => {
|
|
180
|
+
if (el) rowEls.current.set(id, el);
|
|
181
|
+
else rowEls.current.delete(id);
|
|
182
|
+
};
|
|
183
|
+
refs.current.set(id, callback);
|
|
184
|
+
}
|
|
185
|
+
return callback;
|
|
186
|
+
};
|
|
187
|
+
const [request, setRequest] = useState(null);
|
|
188
|
+
const focusAt = useCallback(
|
|
189
|
+
(id, col) => {
|
|
190
|
+
if (current.current.addRow?.(id) == null) current.current.onSelect?.(id);
|
|
191
|
+
setActive(id);
|
|
192
|
+
setColumn(col);
|
|
193
|
+
setRequest({ id, column: col });
|
|
194
|
+
},
|
|
195
|
+
[setActive]
|
|
196
|
+
);
|
|
197
|
+
useLayoutEffect(() => {
|
|
198
|
+
const row = request ? rowEls.current.get(request.id) : void 0;
|
|
199
|
+
if (!request || !row) return;
|
|
200
|
+
if (request.column === null) {
|
|
201
|
+
row.focus();
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const cell = row.querySelector(`[aria-colindex="${request.column}"]`);
|
|
205
|
+
const control = cell ? controlIn(cell) : null;
|
|
206
|
+
(control ?? cell ?? row).focus();
|
|
207
|
+
}, [request]);
|
|
208
|
+
const focusRef = useRef(() => {
|
|
209
|
+
});
|
|
210
|
+
focusRef.current = (id) => {
|
|
211
|
+
if (!model.parent.has(id)) return;
|
|
212
|
+
tree.open(id);
|
|
213
|
+
focusAt(id, null);
|
|
214
|
+
};
|
|
215
|
+
const { expandAll, collapseAll } = tree;
|
|
216
|
+
useImperativeHandle(ref, () => ({ focusNode: (id) => focusRef.current(id), expandAll, collapseAll }), [
|
|
217
|
+
expandAll,
|
|
218
|
+
collapseAll
|
|
219
|
+
]);
|
|
220
|
+
function follow(row, event) {
|
|
221
|
+
const link = row.querySelector(':scope > [role="gridcell"] > a.crewlet-tree-grid__row-link');
|
|
222
|
+
if (!link) return false;
|
|
223
|
+
link.dispatchEvent(
|
|
224
|
+
new window.MouseEvent("click", {
|
|
225
|
+
bubbles: true,
|
|
226
|
+
cancelable: true,
|
|
227
|
+
metaKey: event.metaKey,
|
|
228
|
+
ctrlKey: event.ctrlKey,
|
|
229
|
+
shiftKey: event.shiftKey,
|
|
230
|
+
altKey: event.altKey
|
|
231
|
+
})
|
|
232
|
+
);
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
function onKeyDownCapture(event) {
|
|
236
|
+
const target = event.target;
|
|
237
|
+
const row = target.closest("[data-tree-id]");
|
|
238
|
+
if (!row) return;
|
|
239
|
+
const id = row.getAttribute("data-tree-id");
|
|
240
|
+
const onRow = target === row;
|
|
241
|
+
const cellIndex = target.closest("[role='gridcell']")?.getAttribute("aria-colindex");
|
|
242
|
+
const col = onRow || !cellIndex ? null : Number(cellIndex);
|
|
243
|
+
const add = isAddRow(id);
|
|
244
|
+
const cells = add ? add.cells : drawn.length;
|
|
245
|
+
const handled = () => {
|
|
246
|
+
event.preventDefault();
|
|
247
|
+
event.stopPropagation();
|
|
248
|
+
};
|
|
249
|
+
if (onRow && add === null) {
|
|
250
|
+
if (onRowKeyDown?.(id, event)) {
|
|
251
|
+
handled();
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const action = treeItemAction(event);
|
|
255
|
+
if (action === "menu") {
|
|
256
|
+
if (hasRowMenu?.(id)) {
|
|
257
|
+
handled();
|
|
258
|
+
setMenuFor(id);
|
|
259
|
+
}
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (action !== null) {
|
|
263
|
+
if (onRowKey?.(id, action)) handled();
|
|
264
|
+
else if (action === "activate" && follow(row, event)) handled();
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (event.key === "Enter" && (event.metaKey || event.ctrlKey) && !event.altKey && follow(row, event)) {
|
|
268
|
+
handled();
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (event.ctrlKey || event.metaKey || event.altKey) return;
|
|
273
|
+
const sameColumn = (next) => {
|
|
274
|
+
if (next === null) return;
|
|
275
|
+
const other = isAddRow(next);
|
|
276
|
+
const count = other ? other.cells : drawn.length;
|
|
277
|
+
focusAt(next, col === null ? null : Math.min(col, count));
|
|
278
|
+
};
|
|
279
|
+
if (col !== null && caretKey(target, event.key)) return;
|
|
280
|
+
if (col !== null) {
|
|
281
|
+
switch (event.key) {
|
|
282
|
+
case "ArrowRight":
|
|
283
|
+
handled();
|
|
284
|
+
if (col < cells) focusAt(id, col + 1);
|
|
285
|
+
return;
|
|
286
|
+
case "ArrowLeft":
|
|
287
|
+
handled();
|
|
288
|
+
focusAt(id, col > 1 ? col - 1 : null);
|
|
289
|
+
return;
|
|
290
|
+
case "Home":
|
|
291
|
+
handled();
|
|
292
|
+
focusAt(id, 1);
|
|
293
|
+
return;
|
|
294
|
+
case "End":
|
|
295
|
+
handled();
|
|
296
|
+
focusAt(id, cells);
|
|
297
|
+
return;
|
|
298
|
+
case "ArrowDown":
|
|
299
|
+
handled();
|
|
300
|
+
sameColumn(treeNext(model, expanded, id));
|
|
301
|
+
return;
|
|
302
|
+
case "ArrowUp":
|
|
303
|
+
handled();
|
|
304
|
+
sameColumn(treePrevious(model, expanded, id));
|
|
305
|
+
return;
|
|
306
|
+
default:
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (event.key === "ArrowRight" && !(treeExpandable(model, id) && !expanded.has(id))) {
|
|
311
|
+
handled();
|
|
312
|
+
focusAt(id, 1);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
if (add !== null && event.key === "Enter") {
|
|
316
|
+
handled();
|
|
317
|
+
focusAt(id, 1);
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
const step = treeStep(tree, id, event);
|
|
321
|
+
if (step === void 0) return;
|
|
322
|
+
handled();
|
|
323
|
+
if (step === null) return;
|
|
324
|
+
if ("toggle" in step) toggle(step.toggle);
|
|
325
|
+
else focusAt(step.focus, null);
|
|
326
|
+
}
|
|
327
|
+
const [layer, setLayer] = useState(null);
|
|
328
|
+
const onScroll = () => layer?.dispatchEvent(new CustomEvent(LAYER_REPOSITION_EVENT));
|
|
329
|
+
const stop = (id, col) => id === active && column === col;
|
|
330
|
+
const grid = {
|
|
331
|
+
expanded: (id) => expanded.has(id),
|
|
332
|
+
expandable: (id) => treeExpandable(model, id),
|
|
333
|
+
toggle,
|
|
334
|
+
tabStop: stop,
|
|
335
|
+
opened: (id, col) => {
|
|
336
|
+
setActive(id);
|
|
337
|
+
setColumn(col);
|
|
338
|
+
},
|
|
339
|
+
press: (id) => ({
|
|
340
|
+
onMouseDown: (event) => {
|
|
341
|
+
event.preventDefault();
|
|
342
|
+
focusAt(id, null);
|
|
343
|
+
}
|
|
344
|
+
}),
|
|
345
|
+
menuOpen: (id) => menuFor === id,
|
|
346
|
+
setMenuOpen: (id, open) => setMenuFor((was) => open ? id : was === id ? null : was),
|
|
347
|
+
columnKey: (col) => drawn[col - 1]?.key,
|
|
348
|
+
shown: (key) => drawn.some((one) => one.key === key),
|
|
349
|
+
tree: model
|
|
350
|
+
};
|
|
351
|
+
const hasControl = (id, col, key) => col === 1 && selection !== void 0 && selection.checked(id) !== null || (cellHasControl?.(id, col, key) ?? false);
|
|
352
|
+
function headerClick(one) {
|
|
353
|
+
if (!sortsBy(one) || !onSortChange) return;
|
|
354
|
+
onSortChange(nextGridSort(one.key, sortRaw, defaultSort));
|
|
355
|
+
}
|
|
356
|
+
const template = drawn.map((one) => tableTrack({ ...one, width: one.width ?? (one.icon ? GRID_ICON_TRACK : void 0) })).join(" ");
|
|
357
|
+
const frameClass = cx(
|
|
358
|
+
"crewlet-tree-grid",
|
|
359
|
+
headless && "crewlet-tree-grid--headless",
|
|
360
|
+
layout === "container" && "crewlet-tree-grid--container",
|
|
361
|
+
className
|
|
362
|
+
);
|
|
363
|
+
if (forest.length === 0 && empty) {
|
|
364
|
+
return /* @__PURE__ */ jsx("div", { ref: frame, className: frameClass, "data-flush": flush || void 0, children: /* @__PURE__ */ jsx("div", { className: "crewlet-tree-grid__scroller", children: /* @__PURE__ */ jsx(
|
|
365
|
+
EmptyState,
|
|
366
|
+
{
|
|
367
|
+
size: "compact",
|
|
368
|
+
icon: empty.icon,
|
|
369
|
+
title: empty.title,
|
|
370
|
+
description: empty.hint,
|
|
371
|
+
action: empty.action
|
|
372
|
+
}
|
|
373
|
+
) }) });
|
|
374
|
+
}
|
|
375
|
+
return /* @__PURE__ */ jsx(
|
|
376
|
+
"div",
|
|
377
|
+
{
|
|
378
|
+
ref: frame,
|
|
379
|
+
className: frameClass,
|
|
380
|
+
"data-flush": flush || void 0,
|
|
381
|
+
"data-stacked": stacked || void 0,
|
|
382
|
+
"data-phone-rows": stacked && phoneRows === "compact" ? "compact" : void 0,
|
|
383
|
+
children: /* @__PURE__ */ jsxs(LayerHost, { className: "crewlet-tree-grid__layer", children: [
|
|
384
|
+
/* @__PURE__ */ jsxs("div", { className: "crewlet-tree-grid__scroller", onScroll, children: [
|
|
385
|
+
/* @__PURE__ */ jsxs(
|
|
386
|
+
"div",
|
|
387
|
+
{
|
|
388
|
+
ref: gridEl,
|
|
389
|
+
role: "treegrid",
|
|
390
|
+
"aria-label": label,
|
|
391
|
+
"aria-colcount": drawn.length,
|
|
392
|
+
"aria-readonly": readOnly || void 0,
|
|
393
|
+
className: "crewlet-tree-grid__grid",
|
|
394
|
+
style: { "--crewlet-tree-grid-columns": template },
|
|
395
|
+
onKeyDownCapture,
|
|
396
|
+
children: [
|
|
397
|
+
/* @__PURE__ */ jsx("div", { role: "rowgroup", className: "crewlet-tree-grid__head", children: /* @__PURE__ */ jsx("div", { role: "row", className: "crewlet-tree-grid__row", children: drawn.map((one, index) => /* @__PURE__ */ jsx(
|
|
398
|
+
GridHeadCell,
|
|
399
|
+
{
|
|
400
|
+
column: one,
|
|
401
|
+
colIndex: index + 1,
|
|
402
|
+
sort,
|
|
403
|
+
sortable: sortsBy(one) && onSortChange !== void 0,
|
|
404
|
+
onSort: () => headerClick(one),
|
|
405
|
+
hidden: one.headerHidden || one.action
|
|
406
|
+
},
|
|
407
|
+
one.key
|
|
408
|
+
)) }) }),
|
|
409
|
+
/* @__PURE__ */ jsx("div", { role: "rowgroup", className: "crewlet-tree-grid__body", children: rows.map((id) => {
|
|
410
|
+
const add = isAddRow(id);
|
|
411
|
+
const cells = add ? add.cells : drawn.length;
|
|
412
|
+
const expandable = treeExpandable(model, id);
|
|
413
|
+
const open = expanded.has(id);
|
|
414
|
+
const name = model.label.get(id) ?? "";
|
|
415
|
+
const href = add ? void 0 : rowHref?.(id);
|
|
416
|
+
return (
|
|
417
|
+
/* The row's keys are the GRID's, captured at the treegrid so
|
|
418
|
+
one handler serves every row and reaches a cell's control
|
|
419
|
+
first. A listener on the row itself would be a second
|
|
420
|
+
place for them to live. */
|
|
421
|
+
/* eslint-disable-next-line jsx-a11y/click-events-have-key-events -- see above */
|
|
422
|
+
/* @__PURE__ */ jsx(
|
|
423
|
+
"div",
|
|
424
|
+
{
|
|
425
|
+
role: "row",
|
|
426
|
+
"data-tree-id": id,
|
|
427
|
+
ref: rowRef(id),
|
|
428
|
+
tabIndex: id === active && column === null ? 0 : -1,
|
|
429
|
+
"aria-level": treeLevel(model, id),
|
|
430
|
+
"aria-setsize": treeSetSize(model, id),
|
|
431
|
+
"aria-posinset": treePosInSet(model, id),
|
|
432
|
+
"aria-expanded": expandable ? open : void 0,
|
|
433
|
+
"aria-selected": add ? void 0 : id === selectedId,
|
|
434
|
+
"aria-label": add ? add.label : void 0,
|
|
435
|
+
className: cx("crewlet-tree-grid__row", add && "crewlet-tree-grid__row--add"),
|
|
436
|
+
"data-linked": href !== void 0 || void 0,
|
|
437
|
+
"data-failed": !add && isFailed?.(id) || void 0,
|
|
438
|
+
style: { "--crewlet-tree-grid-depth": treeLevel(model, id) - 1 },
|
|
439
|
+
onClick: (event) => {
|
|
440
|
+
if (!event.currentTarget.contains(event.target)) return;
|
|
441
|
+
if (event.target.closest("button, input, label, [role='menu']")) return;
|
|
442
|
+
focusAt(id, null);
|
|
443
|
+
},
|
|
444
|
+
children: Array.from({ length: cells }, (_, index) => {
|
|
445
|
+
const col = index + 1;
|
|
446
|
+
const one = add ? void 0 : drawn[index];
|
|
447
|
+
const align = one ? alignOf(one) : "left";
|
|
448
|
+
return /* @__PURE__ */ jsxs(
|
|
449
|
+
"div",
|
|
450
|
+
{
|
|
451
|
+
role: "gridcell",
|
|
452
|
+
"aria-colindex": col,
|
|
453
|
+
tabIndex: stop(id, col) && !hasControl(id, col, drawn[col - 1]?.key ?? "") ? 0 : -1,
|
|
454
|
+
"data-size": one?.size === "sm" ? "sm" : void 0,
|
|
455
|
+
"data-label": one && !one.action && col > 1 ? headerWord(one) || one.label || void 0 : void 0,
|
|
456
|
+
className: cx(
|
|
457
|
+
"crewlet-tree-grid__cell",
|
|
458
|
+
align !== "left" && `crewlet-tree-grid__cell--${align}`,
|
|
459
|
+
one?.icon && "crewlet-tree-grid__cell--icon",
|
|
460
|
+
one?.shrink && "crewlet-tree-grid__cell--shrink",
|
|
461
|
+
one?.action && "crewlet-tree-grid__cell--action"
|
|
462
|
+
),
|
|
463
|
+
children: [
|
|
464
|
+
col === 1 && href !== void 0 && /* THE ROW'S LINK, STRETCHED OVER IT, for the pointer:
|
|
465
|
+
a real href, so a new tab and copying it work. The
|
|
466
|
+
row is the keyboard's and the reader's way in (Enter
|
|
467
|
+
follows this), so the link is hidden from both. */
|
|
468
|
+
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
|
469
|
+
/* @__PURE__ */ jsx(
|
|
470
|
+
"a",
|
|
471
|
+
{
|
|
472
|
+
className: "crewlet-tree-grid__row-link",
|
|
473
|
+
href,
|
|
474
|
+
tabIndex: -1,
|
|
475
|
+
"aria-hidden": "true",
|
|
476
|
+
...rowLinkTitle
|
|
477
|
+
}
|
|
478
|
+
),
|
|
479
|
+
col === 1 && /* THE PRESS LANDS ON THE ROW. The chevron is a
|
|
480
|
+
pointer-only control hidden from assistive
|
|
481
|
+
technology (the keyboard opens and closes a row
|
|
482
|
+
with Right and Left), and focus inside a hidden
|
|
483
|
+
subtree is focus nowhere, so the press is stopped
|
|
484
|
+
from focusing it and the row takes the focus. */
|
|
485
|
+
/* @__PURE__ */ jsx(
|
|
486
|
+
"span",
|
|
487
|
+
{
|
|
488
|
+
className: "crewlet-tree-grid__toggle",
|
|
489
|
+
"data-open": open ? "" : void 0,
|
|
490
|
+
"aria-hidden": "true",
|
|
491
|
+
...grid.press(id),
|
|
492
|
+
children: expandable && /* @__PURE__ */ jsx(
|
|
493
|
+
IconButton,
|
|
494
|
+
{
|
|
495
|
+
size: "sm",
|
|
496
|
+
label: open ? text.collapse(name) : text.expand(name),
|
|
497
|
+
icon: /* @__PURE__ */ jsx(ChevronRightGlyph, {}),
|
|
498
|
+
tabIndex: -1,
|
|
499
|
+
onClick: () => toggle(id)
|
|
500
|
+
}
|
|
501
|
+
)
|
|
502
|
+
}
|
|
503
|
+
),
|
|
504
|
+
col === 1 && renderIndent?.(id, grid),
|
|
505
|
+
col === 1 && selection && add === null && /* @__PURE__ */ jsx(TreeGridSelect, { id, selection, context: grid }),
|
|
506
|
+
renderCell(id, col, grid)
|
|
507
|
+
]
|
|
508
|
+
},
|
|
509
|
+
col
|
|
510
|
+
);
|
|
511
|
+
})
|
|
512
|
+
},
|
|
513
|
+
id
|
|
514
|
+
)
|
|
515
|
+
);
|
|
516
|
+
}) })
|
|
517
|
+
]
|
|
518
|
+
}
|
|
519
|
+
),
|
|
520
|
+
/* @__PURE__ */ jsx(
|
|
521
|
+
GridFoot,
|
|
522
|
+
{
|
|
523
|
+
footer,
|
|
524
|
+
dropped: droppedNames(shownColumns, dropped, text.and),
|
|
525
|
+
loadedNote,
|
|
526
|
+
onLoadMore,
|
|
527
|
+
onReset: colsRaw && onColsChange ? () => onColsChange("") : void 0,
|
|
528
|
+
labels: text
|
|
529
|
+
}
|
|
530
|
+
)
|
|
531
|
+
] }),
|
|
532
|
+
/* @__PURE__ */ jsx(LayerNodeBridge, { onNode: setLayer })
|
|
533
|
+
] })
|
|
534
|
+
}
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
function TreeGridSelect({
|
|
538
|
+
id,
|
|
539
|
+
selection,
|
|
540
|
+
context
|
|
541
|
+
}) {
|
|
542
|
+
const checked = selection.checked(id);
|
|
543
|
+
return /* @__PURE__ */ jsx("span", { className: "crewlet-tree-grid__select", children: checked !== null && /* @__PURE__ */ jsx(
|
|
544
|
+
Checkbox,
|
|
545
|
+
{
|
|
546
|
+
hideLabel: true,
|
|
547
|
+
label: selection.label(id),
|
|
548
|
+
checked: checked === true,
|
|
549
|
+
indeterminate: checked === "mixed",
|
|
550
|
+
tabIndex: context.tabStop(id, 1) ? 0 : -1,
|
|
551
|
+
onClick: () => context.opened(id, 1),
|
|
552
|
+
onCheckedChange: (next) => selection.onCheckedChange(id, next)
|
|
553
|
+
}
|
|
554
|
+
) });
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
export { TreeGrid };
|