react-glide-table 1.7.0 → 2.0.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/dist/core.cjs CHANGED
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/core/index.ts
21
21
  var core_exports = {};
22
22
  __export(core_exports, {
23
+ BUILTIN_CELL_RENDERERS: () => BUILTIN_CELL_RENDERERS,
23
24
  CELL_SELECTION_EDGES_CLASS: () => CELL_SELECTION_EDGES_CLASS,
24
25
  DEFAULT_DATA_TABLE_LABELS: () => DEFAULT_DATA_TABLE_LABELS,
25
26
  DEFAULT_TREE_CHILDREN_FIELD: () => DEFAULT_TREE_CHILDREN_FIELD,
@@ -27,6 +28,7 @@ __export(core_exports, {
27
28
  DEFAULT_TREE_PARENT_ID_FIELD: () => DEFAULT_TREE_PARENT_ID_FIELD,
28
29
  DEFAULT_TREE_QTY_FIELD: () => DEFAULT_TREE_QTY_FIELD,
29
30
  INLINE_SEARCH_MAX_RESULTS: () => INLINE_SEARCH_MAX_RESULTS,
31
+ ResolvedTableCell: () => ResolvedTableCell,
30
32
  applyCellEdit: () => applyCellEdit,
31
33
  applyFillData: () => applyFillData,
32
34
  applySelectionUpdater: () => applySelectionUpdater,
@@ -45,9 +47,13 @@ __export(core_exports, {
45
47
  collectFillChanges: () => collectFillChanges,
46
48
  collectRowSpanColumns: () => collectRowSpanColumns,
47
49
  collectSearchMatchesInRange: () => collectSearchMatchesInRange,
50
+ commitCellValue: () => commitCellValue,
51
+ createCellRendererRegistry: () => createCellRendererRegistry,
48
52
  createSearchRegex: () => createSearchRegex,
49
53
  escapeSearchRegex: () => escapeSearchRegex,
50
54
  flattenSubtreeRows: () => flattenSubtreeRows,
55
+ formatCellValue: () => formatCellValue,
56
+ formatDefaultCellValue: () => formatDefaultCellValue,
51
57
  formatSearchResultLabel: () => formatSearchResultLabel,
52
58
  getCellEditDraftValue: () => getCellEditDraftValue,
53
59
  getCellSelectionEdgeStyle: () => getCellSelectionEdgeStyle,
@@ -69,8 +75,10 @@ __export(core_exports, {
69
75
  parseClipboardTSV: () => parseClipboardTSV,
70
76
  parseClipboardTSVWithDepths: () => parseClipboardTSVWithDepths,
71
77
  previousSearchIndex: () => previousSearchIndex,
78
+ resolveCellRenderer: () => resolveCellRenderer,
72
79
  resolveColumnFreezeSide: () => resolveColumnFreezeSide,
73
80
  resolveDataTableLabels: () => resolveDataTableLabels,
81
+ resolveHeaderFreezeOffset: () => resolveHeaderFreezeOffset,
74
82
  resolvePasteColumnIds: () => resolvePasteColumnIds,
75
83
  resolveRowSelection: () => resolveRowSelection,
76
84
  resolveRowSpanAt: () => resolveRowSpanAt,
@@ -175,6 +183,37 @@ function applyCellEdit(data, rows, rowIndex, colIndex, raw) {
175
183
  return newData;
176
184
  }
177
185
 
186
+ // src/components/ui/table/features/cell-render/commitCellValue.ts
187
+ function commitCellValue({
188
+ data,
189
+ rows,
190
+ rowId,
191
+ columnId,
192
+ value,
193
+ onCellChange,
194
+ onDataChange
195
+ }) {
196
+ if (!onCellChange && !onDataChange) return true;
197
+ if (onCellChange) {
198
+ onCellChange(rowId, columnId, value);
199
+ return true;
200
+ }
201
+ const row = rows.find((item) => item.id === rowId);
202
+ if (!row) return false;
203
+ const cell = row.getAllCells().find((item) => item.column.id === columnId) ?? row.getVisibleCells().find((item) => item.column.id === columnId);
204
+ if (!cell) return false;
205
+ const accessorKey = getColumnAccessorKey(cell.column.columnDef);
206
+ if (!accessorKey) return false;
207
+ const dataIndex = row.index;
208
+ if (dataIndex < 0 || dataIndex >= data.length) return false;
209
+ const next = data.map((item) => ({ ...item }));
210
+ const target = next[dataIndex];
211
+ if (!target) return false;
212
+ target[accessorKey] = value;
213
+ onDataChange?.(next);
214
+ return true;
215
+ }
216
+
178
217
  // src/components/ui/table/features/cell-edit/useCellEdit.ts
179
218
  function useCellEdit({
180
219
  data,
@@ -210,21 +249,23 @@ function useCellEdit({
210
249
  cancelEdit();
211
250
  return true;
212
251
  }
213
- const value = raw ?? draftValueRef.current;
214
252
  if (!isColumnEditable(cell.column.columnDef)) {
215
253
  cancelEdit();
216
254
  return true;
217
255
  }
256
+ const value = raw ?? draftValueRef.current;
218
257
  const parsed = parseCellEditValue(value, getColumnEditType(cell.column.columnDef));
219
258
  if (!parsed.ok) return false;
220
- if (onCellChange) {
221
- onCellChange(row.id, cell.column.id, parsed.value);
222
- cancelEdit();
223
- return true;
224
- }
225
- const next = applyCellEdit(data, rows, current.rowIndex, current.colIndex, value);
226
- if (!next) return false;
227
- onDataChange?.(next);
259
+ const committed = commitCellValue({
260
+ data,
261
+ rows,
262
+ rowId: row.id,
263
+ columnId: cell.column.id,
264
+ value: parsed.value,
265
+ onCellChange,
266
+ onDataChange
267
+ });
268
+ if (!committed) return false;
228
269
  cancelEdit();
229
270
  return true;
230
271
  },
@@ -253,6 +294,218 @@ function useCellEdit({
253
294
  };
254
295
  }
255
296
 
297
+ // src/components/ui/table/features/cell-render/builtins.tsx
298
+ var import_jsx_runtime = require("react/jsx-runtime");
299
+ function asString(value) {
300
+ if (value == null) return "";
301
+ return String(value);
302
+ }
303
+ function asStringList(value) {
304
+ if (Array.isArray(value)) {
305
+ return value.map((item) => asString(item)).filter(Boolean);
306
+ }
307
+ if (value == null || value === "") return [];
308
+ return [asString(value)];
309
+ }
310
+ function asDrilldownItems(value) {
311
+ if (!Array.isArray(value)) return [];
312
+ return value.flatMap((item) => {
313
+ if (item == null) return [];
314
+ if (typeof item === "string") return [{ text: item }];
315
+ if (typeof item === "object") {
316
+ const record = item;
317
+ const text = asString(record.text ?? record.label ?? "");
318
+ if (!text) return [];
319
+ const img = record.img ?? record.image;
320
+ return [{ text, ...typeof img === "string" ? { img } : {} }];
321
+ }
322
+ return [{ text: asString(item) }];
323
+ });
324
+ }
325
+ function escapeHtml(text) {
326
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
327
+ }
328
+ function simpleMarkdownToHtml(source) {
329
+ const escaped = escapeHtml(source);
330
+ return escaped.replace(/`([^`]+)`/g, "<code>$1</code>").replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>").replace(/\*([^*]+)\*/g, "<em>$1</em>").replace(/\n/g, "<br />");
331
+ }
332
+ function TextCell({ value }) {
333
+ return asString(value);
334
+ }
335
+ function NumberCell({ value }) {
336
+ if (value == null || value === "") return null;
337
+ return asString(value);
338
+ }
339
+ function BooleanCell({ value, update, cellProps }) {
340
+ const checked = Boolean(value);
341
+ const readonly = Boolean(cellProps?.readonly);
342
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
343
+ "input",
344
+ {
345
+ type: "checkbox",
346
+ className: "data-table-cell-boolean",
347
+ checked,
348
+ disabled: readonly,
349
+ "aria-checked": checked,
350
+ onChange: (event) => {
351
+ if (readonly) return;
352
+ update(event.target.checked);
353
+ },
354
+ onClick: (event) => {
355
+ event.stopPropagation();
356
+ },
357
+ onMouseDown: (event) => {
358
+ event.stopPropagation();
359
+ }
360
+ }
361
+ );
362
+ }
363
+ function sanitizeUriHref(raw) {
364
+ const href = raw.trim();
365
+ if (!href) return null;
366
+ if (href.startsWith("/") || href.startsWith("#") || href.startsWith("?") || href.startsWith("./") || href.startsWith("../")) {
367
+ return href;
368
+ }
369
+ try {
370
+ const parsed = new URL(href);
371
+ const protocol = parsed.protocol.toLowerCase();
372
+ if (protocol === "http:" || protocol === "https:" || protocol === "mailto:") {
373
+ return href;
374
+ }
375
+ return null;
376
+ } catch {
377
+ if (/^[a-z][a-z0-9+.-]*:/i.test(href)) return null;
378
+ return href;
379
+ }
380
+ }
381
+ function UriCell({ value }) {
382
+ const raw = asString(value);
383
+ if (!raw) return null;
384
+ const href = sanitizeUriHref(raw);
385
+ if (!href) {
386
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-uri", children: raw });
387
+ }
388
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
389
+ "a",
390
+ {
391
+ className: "data-table-cell-uri",
392
+ href,
393
+ target: "_blank",
394
+ rel: "noopener noreferrer",
395
+ onClick: (event) => event.stopPropagation(),
396
+ onMouseDown: (event) => event.stopPropagation(),
397
+ children: raw
398
+ }
399
+ );
400
+ }
401
+ function ImageCell({ value }) {
402
+ const urls = asStringList(value);
403
+ if (urls.length === 0) return null;
404
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-image", children: urls.map((url, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
405
+ "img",
406
+ {
407
+ src: url,
408
+ alt: "",
409
+ className: "data-table-cell-image-item"
410
+ },
411
+ `${index}:${url}`
412
+ )) });
413
+ }
414
+ function BubbleCell({ value }) {
415
+ const items = asStringList(value);
416
+ if (items.length === 0) return null;
417
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-bubble", children: items.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-bubble-item", children: item }, `${index}:${item}`)) });
418
+ }
419
+ function MarkdownCell({ value }) {
420
+ const source = asString(value);
421
+ if (!source) return null;
422
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
423
+ "span",
424
+ {
425
+ className: "data-table-cell-markdown",
426
+ dangerouslySetInnerHTML: { __html: simpleMarkdownToHtml(source) }
427
+ }
428
+ );
429
+ }
430
+ function DrilldownCell({ value }) {
431
+ const items = asDrilldownItems(value);
432
+ if (items.length === 0) return null;
433
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-drilldown", children: items.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
434
+ "span",
435
+ {
436
+ className: "data-table-cell-drilldown-item",
437
+ children: [
438
+ item.img ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
439
+ "img",
440
+ {
441
+ src: item.img,
442
+ alt: "",
443
+ className: "data-table-cell-drilldown-image"
444
+ }
445
+ ) : null,
446
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-drilldown-text", children: item.text })
447
+ ]
448
+ },
449
+ `${index}:${item.text}:${item.img ?? ""}`
450
+ )) });
451
+ }
452
+ function LoadingCell() {
453
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-loading", "aria-busy": "true" });
454
+ }
455
+ function ProtectedCell() {
456
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-protected", "aria-label": "protected", children: "****" });
457
+ }
458
+ function RowIdCell({ value }) {
459
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-row-id", children: asString(value) });
460
+ }
461
+ var BUILTIN_RENDER_MAP = {
462
+ text: TextCell,
463
+ number: NumberCell,
464
+ boolean: BooleanCell,
465
+ uri: UriCell,
466
+ image: ImageCell,
467
+ bubble: BubbleCell,
468
+ markdown: MarkdownCell,
469
+ drilldown: DrilldownCell,
470
+ loading: LoadingCell,
471
+ protected: ProtectedCell,
472
+ "row-id": RowIdCell
473
+ };
474
+ var BUILTIN_CELL_RENDERERS = Object.keys(BUILTIN_RENDER_MAP).map((kind) => ({
475
+ kind,
476
+ render: BUILTIN_RENDER_MAP[kind]
477
+ }));
478
+
479
+ // src/components/ui/table/features/cell-render/registry.ts
480
+ function createCellRendererRegistry(customRenderers = []) {
481
+ const registry = /* @__PURE__ */ new Map();
482
+ for (const renderer of BUILTIN_CELL_RENDERERS) {
483
+ registry.set(renderer.kind, renderer);
484
+ }
485
+ for (const renderer of customRenderers) {
486
+ registry.set(renderer.kind, renderer);
487
+ }
488
+ return registry;
489
+ }
490
+ function resolveCellRenderer(registry, kind, ctx) {
491
+ if (!kind) return void 0;
492
+ const renderer = registry.get(kind);
493
+ if (!renderer) return void 0;
494
+ if (renderer.isMatch && !renderer.isMatch(ctx)) {
495
+ return void 0;
496
+ }
497
+ return renderer;
498
+ }
499
+ function formatDefaultCellValue(value) {
500
+ if (value == null) return null;
501
+ if (typeof value === "string") return value;
502
+ if (typeof value === "number" || typeof value === "boolean") {
503
+ return String(value);
504
+ }
505
+ if (typeof value === "bigint") return value.toString();
506
+ return String(value);
507
+ }
508
+
256
509
  // src/components/ui/table/features/cell-selection/useCellSelection.ts
257
510
  var import_react2 = require("react");
258
511
 
@@ -562,9 +815,34 @@ function hasCellSelectionEdges(style) {
562
815
  }
563
816
 
564
817
  // src/components/ui/table/features/cell-selection/copyData.ts
818
+ function formatPrimitive(value) {
819
+ if (value === null || value === void 0) return "";
820
+ if (typeof value === "string") return value;
821
+ if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
822
+ return String(value);
823
+ }
824
+ return "";
825
+ }
826
+ function formatObjectValue(value) {
827
+ const text = value.text ?? value.label ?? value.name ?? value.title;
828
+ if (text != null && text !== "") {
829
+ return formatCellValue(text);
830
+ }
831
+ try {
832
+ return JSON.stringify(value);
833
+ } catch {
834
+ return "";
835
+ }
836
+ }
565
837
  function formatCellValue(value) {
566
838
  if (value === null || value === void 0) return "";
567
- return String(value);
839
+ if (Array.isArray(value)) {
840
+ return value.map((item) => formatCellValue(item)).filter((item) => item.length > 0).join(", ");
841
+ }
842
+ if (typeof value === "object") {
843
+ return formatObjectValue(value);
844
+ }
845
+ return formatPrimitive(value);
568
846
  }
569
847
  function getNestedValue(row, path) {
570
848
  if (!path.includes(".")) return row[path];
@@ -1188,10 +1466,40 @@ function getColumnFreezeStyle(offset, options) {
1188
1466
  return {
1189
1467
  position: "sticky",
1190
1468
  ...offset.side === "left" ? { left: offset.offset } : { right: offset.offset },
1191
- zIndex: zBase + offset.stack,
1192
- ...options?.isHeader ? { top: options.headerTop ?? 0 } : {}
1469
+ zIndex: zBase + offset.stack
1193
1470
  };
1194
1471
  }
1472
+ function resolveHeaderFreezeOffset(column, freezeOffsets) {
1473
+ const direct = freezeOffsets.get(column.id);
1474
+ if (direct) return direct;
1475
+ const leaves = typeof column.getLeafColumns === "function" ? column.getLeafColumns() : column.columns && column.columns.length > 0 ? flattenHeaderLeaves(column) : [];
1476
+ if (leaves.length === 0) return void 0;
1477
+ const leafOffsets = [];
1478
+ for (const leaf of leaves) {
1479
+ const offset2 = freezeOffsets.get(leaf.id);
1480
+ if (!offset2) return void 0;
1481
+ leafOffsets.push(offset2);
1482
+ }
1483
+ const side = leafOffsets[0]?.side;
1484
+ if (!side || leafOffsets.some((offset2) => offset2.side !== side)) {
1485
+ return void 0;
1486
+ }
1487
+ const offset = Math.min(...leafOffsets.map((item) => item.offset));
1488
+ const leftmost = leafOffsets[0];
1489
+ const rightmost = leafOffsets[leafOffsets.length - 1];
1490
+ return {
1491
+ side,
1492
+ offset,
1493
+ edgeLeft: leftmost.edgeLeft,
1494
+ edgeRight: rightmost.edgeRight,
1495
+ isEdge: leftmost.edgeLeft || rightmost.edgeRight,
1496
+ stack: Math.max(...leafOffsets.map((item) => item.stack))
1497
+ };
1498
+ }
1499
+ function flattenHeaderLeaves(column) {
1500
+ if (!column.columns || column.columns.length === 0) return [column];
1501
+ return column.columns.flatMap((child) => flattenHeaderLeaves(child));
1502
+ }
1195
1503
 
1196
1504
  // src/components/ui/table/features/inline-search/inlineSearch.ts
1197
1505
  var INLINE_SEARCH_MAX_RESULTS = 1e3;
@@ -1935,6 +2243,7 @@ function useGlideTable(options) {
1935
2243
  onDataChange,
1936
2244
  onCellChange,
1937
2245
  onBatchChange,
2246
+ cellRenderers,
1938
2247
  preserveRowSelection = false,
1939
2248
  toggleField,
1940
2249
  childField,
@@ -2160,6 +2469,22 @@ function useGlideTable(options) {
2160
2469
  commitEdit,
2161
2470
  cancelEdit
2162
2471
  } = useCellEdit({ data: tableData, rows, onDataChange, onCellChange });
2472
+ const cellRendererRegistry = (0, import_react5.useMemo)(
2473
+ () => createCellRendererRegistry(cellRenderers),
2474
+ [cellRenderers]
2475
+ );
2476
+ const commitRenderedCellValue = (0, import_react5.useCallback)(
2477
+ (rowId, columnId, value) => commitCellValue({
2478
+ data: tableData,
2479
+ rows,
2480
+ rowId,
2481
+ columnId,
2482
+ value,
2483
+ onCellChange,
2484
+ onDataChange
2485
+ }),
2486
+ [onCellChange, onDataChange, rows, tableData]
2487
+ );
2163
2488
  const handleCellMouseDownWithCommit = (0, import_react5.useCallback)(
2164
2489
  (rowIndex, colIndex, options2) => {
2165
2490
  const isSameEditingCell = editingCell?.rowIndex === rowIndex && editingCell?.colIndex === colIndex;
@@ -2396,6 +2721,10 @@ function useGlideTable(options) {
2396
2721
  onCommitEdit: commitEdit,
2397
2722
  onCancelEdit: cancelEdit
2398
2723
  },
2724
+ cellRender: {
2725
+ registry: cellRendererRegistry,
2726
+ commitValue: commitRenderedCellValue
2727
+ },
2399
2728
  expand: {
2400
2729
  enableExpand,
2401
2730
  toggleField,
@@ -2442,6 +2771,8 @@ function useGlideTable(options) {
2442
2771
  startEdit,
2443
2772
  commitEdit,
2444
2773
  cancelEdit,
2774
+ cellRendererRegistry,
2775
+ commitRenderedCellValue,
2445
2776
  enableExpand,
2446
2777
  toggleField,
2447
2778
  expandedRows,
@@ -2506,6 +2837,54 @@ function useGlideTable(options) {
2506
2837
  };
2507
2838
  }
2508
2839
 
2840
+ // src/components/ui/table/features/cell-render/ResolvedTableCell.tsx
2841
+ var import_react7 = require("react");
2842
+
2843
+ // src/components/ui/table/DataTableContext.tsx
2844
+ var import_react6 = require("react");
2845
+ var import_jsx_runtime2 = require("react/jsx-runtime");
2846
+ var DataTableContext = (0, import_react6.createContext)(null);
2847
+ function useDataTableRowContext() {
2848
+ const context = (0, import_react6.use)(DataTableContext);
2849
+ if (!context) {
2850
+ throw new Error("useDataTableRowContext must be used within a DataTableContextProvider");
2851
+ }
2852
+ return context;
2853
+ }
2854
+
2855
+ // src/components/ui/table/features/cell-render/ResolvedTableCell.tsx
2856
+ function ResolvedTableCell({
2857
+ info
2858
+ }) {
2859
+ const { cellRender } = useDataTableRowContext();
2860
+ const { row, column, getValue } = info;
2861
+ const meta = column.columnDef.meta;
2862
+ const value = getValue();
2863
+ const columnId = column.id;
2864
+ const update = (0, import_react7.useCallback)(
2865
+ (next) => {
2866
+ cellRender.commitValue(row.id, columnId, next);
2867
+ },
2868
+ [cellRender, columnId, row.id]
2869
+ );
2870
+ const ctx = {
2871
+ value,
2872
+ row,
2873
+ index: row.index,
2874
+ columnId,
2875
+ cellProps: meta?.cellProps,
2876
+ update
2877
+ };
2878
+ if (meta?.cellRender) {
2879
+ return meta.cellRender(ctx);
2880
+ }
2881
+ const renderer = resolveCellRenderer(cellRender.registry, meta?.kind, ctx);
2882
+ if (renderer) {
2883
+ return renderer.render(ctx);
2884
+ }
2885
+ return formatDefaultCellValue(value);
2886
+ }
2887
+
2509
2888
  // src/components/ui/table/features/column-resize/columnResize.ts
2510
2889
  function getColumnSizeStyle(size, options) {
2511
2890
  const { force = false, lockMax = false } = options ?? {};
@@ -2520,6 +2899,7 @@ function getColumnSizeStyle(size, options) {
2520
2899
  }
2521
2900
  // Annotate the CommonJS export names for ESM import in node:
2522
2901
  0 && (module.exports = {
2902
+ BUILTIN_CELL_RENDERERS,
2523
2903
  CELL_SELECTION_EDGES_CLASS,
2524
2904
  DEFAULT_DATA_TABLE_LABELS,
2525
2905
  DEFAULT_TREE_CHILDREN_FIELD,
@@ -2527,6 +2907,7 @@ function getColumnSizeStyle(size, options) {
2527
2907
  DEFAULT_TREE_PARENT_ID_FIELD,
2528
2908
  DEFAULT_TREE_QTY_FIELD,
2529
2909
  INLINE_SEARCH_MAX_RESULTS,
2910
+ ResolvedTableCell,
2530
2911
  applyCellEdit,
2531
2912
  applyFillData,
2532
2913
  applySelectionUpdater,
@@ -2545,9 +2926,13 @@ function getColumnSizeStyle(size, options) {
2545
2926
  collectFillChanges,
2546
2927
  collectRowSpanColumns,
2547
2928
  collectSearchMatchesInRange,
2929
+ commitCellValue,
2930
+ createCellRendererRegistry,
2548
2931
  createSearchRegex,
2549
2932
  escapeSearchRegex,
2550
2933
  flattenSubtreeRows,
2934
+ formatCellValue,
2935
+ formatDefaultCellValue,
2551
2936
  formatSearchResultLabel,
2552
2937
  getCellEditDraftValue,
2553
2938
  getCellSelectionEdgeStyle,
@@ -2569,8 +2954,10 @@ function getColumnSizeStyle(size, options) {
2569
2954
  parseClipboardTSV,
2570
2955
  parseClipboardTSVWithDepths,
2571
2956
  previousSearchIndex,
2957
+ resolveCellRenderer,
2572
2958
  resolveColumnFreezeSide,
2573
2959
  resolveDataTableLabels,
2960
+ resolveHeaderFreezeOffset,
2574
2961
  resolvePasteColumnIds,
2575
2962
  resolveRowSelection,
2576
2963
  resolveRowSpanAt,
package/dist/core.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { M as CellEditType, e as DataTableClassNames, R as RowSelectionMode, c as ColumnFreezeOffset, l as SearchResultItem, m as SearchStatus, h as DataTableProps, g as DataTableLabels, f as DataTableCopyActions, P as PasteMode, k as RowsPastePayload } from './types-Cs9MiZs1.cjs';
2
- export { C as ColumnFreezeColumnInput, a as ColumnFreezeEdgeSide, b as ColumnFreezeMeta, d as ColumnFreezeSide, D as DEFAULT_DATA_TABLE_LABELS, I as INLINE_SEARCH_MAX_RESULTS, S as SearchCorpusRow, p as buildColumnFreezeOffsets, q as buildFlatSearchCorpus, r as buildSearchMatchKey, s as buildSearchMatchKeys, t as buildTreeSearchCorpus, u as cellValueToSearchText, v as collectAncestorKeysToExpand, w as collectSearchMatchesInRange, x as createSearchRegex, y as escapeSearchRegex, z as formatSearchResultLabel, A as getColumnFreezeEdgeAttr, B as getColumnFreezeStyle, E as mapSearchResultToVisibleItem, F as mapSearchResultsToVisibleKeys, G as nextSearchIndex, H as nextSearchStride, J as previousSearchIndex, K as resolveColumnFreezeSide, L as resolveDataTableLabels } from './types-Cs9MiZs1.cjs';
3
- import { Row, ColumnDef, Table, Updater, RowSelectionState } from '@tanstack/react-table';
1
+ import { W as CellEditType, c as CellRenderer, C as CellKind, a as CellRenderContext, i as DataTableClassNames, R as RowSelectionMode, g as ColumnFreezeOffset, p as SearchResultItem, q as SearchStatus, l as DataTableProps, k as DataTableLabels, j as DataTableCopyActions, P as PasteMode, o as RowsPastePayload } from './types-DJOlsDL8.cjs';
2
+ export { B as BuiltinCellKind, b as CellRenderFn, d as ColumnFreezeColumnInput, e as ColumnFreezeEdgeSide, f as ColumnFreezeMeta, h as ColumnFreezeSide, D as DEFAULT_DATA_TABLE_LABELS, I as INLINE_SEARCH_MAX_RESULTS, S as SearchCorpusRow, t as buildColumnFreezeOffsets, u as buildFlatSearchCorpus, v as buildSearchMatchKey, w as buildSearchMatchKeys, x as buildTreeSearchCorpus, y as cellValueToSearchText, z as collectAncestorKeysToExpand, A as collectSearchMatchesInRange, E as createSearchRegex, F as escapeSearchRegex, G as formatSearchResultLabel, H as getColumnFreezeEdgeAttr, J as getColumnFreezeStyle, K as mapSearchResultToVisibleItem, L as mapSearchResultsToVisibleKeys, M as nextSearchIndex, N as nextSearchStride, O as previousSearchIndex, Q as resolveColumnFreezeSide, U as resolveDataTableLabels, V as resolveHeaderFreezeOffset } from './types-DJOlsDL8.cjs';
3
+ import { Row, ColumnDef, Table, CellContext, Updater, RowSelectionState } from '@tanstack/react-table';
4
4
  export { ColumnDef, ColumnResizeMode, ColumnSizingState, RowSelectionState } from '@tanstack/react-table';
5
5
  import { Virtualizer, VirtualItem } from '@tanstack/react-virtual';
6
6
  import * as react from 'react';
@@ -36,6 +36,12 @@ declare function getCellEditDraftValue(value: unknown): string;
36
36
  /** Returns updated data on success; null if parsing fails or the cell is not editable */
37
37
  declare function applyCellEdit<T extends Record<string, unknown>>(data: T[], rows: Row<T>[], rowIndex: number, colIndex: number, raw: string): T[] | null;
38
38
 
39
+ type CellRendererRegistry = Map<string, CellRenderer>;
40
+ /** Later entries with the same `kind` override earlier ones (including builtins). */
41
+ declare function createCellRendererRegistry(customRenderers?: readonly CellRenderer[]): CellRendererRegistry;
42
+ declare function resolveCellRenderer<T extends Record<string, unknown>>(registry: CellRendererRegistry, kind: CellKind | undefined, ctx: CellRenderContext<T>): CellRenderer | undefined;
43
+ declare function formatDefaultCellValue(value: unknown): string | null;
44
+
39
45
  type CellPosition = {
40
46
  row: number;
41
47
  col: number;
@@ -164,6 +170,10 @@ type DataTableRowContextValue = {
164
170
  onCommitEdit: (raw?: string) => boolean;
165
171
  onCancelEdit: () => void;
166
172
  };
173
+ cellRender: {
174
+ registry: CellRendererRegistry;
175
+ commitValue: (rowId: string, columnId: string, value: unknown) => boolean;
176
+ };
167
177
  expand: {
168
178
  enableExpand: boolean;
169
179
  toggleField?: string;
@@ -284,6 +294,27 @@ declare function useCellEdit<T extends Record<string, unknown>>({ data, rows, on
284
294
  cancelEdit: () => void;
285
295
  };
286
296
 
297
+ declare const BUILTIN_CELL_RENDERERS: CellRenderer[];
298
+
299
+ type CommitCellValueOptions<T extends Record<string, unknown>> = {
300
+ data: T[];
301
+ rows: Row<T>[];
302
+ rowId: string;
303
+ columnId: string;
304
+ value: unknown;
305
+ onCellChange?: (rowId: string, columnId: string, value: unknown) => void;
306
+ onDataChange?: (data: T[]) => void;
307
+ };
308
+ /**
309
+ * Shared commit path for custom `render` updates and built-in cell kinds.
310
+ * Prefers `onCellChange`; falls back to immutable `onDataChange` patch.
311
+ */
312
+ declare function commitCellValue<T extends Record<string, unknown>>({ data, rows, rowId, columnId, value, onCellChange, onDataChange, }: CommitCellValueOptions<T>): boolean;
313
+
314
+ declare function ResolvedTableCell<T extends Record<string, unknown>>({ info, }: {
315
+ info: CellContext<T, unknown>;
316
+ }): react.ReactNode;
317
+
287
318
  /** Width styles for header/body cells when column sizing is active. */
288
319
  declare function getColumnSizeStyle(size: number, options?: {
289
320
  force?: boolean;
@@ -350,6 +381,11 @@ type CopyRowEntry<T extends Record<string, unknown>> = {
350
381
  /** Tree depth relative to the table root (0 = top-level). */
351
382
  depth: number;
352
383
  };
384
+ /**
385
+ * Clipboard / Excel paste expects one plain string per cell.
386
+ * Avoids `String(object)` → `[object Object]` and joins arrays with `, `.
387
+ */
388
+ declare function formatCellValue(value: unknown): string;
353
389
  declare function flattenSubtreeRows<T extends Record<string, unknown>>(row: T): T[];
354
390
  /**
355
391
  * Collects copy rows with tree depth so paste can rebuild parent/child nesting.
@@ -409,4 +445,4 @@ declare const useConvertTreeData: <T extends Record<string, unknown>>({ data, en
409
445
  declare function resolveRowSelection(mode: RowSelectionMode, controlledSelection: RowSelectionState | undefined, internalSelection: RowSelectionState): RowSelectionState;
410
446
  declare function applySelectionUpdater(mode: RowSelectionMode, updater: Updater<RowSelectionState>, previous: RowSelectionState): RowSelectionState;
411
447
 
412
- export { CELL_SELECTION_EDGES_CLASS, type CellSelectionBounds, ColumnFreezeOffset, type ColumnRowSpanMap, type CopyRowEntry, type CopySelectionMode, DEFAULT_TREE_CHILDREN_FIELD, DEFAULT_TREE_ID_FIELD, DEFAULT_TREE_PARENT_ID_FIELD, DEFAULT_TREE_QTY_FIELD, DataTableCopyActions, DataTableLabels, DataTableProps, type DragState, type EditingCell, PasteMode, RowSelectionMode, type RowSpanInfo, RowsPastePayload, SearchResultItem, SearchStatus, type TreeRow, type UseConvertTreeDataParams, type UseGlideTableOptions, type UseGlideTableResult, type UseInlineSearchOptions, type UseInlineSearchResult, applyCellEdit, applyFillData, applySelectionUpdater, buildColumnRowSpanMap, buildRowsPastePayload, canExpandRow, collectCopyRowEntries, collectCopyRows, collectFillChanges, collectRowSpanColumns, flattenSubtreeRows, getCellEditDraftValue, getCellSelectionEdgeStyle, getColumnEditType, getColumnSizeStyle, getRowIndexInMergedCell, hasCellSelectionEdges, isCellInSelection, isColumnEditable, isEditablePasteTarget, measureMergedSpanRowHeights, parseCellEditValue, parseClipboardTSV, parseClipboardTSVWithDepths, resolvePasteColumnIds, resolveRowSelection, resolveRowSpanAt, rowRangeToHeightRatios, serializeCopyRowsToTSV, serializeSelectionToTSV, toggleExpandedRowId, useCellEdit, useCellSelection, useConvertTreeData, useGlideTable, useInlineSearch, writeSelectionToClipboard };
448
+ export { BUILTIN_CELL_RENDERERS, CELL_SELECTION_EDGES_CLASS, CellKind, CellRenderContext, CellRenderer, type CellRendererRegistry, type CellSelectionBounds, ColumnFreezeOffset, type ColumnRowSpanMap, type CopyRowEntry, type CopySelectionMode, DEFAULT_TREE_CHILDREN_FIELD, DEFAULT_TREE_ID_FIELD, DEFAULT_TREE_PARENT_ID_FIELD, DEFAULT_TREE_QTY_FIELD, DataTableCopyActions, DataTableLabels, DataTableProps, type DragState, type EditingCell, PasteMode, ResolvedTableCell, RowSelectionMode, type RowSpanInfo, RowsPastePayload, SearchResultItem, SearchStatus, type TreeRow, type UseConvertTreeDataParams, type UseGlideTableOptions, type UseGlideTableResult, type UseInlineSearchOptions, type UseInlineSearchResult, applyCellEdit, applyFillData, applySelectionUpdater, buildColumnRowSpanMap, buildRowsPastePayload, canExpandRow, collectCopyRowEntries, collectCopyRows, collectFillChanges, collectRowSpanColumns, commitCellValue, createCellRendererRegistry, flattenSubtreeRows, formatCellValue, formatDefaultCellValue, getCellEditDraftValue, getCellSelectionEdgeStyle, getColumnEditType, getColumnSizeStyle, getRowIndexInMergedCell, hasCellSelectionEdges, isCellInSelection, isColumnEditable, isEditablePasteTarget, measureMergedSpanRowHeights, parseCellEditValue, parseClipboardTSV, parseClipboardTSVWithDepths, resolveCellRenderer, resolvePasteColumnIds, resolveRowSelection, resolveRowSpanAt, rowRangeToHeightRatios, serializeCopyRowsToTSV, serializeSelectionToTSV, toggleExpandedRowId, useCellEdit, useCellSelection, useConvertTreeData, useGlideTable, useInlineSearch, writeSelectionToClipboard };