trotl-table 1.0.68 → 1.0.70

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/Table.cjs.js CHANGED
@@ -9672,6 +9672,7 @@ function TableInner({
9672
9672
  enableExternalRowDrop = false,
9673
9673
  onExternalRowDrop = () => {},
9674
9674
  useExternalDndContext = false,
9675
+ enableMouseRightClick = null,
9675
9676
  customColumns = [],
9676
9677
  groupDefaultOpen = false,
9677
9678
  showIcons = true,
@@ -9730,9 +9731,49 @@ function TableInner({
9730
9731
  onCellChangeRef.current = onCellChange;
9731
9732
  cellCallbackRef.current = cellCallback;
9732
9733
  });
9734
+
9735
+ // Context menu right click state
9736
+ const [contextMenu, setContextMenu] = React.useState({
9737
+ visible: false,
9738
+ x: 0,
9739
+ y: 0,
9740
+ row: null
9741
+ });
9742
+ const [contextMenuModal, setContextMenuModal] = React.useState({
9743
+ visible: false,
9744
+ title: '',
9745
+ component: null
9746
+ });
9733
9747
  React.useEffect(() => {
9734
9748
  shareCallbackRef.current = shareCallback;
9735
9749
  }, [shareCallback]);
9750
+ React.useEffect(() => {
9751
+ if (!contextMenu.visible) return;
9752
+ const handleClick = () => setContextMenu({
9753
+ visible: false,
9754
+ x: 0,
9755
+ y: 0,
9756
+ row: null
9757
+ });
9758
+ const handleEscape = event => {
9759
+ if (event.key === 'Escape') {
9760
+ setContextMenu({
9761
+ visible: false,
9762
+ x: 0,
9763
+ y: 0,
9764
+ row: null
9765
+ });
9766
+ }
9767
+ };
9768
+ window.addEventListener('click', handleClick);
9769
+ window.addEventListener('contextmenu', handleClick);
9770
+ window.addEventListener('keydown', handleEscape);
9771
+ return () => {
9772
+ window.removeEventListener('click', handleClick);
9773
+ window.removeEventListener('contextmenu', handleClick);
9774
+ window.removeEventListener('keydown', handleEscape);
9775
+ };
9776
+ }, [contextMenu.visible]);
9736
9777
  React.useEffect(() => {
9737
9778
  duplicateCallbackRef.current = duplicateCallback;
9738
9779
  }, [duplicateCallback]);
@@ -9845,6 +9886,43 @@ function TableInner({
9845
9886
  setSelectedRows(prev => prev.includes(rowId) ? prev.filter(r => r !== rowId) : [...prev, rowId]);
9846
9887
  }, []);
9847
9888
  const clearSelection = React.useCallback(() => setSelectedRows([]), []);
9889
+ const performContextMenuAction = React.useCallback((action, row) => {
9890
+ setContextMenu({
9891
+ visible: false,
9892
+ x: 0,
9893
+ y: 0,
9894
+ row: null
9895
+ });
9896
+ if (!action) return;
9897
+ if (action.onClick && typeof action.onClick === "function") {
9898
+ action.onClick(row, action);
9899
+ return;
9900
+ }
9901
+ if (action.isModal) {
9902
+ setContextMenuModal({
9903
+ visible: true,
9904
+ title: action.label || "",
9905
+ component: action.component || null
9906
+ });
9907
+ return;
9908
+ }
9909
+ if (action.link) {
9910
+ window.open(action.link, action.target || "_blank");
9911
+ return;
9912
+ }
9913
+
9914
+ // fallback: provide simple event for the row itself.
9915
+ if (action.label) {
9916
+ console.log(`context action ${action.label} invoked`, row);
9917
+ }
9918
+ }, []);
9919
+ const closeContextMenuModal = React.useCallback(() => {
9920
+ setContextMenuModal({
9921
+ visible: false,
9922
+ title: '',
9923
+ component: null
9924
+ });
9925
+ }, []);
9848
9926
  const setSort = column => {
9849
9927
  setSorting(prev => {
9850
9928
  if (!prev || prev.column !== column) return {
@@ -10772,7 +10850,18 @@ function TableInner({
10772
10850
  const content = /*#__PURE__*/React.createElement("div", {
10773
10851
  key: key,
10774
10852
  style: style,
10775
- className: "table-row"
10853
+ className: "table-row",
10854
+ onContextMenu: e => {
10855
+ if (!Array.isArray(enableMouseRightClick) || enableMouseRightClick.length === 0) return;
10856
+ e.preventDefault();
10857
+ e.stopPropagation();
10858
+ setContextMenu({
10859
+ visible: true,
10860
+ x: e.clientX,
10861
+ y: e.clientY,
10862
+ row
10863
+ });
10864
+ }
10776
10865
  }, /*#__PURE__*/React.createElement("div", {
10777
10866
  className: "row-main",
10778
10867
  onDoubleClick: doubleClickEnable ? handleRowDoubleClick : undefined,
@@ -10887,6 +10976,8 @@ function TableInner({
10887
10976
  }
10888
10977
  return content;
10889
10978
  }, [tableDataFlat, columns, selectedRows, toggleRowSelection, groupRowsById, renderCell, showActions, showDelete, showEdit, showKey, showView, translate, enableDragRow, moveRow, enableMultiSelect, rowHeight, tableId, customColumns, doubleClickEnable, keyWidth, actionColumnStyle, showDuplicate, showDownload, showIcons, showShare, triggerCellCallback, getAccessorKey, getAccessorValue]);
10979
+ const rightClickActions = Array.isArray(enableMouseRightClick) ? enableMouseRightClick : [];
10980
+ const [hoveredActionIndex, setHoveredActionIndex] = React.useState(null);
10890
10981
  const rowHeightGetter = ({
10891
10982
  index
10892
10983
  }) => tableDataFlat[index]?.type === "group" ? groupHeaderHeight : rowHeight;
@@ -11015,7 +11106,49 @@ function TableInner({
11015
11106
  showCancel: true,
11016
11107
  showConfirm: true
11017
11108
  }, /*#__PURE__*/React.createElement("p", null, translate("areYouSureYouWantToDelete"), " ", /*#__PURE__*/React.createElement("strong", null, pendingDelete ? pendingDelete[deleteLabelKey] ?? pendingDelete.name ?? pendingDelete.id : ''), "?")));
11018
- return tableMarkup;
11109
+ const contextMenuMarkup = contextMenu.visible && rightClickActions.length > 0 ? /*#__PURE__*/React.createElement("div", {
11110
+ style: {
11111
+ position: 'fixed',
11112
+ top: contextMenu.y,
11113
+ left: contextMenu.x,
11114
+ backgroundColor: '#fff',
11115
+ border: '1px solid #ccc',
11116
+ boxShadow: '0 2px 8px rgba(0,0,0,.15)',
11117
+ zIndex: 9999,
11118
+ minWidth: 160,
11119
+ padding: 0,
11120
+ borderRadius: 4
11121
+ },
11122
+ onContextMenu: e => e.preventDefault()
11123
+ }, rightClickActions.map((action, i) => /*#__PURE__*/React.createElement("div", {
11124
+ key: i,
11125
+ style: {
11126
+ padding: '8px 12px',
11127
+ cursor: 'pointer',
11128
+ borderBottom: i < rightClickActions.length - 1 ? '1px solid #eee' : 'none',
11129
+ backgroundColor: hoveredActionIndex === i ? '#f5f5f5' : '#fff',
11130
+ color: hoveredActionIndex === i ? '#000' : '#333'
11131
+ },
11132
+ onMouseEnter: () => setHoveredActionIndex(i),
11133
+ onMouseLeave: () => setHoveredActionIndex(null),
11134
+ onClick: () => performContextMenuAction(action, contextMenu.row)
11135
+ }, action.label || action.text || `Action ${i + 1}`))) : null;
11136
+ const contextMenuModalMarkup = contextMenuModal.visible && contextMenuModal.component ? /*#__PURE__*/React.createElement(Modal.default, {
11137
+ isOpen: true,
11138
+ title: contextMenuModal.title || '',
11139
+ onConfirm: () => setContextMenuModal({
11140
+ visible: false,
11141
+ title: '',
11142
+ component: null
11143
+ }),
11144
+ onCancel: () => closeContextMenuModal(),
11145
+ showConfirm: false,
11146
+ showCancel: true,
11147
+ cancelLabel: translate('cancel')
11148
+ }, typeof contextMenuModal.component === 'function' ? /*#__PURE__*/React.createElement(contextMenuModal.component, {
11149
+ row: contextMenu.row
11150
+ }) : contextMenuModal.component) : null;
11151
+ return /*#__PURE__*/React.createElement(React.Fragment, null, tableMarkup, contextMenuMarkup, contextMenuModalMarkup);
11019
11152
  }
11020
11153
  function Table(props) {
11021
11154
  const {