@macrostrat/data-sheet 4.8.0 → 4.9.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/CHANGELOG.md +33 -0
- package/README.md +60 -19
- package/dist/actions/context.cjs +10 -1
- package/dist/actions/context.cjs.map +1 -1
- package/dist/actions/context.js +10 -1
- package/dist/actions/context.js.map +1 -1
- package/dist/actions/types.d.ts +4 -0
- package/dist/components/data-editor.cjs +527 -0
- package/dist/components/data-editor.cjs.map +1 -0
- package/dist/components/data-editor.d.ts +142 -0
- package/dist/components/data-editor.js +524 -0
- package/dist/components/data-editor.js.map +1 -0
- package/dist/components/editor-actions.cjs +167 -0
- package/dist/components/editor-actions.cjs.map +1 -0
- package/dist/components/editor-actions.d.ts +37 -0
- package/dist/components/editor-actions.js +165 -0
- package/dist/components/editor-actions.js.map +1 -0
- package/dist/components/editor-popup.cjs +11 -1
- package/dist/components/editor-popup.cjs.map +1 -1
- package/dist/components/editor-popup.js +11 -1
- package/dist/components/editor-popup.js.map +1 -1
- package/dist/components/index.d.ts +3 -0
- package/dist/components/indicators/selection.cjs +10 -4
- package/dist/components/indicators/selection.cjs.map +1 -1
- package/dist/components/indicators/selection.js +10 -4
- package/dist/components/indicators/selection.js.map +1 -1
- package/dist/components/row-editor.cjs +351 -0
- package/dist/components/row-editor.cjs.map +1 -0
- package/dist/components/row-editor.d.ts +181 -0
- package/dist/components/row-editor.js +349 -0
- package/dist/components/row-editor.js.map +1 -0
- package/dist/components/row-editor.module.sass.cjs +51 -0
- package/dist/components/row-editor.module.sass.cjs.map +1 -0
- package/dist/components/row-editor.module.sass.js +49 -0
- package/dist/components/row-editor.module.sass.js.map +1 -0
- package/dist/components/toolbars/actions-toolbar.cjs +1 -1
- package/dist/components/toolbars/actions-toolbar.cjs.map +1 -1
- package/dist/components/toolbars/actions-toolbar.js +1 -1
- package/dist/components/toolbars/actions-toolbar.js.map +1 -1
- package/dist/data-sheet.css +208 -20
- package/dist/index.cjs +27 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -2
- package/dist/index.js.map +1 -1
- package/dist/main.module.sass.cjs +14 -13
- package/dist/main.module.sass.cjs.map +1 -1
- package/dist/main.module.sass.js +14 -13
- package/dist/main.module.sass.js.map +1 -1
- package/dist/provider/column-spec.cjs +8 -1
- package/dist/provider/column-spec.cjs.map +1 -1
- package/dist/provider/column-spec.d.ts +105 -1
- package/dist/provider/column-spec.js +8 -1
- package/dist/provider/column-spec.js.map +1 -1
- package/dist/provider/core.cjs +16 -4
- package/dist/provider/core.cjs.map +1 -1
- package/dist/provider/core.d.ts +4 -0
- package/dist/provider/core.js +16 -4
- package/dist/provider/core.js.map +1 -1
- package/dist/provider/types.cjs.map +1 -1
- package/dist/provider/types.d.ts +1 -1
- package/dist/provider/types.js.map +1 -1
- package/dist/provider/zustand-store.cjs +26 -13
- package/dist/provider/zustand-store.cjs.map +1 -1
- package/dist/provider/zustand-store.js +14 -1
- package/dist/provider/zustand-store.js.map +1 -1
- package/dist/renderers/cell-renderer.cjs +15 -4
- package/dist/renderers/cell-renderer.cjs.map +1 -1
- package/dist/renderers/cell-renderer.js +13 -4
- package/dist/renderers/cell-renderer.js.map +1 -1
- package/dist/renderers/column-header-cell.cjs +12 -1
- package/dist/renderers/column-header-cell.cjs.map +1 -1
- package/dist/renderers/column-header-cell.js +11 -1
- package/dist/renderers/column-header-cell.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +5 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
- package/src/actions/context.ts +13 -2
- package/src/actions/types.ts +5 -0
- package/src/components/data-editor.ts +741 -0
- package/src/components/editor-actions.ts +228 -0
- package/src/components/editor-popup.ts +16 -3
- package/src/components/index.ts +3 -0
- package/src/components/indicators/selection.ts +12 -4
- package/src/components/row-editor.module.sass +161 -0
- package/src/components/row-editor.ts +620 -0
- package/src/components/toolbars/actions-toolbar.ts +3 -2
- package/src/main.module.sass +19 -0
- package/src/provider/column-spec.ts +94 -16
- package/src/provider/core.ts +19 -4
- package/src/provider/types.ts +1 -1
- package/src/provider/zustand-store.ts +30 -1
- package/src/renderers/cell-renderer.ts +18 -3
- package/src/renderers/column-header-cell.ts +10 -0
- package/src/types.ts +5 -1
|
@@ -4,10 +4,12 @@ const h = require("@macrostrat/hyper");
|
|
|
4
4
|
const table = require("@blueprintjs/table");
|
|
5
5
|
const core = require("@blueprintjs/core");
|
|
6
6
|
const react = require("react");
|
|
7
|
+
const classNames = require("classnames");
|
|
7
8
|
const core$1 = require("../provider/core.cjs");
|
|
8
9
|
const context = require("../actions/context.cjs");
|
|
9
10
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
10
11
|
const h__default = /* @__PURE__ */ _interopDefault(h);
|
|
12
|
+
const classNames__default = /* @__PURE__ */ _interopDefault(classNames);
|
|
11
13
|
function renderColumnHeaderCell({
|
|
12
14
|
col,
|
|
13
15
|
colIndex,
|
|
@@ -64,10 +66,19 @@ function ColumnHeaderName({ col, hasSortActive, hasFilterActive, activeSort }) {
|
|
|
64
66
|
overflow: "hidden",
|
|
65
67
|
textOverflow: "ellipsis",
|
|
66
68
|
whiteSpace: "nowrap"
|
|
67
|
-
}
|
|
69
|
+
},
|
|
70
|
+
className: classNames__default.default({ "derived-column-name": col.derived })
|
|
68
71
|
},
|
|
69
72
|
col.name
|
|
70
73
|
),
|
|
74
|
+
// A derived column says so in its header: the values below are computed
|
|
75
|
+
// and won't take an edit.
|
|
76
|
+
h__default.default.if(col.derived === true)(core.Icon, {
|
|
77
|
+
icon: "function",
|
|
78
|
+
size: 12,
|
|
79
|
+
title: "Derived — computed from other values, not editable",
|
|
80
|
+
style: { marginLeft: "4px", flexShrink: 0, opacity: 0.6 }
|
|
81
|
+
}),
|
|
71
82
|
h__default.default.if(hasSortActive || hasFilterActive)(
|
|
72
83
|
"span",
|
|
73
84
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-header-cell.cjs","sources":["../../src/renderers/column-header-cell.ts"],"sourcesContent":["/**\n * Column header with client-side sort and filter controls.\n *\n * Mirrors the PostgREST column header UX but operates on in-memory data.\n * Sort state is stored in the DataSheet zustand store; filtering uses the\n * existing `setFilter` / `removeFilter` mechanism with auto-generated\n * predicate filters for simple text search.\n */\nimport h from \"@macrostrat/hyper\";\nimport { ColumnHeaderCell, RegionCardinality } from \"@blueprintjs/table\";\nimport { Icon, Menu, MenuItem } from \"@blueprintjs/core\";\nimport { ctx, tableActionsAtom, type ColumnSpec } from \"../provider\";\nimport type {\n PostgrestColumnFilter,\n ColumnSortEntry,\n} from \"../postgrest-table\";\nimport { buildActionContext } from \"../actions\";\nimport { useMemo } from \"react\";\n\nexport interface ColumnActionsConfig {\n activeSort?: ColumnSortEntry | null;\n activeFilter?: PostgrestColumnFilter | null;\n}\n\nexport interface ColumnHeaderRendererProps extends ColumnActionsConfig {\n col: ColumnSpec;\n colIndex: number;\n //actions: ColumnHeaderActions;\n}\n\n// ---- Column header cell ----\n\n/** Column header cell whose dropdown renders the `FULL_COLUMNS` controls\n * (sort/filter + any custom column actions) from the shared action registry,\n * scoped to this column. */\nexport function renderColumnHeaderCell({\n col,\n colIndex,\n activeSort,\n activeFilter,\n}: ColumnHeaderRendererProps) {\n const isSortable = col.sortable === true;\n const isFilterable =\n col.filterable === true ||\n typeof col.filterable === \"object\" ||\n (Array.isArray(col.filters) && col.filters.length > 0);\n const hasCustomActions =\n Array.isArray((col as any).actions) && (col as any).actions.length > 0;\n\n // A column may be pinned against drag-reordering via `reorderable: false`.\n const enableColumnReordering = col.reorderable !== false;\n\n if (!isSortable && !isFilterable && !hasCustomActions) {\n return h(ColumnHeaderCell, {\n name: col.name,\n enableColumnReordering,\n nameRenderer: () =>\n h(ColumnHeaderName, {\n col,\n hasSortActive: false,\n hasFilterActive: false,\n activeSort: null,\n }) as any,\n });\n }\n\n // `activeFilter` is the active store entry targeting this column (any filter\n // type), or null — so the indicator lights for rich and operator filters.\n const hasFilterActive = activeFilter != null;\n const hasSortActive = activeSort != null;\n\n return h(ColumnHeaderCell, {\n name: col.name,\n enableColumnReordering,\n // Persistent interaction bar so the menu caret is always clickable — the\n // hover-triggered caret was blocked by the selection overlay when the\n // column was selected.\n enableColumnInteractionBar: true,\n nameRenderer: () =>\n h(ColumnHeaderName, {\n col,\n hasSortActive,\n hasFilterActive,\n activeSort,\n }) as any,\n menuRenderer: () => h(ColumnHeaderControls, { colIndex }),\n });\n}\n\n/** Column name with active sort/filter indicator icons. The column key is\n * exposed as `data-column-key` so consumers can target a specific header from\n * CSS (e.g. to tint a column) without a bespoke styling prop. */\nfunction ColumnHeaderName({ col, hasSortActive, hasFilterActive, activeSort }) {\n return h(\n \"div\",\n {\n \"data-column-key\": col.key,\n style: { display: \"flex\", alignItems: \"center\", width: \"100%\" },\n },\n [\n h(\n \"span\",\n {\n style: {\n flex: 1,\n overflow: \"hidden\",\n textOverflow: \"ellipsis\",\n whiteSpace: \"nowrap\",\n },\n },\n col.name,\n ),\n h.if(hasSortActive || hasFilterActive)(\n \"span\",\n {\n style: {\n display: \"flex\",\n alignItems: \"center\",\n gap: \"2px\",\n marginLeft: \"4px\",\n flexShrink: 0,\n },\n },\n [\n h.if(hasSortActive)(Icon, {\n icon: activeSort?.ascending ? \"sort-asc\" : \"sort-desc\",\n size: 12,\n style: { color: \"var(--intent-primary, #2965cc)\" },\n }),\n h.if(hasFilterActive)(Icon, {\n icon: \"filter\",\n size: 12,\n style: { color: \"var(--intent-primary, #2965cc)\" },\n }),\n ],\n ),\n ],\n );\n}\n\n/** Dropdown content: the `FULL_COLUMNS` controls for this column, sourced from\n * the shared action registry and scoped to the column via a synthetic\n * single-column selection context — so the header and toolbar render the same\n * sort/filter (and custom column) controls. */\nfunction ColumnHeaderControls({ colIndex }: { colIndex: number }) {\n const actions = ctx.useValue(tableActionsAtom);\n const store = ctx.useStore();\n\n // Scope the action context to this column (as if it were the selection).\n const actionCtx = useMemo(() => {\n return buildActionContext(store.get, store.set, {\n singleColumn: colIndex,\n });\n }, [actions, colIndex, store]);\n\n // Only actions *limited* to column scope belong in a column's dropdown —\n // sort/filter and column-specific actions. Global actions (Save / Reset /\n // Clear-selection, marked by a FULL_TABLE or \"none\" target) are confusing\n // here, so they're excluded even though they nominally apply to columns too.\n const isGlobal = (a: (typeof actions)[number]) =>\n a.targets.includes(RegionCardinality.FULL_TABLE) ||\n a.targets.includes(\"none\" as any);\n const controls = actions.filter(\n (a) =>\n a.targets.includes(RegionCardinality.FULL_COLUMNS) &&\n !isGlobal(a) &&\n (a.appliesTo?.(actionCtx) ?? true),\n );\n\n // Prefer menu-native rendering (`renderMenuItem`) — sort/filter render as\n // items with submenus, so the whole dropdown is one Blueprint `Menu`. A\n // control that only has `render` (a live toolbar control) is embedded as-is;\n // a plain `run` action becomes a clickable item.\n const items = controls\n .map((a, i) => {\n if (a.renderMenuItem != null) return a.renderMenuItem(actionCtx);\n if (a.render != null)\n return h(\n \"li.column-header-control\",\n { key: a.id ?? i },\n a.render(actionCtx),\n );\n return h(MenuItem, {\n key: a.id ?? i,\n icon: a.icon,\n intent: a.intent,\n text: a.name,\n onClick: () => a.run?.(actionCtx),\n });\n })\n .filter(Boolean);\n\n if (items.length === 0) {\n return h(Menu, [h(MenuItem, { text: \"No options\", disabled: true })]);\n }\n\n return h(Menu, { className: \"column-header-controls\" }, items);\n}\n"],"names":["h","ColumnHeaderCell","Icon","ctx","tableActionsAtom","useMemo","buildActionContext","RegionCardinality","MenuItem","Menu"],"mappings":";;;;;;;;;;AAmCO,SAAS,uBAAuB;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA8B;AAC5B,QAAM,aAAa,IAAI,aAAa;AACpC,QAAM,eACJ,IAAI,eAAe,QACnB,OAAO,IAAI,eAAe,YACzB,MAAM,QAAQ,IAAI,OAAO,KAAK,IAAI,QAAQ,SAAS;AACtD,QAAM,mBACJ,MAAM,QAAS,IAAY,OAAO,KAAM,IAAY,QAA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KAAAA,UAAU;AAAA,MACjB,KAAK,EAAE,MAAM;AAAA,MACb,MAAM,EAAE;AAAA,MACR,QAAQ,EAAE;AAAA,MACV,MAAM,EAAE;AAAA,MACR,SAAS,MAAM,EAAE,MAAM,SAAS;AAAA,IAAA,CACjC;AAAA,EACH,CAAC,EACA,OAAO,OAAO;AAEjB,MAAI,MAAM,WAAW,GAAG;AACtB,WAAOR,mBAAES,KAAAA,MAAM,CAACT,WAAAA,QAAEQ,KAAAA,UAAU,EAAE,MAAM,cAAc,UAAU,KAAA,CAAM,CAAC,CAAC;AAAA,EACtE;AAEA,SAAOR,WAAAA,QAAES,KAAAA,MAAM,EAAE,WAAW,yBAAA,GAA4B,KAAK;AAC/D;;"}
|
|
1
|
+
{"version":3,"file":"column-header-cell.cjs","sources":["../../src/renderers/column-header-cell.ts"],"sourcesContent":["/**\n * Column header with client-side sort and filter controls.\n *\n * Mirrors the PostgREST column header UX but operates on in-memory data.\n * Sort state is stored in the DataSheet zustand store; filtering uses the\n * existing `setFilter` / `removeFilter` mechanism with auto-generated\n * predicate filters for simple text search.\n */\nimport h from \"@macrostrat/hyper\";\nimport { ColumnHeaderCell, RegionCardinality } from \"@blueprintjs/table\";\nimport { Icon, Menu, MenuItem } from \"@blueprintjs/core\";\nimport { ctx, tableActionsAtom, type ColumnSpec } from \"../provider\";\nimport type {\n PostgrestColumnFilter,\n ColumnSortEntry,\n} from \"../postgrest-table\";\nimport { buildActionContext } from \"../actions\";\nimport { useMemo } from \"react\";\nimport classNames from \"classnames\";\n\nexport interface ColumnActionsConfig {\n activeSort?: ColumnSortEntry | null;\n activeFilter?: PostgrestColumnFilter | null;\n}\n\nexport interface ColumnHeaderRendererProps extends ColumnActionsConfig {\n col: ColumnSpec;\n colIndex: number;\n //actions: ColumnHeaderActions;\n}\n\n// ---- Column header cell ----\n\n/** Column header cell whose dropdown renders the `FULL_COLUMNS` controls\n * (sort/filter + any custom column actions) from the shared action registry,\n * scoped to this column. */\nexport function renderColumnHeaderCell({\n col,\n colIndex,\n activeSort,\n activeFilter,\n}: ColumnHeaderRendererProps) {\n const isSortable = col.sortable === true;\n const isFilterable =\n col.filterable === true ||\n typeof col.filterable === \"object\" ||\n (Array.isArray(col.filters) && col.filters.length > 0);\n const hasCustomActions =\n Array.isArray((col as any).actions) && (col as any).actions.length > 0;\n\n // A column may be pinned against drag-reordering via `reorderable: false`.\n const enableColumnReordering = col.reorderable !== false;\n\n if (!isSortable && !isFilterable && !hasCustomActions) {\n return h(ColumnHeaderCell, {\n name: col.name,\n enableColumnReordering,\n nameRenderer: () =>\n h(ColumnHeaderName, {\n col,\n hasSortActive: false,\n hasFilterActive: false,\n activeSort: null,\n }) as any,\n });\n }\n\n // `activeFilter` is the active store entry targeting this column (any filter\n // type), or null — so the indicator lights for rich and operator filters.\n const hasFilterActive = activeFilter != null;\n const hasSortActive = activeSort != null;\n\n return h(ColumnHeaderCell, {\n name: col.name,\n enableColumnReordering,\n // Persistent interaction bar so the menu caret is always clickable — the\n // hover-triggered caret was blocked by the selection overlay when the\n // column was selected.\n enableColumnInteractionBar: true,\n nameRenderer: () =>\n h(ColumnHeaderName, {\n col,\n hasSortActive,\n hasFilterActive,\n activeSort,\n }) as any,\n menuRenderer: () => h(ColumnHeaderControls, { colIndex }),\n });\n}\n\n/** Column name with active sort/filter indicator icons. The column key is\n * exposed as `data-column-key` so consumers can target a specific header from\n * CSS (e.g. to tint a column) without a bespoke styling prop. */\nfunction ColumnHeaderName({ col, hasSortActive, hasFilterActive, activeSort }) {\n return h(\n \"div\",\n {\n \"data-column-key\": col.key,\n style: { display: \"flex\", alignItems: \"center\", width: \"100%\" },\n },\n [\n h(\n \"span\",\n {\n style: {\n flex: 1,\n overflow: \"hidden\",\n textOverflow: \"ellipsis\",\n whiteSpace: \"nowrap\",\n },\n className: classNames({ \"derived-column-name\": col.derived }),\n },\n col.name,\n ),\n // A derived column says so in its header: the values below are computed\n // and won't take an edit.\n h.if(col.derived === true)(Icon, {\n icon: \"function\",\n size: 12,\n title: \"Derived — computed from other values, not editable\",\n style: { marginLeft: \"4px\", flexShrink: 0, opacity: 0.6 },\n }),\n h.if(hasSortActive || hasFilterActive)(\n \"span\",\n {\n style: {\n display: \"flex\",\n alignItems: \"center\",\n gap: \"2px\",\n marginLeft: \"4px\",\n flexShrink: 0,\n },\n },\n [\n h.if(hasSortActive)(Icon, {\n icon: activeSort?.ascending ? \"sort-asc\" : \"sort-desc\",\n size: 12,\n style: { color: \"var(--intent-primary, #2965cc)\" },\n }),\n h.if(hasFilterActive)(Icon, {\n icon: \"filter\",\n size: 12,\n style: { color: \"var(--intent-primary, #2965cc)\" },\n }),\n ],\n ),\n ],\n );\n}\n\n/** Dropdown content: the `FULL_COLUMNS` controls for this column, sourced from\n * the shared action registry and scoped to the column via a synthetic\n * single-column selection context — so the header and toolbar render the same\n * sort/filter (and custom column) controls. */\nfunction ColumnHeaderControls({ colIndex }: { colIndex: number }) {\n const actions = ctx.useValue(tableActionsAtom);\n const store = ctx.useStore();\n\n // Scope the action context to this column (as if it were the selection).\n const actionCtx = useMemo(() => {\n return buildActionContext(store.get, store.set, {\n singleColumn: colIndex,\n });\n }, [actions, colIndex, store]);\n\n // Only actions *limited* to column scope belong in a column's dropdown —\n // sort/filter and column-specific actions. Global actions (Save / Reset /\n // Clear-selection, marked by a FULL_TABLE or \"none\" target) are confusing\n // here, so they're excluded even though they nominally apply to columns too.\n const isGlobal = (a: (typeof actions)[number]) =>\n a.targets.includes(RegionCardinality.FULL_TABLE) ||\n a.targets.includes(\"none\" as any);\n const controls = actions.filter(\n (a) =>\n a.targets.includes(RegionCardinality.FULL_COLUMNS) &&\n !isGlobal(a) &&\n (a.appliesTo?.(actionCtx) ?? true),\n );\n\n // Prefer menu-native rendering (`renderMenuItem`) — sort/filter render as\n // items with submenus, so the whole dropdown is one Blueprint `Menu`. A\n // control that only has `render` (a live toolbar control) is embedded as-is;\n // a plain `run` action becomes a clickable item.\n const items = controls\n .map((a, i) => {\n if (a.renderMenuItem != null) return a.renderMenuItem(actionCtx);\n if (a.render != null)\n return h(\n \"li.column-header-control\",\n { key: a.id ?? i },\n a.render(actionCtx),\n );\n return h(MenuItem, {\n key: a.id ?? i,\n icon: a.icon,\n intent: a.intent,\n text: a.name,\n onClick: () => a.run?.(actionCtx),\n });\n })\n .filter(Boolean);\n\n if (items.length === 0) {\n return h(Menu, [h(MenuItem, { text: \"No options\", disabled: true })]);\n }\n\n return h(Menu, { className: \"column-header-controls\" }, items);\n}\n"],"names":["h","ColumnHeaderCell","classNames","Icon","ctx","tableActionsAtom","useMemo","buildActionContext","RegionCardinality","MenuItem","Menu"],"mappings":";;;;;;;;;;;;AAoCO,SAAS,uBAAuB;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA8B;AAC5B,QAAM,aAAa,IAAI,aAAa;AACpC,QAAM,eACJ,IAAI,eAAe,QACnB,OAAO,IAAI,eAAe,YACzB,MAAM,QAAQ,IAAI,OAAO,KAAK,IAAI,QAAQ,SAAS;AACtD,QAAM,mBACJ,MAAM,QAAS,IAAY,OAAO,KAAM,IAAY,QAAQ,SAAS;AAGvE,QAAM,yBAAyB,IAAI,gBAAgB;AAEnD,MAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC,kBAAkB;AACrD,WAAOA,WAAAA,QAAEC,MAAAA,kBAAkB;AAAA,MACzB,MAAM,IAAI;AAAA,MACV;AAAA,MACA,cAAc,MACZD,WAAAA,QAAE,kBAAkB;AAAA,QAClB;AAAA,QACA,eAAe;AAAA,QACf,iBAAiB;AAAA,QACjB,YAAY;AAAA,MAAA,CACb;AAAA,IAAA,CACJ;AAAA,EACH;AAIA,QAAM,kBAAkB,gBAAgB;AACxC,QAAM,gBAAgB,cAAc;AAEpC,SAAOA,WAAAA,QAAEC,MAAAA,kBAAkB;AAAA,IACzB,MAAM,IAAI;AAAA,IACV;AAAA;AAAA;AAAA;AAAA,IAIA,4BAA4B;AAAA,IAC5B,cAAc,MACZD,WAAAA,QAA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CAACV,WAAAA,QAAES,KAAAA,UAAU,EAAE,MAAM,cAAc,UAAU,KAAA,CAAM,CAAC,CAAC;AAAA,EACtE;AAEA,SAAOT,WAAAA,QAAEU,KAAAA,MAAM,EAAE,WAAW,yBAAA,GAA4B,KAAK;AAC/D;;"}
|
|
@@ -2,6 +2,7 @@ import h from "@macrostrat/hyper";
|
|
|
2
2
|
import { ColumnHeaderCell, RegionCardinality } from "@blueprintjs/table";
|
|
3
3
|
import { Icon, MenuItem, Menu } from "@blueprintjs/core";
|
|
4
4
|
import { useMemo } from "react";
|
|
5
|
+
import classNames from "classnames";
|
|
5
6
|
import { ctx, tableActionsAtom } from "../provider/core.js";
|
|
6
7
|
import { buildActionContext } from "../actions/context.js";
|
|
7
8
|
function renderColumnHeaderCell({
|
|
@@ -60,10 +61,19 @@ function ColumnHeaderName({ col, hasSortActive, hasFilterActive, activeSort }) {
|
|
|
60
61
|
overflow: "hidden",
|
|
61
62
|
textOverflow: "ellipsis",
|
|
62
63
|
whiteSpace: "nowrap"
|
|
63
|
-
}
|
|
64
|
+
},
|
|
65
|
+
className: classNames({ "derived-column-name": col.derived })
|
|
64
66
|
},
|
|
65
67
|
col.name
|
|
66
68
|
),
|
|
69
|
+
// A derived column says so in its header: the values below are computed
|
|
70
|
+
// and won't take an edit.
|
|
71
|
+
h.if(col.derived === true)(Icon, {
|
|
72
|
+
icon: "function",
|
|
73
|
+
size: 12,
|
|
74
|
+
title: "Derived — computed from other values, not editable",
|
|
75
|
+
style: { marginLeft: "4px", flexShrink: 0, opacity: 0.6 }
|
|
76
|
+
}),
|
|
67
77
|
h.if(hasSortActive || hasFilterActive)(
|
|
68
78
|
"span",
|
|
69
79
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-header-cell.js","sources":["../../src/renderers/column-header-cell.ts"],"sourcesContent":["/**\n * Column header with client-side sort and filter controls.\n *\n * Mirrors the PostgREST column header UX but operates on in-memory data.\n * Sort state is stored in the DataSheet zustand store; filtering uses the\n * existing `setFilter` / `removeFilter` mechanism with auto-generated\n * predicate filters for simple text search.\n */\nimport h from \"@macrostrat/hyper\";\nimport { ColumnHeaderCell, RegionCardinality } from \"@blueprintjs/table\";\nimport { Icon, Menu, MenuItem } from \"@blueprintjs/core\";\nimport { ctx, tableActionsAtom, type ColumnSpec } from \"../provider\";\nimport type {\n PostgrestColumnFilter,\n ColumnSortEntry,\n} from \"../postgrest-table\";\nimport { buildActionContext } from \"../actions\";\nimport { useMemo } from \"react\";\n\nexport interface ColumnActionsConfig {\n activeSort?: ColumnSortEntry | null;\n activeFilter?: PostgrestColumnFilter | null;\n}\n\nexport interface ColumnHeaderRendererProps extends ColumnActionsConfig {\n col: ColumnSpec;\n colIndex: number;\n //actions: ColumnHeaderActions;\n}\n\n// ---- Column header cell ----\n\n/** Column header cell whose dropdown renders the `FULL_COLUMNS` controls\n * (sort/filter + any custom column actions) from the shared action registry,\n * scoped to this column. */\nexport function renderColumnHeaderCell({\n col,\n colIndex,\n activeSort,\n activeFilter,\n}: ColumnHeaderRendererProps) {\n const isSortable = col.sortable === true;\n const isFilterable =\n col.filterable === true ||\n typeof col.filterable === \"object\" ||\n (Array.isArray(col.filters) && col.filters.length > 0);\n const hasCustomActions =\n Array.isArray((col as any).actions) && (col as any).actions.length > 0;\n\n // A column may be pinned against drag-reordering via `reorderable: false`.\n const enableColumnReordering = col.reorderable !== false;\n\n if (!isSortable && !isFilterable && !hasCustomActions) {\n return h(ColumnHeaderCell, {\n name: col.name,\n enableColumnReordering,\n nameRenderer: () =>\n h(ColumnHeaderName, {\n col,\n hasSortActive: false,\n hasFilterActive: false,\n activeSort: null,\n }) as any,\n });\n }\n\n // `activeFilter` is the active store entry targeting this column (any filter\n // type), or null — so the indicator lights for rich and operator filters.\n const hasFilterActive = activeFilter != null;\n const hasSortActive = activeSort != null;\n\n return h(ColumnHeaderCell, {\n name: col.name,\n enableColumnReordering,\n // Persistent interaction bar so the menu caret is always clickable — the\n // hover-triggered caret was blocked by the selection overlay when the\n // column was selected.\n enableColumnInteractionBar: true,\n nameRenderer: () =>\n h(ColumnHeaderName, {\n col,\n hasSortActive,\n hasFilterActive,\n activeSort,\n }) as any,\n menuRenderer: () => h(ColumnHeaderControls, { colIndex }),\n });\n}\n\n/** Column name with active sort/filter indicator icons. The column key is\n * exposed as `data-column-key` so consumers can target a specific header from\n * CSS (e.g. to tint a column) without a bespoke styling prop. */\nfunction ColumnHeaderName({ col, hasSortActive, hasFilterActive, activeSort }) {\n return h(\n \"div\",\n {\n \"data-column-key\": col.key,\n style: { display: \"flex\", alignItems: \"center\", width: \"100%\" },\n },\n [\n h(\n \"span\",\n {\n style: {\n flex: 1,\n overflow: \"hidden\",\n textOverflow: \"ellipsis\",\n whiteSpace: \"nowrap\",\n },\n },\n col.name,\n ),\n h.if(hasSortActive || hasFilterActive)(\n \"span\",\n {\n style: {\n display: \"flex\",\n alignItems: \"center\",\n gap: \"2px\",\n marginLeft: \"4px\",\n flexShrink: 0,\n },\n },\n [\n h.if(hasSortActive)(Icon, {\n icon: activeSort?.ascending ? \"sort-asc\" : \"sort-desc\",\n size: 12,\n style: { color: \"var(--intent-primary, #2965cc)\" },\n }),\n h.if(hasFilterActive)(Icon, {\n icon: \"filter\",\n size: 12,\n style: { color: \"var(--intent-primary, #2965cc)\" },\n }),\n ],\n ),\n ],\n );\n}\n\n/** Dropdown content: the `FULL_COLUMNS` controls for this column, sourced from\n * the shared action registry and scoped to the column via a synthetic\n * single-column selection context — so the header and toolbar render the same\n * sort/filter (and custom column) controls. */\nfunction ColumnHeaderControls({ colIndex }: { colIndex: number }) {\n const actions = ctx.useValue(tableActionsAtom);\n const store = ctx.useStore();\n\n // Scope the action context to this column (as if it were the selection).\n const actionCtx = useMemo(() => {\n return buildActionContext(store.get, store.set, {\n singleColumn: colIndex,\n });\n }, [actions, colIndex, store]);\n\n // Only actions *limited* to column scope belong in a column's dropdown —\n // sort/filter and column-specific actions. Global actions (Save / Reset /\n // Clear-selection, marked by a FULL_TABLE or \"none\" target) are confusing\n // here, so they're excluded even though they nominally apply to columns too.\n const isGlobal = (a: (typeof actions)[number]) =>\n a.targets.includes(RegionCardinality.FULL_TABLE) ||\n a.targets.includes(\"none\" as any);\n const controls = actions.filter(\n (a) =>\n a.targets.includes(RegionCardinality.FULL_COLUMNS) &&\n !isGlobal(a) &&\n (a.appliesTo?.(actionCtx) ?? true),\n );\n\n // Prefer menu-native rendering (`renderMenuItem`) — sort/filter render as\n // items with submenus, so the whole dropdown is one Blueprint `Menu`. A\n // control that only has `render` (a live toolbar control) is embedded as-is;\n // a plain `run` action becomes a clickable item.\n const items = controls\n .map((a, i) => {\n if (a.renderMenuItem != null) return a.renderMenuItem(actionCtx);\n if (a.render != null)\n return h(\n \"li.column-header-control\",\n { key: a.id ?? i },\n a.render(actionCtx),\n );\n return h(MenuItem, {\n key: a.id ?? i,\n icon: a.icon,\n intent: a.intent,\n text: a.name,\n onClick: () => a.run?.(actionCtx),\n });\n })\n .filter(Boolean);\n\n if (items.length === 0) {\n return h(Menu, [h(MenuItem, { text: \"No options\", disabled: true })]);\n }\n\n return h(Menu, { className: \"column-header-controls\" }, items);\n}\n"],"names":[],"mappings":";;;;;;AAmCO,SAAS,uBAAuB;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA8B;AAC5B,QAAM,aAAa,IAAI,aAAa;AACpC,QAAM,eACJ,IAAI,eAAe,QACnB,OAAO,IAAI,eAAe,YACzB,MAAM,QAAQ,IAAI,OAAO,KAAK,IAAI,QAAQ,SAAS;AACtD,QAAM,mBACJ,MAAM,QAAS,IAAY,OAAO,KAAM,IAAY,QAAQ,SAAS;AAGvE,QAAM,yBAAyB,IAAI,gBAAgB;AAEnD,MAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC,kBAAkB;AACrD,WAAO,EAAE,kBAAkB;AAAA,MACzB,MAAM,IAAI;AAAA,MACV;AAAA,MACA,cAAc,MACZ,EAAE,kBAAkB;AAAA,QAClB;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,yBAAA,GAA4B,KAAK;AAC/D;"}
|
|
1
|
+
{"version":3,"file":"column-header-cell.js","sources":["../../src/renderers/column-header-cell.ts"],"sourcesContent":["/**\n * Column header with client-side sort and filter controls.\n *\n * Mirrors the PostgREST column header UX but operates on in-memory data.\n * Sort state is stored in the DataSheet zustand store; filtering uses the\n * existing `setFilter` / `removeFilter` mechanism with auto-generated\n * predicate filters for simple text search.\n */\nimport h from \"@macrostrat/hyper\";\nimport { ColumnHeaderCell, RegionCardinality } from \"@blueprintjs/table\";\nimport { Icon, Menu, MenuItem } from \"@blueprintjs/core\";\nimport { ctx, tableActionsAtom, type ColumnSpec } from \"../provider\";\nimport type {\n PostgrestColumnFilter,\n ColumnSortEntry,\n} from \"../postgrest-table\";\nimport { buildActionContext } from \"../actions\";\nimport { useMemo } from \"react\";\nimport classNames from \"classnames\";\n\nexport interface ColumnActionsConfig {\n activeSort?: ColumnSortEntry | null;\n activeFilter?: PostgrestColumnFilter | null;\n}\n\nexport interface ColumnHeaderRendererProps extends ColumnActionsConfig {\n col: ColumnSpec;\n colIndex: number;\n //actions: ColumnHeaderActions;\n}\n\n// ---- Column header cell ----\n\n/** Column header cell whose dropdown renders the `FULL_COLUMNS` controls\n * (sort/filter + any custom column actions) from the shared action registry,\n * scoped to this column. */\nexport function renderColumnHeaderCell({\n col,\n colIndex,\n activeSort,\n activeFilter,\n}: ColumnHeaderRendererProps) {\n const isSortable = col.sortable === true;\n const isFilterable =\n col.filterable === true ||\n typeof col.filterable === \"object\" ||\n (Array.isArray(col.filters) && col.filters.length > 0);\n const hasCustomActions =\n Array.isArray((col as any).actions) && (col as any).actions.length > 0;\n\n // A column may be pinned against drag-reordering via `reorderable: false`.\n const enableColumnReordering = col.reorderable !== false;\n\n if (!isSortable && !isFilterable && !hasCustomActions) {\n return h(ColumnHeaderCell, {\n name: col.name,\n enableColumnReordering,\n nameRenderer: () =>\n h(ColumnHeaderName, {\n col,\n hasSortActive: false,\n hasFilterActive: false,\n activeSort: null,\n }) as any,\n });\n }\n\n // `activeFilter` is the active store entry targeting this column (any filter\n // type), or null — so the indicator lights for rich and operator filters.\n const hasFilterActive = activeFilter != null;\n const hasSortActive = activeSort != null;\n\n return h(ColumnHeaderCell, {\n name: col.name,\n enableColumnReordering,\n // Persistent interaction bar so the menu caret is always clickable — the\n // hover-triggered caret was blocked by the selection overlay when the\n // column was selected.\n enableColumnInteractionBar: true,\n nameRenderer: () =>\n h(ColumnHeaderName, {\n col,\n hasSortActive,\n hasFilterActive,\n activeSort,\n }) as any,\n menuRenderer: () => h(ColumnHeaderControls, { colIndex }),\n });\n}\n\n/** Column name with active sort/filter indicator icons. The column key is\n * exposed as `data-column-key` so consumers can target a specific header from\n * CSS (e.g. to tint a column) without a bespoke styling prop. */\nfunction ColumnHeaderName({ col, hasSortActive, hasFilterActive, activeSort }) {\n return h(\n \"div\",\n {\n \"data-column-key\": col.key,\n style: { display: \"flex\", alignItems: \"center\", width: \"100%\" },\n },\n [\n h(\n \"span\",\n {\n style: {\n flex: 1,\n overflow: \"hidden\",\n textOverflow: \"ellipsis\",\n whiteSpace: \"nowrap\",\n },\n className: classNames({ \"derived-column-name\": col.derived }),\n },\n col.name,\n ),\n // A derived column says so in its header: the values below are computed\n // and won't take an edit.\n h.if(col.derived === true)(Icon, {\n icon: \"function\",\n size: 12,\n title: \"Derived — computed from other values, not editable\",\n style: { marginLeft: \"4px\", flexShrink: 0, opacity: 0.6 },\n }),\n h.if(hasSortActive || hasFilterActive)(\n \"span\",\n {\n style: {\n display: \"flex\",\n alignItems: \"center\",\n gap: \"2px\",\n marginLeft: \"4px\",\n flexShrink: 0,\n },\n },\n [\n h.if(hasSortActive)(Icon, {\n icon: activeSort?.ascending ? \"sort-asc\" : \"sort-desc\",\n size: 12,\n style: { color: \"var(--intent-primary, #2965cc)\" },\n }),\n h.if(hasFilterActive)(Icon, {\n icon: \"filter\",\n size: 12,\n style: { color: \"var(--intent-primary, #2965cc)\" },\n }),\n ],\n ),\n ],\n );\n}\n\n/** Dropdown content: the `FULL_COLUMNS` controls for this column, sourced from\n * the shared action registry and scoped to the column via a synthetic\n * single-column selection context — so the header and toolbar render the same\n * sort/filter (and custom column) controls. */\nfunction ColumnHeaderControls({ colIndex }: { colIndex: number }) {\n const actions = ctx.useValue(tableActionsAtom);\n const store = ctx.useStore();\n\n // Scope the action context to this column (as if it were the selection).\n const actionCtx = useMemo(() => {\n return buildActionContext(store.get, store.set, {\n singleColumn: colIndex,\n });\n }, [actions, colIndex, store]);\n\n // Only actions *limited* to column scope belong in a column's dropdown —\n // sort/filter and column-specific actions. Global actions (Save / Reset /\n // Clear-selection, marked by a FULL_TABLE or \"none\" target) are confusing\n // here, so they're excluded even though they nominally apply to columns too.\n const isGlobal = (a: (typeof actions)[number]) =>\n a.targets.includes(RegionCardinality.FULL_TABLE) ||\n a.targets.includes(\"none\" as any);\n const controls = actions.filter(\n (a) =>\n a.targets.includes(RegionCardinality.FULL_COLUMNS) &&\n !isGlobal(a) &&\n (a.appliesTo?.(actionCtx) ?? true),\n );\n\n // Prefer menu-native rendering (`renderMenuItem`) — sort/filter render as\n // items with submenus, so the whole dropdown is one Blueprint `Menu`. A\n // control that only has `render` (a live toolbar control) is embedded as-is;\n // a plain `run` action becomes a clickable item.\n const items = controls\n .map((a, i) => {\n if (a.renderMenuItem != null) return a.renderMenuItem(actionCtx);\n if (a.render != null)\n return h(\n \"li.column-header-control\",\n { key: a.id ?? i },\n a.render(actionCtx),\n );\n return h(MenuItem, {\n key: a.id ?? i,\n icon: a.icon,\n intent: a.intent,\n text: a.name,\n onClick: () => a.run?.(actionCtx),\n });\n })\n .filter(Boolean);\n\n if (items.length === 0) {\n return h(Menu, [h(MenuItem, { text: \"No options\", disabled: true })]);\n }\n\n return h(Menu, { className: \"column-header-controls\" }, items);\n}\n"],"names":[],"mappings":";;;;;;;AAoCO,SAAS,uBAAuB;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA8B;AAC5B,QAAM,aA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SAAS,KAAK;AAAA,EAAA;AAOjC,QAAM,QAAQ,SACX,IAAI,CAAC,GAAG,MAAM;AACb,QAAI,EAAE,kBAAkB,KAAM,QAAO,EAAE,eAAe,SAAS;AAC/D,QAAI,EAAE,UAAU;AACd,aAAO;AAAA,QACL;AAAA,QACA,EAAE,KAAK,EAAE,MAAM,EAAA;AAAA,QACf,EAAE,OAAO,SAAS;AAAA,MAAA;AAEtB,WAAO,EAAE,UAAU;AAAA,MACjB,KAAK,EAAE,MAAM;AAAA,MACb,MAAM,EAAE;AAAA,MACR,QAAQ,EAAE;AAAA,MACV,MAAM,EAAE;AAAA,MACR,SAAS,MAAM,EAAE,MAAM,SAAS;AAAA,IAAA,CACjC;AAAA,EACH,CAAC,EACA,OAAO,OAAO;AAEjB,MAAI,MAAM,WAAW,GAAG;AACtB,WAAO,EAAE,MAAM,CAAC,EAAE,UAAU,EAAE,MAAM,cAAc,UAAU,KAAA,CAAM,CAAC,CAAC;AAAA,EACtE;AAEA,SAAO,EAAE,MAAM,EAAE,WAAW,yBAAA,GAA4B,KAAK;AAC/D;"}
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sources":["../src/types.ts"],"sourcesContent":["import {\n EditEvent,\n FetchData,\n InteractionOptions,\n RowHeaderRenderContext,\n RowStatusStyles,\n TableDataProvider,\n TableElementStatus,\n VisibleCells,\n} from \"./provider\";\nimport type { ColumnSort, ColumnSpec, ColumnSpecOptions } from \"./provider\";\nimport { ReactNode } from \"react\";\nimport {\n ActiveFilterEntry,\n TableAction,\n TableActionContext,\n TableFilter,\n} from \"./actions\";\nimport { Region, TableProps } from \"@blueprintjs/table\";\n\nexport type FetchMode = \"scroll\" | \"paged\";\n\nexport interface InitialDataChunk<T = any> {\n rows: T[];\n /** Total rows in the source, when the caller's fetch reported it. */\n totalCount?: number | null;\n}\n\nexport interface FetchDataOptions<T = any> {\n pageSize?: number;\n fetchMode?: FetchMode;\n /** Rows already in hand for the first window — typically fetched outside the\n * view (a server render, a parent that needed the data anyway) — so mounting\n * doesn't re-request a page the caller already has. The loader starts\n * populated and initialized; scrolling past the seed fetches as usual, and any\n * view change discards it and re-fetches (the seed only describes the view it\n * was fetched for, so pass matching `initialFilters` / `initialSorts`).\n *\n * Pass `totalCount` when it's known — the array is pre-sized to it, so the\n * scrollbar and the counter are right from the first paint. */\n initialData?: T[] | InitialDataChunk<T>;\n /** Identity of the row the view starts after — the keyset cursor of a view\n * that begins mid-list, as reached through a page link (`?after=<id>`). It is\n * passed to the provider as `after` on every chunk of the view it was created\n * for, and dropped on the first view change (sorts, filters, a refresh), since\n * it only describes that view. Read from the URL when the page loads; the\n * client never writes it back while scrolling. Pair it with an `initialData`\n * seed of the rows after it for a complete server render. */\n startAfter?: string | number | null;\n /** Debounce (ms) applied to view-state → refetch, so rapid changes (typing a\n * text filter) collapse into one fetch once the view settles. The input stays\n * instant; only the fetch waits. `0` (default) keeps immediate refetching. */\n filterDebounce?: number;\n}\n\n/** Props shared between the wrapper components and the provider */\nexport interface DataViewCoreProps<T> extends InteractionOptions {\n /** In-memory rows. Internally wrapped in a local `TableDataProvider` and\n * driven through the same loader as any other source. */\n data?: T[];\n /** Column definitions. Either a static array, or a function derived from the\n * loaded rows — invoked once the first rows arrive (and re-invoked when the\n * function's identity changes), so a data-shaped spec needs no separate fetch\n * of sample data. Omit entirely to auto-generate a plain spec via\n * `columnSpecOptions`. */\n columnSpec?: ColumnSpec[] | ((rows: T[]) => ColumnSpec[]);\n columnSpecOptions?: ColumnSpecOptions<T>;\n enableColumnReordering?: boolean;\n defaultColumnWidth?: number;\n // function to fetch a chunk of data (the read side of a data provider)\n fetchData?: FetchData<T>;\n /** A data provider instantiated separately and passed in — bundles the read\n * side (`fetchData` + `identity`) and, optionally, the persistence side\n * (`saveRows` / `deleteRows` / `insertRow`) that drives the Save action. An\n * explicit alternative to the loose `data` / `fetchData` / `identity` props;\n * takes precedence when given. */\n provider?: TableDataProvider<T>;\n /** Row identity for the edit overlay — stable across a provider re-sort (a\n * data provider supplies its own; defaults to `(row) => row?.id`). Lets edits\n * survive a re-ordered re-fetch. */\n identity?: (row: T) => string | number | null | undefined;\n /** Shown as the toolbar's leading label when nothing is selected. */\n name?: string;\n // itemLabel (e.g., \"row\", \"item\")\n itemLabel?: string;\n /** Bump to force a re-fetch from scratch (e.g. after an immediate edit that\n * mutated rows through the provider). */\n refreshToken?: number | string;\n /** Filters active from the start, applied when the store is *created* rather\n * than in an effect — so a restored view (from a link, a saved query, a\n * server render) never fires an unfiltered fetch first and immediately\n * supersedes it. Uncontrolled: the user's later changes win, and changing\n * this prop afterwards does nothing. */\n initialFilters?: ActiveFilterEntry[];\n /** Sorts active from the start. Same contract as `initialFilters`. */\n initialSorts?: ColumnSort[];\n}\n\n/** Links that make a paged view reachable without JavaScript. */\nexport interface PageLinks<T = any> {\n /** The href of the view that starts after `row` (`?after=<id>`). Rendered as\n * a visually hidden `rel=\"next\"` link after the loaded rows, so a crawler\n * following the server-rendered HTML reaches every page of the list while\n * readers keep the infinite scroll. */\n after: (row: T) => string;\n /** The href of the view's first page. Shown as a \"Return to top\" link at the\n * head of the content while the view starts mid-list (`startAfter`). */\n top?: string;\n /** Label for that link (default \"Return to top\"). */\n topLabel?: ReactNode;\n}\n\nexport interface DataViewSharedProps<T = any>\n extends FetchDataOptions<T>, DataViewCoreProps<T> {\n /** Crawlable page links (see `PageLinks`). Neither link is written to the\n * browser's URL as the list is scrolled — deep pages are for crawlers and\n * for whoever follows such a link, not a state the page keeps. */\n pageLinks?: PageLinks<T>;\n /** Configurable table actions shown in a selection-aware toolbar.\n * When provided, the actions toolbar renders alongside the existing\n * edit toolbar. Actions are filtered by the current selection cardinality. */\n actions?: TableAction<T>[];\n /** Available column/table filters shown in a filter bar.\n * Filters can also be defined per-column via `ColumnSpec.filters`. */\n filters?: TableFilter<T>[];\n //enableSelection?: boolean;\n}\n\nexport enum DataSheetDensity {\n HIGH = \"high\",\n MEDIUM = \"medium\",\n LOW = \"low\",\n}\n\n/**\n * How selecting a cell activates its surface (an editor, or a read-only detail\n * panel):\n * - `\"auto\"` (default when `autoFocusEditor` is `true`): open the surface on\n * selection and, for editors, focus it. Editors relinquish focus at their\n * edges — arrow past the start/end of a text cell, or press Escape, and focus\n * returns to the table — so the keyboard stays operable without the mouse.\n * Pressing Escape drops into navigation mode (surfaces stop auto-opening)\n * until the next click.\n * - `\"manual\"` (default when `autoFocusEditor` is `false`): the surface stays\n * closed until the cell is clicked; arrow keys always navigate the table.\n */\nexport type CellInteraction = \"auto\" | \"manual\";\n\nexport interface DataSheetRendererProps<T = any>\n extends TableProps, DataViewSharedProps<T> {\n onVisibleCellsChange?: (visibleCells: VisibleCells) => void;\n onUpdateData?: (updatedData: any[], data: T[]) => void;\n /** Observer called for every user edit as a structured `EditEvent`\n * (Workstream A). Additive: the built-in `updatedData` overlay still\n * applies. */\n onEdit?: (event: EditEvent<T>) => void;\n /** Controlled edited-cell overlay (Workstream A). When provided, it is\n * synced into the store as the source of truth for edited values — pair with\n * `onEdit` to own edit state externally (e.g. an ops model). Optimistic\n * in-table edits are superseded by the next value you pass back. */\n updatedData?: T[];\n /** Controlled row-status overlay (edited / added / deleted), the companion\n * to `updatedData`. */\n rowStatus?: TableElementStatus[];\n\n /** Derive the controlled edit overlay from the loaded rows, *inside* the\n * sheet. For provider-backed tables whose overlay is a function of the loaded\n * data plus external edit state (e.g. an ops stack): the library owns the\n * rows, so it calls this with them and uses the result as the controlled\n * overlay, re-deriving when the rows — or this function's identity (close it\n * over your edit state) — change. Supersedes `updatedData`/`rowStatus`. */\n deriveOverlay?: (rows: T[]) => {\n updatedData: T[];\n rowStatus: TableElementStatus[];\n };\n /** Persistence handler for the built-in Save action. When provided, a Save\n * control is added to the toolbar (always visible, disabled when there are\n * no pending changes). */\n onSave?: (ctx: TableActionContext<T>) => void | Promise<void>;\n onDeleteRows?: (selection: Region[]) => void;\n verbose?: boolean;\n enableColumnReordering?: boolean;\n enableClipboard?: boolean;\n enableFocusedCell?: boolean;\n /** @deprecated Prefer `cellInteraction`. `true` maps to `\"auto\"`,\n * `false` to `\"manual\"`. */\n autoFocusEditor?: boolean;\n /** How selecting a cell activates its surface (editor or detail panel).\n * Defaults from `autoFocusEditor` for backward compatibility. */\n cellInteraction?: CellInteraction;\n density?: DataSheetDensity;\n /** Optional custom column header cell renderer, called for each column.\n * Receives the ColumnSpec and column index; should return a React element\n * (typically a Blueprint ColumnHeaderCell). */\n columnHeaderCellRenderer?: (col: any, colIndex: number) => ReactNode;\n /** Arbitrary nodes for the bottom status bar (left group), rendered beside\n * the active sort/filter tags — the home for view-state controls (show/hide\n * omitted rows/columns, a group-by indicator, etc.). */\n statusBar?: ReactNode;\n /** Presentation per row-status value, merged over the built-in defaults\n * (which style `\"deleted\"`). Supply styles for consumer-defined statuses\n * (e.g. `\"omitted\"`) and/or override the defaults. Each entry may set the\n * cells' style/intent and the row header's style. */\n rowStatusStyles?: RowStatusStyles;\n /** Render the content of a row's header cell (the left gutter). Receives the\n * row, its status, and the default 1-based label; return a node to use, or a\n * nullish value to keep the default. For group-key labels, omit indicators,\n * etc. Header-cell *styling* still comes from `rowStatusStyles`. */\n rowHeaderRenderer?: (ctx: RowHeaderRenderContext<T>) => ReactNode;\n minRowHeight: number;\n defaultColumnWidth: number;\n debug: boolean;\n}\n\nexport type DataSheetProps<T> = DataViewCoreProps<T> &\n DataSheetRendererProps<T>;\n"],"names":["DataSheetDensity"],"mappings":";;AAgIO,IAAK,qCAAAA,sBAAL;AACLA,oBAAA,MAAA,IAAO;AACPA,oBAAA,QAAA,IAAS;AACTA,oBAAA,KAAA,IAAM;AAHI,SAAAA;AAAA,GAAA,oBAAA,CAAA,CAAA;;"}
|
|
1
|
+
{"version":3,"file":"types.cjs","sources":["../src/types.ts"],"sourcesContent":["import {\n EditEvent,\n FetchData,\n InteractionOptions,\n RowHeaderRenderContext,\n RowStatusStyles,\n TableDataProvider,\n TableElementStatus,\n VisibleCells,\n} from \"./provider\";\nimport type { ColumnSort, ColumnSpec, ColumnSpecOptions } from \"./provider\";\nimport { ReactNode } from \"react\";\nimport {\n ActiveFilterEntry,\n TableAction,\n TableActionContext,\n TableFilter,\n} from \"./actions\";\nimport { Region, TableProps } from \"@blueprintjs/table\";\n\nexport type FetchMode = \"scroll\" | \"paged\";\n\nexport interface InitialDataChunk<T = any> {\n rows: T[];\n /** Total rows in the source, when the caller's fetch reported it. */\n totalCount?: number | null;\n}\n\nexport interface FetchDataOptions<T = any> {\n pageSize?: number;\n fetchMode?: FetchMode;\n /** Rows already in hand for the first window — typically fetched outside the\n * view (a server render, a parent that needed the data anyway) — so mounting\n * doesn't re-request a page the caller already has. The loader starts\n * populated and initialized; scrolling past the seed fetches as usual, and any\n * view change discards it and re-fetches (the seed only describes the view it\n * was fetched for, so pass matching `initialFilters` / `initialSorts`).\n *\n * Pass `totalCount` when it's known — the array is pre-sized to it, so the\n * scrollbar and the counter are right from the first paint. */\n initialData?: T[] | InitialDataChunk<T>;\n /** Identity of the row the view starts after — the keyset cursor of a view\n * that begins mid-list, as reached through a page link (`?after=<id>`). It is\n * passed to the provider as `after` on every chunk of the view it was created\n * for, and dropped on the first view change (sorts, filters, a refresh), since\n * it only describes that view. Read from the URL when the page loads; the\n * client never writes it back while scrolling. Pair it with an `initialData`\n * seed of the rows after it for a complete server render. */\n startAfter?: string | number | null;\n /** Debounce (ms) applied to view-state → refetch, so rapid changes (typing a\n * text filter) collapse into one fetch once the view settles. The input stays\n * instant; only the fetch waits. `0` (default) keeps immediate refetching. */\n filterDebounce?: number;\n}\n\n/** Props shared between the wrapper components and the provider */\nexport interface DataViewCoreProps<T> extends InteractionOptions {\n /** In-memory rows. Internally wrapped in a local `TableDataProvider` and\n * driven through the same loader as any other source. */\n data?: T[];\n /** Column definitions. Either a static array, or a function derived from the\n * loaded rows — invoked once the first rows arrive (and re-invoked when the\n * function's identity changes), so a data-shaped spec needs no separate fetch\n * of sample data. Omit entirely to auto-generate a plain spec via\n * `columnSpecOptions`. */\n columnSpec?: ColumnSpec[] | ((rows: T[]) => ColumnSpec[]);\n columnSpecOptions?: ColumnSpecOptions<T>;\n enableColumnReordering?: boolean;\n defaultColumnWidth?: number;\n // function to fetch a chunk of data (the read side of a data provider)\n fetchData?: FetchData<T>;\n /** A data provider instantiated separately and passed in — bundles the read\n * side (`fetchData` + `identity`) and, optionally, the persistence side\n * (`saveRows` / `deleteRows` / `insertRow`) that drives the Save action. An\n * explicit alternative to the loose `data` / `fetchData` / `identity` props;\n * takes precedence when given. */\n provider?: TableDataProvider<T>;\n /** Row identity for the edit overlay — stable across a provider re-sort (a\n * data provider supplies its own; defaults to `(row) => row?.id`). Lets edits\n * survive a re-ordered re-fetch. */\n identity?: (row: T) => string | number | null | undefined;\n /** Shown as the toolbar's leading label when nothing is selected. */\n name?: string;\n // itemLabel (e.g., \"row\", \"item\")\n itemLabel?: string;\n /** Bump to force a re-fetch from scratch (e.g. after an immediate edit that\n * mutated rows through the provider). */\n refreshToken?: number | string;\n /** Filters active from the start, applied when the store is *created* rather\n * than in an effect — so a restored view (from a link, a saved query, a\n * server render) never fires an unfiltered fetch first and immediately\n * supersedes it. Uncontrolled: the user's later changes win, and changing\n * this prop afterwards does nothing. */\n initialFilters?: ActiveFilterEntry[];\n /** Sorts active from the start. Same contract as `initialFilters`. */\n initialSorts?: ColumnSort[];\n}\n\n/** Links that make a paged view reachable without JavaScript. */\nexport interface PageLinks<T = any> {\n /** The href of the view that starts after `row` (`?after=<id>`). Rendered as\n * a visually hidden `rel=\"next\"` link after the loaded rows, so a crawler\n * following the server-rendered HTML reaches every page of the list while\n * readers keep the infinite scroll. */\n after: (row: T) => string;\n /** The href of the view's first page. Shown as a \"Return to top\" link at the\n * head of the content while the view starts mid-list (`startAfter`). */\n top?: string;\n /** Label for that link (default \"Return to top\"). */\n topLabel?: ReactNode;\n}\n\nexport interface DataViewSharedProps<T = any>\n extends FetchDataOptions<T>, DataViewCoreProps<T> {\n /** Crawlable page links (see `PageLinks`). Neither link is written to the\n * browser's URL as the list is scrolled — deep pages are for crawlers and\n * for whoever follows such a link, not a state the page keeps. */\n pageLinks?: PageLinks<T>;\n /** Configurable table actions shown in a selection-aware toolbar.\n * When provided, the actions toolbar renders alongside the existing\n * edit toolbar. Actions are filtered by the current selection cardinality. */\n actions?: TableAction<T>[];\n /** Available column/table filters shown in a filter bar.\n * Filters can also be defined per-column via `ColumnSpec.filters`. */\n filters?: TableFilter<T>[];\n //enableSelection?: boolean;\n}\n\nexport enum DataSheetDensity {\n HIGH = \"high\",\n MEDIUM = \"medium\",\n LOW = \"low\",\n}\n\n/**\n * How selecting a cell activates its surface (an editor, or a read-only detail\n * panel):\n * - `\"auto\"` (default when `autoFocusEditor` is `true`): open the surface on\n * selection and, for editors, focus it. Editors relinquish focus at their\n * edges — arrow past the start/end of a text cell, or press Escape, and focus\n * returns to the table — so the keyboard stays operable without the mouse.\n * Pressing Escape drops into navigation mode (surfaces stop auto-opening)\n * until the next click.\n * - `\"manual\"` (default when `autoFocusEditor` is `false`): the surface stays\n * closed until the cell is clicked; arrow keys always navigate the table.\n * - `\"second-click\"`: a click selects a cell and nothing more; a second click\n * on it (or Enter / F2) opens its surface. For a sheet whose selection\n * already feeds an editor of its own — a row editor beside the grid — so\n * selecting doesn't also open a popover over the cells.\n */\nexport type CellInteraction = \"auto\" | \"manual\" | \"second-click\";\n\nexport interface DataSheetRendererProps<T = any>\n extends TableProps, DataViewSharedProps<T> {\n onVisibleCellsChange?: (visibleCells: VisibleCells) => void;\n onUpdateData?: (updatedData: any[], data: T[]) => void;\n /** Observer called for every user edit as a structured `EditEvent`\n * (Workstream A). Additive: the built-in `updatedData` overlay still\n * applies. */\n onEdit?: (event: EditEvent<T>) => void;\n /** Controlled edited-cell overlay (Workstream A). When provided, it is\n * synced into the store as the source of truth for edited values — pair with\n * `onEdit` to own edit state externally (e.g. an ops model). Optimistic\n * in-table edits are superseded by the next value you pass back. */\n updatedData?: T[];\n /** Controlled row-status overlay (edited / added / deleted), the companion\n * to `updatedData`. */\n rowStatus?: TableElementStatus[];\n\n /** Derive the controlled edit overlay from the loaded rows, *inside* the\n * sheet. For provider-backed tables whose overlay is a function of the loaded\n * data plus external edit state (e.g. an ops stack): the library owns the\n * rows, so it calls this with them and uses the result as the controlled\n * overlay, re-deriving when the rows — or this function's identity (close it\n * over your edit state) — change. Supersedes `updatedData`/`rowStatus`. */\n deriveOverlay?: (rows: T[]) => {\n updatedData: T[];\n rowStatus: TableElementStatus[];\n };\n /** Persistence handler for the built-in Save action. When provided, a Save\n * control is added to the toolbar (always visible, disabled when there are\n * no pending changes). */\n onSave?: (ctx: TableActionContext<T>) => void | Promise<void>;\n onDeleteRows?: (selection: Region[]) => void;\n verbose?: boolean;\n enableColumnReordering?: boolean;\n enableClipboard?: boolean;\n enableFocusedCell?: boolean;\n /** @deprecated Prefer `cellInteraction`. `true` maps to `\"auto\"`,\n * `false` to `\"manual\"`. */\n autoFocusEditor?: boolean;\n /** How selecting a cell activates its surface (editor or detail panel).\n * Defaults from `autoFocusEditor` for backward compatibility. */\n cellInteraction?: CellInteraction;\n density?: DataSheetDensity;\n /** Optional custom column header cell renderer, called for each column.\n * Receives the ColumnSpec and column index; should return a React element\n * (typically a Blueprint ColumnHeaderCell). */\n columnHeaderCellRenderer?: (col: any, colIndex: number) => ReactNode;\n /** Arbitrary nodes for the bottom status bar (left group), rendered beside\n * the active sort/filter tags — the home for view-state controls (show/hide\n * omitted rows/columns, a group-by indicator, etc.). */\n statusBar?: ReactNode;\n /** Presentation per row-status value, merged over the built-in defaults\n * (which style `\"deleted\"`). Supply styles for consumer-defined statuses\n * (e.g. `\"omitted\"`) and/or override the defaults. Each entry may set the\n * cells' style/intent and the row header's style. */\n rowStatusStyles?: RowStatusStyles;\n /** Render the content of a row's header cell (the left gutter). Receives the\n * row, its status, and the default 1-based label; return a node to use, or a\n * nullish value to keep the default. For group-key labels, omit indicators,\n * etc. Header-cell *styling* still comes from `rowStatusStyles`. */\n rowHeaderRenderer?: (ctx: RowHeaderRenderContext<T>) => ReactNode;\n minRowHeight: number;\n defaultColumnWidth: number;\n debug: boolean;\n}\n\nexport type DataSheetProps<T> = DataViewCoreProps<T> &\n DataSheetRendererProps<T>;\n"],"names":["DataSheetDensity"],"mappings":";;AAgIO,IAAK,qCAAAA,sBAAL;AACLA,oBAAA,MAAA,IAAO;AACPA,oBAAA,QAAA,IAAS;AACTA,oBAAA,KAAA,IAAM;AAHI,SAAAA;AAAA,GAAA,oBAAA,CAAA,CAAA;;"}
|
package/dist/types.d.ts
CHANGED
|
@@ -116,8 +116,12 @@ export declare enum DataSheetDensity {
|
|
|
116
116
|
* until the next click.
|
|
117
117
|
* - `"manual"` (default when `autoFocusEditor` is `false`): the surface stays
|
|
118
118
|
* closed until the cell is clicked; arrow keys always navigate the table.
|
|
119
|
+
* - `"second-click"`: a click selects a cell and nothing more; a second click
|
|
120
|
+
* on it (or Enter / F2) opens its surface. For a sheet whose selection
|
|
121
|
+
* already feeds an editor of its own — a row editor beside the grid — so
|
|
122
|
+
* selecting doesn't also open a popover over the cells.
|
|
119
123
|
*/
|
|
120
|
-
export type CellInteraction = "auto" | "manual";
|
|
124
|
+
export type CellInteraction = "auto" | "manual" | "second-click";
|
|
121
125
|
export interface DataSheetRendererProps<T = any> extends TableProps, DataViewSharedProps<T> {
|
|
122
126
|
onVisibleCellsChange?: (visibleCells: VisibleCells) => void;
|
|
123
127
|
onUpdateData?: (updatedData: any[], data: T[]) => void;
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../src/types.ts"],"sourcesContent":["import {\n EditEvent,\n FetchData,\n InteractionOptions,\n RowHeaderRenderContext,\n RowStatusStyles,\n TableDataProvider,\n TableElementStatus,\n VisibleCells,\n} from \"./provider\";\nimport type { ColumnSort, ColumnSpec, ColumnSpecOptions } from \"./provider\";\nimport { ReactNode } from \"react\";\nimport {\n ActiveFilterEntry,\n TableAction,\n TableActionContext,\n TableFilter,\n} from \"./actions\";\nimport { Region, TableProps } from \"@blueprintjs/table\";\n\nexport type FetchMode = \"scroll\" | \"paged\";\n\nexport interface InitialDataChunk<T = any> {\n rows: T[];\n /** Total rows in the source, when the caller's fetch reported it. */\n totalCount?: number | null;\n}\n\nexport interface FetchDataOptions<T = any> {\n pageSize?: number;\n fetchMode?: FetchMode;\n /** Rows already in hand for the first window — typically fetched outside the\n * view (a server render, a parent that needed the data anyway) — so mounting\n * doesn't re-request a page the caller already has. The loader starts\n * populated and initialized; scrolling past the seed fetches as usual, and any\n * view change discards it and re-fetches (the seed only describes the view it\n * was fetched for, so pass matching `initialFilters` / `initialSorts`).\n *\n * Pass `totalCount` when it's known — the array is pre-sized to it, so the\n * scrollbar and the counter are right from the first paint. */\n initialData?: T[] | InitialDataChunk<T>;\n /** Identity of the row the view starts after — the keyset cursor of a view\n * that begins mid-list, as reached through a page link (`?after=<id>`). It is\n * passed to the provider as `after` on every chunk of the view it was created\n * for, and dropped on the first view change (sorts, filters, a refresh), since\n * it only describes that view. Read from the URL when the page loads; the\n * client never writes it back while scrolling. Pair it with an `initialData`\n * seed of the rows after it for a complete server render. */\n startAfter?: string | number | null;\n /** Debounce (ms) applied to view-state → refetch, so rapid changes (typing a\n * text filter) collapse into one fetch once the view settles. The input stays\n * instant; only the fetch waits. `0` (default) keeps immediate refetching. */\n filterDebounce?: number;\n}\n\n/** Props shared between the wrapper components and the provider */\nexport interface DataViewCoreProps<T> extends InteractionOptions {\n /** In-memory rows. Internally wrapped in a local `TableDataProvider` and\n * driven through the same loader as any other source. */\n data?: T[];\n /** Column definitions. Either a static array, or a function derived from the\n * loaded rows — invoked once the first rows arrive (and re-invoked when the\n * function's identity changes), so a data-shaped spec needs no separate fetch\n * of sample data. Omit entirely to auto-generate a plain spec via\n * `columnSpecOptions`. */\n columnSpec?: ColumnSpec[] | ((rows: T[]) => ColumnSpec[]);\n columnSpecOptions?: ColumnSpecOptions<T>;\n enableColumnReordering?: boolean;\n defaultColumnWidth?: number;\n // function to fetch a chunk of data (the read side of a data provider)\n fetchData?: FetchData<T>;\n /** A data provider instantiated separately and passed in — bundles the read\n * side (`fetchData` + `identity`) and, optionally, the persistence side\n * (`saveRows` / `deleteRows` / `insertRow`) that drives the Save action. An\n * explicit alternative to the loose `data` / `fetchData` / `identity` props;\n * takes precedence when given. */\n provider?: TableDataProvider<T>;\n /** Row identity for the edit overlay — stable across a provider re-sort (a\n * data provider supplies its own; defaults to `(row) => row?.id`). Lets edits\n * survive a re-ordered re-fetch. */\n identity?: (row: T) => string | number | null | undefined;\n /** Shown as the toolbar's leading label when nothing is selected. */\n name?: string;\n // itemLabel (e.g., \"row\", \"item\")\n itemLabel?: string;\n /** Bump to force a re-fetch from scratch (e.g. after an immediate edit that\n * mutated rows through the provider). */\n refreshToken?: number | string;\n /** Filters active from the start, applied when the store is *created* rather\n * than in an effect — so a restored view (from a link, a saved query, a\n * server render) never fires an unfiltered fetch first and immediately\n * supersedes it. Uncontrolled: the user's later changes win, and changing\n * this prop afterwards does nothing. */\n initialFilters?: ActiveFilterEntry[];\n /** Sorts active from the start. Same contract as `initialFilters`. */\n initialSorts?: ColumnSort[];\n}\n\n/** Links that make a paged view reachable without JavaScript. */\nexport interface PageLinks<T = any> {\n /** The href of the view that starts after `row` (`?after=<id>`). Rendered as\n * a visually hidden `rel=\"next\"` link after the loaded rows, so a crawler\n * following the server-rendered HTML reaches every page of the list while\n * readers keep the infinite scroll. */\n after: (row: T) => string;\n /** The href of the view's first page. Shown as a \"Return to top\" link at the\n * head of the content while the view starts mid-list (`startAfter`). */\n top?: string;\n /** Label for that link (default \"Return to top\"). */\n topLabel?: ReactNode;\n}\n\nexport interface DataViewSharedProps<T = any>\n extends FetchDataOptions<T>, DataViewCoreProps<T> {\n /** Crawlable page links (see `PageLinks`). Neither link is written to the\n * browser's URL as the list is scrolled — deep pages are for crawlers and\n * for whoever follows such a link, not a state the page keeps. */\n pageLinks?: PageLinks<T>;\n /** Configurable table actions shown in a selection-aware toolbar.\n * When provided, the actions toolbar renders alongside the existing\n * edit toolbar. Actions are filtered by the current selection cardinality. */\n actions?: TableAction<T>[];\n /** Available column/table filters shown in a filter bar.\n * Filters can also be defined per-column via `ColumnSpec.filters`. */\n filters?: TableFilter<T>[];\n //enableSelection?: boolean;\n}\n\nexport enum DataSheetDensity {\n HIGH = \"high\",\n MEDIUM = \"medium\",\n LOW = \"low\",\n}\n\n/**\n * How selecting a cell activates its surface (an editor, or a read-only detail\n * panel):\n * - `\"auto\"` (default when `autoFocusEditor` is `true`): open the surface on\n * selection and, for editors, focus it. Editors relinquish focus at their\n * edges — arrow past the start/end of a text cell, or press Escape, and focus\n * returns to the table — so the keyboard stays operable without the mouse.\n * Pressing Escape drops into navigation mode (surfaces stop auto-opening)\n * until the next click.\n * - `\"manual\"` (default when `autoFocusEditor` is `false`): the surface stays\n * closed until the cell is clicked; arrow keys always navigate the table.\n */\nexport type CellInteraction = \"auto\" | \"manual\";\n\nexport interface DataSheetRendererProps<T = any>\n extends TableProps, DataViewSharedProps<T> {\n onVisibleCellsChange?: (visibleCells: VisibleCells) => void;\n onUpdateData?: (updatedData: any[], data: T[]) => void;\n /** Observer called for every user edit as a structured `EditEvent`\n * (Workstream A). Additive: the built-in `updatedData` overlay still\n * applies. */\n onEdit?: (event: EditEvent<T>) => void;\n /** Controlled edited-cell overlay (Workstream A). When provided, it is\n * synced into the store as the source of truth for edited values — pair with\n * `onEdit` to own edit state externally (e.g. an ops model). Optimistic\n * in-table edits are superseded by the next value you pass back. */\n updatedData?: T[];\n /** Controlled row-status overlay (edited / added / deleted), the companion\n * to `updatedData`. */\n rowStatus?: TableElementStatus[];\n\n /** Derive the controlled edit overlay from the loaded rows, *inside* the\n * sheet. For provider-backed tables whose overlay is a function of the loaded\n * data plus external edit state (e.g. an ops stack): the library owns the\n * rows, so it calls this with them and uses the result as the controlled\n * overlay, re-deriving when the rows — or this function's identity (close it\n * over your edit state) — change. Supersedes `updatedData`/`rowStatus`. */\n deriveOverlay?: (rows: T[]) => {\n updatedData: T[];\n rowStatus: TableElementStatus[];\n };\n /** Persistence handler for the built-in Save action. When provided, a Save\n * control is added to the toolbar (always visible, disabled when there are\n * no pending changes). */\n onSave?: (ctx: TableActionContext<T>) => void | Promise<void>;\n onDeleteRows?: (selection: Region[]) => void;\n verbose?: boolean;\n enableColumnReordering?: boolean;\n enableClipboard?: boolean;\n enableFocusedCell?: boolean;\n /** @deprecated Prefer `cellInteraction`. `true` maps to `\"auto\"`,\n * `false` to `\"manual\"`. */\n autoFocusEditor?: boolean;\n /** How selecting a cell activates its surface (editor or detail panel).\n * Defaults from `autoFocusEditor` for backward compatibility. */\n cellInteraction?: CellInteraction;\n density?: DataSheetDensity;\n /** Optional custom column header cell renderer, called for each column.\n * Receives the ColumnSpec and column index; should return a React element\n * (typically a Blueprint ColumnHeaderCell). */\n columnHeaderCellRenderer?: (col: any, colIndex: number) => ReactNode;\n /** Arbitrary nodes for the bottom status bar (left group), rendered beside\n * the active sort/filter tags — the home for view-state controls (show/hide\n * omitted rows/columns, a group-by indicator, etc.). */\n statusBar?: ReactNode;\n /** Presentation per row-status value, merged over the built-in defaults\n * (which style `\"deleted\"`). Supply styles for consumer-defined statuses\n * (e.g. `\"omitted\"`) and/or override the defaults. Each entry may set the\n * cells' style/intent and the row header's style. */\n rowStatusStyles?: RowStatusStyles;\n /** Render the content of a row's header cell (the left gutter). Receives the\n * row, its status, and the default 1-based label; return a node to use, or a\n * nullish value to keep the default. For group-key labels, omit indicators,\n * etc. Header-cell *styling* still comes from `rowStatusStyles`. */\n rowHeaderRenderer?: (ctx: RowHeaderRenderContext<T>) => ReactNode;\n minRowHeight: number;\n defaultColumnWidth: number;\n debug: boolean;\n}\n\nexport type DataSheetProps<T> = DataViewCoreProps<T> &\n DataSheetRendererProps<T>;\n"],"names":["DataSheetDensity"],"mappings":"AAgIO,IAAK,qCAAAA,sBAAL;AACLA,oBAAA,MAAA,IAAO;AACPA,oBAAA,QAAA,IAAS;AACTA,oBAAA,KAAA,IAAM;AAHI,SAAAA;AAAA,GAAA,oBAAA,CAAA,CAAA;"}
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../src/types.ts"],"sourcesContent":["import {\n EditEvent,\n FetchData,\n InteractionOptions,\n RowHeaderRenderContext,\n RowStatusStyles,\n TableDataProvider,\n TableElementStatus,\n VisibleCells,\n} from \"./provider\";\nimport type { ColumnSort, ColumnSpec, ColumnSpecOptions } from \"./provider\";\nimport { ReactNode } from \"react\";\nimport {\n ActiveFilterEntry,\n TableAction,\n TableActionContext,\n TableFilter,\n} from \"./actions\";\nimport { Region, TableProps } from \"@blueprintjs/table\";\n\nexport type FetchMode = \"scroll\" | \"paged\";\n\nexport interface InitialDataChunk<T = any> {\n rows: T[];\n /** Total rows in the source, when the caller's fetch reported it. */\n totalCount?: number | null;\n}\n\nexport interface FetchDataOptions<T = any> {\n pageSize?: number;\n fetchMode?: FetchMode;\n /** Rows already in hand for the first window — typically fetched outside the\n * view (a server render, a parent that needed the data anyway) — so mounting\n * doesn't re-request a page the caller already has. The loader starts\n * populated and initialized; scrolling past the seed fetches as usual, and any\n * view change discards it and re-fetches (the seed only describes the view it\n * was fetched for, so pass matching `initialFilters` / `initialSorts`).\n *\n * Pass `totalCount` when it's known — the array is pre-sized to it, so the\n * scrollbar and the counter are right from the first paint. */\n initialData?: T[] | InitialDataChunk<T>;\n /** Identity of the row the view starts after — the keyset cursor of a view\n * that begins mid-list, as reached through a page link (`?after=<id>`). It is\n * passed to the provider as `after` on every chunk of the view it was created\n * for, and dropped on the first view change (sorts, filters, a refresh), since\n * it only describes that view. Read from the URL when the page loads; the\n * client never writes it back while scrolling. Pair it with an `initialData`\n * seed of the rows after it for a complete server render. */\n startAfter?: string | number | null;\n /** Debounce (ms) applied to view-state → refetch, so rapid changes (typing a\n * text filter) collapse into one fetch once the view settles. The input stays\n * instant; only the fetch waits. `0` (default) keeps immediate refetching. */\n filterDebounce?: number;\n}\n\n/** Props shared between the wrapper components and the provider */\nexport interface DataViewCoreProps<T> extends InteractionOptions {\n /** In-memory rows. Internally wrapped in a local `TableDataProvider` and\n * driven through the same loader as any other source. */\n data?: T[];\n /** Column definitions. Either a static array, or a function derived from the\n * loaded rows — invoked once the first rows arrive (and re-invoked when the\n * function's identity changes), so a data-shaped spec needs no separate fetch\n * of sample data. Omit entirely to auto-generate a plain spec via\n * `columnSpecOptions`. */\n columnSpec?: ColumnSpec[] | ((rows: T[]) => ColumnSpec[]);\n columnSpecOptions?: ColumnSpecOptions<T>;\n enableColumnReordering?: boolean;\n defaultColumnWidth?: number;\n // function to fetch a chunk of data (the read side of a data provider)\n fetchData?: FetchData<T>;\n /** A data provider instantiated separately and passed in — bundles the read\n * side (`fetchData` + `identity`) and, optionally, the persistence side\n * (`saveRows` / `deleteRows` / `insertRow`) that drives the Save action. An\n * explicit alternative to the loose `data` / `fetchData` / `identity` props;\n * takes precedence when given. */\n provider?: TableDataProvider<T>;\n /** Row identity for the edit overlay — stable across a provider re-sort (a\n * data provider supplies its own; defaults to `(row) => row?.id`). Lets edits\n * survive a re-ordered re-fetch. */\n identity?: (row: T) => string | number | null | undefined;\n /** Shown as the toolbar's leading label when nothing is selected. */\n name?: string;\n // itemLabel (e.g., \"row\", \"item\")\n itemLabel?: string;\n /** Bump to force a re-fetch from scratch (e.g. after an immediate edit that\n * mutated rows through the provider). */\n refreshToken?: number | string;\n /** Filters active from the start, applied when the store is *created* rather\n * than in an effect — so a restored view (from a link, a saved query, a\n * server render) never fires an unfiltered fetch first and immediately\n * supersedes it. Uncontrolled: the user's later changes win, and changing\n * this prop afterwards does nothing. */\n initialFilters?: ActiveFilterEntry[];\n /** Sorts active from the start. Same contract as `initialFilters`. */\n initialSorts?: ColumnSort[];\n}\n\n/** Links that make a paged view reachable without JavaScript. */\nexport interface PageLinks<T = any> {\n /** The href of the view that starts after `row` (`?after=<id>`). Rendered as\n * a visually hidden `rel=\"next\"` link after the loaded rows, so a crawler\n * following the server-rendered HTML reaches every page of the list while\n * readers keep the infinite scroll. */\n after: (row: T) => string;\n /** The href of the view's first page. Shown as a \"Return to top\" link at the\n * head of the content while the view starts mid-list (`startAfter`). */\n top?: string;\n /** Label for that link (default \"Return to top\"). */\n topLabel?: ReactNode;\n}\n\nexport interface DataViewSharedProps<T = any>\n extends FetchDataOptions<T>, DataViewCoreProps<T> {\n /** Crawlable page links (see `PageLinks`). Neither link is written to the\n * browser's URL as the list is scrolled — deep pages are for crawlers and\n * for whoever follows such a link, not a state the page keeps. */\n pageLinks?: PageLinks<T>;\n /** Configurable table actions shown in a selection-aware toolbar.\n * When provided, the actions toolbar renders alongside the existing\n * edit toolbar. Actions are filtered by the current selection cardinality. */\n actions?: TableAction<T>[];\n /** Available column/table filters shown in a filter bar.\n * Filters can also be defined per-column via `ColumnSpec.filters`. */\n filters?: TableFilter<T>[];\n //enableSelection?: boolean;\n}\n\nexport enum DataSheetDensity {\n HIGH = \"high\",\n MEDIUM = \"medium\",\n LOW = \"low\",\n}\n\n/**\n * How selecting a cell activates its surface (an editor, or a read-only detail\n * panel):\n * - `\"auto\"` (default when `autoFocusEditor` is `true`): open the surface on\n * selection and, for editors, focus it. Editors relinquish focus at their\n * edges — arrow past the start/end of a text cell, or press Escape, and focus\n * returns to the table — so the keyboard stays operable without the mouse.\n * Pressing Escape drops into navigation mode (surfaces stop auto-opening)\n * until the next click.\n * - `\"manual\"` (default when `autoFocusEditor` is `false`): the surface stays\n * closed until the cell is clicked; arrow keys always navigate the table.\n * - `\"second-click\"`: a click selects a cell and nothing more; a second click\n * on it (or Enter / F2) opens its surface. For a sheet whose selection\n * already feeds an editor of its own — a row editor beside the grid — so\n * selecting doesn't also open a popover over the cells.\n */\nexport type CellInteraction = \"auto\" | \"manual\" | \"second-click\";\n\nexport interface DataSheetRendererProps<T = any>\n extends TableProps, DataViewSharedProps<T> {\n onVisibleCellsChange?: (visibleCells: VisibleCells) => void;\n onUpdateData?: (updatedData: any[], data: T[]) => void;\n /** Observer called for every user edit as a structured `EditEvent`\n * (Workstream A). Additive: the built-in `updatedData` overlay still\n * applies. */\n onEdit?: (event: EditEvent<T>) => void;\n /** Controlled edited-cell overlay (Workstream A). When provided, it is\n * synced into the store as the source of truth for edited values — pair with\n * `onEdit` to own edit state externally (e.g. an ops model). Optimistic\n * in-table edits are superseded by the next value you pass back. */\n updatedData?: T[];\n /** Controlled row-status overlay (edited / added / deleted), the companion\n * to `updatedData`. */\n rowStatus?: TableElementStatus[];\n\n /** Derive the controlled edit overlay from the loaded rows, *inside* the\n * sheet. For provider-backed tables whose overlay is a function of the loaded\n * data plus external edit state (e.g. an ops stack): the library owns the\n * rows, so it calls this with them and uses the result as the controlled\n * overlay, re-deriving when the rows — or this function's identity (close it\n * over your edit state) — change. Supersedes `updatedData`/`rowStatus`. */\n deriveOverlay?: (rows: T[]) => {\n updatedData: T[];\n rowStatus: TableElementStatus[];\n };\n /** Persistence handler for the built-in Save action. When provided, a Save\n * control is added to the toolbar (always visible, disabled when there are\n * no pending changes). */\n onSave?: (ctx: TableActionContext<T>) => void | Promise<void>;\n onDeleteRows?: (selection: Region[]) => void;\n verbose?: boolean;\n enableColumnReordering?: boolean;\n enableClipboard?: boolean;\n enableFocusedCell?: boolean;\n /** @deprecated Prefer `cellInteraction`. `true` maps to `\"auto\"`,\n * `false` to `\"manual\"`. */\n autoFocusEditor?: boolean;\n /** How selecting a cell activates its surface (editor or detail panel).\n * Defaults from `autoFocusEditor` for backward compatibility. */\n cellInteraction?: CellInteraction;\n density?: DataSheetDensity;\n /** Optional custom column header cell renderer, called for each column.\n * Receives the ColumnSpec and column index; should return a React element\n * (typically a Blueprint ColumnHeaderCell). */\n columnHeaderCellRenderer?: (col: any, colIndex: number) => ReactNode;\n /** Arbitrary nodes for the bottom status bar (left group), rendered beside\n * the active sort/filter tags — the home for view-state controls (show/hide\n * omitted rows/columns, a group-by indicator, etc.). */\n statusBar?: ReactNode;\n /** Presentation per row-status value, merged over the built-in defaults\n * (which style `\"deleted\"`). Supply styles for consumer-defined statuses\n * (e.g. `\"omitted\"`) and/or override the defaults. Each entry may set the\n * cells' style/intent and the row header's style. */\n rowStatusStyles?: RowStatusStyles;\n /** Render the content of a row's header cell (the left gutter). Receives the\n * row, its status, and the default 1-based label; return a node to use, or a\n * nullish value to keep the default. For group-key labels, omit indicators,\n * etc. Header-cell *styling* still comes from `rowStatusStyles`. */\n rowHeaderRenderer?: (ctx: RowHeaderRenderContext<T>) => ReactNode;\n minRowHeight: number;\n defaultColumnWidth: number;\n debug: boolean;\n}\n\nexport type DataSheetProps<T> = DataViewCoreProps<T> &\n DataSheetRendererProps<T>;\n"],"names":["DataSheetDensity"],"mappings":"AAgIO,IAAK,qCAAAA,sBAAL;AACLA,oBAAA,MAAA,IAAO;AACPA,oBAAA,QAAA,IAAS;AACTA,oBAAA,KAAA,IAAM;AAHI,SAAAA;AAAA,GAAA,oBAAA,CAAA,CAAA;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@macrostrat/data-sheet",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.9.0",
|
|
4
4
|
"description": "Scalable data sheet with optional editing capabilities",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"@blueprintjs/core": "^6.14.0",
|
|
50
50
|
"@blueprintjs/table": "^6.1.0",
|
|
51
51
|
"@macrostrat/color-utils": "^1.2.2",
|
|
52
|
-
"@macrostrat/data-components": "^1.
|
|
52
|
+
"@macrostrat/data-components": "^1.7.0",
|
|
53
53
|
"@macrostrat/hyper": "^3.1.1",
|
|
54
54
|
"@macrostrat/scoped-store": "^1.1.0",
|
|
55
55
|
"@macrostrat/ui-components": "^5.2.0",
|
package/src/actions/context.ts
CHANGED
|
@@ -16,7 +16,8 @@ import {
|
|
|
16
16
|
} from "./selection.ts";
|
|
17
17
|
import { Getter, Setter } from "jotai";
|
|
18
18
|
import type { Store as JotaiStore } from "jotai/vanilla/store";
|
|
19
|
-
import { storeAPIAtom } from "../provider";
|
|
19
|
+
import { storeAPIAtom, TableElementStatus } from "../provider";
|
|
20
|
+
import { isColumnWritable } from "../provider/column-spec.ts";
|
|
20
21
|
import type { ColumnSpec } from "../provider";
|
|
21
22
|
import type { TableAction } from "./types.ts";
|
|
22
23
|
|
|
@@ -208,7 +209,17 @@ export function buildActionContext<T>(
|
|
|
208
209
|
getSelectedColumnKeys: () =>
|
|
209
210
|
getSelectedColumnKeys(state.selection, state.columnSpec),
|
|
210
211
|
onCellEdited: state.onCellEdited,
|
|
211
|
-
editCells(
|
|
212
|
+
editCells(rawEdits: CellEdit[]) {
|
|
213
|
+
// Only the cells that take writes: a paste or a fill that spans a locked
|
|
214
|
+
// or derived column, or a deleted row, writes around them — the same
|
|
215
|
+
// rule the inline editor applies (`isColumnWritable`).
|
|
216
|
+
const edits = rawEdits.filter((e) => {
|
|
217
|
+
const columnKey = (e as any).columnKey ?? e.column;
|
|
218
|
+
const col = state.columnSpec.find((c) => c.key === columnKey);
|
|
219
|
+
if (!isColumnWritable(col, state.editable)) return false;
|
|
220
|
+
return state.rowStatus?.[e.rowIndex] !== TableElementStatus.DELETED;
|
|
221
|
+
});
|
|
222
|
+
if (edits.length === 0) return;
|
|
212
223
|
state.setUpdatedData((updatedData: T[]) => {
|
|
213
224
|
const spec: Record<number, any> = {};
|
|
214
225
|
for (const e of edits) {
|
package/src/actions/types.ts
CHANGED
|
@@ -98,6 +98,11 @@ export interface TableAction<T = any, S = null> {
|
|
|
98
98
|
* target), so they appear only for a single column. */
|
|
99
99
|
appliesTo?: (context: TableActionContext<T>) => boolean;
|
|
100
100
|
|
|
101
|
+
/** Where the action sits in the toolbar: with the contextual actions at its
|
|
102
|
+
* start (default), or at its fixed end beside Save and Reset — for a
|
|
103
|
+
* control that doesn't change with the selection, like a panel toggle. */
|
|
104
|
+
placement?: "start" | "end";
|
|
105
|
+
|
|
101
106
|
/** Whether this action requires the table to be in edit mode.
|
|
102
107
|
* Defaults to `true`. Set to `false` for read-only actions
|
|
103
108
|
* (e.g., "open URL", "copy to clipboard"). */
|