@wfrog/vc
Version:
vue3 组件库 vc
413 lines (403 loc) • 16.2 kB
JavaScript
import './index.css'
import { c as buildProps, m as clamp, u as useNamespace } from '../../chunk/E_WRn0OP.mjs';
import { d as dialogEmits, a as dialogProps, u as useDialog, E as ElOverlay } from '../../chunk/B7POrE6v.mjs';
import { E as ElScrollbar } from '../../chunk/CJQcPuNK.mjs';
import { computed, ref, watch, onBeforeUnmount, defineComponent, useSlots, createBlock, openBlock, unref, withCtx, createVNode, Transition, withDirectives, createElementVNode, mergeProps, withModifiers, createElementBlock, createCommentVNode, normalizeClass, renderSlot, toDisplayString, normalizeStyle, vShow, useCssVars, isRef, createTextVNode } from 'vue';
import { C as Component$1 } from '../button/button.mjs';
import { u as useVModel } from '../../chunk/eQT9aAiW.mjs';
import { Close } from '@element-plus/icons-vue';
import { b as ElTeleport, d as ElFocusTrap } from '../../chunk/DUd8IaU9.mjs';
import { E as ElIcon } from '../../chunk/m2vp1CCf.mjs';
import { b as useWindowSize, c as useEventListener } from '../../chunk/CEClY-_T.mjs';
import { a as addUnit } from '../../chunk/CD1S5tP1.mjs';
import { _ as _export_sfc, w as withInstall } from '../../chunk/D389hx_T.mjs';
import { u as useDeprecated } from '../../chunk/VAdRxe-1.mjs';
import { u as useLocale } from '../../chunk/-m34CPRn.mjs';
import { _ as _export_sfc$1 } from '../../chunk/pcqpp-6-.mjs';
const drawerProps = buildProps({
...dialogProps,
direction: {
type: String,
default: "rtl",
values: ["ltr", "rtl", "ttb", "btt"]
},
resizable: Boolean,
size: {
type: [String, Number],
default: "30%"
},
withHeader: {
type: Boolean,
default: true
},
modalFade: {
type: Boolean,
default: true
},
headerAriaLevel: {
type: String,
default: "2"
}
});
const drawerEmits = {
...dialogEmits,
"resize-start": (evt, size) => evt instanceof MouseEvent && typeof size === "number",
resize: (evt, size) => evt instanceof MouseEvent && typeof size === "number",
"resize-end": (evt, size) => evt instanceof MouseEvent && typeof size === "number"
};
function useResizable(props, target, emit) {
const { width, height } = useWindowSize();
const isHorizontal = computed(() => ["ltr", "rtl"].includes(props.direction));
const sign = computed(() => ["ltr", "ttb"].includes(props.direction) ? 1 : -1);
const windowSize = computed(() => isHorizontal.value ? width.value : height.value);
const getSize = computed(() => {
return clamp(startSize.value + sign.value * offset.value, 4, windowSize.value);
});
const startSize = ref(0);
const offset = ref(0);
const isResizing = ref(false);
const hasStartedDragging = ref(false);
let startPos = [];
let cleanups = [];
const getActualSize = () => {
var _a;
const drawerEl = (_a = target.value) == null ? void 0 : _a.closest('[aria-modal="true"]');
if (drawerEl) {
return isHorizontal.value ? drawerEl.offsetWidth : drawerEl.offsetHeight;
}
return 100;
};
watch(() => [props.size, props.resizable], () => {
hasStartedDragging.value = false;
startSize.value = 0;
offset.value = 0;
onMouseUp();
});
const onMousedown = (e) => {
if (!props.resizable)
return;
if (!hasStartedDragging.value) {
startSize.value = getActualSize();
hasStartedDragging.value = true;
}
startPos = [e.pageX, e.pageY];
isResizing.value = true;
emit("resize-start", e, startSize.value);
cleanups.push(useEventListener(window, "mouseup", onMouseUp), useEventListener(window, "mousemove", onMouseMove));
};
const onMouseMove = (e) => {
const { pageX, pageY } = e;
const offsetX = pageX - startPos[0];
const offsetY = pageY - startPos[1];
offset.value = isHorizontal.value ? offsetX : offsetY;
emit("resize", e, getSize.value);
};
const onMouseUp = (e) => {
if (!isResizing.value)
return;
startPos = [];
startSize.value = getSize.value;
offset.value = 0;
isResizing.value = false;
cleanups.forEach((cleanup2) => cleanup2 == null ? void 0 : cleanup2());
cleanups = [];
if (e) {
emit("resize-end", e, startSize.value);
}
};
const cleanup = useEventListener(target, "mousedown", onMousedown);
onBeforeUnmount(() => {
cleanup();
onMouseUp();
});
return {
size: computed(() => {
return hasStartedDragging.value ? `${getSize.value}px` : addUnit(props.size);
}),
isResizing,
isHorizontal
};
}
const __default__ = defineComponent({
name: "ElDrawer",
inheritAttrs: false
});
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
...__default__,
props: drawerProps,
emits: drawerEmits,
setup(__props, { expose, emit }) {
const props = __props;
const slots = useSlots();
useDeprecated({
scope: "el-drawer",
from: "the title slot",
replacement: "the header slot",
version: "3.0.0",
ref: "https://element-plus.org/en-US/component/drawer.html#slots"
}, computed(() => !!slots.title));
const drawerRef = ref();
const focusStartRef = ref();
const draggerRef = ref();
const ns = useNamespace("drawer");
const { t } = useLocale();
const {
afterEnter,
afterLeave,
beforeLeave,
visible,
rendered,
titleId,
bodyId,
zIndex,
onModalClick,
onOpenAutoFocus,
onCloseAutoFocus,
onFocusoutPrevented,
onCloseRequested,
handleClose
} = useDialog(props, drawerRef);
const { isHorizontal, size, isResizing } = useResizable(props, draggerRef, emit);
const penetrable = computed(() => props.modalPenetrable && !props.modal);
expose({
handleClose,
afterEnter,
afterLeave
});
return (_ctx, _cache) => {
return openBlock(), createBlock(unref(ElTeleport), {
to: _ctx.appendTo,
disabled: _ctx.appendTo !== "body" ? false : !_ctx.appendToBody
}, {
default: withCtx(() => [
createVNode(Transition, {
name: unref(ns).b("fade"),
onAfterEnter: unref(afterEnter),
onAfterLeave: unref(afterLeave),
onBeforeLeave: unref(beforeLeave),
persisted: ""
}, {
default: withCtx(() => {
var _a;
return [
withDirectives(createVNode(unref(ElOverlay), {
mask: _ctx.modal,
"overlay-class": [
unref(ns).is("drawer"),
(_a = _ctx.modalClass) != null ? _a : "",
`${unref(ns).namespace.value}-modal-drawer`,
unref(ns).is("penetrable", unref(penetrable))
],
"z-index": unref(zIndex),
onClick: unref(onModalClick)
}, {
default: withCtx(() => [
createVNode(unref(ElFocusTrap), {
loop: "",
trapped: unref(visible),
"focus-trap-el": drawerRef.value,
"focus-start-el": focusStartRef.value,
onFocusAfterTrapped: unref(onOpenAutoFocus),
onFocusAfterReleased: unref(onCloseAutoFocus),
onFocusoutPrevented: unref(onFocusoutPrevented),
onReleaseRequested: unref(onCloseRequested)
}, {
default: withCtx(() => [
createElementVNode("div", mergeProps({
ref_key: "drawerRef",
ref: drawerRef,
"aria-modal": "true",
"aria-label": _ctx.title || void 0,
"aria-labelledby": !_ctx.title ? unref(titleId) : void 0,
"aria-describedby": unref(bodyId)
}, _ctx.$attrs, {
class: [
unref(ns).b(),
_ctx.direction,
unref(visible) && "open",
unref(ns).is("dragging", unref(isResizing))
],
style: { [unref(isHorizontal) ? "width" : "height"]: unref(size) },
role: "dialog",
onClick: withModifiers(() => {
}, ["stop"])
}), [
createElementVNode("span", {
ref_key: "focusStartRef",
ref: focusStartRef,
class: normalizeClass(unref(ns).e("sr-focus")),
tabindex: "-1"
}, null, 2),
_ctx.withHeader ? (openBlock(), createElementBlock("header", {
key: 0,
class: normalizeClass([unref(ns).e("header"), _ctx.headerClass])
}, [
!_ctx.$slots.title ? renderSlot(_ctx.$slots, "header", {
key: 0,
close: unref(handleClose),
titleId: unref(titleId),
titleClass: unref(ns).e("title")
}, () => [
createElementVNode("span", {
id: unref(titleId),
role: "heading",
"aria-level": _ctx.headerAriaLevel,
class: normalizeClass(unref(ns).e("title"))
}, toDisplayString(_ctx.title), 11, ["id", "aria-level"])
]) : renderSlot(_ctx.$slots, "title", { key: 1 }, () => [
createCommentVNode(" DEPRECATED SLOT ")
]),
_ctx.showClose ? (openBlock(), createElementBlock("button", {
key: 2,
"aria-label": unref(t)("el.drawer.close"),
class: normalizeClass(unref(ns).e("close-btn")),
type: "button",
onClick: unref(handleClose)
}, [
createVNode(unref(ElIcon), {
class: normalizeClass(unref(ns).e("close"))
}, {
default: withCtx(() => [
createVNode(unref(Close))
]),
_: 1
}, 8, ["class"])
], 10, ["aria-label", "onClick"])) : createCommentVNode("v-if", true)
], 2)) : createCommentVNode("v-if", true),
unref(rendered) ? (openBlock(), createElementBlock("div", {
key: 1,
id: unref(bodyId),
class: normalizeClass([unref(ns).e("body"), _ctx.bodyClass])
}, [
renderSlot(_ctx.$slots, "default")
], 10, ["id"])) : createCommentVNode("v-if", true),
_ctx.$slots.footer ? (openBlock(), createElementBlock("div", {
key: 2,
class: normalizeClass([unref(ns).e("footer"), _ctx.footerClass])
}, [
renderSlot(_ctx.$slots, "footer")
], 2)) : createCommentVNode("v-if", true),
_ctx.resizable ? (openBlock(), createElementBlock("div", {
key: 3,
ref_key: "draggerRef",
ref: draggerRef,
style: normalizeStyle({ zIndex: unref(zIndex) }),
class: normalizeClass(unref(ns).e("dragger"))
}, null, 6)) : createCommentVNode("v-if", true)
], 16, ["aria-label", "aria-labelledby", "aria-describedby", "onClick"])
]),
_: 3
}, 8, ["trapped", "focus-trap-el", "focus-start-el", "onFocusAfterTrapped", "onFocusAfterReleased", "onFocusoutPrevented", "onReleaseRequested"])
]),
_: 3
}, 8, ["mask", "overlay-class", "z-index", "onClick"]), [
[vShow, unref(visible)]
])
];
}),
_: 3
}, 8, ["name", "onAfterEnter", "onAfterLeave", "onBeforeLeave"])
]),
_: 3
}, 8, ["to", "disabled"]);
};
}
});
var Drawer = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__file", "drawer.vue"]]);
const ElDrawer = withInstall(Drawer);
const _hoisted_1 = {
key: 0,
class: "drawer-footer"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "drawer",
props: {
modelValue: { type: Boolean },
title: { default: "对话框" },
lazy: { type: Boolean, default: true },
showDefaultFooter: { type: Boolean, default: false },
boxPadding: { type: Boolean, default: true }
},
emits: ["update:modelValue", "closed"],
setup(__props, { emit: __emit }) {
useCssVars((_ctx) => ({
"v3e817546": _ctx.boxPadding ? "block" : "none"
}));
const props = __props;
const emits = __emit;
const drawerVisible = useVModel(props, "modelValue", emits);
const visible = ref(false);
watch(drawerVisible, (val) => {
if (val) {
visible.value = true;
}
});
function handleClosed() {
visible.value = false;
emits("closed");
}
return (_ctx, _cache) => {
const _component_ElScrollbar = ElScrollbar;
const _component_ElDrawer = ElDrawer;
return unref(visible) || !__props.lazy ? (openBlock(), createBlock(_component_ElDrawer, mergeProps({
key: 0,
modelValue: unref(drawerVisible),
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => isRef(drawerVisible) ? drawerVisible.value = $event : null)
}, _ctx.$attrs, {
"close-on-click-modal": false,
class: _ctx.$style.main,
onClosed: handleClosed
}), {
header: withCtx(() => [
createElementVNode("div", null, [
renderSlot(_ctx.$slots, "header", {}, () => [
createTextVNode(toDisplayString(__props.title), 1)
])
])
]),
default: withCtx(() => [
createVNode(_component_ElScrollbar, {
class: "drawer-scrollbar",
always: ""
}, {
default: withCtx(() => [
createElementVNode("div", {
class: normalizeClass(_ctx.$style["body-container"])
}, [
renderSlot(_ctx.$slots, "default")
], 2)
]),
_: 3
}),
__props.showDefaultFooter || _ctx.$slots.footer ? (openBlock(), createElementBlock("div", _hoisted_1, [
renderSlot(_ctx.$slots, "footer", {}, () => [
createVNode(Component$1, {
onClick: _cache[0] || (_cache[0] = ($event) => drawerVisible.value = false)
}, {
default: withCtx(() => [..._cache[2] || (_cache[2] = [
createTextVNode("关闭", -1)
])]),
_: 1
})
])
])) : createCommentVNode("", true)
]),
_: 3
}, 16, ["modelValue", "class"])) : createCommentVNode("", true);
};
}
});
/* unplugin-vue-components disabled */const main = "_main_q1oh1_1";
const style0 = {
main: main,
"body-container": "_body-container_q1oh1_54"
};
const cssModules = {
"$style": style0
};
const Component = /* @__PURE__ */ _export_sfc$1(_sfc_main, [["__cssModules", cssModules]]);
const __vite_glob_0_14 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
__proto__: null,
default: Component
}, Symbol.toStringTag, { value: 'Module' }));
export { Component as C, __vite_glob_0_14 as _ };