1 | /*!
|
---|
2 | * Bootstrap data.js v5.3.3 (https://getbootstrap.com/)
|
---|
3 | * Copyright 2011-2024 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
---|
4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
5 | */
|
---|
6 | (function (global, factory) {
|
---|
7 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
---|
8 | typeof define === 'function' && define.amd ? define(factory) :
|
---|
9 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Data = factory());
|
---|
10 | })(this, (function () { 'use strict';
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * --------------------------------------------------------------------------
|
---|
14 | * Bootstrap dom/data.js
|
---|
15 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
16 | * --------------------------------------------------------------------------
|
---|
17 | */
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Constants
|
---|
21 | */
|
---|
22 |
|
---|
23 | const elementMap = new Map();
|
---|
24 | const data = {
|
---|
25 | set(element, key, instance) {
|
---|
26 | if (!elementMap.has(element)) {
|
---|
27 | elementMap.set(element, new Map());
|
---|
28 | }
|
---|
29 | const instanceMap = elementMap.get(element);
|
---|
30 |
|
---|
31 | // make it clear we only want one instance per element
|
---|
32 | // can be removed later when multiple key/instances are fine to be used
|
---|
33 | if (!instanceMap.has(key) && instanceMap.size !== 0) {
|
---|
34 | // eslint-disable-next-line no-console
|
---|
35 | console.error(`Bootstrap doesn't allow more than one instance per element. Bound instance: ${Array.from(instanceMap.keys())[0]}.`);
|
---|
36 | return;
|
---|
37 | }
|
---|
38 | instanceMap.set(key, instance);
|
---|
39 | },
|
---|
40 | get(element, key) {
|
---|
41 | if (elementMap.has(element)) {
|
---|
42 | return elementMap.get(element).get(key) || null;
|
---|
43 | }
|
---|
44 | return null;
|
---|
45 | },
|
---|
46 | remove(element, key) {
|
---|
47 | if (!elementMap.has(element)) {
|
---|
48 | return;
|
---|
49 | }
|
---|
50 | const instanceMap = elementMap.get(element);
|
---|
51 | instanceMap.delete(key);
|
---|
52 |
|
---|
53 | // free up element references if there are no instances left for an element
|
---|
54 | if (instanceMap.size === 0) {
|
---|
55 | elementMap.delete(element);
|
---|
56 | }
|
---|
57 | }
|
---|
58 | };
|
---|
59 |
|
---|
60 | return data;
|
---|
61 |
|
---|
62 | }));
|
---|
63 | //# sourceMappingURL=data.js.map
|
---|