@king-design/intact 3.1.1 → 3.1.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.
Files changed (239) hide show
  1. package/components/affix/styles.ts +4 -2
  2. package/components/badge/index.vdt +1 -1
  3. package/components/badge/styles.ts +4 -3
  4. package/components/breadcrumb/index.vdt +1 -1
  5. package/components/breadcrumb/styles.ts +4 -2
  6. package/components/button/styles.ts +7 -5
  7. package/components/card/styles.ts +4 -2
  8. package/components/carousel/styles.ts +7 -4
  9. package/components/cascader/index.vdt +2 -1
  10. package/components/cascader/styles.ts +7 -4
  11. package/components/checkbox/index.vdt +1 -1
  12. package/components/checkbox/styles.ts +4 -2
  13. package/components/code/styles.ts +3 -2
  14. package/components/collapse/index.spec.ts +1 -1
  15. package/components/collapse/styles.ts +7 -4
  16. package/components/colorpicker/styles.ts +7 -4
  17. package/components/copy/styles.ts +3 -2
  18. package/components/datepicker/styles.ts +10 -6
  19. package/components/diagram/styles.ts +3 -2
  20. package/components/dialog/styles.ts +10 -6
  21. package/components/drawer/styles.ts +4 -2
  22. package/components/dropdown/styles.ts +7 -4
  23. package/components/editable/styles.ts +4 -2
  24. package/components/form/styles.ts +7 -4
  25. package/components/grid/styles.ts +12 -9
  26. package/components/icon/index.vdt +1 -1
  27. package/components/icon/styles.ts +4 -2
  28. package/components/input/styles.ts +8 -5
  29. package/components/layout/styles.ts +13 -9
  30. package/components/menu/demos/recursive.md +340 -0
  31. package/components/menu/styles.ts +21 -16
  32. package/components/message/styles.ts +7 -5
  33. package/components/pagination/styles.ts +4 -2
  34. package/components/popover/content.vdt +1 -1
  35. package/components/popover/styles.ts +4 -2
  36. package/components/progress/styles.ts +4 -4
  37. package/components/radio/styles.ts +4 -2
  38. package/components/rate/styles.ts +4 -2
  39. package/components/scrollSelect/styles.ts +4 -2
  40. package/components/select/base.ts +3 -2
  41. package/components/select/base.vdt +1 -1
  42. package/components/select/styles.ts +10 -6
  43. package/components/skeleton/styles.ts +7 -4
  44. package/components/slider/styles.ts +4 -2
  45. package/components/spin/styles.ts +4 -4
  46. package/components/spinner/styles.ts +4 -3
  47. package/components/split/styles.ts +4 -2
  48. package/components/steps/index.vdt +2 -2
  49. package/components/steps/styles.ts +7 -5
  50. package/components/switch/styles.ts +4 -2
  51. package/components/table/column.ts +2 -0
  52. package/components/table/column.vdt +7 -3
  53. package/components/table/demos/basic.md +2 -2
  54. package/components/table/demos/fixColumn.md +3 -1
  55. package/components/table/demos/groupHeader.md +11 -11
  56. package/components/table/demos/scheme.md +1 -1
  57. package/components/table/index.spec.ts +8 -3
  58. package/components/table/styles.ts +11 -8
  59. package/components/table/table.vdt +3 -4
  60. package/components/table/useColumns.ts +1 -0
  61. package/components/table/useFixedColumns.ts +27 -49
  62. package/components/table/useGroup.ts +5 -0
  63. package/components/table/useResizable.ts +38 -10
  64. package/components/table/useWidth.ts +3 -0
  65. package/components/tabs/styles.ts +4 -2
  66. package/components/tag/styles.ts +7 -4
  67. package/components/timeline/styles.ts +7 -5
  68. package/components/timepicker/styles.ts +4 -2
  69. package/components/tip/styles.ts +4 -2
  70. package/components/tooltip/content.vdt +1 -1
  71. package/components/tooltip/styles.ts +4 -2
  72. package/components/transfer/styles.ts +4 -2
  73. package/components/tree/demos/checkbox.md +1 -0
  74. package/components/tree/demos/contextmenu.md +10 -1
  75. package/components/tree/index.spec.ts +7 -0
  76. package/components/tree/styles.ts +4 -2
  77. package/components/tree/useChecked.ts +3 -0
  78. package/components/treeSelect/styles.ts +4 -2
  79. package/components/upload/styles.ts +7 -4
  80. package/components/utils.ts +10 -4
  81. package/components/wave/styles.ts +4 -2
  82. package/es/components/affix/styles.d.ts +4 -1
  83. package/es/components/affix/styles.js +4 -2
  84. package/es/components/badge/index.vdt.js +1 -1
  85. package/es/components/badge/styles.d.ts +4 -1
  86. package/es/components/badge/styles.js +4 -2
  87. package/es/components/breadcrumb/index.vdt.js +1 -1
  88. package/es/components/breadcrumb/styles.d.ts +4 -1
  89. package/es/components/breadcrumb/styles.js +4 -2
  90. package/es/components/button/styles.d.ts +8 -2
  91. package/es/components/button/styles.js +7 -4
  92. package/es/components/card/styles.d.ts +4 -1
  93. package/es/components/card/styles.js +4 -2
  94. package/es/components/carousel/styles.d.ts +8 -2
  95. package/es/components/carousel/styles.js +7 -4
  96. package/es/components/cascader/index.vdt.js +3 -1
  97. package/es/components/cascader/styles.d.ts +8 -2
  98. package/es/components/cascader/styles.js +7 -4
  99. package/es/components/checkbox/index.vdt.js +1 -1
  100. package/es/components/checkbox/styles.d.ts +4 -1
  101. package/es/components/checkbox/styles.js +4 -2
  102. package/es/components/code/styles.d.ts +4 -1
  103. package/es/components/code/styles.js +3 -2
  104. package/es/components/collapse/index.spec.js +1 -1
  105. package/es/components/collapse/styles.d.ts +8 -2
  106. package/es/components/collapse/styles.js +7 -4
  107. package/es/components/colorpicker/styles.d.ts +8 -2
  108. package/es/components/colorpicker/styles.js +7 -4
  109. package/es/components/copy/styles.d.ts +4 -1
  110. package/es/components/copy/styles.js +3 -2
  111. package/es/components/datepicker/styles.d.ts +12 -3
  112. package/es/components/datepicker/styles.js +10 -6
  113. package/es/components/diagram/styles.d.ts +4 -1
  114. package/es/components/diagram/styles.js +3 -2
  115. package/es/components/dialog/styles.d.ts +12 -3
  116. package/es/components/dialog/styles.js +10 -6
  117. package/es/components/drawer/styles.d.ts +4 -1
  118. package/es/components/drawer/styles.js +4 -2
  119. package/es/components/dropdown/styles.d.ts +8 -2
  120. package/es/components/dropdown/styles.js +7 -4
  121. package/es/components/editable/styles.d.ts +4 -1
  122. package/es/components/editable/styles.js +4 -2
  123. package/es/components/form/styles.d.ts +8 -2
  124. package/es/components/form/styles.js +7 -4
  125. package/es/components/grid/styles.d.ts +8 -2
  126. package/es/components/grid/styles.js +12 -13
  127. package/es/components/icon/index.vdt.js +1 -1
  128. package/es/components/icon/styles.d.ts +4 -1
  129. package/es/components/icon/styles.js +4 -2
  130. package/es/components/input/styles.d.ts +8 -2
  131. package/es/components/input/styles.js +7 -4
  132. package/es/components/layout/styles.d.ts +16 -4
  133. package/es/components/layout/styles.js +13 -8
  134. package/es/components/menu/styles.d.ts +16 -4
  135. package/es/components/menu/styles.js +14 -9
  136. package/es/components/message/styles.d.ts +8 -2
  137. package/es/components/message/styles.js +7 -4
  138. package/es/components/pagination/styles.d.ts +4 -1
  139. package/es/components/pagination/styles.js +4 -2
  140. package/es/components/popover/content.vdt.js +1 -1
  141. package/es/components/popover/styles.d.ts +4 -1
  142. package/es/components/popover/styles.js +4 -2
  143. package/es/components/progress/styles.d.ts +4 -1
  144. package/es/components/progress/styles.js +4 -2
  145. package/es/components/radio/styles.d.ts +4 -1
  146. package/es/components/radio/styles.js +4 -2
  147. package/es/components/rate/styles.d.ts +4 -1
  148. package/es/components/rate/styles.js +4 -2
  149. package/es/components/scrollSelect/styles.d.ts +4 -1
  150. package/es/components/scrollSelect/styles.js +4 -2
  151. package/es/components/select/base.js +3 -1
  152. package/es/components/select/base.vdt.js +1 -1
  153. package/es/components/select/styles.d.ts +12 -3
  154. package/es/components/select/styles.js +10 -6
  155. package/es/components/skeleton/styles.d.ts +8 -2
  156. package/es/components/skeleton/styles.js +7 -4
  157. package/es/components/slider/styles.d.ts +4 -1
  158. package/es/components/slider/styles.js +4 -2
  159. package/es/components/spin/styles.d.ts +4 -1
  160. package/es/components/spin/styles.js +4 -2
  161. package/es/components/spinner/styles.d.ts +4 -1
  162. package/es/components/spinner/styles.js +4 -2
  163. package/es/components/split/styles.d.ts +4 -1
  164. package/es/components/split/styles.js +4 -2
  165. package/es/components/steps/index.vdt.js +2 -2
  166. package/es/components/steps/styles.d.ts +4 -3
  167. package/es/components/steps/styles.js +9 -4
  168. package/es/components/switch/styles.d.ts +4 -1
  169. package/es/components/switch/styles.js +4 -2
  170. package/es/components/table/column.d.ts +1 -0
  171. package/es/components/table/column.js +2 -1
  172. package/es/components/table/column.vdt.js +9 -3
  173. package/es/components/table/index.spec.js +18 -11
  174. package/es/components/table/styles.d.ts +8 -2
  175. package/es/components/table/styles.js +8 -5
  176. package/es/components/table/table.vdt.js +3 -4
  177. package/es/components/table/useColumns.js +1 -0
  178. package/es/components/table/useFixedColumns.d.ts +3 -3
  179. package/es/components/table/useFixedColumns.js +27 -46
  180. package/es/components/table/useGroup.d.ts +1 -0
  181. package/es/components/table/useGroup.js +11 -1
  182. package/es/components/table/useResizable.js +41 -5
  183. package/es/components/table/useWidth.js +3 -0
  184. package/es/components/tabs/styles.d.ts +4 -1
  185. package/es/components/tabs/styles.js +4 -2
  186. package/es/components/tag/styles.d.ts +8 -2
  187. package/es/components/tag/styles.js +7 -4
  188. package/es/components/timeline/styles.d.ts +8 -2
  189. package/es/components/timeline/styles.js +7 -5
  190. package/es/components/timepicker/styles.d.ts +4 -1
  191. package/es/components/timepicker/styles.js +4 -2
  192. package/es/components/tip/styles.d.ts +4 -1
  193. package/es/components/tip/styles.js +4 -2
  194. package/es/components/tooltip/content.vdt.js +1 -1
  195. package/es/components/tooltip/styles.d.ts +4 -1
  196. package/es/components/tooltip/styles.js +4 -2
  197. package/es/components/transfer/styles.d.ts +4 -1
  198. package/es/components/transfer/styles.js +4 -2
  199. package/es/components/tree/index.spec.js +13 -1
  200. package/es/components/tree/styles.d.ts +4 -1
  201. package/es/components/tree/styles.js +4 -2
  202. package/es/components/tree/useChecked.js +4 -0
  203. package/es/components/treeSelect/styles.d.ts +4 -1
  204. package/es/components/treeSelect/styles.js +4 -2
  205. package/es/components/upload/styles.d.ts +8 -2
  206. package/es/components/upload/styles.js +7 -4
  207. package/es/components/utils.d.ts +10 -2
  208. package/es/components/utils.js +9 -2
  209. package/es/components/wave/styles.d.ts +4 -1
  210. package/es/components/wave/styles.js +4 -2
  211. package/es/i18n/en-US.d.ts +1 -0
  212. package/es/i18n/en-US.js +1 -0
  213. package/es/index.d.ts +2 -2
  214. package/es/index.js +2 -2
  215. package/es/site/data/components/menu/demos/recursive/index.d.ts +29 -0
  216. package/es/site/data/components/menu/demos/recursive/index.js +57 -0
  217. package/es/site/data/components/menu/demos/recursive/react.d.ts +2 -0
  218. package/es/site/data/components/menu/demos/recursive/react.js +69 -0
  219. package/es/site/data/components/table/demos/basic/react.js +4 -2
  220. package/es/site/data/components/table/demos/fixColumn/react.js +2 -1
  221. package/es/site/data/components/table/demos/groupHeader/react.js +11 -20
  222. package/es/site/data/components/table/demos/scheme/react.js +2 -1
  223. package/es/site/data/components/tree/demos/checkbox/index.d.ts +12 -2
  224. package/es/site/data/components/tree/demos/checkbox/index.js +1 -0
  225. package/es/site/data/components/tree/demos/checkbox/react.d.ts +12 -2
  226. package/es/site/data/components/tree/demos/checkbox/react.js +1 -0
  227. package/es/site/data/components/tree/demos/contextmenu/index.d.ts +1 -0
  228. package/es/site/data/components/tree/demos/contextmenu/index.js +1 -0
  229. package/es/site/data/components/tree/demos/contextmenu/react.d.ts +1 -0
  230. package/es/site/data/components/tree/demos/contextmenu/react.js +1 -0
  231. package/es/site/src/components/article/index.js +6 -2
  232. package/es/styles/fonts/iconfont.d.ts +4 -1
  233. package/es/styles/fonts/iconfont.js +1 -1
  234. package/es/styles/global.js +1 -1
  235. package/i18n/en-US.ts +1 -0
  236. package/index.ts +2 -2
  237. package/package.json +3 -3
  238. package/styles/fonts/iconfont.ts +2 -2
  239. package/styles/global.ts +22 -0
