@schukai/monster 3.55.6 → 3.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/package.json +2 -2
- package/source/components/datatable/change-button.mjs +265 -0
- package/source/components/datatable/dataset.mjs +76 -5
- package/source/components/datatable/datasource/dom.mjs +1 -1
- package/source/components/datatable/datasource/rest.mjs +401 -345
- package/source/components/datatable/datasource.mjs +8 -0
- package/source/components/datatable/datatable.mjs +600 -600
- package/source/components/datatable/filter/range.mjs +1 -3
- package/source/components/datatable/filter/select.mjs +1 -1
- package/source/components/datatable/filter.mjs +1 -3
- package/source/components/datatable/save-button.mjs +301 -0
- package/source/components/datatable/status.mjs +6 -2
- package/source/components/datatable/style/change-button.pcss +19 -0
- package/source/components/datatable/style/save-button.pcss +44 -0
- package/source/components/datatable/stylesheet/change-button.mjs +27 -0
- package/source/components/datatable/stylesheet/save-button.mjs +27 -0
- package/source/components/datatable/util.mjs +3 -1
- package/source/components/form/button-bar.mjs +3 -3
- package/source/components/form/button.mjs +1 -2
- package/source/components/form/form.mjs +1 -1
- package/source/components/form/message-state-button.mjs +1 -1
- package/source/components/form/select.mjs +1744 -1777
- package/source/components/form/state-button.mjs +1 -1
- package/source/components/form/tabs.mjs +3 -3
- package/source/components/form/tree-select.mjs +6 -2
- package/source/components/host/overlay.mjs +4 -1
- package/source/components/tree-menu/tree-menu.mjs +0 -1
- package/source/data/datasource/server/restapi.mjs +2 -3
- package/source/data/datasource/server.mjs +1 -1
- package/source/data/extend.mjs +55 -55
- package/source/data/pathfinder.mjs +6 -4
- package/source/dom/constants.mjs +9 -0
- package/source/dom/customelement.mjs +25 -7
- package/source/dom/updater.mjs +34 -3
- package/source/i18n/translations.mjs +1 -1
- package/source/monster.mjs +0 -1
- package/source/types/noderecursiveiterator.mjs +2 -3
- package/source/types/version.mjs +1 -1
- 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
|
-
|
|
13
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
-
|
|
303
|
-
|
|
352
|
+
const filterID = this.getOption("filter.id", undefined);
|
|
353
|
+
if (!filterID) return;
|
|
304
354
|
|
|
305
|
-
|
|
355
|
+
const filterControl = findElementWithIdUpwards(this, filterID);
|
|
306
356
|
|
|
307
|
-
|
|
308
|
-
|
|
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
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
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
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
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
|
-
|
|
413
|
-
|
|
469
|
+
const autoInit = this.getOption("features.autoInit");
|
|
470
|
+
validateBoolean(autoInit);
|
|
414
471
|
|
|
415
|
-
|
|
472
|
+
if (autoInit !== true) return;
|
|
416
473
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
474
|
+
if (this.getOption("autoInit.intersectionObserver") === true) {
|
|
475
|
+
initIntersectionObserver.call(this);
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
421
478
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
}, 0);
|
|
479
|
+
setTimeout(() => {
|
|
480
|
+
this.fetch().catch(() => {});
|
|
481
|
+
}, 0);
|
|
426
482
|
}
|
|
427
483
|
|
|
428
484
|
function initEventHandler() {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
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
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
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
|
-
|
|
470
|
-
|
|
525
|
+
// language=HTML
|
|
526
|
+
return `
|
|
471
527
|
<slot></slot>`;
|
|
472
528
|
}
|
|
473
529
|
|