@macrostrat/data-sheet 4.0.1 → 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.
- package/CHANGELOG.md +25 -0
- package/README.md +11 -1
- package/dist/actions/column-controls.cjs +102 -1
- package/dist/actions/column-controls.cjs.map +1 -1
- package/dist/actions/column-controls.js +104 -3
- package/dist/actions/column-controls.js.map +1 -1
- package/dist/actions/column-filter.cjs +48 -25
- package/dist/actions/column-filter.cjs.map +1 -1
- package/dist/actions/column-filter.js +50 -27
- package/dist/actions/column-filter.js.map +1 -1
- package/dist/actions/selection.cjs +2 -1
- package/dist/actions/selection.cjs.map +1 -1
- package/dist/actions/selection.js +2 -1
- package/dist/actions/selection.js.map +1 -1
- package/dist/actions/table-controls.cjs +21 -0
- package/dist/actions/table-controls.cjs.map +1 -1
- package/dist/actions/table-controls.d.ts +4 -0
- package/dist/actions/table-controls.js +21 -0
- package/dist/actions/table-controls.js.map +1 -1
- package/dist/actions/toolbar.cjs +34 -4
- package/dist/actions/toolbar.cjs.map +1 -1
- package/dist/actions/toolbar.js +35 -5
- package/dist/actions/toolbar.js.map +1 -1
- package/dist/actions/types.d.ts +9 -0
- package/dist/cell-renderer.cjs +9 -7
- package/dist/cell-renderer.cjs.map +1 -1
- package/dist/cell-renderer.js +9 -7
- package/dist/cell-renderer.js.map +1 -1
- package/dist/core.cjs +68 -9
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +32 -1
- package/dist/core.js +69 -10
- package/dist/core.js.map +1 -1
- package/dist/filters/operators.cjs +2 -2
- package/dist/filters/operators.cjs.map +1 -1
- package/dist/filters/operators.d.ts +1 -1
- package/dist/filters/operators.js +2 -2
- package/dist/filters/operators.js.map +1 -1
- package/dist/index.cjs +4 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -2
- package/dist/postgrest-table/data-loaders.cjs +1 -8
- package/dist/postgrest-table/data-loaders.cjs.map +1 -1
- package/dist/postgrest-table/data-loaders.js +1 -8
- package/dist/postgrest-table/data-loaders.js.map +1 -1
- package/dist/provider.cjs +9 -3
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.d.ts +2 -1
- package/dist/provider.js +9 -3
- package/dist/provider.js.map +1 -1
- package/dist/renderers/column-header-cell.cjs +33 -32
- package/dist/renderers/column-header-cell.cjs.map +1 -1
- package/dist/renderers/column-header-cell.d.ts +1 -2
- package/dist/renderers/column-header-cell.js +34 -33
- package/dist/renderers/column-header-cell.js.map +1 -1
- package/dist/types.cjs +11 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +55 -2
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -1
- package/dist/utils/column-spec.cjs.map +1 -1
- package/dist/utils/column-spec.d.ts +8 -0
- package/dist/utils/column-spec.js.map +1 -1
- package/dist/zustand-store.cjs +7 -3
- package/dist/zustand-store.cjs.map +1 -1
- package/dist/zustand-store.js +8 -4
- package/dist/zustand-store.js.map +1 -1
- package/package.json +1 -1
- package/src/actions/column-controls.ts +133 -2
- package/src/actions/column-filter.ts +59 -30
- package/src/actions/selection.ts +1 -0
- package/src/actions/table-controls.ts +24 -0
- package/src/actions/toolbar.ts +61 -5
- package/src/actions/types.ts +10 -0
- package/src/cell-renderer.ts +23 -10
- package/src/core.ts +131 -13
- package/src/filters/operators.ts +5 -3
- package/src/postgrest-table/data-loaders.ts +6 -10
- package/src/provider.ts +22 -5
- package/src/renderers/column-header-cell.ts +51 -36
- package/src/types.ts +66 -2
- package/src/utils/column-spec.ts +8 -0
- package/src/zustand-store.ts +12 -5
package/dist/actions/toolbar.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ButtonGroup, Button, PopoverNext } from "@blueprintjs/core";
|
|
1
|
+
import { Tag, ButtonGroup, Button, PopoverNext } from "@blueprintjs/core";
|
|
2
2
|
import { useMemo, useCallback, useState } from "react";
|
|
3
3
|
import h from "./toolbar.module.sass.js";
|
|
4
4
|
import { useSelector, useStoreAPI } from "../provider.js";
|
|
@@ -59,13 +59,43 @@ function ActionsToolbar({
|
|
|
59
59
|
if (!toolbarIsShown) {
|
|
60
60
|
return null;
|
|
61
61
|
}
|
|
62
|
-
const
|
|
62
|
+
const hasSelection = selection != null && selection.length > 0;
|
|
63
|
+
const titleNode = h(
|
|
64
|
+
Tag,
|
|
65
|
+
{
|
|
66
|
+
key: "title",
|
|
67
|
+
minimal: true,
|
|
68
|
+
large: true,
|
|
69
|
+
onRemove: hasSelection ? () => storeAPI.setState({
|
|
70
|
+
selection: [],
|
|
71
|
+
focusedCell: null,
|
|
72
|
+
topLeftCell: null
|
|
73
|
+
}) : void 0,
|
|
74
|
+
style: hasSelection ? void 0 : { background: "transparent" }
|
|
75
|
+
},
|
|
76
|
+
hasSelection ? selectionTitle(ctx) ?? tableName ?? "Selection" : tableName ?? "Table"
|
|
77
|
+
);
|
|
78
|
+
const isGlobal = (a) => a.targets.includes(RegionCardinality.FULL_TABLE) || a.targets.includes("none");
|
|
79
|
+
const contextual = shownActions.filter((a) => !isGlobal(a));
|
|
80
|
+
const globalOrder = {
|
|
81
|
+
"reset-changes": 1,
|
|
82
|
+
"save-changes": 2
|
|
83
|
+
};
|
|
84
|
+
const globalActions = shownActions.filter(isGlobal).sort((a, b) => (globalOrder[a.id] ?? 0) - (globalOrder[b.id] ?? 0));
|
|
63
85
|
return h("div.actions-toolbar", [
|
|
64
|
-
|
|
86
|
+
titleNode,
|
|
87
|
+
h(
|
|
88
|
+
ButtonGroup,
|
|
89
|
+
{ key: "contextual", minimal: true },
|
|
90
|
+
contextual.map(
|
|
91
|
+
(action) => h(ActionButton, { key: action.id, action, ctx })
|
|
92
|
+
)
|
|
93
|
+
),
|
|
94
|
+
h("div.toolbar-spacer", { key: "spacer", style: { flex: 1 } }),
|
|
65
95
|
h(
|
|
66
96
|
ButtonGroup,
|
|
67
|
-
{ key: "
|
|
68
|
-
|
|
97
|
+
{ key: "global", minimal: true },
|
|
98
|
+
globalActions.map(
|
|
69
99
|
(action) => h(ActionButton, { key: action.id, action, ctx })
|
|
70
100
|
)
|
|
71
101
|
)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toolbar.js","sources":["../../src/actions/toolbar.ts"],"sourcesContent":["import { Button, ButtonGroup, PopoverNext } from \"@blueprintjs/core\";\nimport { useCallback, useMemo, useState } from \"react\";\nimport h from \"./toolbar.module.sass\";\nimport { useSelector, useStoreAPI } from \"../provider\";\nimport {\n buildActionContext,\n getApplicableActions,\n getSelectionCardinality,\n mergeColumnActions,\n} from \"./selection\";\nimport type { TableAction, TableActionContext } from \"./types\";\nimport { RegionCardinality } from \"@blueprintjs/table\";\nimport { useToaster } from \"../notifications.ts\";\nimport { DataSheetStore } from \"../types.ts\";\nimport { ColumnSpec } from \"../utils\";\n\n/** A short title describing the current selection (its shape), shown as the\n * toolbar's leading label — no icon. */\nfunction selectionTitle<T>(ctx: TableActionContext<T>): string | null {\n const sh = ctx.selectionShape;\n switch (sh.cardinality) {\n case RegionCardinality.FULL_COLUMNS: {\n if (ctx.columnKey != null) {\n const col = ctx.columnSpec.find((c) => c.key === ctx.columnKey);\n return col?.name ?? \"Column\";\n }\n return `${sh.columns} columns`;\n }\n case RegionCardinality.FULL_ROWS:\n return ctx.rowIndex != null ? \"1 row\" : `${sh.rows} rows`;\n case RegionCardinality.CELLS:\n return ctx.cell != null ? \"Cell\" : `${sh.columns}×${sh.rows} cells`;\n case RegionCardinality.FULL_TABLE:\n return null;\n default:\n return null;\n }\n}\n\n/** Toolbar that renders the actions/controls applicable to the current\n * selection cardinality (modal by selection) and edit mode. Actions with a\n * `render` show their live control; others show a button (with an optional\n * `detailsForm` popover). Column-specific actions from `ColumnSpec.actions`\n * are merged when their columns are selected. A capsule on the left shows the\n * current selection polarity. */\nexport function ActionsToolbar<T>({\n actions,\n tableName,\n}: {\n actions: TableAction<T>[];\n tableName?: string;\n}) {\n const selection = useSelector((state) => state.selection);\n const editable = useSelector((state) => state.editable);\n const columnSpec = useSelector((state) => state.columnSpec);\n const storeAPI = useStoreAPI();\n\n const cardinality = useMemo(\n () => getSelectionCardinality(selection) ?? RegionCardinality.FULL_TABLE,\n [selection],\n );\n\n // Merge global actions with column-specific actions from the selection\n const allActions = useMemo(\n () => mergeColumnActions(actions, columnSpec, selection),\n [actions, columnSpec, selection],\n );\n\n const applicableActions = useMemo(\n () => getApplicableActions(allActions, cardinality, editable),\n [allActions, cardinality, editable],\n );\n\n // Context for `render`-style controls (they subscribe to the store\n // themselves; this resolves the selected column/rows).\n const ctx = buildActionContext(\n storeAPI.getState(),\n storeAPI.setState,\n ) as TableActionContext<T>;\n\n // The toolbar is for actions that AREN'T keyboard-accessible: any action\n // with a `hotkey` (copy/cut/paste, etc.) is reachable from the keyboard and\n // is omitted here (it still works via its shortcut). Then refine by selection\n // shape beyond cardinality (e.g. single column only).\n const shownActions = applicableActions.filter(\n (action) => action.hotkey == null && (action.appliesTo?.(ctx) ?? true),\n );\n\n const toolbarIsShown = useMemo(\n () => hasAnyDisplayableActions(actions, columnSpec),\n [actions, columnSpec],\n );\n\n if (!toolbarIsShown) {\n return null;\n }\n\n // The toolbar is always mounted if actions are available, so it can't flicker\n // in/out as the selection or action set changes — the container is stable;\n // only its contents (title + buttons) change. Avoids layout jank.\n const title = selectionTitle(ctx) ?? tableName ?? \"Table\";\n\n return h(\"div.actions-toolbar\", [\n h(\"span.toolbar-title\", { key: \"title\" }, title),\n h(\n ButtonGroup,\n { key: \"actions\", minimal: true },\n shownActions.map((action) =>\n h(ActionButton, { key: action.id, action, ctx }),\n ),\n ),\n ]);\n}\n\nfunction getMessageForError(e: any) {\n if (e instanceof Error) return e.message;\n if (typeof e === \"string\") return e;\n if (e instanceof Object) return JSON.stringify(e);\n return null;\n}\n\nfunction isActionDisabled(action: TableAction, state: any): boolean {\n if (typeof action.disabled === \"boolean\") return action.disabled;\n if (typeof action.disabled === \"function\") {\n return action.disabled(state);\n }\n return false;\n}\n\nexport function runActionWrapper<T>(\n action: TableAction<T>,\n state: DataSheetStore<any>,\n setState: (state: Partial<DataSheetStore<any>>) => void,\n toaster: any,\n configState: any = undefined,\n) {\n const ctx = buildActionContext(state, setState) as TableActionContext<T>;\n if (action.disabled instanceof Function) {\n if (action.disabled(ctx)) {\n return;\n }\n } else if (action.disabled) {\n return;\n }\n try {\n const res = action.run?.(ctx, configState);\n if (res instanceof Promise) {\n res\n .then(() => {})\n .catch((e) => {\n displayErrorForAction(action, e, toaster);\n });\n }\n } catch (e) {\n displayErrorForAction(action, e, toaster);\n }\n}\n\n/** Dispatcher: a live control (`action.render`) or a run/detailsForm button.\n * Kept hook-free so the two paths don't share a hook order. */\nfunction ActionButton<T>({\n action,\n ctx,\n}: {\n action: TableAction<T>;\n ctx: TableActionContext<T>;\n}) {\n if (action.render != null) {\n return action.render(ctx) as any;\n }\n return h(RunActionButton, { action });\n}\n\n/** A run/detailsForm action rendered as a button. */\nfunction RunActionButton<T>({ action }: { action: TableAction<T> }) {\n const storeAPI = useStoreAPI();\n const toaster = useToaster();\n\n // Reactive disabled check — re-renders when relevant state changes\n const isDisabled = useSelector((state) => {\n return isActionDisabled(action, state);\n });\n\n const runAction = useCallback(\n (configState?: any) => {\n runActionWrapper(\n action,\n storeAPI.getState(),\n storeAPI.setState,\n toaster,\n configState,\n );\n },\n [storeAPI, action, toaster],\n );\n\n if (action.detailsForm != null) {\n return h(ActionButtonWithForm, { action, runAction, isDisabled });\n }\n\n return h(\n Button,\n {\n icon: action.icon,\n intent: action.intent,\n disabled: isDisabled,\n onClick() {\n runAction();\n },\n },\n action.name,\n );\n}\n\nfunction displayErrorForAction(action: TableAction, error: any, toaster: any) {\n const message =\n getMessageForError(error) ?? action.errorMessage ?? \"Action failed\";\n toaster.show({\n message,\n intent: \"danger\",\n });\n}\n\n/** Action button that opens a popover for pre-run configuration. */\nfunction ActionButtonWithForm<T, S>({\n action,\n runAction,\n isDisabled,\n}: {\n action: TableAction<T, S>;\n runAction: (configState?: S) => void;\n isDisabled: boolean;\n}) {\n const [configState, setConfigState] = useState<S>(\n action.defaultState ?? (null as S),\n );\n const [isOpen, setIsOpen] = useState(false);\n\n let ready = true;\n if (action.isReady != null) {\n ready = action.isReady(configState);\n }\n\n return h(\n PopoverNext,\n {\n isOpen,\n onClose: () => setIsOpen(false),\n content: h(\"div.action-popover-content\", [\n h.if(action.description != null)(\"p.description\", action.description),\n h(action.detailsForm, {\n state: configState,\n setState: setConfigState,\n }),\n h(\n Button,\n {\n className: \"run-button\",\n intent: action.intent ?? \"primary\",\n icon: \"play\",\n disabled: !ready,\n fill: true,\n onClick() {\n runAction(configState);\n setIsOpen(false);\n },\n },\n \"Run\",\n ),\n ]),\n placement: \"bottom-start\",\n enforceFocus: false,\n autoFocus: false,\n },\n h(\n Button,\n {\n icon: action.icon,\n intent: action.intent,\n disabled: isDisabled,\n onClick: () => setIsOpen(!isOpen),\n },\n action.name,\n ),\n );\n}\n\nfunction hasAnyDisplayableActions(\n actions: TableAction[],\n columnSpec: ColumnSpec[],\n) {\n /** Check whether there are any actions that can be displayed in the toolbar.\n * for the entire table. This is used to determine whether the toolbar should\n * be rendered. If any actions are available, the toolbar is rendered in ALL\n * selection modes to avoid flickering\n */\n const allActions = [\n ...actions,\n ...columnSpec.flatMap((c) => c.actions ?? []),\n ];\n\n if (allActions.length === 0) {\n return false;\n }\n // Check whether any action doesn't have hotkey and is not disabled\n return allActions.some(\n (action) => action.hotkey == null && !isActionDisabled(action, {}),\n );\n}\n"],"names":[],"mappings":";;;;;;;AAkBA,SAAS,eAAkB,KAA2C;AACpE,QAAM,KAAK,IAAI;AACf,UAAQ,GAAG,aAAA;AAAA,IACT,KAAK,kBAAkB,cAAc;AACnC,UAAI,IAAI,aAAa,MAAM;AACzB,cAAM,MAAM,IAAI,WAAW,KAAK,CAAC,MAAM,EAAE,QAAQ,IAAI,SAAS;AAC9D,eAAO,KAAK,QAAQ;AAAA,MACtB;AACA,aAAO,GAAG,GAAG,OAAO;AAAA,IACtB;AAAA,IACA,KA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,EAAE,GAAG,OAAO,eAAe,IAAI,EAAE,iBAAiB,OAAO,WAAW;AAAA,QACpE,EAAE,OAAO,aAAa;AAAA,UACpB,OAAO;AAAA,UACP,UAAU;AAAA,QAAA,CACX;AAAA,QACD;AAAA,UACE;AAAA,UACA;AAAA,YACE,WAAW;AAAA,YACX,QAAQ,OAAO,UAAU;AAAA,YACzB,MAAM;AAAA,YACN,UAAU,CAAC;AAAA,YACX,MAAM;AAAA,YACN,UAAU;AACR,wBAAU,WAAW;AACrB,wBAAU,KAAK;AAAA,YACjB;AAAA,UAAA;AAAA,UAEF;AAAA,QAAA;AAAA,MACF,CACD;AAAA,MACD,WAAW;AAAA,MACX,cAAc;AAAA,MACd,WAAW;AAAA,IAAA;AAAA,IAEb;AAAA,MACE;AAAA,MACA;AAAA,QACE,MAAM,OAAO;AAAA,QACb,QAAQ,OAAO;AAAA,QACf,UAAU;AAAA,QACV,SAAS,MAAM,UAAU,CAAC,MAAM;AAAA,MAAA;AAAA,MAElC,OAAO;AAAA,IAAA;AAAA,EACT;AAEJ;AAEA,SAAS,yBACP,SACA,YACA;AAMA,QAAM,aAAa;AAAA,IACjB,GAAG;AAAA,IACH,GAAG,WAAW,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA,CAAE;AAAA,EAAA;AAG9C,MAAI,WAAW,WAAW,GAAG;AAC3B,WAAO;AAAA,EACT;AAEA,SAAO,WAAW;AAAA,IAChB,CAAC,WAAW,OAAO,UAAU,QAAQ,CAAC,iBAAiB,QAAQ,CAAA,CAAE;AAAA,EAAA;AAErE;"}
|
|
1
|
+
{"version":3,"file":"toolbar.js","sources":["../../src/actions/toolbar.ts"],"sourcesContent":["import { Button, ButtonGroup, PopoverNext, Tag } from \"@blueprintjs/core\";\nimport { useCallback, useMemo, useState } from \"react\";\nimport h from \"./toolbar.module.sass\";\nimport { useSelector, useStoreAPI } from \"../provider\";\nimport {\n buildActionContext,\n getApplicableActions,\n getSelectionCardinality,\n mergeColumnActions,\n} from \"./selection\";\nimport type { TableAction, TableActionContext } from \"./types\";\nimport { RegionCardinality } from \"@blueprintjs/table\";\nimport { useToaster } from \"../notifications.ts\";\nimport { DataSheetStore } from \"../types.ts\";\nimport { ColumnSpec } from \"../utils\";\n\n/** A short title describing the current selection (its shape), shown as the\n * toolbar's leading label — no icon. */\nfunction selectionTitle<T>(ctx: TableActionContext<T>): string | null {\n const sh = ctx.selectionShape;\n switch (sh.cardinality) {\n case RegionCardinality.FULL_COLUMNS: {\n if (ctx.columnKey != null) {\n const col = ctx.columnSpec.find((c) => c.key === ctx.columnKey);\n return col?.name ?? \"Column\";\n }\n return `${sh.columns} columns`;\n }\n case RegionCardinality.FULL_ROWS:\n return ctx.rowIndex != null ? \"1 row\" : `${sh.rows} rows`;\n case RegionCardinality.CELLS:\n return ctx.cell != null ? \"Cell\" : `${sh.columns}×${sh.rows} cells`;\n case RegionCardinality.FULL_TABLE:\n return null;\n default:\n return null;\n }\n}\n\n/** Toolbar that renders the actions/controls applicable to the current\n * selection cardinality (modal by selection) and edit mode. Actions with a\n * `render` show their live control; others show a button (with an optional\n * `detailsForm` popover). Column-specific actions from `ColumnSpec.actions`\n * are merged when their columns are selected. A capsule on the left shows the\n * current selection polarity. */\nexport function ActionsToolbar<T>({\n actions,\n tableName,\n}: {\n actions: TableAction<T>[];\n tableName?: string;\n}) {\n const selection = useSelector((state) => state.selection);\n const editable = useSelector((state) => state.editable);\n const columnSpec = useSelector((state) => state.columnSpec);\n const storeAPI = useStoreAPI();\n\n const cardinality = useMemo(\n () => getSelectionCardinality(selection) ?? RegionCardinality.FULL_TABLE,\n [selection],\n );\n\n // Merge global actions with column-specific actions from the selection\n const allActions = useMemo(\n () => mergeColumnActions(actions, columnSpec, selection),\n [actions, columnSpec, selection],\n );\n\n const applicableActions = useMemo(\n () => getApplicableActions(allActions, cardinality, editable),\n [allActions, cardinality, editable],\n );\n\n // Context for `render`-style controls (they subscribe to the store\n // themselves; this resolves the selected column/rows).\n const ctx = buildActionContext(\n storeAPI.getState(),\n storeAPI.setState,\n ) as TableActionContext<T>;\n\n // The toolbar is for actions that AREN'T keyboard-accessible: any action\n // with a `hotkey` (copy/cut/paste, etc.) is reachable from the keyboard and\n // is omitted here (it still works via its shortcut). Then refine by selection\n // shape beyond cardinality (e.g. single column only).\n const shownActions = applicableActions.filter(\n (action) => action.hotkey == null && (action.appliesTo?.(ctx) ?? true),\n );\n\n const toolbarIsShown = useMemo(\n () => hasAnyDisplayableActions(actions, columnSpec),\n [actions, columnSpec],\n );\n\n if (!toolbarIsShown) {\n return null;\n }\n\n // The toolbar is always mounted if actions are available, so it can't flicker\n // in/out as the selection or action set changes — the container is stable;\n // only its contents (title + buttons) change. Avoids layout jank.\n //\n // The leading title doubles as the clear-selection affordance: with an active\n // selection it renders as a dismissible tag (its ✕ clears the selection),\n // which ties \"clear\" to the selection it acts on and frees toolbar space.\n // With no selection it's a plain label (table name).\n // Both states render as a `large` `Tag` so the title keeps a constant font\n // and height; only the selected one has a filled background + a ✕ (which\n // clears the selection). The unselected label is a transparent, non-removable\n // tag — visually a plain title, but the same box.\n const hasSelection = selection != null && selection.length > 0;\n const titleNode = h(\n Tag,\n {\n key: \"title\",\n minimal: true,\n large: true,\n onRemove: hasSelection\n ? () =>\n storeAPI.setState({\n selection: [],\n focusedCell: null,\n topLeftCell: null,\n })\n : undefined,\n style: hasSelection ? undefined : { background: \"transparent\" },\n },\n hasSelection\n ? (selectionTitle(ctx) ?? tableName ?? \"Selection\")\n : (tableName ?? \"Table\"),\n );\n\n // Order left→right by generality: actions applicable to the whole table (or\n // no selection) are \"global\" and sit after a spacer on the right (Save /\n // Reset); everything else is contextual and stays on the left. So the left\n // edge tracks the selection and the right edge is constant.\n const isGlobal = (a: TableAction<T>) =>\n a.targets.includes(RegionCardinality.FULL_TABLE) ||\n a.targets.includes(\"none\" as any);\n const contextual = shownActions.filter((a) => !isGlobal(a));\n // Order the built-in global actions least→most impactful, left→right: reset\n // changes, then save. Any other global actions keep their natural order to\n // the left of these (stable sort, rank 0).\n const globalOrder: Record<string, number> = {\n \"reset-changes\": 1,\n \"save-changes\": 2,\n };\n const globalActions = shownActions\n .filter(isGlobal)\n .sort((a, b) => (globalOrder[a.id] ?? 0) - (globalOrder[b.id] ?? 0));\n\n return h(\"div.actions-toolbar\", [\n titleNode,\n h(\n ButtonGroup,\n { key: \"contextual\", minimal: true },\n contextual.map((action) =>\n h(ActionButton, { key: action.id, action, ctx }),\n ),\n ),\n h(\"div.toolbar-spacer\", { key: \"spacer\", style: { flex: 1 } }),\n h(\n ButtonGroup,\n { key: \"global\", minimal: true },\n globalActions.map((action) =>\n h(ActionButton, { key: action.id, action, ctx }),\n ),\n ),\n ]);\n}\n\nfunction getMessageForError(e: any) {\n if (e instanceof Error) return e.message;\n if (typeof e === \"string\") return e;\n if (e instanceof Object) return JSON.stringify(e);\n return null;\n}\n\nfunction isActionDisabled(action: TableAction, state: any): boolean {\n if (typeof action.disabled === \"boolean\") return action.disabled;\n if (typeof action.disabled === \"function\") {\n return action.disabled(state);\n }\n return false;\n}\n\nexport function runActionWrapper<T>(\n action: TableAction<T>,\n state: DataSheetStore<any>,\n setState: (state: Partial<DataSheetStore<any>>) => void,\n toaster: any,\n configState: any = undefined,\n) {\n const ctx = buildActionContext(state, setState) as TableActionContext<T>;\n if (action.disabled instanceof Function) {\n if (action.disabled(ctx)) {\n return;\n }\n } else if (action.disabled) {\n return;\n }\n try {\n const res = action.run?.(ctx, configState);\n if (res instanceof Promise) {\n res\n .then(() => {})\n .catch((e) => {\n displayErrorForAction(action, e, toaster);\n });\n }\n } catch (e) {\n displayErrorForAction(action, e, toaster);\n }\n}\n\n/** Dispatcher: a live control (`action.render`) or a run/detailsForm button.\n * Kept hook-free so the two paths don't share a hook order. */\nfunction ActionButton<T>({\n action,\n ctx,\n}: {\n action: TableAction<T>;\n ctx: TableActionContext<T>;\n}) {\n if (action.render != null) {\n return action.render(ctx) as any;\n }\n return h(RunActionButton, { action });\n}\n\n/** A run/detailsForm action rendered as a button. */\nfunction RunActionButton<T>({ action }: { action: TableAction<T> }) {\n const storeAPI = useStoreAPI();\n const toaster = useToaster();\n\n // Reactive disabled check — re-renders when relevant state changes\n const isDisabled = useSelector((state) => {\n return isActionDisabled(action, state);\n });\n\n const runAction = useCallback(\n (configState?: any) => {\n runActionWrapper(\n action,\n storeAPI.getState(),\n storeAPI.setState,\n toaster,\n configState,\n );\n },\n [storeAPI, action, toaster],\n );\n\n if (action.detailsForm != null) {\n return h(ActionButtonWithForm, { action, runAction, isDisabled });\n }\n\n return h(\n Button,\n {\n icon: action.icon,\n intent: action.intent,\n disabled: isDisabled,\n onClick() {\n runAction();\n },\n },\n action.name,\n );\n}\n\nfunction displayErrorForAction(action: TableAction, error: any, toaster: any) {\n const message =\n getMessageForError(error) ?? action.errorMessage ?? \"Action failed\";\n toaster.show({\n message,\n intent: \"danger\",\n });\n}\n\n/** Action button that opens a popover for pre-run configuration. */\nfunction ActionButtonWithForm<T, S>({\n action,\n runAction,\n isDisabled,\n}: {\n action: TableAction<T, S>;\n runAction: (configState?: S) => void;\n isDisabled: boolean;\n}) {\n const [configState, setConfigState] = useState<S>(\n action.defaultState ?? (null as S),\n );\n const [isOpen, setIsOpen] = useState(false);\n\n let ready = true;\n if (action.isReady != null) {\n ready = action.isReady(configState);\n }\n\n return h(\n PopoverNext,\n {\n isOpen,\n onClose: () => setIsOpen(false),\n content: h(\"div.action-popover-content\", [\n h.if(action.description != null)(\"p.description\", action.description),\n h(action.detailsForm, {\n state: configState,\n setState: setConfigState,\n }),\n h(\n Button,\n {\n className: \"run-button\",\n intent: action.intent ?? \"primary\",\n icon: \"play\",\n disabled: !ready,\n fill: true,\n onClick() {\n runAction(configState);\n setIsOpen(false);\n },\n },\n \"Run\",\n ),\n ]),\n placement: \"bottom-start\",\n enforceFocus: false,\n autoFocus: false,\n },\n h(\n Button,\n {\n icon: action.icon,\n intent: action.intent,\n disabled: isDisabled,\n onClick: () => setIsOpen(!isOpen),\n },\n action.name,\n ),\n );\n}\n\nfunction hasAnyDisplayableActions(\n actions: TableAction[],\n columnSpec: ColumnSpec[],\n) {\n /** Check whether there are any actions that can be displayed in the toolbar.\n * for the entire table. This is used to determine whether the toolbar should\n * be rendered. If any actions are available, the toolbar is rendered in ALL\n * selection modes to avoid flickering\n */\n const allActions = [\n ...actions,\n ...columnSpec.flatMap((c) => c.actions ?? []),\n ];\n\n if (allActions.length === 0) {\n return false;\n }\n // Check whether any action doesn't have hotkey and is not disabled\n return allActions.some(\n (action) => action.hotkey == null && !isActionDisabled(action, {}),\n );\n}\n"],"names":[],"mappings":";;;;;;;AAkBA,SAAS,eAAkB,KAA2C;AACpE,QAAM,KAAK,IAAI;AACf,UAAQ,GAAG,aAAA;AAAA,IACT,KAAK,kBAAkB,cAAc;AACnC,UAAI,IAAI,aAAa,MAAM;AACzB,cAAM,MAAM,IAAI,WAAW,KAAK,CAAC,MAAM,EAAE,QAAQ,IAAI,SAAS;AAC9D,eAAO,KAAK,QAAQ;AAAA,MACtB;AACA,aAAO,GAAG,GAAG,OAAO;AAAA,IACtB;AAAA,IACA,KAAK,kBAAkB;AACrB,aAAO,IAAI,YAAY,OAAO,UAAU,GAAG,GAAG,IAAI;AAAA,IACpD,KAAK,kBAAkB;AACrB,aAAO,IAAI,QAAQ,OAAO,SAAS,GAAG,GAAG,OAAO,IAAI,GAAG,IAAI;AAAA,IAC7D,KAAK,kBAAkB;AACrB,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EAAA;AAEb;AAQO,SAAS,eAAkB;AAAA,EAChC;AAAA,EACA;AACF,GAGG;AACD,QAAM,YAAY,YAAY,CAAC,UAAU,MAAM,SAAS;AACxD,QAAM,WAAW,YAAY,CAAC,UAAU,MAAM,QAAQ;AACtD,QAAM,aAAa,YAAY,CAAC,UAAU,MAAM,UAAU;AAC1D,QAAM,WAAW,YAAA;AAEjB,QAAM,cAAc;AAAA,IAClB,MAAM,wBAAwB,SAAS,KAAK,kBAAkB;AAAA,IAC9D,CAA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WAAW;AAAA,IAChB,CAAC,WAAW,OAAO,UAAU,QAAQ,CAAC,iBAAiB,QAAQ,CAAA,CAAE;AAAA,EAAA;AAErE;"}
|
package/dist/actions/types.d.ts
CHANGED
|
@@ -20,6 +20,9 @@ export interface CellEdit {
|
|
|
20
20
|
rowIndex: number;
|
|
21
21
|
column: string;
|
|
22
22
|
value: any;
|
|
23
|
+
/** The underlying row (base data). Populated on emitted `onEdit` events so a
|
|
24
|
+
* handler can address the row (identity) without reaching into the store. */
|
|
25
|
+
row?: any;
|
|
23
26
|
}
|
|
24
27
|
/** A column filter that can be activated to hide non-matching rows.
|
|
25
28
|
* Parallel to `TableAction` but with persistent state while active.
|
|
@@ -177,6 +180,12 @@ export interface TableAction<T = any, S = null> {
|
|
|
177
180
|
* `run`, unless the control itself invokes it). This is how sort/filter/group
|
|
178
181
|
* are expressed as `FULL_COLUMNS`-scoped controls in the one action system. */
|
|
179
182
|
render?: (context: TableActionContext<T>) => ReactNode;
|
|
183
|
+
/** Menu-native rendering for a menu surface (the column-header dropdown):
|
|
184
|
+
* return `MenuItem`(s) — e.g. sort as a submenu, or a filter list where each
|
|
185
|
+
* filter is an item opening its form in a submenu. When present, the
|
|
186
|
+
* column-header menu uses this instead of `render` (which stays for the
|
|
187
|
+
* toolbar's inline/popover control). May return multiple items (a fragment).*/
|
|
188
|
+
renderMenuItem?: (context: TableActionContext<T>) => ReactNode;
|
|
180
189
|
/** Execute the action. May be synchronous (local state manipulation)
|
|
181
190
|
* or asynchronous (backend fulfillment). For lazy-loaded tables,
|
|
182
191
|
* async actions are required when targeting non-loaded cells.
|
package/dist/cell-renderer.cjs
CHANGED
|
@@ -15,7 +15,9 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, filteredRowInd
|
|
|
15
15
|
const dataRowIndex = filteredRowIndices != null ? filteredRowIndices[rowIndex] ?? rowIndex : rowIndex;
|
|
16
16
|
const data = state.data;
|
|
17
17
|
const updatedData = state.updatedData;
|
|
18
|
-
const
|
|
18
|
+
const statusVal = state.rowStatus[dataRowIndex];
|
|
19
|
+
const isDeleted = statusVal == types.TableElementStatus.DELETED;
|
|
20
|
+
const statusStyle = statusVal != null ? state.rowStatusStyles?.[statusVal] : void 0;
|
|
19
21
|
const row = data[dataRowIndex] ?? updatedData[dataRowIndex];
|
|
20
22
|
const loading = row == null;
|
|
21
23
|
const col = columnSpec;
|
|
@@ -33,13 +35,13 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, filteredRowInd
|
|
|
33
35
|
row,
|
|
34
36
|
isEdited: edited,
|
|
35
37
|
isDeleted,
|
|
38
|
+
status: statusVal,
|
|
36
39
|
validation: validation$1
|
|
37
40
|
};
|
|
38
41
|
const _renderedValue = isEmpty ? null : col.valueRenderer?.(value, cellContext) ?? value;
|
|
39
42
|
let style = { ...col.style ?? {} };
|
|
40
|
-
if (
|
|
41
|
-
style
|
|
42
|
-
style.textDecoration = "line-through";
|
|
43
|
+
if (statusStyle?.cellStyle != null) {
|
|
44
|
+
style = { ...style, ...statusStyle.cellStyle };
|
|
43
45
|
}
|
|
44
46
|
const editable = (col.editable ?? state.editable) && !isDeleted;
|
|
45
47
|
const topLeft = _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;
|
|
@@ -49,8 +51,8 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, filteredRowInd
|
|
|
49
51
|
intent = "danger";
|
|
50
52
|
} else if (validation$1?.severity === "warning") {
|
|
51
53
|
intent = "warning";
|
|
52
|
-
} else if (
|
|
53
|
-
intent =
|
|
54
|
+
} else if (statusStyle?.intent != null) {
|
|
55
|
+
intent = statusStyle.intent;
|
|
54
56
|
} else if (edited) {
|
|
55
57
|
intent = "success";
|
|
56
58
|
}
|
|
@@ -189,7 +191,7 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, filteredRowInd
|
|
|
189
191
|
isEdited: edited,
|
|
190
192
|
onChange(value2) {
|
|
191
193
|
if (!editable) return;
|
|
192
|
-
state.
|
|
194
|
+
state.onCellEdited(dataRowIndex, col.key, value2);
|
|
193
195
|
},
|
|
194
196
|
resetValue() {
|
|
195
197
|
state.resetChanges();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cell-renderer.cjs","sources":["../src/cell-renderer.ts"],"sourcesContent":["import {\n ColumnSpec,\n CellRenderContext,\n CellDetailContext,\n editorKeyHandlerAtom,\n validateCell,\n} from \"./utils\";\nimport { DataSheetStore, TableElementStatus } from \"./types.ts\";\nimport h from \"./main.module.sass\";\nimport { ReactNode, useEffect, useRef, useState } from \"react\";\nimport { EditorPopup, CellDetailModal } from \"./components\";\nimport { singleFocusedCell } from \"./zustand-store.ts\";\nimport { Cell } from \"@blueprintjs/table\";\nimport { ctx, useSelector } from \"./provider.ts\";\n\nexport function basicCellRenderer<T>(\n rowIndex: number,\n colIndex: number,\n columnSpec: ColumnSpec,\n state: DataSheetStore<T>,\n filteredRowIndices?: number[] | null,\n): any {\n // Auto-activation is on when the mode is \"auto\" and it hasn't been suppressed\n // (Escape enters navigation mode until the next click).\n // Whether the inline editor grabs focus. It follows the store-owned surface\n // open state, so it focuses on selection in auto mode and on click in manual\n // mode, and not at all in navigation mode. The popover surfaces read the\n // same state directly.\n const focusOnOpen = state.cellSurfaceOpen;\n // When filters are active, `rowIndex` is the visible row position.\n // Map it to the actual data index for data access.\n const dataRowIndex =\n filteredRowIndices != null\n ? (filteredRowIndices[rowIndex] ?? rowIndex)\n : rowIndex;\n\n const data = state.data;\n const updatedData = state.updatedData;\n\n const isDeleted = state.rowStatus[dataRowIndex] == TableElementStatus.DELETED;\n\n const row = data[dataRowIndex] ?? updatedData[dataRowIndex];\n const loading = row == null;\n const col = columnSpec;\n\n const _topLeftCell = state.topLeftCell;\n const onCellEdited = state.onCellEdited;\n\n const value: T | undefined =\n updatedData[dataRowIndex]?.[col.key] ?? data[dataRowIndex]?.[col.key];\n const isEmpty = value == null || value === \"\";\n\n const edited =\n updatedData[dataRowIndex]?.[col.key] != null ||\n state.rowStatus[dataRowIndex] === TableElementStatus.ADDED;\n\n // Validate the cell (skipped for deleted rows). Orthogonal to edit status.\n const validation = isDeleted ? null : validateCell(col, value, row, dataRowIndex);\n\n // Context passed to custom renderers so they can render based on the\n // row/column position and cell status (and, with the editing API, write\n // edits back). `rowIndex` is the data-row index, stable under sort/filter.\n const cellContext: CellRenderContext<T> = {\n value,\n rowIndex: dataRowIndex,\n colIndex,\n column: col,\n row,\n isEdited: edited,\n isDeleted,\n validation,\n };\n\n const _renderedValue = isEmpty\n ? null\n : (col.valueRenderer?.(value, cellContext) ?? value);\n\n // Clone so we never mutate the caller's column-spec style object\n let style = { ...(col.style ?? {}) };\n\n if (isDeleted) {\n style.opacity = 0.5;\n style.textDecoration = \"line-through\";\n }\n\n const editable = (col.editable ?? state.editable) && !isDeleted;\n\n // topLeftCell stores visible row indices, so compare with the visible rowIndex\n const topLeft =\n _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;\n\n const tableIsEditable = state.editable;\n\n // Intent precedence: error > warning > deleted > edited. Validation state\n // overrides the edited-green so an edited-but-invalid cell reads as invalid.\n let intent: string | undefined;\n if (validation?.severity === \"error\") {\n intent = \"danger\";\n } else if (validation?.severity === \"warning\") {\n intent = \"warning\";\n } else if (isDeleted) {\n intent = \"danger\";\n } else if (edited) {\n intent = \"success\";\n }\n\n const _Cell = col.cellComponent ?? Cell;\n\n // Only forward the render context to a custom cell component; the default\n // Blueprint Cell would spread unknown props onto the DOM.\n const cellComponentProps =\n col.cellComponent != null ? { cellContext } : {};\n\n // Allow a column to pick the editor per-cell (e.g. textarea only when the\n // value is long). A returned key overrides the static column field even\n // when its value is false/null, so use `in` rather than nullish-coalesce.\n const perCellEditors = col.editorForCell?.(cellContext);\n const dataEditorSpec =\n perCellEditors != null && \"dataEditor\" in perCellEditors\n ? perCellEditors.dataEditor\n : col.dataEditor;\n const inlineEditorSpec =\n perCellEditors != null && \"inlineEditor\" in perCellEditors\n ? perCellEditors.inlineEditor\n : col.inlineEditor;\n\n let inlineEditor = editable ? (inlineEditorSpec ?? true) : false;\n\n // Build the detail context for the unified `cellDetail` surface.\n const makeDetailCtx = (editableFlag: boolean): CellDetailContext<T> => ({\n ...cellContext,\n editable: editableFlag,\n onChange(v: any) {\n if (editableFlag) onCellEdited(dataRowIndex, col.key, v);\n },\n resetValue() {\n state.resetChanges();\n },\n close() {\n state.closeCellSurface();\n state.tableElement?.focus?.();\n },\n });\n const detailPresentation =\n col.cellDetail != null ? (col.detailPresentation ?? \"popover\") : null;\n\n if (!topLeft) {\n // An inline surface is a persistent in-cell renderer, so it draws on every\n // cell (read-only when not the focused/editing cell).\n if (detailPresentation === \"inline\") {\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n col.cellDetail!(makeDetailCtx(false)),\n );\n }\n return h(\n _Cell,\n {\n intent,\n loading,\n value,\n style,\n disabled: tableIsEditable && !editable,\n interactive: false,\n ...cellComponentProps,\n },\n _renderedValue,\n );\n }\n\n // The rest is for the top-left cell of a selection or the focused cell\n\n // Unified cell surface: one renderer that acts as editor (when editable) or\n // viewer (otherwise), presented as a popover / modal / inline. Supersedes\n // dataEditor / detailRenderer / editorForCell.\n if (col.cellDetail != null) {\n const content = col.cellDetail(makeDetailCtx(editable));\n\n if (detailPresentation === \"inline\") {\n // Persistent in-cell surface (editable on the focused cell). No popover.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: editable ? \"input-cell\" : \"value-viewer-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n content,\n );\n }\n\n if (detailPresentation === \"modal\") {\n // CellDetailModal subscribes to the store so the dialog closes reactively.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n h(\n CellDetailModal,\n { title: col.name, valueViewer: _renderedValue },\n content,\n ),\n );\n }\n\n // Default: popover (same open/close machinery as editors and panels).\n const panel = h(EditorPopup, { valueViewer: _renderedValue }, content);\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"editor-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n // Read-only detail panel: a surface that opens on selection (auto) or click,\n // shows arbitrary content, and never takes keyboard focus — so arrow keys\n // keep navigating the table. Uses the same open/close machinery as editors.\n if (col.detailRenderer != null) {\n const panel = h(\n EditorPopup,\n { valueViewer: _renderedValue },\n col.detailRenderer(cellContext),\n );\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n // Use the editor-cell popover layout so the target fills the cell\n // without the double-padding offset of `value-viewer-cell`.\n className: \"editor-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n let cellContents: ReactNode = _renderedValue;\n\n let _dataEditor = null;\n let className = null;\n\n if (dataEditorSpec != null) {\n _dataEditor = h(\n EditorPopup,\n {\n valueViewer: _renderedValue,\n },\n [\n h(dataEditorSpec, {\n value,\n editable,\n isEdited: edited,\n onChange(value) {\n if (!editable) return;\n state.onSelectionEdited(value);\n },\n resetValue() {\n state.resetChanges();\n },\n }),\n ],\n );\n }\n\n if (!editable) {\n if (_dataEditor != null) {\n cellContents = _dataEditor;\n }\n const className = \"value-viewer-cell\";\n\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className,\n interactive: false,\n ...cellComponentProps,\n },\n cellContents,\n );\n }\n\n /* The remaining logic covers cells that are focused and editable */\n\n const onChange = (e) => {\n if (!editable) return;\n if (_renderedValue === e.target.value) return;\n // Use dataRowIndex for the actual data mutation\n onCellEdited(dataRowIndex, col.key, e.target.value);\n };\n\n const isSingleCellSelection = singleFocusedCell(state.selection) != null;\n\n let _inlineEditor: ReactNode = null;\n if (typeof inlineEditor == \"boolean\") {\n let _value = value;\n if (\n typeof _renderedValue === \"string\" ||\n typeof _renderedValue === \"number\" ||\n _renderedValue == null\n ) {\n _value = _renderedValue;\n }\n _inlineEditor = h(EditorInput, {\n className: \"main-editor\",\n value: _value ?? \"\",\n autoFocus: focusOnOpen,\n onChange,\n });\n } else {\n // If inlineEditor is a ReactNode, we use it directly\n _inlineEditor = inlineEditor as ReactNode;\n }\n\n let hiddenInput: React.ReactNode = h(EditorInput, {\n className: \"hidden-input\",\n autoFocus: true,\n });\n\n if (_dataEditor != null) {\n className = \"editor-cell\";\n cellContents = _dataEditor;\n hiddenInput = null;\n } else if (_inlineEditor != null) {\n cellContents = _inlineEditor;\n className = \"input-cell\";\n hiddenInput = null;\n }\n\n // Hidden html input\n return h(\n _Cell,\n {\n intent,\n value,\n className,\n style,\n interactive: true,\n ...cellComponentProps,\n //truncated: false,\n },\n [\n cellContents,\n h.if(editable && isSingleCellSelection)(DragHandle),\n //hiddenInput,\n ],\n );\n}\n\nfunction EditorInput(props) {\n const { value, onChange, ...rest } = props;\n const onKeyDown = ctx.useValue(editorKeyHandlerAtom);\n const navDirection = useSelector((s) => s.lastNavDirection);\n const surfaceOpen = useSelector((s) => s.cellSurfaceOpen);\n const inputRef = useRef<HTMLInputElement>(null);\n const [_value, setValue] = useState(value);\n useEffect(() => {\n setValue(value);\n }, [value]);\n useEffect(() => {\n // Focus when the cell's surface is open (on mount, and when reopened via\n // click/F2 while already mounted), placing the cursor on the side we're\n // travelling toward so another arrow in that direction leaves the cell.\n const el = inputRef.current;\n if (el == null || !surfaceOpen) return;\n el.focus();\n const atStart = navDirection === \"up\" || navDirection === \"left\";\n const pos = atStart ? 0 : (el.value?.length ?? 0);\n el.setSelectionRange(pos, pos);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [surfaceOpen]);\n return h(\"input\", {\n ref: inputRef,\n onKeyDown,\n onBlur: onChange,\n value: _value ?? value,\n onChange: (e) => setValue(e.target.value),\n ...rest,\n });\n}\n\nfunction DragHandle() {\n // TODO: we might want to drag multiple columns in some cases\n // This should be on the last cell of a selection\n const onMouseDown = useSelector((state) => state.onDragValue);\n return h(\"div.corner-drag-handle\", { onMouseDown });\n}\n"],"names":["TableElementStatus","validation","validateCell","Cell","h","CellDetailModal","EditorPopup","value","className","singleFocusedCell","ctx","editorKeyHandlerAtom","useSelector","useRef","useState","useEffect"],"mappings":";;;;;;;;;;;;AAeO,SAAS,kBACd,UACA,UACA,YACA,OACA,oBACK;AAOL,QAAM,cAAc,MAAM;AAG1B,QAAM,eACJ,sBAAsB,OACjB,mBAAmB,QAAQ,KAAK,WACjC;AAEN,QAAM,OAAO,MAAM;AACnB,QAAM,cAAc,MAAM;AAE1B,QAAM,YAAY,MAAM,UAAU,YAAY,KAAKA,MAAAA,mBAAmB;AAEtE,QAAM,MAAM,KAAK,YAAY,KAAK,YAAY,YAAY;AAC1D,QAAM,UAAU,OAAO;AACvB,QAAM,MAAM;AAEZ,QAAM,eAAe,MAAM;AAC3B,QAAM,eAAe,MAAM;AAE3B,QAAM,QACJ,YAAY,YAAY,IAAI,IAAI,GAAG,KAAK,KAAK,YAAY,IAAI,IAAI,GAAG;AACtE,QAAM,UAAU,SAAS,QAAQ,UAAU;AAE3C,QAAM,SACJ,YAAY,YAAY,IAAI,IAAI,GAAG,KAAK,QACxC,MAAM,UAAU,YAAY,MAAMA,MAAAA,mBAAmB;AAGvD,QAAMC,eAAa,YAAY,OAAOC,WAAAA,aAAa,KAAK,OAAO,KAAK,YAAY;AAKhF,QAAM,cAAoC;AAAA,IACxC;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IAAA,YACAD;AAAAA,EAAA;AAGF,QAAM,iBAAiB,UACnB,OACC,IAAI,gBAAgB,OAAO,WAAW,KAAK;AAGhD,MAAI,QAAQ,EAAE,GAAI,IAAI,SAAS,CAAA,EAAC;AAEhC,MAAI,WAAW;AACb,UAAM,UAAU;AAChB,UAAM,iBAAiB;AAAA,EACzB;AAEA,QAAM,YAAY,IAAI,YAAY,MAAM,aAAa,CAAC;AAGtD,QAAM,UACJ,cAAc,QAAQ,YAAY,cAAc,QAAQ;AAE1D,QAAM,kBAAkB,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,IAChB,KAAK;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,IACR,OAAO,UAAU;AAAA,IACjB,UAAU,CAAC,MAAM,SAAS,EAAE,OAAO,KAAK;AAAA,IACxC,GAAG;AAAA,EAAA,CACJ;AACH;AAEA,SAAS,aAAa;AAGpB,QAAM,cAAcQ,SAAAA,YAAY,CAAC,UAAU,MAAM,WAAW;AAC5D,SAAOR,oBAAE,0BAA0B,EAAE,aAAa;AACpD;;"}
|
|
1
|
+
{"version":3,"file":"cell-renderer.cjs","sources":["../src/cell-renderer.ts"],"sourcesContent":["import {\n ColumnSpec,\n CellRenderContext,\n CellDetailContext,\n editorKeyHandlerAtom,\n validateCell,\n} from \"./utils\";\nimport { DataSheetStore, TableElementStatus } from \"./types.ts\";\nimport h from \"./main.module.sass\";\nimport { ReactNode, useEffect, useRef, useState } from \"react\";\nimport { EditorPopup, CellDetailModal } from \"./components\";\nimport { singleFocusedCell } from \"./zustand-store.ts\";\nimport { Cell } from \"@blueprintjs/table\";\nimport { ctx, useSelector } from \"./provider.ts\";\n\nexport function basicCellRenderer<T>(\n rowIndex: number,\n colIndex: number,\n columnSpec: ColumnSpec,\n state: DataSheetStore<T>,\n filteredRowIndices?: number[] | null,\n): any {\n // Auto-activation is on when the mode is \"auto\" and it hasn't been suppressed\n // (Escape enters navigation mode until the next click).\n // Whether the inline editor grabs focus. It follows the store-owned surface\n // open state, so it focuses on selection in auto mode and on click in manual\n // mode, and not at all in navigation mode. The popover surfaces read the\n // same state directly.\n const focusOnOpen = state.cellSurfaceOpen;\n // When filters are active, `rowIndex` is the visible row position.\n // Map it to the actual data index for data access.\n const dataRowIndex =\n filteredRowIndices != null\n ? (filteredRowIndices[rowIndex] ?? rowIndex)\n : rowIndex;\n\n const data = state.data;\n const updatedData = state.updatedData;\n\n const statusVal = state.rowStatus[dataRowIndex];\n const isDeleted = statusVal == TableElementStatus.DELETED;\n // Presentation for this row's status (deleted, or a consumer-defined status\n // like \"omitted\"), from the merged `rowStatusStyles`.\n const statusStyle = statusVal != null ? state.rowStatusStyles?.[statusVal] : undefined;\n\n const row = data[dataRowIndex] ?? updatedData[dataRowIndex];\n const loading = row == null;\n const col = columnSpec;\n\n const _topLeftCell = state.topLeftCell;\n const onCellEdited = state.onCellEdited;\n\n const value: T | undefined =\n updatedData[dataRowIndex]?.[col.key] ?? data[dataRowIndex]?.[col.key];\n const isEmpty = value == null || value === \"\";\n\n const edited =\n updatedData[dataRowIndex]?.[col.key] != null ||\n state.rowStatus[dataRowIndex] === TableElementStatus.ADDED;\n\n // Validate the cell (skipped for deleted rows). Orthogonal to edit status.\n const validation = isDeleted ? null : validateCell(col, value, row, dataRowIndex);\n\n // Context passed to custom renderers so they can render based on the\n // row/column position and cell status (and, with the editing API, write\n // edits back). `rowIndex` is the data-row index, stable under sort/filter.\n const cellContext: CellRenderContext<T> = {\n value,\n rowIndex: dataRowIndex,\n colIndex,\n column: col,\n row,\n isEdited: edited,\n isDeleted,\n status: statusVal,\n validation,\n };\n\n const _renderedValue = isEmpty\n ? null\n : (col.valueRenderer?.(value, cellContext) ?? value);\n\n // Clone so we never mutate the caller's column-spec style object, then layer\n // the row-status presentation (deleted → dimmed/struck-through by default;\n // consumer statuses supply their own `cellStyle`).\n let style = { ...(col.style ?? {}) };\n\n if (statusStyle?.cellStyle != null) {\n style = { ...style, ...statusStyle.cellStyle };\n }\n\n const editable = (col.editable ?? state.editable) && !isDeleted;\n\n // topLeftCell stores visible row indices, so compare with the visible rowIndex\n const topLeft =\n _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;\n\n const tableIsEditable = state.editable;\n\n // Intent precedence: error > warning > row-status intent > edited. Validation\n // state overrides the edited-green so an edited-but-invalid cell reads as\n // invalid. A row's status intent (e.g. deleted → danger) outranks the\n // edited-green so status reads through even on an edited row.\n let intent: string | undefined;\n if (validation?.severity === \"error\") {\n intent = \"danger\";\n } else if (validation?.severity === \"warning\") {\n intent = \"warning\";\n } else if (statusStyle?.intent != null) {\n intent = statusStyle.intent;\n } else if (edited) {\n intent = \"success\";\n }\n\n const _Cell = col.cellComponent ?? Cell;\n\n // Only forward the render context to a custom cell component; the default\n // Blueprint Cell would spread unknown props onto the DOM.\n const cellComponentProps =\n col.cellComponent != null ? { cellContext } : {};\n\n // Allow a column to pick the editor per-cell (e.g. textarea only when the\n // value is long). A returned key overrides the static column field even\n // when its value is false/null, so use `in` rather than nullish-coalesce.\n const perCellEditors = col.editorForCell?.(cellContext);\n const dataEditorSpec =\n perCellEditors != null && \"dataEditor\" in perCellEditors\n ? perCellEditors.dataEditor\n : col.dataEditor;\n const inlineEditorSpec =\n perCellEditors != null && \"inlineEditor\" in perCellEditors\n ? perCellEditors.inlineEditor\n : col.inlineEditor;\n\n let inlineEditor = editable ? (inlineEditorSpec ?? true) : false;\n\n // Build the detail context for the unified `cellDetail` surface.\n const makeDetailCtx = (editableFlag: boolean): CellDetailContext<T> => ({\n ...cellContext,\n editable: editableFlag,\n onChange(v: any) {\n if (editableFlag) onCellEdited(dataRowIndex, col.key, v);\n },\n resetValue() {\n state.resetChanges();\n },\n close() {\n state.closeCellSurface();\n state.tableElement?.focus?.();\n },\n });\n const detailPresentation =\n col.cellDetail != null ? (col.detailPresentation ?? \"popover\") : null;\n\n if (!topLeft) {\n // An inline surface is a persistent in-cell renderer, so it draws on every\n // cell (read-only when not the focused/editing cell).\n if (detailPresentation === \"inline\") {\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n col.cellDetail!(makeDetailCtx(false)),\n );\n }\n return h(\n _Cell,\n {\n intent,\n loading,\n value,\n style,\n disabled: tableIsEditable && !editable,\n interactive: false,\n ...cellComponentProps,\n },\n _renderedValue,\n );\n }\n\n // The rest is for the top-left cell of a selection or the focused cell\n\n // Unified cell surface: one renderer that acts as editor (when editable) or\n // viewer (otherwise), presented as a popover / modal / inline. Supersedes\n // dataEditor / detailRenderer / editorForCell.\n if (col.cellDetail != null) {\n const content = col.cellDetail(makeDetailCtx(editable));\n\n if (detailPresentation === \"inline\") {\n // Persistent in-cell surface (editable on the focused cell). No popover.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: editable ? \"input-cell\" : \"value-viewer-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n content,\n );\n }\n\n if (detailPresentation === \"modal\") {\n // CellDetailModal subscribes to the store so the dialog closes reactively.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n h(\n CellDetailModal,\n { title: col.name, valueViewer: _renderedValue },\n content,\n ),\n );\n }\n\n // Default: popover (same open/close machinery as editors and panels).\n const panel = h(EditorPopup, { valueViewer: _renderedValue }, content);\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"editor-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n // Read-only detail panel: a surface that opens on selection (auto) or click,\n // shows arbitrary content, and never takes keyboard focus — so arrow keys\n // keep navigating the table. Uses the same open/close machinery as editors.\n if (col.detailRenderer != null) {\n const panel = h(\n EditorPopup,\n { valueViewer: _renderedValue },\n col.detailRenderer(cellContext),\n );\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n // Use the editor-cell popover layout so the target fills the cell\n // without the double-padding offset of `value-viewer-cell`.\n className: \"editor-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n let cellContents: ReactNode = _renderedValue;\n\n let _dataEditor = null;\n let className = null;\n\n if (dataEditorSpec != null) {\n _dataEditor = h(\n EditorPopup,\n {\n valueViewer: _renderedValue,\n },\n [\n h(dataEditorSpec, {\n value,\n editable,\n isEdited: edited,\n onChange(value) {\n if (!editable) return;\n // Commit to THIS cell — not the live selection. The editor can\n // commit (e.g. on blur) after the selection has moved to another\n // cell or a whole column; `onSelectionEdited` would then write the\n // value to the wrong target (emptying it). `onCellEdited` addresses\n // the editor's own data cell.\n state.onCellEdited(dataRowIndex, col.key, value);\n },\n resetValue() {\n state.resetChanges();\n },\n }),\n ],\n );\n }\n\n if (!editable) {\n if (_dataEditor != null) {\n cellContents = _dataEditor;\n }\n const className = \"value-viewer-cell\";\n\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className,\n interactive: false,\n ...cellComponentProps,\n },\n cellContents,\n );\n }\n\n /* The remaining logic covers cells that are focused and editable */\n\n const onChange = (e) => {\n if (!editable) return;\n if (_renderedValue === e.target.value) return;\n // Use dataRowIndex for the actual data mutation\n onCellEdited(dataRowIndex, col.key, e.target.value);\n };\n\n const isSingleCellSelection = singleFocusedCell(state.selection) != null;\n\n let _inlineEditor: ReactNode = null;\n if (typeof inlineEditor == \"boolean\") {\n let _value = value;\n if (\n typeof _renderedValue === \"string\" ||\n typeof _renderedValue === \"number\" ||\n _renderedValue == null\n ) {\n _value = _renderedValue;\n }\n _inlineEditor = h(EditorInput, {\n className: \"main-editor\",\n value: _value ?? \"\",\n autoFocus: focusOnOpen,\n onChange,\n });\n } else {\n // If inlineEditor is a ReactNode, we use it directly\n _inlineEditor = inlineEditor as ReactNode;\n }\n\n let hiddenInput: React.ReactNode = h(EditorInput, {\n className: \"hidden-input\",\n autoFocus: true,\n });\n\n if (_dataEditor != null) {\n className = \"editor-cell\";\n cellContents = _dataEditor;\n hiddenInput = null;\n } else if (_inlineEditor != null) {\n cellContents = _inlineEditor;\n className = \"input-cell\";\n hiddenInput = null;\n }\n\n // Hidden html input\n return h(\n _Cell,\n {\n intent,\n value,\n className,\n style,\n interactive: true,\n ...cellComponentProps,\n //truncated: false,\n },\n [\n cellContents,\n h.if(editable && isSingleCellSelection)(DragHandle),\n //hiddenInput,\n ],\n );\n}\n\nfunction EditorInput(props) {\n const { value, onChange, ...rest } = props;\n const onKeyDown = ctx.useValue(editorKeyHandlerAtom);\n const navDirection = useSelector((s) => s.lastNavDirection);\n const surfaceOpen = useSelector((s) => s.cellSurfaceOpen);\n const inputRef = useRef<HTMLInputElement>(null);\n const [_value, setValue] = useState(value);\n useEffect(() => {\n setValue(value);\n }, [value]);\n useEffect(() => {\n // Focus when the cell's surface is open (on mount, and when reopened via\n // click/F2 while already mounted), placing the cursor on the side we're\n // travelling toward so another arrow in that direction leaves the cell.\n const el = inputRef.current;\n if (el == null || !surfaceOpen) return;\n el.focus();\n const atStart = navDirection === \"up\" || navDirection === \"left\";\n const pos = atStart ? 0 : (el.value?.length ?? 0);\n el.setSelectionRange(pos, pos);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [surfaceOpen]);\n return h(\"input\", {\n ref: inputRef,\n onKeyDown,\n onBlur: onChange,\n value: _value ?? value,\n onChange: (e) => setValue(e.target.value),\n ...rest,\n });\n}\n\nfunction DragHandle() {\n // TODO: we might want to drag multiple columns in some cases\n // This should be on the last cell of a selection\n const onMouseDown = useSelector((state) => state.onDragValue);\n return h(\"div.corner-drag-handle\", { onMouseDown });\n}\n"],"names":["TableElementStatus","validation","validateCell","Cell","h","CellDetailModal","EditorPopup","value","className","singleFocusedCell","ctx","editorKeyHandlerAtom","useSelector","useRef","useState","useEffect"],"mappings":";;;;;;;;;;;;AAeO,SAAS,kBACd,UACA,UACA,YACA,OACA,oBACK;AAOL,QAAM,cAAc,MAAM;AAG1B,QAAM,eACJ,sBAAsB,OACjB,mBAAmB,QAAQ,KAAK,WACjC;AAEN,QAAM,OAAO,MAAM;AACnB,QAAM,cAAc,MAAM;AAE1B,QAAM,YAAY,MAAM,UAAU,YAAY;AAC9C,QAAM,YAAY,aAAaA,MAAAA,mBAAmB;AAGlD,QAAM,cAAc,aAAa,OAAO,MAAM,kBAAkB,SAAS,IAAI;AAE7E,QAAM,MAAM,KAAK,YAAY,KAAK,YAAY,YAAY;AAC1D,QAAM,UAAU,OAAO;AACvB,QAAM,MAAM;AAEZ,QAAM,eAAe,MAAM;AAC3B,QAAM,eAAe,MAAM;AAE3B,QAAM,QACJ,YAAY,YAAY,IAAI,IAAI,GAAG,KAAK,KAAK,YAAY,IAAI,IAAI,GAAG;AACt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AA,IAAA;AAAA,EAEpD;AAEJ;AAEA,SAAS,YAAY,OAAO;AAC1B,QAAM,EAAE,OAAO,UAAU,GAAG,SAAS;AACrC,QAAM,YAAYM,SAAAA,IAAI,SAASC,gCAAoB;AACnD,QAAM,eAAeC,SAAAA,YAAY,CAAC,MAAM,EAAE,gBAAgB;AAC1D,QAAM,cAAcA,SAAAA,YAAY,CAAC,MAAM,EAAE,eAAe;AACxD,QAAM,WAAWC,MAAAA,OAAyB,IAAI;AAC9C,QAAM,CAAC,QAAQ,QAAQ,IAAIC,MAAAA,SAAS,KAAK;AACzCC,QAAAA,UAAU,MAAM;AACd,aAAS,KAAK;AAAA,EAChB,GAAG,CAAC,KAAK,CAAC;AACVA,QAAAA,UAAU,MAAM;AAId,UAAM,KAAK,SAAS;AACpB,QAAI,MAAM,QAAQ,CAAC,YAAa;AAChC,OAAG,MAAA;AACH,UAAM,UAAU,iBAAiB,QAAQ,iBAAiB;AAC1D,UAAM,MAAM,UAAU,IAAK,GAAG,OAAO,UAAU;AAC/C,OAAG,kBAAkB,KAAK,GAAG;AAAA,EAE/B,GAAG,CAAC,WAAW,CAAC;AAChB,SAAOX,YAAAA,QAAE,SAAS;AAAA,IAChB,KAAK;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,IACR,OAAO,UAAU;AAAA,IACjB,UAAU,CAAC,MAAM,SAAS,EAAE,OAAO,KAAK;AAAA,IACxC,GAAG;AAAA,EAAA,CACJ;AACH;AAEA,SAAS,aAAa;AAGpB,QAAM,cAAcQ,SAAAA,YAAY,CAAC,UAAU,MAAM,WAAW;AAC5D,SAAOR,oBAAE,0BAA0B,EAAE,aAAa;AACpD;;"}
|
package/dist/cell-renderer.js
CHANGED
|
@@ -13,7 +13,9 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, filteredRowInd
|
|
|
13
13
|
const dataRowIndex = filteredRowIndices != null ? filteredRowIndices[rowIndex] ?? rowIndex : rowIndex;
|
|
14
14
|
const data = state.data;
|
|
15
15
|
const updatedData = state.updatedData;
|
|
16
|
-
const
|
|
16
|
+
const statusVal = state.rowStatus[dataRowIndex];
|
|
17
|
+
const isDeleted = statusVal == TableElementStatus.DELETED;
|
|
18
|
+
const statusStyle = statusVal != null ? state.rowStatusStyles?.[statusVal] : void 0;
|
|
17
19
|
const row = data[dataRowIndex] ?? updatedData[dataRowIndex];
|
|
18
20
|
const loading = row == null;
|
|
19
21
|
const col = columnSpec;
|
|
@@ -31,13 +33,13 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, filteredRowInd
|
|
|
31
33
|
row,
|
|
32
34
|
isEdited: edited,
|
|
33
35
|
isDeleted,
|
|
36
|
+
status: statusVal,
|
|
34
37
|
validation
|
|
35
38
|
};
|
|
36
39
|
const _renderedValue = isEmpty ? null : col.valueRenderer?.(value, cellContext) ?? value;
|
|
37
40
|
let style = { ...col.style ?? {} };
|
|
38
|
-
if (
|
|
39
|
-
style
|
|
40
|
-
style.textDecoration = "line-through";
|
|
41
|
+
if (statusStyle?.cellStyle != null) {
|
|
42
|
+
style = { ...style, ...statusStyle.cellStyle };
|
|
41
43
|
}
|
|
42
44
|
const editable = (col.editable ?? state.editable) && !isDeleted;
|
|
43
45
|
const topLeft = _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;
|
|
@@ -47,8 +49,8 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, filteredRowInd
|
|
|
47
49
|
intent = "danger";
|
|
48
50
|
} else if (validation?.severity === "warning") {
|
|
49
51
|
intent = "warning";
|
|
50
|
-
} else if (
|
|
51
|
-
intent =
|
|
52
|
+
} else if (statusStyle?.intent != null) {
|
|
53
|
+
intent = statusStyle.intent;
|
|
52
54
|
} else if (edited) {
|
|
53
55
|
intent = "success";
|
|
54
56
|
}
|
|
@@ -187,7 +189,7 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, filteredRowInd
|
|
|
187
189
|
isEdited: edited,
|
|
188
190
|
onChange(value2) {
|
|
189
191
|
if (!editable) return;
|
|
190
|
-
state.
|
|
192
|
+
state.onCellEdited(dataRowIndex, col.key, value2);
|
|
191
193
|
},
|
|
192
194
|
resetValue() {
|
|
193
195
|
state.resetChanges();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cell-renderer.js","sources":["../src/cell-renderer.ts"],"sourcesContent":["import {\n ColumnSpec,\n CellRenderContext,\n CellDetailContext,\n editorKeyHandlerAtom,\n validateCell,\n} from \"./utils\";\nimport { DataSheetStore, TableElementStatus } from \"./types.ts\";\nimport h from \"./main.module.sass\";\nimport { ReactNode, useEffect, useRef, useState } from \"react\";\nimport { EditorPopup, CellDetailModal } from \"./components\";\nimport { singleFocusedCell } from \"./zustand-store.ts\";\nimport { Cell } from \"@blueprintjs/table\";\nimport { ctx, useSelector } from \"./provider.ts\";\n\nexport function basicCellRenderer<T>(\n rowIndex: number,\n colIndex: number,\n columnSpec: ColumnSpec,\n state: DataSheetStore<T>,\n filteredRowIndices?: number[] | null,\n): any {\n // Auto-activation is on when the mode is \"auto\" and it hasn't been suppressed\n // (Escape enters navigation mode until the next click).\n // Whether the inline editor grabs focus. It follows the store-owned surface\n // open state, so it focuses on selection in auto mode and on click in manual\n // mode, and not at all in navigation mode. The popover surfaces read the\n // same state directly.\n const focusOnOpen = state.cellSurfaceOpen;\n // When filters are active, `rowIndex` is the visible row position.\n // Map it to the actual data index for data access.\n const dataRowIndex =\n filteredRowIndices != null\n ? (filteredRowIndices[rowIndex] ?? rowIndex)\n : rowIndex;\n\n const data = state.data;\n const updatedData = state.updatedData;\n\n const isDeleted = state.rowStatus[dataRowIndex] == TableElementStatus.DELETED;\n\n const row = data[dataRowIndex] ?? updatedData[dataRowIndex];\n const loading = row == null;\n const col = columnSpec;\n\n const _topLeftCell = state.topLeftCell;\n const onCellEdited = state.onCellEdited;\n\n const value: T | undefined =\n updatedData[dataRowIndex]?.[col.key] ?? data[dataRowIndex]?.[col.key];\n const isEmpty = value == null || value === \"\";\n\n const edited =\n updatedData[dataRowIndex]?.[col.key] != null ||\n state.rowStatus[dataRowIndex] === TableElementStatus.ADDED;\n\n // Validate the cell (skipped for deleted rows). Orthogonal to edit status.\n const validation = isDeleted ? null : validateCell(col, value, row, dataRowIndex);\n\n // Context passed to custom renderers so they can render based on the\n // row/column position and cell status (and, with the editing API, write\n // edits back). `rowIndex` is the data-row index, stable under sort/filter.\n const cellContext: CellRenderContext<T> = {\n value,\n rowIndex: dataRowIndex,\n colIndex,\n column: col,\n row,\n isEdited: edited,\n isDeleted,\n validation,\n };\n\n const _renderedValue = isEmpty\n ? null\n : (col.valueRenderer?.(value, cellContext) ?? value);\n\n // Clone so we never mutate the caller's column-spec style object\n let style = { ...(col.style ?? {}) };\n\n if (isDeleted) {\n style.opacity = 0.5;\n style.textDecoration = \"line-through\";\n }\n\n const editable = (col.editable ?? state.editable) && !isDeleted;\n\n // topLeftCell stores visible row indices, so compare with the visible rowIndex\n const topLeft =\n _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;\n\n const tableIsEditable = state.editable;\n\n // Intent precedence: error > warning > deleted > edited. Validation state\n // overrides the edited-green so an edited-but-invalid cell reads as invalid.\n let intent: string | undefined;\n if (validation?.severity === \"error\") {\n intent = \"danger\";\n } else if (validation?.severity === \"warning\") {\n intent = \"warning\";\n } else if (isDeleted) {\n intent = \"danger\";\n } else if (edited) {\n intent = \"success\";\n }\n\n const _Cell = col.cellComponent ?? Cell;\n\n // Only forward the render context to a custom cell component; the default\n // Blueprint Cell would spread unknown props onto the DOM.\n const cellComponentProps =\n col.cellComponent != null ? { cellContext } : {};\n\n // Allow a column to pick the editor per-cell (e.g. textarea only when the\n // value is long). A returned key overrides the static column field even\n // when its value is false/null, so use `in` rather than nullish-coalesce.\n const perCellEditors = col.editorForCell?.(cellContext);\n const dataEditorSpec =\n perCellEditors != null && \"dataEditor\" in perCellEditors\n ? perCellEditors.dataEditor\n : col.dataEditor;\n const inlineEditorSpec =\n perCellEditors != null && \"inlineEditor\" in perCellEditors\n ? perCellEditors.inlineEditor\n : col.inlineEditor;\n\n let inlineEditor = editable ? (inlineEditorSpec ?? true) : false;\n\n // Build the detail context for the unified `cellDetail` surface.\n const makeDetailCtx = (editableFlag: boolean): CellDetailContext<T> => ({\n ...cellContext,\n editable: editableFlag,\n onChange(v: any) {\n if (editableFlag) onCellEdited(dataRowIndex, col.key, v);\n },\n resetValue() {\n state.resetChanges();\n },\n close() {\n state.closeCellSurface();\n state.tableElement?.focus?.();\n },\n });\n const detailPresentation =\n col.cellDetail != null ? (col.detailPresentation ?? \"popover\") : null;\n\n if (!topLeft) {\n // An inline surface is a persistent in-cell renderer, so it draws on every\n // cell (read-only when not the focused/editing cell).\n if (detailPresentation === \"inline\") {\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n col.cellDetail!(makeDetailCtx(false)),\n );\n }\n return h(\n _Cell,\n {\n intent,\n loading,\n value,\n style,\n disabled: tableIsEditable && !editable,\n interactive: false,\n ...cellComponentProps,\n },\n _renderedValue,\n );\n }\n\n // The rest is for the top-left cell of a selection or the focused cell\n\n // Unified cell surface: one renderer that acts as editor (when editable) or\n // viewer (otherwise), presented as a popover / modal / inline. Supersedes\n // dataEditor / detailRenderer / editorForCell.\n if (col.cellDetail != null) {\n const content = col.cellDetail(makeDetailCtx(editable));\n\n if (detailPresentation === \"inline\") {\n // Persistent in-cell surface (editable on the focused cell). No popover.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: editable ? \"input-cell\" : \"value-viewer-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n content,\n );\n }\n\n if (detailPresentation === \"modal\") {\n // CellDetailModal subscribes to the store so the dialog closes reactively.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n h(\n CellDetailModal,\n { title: col.name, valueViewer: _renderedValue },\n content,\n ),\n );\n }\n\n // Default: popover (same open/close machinery as editors and panels).\n const panel = h(EditorPopup, { valueViewer: _renderedValue }, content);\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"editor-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n // Read-only detail panel: a surface that opens on selection (auto) or click,\n // shows arbitrary content, and never takes keyboard focus — so arrow keys\n // keep navigating the table. Uses the same open/close machinery as editors.\n if (col.detailRenderer != null) {\n const panel = h(\n EditorPopup,\n { valueViewer: _renderedValue },\n col.detailRenderer(cellContext),\n );\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n // Use the editor-cell popover layout so the target fills the cell\n // without the double-padding offset of `value-viewer-cell`.\n className: \"editor-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n let cellContents: ReactNode = _renderedValue;\n\n let _dataEditor = null;\n let className = null;\n\n if (dataEditorSpec != null) {\n _dataEditor = h(\n EditorPopup,\n {\n valueViewer: _renderedValue,\n },\n [\n h(dataEditorSpec, {\n value,\n editable,\n isEdited: edited,\n onChange(value) {\n if (!editable) return;\n state.onSelectionEdited(value);\n },\n resetValue() {\n state.resetChanges();\n },\n }),\n ],\n );\n }\n\n if (!editable) {\n if (_dataEditor != null) {\n cellContents = _dataEditor;\n }\n const className = \"value-viewer-cell\";\n\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className,\n interactive: false,\n ...cellComponentProps,\n },\n cellContents,\n );\n }\n\n /* The remaining logic covers cells that are focused and editable */\n\n const onChange = (e) => {\n if (!editable) return;\n if (_renderedValue === e.target.value) return;\n // Use dataRowIndex for the actual data mutation\n onCellEdited(dataRowIndex, col.key, e.target.value);\n };\n\n const isSingleCellSelection = singleFocusedCell(state.selection) != null;\n\n let _inlineEditor: ReactNode = null;\n if (typeof inlineEditor == \"boolean\") {\n let _value = value;\n if (\n typeof _renderedValue === \"string\" ||\n typeof _renderedValue === \"number\" ||\n _renderedValue == null\n ) {\n _value = _renderedValue;\n }\n _inlineEditor = h(EditorInput, {\n className: \"main-editor\",\n value: _value ?? \"\",\n autoFocus: focusOnOpen,\n onChange,\n });\n } else {\n // If inlineEditor is a ReactNode, we use it directly\n _inlineEditor = inlineEditor as ReactNode;\n }\n\n let hiddenInput: React.ReactNode = h(EditorInput, {\n className: \"hidden-input\",\n autoFocus: true,\n });\n\n if (_dataEditor != null) {\n className = \"editor-cell\";\n cellContents = _dataEditor;\n hiddenInput = null;\n } else if (_inlineEditor != null) {\n cellContents = _inlineEditor;\n className = \"input-cell\";\n hiddenInput = null;\n }\n\n // Hidden html input\n return h(\n _Cell,\n {\n intent,\n value,\n className,\n style,\n interactive: true,\n ...cellComponentProps,\n //truncated: false,\n },\n [\n cellContents,\n h.if(editable && isSingleCellSelection)(DragHandle),\n //hiddenInput,\n ],\n );\n}\n\nfunction EditorInput(props) {\n const { value, onChange, ...rest } = props;\n const onKeyDown = ctx.useValue(editorKeyHandlerAtom);\n const navDirection = useSelector((s) => s.lastNavDirection);\n const surfaceOpen = useSelector((s) => s.cellSurfaceOpen);\n const inputRef = useRef<HTMLInputElement>(null);\n const [_value, setValue] = useState(value);\n useEffect(() => {\n setValue(value);\n }, [value]);\n useEffect(() => {\n // Focus when the cell's surface is open (on mount, and when reopened via\n // click/F2 while already mounted), placing the cursor on the side we're\n // travelling toward so another arrow in that direction leaves the cell.\n const el = inputRef.current;\n if (el == null || !surfaceOpen) return;\n el.focus();\n const atStart = navDirection === \"up\" || navDirection === \"left\";\n const pos = atStart ? 0 : (el.value?.length ?? 0);\n el.setSelectionRange(pos, pos);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [surfaceOpen]);\n return h(\"input\", {\n ref: inputRef,\n onKeyDown,\n onBlur: onChange,\n value: _value ?? value,\n onChange: (e) => setValue(e.target.value),\n ...rest,\n });\n}\n\nfunction DragHandle() {\n // TODO: we might want to drag multiple columns in some cases\n // This should be on the last cell of a selection\n const onMouseDown = useSelector((state) => state.onDragValue);\n return h(\"div.corner-drag-handle\", { onMouseDown });\n}\n"],"names":["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DetailContext,\n editorKeyHandlerAtom,\n validateCell,\n} from \"./utils\";\nimport { DataSheetStore, TableElementStatus } from \"./types.ts\";\nimport h from \"./main.module.sass\";\nimport { ReactNode, useEffect, useRef, useState } from \"react\";\nimport { EditorPopup, CellDetailModal } from \"./components\";\nimport { singleFocusedCell } from \"./zustand-store.ts\";\nimport { Cell } from \"@blueprintjs/table\";\nimport { ctx, useSelector } from \"./provider.ts\";\n\nexport function basicCellRenderer<T>(\n rowIndex: number,\n colIndex: number,\n columnSpec: ColumnSpec,\n state: DataSheetStore<T>,\n filteredRowIndices?: number[] | null,\n): any {\n // Auto-activation is on when the mode is \"auto\" and it hasn't been suppressed\n // (Escape enters navigation mode until the next click).\n // Whether the inline editor grabs focus. It follows the store-owned surface\n // open state, so it focuses on selection in auto mode and on click in manual\n // mode, and not at all in navigation mode. The popover surfaces read the\n // same state directly.\n const focusOnOpen = state.cellSurfaceOpen;\n // When filters are active, `rowIndex` is the visible row position.\n // Map it to the actual data index for data access.\n const dataRowIndex =\n filteredRowIndices != null\n ? (filteredRowIndices[rowIndex] ?? rowIndex)\n : rowIndex;\n\n const data = state.data;\n const updatedData = state.updatedData;\n\n const statusVal = state.rowStatus[dataRowIndex];\n const isDeleted = statusVal == TableElementStatus.DELETED;\n // Presentation for this row's status (deleted, or a consumer-defined status\n // like \"omitted\"), from the merged `rowStatusStyles`.\n const statusStyle = statusVal != null ? state.rowStatusStyles?.[statusVal] : undefined;\n\n const row = data[dataRowIndex] ?? updatedData[dataRowIndex];\n const loading = row == null;\n const col = columnSpec;\n\n const _topLeftCell = state.topLeftCell;\n const onCellEdited = state.onCellEdited;\n\n const value: T | undefined =\n updatedData[dataRowIndex]?.[col.key] ?? data[dataRowIndex]?.[col.key];\n const isEmpty = value == null || value === \"\";\n\n const edited =\n updatedData[dataRowIndex]?.[col.key] != null ||\n state.rowStatus[dataRowIndex] === TableElementStatus.ADDED;\n\n // Validate the cell (skipped for deleted rows). Orthogonal to edit status.\n const validation = isDeleted ? null : validateCell(col, value, row, dataRowIndex);\n\n // Context passed to custom renderers so they can render based on the\n // row/column position and cell status (and, with the editing API, write\n // edits back). `rowIndex` is the data-row index, stable under sort/filter.\n const cellContext: CellRenderContext<T> = {\n value,\n rowIndex: dataRowIndex,\n colIndex,\n column: col,\n row,\n isEdited: edited,\n isDeleted,\n status: statusVal,\n validation,\n };\n\n const _renderedValue = isEmpty\n ? null\n : (col.valueRenderer?.(value, cellContext) ?? value);\n\n // Clone so we never mutate the caller's column-spec style object, then layer\n // the row-status presentation (deleted → dimmed/struck-through by default;\n // consumer statuses supply their own `cellStyle`).\n let style = { ...(col.style ?? {}) };\n\n if (statusStyle?.cellStyle != null) {\n style = { ...style, ...statusStyle.cellStyle };\n }\n\n const editable = (col.editable ?? state.editable) && !isDeleted;\n\n // topLeftCell stores visible row indices, so compare with the visible rowIndex\n const topLeft =\n _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;\n\n const tableIsEditable = state.editable;\n\n // Intent precedence: error > warning > row-status intent > edited. Validation\n // state overrides the edited-green so an edited-but-invalid cell reads as\n // invalid. A row's status intent (e.g. deleted → danger) outranks the\n // edited-green so status reads through even on an edited row.\n let intent: string | undefined;\n if (validation?.severity === \"error\") {\n intent = \"danger\";\n } else if (validation?.severity === \"warning\") {\n intent = \"warning\";\n } else if (statusStyle?.intent != null) {\n intent = statusStyle.intent;\n } else if (edited) {\n intent = \"success\";\n }\n\n const _Cell = col.cellComponent ?? Cell;\n\n // Only forward the render context to a custom cell component; the default\n // Blueprint Cell would spread unknown props onto the DOM.\n const cellComponentProps =\n col.cellComponent != null ? { cellContext } : {};\n\n // Allow a column to pick the editor per-cell (e.g. textarea only when the\n // value is long). A returned key overrides the static column field even\n // when its value is false/null, so use `in` rather than nullish-coalesce.\n const perCellEditors = col.editorForCell?.(cellContext);\n const dataEditorSpec =\n perCellEditors != null && \"dataEditor\" in perCellEditors\n ? perCellEditors.dataEditor\n : col.dataEditor;\n const inlineEditorSpec =\n perCellEditors != null && \"inlineEditor\" in perCellEditors\n ? perCellEditors.inlineEditor\n : col.inlineEditor;\n\n let inlineEditor = editable ? (inlineEditorSpec ?? true) : false;\n\n // Build the detail context for the unified `cellDetail` surface.\n const makeDetailCtx = (editableFlag: boolean): CellDetailContext<T> => ({\n ...cellContext,\n editable: editableFlag,\n onChange(v: any) {\n if (editableFlag) onCellEdited(dataRowIndex, col.key, v);\n },\n resetValue() {\n state.resetChanges();\n },\n close() {\n state.closeCellSurface();\n state.tableElement?.focus?.();\n },\n });\n const detailPresentation =\n col.cellDetail != null ? (col.detailPresentation ?? \"popover\") : null;\n\n if (!topLeft) {\n // An inline surface is a persistent in-cell renderer, so it draws on every\n // cell (read-only when not the focused/editing cell).\n if (detailPresentation === \"inline\") {\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n col.cellDetail!(makeDetailCtx(false)),\n );\n }\n return h(\n _Cell,\n {\n intent,\n loading,\n value,\n style,\n disabled: tableIsEditable && !editable,\n interactive: false,\n ...cellComponentProps,\n },\n _renderedValue,\n );\n }\n\n // The rest is for the top-left cell of a selection or the focused cell\n\n // Unified cell surface: one renderer that acts as editor (when editable) or\n // viewer (otherwise), presented as a popover / modal / inline. Supersedes\n // dataEditor / detailRenderer / editorForCell.\n if (col.cellDetail != null) {\n const content = col.cellDetail(makeDetailCtx(editable));\n\n if (detailPresentation === \"inline\") {\n // Persistent in-cell surface (editable on the focused cell). No popover.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: editable ? \"input-cell\" : \"value-viewer-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n content,\n );\n }\n\n if (detailPresentation === \"modal\") {\n // CellDetailModal subscribes to the store so the dialog closes reactively.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n h(\n CellDetailModal,\n { title: col.name, valueViewer: _renderedValue },\n content,\n ),\n );\n }\n\n // Default: popover (same open/close machinery as editors and panels).\n const panel = h(EditorPopup, { valueViewer: _renderedValue }, content);\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"editor-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n // Read-only detail panel: a surface that opens on selection (auto) or click,\n // shows arbitrary content, and never takes keyboard focus — so arrow keys\n // keep navigating the table. Uses the same open/close machinery as editors.\n if (col.detailRenderer != null) {\n const panel = h(\n EditorPopup,\n { valueViewer: _renderedValue },\n col.detailRenderer(cellContext),\n );\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n // Use the editor-cell popover layout so the target fills the cell\n // without the double-padding offset of `value-viewer-cell`.\n className: \"editor-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n let cellContents: ReactNode = _renderedValue;\n\n let _dataEditor = null;\n let className = null;\n\n if (dataEditorSpec != null) {\n _dataEditor = h(\n EditorPopup,\n {\n valueViewer: _renderedValue,\n },\n [\n h(dataEditorSpec, {\n value,\n editable,\n isEdited: edited,\n onChange(value) {\n if (!editable) return;\n // Commit to THIS cell — not the live selection. The editor can\n // commit (e.g. on blur) after the selection has moved to another\n // cell or a whole column; `onSelectionEdited` would then write the\n // value to the wrong target (emptying it). `onCellEdited` addresses\n // the editor's own data cell.\n state.onCellEdited(dataRowIndex, col.key, value);\n },\n resetValue() {\n state.resetChanges();\n },\n }),\n ],\n );\n }\n\n if (!editable) {\n if (_dataEditor != null) {\n cellContents = _dataEditor;\n }\n const className = \"value-viewer-cell\";\n\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className,\n interactive: false,\n ...cellComponentProps,\n },\n cellContents,\n );\n }\n\n /* The remaining logic covers cells that are focused and editable */\n\n const onChange = (e) => {\n if (!editable) return;\n if (_renderedValue === e.target.value) return;\n // Use dataRowIndex for the actual data mutation\n onCellEdited(dataRowIndex, col.key, e.target.value);\n };\n\n const isSingleCellSelection = singleFocusedCell(state.selection) != null;\n\n let _inlineEditor: ReactNode = null;\n if (typeof inlineEditor == \"boolean\") {\n let _value = value;\n if (\n typeof _renderedValue === \"string\" ||\n typeof _renderedValue === \"number\" ||\n _renderedValue == null\n ) {\n _value = _renderedValue;\n }\n _inlineEditor = h(EditorInput, {\n className: \"main-editor\",\n value: _value ?? \"\",\n autoFocus: focusOnOpen,\n onChange,\n });\n } else {\n // If inlineEditor is a ReactNode, we use it directly\n _inlineEditor = inlineEditor as ReactNode;\n }\n\n let hiddenInput: React.ReactNode = h(EditorInput, {\n className: \"hidden-input\",\n autoFocus: true,\n });\n\n if (_dataEditor != null) {\n className = \"editor-cell\";\n cellContents = _dataEditor;\n hiddenInput = null;\n } else if (_inlineEditor != null) {\n cellContents = _inlineEditor;\n className = \"input-cell\";\n hiddenInput = null;\n }\n\n // Hidden html input\n return h(\n _Cell,\n {\n intent,\n value,\n className,\n style,\n interactive: true,\n ...cellComponentProps,\n //truncated: false,\n },\n [\n cellContents,\n h.if(editable && isSingleCellSelection)(DragHandle),\n //hiddenInput,\n ],\n );\n}\n\nfunction EditorInput(props) {\n const { value, onChange, ...rest } = props;\n const onKeyDown = ctx.useValue(editorKeyHandlerAtom);\n const navDirection = useSelector((s) => s.lastNavDirection);\n const surfaceOpen = useSelector((s) => s.cellSurfaceOpen);\n const inputRef = useRef<HTMLInputElement>(null);\n const [_value, setValue] = useState(value);\n useEffect(() => {\n setValue(value);\n }, [value]);\n useEffect(() => {\n // Focus when the cell's surface is open (on mount, and when reopened via\n // click/F2 while already mounted), placing the cursor on the side we're\n // travelling toward so another arrow in that direction leaves the cell.\n const el = inputRef.current;\n if (el == null || !surfaceOpen) return;\n el.focus();\n const atStart = navDirection === \"up\" || navDirection === \"left\";\n const pos = atStart ? 0 : (el.value?.length ?? 0);\n el.setSelectionRange(pos, pos);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [surfaceOpen]);\n return h(\"input\", {\n ref: inputRef,\n onKeyDown,\n onBlur: onChange,\n value: _value ?? value,\n onChange: (e) => setValue(e.target.value),\n ...rest,\n });\n}\n\nfunction DragHandle() {\n // TODO: we might want to drag multiple columns in some cases\n // This should be on the last cell of a selection\n const onMouseDown = useSelector((state) => state.onDragValue);\n return h(\"div.corner-drag-handle\", { onMouseDown });\n}\n"],"names":["value","className"],"mappings":";;;;;;;;;;AAeO,SAAS,kBACd,UACA,UACA,YACA,OACA,oBACK;AAOL,QAAM,cAAc,MAAM;AAG1B,QAAM,eACJ,sBAAsB,OACjB,mBAAmB,QAAQ,KAAK,WACjC;AAEN,QAAM,OAAO,MAAM;AACnB,QAAM,cAAc,MAAM;AAE1B,QAAM,YAAY,MAAM,UAAU,YAAY;AAC9C,QAAM,YAAY,aAAa,mBAAmB;AAGlD,QAAM,cAAc,aAAa,OAAO,MAAM,kBAAkB,SAAS,IAAI;AAE7E,QAAM,MAAM,KAAK,YAAY,KAAK,YAAY,YAAY;AAC1D,QAAM,UAAU,OAAO;AACvB,QAAM,MAAM;AAEZ,QAAM,eAAe,MAAM;AAC3B,QAAM,eAAe,MAAM;AAE3B,QAAM,QACJ,YAAY,YAAY,IAAI,IAAI,GAAG,KAAK,KAAK,YAAY,IAAI,IAAI,GAAG;AACtE,QAAM,UAAU,SAAS,QAAQ,UAAU;AAE3C,QAAM,SACJ,YAAY,YAAY,IAAI,IAAI,GAAG,KAAK,QACxC,MAAM,UAAU,YAAY,MAAM,mBAAmB;AAGvD,QAAM,aAAa,YAAY,OAAO,aAAa,KAAK,OAAO,KAAK,YAAY;AAKhF,QAAM,cAAoC;AAAA,IACxC;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,EAAA;AAGF,QAAM,iBAAiB,UACnB,OACC,IAAI,gBAAgB,OAAO,WAAW,KAAK;AAKhD,MAAI,QAAQ,EAAE,GAAI,IAAI,SAAS,CAAA,EAAC;AAEhC,MAAI,aAAa,aAAa,MAAM;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ACR,OAAO,UAAU;AAAA,IACjB,UAAU,CAAC,MAAM,SAAS,EAAE,OAAO,KAAK;AAAA,IACxC,GAAG;AAAA,EAAA,CACJ;AACH;AAEA,SAAS,aAAa;AAGpB,QAAM,cAAc,YAAY,CAAC,UAAU,MAAM,WAAW;AAC5D,SAAO,EAAE,0BAA0B,EAAE,aAAa;AACpD;"}
|
package/dist/core.cjs
CHANGED
|
@@ -54,6 +54,7 @@ function DataSheet(props) {
|
|
|
54
54
|
main_module.default(_DataSheet, {
|
|
55
55
|
...rest,
|
|
56
56
|
data: data ?? emptyData,
|
|
57
|
+
columnSpec,
|
|
57
58
|
children,
|
|
58
59
|
editable,
|
|
59
60
|
enableColumnReordering,
|
|
@@ -61,10 +62,6 @@ function DataSheet(props) {
|
|
|
61
62
|
})
|
|
62
63
|
);
|
|
63
64
|
}
|
|
64
|
-
const deletedRowHeaderStyle = {
|
|
65
|
-
opacity: 0.5,
|
|
66
|
-
textDecoration: "line-through"
|
|
67
|
-
};
|
|
68
65
|
async function persistViaProvider(provider2, ctx2) {
|
|
69
66
|
const base = ctx2.data ?? [];
|
|
70
67
|
const updates = ctx2.updatedData ?? [];
|
|
@@ -110,6 +107,8 @@ function _DataSheet({
|
|
|
110
107
|
updatedData: updatedDataProp,
|
|
111
108
|
rowStatus: rowStatusProp,
|
|
112
109
|
identity,
|
|
110
|
+
deriveOverlay,
|
|
111
|
+
refreshToken,
|
|
113
112
|
onDeleteRows,
|
|
114
113
|
name,
|
|
115
114
|
verbose = false,
|
|
@@ -122,6 +121,10 @@ function _DataSheet({
|
|
|
122
121
|
actions,
|
|
123
122
|
filters: filters$1,
|
|
124
123
|
columnHeaderCellRenderer,
|
|
124
|
+
columnSpec: columnSpecProp,
|
|
125
|
+
statusBar,
|
|
126
|
+
rowStatusStyles,
|
|
127
|
+
rowHeaderRenderer,
|
|
125
128
|
children,
|
|
126
129
|
...rest
|
|
127
130
|
}) {
|
|
@@ -236,12 +239,39 @@ function _DataSheet({
|
|
|
236
239
|
storeState.setState({ onEdit });
|
|
237
240
|
}, [storeState, onEdit]);
|
|
238
241
|
react.useEffect(() => {
|
|
239
|
-
const controlled = updatedDataProp !== void 0 || rowStatusProp !== void 0;
|
|
242
|
+
const controlled = updatedDataProp !== void 0 || rowStatusProp !== void 0 || deriveOverlay != null;
|
|
240
243
|
const patch = { controlledOverlay: controlled };
|
|
241
244
|
if (updatedDataProp !== void 0) patch.updatedData = updatedDataProp;
|
|
242
245
|
if (rowStatusProp !== void 0) patch.rowStatus = rowStatusProp;
|
|
243
246
|
storeState.setState(patch);
|
|
244
|
-
}, [storeState, updatedDataProp, rowStatusProp]);
|
|
247
|
+
}, [storeState, updatedDataProp, rowStatusProp, deriveOverlay]);
|
|
248
|
+
const loadedData = provider.useSelector((state) => state.data);
|
|
249
|
+
react.useEffect(() => {
|
|
250
|
+
if (deriveOverlay == null) return;
|
|
251
|
+
const overlay = deriveOverlay(loadedData);
|
|
252
|
+
storeState.setState({
|
|
253
|
+
updatedData: overlay.updatedData,
|
|
254
|
+
rowStatus: overlay.rowStatus
|
|
255
|
+
});
|
|
256
|
+
}, [deriveOverlay, loadedData, storeState]);
|
|
257
|
+
const derivedSpecFor = react.useRef(null);
|
|
258
|
+
react.useEffect(() => {
|
|
259
|
+
if (typeof columnSpecProp !== "function") return;
|
|
260
|
+
if (derivedSpecFor.current === columnSpecProp) return;
|
|
261
|
+
const rows = loadedData.filter((r) => r != null);
|
|
262
|
+
if (rows.length === 0) return;
|
|
263
|
+
derivedSpecFor.current = columnSpecProp;
|
|
264
|
+
storeState.setState({ columnSpec: columnSpecProp(rows) });
|
|
265
|
+
}, [columnSpecProp, loadedData, storeState]);
|
|
266
|
+
const bumpRefreshFromToken = provider.ctx.useSet(dataLoaders.dataRefreshTokenAtom);
|
|
267
|
+
const firstRefreshToken = react.useRef(true);
|
|
268
|
+
react.useEffect(() => {
|
|
269
|
+
if (firstRefreshToken.current) {
|
|
270
|
+
firstRefreshToken.current = false;
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
bumpRefreshFromToken((v) => v + 1);
|
|
274
|
+
}, [refreshToken, bumpRefreshFromToken]);
|
|
245
275
|
react.useEffect(() => {
|
|
246
276
|
const id = activeProvider?.identity ?? identity;
|
|
247
277
|
if (id != null) storeState.setState({ identity: id });
|
|
@@ -250,6 +280,13 @@ function _DataSheet({
|
|
|
250
280
|
const canDeleteRows = provider$1 == null || provider$1.deleteRows != null;
|
|
251
281
|
storeState.setState({ canDeleteRows });
|
|
252
282
|
}, [storeState, provider$1]);
|
|
283
|
+
const mergedRowStatusStyles = react.useMemo(
|
|
284
|
+
() => ({ ...types.DEFAULT_ROW_STATUS_STYLES, ...rowStatusStyles }),
|
|
285
|
+
[rowStatusStyles]
|
|
286
|
+
);
|
|
287
|
+
react.useEffect(() => {
|
|
288
|
+
storeState.setState({ rowStatusStyles: mergedRowStatusStyles });
|
|
289
|
+
}, [storeState, mergedRowStatusStyles]);
|
|
253
290
|
const realizedColumns = react.useMemo(() => {
|
|
254
291
|
return columnSpec.map((col, colIndex) => {
|
|
255
292
|
let fn = col.headerCellRenderer ?? columnHeaderCellRenderer ?? columnHeaderCell.renderColumnHeaderCell;
|
|
@@ -302,15 +339,36 @@ function _DataSheet({
|
|
|
302
339
|
const rowHeaderCellRenderer = react.useCallback(
|
|
303
340
|
(rowIndex) => {
|
|
304
341
|
const dataRowIndex = filteredRowIndices != null ? filteredRowIndices[rowIndex] ?? rowIndex : rowIndex;
|
|
305
|
-
const
|
|
342
|
+
const statusVal = rowStatus[dataRowIndex];
|
|
343
|
+
const style2 = (statusVal != null ? mergedRowStatusStyles[statusVal]?.headerStyle : null) ?? null;
|
|
344
|
+
const defaultLabel = `${dataRowIndex + 1}`;
|
|
345
|
+
let name2 = defaultLabel;
|
|
346
|
+
if (rowHeaderRenderer != null) {
|
|
347
|
+
const custom = rowHeaderRenderer({
|
|
348
|
+
rowIndex: dataRowIndex,
|
|
349
|
+
visibleIndex: rowIndex,
|
|
350
|
+
row: data[dataRowIndex] ?? updatedData[dataRowIndex],
|
|
351
|
+
status: statusVal,
|
|
352
|
+
isDeleted: statusVal === types.TableElementStatus.DELETED,
|
|
353
|
+
defaultLabel
|
|
354
|
+
});
|
|
355
|
+
if (custom != null) name2 = custom;
|
|
356
|
+
}
|
|
306
357
|
return main_module.default(table.RowHeaderCell, {
|
|
307
358
|
enableRowReordering: false,
|
|
308
359
|
index: rowIndex,
|
|
309
|
-
name:
|
|
360
|
+
name: name2,
|
|
310
361
|
style: style2
|
|
311
362
|
});
|
|
312
363
|
},
|
|
313
|
-
[
|
|
364
|
+
[
|
|
365
|
+
rowStatus,
|
|
366
|
+
filteredRowIndices,
|
|
367
|
+
mergedRowStatusStyles,
|
|
368
|
+
rowHeaderRenderer,
|
|
369
|
+
data,
|
|
370
|
+
updatedData
|
|
371
|
+
]
|
|
314
372
|
);
|
|
315
373
|
let _selectionModes = selectionModes;
|
|
316
374
|
if (editable && _selectionModes != null && !_selectionModes.includes(table.RegionCardinality.CELLS)) {
|
|
@@ -385,6 +443,7 @@ function _DataSheet({
|
|
|
385
443
|
),
|
|
386
444
|
main_module.default("div.status-bar", [
|
|
387
445
|
filterStatus,
|
|
446
|
+
statusBar,
|
|
388
447
|
main_module.default("div.spacer"),
|
|
389
448
|
main_module.default.if(_showLoadProgress)(viewInfo.LoadProgressIndicator)
|
|
390
449
|
]),
|