{"version":3,"file":"tooltip.cjs","names":["DtTooltip","getUniqueString","TOOLTIP_DIRECTIONS"],"sources":["../../../directives/tooltip_directive/tooltip.js"],"sourcesContent":["import { DtTooltip, TOOLTIP_DIRECTIONS } from '@/components/tooltip';\nimport { getUniqueString } from '@/common/utils';\nimport { createApp, h } from 'vue';\nimport deepEqual from 'deep-equal';\n\nexport const DtTooltipDirective = {\n  name: 'dt-tooltip-directive',\n  install (app) {\n    const DEFAULT_PLACEMENT = 'top';\n    if (!globalThis.__DtTooltipDirectiveApp) {\n      const DtTooltipDirectiveApp = createApp({\n        name: 'DtTooltipDirectiveApp',\n        components: { DtTooltip },\n        data () {\n          return {\n            tooltips: [],\n          };\n        },\n\n        mounted () {\n          globalThis.__DtTooltipDirectiveApp = this;\n        },\n\n        methods: {\n          addOrUpdateTooltip (id, tooltipConfig) {\n            const index = this.tooltips.findIndex(tooltip => tooltip.id === id);\n            if (index !== -1) {\n              // Update existing tooltip\n              this.tooltips.splice(index, 1, { id, ...tooltipConfig });\n            } else {\n              // Add new tooltip\n              this.tooltips.push({ id, ...tooltipConfig });\n            }\n          },\n\n          removeTooltip (id) {\n            this.tooltips = this.tooltips.filter(tooltip => tooltip.id !== id);\n          },\n        },\n\n        render () {\n          return h('div',\n            this.tooltips.map(({ id, anchorElement, ...tooltipProps }) => {\n              return h(DtTooltip, {\n                key: id,\n                ...tooltipProps,\n                sticky: tooltipProps.sticky !== undefined ? tooltipProps.sticky : true,\n                /**\n                 * Set the delay to false when running tests only.\n                 */\n                delay: tooltipProps.delay !== undefined ? tooltipProps.delay : (process.env.NODE_ENV !== 'test'),\n                externalAnchorElement: anchorElement,\n              });\n            }),\n          );\n        },\n      });\n\n      const mountPoint = document.createElement('div');\n      document.body.appendChild(mountPoint);\n      DtTooltipDirectiveApp.mount(mountPoint);\n    }\n\n    const tooltipApp = globalThis.__DtTooltipDirectiveApp;\n\n    app.directive('dt-tooltip', {\n      beforeMount (anchor, binding) {\n        // Initial tooltip setup\n        setupTooltip(anchor, binding);\n      },\n      updated (anchor, binding) {\n        // Update tooltip on binding value change\n        // Use deep equality check to prevent infinite loops when objects are passed\n        if (!deepEqual(binding.value, binding.oldValue)) {\n          setupTooltip(anchor, binding);\n        }\n      },\n      unmounted (anchor) {\n        tooltipApp.removeTooltip(anchor.getAttribute('data-dt-tooltip-id'));\n      },\n    });\n\n    function setupTooltip (anchor, binding) {\n      if (binding.value === null || binding.value === undefined) {\n        const tooltipId = anchor.getAttribute('data-dt-tooltip-id');\n        if (tooltipId) {\n          tooltipApp.removeTooltip(tooltipId);\n        }\n        return;\n      }\n      const tooltipId = anchor.getAttribute('data-dt-tooltip-id') || getUniqueString();\n\n      let tooltipConfig;\n      if (typeof binding.value === 'string') {\n        tooltipConfig = {\n          message: binding.value,\n          placement: binding.arg || DEFAULT_PLACEMENT,\n        };\n      } else if (typeof binding.value === 'object' && binding.value !== null) {\n        tooltipConfig = {\n          placement: binding.arg || binding.value.placement || DEFAULT_PLACEMENT,\n          ...binding.value,\n        };\n      } else {\n        console.error('DtTooltipDirective: binding value must be string, object, null or undefined');\n        return;\n      }\n\n      Object.keys(binding.modifiers).forEach(modifier => {\n        switch (modifier) {\n          case 'inverted':\n            tooltipConfig.inverted = true;\n            break;\n          case 'no-delay':\n            tooltipConfig.delay = false;\n            break;\n          case 'no-transition':\n            tooltipConfig.transition = false;\n            break;\n          default:\n            if (TOOLTIP_DIRECTIONS.includes(modifier)) {\n              tooltipConfig.placement = modifier;\n            }\n            break;\n        }\n      });\n\n      tooltipConfig.anchorElement = anchor;\n      anchor.setAttribute('data-dt-tooltip-id', tooltipId);\n      tooltipApp.addOrUpdateTooltip(tooltipId, tooltipConfig);\n    }\n  },\n};\n\nexport default DtTooltipDirective;\n"],"mappings":"6TAKA,IAAa,EAAqB,CAChC,KAAM,uBACN,QAAS,EAAK,CAEZ,GAAI,CAAC,WAAW,wBAAyB,CACvC,IAAM,GAAA,EAAA,EAAA,WAAkC,CACtC,KAAM,wBACN,WAAY,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