zmdms-webui 2.3.8 → 2.3.9

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.
@@ -90,28 +90,38 @@ var useCopyToClipboard = function (params) {
90
90
  }
91
91
  return rows.join("\n");
92
92
  });
93
- // 处理复制事件
94
- var handleCopy = useMemoizedFn(function (e) {
95
- var _a;
96
- if (!cellSelection)
97
- return;
98
- var text = getSelectedCellsText();
99
- if (text) {
100
- e.preventDefault();
101
- (_a = e.clipboardData) === null || _a === void 0 ? void 0 : _a.setData("text/plain", text);
93
+ // 兼容的复制到剪贴板函数(支持HTTP环境)
94
+ var copyToClipboard = useMemoizedFn(function (text) {
95
+ // 优先使用现代 clipboard API(仅在HTTPS/localhost下可用)
96
+ if (navigator.clipboard && window.isSecureContext) {
97
+ navigator.clipboard.writeText(text).catch(function (err) {
98
+ console.error("Failed to copy with clipboard API:", err);
99
+ });
100
+ return true;
101
+ }
102
+ // 降级方案:使用 execCommand(支持HTTP环境)
103
+ try {
104
+ var textarea = document.createElement("textarea");
105
+ textarea.value = text;
106
+ textarea.style.position = "fixed";
107
+ textarea.style.opacity = "0";
108
+ textarea.style.pointerEvents = "none";
109
+ document.body.appendChild(textarea);
110
+ textarea.select();
111
+ textarea.setSelectionRange(0, textarea.value.length);
112
+ var success = document.execCommand("copy");
113
+ document.body.removeChild(textarea);
114
+ if (!success) {
115
+ console.error("Failed to copy using execCommand");
116
+ }
117
+ return success;
118
+ }
119
+ catch (err) {
120
+ console.error("Failed to copy:", err);
121
+ return false;
102
122
  }
103
123
  });
104
- // 监听复制事件
105
- useEffect(function () {
106
- var container = containerRef.current;
107
- if (!container)
108
- return;
109
- container.addEventListener("copy", handleCopy);
110
- return function () {
111
- container.removeEventListener("copy", handleCopy);
112
- };
113
- }, [handleCopy, containerRef]);
114
- // 监听键盘事件(Ctrl+C / Cmd+C)- 只在表格容器内部处理
124
+ // 监听键盘事件(Ctrl+C / Cmd+C)处理复制
115
125
  useEffect(function () {
116
126
  var container = containerRef.current;
117
127
  if (!container)
@@ -125,25 +135,21 @@ var useCopyToClipboard = function (params) {
125
135
  if (isInContainer) {
126
136
  e.preventDefault(); // 阻止默认复制行为
127
137
  var text = getSelectedCellsText();
128
- if (text && navigator.clipboard) {
129
- navigator.clipboard.writeText(text).catch(function (err) {
130
- console.error("Failed to copy:", err);
131
- });
138
+ if (text) {
139
+ copyToClipboard(text);
132
140
  }
133
141
  }
134
142
  }
135
143
  };
136
- // 监听容器的keydown事件,而不是全局window事件
137
- container.addEventListener("keydown", handleKeyDown);
138
144
  // 同时也监听全局事件,但会检查焦点位置
139
145
  document.addEventListener("keydown", handleKeyDown);
140
146
  return function () {
141
- container.removeEventListener("keydown", handleKeyDown);
142
147
  document.removeEventListener("keydown", handleKeyDown);
143
148
  };
144
- }, [cellSelection, getSelectedCellsText, containerRef]);
149
+ }, [cellSelection, getSelectedCellsText, copyToClipboard, containerRef]);
145
150
  return {
146
151
  getSelectedCellsText: getSelectedCellsText,
152
+ copyToClipboard: copyToClipboard,
147
153
  };
148
154
  };
149
155
 
