vue-devui 1.0.0-beta.18 → 1.0.0-beta.19

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 (161) hide show
  1. package/README.md +200 -187
  2. package/accordion/index.es.js +221 -6
  3. package/accordion/index.umd.js +1 -1
  4. package/alert/index.es.js +28 -30
  5. package/alert/index.umd.js +1 -1
  6. package/auto-complete/index.es.js +131 -269
  7. package/auto-complete/index.umd.js +1 -1
  8. package/auto-complete/style.css +1 -1
  9. package/back-top/index.es.js +4 -2
  10. package/badge/index.es.js +13 -19
  11. package/badge/index.umd.js +1 -1
  12. package/badge/style.css +1 -1
  13. package/breadcrumb/index.es.js +2 -1
  14. package/button/index.es.js +39 -40
  15. package/button/index.umd.js +1 -1
  16. package/carousel/index.es.js +38 -53
  17. package/carousel/index.umd.js +1 -1
  18. package/cascader/index.es.js +16 -8
  19. package/cascader/style.css +1 -1
  20. package/color-picker/index.es.js +97 -89
  21. package/color-picker/index.umd.js +7 -7
  22. package/countdown/index.es.js +2 -1
  23. package/date-picker/index.es.js +40 -57
  24. package/date-picker/index.umd.js +1 -1
  25. package/date-picker/style.css +1 -1
  26. package/drawer/index.es.js +162 -5741
  27. package/drawer/index.umd.js +1 -27
  28. package/drawer/style.css +1 -1
  29. package/dropdown/index.es.js +459 -301
  30. package/dropdown/index.umd.js +1 -1
  31. package/dropdown/style.css +1 -1
  32. package/editable-select/index.es.js +6 -3
  33. package/form/index.es.js +1953 -1550
  34. package/form/index.umd.js +18 -18
  35. package/form/style.css +1 -1
  36. package/fullscreen/index.es.js +112 -133
  37. package/fullscreen/index.umd.js +1 -1
  38. package/fullscreen/style.css +1 -1
  39. package/icon/index.es.js +39 -57
  40. package/icon/index.umd.js +1 -1
  41. package/image-preview/index.es.js +2 -1
  42. package/input/style.css +1 -1
  43. package/input-icon/index.es.js +38 -37
  44. package/input-icon/index.umd.js +1 -1
  45. package/input-icon/style.css +1 -1
  46. package/input-number/index.es.js +46 -57
  47. package/input-number/index.umd.js +1 -1
  48. package/input-number/style.css +1 -1
  49. package/{time-axis → list}/index.d.ts +0 -0
  50. package/list/index.es.js +39 -0
  51. package/list/index.umd.js +1 -0
  52. package/{toast → list}/package.json +1 -1
  53. package/list/style.css +1 -0
  54. package/modal/index.es.js +300 -934
  55. package/modal/index.umd.js +1 -1
  56. package/modal/style.css +1 -1
  57. package/{toast → notification}/index.d.ts +0 -0
  58. package/notification/index.es.js +284 -0
  59. package/notification/index.umd.js +1 -0
  60. package/notification/package.json +7 -0
  61. package/notification/style.css +1 -0
  62. package/nuxt/components/DropdownMenu.js +3 -0
  63. package/nuxt/components/IFileOptions.js +3 -0
  64. package/nuxt/components/IUploadOptions.js +3 -0
  65. package/nuxt/components/List.js +3 -0
  66. package/nuxt/components/ListItem.js +3 -0
  67. package/nuxt/components/Notification.js +3 -0
  68. package/nuxt/components/NotificationService.js +3 -0
  69. package/nuxt/components/PanelBody.js +3 -0
  70. package/nuxt/components/PanelFooter.js +3 -0
  71. package/nuxt/components/PanelHeader.js +3 -0
  72. package/nuxt/components/Timeline.js +3 -0
  73. package/nuxt/components/TimelineItem.js +3 -0
  74. package/nuxt/components/UploadStatus.js +3 -0
  75. package/nuxt/components/alertProps.js +3 -0
  76. package/nuxt/components/badgeProps.js +3 -0
  77. package/nuxt/components/dropdownMenuProps.js +3 -0
  78. package/nuxt/components/fixedOverlayProps.js +3 -0
  79. package/nuxt/components/flexibleOverlayProps.js +3 -0
  80. package/nuxt/components/fullscreenProps.js +3 -0
  81. package/nuxt/components/iconProps.js +2 -0
  82. package/nuxt/components/notificationProps.js +3 -0
  83. package/nuxt/components/overlayEmits.js +3 -0
  84. package/nuxt/components/overlayProps.js +3 -0
  85. package/nuxt/components/paginationProps.js +3 -0
  86. package/nuxt/components/panelProps.js +3 -0
  87. package/nuxt/components/popoverProps.js +3 -0
  88. package/nuxt/components/searchProps.js +3 -0
  89. package/nuxt/components/tooltipProps.js +3 -0
  90. package/nuxt/components/uploadProps.js +3 -0
  91. package/overlay/index.es.js +152 -198
  92. package/overlay/index.umd.js +1 -1
  93. package/overlay/style.css +1 -1
  94. package/package.json +40 -87
  95. package/pagination/index.es.js +10 -12
  96. package/pagination/index.umd.js +1 -1
  97. package/panel/index.es.js +45 -32
  98. package/panel/index.umd.js +1 -1
  99. package/popover/index.es.js +5954 -201
  100. package/popover/index.umd.js +27 -1
  101. package/popover/style.css +1 -1
  102. package/read-tip/index.es.js +6 -3
  103. package/result/index.es.js +38 -53
  104. package/result/index.umd.js +1 -1
  105. package/ripple/index.es.js +9 -5
  106. package/search/index.es.js +19 -29
  107. package/search/index.umd.js +6 -6
  108. package/search/style.css +1 -1
  109. package/select/index.es.js +42 -42
  110. package/select/index.umd.js +1 -1
  111. package/select/style.css +1 -1
  112. package/skeleton/index.es.js +17 -17
  113. package/skeleton/index.umd.js +1 -1
  114. package/slider/index.es.js +2 -1
  115. package/splitter/index.es.js +5814 -98
  116. package/splitter/index.umd.js +27 -1
  117. package/splitter/style.css +1 -1
  118. package/status/index.es.js +1 -4
  119. package/status/index.umd.js +1 -1
  120. package/status/style.css +1 -1
  121. package/steps-guide/index.es.js +6 -3
  122. package/style.css +1 -1
  123. package/table/index.es.js +456 -299
  124. package/table/index.umd.js +1 -1
  125. package/table/style.css +1 -1
  126. package/tabs/index.es.js +3 -4
  127. package/tabs/index.umd.js +1 -1
  128. package/tag/index.es.js +2 -1
  129. package/tag-input/index.es.js +4 -2
  130. package/textarea/style.css +1 -1
  131. package/time-picker/index.es.js +43 -42
  132. package/time-picker/index.umd.js +1 -1
  133. package/timeline/index.d.ts +7 -0
  134. package/{time-axis → timeline}/index.es.js +65 -78
  135. package/timeline/index.umd.js +1 -0
  136. package/{time-axis → timeline}/package.json +1 -1
  137. package/timeline/style.css +1 -0
  138. package/tooltip/index.es.js +5804 -94
  139. package/tooltip/index.umd.js +27 -1
  140. package/tooltip/style.css +1 -1
  141. package/transfer/index.es.js +440 -165
  142. package/transfer/index.umd.js +17 -17
  143. package/transfer/style.css +1 -1
  144. package/tree/index.es.js +12 -7
  145. package/tree/index.umd.js +10 -10
  146. package/tree-select/index.es.js +10 -6
  147. package/tree-select/index.umd.js +1 -1
  148. package/upload/index.es.js +335 -6068
  149. package/upload/index.umd.js +1 -27
  150. package/upload/style.css +1 -1
  151. package/vue-devui.es.js +2555 -2799
  152. package/vue-devui.umd.js +16 -16
  153. package/nuxt/components/TimeAxis.js +0 -3
  154. package/nuxt/components/TimeAxisItem.js +0 -3
  155. package/nuxt/components/Toast.js +0 -3
  156. package/nuxt/components/ToastService.js +0 -3
  157. package/time-axis/index.umd.js +0 -1
  158. package/time-axis/style.css +0 -1
  159. package/toast/index.es.js +0 -5918
  160. package/toast/index.umd.js +0 -27
  161. package/toast/style.css +0 -1
