@king-design/react 3.0.0-beta.0 → 3.0.0-beta.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 (223) hide show
  1. package/__tests__/__snapshots__/Dialog.md +1 -1
  2. package/__tests__/__snapshots__/React Demos.md +468 -309
  3. package/__tests__/components/cascader.spec.tsx +53 -0
  4. package/__tests__/components/drawer.spec.tsx +67 -5
  5. package/components/button/index.d.ts +1 -1
  6. package/components/button/index.js +1 -1
  7. package/components/button/styles.d.ts +1 -1
  8. package/components/button/styles.js +3 -5
  9. package/components/carousel/index.vdt.js +2 -2
  10. package/components/cascader/index.d.ts +22 -11
  11. package/components/cascader/index.js +9 -12
  12. package/components/cascader/index.spec.js +81 -0
  13. package/components/cascader/index.vdt.js +11 -9
  14. package/components/cascader/styles.js +1 -1
  15. package/components/cascader/useFields.d.ts +2 -0
  16. package/components/cascader/useFields.js +18 -0
  17. package/components/cascader/useFilterable.d.ts +2 -1
  18. package/components/cascader/useFilterable.js +17 -6
  19. package/components/cascader/useLabel.d.ts +2 -1
  20. package/components/cascader/useLabel.js +4 -4
  21. package/components/cascader/useLoad.d.ts +2 -1
  22. package/components/cascader/useLoad.js +9 -7
  23. package/components/collapse/item.vdt.js +1 -1
  24. package/components/colorpicker/index.d.ts +2 -0
  25. package/components/colorpicker/index.js +7 -2
  26. package/components/colorpicker/index.vdt.js +3 -6
  27. package/components/copy/index.d.ts +17 -0
  28. package/components/copy/index.js +43 -0
  29. package/components/copy/index.spec.d.ts +1 -0
  30. package/components/copy/index.spec.js +52 -0
  31. package/components/copy/index.vdt.js +45 -0
  32. package/components/copy/styles.d.ts +2 -0
  33. package/components/copy/styles.js +14 -0
  34. package/components/copy/useCopy.d.ts +4 -0
  35. package/components/copy/useCopy.js +90 -0
  36. package/components/datepicker/calendar.vdt.js +6 -6
  37. package/components/datepicker/index.spec.js +171 -153
  38. package/components/datepicker/index.vdt.js +1 -1
  39. package/components/datepicker/styles.js +1 -1
  40. package/components/datepicker/useValue.d.ts +3 -3
  41. package/components/datepicker/useValue.js +38 -9
  42. package/components/diagram/shapes/callout.d.ts +1 -1
  43. package/components/diagram/shapes/circle.d.ts +1 -1
  44. package/components/diagram/shapes/document.d.ts +1 -1
  45. package/components/diagram/shapes/ellipse.d.ts +1 -1
  46. package/components/diagram/shapes/hexagon.d.ts +1 -1
  47. package/components/diagram/shapes/image.d.ts +1 -1
  48. package/components/diagram/shapes/parallelogram.d.ts +1 -1
  49. package/components/diagram/shapes/rectangle.d.ts +1 -1
  50. package/components/diagram/shapes/square.d.ts +1 -1
  51. package/components/diagram/shapes/text.d.ts +1 -1
  52. package/components/dialog/alert.vdt.js +6 -5
  53. package/components/dialog/index.spec.js +6 -6
  54. package/components/dialog/styles.js +1 -1
  55. package/components/dropdown/dropdown.d.ts +6 -6
  56. package/components/dropdown/dropdown.js +58 -75
  57. package/components/dropdown/index.spec.js +96 -17
  58. package/components/dropdown/item.d.ts +1 -1
  59. package/components/dropdown/item.js +19 -7
  60. package/components/dropdown/menu.js +1 -1
  61. package/components/dropdown/usePosition.js +11 -2
  62. package/components/editable/index.d.ts +1 -0
  63. package/components/editable/index.js +20 -6
  64. package/components/editable/index.vdt.js +2 -1
  65. package/components/form/index.spec.js +4 -2
  66. package/components/form/item.vdt.js +2 -1
  67. package/components/form/styles.js +4 -4
  68. package/components/grid/useGutter.js +8 -8
  69. package/components/icon/styles.js +1 -1
  70. package/components/input/index.d.ts +13 -2
  71. package/components/input/index.js +16 -13
  72. package/components/input/index.spec.js +169 -1
  73. package/components/input/index.vdt.js +44 -12
  74. package/components/input/search.vdt.js +2 -4
  75. package/components/input/styles.js +30 -6
  76. package/components/input/useAutoRows.d.ts +2 -0
  77. package/components/input/useAutoRows.js +79 -0
  78. package/components/input/useAutoWidth.js +13 -3
  79. package/components/input/useFocus.d.ts +4 -0
  80. package/components/input/useFocus.js +21 -0
  81. package/components/input/useShowPassword.d.ts +7 -0
  82. package/components/input/useShowPassword.js +31 -0
  83. package/components/menu/index.spec.js +26 -15
  84. package/components/menu/item.d.ts +2 -0
  85. package/components/menu/item.js +5 -0
  86. package/components/menu/item.vdt.js +4 -1
  87. package/components/pagination/index.d.ts +1 -1
  88. package/components/pagination/index.js +3 -2
  89. package/components/pagination/index.spec.js +49 -0
  90. package/components/pagination/index.vdt.js +10 -12
  91. package/components/pagination/styles.js +1 -1
  92. package/components/popover/content.d.ts +19 -0
  93. package/components/popover/content.js +31 -0
  94. package/components/popover/content.vdt.js +68 -0
  95. package/components/popover/index.d.ts +16 -0
  96. package/components/popover/index.js +44 -0
  97. package/components/popover/index.spec.d.ts +1 -0
  98. package/components/popover/index.spec.js +195 -0
  99. package/components/popover/styles.d.ts +1 -0
  100. package/components/popover/styles.js +22 -0
  101. package/components/portal.d.ts +6 -2
  102. package/components/portal.js +4 -3
  103. package/components/position.js +2 -1
  104. package/components/progress/index.js +1 -1
  105. package/components/progress/index.vdt.js +46 -8
  106. package/components/progress/styles.js +19 -13
  107. package/components/rate/styles.js +1 -1
  108. package/components/select/base.d.ts +7 -3
  109. package/components/select/base.js +9 -3
  110. package/components/select/base.vdt.js +75 -47
  111. package/components/select/index.spec.js +25 -13
  112. package/components/select/menu.vdt.js +6 -6
  113. package/components/select/option.vdt.js +2 -1
  114. package/components/select/styles.js +11 -5
  115. package/components/select/useDraggble.d.ts +2 -0
  116. package/components/select/useDraggble.js +11 -0
  117. package/components/slider/index.spec.js +48 -9
  118. package/components/slider/index.vdt.js +23 -12
  119. package/components/slider/styles.js +23 -14
  120. package/components/slider/useValue.d.ts +3 -1
  121. package/components/slider/useValue.js +12 -0
  122. package/components/spinner/index.d.ts +0 -1
  123. package/components/spinner/index.js +1 -19
  124. package/components/spinner/index.vdt.js +13 -8
  125. package/components/spinner/styles.js +2 -2
  126. package/components/spinner/useChange.d.ts +1 -1
  127. package/components/spinner/useChange.js +2 -2
  128. package/components/spinner/useValue.d.ts +1 -0
  129. package/components/spinner/useValue.js +16 -1
  130. package/components/split/index.vdt.js +32 -20
  131. package/components/split/memo.d.ts +9 -0
  132. package/components/split/memo.js +26 -0
  133. package/components/steps/index.d.ts +1 -0
  134. package/components/steps/index.js +2 -1
  135. package/components/steps/index.spec.js +1 -1
  136. package/components/steps/index.vdt.js +7 -4
  137. package/components/steps/step.vdt.js +2 -3
  138. package/components/steps/styles.d.ts +1 -0
  139. package/components/steps/styles.js +50 -17
  140. package/components/switch/index.spec.js +82 -65
  141. package/components/table/cell.js +1 -6
  142. package/components/table/cell.vdt.js +1 -1
  143. package/components/table/column.vdt.js +40 -24
  144. package/components/table/index.spec.js +162 -20
  145. package/components/table/row.d.ts +1 -1
  146. package/components/table/row.js +2 -1
  147. package/components/table/styles.js +16 -9
  148. package/components/table/table.d.ts +15 -0
  149. package/components/table/table.js +16 -7
  150. package/components/table/table.vdt.js +20 -6
  151. package/components/table/useChecked.d.ts +3 -2
  152. package/components/table/useChecked.js +23 -12
  153. package/components/table/useDisableRow.d.ts +2 -1
  154. package/components/table/useDisableRow.js +4 -4
  155. package/components/table/useDraggable.d.ts +3 -2
  156. package/components/table/useDraggable.js +11 -15
  157. package/components/table/useGroup.d.ts +9 -3
  158. package/components/table/useGroup.js +48 -37
  159. package/components/table/useMerge.d.ts +2 -1
  160. package/components/table/useMerge.js +5 -4
  161. package/components/table/usePagination.d.ts +8 -0
  162. package/components/table/usePagination.js +81 -0
  163. package/components/table/useStickyScrollbar.js +2 -2
  164. package/components/table/useTree.d.ts +2 -1
  165. package/components/table/useTree.js +3 -4
  166. package/components/table/useWidth.js +2 -2
  167. package/components/tabs/index.d.ts +1 -1
  168. package/components/tabs/index.js +1 -1
  169. package/components/tabs/index.spec.js +67 -0
  170. package/components/tabs/index.vdt.js +9 -4
  171. package/components/tabs/styles.js +32 -34
  172. package/components/tabs/useScroll.d.ts +1 -1
  173. package/components/tabs/useScroll.js +75 -48
  174. package/components/tag/base.d.ts +1 -0
  175. package/components/tag/base.js +1 -1
  176. package/components/tag/index.d.ts +1 -0
  177. package/components/tag/index.js +2 -1
  178. package/components/tag/index.spec.js +147 -4
  179. package/components/tag/styles.d.ts +67 -0
  180. package/components/tag/styles.js +33 -8
  181. package/components/tag/tags.d.ts +27 -0
  182. package/components/tag/tags.js +51 -0
  183. package/components/tag/tags.vdt.js +91 -0
  184. package/components/tag/useChildren.d.ts +2 -0
  185. package/components/tag/useChildren.js +39 -0
  186. package/components/tag/useDraggable.d.ts +3 -0
  187. package/components/tag/useDraggable.js +89 -0
  188. package/components/tag/useNowrap.d.ts +7 -0
  189. package/components/tag/useNowrap.js +115 -0
  190. package/components/timepicker/index.spec.js +1 -1
  191. package/components/tooltip/content.d.ts +3 -2
  192. package/components/tooltip/content.js +18 -1
  193. package/components/tooltip/content.vdt.js +22 -10
  194. package/components/tooltip/index.spec.js +147 -92
  195. package/components/tooltip/styles.d.ts +23 -0
  196. package/components/tooltip/styles.js +2 -2
  197. package/components/tooltip/tooltip.d.ts +1 -1
  198. package/components/tooltip/tooltip.js +11 -11
  199. package/components/transfer/index.vdt.js +14 -3
  200. package/components/types.d.ts +1 -0
  201. package/components/upload/index.spec.js +5 -6
  202. package/components/upload/index.vdt.js +7 -5
  203. package/components/utils.d.ts +2 -0
  204. package/components/utils.js +24 -3
  205. package/components/virtual.d.ts +8 -0
  206. package/components/virtual.js +126 -0
  207. package/hooks/useResizeObserver.d.ts +1 -1
  208. package/hooks/useResizeObserver.js +19 -6
  209. package/i18n/en-US.d.ts +4 -1
  210. package/i18n/en-US.js +6 -2
  211. package/index.d.ts +5 -3
  212. package/index.js +5 -3
  213. package/package.json +2 -2
  214. package/styles/fonts/iconfont.eot +0 -0
  215. package/styles/fonts/iconfont.js +2 -2
  216. package/styles/fonts/iconfont.svg +35 -35
  217. package/styles/fonts/iconfont.ttf +0 -0
  218. package/styles/fonts/iconfont.woff +0 -0
  219. package/styles/fonts/ionicons.js +3 -3
  220. package/styles/global.js +1 -1
  221. package/yarn-error.log +41 -43
  222. package/components/table/useResizeObserver.d.ts +0 -2
  223. package/components/table/useResizeObserver.js +0 -20
