@schukai/monster 3.55.6 → 3.56.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/package.json +2 -2
  3. package/source/components/datatable/change-button.mjs +265 -0
  4. package/source/components/datatable/dataset.mjs +76 -5
  5. package/source/components/datatable/datasource/dom.mjs +1 -1
  6. package/source/components/datatable/datasource/rest.mjs +401 -345
  7. package/source/components/datatable/datasource.mjs +8 -0
  8. package/source/components/datatable/datatable.mjs +600 -600
  9. package/source/components/datatable/filter/range.mjs +1 -3
  10. package/source/components/datatable/filter/select.mjs +1 -1
  11. package/source/components/datatable/filter.mjs +1 -3
  12. package/source/components/datatable/save-button.mjs +301 -0
  13. package/source/components/datatable/status.mjs +6 -2
  14. package/source/components/datatable/style/change-button.pcss +19 -0
  15. package/source/components/datatable/style/save-button.pcss +44 -0
  16. package/source/components/datatable/stylesheet/change-button.mjs +27 -0
  17. package/source/components/datatable/stylesheet/save-button.mjs +27 -0
  18. package/source/components/datatable/util.mjs +3 -1
  19. package/source/components/form/button-bar.mjs +3 -3
  20. package/source/components/form/button.mjs +1 -2
  21. package/source/components/form/form.mjs +1 -1
  22. package/source/components/form/message-state-button.mjs +1 -1
  23. package/source/components/form/select.mjs +1744 -1777
  24. package/source/components/form/state-button.mjs +1 -1
  25. package/source/components/form/tabs.mjs +3 -3
  26. package/source/components/form/tree-select.mjs +6 -2
  27. package/source/components/host/overlay.mjs +4 -1
  28. package/source/components/tree-menu/tree-menu.mjs +0 -1
  29. package/source/data/datasource/server/restapi.mjs +2 -3
  30. package/source/data/datasource/server.mjs +1 -1
  31. package/source/data/extend.mjs +55 -55
  32. package/source/data/pathfinder.mjs +6 -4
  33. package/source/dom/constants.mjs +9 -0
  34. package/source/dom/customelement.mjs +25 -7
  35. package/source/dom/updater.mjs +34 -3
  36. package/source/i18n/translations.mjs +1 -1
  37. package/source/monster.mjs +0 -1
  38. package/source/types/noderecursiveiterator.mjs +2 -3
  39. package/source/types/version.mjs +1 -1
  40. package/test/cases/monster.mjs +1 -1
@@ -3,25 +3,25 @@
3
3
  * SPDX-License-Identifier: AGPL-3.0
4
4
  */
5
5
 
6
- import {addAttributeToken} from "../../../dom/attributes.mjs";
7
- import {ATTRIBUTE_ERRORMESSAGE} from "../../../dom/constants.mjs";
8
- import {Datasource, dataSourceSymbol} from "../datasource.mjs";
9
- import {DatasourceStyleSheet} from "../stylesheet/datasource.mjs";
10
- import {instanceSymbol} from "../../../constants.mjs";
6
+ import { addAttributeToken } from "../../../dom/attributes.mjs";
7
+ import { ATTRIBUTE_ERRORMESSAGE } from "../../../dom/constants.mjs";
8
+ import { Datasource, dataSourceSymbol } from "../datasource.mjs";
9
+ import { DatasourceStyleSheet } from "../stylesheet/datasource.mjs";
10
+ import { instanceSymbol } from "../../../constants.mjs";
11
11
  import {
12
- assembleMethodSymbol,
13
- registerCustomElement,
12
+ assembleMethodSymbol,
13
+ registerCustomElement,
14
14
  } from "../../../dom/customelement.mjs";