@@ -706,10 +706,11 @@ var useTableInteraction = function (params) {
706
706
  // 清理状态
707
707
  setState(function (prev) {
708
708
  var updates = {};
709
+ // 注释:不再在鼠标离开时停止框选,只在鼠标松开时停止
709
710
  // 结束框选
710
- if (prev.isSelecting) {
711
- updates.isSelecting = false;
712
- }
711
+ // if (prev.isSelecting) {
712
+ // updates.isSelecting = false;
713
+ // }
713
714
  // 清理 hover
714
715
  if (prev.hoverRowIndex !== null) {
715
716
  updates.hoverRowIndex = null;
@@ -738,14 +739,16 @@ var useTableInteraction = function (params) {
738
739
  // 显示右键菜单
739
740
  menuShow({ event: e });
740
741
  });
741
- // 在document上监听拖拽事件,以支持鼠标移出canvas后继续拖拽
742
+ // 在document上监听拖拽事件和框选事件,以支持鼠标移出canvas后继续操作
742
743
  useEffect(function () {
743
744
  var isDragging = scrollState.isDraggingVertical ||
744
745
  scrollState.isDraggingHorizontal ||
745
746
  (resizeState === null || resizeState === void 0 ? void 0 : resizeState.isResizing);
746
- if (!isDragging)
747
+ var isSelecting = state.isSelecting;
748
+ if (!isDragging && !isSelecting)
747
749
  return;
748
750
  var handleDocumentMouseMove = function (e) {
751
+ var _a;
749
752
  // 获取当前实例的canvas
750
753
  var canvas = canvasRef.current;
751
754
  if (!canvas)
@@ -766,6 +769,18 @@ var useTableInteraction = function (params) {
766
769
  // 处理水平滚动条拖拽
767
770
  if (scrollState.isDraggingHorizontal) {
768
771
  handleHorizontalScrollDrag(x - scrollState.dragStartX);
772
+ return;
773
+ }
774
+ // 处理框选(在canvas外也能继续框选)
775
+ if (state.isSelecting) {
776
+ var cell = getCellFromPosition(x, y);
777
+ if (cell) {
778
+ // 检查是否在选择框列,如果是,则不更新框选
779
+ var isSelectionColumn = ((_a = columnRenderInfos[cell.col]) === null || _a === void 0 ? void 0 : _a.column.key) === "__selection__";
780
+ if (!isSelectionColumn) {
781
+ updateSelection(cell);
782
+ }
783
+ }
769
784
  }
770
785
  };
771
786
  var handleDocumentMouseUp = function () {
@@ -773,6 +788,10 @@ var useTableInteraction = function (params) {
773
788
  if ((resizeState === null || resizeState === void 0 ? void 0 : resizeState.isResizing) && endResize) {
774
789
  endResize();
775
790
  }
791
+ // 结束框选
792
+ if (state.isSelecting) {
793
+ setState(function (prev) { return (__assign(__assign({}, prev), { isSelecting: false })); });
794
+ }
776
795
  setScrollState(function (prev) { return (__assign(__assign({}, prev), { isDraggingVertical: false, isDraggingHorizontal: false })); });
777
796
  };
778
797
  document.addEventListener("mousemove", handleDocumentMouseMove);
@@ -786,10 +805,15 @@ var useTableInteraction = function (params) {
786
805
  scrollState.isDraggingVertical,
787
806
  scrollState.isDraggingHorizontal,
788
807
  resizeState === null || resizeState === void 0 ? void 0 : resizeState.isResizing,
808
+ state.isSelecting,
789
809
  updateResize,
790
810
  endResize,
791
811
  handleVerticalScrollDrag,
792
812
  handleHorizontalScrollDrag,
813
+ updateSelection,
814
+ setState,
815
+ getCellFromPosition,
816
+ columnRenderInfos,
793
817
  canvasRef,
794
818
  ]);
795
819
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmdms-webui",
3
- "version": "2.3.8",
3
+ "version": "2.3.9",
4
4
  "private": false,
5
5
  "main": "dist/index.es.js",
6
6
  "module": "dist/index.es.js",