@macrostrat/data-sheet 4.1.0 → 4.1.1

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.
Files changed (69) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/actions/column-controls.cjs +17 -5
  3. package/dist/actions/column-controls.cjs.map +1 -1
  4. package/dist/actions/column-controls.js +18 -6
  5. package/dist/actions/column-controls.js.map +1 -1
  6. package/dist/actions/column-filter.cjs +48 -25
  7. package/dist/actions/column-filter.cjs.map +1 -1
  8. package/dist/actions/column-filter.js +50 -27
  9. package/dist/actions/column-filter.js.map +1 -1
  10. package/dist/actions/table-controls.cjs +4 -0
  11. package/dist/actions/table-controls.cjs.map +1 -1
  12. package/dist/actions/table-controls.js +4 -0
  13. package/dist/actions/table-controls.js.map +1 -1
  14. package/dist/actions/toolbar.cjs +19 -5
  15. package/dist/actions/toolbar.cjs.map +1 -1
  16. package/dist/actions/toolbar.js +20 -6
  17. package/dist/actions/toolbar.js.map +1 -1
  18. package/dist/cell-renderer.cjs +1 -1
  19. package/dist/cell-renderer.cjs.map +1 -1
  20. package/dist/cell-renderer.js +1 -1
  21. package/dist/cell-renderer.js.map +1 -1
  22. package/dist/core.cjs +11 -2
  23. package/dist/core.cjs.map +1 -1
  24. package/dist/core.d.ts +4 -0
  25. package/dist/core.js +11 -2
  26. package/dist/core.js.map +1 -1
  27. package/dist/filters/operators.cjs +2 -2
  28. package/dist/filters/operators.cjs.map +1 -1
  29. package/dist/filters/operators.d.ts +1 -1
  30. package/dist/filters/operators.js +2 -2
  31. package/dist/filters/operators.js.map +1 -1
  32. package/dist/postgrest-table/data-loaders.cjs +1 -8
  33. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  34. package/dist/postgrest-table/data-loaders.js +1 -8
  35. package/dist/postgrest-table/data-loaders.js.map +1 -1
  36. package/dist/provider.cjs +9 -3
  37. package/dist/provider.cjs.map +1 -1
  38. package/dist/provider.d.ts +2 -1
  39. package/dist/provider.js +9 -3
  40. package/dist/provider.js.map +1 -1
  41. package/dist/renderers/column-header-cell.cjs +19 -4
  42. package/dist/renderers/column-header-cell.cjs.map +1 -1
  43. package/dist/renderers/column-header-cell.d.ts +1 -2
  44. package/dist/renderers/column-header-cell.js +20 -5
  45. package/dist/renderers/column-header-cell.js.map +1 -1
  46. package/dist/types.cjs.map +1 -1
  47. package/dist/types.d.ts +10 -1
  48. package/dist/types.js.map +1 -1
  49. package/dist/utils/column-spec.cjs.map +1 -1
  50. package/dist/utils/column-spec.d.ts +4 -0
  51. package/dist/utils/column-spec.js.map +1 -1
  52. package/dist/zustand-store.cjs +1 -0
  53. package/dist/zustand-store.cjs.map +1 -1
  54. package/dist/zustand-store.js +1 -0
  55. package/dist/zustand-store.js.map +1 -1
  56. package/package.json +1 -1
  57. package/src/actions/column-controls.ts +24 -7
  58. package/src/actions/column-filter.ts +59 -30
  59. package/src/actions/table-controls.ts +4 -0
  60. package/src/actions/toolbar.ts +39 -11
  61. package/src/cell-renderer.ts +6 -1
  62. package/src/core.ts +26 -3
  63. package/src/filters/operators.ts +5 -3
  64. package/src/postgrest-table/data-loaders.ts +6 -10
  65. package/src/provider.ts +22 -5
  66. package/src/renderers/column-header-cell.ts +31 -4
  67. package/src/types.ts +10 -1
  68. package/src/utils/column-spec.ts +4 -0
  69. package/src/zustand-store.ts +1 -0
@@ -9,8 +9,8 @@
9
9
  * (overridable via `filterable: { operators }`).
10
10
  */
11
11
  import hyper from "@macrostrat/hyper";