15
- import {RestAPI} from "../../../data/datasource/server/restapi.mjs";
16
- import {Formatter} from "../../../text/formatter.mjs";
17
- import {clone} from "../../../util/clone.mjs";
18
- import {validateBoolean} from "../../../types/validate.mjs";
19
- import {findElementWithIdUpwards} from "../../../dom/util.mjs";
20
- import {Observer} from "../../../types/observer.mjs";
21
- import {Pathfinder} from "../../../data/pathfinder.mjs";
22
- import {fireCustomEvent} from "../../../dom/events.mjs";
15
+ import { RestAPI } from "../../../data/datasource/server/restapi.mjs";
16
+ import { Formatter } from "../../../text/formatter.mjs";
17
+ import { clone } from "../../../util/clone.mjs";
18
+ import { validateBoolean } from "../../../types/validate.mjs";
19
+ import { findElementWithIdUpwards } from "../../../dom/util.mjs";
20
+ import { Observer } from "../../../types/observer.mjs";
21
+ import { Pathfinder } from "../../../data/pathfinder.mjs";
22
+ import { fireCustomEvent } from "../../../dom/events.mjs";
23
23
 
24
- export {Rest};
24
+ export { Rest };
25
25
 
26
26
  /**
27
27
  * @private
@@ -35,7 +35,7 @@ const intersectionObserverHandlerSymbol = Symbol("intersectionObserverHandler");
35
35
  * @type {symbol}
36
36
  */
37
37
  const rawDataSymbol = Symbol.for(
38
- "@schukai/monster/data/datasource/server/restapi/rawdata",
38
+ "@schukai/monster/data/datasource/server/restapi/rawdata",
39
39
  );
40
40
 
41
41
  /**
@@ -43,7 +43,7 @@ const rawDataSymbol = Symbol.for(
43
43
  * @type {symbol}
44
44
  */
45
45
  const intersectionObserverObserverSymbol = Symbol(
46
- "intersectionObserverObserver",
46
+ "intersectionObserverObserver",
47
47
  );
48
48
 
49
49
  /**
@@ -72,23 +72,23 @@ const filterObserverSymbol = Symbol("filterObserver");
72
72
  * @summary A rest api datasource
73
73
  */
