vue-devui 1.0.0-beta.7 → 1.0.0-pre.0

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 (303) hide show
  1. package/README.md +81 -66
  2. package/accordion/index.es.js +522 -39
  3. package/accordion/index.umd.js +1 -1
  4. package/accordion/style.css +1 -1
  5. package/alert/index.es.js +7 -8
  6. package/alert/index.umd.js +1 -1
  7. package/alert/style.css +1 -1
  8. package/{toast → auto-complete}/index.d.ts +0 -0
  9. package/auto-complete/index.es.js +976 -0
  10. package/auto-complete/index.umd.js +1 -0
  11. package/auto-complete/package.json +7 -0
  12. package/auto-complete/style.css +1 -0
  13. package/avatar/index.es.js +1 -1
  14. package/avatar/index.umd.js +1 -1
  15. package/back-top/index.es.js +1 -1
  16. package/back-top/index.umd.js +1 -1
  17. package/badge/index.es.js +13 -19
  18. package/badge/index.umd.js +1 -1
  19. package/button/index.es.js +263 -83
  20. package/button/index.umd.js +1 -1
  21. package/button/style.css +1 -1
  22. package/card/index.es.js +1 -1
  23. package/card/index.umd.js +1 -1
  24. package/carousel/index.es.js +7 -6
  25. package/carousel/index.umd.js +1 -1
  26. package/cascader/index.es.js +5393 -773
  27. package/cascader/index.umd.js +27 -1
  28. package/checkbox/index.es.js +1 -1
  29. package/checkbox/index.umd.js +1 -1
  30. package/checkbox/style.css +1 -1
  31. package/color-picker/index.d.ts +7 -0
  32. package/color-picker/index.es.js +8187 -0
  33. package/color-picker/index.umd.js +27 -0
  34. package/color-picker/package.json +7 -0
  35. package/color-picker/style.css +1 -0
  36. package/comment/index.es.js +42 -13
  37. package/comment/index.umd.js +1 -1
  38. package/comment/style.css +1 -1
  39. package/countdown/index.d.ts +7 -0
  40. package/countdown/index.es.js +176 -0
  41. package/countdown/index.umd.js +1 -0
  42. package/countdown/package.json +7 -0
  43. package/countdown/style.css +1 -0
  44. package/date-picker/index.es.js +11 -12
  45. package/date-picker/index.umd.js +1 -1
  46. package/date-picker/style.css +1 -1
  47. package/dragdrop/index.es.js +135 -10
  48. package/dragdrop/index.umd.js +1 -1
  49. package/drawer/index.es.js +173 -203
  50. package/drawer/index.umd.js +1 -1
  51. package/drawer/style.css +1 -1
  52. package/dropdown/index.es.js +412 -302
  53. package/dropdown/index.umd.js +1 -1
  54. package/dropdown/style.css +1 -1
  55. package/editable-select/index.es.js +275 -5610
  56. package/editable-select/index.umd.js +1 -27
  57. package/editable-select/style.css +1 -1
  58. package/form/index.es.js +6129 -461
  59. package/form/index.umd.js +27 -1
  60. package/form/style.css +1 -1
  61. package/fullscreen/index.es.js +111 -119
  62. package/fullscreen/index.umd.js +1 -1
  63. package/fullscreen/style.css +1 -1
  64. package/gantt/index.es.js +6 -18
  65. package/gantt/index.umd.js +1 -1
  66. package/gantt/style.css +1 -1
  67. package/grid/index.es.js +3 -3
  68. package/grid/index.umd.js +1 -1
  69. package/grid/style.css +1 -1
  70. package/icon/index.es.js +3 -2
  71. package/icon/index.umd.js +1 -1
  72. package/image-preview/index.es.js +78 -20
  73. package/image-preview/index.umd.js +1 -1
  74. package/image-preview/style.css +1 -1
  75. package/input/index.es.js +5 -6
  76. package/input/index.umd.js +1 -1
  77. package/input/style.css +1 -1
  78. package/input-icon/index.es.js +6 -6
  79. package/input-icon/index.umd.js +1 -1
  80. package/input-icon/style.css +1 -1
  81. package/input-number/index.es.js +2 -1
  82. package/input-number/index.umd.js +1 -1
  83. package/layout/index.es.js +1 -1
  84. package/layout/index.umd.js +1 -1
  85. package/list/index.d.ts +7 -0
  86. package/list/index.es.js +39 -0
  87. package/list/index.umd.js +1 -0
  88. package/{toast → list}/package.json +1 -1
  89. package/list/style.css +1 -0
  90. package/loading/index.es.js +3 -3
  91. package/loading/index.umd.js +1 -1
  92. package/modal/index.es.js +297 -761
  93. package/modal/index.umd.js +1 -1
  94. package/modal/style.css +1 -1
  95. package/nav-sprite/index.es.js +1 -675
  96. package/nav-sprite/index.umd.js +1 -1
  97. package/notification/index.d.ts +7 -0
  98. package/notification/index.es.js +286 -0
  99. package/notification/index.umd.js +1 -0
  100. package/notification/package.json +7 -0
  101. package/notification/style.css +1 -0
  102. package/nuxt/components/Accordion.js +3 -0
  103. package/nuxt/components/Alert.js +3 -0
  104. package/nuxt/components/Anchor.js +3 -0
  105. package/nuxt/components/Aside.js +3 -0
  106. package/nuxt/components/AutoComplete.js +3 -0
  107. package/nuxt/components/Avatar.js +3 -0
  108. package/nuxt/components/BackTop.js +3 -0
  109. package/nuxt/components/Badge.js +3 -0
  110. package/nuxt/components/Breadcrumb.js +3 -0
  111. package/nuxt/components/Button.js +3 -0
  112. package/nuxt/components/Card.js +3 -0
  113. package/nuxt/components/Carousel.js +3 -0
  114. package/nuxt/components/CarouselItem.js +3 -0
  115. package/nuxt/components/Cascader.js +3 -0
  116. package/nuxt/components/Checkbox.js +3 -0
  117. package/nuxt/components/Col.js +3 -0
  118. package/nuxt/components/ColorPicker.js +3 -0
  119. package/nuxt/components/Column.js +3 -0
  120. package/nuxt/components/Comment.js +3 -0
  121. package/nuxt/components/Content.js +3 -0
  122. package/nuxt/components/Countdown.js +3 -0
  123. package/nuxt/components/DatePicker.js +3 -0
  124. package/nuxt/components/Drawer.js +3 -0
  125. package/nuxt/components/DrawerService.js +3 -0
  126. package/nuxt/components/Dropdown.js +3 -0
  127. package/nuxt/components/DropdownMenu.js +3 -0
  128. package/nuxt/components/EditableSelect.js +3 -0
  129. package/nuxt/components/FixedOverlay.js +3 -0
  130. package/nuxt/components/FlexibleOverlay.js +3 -0
  131. package/nuxt/components/Footer.js +3 -0
  132. package/nuxt/components/Form.js +3 -0
  133. package/nuxt/components/FormControl.js +3 -0
  134. package/nuxt/components/FormItem.js +3 -0
  135. package/nuxt/components/FormLabel.js +3 -0
  136. package/nuxt/components/FormOperation.js +3 -0
  137. package/nuxt/components/Fullscreen.js +3 -0
  138. package/nuxt/components/Gantt.js +3 -0
  139. package/nuxt/components/Header.js +3 -0
  140. package/nuxt/components/IFileOptions.js +3 -0
  141. package/nuxt/components/IUploadOptions.js +3 -0
  142. package/nuxt/components/Icon.js +2 -0
  143. package/nuxt/components/ImagePreviewService.js +3 -0
  144. package/nuxt/components/Input.js +3 -0
  145. package/nuxt/components/InputIcon.js +3 -0
  146. package/nuxt/components/InputNumber.js +3 -0
  147. package/nuxt/components/Layout.js +3 -0
  148. package/nuxt/components/List.js +3 -0
  149. package/nuxt/components/ListItem.js +3 -0
  150. package/nuxt/components/Loading.js +3 -0
  151. package/nuxt/components/LoadingService.js +3 -0
  152. package/nuxt/components/Modal.js +3 -0
  153. package/nuxt/components/NavSprite.js +2 -0
  154. package/nuxt/components/Notification.js +3 -0
  155. package/nuxt/components/NotificationService.js +3 -0
  156. package/nuxt/components/Pagination.js +3 -0
  157. package/nuxt/components/Panel.js +3 -0
  158. package/nuxt/components/Popover.js +3 -0
  159. package/nuxt/components/Progress.js +3 -0
  160. package/nuxt/components/QuadrantDiagram.js +3 -0
  161. package/nuxt/components/Radio.js +3 -0
  162. package/nuxt/components/RadioGroup.js +3 -0
  163. package/nuxt/components/Rate.js +3 -0
  164. package/nuxt/components/ReadTip.js +3 -0
  165. package/nuxt/components/Result.js +3 -0
  166. package/nuxt/components/Row.js +3 -0
  167. package/nuxt/components/Search.js +3 -0
  168. package/nuxt/components/Select.js +3 -0
  169. package/nuxt/components/Skeleton.js +3 -0
  170. package/nuxt/components/SkeletonItem.js +3 -0
  171. package/nuxt/components/Slider.js +3 -0
  172. package/nuxt/components/Splitter.js +3 -0
  173. package/nuxt/components/Statistic.js +3 -0
  174. package/nuxt/components/Status.js +3 -0
  175. package/nuxt/components/StepsGuide.js +3 -0
  176. package/nuxt/components/StickSlider.js +3 -0
  177. package/nuxt/components/Sticky.js +2 -0
  178. package/nuxt/components/Switch.js +3 -0
  179. package/nuxt/components/Table.js +3 -0
  180. package/nuxt/components/Tabs.js +3 -0
  181. package/nuxt/components/Tag.js +3 -0
  182. package/nuxt/components/TagInput.js +3 -0
  183. package/nuxt/components/Textarea.js +3 -0
  184. package/nuxt/components/TimeAxis.js +3 -0
  185. package/nuxt/components/TimeAxisItem.js +3 -0
  186. package/nuxt/components/TimePicker.js +3 -0
  187. package/nuxt/components/Tooltip.js +3 -0
  188. package/nuxt/components/Transfer.js +3 -0
  189. package/nuxt/components/Tree.js +3 -0
  190. package/nuxt/components/TreeSelect.js +3 -0
  191. package/nuxt/components/Upload.js +3 -0
  192. package/nuxt/components/UploadStatus.js +3 -0
  193. package/nuxt/components/badgeProps.js +3 -0
  194. package/nuxt/components/buttonProps.js +3 -0
  195. package/nuxt/components/dropdownMenuProps.js +3 -0
  196. package/nuxt/components/fixedOverlayProps.js +3 -0
  197. package/nuxt/components/flexibleOverlayProps.js +3 -0
  198. package/nuxt/components/notificationProps.js +3 -0
  199. package/nuxt/components/overlayEmits.js +3 -0
  200. package/nuxt/components/overlayProps.js +3 -0
  201. package/nuxt/components/popoverProps.js +3 -0
  202. package/nuxt/components/tooltipProps.js +3 -0
  203. package/nuxt/components/uploadProps.js +3 -0
  204. package/nuxt/index.js +13 -0
  205. package/overlay/index.es.js +146 -200
  206. package/overlay/index.umd.js +1 -1
  207. package/overlay/style.css +1 -1
  208. package/package.json +10 -18
  209. package/pagination/index.es.js +4 -4
  210. package/pagination/index.umd.js +1 -1
  211. package/pagination/style.css +1 -1
  212. package/panel/index.es.js +3 -3
  213. package/panel/index.umd.js +1 -1
  214. package/popover/index.es.js +5948 -190
  215. package/popover/index.umd.js +27 -1
  216. package/popover/style.css +1 -1
  217. package/progress/index.es.js +9 -9
  218. package/progress/index.umd.js +3 -3
  219. package/quadrant-diagram/index.es.js +5405 -166
  220. package/quadrant-diagram/index.umd.js +27 -1
  221. package/radio/index.es.js +6 -6
  222. package/radio/index.umd.js +1 -1
  223. package/radio/style.css +1 -1
  224. package/rate/index.es.js +1 -1
  225. package/rate/index.umd.js +1 -1
  226. package/read-tip/index.es.js +21 -7
  227. package/read-tip/index.umd.js +1 -1
  228. package/read-tip/style.css +1 -1
  229. package/result/index.d.ts +7 -0
  230. package/result/index.es.js +119 -0
  231. package/result/index.umd.js +1 -0
  232. package/result/package.json +7 -0
  233. package/result/style.css +1 -0
  234. package/ripple/index.es.js +6 -3
  235. package/ripple/index.umd.js +1 -1
  236. package/search/index.es.js +5435 -201
  237. package/search/index.umd.js +27 -1
  238. package/search/style.css +1 -1
  239. package/select/index.es.js +3 -2
  240. package/select/index.umd.js +1 -1
  241. package/select/style.css +1 -1
  242. package/skeleton/index.es.js +1 -1
  243. package/skeleton/index.umd.js +1 -1
  244. package/slider/index.es.js +3 -6
  245. package/slider/index.umd.js +1 -1
  246. package/slider/style.css +1 -1
  247. package/splitter/index.es.js +5904 -60
  248. package/splitter/index.umd.js +27 -1
  249. package/splitter/style.css +1 -1
  250. package/statistic/index.d.ts +7 -0
  251. package/statistic/index.es.js +267 -0
  252. package/statistic/index.umd.js +1 -0
  253. package/statistic/package.json +7 -0
  254. package/statistic/style.css +1 -0
  255. package/status/index.es.js +2 -2
  256. package/status/index.umd.js +1 -1
  257. package/status/style.css +1 -1
  258. package/steps-guide/index.es.js +8 -6
  259. package/steps-guide/index.umd.js +1 -1
  260. package/sticky/index.umd.js +1 -1
  261. package/style.css +1 -1
  262. package/switch/index.es.js +1 -1
  263. package/switch/index.umd.js +1 -1
  264. package/table/index.es.js +701 -359
  265. package/table/index.umd.js +1 -1
  266. package/table/style.css +1 -1
  267. package/tabs/index.es.js +3 -4
  268. package/tabs/index.umd.js +1 -1
  269. package/tabs/style.css +1 -1
  270. package/tag/index.es.js +37 -11
  271. package/tag/index.umd.js +1 -1
  272. package/tag/style.css +1 -1
  273. package/tag-input/index.es.js +1 -13
  274. package/tag-input/index.umd.js +1 -1
  275. package/textarea/index.es.js +1 -1
  276. package/textarea/index.umd.js +1 -1
  277. package/textarea/style.css +1 -1
  278. package/{theme → theme/theme.scss} +0 -0
  279. package/time-axis/index.es.js +5 -2
  280. package/time-axis/index.umd.js +1 -1
  281. package/time-picker/index.es.js +269 -84
  282. package/time-picker/index.umd.js +1 -1
  283. package/time-picker/style.css +1 -1
  284. package/tooltip/index.es.js +5798 -141
  285. package/tooltip/index.umd.js +27 -1
  286. package/tooltip/style.css +1 -1
  287. package/transfer/index.es.js +6522 -635
  288. package/transfer/index.umd.js +27 -1
  289. package/transfer/style.css +1 -1
  290. package/tree/index.es.js +5858 -146
  291. package/tree/index.umd.js +27 -1
  292. package/tree/style.css +1 -1
  293. package/tree-select/index.es.js +130 -35
  294. package/tree-select/index.umd.js +1 -1
  295. package/tree-select/style.css +1 -1
  296. package/upload/index.es.js +464 -2681
  297. package/upload/index.umd.js +1 -1
  298. package/upload/style.css +1 -1
  299. package/vue-devui.es.js +15597 -14569
  300. package/vue-devui.umd.js +16 -16
  301. package/toast/index.es.js +0 -2059
  302. package/toast/index.umd.js +0 -1
  303. package/toast/style.css +0 -1
