@vuu-ui/vuu-table 0.8.26-debug → 0.8.27-debug

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/cjs/index.js CHANGED
@@ -128,7 +128,7 @@ var SortIndicator = ({ column }) => {
128
128
  var import_react2 = require("react");
129
129
  var import_jsx_runtime4 = require("react/jsx-runtime");
130
130
  var NOOP = () => void 0;
131
- var baseClass = "vuuColumnResizerNext";
131
+ var baseClass = "vuuColumnResizer";
132
132
  var ColumnResizer = ({
133
133
  onDrag,
134
134
  onDragEnd = NOOP,
@@ -355,6 +355,7 @@ var GroupHeaderCell = ({
355
355
  };
356
356
 
357
357
  // src/header-cell/HeaderCell.tsx
358
+ var import_vuu_popups2 = require("@vuu-ui/vuu-popups");
358
359
  var import_clsx5 = __toESM(require("clsx"));
359
360
  var import_react7 = require("react");
360
361
 
@@ -383,9 +384,9 @@ var HeaderCell = ({
383
384
  column,
384
385
  onClick,
385
386
  onResize,
387
+ showMenu = true,
386
388
  ...htmlAttributes
387
389
  }) => {
388
- var _a;
389
390
  const { HeaderCellContentRenderer, HeaderCellLabelRenderer } = column;
390
391
  const rootRef = (0, import_react7.useRef)(null);
391
392
  const { isResizing, ...resizeProps } = useTableColumnResize({
@@ -393,26 +394,66 @@ var HeaderCell = ({
393
394
  onResize,
394
395
  rootRef
395
396
  });
397
+ const [showContextMenu] = (0, import_vuu_popups2.useContextMenu)();
398
+ const handleContextMenu = (0, import_react7.useMemo)(() => {
399
+ if (showMenu) {
400
+ return void 0;
401
+ } else {
402
+ return (e) => showContextMenu(e, "column-menu", { column });
403
+ }
404
+ }, [column, showContextMenu, showMenu]);
405
+ const headerItems = (0, import_react7.useMemo)(() => {
406
+ var _a;
407
+ const sortIndicator = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(SortIndicator, { column });
408
+ const columnLabel = HeaderCellLabelRenderer ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
409
+ HeaderCellLabelRenderer,
410
+ {
411
+ className: `${classBase4}-label`,
412
+ column
413
+ }
414
+ ) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: `${classBase4}-label`, children: (_a = column.label) != null ? _a : column.name });
415
+ const columnContent = HeaderCellContentRenderer ? [/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HeaderCellContentRenderer, { column }, "content")] : [];
416
+ if (showMenu) {
417
+ const columnMenu = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ColumnMenu, { column });
418
+ if (column.align === "right") {
419
+ return [sortIndicator, columnLabel, columnContent, columnMenu];
420
+ } else {
421
+ return [columnMenu, columnLabel, sortIndicator, columnContent];
422
+ }
423
+ } else {
424
+ if (column.align === "right") {
425
+ return [sortIndicator, columnLabel, columnContent];
426
+ } else {
427
+ return [columnLabel, sortIndicator, columnContent];
428
+ }
429
+ }
430
+ }, [HeaderCellContentRenderer, HeaderCellLabelRenderer, column, showMenu]);
396
431
  const handleClick = (0, import_react7.useCallback)(
397
432
  (evt) => {
398
433
  !isResizing && (onClick == null ? void 0 : onClick(evt));
399
434
  },
400
435
  [isResizing, onClick]
401
436
  );
437
+ const handleKeyDown = (0, import_react7.useCallback)(
438
+ (evt) => {
439
+ if (evt.key === "Enter") {
440
+ onClick == null ? void 0 : onClick(evt);
441
+ }
442
+ },
443
+ [onClick]
444
+ );
402
445
  const { className, style } = useCell(column, classBase4, true);
403
- const columnMenu = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ColumnMenu, { column });
404
- const columnLabel = HeaderCellLabelRenderer ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HeaderCellLabelRenderer, { className: `${classBase4}-label`, column }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: `${classBase4}-label`, children: (_a = column.label) != null ? _a : column.name });
405
- const columnContent = HeaderCellContentRenderer ? [/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HeaderCellContentRenderer, { column }, "content")] : [];
406
- const sortIndicator = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(SortIndicator, { column });
407
- const headerItems = column.align === "right" ? [sortIndicator, columnLabel].concat(columnContent).concat(columnMenu) : [columnMenu, columnLabel, sortIndicator].concat(columnContent);
408
446
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
409
447
  "div",
