bootstrap-vue-next
Version:
Seamless integration of Vue 3, Bootstrap 5, and TypeScript for modern, type-safe UI development
1 lines • 2.66 kB
Source Map (JSON)
{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/directives/BScrollspy/index.ts"],"sourcesContent":["import {type Directive, type DirectiveBinding} from 'vue'\nimport {useScrollspy} from '../../composables/useScrollspy'\nimport {omit} from '../../utils/object'\nimport {getDirectiveUid} from '../utils'\nimport {getSafeDocument} from '../../utils/dom'\n\nexport interface ElementWithScrollspy extends HTMLElement {\n $__scrollspy?: Record<number, ReturnType<typeof useScrollspy>>\n}\n\nconst bind = (el: ElementWithScrollspy, binding: Readonly<DirectiveBinding>) => {\n // SSR guard: skip on server\n const doc = getSafeDocument()\n if (doc === null) return\n\n const uid = getDirectiveUid(binding)\n\n // Initialize UID namespace for this directive\n const elWithScrollspy = el as ElementWithScrollspy & Record<string, unknown>\n elWithScrollspy.$__scrollspy = elWithScrollspy.$__scrollspy ?? Object.create(null)\n\n // Clean up existing instance if present\n const existingInstance = elWithScrollspy.$__scrollspy![uid]\n if (existingInstance) {\n existingInstance.cleanup()\n }\n\n const {arg, value} = binding\n const isObject = typeof value === 'object' && value !== null\n const content = arg\n ? arg\n : typeof value === 'string'\n ? value\n : isObject\n ? value.content || value.element\n : null\n\n // Store scrollspy instance for this component instance\n elWithScrollspy.$__scrollspy![uid] = useScrollspy(\n content,\n el,\n isObject ? omit(value, ['content', 'element']) : {}\n )\n}\n\nexport const vBScrollspy: Directive<ElementWithScrollspy> = {\n mounted: bind,\n updated: bind,\n beforeUnmount(el, binding) {\n const uid = getDirectiveUid(binding)\n const elWithScrollspy = el as ElementWithScrollspy & Record<string, unknown>\n const instance = elWithScrollspy.$__scrollspy?.[uid]\n\n if (!instance) return\n\n instance.cleanup()\n delete elWithScrollspy.$__scrollspy![uid]\n },\n}\n"],"mappings":";;;;;;AAUA,IAAM,QAAQ,IAA0B,YAAwC;CAG9E,IADY,gBACR,MAAQ,MAAM;CAElB,MAAM,MAAM,gBAAgB,OAAO;CAGnC,MAAM,kBAAkB;CACxB,gBAAgB,eAAe,gBAAgB,gBAAgB,OAAO,OAAO,IAAI;CAGjF,MAAM,mBAAmB,gBAAgB,aAAc;CACvD,IAAI,kBACF,iBAAiB,QAAQ;CAG3B,MAAM,EAAC,KAAK,UAAS;CACrB,MAAM,WAAW,OAAO,UAAU,YAAY,UAAU;CACxD,MAAM,UAAU,MACZ,MACA,OAAO,UAAU,WACf,QACA,WACE,MAAM,WAAW,MAAM,UACvB;CAGR,gBAAgB,aAAc,OAAO,aACnC,SACA,IACA,WAAW,KAAK,OAAO,CAAC,WAAW,SAAS,CAAC,IAAI,CAAC,CACpD;AACF;AAEA,IAAa,cAA+C;CAC1D,SAAS;CACT,SAAS;CACT,cAAc,IAAI,SAAS;EACzB,MAAM,MAAM,gBAAgB,OAAO;EACnC,MAAM,kBAAkB;EACxB,MAAM,WAAW,gBAAgB,eAAe;EAEhD,IAAI,CAAC,UAAU;EAEf,SAAS,QAAQ;EACjB,OAAO,gBAAgB,aAAc;CACvC;AACF"}