@schukai/monster 3.86.4 → 3.87.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 +16 -0
- package/package.json +1 -1
- package/source/components/datatable/datatable.mjs +912 -778
- package/source/components/datatable/filter.mjs +978 -949
- package/source/components/datatable/pagination.mjs +6 -10
- package/source/components/datatable/style/datatable.pcss +20 -0
- package/source/components/datatable/style/filter.pcss +23 -24
- package/source/components/datatable/stylesheet/column-bar.mjs +6 -13
- package/source/components/datatable/stylesheet/datatable.mjs +7 -14
- package/source/components/datatable/stylesheet/filter.mjs +7 -14
- package/source/components/form/action-button.mjs +2 -2
- package/source/components/form/api-button.mjs +7 -38
- package/source/components/form/style/action-button.pcss +2 -1
- package/source/components/form/style/button.pcss +1 -1
- package/source/components/form/style/confirm-button.pcss +1 -1
- package/source/components/form/style/popper-button.pcss +6 -5
- package/source/components/form/style/state-button.pcss +1 -1
- package/source/components/form/stylesheet/action-button.mjs +7 -14
- package/source/components/form/stylesheet/button.mjs +7 -14
- package/source/components/form/stylesheet/confirm-button.mjs +7 -14
- package/source/components/form/stylesheet/popper-button.mjs +7 -14
- package/source/components/form/stylesheet/state-button.mjs +7 -14
|
@@ -12,75 +12,75 @@
|
|
|
12
12
|
* SPDX-License-Identifier: AGPL-3.0
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import {Datasource} from "./datasource.mjs";
|
|
16
16
|
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
assembleMethodSymbol,
|
|
18
|
+
CustomElement,
|
|
19
|
+
registerCustomElement,
|
|
20
|
+
getSlottedElements,
|
|
21
21
|
} from "../../dom/customelement.mjs";
|
|
22
22
|
import {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
findTargetElementFromEvent,
|
|
24
|
+
fireCustomEvent,
|
|
25
25
|
} from "../../dom/events.mjs";
|
|
26
|
-
import {
|
|
26
|
+
import {clone} from "../../util/clone.mjs";
|
|
27
27
|
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
isString,
|
|
29
|
+
isFunction,
|
|
30
|
+
isInstance,
|
|
31
|
+
isObject,
|
|
32
|
+
isArray,
|
|
33
33
|
} from "../../types/is.mjs";
|
|
34
34
|
import {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
validateArray,
|
|
36
|
+
validateInteger,
|
|
37
|
+
validateObject,
|
|
38
38
|
} from "../../types/validate.mjs";
|
|
39
|
-
import {
|
|
39
|
+
import {Observer} from "../../types/observer.mjs";
|
|
40
40
|
import {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
41
|
+
ATTRIBUTE_DATATABLE_HEAD,
|
|
42
|
+
ATTRIBUTE_DATATABLE_GRID_TEMPLATE,
|
|
43
|
+
ATTRIBUTE_DATASOURCE_SELECTOR,
|
|
44
|
+
ATTRIBUTE_DATATABLE_ALIGN,
|
|
45
|
+
ATTRIBUTE_DATATABLE_SORTABLE,
|
|
46
|
+
ATTRIBUTE_DATATABLE_MODE,
|
|
47
|
+
ATTRIBUTE_DATATABLE_INDEX,
|
|
48
|
+
ATTRIBUTE_DATATABLE_MODE_HIDDEN,
|
|
49
|
+
ATTRIBUTE_DATATABLE_MODE_VISIBLE,
|
|
50
|
+
ATTRIBUTE_DATATABLE_RESPONSIVE_BREAKPOINT,
|
|
51
|
+
ATTRIBUTE_DATATABLE_MODE_FIXED,
|
|
52
52
|
} from "./constants.mjs";
|
|
53
|
-
import {
|
|
53
|
+
import {instanceSymbol} from "../../constants.mjs";
|
|
54
54
|
import {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
Header,
|
|
56
|
+
createOrderStatement,
|
|
57
|
+
DIRECTION_ASC,
|
|
58
|
+
DIRECTION_DESC,
|
|
59
|
+
DIRECTION_NONE,
|
|
60
60
|
} from "./datatable/header.mjs";
|
|
61
|
-
import {
|
|
61
|
+
import {DatatableStyleSheet} from "./stylesheet/datatable.mjs";
|
|
62
62
|
import {
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
handleDataSourceChanges,
|
|
64
|
+
datasourceLinkedElementSymbol,
|
|
65
65
|
} from "./util.mjs";
|
|
66
66
|
import "./columnbar.mjs";
|
|
67
67
|
import "./filter-button.mjs";
|
|
68
68
|
import {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
findElementWithSelectorUpwards,
|
|
70
|
+
getDocument,
|
|
71
|
+
getWindow,
|
|
72
72
|
} from "../../dom/util.mjs";
|
|
73
|
-
import {
|
|
74
|
-
import {
|
|
75
|
-
import {
|
|
73
|
+
import {addAttributeToken} from "../../dom/attributes.mjs";
|
|
74
|
+
import {ATTRIBUTE_ERRORMESSAGE} from "../../dom/constants.mjs";
|
|
75
|
+
import {getDocumentTranslations} from "../../i18n/translations.mjs";
|
|
76
76
|
import "../state/state.mjs";
|
|
77
77
|
import "../host/collapse.mjs";
|
|
78
|
-
import {
|
|
78
|
+
import {generateUniqueConfigKey} from "../host/util.mjs";
|
|
79
79
|
|
|
80
80
|
import "./datasource/dom.mjs";
|
|
81
81
|
import "./datasource/rest.mjs";
|
|
82
82
|
|
|
83
|
-
export {
|
|
83
|
+
export {DataTable};
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
86
|
* @private
|
|
@@ -106,6 +106,12 @@ const gridHeadersElementSymbol = Symbol("gridHeadersElement");
|
|
|
106
106
|
*/
|
|
107
107
|
const columnBarElementSymbol = Symbol("columnBarElement");
|
|
108
108
|
|
|
109
|
+
/**
|
|
110
|
+
* @private
|
|
111
|
+
* @type {symbol}
|
|
112
|
+
*/
|
|
113
|
+
const copyAllElementSymbol = Symbol("copyAllElement");
|
|
114
|
+
|
|
109
115
|
/**
|
|
110
116
|
* @private
|
|
111
117
|
* @type {symbol}
|
|
@@ -142,387 +148,398 @@ const resizeObserverSymbol = Symbol("resizeObserver");
|
|
|
142
148
|
* @fires monster-datatable-row-added
|
|
143
149
|
**/
|
|
144
150
|
class DataTable extends CustomElement {
|
|
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
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
151
|
+
/**
|
|
152
|
+
* This method is called by the `instanceof` operator.
|
|
153
|
+
* @return {symbol}
|
|
154
|
+
*/
|
|
155
|
+
static get [instanceSymbol]() {
|
|
156
|
+
return Symbol.for("@schukai/monster/components/datatable@@instance");
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* To set the options via the HTML tag, the attribute `data-monster-options` must be used.
|
|
161
|
+
* @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
|
|
162
|
+
*
|
|
163
|
+
* The individual configuration values can be found in the table.
|
|
164
|
+
*
|
|
165
|
+
* @property {Object} templates Template definitions
|
|
166
|
+
* @property {string} templates.main Main template
|
|
167
|
+
* @property {Object} datasource Datasource configuration
|
|
168
|
+
* @property {string} datasource.selector Selector for the datasource
|
|
169
|
+
* @property {Object} mapping Mapping configuration
|
|
170
|
+
* @property {string} mapping.data Data mapping
|
|
171
|
+
* @property {Array} data Data
|
|
172
|
+
* @property {Array} headers Headers
|
|
173
|
+
* @property {Object} responsive Responsive configuration
|
|
174
|
+
* @property {number} responsive.breakpoint Breakpoint for responsive mode
|
|
175
|
+
* @property {Object} labels Labels
|
|
176
|
+
* @property {string} labels.theListContainsNoEntries Label for empty state
|
|
177
|
+
* @property {Object} classes Classes
|
|
178
|
+
* @property {string} classes.container Container class
|
|
179
|
+
* @property {Object} features Features
|
|
180
|
+
* @property {boolean} features.settings Settings feature
|
|
181
|
+
* @property {boolean} features.footer Footer feature
|
|
182
|
+
* @property {boolean} features.autoInit Auto init feature (init datasource automatically)
|
|
183
|
+
* @property {boolean} features.doubleClickCopyToClipboard Double click copy to clipboard feature
|
|
184
|
+
* @property {Object} templateMapping Template mapping
|
|
185
|
+
* @property {string} templateMapping.row-key Row key
|
|
186
|
+
* @property {string} templateMapping.filter-id Filter id
|
|
187
|
+
**/
|
|
188
|
+
get defaults() {
|
|
189
|
+
return Object.assign(
|
|
190
|
+
{},
|
|
191
|
+
super.defaults,
|
|
192
|
+
{
|
|
193
|
+
templates: {
|
|
194
|
+
main: getTemplate(),
|
|
195
|
+
emptyState: getEmptyTemplate(),
|
|
196
|
+
},
|
|
197
|
+
|
|
198
|
+
datasource: {
|
|
199
|
+
selector: null,
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
mapping: {
|
|
203
|
+
data: "dataset",
|
|
204
|
+
},
|
|
205
|
+
|
|
206
|
+
data: [],
|
|
207
|
+
headers: [],
|
|
208
|
+
|
|
209
|
+
responsive: {
|
|
210
|
+
breakpoint: 900,
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
labels: {
|
|
214
|
+
theListContainsNoEntries: "The list contains no entries",
|
|
215
|
+
copyAll: "Copy all",
|
|
216
|
+
},
|
|
217
|
+
|
|
218
|
+
classes: {
|
|
219
|
+
control: "monster-theme-control-container-1",
|
|
220
|
+
container: "",
|
|
221
|
+
row: "monster-theme-control-row-1",
|
|
222
|
+
},
|
|
223
|
+
|
|
224
|
+
features: {
|
|
225
|
+
settings: true,
|
|
226
|
+
footer: true,
|
|
227
|
+
autoInit: true,
|
|
228
|
+
doubleClickCopyToClipboard: true,
|
|
229
|
+
copyAll: true,
|
|
230
|
+
},
|
|
231
|
+
|
|
232
|
+
copy: {
|
|
233
|
+
delimiter: ";",
|
|
234
|
+
quoteOpen: '"',
|
|
235
|
+
quoteClose: '"',
|
|
236
|
+
rowBreak: "\n",
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
templateMapping: {
|
|
240
|
+
"row-key": null,
|
|
241
|
+
"filter-id": null,
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
initOptionsFromArguments.call(this),
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
*
|
|
250
|
+
* @param {string} selector
|
|
251
|
+
* @return {NodeListOf<*>}
|
|
252
|
+
*/
|
|
253
|
+
getGridElements(selector) {
|
|
254
|
+
return this[gridElementSymbol].querySelectorAll(selector);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
*
|
|
259
|
+
* @return {string}
|
|
260
|
+
*/
|
|
261
|
+
static getTag() {
|
|
262
|
+
return "monster-datatable";
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* @return {void}
|
|
267
|
+
*/
|
|
268
|
+
disconnectedCallback() {
|
|
269
|
+
super.disconnectedCallback();
|
|
270
|
+
if (this?.[resizeObserverSymbol] instanceof ResizeObserver) {
|
|
271
|
+
this[resizeObserverSymbol].disconnect();
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* @return {void}
|
|
277
|
+
*/
|
|
278
|
+
connectedCallback() {
|
|
279
|
+
const self = this;
|
|
280
|
+
super.connectedCallback();
|
|
281
|
+
|
|
282
|
+
this[resizeObserverSymbol] = new ResizeObserver((entries) => {
|
|
283
|
+
updateGrid.call(self);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
this[resizeObserverSymbol].observe(this.parentNode);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* @return void
|
|
291
|
+
*/
|
|
292
|
+
[assembleMethodSymbol]() {
|
|
293
|
+
const rawKey = this.getOption("templateMapping.row-key");
|
|
294
|
+
|
|
295
|
+
if (rawKey === null) {
|
|
296
|
+
if (this.id !== null && this.id !== "") {
|
|
297
|
+
const rawKey = this.getOption("templateMapping.row-key");
|
|
298
|
+
if (rawKey === null) {
|
|
299
|
+
this.setOption("templateMapping.row-key", this.id + "-row");
|
|
300
|
+
}
|
|
301
|
+
} else {
|
|
302
|
+
this.setOption("templateMapping.row-key", "row");
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (this.id !== null && this.id !== "") {
|
|
307
|
+
this.setOption("templateMapping.filter-id", "" + this.id + "-filter");
|
|
308
|
+
} else {
|
|
309
|
+
this.setOption("templateMapping.filter-id", "filter");
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
super[assembleMethodSymbol]();
|
|
313
|
+
|
|
314
|
+
initControlReferences.call(this);
|
|
315
|
+
initEventHandler.call(this);
|
|
316
|
+
|
|
317
|
+
const selector = this.getOption("datasource.selector");
|
|
318
|
+
|
|
319
|
+
if (isString(selector)) {
|
|
320
|
+
const element = findElementWithSelectorUpwards(this, selector);
|
|
321
|
+
if (element === null) {
|
|
322
|
+
throw new Error("the selector must match exactly one element");
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (!isInstance(element, Datasource)) {
|
|
326
|
+
throw new TypeError("the element must be a datasource");
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
this[datasourceLinkedElementSymbol] = element;
|
|
330
|
+
|
|
331
|
+
queueMicrotask(() => {
|
|
332
|
+
handleDataSourceChanges.call(this);
|
|
333
|
+
element.datasource.attachObserver(
|
|
334
|
+
new Observer(handleDataSourceChanges.bind(this)),
|
|
335
|
+
);
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
getHostConfig
|
|
340
|
+
.call(this, getColumnVisibilityConfigKey)
|
|
341
|
+
.then((config) => {
|
|
342
|
+
const headerOrderMap = new Map();
|
|
343
|
+
|
|
344
|
+
getHostConfig
|
|
345
|
+
.call(this, getStoredOrderConfigKey)
|
|
346
|
+
.then((orderConfig) => {
|
|
347
|
+
if (isArray(orderConfig) || orderConfig.length > 0) {
|
|
348
|
+
for (let i = 0; i < orderConfig.length; i++) {
|
|
349
|
+
const item = orderConfig[i];
|
|
350
|
+
const parts = item.split(" ");
|
|
351
|
+
const field = parts[0];
|
|
352
|
+
const direction = parts[1] || DIRECTION_ASC;
|
|
353
|
+
headerOrderMap.set(field, direction);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
})
|
|
357
|
+
.then(() => {
|
|
358
|
+
try {
|
|
359
|
+
initGridAndStructs.call(this, config, headerOrderMap);
|
|
360
|
+
} catch (error) {
|
|
361
|
+
addAttributeToken(
|
|
362
|
+
this,
|
|
363
|
+
ATTRIBUTE_ERRORMESSAGE,
|
|
364
|
+
error?.message || error.toString(),
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
updateColumnBar.call(this);
|
|
369
|
+
})
|
|
370
|
+
.catch((error) => {
|
|
371
|
+
addAttributeToken(
|
|
372
|
+
this,
|
|
373
|
+
ATTRIBUTE_ERRORMESSAGE,
|
|
374
|
+
error?.message || error.toString(),
|
|
375
|
+
);
|
|
376
|
+
});
|
|
377
|
+
})
|
|
378
|
+
.catch((error) => {
|
|
379
|
+
addAttributeToken(
|
|
380
|
+
this,
|
|
381
|
+
ATTRIBUTE_ERRORMESSAGE,
|
|
382
|
+
error?.message || error.toString(),
|
|
383
|
+
);
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* @return {CSSStyleSheet[]}
|
|
389
|
+
*/
|
|
390
|
+
static getCSSStyleSheet() {
|
|
391
|
+
return [DatatableStyleSheet];
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Copy a row from the datatable
|
|
396
|
+
*
|
|
397
|
+
* @param {number|string} fromIndex
|
|
398
|
+
* @param {number|string} toIndex
|
|
399
|
+
* @return {DataTable}
|
|
400
|
+
* @fires monster-datatable-row-copied
|
|
401
|
+
*/
|
|
402
|
+
copyRow(fromIndex, toIndex) {
|
|
403
|
+
const datasource = this[datasourceLinkedElementSymbol];
|
|
404
|
+
if (!datasource) {
|
|
405
|
+
return this;
|
|
406
|
+
}
|
|
407
|
+
let d = datasource.data;
|
|
408
|
+
let c = clone(d);
|
|
409
|
+
|
|
410
|
+
let rows = c;
|
|
411
|
+
const mapping = this.getOption("mapping.data");
|
|
412
|
+
|
|
413
|
+
if (mapping) {
|
|
414
|
+
rows = c?.[mapping];
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (rows === undefined || rows === null) {
|
|
418
|
+
rows = [];
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (toIndex === undefined) {
|
|
422
|
+
toIndex = rows.length;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (isString(fromIndex)) {
|
|
426
|
+
fromIndex = parseInt(fromIndex);
|
|
427
|
+
}
|
|
428
|
+
if (isString(toIndex)) {
|
|
429
|
+
toIndex = parseInt(toIndex);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
if (toIndex < 0 || toIndex > rows.length) {
|
|
433
|
+
throw new RangeError("index out of bounds");
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
validateArray(rows);
|
|
437
|
+
validateInteger(fromIndex);
|
|
438
|
+
validateInteger(toIndex);
|
|
439
|
+
|
|
440
|
+
if (fromIndex < 0 || fromIndex >= rows.length) {
|
|
441
|
+
throw new RangeError("index out of bounds");
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
rows.splice(toIndex, 0, clone(rows[fromIndex]));
|
|
445
|
+
datasource.data = c;
|
|
446
|
+
|
|
447
|
+
fireCustomEvent(this, "monster-datatable-row-copied", {
|
|
448
|
+
index: toIndex,
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
return this;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Remove a row from the datatable
|
|
456
|
+
*
|
|
457
|
+
* @param {number|string} index
|
|
458
|
+
* @return {DataTable}
|
|
459
|
+
* @fires monster-datatable-row-removed
|
|
460
|
+
*/
|
|
461
|
+
removeRow(index) {
|
|
462
|
+
const datasource = this[datasourceLinkedElementSymbol];
|
|
463
|
+
if (!datasource) {
|
|
464
|
+
return this;
|
|
465
|
+
}
|
|
466
|
+
let d = datasource.data;
|
|
467
|
+
let c = clone(d);
|
|
468
|
+
|
|
469
|
+
let rows = c;
|
|
470
|
+
const mapping = this.getOption("mapping.data");
|
|
471
|
+
|
|
472
|
+
if (mapping) {
|
|
473
|
+
rows = c?.[mapping];
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
if (rows === undefined || rows === null) {
|
|
477
|
+
rows = [];
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (isString(index)) {
|
|
481
|
+
index = parseInt(index);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
validateArray(rows);
|
|
485
|
+
validateInteger(index);
|
|
486
|
+
|
|
487
|
+
if (index < 0 || index >= rows.length) {
|
|
488
|
+
throw new RangeError("index out of bounds");
|
|
489
|
+
}
|
|
490
|
+
if (mapping) {
|
|
491
|
+
rows = c?.[mapping];
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
rows.splice(index, 1);
|
|
495
|
+
datasource.data = c;
|
|
496
|
+
|
|
497
|
+
fireCustomEvent(this, "monster-datatable-row-removed", {
|
|
498
|
+
index: index,
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
return this;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Add a row to the datatable
|
|
506
|
+
*
|
|
507
|
+
* @param {Object} data
|
|
508
|
+
* @return {DataTable}
|
|
509
|
+
*
|
|
510
|
+
* @fires monster-datatable-row-added
|
|
511
|
+
**/
|
|
512
|
+
addRow(data) {
|
|
513
|
+
const datasource = this[datasourceLinkedElementSymbol];
|
|
514
|
+
if (!datasource) {
|
|
515
|
+
return this;
|
|
516
|
+
}
|
|
517
|
+
let d = datasource.data;
|
|
518
|
+
let c = clone(d);
|
|
519
|
+
|
|
520
|
+
let rows = c;
|
|
521
|
+
|
|
522
|
+
const mapping = this.getOption("mapping.data");
|
|
523
|
+
if (mapping) {
|
|
524
|
+
rows = c?.[mapping];
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
if (rows === undefined || rows === null) {
|
|
528
|
+
rows = [];
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
validateArray(rows);
|
|
532
|
+
validateObject(data);
|
|
533
|
+
|
|
534
|
+
rows.push(data);
|
|
535
|
+
datasource.data = c;
|
|
536
|
+
|
|
537
|
+
fireCustomEvent(this, "monster-datatable-row-added", {
|
|
538
|
+
index: rows.length - 1,
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
return this;
|
|
542
|
+
}
|
|
526
543
|
}
|
|
527
544
|
|
|
528
545
|
/**
|
|
@@ -530,7 +547,7 @@ class DataTable extends CustomElement {
|
|
|
530
547
|
* @return {string}
|
|
531
548
|
*/
|
|
532
549
|
function getColumnVisibilityConfigKey() {
|
|
533
|
-
|
|
550
|
+
return generateUniqueConfigKey("datatable", this?.id, "columns-visibility");
|
|
534
551
|
}
|
|
535
552
|
|
|
536
553
|
/**
|
|
@@ -538,7 +555,7 @@ function getColumnVisibilityConfigKey() {
|
|
|
538
555
|
* @return {string}
|
|
539
556
|
*/
|
|
540
557
|
function getFilterConfigKey() {
|
|
541
|
-
|
|
558
|
+
return generateUniqueConfigKey("datatable", this?.id, "filter");
|
|
542
559
|
}
|
|
543
560
|
|
|
544
561
|
/**
|
|
@@ -546,287 +563,399 @@ function getFilterConfigKey() {
|
|
|
546
563
|
* @return {Promise}
|
|
547
564
|
*/
|
|
548
565
|
function getHostConfig(callback) {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
566
|
+
const host = findElementWithSelectorUpwards(this, "monster-host");
|
|
567
|
+
|
|
568
|
+
if (!(host && this.id)) {
|
|
569
|
+
return Promise.resolve({});
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
if (!host || !isFunction(host?.getConfig)) {
|
|
573
|
+
throw new TypeError("the host must be a monster-host");
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
const configKey = callback.call(this);
|
|
577
|
+
return host.hasConfig(configKey).then((hasConfig) => {
|
|
578
|
+
if (hasConfig) {
|
|
579
|
+
return host.getConfig(configKey);
|
|
580
|
+
} else {
|
|
581
|
+
return {};
|
|
582
|
+
}
|
|
583
|
+
});
|
|
567
584
|
}
|
|
568
585
|
|
|
569
586
|
/**
|
|
570
587
|
* @private
|
|
571
588
|
*/
|
|
572
589
|
function updateColumnBar() {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
590
|
+
if (!this[columnBarElementSymbol]) {
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
const columns = [];
|
|
595
|
+
for (const header of this.getOption("headers")) {
|
|
596
|
+
const mode = header.getInternal("mode");
|
|
597
|
+
|
|
598
|
+
if (mode === ATTRIBUTE_DATATABLE_MODE_FIXED) {
|
|
599
|
+
continue;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
columns.push({
|
|
603
|
+
visible: mode !== ATTRIBUTE_DATATABLE_MODE_HIDDEN,
|
|
604
|
+
name: header.label,
|
|
605
|
+
index: header.index,
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
this[columnBarElementSymbol].setOption("columns", columns);
|
|
593
610
|
}
|
|
594
611
|
|
|
595
612
|
/**
|
|
596
613
|
* @private
|
|
597
614
|
*/
|
|
598
615
|
function updateHeaderFromColumnBar() {
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
616
|
+
if (!this[columnBarElementSymbol]) {
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
602
619
|
|
|
603
|
-
|
|
604
|
-
|
|
620
|
+
const options = this[columnBarElementSymbol].getOption("columns");
|
|
621
|
+
if (!isArray(options)) return;
|
|
605
622
|
|
|
606
|
-
|
|
623
|
+
const invisibleMap = {};
|
|
607
624
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
625
|
+
for (let i = 0; i < options.length; i++) {
|
|
626
|
+
const option = options[i];
|
|
627
|
+
invisibleMap[option.index] = option.visible;
|
|
628
|
+
}
|
|
612
629
|
|
|
613
|
-
|
|
614
|
-
|
|
630
|
+
for (const header of this.getOption("headers")) {
|
|
631
|
+
const mode = header.getInternal("mode");
|
|
615
632
|
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
633
|
+
if (mode === ATTRIBUTE_DATATABLE_MODE_FIXED) {
|
|
634
|
+
continue;
|
|
635
|
+
}
|
|
619
636
|
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
637
|
+
if (invisibleMap[header.index] === false) {
|
|
638
|
+
header.setInternal("mode", ATTRIBUTE_DATATABLE_MODE_HIDDEN);
|
|
639
|
+
} else {
|
|
640
|
+
header.setInternal("mode", ATTRIBUTE_DATATABLE_MODE_VISIBLE);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
626
643
|
}
|
|
627
644
|
|
|
628
645
|
/**
|
|
629
646
|
* @private
|
|
630
647
|
*/
|
|
631
648
|
function updateConfigColumnBar() {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
649
|
+
if (!this[columnBarElementSymbol]) {
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
const options = this[columnBarElementSymbol].getOption("columns");
|
|
654
|
+
if (!isArray(options)) return;
|
|
655
|
+
|
|
656
|
+
const map = {};
|
|
657
|
+
for (let i = 0; i < options.length; i++) {
|
|
658
|
+
const option = options[i];
|
|
659
|
+
map[option.name] = option.visible;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
const host = findElementWithSelectorUpwards(this, "monster-host");
|
|
663
|
+
if (!(host && this.id)) {
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
const configKey = getColumnVisibilityConfigKey.call(this);
|
|
667
|
+
|
|
668
|
+
try {
|
|
669
|
+
host.setConfig(configKey, map);
|
|
670
|
+
} catch (error) {
|
|
671
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, String(error));
|
|
672
|
+
}
|
|
656
673
|
}
|
|
657
674
|
|
|
658
675
|
/**
|
|
659
676
|
* @private
|
|
660
677
|
*/
|
|
661
678
|
function initEventHandler() {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
679
|
+
const self = this;
|
|
680
|
+
|
|
681
|
+
const quoteOpenChar = this.getOption("copy.quoteOpen");
|
|
682
|
+
const quoteCloseChar = this.getOption("copy.quoteClose");
|
|
683
|
+
const delimiterChar = this.getOption("copy.delimiter");
|
|
684
|
+
const rowBreak = this.getOption("copy.rowBreak");
|
|
685
|
+
|
|
686
|
+
self[columnBarElementSymbol].attachObserver(
|
|
687
|
+
new Observer((e) => {
|
|
688
|
+
updateHeaderFromColumnBar.call(self);
|
|
689
|
+
updateGrid.call(self);
|
|
690
|
+
updateConfigColumnBar.call(self);
|
|
691
|
+
}),
|
|
692
|
+
);
|
|
693
|
+
|
|
694
|
+
self[gridHeadersElementSymbol].addEventListener("click", function (event) {
|
|
695
|
+
let element = null;
|
|
696
|
+
const datasource = self[datasourceLinkedElementSymbol];
|
|
697
|
+
if (!datasource) {
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
element = findTargetElementFromEvent(event, ATTRIBUTE_DATATABLE_SORTABLE);
|
|
702
|
+
if (element) {
|
|
703
|
+
const index = element.parentNode.getAttribute(ATTRIBUTE_DATATABLE_INDEX);
|
|
704
|
+
const headers = self.getOption("headers");
|
|
705
|
+
|
|
706
|
+
event.preventDefault();
|
|
707
|
+
|
|
708
|
+
headers[index].changeDirection();
|
|
709
|
+
|
|
710
|
+
queueMicrotask(function () {
|
|
711
|
+
/** hotfix, normally this should be done via the updater, no idea why this is not possible. */
|
|
712
|
+
element.setAttribute(
|
|
713
|
+
ATTRIBUTE_DATATABLE_SORTABLE,
|
|
714
|
+
`${headers[index].field} ${headers[index].direction}`,
|
|
715
|
+
);
|
|
716
|
+
|
|
717
|
+
storeOrderStatement.call(self, true);
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
const eventHandlerDoubleClickCopyToClipboard = (event) => {
|
|
725
|
+
const element = findTargetElementFromEvent(event, "data-monster-head");
|
|
726
|
+
if (element) {
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
let text = "";
|
|
730
|
+
|
|
731
|
+
if (event.shiftKey) {
|
|
732
|
+
const index = element.getAttribute("data-monster-insert-reference");
|
|
733
|
+
if (index) {
|
|
734
|
+
const cols = self.getGridElements(`[data-monster-insert-reference="${index}"]`);
|
|
735
|
+
|
|
736
|
+
const colTexts = []
|
|
737
|
+
for (let i = 0; i < cols.length; i++) {
|
|
738
|
+
const col = cols[i];
|
|
739
|
+
|
|
740
|
+
if (col.querySelector("monster-button-bar") || col.querySelector("monster-button")) {
|
|
741
|
+
continue;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
if (col.textContent) {
|
|
745
|
+
colTexts.push(quoteOpenChar+col.textContent.trim()+quoteCloseChar);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
text = colTexts.join(delimiterChar);
|
|
750
|
+
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
} else {
|
|
755
|
+
if (element.querySelector("monster-button-bar") || element.querySelector("monster-button")) {
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
text = element.textContent.trim();
|
|
760
|
+
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
if (getWindow().navigator.clipboard && text) {
|
|
764
|
+
getWindow().navigator.clipboard.writeText(text).then(
|
|
765
|
+
() => {
|
|
766
|
+
},
|
|
767
|
+
(err) => {
|
|
768
|
+
}
|
|
769
|
+
);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
if (self.getOption("features.doubleClickCopyToClipboard")) {
|
|
775
|
+
self[gridElementSymbol].addEventListener("dblclick", eventHandlerDoubleClickCopyToClipboard);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
if (self.getOption("features.copyAll") && this[copyAllElementSymbol]) {
|
|
779
|
+
this[copyAllElementSymbol].addEventListener("click", (event) => {
|
|
780
|
+
event.preventDefault();
|
|
781
|
+
|
|
782
|
+
const table = [];
|
|
783
|
+
let currentRow = [];
|
|
784
|
+
let currentIndex= null;
|
|
785
|
+
|
|
786
|
+
const cols = self.getGridElements(`[data-monster-insert-reference]`);
|
|
787
|
+
for (let i = 0; i < cols.length; i++) {
|
|
788
|
+
const col = cols[i];
|
|
789
|
+
|
|
790
|
+
const index = col.getAttribute("data-monster-insert-reference");
|
|
791
|
+
if (currentIndex !== index) {
|
|
792
|
+
if (currentRow.length > 0) {
|
|
793
|
+
table.push(currentRow);
|
|
794
|
+
}
|
|
795
|
+
currentRow = [];
|
|
796
|
+
currentIndex = index;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
if (col.querySelector("monster-button-bar") || col.querySelector("monster-button")) {
|
|
800
|
+
continue;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
if (col.textContent) {
|
|
804
|
+
currentRow.push(quoteOpenChar+col.textContent.trim()+quoteCloseChar);
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
if(table.length > 0) {
|
|
810
|
+
const text = table.map(row => row.join(delimiterChar)).join(rowBreak);
|
|
811
|
+
if (getWindow().navigator.clipboard && text) {
|
|
812
|
+
getWindow().navigator.clipboard.writeText(text).then(
|
|
813
|
+
() => {
|
|
814
|
+
},
|
|
815
|
+
(err) => {
|
|
816
|
+
}
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
});
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
|
|
699
828
|
}
|
|
700
829
|
|
|
701
830
|
/**
|
|
702
831
|
* @private
|
|
703
832
|
*/
|
|
704
833
|
function initGridAndStructs(hostConfig, headerOrderMap) {
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
834
|
+
const rowID = this.getOption("templateMapping.row-key");
|
|
835
|
+
|
|
836
|
+
if (!this[gridElementSymbol]) {
|
|
837
|
+
throw new Error("no grid element is defined");
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
let template;
|
|
841
|
+
getSlottedElements.call(this).forEach((e) => {
|
|
842
|
+
if (e instanceof HTMLTemplateElement && e.id === rowID) {
|
|
843
|
+
template = e;
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
if (!template) {
|
|
848
|
+
throw new Error("no template is defined");
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
const rowCount = template.content.children.length;
|
|
852
|
+
|
|
853
|
+
const headers = [];
|
|
854
|
+
|
|
855
|
+
for (let i = 0; i < rowCount; i++) {
|
|
856
|
+
let hClass = "";
|
|
857
|
+
const row = template.content.children[i];
|
|
858
|
+
|
|
859
|
+
let mode = "";
|
|
860
|
+
if (row.hasAttribute(ATTRIBUTE_DATATABLE_MODE)) {
|
|
861
|
+
mode = row.getAttribute(ATTRIBUTE_DATATABLE_MODE);
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
let grid = row.getAttribute(ATTRIBUTE_DATATABLE_GRID_TEMPLATE);
|
|
865
|
+
if (!grid || grid === "" || grid === "auto") {
|
|
866
|
+
grid = "minmax(0, 1fr)";
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
let label = "";
|
|
870
|
+
let labelKey = "";
|
|
871
|
+
|
|
872
|
+
if (row.hasAttribute(ATTRIBUTE_DATATABLE_HEAD)) {
|
|
873
|
+
label = row.getAttribute(ATTRIBUTE_DATATABLE_HEAD);
|
|
874
|
+
labelKey = label;
|
|
875
|
+
|
|
876
|
+
try {
|
|
877
|
+
if (label.startsWith("i18n:")) {
|
|
878
|
+
label = label.substring(5, label.length);
|
|
879
|
+
label = getDocumentTranslations().getText(label, label);
|
|
880
|
+
}
|
|
881
|
+
} catch (e) {
|
|
882
|
+
label = "i18n error " + label;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
if (!label) {
|
|
887
|
+
label = i + 1 + "";
|
|
888
|
+
mode = ATTRIBUTE_DATATABLE_MODE_FIXED;
|
|
889
|
+
labelKey = label;
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
if (isObject(hostConfig) && hostConfig.hasOwnProperty(label)) {
|
|
893
|
+
if (hostConfig[label] === false) {
|
|
894
|
+
mode = ATTRIBUTE_DATATABLE_MODE_HIDDEN;
|
|
895
|
+
} else {
|
|
896
|
+
mode = ATTRIBUTE_DATATABLE_MODE_VISIBLE;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
let align = "";
|
|
901
|
+
if (row.hasAttribute(ATTRIBUTE_DATATABLE_ALIGN)) {
|
|
902
|
+
align = row.getAttribute(ATTRIBUTE_DATATABLE_ALIGN);
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
switch (align) {
|
|
906
|
+
case "center":
|
|
907
|
+
hClass = "flex-center";
|
|
908
|
+
break;
|
|
909
|
+
case "end":
|
|
910
|
+
hClass = "flex-end";
|
|
911
|
+
break;
|
|
912
|
+
case "start":
|
|
913
|
+
hClass = "flex-start";
|
|
914
|
+
break;
|
|
915
|
+
default:
|
|
916
|
+
hClass = "flex-start";
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
let field = "";
|
|
920
|
+
let direction = DIRECTION_NONE;
|
|
921
|
+
if (row.hasAttribute(ATTRIBUTE_DATATABLE_SORTABLE)) {
|
|
922
|
+
field = row.getAttribute(ATTRIBUTE_DATATABLE_SORTABLE).trim();
|
|
923
|
+
const parts = field.split(" ").map((item) => item.trim());
|
|
924
|
+
field = parts[0];
|
|
925
|
+
|
|
926
|
+
if (headerOrderMap.has(field)) {
|
|
927
|
+
direction = headerOrderMap.get(field);
|
|
928
|
+
} else if (
|
|
929
|
+
parts.length === 2 &&
|
|
930
|
+
[DIRECTION_ASC, DIRECTION_DESC].indexOf(parts[1]) !== -1
|
|
931
|
+
) {
|
|
932
|
+
direction = parts[1];
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
if (mode === ATTRIBUTE_DATATABLE_MODE_HIDDEN) {
|
|
937
|
+
hClass += " hidden";
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
const header = new Header();
|
|
941
|
+
header.setInternals({
|
|
942
|
+
field: field,
|
|
943
|
+
label: label,
|
|
944
|
+
classes: hClass,
|
|
945
|
+
index: i,
|
|
946
|
+
mode: mode,
|
|
947
|
+
grid: grid,
|
|
948
|
+
labelKey: labelKey,
|
|
949
|
+
direction: direction,
|
|
950
|
+
});
|
|
951
|
+
|
|
952
|
+
headers.push(header);
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
this.setOption("headers", headers);
|
|
956
|
+
queueMicrotask(() => {
|
|
957
|
+
storeOrderStatement.call(this, this.getOption("features.autoInit"));
|
|
958
|
+
});
|
|
830
959
|
}
|
|
831
960
|
|
|
832
961
|
/**
|
|
@@ -834,79 +963,79 @@ function initGridAndStructs(hostConfig, headerOrderMap) {
|
|
|
834
963
|
* @return {string}
|
|
835
964
|
*/
|
|
836
965
|
export function getStoredOrderConfigKey() {
|
|
837
|
-
|
|
966
|
+
return generateUniqueConfigKey("datatable", this?.id, "stored-order");
|
|
838
967
|
}
|
|
839
968
|
|
|
840
969
|
/**
|
|
841
970
|
* @private
|
|
842
971
|
*/
|
|
843
972
|
function storeOrderStatement(doFetch) {
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
973
|
+
const headers = this.getOption("headers");
|
|
974
|
+
const statement = createOrderStatement(headers);
|
|
975
|
+
setDataSource.call(this, {orderBy: statement}, doFetch);
|
|
847
976
|
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
977
|
+
const host = findElementWithSelectorUpwards(this, "monster-host");
|
|
978
|
+
if (!(host && this.id)) {
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
852
981
|
|
|
853
|
-
|
|
982
|
+
const configKey = getStoredOrderConfigKey.call(this);
|
|
854
983
|
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
984
|
+
// statement explode with , and remove all empty
|
|
985
|
+
const list = statement.split(",").filter((item) => item.trim() !== "");
|
|
986
|
+
if (list.length === 0) {
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
860
989
|
|
|
861
|
-
|
|
990
|
+
host.setConfig(configKey, list);
|
|
862
991
|
}
|
|
863
992
|
|
|
864
993
|
/**
|
|
865
994
|
* @private
|
|
866
995
|
*/
|
|
867
996
|
function updateGrid() {
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
997
|
+
if (!this[gridElementSymbol]) {
|
|
998
|
+
throw new Error("no grid element is defined");
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
let gridTemplateColumns = "";
|
|
1002
|
+
|
|
1003
|
+
const headers = this.getOption("headers");
|
|
1004
|
+
|
|
1005
|
+
let styles = "";
|
|
1006
|
+
|
|
1007
|
+
for (let i = 0; i < headers.length; i++) {
|
|
1008
|
+
const header = headers[i];
|
|
1009
|
+
|
|
1010
|
+
if (header.mode === ATTRIBUTE_DATATABLE_MODE_HIDDEN) {
|
|
1011
|
+
styles += `[data-monster-role=datatable]>[data-monster-head="${header.labelKey}"] { display: none; }\n`;
|
|
1012
|
+
styles += `[data-monster-role=datatable-headers]>[data-monster-index="${header.index}"] { display: none; }\n`;
|
|
1013
|
+
} else {
|
|
1014
|
+
gridTemplateColumns += `${header.grid} `;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
const sheet = new CSSStyleSheet();
|
|
1019
|
+
if (styles !== "") sheet.replaceSync(styles);
|
|
1020
|
+
this.shadowRoot.adoptedStyleSheets = [...DataTable.getCSSStyleSheet(), sheet];
|
|
1021
|
+
|
|
1022
|
+
const bodyWidth = this.parentNode.clientWidth;
|
|
1023
|
+
|
|
1024
|
+
const breakpoint = this.getOption("responsive.breakpoint");
|
|
1025
|
+
this[dataControlElementSymbol].classList.toggle(
|
|
1026
|
+
"small",
|
|
1027
|
+
bodyWidth <= breakpoint,
|
|
1028
|
+
);
|
|
1029
|
+
|
|
1030
|
+
if (bodyWidth > breakpoint) {
|
|
1031
|
+
this[gridElementSymbol].style.gridTemplateColumns =
|
|
1032
|
+
`${gridTemplateColumns}`;
|
|
1033
|
+
this[gridHeadersElementSymbol].style.gridTemplateColumns =
|
|
1034
|
+
`${gridTemplateColumns}`;
|
|
1035
|
+
} else {
|
|
1036
|
+
this[gridElementSymbol].style.gridTemplateColumns = "auto";
|
|
1037
|
+
this[gridHeadersElementSymbol].style.gridTemplateColumns = "auto";
|
|
1038
|
+
}
|
|
910
1039
|
}
|
|
911
1040
|
|
|
912
1041
|
/**
|
|
@@ -914,20 +1043,20 @@ function updateGrid() {
|
|
|
914
1043
|
* @param {Header[]} headers
|
|
915
1044
|
* @param {bool} doFetch
|
|
916
1045
|
*/
|
|
917
|
-
function setDataSource({
|
|
918
|
-
|
|
1046
|
+
function setDataSource({orderBy}, doFetch) {
|
|
1047
|
+
const datasource = this[datasourceLinkedElementSymbol];
|
|
919
1048
|
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
1049
|
+
if (!datasource) {
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
923
1052
|
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
1053
|
+
if (isFunction(datasource?.setParameters)) {
|
|
1054
|
+
datasource.setParameters({orderBy});
|
|
1055
|
+
}
|
|
927
1056
|
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
1057
|
+
if (doFetch !== false && isFunction(datasource?.fetch)) {
|
|
1058
|
+
datasource.fetch();
|
|
1059
|
+
}
|
|
931
1060
|
}
|
|
932
1061
|
|
|
933
1062
|
/**
|
|
@@ -935,24 +1064,28 @@ function setDataSource({ orderBy }, doFetch) {
|
|
|
935
1064
|
* @return {DataTable}
|
|
936
1065
|
*/
|
|
937
1066
|
function initControlReferences() {
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
1067
|
+
if (!this.shadowRoot) {
|
|
1068
|
+
throw new Error("no shadow-root is defined");
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
this[dataControlElementSymbol] = this.shadowRoot.querySelector(
|
|
1072
|
+
"[data-monster-role=control]",
|
|
1073
|
+
);
|
|
1074
|
+
|
|
1075
|
+
this[gridElementSymbol] = this.shadowRoot.querySelector(
|
|
1076
|
+
"[data-monster-role=datatable]",
|
|
1077
|
+
);
|
|
1078
|
+
this[gridHeadersElementSymbol] = this.shadowRoot.querySelector(
|
|
1079
|
+
"[data-monster-role=datatable-headers]",
|
|
1080
|
+
);
|
|
1081
|
+
this[columnBarElementSymbol] =
|
|
1082
|
+
this.shadowRoot.querySelector("monster-column-bar");
|
|
1083
|
+
|
|
1084
|
+
this[copyAllElementSymbol] = this.shadowRoot.querySelector(
|
|
1085
|
+
"[data-monster-role=copy-all]",
|
|
1086
|
+
);
|
|
1087
|
+
|
|
1088
|
+
return this;
|
|
956
1089
|
}
|
|
957
1090
|
|
|
958
1091
|
/**
|
|
@@ -962,22 +1095,22 @@ function initControlReferences() {
|
|
|
962
1095
|
* @throws {Error} the datasource could not be initialized
|
|
963
1096
|
*/
|
|
964
1097
|
function initOptionsFromArguments() {
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
1098
|
+
const options = {};
|
|
1099
|
+
const selector = this.getAttribute(ATTRIBUTE_DATASOURCE_SELECTOR);
|
|
1100
|
+
|
|
1101
|
+
if (selector) {
|
|
1102
|
+
options.datasource = {selector: selector};
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
const breakpoint = this.getAttribute(
|
|
1106
|
+
ATTRIBUTE_DATATABLE_RESPONSIVE_BREAKPOINT,
|
|
1107
|
+
);
|
|
1108
|
+
if (breakpoint) {
|
|
1109
|
+
options.responsive = {};
|
|
1110
|
+
options.responsive.breakpoint = parseInt(breakpoint);
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
return options;
|
|
981
1114
|
}
|
|
982
1115
|
|
|
983
1116
|
/**
|
|
@@ -985,7 +1118,7 @@ function initOptionsFromArguments() {
|
|
|
985
1118
|
* @return {string}
|
|
986
1119
|
*/
|
|
987
1120
|
function getEmptyTemplate() {
|
|
988
|
-
|
|
1121
|
+
return `<monster-state data-monster-role="empty-without-action">
|
|
989
1122
|
<div part="visual">
|
|
990
1123
|
<svg width="4rem" height="4rem" fill="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
991
1124
|
<path d="m21.5 22h-19c-1.378 0-2.5-1.121-2.5-2.5v-7c0-.07.015-.141.044-.205l3.969-8.82c.404-.896 1.299-1.475 2.28-1.475h11.414c.981 0 1.876.579 2.28 1.475l3.969 8.82c.029.064.044.135.044.205v7c0 1.379-1.122 2.5-2.5 2.5zm-20.5-9.393v6.893c0 .827.673 1.5 1.5 1.5h19c.827 0 1.5-.673 1.5-1.5v-6.893l-3.925-8.723c-.242-.536-.779-.884-1.368-.884h-11.414c-.589 0-1.126.348-1.368.885z"/>
|
|
@@ -1003,8 +1136,8 @@ function getEmptyTemplate() {
|
|
|
1003
1136
|
* @return {string}
|
|
1004
1137
|
*/
|
|
1005
1138
|
function getTemplate() {
|
|
1006
|
-
|
|
1007
|
-
|
|
1139
|
+
// language=HTML
|
|
1140
|
+
return `
|
|
1008
1141
|
<div data-monster-role="control" part="control" data-monster-attributes="class path:classes.control">
|
|
1009
1142
|
<template id="headers-row">
|
|
1010
1143
|
<div data-monster-attributes="class path:headers-row.classes,
|
|
@@ -1018,6 +1151,7 @@ function getTemplate() {
|
|
|
1018
1151
|
<slot name="filter"></slot>
|
|
1019
1152
|
</div>
|
|
1020
1153
|
<div class="bar">
|
|
1154
|
+
<a href="#" data-monster-attributes="class path:features.copyAll | ?::hidden" data-monster-role="copy-all" data-monster-replace="path:locale.copyAll">Copy all</a>
|
|
1021
1155
|
<monster-column-bar
|
|
1022
1156
|
data-monster-attributes="class path:features.settings | ?::hidden"></monster-column-bar>
|
|
1023
1157
|
<slot name="bar"></slot>
|