@zat-design/sisyphus-react 3.6.6-beta.6 → 3.6.6-beta.7

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.
@@ -1783,6 +1783,15 @@
1783
1783
  .pro-table.pro-table-draggable-only .ant-table-tbody .anticon {
1784
1784
  margin-right: 0;
1785
1785
  }
1786
+ .pro-table .ant-table-cell-with-append {
1787
+ white-space: nowrap;
1788
+ position: relative;
1789
+ z-index: 100;
1790
+ }
1791
+ .pro-table .ant-table-row-expand-icon {
1792
+ position: absolute;
1793
+ left: -16px;
1794
+ }
1786
1795
  .pro-table .ant-table-content > table .ant-table-summary {
1787
1796
  background-color: var(--zaui-table-header-bg, #f2f3f5);
1788
1797
  color: var(--zaui-text, #343434);
package/dist/less.esm.css CHANGED
@@ -1783,6 +1783,15 @@
1783
1783
  .pro-table.pro-table-draggable-only .ant-table-tbody .anticon {
1784
1784
  margin-right: 0;
1785
1785
  }
1786
+ .pro-table .ant-table-cell-with-append {
1787
+ white-space: nowrap;
1788
+ position: relative;
1789
+ z-index: 100;
1790
+ }
1791
+ .pro-table .ant-table-row-expand-icon {
1792
+ position: absolute;
1793
+ left: -16px;
1794
+ }
1786
1795
  .pro-table .ant-table-content > table .ant-table-summary {
1787
1796
  background-color: var(--zaui-table-header-bg, #f2f3f5);
1788
1797
  color: var(--zaui-text, #343434);
@@ -2,6 +2,5 @@ import { InternalNamePath, FormInstance, NamePath } from 'rc-field-form/es/inter
2
2
  export declare function toArray<T>(value?: T | T[] | null): T[];
3
3
  export declare function getNamePath(path: NamePath | null): InternalNamePath;
4
4
  export declare function stringify(value: any): string | number;
5
- declare function useWatch(dependencies: string, form?: FormInstance, wait?: number): any;
6
- declare function useWatch(dependencies: NamePath[], form?: FormInstance, wait?: number): any[];
5
+ declare function useWatch(dependencies: string | NamePath[], form?: FormInstance, wait?: number): any;
7
6
  export default useWatch;
@@ -5,11 +5,12 @@ interface RowProps extends React.HTMLAttributes<HTMLTableRowElement> {
5
5
  disabled?: boolean;
6
6
  }
7
7
  export declare const Row: FC<RowProps>;
8
- declare const DndWrapper: ({ draggable, value, onChange, disabled, children }: {
8
+ declare const DndWrapper: ({ draggable, value, onChange, disabled, children, rowKey }: {
9
9
  draggable: any;
10
10
  value: any;
11
11
  onChange: any;
12
12
  disabled: any;
13
13
  children: any;
14
+ rowKey: any;
14
15
  }) => any;
15
16
  export default DndWrapper;
@@ -1,11 +1,13 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
1
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
3
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
4
  var _excluded = ["disabled", "children"];
4
5
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
6
  import React from 'react';
6
- import { DndContext } from '@dnd-kit/core';
7
+ import { DndContext, closestCorners } from '@dnd-kit/core';
7
8
  import { arrayMove, useSortable, SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable';
8
9
  import { CSS } from '@dnd-kit/utilities';
10
+ import { addLevelAndParentId, treeNodeFind, transformTreeToArray, createTreeFromArray } from './utils/index';
9
11
  import ProIcon from '../../../ProIcon';
10
12
  export var Row = function Row(props) {
11
13
  var disabled = props.disabled,
@@ -60,30 +62,67 @@ export var Row = function Row(props) {
60
62
  }));
61
63
  };
62
64
  var DndWrapper = function DndWrapper(_ref2) {
63
- var _value$;
65
+ var _flatTree$;
64
66
  var draggable = _ref2.draggable,
65
67
  value = _ref2.value,
66
68
  onChange = _ref2.onChange,
67
69
  disabled = _ref2.disabled,
68
- children = _ref2.children;
70
+ children = _ref2.children,
71
+ rowKey = _ref2.rowKey;
69
72
  var onDragEnd = function onDragEnd(_ref3) {
70
73
  var active = _ref3.active,
71
74
  over = _ref3.over;
75
+ // 为数据源划分层级及parentId
76
+ var transformedValue = addLevelAndParentId(value, rowKey);
77
+ // 同一level层级的且parentId相同的,可以互相之间拖拽替换
72
78
  if (active.id !== (over === null || over === void 0 ? void 0 : over.id)) {
73
- var activeIndex = value.findIndex(function (i) {
74
- return i.rowKey === active.id;
79
+ var activeObject = treeNodeFind(transformedValue, function (t) {
80
+ return t.rowKey === active.id;
75
81
  });
76
- var overIndex = value.findIndex(function (i) {
77
- return i.rowKey === (over === null || over === void 0 ? void 0 : over.id);
82
+ var overObject = treeNodeFind(transformedValue, function (t) {
83
+ return t.rowKey === (over === null || over === void 0 ? void 0 : over.id);
78
84
  });
79
- var nextValue = arrayMove(value, activeIndex, overIndex);
80
- onChange(nextValue);
85
+ if (activeObject && overObject) {
86
+ var activeLevel = activeObject.level,
87
+ activeParentId = activeObject.parentId;
88
+ var overLevel = overObject.level,
89
+ overParentId = overObject.parentId;
90
+ if (activeLevel === overLevel && activeParentId === overParentId) {
91
+ // 将树平铺
92
+ var _flatTree = transformTreeToArray(transformedValue).map(function (item) {
93
+ return _objectSpread(_objectSpread({}, item), {}, {
94
+ children: undefined
95
+ });
96
+ });
97
+ var activeIndex = _flatTree.findIndex(function (i) {
98
+ return i.rowKey === active.id;
99
+ });
100
+ var overIndex = _flatTree.findIndex(function (i) {
101
+ return i.rowKey === (over === null || over === void 0 ? void 0 : over.id);
102
+ });
103
+ var nextValue = arrayMove(_flatTree, activeIndex, overIndex);
104
+ onChange(createTreeFromArray(nextValue, {
105
+ itemKey: 'rowKey',
106
+ parentKey: 'parentId',
107
+ childrenKey: 'children'
108
+ }));
109
+ }
110
+ }
111
+ } else {
112
+ onChange(_toConsumableArray(value));
81
113
  }
82
114
  };
115
+ // 将树平铺
116
+ var flatTree = transformTreeToArray(value).map(function (item) {
117
+ return _objectSpread(_objectSpread({}, item), {}, {
118
+ children: undefined
119
+ });
120
+ });
83
121
  return draggable && !disabled ? _jsx(DndContext, {
84
122
  onDragEnd: onDragEnd,
123
+ collisionDetection: closestCorners,
85
124
  children: _jsx(SortableContext, {
86
- items: (value === null || value === void 0 ? void 0 : (_value$ = value[0]) === null || _value$ === void 0 ? void 0 : _value$.rowKey) ? value.map(function (i) {
125
+ items: (flatTree === null || flatTree === void 0 ? void 0 : (_flatTree$ = flatTree[0]) === null || _flatTree$ === void 0 ? void 0 : _flatTree$.rowKey) ? flatTree.map(function (i) {
87
126
  return i.rowKey;
88
127
  }) : [],
89
128
  strategy: verticalListSortingStrategy,
@@ -0,0 +1,8 @@
1
+ import { ChildrenKey, Tree, BaseCallbackMeta, BaseInnerOptions, FindCallback, FindOptions, ArrayItemWithParentKey, FromArrayOptions, TreeWithParentKey, TypeOfKey, ForeachOptions, ForeachCallback, ToArrayOptions } from './propsType';
2
+ export declare const getRowKey: (rowKey: any, record: any) => any;
3
+ export declare const addLevelAndParentId: (tree: any[], rowKey: any, currentLevel?: number, currentParentId?: any) => any[];
4
+ export declare function getFinalChildrenKey<T extends ChildrenKey>(tree: Tree<T>, meta: BaseCallbackMeta, options: BaseInnerOptions<T>): ChildrenKey;
5
+ export declare function treeNodeFind<T extends ChildrenKey>(tree: Tree<T> | Tree<T>[], callback: FindCallback<T>, options?: FindOptions): Tree<T> | undefined;
6
+ export declare function createTreeFromArray<K extends TypeOfKey, P extends TypeOfKey, T extends ChildrenKey>(array: ArrayItemWithParentKey<K, P>[], options?: FromArrayOptions): TreeWithParentKey<K, P, T>[];
7
+ export declare function treeForEach<T extends ChildrenKey>(tree: Tree<T> | Tree<T>[], callback: ForeachCallback<T>, options?: ForeachOptions): void;
8
+ export declare function transformTreeToArray<T extends ChildrenKey>(tree: Tree<T> | Tree<T>[], options?: ToArrayOptions): Tree<T>[];
@@ -0,0 +1,165 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ export var getRowKey = function getRowKey(rowKey, record) {
4
+ // 默认取id
5
+ var key = record.rowKey || 'id';
6
+ if (rowKey) {
7
+ var _ref;
8
+ key = (_ref = typeof rowKey === 'function' ? rowKey(record) : record[rowKey]) !== null && _ref !== void 0 ? _ref : key;
9
+ }
10
+ return key;
11
+ };
12
+ var _addLevelAndParentId = function addLevelAndParentId(tree, rowKey) {
13
+ var currentLevel = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
14
+ var currentParentId = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
15
+ return tree.map(function (node) {
16
+ var newNode = _objectSpread({}, node);
17
+ newNode.level = currentLevel;
18
+ newNode.parentId = currentParentId;
19
+ newNode.rowKey = getRowKey(rowKey, node);
20
+ if (node.children) {
21
+ newNode.children = _addLevelAndParentId(node.children, rowKey, currentLevel + 1, newNode.rowKey);
22
+ }
23
+ return newNode;
24
+ });
25
+ };
26
+ export { _addLevelAndParentId as addLevelAndParentId };
27
+ export function getFinalChildrenKey(tree, meta, options) {
28
+ if (typeof options.getChildrenKey === 'function') {
29
+ var dynamicChildrenKey = options.getChildrenKey(tree, meta);
30
+ if (dynamicChildrenKey != null) {
31
+ return dynamicChildrenKey;
32
+ }
33
+ }
34
+ return options.childrenKey;
35
+ }
36
+ // 前置深度优先遍历
37
+ var _treeNodePreImpl = function treeNodePreImpl(treeItem, callback, options) {
38
+ var callbackResult = callback(treeItem, options);
39
+ if (callbackResult) {
40
+ return treeItem;
41
+ }
42
+ var finalChildrenKey = getFinalChildrenKey(treeItem, options, options);
43
+ var children = treeItem[finalChildrenKey];
44
+ if (!children || !Array.isArray(children)) {
45
+ return undefined;
46
+ }
47
+ for (var i = 0, count = children.length; i < count; i++) {
48
+ var childItem = children[i];
49
+ var findOne = _treeNodePreImpl(childItem, callback, _objectSpread(_objectSpread({}, options), {}, {
50
+ parents: [].concat(_toConsumableArray(options.parents), [treeItem]),
51
+ depth: options.depth + 1
52
+ }));
53
+ if (findOne) {
54
+ return findOne;
55
+ }
56
+ }
57
+ return undefined;
58
+ };
59
+ var treeNodeStrategies = {
60
+ pre: _treeNodePreImpl
61
+ };
62
+ export function treeNodeFind(tree, callback, options) {
63
+ var _options$childrenKey, _options$strategy;
64
+ var childrenKey = (_options$childrenKey = options === null || options === void 0 ? void 0 : options.childrenKey) !== null && _options$childrenKey !== void 0 ? _options$childrenKey : 'children';
65
+ var strategy = (_options$strategy = options === null || options === void 0 ? void 0 : options.strategy) !== null && _options$strategy !== void 0 ? _options$strategy : 'pre';
66
+ var getChildrenKey = options === null || options === void 0 ? void 0 : options.getChildrenKey;
67
+ var method = treeNodeStrategies[strategy];
68
+ var innerOptions = {
69
+ childrenKey: childrenKey,
70
+ depth: 0,
71
+ parents: [],
72
+ getChildrenKey: getChildrenKey
73
+ };
74
+ if (Array.isArray(tree)) {
75
+ for (var i = 0, count = tree.length; i < count; i++) {
76
+ var treeItem = tree[i];
77
+ var result = method(treeItem, callback, innerOptions);
78
+ if (result) {
79
+ return result;
80
+ }
81
+ }
82
+ return undefined;
83
+ }
84
+ return method(tree, callback, innerOptions);
85
+ }
86
+ export function createTreeFromArray(array, options) {
87
+ var result = [];
88
+ var _ref2 = options || {},
89
+ _ref2$parentKey = _ref2.parentKey,
90
+ parentKey = _ref2$parentKey === void 0 ? 'pid' : _ref2$parentKey,
91
+ _ref2$itemKey = _ref2.itemKey,
92
+ itemKey = _ref2$itemKey === void 0 ? 'id' : _ref2$itemKey,
93
+ _ref2$childrenKey = _ref2.childrenKey,
94
+ childrenKey = _ref2$childrenKey === void 0 ? 'children' : _ref2$childrenKey;
95
+ var map = new Map();
96
+ array.map(function (item) {
97
+ var itemKeyValue = item[itemKey];
98
+ if (!map.get(itemKeyValue)) {
99
+ map.set(itemKeyValue, item);
100
+ }
101
+ return item;
102
+ });
103
+ array.map(function (item) {
104
+ var parentKeyValue = item[parentKey];
105
+ var parentItem = map.get(parentKeyValue);
106
+ if (!parentItem || !parentKeyValue) {
107
+ result.push(item);
108
+ return;
109
+ }
110
+ var siblings = parentItem[childrenKey];
111
+ if (siblings === null || siblings === undefined) {
112
+ // disable eslint tslint
113
+ parentItem[childrenKey] = [item];
114
+ } else if (Array.isArray(siblings)) {
115
+ siblings.push(item);
116
+ } else {
117
+ var msg = "the key \"".concat(childrenKey, "\" is not an array, please check your data");
118
+ throw new Error(msg);
119
+ }
120
+ return item;
121
+ });
122
+ return result;
123
+ }
124
+ // 前置遍历
125
+ var _treeForEachPreImpl = function treeForEachPreImpl(treeItem, callback, options) {
126
+ callback(treeItem, options);
127
+ var finalChildrenKey = getFinalChildrenKey(treeItem, options, options);
128
+ var children = treeItem[finalChildrenKey];
129
+ if (children && Array.isArray(children)) {
130
+ var nextLevelOptions = _objectSpread(_objectSpread({}, options), {}, {
131
+ parents: [].concat(_toConsumableArray(options.parents), [treeItem]),
132
+ depth: options.depth + 1
133
+ });
134
+ children.forEach(function (childItem) {
135
+ _treeForEachPreImpl(childItem, callback, nextLevelOptions);
136
+ });
137
+ }
138
+ };
139
+ var treeForEachStrategies = {
140
+ pre: _treeForEachPreImpl
141
+ };
142
+ export function treeForEach(tree, callback, options) {
143
+ var _options$childrenKey2, _options$strategy2;
144
+ var childrenKey = (_options$childrenKey2 = options === null || options === void 0 ? void 0 : options.childrenKey) !== null && _options$childrenKey2 !== void 0 ? _options$childrenKey2 : 'children';
145
+ var strategy = (_options$strategy2 = options === null || options === void 0 ? void 0 : options.strategy) !== null && _options$strategy2 !== void 0 ? _options$strategy2 : 'pre';
146
+ var getChildrenKey = options === null || options === void 0 ? void 0 : options.getChildrenKey;
147
+ var isForest = Array.isArray(tree);
148
+ var method = treeForEachStrategies[strategy];
149
+ var innerOptions = {
150
+ childrenKey: childrenKey,
151
+ depth: 0,
152
+ parents: [],
153
+ getChildrenKey: getChildrenKey
154
+ };
155
+ isForest ? tree.forEach(function (tree) {
156
+ method(tree, callback, innerOptions);
157
+ }) : method(tree, callback, innerOptions);
158
+ }
159
+ export function transformTreeToArray(tree, options) {
160
+ var results = [];
161
+ treeForEach(tree, function (t) {
162
+ results.push(t);
163
+ }, options);
164
+ return results;
165
+ }
@@ -0,0 +1,61 @@
1
+ export type TreeKey = string | number;
2
+ export type ChildrenKey = TreeKey;
3
+ export type Tree<T extends ChildrenKey = 'children'> = {
4
+ [key in T]?: Tree<T>[];
5
+ } & {
6
+ [key in TreeKey]: any;
7
+ };
8
+ export type Strategy = 'pre' | 'post' | 'breadth';
9
+ export interface BaseOptions {
10
+ itemKey?: String;
11
+ parentKey?: String;
12
+ childrenKey?: ChildrenKey;
13
+ strategy?: Strategy;
14
+ getChildrenKey?: (tree: Tree, meta: BaseCallbackMeta) => ChildrenKey | undefined;
15
+ }
16
+ export interface BaseInnerOptions<T extends ChildrenKey = 'children'> {
17
+ childrenKey: ChildrenKey;
18
+ parents: Tree<T>[];
19
+ depth: number;
20
+ getChildrenKey?: (tree: Tree, meta: BaseCallbackMeta) => ChildrenKey | undefined;
21
+ }
22
+ export interface BaseCallbackMeta<T extends ChildrenKey = 'children'> {
23
+ depth: number;
24
+ parents?: Tree<T>[];
25
+ }
26
+ export type FindOptions = BaseOptions;
27
+ export type FindCallbackMeta<T extends ChildrenKey> = BaseCallbackMeta<T>;
28
+ export type FindCallback<T extends ChildrenKey> = (treeItem: Tree<T>, meta: FindCallbackMeta<T>) => boolean | undefined;
29
+ type FindInnerOption<T extends ChildrenKey> = BaseInnerOptions<T>;
30
+ export type FindImpl<T extends ChildrenKey> = (treeItem: Tree<T>, callback: FindCallback<T>, options: FindInnerOption<T>) => Tree<T> | undefined;
31
+ export interface QueueItem {
32
+ tree: Tree<ChildrenKey>;
33
+ options: FindInnerOption<ChildrenKey>;
34
+ }
35
+ export type TypeOfKey = string;
36
+ export type KeyValue = string | number | undefined | null;
37
+ export type ArrayItemWithParentKey<P extends TypeOfKey, K extends TypeOfKey> = Record<string, any> & {
38
+ [key in P]?: KeyValue;
39
+ } & {
40
+ [key in K]?: KeyValue;
41
+ };
42
+ export type TreeWithParentKey<K extends TypeOfKey, P extends TypeOfKey, T extends ChildrenKey> = Record<string, any> & {
43
+ [key in P]?: KeyValue;
44
+ } & {
45
+ [key in K]: KeyValue;
46
+ } & {
47
+ [key in T]?: TreeWithParentKey<K, P, T>[];
48
+ };
49
+ export interface FromArrayOptions {
50
+ parentKey?: TypeOfKey;
51
+ itemKey?: TypeOfKey;
52
+ childrenKey?: ChildrenKey;
53
+ }
54
+ export type FromArray<K extends TypeOfKey, P extends TypeOfKey, T extends ChildrenKey> = (array: ArrayItemWithParentKey<K, P>[], options: FromArrayOptions) => TreeWithParentKey<K, P, T>[];
55
+ export type ForeachOptions = BaseOptions;
56
+ export type ForeachCallbackMeta<T extends ChildrenKey> = BaseCallbackMeta<T>;
57
+ export type ForeachCallback<T extends ChildrenKey> = (treeItem: Tree<T>, meta: ForeachCallbackMeta<T>) => void;
58
+ export type ForeachInnerOption<T extends ChildrenKey> = BaseInnerOptions<T>;
59
+ export type ForeachImpl<T extends ChildrenKey> = (treeItem: Tree<T>, callback: ForeachCallback<T>, options: ForeachInnerOption<T>) => void;
60
+ export type ToArrayOptions = ForeachOptions;
61
+ export {};
@@ -370,6 +370,7 @@ function ProTable(props) {
370
370
  onChange: onDataSourceChange,
371
371
  disabled: false,
372
372
  draggable: draggable,
373
+ rowKey: rowKey,
373
374
  children: [(headerRender || columnConfig || resizeColumn) && _jsxs("div", {
374
375
  className: "column-config",
375
376
  children: [_jsx("div", {
@@ -9,6 +9,15 @@
9
9
  }
10
10
  }
11
11
  }
12
+ .@{ant-prefix}-table-cell-with-append {
13
+ white-space: nowrap;
14
+ position: relative;
15
+ z-index: 100;
16
+ }
17
+ .@{ant-prefix}-table-row-expand-icon {
18
+ position: absolute;
19
+ left: -16px;
20
+ }
12
21
 
13
22
  .@{ant-prefix}-table-content {
14
23
  >table {
@@ -2,6 +2,5 @@ import { InternalNamePath, FormInstance, NamePath } from 'rc-field-form/es/inter
2
2
  export declare function toArray<T>(value?: T | T[] | null): T[];
3
3
  export declare function getNamePath(path: NamePath | null): InternalNamePath;
4
4
  export declare function stringify(value: any): string | number;
5
- declare function useWatch(dependencies: string, form?: FormInstance, wait?: number): any;
6
- declare function useWatch(dependencies: NamePath[], form?: FormInstance, wait?: number): any[];
5
+ declare function useWatch(dependencies: string | NamePath[], form?: FormInstance, wait?: number): any;
7
6
  export default useWatch;
@@ -5,11 +5,12 @@ interface RowProps extends React.HTMLAttributes<HTMLTableRowElement> {
5
5
  disabled?: boolean;
6
6
  }
7
7
  export declare const Row: FC<RowProps>;
8
- declare const DndWrapper: ({ draggable, value, onChange, disabled, children }: {
8
+ declare const DndWrapper: ({ draggable, value, onChange, disabled, children, rowKey }: {
9
9
  draggable: any;
10
10
  value: any;
11
11
  onChange: any;
12
12
  disabled: any;
13
13
  children: any;
14
+ rowKey: any;
14
15
  }) => any;
15
16
  export default DndWrapper;
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = exports.Row = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
8
9
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
10
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
11
  var _jsxRuntime = require("react/jsx-runtime");
@@ -12,6 +13,7 @@ var _react = _interopRequireDefault(require("react"));
12
13
  var _core = require("@dnd-kit/core");
13
14
  var _sortable = require("@dnd-kit/sortable");
14
15
  var _utilities = require("@dnd-kit/utilities");
16
+ var _index = require("./utils/index");
15
17
  var _ProIcon = _interopRequireDefault(require("../../../ProIcon"));
16
18
  var _excluded = ["disabled", "children"];
17
19
  var Row = exports.Row = function Row(props) {
@@ -67,30 +69,67 @@ var Row = exports.Row = function Row(props) {
67
69
  }));
68
70
  };
69
71
  var DndWrapper = function DndWrapper(_ref2) {
70
- var _value$;
72
+ var _flatTree$;
71
73
  var draggable = _ref2.draggable,
72
74
  value = _ref2.value,
73
75
  onChange = _ref2.onChange,
74
76
  disabled = _ref2.disabled,
75
- children = _ref2.children;
77
+ children = _ref2.children,
78
+ rowKey = _ref2.rowKey;
76
79
  var onDragEnd = function onDragEnd(_ref3) {
77
80
  var active = _ref3.active,
78
81
  over = _ref3.over;
82
+ // 为数据源划分层级及parentId
83
+ var transformedValue = (0, _index.addLevelAndParentId)(value, rowKey);
84
+ // 同一level层级的且parentId相同的,可以互相之间拖拽替换
79
85
  if (active.id !== (over === null || over === void 0 ? void 0 : over.id)) {
80
- var activeIndex = value.findIndex(function (i) {
81
- return i.rowKey === active.id;
86
+ var activeObject = (0, _index.treeNodeFind)(transformedValue, function (t) {
87
+ return t.rowKey === active.id;
82
88
  });
83
- var overIndex = value.findIndex(function (i) {
84
- return i.rowKey === (over === null || over === void 0 ? void 0 : over.id);
89
+ var overObject = (0, _index.treeNodeFind)(transformedValue, function (t) {
90
+ return t.rowKey === (over === null || over === void 0 ? void 0 : over.id);
85
91
  });
86
- var nextValue = (0, _sortable.arrayMove)(value, activeIndex, overIndex);
87
- onChange(nextValue);
92
+ if (activeObject && overObject) {
93
+ var activeLevel = activeObject.level,
94
+ activeParentId = activeObject.parentId;
95
+ var overLevel = overObject.level,
96
+ overParentId = overObject.parentId;
97
+ if (activeLevel === overLevel && activeParentId === overParentId) {
98
+ // 将树平铺
99
+ var _flatTree = (0, _index.transformTreeToArray)(transformedValue).map(function (item) {
100
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, item), {}, {
101
+ children: undefined
102
+ });
103
+ });
104
+ var activeIndex = _flatTree.findIndex(function (i) {
105
+ return i.rowKey === active.id;
106
+ });
107
+ var overIndex = _flatTree.findIndex(function (i) {
108
+ return i.rowKey === (over === null || over === void 0 ? void 0 : over.id);
109
+ });
110
+ var nextValue = (0, _sortable.arrayMove)(_flatTree, activeIndex, overIndex);
111
+ onChange((0, _index.createTreeFromArray)(nextValue, {
112
+ itemKey: 'rowKey',
113
+ parentKey: 'parentId',
114
+ childrenKey: 'children'
115
+ }));
116
+ }
117
+ }
118
+ } else {
119
+ onChange((0, _toConsumableArray2.default)(value));
88
120
  }
89
121
  };
122
+ // 将树平铺
123
+ var flatTree = (0, _index.transformTreeToArray)(value).map(function (item) {
124
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, item), {}, {
125
+ children: undefined
126
+ });
127
+ });
90
128
  return draggable && !disabled ? (0, _jsxRuntime.jsx)(_core.DndContext, {
91
129
  onDragEnd: onDragEnd,
130
+ collisionDetection: _core.closestCorners,
92
131
  children: (0, _jsxRuntime.jsx)(_sortable.SortableContext, {
93
- items: (value === null || value === void 0 ? void 0 : (_value$ = value[0]) === null || _value$ === void 0 ? void 0 : _value$.rowKey) ? value.map(function (i) {
132
+ items: (flatTree === null || flatTree === void 0 ? void 0 : (_flatTree$ = flatTree[0]) === null || _flatTree$ === void 0 ? void 0 : _flatTree$.rowKey) ? flatTree.map(function (i) {
94
133
  return i.rowKey;
95
134
  }) : [],
96
135
  strategy: _sortable.verticalListSortingStrategy,
@@ -0,0 +1,8 @@
1
+ import { ChildrenKey, Tree, BaseCallbackMeta, BaseInnerOptions, FindCallback, FindOptions, ArrayItemWithParentKey, FromArrayOptions, TreeWithParentKey, TypeOfKey, ForeachOptions, ForeachCallback, ToArrayOptions } from './propsType';
2
+ export declare const getRowKey: (rowKey: any, record: any) => any;
3
+ export declare const addLevelAndParentId: (tree: any[], rowKey: any, currentLevel?: number, currentParentId?: any) => any[];
4
+ export declare function getFinalChildrenKey<T extends ChildrenKey>(tree: Tree<T>, meta: BaseCallbackMeta, options: BaseInnerOptions<T>): ChildrenKey;
5
+ export declare function treeNodeFind<T extends ChildrenKey>(tree: Tree<T> | Tree<T>[], callback: FindCallback<T>, options?: FindOptions): Tree<T> | undefined;
6
+ export declare function createTreeFromArray<K extends TypeOfKey, P extends TypeOfKey, T extends ChildrenKey>(array: ArrayItemWithParentKey<K, P>[], options?: FromArrayOptions): TreeWithParentKey<K, P, T>[];
7
+ export declare function treeForEach<T extends ChildrenKey>(tree: Tree<T> | Tree<T>[], callback: ForeachCallback<T>, options?: ForeachOptions): void;
8
+ export declare function transformTreeToArray<T extends ChildrenKey>(tree: Tree<T> | Tree<T>[], options?: ToArrayOptions): Tree<T>[];
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.addLevelAndParentId = void 0;
8
+ exports.createTreeFromArray = createTreeFromArray;
9
+ exports.getFinalChildrenKey = getFinalChildrenKey;
10
+ exports.getRowKey = void 0;
11
+ exports.transformTreeToArray = transformTreeToArray;
12
+ exports.treeForEach = treeForEach;
13
+ exports.treeNodeFind = treeNodeFind;
14
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
15
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
+ var getRowKey = exports.getRowKey = function getRowKey(rowKey, record) {
17
+ // 默认取id
18
+ var key = record.rowKey || 'id';
19
+ if (rowKey) {
20
+ var _ref;
21
+ key = (_ref = typeof rowKey === 'function' ? rowKey(record) : record[rowKey]) !== null && _ref !== void 0 ? _ref : key;
22
+ }
23
+ return key;
24
+ };
25
+ var _addLevelAndParentId = exports.addLevelAndParentId = function addLevelAndParentId(tree, rowKey) {
26
+ var currentLevel = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
27
+ var currentParentId = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
28
+ return tree.map(function (node) {
29
+ var newNode = (0, _objectSpread2.default)({}, node);
30
+ newNode.level = currentLevel;
31
+ newNode.parentId = currentParentId;
32
+ newNode.rowKey = getRowKey(rowKey, node);
33
+ if (node.children) {
34
+ newNode.children = _addLevelAndParentId(node.children, rowKey, currentLevel + 1, newNode.rowKey);
35
+ }
36
+ return newNode;
37
+ });
38
+ };
39
+ function getFinalChildrenKey(tree, meta, options) {
40
+ if (typeof options.getChildrenKey === 'function') {
41
+ var dynamicChildrenKey = options.getChildrenKey(tree, meta);
42
+ if (dynamicChildrenKey != null) {
43
+ return dynamicChildrenKey;
44
+ }
45
+ }
46
+ return options.childrenKey;
47
+ }
48
+ // 前置深度优先遍历
49
+ var _treeNodePreImpl = function treeNodePreImpl(treeItem, callback, options) {
50
+ var callbackResult = callback(treeItem, options);
51
+ if (callbackResult) {
52
+ return treeItem;
53
+ }
54
+ var finalChildrenKey = getFinalChildrenKey(treeItem, options, options);
55
+ var children = treeItem[finalChildrenKey];
56
+ if (!children || !Array.isArray(children)) {
57
+ return undefined;
58
+ }
59
+ for (var i = 0, count = children.length; i < count; i++) {
60
+ var childItem = children[i];
61
+ var findOne = _treeNodePreImpl(childItem, callback, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, options), {}, {
62
+ parents: [].concat((0, _toConsumableArray2.default)(options.parents), [treeItem]),
63
+ depth: options.depth + 1
64
+ }));
65
+ if (findOne) {
66
+ return findOne;
67
+ }
68
+ }
69
+ return undefined;
70
+ };
71
+ var treeNodeStrategies = {
72
+ pre: _treeNodePreImpl
73
+ };
74
+ function treeNodeFind(tree, callback, options) {
75
+ var _options$childrenKey, _options$strategy;
76
+ var childrenKey = (_options$childrenKey = options === null || options === void 0 ? void 0 : options.childrenKey) !== null && _options$childrenKey !== void 0 ? _options$childrenKey : 'children';
77
+ var strategy = (_options$strategy = options === null || options === void 0 ? void 0 : options.strategy) !== null && _options$strategy !== void 0 ? _options$strategy : 'pre';
78
+ var getChildrenKey = options === null || options === void 0 ? void 0 : options.getChildrenKey;
79
+ var method = treeNodeStrategies[strategy];
80
+ var innerOptions = {
81
+ childrenKey: childrenKey,
82
+ depth: 0,
83
+ parents: [],
84
+ getChildrenKey: getChildrenKey
85
+ };
86
+ if (Array.isArray(tree)) {
87
+ for (var i = 0, count = tree.length; i < count; i++) {
88
+ var treeItem = tree[i];
89
+ var result = method(treeItem, callback, innerOptions);
90
+ if (result) {
91
+ return result;
92
+ }
93
+ }
94
+ return undefined;
95
+ }
96
+ return method(tree, callback, innerOptions);
97
+ }
98
+ function createTreeFromArray(array, options) {
99
+ var result = [];
100
+ var _ref2 = options || {},
101
+ _ref2$parentKey = _ref2.parentKey,
102
+ parentKey = _ref2$parentKey === void 0 ? 'pid' : _ref2$parentKey,
103
+ _ref2$itemKey = _ref2.itemKey,
104
+ itemKey = _ref2$itemKey === void 0 ? 'id' : _ref2$itemKey,
105
+ _ref2$childrenKey = _ref2.childrenKey,
106
+ childrenKey = _ref2$childrenKey === void 0 ? 'children' : _ref2$childrenKey;
107
+ var map = new Map();
108
+ array.map(function (item) {
109
+ var itemKeyValue = item[itemKey];
110
+ if (!map.get(itemKeyValue)) {
111
+ map.set(itemKeyValue, item);
112
+ }
113
+ return item;
114
+ });
115
+ array.map(function (item) {
116
+ var parentKeyValue = item[parentKey];
117
+ var parentItem = map.get(parentKeyValue);
118
+ if (!parentItem || !parentKeyValue) {
119
+ result.push(item);
120
+ return;
121
+ }
122
+ var siblings = parentItem[childrenKey];
123
+ if (siblings === null || siblings === undefined) {
124
+ // disable eslint tslint
125
+ parentItem[childrenKey] = [item];
126
+ } else if (Array.isArray(siblings)) {
127
+ siblings.push(item);
128
+ } else {
129
+ var msg = "the key \"".concat(childrenKey, "\" is not an array, please check your data");
130
+ throw new Error(msg);
131
+ }
132
+ return item;
133
+ });
134
+ return result;
135
+ }
136
+ // 前置遍历
137
+ var _treeForEachPreImpl = function treeForEachPreImpl(treeItem, callback, options) {
138
+ callback(treeItem, options);
139
+ var finalChildrenKey = getFinalChildrenKey(treeItem, options, options);
140
+ var children = treeItem[finalChildrenKey];
141
+ if (children && Array.isArray(children)) {
142
+ var nextLevelOptions = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, options), {}, {
143
+ parents: [].concat((0, _toConsumableArray2.default)(options.parents), [treeItem]),
144
+ depth: options.depth + 1
145
+ });
146
+ children.forEach(function (childItem) {
147
+ _treeForEachPreImpl(childItem, callback, nextLevelOptions);
148
+ });
149
+ }
150
+ };
151
+ var treeForEachStrategies = {
152
+ pre: _treeForEachPreImpl
153
+ };
154
+ function treeForEach(tree, callback, options) {
155
+ var _options$childrenKey2, _options$strategy2;
156
+ var childrenKey = (_options$childrenKey2 = options === null || options === void 0 ? void 0 : options.childrenKey) !== null && _options$childrenKey2 !== void 0 ? _options$childrenKey2 : 'children';
157
+ var strategy = (_options$strategy2 = options === null || options === void 0 ? void 0 : options.strategy) !== null && _options$strategy2 !== void 0 ? _options$strategy2 : 'pre';
158
+ var getChildrenKey = options === null || options === void 0 ? void 0 : options.getChildrenKey;
159
+ var isForest = Array.isArray(tree);
160
+ var method = treeForEachStrategies[strategy];
161
+ var innerOptions = {
162
+ childrenKey: childrenKey,
163
+ depth: 0,
164
+ parents: [],
165
+ getChildrenKey: getChildrenKey
166
+ };
167
+ isForest ? tree.forEach(function (tree) {
168
+ method(tree, callback, innerOptions);
169
+ }) : method(tree, callback, innerOptions);
170
+ }
171
+ function transformTreeToArray(tree, options) {
172
+ var results = [];
173
+ treeForEach(tree, function (t) {
174
+ results.push(t);
175
+ }, options);
176
+ return results;
177
+ }
@@ -0,0 +1,61 @@
1
+ export type TreeKey = string | number;
2
+ export type ChildrenKey = TreeKey;
3
+ export type Tree<T extends ChildrenKey = 'children'> = {
4
+ [key in T]?: Tree<T>[];
5
+ } & {
6
+ [key in TreeKey]: any;
7
+ };
8
+ export type Strategy = 'pre' | 'post' | 'breadth';
9
+ export interface BaseOptions {
10
+ itemKey?: String;
11
+ parentKey?: String;
12
+ childrenKey?: ChildrenKey;
13
+ strategy?: Strategy;
14
+ getChildrenKey?: (tree: Tree, meta: BaseCallbackMeta) => ChildrenKey | undefined;
15
+ }
16
+ export interface BaseInnerOptions<T extends ChildrenKey = 'children'> {
17
+ childrenKey: ChildrenKey;
18
+ parents: Tree<T>[];
19
+ depth: number;
20
+ getChildrenKey?: (tree: Tree, meta: BaseCallbackMeta) => ChildrenKey | undefined;
21
+ }
22
+ export interface BaseCallbackMeta<T extends ChildrenKey = 'children'> {
23
+ depth: number;
24
+ parents?: Tree<T>[];
25
+ }
26
+ export type FindOptions = BaseOptions;
27
+ export type FindCallbackMeta<T extends ChildrenKey> = BaseCallbackMeta<T>;
28
+ export type FindCallback<T extends ChildrenKey> = (treeItem: Tree<T>, meta: FindCallbackMeta<T>) => boolean | undefined;
29
+ type FindInnerOption<T extends ChildrenKey> = BaseInnerOptions<T>;
30
+ export type FindImpl<T extends ChildrenKey> = (treeItem: Tree<T>, callback: FindCallback<T>, options: FindInnerOption<T>) => Tree<T> | undefined;
31
+ export interface QueueItem {
32
+ tree: Tree<ChildrenKey>;
33
+ options: FindInnerOption<ChildrenKey>;
34
+ }
35
+ export type TypeOfKey = string;
36
+ export type KeyValue = string | number | undefined | null;
37
+ export type ArrayItemWithParentKey<P extends TypeOfKey, K extends TypeOfKey> = Record<string, any> & {
38
+ [key in P]?: KeyValue;
39
+ } & {
40
+ [key in K]?: KeyValue;
41
+ };
42
+ export type TreeWithParentKey<K extends TypeOfKey, P extends TypeOfKey, T extends ChildrenKey> = Record<string, any> & {
43
+ [key in P]?: KeyValue;
44
+ } & {
45
+ [key in K]: KeyValue;
46
+ } & {
47
+ [key in T]?: TreeWithParentKey<K, P, T>[];
48
+ };
49
+ export interface FromArrayOptions {
50
+ parentKey?: TypeOfKey;
51
+ itemKey?: TypeOfKey;
52
+ childrenKey?: ChildrenKey;
53
+ }
54
+ export type FromArray<K extends TypeOfKey, P extends TypeOfKey, T extends ChildrenKey> = (array: ArrayItemWithParentKey<K, P>[], options: FromArrayOptions) => TreeWithParentKey<K, P, T>[];
55
+ export type ForeachOptions = BaseOptions;
56
+ export type ForeachCallbackMeta<T extends ChildrenKey> = BaseCallbackMeta<T>;
57
+ export type ForeachCallback<T extends ChildrenKey> = (treeItem: Tree<T>, meta: ForeachCallbackMeta<T>) => void;
58
+ export type ForeachInnerOption<T extends ChildrenKey> = BaseInnerOptions<T>;
59
+ export type ForeachImpl<T extends ChildrenKey> = (treeItem: Tree<T>, callback: ForeachCallback<T>, options: ForeachInnerOption<T>) => void;
60
+ export type ToArrayOptions = ForeachOptions;
61
+ export {};
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -374,6 +374,7 @@ function ProTable(props) {
374
374
  onChange: onDataSourceChange,
375
375
  disabled: false,
376
376
  draggable: draggable,
377
+ rowKey: rowKey,
377
378
  children: [(headerRender || columnConfig || resizeColumn) && (0, _jsxRuntime.jsxs)("div", {
378
379
  className: "column-config",
379
380
  children: [(0, _jsxRuntime.jsx)("div", {
@@ -9,6 +9,15 @@
9
9
  }
10
10
  }
11
11
  }
12
+ .@{ant-prefix}-table-cell-with-append {
13
+ white-space: nowrap;
14
+ position: relative;
15
+ z-index: 100;
16
+ }
17
+ .@{ant-prefix}-table-row-expand-icon {
18
+ position: absolute;
19
+ left: -16px;
20
+ }
12
21
 
13
22
  .@{ant-prefix}-table-content {
14
23
  >table {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zat-design/sisyphus-react",
3
- "version": "3.6.6-beta.6",
3
+ "version": "3.6.6-beta.7",
4
4
  "license": "Apache-2.0",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -68,8 +68,7 @@
68
68
  "rc-resize-observer": "^1.4.0",
69
69
  "react-resizable": "^3.0.4",
70
70
  "react-svg": "^15.1.7",
71
- "react-window": "^1.8.10",
72
- "commander": "<=9.2.0"
71
+ "react-window": "^1.8.10"
73
72
  },
74
73
  "peerDependencies": {
75
74
  "antd": "^4.24.8",
@@ -97,6 +96,7 @@
97
96
  "@zat-design/login-react": "1.0.25",
98
97
  "babel-eslint": "10.0.3",
99
98
  "babel-plugin-import": "^1.13.3",
99
+ "commander": "<=9.2.0",
100
100
  "cross-env": "^7.0.3",
101
101
  "dumi": "^1.0.9",
102
102
  "eslint": "7.10.0",