74
74
  class Rest extends Datasource {
75
- /**
76
- * the constructor of the class
77
- */
78
- constructor() {
79
- super();
80
- this[dataSourceSymbol] = new RestAPI();
81
- }
82
-
83
- /**
84
- * This method is called by the `instanceof` operator.
85
- * @returns {symbol}
86
- */
87
- static get [instanceSymbol]() {
88
- return Symbol.for("@schukai/monster/components/datasource/rest@@instance");
89
- }
90
-
91
- /**
75
+ /**
76
+ * the constructor of the class
77
+ */
78
+ constructor() {
79
+ super();
80
+ this[dataSourceSymbol] = new RestAPI();
81
+ }
82
+
83
+ /**
84
+ * This method is called by the `instanceof` operator.
85
+ * @returns {symbol}
86
+ */
87
+ static get [instanceSymbol]() {
88
+ return Symbol.for("@schukai/monster/components/datasource/rest@@instance");
89
+ }
90
+
91
+ /**
92
92
  * To set the options via the html tag the attribute `data-monster-options` must be used.
93
93
  * @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
94
94
  *
@@ -119,346 +119,402 @@ class Rest extends Datasource {
119
119
  * @property {Object} write Write configuration
120
120
 
121
121
  */
122
- get defaults() {
123
- const restOptions = new RestAPI().defaults;
124
-
125
- restOptions.read.parameters = {
126
- filter: undefined,
127
- oderBy: undefined,
128
- page: "1",
129
- };
130
-
131
- return Object.assign({}, super.defaults, restOptions, {
132
- templates: {
133
- main: getTemplate(),
134
- },
135
-
136
- features: {
137
- autoInit: false,
138
- filter: false,
139
- },
140
-
141
- autoInit: {
142
- intersectionObserver: false,
143
- oneTime: true,
144
- },
145
-
146
- filter: {
147
- id: undefined,
148
- },
149
-
150
- datatable: {
151
- id: undefined,
152
- },
153
-
154
- response: {
155
- path: {
156
- message: "sys.message",
157
- code: "sys.code",
158
- }
159
- },
160
- });
161
- }
162
-
163
- /**
164
- *
165
- * @param {string} page
166
- * @param {string} query
167
- * @param {string} orderBy
168
- * @returns {Monster.Components.Datatable.Datasource.Rest}
169
- */
170
- setParameters({page, query, orderBy}) {
171
- const parameters = this.getOption("read.parameters");
172
- if (query !== undefined) {
173
- parameters.query = `${query}`;
174
- parameters.page = "1";
175
- }
176
-
177
- // after a query the page is set to 1, so if the page is not set, it is set to 1
178
- if (page !== undefined) parameters.page = `${page}`;
179
- if (orderBy !== undefined) parameters.order = `${orderBy}`;
180
- this.setOption("read.parameters", parameters);
181
- return this;
182
- }
183
-
184
- /**
185
- *
186
- * @return {Monster.Components.Form.Form}
187
- */
188
- [assembleMethodSymbol]() {
189
- super[assembleMethodSymbol]();
190
-
191
- initEventHandler.call(this);
192
- initAutoInit.call(this);
193
- }
194
-
195
- /**
196
- * @deprecated 2023-06-25
197
- * @returns {Promise<never>|*}
198
- */
199
- reload() {
200
- return this.fetch();
201
- }
202
-
203
- /**
204
- * Fetches the data from the rest api
205
- * @returns {Promise<never>|*}
206
- */
207
- fetch() {
208
- const opt = clone(this.getOption("read"));
209
- this[dataSourceSymbol].setOption("read", opt);
210
-
211
- let url = this.getOption("read.url");
212
- const formatter = new Formatter(this.getOption("read.parameters"));
213
-
214
- if (!url) {
215
- return Promise.reject(new Error("No url defined"));
216
- }
217
-
218
- url = formatter.format(url);
219
-
220
- this[dataSourceSymbol].setOption("read.url", url);
221
-
222
- return new Promise((resolve, reject) => {
223
- fireCustomEvent(this, "monster-datasource-fetch", {
224
- datasource: this,
225
- });
226
-
227
- setTimeout(() => {
228
- this[dataSourceSymbol]
229
- .read()
230
- .then((response) => {
231
- fireCustomEvent(this, "monster-datasource-fetched", {
232
- datasource: this,
233
- });
234
-
235
- resolve(response);
236
- })
237
- .catch((error) => {
238
- fireCustomEvent(this, "monster-datasource-error", {
239
- error: error,
240
- });
241
-
242
- addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, error.toString());
243
- reject(error);
244
- });
245
- }, 0);
246
- });
247
- }
248
-
249
- /**
250
- *
251
- * @return {CSSStyleSheet[]}
252
- */
253
- static getCSSStyleSheet() {
254
- return [DatasourceStyleSheet];
255
- }
256
-
257
- /**
258
- * @private
259
- * @return {string}
260
- */
261
- static getTag() {
262
- return "monster-datasource-rest";
263
- }
264
-
265
- /**
266
- * This method activates the intersection observer manually.
267
- * For this purpose, the option `autoInit.intersectionObserver` must be set to `false`.
268
- *
269
- * @returns {Monster.Components.Datatable.Datasource.Rest}
270
- */
271
- initIntersectionObserver() {
272
- initIntersectionObserver.call(this);
273
- return this;
274
- }
275
-
276
- /**
277
- * @private
278
- */
279
- connectedCallback() {
280
- super.connectedCallback();
281
-
282
- setTimeout(() => {
283
- if (this.getOption("features.filter", false) === true) {
284
- initFilter.call(this);
285
- }
286
- }, 0);
287
- }
288
-
289
- /**
290
- * @private
291
- */
292
- disconnectedCallback() {
293
- super.disconnectedCallback();
294
- removeFilter.call(this);
295
- }
122
+ get defaults() {
123
+ const restOptions = new RestAPI().defaults;
124
+
125
+ restOptions.read.parameters = {
126
+ filter: undefined,
127
+ oderBy: undefined,
128
+ page: "1",
129
+ };
130
+
131
+ return Object.assign({}, super.defaults, restOptions, {
132
+ templates: {
133
+ main: getTemplate(),
134
+ },
135
+
136
+ features: {
137
+ autoInit: false,
138
+ filter: false,
139
+ },
140
+
141
+ autoInit: {
142
+ intersectionObserver: false,
143
+ oneTime: true,
144
+ },
145
+
146
+ filter: {
147
+ id: undefined,
148
+ },
149
+
150
+ datatable: {
151
+ id: undefined,
152
+ },
153
+
154
+ response: {
155
+ path: {
156
+ message: "sys.message",
157
+ code: "sys.code",
158
+ },
159
+ },
160
+ });
161
+ }
162
+
163
+ /**
164
+ *
165
+ * @param {string} page
166
+ * @param {string} query
167
+ * @param {string} orderBy
168
+ * @returns {Monster.Components.Datatable.Datasource.Rest}
169
+ */
170
+ setParameters({ page, query, orderBy }) {
171
+ const parameters = this.getOption("read.parameters");
172
+ if (query !== undefined) {
173
+ parameters.query = `${query}`;
174
+ parameters.page = "1";
175
+ }
176
+
177
+ // after a query the page is set to 1, so if the page is not set, it is set to 1
178
+ if (page !== undefined) parameters.page = `${page}`;
179
+ if (orderBy !== undefined) parameters.order = `${orderBy}`;
180
+ this.setOption("read.parameters", parameters);
181
+ return this;
182
+ }
183
+
184
+ /**
185
+ *
186
+ * @return {Monster.Components.Form.Form}
187
+ */
188
+ [assembleMethodSymbol]() {
189
+ super[assembleMethodSymbol]();
190
+
191
+ initEventHandler.call(this);
192
+ initAutoInit.call(this);
193
+ }
194
+
195
+ /**
196
+ * @deprecated 2023-06-25
197
+ * @returns {Promise<never>|*}
198
+ */
199
+ reload() {
200
+ return this.fetch();
201
+ }
202
+
203
+ /**
204
+ * Fetches the data from the rest api
205
+ * @returns {Promise<never>|*}
206
+ */
207
+ fetch() {
208
+ const opt = clone(this.getOption("read"));
209
+ this[dataSourceSymbol].setOption("read", opt);
210
+
211
+ let url = this.getOption("read.url");
212
+ const formatter = new Formatter(this.getOption("read.parameters"));
213
+
214
+ if (!url) {
215
+ return Promise.reject(new Error("No url defined"));
216
+ }
217
+
218
+ url = formatter.format(url);
219
+
220
+ this[dataSourceSymbol].setOption("read.url", url);
221
+
222
+ return new Promise((resolve, reject) => {
223
+ fireCustomEvent(this, "monster-datasource-fetch", {
224
+ datasource: this,
225
+ });
226
+
227
+ setTimeout(() => {
228
+ this[dataSourceSymbol]
229
+ .read()
230
+ .then((response) => {
231
+ fireCustomEvent(this, "monster-datasource-fetched", {
232
+ datasource: this,
233
+ });
234
+
235
+ resolve(response);
236
+ })
237
+ .catch((error) => {
238
+ fireCustomEvent(this, "monster-datasource-error", {
239
+ error: error,
240
+ });
241
+
242
+ addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, error.toString());
243
+ reject(error);
244
+ });
245
+ }, 0);
246
+ });
247
+ }
248
+
249
+ /**
250
+ *
251
+ * @return {CSSStyleSheet[]}
252
+ */
253
+ static getCSSStyleSheet() {
254
+ return [DatasourceStyleSheet];
255
+ }
256
+
257
+ /**
258
+ * @private
259
+ * @return {string}
260
+ */
261
+ static getTag() {
262
+ return "monster-datasource-rest";
263
+ }
264
+
265
+ /**
266
+ * This method activates the intersection observer manually.
267
+ * For this purpose, the option `autoInit.intersectionObserver` must be set to `false`.
268
+ *
269
+ * @returns {Monster.Components.Datatable.Datasource.Rest}
270
+ */
271
+ initIntersectionObserver() {
272
+ initIntersectionObserver.call(this);
273
+ return this;
274
+ }
275
+
276
+ /**
277
+ * @private
278
+ */
279
+ connectedCallback() {
280
+ super.connectedCallback();
281
+
282
+ setTimeout(() => {
283
+ if (this.getOption("features.filter", false) === true) {
284
+ initFilter.call(this);
285
+ }
286
+ }, 0);
287
+ }
288
+
289
+ /**
290
+ * @private
291
+ */
292
+ disconnectedCallback() {
293
+ super.disconnectedCallback();
294
+ removeFilter.call(this);
295
+ }
296
+
297
+ read() {
298
+ return this.fetch();
299
+ }
300
+
301
+ /**
302
+ * Fetches the data from the rest api
303
+ * @returns {Promise<never>|*}
304
+ */
305
+ write() {
306
+ const opt = clone(this.getOption("write"));
307
+ this[dataSourceSymbol].setOption("write", opt);
308
+
309
+ let url = this.getOption("write.url");
310
+ const formatter = new Formatter(this.getOption("write.parameters"));
311
+
312
+ if (!url) {
313
+ return Promise.reject(new Error("No url defined"));
314
+ }
315
+
316
+ url = formatter.format(url);
317
+
318
+ this[dataSourceSymbol].setOption("write.url", url);
319
+
320
+ return new Promise((resolve, reject) => {
321
+ fireCustomEvent(this, "monster-datasource-fetch", {
322
+ datasource: this,
323
+ });
324
+
325
+ setTimeout(() => {
326
+ this[dataSourceSymbol]
327
+ .write()
328
+ .then((response) => {
329
+ fireCustomEvent(this, "monster-datasource-fetched", {
330
+ datasource: this,
331
+ });
332
+
333
+ resolve(response);
334
+ })
335
+ .catch((error) => {
336
+ fireCustomEvent(this, "monster-datasource-error", {
337
+ error: error,
338
+ });
339
+
340
+ addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, error.toString());
341
+ reject(error);
342
+ });
343
+ }, 0);
344
+ });
345
+ }
296
346
  }
