@rainbow-oh/yee-c 0.9.2 → 0.11.0

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.
Files changed (162) hide show
  1. package/dist/cjs/Button/demo/icon.js +1 -1
  2. package/dist/cjs/Input/style/index.less +1 -0
  3. package/dist/cjs/Table/demo/resizable.d.ts +3 -0
  4. package/dist/cjs/Table/demo/resizable.js +143 -0
  5. package/dist/cjs/Table/hooks/useColumnResize.d.ts +30 -0
  6. package/dist/cjs/Table/hooks/useColumnResize.js +217 -0
  7. package/dist/cjs/Table/hooks/useColumns.d.ts +3 -1
  8. package/dist/cjs/Table/hooks/useColumns.js +14 -3
  9. package/dist/cjs/Table/interface.d.ts +49 -0
  10. package/dist/cjs/Table/style/index.less +42 -0
  11. package/dist/cjs/Table/table.js +62 -9
  12. package/dist/cjs/Table/theader/cell.js +46 -4
  13. package/dist/cjs/Table/util/index.d.ts +19 -1
  14. package/dist/cjs/Table/util/index.js +22 -0
  15. package/dist/cjs/Tabs/demo/overflow-center.d.ts +3 -0
  16. package/dist/cjs/Tabs/demo/overflow-center.js +54 -0
  17. package/dist/cjs/Tabs/hooks/useNavListMove.d.ts +2 -1
  18. package/dist/cjs/Tabs/hooks/useNavListMove.js +51 -16
  19. package/dist/cjs/Tabs/hooks/useTabScroll.d.ts +1 -0
  20. package/dist/cjs/Tabs/hooks/useTabScroll.js +5 -1
  21. package/dist/cjs/Tabs/interface.d.ts +10 -1
  22. package/dist/cjs/Tabs/style/index.less +5 -0
  23. package/dist/cjs/Tabs/tab-header/index.d.ts +1 -0
  24. package/dist/cjs/Tabs/tab-header/index.js +11 -3
  25. package/dist/cjs/Tabs/tabs.js +4 -1
  26. package/dist/cjs/Upload/demo/auto-upload.d.ts +3 -0
  27. package/dist/cjs/Upload/demo/auto-upload.js +65 -0
  28. package/dist/cjs/Upload/demo/basic.js +5 -10
  29. package/dist/cjs/Upload/demo/controlled.js +4 -4
  30. package/dist/cjs/Upload/demo/pictureWall.js +14 -13
  31. package/dist/cjs/Upload/dragger.d.ts +2 -1
  32. package/dist/cjs/Upload/dragger.js +32 -21
  33. package/dist/cjs/Upload/index.d.ts +1 -1
  34. package/dist/cjs/Upload/interface.d.ts +67 -120
  35. package/dist/cjs/Upload/style/index.less +40 -13
  36. package/dist/cjs/Upload/upload.d.ts +2 -2
  37. package/dist/cjs/Upload/upload.js +435 -185
  38. package/dist/cjs/Upload/uploaded-list/index.d.ts +2 -1
  39. package/dist/cjs/Upload/uploaded-list/index.js +6 -3
  40. package/dist/cjs/Upload/uploaded-list/uploaded-item.d.ts +6 -3
  41. package/dist/cjs/Upload/uploaded-list/uploaded-item.js +127 -138
  42. package/dist/cjs/locale/interface.d.ts +1 -0
  43. package/dist/cjs/locale/lang/en_US.js +2 -1
  44. package/dist/cjs/locale/lang/ja_JP.js +2 -1
  45. package/dist/cjs/locale/lang/zh_CN.js +2 -1
  46. package/dist/cjs/locale/lang/zh_TW.js +2 -1
  47. package/dist/cjs/style/size.css +2 -1
  48. package/dist/cjs/style/themes.css +1 -1
  49. package/dist/cjs/style/variables.css +3 -2
  50. package/dist/cjs/utils/ax/core.d.ts +3 -1
  51. package/dist/cjs/utils/ax/core.js +24 -37
  52. package/dist/cjs/utils/ax/index.d.ts +3 -1
  53. package/dist/cjs/utils/folder-scanner.d.ts +1 -1
  54. package/dist/cjs/utils/folder-scanner.js +43 -34
  55. package/dist/cjs/version.d.ts +1 -1
  56. package/dist/cjs/version.js +1 -1
  57. package/dist/esm/Button/demo/icon.js +7 -4
  58. package/dist/esm/Input/style/index.less +1 -0
  59. package/dist/esm/Table/demo/resizable.d.ts +3 -0
  60. package/dist/esm/Table/demo/resizable.js +110 -0
  61. package/dist/esm/Table/hooks/useColumnResize.d.ts +30 -0
  62. package/dist/esm/Table/hooks/useColumnResize.js +206 -0
  63. package/dist/esm/Table/hooks/useColumns.d.ts +3 -1
  64. package/dist/esm/Table/hooks/useColumns.js +9 -4
  65. package/dist/esm/Table/interface.d.ts +49 -0
  66. package/dist/esm/Table/style/index.less +42 -0
  67. package/dist/esm/Table/table.js +83 -13
  68. package/dist/esm/Table/theader/cell.js +38 -3
  69. package/dist/esm/Table/util/index.d.ts +19 -1
  70. package/dist/esm/Table/util/index.js +37 -0
  71. package/dist/esm/Tabs/demo/overflow-center.d.ts +3 -0
  72. package/dist/esm/Tabs/demo/overflow-center.js +61 -0
  73. package/dist/esm/Tabs/hooks/useNavListMove.d.ts +2 -1
  74. package/dist/esm/Tabs/hooks/useNavListMove.js +62 -25
  75. package/dist/esm/Tabs/hooks/useTabScroll.d.ts +1 -0
  76. package/dist/esm/Tabs/hooks/useTabScroll.js +9 -0
  77. package/dist/esm/Tabs/interface.d.ts +10 -1
  78. package/dist/esm/Tabs/style/index.less +5 -0
  79. package/dist/esm/Tabs/tab-header/index.d.ts +1 -0
  80. package/dist/esm/Tabs/tab-header/index.js +15 -3
  81. package/dist/esm/Tabs/tabs.js +4 -2
  82. package/dist/esm/Upload/demo/auto-upload.d.ts +3 -0
  83. package/dist/esm/Upload/demo/auto-upload.js +42 -0
  84. package/dist/esm/Upload/demo/basic.js +5 -11
  85. package/dist/esm/Upload/demo/controlled.js +8 -6
  86. package/dist/esm/Upload/demo/pictureWall.js +17 -14
  87. package/dist/esm/Upload/dragger.d.ts +2 -1
  88. package/dist/esm/Upload/dragger.js +10 -5
  89. package/dist/esm/Upload/index.d.ts +1 -1
  90. package/dist/esm/Upload/interface.d.ts +67 -120
  91. package/dist/esm/Upload/style/index.less +40 -13
  92. package/dist/esm/Upload/upload.d.ts +2 -2
  93. package/dist/esm/Upload/upload.js +573 -271
  94. package/dist/esm/Upload/uploaded-list/index.d.ts +2 -1
  95. package/dist/esm/Upload/uploaded-list/index.js +9 -4
  96. package/dist/esm/Upload/uploaded-list/uploaded-item.d.ts +6 -3
  97. package/dist/esm/Upload/uploaded-list/uploaded-item.js +145 -150
  98. package/dist/esm/locale/interface.d.ts +1 -0
  99. package/dist/esm/locale/lang/en_US.js +2 -1
  100. package/dist/esm/locale/lang/ja_JP.js +2 -1
  101. package/dist/esm/locale/lang/zh_CN.js +2 -1
  102. package/dist/esm/locale/lang/zh_TW.js +2 -1
  103. package/dist/esm/style/size.css +2 -1
  104. package/dist/esm/style/themes.css +1 -1
  105. package/dist/esm/style/variables.css +3 -2
  106. package/dist/esm/utils/ax/core.d.ts +3 -1
  107. package/dist/esm/utils/ax/core.js +32 -40
  108. package/dist/esm/utils/ax/index.d.ts +3 -1
  109. package/dist/esm/utils/folder-scanner.d.ts +1 -1
  110. package/dist/esm/utils/folder-scanner.js +76 -75
  111. package/dist/esm/version.d.ts +1 -1
  112. package/dist/esm/version.js +1 -1
  113. package/dist/umd/yee-c.min.css +2 -2
  114. package/dist/umd/yee-c.min.js +1 -1
  115. package/package.json +1 -1
  116. package/src/Button/demo/icon.tsx +5 -3
  117. package/src/Input/style/index.less +1 -0
  118. package/src/Table/demo/resizable.tsx +106 -0
  119. package/src/Table/hooks/useColumnResize.ts +224 -0
  120. package/src/Table/hooks/useColumns.ts +18 -3
  121. package/src/Table/index.en-US.md +7 -0
  122. package/src/Table/index.zh-CN.md +7 -0
  123. package/src/Table/interface.ts +52 -0
  124. package/src/Table/style/index.less +42 -0
  125. package/src/Table/table-resize.test.tsx +234 -0
  126. package/src/Table/table.tsx +90 -13
  127. package/src/Table/theader/cell.tsx +52 -2
  128. package/src/Table/util/index.ts +44 -1
  129. package/src/Tabs/demo/overflow-center.tsx +35 -0
  130. package/src/Tabs/hooks/useNavListMove.ts +60 -18
  131. package/src/Tabs/hooks/useTabScroll.ts +7 -1
  132. package/src/Tabs/index.en-US.md +33 -31
  133. package/src/Tabs/index.zh-CN.md +33 -31
  134. package/src/Tabs/interface.ts +10 -1
  135. package/src/Tabs/style/index.less +5 -0
  136. package/src/Tabs/tab-header/index.tsx +14 -3
  137. package/src/Tabs/tabs.tsx +2 -0
  138. package/src/Upload/demo/auto-upload.tsx +35 -0
  139. package/src/Upload/demo/basic.tsx +7 -11
  140. package/src/Upload/demo/controlled.tsx +12 -8
  141. package/src/Upload/demo/directory.tsx +3 -4
  142. package/src/Upload/demo/drag.tsx +5 -12
  143. package/src/Upload/demo/multiple.tsx +3 -4
  144. package/src/Upload/demo/pictureWall.tsx +22 -21
  145. package/src/Upload/dragger.tsx +47 -34
  146. package/src/Upload/index.en-US.md +63 -43
  147. package/src/Upload/index.ts +8 -1
  148. package/src/Upload/index.zh-CN.md +62 -42
  149. package/src/Upload/interface.ts +68 -120
  150. package/src/Upload/style/index.less +40 -13
  151. package/src/Upload/upload.tsx +546 -215
  152. package/src/Upload/uploaded-list/index.tsx +9 -5
  153. package/src/Upload/uploaded-list/uploaded-item.tsx +199 -228
  154. package/src/locale/interface.ts +1 -0
  155. package/src/locale/lang/en_US.ts +1 -0
  156. package/src/locale/lang/ja_JP.ts +1 -0
  157. package/src/locale/lang/zh_CN.ts +1 -0
  158. package/src/locale/lang/zh_TW.ts +1 -0
  159. package/src/style/size.css +2 -1
  160. package/src/utils/ax/core.ts +28 -41
  161. package/src/utils/folder-scanner.ts +51 -37
  162. package/src/version.ts +1 -1
