@unlk/keymaster 1.6.2 → 1.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,18 @@
1
- import BaseComponent from 'bootstrap/js/src/base-component.js';
2
1
  import EventHandler from 'bootstrap/js/src/dom/event-handler.js';
3
2
  import SelectorEngine from 'bootstrap/js/src/dom/selector-engine.js';
4
- import { defineJQueryPlugin } from 'bootstrap/js/src/util/index.js';
5
3
 
6
- const NAME = 'carouselCaption';
7
- const EVENT_SLID = 'slid.bs.carousel';
4
+ const EVENT_SLID = 'slid.bs.carousel';
8
5
  const SELECTOR_CAROUSEL = '.carousel';
9
- const SELECTOR_CAPTION = '.carousel-caption-container p';
6
+ const SELECTOR_CAPTION = '.carousel-caption-container p';
10
7
 
11
- class CarouselCaption extends BaseComponent {
8
+ const instances = new WeakMap();
9
+
10
+ class CarouselCaption {
12
11
  constructor(element) {
13
- super(element);
14
- this._captionEl = this._findCaptionEl();
12
+ this._element = element;
13
+ this._captionEl = element.querySelector(SELECTOR_CAPTION) || null;
15
14
  this._updateCaption();
15
+ instances.set(element, this);
16
16
  }
17
17
 
18
18
  _updateCaption() {
@@ -21,18 +21,8 @@ class CarouselCaption extends BaseComponent {
21
21
  this._captionEl.textContent = activeItem?.getAttribute('data-caption') ?? '';
22
22
  }
23
23
 
24
- _findCaptionEl() {
25
- return this._element.querySelector(SELECTOR_CAPTION) || null;
26
- }
27
-
28
- static get NAME() {
29
- return NAME;
30
- }
31
-
32
- static jQueryInterface(config) {
33
- return this.each(function () {
34
- CarouselCaption.getOrCreateInstance(this, config);
35
- });
24
+ static getOrCreateInstance(element) {
25
+ return instances.get(element) || new CarouselCaption(element);
36
26
  }
37
27
  }
38
28
 
@@ -40,6 +30,4 @@ EventHandler.on(document, EVENT_SLID, SELECTOR_CAROUSEL, function () {
40
30
  CarouselCaption.getOrCreateInstance(this)._updateCaption();
41
31
  });
42
32
 
43
- defineJQueryPlugin(CarouselCaption);
44
-
45
33
  export default CarouselCaption;
@@ -1,56 +1,54 @@
1
- import BaseComponent from 'bootstrap/js/src/base-component.js';
2
1
  import EventHandler from 'bootstrap/js/src/dom/event-handler.js';
3
2
  import SelectorEngine from 'bootstrap/js/src/dom/selector-engine.js';
4
- import { defineJQueryPlugin } from 'bootstrap/js/src/util/index.js';
5
3
 
6
- const NAME = 'carouselHeight';
7
4
  const EVENT_SLIDE = 'slide.bs.carousel';
8
5
  const EVENT_SLID = 'slid.bs.carousel';
9
6
  const SELECTOR_CAROUSEL = '.carousel';
10
7
  const SELECTOR_INNER = '.carousel-inner';
11
8
 
12
- class CarouselHeight extends BaseComponent {
9
+ const instances = new WeakMap();
10
+
11
+ class CarouselHeight {
13
12
  constructor(element) {
14
- super(element);
15
- this._inner = SelectorEngine.findOne(SELECTOR_INNER, this._element);
13
+ this._element = element;
14
+ this._inner = SelectorEngine.findOne(SELECTOR_INNER, element);
15
+ if (this._inner) this._bindEvents();
16
+ instances.set(element, this);
17
+ }
18
+
19
+ dispose() {
20
+ EventHandler.off(this._element, EVENT_SLIDE);
21
+ EventHandler.off(this._element, EVENT_SLID);
22
+ instances.delete(this._element);
23
+ }
24
+
25
+ _bindEvents() {
26
+ EventHandler.on(this._element, EVENT_SLIDE, (e) => this._onSlide(e));
27
+ EventHandler.on(this._element, EVENT_SLID, () => this._onSlid());
16
28
  }
17
29
 
18
30
  _onSlide(e) {
19
- if (!this._inner) return;
20
31
  const nextSlide = e.relatedTarget;
21
32
  if (!nextSlide) return;
22
-
23
- this._inner.style.height = `${this._inner.offsetHeight}px`;
24
-
33
+ this._inner.style.height = `${this._inner.offsetHeight }px`;
25
34
  requestAnimationFrame(() => {
26
- this._inner.style.height = `${nextSlide.offsetHeight}px`;
35
+ this._inner.style.height = `${nextSlide.offsetHeight }px`;
27
36
  });
28
37
  }
29
38
 
30
39
  _onSlid() {
31
- if (!this._inner) return;
32
40
  this._inner.style.height = '';
33
41
  }
34
42
 
35
- static get NAME() {
36
- return NAME;
37
- }
38
-
39
- static jQueryInterface(config) {
40
- return this.each(function () {
41
- CarouselHeight.getOrCreateInstance(this, config);
42
- });
43
+ static getOrCreateInstance(element) {
44
+ return instances.get(element) || new CarouselHeight(element);
43
45
  }
44
46
  }
45
47
 
46
- EventHandler.on(document, EVENT_SLIDE, SELECTOR_CAROUSEL, function (e) {
47
- CarouselHeight.getOrCreateInstance(this)._onSlide(e);
48
- });
49
-
50
- EventHandler.on(document, EVENT_SLID, SELECTOR_CAROUSEL, function () {
51
- CarouselHeight.getOrCreateInstance(this)._onSlid();
48
+ document.addEventListener('DOMContentLoaded', () => {
49
+ for (const el of SelectorEngine.find(SELECTOR_CAROUSEL)) {
50
+ CarouselHeight.getOrCreateInstance(el);
51
+ }
52
52
  });
53
53
 
54
- defineJQueryPlugin(CarouselHeight);
55
-
56
54
  export default CarouselHeight;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unlk/keymaster",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -1,2 +1,2 @@
1
1
  // GENERATED FILE – do not edit manually
2
- $km-version: "1.6.2" !default;
2
+ $km-version: "1.6.3" !default;