Comparing version 1.8.1 to 2.0.0
import type { AccordionItem, AccordionOptions } from './types'; | ||
import { AccordionInterface } from './interface'; | ||
declare class Accordion implements AccordionInterface { | ||
_accordionEl: HTMLElement; | ||
_items: AccordionItem[]; | ||
_options: AccordionOptions; | ||
constructor(items?: AccordionItem[], options?: AccordionOptions); | ||
private _init; | ||
_clickHandler: EventListenerOrEventListenerObject; | ||
_initialized: boolean; | ||
constructor(accordionEl?: HTMLElement | null, items?: AccordionItem[], options?: AccordionOptions); | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
getItem(id: string): AccordionItem; | ||
@@ -9,0 +15,0 @@ open(id: string): void; |
@@ -15,2 +15,3 @@ "use strict"; | ||
exports.initAccordions = void 0; | ||
var instances_1 = require("../../dom/instances"); | ||
var Default = { | ||
@@ -25,23 +26,48 @@ alwaysOpen: false, | ||
var Accordion = /** @class */ (function () { | ||
function Accordion(items, options) { | ||
function Accordion(accordionEl, items, options) { | ||
if (accordionEl === void 0) { accordionEl = null; } | ||
if (items === void 0) { items = []; } | ||
if (options === void 0) { options = Default; } | ||
this._accordionEl = accordionEl; | ||
this._items = items; | ||
this._options = __assign(__assign({}, Default), options); | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances_1.default.addInstance('Accordion', this, this._accordionEl.id, true); | ||
} | ||
Accordion.prototype._init = function () { | ||
Accordion.prototype.init = function () { | ||
var _this = this; | ||
if (this._items.length) { | ||
if (this._items.length && !this._initialized) { | ||
// show accordion item based on click | ||
this._items.map(function (item) { | ||
this._items.forEach(function (item) { | ||
if (item.active) { | ||
_this.open(item.id); | ||
} | ||
item.triggerEl.addEventListener('click', function () { | ||
var clickHandler = function () { | ||
_this.toggle(item.id); | ||
}); | ||
}; | ||
item.triggerEl.addEventListener('click', clickHandler); | ||
// Store the clickHandler in a property of the item for removal later | ||
item.clickHandler = clickHandler; | ||
}); | ||
this._initialized = true; | ||
} | ||
}; | ||
Accordion.prototype.destroy = function () { | ||
if (this._items.length && this._initialized) { | ||
this._items.forEach(function (item) { | ||
item.triggerEl.removeEventListener('click', item.clickHandler); | ||
// Clean up by deleting the clickHandler property from the item | ||
delete item.clickHandler; | ||
}); | ||
this._initialized = false; | ||
} | ||
}; | ||
Accordion.prototype.removeInstance = function () { | ||
instances_1.default.removeInstance('Accordion', this._accordionEl.id); | ||
}; | ||
Accordion.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Accordion.prototype.getItem = function (id) { | ||
@@ -136,3 +162,3 @@ return this._items.filter(function (item) { return item.id === id; })[0]; | ||
}); | ||
new Accordion(items, { | ||
new Accordion($accordionEl, items, { | ||
alwaysOpen: alwaysOpen === 'open' ? true : false, | ||
@@ -139,0 +165,0 @@ activeClasses: activeClasses |
@@ -9,3 +9,6 @@ import { AccordionItem, AccordionOptions } from './types'; | ||
close(id: string): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -8,2 +8,3 @@ import { AccordionInterface } from './interface'; | ||
active?: boolean; | ||
clickHandler?: EventListenerOrEventListenerObject; | ||
}; | ||
@@ -10,0 +11,0 @@ export declare type AccordionOptions = { |
import type { CarouselOptions, CarouselItem, IndicatorItem, RotationItems } from './types'; | ||
import { CarouselInterface } from './interface'; | ||
declare class Carousel implements CarouselInterface { | ||
_carouselEl: HTMLElement; | ||
_items: CarouselItem[]; | ||
@@ -10,7 +11,11 @@ _indicators: IndicatorItem[]; | ||
_options: CarouselOptions; | ||
constructor(items?: CarouselItem[], options?: CarouselOptions); | ||
_initialized: boolean; | ||
constructor(carouselEl?: HTMLElement | null, items?: CarouselItem[], options?: CarouselOptions); | ||
/** | ||
* initialize carousel and items based on active one | ||
*/ | ||
_init(): void; | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
getItem(position: number): CarouselItem; | ||
@@ -17,0 +22,0 @@ /** |
@@ -15,2 +15,3 @@ "use strict"; | ||
exports.initCarousels = void 0; | ||
var instances_1 = require("../../dom/instances"); | ||
var Default = { | ||
@@ -29,5 +30,7 @@ defaultPosition: 0, | ||
var Carousel = /** @class */ (function () { | ||
function Carousel(items, options) { | ||
function Carousel(carouselEl, items, options) { | ||
if (carouselEl === void 0) { carouselEl = null; } | ||
if (items === void 0) { items = []; } | ||
if (options === void 0) { options = Default; } | ||
this._carouselEl = carouselEl; | ||
this._items = items; | ||
@@ -39,3 +42,5 @@ this._options = __assign(__assign(__assign({}, Default), options), { indicators: __assign(__assign({}, Default.indicators), options.indicators) }); | ||
this._intervalInstance = null; | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances_1.default.addInstance('Carousel', this, this._carouselEl.id, true); | ||
} | ||
@@ -45,20 +50,35 @@ /** | ||
*/ | ||
Carousel.prototype._init = function () { | ||
Carousel.prototype.init = function () { | ||
var _this = this; | ||
this._items.map(function (item) { | ||
item.el.classList.add('absolute', 'inset-0', 'transition-transform', 'transform'); | ||
}); | ||
// if no active item is set then first position is default | ||
if (this._getActiveItem()) { | ||
this.slideTo(this._getActiveItem().position); | ||
if (this._items.length && !this._initialized) { | ||
this._items.map(function (item) { | ||
item.el.classList.add('absolute', 'inset-0', 'transition-transform', 'transform'); | ||
}); | ||
// if no active item is set then first position is default | ||
if (this._getActiveItem()) { | ||
this.slideTo(this._getActiveItem().position); | ||
} | ||
else { | ||
this.slideTo(0); | ||
} | ||
this._indicators.map(function (indicator, position) { | ||
indicator.el.addEventListener('click', function () { | ||
_this.slideTo(position); | ||
}); | ||
}); | ||
this._initialized = true; | ||
} | ||
else { | ||
this.slideTo(0); | ||
}; | ||
Carousel.prototype.destroy = function () { | ||
if (this._initialized) { | ||
this._initialized = false; | ||
} | ||
this._indicators.map(function (indicator, position) { | ||
indicator.el.addEventListener('click', function () { | ||
_this.slideTo(position); | ||
}); | ||
}); | ||
}; | ||
Carousel.prototype.removeInstance = function () { | ||
instances_1.default.removeInstance('Carousel', this._carouselEl.id); | ||
}; | ||
Carousel.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Carousel.prototype.getItem = function (position) { | ||
@@ -219,3 +239,3 @@ return this._items[position]; | ||
} | ||
var carousel = new Carousel(items, { | ||
var carousel = new Carousel($carouselEl, items, { | ||
defaultPosition: defaultPosition, | ||
@@ -222,0 +242,0 @@ indicators: { |
@@ -9,3 +9,3 @@ import { CarouselOptions, CarouselItem, IndicatorItem, RotationItems } from './types'; | ||
_options: CarouselOptions; | ||
_init(): void; | ||
init(): void; | ||
getItem(position: number): CarouselItem; | ||
@@ -20,3 +20,6 @@ _getActiveItem(): CarouselItem; | ||
pause(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -8,4 +8,9 @@ import type { CollapseOptions } from './types'; | ||
_visible: boolean; | ||
_initialized: boolean; | ||
_clickHandler: EventListenerOrEventListenerObject; | ||
constructor(targetEl?: HTMLElement | null, triggerEl?: HTMLElement | null, options?: CollapseOptions); | ||
_init(): void; | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
collapse(): void; | ||
@@ -12,0 +17,0 @@ expand(): void; |
@@ -15,2 +15,3 @@ "use strict"; | ||
exports.initCollapses = void 0; | ||
var instances_1 = require("../../dom/instances"); | ||
var Default = { | ||
@@ -30,7 +31,9 @@ onCollapse: function () { }, | ||
this._visible = false; | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances_1.default.addInstance('Collapse', this, this._targetEl.id, true); | ||
} | ||
Collapse.prototype._init = function () { | ||
Collapse.prototype.init = function () { | ||
var _this = this; | ||
if (this._triggerEl) { | ||
if (this._triggerEl && this._targetEl && !this._initialized) { | ||
if (this._triggerEl.hasAttribute('aria-expanded')) { | ||
@@ -44,7 +47,22 @@ this._visible = | ||
} | ||
this._triggerEl.addEventListener('click', function () { | ||
this._clickHandler = function () { | ||
_this.toggle(); | ||
}); | ||
}; | ||
this._triggerEl.addEventListener('click', this._clickHandler); | ||
this._initialized = true; | ||
} | ||
}; | ||
Collapse.prototype.destroy = function () { | ||
if (this._triggerEl && this._initialized) { | ||
this._triggerEl.removeEventListener('click', this._clickHandler); | ||
this._initialized = false; | ||
} | ||
}; | ||
Collapse.prototype.removeInstance = function () { | ||
instances_1.default.removeInstance('Collapse', this._targetEl.id); | ||
}; | ||
Collapse.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Collapse.prototype.collapse = function () { | ||
@@ -51,0 +69,0 @@ this._targetEl.classList.add('hidden'); |
@@ -7,7 +7,10 @@ import { CollapseOptions } from './types'; | ||
_visible: boolean; | ||
_init(): void; | ||
init(): void; | ||
collapse(): void; | ||
expand(): void; | ||
toggle(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -9,4 +9,10 @@ import type { DialOptions, DialTriggerType } from './types'; | ||
_visible: boolean; | ||
_initialized: boolean; | ||
_showEventHandler: EventListenerOrEventListenerObject; | ||
_hideEventHandler: EventListenerOrEventListenerObject; | ||
constructor(parentEl?: HTMLElement | null, triggerEl?: HTMLElement | null, targetEl?: HTMLElement | null, options?: DialOptions); | ||
_init(): void; | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
hide(): void; | ||
@@ -13,0 +19,0 @@ show(): void; |
@@ -15,2 +15,3 @@ "use strict"; | ||
exports.initDials = void 0; | ||
var instances_1 = require("../../dom/instances"); | ||
var Default = { | ||
@@ -33,25 +34,49 @@ triggerType: 'hover', | ||
this._visible = false; | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances_1.default.addInstance('Dial', this, this._targetEl.id, true); | ||
} | ||
Dial.prototype._init = function () { | ||
Dial.prototype.init = function () { | ||
var _this = this; | ||
if (this._triggerEl) { | ||
if (this._triggerEl && this._targetEl && !this._initialized) { | ||
var triggerEventTypes = this._getTriggerEventTypes(this._options.triggerType); | ||
this._showEventHandler = function () { | ||
_this.show(); | ||
}; | ||
triggerEventTypes.showEvents.forEach(function (ev) { | ||
_this._triggerEl.addEventListener(ev, function () { | ||
_this.show(); | ||
}); | ||
_this._targetEl.addEventListener(ev, function () { | ||
_this.show(); | ||
}); | ||
_this._triggerEl.addEventListener(ev, _this._showEventHandler); | ||
_this._targetEl.addEventListener(ev, _this._showEventHandler); | ||
}); | ||
this._hideEventHandler = function () { | ||
if (!_this._parentEl.matches(':hover')) { | ||
_this.hide(); | ||
} | ||
}; | ||
triggerEventTypes.hideEvents.forEach(function (ev) { | ||
_this._parentEl.addEventListener(ev, function () { | ||
if (!_this._parentEl.matches(':hover')) { | ||
_this.hide(); | ||
} | ||
}); | ||
_this._parentEl.addEventListener(ev, _this._hideEventHandler); | ||
}); | ||
this._initialized = true; | ||
} | ||
}; | ||
Dial.prototype.destroy = function () { | ||
var _this = this; | ||
if (this._initialized) { | ||
var triggerEventTypes = this._getTriggerEventTypes(this._options.triggerType); | ||
triggerEventTypes.showEvents.forEach(function (ev) { | ||
_this._triggerEl.removeEventListener(ev, _this._showEventHandler); | ||
_this._targetEl.removeEventListener(ev, _this._showEventHandler); | ||
}); | ||
triggerEventTypes.hideEvents.forEach(function (ev) { | ||
_this._parentEl.removeEventListener(ev, _this._hideEventHandler); | ||
}); | ||
this._initialized = false; | ||
} | ||
}; | ||
Dial.prototype.removeInstance = function () { | ||
instances_1.default.removeInstance('Dial', this._targetEl.id); | ||
}; | ||
Dial.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Dial.prototype.hide = function () { | ||
@@ -58,0 +83,0 @@ this._targetEl.classList.add('hidden'); |
@@ -8,3 +8,3 @@ import { DialOptions, DialTriggerEventTypes, DialTriggerType } from './types'; | ||
_visible: boolean; | ||
_init(): void; | ||
init(): void; | ||
isVisible(): boolean; | ||
@@ -16,3 +16,6 @@ isHidden(): boolean; | ||
_getTriggerEventTypes(triggerType: DialTriggerType): DialTriggerEventTypes; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -7,4 +7,9 @@ import type { DismissOptions } from './types'; | ||
_options: DismissOptions; | ||
_initialized: boolean; | ||
_clickHandler: EventListenerOrEventListenerObject; | ||
constructor(targetEl?: HTMLElement | null, triggerEl?: HTMLElement | null, options?: DismissOptions); | ||
_init(): void; | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
hide(): void; | ||
@@ -11,0 +16,0 @@ } |
@@ -15,2 +15,3 @@ "use strict"; | ||
exports.initDismisses = void 0; | ||
var instances_1 = require("../../dom/instances"); | ||
var Default = { | ||
@@ -30,12 +31,29 @@ transition: 'transition-opacity', | ||
this._options = __assign(__assign({}, Default), options); | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances_1.default.addInstance('Dismiss', this, this._targetEl.id, true); | ||
} | ||
Dismiss.prototype._init = function () { | ||
Dismiss.prototype.init = function () { | ||
var _this = this; | ||
if (this._triggerEl) { | ||
this._triggerEl.addEventListener('click', function () { | ||
if (this._triggerEl && this._targetEl && !this._initialized) { | ||
this._clickHandler = function () { | ||
_this.hide(); | ||
}); | ||
}; | ||
this._triggerEl.addEventListener('click', this._clickHandler); | ||
this._initialized = true; | ||
} | ||
}; | ||
Dismiss.prototype.destroy = function () { | ||
if (this._triggerEl && this._initialized) { | ||
this._triggerEl.removeEventListener('click', this._clickHandler); | ||
this._initialized = false; | ||
} | ||
}; | ||
Dismiss.prototype.removeInstance = function () { | ||
instances_1.default.removeInstance('Dismiss', this._targetEl.id); | ||
}; | ||
Dismiss.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Dismiss.prototype.hide = function () { | ||
@@ -42,0 +60,0 @@ var _this = this; |
@@ -6,5 +6,8 @@ import { DismissOptions } from './types'; | ||
_options: DismissOptions; | ||
_init(): void; | ||
init(): void; | ||
hide(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -8,4 +8,9 @@ import type { DrawerOptions, PlacementClasses } from './types'; | ||
_visible: boolean; | ||
_initialized: boolean; | ||
_handleEscapeKey: EventListenerOrEventListenerObject; | ||
constructor(targetEl?: HTMLElement | null, options?: DrawerOptions); | ||
_init(): void; | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
hide(): void; | ||
@@ -12,0 +17,0 @@ show(): void; |
@@ -15,2 +15,3 @@ "use strict"; | ||
exports.initDrawers = void 0; | ||
var instances_1 = require("../../dom/instances"); | ||
var Default = { | ||
@@ -34,26 +35,45 @@ placement: 'left', | ||
this._visible = false; | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances_1.default.addInstance('Drawer', this, this._targetEl.id, true); | ||
} | ||
Drawer.prototype._init = function () { | ||
Drawer.prototype.init = function () { | ||
var _this = this; | ||
// set initial accessibility attributes | ||
if (this._targetEl) { | ||
if (this._targetEl && !this._initialized) { | ||
this._targetEl.setAttribute('aria-hidden', 'true'); | ||
this._targetEl.classList.add('transition-transform'); | ||
// set base placement classes | ||
this._getPlacementClasses(this._options.placement).base.map(function (c) { | ||
_this._targetEl.classList.add(c); | ||
}); | ||
this._handleEscapeKey = function (event) { | ||
if (event.key === 'Escape') { | ||
// if 'Escape' key is pressed | ||
if (_this.isVisible()) { | ||
// if the Drawer is visible | ||
_this.hide(); // hide the Drawer | ||
} | ||
} | ||
}; | ||
// add keyboard event listener to document | ||
document.addEventListener('keydown', this._handleEscapeKey); | ||
this._initialized = true; | ||
} | ||
// set base placement classes | ||
this._getPlacementClasses(this._options.placement).base.map(function (c) { | ||
_this._targetEl.classList.add(c); | ||
}); | ||
// add keyboard event listener to document | ||
document.addEventListener('keydown', function (event) { | ||
if (event.key === 'Escape') { | ||
// if 'Escape' key is pressed | ||
if (_this.isVisible()) { | ||
// if the Drawer is visible | ||
_this.hide(); // hide the Drawer | ||
} | ||
} | ||
}); | ||
}; | ||
Drawer.prototype.destroy = function () { | ||
if (this._initialized) { | ||
this.hide(); | ||
// Remove the keyboard event listener | ||
document.removeEventListener('keydown', this._handleEscapeKey); | ||
this._initialized = false; | ||
} | ||
}; | ||
Drawer.prototype.removeInstance = function () { | ||
instances_1.default.removeInstance('Drawer', this._targetEl.id); | ||
}; | ||
Drawer.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Drawer.prototype.hide = function () { | ||
@@ -202,9 +222,3 @@ var _this = this; | ||
}()); | ||
var getDrawerInstance = function (id, instances) { | ||
if (instances.some(function (drawerInstance) { return drawerInstance.id === id; })) { | ||
return instances.find(function (drawerInstance) { return drawerInstance.id === id; }); | ||
} | ||
}; | ||
function initDrawers() { | ||
var drawerInstances = []; | ||
document.querySelectorAll('[data-drawer-target]').forEach(function ($triggerEl) { | ||
@@ -221,26 +235,21 @@ // mandatory | ||
var edgeOffset = $triggerEl.getAttribute('data-drawer-edge-offset'); | ||
if (!getDrawerInstance(drawerId, drawerInstances)) { | ||
drawerInstances.push({ | ||
id: drawerId, | ||
object: new Drawer($drawerEl, { | ||
placement: placement ? placement : Default.placement, | ||
bodyScrolling: bodyScrolling | ||
? bodyScrolling === 'true' | ||
? true | ||
: false | ||
: Default.bodyScrolling, | ||
backdrop: backdrop | ||
? backdrop === 'true' | ||
? true | ||
: false | ||
: Default.backdrop, | ||
edge: edge | ||
? edge === 'true' | ||
? true | ||
: false | ||
: Default.edge, | ||
edgeOffset: edgeOffset | ||
? edgeOffset | ||
: Default.edgeOffset, | ||
}), | ||
if (!instances_1.default.instanceExists('Drawer', $drawerEl.getAttribute('id'))) { | ||
new Drawer($drawerEl, { | ||
placement: placement ? placement : Default.placement, | ||
bodyScrolling: bodyScrolling | ||
? bodyScrolling === 'true' | ||
? true | ||
: false | ||
: Default.bodyScrolling, | ||
backdrop: backdrop | ||
? backdrop === 'true' | ||
? true | ||
: false | ||
: Default.backdrop, | ||
edge: edge | ||
? edge === 'true' | ||
? true | ||
: false | ||
: Default.edge, | ||
edgeOffset: edgeOffset ? edgeOffset : Default.edgeOffset, | ||
}); | ||
@@ -257,6 +266,6 @@ } | ||
if ($drawerEl) { | ||
var drawer_1 = getDrawerInstance(drawerId, drawerInstances); | ||
var drawer_1 = instances_1.default.getInstance('Drawer', $drawerEl.getAttribute('id')); | ||
if (drawer_1) { | ||
$triggerEl.addEventListener('click', function () { | ||
drawer_1.object.toggle(); | ||
drawer_1.toggle(); | ||
}); | ||
@@ -280,6 +289,6 @@ } | ||
if ($drawerEl) { | ||
var drawer_2 = getDrawerInstance(drawerId, drawerInstances); | ||
var drawer_2 = instances_1.default.getInstance('Drawer', $drawerEl.getAttribute('id')); | ||
if (drawer_2) { | ||
$triggerEl.addEventListener('click', function () { | ||
drawer_2.object.hide(); | ||
drawer_2.hide(); | ||
}); | ||
@@ -299,6 +308,6 @@ } | ||
if ($drawerEl) { | ||
var drawer_3 = getDrawerInstance(drawerId, drawerInstances); | ||
var drawer_3 = instances_1.default.getInstance('Drawer', $drawerEl.getAttribute('id')); | ||
if (drawer_3) { | ||
$triggerEl.addEventListener('click', function () { | ||
drawer_3.object.show(); | ||
drawer_3.show(); | ||
}); | ||
@@ -305,0 +314,0 @@ } |
@@ -7,3 +7,3 @@ import { DrawerOptions, PlacementClasses } from './types'; | ||
_visible: boolean; | ||
_init(): void; | ||
init(): void; | ||
isVisible(): boolean; | ||
@@ -17,3 +17,6 @@ isHidden(): boolean; | ||
_getPlacementClasses(placement: string): PlacementClasses; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -18,6 +18,2 @@ import { DrawerInterface } from './interface'; | ||
}; | ||
export declare type DrawerInstance = { | ||
id: string; | ||
object: DrawerInterface; | ||
}; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -10,5 +10,13 @@ import type { Instance as PopperInstance } from '@popperjs/core'; | ||
_popperInstance: PopperInstance; | ||
_initialized: boolean; | ||
_clickOutsideEventListener: EventListenerOrEventListenerObject; | ||
_hoverShowTriggerElHandler: EventListenerOrEventListenerObject; | ||
_hoverShowTargetElHandler: EventListenerOrEventListenerObject; | ||
_hoverHideHandler: EventListenerOrEventListenerObject; | ||
_clickHandler: EventListenerOrEventListenerObject; | ||
constructor(targetElement?: HTMLElement | null, triggerElement?: HTMLElement | null, options?: DropdownOptions); | ||
_init(): void; | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
_setupEventListeners(): void; | ||
@@ -15,0 +23,0 @@ _createPopperInstance(): PopperInstance; |
@@ -26,2 +26,3 @@ "use strict"; | ||
var core_1 = require("@popperjs/core"); | ||
var instances_1 = require("../../dom/instances"); | ||
var Default = { | ||
@@ -46,54 +47,86 @@ placement: 'bottom', | ||
this._options = __assign(__assign({}, Default), options); | ||
this._popperInstance = this._createPopperInstance(); | ||
this._popperInstance = null; | ||
this._visible = false; | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances_1.default.addInstance('Dropdown', this, this._targetEl.id, true); | ||
} | ||
Dropdown.prototype._init = function () { | ||
if (this._triggerEl) { | ||
Dropdown.prototype.init = function () { | ||
if (this._triggerEl && this._targetEl && !this._initialized) { | ||
this._popperInstance = this._createPopperInstance(); | ||
this._setupEventListeners(); | ||
this._initialized = true; | ||
} | ||
}; | ||
Dropdown.prototype.destroy = function () { | ||
var _this = this; | ||
var triggerEvents = this._getTriggerEvents(); | ||
// Remove click event listeners for trigger element | ||
if (this._options.triggerType === 'click') { | ||
triggerEvents.showEvents.forEach(function (ev) { | ||
_this._triggerEl.removeEventListener(ev, _this._clickHandler); | ||
}); | ||
} | ||
// Remove hover event listeners for trigger and target elements | ||
if (this._options.triggerType === 'hover') { | ||
triggerEvents.showEvents.forEach(function (ev) { | ||
_this._triggerEl.removeEventListener(ev, _this._hoverShowTriggerElHandler); | ||
_this._targetEl.removeEventListener(ev, _this._hoverShowTargetElHandler); | ||
}); | ||
triggerEvents.hideEvents.forEach(function (ev) { | ||
_this._triggerEl.removeEventListener(ev, _this._hoverHideHandler); | ||
_this._targetEl.removeEventListener(ev, _this._hoverHideHandler); | ||
}); | ||
} | ||
this._popperInstance.destroy(); | ||
this._initialized = false; | ||
}; | ||
Dropdown.prototype.removeInstance = function () { | ||
instances_1.default.removeInstance('Dropdown', this._targetEl.id); | ||
}; | ||
Dropdown.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Dropdown.prototype._setupEventListeners = function () { | ||
var _this = this; | ||
var triggerEvents = this._getTriggerEvents(); | ||
this._clickHandler = function () { | ||
_this.toggle(); | ||
}; | ||
// click event handling for trigger element | ||
if (this._options.triggerType === 'click') { | ||
triggerEvents.showEvents.forEach(function (ev) { | ||
_this._triggerEl.addEventListener(ev, function () { | ||
_this.toggle(); | ||
}); | ||
_this._triggerEl.addEventListener(ev, _this._clickHandler); | ||
}); | ||
} | ||
this._hoverShowTriggerElHandler = function (ev) { | ||
if (ev.type === 'click') { | ||
_this.toggle(); | ||
} | ||
else { | ||
setTimeout(function () { | ||
_this.show(); | ||
}, _this._options.delay); | ||
} | ||
}; | ||
this._hoverShowTargetElHandler = function () { | ||
_this.show(); | ||
}; | ||
this._hoverHideHandler = function () { | ||
setTimeout(function () { | ||
if (!_this._targetEl.matches(':hover')) { | ||
_this.hide(); | ||
} | ||
}, _this._options.delay); | ||
}; | ||
// hover event handling for trigger element | ||
if (this._options.triggerType === 'hover') { | ||
triggerEvents.showEvents.forEach(function (ev) { | ||
_this._triggerEl.addEventListener(ev, function () { | ||
if (ev === 'click') { | ||
_this.toggle(); | ||
} | ||
else { | ||
setTimeout(function () { | ||
_this.show(); | ||
}, _this._options.delay); | ||
} | ||
}); | ||
_this._targetEl.addEventListener(ev, function () { | ||
_this.show(); | ||
}); | ||
_this._triggerEl.addEventListener(ev, _this._hoverShowTriggerElHandler); | ||
_this._targetEl.addEventListener(ev, _this._hoverShowTargetElHandler); | ||
}); | ||
triggerEvents.hideEvents.forEach(function (ev) { | ||
_this._triggerEl.addEventListener(ev, function () { | ||
setTimeout(function () { | ||
if (!_this._targetEl.matches(':hover')) { | ||
_this.hide(); | ||
} | ||
}, _this._options.delay); | ||
}); | ||
_this._targetEl.addEventListener(ev, function () { | ||
setTimeout(function () { | ||
if (!_this._triggerEl.matches(':hover')) { | ||
_this.hide(); | ||
} | ||
}, _this._options.delay); | ||
}); | ||
_this._triggerEl.addEventListener(ev, _this._hoverHideHandler); | ||
_this._targetEl.addEventListener(ev, _this._hoverHideHandler); | ||
}); | ||
@@ -100,0 +133,0 @@ } |
@@ -9,4 +9,5 @@ import { DropdownOptions, DropdownTriggerType, DropdownTriggerEventTypes } from './types'; | ||
_popperInstance: PopperInstance; | ||
_initialized: boolean; | ||
_clickOutsideEventListener: EventListenerOrEventListenerObject; | ||
_init(): void; | ||
init(): void; | ||
_createPopperInstance(): PopperInstance; | ||
@@ -22,3 +23,6 @@ _setupEventListeners(): void; | ||
hide(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -10,4 +10,8 @@ import type { ModalOptions } from './types'; | ||
_keydownEventListener: EventListenerOrEventListenerObject; | ||
_initialized: boolean; | ||
constructor(targetEl?: HTMLElement | null, options?: ModalOptions); | ||
_init(): void; | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
_createBackdrop(): void; | ||
@@ -14,0 +18,0 @@ _destroyBackdropEl(): void; |
@@ -15,2 +15,3 @@ "use strict"; | ||
exports.initModals = void 0; | ||
var instances_1 = require("../../dom/instances"); | ||
var Default = { | ||
@@ -33,12 +34,28 @@ placement: 'center', | ||
this._backdropEl = null; | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances_1.default.addInstance('Modal', this, this._targetEl.id, true); | ||
} | ||
Modal.prototype._init = function () { | ||
Modal.prototype.init = function () { | ||
var _this = this; | ||
if (this._targetEl) { | ||
if (this._targetEl && !this._initialized) { | ||
this._getPlacementClasses().map(function (c) { | ||
_this._targetEl.classList.add(c); | ||
}); | ||
this._initialized = true; | ||
} | ||
}; | ||
Modal.prototype.destroy = function () { | ||
if (this._initialized) { | ||
this.hide(); | ||
this._initialized = false; | ||
} | ||
}; | ||
Modal.prototype.removeInstance = function () { | ||
instances_1.default.removeInstance('Modal', this._targetEl.id); | ||
}; | ||
Modal.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Modal.prototype._createBackdrop = function () { | ||
@@ -132,4 +149,2 @@ var _a; | ||
this._isHidden = false; | ||
// prevent body scroll | ||
document.body.classList.add('overflow-hidden'); | ||
// Add keyboard event listener to the document | ||
@@ -139,2 +154,4 @@ if (this._options.closable) { | ||
} | ||
// prevent body scroll | ||
document.body.classList.add('overflow-hidden'); | ||
// callback function | ||
@@ -170,10 +187,3 @@ this._options.onShow(this); | ||
}()); | ||
var getModalInstance = function (id, instances) { | ||
if (instances.some(function (modalInstance) { return modalInstance.id === id; })) { | ||
return instances.find(function (modalInstance) { return modalInstance.id === id; }); | ||
} | ||
return null; | ||
}; | ||
function initModals() { | ||
var modalInstances = []; | ||
// initiate modal based on data-modal-target | ||
@@ -186,11 +196,6 @@ document.querySelectorAll('[data-modal-target]').forEach(function ($triggerEl) { | ||
var backdrop = $modalEl.getAttribute('data-modal-backdrop'); | ||
if (!getModalInstance(modalId, modalInstances)) { | ||
modalInstances.push({ | ||
id: modalId, | ||
object: new Modal($modalEl, { | ||
placement: placement | ||
? placement | ||
: Default.placement, | ||
backdrop: backdrop ? backdrop : Default.backdrop, | ||
}), | ||
if (instances_1.default.instanceExists('Modal', $modalEl.getAttribute('id'))) { | ||
new Modal($modalEl, { | ||
placement: placement ? placement : Default.placement, | ||
backdrop: backdrop ? backdrop : Default.backdrop, | ||
}); | ||
@@ -210,7 +215,9 @@ } | ||
var backdrop = $modalEl.getAttribute('data-modal-backdrop'); | ||
var modal_1 = getModalInstance(modalId, modalInstances); | ||
if (!modal_1) { | ||
modal_1 = { | ||
id: modalId, | ||
object: new Modal($modalEl, { | ||
var modal_1; | ||
if (instances_1.default.instanceExists('Modal', $modalEl.getAttribute('id'))) { | ||
modal_1 = instances_1.default.getInstance('Modal', $modalEl.getAttribute('id')); | ||
} | ||
else { | ||
{ | ||
modal_1 = new Modal($modalEl, { | ||
placement: placement | ||
@@ -220,8 +227,7 @@ ? placement | ||
backdrop: backdrop ? backdrop : Default.backdrop, | ||
}), | ||
}; | ||
modalInstances.push(modal_1); | ||
}); | ||
} | ||
} | ||
$triggerEl.addEventListener('click', function () { | ||
modal_1.object.toggle(); | ||
modal_1.toggle(); | ||
}); | ||
@@ -238,8 +244,6 @@ } | ||
if ($modalEl) { | ||
var modal_2 = getModalInstance(modalId, modalInstances); | ||
if (modal_2) { | ||
if (instances_1.default.instanceExists('Modal', $modalEl.getAttribute('id'))) { | ||
var modal_2 = instances_1.default.getInstance('Modal', $modalEl.getAttribute('id')); | ||
$triggerEl.addEventListener('click', function () { | ||
if (modal_2.object.isHidden) { | ||
modal_2.object.show(); | ||
} | ||
modal_2.show(); | ||
}); | ||
@@ -260,8 +264,6 @@ } | ||
if ($modalEl) { | ||
var modal_3 = getModalInstance(modalId, modalInstances); | ||
if (modal_3) { | ||
if (instances_1.default.instanceExists('Modal', $modalEl.getAttribute('id'))) { | ||
var modal_3 = instances_1.default.getInstance('Modal', $modalEl.getAttribute('id')); | ||
$triggerEl.addEventListener('click', function () { | ||
if (modal_3.object.isVisible) { | ||
modal_3.object.hide(); | ||
} | ||
modal_3.hide(); | ||
}); | ||
@@ -268,0 +270,0 @@ } |
@@ -9,3 +9,3 @@ import { ModalOptions } from './types'; | ||
_keydownEventListener: EventListenerOrEventListenerObject; | ||
_init(): void; | ||
init(): void; | ||
_createBackdrop(): void; | ||
@@ -21,3 +21,6 @@ _destroyBackdropEl(): void; | ||
isVisible(): boolean; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -13,6 +13,2 @@ import { ModalInterface } from './interface'; | ||
}; | ||
export declare type ModalInstance = { | ||
id: string; | ||
object: ModalInterface; | ||
}; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -12,4 +12,10 @@ import type { Instance as PopperInstance } from '@popperjs/core'; | ||
_visible: boolean; | ||
_initialized: boolean; | ||
_showHandler: EventListenerOrEventListenerObject; | ||
_hideHandler: EventListenerOrEventListenerObject; | ||
constructor(targetEl?: HTMLElement | null, triggerEl?: HTMLElement | null, options?: PopoverOptions); | ||
_init(): void; | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
_setupEventListeners(): void; | ||
@@ -16,0 +22,0 @@ _createPopperInstance(): PopperInstance; |
@@ -26,2 +26,3 @@ "use strict"; | ||
var core_1 = require("@popperjs/core"); | ||
var instances_1 = require("../../dom/instances"); | ||
var Default = { | ||
@@ -43,37 +44,66 @@ placement: 'top', | ||
this._options = __assign(__assign({}, Default), options); | ||
this._popperInstance = this._createPopperInstance(); | ||
this._popperInstance = null; | ||
this._visible = false; | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances_1.default.addInstance('Popover', this, this._targetEl.id, true); | ||
} | ||
Popover.prototype._init = function () { | ||
if (this._triggerEl) { | ||
Popover.prototype.init = function () { | ||
if (this._triggerEl && this._targetEl && !this._initialized) { | ||
this._setupEventListeners(); | ||
this._popperInstance = this._createPopperInstance(); | ||
this._initialized = true; | ||
} | ||
}; | ||
Popover.prototype.destroy = function () { | ||
var _this = this; | ||
if (this._initialized) { | ||
// remove event listeners associated with the trigger element and target element | ||
var triggerEvents = this._getTriggerEvents(); | ||
triggerEvents.showEvents.forEach(function (ev) { | ||
_this._triggerEl.removeEventListener(ev, _this._showHandler); | ||
_this._targetEl.removeEventListener(ev, _this._showHandler); | ||
}); | ||
triggerEvents.hideEvents.forEach(function (ev) { | ||
_this._triggerEl.removeEventListener(ev, _this._hideHandler); | ||
_this._targetEl.removeEventListener(ev, _this._hideHandler); | ||
}); | ||
// remove event listeners for keydown | ||
this._removeKeydownListener(); | ||
// remove event listeners for click outside | ||
this._removeClickOutsideListener(); | ||
// destroy the Popper instance if you have one (assuming this._popperInstance is the Popper instance) | ||
if (this._popperInstance) { | ||
this._popperInstance.destroy(); | ||
} | ||
this._initialized = false; | ||
} | ||
}; | ||
Popover.prototype.removeInstance = function () { | ||
instances_1.default.removeInstance('Popover', this._targetEl.id); | ||
}; | ||
Popover.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Popover.prototype._setupEventListeners = function () { | ||
var _this = this; | ||
var triggerEvents = this._getTriggerEvents(); | ||
this._showHandler = function () { | ||
_this.show(); | ||
}; | ||
this._hideHandler = function () { | ||
setTimeout(function () { | ||
if (!_this._targetEl.matches(':hover')) { | ||
_this.hide(); | ||
} | ||
}, 100); | ||
}; | ||
triggerEvents.showEvents.forEach(function (ev) { | ||
_this._triggerEl.addEventListener(ev, function () { | ||
_this.show(); | ||
}); | ||
_this._targetEl.addEventListener(ev, function () { | ||
_this.show(); | ||
}); | ||
_this._triggerEl.addEventListener(ev, _this._showHandler); | ||
_this._targetEl.addEventListener(ev, _this._showHandler); | ||
}); | ||
triggerEvents.hideEvents.forEach(function (ev) { | ||
_this._triggerEl.addEventListener(ev, function () { | ||
setTimeout(function () { | ||
if (!_this._targetEl.matches(':hover')) { | ||
_this.hide(); | ||
} | ||
}, 100); | ||
}); | ||
_this._targetEl.addEventListener(ev, function () { | ||
setTimeout(function () { | ||
if (!_this._triggerEl.matches(':hover')) { | ||
_this.hide(); | ||
} | ||
}, 100); | ||
}); | ||
_this._triggerEl.addEventListener(ev, _this._hideHandler); | ||
_this._targetEl.addEventListener(ev, _this._hideHandler); | ||
}); | ||
@@ -80,0 +110,0 @@ }; |
@@ -10,2 +10,3 @@ import { PopoverOptions, PopoverTriggerType, PopoverTriggerEventTypes } from './types'; | ||
_keydownEventListener: EventListenerOrEventListenerObject; | ||
init(): void; | ||
_setupEventListeners(): void; | ||
@@ -22,3 +23,6 @@ _setupClickOutsideListener(): void; | ||
toggle(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
import type { TabItem, TabsOptions } from './types'; | ||
import { TabsInterface } from './interface'; | ||
declare class Tabs implements TabsInterface { | ||
_accordionEl: HTMLElement; | ||
_items: TabItem[]; | ||
_activeTab: TabItem; | ||
_options: TabsOptions; | ||
constructor(items?: TabItem[], options?: TabsOptions); | ||
_init(): void; | ||
_initialized: boolean; | ||
constructor(accordionEl?: HTMLElement | null, items?: TabItem[], options?: TabsOptions); | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
getActiveTab(): TabItem; | ||
_setActiveTab(tab: TabItem): void; | ||
setActiveTab(tab: TabItem): void; | ||
getTab(id: string): TabItem; | ||
@@ -12,0 +17,0 @@ show(id: string, forceShow?: boolean): void; |
@@ -15,2 +15,3 @@ "use strict"; | ||
exports.initTabs = void 0; | ||
var instances_1 = require("../../dom/instances"); | ||
var Default = { | ||
@@ -23,16 +24,20 @@ defaultTabId: null, | ||
var Tabs = /** @class */ (function () { | ||
function Tabs(items, options) { | ||
function Tabs(accordionEl, items, options) { | ||
if (accordionEl === void 0) { accordionEl = null; } | ||
if (items === void 0) { items = []; } | ||
if (options === void 0) { options = Default; } | ||
this._accordionEl = accordionEl; | ||
this._items = items; | ||
this._activeTab = options ? this.getTab(options.defaultTabId) : null; | ||
this._options = __assign(__assign({}, Default), options); | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances_1.default.addInstance('Tabs', this, this._accordionEl.id, true); | ||
} | ||
Tabs.prototype._init = function () { | ||
Tabs.prototype.init = function () { | ||
var _this = this; | ||
if (this._items.length) { | ||
if (this._items.length && !this._initialized) { | ||
// set the first tab as active if not set by explicitly | ||
if (!this._activeTab) { | ||
this._setActiveTab(this._items[0]); | ||
this.setActiveTab(this._items[0]); | ||
} | ||
@@ -49,6 +54,19 @@ // force show the first default tab | ||
}; | ||
Tabs.prototype.destroy = function () { | ||
if (this._initialized) { | ||
this._initialized = false; | ||
} | ||
}; | ||
Tabs.prototype.removeInstance = function () { | ||
this.destroy(); | ||
instances_1.default.removeInstance('Tabs', this._accordionEl.id); | ||
}; | ||
Tabs.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Tabs.prototype.getActiveTab = function () { | ||
return this._activeTab; | ||
}; | ||
Tabs.prototype._setActiveTab = function (tab) { | ||
Tabs.prototype.setActiveTab = function (tab) { | ||
this._activeTab = tab; | ||
@@ -83,3 +101,3 @@ }; | ||
tab.targetEl.classList.remove('hidden'); | ||
this._setActiveTab(tab); | ||
this.setActiveTab(tab); | ||
// callback function | ||
@@ -91,6 +109,6 @@ this._options.onShow(this, tab); | ||
function initTabs() { | ||
document.querySelectorAll('[data-tabs-toggle]').forEach(function ($triggerEl) { | ||
document.querySelectorAll('[data-tabs-toggle]').forEach(function ($parentEl) { | ||
var tabItems = []; | ||
var defaultTabId = null; | ||
$triggerEl | ||
$parentEl | ||
.querySelectorAll('[role="tab"]') | ||
@@ -109,3 +127,3 @@ .forEach(function ($triggerEl) { | ||
}); | ||
new Tabs(tabItems, { | ||
new Tabs($parentEl, tabItems, { | ||
defaultTabId: defaultTabId, | ||
@@ -112,0 +130,0 @@ }); |
import { TabItem, TabsOptions } from './types'; | ||
export declare interface TabsInterface { | ||
_accordionEl: HTMLElement; | ||
_items: TabItem[]; | ||
_activeTab: TabItem; | ||
_options: TabsOptions; | ||
_init(): void; | ||
_setActiveTab(tab: TabItem): void; | ||
init(): void; | ||
setActiveTab(tab: TabItem): void; | ||
getActiveTab(): TabItem; | ||
getTab(id: string): TabItem; | ||
show(id: string, forceShow?: boolean): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -12,4 +12,10 @@ import type { Instance as PopperInstance } from '@popperjs/core'; | ||
_visible: boolean; | ||
_initialized: boolean; | ||
_showHandler: EventListenerOrEventListenerObject; | ||
_hideHandler: EventListenerOrEventListenerObject; | ||
constructor(targetEl?: HTMLElement | null, triggerEl?: HTMLElement | null, options?: TooltipOptions); | ||
_init(): void; | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
_setupEventListeners(): void; | ||
@@ -16,0 +22,0 @@ _createPopperInstance(): PopperInstance; |
@@ -26,2 +26,3 @@ "use strict"; | ||
var core_1 = require("@popperjs/core"); | ||
var instances_1 = require("../../dom/instances"); | ||
var Default = { | ||
@@ -42,23 +43,58 @@ placement: 'top', | ||
this._options = __assign(__assign({}, Default), options); | ||
this._popperInstance = this._createPopperInstance(); | ||
this._popperInstance = null; | ||
this._visible = false; | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances_1.default.addInstance('Tooltip', this, this._targetEl.id, true); | ||
} | ||
Tooltip.prototype._init = function () { | ||
if (this._triggerEl) { | ||
Tooltip.prototype.init = function () { | ||
if (this._triggerEl && this._targetEl && !this._initialized) { | ||
this._setupEventListeners(); | ||
this._popperInstance = this._createPopperInstance(); | ||
this._initialized = true; | ||
} | ||
}; | ||
Tooltip.prototype.destroy = function () { | ||
var _this = this; | ||
if (this._initialized) { | ||
// remove event listeners associated with the trigger element | ||
var triggerEvents = this._getTriggerEvents(); | ||
triggerEvents.showEvents.forEach(function (ev) { | ||
_this._triggerEl.removeEventListener(ev, _this._showHandler); | ||
}); | ||
triggerEvents.hideEvents.forEach(function (ev) { | ||
_this._triggerEl.removeEventListener(ev, _this._hideHandler); | ||
}); | ||
// remove event listeners for keydown | ||
this._removeKeydownListener(); | ||
// remove event listeners for click outside | ||
this._removeClickOutsideListener(); | ||
// destroy the Popper instance if you have one (assuming this._popperInstance is the Popper instance) | ||
if (this._popperInstance) { | ||
this._popperInstance.destroy(); | ||
} | ||
this._initialized = false; | ||
} | ||
}; | ||
Tooltip.prototype.removeInstance = function () { | ||
instances_1.default.removeInstance('Tooltip', this._targetEl.id); | ||
}; | ||
Tooltip.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Tooltip.prototype._setupEventListeners = function () { | ||
var _this = this; | ||
var triggerEvents = this._getTriggerEvents(); | ||
this._showHandler = function () { | ||
_this.show(); | ||
}; | ||
this._hideHandler = function () { | ||
_this.hide(); | ||
}; | ||
triggerEvents.showEvents.forEach(function (ev) { | ||
_this._triggerEl.addEventListener(ev, function () { | ||
_this.show(); | ||
}); | ||
_this._triggerEl.addEventListener(ev, _this._showHandler); | ||
}); | ||
triggerEvents.hideEvents.forEach(function (ev) { | ||
_this._triggerEl.addEventListener(ev, function () { | ||
_this.hide(); | ||
}); | ||
_this._triggerEl.addEventListener(ev, _this._hideHandler); | ||
}); | ||
@@ -65,0 +101,0 @@ }; |
@@ -10,3 +10,3 @@ import { TooltipOptions, TooltipTriggerType, TooltipTriggerEventTypes } from './types'; | ||
_keydownEventListener: EventListenerOrEventListenerObject; | ||
_init(): void; | ||
init(): void; | ||
_setupEventListeners(): void; | ||
@@ -23,3 +23,6 @@ _setupClickOutsideListener(): void; | ||
toggle(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -37,4 +37,5 @@ import Accordion from '../components/accordion'; | ||
initFlowbite: () => void; | ||
FlowbiteInstances: any; | ||
} | ||
} | ||
//# sourceMappingURL=global.d.ts.map |
import type { AccordionItem, AccordionOptions } from './types'; | ||
import { AccordionInterface } from './interface'; | ||
declare class Accordion implements AccordionInterface { | ||
_accordionEl: HTMLElement; | ||
_items: AccordionItem[]; | ||
_options: AccordionOptions; | ||
constructor(items?: AccordionItem[], options?: AccordionOptions); | ||
private _init; | ||
_clickHandler: EventListenerOrEventListenerObject; | ||
_initialized: boolean; | ||
constructor(accordionEl?: HTMLElement | null, items?: AccordionItem[], options?: AccordionOptions); | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
getItem(id: string): AccordionItem; | ||
@@ -9,0 +15,0 @@ open(id: string): void; |
@@ -12,2 +12,3 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
import instances from '../../dom/instances'; | ||
var Default = { | ||
@@ -22,23 +23,48 @@ alwaysOpen: false, | ||
var Accordion = /** @class */ (function () { | ||
function Accordion(items, options) { | ||
function Accordion(accordionEl, items, options) { | ||
if (accordionEl === void 0) { accordionEl = null; } | ||
if (items === void 0) { items = []; } | ||
if (options === void 0) { options = Default; } | ||
this._accordionEl = accordionEl; | ||
this._items = items; | ||
this._options = __assign(__assign({}, Default), options); | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances.addInstance('Accordion', this, this._accordionEl.id, true); | ||
} | ||
Accordion.prototype._init = function () { | ||
Accordion.prototype.init = function () { | ||
var _this = this; | ||
if (this._items.length) { | ||
if (this._items.length && !this._initialized) { | ||
// show accordion item based on click | ||
this._items.map(function (item) { | ||
this._items.forEach(function (item) { | ||
if (item.active) { | ||
_this.open(item.id); | ||
} | ||
item.triggerEl.addEventListener('click', function () { | ||
var clickHandler = function () { | ||
_this.toggle(item.id); | ||
}); | ||
}; | ||
item.triggerEl.addEventListener('click', clickHandler); | ||
// Store the clickHandler in a property of the item for removal later | ||
item.clickHandler = clickHandler; | ||
}); | ||
this._initialized = true; | ||
} | ||
}; | ||
Accordion.prototype.destroy = function () { | ||
if (this._items.length && this._initialized) { | ||
this._items.forEach(function (item) { | ||
item.triggerEl.removeEventListener('click', item.clickHandler); | ||
// Clean up by deleting the clickHandler property from the item | ||
delete item.clickHandler; | ||
}); | ||
this._initialized = false; | ||
} | ||
}; | ||
Accordion.prototype.removeInstance = function () { | ||
instances.removeInstance('Accordion', this._accordionEl.id); | ||
}; | ||
Accordion.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Accordion.prototype.getItem = function (id) { | ||
@@ -133,3 +159,3 @@ return this._items.filter(function (item) { return item.id === id; })[0]; | ||
}); | ||
new Accordion(items, { | ||
new Accordion($accordionEl, items, { | ||
alwaysOpen: alwaysOpen === 'open' ? true : false, | ||
@@ -136,0 +162,0 @@ activeClasses: activeClasses |
@@ -9,3 +9,6 @@ import { AccordionItem, AccordionOptions } from './types'; | ||
close(id: string): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -8,2 +8,3 @@ import { AccordionInterface } from './interface'; | ||
active?: boolean; | ||
clickHandler?: EventListenerOrEventListenerObject; | ||
}; | ||
@@ -10,0 +11,0 @@ export declare type AccordionOptions = { |
import type { CarouselOptions, CarouselItem, IndicatorItem, RotationItems } from './types'; | ||
import { CarouselInterface } from './interface'; | ||
declare class Carousel implements CarouselInterface { | ||
_carouselEl: HTMLElement; | ||
_items: CarouselItem[]; | ||
@@ -10,7 +11,11 @@ _indicators: IndicatorItem[]; | ||
_options: CarouselOptions; | ||
constructor(items?: CarouselItem[], options?: CarouselOptions); | ||
_initialized: boolean; | ||
constructor(carouselEl?: HTMLElement | null, items?: CarouselItem[], options?: CarouselOptions); | ||
/** | ||
* initialize carousel and items based on active one | ||
*/ | ||
_init(): void; | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
getItem(position: number): CarouselItem; | ||
@@ -17,0 +22,0 @@ /** |
@@ -12,2 +12,3 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
import instances from '../../dom/instances'; | ||
var Default = { | ||
@@ -26,5 +27,7 @@ defaultPosition: 0, | ||
var Carousel = /** @class */ (function () { | ||
function Carousel(items, options) { | ||
function Carousel(carouselEl, items, options) { | ||
if (carouselEl === void 0) { carouselEl = null; } | ||
if (items === void 0) { items = []; } | ||
if (options === void 0) { options = Default; } | ||
this._carouselEl = carouselEl; | ||
this._items = items; | ||
@@ -36,3 +39,5 @@ this._options = __assign(__assign(__assign({}, Default), options), { indicators: __assign(__assign({}, Default.indicators), options.indicators) }); | ||
this._intervalInstance = null; | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances.addInstance('Carousel', this, this._carouselEl.id, true); | ||
} | ||
@@ -42,20 +47,35 @@ /** | ||
*/ | ||
Carousel.prototype._init = function () { | ||
Carousel.prototype.init = function () { | ||
var _this = this; | ||
this._items.map(function (item) { | ||
item.el.classList.add('absolute', 'inset-0', 'transition-transform', 'transform'); | ||
}); | ||
// if no active item is set then first position is default | ||
if (this._getActiveItem()) { | ||
this.slideTo(this._getActiveItem().position); | ||
if (this._items.length && !this._initialized) { | ||
this._items.map(function (item) { | ||
item.el.classList.add('absolute', 'inset-0', 'transition-transform', 'transform'); | ||
}); | ||
// if no active item is set then first position is default | ||
if (this._getActiveItem()) { | ||
this.slideTo(this._getActiveItem().position); | ||
} | ||
else { | ||
this.slideTo(0); | ||
} | ||
this._indicators.map(function (indicator, position) { | ||
indicator.el.addEventListener('click', function () { | ||
_this.slideTo(position); | ||
}); | ||
}); | ||
this._initialized = true; | ||
} | ||
else { | ||
this.slideTo(0); | ||
}; | ||
Carousel.prototype.destroy = function () { | ||
if (this._initialized) { | ||
this._initialized = false; | ||
} | ||
this._indicators.map(function (indicator, position) { | ||
indicator.el.addEventListener('click', function () { | ||
_this.slideTo(position); | ||
}); | ||
}); | ||
}; | ||
Carousel.prototype.removeInstance = function () { | ||
instances.removeInstance('Carousel', this._carouselEl.id); | ||
}; | ||
Carousel.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Carousel.prototype.getItem = function (position) { | ||
@@ -216,3 +236,3 @@ return this._items[position]; | ||
} | ||
var carousel = new Carousel(items, { | ||
var carousel = new Carousel($carouselEl, items, { | ||
defaultPosition: defaultPosition, | ||
@@ -219,0 +239,0 @@ indicators: { |
@@ -9,3 +9,3 @@ import { CarouselOptions, CarouselItem, IndicatorItem, RotationItems } from './types'; | ||
_options: CarouselOptions; | ||
_init(): void; | ||
init(): void; | ||
getItem(position: number): CarouselItem; | ||
@@ -20,3 +20,6 @@ _getActiveItem(): CarouselItem; | ||
pause(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -8,4 +8,9 @@ import type { CollapseOptions } from './types'; | ||
_visible: boolean; | ||
_initialized: boolean; | ||
_clickHandler: EventListenerOrEventListenerObject; | ||
constructor(targetEl?: HTMLElement | null, triggerEl?: HTMLElement | null, options?: CollapseOptions); | ||
_init(): void; | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
collapse(): void; | ||
@@ -12,0 +17,0 @@ expand(): void; |
@@ -12,2 +12,3 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
import instances from '../../dom/instances'; | ||
var Default = { | ||
@@ -27,7 +28,9 @@ onCollapse: function () { }, | ||
this._visible = false; | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances.addInstance('Collapse', this, this._targetEl.id, true); | ||
} | ||
Collapse.prototype._init = function () { | ||
Collapse.prototype.init = function () { | ||
var _this = this; | ||
if (this._triggerEl) { | ||
if (this._triggerEl && this._targetEl && !this._initialized) { | ||
if (this._triggerEl.hasAttribute('aria-expanded')) { | ||
@@ -41,7 +44,22 @@ this._visible = | ||
} | ||
this._triggerEl.addEventListener('click', function () { | ||
this._clickHandler = function () { | ||
_this.toggle(); | ||
}); | ||
}; | ||
this._triggerEl.addEventListener('click', this._clickHandler); | ||
this._initialized = true; | ||
} | ||
}; | ||
Collapse.prototype.destroy = function () { | ||
if (this._triggerEl && this._initialized) { | ||
this._triggerEl.removeEventListener('click', this._clickHandler); | ||
this._initialized = false; | ||
} | ||
}; | ||
Collapse.prototype.removeInstance = function () { | ||
instances.removeInstance('Collapse', this._targetEl.id); | ||
}; | ||
Collapse.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Collapse.prototype.collapse = function () { | ||
@@ -48,0 +66,0 @@ this._targetEl.classList.add('hidden'); |
@@ -7,7 +7,10 @@ import { CollapseOptions } from './types'; | ||
_visible: boolean; | ||
_init(): void; | ||
init(): void; | ||
collapse(): void; | ||
expand(): void; | ||
toggle(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -9,4 +9,10 @@ import type { DialOptions, DialTriggerType } from './types'; | ||
_visible: boolean; | ||
_initialized: boolean; | ||
_showEventHandler: EventListenerOrEventListenerObject; | ||
_hideEventHandler: EventListenerOrEventListenerObject; | ||
constructor(parentEl?: HTMLElement | null, triggerEl?: HTMLElement | null, targetEl?: HTMLElement | null, options?: DialOptions); | ||
_init(): void; | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
hide(): void; | ||
@@ -13,0 +19,0 @@ show(): void; |
@@ -12,2 +12,3 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
import instances from '../../dom/instances'; | ||
var Default = { | ||
@@ -30,25 +31,49 @@ triggerType: 'hover', | ||
this._visible = false; | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances.addInstance('Dial', this, this._targetEl.id, true); | ||
} | ||
Dial.prototype._init = function () { | ||
Dial.prototype.init = function () { | ||
var _this = this; | ||
if (this._triggerEl) { | ||
if (this._triggerEl && this._targetEl && !this._initialized) { | ||
var triggerEventTypes = this._getTriggerEventTypes(this._options.triggerType); | ||
this._showEventHandler = function () { | ||
_this.show(); | ||
}; | ||
triggerEventTypes.showEvents.forEach(function (ev) { | ||
_this._triggerEl.addEventListener(ev, function () { | ||
_this.show(); | ||
}); | ||
_this._targetEl.addEventListener(ev, function () { | ||
_this.show(); | ||
}); | ||
_this._triggerEl.addEventListener(ev, _this._showEventHandler); | ||
_this._targetEl.addEventListener(ev, _this._showEventHandler); | ||
}); | ||
this._hideEventHandler = function () { | ||
if (!_this._parentEl.matches(':hover')) { | ||
_this.hide(); | ||
} | ||
}; | ||
triggerEventTypes.hideEvents.forEach(function (ev) { | ||
_this._parentEl.addEventListener(ev, function () { | ||
if (!_this._parentEl.matches(':hover')) { | ||
_this.hide(); | ||
} | ||
}); | ||
_this._parentEl.addEventListener(ev, _this._hideEventHandler); | ||
}); | ||
this._initialized = true; | ||
} | ||
}; | ||
Dial.prototype.destroy = function () { | ||
var _this = this; | ||
if (this._initialized) { | ||
var triggerEventTypes = this._getTriggerEventTypes(this._options.triggerType); | ||
triggerEventTypes.showEvents.forEach(function (ev) { | ||
_this._triggerEl.removeEventListener(ev, _this._showEventHandler); | ||
_this._targetEl.removeEventListener(ev, _this._showEventHandler); | ||
}); | ||
triggerEventTypes.hideEvents.forEach(function (ev) { | ||
_this._parentEl.removeEventListener(ev, _this._hideEventHandler); | ||
}); | ||
this._initialized = false; | ||
} | ||
}; | ||
Dial.prototype.removeInstance = function () { | ||
instances.removeInstance('Dial', this._targetEl.id); | ||
}; | ||
Dial.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Dial.prototype.hide = function () { | ||
@@ -55,0 +80,0 @@ this._targetEl.classList.add('hidden'); |
@@ -8,3 +8,3 @@ import { DialOptions, DialTriggerEventTypes, DialTriggerType } from './types'; | ||
_visible: boolean; | ||
_init(): void; | ||
init(): void; | ||
isVisible(): boolean; | ||
@@ -16,3 +16,6 @@ isHidden(): boolean; | ||
_getTriggerEventTypes(triggerType: DialTriggerType): DialTriggerEventTypes; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -7,4 +7,9 @@ import type { DismissOptions } from './types'; | ||
_options: DismissOptions; | ||
_initialized: boolean; | ||
_clickHandler: EventListenerOrEventListenerObject; | ||
constructor(targetEl?: HTMLElement | null, triggerEl?: HTMLElement | null, options?: DismissOptions); | ||
_init(): void; | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
hide(): void; | ||
@@ -11,0 +16,0 @@ } |
@@ -12,2 +12,3 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
import instances from '../../dom/instances'; | ||
var Default = { | ||
@@ -27,12 +28,29 @@ transition: 'transition-opacity', | ||
this._options = __assign(__assign({}, Default), options); | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances.addInstance('Dismiss', this, this._targetEl.id, true); | ||
} | ||
Dismiss.prototype._init = function () { | ||
Dismiss.prototype.init = function () { | ||
var _this = this; | ||
if (this._triggerEl) { | ||
this._triggerEl.addEventListener('click', function () { | ||
if (this._triggerEl && this._targetEl && !this._initialized) { | ||
this._clickHandler = function () { | ||
_this.hide(); | ||
}); | ||
}; | ||
this._triggerEl.addEventListener('click', this._clickHandler); | ||
this._initialized = true; | ||
} | ||
}; | ||
Dismiss.prototype.destroy = function () { | ||
if (this._triggerEl && this._initialized) { | ||
this._triggerEl.removeEventListener('click', this._clickHandler); | ||
this._initialized = false; | ||
} | ||
}; | ||
Dismiss.prototype.removeInstance = function () { | ||
instances.removeInstance('Dismiss', this._targetEl.id); | ||
}; | ||
Dismiss.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Dismiss.prototype.hide = function () { | ||
@@ -39,0 +57,0 @@ var _this = this; |
@@ -6,5 +6,8 @@ import { DismissOptions } from './types'; | ||
_options: DismissOptions; | ||
_init(): void; | ||
init(): void; | ||
hide(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -8,4 +8,9 @@ import type { DrawerOptions, PlacementClasses } from './types'; | ||
_visible: boolean; | ||
_initialized: boolean; | ||
_handleEscapeKey: EventListenerOrEventListenerObject; | ||
constructor(targetEl?: HTMLElement | null, options?: DrawerOptions); | ||
_init(): void; | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
hide(): void; | ||
@@ -12,0 +17,0 @@ show(): void; |
@@ -12,2 +12,3 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
import instances from '../../dom/instances'; | ||
var Default = { | ||
@@ -31,26 +32,45 @@ placement: 'left', | ||
this._visible = false; | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances.addInstance('Drawer', this, this._targetEl.id, true); | ||
} | ||
Drawer.prototype._init = function () { | ||
Drawer.prototype.init = function () { | ||
var _this = this; | ||
// set initial accessibility attributes | ||
if (this._targetEl) { | ||
if (this._targetEl && !this._initialized) { | ||
this._targetEl.setAttribute('aria-hidden', 'true'); | ||
this._targetEl.classList.add('transition-transform'); | ||
// set base placement classes | ||
this._getPlacementClasses(this._options.placement).base.map(function (c) { | ||
_this._targetEl.classList.add(c); | ||
}); | ||
this._handleEscapeKey = function (event) { | ||
if (event.key === 'Escape') { | ||
// if 'Escape' key is pressed | ||
if (_this.isVisible()) { | ||
// if the Drawer is visible | ||
_this.hide(); // hide the Drawer | ||
} | ||
} | ||
}; | ||
// add keyboard event listener to document | ||
document.addEventListener('keydown', this._handleEscapeKey); | ||
this._initialized = true; | ||
} | ||
// set base placement classes | ||
this._getPlacementClasses(this._options.placement).base.map(function (c) { | ||
_this._targetEl.classList.add(c); | ||
}); | ||
// add keyboard event listener to document | ||
document.addEventListener('keydown', function (event) { | ||
if (event.key === 'Escape') { | ||
// if 'Escape' key is pressed | ||
if (_this.isVisible()) { | ||
// if the Drawer is visible | ||
_this.hide(); // hide the Drawer | ||
} | ||
} | ||
}); | ||
}; | ||
Drawer.prototype.destroy = function () { | ||
if (this._initialized) { | ||
this.hide(); | ||
// Remove the keyboard event listener | ||
document.removeEventListener('keydown', this._handleEscapeKey); | ||
this._initialized = false; | ||
} | ||
}; | ||
Drawer.prototype.removeInstance = function () { | ||
instances.removeInstance('Drawer', this._targetEl.id); | ||
}; | ||
Drawer.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Drawer.prototype.hide = function () { | ||
@@ -199,9 +219,3 @@ var _this = this; | ||
}()); | ||
var getDrawerInstance = function (id, instances) { | ||
if (instances.some(function (drawerInstance) { return drawerInstance.id === id; })) { | ||
return instances.find(function (drawerInstance) { return drawerInstance.id === id; }); | ||
} | ||
}; | ||
export function initDrawers() { | ||
var drawerInstances = []; | ||
document.querySelectorAll('[data-drawer-target]').forEach(function ($triggerEl) { | ||
@@ -218,26 +232,21 @@ // mandatory | ||
var edgeOffset = $triggerEl.getAttribute('data-drawer-edge-offset'); | ||
if (!getDrawerInstance(drawerId, drawerInstances)) { | ||
drawerInstances.push({ | ||
id: drawerId, | ||
object: new Drawer($drawerEl, { | ||
placement: placement ? placement : Default.placement, | ||
bodyScrolling: bodyScrolling | ||
? bodyScrolling === 'true' | ||
? true | ||
: false | ||
: Default.bodyScrolling, | ||
backdrop: backdrop | ||
? backdrop === 'true' | ||
? true | ||
: false | ||
: Default.backdrop, | ||
edge: edge | ||
? edge === 'true' | ||
? true | ||
: false | ||
: Default.edge, | ||
edgeOffset: edgeOffset | ||
? edgeOffset | ||
: Default.edgeOffset, | ||
}), | ||
if (!instances.instanceExists('Drawer', $drawerEl.getAttribute('id'))) { | ||
new Drawer($drawerEl, { | ||
placement: placement ? placement : Default.placement, | ||
bodyScrolling: bodyScrolling | ||
? bodyScrolling === 'true' | ||
? true | ||
: false | ||
: Default.bodyScrolling, | ||
backdrop: backdrop | ||
? backdrop === 'true' | ||
? true | ||
: false | ||
: Default.backdrop, | ||
edge: edge | ||
? edge === 'true' | ||
? true | ||
: false | ||
: Default.edge, | ||
edgeOffset: edgeOffset ? edgeOffset : Default.edgeOffset, | ||
}); | ||
@@ -254,6 +263,6 @@ } | ||
if ($drawerEl) { | ||
var drawer_1 = getDrawerInstance(drawerId, drawerInstances); | ||
var drawer_1 = instances.getInstance('Drawer', $drawerEl.getAttribute('id')); | ||
if (drawer_1) { | ||
$triggerEl.addEventListener('click', function () { | ||
drawer_1.object.toggle(); | ||
drawer_1.toggle(); | ||
}); | ||
@@ -277,6 +286,6 @@ } | ||
if ($drawerEl) { | ||
var drawer_2 = getDrawerInstance(drawerId, drawerInstances); | ||
var drawer_2 = instances.getInstance('Drawer', $drawerEl.getAttribute('id')); | ||
if (drawer_2) { | ||
$triggerEl.addEventListener('click', function () { | ||
drawer_2.object.hide(); | ||
drawer_2.hide(); | ||
}); | ||
@@ -296,6 +305,6 @@ } | ||
if ($drawerEl) { | ||
var drawer_3 = getDrawerInstance(drawerId, drawerInstances); | ||
var drawer_3 = instances.getInstance('Drawer', $drawerEl.getAttribute('id')); | ||
if (drawer_3) { | ||
$triggerEl.addEventListener('click', function () { | ||
drawer_3.object.show(); | ||
drawer_3.show(); | ||
}); | ||
@@ -302,0 +311,0 @@ } |
@@ -7,3 +7,3 @@ import { DrawerOptions, PlacementClasses } from './types'; | ||
_visible: boolean; | ||
_init(): void; | ||
init(): void; | ||
isVisible(): boolean; | ||
@@ -17,3 +17,6 @@ isHidden(): boolean; | ||
_getPlacementClasses(placement: string): PlacementClasses; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -18,6 +18,2 @@ import { DrawerInterface } from './interface'; | ||
}; | ||
export declare type DrawerInstance = { | ||
id: string; | ||
object: DrawerInterface; | ||
}; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -10,5 +10,13 @@ import type { Instance as PopperInstance } from '@popperjs/core'; | ||
_popperInstance: PopperInstance; | ||
_initialized: boolean; | ||
_clickOutsideEventListener: EventListenerOrEventListenerObject; | ||
_hoverShowTriggerElHandler: EventListenerOrEventListenerObject; | ||
_hoverShowTargetElHandler: EventListenerOrEventListenerObject; | ||
_hoverHideHandler: EventListenerOrEventListenerObject; | ||
_clickHandler: EventListenerOrEventListenerObject; | ||
constructor(targetElement?: HTMLElement | null, triggerElement?: HTMLElement | null, options?: DropdownOptions); | ||
_init(): void; | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
_setupEventListeners(): void; | ||
@@ -15,0 +23,0 @@ _createPopperInstance(): PopperInstance; |
@@ -23,2 +23,3 @@ var __assign = (this && this.__assign) || function () { | ||
import { createPopper } from '@popperjs/core'; | ||
import instances from '../../dom/instances'; | ||
var Default = { | ||
@@ -43,54 +44,86 @@ placement: 'bottom', | ||
this._options = __assign(__assign({}, Default), options); | ||
this._popperInstance = this._createPopperInstance(); | ||
this._popperInstance = null; | ||
this._visible = false; | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances.addInstance('Dropdown', this, this._targetEl.id, true); | ||
} | ||
Dropdown.prototype._init = function () { | ||
if (this._triggerEl) { | ||
Dropdown.prototype.init = function () { | ||
if (this._triggerEl && this._targetEl && !this._initialized) { | ||
this._popperInstance = this._createPopperInstance(); | ||
this._setupEventListeners(); | ||
this._initialized = true; | ||
} | ||
}; | ||
Dropdown.prototype.destroy = function () { | ||
var _this = this; | ||
var triggerEvents = this._getTriggerEvents(); | ||
// Remove click event listeners for trigger element | ||
if (this._options.triggerType === 'click') { | ||
triggerEvents.showEvents.forEach(function (ev) { | ||
_this._triggerEl.removeEventListener(ev, _this._clickHandler); | ||
}); | ||
} | ||
// Remove hover event listeners for trigger and target elements | ||
if (this._options.triggerType === 'hover') { | ||
triggerEvents.showEvents.forEach(function (ev) { | ||
_this._triggerEl.removeEventListener(ev, _this._hoverShowTriggerElHandler); | ||
_this._targetEl.removeEventListener(ev, _this._hoverShowTargetElHandler); | ||
}); | ||
triggerEvents.hideEvents.forEach(function (ev) { | ||
_this._triggerEl.removeEventListener(ev, _this._hoverHideHandler); | ||
_this._targetEl.removeEventListener(ev, _this._hoverHideHandler); | ||
}); | ||
} | ||
this._popperInstance.destroy(); | ||
this._initialized = false; | ||
}; | ||
Dropdown.prototype.removeInstance = function () { | ||
instances.removeInstance('Dropdown', this._targetEl.id); | ||
}; | ||
Dropdown.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Dropdown.prototype._setupEventListeners = function () { | ||
var _this = this; | ||
var triggerEvents = this._getTriggerEvents(); | ||
this._clickHandler = function () { | ||
_this.toggle(); | ||
}; | ||
// click event handling for trigger element | ||
if (this._options.triggerType === 'click') { | ||
triggerEvents.showEvents.forEach(function (ev) { | ||
_this._triggerEl.addEventListener(ev, function () { | ||
_this.toggle(); | ||
}); | ||
_this._triggerEl.addEventListener(ev, _this._clickHandler); | ||
}); | ||
} | ||
this._hoverShowTriggerElHandler = function (ev) { | ||
if (ev.type === 'click') { | ||
_this.toggle(); | ||
} | ||
else { | ||
setTimeout(function () { | ||
_this.show(); | ||
}, _this._options.delay); | ||
} | ||
}; | ||
this._hoverShowTargetElHandler = function () { | ||
_this.show(); | ||
}; | ||
this._hoverHideHandler = function () { | ||
setTimeout(function () { | ||
if (!_this._targetEl.matches(':hover')) { | ||
_this.hide(); | ||
} | ||
}, _this._options.delay); | ||
}; | ||
// hover event handling for trigger element | ||
if (this._options.triggerType === 'hover') { | ||
triggerEvents.showEvents.forEach(function (ev) { | ||
_this._triggerEl.addEventListener(ev, function () { | ||
if (ev === 'click') { | ||
_this.toggle(); | ||
} | ||
else { | ||
setTimeout(function () { | ||
_this.show(); | ||
}, _this._options.delay); | ||
} | ||
}); | ||
_this._targetEl.addEventListener(ev, function () { | ||
_this.show(); | ||
}); | ||
_this._triggerEl.addEventListener(ev, _this._hoverShowTriggerElHandler); | ||
_this._targetEl.addEventListener(ev, _this._hoverShowTargetElHandler); | ||
}); | ||
triggerEvents.hideEvents.forEach(function (ev) { | ||
_this._triggerEl.addEventListener(ev, function () { | ||
setTimeout(function () { | ||
if (!_this._targetEl.matches(':hover')) { | ||
_this.hide(); | ||
} | ||
}, _this._options.delay); | ||
}); | ||
_this._targetEl.addEventListener(ev, function () { | ||
setTimeout(function () { | ||
if (!_this._triggerEl.matches(':hover')) { | ||
_this.hide(); | ||
} | ||
}, _this._options.delay); | ||
}); | ||
_this._triggerEl.addEventListener(ev, _this._hoverHideHandler); | ||
_this._targetEl.addEventListener(ev, _this._hoverHideHandler); | ||
}); | ||
@@ -97,0 +130,0 @@ } |
@@ -9,4 +9,5 @@ import { DropdownOptions, DropdownTriggerType, DropdownTriggerEventTypes } from './types'; | ||
_popperInstance: PopperInstance; | ||
_initialized: boolean; | ||
_clickOutsideEventListener: EventListenerOrEventListenerObject; | ||
_init(): void; | ||
init(): void; | ||
_createPopperInstance(): PopperInstance; | ||
@@ -22,3 +23,6 @@ _setupEventListeners(): void; | ||
hide(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -10,4 +10,8 @@ import type { ModalOptions } from './types'; | ||
_keydownEventListener: EventListenerOrEventListenerObject; | ||
_initialized: boolean; | ||
constructor(targetEl?: HTMLElement | null, options?: ModalOptions); | ||
_init(): void; | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
_createBackdrop(): void; | ||
@@ -14,0 +18,0 @@ _destroyBackdropEl(): void; |
@@ -12,2 +12,3 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
import instances from '../../dom/instances'; | ||
var Default = { | ||
@@ -30,12 +31,28 @@ placement: 'center', | ||
this._backdropEl = null; | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances.addInstance('Modal', this, this._targetEl.id, true); | ||
} | ||
Modal.prototype._init = function () { | ||
Modal.prototype.init = function () { | ||
var _this = this; | ||
if (this._targetEl) { | ||
if (this._targetEl && !this._initialized) { | ||
this._getPlacementClasses().map(function (c) { | ||
_this._targetEl.classList.add(c); | ||
}); | ||
this._initialized = true; | ||
} | ||
}; | ||
Modal.prototype.destroy = function () { | ||
if (this._initialized) { | ||
this.hide(); | ||
this._initialized = false; | ||
} | ||
}; | ||
Modal.prototype.removeInstance = function () { | ||
instances.removeInstance('Modal', this._targetEl.id); | ||
}; | ||
Modal.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Modal.prototype._createBackdrop = function () { | ||
@@ -129,4 +146,2 @@ var _a; | ||
this._isHidden = false; | ||
// prevent body scroll | ||
document.body.classList.add('overflow-hidden'); | ||
// Add keyboard event listener to the document | ||
@@ -136,2 +151,4 @@ if (this._options.closable) { | ||
} | ||
// prevent body scroll | ||
document.body.classList.add('overflow-hidden'); | ||
// callback function | ||
@@ -167,10 +184,3 @@ this._options.onShow(this); | ||
}()); | ||
var getModalInstance = function (id, instances) { | ||
if (instances.some(function (modalInstance) { return modalInstance.id === id; })) { | ||
return instances.find(function (modalInstance) { return modalInstance.id === id; }); | ||
} | ||
return null; | ||
}; | ||
export function initModals() { | ||
var modalInstances = []; | ||
// initiate modal based on data-modal-target | ||
@@ -183,11 +193,6 @@ document.querySelectorAll('[data-modal-target]').forEach(function ($triggerEl) { | ||
var backdrop = $modalEl.getAttribute('data-modal-backdrop'); | ||
if (!getModalInstance(modalId, modalInstances)) { | ||
modalInstances.push({ | ||
id: modalId, | ||
object: new Modal($modalEl, { | ||
placement: placement | ||
? placement | ||
: Default.placement, | ||
backdrop: backdrop ? backdrop : Default.backdrop, | ||
}), | ||
if (instances.instanceExists('Modal', $modalEl.getAttribute('id'))) { | ||
new Modal($modalEl, { | ||
placement: placement ? placement : Default.placement, | ||
backdrop: backdrop ? backdrop : Default.backdrop, | ||
}); | ||
@@ -207,7 +212,9 @@ } | ||
var backdrop = $modalEl.getAttribute('data-modal-backdrop'); | ||
var modal_1 = getModalInstance(modalId, modalInstances); | ||
if (!modal_1) { | ||
modal_1 = { | ||
id: modalId, | ||
object: new Modal($modalEl, { | ||
var modal_1; | ||
if (instances.instanceExists('Modal', $modalEl.getAttribute('id'))) { | ||
modal_1 = instances.getInstance('Modal', $modalEl.getAttribute('id')); | ||
} | ||
else { | ||
{ | ||
modal_1 = new Modal($modalEl, { | ||
placement: placement | ||
@@ -217,8 +224,7 @@ ? placement | ||
backdrop: backdrop ? backdrop : Default.backdrop, | ||
}), | ||
}; | ||
modalInstances.push(modal_1); | ||
}); | ||
} | ||
} | ||
$triggerEl.addEventListener('click', function () { | ||
modal_1.object.toggle(); | ||
modal_1.toggle(); | ||
}); | ||
@@ -235,8 +241,6 @@ } | ||
if ($modalEl) { | ||
var modal_2 = getModalInstance(modalId, modalInstances); | ||
if (modal_2) { | ||
if (instances.instanceExists('Modal', $modalEl.getAttribute('id'))) { | ||
var modal_2 = instances.getInstance('Modal', $modalEl.getAttribute('id')); | ||
$triggerEl.addEventListener('click', function () { | ||
if (modal_2.object.isHidden) { | ||
modal_2.object.show(); | ||
} | ||
modal_2.show(); | ||
}); | ||
@@ -257,8 +261,6 @@ } | ||
if ($modalEl) { | ||
var modal_3 = getModalInstance(modalId, modalInstances); | ||
if (modal_3) { | ||
if (instances.instanceExists('Modal', $modalEl.getAttribute('id'))) { | ||
var modal_3 = instances.getInstance('Modal', $modalEl.getAttribute('id')); | ||
$triggerEl.addEventListener('click', function () { | ||
if (modal_3.object.isVisible) { | ||
modal_3.object.hide(); | ||
} | ||
modal_3.hide(); | ||
}); | ||
@@ -265,0 +267,0 @@ } |
@@ -9,3 +9,3 @@ import { ModalOptions } from './types'; | ||
_keydownEventListener: EventListenerOrEventListenerObject; | ||
_init(): void; | ||
init(): void; | ||
_createBackdrop(): void; | ||
@@ -21,3 +21,6 @@ _destroyBackdropEl(): void; | ||
isVisible(): boolean; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -13,6 +13,2 @@ import { ModalInterface } from './interface'; | ||
}; | ||
export declare type ModalInstance = { | ||
id: string; | ||
object: ModalInterface; | ||
}; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -12,4 +12,10 @@ import type { Instance as PopperInstance } from '@popperjs/core'; | ||
_visible: boolean; | ||
_initialized: boolean; | ||
_showHandler: EventListenerOrEventListenerObject; | ||
_hideHandler: EventListenerOrEventListenerObject; | ||
constructor(targetEl?: HTMLElement | null, triggerEl?: HTMLElement | null, options?: PopoverOptions); | ||
_init(): void; | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
_setupEventListeners(): void; | ||
@@ -16,0 +22,0 @@ _createPopperInstance(): PopperInstance; |
@@ -23,2 +23,3 @@ var __assign = (this && this.__assign) || function () { | ||
import { createPopper } from '@popperjs/core'; | ||
import instances from '../../dom/instances'; | ||
var Default = { | ||
@@ -40,37 +41,66 @@ placement: 'top', | ||
this._options = __assign(__assign({}, Default), options); | ||
this._popperInstance = this._createPopperInstance(); | ||
this._popperInstance = null; | ||
this._visible = false; | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances.addInstance('Popover', this, this._targetEl.id, true); | ||
} | ||
Popover.prototype._init = function () { | ||
if (this._triggerEl) { | ||
Popover.prototype.init = function () { | ||
if (this._triggerEl && this._targetEl && !this._initialized) { | ||
this._setupEventListeners(); | ||
this._popperInstance = this._createPopperInstance(); | ||
this._initialized = true; | ||
} | ||
}; | ||
Popover.prototype.destroy = function () { | ||
var _this = this; | ||
if (this._initialized) { | ||
// remove event listeners associated with the trigger element and target element | ||
var triggerEvents = this._getTriggerEvents(); | ||
triggerEvents.showEvents.forEach(function (ev) { | ||
_this._triggerEl.removeEventListener(ev, _this._showHandler); | ||
_this._targetEl.removeEventListener(ev, _this._showHandler); | ||
}); | ||
triggerEvents.hideEvents.forEach(function (ev) { | ||
_this._triggerEl.removeEventListener(ev, _this._hideHandler); | ||
_this._targetEl.removeEventListener(ev, _this._hideHandler); | ||
}); | ||
// remove event listeners for keydown | ||
this._removeKeydownListener(); | ||
// remove event listeners for click outside | ||
this._removeClickOutsideListener(); | ||
// destroy the Popper instance if you have one (assuming this._popperInstance is the Popper instance) | ||
if (this._popperInstance) { | ||
this._popperInstance.destroy(); | ||
} | ||
this._initialized = false; | ||
} | ||
}; | ||
Popover.prototype.removeInstance = function () { | ||
instances.removeInstance('Popover', this._targetEl.id); | ||
}; | ||
Popover.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Popover.prototype._setupEventListeners = function () { | ||
var _this = this; | ||
var triggerEvents = this._getTriggerEvents(); | ||
this._showHandler = function () { | ||
_this.show(); | ||
}; | ||
this._hideHandler = function () { | ||
setTimeout(function () { | ||
if (!_this._targetEl.matches(':hover')) { | ||
_this.hide(); | ||
} | ||
}, 100); | ||
}; | ||
triggerEvents.showEvents.forEach(function (ev) { | ||
_this._triggerEl.addEventListener(ev, function () { | ||
_this.show(); | ||
}); | ||
_this._targetEl.addEventListener(ev, function () { | ||
_this.show(); | ||
}); | ||
_this._triggerEl.addEventListener(ev, _this._showHandler); | ||
_this._targetEl.addEventListener(ev, _this._showHandler); | ||
}); | ||
triggerEvents.hideEvents.forEach(function (ev) { | ||
_this._triggerEl.addEventListener(ev, function () { | ||
setTimeout(function () { | ||
if (!_this._targetEl.matches(':hover')) { | ||
_this.hide(); | ||
} | ||
}, 100); | ||
}); | ||
_this._targetEl.addEventListener(ev, function () { | ||
setTimeout(function () { | ||
if (!_this._triggerEl.matches(':hover')) { | ||
_this.hide(); | ||
} | ||
}, 100); | ||
}); | ||
_this._triggerEl.addEventListener(ev, _this._hideHandler); | ||
_this._targetEl.addEventListener(ev, _this._hideHandler); | ||
}); | ||
@@ -77,0 +107,0 @@ }; |
@@ -10,2 +10,3 @@ import { PopoverOptions, PopoverTriggerType, PopoverTriggerEventTypes } from './types'; | ||
_keydownEventListener: EventListenerOrEventListenerObject; | ||
init(): void; | ||
_setupEventListeners(): void; | ||
@@ -22,3 +23,6 @@ _setupClickOutsideListener(): void; | ||
toggle(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
import type { TabItem, TabsOptions } from './types'; | ||
import { TabsInterface } from './interface'; | ||
declare class Tabs implements TabsInterface { | ||
_accordionEl: HTMLElement; | ||
_items: TabItem[]; | ||
_activeTab: TabItem; | ||
_options: TabsOptions; | ||
constructor(items?: TabItem[], options?: TabsOptions); | ||
_init(): void; | ||
_initialized: boolean; | ||
constructor(accordionEl?: HTMLElement | null, items?: TabItem[], options?: TabsOptions); | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
getActiveTab(): TabItem; | ||
_setActiveTab(tab: TabItem): void; | ||
setActiveTab(tab: TabItem): void; | ||
getTab(id: string): TabItem; | ||
@@ -12,0 +17,0 @@ show(id: string, forceShow?: boolean): void; |
@@ -12,2 +12,3 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
import instances from '../../dom/instances'; | ||
var Default = { | ||
@@ -20,16 +21,20 @@ defaultTabId: null, | ||
var Tabs = /** @class */ (function () { | ||
function Tabs(items, options) { | ||
function Tabs(accordionEl, items, options) { | ||
if (accordionEl === void 0) { accordionEl = null; } | ||
if (items === void 0) { items = []; } | ||
if (options === void 0) { options = Default; } | ||
this._accordionEl = accordionEl; | ||
this._items = items; | ||
this._activeTab = options ? this.getTab(options.defaultTabId) : null; | ||
this._options = __assign(__assign({}, Default), options); | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances.addInstance('Tabs', this, this._accordionEl.id, true); | ||
} | ||
Tabs.prototype._init = function () { | ||
Tabs.prototype.init = function () { | ||
var _this = this; | ||
if (this._items.length) { | ||
if (this._items.length && !this._initialized) { | ||
// set the first tab as active if not set by explicitly | ||
if (!this._activeTab) { | ||
this._setActiveTab(this._items[0]); | ||
this.setActiveTab(this._items[0]); | ||
} | ||
@@ -46,6 +51,19 @@ // force show the first default tab | ||
}; | ||
Tabs.prototype.destroy = function () { | ||
if (this._initialized) { | ||
this._initialized = false; | ||
} | ||
}; | ||
Tabs.prototype.removeInstance = function () { | ||
this.destroy(); | ||
instances.removeInstance('Tabs', this._accordionEl.id); | ||
}; | ||
Tabs.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Tabs.prototype.getActiveTab = function () { | ||
return this._activeTab; | ||
}; | ||
Tabs.prototype._setActiveTab = function (tab) { | ||
Tabs.prototype.setActiveTab = function (tab) { | ||
this._activeTab = tab; | ||
@@ -80,3 +98,3 @@ }; | ||
tab.targetEl.classList.remove('hidden'); | ||
this._setActiveTab(tab); | ||
this.setActiveTab(tab); | ||
// callback function | ||
@@ -88,6 +106,6 @@ this._options.onShow(this, tab); | ||
export function initTabs() { | ||
document.querySelectorAll('[data-tabs-toggle]').forEach(function ($triggerEl) { | ||
document.querySelectorAll('[data-tabs-toggle]').forEach(function ($parentEl) { | ||
var tabItems = []; | ||
var defaultTabId = null; | ||
$triggerEl | ||
$parentEl | ||
.querySelectorAll('[role="tab"]') | ||
@@ -106,3 +124,3 @@ .forEach(function ($triggerEl) { | ||
}); | ||
new Tabs(tabItems, { | ||
new Tabs($parentEl, tabItems, { | ||
defaultTabId: defaultTabId, | ||
@@ -109,0 +127,0 @@ }); |
import { TabItem, TabsOptions } from './types'; | ||
export declare interface TabsInterface { | ||
_accordionEl: HTMLElement; | ||
_items: TabItem[]; | ||
_activeTab: TabItem; | ||
_options: TabsOptions; | ||
_init(): void; | ||
_setActiveTab(tab: TabItem): void; | ||
init(): void; | ||
setActiveTab(tab: TabItem): void; | ||
getActiveTab(): TabItem; | ||
getTab(id: string): TabItem; | ||
show(id: string, forceShow?: boolean): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -12,4 +12,10 @@ import type { Instance as PopperInstance } from '@popperjs/core'; | ||
_visible: boolean; | ||
_initialized: boolean; | ||
_showHandler: EventListenerOrEventListenerObject; | ||
_hideHandler: EventListenerOrEventListenerObject; | ||
constructor(targetEl?: HTMLElement | null, triggerEl?: HTMLElement | null, options?: TooltipOptions); | ||
_init(): void; | ||
init(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
_setupEventListeners(): void; | ||
@@ -16,0 +22,0 @@ _createPopperInstance(): PopperInstance; |
@@ -23,2 +23,3 @@ var __assign = (this && this.__assign) || function () { | ||
import { createPopper } from '@popperjs/core'; | ||
import instances from '../../dom/instances'; | ||
var Default = { | ||
@@ -39,23 +40,58 @@ placement: 'top', | ||
this._options = __assign(__assign({}, Default), options); | ||
this._popperInstance = this._createPopperInstance(); | ||
this._popperInstance = null; | ||
this._visible = false; | ||
this._init(); | ||
this._initialized = false; | ||
this.init(); | ||
instances.addInstance('Tooltip', this, this._targetEl.id, true); | ||
} | ||
Tooltip.prototype._init = function () { | ||
if (this._triggerEl) { | ||
Tooltip.prototype.init = function () { | ||
if (this._triggerEl && this._targetEl && !this._initialized) { | ||
this._setupEventListeners(); | ||
this._popperInstance = this._createPopperInstance(); | ||
this._initialized = true; | ||
} | ||
}; | ||
Tooltip.prototype.destroy = function () { | ||
var _this = this; | ||
if (this._initialized) { | ||
// remove event listeners associated with the trigger element | ||
var triggerEvents = this._getTriggerEvents(); | ||
triggerEvents.showEvents.forEach(function (ev) { | ||
_this._triggerEl.removeEventListener(ev, _this._showHandler); | ||
}); | ||
triggerEvents.hideEvents.forEach(function (ev) { | ||
_this._triggerEl.removeEventListener(ev, _this._hideHandler); | ||
}); | ||
// remove event listeners for keydown | ||
this._removeKeydownListener(); | ||
// remove event listeners for click outside | ||
this._removeClickOutsideListener(); | ||
// destroy the Popper instance if you have one (assuming this._popperInstance is the Popper instance) | ||
if (this._popperInstance) { | ||
this._popperInstance.destroy(); | ||
} | ||
this._initialized = false; | ||
} | ||
}; | ||
Tooltip.prototype.removeInstance = function () { | ||
instances.removeInstance('Tooltip', this._targetEl.id); | ||
}; | ||
Tooltip.prototype.destroyAndRemoveInstance = function () { | ||
this.destroy(); | ||
this.removeInstance(); | ||
}; | ||
Tooltip.prototype._setupEventListeners = function () { | ||
var _this = this; | ||
var triggerEvents = this._getTriggerEvents(); | ||
this._showHandler = function () { | ||
_this.show(); | ||
}; | ||
this._hideHandler = function () { | ||
_this.hide(); | ||
}; | ||
triggerEvents.showEvents.forEach(function (ev) { | ||
_this._triggerEl.addEventListener(ev, function () { | ||
_this.show(); | ||
}); | ||
_this._triggerEl.addEventListener(ev, _this._showHandler); | ||
}); | ||
triggerEvents.hideEvents.forEach(function (ev) { | ||
_this._triggerEl.addEventListener(ev, function () { | ||
_this.hide(); | ||
}); | ||
_this._triggerEl.addEventListener(ev, _this._hideHandler); | ||
}); | ||
@@ -62,0 +98,0 @@ }; |
@@ -10,3 +10,3 @@ import { TooltipOptions, TooltipTriggerType, TooltipTriggerEventTypes } from './types'; | ||
_keydownEventListener: EventListenerOrEventListenerObject; | ||
_init(): void; | ||
init(): void; | ||
_setupEventListeners(): void; | ||
@@ -23,3 +23,6 @@ _setupClickOutsideListener(): void; | ||
toggle(): void; | ||
destroy(): void; | ||
removeInstance(): void; | ||
destroyAndRemoveInstance(): void; | ||
} | ||
//# sourceMappingURL=interface.d.ts.map |
@@ -37,4 +37,5 @@ import Accordion from '../components/accordion'; | ||
initFlowbite: () => void; | ||
FlowbiteInstances: any; | ||
} | ||
} | ||
//# sourceMappingURL=global.d.ts.map |
{ | ||
"name": "flowbite", | ||
"version": "1.8.1", | ||
"version": "2.0.0", | ||
"description": "The most popular library of interactive components built with Tailwind CSS", | ||
@@ -48,4 +48,4 @@ "keywords": [ | ||
"contributors": [ | ||
"Zoltán Szőgyényi (https://twitter.com/zoltanszogyenyi)", | ||
"Robert Tanislav (https://twitter.com/roberttanislav)" | ||
"Zoltán Szőgyényi (https://x.com/zoltanszogyenyi)", | ||
"Robert Tanislav (https://x.com/roberttanislav)" | ||
], | ||
@@ -52,0 +52,0 @@ "author": "Bergside Inc.", |
@@ -94,3 +94,3 @@ <p> | ||
```html | ||
<link href="https://cdnjs.cloudflare.com/ajax/libs/flowbite/1.8.1/flowbite.min.css" rel="stylesheet" /> | ||
<link href="https://cdnjs.cloudflare.com/ajax/libs/flowbite/2.0.0/flowbite.min.css" rel="stylesheet" /> | ||
``` | ||
@@ -101,3 +101,3 @@ | ||
```html | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/flowbite/1.8.1/flowbite.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/flowbite/2.0.0/flowbite.min.js"></script> | ||
``` | ||
@@ -270,4 +270,6 @@ | ||
- [📝 Flowbite with Astro guide](https://flowbite.com/docs/getting-started/astro/) | ||
- [📝 Flowbite with MeteorJS guide](https://flowbite.com/docs/getting-started/meteor-js/) | ||
- [📝 Flowbite with Gatsby guide](https://flowbite.com/docs/getting-started/gatsby/) | ||
- [📝 Flowbite with SolidJS guide](https://flowbite.com/docs/getting-started/solid-js/) | ||
- [📝 Flowbite with Qwik guide](https://flowbite.com/docs/getting-started/qwik/) | ||
@@ -274,0 +276,0 @@ ### Back-end Frameworks |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3786191
354
35492
781