@crispy-seed/data-table 0.4.0 → 0.5.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/index.cjs +767 -154
- package/dist/index.d.ts +96 -2
- package/dist/index.js +767 -155
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -859,18 +859,33 @@ function useDataTableColumnCalc(props) {
|
|
|
859
859
|
return next;
|
|
860
860
|
}
|
|
861
861
|
/**
|
|
862
|
-
* Drag-to-reorder:
|
|
863
|
-
* `
|
|
864
|
-
*
|
|
865
|
-
* equal-valued copy) when either key is missing or
|
|
862
|
+
* Drag-to-reorder: moves `dragKey` to `dropKey`'s own ORIGINAL index (the standard
|
|
863
|
+
* `arrayMove` two-splice shape -- remove `dragKey`, then reinsert it at `dropKey`'s
|
|
864
|
+
* pre-removal index of the now-shorter array), the same semantics dnd-kit's own
|
|
865
|
+
* `arrayMove` uses. A no-op (an equal-valued copy) when either key is missing or
|
|
866
|
+
* they're the same key.
|
|
867
|
+
*
|
|
868
|
+
* An EARLIER version of this function instead reinserted `dragKey` immediately before
|
|
869
|
+
* `dropKey`'s post-removal position. That reads the same for a multi-column jump, but
|
|
870
|
+
* is a silent no-op for the single most common drag gesture there is: dragging a
|
|
871
|
+
* column onto its own immediate RIGHT neighbor. Concretely, for `["a","b"]`, dragging
|
|
872
|
+
* "a" onto "b": removing "a" leaves `["b"]`, and "immediately before b" is index 0 --
|
|
873
|
+
* exactly where "a" already was, so nothing moved even though a real drag-and-drop
|
|
874
|
+
* gesture happened (caught by `DataTable.columns.test.tsx`'s own end-to-end drag test,
|
|
875
|
+
* which fires a real `dragover` DOM event and asserts the header order actually
|
|
876
|
+
* changed -- it didn't). This version's two-splice shape lands the dragged column at
|
|
877
|
+
* the target's own original slot instead, which swaps immediate neighbors correctly in
|
|
878
|
+
* both directions and still matches the old multi-jump behavior for a LEFTWARD drag
|
|
879
|
+
* (only a RIGHTWARD multi-column jump now lands one slot further, after the drop
|
|
880
|
+
* target instead of before it -- see this file's own test for both directions).
|
|
866
881
|
*/ function reorderColumnKey(order, dragKey, dropKey) {
|
|
867
882
|
if (dragKey === dropKey || !order.includes(dragKey) || !order.includes(dropKey)) {
|
|
868
883
|
return [
|
|
869
884
|
...order
|
|
870
885
|
];
|
|
871
886
|
}
|
|
887
|
+
const dropIndex = order.indexOf(dropKey);
|
|
872
888
|
const withoutDrag = order.filter((key)=>key !== dragKey);
|
|
873
|
-
const dropIndex = withoutDrag.indexOf(dropKey);
|
|
874
889
|
return [
|
|
875
890
|
...withoutDrag.slice(0, dropIndex),
|
|
876
891
|
dragKey,
|
|
@@ -882,6 +897,24 @@ function useDataTableColumnCalc(props) {
|
|
|
882
897
|
* nor balloon past a sane cap from one fast mouse move). */ function clampColumnWidth(width, min = 80, max = 640) {
|
|
883
898
|
return Math.min(max, Math.max(min, width));
|
|
884
899
|
}
|
|
900
|
+
/**
|
|
901
|
+
* Reconciles a persisted/controlled PINNED set against the table's current column
|
|
902
|
+
* KEYS -- the same drop-what's-gone rule `reconcileColumnOrder` already applies to
|
|
903
|
+
* `columnOrder`, but pins never need the "append what's new" half of that: an unpinned
|
|
904
|
+
* column simply isn't in the set, appending it here would silently pin every brand-new
|
|
905
|
+
* column by accident. A key no longer in `keys` (hidden isn't "gone" -- only removed
|
|
906
|
+
* from `columns` entirely) is dropped; everything else keeps its order.
|
|
907
|
+
*/ function reconcilePinnedColumns(pinned, keys) {
|
|
908
|
+
const keySet = new Set(keys);
|
|
909
|
+
return pinned.filter((key)=>keySet.has(key));
|
|
910
|
+
}
|
|
911
|
+
/** Pin/unpin: adds `key` if absent, removes it if present -- column-menu.tsx's own
|
|
912
|
+
* "Pin column"/"Unpin column" toggle is one call of this, the same shape
|
|
913
|
+
* `toggleMembership` already gives row selection. Kept as its own named function
|
|
914
|
+
* (rather than reusing `toggleMembership` directly) so a pin-specific doc comment and
|
|
915
|
+
* call sites aren't reading a generically-named helper for a column-specific concern. */ function togglePinnedColumn(pinned, key) {
|
|
916
|
+
return toggleMembership(pinned, key);
|
|
917
|
+
}
|
|
885
918
|
/**
|
|
886
919
|
* Infinite scroll's own gate: fire `onLoadMore` only when the sentinel is ACTUALLY
|
|
887
920
|
* intersecting (not e.g. an observer's initial `false` callback, which fires once on
|
|
@@ -895,19 +928,90 @@ function useDataTableColumnCalc(props) {
|
|
|
895
928
|
*/ function shouldTriggerLoadMore(isIntersecting, hasMore, loadingMore) {
|
|
896
929
|
return hasMore && !loadingMore;
|
|
897
930
|
}
|
|
931
|
+
function isPlainObject(value) {
|
|
932
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
933
|
+
}
|
|
934
|
+
/** Structural validation for ONE parsed view -- every field of `DataTableViewState` is
|
|
935
|
+
* optional, so this only rejects a field that's actually PRESENT but the wrong shape
|
|
936
|
+
* (a consumer's storage from a future/older version of this shape), not a field that's
|
|
937
|
+
* simply missing. */ function isValidDataTableView(value) {
|
|
938
|
+
if (!isPlainObject(value)) return false;
|
|
939
|
+
if (typeof value["id"] !== "string" || typeof value["name"] !== "string") return false;
|
|
940
|
+
if (!isPlainObject(value["state"])) return false;
|
|
941
|
+
const state = value["state"];
|
|
942
|
+
if (state["columnOrder"] !== undefined && !isStringArray(state["columnOrder"])) return false;
|
|
943
|
+
if (state["hiddenColumnKeys"] !== undefined && !isStringArray(state["hiddenColumnKeys"])) return false;
|
|
944
|
+
if (state["pinnedColumnKeys"] !== undefined && !isStringArray(state["pinnedColumnKeys"])) return false;
|
|
945
|
+
if (state["columnWidths"] !== undefined && !isPlainObject(state["columnWidths"])) return false;
|
|
946
|
+
if (state["toolbarSorts"] !== undefined && !Array.isArray(state["toolbarSorts"])) return false;
|
|
947
|
+
if (state["toolbarFilters"] !== undefined && !Array.isArray(state["toolbarFilters"])) return false;
|
|
948
|
+
return true;
|
|
949
|
+
}
|
|
950
|
+
function isStringArray(value) {
|
|
951
|
+
return Array.isArray(value) && value.every((entry)=>typeof entry === "string");
|
|
952
|
+
}
|
|
953
|
+
/** JSON-serializes a saved-views list for the default localStorage store -- pure so it
|
|
954
|
+
* can be unit- and mutation-tested without touching `window.localStorage` at all (the
|
|
955
|
+
* hook's own effect, `useDataTableViews.ts`, is the only thing that actually touches
|
|
956
|
+
* storage; this is just the byte-for-byte shape it writes/reads). */ function serializeDataTableViews(views) {
|
|
957
|
+
return JSON.stringify(views);
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* Parses a saved-views blob back into a `DataTableView[]`, defensively: malformed JSON,
|
|
961
|
+
* a non-array root, or any single malformed entry drops just that problem (an empty
|
|
962
|
+
* list, or that one entry) rather than throwing -- a consumer's localStorage can hold a
|
|
963
|
+
* PRIOR version's shape after this ships a new field, and one bad/stale entry shouldn't
|
|
964
|
+
* cost every other saved view.
|
|
965
|
+
*/ function deserializeDataTableViews(raw) {
|
|
966
|
+
if (!raw) return [];
|
|
967
|
+
let parsed;
|
|
968
|
+
try {
|
|
969
|
+
parsed = JSON.parse(raw);
|
|
970
|
+
} catch {
|
|
971
|
+
return [];
|
|
972
|
+
}
|
|
973
|
+
if (!Array.isArray(parsed)) return [];
|
|
974
|
+
return parsed.filter(isValidDataTableView);
|
|
975
|
+
}
|
|
976
|
+
/** Inserts `view` (by `id`), or replaces the existing entry with the same `id` in
|
|
977
|
+
* place -- "Save" (new view) and "update the currently loaded view" are both one call
|
|
978
|
+
* of this, matching `moveColumnKey`/`reorderColumnKey`'s own "one pure op per user
|
|
979
|
+
* gesture" shape. */ function upsertDataTableView(views, view) {
|
|
980
|
+
const index = views.findIndex((existing)=>existing.id === view.id);
|
|
981
|
+
if (index === -1) return [
|
|
982
|
+
...views,
|
|
983
|
+
view
|
|
984
|
+
];
|
|
985
|
+
const next = [
|
|
986
|
+
...views
|
|
987
|
+
];
|
|
988
|
+
next[index] = view;
|
|
989
|
+
return next;
|
|
990
|
+
}
|
|
991
|
+
/** Renames the view with this `id` -- a no-op (an equal-valued copy) if no view has
|
|
992
|
+
* that id. */ function renameDataTableView(views, id, name) {
|
|
993
|
+
return views.map((view)=>view.id === id ? {
|
|
994
|
+
...view,
|
|
995
|
+
name
|
|
996
|
+
} : view);
|
|
997
|
+
}
|
|
998
|
+
/** Removes the view with this `id`. */ function removeDataTableView(views, id) {
|
|
999
|
+
return views.filter((view)=>view.id !== id);
|
|
1000
|
+
}
|
|
898
1001
|
const EMPTY_STRINGS = [];
|
|
899
1002
|
const EMPTY_RECORD = {};
|
|
900
1003
|
/**
|
|
901
1004
|
* Owns everything DATATABLE-ATTIO-SPEC.md's column menu + reorder + resize tranche
|
|
902
|
-
* needs -- order, visibility, a per-column label override,
|
|
903
|
-
*
|
|
904
|
-
*
|
|
905
|
-
*
|
|
906
|
-
* separate ones; drag-to-reorder
|
|
907
|
-
* built on top of the order/width
|
|
1005
|
+
* needs -- order, visibility, a per-column label override, a per-column width, and
|
|
1006
|
+
* (Attio's "Pin column") a per-column left-pinned flag -- the way useDataTableSelection
|
|
1007
|
+
* owns the one selected-id SET rather than one hook per row. All five are "one value
|
|
1008
|
+
* per column key" maps/lists/sets a consumer may want to persist (a saved view), so
|
|
1009
|
+
* they share this hook instead of splitting into five separate ones; drag-to-reorder
|
|
1010
|
+
* and drag-to-resize (below) are the two INTERACTIONS built on top of the order/width
|
|
1011
|
+
* state this hook already owns, not independent state
|
|
908
1012
|
* of their own.
|
|
909
1013
|
*/ function useDataTableColumns(props) {
|
|
910
|
-
const { columnKeys = EMPTY_STRINGS, columnOrder: columnOrderProp, defaultColumnOrder, onColumnOrderChange, hiddenColumnKeys: hiddenProp, defaultHiddenColumnKeys = EMPTY_STRINGS, onHiddenColumnKeysChange, columnWidths: widthsProp, defaultColumnWidths = EMPTY_RECORD, onColumnWidthsChange, columnLabels: labelsProp, defaultColumnLabels = EMPTY_RECORD, onColumnLabelsChange } = props;
|
|
1014
|
+
const { columnKeys = EMPTY_STRINGS, columnOrder: columnOrderProp, defaultColumnOrder, onColumnOrderChange, hiddenColumnKeys: hiddenProp, defaultHiddenColumnKeys = EMPTY_STRINGS, onHiddenColumnKeysChange, columnWidths: widthsProp, defaultColumnWidths = EMPTY_RECORD, onColumnWidthsChange, columnLabels: labelsProp, defaultColumnLabels = EMPTY_RECORD, onColumnLabelsChange, pinnedColumnKeys: pinnedProp, defaultPinnedColumnKeys = EMPTY_STRINGS, onPinnedColumnKeysChange } = props;
|
|
911
1015
|
const [rawOrder, setRawOrder] = useControllableState$1({
|
|
912
1016
|
prop: columnOrderProp,
|
|
913
1017
|
defaultProp: defaultColumnOrder ?? columnKeys,
|
|
@@ -944,6 +1048,36 @@ const EMPTY_RECORD = {};
|
|
|
944
1048
|
columnOrder,
|
|
945
1049
|
hiddenSet
|
|
946
1050
|
]);
|
|
1051
|
+
const [rawPinnedColumnKeys, setRawPinnedColumnKeys] = useControllableState$1({
|
|
1052
|
+
prop: pinnedProp,
|
|
1053
|
+
defaultProp: defaultPinnedColumnKeys,
|
|
1054
|
+
onChange: onPinnedColumnKeysChange
|
|
1055
|
+
});
|
|
1056
|
+
// Reconciled against `columnKeys` every render, the same way `columnOrder` is above --
|
|
1057
|
+
// a controlled `pinnedColumnKeys` a consumer persisted (e.g. a saved view) before a
|
|
1058
|
+
// column was removed from `columns` must not keep pinning a ghost key.
|
|
1059
|
+
const pinnedColumnKeys = useMemo(()=>reconcilePinnedColumns(rawPinnedColumnKeys ?? EMPTY_STRINGS, columnKeys), [
|
|
1060
|
+
rawPinnedColumnKeys,
|
|
1061
|
+
columnKeys
|
|
1062
|
+
]);
|
|
1063
|
+
const pinnedSet = useMemo(()=>new Set(pinnedColumnKeys), [
|
|
1064
|
+
pinnedColumnKeys
|
|
1065
|
+
]);
|
|
1066
|
+
const isColumnPinned = useCallback((key)=>pinnedSet.has(key), [
|
|
1067
|
+
pinnedSet
|
|
1068
|
+
]);
|
|
1069
|
+
const pinColumn = useCallback((key)=>setRawPinnedColumnKeys((current = EMPTY_STRINGS)=>current.includes(key) ? current : [
|
|
1070
|
+
...current,
|
|
1071
|
+
key
|
|
1072
|
+
]), [
|
|
1073
|
+
setRawPinnedColumnKeys
|
|
1074
|
+
]);
|
|
1075
|
+
const unpinColumn = useCallback((key)=>setRawPinnedColumnKeys((current = EMPTY_STRINGS)=>current.filter((existing)=>existing !== key)), [
|
|
1076
|
+
setRawPinnedColumnKeys
|
|
1077
|
+
]);
|
|
1078
|
+
const togglePinColumn = useCallback((key)=>setRawPinnedColumnKeys((current = EMPTY_STRINGS)=>togglePinnedColumn(current, key)), [
|
|
1079
|
+
setRawPinnedColumnKeys
|
|
1080
|
+
]);
|
|
947
1081
|
const isColumnHidden = useCallback((key)=>hiddenSet.has(key), [
|
|
948
1082
|
hiddenSet
|
|
949
1083
|
]);
|
|
@@ -988,22 +1122,30 @@ const EMPTY_RECORD = {};
|
|
|
988
1122
|
columnKeys
|
|
989
1123
|
]);
|
|
990
1124
|
// -- drag-to-reorder ---------------------------------------------------------------
|
|
991
|
-
// Live state only (which column is currently being dragged) -- the styled layer
|
|
992
|
-
//
|
|
993
|
-
//
|
|
994
|
-
//
|
|
995
|
-
//
|
|
996
|
-
//
|
|
997
|
-
//
|
|
1125
|
+
// Live state only (which column is currently being dragged) -- the styled layer's
|
|
1126
|
+
// header cells are natively `draggable`, so `dragOverColumn` is driven straight off
|
|
1127
|
+
// each cell's own `onDragOver` (one real browser event per column the pointer
|
|
1128
|
+
// crosses), which reorders immediately rather than waiting for a drop. That is
|
|
1129
|
+
// exactly what Attio's own header drag does (the column being passed visibly swaps
|
|
1130
|
+
// live), and it means `endColumnDrag` never has to also commit a move -- there is
|
|
1131
|
+
// nothing left to commit.
|
|
998
1132
|
const [draggingColumnKey, setDraggingColumnKey] = useState(null);
|
|
999
1133
|
const beginColumnDrag = useCallback((key)=>setDraggingColumnKey(key), []);
|
|
1134
|
+
// Reads `draggingColumnKey` straight from this render's own closure rather than via
|
|
1135
|
+
// `setDraggingColumnKey`'s functional-updater form (an earlier version of this hook
|
|
1136
|
+
// nested the `reorderColumn` call inside that updater, to read a "live" value --
|
|
1137
|
+
// `draggingColumnKey` never actually CHANGES during a drag, so that state update was
|
|
1138
|
+
// pure ceremony, and nesting one hook's setState inside another's updater callback is
|
|
1139
|
+
// exactly what silently dropped the reorder in DataTable.columns.test.tsx's own
|
|
1140
|
+
// end-to-end drag test: a REAL `dragover` DOM event fired, `dragOverColumn` fired with
|
|
1141
|
+
// the right key, but `columnOrder` never actually moved). Each `onDragOver` is its own
|
|
1142
|
+
// discrete browser event (not a tight synchronous loop within one render), so a plain
|
|
1143
|
+
// closure read is exactly as live as the updater trick was trying to be.
|
|
1000
1144
|
const dragOverColumn = useCallback((hoverKey)=>{
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
reorderColumn(current, hoverKey);
|
|
1004
|
-
return current;
|
|
1005
|
-
});
|
|
1145
|
+
if (!draggingColumnKey || draggingColumnKey === hoverKey) return;
|
|
1146
|
+
reorderColumn(draggingColumnKey, hoverKey);
|
|
1006
1147
|
}, [
|
|
1148
|
+
draggingColumnKey,
|
|
1007
1149
|
reorderColumn
|
|
1008
1150
|
]);
|
|
1009
1151
|
const endColumnDrag = useCallback(()=>setDraggingColumnKey(null), []);
|
|
@@ -1039,10 +1181,15 @@ const EMPTY_RECORD = {};
|
|
|
1039
1181
|
hiddenColumnKeys,
|
|
1040
1182
|
columnWidths,
|
|
1041
1183
|
columnLabels,
|
|
1184
|
+
pinnedColumnKeys,
|
|
1042
1185
|
isColumnHidden,
|
|
1043
1186
|
hideColumn,
|
|
1044
1187
|
showColumn,
|
|
1045
1188
|
toggleColumnVisibility,
|
|
1189
|
+
isColumnPinned,
|
|
1190
|
+
pinColumn,
|
|
1191
|
+
unpinColumn,
|
|
1192
|
+
togglePinColumn,
|
|
1046
1193
|
getColumnLabel,
|
|
1047
1194
|
renameColumn,
|
|
1048
1195
|
getColumnWidth,
|
|
@@ -1691,7 +1838,7 @@ function useDataTableRowContext({ strict = true } = {}) {
|
|
|
1691
1838
|
return context;
|
|
1692
1839
|
}
|
|
1693
1840
|
const DataTableRoot = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
1694
|
-
const { sort, defaultSort, onSortChange, rowIds, selectable, selectedIds, defaultSelectedIds, onSelectionChange, query, defaultQuery, onQueryChange, toolbarSorts, defaultToolbarSorts, onToolbarSortsChange, toolbarFilters, defaultToolbarFilters, onToolbarFiltersChange, columnKeys, columnOrder, defaultColumnOrder, onColumnOrderChange, hiddenColumnKeys, defaultHiddenColumnKeys, onHiddenColumnKeysChange, columnWidths, defaultColumnWidths, onColumnWidthsChange, columnLabels, defaultColumnLabels, onColumnLabelsChange, columnCalcOps, defaultColumnCalcOps, onColumnCalcOpsChange, onEdit, onLoadMore, hasMore, loadingMore, ...otherProps } = props;
|
|
1841
|
+
const { sort, defaultSort, onSortChange, rowIds, selectable, selectedIds, defaultSelectedIds, onSelectionChange, query, defaultQuery, onQueryChange, toolbarSorts, defaultToolbarSorts, onToolbarSortsChange, toolbarFilters, defaultToolbarFilters, onToolbarFiltersChange, columnKeys, columnOrder, defaultColumnOrder, onColumnOrderChange, hiddenColumnKeys, defaultHiddenColumnKeys, onHiddenColumnKeysChange, columnWidths, defaultColumnWidths, onColumnWidthsChange, columnLabels, defaultColumnLabels, onColumnLabelsChange, pinnedColumnKeys, defaultPinnedColumnKeys, onPinnedColumnKeysChange, columnCalcOps, defaultColumnCalcOps, onColumnCalcOpsChange, onEdit, onLoadMore, hasMore, loadingMore, ...otherProps } = props;
|
|
1695
1842
|
const api = useDataTable({
|
|
1696
1843
|
sort,
|
|
1697
1844
|
defaultSort,
|
|
@@ -1723,6 +1870,9 @@ const DataTableRoot = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
1723
1870
|
columnLabels,
|
|
1724
1871
|
defaultColumnLabels,
|
|
1725
1872
|
onColumnLabelsChange,
|
|
1873
|
+
pinnedColumnKeys,
|
|
1874
|
+
defaultPinnedColumnKeys,
|
|
1875
|
+
onPinnedColumnKeysChange,
|
|
1726
1876
|
columnCalcOps,
|
|
1727
1877
|
defaultColumnCalcOps,
|
|
1728
1878
|
onColumnCalcOpsChange,
|
|
@@ -1810,6 +1960,132 @@ const DataTableCell$1 = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
|
1810
1960
|
});
|
|
1811
1961
|
DataTableCell$1.displayName = "DataTableCell";
|
|
1812
1962
|
|
|
1963
|
+
const EMPTY_VIEWS = [];
|
|
1964
|
+
function readStoredViews(storageKey) {
|
|
1965
|
+
if (!storageKey || typeof window === "undefined") return EMPTY_VIEWS;
|
|
1966
|
+
try {
|
|
1967
|
+
return deserializeDataTableViews(window.localStorage.getItem(storageKey));
|
|
1968
|
+
} catch {
|
|
1969
|
+
// A private-browsing tab / blocked storage throws on access, not just on quota --
|
|
1970
|
+
// this hook degrades to in-memory-only rather than crash the table over it.
|
|
1971
|
+
return EMPTY_VIEWS;
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
/** A reasonably unique id for a newly created view -- `crypto.randomUUID` where it
|
|
1975
|
+
* exists (every real browser + modern Node), a plain timestamp+random fallback
|
|
1976
|
+
* otherwise (older jsdom/test environments) so this hook never throws just because a
|
|
1977
|
+
* test runner's `crypto` is a stub. */ function generateViewId() {
|
|
1978
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
1979
|
+
return crypto.randomUUID();
|
|
1980
|
+
}
|
|
1981
|
+
return `view-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
1982
|
+
}
|
|
1983
|
+
/**
|
|
1984
|
+
* Owns the saved-views LIST (create/rename/delete/select) and its default persistence
|
|
1985
|
+
* (localStorage, pluggable away by controlling `views`/`onViewsChange` instead) -- the
|
|
1986
|
+
* same controllable shape every other DataTable state hook already uses
|
|
1987
|
+
* (`useDataTableColumns`, `useDataTableToolbarSort`, ...). Read `DataTableViewsControl`
|
|
1988
|
+
* (`views.tsx`, the styled layer) for how a consumer wires `captureState`/`applyState`
|
|
1989
|
+
* around this to actually save/restore column + sort + filter state.
|
|
1990
|
+
*/ function useDataTableViews(props) {
|
|
1991
|
+
const { views: viewsProp, defaultViews = EMPTY_VIEWS, onViewsChange, activeViewId: activeViewIdProp, defaultActiveViewId = null, onActiveViewIdChange, storageKey } = props;
|
|
1992
|
+
// Lazy, ONE-TIME read of localStorage as this render's default -- re-reading it on
|
|
1993
|
+
// every render (rather than a lazy ref) would clobber whatever the user just did in
|
|
1994
|
+
// THIS tab with whatever another tab most recently wrote. Only fires at all when this
|
|
1995
|
+
// hook truly owns persistence: `views` is uncontrolled AND a `storageKey` was given.
|
|
1996
|
+
const initialViewsRef = useRef(null);
|
|
1997
|
+
if (initialViewsRef.current === null) {
|
|
1998
|
+
if (viewsProp !== undefined) {
|
|
1999
|
+
initialViewsRef.current = defaultViews;
|
|
2000
|
+
} else {
|
|
2001
|
+
const stored = readStoredViews(storageKey);
|
|
2002
|
+
// Nothing in storage yet (first run, or no `storageKey` at all) -- seed from
|
|
2003
|
+
// `defaultViews` instead of an empty list, matching every other hook's own
|
|
2004
|
+
// `defaultProp` semantics.
|
|
2005
|
+
initialViewsRef.current = stored.length > 0 ? stored : defaultViews;
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
const [views = EMPTY_VIEWS, setViews] = useControllableState$1({
|
|
2009
|
+
prop: viewsProp,
|
|
2010
|
+
defaultProp: initialViewsRef.current,
|
|
2011
|
+
onChange: onViewsChange
|
|
2012
|
+
});
|
|
2013
|
+
// Persists every change back to `storageKey` -- same "only when this hook owns
|
|
2014
|
+
// persistence" gate as the lazy read above. Skips the FIRST render (the effect would
|
|
2015
|
+
// otherwise immediately re-write back the exact bytes it just read, or stomp an
|
|
2016
|
+
// empty default over a controlled consumer's storage before it ever mounts).
|
|
2017
|
+
const skipFirstPersistRef = useRef(true);
|
|
2018
|
+
useEffect(()=>{
|
|
2019
|
+
if (viewsProp !== undefined || !storageKey || typeof window === "undefined") return;
|
|
2020
|
+
if (skipFirstPersistRef.current) {
|
|
2021
|
+
skipFirstPersistRef.current = false;
|
|
2022
|
+
return;
|
|
2023
|
+
}
|
|
2024
|
+
try {
|
|
2025
|
+
window.localStorage.setItem(storageKey, serializeDataTableViews(views));
|
|
2026
|
+
} catch {
|
|
2027
|
+
// Storage full/blocked -- the view still exists in memory for this session.
|
|
2028
|
+
}
|
|
2029
|
+
}, [
|
|
2030
|
+
views,
|
|
2031
|
+
viewsProp,
|
|
2032
|
+
storageKey
|
|
2033
|
+
]);
|
|
2034
|
+
const [activeViewId = null, setActiveViewId] = useControllableState$1({
|
|
2035
|
+
prop: activeViewIdProp,
|
|
2036
|
+
defaultProp: defaultActiveViewId,
|
|
2037
|
+
onChange: onActiveViewIdChange
|
|
2038
|
+
});
|
|
2039
|
+
const activeView = views.find((view)=>view.id === activeViewId) ?? null;
|
|
2040
|
+
const createView = useCallback((name, state)=>{
|
|
2041
|
+
const id = generateViewId();
|
|
2042
|
+
setViews((current = EMPTY_VIEWS)=>upsertDataTableView(current, {
|
|
2043
|
+
id,
|
|
2044
|
+
name,
|
|
2045
|
+
state
|
|
2046
|
+
}));
|
|
2047
|
+
setActiveViewId(id);
|
|
2048
|
+
return id;
|
|
2049
|
+
}, [
|
|
2050
|
+
setViews,
|
|
2051
|
+
setActiveViewId
|
|
2052
|
+
]);
|
|
2053
|
+
const updateView = useCallback((id, state)=>{
|
|
2054
|
+
setViews((current = EMPTY_VIEWS)=>{
|
|
2055
|
+
const existing = current.find((view)=>view.id === id);
|
|
2056
|
+
return existing ? upsertDataTableView(current, {
|
|
2057
|
+
...existing,
|
|
2058
|
+
state
|
|
2059
|
+
}) : current;
|
|
2060
|
+
});
|
|
2061
|
+
}, [
|
|
2062
|
+
setViews
|
|
2063
|
+
]);
|
|
2064
|
+
const renameView = useCallback((id, name)=>setViews((current = EMPTY_VIEWS)=>renameDataTableView(current, id, name)), [
|
|
2065
|
+
setViews
|
|
2066
|
+
]);
|
|
2067
|
+
const deleteView = useCallback((id)=>{
|
|
2068
|
+
setViews((current = EMPTY_VIEWS)=>removeDataTableView(current, id));
|
|
2069
|
+
setActiveViewId((current)=>current === id ? null : current);
|
|
2070
|
+
}, [
|
|
2071
|
+
setViews,
|
|
2072
|
+
setActiveViewId
|
|
2073
|
+
]);
|
|
2074
|
+
const selectView = useCallback((id)=>setActiveViewId(id), [
|
|
2075
|
+
setActiveViewId
|
|
2076
|
+
]);
|
|
2077
|
+
return {
|
|
2078
|
+
views,
|
|
2079
|
+
activeViewId,
|
|
2080
|
+
activeView,
|
|
2081
|
+
createView,
|
|
2082
|
+
updateView,
|
|
2083
|
+
renameView,
|
|
2084
|
+
deleteView,
|
|
2085
|
+
selectView
|
|
2086
|
+
};
|
|
2087
|
+
}
|
|
2088
|
+
|
|
1813
2089
|
function r(e) {
|
|
1814
2090
|
var t, f, n = "";
|
|
1815
2091
|
if ("string" == typeof e || "number" == typeof e) n += e;
|
|
@@ -2335,76 +2611,121 @@ function RatingCell({ value, maxRating = 5 }) {
|
|
|
2335
2611
|
});
|
|
2336
2612
|
}
|
|
2337
2613
|
|
|
2338
|
-
/**
|
|
2339
|
-
*
|
|
2340
|
-
*
|
|
2341
|
-
*
|
|
2342
|
-
|
|
2614
|
+
/** Fallback width (px) used to compute a pinned column's cumulative sticky offset when
|
|
2615
|
+
* it has no explicit `width` and hasn't been drag-resized -- pinning needs a STATIC
|
|
2616
|
+
* number to put in an inline `insetInlineStart`, and `table-layout: fixed` only
|
|
2617
|
+
* decides how an unset column's share of the leftover width actually renders at paint
|
|
2618
|
+
* time (something no amount of JS math here can know ahead of it). Matches
|
|
2619
|
+
* `clampColumnWidth`'s own floor (react-headless's `dom.ts`) -- a real pinned column
|
|
2620
|
+
* narrower than this only needs its offset "wide enough not to overlap", not exact. */ const DEFAULT_PINNED_COLUMN_WIDTH = 180;
|
|
2621
|
+
/**
|
|
2622
|
+
* Every column this table actually renders, in RENDER order: any pinned columns first
|
|
2623
|
+
* (their own relative order preserved from `visibleColumnOrder`, not a separate pin-
|
|
2624
|
+
* order of their own), then everything else in normal order -- resolved label/width,
|
|
2625
|
+
* and this file's own sticky-left bookkeeping (`pinned`/`pinOffset`/`pinnedEdge`). Read
|
|
2626
|
+
* by the header, the body, the ColumnCalc footer AND the `<colgroup>` alike -- all four
|
|
2627
|
+
* must agree on this exact order, since a `<colgroup>`'s `<col>`s are matched
|
|
2628
|
+
* POSITIONALLY to every row's cells; splitting "order" (here) from "which one is
|
|
2629
|
+
* pinned" into two independently-ordered helpers would let a `<colgroup>` built from
|
|
2630
|
+
* one and a header row built from the other drift out of sync under `table-layout:
|
|
2631
|
+
* fixed`'s own column-to-cell matching.
|
|
2632
|
+
*/ function useEffectiveColumns(columns, options) {
|
|
2633
|
+
const { visibleColumnOrder, getColumnLabel, getColumnWidth, pinnedColumnKeys } = useDataTableContext();
|
|
2634
|
+
const { selectable, stickyFirst } = options;
|
|
2343
2635
|
return React.useMemo(()=>{
|
|
2344
2636
|
const byKey = new Map(columns.map((column)=>[
|
|
2345
2637
|
column.key,
|
|
2346
2638
|
column
|
|
2347
2639
|
]));
|
|
2348
|
-
|
|
2640
|
+
const visibleKeySet = new Set(visibleColumnOrder);
|
|
2641
|
+
const explicitPins = new Set((pinnedColumnKeys ?? []).filter((key)=>byKey.has(key) && visibleKeySet.has(key)));
|
|
2642
|
+
// Legacy fallback (DataTable.columns.test.tsx's own `stickyFirst` tests, predating
|
|
2643
|
+
// per-column pin): no EXPLICIT pin at all, `stickyFirst` pins exactly the first
|
|
2644
|
+
// visible column -- the single-column behavior this file now generalizes to a
|
|
2645
|
+
// whole pinned GROUP.
|
|
2646
|
+
const pinnedSet = explicitPins.size > 0 ? explicitPins : stickyFirst && visibleColumnOrder.length > 0 ? new Set([
|
|
2647
|
+
visibleColumnOrder[0]
|
|
2648
|
+
]) : explicitPins;
|
|
2649
|
+
// Stable partition: pinned columns first (their relative order among THEMSELVES
|
|
2650
|
+
// preserved from `visibleColumnOrder`), then every other column, also in its
|
|
2651
|
+
// existing relative order. `Array.prototype.sort` is spec-stable (ES2019+).
|
|
2652
|
+
const ordered = [
|
|
2653
|
+
...visibleColumnOrder
|
|
2654
|
+
].sort((a, b)=>{
|
|
2655
|
+
const aPinned = pinnedSet.has(a) ? 0 : 1;
|
|
2656
|
+
const bPinned = pinnedSet.has(b) ? 0 : 1;
|
|
2657
|
+
return aPinned - bPinned;
|
|
2658
|
+
});
|
|
2659
|
+
let cursor = selectable ? 40 : 0;
|
|
2660
|
+
let pinnedCount = 0;
|
|
2661
|
+
const entries = ordered.map((key)=>byKey.get(key)).filter((column)=>Boolean(column)).map((column)=>{
|
|
2662
|
+
const width = getColumnWidth(column.key) ?? column.width;
|
|
2663
|
+
const pinned = pinnedSet.has(column.key);
|
|
2664
|
+
const pinOffset = pinned ? cursor : 0;
|
|
2665
|
+
if (pinned) {
|
|
2666
|
+
cursor += width ?? DEFAULT_PINNED_COLUMN_WIDTH;
|
|
2667
|
+
pinnedCount += 1;
|
|
2668
|
+
}
|
|
2669
|
+
return {
|
|
2349
2670
|
column,
|
|
2350
2671
|
label: getColumnLabel(column.key, column.header),
|
|
2351
|
-
width
|
|
2352
|
-
|
|
2672
|
+
width,
|
|
2673
|
+
pinned,
|
|
2674
|
+
pinOffset,
|
|
2675
|
+
pinnedEdge: false
|
|
2676
|
+
};
|
|
2677
|
+
});
|
|
2678
|
+
if (pinnedCount > 0) entries[pinnedCount - 1].pinnedEdge = true;
|
|
2679
|
+
return entries;
|
|
2353
2680
|
}, [
|
|
2354
2681
|
columns,
|
|
2355
2682
|
visibleColumnOrder,
|
|
2356
2683
|
getColumnLabel,
|
|
2357
|
-
getColumnWidth
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
*
|
|
2365
|
-
*
|
|
2366
|
-
*
|
|
2367
|
-
*
|
|
2368
|
-
*
|
|
2369
|
-
*
|
|
2370
|
-
*
|
|
2371
|
-
*
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
style: {
|
|
2396
|
-
insetInlineStart: 0
|
|
2397
|
-
}
|
|
2398
|
-
};
|
|
2399
|
-
}
|
|
2400
|
-
if (stickyFirst && isFirst && selectable) {
|
|
2401
|
-
// The trailing edge of the pinned group -- past the 40px selection cell, so this
|
|
2402
|
-
// is where the scroll shadow actually renders unobstructed.
|
|
2684
|
+
getColumnWidth,
|
|
2685
|
+
pinnedColumnKeys,
|
|
2686
|
+
selectable,
|
|
2687
|
+
stickyFirst
|
|
2688
|
+
]);
|
|
2689
|
+
}
|
|
2690
|
+
/** The 40px selection column's own sticky-left state -- `stickyFirst` (the table-wide
|
|
2691
|
+
* prop) alone undercounts "should the checkbox column stick" the moment ANY per-column
|
|
2692
|
+
* pin is live, controlled or not, since the live pinned SET only exists once
|
|
2693
|
+
* `DataTablePrimitiveRoot`'s provider has mounted (an uncontrolled consumer never
|
|
2694
|
+
* hands its pinned columns back up as a prop for `DataTable.tsx` to read directly).
|
|
2695
|
+
* Mirrors `DataTable.tsx`'s own `resolvedStickyLast = stickyLast ||
|
|
2696
|
+
* columns.some(actions)` widening, just resolved one level down (live STATE, not
|
|
2697
|
+
* static column config) -- read via context from a component under the provider, not
|
|
2698
|
+
* computed above it. */ function useSelectionStickyFirst(stickyFirst) {
|
|
2699
|
+
const { pinnedColumnKeys } = useDataTableContext();
|
|
2700
|
+
return stickyFirst || (pinnedColumnKeys?.length ?? 0) > 0;
|
|
2701
|
+
}
|
|
2702
|
+
/** Sticky positioning for the 40px SELECTION cell only (header/body/footer) -- data
|
|
2703
|
+
* columns use their own `pinned`/`pinOffset`/`pinnedEdge` (`useEffectiveColumns`,
|
|
2704
|
+
* above) instead, via `pinnedCellProps` below. The selection cell is always the
|
|
2705
|
+
* leading edge of the pinned-left group when it's sticky at all, so it never itself
|
|
2706
|
+
* carries `data-sticky-edge` -- the trailing-most pinned DATA column does (its own
|
|
2707
|
+
* `pinnedEdge`), the same split the original single-column `stickyFirst` already drew
|
|
2708
|
+
* between the selection cell and Company/Name. */ function selectionStickyProps(stickyFirst) {
|
|
2709
|
+
return stickyFirst ? {
|
|
2710
|
+
"data-sticky": "",
|
|
2711
|
+
style: {
|
|
2712
|
+
insetInlineStart: 0
|
|
2713
|
+
}
|
|
2714
|
+
} : {};
|
|
2715
|
+
}
|
|
2716
|
+
/** Sticky positioning for one DATA cell (header, body, or ColumnCalc footer) -- pinned-
|
|
2717
|
+
* left (this column's own `pinOffset`, `data-sticky-edge` only on the group's
|
|
2718
|
+
* trailing-most member) takes priority over sticky-right (`stickyLast`, always just
|
|
2719
|
+
* the last VISIBLE column, e.g. an `actions` column) since a column can only stick to
|
|
2720
|
+
* one edge. */ function pinnedCellProps(entry, stickyLast, isLast) {
|
|
2721
|
+
if (entry.pinned) {
|
|
2403
2722
|
return {
|
|
2404
2723
|
"data-sticky": "",
|
|
2405
|
-
|
|
2724
|
+
...entry.pinnedEdge ? {
|
|
2725
|
+
"data-sticky-edge": ""
|
|
2726
|
+
} : {},
|
|
2406
2727
|
style: {
|
|
2407
|
-
insetInlineStart:
|
|
2728
|
+
insetInlineStart: entry.pinOffset
|
|
2408
2729
|
}
|
|
2409
2730
|
};
|
|
2410
2731
|
}
|
|
@@ -3452,20 +3773,16 @@ function RatingEditor({ column, value, pending, onCommit }) {
|
|
|
3452
3773
|
return column.editor === "switch" || column.type === "rating" || column.type === "checkbox";
|
|
3453
3774
|
}
|
|
3454
3775
|
function ColumnBodyCells({ columns, row, classNames, locale, selectable, stickyFirst, stickyLast }) {
|
|
3455
|
-
const effective = useEffectiveColumns(columns
|
|
3776
|
+
const effective = useEffectiveColumns(columns, {
|
|
3777
|
+
selectable,
|
|
3778
|
+
stickyFirst
|
|
3779
|
+
});
|
|
3456
3780
|
const { startEdit } = useDataTableContext();
|
|
3457
3781
|
return /*#__PURE__*/ jsx(Fragment, {
|
|
3458
|
-
children: effective.map((
|
|
3459
|
-
const
|
|
3782
|
+
children: effective.map((entry, index)=>{
|
|
3783
|
+
const { column } = entry;
|
|
3460
3784
|
const isLast = index === effective.length - 1;
|
|
3461
|
-
const sticky =
|
|
3462
|
-
selectable,
|
|
3463
|
-
stickyFirst,
|
|
3464
|
-
stickyLast,
|
|
3465
|
-
isSelectionCell: false,
|
|
3466
|
-
isFirst,
|
|
3467
|
-
isLast
|
|
3468
|
-
});
|
|
3785
|
+
const sticky = pinnedCellProps(entry, stickyLast, isLast);
|
|
3469
3786
|
// A gated `editable` column (everything except the always-live widgets)
|
|
3470
3787
|
// opens on double-click -- Attio's own measured gesture (crisp's #411),
|
|
3471
3788
|
// matched here rather than a single click, which stays "select this cell"
|
|
@@ -3701,19 +4018,15 @@ const MenuItemLabel = withItemContext(withItemStateProps(Primitive.span), "label
|
|
|
3701
4018
|
withItemContext(withItemStateProps(Primitive.span), "description");
|
|
3702
4019
|
|
|
3703
4020
|
function ColumnCalcCells({ columns, rows, selectable, stickyFirst, stickyLast }) {
|
|
3704
|
-
const effective = useEffectiveColumns(columns
|
|
4021
|
+
const effective = useEffectiveColumns(columns, {
|
|
4022
|
+
selectable,
|
|
4023
|
+
stickyFirst
|
|
4024
|
+
});
|
|
3705
4025
|
return /*#__PURE__*/ jsx(Fragment, {
|
|
3706
|
-
children: effective.map((
|
|
3707
|
-
const
|
|
4026
|
+
children: effective.map((entry, index)=>{
|
|
4027
|
+
const { column } = entry;
|
|
3708
4028
|
const isLast = index === effective.length - 1;
|
|
3709
|
-
const sticky =
|
|
3710
|
-
selectable,
|
|
3711
|
-
stickyFirst,
|
|
3712
|
-
stickyLast,
|
|
3713
|
-
isSelectionCell: false,
|
|
3714
|
-
isFirst,
|
|
3715
|
-
isLast
|
|
3716
|
-
});
|
|
4029
|
+
const sticky = pinnedCellProps(entry, stickyLast, isLast);
|
|
3717
4030
|
return /*#__PURE__*/ jsx(DataTableFooterCell, {
|
|
3718
4031
|
"data-sticky": sticky["data-sticky"],
|
|
3719
4032
|
"data-sticky-edge": sticky["data-sticky-edge"],
|
|
@@ -3897,20 +4210,16 @@ const DEFAULT_SORT_ICON = {
|
|
|
3897
4210
|
* `visibleColumnOrder`/labels/widths change, without also re-deriving `sortedData`'s
|
|
3898
4211
|
* render above it. */ function ColumnHeaderCells({ columns, columnMenu, reorderable, resizable, sortIcon, selectable, stickyFirst, stickyLast }) {
|
|
3899
4212
|
const { draggingColumnKey, beginColumnDrag, dragOverColumn, endColumnDrag } = useDataTableContext();
|
|
3900
|
-
const effective = useEffectiveColumns(columns
|
|
4213
|
+
const effective = useEffectiveColumns(columns, {
|
|
4214
|
+
selectable,
|
|
4215
|
+
stickyFirst
|
|
4216
|
+
});
|
|
3901
4217
|
const [renamingKey, setRenamingKey] = React.useState(null);
|
|
3902
4218
|
return /*#__PURE__*/ jsx(Fragment, {
|
|
3903
|
-
children: effective.map((
|
|
3904
|
-
const
|
|
4219
|
+
children: effective.map((entry, index)=>{
|
|
4220
|
+
const { column, label, width } = entry;
|
|
3905
4221
|
const isLast = index === effective.length - 1;
|
|
3906
|
-
const sticky =
|
|
3907
|
-
selectable,
|
|
3908
|
-
stickyFirst,
|
|
3909
|
-
stickyLast,
|
|
3910
|
-
isSelectionCell: false,
|
|
3911
|
-
isFirst,
|
|
3912
|
-
isLast
|
|
3913
|
-
});
|
|
4222
|
+
const sticky = pinnedCellProps(entry, stickyLast, isLast);
|
|
3914
4223
|
return /*#__PURE__*/ jsxs(DataTableHeaderCell, {
|
|
3915
4224
|
columnKey: column.key,
|
|
3916
4225
|
sortable: column.sortable,
|
|
@@ -4040,8 +4349,9 @@ function ColumnRenameInput({ column, initialLabel, onDone }) {
|
|
|
4040
4349
|
* permanently, so this one carries its own marker attribute distinct from that
|
|
4041
4350
|
* slot's OTHER occupants (the sort chevron, the filter trigger), which stay visible
|
|
4042
4351
|
* under their own separate rules regardless of hover. */ function ColumnMenu({ column, onRename }) {
|
|
4043
|
-
const { moveColumn, hideColumn } = useDataTableContext();
|
|
4352
|
+
const { moveColumn, hideColumn, isColumnPinned, togglePinColumn } = useDataTableContext();
|
|
4044
4353
|
const columnLabel = typeof column.header === "string" ? column.header : column.key;
|
|
4354
|
+
const pinned = isColumnPinned(column.key);
|
|
4045
4355
|
const stopPropagation = (event)=>event.stopPropagation();
|
|
4046
4356
|
return /*#__PURE__*/ jsxs(MenuRoot, {
|
|
4047
4357
|
children: [
|
|
@@ -4083,6 +4393,12 @@ function ColumnRenameInput({ column, initialLabel, onDone }) {
|
|
|
4083
4393
|
children: "Move right"
|
|
4084
4394
|
})
|
|
4085
4395
|
}),
|
|
4396
|
+
/*#__PURE__*/ jsx(MenuItem, {
|
|
4397
|
+
onClick: ()=>togglePinColumn(column.key),
|
|
4398
|
+
children: /*#__PURE__*/ jsx(MenuItemLabel, {
|
|
4399
|
+
children: pinned ? "Unpin column" : "Pin column"
|
|
4400
|
+
})
|
|
4401
|
+
}),
|
|
4086
4402
|
/*#__PURE__*/ jsx(MenuItem, {
|
|
4087
4403
|
onClick: ()=>hideColumn(column.key),
|
|
4088
4404
|
children: /*#__PURE__*/ jsx(MenuItemLabel, {
|
|
@@ -9303,7 +9619,7 @@ const fromDatePickerDate = (d)=>new Date(d.year, d.month - 1, d.day);
|
|
|
9303
9619
|
"aria-label": "Move sort up",
|
|
9304
9620
|
disabled: index === 0,
|
|
9305
9621
|
onClick: ()=>moveToolbarSort(index, index - 1),
|
|
9306
|
-
style: iconButtonStyle,
|
|
9622
|
+
style: iconButtonStyle$1,
|
|
9307
9623
|
children: /*#__PURE__*/ jsx(IconArrowUpLine_default, {
|
|
9308
9624
|
size: 13,
|
|
9309
9625
|
strokeWidth: 1.75
|
|
@@ -9314,7 +9630,7 @@ const fromDatePickerDate = (d)=>new Date(d.year, d.month - 1, d.day);
|
|
|
9314
9630
|
"aria-label": "Move sort down",
|
|
9315
9631
|
disabled: index === toolbarSorts.length - 1,
|
|
9316
9632
|
onClick: ()=>moveToolbarSort(index, index + 1),
|
|
9317
|
-
style: iconButtonStyle,
|
|
9633
|
+
style: iconButtonStyle$1,
|
|
9318
9634
|
children: /*#__PURE__*/ jsx(IconArrowDownLine_default, {
|
|
9319
9635
|
size: 13,
|
|
9320
9636
|
strokeWidth: 1.75
|
|
@@ -9324,7 +9640,7 @@ const fromDatePickerDate = (d)=>new Date(d.year, d.month - 1, d.day);
|
|
|
9324
9640
|
type: "button",
|
|
9325
9641
|
"aria-label": "Remove sort",
|
|
9326
9642
|
onClick: ()=>removeToolbarSort(index),
|
|
9327
|
-
style: iconButtonStyle,
|
|
9643
|
+
style: iconButtonStyle$1,
|
|
9328
9644
|
children: /*#__PURE__*/ jsx(IconXmarkLine_default, {
|
|
9329
9645
|
size: 13,
|
|
9330
9646
|
strokeWidth: 1.75
|
|
@@ -9339,7 +9655,7 @@ const fromDatePickerDate = (d)=>new Date(d.year, d.month - 1, d.day);
|
|
|
9339
9655
|
disabled: availableColumns.length === 0,
|
|
9340
9656
|
onClick: ()=>availableColumns[0] && addToolbarSort(availableColumns[0].key),
|
|
9341
9657
|
style: {
|
|
9342
|
-
...iconButtonStyle,
|
|
9658
|
+
...iconButtonStyle$1,
|
|
9343
9659
|
width: "auto",
|
|
9344
9660
|
gap: 6,
|
|
9345
9661
|
padding: "6px 8px",
|
|
@@ -9361,7 +9677,7 @@ const fromDatePickerDate = (d)=>new Date(d.year, d.month - 1, d.day);
|
|
|
9361
9677
|
]
|
|
9362
9678
|
});
|
|
9363
9679
|
}
|
|
9364
|
-
const iconButtonStyle = {
|
|
9680
|
+
const iconButtonStyle$1 = {
|
|
9365
9681
|
display: "inline-flex",
|
|
9366
9682
|
alignItems: "center",
|
|
9367
9683
|
justifyContent: "center",
|
|
@@ -9459,7 +9775,7 @@ const formatFilterDate = (iso)=>{
|
|
|
9459
9775
|
type: "button",
|
|
9460
9776
|
"aria-label": `Remove ${column ? columnLabel(column) : filter.key} filter`,
|
|
9461
9777
|
onClick: ()=>removeToolbarFilter(filter.id),
|
|
9462
|
-
style: iconButtonStyle,
|
|
9778
|
+
style: iconButtonStyle$1,
|
|
9463
9779
|
children: /*#__PURE__*/ jsx(IconXmarkLine_default, {
|
|
9464
9780
|
size: 12,
|
|
9465
9781
|
strokeWidth: 1.75
|
|
@@ -9716,7 +10032,7 @@ const formatFilterDate = (iso)=>{
|
|
|
9716
10032
|
type: "button",
|
|
9717
10033
|
onClick: ()=>setPickingField(true),
|
|
9718
10034
|
style: {
|
|
9719
|
-
...iconButtonStyle,
|
|
10035
|
+
...iconButtonStyle$1,
|
|
9720
10036
|
width: "auto",
|
|
9721
10037
|
gap: 6,
|
|
9722
10038
|
padding: "6px 8px",
|
|
@@ -9801,7 +10117,7 @@ function RowCount({ shown, total, countLabel }) {
|
|
|
9801
10117
|
}
|
|
9802
10118
|
|
|
9803
10119
|
function DataTableInner(props, ref) {
|
|
9804
|
-
const { columns, data, surface, className, locale = "en-US", sort, defaultSort, onSortChange, sortIcon, selectable, selectedIds, defaultSelectedIds, onSelectionChange, selectAllLabel = "Select all rows", getRowSelectionLabel = ()=>"Select row", selectionCheckedIcon, selectionIndeterminateIcon, query, defaultQuery, onQueryChange, searchPlaceholder = "Search…", searchLabel = "Search table", toolbarSorts, defaultToolbarSorts, onToolbarSortsChange, toolbarFilters, defaultToolbarFilters, onToolbarFiltersChange, showCount = true, countLabel, toolbarActions, columnMenu = false, reorderable = true, resizable = true, columnOrder, defaultColumnOrder, onColumnOrderChange, hiddenColumnKeys, defaultHiddenColumnKeys, onHiddenColumnKeysChange, columnWidths, defaultColumnWidths, onColumnWidthsChange, columnLabels, defaultColumnLabels, onColumnLabelsChange, onColumnsChange, columnCalcOps, defaultColumnCalcOps, onColumnCalcOpsChange, stickyFirst = false, stickyLast = false, onEdit, interactive = false, onRowClick, onAddRow, addRowLabel = "New record", loading = false, loadingLabel = "Loading...", error, empty = "No results.", onLoadMore, hasMore, loadingMore, scrollProps, ...restProps } = props;
|
|
10120
|
+
const { columns, data, surface, className, locale = "en-US", sort, defaultSort, onSortChange, sortIcon, selectable, selectedIds, defaultSelectedIds, onSelectionChange, selectAllLabel = "Select all rows", getRowSelectionLabel = ()=>"Select row", selectionCheckedIcon, selectionIndeterminateIcon, query, defaultQuery, onQueryChange, searchPlaceholder = "Search…", searchLabel = "Search table", toolbarSorts, defaultToolbarSorts, onToolbarSortsChange, toolbarFilters, defaultToolbarFilters, onToolbarFiltersChange, showCount = true, countLabel, toolbarActions, columnMenu = false, reorderable = true, resizable = true, columnOrder, defaultColumnOrder, onColumnOrderChange, hiddenColumnKeys, defaultHiddenColumnKeys, onHiddenColumnKeysChange, columnWidths, defaultColumnWidths, onColumnWidthsChange, columnLabels, defaultColumnLabels, onColumnLabelsChange, pinnedColumnKeys, defaultPinnedColumnKeys, onPinnedColumnKeysChange, onColumnsChange, columnCalcOps, defaultColumnCalcOps, onColumnCalcOpsChange, stickyFirst = false, stickyLast = false, onEdit, interactive = false, onRowClick, onAddRow, addRowLabel = "New record", loading = false, loadingLabel = "Loading...", error, empty = "No results.", onLoadMore, hasMore, loadingMore, scrollProps, ...restProps } = props;
|
|
9805
10121
|
const classNames = dataTable({
|
|
9806
10122
|
surface,
|
|
9807
10123
|
interactive
|
|
@@ -9937,6 +10253,9 @@ function DataTableInner(props, ref) {
|
|
|
9937
10253
|
columnLabels: columnLabels,
|
|
9938
10254
|
defaultColumnLabels: defaultColumnLabels,
|
|
9939
10255
|
onColumnLabelsChange: onColumnLabelsChange,
|
|
10256
|
+
pinnedColumnKeys: pinnedColumnKeys,
|
|
10257
|
+
defaultPinnedColumnKeys: defaultPinnedColumnKeys,
|
|
10258
|
+
onPinnedColumnKeysChange: onPinnedColumnKeysChange,
|
|
9940
10259
|
columnCalcOps: columnCalcOps,
|
|
9941
10260
|
defaultColumnCalcOps: defaultColumnCalcOps,
|
|
9942
10261
|
onColumnCalcOpsChange: onColumnCalcOpsChange,
|
|
@@ -9980,19 +10299,13 @@ function DataTableInner(props, ref) {
|
|
|
9980
10299
|
children: [
|
|
9981
10300
|
/*#__PURE__*/ jsx(DataTableColGroup, {
|
|
9982
10301
|
columns: columns,
|
|
9983
|
-
selectable: !!selectable
|
|
10302
|
+
selectable: !!selectable,
|
|
10303
|
+
stickyFirst: stickyFirst
|
|
9984
10304
|
}),
|
|
9985
10305
|
/*#__PURE__*/ jsxs(DataTableHeader, {
|
|
9986
10306
|
children: [
|
|
9987
|
-
selectable && /*#__PURE__*/ jsx(
|
|
9988
|
-
|
|
9989
|
-
selectable,
|
|
9990
|
-
stickyFirst,
|
|
9991
|
-
stickyLast: resolvedStickyLast,
|
|
9992
|
-
isSelectionCell: true,
|
|
9993
|
-
isFirst: false,
|
|
9994
|
-
isLast: false
|
|
9995
|
-
}),
|
|
10307
|
+
selectable && /*#__PURE__*/ jsx(SelectionHeaderCell, {
|
|
10308
|
+
stickyFirst: stickyFirst,
|
|
9996
10309
|
children: /*#__PURE__*/ jsx(SelectAllCheckbox, {
|
|
9997
10310
|
label: selectAllLabel,
|
|
9998
10311
|
checkedIcon: selectionCheckedIcon ?? DEFAULT_CHECKED_ICON,
|
|
@@ -10043,7 +10356,7 @@ function DataTableInner(props, ref) {
|
|
|
10043
10356
|
"data-clickable": onRowClick ? "" : undefined,
|
|
10044
10357
|
onClick: onRowClick ? ()=>onRowClick(row) : undefined,
|
|
10045
10358
|
children: [
|
|
10046
|
-
selectable && /*#__PURE__*/ jsx(
|
|
10359
|
+
selectable && /*#__PURE__*/ jsx(SelectionCell, {
|
|
10047
10360
|
// The row itself carries `onClick={onRowClick}` above, and a
|
|
10048
10361
|
// native click on this cell's checkbox bubbles up through it
|
|
10049
10362
|
// (React attaches DataTableRow's handler on the <tr>, which
|
|
@@ -10051,14 +10364,7 @@ function DataTableInner(props, ref) {
|
|
|
10051
10364
|
// it from at -- so this has to live here, not in the consumer).
|
|
10052
10365
|
// Without this, checking a row's box also fires `onRowClick`.
|
|
10053
10366
|
onClick: (event)=>event.stopPropagation(),
|
|
10054
|
-
|
|
10055
|
-
selectable,
|
|
10056
|
-
stickyFirst,
|
|
10057
|
-
stickyLast: resolvedStickyLast,
|
|
10058
|
-
isSelectionCell: true,
|
|
10059
|
-
isFirst: false,
|
|
10060
|
-
isLast: false
|
|
10061
|
-
}),
|
|
10367
|
+
stickyFirst: stickyFirst,
|
|
10062
10368
|
children: /*#__PURE__*/ jsx(RowCheckbox, {
|
|
10063
10369
|
label: getRowSelectionLabel(row),
|
|
10064
10370
|
checkedIcon: selectionCheckedIcon ?? DEFAULT_CHECKED_ICON
|
|
@@ -10090,15 +10396,8 @@ function DataTableInner(props, ref) {
|
|
|
10090
10396
|
// is what makes every row's selection column line up now, not a matching
|
|
10091
10397
|
// per-slot width formula, so there is no more reason for this cell to
|
|
10092
10398
|
// borrow a different slot than its footer siblings.
|
|
10093
|
-
/*#__PURE__*/ jsx(
|
|
10094
|
-
|
|
10095
|
-
selectable,
|
|
10096
|
-
stickyFirst,
|
|
10097
|
-
stickyLast: resolvedStickyLast,
|
|
10098
|
-
isSelectionCell: true,
|
|
10099
|
-
isFirst: false,
|
|
10100
|
-
isLast: false
|
|
10101
|
-
})
|
|
10399
|
+
/*#__PURE__*/ jsx(SelectionFooterCell, {
|
|
10400
|
+
stickyFirst: stickyFirst
|
|
10102
10401
|
}),
|
|
10103
10402
|
/*#__PURE__*/ jsx(ColumnCalcCells, {
|
|
10104
10403
|
columns: columns,
|
|
@@ -10134,7 +10433,16 @@ DataTableInner.displayName = "DataTable";
|
|
|
10134
10433
|
* `DataTableInner`) purely so it can call `useDataTableContext()` -- that context is
|
|
10135
10434
|
* provided by the `DataTablePrimitiveRoot` this renders as a SIBLING of, one level
|
|
10136
10435
|
* up from where `DataTableInner` itself sits. */ function ColumnsChangeEffect({ columns, onColumnsChange }) {
|
|
10137
|
-
|
|
10436
|
+
// `selectable`/`stickyFirst` are both `false` here on purpose: this convenience blob
|
|
10437
|
+
// never renders a row of its own, so it needs neither the +40px selection offset nor
|
|
10438
|
+
// `stickyFirst`'s legacy "no explicit pin -> pin the first visible column" fallback.
|
|
10439
|
+
// An EXPLICIT per-column pin (`pinnedColumnKeys`) still reorders this list the same
|
|
10440
|
+
// way it reorders every rendered row -- this callback reports "what's showing now",
|
|
10441
|
+
// and a pinned column showing first IS what's showing now.
|
|
10442
|
+
const effective = useEffectiveColumns(columns, {
|
|
10443
|
+
selectable: false,
|
|
10444
|
+
stickyFirst: false
|
|
10445
|
+
});
|
|
10138
10446
|
// A NEW array every time `effective` itself is a new array (its own `useMemo`
|
|
10139
10447
|
// recomputes only when order/hidden/label/width actually change) -- `header`
|
|
10140
10448
|
// resolves to the menu's rename override (falling back to the column's own static
|
|
@@ -10169,8 +10477,16 @@ const DataTableTable = withContext$1(DataTableTable$1, "table");
|
|
|
10169
10477
|
* out of sync between the three. A column with no explicit width gets a bare `<col>`
|
|
10170
10478
|
* (no `style`): `table-layout: fixed`'s own algorithm gives every such column an equal
|
|
10171
10479
|
* share of whatever space is left, matching the old flex grid's `flex: 1 1 0%`
|
|
10172
|
-
* default with no extra code needed here. */ function DataTableColGroup({ columns, selectable }) {
|
|
10173
|
-
|
|
10480
|
+
* default with no extra code needed here. */ function DataTableColGroup({ columns, selectable, stickyFirst }) {
|
|
10481
|
+
// MUST use the same pinned-first ordering every OTHER row (header/body/footer)
|
|
10482
|
+
// renders in (`useEffectiveColumns`'s own doc comment) -- a `<colgroup>`'s `<col>`s
|
|
10483
|
+
// are matched positionally to each row's cells, so if a pinned column visually moves
|
|
10484
|
+
// to the front of the header/body but not here, every column's width applies to the
|
|
10485
|
+
// WRONG cell.
|
|
10486
|
+
const effective = useEffectiveColumns(columns, {
|
|
10487
|
+
selectable,
|
|
10488
|
+
stickyFirst
|
|
10489
|
+
});
|
|
10174
10490
|
return /*#__PURE__*/ jsxs("colgroup", {
|
|
10175
10491
|
children: [
|
|
10176
10492
|
selectable && /*#__PURE__*/ jsx("col", {
|
|
@@ -10256,6 +10572,32 @@ function DataTableFooter({ children, ...props }) {
|
|
|
10256
10572
|
});
|
|
10257
10573
|
}
|
|
10258
10574
|
const DataTableFooterCell = withContext$1(Primitive.td, "footerCell");
|
|
10575
|
+
// The selection column's OWN sticky wrappers -- one each for header/body/footer,
|
|
10576
|
+
// reading the live pinned set via `useSelectionStickyFirst` (column-layout.ts) instead
|
|
10577
|
+
// of the `stickyFirst` PROP alone, so the checkbox column sticks the moment ANY column
|
|
10578
|
+
// is pinned, uncontrolled or not (see that hook's own doc comment for why this can't
|
|
10579
|
+
// just be computed once, above, in `DataTableInner`).
|
|
10580
|
+
function SelectionHeaderCell({ stickyFirst, children }) {
|
|
10581
|
+
const resolvedStickyFirst = useSelectionStickyFirst(stickyFirst);
|
|
10582
|
+
return /*#__PURE__*/ jsx(DataTableSelectionHeaderCell, {
|
|
10583
|
+
...selectionStickyProps(resolvedStickyFirst),
|
|
10584
|
+
children: children
|
|
10585
|
+
});
|
|
10586
|
+
}
|
|
10587
|
+
function SelectionCell({ stickyFirst, onClick, children }) {
|
|
10588
|
+
const resolvedStickyFirst = useSelectionStickyFirst(stickyFirst);
|
|
10589
|
+
return /*#__PURE__*/ jsx(DataTableSelectionCell, {
|
|
10590
|
+
onClick: onClick,
|
|
10591
|
+
...selectionStickyProps(resolvedStickyFirst),
|
|
10592
|
+
children: children
|
|
10593
|
+
});
|
|
10594
|
+
}
|
|
10595
|
+
function SelectionFooterCell({ stickyFirst }) {
|
|
10596
|
+
const resolvedStickyFirst = useSelectionStickyFirst(stickyFirst);
|
|
10597
|
+
return /*#__PURE__*/ jsx(DataTableFooterCell, {
|
|
10598
|
+
...selectionStickyProps(resolvedStickyFirst)
|
|
10599
|
+
});
|
|
10600
|
+
}
|
|
10259
10601
|
////////////////////////////////////////////////////////////////////////////////////
|
|
10260
10602
|
// Fix (bug report): karrot icons default to a 24px intrinsic SVG attribute size
|
|
10261
10603
|
// -- see column-menu.tsx's own `SORT_ICON_SIZE` comment for the full mechanism.
|
|
@@ -10311,4 +10653,274 @@ function SelectAllCheckbox({ label, checkedIcon, indeterminateIcon }) {
|
|
|
10311
10653
|
});
|
|
10312
10654
|
}
|
|
10313
10655
|
|
|
10314
|
-
|
|
10656
|
+
const rowStyle = {
|
|
10657
|
+
display: "flex",
|
|
10658
|
+
alignItems: "center",
|
|
10659
|
+
gap: 4
|
|
10660
|
+
};
|
|
10661
|
+
const rowButtonStyle = {
|
|
10662
|
+
flex: 1,
|
|
10663
|
+
minWidth: 0,
|
|
10664
|
+
textAlign: "left",
|
|
10665
|
+
display: "flex",
|
|
10666
|
+
alignItems: "center",
|
|
10667
|
+
gap: 6,
|
|
10668
|
+
padding: "6px 8px",
|
|
10669
|
+
border: "none",
|
|
10670
|
+
borderRadius: 6,
|
|
10671
|
+
background: "transparent",
|
|
10672
|
+
color: "var(--seed-color-fg-neutral)",
|
|
10673
|
+
fontSize: 13,
|
|
10674
|
+
cursor: "pointer",
|
|
10675
|
+
overflow: "hidden",
|
|
10676
|
+
textOverflow: "ellipsis",
|
|
10677
|
+
whiteSpace: "nowrap"
|
|
10678
|
+
};
|
|
10679
|
+
const smallButtonStyle = {
|
|
10680
|
+
flexShrink: 0,
|
|
10681
|
+
border: "none",
|
|
10682
|
+
borderRadius: 6,
|
|
10683
|
+
background: "transparent",
|
|
10684
|
+
color: "var(--seed-color-fg-neutral-subtle)",
|
|
10685
|
+
fontSize: 12,
|
|
10686
|
+
padding: "4px 6px",
|
|
10687
|
+
cursor: "pointer"
|
|
10688
|
+
};
|
|
10689
|
+
const iconButtonStyle = {
|
|
10690
|
+
display: "inline-flex",
|
|
10691
|
+
alignItems: "center",
|
|
10692
|
+
justifyContent: "center",
|
|
10693
|
+
width: 22,
|
|
10694
|
+
height: 22,
|
|
10695
|
+
flexShrink: 0,
|
|
10696
|
+
border: "none",
|
|
10697
|
+
borderRadius: 6,
|
|
10698
|
+
background: "transparent",
|
|
10699
|
+
color: "var(--seed-color-fg-neutral-subtle)",
|
|
10700
|
+
cursor: "pointer"
|
|
10701
|
+
};
|
|
10702
|
+
/**
|
|
10703
|
+
* A compact saved-views switcher -- current view name (or `label`) as the trigger,
|
|
10704
|
+
* a popover listing every saved view (click to switch, inline Rename/Delete), a
|
|
10705
|
+
* trailing "Save as new view", and (once a view is active) "Update view" to overwrite
|
|
10706
|
+
* the loaded view with the table's current state.
|
|
10707
|
+
*/ function DataTableViewsControl({ label = "Views", showClearRow = false, clearLabel, captureState, applyState, newViewLabel = "Save as new view", updateViewLabel = "Update view", renameLabel = "Rename", deleteLabel = "Delete", renameInputLabel = (name)=>`Rename ${name}`, ...viewsProps }) {
|
|
10708
|
+
const viewsApi = useDataTableViews(viewsProps);
|
|
10709
|
+
const { activeViewId, activeView } = viewsApi;
|
|
10710
|
+
const triggerLabel = activeView ? activeView.name : label;
|
|
10711
|
+
return /*#__PURE__*/ jsxs(MenuRoot, {
|
|
10712
|
+
children: [
|
|
10713
|
+
/*#__PURE__*/ jsx(MenuTrigger, {
|
|
10714
|
+
asChild: true,
|
|
10715
|
+
children: /*#__PURE__*/ jsxs(ActionButton, {
|
|
10716
|
+
variant: "neutralOutline",
|
|
10717
|
+
size: "xsmall",
|
|
10718
|
+
"data-active": activeViewId ? "" : undefined,
|
|
10719
|
+
children: [
|
|
10720
|
+
/*#__PURE__*/ jsx(IconArrowUpArrowDownLine_default, {
|
|
10721
|
+
size: 14,
|
|
10722
|
+
strokeWidth: 1.75
|
|
10723
|
+
}),
|
|
10724
|
+
triggerLabel,
|
|
10725
|
+
/*#__PURE__*/ jsx(IconChevronDownSmallLine_default, {
|
|
10726
|
+
size: 14,
|
|
10727
|
+
strokeWidth: 1.75
|
|
10728
|
+
})
|
|
10729
|
+
]
|
|
10730
|
+
})
|
|
10731
|
+
}),
|
|
10732
|
+
/*#__PURE__*/ jsx(MenuPositioner, {
|
|
10733
|
+
children: /*#__PURE__*/ jsx(MenuContent, {
|
|
10734
|
+
style: {
|
|
10735
|
+
minWidth: 240
|
|
10736
|
+
},
|
|
10737
|
+
children: /*#__PURE__*/ jsx(MenuScrollArea, {
|
|
10738
|
+
children: /*#__PURE__*/ jsx(ViewsMenuBody, {
|
|
10739
|
+
viewsApi: viewsApi,
|
|
10740
|
+
captureState: captureState,
|
|
10741
|
+
applyState: applyState,
|
|
10742
|
+
label: label,
|
|
10743
|
+
showClearRow: showClearRow,
|
|
10744
|
+
clearLabel: clearLabel,
|
|
10745
|
+
newViewLabel: newViewLabel,
|
|
10746
|
+
updateViewLabel: updateViewLabel,
|
|
10747
|
+
renameLabel: renameLabel,
|
|
10748
|
+
deleteLabel: deleteLabel,
|
|
10749
|
+
renameInputLabel: renameInputLabel
|
|
10750
|
+
})
|
|
10751
|
+
})
|
|
10752
|
+
})
|
|
10753
|
+
})
|
|
10754
|
+
]
|
|
10755
|
+
});
|
|
10756
|
+
}
|
|
10757
|
+
DataTableViewsControl.displayName = "DataTableViewsControl";
|
|
10758
|
+
/**
|
|
10759
|
+
* The popover's own body -- split out from `DataTableViewsControl` purely so it can
|
|
10760
|
+
* call `useMenuContext()` (`@seed-design/react-menu`), which only resolves for a
|
|
10761
|
+
* descendant of `MenuRoot`, not the component that RENDERS `MenuRoot` itself (the same
|
|
10762
|
+
* reason `column-layout.ts`'s `useSelectionStickyFirst` is its own component-level
|
|
10763
|
+
* hook rather than something computed in `DataTable.tsx` above its provider). Plain
|
|
10764
|
+
* `<button>` rows here (not seed `MenuItem`s -- `toolbar-conditions.tsx`'s own Sort/
|
|
10765
|
+
* Filter popovers make the same call) don't auto-close the menu on click the way a real
|
|
10766
|
+
* `MenuItem` does, so switching/creating/updating a view calls `setOpen(false)` here
|
|
10767
|
+
* explicitly; renaming and deleting deliberately do NOT close it, so a consumer can
|
|
10768
|
+
* clean up more than one view without reopening the popover each time.
|
|
10769
|
+
*/ function ViewsMenuBody({ viewsApi, captureState, applyState, label, showClearRow, clearLabel, newViewLabel, updateViewLabel, renameLabel, deleteLabel, renameInputLabel }) {
|
|
10770
|
+
const { views, activeViewId, createView, updateView, renameView, deleteView, selectView } = viewsApi;
|
|
10771
|
+
const { setOpen } = useMenuContext();
|
|
10772
|
+
const [renamingId, setRenamingId] = React.useState(null);
|
|
10773
|
+
const [renameValue, setRenameValue] = React.useState("");
|
|
10774
|
+
// Same race `column-menu.tsx`'s own inline rename input already guards against:
|
|
10775
|
+
// starting a rename swaps the clicked "Rename" button for an input in the SAME
|
|
10776
|
+
// MenuContent this popover's own floating-ui focus management watches, and its
|
|
10777
|
+
// focus-guard spans can steal focus right back (to the content, or the trigger)
|
|
10778
|
+
// one frame after mount -- BEFORE this ref flips true -- so `onBlur` ignores that
|
|
10779
|
+
// one spurious blur and only commits a REAL blur (an actual click/tab away) after.
|
|
10780
|
+
const renameReadyRef = React.useRef(false);
|
|
10781
|
+
const renameInputRef = React.useRef(null);
|
|
10782
|
+
const handleSelect = (id)=>{
|
|
10783
|
+
selectView(id);
|
|
10784
|
+
if (id !== null) {
|
|
10785
|
+
const view = views.find((v)=>v.id === id);
|
|
10786
|
+
if (view) applyState(view.state);
|
|
10787
|
+
}
|
|
10788
|
+
setOpen(false);
|
|
10789
|
+
};
|
|
10790
|
+
const handleCreate = ()=>{
|
|
10791
|
+
createView(`View ${views.length + 1}`, captureState());
|
|
10792
|
+
setOpen(false);
|
|
10793
|
+
};
|
|
10794
|
+
const handleUpdate = ()=>{
|
|
10795
|
+
if (activeViewId) updateView(activeViewId, captureState());
|
|
10796
|
+
setOpen(false);
|
|
10797
|
+
};
|
|
10798
|
+
const startRename = (view)=>{
|
|
10799
|
+
renameReadyRef.current = false;
|
|
10800
|
+
setRenamingId(view.id);
|
|
10801
|
+
setRenameValue(view.name);
|
|
10802
|
+
};
|
|
10803
|
+
const commitRename = ()=>{
|
|
10804
|
+
if (renamingId && renameValue.trim()) renameView(renamingId, renameValue.trim());
|
|
10805
|
+
setRenamingId(null);
|
|
10806
|
+
};
|
|
10807
|
+
React.useEffect(()=>{
|
|
10808
|
+
if (!renamingId) return;
|
|
10809
|
+
// Re-grab focus (and select the text) one frame after mount, AFTER whatever
|
|
10810
|
+
// floating-ui's own focus-guard restore was going to do -- see this component's
|
|
10811
|
+
// own `renameReadyRef` doc comment above.
|
|
10812
|
+
const frame = requestAnimationFrame(()=>{
|
|
10813
|
+
renameReadyRef.current = true;
|
|
10814
|
+
renameInputRef.current?.focus();
|
|
10815
|
+
renameInputRef.current?.select();
|
|
10816
|
+
});
|
|
10817
|
+
return ()=>cancelAnimationFrame(frame);
|
|
10818
|
+
}, [
|
|
10819
|
+
renamingId
|
|
10820
|
+
]);
|
|
10821
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
10822
|
+
style: {
|
|
10823
|
+
display: "flex",
|
|
10824
|
+
flexDirection: "column",
|
|
10825
|
+
gap: 2,
|
|
10826
|
+
padding: "4px 8px"
|
|
10827
|
+
},
|
|
10828
|
+
children: [
|
|
10829
|
+
showClearRow && /*#__PURE__*/ jsx("button", {
|
|
10830
|
+
type: "button",
|
|
10831
|
+
onClick: ()=>handleSelect(null),
|
|
10832
|
+
"data-active": !activeViewId ? "" : undefined,
|
|
10833
|
+
style: rowButtonStyle,
|
|
10834
|
+
children: clearLabel ?? label
|
|
10835
|
+
}),
|
|
10836
|
+
views.length === 0 && /*#__PURE__*/ jsx("div", {
|
|
10837
|
+
style: {
|
|
10838
|
+
fontSize: 13,
|
|
10839
|
+
color: "var(--seed-color-fg-neutral-subtle)",
|
|
10840
|
+
padding: "4px 8px"
|
|
10841
|
+
},
|
|
10842
|
+
children: "No saved views yet."
|
|
10843
|
+
}),
|
|
10844
|
+
views.map((view)=>renamingId === view.id ? /*#__PURE__*/ jsx("div", {
|
|
10845
|
+
style: rowStyle,
|
|
10846
|
+
children: /*#__PURE__*/ jsx("input", {
|
|
10847
|
+
ref: renameInputRef,
|
|
10848
|
+
// biome-ignore lint/a11y/noAutofocus: opening this input IS the user's own "Rename" click a moment earlier, not an unannounced page-load autofocus (same call column-menu.tsx's own inline rename input makes).
|
|
10849
|
+
autoFocus: true,
|
|
10850
|
+
"aria-label": renameInputLabel(view.name),
|
|
10851
|
+
value: renameValue,
|
|
10852
|
+
onChange: (event)=>setRenameValue(event.target.value),
|
|
10853
|
+
onBlur: ()=>{
|
|
10854
|
+
if (renameReadyRef.current) commitRename();
|
|
10855
|
+
},
|
|
10856
|
+
onKeyDown: (event)=>{
|
|
10857
|
+
event.stopPropagation();
|
|
10858
|
+
if (event.key === "Enter") commitRename();
|
|
10859
|
+
if (event.key === "Escape") setRenamingId(null);
|
|
10860
|
+
},
|
|
10861
|
+
style: {
|
|
10862
|
+
flex: 1,
|
|
10863
|
+
minWidth: 0,
|
|
10864
|
+
font: "inherit",
|
|
10865
|
+
fontSize: 13,
|
|
10866
|
+
padding: "6px 8px",
|
|
10867
|
+
border: "1px solid var(--seed-color-border-neutral)",
|
|
10868
|
+
borderRadius: 6,
|
|
10869
|
+
background: "var(--seed-color-bg-surface)",
|
|
10870
|
+
color: "var(--seed-color-fg-neutral)"
|
|
10871
|
+
}
|
|
10872
|
+
})
|
|
10873
|
+
}, view.id) : /*#__PURE__*/ jsxs("div", {
|
|
10874
|
+
style: rowStyle,
|
|
10875
|
+
children: [
|
|
10876
|
+
/*#__PURE__*/ jsx("button", {
|
|
10877
|
+
type: "button",
|
|
10878
|
+
onClick: ()=>handleSelect(view.id),
|
|
10879
|
+
"data-active": view.id === activeViewId ? "" : undefined,
|
|
10880
|
+
style: rowButtonStyle,
|
|
10881
|
+
children: view.name
|
|
10882
|
+
}),
|
|
10883
|
+
/*#__PURE__*/ jsx("button", {
|
|
10884
|
+
type: "button",
|
|
10885
|
+
onClick: ()=>startRename(view),
|
|
10886
|
+
style: smallButtonStyle,
|
|
10887
|
+
children: renameLabel
|
|
10888
|
+
}),
|
|
10889
|
+
/*#__PURE__*/ jsx("button", {
|
|
10890
|
+
type: "button",
|
|
10891
|
+
"aria-label": `${deleteLabel} ${view.name}`,
|
|
10892
|
+
onClick: ()=>deleteView(view.id),
|
|
10893
|
+
style: iconButtonStyle,
|
|
10894
|
+
children: /*#__PURE__*/ jsx(IconXmarkLine_default, {
|
|
10895
|
+
size: 13,
|
|
10896
|
+
strokeWidth: 1.75
|
|
10897
|
+
})
|
|
10898
|
+
})
|
|
10899
|
+
]
|
|
10900
|
+
}, view.id)),
|
|
10901
|
+
activeViewId && /*#__PURE__*/ jsx("button", {
|
|
10902
|
+
type: "button",
|
|
10903
|
+
onClick: handleUpdate,
|
|
10904
|
+
style: {
|
|
10905
|
+
...rowButtonStyle,
|
|
10906
|
+
color: "var(--seed-color-fg-neutral-subtle)"
|
|
10907
|
+
},
|
|
10908
|
+
children: updateViewLabel
|
|
10909
|
+
}),
|
|
10910
|
+
/*#__PURE__*/ jsxs("button", {
|
|
10911
|
+
type: "button",
|
|
10912
|
+
onClick: handleCreate,
|
|
10913
|
+
style: rowButtonStyle,
|
|
10914
|
+
children: [
|
|
10915
|
+
/*#__PURE__*/ jsx(IconPlusLine_default, {
|
|
10916
|
+
size: 13,
|
|
10917
|
+
strokeWidth: 1.75
|
|
10918
|
+
}),
|
|
10919
|
+
newViewLabel
|
|
10920
|
+
]
|
|
10921
|
+
})
|
|
10922
|
+
]
|
|
10923
|
+
});
|
|
10924
|
+
}
|
|
10925
|
+
|
|
10926
|
+
export { DataTable, DataTableViewsControl };
|