package/table/index.es.js CHANGED
@@ -21,7 +21,9 @@ var __publicField = (obj, key, value) => {
21
21
  __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
22
  return value;
23
23
  };
24
- import { computed, ref, watch, defineComponent, inject, createVNode, mergeProps, toRef, provide, Teleport, Transition, renderSlot, isVNode, onMounted, onUnmounted, withDirectives, vShow, reactive, isRef, toRefs, Fragment, shallowRef, getCurrentInstance, createTextVNode, resolveDirective, onBeforeMount, h, onBeforeUnmount, render } from "vue";
24
+ import { computed, ref, watch, defineComponent, inject, createVNode, mergeProps, toRef, provide, toRefs, onMounted, onUnmounted, Teleport, Transition, renderSlot, isVNode, unref, nextTick, Fragment, withDirectives, vShow, shallowRef, getCurrentInstance, createTextVNode, resolveDirective, reactive, onBeforeMount, h, onBeforeUnmount, render } from "vue";
25
+ import { shift, offset, autoPlacement, arrow, computePosition } from "@floating-ui/dom";
26
+ import { onClickOutside } from "@vueuse/core";
25
27
  const TableProps = {
26
28
  data: {
27
29
  type: Array,
@@ -686,14 +688,7 @@ const Sort = defineComponent({
686
688
  }
687
689
  });
688
690
  const dropdownProps = {
689
- origin: {
690
- type: Object
691
- },
692
- isOpen: {
693
- type: Boolean,
694
- default: false
695
- },
696
- disabled: {
691
+ visible: {
697
692
  type: Boolean,
698
693
  default: false
699
694
  },
@@ -705,6 +700,18 @@ const dropdownProps = {
705
700
  type: String,
706
701
  default: "all"
707
702
  },
703
+ position: {
704
+ type: Array,
705
+ default: ["bottom"]
706
+ },
707
+ align: {
708
+ type: String,
709
+ default: null
710
+ },
711
+ offset: {
712
+ type: [Number, Object],
713
+ default: 4
714
+ },
708
715
  closeOnMouseLeaveMenu: {
709
716
  type: Boolean,
710
717
  default: false
@@ -713,14 +720,15 @@ const dropdownProps = {
713
720
  type: Boolean,
714
721
  default: true
715
722
  },
716
- width: {
717
- type: [Number, String],
718
- default: "102px"
723
+ overlayClass: {
724
+ type: String,
725
+ default: ""
726
+ },
727
+ destroyOnHide: {
728
+ type: Boolean,
729
+ default: true
719
730
  }
720
731
  };
721
- function isComponent(target) {
722
- return !!(target == null ? void 0 : target.$el);
723
- }
724
732
  function getElement(element) {
725
733
  if (element instanceof Element) {
726
734
  return element;
@@ -730,85 +738,158 @@ function getElement(element) {
730
738
  }
731
739
  return null;
732
740
  }
741
+ const dropdownMap = /* @__PURE__ */ new Map();
733
742
  function subscribeEvent(dom, type, callback) {
734
743
  dom == null ? void 0 : dom.addEventListener(type, callback);
735
744
  return () => {
736
745
  dom == null ? void 0 : dom.removeEventListener(type, callback);
737
746
  };
738
747
  }
739
- const useDropdown = ({
740
- visible,
741
- trigger,
742
- origin,
743
- closeScope,
744
- closeOnMouseLeaveMenu
745
- }) => {
746
- const dropdownElRef = ref();
747
- const closeByScope = () => {
748
- if (closeScope.value === "none") {
749
- return;
750
- }
751
- visible.value = false;
748
+ const useDropdownEvent = ({ id, isOpen, origin, dropdownRef, props, emit }) => {
749
+ let overlayEnter = false;
750
+ let originEnter = false;
751
+ const { trigger, closeScope, closeOnMouseLeaveMenu } = toRefs(props);
752
+ const toggle = (status) => {
753
+ isOpen.value = status;
754
+ emit("toggle", isOpen.value);
752
755
  };
753
- watch([trigger, origin, dropdownElRef], ([trigger2, origin2, dropdownEl], ov, onInvalidate) => {
754
- const originEl = getElement(origin2);
755
- if (!originEl || !dropdownEl) {
756
+ const handleLeave = async (elementType, closeAll) => {
757
+ await new Promise((resolve) => setTimeout(resolve, 50));
758
+ if (elementType === "origin" && overlayEnter || elementType === "dropdown" && originEnter) {
756
759
  return;
757
760
  }
758
- const subscriptions = [
759
- subscribeEvent(dropdownEl, "click", () => {
760
- if (closeScope.value === "all") {
761
- visible.value = false;
762
- }
763
- })
764
- ];
765
- if (trigger2 === "click") {
766
- subscriptions.push(subscribeEvent(originEl, "click", () => visible.value = !visible.value), subscribeEvent(document, "click", (e) => {
767
- if (!visible.value) {
768
- return;
769
- }
770
- const target = e.target;
771
- const isContain = originEl.contains(target) || dropdownEl.contains(target);
772
- if (isContain) {
761
+ if (closeAll) {
762
+ [...dropdownMap.values()].reverse().forEach((item) => {
763
+ setTimeout(() => {
764
+ var _a;
765
+ (_a = item.toggle) == null ? void 0 : _a.call(item);
766
+ }, 0);
767
+ });
768
+ }
769
+ toggle(false);
770
+ };
771
+ watch([trigger, origin, dropdownRef], ([triggerVal, originVal, dropdownEl], ov, onInvalidate) => {
772
+ const originEl = getElement(originVal);
773
+ const subscriptions = [];
774
+ setTimeout(() => {
775
+ subscriptions.push(subscribeEvent(document, "click", (e) => {
776
+ const dropdownValues = [...dropdownMap.values()];
777
+ if (!isOpen.value || closeScope.value === "none" || dropdownEl.contains(e.target) && closeScope.value === "blank" || dropdownValues.some((item) => {
778
+ var _a;
779
+ return (_a = item.toggleEl) == null ? void 0 : _a.contains(e.target);
780
+ }) && dropdownValues.some((item) => {
781
+ var _a;
782
+ return (_a = item.menuEl) == null ? void 0 : _a.contains(e.target);
783
+ })) {
773
784
  return;
774
785
  }
775
- closeByScope();
776
- }), subscribeEvent(dropdownEl, "mouseleave", () => {
777
- if (closeOnMouseLeaveMenu.value) {
778
- visible.value = false;
779
- }
786
+ [...dropdownMap.values()].reverse().forEach((item) => {
787
+ setTimeout(() => {
788
+ var _a, _b;
789
+ if (!((_a = item.toggleEl) == null ? void 0 : _a.contains(e.target))) {
790
+ (_b = item.toggle) == null ? void 0 : _b.call(item);
791
+ }
792
+ }, 0);
793
+ });
794
+ overlayEnter = false;
780
795
  }));
781
- } else if (trigger2 === "hover") {
782
- let overlayEnter = false;
783
- let originEnter = false;
784
- const handleLeave = async (elementType) => {
785
- await new Promise((resolve) => setTimeout(resolve, 50));
786
- if (elementType === "origin" && overlayEnter || elementType === "dropdown" && originEnter) {
787
- return;
796
+ }, 0);
797
+ if (triggerVal === "click") {
798
+ subscriptions.push(subscribeEvent(originEl, "click", () => toggle(!isOpen.value)), subscribeEvent(dropdownEl, "mouseleave", (e) => {
799
+ var _a;
800
+ if (closeOnMouseLeaveMenu.value && !((_a = dropdownMap.get(id).child) == null ? void 0 : _a.contains(e.relatedTarget))) {
801
+ handleLeave("dropdown", true);
788
802
  }
789
- closeByScope();
790
- };
803
+ }));
804
+ } else if (triggerVal === "hover") {
791
805
  subscriptions.push(subscribeEvent(originEl, "mouseenter", () => {
792
806
  originEnter = true;
793
- visible.value = true;
807
+ toggle(true);
794
808
  }), subscribeEvent(originEl, "mouseleave", () => {
795
809
  originEnter = false;
796
- if (!closeOnMouseLeaveMenu.value) {
797
- handleLeave("origin");
798
- }
810
+ handleLeave("origin");
799
811
  }), subscribeEvent(dropdownEl, "mouseenter", () => {
800
812
  overlayEnter = true;
801
- visible.value = true;
802
- }), subscribeEvent(dropdownEl, "mouseleave", () => {
813
+ isOpen.value = true;
814
+ }), subscribeEvent(dropdownEl, "mouseleave", (e) => {
815
+ var _a;
803
816
  overlayEnter = false;
804
- handleLeave("dropdown");
817
+ if (e.relatedTarget && ((originEl == null ? void 0 : originEl.contains(e.relatedTarget)) || ((_a = dropdownMap.get(id).child) == null ? void 0 : _a.contains(e.relatedTarget)))) {
818
+ return;
819
+ }
820
+ handleLeave("dropdown", true);
805
821
  }));
806
822
  }
807
823
  onInvalidate(() => subscriptions.forEach((v) => v()));
808
824
  });
809
- return { dropdownEl: dropdownElRef };
810
825
  };
811
- var overlay = "";
826
+ function useDropdown(id, visible, isOpen, origin, dropdownRef, popDirection, emit) {
827
+ const calcPopDirection = (dropdownEl) => {
828
+ const elementHeight = dropdownEl.offsetHeight;
829
+ const bottomDistance = window.innerHeight - origin.value.getBoundingClientRect().bottom;
830
+ const isBottomEnough = bottomDistance >= elementHeight;
831
+ if (!isBottomEnough) {
832
+ popDirection.value = "top";
833
+ } else {
834
+ popDirection.value = "bottom";
835
+ }
836
+ };
837
+ watch(visible, (newVal, oldVal) => {
838
+ if (oldVal === void 0) {
839
+ return;
840
+ }
841
+ isOpen.value = newVal;
842
+ emit("toggle", isOpen.value);
843
+ }, { immediate: true });
844
+ watch([isOpen, dropdownRef], ([isOpenVal, dropdownEl]) => {
845
+ var _a;
846
+ if (isOpenVal) {
847
+ dropdownMap.set(id, __spreadProps(__spreadValues({}, dropdownMap.get(id)), {
848
+ menuEl: dropdownEl,
849
+ toggle: () => {
850
+ isOpen.value = false;
851
+ emit("toggle", isOpen.value);
852
+ }
853
+ }));
854
+ for (const value of dropdownMap.values()) {
855
+ if ((_a = value.menuEl) == null ? void 0 : _a.contains(origin.value)) {
856
+ value.child = dropdownEl;
857
+ }
858
+ }
859
+ }
860
+ if (dropdownEl) {
861
+ calcPopDirection(dropdownEl);
862
+ }
863
+ });
864
+ onMounted(() => {
865
+ dropdownMap.set(id, { toggleEl: origin.value });
866
+ });
867
+ onUnmounted(() => {
868
+ dropdownMap.delete(id);
869
+ });
870
+ }
871
+ function useOverlayProps(props, currentPosition, isOpen) {
872
+ const { showAnimation, overlayClass, destroyOnHide } = toRefs(props);
873
+ const overlayModelValue = ref(false);
874
+ const overlayShowValue = ref(false);
875
+ const styles = computed(() => ({
876
+ transformOrigin: currentPosition.value === "top" ? "0% 100%" : "0% 0%"
877
+ }));
878
+ const classes = computed(() => ({
879
+ "fade-in-bottom": showAnimation.value && isOpen.value && currentPosition.value === "bottom",
880
+ "fade-in-top": showAnimation.value && isOpen.value && currentPosition.value === "top",
881
+ [`${overlayClass.value}`]: true
882
+ }));
883
+ const handlePositionChange = (pos) => {
884
+ currentPosition.value = pos.includes("top") || pos.includes("end") ? "top" : "bottom";
885
+ };
886
+ watch(isOpen, (isOpenVal) => {
887
+ overlayModelValue.value = destroyOnHide.value ? isOpenVal : true;
888
+ overlayShowValue.value = isOpenVal;
889
+ });
890
+ return { overlayModelValue, overlayShowValue, styles, classes, handlePositionChange };
891
+ }
892
+ var baseOverlay = "";
812
893
  function _isSlot(s) {
813
894
  return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
814
895
  }
@@ -855,28 +936,13 @@ const overlayProps = {
855
936
  default: true
856
937
  }
857
938
  };
858
- const overlayEmits = ["update:visible", "backdropClick"];
859
939
  const fixedOverlayProps = __spreadProps(__spreadValues({}, overlayProps), {
860
940
  overlayStyle: {
861
941
  type: [String, Object],
862
942
  default: void 0
863
943
  }
864
944
  });
865
- const flexibleOverlayProps = __spreadValues({
866
- origin: {
867
- type: Object,
868
- require: true
869
- },
870
- position: {
871
- type: Object,
872
- default: () => ({
873
- originX: "left",
874
- originY: "top",
875
- overlayX: "left",
876
- overlayY: "top"
877
- })
878
- }
879
- }, overlayProps);
945
+ const overlayEmits = ["update:visible", "backdropClick"];
880
946
  function useOverlayLogic(props, ctx) {
881
947
  const backgroundClass = computed(() => {
882
948
  return [
@@ -927,7 +993,8 @@ function useOverlayLogic(props, ctx) {
927
993
  handleOverlayBubbleCancel
928
994
  };
929
995
  }
930
- const FixedOverlay = defineComponent({
996
+ var fixedOverlay = "";
997
+ defineComponent({
931
998
  name: "DFixedOverlay",
932
999
  props: fixedOverlayProps,
933
1000
  emits: overlayEmits,
@@ -939,7 +1006,7 @@ const FixedOverlay = defineComponent({
939
1006
  handleOverlayBubbleCancel
940
1007
  } = useOverlayLogic(props, ctx);
941
1008
  return () => createVNode(CommonOverlay, null, {
942
- default: () => [withDirectives(createVNode("div", {
1009
+ default: () => [props.visible && createVNode("div", {
943
1010
  "class": backgroundClass.value,
944
1011
  "style": props.backgroundStyle,
945
1012
  "onClick": handleBackdropClick
@@ -947,250 +1014,340 @@ const FixedOverlay = defineComponent({
947
1014
  "class": overlayClass.value,
948
1015
  "style": props.overlayStyle,
949
1016
  "onClick": handleOverlayBubbleCancel
950
- }, [renderSlot(ctx.slots, "default")])]), [[vShow, props.visible]])]
1017
+ }, [renderSlot(ctx.slots, "default")])])]
951
1018
  });
952
1019
  }
953
1020
  });
954
- const FlexibleOverlay = defineComponent({
955
- name: "DFlexibleOverlay",
956
- props: flexibleOverlayProps,
957
- emits: overlayEmits,
958
- setup(props, ctx) {
959
- const overlayRef = ref(null);
960
- const positionedStyle = reactive({
961
- position: "absolute"
962
- });
963
- onMounted(async () => {
964
- const handleRectChange = (position, rect, origin) => {
965
- const point = calculatePosition(position, rect, origin);
966
- positionedStyle.left = `${point.x}px`;
967
- positionedStyle.top = `${point.y}px`;
968
- };
969
- const locationElements = computed(() => {
970
- const overlay2 = overlayRef.value;
971
- const origin = getOrigin(props.origin);
972
- if (!overlay2 || !origin) {
973
- return;
974
- }
975
- return {
976
- origin,
977
- overlay: overlay2
978
- };
979
- });
980
- const visibleRef = toRef(props, "visible");
981
- const positionRef = toRef(props, "position");
982
- watch([locationElements, visibleRef, positionRef], async ([locationElements2, visible, position], ov, onInvalidate) => {
983
- if (!visible || !locationElements2) {
984
- return;
985
- }
986
- const {
987
- origin,
988
- overlay: overlay2
989
- } = locationElements2;
990
- handleRectChange(position, overlay2.getBoundingClientRect(), origin);
991
- const unsubscriptions = [subscribeLayoutEvent(() => handleRectChange(position, overlay2.getBoundingClientRect(), origin)), subscribeOverlayResize(overlay2, (entries) => handleRectChange(position, entries[0].contentRect, origin)), subscribeOriginResize(origin, () => handleRectChange(position, overlay2.getBoundingClientRect(), origin))];
992
- onInvalidate(() => {
993
- unsubscriptions.forEach((fn) => fn());
994
- });
995
- });
996
- });
997
- const {
998
- backgroundClass,
999
- overlayClass,
1000
- handleBackdropClick,
1001
- handleOverlayBubbleCancel
1002
- } = useOverlayLogic(props, ctx);
1003
- return () => createVNode(CommonOverlay, null, {
1004
- default: () => [withDirectives(createVNode("div", {
1005
- "style": props.backgroundStyle,
1006
- "class": backgroundClass.value,
1007
- "onClick": handleBackdropClick
1008
- }, [createVNode("div", {
1009
- "ref": overlayRef,
1010
- "class": overlayClass.value,
1011
- "style": positionedStyle,
1012
- "onClick": handleOverlayBubbleCancel
1013
- }, [renderSlot(ctx.slots, "default")])]), [[vShow, props.visible]])]
1014
- });
1015
- }
1016
- });
1017
- function getOrigin(origin) {
1018
- if (origin instanceof Element) {
1019
- return origin;
1020
- }
1021
- if (isRef(origin)) {
1022
- return getElement(origin.value);
1023
- }
1024
- if (isComponent(origin)) {
1025
- return getElement(origin);
1026
- }
1027
- return origin;
1028
- }
1029
- function calculatePosition(position, rect, origin) {
1030
- const originRect = getOriginRect(origin);
1031
- const originPoint = getOriginRelativePoint(originRect, position);
1032
- return getOverlayPoint(originPoint, rect, position);
1033
- }
1034
- function getOriginRect(origin) {
1035
- if (origin instanceof Element) {
1036
- return origin.getBoundingClientRect();
1037
- }
1038
- const width = origin.width || 0;
1039
- const height = origin.height || 0;
1040
- return {
1041
- top: origin.y,
1042
- bottom: origin.y + height,
1043
- left: origin.x,
1044
- right: origin.x + width,
1045
- height,
1046
- width
1047
- };
1048
- }
1049
- function getOverlayPoint(originPoint, rect, position) {
1050
- let x;
1051
- const {
1052
- width,
1053
- height
1054
- } = rect;
1055
- if (position.overlayX == "center") {
1056
- x = originPoint.x - width / 2;
1057
- } else {
1058
- x = position.overlayX == "left" ? originPoint.x : originPoint.x - width;
1021
+ const flexibleOverlayProps = {
1022
+ modelValue: {
1023
+ type: Boolean,
1024
+ default: false
1025
+ },
1026
+ origin: {
1027
+ type: Object,
1028
+ require: true
1029
+ },
1030
+ position: {
1031
+ type: Array,
1032
+ default: ["bottom"]
1033
+ },
1034
+ offset: {
1035
+ type: [Number, Object],
1036
+ default: 8
1037
+ },
1038
+ align: {
1039
+ type: String,
1040
+ default: null
1041
+ },
1042
+ showArrow: {
1043
+ type: Boolean,
1044
+ default: false
1045
+ },
1046
+ isArrowCenter: {
1047
+ type: Boolean,
1048
+ default: true
1059
1049
  }
1060
- let y;
1061
- if (position.overlayY == "center") {
1062
- y = originPoint.y - height / 2;
1063
- } else {
1064
- y = position.overlayY == "top" ? originPoint.y : originPoint.y - height;
1050
+ };
1051
+ function getScrollParent(element) {
1052
+ const overflowRegex = /(auto|scroll|hidden)/;
1053
+ for (let parent = element; parent = parent.parentElement; parent.parentElement !== document.body) {
1054
+ const style = window.getComputedStyle(parent);
1055
+ if (overflowRegex.test(style.overflow + style.overflowX + style.overflowY)) {
1056
+ return parent;
1057
+ }
1065
1058
  }
1066
- return {
1067
- x,
1068
- y
1069
- };
1059
+ return window;
1070
1060
  }
1071
- function getOriginRelativePoint(originRect, position) {
1072
- let x;
1073
- if (position.originX == "center") {
1074
- x = originRect.left + originRect.width / 2;
1075
- } else {
1076
- const startX = originRect.left;
1077
- const endX = originRect.right;
1078
- x = position.originX == "left" ? startX : endX;
1079
- }
1080
- let y;
1081
- if (position.originY == "center") {
1082
- y = originRect.top + originRect.height / 2;
1083
- } else {
1084
- y = position.originY == "top" ? originRect.top : originRect.bottom;
1061
+ function adjustArrowPosition(isArrowCenter, point, placement, originRect) {
1062
+ let { x, y } = point;
1063
+ if (!isArrowCenter) {
1064
+ const { width, height } = originRect;
1065
+ if (x && placement.includes("start")) {
1066
+ x = 12;
1067
+ }
1068
+ if (x && placement.includes("end")) {
1069
+ x = Math.round(width - 24);
1070
+ }
1071
+ if (y && placement.includes("start")) {
1072
+ y = 10;
1073
+ }
1074
+ if (y && placement.includes("end")) {
1075
+ y = height - 14;
1076
+ }
1085
1077
  }
1086
- return {
1087
- x,
1088
- y
1089
- };
1078
+ return { x, y };
1090
1079
  }
1091
- function subscribeLayoutEvent(event) {
1092
- window.addEventListener("scroll", event, true);
1093
- window.addEventListener("resize", event);
1094
- window.addEventListener("orientationchange", event);
1095
- return () => {
1096
- window.removeEventListener("scroll", event, true);
1097
- window.removeEventListener("resize", event);
1098
- window.removeEventListener("orientationchange", event);
1080
+ function useOverlay(props, emit) {
1081
+ const overlayRef = ref();
1082
+ const arrowRef = ref();
1083
+ const updateArrowPosition = (arrowEl, placement, point, overlayEl) => {
1084
+ const { x, y } = adjustArrowPosition(props.isArrowCenter, point, placement, overlayEl.getBoundingClientRect());
1085
+ const staticSide = {
1086
+ top: "bottom",
1087
+ right: "left",
1088
+ bottom: "top",
1089
+ left: "right"
1090
+ }[placement.split("-")[0]];
1091
+ Object.assign(arrowEl.style, {
1092
+ left: x ? `${x}px` : "",
1093
+ top: y ? `${y}px` : "",
1094
+ right: "",
1095
+ bottom: "",
1096
+ [staticSide]: "-4px"
1097
+ });
1099
1098
  };
1100
- }
1101
- function subscribeOverlayResize(overlay2, callback) {
1102
- if (overlay2 instanceof Element) {
1103
- const resizeObserver = new ResizeObserver(callback);
1104
- resizeObserver.observe(overlay2);
1105
- return () => resizeObserver.disconnect();
1106
- }
1107
- return () => {
1099
+ const updatePosition = async () => {
1100
+ const hostEl = props.origin;
1101
+ const overlayEl = unref(overlayRef.value);
1102
+ const arrowEl = unref(arrowRef.value);
1103
+ const middleware = [
1104
+ shift(),
1105
+ offset(props.offset),
1106
+ autoPlacement({
1107
+ alignment: props.align,
1108
+ allowedPlacements: props.position
1109
+ })
1110
+ ];
1111
+ props.showArrow && middleware.push(arrow({ element: arrowEl }));
1112
+ const { x, y, placement, middlewareData } = await computePosition(hostEl, overlayEl, {
1113
+ strategy: "fixed",
1114
+ middleware
1115
+ });
1116
+ emit("positionChange", placement);
1117
+ Object.assign(overlayEl.style, { top: `${y}px`, left: `${x}px` });
1118
+ props.showArrow && updateArrowPosition(arrowEl, placement, middlewareData.arrow, overlayEl);
1108
1119
  };
1120
+ watch(() => props.modelValue, () => {
1121
+ const originParent = getScrollParent(props.origin);
1122
+ if (props.modelValue && props.origin) {
1123
+ nextTick(updatePosition);
1124
+ originParent.addEventListener("scroll", updatePosition);
1125
+ originParent !== window && window.addEventListener("scroll", updatePosition);
1126
+ window.addEventListener("resize", updatePosition);
1127
+ } else {
1128
+ originParent.removeEventListener("scroll", updatePosition);
1129
+ originParent !== window && window.removeEventListener("scroll", updatePosition);
1130
+ window.removeEventListener("resize", updatePosition);
1131
+ }
1132
+ });
1133
+ onUnmounted(() => {
1134
+ const originParent = getScrollParent(props.origin);
1135
+ originParent.removeEventListener("scroll", updatePosition);
1136
+ originParent !== window && window.removeEventListener("scroll", updatePosition);
1137
+ window.removeEventListener("resize", updatePosition);
1138
+ });
1139
+ return { arrowRef, overlayRef, updatePosition };
1109
1140
  }
1110
- function subscribeOriginResize(origin, callback) {
1111
- if (origin instanceof Element) {
1112
- const observer = new MutationObserver(callback);
1113
- observer.observe(origin, {
1114
- attributeFilter: ["style"]
1141
+ var flexibleOverlay = "";
1142
+ const FlexibleOverlay = defineComponent({
1143
+ name: "DFlexibleOverlay",
1144
+ inheritAttrs: false,
1145
+ props: flexibleOverlayProps,
1146
+ emits: ["update:modelValue", "positionChange"],
1147
+ setup(props, {
1148
+ slots,
1149
+ attrs,
1150
+ emit,
1151
+ expose
1152
+ }) {
1153
+ const {
1154
+ arrowRef,
1155
+ overlayRef,
1156
+ updatePosition
1157
+ } = useOverlay(props, emit);
1158
+ expose({
1159
+ updatePosition
1115
1160
  });
1116
- return () => observer.disconnect();
1161
+ return () => {
1162
+ var _a;
1163
+ return props.modelValue && createVNode("div", mergeProps({
1164
+ "ref": overlayRef,
1165
+ "class": "devui-flexible-overlay"
1166
+ }, attrs), [(_a = slots.default) == null ? void 0 : _a.call(slots), props.showArrow && createVNode("div", {
1167
+ "ref": arrowRef,
1168
+ "class": "devui-flexible-overlay-arrow"
1169
+ }, null)]);
1170
+ };
1117
1171
  }
1118
- return () => {
1119
- };
1120
- }
1121
- FlexibleOverlay.install = function(app) {
1122
- app.component(FlexibleOverlay.name, FlexibleOverlay);
1123
- };
1124
- FixedOverlay.install = function(app) {
1125
- app.component(FixedOverlay.name, FixedOverlay);
1126
- };
1172
+ });
1127
1173
  var dropdown = "";
1174
+ let dropdownId = 1;
1128
1175
  var Dropdown = defineComponent({
1129
1176
  name: "DDropdown",
1177
+ inheritAttrs: false,
1130
1178
  props: dropdownProps,
1131
- emits: [],
1132
- setup(props, ctx) {
1179
+ emits: ["toggle"],
1180
+ setup(props, {
1181
+ slots,
1182
+ attrs,
1183
+ emit,
1184
+ expose
1185
+ }) {
1133
1186
  const {
1187
+ visible,
1188
+ position,
1189
+ align,
1190
+ offset: offset2,
1191
+ showAnimation
1192
+ } = toRefs(props);
1193
+ const origin = ref();
1194
+ const dropdownRef = ref();
1195
+ const overlayRef = ref();
1196
+ const id = `dropdown_${dropdownId++}`;
1197
+ const isOpen = ref(false);
1198
+ const currentPosition = ref("bottom");
1199
+ useDropdownEvent({
1200
+ id,
1134
1201
  isOpen,
1135
1202
  origin,
1136
- trigger,
1137
- closeScope,
1138
- closeOnMouseLeaveMenu
1139
- } = toRefs(props);
1140
- const visible = ref(false);
1141
- watch(isOpen, (value) => {
1142
- visible.value = value;
1143
- }, {
1144
- immediate: true
1203
+ dropdownRef,
1204
+ props,
1205
+ emit
1145
1206
  });
1146
- const position = {
1147
- originX: "center",
1148
- originY: "bottom",
1149
- overlayX: "center",
1150
- overlayY: "top"
1207
+ useDropdown(id, visible, isOpen, origin, dropdownRef, currentPosition, emit);
1208
+ const {
1209
+ overlayModelValue,
1210
+ overlayShowValue,
1211
+ styles,
1212
+ classes,
1213
+ handlePositionChange
1214
+ } = useOverlayProps(props, currentPosition, isOpen);
1215
+ expose({
1216
+ updatePosition: () => overlayRef.value.updatePosition()
1217
+ });
1218
+ return () => {
1219
+ var _a;
1220
+ return createVNode(Fragment, null, [createVNode("div", {
1221
+ "ref": origin,
1222
+ "class": "devui-dropdown-toggle"
1223
+ }, [(_a = slots.default) == null ? void 0 : _a.call(slots)]), createVNode(Teleport, {
1224
+ "to": "body"
1225
+ }, {
1226
+ default: () => [createVNode(Transition, {
1227
+ "name": showAnimation.value ? `devui-dropdown-fade-${currentPosition.value}` : ""
1228
+ }, {
1229
+ default: () => [withDirectives(createVNode(FlexibleOverlay, {
1230
+ "modelValue": overlayModelValue.value,
1231
+ "onUpdate:modelValue": ($event) => overlayModelValue.value = $event,
1232
+ "ref": overlayRef,
1233
+ "origin": origin.value,
1234
+ "position": position.value,
1235
+ "align": align.value,
1236
+ "offset": offset2.value,
1237
+ "onPositionChange": handlePositionChange,
1238
+ "class": classes.value,
1239
+ "style": styles.value
1240
+ }, {
1241
+ default: () => {
1242
+ var _a2;
1243
+ return [createVNode("div", mergeProps({
1244
+ "ref": dropdownRef,
1245
+ "class": "devui-dropdown-menu-wrap"
1246
+ }, attrs), [(_a2 = slots.menu) == null ? void 0 : _a2.call(slots)])];
1247
+ }
1248
+ }), [[vShow, overlayShowValue.value]])]
1249
+ })]
1250
+ })]);
1151
1251
  };
1252
+ }
1253
+ });
1254
+ const dropdownMenuProps = {
1255
+ modelValue: {
1256
+ type: Boolean,
1257
+ default: false
1258
+ },
1259
+ origin: {
1260
+ type: Object,
1261
+ require: true
1262
+ },
1263
+ position: {
1264
+ type: Array,
1265
+ default: ["bottom"]
1266
+ },
1267
+ align: {
1268
+ type: String,
1269
+ default: null
1270
+ },
1271
+ offset: {
1272
+ type: [Number, Object],
1273
+ default: 4
1274
+ },
1275
+ clickOutside: {
1276
+ type: Function,
1277
+ default: () => true
1278
+ },
1279
+ showAnimation: {
1280
+ type: Boolean,
1281
+ default: true
1282
+ },
1283
+ overlayClass: {
1284
+ type: String,
1285
+ default: ""
1286
+ }
1287
+ };
1288
+ defineComponent({
1289
+ name: "DDropdownMenu",
1290
+ inheritAttrs: false,
1291
+ props: dropdownMenuProps,
1292
+ emits: ["update:modelValue"],
1293
+ setup(props, {
1294
+ slots,
1295
+ attrs,
1296
+ emit
1297
+ }) {
1152
1298
  const {
1153
- dropdownEl
1154
- } = useDropdown({
1155
- visible,
1299
+ modelValue,
1156
1300
  origin,
1157
- trigger,
1158
- closeScope,
1159
- closeOnMouseLeaveMenu
1160
- });
1161
- const animatedVisible = computed(() => {
1162
- return props.showAnimation ? visible.value : true;
1163
- });
1164
- const wrapStyle = computed(() => typeof props.width === "string" ? {
1165
- width: props.width
1166
- } : {
1167
- width: `${props.width}px`
1301
+ position,
1302
+ align,
1303
+ offset: offset2,
1304
+ clickOutside,
1305
+ showAnimation,
1306
+ overlayClass
1307
+ } = toRefs(props);
1308
+ const dropdownMenuRef = ref(null);
1309
+ onClickOutside(dropdownMenuRef, (value) => {
1310
+ var _a, _b;
1311
+ if (((_a = clickOutside.value) == null ? void 0 : _a.call(clickOutside)) && !((_b = origin == null ? void 0 : origin.value) == null ? void 0 : _b.contains(value.target))) {
1312
+ emit("update:modelValue", false);
1313
+ }
1168
1314
  });
1169
- return () => createVNode(FlexibleOverlay, {
1170
- "origin": props.origin,
1171
- "visible": visible.value,
1172
- "onUpdate:visible": ($event) => visible.value = $event,
1173
- "position": position,
1174
- "hasBackdrop": false
1315
+ const currentPosition = ref("bottom");
1316
+ const handlePositionChange = (pos) => {
1317
+ currentPosition.value = pos.split("-")[0] === "top" ? "top" : "bottom";
1318
+ };
1319
+ const styles = computed(() => ({
1320
+ transformOrigin: currentPosition.value === "top" ? "0% 100%" : "0% 0%"
1321
+ }));
1322
+ return () => createVNode(Teleport, {
1323
+ "to": "body"
1175
1324
  }, {
1176
1325
  default: () => [createVNode(Transition, {
1177
- "name": "devui-dropdown-fade"
1326
+ "name": showAnimation.value ? `devui-dropdown-fade-${currentPosition.value}` : ""
1178
1327
  }, {
1179
- default: () => {
1180
- var _a, _b;
1181
- return [withDirectives(createVNode("div", {
1182
- "ref": dropdownEl,
1183
- "class": "devui-dropdown-menu-wrap",
1184
- "style": wrapStyle.value
1185
- }, [(_b = (_a = ctx.slots).default) == null ? void 0 : _b.call(_a)]), [[vShow, animatedVisible.value]])];
1186
- }
1328
+ default: () => [createVNode(FlexibleOverlay, {
1329
+ "modelValue": modelValue.value,
1330
+ "onUpdate:modelValue": ($event) => modelValue.value = $event,
1331
+ "origin": origin == null ? void 0 : origin.value,
1332
+ "position": position.value,
1333
+ "align": align.value,
1334
+ "offset": offset2.value,
1335
+ "onPositionChange": handlePositionChange,
1336
+ "class": overlayClass.value,
1337
+ "style": styles.value
1338
+ }, {
1339
+ default: () => {
1340
+ var _a;
1341
+ return [createVNode("div", mergeProps({
1342
+ "ref": dropdownMenuRef,
1343
+ "class": "devui-dropdown-menu-wrap"
1344
+ }, attrs), [(_a = slots.default) == null ? void 0 : _a.call(slots)])];
1345
+ }
1346
+ })]
1187
1347
  })]
1188
1348
  });
1189
1349
  }
1190
1350
  });
1191
- Dropdown.install = function(app) {
1192
- app.component(Dropdown.name, Dropdown);
1193
- };
1194
1351
  var filter = "";
1195
1352
  const Filter = defineComponent({
1196
1353
  props: {