@@ -26,7 +26,13 @@ var defaults = deepDefaults({
26
26
 
27
27
  close: {
28
28
  fontSize: '20px',
29
- gap: '8px'
29
+ gap: '8px',
30
+
31
+ /**
32
+ * fix the width to calculate the width for nowrap tags,
33
+ * otherwise the width will be decided by font font-icons loaded
34
+ */
35
+ width: '7px'
30
36
  },
31
37
  disabled: {
32
38
  get color() {
@@ -45,24 +51,36 @@ var defaults = deepDefaults({
45
51
  large: {
46
52
  padding: "0px 8px",
47
53
  height: '24px',
54
+
55
+ get fontSize() {
56
+ return theme.large.fontSize;
57
+ },
58
+
48
59
  close: {
49
- fontSize: '20px',
50
- gap: '12px'
60
+ fontSize: '22px',
61
+ gap: '6px'
51
62
  }
52
63
  },
53
64
  small: {
54
65
  padding: "0 4px",
55
66
  height: '16px',
67
+
68
+ get fontSize() {
69
+ return theme.small.fontSize;
70
+ },
71
+
56
72
  close: {
57
- fontSize: '12px',
73
+ fontSize: '18px',
58
74
  gap: '4px'
59
75
  }
60
76
  },
61
77
  mini: {
62
78
  padding: "0 2px",
63
79
  height: '14px',
80
+ // get fontSize() { return theme.mini.fontSize },
81
+ fontSize: '11px',
64
82
  close: {
65
- fontSize: '12px',
83
+ fontSize: '16px',
66
84
  gap: '2px'
67
85
  }
68
86
  },
@@ -71,6 +89,9 @@ var defaults = deepDefaults({
71
89
  return theme.color.bg;
72
90
  }
73
91
 
92
+ },
93
+ tags: {
94
+ gap: '8px'
74
95
  }
75
96
  }, types.reduce(function (memo, type) {
76
97
  if (type === 'disabled') return memo;
@@ -92,13 +113,17 @@ setDefault(function () {
92
113
  tag: defaults
93
114
  }).tag;
94
115
  });
116
+ export { tag };
95
117
  export function makeStyles() {
96
- return /*#__PURE__*/css("display:inline-flex;align-items:center;padding:", tag.padding, ";border:", tag.border, ";border-radius:", tag.borderRadius, ";font-size:", tag.fontSize, ";height:", tag.height, ";.k-tag-close{font-size:", tag.close.fontSize, ";margin-left:", tag.close.gap, ";}&.k-none{border:none;background:", tag.none.bgColor, ";}", _mapInstanceProperty(types).call(types, function (t) {
118
+ return /*#__PURE__*/css("display:inline-flex;align-items:center;padding:", tag.padding, ";border:", tag.border, ";border-radius:", tag.borderRadius, ";font-size:", tag.fontSize, ";height:", tag.height, ";.k-tag-close{font-size:", tag.close.fontSize, ";margin-left:", tag.close.gap, ";width:", tag.close.width, ";}&.k-none{border:none;background:", tag.none.bgColor, ";}", _mapInstanceProperty(types).call(types, function (t) {
97
119
  var styles = tag[t];
98
120
  return /*#__PURE__*/css("&.k-", t, "{color:", styles.color, ";border-color:", styles.color, ";background:", styles.bgColor, ";}");
99
121
  }), " ", _mapInstanceProperty(sizes).call(sizes, function (s) {
100
122
  if (s === 'default') return;
101
123
  var styles = tag[s];
102
- return /*#__PURE__*/css("&.k-", s, "{padding:", styles.padding, ";height:", styles.height, ";.k-tag-close{font-size:", styles.close.fontSize, ";margin-left:", styles.close.gap, ";}}");
103
- }), "&.k-dashed{border-style:dashed;}");
124
+ return /*#__PURE__*/css("&.k-", s, "{padding:", styles.padding, ";height:", styles.height, ";font-size:", styles.fontSize, ";.k-tag-close{font-size:", styles.close.fontSize, ";margin-left:", styles.close.gap, ";}}");
125
+ }), "&.k-dashed{border-style:dashed;}&.k-dragging{opacity:0;}");
126
+ }
127
+ export function makeTagsStyles() {
128
+ return /*#__PURE__*/css("display:flex;flex-wrap:wrap;gap:", defaults.tags.gap, ";position:relative;overflow:hidden;&.k-nowrap{flex-wrap:nowrap;.k-tag{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex-shrink:0;}}.k-tags-more{cursor:default;font-family:monospace;}.k-tag.k-draggable{cursor:move;}");
104
129
  }
@@ -0,0 +1,27 @@
1
+ import { Component, TypeDefs, Key } from 'intact-react';
2
+ import { TagProps } from './base';
3
+ import type { Events } from '../types';
4
+ export interface TagsProps extends Pick<TagProps, 'size' | 'border'> {
5
+ nowrap?: boolean;
6
+ draggable?: boolean;
7
+ }
8
+ export declare type TagsDragStartParam = {
9
+ key: Key;
10
+ from: number;
11
+ };
12
+ export declare type TagsDragEndParam = TagsDragStartParam & {
13
+ to: number;
14
+ };
15
+ export interface TagsEvents {
16
+ dragstart: [TagsDragStartParam];
17
+ dragend: [TagsDragEndParam];
18
+ }
19
+ export declare class Tags extends Component<TagsProps, TagsEvents> {
20
+ static template: string | import("intact").Template<any>;
21
+ static typeDefs: Required<TypeDefs<TagsProps>>;
22
+ static defaults: () => Partial<TagsProps>;
23
+ static events: Events<TagsEvents>;
24
+ private children;
25
+ private draggable;
26
+ private nowrap;
27
+ }
@@ -0,0 +1,51 @@
1
+ import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
2
+ import _concatInstanceProperty from "@babel/runtime-corejs3/core-js/instance/concat";
3
+ import { Component } from 'intact-react';
4
+ import template from './tags.vdt';
5
+ import { useNowrap } from './useNowrap';
6
+ import { typeDefs as tagTypeDefs } from './base';
7
+ import { useChildren } from './useChildren';
8
+ import { useDraggable } from './useDraggable';
9
+ var typeDefs = {
10
+ nowrap: Boolean,
11
+ draggable: Boolean,
12
+ size: tagTypeDefs.size,
13
+ border: tagTypeDefs.border
14
+ };
15
+
16
+ var defaults = function defaults() {
17
+ return {
18
+ size: 'default',
19
+ border: 'none'
20
+ };
21
+ };
22
+
23
+ var events = {
24
+ dragstart: true,
25
+ dragend: true
26
+ };
27
+ export var Tags = /*#__PURE__*/function (_Component) {
28
+ _inheritsLoose(Tags, _Component);
29
+
30
+ function Tags() {
31
+ var _context;
32
+
33
+ var _this;
34
+
35
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
36
+ args[_key] = arguments[_key];
37
+ }
38
+
39
+ _this = _Component.call.apply(_Component, _concatInstanceProperty(_context = [this]).call(_context, args)) || this;
40
+ _this.children = useChildren();
41
+ _this.draggable = useDraggable(_this.children);
42
+ _this.nowrap = useNowrap(_this.draggable);
43
+ return _this;
44
+ }
45
+
46
+ return Tags;
47
+ }(Component);
48
+ Tags.template = template;
49
+ Tags.typeDefs = typeDefs;
50
+ Tags.defaults = defaults;
51
+ Tags.events = events;
@@ -0,0 +1,91 @@
1
+ import _extends from "@babel/runtime-corejs3/helpers/extends";
2
+ import { createVNode as _$cv, className as _$cn, createUnknownComponentVNode as _$cc, createTextVNode as _$ct, extend as _$ex, EMPTY_OBJ as _$em, createElementVNode as _$ce, noop as _$no } from 'intact-react';
3
+ import { TransitionGroup } from 'intact';
4
+ import { getRestProps } from '../utils';
5
+ import { makeTagsStyles } from './styles';
6
+ import { Tag } from './';
7
+ import { Tooltip } from '../tooltip';
8
+ import { Tags } from './tags';
9
+ import { Virtual } from '../virtual';
10
+ export default function ($props, $blocks, $__proto__) {
11
+ var _classNameObj;
12
+
13
+ $blocks || ($blocks = {});
14
+ $props || ($props = {});
15
+ var $this = this;
16
+ var _$blocks = {};
17
+ var __$blocks = {};
18
+
19
+ var _this$get = this.get(),
20
+ className = _this$get.className,
21
+ nowrap = _this$get.nowrap,
22
+ size = _this$get.size,
23
+ border = _this$get.border,
24
+ draggable = _this$get.draggable;
25
+
26
+ var classNameObj = (_classNameObj = {
27
+ 'k-tags': true,
28
+ 'k-nowrap': nowrap,
29
+ 'k-draggable': draggable
30
+ }, _classNameObj[makeTagsStyles()] = true, _classNameObj[className] = className, _classNameObj);
31
+ var _this$nowrap = this.nowrap,
32
+ containerRef = _this$nowrap.containerRef,
33
+ children = _this$nowrap.children,
34
+ hiddenChildren = _this$nowrap.hiddenChildren;
35
+ var vNodes = children.value;
36
+ /**
37
+ * We should always render Tooltip in nowrap mode, otherwise it will be removed while we close one tag.
38
+ * Because we will render all tags to calculate the width
39
+ */
40
+
41
+ return _$cv('div', _extends({
42
+ 'className': _$cn(classNameObj)
43
+ }, getRestProps(this), {
44
+ 'ref': containerRef
45
+ }), [!nowrap ? _$cc(TransitionGroup, {
46
+ 'name': 'k-fade',
47
+ 'children': vNodes
48
+ }) : vNodes, nowrap ? _$cc(Tooltip, {
49
+ 'key': '$tooltip',
50
+ 'hoverable': true,
51
+ 'theme': 'light',
52
+ 'className': 'k-tags-tooltip',
53
+ 'children': _$cc(Tag, {
54
+ 'key': '$more',
55
+ 'className': _$cn({
56
+ "k-tags-more": true,
57
+ 'c-hidden': !hiddenChildren.value.length
58
+ }),
59
+ 'size': size,
60
+ 'border': border,
61
+ 'children': [_$ct('\n +'), hiddenChildren.value.length]
62
+ }, '$more'),
63
+ '$blocks': function ($blocks) {
64
+ var _$blocks = {},
65
+ __$blocks = _$ex({}, $blocks);
66
+
67
+ return (_$blocks['content'] = function ($super) {
68
+ return _$ce(2, 'div', hiddenChildren.value, 0, _$cn(classNameObj));
69
+ }, __$blocks['content'] = function ($super, data) {
70
+ var block = $blocks['content'];
71
+
72
+ var callBlock = function callBlock() {
73
+ return _$blocks['content'].call($this, $super, data);
74
+ };
75
+
76
+ return block ? block.call($this, callBlock, data) : callBlock();
77
+ }), __$blocks;
78
+ }.call($this, _$em)
79
+ }, '$tooltip') : undefined, (_$blocks['append'] = function ($super) {
80
+ return null;
81
+ }, __$blocks['append'] = function ($super, data) {
82
+ var block = $blocks['append'];
83
+
84
+ var callBlock = function callBlock() {
85
+ return _$blocks['append'].call($this, $super, data);
86
+ };
87
+
88
+ return block ? block.call($this, callBlock, data) : callBlock();
89
+ }, __$blocks['append'](_$no))]);
90
+ }
91
+ ;
@@ -0,0 +1,2 @@
1
+ import { VNode } from 'intact-react';
2
+ export declare function useChildren(): import("../../hooks/useState").State<VNode<import("intact").VNodeTag>[]>;
@@ -0,0 +1,39 @@
1
+ import { useInstance } from 'intact-react';
2
+ import { eachChildren, findChildren, isComponentVNode } from '../utils';
3
+ import { isStringOrNumber } from 'intact-shared';
4
+ import { useState } from '../../hooks/useState';
5
+ import { Tag } from './';
6
+ import { Dropdown } from '../dropdown';
7
+ import { Tooltip } from '../tooltip';
8
+ export function useChildren() {
9
+ var instance = useInstance();
10
+ var children = useState([]);
11
+ instance.watch('children', function (v) {
12
+ var vNodes = [];
13
+ eachChildren(v, function (vNode) {
14
+ if (isTagOrContainsTag(vNode)) {
15
+ vNodes.push(vNode);
16
+ }
17
+ });
18
+ children.set(vNodes);
19
+ });
20
+ return children;
21
+ }
22
+
23
+ function isTagOrContainsTag(vNode) {
24
+ if (isStringOrNumber(vNode)) return false;
25
+
26
+ if (isComponentVNode(vNode, Tag)) {
27
+ return true;
28
+ }
29
+
30
+ if (isComponentVNode(vNode, Dropdown) || isComponentVNode(vNode, Tooltip)) {
31
+ var _vNode$props;
32
+
33
+ return !!findChildren((_vNode$props = vNode.props) == null ? void 0 : _vNode$props.children, function (vNode) {
34
+ return isTagOrContainsTag(vNode);
35
+ });
36
+ }
37
+
38
+ return false;
39
+ }
@@ -0,0 +1,3 @@
1
+ import { VNode } from 'intact-react';
2
+ import { State } from '../../hooks/useState';
3
+ export declare function useDraggable(originVNodes: State<VNode[]>): State<VNode<import("intact").VNodeTag>[]>;
@@ -0,0 +1,89 @@
1
+ import _mapInstanceProperty from "@babel/runtime-corejs3/core-js/instance/map";
2
+ import { useInstance, findDomFromVNode, createVNode as h } from 'intact-react';
3
+ import { nextFrame, swap } from '../utils';
4
+ import { useState, watchState } from '../../hooks/useState';
5
+ import { Virtual } from '../virtual';
6
+ import { cx } from '@emotion/css';
7
+ export function useDraggable(originVNodes) {
8
+ var instance = useInstance();
9
+ var children = useState([]);
10
+ var draggingKey = useState(null);
11
+ var draggingIndex = -1;
12
+ var originIndex = -1;
13
+ var lastOverIndex = -1;
14
+ /* let the dragover event only trigger once when tags changed order */
15
+
16
+ watchState(originVNodes, render);
17
+ watchState(draggingKey, render);
18
+
19
+ function render() {
20
+ var _context;
21
+
22
+ var _instance$get = instance.get(),
23
+ draggable = _instance$get.draggable;
24
+
25
+ children.set(!draggable ? originVNodes.value : _mapInstanceProperty(_context = originVNodes.value).call(_context, function (vNode, index) {
26
+ var key = vNode.key;
27
+ return h(Virtual, {
28
+ 'ev-dragstart': function evDragstart() {
29
+ return onStart(key, index);
30
+ },
31
+ 'ev-dragover': function evDragover(e) {
32
+ return onOver(e, key, index);
33
+ },
34
+ 'ev-dragend': function evDragend(e) {
35
+ return onEnd(e);
36
+ },
37
+ key: key,
38
+ draggable: draggable,
39
+ className: cx({
40
+ 'k-dragging': key === draggingKey.value,
41
+ 'k-draggable': draggable
42
+ })
43
+ }, vNode);
44
+ }));
45
+ }
46
+
47
+ function onStart(key, index) {
48
+ draggingIndex = originIndex = index;
49
+ nextFrame(function () {
50
+ draggingKey.set(key);
51
+ });
52
+ instance.trigger('dragstart', {
53
+ key: key,
54
+ from: index
55
+ });
56
+ }
57
+
58
+ function onOver(e, key, index) {
59
+ e.preventDefault();
60
+ e.stopPropagation(); // Dragging the tag of another tags drag to this tags should be ignored
61
+
62
+ if (draggingIndex === -1) return;
63
+ if (lastOverIndex === index) return;
64
+ lastOverIndex = index;
65
+ if (index === draggingIndex) return; // if the tag has move transition, you cannot drag over it before transition ended.
66
+
67
+ var dom = findDomFromVNode(children.value[index], true);
68
+ if (dom.classList.contains('k-fade-move')) return;
69
+ var vNodes = swap(originVNodes.value, draggingIndex, index);
70
+ lastOverIndex = draggingIndex;
71
+ draggingIndex = index;
72
+ originVNodes.set(vNodes);
73
+ }
74
+
75
+ function onEnd(e) {
76
+ e.preventDefault();
77
+ instance.trigger('dragend', {
78
+ key: draggingKey.value,
79
+ from: originIndex,
80
+ to: draggingIndex
81
+ });
82
+ draggingKey.set(null);
83
+ lastOverIndex = -1;
84
+ draggingIndex = -1;
85
+ originIndex = -1;
86
+ }
87
+
88
+ return children;
89
+ }
@@ -0,0 +1,7 @@
1
+ import { VNode } from 'intact-react';
2
+ import { State } from '../../hooks/useState';
3
+ export declare function useNowrap(originVNodes: State<VNode[]>): {
4
+ containerRef: import("intact").RefObject<HTMLDivElement>;
5
+ children: State<VNode<import("intact").VNodeTag>[]>;
6
+ hiddenChildren: State<VNode<import("intact").VNodeTag>[]>;
7
+ };
@@ -0,0 +1,115 @@
1
+ import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js/instance/slice";
2
+ import _Map from "@babel/runtime-corejs3/core-js/map";
3
+ import { useInstance, createRef, findDomFromVNode, onBeforeMount, nextTick } from 'intact-react';
4
+ import { useState, watchState } from '../../hooks/useState';
5
+ import { tag as tagStyles } from './styles';
6
+ import { getLeft, getRight } from '../../styles/utils';
7
+ import { useReceive } from '../../hooks/useReceive';
8
+ import { useResizeObserver } from '../../hooks/useResizeObserver';
9
+ export function useNowrap(originVNodes) {
10
+ var instance = useInstance();
11
+ var containerRef = createRef();
12
+ var children = useState([]);
13
+ var hiddenChildren = useState([]);
14
+ var estimateMoreElementWidth = useEstimateMoreElementWidth();
15
+ var offsetMap = useChildrenOffset(originVNodes);
16
+ watchState(originVNodes, function (v) {
17
+ children.set(v);
18
+ nextTick(refresh);
19
+ }); // instance.watch('children', refresh, { presented: true })
20
+
21
+ useResizeObserver(containerRef, refresh);
22
+
23
+ function refresh() {
24
+ if (!instance.get('nowrap') || instance.$unmounted) return;
25
+ var container = containerRef.value;
26
+ var containerWidth = container.offsetWidth;
27
+ var vNodes = [];
28
+ var _originVNodes = originVNodes.value;
29
+ var length = _originVNodes.length;
30
+
31
+ if (_originVNodes.length > 1) {
32
+ _originVNodes.forEach(function (vNode, index) {
33
+ var offset = offsetMap.get(vNode); // estimate the "more" element's with for performance
34
+
35
+ var width = estimateMoreElementWidth(length - index - 1);
36
+
37
+ if (offset + width <= containerWidth) {
38
+ vNodes.push(vNode);
39
+ }
40
+ });
41
+ } else {
42
+ vNodes.push.apply(vNodes, _originVNodes);
43
+ }
44
+ /**
45
+ * refresh function will be called in ResizeObserver,
46
+ * state changed will cause container's width to change,
47
+ * and a error will throw (ResizeObserver loop completed with undelivered notifications)
48
+ * so we call setState in requestAnimationFrame
49
+ */
50
+
51
+
52
+ requestAnimationFrame(function () {
53
+ hiddenChildren.set(_sliceInstanceProperty(_originVNodes).call(_originVNodes, vNodes.length));
54
+ children.set(vNodes);
55
+ });
56
+ }
57
+
58
+ return {
59
+ containerRef: containerRef,
60
+ children: children,
61
+ hiddenChildren: hiddenChildren
62
+ };
63
+ }
64
+
65
+ function useChildrenOffset(vNodes) {
66
+ var instance = useInstance();
67
+ var map = new _Map(); // instance.watch('children', updateMap, { presented: true })
68
+
69
+ watchState(vNodes, function () {
70
+ return nextTick(updateMap);
71
+ });
72
+
73
+ function updateMap() {
74
+ map.clear();
75
+ if (!instance.get('nowrap')) return;
76
+ vNodes.value.forEach(function (vNode) {
77
+ var dom = findDomFromVNode(vNode, true);
78
+ if (!dom || dom.nodeType !== 1) return;
79
+ var offsetLeft = dom.offsetLeft,
80
+ offsetWidth = dom.offsetWidth;
81
+ map.set(vNode, offsetLeft + offsetWidth);
82
+ });
83
+ }
84
+
85
+ return map;
86
+ }
87
+
88
+ function useEstimateMoreElementWidth() {
89
+ var instance = useInstance();
90
+ var widthPerChar = 7.2;
91
+ var cacheWidth = 0;
92
+ onBeforeMount(cache);
93
+ useReceive(['size', 'border'], cache, true);
94
+
95
+ function cache() {
96
+ var _instance$get = instance.get(),
97
+ size = _instance$get.size,
98
+ border = _instance$get.border;
99
+
100
+ cacheWidth = parseInt(tagStyles.tags.gap) + widthPerChar
101
+ /* the "+" mark */
102
+ ;
103
+
104
+ if (border !== 'none') {
105
+ cacheWidth += 2;
106
+ }
107
+
108
+ var padding = size === 'default' ? tagStyles.padding : tagStyles[size].padding;
109
+ cacheWidth += parseInt(getLeft(padding)) + parseInt(getRight(padding));
110
+ }
111
+
112
+ return function (count) {
113
+ return Math.round(count.toString().length * widthPerChar + cacheWidth);
114
+ };
115
+ }
@@ -100,7 +100,7 @@ describe('Timepicker', function () {
100
100
  case 45:
101
101
  expect(instance.get('timeArray')).to.eql(['01:00:00', '02:00:00']); // remove one value
102
102
 
103
- _picker2$querySelecto = picker2.querySelectorAll('.k-select-close'), close = _picker2$querySelecto[1];
103
+ _picker2$querySelecto = picker2.querySelectorAll('.k-tag-close'), close = _picker2$querySelecto[1];
104
104
  close.click();
105
105
  _context2.next = 50;
106
106
  return wait();
@@ -6,12 +6,13 @@ export interface TooltipContentEvents extends DropdownMenuEvents {
6
6
  export interface TooltipContentBlocks extends DropdownMenuBlocks {
7
7
  buttons: null;
8
8
  }
9
- export declare class TooltipContent extends DropdownMenu<TooltipContentProps, TooltipContentEvents, TooltipContentBlocks> {
9
+ export declare class TooltipContent<T extends TooltipContentProps = TooltipContentProps, E extends TooltipContentEvents = TooltipContentEvents, B extends TooltipContentBlocks = TooltipContentBlocks> extends DropdownMenu<T, E, B> {
10
10
  static template: string | import('intact-react').Template<any>;
11
- private isEmptyChildren;
11
+ protected isEmptyChildren: boolean;
12
12
  private arrow;
13
13
  init(): void;
14
14
  private onEnter;
15
+ private onAfterLeave;
15
16
  protected onMouseEnter(e: MouseEvent): void;
16
17
  private ok;
17
18
  private cancel;
@@ -5,6 +5,7 @@ import { DropdownMenu } from '../dropdown/menu';
5
5
  import template from './content.vdt';
6
6
  import { bind } from '../utils';
7
7
  import { useArrow } from './useArrow';
8
+ import { tooltip as tooltipTheme } from './styles';
8
9
  export var TooltipContent = /*#__PURE__*/function (_DropdownMenu) {
9
10
  _inheritsLoose(TooltipContent, _DropdownMenu);
10
11
 
@@ -35,10 +36,24 @@ export var TooltipContent = /*#__PURE__*/function (_DropdownMenu) {
35
36
  });
36
37
  };
37
38
 
38
- _proto.onEnter = function onEnter() {
39
+ _proto.onEnter = function onEnter(elem) {
40
+ // fix the width, https://github.com/ksc-fe/kpc/issues/873
41
+ var maxWidth = parseInt(tooltipTheme.maxWidth);
42
+ var width = elem.offsetWidth;
43
+
44
+ if (width === maxWidth) {
45
+ elem.style.width = width + "px";
46
+ }
47
+
39
48
  this.dropdown.position();
40
49
  };
41
50
 
51
+ _proto.onAfterLeave = function onAfterLeave(elem) {
52
+ // remove the position after leave, https://github.com/ksc-fe/kpc/issues/873
53
+ var style = elem.style;
54
+ style.left = style.top = style.width = '';
55
+ };
56
+
42
57
  _proto.onMouseEnter = function onMouseEnter(e) {
43
58
  var dropdown = this.dropdown;
44
59
 
@@ -67,6 +82,8 @@ TooltipContent.template = template;
67
82
 
68
83
  __decorate([bind], TooltipContent.prototype, "onEnter", null);
69
84
 
85
+ __decorate([bind], TooltipContent.prototype, "onAfterLeave", null);
86
+
70
87
  __decorate([bind], TooltipContent.prototype, "onMouseEnter", null);
71
88
 
72
89
  __decorate([bind], TooltipContent.prototype, "ok", null);
@@ -1,4 +1,4 @@
1
- import { superCall as _$su, className as _$cn, extend as _$ex, EMPTY_OBJ as _$em, createElementVNode as _$ce, createUnknownComponentVNode as _$cc, noop as _$no } from 'intact-react';
1
+ import { superCall as _$su, className as _$cn, extend as _$ex, EMPTY_OBJ as _$em, noop as _$no, createElementVNode as _$ce, createUnknownComponentVNode as _$cc } from 'intact-react';
2
2
  import { Button } from '../button';
3
3
  import makeStyles from './styles';
4
4
  export default function ($props, $blocks, $__proto__) {
@@ -33,12 +33,14 @@ export default function ($props, $blocks, $__proto__) {
33
33
  'k-tooltip-content': true,
34
34
  'k-hoverable': hoverable || trigger === 'click',
35
35
  'k-always': always
36
- }, _classNameObj["k-" + theme] = true, _classNameObj["k-" + size] = size !== 'default', _classNameObj[className] = className, _classNameObj[makeStyles()] = true, _classNameObj);
36
+ }, _classNameObj["k-" + theme] = true, _classNameObj["k-" + size] = size !== 'default', _classNameObj[className] = className, _classNameObj[makeStyles()] = true, _classNameObj[$props.className] = $props.className, _classNameObj);
37
37
  return _$su.call($this, {
38
38
  'value': !!value && !this.isEmptyChildren,
39
39
  'transition': {
40
40
  name: 'k-fade',
41
- onEnter: this.onEnter
41
+ onEnter: this.onEnter,
42
+ onAfterLeave: this.onAfterLeave,
43
+ onLeaveCancelled: this.onAfterLeave
42
44
  },
43
45
  'className': _$cn(classNameObj)
44
46
  }, function ($blocks) {
@@ -48,9 +50,17 @@ export default function ($props, $blocks, $__proto__) {
48
50
  return (_$blocks['children'] = function ($super) {
49
51
  var _$cn2;
50
52
 
51
- return [children, showArrow ? _$ce(2, 'i', null, 1, _$cn((_$cn2 = {
52
- "k-tooltip-arrow": true
53
- }, _$cn2["k-" + arrowType.value] = arrowType.value, _$cn2)), null, 'tooltip-arrow', arrowRef) : undefined, confirm ? _$ce(2, 'div', (_$blocks['buttons'] = function ($super) {
53
+ return [(_$blocks['body'] = function ($super) {
54
+ return children;
55
+ }, __$blocks['body'] = function ($super, data) {
56
+ var block = $blocks['body'];
57
+
58
+ var callBlock = function callBlock() {
59
+ return _$blocks['body'].call($this, $super, data);
60
+ };
61
+
62
+ return block ? block.call($this, callBlock, data) : callBlock();
63
+ }, __$blocks['body'](_$no)), confirm ? _$ce(2, 'div', (_$blocks['footer'] = function ($super) {
54
64
  return [_$cc(Button, {
55
65
  'ev-click': this.cancel,
56
66
  'size': 'small',
@@ -61,15 +71,17 @@ export default function ($props, $blocks, $__proto__) {
61
71
  'size': 'small',
62
72
  'children': okText
63
73
  })];
64
- }, __$blocks['buttons'] = function ($super, data) {
65
- var block = $blocks['buttons'];
74
+ }, __$blocks['footer'] = function ($super, data) {
75
+ var block = $blocks['footer'];
66
76
 
67
77
  var callBlock = function callBlock() {
68
- return _$blocks['buttons'].call($this, $super, data);
78
+ return _$blocks['footer'].call($this, $super, data);
69
79
  };
70
80
 
71
81
  return block ? block.call($this, callBlock, data) : callBlock();
72
- }, __$blocks['buttons'](_$no)), 0, 'k-tooltip-buttons', null, 'tooltip-buttons') : undefined];
82
+ }, __$blocks['footer'](_$no)), 0, 'k-tooltip-footer', null, 'tooltip-footer') : undefined, showArrow ? _$ce(2, 'i', null, 1, _$cn((_$cn2 = {
83
+ "k-tooltip-arrow": true
84
+ }, _$cn2["k-" + arrowType.value] = arrowType.value, _$cn2)), null, 'tooltip-arrow', arrowRef) : undefined];
73
85
  }, __$blocks['children'] = function ($super, data) {
74
86
  var block = $blocks['children'];
75
87