tour2.mjs 6.1 KB

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