@pisell/materials 1.0.624 → 1.0.625
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-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 +1 -1
- package/build/lowcode/preview.js +7 -7
- package/build/lowcode/render/default/view.js +8 -8
- package/build/lowcode/view.js +8 -8
- package/es/components/pisellDraggable/components/TreeItem/TreeItem.d.ts +2 -0
- package/es/components/pisellDraggable/components/TreeItem/TreeItem.js +2 -1
- package/es/components/pisellDraggable/index.d.ts +4 -2
- package/es/components/pisellDraggable/index.js +90 -10
- package/es/components/pisellDraggable/types.d.ts +1 -0
- package/es/components/pisellNavigationMenu/PisellNavigationMenu.js +9 -17
- package/es/components/pisellNavigationMenu/utils.d.ts +15 -0
- package/es/components/pisellNavigationMenu/utils.js +29 -0
- package/lib/components/pisellDraggable/components/TreeItem/TreeItem.d.ts +2 -0
- package/lib/components/pisellDraggable/components/TreeItem/TreeItem.js +2 -6
- package/lib/components/pisellDraggable/index.d.ts +4 -2
- package/lib/components/pisellDraggable/index.js +60 -8
- package/lib/components/pisellDraggable/types.d.ts +1 -0
- package/lib/components/pisellNavigationMenu/PisellNavigationMenu.js +8 -11
- package/lib/components/pisellNavigationMenu/utils.d.ts +15 -0
- package/lib/components/pisellNavigationMenu/utils.js +44 -0
- package/package.json +1 -1
|
@@ -18,5 +18,7 @@ export interface Props extends Omit<HTMLAttributes<HTMLLIElement>, 'id'> {
|
|
|
18
18
|
item: TreeItemType;
|
|
19
19
|
renderItem?(item: Props, ref: React.ForwardedRef<HTMLDivElement>): React.ReactNode;
|
|
20
20
|
__designMode?: string;
|
|
21
|
+
renderItem?(item: TreeItemType): React.ReactNode;
|
|
22
|
+
isBlocked?: boolean;
|
|
21
23
|
}
|
|
22
24
|
export declare const TreeItem: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
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
|
-
var _excluded = ["childCount", "clone", "depth", "disableSelection", "disableInteraction", "ghost", "handleProps", "indentationWidth", "indicator", "collapsed", "onCollapse", "onRemove", "style", "wrapperRef", "item", "renderItem", "__designMode"];
|
|
2
|
+
var _excluded = ["childCount", "clone", "depth", "disableSelection", "disableInteraction", "ghost", "handleProps", "indentationWidth", "indicator", "collapsed", "onCollapse", "onRemove", "style", "wrapperRef", "item", "renderItem", "__designMode", "isBlocked"];
|
|
3
3
|
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); }
|
|
4
4
|
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; }
|
|
5
5
|
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; }
|
|
@@ -30,6 +30,7 @@ export var TreeItem = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
30
30
|
item = props.item,
|
|
31
31
|
renderItem = props.renderItem,
|
|
32
32
|
__designMode = props.__designMode,
|
|
33
|
+
isBlocked = props.isBlocked,
|
|
33
34
|
otherProps = _objectWithoutProperties(props, _excluded);
|
|
34
35
|
if (renderItem) {
|
|
35
36
|
return renderItem(props, ref);
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* 基于@dnd-kit库实现,支持拖拽排序、展开折叠、删除等功能
|
|
4
4
|
*/
|
|
5
5
|
import React from 'react';
|
|
6
|
-
import type { TreeItem, TreeItems } from './types';
|
|
7
6
|
import type { Props as TreeItemProps } from './components/TreeItem/TreeItem';
|
|
7
|
+
import type { TreeItem, TreeItems } from './types';
|
|
8
8
|
interface Props {
|
|
9
9
|
/** 是否支持折叠功能 */
|
|
10
10
|
collapsible?: boolean;
|
|
@@ -24,7 +24,9 @@ interface Props {
|
|
|
24
24
|
onRemoveBefore?: (item: TreeItem) => Promise<boolean>;
|
|
25
25
|
/** 设计模式 */
|
|
26
26
|
__designMode?: string;
|
|
27
|
+
/** 最大层级 */
|
|
28
|
+
maxLevel?: number;
|
|
27
29
|
}
|
|
28
|
-
export declare function SortableTree({ collapsible, value, indicator, indentationWidth, removable, renderItem, onChange, onRemoveBefore, __designMode, }: Props): React.JSX.Element;
|
|
30
|
+
export declare function SortableTree({ collapsible, value, indicator, indentationWidth, removable, renderItem, onChange, onRemoveBefore, __designMode, maxLevel, }: Props): React.JSX.Element;
|
|
29
31
|
declare const Demo: (props: Props) => React.JSX.Element;
|
|
30
32
|
export default Demo;
|
|
@@ -50,7 +50,8 @@ var initialItems = [{
|
|
|
50
50
|
children: []
|
|
51
51
|
}, {
|
|
52
52
|
id: 'Winter',
|
|
53
|
-
children: []
|
|
53
|
+
children: [],
|
|
54
|
+
disabledDrop: true
|
|
54
55
|
}]
|
|
55
56
|
}, {
|
|
56
57
|
id: 'About Us',
|
|
@@ -121,7 +122,9 @@ export function SortableTree(_ref3) {
|
|
|
121
122
|
renderItem = _ref3.renderItem,
|
|
122
123
|
onChange = _ref3.onChange,
|
|
123
124
|
onRemoveBefore = _ref3.onRemoveBefore,
|
|
124
|
-
__designMode = _ref3.__designMode
|
|
125
|
+
__designMode = _ref3.__designMode,
|
|
126
|
+
_ref3$maxLevel = _ref3.maxLevel,
|
|
127
|
+
maxLevel = _ref3$maxLevel === void 0 ? 3 : _ref3$maxLevel;
|
|
125
128
|
// 状态管理
|
|
126
129
|
/** 当前树形数据 */
|
|
127
130
|
var _useState = useState([]),
|
|
@@ -147,6 +150,9 @@ export function SortableTree(_ref3) {
|
|
|
147
150
|
console.log('初始化', value);
|
|
148
151
|
setItems(value);
|
|
149
152
|
}, [value]);
|
|
153
|
+
var flattenTreeData = useMemo(function () {
|
|
154
|
+
return flattenTree(items);
|
|
155
|
+
}, [items]);
|
|
150
156
|
|
|
151
157
|
/**
|
|
152
158
|
* 扁平化处理树形数据
|
|
@@ -155,17 +161,16 @@ export function SortableTree(_ref3) {
|
|
|
155
161
|
* 3. 移除被折叠节点的子节点
|
|
156
162
|
*/
|
|
157
163
|
var flattenedItems = useMemo(function () {
|
|
158
|
-
var
|
|
159
|
-
var collapsedItems = flattenedTree.reduce(function (acc, _ref4) {
|
|
164
|
+
var collapsedItems = flattenTreeData.reduce(function (acc, _ref4) {
|
|
160
165
|
var _ref4$children = _ref4.children,
|
|
161
166
|
children = _ref4$children === void 0 ? [] : _ref4$children,
|
|
162
167
|
collapsed = _ref4.collapsed,
|
|
163
168
|
id = _ref4.id;
|
|
164
|
-
return collapsed && children
|
|
169
|
+
return collapsed && children.length ? [].concat(_toConsumableArray(acc), [id]) : acc;
|
|
165
170
|
}, []);
|
|
166
|
-
return removeChildrenOf(
|
|
167
|
-
}, [activeId,
|
|
168
|
-
|
|
171
|
+
return removeChildrenOf(flattenTreeData, activeId != null ? [activeId].concat(_toConsumableArray(collapsedItems)) : collapsedItems);
|
|
172
|
+
}, [activeId, flattenTreeData]);
|
|
173
|
+
console.log('flattenedItems', flattenedItems);
|
|
169
174
|
/**
|
|
170
175
|
* 计算拖拽投影
|
|
171
176
|
* 根据当前拖拽状态计算目标位置和深度
|
|
@@ -200,6 +205,39 @@ export function SortableTree(_ref3) {
|
|
|
200
205
|
useEffect(function () {
|
|
201
206
|
document.body.id = 'body';
|
|
202
207
|
}, []);
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* 检查子树是否超过最大深度限制
|
|
211
|
+
* @param items 当前项目列表
|
|
212
|
+
* @param itemId 要检查的项目ID
|
|
213
|
+
* @param baseDepth 基础深度
|
|
214
|
+
* @returns 是否超过限制
|
|
215
|
+
*/
|
|
216
|
+
function checkSubtreeDepth(items, itemId, baseDepth) {
|
|
217
|
+
var item = items.find(function (i) {
|
|
218
|
+
return i.id === itemId;
|
|
219
|
+
});
|
|
220
|
+
if (!item) return false;
|
|
221
|
+
|
|
222
|
+
// 首先检查目标位置的深度
|
|
223
|
+
if (baseDepth >= maxLevel) return true;
|
|
224
|
+
|
|
225
|
+
// 获取所有子节点
|
|
226
|
+
var children = items.filter(function (i) {
|
|
227
|
+
return i.parentId === itemId;
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// 如果当前节点已经是最大深度,且尝试添加子节点,则返回 true
|
|
231
|
+
if (baseDepth >= maxLevel - 1 && children.length > 0) return true;
|
|
232
|
+
|
|
233
|
+
// 递归检查所有子节点
|
|
234
|
+
return children.some(function (child) {
|
|
235
|
+
// 计算子节点在新位置的深度
|
|
236
|
+
var childNewDepth = baseDepth + 1;
|
|
237
|
+
// 如果子节点深度超过限制,或者子节点的子树超过限制,则返回 true
|
|
238
|
+
return childNewDepth >= maxLevel || checkSubtreeDepth(items, child.id, childNewDepth);
|
|
239
|
+
});
|
|
240
|
+
}
|
|
203
241
|
return /*#__PURE__*/React.createElement(DndContext, {
|
|
204
242
|
sensors: sensors,
|
|
205
243
|
collisionDetection: closestCenter,
|
|
@@ -267,9 +305,32 @@ export function SortableTree(_ref3) {
|
|
|
267
305
|
setOffsetLeft(delta.x);
|
|
268
306
|
}
|
|
269
307
|
function handleDragOver(_ref9) {
|
|
270
|
-
var _over$id;
|
|
271
308
|
var over = _ref9.over;
|
|
272
|
-
|
|
309
|
+
if (!projected || !over) {
|
|
310
|
+
var _over$id;
|
|
311
|
+
setOverId((_over$id = over === null || over === void 0 ? void 0 : over.id) !== null && _over$id !== void 0 ? _over$id : null);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// 检查目标父节点是否禁止拖入
|
|
316
|
+
var targetParent = projected.parentId ? flattenedItems.find(function (item) {
|
|
317
|
+
return item.id === projected.parentId;
|
|
318
|
+
}) : null;
|
|
319
|
+
if (targetParent !== null && targetParent !== void 0 && targetParent.disabledDrop) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// 检查目标深度是否超过最大层级限制
|
|
324
|
+
if (projected.depth >= maxLevel) {
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// 检查整个子树的深度是否会超过限制
|
|
329
|
+
var willExceedLimit = checkSubtreeDepth(flattenTreeData, activeId, projected.depth);
|
|
330
|
+
if (willExceedLimit) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
setOverId(over.id);
|
|
273
334
|
}
|
|
274
335
|
|
|
275
336
|
/**
|
|
@@ -285,6 +346,25 @@ export function SortableTree(_ref3) {
|
|
|
285
346
|
if (projected && over) {
|
|
286
347
|
var depth = projected.depth,
|
|
287
348
|
parentId = projected.parentId;
|
|
349
|
+
|
|
350
|
+
// 检查目标父节点是否禁止拖入
|
|
351
|
+
var targetParent = parentId ? flattenedItems.find(function (item) {
|
|
352
|
+
return item.id === parentId;
|
|
353
|
+
}) : null;
|
|
354
|
+
if (targetParent !== null && targetParent !== void 0 && targetParent.disabledDrop) {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// 检查是否超过最大层级限制
|
|
359
|
+
if (depth >= maxLevel) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// 检查整个子树的深度是否会超过限制
|
|
364
|
+
var willExceedLimit = checkSubtreeDepth(flattenTreeData, active.id, depth);
|
|
365
|
+
if (willExceedLimit) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
288
368
|
var clonedItems = JSON.parse(JSON.stringify(flattenTree(items)));
|
|
289
369
|
var overIndex = clonedItems.findIndex(function (_ref11) {
|
|
290
370
|
var id = _ref11.id;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
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
|
-
var _excluded = ["id", "children"];
|
|
3
2
|
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
3
|
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
4
|
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
5
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
6
|
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 _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
9
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
10
7
|
import React, { useCallback, useMemo } from 'react';
|
|
11
8
|
import PisellDropSort from "../pisellDropSort";
|
|
12
9
|
import PisellTags from "../pisellTags";
|
|
@@ -15,6 +12,7 @@ import Button from "../button";
|
|
|
15
12
|
import { getText } from "../../locales";
|
|
16
13
|
import { Dropdown } from 'antd';
|
|
17
14
|
import PisellEmpty from "../pisellEmpty";
|
|
15
|
+
import { formatTree } from "./utils";
|
|
18
16
|
import "./PisellNavigationMenu.less";
|
|
19
17
|
var PisellNavigationMenu = function PisellNavigationMenu(_ref) {
|
|
20
18
|
var _ref$value = _ref.value,
|
|
@@ -42,19 +40,6 @@ var PisellNavigationMenu = function PisellNavigationMenu(_ref) {
|
|
|
42
40
|
onDelete = _ref.onDelete,
|
|
43
41
|
__designMode = _ref.__designMode,
|
|
44
42
|
title = _ref.title;
|
|
45
|
-
// 将NavigationMenuItem转换为DropSortItem
|
|
46
|
-
var convertToDropSortItems = function convertToDropSortItems(items) {
|
|
47
|
-
return items.map(function (item) {
|
|
48
|
-
var id = item.id,
|
|
49
|
-
children = item.children,
|
|
50
|
-
rest = _objectWithoutProperties(item, _excluded);
|
|
51
|
-
return _objectSpread({
|
|
52
|
-
id: id,
|
|
53
|
-
children: children ? convertToDropSortItems(children) : []
|
|
54
|
-
}, rest);
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
|
|
58
43
|
// 将DropSortItem转换回NavigationMenuItem
|
|
59
44
|
var convertToNavigationItems = function convertToNavigationItems(items) {
|
|
60
45
|
return items.map(function (item) {
|
|
@@ -174,8 +159,15 @@ var PisellNavigationMenu = function PisellNavigationMenu(_ref) {
|
|
|
174
159
|
}
|
|
175
160
|
}, getText('pisell-lowcode-navigation-menu-add-page')));
|
|
176
161
|
}, [title]);
|
|
162
|
+
var formatValue = useMemo(function () {
|
|
163
|
+
return formatTree(value, function (item) {
|
|
164
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
165
|
+
disabledDrop: !item.isGroup
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}, [value]);
|
|
177
169
|
return /*#__PURE__*/React.createElement(PisellDropSort, {
|
|
178
|
-
value:
|
|
170
|
+
value: formatValue,
|
|
179
171
|
allowDrag: allowDrag,
|
|
180
172
|
allowDelete: allowDelete,
|
|
181
173
|
allowAddChild: allowAddChild,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 树节点的基本接口
|
|
3
|
+
*/
|
|
4
|
+
export interface TreeNode {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
children?: TreeNode[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 格式化树结构数据
|
|
10
|
+
* @param tree 要格式化的树结构数据
|
|
11
|
+
* @param formatter 格式化函数,用于处理每个节点
|
|
12
|
+
* @param childrenField 子节点字段名,默认为 'children'
|
|
13
|
+
* @returns 格式化后的树结构
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatTree<T extends TreeNode, R = T>(tree: T[], formatter: (node: T, level: number, parent: T | null) => R, childrenField?: string): R[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 树节点的基本接口
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 格式化树结构数据
|
|
7
|
+
* @param tree 要格式化的树结构数据
|
|
8
|
+
* @param formatter 格式化函数,用于处理每个节点
|
|
9
|
+
* @param childrenField 子节点字段名,默认为 'children'
|
|
10
|
+
* @returns 格式化后的树结构
|
|
11
|
+
*/
|
|
12
|
+
export function formatTree(tree, formatter) {
|
|
13
|
+
var childrenField = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children';
|
|
14
|
+
var format = function format(nodes) {
|
|
15
|
+
var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
16
|
+
var parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
17
|
+
return nodes.map(function (node) {
|
|
18
|
+
// 格式化当前节点
|
|
19
|
+
var formattedNode = formatter(node, level, parent);
|
|
20
|
+
|
|
21
|
+
// 如果有子节点,递归处理
|
|
22
|
+
if (node[childrenField] && Array.isArray(node[childrenField])) {
|
|
23
|
+
formattedNode[childrenField] = format(node[childrenField], level + 1, node);
|
|
24
|
+
}
|
|
25
|
+
return formattedNode;
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
return format(tree);
|
|
29
|
+
}
|
|
@@ -18,5 +18,7 @@ export interface Props extends Omit<HTMLAttributes<HTMLLIElement>, 'id'> {
|
|
|
18
18
|
item: TreeItemType;
|
|
19
19
|
renderItem?(item: Props, ref: React.ForwardedRef<HTMLDivElement>): React.ReactNode;
|
|
20
20
|
__designMode?: string;
|
|
21
|
+
renderItem?(item: TreeItemType): React.ReactNode;
|
|
22
|
+
isBlocked?: boolean;
|
|
21
23
|
}
|
|
22
24
|
export declare const TreeItem: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -55,6 +55,7 @@ var TreeItem = (0, import_react.forwardRef)((props, ref) => {
|
|
|
55
55
|
item,
|
|
56
56
|
renderItem,
|
|
57
57
|
__designMode,
|
|
58
|
+
isBlocked,
|
|
58
59
|
...otherProps
|
|
59
60
|
} = props;
|
|
60
61
|
if (renderItem) {
|
|
@@ -77,12 +78,7 @@ var TreeItem = (0, import_react.forwardRef)((props, ref) => {
|
|
|
77
78
|
},
|
|
78
79
|
...otherProps
|
|
79
80
|
},
|
|
80
|
-
/* @__PURE__ */ import_react.default.createElement("div", { className: "TreeItem", ref, style }, /* @__PURE__ */ import_react.default.createElement(
|
|
81
|
-
import_components.Handle,
|
|
82
|
-
{
|
|
83
|
-
...__designMode === "design" ? {} : { ...handleProps }
|
|
84
|
-
}
|
|
85
|
-
), onCollapse && /* @__PURE__ */ import_react.default.createElement(
|
|
81
|
+
/* @__PURE__ */ import_react.default.createElement("div", { className: "TreeItem", ref, style }, /* @__PURE__ */ import_react.default.createElement(import_components.Handle, { ...__designMode === "design" ? {} : { ...handleProps } }), onCollapse && /* @__PURE__ */ import_react.default.createElement(
|
|
86
82
|
import_components.Action,
|
|
87
83
|
{
|
|
88
84
|
onClick: onCollapse,
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* 基于@dnd-kit库实现,支持拖拽排序、展开折叠、删除等功能
|
|
4
4
|
*/
|
|
5
5
|
import React from 'react';
|
|
6
|
-
import type { TreeItem, TreeItems } from './types';
|
|
7
6
|
import type { Props as TreeItemProps } from './components/TreeItem/TreeItem';
|
|
7
|
+
import type { TreeItem, TreeItems } from './types';
|
|
8
8
|
interface Props {
|
|
9
9
|
/** 是否支持折叠功能 */
|
|
10
10
|
collapsible?: boolean;
|
|
@@ -24,7 +24,9 @@ interface Props {
|
|
|
24
24
|
onRemoveBefore?: (item: TreeItem) => Promise<boolean>;
|
|
25
25
|
/** 设计模式 */
|
|
26
26
|
__designMode?: string;
|
|
27
|
+
/** 最大层级 */
|
|
28
|
+
maxLevel?: number;
|
|
27
29
|
}
|
|
28
|
-
export declare function SortableTree({ collapsible, value, indicator, indentationWidth, removable, renderItem, onChange, onRemoveBefore, __designMode, }: Props): React.JSX.Element;
|
|
30
|
+
export declare function SortableTree({ collapsible, value, indicator, indentationWidth, removable, renderItem, onChange, onRemoveBefore, __designMode, maxLevel, }: Props): React.JSX.Element;
|
|
29
31
|
declare const Demo: (props: Props) => React.JSX.Element;
|
|
30
32
|
export default Demo;
|
|
@@ -51,7 +51,7 @@ var initialItems = [
|
|
|
51
51
|
{ id: "Spring", children: [] },
|
|
52
52
|
{ id: "Summer", children: [] },
|
|
53
53
|
{ id: "Fall", children: [] },
|
|
54
|
-
{ id: "Winter", children: [] }
|
|
54
|
+
{ id: "Winter", children: [], disabledDrop: true }
|
|
55
55
|
]
|
|
56
56
|
},
|
|
57
57
|
{
|
|
@@ -102,7 +102,8 @@ function SortableTree({
|
|
|
102
102
|
renderItem,
|
|
103
103
|
onChange,
|
|
104
104
|
onRemoveBefore,
|
|
105
|
-
__designMode
|
|
105
|
+
__designMode,
|
|
106
|
+
maxLevel = 3
|
|
106
107
|
}) {
|
|
107
108
|
const [items, setItems] = (0, import_react.useState)([]);
|
|
108
109
|
const [activeId, setActiveId] = (0, import_react.useState)(null);
|
|
@@ -112,17 +113,20 @@ function SortableTree({
|
|
|
112
113
|
console.log("初始化", value);
|
|
113
114
|
setItems(value);
|
|
114
115
|
}, [value]);
|
|
116
|
+
const flattenTreeData = (0, import_react.useMemo)(() => {
|
|
117
|
+
return (0, import_utilities2.flattenTree)(items);
|
|
118
|
+
}, [items]);
|
|
115
119
|
const flattenedItems = (0, import_react.useMemo)(() => {
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
(acc, { children = [], collapsed, id }) => collapsed && (children == null ? void 0 : children.length) ? [...acc, id] : acc,
|
|
120
|
+
const collapsedItems = flattenTreeData.reduce(
|
|
121
|
+
(acc, { children = [], collapsed, id }) => collapsed && children.length ? [...acc, id] : acc,
|
|
119
122
|
[]
|
|
120
123
|
);
|
|
121
124
|
return (0, import_utilities2.removeChildrenOf)(
|
|
122
|
-
|
|
125
|
+
flattenTreeData,
|
|
123
126
|
activeId != null ? [activeId, ...collapsedItems] : collapsedItems
|
|
124
127
|
);
|
|
125
|
-
}, [activeId,
|
|
128
|
+
}, [activeId, flattenTreeData]);
|
|
129
|
+
console.log("flattenedItems", flattenedItems);
|
|
126
130
|
const projected = activeId && overId ? (0, import_utilities2.getProjection)(
|
|
127
131
|
flattenedItems,
|
|
128
132
|
activeId,
|
|
@@ -149,6 +153,20 @@ function SortableTree({
|
|
|
149
153
|
(0, import_react.useEffect)(() => {
|
|
150
154
|
document.body.id = "body";
|
|
151
155
|
}, []);
|
|
156
|
+
function checkSubtreeDepth(items2, itemId, baseDepth) {
|
|
157
|
+
const item = items2.find((i) => i.id === itemId);
|
|
158
|
+
if (!item)
|
|
159
|
+
return false;
|
|
160
|
+
if (baseDepth >= maxLevel)
|
|
161
|
+
return true;
|
|
162
|
+
const children = items2.filter((i) => i.parentId === itemId);
|
|
163
|
+
if (baseDepth >= maxLevel - 1 && children.length > 0)
|
|
164
|
+
return true;
|
|
165
|
+
return children.some((child) => {
|
|
166
|
+
const childNewDepth = baseDepth + 1;
|
|
167
|
+
return childNewDepth >= maxLevel || checkSubtreeDepth(items2, child.id, childNewDepth);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
152
170
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
153
171
|
import_core.DndContext,
|
|
154
172
|
{
|
|
@@ -211,12 +229,46 @@ function SortableTree({
|
|
|
211
229
|
setOffsetLeft(delta.x);
|
|
212
230
|
}
|
|
213
231
|
function handleDragOver({ over }) {
|
|
214
|
-
|
|
232
|
+
if (!projected || !over) {
|
|
233
|
+
setOverId((over == null ? void 0 : over.id) ?? null);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const targetParent = projected.parentId ? flattenedItems.find((item) => item.id === projected.parentId) : null;
|
|
237
|
+
if (targetParent == null ? void 0 : targetParent.disabledDrop) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (projected.depth >= maxLevel) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const willExceedLimit = checkSubtreeDepth(
|
|
244
|
+
flattenTreeData,
|
|
245
|
+
activeId,
|
|
246
|
+
projected.depth
|
|
247
|
+
);
|
|
248
|
+
if (willExceedLimit) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
setOverId(over.id);
|
|
215
252
|
}
|
|
216
253
|
function handleDragEnd({ active, over }) {
|
|
217
254
|
resetState();
|
|
218
255
|
if (projected && over) {
|
|
219
256
|
const { depth, parentId } = projected;
|
|
257
|
+
const targetParent = parentId ? flattenedItems.find((item) => item.id === parentId) : null;
|
|
258
|
+
if (targetParent == null ? void 0 : targetParent.disabledDrop) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (depth >= maxLevel) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const willExceedLimit = checkSubtreeDepth(
|
|
265
|
+
flattenTreeData,
|
|
266
|
+
active.id,
|
|
267
|
+
depth
|
|
268
|
+
);
|
|
269
|
+
if (willExceedLimit) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
220
272
|
const clonedItems = JSON.parse(
|
|
221
273
|
JSON.stringify((0, import_utilities2.flattenTree)(items))
|
|
222
274
|
);
|
|
@@ -40,6 +40,7 @@ var import_button = __toESM(require("../button"));
|
|
|
40
40
|
var import_locales = require("../../locales");
|
|
41
41
|
var import_antd = require("antd");
|
|
42
42
|
var import_pisellEmpty = __toESM(require("../pisellEmpty"));
|
|
43
|
+
var import_utils = require("./utils");
|
|
43
44
|
var import_PisellNavigationMenu = require("./PisellNavigationMenu.less");
|
|
44
45
|
var PisellNavigationMenu = ({
|
|
45
46
|
value = [],
|
|
@@ -60,16 +61,6 @@ var PisellNavigationMenu = ({
|
|
|
60
61
|
__designMode,
|
|
61
62
|
title
|
|
62
63
|
}) => {
|
|
63
|
-
const convertToDropSortItems = (items2) => {
|
|
64
|
-
return items2.map((item) => {
|
|
65
|
-
const { id, children, ...rest } = item;
|
|
66
|
-
return {
|
|
67
|
-
id,
|
|
68
|
-
children: children ? convertToDropSortItems(children) : [],
|
|
69
|
-
...rest
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
64
|
const convertToNavigationItems = (items2) => {
|
|
74
65
|
return items2.map((item) => ({
|
|
75
66
|
id: String(item.id),
|
|
@@ -183,10 +174,16 @@ var PisellNavigationMenu = ({
|
|
|
183
174
|
(0, import_locales.getText)("pisell-lowcode-navigation-menu-add-page")
|
|
184
175
|
));
|
|
185
176
|
}, [title]);
|
|
177
|
+
const formatValue = (0, import_react.useMemo)(() => {
|
|
178
|
+
return (0, import_utils.formatTree)(value, (item) => ({
|
|
179
|
+
...item,
|
|
180
|
+
disabledDrop: !item.isGroup
|
|
181
|
+
}));
|
|
182
|
+
}, [value]);
|
|
186
183
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
187
184
|
import_pisellDropSort.default,
|
|
188
185
|
{
|
|
189
|
-
value:
|
|
186
|
+
value: formatValue,
|
|
190
187
|
allowDrag,
|
|
191
188
|
allowDelete,
|
|
192
189
|
allowAddChild,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 树节点的基本接口
|
|
3
|
+
*/
|
|
4
|
+
export interface TreeNode {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
children?: TreeNode[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* 格式化树结构数据
|
|
10
|
+
* @param tree 要格式化的树结构数据
|
|
11
|
+
* @param formatter 格式化函数,用于处理每个节点
|
|
12
|
+
* @param childrenField 子节点字段名,默认为 'children'
|
|
13
|
+
* @returns 格式化后的树结构
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatTree<T extends TreeNode, R = T>(tree: T[], formatter: (node: T, level: number, parent: T | null) => R, childrenField?: string): R[];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/components/pisellNavigationMenu/utils.ts
|
|
20
|
+
var utils_exports = {};
|
|
21
|
+
__export(utils_exports, {
|
|
22
|
+
formatTree: () => formatTree
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(utils_exports);
|
|
25
|
+
function formatTree(tree, formatter, childrenField = "children") {
|
|
26
|
+
const format = (nodes, level = 0, parent = null) => {
|
|
27
|
+
return nodes.map((node) => {
|
|
28
|
+
const formattedNode = formatter(node, level, parent);
|
|
29
|
+
if (node[childrenField] && Array.isArray(node[childrenField])) {
|
|
30
|
+
formattedNode[childrenField] = format(
|
|
31
|
+
node[childrenField],
|
|
32
|
+
level + 1,
|
|
33
|
+
node
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return formattedNode;
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
return format(tree);
|
|
40
|
+
}
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
formatTree
|
|
44
|
+
});
|