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