@canlooks/can-ui 0.0.95 → 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.
Files changed (81) hide show
  1. package/dist/cjs/components/accordion/accordion.style.d.ts +1 -1
  2. package/dist/cjs/components/alert/alert.style.d.ts +3 -3
  3. package/dist/cjs/components/button/button.style.d.ts +1 -1
  4. package/dist/cjs/components/checkboxBase/checkboxBase.style.d.ts +2 -2
  5. package/dist/cjs/components/clickAway/clickAway.d.ts +27 -27
  6. package/dist/cjs/components/dataGrid/dataGrid.style.d.ts +1 -1
  7. package/dist/cjs/components/descriptions/descriptions.style.d.ts +1 -1
  8. package/dist/cjs/components/dialog/dialog.style.d.ts +3 -3
  9. package/dist/cjs/components/drawer/drawer.d.ts +3 -1
  10. package/dist/cjs/components/drawer/drawer.js +2 -2
  11. package/dist/cjs/components/inputBase/inputBase.style.d.ts +2 -2
  12. package/dist/cjs/components/menuItem/menuItem.d.ts +4 -0
  13. package/dist/cjs/components/menuItem/menuItem.style.d.ts +2 -2
  14. package/dist/cjs/components/optionsBase/optionsBase.js +2 -1
  15. package/dist/cjs/components/palette/palette.style.d.ts +1 -1
  16. package/dist/cjs/components/pickerDialog/pickerDialog.style.d.ts +1 -1
  17. package/dist/cjs/components/progress/progress.js +2 -1
  18. package/dist/cjs/components/progress/progress.style.d.ts +1 -1
  19. package/dist/cjs/components/resizable/resizable.style.d.ts +1 -1
  20. package/dist/cjs/components/segmented/segmented.style.d.ts +1 -1
  21. package/dist/cjs/components/selectionContext/selectionContext.d.ts +2 -0
  22. package/dist/cjs/components/selectionContext/selectionHook.js +2 -1
  23. package/dist/cjs/components/snackbarBase/snackbarBase.style.d.ts +1 -1
  24. package/dist/cjs/components/status/status.style.d.ts +1 -1
  25. package/dist/cjs/components/tabs/tabs.style.d.ts +4 -4
  26. package/dist/cjs/components/tag/tag.style.d.ts +2 -2
  27. package/dist/cjs/components/transfer/transfer.style.d.ts +2 -2
  28. package/dist/cjs/components/tree/tree.d.ts +2 -2
  29. package/dist/cjs/components/tree/tree.js +15 -13
  30. package/dist/cjs/components/tree/tree.style.d.ts +5 -9
  31. package/dist/cjs/components/tree/tree.style.js +96 -206
  32. package/dist/cjs/components/tree/treeDnd.d.ts +3 -7
  33. package/dist/cjs/components/tree/treeDnd.js +7 -19
  34. package/dist/cjs/components/tree/treeDnd.style.d.ts +15 -0
  35. package/dist/cjs/components/tree/treeDnd.style.js +191 -0
  36. package/dist/cjs/components/tree/treeNode.d.ts +4 -4
  37. package/dist/cjs/components/tree/treeNode.js +82 -69
  38. package/dist/cjs/components/upload/upload.style.d.ts +1 -1
  39. package/dist/cjs/utils/dnd.d.ts +11 -3
  40. package/dist/cjs/utils/dnd.js +45 -2
  41. package/dist/esm/components/accordion/accordion.style.d.ts +1 -1
  42. package/dist/esm/components/alert/alert.style.d.ts +3 -3
  43. package/dist/esm/components/button/button.style.d.ts +1 -1
  44. package/dist/esm/components/checkboxBase/checkboxBase.style.d.ts +2 -2
  45. package/dist/esm/components/clickAway/clickAway.d.ts +27 -27
  46. package/dist/esm/components/dataGrid/dataGrid.style.d.ts +1 -1
  47. package/dist/esm/components/descriptions/descriptions.style.d.ts +1 -1
  48. package/dist/esm/components/dialog/dialog.style.d.ts +3 -3
  49. package/dist/esm/components/drawer/drawer.d.ts +3 -1
  50. package/dist/esm/components/drawer/drawer.js +2 -2
  51. package/dist/esm/components/inputBase/inputBase.style.d.ts +2 -2
  52. package/dist/esm/components/menuItem/menuItem.d.ts +4 -0
  53. package/dist/esm/components/menuItem/menuItem.style.d.ts +2 -2
  54. package/dist/esm/components/optionsBase/optionsBase.js +2 -1
  55. package/dist/esm/components/palette/palette.style.d.ts +1 -1
  56. package/dist/esm/components/pickerDialog/pickerDialog.style.d.ts +1 -1
  57. package/dist/esm/components/progress/progress.js +2 -1
  58. package/dist/esm/components/progress/progress.style.d.ts +1 -1
  59. package/dist/esm/components/resizable/resizable.style.d.ts +1 -1
  60. package/dist/esm/components/segmented/segmented.style.d.ts +1 -1
  61. package/dist/esm/components/selectionContext/selectionContext.d.ts +2 -0
  62. package/dist/esm/components/selectionContext/selectionHook.js +2 -1
  63. package/dist/esm/components/snackbarBase/snackbarBase.style.d.ts +1 -1
  64. package/dist/esm/components/status/status.style.d.ts +1 -1
  65. package/dist/esm/components/tabs/tabs.style.d.ts +4 -4
  66. package/dist/esm/components/tag/tag.style.d.ts +2 -2
  67. package/dist/esm/components/transfer/transfer.style.d.ts +2 -2
  68. package/dist/esm/components/tree/tree.d.ts +2 -2
  69. package/dist/esm/components/tree/tree.js +18 -16
  70. package/dist/esm/components/tree/tree.style.d.ts +5 -9
  71. package/dist/esm/components/tree/tree.style.js +95 -206
  72. package/dist/esm/components/tree/treeDnd.d.ts +3 -7
  73. package/dist/esm/components/tree/treeDnd.js +8 -20
  74. package/dist/esm/components/tree/treeDnd.style.d.ts +15 -0
  75. package/dist/esm/components/tree/treeDnd.style.js +186 -0
  76. package/dist/esm/components/tree/treeNode.d.ts +4 -4
  77. package/dist/esm/components/tree/treeNode.js +82 -69
  78. package/dist/esm/components/upload/upload.style.d.ts +1 -1
  79. package/dist/esm/utils/dnd.d.ts +11 -3
  80. package/dist/esm/utils/dnd.js +44 -2
  81. package/package.json +1 -1