@@ -68,6 +68,7 @@ var import_Spin = __toESM(require("../Spin"));
68
68
  var import_col_group = __toESM(require("./col-group"));
69
69
  var import_footer = __toESM(require("./footer"));
70
70
  var import_header = __toESM(require("./header"));
71
+ var import_useColumnResize = __toESM(require("./hooks/useColumnResize"));
71
72
  var import_useColumns = __toESM(require("./hooks/useColumns"));
72
73
  var import_useExpand = __toESM(require("./hooks/useExpand"));
73
74
  var import_useSelection = __toESM(require("./hooks/useSelection"));
@@ -75,7 +76,6 @@ var import_tbody = __toESM(require("./tbody"));
75
76
  var import_tfooter = __toESM(require("./tfooter"));
76
77
  var import_theader = __toESM(require("./theader"));
77
78
  var import_Config_Provider = require("../Config-Provider");
78
- var import_useLatest = __toESM(require("../hooks/useLatest"));
79
79
  var import_mergeContextToProps = __toESM(require("../utils/mergeContextToProps"));
80
80
  var import_omit = __toESM(require("../utils/omit"));
81
81
  var import_types = require("../utils/types");
@@ -97,6 +97,9 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
97
97
  rowKey = "key",
98
98
  bordered,
99
99
  tableLayout,
