@pisell/materials 1.0.337 → 1.0.339
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.
- package/build/lowcode/assets/c052fb4b37973c8e0885712a7e26bb99.png +0 -0
- package/build/lowcode/assets-daily.json +11 -11
- package/build/lowcode/assets-dev.json +2 -2
- package/build/lowcode/assets-prod.json +11 -11
- package/build/lowcode/index.js +1 -1
- package/build/lowcode/meta.js +2 -2
- package/build/lowcode/preview.js +8 -8
- package/build/lowcode/render/default/view.css +1 -1
- package/build/lowcode/render/default/view.js +12 -12
- package/build/lowcode/view.css +1 -1
- package/build/lowcode/view.js +11 -11
- package/es/components/Pagination/index.d.ts +1 -1
- package/es/components/drag-sort-tree/TreeItem/index.d.ts +16 -0
- package/es/components/drag-sort-tree/TreeItem/index.js +192 -0
- package/es/components/drag-sort-tree/TreeItem/index.less +37 -0
- package/es/components/drag-sort-tree/index.d.ts +4 -0
- package/es/components/drag-sort-tree/index.js +82 -0
- package/es/components/drag-sort-tree/types.d.ts +19 -0
- package/es/components/drag-sort-tree/types.js +1 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +2 -1
- package/lib/components/Pagination/index.d.ts +1 -1
- package/lib/components/drag-sort-tree/TreeItem/index.d.ts +16 -0
- package/lib/components/drag-sort-tree/TreeItem/index.js +179 -0
- package/lib/components/drag-sort-tree/TreeItem/index.less +37 -0
- package/lib/components/drag-sort-tree/index.d.ts +4 -0
- package/lib/components/drag-sort-tree/index.js +111 -0
- package/lib/components/drag-sort-tree/types.d.ts +19 -0
- package/lib/components/drag-sort-tree/types.js +17 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -0
- package/lowcode/drag-sort-tree/__screenshots__/drag-sort-tree.png +0 -0
- package/lowcode/drag-sort-tree/meta.ts +103 -0
- package/lowcode/drag-sort-tree/snippets.ts +57 -0
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ export declare const paginationConfig: {
|
|
|
5
5
|
className: string;
|
|
6
6
|
defaultCurrent: number;
|
|
7
7
|
showTotal: (total: number, range: [number, number]) => string;
|
|
8
|
-
itemRender: (page: number, type: "
|
|
8
|
+
itemRender: (page: number, type: "next" | "page" | "prev" | "jump-prev" | "jump-next", element: React.ReactNode) => React.ReactNode;
|
|
9
9
|
responsive: boolean;
|
|
10
10
|
size: string;
|
|
11
11
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './index.less';
|
|
3
|
+
import { ValueProps, SortType } from '../types';
|
|
4
|
+
declare type TreeItemProps = {
|
|
5
|
+
id: string | number;
|
|
6
|
+
key: string | number;
|
|
7
|
+
item: ValueProps | any;
|
|
8
|
+
depth: number;
|
|
9
|
+
lists: any[];
|
|
10
|
+
activeId?: string | null;
|
|
11
|
+
childrenProps?: SortType;
|
|
12
|
+
sensors?: any;
|
|
13
|
+
onChange?: (value: any[]) => void;
|
|
14
|
+
};
|
|
15
|
+
declare const TreeItem: (props: TreeItemProps) => React.JSX.Element;
|
|
16
|
+
export default TreeItem;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
11
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
13
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
16
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
17
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
19
|
+
import { useSortable } from '@dnd-kit/sortable';
|
|
20
|
+
import { DndContext } from '@dnd-kit/core';
|
|
21
|
+
import { CSS } from '@dnd-kit/utilities';
|
|
22
|
+
import { HolderOutlined, EyeOutlined, EyeInvisibleOutlined, WarningOutlined } from '@ant-design/icons';
|
|
23
|
+
import { SortableContext, verticalListSortingStrategy, arrayMove } from '@dnd-kit/sortable';
|
|
24
|
+
import { restrictToVerticalAxis, restrictToParentElement } from '@dnd-kit/modifiers';
|
|
25
|
+
import classNames from 'classnames';
|
|
26
|
+
import "./index.less";
|
|
27
|
+
var prefix = 'pisell-lowcode';
|
|
28
|
+
var TreeItem = function TreeItem(props) {
|
|
29
|
+
var id = props.id,
|
|
30
|
+
item = props.item,
|
|
31
|
+
depth = props.depth,
|
|
32
|
+
activeId = props.activeId,
|
|
33
|
+
sensors = props.sensors,
|
|
34
|
+
childrenProps = props.childrenProps,
|
|
35
|
+
lists = props.lists,
|
|
36
|
+
onChange = props.onChange;
|
|
37
|
+
var _useState = useState([]),
|
|
38
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
39
|
+
expandedKeys = _useState2[0],
|
|
40
|
+
setExpandedKeys = _useState2[1];
|
|
41
|
+
var _useSortable = useSortable({
|
|
42
|
+
id: id
|
|
43
|
+
}),
|
|
44
|
+
attributes = _useSortable.attributes,
|
|
45
|
+
listeners = _useSortable.listeners,
|
|
46
|
+
setNodeRef = _useSortable.setNodeRef,
|
|
47
|
+
transform = _useSortable.transform,
|
|
48
|
+
transition = _useSortable.transition;
|
|
49
|
+
useEffect(function () {
|
|
50
|
+
// 拖拽的时候将节点收起
|
|
51
|
+
if (activeId) {
|
|
52
|
+
setExpandedKeys([]);
|
|
53
|
+
}
|
|
54
|
+
}, [activeId]);
|
|
55
|
+
var style = {
|
|
56
|
+
transform: CSS.Transform.toString(transform),
|
|
57
|
+
transition: transition
|
|
58
|
+
};
|
|
59
|
+
var rowKey = useMemo(function () {
|
|
60
|
+
return (childrenProps === null || childrenProps === void 0 ? void 0 : childrenProps.rowKey) || 'id';
|
|
61
|
+
}, [childrenProps === null || childrenProps === void 0 ? void 0 : childrenProps.rowKey]);
|
|
62
|
+
var handleDragEnd = function handleDragEnd(event) {
|
|
63
|
+
var active = event.active,
|
|
64
|
+
over = event.over;
|
|
65
|
+
if (!over || !active || !lists.length) return;
|
|
66
|
+
try {
|
|
67
|
+
var _active$rowKey, _over$rowKey;
|
|
68
|
+
var _active$rowKey$split = (_active$rowKey = active[rowKey]) === null || _active$rowKey === void 0 ? void 0 : _active$rowKey.split('-'),
|
|
69
|
+
_active$rowKey$split2 = _slicedToArray(_active$rowKey$split, 2),
|
|
70
|
+
activeParentId = _active$rowKey$split2[0],
|
|
71
|
+
_activeId = _active$rowKey$split2[1];
|
|
72
|
+
var _over$rowKey$split = (_over$rowKey = over[rowKey]) === null || _over$rowKey === void 0 ? void 0 : _over$rowKey.split('-'),
|
|
73
|
+
_over$rowKey$split2 = _slicedToArray(_over$rowKey$split, 2),
|
|
74
|
+
overParentId = _over$rowKey$split2[0],
|
|
75
|
+
overId = _over$rowKey$split2[1];
|
|
76
|
+
var parentIndex = lists.findIndex(function (item) {
|
|
77
|
+
return item[rowKey] == activeParentId;
|
|
78
|
+
});
|
|
79
|
+
if (_activeId !== overId && activeParentId === overParentId && parentIndex !== -1) {
|
|
80
|
+
var activeIndex = item.children.findIndex(function (item) {
|
|
81
|
+
return item[rowKey] == _activeId;
|
|
82
|
+
});
|
|
83
|
+
var overIndex = item.children.findIndex(function (item) {
|
|
84
|
+
return item[rowKey] == overId;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// 移动数据
|
|
88
|
+
if (activeIndex !== -1 && overIndex !== -1) {
|
|
89
|
+
var _lists$parentIndex;
|
|
90
|
+
var newChildren = arrayMove((_lists$parentIndex = lists[parentIndex]) === null || _lists$parentIndex === void 0 ? void 0 : _lists$parentIndex.children, activeIndex, overIndex);
|
|
91
|
+
var _lists = [].concat(_toConsumableArray(lists.slice(0, parentIndex)), [_objectSpread(_objectSpread({}, lists === null || lists === void 0 ? void 0 : lists[parentIndex]), {}, {
|
|
92
|
+
children: newChildren
|
|
93
|
+
})], _toConsumableArray(lists.slice(parentIndex + 1)));
|
|
94
|
+
onChange && onChange(_toConsumableArray(_lists));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} catch (error) {}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @title: 点击切换眼睛
|
|
102
|
+
* @description:
|
|
103
|
+
* @param {any} e
|
|
104
|
+
* @return {*}
|
|
105
|
+
* @Author: WangHan
|
|
106
|
+
* @Date: 2024-07-19 22:43
|
|
107
|
+
*/
|
|
108
|
+
var handleShow = function handleShow(e) {
|
|
109
|
+
e.stopPropagation(); // 阻止事件冒泡
|
|
110
|
+
e.preventDefault(); // 阻止默认行为
|
|
111
|
+
var index = lists === null || lists === void 0 ? void 0 : lists.findIndex(function (node) {
|
|
112
|
+
return node[rowKey] === item[rowKey];
|
|
113
|
+
});
|
|
114
|
+
if (index !== -1) {
|
|
115
|
+
lists[index].show = !lists[index].show;
|
|
116
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(_toConsumableArray(lists));
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
var onSelect = function onSelect() {
|
|
120
|
+
var _item$children;
|
|
121
|
+
if (depth === 0 && (_item$children = item.children) !== null && _item$children !== void 0 && _item$children.length) {
|
|
122
|
+
var key = item[rowKey];
|
|
123
|
+
if (expandedKeys.includes(key)) {
|
|
124
|
+
var _ids = expandedKeys.filter(function (id) {
|
|
125
|
+
return id !== key;
|
|
126
|
+
});
|
|
127
|
+
setExpandedKeys(_ids);
|
|
128
|
+
} else {
|
|
129
|
+
setExpandedKeys([].concat(_toConsumableArray(expandedKeys), [key]));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
var renderChildren = useMemo(function () {
|
|
134
|
+
var _item$children2;
|
|
135
|
+
return (item === null || item === void 0 ? void 0 : (_item$children2 = item.children) === null || _item$children2 === void 0 ? void 0 : _item$children2.length) > 0 && (expandedKeys === null || expandedKeys === void 0 ? void 0 : expandedKeys.includes(item[rowKey])) && /*#__PURE__*/React.createElement(SortableContext, {
|
|
136
|
+
items: item.children.map(function (child) {
|
|
137
|
+
return "".concat(item[rowKey], "-").concat(child[rowKey]);
|
|
138
|
+
}),
|
|
139
|
+
strategy: verticalListSortingStrategy
|
|
140
|
+
}, item.children.map(function (child) {
|
|
141
|
+
return /*#__PURE__*/React.createElement(TreeItem, {
|
|
142
|
+
id: "".concat(item[rowKey], "-").concat(child[rowKey]),
|
|
143
|
+
key: "".concat(item[rowKey], "-").concat(child[rowKey]),
|
|
144
|
+
item: child,
|
|
145
|
+
lists: lists,
|
|
146
|
+
depth: depth + 1,
|
|
147
|
+
childrenProps: childrenProps
|
|
148
|
+
});
|
|
149
|
+
}));
|
|
150
|
+
}, [item.children, expandedKeys, rowKey, lists]);
|
|
151
|
+
|
|
152
|
+
// 右侧图标
|
|
153
|
+
var rightIcon = useMemo(function () {
|
|
154
|
+
// 右侧子级图标
|
|
155
|
+
var hiddenRightIcon = childrenProps === null || childrenProps === void 0 ? void 0 : childrenProps.hiddenRightIcon;
|
|
156
|
+
return !hiddenRightIcon ? /*#__PURE__*/React.createElement("div", {
|
|
157
|
+
className: classNames("".concat(prefix, "-drag-sort-tree-icon")),
|
|
158
|
+
onClick: handleShow
|
|
159
|
+
}, item.show ? /*#__PURE__*/React.createElement(EyeOutlined, null) : /*#__PURE__*/React.createElement(EyeInvisibleOutlined, null)) : null;
|
|
160
|
+
}, [childrenProps === null || childrenProps === void 0 ? void 0 : childrenProps.hiddenRightIcon, item === null || item === void 0 ? void 0 : item.show, lists]);
|
|
161
|
+
|
|
162
|
+
// 警告图标
|
|
163
|
+
var warningIcon = useMemo(function () {
|
|
164
|
+
var hiddenWarningIcon = childrenProps === null || childrenProps === void 0 ? void 0 : childrenProps.hiddenWarningIcon;
|
|
165
|
+
return !hiddenWarningIcon && !(item !== null && item !== void 0 && item.is_available) ? /*#__PURE__*/React.createElement("div", {
|
|
166
|
+
className: classNames("".concat(prefix, "-drag-sort-tree-item-icon"))
|
|
167
|
+
}, /*#__PURE__*/React.createElement(WarningOutlined, {
|
|
168
|
+
style: {
|
|
169
|
+
color: 'red'
|
|
170
|
+
}
|
|
171
|
+
})) : null;
|
|
172
|
+
}, [childrenProps === null || childrenProps === void 0 ? void 0 : childrenProps.hiddenWarningIcon, item === null || item === void 0 ? void 0 : item.is_available]);
|
|
173
|
+
return /*#__PURE__*/React.createElement(DndContext, {
|
|
174
|
+
sensors: sensors,
|
|
175
|
+
modifiers: [restrictToVerticalAxis, restrictToParentElement],
|
|
176
|
+
onDragEnd: handleDragEnd
|
|
177
|
+
}, /*#__PURE__*/React.createElement("div", _extends({
|
|
178
|
+
ref: setNodeRef,
|
|
179
|
+
style: style
|
|
180
|
+
}, attributes, listeners), /*#__PURE__*/React.createElement("div", {
|
|
181
|
+
style: {
|
|
182
|
+
paddingLeft: "".concat(depth * 20, "px")
|
|
183
|
+
},
|
|
184
|
+
className: classNames("".concat(prefix, "-drag-sort-tree"), childrenProps === null || childrenProps === void 0 ? void 0 : childrenProps.className),
|
|
185
|
+
onClick: onSelect
|
|
186
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
187
|
+
className: classNames("".concat(prefix, "-drag-sort-tree-item"))
|
|
188
|
+
}, !(childrenProps !== null && childrenProps !== void 0 && childrenProps.hiddenDraggableIcon) ? /*#__PURE__*/React.createElement(HolderOutlined, null) : null, /*#__PURE__*/React.createElement("div", {
|
|
189
|
+
className: "".concat(prefix, "-drag-sort-tree-title")
|
|
190
|
+
}, (childrenProps === null || childrenProps === void 0 ? void 0 : childrenProps.titleRender) || (item === null || item === void 0 ? void 0 : item.title))), !depth ? rightIcon : warningIcon), renderChildren));
|
|
191
|
+
};
|
|
192
|
+
export default TreeItem;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
@pisell-prefix: pisell-lowcode;
|
|
2
|
+
|
|
3
|
+
.@{pisell-prefix} {
|
|
4
|
+
&-drag-sort-tree{
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
justify-content: space-between;
|
|
8
|
+
font-size: 16px;
|
|
9
|
+
padding: 6px;
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
touch-action: none !important;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
&-drag-sort-tree:hover {
|
|
15
|
+
background: rgb(237, 238, 238);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
&-drag-sort-tree-item {
|
|
19
|
+
display: flex;
|
|
20
|
+
align-items: center;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&-drag-sort-tree &-drag-sort-tree-title {
|
|
24
|
+
margin-left: 10px;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
&-drag-sort-tree-icon,
|
|
28
|
+
&-drag-sort-tree-item-icon {
|
|
29
|
+
height: 30px;
|
|
30
|
+
width: 30px;
|
|
31
|
+
display: flex;
|
|
32
|
+
align-items: center;
|
|
33
|
+
justify-content: center;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import React, { useState } from 'react';
|
|
8
|
+
import { DndContext, useSensor, useSensors, PointerSensor } from '@dnd-kit/core';
|
|
9
|
+
import { SortableContext, verticalListSortingStrategy, arrayMove } from '@dnd-kit/sortable';
|
|
10
|
+
import TreeItem from "./TreeItem";
|
|
11
|
+
import { restrictToVerticalAxis, restrictToParentElement } from '@dnd-kit/modifiers';
|
|
12
|
+
var DragSortTree = function DragSortTree(props) {
|
|
13
|
+
var value = props.value,
|
|
14
|
+
rowKey = props.rowKey,
|
|
15
|
+
onChange = props.onChange;
|
|
16
|
+
var _useState = useState(value || []),
|
|
17
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
18
|
+
items = _useState2[0],
|
|
19
|
+
setItems = _useState2[1];
|
|
20
|
+
var _useState3 = useState(null),
|
|
21
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
22
|
+
activeId = _useState4[0],
|
|
23
|
+
setActiveId = _useState4[1];
|
|
24
|
+
var sensors = useSensors(useSensor(PointerSensor, {
|
|
25
|
+
activationConstraint: {
|
|
26
|
+
distance: 5
|
|
27
|
+
}
|
|
28
|
+
}));
|
|
29
|
+
var handleDragStart = function handleDragStart(event) {
|
|
30
|
+
var active = event.active;
|
|
31
|
+
setActiveId(active[rowKey]);
|
|
32
|
+
};
|
|
33
|
+
var handleDragEnd = function handleDragEnd(event) {
|
|
34
|
+
var active = event.active,
|
|
35
|
+
over = event.over;
|
|
36
|
+
// 拖拽结束将这个值设置为空,防止第二次拖拽同一个节点,监听不到这个变化
|
|
37
|
+
setActiveId(null);
|
|
38
|
+
if (!over || !active) return;
|
|
39
|
+
try {
|
|
40
|
+
var _activeId = active[rowKey];
|
|
41
|
+
var overId = over[rowKey];
|
|
42
|
+
if (_activeId !== overId) {
|
|
43
|
+
var activeIndex = items.findIndex(function (item) {
|
|
44
|
+
return item[rowKey] === _activeId;
|
|
45
|
+
});
|
|
46
|
+
var overIndex = items.findIndex(function (item) {
|
|
47
|
+
return item[rowKey] === overId;
|
|
48
|
+
});
|
|
49
|
+
var _lists = arrayMove(items, activeIndex, overIndex);
|
|
50
|
+
handleChange(_lists);
|
|
51
|
+
}
|
|
52
|
+
} catch (error) {}
|
|
53
|
+
};
|
|
54
|
+
var handleChange = function handleChange(value) {
|
|
55
|
+
setItems(value);
|
|
56
|
+
onChange && onChange(value);
|
|
57
|
+
};
|
|
58
|
+
return /*#__PURE__*/React.createElement(DndContext, {
|
|
59
|
+
sensors: sensors,
|
|
60
|
+
onDragEnd: handleDragEnd,
|
|
61
|
+
onDragStart: handleDragStart,
|
|
62
|
+
modifiers: [restrictToVerticalAxis, restrictToParentElement]
|
|
63
|
+
}, /*#__PURE__*/React.createElement(SortableContext, {
|
|
64
|
+
items: items.map(function (item) {
|
|
65
|
+
return item[rowKey];
|
|
66
|
+
}),
|
|
67
|
+
strategy: verticalListSortingStrategy
|
|
68
|
+
}, items.map(function (item) {
|
|
69
|
+
return /*#__PURE__*/React.createElement(TreeItem, {
|
|
70
|
+
key: item[rowKey],
|
|
71
|
+
id: item[rowKey],
|
|
72
|
+
item: item,
|
|
73
|
+
depth: 0,
|
|
74
|
+
sensors: sensors,
|
|
75
|
+
activeId: activeId,
|
|
76
|
+
childrenProps: props,
|
|
77
|
+
lists: items,
|
|
78
|
+
onChange: handleChange
|
|
79
|
+
});
|
|
80
|
+
})));
|
|
81
|
+
};
|
|
82
|
+
export default DragSortTree;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare type ValueProps = {
|
|
3
|
+
id: number | string;
|
|
4
|
+
title: string;
|
|
5
|
+
show?: boolean;
|
|
6
|
+
is_available?: boolean;
|
|
7
|
+
type_id?: number;
|
|
8
|
+
children?: ValueProps[];
|
|
9
|
+
};
|
|
10
|
+
export declare type SortType = {
|
|
11
|
+
value: ValueProps[];
|
|
12
|
+
rowKey: string;
|
|
13
|
+
className?: string | Function;
|
|
14
|
+
titleRender?: string | React.ReactElement;
|
|
15
|
+
hiddenDraggableIcon?: boolean;
|
|
16
|
+
hiddenRightIcon?: boolean;
|
|
17
|
+
hiddenWarningIcon?: boolean;
|
|
18
|
+
onChange?: (value: ValueProps[]) => void;
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/es/index.d.ts
CHANGED
|
@@ -79,3 +79,4 @@ export { default as VirtualKeyboardTime } from './components/virtual-keyboard/Ti
|
|
|
79
79
|
export { default as SelectTime } from './components/select-time';
|
|
80
80
|
export { default as AutoCompleteNumber } from './components/auto-complete-number';
|
|
81
81
|
export { default as BatchEditor } from './components/batch-editor';
|
|
82
|
+
export { default as DragSortTree } from './components/drag-sort-tree';
|
package/es/index.js
CHANGED
|
@@ -98,4 +98,5 @@ export { default as VirtualKeyboard } from "./components/virtual-keyboard";
|
|
|
98
98
|
export { default as VirtualKeyboardTime } from "./components/virtual-keyboard/Time";
|
|
99
99
|
export { default as SelectTime } from "./components/select-time";
|
|
100
100
|
export { default as AutoCompleteNumber } from "./components/auto-complete-number";
|
|
101
|
-
export { default as BatchEditor } from "./components/batch-editor";
|
|
101
|
+
export { default as BatchEditor } from "./components/batch-editor";
|
|
102
|
+
export { default as DragSortTree } from "./components/drag-sort-tree";
|
|
@@ -5,7 +5,7 @@ export declare const paginationConfig: {
|
|
|
5
5
|
className: string;
|
|
6
6
|
defaultCurrent: number;
|
|
7
7
|
showTotal: (total: number, range: [number, number]) => string;
|
|
8
|
-
itemRender: (page: number, type: "
|
|
8
|
+
itemRender: (page: number, type: "next" | "page" | "prev" | "jump-prev" | "jump-next", element: React.ReactNode) => React.ReactNode;
|
|
9
9
|
responsive: boolean;
|
|
10
10
|
size: string;
|
|
11
11
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './index.less';
|
|
3
|
+
import { ValueProps, SortType } from '../types';
|
|
4
|
+
declare type TreeItemProps = {
|
|
5
|
+
id: string | number;
|
|
6
|
+
key: string | number;
|
|
7
|
+
item: ValueProps | any;
|
|
8
|
+
depth: number;
|
|
9
|
+
lists: any[];
|
|
10
|
+
activeId?: string | null;
|
|
11
|
+
childrenProps?: SortType;
|
|
12
|
+
sensors?: any;
|
|
13
|
+
onChange?: (value: any[]) => void;
|
|
14
|
+
};
|
|
15
|
+
declare const TreeItem: (props: TreeItemProps) => React.JSX.Element;
|
|
16
|
+
export default TreeItem;
|
|
@@ -0,0 +1,179 @@
|
|
|
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/components/drag-sort-tree/TreeItem/index.tsx
|
|
30
|
+
var TreeItem_exports = {};
|
|
31
|
+
__export(TreeItem_exports, {
|
|
32
|
+
default: () => TreeItem_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(TreeItem_exports);
|
|
35
|
+
var import_react = __toESM(require("react"));
|
|
36
|
+
var import_sortable = require("@dnd-kit/sortable");
|
|
37
|
+
var import_core = require("@dnd-kit/core");
|
|
38
|
+
var import_utilities = require("@dnd-kit/utilities");
|
|
39
|
+
var import_icons = require("@ant-design/icons");
|
|
40
|
+
var import_sortable2 = require("@dnd-kit/sortable");
|
|
41
|
+
var import_modifiers = require("@dnd-kit/modifiers");
|
|
42
|
+
var import_classnames = __toESM(require("classnames"));
|
|
43
|
+
var import_index = require("./index.less");
|
|
44
|
+
var prefix = "pisell-lowcode";
|
|
45
|
+
var TreeItem = (props) => {
|
|
46
|
+
const { id, item, depth, activeId, sensors, childrenProps, lists, onChange } = props;
|
|
47
|
+
const [expandedKeys, setExpandedKeys] = (0, import_react.useState)([]);
|
|
48
|
+
const { attributes, listeners, setNodeRef, transform, transition } = (0, import_sortable.useSortable)({ id });
|
|
49
|
+
(0, import_react.useEffect)(() => {
|
|
50
|
+
if (activeId) {
|
|
51
|
+
setExpandedKeys([]);
|
|
52
|
+
}
|
|
53
|
+
}, [activeId]);
|
|
54
|
+
const style = {
|
|
55
|
+
transform: import_utilities.CSS.Transform.toString(transform),
|
|
56
|
+
transition
|
|
57
|
+
};
|
|
58
|
+
const rowKey = (0, import_react.useMemo)(() => {
|
|
59
|
+
return (childrenProps == null ? void 0 : childrenProps.rowKey) || "id";
|
|
60
|
+
}, [childrenProps == null ? void 0 : childrenProps.rowKey]);
|
|
61
|
+
const handleDragEnd = (event) => {
|
|
62
|
+
var _a, _b, _c;
|
|
63
|
+
const { active, over } = event;
|
|
64
|
+
if (!over || !active || !lists.length)
|
|
65
|
+
return;
|
|
66
|
+
try {
|
|
67
|
+
let [activeParentId, activeId2] = (_a = active[rowKey]) == null ? void 0 : _a.split("-");
|
|
68
|
+
let [overParentId, overId] = (_b = over[rowKey]) == null ? void 0 : _b.split("-");
|
|
69
|
+
const parentIndex = lists.findIndex(
|
|
70
|
+
(item2) => item2[rowKey] == activeParentId
|
|
71
|
+
);
|
|
72
|
+
if (activeId2 !== overId && activeParentId === overParentId && parentIndex !== -1) {
|
|
73
|
+
const activeIndex = item.children.findIndex(
|
|
74
|
+
(item2) => item2[rowKey] == activeId2
|
|
75
|
+
);
|
|
76
|
+
const overIndex = item.children.findIndex(
|
|
77
|
+
(item2) => item2[rowKey] == overId
|
|
78
|
+
);
|
|
79
|
+
if (activeIndex !== -1 && overIndex !== -1) {
|
|
80
|
+
const newChildren = (0, import_sortable2.arrayMove)(
|
|
81
|
+
(_c = lists[parentIndex]) == null ? void 0 : _c.children,
|
|
82
|
+
activeIndex,
|
|
83
|
+
overIndex
|
|
84
|
+
);
|
|
85
|
+
const _lists = [
|
|
86
|
+
...lists.slice(0, parentIndex),
|
|
87
|
+
{ ...lists == null ? void 0 : lists[parentIndex], children: newChildren },
|
|
88
|
+
...lists.slice(parentIndex + 1)
|
|
89
|
+
];
|
|
90
|
+
onChange && onChange([..._lists]);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
} catch (error) {
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
const handleShow = (e) => {
|
|
97
|
+
e.stopPropagation();
|
|
98
|
+
e.preventDefault();
|
|
99
|
+
const index = lists == null ? void 0 : lists.findIndex(
|
|
100
|
+
(node) => node[rowKey] === item[rowKey]
|
|
101
|
+
);
|
|
102
|
+
if (index !== -1) {
|
|
103
|
+
lists[index].show = !lists[index].show;
|
|
104
|
+
onChange == null ? void 0 : onChange([...lists]);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const onSelect = () => {
|
|
108
|
+
var _a;
|
|
109
|
+
if (depth === 0 && ((_a = item.children) == null ? void 0 : _a.length)) {
|
|
110
|
+
const key = item[rowKey];
|
|
111
|
+
if (expandedKeys.includes(key)) {
|
|
112
|
+
const _ids = expandedKeys.filter((id2) => id2 !== key);
|
|
113
|
+
setExpandedKeys(_ids);
|
|
114
|
+
} else {
|
|
115
|
+
setExpandedKeys([...expandedKeys, key]);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const renderChildren = (0, import_react.useMemo)(() => {
|
|
120
|
+
var _a;
|
|
121
|
+
return ((_a = item == null ? void 0 : item.children) == null ? void 0 : _a.length) > 0 && (expandedKeys == null ? void 0 : expandedKeys.includes(item[rowKey])) && /* @__PURE__ */ import_react.default.createElement(
|
|
122
|
+
import_sortable2.SortableContext,
|
|
123
|
+
{
|
|
124
|
+
items: item.children.map(
|
|
125
|
+
(child) => `${item[rowKey]}-${child[rowKey]}`
|
|
126
|
+
),
|
|
127
|
+
strategy: import_sortable2.verticalListSortingStrategy
|
|
128
|
+
},
|
|
129
|
+
item.children.map((child) => /* @__PURE__ */ import_react.default.createElement(
|
|
130
|
+
TreeItem,
|
|
131
|
+
{
|
|
132
|
+
id: `${item[rowKey]}-${child[rowKey]}`,
|
|
133
|
+
key: `${item[rowKey]}-${child[rowKey]}`,
|
|
134
|
+
item: child,
|
|
135
|
+
lists,
|
|
136
|
+
depth: depth + 1,
|
|
137
|
+
childrenProps
|
|
138
|
+
}
|
|
139
|
+
))
|
|
140
|
+
);
|
|
141
|
+
}, [item.children, expandedKeys, rowKey, lists]);
|
|
142
|
+
const rightIcon = (0, import_react.useMemo)(() => {
|
|
143
|
+
const hiddenRightIcon = childrenProps == null ? void 0 : childrenProps.hiddenRightIcon;
|
|
144
|
+
return !hiddenRightIcon ? /* @__PURE__ */ import_react.default.createElement(
|
|
145
|
+
"div",
|
|
146
|
+
{
|
|
147
|
+
className: (0, import_classnames.default)(`${prefix}-drag-sort-tree-icon`),
|
|
148
|
+
onClick: handleShow
|
|
149
|
+
},
|
|
150
|
+
item.show ? /* @__PURE__ */ import_react.default.createElement(import_icons.EyeOutlined, null) : /* @__PURE__ */ import_react.default.createElement(import_icons.EyeInvisibleOutlined, null)
|
|
151
|
+
) : null;
|
|
152
|
+
}, [childrenProps == null ? void 0 : childrenProps.hiddenRightIcon, item == null ? void 0 : item.show, lists]);
|
|
153
|
+
const warningIcon = (0, import_react.useMemo)(() => {
|
|
154
|
+
const hiddenWarningIcon = childrenProps == null ? void 0 : childrenProps.hiddenWarningIcon;
|
|
155
|
+
return !hiddenWarningIcon && !(item == null ? void 0 : item.is_available) ? /* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)(`${prefix}-drag-sort-tree-item-icon`) }, /* @__PURE__ */ import_react.default.createElement(import_icons.WarningOutlined, { style: { color: "red" } })) : null;
|
|
156
|
+
}, [childrenProps == null ? void 0 : childrenProps.hiddenWarningIcon, item == null ? void 0 : item.is_available]);
|
|
157
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
158
|
+
import_core.DndContext,
|
|
159
|
+
{
|
|
160
|
+
sensors,
|
|
161
|
+
modifiers: [import_modifiers.restrictToVerticalAxis, import_modifiers.restrictToParentElement],
|
|
162
|
+
onDragEnd: handleDragEnd
|
|
163
|
+
},
|
|
164
|
+
/* @__PURE__ */ import_react.default.createElement("div", { ref: setNodeRef, style, ...attributes, ...listeners }, /* @__PURE__ */ import_react.default.createElement(
|
|
165
|
+
"div",
|
|
166
|
+
{
|
|
167
|
+
style: { paddingLeft: `${depth * 20}px` },
|
|
168
|
+
className: (0, import_classnames.default)(
|
|
169
|
+
`${prefix}-drag-sort-tree`,
|
|
170
|
+
childrenProps == null ? void 0 : childrenProps.className
|
|
171
|
+
),
|
|
172
|
+
onClick: onSelect
|
|
173
|
+
},
|
|
174
|
+
/* @__PURE__ */ import_react.default.createElement("div", { className: (0, import_classnames.default)(`${prefix}-drag-sort-tree-item`) }, !(childrenProps == null ? void 0 : childrenProps.hiddenDraggableIcon) ? /* @__PURE__ */ import_react.default.createElement(import_icons.HolderOutlined, null) : null, /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefix}-drag-sort-tree-title` }, (childrenProps == null ? void 0 : childrenProps.titleRender) || (item == null ? void 0 : item.title))),
|
|
175
|
+
!depth ? rightIcon : warningIcon
|
|
176
|
+
), renderChildren)
|
|
177
|
+
);
|
|
178
|
+
};
|
|
179
|
+
var TreeItem_default = TreeItem;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
@pisell-prefix: pisell-lowcode;
|
|
2
|
+
|
|
3
|
+
.@{pisell-prefix} {
|
|
4
|
+
&-drag-sort-tree{
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
justify-content: space-between;
|
|
8
|
+
font-size: 16px;
|
|
9
|
+
padding: 6px;
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
touch-action: none !important;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
&-drag-sort-tree:hover {
|
|
15
|
+
background: rgb(237, 238, 238);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
&-drag-sort-tree-item {
|
|
19
|
+
display: flex;
|
|
20
|
+
align-items: center;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&-drag-sort-tree &-drag-sort-tree-title {
|
|
24
|
+
margin-left: 10px;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
&-drag-sort-tree-icon,
|
|
28
|
+
&-drag-sort-tree-item-icon {
|
|
29
|
+
height: 30px;
|
|
30
|
+
width: 30px;
|
|
31
|
+
display: flex;
|
|
32
|
+
align-items: center;
|
|
33
|
+
justify-content: center;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|