297
347
 
298
348
  /**
299
349
  * @private
300
350
  */
301
351
  function removeFilter() {
302
- const filterID = this.getOption("filter.id", undefined);
303
- if (!filterID) return;
352
+ const filterID = this.getOption("filter.id", undefined);
353
+ if (!filterID) return;
304
354
 
305
- const filterControl = findElementWithIdUpwards(this, filterID);
355
+ const filterControl = findElementWithIdUpwards(this, filterID);
306
356
 
307
- if (filterControl && this[filterObserverSymbol]) {
308
- filterControl?.detachObserver(this[filterObserverSymbol]);
309
- }
357
+ if (filterControl && this[filterObserverSymbol]) {
358
+ filterControl?.detachObserver(this[filterObserverSymbol]);
359
+ }
310
360
  }
311
361
 
312
362
  /**
313
363
  * @private
314
364
  */
315
365
  function initFilter() {
316
- const filterID = this.getOption("filter.id", undefined);
317
-
318
- if (!filterID)
319
- throw new Error("filter feature is enabled but no filter id is defined");
320
-
321
- const filterControl = findElementWithIdUpwards(this, filterID);
322
- if (!filterControl)
323
- throw new Error(
324
- "filter feature is enabled but no filter control with id " +
325
- filterID +
326
- " is found",
327
- );
328
-
329
- this[filterObserverSymbol] = new Observer(() => {
330
- const query = filterControl.getOption("query", undefined);
331
- this.setParameters({query: query});
332
- this.fetch()
333
- .then((response) => {
334
- if (!(response instanceof Response)) {
335
- throw new Error("Response is not an instance of Response");
336
- }
337
-
338
- if (response?.ok === true) {
339
- this.dispatchEvent(new CustomEvent("reload", {bubbles: true}));
340
- filterControl?.showSuccess();
341
- }
342
-
343
- if (response.bodyUsed === true) {
344
- return handleIntersectionObserver.call(this, response[rawDataSymbol], response, filterControl);
345
- }
346
-
347
- response
348
- .text()
349
- .then((jsonAsText) => {
350
- let json;
351
- try {
352
- json = JSON.parse(jsonAsText);
353
- } catch (e) {
354
- let message = e instanceof Error ? e.message : `${e}`;
355
- filterControl?.showFailureMessage(message);
356
- return Promise.reject(e);
357
- }
358
-
359
- return handleIntersectionObserver.call(this,json, response, filterControl);
360
-
361
-
362
- })
363
- .catch((e) => {
364
- filterControl?.showFailureMessage(e.message);
365
- });
366
- })
367
- .catch((e) => {
368
- this.dispatchEvent(
369
- new CustomEvent("error", {bubbles: true, detail: e}),
370
- );
371
-
372
- if (!(e instanceof Error)) {
373
- e = new Error(e);
374
- }
375
-
376
- filterControl?.showFailureMessage(e.message);
377
- return Promise.reject(e);
378
- });
379
- });
380
-
381
- filterControl.attachObserver(this[filterObserverSymbol]);
366
+ const filterID = this.getOption("filter.id", undefined);
367
+
368
+ if (!filterID)
369
+ throw new Error("filter feature is enabled but no filter id is defined");
370
+
371
+ const filterControl = findElementWithIdUpwards(this, filterID);
372
+ if (!filterControl)
373
+ throw new Error(
374
+ "filter feature is enabled but no filter control with id " +
375
+ filterID +
376
+ " is found",
377
+ );
378
+
379
+ this[filterObserverSymbol] = new Observer(() => {
380
+ const query = filterControl.getOption("query", undefined);
381
+ this.setParameters({ query: query });
382
+ this.fetch()
383
+ .then((response) => {
384
+ if (!(response instanceof Response)) {
385
+ throw new Error("Response is not an instance of Response");
386
+ }
387
+
388
+ if (response?.ok === true) {
389
+ this.dispatchEvent(new CustomEvent("reload", { bubbles: true }));
390
+ filterControl?.showSuccess();
391
+ }
392
+
393
+ if (response.bodyUsed === true) {
394
+ return handleIntersectionObserver.call(
395
+ this,
396
+ response[rawDataSymbol],
397
+ response,
398
+ filterControl,
399
+ );
400
+ }
401
+
402
+ response
403
+ .text()
404
+ .then((jsonAsText) => {
405
+ let json;
406
+ try {
407
+ json = JSON.parse(jsonAsText);
408
+ } catch (e) {
409
+ const message = e instanceof Error ? e.message : `${e}`;
410
+ filterControl?.showFailureMessage(message);
411
+ return Promise.reject(e);
412
+ }
413
+
414
+ return handleIntersectionObserver.call(
415
+ this,
416
+ json,
417
+ response,
418
+ filterControl,
419
+ );
420
+ })
421
+ .catch((e) => {
422
+ filterControl?.showFailureMessage(e.message);
423
+ });
424
+ })
425
+ .catch((e) => {
426
+ this.dispatchEvent(
427
+ new CustomEvent("error", { bubbles: true, detail: e }),
428
+ );
429
+
430
+ if (!(e instanceof Error)) {
431
+ e = new Error(e);
432
+ }
433
+
434
+ filterControl?.showFailureMessage(e.message);
435
+ return Promise.reject(e);
436
+ });
437
+ });
438
+
439
+ filterControl.attachObserver(this[filterObserverSymbol]);
382
440
  }