@@ -3,8 +3,8 @@ export declare const classes: {
3
3
  info: string;
4
4
  track: string;
5
5
  svg: string;
6
- icon: string;
7
6
  bar: string;
7
+ icon: string;
8
8
  } & {
9
9
  root: string;
10
10
  };
@@ -1,8 +1,8 @@
1
1
  import { Handle, ResizableProps } from './resizable';
2
2
  export declare const classes: {
3
+ container: string;
3
4
  corner: string;
4
5
  edge: string;
5
- container: string;
6
6
  } & {
7
7
  root: string;
8
8
  };
@@ -3,8 +3,8 @@ export declare const classes: {
3
3
  label: string;
4
4
  option: string;
5
5
  prefix: string;
6
- indicator: string;
7
6
  suffix: string;
7
+ indicator: string;
8
8
  } & {
9
9
  root: string;
10
10
  };
@@ -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);
@@ -2,8 +2,8 @@ export declare const classes: {
2
2
  text: string;
3
3
  title: string;
4
4
  content: string;
5
- close: string;
6
5
  icon: string;
6
+ close: string;
7
7
  item: string;
8
8
  titleRow: string;
9
9
  itemWrap: string;
@@ -1,7 +1,7 @@
1
1
  export declare const classes: {
2
2
  label: string;
3
- icon: string;
4
3
  dot: string;
4
+ icon: string;
5
5
  } & {
6
6
  root: string;
7
7
  };
@@ -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;
@@ -1,9 +1,9 @@
1
1
  import { TagProps } from './tag';
2
2
  export declare const classes: {
3
- content: string;
4
- close: string;
5
3
  prefix: string;
4
+ content: string;
6
5
  suffix: string;
6
+ close: string;
7
7
  } & {
8
8
  root: string;
9
9
  };
@@ -2,11 +2,11 @@ export declare const classes: {
2
2
  info: string;
3
3
  header: string;
4
4
  title: string;
5
- list: string;
6
5
  checkbox: string;
6
+ list: string;
7
+ buttons: string;
7
8
  count: string;
8
9
  panel: string;
9
- buttons: string;
10
10
  } & {
11
11
  root: string;
12
12
  };
@@ -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 | 'child';
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, useRef } from 'react';
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, style } from './tree.style';
7
- import { cloneRef, clsx, useTreeSearch } from '../../utils';
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, ref: cloneRef(containerRef, props.ref), css: style, className: clsx(classes.root, classes.levelBlock, props.className), "data-show-line": showLine, "data-sortable": sortable, children: [searchable &&
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, { ...selectionContextProps, children: _jsx(TreeContext, { value: useMemo(() => ({
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, containerRef: containerRef, children: useMemo(() => {
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 }, i) => {
72
- const currentValue = nodeProps[primaryKey];
69
+ return arr?.map(({ _isLast, _parentId, ...nodeProps }) => {
70
+ const currentId = nodeProps[primaryKey];
73
71
  const label = nodeProps[labelKey];
74
- return (_createElement(TreeNode, { ...nodeProps, key: currentValue, value: currentValue, label: typeof label === 'string' && deferredSearchValue
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(nodeProps[childrenKey])));
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 const style: () => import("@emotion/react").SerializedStyles;
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, defineCss } from '../../utils';
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 const style = defineCss(({ spacing, mode, borderRadius, text, easing, gray, divider, colors }) => {
23
- const c = Color(colors.primary.main);
24
- const hover = gray(mode === 'light' ? .05 : .2);
25
- const active = gray(mode === 'light' ? .1 : .12);
26
- const selectedBg = c.alpha(mode === 'light' ? .1 : .2).string();
27
- const selectedHover = c.alpha(mode === 'light' ? .07 : .17).string();
28
- const selectedActive = c.alpha(mode === 'light' ? .13 : .23).string();
29
- return css `
30
- .${classes.search} {
31
- margin-bottom: ${spacing[3]}px;
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
- &:active {
66
- transition: background-color 0s;
67
- background-color: ${selectedActive};
68
- }
69
- }
70
-
71
- &:not([data-disabled=true]):not([data-selected=true]):hover {
72
- background-color: ${hover};
73
- }
74
-
75
- &:not([data-disabled=true]):not([data-selected=true]):active {
76
- transition: background-color 0s;
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
- &:before {
149
- width: 8px;
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
- &:after {
157
- width: 100%;
158
- height: 2px;
159
- background: ${colors.primary.main};
160
- left: 8px;
49
+ .${classes.indent} {
50
+ width: ${indent}px;
51
+ align-self: stretch;
52
+ display: flex;
161
53
  }
162
54
 
163
- &.${classes.dragMaskPrev} {
164
- top: 0;
55
+ .${classes.expand} {
56
+ width: 29px;
57
+ align-self: stretch;
58
+ align-items: center;
59
+ justify-content: center;
165
60
 
166
- &:before {
167
- top: -4px;
61
+ .${classes.icon} {
62
+ transition: rotate .25s ${easing.easeOut};
168
63
  }
64
+ }
169
65
 
170
- &:after {
171
- top: -1px;
172
- }
66
+ .${classes.contentWrap} {
67
+ flex: 1;
68
+ display: flex;
69
+ align-items: center;
70
+ position: relative;
173
71
  }
174
72
 
175
- &.${classes.dragMaskNext} {
176
- bottom: 0;
73
+ .${classes.checkbox} {
74
+ margin-right: ${spacing[3]}px;
75
+ }
177
76
 
178
- &:before {
179
- bottom: -4px;
180
- }
77
+ .${classes.label} {
78
+ flex: 1;
79
+ padding: 6px 0;
181
80
 
182
- &:after {
183
- bottom: -1px;
184
- }
185
81
  }
186
82
 
187
- &[data-offset=true] {
188
- &:before {
189
- width: 10px;
190
- border-top: 0;
191
- border-right: 0;
192
- border-bottom: 2px dashed ${colors.primary.main};
193
- border-left: 2px dashed ${colors.primary.main};
194
- border-radius: 0;
195
- left: 24px;
196
- bottom: -1px;
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
- &:after {
200
- width: calc(100% - 36px);
201
- left: 36px;
109
+ &:not([data-disabled=true]):not([data-selected=true]):hover {
110
+ background-color: ${hover};
202
111
  }
203
- }
204
112
 
205
- &[data-overing=true] {
206
- &:before, &:after {
207
- display: block;
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
- &:has(+ .${classes.levelBlock}[data-active=true]) {
239
- outline: 1px solid ${colors.primary.main};
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: TreeDndContextItem<Id>;
12
- placement: [RefObject<SortPlacement | undefined>, Dispatch<SetStateAction<SortPlacement | undefined>>];
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, containerRef, children }: {
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, useEffect, useRef, useState } from 'react';
3
- import { useSyncState } from '../../utils';
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, containerRef, children }) => {
10
- const isOffsetSatisfied = useState(false);
8
+ export const TreeDnd = memo(({ sortable, showDragHandle, onSort, children }) => {
11
9
  const dragging = useState(void 0);
12
- const overing = useState(void 0);
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]]);
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, containerRef,
25
- isOffsetSatisfied, dragging, overing, placement,
26
- overingTimer
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;