react-glide-table 1.7.0 → 2.0.2
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/README.md +87 -6
- package/dist/compound.cjs +474 -98
- package/dist/compound.d.cts +2 -2
- package/dist/compound.d.ts +2 -2
- package/dist/compound.js +459 -83
- package/dist/core.cjs +416 -12
- package/dist/core.d.cts +58 -4
- package/dist/core.d.ts +58 -4
- package/dist/core.js +407 -12
- package/dist/index.cjs +574 -166
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +545 -146
- package/dist/{types-Cs9MiZs1.d.cts → types-bgEceyRV.d.cts} +82 -4
- package/dist/{types-Cs9MiZs1.d.ts → types-bgEceyRV.d.ts} +82 -4
- package/package.json +1 -1
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,
|
|
@@ -83,6 +91,7 @@ __export(core_exports, {
|
|
|
83
91
|
useConvertTreeData: () => useConvertTreeData,
|
|
84
92
|
useGlideTable: () => useGlideTable,
|
|
85
93
|
useInlineSearch: () => useInlineSearch,
|
|
94
|
+
withCellUpdate: () => withCellUpdate,
|
|
86
95
|
writeSelectionToClipboard: () => writeSelectionToClipboard
|
|
87
96
|
});
|
|
88
97
|
module.exports = __toCommonJS(core_exports);
|
|
@@ -175,6 +184,37 @@ function applyCellEdit(data, rows, rowIndex, colIndex, raw) {
|
|
|
175
184
|
return newData;
|
|
176
185
|
}
|
|
177
186
|
|
|
187
|
+
// src/components/ui/table/features/cell-render/commitCellValue.ts
|
|
188
|
+
function commitCellValue({
|
|
189
|
+
data,
|
|
190
|
+
rows,
|
|
191
|
+
rowId,
|
|
192
|
+
columnId,
|
|
193
|
+
value,
|
|
194
|
+
onCellChange,
|
|
195
|
+
onDataChange
|
|
196
|
+
}) {
|
|
197
|
+
if (!onCellChange && !onDataChange) return true;
|
|
198
|
+
if (onCellChange) {
|
|
199
|
+
onCellChange(rowId, columnId, value);
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
const row = rows.find((item) => item.id === rowId);
|
|
203
|
+
if (!row) return false;
|
|
204
|
+
const cell = row.getAllCells().find((item) => item.column.id === columnId) ?? row.getVisibleCells().find((item) => item.column.id === columnId);
|
|
205
|
+
if (!cell) return false;
|
|
206
|
+
const accessorKey = getColumnAccessorKey(cell.column.columnDef);
|
|
207
|
+
if (!accessorKey) return false;
|
|
208
|
+
const dataIndex = row.index;
|
|
209
|
+
if (dataIndex < 0 || dataIndex >= data.length) return false;
|
|
210
|
+
const next = data.map((item) => ({ ...item }));
|
|
211
|
+
const target = next[dataIndex];
|
|
212
|
+
if (!target) return false;
|
|
213
|
+
target[accessorKey] = value;
|
|
214
|
+
onDataChange?.(next);
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
|
|
178
218
|
// src/components/ui/table/features/cell-edit/useCellEdit.ts
|
|
179
219
|
function useCellEdit({
|
|
180
220
|
data,
|
|
@@ -210,21 +250,23 @@ function useCellEdit({
|
|
|
210
250
|
cancelEdit();
|
|
211
251
|
return true;
|
|
212
252
|
}
|
|
213
|
-
const value = raw ?? draftValueRef.current;
|
|
214
253
|
if (!isColumnEditable(cell.column.columnDef)) {
|
|
215
254
|
cancelEdit();
|
|
216
255
|
return true;
|
|
217
256
|
}
|
|
257
|
+
const value = raw ?? draftValueRef.current;
|
|
218
258
|
const parsed = parseCellEditValue(value, getColumnEditType(cell.column.columnDef));
|
|
219
259
|
if (!parsed.ok) return false;
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
260
|
+
const committed = commitCellValue({
|
|
261
|
+
data,
|
|
262
|
+
rows,
|
|
263
|
+
rowId: row.id,
|
|
264
|
+
columnId: cell.column.id,
|
|
265
|
+
value: parsed.value,
|
|
266
|
+
onCellChange,
|
|
267
|
+
onDataChange
|
|
268
|
+
});
|
|
269
|
+
if (!committed) return false;
|
|
228
270
|
cancelEdit();
|
|
229
271
|
return true;
|
|
230
272
|
},
|
|
@@ -253,6 +295,228 @@ function useCellEdit({
|
|
|
253
295
|
};
|
|
254
296
|
}
|
|
255
297
|
|
|
298
|
+
// src/components/ui/table/features/cell-render/builtins.tsx
|
|
299
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
300
|
+
function asString(value) {
|
|
301
|
+
if (value == null) return "";
|
|
302
|
+
return String(value);
|
|
303
|
+
}
|
|
304
|
+
function asStringList(value) {
|
|
305
|
+
if (Array.isArray(value)) {
|
|
306
|
+
return value.map((item) => asString(item)).filter(Boolean);
|
|
307
|
+
}
|
|
308
|
+
if (value == null || value === "") return [];
|
|
309
|
+
return [asString(value)];
|
|
310
|
+
}
|
|
311
|
+
function asDrilldownItems(value) {
|
|
312
|
+
if (!Array.isArray(value)) return [];
|
|
313
|
+
return value.flatMap((item) => {
|
|
314
|
+
if (item == null) return [];
|
|
315
|
+
if (typeof item === "string") return [{ text: item }];
|
|
316
|
+
if (typeof item === "object") {
|
|
317
|
+
const record = item;
|
|
318
|
+
const text = asString(record.text ?? record.label ?? "");
|
|
319
|
+
if (!text) return [];
|
|
320
|
+
const img = record.img ?? record.image;
|
|
321
|
+
return [{ text, ...typeof img === "string" ? { img } : {} }];
|
|
322
|
+
}
|
|
323
|
+
return [{ text: asString(item) }];
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
function escapeHtml(text) {
|
|
327
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
328
|
+
}
|
|
329
|
+
function simpleMarkdownToHtml(source) {
|
|
330
|
+
const escaped = escapeHtml(source);
|
|
331
|
+
return escaped.replace(/`([^`]+)`/g, "<code>$1</code>").replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>").replace(/\*([^*]+)\*/g, "<em>$1</em>").replace(/\n/g, "<br />");
|
|
332
|
+
}
|
|
333
|
+
function TextCell({ value }) {
|
|
334
|
+
return asString(value);
|
|
335
|
+
}
|
|
336
|
+
function NumberCell({ value }) {
|
|
337
|
+
if (value == null || value === "") return null;
|
|
338
|
+
return asString(value);
|
|
339
|
+
}
|
|
340
|
+
function BooleanCell({ value, update, cellProps }) {
|
|
341
|
+
const checked = Boolean(value);
|
|
342
|
+
const readonly = Boolean(cellProps?.readonly);
|
|
343
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
344
|
+
"input",
|
|
345
|
+
{
|
|
346
|
+
type: "checkbox",
|
|
347
|
+
className: "data-table-cell-boolean",
|
|
348
|
+
checked,
|
|
349
|
+
disabled: readonly,
|
|
350
|
+
"aria-checked": checked,
|
|
351
|
+
onChange: (event) => {
|
|
352
|
+
if (readonly) return;
|
|
353
|
+
update(event.target.checked);
|
|
354
|
+
},
|
|
355
|
+
onClick: (event) => {
|
|
356
|
+
event.stopPropagation();
|
|
357
|
+
},
|
|
358
|
+
onMouseDown: (event) => {
|
|
359
|
+
event.stopPropagation();
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
function sanitizeUriHref(raw) {
|
|
365
|
+
const href = raw.trim();
|
|
366
|
+
if (!href) return null;
|
|
367
|
+
if (href.startsWith("/") || href.startsWith("#") || href.startsWith("?") || href.startsWith("./") || href.startsWith("../")) {
|
|
368
|
+
return href;
|
|
369
|
+
}
|
|
370
|
+
try {
|
|
371
|
+
const parsed = new URL(href);
|
|
372
|
+
const protocol = parsed.protocol.toLowerCase();
|
|
373
|
+
if (protocol === "http:" || protocol === "https:" || protocol === "mailto:") {
|
|
374
|
+
return href;
|
|
375
|
+
}
|
|
376
|
+
return null;
|
|
377
|
+
} catch {
|
|
378
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(href)) return null;
|
|
379
|
+
return href;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
function UriCell({ value }) {
|
|
383
|
+
const raw = asString(value);
|
|
384
|
+
if (!raw) return null;
|
|
385
|
+
const href = sanitizeUriHref(raw);
|
|
386
|
+
if (!href) {
|
|
387
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-uri", children: raw });
|
|
388
|
+
}
|
|
389
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
390
|
+
"a",
|
|
391
|
+
{
|
|
392
|
+
className: "data-table-cell-uri",
|
|
393
|
+
href,
|
|
394
|
+
target: "_blank",
|
|
395
|
+
rel: "noopener noreferrer",
|
|
396
|
+
onClick: (event) => event.stopPropagation(),
|
|
397
|
+
onMouseDown: (event) => event.stopPropagation(),
|
|
398
|
+
children: raw
|
|
399
|
+
}
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
function ImageCell({ value }) {
|
|
403
|
+
const urls = asStringList(value);
|
|
404
|
+
if (urls.length === 0) return null;
|
|
405
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-image", children: urls.map((url, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
406
|
+
"img",
|
|
407
|
+
{
|
|
408
|
+
src: url,
|
|
409
|
+
alt: "",
|
|
410
|
+
className: "data-table-cell-image-item"
|
|
411
|
+
},
|
|
412
|
+
`${index}:${url}`
|
|
413
|
+
)) });
|
|
414
|
+
}
|
|
415
|
+
function BubbleCell({ value }) {
|
|
416
|
+
const items = asStringList(value);
|
|
417
|
+
if (items.length === 0) return null;
|
|
418
|
+
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}`)) });
|
|
419
|
+
}
|
|
420
|
+
function MarkdownCell({ value }) {
|
|
421
|
+
const source = asString(value);
|
|
422
|
+
if (!source) return null;
|
|
423
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
424
|
+
"span",
|
|
425
|
+
{
|
|
426
|
+
className: "data-table-cell-markdown",
|
|
427
|
+
dangerouslySetInnerHTML: { __html: simpleMarkdownToHtml(source) }
|
|
428
|
+
}
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
function DrilldownCell({ value }) {
|
|
432
|
+
const items = asDrilldownItems(value);
|
|
433
|
+
if (items.length === 0) return null;
|
|
434
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-drilldown", children: items.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
435
|
+
"span",
|
|
436
|
+
{
|
|
437
|
+
className: "data-table-cell-drilldown-item",
|
|
438
|
+
children: [
|
|
439
|
+
item.img ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
440
|
+
"img",
|
|
441
|
+
{
|
|
442
|
+
src: item.img,
|
|
443
|
+
alt: "",
|
|
444
|
+
className: "data-table-cell-drilldown-image"
|
|
445
|
+
}
|
|
446
|
+
) : null,
|
|
447
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-drilldown-text", children: item.text })
|
|
448
|
+
]
|
|
449
|
+
},
|
|
450
|
+
`${index}:${item.text}:${item.img ?? ""}`
|
|
451
|
+
)) });
|
|
452
|
+
}
|
|
453
|
+
function LoadingCell() {
|
|
454
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-loading", "aria-busy": "true" });
|
|
455
|
+
}
|
|
456
|
+
function ProtectedCell() {
|
|
457
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-protected", "aria-label": "protected", children: "****" });
|
|
458
|
+
}
|
|
459
|
+
function RowIdCell({ value }) {
|
|
460
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "data-table-cell-row-id", children: asString(value) });
|
|
461
|
+
}
|
|
462
|
+
var BUILTIN_RENDER_MAP = {
|
|
463
|
+
text: TextCell,
|
|
464
|
+
number: NumberCell,
|
|
465
|
+
boolean: BooleanCell,
|
|
466
|
+
uri: UriCell,
|
|
467
|
+
image: ImageCell,
|
|
468
|
+
bubble: BubbleCell,
|
|
469
|
+
markdown: MarkdownCell,
|
|
470
|
+
drilldown: DrilldownCell,
|
|
471
|
+
loading: LoadingCell,
|
|
472
|
+
protected: ProtectedCell,
|
|
473
|
+
"row-id": RowIdCell
|
|
474
|
+
};
|
|
475
|
+
var BUILTIN_CELL_RENDERERS = Object.keys(BUILTIN_RENDER_MAP).map((kind) => ({
|
|
476
|
+
kind,
|
|
477
|
+
render: BUILTIN_RENDER_MAP[kind]
|
|
478
|
+
}));
|
|
479
|
+
|
|
480
|
+
// src/components/ui/table/features/cell-render/registry.ts
|
|
481
|
+
function createCellRendererRegistry(customRenderers = []) {
|
|
482
|
+
const registry = /* @__PURE__ */ new Map();
|
|
483
|
+
for (const renderer of BUILTIN_CELL_RENDERERS) {
|
|
484
|
+
registry.set(renderer.kind, renderer);
|
|
485
|
+
}
|
|
486
|
+
for (const renderer of customRenderers) {
|
|
487
|
+
registry.set(renderer.kind, renderer);
|
|
488
|
+
}
|
|
489
|
+
return registry;
|
|
490
|
+
}
|
|
491
|
+
function resolveCellRenderer(registry, kind, ctx) {
|
|
492
|
+
if (!kind) return void 0;
|
|
493
|
+
const renderer = registry.get(kind);
|
|
494
|
+
if (!renderer) return void 0;
|
|
495
|
+
if (renderer.isMatch && !renderer.isMatch(ctx)) {
|
|
496
|
+
return void 0;
|
|
497
|
+
}
|
|
498
|
+
return renderer;
|
|
499
|
+
}
|
|
500
|
+
function formatDefaultCellValue(value) {
|
|
501
|
+
if (value == null) return null;
|
|
502
|
+
if (typeof value === "string") return value;
|
|
503
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
504
|
+
return String(value);
|
|
505
|
+
}
|
|
506
|
+
if (typeof value === "bigint") return value.toString();
|
|
507
|
+
return String(value);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// src/components/ui/table/features/cell-render/withCellUpdate.ts
|
|
511
|
+
function withCellUpdate(context, commitValue) {
|
|
512
|
+
return {
|
|
513
|
+
...context,
|
|
514
|
+
update: (next) => {
|
|
515
|
+
commitValue(context.row.id, context.column.id, next);
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
|
|
256
520
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
257
521
|
var import_react2 = require("react");
|
|
258
522
|
|
|
@@ -562,9 +826,34 @@ function hasCellSelectionEdges(style) {
|
|
|
562
826
|
}
|
|
563
827
|
|
|
564
828
|
// src/components/ui/table/features/cell-selection/copyData.ts
|
|
829
|
+
function formatPrimitive(value) {
|
|
830
|
+
if (value === null || value === void 0) return "";
|
|
831
|
+
if (typeof value === "string") return value;
|
|
832
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
|
|
833
|
+
return String(value);
|
|
834
|
+
}
|
|
835
|
+
return "";
|
|
836
|
+
}
|
|
837
|
+
function formatObjectValue(value) {
|
|
838
|
+
const text = value.text ?? value.label ?? value.name ?? value.title;
|
|
839
|
+
if (text != null && text !== "") {
|
|
840
|
+
return formatCellValue(text);
|
|
841
|
+
}
|
|
842
|
+
try {
|
|
843
|
+
return JSON.stringify(value);
|
|
844
|
+
} catch {
|
|
845
|
+
return "";
|
|
846
|
+
}
|
|
847
|
+
}
|
|
565
848
|
function formatCellValue(value) {
|
|
566
849
|
if (value === null || value === void 0) return "";
|
|
567
|
-
|
|
850
|
+
if (Array.isArray(value)) {
|
|
851
|
+
return value.map((item) => formatCellValue(item)).filter((item) => item.length > 0).join(", ");
|
|
852
|
+
}
|
|
853
|
+
if (typeof value === "object") {
|
|
854
|
+
return formatObjectValue(value);
|
|
855
|
+
}
|
|
856
|
+
return formatPrimitive(value);
|
|
568
857
|
}
|
|
569
858
|
function getNestedValue(row, path) {
|
|
570
859
|
if (!path.includes(".")) return row[path];
|
|
@@ -1188,10 +1477,40 @@ function getColumnFreezeStyle(offset, options) {
|
|
|
1188
1477
|
return {
|
|
1189
1478
|
position: "sticky",
|
|
1190
1479
|
...offset.side === "left" ? { left: offset.offset } : { right: offset.offset },
|
|
1191
|
-
zIndex: zBase + offset.stack
|
|
1192
|
-
|
|
1480
|
+
zIndex: zBase + offset.stack
|
|
1481
|
+
};
|
|
1482
|
+
}
|
|
1483
|
+
function resolveHeaderFreezeOffset(column, freezeOffsets) {
|
|
1484
|
+
const direct = freezeOffsets.get(column.id);
|
|
1485
|
+
if (direct) return direct;
|
|
1486
|
+
const leaves = typeof column.getLeafColumns === "function" ? column.getLeafColumns() : column.columns && column.columns.length > 0 ? flattenHeaderLeaves(column) : [];
|
|
1487
|
+
if (leaves.length === 0) return void 0;
|
|
1488
|
+
const leafOffsets = [];
|
|
1489
|
+
for (const leaf of leaves) {
|
|
1490
|
+
const offset2 = freezeOffsets.get(leaf.id);
|
|
1491
|
+
if (!offset2) return void 0;
|
|
1492
|
+
leafOffsets.push(offset2);
|
|
1493
|
+
}
|
|
1494
|
+
const side = leafOffsets[0]?.side;
|
|
1495
|
+
if (!side || leafOffsets.some((offset2) => offset2.side !== side)) {
|
|
1496
|
+
return void 0;
|
|
1497
|
+
}
|
|
1498
|
+
const offset = Math.min(...leafOffsets.map((item) => item.offset));
|
|
1499
|
+
const leftmost = leafOffsets[0];
|
|
1500
|
+
const rightmost = leafOffsets[leafOffsets.length - 1];
|
|
1501
|
+
return {
|
|
1502
|
+
side,
|
|
1503
|
+
offset,
|
|
1504
|
+
edgeLeft: leftmost.edgeLeft,
|
|
1505
|
+
edgeRight: rightmost.edgeRight,
|
|
1506
|
+
isEdge: leftmost.edgeLeft || rightmost.edgeRight,
|
|
1507
|
+
stack: Math.max(...leafOffsets.map((item) => item.stack))
|
|
1193
1508
|
};
|
|
1194
1509
|
}
|
|
1510
|
+
function flattenHeaderLeaves(column) {
|
|
1511
|
+
if (!column.columns || column.columns.length === 0) return [column];
|
|
1512
|
+
return column.columns.flatMap((child) => flattenHeaderLeaves(child));
|
|
1513
|
+
}
|
|
1195
1514
|
|
|
1196
1515
|
// src/components/ui/table/features/inline-search/inlineSearch.ts
|
|
1197
1516
|
var INLINE_SEARCH_MAX_RESULTS = 1e3;
|
|
@@ -1935,6 +2254,7 @@ function useGlideTable(options) {
|
|
|
1935
2254
|
onDataChange,
|
|
1936
2255
|
onCellChange,
|
|
1937
2256
|
onBatchChange,
|
|
2257
|
+
cellRenderers,
|
|
1938
2258
|
preserveRowSelection = false,
|
|
1939
2259
|
toggleField,
|
|
1940
2260
|
childField,
|
|
@@ -2160,6 +2480,26 @@ function useGlideTable(options) {
|
|
|
2160
2480
|
commitEdit,
|
|
2161
2481
|
cancelEdit
|
|
2162
2482
|
} = useCellEdit({ data: tableData, rows, onDataChange, onCellChange });
|
|
2483
|
+
const cellRendererRegistry = (0, import_react5.useMemo)(
|
|
2484
|
+
() => createCellRendererRegistry(cellRenderers),
|
|
2485
|
+
[cellRenderers]
|
|
2486
|
+
);
|
|
2487
|
+
const commitRenderedCellValue = (0, import_react5.useCallback)(
|
|
2488
|
+
(rowId, columnId, value) => commitCellValue({
|
|
2489
|
+
data: tableData,
|
|
2490
|
+
rows,
|
|
2491
|
+
rowId,
|
|
2492
|
+
columnId,
|
|
2493
|
+
value,
|
|
2494
|
+
onCellChange,
|
|
2495
|
+
onDataChange
|
|
2496
|
+
}),
|
|
2497
|
+
[onCellChange, onDataChange, rows, tableData]
|
|
2498
|
+
);
|
|
2499
|
+
const getCellContext = (0, import_react5.useCallback)(
|
|
2500
|
+
(cell) => withCellUpdate(cell.getContext(), commitRenderedCellValue),
|
|
2501
|
+
[commitRenderedCellValue]
|
|
2502
|
+
);
|
|
2163
2503
|
const handleCellMouseDownWithCommit = (0, import_react5.useCallback)(
|
|
2164
2504
|
(rowIndex, colIndex, options2) => {
|
|
2165
2505
|
const isSameEditingCell = editingCell?.rowIndex === rowIndex && editingCell?.colIndex === colIndex;
|
|
@@ -2396,6 +2736,10 @@ function useGlideTable(options) {
|
|
|
2396
2736
|
onCommitEdit: commitEdit,
|
|
2397
2737
|
onCancelEdit: cancelEdit
|
|
2398
2738
|
},
|
|
2739
|
+
cellRender: {
|
|
2740
|
+
registry: cellRendererRegistry,
|
|
2741
|
+
commitValue: commitRenderedCellValue
|
|
2742
|
+
},
|
|
2399
2743
|
expand: {
|
|
2400
2744
|
enableExpand,
|
|
2401
2745
|
toggleField,
|
|
@@ -2442,6 +2786,8 @@ function useGlideTable(options) {
|
|
|
2442
2786
|
startEdit,
|
|
2443
2787
|
commitEdit,
|
|
2444
2788
|
cancelEdit,
|
|
2789
|
+
cellRendererRegistry,
|
|
2790
|
+
commitRenderedCellValue,
|
|
2445
2791
|
enableExpand,
|
|
2446
2792
|
toggleField,
|
|
2447
2793
|
expandedRows,
|
|
@@ -2486,6 +2832,7 @@ function useGlideTable(options) {
|
|
|
2486
2832
|
paddingTop,
|
|
2487
2833
|
paddingBottom,
|
|
2488
2834
|
rowContextValue,
|
|
2835
|
+
getCellContext,
|
|
2489
2836
|
handleToggleSelect,
|
|
2490
2837
|
clearHover,
|
|
2491
2838
|
copySelection: stableCopySelection,
|
|
@@ -2506,6 +2853,54 @@ function useGlideTable(options) {
|
|
|
2506
2853
|
};
|
|
2507
2854
|
}
|
|
2508
2855
|
|
|
2856
|
+
// src/components/ui/table/features/cell-render/ResolvedTableCell.tsx
|
|
2857
|
+
var import_react7 = require("react");
|
|
2858
|
+
|
|
2859
|
+
// src/components/ui/table/DataTableContext.tsx
|
|
2860
|
+
var import_react6 = require("react");
|
|
2861
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
2862
|
+
var DataTableContext = (0, import_react6.createContext)(null);
|
|
2863
|
+
function useDataTableRowContext() {
|
|
2864
|
+
const context = (0, import_react6.use)(DataTableContext);
|
|
2865
|
+
if (!context) {
|
|
2866
|
+
throw new Error("useDataTableRowContext must be used within a DataTableContextProvider");
|
|
2867
|
+
}
|
|
2868
|
+
return context;
|
|
2869
|
+
}
|
|
2870
|
+
|
|
2871
|
+
// src/components/ui/table/features/cell-render/ResolvedTableCell.tsx
|
|
2872
|
+
function ResolvedTableCell({
|
|
2873
|
+
info
|
|
2874
|
+
}) {
|
|
2875
|
+
const { cellRender } = useDataTableRowContext();
|
|
2876
|
+
const { row, column, getValue } = info;
|
|
2877
|
+
const meta = column.columnDef.meta;
|
|
2878
|
+
const value = getValue();
|
|
2879
|
+
const columnId = column.id;
|
|
2880
|
+
const update = (0, import_react7.useCallback)(
|
|
2881
|
+
(next) => {
|
|
2882
|
+
cellRender.commitValue(row.id, columnId, next);
|
|
2883
|
+
},
|
|
2884
|
+
[cellRender, columnId, row.id]
|
|
2885
|
+
);
|
|
2886
|
+
const ctx = {
|
|
2887
|
+
value,
|
|
2888
|
+
row,
|
|
2889
|
+
index: row.index,
|
|
2890
|
+
columnId,
|
|
2891
|
+
cellProps: meta?.cellProps,
|
|
2892
|
+
update
|
|
2893
|
+
};
|
|
2894
|
+
if (meta?.cellRender) {
|
|
2895
|
+
return meta.cellRender(ctx);
|
|
2896
|
+
}
|
|
2897
|
+
const renderer = resolveCellRenderer(cellRender.registry, meta?.kind, ctx);
|
|
2898
|
+
if (renderer) {
|
|
2899
|
+
return renderer.render(ctx);
|
|
2900
|
+
}
|
|
2901
|
+
return formatDefaultCellValue(value);
|
|
2902
|
+
}
|
|
2903
|
+
|
|
2509
2904
|
// src/components/ui/table/features/column-resize/columnResize.ts
|
|
2510
2905
|
function getColumnSizeStyle(size, options) {
|
|
2511
2906
|
const { force = false, lockMax = false } = options ?? {};
|
|
@@ -2520,6 +2915,7 @@ function getColumnSizeStyle(size, options) {
|
|
|
2520
2915
|
}
|
|
2521
2916
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2522
2917
|
0 && (module.exports = {
|
|
2918
|
+
BUILTIN_CELL_RENDERERS,
|
|
2523
2919
|
CELL_SELECTION_EDGES_CLASS,
|
|
2524
2920
|
DEFAULT_DATA_TABLE_LABELS,
|
|
2525
2921
|
DEFAULT_TREE_CHILDREN_FIELD,
|
|
@@ -2527,6 +2923,7 @@ function getColumnSizeStyle(size, options) {
|
|
|
2527
2923
|
DEFAULT_TREE_PARENT_ID_FIELD,
|
|
2528
2924
|
DEFAULT_TREE_QTY_FIELD,
|
|
2529
2925
|
INLINE_SEARCH_MAX_RESULTS,
|
|
2926
|
+
ResolvedTableCell,
|
|
2530
2927
|
applyCellEdit,
|
|
2531
2928
|
applyFillData,
|
|
2532
2929
|
applySelectionUpdater,
|
|
@@ -2545,9 +2942,13 @@ function getColumnSizeStyle(size, options) {
|
|
|
2545
2942
|
collectFillChanges,
|
|
2546
2943
|
collectRowSpanColumns,
|
|
2547
2944
|
collectSearchMatchesInRange,
|
|
2945
|
+
commitCellValue,
|
|
2946
|
+
createCellRendererRegistry,
|
|
2548
2947
|
createSearchRegex,
|
|
2549
2948
|
escapeSearchRegex,
|
|
2550
2949
|
flattenSubtreeRows,
|
|
2950
|
+
formatCellValue,
|
|
2951
|
+
formatDefaultCellValue,
|
|
2551
2952
|
formatSearchResultLabel,
|
|
2552
2953
|
getCellEditDraftValue,
|
|
2553
2954
|
getCellSelectionEdgeStyle,
|
|
@@ -2569,8 +2970,10 @@ function getColumnSizeStyle(size, options) {
|
|
|
2569
2970
|
parseClipboardTSV,
|
|
2570
2971
|
parseClipboardTSVWithDepths,
|
|
2571
2972
|
previousSearchIndex,
|
|
2973
|
+
resolveCellRenderer,
|
|
2572
2974
|
resolveColumnFreezeSide,
|
|
2573
2975
|
resolveDataTableLabels,
|
|
2976
|
+
resolveHeaderFreezeOffset,
|
|
2574
2977
|
resolvePasteColumnIds,
|
|
2575
2978
|
resolveRowSelection,
|
|
2576
2979
|
resolveRowSpanAt,
|
|
@@ -2583,5 +2986,6 @@ function getColumnSizeStyle(size, options) {
|
|
|
2583
2986
|
useConvertTreeData,
|
|
2584
2987
|
useGlideTable,
|
|
2585
2988
|
useInlineSearch,
|
|
2989
|
+
withCellUpdate,
|
|
2586
2990
|
writeSelectionToClipboard
|
|
2587
2991
|
});
|