wj-elements 0.1.215 → 0.1.217
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/dist/light.css +10 -1
- package/dist/packages/wje-carousel/carousel.element.d.ts +8 -0
- package/dist/wje-carousel.js +95 -46
- package/dist/wje-carousel.js.map +1 -1
- package/dist/wje-checkbox.js +1 -0
- package/dist/wje-checkbox.js.map +1 -1
- package/dist/wje-chip.js +2 -1
- package/dist/wje-chip.js.map +1 -1
- package/dist/wje-pagination.js +14 -10
- package/dist/wje-pagination.js.map +1 -1
- package/dist/wje-radio.js +1 -1
- package/dist/wje-reorder-item.js +1 -1
- package/package.json +1 -1
package/dist/light.css
CHANGED
|
@@ -330,7 +330,11 @@
|
|
|
330
330
|
--wje-chip-background-hover: var(--wje-color-contrast-4);
|
|
331
331
|
--wje-chip-color-hover: var(--wje-color-contrast-11);
|
|
332
332
|
--wje-chip-border-radius: 100px;
|
|
333
|
-
--wje-chip-
|
|
333
|
+
--wje-chip-round-border-radius: var(--wje-border-radius-large);
|
|
334
|
+
--wje-chip-margin-block: 0;
|
|
335
|
+
--wje-chip-margin-inline: 0;
|
|
336
|
+
--wje-chip-padding-block: var(--wje-spacing-small);
|
|
337
|
+
--wje-chip-padding-inline: var(--wje-spacing-small);
|
|
334
338
|
|
|
335
339
|
/* Dialog */
|
|
336
340
|
--wje-dialog-width: 600px;
|
|
@@ -516,6 +520,11 @@
|
|
|
516
520
|
--wje-orgchart-group-height-line: 10px;
|
|
517
521
|
--wje-orgchart-group-padding: 0.25rem 0;
|
|
518
522
|
|
|
523
|
+
/* Radio */
|
|
524
|
+
--wje-radio-margin-top: 0;
|
|
525
|
+
--wje-radio-margin-bottom: 0.5rem;
|
|
526
|
+
--wje-radio-margin-inline: 0;
|
|
527
|
+
|
|
519
528
|
/* Rate */
|
|
520
529
|
--wje-rate-gap: 0.25rem;
|
|
521
530
|
--wje-rate-color: var(--wje-color-contrast-11);
|
|
@@ -65,6 +65,10 @@ export default class Carousel extends WJElement {
|
|
|
65
65
|
* After draw method for the Carousel.
|
|
66
66
|
*/
|
|
67
67
|
afterDraw(): void;
|
|
68
|
+
/**
|
|
69
|
+
* Sync `activeSlide` to the slide whose center is closest to the container center.
|
|
70
|
+
*/
|
|
71
|
+
syncActiveToCenter(): void;
|
|
68
72
|
/**
|
|
69
73
|
* Sets up the IntersectionObserver for the Carousel.
|
|
70
74
|
*/
|
|
@@ -133,6 +137,10 @@ export default class Carousel extends WJElement {
|
|
|
133
137
|
* @returns {Array}
|
|
134
138
|
*/
|
|
135
139
|
getSlidesWithClones(): any[];
|
|
140
|
+
/** Maps logical index -> visual index (accounts for leading clone when loop=true) */
|
|
141
|
+
getVisualIndexForLogical(index: any): any;
|
|
142
|
+
/** Maps visual index -> logical index (handles clones at 0 and last when loop=true) */
|
|
143
|
+
getLogicalIndexForVisual(vIndex: any): any;
|
|
136
144
|
/**
|
|
137
145
|
* Goes to the slide.
|
|
138
146
|
* @returns {boolean}
|
package/dist/wje-carousel.js
CHANGED
|
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
import WJElement from "./wje-element.js";
|
|
5
|
-
const styles =
|
|
5
|
+
const styles = '/*\n[ Carousel ]\n*/\n\n.native-carousel {\n position: relative;\n width: var(--wje-carousel-width, 100%);\n height: var(--wje-carousel-height, 300px);\n scroll-behavior: smooth;\n}\n\n.slides-wrapper {\n position: relative;\n width: var(--wje-carousel-width, 100%);\n height: var(--wje-carousel-height, 300px);\n}\n\n.carousel-slides {\n display: flex;\n transition: transform 0.5s ease;\n align-items: center;\n justify-items: center;\n overflow: auto;\n overscroll-behavior-x: contain;\n scrollbar-width: none;\n -ms-overflow-style: none;\n aspect-ratio: var(--wje-aspect-ratio, 4 / 3);\n scroll-snap-type: x mandatory;\n scroll-padding-inline: 0;\n overflow-y: hidden;\n padding-inline: var(--wje-spacing-inline, 0);\n gap: 0.5rem;\n}\n\n.carousel-slides::-webkit-scrollbar {\n display: none;\n}\n\n::slotted(wje-carousel-item) {\n flex: 0 0 var(--wje-carousel-size);\n height: 100%;\n}\n\n/*NAVIGATION*/\n\n[name="prev"], [name="next"] {\n display: block;\n position: absolute;\n top: 50%;\n border: none;\n cursor: pointer;\n z-index: 2;\n}\n\n[name="prev"] {\n left: -1rem;\n transform: translate(-100%, -50%);\n}\n\n[name="next"] {\n right: -1rem;\n transform: translate(100%, -50%);\n}\n\n/*PAGINATION*/\n\n.pagination {\n position: relative;\n left: 50%;\n transform: translate(-50%, 0);\n display: flex;\n z-index: 2;\n justify-content: center;\n padding-block: 1rem;\n}\n.pagination-item {\n cursor: pointer;\n height: 15px;\n width: 15px;\n margin: 0 2px;\n background-color: var(--wje-color-contrast-4);\n display: inline-block;\n border-radius: 50%;\n}\n.pagination-item.active {\n background-color: var(--wje-color);\n}\n\n/*THUMBNAILS*/\n\n.thumbnails {\n display: flex;\n justify-content: center;\n align-items: center;\n overflow-x: auto;\n gap: 0.5rem;\n padding: 0 0.5rem;\n margin-top: 0.5rem;\n margin-bottom: 0.5rem;\n box-sizing: border-box;\n overflow-y: hidden;\n wje-thumbnail {\n --wje-thumbnail-width: 48px;\n --wje-thumbnail-height: 48px;\n --wje-thumbnail-border-radius: 0;\n cursor: pointer;\n border: 1px solid transparent;\n }\n .active {\n border: 1px solid var(--wje-color-primary-11);\n }\n}\n';
|
|
6
6
|
class Carousel extends WJElement {
|
|
7
7
|
/**
|
|
8
8
|
* Carousel constructor method.
|
|
@@ -104,20 +104,29 @@ class Carousel extends WJElement {
|
|
|
104
104
|
let fragment = document.createDocumentFragment();
|
|
105
105
|
let native = document.createElement("div");
|
|
106
106
|
native.classList.add("native-carousel");
|
|
107
|
+
let wrapper = document.createElement("div");
|
|
108
|
+
wrapper.classList.add("slides-wrapper");
|
|
107
109
|
let slides = document.createElement("div");
|
|
108
110
|
slides.classList.add("carousel-slides");
|
|
109
111
|
let slot = document.createElement("slot");
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
let slotPrev = document.createElement("slot");
|
|
113
|
+
slotPrev.setAttribute("name", "prev");
|
|
114
|
+
let slotNext = document.createElement("slot");
|
|
115
|
+
slotNext.setAttribute("name", "next");
|
|
116
|
+
slides.append(slot);
|
|
117
|
+
native.append(wrapper);
|
|
112
118
|
if (this.navigation) {
|
|
113
119
|
this.prevButton = this.createPreviousButton();
|
|
114
120
|
this.nextButton = this.createNextButton();
|
|
115
|
-
|
|
116
|
-
|
|
121
|
+
this.append(this.prevButton);
|
|
122
|
+
this.append(this.nextButton);
|
|
123
|
+
wrapper.append(slotPrev);
|
|
124
|
+
wrapper.append(slotNext);
|
|
117
125
|
}
|
|
118
|
-
|
|
119
|
-
if (this.
|
|
120
|
-
|
|
126
|
+
wrapper.append(slides);
|
|
127
|
+
if (this.pagination) native.append(this.createPagination());
|
|
128
|
+
if (this.thumbnails) native.append(this.createThumbnails());
|
|
129
|
+
fragment.append(native);
|
|
121
130
|
this.slides = slides;
|
|
122
131
|
return fragment;
|
|
123
132
|
}
|
|
@@ -133,19 +142,39 @@ class Carousel extends WJElement {
|
|
|
133
142
|
let carouselSize = 100 / +this.slidePerPage;
|
|
134
143
|
this.style.setProperty("--wje-carousel-size", carouselSize + "%");
|
|
135
144
|
this.goToSlide(this.activeSlide, "auto");
|
|
145
|
+
requestAnimationFrame(() => requestAnimationFrame(() => this.syncActiveToCenter()));
|
|
136
146
|
this.slides.addEventListener("scrollend", (e) => {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
+
this.syncActiveToCenter();
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Sync `activeSlide` to the slide whose center is closest to the container center.
|
|
152
|
+
*/
|
|
153
|
+
syncActiveToCenter() {
|
|
154
|
+
this.getSlides();
|
|
155
|
+
const withClones = this.getSlidesWithClones();
|
|
156
|
+
if (!withClones.length) return;
|
|
157
|
+
const containerRect = this.slides.getBoundingClientRect();
|
|
158
|
+
const containerCenterX = containerRect.left + containerRect.width / 2;
|
|
159
|
+
let best = null;
|
|
160
|
+
let bestDist = Infinity;
|
|
161
|
+
withClones.forEach((el) => {
|
|
162
|
+
const r = el.getBoundingClientRect();
|
|
163
|
+
const center = r.left + r.width / 2;
|
|
164
|
+
const dist = Math.abs(center - containerCenterX);
|
|
165
|
+
if (dist < bestDist) {
|
|
166
|
+
bestDist = dist;
|
|
167
|
+
best = el;
|
|
147
168
|
}
|
|
148
169
|
});
|
|
170
|
+
if (!best) return;
|
|
171
|
+
const vIndex = withClones.indexOf(best);
|
|
172
|
+
if (vIndex === -1) return;
|
|
173
|
+
const logicalIndex = this.getLogicalIndexForVisual(vIndex);
|
|
174
|
+
this.activeSlide = logicalIndex;
|
|
175
|
+
if (this.loop && (vIndex === 0 || vIndex === withClones.length - 1)) {
|
|
176
|
+
this.goToSlide(logicalIndex, "auto");
|
|
177
|
+
}
|
|
149
178
|
}
|
|
150
179
|
/**
|
|
151
180
|
* Sets up the IntersectionObserver for the Carousel.
|
|
@@ -176,23 +205,25 @@ class Carousel extends WJElement {
|
|
|
176
205
|
*/
|
|
177
206
|
goToSlide(index, behavior = "smooth", next = true) {
|
|
178
207
|
const slides = this.getSlides();
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
Math.max(index
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
208
|
+
const withClones = this.getSlidesWithClones();
|
|
209
|
+
withClones.forEach((slide) => slide.classList.remove("active"));
|
|
210
|
+
const maxIndex = Math.max(slides.length - 1, 0);
|
|
211
|
+
let logical;
|
|
212
|
+
if (this.loop && slides.length > 0) {
|
|
213
|
+
logical = (index % slides.length + slides.length) % slides.length;
|
|
214
|
+
} else {
|
|
215
|
+
logical = Math.min(Math.max(index, 0), maxIndex);
|
|
216
|
+
}
|
|
217
|
+
this.activeSlide = logical;
|
|
218
|
+
const vIndex = this.getVisualIndexForLogical(logical);
|
|
219
|
+
const targetEl = withClones[vIndex];
|
|
220
|
+
if (!targetEl) return;
|
|
221
|
+
targetEl.classList.add("active");
|
|
222
|
+
const targetRect = targetEl.getBoundingClientRect();
|
|
223
|
+
const containerRect = this.slides.getBoundingClientRect();
|
|
193
224
|
this.slides.scrollTo({
|
|
194
|
-
left:
|
|
195
|
-
top:
|
|
225
|
+
left: targetRect.left - containerRect.left + this.slides.scrollLeft,
|
|
226
|
+
top: targetRect.top - containerRect.top + this.slides.scrollTop,
|
|
196
227
|
behavior: behavior === "smooth" ? "smooth" : "auto"
|
|
197
228
|
});
|
|
198
229
|
if (this.navigation && !this.loop) {
|
|
@@ -210,12 +241,10 @@ class Carousel extends WJElement {
|
|
|
210
241
|
if (items.length && this.loop) {
|
|
211
242
|
const firstItemClone = items[0].cloneNode(true);
|
|
212
243
|
firstItemClone.classList.add("clone");
|
|
213
|
-
|
|
214
|
-
this.appendChild(firstItemClone);
|
|
244
|
+
this.append(firstItemClone);
|
|
215
245
|
const lastItemClone = items[items.length - 1].cloneNode(true);
|
|
216
246
|
lastItemClone.classList.add("clone");
|
|
217
|
-
|
|
218
|
-
this.insertBefore(lastItemClone, this.firstChild);
|
|
247
|
+
this.insertBefore(lastItemClone, items[0]);
|
|
219
248
|
}
|
|
220
249
|
}
|
|
221
250
|
/**
|
|
@@ -268,10 +297,12 @@ class Carousel extends WJElement {
|
|
|
268
297
|
*/
|
|
269
298
|
createNextButton() {
|
|
270
299
|
const nextButton = document.createElement("wje-button");
|
|
271
|
-
nextButton.
|
|
272
|
-
nextButton.innerHTML = '<wje-icon name="chevron-right" size="large"></wje-icon>';
|
|
300
|
+
nextButton.setAttribute("part", "next-button");
|
|
273
301
|
nextButton.setAttribute("circle", "");
|
|
274
302
|
nextButton.setAttribute("fill", "link");
|
|
303
|
+
nextButton.setAttribute("slot", "next");
|
|
304
|
+
nextButton.innerHTML = '<wje-icon name="chevron-right" size="large"></wje-icon>';
|
|
305
|
+
nextButton.classList.add("next");
|
|
275
306
|
nextButton.addEventListener("click", (e) => {
|
|
276
307
|
this.nextSlide();
|
|
277
308
|
});
|
|
@@ -283,10 +314,12 @@ class Carousel extends WJElement {
|
|
|
283
314
|
*/
|
|
284
315
|
createPreviousButton() {
|
|
285
316
|
const previousButton = document.createElement("wje-button");
|
|
286
|
-
previousButton.
|
|
287
|
-
previousButton.innerHTML = '<wje-icon name="chevron-left" size="large"></wje-icon>';
|
|
317
|
+
previousButton.setAttribute("part", "previous-button");
|
|
288
318
|
previousButton.setAttribute("circle", "");
|
|
289
319
|
previousButton.setAttribute("fill", "link");
|
|
320
|
+
previousButton.setAttribute("slot", "prev");
|
|
321
|
+
previousButton.innerHTML = '<wje-icon name="chevron-left" size="large"></wje-icon>';
|
|
322
|
+
previousButton.classList.add("prev");
|
|
290
323
|
previousButton.addEventListener("click", (e) => {
|
|
291
324
|
this.previousSlide();
|
|
292
325
|
});
|
|
@@ -298,6 +331,7 @@ class Carousel extends WJElement {
|
|
|
298
331
|
*/
|
|
299
332
|
createPagination() {
|
|
300
333
|
const pagination = document.createElement("div");
|
|
334
|
+
pagination.setAttribute("part", "pagination");
|
|
301
335
|
pagination.classList.add("pagination");
|
|
302
336
|
const slides = this.getSlides();
|
|
303
337
|
slides.forEach((slide, i) => {
|
|
@@ -308,7 +342,7 @@ class Carousel extends WJElement {
|
|
|
308
342
|
e.target.classList.add("active");
|
|
309
343
|
this.goToSlide(i);
|
|
310
344
|
});
|
|
311
|
-
pagination.
|
|
345
|
+
pagination.append(paginationItem);
|
|
312
346
|
});
|
|
313
347
|
return pagination;
|
|
314
348
|
}
|
|
@@ -328,7 +362,7 @@ class Carousel extends WJElement {
|
|
|
328
362
|
e.target.closest("wje-thumbnail").classList.add("active");
|
|
329
363
|
this.goToSlide(i);
|
|
330
364
|
});
|
|
331
|
-
thumbnails.
|
|
365
|
+
thumbnails.append(thumbnail);
|
|
332
366
|
});
|
|
333
367
|
return thumbnails;
|
|
334
368
|
}
|
|
@@ -358,19 +392,34 @@ class Carousel extends WJElement {
|
|
|
358
392
|
getSlidesWithClones() {
|
|
359
393
|
return Array.from(this.querySelectorAll("wje-carousel-item"));
|
|
360
394
|
}
|
|
395
|
+
/** Maps logical index -> visual index (accounts for leading clone when loop=true) */
|
|
396
|
+
getVisualIndexForLogical(index) {
|
|
397
|
+
return this.loop ? index + 1 : index;
|
|
398
|
+
}
|
|
399
|
+
/** Maps visual index -> logical index (handles clones at 0 and last when loop=true) */
|
|
400
|
+
getLogicalIndexForVisual(vIndex) {
|
|
401
|
+
const slides = this.getSlides();
|
|
402
|
+
const withClones = this.getSlidesWithClones();
|
|
403
|
+
if (!this.loop) return vIndex;
|
|
404
|
+
if (vIndex === 0) return slides.length - 1;
|
|
405
|
+
if (vIndex === withClones.length - 1) return 0;
|
|
406
|
+
return vIndex - 1;
|
|
407
|
+
}
|
|
361
408
|
/**
|
|
362
409
|
* Goes to the slide.
|
|
363
410
|
* @returns {boolean}
|
|
364
411
|
*/
|
|
365
412
|
canGoNext() {
|
|
366
|
-
|
|
413
|
+
const el = this.context.querySelector(".carousel-slides");
|
|
414
|
+
return el.scrollLeft < el.scrollWidth - el.clientWidth;
|
|
367
415
|
}
|
|
368
416
|
/**
|
|
369
417
|
* Goes to the slide.
|
|
370
418
|
* @returns {boolean}
|
|
371
419
|
*/
|
|
372
420
|
canGoPrevious() {
|
|
373
|
-
|
|
421
|
+
const el = this.context.querySelector(".carousel-slides");
|
|
422
|
+
return el.scrollLeft > 0;
|
|
374
423
|
}
|
|
375
424
|
}
|
|
376
425
|
WJElement.define("wje-carousel", Carousel);
|
package/dist/wje-carousel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wje-carousel.js","sources":["../packages/wje-carousel/carousel.element.js","../packages/wje-carousel/carousel.js"],"sourcesContent":["import { default as WJElement, event } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary Carousel class that extends WJElement.\n * @documentation https://elements.webjet.sk/components/carousel\n * @status stable\n * @augments WJElement\n * @slot - The carousel main content.\n * @cssproperty [--wje-carousel-size=100%] - Size of the carousel component;\n */\nexport default class Carousel extends WJElement {\n /**\n * Carousel constructor method.\n */\n constructor() {\n super();\n\n this.slidePerPage = 1;\n }\n\n /**\n * Active slide attribute.\n * @param value\n */\n set activeSlide(value) {\n this.setAttribute('active-slide', value);\n }\n\n /**\n * Active slide attribute.\n * @returns {number|number}\n */\n get activeSlide() {\n return +this.getAttribute('active-slide') || 0;\n }\n\n /**\n * Pagination attribute.\n * @returns {boolean}\n */\n get pagination() {\n return this.hasAttribute('pagination');\n }\n\n /**\n * Navigation attribute.\n * @returns {boolean}\n */\n get navigation() {\n return this.hasAttribute('navigation');\n }\n\n /**\n * Thumbnails attribute.\n * @returns {boolean}\n */\n get thumbnails() {\n return this.hasAttribute('thumbnails');\n }\n\n /**\n * Loop attribute.\n * @returns {boolean}\n */\n get loop() {\n return this.hasAttribute('loop');\n }\n\n /**\n * Class name for the Carousel.\n * @type {string}\n */\n className = 'Carousel';\n\n /**\n * Getter for the CSS stylesheet.\n * @returns {*}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Getter for the observed attributes.\n * @returns {string[]}\n */\n static get observedAttributes() {\n return ['active-slide'];\n }\n\n /**\n * Sets up the attributes for the Carousel.\n * @param name\n * @param old\n * @param newName\n */\n attributeChangedCallback(name, old, newName) {\n if (name === 'active-slide') {\n if (this.pagination) this.changePagination();\n\n if (this.thumbnails) this.changeThumbnails();\n }\n }\n\n /**\n * Sets up the attributes for the Carousel.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Before draw method for the Carousel.\n */\n beforeDraw() {\n this.cloneFirstAndLastItems();\n }\n\n /**\n * Draw method for the Carousel.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.classList.add('native-carousel');\n\n let slides = document.createElement('div');\n slides.classList.add('carousel-slides');\n\n let slot = document.createElement('slot');\n\n slides.appendChild(slot);\n native.appendChild(slides);\n\n if (this.navigation) {\n this.prevButton = this.createPreviousButton();\n this.nextButton = this.createNextButton();\n\n native.appendChild(this.prevButton);\n native.appendChild(this.nextButton);\n }\n\n if (this.pagination) native.appendChild(this.createPagination());\n\n if (this.thumbnails) native.appendChild(this.createThumbnails());\n\n fragment.appendChild(native);\n\n this.slides = slides;\n\n return fragment;\n }\n\n /**\n * After draw method for the Carousel.\n */\n afterDraw() {\n this.setIntersectionObserver();\n this.getSlidesWithClones().forEach((slide, i) => {\n this.intersectionObserver.observe(slide);\n });\n\n this.slidePerPage = this.getAttribute('slide-per-page') || 1;\n let carouselSize = 100 / +this.slidePerPage;\n this.style.setProperty('--wje-carousel-size', carouselSize + '%');\n\n this.goToSlide(this.activeSlide, 'auto');\n\n this.slides.addEventListener('scrollend', (e) => {\n const slides = this.getSlides();\n const entries = [...this.entriesMap.values()];\n const visibleEntries = entries.find((entry) => entry.isIntersecting);\n\n if (visibleEntries?.target.classList.contains('clone')) {\n const cloneIndex = +visibleEntries.target.getAttribute('clone-index');\n this.goToSlide(cloneIndex, 'auto');\n this.activeSlide = cloneIndex;\n } else if (visibleEntries) {\n let slideIndex = slides.indexOf(visibleEntries.target);\n this.activeSlide = slideIndex;\n }\n });\n }\n\n /**\n * Sets up the IntersectionObserver for the Carousel.\n */\n setIntersectionObserver() {\n this.intersectionObserver = new IntersectionObserver(\n (entries) => {\n entries.forEach((entry) => {\n this.entriesMap.set(entry.target, entry);\n });\n },\n {\n root: this.context.querySelector('.carousel-slides'),\n threshold: 0.5,\n }\n );\n\n this.entriesMap = new Map();\n this.records = this.intersectionObserver.takeRecords();\n this.records.forEach((entry) => {\n this.entriesMap.set(entry.target, entry);\n });\n }\n\n /**\n * Goes to the slide.\n * @param index\n * @param behavior\n * @param next\n */\n goToSlide(index, behavior = 'smooth', next = true) {\n const slides = this.getSlides();\n const slideWithClones = this.getSlidesWithClones();\n\n // remove active class from all slides\n slideWithClones.forEach((slide, i) => {\n slide.classList.remove('active');\n });\n\n let newActiveSlide = this.loop\n ? (index + slides.length) % slides.length\n : Math.min(Math.max(index, 0), slides.length - 1);\n this.activeSlide = newActiveSlide;\n\n const nextSlideIndex = Math.min(\n Math.max(index + (this.loop ? this.slidePerPage : 0), 0),\n slideWithClones.length - 1\n );\n const nextSlideEl = this.getSlidesWithClones()[nextSlideIndex];\n nextSlideEl.classList.add('active');\n\n let nextSlideRect = nextSlideEl.getBoundingClientRect();\n let slidesContainerRect = this.slides.getBoundingClientRect();\n\n this.slides.scrollTo({\n left: nextSlideRect.left - slidesContainerRect.left + this.slides.scrollLeft,\n top: nextSlideRect.top - slidesContainerRect.top + this.slides.scrollTop,\n behavior: behavior === 'smooth' ? 'smooth' : 'auto',\n });\n\n if (this.navigation && !this.loop) {\n this.nextButton.removeAttribute('disabled');\n this.prevButton.removeAttribute('disabled');\n\n if (this.activeSlide === slides.length - 1) this.nextButton.setAttribute('disabled', '');\n\n if (this.activeSlide === 0) this.prevButton.setAttribute('disabled', '');\n }\n }\n\n /**\n * Clones the first and last items.\n */\n cloneFirstAndLastItems() {\n const items = this.getSlides();\n\n if (items.length && this.loop) {\n // Klonovánie prveho položky a pridanie na koniec\n const firstItemClone = items[0].cloneNode(true);\n firstItemClone.classList.add('clone');\n firstItemClone.setAttribute('clone-index', 0);\n\n this.appendChild(firstItemClone);\n\n // Klonovanie poslednej položky a pridanie na zaciatok\n const lastItemClone = items[items.length - 1].cloneNode(true);\n lastItemClone.classList.add('clone');\n lastItemClone.setAttribute('clone-index', items.length - 1);\n\n this.insertBefore(lastItemClone, this.firstChild);\n }\n }\n\n /**\n * Goes to the next slide.\n */\n removeActiveSlide() {\n this.getSlidesWithClones().forEach((slide, i) => {\n slide.classList.remove('active');\n });\n\n if (this.pagination) {\n this.context.querySelectorAll('.pagination-item').forEach((item) => {\n item.classList.remove('active');\n });\n }\n\n if (this.thumbnails) {\n this.context.querySelectorAll('wje-thumbnail').forEach((item) => {\n item.classList.remove('active');\n });\n }\n }\n\n /**\n * Goes to the next slide.\n */\n changePagination() {\n if (this.pagination) {\n this.removeActiveSlide();\n this.context.querySelectorAll('.pagination-item').forEach((item, i) => {\n if (i === this.activeSlide) {\n item.classList.add('active');\n }\n });\n }\n }\n\n /**\n * Goes to the next slide.\n */\n changeThumbnails() {\n if (this.thumbnails) {\n this.removeActiveSlide();\n this.context.querySelectorAll('wje-thumbnail').forEach((item, i) => {\n if (i === this.activeSlide) {\n item.classList.add('active');\n }\n });\n }\n }\n\n /**\n * Goes to the next slide.\n * @returns {Element}\n */\n createNextButton() {\n const nextButton = document.createElement('wje-button');\n nextButton.classList.add('next');\n nextButton.innerHTML = '<wje-icon name=\"chevron-right\" size=\"large\"></wje-icon>';\n nextButton.setAttribute('circle', '');\n nextButton.setAttribute('fill', 'link');\n nextButton.addEventListener('click', (e) => {\n this.nextSlide();\n });\n\n return nextButton;\n }\n\n /**\n * Goes to the next slide.\n * @returns {Element}\n */\n createPreviousButton() {\n const previousButton = document.createElement('wje-button');\n previousButton.classList.add('prev');\n previousButton.innerHTML = '<wje-icon name=\"chevron-left\" size=\"large\"></wje-icon>';\n previousButton.setAttribute('circle', '');\n previousButton.setAttribute('fill', 'link');\n previousButton.addEventListener('click', (e) => {\n this.previousSlide();\n });\n\n return previousButton;\n }\n\n /**\n * Goes to the next slide.\n * @returns {Element}\n */\n createPagination() {\n const pagination = document.createElement('div');\n pagination.classList.add('pagination');\n\n const slides = this.getSlides();\n slides.forEach((slide, i) => {\n const paginationItem = document.createElement('div');\n paginationItem.classList.add('pagination-item');\n paginationItem.addEventListener('click', (e) => {\n this.removeActiveSlide();\n e.target.classList.add('active');\n this.goToSlide(i);\n });\n pagination.appendChild(paginationItem);\n });\n\n return pagination;\n }\n\n /**\n * Goes to the next slide.\n * @returns {Element}\n */\n createThumbnails() {\n const thumbnails = document.createElement('div');\n thumbnails.classList.add('thumbnails');\n\n const slides = this.getSlides();\n slides.forEach((slide, i) => {\n const thumbnail = document.createElement('wje-thumbnail');\n thumbnail.innerHTML = `<img src=\"${slide.querySelector('wje-img').getAttribute('src')}\"></img>`;\n thumbnail.addEventListener('click', (e) => {\n this.removeActiveSlide();\n e.target.closest('wje-thumbnail').classList.add('active');\n this.goToSlide(i);\n });\n thumbnails.appendChild(thumbnail);\n });\n\n return thumbnails;\n }\n\n /**\n * Goes to the next slide.\n */\n nextSlide() {\n this.goToSlide(this.activeSlide + this.slidePerPage);\n }\n\n /**\n * Goes to the previous slide.\n */\n previousSlide() {\n this.goToSlide(this.activeSlide - this.slidePerPage);\n }\n\n /**\n * Goes to the slide.\n * @returns {Array}\n */\n getSlides() {\n return Array.from(this.querySelectorAll('wje-carousel-item:not(.clone)'));\n }\n\n /**\n * Goes to the slide.\n * @returns {Array}\n */\n getSlidesWithClones() {\n return Array.from(this.querySelectorAll('wje-carousel-item'));\n }\n\n /**\n * Goes to the slide.\n * @returns {boolean}\n */\n canGoNext() {\n return this.querySelector('.native-carousel').scrollLeft < this.querySelector('.native-carousel').scrollWidth;\n }\n\n /**\n * Goes to the slide.\n * @returns {boolean}\n */\n canGoPrevious() {\n return this.querySelector('.native-carousel').scrollLeft > 0;\n }\n}\n","import { default as WJElement } from '../wje-element/element.js';\nimport Carousel from './carousel.element.js';\n\n// export * from \"./carousel.element.js\";\nexport default Carousel;\n\nWJElement.define('wje-carousel', Carousel);\n"],"names":[],"mappings":";;;;;AAWe,MAAM,iBAAiB,UAAU;AAAA;AAAA;AAAA;AAAA,EAI5C,cAAc;AACV,UAAO;AAy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,+BAA+B,CAAC;AAAA,EAChF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,sBAAsB;AAClB,WAAO,MAAM,KAAK,KAAK,iBAAiB,mBAAmB,CAAC;AAAA,EACpE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,YAAY;AACR,WAAO,KAAK,cAAc,kBAAkB,EAAE,aAAa,KAAK,cAAc,kBAAkB,EAAE;AAAA,EAC1G;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,gBAAgB;AACZ,WAAO,KAAK,cAAc,kBAAkB,EAAE,aAAa;AAAA,EACnE;AACA;AC/bA,UAAU,OAAO,gBAAgB,QAAQ;"}
|
|
1
|
+
{"version":3,"file":"wje-carousel.js","sources":["../packages/wje-carousel/carousel.element.js","../packages/wje-carousel/carousel.js"],"sourcesContent":["import { default as WJElement, event } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary Carousel class that extends WJElement.\n * @documentation https://elements.webjet.sk/components/carousel\n * @status stable\n * @augments WJElement\n * @slot - The carousel main content.\n * @cssproperty [--wje-carousel-size=100%] - Size of the carousel component;\n */\nexport default class Carousel extends WJElement {\n /**\n * Carousel constructor method.\n */\n constructor() {\n super();\n\n this.slidePerPage = 1;\n }\n\n /**\n * Active slide attribute.\n * @param value\n */\n set activeSlide(value) {\n this.setAttribute('active-slide', value);\n }\n\n /**\n * Active slide attribute.\n * @returns {number|number}\n */\n get activeSlide() {\n return +this.getAttribute('active-slide') || 0;\n }\n\n /**\n * Pagination attribute.\n * @returns {boolean}\n */\n get pagination() {\n return this.hasAttribute('pagination');\n }\n\n /**\n * Navigation attribute.\n * @returns {boolean}\n */\n get navigation() {\n return this.hasAttribute('navigation');\n }\n\n /**\n * Thumbnails attribute.\n * @returns {boolean}\n */\n get thumbnails() {\n return this.hasAttribute('thumbnails');\n }\n\n /**\n * Loop attribute.\n * @returns {boolean}\n */\n get loop() {\n return this.hasAttribute('loop');\n }\n\n /**\n * Class name for the Carousel.\n * @type {string}\n */\n className = 'Carousel';\n\n /**\n * Getter for the CSS stylesheet.\n * @returns {*}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Getter for the observed attributes.\n * @returns {string[]}\n */\n static get observedAttributes() {\n return ['active-slide'];\n }\n\n /**\n * Sets up the attributes for the Carousel.\n * @param name\n * @param old\n * @param newName\n */\n attributeChangedCallback(name, old, newName) {\n if (name === 'active-slide') {\n if (this.pagination) this.changePagination();\n\n if (this.thumbnails) this.changeThumbnails();\n }\n }\n\n /**\n * Sets up the attributes for the Carousel.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Before draw method for the Carousel.\n */\n beforeDraw() {\n this.cloneFirstAndLastItems();\n }\n\n /**\n * Draw method for the Carousel.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.classList.add('native-carousel');\n\n let wrapper = document.createElement('div');\n wrapper.classList.add('slides-wrapper');\n\n let slides = document.createElement('div');\n slides.classList.add('carousel-slides');\n\n let slot = document.createElement('slot');\n\n let slotPrev = document.createElement('slot');\n slotPrev.setAttribute('name', 'prev');\n\n let slotNext = document.createElement('slot');\n slotNext.setAttribute('name', 'next');\n\n slides.append(slot);\n native.append(wrapper);\n\n if (this.navigation) {\n this.prevButton = this.createPreviousButton();\n this.nextButton = this.createNextButton();\n\n this.append(this.prevButton);\n this.append(this.nextButton);\n\n wrapper.append(slotPrev);\n wrapper.append(slotNext);\n }\n\n wrapper.append(slides);\n\n if (this.pagination) native.append(this.createPagination());\n\n if (this.thumbnails) native.append(this.createThumbnails());\n\n fragment.append(native);\n\n this.slides = slides;\n\n return fragment;\n }\n\n /**\n * After draw method for the Carousel.\n */\n afterDraw() {\n this.setIntersectionObserver();\n this.getSlidesWithClones().forEach((slide, i) => {\n this.intersectionObserver.observe(slide);\n });\n\n this.slidePerPage = this.getAttribute('slide-per-page') || 1;\n let carouselSize = 100 / +this.slidePerPage;\n this.style.setProperty('--wje-carousel-size', carouselSize + '%');\n\n this.goToSlide(this.activeSlide, 'auto');\n\n requestAnimationFrame(() => requestAnimationFrame(() => this.syncActiveToCenter()));\n\n this.slides.addEventListener('scrollend', (e) => {\n this.syncActiveToCenter();\n });\n }\n\n /**\n * Sync `activeSlide` to the slide whose center is closest to the container center.\n */\n syncActiveToCenter() {\n const slides = this.getSlides();\n const withClones = this.getSlidesWithClones();\n if (!withClones.length) return;\n\n const containerRect = this.slides.getBoundingClientRect();\n const containerCenterX = containerRect.left + containerRect.width / 2;\n\n let best = null;\n let bestDist = Infinity;\n withClones.forEach((el) => {\n const r = el.getBoundingClientRect();\n const center = r.left + r.width / 2;\n const dist = Math.abs(center - containerCenterX);\n if (dist < bestDist) {\n bestDist = dist;\n best = el;\n }\n });\n\n if (!best) return;\n\n const vIndex = withClones.indexOf(best);\n if (vIndex === -1) return;\n\n const logicalIndex = this.getLogicalIndexForVisual(vIndex);\n this.activeSlide = logicalIndex;\n\n // If we landed on a clone, silently snap to the corresponding real slide\n if (this.loop && (vIndex === 0 || vIndex === withClones.length - 1)) {\n this.goToSlide(logicalIndex, 'auto');\n }\n }\n\n /**\n * Sets up the IntersectionObserver for the Carousel.\n */\n setIntersectionObserver() {\n this.intersectionObserver = new IntersectionObserver(\n (entries) => {\n entries.forEach((entry) => {\n this.entriesMap.set(entry.target, entry);\n });\n },\n {\n root: this.context.querySelector('.carousel-slides'),\n threshold: 0.5,\n }\n );\n\n this.entriesMap = new Map();\n this.records = this.intersectionObserver.takeRecords();\n this.records.forEach((entry) => {\n this.entriesMap.set(entry.target, entry);\n });\n }\n\n /**\n * Goes to the slide.\n * @param index\n * @param behavior\n * @param next\n */\n goToSlide(index, behavior = 'smooth', next = true) {\n const slides = this.getSlides();\n const withClones = this.getSlidesWithClones();\n\n // remove active class from all slides (including clones)\n withClones.forEach(slide => slide.classList.remove('active'));\n\n // compute logical index: wrap when loop=true, else clamp\n const maxIndex = Math.max(slides.length - 1, 0);\n let logical;\n if (this.loop && slides.length > 0) {\n logical = ((index % slides.length) + slides.length) % slides.length; // safe modulo\n } else {\n logical = Math.min(Math.max(index, 0), maxIndex);\n }\n this.activeSlide = logical;\n\n // compute visual target considering clones when loop=true\n const vIndex = this.getVisualIndexForLogical(logical);\n const targetEl = withClones[vIndex];\n if (!targetEl) return;\n\n targetEl.classList.add('active');\n\n const targetRect = targetEl.getBoundingClientRect();\n const containerRect = this.slides.getBoundingClientRect();\n\n this.slides.scrollTo({\n left: targetRect.left - containerRect.left + this.slides.scrollLeft,\n top: targetRect.top - containerRect.top + this.slides.scrollTop,\n behavior: behavior === 'smooth' ? 'smooth' : 'auto',\n });\n\n if (this.navigation && !this.loop) {\n this.nextButton.removeAttribute('disabled');\n this.prevButton.removeAttribute('disabled');\n\n if (this.activeSlide === slides.length - 1) this.nextButton.setAttribute('disabled', '');\n if (this.activeSlide === 0) this.prevButton.setAttribute('disabled', '');\n }\n }\n\n /**\n * Clones the first and last items.\n */\n cloneFirstAndLastItems() {\n const items = this.getSlides();\n\n if (items.length && this.loop) {\n // Clone first -> append to end\n const firstItemClone = items[0].cloneNode(true);\n firstItemClone.classList.add('clone');\n this.append(firstItemClone);\n\n // Clone last -> insert before the first original item so it becomes the leading clone\n const lastItemClone = items[items.length - 1].cloneNode(true);\n lastItemClone.classList.add('clone');\n this.insertBefore(lastItemClone, items[0]);\n }\n }\n\n /**\n * Goes to the next slide.\n */\n removeActiveSlide() {\n this.getSlidesWithClones().forEach((slide, i) => {\n slide.classList.remove('active');\n });\n\n if (this.pagination) {\n this.context.querySelectorAll('.pagination-item').forEach((item) => {\n item.classList.remove('active');\n });\n }\n\n if (this.thumbnails) {\n this.context.querySelectorAll('wje-thumbnail').forEach((item) => {\n item.classList.remove('active');\n });\n }\n }\n\n /**\n * Goes to the next slide.\n */\n changePagination() {\n if (this.pagination) {\n this.removeActiveSlide();\n this.context.querySelectorAll('.pagination-item').forEach((item, i) => {\n if (i === this.activeSlide) {\n item.classList.add('active');\n }\n });\n }\n }\n\n /**\n * Goes to the next slide.\n */\n changeThumbnails() {\n if (this.thumbnails) {\n this.removeActiveSlide();\n this.context.querySelectorAll('wje-thumbnail').forEach((item, i) => {\n if (i === this.activeSlide) {\n item.classList.add('active');\n }\n });\n }\n }\n\n /**\n * Goes to the next slide.\n * @returns {Element}\n */\n createNextButton() {\n const nextButton = document.createElement('wje-button');\n nextButton.setAttribute('part', 'next-button');\n nextButton.setAttribute('circle', '');\n nextButton.setAttribute('fill', 'link');\n nextButton.setAttribute('slot', 'next');\n nextButton.innerHTML = '<wje-icon name=\"chevron-right\" size=\"large\"></wje-icon>';\n nextButton.classList.add('next');\n nextButton.addEventListener('click', (e) => {\n this.nextSlide();\n });\n\n return nextButton;\n }\n\n /**\n * Goes to the next slide.\n * @returns {Element}\n */\n createPreviousButton() {\n const previousButton = document.createElement('wje-button');\n previousButton.setAttribute('part', 'previous-button');\n previousButton.setAttribute('circle', '');\n previousButton.setAttribute('fill', 'link');\n previousButton.setAttribute('slot', 'prev');\n previousButton.innerHTML = '<wje-icon name=\"chevron-left\" size=\"large\"></wje-icon>';\n previousButton.classList.add('prev');\n previousButton.addEventListener('click', (e) => {\n this.previousSlide();\n });\n\n return previousButton;\n }\n\n /**\n * Goes to the next slide.\n * @returns {Element}\n */\n createPagination() {\n const pagination = document.createElement('div');\n pagination.setAttribute('part', 'pagination');\n pagination.classList.add('pagination');\n\n const slides = this.getSlides();\n slides.forEach((slide, i) => {\n const paginationItem = document.createElement('div');\n paginationItem.classList.add('pagination-item');\n paginationItem.addEventListener('click', (e) => {\n this.removeActiveSlide();\n e.target.classList.add('active');\n this.goToSlide(i);\n });\n pagination.append(paginationItem);\n });\n\n return pagination;\n }\n\n /**\n * Goes to the next slide.\n * @returns {Element}\n */\n createThumbnails() {\n const thumbnails = document.createElement('div');\n thumbnails.classList.add('thumbnails');\n\n const slides = this.getSlides();\n slides.forEach((slide, i) => {\n const thumbnail = document.createElement('wje-thumbnail');\n thumbnail.innerHTML = `<img src=\"${slide.querySelector('wje-img').getAttribute('src')}\"></img>`;\n thumbnail.addEventListener('click', (e) => {\n this.removeActiveSlide();\n e.target.closest('wje-thumbnail').classList.add('active');\n this.goToSlide(i);\n });\n thumbnails.append(thumbnail);\n });\n\n return thumbnails;\n }\n\n /**\n * Goes to the next slide.\n */\n nextSlide() {\n this.goToSlide(this.activeSlide + this.slidePerPage);\n }\n\n /**\n * Goes to the previous slide.\n */\n previousSlide() {\n this.goToSlide(this.activeSlide - this.slidePerPage);\n }\n\n /**\n * Goes to the slide.\n * @returns {Array}\n */\n getSlides() {\n return Array.from(this.querySelectorAll('wje-carousel-item:not(.clone)'));\n }\n\n /**\n * Goes to the slide.\n * @returns {Array}\n */\n getSlidesWithClones() {\n return Array.from(this.querySelectorAll('wje-carousel-item'));\n }\n\n /** Maps logical index -> visual index (accounts for leading clone when loop=true) */\n getVisualIndexForLogical(index) {\n return this.loop ? index + 1 : index;\n }\n\n /** Maps visual index -> logical index (handles clones at 0 and last when loop=true) */\n getLogicalIndexForVisual(vIndex) {\n const slides = this.getSlides();\n const withClones = this.getSlidesWithClones();\n if (!this.loop) return vIndex;\n if (vIndex === 0) return slides.length - 1; // leading clone\n if (vIndex === withClones.length - 1) return 0; // trailing clone\n return vIndex - 1;\n }\n\n /**\n * Goes to the slide.\n * @returns {boolean}\n */\n canGoNext() {\n const el = this.context.querySelector('.carousel-slides');\n return el.scrollLeft < (el.scrollWidth - el.clientWidth);\n }\n\n /**\n * Goes to the slide.\n * @returns {boolean}\n */\n canGoPrevious() {\n const el = this.context.querySelector('.carousel-slides');\n return el.scrollLeft > 0;\n }\n}\n","import { default as WJElement } from '../wje-element/element.js';\nimport Carousel from './carousel.element.js';\n\n// export * from \"./carousel.element.js\";\nexport default Carousel;\n\nWJElement.define('wje-carousel', Carousel);\n"],"names":[],"mappings":";;;;;AAWe,MAAM,iBAAiB,UAAU;AAAA;AAAA;AAAA;AAAA,EAI5C,cAAc;AACV,UAAO;AAyDX;AAAA;AAAA;AAA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;AAC7C,WAAO,SAAS;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,YAAY;AACR,UAAM,KAAK,KAAK,QAAQ,cAAc,kBAAkB;AACxD,WAAO,GAAG,aAAc,GAAG,cAAc,GAAG;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,gBAAgB;AACZ,UAAM,KAAK,KAAK,QAAQ,cAAc,kBAAkB;AACxD,WAAO,GAAG,aAAa;AAAA,EAC/B;AACA;AC7fA,UAAU,OAAO,gBAAgB,QAAQ;"}
|
package/dist/wje-checkbox.js
CHANGED
|
@@ -204,6 +204,7 @@ class Checkbox extends FormAssociatedElement {
|
|
|
204
204
|
* Adds an event listener after drawing the checkbox.
|
|
205
205
|
*/
|
|
206
206
|
afterDraw() {
|
|
207
|
+
this.internals.setFormValue(this.checked ? this.value : null);
|
|
207
208
|
if (!this.disabled) {
|
|
208
209
|
this.input.addEventListener("input", (e) => {
|
|
209
210
|
this.validate();
|
package/dist/wje-checkbox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wje-checkbox.js","sources":["../packages/wje-checkbox/checkbox.element.js","../packages/wje-checkbox/checkbox.js"],"sourcesContent":["import { FormAssociatedElement } from '../internals/form-associated-element.js';\nimport { event } from '../utils/event.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary This method dispatches a custom event named \"wje-toggle:change\".\n * It is triggered when the input event is fired, which happens when the state of the checkbox changes.\n * The event is dispatched on the current instance of the Checkbox class.\n * @documentation https://elements.webjet.sk/components/checkbox\n * @status stable\n * @augments {FormAssociatedElement}\n * @slot - The checkbox main content.\n * @csspart native - The component's native wrapper.\n * @cssproperty [--wje-checkbox-border-radius=--wje-border-radius-medium] - Border radius of the component;\n * @cssproperty [--wje-checkbox-border-width=1px] - Border width of the component;\n * @cssproperty [--wje-checkbox-border-style=solid] - Border style of the component;\n * @cssproperty [--wje-checkbox-border-color=--wje-color-contrast-1] - Border color of the component;\n * @cssproperty [--wje-checkbox-margin-inline=0] - Margin inline of the component;\n */\nexport default class Checkbox extends FormAssociatedElement {\n\t#internalValue;\n\t/**\n\t * Checkbox constructor method.\n\t */\n\tconstructor() {\n\t\tsuper();\n\n\t\tthis.invalid = false;\n\t\tthis.pristine = true;\n\t}\n\n\t/**\n\t * Setter for the value attribute.\n\t * @param {string} value The value to set.\n\t */\n\tset value(value) {\n\t\tthis.#internalValue = value;\n\t\tif (this.input) {\n\t\t\tthis.input.value = value;\n\t\t}\n\t}\n\n\t/**\n\t * Getter for the value attribute.\n\t * @returns {string} The value of the attribute.\n\t */\n\tget value() {\n\t\treturn this.#internalValue ?? this.getAttribute('value') ?? 'on';;\n\t}\n\n\t/**\n\t * Getter for the customErrorDisplay attribute.\n\t * @returns {boolean} Whether the attribute is present.\n\t */\n\tget customErrorDisplay() {\n\t\treturn this.hasAttribute('custom-error-display');\n\t}\n\n\t/**\n\t * Getter for the validateOnChange attribute.\n\t * @returns {boolean} Whether the attribute is present.\n\t */\n\tget validateOnChange() {\n\t\treturn this.hasAttribute('validate-on-change');\n\t}\n\n\t/**\n\t * Setter for the defaultValue attribute.\n\t * This method sets the 'value' attribute of the custom input element to the provided value.\n\t * The 'value' attribute represents the default value of the input element.\n\t * @param {string} value The value to set as the default value.\n\t */\n\tset defaultValue(value) {\n\t\tthis.setAttribute('value', value);\n\t}\n\n\t/**\n\t * Getter for the defaultValue attribute.\n\t * This method retrieves the 'value' attribute of the custom input element.\n\t * The 'value' attribute represents the default value of the input element.\n\t * If the 'value' attribute is not set, it returns an empty string.\n\t * @returns {string} The default value of the input element.\n\t */\n\tget defaultValue() {\n\t\treturn this.getAttribute('value') ?? '';\n\t}\n\n\t/**\n\t * Sets or removes the 'indeterminate' attribute for the object.\n\t * This property typically reflects the visual or functional state where\n\t * the component is neither fully active nor inactive.\n\t * @param {boolean} value A boolean where `true` indicates the 'indeterminate'\n\t * state should be set, and `false` removes it.\n\t */\n\tset indeterminate(value) {\n\t\tif (value) {\n\t\t\tthis.setAttribute('indeterminate', '');\n\t\t} else {\n\t\t\tthis.removeAttribute('indeterminate');\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves the current state of the 'indeterminate' attribute.\n\t *\n\t * The 'indeterminate' attribute is typically used to signify a state\n\t * where a checkbox is neither checked nor unchecked, such as a partially\n\t * selected state.\n\t * @returns {boolean} Returns true if the 'indeterminate' attribute is present; otherwise, false.\n\t */\n\tget indeterminate() {\n\t\treturn this.hasAttribute('indeterminate');\n\t}\n\n\t/**\n\t * Set checked attribute.\n\t * @param {boolean} value true if the toggle is checked, false otherwise\n\t */\n\tset checked(value) {\n\t\tif (value) {\n\t\t\tthis.setAttribute('checked', '');\n\t\t\tthis.internals.setFormValue(this.value); // len ak je checked\n\t\t} else {\n\t\t\tthis.removeAttribute('checked');\n\t\t\tthis.internals.setFormValue(null); // ak nie je checked, nič sa neposiela\n\t\t}\n\t\tif (this.input) {\n\t\t\tthis.input.checked = value;\n\t\t}\n\t}\n\n\t/**\n\t * Get checked attribute.\n\t * @returns {boolean} true if the toggle is checked, false otherwise\n\t */\n\tget checked() {\n\t\treturn this.hasAttribute('checked');\n\t}\n\n\t/**\n\t * The class name for the Checkbox.\n\t */\n\tclassName = 'Checkbox';\n\n\t/**\n\t * Getter for the CSS stylesheet.\n\t * @returns {string} The CSS stylesheet.\n\t */\n\tstatic get cssStyleSheet() {\n\t\treturn styles;\n\t}\n\n\tstatic get observedAttributes() {\n\t\treturn ['checked', 'disabled', 'value', 'indeterminate'];\n\t}\n\n\tattributeChangedCallback(name, oldValue, newValue) {\n\t\tif (!this.input) return;\n\t\tif (name === 'checked') {\n\t\t\tconst isChecked = this.hasAttribute('checked');\n\t\t\tthis.input.checked = isChecked;\n\t\t\t// Reflect into form value\n\t\t\tif (isChecked) {\n\t\t\t\tthis.internals.setFormValue(this.value);\n\t\t\t} else {\n\t\t\t\tthis.internals.setFormValue(null);\n\t\t\t}\n\t\t} else if (name === 'disabled') {\n\t\t\tthis.input.disabled = this.hasAttribute('disabled');\n\t\t} else if (name === 'indeterminate') {\n\t\t\tthis.input.indeterminate = this.hasAttribute('indeterminate');\n\t\t} else if (name === 'value') {\n\t\t\t// keep payload in sync; do not toggle checked here\n\t\t\tthis.#internalValue = newValue ?? undefined;\n\t\t\tthis.input.value = this.value;\n\t\t\t// If currently checked, update the submitted payload\n\t\t\tif (this.input.checked) {\n\t\t\t\tthis.internals.setFormValue(this.value);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Sets up the attributes for the checkbox.\n\t */\n\tsetupAttributes() {\n\t\tthis.isShadowRoot = 'open';\n\t\t// if some value was set via value setter then dont use default value\n\t\tif (this.pristine) {\n\t\t\tthis.value = this.#internalValue;\n\t\t\tthis.pristine = false;\n\t\t}\n\t}\n\n\t/**\n\t * Draws the checkbox element.\n\t * @returns {DocumentFragment} The created fragment.\n\t */\n\tdraw() {\n\t\tlet fragment = document.createDocumentFragment();\n\n\t\tlet native = document.createElement('div');\n\t\tnative.setAttribute('part', 'native');\n\t\tnative.classList.add('native-checkbox');\n\n\t\tlet input = document.createElement('input');\n\t\tinput.type = 'checkbox';\n\t\tinput.id = 'checkbox';\n\t\tinput.name = this.name || 'checkbox';\n\t\tinput.checked = this.checked;\n\t\tinput.disabled = this.disabled;\n\t\tinput.indeterminate = this.indeterminate;\n\t\tinput.required = this.required;\n\t\tinput.value = this.value;\n\n\t\tlet label = document.createElement('label');\n\t\tlabel.htmlFor = 'checkbox';\n\t\tlabel.innerHTML = '<slot></slot>';\n\n\t\t// Error\n\t\tlet errorSlot = document.createElement('slot');\n\t\terrorSlot.setAttribute('name', 'error');\n\n\t\tlet error = document.createElement('div');\n\t\terror.setAttribute('slot', 'error');\n\n\t\tnative.append(input);\n\t\tnative.append(label);\n\t\tnative.append(errorSlot);\n\n\t\tthis.append(error);\n\n\t\tthis.input = input;\n\n\t\tfragment.appendChild(native);\n\n\t\treturn fragment;\n\t}\n\n\t/**\n\t * Adds an event listener after drawing the checkbox.\n\t */\n\tafterDraw() {\n\t\tif (!this.disabled) {\n\t\t\tthis.input.addEventListener('input', (e) => {\n\t\t\t\tthis.validate();\n\n\t\t\t\tthis.pristine = false;\n\t\t\t\tthis.propagateValidation();\n\n\t\t\t\t// User interaction decides the checked state; value stays as payload\n\t\t\t\tthis.indeterminate = false;\n\t\t\t\tthis.checked = e.target.checked;\n\n\t\t\t\t// Fire checkbox-specific event name\n\t\t\t\tevent.dispatchCustomEvent(this, 'wje-toggle:input');\n\t\t\t});\n\n\t\t\tthis.input.addEventListener('change', (e) => {\n\t\t\t\tevent.dispatchCustomEvent(this, 'wje-toggle:change');\n\t\t\t});\n\n\t\t\tthis.addEventListener('wje-toggle:invalid', (e) => {\n\t\t\t\tthis.invalid = true;\n\t\t\t\tthis.pristine = false;\n\n\t\t\t\tthis.showInvalidMessage();\n\t\t\t});\n\n\t\t\tthis.validate();\n\n\t\t\tif (this.invalid) {\n\t\t\t\tthis.showInvalidMessage();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Removes the event listener when the checkbox is disconnected.\n\t */\n\tbeforeDisconnect() {\n\t\tevent.removeElement(this.input);\n\t}\n}\n","import { default as WJElement } from '../wje-element/element.js';\nimport Checkbox from './checkbox.element.js';\n\n// export * from \"./checkbox.element.js\";\nexport default Checkbox;\n\nWJElement.define('wje-checkbox', Checkbox);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAmBe,MAAM,iBAAiB,sBAAsB;AAAA;AAAA;AAAA;AAAA,EAK3D,cAAc;AACb,UAAO;AALR;AA0HA;AAAA;AAAA;AAAA,qCAAY;AAnHX,SAAK,UAAU;AACf,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMC,IAAI,MAAM,OAAO;AAChB,uBAAK,gBAAiB;AACtB,QAAI,KAAK,OAAO;AACf,WAAK,MAAM,QAAQ;AAAA,IACtB;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMC,IAAI,QAAQ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tB,UAAM,QAAQ,KAAK;AAEnB,QAAI,QAAQ,SAAS,cAAc,OAAO;AAC1C,UAAM,UAAU;AAChB,UAAM,YAAY;AAGlB,QAAI,YAAY,SAAS,cAAc,MAAM;AAC7C,cAAU,aAAa,QAAQ,OAAO;AAEtC,QAAI,QAAQ,SAAS,cAAc,KAAK;AACxC,UAAM,aAAa,QAAQ,OAAO;AAElC,WAAO,OAAO,KAAK;AACnB,WAAO,OAAO,KAAK;AACnB,WAAO,OAAO,SAAS;AAEvB,SAAK,OAAO,KAAK;AAEjB,SAAK,QAAQ;AAEb,aAAS,YAAY,MAAM;AAE3B,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKC,YAAY;AACX,QAAI,CAAC,KAAK,UAAU;AACnB,WAAK,MAAM,iBAAiB,SAAS,CAAC,MAAM;AAC3C,aAAK,SAAU;AAEf,aAAK,WAAW;AAChB,aAAK,oBAAqB;AAG1B,aAAK,gBAAgB;AACrB,aAAK,UAAU,EAAE,OAAO;AAGxB,cAAM,oBAAoB,MAAM,kBAAkB;AAAA,MACtD,CAAI;AAED,WAAK,MAAM,iBAAiB,UAAU,CAAC,MAAM;AAC5C,cAAM,oBAAoB,MAAM,mBAAmB;AAAA,MACvD,CAAI;AAED,WAAK,iBAAiB,sBAAsB,CAAC,MAAM;AAClD,aAAK,UAAU;AACf,aAAK,WAAW;AAEhB,aAAK,mBAAoB;AAAA,MAC7B,CAAI;AAED,WAAK,SAAU;AAEf,UAAI,KAAK,SAAS;AACjB,aAAK,mBAAoB;AAAA,MAC7B;AAAA,IACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAKC,mBAAmB;AAClB,UAAM,cAAc,KAAK,KAAK;AAAA,EAChC;AACA;AAvQC;ACdD,UAAU,OAAO,gBAAgB,QAAQ;"}
|
|
1
|
+
{"version":3,"file":"wje-checkbox.js","sources":["../packages/wje-checkbox/checkbox.element.js","../packages/wje-checkbox/checkbox.js"],"sourcesContent":["import { FormAssociatedElement } from '../internals/form-associated-element.js';\nimport { event } from '../utils/event.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary This method dispatches a custom event named \"wje-toggle:change\".\n * It is triggered when the input event is fired, which happens when the state of the checkbox changes.\n * The event is dispatched on the current instance of the Checkbox class.\n * @documentation https://elements.webjet.sk/components/checkbox\n * @status stable\n * @augments {FormAssociatedElement}\n * @slot - The checkbox main content.\n * @csspart native - The component's native wrapper.\n * @cssproperty [--wje-checkbox-border-radius=--wje-border-radius-medium] - Border radius of the component;\n * @cssproperty [--wje-checkbox-border-width=1px] - Border width of the component;\n * @cssproperty [--wje-checkbox-border-style=solid] - Border style of the component;\n * @cssproperty [--wje-checkbox-border-color=--wje-color-contrast-1] - Border color of the component;\n * @cssproperty [--wje-checkbox-margin-inline=0] - Margin inline of the component;\n */\nexport default class Checkbox extends FormAssociatedElement {\n\t#internalValue;\n\t/**\n\t * Checkbox constructor method.\n\t */\n\tconstructor() {\n\t\tsuper();\n\n\t\tthis.invalid = false;\n\t\tthis.pristine = true;\n\t}\n\n\t/**\n\t * Setter for the value attribute.\n\t * @param {string} value The value to set.\n\t */\n\tset value(value) {\n\t\tthis.#internalValue = value;\n\t\tif (this.input) {\n\t\t\tthis.input.value = value;\n\t\t}\n\t}\n\n\t/**\n\t * Getter for the value attribute.\n\t * @returns {string} The value of the attribute.\n\t */\n\tget value() {\n\t\treturn this.#internalValue ?? this.getAttribute('value') ?? 'on';;\n\t}\n\n\t/**\n\t * Getter for the customErrorDisplay attribute.\n\t * @returns {boolean} Whether the attribute is present.\n\t */\n\tget customErrorDisplay() {\n\t\treturn this.hasAttribute('custom-error-display');\n\t}\n\n\t/**\n\t * Getter for the validateOnChange attribute.\n\t * @returns {boolean} Whether the attribute is present.\n\t */\n\tget validateOnChange() {\n\t\treturn this.hasAttribute('validate-on-change');\n\t}\n\n\t/**\n\t * Setter for the defaultValue attribute.\n\t * This method sets the 'value' attribute of the custom input element to the provided value.\n\t * The 'value' attribute represents the default value of the input element.\n\t * @param {string} value The value to set as the default value.\n\t */\n\tset defaultValue(value) {\n\t\tthis.setAttribute('value', value);\n\t}\n\n\t/**\n\t * Getter for the defaultValue attribute.\n\t * This method retrieves the 'value' attribute of the custom input element.\n\t * The 'value' attribute represents the default value of the input element.\n\t * If the 'value' attribute is not set, it returns an empty string.\n\t * @returns {string} The default value of the input element.\n\t */\n\tget defaultValue() {\n\t\treturn this.getAttribute('value') ?? '';\n\t}\n\n\t/**\n\t * Sets or removes the 'indeterminate' attribute for the object.\n\t * This property typically reflects the visual or functional state where\n\t * the component is neither fully active nor inactive.\n\t * @param {boolean} value A boolean where `true` indicates the 'indeterminate'\n\t * state should be set, and `false` removes it.\n\t */\n\tset indeterminate(value) {\n\t\tif (value) {\n\t\t\tthis.setAttribute('indeterminate', '');\n\t\t} else {\n\t\t\tthis.removeAttribute('indeterminate');\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves the current state of the 'indeterminate' attribute.\n\t *\n\t * The 'indeterminate' attribute is typically used to signify a state\n\t * where a checkbox is neither checked nor unchecked, such as a partially\n\t * selected state.\n\t * @returns {boolean} Returns true if the 'indeterminate' attribute is present; otherwise, false.\n\t */\n\tget indeterminate() {\n\t\treturn this.hasAttribute('indeterminate');\n\t}\n\n\t/**\n\t * Set checked attribute.\n\t * @param {boolean} value true if the toggle is checked, false otherwise\n\t */\n\tset checked(value) {\n\t\tif (value) {\n\t\t\tthis.setAttribute('checked', '');\n\t\t\tthis.internals.setFormValue(this.value); // len ak je checked\n\t\t} else {\n\t\t\tthis.removeAttribute('checked');\n\t\t\tthis.internals.setFormValue(null); // ak nie je checked, nič sa neposiela\n\t\t}\n\t\tif (this.input) {\n\t\t\tthis.input.checked = value;\n\t\t}\n\t}\n\n\t/**\n\t * Get checked attribute.\n\t * @returns {boolean} true if the toggle is checked, false otherwise\n\t */\n\tget checked() {\n\t\treturn this.hasAttribute('checked');\n\t}\n\n\t/**\n\t * The class name for the Checkbox.\n\t */\n\tclassName = 'Checkbox';\n\n\t/**\n\t * Getter for the CSS stylesheet.\n\t * @returns {string} The CSS stylesheet.\n\t */\n\tstatic get cssStyleSheet() {\n\t\treturn styles;\n\t}\n\n\tstatic get observedAttributes() {\n\t\treturn ['checked', 'disabled', 'value', 'indeterminate'];\n\t}\n\n\tattributeChangedCallback(name, oldValue, newValue) {\n\t\tif (!this.input) return;\n\t\tif (name === 'checked') {\n\t\t\tconst isChecked = this.hasAttribute('checked');\n\t\t\tthis.input.checked = isChecked;\n\t\t\t// Reflect into form value\n\t\t\tif (isChecked) {\n\t\t\t\tthis.internals.setFormValue(this.value);\n\t\t\t} else {\n\t\t\t\tthis.internals.setFormValue(null);\n\t\t\t}\n\t\t} else if (name === 'disabled') {\n\t\t\tthis.input.disabled = this.hasAttribute('disabled');\n\t\t} else if (name === 'indeterminate') {\n\t\t\tthis.input.indeterminate = this.hasAttribute('indeterminate');\n\t\t} else if (name === 'value') {\n\t\t\t// keep payload in sync; do not toggle checked here\n\t\t\tthis.#internalValue = newValue ?? undefined;\n\t\t\tthis.input.value = this.value;\n\t\t\t// If currently checked, update the submitted payload\n\t\t\tif (this.input.checked) {\n\t\t\t\tthis.internals.setFormValue(this.value);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Sets up the attributes for the checkbox.\n\t */\n\tsetupAttributes() {\n\t\tthis.isShadowRoot = 'open';\n\t\t// if some value was set via value setter then dont use default value\n\t\tif (this.pristine) {\n\t\t\tthis.value = this.#internalValue;\n\t\t\tthis.pristine = false;\n\t\t}\n\t}\n\n\t/**\n\t * Draws the checkbox element.\n\t * @returns {DocumentFragment} The created fragment.\n\t */\n\tdraw() {\n\t\tlet fragment = document.createDocumentFragment();\n\n\t\tlet native = document.createElement('div');\n\t\tnative.setAttribute('part', 'native');\n\t\tnative.classList.add('native-checkbox');\n\n\t\tlet input = document.createElement('input');\n\t\tinput.type = 'checkbox';\n\t\tinput.id = 'checkbox';\n\t\tinput.name = this.name || 'checkbox';\n\t\tinput.checked = this.checked;\n\t\tinput.disabled = this.disabled;\n\t\tinput.indeterminate = this.indeterminate;\n\t\tinput.required = this.required;\n\t\tinput.value = this.value;\n\n\t\tlet label = document.createElement('label');\n\t\tlabel.htmlFor = 'checkbox';\n\t\tlabel.innerHTML = '<slot></slot>';\n\n\t\t// Error\n\t\tlet errorSlot = document.createElement('slot');\n\t\terrorSlot.setAttribute('name', 'error');\n\n\t\tlet error = document.createElement('div');\n\t\terror.setAttribute('slot', 'error');\n\n\t\tnative.append(input);\n\t\tnative.append(label);\n\t\tnative.append(errorSlot);\n\n\t\tthis.append(error);\n\n\t\tthis.input = input;\n\n\t\tfragment.appendChild(native);\n\n\t\treturn fragment;\n\t}\n\n\t/**\n\t * Adds an event listener after drawing the checkbox.\n\t */\n\tafterDraw() {\n\t\tthis.internals.setFormValue(this.checked ? this.value : null); // Set initial form value based on checked state\n\n\t\tif (!this.disabled) {\n\t\t\tthis.input.addEventListener('input', (e) => {\n\t\t\t\tthis.validate();\n\n\t\t\t\tthis.pristine = false;\n\t\t\t\tthis.propagateValidation();\n\n\t\t\t\t// User interaction decides the checked state; value stays as payload\n\t\t\t\tthis.indeterminate = false;\n\t\t\t\tthis.checked = e.target.checked;\n\n\t\t\t\t// Fire checkbox-specific event name\n\t\t\t\tevent.dispatchCustomEvent(this, 'wje-toggle:input');\n\t\t\t});\n\n\t\t\tthis.input.addEventListener('change', (e) => {\n\t\t\t\tevent.dispatchCustomEvent(this, 'wje-toggle:change');\n\t\t\t});\n\n\t\t\tthis.addEventListener('wje-toggle:invalid', (e) => {\n\t\t\t\tthis.invalid = true;\n\t\t\t\tthis.pristine = false;\n\n\t\t\t\tthis.showInvalidMessage();\n\t\t\t});\n\n\t\t\tthis.validate();\n\n\t\t\tif (this.invalid) {\n\t\t\t\tthis.showInvalidMessage();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Removes the event listener when the checkbox is disconnected.\n\t */\n\tbeforeDisconnect() {\n\t\tevent.removeElement(this.input);\n\t}\n}\n","import { default as WJElement } from '../wje-element/element.js';\nimport Checkbox from './checkbox.element.js';\n\n// export * from \"./checkbox.element.js\";\nexport default Checkbox;\n\nWJElement.define('wje-checkbox', Checkbox);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAmBe,MAAM,iBAAiB,sBAAsB;AAAA;AAAA;AAAA;AAAA,EAK3D,cAAc;AACb,UAAO;AALR;AA0HA;AAAA;AAAA;AAAA,qCAAY;AAnHX,SAAK,UAAU;AACf,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMC,IAAI,MAAM,OAAO;AAChB,uBAAK,gBAAiB;AACtB,QAAI,KAAK,OAAO;AACf,WAAK,MAAM,QAAQ;AAAA,IACtB;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMC,IAAI,QAAQ;AACX,WAAO,mBAAK,mBAAkB,KAAK,aAAa,OAAO,KAAK;AAAA,EAC9D;AAAA;AAAA;AAAA;AAAA;AAAA,EAMC,IAAI,qBAAqB;AACxB,WAAO,KAAK,aAAa,sBAAsB;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMC,IAAI,mBAAmB;AACtB,WAAO,KAAK,aAAa,oBAAoB;AAAA,EAC/C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQC,IAAI,aAAa,OAAO;AACvB,SAAK,aAAa,SAAS,KAAK;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASC,IAAI,eAAe;AAClB,WAAO,KAAK,aAAa,OAAO,KAAK;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASC,IAAI,cAAc,OAAO;AACxB,QAAI,OAAO;AACV,WAAK,aAAa,iBAAiB,EAAE;AAAA,IACxC,OAAS;AACN,WAAK,gBAAgB,eAAe;AAAA,IACvC;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAU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MACtD,CAAI;AAED,WAAK,MAAM,iBAAiB,UAAU,CAAC,MAAM;AAC5C,cAAM,oBAAoB,MAAM,mBAAmB;AAAA,MACvD,CAAI;AAED,WAAK,iBAAiB,sBAAsB,CAAC,MAAM;AAClD,aAAK,UAAU;AACf,aAAK,WAAW;AAEhB,aAAK,mBAAoB;AAAA,MAC7B,CAAI;AAED,WAAK,SAAU;AAEf,UAAI,KAAK,SAAS;AACjB,aAAK,mBAAoB;AAAA,MAC7B;AAAA,IACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAKC,mBAAmB;AAClB,UAAM,cAAc,KAAK,KAAK;AAAA,EAChC;AACA;AAzQC;ACdD,UAAU,OAAO,gBAAgB,QAAQ;"}
|
package/dist/wje-chip.js
CHANGED
|
@@ -4,7 +4,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4
4
|
import WJElement from "./wje-element.js";
|
|
5
5
|
import { WjElementUtils } from "./element-utils.js";
|
|
6
6
|
import { event } from "./event.js";
|
|
7
|
-
const styles = "/*\n[ WJ Chip ]\n*/\n\n:host {\n display: inline-flex;\n --wje-
|
|
7
|
+
const styles = "/*\n[ WJ Chip ]\n*/\n\n:host {\n display: inline-flex;\n --wje-button-border-radius: var(--wje-chip-round-border-radius);\n}\n\n.native-chip {\n display: inline-flex;\n justify-content: center;\n align-items: center;\n font-size: var(--wje-font-size);\n line-height: 1;\n letter-spacing: -0.006em;\n padding-block: var(--wje-chip-padding-block);\n padding-inline: var(--wje-chip-padding-inline);\n margin-block: var(--wje-chip-margin-block);\n margin-inline: var(--wje-chip-margin-inline);\n text-align: center;\n cursor: pointer;\n white-space: nowrap;\n text-shadow: none;\n box-shadow: none;\n border: 0 none;\n width: 100%;\n height: 28px;\n max-width: fit-content;\n position: relative;\n transition: width 0.15s cubic-bezier(0.4, 0, 0.2, 1);\n border-radius: var(--wje-border-radius-pill);\n overflow: hidden;\n vertical-align: middle;\n box-sizing: border-box;\n background-color: var(--wje-chip-background);\n color: var(--wje-chip-color);\n &:hover {\n background-color: var(--wje-chip-background-hover);\n color: var(--wje-chip-color-hover);\n }\n}\n\n:host(.focus) {\n box-shadow: none;\n}\n\n:host(.wje-active) .native-chip {\n border: 1px solid var(--wje-color-primary-11);\n background-color: var(--wje-color-contrast-3);\n color: var(--wje-color);\n}\n\n:host(:focus, :active:focus, .wje-active:focus) {\n outline: none !important;\n}\n\n:host([size='small']) .native-chip {\n font-size: var(--wje-font-size-small);\n height: 24px;\n padding: var(--wje-spacing-3x-small) var(--wje-spacing-x-small);\n wje-button {\n --wje-button-margin-inline: var(--wje-spacing-3x-small) calc(-1 * var(--wje-spacing-3x-small));\n }\n}\n\n:host([size='large']) .native-chip {\n font-size: var(--wje-font-size-medium);\n height: 34px;\n padding: var(--wje-spacing-x-small) var(--wje-spacing-small);\n\n}\n\n:host([round]) .native-chip {\n border-radius: var(--wje-chip-round-border-radius);\n}\n\n.check {\n display: none;\n}\n\n:host([active]) {\n .check {\n display: block;\n margin-inline: 4px 0;\n }\n}\n\n:host([disabled]) {\n opacity: 0.5;\n border: 0;\n pointer-events: none;\n cursor: not-allowed;\n}\n\n::slotted(wje-avatar) {\n width: 22px;\n height: 22px;\n}\n\n::slotted(wje-avatar:first-child) {\n margin-inline: -8px 8px;\n margin-top: -4px;\n margin-bottom: -4px;\n}\n\n::slotted(wje-icon:first-child) {\n margin: -4px 8px -4px -4px;\n}\n\n::slotted(wje-icon:last-child) {\n margin: -4px -4px -4px 8px;\n}\n\nslot[name='end'].has-content {\n display: block;\n margin-inline-start: 8px;\n}\n\nwje-button {\n /*--wje-button-border-radius: 50%;*/\n --wje-button-margin-inline: 0.25rem -0.5rem;\n --wje-padding-top: 0.15rem;\n --wje-padding-start: 0.15rem;\n --wje-padding-end: 0.15rem;\n --wje-padding-bottom: 0.15rem;\n}\n\n/*BG - TEXT*/\n.native-chip.wje-color-primary {\n background-color: var(--wje-color-primary-1);\n color: var(--wje-color-primary-9);\n}\n\n.native-chip.wje-color-complete {\n background-color: var(--wje-color-complete-1);\n color: var(--wje-color-complete-9);\n}\n\n.native-chip.wje-color-success {\n background-color: var(--wje-color-success-1);\n color: var(--wje-color-success-9);\n}\n\n.native-chip.wje-color-warning {\n background-color: var(--wje-color-warning-2);\n color: var(--wje-color-warning-11);\n}\n\n.native-chip.wje-color-danger {\n background-color: var(--wje-color-danger-1);\n color: var(--wje-color-danger-9);\n}\n\n.native-chip.wje-color-info {\n background-color: var(--wje-color-info-1);\n color: var(--wje-color-info-9);\n}\n\n/*HOVER*/\n@media (any-hover: hover) {\n .native-chip.wje-color-primary:hover {\n background-color: var(--wje-color-primary-4);\n color: var(--wje-color-primary-10);\n }\n\n .native-chip.wje-color-complete:hover {\n background-color: var(--wje-color-complete-4);\n color: var(--wje-color-complete-10);\n }\n\n .native-chip.wje-color-success:hover {\n background-color: var(--wje-color-success-4);\n color: var(--wje-color-success-10);\n }\n\n .native-chip.wje-color-warning:hover {\n background-color: var(--wje-color-warning-4);\n color: var(--wje-color-warning-11);\n }\n\n .native-chip.wje-color-danger:hover {\n background-color: var(--wje-color-danger-4);\n color: var(--wje-color-danger-10);\n }\n\n .native-chip.wje-color-info:hover {\n background-color: var(--wje-color-info-4);\n color: var(--wje-color-info-10);\n }\n}\n";
|
|
8
8
|
class Chip extends WJElement {
|
|
9
9
|
/**
|
|
10
10
|
* Chip constructor method.
|
|
@@ -91,6 +91,7 @@ class Chip extends WJElement {
|
|
|
91
91
|
draw() {
|
|
92
92
|
let fragment = document.createDocumentFragment();
|
|
93
93
|
let native = document.createElement("div");
|
|
94
|
+
native.setAttribute("part", "native");
|
|
94
95
|
native.classList.add("native-chip");
|
|
95
96
|
let slot = document.createElement("slot");
|
|
96
97
|
let slotEnd = document.createElement("slot");
|
package/dist/wje-chip.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wje-chip.js","sources":["../packages/wje-chip/chip.element.js","../packages/wje-chip/chip.js"],"sourcesContent":["import { default as WJElement, event, WjElementUtils } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary This method dispatches a custom event named \"wje-chip:remove\".\n * It is triggered when the remove button is clicked, which happens when the chip is removed.\n * The event is dispatched on the current instance of the Chip class.\n * @documentation https://elements.webjet.sk/components/chip\n * @status stable\n * @augments WJElement\n * @slot - The chip main content.\n * @csspart native - The component's native wrapper.\n * //@fires wje-chip:remove - Dispatched when the chip is removed;\n */\nexport default class Chip extends WJElement {\n /**\n * Chip constructor method.\n */\n constructor() {\n super();\n }\n\n /**\n * Sets or removes the \"round\" attribute on the element based on the provided value.\n * @param {boolean} value Determines whether the \"round\" attribute should be set or removed.\n * If true, the \"round\" attribute is added. If false, the \"round\"\n * attribute is removed.\n */\n set round(value) {\n if (value) {\n this.setAttribute('round', '');\n } else {\n this.removeAttribute('round');\n }\n }\n\n /**\n * Checks if the 'round' attribute is present on the element.\n * @returns {boolean} Returns true if the 'round' attribute exists, otherwise false.\n */\n get round() {\n return this.hasAttribute('round');\n }\n\n /**\n * Sets the size attribute of the element.\n * @param {string} value The value to set for the size attribute.\n */\n set size(value) {\n this.setAttribute('size', value);\n }\n\n /**\n * Retrieves the 'size' attribute of the current element.\n * @returns {string | null} The value of the 'size' attribute, or null if the attribute is not set.\n */\n get size() {\n return this.getAttribute('size');\n }\n\n /**\n * Sets or removes the \"removable\" attribute on the element.\n * @param {boolean} value A boolean indicating whether the element should have the \"removable\" attribute.\n * If true, the \"removable\" attribute is added;\n * if false, the \"removable\" attribute is removed.\n */\n set removable(value) {\n if (value) {\n this.setAttribute('removable', '');\n } else {\n this.removeAttribute('removable');\n }\n }\n\n /**\n * Determines if the element has the 'removable' attribute.\n * @returns {boolean} True if the element has the 'removable' attribute, otherwise false.\n */\n get removable() {\n return this.hasAttribute('removable');\n }\n\n /**\n * Class name for the Chip element.\n * @type {string}\n */\n className = 'Chip';\n\n /**\n * Getter for the CSS stylesheet.\n * @returns {*}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Getter for the observed attributes.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Draws the Chip element.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.classList.add('native-chip');\n\n let slot = document.createElement('slot');\n\n let slotEnd = document.createElement('slot');\n slotEnd.setAttribute('name', 'end');\n\n let remove = document.createElement('wje-button');\n remove.setAttribute('part', 'remove');\n remove.setAttribute('fill', 'link');\n remove.setAttribute('color', this.color || 'default');\n remove.round = !this.round;\n\n if(this.hasAttribute('size')) {\n if(this.size === 'small') {\n remove.innerHTML = `<wje-icon name=\"x\" size=\"small\"></wje-icon>`;\n } else if (this.size === 'large') {\n remove.innerHTML = `<wje-icon name=\"x\"></wje-icon>`;\n }\n } else {\n remove.innerHTML = `<wje-icon name=\"x\"></wje-icon>`;\n }\n\n let active = document.createElement('wje-icon');\n active.setAttribute('name', 'check');\n active.classList.add('check');\n\n // Add color\n if (this.hasAttribute('color')) native.classList.add('wje-color-' + this.color, 'wje-color');\n else native.classList.add('wje-color-default', 'wje-color');\n\n if (this.disabled) this.classList.add('wje-disabled');\n\n if (this.outline) this.classList.add('wje-outline');\n\n native.appendChild(slot);\n native.appendChild(slotEnd);\n native.appendChild(active);\n\n if (this.removable) native.appendChild(remove);\n\n fragment.appendChild(native);\n\n this.removeElement = remove;\n this.slotEnd = slotEnd;\n\n return fragment;\n }\n\n /**\n * Getter for the observed attributes.\n */\n afterDraw() {\n if (WjElementUtils.hasSlotContent(this.context, 'end')) this.slotEnd.classList.add('has-content');\n\n event.addListener(this.removeElement, 'click', 'wje:chip-remove', null, { stopPropagation: true });\n }\n\n /**\n * Before disconnect event for the Chip element.\n */\n beforeDisconnect() {\n event.removeListener(this.removeElement, 'click', 'wje:chip-remove');\n }\n}\n","import { default as WJElement } from '../wje-element/element.js';\nimport Chip from './chip.element.js';\n\n// export * from \"./chip.element.js\";\nexport default Chip;\n\nWJElement.define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A,EAC3E;AACA;
|
|
1
|
+
{"version":3,"file":"wje-chip.js","sources":["../packages/wje-chip/chip.element.js","../packages/wje-chip/chip.js"],"sourcesContent":["import { default as WJElement, event, WjElementUtils } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary This method dispatches a custom event named \"wje-chip:remove\".\n * It is triggered when the remove button is clicked, which happens when the chip is removed.\n * The event is dispatched on the current instance of the Chip class.\n * @documentation https://elements.webjet.sk/components/chip\n * @status stable\n * @augments WJElement\n * @slot - The chip main content.\n * @csspart native - The component's native wrapper.\n * //@fires wje-chip:remove - Dispatched when the chip is removed;\n */\nexport default class Chip extends WJElement {\n /**\n * Chip constructor method.\n */\n constructor() {\n super();\n }\n\n /**\n * Sets or removes the \"round\" attribute on the element based on the provided value.\n * @param {boolean} value Determines whether the \"round\" attribute should be set or removed.\n * If true, the \"round\" attribute is added. If false, the \"round\"\n * attribute is removed.\n */\n set round(value) {\n if (value) {\n this.setAttribute('round', '');\n } else {\n this.removeAttribute('round');\n }\n }\n\n /**\n * Checks if the 'round' attribute is present on the element.\n * @returns {boolean} Returns true if the 'round' attribute exists, otherwise false.\n */\n get round() {\n return this.hasAttribute('round');\n }\n\n /**\n * Sets the size attribute of the element.\n * @param {string} value The value to set for the size attribute.\n */\n set size(value) {\n this.setAttribute('size', value);\n }\n\n /**\n * Retrieves the 'size' attribute of the current element.\n * @returns {string | null} The value of the 'size' attribute, or null if the attribute is not set.\n */\n get size() {\n return this.getAttribute('size');\n }\n\n /**\n * Sets or removes the \"removable\" attribute on the element.\n * @param {boolean} value A boolean indicating whether the element should have the \"removable\" attribute.\n * If true, the \"removable\" attribute is added;\n * if false, the \"removable\" attribute is removed.\n */\n set removable(value) {\n if (value) {\n this.setAttribute('removable', '');\n } else {\n this.removeAttribute('removable');\n }\n }\n\n /**\n * Determines if the element has the 'removable' attribute.\n * @returns {boolean} True if the element has the 'removable' attribute, otherwise false.\n */\n get removable() {\n return this.hasAttribute('removable');\n }\n\n /**\n * Class name for the Chip element.\n * @type {string}\n */\n className = 'Chip';\n\n /**\n * Getter for the CSS stylesheet.\n * @returns {*}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Getter for the observed attributes.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Draws the Chip element.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.setAttribute('part', 'native');\n native.classList.add('native-chip');\n\n let slot = document.createElement('slot');\n\n let slotEnd = document.createElement('slot');\n slotEnd.setAttribute('name', 'end');\n\n let remove = document.createElement('wje-button');\n remove.setAttribute('part', 'remove');\n remove.setAttribute('fill', 'link');\n remove.setAttribute('color', this.color || 'default');\n remove.round = !this.round;\n\n if(this.hasAttribute('size')) {\n if(this.size === 'small') {\n remove.innerHTML = `<wje-icon name=\"x\" size=\"small\"></wje-icon>`;\n } else if (this.size === 'large') {\n remove.innerHTML = `<wje-icon name=\"x\"></wje-icon>`;\n }\n } else {\n remove.innerHTML = `<wje-icon name=\"x\"></wje-icon>`;\n }\n\n let active = document.createElement('wje-icon');\n active.setAttribute('name', 'check');\n active.classList.add('check');\n\n // Add color\n if (this.hasAttribute('color')) native.classList.add('wje-color-' + this.color, 'wje-color');\n else native.classList.add('wje-color-default', 'wje-color');\n\n if (this.disabled) this.classList.add('wje-disabled');\n\n if (this.outline) this.classList.add('wje-outline');\n\n native.appendChild(slot);\n native.appendChild(slotEnd);\n native.appendChild(active);\n\n if (this.removable) native.appendChild(remove);\n\n fragment.appendChild(native);\n\n this.removeElement = remove;\n this.slotEnd = slotEnd;\n\n return fragment;\n }\n\n /**\n * Getter for the observed attributes.\n */\n afterDraw() {\n if (WjElementUtils.hasSlotContent(this.context, 'end')) this.slotEnd.classList.add('has-content');\n\n event.addListener(this.removeElement, 'click', 'wje:chip-remove', null, { stopPropagation: true });\n }\n\n /**\n * Before disconnect event for the Chip element.\n */\n beforeDisconnect() {\n event.removeListener(this.removeElement, 'click', 'wje:chip-remove');\n }\n}\n","import { default as WJElement } from '../wje-element/element.js';\nimport Chip from './chip.element.js';\n\n// export * from \"./chip.element.js\";\nexport default Chip;\n\nWJElement.define('wje-chip', Chip);\n"],"names":[],"mappings":";;;;;;;AAce,MAAM,aAAa,UAAU;AAAA;AAAA;AAAA;AAAA,EAIxC,cAAc;AACV,UAAO;AAmEX;AAAA;AAAA;AAAA;AAAA,qCAAY;AAAA,EAlEhB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQI,IAAI,MAAM,OAAO;AACb,QAAI,OAAO;AACP,WAAK,aAAa,SAAS,EAAE;AAAA,IACzC,OAAe;AACH,WAAK,gBAAgB,OAAO;AAAA,IACxC;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,IAAI,QAAQ;AACR,WAAO,KAAK,aAAa,OAAO;AAAA,EACxC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,IAAI,KAAK,OAAO;AACZ,SAAK,aAAa,QAAQ,KAAK;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,IAAI,OAAO;AACP,WAAO,KAAK,aAAa,MAAM;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQI,IAAI,UAAU,OAAO;AACjB,QAAI,OAAO;AACP,WAAK,aAAa,aAAa,EAAE;AAAA,IAC7C,OAAe;AACH,WAAK,gBAAgB,WAAW;AAAA,IAC5C;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,IAAI,YAAY;AACZ,WAAO,KAAK,aAAa,WAAW;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA,EAYI,WAAW,gBAAgB;AACvB,WAAO;AAAA,EACf;AAAA;AAAA;AAAA;AAAA,EAKI,kBAAkB;AACd,SAAK,eAAe;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,OAAO;AACH,QAAI,WAAW,SAAS,uBAAwB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AM,YAAY,KAAK,eAAe,SAAS,mBAAmB,MAAM,EAAE,iBAAiB,MAAM;AAAA,EACzG;AAAA;AAAA;AAAA;AAAA,EAKI,mBAAmB;AACf,UAAM,eAAe,KAAK,eAAe,SAAS,iBAAiB;AAAA,EAC3E;AACA;AC1KA,UAAU,OAAO,YAAY,IAAI;"}
|
package/dist/wje-pagination.js
CHANGED
|
@@ -289,7 +289,7 @@ class Pagination extends WJElement {
|
|
|
289
289
|
this.setAttribute("hidden", "");
|
|
290
290
|
return;
|
|
291
291
|
}
|
|
292
|
-
this.paginateObj = await paginate(this.totalItems, this.page, this.pageSize, this.maxPages);
|
|
292
|
+
this.paginateObj = await paginate(this.totalItems, this.page, this.pageSize, this.maxPages) || {};
|
|
293
293
|
}
|
|
294
294
|
/**
|
|
295
295
|
* Creates a document fragment, appends a new slot element to it, and returns the fragment.
|
|
@@ -310,6 +310,7 @@ class Pagination extends WJElement {
|
|
|
310
310
|
* @returns {DocumentFragment} A document fragment containing the pagination controls.
|
|
311
311
|
*/
|
|
312
312
|
htmlPagination() {
|
|
313
|
+
var _a, _b, _c, _d;
|
|
313
314
|
let fragment = document.createDocumentFragment();
|
|
314
315
|
let select = document.createElement("wje-select");
|
|
315
316
|
select.setAttribute("size", "small");
|
|
@@ -330,7 +331,7 @@ class Pagination extends WJElement {
|
|
|
330
331
|
});
|
|
331
332
|
let info = document.createElement("div");
|
|
332
333
|
info.classList.add("info");
|
|
333
|
-
info.innerHTML = `${this.paginateObj.startIndex + 1} - ${this.paginateObj.endIndex + 1} ${this.localizer.translate("wj.pagination.of")} ${this.totalItems}`;
|
|
334
|
+
info.innerHTML = `${((_a = this.paginateObj) == null ? void 0 : _a.startIndex) + 1} - ${((_b = this.paginateObj) == null ? void 0 : _b.endIndex) + 1} ${this.localizer.translate("wj.pagination.of")} ${this.totalItems}`;
|
|
334
335
|
let pagination = document.createElement("div");
|
|
335
336
|
pagination.classList.add("pages");
|
|
336
337
|
const button = document.createElement("wje-button");
|
|
@@ -348,15 +349,18 @@ class Pagination extends WJElement {
|
|
|
348
349
|
const nextButton = button.cloneNode(true);
|
|
349
350
|
nextButton.title = this.localizer.translate("wj.pagination.next");
|
|
350
351
|
nextButton.innerHTML = `<wje-icon name="chevron-right" slot="icon-only"></wje-icon>`;
|
|
351
|
-
if (this.page + 1 >= this.paginateObj.totalPages) nextButton.disabled = true;
|
|
352
|
+
if (this.page + 1 >= ((_c = this.paginateObj) == null ? void 0 : _c.totalPages)) nextButton.disabled = true;
|
|
352
353
|
nextButton.addEventListener("wje-button:click", (e) => this.pageClickAction(e, this.page + 1));
|
|
353
354
|
let lastButton = button.cloneNode(true);
|
|
354
355
|
lastButton.title = this.localizer.translate("wj.pagination.last");
|
|
355
356
|
lastButton.innerHTML = `<wje-icon name="chevron-right-pipe" slot="icon-only"></wje-icon>`;
|
|
356
|
-
lastButton.disabled = this.paginateObj.endIndex + 1 >= this.totalItems;
|
|
357
|
+
lastButton.disabled = ((_d = this.paginateObj) == null ? void 0 : _d.endIndex) + 1 >= this.totalItems;
|
|
357
358
|
lastButton.addEventListener(
|
|
358
359
|
"wje-button:click",
|
|
359
|
-
(e) =>
|
|
360
|
+
(e) => {
|
|
361
|
+
var _a2;
|
|
362
|
+
return this.pageClickAction(e, ((_a2 = this.paginateObj) == null ? void 0 : _a2.totalPages) - 1);
|
|
363
|
+
}
|
|
360
364
|
);
|
|
361
365
|
select.append(...options);
|
|
362
366
|
if (this.showFirstButton) pagination.appendChild(firstButton);
|
|
@@ -389,13 +393,13 @@ class Pagination extends WJElement {
|
|
|
389
393
|
first.textContent = "1";
|
|
390
394
|
first.addEventListener("wje-button:click", (e) => this.pageClickAction(e, 0));
|
|
391
395
|
const last = button.cloneNode(true);
|
|
392
|
-
last.textContent = paginateObj.totalPages;
|
|
393
|
-
last.addEventListener("wje-button:click", (e) => this.pageClickAction(e, paginateObj.totalPages - 1));
|
|
394
|
-
if (paginateObj.currentPage >= this.maxPages + 1 && paginateObj.boundary < paginateObj.totalPages) {
|
|
396
|
+
last.textContent = paginateObj == null ? void 0 : paginateObj.totalPages;
|
|
397
|
+
last.addEventListener("wje-button:click", (e) => this.pageClickAction(e, (paginateObj == null ? void 0 : paginateObj.totalPages) - 1));
|
|
398
|
+
if ((paginateObj == null ? void 0 : paginateObj.currentPage) >= this.maxPages + 1 && (paginateObj == null ? void 0 : paginateObj.boundary) < (paginateObj == null ? void 0 : paginateObj.totalPages)) {
|
|
395
399
|
fragment.appendChild(first);
|
|
396
400
|
fragment.appendChild(dots);
|
|
397
401
|
}
|
|
398
|
-
paginateObj.pages.forEach((page) => {
|
|
402
|
+
paginateObj == null ? void 0 : paginateObj.pages.forEach((page) => {
|
|
399
403
|
let newButton = button.cloneNode(true);
|
|
400
404
|
newButton.textContent = page;
|
|
401
405
|
if (page - 1 === this.page) {
|
|
@@ -405,7 +409,7 @@ class Pagination extends WJElement {
|
|
|
405
409
|
}
|
|
406
410
|
fragment.appendChild(newButton);
|
|
407
411
|
});
|
|
408
|
-
if ((paginateObj.pages.length === this.maxPages || paginateObj.currentPage < this.maxPages + 1) && paginateObj.boundary < paginateObj.totalPages) {
|
|
412
|
+
if (((paginateObj == null ? void 0 : paginateObj.pages.length) === this.maxPages || (paginateObj == null ? void 0 : paginateObj.currentPage) < this.maxPages + 1) && paginateObj.boundary < (paginateObj == null ? void 0 : paginateObj.totalPages)) {
|
|
409
413
|
fragment.appendChild(dots.cloneNode(true));
|
|
410
414
|
fragment.appendChild(last);
|
|
411
415
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wje-pagination.js","sources":["../packages/wje-pagination/service/service.js","../packages/wje-pagination/pagination.element.js","../packages/wje-pagination/pagination.js"],"sourcesContent":["/**\n * Paginates items based on the total number of items, current page, page size, and maximum number of pages to display.\n * @param {number} totalItems The total number of items to paginate.\n * @param {number} [currentPage] The current page number (default is 1).\n * @param {number} [pageSize] The number of items per page (default is 10).\n * @param {number} [maxPages] The maximum number of pages to display in the pagination control (default is 5).\n * @returns {object} An object containing pagination details including total items, current page, page size, total pages, start/end page, start/end index, and the pages array.\n */\nexport function paginate(totalItems, currentPage = 1, pageSize = 10, maxPages = 5) {\n // Calculate total pages\n const totalPages = Math.ceil(totalItems / pageSize);\n\n // Ensure current page is within valid range\n if (currentPage < 1) {\n currentPage = 1;\n } else if (currentPage > totalPages) {\n currentPage = totalPages;\n }\n\n let startPage;\n let endPage;\n\n const pagesNearEnd = maxPages + 1; // Define how close to the end we switch back to 5 pages 4\n\n const boundary = pagesNearEnd + 3;\n\n if (totalPages > boundary) {\n if (currentPage < pagesNearEnd) {\n // If in the first 4 pages, show up to 5 pages\n startPage = 1;\n endPage = Math.min(pagesNearEnd + 1, totalPages); //5\n } else if (currentPage >= totalPages - pagesNearEnd) {\n // If within 4 pages from the end, show last 5 pages\n startPage = Math.max(totalPages - pagesNearEnd, 1); //4\n endPage = totalPages;\n } else {\n const halfPages = Math.floor(maxPages / 2);\n // Otherwise, only show 3 pages (current, previous, next)\n startPage = currentPage - halfPages + 1;\n endPage = maxPages % 2 === 1 ? currentPage + halfPages + 1 : currentPage + halfPages - 1;\n }\n } else {\n startPage = 1;\n endPage = totalPages;\n }\n\n // Calculate start and end item indexes\n const startIndex = (currentPage - 1) * pageSize;\n const endIndex = Math.min(startIndex + pageSize - 1, totalItems - 1);\n\n // Create an array of pages to display\n const pages = Array.from({ length: endPage - startPage + 1 }, (_, i) => startPage + i);\n\n // Return object with all pager properties (preserving original format)\n return {\n boundary: boundary,\n currentPage: currentPage,\n endIndex: endIndex,\n endPage: endPage,\n totalPages: totalPages,\n pages: pages,\n pageSize: pageSize,\n startIndex: startIndex,\n startPage: startPage,\n totalItems: totalItems,\n };\n}\n","import { Localizer } from '../utils/localize.js';\nimport { default as WJElement, event } from '../wje-element/element.js';\nimport { paginate } from './service/service.js';\nimport Icon from '../wje-icon/icon.js';\nimport Button from '../wje-button/button.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary This class represents the Pagination component for navigating through paginated content and dynamically updating navigation elements based on attributes like the number of items, page size, etc. Extends the WJElement class.\n * @documentation https://elements.webjet.sk/components/pagination\n * @status stable\n * @augments WJElement\n * @dependency wje-icon, wje-button\n * @csspart native - The wrapper element for the pagination component.\n */\nexport default class Pagination extends WJElement {\n /**\n * Creates an instance of Pagination.\n */\n constructor() {\n super();\n this.localizer = new Localizer(this);\n\n this._paginateObj = null;\n }\n\n /**\n * Sets the value of the 'page' attribute for the object.\n * @param {string} value The value to set for the 'page' attribute.\n */\n set page(value) {\n this.setAttribute('page', value);\n }\n\n /**\n * Retrieves the current page number as a numeric value.\n * @returns {number} The current page number. Returns 0 if the attribute 'page' is not set or is not a numeric value.\n */\n get page() {\n return +this.getAttribute('page') || 0;\n }\n\n /**\n * Sets the maximum number of pages.\n * Updates the 'max-pages' attribute with the provided value.\n * @param {number|string} value The maximum number of pages to set. Can be a number or a parsable string representing a number.\n */\n set maxPages(value) {\n this.setAttribute('max-pages', value);\n }\n\n /**\n * Gets the maximum number of pages.\n * This getter retrieves the value of the \"max-pages\" attribute from the element.\n * If the attribute is not set or is invalid, it defaults to 3.\n * @returns {number} The maximum number of pages as a numeric value.\n */\n get maxPages() {\n return +this.getAttribute('max-pages') || 10;\n }\n\n /**\n * Sets the `pageSize` attribute to the specified value.\n * @param {number|string} value The desired page size value. This can be a number or a string representation of the size.\n */\n set pageSize(value) {\n this.setAttribute('page-size', value);\n }\n\n /**\n * Retrieves the value of the 'page-size' attribute and converts it to a number.\n * If the attribute is not set or is invalid, returns the default value of 3.\n * @returns {number} The numeric value of the 'page-size' attribute or the default value of 3.\n */\n get pageSize() {\n return +this.getAttribute('page-size') || 3;\n }\n\n /**\n * Sets the total number of items.\n * @param {number} value The new total number of items to set.\n */\n set totalItems(value) {\n this.setAttribute('total-items', value);\n }\n\n /**\n * Retrieves the total number of items represented by the 'total-items' attribute.\n * @returns {number} The total number of items. Defaults to 0 if the attribute is not set or is invalid.\n */\n get totalItems() {\n return +this.getAttribute('total-items') || 0;\n }\n\n /**\n * Sets the visibility of the first button based on the provided value.\n * Adds the 'show-first-button' attribute when the value is truthy, and removes it otherwise.\n * @param {boolean} value Determines whether to show the first button. If true, the 'show-first-button' attribute is added; if false, it is removed.\n */\n set showFirstButton(value) {\n this.removeAttribute('show-first-button');\n\n if (value) {\n this.setAttribute('show-first-button', '');\n }\n }\n\n /**\n * Determines whether the 'show-first-button' attribute is present on the element.\n * @returns {boolean} True if the 'show-first-button' attribute is set; otherwise, false.\n */\n get showFirstButton() {\n return this.hasAttribute('show-first-button');\n }\n\n /**\n * Sets the visibility of the \"last\" button. This method controls the presence\n * or absence of the \"show-last-button\" attribute based on the provided value.\n * @param {boolean} value A boolean value indicating whether to show the \"last\" button.\n * If true, the \"show-last-button\" attribute is added;\n * if false, the attribute is removed.\n */\n set showLastButton(value) {\n this.removeAttribute('show-last-button');\n\n if (value) {\n this.setAttribute('show-last-button', '');\n }\n }\n\n /**\n * Determines if the 'show-last-button' attribute is present on the element.\n * @returns {boolean} True if the 'show-last-button' attribute is present, otherwise false.\n */\n get showLastButton() {\n return this.hasAttribute('show-last-button');\n }\n\n /**\n * Sets the pagination object by calculating the pagination details\n * based on the total items, current page, page size, and maximum pages.\n * @param {object} value The value to set the pagination object. The pagination details are computed internally.\n */\n set paginateObj(value) {\n this._paginateObj = value;\n }\n\n /**\n * Retrieves the pagination object used for managing paginated data.\n * @returns {object} The pagination object containing details and functionality for paginating data.\n */\n get paginateObj() {\n return this._paginateObj;\n }\n\n /**\n * Sets the 'round' attribute on the element. If the provided value is truthy,\n * the 'round' attribute is added. If the value is falsy, the attribute is removed.\n * @param {boolean} value A boolean value determining whether to add or remove the 'round' attribute.\n */\n set round(value) {\n this.removeAttribute('round');\n\n if (value) {\n this.setAttribute('round', '');\n }\n }\n\n /**\n * Retrieves the value of the 'round' attribute for the current element.\n * @returns {boolean} A boolean indicating whether the 'round' attribute is present on the element.\n */\n get round() {\n return this.hasAttribute('round');\n }\n\n /**\n * Sets the `show-info` attribute on the element based on the provided value.\n * @param {boolean} value A boolean indicating whether to add or remove the `show-info` attribute.\n */\n set showInfo(value) {\n this.removeAttribute('show-info');\n\n if (value) {\n this.setAttribute('show-info', '');\n }\n }\n\n /**\n * Retrieves the value of the 'show-info' attribute.\n * Checks if the 'show-info' attribute is present on the element.\n * @returns {boolean} True if the 'show-info' attribute is present, otherwise false.\n */\n get showInfo() {\n return this.hasAttribute('show-info');\n }\n\n set showPageSizeOptions(value) {\n if (!value) return;\n this.setAttribute('show-page-size-options', value);\n }\n\n get showPageSizeOptions() {\n return this.hasAttribute('show-page-size-options');\n }\n\n set pageSizeOptions(value) {\n if (!value) return;\n this.setAttribute('page-size-options', value);\n }\n\n /**\n * Retrieves the list of available page size options.\n * This method is used to fetch the values representing the different page size options\n * that can be provided or configured in a paginated component or system.\n * @returns {Array<number>} An array of numbers representing the selectable page size options.\n */\n get pageSizeOptions() {\n let options = this.getAttribute('page-size-options');\n if (!options) return [6, 10, 50, 100, 500];\n return options.split(',').map((o) => +o).filter((o) => !isNaN(o));\n }\n\n set hideEmpty(value) {\n if (!value) return;\n this.setAttribute('hide-empty', value);\n }\n\n get hideEmpty() {\n return this.hasAttribute('hide-empty');\n }\n\n /**\n * Dependencies of the Button element.\n * @type {object}\n */\n dependencies = {\n 'wje-icon': Icon,\n 'wje-button': Button,\n };\n\n className = 'Pagination';\n\n /**\n * Returns the CSS styles for the component.\n * @static\n * @returns {CSSStyleSheet}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Getter for the observedAttributes attribute of the input element.\n * @returns {Array} The attributes to observe for changes.\n */\n static get observedAttributes() {\n return ['page', 'total-items', 'page-size'];\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n async beforeDraw() {\n this.classList.remove('empty');\n this.removeAttribute(\"hidden\");\n\n if (!this.totalItems || this.totalItems === 0) {\n this.classList.add('empty');\n if (this.hideEmpty)\n this.setAttribute(\"hidden\", \"\");\n\n return;\n }\n\n this.paginateObj = await paginate(this.totalItems, this.page, this.pageSize, this.maxPages);\n }\n\n /**\n * Creates a document fragment, appends a new slot element to it, and returns the fragment.\n * @returns {DocumentFragment} A document fragment containing a slot element.\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.setAttribute('part', 'native');\n native.classList.add('native-pagination');\n\n native.append(this.htmlPagination());\n\n fragment.append(native);\n\n return fragment;\n }\n\n /**\n * Creates a pagination control for navigating between pages of content.\n * This method generates and returns a document fragment containing pagination controls, including buttons for navigating to the first, previous, next, and last pages, as well as optional informational text about the current set of displayed items and total number of items.\n * @returns {DocumentFragment} A document fragment containing the pagination controls.\n */\n htmlPagination() {\n let fragment = document.createDocumentFragment();\n\n let select = document.createElement('wje-select');\n select.setAttribute('size', 'small');\n select.setAttribute('variant', 'standard');\n select.setAttribute('value', this.pageSize);\n select.addEventListener('wje-select:change', (e) => {\n\n if(+e.detail.context.value[0] !== this.pageSize) {\n this.pageSize = +e.detail.context.value[0];\n this.page = 0; // Reset to first page when page size changes\n event.dispatchCustomEvent(this, 'wje-pagination:page-change', { page: this.page, pageSize: this.pageSize });\n }\n });\n\n let options = this.pageSizeOptions.map((o) => {\n let option = document.createElement('wje-option');\n option.value = o;\n option.textContent = o;\n return option;\n });\n\n let info = document.createElement('div');\n info.classList.add('info');\n info.innerHTML = `${this.paginateObj.startIndex + 1} - ${this.paginateObj.endIndex + 1} ${this.localizer.translate('wj.pagination.of')} ${this.totalItems}`;\n\n let pagination = document.createElement('div');\n pagination.classList.add('pages');\n\n const button = document.createElement('wje-button');\n button.setAttribute('fill', 'link');\n if (this.round) button.setAttribute('round', '');\n\n // First button\n let firstButton = button.cloneNode(true);\n firstButton.title = this.localizer.translate('wj.pagination.first');\n firstButton.innerHTML = `<wje-icon name=\"chevron-left-pipe\" slot=\"icon-only\"></wje-icon>`;\n firstButton.addEventListener('wje-button:click', (e) => this.pageClickAction(e, 0));\n\n // Previous button\n const prevButton = button.cloneNode(true);\n prevButton.title = this.localizer.translate('wj.pagination.prev');\n prevButton.innerHTML = `<wje-icon name=\"chevron-left\" slot=\"icon-only\"></wje-icon>`;\n if (this.page === 0) prevButton.disabled = true;\n prevButton.addEventListener('wje-button:click', (e) => this.pageClickAction(e, this.page - 1));\n\n // Next button\n const nextButton = button.cloneNode(true);\n nextButton.title = this.localizer.translate('wj.pagination.next');\n nextButton.innerHTML = `<wje-icon name=\"chevron-right\" slot=\"icon-only\"></wje-icon>`;\n if (this.page + 1 >= this.paginateObj.totalPages) nextButton.disabled = true;\n nextButton.addEventListener('wje-button:click', (e) => this.pageClickAction(e, this.page + 1));\n\n // Last button\n let lastButton = button.cloneNode(true);\n lastButton.title = this.localizer.translate('wj.pagination.last');\n lastButton.innerHTML = `<wje-icon name=\"chevron-right-pipe\" slot=\"icon-only\"></wje-icon>`;\n lastButton.disabled = this.paginateObj.endIndex + 1 >= this.totalItems;\n lastButton.addEventListener('wje-button:click', (e) =>\n this.pageClickAction(e, this.paginateObj.totalPages - 1)\n );\n\n select.append(...options);\n\n if (this.showFirstButton) pagination.appendChild(firstButton);\n pagination.appendChild(prevButton);\n pagination.appendChild(this.htmlStackButtons(this.paginateObj));\n pagination.appendChild(nextButton);\n if (this.showLastButton) pagination.appendChild(lastButton);\n\n if (this.showPageSizeOptions) fragment.append(select);\n if (this.showInfo) fragment.appendChild(info);\n fragment.appendChild(pagination);\n\n return fragment;\n }\n\n /**\n * Creates and returns a DocumentFragment containing a series of buttons for pagination purposes,\n * based on the provided pagination object.\n * @param {object} paginateObj An object containing pagination details.\n * @param {number} paginateObj.currentPage The current active page index (1-based).\n * @param {Array<number>} paginateObj.pages An array of page numbers to display in the pagination.\n * @param {number} paginateObj.totalPages Total number of pages available for pagination.\n * @returns {DocumentFragment} A DocumentFragment containing the buttons and additional pagination elements.\n */\n htmlStackButtons(paginateObj) {\n let fragment = document.createDocumentFragment();\n\n const button = document.createElement('wje-button');\n button.setAttribute('fill', 'link');\n if (this.round) button.setAttribute('round', '');\n\n let dots = document.createElement('span');\n dots.classList.add('dots');\n\n const first = button.cloneNode(true);\n first.textContent = '1';\n first.addEventListener('wje-button:click', (e) => this.pageClickAction(e, 0));\n\n const last = button.cloneNode(true);\n last.textContent = paginateObj.totalPages;\n last.addEventListener('wje-button:click', (e) => this.pageClickAction(e, paginateObj.totalPages - 1));\n\n if (paginateObj.currentPage >= this.maxPages + 1 && paginateObj.boundary < paginateObj.totalPages) {\n fragment.appendChild(first);\n fragment.appendChild(dots);\n }\n\n paginateObj.pages.forEach((page) => {\n let newButton = button.cloneNode(true);\n newButton.textContent = page;\n\n if (page - 1 === this.page) {\n newButton.removeAttribute('fill');\n } else {\n newButton.addEventListener('wje-button:click', (e) => this.pageClickAction(e, page - 1));\n }\n\n fragment.appendChild(newButton);\n });\n\n if (\n (paginateObj.pages.length === this.maxPages || paginateObj.currentPage < this.maxPages + 1) &&\n paginateObj.boundary < paginateObj.totalPages\n ) {\n fragment.appendChild(dots.cloneNode(true));\n fragment.appendChild(last);\n }\n\n return fragment;\n }\n\n /**\n * Handles the click action for pagination and updates the current page.\n * If the clicked page number is the same as the current page, no action is performed.\n * Otherwise, the current page is updated to the new page number, and a custom event\n * 'wje-pagination:page-change' is dispatched with the pagination object.\n * @param {Event} e The event triggered by the page click.\n * @param {number} page The page number that was clicked.\n */\n pageClickAction = (e, page) => {\n if (+page === this.page || this.page > this.paginateObj.totalPages) return;\n this.page = page;\n event.dispatchCustomEvent(this, 'wje-pagination:page-change', { page: this.page, pageSize: this.pageSize });\n };\n}\n\nPagination.define('wje-pagination', Pagination);\n","import Pagination from './pagination.element.js';\n\nexport default Pagination;\n\nPagination.define('wje-pagination', Pagination);\n"],"names":[],"mappings":";;;;;;;;AAQO,SAAS,SAAS,YAAY,cAAc,GAAG,WAAW,IAAI,WAAW,GAAG;AAE/E,QAAM,aAAa,KAAK,KAAK,aAAa,QAAQ;AAGlD,MAAI,cAAc,GAAG;AACjB,kBAAc;AAAA,EACt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packages/wje-pagination/pagination.element.js","../packages/wje-pagination/pagination.js"],"sourcesContent":["/**\n * Paginates items based on the total number of items, current page, page size, and maximum number of pages to display.\n * @param {number} totalItems The total number of items to paginate.\n * @param {number} [currentPage] The current page number (default is 1).\n * @param {number} [pageSize] The number of items per page (default is 10).\n * @param {number} [maxPages] The maximum number of pages to display in the pagination control (default is 5).\n * @returns {object} An object containing pagination details including total items, current page, page size, total pages, start/end page, start/end index, and the pages array.\n */\nexport function paginate(totalItems, currentPage = 1, pageSize = 10, maxPages = 5) {\n // Calculate total pages\n const totalPages = Math.ceil(totalItems / pageSize);\n\n // Ensure current page is within valid range\n if (currentPage < 1) {\n currentPage = 1;\n } else if (currentPage > totalPages) {\n currentPage = totalPages;\n }\n\n let startPage;\n let endPage;\n\n const pagesNearEnd = maxPages + 1; // Define how close to the end we switch back to 5 pages 4\n\n const boundary = pagesNearEnd + 3;\n\n if (totalPages > boundary) {\n if (currentPage < pagesNearEnd) {\n // If in the first 4 pages, show up to 5 pages\n startPage = 1;\n endPage = Math.min(pagesNearEnd + 1, totalPages); //5\n } else if (currentPage >= totalPages - pagesNearEnd) {\n // If within 4 pages from the end, show last 5 pages\n startPage = Math.max(totalPages - pagesNearEnd, 1); //4\n endPage = totalPages;\n } else {\n const halfPages = Math.floor(maxPages / 2);\n // Otherwise, only show 3 pages (current, previous, next)\n startPage = currentPage - halfPages + 1;\n endPage = maxPages % 2 === 1 ? currentPage + halfPages + 1 : currentPage + halfPages - 1;\n }\n } else {\n startPage = 1;\n endPage = totalPages;\n }\n\n // Calculate start and end item indexes\n const startIndex = (currentPage - 1) * pageSize;\n const endIndex = Math.min(startIndex + pageSize - 1, totalItems - 1);\n\n // Create an array of pages to display\n const pages = Array.from({ length: endPage - startPage + 1 }, (_, i) => startPage + i);\n\n // Return object with all pager properties (preserving original format)\n return {\n boundary: boundary,\n currentPage: currentPage,\n endIndex: endIndex,\n endPage: endPage,\n totalPages: totalPages,\n pages: pages,\n pageSize: pageSize,\n startIndex: startIndex,\n startPage: startPage,\n totalItems: totalItems,\n };\n}\n","import { Localizer } from '../utils/localize.js';\nimport { default as WJElement, event } from '../wje-element/element.js';\nimport { paginate } from './service/service.js';\nimport Icon from '../wje-icon/icon.js';\nimport Button from '../wje-button/button.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary This class represents the Pagination component for navigating through paginated content and dynamically updating navigation elements based on attributes like the number of items, page size, etc. Extends the WJElement class.\n * @documentation https://elements.webjet.sk/components/pagination\n * @status stable\n * @augments WJElement\n * @dependency wje-icon, wje-button\n * @csspart native - The wrapper element for the pagination component.\n */\nexport default class Pagination extends WJElement {\n /**\n * Creates an instance of Pagination.\n */\n constructor() {\n super();\n this.localizer = new Localizer(this);\n\n this._paginateObj = null;\n }\n\n /**\n * Sets the value of the 'page' attribute for the object.\n * @param {string} value The value to set for the 'page' attribute.\n */\n set page(value) {\n this.setAttribute('page', value);\n }\n\n /**\n * Retrieves the current page number as a numeric value.\n * @returns {number} The current page number. Returns 0 if the attribute 'page' is not set or is not a numeric value.\n */\n get page() {\n return +this.getAttribute('page') || 0;\n }\n\n /**\n * Sets the maximum number of pages.\n * Updates the 'max-pages' attribute with the provided value.\n * @param {number|string} value The maximum number of pages to set. Can be a number or a parsable string representing a number.\n */\n set maxPages(value) {\n this.setAttribute('max-pages', value);\n }\n\n /**\n * Gets the maximum number of pages.\n * This getter retrieves the value of the \"max-pages\" attribute from the element.\n * If the attribute is not set or is invalid, it defaults to 3.\n * @returns {number} The maximum number of pages as a numeric value.\n */\n get maxPages() {\n return +this.getAttribute('max-pages') || 10;\n }\n\n /**\n * Sets the `pageSize` attribute to the specified value.\n * @param {number|string} value The desired page size value. This can be a number or a string representation of the size.\n */\n set pageSize(value) {\n this.setAttribute('page-size', value);\n }\n\n /**\n * Retrieves the value of the 'page-size' attribute and converts it to a number.\n * If the attribute is not set or is invalid, returns the default value of 3.\n * @returns {number} The numeric value of the 'page-size' attribute or the default value of 3.\n */\n get pageSize() {\n return +this.getAttribute('page-size') || 3;\n }\n\n /**\n * Sets the total number of items.\n * @param {number} value The new total number of items to set.\n */\n set totalItems(value) {\n this.setAttribute('total-items', value);\n }\n\n /**\n * Retrieves the total number of items represented by the 'total-items' attribute.\n * @returns {number} The total number of items. Defaults to 0 if the attribute is not set or is invalid.\n */\n get totalItems() {\n return +this.getAttribute('total-items') || 0;\n }\n\n /**\n * Sets the visibility of the first button based on the provided value.\n * Adds the 'show-first-button' attribute when the value is truthy, and removes it otherwise.\n * @param {boolean} value Determines whether to show the first button. If true, the 'show-first-button' attribute is added; if false, it is removed.\n */\n set showFirstButton(value) {\n this.removeAttribute('show-first-button');\n\n if (value) {\n this.setAttribute('show-first-button', '');\n }\n }\n\n /**\n * Determines whether the 'show-first-button' attribute is present on the element.\n * @returns {boolean} True if the 'show-first-button' attribute is set; otherwise, false.\n */\n get showFirstButton() {\n return this.hasAttribute('show-first-button');\n }\n\n /**\n * Sets the visibility of the \"last\" button. This method controls the presence\n * or absence of the \"show-last-button\" attribute based on the provided value.\n * @param {boolean} value A boolean value indicating whether to show the \"last\" button.\n * If true, the \"show-last-button\" attribute is added;\n * if false, the attribute is removed.\n */\n set showLastButton(value) {\n this.removeAttribute('show-last-button');\n\n if (value) {\n this.setAttribute('show-last-button', '');\n }\n }\n\n /**\n * Determines if the 'show-last-button' attribute is present on the element.\n * @returns {boolean} True if the 'show-last-button' attribute is present, otherwise false.\n */\n get showLastButton() {\n return this.hasAttribute('show-last-button');\n }\n\n /**\n * Sets the pagination object by calculating the pagination details\n * based on the total items, current page, page size, and maximum pages.\n * @param {object} value The value to set the pagination object. The pagination details are computed internally.\n */\n set paginateObj(value) {\n this._paginateObj = value;\n }\n\n /**\n * Retrieves the pagination object used for managing paginated data.\n * @returns {object} The pagination object containing details and functionality for paginating data.\n */\n get paginateObj() {\n return this._paginateObj;\n }\n\n /**\n * Sets the 'round' attribute on the element. If the provided value is truthy,\n * the 'round' attribute is added. If the value is falsy, the attribute is removed.\n * @param {boolean} value A boolean value determining whether to add or remove the 'round' attribute.\n */\n set round(value) {\n this.removeAttribute('round');\n\n if (value) {\n this.setAttribute('round', '');\n }\n }\n\n /**\n * Retrieves the value of the 'round' attribute for the current element.\n * @returns {boolean} A boolean indicating whether the 'round' attribute is present on the element.\n */\n get round() {\n return this.hasAttribute('round');\n }\n\n /**\n * Sets the `show-info` attribute on the element based on the provided value.\n * @param {boolean} value A boolean indicating whether to add or remove the `show-info` attribute.\n */\n set showInfo(value) {\n this.removeAttribute('show-info');\n\n if (value) {\n this.setAttribute('show-info', '');\n }\n }\n\n /**\n * Retrieves the value of the 'show-info' attribute.\n * Checks if the 'show-info' attribute is present on the element.\n * @returns {boolean} True if the 'show-info' attribute is present, otherwise false.\n */\n get showInfo() {\n return this.hasAttribute('show-info');\n }\n\n set showPageSizeOptions(value) {\n if (!value) return;\n this.setAttribute('show-page-size-options', value);\n }\n\n get showPageSizeOptions() {\n return this.hasAttribute('show-page-size-options');\n }\n\n set pageSizeOptions(value) {\n if (!value) return;\n this.setAttribute('page-size-options', value);\n }\n\n /**\n * Retrieves the list of available page size options.\n * This method is used to fetch the values representing the different page size options\n * that can be provided or configured in a paginated component or system.\n * @returns {Array<number>} An array of numbers representing the selectable page size options.\n */\n get pageSizeOptions() {\n let options = this.getAttribute('page-size-options');\n if (!options) return [6, 10, 50, 100, 500];\n return options.split(',').map((o) => +o).filter((o) => !isNaN(o));\n }\n\n set hideEmpty(value) {\n if (!value) return;\n this.setAttribute('hide-empty', value);\n }\n\n get hideEmpty() {\n return this.hasAttribute('hide-empty');\n }\n\n /**\n * Dependencies of the Button element.\n * @type {object}\n */\n dependencies = {\n 'wje-icon': Icon,\n 'wje-button': Button,\n };\n\n className = 'Pagination';\n\n /**\n * Returns the CSS styles for the component.\n * @static\n * @returns {CSSStyleSheet}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Getter for the observedAttributes attribute of the input element.\n * @returns {Array} The attributes to observe for changes.\n */\n static get observedAttributes() {\n return ['page', 'total-items', 'page-size'];\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n async beforeDraw() {\n this.classList.remove('empty');\n this.removeAttribute(\"hidden\");\n\n if (!this.totalItems || this.totalItems === 0) {\n this.classList.add('empty');\n if (this.hideEmpty)\n this.setAttribute(\"hidden\", \"\");\n\n return;\n }\n\n this.paginateObj = await paginate(this.totalItems, this.page, this.pageSize, this.maxPages) || {};\n }\n\n /**\n * Creates a document fragment, appends a new slot element to it, and returns the fragment.\n * @returns {DocumentFragment} A document fragment containing a slot element.\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.setAttribute('part', 'native');\n native.classList.add('native-pagination');\n\n native.append(this.htmlPagination());\n\n fragment.append(native);\n\n return fragment;\n }\n\n /**\n * Creates a pagination control for navigating between pages of content.\n * This method generates and returns a document fragment containing pagination controls, including buttons for navigating to the first, previous, next, and last pages, as well as optional informational text about the current set of displayed items and total number of items.\n * @returns {DocumentFragment} A document fragment containing the pagination controls.\n */\n htmlPagination() {\n let fragment = document.createDocumentFragment();\n\n let select = document.createElement('wje-select');\n select.setAttribute('size', 'small');\n select.setAttribute('variant', 'standard');\n select.setAttribute('value', this.pageSize);\n select.addEventListener('wje-select:change', (e) => {\n\n if(+e.detail.context.value[0] !== this.pageSize) {\n this.pageSize = +e.detail.context.value[0];\n this.page = 0; // Reset to first page when page size changes\n event.dispatchCustomEvent(this, 'wje-pagination:page-change', { page: this.page, pageSize: this.pageSize });\n }\n });\n\n let options = this.pageSizeOptions.map((o) => {\n let option = document.createElement('wje-option');\n option.value = o;\n option.textContent = o;\n return option;\n });\n\n let info = document.createElement('div');\n info.classList.add('info');\n info.innerHTML = `${this.paginateObj?.startIndex + 1} - ${this.paginateObj?.endIndex + 1} ${this.localizer.translate('wj.pagination.of')} ${this.totalItems}`;\n\n let pagination = document.createElement('div');\n pagination.classList.add('pages');\n\n const button = document.createElement('wje-button');\n button.setAttribute('fill', 'link');\n if (this.round) button.setAttribute('round', '');\n\n // First button\n let firstButton = button.cloneNode(true);\n firstButton.title = this.localizer.translate('wj.pagination.first');\n firstButton.innerHTML = `<wje-icon name=\"chevron-left-pipe\" slot=\"icon-only\"></wje-icon>`;\n firstButton.addEventListener('wje-button:click', (e) => this.pageClickAction(e, 0));\n\n // Previous button\n const prevButton = button.cloneNode(true);\n prevButton.title = this.localizer.translate('wj.pagination.prev');\n prevButton.innerHTML = `<wje-icon name=\"chevron-left\" slot=\"icon-only\"></wje-icon>`;\n if (this.page === 0) prevButton.disabled = true;\n prevButton.addEventListener('wje-button:click', (e) => this.pageClickAction(e, this.page - 1));\n\n // Next button\n const nextButton = button.cloneNode(true);\n nextButton.title = this.localizer.translate('wj.pagination.next');\n nextButton.innerHTML = `<wje-icon name=\"chevron-right\" slot=\"icon-only\"></wje-icon>`;\n if (this.page + 1 >= this.paginateObj?.totalPages) nextButton.disabled = true;\n nextButton.addEventListener('wje-button:click', (e) => this.pageClickAction(e, this.page + 1));\n\n // Last button\n let lastButton = button.cloneNode(true);\n lastButton.title = this.localizer.translate('wj.pagination.last');\n lastButton.innerHTML = `<wje-icon name=\"chevron-right-pipe\" slot=\"icon-only\"></wje-icon>`;\n lastButton.disabled = this.paginateObj?.endIndex + 1 >= this.totalItems;\n lastButton.addEventListener('wje-button:click', (e) =>\n this.pageClickAction(e, this.paginateObj?.totalPages - 1)\n );\n\n select.append(...options);\n\n if (this.showFirstButton) pagination.appendChild(firstButton);\n pagination.appendChild(prevButton);\n pagination.appendChild(this.htmlStackButtons(this.paginateObj));\n pagination.appendChild(nextButton);\n if (this.showLastButton) pagination.appendChild(lastButton);\n\n if (this.showPageSizeOptions) fragment.append(select);\n if (this.showInfo) fragment.appendChild(info);\n fragment.appendChild(pagination);\n\n return fragment;\n }\n\n /**\n * Creates and returns a DocumentFragment containing a series of buttons for pagination purposes,\n * based on the provided pagination object.\n * @param {object} paginateObj An object containing pagination details.\n * @param {number} paginateObj.currentPage The current active page index (1-based).\n * @param {Array<number>} paginateObj.pages An array of page numbers to display in the pagination.\n * @param {number} paginateObj.totalPages Total number of pages available for pagination.\n * @returns {DocumentFragment} A DocumentFragment containing the buttons and additional pagination elements.\n */\n htmlStackButtons(paginateObj) {\n let fragment = document.createDocumentFragment();\n\n const button = document.createElement('wje-button');\n button.setAttribute('fill', 'link');\n if (this.round) button.setAttribute('round', '');\n\n let dots = document.createElement('span');\n dots.classList.add('dots');\n\n const first = button.cloneNode(true);\n first.textContent = '1';\n first.addEventListener('wje-button:click', (e) => this.pageClickAction(e, 0));\n\n const last = button.cloneNode(true);\n last.textContent = paginateObj?.totalPages;\n last.addEventListener('wje-button:click', (e) => this.pageClickAction(e, paginateObj?.totalPages - 1));\n\n if (paginateObj?.currentPage >= this.maxPages + 1 && paginateObj?.boundary < paginateObj?.totalPages) {\n fragment.appendChild(first);\n fragment.appendChild(dots);\n }\n\n paginateObj?.pages.forEach((page) => {\n let newButton = button.cloneNode(true);\n newButton.textContent = page;\n\n if (page - 1 === this.page) {\n newButton.removeAttribute('fill');\n } else {\n newButton.addEventListener('wje-button:click', (e) => this.pageClickAction(e, page - 1));\n }\n\n fragment.appendChild(newButton);\n });\n\n if (\n (paginateObj?.pages.length === this.maxPages || paginateObj?.currentPage < this.maxPages + 1) &&\n paginateObj.boundary < paginateObj?.totalPages\n ) {\n fragment.appendChild(dots.cloneNode(true));\n fragment.appendChild(last);\n }\n\n return fragment;\n }\n\n /**\n * Handles the click action for pagination and updates the current page.\n * If the clicked page number is the same as the current page, no action is performed.\n * Otherwise, the current page is updated to the new page number, and a custom event\n * 'wje-pagination:page-change' is dispatched with the pagination object.\n * @param {Event} e The event triggered by the page click.\n * @param {number} page The page number that was clicked.\n */\n pageClickAction = (e, page) => {\n if (+page === this.page || this.page > this.paginateObj.totalPages) return;\n this.page = page;\n event.dispatchCustomEvent(this, 'wje-pagination:page-change', { page: this.page, pageSize: this.pageSize });\n };\n}\n\nPagination.define('wje-pagination', Pagination);\n","import Pagination from './pagination.element.js';\n\nexport default Pagination;\n\nPagination.define('wje-pagination', Pagination);\n"],"names":["_a"],"mappings":";;;;;;;;AAQO,SAAS,SAAS,YAAY,cAAc,GAAG,WAAW,IAAI,WAAW,GAAG;AAE/E,QAAM,aAAa,KAAK,KAAK,aAAa,QAAQ;AAGlD,MAAI,cAAc,GAAG;AACjB,kBAAc;AAAA,EACtB,WAAe,cAAc,YAAY;AACjC,kBAAc;AAAA,EACtB;AAEI,MAAI;AACJ,MAAI;AAEJ,QAAM,eAAe,WAAW;AAEhC,QAAM,WAAW,eAAe;AAEhC,MAAI,aAAa,UAAU;AACvB,QAAI,cAAc,cAAc;AAE5B,kBAAY;AACZ,gBAAU,KAAK,IAAI,eAAe,GAAG,UAAU;AAAA,IAC3D,WAAmB,eAAe,aAAa,cAAc;AAEjD,kBAAY,KAAK,IAAI,aAAa,cAAc,CAAC;AACjD,gBAAU;AAAA,IACtB,OAAe;AACH,YAAM,YAAY,KAAK,MAAM,WAAW,CAAC;AAEzC,kBAAY,cAAc,YAAY;AACtC,gBAAU,WAAW,MAAM,IAAI,cAAc,YAAY,IAAI,cAAc,YAAY;AAAA,IACnG;AAAA,EACA,OAAW;AACH,gBAAY;AACZ,cAAU;AAAA,EAClB;AAGI,QAAM,cAAc,cAAc,KAAK;AACvC,QAAM,WAAW,KAAK,IAAI,aAAa,WAAW,GAAG,aAAa,CAAC;AAGnE,QAAM,QAAQ,MAAM,KAAK,EAAE,QAAQ,UAAU,YAAY,EAAG,GAAE,CAAC,GAAG,MAAM,YAAY,CAAC;AAGrF,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACH;AACL;;ACnDe,MAAM,mBAAmB,UAAU;AAAA;AAAA;AAAA;AAAA,EAI9C,cAAc;AACV,UAAO;AAwNX;AAAA;AAAA;AAAA;AAAA,wCAAe;AAAA,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C;AAEQ,UACK,2CAAa,MAAM,YAAW,KAAK,aAAY,2CAAa,eAAc,KAAK,WAAW,MAC3F,YAAY,YAAW,2CAAa,aACtC;AACE,eAAS,YAAY,KAAK,UAAU,IAAI,CAAC;AACzC,eAAS,YAAY,IAAI;AAAA,IACrC;AAEQ,WAAO;AAAA,EACf;AAeA;AAEA,WAAW,OAAO,kBAAkB,UAAU;AClc9C,WAAW,OAAO,kBAAkB,UAAU;"}
|
package/dist/wje-radio.js
CHANGED
|
@@ -3,7 +3,7 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
import WJElement from "./wje-element.js";
|
|
5
5
|
import { event } from "./event.js";
|
|
6
|
-
const styles = "/*\n[ WJ Radio ]\n*/\n\n:host {\n
|
|
6
|
+
const styles = "/*\n[ WJ Radio ]\n*/\n\n:host {\n display: block;\n margin-top: var(--wje-radio-margin-top);\n margin-bottom: var(--wje-radio-margin-bottom);\n margin-inline: var(--wje-radio-margin-inline);\n line-height: 100%;\n padding-left: 0;\n position: relative;\n\n label {\n display: flex;\n cursor: pointer;\n position: relative;\n padding-left: 1.5rem;\n min-width: 16px;\n min-height: 16px;\n margin-bottom: 0;\n -webkit-touch-callout: none; /* iOS Safari */\n -webkit-user-select: none; /* Safari */\n -moz-user-select: none; /* Old versions of Firefox */\n -ms-user-select: none; /* Internet Explorer/Edge */\n user-select: none; /* Non-prefixed version, currently supported by Chrome, Opera and Firefox */\n align-items: center;\n &:before {\n content: '';\n position: absolute;\n width: 16px;\n height: 16px;\n left: 0;\n box-sizing: border-box;\n background-color: var(--wje-color-contrast-1);\n border: 1px solid var(--wje-color-contrast-4);\n }\n }\n}\n\n.native-radio {\n input[type='radio'] + label {\n &:before {\n border-radius: var(--wje-border-radius-circle);\n transition: border 0.3s 0s cubic-bezier(0.455, 0.03, 0.215, 1.33);\n }\n }\n input[type='radio']:checked {\n & + label {\n &:before {\n border-color: var(--wje-color-contrast-6);\n border-width: 5px;\n }\n }\n }\n input[type='radio']:focus {\n & + label {\n color: var(--wje-color);\n &:before {\n outline: none !important;\n box-shadow: 0 0 0 0 #78c8fe;\n }\n }\n }\n\n input[type='radio'] {\n opacity: 0;\n position: absolute;\n top: 3px;\n width: 16px;\n height: 16px;\n }\n\n input[type='radio'][disabled] {\n & + label {\n cursor: not-allowed !important;\n color: var(--wje-color-contrast-9);\n opacity: 0.5;\n &:before {\n cursor: not-allowed !important;\n }\n }\n }\n}\n\n:host([placement='end']) {\n label {\n padding-left: 0;\n padding-right: 26px;\n\n &:before {\n right: 0;\n left: auto;\n }\n }\n\n input[type='checkbox']:checked {\n & + label {\n position: relative;\n\n &::after {\n position: absolute;\n right: 0;\n left: auto;\n }\n }\n }\n}\n\n/* Colors */\n\n:host([color='primary']) input[type='radio']:checked + label:before {\n border-color: var(--wje-color-primary-9);\n}\n\n:host([color='complete']) input[type='radio']:checked + label:before {\n border-color: var(--wje-color-complete-9);\n}\n\n:host([color='success']) input[type='radio']:checked + label:before {\n border-color: var(--wje-color-success-9);\n}\n\n:host([color='warning']) input[type='radio']:checked + label:before {\n border-color: var(--wje-color-warning-9);\n}\n\n:host([color='danger']) input[type='radio']:checked + label:before {\n border-color: var(--wje-color-danger-9);\n}\n\n:host([color='info']) input[type='radio']:checked + label:before {\n border-color: var(--wje-color-info-9);\n}\n";
|
|
7
7
|
class Radio extends WJElement {
|
|
8
8
|
/**
|
|
9
9
|
* Creates an instance of Radio.
|
package/dist/wje-reorder-item.js
CHANGED
|
@@ -3,7 +3,7 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
import WJElement from "./wje-element.js";
|
|
5
5
|
import { WjElementUtils } from "./element-utils.js";
|
|
6
|
-
const styles = ":host {\n /*--reorder-background-color: var(--wje-color-contrast-0);*/\n --reorder-item-spacing: 0.5rem;\n}\n\n.item {\n width: 134px;\n height: 19px;\n display: flex;\n align-items: center;\n justify-content: left;\n position: relative;\n gap: var(--reorder-item-spacing);\n padding: var(--reorder-item-spacing);\n border-radius: var(--wje-border-radius-small);\n background-color: var(--reorder-background-color);\n cursor: grab;\n transition:\n top 0.3s ease,\n left 0.3s ease;\n}\n\n.item-w-handle {\n cursor: default;\n}\n\n.item-w-handle:active {\n opacity: 0.3;\n}\n\n.item:active:not(.item-w-handle):not(.moving) {\n background-color: var(--reorder-background-color);\n cursor: grabbing;\n}\n\n.moving {\n background-color: lightgrey;\n}\n\n.handle {\n cursor: grab;\n gap: 10px;\n}\n\n.handle:active {\n cursor: grabbing;\n}\n\n.name {\n width: 108px;\n height: 19px;\n text-align: center;\n font-size: var(--wje-font-size
|
|
6
|
+
const styles = ":host {\n /*--reorder-background-color: var(--wje-color-contrast-0);*/\n --reorder-item-spacing: 0.5rem;\n}\n\n.item {\n width: 134px;\n height: 19px;\n display: flex;\n align-items: center;\n justify-content: left;\n position: relative;\n gap: var(--reorder-item-spacing);\n padding: var(--reorder-item-spacing);\n border-radius: var(--wje-border-radius-small);\n background-color: var(--reorder-background-color);\n cursor: grab;\n transition:\n top 0.3s ease,\n left 0.3s ease;\n}\n\n.item-w-handle {\n cursor: default;\n}\n\n.item-w-handle:active {\n opacity: 0.3;\n}\n\n.item:active:not(.item-w-handle):not(.moving) {\n background-color: var(--reorder-background-color);\n cursor: grabbing;\n}\n\n.moving {\n background-color: lightgrey;\n}\n\n.handle {\n cursor: grab;\n gap: 10px;\n}\n\n.handle:active {\n cursor: grabbing;\n}\n\n.name {\n width: 108px;\n height: 19px;\n text-align: center;\n font-size: var(--wje-font-size);\n font-weight: 400;\n line-height: 19.36px;\n gap: 10px;\n}\n\n/* .drag--down {\n --item-transform: translateY(-5px);\n}\n\n.drag--up {\n --item-transform: translateY(5px);\n} */\n\n.item {\n transform: var(--item-transform);\n}\n";
|
|
7
7
|
class ReorderItem extends WJElement {
|
|
8
8
|
/**
|
|
9
9
|
* Creates an instance of ReorderItem.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wj-elements",
|
|
3
3
|
"description": "WebJET Elements is a modern set of user interface tools harnessing the power of web components designed to simplify web application development.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.217",
|
|
5
5
|
"homepage": "https://github.com/lencys/wj-elements",
|
|
6
6
|
"author": "Lukáš Ondrejček <lukas.ondrejcek@gmail.com>",
|
|
7
7
|
"license": "MIT",
|