ztxkui 4.2.23-631 → 4.2.23-633

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.
@@ -21,7 +21,7 @@ export var COLORS = {
21
21
  selectionBg: 'rgba(24, 144, 255, 0.1)',
22
22
  text: '#333333',
23
23
  secondaryText: '#999999',
24
- border: '#f0f0f0',
24
+ border: '#ebebeb',
25
25
  primary: '#1890ff',
26
26
  scrollbarTrack: '#f0f0f0',
27
27
  scrollbarThumb: '#bfbfbf',
@@ -25,7 +25,8 @@ function drawTextCell(ctx, cell, useHeaderAlign) {
25
25
  }
26
26
  ctx.fillStyle = COLORS.text;
27
27
  // 换行绘制(垂直居中多行;超出单元格高度被 clip 裁剪)
28
- if (cell.wrap && cell.text) {
28
+ // 含显式换行符:按换行符分段(表头"复制整列"两行布局),其余同 wrap 逻辑
29
+ if (cell.text && (cell.wrap || cell.text.indexOf('\n') >= 0)) {
29
30
  var lines = wrapText(ctx, cell.text, availWidth);
30
31
  var lineHeight_1 = FONT_SIZE + 5;
31
32
  var totalH = lines.length * lineHeight_1;
@@ -43,18 +44,16 @@ function drawTextCell(ctx, cell, useHeaderAlign) {
43
44
  }
44
45
  function drawHeaderIcons(ctx, cell) {
45
46
  var _a;
46
- if (!cell.canSort && !cell.hasFilter)
47
+ if (!cell.canSort && !cell.hasFilter && !cell.canCopy)
47
48
  return;
48
49
  var centerY = cell.y + cell.height / 2;
49
- // 图标布局与 hitTest.getHeaderIconAt 一致:筛选中心 width-10,排序中心 width-25
50
+ // 图标布局与 hitTest.getHeaderIconAt 一致:
51
+ // filter 中心 width-10;sort 无 copy 时 width-25、有 copy 时 width-29;copy 中心 width-47
50
52
  if (cell.hasFilter) {
51
53
  drawFilterIcon(ctx, cell.x + cell.width - 10, centerY, !!cell.filterActive);
52
54
  }
53
55
  if (cell.canSort) {
54
- var sortCenterX = cell.hasFilter
55
- ? cell.x + cell.width - 25
56
- : cell.x + cell.width - 10;
57
- drawSortIcon(ctx, sortCenterX, centerY, (_a = cell.sortState) !== null && _a !== void 0 ? _a : null);
56
+ drawSortIcon(ctx, cell.x + cell.width - (cell.hasFilter ? 29 : 10), centerY, (_a = cell.sortState) !== null && _a !== void 0 ? _a : null);
58
57
  }
59
58
  }
60
59
  /** 展开图标占位宽度(缩进 + 图标区),用于文本偏移 */
@@ -139,6 +138,39 @@ function drawSelectionHighlight(ctx, scene) {
139
138
  ctx.strokeRect(xStart + 0.5, yTop + 0.5, xEnd - xStart - 1, yBottom - yTop - 1);
140
139
  }
141
140
  }
141
+ /**
142
+ * 表头框选高亮(表头支持选入框选用于复制表头,绘制在表头内容之上)。
143
+ * 仅当选区包含表头行(minRow < 0)时绘制,覆盖选列范围内的整条表头带
144
+ */
145
+ function drawHeaderSelectionHighlight(ctx, scene) {
146
+ var sel = scene.cellSelection;
147
+ if (!sel)
148
+ return;
149
+ var minRow = Math.min(sel.startRow, sel.endRow);
150
+ if (minRow >= 0)
151
+ return;
152
+ var minCol = Math.min(sel.startCol, sel.endCol);
153
+ var maxCol = Math.max(sel.startCol, sel.endCol);
154
+ var xStart = Infinity;
155
+ var xEnd = -Infinity;
156
+ for (var _i = 0, _a = scene.layouts; _i < _a.length; _i++) {
157
+ var layout = _a[_i];
158
+ if (layout.index < minCol || layout.index > maxCol)
159
+ continue;
160
+ var drawX = layout.fixed
161
+ ? layout.fixedLeft
162
+ : layout.x - scene.scrollLeft;
163
+ xStart = Math.min(xStart, drawX);
164
+ xEnd = Math.max(xEnd, drawX + layout.width);
165
+ }
166
+ if (xEnd === -Infinity)
167
+ return;
168
+ ctx.fillStyle = COLORS.selectionBg;
169
+ ctx.fillRect(xStart, 0, xEnd - xStart, scene.headerHeight);
170
+ ctx.strokeStyle = COLORS.primary;
171
+ ctx.lineWidth = 1;
172
+ ctx.strokeRect(xStart + 0.5, 0.5, xEnd - xStart - 1, scene.headerHeight - 1);
173
+ }
142
174
  /**
143
175
  * 主绘制入口。ctx 的 DPR 变换由外部管理,这里只负责画内容
144
176
  */
@@ -358,7 +390,18 @@ export function drawScene(ctx, scene) {
358
390
  drawCheckbox(ctx, cell.x + cell.width / 2, cell.y + cell.height / 2, isAll, false, isIndeterminate);
359
391
  }
360
392
  else if (cell.kind === 'text') {
361
- if (!cell.isDynamicButton) {
393
+ if (cell.canCopy) {
394
+ // 复制整列:两行表头(标题 #333 + “复制整列” link 蓝,点击蓝字触发复制)
395
+ var cxm = cell.x + cell.width / 2;
396
+ ctx.textAlign = 'center';
397
+ ctx.textBaseline = 'middle';
398
+ ctx.fillStyle = COLORS.text;
399
+ ctx.fillText((cell.text || '').split('\n')[0], cxm, cell.y + 10);
400
+ ctx.fillStyle = COLORS.primary;
401
+ ctx.fillText('复制整列', cxm, cell.y + 26);
402
+ drawHeaderIcons(ctx, cell);
403
+ }
404
+ else if (!cell.isDynamicButton) {
362
405
  drawTextCell(ctx, cell, true);
363
406
  drawHeaderIcons(ctx, cell);
364
407
  }
@@ -390,6 +433,8 @@ export function drawScene(ctx, scene) {
390
433
  };
391
434
  drawHeaderPass(false);
392
435
  drawHeaderPass(true);
436
+ // ---- 表头框选高亮(表头选入选区时,覆盖在表头内容之上)----
437
+ drawHeaderSelectionHighlight(ctx, scene);
393
438
  // ---- 列宽调整手柄 ----
394
439
  if (scene.resizeHoverIndex !== null || scene.resizeActiveIndex !== null) {
395
440
  for (var _c = 0, layouts_2 = layouts; _c < layouts_2.length; _c++) {
@@ -416,7 +461,7 @@ export function drawScene(ctx, scene) {
416
461
  }
417
462
  }
418
463
  }
419
- // ---- 固定列阴影(常显,antd 风格 inset 渐变)----
464
+ // ---- 固定列阴影(仅在固定列覆盖到滚动内容时显示,antd 风格 inset 渐变)----
420
465
  var drawFixedShadow = function (edgeX, dir) {
421
466
  var gradient = ctx.createLinearGradient(edgeX, 0, edgeX + dir * 20, 0);
422
467
  gradient.addColorStop(0, 'rgba(0, 0, 0, 0.08)');
@@ -424,10 +469,13 @@ export function drawScene(ctx, scene) {
424
469
  ctx.fillStyle = gradient;
425
470
  ctx.fillRect(Math.min(edgeX, edgeX + dir * 20), 0, 20, height);
426
471
  };
427
- if (fixedLeftRightEdge > 0) {
472
+ // 左固定列:横向已滚动(盖住了左侧滚出的内容)才显示右缘阴影
473
+ if (fixedLeftRightEdge > 0 && scrollLeft > 0) {
428
474
  drawFixedShadow(fixedLeftRightEdge, 1);
429
475
  }
430
- if (fixedRightZoneLeft !== Infinity) {
476
+ // 右固定列:还能向右滚(右固定列盖住了右侧内容)才显示左缘阴影
477
+ if (fixedRightZoneLeft !== Infinity &&
478
+ scrollLeft < metrics.maxScrollLeft - 1) {
431
479
  drawFixedShadow(fixedRightZoneLeft, -1);
432
480
  }
433
481
  // ---- 最外层边框(bordered)----
@@ -38,6 +38,8 @@ export interface SceneCell {
38
38
  /** 表头功能图标(仅最末级表头) */
39
39
  canSort?: boolean;
40
40
  hasFilter?: boolean;
41
+ /** 表头复制整列图标 */
42
+ canCopy?: boolean;
41
43
  sortState?: SortOrder;
42
44
  filterActive?: boolean;
43
45
  /** 角标 */
@@ -34,7 +34,10 @@ function resolveRendered(renderCache, column, value, record, rowIndex, cacheKey)
34
34
  return node;
35
35
  }
36
36
  function resolveAlign(column) {
37
- return column.align || 'left';
37
+ if (column.align)
38
+ return column.align;
39
+ // 设置了 precision 的数值列默认靠右(对齐业务 Table 数值展示习惯)
40
+ return column.precision !== undefined ? 'right' : 'left';
38
41
  }
39
42
  function resolveHeaderAlign(column, globalAlign) {
40
43
  return column.headerAlign || globalAlign;
@@ -182,14 +185,20 @@ export function buildScene(params) {
182
185
  !isDynamicButton &&
183
186
  column.sorter !== false,
184
187
  hasFilter: isLeaf && !isSelection && !isIndex && !isDynamicButton,
188
+ canCopy: isLeaf &&
189
+ !isSelection &&
190
+ !isIndex &&
191
+ !isDynamicButton &&
192
+ !!column.showCopy,
185
193
  sortState: column.key === sortField ? sortOrder : null,
186
194
  filterActive: !!(filters[column.key] && filters[column.key].length > 0),
187
195
  isDynamicButton: isDynamicButton,
188
196
  wrap: isLeaf && (!!column.wrap || !!headerWrapParam),
189
197
  };
190
198
  if (titleIsText) {
191
- cell.text =
192
- column.title === undefined ? column.key : String(column.title);
199
+ var baseTitle = column.title === undefined ? column.key : String(column.title);
200
+ // 复制整列:标题下方换行显示文字按钮(绘制端配合两行布局)
201
+ cell.text = column.showCopy ? baseTitle + '\n复制整列' : baseTitle;
193
202
  }
194
203
  else {
195
204
  cell.kind = 'overlay';
@@ -7,5 +7,6 @@ export declare function useColumnWidths<T = any>(params: {
7
7
  }): {
8
8
  applyColumnWidth: (columns: IColumnType<T>[]) => IColumnType<T>[];
9
9
  setColumnWidth: (column: IColumnType<T>, width: number) => void;
10
+ manualWidths: Record<string, number>;
10
11
  manualKeys: Set<string>;
11
12
  };
@@ -46,5 +46,5 @@ export function useColumnWidths(params) {
46
46
  });
47
47
  onColumnResize === null || onColumnResize === void 0 ? void 0 : onColumnResize(column.key, width);
48
48
  }, [onColumnResize]);
49
- return { applyColumnWidth: applyColumnWidth, setColumnWidth: setColumnWidth, manualKeys: manualKeys };
49
+ return { applyColumnWidth: applyColumnWidth, setColumnWidth: setColumnWidth, manualWidths: manualWidths, manualKeys: manualKeys };
50
50
  }
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { ICellSelection, IRowSelection, SortOrder } from '../interface';
2
+ import { ICellSelection, IColumnType, IRowSelection, SortOrder } from '../interface';
3
3
  import { Scene } from '../draw/scene';
4
4
  import { ScrollbarMetrics } from '../utils/layout';
5
5
  import { FlatRowMeta } from './useExpandable';
@@ -44,6 +44,8 @@ export declare function useInteractions<T = any>(params: {
44
44
  } | null>;
45
45
  /** 非受控模式的内部勾选 keys(rowSelection 未传 selectedRowKeys 时以它为准) */
46
46
  internalKeysRef: React.MutableRefObject<React.Key[]>;
47
+ /** 点击表头“复制整列”图标回调 */
48
+ onCopyColumn?: (column: IColumnType<any>) => void;
47
49
  setHoverRow: (row: number | null) => void;
48
50
  setTooltip: (tip: {
49
51
  visible: boolean;
@@ -34,12 +34,15 @@ export function nextSortOrder(clickedUp, current) {
34
34
  * mousemove/mouseup 常驻注册一次(读 ref 判定),canvas 事件只做入口分发
35
35
  */
36
36
  export function useInteractions(params) {
37
- var canvasRef = params.canvasRef, sceneRef = params.sceneRef, metricsRef = params.metricsRef, dragRef = params.dragRef, commitScroll = params.commitScroll, commitScrollLazy = params.commitScrollLazy, setHoverAtom = params.setHoverAtom, hoverAtomRef = params.hoverAtomRef, internalKeysRef = params.internalKeysRef, setHoverRow = params.setHoverRow, setTooltip = params.setTooltip, setCellSelection = params.setCellSelection, cellSelectionRef = params.cellSelectionRef, onCellSelectionChangeRef = params.onCellSelectionChangeRef, setFilterPopover = params.setFilterPopover, setBadgePopover = params.setBadgePopover, expandRef = params.expandRef, setSort = params.setSort, sortRef = params.sortRef, rowSelectionRef = params.rowSelectionRef, getRowKeyRef = params.getRowKeyRef, dataSourceRef = params.dataSourceRef, setInternalSelectedKeys = params.setInternalSelectedKeys, resizingRef = params.resizingRef, onResizeMove = params.onResizeMove, onResizeEnd = params.onResizeEnd, callbacksRef = params.callbacksRef;
37
+ var canvasRef = params.canvasRef, sceneRef = params.sceneRef, metricsRef = params.metricsRef, dragRef = params.dragRef, commitScroll = params.commitScroll, commitScrollLazy = params.commitScrollLazy, setHoverAtom = params.setHoverAtom, hoverAtomRef = params.hoverAtomRef, internalKeysRef = params.internalKeysRef, onCopyColumn = params.onCopyColumn, setHoverRow = params.setHoverRow, setTooltip = params.setTooltip, setCellSelection = params.setCellSelection, cellSelectionRef = params.cellSelectionRef, onCellSelectionChangeRef = params.onCellSelectionChangeRef, setFilterPopover = params.setFilterPopover, setBadgePopover = params.setBadgePopover, expandRef = params.expandRef, setSort = params.setSort, sortRef = params.sortRef, rowSelectionRef = params.rowSelectionRef, getRowKeyRef = params.getRowKeyRef, dataSourceRef = params.dataSourceRef, setInternalSelectedKeys = params.setInternalSelectedKeys, resizingRef = params.resizingRef, onResizeMove = params.onResizeMove, onResizeEnd = params.onResizeEnd, callbacksRef = params.callbacksRef;
38
38
  // 本 hook 内部的拖拽模式(select / resize 独立于滚动条拖拽)
39
39
  var modeRef = useRef('none');
40
40
  var selectStartRef = useRef(null);
41
41
  var movedRef = useRef(false);
42
42
  var hoverRowRef = useRef(null);
43
+ // 列宽拖拽:mousemove 合并到动画帧(大数据量下避免每帧全量重渲),松手时 flush
44
+ var pendingResizeRef = useRef(null);
45
+ var resizeRafRef = useRef(null);
43
46
  var notifySelection = useCallback(function (sel, notifyBusiness) {
44
47
  var _a;
45
48
  if (notifyBusiness === void 0) { notifyBusiness = true; }
@@ -267,6 +270,12 @@ export function useInteractions(params) {
267
270
  else if (iconHit.type === 'filter') {
268
271
  openFilter(iconHit.colIndex);
269
272
  }
273
+ else if (iconHit.type === 'copy') {
274
+ window.__probe = { routedCopy: true };
275
+ var layout = scene.layouts[iconHit.colIndex];
276
+ if (layout)
277
+ onCopyColumn === null || onCopyColumn === void 0 ? void 0 : onCopyColumn(layout.column);
278
+ }
270
279
  else {
271
280
  handleSort(iconHit.colIndex, iconHit.type === 'sort-up');
272
281
  }
@@ -451,7 +460,19 @@ export function useInteractions(params) {
451
460
  // 拖拽分发
452
461
  if (mode === 'resize' && resizingRef.current) {
453
462
  var _e = resizingRef.current, colIndex = _e.colIndex, startX = _e.startX, startWidth = _e.startWidth;
454
- onResizeMove(colIndex, Math.max(MIN_COLUMN_WIDTH, startWidth + x - startX));
463
+ pendingResizeRef.current = {
464
+ colIndex: colIndex,
465
+ width: Math.max(MIN_COLUMN_WIDTH, startWidth + x - startX),
466
+ };
467
+ // 合并到下一动画帧:高频 mousemove 只触发一次重渲
468
+ if (resizeRafRef.current === null) {
469
+ resizeRafRef.current = requestAnimationFrame(function () {
470
+ resizeRafRef.current = null;
471
+ var pending = pendingResizeRef.current;
472
+ if (pending)
473
+ onResizeMove(pending.colIndex, pending.width);
474
+ });
475
+ }
455
476
  canvasEl.style.cursor = 'col-resize';
456
477
  return;
457
478
  }
@@ -619,9 +640,13 @@ export function useInteractions(params) {
619
640
  if (sceneCell && sceneCell.kind === 'atoms' && sceneCell.atoms) {
620
641
  // renderToCanvas 协议:命中链接 → 指针 + hover 下划线
621
642
  var hitIdx = hitTestAtoms(sceneCell.atoms.layout, x - sceneCell.x, y - sceneCell.y, sceneCell.width, sceneCell.height);
622
- canvasEl.style.cursor = hitIdx >= 0 ? 'pointer' : 'default';
643
+ var hitAtom = hitIdx >= 0 ? sceneCell.atoms.atoms[hitIdx] : null;
644
+ var isClickable = !!hitAtom && hitAtom.type === 'link' && !hitAtom.disabled;
645
+ canvasEl.style.cursor = isClickable ? 'pointer' : 'default';
623
646
  var prev = hoverAtomRef.current;
624
- var next = hitIdx >= 0 ? { row: cell.row, col: cell.col, index: hitIdx } : null;
647
+ var next = isClickable
648
+ ? { row: cell.row, col: cell.col, index: hitIdx }
649
+ : null;
625
650
  var same = prev && next
626
651
  ? prev.row === next.row &&
627
652
  prev.col === next.col &&
@@ -629,6 +654,13 @@ export function useInteractions(params) {
629
654
  : prev === next;
630
655
  if (!same)
631
656
  setHoverAtom(next);
657
+ // 任意原子带 title:hover 出悬浮提示(与 link 下划线互不影响)
658
+ if (hitAtom && hitAtom.title) {
659
+ setTooltip({ visible: true, content: hitAtom.title, x: x, y: y });
660
+ }
661
+ else {
662
+ setTooltip({ visible: false, content: '', x: 0, y: 0 });
663
+ }
632
664
  return;
633
665
  }
634
666
  if (sceneCell &&
@@ -666,6 +698,15 @@ export function useInteractions(params) {
666
698
  var _a, _b, _c, _d, _e;
667
699
  var mode = modeRef.current;
668
700
  if (mode === 'resize') {
701
+ // flush 未执行的动画帧回调,确保落点宽度生效(onResizeEnd 的函数式更新在其后读取最新值)
702
+ if (resizeRafRef.current !== null) {
703
+ cancelAnimationFrame(resizeRafRef.current);
704
+ resizeRafRef.current = null;
705
+ var pending_1 = pendingResizeRef.current;
706
+ if (pending_1)
707
+ onResizeMove(pending_1.colIndex, pending_1.width);
708
+ pendingResizeRef.current = null;
709
+ }
669
710
  var info = resizingRef.current;
670
711
  resizingRef.current = null;
671
712
  modeRef.current = 'none';
@@ -730,6 +771,7 @@ export function useInteractions(params) {
730
771
  }, [
731
772
  dragRef,
732
773
  resizingRef,
774
+ onResizeMove,
733
775
  onResizeEnd,
734
776
  sceneRef,
735
777
  metricsRef,