383
441
 
384
442
  function handleIntersectionObserver(json, response, filterControl) {
385
-
386
- const path = new Pathfinder(json);
387
-
388
- const codePath = this.getOption("response.path.code");
389
-
390
- if (path.exists(codePath)) {
391
- const code = `${path.getVia(codePath)}`;
392
- if (code && code === "200") {
393
- filterControl?.showSuccess();
394
- return Promise.resolve(response);
395
- }
396
-
397
- const messagePath = this.getOption("response.path.message");
398
- if (path.exists(messagePath)) {
399
- const message = path.getVia(messagePath);
400
- filterControl?.showFailureMessage(message);
401
- return Promise.reject(new Error(message));
402
- }
403
-
404
- return Promise.reject(new Error("Response code is not 200"));
405
- }
443
+ const path = new Pathfinder(json);
444
+
445
+ const codePath = this.getOption("response.path.code");
446
+
447
+ if (path.exists(codePath)) {
448
+ const code = `${path.getVia(codePath)}`;
449
+ if (code && code === "200") {
450
+ filterControl?.showSuccess();
451
+ return Promise.resolve(response);
452
+ }
453
+
454
+ const messagePath = this.getOption("response.path.message");
455
+ if (path.exists(messagePath)) {
456
+ const message = path.getVia(messagePath);
457
+ filterControl?.showFailureMessage(message);
458
+ return Promise.reject(new Error(message));
459
+ }
460
+
461
+ return Promise.reject(new Error("Response code is not 200"));
462
+ }
406
463
  }
