@crisp-ui-kit/crisp 0.54.8 → 0.54.9
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/board.css +32 -8
- package/dist/board.layered.css +32 -8
- package/dist/cjs/components/contextmenu/contextmenu.js +2 -2
- package/dist/cjs/components/contextmenu/contextmenu.recipe.js +24 -0
- package/dist/cjs/components/datatable/datatable.js +541 -51
- package/dist/cjs/components/datatable/datatable.recipe.js +61 -3
- package/dist/cjs/components/dialog/dialog.js +65 -1
- package/dist/cjs/components/tabletoolbar/tabletoolbar.chrome.js +37 -2
- package/dist/cjs/components/tabletoolbar/tabletoolbar.js +148 -15
- package/dist/cjs/components/tabletoolbar/tabletoolbar.recipe.js +35 -1
- package/dist/cjs/product/board/board.js +62 -28
- package/dist/cjs/product/board/board.recipe.js +42 -2
- package/dist/cjs/product/comments/comments.js +11 -2
- package/dist/cjs/product/comments/comments.recipe.js +14 -4
- package/dist/cjs/product/recordstable/recordstable.js +1 -17
- package/dist/cjs/product/savedviews/savedviews.js +55 -24
- package/dist/cjs/product/savedviews/savedviews.recipe.js +27 -0
- package/dist/comments.css +14 -4
- package/dist/comments.layered.css +14 -4
- package/dist/contextmenu.css +24 -0
- package/dist/contextmenu.layered.css +24 -0
- package/dist/datatable.css +103 -77
- package/dist/datatable.layered.css +103 -77
- package/dist/esm/components/contextmenu/contextmenu.js +2 -2
- package/dist/esm/components/contextmenu/contextmenu.recipe.js +24 -0
- package/dist/esm/components/datatable/datatable.js +541 -52
- package/dist/esm/components/datatable/datatable.recipe.js +62 -4
- package/dist/esm/components/dialog/dialog.js +65 -1
- package/dist/esm/components/tabletoolbar/tabletoolbar.chrome.js +37 -2
- package/dist/esm/components/tabletoolbar/tabletoolbar.js +149 -16
- package/dist/esm/components/tabletoolbar/tabletoolbar.recipe.js +37 -3
- package/dist/esm/product/board/board.js +63 -29
- package/dist/esm/product/board/board.recipe.js +42 -2
- package/dist/esm/product/comments/comments.js +12 -3
- package/dist/esm/product/comments/comments.recipe.js +14 -4
- package/dist/esm/product/recordstable/recordstable.js +2 -18
- package/dist/esm/product/savedviews/savedviews.js +57 -26
- package/dist/esm/product/savedviews/savedviews.recipe.js +27 -0
- package/dist/recordstable.css +33 -31
- package/dist/recordstable.layered.css +33 -31
- package/dist/savedviews.css +27 -0
- package/dist/savedviews.layered.css +27 -0
- package/dist/styles.css +266 -124
- package/dist/styles.layered.css +266 -124
- package/dist/tabletoolbar.css +33 -4
- package/dist/tabletoolbar.layered.css +33 -4
- package/dist/types/components/contextmenu/contextmenu.d.ts +8 -1
- package/dist/types/components/datatable/datatable.d.ts +90 -2
- package/dist/types/components/tabletoolbar/tabletoolbar.d.ts +72 -2
- package/dist/types/product/board/board.d.ts +48 -2
- package/dist/types/product/comments/comments.d.ts +6 -1
- package/dist/types/product/recordstable/recordstable.d.ts +0 -1
- package/dist/types/product/savedviews/savedviews.d.ts +45 -8
- package/package.json +1 -1
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { ArrowDown, ArrowUp, Check, ChevronsUpDown, CircleUserRound, GripVertical, Lock, Plus, Search, SlidersHorizontal, } from "lucide-react";
|
|
2
|
+
import { ArrowDown, ArrowUp, Check, ChevronsUpDown, CircleUserRound, ClipboardPaste, Copy, GripVertical, History, Lock, PanelRight, Plus, Search, SlidersHorizontal, X, } from "lucide-react";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { cellDatePrecision, formatCellDate, isRtlElement, parseCellDate, useCrispMessage, useCrispMessages, } from "../../core/index.js";
|
|
5
|
+
// crisp/#601 supersession: a deliberate exception to "DS atoms stay
|
|
6
|
+
// generic; product components compose them" (AUTHORING.md) -- the row's
|
|
7
|
+
// own comment affordance is `CommentCountBadge` (product/comments, #625),
|
|
8
|
+
// already correctly built and measured for the dot/hover-count states this
|
|
9
|
+
// plain icon path can't express on its own. Reaching into `product/` from
|
|
10
|
+
// `components/` runs backwards from every other import in this file; it's
|
|
11
|
+
// scoped to this one component, not a precedent for the rest of DataTable.
|
|
12
|
+
import { CommentCountBadge } from "../../product/comments/index.js";
|
|
5
13
|
import { Avatar } from "../avatar/index.js";
|
|
6
14
|
import { Checkbox } from "../checkbox/index.js";
|
|
15
|
+
import { ColumnCalc } from "../columncalc/index.js";
|
|
16
|
+
import { ContextMenu } from "../contextmenu/index.js";
|
|
7
17
|
import { Menu, MenuItem } from "../menu/index.js";
|
|
8
18
|
import { Select } from "../select/index.js";
|
|
9
19
|
import { Spinner } from "../spinner/index.js";
|
|
@@ -18,6 +28,35 @@ import { datatableRecipe } from "./datatable.recipe.js";
|
|
|
18
28
|
export function isLabelTruncated(el) {
|
|
19
29
|
return el.scrollWidth > el.clientWidth;
|
|
20
30
|
}
|
|
31
|
+
// #731: the pure resequencing behind both the controlled `columnOrder` prop
|
|
32
|
+
// and the drag/Move-left-right mutations that produce one -- exported so the
|
|
33
|
+
// "does this actually reorder, and does it survive a stale/unknown key"
|
|
34
|
+
// logic can be mutation-tested without mounting the table. Every key in
|
|
35
|
+
// `order` that matches a real column is placed first, in `order`'s own
|
|
36
|
+
// sequence; every column NOT named in `order` (a brand-new column a
|
|
37
|
+
// consumer's persisted order hasn't caught up to yet) keeps its relative
|
|
38
|
+
// position at the end, in `cols`' own order -- so a column can never be
|
|
39
|
+
// dropped or duplicated by this, only resequenced. An `order` entry with no
|
|
40
|
+
// matching column (one that was removed, or a stale value from a saved
|
|
41
|
+
// view) is silently skipped rather than throwing.
|
|
42
|
+
export function reorderColumns(cols, order) {
|
|
43
|
+
if (!order || order.length === 0)
|
|
44
|
+
return cols;
|
|
45
|
+
const byKey = new Map(cols.map((c) => [c.key, c]));
|
|
46
|
+
const seen = new Set();
|
|
47
|
+
const ordered = [];
|
|
48
|
+
for (const key of order) {
|
|
49
|
+
const c = byKey.get(key);
|
|
50
|
+
if (c && !seen.has(key)) {
|
|
51
|
+
ordered.push(c);
|
|
52
|
+
seen.add(key);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
for (const c of cols)
|
|
56
|
+
if (!seen.has(c.key))
|
|
57
|
+
ordered.push(c);
|
|
58
|
+
return ordered;
|
|
59
|
+
}
|
|
21
60
|
/**
|
|
22
61
|
* The header label span: a `Tooltip` (full text, `asChild` so the wrapper
|
|
23
62
|
* never displaces the ellipsis CSS the span already carries -- see
|
|
@@ -223,7 +262,7 @@ function formatCell(type, v, symbol, locale = "en-US") {
|
|
|
223
262
|
// silently drop the cell's data. Each branch decides for itself where a
|
|
224
263
|
// display string belongs -- as an entity's name, a status' label -- while the
|
|
225
264
|
// raw value keeps driving structure and tone.
|
|
226
|
-
function renderTyped(col, value, avatarTone, row, display, locale = "en-US") {
|
|
265
|
+
function renderTyped(col, value, avatarTone, row, display, locale = "en-US", openPreviewLabel = "Open preview", rowHovered = false) {
|
|
227
266
|
// Attio's own empty cell is genuinely blank -- no placeholder character at
|
|
228
267
|
// all, for any column type (#412).
|
|
229
268
|
const empty = null;
|
|
@@ -242,7 +281,10 @@ function renderTyped(col, value, avatarTone, row, display, locale = "en-US") {
|
|
|
242
281
|
// at a DIFFERENT record than the row itself (#501).
|
|
243
282
|
ev.stopPropagation();
|
|
244
283
|
col.onEntityClick?.(row);
|
|
245
|
-
}, children: e.name })) : (_jsx("span", { className: "crisp-datatable-entity-name", children: e.name }))
|
|
284
|
+
}, children: e.name })) : (_jsx("span", { className: "crisp-datatable-entity-name", children: e.name })), col.onOpenComments ? (_jsx("span", { className: "crisp-datatable-entity-actions", children: _jsx(CommentCountBadge, { count: col.commentCount?.(row) ?? 0, hovered: rowHovered, onOpen: () => col.onOpenComments?.(row), onOpenPreview: col.onOpenPreview ? () => col.onOpenPreview?.(row) : undefined, previewLabel: openPreviewLabel }) })) : (col.onOpenPreview && (_jsx("span", { className: "crisp-datatable-entity-actions", children: _jsx("button", { type: "button", className: "crisp-datatable-entity-action", "aria-label": openPreviewLabel, onClick: (ev) => {
|
|
285
|
+
ev.stopPropagation();
|
|
286
|
+
col.onOpenPreview?.(row);
|
|
287
|
+
}, children: _jsx(PanelRight, { "data-rtl-flip": "", size: 16, strokeWidth: 1.75, "aria-hidden": "true" }) }) })))] }));
|
|
246
288
|
}
|
|
247
289
|
case "tags": {
|
|
248
290
|
// asking for a format on a tag column means "render it your way" -- show
|
|
@@ -415,7 +457,7 @@ function DataReferenceEditor({ col, value, isPending, onCommit, onCancel, }) {
|
|
|
415
457
|
onCommit(v);
|
|
416
458
|
} }) }));
|
|
417
459
|
}
|
|
418
|
-
export function DataTable({ columns: columnsProp, data, selectable = false, selectedIds, onSelectionChange, selectAllLabel: selectAllLabelProp, selectRowLabel = (row) => `Select row ${row.id}`, selectionAnnouncement, columnMenu = false, onColumnsChange, groupBy, onRowsReorder, error, sort: sortProp, defaultSort, onSortChange, filterable = false, searchPlaceholder: searchPlaceholderProp, searchLabel: searchLabelProp, onEdit, stickyFirst = true, stickyLast = false, scrollProps, locale: localeProp, avatarTone = "brand", surface, interactive = false, onRowClick, onAddRow, addRowLabel: addRowLabelProp, empty: emptyProp, showCount = true, countLabel, toolbar, height, className, reorderRowLabel: reorderRowLabelProp, sortAscendingLabel: sortAscendingLabelProp, sortDescendingLabel: sortDescendingLabelProp, moveColumnLeftLabel: moveColumnLeftLabelProp, moveColumnRightLabel: moveColumnRightLabelProp, editColumnLabel: editColumnLabelProp, hideColumnLabel: hideColumnLabelProp, renameColumnLabel: renameColumnLabelProp, viewSettingsLabel: viewSettingsLabelProp, columnsGroupLabel: columnsGroupLabelProp, ...rest }) {
|
|
460
|
+
export function DataTable({ columns: columnsProp, data, selectable = false, selectedIds, onSelectionChange, selectAllLabel: selectAllLabelProp, selectRowLabel = (row) => `Select row ${row.id}`, selectionAnnouncement, columnMenu = false, onColumnsChange, columnOrder, onColumnOrderChange, groupBy, onRowsReorder, error, sort: sortProp, defaultSort, onSortChange, filterable = false, searchPlaceholder: searchPlaceholderProp, searchLabel: searchLabelProp, onEdit, onViewEditHistory, stickyFirst = true, stickyLast = false, scrollProps, locale: localeProp, avatarTone = "brand", surface, interactive = false, onRowClick, onAddRow, addRowLabel: addRowLabelProp, empty: emptyProp, showCount = true, countLabel, toolbar, height, className, reorderRowLabel: reorderRowLabelProp, openPreviewLabel: openPreviewLabelProp, sortAscendingLabel: sortAscendingLabelProp, sortDescendingLabel: sortDescendingLabelProp, moveColumnLeftLabel: moveColumnLeftLabelProp, moveColumnRightLabel: moveColumnRightLabelProp, editColumnLabel: editColumnLabelProp, hideColumnLabel: hideColumnLabelProp, renameColumnLabel: renameColumnLabelProp, viewSettingsLabel: viewSettingsLabelProp, columnsGroupLabel: columnsGroupLabelProp, cellMenuLabel: cellMenuLabelProp, copyLabel: copyLabelProp, pasteLabel: pasteLabelProp, viewEditHistoryLabel: viewEditHistoryLabelProp, clearValueLabel: clearValueLabelProp, ...rest }) {
|
|
419
461
|
// crisp/#471: same resolution order as TableToolbar's own — an explicit
|
|
420
462
|
// prop wins, then the provider's translation of the built-in English
|
|
421
463
|
// default, then that default itself with no provider in the tree.
|
|
@@ -432,6 +474,7 @@ export function DataTable({ columns: columnsProp, data, selectable = false, sele
|
|
|
432
474
|
// wants shown); only the built-in string default translates.
|
|
433
475
|
const empty = emptyProp ?? crispMessages["No results."] ?? "No results.";
|
|
434
476
|
const reorderRowLabel = useCrispMessage(reorderRowLabelProp, "Reorder row");
|
|
477
|
+
const openPreviewLabel = useCrispMessage(openPreviewLabelProp, "Open preview");
|
|
435
478
|
const sortAscendingLabel = useCrispMessage(sortAscendingLabelProp, "Sort ascending");
|
|
436
479
|
const sortDescendingLabel = useCrispMessage(sortDescendingLabelProp, "Sort descending");
|
|
437
480
|
const moveColumnLeftLabel = useCrispMessage(moveColumnLeftLabelProp, "Move left");
|
|
@@ -441,6 +484,11 @@ export function DataTable({ columns: columnsProp, data, selectable = false, sele
|
|
|
441
484
|
const renameColumnLabel = useCrispMessage(renameColumnLabelProp, "Rename column");
|
|
442
485
|
const viewSettingsLabel = useCrispMessage(viewSettingsLabelProp, "View settings");
|
|
443
486
|
const columnsGroupLabel = useCrispMessage(columnsGroupLabelProp, "Columns");
|
|
487
|
+
const cellMenuLabel = useCrispMessage(cellMenuLabelProp, "Cell options");
|
|
488
|
+
const copyLabel = useCrispMessage(copyLabelProp, "Copy");
|
|
489
|
+
const pasteLabel = useCrispMessage(pasteLabelProp, "Paste");
|
|
490
|
+
const viewEditHistoryLabel = useCrispMessage(viewEditHistoryLabelProp, "View edit history");
|
|
491
|
+
const clearValueLabel = useCrispMessage(clearValueLabelProp, "Clear value");
|
|
444
492
|
// countLabel/selectionAnnouncement stay formatter props, same escape hatch
|
|
445
493
|
// as TableToolbar's sortTriggerLabel — word order and pluralisation rules
|
|
446
494
|
// differ too much across languages for a template. Their BUILT-IN default
|
|
@@ -469,14 +517,32 @@ export function DataTable({ columns: columnsProp, data, selectable = false, sele
|
|
|
469
517
|
// menu mutates this copy and reports upward via `onColumnsChange`.
|
|
470
518
|
const [internalCols, setInternalCols] = React.useState(columnsProp);
|
|
471
519
|
React.useEffect(() => setInternalCols(columnsProp), [columnsProp]);
|
|
472
|
-
/** Every column, hidden ones included — what the column manager lists.
|
|
473
|
-
|
|
520
|
+
/** Every column, hidden ones included — what the column manager lists.
|
|
521
|
+
* `columnOrder`, controlled or not, is the one source of truth for ORDER;
|
|
522
|
+
* `internalCols` still carries each column's hidden/renamed state, so
|
|
523
|
+
* resequencing it here never loses either. */
|
|
524
|
+
const allColumns = React.useMemo(() => reorderColumns(internalCols, columnOrder), [internalCols, columnOrder]);
|
|
474
525
|
/** What the grid actually renders. */
|
|
475
|
-
const columns = React.useMemo(() =>
|
|
526
|
+
const columns = React.useMemo(() => allColumns.filter((c) => !c.hidden), [allColumns]);
|
|
476
527
|
const applyColumns = React.useCallback((next) => {
|
|
477
528
|
setInternalCols(next);
|
|
478
529
|
onColumnsChange?.(next);
|
|
479
530
|
}, [onColumnsChange]);
|
|
531
|
+
// Reordering specifically (a header drag, or the menu's Move left/right) —
|
|
532
|
+
// separate from `applyColumns` above (hide/rename, which never touch
|
|
533
|
+
// order) because this is the one path that also owns `columnOrder`:
|
|
534
|
+
// uncontrolled, it seeds `internalCols`' own order same as any other
|
|
535
|
+
// mutation; controlled, the next render's `allColumns` re-derives order
|
|
536
|
+
// from the (now stale, until the consumer updates it) `columnOrder` prop
|
|
537
|
+
// instead — the same contract `sort`/`selectedIds` already use — so this
|
|
538
|
+
// deliberately does NOT touch `internalCols`' order when controlled.
|
|
539
|
+
const applyOrder = React.useCallback((nextOrder) => {
|
|
540
|
+
const next = reorderColumns(allColumns, nextOrder);
|
|
541
|
+
if (columnOrder === undefined)
|
|
542
|
+
setInternalCols(next);
|
|
543
|
+
onColumnsChange?.(next);
|
|
544
|
+
onColumnOrderChange?.(next.map((c) => c.key));
|
|
545
|
+
}, [allColumns, columnOrder, onColumnsChange, onColumnOrderChange]);
|
|
480
546
|
const moveColumn = React.useCallback((key, dir) => {
|
|
481
547
|
const i = allColumns.findIndex((c) => c.key === key);
|
|
482
548
|
const j = i + dir;
|
|
@@ -484,14 +550,44 @@ export function DataTable({ columns: columnsProp, data, selectable = false, sele
|
|
|
484
550
|
return;
|
|
485
551
|
const next = [...allColumns];
|
|
486
552
|
[next[i], next[j]] = [next[j], next[i]];
|
|
487
|
-
|
|
488
|
-
}, [allColumns,
|
|
553
|
+
applyOrder(next.map((c) => c.key));
|
|
554
|
+
}, [allColumns, applyOrder]);
|
|
489
555
|
const hideColumn = React.useCallback((key) => applyColumns(allColumns.map((c) => (c.key === key ? { ...c, hidden: true } : c))), [allColumns, applyColumns]);
|
|
490
556
|
const renameColumn = React.useCallback((key, header) => applyColumns(allColumns.map((c) => (c.key === key ? { ...c, header } : c))), [allColumns, applyColumns]);
|
|
491
557
|
const [renaming, setRenaming] = React.useState(null);
|
|
492
558
|
const showColumn = React.useCallback((key) => applyColumns(allColumns.map((c) => (c.key === key ? { ...c, hidden: false } : c))), [allColumns, applyColumns]);
|
|
493
559
|
const [selCell, setSelCell] = React.useState(null);
|
|
560
|
+
// crisp/#625/#601 supersession: `CommentCountBadge` branches its own
|
|
561
|
+
// render (a plain dot vs. the icon+count row) on a `hovered` boolean it
|
|
562
|
+
// takes as a prop -- unlike the plain #601 icons this replaces, which
|
|
563
|
+
// reveal on pure `tr:hover` CSS, the badge has no hover detection of its
|
|
564
|
+
// own (see its own doc comment) and needs the row's hover state IN JS.
|
|
565
|
+
// A single id, not a Set: only one row is ever hovered at a time, so this
|
|
566
|
+
// is one extra re-render on enter/leave, not per-row state.
|
|
567
|
+
const [hoveredRowId, setHoveredRowId] = React.useState(null);
|
|
568
|
+
// crisp/#645, checklist G-101: a Shift+Click extends a RANGE from the last
|
|
569
|
+
// plain-click anchor to the newly clicked cell (spreadsheet convention --
|
|
570
|
+
// Attio's own trigger is "Click cell A, Shift+Click cell B"). `selAnchor`
|
|
571
|
+
// is the fixed corner; `selCell` (above) keeps doubling as the moving
|
|
572
|
+
// corner/focus cell, so every existing single-cell consumer (editing,
|
|
573
|
+
// arrow-key nav, Enter) is unaffected -- a plain click resets `selAnchor`
|
|
574
|
+
// to null, collapsing back to single-cell mode.
|
|
575
|
+
const [selAnchor, setSelAnchor] = React.useState(null);
|
|
494
576
|
const gridRef = React.useRef(null);
|
|
577
|
+
// The native-copy-event proxy (crisp/#645): Attio "has no Mousetrap/
|
|
578
|
+
// JS-keydown binding for c/mod+c ... it copies purely via the native
|
|
579
|
+
// browser copy event" -- confirmed live, `document.execCommand('copy')`
|
|
580
|
+
// on the focused element is what reliably fires it, a synthetic keydown
|
|
581
|
+
// does not. A plain focused `<div>` (what `gridRef` is) never receives a
|
|
582
|
+
// native `copy` event at all (no selection, nothing editable) -- verified
|
|
583
|
+
// empirically (Playwright, a focused non-editable div, real Ctrl+C: no
|
|
584
|
+
// `copy` event fires; the same page's `<input>` with selected text does).
|
|
585
|
+
// This hidden, always-selected textarea is what a spreadsheet-style grid
|
|
586
|
+
// needs to give the browser something copyable while the VISIBLE focus
|
|
587
|
+
// styling stays on the grid: it's the same visually-hidden-but-focusable
|
|
588
|
+
// shape as `.crisp-datatable-live` below, just interactive instead of
|
|
589
|
+
// `aria-live`.
|
|
590
|
+
const clipboardProxyRef = React.useRef(null);
|
|
495
591
|
// #579: the click-to-expand overlay for a truncated cell. Only one is ever
|
|
496
592
|
// open (a second click-to-expand elsewhere closes the first, matching "one
|
|
497
593
|
// live session"-style singular UI state already used for `selCell`).
|
|
@@ -635,6 +731,25 @@ export function DataTable({ columns: columnsProp, data, selectable = false, sele
|
|
|
635
731
|
const [widths, setWidths] = React.useState({});
|
|
636
732
|
const [resizingKey, setResizingKey] = React.useState(null);
|
|
637
733
|
const resizeRef = React.useRef(null);
|
|
734
|
+
// crisp/#731 -- column drag-to-reorder. Pointer events, not native HTML5
|
|
735
|
+
// `draggable`: measured live on Attio's own grid (#731's issue comment) --
|
|
736
|
+
// `aria-roledescription="draggable"` etc. on every draggable header is
|
|
737
|
+
// dnd-kit's own signature, itself pointer-events-based, the same primitive
|
|
738
|
+
// `board.tsx` moved to in #724 (mousedown -> several mousemoves -> mouseup,
|
|
739
|
+
// no `[draggable]` anywhere). Mirrors that fix's own shape: a ref for the
|
|
740
|
+
// in-flight gesture (so a pointermove before the 2px threshold never
|
|
741
|
+
// re-renders), React state for what actually needs to paint.
|
|
742
|
+
const [dragColKey, setDragColKey] = React.useState(null);
|
|
743
|
+
const [dropCol, setDropCol] = React.useState(null);
|
|
744
|
+
const colDragRef = React.useRef(null);
|
|
745
|
+
// Keyed by column key, not index -- #577's own column virtualization means
|
|
746
|
+
// an off-screen column's `TableHead` unmounts entirely (confirmed live:
|
|
747
|
+
// Attio does the same, a column scrolled far enough away disappears from
|
|
748
|
+
// the DOM), so this only ever holds the currently-mounted ones, same as
|
|
749
|
+
// `board.tsx`'s `colRefs`.
|
|
750
|
+
const colRefs = React.useRef(new Map());
|
|
751
|
+
const autoScrollRef = React.useRef(null);
|
|
752
|
+
const COL_DRAG_THRESHOLD = 2; // crisp/#736 review fix: measured ~2px, not 4px
|
|
638
753
|
const colWidth = (col) => widths[col.key] ?? col.width ?? (col.type === "entity" ? 220 : 160);
|
|
639
754
|
const minWidth = (showGrip ? GRIP_W : 0) +
|
|
640
755
|
(selectable ? CHECK_W : 0) +
|
|
@@ -883,21 +998,166 @@ export function DataTable({ columns: columnsProp, data, selectable = false, sele
|
|
|
883
998
|
return { type: "text", inputMode: "text" };
|
|
884
999
|
}
|
|
885
1000
|
}
|
|
1001
|
+
/** The rectangular range's index bounds (inclusive), or null outside range
|
|
1002
|
+
* mode (`selAnchor` unset -- single-cell selection, the common case).
|
|
1003
|
+
* Indices, not ids/keys, so it always reads against the CURRENT rendered
|
|
1004
|
+
* `rows`/`columns` order -- the same order arrow-key nav already uses. */
|
|
1005
|
+
function getSelRangeIndices() {
|
|
1006
|
+
if (!selAnchor || !selCell)
|
|
1007
|
+
return null;
|
|
1008
|
+
const ar = rows.findIndex((row) => row.id === selAnchor.id);
|
|
1009
|
+
const ac = columns.findIndex((col) => col.key === selAnchor.key);
|
|
1010
|
+
const fr = rows.findIndex((row) => row.id === selCell.id);
|
|
1011
|
+
const fc = columns.findIndex((col) => col.key === selCell.key);
|
|
1012
|
+
if (ar < 0 || ac < 0 || fr < 0 || fc < 0)
|
|
1013
|
+
return null;
|
|
1014
|
+
return {
|
|
1015
|
+
r0: Math.min(ar, fr),
|
|
1016
|
+
r1: Math.max(ar, fr),
|
|
1017
|
+
c0: Math.min(ac, fc),
|
|
1018
|
+
c1: Math.max(ac, fc),
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
/**
|
|
1022
|
+
* crisp/#645: Attio copies the RAW, unformatted value (`asText`, not
|
|
1023
|
+
* `formatCell` -- G-070: a formatted "28,946,065" cell copies as raw
|
|
1024
|
+
* "28946065"), writes nothing at all for a `readOnly`/computed cell
|
|
1025
|
+
* (G-100 -- no clipboard write occurs, not an empty string), and a
|
|
1026
|
+
* Shift+Click range copies as TSV: `\t` between columns, `\r\n` between
|
|
1027
|
+
* rows, no header row, raw values (G-101). Returns null for "no clipboard
|
|
1028
|
+
* write" (the single-readOnly-cell case, or nothing selected) rather than
|
|
1029
|
+
* "" -- the caller must not fall back to writing an empty string either.
|
|
1030
|
+
*/
|
|
1031
|
+
function buildCopyText() {
|
|
1032
|
+
const range = getSelRangeIndices();
|
|
1033
|
+
if (range) {
|
|
1034
|
+
const { r0, r1, c0, c1 } = range;
|
|
1035
|
+
const lines = [];
|
|
1036
|
+
for (let ri = r0; ri <= r1; ri++) {
|
|
1037
|
+
const row = rows[ri];
|
|
1038
|
+
const cells = [];
|
|
1039
|
+
for (let ci = c0; ci <= c1; ci++) {
|
|
1040
|
+
const col = columns[ci];
|
|
1041
|
+
cells.push(col.readOnly ? "" : asText(cellValue(col, row)));
|
|
1042
|
+
}
|
|
1043
|
+
lines.push(cells.join("\t"));
|
|
1044
|
+
}
|
|
1045
|
+
return lines.join("\r\n");
|
|
1046
|
+
}
|
|
1047
|
+
if (!selCell)
|
|
1048
|
+
return null;
|
|
1049
|
+
const row = rows.find((rw) => rw.id === selCell.id);
|
|
1050
|
+
const col = columns.find((cc) => cc.key === selCell.key);
|
|
1051
|
+
if (!row || !col || col.readOnly)
|
|
1052
|
+
return null;
|
|
1053
|
+
return asText(cellValue(col, row));
|
|
1054
|
+
}
|
|
1055
|
+
/**
|
|
1056
|
+
* crisp/#645: the native `copy`/`paste` events, not a keydown handler --
|
|
1057
|
+
* Attio "has no Mousetrap/JS-keydown binding for c/mod+c ... it copies
|
|
1058
|
+
* purely via the native browser copy event" (confirmed live). These fire
|
|
1059
|
+
* on `clipboardProxyRef`'s hidden textarea (see its own comment), which
|
|
1060
|
+
* `onGridKeyDown` below no longer intercepts Cmd/Ctrl+C for.
|
|
1061
|
+
*/
|
|
1062
|
+
function onGridCopy(e) {
|
|
1063
|
+
e.preventDefault();
|
|
1064
|
+
const text = buildCopyText();
|
|
1065
|
+
if (text != null)
|
|
1066
|
+
e.clipboardData.setData("text/plain", text);
|
|
1067
|
+
}
|
|
1068
|
+
/** crisp/#598, G-071: Attio's own context-menu Paste "looked like it would
|
|
1069
|
+
* commit immediately with no safe cancel step" -- matched here: paste
|
|
1070
|
+
* commits straight to `onEdit`, it doesn't open the cell's editor first.
|
|
1071
|
+
* Single-cell only -- a range-fill paste isn't measured (G-071 was
|
|
1072
|
+
* deliberately not exercised against real clipboard content), so it isn't
|
|
1073
|
+
* built rather than guessed. */
|
|
1074
|
+
function onGridPaste(e) {
|
|
1075
|
+
e.preventDefault();
|
|
1076
|
+
if (!selCell || editing)
|
|
1077
|
+
return;
|
|
1078
|
+
const col = columns.find((cc) => cc.key === selCell.key);
|
|
1079
|
+
if (!col?.editable || col.readOnly)
|
|
1080
|
+
return;
|
|
1081
|
+
const text = e.clipboardData.getData("text/plain");
|
|
1082
|
+
onEdit?.(selCell.id, selCell.key, text);
|
|
1083
|
+
}
|
|
1084
|
+
/**
|
|
1085
|
+
* crisp/#598, checklist G-043: Attio's cell context menu is "identical
|
|
1086
|
+
* regardless of field type" — Copy, Paste, View edit history, Clear
|
|
1087
|
+
* value, every time, just some items disabled. No row-level menu exists
|
|
1088
|
+
* at all (G-044 — RecordsTable's own Copy/Duplicate/Pin/Delete row menu
|
|
1089
|
+
* was dropped rather than carried onto DataTable, per the consolidation
|
|
1090
|
+
* plan's own decision: Attio has no row menu to match).
|
|
1091
|
+
*/
|
|
1092
|
+
function cellMenuItems(row, col) {
|
|
1093
|
+
return [
|
|
1094
|
+
{
|
|
1095
|
+
label: copyLabel,
|
|
1096
|
+
icon: _jsx(Copy, { size: 16, strokeWidth: 1.75 }),
|
|
1097
|
+
// G-100: Attio has "no copy handler at all" for a computed/
|
|
1098
|
+
// read-only field -- disabled here, not just silently a no-op, so
|
|
1099
|
+
// the menu itself tells the reader why.
|
|
1100
|
+
disabled: !!col.readOnly,
|
|
1101
|
+
onSelect: () => {
|
|
1102
|
+
if (col.readOnly)
|
|
1103
|
+
return;
|
|
1104
|
+
navigator.clipboard
|
|
1105
|
+
?.writeText(asText(cellValue(col, row)))
|
|
1106
|
+
.catch(() => { });
|
|
1107
|
+
},
|
|
1108
|
+
},
|
|
1109
|
+
{
|
|
1110
|
+
label: pasteLabel,
|
|
1111
|
+
icon: _jsx(ClipboardPaste, { size: 16, strokeWidth: 1.75 }),
|
|
1112
|
+
disabled: !col.editable || !!col.readOnly,
|
|
1113
|
+
onSelect: () => {
|
|
1114
|
+
navigator.clipboard
|
|
1115
|
+
?.readText()
|
|
1116
|
+
.then((text) => onEdit?.(row.id, col.key, text))
|
|
1117
|
+
.catch(() => { });
|
|
1118
|
+
},
|
|
1119
|
+
},
|
|
1120
|
+
{ separator: true },
|
|
1121
|
+
{
|
|
1122
|
+
label: viewEditHistoryLabel,
|
|
1123
|
+
icon: _jsx(History, { size: 16, strokeWidth: 1.75 }),
|
|
1124
|
+
// Attio's own item carries a "Pro" pill (crisp has no billing
|
|
1125
|
+
// concept to gate on, see this prop's own doc comment) -- disabled
|
|
1126
|
+
// only when the consumer gave nothing for it to open, not gated on
|
|
1127
|
+
// a plan crisp doesn't model.
|
|
1128
|
+
disabled: !onViewEditHistory,
|
|
1129
|
+
onSelect: () => onViewEditHistory?.(row.id, col.key),
|
|
1130
|
+
},
|
|
1131
|
+
{ separator: true },
|
|
1132
|
+
{
|
|
1133
|
+
label: clearValueLabel,
|
|
1134
|
+
icon: _jsx(X, { size: 16, strokeWidth: 1.75 }),
|
|
1135
|
+
danger: true,
|
|
1136
|
+
disabled: !col.editable,
|
|
1137
|
+
onSelect: () => onEdit?.(row.id, col.key, ""),
|
|
1138
|
+
},
|
|
1139
|
+
];
|
|
1140
|
+
}
|
|
886
1141
|
/**
|
|
887
1142
|
* Spreadsheet keyboard model, ported from RecordsTable: arrows move the
|
|
888
1143
|
* selected cell, Enter opens its editor (or, on a non-editable cell,
|
|
889
|
-
* activates the row via `onRowClick`), Escape clears
|
|
890
|
-
*
|
|
1144
|
+
* activates the row via `onRowClick`), Escape clears. Cmd/Ctrl+C is
|
|
1145
|
+
* deliberately NOT handled here (crisp/#645) -- copy is the native `copy`
|
|
1146
|
+
* event on `clipboardProxyRef`, see `onGridCopy` above.
|
|
891
1147
|
*/
|
|
892
1148
|
function onGridKeyDown(e) {
|
|
893
1149
|
if (!selCell || editing)
|
|
894
1150
|
return;
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
1151
|
+
// crisp/#607, G-069: Attio's own Cmd+A selects every row (confirmed
|
|
1152
|
+
// live, `metaKey:true`, all 37/37 rows, header checkbox fully checked)
|
|
1153
|
+
// -- a real SELECT ALL, not `toggleAll`'s flip-if-already-all-selected,
|
|
1154
|
+
// so a second Cmd+A with everything already picked stays a no-op
|
|
1155
|
+
// instead of clearing the selection out from under the user.
|
|
1156
|
+
if ((e.metaKey || e.ctrlKey) && (e.key === "a" || e.key === "A")) {
|
|
1157
|
+
if (!selectable)
|
|
1158
|
+
return;
|
|
900
1159
|
e.preventDefault();
|
|
1160
|
+
setSelected(new Set(rows.map((rw) => rw.id)));
|
|
901
1161
|
return;
|
|
902
1162
|
}
|
|
903
1163
|
const r = rows.findIndex((row) => row.id === selCell.id);
|
|
@@ -917,8 +1177,27 @@ export function DataTable({ columns: columnsProp, data, selectable = false, sele
|
|
|
917
1177
|
const forward = e.key === (rtl ? "ArrowLeft" : "ArrowRight");
|
|
918
1178
|
nc = forward ? Math.min(columns.length - 1, c + 1) : Math.max(0, c - 1);
|
|
919
1179
|
}
|
|
1180
|
+
// crisp/#607, G-066/G-068: End jumps to the last row (confirmed live --
|
|
1181
|
+
// it also triggers Attio's own lazy-load, which is a data-loading
|
|
1182
|
+
// concern outside this component; the #577 scroll-into-view effect
|
|
1183
|
+
// below already re-runs on every `selCell` change, on a virtualized
|
|
1184
|
+
// grid too, so jumping straight to the last row is enough to reveal it
|
|
1185
|
+
// the same way arrowing down one row at a time would). PageUp/PageDown
|
|
1186
|
+
// move a viewport's worth of rows -- `scrollRef`'s own rendered height
|
|
1187
|
+
// divided by the uniform row height, at least one row so a viewport
|
|
1188
|
+
// shorter than one row can't get stuck.
|
|
1189
|
+
else if (e.key === "End")
|
|
1190
|
+
nr = rows.length - 1;
|
|
1191
|
+
else if (e.key === "PageDown" || e.key === "PageUp") {
|
|
1192
|
+
const viewportRows = Math.max(1, Math.floor((scrollRef.current?.clientHeight ?? 0) / ROW_HEIGHT));
|
|
1193
|
+
nr =
|
|
1194
|
+
e.key === "PageDown"
|
|
1195
|
+
? Math.min(rows.length - 1, r + viewportRows)
|
|
1196
|
+
: Math.max(0, r - viewportRows);
|
|
1197
|
+
}
|
|
920
1198
|
else if (e.key === "Escape") {
|
|
921
1199
|
setSelCell(null);
|
|
1200
|
+
setSelAnchor(null);
|
|
922
1201
|
return;
|
|
923
1202
|
}
|
|
924
1203
|
else if (e.key === "Enter") {
|
|
@@ -940,7 +1219,16 @@ export function DataTable({ columns: columnsProp, data, selectable = false, sele
|
|
|
940
1219
|
else
|
|
941
1220
|
return;
|
|
942
1221
|
e.preventDefault();
|
|
1222
|
+
// A plain arrow key moves the single-cell selection and drops any active
|
|
1223
|
+
// range -- Attio's own range trigger is Shift+Click only (G-101), arrow
|
|
1224
|
+
// keys were never measured as a range-extend gesture, so this doesn't
|
|
1225
|
+
// invent one.
|
|
1226
|
+
setSelAnchor(null);
|
|
943
1227
|
setSelCell({ id: rows[nr].id, key: columns[nc].key });
|
|
1228
|
+
// keeps the clipboard proxy's selection non-collapsed after a move, so
|
|
1229
|
+
// a Cmd+C right after an arrow key still has something native `copy`
|
|
1230
|
+
// can fire on (see `clipboardProxyRef`'s own comment).
|
|
1231
|
+
clipboardProxyRef.current?.select();
|
|
944
1232
|
}
|
|
945
1233
|
// Opening a cell's editor also clears any stale error left over from a
|
|
946
1234
|
// PREVIOUS failed commit on it (#385) -- otherwise a rejection from three
|
|
@@ -1052,7 +1340,8 @@ export function DataTable({ columns: columnsProp, data, selectable = false, sele
|
|
|
1052
1340
|
renderItems,
|
|
1053
1341
|
]);
|
|
1054
1342
|
const totalCols = columns.length + (selectable ? 1 : 0) + (showGrip ? 1 : 0);
|
|
1055
|
-
const hasSummary = columns.some((c) => c.summary);
|
|
1343
|
+
const hasSummary = columns.some((c) => c.summary || c.calc);
|
|
1344
|
+
const hasCommentColumn = columns.some((c) => c.onOpenComments);
|
|
1056
1345
|
// sticky attrs for the leading column(s): grip col (index -2) + selection
|
|
1057
1346
|
// col (-1) + first data column (0). Each offsets by whatever leading
|
|
1058
1347
|
// columns come before it, so the group stays contiguous when scrolled.
|
|
@@ -1149,13 +1438,135 @@ export function DataTable({ columns: columnsProp, data, selectable = false, sele
|
|
|
1149
1438
|
setResizingKey(null);
|
|
1150
1439
|
e.target.releasePointerCapture(e.pointerId);
|
|
1151
1440
|
}
|
|
1441
|
+
// Which mounted column (if any) `clientX` is over, and which side of it --
|
|
1442
|
+
// X only, not the full box: like `board.tsx`'s own `columnAt` (#724), the
|
|
1443
|
+
// header row is a single non-wrapping row, so X alone already identifies a
|
|
1444
|
+
// column unambiguously, and checking Y too only risks the same short-row
|
|
1445
|
+
// miss that #724 found the hard way. The midpoint split is what turns
|
|
1446
|
+
// "over column C" into an insertion point: left half means "before C",
|
|
1447
|
+
// right half means "after C" -- exposed as `dropCol` so the render can draw
|
|
1448
|
+
// the measured blue line on the correct edge.
|
|
1449
|
+
function columnDropAt(clientX) {
|
|
1450
|
+
for (const [key, el] of colRefs.current) {
|
|
1451
|
+
const r = el.getBoundingClientRect();
|
|
1452
|
+
if (clientX >= r.left && clientX <= r.right) {
|
|
1453
|
+
return {
|
|
1454
|
+
key,
|
|
1455
|
+
side: clientX < r.left + r.width / 2 ? "before" : "after",
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
return null;
|
|
1460
|
+
}
|
|
1461
|
+
function stopColAutoScroll() {
|
|
1462
|
+
if (autoScrollRef.current != null) {
|
|
1463
|
+
cancelAnimationFrame(autoScrollRef.current);
|
|
1464
|
+
autoScrollRef.current = null;
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
// Edge auto-scroll (measured live, #731's issue comment: dragging a header
|
|
1468
|
+
// toward the viewport edge scrolls the grid to reveal more columns). A
|
|
1469
|
+
// `requestAnimationFrame` loop, not a one-shot nudge per pointermove: the
|
|
1470
|
+
// scroll has to keep going even while the pointer itself sits still near
|
|
1471
|
+
// the edge, which a per-event nudge can't do. Guarded for environments with
|
|
1472
|
+
// no `requestAnimationFrame` (bun test's happy-dom) -- never throws, just a
|
|
1473
|
+
// no-op there, same as the `ResizeObserver` guards elsewhere in this file.
|
|
1474
|
+
function updateColAutoScroll(clientX) {
|
|
1475
|
+
if (typeof requestAnimationFrame === "undefined")
|
|
1476
|
+
return;
|
|
1477
|
+
const el = scrollRef.current;
|
|
1478
|
+
if (!el)
|
|
1479
|
+
return;
|
|
1480
|
+
const r = el.getBoundingClientRect();
|
|
1481
|
+
const EDGE = 40;
|
|
1482
|
+
const dir = clientX < r.left + EDGE ? -1 : clientX > r.right - EDGE ? 1 : 0;
|
|
1483
|
+
stopColAutoScroll();
|
|
1484
|
+
if (dir === 0)
|
|
1485
|
+
return;
|
|
1486
|
+
const step = () => {
|
|
1487
|
+
el.scrollLeft += dir * 12;
|
|
1488
|
+
autoScrollRef.current = requestAnimationFrame(step);
|
|
1489
|
+
};
|
|
1490
|
+
autoScrollRef.current = requestAnimationFrame(step);
|
|
1491
|
+
}
|
|
1492
|
+
function onColHeaderPointerDown(e, key) {
|
|
1493
|
+
if (!e.isPrimary)
|
|
1494
|
+
return;
|
|
1495
|
+
colDragRef.current = {
|
|
1496
|
+
key,
|
|
1497
|
+
pointerId: e.pointerId,
|
|
1498
|
+
startX: e.clientX,
|
|
1499
|
+
startY: e.clientY,
|
|
1500
|
+
active: false,
|
|
1501
|
+
};
|
|
1502
|
+
}
|
|
1503
|
+
function onColHeaderPointerMove(e) {
|
|
1504
|
+
const st = colDragRef.current;
|
|
1505
|
+
if (!st || st.pointerId !== e.pointerId)
|
|
1506
|
+
return;
|
|
1507
|
+
if (!st.active) {
|
|
1508
|
+
if (Math.hypot(e.clientX - st.startX, e.clientY - st.startY) <
|
|
1509
|
+
COL_DRAG_THRESHOLD)
|
|
1510
|
+
return;
|
|
1511
|
+
st.active = true;
|
|
1512
|
+
setDragColKey(st.key);
|
|
1513
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
1514
|
+
}
|
|
1515
|
+
const at = columnDropAt(e.clientX);
|
|
1516
|
+
setDropCol(at && at.key !== st.key ? at : null);
|
|
1517
|
+
updateColAutoScroll(e.clientX);
|
|
1518
|
+
}
|
|
1519
|
+
function endColHeaderDrag(e, commit) {
|
|
1520
|
+
const st = colDragRef.current;
|
|
1521
|
+
if (!st || st.pointerId !== e.pointerId)
|
|
1522
|
+
return;
|
|
1523
|
+
if (commit && st.active && dropCol) {
|
|
1524
|
+
const keys = allColumns.map((c) => c.key);
|
|
1525
|
+
const from = keys.indexOf(st.key);
|
|
1526
|
+
const to = keys.indexOf(dropCol.key);
|
|
1527
|
+
if (from >= 0 && to >= 0) {
|
|
1528
|
+
keys.splice(from, 1);
|
|
1529
|
+
let insertAt = keys.indexOf(dropCol.key);
|
|
1530
|
+
if (dropCol.side === "after")
|
|
1531
|
+
insertAt += 1;
|
|
1532
|
+
keys.splice(insertAt, 0, st.key);
|
|
1533
|
+
applyOrder(keys);
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
colDragRef.current = null;
|
|
1537
|
+
setDragColKey(null);
|
|
1538
|
+
setDropCol(null);
|
|
1539
|
+
stopColAutoScroll();
|
|
1540
|
+
}
|
|
1541
|
+
// Escape cancels the drag without committing (measured live, #731's issue
|
|
1542
|
+
// comment: verified twice against the real grid) -- a document listener,
|
|
1543
|
+
// not a React `onKeyDown` on the header, for the same reason
|
|
1544
|
+
// `useEscapeExitsEditing` above uses one: focus during a pointer drag isn't
|
|
1545
|
+
// reliably inside the dragged element.
|
|
1546
|
+
React.useEffect(() => {
|
|
1547
|
+
if (!dragColKey)
|
|
1548
|
+
return;
|
|
1549
|
+
const onKey = (e) => {
|
|
1550
|
+
if (e.key !== "Escape")
|
|
1551
|
+
return;
|
|
1552
|
+
colDragRef.current = null;
|
|
1553
|
+
setDragColKey(null);
|
|
1554
|
+
setDropCol(null);
|
|
1555
|
+
if (autoScrollRef.current != null) {
|
|
1556
|
+
cancelAnimationFrame(autoScrollRef.current);
|
|
1557
|
+
autoScrollRef.current = null;
|
|
1558
|
+
}
|
|
1559
|
+
};
|
|
1560
|
+
document.addEventListener("keydown", onKey);
|
|
1561
|
+
return () => document.removeEventListener("keydown", onKey);
|
|
1562
|
+
}, [dragColKey]);
|
|
1152
1563
|
function ChevronFor({ colKey }) {
|
|
1153
1564
|
const dir = sortDirByKey.get(colKey);
|
|
1154
1565
|
if (dir)
|
|
1155
1566
|
return dir === "asc" ? (_jsx(ArrowUp, { className: "crisp-datatable-chevron", size: 13, strokeWidth: 2 })) : (_jsx(ArrowDown, { className: "crisp-datatable-chevron", size: 13, strokeWidth: 2 }));
|
|
1156
1567
|
return (_jsx(ChevronsUpDown, { className: "crisp-datatable-chevron", size: 13, strokeWidth: 2 }));
|
|
1157
1568
|
}
|
|
1158
|
-
return (_jsxs("div", { ref: gridRef, className: datatableRecipe({ className }), tabIndex: -1, onKeyDown: onGridKeyDown, ...rest, children: [_jsx("div", { className: "crisp-datatable-live", role: "status", "aria-live": "polite", children: selectionText }), (filterable || showCount || toolbar || columnMenu) && (_jsxs("div", { className: "crisp-datatable-toolbar", children: [columnMenu && (_jsxs(Menu, { align: "start", trigger: _jsxs("button", { type: "button", className: "crisp-datatable-viewsettings", children: [_jsx(SlidersHorizontal, { size: 14, strokeWidth: 1.75 }), viewSettingsLabel] }), children: [_jsx("div", { className: "crisp-datatable-group-label", children: columnsGroupLabel }), allColumns.map((c) => (_jsxs(MenuItem, { onSelect: () => c.hidden ? showColumn(c.key) : hideColumn(c.key), children: [_jsx(Check, { size: 14, strokeWidth: 2, style: { opacity: c.hidden ? 0 : 1 } }), typeof c.header === "string" ? c.header : c.key] }, c.key)))] })), filterable && (_jsxs("span", { className: "crisp-datatable-search", children: [_jsx(Search, { size: 15, strokeWidth: 1.75, "aria-hidden": "true" }), _jsx("input", { type: "search", placeholder: searchPlaceholder, value: query, onChange: (e) => setQuery(e.target.value), "aria-label": searchLabel })] })), showCount && (_jsx("span", { className: "crisp-datatable-count", children: resolvedCountLabel(rows.length, data.length) })), toolbar] })), _jsxs(Table, { interactive: interactive, surface: surface,
|
|
1569
|
+
return (_jsxs("div", { ref: gridRef, className: datatableRecipe({ className }), tabIndex: -1, onKeyDown: onGridKeyDown, ...rest, children: [_jsx("div", { className: "crisp-datatable-live", role: "status", "aria-live": "polite", children: selectionText }), _jsx("textarea", { ref: clipboardProxyRef, className: "crisp-datatable-clipboard-proxy", readOnly: true, value: " ", "aria-label": cellMenuLabel, tabIndex: -1, onCopy: onGridCopy, onPaste: onGridPaste }), (filterable || showCount || toolbar || columnMenu) && (_jsxs("div", { className: "crisp-datatable-toolbar", children: [columnMenu && (_jsxs(Menu, { align: "start", trigger: _jsxs("button", { type: "button", className: "crisp-datatable-viewsettings", children: [_jsx(SlidersHorizontal, { size: 14, strokeWidth: 1.75 }), viewSettingsLabel] }), children: [_jsx("div", { className: "crisp-datatable-group-label", children: columnsGroupLabel }), allColumns.map((c) => (_jsxs(MenuItem, { onSelect: () => c.hidden ? showColumn(c.key) : hideColumn(c.key), children: [_jsx(Check, { size: 14, strokeWidth: 2, style: { opacity: c.hidden ? 0 : 1 } }), typeof c.header === "string" ? c.header : c.key] }, c.key)))] })), filterable && (_jsxs("span", { className: "crisp-datatable-search", children: [_jsx(Search, { size: 15, strokeWidth: 1.75, "aria-hidden": "true" }), _jsx("input", { type: "search", placeholder: searchPlaceholder, value: query, onChange: (e) => setQuery(e.target.value), "aria-label": searchLabel })] })), showCount && (_jsx("span", { className: "crisp-datatable-count", children: resolvedCountLabel(rows.length, data.length) })), toolbar] })), _jsxs(Table, { interactive: interactive, surface: surface,
|
|
1159
1570
|
// crisp/#581: on the <table> itself (`tableStyle`), not the outer
|
|
1160
1571
|
// wrapper (`style`) -- see `Table`'s own doc comment on why. This is
|
|
1161
1572
|
// what lets the grid actually scroll horizontally INSIDE its own
|
|
@@ -1226,7 +1637,30 @@ export function DataTable({ columns: columnsProp, data, selectable = false, sele
|
|
|
1226
1637
|
: "descending"
|
|
1227
1638
|
: "none";
|
|
1228
1639
|
const inner = (_jsxs("span", { className: "crisp-datatable-th-inner", children: [Icon ? _jsx(Icon, { size: 16, strokeWidth: 1.75 }) : null, _jsx(ThLabel, { header: col.header, referencedType: col.referencedType }), col.sortable ? _jsx(ChevronFor, { colKey: col.key }) : null] }));
|
|
1229
|
-
return (_jsxs(TableHead, {
|
|
1640
|
+
return (_jsxs(TableHead, { ref: isPrimary
|
|
1641
|
+
? undefined
|
|
1642
|
+
: (el) => {
|
|
1643
|
+
if (el)
|
|
1644
|
+
colRefs.current.set(col.key, el);
|
|
1645
|
+
else
|
|
1646
|
+
colRefs.current.delete(col.key);
|
|
1647
|
+
}, align: alignFor(col), "aria-sort": ariaSort, "aria-colindex": colAriaIndex(i), "data-dragging": dragColKey === col.key ? "" : undefined, "data-drop-before": dropCol?.key === col.key && dropCol.side === "before"
|
|
1648
|
+
? ""
|
|
1649
|
+
: undefined, "data-drop-after": dropCol?.key === col.key && dropCol.side === "after"
|
|
1650
|
+
? ""
|
|
1651
|
+
: undefined,
|
|
1652
|
+
// #731: column drag-to-reorder lives on the TH itself, not
|
|
1653
|
+
// a dedicated grip -- Attio's own header is draggable by
|
|
1654
|
+
// its whole surface (measured live). A plain click (no
|
|
1655
|
+
// movement past the 2px threshold) never calls
|
|
1656
|
+
// `setPointerCapture`/`preventDefault`, so the sort
|
|
1657
|
+
// button/menu trigger/resize handle nested inside still get
|
|
1658
|
+
// their own click normally; `startResize`'s own
|
|
1659
|
+
// `stopPropagation` (above) keeps a resize drag from ever
|
|
1660
|
+
// reaching this handler in the first place.
|
|
1661
|
+
onPointerDown: isPrimary
|
|
1662
|
+
? undefined
|
|
1663
|
+
: (e) => onColHeaderPointerDown(e, col.key), onPointerMove: isPrimary ? undefined : onColHeaderPointerMove, onPointerUp: isPrimary ? undefined : (e) => endColHeaderDrag(e, true), onPointerCancel: isPrimary ? undefined : (e) => endColHeaderDrag(e, false), ...dataStickyCol(i), children: [renaming === col.key ? (_jsx("input", {
|
|
1230
1664
|
// biome-ignore lint/a11y/noAutofocus: the rename item opens this field
|
|
1231
1665
|
autoFocus: true, className: "crisp-datatable-th-rename", defaultValue: typeof col.header === "string" ? col.header : "", "aria-label": renameColumnLabel, onBlur: (e) => {
|
|
1232
1666
|
renameColumn(col.key, e.currentTarget.value);
|
|
@@ -1258,7 +1692,9 @@ export function DataTable({ columns: columnsProp, data, selectable = false, sele
|
|
|
1258
1692
|
dragRowId !== row.id &&
|
|
1259
1693
|
dropRowId === row.id
|
|
1260
1694
|
? ""
|
|
1261
|
-
: undefined, onClick: onRowClick ? () => onRowClick(row) : undefined, style: onRowClick ? { cursor: "pointer" } : undefined,
|
|
1695
|
+
: undefined, onClick: onRowClick ? () => onRowClick(row) : undefined, style: onRowClick ? { cursor: "pointer" } : undefined, onMouseEnter: hasCommentColumn
|
|
1696
|
+
? () => setHoveredRowId(row.id)
|
|
1697
|
+
: undefined, onMouseLeave: hasCommentColumn ? () => setHoveredRowId(null) : undefined, onDragOver: showGrip && dragRowId
|
|
1262
1698
|
? (e) => {
|
|
1263
1699
|
e.preventDefault();
|
|
1264
1700
|
if (dropRowId !== row.id)
|
|
@@ -1342,46 +1778,99 @@ export function DataTable({ columns: columnsProp, data, selectable = false, sele
|
|
|
1342
1778
|
commitEdit(row.id, col.key, e.currentTarget.value);
|
|
1343
1779
|
} }), isPending && (_jsx(Spinner, { size: 14, className: "crisp-datatable-edit-pending" }))] }, col.key));
|
|
1344
1780
|
}
|
|
1781
|
+
// `itemIndex` is the row's position in the full
|
|
1782
|
+
// `rows` array (getSelRangeIndices' own r0/r1 are
|
|
1783
|
+
// indices into that same array) for the common,
|
|
1784
|
+
// ungrouped case. A `groupBy` view interleaves group-
|
|
1785
|
+
// header items into `visibleItems`, which this
|
|
1786
|
+
// doesn't correct for -- Shift+Click ranging across a
|
|
1787
|
+
// grouped view isn't a measured Attio interaction
|
|
1788
|
+
// (G-101's own trigger is a plain table), so it's a
|
|
1789
|
+
// known gap rather than a guess at behaviour there.
|
|
1790
|
+
const inRange = (() => {
|
|
1791
|
+
const range = getSelRangeIndices();
|
|
1792
|
+
if (!range)
|
|
1793
|
+
return false;
|
|
1794
|
+
return (itemIndex >= range.r0 &&
|
|
1795
|
+
itemIndex <= range.r1 &&
|
|
1796
|
+
i >= range.c0 &&
|
|
1797
|
+
i <= range.c1);
|
|
1798
|
+
})();
|
|
1345
1799
|
const rendered = col.render
|
|
1346
1800
|
? col.render(value, row)
|
|
1347
|
-
: renderTyped(col, value, avatarTone, row, col.format?.(value, row), locale);
|
|
1801
|
+
: renderTyped(col, value, avatarTone, row, col.format?.(value, row), locale, openPreviewLabel, hoveredRowId === row.id);
|
|
1348
1802
|
const isExpanded = expandedCell?.id === row.id &&
|
|
1349
1803
|
expandedCell?.key === col.key;
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1804
|
+
const cellContent = (_jsxs(_Fragment, { children: [!isExpanded && rendered, errorHere && (_jsx("span", { className: "crisp-datatable-edit-error", children: errorHere })), isExpanded && (_jsx("div", { className: "crisp-datatable-cell-overlay", onClick: (e) => e.stopPropagation(), children: rendered }))] }));
|
|
1805
|
+
return (_jsx(ContextMenu, { asChild: true, variant: "dark", menuLabel: cellMenuLabel, items: cellMenuItems(row, col), children: _jsx(TableCell, { align: alignFor(col), "aria-colindex": colAriaIndex(i), ...sticky, className: col.editable
|
|
1806
|
+
? "crisp-datatable-editable"
|
|
1807
|
+
: undefined, "data-selected": selCell?.id === row.id && selCell?.key === col.key
|
|
1808
|
+
? ""
|
|
1809
|
+
: undefined, "data-in-range": inRange ? "" : undefined, "data-cell-expanded": isExpanded ? "" : undefined, onClick: (e) => {
|
|
1810
|
+
// the keyboard model's anchor -- a single click
|
|
1811
|
+
// only selects. A genuine double-click (or Enter
|
|
1812
|
+
// on the selected cell) opens the editor (#411),
|
|
1813
|
+
// matching RecordsTable's own onDoubleClick.
|
|
1814
|
+
// crisp/#645, G-101: Shift+Click extends a
|
|
1815
|
+
// range from the last plain-click anchor
|
|
1816
|
+
// ("Click cell A, Shift+Click cell B") --
|
|
1817
|
+
// `selCell` keeps doubling as the moving
|
|
1818
|
+
// corner, `selAnchor` is the fixed one.
|
|
1819
|
+
if (e.shiftKey && selCell) {
|
|
1820
|
+
setSelAnchor(selAnchor ?? selCell);
|
|
1821
|
+
}
|
|
1822
|
+
else {
|
|
1823
|
+
setSelAnchor(null);
|
|
1824
|
+
}
|
|
1825
|
+
setSelCell({ id: row.id, key: col.key });
|
|
1826
|
+
// Focuses the clipboard proxy, not `gridRef`
|
|
1827
|
+
// itself (crisp/#645) -- it's a DESCENDANT of
|
|
1828
|
+
// `gridRef`, so `onGridKeyDown` still sees
|
|
1829
|
+
// every key via bubbling, but now the browser
|
|
1830
|
+
// also has a focused, selectable text node to
|
|
1831
|
+
// fire a native `copy`/`paste` on. `focus()`
|
|
1832
|
+
// then `select()`, not `select()` alone --
|
|
1833
|
+
// `select()` only guarantees the SELECTION,
|
|
1834
|
+
// focus is a side effect some engines don't
|
|
1835
|
+
// give it for free.
|
|
1836
|
+
clipboardProxyRef.current?.focus();
|
|
1837
|
+
clipboardProxyRef.current?.select();
|
|
1838
|
+
// #579: a truncated cell also opens a read-only
|
|
1839
|
+
// overlay with its full value -- settled live
|
|
1840
|
+
// that this is click, not Attio's usual
|
|
1841
|
+
// hover-expand (a 1s hover on a truncated
|
|
1842
|
+
// Description cell produced nothing). Measured
|
|
1843
|
+
// the same way as `ThLabel`'s header tooltip
|
|
1844
|
+
// (#534): scrollWidth vs clientWidth on the
|
|
1845
|
+
// element the CSS ellipsis actually applies to,
|
|
1846
|
+
// which for a data cell is the `td` itself
|
|
1847
|
+
// (table.recipe.ts's own `overflow: hidden;
|
|
1848
|
+
// text-overflow: ellipsis`), not a nested span.
|
|
1849
|
+
// Skipped on a Shift+Click (crisp/#645) -- that
|
|
1850
|
+
// gesture's own intent is extending the range,
|
|
1851
|
+
// not popping open a read-only overlay on top
|
|
1852
|
+
// of it.
|
|
1853
|
+
setExpandedCell(!e.shiftKey && isLabelTruncated(e.currentTarget)
|
|
1854
|
+
? { id: row.id, key: col.key }
|
|
1855
|
+
: null);
|
|
1856
|
+
}, onDoubleClick: col.editable
|
|
1857
|
+
? () => openEditing(row.id, col.key)
|
|
1858
|
+
: undefined, onContextMenu: () => {
|
|
1859
|
+
// Right-clicking targets THAT cell for the
|
|
1860
|
+
// menu regardless of what was previously
|
|
1861
|
+
// selected (crisp/#598) -- collapses any
|
|
1862
|
+
// active range, same as a plain left-click.
|
|
1863
|
+
setSelAnchor(null);
|
|
1864
|
+
setSelCell({ id: row.id, key: col.key });
|
|
1865
|
+
clipboardProxyRef.current?.focus();
|
|
1866
|
+
clipboardProxyRef.current?.select();
|
|
1867
|
+
}, children: cellContent }) }, col.key));
|
|
1378
1868
|
})] }, row.id));
|
|
1379
1869
|
}), bottomSpacerHeight > 0 && (_jsx("tr", { "aria-hidden": "true", children: _jsx("td", { colSpan: totalCols, style: {
|
|
1380
1870
|
height: bottomSpacerHeight,
|
|
1381
1871
|
padding: 0,
|
|
1382
1872
|
border: "none",
|
|
1383
|
-
} }) }))] })) }), (hasSummary || onAddRow) && (_jsxs(TableFooter, { children: [hasSummary && (_jsxs(TableRow, { children: [showGrip && _jsx(TableCell, { ...stickyCol(-2) }), selectable && _jsx(TableCell, { ...stickyCol(-1) }), colSlots.map((slot) => slot.type === "spacer" ? (_jsx("td", { role: "presentation", "aria-hidden": "true", style: { padding: 0, border: "none" } }, `__spacer_${slot.side}`)) : (_jsx(TableCell, { align: alignFor(columns[slot.i]), "aria-colindex": colAriaIndex(slot.i), ...dataStickyCol(slot.i), children: columns[slot.i].
|
|
1384
|
-
|
|
1385
|
-
: null }, columns[slot.i].key)))] })), onAddRow && (_jsx(TableRow, { children: _jsx(TableCell, { className: "crisp-datatable-addcell", colSpan: totalCols, children: _jsxs("button", { type: "button", className: "crisp-datatable-addrow", onClick: onAddRow, children: [_jsx(Plus, { size: 15, strokeWidth: 1.75, "aria-hidden": "true" }), addRowLabel] }) }) }))] }))] })] }));
|
|
1873
|
+
} }) }))] })) }), (hasSummary || onAddRow) && (_jsxs(TableFooter, { children: [hasSummary && (_jsxs(TableRow, { children: [showGrip && _jsx(TableCell, { ...stickyCol(-2) }), selectable && _jsx(TableCell, { ...stickyCol(-1) }), colSlots.map((slot) => slot.type === "spacer" ? (_jsx("td", { role: "presentation", "aria-hidden": "true", style: { padding: 0, border: "none" } }, `__spacer_${slot.side}`)) : (_jsx(TableCell, { align: alignFor(columns[slot.i]), "aria-colindex": colAriaIndex(slot.i), ...dataStickyCol(slot.i), children: columns[slot.i].calc ? (_jsx(ColumnCalc, { rows: rows, value: (row) => cellValue(columns[slot.i], row), numeric: columns[slot.i].type === "number" ||
|
|
1874
|
+
columns[slot.i].type === "currency", defaultOp: columns[slot.i].calc?.defaultOp, op: columns[slot.i].calc?.op, onOpChange: columns[slot.i].calc?.onOpChange, align: alignFor(columns[slot.i]) })) : columns[slot.i].summary ? (columns[slot.i].summary?.(rows)) : null }, columns[slot.i].key)))] })), onAddRow && (_jsx(TableRow, { children: _jsx(TableCell, { className: "crisp-datatable-addcell", colSpan: totalCols, children: _jsxs("button", { type: "button", className: "crisp-datatable-addrow", onClick: onAddRow, children: [_jsx(Plus, { size: 15, strokeWidth: 1.75, "aria-hidden": "true" }), addRowLabel] }) }) }))] }))] })] }));
|
|
1386
1875
|
}
|
|
1387
1876
|
DataTable.displayName = "DataTable";
|