100
+ resizable,
101
+ onColumnResize,
102
+ onColumnResizeEnd,
100
103
  loading = false,
101
104
  showHeader = true,
102
105
  pagination: propPagination = true,
@@ -123,6 +126,9 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
123
126
  "rowKey",
124
127
  "bordered",
125
128
  "tableLayout",
129
+ "resizable",
130
+ "onColumnResize",
131
+ "onColumnResizeEnd",
126
132
  "loading",
127
133
  "showHeader",
128
134
  "pagination",
@@ -142,6 +148,22 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
142
148
  ]);
143
149
  const dataAttrs = (0, import_types.pickDataAttrs)(rest);
144
150
  const [measuredColumnWidths, setMeasuredColumnWidths] = import_react.default.useState();
151
+ const contentRef = (0, import_react.useRef)(null);
152
+ const tableRef = (0, import_react.useRef)(null);
153
+ const wrapedColumnsRef = (0, import_react.useRef)([]);
154
+ const {
155
+ resizedWidths,
156
+ resizingKey,
157
+ onResizeStart,
158
+ onResizeStep,
159
+ resetResizedWidths
160
+ } = (0, import_useColumnResize.default)({
161
+ tableRef,
162
+ columnsRef: wrapedColumnsRef,
163
+ onColumnResize,
164
+ onColumnResizeEnd
165
+ });
166
+ const hasResizeSnapshot = Object.keys(resizedWidths).length > 0;
145
167
  const getRowKey = import_react.default.useCallback(
146
168
  (record, key = rowKey) => {
147
169
  return typeof key === "function" ? key(record) : record[key];
@@ -156,8 +178,31 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
156
178
  columns: propColumns,
157
179
  expandable,
158
180
  rowSelection,
159
- measuredColumnWidths
181
+ measuredColumnWidths: hasResizeSnapshot ? void 0 : measuredColumnWidths,
182
+ resizable,
183
+ resizedWidths
160
184
  });
