c8d22e250f0c29aeebb5ab3f6e72b499526f68a2f23ee7a78a531b844f5c74fde969f3040286cb7d4e76d6cc64a2b92677da149ab7f579cf5b9d3703aaafda 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import { defineComponent, useSlots, computed, ref, provide, openBlock, createBlock, unref, withCtx, createVNode, Transition, mergeProps, withDirectives, createElementVNode, normalizeClass, normalizeStyle, createSlots, renderSlot, createCommentVNode, vShow } from 'vue';
  2. import { ElOverlay } from '../../overlay/index.mjs';
  3. import ElFocusTrap from '../../focus-trap/src/focus-trap.mjs';
  4. import { ElTeleport } from '../../teleport/index.mjs';
  5. import ElDialogContent from './dialog-content2.mjs';
  6. import { dialogInjectionKey } from './constants.mjs';
  7. import { dialogProps, dialogEmits } from './dialog.mjs';
  8. import { useDialog } from './use-dialog.mjs';
  9. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  10. import { useDeprecated } from '../../../hooks/use-deprecated/index.mjs';
  11. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  12. import { useSameTarget } from '../../../hooks/use-same-target/index.mjs';
  13. const __default__ = defineComponent({
  14. name: "ElDialog",
  15. inheritAttrs: false
  16. });
  17. const _sfc_main = /* @__PURE__ */ defineComponent({
  18. ...__default__,
  19. props: dialogProps,
  20. emits: dialogEmits,
  21. setup(__props, { expose }) {
  22. const props = __props;
  23. const slots = useSlots();
  24. useDeprecated({
  25. scope: "el-dialog",
  26. from: "the title slot",
  27. replacement: "the header slot",
  28. version: "3.0.0",
  29. ref: "https://element-plus.org/en-US/component/dialog.html#slots"
  30. }, computed(() => !!slots.title));
  31. const ns = useNamespace("dialog");
  32. const dialogRef = ref();
  33. const headerRef = ref();
  34. const dialogContentRef = ref();
  35. const {
  36. visible,
  37. titleId,
  38. bodyId,
  39. style,
  40. overlayDialogStyle,
  41. rendered,
  42. transitionConfig,
  43. zIndex,
  44. _draggable,
  45. _alignCenter,
  46. _overflow,
  47. handleClose,
  48. onModalClick,
  49. onOpenAutoFocus,
  50. onCloseAutoFocus,
  51. onCloseRequested,
  52. onFocusoutPrevented
  53. } = useDialog(props, dialogRef);
  54. provide(dialogInjectionKey, {
  55. dialogRef,
  56. headerRef,
  57. bodyId,
  58. ns,
  59. rendered,
  60. style
  61. });
  62. const overlayEvent = useSameTarget(onModalClick);
  63. const penetrable = computed(() => props.modalPenetrable && !props.modal && !props.fullscreen);
  64. const resetPosition = () => {
  65. var _a;
  66. (_a = dialogContentRef.value) == null ? void 0 : _a.resetPosition();
  67. };
  68. expose({
  69. visible,
  70. dialogContentRef,
  71. resetPosition,
  72. handleClose
  73. });
  74. return (_ctx, _cache) => {
  75. return openBlock(), createBlock(unref(ElTeleport), {
  76. to: _ctx.appendTo,
  77. disabled: _ctx.appendTo !== "body" ? false : !_ctx.appendToBody
  78. }, {
  79. default: withCtx(() => [
  80. createVNode(Transition, mergeProps(unref(transitionConfig), { persisted: "" }), {
  81. default: withCtx(() => {
  82. var _a;
  83. return [
  84. withDirectives(createVNode(unref(ElOverlay), {
  85. "custom-mask-event": "",
  86. mask: _ctx.modal,
  87. "overlay-class": [
  88. (_a = _ctx.modalClass) != null ? _a : "",
  89. `${unref(ns).namespace.value}-modal-dialog`,
  90. unref(ns).is("penetrable", unref(penetrable))
  91. ],
  92. "z-index": unref(zIndex)
  93. }, {
  94. default: withCtx(() => [
  95. createElementVNode("div", {
  96. role: "dialog",
  97. "aria-modal": "true",
  98. "aria-label": _ctx.title || void 0,
  99. "aria-labelledby": !_ctx.title ? unref(titleId) : void 0,
  100. "aria-describedby": unref(bodyId),
  101. class: normalizeClass(`${unref(ns).namespace.value}-overlay-dialog`),
  102. style: normalizeStyle(unref(overlayDialogStyle)),
  103. onClick: unref(overlayEvent).onClick,
  104. onMousedown: unref(overlayEvent).onMousedown,
  105. onMouseup: unref(overlayEvent).onMouseup
  106. }, [
  107. createVNode(unref(ElFocusTrap), {
  108. loop: "",
  109. trapped: unref(visible),
  110. "focus-start-el": "container",
  111. onFocusAfterTrapped: unref(onOpenAutoFocus),
  112. onFocusAfterReleased: unref(onCloseAutoFocus),
  113. onFocusoutPrevented: unref(onFocusoutPrevented),
  114. onReleaseRequested: unref(onCloseRequested)
  115. }, {
  116. default: withCtx(() => [
  117. unref(rendered) ? (openBlock(), createBlock(ElDialogContent, mergeProps({
  118. key: 0,
  119. ref_key: "dialogContentRef",
  120. ref: dialogContentRef
  121. }, _ctx.$attrs, {
  122. center: _ctx.center,
  123. "align-center": unref(_alignCenter),
  124. "close-icon": _ctx.closeIcon,
  125. draggable: unref(_draggable),
  126. overflow: unref(_overflow),
  127. fullscreen: _ctx.fullscreen,
  128. "header-class": _ctx.headerClass,
  129. "body-class": _ctx.bodyClass,
  130. "footer-class": _ctx.footerClass,
  131. "show-close": _ctx.showClose,
  132. title: _ctx.title,
  133. "aria-level": _ctx.headerAriaLevel,
  134. onClose: unref(handleClose)
  135. }), createSlots({
  136. header: withCtx(() => [
  137. !_ctx.$slots.title ? renderSlot(_ctx.$slots, "header", {
  138. key: 0,
  139. close: unref(handleClose),
  140. titleId: unref(titleId),
  141. titleClass: unref(ns).e("title")
  142. }) : renderSlot(_ctx.$slots, "title", { key: 1 })
  143. ]),
  144. default: withCtx(() => [
  145. renderSlot(_ctx.$slots, "default")
  146. ]),
  147. _: 2
  148. }, [
  149. _ctx.$slots.footer ? {
  150. name: "footer",
  151. fn: withCtx(() => [
  152. renderSlot(_ctx.$slots, "footer")
  153. ])
  154. } : void 0
  155. ]), 1040, ["center", "align-center", "close-icon", "draggable", "overflow", "fullscreen", "header-class", "body-class", "footer-class", "show-close", "title", "aria-level", "onClose"])) : createCommentVNode("v-if", true)
  156. ]),
  157. _: 3
  158. }, 8, ["trapped", "onFocusAfterTrapped", "onFocusAfterReleased", "onFocusoutPrevented", "onReleaseRequested"])
  159. ], 46, ["aria-label", "aria-labelledby", "aria-describedby", "onClick", "onMousedown", "onMouseup"])
  160. ]),
  161. _: 3
  162. }, 8, ["mask", "overlay-class", "z-index"]), [
  163. [vShow, unref(visible)]
  164. ])
  165. ];
  166. }),
  167. _: 3
  168. }, 16)
  169. ]),
  170. _: 3
  171. }, 8, ["to", "disabled"]);
  172. };
  173. }
  174. });
  175. var Dialog = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "dialog.vue"]]);
  176. export { Dialog as default };
  177. //# sourceMappingURL=dialog2.mjs.map