@pisell/materials 3.3.32 → 3.3.34
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 +2 -2
- package/build/lowcode/preview.js +9 -9
- package/build/lowcode/render/default/view.css +1 -1
- package/build/lowcode/render/default/view.js +24 -24
- package/build/lowcode/view.css +1 -1
- package/build/lowcode/view.js +25 -25
- package/es/components/buttonGroupEdit/index.d.ts +8 -0
- package/es/components/dataSourceComponents/dataSourceMenu/Basic.js +6 -2
- package/es/components/dataSourceComponents/dataSourceTable/hooks/useDataSourceKey.d.ts +2 -2
- package/es/components/dataSourceComponents/dataSourceTable/hooks/useTableProps.d.ts +4 -4
- package/es/components/dataSourceComponents/dataSourceTable/hooks/useTableQuery.d.ts +32 -0
- package/es/components/dataSourceComponents/dataSourceTable/hooks/useTableQuery.js +1 -1
- package/es/components/dataSourceComponents/fields/DatePicker/ReadPretty.d.ts +5 -0
- package/es/components/dataSourceComponents/fields/DatePicker/ReadPretty.js +4 -12
- package/es/components/dataSourceComponents/fields/utils.js +0 -5
- package/es/components/div/index.js +45 -8
- package/es/components/pisellDraggable/components/TreeItem/SortableTreeItem.js +4 -3
- package/es/components/pisellDraggable/components/TreeItem/index.js +1 -1
- package/es/components/pisellDraggable/index.js +165 -127
- package/es/components/pisellDropSort/PisellDropSort.js +10 -3
- package/es/components/pisellDropSort/components/SortableItem/index.js +6 -1
- package/es/components/pisellDropSort/components/SortableItem/index.less +0 -1
- package/es/components/pisellMenu/PisellMenu.js +1 -0
- package/es/components/pisellNavigationMenu/PisellNavigationMenu.d.ts +5 -0
- package/es/components/pisellNavigationMenu/PisellNavigationMenu.js +79 -11
- package/es/components/pisellNavigationMenu/PisellNavigationMenu.less +14 -0
- package/es/components/productCard/components/MultiDay/index.d.ts +3 -0
- package/es/components/productCard/components/Packages/components/collapsibleList/utils.d.ts +1 -0
- package/es/components/productCard/components/Packages/components/options/index.d.ts +3 -0
- package/es/components/productCard/components/Packages/utils.d.ts +1 -1
- package/es/components/table/Gallery/components/VirtualGrid/useGapSize.d.ts +2 -2
- package/es/components/table/Table/SelectField/index.d.ts +1 -0
- package/es/components/table/Table/fields/index.d.ts +3 -2
- package/es/components/table/Table/fields/select/filterUtil/index.d.ts +1 -1
- package/es/components/table/Table/fields/treeSelect/filterUtil/index.d.ts +1 -1
- package/es/components/table/Table/utils.d.ts +1 -1
- package/es/locales/en-US.js +4 -0
- package/es/locales/zh-CN.js +4 -0
- package/es/locales/zh-TW.js +4 -0
- package/es/utils/index.d.ts +1 -1
- package/es/utils/platform.d.ts +1 -1
- package/lib/components/buttonGroupEdit/index.d.ts +8 -0
- package/lib/components/dataSourceComponents/dataSourceMenu/Basic.js +6 -2
- package/lib/components/dataSourceComponents/dataSourceTable/hooks/useDataSourceKey.d.ts +2 -2
- package/lib/components/dataSourceComponents/dataSourceTable/hooks/useTableProps.d.ts +4 -4
- package/lib/components/dataSourceComponents/dataSourceTable/hooks/useTableQuery.d.ts +32 -0
- package/lib/components/dataSourceComponents/dataSourceTable/hooks/useTableQuery.js +1 -1
- package/lib/components/dataSourceComponents/fields/DatePicker/ReadPretty.d.ts +5 -0
- package/lib/components/dataSourceComponents/fields/DatePicker/ReadPretty.js +7 -15
- package/lib/components/dataSourceComponents/fields/utils.js +0 -5
- package/lib/components/div/index.js +33 -3
- package/lib/components/pisellDraggable/components/TreeItem/SortableTreeItem.js +4 -7
- package/lib/components/pisellDraggable/components/TreeItem/index.js +12 -2
- package/lib/components/pisellDraggable/index.js +114 -80
- package/lib/components/pisellDropSort/PisellDropSort.js +9 -3
- package/lib/components/pisellDropSort/components/SortableItem/index.js +5 -0
- package/lib/components/pisellDropSort/components/SortableItem/index.less +0 -1
- package/lib/components/pisellMenu/PisellMenu.js +1 -0
- package/lib/components/pisellNavigationMenu/PisellNavigationMenu.d.ts +5 -0
- package/lib/components/pisellNavigationMenu/PisellNavigationMenu.js +64 -9
- package/lib/components/pisellNavigationMenu/PisellNavigationMenu.less +14 -0
- package/lib/components/productCard/components/MultiDay/index.d.ts +3 -0
- package/lib/components/productCard/components/Packages/components/collapsibleList/utils.d.ts +1 -0
- package/lib/components/productCard/components/Packages/components/options/index.d.ts +3 -0
- package/lib/components/productCard/components/Packages/utils.d.ts +1 -1
- package/lib/components/table/Gallery/components/VirtualGrid/useGapSize.d.ts +2 -2
- package/lib/components/table/Table/SelectField/index.d.ts +1 -0
- package/lib/components/table/Table/fields/index.d.ts +3 -2
- package/lib/components/table/Table/fields/select/filterUtil/index.d.ts +1 -1
- package/lib/components/table/Table/fields/treeSelect/filterUtil/index.d.ts +1 -1
- package/lib/components/table/Table/utils.d.ts +1 -1
- package/lib/locales/en-US.js +4 -0
- package/lib/locales/zh-CN.js +4 -0
- package/lib/locales/zh-TW.js +4 -0
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/platform.d.ts +1 -1
- package/lowcode/div/meta.ts +39 -4
- package/lowcode/pisell-navigation-menu/meta.ts +12 -0
- package/package.json +3 -3
- package/es/components/appVersionControl/index.d.ts +0 -4
- package/es/components/dataSourceComponents/dataSourceTable/hooks/useDrawerState.d.ts +0 -38
- package/es/components/dataSourceComponents/dataSourceTable/type.d.ts +0 -78
- package/es/components/div/index.d.ts +0 -8
- package/es/components/drag-sort-tree/index.d.ts +0 -4
- package/es/components/pisellDraggable/components/TreeItem/SortableTreeItem.d.ts +0 -9
- package/es/components/pisellDraggable/components/TreeItem/TreeItem.d.ts +0 -23
- package/es/components/pisellDraggable/components/TreeItem/index.d.ts +0 -2
- package/es/components/pisellDraggable/index.d.ts +0 -32
- package/es/components/pisellDropSort/PisellDropSort.d.ts +0 -5
- package/es/components/pisellDropSort/components/SortableItem/index.d.ts +0 -25
- package/es/components/pisellDropSort/types.d.ts +0 -52
- package/es/components/pisellMenu/PisellMenu.d.ts +0 -9
- package/es/components/pisellMenu/types.d.ts +0 -26
- package/es/components/pisellNavigationMenu/types.d.ts +0 -64
- package/es/components/table/Actions/component/ExportImport/index.d.ts +0 -7
- package/es/components/table/Table/index.d.ts +0 -4
- package/es/components/table/types.d.ts +0 -251
- package/es/components/versionModal/index.d.ts +0 -23
- package/lib/components/appVersionControl/index.d.ts +0 -4
- package/lib/components/dataSourceComponents/dataSourceTable/hooks/useDrawerState.d.ts +0 -38
- package/lib/components/dataSourceComponents/dataSourceTable/type.d.ts +0 -78
- package/lib/components/div/index.d.ts +0 -8
- package/lib/components/drag-sort-tree/index.d.ts +0 -4
- package/lib/components/pisellDraggable/components/TreeItem/SortableTreeItem.d.ts +0 -9
- package/lib/components/pisellDraggable/components/TreeItem/TreeItem.d.ts +0 -23
- package/lib/components/pisellDraggable/components/TreeItem/index.d.ts +0 -2
- package/lib/components/pisellDraggable/index.d.ts +0 -32
- package/lib/components/pisellDropSort/PisellDropSort.d.ts +0 -5
- package/lib/components/pisellDropSort/components/SortableItem/index.d.ts +0 -25
- package/lib/components/pisellDropSort/types.d.ts +0 -52
- package/lib/components/pisellMenu/PisellMenu.d.ts +0 -9
- package/lib/components/pisellMenu/types.d.ts +0 -26
- package/lib/components/pisellNavigationMenu/types.d.ts +0 -64
- package/lib/components/table/Actions/component/ExportImport/index.d.ts +0 -7
- package/lib/components/table/Table/index.d.ts +0 -4
- package/lib/components/table/types.d.ts +0 -251
- package/lib/components/versionModal/index.d.ts +0 -23
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ButtonGroupListItemProps } from './../buttonGroupPreview';
|
|
3
|
+
interface ButtonGroupEditProps {
|
|
4
|
+
buttonList: ButtonGroupListItemProps[];
|
|
5
|
+
buttonGroupList: ButtonGroupListItemProps[][];
|
|
6
|
+
}
|
|
7
|
+
declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<ButtonGroupEditProps & React.RefAttributes<any>>>;
|
|
8
|
+
export default _default;
|
|
@@ -34,8 +34,12 @@ var DataSourceMenu = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
34
34
|
return null;
|
|
35
35
|
}
|
|
36
36
|
var _children = getShowChildren(item.children || []);
|
|
37
|
-
if (_children !== null && _children !== void 0 && _children.length) {
|
|
38
|
-
|
|
37
|
+
if (_children !== null && _children !== void 0 && _children.length || item.isGroup) {
|
|
38
|
+
var CptMenu = BaseMenu.SubMenu;
|
|
39
|
+
if (item.type === 'group') {
|
|
40
|
+
CptMenu = BaseMenu.ItemGroup;
|
|
41
|
+
}
|
|
42
|
+
return /*#__PURE__*/React.createElement(CptMenu, {
|
|
39
43
|
key: item.key,
|
|
40
44
|
title: translation(item.label),
|
|
41
45
|
icon: item.icon,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const useDataSourceKey: () => {
|
|
2
|
-
dataSourceKey: string | undefined;
|
|
3
|
-
dataSourceKeyRef: import("react").MutableRefObject<string | undefined>;
|
|
2
|
+
dataSourceKey: string | import("../../provider/dataSource/DataSourceContext").DataSourceType | undefined;
|
|
3
|
+
dataSourceKeyRef: import("react").MutableRefObject<string | import("../../provider/dataSource/DataSourceContext").DataSourceType | undefined>;
|
|
4
4
|
};
|
|
5
5
|
export default useDataSourceKey;
|
|
@@ -17,7 +17,7 @@ interface UseTablePropsProps {
|
|
|
17
17
|
* @returns
|
|
18
18
|
*/
|
|
19
19
|
declare const useTableProps: (props: UseTablePropsProps) => {
|
|
20
|
-
title: number | boolean |
|
|
20
|
+
title: string | number | boolean | React.ReactFragment | JSX.Element | (() => React.ReactNode) | null | undefined;
|
|
21
21
|
pagination: {
|
|
22
22
|
total: number;
|
|
23
23
|
current: number;
|
|
@@ -26,7 +26,7 @@ declare const useTableProps: (props: UseTablePropsProps) => {
|
|
|
26
26
|
showSizeChanger: boolean;
|
|
27
27
|
};
|
|
28
28
|
columns: import("./useColumns").Column[];
|
|
29
|
-
subTitle: number | boolean |
|
|
29
|
+
subTitle: string | number | boolean | React.ReactFragment | JSX.Element | (() => React.ReactNode) | null | undefined;
|
|
30
30
|
buttons: any[] | null;
|
|
31
31
|
filter: JSX.Element | null;
|
|
32
32
|
onRow: (record: any) => any;
|
|
@@ -52,7 +52,7 @@ declare const useTableProps: (props: UseTablePropsProps) => {
|
|
|
52
52
|
width: number;
|
|
53
53
|
align: "center" | "left" | "right";
|
|
54
54
|
fixed: false | "left" | "right";
|
|
55
|
-
type: "
|
|
55
|
+
type: "button" | "link";
|
|
56
56
|
items: OperationItem[];
|
|
57
57
|
} | undefined;
|
|
58
58
|
operationContent?: {
|
|
@@ -70,7 +70,7 @@ declare const useTableProps: (props: UseTablePropsProps) => {
|
|
|
70
70
|
useCustomAction: boolean;
|
|
71
71
|
actionType: string;
|
|
72
72
|
openMode: "modal" | "drawer";
|
|
73
|
-
openContentSize: "
|
|
73
|
+
openContentSize: "large" | "middle" | "small";
|
|
74
74
|
openTitle: string;
|
|
75
75
|
key: string;
|
|
76
76
|
} | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DataSourceTableProps } from '../type';
|
|
2
|
+
declare type Params = {
|
|
3
|
+
pagination?: {
|
|
4
|
+
page: number;
|
|
5
|
+
size: number;
|
|
6
|
+
};
|
|
7
|
+
order_by?: string;
|
|
8
|
+
tabs?: {
|
|
9
|
+
name: string;
|
|
10
|
+
filterBy: Record<string, any>;
|
|
11
|
+
sortBy: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
declare const useTableQuery: (props: DataSourceTableProps) => {
|
|
15
|
+
queryPageConfig: {
|
|
16
|
+
page: number;
|
|
17
|
+
pageSize: number;
|
|
18
|
+
filter: Record<string, any>;
|
|
19
|
+
sort: string;
|
|
20
|
+
};
|
|
21
|
+
setQueryPageConfig: import("react").Dispatch<import("react").SetStateAction<{
|
|
22
|
+
page: number;
|
|
23
|
+
pageSize: number;
|
|
24
|
+
filter: Record<string, any>;
|
|
25
|
+
sort: string;
|
|
26
|
+
}>>;
|
|
27
|
+
handleValuesChange: (params: Params, allParams: Params) => void;
|
|
28
|
+
refreshData: () => void;
|
|
29
|
+
handleFilterChange: (changedFields: any, allFields: any) => void;
|
|
30
|
+
refreshCurrentPage: () => void;
|
|
31
|
+
};
|
|
32
|
+
export default useTableQuery;
|
|
@@ -21,7 +21,7 @@ var useTableQuery = function useTableQuery(props) {
|
|
|
21
21
|
// 分页配置
|
|
22
22
|
var _useState = useState({
|
|
23
23
|
page: 1,
|
|
24
|
-
pageSize:
|
|
24
|
+
pageSize: 10,
|
|
25
25
|
filter: (tabs === null || tabs === void 0 || (_tabs$items = tabs.items) === null || _tabs$items === void 0 || (_tabs$items = _tabs$items[0]) === null || _tabs$items === void 0 ? void 0 : _tabs$items.filterBy) || filterBy || {},
|
|
26
26
|
sort: (tabs === null || tabs === void 0 || (_tabs$items2 = tabs.items) === null || _tabs$items2 === void 0 || (_tabs$items2 = _tabs$items2[0]) === null || _tabs$items2 === void 0 ? void 0 : _tabs$items2.sortBy) || sortBy
|
|
27
27
|
}),
|
|
@@ -3,23 +3,15 @@ import classNames from 'classnames';
|
|
|
3
3
|
import dayjs from 'dayjs';
|
|
4
4
|
import usePisellConfig from "../../../pisell-config-provider/hooks/usePisellConfig";
|
|
5
5
|
import "./ReadPretty.less";
|
|
6
|
-
var DEFAULT_FORMAT = 'DD
|
|
6
|
+
var DEFAULT_FORMAT = 'YYYY-MM-DD HH:mm:ss';
|
|
7
7
|
var DATE_FORMATS = {
|
|
8
8
|
'zh-CN': {
|
|
9
|
-
withTime: 'YYYY-MM-DD HH:mm',
|
|
9
|
+
withTime: 'YYYY-MM-DD HH:mm:ss',
|
|
10
10
|
withoutTime: 'YYYY-MM-DD'
|
|
11
11
|
},
|
|
12
12
|
'en-US': {
|
|
13
|
-
withTime: '
|
|
14
|
-
withoutTime: 'MM
|
|
15
|
-
},
|
|
16
|
-
'en-AU': {
|
|
17
|
-
withTime: 'DD/MM/YYYY HH:mm',
|
|
18
|
-
withoutTime: 'DD/MM/YYYY'
|
|
19
|
-
},
|
|
20
|
-
en: {
|
|
21
|
-
withTime: 'DD/MM/YYYY HH:mm',
|
|
22
|
-
withoutTime: 'DD/MM/YYYY'
|
|
13
|
+
withTime: 'HH:mm:ss YYYY-MM-DD',
|
|
14
|
+
withoutTime: 'YYYY-MM-DD'
|
|
23
15
|
}
|
|
24
16
|
};
|
|
25
17
|
var DatePickerReadPretty = function DatePickerReadPretty(_ref) {
|
|
@@ -1,17 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
var _excluded = ["baseClassName", "className", "render", "children", "style", "others"];
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
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(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
3
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; }
|
|
4
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; }
|
|
5
|
-
import React from "react";
|
|
10
|
+
import React, { useMemo } from "react";
|
|
6
11
|
var Div = function Div(props) {
|
|
7
|
-
var
|
|
12
|
+
var _props$baseClassName = props.baseClassName,
|
|
13
|
+
baseClassName = _props$baseClassName === void 0 ? "div" : _props$baseClassName,
|
|
14
|
+
_props$className = props.className,
|
|
15
|
+
className = _props$className === void 0 ? "" : _props$className,
|
|
16
|
+
render = props.render,
|
|
17
|
+
children = props.children,
|
|
8
18
|
_props$style = props.style,
|
|
9
19
|
style = _props$style === void 0 ? {} : _props$style,
|
|
10
20
|
_props$others = props.others,
|
|
11
21
|
others = _props$others === void 0 ? {} : _props$others,
|
|
12
22
|
otherProps = _objectWithoutProperties(props, _excluded);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
23
|
+
|
|
24
|
+
// 合并类名
|
|
25
|
+
var combinedClassName = useMemo(function () {
|
|
26
|
+
var parts = [baseClassName, className].filter(Boolean);
|
|
27
|
+
return parts.length > 0 ? parts.join(' ') : undefined;
|
|
28
|
+
}, [baseClassName, className]);
|
|
29
|
+
|
|
30
|
+
// 决定渲染内容:优先使用 render 函数
|
|
31
|
+
var content = useMemo(function () {
|
|
32
|
+
if (render) {
|
|
33
|
+
try {
|
|
34
|
+
return render();
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error('Div render function error:', error);
|
|
37
|
+
return children;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return children;
|
|
41
|
+
}, [render, children]);
|
|
42
|
+
|
|
43
|
+
// 合并所有要传递给 div 的 props
|
|
44
|
+
var divProps = useMemo(function () {
|
|
45
|
+
return _objectSpread(_objectSpread(_objectSpread({}, combinedClassName && {
|
|
46
|
+
className: combinedClassName
|
|
47
|
+
}), {}, {
|
|
48
|
+
style: style
|
|
49
|
+
}, others), otherProps);
|
|
50
|
+
}, [combinedClassName, style, others, otherProps]);
|
|
51
|
+
return /*#__PURE__*/React.createElement("div", divProps, content);
|
|
16
52
|
};
|
|
17
|
-
|
|
53
|
+
Div.displayName = 'Div';
|
|
54
|
+
export default /*#__PURE__*/React.memo(Div);
|
|
@@ -10,7 +10,7 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
10
10
|
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; }
|
|
11
11
|
import { useSortable } from '@dnd-kit/sortable';
|
|
12
12
|
import { CSS } from '@dnd-kit/utilities';
|
|
13
|
-
import React from 'react';
|
|
13
|
+
import React, { memo } from 'react';
|
|
14
14
|
import { iOS } from "../../utilities";
|
|
15
15
|
import { TreeItem } from "./TreeItem";
|
|
16
16
|
var animateLayoutChanges = function animateLayoutChanges(_ref) {
|
|
@@ -18,7 +18,7 @@ var animateLayoutChanges = function animateLayoutChanges(_ref) {
|
|
|
18
18
|
wasDragging = _ref.wasDragging;
|
|
19
19
|
return isSorting || wasDragging ? false : true;
|
|
20
20
|
};
|
|
21
|
-
|
|
21
|
+
var SortableTreeItem = function SortableTreeItem(_ref2) {
|
|
22
22
|
var id = _ref2.id,
|
|
23
23
|
depth = _ref2.depth,
|
|
24
24
|
props = _objectWithoutProperties(_ref2, _excluded);
|
|
@@ -48,4 +48,5 @@ export function SortableTreeItem(_ref2) {
|
|
|
48
48
|
disableInteraction: isSorting,
|
|
49
49
|
handleProps: _objectSpread(_objectSpread({}, attributes), listeners)
|
|
50
50
|
}, props));
|
|
51
|
-
}
|
|
51
|
+
};
|
|
52
|
+
export default /*#__PURE__*/memo(SortableTreeItem);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { TreeItem } from "./TreeItem";
|
|
2
|
-
export { SortableTreeItem } from "./SortableTreeItem";
|
|
2
|
+
export { default as SortableTreeItem } from "./SortableTreeItem";
|
|
@@ -26,6 +26,7 @@ import { DndContext, DragOverlay, MeasuringStrategy, PointerSensor, closestCente
|
|
|
26
26
|
import { SortableContext, arrayMove, verticalListSortingStrategy } from '@dnd-kit/sortable';
|
|
27
27
|
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
28
28
|
import { createPortal } from 'react-dom';
|
|
29
|
+
import { useMemoizedFn } from 'ahooks';
|
|
29
30
|
import { CSS } from '@dnd-kit/utilities';
|
|
30
31
|
import { SortableTreeItem } from "./components";
|
|
31
32
|
import { buildTree, flattenTree, getChildCount, getProjection, removeChildrenOf, removeItem, setProperty } from "./utilities";
|
|
@@ -119,12 +120,13 @@ export function SortableTree(_ref3) {
|
|
|
119
120
|
indentationWidth = _ref3$indentationWidt === void 0 ? 50 : _ref3$indentationWidt,
|
|
120
121
|
_ref3$removable = _ref3.removable,
|
|
121
122
|
removable = _ref3$removable === void 0 ? true : _ref3$removable,
|
|
122
|
-
|
|
123
|
+
_renderItem = _ref3.renderItem,
|
|
123
124
|
onChange = _ref3.onChange,
|
|
124
125
|
onRemoveBefore = _ref3.onRemoveBefore,
|
|
125
126
|
__designMode = _ref3.__designMode,
|
|
126
127
|
_ref3$maxLevel = _ref3.maxLevel,
|
|
127
|
-
maxLevel = _ref3$maxLevel === void 0 ? 3 : _ref3$maxLevel
|
|
128
|
+
maxLevel = _ref3$maxLevel === void 0 ? 3 : _ref3$maxLevel,
|
|
129
|
+
canDrop = _ref3.canDrop;
|
|
128
130
|
// 状态管理
|
|
129
131
|
/** 当前树形数据 */
|
|
130
132
|
var _useState = useState([]),
|
|
@@ -171,6 +173,7 @@ export function SortableTree(_ref3) {
|
|
|
171
173
|
return removeChildrenOf(flattenTreeData, activeId != null ? [activeId].concat(_toConsumableArray(collapsedItems)) : collapsedItems);
|
|
172
174
|
}, [activeId, flattenTreeData]);
|
|
173
175
|
console.log('flattenedItems', flattenedItems);
|
|
176
|
+
|
|
174
177
|
/**
|
|
175
178
|
* 计算拖拽投影
|
|
176
179
|
* 根据当前拖拽状态计算目标位置和深度
|
|
@@ -192,10 +195,12 @@ export function SortableTree(_ref3) {
|
|
|
192
195
|
return id;
|
|
193
196
|
});
|
|
194
197
|
}, [flattenedItems]);
|
|
195
|
-
var activeItem =
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
198
|
+
var activeItem = useMemo(function () {
|
|
199
|
+
return activeId ? flattenedItems.find(function (_ref6) {
|
|
200
|
+
var id = _ref6.id;
|
|
201
|
+
return id === activeId;
|
|
202
|
+
}) : null;
|
|
203
|
+
}, [activeId, flattenedItems]);
|
|
199
204
|
useEffect(function () {
|
|
200
205
|
sensorContext.current = {
|
|
201
206
|
items: flattenedItems,
|
|
@@ -238,74 +243,67 @@ export function SortableTree(_ref3) {
|
|
|
238
243
|
return childNewDepth >= maxLevel || checkSubtreeDepth(items, child.id, childNewDepth);
|
|
239
244
|
});
|
|
240
245
|
}
|
|
241
|
-
return /*#__PURE__*/React.createElement(DndContext, {
|
|
242
|
-
sensors: sensors,
|
|
243
|
-
collisionDetection: closestCenter,
|
|
244
|
-
measuring: measuring,
|
|
245
|
-
onDragStart: handleDragStart,
|
|
246
|
-
onDragMove: handleDragMove,
|
|
247
|
-
onDragOver: handleDragOver,
|
|
248
|
-
onDragEnd: handleDragEnd,
|
|
249
|
-
onDragCancel: handleDragCancel
|
|
250
|
-
}, /*#__PURE__*/React.createElement(SortableContext, {
|
|
251
|
-
items: sortedIds,
|
|
252
|
-
strategy: verticalListSortingStrategy
|
|
253
|
-
}, flattenedItems.map(function (item) {
|
|
254
|
-
var id = item.id,
|
|
255
|
-
children = item.children,
|
|
256
|
-
collapsed = item.collapsed,
|
|
257
|
-
depth = item.depth;
|
|
258
|
-
return /*#__PURE__*/React.createElement(SortableTreeItem, {
|
|
259
|
-
key: id,
|
|
260
|
-
id: id,
|
|
261
|
-
item: item,
|
|
262
|
-
depth: id === activeId && projected ? projected.depth : depth,
|
|
263
|
-
indentationWidth: indentationWidth,
|
|
264
|
-
indicator: indicator,
|
|
265
|
-
collapsed: Boolean(collapsed && (children === null || children === void 0 ? void 0 : children.length)),
|
|
266
|
-
onCollapse: collapsible && children !== null && children !== void 0 && children.length ? function () {
|
|
267
|
-
return handleCollapse(id);
|
|
268
|
-
} : undefined,
|
|
269
|
-
onRemove: removable ? function () {
|
|
270
|
-
return handleRemove(item);
|
|
271
|
-
} : undefined,
|
|
272
|
-
renderItem: renderItem,
|
|
273
|
-
__designMode: __designMode
|
|
274
|
-
});
|
|
275
|
-
}), /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement(DragOverlay, {
|
|
276
|
-
dropAnimation: dropAnimationConfig,
|
|
277
|
-
modifiers: indicator ? [adjustTranslate] : undefined
|
|
278
|
-
}, activeId && activeItem ? /*#__PURE__*/React.createElement(SortableTreeItem, {
|
|
279
|
-
id: activeId,
|
|
280
|
-
depth: activeItem.depth,
|
|
281
|
-
clone: true,
|
|
282
|
-
childCount: getChildCount(items, activeId) + 1,
|
|
283
|
-
item: activeItem,
|
|
284
|
-
indentationWidth: indentationWidth,
|
|
285
|
-
renderItem: renderItem
|
|
286
|
-
}) : null), document.body)));
|
|
287
246
|
|
|
288
247
|
/**
|
|
289
|
-
*
|
|
290
|
-
*
|
|
248
|
+
* 处理节点删除
|
|
249
|
+
* 从树形结构中移除指定节点
|
|
291
250
|
*/
|
|
292
|
-
function
|
|
293
|
-
var
|
|
251
|
+
var handleRemove = useMemoizedFn( /*#__PURE__*/function () {
|
|
252
|
+
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(item) {
|
|
253
|
+
var res;
|
|
254
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
255
|
+
while (1) switch (_context.prev = _context.next) {
|
|
256
|
+
case 0:
|
|
257
|
+
if (!onRemoveBefore) {
|
|
258
|
+
_context.next = 6;
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
_context.next = 3;
|
|
262
|
+
return onRemoveBefore === null || onRemoveBefore === void 0 ? void 0 : onRemoveBefore(item);
|
|
263
|
+
case 3:
|
|
264
|
+
res = _context.sent;
|
|
265
|
+
if (res) {
|
|
266
|
+
_context.next = 6;
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
return _context.abrupt("return");
|
|
270
|
+
case 6:
|
|
271
|
+
setItems(function (items) {
|
|
272
|
+
return removeItem(items, item.id);
|
|
273
|
+
});
|
|
274
|
+
onChange === null || onChange === void 0 || onChange(items);
|
|
275
|
+
case 8:
|
|
276
|
+
case "end":
|
|
277
|
+
return _context.stop();
|
|
278
|
+
}
|
|
279
|
+
}, _callee);
|
|
280
|
+
}));
|
|
281
|
+
return function (_x) {
|
|
282
|
+
return _ref7.apply(this, arguments);
|
|
283
|
+
};
|
|
284
|
+
}());
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* 处理拖拽开始事件
|
|
288
|
+
* 设置当前拖拽项和初始状态
|
|
289
|
+
*/
|
|
290
|
+
var handleDragStart = useMemoizedFn(function (_ref8) {
|
|
291
|
+
var activeId = _ref8.active.id;
|
|
294
292
|
setActiveId(activeId);
|
|
295
293
|
setOverId(activeId);
|
|
296
294
|
document.body.style.setProperty('cursor', 'grabbing');
|
|
297
|
-
}
|
|
295
|
+
});
|
|
298
296
|
|
|
299
297
|
/**
|
|
300
298
|
* 处理拖拽移动事件
|
|
301
299
|
* 更新水平偏移量
|
|
302
300
|
*/
|
|
303
|
-
|
|
304
|
-
var delta =
|
|
301
|
+
var handleDragMove = useMemoizedFn(function (_ref9) {
|
|
302
|
+
var delta = _ref9.delta;
|
|
305
303
|
setOffsetLeft(delta.x);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
var over =
|
|
304
|
+
});
|
|
305
|
+
var handleDragOver = useMemoizedFn(function (_ref10) {
|
|
306
|
+
var over = _ref10.over;
|
|
309
307
|
if (!projected || !over) {
|
|
310
308
|
var _over$id;
|
|
311
309
|
setOverId((_over$id = over === null || over === void 0 ? void 0 : over.id) !== null && _over$id !== void 0 ? _over$id : null);
|
|
@@ -331,7 +329,12 @@ export function SortableTree(_ref3) {
|
|
|
331
329
|
return;
|
|
332
330
|
}
|
|
333
331
|
setOverId(over.id);
|
|
334
|
-
}
|
|
332
|
+
});
|
|
333
|
+
var parentNode = useMemo(function () {
|
|
334
|
+
return projected !== null && projected !== void 0 && projected.parentId ? flattenedItems.find(function (item) {
|
|
335
|
+
return item.id === projected.parentId;
|
|
336
|
+
}) : null;
|
|
337
|
+
}, [flattenedItems, projected === null || projected === void 0 ? void 0 : projected.parentId]);
|
|
335
338
|
|
|
336
339
|
/**
|
|
337
340
|
* 处理拖拽结束事件
|
|
@@ -339,22 +342,38 @@ export function SortableTree(_ref3) {
|
|
|
339
342
|
* 2. 更新节点位置和层级
|
|
340
343
|
* 3. 重建树形结构
|
|
341
344
|
*/
|
|
342
|
-
|
|
343
|
-
var active =
|
|
344
|
-
over =
|
|
345
|
+
var handleDragEnd = useMemoizedFn(function (_ref11) {
|
|
346
|
+
var active = _ref11.active,
|
|
347
|
+
over = _ref11.over;
|
|
345
348
|
resetState();
|
|
346
349
|
if (projected && over) {
|
|
347
350
|
var depth = projected.depth,
|
|
348
|
-
|
|
351
|
+
_parentId = projected.parentId;
|
|
349
352
|
|
|
350
353
|
// 检查目标父节点是否禁止拖入
|
|
351
|
-
var targetParent =
|
|
352
|
-
return item.id ===
|
|
354
|
+
var targetParent = _parentId ? flattenedItems.find(function (item) {
|
|
355
|
+
return item.id === _parentId;
|
|
353
356
|
}) : null;
|
|
354
357
|
if (targetParent !== null && targetParent !== void 0 && targetParent.disabledDrop) {
|
|
355
358
|
return;
|
|
356
359
|
}
|
|
357
360
|
|
|
361
|
+
// 获取拖拽元素和目标元素
|
|
362
|
+
var _dragItem = flattenedItems.find(function (item) {
|
|
363
|
+
return item.id === active.id;
|
|
364
|
+
});
|
|
365
|
+
var _dropTarget = flattenedItems.find(function (item) {
|
|
366
|
+
return item.id === over.id;
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
// 调用自定义拖拽判断函数
|
|
370
|
+
if (canDrop && _dragItem && _dropTarget) {
|
|
371
|
+
var canDropResult = canDrop(_dragItem, _dropTarget, _parentId, targetParent);
|
|
372
|
+
if (!canDropResult) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
358
377
|
// 检查是否超过最大层级限制
|
|
359
378
|
if (depth >= maxLevel) {
|
|
360
379
|
return;
|
|
@@ -366,84 +385,103 @@ export function SortableTree(_ref3) {
|
|
|
366
385
|
return;
|
|
367
386
|
}
|
|
368
387
|
var clonedItems = JSON.parse(JSON.stringify(flattenTree(items)));
|
|
369
|
-
var overIndex = clonedItems.findIndex(function (
|
|
370
|
-
var id =
|
|
388
|
+
var overIndex = clonedItems.findIndex(function (_ref12) {
|
|
389
|
+
var id = _ref12.id;
|
|
371
390
|
return id === over.id;
|
|
372
391
|
});
|
|
373
|
-
var activeIndex = clonedItems.findIndex(function (
|
|
374
|
-
var id =
|
|
392
|
+
var activeIndex = clonedItems.findIndex(function (_ref13) {
|
|
393
|
+
var id = _ref13.id;
|
|
375
394
|
return id === active.id;
|
|
376
395
|
});
|
|
377
396
|
var activeTreeItem = clonedItems[activeIndex];
|
|
378
397
|
clonedItems[activeIndex] = _objectSpread(_objectSpread({}, activeTreeItem), {}, {
|
|
379
398
|
depth: depth,
|
|
380
|
-
parentId:
|
|
399
|
+
parentId: _parentId
|
|
381
400
|
});
|
|
382
401
|
var sortedItems = arrayMove(clonedItems, activeIndex, overIndex);
|
|
383
402
|
var newItems = buildTree(sortedItems);
|
|
384
403
|
setItems(newItems);
|
|
385
404
|
onChange === null || onChange === void 0 || onChange(newItems);
|
|
386
405
|
}
|
|
387
|
-
}
|
|
388
|
-
function handleDragCancel() {
|
|
389
|
-
resetState();
|
|
390
|
-
}
|
|
391
|
-
function resetState() {
|
|
392
|
-
setOverId(null);
|
|
393
|
-
setActiveId(null);
|
|
394
|
-
setOffsetLeft(0);
|
|
395
|
-
document.body.style.setProperty('cursor', '');
|
|
396
|
-
}
|
|
406
|
+
});
|
|
397
407
|
|
|
398
|
-
/**
|
|
399
|
-
* 处理节点删除
|
|
400
|
-
* 从树形结构中移除指定节点
|
|
401
|
-
*/
|
|
402
|
-
function handleRemove(_x) {
|
|
403
|
-
return _handleRemove.apply(this, arguments);
|
|
404
|
-
}
|
|
405
408
|
/**
|
|
406
409
|
* 处理节点折叠/展开
|
|
407
410
|
* 切换指定节点的折叠状态
|
|
408
411
|
*/
|
|
409
|
-
function
|
|
410
|
-
_handleRemove = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(item) {
|
|
411
|
-
var res;
|
|
412
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
413
|
-
while (1) switch (_context.prev = _context.next) {
|
|
414
|
-
case 0:
|
|
415
|
-
if (!onRemoveBefore) {
|
|
416
|
-
_context.next = 6;
|
|
417
|
-
break;
|
|
418
|
-
}
|
|
419
|
-
_context.next = 3;
|
|
420
|
-
return onRemoveBefore === null || onRemoveBefore === void 0 ? void 0 : onRemoveBefore(item);
|
|
421
|
-
case 3:
|
|
422
|
-
res = _context.sent;
|
|
423
|
-
if (res) {
|
|
424
|
-
_context.next = 6;
|
|
425
|
-
break;
|
|
426
|
-
}
|
|
427
|
-
return _context.abrupt("return");
|
|
428
|
-
case 6:
|
|
429
|
-
setItems(function (items) {
|
|
430
|
-
return removeItem(items, item.id);
|
|
431
|
-
});
|
|
432
|
-
onChange === null || onChange === void 0 || onChange(items);
|
|
433
|
-
case 8:
|
|
434
|
-
case "end":
|
|
435
|
-
return _context.stop();
|
|
436
|
-
}
|
|
437
|
-
}, _callee);
|
|
438
|
-
}));
|
|
439
|
-
return _handleRemove.apply(this, arguments);
|
|
440
|
-
}
|
|
441
|
-
function handleCollapse(id) {
|
|
412
|
+
var handleCollapse = useMemoizedFn(function (id) {
|
|
442
413
|
setItems(function (items) {
|
|
443
|
-
|
|
414
|
+
var newVal = setProperty(items, id, 'collapsed', function (value) {
|
|
444
415
|
return !value;
|
|
445
416
|
});
|
|
417
|
+
onChange === null || onChange === void 0 || onChange(items);
|
|
418
|
+
return newVal;
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
var isError = useMemo(function () {
|
|
422
|
+
return !(canDrop !== null && canDrop !== void 0 && canDrop(activeItem || {}, {}, projected === null || projected === void 0 ? void 0 : projected.parentId, parentNode));
|
|
423
|
+
}, [projected, activeItem, canDrop, parentNode]);
|
|
424
|
+
var renderTreeItems = useMemo(function () {
|
|
425
|
+
return flattenedItems.map(function (item) {
|
|
426
|
+
var id = item.id,
|
|
427
|
+
children = item.children,
|
|
428
|
+
collapsed = item.collapsed,
|
|
429
|
+
depth = item.depth;
|
|
430
|
+
return /*#__PURE__*/React.createElement(SortableTreeItem, {
|
|
431
|
+
key: id,
|
|
432
|
+
id: id,
|
|
433
|
+
item: item,
|
|
434
|
+
depth: id === activeId && projected ? projected.depth : depth,
|
|
435
|
+
indentationWidth: indentationWidth,
|
|
436
|
+
indicator: indicator,
|
|
437
|
+
collapsed: Boolean(collapsed && (children === null || children === void 0 ? void 0 : children.length)),
|
|
438
|
+
onCollapse: collapsible && children !== null && children !== void 0 && children.length ? function () {
|
|
439
|
+
return handleCollapse(id);
|
|
440
|
+
} : undefined,
|
|
441
|
+
onRemove: removable ? function () {
|
|
442
|
+
return handleRemove(item);
|
|
443
|
+
} : undefined,
|
|
444
|
+
renderItem: _renderItem,
|
|
445
|
+
__designMode: __designMode
|
|
446
|
+
});
|
|
446
447
|
});
|
|
448
|
+
}, [flattenedItems, activeId, projected === null || projected === void 0 ? void 0 : projected.depth, indentationWidth, indicator, collapsible, handleCollapse, handleRemove, _renderItem, __designMode]);
|
|
449
|
+
return /*#__PURE__*/React.createElement(DndContext, {
|
|
450
|
+
sensors: sensors,
|
|
451
|
+
collisionDetection: closestCenter,
|
|
452
|
+
measuring: measuring,
|
|
453
|
+
onDragStart: handleDragStart,
|
|
454
|
+
onDragMove: handleDragMove,
|
|
455
|
+
onDragOver: handleDragOver,
|
|
456
|
+
onDragEnd: handleDragEnd,
|
|
457
|
+
onDragCancel: handleDragCancel
|
|
458
|
+
}, /*#__PURE__*/React.createElement(SortableContext, {
|
|
459
|
+
items: sortedIds,
|
|
460
|
+
strategy: verticalListSortingStrategy
|
|
461
|
+
}, renderTreeItems, /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement(DragOverlay, {
|
|
462
|
+
dropAnimation: dropAnimationConfig,
|
|
463
|
+
modifiers: indicator ? [adjustTranslate] : undefined
|
|
464
|
+
}, activeId && activeItem ? /*#__PURE__*/React.createElement(SortableTreeItem, {
|
|
465
|
+
id: activeId,
|
|
466
|
+
depth: activeItem.depth,
|
|
467
|
+
clone: true,
|
|
468
|
+
childCount: getChildCount(items, activeId) + 1,
|
|
469
|
+
item: activeItem,
|
|
470
|
+
indentationWidth: indentationWidth,
|
|
471
|
+
renderItem: function renderItem(props, ref) {
|
|
472
|
+
return _renderItem === null || _renderItem === void 0 ? void 0 : _renderItem(_objectSpread(_objectSpread({}, props), {}, {
|
|
473
|
+
isError: isError
|
|
474
|
+
}), ref);
|
|
475
|
+
}
|
|
476
|
+
}) : null), document.body)));
|
|
477
|
+
function handleDragCancel() {
|
|
478
|
+
resetState();
|
|
479
|
+
}
|
|
480
|
+
function resetState() {
|
|
481
|
+
setOverId(null);
|
|
482
|
+
setActiveId(null);
|
|
483
|
+
setOffsetLeft(0);
|
|
484
|
+
document.body.style.setProperty('cursor', '');
|
|
447
485
|
}
|
|
448
486
|
}
|
|
449
487
|
|
|
@@ -451,8 +489,8 @@ export function SortableTree(_ref3) {
|
|
|
451
489
|
* 调整拖拽项的位置
|
|
452
490
|
* 对拖拽时的位置进行微调,提升视觉效果
|
|
453
491
|
*/
|
|
454
|
-
var adjustTranslate = function adjustTranslate(
|
|
455
|
-
var transform =
|
|
492
|
+
var adjustTranslate = function adjustTranslate(_ref14) {
|
|
493
|
+
var transform = _ref14.transform;
|
|
456
494
|
return _objectSpread(_objectSpread({}, transform), {}, {
|
|
457
495
|
y: transform.y - 25
|
|
458
496
|
});
|