zs_library 0.2.0 → 0.2.2
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/dist/Desktop/ContextMenu/index.d.ts +12 -2
- package/dist/Desktop/ContextMenu/index.js +45 -18
- package/dist/Desktop/Items/GroupItem.js +17 -14
- package/dist/Desktop/Items/Modal/GroupItemModal.d.ts +0 -1
- package/dist/Desktop/Items/Modal/GroupItemModal.js +13 -13
- package/dist/Desktop/Items/SortableItem.d.ts +0 -1
- package/dist/Desktop/Items/SortableItem.js +16 -11
- package/dist/Desktop/Sortable.d.ts +5 -22
- package/dist/Desktop/Sortable.js +56 -35
- package/dist/Desktop/context/config/context.d.ts +44 -0
- package/dist/Desktop/context/config/context.js +36 -0
- package/dist/Desktop/context/config/hooks.d.ts +1 -0
- package/dist/Desktop/context/config/hooks.js +6 -0
- package/dist/Desktop/{context.d.ts → context/state/context.d.ts} +22 -12
- package/dist/Desktop/{context.js → context/state/context.js} +52 -28
- package/dist/Desktop/context/state/hooks.d.ts +1 -0
- package/dist/Desktop/context/state/hooks.js +6 -0
- package/dist/Desktop/index.d.ts +3 -24
- package/dist/Desktop/index.js +24 -6
- package/package.json +1 -1
- package/dist/Desktop/hook.d.ts +0 -1
- package/dist/Desktop/hook.js +0 -6
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SortItem } from '../types';
|
|
3
|
+
export interface ContextMenuProps<D, C> {
|
|
4
|
+
showShareButton?: boolean;
|
|
5
|
+
showInfoButton?: boolean;
|
|
6
|
+
showRemoveButton?: boolean;
|
|
7
|
+
showSizeButton?: boolean;
|
|
8
|
+
onShareClick?: (item: SortItem<D, C>) => void;
|
|
9
|
+
onInfoClick?: (item: SortItem<D, C>) => void;
|
|
10
|
+
onRemoveClick?: (item: SortItem<D, C>, remove: (id: string) => void) => void;
|
|
11
|
+
}
|
|
12
|
+
declare const ContextMenu: <D, C>(props: ContextMenuProps<D, C>) => React.JSX.Element;
|
|
3
13
|
export default ContextMenu;
|
|
@@ -19,7 +19,8 @@ import { RiCloseCircleLine, RiInformationLine, RiPencilRuler2Line, RiShareLine }
|
|
|
19
19
|
import { AnimatePresence, motion } from 'framer-motion';
|
|
20
20
|
import React from 'react';
|
|
21
21
|
import { configMap } from "../config";
|
|
22
|
-
import {
|
|
22
|
+
import { useSortableConfig } from "../context/config/hooks";
|
|
23
|
+
import { useSortableState } from "../context/state/hooks";
|
|
23
24
|
import SortableUtils from "../utils";
|
|
24
25
|
var itemVariants = {
|
|
25
26
|
menuShow: {
|
|
@@ -43,8 +44,8 @@ var ContextButton = function ContextButton(props) {
|
|
|
43
44
|
var icon = props.icon,
|
|
44
45
|
title = props.title,
|
|
45
46
|
_onClick = props.onClick;
|
|
46
|
-
var
|
|
47
|
-
theme =
|
|
47
|
+
var _useSortableConfig = useSortableConfig(),
|
|
48
|
+
theme = _useSortableConfig.theme;
|
|
48
49
|
var _SortableUtils$getThe = SortableUtils.getTheme(theme),
|
|
49
50
|
light = _SortableUtils$getThe.light,
|
|
50
51
|
dark = _SortableUtils$getThe.dark;
|
|
@@ -64,15 +65,27 @@ var ContextButton = function ContextButton(props) {
|
|
|
64
65
|
className: cx(css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n margin-bottom: 0.375rem;\n display: flex;\n justify-content: center;\n "]))))
|
|
65
66
|
}, icon), /*#__PURE__*/React.createElement(motion.div, null, title)));
|
|
66
67
|
};
|
|
67
|
-
var ContextMenu = function ContextMenu() {
|
|
68
|
-
var
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
var ContextMenu = function ContextMenu(props) {
|
|
69
|
+
var _props$showInfoButton = props.showInfoButton,
|
|
70
|
+
showInfoButton = _props$showInfoButton === void 0 ? true : _props$showInfoButton,
|
|
71
|
+
_props$showRemoveButt = props.showRemoveButton,
|
|
72
|
+
showRemoveButton = _props$showRemoveButt === void 0 ? true : _props$showRemoveButt,
|
|
73
|
+
_props$showShareButto = props.showShareButton,
|
|
74
|
+
showShareButton = _props$showShareButto === void 0 ? true : _props$showShareButto,
|
|
75
|
+
_props$showSizeButton = props.showSizeButton,
|
|
76
|
+
showSizeButton = _props$showSizeButton === void 0 ? true : _props$showSizeButton,
|
|
77
|
+
onInfoClick = props.onInfoClick,
|
|
78
|
+
onShareClick = props.onShareClick,
|
|
79
|
+
onRemoveClick = props.onRemoveClick;
|
|
80
|
+
var _useSortableState = useSortableState(),
|
|
81
|
+
contextMenu = _useSortableState.contextMenu,
|
|
82
|
+
setContextMenu = _useSortableState.setContextMenu,
|
|
83
|
+
hideContextMenu = _useSortableState.hideContextMenu,
|
|
84
|
+
setShowInfoItemData = _useSortableState.setShowInfoItemData,
|
|
85
|
+
removeItem = _useSortableState.removeItem,
|
|
86
|
+
updateItemConfig = _useSortableState.updateItemConfig;
|
|
87
|
+
var _useSortableConfig2 = useSortableConfig(),
|
|
88
|
+
theme = _useSortableConfig2.theme;
|
|
76
89
|
var _SortableUtils$getThe2 = SortableUtils.getTheme(theme),
|
|
77
90
|
light = _SortableUtils$getThe2.light,
|
|
78
91
|
dark = _SortableUtils$getThe2.dark;
|
|
@@ -110,7 +123,7 @@ var ContextMenu = function ContextMenu() {
|
|
|
110
123
|
}
|
|
111
124
|
}, /*#__PURE__*/React.createElement(motion.div, {
|
|
112
125
|
className: cx(css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n border-radius: 0.5rem;\n overflow: hidden;\n background-color: ", ";\n box-shadow: 0 0 0.5rem ", ";\n @media (prefers-color-scheme: dark) {\n background-color: ", ";\n box-shadow: 0 0 0.5rem ", ";\n }\n "])), light.contextMenuBackgroundColor, light.contextMenuShadowColor, dark.contextMenuBackgroundColor, dark.contextMenuShadowColor))
|
|
113
|
-
}, config.allowResize !== false && /*#__PURE__*/React.createElement(motion.ul, {
|
|
126
|
+
}, showSizeButton && config.allowResize !== false && /*#__PURE__*/React.createElement(motion.ul, {
|
|
114
127
|
className: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n background-color: white;\n padding: 0.25rem;\n margin: 0;\n "])))
|
|
115
128
|
}, [{
|
|
116
129
|
label: '修改大小',
|
|
@@ -150,30 +163,44 @@ var ContextMenu = function ContextMenu() {
|
|
|
150
163
|
}, it.label);
|
|
151
164
|
})));
|
|
152
165
|
}))), /*#__PURE__*/React.createElement(motion.div, {
|
|
153
|
-
className: cx(css(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["\n background-color: ", ";\n box-shadow: 0 0 0.5rem ", ";\n @media (prefers-color-scheme: dark) {\n background-color: ", ";\n box-shadow: 0 0 0.5rem ", ";\n }\n display: flex;\n margin-top: 0.5rem;\n border-radius: 0.5rem;\n overflow: hidden;\n padding: 0.25rem;\n "])), light.contextMenuBackgroundColor, light.contextMenuShadowColor, dark.contextMenuBackgroundColor, dark.contextMenuShadowColor))
|
|
154
|
-
}, /*#__PURE__*/React.createElement(ContextButton, {
|
|
166
|
+
className: cx(css(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["\n background-color: ", ";\n box-shadow: 0 0 0.5rem ", ";\n @media (prefers-color-scheme: dark) {\n background-color: ", ";\n box-shadow: 0 0 0.5rem ", ";\n }\n display: flex;\n justify-content: space-around;\n align-items: center;\n margin-top: 0.5rem;\n border-radius: 0.5rem;\n overflow: hidden;\n padding: 0.25rem;\n "])), light.contextMenuBackgroundColor, light.contextMenuShadowColor, dark.contextMenuBackgroundColor, dark.contextMenuShadowColor))
|
|
167
|
+
}, showShareButton && /*#__PURE__*/React.createElement(ContextButton, {
|
|
155
168
|
icon: /*#__PURE__*/React.createElement(RiShareLine, {
|
|
156
169
|
size: 20
|
|
157
170
|
}),
|
|
158
|
-
title: "\u5206\u4EAB"
|
|
159
|
-
|
|
171
|
+
title: "\u5206\u4EAB",
|
|
172
|
+
onClick: function onClick() {
|
|
173
|
+
if (onShareClick) {
|
|
174
|
+
onShareClick(contextMenu.data);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}), showInfoButton && /*#__PURE__*/React.createElement(ContextButton, {
|
|
160
179
|
icon: /*#__PURE__*/React.createElement(RiInformationLine, {
|
|
161
180
|
size: 20
|
|
162
181
|
}),
|
|
163
182
|
title: "\u4FE1\u606F",
|
|
164
183
|
onClick: function onClick() {
|
|
184
|
+
if (onInfoClick) {
|
|
185
|
+
onInfoClick(contextMenu.data);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
165
188
|
setShowInfoItemData(_objectSpread(_objectSpread({}, contextMenu.data), {}, {
|
|
166
189
|
pageX: contextMenu.pageX,
|
|
167
190
|
pageY: contextMenu.pageY
|
|
168
191
|
}));
|
|
169
192
|
hideContextMenu();
|
|
170
193
|
}
|
|
171
|
-
}), /*#__PURE__*/React.createElement(ContextButton, {
|
|
194
|
+
}), showRemoveButton && /*#__PURE__*/React.createElement(ContextButton, {
|
|
172
195
|
icon: /*#__PURE__*/React.createElement(RiCloseCircleLine, {
|
|
173
196
|
size: 20
|
|
174
197
|
}),
|
|
175
198
|
title: "\u79FB\u9664",
|
|
176
199
|
onClick: function onClick() {
|
|
200
|
+
if (onRemoveClick) {
|
|
201
|
+
onRemoveClick(contextMenu.data, removeItem);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
177
204
|
setContextMenu(null);
|
|
178
205
|
removeItem(contextMenu.data.id);
|
|
179
206
|
}
|
|
@@ -11,7 +11,8 @@ import { css, cx } from '@emotion/css';
|
|
|
11
11
|
import { motion } from 'framer-motion';
|
|
12
12
|
import React, { useMemo } from 'react';
|
|
13
13
|
import { ReactSortable } from 'react-sortablejs';
|
|
14
|
-
import {
|
|
14
|
+
import { useSortableConfig } from "../context/config/hooks";
|
|
15
|
+
import { useSortableState } from "../context/state/hooks";
|
|
15
16
|
import SortableUtils from "../utils";
|
|
16
17
|
import SortableItem from "./SortableItem";
|
|
17
18
|
var SortableGroupItem = function SortableGroupItem(props) {
|
|
@@ -22,18 +23,20 @@ var SortableGroupItem = function SortableGroupItem(props) {
|
|
|
22
23
|
itemIndex = props.itemIndex,
|
|
23
24
|
_onClick = props.onClick,
|
|
24
25
|
_props$noLetters = props.noLetters,
|
|
25
|
-
noLetters = _props$noLetters === void 0 ? false : _props$noLetters
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
noLetters = _props$noLetters === void 0 ? false : _props$noLetters;
|
|
27
|
+
var _useSortableState = useSortableState(),
|
|
28
|
+
contextMenuFuns = _useSortableState.contextMenuFuns,
|
|
29
|
+
_setList = _useSortableState.setList,
|
|
30
|
+
setOpenGroupItemData = _useSortableState.setOpenGroupItemData,
|
|
31
|
+
longPressTriggered = _useSortableState.longPressTriggered,
|
|
32
|
+
moveItemId = _useSortableState.moveItemId,
|
|
33
|
+
moveTargetId = _useSortableState.moveTargetId,
|
|
34
|
+
setMoveTargetId = _useSortableState.setMoveTargetId,
|
|
35
|
+
listStatus = _useSortableState.listStatus;
|
|
36
|
+
var _useSortableConfig = useSortableConfig(),
|
|
37
|
+
itemIconBuilder = _useSortableConfig.itemIconBuilder,
|
|
38
|
+
theme = _useSortableConfig.theme,
|
|
39
|
+
contextMenu = _useSortableConfig.contextMenu;
|
|
37
40
|
var _SortableUtils$getThe = SortableUtils.getTheme(theme),
|
|
38
41
|
light = _SortableUtils$getThe.light,
|
|
39
42
|
dark = _SortableUtils$getThe.dark;
|
|
@@ -143,7 +146,7 @@ var SortableGroupItem = function SortableGroupItem(props) {
|
|
|
143
146
|
setOpenGroupItemData(data);
|
|
144
147
|
}
|
|
145
148
|
}
|
|
146
|
-
}, contextMenuFuns(data)), /*#__PURE__*/React.createElement(motion.div, {
|
|
149
|
+
}, contextMenuFuns(data, contextMenu !== false)), /*#__PURE__*/React.createElement(motion.div, {
|
|
147
150
|
className: css(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["\n position: relative;\n width: 100%;\n height: 100%;\n display: flex;\n justify-content: center;\n align-items: center;\n padding: 0.375rem;\n "])))
|
|
148
151
|
}, sizedContent(), /*#__PURE__*/React.createElement(ReactSortable, {
|
|
149
152
|
className: cx('sortable-group-item', css(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["\n position: absolute;\n cursor: pointer;\n left: 0.375rem;\n top: 0.375rem;\n width: calc(100% - 0.75rem);\n height: calc(100% - 0.75rem);\n pointer-events: ", ";\n > * {\n opacity: 0;\n }\n "])), listStatus === null ? 'none' : 'auto')),
|
|
@@ -4,7 +4,6 @@ interface GroupItemModalProps<D, C> {
|
|
|
4
4
|
data: SortItem | null;
|
|
5
5
|
onClose: () => void;
|
|
6
6
|
onItemClick?: (item: SortItem<D, C>) => void;
|
|
7
|
-
itemIconBuilder?: (item: SortItem<D, C>) => React.ReactNode;
|
|
8
7
|
}
|
|
9
8
|
declare const GroupItemModal: <D, C>(props: GroupItemModalProps<D, C>) => React.JSX.Element;
|
|
10
9
|
export default GroupItemModal;
|
|
@@ -22,7 +22,8 @@ import { css, cx } from '@emotion/css';
|
|
|
22
22
|
import Dialog from 'rc-dialog';
|
|
23
23
|
import React, { useEffect, useState } from 'react';
|
|
24
24
|
import { ReactSortable } from 'react-sortablejs';
|
|
25
|
-
import {
|
|
25
|
+
import { useSortableConfig } from "../../context/config/hooks";
|
|
26
|
+
import { useSortableState } from "../../context/state/hooks";
|
|
26
27
|
import { ghostClass } from "../../style";
|
|
27
28
|
import SortableUtils from "../../utils";
|
|
28
29
|
import SortableItem from "../SortableItem";
|
|
@@ -30,16 +31,16 @@ var GroupItemModal = function GroupItemModal(props) {
|
|
|
30
31
|
var _data$children, _data$children2;
|
|
31
32
|
var data = props.data,
|
|
32
33
|
_onClose = props.onClose,
|
|
33
|
-
onItemClick = props.onItemClick
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
theme =
|
|
34
|
+
onItemClick = props.onItemClick;
|
|
35
|
+
var _useSortableState = useSortableState(),
|
|
36
|
+
list = _useSortableState.list,
|
|
37
|
+
_setList = _useSortableState.setList,
|
|
38
|
+
setListStatus = _useSortableState.setListStatus,
|
|
39
|
+
setMoveItemId = _useSortableState.setMoveItemId,
|
|
40
|
+
setMoveTargetId = _useSortableState.setMoveTargetId,
|
|
41
|
+
updateItem = _useSortableState.updateItem;
|
|
42
|
+
var _useSortableConfig = useSortableConfig(),
|
|
43
|
+
theme = _useSortableConfig.theme;
|
|
43
44
|
var _SortableUtils$getThe = SortableUtils.getTheme(theme),
|
|
44
45
|
light = _SortableUtils$getThe.light,
|
|
45
46
|
dark = _SortableUtils$getThe.dark;
|
|
@@ -151,8 +152,7 @@ var GroupItemModal = function GroupItemModal(props) {
|
|
|
151
152
|
key: item.id,
|
|
152
153
|
data: item,
|
|
153
154
|
itemIndex: index,
|
|
154
|
-
onClick: onItemClick
|
|
155
|
-
itemIconBuilder: itemIconBuilder
|
|
155
|
+
onClick: onItemClick
|
|
156
156
|
});
|
|
157
157
|
}))));
|
|
158
158
|
};
|
|
@@ -11,7 +11,6 @@ export interface SortableItemProps<D, C> {
|
|
|
11
11
|
children?: React.ReactNode;
|
|
12
12
|
parentIds?: (string | number)[];
|
|
13
13
|
childrenLength?: number;
|
|
14
|
-
itemIconBuilder?: (item: SortItem<D, C>) => React.ReactNode;
|
|
15
14
|
}
|
|
16
15
|
export declare const SortableItemDefaultContent: <D, C>(props: SortableItemProps<D, C>) => React.JSX.Element;
|
|
17
16
|
declare const SortableItem: <D, C>(props: SortableItemProps<D, C>) => React.JSX.Element;
|
|
@@ -7,16 +7,19 @@ import RcTooltip from 'rc-tooltip';
|
|
|
7
7
|
import 'rc-tooltip/assets/bootstrap_white.css';
|
|
8
8
|
import React from 'react';
|
|
9
9
|
import ContextMenu from "../ContextMenu";
|
|
10
|
-
import {
|
|
10
|
+
import { useSortableConfig } from "../context/config/hooks";
|
|
11
|
+
import { useSortableState } from "../context/state/hooks";
|
|
11
12
|
import SortableUtils from "../utils";
|
|
12
13
|
export var SortableItemDefaultContent = function SortableItemDefaultContent(props) {
|
|
13
14
|
var data = props.data,
|
|
14
15
|
_props$noLetters = props.noLetters,
|
|
15
|
-
noLetters = _props$noLetters === void 0 ? false : _props$noLetters
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
noLetters = _props$noLetters === void 0 ? false : _props$noLetters;
|
|
17
|
+
var _useSortableState = useSortableState(),
|
|
18
|
+
contextMenuFuns = _useSortableState.contextMenuFuns;
|
|
19
|
+
var _useSortableConfig = useSortableConfig(),
|
|
20
|
+
itemIconBuilder = _useSortableConfig.itemIconBuilder,
|
|
21
|
+
theme = _useSortableConfig.theme,
|
|
22
|
+
contextMenu = _useSortableConfig.contextMenu;
|
|
20
23
|
var _SortableUtils$getThe = SortableUtils.getTheme(theme),
|
|
21
24
|
light = _SortableUtils$getThe.light,
|
|
22
25
|
dark = _SortableUtils$getThe.dark;
|
|
@@ -31,7 +34,7 @@ export var SortableItemDefaultContent = function SortableItemDefaultContent(prop
|
|
|
31
34
|
}
|
|
32
35
|
}, /*#__PURE__*/React.createElement("div", _extends({
|
|
33
36
|
className: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n color: ", ";\n @media (prefers-color-scheme: dark) {\n color: ", ";\n }\n "])), light.itemNameColor, dark.itemNameColor)
|
|
34
|
-
}, contextMenuFuns(data)), itemIconBuilder === null || itemIconBuilder === void 0 ? void 0 : itemIconBuilder(data))), /*#__PURE__*/React.createElement(motion.p, {
|
|
37
|
+
}, contextMenuFuns(data, contextMenu !== false)), itemIconBuilder === null || itemIconBuilder === void 0 ? void 0 : itemIconBuilder(data))), /*#__PURE__*/React.createElement(motion.p, {
|
|
35
38
|
className: cx(css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n text-align: center;\n margin-top: 0.25rem;\n margin-bottom: 0;\n color: ", ";\n @media (prefers-color-scheme: dark) {\n color: ", ";\n }\n "])), light.itemNameColor, dark.itemNameColor), noLetters && css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n color: transparent;\n "]))))
|
|
36
39
|
}, name));
|
|
37
40
|
};
|
|
@@ -45,13 +48,15 @@ var SortableItem = function SortableItem(props) {
|
|
|
45
48
|
children = props.children,
|
|
46
49
|
parentIds = props.parentIds,
|
|
47
50
|
childrenLength = props.childrenLength;
|
|
48
|
-
var
|
|
49
|
-
contextMenu =
|
|
50
|
-
setContextMenu =
|
|
51
|
+
var _useSortableState2 = useSortableState(),
|
|
52
|
+
contextMenu = _useSortableState2.contextMenu,
|
|
53
|
+
setContextMenu = _useSortableState2.setContextMenu;
|
|
54
|
+
var _useSortableConfig2 = useSortableConfig(),
|
|
55
|
+
configContextMenu = _useSortableConfig2.contextMenu;
|
|
51
56
|
return /*#__PURE__*/React.createElement(RcTooltip, {
|
|
52
57
|
placement: "bottom",
|
|
53
58
|
overlayClassName: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n background-color: transparent;\n .rc-tooltip-inner {\n background-color: transparent;\n padding: 0;\n border: none;\n }\n "]))),
|
|
54
|
-
overlay: /*#__PURE__*/React.createElement(ContextMenu,
|
|
59
|
+
overlay: /*#__PURE__*/React.createElement(ContextMenu, configContextMenu),
|
|
55
60
|
visible: (contextMenu === null || contextMenu === void 0 ? void 0 : contextMenu.data.id) === data.id,
|
|
56
61
|
onVisibleChange: function onVisibleChange(visible) {
|
|
57
62
|
if (!visible) {
|
|
@@ -3,15 +3,18 @@ import Slider, { Settings } from 'react-slick';
|
|
|
3
3
|
import 'slick-carousel/slick/slick-theme.css';
|
|
4
4
|
import 'slick-carousel/slick/slick.css';
|
|
5
5
|
import { SortItem } from './types';
|
|
6
|
+
export interface Pagination {
|
|
7
|
+
position?: 'top' | 'bottom' | 'left' | 'right';
|
|
8
|
+
}
|
|
6
9
|
export interface SortableProps<D, C> {
|
|
7
10
|
/**
|
|
8
11
|
* className
|
|
9
12
|
*/
|
|
10
13
|
className?: string;
|
|
11
14
|
/**
|
|
12
|
-
*
|
|
15
|
+
* 分页
|
|
13
16
|
*/
|
|
14
|
-
|
|
17
|
+
pagination?: Pagination | false;
|
|
15
18
|
/**
|
|
16
19
|
* slider ref
|
|
17
20
|
*/
|
|
@@ -21,30 +24,10 @@ export interface SortableProps<D, C> {
|
|
|
21
24
|
* @see https://react-slick.neostack.com/docs/api
|
|
22
25
|
*/
|
|
23
26
|
sliderProps?: Omit<Settings, 'appendDots' | 'customPaging'>;
|
|
24
|
-
/**
|
|
25
|
-
* 是否不显示名称
|
|
26
|
-
*/
|
|
27
|
-
noLetters?: boolean;
|
|
28
27
|
/**
|
|
29
28
|
* 点击 item 事件
|
|
30
29
|
*/
|
|
31
30
|
onItemClick?: (item: SortItem<D, C>) => void;
|
|
32
|
-
/**
|
|
33
|
-
* 自定义分页点容器
|
|
34
|
-
*/
|
|
35
|
-
pagingDotsBuilder?: (dots: React.ReactNode) => React.JSX.Element;
|
|
36
|
-
/**
|
|
37
|
-
* 自定义分页点
|
|
38
|
-
*/
|
|
39
|
-
pagingDotBuilder?: (item: SortItem<D, C>, index: number) => React.JSX.Element;
|
|
40
|
-
/**
|
|
41
|
-
* 自定义 item 渲染
|
|
42
|
-
*/
|
|
43
|
-
itemBuilder?: (item: SortItem<D, C>) => React.ReactNode;
|
|
44
|
-
/**
|
|
45
|
-
* 自定义 item 图标渲染
|
|
46
|
-
*/
|
|
47
|
-
itemIconBuilder?: (item: SortItem<D, C>) => React.ReactNode;
|
|
48
31
|
}
|
|
49
32
|
declare const Sortable: <D, C>(props: SortableProps<D, C>) => React.JSX.Element;
|
|
50
33
|
export default Sortable;
|
package/dist/Desktop/Sortable.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
|
|
1
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7;
|
|
2
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
3
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
4
4
|
import { css, cx } from '@emotion/css';
|
|
@@ -11,48 +11,57 @@ import SortableGroupItem from "./Items/GroupItem";
|
|
|
11
11
|
import GroupItemModal from "./Items/Modal/GroupItemModal";
|
|
12
12
|
import ItemInfoModal from "./Items/Modal/InfoModal";
|
|
13
13
|
import SortableItem from "./Items/SortableItem";
|
|
14
|
-
import {
|
|
14
|
+
import { useSortableConfig } from "./context/config/hooks";
|
|
15
|
+
import { useSortableState } from "./context/state/hooks";
|
|
15
16
|
import { ghostClass } from "./style";
|
|
16
17
|
var Sortable = function Sortable(props) {
|
|
17
|
-
var _props$
|
|
18
|
-
|
|
18
|
+
var _props$pagination = props.pagination,
|
|
19
|
+
pagination = _props$pagination === void 0 ? {
|
|
20
|
+
position: 'bottom'
|
|
21
|
+
} : _props$pagination,
|
|
19
22
|
className = props.className,
|
|
20
|
-
pagingDotBuilder = props.pagingDotBuilder,
|
|
21
|
-
pagingDotsBuilder = props.pagingDotsBuilder,
|
|
22
23
|
sliderProps = props.sliderProps,
|
|
23
24
|
_sliderRef = props.sliderRef,
|
|
24
|
-
onItemClick = props.onItemClick
|
|
25
|
-
noLetters = props.noLetters,
|
|
26
|
-
itemBuilder = props.itemBuilder,
|
|
27
|
-
itemIconBuilder = props.itemIconBuilder;
|
|
25
|
+
onItemClick = props.onItemClick;
|
|
28
26
|
var sliderRef = useRef(null);
|
|
29
27
|
var sliderDotsRef = useRef(null);
|
|
30
|
-
var
|
|
31
|
-
list =
|
|
32
|
-
_setList =
|
|
33
|
-
setListStatus =
|
|
34
|
-
showInfoItemData =
|
|
35
|
-
setShowInfoItemData =
|
|
36
|
-
openGroupItemData =
|
|
37
|
-
setOpenGroupItemData =
|
|
38
|
-
setMoveItemId =
|
|
39
|
-
setMoveTargetId =
|
|
28
|
+
var _useSortableState = useSortableState(),
|
|
29
|
+
list = _useSortableState.list,
|
|
30
|
+
_setList = _useSortableState.setList,
|
|
31
|
+
setListStatus = _useSortableState.setListStatus,
|
|
32
|
+
showInfoItemData = _useSortableState.showInfoItemData,
|
|
33
|
+
setShowInfoItemData = _useSortableState.setShowInfoItemData,
|
|
34
|
+
openGroupItemData = _useSortableState.openGroupItemData,
|
|
35
|
+
setOpenGroupItemData = _useSortableState.setOpenGroupItemData,
|
|
36
|
+
setMoveItemId = _useSortableState.setMoveItemId,
|
|
37
|
+
setMoveTargetId = _useSortableState.setMoveTargetId,
|
|
38
|
+
addItem = _useSortableState.addItem;
|
|
39
|
+
var _useSortableConfig = useSortableConfig(),
|
|
40
|
+
pagingDotBuilder = _useSortableConfig.pagingDotBuilder,
|
|
41
|
+
pagingDotsBuilder = _useSortableConfig.pagingDotsBuilder,
|
|
42
|
+
itemBuilder = _useSortableConfig.itemBuilder;
|
|
40
43
|
var paginingLocationCss = useMemo(function () {
|
|
44
|
+
var _pagination$position;
|
|
45
|
+
if (pagination === false) {
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
41
48
|
return {
|
|
42
49
|
top: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: column;\n .slick-list {\n order: 1;\n }\n .slick-dots {\n position: static;\n }\n "]))),
|
|
43
50
|
bottom: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n .slick-dots {\n position: static;\n }\n "]))),
|
|
44
51
|
left: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n .slick-dots {\n position: absolute;\n width: auto;\n left: 0;\n top: 0;\n bottom: 0;\n transform: translateX(-100%);\n display: flex;\n justify-content: center;\n align-items: center;\n .slick-dots-default {\n flex-direction: column;\n }\n }\n "]))),
|
|
45
52
|
right: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n .slick-dots {\n position: absolute;\n width: auto;\n right: 0;\n top: 0;\n bottom: 0;\n transform: translateX(100%);\n display: flex;\n justify-content: center;\n align-items: center;\n .slick-dots-default {\n flex-direction: column;\n }\n }\n "])))
|
|
46
|
-
}[
|
|
47
|
-
}, [
|
|
48
|
-
return /*#__PURE__*/React.createElement(
|
|
53
|
+
}[(_pagination$position = pagination.position) !== null && _pagination$position !== void 0 ? _pagination$position : 'bottom'];
|
|
54
|
+
}, [pagination]);
|
|
55
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Slider, _extends({
|
|
56
|
+
useCSS: true,
|
|
57
|
+
useTransform: true,
|
|
49
58
|
arrows: false,
|
|
50
59
|
ref: _sliderRef !== null && _sliderRef !== void 0 ? _sliderRef : sliderRef,
|
|
51
60
|
infinite: false,
|
|
52
61
|
dots: true,
|
|
53
62
|
touchMove: false,
|
|
54
63
|
lazyLoad: "anticipated",
|
|
55
|
-
className: cx(paginingLocationCss, className),
|
|
64
|
+
className: cx(paginingLocationCss, css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n .slick-track {\n display: flex;\n align-items: stretch;\n }\n .slick-slide {\n display: flex;\n align-self: stretch;\n height: unset;\n > div {\n display: flex;\n align-self: stretch;\n width: 100%;\n }\n }\n "]))), className),
|
|
56
65
|
customPaging: function customPaging(i) {
|
|
57
66
|
var _list$i;
|
|
58
67
|
if (pagingDotBuilder) {
|
|
@@ -69,17 +78,34 @@ var Sortable = function Sortable(props) {
|
|
|
69
78
|
if (pagingDotsBuilder) {
|
|
70
79
|
return pagingDotsBuilder(dots);
|
|
71
80
|
}
|
|
81
|
+
if (pagination === false) {
|
|
82
|
+
return /*#__PURE__*/React.createElement("div", null);
|
|
83
|
+
}
|
|
72
84
|
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("ul", {
|
|
73
85
|
ref: sliderDotsRef,
|
|
74
|
-
className: cx('slick-dots-default', css(
|
|
86
|
+
className: cx('slick-dots-default', css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n padding: 0.5rem;\n display: inline-flex;\n justify-content: center;\n align-items: center;\n gap: 0.5rem;\n background-color: rgba(0, 0, 0, 0.1);\n border-radius: 0.5rem;\n .slick-active {\n background-color: rgba(0, 0, 0, 0.3);\n color: white;\n padding: 0.25rem;\n border-radius: 0.25rem;\n }\n li {\n margin: 0;\n width: auto;\n height: auto;\n }\n "]))))
|
|
75
87
|
}, dots));
|
|
76
88
|
}
|
|
77
89
|
}, sliderProps), list.map(function (l) {
|
|
78
90
|
var _l$children, _l$children2;
|
|
79
91
|
return /*#__PURE__*/React.createElement("div", {
|
|
80
|
-
key: l.id
|
|
92
|
+
key: l.id,
|
|
93
|
+
onDrop: function onDrop(e) {
|
|
94
|
+
e.preventDefault();
|
|
95
|
+
var data = e.dataTransfer.getData('text/plain');
|
|
96
|
+
if (data !== '') {
|
|
97
|
+
try {
|
|
98
|
+
addItem(JSON.parse(data), [l.id]);
|
|
99
|
+
} catch (e) {
|
|
100
|
+
console.log('drag error', e);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
onDragOver: function onDragOver(e) {
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
}
|
|
81
107
|
}, /*#__PURE__*/React.createElement(ReactSortable, {
|
|
82
|
-
className: cx(css(
|
|
108
|
+
className: cx(css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n display: grid;\n transition: all 0.3s;\n grid-template-columns: repeat(auto-fill, 96px);\n grid-auto-flow: dense;\n grid-auto-rows: 96px;\n place-items: center;\n justify-content: center;\n align-items: center;\n "])))),
|
|
83
109
|
animation: 150,
|
|
84
110
|
fallbackOnBody: true,
|
|
85
111
|
swapThreshold: 0.65,
|
|
@@ -129,9 +155,7 @@ var Sortable = function Sortable(props) {
|
|
|
129
155
|
data: item,
|
|
130
156
|
itemIndex: index,
|
|
131
157
|
parentIds: [l.id, item.id],
|
|
132
|
-
onClick: onItemClick
|
|
133
|
-
noLetters: noLetters,
|
|
134
|
-
itemIconBuilder: itemIconBuilder
|
|
158
|
+
onClick: onItemClick
|
|
135
159
|
});
|
|
136
160
|
break;
|
|
137
161
|
default:
|
|
@@ -139,9 +163,7 @@ var Sortable = function Sortable(props) {
|
|
|
139
163
|
key: item.id,
|
|
140
164
|
data: item,
|
|
141
165
|
itemIndex: index,
|
|
142
|
-
onClick: onItemClick
|
|
143
|
-
noLetters: noLetters,
|
|
144
|
-
itemIconBuilder: itemIconBuilder
|
|
166
|
+
onClick: onItemClick
|
|
145
167
|
});
|
|
146
168
|
break;
|
|
147
169
|
}
|
|
@@ -157,8 +179,7 @@ var Sortable = function Sortable(props) {
|
|
|
157
179
|
onClose: function onClose() {
|
|
158
180
|
setOpenGroupItemData(null);
|
|
159
181
|
},
|
|
160
|
-
onItemClick: onItemClick
|
|
161
|
-
itemIconBuilder: itemIconBuilder
|
|
182
|
+
onItemClick: onItemClick
|
|
162
183
|
}));
|
|
163
184
|
};
|
|
164
185
|
export default Sortable;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ContextMenuProps } from '../../ContextMenu';
|
|
3
|
+
import { Theme } from '../../theme';
|
|
4
|
+
import { SortItem } from '../../types';
|
|
5
|
+
/**
|
|
6
|
+
* 需要跨多个组件传递的配置,使用 context 传递
|
|
7
|
+
*/
|
|
8
|
+
export interface SortableConfig<D, C> {
|
|
9
|
+
theme?: Theme;
|
|
10
|
+
/**
|
|
11
|
+
* 是否不显示名称
|
|
12
|
+
*/
|
|
13
|
+
noLetters?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* 右键菜单设置
|
|
16
|
+
*/
|
|
17
|
+
contextMenu?: ContextMenuProps<D, C> | ((data: SortItem<D, C>) => ContextMenuProps<D, C> | false) | false;
|
|
18
|
+
/**
|
|
19
|
+
* 自定义分页点容器
|
|
20
|
+
*/
|
|
21
|
+
pagingDotsBuilder?: (dots: React.ReactNode) => React.JSX.Element;
|
|
22
|
+
/**
|
|
23
|
+
* 自定义分页点
|
|
24
|
+
*/
|
|
25
|
+
pagingDotBuilder?: (item: SortItem<D, C>, index: number) => React.JSX.Element;
|
|
26
|
+
/**
|
|
27
|
+
* 自定义 item 渲染
|
|
28
|
+
*/
|
|
29
|
+
itemBuilder?: (item: SortItem<D, C>) => React.ReactNode;
|
|
30
|
+
/**
|
|
31
|
+
* 自定义 item 图标渲染
|
|
32
|
+
*/
|
|
33
|
+
itemIconBuilder?: (item: SortItem<D, C>) => React.ReactNode;
|
|
34
|
+
/**
|
|
35
|
+
* 自定义右键菜单
|
|
36
|
+
*/
|
|
37
|
+
contextMenuBuilder?: (data: SortItem<D, C>) => ContextMenuProps<D, C>;
|
|
38
|
+
}
|
|
39
|
+
export declare const SortableConfigContext: React.Context<SortableConfig<any, any>>;
|
|
40
|
+
export interface SortableConfigProviderProps<D, C> extends Omit<SortableConfig<D, C>, 'theme'> {
|
|
41
|
+
readonly theme?: 'light' | 'dark' | Theme;
|
|
42
|
+
children: React.ReactNode;
|
|
43
|
+
}
|
|
44
|
+
export declare const SortableConfigProvider: <D, C>(props: SortableConfigProviderProps<D, C>) => React.JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
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 = ["children", "theme"];
|
|
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); }
|
|
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
|
+
import React, { createContext, useMemo } from 'react';
|
|
11
|
+
import { themeDark, themeLight } from "../../theme";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 需要跨多个组件传递的配置,使用 context 传递
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export var SortableConfigContext = /*#__PURE__*/createContext({});
|
|
18
|
+
export var SortableConfigProvider = function SortableConfigProvider(props) {
|
|
19
|
+
var children = props.children,
|
|
20
|
+
propTheme = props.theme,
|
|
21
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
22
|
+
var theme = useMemo(function () {
|
|
23
|
+
if (propTheme === 'light') {
|
|
24
|
+
return themeLight;
|
|
25
|
+
} else if (propTheme === 'dark') {
|
|
26
|
+
return themeDark;
|
|
27
|
+
} else {
|
|
28
|
+
return propTheme;
|
|
29
|
+
}
|
|
30
|
+
}, [propTheme]);
|
|
31
|
+
return /*#__PURE__*/React.createElement(SortableConfigContext.Provider, {
|
|
32
|
+
value: _objectSpread({
|
|
33
|
+
theme: theme
|
|
34
|
+
}, rest)
|
|
35
|
+
}, children);
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useSortableConfig: () => import("./context").SortableConfig<any, any>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import {
|
|
3
|
-
import { SortItem } from './types';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SortItem } from '../../types';
|
|
4
3
|
interface ContextMenu {
|
|
5
4
|
rect: DOMRect;
|
|
6
5
|
data: any;
|
|
@@ -8,14 +7,14 @@ interface ContextMenu {
|
|
|
8
7
|
pageY?: number;
|
|
9
8
|
}
|
|
10
9
|
type ListStatus = 'onMove';
|
|
11
|
-
export interface
|
|
10
|
+
export interface SortableState {
|
|
12
11
|
list: SortItem[];
|
|
13
12
|
setList: any;
|
|
14
13
|
contextMenu: ContextMenu | null;
|
|
15
14
|
setContextMenu: (e: ContextMenu | null) => void;
|
|
16
15
|
listStatus: ListStatus | null;
|
|
17
16
|
setListStatus: (e: ListStatus | null) => void;
|
|
18
|
-
contextMenuFuns: (data: any) => any;
|
|
17
|
+
contextMenuFuns: (data: any, enable: boolean) => any;
|
|
19
18
|
hideContextMenu: () => void;
|
|
20
19
|
/** 点击右键菜单信息数据 */
|
|
21
20
|
showInfoItemData: SortItem | null;
|
|
@@ -28,22 +27,33 @@ export interface SortableContextProps {
|
|
|
28
27
|
updateItem: (id: string | number, data: any) => void;
|
|
29
28
|
updateItemConfig: (id: string | number, config: any) => void;
|
|
30
29
|
removeItem: (id: string) => void;
|
|
30
|
+
addItem: (data: SortItem, parentIds: (string | number)[]) => void;
|
|
31
31
|
/** 当前移动的元素id */
|
|
32
32
|
moveItemId: string | null;
|
|
33
33
|
setMoveItemId: (e: string | null) => void;
|
|
34
34
|
/** 当前元素将要移动到的元素id */
|
|
35
35
|
moveTargetId: string | number | null;
|
|
36
36
|
setMoveTargetId: (e: string | number | null) => void;
|
|
37
|
-
theme?: Theme;
|
|
38
37
|
}
|
|
39
|
-
export declare const
|
|
40
|
-
interface
|
|
41
|
-
|
|
38
|
+
export declare const SortableStateContext: React.Context<SortableState>;
|
|
39
|
+
export interface SortableStateProviderProps<D, C> {
|
|
40
|
+
/**
|
|
41
|
+
* 列表数据
|
|
42
|
+
*/
|
|
42
43
|
list?: SortItem<D, C>[];
|
|
44
|
+
/**
|
|
45
|
+
* 列表数据变更事件
|
|
46
|
+
*/
|
|
43
47
|
onChange?: (list: SortItem<D, C>[]) => void;
|
|
48
|
+
/**
|
|
49
|
+
* 本地存储 key
|
|
50
|
+
*/
|
|
44
51
|
readonly storageKey?: string;
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
/**
|
|
53
|
+
* 是否启用缓存
|
|
54
|
+
*/
|
|
55
|
+
enableCaching?: boolean;
|
|
56
|
+
children: React.ReactNode;
|
|
47
57
|
}
|
|
48
|
-
export declare const
|
|
58
|
+
export declare const SortableStateProvider: <D, C>(props: SortableStateProviderProps<D, C>) => React.JSX.Element;
|
|
49
59
|
export {};
|
|
@@ -15,11 +15,11 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
15
15
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
16
16
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
17
17
|
import { useDebounceEffect, useLocalStorageState } from 'ahooks';
|
|
18
|
-
import React, { createContext, useEffect,
|
|
18
|
+
import React, { createContext, useEffect, useRef, useState } from 'react';
|
|
19
19
|
import { v4 as uuidv4 } from 'uuid';
|
|
20
|
-
import {
|
|
21
|
-
import SortableUtils from "
|
|
22
|
-
export var
|
|
20
|
+
import { configMap } from "../../config";
|
|
21
|
+
import SortableUtils from "../../utils";
|
|
22
|
+
export var SortableStateContext = /*#__PURE__*/createContext({
|
|
23
23
|
list: [],
|
|
24
24
|
setList: function setList() {},
|
|
25
25
|
contextMenu: null,
|
|
@@ -36,22 +36,21 @@ export var SortableContext = /*#__PURE__*/createContext({
|
|
|
36
36
|
updateItem: function updateItem() {},
|
|
37
37
|
updateItemConfig: function updateItemConfig() {},
|
|
38
38
|
removeItem: function removeItem() {},
|
|
39
|
+
addItem: function addItem() {},
|
|
39
40
|
moveItemId: null,
|
|
40
41
|
setMoveItemId: function setMoveItemId() {},
|
|
41
42
|
moveTargetId: null,
|
|
42
|
-
setMoveTargetId: function setMoveTargetId() {}
|
|
43
|
-
theme: themeLight
|
|
43
|
+
setMoveTargetId: function setMoveTargetId() {}
|
|
44
44
|
});
|
|
45
|
-
export var
|
|
46
|
-
var children =
|
|
47
|
-
|
|
48
|
-
propList =
|
|
49
|
-
propOnChange =
|
|
50
|
-
|
|
51
|
-
storageKey =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
enableCaching = _ref$enableCaching === void 0 ? true : _ref$enableCaching;
|
|
45
|
+
export var SortableStateProvider = function SortableStateProvider(props) {
|
|
46
|
+
var children = props.children,
|
|
47
|
+
_props$list = props.list,
|
|
48
|
+
propList = _props$list === void 0 ? [] : _props$list,
|
|
49
|
+
propOnChange = props.onChange,
|
|
50
|
+
_props$storageKey = props.storageKey,
|
|
51
|
+
storageKey = _props$storageKey === void 0 ? 'ZS_LIBRARY_DESKTOP_SORTABLE_CONFIG' : _props$storageKey,
|
|
52
|
+
_props$enableCaching = props.enableCaching,
|
|
53
|
+
enableCaching = _props$enableCaching === void 0 ? true : _props$enableCaching;
|
|
55
54
|
var _useState = useState(),
|
|
56
55
|
_useState2 = _slicedToArray(_useState, 2),
|
|
57
56
|
contextMenuTimer = _useState2[0],
|
|
@@ -119,6 +118,7 @@ export var SortableProvider = function SortableProvider(_ref) {
|
|
|
119
118
|
clearTimeout(contextMenuTimer);
|
|
120
119
|
};
|
|
121
120
|
var contextMenuFuns = function contextMenuFuns(data) {
|
|
121
|
+
var enable = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
122
122
|
var _data$config = data.config,
|
|
123
123
|
config = _data$config === void 0 ? {} : _data$config;
|
|
124
124
|
if (config.allowContextMenu === false) {
|
|
@@ -127,6 +127,7 @@ export var SortableProvider = function SortableProvider(_ref) {
|
|
|
127
127
|
return {
|
|
128
128
|
onMouseDown: function onMouseDown(e) {
|
|
129
129
|
setContextMenuTimer(setTimeout(function () {
|
|
130
|
+
if (!enable) return;
|
|
130
131
|
// 解决闭包导致拖拽时右键菜单不消失的问题
|
|
131
132
|
if (listStatusRef.current !== null) return;
|
|
132
133
|
getItemRectAndSetContextMenu(e, data);
|
|
@@ -144,6 +145,7 @@ export var SortableProvider = function SortableProvider(_ref) {
|
|
|
144
145
|
setContextMenuTimer(undefined);
|
|
145
146
|
},
|
|
146
147
|
onContextMenu: function onContextMenu(e) {
|
|
148
|
+
if (!enable) return;
|
|
147
149
|
e.preventDefault();
|
|
148
150
|
getItemRectAndSetContextMenu(e, data);
|
|
149
151
|
}
|
|
@@ -275,6 +277,37 @@ export var SortableProvider = function SortableProvider(_ref) {
|
|
|
275
277
|
return _list;
|
|
276
278
|
});
|
|
277
279
|
};
|
|
280
|
+
var addItem = function addItem(data, parentIds) {
|
|
281
|
+
var _list = _toConsumableArray(list);
|
|
282
|
+
|
|
283
|
+
// 根据 parentIds 递归查找,放置到对应的父级下
|
|
284
|
+
var addToChild = function addToChild(list, parentIds) {
|
|
285
|
+
var parentId = parentIds.shift();
|
|
286
|
+
var parent = list.find(function (item) {
|
|
287
|
+
return item.id === parentId;
|
|
288
|
+
});
|
|
289
|
+
var parentIndex = list.findIndex(function (item) {
|
|
290
|
+
return item.id === parentId;
|
|
291
|
+
});
|
|
292
|
+
if (!parent) {
|
|
293
|
+
return list;
|
|
294
|
+
} else {
|
|
295
|
+
if (parentIds.length) {
|
|
296
|
+
parent.children = addToChild(parent.children || [], parentIds);
|
|
297
|
+
} else {
|
|
298
|
+
var _data$type, _parent$children3, _data$config2;
|
|
299
|
+
var type = (_data$type = data === null || data === void 0 ? void 0 : data.type) !== null && _data$type !== void 0 ? _data$type : 'app';
|
|
300
|
+
parent.children = [].concat(_toConsumableArray((_parent$children3 = parent.children) !== null && _parent$children3 !== void 0 ? _parent$children3 : []), [_objectSpread(_objectSpread({}, data), {}, {
|
|
301
|
+
id: uuidv4(),
|
|
302
|
+
config: (_data$config2 = data === null || data === void 0 ? void 0 : data.config) !== null && _data$config2 !== void 0 ? _data$config2 : configMap[type]
|
|
303
|
+
})]);
|
|
304
|
+
}
|
|
305
|
+
list.splice(parentIndex, 1, parent);
|
|
306
|
+
return list;
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
setList(addToChild(_list, parentIds));
|
|
310
|
+
};
|
|
278
311
|
useEffect(function () {
|
|
279
312
|
if ((propList === null || propList === void 0 ? void 0 : propList.length) > 0 && list.length === 0) {
|
|
280
313
|
_setList(propList);
|
|
@@ -301,16 +334,7 @@ export var SortableProvider = function SortableProvider(_ref) {
|
|
|
301
334
|
}, [list, enableCaching], {
|
|
302
335
|
wait: 1000
|
|
303
336
|
});
|
|
304
|
-
|
|
305
|
-
if (propTheme === 'light') {
|
|
306
|
-
return themeLight;
|
|
307
|
-
} else if (propTheme === 'dark') {
|
|
308
|
-
return themeDark;
|
|
309
|
-
} else {
|
|
310
|
-
return propTheme;
|
|
311
|
-
}
|
|
312
|
-
}, [propTheme]);
|
|
313
|
-
return /*#__PURE__*/React.createElement(SortableContext.Provider, {
|
|
337
|
+
return /*#__PURE__*/React.createElement(SortableStateContext.Provider, {
|
|
314
338
|
value: {
|
|
315
339
|
list: list,
|
|
316
340
|
setList: _setList,
|
|
@@ -328,11 +352,11 @@ export var SortableProvider = function SortableProvider(_ref) {
|
|
|
328
352
|
updateItemConfig: updateItemConfig,
|
|
329
353
|
updateItem: updateItem,
|
|
330
354
|
removeItem: removeItem,
|
|
355
|
+
addItem: addItem,
|
|
331
356
|
moveItemId: moveItemId,
|
|
332
357
|
setMoveItemId: setMoveItemId,
|
|
333
358
|
moveTargetId: moveTargetId,
|
|
334
|
-
setMoveTargetId: setMoveTargetId
|
|
335
|
-
theme: theme
|
|
359
|
+
setMoveTargetId: setMoveTargetId
|
|
336
360
|
}
|
|
337
361
|
}, children);
|
|
338
362
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useSortableState: () => import("./context").SortableState;
|
package/dist/Desktop/index.d.ts
CHANGED
|
@@ -1,29 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { SortableProps } from './Sortable';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export interface DesktopProps<D = any, C = any> extends SortableProps<D, C> {
|
|
6
|
-
/**
|
|
7
|
-
* 数据源
|
|
8
|
-
*/
|
|
9
|
-
list: SortItem<D, C>[];
|
|
10
|
-
/**
|
|
11
|
-
* onChange 事件,当排序发生变化时触发
|
|
12
|
-
*/
|
|
13
|
-
onChange?: (list: SortItem<D, C>[]) => void;
|
|
14
|
-
/**
|
|
15
|
-
* 本地存储 key
|
|
16
|
-
*/
|
|
17
|
-
readonly storageKey?: string;
|
|
18
|
-
/**
|
|
19
|
-
* 主题配置
|
|
20
|
-
*/
|
|
21
|
-
theme?: 'light' | 'dark' | Theme;
|
|
22
|
-
/**
|
|
23
|
-
* 是否启用缓存
|
|
24
|
-
* @default true
|
|
25
|
-
*/
|
|
26
|
-
enableCaching: boolean;
|
|
3
|
+
import { SortableConfigProviderProps } from './context/config/context';
|
|
4
|
+
import { SortableStateProviderProps } from './context/state/context';
|
|
5
|
+
export interface DesktopProps<D = any, C = any> extends SortableProps<D, C>, Omit<SortableStateProviderProps<D, C>, 'children'>, Omit<SortableConfigProviderProps<D, C>, 'children'> {
|
|
27
6
|
}
|
|
28
7
|
declare const Desktop: <D, C>(props: DesktopProps<D, C>) => React.JSX.Element;
|
|
29
8
|
export default Desktop;
|
package/dist/Desktop/index.js
CHANGED
|
@@ -1,22 +1,40 @@
|
|
|
1
|
-
var _excluded = ["list", "onChange", "storageKey", "theme", "
|
|
1
|
+
var _excluded = ["list", "onChange", "storageKey", "enableCaching", "theme", "noLetters", "contextMenu", "contextMenuBuilder", "itemBuilder", "itemIconBuilder", "pagingDotBuilder", "pagingDotsBuilder"];
|
|
2
2
|
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; }
|
|
3
3
|
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; }
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import Sortable from "./Sortable";
|
|
6
|
-
import {
|
|
6
|
+
import { SortableConfigProvider } from "./context/config/context";
|
|
7
|
+
import { SortableStateProvider } from "./context/state/context";
|
|
7
8
|
var Desktop = function Desktop(props) {
|
|
8
9
|
var list = props.list,
|
|
9
10
|
onChange = props.onChange,
|
|
10
11
|
storageKey = props.storageKey,
|
|
11
|
-
theme = props.theme,
|
|
12
12
|
enableCaching = props.enableCaching,
|
|
13
|
+
theme = props.theme,
|
|
14
|
+
noLetters = props.noLetters,
|
|
15
|
+
contextMenu = props.contextMenu,
|
|
16
|
+
contextMenuBuilder = props.contextMenuBuilder,
|
|
17
|
+
itemBuilder = props.itemBuilder,
|
|
18
|
+
itemIconBuilder = props.itemIconBuilder,
|
|
19
|
+
pagingDotBuilder = props.pagingDotBuilder,
|
|
20
|
+
pagingDotsBuilder = props.pagingDotsBuilder,
|
|
13
21
|
rest = _objectWithoutProperties(props, _excluded);
|
|
14
|
-
|
|
15
|
-
theme: theme,
|
|
22
|
+
var state = {
|
|
16
23
|
list: list,
|
|
17
24
|
onChange: onChange,
|
|
18
25
|
storageKey: storageKey,
|
|
19
26
|
enableCaching: enableCaching
|
|
20
|
-
}
|
|
27
|
+
};
|
|
28
|
+
var config = {
|
|
29
|
+
theme: theme,
|
|
30
|
+
noLetters: noLetters,
|
|
31
|
+
contextMenu: contextMenu,
|
|
32
|
+
pagingDotsBuilder: pagingDotsBuilder,
|
|
33
|
+
pagingDotBuilder: pagingDotBuilder,
|
|
34
|
+
itemBuilder: itemBuilder,
|
|
35
|
+
itemIconBuilder: itemIconBuilder,
|
|
36
|
+
contextMenuBuilder: contextMenuBuilder
|
|
37
|
+
};
|
|
38
|
+
return /*#__PURE__*/React.createElement(SortableStateProvider, state, /*#__PURE__*/React.createElement(SortableConfigProvider, config, /*#__PURE__*/React.createElement(Sortable, rest)));
|
|
21
39
|
};
|
|
22
40
|
export default Desktop;
|
package/package.json
CHANGED
package/dist/Desktop/hook.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useSortable: () => import("./context").SortableContextProps;
|