407
464
 
408
465
  /**
409
466
  * @private
410
467
  */
411
468
  function initAutoInit() {
412
- const autoInit = this.getOption("features.autoInit");
413
- validateBoolean(autoInit);
469
+ const autoInit = this.getOption("features.autoInit");
470
+ validateBoolean(autoInit);
414
471
 
415
- if (autoInit !== true) return;
472
+ if (autoInit !== true) return;
416
473
 
417
- if (this.getOption("autoInit.intersectionObserver") === true) {
418
- initIntersectionObserver.call(this);
419
- return;
420
- }
474
+ if (this.getOption("autoInit.intersectionObserver") === true) {
475
+ initIntersectionObserver.call(this);
476
+ return;
477
+ }
421
478
 
422
- setTimeout(() => {
423
- this.fetch().catch(() => {
424
- });
425
- }, 0);
479
+ setTimeout(() => {
480
+ this.fetch().catch(() => {});
481
+ }, 0);
426
482
  }
427
483
 
428
484
  function initEventHandler() {
429
- this[intersectionObserverHandlerSymbol] = (entries) => {
430
- entries.forEach((entry) => {
431
- if (entry.isIntersecting) {
432
- if (entry.intersectionRatio > 0) {
433
- this.fetch();
434
- }
435
-
436
- // only load once
437
- if (
438
- this.getOption("autoInit.oneTime") === true &&
439
- this[intersectionObserverObserverSymbol] !== undefined
440
- ) {
441
- this[intersectionObserverObserverSymbol].unobserve(this);
442
- }
443
- }
444
- });
445
- };
485
+ this[intersectionObserverHandlerSymbol] = (entries) => {
486
+ entries.forEach((entry) => {
487
+ if (entry.isIntersecting) {
488
+ if (entry.intersectionRatio > 0) {
489
+ this.fetch();
490
+ }
491
+
492
+ // only load once
493
+ if (
494
+ this.getOption("autoInit.oneTime") === true &&
495
+ this[intersectionObserverObserverSymbol] !== undefined
496
+ ) {
497
+ this[intersectionObserverObserverSymbol].unobserve(this);
498
+ }
499
+ }
500
+ });
501
+ };
446
502
  }
447
503
 
448
504
  function initIntersectionObserver() {
449
- this.classList.add("intersection-observer");
450
-
451
- const options = {
452
- root: null,
453
- rootMargin: "0px",
454
- threshold: 0.1,
455
- };
456
-
457
- this[intersectionObserverObserverSymbol] = new IntersectionObserver(
458
- this[intersectionObserverHandlerSymbol],
459
- options,
460
- );
461
- this[intersectionObserverObserverSymbol].observe(this);
505
+ this.classList.add("intersection-observer");
506
+
507
+ const options = {
508
+ root: null,
509
+ rootMargin: "0px",
510
+ threshold: 0.1,
511
+ };
512
+
513
+ this[intersectionObserverObserverSymbol] = new IntersectionObserver(
514
+ this[intersectionObserverHandlerSymbol],
515
+ options,
516
+ );
517
+ this[intersectionObserverObserverSymbol].observe(this);
462
518
  }
463
519
 
464
520
  /**
@@ -466,8 +522,8 @@ function initIntersectionObserver() {
466
522
  * @return {string}
467
523
  */
468
524
  function getTemplate() {
469
- // language=HTML
470
- return `
525
+ // language=HTML
526
+ return `
471
527
  <slot></slot>`;
472
528
  }
473
529