@@ -17,16 +17,11 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- import { ref, watch, defineComponent, createVNode, Teleport, Transition, renderSlot, isVNode, computed, onMounted, onUnmounted, withDirectives, vShow, reactive, toRef, isRef, toRefs, Fragment } from "vue";
20
+ import { toRefs, watch, onMounted, onUnmounted, defineComponent, createVNode, Teleport, Transition, renderSlot, isVNode, computed, ref, nextTick, unref, mergeProps, Fragment } from "vue";
21
+ import { offset, autoPlacement, arrow, computePosition } from "@floating-ui/dom";
22
+ import { onClickOutside } from "@vueuse/core";
21
23
  const dropdownProps = {
22
- origin: {
23
- type: Object
24
- },
25
- isOpen: {
26
- type: Boolean,
27
- default: false
28
- },
29
- disabled: {
24
+ visible: {
30
25
  type: Boolean,
31
26
  default: false
32
27
  },
@@ -38,18 +33,23 @@ const dropdownProps = {
38
33
  type: String,
39
34
  default: "all"
40
35
  },
36
+ position: {
37
+ type: Array,
38
+ default: ["bottom"]
39
+ },
40
+ align: {
41
+ type: String,
42
+ default: null
43
+ },
44
+ offset: {
45
+ type: [Number, Object],
46
+ default: 4
47
+ },
41
48
  closeOnMouseLeaveMenu: {
42
49
  type: Boolean,
43
50
  default: false
44
- },
45
- showAnimation: {
46
- type: Boolean,
47
- default: true
48
51
  }
49
52
  };
50
- function isComponent(target) {
51
- return !!(target == null ? void 0 : target.$el);
52
- }
53
53
  function getElement(element) {
54
54
  if (element instanceof Element) {
55
55
  return element;
@@ -59,84 +59,136 @@ function getElement(element) {
59
59
  }
60
60
  return null;
61
61
  }
62
+ const dropdownMap = /* @__PURE__ */ new Map();
62
63
  function subscribeEvent(dom, type, callback) {
63
64
  dom == null ? void 0 : dom.addEventListener(type, callback);
64
65
  return () => {
65
66
  dom == null ? void 0 : dom.removeEventListener(type, callback);
66
67
  };
67
68
  }
68
- const useDropdown = ({
69
- visible,
70
- trigger,
71
- origin,
72
- closeScope,
73
- closeOnMouseLeaveMenu
74
- }) => {
75
- const dropdownElRef = ref();
76
- const closeByScope = () => {
77
- if (closeScope.value === "none") {
78
- return;
79
- }
80
- visible.value = false;
69
+ const useDropdownEvent = ({ id, isOpen, origin, dropdownRef, props, emit }) => {
70
+ let overlayEnter = false;
71
+ let originEnter = false;
72
+ const { trigger, closeScope, closeOnMouseLeaveMenu } = toRefs(props);
73
+ const toggle = (status) => {
74
+ isOpen.value = status;
75
+ emit("toggle", isOpen.value);
81
76
  };
82
- watch([trigger, origin, dropdownElRef], ([trigger2, origin2, dropdownEl], ov, onInvalidate) => {
83
- const originEl = getElement(origin2);
84
- if (!originEl || !dropdownEl) {
77
+ const handleLeave = async (elementType, e) => {
78
+ await new Promise((resolve) => setTimeout(resolve, 50));
79
+ if (elementType === "origin" && overlayEnter || elementType === "dropdown" && originEnter) {
85
80
  return;
86
81
  }
87
- const subscriptions = [
88
- subscribeEvent(dropdownEl, "click", () => {
89
- if (closeScope.value === "all") {
90
- visible.value = false;
91
- }
92
- })
93
- ];
94
- if (trigger2 === "click") {
95
- subscriptions.push(subscribeEvent(originEl, "click", () => visible.value = !visible.value), subscribeEvent(document, "click", (e) => {
96
- if (!visible.value) {
97
- return;
98
- }
99
- const target = e.target;
100
- const isContain = originEl.contains(target) || dropdownEl.contains(target);
101
- if (isContain) {
82
+ if (e) {
83
+ [...dropdownMap.values()].reverse().forEach((item) => {
84
+ setTimeout(() => {
85
+ var _a;
86
+ (_a = item.toggle) == null ? void 0 : _a.call(item);
87
+ }, 0);
88
+ });
89
+ }
90
+ toggle(false);
91
+ };
92
+ watch([trigger, origin, dropdownRef], ([triggerVal, originVal, dropdownEl], ov, onInvalidate) => {
93
+ const originEl = getElement(originVal);
94
+ const subscriptions = [];
95
+ setTimeout(() => {
96
+ subscriptions.push(subscribeEvent(document, "click", (e) => {
97
+ const dropdownValues = [...dropdownMap.values()];
98
+ if (!isOpen.value || closeScope.value === "none" || dropdownEl.contains(e.target) && closeScope.value === "blank" || dropdownValues.some((item) => {
99
+ var _a;
100
+ return (_a = item.toggleEl) == null ? void 0 : _a.contains(e.target);
101
+ }) && dropdownValues.some((item) => {
102
+ var _a;
103
+ return (_a = item.menuEl) == null ? void 0 : _a.contains(e.target);
104
+ })) {
102
105
  return;
103
106
  }
104
- closeByScope();
105
- }), subscribeEvent(dropdownEl, "mouseleave", () => {
106
- if (closeOnMouseLeaveMenu.value) {
107
- visible.value = false;
108
- }
107
+ [...dropdownMap.values()].reverse().forEach((item) => {
108
+ setTimeout(() => {
109
+ var _a, _b;
110
+ if (!((_a = item.toggleEl) == null ? void 0 : _a.contains(e.target))) {
111
+ (_b = item.toggle) == null ? void 0 : _b.call(item);
112
+ }
113
+ }, 0);
114
+ });
115
+ overlayEnter = false;
109
116
  }));
110
- } else if (trigger2 === "hover") {
111
- let overlayEnter = false;
112
- let originEnter = false;
113
- const handleLeave = async (elementType) => {
114
- await new Promise((resolve) => setTimeout(resolve, 50));
115
- if (elementType === "origin" && overlayEnter || elementType === "dropdown" && originEnter) {
116
- return;
117
+ }, 0);
118
+ if (triggerVal === "click") {
119
+ subscriptions.push(subscribeEvent(originEl, "click", () => toggle(!isOpen.value)), subscribeEvent(dropdownEl, "mouseleave", (e) => {
120
+ var _a;
121
+ if (closeOnMouseLeaveMenu.value && !((_a = dropdownMap.get(id).child) == null ? void 0 : _a.contains(e.relatedTarget))) {
122
+ handleLeave("dropdown", e);
117
123
  }
118
- closeByScope();
119
- };
124
+ }));
125
+ } else if (triggerVal === "hover") {
120
126
  subscriptions.push(subscribeEvent(originEl, "mouseenter", () => {
121
127
  originEnter = true;
122
- visible.value = true;
128
+ toggle(true);
123
129
  }), subscribeEvent(originEl, "mouseleave", () => {
124
130
  originEnter = false;
125
- if (!closeOnMouseLeaveMenu.value) {
126
- handleLeave("origin");
127
- }
131
+ handleLeave("origin");
128
132
  }), subscribeEvent(dropdownEl, "mouseenter", () => {
129
133
  overlayEnter = true;
130
- visible.value = true;
131
- }), subscribeEvent(dropdownEl, "mouseleave", () => {
134
+ isOpen.value = true;
135
+ }), subscribeEvent(dropdownEl, "mouseleave", (e) => {
136
+ var _a;
132
137
  overlayEnter = false;
133
- handleLeave("dropdown");
138
+ if (e.relatedTarget && ((originEl == null ? void 0 : originEl.contains(e.relatedTarget)) || ((_a = dropdownMap.get(id).child) == null ? void 0 : _a.contains(e.relatedTarget)))) {
139
+ return;
140
+ }
141
+ handleLeave("dropdown", e);
134
142
  }));
135
143
  }
136
144
  onInvalidate(() => subscriptions.forEach((v) => v()));
137
145
  });
138
- return { dropdownEl: dropdownElRef };
139
146
  };
147
+ function useDropdown(id, visible, isOpen, origin, dropdownRef, popDirection, emit) {
148
+ const calcPopDirection = (dropdownEl) => {
149
+ const elementHeight = dropdownEl.offsetHeight;
150
+ const bottomDistance = window.innerHeight - origin.value.getBoundingClientRect().bottom;
151
+ const isBottomEnough = bottomDistance >= elementHeight;
152
+ if (!isBottomEnough) {
153
+ popDirection.value = "top";
154
+ } else {
155
+ popDirection.value = "bottom";
156
+ }
157
+ };
158
+ watch(visible, (newVal, oldVal) => {
159
+ if (oldVal === void 0) {
160
+ return;
161
+ }
162
+ isOpen.value = newVal;
163
+ emit("toggle", isOpen.value);
164
+ }, { immediate: true });
165
+ watch([isOpen, dropdownRef], ([isOpenVal, dropdownEl]) => {
166
+ var _a;
167
+ if (isOpenVal) {
168
+ dropdownMap.set(id, __spreadProps(__spreadValues({}, dropdownMap.get(id)), {
169
+ menuEl: dropdownEl,
170
+ toggle: () => {
171
+ isOpen.value = false;
172
+ emit("toggle", isOpen.value);
173
+ }
174
+ }));
175
+ for (const value of dropdownMap.values()) {
176
+ if ((_a = value.menuEl) == null ? void 0 : _a.contains(origin.value)) {
177
+ value.child = dropdownEl;
178
+ }
179
+ }
180
+ }
181
+ if (dropdownEl) {
182
+ calcPopDirection(dropdownEl);
183
+ }
184
+ });
185
+ onMounted(() => {
186
+ dropdownMap.set(id, { toggleEl: origin.value });
187
+ });
188
+ onUnmounted(() => {
189
+ dropdownMap.delete(id);
190
+ });
191
+ }
140
192
  var overlay = "";
141
193
  function _isSlot(s) {
142
194
  return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
@@ -161,9 +213,6 @@ const overlayProps = {
161
213
  visible: {
162
214
  type: Boolean
163
215
  },
164
- "onUpdate:visible": {
165
- type: Function
166
- },
167
216
  backgroundBlock: {
168
217
  type: Boolean,
169
218
  default: false
@@ -175,7 +224,7 @@ const overlayProps = {
175
224
  backgroundStyle: {
176
225
  type: [String, Object]
177
226
  },
178
- backdropClick: {
227
+ onBackdropClick: {
179
228
  type: Function
180
229
  },
181
230
  backdropClose: {
@@ -187,28 +236,44 @@ const overlayProps = {
187
236
  default: true
188
237
  }
189
238
  };
239
+ const overlayEmits = ["update:visible", "backdropClick"];
190
240
  const fixedOverlayProps = __spreadProps(__spreadValues({}, overlayProps), {
191
241
  overlayStyle: {
192
242
  type: [String, Object],
193
243
  default: void 0
194
244
  }
195
245
  });
196
- const flexibleOverlayProps = __spreadValues({
246
+ const flexibleOverlayProps = {
247
+ modelValue: {
248
+ type: Boolean,
249
+ default: false
250
+ },
197
251
  origin: {
198
252
  type: Object,
199
253
  require: true
200
254
  },
201
255
  position: {
202
- type: Object,
203
- default: () => ({
204
- originX: "left",
205
- originY: "top",
206
- overlayX: "left",
207
- overlayY: "top"
208
- })
256
+ type: Array,
257
+ default: ["bottom"]
258
+ },
259
+ offset: {
260
+ type: [Number, Object],
261
+ default: 8
262
+ },
263
+ align: {
264
+ type: String,
265
+ default: null
266
+ },
267
+ showArrow: {
268
+ type: Boolean,
269
+ default: false
270
+ },
271
+ isArrowCenter: {
272
+ type: Boolean,
273
+ default: true
209
274
  }
210
- }, overlayProps);
211
- function useOverlayLogic(props) {
275
+ };
276
+ function useOverlayLogic(props, ctx) {
212
277
  const backgroundClass = computed(() => {
213
278
  return [
214
279
  "devui-overlay-background",
@@ -220,11 +285,11 @@ function useOverlayLogic(props) {
220
285
  return "devui-overlay";
221
286
  });
222
287
  const handleBackdropClick = (event) => {
223
- var _a, _b;
288
+ var _a;
224
289
  event.preventDefault();
225
- (_a = props.backdropClick) == null ? void 0 : _a.call(props);
290
+ (_a = props.onBackdropClick) == null ? void 0 : _a.call(props);
226
291
  if (props.backdropClose) {
227
- (_b = props["onUpdate:visible"]) == null ? void 0 : _b.call(props, false);
292
+ ctx.emit("update:visible", false);
228
293
  }
229
294
  };
230
295
  const handleOverlayBubbleCancel = (event) => event.cancelBubble = true;
@@ -258,18 +323,19 @@ function useOverlayLogic(props) {
258
323
  handleOverlayBubbleCancel
259
324
  };
260
325
  }
261
- const FixedOverlay = defineComponent({
326
+ defineComponent({
262
327
  name: "DFixedOverlay",
263
328
  props: fixedOverlayProps,
329
+ emits: overlayEmits,
264
330
  setup(props, ctx) {
265
331
  const {
266
332
  backgroundClass,
267
333
  overlayClass,
268
334
  handleBackdropClick,
269
335
  handleOverlayBubbleCancel
270
- } = useOverlayLogic(props);
336
+ } = useOverlayLogic(props, ctx);
271
337
  return () => createVNode(CommonOverlay, null, {
272
- default: () => [withDirectives(createVNode("div", {
338
+ default: () => [props.visible && createVNode("div", {
273
339
  "class": backgroundClass.value,
274
340
  "style": props.backgroundStyle,
275
341
  "onClick": handleBackdropClick
@@ -277,252 +343,296 @@ const FixedOverlay = defineComponent({
277
343
  "class": overlayClass.value,
278
344
  "style": props.overlayStyle,
279
345
  "onClick": handleOverlayBubbleCancel
280
- }, [renderSlot(ctx.slots, "default")])]), [[vShow, props.visible]])]
281
- });
282
- }
283
- });
284
- const FlexibleOverlay = defineComponent({
285
- name: "DFlexibleOverlay",
286
- props: flexibleOverlayProps,
287
- emits: ["onUpdate:visible"],
288
- setup(props, ctx) {
289
- const overlayRef = ref(null);
290
- const positionedStyle = reactive({
291
- position: "absolute"
292
- });
293
- onMounted(async () => {
294
- const handleRectChange = (position, rect, origin) => {
295
- const point = calculatePosition(position, rect, origin);
296
- positionedStyle.left = `${point.x}px`;
297
- positionedStyle.top = `${point.y}px`;
298
- };
299
- const locationElements = computed(() => {
300
- const overlay2 = overlayRef.value;
301
- const origin = getOrigin(props.origin);
302
- if (!overlay2 || !origin) {
303
- return;
304
- }
305
- return {
306
- origin,
307
- overlay: overlay2
308
- };
309
- });
310
- const visibleRef = toRef(props, "visible");
311
- const positionRef = toRef(props, "position");
312
- watch([locationElements, visibleRef, positionRef], async ([locationElements2, visible, position], ov, onInvalidate) => {
313
- if (!visible || !locationElements2) {
314
- return;
315
- }
316
- const {
317
- origin,
318
- overlay: overlay2
319
- } = locationElements2;
320
- handleRectChange(position, overlay2.getBoundingClientRect(), origin);
321
- const unsubscriptions = [subscribeLayoutEvent(() => handleRectChange(position, overlay2.getBoundingClientRect(), origin)), subscribeOverlayResize(overlay2, (entries) => handleRectChange(position, entries[0].contentRect, origin)), subscribeOriginResize(origin, () => handleRectChange(position, overlay2.getBoundingClientRect(), origin))];
322
- onInvalidate(() => {
323
- unsubscriptions.forEach((fn) => fn());
324
- });
325
- });
326
- });
327
- const {
328
- backgroundClass,
329
- overlayClass,
330
- handleBackdropClick,
331
- handleOverlayBubbleCancel
332
- } = useOverlayLogic(props);
333
- return () => createVNode(CommonOverlay, null, {
334
- default: () => [withDirectives(createVNode("div", {
335
- "style": props.backgroundStyle,
336
- "class": backgroundClass.value,
337
- "onClick": handleBackdropClick
338
- }, [createVNode("div", {
339
- "ref": overlayRef,
340
- "class": overlayClass.value,
341
- "style": positionedStyle,
342
- "onClick": handleOverlayBubbleCancel
343
- }, [renderSlot(ctx.slots, "default")])]), [[vShow, props.visible]])]
346
+ }, [renderSlot(ctx.slots, "default")])])]
344
347
  });
345
348
  }
346
349
  });
347
- function getOrigin(origin) {
348
- if (origin instanceof Element) {
349
- return origin;
350
- }
351
- if (isRef(origin)) {
352
- return getElement(origin.value);
353
- }
354
- if (isComponent(origin)) {
355
- return getElement(origin);
356
- }
357
- return origin;
358
- }
359
- function calculatePosition(position, rect, origin) {
360
- const originRect = getOriginRect(origin);
361
- const originPoint = getOriginRelativePoint(originRect, position);
362
- return getOverlayPoint(originPoint, rect, position);
363
- }
364
- function getOriginRect(origin) {
365
- if (origin instanceof Element) {
366
- return origin.getBoundingClientRect();
350
+ function getScrollParent(element) {
351
+ const overflowRegex = /(auto|scroll|hidden)/;
352
+ for (let parent = element; parent = parent.parentElement; parent.parentElement !== document.body) {
353
+ const style = window.getComputedStyle(parent);
354
+ if (overflowRegex.test(style.overflow + style.overflowX + style.overflowY)) {
355
+ return parent;
356
+ }
367
357
  }
368
- const width = origin.width || 0;
369
- const height = origin.height || 0;
370
- return {
371
- top: origin.y,
372
- bottom: origin.y + height,
373
- left: origin.x,
374
- right: origin.x + width,
375
- height,
376
- width
377
- };
358
+ return window;
378
359
  }
379
- function getOverlayPoint(originPoint, rect, position) {
380
- let x;
381
- const {
382
- width,
383
- height
384
- } = rect;
385
- if (position.overlayX == "center") {
386
- x = originPoint.x - width / 2;
387
- } else {
388
- x = position.overlayX == "left" ? originPoint.x : originPoint.x - width;
389
- }
390
- let y;
391
- if (position.overlayY == "center") {
392
- y = originPoint.y - height / 2;
393
- } else {
394
- y = position.overlayY == "top" ? originPoint.y : originPoint.y - height;
360
+ function adjustArrowPosition(isArrowCenter, point, placement, originRect) {
361
+ let { x, y } = point;
362
+ if (!isArrowCenter) {
363
+ const { width, height } = originRect;
364
+ if (x && placement.includes("start")) {
365
+ x = 12;
366
+ }
367
+ if (x && placement.includes("end")) {
368
+ x = Math.round(width - 24);
369
+ }
370
+ if (y && placement.includes("start")) {
371
+ y = 10;
372
+ }
373
+ if (y && placement.includes("end")) {
374
+ y = height - 14;
375
+ }
395
376
  }
396
- return {
397
- x,
398
- y
399
- };
377
+ return { x, y };
400
378
  }
401
- function getOriginRelativePoint(originRect, position) {
402
- let x;
403
- if (position.originX == "center") {
404
- x = originRect.left + originRect.width / 2;
405
- } else {
406
- const startX = originRect.left;
407
- const endX = originRect.right;
408
- x = position.originX == "left" ? startX : endX;
409
- }
410
- let y;
411
- if (position.originY == "center") {
412
- y = originRect.top + originRect.height / 2;
413
- } else {
414
- y = position.originY == "top" ? originRect.top : originRect.bottom;
415
- }
416
- return {
417
- x,
418
- y
419
- };
420
- }
421
- function subscribeLayoutEvent(event) {
422
- window.addEventListener("scroll", event, true);
423
- window.addEventListener("resize", event);
424
- window.addEventListener("orientationchange", event);
425
- return () => {
426
- window.removeEventListener("scroll", event, true);
427
- window.removeEventListener("resize", event);
428
- window.removeEventListener("orientationchange", event);
429
- };
430
- }
431
- function subscribeOverlayResize(overlay2, callback) {
432
- if (overlay2 instanceof Element) {
433
- const resizeObserver = new ResizeObserver(callback);
434
- resizeObserver.observe(overlay2);
435
- return () => resizeObserver.disconnect();
436
- }
437
- return () => {
379
+ function useOverlay(props, emit) {
380
+ const overlayRef = ref();
381
+ const arrowRef = ref();
382
+ const updateArrowPosition = (arrowEl, placement, point, overlayEl) => {
383
+ const { x, y } = adjustArrowPosition(props.isArrowCenter, point, placement, overlayEl.getBoundingClientRect());
384
+ const staticSide = {
385
+ top: "bottom",
386
+ right: "left",
387
+ bottom: "top",
388
+ left: "right"
389
+ }[placement.split("-")[0]];
390
+ Object.assign(arrowEl.style, {
391
+ left: x ? `${x}px` : "",
392
+ top: y ? `${y}px` : "",
393
+ right: "",
394
+ bottom: "",
395
+ [staticSide]: "-4px"
396
+ });
438
397
  };
439
- }
440
- function subscribeOriginResize(origin, callback) {
441
- if (origin instanceof Element) {
442
- const observer = new MutationObserver(callback);
443
- observer.observe(origin, {
444
- attributeFilter: ["style"]
398
+ const updatePosition = async () => {
399
+ const hostEl = props.origin;
400
+ const overlayEl = unref(overlayRef.value);
401
+ const arrowEl = unref(arrowRef.value);
402
+ const middleware = [
403
+ offset(props.offset),
404
+ autoPlacement({
405
+ alignment: props.align,
406
+ allowedPlacements: props.position
407
+ })
408
+ ];
409
+ props.showArrow && middleware.push(arrow({ element: arrowEl }));
410
+ const { x, y, placement, middlewareData } = await computePosition(hostEl, overlayEl, {
411
+ strategy: "fixed",
412
+ middleware
445
413
  });
446
- return () => observer.disconnect();
447
- }
448
- return () => {
414
+ emit("positionChange", placement);
415
+ Object.assign(overlayEl.style, { top: `${y}px`, left: `${x}px` });
416
+ props.showArrow && updateArrowPosition(arrowEl, placement, middlewareData.arrow, overlayEl);
449
417
  };
418
+ watch(() => props.modelValue, () => {
419
+ const originParent = getScrollParent(props.origin);
420
+ if (props.modelValue && props.origin) {
421
+ nextTick(updatePosition);
422
+ originParent.addEventListener("scroll", updatePosition);
423
+ originParent !== window && window.addEventListener("scroll", updatePosition);
424
+ window.addEventListener("resize", updatePosition);
425
+ } else {
426
+ originParent.removeEventListener("scroll", updatePosition);
427
+ originParent !== window && window.removeEventListener("scroll", updatePosition);
428
+ window.removeEventListener("resize", updatePosition);
429
+ }
430
+ });
431
+ onUnmounted(() => {
432
+ const originParent = getScrollParent(props.origin);
433
+ originParent.removeEventListener("scroll", updatePosition);
434
+ originParent !== window && window.removeEventListener("scroll", updatePosition);
435
+ window.removeEventListener("resize", updatePosition);
436
+ });
437
+ return { arrowRef, overlayRef };
450
438
  }
451
- FlexibleOverlay.install = function(app) {
452
- app.component(FlexibleOverlay.name, FlexibleOverlay);
453
- };
454
- FixedOverlay.install = function(app) {
455
- app.component(FixedOverlay.name, FixedOverlay);
456
- };
439
+ var flexibleOverlay = "";
440
+ const FlexibleOverlay = defineComponent({
441
+ name: "DFlexibleOverlay",
442
+ inheritAttrs: false,
443
+ props: flexibleOverlayProps,
444
+ emits: ["update:modelValue", "positionChange"],
445
+ setup(props, {
446
+ slots,
447
+ attrs,
448
+ emit
449
+ }) {
450
+ const {
451
+ arrowRef,
452
+ overlayRef
453
+ } = useOverlay(props, emit);
454
+ return () => {
455
+ var _a;
456
+ return props.modelValue && createVNode("div", mergeProps({
457
+ "ref": overlayRef,
458
+ "class": "devui-flexible-overlay"
459
+ }, attrs), [(_a = slots.default) == null ? void 0 : _a.call(slots), props.showArrow && createVNode("div", {
460
+ "ref": arrowRef,
461
+ "class": "devui-flexible-overlay-arrow"
462
+ }, null)]);
463
+ };
464
+ }
465
+ });
457
466
  var dropdown = "";
467
+ let dropdownId = 1;
458
468
  var Dropdown = defineComponent({
459
469
  name: "DDropdown",
470
+ inheritAttrs: false,
460
471
  props: dropdownProps,
461
- emits: [],
462
- setup(props, ctx) {
472
+ emits: ["toggle"],
473
+ setup(props, {
474
+ slots,
475
+ attrs,
476
+ emit
477
+ }) {
463
478
  const {
464
- isOpen,
465
- origin,
466
- trigger,
467
- closeScope,
468
- closeOnMouseLeaveMenu
479
+ visible,
480
+ position,
481
+ align,
482
+ offset: offset2
469
483
  } = toRefs(props);
470
- const visible = ref(false);
471
- watch(isOpen, (value) => {
472
- visible.value = value;
473
- }, {
474
- immediate: true
475
- });
476
- const position = {
477
- originX: "center",
478
- originY: "bottom",
479
- overlayX: "center",
480
- overlayY: "top"
484
+ const origin = ref();
485
+ const dropdownRef = ref();
486
+ const id = `dropdown_${dropdownId++}`;
487
+ const isOpen = ref(false);
488
+ const currentPosition = ref("bottom");
489
+ const handlePositionChange = (pos) => {
490
+ currentPosition.value = pos.includes("top") || pos.includes("end") ? "top" : "bottom";
481
491
  };
482
- const {
483
- dropdownEl
484
- } = useDropdown({
485
- visible,
492
+ const styles = computed(() => ({
493
+ transformOrigin: currentPosition.value === "top" ? "0% 100%" : "0% 0%"
494
+ }));
495
+ const classes = computed(() => ({
496
+ "fade-in-bottom": isOpen.value && currentPosition.value === "bottom",
497
+ "fade-in-top": isOpen.value && currentPosition.value === "top"
498
+ }));
499
+ useDropdownEvent({
500
+ id,
501
+ isOpen,
486
502
  origin,
487
- trigger,
488
- closeScope,
489
- closeOnMouseLeaveMenu
490
- });
491
- const animatedVisible = computed(() => {
492
- return props.showAnimation ? visible.value : true;
503
+ dropdownRef,
504
+ props,
505
+ emit
493
506
  });
507
+ useDropdown(id, visible, isOpen, origin, dropdownRef, currentPosition, emit);
494
508
  return () => {
495
- return createVNode(Fragment, null, [createVNode(FlexibleOverlay, {
496
- "origin": props.origin,
497
- "visible": visible.value,
498
- "onUpdate:visible": ($event) => visible.value = $event,
499
- "position": position,
500
- "hasBackdrop": false
509
+ var _a;
510
+ return createVNode(Fragment, null, [createVNode("div", {
511
+ "ref": origin,
512
+ "class": "devui-dropdown-toggle"
513
+ }, [(_a = slots.default) == null ? void 0 : _a.call(slots)]), createVNode(Teleport, {
514
+ "to": "body"
501
515
  }, {
502
516
  default: () => [createVNode(Transition, {
503
- "name": "devui-dropdown-fade"
517
+ "name": `devui-dropdown-fade-${currentPosition.value}`
504
518
  }, {
505
- default: () => {
506
- var _a, _b;
507
- return [withDirectives(createVNode("div", {
508
- "ref": dropdownEl,
509
- "style": "min-width:102px"
510
- }, [(_b = (_a = ctx.slots).default) == null ? void 0 : _b.call(_a)]), [[vShow, animatedVisible.value]])];
511
- }
519
+ default: () => [createVNode(FlexibleOverlay, {
520
+ "modelValue": isOpen.value,
521
+ "onUpdate:modelValue": ($event) => isOpen.value = $event,
522
+ "origin": origin.value,
523
+ "position": position.value,
524
+ "align": align.value,
525
+ "offset": offset2.value,
526
+ "onPositionChange": handlePositionChange,
527
+ "class": classes.value,
528
+ "style": styles.value
529
+ }, {
530
+ default: () => {
531
+ var _a2;
532
+ return [createVNode("div", mergeProps({
533
+ "ref": dropdownRef,
534
+ "class": "devui-dropdown-menu-wrap"
535
+ }, attrs), [(_a2 = slots.menu) == null ? void 0 : _a2.call(slots)])];
536
+ }
537
+ })]
512
538
  })]
513
539
  })]);
514
540
  };
515
541
  }
516
542
  });
517
- Dropdown.install = function(app) {
518
- app.component(Dropdown.name, Dropdown);
543
+ const dropdownMenuProps = {
544
+ modelValue: {
545
+ type: Boolean,
546
+ default: false
547
+ },
548
+ origin: {
549
+ type: Object,
550
+ require: true
551
+ },
552
+ position: {
553
+ type: Array,
554
+ default: ["bottom"]
555
+ },
556
+ align: {
557
+ type: String,
558
+ default: null
559
+ },
560
+ offset: {
561
+ type: [Number, Object],
562
+ default: 4
563
+ },
564
+ clickOutside: {
565
+ type: Function,
566
+ default: () => true
567
+ }
519
568
  };
569
+ var DropdownMenu = defineComponent({
570
+ name: "DDropdownMenu",
571
+ inheritAttrs: false,
572
+ props: dropdownMenuProps,
573
+ emits: ["update:modelValue"],
574
+ setup(props, {
575
+ slots,
576
+ attrs,
577
+ emit
578
+ }) {
579
+ const {
580
+ modelValue,
581
+ origin,
582
+ position,
583
+ align,
584
+ offset: offset2,
585
+ clickOutside
586
+ } = toRefs(props);
587
+ const dropdownMenuRef = ref(null);
588
+ onClickOutside(dropdownMenuRef, (value) => {
589
+ var _a;
590
+ if (((_a = clickOutside.value) == null ? void 0 : _a.call(clickOutside)) && !origin.value.contains(value.target)) {
591
+ emit("update:modelValue", false);
592
+ }
593
+ });
594
+ const currentPosition = ref("bottom");
595
+ const handlePositionChange = (pos) => {
596
+ currentPosition.value = pos.split("-")[0] === "top" ? "top" : "bottom";
597
+ };
598
+ const styles = computed(() => ({
599
+ transformOrigin: currentPosition.value === "top" ? "0% 100%" : "0% 0%"
600
+ }));
601
+ return () => createVNode(Teleport, {
602
+ "to": "body"
603
+ }, {
604
+ default: () => [createVNode(Transition, {
605
+ "name": `devui-dropdown-fade-${currentPosition.value}`
606
+ }, {
607
+ default: () => [createVNode(FlexibleOverlay, {
608
+ "modelValue": modelValue.value,
609
+ "onUpdate:modelValue": ($event) => modelValue.value = $event,
610
+ "origin": origin == null ? void 0 : origin.value,
611
+ "position": position.value,
612
+ "align": align.value,
613
+ "offset": offset2.value,
614
+ "onPositionChange": handlePositionChange,
615
+ "style": styles.value
616
+ }, {
617
+ default: () => {
618
+ var _a;
619
+ return [createVNode("div", mergeProps({
620
+ "ref": dropdownMenuRef,
621
+ "class": "devui-dropdown-menu-wrap"
622
+ }, attrs), [(_a = slots.default) == null ? void 0 : _a.call(slots)])];
623
+ }
624
+ })]
625
+ })]
626
+ });
627
+ }
628
+ });
520
629
  var index = {
521
630
  title: "Dropdown \u4E0B\u62C9\u83DC\u5355",
522
631
  category: "\u5BFC\u822A",
523
- status: void 0,
632
+ status: "10%",
524
633
  install(app) {
525
- app.use(Dropdown);
634
+ app.component(Dropdown.name, Dropdown);
635
+ app.component(DropdownMenu.name, DropdownMenu);
526
636
  }
527
637
  };
528
- export { Dropdown, index as default };
638
+ export { Dropdown, DropdownMenu, index as default, dropdownMenuProps };