UNPKG

bootstrap-vue-next

Version:

Seamless integration of Vue 3, Bootstrap 5, and TypeScript for modern, type-safe UI development

1 lines 2.68 kB
{"version":3,"file":"index.mjs","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'\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 if (typeof document === 'undefined') 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"],"names":[],"mappings":";;;;AASA,MAAM,OAAO,CAAC,IAA0B,YAAwC;AAE9E,MAAI,OAAO,aAAa,YAAa;AAErC,QAAM,MAAM,gBAAgB,OAAO;AAGnC,QAAM,kBAAkB;AACxB,kBAAgB,eAAe,gBAAgB,gBAAgB,uBAAO,OAAO,IAAI;AAGjF,QAAM,mBAAmB,gBAAgB,aAAc,GAAG;AAC1D,MAAI,kBAAkB;AACpB,qBAAiB,QAAA;AAAA,EACnB;AAEA,QAAM,EAAC,KAAK,MAAA,IAAS;AACrB,QAAM,WAAW,OAAO,UAAU,YAAY,UAAU;AACxD,QAAM,UAAU,MACZ,MACA,OAAO,UAAU,WACf,QACA,WACE,MAAM,WAAW,MAAM,UACvB;AAGR,kBAAgB,aAAc,GAAG,IAAI;AAAA,IACnC;AAAA,IACA;AAAA,IACA,WAAW,KAAK,OAAO,CAAC,WAAW,SAAS,CAAC,IAAI,CAAA;AAAA,EAAC;AAEtD;AAEO,MAAM,cAA+C;AAAA,EAC1D,SAAS;AAAA,EACT,SAAS;AAAA,EACT,cAAc,IAAI,SAAS;AACzB,UAAM,MAAM,gBAAgB,OAAO;AACnC,UAAM,kBAAkB;AACxB,UAAM,WAAW,gBAAgB,eAAe,GAAG;AAEnD,QAAI,CAAC,SAAU;AAEf,aAAS,QAAA;AACT,WAAO,gBAAgB,aAAc,GAAG;AAAA,EAC1C;AACF;"}