@canlooks/can-ui 0.0.96 → 0.0.97
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/accordion/accordion.style.d.ts +1 -1
- package/dist/cjs/components/alert/alert.style.d.ts +3 -3
- package/dist/cjs/components/button/button.style.d.ts +1 -1
- package/dist/cjs/components/checkboxBase/checkboxBase.style.d.ts +2 -2
- package/dist/cjs/components/clickAway/clickAway.d.ts +27 -27
- package/dist/cjs/components/dataGrid/dataGrid.style.d.ts +1 -1
- package/dist/cjs/components/descriptions/descriptions.style.d.ts +1 -1
- package/dist/cjs/components/dialog/dialog.style.d.ts +3 -3
- package/dist/cjs/components/inputBase/inputBase.style.d.ts +2 -2
- package/dist/cjs/components/menuItem/menuItem.d.ts +4 -0
- package/dist/cjs/components/menuItem/menuItem.style.d.ts +2 -2
- package/dist/cjs/components/optionsBase/optionsBase.js +2 -1
- package/dist/cjs/components/palette/palette.style.d.ts +1 -1
- package/dist/cjs/components/pickerDialog/pickerDialog.style.d.ts +1 -1
- package/dist/cjs/components/progress/progress.js +2 -1
- package/dist/cjs/components/progress/progress.style.d.ts +1 -1
- package/dist/cjs/components/resizable/resizable.style.d.ts +1 -1
- package/dist/cjs/components/segmented/segmented.style.d.ts +1 -1
- package/dist/cjs/components/selectionContext/selectionContext.d.ts +2 -0
- package/dist/cjs/components/selectionContext/selectionHook.js +2 -1
- package/dist/cjs/components/snackbarBase/snackbarBase.style.d.ts +1 -1
- package/dist/cjs/components/status/status.style.d.ts +1 -1
- package/dist/cjs/components/tabs/tabs.style.d.ts +4 -4
- package/dist/cjs/components/tag/tag.style.d.ts +2 -2
- package/dist/cjs/components/transfer/transfer.style.d.ts +2 -2
- package/dist/cjs/components/tree/tree.d.ts +2 -2
- package/dist/cjs/components/tree/tree.js +15 -13
- package/dist/cjs/components/tree/tree.style.d.ts +5 -9
- package/dist/cjs/components/tree/tree.style.js +96 -206
- package/dist/cjs/components/tree/treeDnd.d.ts +3 -7
- package/dist/cjs/components/tree/treeDnd.js +7 -19
- package/dist/cjs/components/tree/treeDnd.style.d.ts +15 -0
- package/dist/cjs/components/tree/treeDnd.style.js +191 -0
- package/dist/cjs/components/tree/treeNode.d.ts +4 -4
- package/dist/cjs/components/tree/treeNode.js +82 -69
- package/dist/cjs/components/upload/upload.style.d.ts +1 -1
- package/dist/cjs/utils/dnd.d.ts +11 -3
- package/dist/cjs/utils/dnd.js +45 -2
- package/dist/esm/components/accordion/accordion.style.d.ts +1 -1
- package/dist/esm/components/alert/alert.style.d.ts +3 -3
- package/dist/esm/components/button/button.style.d.ts +1 -1
- package/dist/esm/components/checkboxBase/checkboxBase.style.d.ts +2 -2
- package/dist/esm/components/clickAway/clickAway.d.ts +27 -27
- package/dist/esm/components/dataGrid/dataGrid.style.d.ts +1 -1
- package/dist/esm/components/descriptions/descriptions.style.d.ts +1 -1
- package/dist/esm/components/dialog/dialog.style.d.ts +3 -3
- package/dist/esm/components/inputBase/inputBase.style.d.ts +2 -2
- package/dist/esm/components/menuItem/menuItem.d.ts +4 -0
- package/dist/esm/components/menuItem/menuItem.style.d.ts +2 -2
- package/dist/esm/components/optionsBase/optionsBase.js +2 -1
- package/dist/esm/components/palette/palette.style.d.ts +1 -1
- package/dist/esm/components/pickerDialog/pickerDialog.style.d.ts +1 -1
- package/dist/esm/components/progress/progress.js +2 -1
- package/dist/esm/components/progress/progress.style.d.ts +1 -1
- package/dist/esm/components/resizable/resizable.style.d.ts +1 -1
- package/dist/esm/components/segmented/segmented.style.d.ts +1 -1
- package/dist/esm/components/selectionContext/selectionContext.d.ts +2 -0
- package/dist/esm/components/selectionContext/selectionHook.js +2 -1
- package/dist/esm/components/snackbarBase/snackbarBase.style.d.ts +1 -1
- package/dist/esm/components/status/status.style.d.ts +1 -1
- package/dist/esm/components/tabs/tabs.style.d.ts +4 -4
- package/dist/esm/components/tag/tag.style.d.ts +2 -2
- package/dist/esm/components/transfer/transfer.style.d.ts +2 -2
- package/dist/esm/components/tree/tree.d.ts +2 -2
- package/dist/esm/components/tree/tree.js +18 -16
- package/dist/esm/components/tree/tree.style.d.ts +5 -9
- package/dist/esm/components/tree/tree.style.js +95 -206
- package/dist/esm/components/tree/treeDnd.d.ts +3 -7
- package/dist/esm/components/tree/treeDnd.js +8 -20
- package/dist/esm/components/tree/treeDnd.style.d.ts +15 -0
- package/dist/esm/components/tree/treeDnd.style.js +186 -0
- package/dist/esm/components/tree/treeNode.d.ts +4 -4
- package/dist/esm/components/tree/treeNode.js +82 -69
- package/dist/esm/components/upload/upload.style.d.ts +1 -1
- package/dist/esm/utils/dnd.d.ts +11 -3
- package/dist/esm/utils/dnd.js +44 -2
- package/package.json +1 -1
|
@@ -4,6 +4,8 @@ export interface OptionType<V extends Id = Id> extends Obj {
|
|
|
4
4
|
children?: OptionType<V>[];
|
|
5
5
|
/** @private */
|
|
6
6
|
_parentId?: V;
|
|
7
|
+
/** @private */
|
|
8
|
+
_isLast?: boolean;
|
|
7
9
|
}
|
|
8
10
|
export type SelectionContextBaseProps<O extends OptionType<V>, V extends Id = Id> = {
|
|
9
11
|
options?: O[];
|
|
@@ -29,8 +29,9 @@ export function useSelection(props) {
|
|
|
29
29
|
const map = new Map();
|
|
30
30
|
const fn = (arr, parentId) => {
|
|
31
31
|
// 有时arr可能不为数组,需要判断,如DataGrid组件的row.children
|
|
32
|
-
Array.isArray(arr) && arr.forEach(item => {
|
|
32
|
+
Array.isArray(arr) && arr.forEach((item, i) => {
|
|
33
33
|
item._parentId = parentId;
|
|
34
|
+
item._isLast = i === arr.length - 1;
|
|
34
35
|
const id = item[props.primaryKey];
|
|
35
36
|
!isUnset(id) && map.set(id, item);
|
|
36
37
|
fn(item[props.childrenKey], id);
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { TabsProps } from './tabs';
|
|
2
2
|
export declare const classes: {
|
|
3
3
|
label: string;
|
|
4
|
-
scroll: string;
|
|
5
4
|
prefix: string;
|
|
5
|
+
suffix: string;
|
|
6
|
+
indicator: string;
|
|
6
7
|
end: string;
|
|
7
|
-
ellipsis: string;
|
|
8
8
|
start: string;
|
|
9
|
+
scroll: string;
|
|
10
|
+
ellipsis: string;
|
|
9
11
|
tab: string;
|
|
10
|
-
indicator: string;
|
|
11
|
-
suffix: string;
|
|
12
12
|
scrollWrap: string;
|
|
13
13
|
tabPrefix: string;
|
|
14
14
|
tabSuffix: string;
|
|
@@ -6,11 +6,11 @@ import { TreeNode, TreeNodeProps } from './treeNode';
|
|
|
6
6
|
export interface NodeType<V extends Id = Id> extends Partial<Omit<TreeNodeProps, 'children'>>, Omit<OptionType<V>, 'children'> {
|
|
7
7
|
children?: NodeType<V>[];
|
|
8
8
|
}
|
|
9
|
-
export type SortPlacement = 'before' | 'after';
|
|
9
|
+
export type SortPlacement = 'before' | 'after' | 'child';
|
|
10
10
|
export type SortInfo<V extends Id = Id> = {
|
|
11
11
|
source: V;
|
|
12
12
|
destination: V;
|
|
13
|
-
placement: SortPlacement
|
|
13
|
+
placement: SortPlacement;
|
|
14
14
|
};
|
|
15
15
|
export interface TreeBaseProps<N extends NodeType<V>, V extends Id = Id> extends Omit<SelectionContextBaseProps<N, V>, 'options'>, Omit<DivProps, 'defaultValue' | 'onChange' | 'onToggle'> {
|
|
16
16
|
nodes?: N[];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createElement as _createElement } from "@emotion/react";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
3
|
-
import { Children, createContext, isValidElement, memo, useContext, useMemo
|
|
3
|
+
import { Children, createContext, isValidElement, memo, useContext, useMemo } from 'react';
|
|
4
4
|
import { SelectionContext } from '../selectionContext';
|
|
5
5
|
import { Input } from '../input';
|
|
6
|
-
import { classes,
|
|
7
|
-
import {
|
|
6
|
+
import { classes, useStyle } from './tree.style';
|
|
7
|
+
import { clsx, useTreeSearch } from '../../utils';
|
|
8
8
|
import { Highlight } from '../highlight';
|
|
9
9
|
import { TreeNode } from './treeNode';
|
|
10
10
|
import { Icon } from '../icon';
|
|
@@ -17,11 +17,6 @@ export function useTreeContext() {
|
|
|
17
17
|
export const Tree = memo(({ nodes, labelKey = 'label', searchTokenKey, showLine = true, indent = 24, renderExpandIcon, multiple, showCheckbox = !!multiple, readOnly, clickLabelToExpand, defaultExpanded, expanded, onExpandedChange, sortable = false, showDragHandle = true, onSort, searchable, searchInputProps, defaultSearchValue, searchValue, onSearchChange,
|
|
18
18
|
// 从SelectionContext继承来的属性
|
|
19
19
|
primaryKey = 'id', childrenKey = 'children', relation = 'dependent', integration = 'shallowest', clearable, disabled, defaultValue, value, onChange, onToggle, ...props }) => {
|
|
20
|
-
const selectionContextProps = {
|
|
21
|
-
options: nodes, primaryKey, childrenKey, relation, integration,
|
|
22
|
-
multiple, defaultValue, value, onChange, disabled
|
|
23
|
-
};
|
|
24
|
-
const containerRef = useRef(null);
|
|
25
20
|
/**
|
|
26
21
|
* --------------------------------------------------------------
|
|
27
22
|
* 统一处理nodes与children
|
|
@@ -53,30 +48,37 @@ primaryKey = 'id', childrenKey = 'children', relation = 'dependent', integration
|
|
|
53
48
|
defaultExpanded, expanded, onExpandedChange,
|
|
54
49
|
defaultSearchValue, searchValue, onSearchChange
|
|
55
50
|
});
|
|
56
|
-
return (_jsxs("div", { ...props,
|
|
51
|
+
return (_jsxs("div", { ...props, css: useStyle({ indent }), className: clsx(classes.root, props.className), "data-show-line": showLine, children: [searchable &&
|
|
57
52
|
_jsx(Input, { className: classes.search, prefix: _jsx(Icon, { icon: faMagnifyingGlass }), placeholder: "\u641C\u7D22", value: innerSearchValue.current, ...searchInputProps, onChange: e => {
|
|
58
53
|
searchInputProps?.onChange?.(e);
|
|
59
54
|
setInnerSearchValue(e.target.value);
|
|
60
|
-
} }), _jsx(SelectionContext, { ...
|
|
55
|
+
} }), _jsx(SelectionContext, { ...{
|
|
56
|
+
options: actualTreeNodes, primaryKey, childrenKey, relation, integration,
|
|
57
|
+
multiple, defaultValue, value, onChange, disabled
|
|
58
|
+
}, children: _jsx(TreeContext, { value: useMemo(() => ({
|
|
61
59
|
expandedSet, toggleExpanded, indent, renderExpandIcon, clickLabelToExpand,
|
|
62
60
|
showCheckbox, readOnly, disabled
|
|
63
61
|
}), [
|
|
64
62
|
expandedSet, indent, renderExpandIcon, clickLabelToExpand,
|
|
65
63
|
showCheckbox, readOnly, disabled
|
|
66
|
-
]), children: _jsx(TreeDnd, { sortable: sortable, showDragHandle: showDragHandle, onSort: onSort,
|
|
64
|
+
]), children: _jsx(TreeDnd, { sortable: sortable, showDragHandle: showDragHandle, onSort: onSort, children: useMemo(() => {
|
|
67
65
|
if (!filteredTreeData?.length) {
|
|
68
66
|
return null;
|
|
69
67
|
}
|
|
70
68
|
const fn = (arr) => {
|
|
71
|
-
return arr?.map(({ _parentId, ...nodeProps }
|
|
72
|
-
const
|
|
69
|
+
return arr?.map(({ _isLast, _parentId, ...nodeProps }) => {
|
|
70
|
+
const currentId = nodeProps[primaryKey];
|
|
73
71
|
const label = nodeProps[labelKey];
|
|
74
|
-
|
|
72
|
+
const children = nodeProps[childrenKey];
|
|
73
|
+
delete nodeProps[primaryKey];
|
|
74
|
+
delete nodeProps[labelKey];
|
|
75
|
+
delete nodeProps[childrenKey];
|
|
76
|
+
return (_createElement(TreeNode, { ...nodeProps, key: currentId, id: currentId, label: typeof label === 'string' && deferredSearchValue
|
|
75
77
|
? _jsx(Highlight, { keywords: deferredSearchValue.split(' '), children: label })
|
|
76
|
-
: label }, fn(
|
|
78
|
+
: label }, fn(children)));
|
|
77
79
|
});
|
|
78
80
|
};
|
|
79
81
|
return fn(filteredTreeData);
|
|
80
|
-
}, [filteredTreeData]) }) }) })] }));
|
|
82
|
+
}, [filteredTreeData, primaryKey, labelKey, childrenKey, deferredSearchValue]) }) }) })] }));
|
|
81
83
|
});
|
|
82
84
|
Tree.Node = TreeNode;
|
|
@@ -2,20 +2,16 @@ export declare const classes: {
|
|
|
2
2
|
label: string;
|
|
3
3
|
search: string;
|
|
4
4
|
prefix: string;
|
|
5
|
+
suffix: string;
|
|
6
|
+
checkbox: string;
|
|
5
7
|
icon: string;
|
|
6
8
|
expand: string;
|
|
7
9
|
indent: string;
|
|
8
10
|
node: string;
|
|
9
|
-
checkbox: string;
|
|
10
|
-
container: string;
|
|
11
|
-
suffix: string;
|
|
12
11
|
contentWrap: string;
|
|
13
|
-
levelBlock: string;
|
|
14
|
-
dragHandle: string;
|
|
15
|
-
dragMask: string;
|
|
16
|
-
dragMaskPrev: string;
|
|
17
|
-
dragMaskNext: string;
|
|
18
12
|
} & {
|
|
19
13
|
root: string;
|
|
20
14
|
};
|
|
21
|
-
export declare
|
|
15
|
+
export declare function useStyle({ indent }: {
|
|
16
|
+
indent: number;
|
|
17
|
+
}): import("@emotion/react").SerializedStyles[];
|
|
@@ -1,244 +1,133 @@
|
|
|
1
1
|
import { css } from '@emotion/react';
|
|
2
|
-
import { defineInnerClasses,
|
|
2
|
+
import { defineInnerClasses, useCss } from '../../utils';
|
|
3
3
|
import Color from 'color';
|
|
4
|
+
import { useStyle as useDndStyle } from './treeDnd.style';
|
|
4
5
|
export const classes = defineInnerClasses('tree', [
|
|
5
|
-
'levelBlock',
|
|
6
6
|
'search',
|
|
7
|
-
'container',
|
|
8
7
|
'node',
|
|
9
8
|
'contentWrap',
|
|
10
9
|
'indent',
|
|
11
10
|
'expand',
|
|
12
11
|
'checkbox',
|
|
13
|
-
'dragHandle',
|
|
14
12
|
'icon',
|
|
15
13
|
'label',
|
|
16
14
|
'prefix',
|
|
17
|
-
'suffix'
|
|
18
|
-
'dragMask',
|
|
19
|
-
'dragMaskPrev',
|
|
20
|
-
'dragMaskNext'
|
|
15
|
+
'suffix'
|
|
21
16
|
]);
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
.${classes.container}[data-dragging=true] {
|
|
35
|
-
&, * {
|
|
36
|
-
cursor: grabbing;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.${classes.node} {
|
|
41
|
-
display: flex;
|
|
42
|
-
align-items: center;
|
|
43
|
-
padding-right: ${spacing[2]}px;
|
|
44
|
-
border-radius: ${borderRadius}px;
|
|
45
|
-
transition: background-color .25s ${easing.easeOut};
|
|
46
|
-
touch-action: none;
|
|
47
|
-
-webkit-tap-highlight-color: transparent;
|
|
48
|
-
|
|
49
|
-
&[data-disabled=true] {
|
|
50
|
-
color: ${text.disabled};
|
|
51
|
-
cursor: not-allowed;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
&:not([data-read-only=true]) {
|
|
55
|
-
cursor: pointer;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
&[data-selected=true] {
|
|
59
|
-
background-color: ${selectedBg};
|
|
60
|
-
|
|
61
|
-
&:hover {
|
|
62
|
-
background-color: ${selectedHover};
|
|
17
|
+
export function useStyle({ indent }) {
|
|
18
|
+
return [
|
|
19
|
+
useCss(({ spacing, mode, borderRadius, text, easing, gray, divider, colors }) => {
|
|
20
|
+
const c = Color(colors.primary.main);
|
|
21
|
+
const hover = gray(mode === 'light' ? .05 : .2);
|
|
22
|
+
const active = gray(mode === 'light' ? .1 : .12);
|
|
23
|
+
const selectedBg = c.alpha(mode === 'light' ? .1 : .2).string();
|
|
24
|
+
const selectedHover = c.alpha(mode === 'light' ? .07 : .17).string();
|
|
25
|
+
const selectedActive = c.alpha(mode === 'light' ? .13 : .23).string();
|
|
26
|
+
return css `
|
|
27
|
+
.${classes.search} {
|
|
28
|
+
margin-bottom: ${spacing[3]}px;
|
|
63
29
|
}
|
|
64
30
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
background-color: ${active};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
.${classes.indent} {
|
|
81
|
-
align-self: stretch;
|
|
82
|
-
display: flex;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
.${classes.expand} {
|
|
86
|
-
width: 29px;
|
|
87
|
-
align-self: stretch;
|
|
88
|
-
align-items: center;
|
|
89
|
-
justify-content: center;
|
|
90
|
-
|
|
91
|
-
.${classes.icon} {
|
|
92
|
-
transition: rotate .25s ${easing.easeOut};
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
.${classes.contentWrap} {
|
|
97
|
-
flex: 1;
|
|
98
|
-
display: flex;
|
|
99
|
-
align-items: center;
|
|
100
|
-
position: relative;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
.${classes.dragHandle} {
|
|
104
|
-
width: 20px;
|
|
105
|
-
margin-right: ${spacing[3]}px;
|
|
106
|
-
text-align: center;
|
|
107
|
-
color: ${gray(.12)};
|
|
108
|
-
cursor: grab;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
.${classes.checkbox} {
|
|
112
|
-
margin-right: ${spacing[3]}px;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
.${classes.label} {
|
|
116
|
-
flex: 1;
|
|
117
|
-
padding: 5px 0;
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
.${classes.prefix} {
|
|
122
|
-
color: ${text.secondary};
|
|
123
|
-
margin-right: ${spacing[2]}px;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
.${classes.suffix} {
|
|
127
|
-
color: ${text.disabled};
|
|
128
|
-
margin-left: ${spacing[2]}px;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
.${classes.dragMask} {
|
|
132
|
-
position: absolute;
|
|
133
|
-
inset: 0;
|
|
134
|
-
|
|
135
|
-
> div {
|
|
136
|
-
width: 100%;
|
|
137
|
-
height: 50%;
|
|
138
|
-
position: absolute;
|
|
139
|
-
left: 0;
|
|
140
|
-
|
|
141
|
-
&:before, &:after {
|
|
142
|
-
content: '';
|
|
143
|
-
display: none;
|
|
144
|
-
position: absolute;
|
|
145
|
-
pointer-events: none;
|
|
31
|
+
.${classes.node} {
|
|
32
|
+
display: flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
padding-right: ${spacing[2]}px;
|
|
35
|
+
border-radius: ${borderRadius}px;
|
|
36
|
+
transition: background-color .25s ${easing.easeOut};
|
|
37
|
+
touch-action: none;
|
|
38
|
+
-webkit-tap-highlight-color: transparent;
|
|
39
|
+
|
|
40
|
+
&[data-disabled=true] {
|
|
41
|
+
color: ${text.disabled};
|
|
42
|
+
cursor: not-allowed;
|
|
146
43
|
}
|
|
147
44
|
|
|
148
|
-
&:
|
|
149
|
-
|
|
150
|
-
height: 8px;
|
|
151
|
-
border: 2px solid ${colors.primary.main};
|
|
152
|
-
border-radius: 50%;
|
|
153
|
-
left: 0;
|
|
45
|
+
&:not([data-read-only=true]) {
|
|
46
|
+
cursor: pointer;
|
|
154
47
|
}
|
|
155
48
|
|
|
156
|
-
|
|
157
|
-
width:
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
left: 8px;
|
|
49
|
+
.${classes.indent} {
|
|
50
|
+
width: ${indent}px;
|
|
51
|
+
align-self: stretch;
|
|
52
|
+
display: flex;
|
|
161
53
|
}
|
|
162
54
|
|
|
163
|
-
|
|
164
|
-
|
|
55
|
+
.${classes.expand} {
|
|
56
|
+
width: 29px;
|
|
57
|
+
align-self: stretch;
|
|
58
|
+
align-items: center;
|
|
59
|
+
justify-content: center;
|
|
165
60
|
|
|
166
|
-
|
|
167
|
-
|
|
61
|
+
.${classes.icon} {
|
|
62
|
+
transition: rotate .25s ${easing.easeOut};
|
|
168
63
|
}
|
|
64
|
+
}
|
|
169
65
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
66
|
+
.${classes.contentWrap} {
|
|
67
|
+
flex: 1;
|
|
68
|
+
display: flex;
|
|
69
|
+
align-items: center;
|
|
70
|
+
position: relative;
|
|
173
71
|
}
|
|
174
72
|
|
|
175
|
-
|
|
176
|
-
|
|
73
|
+
.${classes.checkbox} {
|
|
74
|
+
margin-right: ${spacing[3]}px;
|
|
75
|
+
}
|
|
177
76
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
77
|
+
.${classes.label} {
|
|
78
|
+
flex: 1;
|
|
79
|
+
padding: 6px 0;
|
|
181
80
|
|
|
182
|
-
&:after {
|
|
183
|
-
bottom: -1px;
|
|
184
|
-
}
|
|
185
81
|
}
|
|
186
82
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
83
|
+
.${classes.prefix} {
|
|
84
|
+
color: ${text.secondary};
|
|
85
|
+
margin-right: ${spacing[2]}px;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.${classes.suffix} {
|
|
89
|
+
color: ${text.disabled};
|
|
90
|
+
margin-left: ${spacing[2]}px;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
&:not(:has([data-dragging=true])) { {
|
|
95
|
+
.${classes.node} {
|
|
96
|
+
&[data-selected=true] {
|
|
97
|
+
background-color: ${selectedBg};
|
|
98
|
+
|
|
99
|
+
&:hover {
|
|
100
|
+
background-color: ${selectedHover};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
&:active {
|
|
104
|
+
transition: background-color 0s;
|
|
105
|
+
background-color: ${selectedActive};
|
|
106
|
+
}
|
|
197
107
|
}
|
|
198
108
|
|
|
199
|
-
&:
|
|
200
|
-
|
|
201
|
-
left: 36px;
|
|
109
|
+
&:not([data-disabled=true]):not([data-selected=true]):hover {
|
|
110
|
+
background-color: ${hover};
|
|
202
111
|
}
|
|
203
|
-
}
|
|
204
112
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
113
|
+
&:not([data-disabled=true]):not([data-selected=true]):active {
|
|
114
|
+
transition: background-color 0s;
|
|
115
|
+
background-color: ${active};
|
|
208
116
|
}
|
|
209
117
|
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
&[data-show-line=true] {
|
|
215
|
-
.${classes.indent}:after {
|
|
216
|
-
content: '';
|
|
217
|
-
width: 1px;
|
|
218
|
-
height: 100%;
|
|
219
|
-
margin-left: 14px;
|
|
220
|
-
background-color: ${divider};
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
&, .${classes.levelBlock} {
|
|
225
|
-
&[data-active=true] {
|
|
226
|
-
outline: 1px dashed ${colors.primary.main};
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
&[data-sortable=true] {
|
|
231
|
-
.${classes.node} {
|
|
232
|
-
&[data-dragging=true] {
|
|
233
|
-
&, &:active {
|
|
234
|
-
background-color: ${selectedBg};
|
|
235
|
-
}
|
|
236
|
-
}
|
|
118
|
+
}}
|
|
237
119
|
|
|
238
|
-
|
|
239
|
-
|
|
120
|
+
&[data-show-line=true] {
|
|
121
|
+
.${classes.indent}:after {
|
|
122
|
+
content: '';
|
|
123
|
+
width: 1px;
|
|
124
|
+
height: 100%;
|
|
125
|
+
margin-left: 14px;
|
|
126
|
+
background-color: ${divider};
|
|
127
|
+
}
|
|
240
128
|
}
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
|
|
129
|
+
`;
|
|
130
|
+
}),
|
|
131
|
+
useDndStyle({ indent })
|
|
132
|
+
];
|
|
133
|
+
}
|
|
@@ -5,21 +5,17 @@ type TreeDndContextItem<T> = [T | undefined, Dispatch<SetStateAction<T | undefin
|
|
|
5
5
|
type ITreeDndContext = {
|
|
6
6
|
sortable: boolean;
|
|
7
7
|
showDragHandle: boolean;
|
|
8
|
-
containerRef: RefObject<HTMLDivElement | null>;
|
|
9
|
-
isOffsetSatisfied: [boolean, Dispatch<SetStateAction<boolean>>];
|
|
10
8
|
dragging: TreeDndContextItem<Id>;
|
|
11
|
-
overing:
|
|
12
|
-
placement:
|
|
9
|
+
overing: RefObject<Id | undefined>;
|
|
10
|
+
placement: RefObject<SortPlacement | undefined>;
|
|
13
11
|
onSort: TreeBaseProps<any>['onSort'];
|
|
14
|
-
overingTimer: RefObject<any>;
|
|
15
12
|
};
|
|
16
13
|
export declare const TreeDndContext: import("react").Context<ITreeDndContext>;
|
|
17
14
|
export declare function useTreeDndContext(): ITreeDndContext;
|
|
18
|
-
export declare const TreeDnd: import("react").MemoExoticComponent<({ sortable, showDragHandle, onSort,
|
|
15
|
+
export declare const TreeDnd: import("react").MemoExoticComponent<({ sortable, showDragHandle, onSort, children }: {
|
|
19
16
|
sortable: boolean;
|
|
20
17
|
showDragHandle: boolean;
|
|
21
18
|
onSort: TreeBaseProps<any>["onSort"];
|
|
22
|
-
containerRef: RefObject<HTMLDivElement | null>;
|
|
23
19
|
children: ReactNode;
|
|
24
20
|
}) => import("@emotion/react/jsx-runtime").JSX.Element>;
|
|
25
21
|
export {};
|
|
@@ -1,28 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
-
import { createContext, memo, useContext,
|
|
3
|
-
import {
|
|
4
|
-
import { classes } from './tree.style';
|
|
2
|
+
import { createContext, memo, useContext, useRef, useState } from 'react';
|
|
3
|
+
import { treeDndClasses } from './treeDnd.style';
|
|
5
4
|
export const TreeDndContext = createContext({});
|
|
6
5
|
export function useTreeDndContext() {
|
|
7
6
|
return useContext(TreeDndContext);
|
|
8
7
|
}
|
|
9
|
-
export const TreeDnd = memo(({ sortable, showDragHandle, onSort,
|
|
10
|
-
const isOffsetSatisfied = useState(false);
|
|
8
|
+
export const TreeDnd = memo(({ sortable, showDragHandle, onSort, children }) => {
|
|
11
9
|
const dragging = useState(void 0);
|
|
12
|
-
const overing =
|
|
13
|
-
const placement =
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
if (dragging[0]) {
|
|
16
|
-
document.documentElement.style.cursor = 'grabbing';
|
|
17
|
-
}
|
|
18
|
-
return () => {
|
|
19
|
-
document.documentElement.style.cursor = '';
|
|
20
|
-
};
|
|
21
|
-
}, [dragging[0]]);
|
|
22
|
-
const overingTimer = useRef(void 0);
|
|
10
|
+
const overing = useRef(void 0);
|
|
11
|
+
const placement = useRef(void 0);
|
|
23
12
|
return (_jsx(TreeDndContext, { value: {
|
|
24
|
-
sortable, showDragHandle, onSort,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}, children: _jsx("div", { className: classes.container, "data-dragging": !!dragging[0], children: children }) }));
|
|
13
|
+
sortable, showDragHandle, onSort,
|
|
14
|
+
dragging, overing, placement
|
|
15
|
+
}, children: _jsx("div", { className: treeDndClasses.levelBlock, children: children }) }));
|
|
28
16
|
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const treeDndClasses: {
|
|
2
|
+
mask: string;
|
|
3
|
+
child: string;
|
|
4
|
+
levelBlock: string;
|
|
5
|
+
dragHandle: string;
|
|
6
|
+
predecessor: string;
|
|
7
|
+
sibling: string;
|
|
8
|
+
siblingPrev: string;
|
|
9
|
+
siblingNext: string;
|
|
10
|
+
} & {
|
|
11
|
+
root: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function useStyle({ indent }: {
|
|
14
|
+
indent: number;
|
|
15
|
+
}): import("@emotion/react").SerializedStyles;
|