@canlooks/can-ui 0.0.90 → 0.0.91
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/cjs/components/tree/tree.style.d.ts +1 -0
- package/dist/cjs/components/tree/tree.style.js +7 -4
- package/dist/cjs/components/tree/treeDnd.js +10 -1
- package/dist/cjs/components/tree/treeNode.js +7 -2
- package/dist/esm/components/tree/tree.style.d.ts +1 -0
- package/dist/esm/components/tree/tree.style.js +7 -4
- package/dist/esm/components/tree/treeDnd.js +11 -2
- package/dist/esm/components/tree/treeNode.js +7 -2
- package/package.json +1 -1
|
@@ -8,6 +8,7 @@ const color_1 = tslib_1.__importDefault(require("color"));
|
|
|
8
8
|
exports.classes = (0, utils_1.defineInnerClasses)('tree', [
|
|
9
9
|
'levelBlock',
|
|
10
10
|
'search',
|
|
11
|
+
'container',
|
|
11
12
|
'node',
|
|
12
13
|
'contentWrap',
|
|
13
14
|
'indent',
|
|
@@ -33,6 +34,12 @@ exports.style = (0, utils_1.defineCss)(({ spacing, mode, borderRadius, text, eas
|
|
|
33
34
|
.${exports.classes.search} {
|
|
34
35
|
margin-bottom: ${spacing[3]}px;
|
|
35
36
|
}
|
|
37
|
+
|
|
38
|
+
.${exports.classes.container}[data-dragging=true] {
|
|
39
|
+
&, * {
|
|
40
|
+
cursor: grabbing;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
36
43
|
|
|
37
44
|
.${exports.classes.node} {
|
|
38
45
|
display: flex;
|
|
@@ -226,10 +233,6 @@ exports.style = (0, utils_1.defineCss)(({ spacing, mode, borderRadius, text, eas
|
|
|
226
233
|
|
|
227
234
|
&[data-sortable=true] {
|
|
228
235
|
.${exports.classes.node} {
|
|
229
|
-
&:not(:has(.${exports.classes.dragHandle})) {
|
|
230
|
-
cursor: grab;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
236
|
&[data-dragging=true] {
|
|
234
237
|
&, &:active {
|
|
235
238
|
background-color: ${selectedBg};
|
|
@@ -5,6 +5,7 @@ exports.useTreeDndContext = useTreeDndContext;
|
|
|
5
5
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
6
6
|
const react_1 = require("react");
|
|
7
7
|
const utils_1 = require("../../utils");
|
|
8
|
+
const tree_style_1 = require("./tree.style");
|
|
8
9
|
exports.TreeDndContext = (0, react_1.createContext)({});
|
|
9
10
|
function useTreeDndContext() {
|
|
10
11
|
return (0, react_1.useContext)(exports.TreeDndContext);
|
|
@@ -14,10 +15,18 @@ exports.TreeDnd = (0, react_1.memo)(({ sortable, showDragHandle, onSort, contain
|
|
|
14
15
|
const dragging = (0, react_1.useState)(void 0);
|
|
15
16
|
const overing = (0, react_1.useState)(void 0);
|
|
16
17
|
const placement = (0, utils_1.useSyncState)(void 0);
|
|
18
|
+
(0, react_1.useEffect)(() => {
|
|
19
|
+
if (dragging[0]) {
|
|
20
|
+
document.documentElement.style.cursor = 'grabbing';
|
|
21
|
+
}
|
|
22
|
+
return () => {
|
|
23
|
+
document.documentElement.style.cursor = '';
|
|
24
|
+
};
|
|
25
|
+
}, [dragging[0]]);
|
|
17
26
|
const overingTimer = (0, react_1.useRef)(void 0);
|
|
18
27
|
return ((0, jsx_runtime_1.jsx)(exports.TreeDndContext, { value: {
|
|
19
28
|
sortable, showDragHandle, onSort, containerRef,
|
|
20
29
|
isOffsetSatisfied, dragging, overing, placement,
|
|
21
30
|
overingTimer
|
|
22
|
-
}, children: children }));
|
|
31
|
+
}, children: (0, jsx_runtime_1.jsx)("div", { className: tree_style_1.classes.container, "data-dragging": !!dragging[0], children: children }) }));
|
|
23
32
|
});
|
|
@@ -30,6 +30,10 @@ exports.TreeNode = (0, react_1.memo)(({ value, label, prefix, suffix, disabled,
|
|
|
30
30
|
* 拖拽部分
|
|
31
31
|
*/
|
|
32
32
|
const { sortable, showDragHandle, onSort, containerRef, isOffsetSatisfied: [isOffsetSatisfied, setIsOffsetSatisfied], dragging: [dragging, setDragging], overing: [overing, setOvering], placement: [placement, setPlacement], overingTimer } = (0, treeDnd_1.useTreeDndContext)();
|
|
33
|
+
const onClick = (e) => {
|
|
34
|
+
props.onClick?.(e);
|
|
35
|
+
!showCheckbox && clickHandler();
|
|
36
|
+
};
|
|
33
37
|
const dragHandleProps = (0, utils_1.useDraggable)({
|
|
34
38
|
disabled: !sortable,
|
|
35
39
|
onDragStart(e) {
|
|
@@ -51,7 +55,8 @@ exports.TreeNode = (0, react_1.memo)(({ value, label, prefix, suffix, disabled,
|
|
|
51
55
|
placement: isOffsetSatisfied ? 'child' : placement.current
|
|
52
56
|
});
|
|
53
57
|
}
|
|
54
|
-
}
|
|
58
|
+
},
|
|
59
|
+
onClick
|
|
55
60
|
});
|
|
56
61
|
const nodeRef = (0, react_1.useRef)(null);
|
|
57
62
|
const activeParentBlock = (target) => {
|
|
@@ -98,7 +103,7 @@ exports.TreeNode = (0, react_1.memo)(({ value, label, prefix, suffix, disabled,
|
|
|
98
103
|
const renderedIndents = (0, react_1.useMemo)(() => {
|
|
99
104
|
return Array(_level).fill(void 0).map((_, i) => (0, jsx_runtime_1.jsx)("div", { className: tree_style_1.classes.indent, style: { width: indent } }, i));
|
|
100
105
|
}, [_level, indent]);
|
|
101
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { ...props, ref: (0, utils_1.cloneRef)(nodeRef, props.ref), className: (0, utils_1.clsx)(tree_style_1.classes.node, props.className), "data-selected": status === 2, "data-read-only": readOnly, "data-disabled": disabled, "data-dragging": dragging === value, ...!showDragHandle && dragHandleProps, children: [renderedIndents, (0, jsx_runtime_1.jsx)(button_1.Button, { className: tree_style_1.classes.expand, variant: "plain", color: "text.secondary", onClick: e => {
|
|
106
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { ...props, ref: (0, utils_1.cloneRef)(nodeRef, props.ref), className: (0, utils_1.clsx)(tree_style_1.classes.node, props.className), "data-selected": status === 2, "data-read-only": readOnly, "data-disabled": disabled, "data-dragging": dragging === value, ...!showDragHandle && dragHandleProps, onClick: showDragHandle ? onClick : props.onClick, children: [renderedIndents, (0, jsx_runtime_1.jsx)(button_1.Button, { className: tree_style_1.classes.expand, variant: "plain", color: "text.secondary", onClick: e => {
|
|
102
107
|
e.stopPropagation();
|
|
103
108
|
toggleExpanded(value);
|
|
104
109
|
}, onPointerDown: e => e.stopPropagation(), children: renderExpandIcon
|
|
@@ -4,6 +4,7 @@ import Color from 'color';
|
|
|
4
4
|
export const classes = defineInnerClasses('tree', [
|
|
5
5
|
'levelBlock',
|
|
6
6
|
'search',
|
|
7
|
+
'container',
|
|
7
8
|
'node',
|
|
8
9
|
'contentWrap',
|
|
9
10
|
'indent',
|
|
@@ -29,6 +30,12 @@ export const style = defineCss(({ spacing, mode, borderRadius, text, easing, gra
|
|
|
29
30
|
.${classes.search} {
|
|
30
31
|
margin-bottom: ${spacing[3]}px;
|
|
31
32
|
}
|
|
33
|
+
|
|
34
|
+
.${classes.container}[data-dragging=true] {
|
|
35
|
+
&, * {
|
|
36
|
+
cursor: grabbing;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
32
39
|
|
|
33
40
|
.${classes.node} {
|
|
34
41
|
display: flex;
|
|
@@ -222,10 +229,6 @@ export const style = defineCss(({ spacing, mode, borderRadius, text, easing, gra
|
|
|
222
229
|
|
|
223
230
|
&[data-sortable=true] {
|
|
224
231
|
.${classes.node} {
|
|
225
|
-
&:not(:has(.${classes.dragHandle})) {
|
|
226
|
-
cursor: grab;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
232
|
&[data-dragging=true] {
|
|
230
233
|
&, &:active {
|
|
231
234
|
background-color: ${selectedBg};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
-
import { createContext, memo, useContext, useRef, useState } from 'react';
|
|
2
|
+
import { createContext, memo, useContext, useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { useSyncState } from '../../utils';
|
|
4
|
+
import { classes } from './tree.style';
|
|
4
5
|
export const TreeDndContext = createContext({});
|
|
5
6
|
export function useTreeDndContext() {
|
|
6
7
|
return useContext(TreeDndContext);
|
|
@@ -10,10 +11,18 @@ export const TreeDnd = memo(({ sortable, showDragHandle, onSort, containerRef, c
|
|
|
10
11
|
const dragging = useState(void 0);
|
|
11
12
|
const overing = useState(void 0);
|
|
12
13
|
const placement = useSyncState(void 0);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (dragging[0]) {
|
|
16
|
+
document.documentElement.style.cursor = 'grabbing';
|
|
17
|
+
}
|
|
18
|
+
return () => {
|
|
19
|
+
document.documentElement.style.cursor = '';
|
|
20
|
+
};
|
|
21
|
+
}, [dragging[0]]);
|
|
13
22
|
const overingTimer = useRef(void 0);
|
|
14
23
|
return (_jsx(TreeDndContext, { value: {
|
|
15
24
|
sortable, showDragHandle, onSort, containerRef,
|
|
16
25
|
isOffsetSatisfied, dragging, overing, placement,
|
|
17
26
|
overingTimer
|
|
18
|
-
}, children: children }));
|
|
27
|
+
}, children: _jsx("div", { className: classes.container, "data-dragging": !!dragging[0], children: children }) }));
|
|
19
28
|
});
|
|
@@ -27,6 +27,10 @@ export const TreeNode = memo(({ value, label, prefix, suffix, disabled, _level =
|
|
|
27
27
|
* 拖拽部分
|
|
28
28
|
*/
|
|
29
29
|
const { sortable, showDragHandle, onSort, containerRef, isOffsetSatisfied: [isOffsetSatisfied, setIsOffsetSatisfied], dragging: [dragging, setDragging], overing: [overing, setOvering], placement: [placement, setPlacement], overingTimer } = useTreeDndContext();
|
|
30
|
+
const onClick = (e) => {
|
|
31
|
+
props.onClick?.(e);
|
|
32
|
+
!showCheckbox && clickHandler();
|
|
33
|
+
};
|
|
30
34
|
const dragHandleProps = useDraggable({
|
|
31
35
|
disabled: !sortable,
|
|
32
36
|
onDragStart(e) {
|
|
@@ -48,7 +52,8 @@ export const TreeNode = memo(({ value, label, prefix, suffix, disabled, _level =
|
|
|
48
52
|
placement: isOffsetSatisfied ? 'child' : placement.current
|
|
49
53
|
});
|
|
50
54
|
}
|
|
51
|
-
}
|
|
55
|
+
},
|
|
56
|
+
onClick
|
|
52
57
|
});
|
|
53
58
|
const nodeRef = useRef(null);
|
|
54
59
|
const activeParentBlock = (target) => {
|
|
@@ -95,7 +100,7 @@ export const TreeNode = memo(({ value, label, prefix, suffix, disabled, _level =
|
|
|
95
100
|
const renderedIndents = useMemo(() => {
|
|
96
101
|
return Array(_level).fill(void 0).map((_, i) => _jsx("div", { className: classes.indent, style: { width: indent } }, i));
|
|
97
102
|
}, [_level, indent]);
|
|
98
|
-
return (_jsxs(_Fragment, { children: [_jsxs("div", { ...props, ref: cloneRef(nodeRef, props.ref), className: clsx(classes.node, props.className), "data-selected": status === 2, "data-read-only": readOnly, "data-disabled": disabled, "data-dragging": dragging === value, ...!showDragHandle && dragHandleProps, children: [renderedIndents, _jsx(Button, { className: classes.expand, variant: "plain", color: "text.secondary", onClick: e => {
|
|
103
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { ...props, ref: cloneRef(nodeRef, props.ref), className: clsx(classes.node, props.className), "data-selected": status === 2, "data-read-only": readOnly, "data-disabled": disabled, "data-dragging": dragging === value, ...!showDragHandle && dragHandleProps, onClick: showDragHandle ? onClick : props.onClick, children: [renderedIndents, _jsx(Button, { className: classes.expand, variant: "plain", color: "text.secondary", onClick: e => {
|
|
99
104
|
e.stopPropagation();
|
|
100
105
|
toggleExpanded(value);
|
|
101
106
|
}, onPointerDown: e => e.stopPropagation(), children: renderExpandIcon
|