tour2.mjs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import { defineComponent, ref, computed, toRef, watch, useSlots, provide, openBlock, createElementBlock, Fragment, createVNode, unref, withCtx, createElementVNode, mergeProps, normalizeStyle, createBlock, renderSlot, createCommentVNode } from 'vue';
  2. import { useVModel } from '@vueuse/core';
  3. import { ElTeleport } from '../../teleport/index.mjs';
  4. import ElTourMask from './mask2.mjs';
  5. import ElTourContent from './content2.mjs';
  6. import ElTourSteps from './steps.mjs';
  7. import { tourProps, tourEmits } from './tour.mjs';
  8. import { useTarget, tourKey } from './helper.mjs';
  9. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  10. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  11. import { isBoolean } from '../../../utils/types.mjs';
  12. import { useZIndex } from '../../../hooks/use-z-index/index.mjs';
  13. const __default__ = defineComponent({
  14. name: "ElTour"
  15. });
  16. const _sfc_main = /* @__PURE__ */ defineComponent({
  17. ...__default__,
  18. props: tourProps,
  19. emits: tourEmits,
  20. setup(__props, { emit }) {
  21. const props = __props;
  22. const ns = useNamespace("tour");
  23. const total = ref(0);
  24. const currentStep = ref();
  25. const current = useVModel(props, "current", emit, {
  26. passive: true
  27. });
  28. const currentTarget = computed(() => {
  29. var _a;
  30. return (_a = currentStep.value) == null ? void 0 : _a.target;
  31. });
  32. const kls = computed(() => [
  33. ns.b(),
  34. mergedType.value === "primary" ? ns.m("primary") : ""
  35. ]);
  36. const mergedPlacement = computed(() => {
  37. var _a;
  38. return ((_a = currentStep.value) == null ? void 0 : _a.placement) || props.placement;
  39. });
  40. const mergedContentStyle = computed(() => {
  41. var _a, _b;
  42. return (_b = (_a = currentStep.value) == null ? void 0 : _a.contentStyle) != null ? _b : props.contentStyle;
  43. });
  44. const mergedMask = computed(() => {
  45. var _a, _b;
  46. return (_b = (_a = currentStep.value) == null ? void 0 : _a.mask) != null ? _b : props.mask;
  47. });
  48. const mergedShowMask = computed(() => !!mergedMask.value && props.modelValue);
  49. const mergedMaskStyle = computed(() => isBoolean(mergedMask.value) ? void 0 : mergedMask.value);
  50. const mergedShowArrow = computed(() => {
  51. var _a, _b;
  52. return !!currentTarget.value && ((_b = (_a = currentStep.value) == null ? void 0 : _a.showArrow) != null ? _b : props.showArrow);
  53. });
  54. const mergedScrollIntoViewOptions = computed(() => {
  55. var _a, _b;
  56. return (_b = (_a = currentStep.value) == null ? void 0 : _a.scrollIntoViewOptions) != null ? _b : props.scrollIntoViewOptions;
  57. });
  58. const mergedType = computed(() => {
  59. var _a, _b;
  60. return (_b = (_a = currentStep.value) == null ? void 0 : _a.type) != null ? _b : props.type;
  61. });
  62. const { nextZIndex } = useZIndex();
  63. const nowZIndex = nextZIndex();
  64. const mergedZIndex = computed(() => {
  65. var _a;
  66. return (_a = props.zIndex) != null ? _a : nowZIndex;
  67. });
  68. const { mergedPosInfo: pos, triggerTarget } = useTarget(currentTarget, toRef(props, "modelValue"), toRef(props, "gap"), mergedMask, mergedScrollIntoViewOptions);
  69. watch(() => props.modelValue, (val) => {
  70. if (!val) {
  71. current.value = 0;
  72. }
  73. });
  74. const onEscClose = () => {
  75. if (props.closeOnPressEscape) {
  76. emit("update:modelValue", false);
  77. emit("close", current.value);
  78. }
  79. };
  80. const onUpdateTotal = (val) => {
  81. total.value = val;
  82. };
  83. const slots = useSlots();
  84. provide(tourKey, {
  85. currentStep,
  86. current,
  87. total,
  88. showClose: toRef(props, "showClose"),
  89. closeIcon: toRef(props, "closeIcon"),
  90. mergedType,
  91. ns,
  92. slots,
  93. updateModelValue(modelValue) {
  94. emit("update:modelValue", modelValue);
  95. },
  96. onClose() {
  97. emit("close", current.value);
  98. },
  99. onFinish() {
  100. emit("finish");
  101. },
  102. onChange() {
  103. emit("change", current.value);
  104. }
  105. });
  106. return (_ctx, _cache) => {
  107. return openBlock(), createElementBlock(Fragment, null, [
  108. createVNode(unref(ElTeleport), { to: _ctx.appendTo }, {
  109. default: withCtx(() => {
  110. var _a, _b;
  111. return [
  112. createElementVNode("div", mergeProps({ class: unref(kls) }, _ctx.$attrs), [
  113. createVNode(ElTourMask, {
  114. visible: unref(mergedShowMask),
  115. fill: (_a = unref(mergedMaskStyle)) == null ? void 0 : _a.color,
  116. style: normalizeStyle((_b = unref(mergedMaskStyle)) == null ? void 0 : _b.style),
  117. pos: unref(pos),
  118. "z-index": unref(mergedZIndex),
  119. "target-area-clickable": _ctx.targetAreaClickable
  120. }, null, 8, ["visible", "fill", "style", "pos", "z-index", "target-area-clickable"]),
  121. _ctx.modelValue ? (openBlock(), createBlock(ElTourContent, {
  122. key: unref(current),
  123. reference: unref(triggerTarget),
  124. placement: unref(mergedPlacement),
  125. "show-arrow": unref(mergedShowArrow),
  126. "z-index": unref(mergedZIndex),
  127. style: normalizeStyle(unref(mergedContentStyle)),
  128. onClose: onEscClose
  129. }, {
  130. default: withCtx(() => [
  131. createVNode(unref(ElTourSteps), {
  132. current: unref(current),
  133. onUpdateTotal
  134. }, {
  135. default: withCtx(() => [
  136. renderSlot(_ctx.$slots, "default")
  137. ]),
  138. _: 3
  139. }, 8, ["current"])
  140. ]),
  141. _: 3
  142. }, 8, ["reference", "placement", "show-arrow", "z-index", "style"])) : createCommentVNode("v-if", true)
  143. ], 16)
  144. ];
  145. }),
  146. _: 3
  147. }, 8, ["to"]),
  148. createCommentVNode(" just for IDE "),
  149. createCommentVNode("v-if", true)
  150. ], 64);
  151. };
  152. }
  153. });
  154. var Tour = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "tour.vue"]]);
  155. export { Tour as default };
  156. //# sourceMappingURL=tour2.mjs.map