tablefilter 0.7.7 → 0.7.8
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/README.md +2 -1
- package/dist/starter.html +2 -2
- package/dist/tablefilter/tablefilter.js +1 -1
- package/dist/tablefilter/tf-1-dca7dae32ca501c46faf.js +1 -0
- package/dist/tablefilter/{tf-2-0ea691278d572212426a.js → tf-2-eaf25ea22f7cd033d053.js} +2 -2
- package/dist/tablefilter.cjs.js +300 -58
- package/dist/tablefilter.esm.js +300 -58
- package/dist/tablefilter.umd.js +300 -58
- package/package.json +8 -7
- package/src/components/tf-checklist.js +571 -0
- package/src/modules/checkList.js +405 -93
- package/src/number.js +13 -1
- package/dist/tablefilter/tf-1-7e29d0dbe6e0e0a4ff05.js +0 -1
package/src/modules/checkList.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import {BaseDropdown} from './baseDropdown';
|
|
2
2
|
import {
|
|
3
|
-
addClass, createCheckItem, createText, createElm, elm, removeClass,
|
|
3
|
+
addClass, createCheckItem, createText, createElm, elm, removeClass,
|
|
4
|
+
removeElm, tag
|
|
4
5
|
} from '../dom';
|
|
5
6
|
import {has} from '../array';
|
|
6
7
|
import {matchCase, trim, rgxEsc} from '../string';
|
|
7
8
|
import {addEvt, removeEvt, targetEvt} from '../event';
|
|
8
|
-
import {isEmpty} from '../types';
|
|
9
|
+
import {isArray, isEmpty} from '../types';
|
|
9
10
|
import {CHECKLIST, NONE} from '../const';
|
|
10
11
|
import {defaultsStr, defaultsBool} from '../settings';
|
|
11
12
|
|
|
@@ -32,6 +33,34 @@ export class CheckList extends BaseDropdown {
|
|
|
32
33
|
*/
|
|
33
34
|
this.containers = [];
|
|
34
35
|
|
|
36
|
+
/**
|
|
37
|
+
* `<tf-checklist>` hosts, when the bridge is active
|
|
38
|
+
* @type {Array}
|
|
39
|
+
* @private
|
|
40
|
+
*/
|
|
41
|
+
this.ceElms = [];
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Handlers bound to each `<tf-checklist>` host
|
|
45
|
+
* @type {Array}
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
this.ceEvt = [];
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Selected values reported by each `<tf-checklist>` host
|
|
52
|
+
* @type {Array}
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
this.ceValues = [];
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Trigger names cached per column for `<tf-checklist>` hosts
|
|
59
|
+
* @type {Array}
|
|
60
|
+
* @private
|
|
61
|
+
*/
|
|
62
|
+
this.ceNames = [];
|
|
63
|
+
|
|
35
64
|
/**
|
|
36
65
|
* Css class for the container of the checklist filter (div)
|
|
37
66
|
* @type {String}
|
|
@@ -125,6 +154,107 @@ export class CheckList extends BaseDropdown {
|
|
|
125
154
|
}
|
|
126
155
|
}
|
|
127
156
|
|
|
157
|
+
/**
|
|
158
|
+
* `<tf-checklist>` selection event handler
|
|
159
|
+
* @param {Number} colIndex Column index
|
|
160
|
+
* @param {Event} evt `selection-change` event
|
|
161
|
+
* @private
|
|
162
|
+
*/
|
|
163
|
+
onCESelectionChange(colIndex, evt) {
|
|
164
|
+
let tf = this.tf;
|
|
165
|
+
let host = this.ceElms[colIndex];
|
|
166
|
+
let values = evt.detail && isArray(evt.detail.values) ?
|
|
167
|
+
evt.detail.values.slice() : [];
|
|
168
|
+
|
|
169
|
+
values = this.normalizeCESelection(colIndex, values);
|
|
170
|
+
this.ceValues[colIndex] = values;
|
|
171
|
+
this.syncCEText(colIndex);
|
|
172
|
+
|
|
173
|
+
this.emitter.emit('filter-focus', tf, host);
|
|
174
|
+
tf.filter();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* `<tf-checklist>` open event handler used by the load-on-demand
|
|
179
|
+
* feature: the options are rendered on the first expansion
|
|
180
|
+
* @param {Number} colIndex Column index
|
|
181
|
+
* @param {Event} evt `open-change` event
|
|
182
|
+
* @private
|
|
183
|
+
*/
|
|
184
|
+
onCEOpenChange(colIndex, evt) {
|
|
185
|
+
let host = this.ceElms[colIndex];
|
|
186
|
+
if (!evt.detail || !evt.detail.open || !host) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (host.getAttribute('filled') !== '1') {
|
|
190
|
+
this.build(colIndex);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Keep the reset option exclusive. The element toggles every option
|
|
196
|
+
* independently, while the legacy checklist clears the other
|
|
197
|
+
* selections when the reset item is picked and unchecks the reset
|
|
198
|
+
* item when another option is picked (checkList.js:391-425).
|
|
199
|
+
* @param {Number} colIndex Column index
|
|
200
|
+
* @param {Array} values Selected values reported by the element
|
|
201
|
+
* @returns {Array} Normalized selection
|
|
202
|
+
* @private
|
|
203
|
+
*/
|
|
204
|
+
normalizeCESelection(colIndex, values) {
|
|
205
|
+
let host = this.ceElms[colIndex];
|
|
206
|
+
let previous = this.ceValues[colIndex] || [];
|
|
207
|
+
let hasReset = values.indexOf('') !== -1;
|
|
208
|
+
|
|
209
|
+
if (!host || !hasReset || values.length === 1) {
|
|
210
|
+
return values;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
let normalized = previous.indexOf('') === -1 ?
|
|
214
|
+
[''] : values.filter((value) => value !== '');
|
|
215
|
+
host.setSelectedValues(normalized);
|
|
216
|
+
return normalized;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Render the trigger text from the column name and the selection
|
|
221
|
+
* count, and name the listbox from the same column name
|
|
222
|
+
* (v1-webcomponents-investigation.md:247-289)
|
|
223
|
+
* @param {Number} colIndex Column index
|
|
224
|
+
* @private
|
|
225
|
+
*/
|
|
226
|
+
syncCEText(colIndex) {
|
|
227
|
+
let host = this.ceElms[colIndex];
|
|
228
|
+
if (!host) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
let name = this.getCEName(colIndex);
|
|
233
|
+
let count = (this.ceValues[colIndex] || [])
|
|
234
|
+
.filter((value) => value !== '').length;
|
|
235
|
+
|
|
236
|
+
host.setAttribute('trigger-text',
|
|
237
|
+
count ? `${name} (${count})` : name);
|
|
238
|
+
host.setAttribute('listbox-label', `${name} options`);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Return the trigger name for a column: its header text, or a
|
|
243
|
+
* position-based fallback when the header is empty
|
|
244
|
+
* @param {Number} colIndex Column index
|
|
245
|
+
* @returns {String} Column name
|
|
246
|
+
* @private
|
|
247
|
+
*/
|
|
248
|
+
getCEName(colIndex) {
|
|
249
|
+
let name = this.ceNames[colIndex];
|
|
250
|
+
if (!name) {
|
|
251
|
+
let header = this.tf.getHeadersText()[colIndex];
|
|
252
|
+
name = header || `Column ${colIndex + 1}`;
|
|
253
|
+
this.ceNames[colIndex] = name;
|
|
254
|
+
}
|
|
255
|
+
return name;
|
|
256
|
+
}
|
|
257
|
+
|
|
128
258
|
/**
|
|
129
259
|
* Refresh all checklist filters
|
|
130
260
|
*/
|
|
@@ -140,6 +270,99 @@ export class CheckList extends BaseDropdown {
|
|
|
140
270
|
* @param {DOMElement} container Dom element containing the filter
|
|
141
271
|
*/
|
|
142
272
|
init(colIndex, isExternal, container) {
|
|
273
|
+
// `init()` runs per checklist column (tablefilter.js:1009-1010),
|
|
274
|
+
// but the feature instance is shared and its emitter handlers are
|
|
275
|
+
// only registered on the first call; structural per-column setup
|
|
276
|
+
// (initCE/initLegacy) still runs every call.
|
|
277
|
+
if (!this.initialized) {
|
|
278
|
+
// Store stable handler refs so `destroy()` removes the right
|
|
279
|
+
// listeners (the emitter keys on function identity).
|
|
280
|
+
this.onBuildChecklistFilter =
|
|
281
|
+
(tf, colIndex, isLinked) =>
|
|
282
|
+
this.build(colIndex, isLinked);
|
|
283
|
+
this.onSelectChecklistOptions =
|
|
284
|
+
(tf, colIndex, values) =>
|
|
285
|
+
this.selectOptions(colIndex, values);
|
|
286
|
+
this.onRowsChanged = () => this.refreshAll();
|
|
287
|
+
this.onAfterFiltering = () => this.linkFilters();
|
|
288
|
+
|
|
289
|
+
this.emitter.on(['build-checklist-filter'],
|
|
290
|
+
this.onBuildChecklistFilter);
|
|
291
|
+
this.emitter.on(['select-checklist-options'],
|
|
292
|
+
this.onSelectChecklistOptions);
|
|
293
|
+
this.emitter.on(['rows-changed'], this.onRowsChanged);
|
|
294
|
+
this.emitter.on(['after-filtering'], this.onAfterFiltering);
|
|
295
|
+
|
|
296
|
+
/** @inherited */
|
|
297
|
+
this.initialized = true;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// Bridge to <tf-checklist> (#930). The element is used when the
|
|
301
|
+
// source registers it (Vite / module load); otherwise the legacy
|
|
302
|
+
// div/ul/li structure is rendered.
|
|
303
|
+
// TODO(#965): drop this fork once <tf-checklist> is part of the
|
|
304
|
+
// published bundle so the element path is the only path.
|
|
305
|
+
if (typeof customElements !== 'undefined' &&
|
|
306
|
+
customElements.get('tf-checklist')) {
|
|
307
|
+
this.initCE(colIndex, isExternal, container);
|
|
308
|
+
} else {
|
|
309
|
+
this.initLegacy(colIndex, isExternal, container);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Initialize using the <tf-checklist> custom element
|
|
315
|
+
* @param {Number} colIndex Column index
|
|
316
|
+
* @param {Boolean} isExternal External filter flag
|
|
317
|
+
* @param {DOMElement} container Dom element containing the filter
|
|
318
|
+
* @private
|
|
319
|
+
*/
|
|
320
|
+
initCE(colIndex, isExternal, container) {
|
|
321
|
+
let tf = this.tf;
|
|
322
|
+
let externalFltTgtId = isExternal ?
|
|
323
|
+
tf.externalFltIds[colIndex] : null;
|
|
324
|
+
|
|
325
|
+
let host = document.createElement('tf-checklist');
|
|
326
|
+
// The host carries the filter id: `getFilterElement()`,
|
|
327
|
+
// `getFilterId()` and `getColumnIndexFromFilterId()` resolve it.
|
|
328
|
+
host.id = tf.buildFilterId(colIndex);
|
|
329
|
+
host.className = this.containerCssClass;
|
|
330
|
+
host.setAttribute('col', String(colIndex));
|
|
331
|
+
|
|
332
|
+
if (externalFltTgtId) {
|
|
333
|
+
elm(externalFltTgtId).appendChild(host);
|
|
334
|
+
} else {
|
|
335
|
+
container.appendChild(host);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
this.containers[colIndex] = host;
|
|
339
|
+
this.ceElms[colIndex] = host;
|
|
340
|
+
this.ceValues[colIndex] = [];
|
|
341
|
+
tf.fltIds.push(host.id);
|
|
342
|
+
|
|
343
|
+
let evt = this.ceEvt[colIndex] = {
|
|
344
|
+
selectionChange: (e) => this.onCESelectionChange(colIndex, e),
|
|
345
|
+
openChange: (e) => this.onCEOpenChange(colIndex, e)
|
|
346
|
+
};
|
|
347
|
+
addEvt(host, 'selection-change', evt.selectionChange);
|
|
348
|
+
addEvt(host, 'open-change', evt.openChange);
|
|
349
|
+
|
|
350
|
+
if (!tf.loadFltOnDemand) {
|
|
351
|
+
this.build(colIndex);
|
|
352
|
+
} else {
|
|
353
|
+
host.setAttribute('trigger-text', this.activateText);
|
|
354
|
+
host.setAttribute('listbox-label', `${this.activateText} options`);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Initialize using the legacy div/ul/li structure
|
|
360
|
+
* @param {Number} colIndex Column index
|
|
361
|
+
* @param {Boolean} isExternal External filter flag
|
|
362
|
+
* @param {DOMElement} container Dom element containing the filter
|
|
363
|
+
* @private
|
|
364
|
+
*/
|
|
365
|
+
initLegacy(colIndex, isExternal, container) {
|
|
143
366
|
let tf = this.tf;
|
|
144
367
|
let externalFltTgtId = isExternal ?
|
|
145
368
|
tf.externalFltIds[colIndex] : null;
|
|
@@ -165,23 +388,6 @@ export class CheckList extends BaseDropdown {
|
|
|
165
388
|
addEvt(divCont, 'click', (evt) => this.onCheckListClick(evt));
|
|
166
389
|
divCont.appendChild(createText(this.activateText));
|
|
167
390
|
}
|
|
168
|
-
|
|
169
|
-
this.emitter.on(
|
|
170
|
-
['build-checklist-filter'],
|
|
171
|
-
(tf, colIndex, isLinked) => this.build(colIndex, isLinked)
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
this.emitter.on(
|
|
175
|
-
['select-checklist-options'],
|
|
176
|
-
(tf, colIndex, values) => this.selectOptions(colIndex, values)
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
this.emitter.on(['rows-changed'], () => this.refreshAll());
|
|
180
|
-
|
|
181
|
-
this.emitter.on(['after-filtering'], () => this.linkFilters());
|
|
182
|
-
|
|
183
|
-
/** @inherited */
|
|
184
|
-
this.initialized = true;
|
|
185
391
|
}
|
|
186
392
|
|
|
187
393
|
/**
|
|
@@ -200,12 +406,6 @@ export class CheckList extends BaseDropdown {
|
|
|
200
406
|
/** @inherited */
|
|
201
407
|
this.optsTxt = [];
|
|
202
408
|
|
|
203
|
-
let flt = this.containers[colIndex];
|
|
204
|
-
let ul = createElm('ul',
|
|
205
|
-
['id', tf.fltIds[colIndex]],
|
|
206
|
-
['colIndex', colIndex]);
|
|
207
|
-
ul.className = this.filterCssClass;
|
|
208
|
-
|
|
209
409
|
let caseSensitive = tf.caseSensitive;
|
|
210
410
|
/** @inherited */
|
|
211
411
|
this.isCustom = tf.isCustomOptions(colIndex);
|
|
@@ -230,8 +430,6 @@ export class CheckList extends BaseDropdown {
|
|
|
230
430
|
this.excludedOpts = [];
|
|
231
431
|
}
|
|
232
432
|
|
|
233
|
-
flt.innerHTML = '';
|
|
234
|
-
|
|
235
433
|
let eachRow = tf.eachRow();
|
|
236
434
|
eachRow(
|
|
237
435
|
(row) => {
|
|
@@ -277,6 +475,51 @@ export class CheckList extends BaseDropdown {
|
|
|
277
475
|
this.excludedOpts = this.sortOptions(colIndex, this.excludedOpts);
|
|
278
476
|
}
|
|
279
477
|
|
|
478
|
+
if (this.ceElms[colIndex]) {
|
|
479
|
+
this.buildCE(colIndex);
|
|
480
|
+
} else {
|
|
481
|
+
this.buildLegacy(colIndex);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Render the options into a <tf-checklist> host
|
|
487
|
+
* @param {Number} colIndex Column index
|
|
488
|
+
* @private
|
|
489
|
+
*/
|
|
490
|
+
buildCE(colIndex) {
|
|
491
|
+
let tf = this.tf;
|
|
492
|
+
let host = this.ceElms[colIndex];
|
|
493
|
+
|
|
494
|
+
host.setOptions(this.getOptionEntries(colIndex)
|
|
495
|
+
.filter((entry) => !entry.hidden)
|
|
496
|
+
.map((entry) => ({
|
|
497
|
+
value: entry.value,
|
|
498
|
+
text: entry.text,
|
|
499
|
+
disabled: entry.disabled
|
|
500
|
+
})));
|
|
501
|
+
host.setAttribute('filled', '1');
|
|
502
|
+
|
|
503
|
+
this.ceValues[colIndex] = [];
|
|
504
|
+
this.syncCEText(colIndex);
|
|
505
|
+
|
|
506
|
+
this.emitter.emit('after-populating-filter', tf, colIndex, host);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Render the options into the legacy ul element
|
|
511
|
+
* @param {Number} colIndex Column index
|
|
512
|
+
* @private
|
|
513
|
+
*/
|
|
514
|
+
buildLegacy(colIndex) {
|
|
515
|
+
let tf = this.tf;
|
|
516
|
+
let flt = this.containers[colIndex];
|
|
517
|
+
let ul = createElm('ul',
|
|
518
|
+
['id', tf.fltIds[colIndex]],
|
|
519
|
+
['colIndex', colIndex]);
|
|
520
|
+
ul.className = this.filterCssClass;
|
|
521
|
+
|
|
522
|
+
flt.innerHTML = '';
|
|
280
523
|
this.addChecks(colIndex, ul);
|
|
281
524
|
|
|
282
525
|
if (tf.loadFltOnDemand) {
|
|
@@ -288,6 +531,46 @@ export class CheckList extends BaseDropdown {
|
|
|
288
531
|
this.emitter.emit('after-populating-filter', tf, colIndex, flt);
|
|
289
532
|
}
|
|
290
533
|
|
|
534
|
+
/**
|
|
535
|
+
* Return the checklist entries in render order: the reset option,
|
|
536
|
+
* the optional empty and non-empty options, then the column values.
|
|
537
|
+
* A `hidden` entry is rendered with `display: none` by the legacy
|
|
538
|
+
* path and skipped by `<tf-checklist>`, which has no hidden option
|
|
539
|
+
* state (checkList.js:321-324, :345-347).
|
|
540
|
+
* @param {Number} colIndex Column index
|
|
541
|
+
* @returns {Array} Option entries
|
|
542
|
+
* @private
|
|
543
|
+
*/
|
|
544
|
+
getOptionEntries(colIndex) {
|
|
545
|
+
let tf = this.tf;
|
|
546
|
+
let entries = [{
|
|
547
|
+
value: '',
|
|
548
|
+
text: tf.getClearFilterText(colIndex),
|
|
549
|
+
hidden: !this.enableResetOption
|
|
550
|
+
}];
|
|
551
|
+
|
|
552
|
+
if (tf.enableEmptyOption) {
|
|
553
|
+
entries.push({ value: tf.emOperator, text: tf.emptyText });
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
if (tf.enableNonEmptyOption) {
|
|
557
|
+
entries.push({ value: tf.nmOperator, text: tf.nonEmptyText });
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
this.opts.forEach((val, y) => {
|
|
561
|
+
entries.push({
|
|
562
|
+
value: val,
|
|
563
|
+
text: this.isCustom ? this.optsTxt[y] : val,
|
|
564
|
+
disabled: tf.linkedFilters && tf.disableExcludedOptions &&
|
|
565
|
+
has(this.excludedOpts,
|
|
566
|
+
matchCase(val, tf.caseSensitive), tf.caseSensitive),
|
|
567
|
+
hidden: val === ''
|
|
568
|
+
});
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
return entries;
|
|
572
|
+
}
|
|
573
|
+
|
|
291
574
|
/**
|
|
292
575
|
* Add checklist options
|
|
293
576
|
* @param {Number} colIndex Column index
|
|
@@ -296,20 +579,14 @@ export class CheckList extends BaseDropdown {
|
|
|
296
579
|
*/
|
|
297
580
|
addChecks(colIndex, ul) {
|
|
298
581
|
let tf = this.tf;
|
|
299
|
-
let
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
let
|
|
303
|
-
|
|
304
|
-
let fltId = tf.fltIds[colIndex];
|
|
305
|
-
let lblIdx = y + chkCt;
|
|
306
|
-
let li = createCheckItem(`${fltId}_${lblIdx}`, val, lbl,
|
|
307
|
-
['data-idx', lblIdx]);
|
|
582
|
+
let fltId = tf.fltIds[colIndex];
|
|
583
|
+
|
|
584
|
+
this.getOptionEntries(colIndex).forEach((entry, idx) => {
|
|
585
|
+
let li = createCheckItem(`${fltId}_${idx}`, entry.value,
|
|
586
|
+
entry.text, ['data-idx', idx]);
|
|
308
587
|
li.className = this.itemCssClass;
|
|
309
588
|
|
|
310
|
-
if (
|
|
311
|
-
has(this.excludedOpts, matchCase(val, tf.caseSensitive),
|
|
312
|
-
tf.caseSensitive)) {
|
|
589
|
+
if (entry.disabled) {
|
|
313
590
|
addClass(li, this.disabledItemCssClass);
|
|
314
591
|
li.check.disabled = true;
|
|
315
592
|
li.disabled = true;
|
|
@@ -318,52 +595,10 @@ export class CheckList extends BaseDropdown {
|
|
|
318
595
|
}
|
|
319
596
|
ul.appendChild(li);
|
|
320
597
|
|
|
321
|
-
if (
|
|
322
|
-
//item is hidden
|
|
598
|
+
if (entry.hidden) {
|
|
323
599
|
li.style.display = NONE;
|
|
324
600
|
}
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* Add checklist header option
|
|
330
|
-
* @param {Number} colIndex Column index
|
|
331
|
-
* @param {Object} ul Ul element
|
|
332
|
-
* @private
|
|
333
|
-
*/
|
|
334
|
-
addTChecks(colIndex, ul) {
|
|
335
|
-
let tf = this.tf;
|
|
336
|
-
let chkCt = 1;
|
|
337
|
-
let fltId = tf.fltIds[colIndex];
|
|
338
|
-
let li0 = createCheckItem(`${fltId}_0`, '',
|
|
339
|
-
tf.getClearFilterText(colIndex), ['data-idx', 0]);
|
|
340
|
-
li0.className = this.itemCssClass;
|
|
341
|
-
ul.appendChild(li0);
|
|
342
|
-
|
|
343
|
-
addEvt(li0.check, 'click', evt => this.optionClick(evt));
|
|
344
|
-
|
|
345
|
-
if (!this.enableResetOption) {
|
|
346
|
-
li0.style.display = NONE;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
if (tf.enableEmptyOption) {
|
|
350
|
-
let li1 = createCheckItem(`${fltId}_1`, tf.emOperator,
|
|
351
|
-
tf.emptyText, ['data-idx', 1]);
|
|
352
|
-
li1.className = this.itemCssClass;
|
|
353
|
-
ul.appendChild(li1);
|
|
354
|
-
addEvt(li1.check, 'click', evt => this.optionClick(evt));
|
|
355
|
-
chkCt++;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
if (tf.enableNonEmptyOption) {
|
|
359
|
-
let li2 = createCheckItem(`${fltId}_2`, tf.nmOperator,
|
|
360
|
-
tf.nonEmptyText, ['data-idx', 2]);
|
|
361
|
-
li2.className = this.itemCssClass;
|
|
362
|
-
ul.appendChild(li2);
|
|
363
|
-
addEvt(li2.check, 'click', evt => this.optionClick(evt));
|
|
364
|
-
chkCt++;
|
|
365
|
-
}
|
|
366
|
-
return chkCt;
|
|
601
|
+
});
|
|
367
602
|
}
|
|
368
603
|
|
|
369
604
|
/**
|
|
@@ -443,6 +678,11 @@ export class CheckList extends BaseDropdown {
|
|
|
443
678
|
* @param {Array} values Array of option values to select
|
|
444
679
|
*/
|
|
445
680
|
selectOptions(colIndex, values = []) {
|
|
681
|
+
if (this.ceElms[colIndex]) {
|
|
682
|
+
this.selectOptionsCE(colIndex, values);
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
|
|
446
686
|
let tf = this.tf;
|
|
447
687
|
let flt = tf.getFilterElement(colIndex);
|
|
448
688
|
if (!flt || values.length === 0) {
|
|
@@ -477,12 +717,59 @@ export class CheckList extends BaseDropdown {
|
|
|
477
717
|
});
|
|
478
718
|
}
|
|
479
719
|
|
|
720
|
+
/**
|
|
721
|
+
* Select options on a <tf-checklist> host. Values are matched against
|
|
722
|
+
* the rendered entries the way the legacy `selectOptions()` matches
|
|
723
|
+
* the checkbox values, and the reset value (`''`) clears the
|
|
724
|
+
* selection instead of being selected (checkList.js:457-477).
|
|
725
|
+
* @param {Number} colIndex Column index
|
|
726
|
+
* @param {Array} values Array of option values to select
|
|
727
|
+
* @private
|
|
728
|
+
*/
|
|
729
|
+
selectOptionsCE(colIndex, values) {
|
|
730
|
+
let tf = this.tf;
|
|
731
|
+
let host = this.ceElms[colIndex];
|
|
732
|
+
if (!host) {
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// Legacy `selectOptions()` returns early for an empty values array
|
|
737
|
+
// (checkList.js:677), so mirror that for path parity: a
|
|
738
|
+
// `setFilterValue(col, [])` does not change the selection.
|
|
739
|
+
if (isArray(values) && values.length === 0) {
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
let requested = (isArray(values) ? values : [])
|
|
744
|
+
.filter((value) => String(value) !== '');
|
|
745
|
+
let selected = [];
|
|
746
|
+
|
|
747
|
+
this.getOptionEntries(colIndex)
|
|
748
|
+
.filter((entry) => !entry.hidden)
|
|
749
|
+
.forEach((entry) => {
|
|
750
|
+
let value = matchCase(String(entry.value), tf.caseSensitive);
|
|
751
|
+
if (has(requested, value, tf.caseSensitive)) {
|
|
752
|
+
selected.push(entry.value);
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
|
|
756
|
+
host.setSelectedValues(selected);
|
|
757
|
+
this.ceValues[colIndex] = selected;
|
|
758
|
+
this.syncCEText(colIndex);
|
|
759
|
+
}
|
|
760
|
+
|
|
480
761
|
/**
|
|
481
762
|
* Get filter values for a given column index
|
|
482
763
|
* @param {Number} colIndex Column index
|
|
483
764
|
* @returns {Array} values Collection of selected values
|
|
484
765
|
*/
|
|
485
766
|
getValues(colIndex) {
|
|
767
|
+
let host = this.ceElms[colIndex];
|
|
768
|
+
if (host) {
|
|
769
|
+
let values = host.getSelectedValues();
|
|
770
|
+
return values.length === 0 ? [''] : values;
|
|
771
|
+
}
|
|
772
|
+
|
|
486
773
|
let tf = this.tf;
|
|
487
774
|
let flt = tf.getFilterElement(colIndex);
|
|
488
775
|
if (!flt) {
|
|
@@ -499,20 +786,45 @@ export class CheckList extends BaseDropdown {
|
|
|
499
786
|
return values;
|
|
500
787
|
}
|
|
501
788
|
|
|
789
|
+
/**
|
|
790
|
+
* Remove the <tf-checklist> hosts and the handlers bound to them
|
|
791
|
+
* @private
|
|
792
|
+
*/
|
|
793
|
+
destroyCE() {
|
|
794
|
+
this.ceElms.forEach((host, colIndex) => {
|
|
795
|
+
if (!host) {
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
let evt = this.ceEvt[colIndex];
|
|
799
|
+
if (evt) {
|
|
800
|
+
removeEvt(host, 'selection-change', evt.selectionChange);
|
|
801
|
+
removeEvt(host, 'open-change', evt.openChange);
|
|
802
|
+
}
|
|
803
|
+
if (host.parentNode) {
|
|
804
|
+
removeElm(host);
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
this.ceElms = [];
|
|
809
|
+
this.ceEvt = [];
|
|
810
|
+
this.ceValues = [];
|
|
811
|
+
}
|
|
812
|
+
|
|
502
813
|
/**
|
|
503
814
|
* Destroy CheckList instance
|
|
504
815
|
*/
|
|
505
816
|
destroy() {
|
|
506
|
-
this.
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
);
|
|
514
|
-
this.emitter.off(['
|
|
515
|
-
|
|
817
|
+
if (!this.initialized) {
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
this.emitter.off(['build-checklist-filter'],
|
|
821
|
+
this.onBuildChecklistFilter);
|
|
822
|
+
this.emitter.off(['select-checklist-options'],
|
|
823
|
+
this.onSelectChecklistOptions);
|
|
824
|
+
this.emitter.off(['rows-changed'], this.onRowsChanged);
|
|
825
|
+
this.emitter.off(['after-filtering'], this.onAfterFiltering);
|
|
826
|
+
|
|
827
|
+
this.destroyCE();
|
|
516
828
|
|
|
517
829
|
this.initialized = false;
|
|
518
830
|
}
|
package/src/number.js
CHANGED
|
@@ -2,11 +2,23 @@ import {isNumber} from './types';
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Formats a numeric value with configurable separators and affixes.
|
|
5
|
+
*
|
|
6
|
+
* Supported options: `locale`, `decimal`, `integerSeparator`, `precision`,
|
|
7
|
+
* `round`, `prefix` and `suffix`. The `format-number` options `truncate`,
|
|
8
|
+
* `padLeft`, `padRight`, `negativeType`, `negativeLeftSymbol`,
|
|
9
|
+
* `negativeRightSymbol`, `negativeOut`, `decimalsSeparator` and `noUnits`
|
|
10
|
+
* have no effect. `integerSeparator: null` disables grouping. Values of
|
|
11
|
+
* magnitude 1e21 and above are rendered in full instead of exponential
|
|
12
|
+
* notation.
|
|
13
|
+
*
|
|
14
|
+
* Requires `Intl.NumberFormat.prototype.formatToParts` (Chrome 64+, Edge 79+,
|
|
15
|
+
* Firefox 58+, Safari 11+, Node 10+).
|
|
5
16
|
* @param {Number|String} value Numeric value
|
|
6
17
|
* @param {Object} [options={}] Formatting options
|
|
7
18
|
* @param {String} [options.locale='en'] Intl locale
|
|
8
19
|
* @param {String} [options.decimal] Decimal separator override
|
|
9
|
-
* @param {String} [options.integerSeparator] Thousands separator override
|
|
20
|
+
* @param {String|null} [options.integerSeparator] Thousands separator override:
|
|
21
|
+
* `undefined` uses locale default grouping, `null` or `''` disables grouping
|
|
10
22
|
* @param {Number} [options.precision] Fixed number of fraction digits
|
|
11
23
|
* @param {Number} [options.round] Maximum number of fraction digits
|
|
12
24
|
* @param {String} [options.prefix=''] Value prefix
|