tablefilter 0.7.6 → 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.
@@ -889,11 +889,23 @@ function bound(fn, scope) {
889
889
  //#region src/number.js
890
890
  /**
891
891
  * Formats a numeric value with configurable separators and affixes.
892
+ *
893
+ * Supported options: `locale`, `decimal`, `integerSeparator`, `precision`,
894
+ * `round`, `prefix` and `suffix`. The `format-number` options `truncate`,
895
+ * `padLeft`, `padRight`, `negativeType`, `negativeLeftSymbol`,
896
+ * `negativeRightSymbol`, `negativeOut`, `decimalsSeparator` and `noUnits`
897
+ * have no effect. `integerSeparator: null` disables grouping. Values of
898
+ * magnitude 1e21 and above are rendered in full instead of exponential
899
+ * notation.
900
+ *
901
+ * Requires `Intl.NumberFormat.prototype.formatToParts` (Chrome 64+, Edge 79+,
902
+ * Firefox 58+, Safari 11+, Node 10+).
892
903
  * @param {Number|String} value Numeric value
893
904
  * @param {Object} [options={}] Formatting options
894
905
  * @param {String} [options.locale='en'] Intl locale
895
906
  * @param {String} [options.decimal] Decimal separator override
896
- * @param {String} [options.integerSeparator] Thousands separator override
907
+ * @param {String|null} [options.integerSeparator] Thousands separator override:
908
+ * `undefined` uses locale default grouping, `null` or `''` disables grouping
897
909
  * @param {Number} [options.precision] Fixed number of fraction digits
898
910
  * @param {Number} [options.round] Maximum number of fraction digits
899
911
  * @param {String} [options.prefix=''] Value prefix
@@ -10282,6 +10294,30 @@ var CheckList = class CheckList extends BaseDropdown {
10282
10294
  */
10283
10295
  this.containers = [];
10284
10296
  /**
10297
+ * `<tf-checklist>` hosts, when the bridge is active
10298
+ * @type {Array}
10299
+ * @private
10300
+ */
10301
+ this.ceElms = [];
10302
+ /**
10303
+ * Handlers bound to each `<tf-checklist>` host
10304
+ * @type {Array}
10305
+ * @private
10306
+ */
10307
+ this.ceEvt = [];
10308
+ /**
10309
+ * Selected values reported by each `<tf-checklist>` host
10310
+ * @type {Array}
10311
+ * @private
10312
+ */
10313
+ this.ceValues = [];
10314
+ /**
10315
+ * Trigger names cached per column for `<tf-checklist>` hosts
10316
+ * @type {Array}
10317
+ * @private
10318
+ */
10319
+ this.ceNames = [];
10320
+ /**
10285
10321
  * Css class for the container of the checklist filter (div)
10286
10322
  * @type {String}
10287
10323
  */
@@ -10351,6 +10387,83 @@ var CheckList = class CheckList extends BaseDropdown {
10351
10387
  }
10352
10388
  }
10353
10389
  /**
10390
+ * `<tf-checklist>` selection event handler
10391
+ * @param {Number} colIndex Column index
10392
+ * @param {Event} evt `selection-change` event
10393
+ * @private
10394
+ */
10395
+ onCESelectionChange(colIndex, evt) {
10396
+ let tf = this.tf;
10397
+ let host = this.ceElms[colIndex];
10398
+ let values = evt.detail && isArray(evt.detail.values) ? evt.detail.values.slice() : [];
10399
+ values = this.normalizeCESelection(colIndex, values);
10400
+ this.ceValues[colIndex] = values;
10401
+ this.syncCEText(colIndex);
10402
+ this.emitter.emit("filter-focus", tf, host);
10403
+ tf.filter();
10404
+ }
10405
+ /**
10406
+ * `<tf-checklist>` open event handler used by the load-on-demand
10407
+ * feature: the options are rendered on the first expansion
10408
+ * @param {Number} colIndex Column index
10409
+ * @param {Event} evt `open-change` event
10410
+ * @private
10411
+ */
10412
+ onCEOpenChange(colIndex, evt) {
10413
+ let host = this.ceElms[colIndex];
10414
+ if (!evt.detail || !evt.detail.open || !host) return;
10415
+ if (host.getAttribute("filled") !== "1") this.build(colIndex);
10416
+ }
10417
+ /**
10418
+ * Keep the reset option exclusive. The element toggles every option
10419
+ * independently, while the legacy checklist clears the other
10420
+ * selections when the reset item is picked and unchecks the reset
10421
+ * item when another option is picked (checkList.js:391-425).
10422
+ * @param {Number} colIndex Column index
10423
+ * @param {Array} values Selected values reported by the element
10424
+ * @returns {Array} Normalized selection
10425
+ * @private
10426
+ */
10427
+ normalizeCESelection(colIndex, values) {
10428
+ let host = this.ceElms[colIndex];
10429
+ let previous = this.ceValues[colIndex] || [];
10430
+ let hasReset = values.indexOf("") !== -1;
10431
+ if (!host || !hasReset || values.length === 1) return values;
10432
+ let normalized = previous.indexOf("") === -1 ? [""] : values.filter((value) => value !== "");
10433
+ host.setSelectedValues(normalized);
10434
+ return normalized;
10435
+ }
10436
+ /**
10437
+ * Render the trigger text from the column name and the selection
10438
+ * count, and name the listbox from the same column name
10439
+ * (v1-webcomponents-investigation.md:247-289)
10440
+ * @param {Number} colIndex Column index
10441
+ * @private
10442
+ */
10443
+ syncCEText(colIndex) {
10444
+ let host = this.ceElms[colIndex];
10445
+ if (!host) return;
10446
+ let name = this.getCEName(colIndex);
10447
+ let count = (this.ceValues[colIndex] || []).filter((value) => value !== "").length;
10448
+ host.setAttribute("trigger-text", count ? `${name} (${count})` : name);
10449
+ host.setAttribute("listbox-label", `${name} options`);
10450
+ }
10451
+ /**
10452
+ * Return the trigger name for a column: its header text, or a
10453
+ * position-based fallback when the header is empty
10454
+ * @param {Number} colIndex Column index
10455
+ * @returns {String} Column name
10456
+ * @private
10457
+ */
10458
+ getCEName(colIndex) {
10459
+ let name = this.ceNames[colIndex];
10460
+ if (!name) {
10461
+ name = this.tf.getHeadersText()[colIndex] || `Column ${colIndex + 1}`;
10462
+ this.ceNames[colIndex] = name;
10463
+ }
10464
+ return name;
10465
+ }
10466
+ /**
10354
10467
  * Refresh all checklist filters
10355
10468
  */
