@programmerg/bs-elements 0.1.0
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.
- package/LICENSE.md +9 -0
- package/README.md +148 -0
- package/custom-elements.json +7773 -0
- package/dist/bs-elements.bundle.min.js +8 -0
- package/dist/bs-elements.bundle.min.js.map +1 -0
- package/dist/bs-elements.esm.js +1721 -0
- package/dist/bs-elements.esm.js.map +1 -0
- package/dist/bs-elements.min.js +2 -0
- package/dist/bs-elements.min.js.map +1 -0
- package/package.json +50 -0
- package/src/base/BsAccordion.js +116 -0
- package/src/base/BsAlert.js +91 -0
- package/src/base/BsButton.js +129 -0
- package/src/base/BsCarousel.js +216 -0
- package/src/base/BsCollapse.js +84 -0
- package/src/base/BsDropdown.js +98 -0
- package/src/base/BsModal.js +204 -0
- package/src/base/BsOffcanvas.js +157 -0
- package/src/base/BsPopover.js +31 -0
- package/src/base/BsTab.js +69 -0
- package/src/base/BsToast.js +163 -0
- package/src/base/BsTooltip.js +118 -0
- package/src/core/BsElement.js +81 -0
- package/src/core/ReactiveElement.js +183 -0
- package/src/extra/BsCalendar.js +14 -0
- package/src/extra/BsCombobox.js +14 -0
- package/src/extra/BsForm.js +152 -0
- package/src/extra/BsInput.js +209 -0
- package/src/extra/BsTable.js +210 -0
- package/src/extra/BsTabs.js +0 -0
- package/src/extra/BsToastManager.js +0 -0
- package/src/extra/BsTree.js +14 -0
- package/src/extra/BsUploader.js +154 -0
- package/src/index.js +12 -0
|
@@ -0,0 +1,1721 @@
|
|
|
1
|
+
import { Alert, Button, Carousel, Collapse, Dropdown, Modal, Offcanvas, Tooltip, Popover, Tab, Toast } from 'bootstrap';
|
|
2
|
+
|
|
3
|
+
class ReactiveElement extends HTMLElement {
|
|
4
|
+
|
|
5
|
+
constructor() {
|
|
6
|
+
super();
|
|
7
|
+
|
|
8
|
+
// reactive internals
|
|
9
|
+
this.__propValues = Object.create(null);
|
|
10
|
+
this.__changed = new Set();
|
|
11
|
+
this.__updateScheduled = false;
|
|
12
|
+
this.__reflecting = false;
|
|
13
|
+
|
|
14
|
+
this.createReactiveProperties();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* ------------------------------------------------------------------
|
|
18
|
+
* Reactive helpers
|
|
19
|
+
* ------------------------------------------------------------------ */
|
|
20
|
+
|
|
21
|
+
static get properties() {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static __propertyToAttributeMap;
|
|
26
|
+
|
|
27
|
+
static __attributeToPropertyMap;
|
|
28
|
+
|
|
29
|
+
static propertyToAttribute(property) {
|
|
30
|
+
if (this.__propertyToAttributeMap.size < 1) this.observedAttributes();
|
|
31
|
+
return this.__propertyToAttributeMap.get(property);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static attributeToProperty(attribute) {
|
|
35
|
+
if (this.__attributeToPropertyMap.size < 1) this.observedAttributes();
|
|
36
|
+
return this.__attributeToPropertyMap.get(attribute);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static get observedAttributes() {
|
|
40
|
+
if (this.__attributeToPropertyMap === undefined) {
|
|
41
|
+
this.__propertyToAttributeMap = new Map();
|
|
42
|
+
this.__attributeToPropertyMap = new Map();
|
|
43
|
+
|
|
44
|
+
// memoize mappings
|
|
45
|
+
const props = this.properties || this.properties?.() || {};
|
|
46
|
+
for (const [prop, def] of Object.entries(props)) {
|
|
47
|
+
const attr = def?.attribute ?? prop.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
48
|
+
this.__propertyToAttributeMap.set(prop, attr);
|
|
49
|
+
this.__attributeToPropertyMap.set(attr, prop);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return [...this.__attributeToPropertyMap.keys()];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
getAttrValue(attr, type) {
|
|
56
|
+
const value = this.getAttribute(attr);
|
|
57
|
+
|
|
58
|
+
switch (type) {
|
|
59
|
+
case Boolean:
|
|
60
|
+
return this.hasAttribute(attr) && (value === "" || value === "true");
|
|
61
|
+
case Number:
|
|
62
|
+
const n = Number(value);
|
|
63
|
+
return Number.isNaN(n) ? undefined : n;
|
|
64
|
+
default:
|
|
65
|
+
return value === null ? undefined : value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
setAttrValue(attr, value, type) {
|
|
70
|
+
if (value === null || value === undefined || (type === Boolean && !value)) {
|
|
71
|
+
this.removeAttribute(attr);
|
|
72
|
+
} else {
|
|
73
|
+
this.setAttribute(attr, (type === Boolean) ? "" : String(value));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
createReactiveProperties() {
|
|
78
|
+
const props = this.constructor.properties || this.constructor.properties?.() || {};
|
|
79
|
+
for (const [prop, def] of Object.entries(props)) {
|
|
80
|
+
this.createReactiveProperty(prop, def);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
createReactiveProperty(prop, def) {
|
|
85
|
+
const attr = this.constructor.propertyToAttribute(prop);
|
|
86
|
+
|
|
87
|
+
// avoid redefining existing properties
|
|
88
|
+
if (!Object.getOwnPropertyDescriptor(this.constructor.prototype, prop)) {
|
|
89
|
+
Object.defineProperty(this.constructor.prototype, prop, {
|
|
90
|
+
get() {
|
|
91
|
+
return this.__propValues[prop];
|
|
92
|
+
},
|
|
93
|
+
set(value) {
|
|
94
|
+
const old = this.__propValues[prop];
|
|
95
|
+
if (old === value) return;
|
|
96
|
+
|
|
97
|
+
this.__propValues[prop] = value;
|
|
98
|
+
|
|
99
|
+
// reflect props to attributes
|
|
100
|
+
const shouldReflect = def.reflect;
|
|
101
|
+
if (shouldReflect) {
|
|
102
|
+
this.__reflecting = true;
|
|
103
|
+
this.setAttrValue(attr, value, def.type);
|
|
104
|
+
queueMicrotask(() => (this.__reflecting = false));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
this.__changed.add(prop);
|
|
108
|
+
this.scheduleUpdate();
|
|
109
|
+
},
|
|
110
|
+
configurable: true,
|
|
111
|
+
enumerable: true
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// seed initial values from attributes or defaults
|
|
116
|
+
this.__propValues[prop] = this.getAttrValue(attr, def.type) ?? def.default;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
childrenToSlots(html) {
|
|
120
|
+
var template = document.createElement("template");
|
|
121
|
+
template.innerHTML = html;
|
|
122
|
+
|
|
123
|
+
const slots = template.content.querySelectorAll("slot");
|
|
124
|
+
for (const slot of slots) {
|
|
125
|
+
const slotChildren = this.querySelectorAll(`[slot="${slot.name}"]`);
|
|
126
|
+
slotChildren.forEach(el => el.removeAttribute("slot"));
|
|
127
|
+
slot.replaceWith(...slotChildren);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this.replaceChildren(template.content);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/* ------------------------------------------------------------------
|
|
134
|
+
* Custom Element Lifecycle
|
|
135
|
+
* ------------------------------------------------------------------ */
|
|
136
|
+
|
|
137
|
+
connectedCallback() {
|
|
138
|
+
this.firstUpdated();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// eslint-disable-next-line class-methods-use-this
|
|
142
|
+
firstUpdated() {}
|
|
143
|
+
|
|
144
|
+
attributeChangedCallback(attrName, oldValue, newValue) {
|
|
145
|
+
if (this.__reflecting) return;
|
|
146
|
+
|
|
147
|
+
const prop = this.constructor.attributeToProperty(attrName);
|
|
148
|
+
|
|
149
|
+
const props = this.constructor.properties || this.constructor.properties?.() || {};
|
|
150
|
+
const def = props[prop] || {};
|
|
151
|
+
|
|
152
|
+
const old = this.__propValues[prop];
|
|
153
|
+
const value = this.getAttrValue(attrName, def.type);
|
|
154
|
+
if (old === value) return;
|
|
155
|
+
this.__propValues[prop] = value;
|
|
156
|
+
this.__changed.add(prop);
|
|
157
|
+
this.scheduleUpdate();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
scheduleUpdate() {
|
|
161
|
+
if (this.__updateScheduled) return;
|
|
162
|
+
this.__updateScheduled = true;
|
|
163
|
+
queueMicrotask(() => {
|
|
164
|
+
this.__updateScheduled = false;
|
|
165
|
+
const changed = new Set(this.__changed);
|
|
166
|
+
this.__changed.clear();
|
|
167
|
+
try {
|
|
168
|
+
this.updated(changed);
|
|
169
|
+
} catch (e) {
|
|
170
|
+
console.error(e);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
updated(changed) {
|
|
176
|
+
changed.forEach(prop => {
|
|
177
|
+
const fn = `_update${prop.charAt(0).toUpperCase() + prop.slice(1)}State`;
|
|
178
|
+
if (typeof this[fn] === "function") this[fn]();
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// eslint-disable-next-line class-methods-use-this
|
|
183
|
+
disconnectedCallback() {}
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Reactive Element with Bootstrap integration
|
|
189
|
+
*/
|
|
190
|
+
class BsElement extends ReactiveElement {
|
|
191
|
+
|
|
192
|
+
constructor() {
|
|
193
|
+
super();
|
|
194
|
+
|
|
195
|
+
this.bs = null;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
static __bsProps = [];
|
|
199
|
+
|
|
200
|
+
static get bsProps() {
|
|
201
|
+
if (this.__bsProps === undefined) {
|
|
202
|
+
this.__bsProps = [];
|
|
203
|
+
|
|
204
|
+
// memoize related props
|
|
205
|
+
const props = this.properties || this.properties?.() || {};
|
|
206
|
+
for (const [prop, def] of Object.entries(props)) {
|
|
207
|
+
if ((def.attribute ?? '').startsWith('data-bs-')) this.__bsProps.push(prop);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return this.__bsProps;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Must return a Bootstrap JS constructor (e.g. bootstrap.Modal, bootstrap.Collapse)
|
|
215
|
+
*/
|
|
216
|
+
static get bs() {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
createInstance() {
|
|
221
|
+
if (!this.constructor.bs || this.bs) return;
|
|
222
|
+
|
|
223
|
+
const options = this.constructor.bsProps.reduce((acc, key) => {
|
|
224
|
+
if (key in this.__propValues) acc[key] = this.__propValues[key];
|
|
225
|
+
return acc;
|
|
226
|
+
}, {}) || {};
|
|
227
|
+
|
|
228
|
+
this.bs = new this.constructor.bs(this, options);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
dispose() {
|
|
232
|
+
if (!this.bs) return;
|
|
233
|
+
|
|
234
|
+
this.bs?.dispose();
|
|
235
|
+
this.bs = null;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
connectedCallback() {
|
|
239
|
+
// try to guess prop initial values from markup when it's not set
|
|
240
|
+
const props = this.properties || this.properties?.() || {};
|
|
241
|
+
for (const [prop, def] of Object.entries(props)) {
|
|
242
|
+
if (this.__propValues[prop] !== undefined) continue;
|
|
243
|
+
this[prop] = def.values?.find(v => this.className.includes(v));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
super.connectedCallback();
|
|
247
|
+
this.createInstance();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
updated(changed) {
|
|
251
|
+
super.updated(changed);
|
|
252
|
+
|
|
253
|
+
const shouldReinit = this.constructor.bsProps.some(p => changed.has(p));
|
|
254
|
+
if (shouldReinit) {
|
|
255
|
+
this.dispose();
|
|
256
|
+
this.createInstance();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
disconnectedCallback() {
|
|
261
|
+
super.disconnectedCallback();
|
|
262
|
+
this.dispose();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
class BsAccordion extends BsElement {
|
|
268
|
+
|
|
269
|
+
static get properties() {
|
|
270
|
+
return {
|
|
271
|
+
flush: {
|
|
272
|
+
description: "Flag to indicate if the alert is dismissible.",
|
|
273
|
+
type: Boolean,
|
|
274
|
+
default: false
|
|
275
|
+
},
|
|
276
|
+
alwaysOpen: {
|
|
277
|
+
description: "Flag to indicate if the alert is dismissible.",
|
|
278
|
+
type: Boolean,
|
|
279
|
+
default: false
|
|
280
|
+
},
|
|
281
|
+
active: {
|
|
282
|
+
description: "Controls the visibility of the alert.",
|
|
283
|
+
type: Number,
|
|
284
|
+
default: 0
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
toggle(idx) {
|
|
290
|
+
this.children[idx].querySelector('.accordion-button').click();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
firstUpdated() {
|
|
294
|
+
this.classList.add("accordion");
|
|
295
|
+
|
|
296
|
+
this._fixMarkup();
|
|
297
|
+
this._updateAlwaysOpenState();
|
|
298
|
+
this._updateFlushState();
|
|
299
|
+
this._updateActiveState(true);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
_fixMarkup() {
|
|
303
|
+
if (!this.id) this.id = crypto.randomUUID();
|
|
304
|
+
Array.from(this.children).forEach((item, idx) => {
|
|
305
|
+
item.classList.add('accordion-item');
|
|
306
|
+
|
|
307
|
+
let header = item.querySelector('.accordion-header');
|
|
308
|
+
if (!header) {
|
|
309
|
+
header = document.createElement('h2');
|
|
310
|
+
header.classList.add('accordion-header');
|
|
311
|
+
item.insertBefore(header, item.firstChild);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
let button = item.querySelector('.accordion-button, [data-bs-toggle="collapse"]');
|
|
315
|
+
if (!button) {
|
|
316
|
+
button = document.createElement('h2');
|
|
317
|
+
}
|
|
318
|
+
button.classList.add('accordion-button');
|
|
319
|
+
button.setAttribute('data-bs-toggle', 'collapse');
|
|
320
|
+
console.log(button);
|
|
321
|
+
if (!button.hasAttribute('type')) button.setAttribute('type', 'button');
|
|
322
|
+
if (button.parentElement !== header) header.appendChild(button);
|
|
323
|
+
|
|
324
|
+
let collapse = item.querySelector('.accordion-collapse, .collapse');
|
|
325
|
+
if (!collapse) {
|
|
326
|
+
collapse = document.createElement('div');
|
|
327
|
+
}
|
|
328
|
+
collapse.classList.add('accordion-collapse', 'collapse');
|
|
329
|
+
const collapseId = collapse.id || `${this.id}-collapse-${idx}`;
|
|
330
|
+
collapse.id = collapseId;
|
|
331
|
+
|
|
332
|
+
// Ensure collapse content is wrapped in .accordion-body
|
|
333
|
+
let body = collapse.querySelector('.accordion-body');
|
|
334
|
+
if (!body) {
|
|
335
|
+
body = document.createElement('div');
|
|
336
|
+
body.classList.add('accordion-body');
|
|
337
|
+
|
|
338
|
+
while (collapse.firstChild) {
|
|
339
|
+
body.appendChild(collapse.firstChild);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
collapse.appendChild(body);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Wire button -> collapse
|
|
346
|
+
button.setAttribute('data-bs-target', `#${collapseId}`);
|
|
347
|
+
button.setAttribute('aria-controls', collapseId);
|
|
348
|
+
|
|
349
|
+
// Set initial expanded/collapsed classes and aria state based on active
|
|
350
|
+
const activeIdx = Number(this.active) || 0;
|
|
351
|
+
if (idx === activeIdx) {
|
|
352
|
+
collapse.classList.add('show');
|
|
353
|
+
button.classList.remove('collapsed');
|
|
354
|
+
button.setAttribute('aria-expanded', 'true');
|
|
355
|
+
} else {
|
|
356
|
+
collapse.classList.remove('show');
|
|
357
|
+
if (!button.classList.contains('collapsed')) button.classList.add('collapsed');
|
|
358
|
+
button.setAttribute('aria-expanded', 'false');
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
_updateAlwaysOpenState() {
|
|
364
|
+
this.querySelectorAll('.collapse').forEach(collapse => {
|
|
365
|
+
if (!this.alwaysOpen) collapse.setAttribute('data-bs-parent', `#${this.id}`);
|
|
366
|
+
else collapse.removeAttribute('data-bs-parent');
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
_updateFlushState() {
|
|
371
|
+
this.classList.toggle('accordion-flush', this.flush);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
_updateActiveState(isFirstUpdated = false) {
|
|
375
|
+
if (!isFirstUpdated) this.toggle(this.active);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
customElements.define("bs-accordion", BsAccordion);
|
|
381
|
+
|
|
382
|
+
class BsAlert extends BsElement {
|
|
383
|
+
|
|
384
|
+
static get properties() {
|
|
385
|
+
return {
|
|
386
|
+
color: {
|
|
387
|
+
description: "The color theme for the alert.",
|
|
388
|
+
type: String,
|
|
389
|
+
default: "success",
|
|
390
|
+
values: ["primary", "secondary", "success", "danger", "warning", "info", "light", "dark"]
|
|
391
|
+
},
|
|
392
|
+
dismissible: {
|
|
393
|
+
description: "Flag to indicate if the alert is dismissible.",
|
|
394
|
+
type: Boolean,
|
|
395
|
+
default: false
|
|
396
|
+
},
|
|
397
|
+
fade: {
|
|
398
|
+
description: "Flag to enable fade transition.",
|
|
399
|
+
type: Boolean,
|
|
400
|
+
default: true
|
|
401
|
+
},
|
|
402
|
+
open: {
|
|
403
|
+
description: "Controls the visibility of the alert.",
|
|
404
|
+
type: Boolean,
|
|
405
|
+
default: true
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
static get bs() {
|
|
411
|
+
return Alert;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
constructor() {
|
|
415
|
+
super();
|
|
416
|
+
|
|
417
|
+
// this is an external state managed by bootstrap
|
|
418
|
+
Object.defineProperty(this.constructor.prototype, "open", {
|
|
419
|
+
get() {
|
|
420
|
+
return this.classList.contains("show");
|
|
421
|
+
},
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
close() {
|
|
426
|
+
return this.bs?.close();
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
firstUpdated() {
|
|
430
|
+
this.classList.add("alert");
|
|
431
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "alert");
|
|
432
|
+
|
|
433
|
+
this._updateColorState();
|
|
434
|
+
this._updateFadeState();
|
|
435
|
+
this._updateDismissibleState();
|
|
436
|
+
this._updateOpenState(true);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
_updateColorState() {
|
|
440
|
+
this.classList.remove(
|
|
441
|
+
...this.constructor.properties
|
|
442
|
+
.color.values.map(v => "alert-" + v)
|
|
443
|
+
);
|
|
444
|
+
this.classList.add("alert-" + this.color);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
_updateFadeState() {
|
|
448
|
+
this.classList.toggle("fade", this.fade);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
_updateDismissibleState() {
|
|
452
|
+
this.classList.toggle("alert-dismissible", this.dismissible);
|
|
453
|
+
const btn = this.querySelector(":scope > .btn-close");
|
|
454
|
+
const markup = `<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>`;
|
|
455
|
+
|
|
456
|
+
if (this.dismissible) {
|
|
457
|
+
if (!btn) this.insertAdjacentHTML("beforeend", markup);
|
|
458
|
+
} else {
|
|
459
|
+
if (btn) btn.remove();
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
_updateOpenState(isFirstUpdate = false) {
|
|
464
|
+
this.classList.toggle("show", this.__propValues['open']);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
customElements.define("bs-alert", BsAlert);
|
|
470
|
+
|
|
471
|
+
class BsButton extends BsElement {
|
|
472
|
+
|
|
473
|
+
static get properties() {
|
|
474
|
+
return {
|
|
475
|
+
active: {
|
|
476
|
+
description: "Indicates if the component is active.",
|
|
477
|
+
type: Boolean,
|
|
478
|
+
default: false
|
|
479
|
+
},
|
|
480
|
+
color: {
|
|
481
|
+
description: "Color theme for the button.",
|
|
482
|
+
type: String,
|
|
483
|
+
default: undefined,
|
|
484
|
+
values: ["primary", "secondary", "success", "danger", "warning", "info", "light", "dark"]
|
|
485
|
+
},
|
|
486
|
+
outline: {
|
|
487
|
+
description: "Indicates if the component should have an outline.",
|
|
488
|
+
type: Boolean,
|
|
489
|
+
default: false
|
|
490
|
+
},
|
|
491
|
+
size: {
|
|
492
|
+
description: "Size of the Button.",
|
|
493
|
+
type: String,
|
|
494
|
+
default: undefined,
|
|
495
|
+
values: ["sm", "lg"]
|
|
496
|
+
},
|
|
497
|
+
toggle: {
|
|
498
|
+
description: "Bootstrap toggle type.",
|
|
499
|
+
type: String,
|
|
500
|
+
default: undefined,
|
|
501
|
+
values: ["button", "collapse", "dropdown", "modal", "offcanvas", "tab"]
|
|
502
|
+
},
|
|
503
|
+
target: {
|
|
504
|
+
description: "Target selector for toggles (data-bs-target).",
|
|
505
|
+
type: String,
|
|
506
|
+
default: undefined
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
static get bs() {
|
|
512
|
+
return Button;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
constructor() {
|
|
516
|
+
super();
|
|
517
|
+
|
|
518
|
+
// this is an external state managed by bootstrap
|
|
519
|
+
Object.defineProperty(this.constructor.prototype, "active", {
|
|
520
|
+
get() {
|
|
521
|
+
return this.classList.contains("active");
|
|
522
|
+
},
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// toggle() {
|
|
527
|
+
// return this.bs?.toggle();
|
|
528
|
+
// }
|
|
529
|
+
|
|
530
|
+
firstUpdated() {
|
|
531
|
+
//this.classList.add("btn");
|
|
532
|
+
|
|
533
|
+
// default type to prevent accidental form submit
|
|
534
|
+
if (!this.hasAttribute("type")) this.setAttribute("type", "button");
|
|
535
|
+
|
|
536
|
+
this._updateColorState();
|
|
537
|
+
this._updateOutlineState();
|
|
538
|
+
this._updateSizeState();
|
|
539
|
+
this._updateToggleState();
|
|
540
|
+
this._updateTargetState();
|
|
541
|
+
this._updateActiveState(true);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
_updateColorState() {
|
|
545
|
+
this.classList.remove(
|
|
546
|
+
...this.constructor.properties
|
|
547
|
+
.color.values.map(v => "btn-" + v)
|
|
548
|
+
);
|
|
549
|
+
this.classList.remove(
|
|
550
|
+
...this.constructor.properties
|
|
551
|
+
.color.values.map(v => "btn-outline-" + v)
|
|
552
|
+
);
|
|
553
|
+
|
|
554
|
+
const variant = this.outline ? `btn-outline-${this.color}` : `btn-${this.color}`;
|
|
555
|
+
this.classList.add(variant);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
_updateOutlineState() {
|
|
559
|
+
this._updateColorState();
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
_updateSizeState() {
|
|
563
|
+
this.classList.remove(
|
|
564
|
+
...this.constructor.properties
|
|
565
|
+
.size.values.map(v => "btn-" + v)
|
|
566
|
+
);
|
|
567
|
+
if (this.size) this.classList.add("btn-" + this.size);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
_updateToggleState() {
|
|
571
|
+
if (this.toggle) this.setAttribute("data-bs-toggle", this.toggle);
|
|
572
|
+
else this.removeAttribute("data-bs-toggle");
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
_updateTargetState() {
|
|
576
|
+
if (this.target) this.setAttribute("data-bs-target", this.target);
|
|
577
|
+
else this.removeAttribute("data-bs-target");
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
_updateActiveState(isFirstUpdate = false) {
|
|
581
|
+
if (isFirstUpdate) {
|
|
582
|
+
this.classList.toggle("active", !!this.__propValues['active']);
|
|
583
|
+
|
|
584
|
+
if (this.toggle === "button") {
|
|
585
|
+
this.setAttribute("aria-pressed", this.active ? "true" : "false");
|
|
586
|
+
} else {
|
|
587
|
+
this.removeAttribute("aria-pressed");
|
|
588
|
+
}
|
|
589
|
+
} else {
|
|
590
|
+
this.toggle();
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
customElements.define("bs-button", BsButton);
|
|
597
|
+
|
|
598
|
+
class BsCarousel extends BsElement {
|
|
599
|
+
|
|
600
|
+
static get properties() {
|
|
601
|
+
return {
|
|
602
|
+
fade: {
|
|
603
|
+
description: "",
|
|
604
|
+
type: Boolean,
|
|
605
|
+
default: false
|
|
606
|
+
},
|
|
607
|
+
indicators: {
|
|
608
|
+
description: "",
|
|
609
|
+
type: Boolean,
|
|
610
|
+
default: true
|
|
611
|
+
},
|
|
612
|
+
interval: {
|
|
613
|
+
description: "The time interval (in milliseconds) between automatic transitions of the carousel items.",
|
|
614
|
+
type: Number,
|
|
615
|
+
default: 5000,
|
|
616
|
+
attribute: 'data-bs-interval'
|
|
617
|
+
},
|
|
618
|
+
keyboard: {
|
|
619
|
+
description: "A Boolean indicating whether the carousel should respond to keyboard navigation.",
|
|
620
|
+
type: Boolean,
|
|
621
|
+
default: true,
|
|
622
|
+
attribute: 'data-bs-keyboard'
|
|
623
|
+
},
|
|
624
|
+
pause: {
|
|
625
|
+
description: "A Boolean indicating whether automatic cycling of the carousel should pause on hover.",
|
|
626
|
+
type: Boolean,
|
|
627
|
+
default: true,
|
|
628
|
+
attribute: 'data-bs-pause'
|
|
629
|
+
},
|
|
630
|
+
ride: {
|
|
631
|
+
description: "A Boolean indicating whether the carousel should automatically cycle through items.",
|
|
632
|
+
type: Boolean,
|
|
633
|
+
default: true,
|
|
634
|
+
attribute: 'data-bs-ride'
|
|
635
|
+
},
|
|
636
|
+
touch: {
|
|
637
|
+
description: "A Boolean indicating whether the carousel should support left/right swipe interactions on touchscreen",
|
|
638
|
+
type: Boolean,
|
|
639
|
+
default: true,
|
|
640
|
+
attribute: 'data-bs-touch'
|
|
641
|
+
},
|
|
642
|
+
wrap: {
|
|
643
|
+
description: "A Boolean indicating whether the carousel should cycle continuously or have hard stops",
|
|
644
|
+
type: Boolean,
|
|
645
|
+
default: true,
|
|
646
|
+
attribute: 'data-bs-wrap'
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
static get bs() {
|
|
652
|
+
return Carousel;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
cycle() {
|
|
656
|
+
return this.bs?.cycle();
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
next() {
|
|
660
|
+
return this.bs?.next();
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
nextWhenVisible() {
|
|
664
|
+
return this.bs?.nextWhenVisible();
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
pause() {
|
|
668
|
+
return this.bs?.pause();
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
prev() {
|
|
672
|
+
return this.bs?.prev();
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
to(idx) {
|
|
676
|
+
return this.bs?.to(idx);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
firstUpdated() {
|
|
680
|
+
this.classList.add("carousel");
|
|
681
|
+
this.classList.add("slide");
|
|
682
|
+
|
|
683
|
+
this._fixMarkup();
|
|
684
|
+
this._updateFadeState();
|
|
685
|
+
this._updateIndicatorsState();
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
_fixMarkup() {
|
|
689
|
+
// ensure inner wrapper
|
|
690
|
+
let inner = this.querySelector(":scope > .carousel-inner");
|
|
691
|
+
if (!inner) {
|
|
692
|
+
inner = document.createElement("div");
|
|
693
|
+
inner.className = "carousel-inner";
|
|
694
|
+
|
|
695
|
+
// move suitable children into inner
|
|
696
|
+
const toMove = [];
|
|
697
|
+
for (const child of Array.from(this.childNodes)) {
|
|
698
|
+
if (child.nodeType !== Node.ELEMENT_NODE) continue;
|
|
699
|
+
const el = child;
|
|
700
|
+
if (el.classList && (el.classList.contains("carousel-indicators") || el.classList.contains("carousel-control-prev") || el.classList.contains("carousel-control-next") || el.classList.contains("carousel-inner"))) continue;
|
|
701
|
+
toMove.push(el);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
toMove.forEach(el => {
|
|
705
|
+
// if element is already a carousel-item, just append
|
|
706
|
+
if (el.classList && el.classList.contains("carousel-item")) inner.appendChild(el);
|
|
707
|
+
else {
|
|
708
|
+
const wrap = document.createElement("div");
|
|
709
|
+
wrap.className = "carousel-item";
|
|
710
|
+
wrap.appendChild(el);
|
|
711
|
+
inner.appendChild(wrap);
|
|
712
|
+
}
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
// insert inner at the end (indicators may be inserted before it later)
|
|
716
|
+
this.appendChild(inner);
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
// ensure every child of inner has the proper classes
|
|
720
|
+
const items = Array.from(inner.children).filter(n => n.nodeType === Node.ELEMENT_NODE);
|
|
721
|
+
items.forEach((it, i) => {
|
|
722
|
+
it.classList.add("carousel-item");
|
|
723
|
+
if (!inner.querySelector(".carousel-item.active") && i === 0) {
|
|
724
|
+
it.classList.add("active");
|
|
725
|
+
}
|
|
726
|
+
});
|
|
727
|
+
|
|
728
|
+
// indicators and controls
|
|
729
|
+
this._ensureControls();
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
_renderIndicators() {
|
|
733
|
+
// remove existing indicators container
|
|
734
|
+
let indicators = this.querySelector(":scope > .carousel-indicators");
|
|
735
|
+
if (indicators) indicators.remove();
|
|
736
|
+
|
|
737
|
+
const inner = this.querySelector(":scope > .carousel-inner");
|
|
738
|
+
if (!inner) return;
|
|
739
|
+
|
|
740
|
+
indicators = document.createElement("div");
|
|
741
|
+
indicators.className = "carousel-indicators";
|
|
742
|
+
|
|
743
|
+
const slides = Array.from(inner.children).filter(n => n.nodeType === Node.ELEMENT_NODE);
|
|
744
|
+
slides.forEach((_, idx) => {
|
|
745
|
+
const btn = document.createElement("button");
|
|
746
|
+
btn.type = "button";
|
|
747
|
+
btn.setAttribute("aria-label", `Slide ${idx + 1}`);
|
|
748
|
+
btn.className = idx === 0 ? "active" : "";
|
|
749
|
+
btn.addEventListener("click", () => this.to(idx));
|
|
750
|
+
indicators.appendChild(btn);
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
// insert indicators before inner
|
|
754
|
+
this.insertBefore(indicators, inner);
|
|
755
|
+
this._renderIndicatorsActive();
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
_ensureControls() {
|
|
759
|
+
// prev
|
|
760
|
+
if (!this.querySelector(":scope > .carousel-control-prev")) {
|
|
761
|
+
const prev = document.createElement("button");
|
|
762
|
+
prev.className = "carousel-control-prev";
|
|
763
|
+
prev.type = "button";
|
|
764
|
+
prev.innerHTML = `<span class="carousel-control-prev-icon" aria-hidden="true"></span><span class="visually-hidden">Previous</span>`;
|
|
765
|
+
prev.addEventListener("click", () => this.prev());
|
|
766
|
+
this.appendChild(prev);
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
// next
|
|
770
|
+
if (!this.querySelector(":scope > .carousel-control-next")) {
|
|
771
|
+
const next = document.createElement("button");
|
|
772
|
+
next.className = "carousel-control-next";
|
|
773
|
+
next.type = "button";
|
|
774
|
+
next.innerHTML = `<span class="carousel-control-next-icon" aria-hidden="true"></span><span class="visually-hidden">Next</span>`;
|
|
775
|
+
next.addEventListener("click", () => this.next());
|
|
776
|
+
this.appendChild(next);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
_renderIndicatorsActive() {
|
|
781
|
+
const indicators = this.querySelector(":scope > .carousel-indicators");
|
|
782
|
+
const inner = this.querySelector(":scope > .carousel-inner");
|
|
783
|
+
if (!indicators || !inner) return;
|
|
784
|
+
|
|
785
|
+
const slides = Array.from(inner.children).filter(n => n.nodeType === Node.ELEMENT_NODE);
|
|
786
|
+
const activeIndex = slides.findIndex(s => s.classList.contains("active"));
|
|
787
|
+
|
|
788
|
+
Array.from(indicators.children).forEach((btn, idx) => {
|
|
789
|
+
btn.classList.toggle("active", idx === activeIndex);
|
|
790
|
+
if (idx === activeIndex) btn.setAttribute("aria-current", "true");
|
|
791
|
+
else btn.removeAttribute("aria-current");
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
_updateFadeState() {
|
|
796
|
+
this.classList.toggle("carousel-fade", !!this.fade);
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
_updateIndicatorsState() {
|
|
800
|
+
if (this.indicators) {
|
|
801
|
+
this._renderIndicators();
|
|
802
|
+
} else {
|
|
803
|
+
const el = this.querySelector(".carousel-indicators");
|
|
804
|
+
if (el) el.remove();
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
customElements.define("bs-carousel", BsCarousel);
|
|
811
|
+
|
|
812
|
+
class BsCollapse extends BsElement {
|
|
813
|
+
|
|
814
|
+
static get properties() {
|
|
815
|
+
return {
|
|
816
|
+
open: {
|
|
817
|
+
description: "Toggle visible state",
|
|
818
|
+
type: Boolean,
|
|
819
|
+
default: false
|
|
820
|
+
},
|
|
821
|
+
horizontal: {
|
|
822
|
+
description: "Toggle horizontal collapsing",
|
|
823
|
+
type: Boolean,
|
|
824
|
+
default: false
|
|
825
|
+
},
|
|
826
|
+
parent: {
|
|
827
|
+
description: "Selector of the container element",
|
|
828
|
+
type: String,
|
|
829
|
+
default: undefined,
|
|
830
|
+
attribute: "data-bs-parent"
|
|
831
|
+
},
|
|
832
|
+
toggle: {
|
|
833
|
+
description: "Toggles the collapsible element",
|
|
834
|
+
type: Boolean,
|
|
835
|
+
default: false,
|
|
836
|
+
attribute: "data-bs-toggle"
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
static get bs() {
|
|
842
|
+
return Collapse;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
constructor() {
|
|
846
|
+
super();
|
|
847
|
+
|
|
848
|
+
// this is an external state managed by bootstrap
|
|
849
|
+
Object.defineProperty(this.constructor.prototype, "open", {
|
|
850
|
+
get() {
|
|
851
|
+
return this.classList.contains("show");
|
|
852
|
+
},
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
hide() {
|
|
857
|
+
return this.bs?.hide();
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
show() {
|
|
861
|
+
return this.bs?.show();
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
toggle() {
|
|
865
|
+
return this.bs?.toggle();
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
firstUpdated() {
|
|
869
|
+
this.classList.add("collapse");
|
|
870
|
+
|
|
871
|
+
this._updateHorizontalState();
|
|
872
|
+
this._updateOpenState(true);
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
_updateHorizontalState() {
|
|
876
|
+
if (this.horizontal) {
|
|
877
|
+
this.classList.add("collapse-horizontal");
|
|
878
|
+
this.style.width ||= "0px";
|
|
879
|
+
} else {
|
|
880
|
+
this.classList.remove("collapse-horizontal");
|
|
881
|
+
this.style.width = "";
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
_updateOpenState(isFirstUpdate = false) {
|
|
886
|
+
if (isFirstUpdate) this.classList.toggle("show", this.__propValues['open']);
|
|
887
|
+
else this.toggle();
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
customElements.define("bs-collapse", BsCollapse);
|
|
893
|
+
|
|
894
|
+
class BsDropdown extends BsElement {
|
|
895
|
+
|
|
896
|
+
static get properties() {
|
|
897
|
+
return {
|
|
898
|
+
autoClose: {
|
|
899
|
+
description: "A boolean indicating whether the Dropdown should automatically close when an item is selected.",
|
|
900
|
+
type: Boolean,
|
|
901
|
+
default: true,
|
|
902
|
+
attribute: "data-bs-auto-close"
|
|
903
|
+
},
|
|
904
|
+
direction: {
|
|
905
|
+
description: "The direction of the Dropdown menu",
|
|
906
|
+
type: String,
|
|
907
|
+
default: "down",
|
|
908
|
+
values: ["down", "start", "end", "up", "down-center", "up-center"]
|
|
909
|
+
},
|
|
910
|
+
open: {
|
|
911
|
+
description: "A boolean indicating whether the Dropdown is currently open.",
|
|
912
|
+
type: Boolean,
|
|
913
|
+
default: false
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
static get bs() {
|
|
919
|
+
return Dropdown;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
constructor() {
|
|
923
|
+
super();
|
|
924
|
+
|
|
925
|
+
// this is an external state managed by bootstrap
|
|
926
|
+
Object.defineProperty(this.constructor.prototype, "open", {
|
|
927
|
+
get() {
|
|
928
|
+
return this.classList.contains("show");
|
|
929
|
+
},
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
hide() {
|
|
934
|
+
return this.bs?.hide();
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
show() {
|
|
938
|
+
return this.bs?.show();
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
toggle() {
|
|
942
|
+
return this.bs?.toggle();
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
update() {
|
|
946
|
+
return this.bs?.update();
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
firstUpdated() {
|
|
950
|
+
this.classList.add("dropdown");
|
|
951
|
+
|
|
952
|
+
// Ensure toggle has the proper data attribute
|
|
953
|
+
const toggle = this.querySelector(
|
|
954
|
+
`:scope > [data-bs-toggle="dropdown"], :scope > .dropdown-toggle`
|
|
955
|
+
);
|
|
956
|
+
if (toggle && !toggle.hasAttribute("data-bs-toggle")) {
|
|
957
|
+
toggle.setAttribute("data-bs-toggle", "dropdown");
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
this._fixMarkup();
|
|
961
|
+
this._updateDirectionState();
|
|
962
|
+
this._updateOpenState(true);
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
_fixMarkup() {
|
|
966
|
+
// Ensure bs-dropdown-menu children receive Bootstrap class
|
|
967
|
+
const menu = this.querySelector(":scope > div, :scope > .dropdown-menu");
|
|
968
|
+
if (menu && !menu.classList.contains("dropdown-menu")) {
|
|
969
|
+
menu.classList.add("dropdown-menu");
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
_updateDirectionState() {
|
|
974
|
+
this.classList.remove(
|
|
975
|
+
...this.constructor.properties
|
|
976
|
+
.direction.values.map(v => "drop" + v)
|
|
977
|
+
);
|
|
978
|
+
this.classList.add("drop" + this.direction);
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
_updateOpenState(isFirstUpdate = false) {
|
|
982
|
+
if (isFirstUpdate) this.classList.toggle("show", this.__propValues['open']);
|
|
983
|
+
else this.toggle();
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
customElements.define("bs-dropdown", BsDropdown);
|
|
989
|
+
|
|
990
|
+
class BsModal extends BsElement {
|
|
991
|
+
|
|
992
|
+
static get properties() {
|
|
993
|
+
return {
|
|
994
|
+
focus: {
|
|
995
|
+
description: "Automatically puts focus on the modal with it first opens.",
|
|
996
|
+
type: Boolean,
|
|
997
|
+
default: false,
|
|
998
|
+
attribute: "data-bs-focus"
|
|
999
|
+
},
|
|
1000
|
+
backdrop: {
|
|
1001
|
+
description: "Controls the visibility of the modal backdrop.",
|
|
1002
|
+
type: Boolean,
|
|
1003
|
+
default: true,
|
|
1004
|
+
attribute: "data-bs-backdrop"
|
|
1005
|
+
},
|
|
1006
|
+
centered: {
|
|
1007
|
+
description: "Auto-positioning of the modal to ensure its centered in the viewport.",
|
|
1008
|
+
type: Boolean,
|
|
1009
|
+
default: false
|
|
1010
|
+
},
|
|
1011
|
+
fade: {
|
|
1012
|
+
description: "Control the fade effect when opening or closing the modal.",
|
|
1013
|
+
type: Boolean,
|
|
1014
|
+
default: true
|
|
1015
|
+
},
|
|
1016
|
+
fullscreen: {
|
|
1017
|
+
description: "Determines whether or no the modal is rendered in fullscreen mode.",
|
|
1018
|
+
type: String,
|
|
1019
|
+
default: "",
|
|
1020
|
+
values: ["true", "sm", "md", "lg", "xl", "xxl"]
|
|
1021
|
+
},
|
|
1022
|
+
header: {
|
|
1023
|
+
description: "Customize the modal header content.",
|
|
1024
|
+
type: String,
|
|
1025
|
+
default: undefined
|
|
1026
|
+
},
|
|
1027
|
+
open: {
|
|
1028
|
+
description: "Used to control the modal state",
|
|
1029
|
+
type: Boolean,
|
|
1030
|
+
default: false
|
|
1031
|
+
},
|
|
1032
|
+
keyboard: {
|
|
1033
|
+
description: "Ccontrol whether the modal can be closed using the ESC key.",
|
|
1034
|
+
type: Boolean,
|
|
1035
|
+
default: true,
|
|
1036
|
+
attribute: "data-bs-keyboard"
|
|
1037
|
+
},
|
|
1038
|
+
scrollable: {
|
|
1039
|
+
description: "Determines if the modal content should be scrollable.",
|
|
1040
|
+
type: Boolean,
|
|
1041
|
+
default: false
|
|
1042
|
+
},
|
|
1043
|
+
size: {
|
|
1044
|
+
description: "Specify the size of the modal.",
|
|
1045
|
+
type: String,
|
|
1046
|
+
default: "",
|
|
1047
|
+
values: ["sm", "lg", "xl"]
|
|
1048
|
+
}
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
static get bs() {
|
|
1053
|
+
return Modal;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
constructor() {
|
|
1057
|
+
super();
|
|
1058
|
+
|
|
1059
|
+
// this is an external state managed by bootstrap
|
|
1060
|
+
Object.defineProperty(this.constructor.prototype, "open", {
|
|
1061
|
+
get() {
|
|
1062
|
+
return this.classList.contains("show");
|
|
1063
|
+
},
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
handleUpdate() {
|
|
1068
|
+
return this.bs?.handleUpdate();
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
hide() {
|
|
1072
|
+
return this.bs?.hide();
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
show() {
|
|
1076
|
+
return this.bs?.show();
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
toggle() {
|
|
1080
|
+
return this.bs?.toggle();
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
firstUpdated() {
|
|
1084
|
+
this.classList.add("modal");
|
|
1085
|
+
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "-1");
|
|
1086
|
+
|
|
1087
|
+
this._fixMarkup();
|
|
1088
|
+
this._updateFadeState();
|
|
1089
|
+
this._updateCenteredState();
|
|
1090
|
+
this._updateScrollableState();
|
|
1091
|
+
this._updateSizeState();
|
|
1092
|
+
this._updateFullscreenState();
|
|
1093
|
+
this._updateOpenState(true);
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
_fixMarkup() {
|
|
1097
|
+
let dialog = this.querySelector(":scope > .modal-dialog");
|
|
1098
|
+
if (dialog) return;
|
|
1099
|
+
|
|
1100
|
+
dialog = document.createElement("div");
|
|
1101
|
+
dialog.classList.add("modal-dialog");
|
|
1102
|
+
|
|
1103
|
+
const content = document.createElement("div");
|
|
1104
|
+
content.classList.add("modal-content");
|
|
1105
|
+
|
|
1106
|
+
let header = this.querySelector(":scope > .modal-header");
|
|
1107
|
+
if (!header) {
|
|
1108
|
+
header = document.createElement("div");
|
|
1109
|
+
header.classList.add("modal-header");
|
|
1110
|
+
header.insertAdjacentHTML("afterbegin", `<h5 class="modal-title">${this.header}</h5>`);
|
|
1111
|
+
}
|
|
1112
|
+
content.appendChild(header);
|
|
1113
|
+
|
|
1114
|
+
if (header.querySelector(".btn-close")) {
|
|
1115
|
+
header.insertAdjacentHTML("beforeend",
|
|
1116
|
+
`<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>`
|
|
1117
|
+
);
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
let body = this.querySelector(":scope > .modal-body");
|
|
1121
|
+
if (!body) {
|
|
1122
|
+
body = document.createElement("div");
|
|
1123
|
+
body.classList.add("modal-body");
|
|
1124
|
+
}
|
|
1125
|
+
content.appendChild(body);
|
|
1126
|
+
|
|
1127
|
+
let footer = this.querySelector(":scope > .modal-footer");
|
|
1128
|
+
if (footer) {
|
|
1129
|
+
content.appendChild(footer);
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
while (this.firstChild) {
|
|
1133
|
+
body.appendChild(this.firstChild);
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
dialog.appendChild(content);
|
|
1137
|
+
this.appendChild(dialog);
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
_updateHeaderState() {
|
|
1141
|
+
const title = this.querySelector(":scope > .modal-dialog > .modal-header > .modal-title");
|
|
1142
|
+
if (title) {
|
|
1143
|
+
title.textContent = this.header;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
_updateFadeState() {
|
|
1148
|
+
this.classList.toggle("fade", this.fade);
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
_updateCenteredState() {
|
|
1152
|
+
const dialog = this.querySelector(":scope > .modal-dialog");
|
|
1153
|
+
dialog?.classList.toggle("modal-dialog-centered", this.centered);
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
_updateScrollableState() {
|
|
1157
|
+
const dialog = this.querySelector(":scope > .modal-dialog");
|
|
1158
|
+
dialog?.classList.toggle("modal-dialog-scrollable", this.scrollable);
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
_updateSizeState() {
|
|
1162
|
+
const dialog = this.querySelector(":scope > .modal-dialog");
|
|
1163
|
+
dialog?.classList.remove(
|
|
1164
|
+
...this.constructor.properties
|
|
1165
|
+
.size.values.map(v => "modal-" + v)
|
|
1166
|
+
);
|
|
1167
|
+
if (this.size) dialog?.classList.add(`modal-${this.size}`);
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
_updateFullscreenState() {
|
|
1171
|
+
const dialog = this.querySelector(":scope > .modal-dialog");
|
|
1172
|
+
dialog?.classList.remove(
|
|
1173
|
+
...this.constructor.properties
|
|
1174
|
+
.fullscreen.values.map(v => "modal-fullscreen-" + v + "-down")
|
|
1175
|
+
);
|
|
1176
|
+
if (this.fullscreen) dialog?.classList.add(
|
|
1177
|
+
this.fullscreen === "true"
|
|
1178
|
+
? "modal-fullscreen"
|
|
1179
|
+
: `modal-fullscreen-${this.fullscreen}-down`
|
|
1180
|
+
);
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
_updateOpenState(isFirstUpdate = false) {
|
|
1184
|
+
if (isFirstUpdate) this.classList.toggle("show", this.__propValues['open']);
|
|
1185
|
+
else this.toggle();
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
customElements.define("bs-modal", BsModal);
|
|
1191
|
+
|
|
1192
|
+
class BsOffcanvas extends BsElement {
|
|
1193
|
+
|
|
1194
|
+
static get properties() {
|
|
1195
|
+
return {
|
|
1196
|
+
backdrop: {
|
|
1197
|
+
description: "Controls whether the backdrop is displayed behind the offcanvas.",
|
|
1198
|
+
type: Boolean,
|
|
1199
|
+
default: true,
|
|
1200
|
+
attribute: "data-bs-backdrop"
|
|
1201
|
+
},
|
|
1202
|
+
fade: {
|
|
1203
|
+
description: "Controls whether to use a fade animation when opening/closing the offcanvas.",
|
|
1204
|
+
type: Boolean,
|
|
1205
|
+
default: true
|
|
1206
|
+
},
|
|
1207
|
+
header: {
|
|
1208
|
+
description: "The header content of the offcanvas.",
|
|
1209
|
+
type: String,
|
|
1210
|
+
default: ""
|
|
1211
|
+
},
|
|
1212
|
+
open: {
|
|
1213
|
+
description: "Used to control the modal state",
|
|
1214
|
+
type: Boolean,
|
|
1215
|
+
default: false
|
|
1216
|
+
},
|
|
1217
|
+
keyboard: {
|
|
1218
|
+
description: "Controls whether keyboard interaction is enabled for closing the offcanvas.",
|
|
1219
|
+
type: Boolean,
|
|
1220
|
+
default: true,
|
|
1221
|
+
attribute: "data-bs-keyboard"
|
|
1222
|
+
},
|
|
1223
|
+
placement: {
|
|
1224
|
+
description: "The placement of the offcanvas.",
|
|
1225
|
+
type: String,
|
|
1226
|
+
default: "start",
|
|
1227
|
+
values: ["start", "end", "top", "bottom"]
|
|
1228
|
+
},
|
|
1229
|
+
scroll: {
|
|
1230
|
+
description: "Controls whether to allow scrolling of the body when the offcanvas is open.",
|
|
1231
|
+
type: Boolean,
|
|
1232
|
+
default: false,
|
|
1233
|
+
attribute: "data-bs-scroll"
|
|
1234
|
+
},
|
|
1235
|
+
size: {
|
|
1236
|
+
description: "Specify the size of the modal.",
|
|
1237
|
+
type: String,
|
|
1238
|
+
default: "",
|
|
1239
|
+
values: ["sm", "md", "lg", "xl", "xxl"]
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
static get bs() {
|
|
1245
|
+
return Offcanvas;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
constructor() {
|
|
1249
|
+
super();
|
|
1250
|
+
|
|
1251
|
+
// this is an external state managed by bootstrap
|
|
1252
|
+
Object.defineProperty(this.constructor.prototype, "open", {
|
|
1253
|
+
get() {
|
|
1254
|
+
return this.classList.contains("show");
|
|
1255
|
+
},
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
hide() {
|
|
1260
|
+
return this.bs?.hide();
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
show() {
|
|
1264
|
+
return this.bs?.show();
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
toggle() {
|
|
1268
|
+
return this.bs?.toggle();
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
firstUpdated() {
|
|
1272
|
+
this.classList.add("offcanvas");
|
|
1273
|
+
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "-1");
|
|
1274
|
+
|
|
1275
|
+
this._fixMarkup();
|
|
1276
|
+
this._updateFadeState();
|
|
1277
|
+
this._updatePlacementState();
|
|
1278
|
+
this._updateSizeState();
|
|
1279
|
+
this._updateOpenState(true);
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
_fixMarkup() {
|
|
1283
|
+
let header = this.querySelector(":scope > .offcanvas-header");
|
|
1284
|
+
if (!header) {
|
|
1285
|
+
header = document.createElement("div");
|
|
1286
|
+
header.classList.add("offcanvas-header");
|
|
1287
|
+
header.insertAdjacentHTML("afterbegin", `<h5 class="offcanvas-title">${this.header ?? ""}</h5>`);
|
|
1288
|
+
header.insertAdjacentHTML("beforeend",
|
|
1289
|
+
`<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>`
|
|
1290
|
+
);
|
|
1291
|
+
this.appendChild(header);
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
if (!header.querySelector(".btn-close")) {
|
|
1295
|
+
header.insertAdjacentHTML("beforeend",
|
|
1296
|
+
`<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>`
|
|
1297
|
+
);
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
let body = this.querySelector(":scope > .offcanvas-body");
|
|
1301
|
+
if (!body) {
|
|
1302
|
+
body = document.createElement("div");
|
|
1303
|
+
body.classList.add("offcanvas-body");
|
|
1304
|
+
this.appendChild(body);
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
for (const node of Array.from(this.childNodes)) {
|
|
1308
|
+
if (node === header || node === body) continue;
|
|
1309
|
+
body.appendChild(node);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
_updateHeaderState() {
|
|
1314
|
+
const title = this.querySelector(":scope > .offcanvas-header > .offcanvas-title");
|
|
1315
|
+
if (title) title.textContent = this.header ?? "";
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
_updateFadeState() {
|
|
1319
|
+
this.classList.toggle("fade", this.fade);
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
_updatePlacementState() {
|
|
1323
|
+
this.classList.remove(
|
|
1324
|
+
...this.constructor.properties
|
|
1325
|
+
.placement.values.map(v => "offcanvas-" + v)
|
|
1326
|
+
);
|
|
1327
|
+
if (this.placement) this.classList.add(`offcanvas-${this.placement}`);
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
_updateSizeState() {
|
|
1331
|
+
this.classList.remove(
|
|
1332
|
+
...this.constructor.properties
|
|
1333
|
+
.size.values.map(v => "offcanvas-" + v)
|
|
1334
|
+
);
|
|
1335
|
+
if (this.size) this.classList.add(`offcanvas-${this.size}`);
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
_updateOpenState(isFirstUpdate = false) {
|
|
1339
|
+
if (isFirstUpdate) this.classList.toggle("show", this.__propValues['open']);
|
|
1340
|
+
else this.toggle();
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
customElements.define("bs-offcanvas", BsOffcanvas);
|
|
1346
|
+
|
|
1347
|
+
class BsTooltip extends BsElement {
|
|
1348
|
+
|
|
1349
|
+
static get properties() {
|
|
1350
|
+
return {
|
|
1351
|
+
animation: {
|
|
1352
|
+
description: "Flag to enable animation for the tooltip.",
|
|
1353
|
+
type: Boolean,
|
|
1354
|
+
default: true,
|
|
1355
|
+
attribute: "data-bs-animation"
|
|
1356
|
+
},
|
|
1357
|
+
title: {
|
|
1358
|
+
description: "The title to be displayed within the tooltip.",
|
|
1359
|
+
type: String,
|
|
1360
|
+
default: "",
|
|
1361
|
+
attribute: "data-bs-title"
|
|
1362
|
+
},
|
|
1363
|
+
delay: {
|
|
1364
|
+
description: "The delay for showing the tooltip (in milliseconds).",
|
|
1365
|
+
type: Number,
|
|
1366
|
+
default: 0,
|
|
1367
|
+
attribute: "data-bs-delay"
|
|
1368
|
+
},
|
|
1369
|
+
html: {
|
|
1370
|
+
description: "",
|
|
1371
|
+
type: Boolean,
|
|
1372
|
+
default: false,
|
|
1373
|
+
attribute: "data-bs-html"
|
|
1374
|
+
},
|
|
1375
|
+
open: {
|
|
1376
|
+
description: "Controls the visibility of the tooltip.",
|
|
1377
|
+
type: Boolean,
|
|
1378
|
+
default: false
|
|
1379
|
+
},
|
|
1380
|
+
placement: {
|
|
1381
|
+
description: "The preferred placement of the tooltip.",
|
|
1382
|
+
type: String,
|
|
1383
|
+
default: "top",
|
|
1384
|
+
attribute: "data-bs-placement"
|
|
1385
|
+
},
|
|
1386
|
+
trigger: {
|
|
1387
|
+
description: "The trigger action to open/close the popover.",
|
|
1388
|
+
type: String,
|
|
1389
|
+
default: "click",
|
|
1390
|
+
attribute: "data-bs-trigger"
|
|
1391
|
+
},
|
|
1392
|
+
container: {
|
|
1393
|
+
description: "the popover’s HTML appears within that element.",
|
|
1394
|
+
type: String,
|
|
1395
|
+
default: "body",
|
|
1396
|
+
attribute: "data-bs-container"
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
static get bs() {
|
|
1402
|
+
return Tooltip;
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
constructor() {
|
|
1406
|
+
super();
|
|
1407
|
+
|
|
1408
|
+
// this is an external state managed by bootstrap
|
|
1409
|
+
Object.defineProperty(this.constructor.prototype, "open", {
|
|
1410
|
+
get() {
|
|
1411
|
+
return this.bs?.tip && this.bs?.tip.classList.contains('show');
|
|
1412
|
+
},
|
|
1413
|
+
});
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
disable() {
|
|
1417
|
+
return this.bs?.disable();
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
enable() {
|
|
1421
|
+
return this.bs?.enable();
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
hide() {
|
|
1425
|
+
return this.bs?.hide();
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
show() {
|
|
1429
|
+
return this.bs?.show();
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
toggle() {
|
|
1433
|
+
return this.bs?.toggle();
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
toggleEnabled() {
|
|
1437
|
+
return this.bs?.toggleEnabled();
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
setContent() {
|
|
1441
|
+
return this.bs?.setContent();
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
update() {
|
|
1445
|
+
return this.bs?.update();
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
firstUpdated() {
|
|
1449
|
+
if (!this.hasAttribute("data-bs-toggle")) this.setAttribute("data-bs-toggle", "tooltip");
|
|
1450
|
+
|
|
1451
|
+
this._updateOpenState(true);
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
_updateOpenState(isFirstUpdate = false) {
|
|
1455
|
+
if (isFirstUpdate) this.classList.toggle("show", this.__propValues['open']);
|
|
1456
|
+
else this.toggle();
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
customElements.define("bs-tooltip", BsTooltip);
|
|
1462
|
+
|
|
1463
|
+
class BsPopover extends BsTooltip {
|
|
1464
|
+
|
|
1465
|
+
static get properties() {
|
|
1466
|
+
return {
|
|
1467
|
+
...super.constructor.properties,
|
|
1468
|
+
content: {
|
|
1469
|
+
description: "The content to be displayed within the popover.",
|
|
1470
|
+
type: String,
|
|
1471
|
+
default: "",
|
|
1472
|
+
attribute: "data-bs-content"
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
static get bs() {
|
|
1478
|
+
return Popover;
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
firstUpdated() {
|
|
1482
|
+
if (!this.hasAttribute("data-bs-toggle")) {
|
|
1483
|
+
this.setAttribute("data-bs-toggle", "popover");
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
this._updateOpenState(true);
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
customElements.define("bs-popover", BsPopover);
|
|
1491
|
+
|
|
1492
|
+
class BsTab extends BsElement {
|
|
1493
|
+
|
|
1494
|
+
static get properties() {
|
|
1495
|
+
return {
|
|
1496
|
+
fade: {
|
|
1497
|
+
description: "Control the fade effect when opening or closing the modal.",
|
|
1498
|
+
type: Boolean,
|
|
1499
|
+
default: true
|
|
1500
|
+
},
|
|
1501
|
+
active: {
|
|
1502
|
+
description: "Whether the element is active or not",
|
|
1503
|
+
type: Boolean,
|
|
1504
|
+
default: false
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
static get bs() {
|
|
1510
|
+
return Tab;
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
constructor() {
|
|
1514
|
+
super();
|
|
1515
|
+
|
|
1516
|
+
// this is an external state managed by bootstrap
|
|
1517
|
+
Object.defineProperty(this.constructor.prototype, "active", {
|
|
1518
|
+
get() {
|
|
1519
|
+
return this.classList.contains("active");
|
|
1520
|
+
},
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
show() {
|
|
1525
|
+
return this.bs?.show();
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
firstUpdated() {
|
|
1529
|
+
this.classList.add("tab-pane");
|
|
1530
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "tabpanel");
|
|
1531
|
+
if (!this.hasAttribute("tabindex")) this.setAttribute("tabindex", "0");
|
|
1532
|
+
|
|
1533
|
+
this._updateFadeState();
|
|
1534
|
+
this._updateActiveState(true);
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
_updateFadeState() {
|
|
1538
|
+
this.classList.toggle("fade", this.fade);
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
_updateActiveState(isFirstUpdate = false) {
|
|
1542
|
+
const newState = this.__propValues["active"];
|
|
1543
|
+
if (isFirstUpdate) {
|
|
1544
|
+
this.classList.toggle("show", newState);
|
|
1545
|
+
this.classList.toggle("active", newState);
|
|
1546
|
+
} else {
|
|
1547
|
+
if (newState) this.show();
|
|
1548
|
+
else {
|
|
1549
|
+
this.classList.toggle("show", false);
|
|
1550
|
+
this.classList.toggle("active", false);
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
}
|
|
1556
|
+
|
|
1557
|
+
customElements.define("bs-tab", BsTab);
|
|
1558
|
+
|
|
1559
|
+
class BsToast extends BsElement {
|
|
1560
|
+
|
|
1561
|
+
static get properties() {
|
|
1562
|
+
return {
|
|
1563
|
+
color: {
|
|
1564
|
+
description: "Color of the Toast background.",
|
|
1565
|
+
type: String,
|
|
1566
|
+
default: "",
|
|
1567
|
+
values: ["", "primary", "secondary", "success", "danger", "warning", "info", "light", "dark"]
|
|
1568
|
+
},
|
|
1569
|
+
header: {
|
|
1570
|
+
description: "Customize the modal header content.",
|
|
1571
|
+
type: String,
|
|
1572
|
+
default: undefined
|
|
1573
|
+
},
|
|
1574
|
+
autohide: {
|
|
1575
|
+
description: "Controls whether the Toast component autohides after a certain duration.",
|
|
1576
|
+
type: Boolean,
|
|
1577
|
+
default: false,
|
|
1578
|
+
attribute: "data-bs-autohide"
|
|
1579
|
+
},
|
|
1580
|
+
delay: {
|
|
1581
|
+
description: "The time delay (in milliseconds) before the Toast component autohides.",
|
|
1582
|
+
type: Number,
|
|
1583
|
+
default: 5000,
|
|
1584
|
+
attribute: "data-bs-delay"
|
|
1585
|
+
},
|
|
1586
|
+
animation: {
|
|
1587
|
+
description: "Controls whether the Toast component fades in and out.",
|
|
1588
|
+
type: Boolean,
|
|
1589
|
+
default: true,
|
|
1590
|
+
attribute: "data-bs-animation"
|
|
1591
|
+
},
|
|
1592
|
+
open: {
|
|
1593
|
+
description: "Controls whether the Toast component is initially open.",
|
|
1594
|
+
type: Boolean,
|
|
1595
|
+
default: true
|
|
1596
|
+
},
|
|
1597
|
+
dismissible: {
|
|
1598
|
+
description: "Controls whether the Toast component is dismissible",
|
|
1599
|
+
type: Boolean,
|
|
1600
|
+
default: true
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
static get bs() {
|
|
1606
|
+
return Toast;
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
constructor() {
|
|
1610
|
+
super();
|
|
1611
|
+
|
|
1612
|
+
// this is an external state managed by bootstrap
|
|
1613
|
+
Object.defineProperty(this.constructor.prototype, "open", {
|
|
1614
|
+
get() {
|
|
1615
|
+
return this.classList.contains("show");
|
|
1616
|
+
},
|
|
1617
|
+
});
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
hide() {
|
|
1621
|
+
return this.bs?.hide();
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
show() {
|
|
1625
|
+
return this.bs?.show();
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
isShown() {
|
|
1629
|
+
return this.bs?.isShown();
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
firstUpdated() {
|
|
1633
|
+
this.classList.add("toast");
|
|
1634
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "alert");
|
|
1635
|
+
if (!this.hasAttribute("aria-live")) this.setAttribute("aria-live", "assertive");
|
|
1636
|
+
if (!this.hasAttribute("aria-atomic")) this.setAttribute("aria-atomic", "true");
|
|
1637
|
+
|
|
1638
|
+
this._fixMarkup();
|
|
1639
|
+
this._updateHeaderState();
|
|
1640
|
+
this._updateDismissibleState();
|
|
1641
|
+
this._updateColorState();
|
|
1642
|
+
this._updateOpenState(true);
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
_fixMarkup() {
|
|
1646
|
+
let header = this.querySelector(":scope > .toast-header");
|
|
1647
|
+
if (!header && this.header) {
|
|
1648
|
+
header = document.createElement("div");
|
|
1649
|
+
header.classList.add("toast-header");
|
|
1650
|
+
|
|
1651
|
+
header.insertAdjacentHTML("afterbegin", `<strong class="me-auto">${this.header}</strong>`);
|
|
1652
|
+
|
|
1653
|
+
this.appendChild(header);
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
let body = this.querySelector(":scope > .toast-body");
|
|
1657
|
+
if (!body) {
|
|
1658
|
+
body = document.createElement("div");
|
|
1659
|
+
body.classList.add("toast-body");
|
|
1660
|
+
|
|
1661
|
+
for (let i = 0; i < this.childNodes.length; i++) {
|
|
1662
|
+
if (this.childNodes[i].classList?.contains("toast-header")) continue;
|
|
1663
|
+
body.appendChild(this.childNodes[i]);
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
this.appendChild(body);
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
_updateHeaderState() {
|
|
1671
|
+
let header = this.querySelector(":scope > .toast-header");
|
|
1672
|
+
if (!header && this.header) {
|
|
1673
|
+
this._fixMarkup();
|
|
1674
|
+
header = this.querySelector(":scope > .toast-header");
|
|
1675
|
+
header.textContent = this.header || "";
|
|
1676
|
+
}
|
|
1677
|
+
if (header && !this.header) {
|
|
1678
|
+
header.remove();
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
_updateDismissibleState() {
|
|
1683
|
+
const closeBtn = this.querySelector(".btn-close");
|
|
1684
|
+
if (this.dismissible) {
|
|
1685
|
+
if (!closeBtn) this.firstChild?.insertAdjacentHTML("beforeend",
|
|
1686
|
+
`<button type="button" class="btn-close ms-2 mb-1" data-bs-dismiss="toast" aria-label="Close"></button>`
|
|
1687
|
+
);
|
|
1688
|
+
} else {
|
|
1689
|
+
if (closeBtn) closeBtn.remove();
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
_updateColorState() {
|
|
1694
|
+
this.classList.remove(
|
|
1695
|
+
...this.constructor.properties
|
|
1696
|
+
.color.values.map(v => "bg-" + v)
|
|
1697
|
+
);
|
|
1698
|
+
if (this.color) this.classList.add("bg-" + this.color);
|
|
1699
|
+
|
|
1700
|
+
if (this.color === "" || this.color === "light" || this.color === "warning") {
|
|
1701
|
+
this.classList.remove("text-white");
|
|
1702
|
+
} else {
|
|
1703
|
+
this.classList.add("text-white");
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
_updateOpenState(isFirstUpdate = false) {
|
|
1708
|
+
const newState = this.__propValues['open'];
|
|
1709
|
+
if (isFirstUpdate) this.classList.toggle("show", newState);
|
|
1710
|
+
else {
|
|
1711
|
+
if (newState) this.show();
|
|
1712
|
+
else this.hide();
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
customElements.define("bs-toast", BsToast);
|
|
1719
|
+
|
|
1720
|
+
export { BsAccordion, BsAlert, BsButton, BsCarousel, BsCollapse, BsDropdown, BsModal, BsOffcanvas, BsPopover, BsTab, BsToast, BsTooltip };
|
|
1721
|
+
//# sourceMappingURL=bs-elements.esm.js.map
|