185
+ wrapedColumnsRef.current = wrapedColumns;
186
+ const resizeTotalWidth = (0, import_react.useMemo)(() => {
187
+ if (!wrapedColumns.length)
188
+ return void 0;
189
+ let total = 0;
190
+ for (const column of wrapedColumns) {
191
+ const width = column.resizeKey ? resizedWidths[column.resizeKey] : void 0;
192
+ if (!width || !Number.isFinite(width))
193
+ return void 0;
194
+ total += width;
195
+ }
196
+ return total;
197
+ }, [wrapedColumns, resizedWidths]);
198
+ const resizeActive = resizeTotalWidth !== void 0;
199
+ const resizeKeysSignature = (0, import_react.useMemo)(
200
+ () => wrapedColumns.map((column) => column.resizeKey).join("|"),
201
+ [wrapedColumns]
202
+ );
203
+ (0, import_react.useEffect)(() => {
204
+ resetResizedWidths();
205
+ }, [resizeKeysSignature, resetResizedWidths]);
161
206
  const {
162
207
  data: filteredData,
163
208
  filterRecords,
@@ -215,8 +260,6 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
215
260
  onChange: onSelectionChange
216
261
  } = (0, import_useSelection.default)({ pageData, dataSource, getRowKey, rowSelection, allKeys });
217
262
  const prevFilterRecordsRef = (0, import_react.useRef)(filterRecords);
218
- const contentRef = (0, import_react.useRef)(null);
219
- const tableRef = (0, import_react.useRef)(null);
220
263
  const [horizontalScroll, setHorizontalScroll] = import_react.default.useState({
221
264
  left: false,
222
265
  right: false
@@ -244,7 +287,6 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
244
287
  ).join("|"),
245
288
  [wrapedColumns]
246
289
  );
247
- const wrapedColumnsRef = (0, import_useLatest.default)(wrapedColumns);
248
290
  const updateMeasuredColumnWidths = import_react.default.useCallback(() => {
249
291
  var _a2;
250
292
  const columns = wrapedColumnsRef.current;
@@ -345,7 +387,10 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
345
387
  sorters,
346
388
  onSort: handleSort,
347
389
  onCheckAll,
348
- onInternalFilter: onFilterInternal
390
+ onInternalFilter: onFilterInternal,
391
+ resizingKey,
392
+ onResizeStart,
393
+ onResizeStep
349
394
  })
350
395
  );
351
396
  };