12
- import { useEffect, useState } from "react";
13
- import { ControlGroup, FormGroup, HTMLSelect, InputGroup } from "@blueprintjs/core";
12
+ import { useState } from "react";
13
+ import { Button, HTMLSelect, InputGroup } from "@blueprintjs/core";
14
14
  import type { ColumnSpec } from "../utils/column-spec";
15
15
  import type { TableFilter } from "./types";
16
16
  import {
@@ -63,42 +63,71 @@ function ColumnFilterForm({
63
63
  state: ColumnFilterState;
64
64
  setState: (s: ColumnFilterState) => void;
65
65
  }) {
66
- // The value is edited in local state and only committed (which triggers a
67
- // re-fetch for server sources) on blur or Enter — not on every keystroke.
68
- // The operator select commits immediately (a discrete choice).
69
- const [draft, setDraft] = useState(state.value ?? "");
70
- useEffect(() => setDraft(state.value ?? ""), [state.value]);
71
- const commit = () => {
72
- if (draft !== state.value) setState({ ...state, value: draft });
66
+ // Operator and value are held locally, seeded once from the incoming state.
67
+ // The operator must be local: committing it with an empty value clears the
68
+ // filter (so the store round-trips back to the default state), which would
69
+ // otherwise snap the dropdown back to the default — the operator wouldn't
70
+ // "stick" until a value was typed. The value commits (triggering a server
71
+ // re-fetch) on blur / Enter, not on every keystroke.
72
+ const [op, setOp] = useState<FilterOperator>(
73
+ state?.operator ?? operators[0],
74
+ );
75
+ const [val, setVal] = useState<string>(state?.value ?? "");
76
+
77
+ const commit = (nextOp: FilterOperator, nextVal: string) =>
78
+ setState({ operator: nextOp, value: nextVal });
79
+
80
+ const clear = () => {
81
+ setVal("");
82
+ commit(op, "");
73
83
  };
84
+
74
85
  return h(
75
- FormGroup,
76
- { label: "Filter" },
77
- h(ControlGroup, { fill: true }, [
78
- h(HTMLSelect, {
79
- key: "op",
80
- value: state.operator,
81
- options: operators.map((op) => ({
82
- value: op,
83
- label: OPERATOR_LABELS[op] ?? op,
84
- })),
85
- onChange: (e) =>
86
- setState({
87
- ...state,
88
- operator: e.currentTarget.value as FilterOperator,
86
+ "div",
87
+ { style: { display: "flex", flexDirection: "column", gap: "6px" } },
88
+ [
89
+ // Compact header: title + operator on one row (with a clear ✕ when set),
90
+ // value on the next — space-efficient and full-width for the value.
91
+ h(
92
+ "div",
93
+ { style: { display: "flex", alignItems: "center", gap: "6px" } },
94
+ [
95
+ h("span", { style: { fontWeight: 600 } }, "Filter"),
96
+ h(HTMLSelect, {
97
+ small: true,
98
+ value: op,
99
+ options: operators.map((o) => ({
100
+ value: o,
101
+ label: OPERATOR_LABELS[o] ?? o,
102
+ })),
103
+ onChange: (e) => {
104
+ const nextOp = e.currentTarget.value as FilterOperator;
105
+ setOp(nextOp);
106
+ commit(nextOp, val);
107
+ },
89
108
  }),
90
- }),
109
+ h("div", { style: { flex: 1 } }),
110
+ h.if(val !== "")(Button, {
111
+ small: true,
112
+ minimal: true,
113
+ icon: "cross",
114
+ "aria-label": "Clear filter",
115
+ onClick: clear,
116
+ }),
117
+ ],
118
+ ),
91
119
  h(InputGroup, {
92
- key: "val",
93
- value: draft,
120
+ small: true,
121
+ fill: true,
122
+ value: val,
94
123
  placeholder: "value",
95
124
  autoFocus: true,
96
- onChange: (e) => setDraft(e.target.value),
97
- onBlur: commit,
125
+ onChange: (e) => setVal(e.target.value),
126
+ onBlur: () => commit(op, val),
98
127
  onKeyDown: (e) => {
99
- if (e.key === "Enter") commit();
128
+ if (e.key === "Enter") commit(op, val);
100
129
  },
101
130
  }),
102
- ]),
131
+ ],
103
132
  );
104
133
  }
@@ -49,6 +49,10 @@ export const clearSelectionAction: TableAction = {
49
49
  RegionCardinality.FULL_COLUMNS,
50
50
  RegionCardinality.FULL_TABLE,
51
51
  ],
52
+ // Empty selection maps to the FULL_TABLE cardinality, so the action still
53
+ // shows with nothing selected — grey it out there rather than act on nothing.
54
+ // (`disabled` is probed with a bare state, hence the `?? []`.)
55
+ disabled: (s: any) => (s.selection?.length ?? 0) === 0,
52
56
  run(ctx) {
53
57
  ctx.setState({ selection: [], focusedCell: null, topLeftCell: null });
54
58
  },
@@ -1,4 +1,4 @@
1
- import { Button, ButtonGroup, PopoverNext } from "@blueprintjs/core";
1
+ import { Button, ButtonGroup, PopoverNext, Tag } from "@blueprintjs/core";
2
2
  import { useCallback, useMemo, useState } from "react";
3
3
  import h from "./toolbar.module.sass";
4
4
  import { useSelector, useStoreAPI } from "../provider";
@@ -98,30 +98,58 @@ export function ActionsToolbar<T>({
98
98
  // The toolbar is always mounted if actions are available, so it can't flicker
99
99
  // in/out as the selection or action set changes — the container is stable;
100
100
  // only its contents (title + buttons) change. Avoids layout jank.
101
- const title = selectionTitle(ctx) ?? tableName ?? "Table";
101
+ //
102
+ // The leading title doubles as the clear-selection affordance: with an active
103
+ // selection it renders as a dismissible tag (its ✕ clears the selection),
104
+ // which ties "clear" to the selection it acts on and frees toolbar space.
105
+ // With no selection it's a plain label (table name).
106
+ // Both states render as a `large` `Tag` so the title keeps a constant font
107
+ // and height; only the selected one has a filled background + a ✕ (which
108
+ // clears the selection). The unselected label is a transparent, non-removable
109
+ // tag — visually a plain title, but the same box.
110
+ const hasSelection = selection != null && selection.length > 0;
111
+ const titleNode = h(
112
+ Tag,
113
+ {
114
+ key: "title",
115
+ minimal: true,
116
+ large: true,
117
+ onRemove: hasSelection
118
+ ? () =>
119
+ storeAPI.setState({
120
+ selection: [],
121
+ focusedCell: null,
122
+ topLeftCell: null,
123
+ })
124
+ : undefined,
125
+ style: hasSelection ? undefined : { background: "transparent" },
126
+ },
127
+ hasSelection
128
+ ? (selectionTitle(ctx) ?? tableName ?? "Selection")
129
+ : (tableName ?? "Table"),
130
+ );
102
131
 
103
132
  // Order left→right by generality: actions applicable to the whole table (or
104
133
  // no selection) are "global" and sit after a spacer on the right (Save /
105
- // Reset / Clear-selection); everything else is contextual and stays on the
106
- // left. So the left edge tracks the selection and the right edge is constant.
134
+ // Reset); everything else is contextual and stays on the left. So the left
135
+ // edge tracks the selection and the right edge is constant.
107
136
  const isGlobal = (a: TableAction<T>) =>
108
137
  a.targets.includes(RegionCardinality.FULL_TABLE) ||
109
138
  a.targets.includes("none" as any);
110
139
  const contextual = shownActions.filter((a) => !isGlobal(a));
111
- // Order the built-in global actions least→most impactful, left→right:
112
- // clear selection, reset changes, save. Any other global actions keep their
113
- // natural order to the left of these (stable sort, rank 0).
140
+ // Order the built-in global actions least→most impactful, left→right: reset
141
+ // changes, then save. Any other global actions keep their natural order to
142
+ // the left of these (stable sort, rank 0).
114
143
  const globalOrder: Record<string, number> = {
115
- "clear-selection": 1,
116
- "reset-changes": 2,
117
- "save-changes": 3,
144
+ "reset-changes": 1,
145
+ "save-changes": 2,
118
146
  };
119
147
  const globalActions = shownActions
120
148
  .filter(isGlobal)
121
149
  .sort((a, b) => (globalOrder[a.id] ?? 0) - (globalOrder[b.id] ?? 0));
122
150
 
123
151
  return h("div.actions-toolbar", [
124
- h("span.toolbar-title", { key: "title" }, title),
152
+ titleNode,
125
153
  h(
126
154
  ButtonGroup,
127
155
  { key: "contextual", minimal: true },
@@ -287,7 +287,12 @@ export function basicCellRenderer<T>(
287
287
  isEdited: edited,
288
288
  onChange(value) {
289
289
  if (!editable) return;
290
- state.onSelectionEdited(value);
290
+ // Commit to THIS cell — not the live selection. The editor can
291
+ // commit (e.g. on blur) after the selection has moved to another
292
+ // cell or a whole column; `onSelectionEdited` would then write the
293
+ // value to the wrong target (emptying it). `onCellEdited` addresses
294
+ // the editor's own data cell.
295
+ state.onCellEdited(dataRowIndex, col.key, value);
291
296
  },
292
297
  resetValue() {
293
298
  state.resetChanges();
package/src/core.ts CHANGED
@@ -32,10 +32,13 @@ import {
32
32
  VisibleCells,
33
33
  } from "./types.ts";
34
34
  import { basicCellRenderer } from "./cell-renderer.ts";
35
- import { CellRendererDebugOverlay, tableHotkeysAtom } from "./utils";
35
+ import {
36
+ CellRendererDebugOverlay,
37
+ tableHotkeysAtom,
38
+ type ColumnSpec,
39
+ } from "./utils";
36
40
  import {
37
41
  ActionsToolbar,
38
- clearSelectionAction,
39
42
  clipboardActions,
40
43
  columnControlActions,
41
44
  createSaveAction,
@@ -89,6 +92,9 @@ interface DataSheetInternalProps<T> extends TableProps, FetchDataOptions {
89
92
  /** In-memory rows. Internally wrapped in a local `TableDataProvider` and
90
93
  * driven through the same loader as any other source. */
91
94
  data?: T[];
95
+ /** Passed through from the public props so a function form can be derived
96
+ * from the loaded rows here (a static array is handled by the provider). */
97
+ columnSpec?: ColumnSpec[] | ((rows: T[]) => ColumnSpec[]);
92
98
  // function to fetch a chunk of data (the read side of a data provider)
93
99
  fetchData?: FetchData<T>;
94
100
  /** A data provider instantiated separately and passed in — bundles the read
@@ -205,6 +211,7 @@ export function DataSheet<T>(props: DataSheetProps<T>) {
205
211
  h(_DataSheet<any>, {
206
212
  ...rest,
207
213
  data: data ?? emptyData,
214
+ columnSpec,
208
215
  children,
209
216
  editable,
210
217
  enableColumnReordering,
@@ -281,6 +288,7 @@ function _DataSheet<T>({
281
288
  actions,
282
289
  filters,
283
290
  columnHeaderCellRenderer,
291
+ columnSpec: columnSpecProp,
284
292
  statusBar,
285
293
  rowStatusStyles,
286
294
  rowHeaderRenderer,
@@ -350,7 +358,6 @@ function _DataSheet<T>({
350
358
  };
351
359
  if (actions != null) add(actions);
352
360
  add(columnControlActions);
353
- add([clearSelectionAction]);
354
361
  if (enableClipboard) add(clipboardActions);
355
362
  // Save/reset last — they're the most significant actions — and present for
356
363
  // every cardinality (editable), so the toolbar stays mounted regardless of
@@ -511,6 +518,22 @@ function _DataSheet<T>({
511
518
  });
512
519
  }, [deriveOverlay, loadedData, storeState]);
513
520
 
521
+ // Function `columnSpec`: derive the spec from the loaded rows (no separate
522
+ // fetch of sample data). Derive once the first rows arrive, and re-derive
523
+ // when the function's identity changes (a consumer memoizes it over its
524
+ // own view state — hidden columns, order, overrides). Not re-run as more
525
+ // rows page in (guarded by the function identity), so it never clobbers
526
+ // in-store column state on scroll.
527
+ const derivedSpecFor = useRef<unknown>(null);
528
+ useEffect(() => {
529
+ if (typeof columnSpecProp !== "function") return;
530
+ if (derivedSpecFor.current === columnSpecProp) return;
531
+ const rows = loadedData.filter((r) => r != null);
532
+ if (rows.length === 0) return;
533
+ derivedSpecFor.current = columnSpecProp;
534
+ storeState.setState({ columnSpec: columnSpecProp(rows) });
535
+ }, [columnSpecProp, loadedData, storeState]);
536
+
514
537
  // Imperative re-fetch: bump `refreshToken` to reload the provider (e.g. after
515
538
  // a save). Skips the initial mount (the loader does its own first fetch).
516
539
  const bumpRefreshFromToken = ctx.useSet(dataRefreshTokenAtom);
@@ -32,7 +32,9 @@ export const OPERATOR_LABELS: Record<FilterOperator, string> = {
32
32
  is: "is",
33
33
  };
34
34
 
35
- const STRING_OPERATORS: FilterOperator[] = ["eq", "neq", "ilike"];
35
+ // "contains" (`ilike`) leads for text, so it's the default operator — the most
36
+ // common intent when filtering a string column.
37
+ const STRING_OPERATORS: FilterOperator[] = ["ilike", "eq", "neq"];
36
38
  const NUMERIC_OPERATORS: FilterOperator[] = [
37
39
  "eq",
38
40
  "neq",
@@ -43,11 +45,11 @@ const NUMERIC_OPERATORS: FilterOperator[] = [
43
45
  ];
44
46
  const BOOLEAN_OPERATORS: FilterOperator[] = ["eq", "neq"];
45
47
 
46
- /** Fallback when the column has no type information. */
48
+ /** Fallback when the column has no type information. Leads with "contains". */
47
49
  export const DEFAULT_FILTER_OPERATORS: FilterOperator[] = [
50
+ "ilike",
48
51
  "eq",
49
52
  "neq",
50
- "ilike",
51
53
  "gt",
52
54
  "lt",
53
55
  "gte",
@@ -109,7 +109,6 @@ type LazyLoaderAction<T> =
109
109
  | { type: "error"; error: Error }
110
110
  | { type: "update-data"; changes: Spec<T[]> }
111
111
  | { type: "reset" }
112
- | { type: "start-reload" }
113
112
  | { type: "configure"; fetchMode: FetchMode; pageSize: number };
114
113
 
115
114
  function lazyLoadingReducer<T>(
@@ -153,18 +152,15 @@ function lazyLoadingReducer<T>(
153
152
  fetchMode: action.fetchMode,
154
153
  pageSize: action.pageSize,
155
154
  };
156
- case "start-reload":
157
- // Preserve the table dimensions but show ghost/skeleton cells
158
- return {
159
- ...state,
160
- data: new Array(state.data.length).fill(null),
161
- loading: true,
162
- initialized: false,
163
- };
164
155
  case "reset":
156
+ // A view change (or initial load) re-fetches from scratch. Rather than
157
+ // blanking the table (which reads as a jarring empty flash while the
158
+ // request is in flight — very visible on sort/filter), pre-size to a page
159
+ // of `null` ghost/skeleton rows so the body stays populated and the load
160
+ // is legible. `loaded` then adjusts the array to the real size.
165
161
  return {
166
162
  visibleRegion: defaultVisibleRegion,
167
- data: [],
163
+ data: new Array(Math.max(state.pageSize, 0)).fill(null),
168
164
  loading: false,
169
165
  error: null,
170
166
  initialized: false,
package/src/provider.ts CHANGED
@@ -2,7 +2,7 @@ import { SetStateAction, useEffect, useRef, useState } from "react";
2
2
  import h from "@macrostrat/hyper";
3
3
  import { createStore, StoreApi, useStore } from "zustand";
4
4
  import type { Table } from "@blueprintjs/table";
5
- import { generateColumnSpec } from "./utils";
5
+ import { generateColumnSpec, type ColumnSpec } from "./utils";
6
6
  import { createScopedStore } from "@macrostrat/data-components";
7
7
  import {
8
8
  DataSheetProviderProps,
@@ -48,6 +48,10 @@ export const storeAtom = atom(
48
48
  },
49
49
  );
50
50
 
51
+ /** Stable empty spec so a function `columnSpec` yields a constant init value
52
+ * (see `DataSheetProviderInner`). */
53
+ const EMPTY_SPEC: ColumnSpec[] = [];
54
+
51
55
  const initializeStoreAtom = atom(
52
56
  null,
53
57
  (get, set, payload: Partial<DataSheetStore<T>>) => {
@@ -92,17 +96,28 @@ export function DataSheetProviderInner<T>({
92
96
 
93
97
  const initializeStore = ctx.useSet(initializeStoreAtom);
94
98
 
99
+ // A function `columnSpec` is derived from the loaded rows later (in
100
+ // `_DataSheet`), not here — start it empty. Crucially it's kept OUT of the
101
+ // init effect's deps: re-running init also resets `data`, so re-initializing
102
+ // when the function's identity changes (e.g. a consumer hiding a column)
103
+ // would wipe the loaded rows. `staticSpec` is a stable value in that case.
104
+ const isFnSpec = typeof columnSpec === "function";
105
+ const staticSpec = isFnSpec ? EMPTY_SPEC : columnSpec;
106
+
95
107
  // Not sure how required this initialization is
96
108
  useEffect(() => {
97
109
  initializeStore({
98
- columnSpec: columnSpec ?? generateColumnSpec(data, columnSpecOptions),
110
+ columnSpec: staticSpec ?? generateColumnSpec(data, columnSpecOptions),
111
+ // A function spec is derived from the loaded rows in `_DataSheet`; tell
112
+ // the loader not to auto-generate a plain spec from the first chunk.
113
+ deferColumnSpec: isFnSpec,
99
114
  editable,
100
115
  enableColumnReordering,
101
116
  data,
102
117
  defaultColumnWidth,
103
118
  tableRef,
104
119
  });
105
- }, [data, editable, columnSpec, columnSpecOptions, enableColumnReordering]);
120
+ }, [data, editable, staticSpec, isFnSpec, columnSpecOptions, enableColumnReordering]);
106
121
 
107
122
  return children;
108
123
  }
@@ -135,9 +150,11 @@ export const tableDataAtom = atom(
135
150
  if (
136
151
  state.data.length == 0 &&
137
152
  newData.length > 0 &&
138
- state.columnSpec.length == 0
153
+ state.columnSpec.length == 0 &&
154
+ !state.deferColumnSpec
139
155
  ) {
140
- // We haven't yet generated the column spec, and we need to do so.
156
+ // No spec yet and none deferred to a function — auto-generate a plain
157
+ // spec from the first chunk. (A function spec is derived separately.)
141
158
  next.columnSpec = generateColumnSpec(newData, state.columnSpecOptions);
142
159
  }
143
160
 
@@ -47,8 +47,21 @@ export function renderColumnHeaderCell({
47
47
  const hasCustomActions =
48
48
  Array.isArray((col as any).actions) && (col as any).actions.length > 0;
49
49
 
50
+ // A column may be pinned against drag-reordering via `reorderable: false`.
51
+ const enableColumnReordering = col.reorderable !== false;
52
+
50
53
  if (!isSortable && !isFilterable && !hasCustomActions) {
51
- return h(ColumnHeaderCell, { name: col.name });
54
+ return h(ColumnHeaderCell, {
55
+ name: col.name,
56
+ enableColumnReordering,
57
+ nameRenderer: () =>
58
+ h(ColumnHeaderName, {
59
+ col,
60
+ hasSortActive: false,
61
+ hasFilterActive: false,
62
+ activeSort: null,
63
+ }),
64
+ });
52
65
  }
53
66
 
54
67
  // `activeFilter` is the active store entry targeting this column (any filter
@@ -58,6 +71,7 @@ export function renderColumnHeaderCell({
58
71
 
59
72
  return h(ColumnHeaderCell, {
60
73
  name: col.name,
74
+ enableColumnReordering,
61
75
  // Persistent interaction bar so the menu caret is always clickable — the
62
76
  // hover-triggered caret was blocked by the selection overlay when the
63
77
  // column was selected.
@@ -68,11 +82,16 @@ export function renderColumnHeaderCell({
68
82
  });
69
83
  }
70
84
 
71
- /** Column name with active sort/filter indicator icons. */
85
+ /** Column name with active sort/filter indicator icons. The column key is
86
+ * exposed as `data-column-key` so consumers can target a specific header from
87
+ * CSS (e.g. to tint a column) without a bespoke styling prop. */
72
88
  function ColumnHeaderName({ col, hasSortActive, hasFilterActive, activeSort }) {
73
89
  return h(
74
90
  "div",
75
- { style: { display: "flex", alignItems: "center", width: "100%" } },
91
+ {
92
+ "data-column-key": col.key,
93
+ style: { display: "flex", alignItems: "center", width: "100%" },
94
+ },
76
95
  [
77
96
  h(
78
97
  "span",
@@ -106,7 +125,7 @@ function ColumnHeaderName({ col, hasSortActive, hasFilterActive, activeSort }) {
106
125
  h.if(hasFilterActive)(Icon, {
107
126
  icon: "filter",
108
127
  size: 12,
109
- style: { color: "var(--intent-warning, #d99e0b)" },
128
+ style: { color: "var(--intent-primary, #2965cc)" },
110
129
  }),
111
130
  ],
112
131
  ),
@@ -131,9 +150,17 @@ function ColumnHeaderControls({ colIndex }: { colIndex: number }) {
131
150
  storeAPI.setState,
132
151
  );
133
152
 
153
+ // Only actions *limited* to column scope belong in a column's dropdown —
154
+ // sort/filter and column-specific actions. Global actions (Save / Reset /
155
+ // Clear-selection, marked by a FULL_TABLE or "none" target) are confusing
156
+ // here, so they're excluded even though they nominally apply to columns too.
157
+ const isGlobal = (a: (typeof actions)[number]) =>
158
+ a.targets.includes(RegionCardinality.FULL_TABLE) ||
159
+ a.targets.includes("none" as any);
134
160
  const controls = actions.filter(
135
161
  (a) =>
136
162
  a.targets.includes(RegionCardinality.FULL_COLUMNS) &&
163
+ !isGlobal(a) &&
137
164
  (a.appliesTo?.(actionCtx) ?? true),
138
165
  );
139
166
 
package/src/types.ts CHANGED
@@ -34,7 +34,12 @@ export type EditEvent<T = any> =
34
34
 
35
35
  export interface DataSheetCoreProps<T> {
36
36
  data: T[];
37
- columnSpec?: ColumnSpec[];
37
+ /** Column definitions. Either a static array, or a function derived from the
38
+ * loaded rows — invoked once the first rows arrive (and re-invoked when the
39
+ * function's identity changes), so a data-shaped spec needs no separate fetch
40
+ * of sample data. Omit entirely to auto-generate a plain spec via
41
+ * `columnSpecOptions`. */
42
+ columnSpec?: ColumnSpec[] | ((rows: T[]) => ColumnSpec[]);
38
43
  editable?: boolean;
39
44
  enableColumnReordering?: boolean;
40
45
  defaultColumnWidth?: number;
@@ -117,6 +122,10 @@ export interface ClipboardProxy {
117
122
  export interface DataSheetState<T> {
118
123
  selection: Region[];
119
124
  columnSpec: ColumnSpec[];
125
+ /** When `true`, the loader's first-chunk auto-generation of `columnSpec` is
126
+ * suppressed — a function `columnSpec` derives it from the loaded rows
127
+ * instead (in `_DataSheet`). Set at init from the prop's shape. */
128
+ deferColumnSpec: boolean;
120
129
  fillValueBaseCell: FocusedCellCoordinates | null;
121
130
  focusedCell: FocusedCellCoordinates | null;
122
131
  topLeftCell: FocusedCellCoordinates | null;
@@ -173,6 +173,10 @@ export interface ColumnSpec {
173
173
  /** Inferred data type, used to select context-appropriate filter
174
174
  * operators when `filterable` is `true` without explicit operators. */
175
175
  dataType?: ColumnDataType;
176
+ /** Whether this column may be drag-reordered. Defaults to `true`; set
177
+ * `false` to pin a fixed/system column in place. Applied by the default
178
+ * header renderer (requires table-level `enableColumnReordering`). */
179
+ reorderable?: boolean;
176
180
  }
177
181
 
178
182
  export interface ColumnSpecOptions<T> {
@@ -32,6 +32,7 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
32
32
  rowStatus: [],
33
33
  rowStatusStyles: DEFAULT_ROW_STATUS_STYLES,
34
34
  columnSpec: [],
35
+ deferColumnSpec: false,
35
36
  defaultColumnWidth: 150,
36
37
  editable: false,
37
38
  selection: [],