@guozhi5658/srp-table 1.1.4 → 1.1.5

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -1022,8 +1022,36 @@ const StyledArtTableWrapper = styled__default.div `
1022
1022
  //#endregion
1023
1023
  `;
1024
1024
 
1025
+ /** 内联的空状态插图(原 img.alicdn.com 上的同一张 SVG),避免渲染空表格时发起外部网络请求 */
1026
+ function EmptyImage() {
1027
+ return (React.createElement("svg", { className: "empty-image", role: "img", "aria-label": "empty-image", width: "50", height: "50", viewBox: "0 0 50 50" },
1028
+ React.createElement("defs", null,
1029
+ React.createElement("path", { d: "M.008 3.68v23.456l17.808-4.963.366-22.165L.008 3.68z", id: "srp-empty-a" }),
1030
+ React.createElement("linearGradient", { x1: "33.757%", y1: "68.854%", x2: "80.209%", y2: "31.388%", id: "srp-empty-b" },
1031
+ React.createElement("stop", { stopColor: "#7B8594", stopOpacity: ".2", offset: "0%" }),
1032
+ React.createElement("stop", { stopColor: "#8C96A5", stopOpacity: ".4", offset: "100%" })),
1033
+ React.createElement("linearGradient", { x1: "50%", y1: "60.911%", x2: "50%", y2: "0%", id: "srp-empty-c" },
1034
+ React.createElement("stop", { stopColor: "#B0B8C2", stopOpacity: ".2", offset: "0%" }),
1035
+ React.createElement("stop", { stopColor: "#8992A1", stopOpacity: ".2", offset: "100%" }))),
1036
+ React.createElement("g", { fill: "none", fillRule: "evenodd" },
1037
+ React.createElement("circle", { fillOpacity: ".04", fill: "#1F3858", cx: "25", cy: "25", r: "25" }),
1038
+ React.createElement("path", { d: "M25.052 21.613v23.455l17.807-4.963.366-22.164-18.173 3.672z", fill: "#E0E4E9", opacity: ".96" }),
1039
+ React.createElement("use", { fill: "#E0E4E9", xlinkHref: "#srp-empty-a", transform: "translate(25.043 17.933)" }),
1040
+ React.createElement("path", { fill: "#E0E4E9", d: "M5.38 19.338V40.83l19.767 4.27-.131-23.426z" }),
1041
+ React.createElement("path", { fill: "url(#srp-empty-b)", opacity: ".6", transform: "matrix(1 0 0 -1 5 48.762)", d: "M.456 7.927L0 28.729l19.39-2.121V3.783z" }),
1042
+ React.createElement("path", { fill: "url(#srp-empty-c)", d: "M19.493 5.517v23.38l18.357-5.018.578-22.15z", transform: "translate(5 16.25)" }),
1043
+ React.createElement("path", { fill: "#A4AFBF", opacity: ".8", d: "M5.102 19.467l17.003-3.184 21.336 1.702-18.35 3.67z" }),
1044
+ React.createElement("path", { fill: "#9EA7B3", opacity: ".8", d: "M22.105 21.654v-5.37l21.336 1.7-18.35 3.67z" }),
1045
+ React.createElement("path", { fill: "#F3F4F5", d: "M25.058 21.663l6.152 8.96 18.376-5.081-6.147-7.562z" }),
1046
+ React.createElement("path", { fill: "#FFF", opacity: ".1", d: "M49.586 25.542L43.44 17.98l-18.381 3.683 6.152 8.96z" }),
1047
+ React.createElement("path", { fill: "#F3F4F5", d: "M5.121 19.47l-4.51 8.165 20.125 3.38 4.304-9.355z" }),
1048
+ React.createElement("path", { fill: "#FFF", opacity: ".1", d: "M20.736 31.016l4.304-9.356-19.919-2.19-4.51 8.165z" }),
1049
+ React.createElement("path", { d: "M7.465.327s.31 7.984 5.255 10.119c4.946 2.134 10.727-1.347 10.727-1.347s-7.445-3.635-8.152-6.672c-4.63.725-7.83-2.1-7.83-2.1z", fill: "#FFF" }),
1050
+ React.createElement("path", { d: "M8.369 5.029s2.201 2.844 5.68 2.54c1.816 2.823 7.532 2.462 7.532 2.462s-4.541 2.134-8.043.988c-3.503-1.145-5.17-5.99-5.17-5.99z", fill: "#CFD4DB" }),
1051
+ React.createElement("path", { d: "M33.426 9.209c.877.466 3.192.205 4.399-.207-.512.963-1.56 2.314-2.757 3.614-.755.82-2.013 1.64-3.18 2.009-1.898.165-3.603-.37-3.603-.37s3.509-1.977 5.14-5.046z", fill: "#FFF" }))));
1052
+ }
1025
1053
  const DefaultEmptyContent = React.memo(() => (React.createElement(React.Fragment, null,
1026
- React.createElement("img", { alt: "empty-image", className: "empty-image", src: "//img.alicdn.com/tfs/TB1l1LcM3HqK1RjSZJnXXbNLpXa-50-50.svg" }),
1054
+ React.createElement(EmptyImage, null),
1027
1055
  React.createElement("div", { className: "empty-tips" },
1028
1056
  "\u6CA1\u6709\u7B26\u5408\u67E5\u8BE2\u6761\u4EF6\u7684\u6570\u636E",
1029
1057
  React.createElement("br", null),
@@ -1049,8 +1049,36 @@ const StyledArtTableWrapper = styled__default["default"].div `
1049
1049
  //#endregion
1050
1050
  `;
1051
1051
 
1052
+ /** 内联的空状态插图(原 img.alicdn.com 上的同一张 SVG),避免渲染空表格时发起外部网络请求 */
1053
+ function EmptyImage() {
1054
+ return (React__default["default"].createElement("svg", { className: "empty-image", role: "img", "aria-label": "empty-image", width: "50", height: "50", viewBox: "0 0 50 50" },
1055
+ React__default["default"].createElement("defs", null,
1056
+ React__default["default"].createElement("path", { d: "M.008 3.68v23.456l17.808-4.963.366-22.165L.008 3.68z", id: "srp-empty-a" }),
1057
+ React__default["default"].createElement("linearGradient", { x1: "33.757%", y1: "68.854%", x2: "80.209%", y2: "31.388%", id: "srp-empty-b" },
1058
+ React__default["default"].createElement("stop", { stopColor: "#7B8594", stopOpacity: ".2", offset: "0%" }),
1059
+ React__default["default"].createElement("stop", { stopColor: "#8C96A5", stopOpacity: ".4", offset: "100%" })),
1060
+ React__default["default"].createElement("linearGradient", { x1: "50%", y1: "60.911%", x2: "50%", y2: "0%", id: "srp-empty-c" },
1061
+ React__default["default"].createElement("stop", { stopColor: "#B0B8C2", stopOpacity: ".2", offset: "0%" }),
1062
+ React__default["default"].createElement("stop", { stopColor: "#8992A1", stopOpacity: ".2", offset: "100%" }))),
1063
+ React__default["default"].createElement("g", { fill: "none", fillRule: "evenodd" },
1064
+ React__default["default"].createElement("circle", { fillOpacity: ".04", fill: "#1F3858", cx: "25", cy: "25", r: "25" }),
1065
+ React__default["default"].createElement("path", { d: "M25.052 21.613v23.455l17.807-4.963.366-22.164-18.173 3.672z", fill: "#E0E4E9", opacity: ".96" }),
1066
+ React__default["default"].createElement("use", { fill: "#E0E4E9", xlinkHref: "#srp-empty-a", transform: "translate(25.043 17.933)" }),
1067
+ React__default["default"].createElement("path", { fill: "#E0E4E9", d: "M5.38 19.338V40.83l19.767 4.27-.131-23.426z" }),
1068
+ React__default["default"].createElement("path", { fill: "url(#srp-empty-b)", opacity: ".6", transform: "matrix(1 0 0 -1 5 48.762)", d: "M.456 7.927L0 28.729l19.39-2.121V3.783z" }),
1069
+ React__default["default"].createElement("path", { fill: "url(#srp-empty-c)", d: "M19.493 5.517v23.38l18.357-5.018.578-22.15z", transform: "translate(5 16.25)" }),
1070
+ React__default["default"].createElement("path", { fill: "#A4AFBF", opacity: ".8", d: "M5.102 19.467l17.003-3.184 21.336 1.702-18.35 3.67z" }),
1071
+ React__default["default"].createElement("path", { fill: "#9EA7B3", opacity: ".8", d: "M22.105 21.654v-5.37l21.336 1.7-18.35 3.67z" }),
1072
+ React__default["default"].createElement("path", { fill: "#F3F4F5", d: "M25.058 21.663l6.152 8.96 18.376-5.081-6.147-7.562z" }),
1073
+ React__default["default"].createElement("path", { fill: "#FFF", opacity: ".1", d: "M49.586 25.542L43.44 17.98l-18.381 3.683 6.152 8.96z" }),
1074
+ React__default["default"].createElement("path", { fill: "#F3F4F5", d: "M5.121 19.47l-4.51 8.165 20.125 3.38 4.304-9.355z" }),
1075
+ React__default["default"].createElement("path", { fill: "#FFF", opacity: ".1", d: "M20.736 31.016l4.304-9.356-19.919-2.19-4.51 8.165z" }),
1076
+ React__default["default"].createElement("path", { d: "M7.465.327s.31 7.984 5.255 10.119c4.946 2.134 10.727-1.347 10.727-1.347s-7.445-3.635-8.152-6.672c-4.63.725-7.83-2.1-7.83-2.1z", fill: "#FFF" }),
1077
+ React__default["default"].createElement("path", { d: "M8.369 5.029s2.201 2.844 5.68 2.54c1.816 2.823 7.532 2.462 7.532 2.462s-4.541 2.134-8.043.988c-3.503-1.145-5.17-5.99-5.17-5.99z", fill: "#CFD4DB" }),
1078
+ React__default["default"].createElement("path", { d: "M33.426 9.209c.877.466 3.192.205 4.399-.207-.512.963-1.56 2.314-2.757 3.614-.755.82-2.013 1.64-3.18 2.009-1.898.165-3.603-.37-3.603-.37s3.509-1.977 5.14-5.046z", fill: "#FFF" }))));
1079
+ }
1052
1080
  const DefaultEmptyContent = React__default["default"].memo(() => (React__default["default"].createElement(React__default["default"].Fragment, null,
1053
- React__default["default"].createElement("img", { alt: "empty-image", className: "empty-image", src: "//img.alicdn.com/tfs/TB1l1LcM3HqK1RjSZJnXXbNLpXa-50-50.svg" }),
1081
+ React__default["default"].createElement(EmptyImage, null),
1054
1082
  React__default["default"].createElement("div", { className: "empty-tips" },
1055
1083
  "\u6CA1\u6709\u7B26\u5408\u67E5\u8BE2\u6761\u4EF6\u7684\u6570\u636E",
1056
1084
  React__default["default"].createElement("br", null),
@@ -1,4 +1,4 @@
1
- import { l as groupBy2, e as always, i as isLeafNode, n as fromEntries, d as icons, g as getTreeDepth, _ as __rest, B as BaseTable, T as TablePipeline, j as treeMode } from './chunks/srp-table-pipeline-eab4ee87.esm.js';
1
+ import { l as groupBy2, e as always, i as isLeafNode, n as fromEntries, d as icons, g as getTreeDepth, _ as __rest, B as BaseTable, T as TablePipeline, j as treeMode } from './chunks/srp-table-pipeline-0c8b9684.esm.js';
2
2
  import React from 'react';
3
3
  import { noop } from 'rxjs';
4
4
  import styled__default from 'styled-components';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var pipeline = require('./chunks/srp-table-pipeline-6f4336b2.js');
5
+ var pipeline = require('./chunks/srp-table-pipeline-68f4025a.js');
6
6
  var React = require('react');
7
7
  var rxjs = require('rxjs');
8
8
  var styled = require('styled-components');
@@ -1,6 +1,6 @@
1
- import { f as flatMap, g as getTreeDepth, i as isLeafNode, c as collectNodes, a as internals, S as SpanManager, C as Classes, b as appendFillRemainingWidthColumn, m as mergeCellProps, _ as __rest, d as icons, t as takeFillRemainingWidthColumn, e as always, h as arrayUtils, I as InlineFlexCell, E as ExpansionCell, j as treeMode, k as treeMetaSymbol } from './chunks/srp-table-pipeline-eab4ee87.esm.js';
2
- export { B as BaseTable, C as Classes, T as TablePipeline, c as collectNodes, g as getTreeDepth, l as groupBy2, a as internals, i as isLeafNode, m as mergeCellProps, u as useTablePipeline } from './chunks/srp-table-pipeline-eab4ee87.esm.js';
3
- import React, { useState, useEffect } from 'react';
1
+ import { f as flatMap, g as getTreeDepth, i as isLeafNode, c as collectNodes, a as internals, S as SpanManager, C as Classes, b as appendFillRemainingWidthColumn, m as mergeCellProps, _ as __rest, d as icons, t as takeFillRemainingWidthColumn, e as always, h as arrayUtils, I as InlineFlexCell, E as ExpansionCell, j as treeMode, k as treeMetaSymbol } from './chunks/srp-table-pipeline-0c8b9684.esm.js';
2
+ export { B as BaseTable, C as Classes, T as TablePipeline, c as collectNodes, g as getTreeDepth, l as groupBy2, a as internals, i as isLeafNode, m as mergeCellProps, u as useTablePipeline } from './chunks/srp-table-pipeline-0c8b9684.esm.js';
3
+ import React, { useState, useEffect, useRef } from 'react';
4
4
  import styled__default from 'styled-components';
5
5
  import { fromEvent } from 'rxjs';
6
6
  import * as op from 'rxjs/operators';
@@ -1124,6 +1124,7 @@ const ResizeHandle = styled__default.span `
1124
1124
  right: -5px;
1125
1125
  width: 10px;
1126
1126
  cursor: col-resize;
1127
+ touch-action: none;
1127
1128
  z-index: 1;
1128
1129
  transition: background-color 200ms;
1129
1130
 
@@ -1137,6 +1138,20 @@ const ResizeHandle = styled__default.span `
1137
1138
  }};
1138
1139
  }
1139
1140
  `;
1141
+ /** 把手在卸载时结束仍在进行的拖拽,避免遗留 window 监听与 user-select 状态 */
1142
+ function ColumnResizeHandle(_a) {
1143
+ var { onStartResize } = _a, rest = __rest(_a, ["onStartResize"]);
1144
+ const stopRef = useRef();
1145
+ useEffect(() => () => { var _a; return (_a = stopRef.current) === null || _a === void 0 ? void 0 : _a.call(stopRef, false); }, []);
1146
+ return (React.createElement(ResizeHandle, Object.assign({}, rest, { onPointerDown: (e) => {
1147
+ if (e.button !== 0 || stopRef.current) {
1148
+ return;
1149
+ }
1150
+ stopRef.current = onStartResize(e, () => {
1151
+ stopRef.current = undefined;
1152
+ });
1153
+ } })));
1154
+ }
1140
1155
  function columnResize(opts = {}) {
1141
1156
  var _a, _b, _c, _d;
1142
1157
  const stateKey = 'columnResize';
@@ -1164,26 +1179,24 @@ function columnResize(opts = {}) {
1164
1179
  pipeline.setStateAtKey(stateKey, nextSizes);
1165
1180
  (_a = opts.onChangeSizes) === null || _a === void 0 ? void 0 : _a.call(opts, nextSizes);
1166
1181
  };
1167
- const startResize = (startIndex, endIndex, e) => {
1182
+ const computeSizes = (startIndex, endIndex, deltaSum) => {
1183
+ const nextSizes = sizes.slice();
1184
+ const sizeSum = sizes.slice(startIndex, endIndex).reduce((sum, s) => sum + s, 0);
1185
+ let deltaRemaining = deltaSum;
1186
+ for (let colIndex = startIndex; colIndex < endIndex - 1; colIndex++) {
1187
+ const startSize = sizes[colIndex];
1188
+ // 将每一列的宽度变化量 都四舍五入至 整数,不然看起来非常难受
1189
+ const colDelta = Math.round(deltaSum * (startSize / sizeSum));
1190
+ nextSizes[colIndex] = clamp(minSize, startSize + colDelta, maxSize);
1191
+ deltaRemaining -= colDelta;
1192
+ }
1193
+ // 因为前面的列宽都进行了四舍五入,最后一列的变化量需要使用 deltaRemaining 以避免误差
1194
+ nextSizes[endIndex - 1] = clamp(minSize, sizes[endIndex - 1] + deltaRemaining, maxSize);
1195
+ return nextSizes;
1196
+ };
1197
+ const startResize = (startIndex, endIndex, e, onFinish) => {
1168
1198
  const startX = e.clientX;
1169
- const target = e.target;
1170
- const nextSizes$ = fromEvent(window, 'mousemove').pipe(op.takeUntil(fromEvent(window, 'mouseup')), op.map((e) => {
1171
- const movingX = e.clientX;
1172
- const nextSizes = sizes.slice();
1173
- const deltaSum = movingX - startX;
1174
- const sizeSum = sizes.slice(startIndex, endIndex).reduce((sum, s) => sum + s, 0);
1175
- let deltaRemaining = deltaSum;
1176
- for (let colIndex = startIndex; colIndex < endIndex - 1; colIndex++) {
1177
- const startSize = sizes[colIndex];
1178
- // 将每一列的宽度变化量 都四舍五入至 整数,不然看起来非常难受
1179
- const colDelta = Math.round(deltaSum * (startSize / sizeSum));
1180
- nextSizes[colIndex] = clamp(minSize, startSize + colDelta, maxSize);
1181
- deltaRemaining -= colDelta;
1182
- }
1183
- // 因为前面的列宽都进行了四舍五入,最后一列的变化量需要使用 deltaRemaining 以避免误差
1184
- nextSizes[endIndex - 1] = clamp(minSize, sizes[endIndex - 1] + deltaRemaining, maxSize);
1185
- return nextSizes;
1186
- }));
1199
+ const target = e.currentTarget;
1187
1200
  let prevUserSelect = '';
1188
1201
  let docElemStyle;
1189
1202
  if (disableUserSelectWhenResizing) {
@@ -1194,23 +1207,52 @@ function columnResize(opts = {}) {
1194
1207
  if (opts.handleActiveBackground) {
1195
1208
  target.style.background = opts.handleActiveBackground;
1196
1209
  }
1197
- nextSizes$.subscribe({
1198
- next: onChangeSizes,
1199
- complete() {
1200
- if (disableUserSelectWhenResizing) {
1201
- docElemStyle.userSelect = prevUserSelect;
1202
- }
1203
- if (opts.handleActiveBackground) {
1204
- target.style.background = '';
1205
- }
1206
- },
1207
- });
1210
+ // 拖动过程中每帧最多提交一次列宽,松手时补交最后一次
1211
+ let pending = null;
1212
+ let frame = 0;
1213
+ const flush = () => {
1214
+ frame = 0;
1215
+ if (pending != null) {
1216
+ const nextSizes = pending;
1217
+ pending = null;
1218
+ onChangeSizes(nextSizes);
1219
+ }
1220
+ };
1221
+ const onMove = (ev) => {
1222
+ pending = computeSizes(startIndex, endIndex, ev.clientX - startX);
1223
+ if (frame === 0) {
1224
+ frame = requestAnimationFrame(flush);
1225
+ }
1226
+ };
1227
+ const stop = (commit) => {
1228
+ window.removeEventListener('pointermove', onMove);
1229
+ window.removeEventListener('pointerup', onEnd);
1230
+ window.removeEventListener('pointercancel', onEnd);
1231
+ cancelAnimationFrame(frame);
1232
+ if (commit) {
1233
+ flush();
1234
+ }
1235
+ if (disableUserSelectWhenResizing) {
1236
+ docElemStyle.userSelect = prevUserSelect;
1237
+ }
1238
+ if (opts.handleActiveBackground) {
1239
+ target.style.background = '';
1240
+ }
1241
+ };
1242
+ const onEnd = () => {
1243
+ stop(true);
1244
+ onFinish();
1245
+ };
1246
+ window.addEventListener('pointermove', onMove);
1247
+ window.addEventListener('pointerup', onEnd);
1248
+ window.addEventListener('pointercancel', onEnd);
1249
+ return stop;
1208
1250
  };
1209
1251
  const resizedColumns = makeRecursiveMapper((col, { startIndex, endIndex }) => {
1210
1252
  const prevTitle = internals.safeRenderHeader(col);
1211
1253
  return Object.assign(Object.assign({}, col), { width: sizes[startIndex], title: (React.createElement(React.Fragment, null,
1212
1254
  prevTitle,
1213
- React.createElement(ResizeHandle, { className: "resize-handle", "var-handleBackground": opts.handleBackground, "var-handleHoverBackground": opts.handleHoverBackground, onMouseDown: (e) => startResize(startIndex, endIndex, e) }))), headerCellProps: mergeCellProps(col.headerCellProps, {
1255
+ React.createElement(ColumnResizeHandle, { className: "resize-handle", "var-handleBackground": opts.handleBackground, "var-handleHoverBackground": opts.handleHoverBackground, onStartResize: (e, onFinish) => startResize(startIndex, endIndex, e, onFinish) }))), headerCellProps: mergeCellProps(col.headerCellProps, {
1214
1256
  style: {
1215
1257
  overflow: 'visible',
1216
1258
  position: 'relative',
package/dist/srp-table.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var pipeline = require('./chunks/srp-table-pipeline-6f4336b2.js');
5
+ var pipeline = require('./chunks/srp-table-pipeline-68f4025a.js');
6
6
  var React = require('react');
7
7
  var styled = require('styled-components');
8
8
  var rxjs = require('rxjs');
@@ -1152,6 +1152,7 @@ const ResizeHandle = styled__default["default"].span `
1152
1152
  right: -5px;
1153
1153
  width: 10px;
1154
1154
  cursor: col-resize;
1155
+ touch-action: none;
1155
1156
  z-index: 1;
1156
1157
  transition: background-color 200ms;
1157
1158
 
@@ -1165,6 +1166,20 @@ const ResizeHandle = styled__default["default"].span `
1165
1166
  }};
1166
1167
  }
1167
1168
  `;
1169
+ /** 把手在卸载时结束仍在进行的拖拽,避免遗留 window 监听与 user-select 状态 */
1170
+ function ColumnResizeHandle(_a) {
1171
+ var { onStartResize } = _a, rest = pipeline.__rest(_a, ["onStartResize"]);
1172
+ const stopRef = React.useRef();
1173
+ React.useEffect(() => () => { var _a; return (_a = stopRef.current) === null || _a === void 0 ? void 0 : _a.call(stopRef, false); }, []);
1174
+ return (React__default["default"].createElement(ResizeHandle, Object.assign({}, rest, { onPointerDown: (e) => {
1175
+ if (e.button !== 0 || stopRef.current) {
1176
+ return;
1177
+ }
1178
+ stopRef.current = onStartResize(e, () => {
1179
+ stopRef.current = undefined;
1180
+ });
1181
+ } })));
1182
+ }
1168
1183
  function columnResize(opts = {}) {
1169
1184
  var _a, _b, _c, _d;
1170
1185
  const stateKey = 'columnResize';
@@ -1192,26 +1207,24 @@ function columnResize(opts = {}) {
1192
1207
  pipeline$1.setStateAtKey(stateKey, nextSizes);
1193
1208
  (_a = opts.onChangeSizes) === null || _a === void 0 ? void 0 : _a.call(opts, nextSizes);
1194
1209
  };
1195
- const startResize = (startIndex, endIndex, e) => {
1210
+ const computeSizes = (startIndex, endIndex, deltaSum) => {
1211
+ const nextSizes = sizes.slice();
1212
+ const sizeSum = sizes.slice(startIndex, endIndex).reduce((sum, s) => sum + s, 0);
1213
+ let deltaRemaining = deltaSum;
1214
+ for (let colIndex = startIndex; colIndex < endIndex - 1; colIndex++) {
1215
+ const startSize = sizes[colIndex];
1216
+ // 将每一列的宽度变化量 都四舍五入至 整数,不然看起来非常难受
1217
+ const colDelta = Math.round(deltaSum * (startSize / sizeSum));
1218
+ nextSizes[colIndex] = clamp(minSize, startSize + colDelta, maxSize);
1219
+ deltaRemaining -= colDelta;
1220
+ }
1221
+ // 因为前面的列宽都进行了四舍五入,最后一列的变化量需要使用 deltaRemaining 以避免误差
1222
+ nextSizes[endIndex - 1] = clamp(minSize, sizes[endIndex - 1] + deltaRemaining, maxSize);
1223
+ return nextSizes;
1224
+ };
1225
+ const startResize = (startIndex, endIndex, e, onFinish) => {
1196
1226
  const startX = e.clientX;
1197
- const target = e.target;
1198
- const nextSizes$ = rxjs.fromEvent(window, 'mousemove').pipe(op__namespace.takeUntil(rxjs.fromEvent(window, 'mouseup')), op__namespace.map((e) => {
1199
- const movingX = e.clientX;
1200
- const nextSizes = sizes.slice();
1201
- const deltaSum = movingX - startX;
1202
- const sizeSum = sizes.slice(startIndex, endIndex).reduce((sum, s) => sum + s, 0);
1203
- let deltaRemaining = deltaSum;
1204
- for (let colIndex = startIndex; colIndex < endIndex - 1; colIndex++) {
1205
- const startSize = sizes[colIndex];
1206
- // 将每一列的宽度变化量 都四舍五入至 整数,不然看起来非常难受
1207
- const colDelta = Math.round(deltaSum * (startSize / sizeSum));
1208
- nextSizes[colIndex] = clamp(minSize, startSize + colDelta, maxSize);
1209
- deltaRemaining -= colDelta;
1210
- }
1211
- // 因为前面的列宽都进行了四舍五入,最后一列的变化量需要使用 deltaRemaining 以避免误差
1212
- nextSizes[endIndex - 1] = clamp(minSize, sizes[endIndex - 1] + deltaRemaining, maxSize);
1213
- return nextSizes;
1214
- }));
1227
+ const target = e.currentTarget;
1215
1228
  let prevUserSelect = '';
1216
1229
  let docElemStyle;
1217
1230
  if (disableUserSelectWhenResizing) {
@@ -1222,23 +1235,52 @@ function columnResize(opts = {}) {
1222
1235
  if (opts.handleActiveBackground) {
1223
1236
  target.style.background = opts.handleActiveBackground;
1224
1237
  }
1225
- nextSizes$.subscribe({
1226
- next: onChangeSizes,
1227
- complete() {
1228
- if (disableUserSelectWhenResizing) {
1229
- docElemStyle.userSelect = prevUserSelect;
1230
- }
1231
- if (opts.handleActiveBackground) {
1232
- target.style.background = '';
1233
- }
1234
- },
1235
- });
1238
+ // 拖动过程中每帧最多提交一次列宽,松手时补交最后一次
1239
+ let pending = null;
1240
+ let frame = 0;
1241
+ const flush = () => {
1242
+ frame = 0;
1243
+ if (pending != null) {
1244
+ const nextSizes = pending;
1245
+ pending = null;
1246
+ onChangeSizes(nextSizes);
1247
+ }
1248
+ };
1249
+ const onMove = (ev) => {
1250
+ pending = computeSizes(startIndex, endIndex, ev.clientX - startX);
1251
+ if (frame === 0) {
1252
+ frame = requestAnimationFrame(flush);
1253
+ }
1254
+ };
1255
+ const stop = (commit) => {
1256
+ window.removeEventListener('pointermove', onMove);
1257
+ window.removeEventListener('pointerup', onEnd);
1258
+ window.removeEventListener('pointercancel', onEnd);
1259
+ cancelAnimationFrame(frame);
1260
+ if (commit) {
1261
+ flush();
1262
+ }
1263
+ if (disableUserSelectWhenResizing) {
1264
+ docElemStyle.userSelect = prevUserSelect;
1265
+ }
1266
+ if (opts.handleActiveBackground) {
1267
+ target.style.background = '';
1268
+ }
1269
+ };
1270
+ const onEnd = () => {
1271
+ stop(true);
1272
+ onFinish();
1273
+ };
1274
+ window.addEventListener('pointermove', onMove);
1275
+ window.addEventListener('pointerup', onEnd);
1276
+ window.addEventListener('pointercancel', onEnd);
1277
+ return stop;
1236
1278
  };
1237
1279
  const resizedColumns = makeRecursiveMapper((col, { startIndex, endIndex }) => {
1238
1280
  const prevTitle = pipeline.internals.safeRenderHeader(col);
1239
1281
  return Object.assign(Object.assign({}, col), { width: sizes[startIndex], title: (React__default["default"].createElement(React__default["default"].Fragment, null,
1240
1282
  prevTitle,
1241
- React__default["default"].createElement(ResizeHandle, { className: "resize-handle", "var-handleBackground": opts.handleBackground, "var-handleHoverBackground": opts.handleHoverBackground, onMouseDown: (e) => startResize(startIndex, endIndex, e) }))), headerCellProps: pipeline.mergeCellProps(col.headerCellProps, {
1283
+ React__default["default"].createElement(ColumnResizeHandle, { className: "resize-handle", "var-handleBackground": opts.handleBackground, "var-handleHoverBackground": opts.handleHoverBackground, onStartResize: (e, onFinish) => startResize(startIndex, endIndex, e, onFinish) }))), headerCellProps: pipeline.mergeCellProps(col.headerCellProps, {
1242
1284
  style: {
1243
1285
  overflow: 'visible',
1244
1286
  position: 'relative',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guozhi5658/srp-table",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "High-performance React table component library",
5
5
  "sideEffects": false,
6
6
  "module": "dist/srp-table.esm.js",
@@ -46,6 +46,7 @@
46
46
  "devDependencies": {
47
47
  "@babel/core": "^7.12.3",
48
48
  "@babel/preset-env": "^7.12.1",
49
+ "@babel/preset-react": "^7.29.7",
49
50
  "@babel/preset-typescript": "^7.12.1",
50
51
  "@rollup/plugin-node-resolve": "^11.2.0",
51
52
  "@rollup/plugin-typescript": "^12.3.0",
package/readme.md CHANGED
@@ -11,30 +11,53 @@
11
11
  [node-url]: http://nodejs.org/download/
12
12
  [download-image]: https://img.shields.io/npm/dm/%40guozhi5658%2Fsrp-table.svg?style=flat-square
13
13
  [download-url]: https://www.npmjs.com/package/@guozhi5658/srp-table
14
- [license-image]: https://img.shields.io/npm/l/%40guozhi5658%2Fsrp-table.svg
14
+ [license-image]: https://img.shields.io/npm/l/%40guozhi5658%2Fsrp-table.svg?style=flat-square
15
15
 
16
- `srp-table` is a high-performance table component library for React applications. It is designed for data-intensive UIs and supports two integration styles:
16
+ **`@guozhi5658/srp-table`** is a high-performance React table library for data-heavy UIs. It is **forked from** [alibaba/ali-react-table](https://github.com/alibaba/ali-react-table) and keeps the MIT model; retain upstream attribution when redistributing or modifying the codebase.
17
17
 
18
- - direct prop-based usage with `BaseTable`
19
- - composable enhancement through `pipeline` and feature plugins
18
+ ## Architecture
20
19
 
21
- The library also exposes customizable component injection points and feature slots so teams can adapt rendering, interaction, and business behaviors without rewriting the rendering core.
20
+ | Layer | Role |
21
+ |-------|------|
22
+ | **`BaseTable`** | Rendering core: horizontal/vertical virtualization, left/right locked columns, sticky header/footer, row height management. |
23
+ | **`TablePipeline` + `features`** | Composable enhancements to `columns`, `dataSource`, row props, selection, tree shape, sorting, filters, etc., before props reach `<BaseTable />`. |
22
24
 
23
- ## Project Status
25
+ Integration styles:
24
26
 
25
- This project is forked from [alibaba/ali-react-table](https://github.com/alibaba/ali-react-table).
27
+ - Pass props directly to **`BaseTable`**
28
+ - Chain **`.use(features.xxx(...))`** on a pipeline, then **`<BaseTable {...pipeline.getProps()} />`**
26
29
 
27
- The fork keeps the original MIT licensing model. Please retain the upstream attribution and license terms when redistributing or modifying the codebase.
30
+ A legacy **`transforms`** API still exists for compatibility; **new capabilities belong in `pipeline/features`**, not in `transforms`.
31
+
32
+ Pivot / cross-table scenarios use the subpath package:
33
+
34
+ ```bash
35
+ npm install @guozhi5658/srp-table
36
+ # import from '@guozhi5658/srp-table/pivot'
37
+ ```
38
+
39
+ ## Pipeline features (overview)
40
+
41
+ Sixteen features live under `features` and are composed with `pipeline.use(features.xxx(...))`. Several require UI components via **`ctx.components`** (e.g. Checkbox, Radio, Popover).
42
+
43
+ | Group | Features |
44
+ |-------|----------|
45
+ | Selection | `multiSelect`, `singleSelect`, `treeSelect` |
46
+ | Tree | `treeMode`, `buildTree` |
47
+ | Expand / group | `rowDetail`, `rowGrouping` |
48
+ | Column UX | `columnHover`, `columnRangeHover`, `columnResize`, `sort`, `tips`, `filterMode` |
49
+ | Layout | `fillRemainingWidth`, `autoRowSpan` |
50
+ | Row | `rowPopover` |
51
+
52
+ For descriptions, `ctx.components` dependencies, and engineering constraints, see **[AGENTS.md](./AGENTS.md)** (Chinese, detailed). **[CLAUDE.md](./CLAUDE.md)** is a shorter English checklist for agents working in this repo.
28
53
 
29
54
  ## Highlights
30
55
 
31
- - high-performance rendering for large datasets
32
- - sticky header and sticky footer support
33
- - left and right locked columns
34
- - horizontal and vertical virtualization
35
- - tree data, row detail, sorting, and other pipeline-driven features
36
- - pluggable renderers and component slots for customization
37
- - pivot table entry for cross-table and cross-tree-table scenarios
56
+ - Virtualized rows and columns for large datasets
57
+ - Sticky header/footer, left/right locked columns
58
+ - Tree rows, row detail, grouping, sorting, resizing, filters, and other pipeline-driven behavior
59
+ - Customizable slots: `BaseTableProps.components`, column render hooks, pipeline `ctx.components`
60
+ - **`@guozhi5658/srp-table/pivot`**: cross-table and cross-tree-table built on the same `BaseTable` core
38
61
 
39
62
  ## Installation
40
63
 
@@ -42,7 +65,9 @@ The fork keeps the original MIT licensing model. Please retain the upstream attr
42
65
  npm install @guozhi5658/srp-table
43
66
  ```
44
67
 
45
- ## Quick Start
68
+ Peer dependency: **React** `^16.8.0 || ^17.0.1 || ^18.0.0`.
69
+
70
+ ## Quick start
46
71
 
47
72
  ### BaseTable
48
73
 
@@ -93,60 +118,27 @@ export function PipelineDemo({ columns, dataSource }) {
93
118
  }
94
119
  ```
95
120
 
96
- ### Fill Remaining Width
97
-
98
- Use `features.fillRemainingWidth()` when you want fixed-width columns to keep their original widths as the container grows. Instead of stretching existing columns proportionally, the table appends a blank column on the right to absorb the remaining space.
99
-
100
- ```tsx
101
- import { BaseTable, features, useTablePipeline } from '@guozhi5658/srp-table'
102
-
103
- export function FixedWidthDemo({ columns, dataSource }) {
104
- const pipeline = useTablePipeline()
105
-
106
- const tableProps = pipeline
107
- .input({ columns, dataSource })
108
- .primaryKey('id')
109
- .use(features.fillRemainingWidth())
110
- .getProps()
111
-
112
- return (
113
- <BaseTable
114
- {...tableProps}
115
- defaultColumnWidth={140}
116
- isStickyHeader
117
- />
118
- )
119
- }
120
- ```
121
-
122
- This feature is designed for the pipeline path and works with `defaultColumnWidth`, locked columns, and the table's built-in virtualization logic.
121
+ You can combine multiple `.use(...)` calls; **order matters** when features append or rewrite columns. See **AGENTS.md** for full-row span and lock-column caveats.
123
122
 
124
123
  ## Playground
125
124
 
126
- Run the local playground to develop and validate new features against the built-in flat, tree, and row-detail mock datasets:
127
-
128
125
  ```bash
129
126
  npm install
130
- npm run playground
127
+ npm run playground # dev server (e.g. port 3100)
131
128
  ```
132
129
 
133
- The playground is intended for iterative feature work in a real React runtime and is the fastest way to verify layout, interaction, sticky behavior, and virtualization changes.
130
+ The playground is a Vite app for flat, tree, row-detail, grouped-header, and merged-cell scenarios—useful for layout, sticky behavior, and virtualization checks. For library development, this repo pins **Node 22.x** via **Volta** (see `package.json`).
134
131
 
135
- ## Build
132
+ ## Build & compatibility
136
133
 
137
134
  ```bash
138
- npm run build
135
+ npm run build # Rollup → dist/
136
+ npm run playground:build
137
+ npm run verify:react-compat # React 16 / 17 / 18 smoke script
139
138
  ```
140
139
 
141
- Build artifacts are emitted to `dist/`, including:
142
-
143
- - `dist/srp-table.js`
144
- - `dist/srp-table.esm.js`
145
- - `dist/srp-table.d.ts`
146
- - `dist/srp-table-pivot.js`
147
- - `dist/srp-table-pivot.esm.js`
148
- - `dist/srp-table-pivot.d.ts`
140
+ Artifacts under `dist/` include `srp-table` and `srp-table-pivot` entry bundles and `.d.ts` files (see **Build** list in **AGENTS.md** if you need exact filenames).
149
141
 
150
142
  ## License
151
143
 
152
- MIT. This fork is based on [alibaba/ali-react-table](https://github.com/alibaba/ali-react-table), and the upstream attribution should be preserved.
144
+ MIT. This fork is based on [alibaba/ali-react-table](https://github.com/alibaba/ali-react-table); preserve upstream attribution.