wj-elements 0.1.181 → 0.1.182
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 +9 -1
- package/dist/packages/wje-button-group/button-group.element.d.ts +57 -0
- package/dist/packages/wje-options/options.element.d.ts +2 -2
- package/dist/packages/wje-select/select.element.d.ts +2 -0
- package/dist/wje-button-group.js +105 -8
- package/dist/wje-button-group.js.map +1 -1
- package/dist/wje-button.js +2 -2
- package/dist/wje-button.js.map +1 -1
- package/dist/wje-icon-picker.js +1 -2
- package/dist/wje-icon-picker.js.map +1 -1
- package/dist/wje-infinite-scroll.js +380 -1
- package/dist/wje-infinite-scroll.js.map +1 -1
- package/dist/wje-list.js +46 -1
- package/dist/wje-list.js.map +1 -1
- package/dist/wje-master.js +110 -112
- package/dist/wje-master.js.map +1 -1
- package/dist/wje-option.js +1 -0
- package/dist/wje-option.js.map +1 -1
- package/dist/wje-options.js +2 -2
- package/dist/wje-options.js.map +1 -1
- package/dist/wje-select.js +8 -1
- package/dist/wje-select.js.map +1 -1
- package/package.json +1 -1
- package/dist/infinite-scroll.element-La0Qx41F.js +0 -384
- package/dist/infinite-scroll.element-La0Qx41F.js.map +0 -1
- package/dist/list.element-D4-wlFN_.js +0 -50
- package/dist/list.element-D4-wlFN_.js.map +0 -1
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __typeError = (msg) => {
|
|
3
|
-
throw TypeError(msg);
|
|
4
|
-
};
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
|
-
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
8
|
-
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
9
|
-
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
10
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
11
|
-
var _drawnItems, _loadedItems, _response, _infiniteScrollTemplate, _abortController, _signal, _loading;
|
|
12
|
-
import WJElement from "./wje-element.js";
|
|
13
|
-
import { WjElementUtils } from "./element-utils.js";
|
|
14
|
-
import { event } from "./event.js";
|
|
15
|
-
const styles = "/*\n[ Wj infinite Scroll ]\n*/\n\n:host {\n overflow-x: auto;\n width: var(--wje-infinite-scroll-width);\n height: var(--wje-infinite-scroll-height);\n display: block;\n}\n\n.native {\n /*position: relative;*/\n}\n\n.loading {\n position: sticky;\n display: none;\n justify-content: center;\n align-items: center;\n width: 100%;\n height: 100%;\n top: 0;\n left: 0;\n z-index: 9999;\n background-color: var(--wje-infinite-scroll-loading-bg);\n &.show {\n display: flex;\n }\n}\n\n[name='ending'] {\n display: none;\n margin-top: 1rem;\n text-align: center;\n}\n\n[name='ending'].show {\n display: block;\n}\n";
|
|
16
|
-
class InfiniteScroll extends WJElement {
|
|
17
|
-
/**
|
|
18
|
-
* Creates an instance of InfiniteScroll.
|
|
19
|
-
*/
|
|
20
|
-
constructor() {
|
|
21
|
-
super();
|
|
22
|
-
__privateAdd(this, _drawnItems);
|
|
23
|
-
__privateAdd(this, _loadedItems);
|
|
24
|
-
__privateAdd(this, _response);
|
|
25
|
-
__privateAdd(this, _infiniteScrollTemplate);
|
|
26
|
-
__privateAdd(this, _abortController);
|
|
27
|
-
__privateAdd(this, _signal);
|
|
28
|
-
__privateAdd(this, _loading);
|
|
29
|
-
__publicField(this, "className", "InfiniteScroll");
|
|
30
|
-
/**
|
|
31
|
-
* Attaches a scroll event listener to the current object.
|
|
32
|
-
* The `scrollEvent` function binds the `onScroll` method to the 'scroll' event
|
|
33
|
-
* of the current object. This enables handling of scroll events for
|
|
34
|
-
* specific functionality such as updating UI elements, loading content dynamically,
|
|
35
|
-
* or tracking user interaction with scrollable content.
|
|
36
|
-
*/
|
|
37
|
-
__publicField(this, "scrollEvent", () => {
|
|
38
|
-
this.addEventListener("scroll", this.onScroll);
|
|
39
|
-
});
|
|
40
|
-
/**
|
|
41
|
-
* A function that removes the scroll event listener from the current context.
|
|
42
|
-
* This function is used to unbind the `onScroll` event listener
|
|
43
|
-
* from the `scroll` event of the current object. It ensures that
|
|
44
|
-
* the scroll event no longer triggers the `onScroll` handler.
|
|
45
|
-
* @function
|
|
46
|
-
*/
|
|
47
|
-
__publicField(this, "unScrollEvent", () => {
|
|
48
|
-
this.removeEventListener("scroll", this.onScroll);
|
|
49
|
-
});
|
|
50
|
-
/**
|
|
51
|
-
* A scroll event handler function that checks the scroll position and triggers loading additional content
|
|
52
|
-
* when the user scrolls near the bottom of the page.
|
|
53
|
-
* Properties accessed:
|
|
54
|
-
* - `scrollTop`: The number of pixels that the content of an element is scrolled vertically.
|
|
55
|
-
* - `scrollHeight`: The total height of the element's content.
|
|
56
|
-
* - `clientHeight`: The inner height of the element in pixels, including padding but excluding borders and scrollbars.
|
|
57
|
-
* Conditions:
|
|
58
|
-
* - Determines if the scroll position is within 300 pixels of the bottom of the element.
|
|
59
|
-
* - Verifies that the current page number is less than or equal to the total number of pages.
|
|
60
|
-
* - Checks if the current page is already in the loading state.
|
|
61
|
-
* Actions:
|
|
62
|
-
* - Increments the current page number when the conditions are met.
|
|
63
|
-
* - Initiates loading for the next page by calling the `loadPages` function.
|
|
64
|
-
* @param {Event} e The scroll event object.
|
|
65
|
-
*/
|
|
66
|
-
__publicField(this, "onScroll", (e) => {
|
|
67
|
-
const { scrollTop, scrollHeight, clientHeight } = e.target;
|
|
68
|
-
if (scrollTop + clientHeight >= scrollHeight - 300 && this.currentPage <= this.totalPages && this.isLoading.includes(this.currentPage)) {
|
|
69
|
-
this.currentPage++;
|
|
70
|
-
__privateSet(this, _loading, this.loadPages(this.currentPage));
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
__publicField(this, "compareFunction", (i, item) => i.id === item.id);
|
|
74
|
-
/**
|
|
75
|
-
* Converts a data item into an HTML element based on a template.
|
|
76
|
-
* This function takes a data item, interpolates it into a predefined template,
|
|
77
|
-
* parses the resulting HTML string, and returns the first child element of the parsed HTML content.
|
|
78
|
-
* @param {object} item The data object to interpolate into the HTML template.
|
|
79
|
-
* @returns {Element} The first child element generated from the interpolated HTML string.
|
|
80
|
-
*/
|
|
81
|
-
__publicField(this, "dataToHtml", (item) => {
|
|
82
|
-
let interpolateItem = this.interpolate(this.infiniteScrollTemplate, item);
|
|
83
|
-
let doc = this.parser.parseFromString(interpolateItem, "text/html");
|
|
84
|
-
let element = doc.activeElement.firstElementChild;
|
|
85
|
-
return element;
|
|
86
|
-
});
|
|
87
|
-
/**
|
|
88
|
-
* A custom implementation of the forEach method designed to iterate over an array of data,
|
|
89
|
-
* transform each item into an HTML element, and append the element to a specified placement object.
|
|
90
|
-
* Additionally, it adds an event listener to each generated element for handling click events.
|
|
91
|
-
* @param {Array} data An array of items to process. Each item is transformed into an HTML element
|
|
92
|
-
* and appended to the placement object specified in the context of `this`.
|
|
93
|
-
*/
|
|
94
|
-
__publicField(this, "customForeach", (data) => {
|
|
95
|
-
data.forEach((item) => {
|
|
96
|
-
let element = this.dataToHtml(item);
|
|
97
|
-
let symbol = Symbol("infinite-scroll-item");
|
|
98
|
-
element[symbol] = item;
|
|
99
|
-
item[symbol] = element;
|
|
100
|
-
event.addListener(element, "click", "wje-infinite-scroll:click-item", null);
|
|
101
|
-
this.placementObj.insertAdjacentElement("beforeend", element);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
/**
|
|
105
|
-
* Interpolates a string template with values from the provided parameters object.
|
|
106
|
-
* The template contains placeholders in the format `{{key}}` or `{{key.subkey}}`,
|
|
107
|
-
* which are replaced with the corresponding values from the `params` object.
|
|
108
|
-
* Placeholders support dot notation for accessing nested properties within the `params` object.
|
|
109
|
-
* @param {string} template The string template containing placeholders to be replaced.
|
|
110
|
-
* @param {object} params The object containing key-value pairs used for substitution in the template.
|
|
111
|
-
* @returns {string} A string with all placeholders replaced by their respective values from the `params` object.
|
|
112
|
-
*/
|
|
113
|
-
__publicField(this, "interpolate", (template, params) => {
|
|
114
|
-
let keys = template.match(/\{{.*?\}}/g);
|
|
115
|
-
if (keys) {
|
|
116
|
-
for (let key of keys) {
|
|
117
|
-
let cleanKey = key.replace("{{", "").replace("}}", "");
|
|
118
|
-
let val = "";
|
|
119
|
-
cleanKey.split(".").forEach((k) => {
|
|
120
|
-
val = val === "" ? params[k] : val[k];
|
|
121
|
-
});
|
|
122
|
-
template = template.replace(key, val);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return template;
|
|
126
|
-
});
|
|
127
|
-
this.totalPages = 0;
|
|
128
|
-
this.isLoading = [];
|
|
129
|
-
__privateSet(this, _response, {});
|
|
130
|
-
this.iterate = null;
|
|
131
|
-
__privateSet(this, _infiniteScrollTemplate, null);
|
|
132
|
-
__privateSet(this, _abortController, new AbortController());
|
|
133
|
-
__privateSet(this, _signal, __privateGet(this, _abortController).signal);
|
|
134
|
-
__privateSet(this, _drawnItems, []);
|
|
135
|
-
__privateSet(this, _loadedItems, []);
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Dependencies of the InfiniteScroll component.
|
|
139
|
-
* @param value
|
|
140
|
-
*/
|
|
141
|
-
set infiniteScrollTemplate(value) {
|
|
142
|
-
__privateSet(this, _infiniteScrollTemplate, value);
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Getter for the infiniteScrollTemplate property.
|
|
146
|
-
* @returns {null}
|
|
147
|
-
*/
|
|
148
|
-
get infiniteScrollTemplate() {
|
|
149
|
-
return __privateGet(this, _infiniteScrollTemplate);
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Dependencies of the InfiniteScroll component.
|
|
153
|
-
* @param value
|
|
154
|
-
*/
|
|
155
|
-
set response(value) {
|
|
156
|
-
__privateSet(this, _response, value);
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Getter for the response property.
|
|
160
|
-
* @returns {*|{}}
|
|
161
|
-
*/
|
|
162
|
-
get response() {
|
|
163
|
-
return __privateGet(this, _response);
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Dependencies of the InfiniteScroll component.
|
|
167
|
-
* @param value
|
|
168
|
-
*/
|
|
169
|
-
set objectName(value) {
|
|
170
|
-
this.setAttribute("object-name", value);
|
|
171
|
-
}
|
|
172
|
-
get objectName() {
|
|
173
|
-
return this.getAttribute("object-name") ?? "data";
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Returns the CSS styles for the component.
|
|
177
|
-
* @static
|
|
178
|
-
* @returns {CSSStyleSheet}
|
|
179
|
-
*/
|
|
180
|
-
static get cssStyleSheet() {
|
|
181
|
-
return styles;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Returns the list of attributes to observe for changes.
|
|
185
|
-
* @static
|
|
186
|
-
* @returns {Array<string>}
|
|
187
|
-
*/
|
|
188
|
-
static get observedAttributes() {
|
|
189
|
-
return [];
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Sets up the attributes for the component.
|
|
193
|
-
*/
|
|
194
|
-
setupAttributes() {
|
|
195
|
-
this.isShadowRoot = "open";
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Prepares the component for updates before it is drawn.
|
|
199
|
-
* This method handles the removal of templates for iteration, adjusts the height styling of the component,
|
|
200
|
-
* and manages abort signals for loading operations.
|
|
201
|
-
* @returns {void} No return value.
|
|
202
|
-
*/
|
|
203
|
-
beforeDraw() {
|
|
204
|
-
var _a, _b, _c;
|
|
205
|
-
__privateSet(this, _loadedItems, []);
|
|
206
|
-
__privateSet(this, _drawnItems, []);
|
|
207
|
-
this.iterate = this.querySelector("[iterate]");
|
|
208
|
-
if (this.iterate) {
|
|
209
|
-
if (this.iterate.nodeName !== "TEMPLATE") {
|
|
210
|
-
console.error("The iterate attribute must be a template element");
|
|
211
|
-
this.infiniteScrollTemplate = (_a = this.iterate) == null ? void 0 : _a.outerHTML;
|
|
212
|
-
} else {
|
|
213
|
-
this.infiniteScrollTemplate = (_b = this.iterate) == null ? void 0 : _b.innerHTML;
|
|
214
|
-
}
|
|
215
|
-
(_c = this.iterate) == null ? void 0 : _c.remove();
|
|
216
|
-
}
|
|
217
|
-
this.setAttribute("style", "height: " + this.height);
|
|
218
|
-
if (__privateGet(this, _signal)) {
|
|
219
|
-
__privateGet(this, _abortController).abort();
|
|
220
|
-
__privateSet(this, _abortController, new AbortController());
|
|
221
|
-
__privateSet(this, _signal, __privateGet(this, _abortController).signal);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Creates and returns a document fragment containing the structure for an infinite scroll component.
|
|
226
|
-
* The structure includes native elements, slots for customization, and optional loading content.
|
|
227
|
-
* @returns {DocumentFragment} The document fragment containing the component's DOM structure.
|
|
228
|
-
*/
|
|
229
|
-
draw() {
|
|
230
|
-
let fragment = document.createDocumentFragment();
|
|
231
|
-
let native = document.createElement("div");
|
|
232
|
-
native.classList.add("native");
|
|
233
|
-
native.setAttribute("part", "native-infinite-scroll");
|
|
234
|
-
let slot = document.createElement("slot");
|
|
235
|
-
let ending = document.createElement("slot");
|
|
236
|
-
ending.setAttribute("name", "ending");
|
|
237
|
-
if (WjElementUtils.hasSlot(this, "loader")) {
|
|
238
|
-
let loading = document.createElement("div");
|
|
239
|
-
loading.classList.add("loading");
|
|
240
|
-
let loader = document.createElement("slot");
|
|
241
|
-
loader.setAttribute("name", "loader");
|
|
242
|
-
loading.appendChild(loader);
|
|
243
|
-
this.loadingEl = loading;
|
|
244
|
-
fragment.appendChild(loading);
|
|
245
|
-
}
|
|
246
|
-
native.appendChild(slot);
|
|
247
|
-
native.appendChild(ending);
|
|
248
|
-
fragment.appendChild(native);
|
|
249
|
-
this.endingEl = ending;
|
|
250
|
-
return fragment;
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Called after the component has been drawn.
|
|
254
|
-
*/
|
|
255
|
-
async afterDraw() {
|
|
256
|
-
this.queryParams = this.queryParams || "";
|
|
257
|
-
this.size = +this.size || 10;
|
|
258
|
-
this.currentPage = 0;
|
|
259
|
-
this.scrollEvent();
|
|
260
|
-
__privateSet(this, _loading, this.loadPages(this.currentPage));
|
|
261
|
-
await __privateGet(this, _loading);
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Fetches the pages from the server.
|
|
265
|
-
* @param {number} page The page number.
|
|
266
|
-
* @returns {Promise<object>} The response from the server.
|
|
267
|
-
*/
|
|
268
|
-
async getPages(page) {
|
|
269
|
-
let hasParams = this.url.includes("?");
|
|
270
|
-
const response = await fetch(
|
|
271
|
-
`${this.url}${hasParams ? "&" : "?"}page=${page}&size=${this.size}${this == null ? void 0 : this.queryParams}`,
|
|
272
|
-
{
|
|
273
|
-
signal: __privateGet(this, _signal)
|
|
274
|
-
}
|
|
275
|
-
);
|
|
276
|
-
if (!response.ok) {
|
|
277
|
-
throw new Error(`An error occurred: ${response.status}`);
|
|
278
|
-
}
|
|
279
|
-
return await response.json();
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Hides the loader.
|
|
283
|
-
*/
|
|
284
|
-
hideLoader() {
|
|
285
|
-
var _a;
|
|
286
|
-
(_a = this == null ? void 0 : this.loadingEl) == null ? void 0 : _a.classList.remove("show");
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Displays the loader element by adding the 'show' class to its class list.
|
|
290
|
-
* This method is useful for indicating a loading or processing state in the UI.
|
|
291
|
-
* @returns {void} No return value.
|
|
292
|
-
*/
|
|
293
|
-
showLoader() {
|
|
294
|
-
var _a;
|
|
295
|
-
(_a = this == null ? void 0 : this.loadingEl) == null ? void 0 : _a.classList.add("show");
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Checks if there are more pages to load.
|
|
299
|
-
* @param {number} page The page number.
|
|
300
|
-
* @returns {boolean} Whether there are more pages to load.
|
|
301
|
-
*/
|
|
302
|
-
hasMorePages(page) {
|
|
303
|
-
return this.totalPages === 0 || page < this.totalPages;
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Loads the pages.
|
|
307
|
-
* @param {number} page The page number.
|
|
308
|
-
*/
|
|
309
|
-
async loadPages(page) {
|
|
310
|
-
this.showLoader();
|
|
311
|
-
try {
|
|
312
|
-
if (this.hasMorePages(page)) {
|
|
313
|
-
let response;
|
|
314
|
-
this.parser = new DOMParser();
|
|
315
|
-
if (typeof this.setCustomData === "function") {
|
|
316
|
-
response = await this.setCustomData(page, __privateGet(this, _signal));
|
|
317
|
-
} else {
|
|
318
|
-
response = await this.getPages(page);
|
|
319
|
-
}
|
|
320
|
-
this.totalPages = response == null ? void 0 : response.totalPages;
|
|
321
|
-
this.currentPage = page;
|
|
322
|
-
this.placementObj = this;
|
|
323
|
-
if (this.hasAttribute("placement")) this.placementObj = this.querySelector(this.placement);
|
|
324
|
-
event.dispatchCustomEvent(this, "wje-infinite-scroll:load", response);
|
|
325
|
-
this.response = response;
|
|
326
|
-
__privateSet(this, _loadedItems, this.objectName ? response[this.objectName] : response);
|
|
327
|
-
const notDrawnItems = __privateGet(this, _loadedItems).filter(
|
|
328
|
-
(item) => !__privateGet(this, _drawnItems).some(this.compareFunction.bind(this, item))
|
|
329
|
-
);
|
|
330
|
-
this.customForeach(notDrawnItems);
|
|
331
|
-
__privateGet(this, _drawnItems).push(...notDrawnItems);
|
|
332
|
-
this.isLoading.push(page);
|
|
333
|
-
} else {
|
|
334
|
-
event.dispatchCustomEvent(this, "wje-infinite-scroll:complete");
|
|
335
|
-
this.endingEl.classList.add("show");
|
|
336
|
-
}
|
|
337
|
-
} catch (error) {
|
|
338
|
-
console.log(error);
|
|
339
|
-
} finally {
|
|
340
|
-
this.hideLoader();
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
addItem(item, place = "beforeend") {
|
|
344
|
-
let element = this.dataToHtml(item);
|
|
345
|
-
let symbol = Symbol("infinite-scroll-item");
|
|
346
|
-
element[symbol] = item;
|
|
347
|
-
item[symbol] = element;
|
|
348
|
-
this.placementObj.insertAdjacentElement(place, element);
|
|
349
|
-
__privateGet(this, _drawnItems).push(item);
|
|
350
|
-
if (__privateGet(this, _drawnItems).length > this.size * this.currentPage) {
|
|
351
|
-
this.totalPages += 1;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
removeItem(item) {
|
|
355
|
-
let drawnItem = __privateGet(this, _drawnItems).find(this.compareFunction.bind(this, item));
|
|
356
|
-
if (!drawnItem) {
|
|
357
|
-
console.error("Item not found");
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
let symbol = Object.getOwnPropertySymbols(drawnItem).at(0);
|
|
361
|
-
let element = drawnItem[symbol];
|
|
362
|
-
if (!element) {
|
|
363
|
-
console.error("Element not found");
|
|
364
|
-
return;
|
|
365
|
-
}
|
|
366
|
-
element == null ? void 0 : element.remove();
|
|
367
|
-
__privateSet(this, _drawnItems, __privateGet(this, _drawnItems).filter((i) => i !== item));
|
|
368
|
-
if (__privateGet(this, _drawnItems).length < this.size * this.currentPage) {
|
|
369
|
-
this.isLoading = this.isLoading.filter((i) => i !== this.currentPage);
|
|
370
|
-
this.currentPage--;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
_drawnItems = new WeakMap();
|
|
375
|
-
_loadedItems = new WeakMap();
|
|
376
|
-
_response = new WeakMap();
|
|
377
|
-
_infiniteScrollTemplate = new WeakMap();
|
|
378
|
-
_abortController = new WeakMap();
|
|
379
|
-
_signal = new WeakMap();
|
|
380
|
-
_loading = new WeakMap();
|
|
381
|
-
export {
|
|
382
|
-
InfiniteScroll as I
|
|
383
|
-
};
|
|
384
|
-
//# sourceMappingURL=infinite-scroll.element-La0Qx41F.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"infinite-scroll.element-La0Qx41F.js","sources":["../packages/wje-infinite-scroll/infinite-scroll.element.js"],"sourcesContent":["import { default as WJElement, event, WjElementUtils } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * `InfiniteScroll` is a custom web component that represents an infinite scroll.\n * It extends from `WJElement`.\n * @summary This element allows users to scroll through a potentially infinite amount of content.\n * @documentation https://elements.webjet.sk/components/infinite-scroll\n * @status stable\n * @augments {WJElement}\n * @csspart loader - The loader part of the infinite scroll.\n * @slot - The default slot for the infinite scroll.\n * @cssproperty [--wje-infinite-scroll-width=100%] - Sets the width of the infinite scroll container. his property determines how wide the infinite scroll area will be relative to its parent element. Accepts any valid CSS width value, such as percentages (`%`), pixels (`px`), or viewport units (`vw`). The default value is `100%`, which makes it span the full width of its container.\n * @cssproperty [--wje-infinite-scroll-height=300px] - Defines the height of the infinite scroll container. This property specifies how tall the infinite scroll area should be. Accepts any valid CSS height value, such as pixels (`px`), percentages (`%`), or viewport units (`vh`). The default value is `300px`, providing a fixed height suitable for most use cases.\n * //@fires wje-infinite-scroll:click-item - Event fired when an item is clicked.\n * @tag wje-infinite-scroll\n */\n\nexport default class InfiniteScroll extends WJElement {\n #drawnItems;\n #loadedItems;\n #response;\n #infiniteScrollTemplate;\n #abortController;\n #signal;\n #loading;\n /**\n * Creates an instance of InfiniteScroll.\n */\n constructor() {\n super();\n\n this.totalPages = 0;\n this.isLoading = [];\n this.#response = {};\n this.iterate = null;\n this.#infiniteScrollTemplate = null;\n this.#abortController = new AbortController();\n this.#signal = this.#abortController.signal;\n this.#drawnItems = [];\n this.#loadedItems = [];\n }\n\n /**\n * Dependencies of the InfiniteScroll component.\n * @param value\n */\n set infiniteScrollTemplate(value) {\n this.#infiniteScrollTemplate = value;\n }\n\n /**\n * Getter for the infiniteScrollTemplate property.\n * @returns {null}\n */\n get infiniteScrollTemplate() {\n return this.#infiniteScrollTemplate;\n }\n\n /**\n * Dependencies of the InfiniteScroll component.\n * @param value\n */\n set response(value) {\n this.#response = value;\n }\n\n /**\n * Getter for the response property.\n * @returns {*|{}}\n */\n get response() {\n return this.#response;\n }\n\n /**\n * Dependencies of the InfiniteScroll component.\n * @param value\n */\n set objectName(value) {\n this.setAttribute('object-name', value);\n }\n\n get objectName() {\n return this.getAttribute('object-name') ?? 'data';\n }\n\n className = 'InfiniteScroll';\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 * Returns the list of attributes to observe for changes.\n * @static\n * @returns {Array<string>}\n */\n static get observedAttributes() {\n return [];\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Prepares the component for updates before it is drawn.\n * This method handles the removal of templates for iteration, adjusts the height styling of the component,\n * and manages abort signals for loading operations.\n * @returns {void} No return value.\n */\n beforeDraw() {\n this.#loadedItems = [];\n this.#drawnItems = [];\n\n this.iterate = this.querySelector('[iterate]');\n\n if (this.iterate) {\n if (this.iterate.nodeName !== 'TEMPLATE') {\n console.error('The iterate attribute must be a template element');\n this.infiniteScrollTemplate = this.iterate?.outerHTML;\n } else {\n this.infiniteScrollTemplate = this.iterate?.innerHTML;\n }\n\n this.iterate?.remove(); // remove template\n }\n\n this.setAttribute('style', 'height: ' + this.height);\n\n // if this.#loading is not fulfilled then cancel the promise\n if (this.#signal) {\n this.#abortController.abort();\n this.#abortController = new AbortController();\n this.#signal = this.#abortController.signal;\n }\n }\n\n /**\n * Creates and returns a document fragment containing the structure for an infinite scroll component.\n * The structure includes native elements, slots for customization, and optional loading content.\n * @returns {DocumentFragment} The document fragment containing the component's DOM structure.\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.classList.add('native');\n native.setAttribute('part', 'native-infinite-scroll');\n\n let slot = document.createElement('slot');\n\n let ending = document.createElement('slot');\n ending.setAttribute('name', 'ending');\n\n if (WjElementUtils.hasSlot(this, 'loader')) {\n let loading = document.createElement('div');\n loading.classList.add('loading');\n\n let loader = document.createElement('slot');\n loader.setAttribute('name', 'loader');\n\n loading.appendChild(loader);\n\n this.loadingEl = loading;\n\n fragment.appendChild(loading);\n }\n\n native.appendChild(slot);\n native.appendChild(ending);\n\n fragment.appendChild(native);\n\n this.endingEl = ending;\n\n return fragment;\n }\n\n /**\n * Called after the component has been drawn.\n */\n async afterDraw() {\n this.queryParams = this.queryParams || '';\n this.size = +this.size || 10;\n this.currentPage = 0;\n\n this.scrollEvent();\n this.#loading = this.loadPages(this.currentPage);\n await this.#loading;\n }\n\n /**\n * Attaches a scroll event listener to the current object.\n * The `scrollEvent` function binds the `onScroll` method to the 'scroll' event\n * of the current object. This enables handling of scroll events for\n * specific functionality such as updating UI elements, loading content dynamically,\n * or tracking user interaction with scrollable content.\n */\n scrollEvent = () => {\n this.addEventListener('scroll', this.onScroll);\n };\n\n /**\n * A function that removes the scroll event listener from the current context.\n * This function is used to unbind the `onScroll` event listener\n * from the `scroll` event of the current object. It ensures that\n * the scroll event no longer triggers the `onScroll` handler.\n * @function\n */\n unScrollEvent = () => {\n this.removeEventListener('scroll', this.onScroll);\n };\n\n /**\n * A scroll event handler function that checks the scroll position and triggers loading additional content\n * when the user scrolls near the bottom of the page.\n * Properties accessed:\n * - `scrollTop`: The number of pixels that the content of an element is scrolled vertically.\n * - `scrollHeight`: The total height of the element's content.\n * - `clientHeight`: The inner height of the element in pixels, including padding but excluding borders and scrollbars.\n * Conditions:\n * - Determines if the scroll position is within 300 pixels of the bottom of the element.\n * - Verifies that the current page number is less than or equal to the total number of pages.\n * - Checks if the current page is already in the loading state.\n * Actions:\n * - Increments the current page number when the conditions are met.\n * - Initiates loading for the next page by calling the `loadPages` function.\n * @param {Event} e The scroll event object.\n */\n onScroll = (e) => {\n const { scrollTop, scrollHeight, clientHeight } = e.target;\n\n if (\n scrollTop + clientHeight >= scrollHeight - 300 &&\n this.currentPage <= this.totalPages &&\n this.isLoading.includes(this.currentPage)\n ) {\n this.currentPage++;\n this.#loading = this.loadPages(this.currentPage);\n }\n };\n\n /**\n * Fetches the pages from the server.\n * @param {number} page The page number.\n * @returns {Promise<object>} The response from the server.\n */\n async getPages(page) {\n let hasParams = this.url.includes('?');\n const response = await fetch(\n `${this.url}${hasParams ? '&' : '?'}page=${page}&size=${this.size}${this?.queryParams}`,\n {\n signal: this.#signal,\n }\n );\n\n if (!response.ok) {\n throw new Error(`An error occurred: ${response.status}`);\n }\n return await response.json();\n }\n\n /**\n * Hides the loader.\n */\n hideLoader() {\n this?.loadingEl?.classList.remove('show');\n }\n\n /**\n * Displays the loader element by adding the 'show' class to its class list.\n * This method is useful for indicating a loading or processing state in the UI.\n * @returns {void} No return value.\n */\n showLoader() {\n this?.loadingEl?.classList.add('show');\n }\n\n /**\n * Checks if there are more pages to load.\n * @param {number} page The page number.\n * @returns {boolean} Whether there are more pages to load.\n */\n hasMorePages(page) {\n return this.totalPages === 0 || page < this.totalPages;\n }\n\n /**\n * Loads the pages.\n * @param {number} page The page number.\n */\n async loadPages(page) {\n this.showLoader();\n try {\n if (this.hasMorePages(page)) {\n let response;\n this.parser = new DOMParser();\n\n if (typeof this.setCustomData === 'function') {\n response = await this.setCustomData(page, this.#signal);\n } else {\n response = await this.getPages(page);\n }\n\n this.totalPages = response?.totalPages;\n this.currentPage = page;\n\n this.placementObj = this;\n\n // if there is a \"container\" attribute, find the element\n if (this.hasAttribute('placement')) this.placementObj = this.querySelector(this.placement);\n\n event.dispatchCustomEvent(this, 'wje-infinite-scroll:load', response);\n\n this.response = response;\n this.#loadedItems = this.objectName ? response[this.objectName] : response;\n const notDrawnItems = this.#loadedItems.filter(\n (item) => !this.#drawnItems.some(this.compareFunction.bind(this, item))\n );\n this.customForeach(notDrawnItems);\n this.#drawnItems.push(...notDrawnItems);\n\n this.isLoading.push(page);\n } else {\n event.dispatchCustomEvent(this, 'wje-infinite-scroll:complete');\n this.endingEl.classList.add('show');\n }\n } catch (error) {\n console.log(error);\n } finally {\n this.hideLoader();\n }\n }\n\n compareFunction = (i, item) => i.id === item.id;\n\n /**\n * Converts a data item into an HTML element based on a template.\n * This function takes a data item, interpolates it into a predefined template,\n * parses the resulting HTML string, and returns the first child element of the parsed HTML content.\n * @param {object} item The data object to interpolate into the HTML template.\n * @returns {Element} The first child element generated from the interpolated HTML string.\n */\n dataToHtml = (item) => {\n let interpolateItem = this.interpolate(this.infiniteScrollTemplate, item);\n let doc = this.parser.parseFromString(interpolateItem, 'text/html');\n let element = doc.activeElement.firstElementChild;\n\n return element;\n };\n\n /**\n * A custom implementation of the forEach method designed to iterate over an array of data,\n * transform each item into an HTML element, and append the element to a specified placement object.\n * Additionally, it adds an event listener to each generated element for handling click events.\n * @param {Array} data An array of items to process. Each item is transformed into an HTML element\n * and appended to the placement object specified in the context of `this`.\n */\n customForeach = (data) => {\n data.forEach((item) => {\n let element = this.dataToHtml(item);\n\n let symbol = Symbol(\"infinite-scroll-item\");\n element[symbol] = item;\n item[symbol] = element;\n\n event.addListener(element, 'click', 'wje-infinite-scroll:click-item', null);\n\n this.placementObj.insertAdjacentElement('beforeend', element);\n });\n };\n\n /**\n * Interpolates a string template with values from the provided parameters object.\n * The template contains placeholders in the format `{{key}}` or `{{key.subkey}}`,\n * which are replaced with the corresponding values from the `params` object.\n * Placeholders support dot notation for accessing nested properties within the `params` object.\n * @param {string} template The string template containing placeholders to be replaced.\n * @param {object} params The object containing key-value pairs used for substitution in the template.\n * @returns {string} A string with all placeholders replaced by their respective values from the `params` object.\n */\n interpolate = (template, params) => {\n let keys = template.match(/\\{{.*?\\}}/g);\n\n if (keys) {\n for (let key of keys) {\n let cleanKey = key.replace('{{', '').replace('}}', '');\n let val = '';\n cleanKey.split('.').forEach((k) => {\n val = val === '' ? params[k] : val[k];\n });\n\n template = template.replace(key, val);\n }\n }\n return template;\n };\n\n addItem(item, place = 'beforeend') {\n let element = this.dataToHtml(item);\n\n let symbol = Symbol(\"infinite-scroll-item\");\n element[symbol] = item;\n item[symbol] = element;\n\n this.placementObj.insertAdjacentElement(place, element);\n\n this.#drawnItems.push(item);\n\n // if drawnItems are more than page * size then add the page to isLoading\n if (this.#drawnItems.length > this.size * this.currentPage) {\n this.totalPages += 1;\n }\n }\n\n removeItem(item) {\n let drawnItem = this.#drawnItems.find(this.compareFunction.bind(this, item));\n if (!drawnItem) {\n console.error('Item not found');\n return;\n }\n let symbol = Object.getOwnPropertySymbols(drawnItem).at(0);\n let element = drawnItem[symbol];\n if (!element) {\n console.error('Element not found');\n return;\n }\n\n element?.remove();\n\n this.#drawnItems = this.#drawnItems.filter((i) => i !== item);\n // if drawnItems are less than page * size then remove the page from isLoading\n if (this.#drawnItems.length < this.size * this.currentPage) {\n this.isLoading = this.isLoading.filter((i) => i !== this.currentPage);\n this.currentPage--;\n }\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAkBe,MAAM,uBAAuB,UAAU;AAAA;AAAA;AAAA;AAAA,EAWlD,cAAc;AACV,UAAO;AAXX;AACA;AACA;AACA;AACA;AACA;AACA;AA8DA,qCAAY;AAyHZ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uCAAc,MAAM;AAChB,WAAK,iBAAiB,UAAU,KAAK,QAAQ;AAAA,IAChD;AASD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yCAAgB,MAAM;AAClB,WAAK,oBAAoB,UAAU,KAAK,QAAQ;AAAA,IACnD;AAkBD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oCAAW,CAAC,MAAM;AACd,YAAM,EAAE,WAAW,cAAc,aAAc,IAAG,EAAE;AAEpD,UACI,YAAY,gBAAgB,eAAe,OAC3C,KAAK,eAAe,KAAK,cACzB,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,KAAK,aAAa;AACxD,WAAK,YAAY,KAAK,UAAU,OAAO,CAAC,MAAM,MAAM,KAAK,WAAW;AACpE,WAAK;AAAA,IACjB;AAAA,EACA;AACA;AA5aI;AACA;AACA;AACA;AACA;AACA;AACA;"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
-
import WJElement from "./wje-element.js";
|
|
5
|
-
const styles = "/*\n[ WJ List ]\n*/\n:host {\n margin: 0;\n padding: 0;\n display: block;\n contain: content;\n list-style-type: none;\n}\n\n:host(.wje-inset) {\n background: var(--wje-list-background);\n transform: translateZ(0);\n overflow: hidden;\n padding: var(--wje-list-inset-padding);\n border-radius: var(--wje-list-border-radius);\n}\n\n:host(.wje-lines-none) ::slotted(wje-item) {\n --wje-border-width: 0 !important;\n --wje-item-border-width: 0!important;\n}";
|
|
6
|
-
class List extends WJElement {
|
|
7
|
-
/**
|
|
8
|
-
* Creates an instance of List.
|
|
9
|
-
* @class
|
|
10
|
-
*/
|
|
11
|
-
constructor() {
|
|
12
|
-
super();
|
|
13
|
-
__publicField(this, "className", "List");
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Returns the CSS styles for the component.
|
|
17
|
-
* @static
|
|
18
|
-
* @returns {CSSStyleSheet}
|
|
19
|
-
*/
|
|
20
|
-
static get cssStyleSheet() {
|
|
21
|
-
return styles;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Sets up the attributes for the component.
|
|
25
|
-
*/
|
|
26
|
-
setupAttributes() {
|
|
27
|
-
this.isShadowRoot = "open";
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Returns the list of attributes to observe for changes.
|
|
31
|
-
* @returns {DocumentFragment}
|
|
32
|
-
*/
|
|
33
|
-
draw() {
|
|
34
|
-
let fragment = document.createDocumentFragment();
|
|
35
|
-
let element = document.createElement("slot");
|
|
36
|
-
fragment.appendChild(element);
|
|
37
|
-
return fragment;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Called after the component has been drawn.
|
|
41
|
-
*/
|
|
42
|
-
afterDraw() {
|
|
43
|
-
this.classList.toggle("wje-lines-" + this.lines, this.hasAttribute("lines"));
|
|
44
|
-
this.classList.toggle("wje-inset", this.hasAttribute("inset"));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
export {
|
|
48
|
-
List as L
|
|
49
|
-
};
|
|
50
|
-
//# sourceMappingURL=list.element-D4-wlFN_.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"list.element-D4-wlFN_.js","sources":["../packages/wje-list/list.element.js"],"sourcesContent":["import { default as WJElement } from '../wje-element/element.js';\nimport styles from './styles/styles.scss?inline';\n\n/**\n * `List` is a custom web component that represents a list.\n * It extends from `WJElement`.\n * @summary This element represents a list.\n * @documentation https://elements.webjet.sk/components/list\n * @status stable\n * @augments {WJElement}\n * @slot - The default slot for the list.\n * @cssproperty [--wje-list-inset-padding=1rem] - The padding of the list when it is inset.\n * @cssproperty [--wje-list-border-radius=8px] - The border radius of the list. Accepts any valid CSS length.\n * @cssproperty [--wje-list-background=var(--wje-background)] - The background of the list. Accepts any valid CSS color value.\n * @tag wje-list\n */\nexport default class List extends WJElement {\n /**\n * Creates an instance of List.\n * @class\n */\n constructor() {\n super();\n }\n\n className = 'List';\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 * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Returns the list of attributes to observe for changes.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let element = document.createElement('slot');\n fragment.appendChild(element);\n\n return fragment;\n }\n\n /**\n * Called after the component has been drawn.\n */\n afterDraw() {\n this.classList.toggle('wje-lines-' + this.lines, this.hasAttribute('lines'));\n this.classList.toggle('wje-inset', this.hasAttribute('inset'));\n }\n}\n"],"names":[],"mappings":";;;;;AAgBe,MAAM,aAAa,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAKxC,cAAc;AACV,UAAO;AAGX,qCAAY;AAAA,EAFhB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASI,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;AAEhD,QAAI,UAAU,SAAS,cAAc,MAAM;AAC3C,aAAS,YAAY,OAAO;AAE5B,WAAO;AAAA,EACf;AAAA;AAAA;AAAA;AAAA,EAKI,YAAY;AACR,SAAK,UAAU,OAAO,eAAe,KAAK,OAAO,KAAK,aAAa,OAAO,CAAC;AAC3E,SAAK,UAAU,OAAO,aAAa,KAAK,aAAa,OAAO,CAAC;AAAA,EACrE;AACA;"}
|