@@ -373,8 +418,12 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
373
418
  const renderTable = () => {
374
419
  const tableProps = {
375
420
  style: __spreadProps(__spreadValues({}, styles == null ? void 0 : styles.table), {
376
- minWidth: scroll == null ? void 0 : scroll.x,
377
- tableLayout: (pageData == null ? void 0 : pageData.length) ? tableLayout : void 0
421
+ // An explicit total width replaces both `width: 100%` and `scroll.x`:
422
+ // either of those would let the browser stretch the table and redistribute
423
+ // the extra space across the columns, undoing the drag.
424
+ minWidth: resizeActive ? void 0 : scroll == null ? void 0 : scroll.x,
425
+ width: resizeTotalWidth,
426
+ tableLayout: resizeActive ? "fixed" : (pageData == null ? void 0 : pageData.length) ? tableLayout : void 0
378
427
  }),
379
428
  className: (0, import_clsx.default)(
380
429
  { [`${prefixCls}-bordered`]: bordered },
@@ -434,7 +483,11 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
434
483
  return /* @__PURE__ */ import_react.default.createElement(
435
484
  "div",
436
485
  __spreadValues({
437
- className: (0, import_clsx.default)(`${prefixCls}-box`, className),
486
+ className: (0, import_clsx.default)(
487
+ `${prefixCls}-box`,
488
+ { [`${prefixCls}-resizing`]: !!resizingKey },
489
+ className
490
+ ),
438
491
  style,
439
492
  ref
440
493
  }, dataAttrs),
@@ -89,9 +89,14 @@ var HeadCell = (props) => {
89
89
  width,
90
90
  colSpan,
91
91
  rowSpan,
92
+ resizable,
93
+ resizeKey,
94
+ resizingKey,
92
95
  onHeaderCell,
93
96
  onSort,
94
- onInternalFilter
97
+ onInternalFilter,
98
+ onResizeStart,
99
+ onResizeStep
95
100
  } = _a, rest = __objRest(_a, [
96
101
  "fixed",
97
102
  "isFixedLeftLast",
@@ -112,9 +117,14 @@ var HeadCell = (props) => {
112
117
  "width",
113
118
  "colSpan",
114
119
  "rowSpan",
120
+ "resizable",
121
+ "resizeKey",
122
+ "resizingKey",
115
123
  "onHeaderCell",
116
124
  "onSort",
117
- "onInternalFilter"
125
+ "onInternalFilter",
126
+ "onResizeStart",
127
+ "onResizeStep"
118
128
  ]);
119
129
  const { prefixCls } = (0, import_react.useContext)(import_table.TableCtx);
120
130
  const { locale } = (0, import_locale.useLocale)();
@@ -208,6 +218,38 @@ var HeadCell = (props) => {
208
218
  },
209
219
  className
210
220
  );
221
+ const showResizeHandle = !!(resizable && resizeKey && onResizeStart);
222
+ const isResizing = !!resizeKey && resizingKey === resizeKey;
223
+ const renderResizeHandle = () => {
224
+ if (!showResizeHandle)
225
+ return null;
226
+ return /* @__PURE__ */ import_react.default.createElement(
227
+ "span",
228
+ {
229
+ role: "separator",
230
+ "aria-orientation": "vertical",
231
+ "aria-label": tableLocale.resizeColumn || "Drag to resize column",
232
+ tabIndex: 0,
233
+ className: (0, import_clsx.default)(`${prefixCls}-resize-handle`, {
234
+ [`${prefixCls}-resize-handle-active`]: isResizing
235
+ }),
236
+ onPointerDown: (event) => onResizeStart == null ? void 0 : onResizeStart(event, resizeKey),
237
+ onClick: (event) => {
238
+ event.preventDefault();
239
+ event.stopPropagation();
240
+ },
241
+ onKeyDown: (event) => {
242
+ if (event.key !== "ArrowLeft" && event.key !== "ArrowRight")
243
+ return;
244
+ event.preventDefault();
245
+ onResizeStep == null ? void 0 : onResizeStep(
246
+ resizeKey,
247
+ event.key === "ArrowLeft" ? -1 : 1
248
+ );
249
+ }
250
+ }
251
+ );
252
+ };
211
253
  const getThProps = () => {
212
254
  const styles2 = __spreadProps(__spreadValues({}, style), { width, maxWidth: width, textAlign: align });
213
255
  const cellProps = onHeaderCell ? onHeaderCell(props) : {};
@@ -222,9 +264,9 @@ var HeadCell = (props) => {
222
264
  const thProps = getThProps();
223
265
  const renderCell = () => {
224
266
  if (!filter && !sorter) {
225
- return /* @__PURE__ */ import_react.default.createElement("th", __spreadValues({}, thProps), title);
267
+ return /* @__PURE__ */ import_react.default.createElement("th", __spreadValues({}, thProps), title, renderResizeHandle());
226
268
  }
227
- return /* @__PURE__ */ import_react.default.createElement("th", __spreadValues({}, thProps), renderCellWithAction());
269
+ return /* @__PURE__ */ import_react.default.createElement("th", __spreadValues({}, thProps), renderCellWithAction(), renderResizeHandle());
228
270
  };
229
271
  const cell = renderCell();
230
272
  return cell;
@@ -1,2 +1,20 @@
1
- import { WrapedColumnProps } from '../interface';
1
+ import { ColumnProps, WrapedColumnProps } from '../interface';
2
+ /**
3
+ * Stable identity for a leaf column, used to key its resized width.
4
+ *
5
+ * `key`/`dataIndex` survive re-ordering and data changes, so they are preferred.
6
+ * Columns declaring neither fall back to their position, which is the best that
7
+ * can be done without asking the caller for an id.
8
+ */
9
+ export declare function getColumnResizeKey(column: ColumnProps, index: number): string;
10
+ /**
11
+ * Stamp every leaf column with its `resizeKey`, resolve whether it is resizable
12
+ * (column level setting wins over the table level one) and override `width` with
13
+ * the dragged value when there is one.
14
+ *
15
+ * This runs before `handleColumns` so that the colgroup, the header cells, the
16
+ * body cells and the sticky offsets of fixed columns all read the same width
17
+ * from a single place.
18
+ */
19
+ export declare function applyColumnResize(columns: Array<WrapedColumnProps>, resizable?: boolean, resizedWidths?: Record<string, number>): WrapedColumnProps[];
2
20
  export declare function handleColumns(columns: Array<WrapedColumnProps>, measuredColumnWidths?: number[]): WrapedColumnProps[];
@@ -36,9 +36,31 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
36
36
  // src/Table/util/index.ts
37
37
  var util_exports = {};
38
38
  __export(util_exports, {
39
+ applyColumnResize: () => applyColumnResize,
40
+ getColumnResizeKey: () => getColumnResizeKey,
39
41
  handleColumns: () => handleColumns
40
42
  });
41
43
  module.exports = __toCommonJS(util_exports);
44
+ function getColumnResizeKey(column, index) {
45
+ var _a;
46
+ const id = (_a = column.key) != null ? _a : column.dataIndex;
47
+ return id === void 0 || id === null || id === "" ? `index:${index}` : `id:${id}`;
48
+ }
49
+ function applyColumnResize(columns, resizable, resizedWidths) {
50
+ return columns.map((column, index) => {
51
+ var _a, _b;
52
+ const resizeKey = getColumnResizeKey(column, index);
53
+ const resizedWidth = resizedWidths == null ? void 0 : resizedWidths[resizeKey];
54
+ const next = __spreadProps(__spreadValues({}, column), {
55
+ resizeKey,
56
+ resizable: (_b = (_a = column.resizable) != null ? _a : resizable) != null ? _b : false
57
+ });
58
+ if (Number.isFinite(resizedWidth) && resizedWidth > 0) {
59
+ next.width = resizedWidth;
60
+ }
61
+ return next;
62
+ });
63
+ }
42
64
  var getColumnWidth = (column, index, measuredColumnWidths) => {
43
65
  const measuredWidth = measuredColumnWidths == null ? void 0 : measuredColumnWidths[index];
44
66
  if (Number.isFinite(measuredWidth) && measuredWidth && measuredWidth > 0) {
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const _default: () => React.JSX.Element;
3
+ export default _default;
@@ -0,0 +1,54 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/Tabs/demo/overflow-center.tsx
30
+ var overflow_center_exports = {};
31
+ __export(overflow_center_exports, {
32
+ default: () => overflow_center_default
33
+ });
34
+ module.exports = __toCommonJS(overflow_center_exports);
35
+ var import_yee_c = require("../..");
36
+ var import_react = __toESM(require("react"));
37
+ var overflow_center_default = () => {
38
+ const items = Array.from({ length: 24 }, (_, i) => ({
39
+ key: `tab-${i + 1}`,
40
+ label: `Tab ${i + 1}`,
41
+ children: `Content of Tab Pane ${i + 1}`
42
+ }));
43
+ const [centerKey, setCenterKey] = (0, import_react.useState)("tab-1");
44
+ const [autoKey, setAutoKey] = (0, import_react.useState)("tab-1");
45
+ return /* @__PURE__ */ import_react.default.createElement("div", { style: { display: "flex", flexDirection: "column", gap: 24 } }, /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("p", { style: { marginBottom: 8 } }, 'activeAlign="center"'), /* @__PURE__ */ import_react.default.createElement("div", { style: { maxWidth: 480 }, "data-testid": "center-wrap" }, /* @__PURE__ */ import_react.default.createElement(
46
+ import_yee_c.Tabs,
47
+ {
48
+ activeAlign: "center",
49
+ items,
50
+ activeKey: centerKey,
51
+ onChange: setCenterKey
52
+ }
53
+ ))), /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("p", { style: { marginBottom: 8 } }, "default (auto)"), /* @__PURE__ */ import_react.default.createElement("div", { style: { maxWidth: 480 }, "data-testid": "auto-wrap" }, /* @__PURE__ */ import_react.default.createElement(import_yee_c.Tabs, { items, activeKey: autoKey, onChange: setAutoKey }))));
54
+ };
@@ -3,10 +3,11 @@ interface UseNavListMoveOptions {
3
3
  direction: 'horizontal' | 'vertical';
4
4
  activeKey: string | number;
5
5
  enabled: boolean;
6
+ align?: 'auto' | 'center';
6
7
  activetab: React.RefObject<HTMLElement | null>;
7
8
  navList: React.RefObject<HTMLDivElement | null>;
8
9
  navContainer: React.RefObject<HTMLDivElement | null>;
9
10
  onMoved?: () => void;
10
11
  }
11
- export declare function useNavListMove({ direction, activeKey, enabled, activetab, navList, navContainer, onMoved, }: UseNavListMoveOptions): void;
12
+ export declare function useNavListMove({ direction, activeKey, enabled, align, activetab, navList, navContainer, onMoved, }: UseNavListMoveOptions): void;
12
13
  export {};
@@ -28,6 +28,7 @@ function useNavListMove({
28
28
  direction,
29
29
  activeKey,
30
30
  enabled,
31
+ align = "auto",
31
32
  activetab,
32
33
  navList,
33
34
  navContainer,
@@ -40,23 +41,52 @@ function useNavListMove({
40
41
  if (!enabled || !tab || !list || !container) {
41
42
  return;
42
43
  }
43
- const [isVisible] = (0, import_tab_utils.isInContainer)(direction, tab, list, container);
44
- if (isVisible)
45
- return;
44
+ if (align !== "center") {
45
+ const [isVisible] = (0, import_tab_utils.isInContainer)(direction, tab, list, container);
46
+ if (isVisible)
47
+ return;
48
+ }
49
+ let moved = false;
46
50
  if (direction === "horizontal") {
47
- const [x] = (0, import_tab_utils.getEleTranslate)(list);
48
- const tabLeft = tab.offsetLeft;
49
- const tabWidth = tab.offsetWidth;
50
- const containerWidth = container.clientWidth;
51
- let newX = x;
52
- if (tabLeft + tabWidth - Math.abs(x) > containerWidth) {
53
- const overflow = tabLeft + tabWidth - Math.abs(x) - containerWidth;
54
- newX = x - overflow;
55
- } else if (tabLeft < Math.abs(x)) {
56
- const overflow = Math.abs(x) - tabLeft;
57
- newX = x + overflow;
51
+ if (align === "center") {
52
+ const containerWidth = container.clientWidth;
53
+ const maxOffset = list.scrollWidth - containerWidth;
54
+ const tabCenter = tab.offsetLeft + tab.offsetWidth / 2;
55
+ let newX = Math.round(containerWidth / 2 - tabCenter);
56
+ newX = Math.max(-maxOffset, Math.min(0, newX));
57
+ const [x] = (0, import_tab_utils.getEleTranslate)(list);
58
+ if (Math.abs(newX - x) > 0.5) {
59
+ (0, import_tab_utils.setEleTranslate)(list, newX);
60
+ moved = true;
61
+ }
62
+ } else {
63
+ const [x] = (0, import_tab_utils.getEleTranslate)(list);
64
+ const tabLeft = tab.offsetLeft;
65
+ const tabWidth = tab.offsetWidth;
66
+ const containerWidth = container.clientWidth;
67
+ let newX = x;
68
+ if (tabLeft + tabWidth - Math.abs(x) > containerWidth) {
69
+ const overflow = tabLeft + tabWidth - Math.abs(x) - containerWidth;
70
+ newX = x - overflow;
71
+ } else if (tabLeft < Math.abs(x)) {
72
+ const overflow = Math.abs(x) - tabLeft;
73
+ newX = x + overflow;
74
+ }
75
+ (0, import_tab_utils.setEleTranslate)(list, newX);
76
+ moved = true;
77
+ }
78
+ } else if (align === "center") {
79
+ const containerHeight = container.clientHeight;
80
+ const maxOffset = container.scrollHeight - containerHeight;
81
+ const tabCenter = tab.offsetTop + tab.offsetHeight / 2;
82
+ const newScrollTop = Math.max(
83
+ 0,
84
+ Math.min(maxOffset, Math.round(tabCenter - containerHeight / 2))
85
+ );
86
+ if (Math.abs(newScrollTop - container.scrollTop) > 0.5) {
87
+ container.scrollTop = newScrollTop;
88
+ moved = true;
58
89
  }
59
- (0, import_tab_utils.setEleTranslate)(list, newX);
60
90
  } else {
61
91
  const tabTop = tab.offsetTop;
62
92
  const tabHeight = tab.offsetHeight;
@@ -65,16 +95,21 @@ function useNavListMove({
65
95
  if (tabTop + tabHeight - scrollTop >= containerHeight) {
66
96
  const overflow = tabTop + tabHeight - scrollTop - containerHeight;
67
97
  container.scrollTop = scrollTop + overflow;
98
+ moved = true;
68
99
  } else if (tabTop < scrollTop) {
69
100
  const overflow = scrollTop - tabTop;
70
101
  container.scrollTop = scrollTop - overflow;
102
+ moved = true;
71
103
  }
72
104
  }
73
- onMoved == null ? void 0 : onMoved();
105
+ if (moved) {
106
+ onMoved == null ? void 0 : onMoved();
107
+ }
74
108
  }, [
75
109
  activeKey,
76
110
  enabled,
77
111
  direction,
112
+ align,
78
113
  activetab,
79
114
  navList,
80
115
  navContainer,
@@ -7,6 +7,7 @@ interface UseTabScrollOptions {
7
7
  }
8
8
  export declare function useTabScroll({ direction, navContainer, navList, enabled, }: UseTabScrollOptions): {
9
9
  refreshKey: number;
10
+ refresh: () => void;
10
11
  updateShadow: import("../../utils/debounce").Debounced<() => void>;
11
12
  };
12
13
  export {};
@@ -57,6 +57,10 @@ function useTabScroll({
57
57
  container.classList.toggle("with-suffix-shadow", currentOffset < maxOffset);
58
58
  }, [direction, navContainer, navList]);
59
59
  const debouncedUpdateShadow = (0, import_useDebounceFunction.default)(updateShadow, 200);
60
+ const refresh = (0, import_react.useCallback)(() => {
61
+ setRefreshKey((prev) => prev + 1);
62
+ debouncedUpdateShadow();
63
+ }, [debouncedUpdateShadow]);
60
64
  (0, import_react.useEffect)(() => {
61
65
  const container = navContainer.current;
62
66
  const list = navList.current;
@@ -95,5 +99,5 @@ function useTabScroll({
95
99
  debouncedUpdateShadow,
96
100
  updateShadow
97
101
  ]);
98
- return { refreshKey, updateShadow: debouncedUpdateShadow };
102
+ return { refreshKey, refresh, updateShadow: debouncedUpdateShadow };
99
103
  }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import type { DataAttributeProps } from '../utils/types';
3
- type SemanticDOM = 'header' | 'content' | 'track' | 'list' | 'activeBar';
3
+ type SemanticDOM = 'header' | 'content' | 'track' | 'list' | 'activeBar' | 'more';
4
4
  export type TabItemType = {
5
5
  /**
6
6
  * Unique key corresponding to activeKey
@@ -121,5 +121,14 @@ export interface TabsProps extends DataAttributeProps {
121
121
  * @default false
122
122
  */
123
123
  fixedHeader?: boolean;
124
+ /**
125
+ * How the active tab is aligned when the tab list overflows
126
+ * - 'auto': scroll minimally so the active tab is visible at the edge;
127
+ * no scrolling when it is already fully visible
128
+ * - 'center': always scroll so the active tab is centered in the header,
129
+ * including tabs clicked directly on the header
130
+ * @default 'auto'
131
+ */
132
+ activeAlign?: 'auto' | 'center';
124
133
  }
125
134
  export {};
@@ -439,6 +439,10 @@
439
439
  height: var(--yee-tabs-nav-operations-height);
440
440
  }
441
441
 
442
+ @{pls}-nav-more {
443
+ margin-left: 4px;
444
+ }
445
+
442
446
  // 下拉框
443
447
  @{pls}-operation-container {
444
448
  max-height: var(--yee-tabs-operation-container-max-height);
@@ -452,6 +456,7 @@
452
456
 
453
457
  @{pls}-tab {
454
458
  height: var(--yee-tabs-operation-tab-height);
459
+ margin: 0;
455
460
  padding: var(--yee-tabs-operation-tab-padding);
456
461
  cursor: pointer;
457
462
 
@@ -12,6 +12,7 @@ export interface TabHeaderProps {
12
12
  prefixCls: string;
13
13
  type?: 'card' | 'editable-card';
14
14
  position?: 'top' | 'bottom' | 'left' | 'right';
15
+ activeAlign?: 'auto' | 'center';
15
16
  headerExtra?: {
16
17
  prefix?: React.ReactNode | (() => React.ReactNode);
17
18
  suffix?: React.ReactNode | (() => React.ReactNode);
@@ -67,6 +67,7 @@ var TabHeader = (props) => {
67
67
  prefixCls,
68
68
  type,
69
69
  position = "top",
70
+ activeAlign = "auto",
70
71
  headerExtra,
71
72
  classNames,
72
73
  styles,
@@ -84,7 +85,7 @@ var TabHeader = (props) => {
84
85
  navList,
85
86
  itemsLength: (items == null ? void 0 : items.length) || 0
86
87
  });
87
- const { refreshKey } = (0, import_hooks.useTabScroll)({
88
+ const { refreshKey, refresh: refreshNav } = (0, import_hooks.useTabScroll)({
88
89
  direction,
89
90
  navContainer,
90
91
  navList,
@@ -99,14 +100,19 @@ var TabHeader = (props) => {
99
100
  enabled: !type
100
101
  // Only show active bar for non-card types
101
102
  });
103
+ const handleNavMoved = (0, import_react.useCallback)(() => {
104
+ checkVisibility();
105
+ refreshNav();
106
+ }, [checkVisibility, refreshNav]);
102
107
  (0, import_hooks.useNavListMove)({
103
108
  direction,
104
109
  activeKey,
105
110
  enabled: moreOpen,
111
+ align: activeAlign,
106
112
  activetab,
107
113
  navList,
108
114
  navContainer,
109
- onMoved: checkVisibility
115
+ onMoved: handleNavMoved
110
116
  });
111
117
  (0, import_hooks.useContainerResize)(navContainer, checkVisibility);
112
118
  const renderPrefixExtra = (0, import_react.useCallback)(() => {
@@ -197,7 +203,9 @@ var TabHeader = (props) => {
197
203
  ), moreOpen && /* @__PURE__ */ import_react.default.createElement(import_dropdown_tabs.default, { visible: moreOpen, items: items || [], range }, /* @__PURE__ */ import_react.default.createElement(
198
204
  import_Button.default,
199
205
  {
200
- className: `${prefixCls}-nav-more`,
206
+ className: (0, import_clsx.default)(`${prefixCls}-nav-more`, classNames == null ? void 0 : classNames.more),
207
+ style: styles == null ? void 0 : styles.more,
208
+ size: "small",
201
209
  icon: /* @__PURE__ */ import_react.default.createElement(import_lucide_react.Ellipsis, { size: 14, strokeWidth: 1.5 }),
202
210
  type: "text",
203
211
  "aria-label": "More tabs"
@@ -88,6 +88,7 @@ var Tabs = (baseprops) => {
88
88
  activeKey,
89
89
  defaultActiveKey,
90
90
  fixedHeader,
91
+ activeAlign,
91
92
  onChange,
92
93
  onEdit,
93
94
  onTabClick
@@ -104,6 +105,7 @@ var Tabs = (baseprops) => {
104
105
  "activeKey",
105
106
  "defaultActiveKey",
106
107
  "fixedHeader",
108
+ "activeAlign",
107
109
  "onChange",
108
110
  "onEdit",
109
111
  "onTabClick"
@@ -167,7 +169,8 @@ var Tabs = (baseprops) => {
167
169
  return /* @__PURE__ */ import_react.default.createElement("div", __spreadProps(__spreadValues({}, (0, import_omit.default)(rest, ["headerExtra"])), { className: cls, style }), /* @__PURE__ */ import_react.default.createElement(TabsCtx.Provider, { value: contextValue }, /* @__PURE__ */ import_react.default.createElement(
168
170
  import_tab_header.default,
169
171
  __spreadProps(__spreadValues({}, (0, import_omit.default)(props, ["children", "className", "style"])), {
170
- prefixCls
172
+ prefixCls,
173
+ activeAlign
171
174
  })
172
175
  ), /* @__PURE__ */ import_react.default.createElement(
173
176
  import_tab_content.default,
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const _default: () => React.JSX.Element;
3
+ export default _default;