{"version":3,"file":"hovercard.cjs","sources":["../../../components/hovercard/hovercard.vue"],"sourcesContent":["<!-- eslint-disable vue/multi-word-component-names -->\n<template>\n  <dt-popover\n    :id=\"id\"\n    ref=\"popover\"\n    :open=\"hovercardOpen\"\n    :placement=\"placement\"\n    :content-class=\"contentClass\"\n    :dialog-class=\"dialogClass\"\n    :fallback-placements=\"fallbackPlacements\"\n    :padding=\"padding\"\n    :transition=\"transition ? 'fade' : null\"\n    :offset=\"offset\"\n    :modal=\"false\"\n    initial-focus-element=\"none\"\n    :header-class=\"headerClass\"\n    :footer-class=\"footerClass\"\n    :append-to=\"appendTo\"\n    data-qa=\"dt-hovercard\"\n    :enter-delay=\"enterDelay\"\n    :leave-delay=\"leaveDelay\"\n    @opened=\"(e) => ($emit('opened', e))\"\n    @mouseenter-popover=\"onMouseEnter\"\n    @mouseleave-popover=\"onMouseLeave\"\n    @mouseenter-popover-anchor=\"onMouseEnter\"\n    @mouseleave-popover-anchor=\"onMouseLeave\"\n  >\n    <template #anchor=\"{ attrs }\">\n      <!-- @slot Anchor element that activates the hovercard. Usually a button. -->\n      <slot\n        name=\"anchor\"\n        v-bind=\"attrs\"\n      />\n    </template>\n    <template #content>\n      <!-- @slot Slot for the content that is displayed in the hovercard. -->\n      <slot name=\"content\" />\n    </template>\n    <template #headerContent>\n      <!-- @slot Slot for hovercard header content -->\n      <slot name=\"headerContent\" />\n    </template>\n\n    <template #footerContent>\n      <!-- @slot Slot for the footer content. -->\n      <slot name=\"footerContent\" />\n    </template>\n  </dt-popover>\n</template>\n\n<script setup>\nimport { ref, watch, nextTick, onMounted, onBeforeUnmount } from 'vue';\nimport { POPOVER_APPEND_TO_VALUES, POPOVER_PADDING_CLASSES, DtPopover } from '@/components/popover/index.js';\nimport { TOOLTIP_DIRECTIONS, TOOLTIP_DELAY_MS } from '@/components/tooltip/index.js';\nimport { getUniqueString } from '@/common/utils';\n\nconst props = defineProps({\n  /**\n     * Fade transition when the content display is toggled.\n     * @type boolean\n     * @values true, false\n     */\n  transition: {\n    type: Boolean,\n    default: false,\n  },\n\n  /**\n     * Controls whether the hovercard is shown. Leaving this null will have the hovercard trigger on hover by default.\n     * If you set this value, the default trigger behavior will be disabled, and you can control it as you need.\n     * Supports .sync modifier\n     * @values null, true, false\n     */\n  open: {\n    type: Boolean,\n    default: null,\n  },\n\n  /**\n      * If the popover does not fit in the direction described by \"placement\",\n     * it will attempt to change its direction to the \"fallbackPlacements\".\n     * @see https://popper.js.org/docs/v2/modifiers/flip/#fallbackplacements\"\n     */\n  fallbackPlacements: {\n    type: Array,\n    default: () => {\n      return ['auto'];\n    },\n  },\n\n  /**\n     * The direction the popover displays relative to the anchor.\n     * @see https://atomiks.github.io/tippyjs/v6/all-props/#placement\"\n     * @values top, top-start, top-end,\n     * right, right-start, right-end,\n     * left, left-start, left-end,\n     * bottom, bottom-start, bottom-end,\n     * auto, auto-start, auto-end\n     */\n  placement: {\n    type: String,\n    default: 'top-start',\n    validator (placement) {\n      return TOOLTIP_DIRECTIONS.includes(placement);\n    },\n  },\n\n  /**\n     * Padding size class for the popover content.\n     * @values none, small, medium, large\n     */\n  padding: {\n    type: String,\n    default: 'large',\n    validator: (padding) => {\n      return Object.keys(POPOVER_PADDING_CLASSES).some((item) => item === padding);\n    },\n  },\n\n  /**\n     * Displaces the content box from its anchor element\n     * by the specified number of pixels.\n     * @see https://atomiks.github.io/tippyjs/v6/all-props/#offset\"\n     */\n  offset: {\n    type: Array,\n    default: () => [0, 16],\n  },\n\n  /**\n     * The id of the tooltip\n     */\n  id: {\n    type: String,\n    default () { return getUniqueString(); },\n  },\n\n  /**\n     * Additional class name for the header content wrapper element.\n     */\n  headerClass: {\n    type: [String, Array, Object],\n    default: '',\n  },\n\n  /**\n     * Additional class name for the footer content wrapper element.\n     */\n  footerClass: {\n    type: [String, Array, Object],\n    default: '',\n  },\n\n  /**\n     * Additional class name for the dialog element.\n     */\n  dialogClass: {\n    type: [String, Array, Object],\n    default: '',\n  },\n\n  /**\n     * Additional class name for the content wrapper element.\n     */\n  contentClass: {\n    type: [String, Array, Object],\n    default: '',\n  },\n\n  /**\n     * Sets the element to which the popover is going to append to.\n     * 'body' will append to the nearest body (supports shadow DOM).\n     * @values 'body', 'parent', HTMLElement,\n     */\n  appendTo: {\n    type: [HTMLElement, String],\n    default: 'body',\n    validator: appendTo => {\n      return POPOVER_APPEND_TO_VALUES.includes(appendTo) ||\n            (appendTo instanceof HTMLElement);\n    },\n  },\n\n  /**\n   * The enter delay in milliseconds before the hovercard is shown.\n   * @type number\n   */\n  enterDelay: {\n    type: Number,\n    default: TOOLTIP_DELAY_MS,\n  },\n\n  /**\n   * The leave delay in milliseconds before the hovercard is hidden.\n   * @type number\n   */\n  leaveDelay: {\n    type: Number,\n    default: TOOLTIP_DELAY_MS,\n  },\n});\n\ndefineEmits([\n  /**\n   * Emitted when hovercard is shown or hidden\n   *\n   * @event opened\n   * @type {Boolean | Array}\n   */\n  'opened',\n]);\n\nconst hovercardOpen = ref(props.open);\nconst inTimer = ref(null);\nconst outTimer = ref(null);\nconst anchorEl = ref(null);\nconst observer = ref(null);\nconst popover = ref(null);\n\nonMounted(() => {\n  nextTick(() => {\n    anchorEl.value = popover.value?.$refs?.anchor?.firstElementChild;\n\n    observer.value = new MutationObserver(() => {\n      if (anchorEl.value && !anchorEl.value.isConnected) {\n        hovercardOpen.value = false;\n      }\n    });\n\n    observer.value.observe(document.body, {\n      childList: true,\n      subtree: true,\n    });\n  });\n});\n\nonBeforeUnmount(() => {\n  if (observer.value) {\n    observer.value.disconnect();\n  }\n  clearTimeout(inTimer);\n  clearTimeout(outTimer);\n});\nwatch(() => props.open, (open) => {\n  hovercardOpen.value = open;\n}, { immediate: true });\n\nfunction setInTimer () {\n  inTimer.value = setTimeout(() => {\n    hovercardOpen.value = true;\n  }, props.enterDelay);\n}\n\nfunction setOutTimer () {\n  outTimer.value = setTimeout(() => {\n    hovercardOpen.value = false;\n  }, props.leaveDelay);\n}\n\nfunction onMouseEnter () {\n  if (props.open === null) {\n    clearTimeout(outTimer.value);\n    setInTimer();\n  }\n}\n\nfunction onMouseLeave () {\n  if (props.open === null) {\n    clearTimeout(inTimer.value);\n    setOutTimer();\n  }\n}\n</script>\n"],"names":["props","__props","hovercardOpen","ref","inTimer","outTimer","anchorEl","observer","popover","onMounted","nextTick","_c","_b","_a","onBeforeUnmount","watch","open","setInTimer","setOutTimer","onMouseEnter","onMouseLeave"],"mappings":"osCAwDA,MAAMA,EAAQC,EA4JRC,EAAgBC,EAAAA,IAAIH,EAAM,IAAI,EAC9BI,EAAUD,EAAAA,IAAI,IAAI,EAClBE,EAAWF,EAAAA,IAAI,IAAI,EACnBG,EAAWH,EAAAA,IAAI,IAAI,EACnBI,EAAWJ,EAAAA,IAAI,IAAI,EACnBK,EAAUL,EAAAA,IAAI,IAAI,EAExBM,EAAAA,UAAU,IAAM,CACdC,EAAAA,SAAS,IAAM,WACbJ,EAAS,OAAQK,GAAAC,GAAAC,EAAAL,EAAQ,QAAR,YAAAK,EAAe,QAAf,YAAAD,EAAsB,SAAtB,YAAAD,EAA8B,kBAE/CJ,EAAS,MAAQ,IAAI,iBAAiB,IAAM,CACtCD,EAAS,OAAS,CAACA,EAAS,MAAM,cACpCJ,EAAc,MAAQ,GAE1B,CAAC,EAEDK,EAAS,MAAM,QAAQ,SAAS,KAAM,CACpC,UAAW,GACX,QAAS,EACf,CAAK,CACH,CAAC,CACH,CAAC,EAEDO,EAAAA,gBAAgB,IAAM,CAChBP,EAAS,OACXA,EAAS,MAAM,WAAU,EAE3B,aAAaH,CAAO,EACpB,aAAaC,CAAQ,CACvB,CAAC,EACDU,EAAAA,MAAM,IAAMf,EAAM,KAAOgB,GAAS,CAChCd,EAAc,MAAQc,CACxB,EAAG,CAAE,UAAW,GAAM,EAEtB,SAASC,GAAc,CACrBb,EAAQ,MAAQ,WAAW,IAAM,CAC/BF,EAAc,MAAQ,EACxB,EAAGF,EAAM,UAAU,CACrB,CAEA,SAASkB,GAAe,CACtBb,EAAS,MAAQ,WAAW,IAAM,CAChCH,EAAc,MAAQ,EACxB,EAAGF,EAAM,UAAU,CACrB,CAEA,SAASmB,GAAgB,CACnBnB,EAAM,OAAS,OACjB,aAAaK,EAAS,KAAK,EAC3BY,EAAU,EAEd,CAEA,SAASG,GAAgB,CACnBpB,EAAM,OAAS,OACjB,aAAaI,EAAQ,KAAK,EAC1Bc,EAAW,EAEf"}