410
448
  {
411
449
  ...htmlAttributes,
412
450
  className: (0, import_clsx5.default)(className, classNameProp, {
413
- [`${classBase4}-resizing`]: isResizing
451
+ [`${classBase4}-resizing`]: isResizing,
452
+ [`${classBase4}-noMenu`]: showMenu === false
414
453
  }),
415
454
  onClick: handleClick,
455
+ onContextMenu: handleContextMenu,
456
+ onKeyDown: handleKeyDown,
416
457
  ref: rootRef,
417
458
  role: "columnheader",
418
459
  style,
@@ -425,7 +466,7 @@ var HeaderCell = ({
425
466
  };
426
467
 
427
468
  // src/Table.tsx
428
- var import_vuu_popups3 = require("@vuu-ui/vuu-popups");
469
+ var import_vuu_popups4 = require("@vuu-ui/vuu-popups");
429
470
  var import_vuu_ui_controls5 = require("@vuu-ui/vuu-ui-controls");
430
471
  var import_vuu_utils24 = require("@vuu-ui/vuu-utils");
431
472
  var import_core2 = require("@salt-ds/core");
@@ -684,10 +725,7 @@ var useTableHeader = ({
684
725
  const handleColumnHeaderClick = (0, import_react11.useCallback)(
685
726
  (evt) => {
686
727
  var _a;
687
- const targetElement = evt.target;
688
- const headerCell = targetElement.closest(
689
- ".vuuTableHeaderCell"
690
- );
728
+ const headerCell = (0, import_vuu_utils6.queryClosest)(evt.target, ".vuuTableHeaderCell");
691
729
  const colIdx = parseInt((_a = headerCell == null ? void 0 : headerCell.dataset.index) != null ? _a : "-1");
692
730
  const column = (0, import_vuu_utils6.visibleColumnAtIndex)(columns, colIdx);
693
731
  const isAdditive = evt.shiftKey;
@@ -729,6 +767,7 @@ var TableHeader = (0, import_react12.memo)(
729
767
  onRemoveGroupColumn,
730
768
  onResizeColumn,
731
769
  onSortColumn,
770
+ showColumnHeaderMenus,
732
771
  tableConfig,
733
772
  tableId,
734
773
  virtualColSpan = 0
@@ -780,7 +819,8 @@ var TableHeader = (0, import_react12.memo)(
780
819
  id: `${tableId}-col-${i}`,
781
820
  onClick,
782
821
  onMouseDown,
783
- onResize: onResizeColumn
822
+ onResize: onResizeColumn,
823
+ showMenu: showColumnHeaderMenus
784
824
  },
785
825
  col.name
786
826
  )
@@ -1768,7 +1808,7 @@ var useSelection = ({
1768
1808
  };
1769
1809
 
1770
1810
  // src/useTableContextMenu.ts
1771
- var import_vuu_popups2 = require("@vuu-ui/vuu-popups");
1811
+ var import_vuu_popups3 = require("@vuu-ui/vuu-popups");
1772
1812
  var import_vuu_utils16 = require("@vuu-ui/vuu-utils");
1773
1813
  var import_react18 = require("react");
1774
1814
  var NO_ROWS = [];
@@ -1778,7 +1818,7 @@ var useTableContextMenu = ({
1778
1818
  dataSource,
1779
1819
  getSelectedRows
1780
1820
  }) => {
1781
- const [showContextMenu] = (0, import_vuu_popups2.useContextMenu)();
1821
+ const [showContextMenu] = (0, import_vuu_popups3.useContextMenu)();
1782
1822
  const onContextMenu = (0, import_react18.useCallback)(
1783
1823
  (evt) => {
1784
1824
  const target = evt.target;
@@ -2077,6 +2117,11 @@ function updateTableConfig2(state, { confirmed, filter, groupBy, sort }) {
2077
2117
  ...state,
2078
2118
  columns: (0, import_vuu_utils17.applySortToColumns)(result.columns, sort)
2079
2119
  };
2120
+ } else if ((0, import_vuu_utils17.existingSort)(result.columns)) {
2121
+ result = {
2122
+ ...state,
2123
+ columns: (0, import_vuu_utils17.removeSort)(result.columns)
2124
+ };
2080
2125
  }
2081
2126
  if (hasFilter) {
2082
2127
  result = {
@@ -3000,7 +3045,7 @@ var useTable = ({
3000
3045
  const handleSort = (0, import_react24.useCallback)(
3001
3046
  (column, extendSort = false, sortType) => {
3002
3047
  if (dataSource) {
3003
- dataSource.sort = (0, import_vuu_utils22.applySort)(
3048
+ dataSource.sort = (0, import_vuu_utils22.toggleOrApplySort)(
3004
3049
  dataSource.sort,
3005
3050
  column,
3006
3051
  extendSort,
@@ -3359,6 +3404,7 @@ var TableCore = ({
3359
3404
  scrollingApiRef,
3360
3405
  selectionModel = "extended",
3361
3406
  showColumnHeaders = true,
3407
+ showColumnHeaderMenus = true,
3362
3408
  headerHeight = showColumnHeaders ? rowHeight * 1.25 : 0,
3363
3409
  size
3364
3410
  }) => {
@@ -3431,7 +3477,7 @@ var TableCore = ({
3431
3477
  "--viewport-body-height": `${viewportMeasurements.viewportBodyHeight}px`
3432
3478
  };
3433
3479
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
3434
- import_vuu_popups3.ContextMenuProvider,
3480
+ import_vuu_popups4.ContextMenuProvider,
3435
3481
  {
3436
3482
  menuActionHandler: handleContextMenuAction,
3437
3483
  menuBuilder,
@@ -3469,6 +3515,7 @@ var TableCore = ({
3469
3515
  onRemoveGroupColumn,
3470
3516
  onResizeColumn,
3471
3517
  onSortColumn,
3518
+ showColumnHeaderMenus,
3472
3519
  tableConfig,
3473
3520
  tableId: id,
3474
3521
  virtualColSpan: scrollProps.virtualColSpan
@@ -3527,6 +3574,7 @@ var Table = (0, import_react26.forwardRef)(function TableNext({
3527
3574
  scrollingApiRef,
3528
3575
  selectionModel,
3529
3576
  showColumnHeaders,
3577
+ showColumnHeaderMenus,
3530
3578
  headerHeight,
3531
3579
  style: styleProp,
3532
3580
  ...htmlAttributes
@@ -3542,7 +3590,6 @@ var Table = (0, import_react26.forwardRef)(function TableNext({
3542
3590
  if (dataSource === void 0) {
3543
3591
  throw Error("vuu Table requires dataSource prop");
3544
3592
  }
3545
- console.log({ rowHeight });
3546
3593
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
3547
3594
  import_vuu_ui_controls5.MeasuredContainer,
3548
3595
  {
@@ -3581,6 +3628,7 @@ var Table = (0, import_react26.forwardRef)(function TableNext({
3581
3628
  scrollingApiRef,
3582
3629
  selectionModel,
3583
3630
  showColumnHeaders,
3631
+ showColumnHeaderMenus,
3584
3632
  size
3585
3633
  }
3586
3634
  ) : null