@open-grid/vue-ui 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1742 @@
1
+ // src/index.ts
2
+ import {
3
+ addPassiveScrollListener,
4
+ addPointerMoveUpCancelListeners,
5
+ addPointerMoveUpListeners,
6
+ applyResizeObserverMeasuredSizes,
7
+ createClickSuppressionController,
8
+ createResizeObserver,
9
+ disconnectResizeObserver,
10
+ GROUPING_PANEL_EMPTY_MESSAGE,
11
+ HEADER_ACTION_MENU_TRIGGER_TEXT,
12
+ getCellEditorProps,
13
+ getCellEditorEventValue,
14
+ getCellEditorKeyboardAction,
15
+ getCellEditorOptionProps,
16
+ getCellEditorOptionText,
17
+ getCellProps,
18
+ getCellDisplayText,
19
+ getCellEditText,
20
+ getCellEditValidationMessage,
21
+ getCellFillHandleProps,
22
+ getCellFillHandleVisible,
23
+ getCellLayoutProps,
24
+ getCellValidationMessageProps,
25
+ getCanApplyColumnResize,
26
+ getCanCancelCellEdit,
27
+ getCanContinuePointerDrag,
28
+ getCanEndPointerDrag,
29
+ getCanRestoreFocusedCell,
30
+ getShouldCancelFocusedCellRestoreOnFrameSync,
31
+ getCanRunGridKeyboardShortcut,
32
+ getCanStartColumnResize,
33
+ getCanStartCellPointerDrag,
34
+ getCanStartCellEdit,
35
+ getCanStartFocusedCellEdit,
36
+ getCanToggleRowSelection,
37
+ downloadBrowserExportFile,
38
+ focusCellEditorElement,
39
+ focusFocusedCellInGrid,
40
+ focusHeaderActionMenuItemById,
41
+ focusHeaderActionMenuTriggerById,
42
+ getColumnById,
43
+ getColumnFilterCellProps,
44
+ getColumnFilterInputProps,
45
+ getColumnFilterText,
46
+ getColumnIndexById,
47
+ getColumnLayoutById,
48
+ getColumnLayoutTotalWidth,
49
+ getColumnHeaderText,
50
+ getColumnVisibilityCheckboxProps,
51
+ getColumnVisibilityControlsProps,
52
+ getColumnVisibilityEmptyText,
53
+ getColumnVisibilityListProps,
54
+ getColumnVisibilityResetButtonProps,
55
+ getColumnVisibilityResetButtonText,
56
+ getColumnVisibilitySearchInputProps,
57
+ getColumnVisibilityStatusProps,
58
+ getColumnVisibilityStatusText,
59
+ getColumnVisibilitySummaryProps,
60
+ getColumnVisibilitySummaryText,
61
+ getFilteredColumnVisibilityColumns,
62
+ getDensityButtonProps,
63
+ getDensityButtonText,
64
+ getDensityControlsProps,
65
+ getColumnPinningButtonProps,
66
+ getColumnPinningButtonText,
67
+ getColumnPinningControlsProps,
68
+ getColumnResizeFinalSize,
69
+ getColumnResizeHandleProps,
70
+ getColumnResizeKeyboardSize,
71
+ getColumnResizePointerSize,
72
+ getColumnResizeStartSize,
73
+ getColumnSpacerProps,
74
+ getElementOffsetBlockSize,
75
+ getGridBodyProps,
76
+ getGridBodyRowIndexOffset,
77
+ getGridEmptyCellProps,
78
+ getGridEmptyRowProps,
79
+ getGridErrorOverlayProps,
80
+ getGridErrorRetryButtonProps,
81
+ getGridErrorRetryButtonText,
82
+ getGridErrorText,
83
+ getFocusedRowSelectionTarget,
84
+ getGridHeaderProps,
85
+ getGridHeaderRowProps,
86
+ getGridKeyboardEditAction,
87
+ getGridKeyboardFocusMove,
88
+ getGridKeyboardShortcutAction,
89
+ getGridLoadingOverlayProps,
90
+ getGridLoadingText,
91
+ getGridProps,
92
+ getGridDensityProps,
93
+ getGridDensityRowHeight,
94
+ getNextColumnFilters,
95
+ getPaginationButtonProps,
96
+ getPaginationButtonText,
97
+ getPaginationPageSizeOptions,
98
+ getPaginationPageSizeOptionText,
99
+ getPaginationPageSizeSelectProps,
100
+ getPaginationPageText,
101
+ getPaginationProps,
102
+ getPaginationStatusProps,
103
+ getQuickFilterClearButtonProps,
104
+ getQuickFilterClearButtonText,
105
+ getQuickFilterInputProps,
106
+ getQuickFilterProps,
107
+ getRowSelectionCheckboxProps,
108
+ getRowSelectionCheckboxText,
109
+ getRowSelectionClearButtonProps,
110
+ getRowSelectionClearButtonText,
111
+ getRowSelectionControlsProps,
112
+ getRowSelectionStatusProps,
113
+ getRowSelectionStatusText,
114
+ getGroupCellIndentStyleText,
115
+ getGroupRowCountText,
116
+ getGroupRowLabel,
117
+ getGroupingPanelChipProps,
118
+ getGroupingPanelMoveButtonProps,
119
+ getGroupingPanelPlaceholderProps,
120
+ getGroupingPanelProps,
121
+ getGroupingPanelRemoveButtonProps,
122
+ getHeaderActionMenuDefaultItemDescriptors,
123
+ getHeaderActionMenuFocusTarget,
124
+ getHeaderActionMenuId,
125
+ getHeaderActionMenuTriggerId,
126
+ getHeaderActionMenuCustomItemProps,
127
+ getHeaderActionMenuItemProps,
128
+ getHeaderActionMenuKeyboardAction,
129
+ getHeaderActionMenuLabelProps,
130
+ getHeaderActionMenuProps,
131
+ getHeaderActionMenuSeparatorProps,
132
+ getHeaderActionMenuTriggerProps,
133
+ getHeaderActionMenuTriggerFocusPosition,
134
+ getHeaderButtonProps,
135
+ getHeaderCellLayoutProps,
136
+ getHeaderCellProps,
137
+ getHeaderDragEndAction,
138
+ getHeaderKeyboardMoveDirection,
139
+ getHeaderPlaceholderCellProps,
140
+ getHeaderSortIndicatorProps,
141
+ getHeaderSortIndicatorText,
142
+ getFocusedCellScrollOptionsFromElement,
143
+ getInlineSizeStyleText,
144
+ getPinnedColumnOffsetStyleText,
145
+ getPointerCaptureTarget,
146
+ getScrollForFocusedCell,
147
+ getScrollFrameOptionsFromElement,
148
+ getShouldPreventEventDefault,
149
+ getVirtualBodyStyleText,
150
+ getVirtualizedInlineSizeStyleText,
151
+ getVirtualRowStyleText,
152
+ preventDefaultAndStopPropagation,
153
+ preventEventDefault,
154
+ stopEventPropagation,
155
+ isCellCoordinateEqual,
156
+ isPrimaryPointerButton,
157
+ getIsGroupLabelCell,
158
+ isHeaderActionMenuActionItem,
159
+ isHeaderActionMenuCloseAction,
160
+ isHeaderActionMenuCustomItem,
161
+ isHeaderActionMenuFocusAction,
162
+ isHeaderActionMenuItem,
163
+ isHeaderActionMenuLabelItem,
164
+ isHeaderActionMenuSeparatorItem,
165
+ isHeaderActionMenuTabCloseAction,
166
+ isHeaderDragGroupAction,
167
+ isHeaderDragMoveAction,
168
+ focusHeaderActionMenuItem,
169
+ resolveColumnVirtualizationOptions,
170
+ resolveRowVirtualizationOptions,
171
+ getRowExpansionSpacerProps,
172
+ getRowExpansionToggleProps,
173
+ getRowExpansionToggleText,
174
+ getRowById,
175
+ getRowLayoutProps,
176
+ getRowProps,
177
+ getResizeObserverEntryBlockSize,
178
+ getResizeObserverEntryInlineSize,
179
+ getMeasuredElementBlockSizeFromRect,
180
+ getMeasuredElementInlineSize,
181
+ isGridInteractiveKeyboardEventTarget,
182
+ isMeasuredBlockRectElementTarget,
183
+ isMeasuredInlineDatasetElementTarget,
184
+ moveColumnToTarget,
185
+ moveGroupedColumn,
186
+ moveVisibleColumn,
187
+ observeElements,
188
+ parseCellEditValue,
189
+ readClipboardText,
190
+ removeObservedElement,
191
+ replaceObservedElement,
192
+ scrollElementToPosition,
193
+ setCheckboxIndeterminate,
194
+ setElementDatasetId,
195
+ tryReleasePointerCapture,
196
+ trySetPointerCapture,
197
+ updatePointerDragDidMovePastThreshold,
198
+ GRID_DENSITIES,
199
+ writeClipboardText
200
+ } from "@open-grid/primitives";
201
+ import { createColumnHelper, useGrid } from "@open-grid/vue";
202
+ import { createMeasuredSizeCache, createMeasuredSizeResolver, getColumnCellRenderItems, getColumnLayoutMeasurementSignature, getColumnRenderItems, getHeaderRenderItemKey, getHeaderRenderItems, getInitialScrollFrame, getMeasuredColumnLayoutFromCache, getScrollFrame, getSizedColumnLayout, getVirtualRowRange, getVirtualRowItems, isHeaderRenderSpacerItem, syncMeasuredColumnLayoutCache } from "@open-grid/virtual";
203
+ import { defineComponent, Fragment, h, nextTick, onBeforeUnmount, onMounted, ref, watch } from "vue";
204
+ import { fitColumnsToWidth } from "@open-grid/core";
205
+ import {
206
+ GRID_PREFERENCES_VERSION,
207
+ createGridPreferences,
208
+ getBrowserGridPreferencesStorage,
209
+ parseGridPreferences,
210
+ readGridPreferences,
211
+ removeGridPreferences,
212
+ serializeGridPreferences,
213
+ writeGridPreferences
214
+ } from "@open-grid/primitives";
215
+ var DataGrid = defineComponent({
216
+ name: "OpenGridDataGrid",
217
+ inheritAttrs: false,
218
+ props: {
219
+ ariaLabel: {
220
+ type: String,
221
+ default: "Data grid"
222
+ },
223
+ options: {
224
+ type: Object,
225
+ required: true
226
+ },
227
+ emptyState: {
228
+ type: [String, Number, Object, Array],
229
+ default: "No rows"
230
+ },
231
+ error: {
232
+ type: Boolean,
233
+ default: false
234
+ },
235
+ errorState: {
236
+ type: [String, Number, Object, Array],
237
+ default: () => getGridErrorText()
238
+ },
239
+ onRetry: {
240
+ type: Function,
241
+ default: void 0
242
+ },
243
+ loading: {
244
+ type: Boolean,
245
+ default: false
246
+ },
247
+ loadingState: {
248
+ type: [String, Number, Object, Array],
249
+ default: () => getGridLoadingText()
250
+ },
251
+ onGridReady: {
252
+ type: Function,
253
+ default: void 0
254
+ },
255
+ getRowClassName: {
256
+ type: Function,
257
+ default: void 0
258
+ },
259
+ getHeaderClassName: {
260
+ type: Function,
261
+ default: void 0
262
+ },
263
+ getCellClassName: {
264
+ type: Function,
265
+ default: void 0
266
+ },
267
+ groupingPanel: {
268
+ type: Boolean,
269
+ default: false
270
+ },
271
+ quickFilterControl: {
272
+ type: Boolean,
273
+ default: false
274
+ },
275
+ rowSelectionControls: {
276
+ type: Boolean,
277
+ default: false
278
+ },
279
+ columnVisibilityControls: {
280
+ type: Boolean,
281
+ default: false
282
+ },
283
+ density: {
284
+ type: String,
285
+ default: void 0
286
+ },
287
+ defaultDensity: {
288
+ type: String,
289
+ default: void 0
290
+ },
291
+ densityControl: {
292
+ type: Boolean,
293
+ default: false
294
+ },
295
+ onDensityChange: {
296
+ type: Function,
297
+ default: void 0
298
+ },
299
+ columnFilterControls: {
300
+ type: Boolean,
301
+ default: false
302
+ },
303
+ paginationControls: {
304
+ type: Boolean,
305
+ default: false
306
+ },
307
+ pageSizeOptions: {
308
+ type: Array,
309
+ default: void 0
310
+ },
311
+ columnPinningControls: {
312
+ type: Boolean,
313
+ default: false
314
+ },
315
+ headerActionMenu: {
316
+ type: Boolean,
317
+ default: false
318
+ },
319
+ headerActionMenuItems: {
320
+ type: Function,
321
+ default: void 0
322
+ },
323
+ rowVirtualization: {
324
+ type: [Boolean, Object],
325
+ default: false
326
+ },
327
+ columnVirtualization: {
328
+ type: [Boolean, Object],
329
+ default: false
330
+ },
331
+ cellFillOptions: {
332
+ type: Object,
333
+ default: void 0
334
+ },
335
+ onClipboardPaste: {
336
+ type: Function,
337
+ default: void 0
338
+ },
339
+ clipboardPasteOptions: {
340
+ type: Object,
341
+ default: void 0
342
+ }
343
+ },
344
+ setup(props, { attrs }) {
345
+ const { grid, state } = useGrid(() => props.options);
346
+ const scrollerRef = ref(null);
347
+ const headerRef = ref(null);
348
+ const groupingPanelRef = ref(null);
349
+ const headerMenuColumnId = ref(null);
350
+ const rowSizeCache = createMeasuredSizeCache();
351
+ const rowSizeVersion = ref(rowSizeCache.version);
352
+ const observedRowElements = /* @__PURE__ */ new Map();
353
+ let rowResizeObserver = null;
354
+ const columnSizeCache = createMeasuredSizeCache();
355
+ const columnSizeVersion = ref(columnSizeCache.version);
356
+ const columnVisibilityQuery = ref("");
357
+ const uncontrolledDensity = ref(props.defaultDensity ?? "standard");
358
+ const getResolvedDensity = () => props.density ?? uncontrolledDensity.value;
359
+ const getDensitySizingEnabled = () => props.densityControl || props.density !== void 0 || props.defaultDensity !== void 0;
360
+ const getResolvedRowEstimate = (estimate) => getDensitySizingEnabled() ? getGridDensityRowHeight(getResolvedDensity()) : estimate;
361
+ const observedColumnElements = /* @__PURE__ */ new Map();
362
+ let columnResizeObserver = null;
363
+ let measuredCoreLayoutSignature = "";
364
+ let cleanupScrollListener = null;
365
+ let cleanupPointerListeners = null;
366
+ let cleanupGridReady = null;
367
+ const editDraft = ref("");
368
+ const editValidationMessage = ref(null);
369
+ let rangeDrag = null;
370
+ let fillDrag = null;
371
+ let headerDrag = null;
372
+ const cellClickSuppression = createClickSuppressionController();
373
+ const headerClickSuppression = createClickSuppressionController();
374
+ const scrollFrame = ref(getInitialScrollFrame());
375
+ let shouldRestoreFocusedCell = false;
376
+ let focusRestoreInProgress = false;
377
+ const syncFrame = () => {
378
+ const scroller = scrollerRef.value;
379
+ if (!scroller) {
380
+ return;
381
+ }
382
+ if (getShouldCancelFocusedCellRestoreOnFrameSync({ inProgress: focusRestoreInProgress })) {
383
+ shouldRestoreFocusedCell = false;
384
+ }
385
+ scrollFrame.value = getScrollFrame(
386
+ getScrollFrameOptionsFromElement(scroller, {
387
+ stickyTopOffset: getElementOffsetBlockSize(headerRef.value, 42)
388
+ })
389
+ );
390
+ };
391
+ const resetPaginationScroll = () => {
392
+ const scroller = scrollerRef.value;
393
+ if (scroller) {
394
+ scrollElementToPosition(scroller, { scrollTop: 0, scrollLeft: scroller.scrollLeft });
395
+ syncFrame();
396
+ }
397
+ };
398
+ const runPaginationAction = (action) => {
399
+ action();
400
+ resetPaginationScroll();
401
+ };
402
+ const getCurrentMeasuredColumnLayout = (layout, visibleColumns, columnVirtualOptions) => {
403
+ const columnById = new Map(visibleColumns.map((column) => [column.id, column]));
404
+ const sizedLayout = getSizedColumnLayout(layout, {
405
+ getColumnSize: (columnId) => grid.getColumnSize(columnId),
406
+ getFallbackSize: (columnId) => columnById.get(columnId)?.getSize()
407
+ });
408
+ const coreLayoutSignature = getColumnLayoutMeasurementSignature(sizedLayout);
409
+ return getMeasuredColumnLayoutFromCache(sizedLayout, {
410
+ cache: columnSizeCache,
411
+ enabled: columnVirtualOptions.enabled && columnVirtualOptions.measureColumnWidth && measuredCoreLayoutSignature === coreLayoutSignature
412
+ });
413
+ };
414
+ const restoreFocusedCell = async () => {
415
+ const focusedCell = state.value.focusedCell;
416
+ const scroller = scrollerRef.value;
417
+ if (!getCanRestoreFocusedCell({
418
+ focusedCell,
419
+ scroller,
420
+ shouldRestore: shouldRestoreFocusedCell,
421
+ inProgress: focusRestoreInProgress
422
+ })) {
423
+ return;
424
+ }
425
+ if (!focusedCell || !scroller) {
426
+ return;
427
+ }
428
+ focusRestoreInProgress = true;
429
+ try {
430
+ const rows = grid.getRowModel().rows;
431
+ const rowVirtualOptions = resolveRowVirtualizationOptions(props.rowVirtualization);
432
+ const columnVirtualOptions = resolveColumnVirtualizationOptions(props.columnVirtualization);
433
+ const layout = getCurrentMeasuredColumnLayout(grid.getColumnLayout(), grid.getVisibleLeafColumns(), columnVirtualOptions);
434
+ const resolvedRowEstimate = getResolvedRowEstimate(rowVirtualOptions.estimateRowHeight);
435
+ const rowSizeResolver = rowVirtualOptions.measureRowHeight ? createMeasuredSizeResolver(rowSizeCache, (index) => rows[index]?.id ?? index, resolvedRowEstimate) : () => resolvedRowEstimate;
436
+ for (let attempt = 0; attempt < 4; attempt += 1) {
437
+ const nextScroll = getScrollForFocusedCell(
438
+ getFocusedCellScrollOptionsFromElement(scroller, {
439
+ focusedCell,
440
+ layout,
441
+ rows,
442
+ headerHeight: getElementOffsetBlockSize(headerRef.value, 42),
443
+ getRowSize: rowSizeResolver,
444
+ rowVirtualOptions,
445
+ columnVirtualOptions
446
+ })
447
+ );
448
+ if (nextScroll) {
449
+ scrollElementToPosition(scroller, nextScroll);
450
+ scrollFrame.value = getScrollFrame(
451
+ getScrollFrameOptionsFromElement(scroller, {
452
+ scrollTop: nextScroll.scrollTop,
453
+ scrollLeft: nextScroll.scrollLeft,
454
+ stickyTopOffset: getElementOffsetBlockSize(headerRef.value, 42)
455
+ })
456
+ );
457
+ }
458
+ await nextTick();
459
+ if (focusFocusedCellInGrid(scroller)) {
460
+ shouldRestoreFocusedCell = false;
461
+ break;
462
+ }
463
+ if (!nextScroll) {
464
+ break;
465
+ }
466
+ }
467
+ } finally {
468
+ focusRestoreInProgress = false;
469
+ }
470
+ };
471
+ const moveFocusWithRestore = (direction, options) => {
472
+ grid.moveFocus(direction, options);
473
+ shouldRestoreFocusedCell = true;
474
+ };
475
+ onMounted(() => {
476
+ cleanupGridReady = props.onGridReady?.(grid) ?? null;
477
+ syncFrame();
478
+ if (scrollerRef.value) {
479
+ cleanupScrollListener = addPassiveScrollListener(syncFrame, scrollerRef.value);
480
+ }
481
+ cleanupPointerListeners = addPointerMoveUpCancelListeners({
482
+ move: updateHeaderDrag,
483
+ up: clearPointerDrags,
484
+ cancel: clearPointerDrags
485
+ });
486
+ rowResizeObserver = createResizeObserver((entries) => {
487
+ if (applyResizeObserverMeasuredSizes(entries, {
488
+ cache: rowSizeCache,
489
+ datasetKey: "rowId",
490
+ getSize: getResizeObserverEntryBlockSize
491
+ })) {
492
+ rowSizeVersion.value = rowSizeCache.version;
493
+ }
494
+ });
495
+ if (rowResizeObserver) {
496
+ observeElements(rowResizeObserver, observedRowElements.values());
497
+ }
498
+ columnResizeObserver = createResizeObserver((entries) => {
499
+ if (applyResizeObserverMeasuredSizes(entries, {
500
+ cache: columnSizeCache,
501
+ datasetKey: "columnId",
502
+ getSize: getResizeObserverEntryInlineSize
503
+ })) {
504
+ columnSizeVersion.value = columnSizeCache.version;
505
+ }
506
+ });
507
+ if (columnResizeObserver) {
508
+ observeElements(columnResizeObserver, observedColumnElements.values());
509
+ }
510
+ });
511
+ onBeforeUnmount(() => {
512
+ cleanupGridReady?.();
513
+ cleanupGridReady = null;
514
+ cleanupScrollListener?.();
515
+ cleanupScrollListener = null;
516
+ cleanupPointerListeners?.();
517
+ cleanupPointerListeners = null;
518
+ disconnectResizeObserver(rowResizeObserver);
519
+ rowResizeObserver = null;
520
+ observedRowElements.clear();
521
+ disconnectResizeObserver(columnResizeObserver);
522
+ columnResizeObserver = null;
523
+ observedColumnElements.clear();
524
+ });
525
+ watch(
526
+ () => [props.density, props.defaultDensity, props.densityControl],
527
+ () => {
528
+ if (rowSizeCache.clear()) {
529
+ rowSizeVersion.value = rowSizeCache.version;
530
+ }
531
+ }
532
+ );
533
+ watch(
534
+ () => {
535
+ state.value;
536
+ return grid.getRowModel().rows.map((row) => row.id).join("\0");
537
+ },
538
+ () => {
539
+ if (!resolveRowVirtualizationOptions(props.rowVirtualization).measureRowHeight) {
540
+ return;
541
+ }
542
+ if (rowSizeCache.prune(grid.getRowModel().rows.map((row) => row.id))) {
543
+ rowSizeVersion.value = rowSizeCache.version;
544
+ }
545
+ }
546
+ );
547
+ watch(
548
+ () => {
549
+ state.value;
550
+ return grid.getColumnLayout().map((column) => column.id).join("\0");
551
+ },
552
+ () => {
553
+ const options = resolveColumnVirtualizationOptions(props.columnVirtualization);
554
+ if (!options.enabled || !options.measureColumnWidth) {
555
+ return;
556
+ }
557
+ if (columnSizeCache.prune(grid.getColumnLayout().map((column) => column.id))) {
558
+ columnSizeVersion.value = columnSizeCache.version;
559
+ }
560
+ }
561
+ );
562
+ watch(
563
+ () => {
564
+ state.value;
565
+ const visibleColumns = grid.getVisibleLeafColumns();
566
+ const columnById = new Map(visibleColumns.map((column) => [column.id, column]));
567
+ const sizedLayout = getSizedColumnLayout(grid.getColumnLayout(), {
568
+ getColumnSize: (columnId) => grid.getColumnSize(columnId),
569
+ getFallbackSize: (columnId) => columnById.get(columnId)?.getSize()
570
+ });
571
+ const columnVirtualOptions = resolveColumnVirtualizationOptions(props.columnVirtualization);
572
+ return {
573
+ enabled: columnVirtualOptions.enabled && columnVirtualOptions.measureColumnWidth,
574
+ signature: getColumnLayoutMeasurementSignature(sizedLayout)
575
+ };
576
+ },
577
+ ({ enabled, signature }) => {
578
+ const syncResult = syncMeasuredColumnLayoutCache({
579
+ cache: columnSizeCache,
580
+ currentSignature: measuredCoreLayoutSignature,
581
+ enabled,
582
+ nextSignature: signature
583
+ });
584
+ measuredCoreLayoutSignature = syncResult.signature;
585
+ if (syncResult.changed) {
586
+ columnSizeVersion.value = columnSizeCache.version;
587
+ }
588
+ },
589
+ { immediate: true }
590
+ );
591
+ watch(
592
+ () => [
593
+ state.value.focusedCell?.rowId,
594
+ state.value.focusedCell?.columnId,
595
+ state.value.editingCell?.rowId,
596
+ state.value.editingCell?.columnId,
597
+ scrollFrame.value.scrollTop,
598
+ scrollFrame.value.scrollLeft,
599
+ rowSizeVersion.value,
600
+ columnSizeVersion.value,
601
+ props.rowVirtualization,
602
+ props.columnVirtualization
603
+ ],
604
+ () => {
605
+ void restoreFocusedCell();
606
+ },
607
+ { flush: "post" }
608
+ );
609
+ const updateHeaderDrag = (event) => {
610
+ if (!getCanContinuePointerDrag(headerDrag, event)) {
611
+ return;
612
+ }
613
+ updatePointerDragDidMovePastThreshold(headerDrag, event);
614
+ };
615
+ const clearPointerDrags = (event) => {
616
+ const endingHeaderDrag = getCanEndPointerDrag(headerDrag, event) ? headerDrag : null;
617
+ if (rangeDrag?.didDrag) {
618
+ cellClickSuppression.suppress();
619
+ }
620
+ if (fillDrag) {
621
+ grid.fillCellRange(fillDrag.target, { ...props.cellFillOptions, sourceEvent: event });
622
+ cellClickSuppression.suppress();
623
+ }
624
+ const headerDragAction = endingHeaderDrag ? getHeaderDragEndAction(endingHeaderDrag, {
625
+ event,
626
+ groupingPanel: Boolean(props.groupingPanel),
627
+ groupingPanelElement: groupingPanelRef.value,
628
+ columns: grid.getAllLeafColumns()
629
+ }) : null;
630
+ if (isHeaderDragGroupAction(headerDragAction)) {
631
+ grid.toggleColumnGrouping(headerDragAction.columnId, true);
632
+ } else if (isHeaderDragMoveAction(headerDragAction)) {
633
+ moveColumnToTarget(grid, headerDragAction.sourceColumnId, headerDragAction.targetColumnId);
634
+ headerClickSuppression.suppress();
635
+ }
636
+ rangeDrag = null;
637
+ fillDrag = null;
638
+ if (endingHeaderDrag) {
639
+ headerDrag = null;
640
+ }
641
+ };
642
+ const headerDragHandlers = {
643
+ onPointerDown: (columnId, event) => {
644
+ if (!isPrimaryPointerButton(event)) {
645
+ return;
646
+ }
647
+ headerDrag = {
648
+ sourceColumnId: columnId,
649
+ targetColumnId: columnId,
650
+ pointerId: event.pointerId,
651
+ startX: event.clientX,
652
+ startY: event.clientY,
653
+ didDrag: false
654
+ };
655
+ },
656
+ onPointerEnter: (columnId, event) => {
657
+ if (!getCanContinuePointerDrag(headerDrag, event)) {
658
+ return;
659
+ }
660
+ headerDrag.targetColumnId = columnId;
661
+ },
662
+ onClick: () => {
663
+ return headerClickSuppression.consume();
664
+ }
665
+ };
666
+ const rangeDragHandlers = {
667
+ onPointerDown: (coordinate, event) => {
668
+ if (!getCanStartCellPointerDrag(event, state.value.editingCell)) {
669
+ return;
670
+ }
671
+ rangeDrag = { anchor: coordinate, pointerId: event.pointerId, didDrag: false };
672
+ grid.selectCellRange(coordinate);
673
+ },
674
+ onPointerEnter: (coordinate, event) => {
675
+ if (getCanContinuePointerDrag(fillDrag, event)) {
676
+ fillDrag.target = coordinate;
677
+ }
678
+ if (!getCanContinuePointerDrag(rangeDrag, event)) {
679
+ return;
680
+ }
681
+ if (!isCellCoordinateEqual(rangeDrag.anchor, coordinate)) {
682
+ rangeDrag.didDrag = true;
683
+ }
684
+ grid.selectCellRange(rangeDrag.anchor, coordinate);
685
+ },
686
+ onPointerUp: (event) => {
687
+ if (!getCanEndPointerDrag(rangeDrag, event)) {
688
+ return;
689
+ }
690
+ if (rangeDrag.didDrag) {
691
+ cellClickSuppression.suppress();
692
+ }
693
+ rangeDrag = null;
694
+ },
695
+ onFillPointerDown: (coordinate, event) => {
696
+ if (!getCanStartCellPointerDrag(event, state.value.editingCell)) {
697
+ return;
698
+ }
699
+ preventDefaultAndStopPropagation(event);
700
+ fillDrag = { pointerId: event.pointerId, target: coordinate };
701
+ },
702
+ onClick: (event) => {
703
+ if (!cellClickSuppression.consume(event)) {
704
+ return false;
705
+ }
706
+ return true;
707
+ }
708
+ };
709
+ const handleKeyDown = (event) => {
710
+ if (isGridInteractiveKeyboardEventTarget(event)) {
711
+ return;
712
+ }
713
+ const shortcutAction = getGridKeyboardShortcutAction(event);
714
+ const focusMove = getGridKeyboardFocusMove(event);
715
+ const editAction = getGridKeyboardEditAction(event);
716
+ const focusedCell = state.value.focusedCell;
717
+ const editingCell = state.value.editingCell;
718
+ const canRunShortcut = getCanRunGridKeyboardShortcut(editingCell);
719
+ if (editAction === "start-edit" && getCanStartFocusedCellEdit(focusedCell, editingCell)) {
720
+ preventEventDefault(event);
721
+ shouldRestoreFocusedCell = false;
722
+ startCellEdit(grid, focusedCell.rowId, focusedCell.columnId, event, editDraft, editValidationMessage);
723
+ } else if (editAction === "cancel-edit" && getCanCancelCellEdit(editingCell)) {
724
+ preventEventDefault(event);
725
+ shouldRestoreFocusedCell = true;
726
+ editValidationMessage.value = null;
727
+ grid.cancelCellEdit(event);
728
+ } else if (shortcutAction === "copy" && canRunShortcut) {
729
+ const clipboardText = grid.getClipboardText();
730
+ if (clipboardText) {
731
+ preventEventDefault(event);
732
+ void writeClipboardText(clipboardText);
733
+ }
734
+ } else if (shortcutAction === "paste" && canRunShortcut) {
735
+ preventEventDefault(event);
736
+ shouldRestoreFocusedCell = true;
737
+ void readClipboardText().then((clipboardText) => {
738
+ if (clipboardText) {
739
+ const result = grid.pasteClipboardText(clipboardText, { ...props.clipboardPasteOptions, sourceEvent: event });
740
+ props.onClipboardPaste?.(result);
741
+ }
742
+ });
743
+ } else if (shortcutAction === "undo-edit" && canRunShortcut && grid.getCanUndoCellEdit()) {
744
+ preventEventDefault(event);
745
+ shouldRestoreFocusedCell = true;
746
+ grid.undoCellEdit(event);
747
+ } else if (shortcutAction === "redo-edit" && canRunShortcut && grid.getCanRedoCellEdit()) {
748
+ preventEventDefault(event);
749
+ shouldRestoreFocusedCell = true;
750
+ grid.redoCellEdit(event);
751
+ } else if (shortcutAction === "row-selection" && canRunShortcut) {
752
+ const rows = grid.getRowModel().rows;
753
+ const rowSelectionTarget = getFocusedRowSelectionTarget(rows, state.value.focusedCell);
754
+ if (rowSelectionTarget) {
755
+ preventEventDefault(event);
756
+ const { row, rowIndex } = rowSelectionTarget;
757
+ const rowEvent = grid.emitRowEvent({ type: "keydown", row, rowIndex, sourceEvent: event });
758
+ if (getCanToggleRowSelection(rowEvent)) {
759
+ grid.toggleRowSelected(row.id);
760
+ }
761
+ }
762
+ } else if (focusMove) {
763
+ preventEventDefault(event);
764
+ moveFocusWithRestore(focusMove.direction, focusMove.options);
765
+ }
766
+ };
767
+ const measureVirtualRow = (rowId, element) => {
768
+ const previous = observedRowElements.get(rowId);
769
+ if (previous && previous !== element) {
770
+ removeObservedElement(rowResizeObserver, observedRowElements, rowId);
771
+ }
772
+ if (!resolveRowVirtualizationOptions(props.rowVirtualization).measureRowHeight || !isMeasuredBlockRectElementTarget(element)) {
773
+ return;
774
+ }
775
+ replaceObservedElement(rowResizeObserver, observedRowElements, rowId, element);
776
+ if (rowSizeCache.set(rowId, getMeasuredElementBlockSizeFromRect(element))) {
777
+ rowSizeVersion.value = rowSizeCache.version;
778
+ }
779
+ };
780
+ const measureVirtualColumn = (columnId, element, enabled) => {
781
+ const previous = observedColumnElements.get(columnId);
782
+ if (previous && (previous !== element || !enabled || !isMeasuredInlineDatasetElementTarget(element))) {
783
+ removeObservedElement(columnResizeObserver, observedColumnElements, columnId);
784
+ }
785
+ if (!isMeasuredInlineDatasetElementTarget(element) || !enabled) {
786
+ return;
787
+ }
788
+ setElementDatasetId(element, "columnId", columnId);
789
+ replaceObservedElement(columnResizeObserver, observedColumnElements, columnId, element);
790
+ if (columnSizeCache.set(columnId, getMeasuredElementInlineSize(element))) {
791
+ columnSizeVersion.value = columnSizeCache.version;
792
+ }
793
+ };
794
+ return () => {
795
+ state.value;
796
+ rowSizeVersion.value;
797
+ columnSizeVersion.value;
798
+ const headerGroups = grid.getHeaderGroups();
799
+ const additionalHeaderRowCount = props.columnFilterControls ? 1 : 0;
800
+ const bodyRowIndexOffset = getGridBodyRowIndexOffset(grid, { additionalHeaderRowCount });
801
+ const groupingColumns = state.value.grouping.flatMap((columnId) => {
802
+ const column = getColumnById(columnId, grid.getAllLeafColumns());
803
+ return column ? [column] : [];
804
+ });
805
+ const rows = grid.getRowModel().rows;
806
+ const allColumns = grid.getAllLeafColumns();
807
+ const visibleColumns = grid.getVisibleLeafColumns();
808
+ const layout = grid.getColumnLayout();
809
+ const columnById = new Map(visibleColumns.map((column) => [column.id, column]));
810
+ const columnIndexById = new Map(visibleColumns.map((column, index) => [column.id, index]));
811
+ const rowVirtualOptions = resolveRowVirtualizationOptions(props.rowVirtualization);
812
+ const columnVirtualOptions = resolveColumnVirtualizationOptions(props.columnVirtualization);
813
+ const measuredLayout = getCurrentMeasuredColumnLayout(layout, visibleColumns, columnVirtualOptions);
814
+ const layoutById = getColumnLayoutById(measuredLayout);
815
+ const totalWidth = getColumnLayoutTotalWidth(measuredLayout);
816
+ const columnRenderItems = getColumnRenderItems(measuredLayout, scrollFrame.value, columnVirtualOptions);
817
+ const columnCellRenderItems = getColumnCellRenderItems(columnRenderItems);
818
+ const resolvedRowEstimate = getResolvedRowEstimate(rowVirtualOptions.estimateRowHeight);
819
+ const rowRangeEstimate = rowVirtualOptions.measureRowHeight ? createMeasuredSizeResolver(rowSizeCache, (index) => rows[index]?.id ?? index, resolvedRowEstimate) : resolvedRowEstimate;
820
+ const virtualRange = getVirtualRowRange({
821
+ count: rows.length,
822
+ scrollFrame: scrollFrame.value,
823
+ enabled: rowVirtualOptions.enabled,
824
+ estimateSize: rowRangeEstimate,
825
+ overscan: rowVirtualOptions.overscan
826
+ });
827
+ const visibleRowItems = getVirtualRowItems(rows, virtualRange);
828
+ const resolvedPageSizeOptions = getPaginationPageSizeOptions(props.pageSizeOptions, state.value.pagination.pageSize);
829
+ const densitySizingEnabled = getDensitySizingEnabled();
830
+ const resolvedDensity = getResolvedDensity();
831
+ const { class: rootClass, style: rootStyle, ...gridAttrs } = attrs;
832
+ const rootProps = {
833
+ ...densitySizingEnabled ? getGridDensityProps(resolvedDensity) : {},
834
+ class: ["og-grid", rootClass],
835
+ style: rootStyle
836
+ };
837
+ const semanticGridProps = {
838
+ ...getGridProps(grid, { additionalHeaderRowCount, ariaLabel: props.ariaLabel, error: props.error, loading: props.loading }),
839
+ ...densitySizingEnabled ? getGridDensityProps(resolvedDensity) : {},
840
+ ...gridAttrs
841
+ };
842
+ const setQuickFilter = (value) => {
843
+ grid.setState((previous) => ({
844
+ ...previous,
845
+ globalFilter: value,
846
+ pagination: { ...previous.pagination, pageIndex: 0 }
847
+ }));
848
+ resetPaginationScroll();
849
+ };
850
+ const quickFilterNode = props.quickFilterControl ? h("div", { ...getQuickFilterProps(), class: "og-grid__quick-filter" }, [
851
+ h("input", {
852
+ ...getQuickFilterInputProps({ value: state.value.globalFilter }),
853
+ class: "og-grid__quick-filter-input",
854
+ onInput: (event) => setQuickFilter(getCellEditorEventValue(event))
855
+ }),
856
+ h(
857
+ "button",
858
+ {
859
+ ...getQuickFilterClearButtonProps(state.value.globalFilter),
860
+ class: "og-grid__quick-filter-clear",
861
+ onClick: () => setQuickFilter("")
862
+ },
863
+ getQuickFilterClearButtonText()
864
+ )
865
+ ]) : null;
866
+ const allPageRowsSelected = props.rowSelectionControls ? grid.getIsAllPageRowsSelected() : false;
867
+ const somePageRowsSelected = props.rowSelectionControls ? grid.getIsSomePageRowsSelected() : false;
868
+ const selectedRowCount = props.rowSelectionControls ? grid.getSelectedRowModel().rows.length : 0;
869
+ const selectionControlsNode = props.rowSelectionControls ? h("div", { ...getRowSelectionControlsProps(), class: "og-grid__selection-controls" }, [
870
+ h("label", { class: "og-grid__selection-toggle" }, [
871
+ h("input", {
872
+ ...getRowSelectionCheckboxProps({
873
+ allSelected: allPageRowsSelected,
874
+ someSelected: somePageRowsSelected,
875
+ disabled: rows.length === 0
876
+ }),
877
+ ref: (element) => {
878
+ setCheckboxIndeterminate(element, somePageRowsSelected);
879
+ },
880
+ onChange: () => grid.toggleAllPageRowsSelected(!allPageRowsSelected)
881
+ }),
882
+ h("span", getRowSelectionCheckboxText())
883
+ ]),
884
+ h("span", { ...getRowSelectionStatusProps(), class: "og-grid__selection-status" }, getRowSelectionStatusText(selectedRowCount)),
885
+ h(
886
+ "button",
887
+ {
888
+ ...getRowSelectionClearButtonProps(selectedRowCount === 0),
889
+ class: "og-grid__selection-clear",
890
+ onClick: () => grid.resetRowSelection()
891
+ },
892
+ getRowSelectionClearButtonText()
893
+ )
894
+ ]) : null;
895
+ const filteredVisibilityColumns = getFilteredColumnVisibilityColumns(allColumns, columnVisibilityQuery.value);
896
+ const columnVisibilityNode = props.columnVisibilityControls ? h("details", { ...getColumnVisibilityControlsProps(), class: "og-grid__column-visibility" }, [
897
+ h(
898
+ "summary",
899
+ { ...getColumnVisibilitySummaryProps(visibleColumns.length, allColumns.length), class: "og-grid__column-visibility-summary" },
900
+ getColumnVisibilitySummaryText(visibleColumns.length, allColumns.length)
901
+ ),
902
+ h("div", { class: "og-grid__column-visibility-panel" }, [
903
+ h("input", {
904
+ ...getColumnVisibilitySearchInputProps(columnVisibilityQuery.value),
905
+ class: "og-grid__column-visibility-search",
906
+ onInput: (event) => {
907
+ columnVisibilityQuery.value = getCellEditorEventValue(event);
908
+ }
909
+ }),
910
+ h(
911
+ "span",
912
+ { ...getColumnVisibilityStatusProps(), class: "og-grid__column-visibility-status" },
913
+ getColumnVisibilityStatusText(visibleColumns.length, allColumns.length)
914
+ ),
915
+ h(
916
+ "div",
917
+ { ...getColumnVisibilityListProps(), class: "og-grid__column-visibility-list" },
918
+ filteredVisibilityColumns.length > 0 ? filteredVisibilityColumns.map((column) => {
919
+ const label = getColumnHeaderText(column);
920
+ const visible = grid.getIsColumnVisible(column.id);
921
+ return h("label", { class: "og-grid__column-visibility-item", key: column.id }, [
922
+ h("input", {
923
+ ...getColumnVisibilityCheckboxProps({
924
+ columnId: column.id,
925
+ label,
926
+ visible,
927
+ visibleCount: visibleColumns.length
928
+ }),
929
+ onChange: (event) => grid.toggleColumnVisibility(column.id, event.currentTarget.checked)
930
+ }),
931
+ h("span", label)
932
+ ]);
933
+ }) : [h("span", { class: "og-grid__column-visibility-empty" }, getColumnVisibilityEmptyText())]
934
+ ),
935
+ h(
936
+ "button",
937
+ {
938
+ ...getColumnVisibilityResetButtonProps(allColumns.length - visibleColumns.length),
939
+ class: "og-grid__column-visibility-reset",
940
+ onClick: () => grid.resetColumnVisibility()
941
+ },
942
+ getColumnVisibilityResetButtonText()
943
+ )
944
+ ])
945
+ ]) : null;
946
+ const densityNode = props.densityControl ? h(
947
+ "div",
948
+ { ...getDensityControlsProps(), class: "og-grid__density-controls" },
949
+ GRID_DENSITIES.map(
950
+ (densityOption) => h(
951
+ "button",
952
+ {
953
+ ...getDensityButtonProps(densityOption, resolvedDensity),
954
+ class: "og-grid__density-button",
955
+ onClick: () => {
956
+ if (props.density === void 0) {
957
+ uncontrolledDensity.value = densityOption;
958
+ }
959
+ if (rowSizeCache.clear()) {
960
+ rowSizeVersion.value = rowSizeCache.version;
961
+ }
962
+ props.onDensityChange?.(densityOption);
963
+ }
964
+ },
965
+ getDensityButtonText(densityOption)
966
+ )
967
+ )
968
+ ) : null;
969
+ const controlsNode = props.quickFilterControl || props.rowSelectionControls || props.columnVisibilityControls || props.densityControl ? h("div", { class: "og-grid__controls" }, [selectionControlsNode, columnVisibilityNode, densityNode, quickFilterNode]) : null;
970
+ const gridNode = h("div", rootProps, [
971
+ props.groupingPanel ? renderGroupingPanel(grid, groupingColumns, groupingPanelRef) : null,
972
+ h("div", { ...semanticGridProps, class: "og-grid__scroller", onKeydown: handleKeyDown, ref: scrollerRef }, [
973
+ h("div", { class: "og-grid__canvas", style: getInlineSizeStyleText(totalWidth) }, [
974
+ h(
975
+ "div",
976
+ { ...getGridHeaderProps(), class: "og-grid__header", ref: headerRef },
977
+ [
978
+ ...headerGroups.map(
979
+ (headerGroup, headerRowIndex) => h(
980
+ "div",
981
+ {
982
+ key: headerGroup.id,
983
+ ...getGridHeaderRowProps({ columnVirtualized: columnVirtualOptions.enabled, rowIndex: headerRowIndex }),
984
+ class: "og-grid__row og-grid__row--header",
985
+ style: getVirtualizedInlineSizeStyleText(totalWidth, columnVirtualOptions.enabled)
986
+ },
987
+ getHeaderRenderItems(headerGroup, columnRenderItems, layoutById).map((item) => {
988
+ if (isHeaderRenderSpacerItem(item)) {
989
+ return h("div", {
990
+ key: getHeaderRenderItemKey(headerGroup.id, item),
991
+ ...getColumnSpacerProps(),
992
+ class: "og-grid__column-spacer",
993
+ style: getInlineSizeStyleText(item.size)
994
+ });
995
+ }
996
+ const firstLeafId = item.leafColumnIds[0];
997
+ return renderHeader(
998
+ grid,
999
+ getHeaderRenderItemKey(headerGroup.id, item),
1000
+ item.header,
1001
+ firstLeafId ? layoutById.get(firstLeafId) : void 0,
1002
+ item.size,
1003
+ item.leafColumnIds.length,
1004
+ firstLeafId ? columnIndexById.get(firstLeafId) ?? 0 : 0,
1005
+ headerDragHandlers,
1006
+ props.columnPinningControls,
1007
+ props.headerActionMenu,
1008
+ props.headerActionMenuItems,
1009
+ props.getHeaderClassName,
1010
+ headerMenuColumnId.value,
1011
+ (columnId, element) => measureVirtualColumn(columnId, element, columnVirtualOptions.enabled && columnVirtualOptions.measureColumnWidth),
1012
+ (columnId) => {
1013
+ headerMenuColumnId.value = columnId;
1014
+ },
1015
+ (columnId) => {
1016
+ headerMenuColumnId.value = headerMenuColumnId.value === columnId ? null : columnId;
1017
+ },
1018
+ () => {
1019
+ headerMenuColumnId.value = null;
1020
+ }
1021
+ );
1022
+ })
1023
+ )
1024
+ ),
1025
+ props.columnFilterControls ? h(
1026
+ "div",
1027
+ {
1028
+ ...getGridHeaderRowProps({ columnVirtualized: columnVirtualOptions.enabled, rowIndex: headerGroups.length }),
1029
+ class: "og-grid__row og-grid__row--filter",
1030
+ style: getVirtualizedInlineSizeStyleText(totalWidth, columnVirtualOptions.enabled)
1031
+ },
1032
+ columnCellRenderItems.flatMap((item) => {
1033
+ const column = columnById.get(item.layout.id);
1034
+ if (!column) {
1035
+ return [];
1036
+ }
1037
+ const columnIndex = columnIndexById.get(column.id) ?? 0;
1038
+ return [
1039
+ h(
1040
+ "div",
1041
+ {
1042
+ key: `filter:${column.id}`,
1043
+ ...getColumnFilterCellProps(column, {
1044
+ columnIndex,
1045
+ rowIndex: headerGroups.length,
1046
+ pinned: item.layout.pinned,
1047
+ pinnedEdge: item.layout.pinnedEdge
1048
+ }),
1049
+ class: "og-grid__filter-cell",
1050
+ style: getColumnStyle(item.layout.size, item.layout, item.beforeSpacerSize, item.afterSpacerSize)
1051
+ },
1052
+ column.getCanFilter() ? [
1053
+ h("input", {
1054
+ ...getColumnFilterInputProps(column, {
1055
+ label: getColumnHeaderText(column),
1056
+ value: getColumnFilterText(state.value.columnFilters, column.id)
1057
+ }),
1058
+ class: "og-grid__filter-input",
1059
+ onInput: (event) => {
1060
+ const value = getCellEditorEventValue(event);
1061
+ grid.setState((previous) => ({
1062
+ ...previous,
1063
+ columnFilters: getNextColumnFilters(previous.columnFilters, column.id, value),
1064
+ pagination: { ...previous.pagination, pageIndex: 0 }
1065
+ }));
1066
+ }
1067
+ })
1068
+ ] : []
1069
+ )
1070
+ ];
1071
+ })
1072
+ ) : null
1073
+ ]
1074
+ ),
1075
+ h(
1076
+ "div",
1077
+ {
1078
+ ...getGridBodyProps({ virtualized: rowVirtualOptions.enabled }),
1079
+ class: "og-grid__body",
1080
+ style: getVirtualBodyStyleText(virtualRange)
1081
+ },
1082
+ rows.length === 0 ? [
1083
+ h("div", { ...getGridEmptyRowProps({ rowIndexOffset: bodyRowIndexOffset }), class: "og-grid__empty" }, [
1084
+ h("div", { ...getGridEmptyCellProps({ rowIndexOffset: bodyRowIndexOffset, columnCount: visibleColumns.length }), class: "og-grid__empty-cell", style: getInlineSizeStyleText(totalWidth) }, [
1085
+ props.emptyState
1086
+ ])
1087
+ ])
1088
+ ] : visibleRowItems.map(
1089
+ ({ row, rowIndex, virtualItem }) => h(
1090
+ "div",
1091
+ {
1092
+ key: row.id,
1093
+ ...getRowProps(row, rowIndex, { selected: grid.getIsRowSelected(row.id), rowIndexOffset: bodyRowIndexOffset }),
1094
+ ...getRowLayoutProps(row, {
1095
+ expanded: grid.getIsRowExpanded(row.id),
1096
+ virtualIndex: virtualItem?.index,
1097
+ columnVirtualized: columnVirtualOptions.enabled
1098
+ }),
1099
+ class: ["og-grid__row", props.getRowClassName?.(row)],
1100
+ ...rowVirtualOptions.enabled && rowVirtualOptions.measureRowHeight ? { ref: (element) => measureVirtualRow(row.id, element) } : {},
1101
+ onClick: (event) => {
1102
+ const rowEvent = grid.emitRowEvent({ type: "click", row, rowIndex, sourceEvent: event });
1103
+ if (getCanToggleRowSelection(rowEvent)) {
1104
+ grid.toggleRowSelected(row.id);
1105
+ }
1106
+ },
1107
+ style: getVirtualRowStyleText(virtualItem)
1108
+ },
1109
+ columnCellRenderItems.flatMap((item) => {
1110
+ const column = columnById.get(item.layout.id);
1111
+ if (!column) {
1112
+ return [];
1113
+ }
1114
+ return [
1115
+ renderCell(
1116
+ grid,
1117
+ row,
1118
+ rowIndex,
1119
+ bodyRowIndexOffset,
1120
+ column,
1121
+ columnIndexById.get(column.id) ?? 0,
1122
+ item.layout,
1123
+ item.beforeSpacerSize,
1124
+ item.afterSpacerSize,
1125
+ visibleColumns,
1126
+ editDraft,
1127
+ editValidationMessage,
1128
+ (value, event) => {
1129
+ const editEvent = grid.commitCellEdit(value, event);
1130
+ if (editEvent && !editEvent.defaultPrevented) {
1131
+ shouldRestoreFocusedCell = true;
1132
+ }
1133
+ return editEvent;
1134
+ },
1135
+ (event) => {
1136
+ shouldRestoreFocusedCell = true;
1137
+ grid.cancelCellEdit(event);
1138
+ },
1139
+ rangeDragHandlers,
1140
+ props.getCellClassName
1141
+ )
1142
+ ];
1143
+ })
1144
+ )
1145
+ )
1146
+ )
1147
+ ])
1148
+ ]),
1149
+ props.error ? h("div", { ...getGridErrorOverlayProps(), class: "og-grid__status-overlay og-grid__error-overlay" }, [
1150
+ h("span", { class: "og-grid__status-text" }, [props.errorState]),
1151
+ props.onRetry ? h("button", { ...getGridErrorRetryButtonProps(), class: "og-grid__retry-button", onClick: props.onRetry }, getGridErrorRetryButtonText()) : null
1152
+ ]) : props.loading ? h("div", { ...getGridLoadingOverlayProps(), class: "og-grid__status-overlay og-grid__loading-overlay" }, [
1153
+ h("span", { class: "og-grid__loading-spinner", "aria-hidden": "true" }),
1154
+ h("span", { class: "og-grid__status-text" }, [props.loadingState])
1155
+ ]) : null
1156
+ ]);
1157
+ const paginationNode = props.paginationControls ? h("nav", { ...getPaginationProps(), class: "og-grid__pagination" }, [
1158
+ h("div", { class: "og-grid__pagination-buttons" }, [
1159
+ h("button", { ...getPaginationButtonProps({ action: "first", disabled: !grid.getCanPreviousPage() }), class: "og-grid__pagination-button", onClick: () => runPaginationAction(() => grid.firstPage()) }, getPaginationButtonText("first")),
1160
+ h("button", { ...getPaginationButtonProps({ action: "previous", disabled: !grid.getCanPreviousPage() }), class: "og-grid__pagination-button", onClick: () => runPaginationAction(() => grid.previousPage()) }, getPaginationButtonText("previous")),
1161
+ h("span", { ...getPaginationStatusProps(), class: "og-grid__pagination-status" }, getPaginationPageText(grid)),
1162
+ h("button", { ...getPaginationButtonProps({ action: "next", disabled: !grid.getCanNextPage() }), class: "og-grid__pagination-button", onClick: () => runPaginationAction(() => grid.nextPage()) }, getPaginationButtonText("next")),
1163
+ h("button", { ...getPaginationButtonProps({ action: "last", disabled: !grid.getCanNextPage() }), class: "og-grid__pagination-button", onClick: () => runPaginationAction(() => grid.lastPage()) }, getPaginationButtonText("last"))
1164
+ ]),
1165
+ h(
1166
+ "select",
1167
+ {
1168
+ ...getPaginationPageSizeSelectProps(state.value.pagination.pageSize),
1169
+ class: "og-grid__pagination-size",
1170
+ onChange: (event) => {
1171
+ grid.setPageSize(Number(getCellEditorEventValue(event)));
1172
+ resetPaginationScroll();
1173
+ }
1174
+ },
1175
+ resolvedPageSizeOptions.map(
1176
+ (pageSize) => h("option", { key: pageSize, value: pageSize }, getPaginationPageSizeOptionText(pageSize))
1177
+ )
1178
+ )
1179
+ ]) : null;
1180
+ return h(Fragment, null, [controlsNode, gridNode, paginationNode]);
1181
+ };
1182
+ }
1183
+ });
1184
+ function createDataGrid() {
1185
+ return DataGrid;
1186
+ }
1187
+ function renderHeader(grid, renderKey, header, layout, size, colSpan, columnIndex, headerDragHandlers, columnPinningControls, headerActionMenu, headerActionMenuItems, getHeaderClassName, openHeaderMenuColumnId, onMeasureColumn, onOpenHeaderMenu, onToggleHeaderMenu, onCloseHeaderMenu) {
1188
+ const canSort = !header.isPlaceholder && header.column.columns.length === 0 && header.column.getCanSort();
1189
+ const canResize = !header.isPlaceholder && header.column.columns.length === 0;
1190
+ const canInteract = !header.isPlaceholder && header.column.columns.length === 0;
1191
+ const sortDirection = grid.getColumnSortDirection(header.column.id);
1192
+ const pinningPosition = header.column.getIsPinned();
1193
+ const visibleColumns = grid.getVisibleLeafColumns();
1194
+ const visibleColumnIndex = getColumnIndexById(header.column.id, visibleColumns);
1195
+ const canMoveLeft = visibleColumnIndex > 0;
1196
+ const canMoveRight = visibleColumnIndex >= 0 && visibleColumnIndex < visibleColumns.length - 1;
1197
+ const isGrouped = grid.getState().grouping.includes(header.column.id);
1198
+ const menuId = getHeaderActionMenuId(header.column.id);
1199
+ const menuTriggerId = getHeaderActionMenuTriggerId(header.column.id);
1200
+ const defaultMenuItems = getHeaderActionMenuDefaultItemDescriptors({
1201
+ sortDirection,
1202
+ pinningPosition,
1203
+ isGrouped,
1204
+ canGroup: header.column.getCanGroup(),
1205
+ canMoveLeft,
1206
+ canMoveRight
1207
+ }).map((descriptor) => {
1208
+ if (descriptor.id === "sort-asc") {
1209
+ return { ...descriptor, onSelect: () => grid.toggleColumnSorting(header.column.id, false) };
1210
+ }
1211
+ if (descriptor.id === "sort-desc") {
1212
+ return { ...descriptor, onSelect: () => grid.toggleColumnSorting(header.column.id, true) };
1213
+ }
1214
+ if (descriptor.id === "clear-sort") {
1215
+ return { ...descriptor, onSelect: () => grid.setSorting((previous) => previous.filter((rule) => rule.id !== header.column.id)) };
1216
+ }
1217
+ if (descriptor.id === "move-left") {
1218
+ return { ...descriptor, onSelect: () => moveVisibleColumn(grid, header.column.id, "left") };
1219
+ }
1220
+ if (descriptor.id === "move-right") {
1221
+ return { ...descriptor, onSelect: () => moveVisibleColumn(grid, header.column.id, "right") };
1222
+ }
1223
+ if (descriptor.id === "pin-left") {
1224
+ return { ...descriptor, onSelect: () => grid.pinColumn(header.column.id, "left") };
1225
+ }
1226
+ if (descriptor.id === "unpin") {
1227
+ return { ...descriptor, onSelect: () => grid.pinColumn(header.column.id, false) };
1228
+ }
1229
+ if (descriptor.id === "pin-right") {
1230
+ return { ...descriptor, onSelect: () => grid.pinColumn(header.column.id, "right") };
1231
+ }
1232
+ return { ...descriptor, onSelect: () => grid.toggleColumnGrouping(header.column.id, !isGrouped) };
1233
+ });
1234
+ const menuContext = {
1235
+ grid,
1236
+ column: header.column,
1237
+ sortDirection,
1238
+ pinningPosition,
1239
+ isGrouped,
1240
+ canMoveLeft,
1241
+ canMoveRight,
1242
+ defaultItems: defaultMenuItems
1243
+ };
1244
+ const menuItems = (headerActionMenuItems ? headerActionMenuItems(menuContext) : defaultMenuItems).filter(isHeaderActionMenuItem);
1245
+ const runMenuAction = (item) => {
1246
+ item.onSelect(menuContext);
1247
+ onCloseHeaderMenu();
1248
+ };
1249
+ const headerProps = header.isPlaceholder ? getHeaderPlaceholderCellProps(header.column) : getHeaderCellProps(grid, header.column, Math.max(0, columnIndex));
1250
+ return h(
1251
+ "div",
1252
+ {
1253
+ key: renderKey,
1254
+ ...headerProps,
1255
+ ...getHeaderCellLayoutProps({
1256
+ colSpan,
1257
+ rowSpan: header.rowSpan,
1258
+ grouped: header.column.columns.length > 0,
1259
+ placeholder: header.isPlaceholder,
1260
+ pinnedEdge: layout?.pinnedEdge,
1261
+ draggable: canInteract
1262
+ }),
1263
+ class: ["og-grid__header-cell", getHeaderClassName?.({ grid, column: header.column, header })],
1264
+ ...canInteract ? { ref: (element) => onMeasureColumn(header.column.id, element) } : {},
1265
+ onPointerdown: canInteract ? (event) => headerDragHandlers.onPointerDown(header.column.id, event) : void 0,
1266
+ onPointerenter: canInteract ? (event) => headerDragHandlers.onPointerEnter(header.column.id, event) : void 0,
1267
+ style: getColumnStyle(size, layout)
1268
+ },
1269
+ header.isPlaceholder ? "" : [
1270
+ h("button", getHeaderButtonEventProps(grid, header.column, canSort, canInteract, headerDragHandlers), [
1271
+ h("span", { class: "og-grid__header-label" }, renderHeaderValue(grid, header)),
1272
+ h("span", { ...getHeaderSortIndicatorProps(), class: "og-grid__sort-indicator" }, getHeaderSortIndicatorText(sortDirection, { visible: canSort }))
1273
+ ]),
1274
+ canInteract && columnPinningControls ? h("span", { ...getColumnPinningControlsProps(header.column), class: "og-grid__pinning-controls" }, [
1275
+ h("button", getPinningButtonProps(grid, header.column, "left", pinningPosition === "left"), getColumnPinningButtonText("left")),
1276
+ h("button", getPinningButtonProps(grid, header.column, false, pinningPosition === false), getColumnPinningButtonText(false)),
1277
+ h("button", getPinningButtonProps(grid, header.column, "right", pinningPosition === "right"), getColumnPinningButtonText("right"))
1278
+ ]) : null,
1279
+ canInteract && headerActionMenu ? h("span", { class: "og-grid__header-menu" }, [
1280
+ h(
1281
+ "button",
1282
+ {
1283
+ ...getHeaderActionMenuTriggerProps(header.column, { expanded: openHeaderMenuColumnId === header.column.id, controls: menuId }),
1284
+ id: menuTriggerId,
1285
+ class: "og-grid__header-menu-trigger",
1286
+ onPointerdown: (event) => stopEventPropagation(event),
1287
+ onClick: (event) => {
1288
+ stopEventPropagation(event);
1289
+ onToggleHeaderMenu(header.column.id);
1290
+ },
1291
+ onKeydown: (event) => {
1292
+ const focusPosition = getHeaderActionMenuTriggerFocusPosition(event);
1293
+ if (!focusPosition) {
1294
+ return;
1295
+ }
1296
+ preventDefaultAndStopPropagation(event);
1297
+ onOpenHeaderMenu(header.column.id);
1298
+ nextTick(() => focusHeaderActionMenuItemById(document, menuId, focusPosition));
1299
+ }
1300
+ },
1301
+ HEADER_ACTION_MENU_TRIGGER_TEXT
1302
+ ),
1303
+ openHeaderMenuColumnId === header.column.id ? h(
1304
+ "div",
1305
+ {
1306
+ ...getHeaderActionMenuProps(header.column),
1307
+ class: "og-grid__header-menu-popover",
1308
+ id: menuId,
1309
+ onPointerdown: (event) => stopEventPropagation(event),
1310
+ onKeydown: (event) => {
1311
+ const menuAction = getHeaderActionMenuKeyboardAction(event);
1312
+ if (!menuAction) {
1313
+ return;
1314
+ }
1315
+ if (isHeaderActionMenuCloseAction(menuAction)) {
1316
+ preventDefaultAndStopPropagation(event);
1317
+ onCloseHeaderMenu();
1318
+ nextTick(() => focusHeaderActionMenuTriggerById(document, menuTriggerId));
1319
+ } else if (isHeaderActionMenuFocusAction(menuAction)) {
1320
+ preventDefaultAndStopPropagation(event);
1321
+ focusHeaderActionMenuItem(getHeaderActionMenuFocusTarget(event), menuAction.position);
1322
+ } else if (isHeaderActionMenuTabCloseAction(menuAction)) {
1323
+ onCloseHeaderMenu();
1324
+ }
1325
+ }
1326
+ },
1327
+ menuItems.map(
1328
+ (item) => isHeaderActionMenuActionItem(item) ? h(
1329
+ "button",
1330
+ {
1331
+ key: item.id,
1332
+ ...getHeaderActionMenuItemProps({ disabled: item.disabled }),
1333
+ onClick: () => runMenuAction(item)
1334
+ },
1335
+ item.label
1336
+ ) : isHeaderActionMenuCustomItem(item) ? h("span", { key: item.id, ...getHeaderActionMenuCustomItemProps({ label: item.label }), class: "og-grid__header-menu-custom" }, item.render(menuContext) ?? "") : isHeaderActionMenuLabelItem(item) ? h("span", { key: item.id, ...getHeaderActionMenuLabelProps(), class: "og-grid__header-menu-label" }, item.label) : isHeaderActionMenuSeparatorItem(item) ? h("span", { key: item.id, ...getHeaderActionMenuSeparatorProps({ label: item.label }), class: "og-grid__header-menu-separator" }) : null
1337
+ )
1338
+ ) : null
1339
+ ]) : null,
1340
+ canResize ? h("span", {
1341
+ ...getColumnResizeHandleProps(header.column),
1342
+ class: "og-grid__resize-handle",
1343
+ onKeydown: (event) => handleResizeKeyDown(grid, header.column, Math.max(0, columnIndex), event),
1344
+ onPointerdown: (event) => handleResizePointerDown(grid, header.column, Math.max(0, columnIndex), event)
1345
+ }) : null
1346
+ ]
1347
+ );
1348
+ }
1349
+ function getPinningButtonProps(grid, column, position, active) {
1350
+ return {
1351
+ ...getColumnPinningButtonProps(column, { position, active }),
1352
+ class: "og-grid__pinning-button",
1353
+ onPointerdown: (event) => stopEventPropagation(event),
1354
+ onClick: (event) => {
1355
+ stopEventPropagation(event);
1356
+ grid.pinColumn(column.id, position);
1357
+ }
1358
+ };
1359
+ }
1360
+ function getHeaderButtonEventProps(grid, column, canSort, canInteract, headerDragHandlers) {
1361
+ return {
1362
+ ...getHeaderButtonProps({ disabled: !canInteract }),
1363
+ class: "og-grid__header-button",
1364
+ onClick: (event) => {
1365
+ if (headerDragHandlers.onClick()) {
1366
+ preventDefaultAndStopPropagation(event);
1367
+ return;
1368
+ }
1369
+ if (canSort) {
1370
+ grid.toggleColumnSorting(column.id, void 0, event.shiftKey);
1371
+ }
1372
+ },
1373
+ onKeydown: (event) => {
1374
+ const direction = getHeaderKeyboardMoveDirection(event);
1375
+ if (!direction) {
1376
+ return;
1377
+ }
1378
+ preventDefaultAndStopPropagation(event);
1379
+ moveVisibleColumn(grid, column.id, direction);
1380
+ }
1381
+ };
1382
+ }
1383
+ function handleResizePointerDown(grid, column, columnIndex, event) {
1384
+ preventDefaultAndStopPropagation(event);
1385
+ const startX = event.clientX;
1386
+ const startSize = getColumnResizeStartSize(grid, column);
1387
+ const startEvent = grid.emitColumnResizeEvent({
1388
+ phase: "start",
1389
+ column,
1390
+ columnIndex,
1391
+ startSize,
1392
+ size: startSize,
1393
+ sourceEvent: event
1394
+ });
1395
+ if (!getCanStartColumnResize(startEvent)) {
1396
+ return;
1397
+ }
1398
+ const target = getPointerCaptureTarget(event);
1399
+ let lastSize = startSize;
1400
+ let cleanupPointerListeners = null;
1401
+ trySetPointerCapture(target, event.pointerId);
1402
+ const handlePointerMove = (moveEvent) => {
1403
+ const size = getColumnResizePointerSize(startSize, startX, moveEvent);
1404
+ const resizeEvent = grid.emitColumnResizeEvent({
1405
+ phase: "move",
1406
+ column,
1407
+ columnIndex,
1408
+ startSize,
1409
+ size,
1410
+ sourceEvent: moveEvent
1411
+ });
1412
+ if (getCanApplyColumnResize(resizeEvent)) {
1413
+ lastSize = resizeEvent.size;
1414
+ grid.setColumnSize(column.id, resizeEvent.size);
1415
+ }
1416
+ };
1417
+ const handlePointerUp = (upEvent) => {
1418
+ grid.emitColumnResizeEvent({
1419
+ phase: "end",
1420
+ column,
1421
+ columnIndex,
1422
+ startSize,
1423
+ size: lastSize,
1424
+ sourceEvent: upEvent
1425
+ });
1426
+ tryReleasePointerCapture(target, upEvent.pointerId);
1427
+ cleanupPointerListeners?.();
1428
+ cleanupPointerListeners = null;
1429
+ };
1430
+ cleanupPointerListeners = addPointerMoveUpListeners({ move: handlePointerMove, up: handlePointerUp });
1431
+ }
1432
+ function handleResizeKeyDown(grid, column, columnIndex, event) {
1433
+ const startSize = getColumnResizeStartSize(grid, column);
1434
+ const nextSize = getColumnResizeKeyboardSize(column, startSize, event);
1435
+ if (nextSize === null) {
1436
+ return;
1437
+ }
1438
+ preventDefaultAndStopPropagation(event);
1439
+ const startEvent = grid.emitColumnResizeEvent({
1440
+ phase: "start",
1441
+ column,
1442
+ columnIndex,
1443
+ startSize,
1444
+ size: startSize,
1445
+ sourceEvent: event
1446
+ });
1447
+ if (!getCanStartColumnResize(startEvent)) {
1448
+ return;
1449
+ }
1450
+ const resizeEvent = grid.emitColumnResizeEvent({
1451
+ phase: "move",
1452
+ column,
1453
+ columnIndex,
1454
+ startSize,
1455
+ size: nextSize,
1456
+ sourceEvent: event
1457
+ });
1458
+ const finalSize = getColumnResizeFinalSize(startSize, resizeEvent);
1459
+ if (getCanApplyColumnResize(resizeEvent)) {
1460
+ grid.setColumnSize(column.id, finalSize);
1461
+ }
1462
+ grid.emitColumnResizeEvent({
1463
+ phase: "end",
1464
+ column,
1465
+ columnIndex,
1466
+ startSize,
1467
+ size: finalSize,
1468
+ sourceEvent: event
1469
+ });
1470
+ }
1471
+ function renderCell(grid, row, rowIndex, rowIndexOffset, column, columnIndex, layout, beforeSpacerSize, afterSpacerSize, visibleColumns, editDraft, editValidationMessage, commitCellEdit, cancelCellEdit, rangeDragHandlers, getCellClassName) {
1472
+ const editing = grid.getIsCellEditing(row.id, column.id);
1473
+ const rangeSelected = grid.getIsCellRangeSelected(row.id, column.id);
1474
+ const groupLabelCell = getIsGroupLabelCell(row, column, visibleColumns);
1475
+ const coordinate = { rowId: row.id, columnId: column.id };
1476
+ const selectedCoordinates = grid.getSelectedCellCoordinates();
1477
+ const fillHandleCoordinate = selectedCoordinates[selectedCoordinates.length - 1] ?? null;
1478
+ const fillHandleVisible = getCellFillHandleVisible(row, column, {
1479
+ activeEditing: Boolean(grid.getState().editingCell),
1480
+ fillHandleCoordinate,
1481
+ rangeSelected
1482
+ });
1483
+ return h(
1484
+ "div",
1485
+ {
1486
+ key: `${row.id}:${column.id}`,
1487
+ ...getCellProps(row, column, rowIndex, columnIndex, {
1488
+ focusedCell: grid.getState().focusedCell,
1489
+ editing,
1490
+ rangeSelected,
1491
+ rowIndexOffset
1492
+ }),
1493
+ ...getCellLayoutProps({ invalid: Boolean(editValidationMessage.value && editing), pinnedEdge: layout?.pinnedEdge }),
1494
+ class: ["og-grid__cell", getCellClassName?.({ grid, row, column, value: row.getValue(column.id) })],
1495
+ onFocus: () => grid.setFocusedCell({ rowId: row.id, columnId: column.id }),
1496
+ onPointerdown: (event) => rangeDragHandlers.onPointerDown(coordinate, event),
1497
+ onPointerenter: (event) => rangeDragHandlers.onPointerEnter(coordinate, event),
1498
+ onPointerup: (event) => rangeDragHandlers.onPointerUp(event),
1499
+ onDblclick: (event) => {
1500
+ if (!getCanStartCellEdit(row, column)) {
1501
+ return;
1502
+ }
1503
+ preventDefaultAndStopPropagation(event);
1504
+ startCellEdit(grid, row.id, column.id, event, editDraft, editValidationMessage);
1505
+ },
1506
+ onClick: (event) => {
1507
+ if (rangeDragHandlers.onClick(event)) {
1508
+ return;
1509
+ }
1510
+ const cellEvent = grid.emitCellEvent({ type: "click", row, rowIndex, column, columnIndex, sourceEvent: event });
1511
+ if (getShouldPreventEventDefault(cellEvent)) {
1512
+ preventEventDefault(event);
1513
+ }
1514
+ },
1515
+ style: getColumnStyle(layout.size, layout, beforeSpacerSize, afterSpacerSize)
1516
+ },
1517
+ editing ? [
1518
+ column.columnDef.editOptions ? h(
1519
+ "select",
1520
+ {
1521
+ ...getCellEditorProps(column, { invalid: Boolean(editValidationMessage.value) }),
1522
+ class: "og-grid__cell-editor",
1523
+ value: editDraft.value,
1524
+ onChange: (event) => {
1525
+ editDraft.value = getCellEditorEventValue(event);
1526
+ editValidationMessage.value = null;
1527
+ },
1528
+ onClick: (event) => stopEventPropagation(event),
1529
+ onDblclick: (event) => stopEventPropagation(event),
1530
+ onKeydown: (event) => {
1531
+ stopEventPropagation(event);
1532
+ const editorAction = getCellEditorKeyboardAction(event);
1533
+ if (!editorAction) {
1534
+ return;
1535
+ }
1536
+ preventEventDefault(event);
1537
+ if (editorAction === "commit-edit") {
1538
+ const editEvent = commitCellEdit(parseCellEditValue(grid, row, column, editDraft.value), event);
1539
+ editValidationMessage.value = getCellEditValidationMessage(editEvent);
1540
+ } else {
1541
+ editValidationMessage.value = null;
1542
+ cancelCellEdit(event);
1543
+ }
1544
+ },
1545
+ onBlur: (event) => {
1546
+ if (grid.getIsCellEditing(row.id, column.id)) {
1547
+ const editEvent = commitCellEdit(parseCellEditValue(grid, row, column, editDraft.value), event);
1548
+ editValidationMessage.value = getCellEditValidationMessage(editEvent);
1549
+ }
1550
+ },
1551
+ onVnodeMounted: (vnode) => {
1552
+ const element = vnode.el;
1553
+ focusCellEditorElement(element instanceof HTMLSelectElement ? element : null);
1554
+ }
1555
+ },
1556
+ column.columnDef.editOptions.map((option) => h("option", getCellEditorOptionProps(option), getCellEditorOptionText(option)))
1557
+ ) : h("input", {
1558
+ ...getCellEditorProps(column, { invalid: Boolean(editValidationMessage.value) }),
1559
+ class: "og-grid__cell-editor",
1560
+ value: editDraft.value,
1561
+ onInput: (event) => {
1562
+ editDraft.value = getCellEditorEventValue(event);
1563
+ editValidationMessage.value = null;
1564
+ },
1565
+ onClick: (event) => stopEventPropagation(event),
1566
+ onDblclick: (event) => stopEventPropagation(event),
1567
+ onKeydown: (event) => {
1568
+ stopEventPropagation(event);
1569
+ const editorAction = getCellEditorKeyboardAction(event);
1570
+ if (!editorAction) {
1571
+ return;
1572
+ }
1573
+ preventEventDefault(event);
1574
+ if (editorAction === "commit-edit") {
1575
+ const editEvent = commitCellEdit(parseCellEditValue(grid, row, column, editDraft.value), event);
1576
+ editValidationMessage.value = getCellEditValidationMessage(editEvent);
1577
+ } else {
1578
+ editValidationMessage.value = null;
1579
+ cancelCellEdit(event);
1580
+ }
1581
+ },
1582
+ onBlur: (event) => {
1583
+ if (grid.getIsCellEditing(row.id, column.id)) {
1584
+ const editEvent = commitCellEdit(parseCellEditValue(grid, row, column, editDraft.value), event);
1585
+ editValidationMessage.value = getCellEditValidationMessage(editEvent);
1586
+ }
1587
+ },
1588
+ onVnodeMounted: (vnode) => {
1589
+ const element = vnode.el;
1590
+ focusCellEditorElement(element instanceof HTMLInputElement ? element : null);
1591
+ }
1592
+ }),
1593
+ editValidationMessage.value ? h("span", { ...getCellValidationMessageProps(), class: "og-grid__cell-validation" }, editValidationMessage.value) : null
1594
+ ] : fillHandleVisible ? [renderFillHandle(coordinate, rangeDragHandlers), renderCellValue(grid, row, column)] : groupLabelCell ? renderGroupCell(grid, row, column) : renderCellValue(grid, row, column)
1595
+ );
1596
+ }
1597
+ function renderGroupCell(grid, row, column) {
1598
+ const expanded = grid.getIsRowExpanded(row.id);
1599
+ const fallback = row.getIsGroupFooter() || row.groupingColumnId ? void 0 : renderCellValue(grid, row, column);
1600
+ const label = getGroupRowLabel(row, column, { fallback });
1601
+ const countText = getGroupRowCountText(row);
1602
+ return h(
1603
+ "span",
1604
+ {
1605
+ class: "og-grid__group-cell",
1606
+ style: getGroupCellIndentStyleText(row)
1607
+ },
1608
+ [
1609
+ row.getCanExpand() ? h(
1610
+ "button",
1611
+ {
1612
+ ...getRowExpansionToggleProps(row, { expanded, label: String(label) }),
1613
+ class: "og-grid__group-toggle",
1614
+ onPointerdown: (event) => {
1615
+ stopEventPropagation(event);
1616
+ },
1617
+ onClick: (event) => {
1618
+ preventDefaultAndStopPropagation(event);
1619
+ grid.toggleRowExpanded(row.id);
1620
+ }
1621
+ },
1622
+ getRowExpansionToggleText(expanded)
1623
+ ) : h("span", { ...getRowExpansionSpacerProps(), class: "og-grid__group-toggle-spacer" }),
1624
+ h("span", { class: "og-grid__group-label" }, label),
1625
+ countText ? h("span", { class: "og-grid__group-count" }, countText) : null
1626
+ ]
1627
+ );
1628
+ }
1629
+ function renderFillHandle(coordinate, rangeDragHandlers) {
1630
+ return h("span", {
1631
+ ...getCellFillHandleProps(),
1632
+ class: "og-grid__fill-handle",
1633
+ onPointerdown: (event) => rangeDragHandlers.onFillPointerDown(coordinate, event)
1634
+ });
1635
+ }
1636
+ function startCellEdit(grid, rowId, columnId, sourceEvent, editDraft, editValidationMessage) {
1637
+ const row = getRowById(rowId, grid.getRowModel().rows);
1638
+ const column = getColumnById(columnId, grid.getVisibleLeafColumns());
1639
+ if (!row || !column) {
1640
+ return;
1641
+ }
1642
+ editDraft.value = getCellEditText(row.getValue(column.id));
1643
+ editValidationMessage.value = null;
1644
+ grid.startCellEdit(rowId, columnId, sourceEvent);
1645
+ }
1646
+ function renderGroupingPanel(grid, groupingColumns, panelRef) {
1647
+ return h(
1648
+ "div",
1649
+ {
1650
+ ref: panelRef,
1651
+ ...getGroupingPanelProps({ empty: groupingColumns.length === 0 }),
1652
+ class: "og-grid__grouping-panel"
1653
+ },
1654
+ groupingColumns.length === 0 ? [h("span", { ...getGroupingPanelPlaceholderProps(), class: "og-grid__grouping-placeholder" }, GROUPING_PANEL_EMPTY_MESSAGE)] : groupingColumns.map(
1655
+ (column, index) => h("span", { key: column.id, ...getGroupingPanelChipProps(column), class: "og-grid__grouping-chip" }, [
1656
+ h("span", { class: "og-grid__grouping-chip-label" }, getColumnLabel(column)),
1657
+ h(
1658
+ "button",
1659
+ {
1660
+ ...getGroupingPanelMoveButtonProps(column, { direction: "left", disabled: index === 0 }),
1661
+ class: "og-grid__grouping-move",
1662
+ onClick: () => moveGroupedColumn(grid, groupingColumns, column.id, "left")
1663
+ },
1664
+ "<"
1665
+ ),
1666
+ h(
1667
+ "button",
1668
+ {
1669
+ ...getGroupingPanelMoveButtonProps(column, { direction: "right", disabled: index === groupingColumns.length - 1 }),
1670
+ class: "og-grid__grouping-move",
1671
+ onClick: () => moveGroupedColumn(grid, groupingColumns, column.id, "right")
1672
+ },
1673
+ ">"
1674
+ ),
1675
+ h(
1676
+ "button",
1677
+ {
1678
+ ...getGroupingPanelRemoveButtonProps(column),
1679
+ class: "og-grid__grouping-remove",
1680
+ onClick: () => grid.toggleColumnGrouping(column.id, false)
1681
+ },
1682
+ "x"
1683
+ )
1684
+ ])
1685
+ )
1686
+ );
1687
+ }
1688
+ function getColumnLabel(column) {
1689
+ return normalizeRenderable(getColumnHeaderText(column));
1690
+ }
1691
+ function renderHeaderValue(grid, header) {
1692
+ const value = header.column.columnDef.header;
1693
+ if (typeof value === "function") {
1694
+ return normalizeRenderable(value({ grid, column: header.column, header }));
1695
+ }
1696
+ return normalizeRenderable(getColumnHeaderText(header.column));
1697
+ }
1698
+ function renderCellValue(grid, row, column) {
1699
+ const value = row.getValue(column.id);
1700
+ const renderer = column.columnDef.cell;
1701
+ if (renderer) {
1702
+ return normalizeRenderable(renderer({ grid, row, column, value }));
1703
+ }
1704
+ return normalizeRenderable(getCellDisplayText(value));
1705
+ }
1706
+ function normalizeRenderable(value) {
1707
+ if (value === null || value === void 0) {
1708
+ return "";
1709
+ }
1710
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1711
+ return String(value);
1712
+ }
1713
+ return value;
1714
+ }
1715
+ function getColumnStyle(size, layout, beforeSpacerSize = 0, afterSpacerSize = 0) {
1716
+ return [
1717
+ `flex: 0 0 ${size}px`,
1718
+ `width: ${size}px`,
1719
+ beforeSpacerSize > 0 ? `margin-left: ${beforeSpacerSize}px` : "",
1720
+ afterSpacerSize > 0 ? `margin-right: ${afterSpacerSize}px` : "",
1721
+ getPinnedColumnOffsetStyleText(layout)
1722
+ ].filter(Boolean).join("; ");
1723
+ }
1724
+ function downloadExportFile(file) {
1725
+ return downloadBrowserExportFile(file);
1726
+ }
1727
+ export {
1728
+ DataGrid,
1729
+ GRID_PREFERENCES_VERSION,
1730
+ createColumnHelper,
1731
+ createDataGrid,
1732
+ createGridPreferences,
1733
+ downloadExportFile,
1734
+ fitColumnsToWidth,
1735
+ getBrowserGridPreferencesStorage,
1736
+ parseGridPreferences,
1737
+ readGridPreferences,
1738
+ removeGridPreferences,
1739
+ serializeGridPreferences,
1740
+ useGrid,
1741
+ writeGridPreferences
1742
+ };