10356
10469
  refreshAll() {
@@ -10364,6 +10477,61 @@ var CheckList = class CheckList extends BaseDropdown {
10364
10477
  * @param {DOMElement} container Dom element containing the filter
10365
10478
  */
10366
10479
  init(colIndex, isExternal, container) {
10480
+ if (!this.initialized) {
10481
+ this.onBuildChecklistFilter = (tf, colIndex, isLinked) => this.build(colIndex, isLinked);
10482
+ this.onSelectChecklistOptions = (tf, colIndex, values) => this.selectOptions(colIndex, values);
10483
+ this.onRowsChanged = () => this.refreshAll();
10484
+ this.onAfterFiltering = () => this.linkFilters();
10485
+ this.emitter.on(["build-checklist-filter"], this.onBuildChecklistFilter);
10486
+ this.emitter.on(["select-checklist-options"], this.onSelectChecklistOptions);
10487
+ this.emitter.on(["rows-changed"], this.onRowsChanged);
10488
+ this.emitter.on(["after-filtering"], this.onAfterFiltering);
10489
+ /** @inherited */
10490
+ this.initialized = true;
10491
+ }
10492
+ if (typeof customElements !== "undefined" && customElements.get("tf-checklist")) this.initCE(colIndex, isExternal, container);
10493
+ else this.initLegacy(colIndex, isExternal, container);
10494
+ }
10495
+ /**
10496
+ * Initialize using the <tf-checklist> custom element
10497
+ * @param {Number} colIndex Column index
10498
+ * @param {Boolean} isExternal External filter flag
10499
+ * @param {DOMElement} container Dom element containing the filter
10500
+ * @private
10501
+ */
10502
+ initCE(colIndex, isExternal, container) {
10503
+ let tf = this.tf;
10504
+ let externalFltTgtId = isExternal ? tf.externalFltIds[colIndex] : null;
10505
+ let host = document.createElement("tf-checklist");
10506
+ host.id = tf.buildFilterId(colIndex);
10507
+ host.className = this.containerCssClass;
10508
+ host.setAttribute("col", String(colIndex));
10509
+ if (externalFltTgtId) elm(externalFltTgtId).appendChild(host);
10510
+ else container.appendChild(host);
10511
+ this.containers[colIndex] = host;
10512
+ this.ceElms[colIndex] = host;
10513
+ this.ceValues[colIndex] = [];
10514
+ tf.fltIds.push(host.id);
10515
+ let evt = this.ceEvt[colIndex] = {
10516
+ selectionChange: (e) => this.onCESelectionChange(colIndex, e),
10517
+ openChange: (e) => this.onCEOpenChange(colIndex, e)
10518
+ };
10519
+ addEvt(host, "selection-change", evt.selectionChange);
10520
+ addEvt(host, "open-change", evt.openChange);
10521
+ if (!tf.loadFltOnDemand) this.build(colIndex);
10522
+ else {
10523
+ host.setAttribute("trigger-text", this.activateText);
10524
+ host.setAttribute("listbox-label", `${this.activateText} options`);
10525
+ }
10526
+ }
10527
+ /**
10528
+ * Initialize using the legacy div/ul/li structure
10529
+ * @param {Number} colIndex Column index
10530
+ * @param {Boolean} isExternal External filter flag
10531
+ * @param {DOMElement} container Dom element containing the filter
10532
+ * @private
10533
+ */
10534
+ initLegacy(colIndex, isExternal, container) {
10367
10535
  let tf = this.tf;
10368
10536
  let externalFltTgtId = isExternal ? tf.externalFltIds[colIndex] : null;
10369
10537
  let divCont = createElm("div", ["id", `${this.prfx}${colIndex}_${tf.id}`], ["ct", colIndex], ["filled", "0"]);
@@ -10377,12 +10545,6 @@ var CheckList = class CheckList extends BaseDropdown {
10377
10545
  addEvt(divCont, "click", (evt) => this.onCheckListClick(evt));
10378
10546
  divCont.appendChild(createText(this.activateText));
10379
10547
  }
10380
- this.emitter.on(["build-checklist-filter"], (tf, colIndex, isLinked) => this.build(colIndex, isLinked));
10381
- this.emitter.on(["select-checklist-options"], (tf, colIndex, values) => this.selectOptions(colIndex, values));
10382
- this.emitter.on(["rows-changed"], () => this.refreshAll());
10383
- this.emitter.on(["after-filtering"], () => this.linkFilters());
10384
- /** @inherited */
10385
- this.initialized = true;
10386
10548
  }
10387
10549
  /**
10388
10550
  * Build checklist UI
@@ -10397,9 +10559,6 @@ var CheckList = class CheckList extends BaseDropdown {
10397
10559
  this.opts = [];
10398
10560
  /** @inherited */
10399
10561
  this.optsTxt = [];
10400
- let flt = this.containers[colIndex];
10401
- let ul = createElm("ul", ["id", tf.fltIds[colIndex]], ["colIndex", colIndex]);
10402
- ul.className = this.filterCssClass;
10403
10562
  let caseSensitive = tf.caseSensitive;
10404
10563
  /** @inherited */
10405
10564
  this.isCustom = tf.isCustomOptions(colIndex);
@@ -10415,7 +10574,6 @@ var CheckList = class CheckList extends BaseDropdown {
10415
10574
  if (isLinked && tf.disableExcludedOptions)
10416
10575
  /** @inherited */
10417
10576
  this.excludedOpts = [];
10418
- flt.innerHTML = "";
10419
10577
  tf.eachRow()((row) => {
10420
10578
  let cellValue = tf.getCellValue(row.cells[colIndex]);
10421
10579
  let cellString = matchCase(cellValue, caseSensitive);
@@ -10432,6 +10590,38 @@ var CheckList = class CheckList extends BaseDropdown {
10432
10590
  });
10433
10591
  this.opts = this.sortOptions(colIndex, this.opts);
10434
10592
  if (this.excludedOpts) this.excludedOpts = this.sortOptions(colIndex, this.excludedOpts);
10593
+ if (this.ceElms[colIndex]) this.buildCE(colIndex);
10594
+ else this.buildLegacy(colIndex);
10595
+ }
10596
+ /**
10597
+ * Render the options into a <tf-checklist> host
10598
+ * @param {Number} colIndex Column index
10599
+ * @private
10600
+ */
10601
+ buildCE(colIndex) {
10602
+ let tf = this.tf;
10603
+ let host = this.ceElms[colIndex];
10604
+ host.setOptions(this.getOptionEntries(colIndex).filter((entry) => !entry.hidden).map((entry) => ({
10605
+ value: entry.value,
10606
+ text: entry.text,
10607
+ disabled: entry.disabled
10608
+ })));
10609
+ host.setAttribute("filled", "1");
10610
+ this.ceValues[colIndex] = [];
10611
+ this.syncCEText(colIndex);
10612
+ this.emitter.emit("after-populating-filter", tf, colIndex, host);
10613
+ }
10614
+ /**
10615
+ * Render the options into the legacy ul element
10616
+ * @param {Number} colIndex Column index
10617
+ * @private
10618
+ */
10619
+ buildLegacy(colIndex) {
10620
+ let tf = this.tf;
10621
+ let flt = this.containers[colIndex];
10622
+ let ul = createElm("ul", ["id", tf.fltIds[colIndex]], ["colIndex", colIndex]);
10623
+ ul.className = this.filterCssClass;
10624
+ flt.innerHTML = "";
10435
10625
  this.addChecks(colIndex, ul);
10436
10626
  if (tf.loadFltOnDemand) flt.innerHTML = "";
10437
10627
  flt.appendChild(ul);
@@ -10439,60 +10629,59 @@ var CheckList = class CheckList extends BaseDropdown {
10439
10629
  this.emitter.emit("after-populating-filter", tf, colIndex, flt);
10440
10630
  }
10441
10631
  /**
10632
+ * Return the checklist entries in render order: the reset option,
10633
+ * the optional empty and non-empty options, then the column values.
10634
+ * A `hidden` entry is rendered with `display: none` by the legacy
10635
+ * path and skipped by `<tf-checklist>`, which has no hidden option
10636
+ * state (checkList.js:321-324, :345-347).
10637
+ * @param {Number} colIndex Column index
10638
+ * @returns {Array} Option entries
10639
+ * @private
10640
+ */
10641
+ getOptionEntries(colIndex) {
10642
+ let tf = this.tf;
10643
+ let entries = [{
10644
+ value: "",
10645
+ text: tf.getClearFilterText(colIndex),
10646
+ hidden: !this.enableResetOption
10647
+ }];
10648
+ if (tf.enableEmptyOption) entries.push({
10649
+ value: tf.emOperator,
10650
+ text: tf.emptyText
10651
+ });
10652
+ if (tf.enableNonEmptyOption) entries.push({
10653
+ value: tf.nmOperator,
10654
+ text: tf.nonEmptyText
10655
+ });
10656
+ this.opts.forEach((val, y) => {
10657
+ entries.push({
10658
+ value: val,
10659
+ text: this.isCustom ? this.optsTxt[y] : val,
10660
+ disabled: tf.linkedFilters && tf.disableExcludedOptions && has(this.excludedOpts, matchCase(val, tf.caseSensitive), tf.caseSensitive),
10661
+ hidden: val === ""
10662
+ });
10663
+ });
10664
+ return entries;
10665
+ }
10666
+ /**
10442
10667
  * Add checklist options
10443
10668
  * @param {Number} colIndex Column index
10444
10669
  * @param {Object} ul Ul element
10445
10670
  * @private
10446
10671
  */
10447
10672
  addChecks(colIndex, ul) {
10448
- let tf = this.tf;
10449
- let chkCt = this.addTChecks(colIndex, ul);
10450
- for (let y = 0; y < this.opts.length; y++) {
10451
- let val = this.opts[y];
10452
- let lbl = this.isCustom ? this.optsTxt[y] : val;
10453
- let fltId = tf.fltIds[colIndex];
10454
- let lblIdx = y + chkCt;
10455
- let li = createCheckItem(`${fltId}_${lblIdx}`, val, lbl, ["data-idx", lblIdx]);
10673
+ let fltId = this.tf.fltIds[colIndex];
10674
+ this.getOptionEntries(colIndex).forEach((entry, idx) => {
10675
+ let li = createCheckItem(`${fltId}_${idx}`, entry.value, entry.text, ["data-idx", idx]);
10456
10676
  li.className = this.itemCssClass;
10457
- if (tf.linkedFilters && tf.disableExcludedOptions && has(this.excludedOpts, matchCase(val, tf.caseSensitive), tf.caseSensitive)) {
10677
+ if (entry.disabled) {
10458
10678
  addClass(li, this.disabledItemCssClass);
10459
10679
  li.check.disabled = true;
10460
10680
  li.disabled = true;
10461
10681
  } else addEvt(li.check, "click", (evt) => this.optionClick(evt));
10462
10682
  ul.appendChild(li);
10463
- if (val === "") li.style.display = NONE;
10464
- }
10465
- }
10466
- /**
10467
- * Add checklist header option
10468
- * @param {Number} colIndex Column index
10469
- * @param {Object} ul Ul element
10470
- * @private
10471
- */
10472
- addTChecks(colIndex, ul) {
10473
- let tf = this.tf;
10474
- let chkCt = 1;
10475
- let fltId = tf.fltIds[colIndex];
10476
- let li0 = createCheckItem(`${fltId}_0`, "", tf.getClearFilterText(colIndex), ["data-idx", 0]);
10477
- li0.className = this.itemCssClass;
10478
- ul.appendChild(li0);
10479
- addEvt(li0.check, "click", (evt) => this.optionClick(evt));
10480
- if (!this.enableResetOption) li0.style.display = NONE;
10481
- if (tf.enableEmptyOption) {
10482
- let li1 = createCheckItem(`${fltId}_1`, tf.emOperator, tf.emptyText, ["data-idx", 1]);
10483
- li1.className = this.itemCssClass;
10484
- ul.appendChild(li1);
10485
- addEvt(li1.check, "click", (evt) => this.optionClick(evt));
10486
- chkCt++;
10487
- }
10488
- if (tf.enableNonEmptyOption) {
10489
- let li2 = createCheckItem(`${fltId}_2`, tf.nmOperator, tf.nonEmptyText, ["data-idx", 2]);
10490
- li2.className = this.itemCssClass;
10491
- ul.appendChild(li2);
10492
- addEvt(li2.check, "click", (evt) => this.optionClick(evt));
10493
- chkCt++;
10494
- }
10495
- return chkCt;
10683
+ if (entry.hidden) li.style.display = NONE;
10684
+ });
10496
10685
  }
10497
10686
  /**
10498
10687
  * Set/unset value of passed item option in filter's DOM element attribute
@@ -10549,6 +10738,10 @@ var CheckList = class CheckList extends BaseDropdown {
10549
10738
  * @param {Array} values Array of option values to select
10550
10739
  */
10551
10740
  selectOptions(colIndex, values = []) {
10741
+ if (this.ceElms[colIndex]) {
10742
+ this.selectOptionsCE(colIndex, values);
10743
+ return;
10744
+ }
10552
10745
  let tf = this.tf;
10553
10746
  let flt = tf.getFilterElement(colIndex);
10554
10747
  if (!flt || values.length === 0) return;
@@ -10566,11 +10759,40 @@ var CheckList = class CheckList extends BaseDropdown {
10566
10759
  });
10567
10760
  }
10568
10761
  /**
10762
+ * Select options on a <tf-checklist> host. Values are matched against
10763
+ * the rendered entries the way the legacy `selectOptions()` matches
10764
+ * the checkbox values, and the reset value (`''`) clears the
10765
+ * selection instead of being selected (checkList.js:457-477).
10766
+ * @param {Number} colIndex Column index
10767
+ * @param {Array} values Array of option values to select
10768
+ * @private
10769
+ */
10770
+ selectOptionsCE(colIndex, values) {
10771
+ let tf = this.tf;
10772
+ let host = this.ceElms[colIndex];
10773
+ if (!host) return;
10774
+ if (isArray(values) && values.length === 0) return;
10775
+ let requested = (isArray(values) ? values : []).filter((value) => String(value) !== "");
10776
+ let selected = [];
10777
+ this.getOptionEntries(colIndex).filter((entry) => !entry.hidden).forEach((entry) => {
10778
+ let value = matchCase(String(entry.value), tf.caseSensitive);
10779
+ if (has(requested, value, tf.caseSensitive)) selected.push(entry.value);
10780
+ });
10781
+ host.setSelectedValues(selected);
10782
+ this.ceValues[colIndex] = selected;
10783
+ this.syncCEText(colIndex);
10784
+ }
10785
+ /**
10569
10786
  * Get filter values for a given column index
10570
10787
  * @param {Number} colIndex Column index
10571
10788
  * @returns {Array} values Collection of selected values
10572
10789
  */
10573
10790
  getValues(colIndex) {
10791
+ let host = this.ceElms[colIndex];
10792
+ if (host) {
10793
+ let values = host.getSelectedValues();
10794
+ return values.length === 0 ? [""] : values;
10795
+ }
10574
10796
  let tf = this.tf;
10575
10797
  let flt = tf.getFilterElement(colIndex);
10576
10798
  if (!flt) return [];
@@ -10581,13 +10803,33 @@ var CheckList = class CheckList extends BaseDropdown {
10581
10803
  return values;
10582
10804
  }
10583
10805
  /**
10806
+ * Remove the <tf-checklist> hosts and the handlers bound to them
10807
+ * @private
10808
+ */
10809
+ destroyCE() {
10810
+ this.ceElms.forEach((host, colIndex) => {
10811
+ if (!host) return;
10812
+ let evt = this.ceEvt[colIndex];
10813
+ if (evt) {
10814
+ removeEvt(host, "selection-change", evt.selectionChange);
10815
+ removeEvt(host, "open-change", evt.openChange);
10816
+ }
10817
+ if (host.parentNode) removeElm(host);
10818
+ });
10819
+ this.ceElms = [];
10820
+ this.ceEvt = [];
10821
+ this.ceValues = [];
10822
+ }
10823
+ /**
10584
10824
  * Destroy CheckList instance
10585
10825
  */
10586
10826
  destroy() {
10587
- this.emitter.off(["build-checklist-filter"], (tf, colIndex, isLinked) => this.build(colIndex, isLinked));
10588
- this.emitter.off(["select-checklist-options"], (tf, colIndex, values) => this.selectOptions(colIndex, values));
10589
- this.emitter.off(["rows-changed"], () => this.refreshAll());
10590
- this.emitter.off(["after-filtering"], () => this.linkFilters());
10827
+ if (!this.initialized) return;
10828
+ this.emitter.off(["build-checklist-filter"], this.onBuildChecklistFilter);
10829
+ this.emitter.off(["select-checklist-options"], this.onSelectChecklistOptions);
10830
+ this.emitter.off(["rows-changed"], this.onRowsChanged);
10831
+ this.emitter.off(["after-filtering"], this.onAfterFiltering);
10832
+ this.destroyCE();
10591
10833
  this.initialized = false;
10592
10834
  }
10593
10835
  };
@@ -15050,6 +15292,12 @@ var Paging = class Paging extends Feature {
15050
15292
  * @private
15051
15293
  */
15052
15294
  this.pgAfter = null;
15295
+ /**
15296
+ * <tf-pager> custom element host, when the bridge is active
15297
+ * @type {DOMElement}
15298
+ * @private
15299
+ */
15300
+ this.pagerEl = null;
15053
15301
  let startRow = tf.refRow;
15054
15302
  let nrows = tf.getRowsNb(true);
15055
15303
  this.nbPages = Math.ceil((nrows - startRow) / this.pageLength);
@@ -15090,6 +15338,7 @@ var Paging = class Paging extends Feature {
15090
15338
  }
15091
15339
  },
15092
15340
  slcPagesChange: null,
15341
+ pagerPageChange: null,
15093
15342
  nextEvt: null,
15094
15343
  prevEvt: null,
15095
15344
  lastEvt: null,
@@ -15100,9 +15349,7 @@ var Paging = class Paging extends Feature {
15100
15349
  * Initialize DOM elements
15101
15350
  */
15102
15351
  init() {
15103
- let slcPages;
15104
15352
  let tf = this.tf;
15105
- let evt = this.evt;
15106
15353
  if (this.initialized) return;
15107
15354
  this.emitter.emit("initializing-feature", this, !isNull(this.tgtId));
15108
15355
  if (this.hasResultsPerPage) {
@@ -15112,6 +15359,60 @@ var Paging = class Paging extends Feature {
15112
15359
  this.setResultsPerPage();
15113
15360
  }
15114
15361
  }
15362
+ let targetEl = !this.tgtId ? tf.feature("toolbar").container(this.toolbarPosition) : elm(this.tgtId);
15363
+ if (typeof customElements !== "undefined" && customElements.get("tf-pager") && !tf.enableIcons && !this.hasBtnHtml()) this.initCE(targetEl);
15364
+ else this.initLegacy(targetEl);
15365
+ this.setPagingInfo();
15366
+ if (!tf.fltGrid) {
15367
+ tf.validateAllRows();
15368
+ this.setPagingInfo(tf.validRowsIndex);
15369
+ }
15370
+ this.emitter.on(["after-filtering"], bound(this.resetPagingInfo, this));
15371
+ this.emitter.on(["change-page"], bound(this.changePageHandler, this));
15372
+ this.emitter.on(["change-page-results"], bound(this.changePageResultsHandler, this));
15373
+ /** @inherited */
15374
+ this.initialized = true;
15375
+ this.emitter.emit("feature-initialized", this);
15376
+ }
15377
+ /**
15378
+ * Initialize using the <tf-pager> custom element
15379
+ * @param {DOMElement} targetEl Target container element
15380
+ * @private
15381
+ */
15382
+ initCE(targetEl) {
15383
+ let evt = this.evt;
15384
+ let tf = this.tf;
15385
+ let pagerEl = document.createElement("tf-pager");
15386
+ pagerEl.className = this.pgCssClass();
15387
+ pagerEl.setAttribute("selector-type", this.pageSelectorType);
15388
+ pagerEl.setAttribute("page-text", this.pageText);
15389
+ pagerEl.setAttribute("of-text", this.ofText);
15390
+ if (!this.hasBtns) pagerEl.setAttribute("buttons", "false");
15391
+ this.setPagerButtons(pagerEl);
15392
+ if (!this.isEnabled()) pagerEl.setAttribute("disabled", "");
15393
+ targetEl.appendChild(pagerEl);
15394
+ this.pagerEl = pagerEl;
15395
+ this.pageSlc = pagerEl.shadowRoot.querySelector(this.pageSelectorType === "input" ? "[part=\"page-input\"]" : "[part=\"page-select\"]");
15396
+ this.bindPagerButton("first", evt.first);
15397
+ this.bindPagerButton("prev", evt.prev);
15398
+ this.bindPagerButton("next", evt.next);
15399
+ this.bindPagerButton("last", evt.last);
15400
+ evt.pagerPageChange = (event) => {
15401
+ let page = parseInt(event.detail.page, 10);
15402
+ if (isNaN(page)) return;
15403
+ if (this.pageSelectorType === "input" && tf.sorted) tf.filter();
15404
+ this.changePage(page - 1);
15405
+ };
15406
+ addEvt(pagerEl, "page-change", evt.pagerPageChange);
15407
+ }
15408
+ /**
15409
+ * Initialize using the legacy spans, controls and select
15410
+ * @param {DOMElement} targetEl Target container element
15411
+ * @private
15412
+ */
15413
+ initLegacy(targetEl) {
15414
+ let slcPages;
15415
+ let evt = this.evt;
15115
15416
  evt.slcPagesChange = (event) => {
15116
15417
  let slc = event.target;
15117
15418
  this.changePage(slc.selectedIndex);
@@ -15168,7 +15469,6 @@ var Paging = class Paging extends Feature {
15168
15469
  addEvt(btnFirstSpan, "click", evt.first);
15169
15470
  }
15170
15471
  }
15171
- let targetEl = !this.tgtId ? tf.feature("toolbar").container(this.toolbarPosition) : elm(this.tgtId);
15172
15472
  targetEl.appendChild(btnFirstSpan);
15173
15473
  targetEl.appendChild(btnPrevSpan);
15174
15474
  let pgBeforeSpan = createElm("span");
@@ -15194,17 +15494,87 @@ var Paging = class Paging extends Feature {
15194
15494
  this.pgBefore = pgBeforeSpan;
15195
15495
  this.pgAfter = pgAfterSpan;
15196
15496
  this.pageSlc = slcPages;
15197
- this.setPagingInfo();
15198
- if (!tf.fltGrid) {
15199
- tf.validateAllRows();
15200
- this.setPagingInfo(tf.validRowsIndex);
15201
- }
15202
- this.emitter.on(["after-filtering"], bound(this.resetPagingInfo, this));
15203
- this.emitter.on(["change-page"], bound(this.changePageHandler, this));
15204
- this.emitter.on(["change-page-results"], bound(this.changePageResultsHandler, this));
15205
- /** @inherited */
15206
- this.initialized = true;
15207
- this.emitter.emit("feature-initialized", this);
15497
+ }
15498
+ /**
15499
+ * The legacy paging classes, applied to the <tf-pager> host
15500
+ * @return {String} Space-separated class list
15501
+ * @private
15502
+ */
15503
+ pgCssClass() {
15504
+ return [
15505
+ this.btnCssClass,
15506
+ this.pgSlcCssClass,
15507
+ this.pgInpCssClass,
15508
+ this.nbPgSpanCssClass
15509
+ ].join(" ");
15510
+ }
15511
+ /**
15512
+ * Whether a `btn_*_page_html` value is set
15513
+ * @return {Boolean} True when any button HTML is configured
15514
+ * @private
15515
+ */
15516
+ hasBtnHtml() {
15517
+ return Boolean(this.btnFirstPageHtml || this.btnPrevPageHtml || this.btnNextPageHtml || this.btnLastPageHtml);
15518
+ }
15519
+ /**
15520
+ * Set the `btn_*_page_text` captions on the <tf-pager> buttons
15521
+ * (paging.js:390-444).
15522
+ * @param {DOMElement} pagerEl <tf-pager> host
15523
+ * @private
15524
+ */
15525
+ setPagerButtons(pagerEl) {
15526
+ [
15527
+ {
15528
+ part: "first",
15529
+ text: this.btnFirstPageText
15530
+ },
15531
+ {
15532
+ part: "prev",
15533
+ text: this.btnPrevPageText
15534
+ },
15535
+ {
15536
+ part: "next",
15537
+ text: this.btnNextPageText
15538
+ },
15539
+ {
15540
+ part: "last",
15541
+ text: this.btnLastPageText
15542
+ }
15543
+ ].forEach((btn) => {
15544
+ pagerEl.setAttribute(`${btn.part}-text`, btn.text);
15545
+ });
15546
+ }
15547
+ /**
15548
+ * Bind a paging handler to a <tf-pager> button
15549
+ * @param {String} part Button part name
15550
+ * @param {Function} handler Paging handler
15551
+ * @private
15552
+ */
15553
+ bindPagerButton(part, handler) {
15554
+ addEvt(this.pagerEl.shadowRoot.querySelector(`[part="${part}"]`), "click", handler);
15555
+ }
15556
+ /**
15557
+ * Remove a paging handler from a <tf-pager> button
15558
+ * @param {String} part Button part name
15559
+ * @param {Function} handler Paging handler
15560
+ * @private
15561
+ */
15562
+ unbindPagerButton(part, handler) {
15563
+ removeEvt(this.pagerEl.shadowRoot.querySelector(`[part="${part}"]`), "click", handler);
15564
+ }
15565
+ /**
15566
+ * Paging entries shared by the legacy select and <tf-pager>: page
15567
+ * number as visible text, start row as value
15568
+ * @return {Array<Object>} Page entries
15569
+ * @private
15570
+ */
15571
+ pageEntries() {
15572
+ let entries = [];
15573
+ for (let z = 0; z < this.nbPages; z++) entries.push({
15574
+ text: String(z + 1),
15575
+ value: String(z * this.pageLength)
15576
+ });
15577
+ return entries;
15208
15578
  }
15209
15579
  /**
15210
15580
  * Reset paging when filters are already instantiated
@@ -15233,15 +15603,22 @@ var Paging = class Paging extends Feature {
15233
15603
  let cont = !this.tgtId ? tf.feature("toolbar").container(this.toolbarPosition) : elm(this.tgtId);
15234
15604
  tf.validRowsIndex = validRows || tf.getValidRows(true);
15235
15605
  this.nbPages = Math.ceil(tf.validRowsIndex.length / this.pageLength);
15236
- this.pgCont.innerHTML = this.nbPages;
15237
- if (this.pageSelectorType === "select") this.pageSlc.innerHTML = "";
15606
+ if (this.pagerEl) {
15607
+ this.pagerEl.setTotalPages(this.nbPages);
15608
+ this.pagerEl.setPages(this.pageEntries());
15609
+ this.pagerEl.setPage(this.currentPageNb);
15610
+ } else {
15611
+ this.pgCont.innerHTML = this.nbPages;
15612
+ if (this.pageSelectorType === "select") this.pageSlc.innerHTML = "";
15613
+ }
15238
15614
  if (this.nbPages > 0) {
15239
15615
  cont.style.visibility = "visible";
15240
- if (this.pageSelectorType === "select") for (let z = 0; z < this.nbPages; z++) {
15241
- let opt = createOpt(z + 1, z * this.pageLength, false);
15242
- this.pageSlc.options[z] = opt;
15616
+ if (!this.pagerEl) {
15617
+ if (this.pageSelectorType === "select") this.pageEntries().forEach((entry, z) => {
15618
+ this.pageSlc.options[z] = createOpt(entry.text, entry.value, false);
15619
+ });
15620
+ else this.pageSlc.value = this.currentPageNb;
15243
15621
  }
15244
- else this.pageSlc.value = this.currentPageNb;
15245
15622
  } else
15246
15623
  /*** if no results paging select and buttons are hidden ***/
15247
15624
  cont.style.visibility = "hidden";
@@ -15360,7 +15737,8 @@ var Paging = class Paging extends Feature {
15360
15737
  if (index >= 0 && index <= this.nbPages - 1) {
15361
15738
  this.onBeforeChangePage(this, index + 1);
15362
15739
  this.currentPageNb = parseInt(index, 10) + 1;
15363
- if (this.pageSelectorType === "select") this.pageSlc.options[index].selected = true;
15740
+ if (this.pagerEl) this.pagerEl.setPage(this.currentPageNb);
15741
+ else if (this.pageSelectorType === "select") this.pageSlc.options[index].selected = true;
15364
15742
  else this.pageSlc.value = this.currentPageNb;
15365
15743
  this.startPagingRow = this.pageSelectorType === "select" ? this.pageSlc.value : index * this.pageLength;
15366
15744
  this.groupByPage();
@@ -15392,7 +15770,8 @@ var Paging = class Paging extends Feature {
15392
15770
  if (!isNaN(this.pageLength)) {
15393
15771
  if (this.startPagingRow >= tf.nbFilterableRows) this.startPagingRow = tf.nbFilterableRows - this.pageLength;
15394
15772
  this.setPagingInfo();
15395
- if (pageSelectorType === "select") {
15773
+ if (this.pagerEl) this.pagerEl.setPage(Math.min(slcPagesSelIndex, this.nbPages - 1) + 1);
15774
+ else if (pageSelectorType === "select") {
15396
15775
  let slcIdx = pageSlc.options.length - 1 <= slcPagesSelIndex ? pageSlc.options.length - 1 : slcPagesSelIndex;
15397
15776
  pageSlc.options[slcIdx].selected = true;
15398
15777
  }
@@ -15433,10 +15812,53 @@ var Paging = class Paging extends Feature {
15433
15812
  this.changeResultsPerPage(pageLength);
15434
15813
  }
15435
15814
  /**
15815
+ * Disable paging and reflect the state on the pager element
15816
+ */
15817
+ disable() {
15818
+ super.disable();
15819
+ if (this.pagerEl) this.pagerEl.setAttribute("disabled", "");
15820
+ }
15821
+ /**
15822
+ * Enable paging and reflect the state on the pager element
15823
+ */
15824
+ enable() {
15825
+ super.enable();
15826
+ if (this.pagerEl) this.pagerEl.removeAttribute("disabled");
15827
+ }
15828
+ /**
15436
15829
  * Remove paging feature
15437
15830
  */
15438
15831
  destroy() {
15439
15832
  if (!this.initialized) return;
15833
+ if (this.pagerEl) this.destroyCE();
15834
+ else this.destroyLegacy();
15835
+ if (this.hasResultsPerPage) this.removeResultsPerPage();
15836
+ this.emitter.off(["after-filtering"], bound(this.resetPagingInfo, this));
15837
+ this.emitter.off(["change-page"], bound(this.changePageHandler, this));
15838
+ this.emitter.off(["change-page-results"], bound(this.changePageResultsHandler, this));
15839
+ this.pageSlc = null;
15840
+ this.nbPages = 0;
15841
+ this.initialized = false;
15842
+ }
15843
+ /**
15844
+ * Remove the <tf-pager> element and the handlers bound to it
15845
+ * @private
15846
+ */
15847
+ destroyCE() {
15848
+ let evt = this.evt;
15849
+ removeEvt(this.pagerEl, "page-change", evt.pagerPageChange);
15850
+ this.unbindPagerButton("first", evt.first);
15851
+ this.unbindPagerButton("prev", evt.prev);
15852
+ this.unbindPagerButton("next", evt.next);
15853
+ this.unbindPagerButton("last", evt.last);
15854
+ removeElm(this.pagerEl);
15855
+ this.pagerEl = null;
15856
+ }
15857
+ /**
15858
+ * Remove the legacy paging controls and the handlers bound to them
15859
+ * @private
15860
+ */
15861
+ destroyLegacy() {
15440
15862
  let evt = this.evt;
15441
15863
  if (this.pageSlc) {
15442
15864
  if (this.pageSelectorType === "select") removeEvt(this.pageSlc, "change", evt.slcPagesChange);
@@ -15475,13 +15897,6 @@ var Paging = class Paging extends Feature {
15475
15897
  removeElm(this.pgCont);
15476
15898
  this.pgCont = null;
15477
15899
  }
15478
- if (this.hasResultsPerPage) this.removeResultsPerPage();
15479
- this.emitter.off(["after-filtering"], bound(this.resetPagingInfo, this));
15480
- this.emitter.off(["change-page"], bound(this.changePageHandler, this));
15481
- this.emitter.off(["change-page-results"], bound(this.changePageResultsHandler, this));
15482
- this.pageSlc = null;
15483
- this.nbPages = 0;
15484
- this.initialized = false;
15485
15900
  }
15486
15901
  };
15487
15902
  //#endregion
@@ -15544,7 +15959,7 @@ var TableFilter = class {
15544
15959
  * Current version
15545
15960
  * @type {String}
15546
15961
  */
15547
- this.version = "0.7.6";
15962
+ this.version = "0.7.8";
15548
15963
  /**
15549
15964
  * Current year
15550
15965
  * @type {Number}