200b9fcbc5b4f6ab77ab6c139c0e40a0ff7b4912c697e90ebd7d67c0a10034c762e14b2838f25d3c8fbc5f37f40a1feb3154b4f712c6a3019efa3bb79bda9a 5.7 KB

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