@@ -2,6 +2,7 @@ import {css} from '@emotion/css';
2
2
  import {theme, setDefault} from '../../styles/theme';
3
3
  import {deepDefaults, palette} from '../../styles/utils';
4
4
  import '../../styles/global';
5
+ import { cache } from '../utils';
5
6
 
6
7
  const defaults = {
7
8
  get transition() { return theme.transition.large },
@@ -72,9 +73,11 @@ const aligns = ['left', 'right', 'center'];
72
73
  let table: typeof defaults;
73
74
  setDefault(() => {
74
75
  table = deepDefaults(theme, {table: defaults}).table;
76
+ makeStyles?.clearCache();
77
+ makeGroupMenuStyles?.clearCache();
75
78
  });
76
79
 
77
- export function makeStyles(k: string) {
80
+ export const makeStyles = cache(function makeStyles(k: string) {
78
81
  return css`
79
82
  font-size: ${table.fontSize};
80
83
  color: ${table.color};
@@ -90,10 +93,10 @@ export function makeStyles(k: string) {
90
93
  // border-collapse: collapse;
91
94
  border-spacing: 0;
92
95
  table-layout: fixed;
93
- td,
94
- th {
95
- transition: all ${table.transition};
96
- }
96
+ // td,
97
+ // th {
98
+ // transition: all ${table.transition};
99
+ // }
97
100
  }
98
101
 
99
102
  // thead
@@ -369,9 +372,9 @@ export function makeStyles(k: string) {
369
372
  }
370
373
  }
371
374
  `;
372
- }
375
+ });
373
376
 
374
- export function makeGroupMenuStyles(k: string) {
377
+ export const makeGroupMenuStyles = cache(function makeGroupMenuStyles(k: string) {
375
378
  return css`
376
379
  min-width: ${table.group.menuMinWidth} !important;
377
380
  .${k}-dropdown-item.${k}-active {
@@ -394,4 +397,4 @@ export function makeGroupMenuStyles(k: string) {
394
397
  }
395
398
  }
396
399
  `
397
- }
400
+ });
@@ -29,7 +29,7 @@ const {
29
29
  } = this.get();
30
30
  const animation = !Array.isArray(_animation) ? [_animation, _animation] : _animation;
31
31
  const {columns, cols, maxRows, maxCols} = this.columns.getData();
32
- const {scrollPosition, hasFixed, getHasFixedLeft, getOffsetMap} = this.fixedColumns;
32
+ const {scrollPosition, hasFixed, getHasFixedLeft, offsetMap} = this.fixedColumns;
33
33
  const {scrollRef} = this.scroll;
34
34
  const {stickHeader, excludeStickHeader, elementRef, headRef} = this.stickyHeader;
35
35
  const { k } = this.config;
@@ -66,13 +66,12 @@ const hasData = data && data.length;
66
66
  const hasFixedLeft = getHasFixedLeft();
67
67
  const {getAllCheckedStatus, toggleCheckedAll, getAllStatus, onChangeChecked} = this.checked;
68
68
  const allCheckedStatus = getAllCheckedStatus();
69
- const offsetMap = getOffsetMap();
70
69
  const thead = hideHeader ? null : (
71
70
  <TableContext.Provider value={checkType}>
72
71
  <GroupContext.Provider value={{group, onChange: this.onChangeGroup}}>
73
72
  <SortableContext.Provider value={{sort, onChange: this.sortable.onChange}}>
74
73
  <ResizableContext.Provider value={{resizable, onStart}}>
75
- <FixedColumnsContext.Provider value={offsetMap}>
74
+ <FixedColumnsContext.Provider value={offsetMap.value}>
76
75
  <thead>
77
76
  <tr v-for={columns}>
78
77
  {(() => {
@@ -158,7 +157,7 @@ const tbody = (
158
157
  indent={indentSize}
159
158
  onToggleSpreadRow={toggleSpreadRow}
160
159
  onBeforeUnmount={this.resetRowStatus.onRowBeforeUnmount}
161
- offsetMap={offsetMap}
160
+ offsetMap={offsetMap.value}
162
161
  animation={animation[1]}
163
162
 
164
163
  draggable={draggable}
@@ -51,6 +51,7 @@ export function useColumns() {
51
51
  ret = true;
52
52
 
53
53
  const clonedVNode = directClone(vNode) as VNodeComponentClass<TableColumn>;
54
+ if (currentVNode) (currentVNode.props as any).nextVNode = clonedVNode;
54
55
  const props = {
55
56
  ...clonedVNode.props!,
56
57
  cols: 0,
@@ -2,21 +2,19 @@ import {
2
2
  useInstance,
3
3
  VNodeComponentClass,
4
4
  Props,
5
- directClone,
6
- onMounted,
7
- onUnmounted,
8
- RefObject,
9
5
  Key,
6
+ findDomFromVNode,
7
+ nextTick,
10
8
  } from 'intact';
11
9
  import {TableColumn, TableColumnProps} from './column';
12
10
  import {useState} from '../../hooks/useState';
13
11
  import {cx} from '@emotion/css';
14
- import type {TableProps, TableRowKey} from './table';
15
- import {isNullOrUndefined, isString, error} from 'intact-shared';
16
- import {throttle} from '../utils';
12
+ import type {TableProps, TableRowKey, Table} from './table';
17
13
  import {State, watchState} from '../../hooks/useState';
18
14
  import {createContext} from '../context';
19
15
  import type {useScroll} from './useScroll';
16
+ import { useResizeObserver } from '../../hooks/useResizeObserver';
17
+ import { isEqualObject } from '../utils';
20
18
 
21
19
  type ScrollPosition = 'left' | 'middle' | 'right';
22
20
  type FixedInfo = {
@@ -31,48 +29,35 @@ export function useFixedColumns(
31
29
  {scrollRef, callbacks}: ReturnType<typeof useScroll>,
32
30
  widthMap: State<Record<TableRowKey, number>>,
33
31
  ) {
34
- const instance = useInstance()!;
32
+ const instance = useInstance() as Table;
35
33
  const scrollPosition = useState<ScrollPosition | null>(null);
36
34
  const hasFixed = useState<boolean>(false);
35
+ const offsetMap = useState<Record<Key, number>>({}, isEqualObject);
37
36
  let hasFixedLeft = false;
38
37
  let hasFixedRight = false;
39
- let offsetMap: Record<Key, number> = {};
40
38
 
41
39
  callbacks.push(setScrollPosition);
42
40
 
43
- instance.on('$receive:children', handleFixedColumns);
44
- watchState(widthMap, () => {
45
- handleFixedColumns();
46
- updateScrollPositionOnResize();
47
- });
48
-
49
- const throttleUpdate = throttle(() => {
50
- if (instance.$unmounted) return;
51
- updateScrollPositionOnResize();
52
- }, 100);
41
+ instance.watch('children', handleFixedColumnsAndUpdate, { presented: true });
42
+ watchState(widthMap, () => nextTick(handleFixedColumnsAndUpdate));
43
+ useResizeObserver(scrollRef, handleFixedColumnsAndUpdate, true);
53
44
 
54
- onMounted(() => {
45
+ function handleFixedColumnsAndUpdate() {
46
+ handleFixedColumns();
55
47
  updateScrollPositionOnResize();
56
- window.addEventListener('resize', throttleUpdate);
57
- });
58
-
59
- onUnmounted(() => {
60
- window.removeEventListener('resize', throttleUpdate);
61
- });
48
+ }
62
49
 
63
50
  function handleFixedColumns() {
64
51
  const columns = getColumns();
65
52
 
53
+ let _offsetMap: Record<Key, number> = {};
66
54
  hasFixedLeft = false;
67
55
  hasFixedRight = false;
68
- offsetMap = {};
69
56
 
70
57
  columns.forEach((columns, row) => {
71
- let offset = 0;
72
58
  columns.forEach((vNode, col) => {
73
59
  const props = vNode.props as Props<TableColumnProps>;
74
60
  const key = props.key;
75
- offsetMap[key] = 0;
76
61
 
77
62
  const fixed = props.fixed;
78
63
  if (fixed === 'left') {
@@ -81,34 +66,29 @@ export function useFixedColumns(
81
66
  while (prevVNode) {
82
67
  const props = prevVNode.props!;
83
68
  if (props.fixed === 'left') {
84
- if (process.env.NODE_ENV !== 'production') {
85
- validateWidth(props);
86
- }
87
- value += widthMap.value[props.key] || parseInt(props.width as string, 10) || 0;
69
+ value += getWidth(prevVNode);
88
70
  }
89
71
  prevVNode = props.prevVNode;
90
72
  }
91
- offsetMap[key] = value;
73
+ _offsetMap[key] = value;
92
74
  hasFixedLeft = true;
93
75
  } else if (fixed === 'right') {
94
76
  let value = 0;
95
- let lastVNode = columns[columns.length - 1];
96
- while (vNode !== lastVNode) {
97
- const props = lastVNode.props!;
77
+ let nextVNode = props.nextVNode;
78
+ while (nextVNode) {
79
+ const props = nextVNode.props!;
98
80
  if (props.fixed === 'right') {
99
- if (process.env.NODE_ENV !== 'production') {
100
- validateWidth(props);
101
- }
102
- value += widthMap.value[props.key] || parseInt(props.width as string, 10) || 0;
81
+ value += getWidth(nextVNode);
103
82
  }
104
- lastVNode = props.prevVNode!;
83
+ nextVNode = props.nextVNode;
105
84
  }
106
- offsetMap[key] = value;
85
+ _offsetMap[key] = value;
107
86
  hasFixedRight = true;
108
87
  }
109
88
  });
110
89
  });
111
90
 
91
+ offsetMap.set(_offsetMap);
112
92
  hasFixed.set(hasFixedLeft || hasFixedRight);
113
93
  }
114
94
 
@@ -138,8 +118,8 @@ export function useFixedColumns(
138
118
  scrollPosition,
139
119
  setScrollPosition,
140
120
  hasFixed,
121
+ offsetMap,
141
122
  getHasFixedLeft: () => hasFixedLeft,
142
- getOffsetMap: () => offsetMap,
143
123
  };
144
124
  }
145
125
 
@@ -160,9 +140,7 @@ export function getClassAndStyleForFixed(
160
140
  };
161
141
  }
162
142
 
163
-
164
- function validateWidth({width, key}: TableColumnProps) {
165
- if (isNullOrUndefined(width) || isString(width) && !/\d+(px)?/.test(width)) {
166
- error(`The width must be specified with 'px' when the column has fixed. <TableColumn key="${key}" />`);
167
- }
143
+ function getWidth(vNode: VNodeComponentClass) {
144
+ const dom = findDomFromVNode(vNode, true) as HTMLElement;
145
+ return dom.offsetWidth;
168
146
  }
@@ -59,6 +59,10 @@ export function useGroup() {
59
59
  confirm(onChange);
60
60
  }
61
61
 
62
+ function checkAll() {
63
+ localGroupValue.set(filteredGroup.value?.map((item) => item.value));
64
+ }
65
+
62
66
  function isEmptyValue(groupValue: any) {
63
67
  const {multiple} = instance.get();
64
68
  return !groupValue || multiple && (!isArray(groupValue) || groupValue.every(value => !value));
@@ -88,5 +92,6 @@ export function useGroup() {
88
92
  dropdownRef,
89
93
  localGroupValue,
90
94
  isEmptyValue,
95
+ checkAll,
91
96
  };
92
97
  }
@@ -22,16 +22,18 @@ export function useResizable(
22
22
  let x: number;
23
23
  let prevVNode: ColumnVNode;
24
24
  let prevTh: HTMLElement;
25
+ let prevMinWidth: number;
25
26
  let currentVNode: ColumnVNode;
26
27
  let currentTh: HTMLElement;
27
- let minWidth: number;
28
+ let currentMinWidth: number;
29
+ let nextVNode: ColumnVNode | null | undefined;
28
30
 
29
31
  function onStart(e: MouseEvent) {
30
32
  containerWidth = scrollRef.value!.clientWidth;
31
33
  x = e.clientX;
32
34
 
33
35
  // find the previous column but exclude the hidden columns, #467
34
- prevVNode = currentVNode = (e as MouseEvent & {_vNode: ColumnVNode})._vNode;
36
+ prevVNode = nextVNode = currentVNode = (e as MouseEvent & {_vNode: ColumnVNode})._vNode;
35
37
  prevTh;
36
38
  do {
37
39
  prevVNode = prevVNode.props!.prevVNode!;
@@ -39,27 +41,53 @@ export function useResizable(
39
41
  } while(window.getComputedStyle(prevTh).display === 'none');
40
42
 
41
43
  currentTh = findDomFromVNode(currentVNode, true) as HTMLElement;
42
- minWidth = prevVNode.props!.minWidth || instance.get('minColWidth')!;
44
+ prevMinWidth= prevVNode.props!.minWidth || instance.get('minColWidth')!;
45
+ currentMinWidth = currentVNode.props!.minWidth || instance.get('minColWidth')!;
46
+
47
+ while (nextVNode = nextVNode?.props!.nextVNode) {
48
+ const th = findDomFromVNode(nextVNode, true) as HTMLElement;
49
+ if (window.getComputedStyle(th).display === 'none') {
50
+ continue;
51
+ }
52
+ break;
53
+ }
43
54
  }
44
55
 
45
56
  function onMove(e: MouseEvent) {
46
57
  const delX = e.clientX - x;
47
58
  if (delX === 0) return;
48
59
 
49
- const newPrevWidth = prevTh.offsetWidth + delX;
50
- if (newPrevWidth < minWidth && delX < 0) return;
60
+ let newPrevWidth = prevTh.offsetWidth + delX;
61
+ let newCurrentWidth = currentTh.offsetWidth - delX;
62
+ let newTableWidth = tableRef.value!.offsetWidth + delX;
63
+ const isCurrentFixedRight = currentVNode.props!.fixed === 'right';
64
+ // const isPrevFixedRight = prevVNode.props!.fixed === 'right';
65
+
66
+ if ((newPrevWidth < prevMinWidth || isCurrentFixedRight) && delX < 0) {
67
+ // if (nextVNode) return;
68
+ // the last column, we should expand its width
69
+ if (newPrevWidth < prevMinWidth) {
70
+ newPrevWidth -= delX;
71
+ newTableWidth -= delX;
72
+ }
73
+ }
51
74
 
52
- const newCurrentWidth = currentTh.offsetWidth - delX;
53
- const newTableWidth = tableRef.value!.offsetWidth + delX;
54
75
  const currentKey = currentVNode.props!.key;
55
76
  const prevKey = prevVNode.props!.key;
56
-
57
- x = e.clientX;
58
-
59
77
  const map = {
60
78
  [prevKey]: newPrevWidth
61
79
  }
62
80
 
81
+ if (!nextVNode || isCurrentFixedRight) {
82
+ newTableWidth -= delX;
83
+ if (newCurrentWidth < currentMinWidth && delX > 0) {
84
+ newCurrentWidth = currentMinWidth;
85
+ }
86
+ map[currentKey] = newCurrentWidth;
87
+ }
88
+
89
+ x = e.clientX;
90
+
63
91
  if (containerWidth > newTableWidth) {
64
92
  map[currentKey] = newCurrentWidth;
65
93
  } else {
@@ -90,6 +90,9 @@ export function useWidth(
90
90
  });
91
91
  });
92
92
  if (shouldUpdate) {
93
+ // let useFixedColumns to update scroll position
94
+ widthMap.set({ ...widthMap.value });
95
+
93
96
  instance.forceUpdate(() => {
94
97
  // check again because it may affect other columns
95
98
  if (!isStop) {
@@ -2,6 +2,7 @@ import {css} from '@emotion/css';
2
2
  import {theme, setDefault} from '../../styles/theme';
3
3
  import {deepDefaults, sizes, Sizes} from '../../styles/utils';
4
4
  import '../../styles/global';
5
+ import { cache } from '../utils';
5
6
 
6
7
  type SizeStyles = {
7
8
  fontSize: string;
@@ -81,9 +82,10 @@ const defaults = deepDefaults(
81
82
  let tabs: typeof defaults;
82
83
  setDefault(() => {
83
84
  tabs = deepDefaults(theme, {tabs: defaults}).tabs;
85
+ makeStyles?.clearCache();
84
86
  });
85
87
 
86
- export function makeStyles(k: string) {
88
+ export const makeStyles = cache(function makeStyles(k: string) {
87
89
  return css`
88
90
  ${makeCommonStyles(k)};
89
91
  ${makeScrollStyles(k)};
@@ -100,7 +102,7 @@ export function makeStyles(k: string) {
100
102
  ${makeFlatCardStyles(k)};
101
103
  }
102
104
  `;
103
- }
105
+ });
104
106
 
105
107
  function makeCommonStyles(k: string) {
106
108
  const active = tabs.active;
@@ -2,6 +2,7 @@ import {css} from '@emotion/css';
2
2
  import {deepDefaults, sizes, palette} from '../../styles/utils';
3
3
  import {theme, setDefault} from '../../styles/theme';
4
4
  import '../../styles/global';
5
+ import { cache } from '../utils';
5
6
 
6
7
  type ValueOf<T extends readonly any[]> = T[number]
7
8
  type Types = ValueOf<typeof types>
@@ -83,11 +84,13 @@ const defaults = deepDefaults(
83
84
  let tag: typeof defaults;
84
85
  setDefault(() => {
85
86
  tag = deepDefaults(theme, {tag: defaults}).tag;
87
+ makeStyles?.clearCache();
88
+ makeTagsStyles?.clearCache();
86
89
  });
87
90
 
88
91
  export { tag };
89
92
 
90
- export function makeStyles(k: string) {
93
+ export const makeStyles = cache(function makeStyles(k: string) {
91
94
  return css`
92
95
  display: inline-flex;
93
96
  align-items: center;
@@ -144,9 +147,9 @@ export function makeStyles(k: string) {
144
147
  opacity: 0;
145
148
  }
146
149
  `;
147
- }
150
+ });
148
151
 
149
- export function makeTagsStyles(k: string) {
152
+ export const makeTagsStyles = cache(function makeTagsStyles(k: string) {
150
153
  return css`
151
154
  display: flex;
152
155
  flex-wrap: wrap;
@@ -172,4 +175,4 @@ export function makeTagsStyles(k: string) {
172
175
  cursor: move;
173
176
  }
174
177
  `;
175
- }
178
+ });
@@ -2,6 +2,7 @@ import {css} from '@emotion/css';
2
2
  import {theme, setDefault} from '../../styles/theme';
3
3
  import {deepDefaults, Sizes, sizes, palette} from '../../styles/utils';
4
4
  import '../../styles/global';
5
+ import { cache } from '../utils';
5
6
 
6
7
  type ValueOf<T extends readonly any[]> = T[number]
7
8
 
@@ -58,16 +59,18 @@ const defaults = deepDefaults(
58
59
  let timeline: typeof defaults;
59
60
  setDefault(() => {
60
61
  timeline = deepDefaults(theme, {timeline: defaults}).timeline;
62
+ makeStyles?.clearCache();
63
+ makeItemStyles?.clearCache();
61
64
  });
62
65
 
63
- export function makeStyles(k: string) {
66
+ export const makeStyles = cache(function makeStyles(k: string) {
64
67
  return css`
65
68
  font-size: ${timeline.fontSize};
66
69
  padding-top: calc(${theme.lineHeight}em / 2);
67
70
  `;
68
- }
71
+ });
69
72
 
70
- export function makeItemStyles(k: string) {
73
+ export const makeItemStyles = cache(function makeItemStyles(k: string) {
71
74
  return css`
72
75
  position: relative;
73
76
  padding: ${timeline.padding};
@@ -148,5 +151,4 @@ export function makeItemStyles(k: string) {
148
151
  `
149
152
  })}
150
153
  `;
151
- };
152
-
154
+ });
@@ -3,6 +3,7 @@ import {theme, setDefault} from '../../styles/theme';
3
3
  import {deepDefaults, sizes, Sizes, getRight, getLeft, palette} from '../../styles/utils';
4
4
  import '../../styles/global';
5
5
  import {datepicker, makePanelStyles as makePanelStylesBase} from '../datepicker/styles';
6
+ import { cache } from '../utils';
6
7
 
7
8
  const defaults = {
8
9
  get border() { return datepicker.border; },
@@ -21,9 +22,10 @@ const defaults = {
21
22
  let timepicker: typeof defaults;
22
23
  setDefault(() => {
23
24
  timepicker = deepDefaults(theme, {timepicker: defaults}).timepicker;
25
+ makePanelStyles?.clearCache();
24
26
  });
25
27
 
26
- export function makePanelStyles(k: string) {
28
+ export const makePanelStyles = cache(function makePanelStyles(k: string) {
27
29
  return cx(
28
30
  makePanelStylesBase(k),
29
31
  css`
@@ -55,4 +57,4 @@ export function makePanelStyles(k: string) {
55
57
  }
56
58
  `,
57
59
  );
58
- }
60
+ });
@@ -2,6 +2,7 @@ import {theme, setDefault} from '../../styles/theme';
2
2
  import {css} from '@emotion/css';
3
3
  import '../../styles/global';
4
4
  import {deepDefaults} from '../../styles/utils';
5
+ import { cache } from '../utils';
5
6
 
6
7
  const defaults = {
7
8
  title: {
@@ -16,9 +17,10 @@ const defaults = {
16
17
  let tip: typeof defaults;
17
18
  setDefault(() => {
18
19
  tip = deepDefaults(theme, {tip: defaults}).tip;
20
+ makeStyles?.clearCache();
19
21
  });
20
22
 
21
- export function makeStyles(k: string) {
23
+ export const makeStyles = cache(function makeStyles(k: string) {
22
24
  return css`
23
25
  // Tip extends Tag, so we add.${k}-tip to increase the priority of class
24
26
  &.${k}-tip {
@@ -47,4 +49,4 @@ export function makeStyles(k: string) {
47
49
  background: none;
48
50
  }
49
51
  `;
50
- }
52
+ });
@@ -1,5 +1,5 @@
1
1
  import {Button} from '../button';
2
- import makeStyles from './styles';
2
+ import {makeStyles} from './styles';
3
3
 
4
4
  const {
5
5
  showArrow, confirm, className,
@@ -2,6 +2,7 @@ import {css} from '@emotion/css';
2
2
  import {theme, setDefault} from '../../styles/theme';
3
3
  import {deepDefaults} from '../../styles/utils';
4
4
  import '../../styles/global';
5
+ import { cache } from '../utils';
5
6
 
6
7
  const defaults = {
7
8
  padding: '8px 12px',
@@ -35,6 +36,7 @@ const defaults = {
35
36
  export let tooltip: typeof defaults;
36
37
  setDefault(() => {
37
38
  tooltip = deepDefaults(theme, {tooltip: defaults}).tooltip;
39
+ makeStyles?.clearCache();
38
40
  });
39
41
 
40
42
  export type Theme = 'dark' | 'light';
@@ -47,7 +49,7 @@ const directionMap = {
47
49
  right: 'left',
48
50
  };
49
51
 
50
- export default function makeStyles(k: string) {
52
+ export const makeStyles = cache(function makeStyles(k: string) {
51
53
  const arrowLong = tooltip.arrow.width;
52
54
  const arrowShort = `calc(${arrowLong} - 1px)`;
53
55
 
@@ -174,4 +176,4 @@ export default function makeStyles(k: string) {
174
176
  }
175
177
  }
176
178
  `
177
- }
179
+ });
@@ -2,6 +2,7 @@ import {css} from '@emotion/css';
2
2
  import {theme, setDefault} from '../../styles/theme';
3
3
  import {deepDefaults, palette} from '../../styles/utils';
4
4
  import '../../styles/global';
5
+ import { cache } from '../utils';
5
6
 
6
7
  const defaults = {
7
8
  fontSize: '12px',
@@ -41,9 +42,10 @@ const defaults = {
41
42
  let transfer: typeof defaults;
42
43
  setDefault(() => {
43
44
  transfer = deepDefaults(theme, {transfer: defaults}).transfer;
45
+ makeStyles?.clearCache();
44
46
  });
45
47
 
46
- export function makeStyles(k: string) {
48
+ export const makeStyles = cache(function makeStyles(k: string) {
47
49
  return css`
48
50
  font-size: ${transfer.fontSize};
49
51
  .${k}-transfer-panel,
@@ -117,4 +119,4 @@ export function makeStyles(k: string) {
117
119
  }
118
120
  }
119
121
  `;
120
- }
122
+ });
@@ -55,6 +55,7 @@ export default class extends Component {
55
55
  },
56
56
  {
57
57
  label: 'First floor-2',
58
+ key: 'floor-2',
58
59
  children: [
59
60
  {
60
61
  label: 'Second floor-2.1',
@@ -3,7 +3,10 @@ title: 右键菜单
3
3
  order: 4
4
4
  ---
5
5
 
6
- 绑定`rightclick:node`并利用`DropdownMenu`可以实现右键菜单来操作节点增删
6
+ 利用`label`扩展点,配合`Dropdown`的`contextmenu`触发方式,可以实现右键菜单来操作节点增删
7
+
8
+ > 当鼠标移动到菜单上时,节点的hover样式将会丢失,但是菜单弹出时,`Dropdown`会给触发元素添加`.k-dropdown-open`的类名,
9
+ > 可以用`:has`选择器来添加hover样式。如本例所示
7
10
 
8
11
  ```vdt
9
12
  import {Tree, Dropdown, DropdownMenu, DropdownItem} from 'kpc';
@@ -26,6 +29,12 @@ import {Tree, Dropdown, DropdownMenu, DropdownItem} from 'kpc';
26
29
  </div>
27
30
  ```
28
31
 
32
+ ```styl
33
+ // 鼠标移动到弹出菜单上,依然展示hover样式
34
+ .k-tree-text:has(.k-dropdown-open)
35
+ background: #f3f5f6
36
+ ```
37
+
29
38
  ```ts
30
39
  import {bind, Tree, TreeDataItem, TreeNode} from 'kpc';
31
40
 
@@ -69,6 +69,13 @@ describe('Tree', () => {
69
69
  checkbox3.click();
70
70
  await wait();
71
71
  expect(element.outerHTML).to.matchSnapshot();
72
+
73
+ checkbox4.click();
74
+ await wait();
75
+ instance.set<string[]>('checkedKeys', ['floor-2']);
76
+ await wait();
77
+ expect(checkbox2.classList.contains('k-checked')).to.be.true;
78
+ expect(checkbox2.classList.contains('k-indeterminate')).to.be.false;
72
79
  });
73
80
 
74
81
  it('async load', async function() {
@@ -2,6 +2,7 @@ import {css} from '@emotion/css';
2
2
  import {theme, setDefault} from '../../styles/theme';
3
3
  import {deepDefaults, palette} from '../../styles/utils';
4
4
  import '../../styles/global';
5
+ import { cache } from '../utils';
5
6
 
6
7
  const defaults = {
7
8
  get transition() { return theme.transition.middle },
@@ -37,9 +38,10 @@ const defaults = {
37
38
  let tree: typeof defaults;
38
39
  setDefault(() => {
39
40
  tree = deepDefaults(theme, {tree: defaults}).tree;
41
+ makeStyles?.clearCache();
40
42
  });
41
43
 
42
- export function makeStyles(k: string) {
44
+ export const makeStyles = cache(function makeStyles(k: string) {
43
45
  return css`
44
46
  font-size: ${tree.fontSize};
45
47
  line-height: ${tree.lineHeight};
@@ -151,4 +153,4 @@ export function makeStyles(k: string) {
151
153
  border-left: ${tree.line}
152
154
  }
153
155
  `;
154
- }
156
+ });
@@ -38,6 +38,9 @@ export function useChecked(getNodes: () => Node<Key>[]) {
38
38
  }
39
39
 
40
40
  node.checked = checked;
41
+ if (checked) {
42
+ node.indeterminate = false;
43
+ }
41
44
 
42
45
  if (shouldUpdateCheckedKeys) {
43
46
  updateCheckedKeys(node);