4df414bf4793a8c789282912842a65755e325c792ae70cdf061d7d187a4487d75688e6f02d3c78443ff4d39085461966401bd69b2be40f3c32f5ac3a3d2abb 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import { defineComponent, computed, ref, openBlock, createElementBlock, normalizeClass, unref, normalizeStyle, renderSlot, createBlock, resolveDynamicComponent, createCommentVNode, createElementVNode } from 'vue';
  2. import { ArrowLeft, ArrowUp, ArrowRight, ArrowDown } from '@element-plus/icons-vue';
  3. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  4. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  5. const __default__ = defineComponent({
  6. name: "ElSplitterBar"
  7. });
  8. const _sfc_main = /* @__PURE__ */ defineComponent({
  9. ...__default__,
  10. props: {
  11. index: {
  12. type: Number,
  13. required: true
  14. },
  15. layout: {
  16. type: String,
  17. values: ["horizontal", "vertical"],
  18. default: "horizontal"
  19. },
  20. resizable: {
  21. type: Boolean,
  22. default: true
  23. },
  24. lazy: Boolean,
  25. startCollapsible: Boolean,
  26. endCollapsible: Boolean
  27. },
  28. emits: ["moveStart", "moving", "moveEnd", "collapse"],
  29. setup(__props, { emit }) {
  30. const props = __props;
  31. const ns = useNamespace("splitter-bar");
  32. const isHorizontal = computed(() => props.layout === "horizontal");
  33. const barWrapStyles = computed(() => {
  34. if (isHorizontal.value) {
  35. return { width: 0 };
  36. }
  37. return { height: 0 };
  38. });
  39. const draggerStyles = computed(() => {
  40. return {
  41. width: isHorizontal.value ? "16px" : "100%",
  42. height: isHorizontal.value ? "100%" : "16px",
  43. cursor: !props.resizable ? "auto" : isHorizontal.value ? "ew-resize" : "ns-resize",
  44. touchAction: "none"
  45. };
  46. });
  47. const draggerPseudoClass = computed(() => {
  48. const prefix = ns.e("dragger");
  49. return {
  50. [`${prefix}-horizontal`]: isHorizontal.value,
  51. [`${prefix}-vertical`]: !isHorizontal.value,
  52. [`${prefix}-active`]: !!startPos.value
  53. };
  54. });
  55. const startPos = ref(null);
  56. const onMousedown = (e) => {
  57. if (!props.resizable)
  58. return;
  59. startPos.value = [e.pageX, e.pageY];
  60. emit("moveStart", props.index);
  61. window.addEventListener("mouseup", onMouseUp);
  62. window.addEventListener("mousemove", onMouseMove);
  63. };
  64. const onTouchStart = (e) => {
  65. if (props.resizable && e.touches.length === 1) {
  66. e.preventDefault();
  67. const touch = e.touches[0];
  68. startPos.value = [touch.pageX, touch.pageY];
  69. emit("moveStart", props.index);
  70. window.addEventListener("touchend", onTouchEnd);
  71. window.addEventListener("touchmove", onTouchMove);
  72. }
  73. };
  74. const onMouseMove = (e) => {
  75. const { pageX, pageY } = e;
  76. const offsetX = pageX - startPos.value[0];
  77. const offsetY = pageY - startPos.value[1];
  78. const offset = isHorizontal.value ? offsetX : offsetY;
  79. emit("moving", props.index, offset);
  80. };
  81. const onTouchMove = (e) => {
  82. if (e.touches.length === 1) {
  83. e.preventDefault();
  84. const touch = e.touches[0];
  85. const offsetX = touch.pageX - startPos.value[0];
  86. const offsetY = touch.pageY - startPos.value[1];
  87. const offset = isHorizontal.value ? offsetX : offsetY;
  88. emit("moving", props.index, offset);
  89. }
  90. };
  91. const onMouseUp = () => {
  92. startPos.value = null;
  93. window.removeEventListener("mouseup", onMouseUp);
  94. window.removeEventListener("mousemove", onMouseMove);
  95. emit("moveEnd", props.index);
  96. };
  97. const onTouchEnd = () => {
  98. startPos.value = null;
  99. window.removeEventListener("touchend", onTouchEnd);
  100. window.removeEventListener("touchmove", onTouchMove);
  101. emit("moveEnd", props.index);
  102. };
  103. const StartIcon = computed(() => isHorizontal.value ? ArrowLeft : ArrowUp);
  104. const EndIcon = computed(() => isHorizontal.value ? ArrowRight : ArrowDown);
  105. return (_ctx, _cache) => {
  106. return openBlock(), createElementBlock("div", {
  107. class: normalizeClass([unref(ns).b()]),
  108. style: normalizeStyle(unref(barWrapStyles))
  109. }, [
  110. __props.startCollapsible ? (openBlock(), createElementBlock("div", {
  111. key: 0,
  112. class: normalizeClass([unref(ns).e("collapse-icon"), unref(ns).e(`${__props.layout}-collapse-icon-start`)]),
  113. onClick: ($event) => emit("collapse", __props.index, "start")
  114. }, [
  115. renderSlot(_ctx.$slots, "start-collapsible", {}, () => [
  116. (openBlock(), createBlock(resolveDynamicComponent(unref(StartIcon)), { style: { "width": "12px", "height": "12px" } }))
  117. ])
  118. ], 10, ["onClick"])) : createCommentVNode("v-if", true),
  119. createElementVNode("div", {
  120. class: normalizeClass([
  121. unref(ns).e("dragger"),
  122. unref(draggerPseudoClass),
  123. unref(ns).is("disabled", !__props.resizable),
  124. unref(ns).is("lazy", __props.resizable && __props.lazy)
  125. ]),
  126. style: normalizeStyle(unref(draggerStyles)),
  127. onMousedown,
  128. onTouchstart: onTouchStart
  129. }, null, 38),
  130. __props.endCollapsible ? (openBlock(), createElementBlock("div", {
  131. key: 1,
  132. class: normalizeClass([unref(ns).e("collapse-icon"), unref(ns).e(`${__props.layout}-collapse-icon-end`)]),
  133. onClick: ($event) => emit("collapse", __props.index, "end")
  134. }, [
  135. renderSlot(_ctx.$slots, "end-collapsible", {}, () => [
  136. (openBlock(), createBlock(resolveDynamicComponent(unref(EndIcon)), { style: { "width": "12px", "height": "12px" } }))
  137. ])
  138. ], 10, ["onClick"])) : createCommentVNode("v-if", true)
  139. ], 6);
  140. };
  141. }
  142. });
  143. var SplitBar = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "split-bar.vue"]]);
  144. export { SplitBar as default };
  145. //# sourceMappingURL=split-bar.mjs.map