@optionfactory/fml 9.0.0-rc31 → 9.0.0-rc33
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/dist/custom-elements.json +7 -0
- package/dist/fml.css +1 -1
- package/dist/fml.css.map +1 -1
- package/dist/fml.iife.js +683 -28
- package/dist/fml.iife.js.map +1 -1
- package/dist/fml.iife.min.js +1 -1
- package/dist/fml.iife.min.js.map +1 -1
- package/dist/ful.css +1 -1
- package/dist/ful.css.map +1 -1
- package/dist/ful.d.mts +68 -0
- package/dist/ful.iife.js +683 -28
- package/dist/ful.iife.js.map +1 -1
- package/dist/ful.iife.min.js +1 -1
- package/dist/ful.iife.min.js.map +1 -1
- package/dist/ful.min.mjs +1 -1
- package/dist/ful.min.mjs.map +1 -1
- package/dist/ful.mjs +683 -28
- package/dist/ful.mjs.map +1 -1
- package/dist/vscode.html-custom-data.json +4 -0
- package/dist/web-types.json +9 -1
- package/package.json +1 -1
package/dist/ful.mjs
CHANGED
|
@@ -4928,6 +4928,10 @@ class Checkbox extends Field {
|
|
|
4928
4928
|
* @typedef {{ data: any[], size: number }} TablePageResponse the rows of the
|
|
4929
4929
|
* requested page and the total number of rows across every page
|
|
4930
4930
|
*/
|
|
4931
|
+
/**
|
|
4932
|
+
* @typedef {{ count: Element, appending: Element, failure: Element, error: Element }} TableStatus the pieces
|
|
4933
|
+
* of the status bar `paging="infinite"` and `paging="virtual"` show in place of the pager
|
|
4934
|
+
*/
|
|
4931
4935
|
/**
|
|
4932
4936
|
* @typedef {{ load(pageRequest: TablePageRequest, sortRequest: TableSortRequest|null, filterRequest: Record<string, any>): Promise<TablePageResponse> }} TableRowLoader
|
|
4933
4937
|
*/
|
|
@@ -5400,6 +5404,21 @@ class TableLoader {
|
|
|
5400
5404
|
* for it. Without it the table shows an initial panel until `load`,
|
|
5401
5405
|
* `reload` or `resetWithFilter` is called.
|
|
5402
5406
|
*
|
|
5407
|
+
* `paging="infinite"`, read once at the upgrade, replaces the pager with a
|
|
5408
|
+
* status bar saying how many rows of how many are shown, with a reload
|
|
5409
|
+
* button. A load still replaces the rows with one page, scrolling the rows
|
|
5410
|
+
* back to the top; from then on, whenever a row of the last half page
|
|
5411
|
+
* comes into view, the next page is asked with the same size, sort and
|
|
5412
|
+
* filters and appended (see `load`). `reload`, a sort, a filter submit and a
|
|
5413
|
+
* size change start over from the first page.
|
|
5414
|
+
*
|
|
5415
|
+
* `paging="virtual"` shows the same status bar, saying which rows of how many
|
|
5416
|
+
* are in view, and keeps in the page only the page in view and one on either
|
|
5417
|
+
* side of it, the others standing in as empty space sized on the height of
|
|
5418
|
+
* the rows. The rows must scroll inside the table, as `ful-fill` makes them:
|
|
5419
|
+
* a table whose rows the page scrolls appends as `paging="infinite"` does,
|
|
5420
|
+
* and warns. See `load` and `reload`.
|
|
5421
|
+
*
|
|
5403
5422
|
* Inside the table, and not inside a `ful-table` nested in it, a
|
|
5404
5423
|
* `page:requested` loads that page with the current size,
|
|
5405
5424
|
* sort and filters; a `sort:requested` loads the current page with the new
|
|
@@ -5415,13 +5434,14 @@ class TableLoader {
|
|
|
5415
5434
|
*/
|
|
5416
5435
|
class Table extends ParsedElement {
|
|
5417
5436
|
/** Read once at the upgrade. */
|
|
5418
|
-
static attributes = ['loader', 'autoload:presence'];
|
|
5437
|
+
static attributes = ['loader', 'autoload:presence', 'paging'];
|
|
5419
5438
|
/** These stay live after the upgrade: see `pageSize`, `src` and `method`. */
|
|
5420
5439
|
static observed = ['page-size:number', 'src', 'method'];
|
|
5421
5440
|
static slots = true;
|
|
5422
5441
|
static config = {
|
|
5423
5442
|
searchIcon: 'search',
|
|
5424
5443
|
emptyIcon: 'inbox',
|
|
5444
|
+
reloadIcon: 'arrow-clockwise',
|
|
5425
5445
|
};
|
|
5426
5446
|
static template = `
|
|
5427
5447
|
<ful-form data-tpl-if="slots.filters">
|
|
@@ -5431,7 +5451,9 @@ class Table extends ParsedElement {
|
|
|
5431
5451
|
<table>
|
|
5432
5452
|
<caption data-tpl-if="slots.caption">{{{{ slots.caption }}}}</caption>
|
|
5433
5453
|
<thead></thead>
|
|
5454
|
+
<tbody data-tpl-if="virtual" data-ref="before" aria-hidden="true"><tr><td data-tpl-colspan="schema.length"></td></tr></tbody>
|
|
5434
5455
|
<tbody></tbody>
|
|
5456
|
+
<tbody data-tpl-if="virtual" data-ref="after" aria-hidden="true"><tr><td data-tpl-colspan="schema.length"></td></tr></tbody>
|
|
5435
5457
|
<tbody data-ref="initial">
|
|
5436
5458
|
<tr>
|
|
5437
5459
|
<td data-tpl-colspan="schema.length">
|
|
@@ -5475,7 +5497,16 @@ class Table extends ParsedElement {
|
|
|
5475
5497
|
</tfoot>
|
|
5476
5498
|
</table>
|
|
5477
5499
|
</ful-table-wrapper>
|
|
5478
|
-
<ful-pagination current="0" total="1"></ful-pagination>
|
|
5500
|
+
<ful-pagination data-tpl-if="!scrolled" current="0" total="1"></ful-pagination>
|
|
5501
|
+
<ful-table-status data-tpl-if="scrolled">
|
|
5502
|
+
<span data-ref="count"></span>
|
|
5503
|
+
<ful-spinner data-ref="appending" role="status" hidden><span class="ful-sr-only">{{ #l10n:t('spinner.loading') }}</span></ful-spinner>
|
|
5504
|
+
<div data-ref="append-failure" role="alert" hidden>
|
|
5505
|
+
<span>{{ #l10n:t('table.error') }} <span data-ref="append-error"></span></span>
|
|
5506
|
+
<button type="button" data-ref="retry">{{ #l10n:t('table.retry') }}</button>
|
|
5507
|
+
</div>
|
|
5508
|
+
<button type="button" data-ref="reload" data-tpl-aria-label="#l10n:t('pagination.reload')"><ful-icon data-tpl-name="config.reloadIcon" aria-hidden="true"></ful-icon></button>
|
|
5509
|
+
</ful-table-status>
|
|
5479
5510
|
`;
|
|
5480
5511
|
static templates = {
|
|
5481
5512
|
row: `
|
|
@@ -5493,6 +5524,31 @@ class Table extends ParsedElement {
|
|
|
5493
5524
|
#feedback;
|
|
5494
5525
|
#paginator;
|
|
5495
5526
|
#sorters;
|
|
5527
|
+
#wrapper;
|
|
5528
|
+
/** @type {TableStatus|null} null under the pager */
|
|
5529
|
+
#status = null;
|
|
5530
|
+
/** @type {IntersectionObserver|null} */
|
|
5531
|
+
#endWatch = null;
|
|
5532
|
+
/** @type {Element[]} the rows whose coming into view appends the next page, none while no append is awaited */
|
|
5533
|
+
#watched = [];
|
|
5534
|
+
/** the page the next append asks for, the rows shown, the total the last answer reported and the rows it carried */
|
|
5535
|
+
#appended = { next: 1, shown: 0, total: 0, last: 0 };
|
|
5536
|
+
/** whether the table keeps a window of pages, `paging="virtual"` over rows that scroll inside it */
|
|
5537
|
+
#virtual = false;
|
|
5538
|
+
/** @type {{ before: HTMLElement, after: HTMLElement } | null} the cells standing in for the rows above and below the window */
|
|
5539
|
+
#spacers = null;
|
|
5540
|
+
/** @type {{ first: number, last: number, pages: Map<number, Element[]> } | null} the pages in the page, in order, null while no rows show */
|
|
5541
|
+
#window = null;
|
|
5542
|
+
/** the total number of rows the last answer reported */
|
|
5543
|
+
#total = 0;
|
|
5544
|
+
/** the height of a row the spacers are sized on, measured on the first rows a load shows; 0 until measured */
|
|
5545
|
+
#rowHeight = 0;
|
|
5546
|
+
/** @type {{ readonly stale: boolean } | null} the claim of the window shift in flight */
|
|
5547
|
+
#shifting = null;
|
|
5548
|
+
/** whether the last window shift failed: scrolling asks for nothing more until a retry or a load */
|
|
5549
|
+
#windowFailed = false;
|
|
5550
|
+
/** @type {ReturnType<typeof setTimeout>|undefined} */
|
|
5551
|
+
#jump = undefined;
|
|
5496
5552
|
/** @type {{ pageRequest: { page: number, size: number }, sortRequest: any, filterRequest: any }} */
|
|
5497
5553
|
#latestRequest = { pageRequest: { page: 0, size: 10 }, sortRequest: null, filterRequest: {} };
|
|
5498
5554
|
/** whether a load has been asked for, by autoload or by a caller */
|
|
@@ -5620,6 +5676,7 @@ class Table extends ParsedElement {
|
|
|
5620
5676
|
}
|
|
5621
5677
|
this.#buildLoader();
|
|
5622
5678
|
this.#latestRequest = { ...this.#latestRequest, pageRequest: { ...this.#latestRequest.pageRequest, page: 0 } };
|
|
5679
|
+
this.#window = null;
|
|
5623
5680
|
return true;
|
|
5624
5681
|
}
|
|
5625
5682
|
/**
|
|
@@ -5630,14 +5687,24 @@ class Table extends ParsedElement {
|
|
|
5630
5687
|
async render({ slots }) {
|
|
5631
5688
|
const template = this.template();
|
|
5632
5689
|
const schema = TableSchemaParser.parse(slots.schema, template);
|
|
5633
|
-
const
|
|
5690
|
+
const paging = this.declared('paging');
|
|
5691
|
+
const fragment = template
|
|
5692
|
+
.withOverlay({
|
|
5693
|
+
slots,
|
|
5694
|
+
schema,
|
|
5695
|
+
scrolled: paging === 'infinite' || paging === 'virtual',
|
|
5696
|
+
virtual: paging === 'virtual',
|
|
5697
|
+
})
|
|
5698
|
+
.render();
|
|
5634
5699
|
const tableWrapper = /** @type HTMLTableElement */ (Nodes.queryChildren(fragment, 'ful-table-wrapper'));
|
|
5635
5700
|
const table = /** @type HTMLTableElement */ (tableWrapper.querySelector('table'));
|
|
5636
5701
|
Attributes.forward('table-', this, table);
|
|
5637
5702
|
this.#buildLoader();
|
|
5638
5703
|
|
|
5704
|
+
this.#wrapper = tableWrapper;
|
|
5705
|
+
const status = Nodes.queryChildren(fragment, 'ful-table-status');
|
|
5639
5706
|
this.#schema = schema;
|
|
5640
|
-
this.#body = table.querySelector(':scope > tbody');
|
|
5707
|
+
this.#body = table.querySelector(':scope > tbody:not([data-ref])');
|
|
5641
5708
|
this.#loading = table.querySelector(':scope > tbody[data-ref=loading]');
|
|
5642
5709
|
this.#noAutoload = table.querySelector(':scope > tbody[data-ref=initial]');
|
|
5643
5710
|
this.#empty = table.querySelector(':scope > tbody[data-ref=empty]');
|
|
@@ -5647,6 +5714,63 @@ class Table extends ParsedElement {
|
|
|
5647
5714
|
this.#feedback = table.querySelector(':scope > tbody[data-ref=feedback]');
|
|
5648
5715
|
this.#paginator = Nodes.queryChildren(fragment, 'ful-pagination');
|
|
5649
5716
|
this.replaceChildren(fragment);
|
|
5717
|
+
if (paging === 'virtual') {
|
|
5718
|
+
const overflow = getComputedStyle(tableWrapper).overflowY;
|
|
5719
|
+
this.#virtual = overflow === 'auto' || overflow === 'scroll';
|
|
5720
|
+
if (!this.#virtual) {
|
|
5721
|
+
console.warn(
|
|
5722
|
+
'ful-table: paging="virtual" needs rows that scroll inside the table, as ful-fill makes them; this one appends its pages as paging="infinite" does',
|
|
5723
|
+
);
|
|
5724
|
+
}
|
|
5725
|
+
}
|
|
5726
|
+
if (status) {
|
|
5727
|
+
const piece = (/** @type string */ ref) =>
|
|
5728
|
+
/** @type Element */ (status.querySelector(`[data-ref=${ref}]`));
|
|
5729
|
+
this.#status = {
|
|
5730
|
+
count: piece('count'),
|
|
5731
|
+
appending: piece('appending'),
|
|
5732
|
+
failure: piece('append-failure'),
|
|
5733
|
+
error: piece('append-error'),
|
|
5734
|
+
};
|
|
5735
|
+
piece('reload').addEventListener('click', () => this.reload());
|
|
5736
|
+
piece('retry').addEventListener('click', () => {
|
|
5737
|
+
if (!this.#virtual) {
|
|
5738
|
+
this.#appendNext();
|
|
5739
|
+
return;
|
|
5740
|
+
}
|
|
5741
|
+
this.#windowFailed = false;
|
|
5742
|
+
this.#reconcile(true);
|
|
5743
|
+
});
|
|
5744
|
+
}
|
|
5745
|
+
if (this.#virtual) {
|
|
5746
|
+
this.#spacers = {
|
|
5747
|
+
before: /** @type HTMLElement */ (table.querySelector(':scope > tbody[data-ref=before] td')),
|
|
5748
|
+
after: /** @type HTMLElement */ (table.querySelector(':scope > tbody[data-ref=after] td')),
|
|
5749
|
+
};
|
|
5750
|
+
// scroll fires once per frame at most, so it needs no throttle of its own
|
|
5751
|
+
tableWrapper.addEventListener(
|
|
5752
|
+
'scroll',
|
|
5753
|
+
() => {
|
|
5754
|
+
this.#countInView();
|
|
5755
|
+
this.#reconcile(false);
|
|
5756
|
+
},
|
|
5757
|
+
{ passive: true },
|
|
5758
|
+
);
|
|
5759
|
+
// a table that loaded while it was not laid out, in a tab not yet shown for one, has
|
|
5760
|
+
// measured nothing: with a first page shorter than its panel no scroll would ever come
|
|
5761
|
+
// to do it. Its box changing size is the moment it is laid out, or shows more rows.
|
|
5762
|
+
new ResizeObserver(() => {
|
|
5763
|
+
this.#countInView();
|
|
5764
|
+
this.#reconcile(false);
|
|
5765
|
+
}).observe(tableWrapper);
|
|
5766
|
+
} else if (status) {
|
|
5767
|
+
this.#endWatch = new IntersectionObserver((entries) => {
|
|
5768
|
+
// an entry queued before the watch moved on to another row, or stopped, asks for nothing
|
|
5769
|
+
if (entries.some((e) => e.isIntersecting && this.#watched.includes(e.target))) {
|
|
5770
|
+
this.#appendNext();
|
|
5771
|
+
}
|
|
5772
|
+
});
|
|
5773
|
+
}
|
|
5650
5774
|
const thead = /** @type HTMLTableSectionElement */ (this.querySelector('thead'));
|
|
5651
5775
|
schema.headersTemplate.renderTo(thead);
|
|
5652
5776
|
this.#sorters = thead.querySelectorAll('ful-sorter');
|
|
@@ -5703,6 +5827,14 @@ class Table extends ParsedElement {
|
|
|
5703
5827
|
* `submit` listeners as the later ones, and the load its `submit:success`
|
|
5704
5828
|
* starts is the one awaited. A filter submit that is cancelled, fails or
|
|
5705
5829
|
* is dropped for one in flight loads nothing, and the promise resolves.
|
|
5830
|
+
*
|
|
5831
|
+
* Under `paging="virtual"`, once rows show, it asks again for the pages in
|
|
5832
|
+
* the page, with the same size, sort and filters, and shows them where
|
|
5833
|
+
* they are, the scroll position and the widths of the columns kept; the
|
|
5834
|
+
* table is busy and settles, fails and dispatches as a load does, one
|
|
5835
|
+
* `load:success` per page. When the answers report fewer rows than the
|
|
5836
|
+
* window starts at, it loads the first page instead. A `src` or `method`
|
|
5837
|
+
* write still starts over from the first page.
|
|
5706
5838
|
* @returns {Promise<void>} as `load`
|
|
5707
5839
|
*/
|
|
5708
5840
|
async reload() {
|
|
@@ -5712,6 +5844,9 @@ class Table extends ParsedElement {
|
|
|
5712
5844
|
}
|
|
5713
5845
|
return;
|
|
5714
5846
|
}
|
|
5847
|
+
if (this.#window) {
|
|
5848
|
+
return await this.#reloadWindow();
|
|
5849
|
+
}
|
|
5715
5850
|
return await this.load(
|
|
5716
5851
|
this.#latestRequest.pageRequest,
|
|
5717
5852
|
this.#latestRequest.sortRequest,
|
|
@@ -5750,6 +5885,40 @@ class Table extends ParsedElement {
|
|
|
5750
5885
|
* failure arrives it changes nothing, dispatches nothing and resolves;
|
|
5751
5886
|
* superseded while its rows render, it leaves them to the newer load and
|
|
5752
5887
|
* dispatches nothing.
|
|
5888
|
+
*
|
|
5889
|
+
* Under `paging="infinite"` the status bar takes the pager's place, and
|
|
5890
|
+
* once the load has dispatched `load:success` the next page is awaited:
|
|
5891
|
+
* when a row of the last half page comes into view, through
|
|
5892
|
+
* whatever scrolls it, the following page is asked for with the same
|
|
5893
|
+
* size, sort and filters and its rows are appended. An append runs
|
|
5894
|
+
* without `aria-busy`, a spinner in the status bar standing in, and
|
|
5895
|
+
* dispatches `load:success` or `load:failure` as a load does, its
|
|
5896
|
+
* `pageRequest` naming the appended page. A failed append keeps the
|
|
5897
|
+
* rows, shows the error in the status bar with a retry button and
|
|
5898
|
+
* rejects to nobody, nothing awaiting it. Appending stops once the rows
|
|
5899
|
+
* shown reach the total the last answer reported, or an answer carries
|
|
5900
|
+
* no rows. A load supersedes an append in flight; `reload` repeats this
|
|
5901
|
+
* load, not the pages appended to it.
|
|
5902
|
+
*
|
|
5903
|
+
* Under `paging="virtual"` the load shows its page as the window, scrolled
|
|
5904
|
+
* to where it sits among the total, and measures two things on its rows:
|
|
5905
|
+
* the height the empty space standing in for the other rows is sized on,
|
|
5906
|
+
* and the width of the columns, which then stay as they are, in
|
|
5907
|
+
* proportion, until the next load, so that the pages coming and going do
|
|
5908
|
+
* not move them. From then on the window follows the scroll: the page in
|
|
5909
|
+
* view and one on either side stay in the page and the others are dropped,
|
|
5910
|
+
* the page holding the focus kept while it is within two pages of them. A
|
|
5911
|
+
* page next to the window is asked for at once; a scroll landing farther
|
|
5912
|
+
* waits for the scroll to rest. Window pages are asked for without
|
|
5913
|
+
* `aria-busy`, a spinner in the status bar standing in, and dispatch
|
|
5914
|
+
* `load:success` or `load:failure` per page as appends do; a failure keeps
|
|
5915
|
+
* the rows and offers a retry. The row in view stays where it is as pages
|
|
5916
|
+
* come and go above it: the table measures it before and after and
|
|
5917
|
+
* corrects the scroll by whatever the browser's own scroll anchoring has
|
|
5918
|
+
* not kept, which is all of it where the browser anchors no table rows
|
|
5919
|
+
* (Firefox), has no scroll anchoring or the rows' container declares
|
|
5920
|
+
* `overflow-anchor: none`, and nothing where it has. The table carries
|
|
5921
|
+
* `aria-rowcount` and each row its `aria-rowindex`.
|
|
5753
5922
|
* @param {TablePageRequest} pageRequest
|
|
5754
5923
|
* @param {TableSortRequest|null} sortRequest
|
|
5755
5924
|
* @param {Record<string, any>} filterRequest
|
|
@@ -5760,6 +5929,13 @@ class Table extends ParsedElement {
|
|
|
5760
5929
|
this.#loadRequested = true;
|
|
5761
5930
|
this.#requestedFilters = filterRequest;
|
|
5762
5931
|
const claim = this.#loads.take();
|
|
5932
|
+
this.#watched = [];
|
|
5933
|
+
this.#endWatch?.disconnect();
|
|
5934
|
+
clearTimeout(this.#jump);
|
|
5935
|
+
this.#shifting = null;
|
|
5936
|
+
this.#windowFailed = false;
|
|
5937
|
+
this.#status?.appending.setAttribute('hidden', '');
|
|
5938
|
+
this.#status?.failure.setAttribute('hidden', '');
|
|
5763
5939
|
this.#loading.toggleAttribute('hidden', this.#body.childElementCount > 0);
|
|
5764
5940
|
this.#feedback.setAttribute('hidden', '');
|
|
5765
5941
|
this.#noAutoload.setAttribute('hidden', '');
|
|
@@ -5789,6 +5965,9 @@ class Table extends ParsedElement {
|
|
|
5789
5965
|
if (claim.stale) {
|
|
5790
5966
|
return;
|
|
5791
5967
|
}
|
|
5968
|
+
if (this.#virtual) {
|
|
5969
|
+
this.#settleWindow();
|
|
5970
|
+
}
|
|
5792
5971
|
this.removeAttribute('aria-busy');
|
|
5793
5972
|
this.dispatchEvent(
|
|
5794
5973
|
new CustomEvent('load:success', {
|
|
@@ -5797,24 +5976,15 @@ class Table extends ParsedElement {
|
|
|
5797
5976
|
detail: { pageRequest, sortRequest, filterRequest, response: pageResponse },
|
|
5798
5977
|
}),
|
|
5799
5978
|
);
|
|
5979
|
+
this.#watchEnd(pageRequest.size);
|
|
5980
|
+
this.#reconcile(false);
|
|
5800
5981
|
return;
|
|
5801
5982
|
}
|
|
5802
5983
|
} catch (/** @type any */ error) {
|
|
5803
5984
|
if (claim.stale) {
|
|
5804
5985
|
return;
|
|
5805
5986
|
}
|
|
5806
|
-
this.#
|
|
5807
|
-
this.#body.replaceChildren();
|
|
5808
|
-
this.#feedback.removeAttribute('hidden');
|
|
5809
|
-
this.#feedback.querySelector('[data-ref=feedback-error]').textContent = Localization.of().failure(error);
|
|
5810
|
-
this.removeAttribute('aria-busy');
|
|
5811
|
-
this.dispatchEvent(
|
|
5812
|
-
new CustomEvent('load:failure', {
|
|
5813
|
-
bubbles: true,
|
|
5814
|
-
cancelable: false,
|
|
5815
|
-
detail: { pageRequest, sortRequest, filterRequest, exception: error },
|
|
5816
|
-
}),
|
|
5817
|
-
);
|
|
5987
|
+
this.#fail(error, { pageRequest, sortRequest, filterRequest });
|
|
5818
5988
|
throw error;
|
|
5819
5989
|
}
|
|
5820
5990
|
return await this.load({ page: lastPage, size: pageRequest.size }, sortRequest, filterRequest);
|
|
@@ -5845,19 +6015,471 @@ class Table extends ParsedElement {
|
|
|
5845
6015
|
filterRequest,
|
|
5846
6016
|
);
|
|
5847
6017
|
}
|
|
5848
|
-
|
|
5849
|
-
|
|
6018
|
+
/**
|
|
6019
|
+
* Watches the last half page of rows, so that any of them coming into
|
|
6020
|
+
* view appends the next page, unless the rows shown already reach the
|
|
6021
|
+
* total or the last answer carried none. A single row would be missed by
|
|
6022
|
+
* a scroll jumping past it, to the end for instance.
|
|
6023
|
+
* @param {number} size the rows a page asks for
|
|
6024
|
+
*/
|
|
6025
|
+
#watchEnd(size) {
|
|
6026
|
+
const { shown, total, last } = this.#appended;
|
|
6027
|
+
if (!this.#endWatch || !(shown < total) || last === 0) {
|
|
6028
|
+
return;
|
|
6029
|
+
}
|
|
6030
|
+
const rows = [...this.#body.children];
|
|
6031
|
+
this.#watched = rows.slice(Math.max(0, rows.length - Math.ceil(size / 2)));
|
|
6032
|
+
for (const row of this.#watched) {
|
|
6033
|
+
this.#endWatch.observe(row);
|
|
6034
|
+
}
|
|
6035
|
+
}
|
|
6036
|
+
async #appendNext() {
|
|
6037
|
+
const status = /** @type TableStatus */ (this.#status);
|
|
6038
|
+
this.#watched = [];
|
|
6039
|
+
this.#endWatch?.disconnect();
|
|
6040
|
+
const { sortRequest, filterRequest } = this.#latestRequest;
|
|
6041
|
+
const pageRequest = { page: this.#appended.next, size: this.#latestRequest.pageRequest.size };
|
|
6042
|
+
const claim = this.#loads.take();
|
|
6043
|
+
status.failure.setAttribute('hidden', '');
|
|
6044
|
+
status.appending.removeAttribute('hidden');
|
|
6045
|
+
try {
|
|
6046
|
+
const pageResponse = await this.#loader.load(pageRequest, sortRequest, filterRequest);
|
|
6047
|
+
if (claim.stale) {
|
|
6048
|
+
return;
|
|
6049
|
+
}
|
|
6050
|
+
this.#body.append(
|
|
6051
|
+
this.template('row')
|
|
6052
|
+
.withOverlay({ schema: this.#schema, pageRequest, filterRequest, pageResponse })
|
|
6053
|
+
.render(),
|
|
6054
|
+
);
|
|
6055
|
+
this.#appended = {
|
|
6056
|
+
next: pageRequest.page + 1,
|
|
6057
|
+
shown: this.#appended.shown + pageResponse.data.length,
|
|
6058
|
+
total: pageResponse.size,
|
|
6059
|
+
last: pageResponse.data.length,
|
|
6060
|
+
};
|
|
6061
|
+
status.count.textContent = Localization.of().t('table.loaded', {
|
|
6062
|
+
loaded: this.#appended.shown,
|
|
6063
|
+
total: this.#appended.total,
|
|
6064
|
+
});
|
|
6065
|
+
await Rendering.waitForChildren(this.#body).catch(() => undefined);
|
|
6066
|
+
if (claim.stale) {
|
|
6067
|
+
return;
|
|
6068
|
+
}
|
|
6069
|
+
status.appending.setAttribute('hidden', '');
|
|
6070
|
+
this.dispatchEvent(
|
|
6071
|
+
new CustomEvent('load:success', {
|
|
6072
|
+
bubbles: true,
|
|
6073
|
+
cancelable: false,
|
|
6074
|
+
detail: { pageRequest, sortRequest, filterRequest, response: pageResponse },
|
|
6075
|
+
}),
|
|
6076
|
+
);
|
|
6077
|
+
this.#watchEnd(pageRequest.size);
|
|
6078
|
+
} catch (/** @type any */ error) {
|
|
6079
|
+
if (claim.stale) {
|
|
6080
|
+
return;
|
|
6081
|
+
}
|
|
6082
|
+
status.appending.setAttribute('hidden', '');
|
|
6083
|
+
status.error.textContent = Localization.of().failure(error);
|
|
6084
|
+
status.failure.removeAttribute('hidden');
|
|
6085
|
+
this.dispatchEvent(
|
|
6086
|
+
new CustomEvent('load:failure', {
|
|
6087
|
+
bubbles: true,
|
|
6088
|
+
cancelable: false,
|
|
6089
|
+
detail: { pageRequest, sortRequest, filterRequest, exception: error },
|
|
6090
|
+
}),
|
|
6091
|
+
);
|
|
6092
|
+
}
|
|
6093
|
+
}
|
|
6094
|
+
/**
|
|
6095
|
+
* Renders the rows of a page, numbering them with `aria-rowindex` under
|
|
6096
|
+
* `paging="virtual"`, the header row being the first.
|
|
6097
|
+
* @param {TablePageRequest} pageRequest
|
|
6098
|
+
* @param {Record<string, any>} filterRequest
|
|
6099
|
+
* @param {TablePageResponse} pageResponse
|
|
6100
|
+
* @returns {Element[]}
|
|
6101
|
+
*/
|
|
6102
|
+
#pageRows(pageRequest, filterRequest, pageResponse) {
|
|
6103
|
+
const rows = [
|
|
6104
|
+
...this.template('row')
|
|
6105
|
+
.withOverlay({ schema: this.#schema, pageRequest, filterRequest, pageResponse })
|
|
6106
|
+
.render().children,
|
|
6107
|
+
];
|
|
6108
|
+
if (this.#virtual) {
|
|
6109
|
+
rows.forEach((row, i) => {
|
|
6110
|
+
row.setAttribute('aria-rowindex', String(pageRequest.page * pageRequest.size + i + 2));
|
|
6111
|
+
});
|
|
6112
|
+
}
|
|
6113
|
+
return rows;
|
|
6114
|
+
}
|
|
6115
|
+
/**
|
|
6116
|
+
* Shows a failed load: the rows go, the error panel shows and
|
|
6117
|
+
* `load:failure` is dispatched.
|
|
6118
|
+
* @param {any} error
|
|
6119
|
+
* @param {{ pageRequest: TablePageRequest, sortRequest: TableSortRequest|null, filterRequest: Record<string, any> }} request
|
|
6120
|
+
*/
|
|
6121
|
+
#fail(error, request) {
|
|
5850
6122
|
this.#loading.setAttribute('hidden', '');
|
|
5851
|
-
this.#body.replaceChildren(
|
|
5852
|
-
|
|
5853
|
-
|
|
5854
|
-
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
6123
|
+
this.#body.replaceChildren();
|
|
6124
|
+
this.#window = null;
|
|
6125
|
+
this.#fitSpacers();
|
|
6126
|
+
this.#status?.count.replaceChildren();
|
|
6127
|
+
this.#feedback.removeAttribute('hidden');
|
|
6128
|
+
this.#feedback.querySelector('[data-ref=feedback-error]').textContent = Localization.of().failure(error);
|
|
6129
|
+
this.removeAttribute('aria-busy');
|
|
6130
|
+
this.dispatchEvent(
|
|
6131
|
+
new CustomEvent('load:failure', {
|
|
6132
|
+
bubbles: true,
|
|
6133
|
+
cancelable: false,
|
|
6134
|
+
detail: { ...request, exception: error },
|
|
6135
|
+
}),
|
|
5860
6136
|
);
|
|
6137
|
+
}
|
|
6138
|
+
/** Counts the rows of a load just shown and moves the window where its page sits. */
|
|
6139
|
+
#settleWindow() {
|
|
6140
|
+
const table = /** @type HTMLTableElement */ (this.#body.parentElement);
|
|
6141
|
+
table.setAttribute('aria-rowcount', String(this.#total + 1));
|
|
6142
|
+
table.tHead?.rows[0]?.setAttribute('aria-rowindex', '1');
|
|
6143
|
+
const status = /** @type TableStatus */ (this.#status);
|
|
6144
|
+
const window = this.#window;
|
|
6145
|
+
if (!window) {
|
|
6146
|
+
this.#fitSpacers();
|
|
6147
|
+
status.count.textContent = Localization.of().t('table.loaded', { loaded: 0, total: this.#total });
|
|
6148
|
+
return;
|
|
6149
|
+
}
|
|
6150
|
+
const size = this.#latestRequest.pageRequest.size;
|
|
6151
|
+
const from = window.first * size;
|
|
6152
|
+
status.count.textContent = Localization.of().t('table.range', {
|
|
6153
|
+
from: from + 1,
|
|
6154
|
+
to: from + /** @type Element[] */ (window.pages.get(window.first)).length,
|
|
6155
|
+
total: this.#total,
|
|
6156
|
+
});
|
|
6157
|
+
if (this.#measureRows()) {
|
|
6158
|
+
this.#wrapper.scrollTop = from * this.#rowHeight;
|
|
6159
|
+
}
|
|
6160
|
+
}
|
|
6161
|
+
/**
|
|
6162
|
+
* Measures the height of a row and locks the widths of the columns, once
|
|
6163
|
+
* per load, on the rows it shows, then sizes the spacers. A table that is not laid out, inside a
|
|
6164
|
+
* closed disclosure for instance, measures nothing and is measured when
|
|
6165
|
+
* it is laid out, or when its rows next scroll.
|
|
6166
|
+
* @returns {boolean} whether the rows are measured
|
|
6167
|
+
*/
|
|
6168
|
+
#measureRows() {
|
|
6169
|
+
if (this.#rowHeight > 0) {
|
|
6170
|
+
return true;
|
|
6171
|
+
}
|
|
6172
|
+
const count = this.#body.childElementCount;
|
|
6173
|
+
const height = this.#body.getBoundingClientRect().height;
|
|
6174
|
+
if (count === 0 || height === 0) {
|
|
6175
|
+
return false;
|
|
6176
|
+
}
|
|
6177
|
+
this.#rowHeight = height / count;
|
|
6178
|
+
this.#lockColumns();
|
|
6179
|
+
this.#fitSpacers();
|
|
6180
|
+
return true;
|
|
6181
|
+
}
|
|
6182
|
+
/**
|
|
6183
|
+
* Fixes the widths of the columns, in proportion to the table, at those
|
|
6184
|
+
* the rows in the page give them.
|
|
6185
|
+
*/
|
|
6186
|
+
#lockColumns() {
|
|
6187
|
+
const table = /** @type HTMLTableElement */ (this.#body.parentElement);
|
|
6188
|
+
const widths = [...(table.tHead?.rows[0]?.cells ?? [])].map((cell) => cell.getBoundingClientRect().width);
|
|
6189
|
+
const sum = widths.reduce((a, b) => a + b, 0);
|
|
6190
|
+
const columns = document.createElement('colgroup');
|
|
6191
|
+
columns.setAttribute('data-ref', 'widths');
|
|
6192
|
+
for (const width of widths) {
|
|
6193
|
+
const column = document.createElement('col');
|
|
6194
|
+
column.style.width = `${(width / sum) * 100}%`;
|
|
6195
|
+
columns.append(column);
|
|
6196
|
+
}
|
|
6197
|
+
table.insertBefore(columns, table.tHead);
|
|
6198
|
+
}
|
|
6199
|
+
#unlockColumns() {
|
|
6200
|
+
this.#body.parentElement?.querySelector(':scope > colgroup[data-ref=widths]')?.remove();
|
|
6201
|
+
}
|
|
6202
|
+
/** Sizes the space standing in for the rows above and below the window. */
|
|
6203
|
+
#fitSpacers() {
|
|
6204
|
+
if (!this.#spacers) {
|
|
6205
|
+
return;
|
|
6206
|
+
}
|
|
6207
|
+
const window = this.#window;
|
|
6208
|
+
const size = this.#latestRequest.pageRequest.size;
|
|
6209
|
+
const above = window ? window.first * size : 0;
|
|
6210
|
+
const below = window ? Math.max(0, this.#total - (window.last + 1) * size) : 0;
|
|
6211
|
+
this.#spacers.before.style.height = `${above * this.#rowHeight}px`;
|
|
6212
|
+
this.#spacers.after.style.height = `${below * this.#rowHeight}px`;
|
|
6213
|
+
}
|
|
6214
|
+
/** Says in the status bar which rows are in view; nothing changes while none is. */
|
|
6215
|
+
#countInView() {
|
|
6216
|
+
const status = /** @type TableStatus */ (this.#status);
|
|
6217
|
+
const size = this.#latestRequest.pageRequest.size;
|
|
6218
|
+
const view = this.#wrapper.getBoundingClientRect();
|
|
6219
|
+
const top = view.top + (this.#body.parentElement?.querySelector(':scope > thead')?.getBoundingClientRect().height ?? 0);
|
|
6220
|
+
let from = 0;
|
|
6221
|
+
let to = 0;
|
|
6222
|
+
for (const [page, rows] of this.#window?.pages ?? []) {
|
|
6223
|
+
rows.forEach((row, i) => {
|
|
6224
|
+
const rect = row.getBoundingClientRect();
|
|
6225
|
+
if (rect.bottom > top && rect.top < view.bottom) {
|
|
6226
|
+
from ||= page * size + i + 1;
|
|
6227
|
+
to = page * size + i + 1;
|
|
6228
|
+
}
|
|
6229
|
+
});
|
|
6230
|
+
}
|
|
6231
|
+
if (from > 0) {
|
|
6232
|
+
status.count.textContent = Localization.of().t('table.range', { from, to, total: this.#total });
|
|
6233
|
+
}
|
|
6234
|
+
}
|
|
6235
|
+
/**
|
|
6236
|
+
* The page at the middle of the view: found among the rows in the page,
|
|
6237
|
+
* or estimated on the height of a row when the middle falls in the space
|
|
6238
|
+
* standing in for others.
|
|
6239
|
+
* @param {{ first: number, last: number, pages: Map<number, Element[]> }} window
|
|
6240
|
+
* @returns {number}
|
|
6241
|
+
*/
|
|
6242
|
+
#pageInView(window) {
|
|
6243
|
+
const pageHeight = this.#latestRequest.pageRequest.size * this.#rowHeight;
|
|
6244
|
+
const view = this.#wrapper.getBoundingClientRect();
|
|
6245
|
+
const middle = view.top + view.height / 2;
|
|
6246
|
+
const rows = this.#body.getBoundingClientRect();
|
|
6247
|
+
if (middle < rows.top) {
|
|
6248
|
+
return Math.max(0, window.first - Math.ceil((rows.top - middle) / pageHeight));
|
|
6249
|
+
}
|
|
6250
|
+
if (middle >= rows.bottom) {
|
|
6251
|
+
return window.last + 1 + Math.floor((middle - rows.bottom) / pageHeight);
|
|
6252
|
+
}
|
|
6253
|
+
let found = window.first;
|
|
6254
|
+
for (const [page, pageRows] of window.pages) {
|
|
6255
|
+
if (pageRows.length > 0 && pageRows[0].getBoundingClientRect().top <= middle) {
|
|
6256
|
+
found = page;
|
|
6257
|
+
}
|
|
6258
|
+
}
|
|
6259
|
+
return found;
|
|
6260
|
+
}
|
|
6261
|
+
/**
|
|
6262
|
+
* Moves the window to the page in view and its neighbours. A window next
|
|
6263
|
+
* to the current one moves at once; one farther away waits for the scroll
|
|
6264
|
+
* to rest, unless `settled` says it has.
|
|
6265
|
+
* @param {boolean} settled
|
|
6266
|
+
*/
|
|
6267
|
+
#reconcile(settled) {
|
|
6268
|
+
const window = this.#window;
|
|
6269
|
+
const pageCount = Math.ceil(this.#total / this.#latestRequest.pageRequest.size);
|
|
6270
|
+
if (
|
|
6271
|
+
!window ||
|
|
6272
|
+
this.#shifting ||
|
|
6273
|
+
this.#windowFailed ||
|
|
6274
|
+
this.hasAttribute('aria-busy') ||
|
|
6275
|
+
!this.#wrapper.isConnected ||
|
|
6276
|
+
!(pageCount > 0) ||
|
|
6277
|
+
!this.#measureRows()
|
|
6278
|
+
) {
|
|
6279
|
+
return;
|
|
6280
|
+
}
|
|
6281
|
+
const target = Math.min(pageCount - 1, this.#pageInView(window));
|
|
6282
|
+
let first = Math.max(0, target - 1);
|
|
6283
|
+
let last = Math.min(pageCount - 1, target + 1);
|
|
6284
|
+
const focused = this.#body.contains(document.activeElement)
|
|
6285
|
+
? /** @type Element */ (document.activeElement).closest('tr')
|
|
6286
|
+
: null;
|
|
6287
|
+
const focusedPage = [...window.pages].find(([, rows]) => focused && rows.includes(focused))?.[0];
|
|
6288
|
+
if (focusedPage !== undefined && Math.max(last, focusedPage) - Math.min(first, focusedPage) <= 4) {
|
|
6289
|
+
first = Math.min(first, focusedPage);
|
|
6290
|
+
last = Math.max(last, focusedPage);
|
|
6291
|
+
}
|
|
6292
|
+
if (first === window.first && last === window.last) {
|
|
6293
|
+
return;
|
|
6294
|
+
}
|
|
6295
|
+
clearTimeout(this.#jump);
|
|
6296
|
+
if (!settled && (last < window.first - 1 || first > window.last + 1)) {
|
|
6297
|
+
this.#jump = setTimeout(() => this.#reconcile(true), 150);
|
|
6298
|
+
return;
|
|
6299
|
+
}
|
|
6300
|
+
this.#shiftWindow(window, first, last);
|
|
6301
|
+
}
|
|
6302
|
+
/**
|
|
6303
|
+
* Asks for the pages of the new window that are not in the page, drops
|
|
6304
|
+
* the ones outside it and keeps the row in view where it is.
|
|
6305
|
+
* @param {{ first: number, last: number, pages: Map<number, Element[]> }} window
|
|
6306
|
+
* @param {number} first
|
|
6307
|
+
* @param {number} last
|
|
6308
|
+
*/
|
|
6309
|
+
async #shiftWindow(window, first, last) {
|
|
6310
|
+
const status = /** @type TableStatus */ (this.#status);
|
|
6311
|
+
const claim = this.#loads.hold();
|
|
6312
|
+
this.#shifting = claim;
|
|
6313
|
+
const { sortRequest, filterRequest } = this.#latestRequest;
|
|
6314
|
+
const size = this.#latestRequest.pageRequest.size;
|
|
6315
|
+
const wanted = Array.from({ length: last - first + 1 }, (_, i) => first + i);
|
|
6316
|
+
const missing = wanted.filter((page) => !window.pages.has(page));
|
|
6317
|
+
status.failure.setAttribute('hidden', '');
|
|
6318
|
+
status.appending.removeAttribute('hidden');
|
|
6319
|
+
try {
|
|
6320
|
+
const answers = await Promise.all(
|
|
6321
|
+
missing.map(async (page) => {
|
|
6322
|
+
const pageRequest = { page, size };
|
|
6323
|
+
return { pageRequest, response: await this.#loader.load(pageRequest, sortRequest, filterRequest) };
|
|
6324
|
+
}),
|
|
6325
|
+
);
|
|
6326
|
+
if (claim.stale) {
|
|
6327
|
+
return;
|
|
6328
|
+
}
|
|
6329
|
+
const kept = wanted.filter((page) => window.pages.has(page));
|
|
6330
|
+
const top = this.#wrapper.getBoundingClientRect().top;
|
|
6331
|
+
const anchor = kept
|
|
6332
|
+
.flatMap((page) => window.pages.get(page) ?? [])
|
|
6333
|
+
.find((row) => row.getBoundingClientRect().bottom > top);
|
|
6334
|
+
const anchorTop = anchor?.getBoundingClientRect().top ?? 0;
|
|
6335
|
+
for (const [page, rows] of window.pages) {
|
|
6336
|
+
if (page < first || page > last) {
|
|
6337
|
+
for (const row of rows) {
|
|
6338
|
+
row.remove();
|
|
6339
|
+
}
|
|
6340
|
+
}
|
|
6341
|
+
}
|
|
6342
|
+
/** @type {Map<number, Element[]>} */
|
|
6343
|
+
const pages = new Map();
|
|
6344
|
+
for (const page of wanted) {
|
|
6345
|
+
const answer = answers.find((a) => a.pageRequest.page === page);
|
|
6346
|
+
pages.set(
|
|
6347
|
+
page,
|
|
6348
|
+
window.pages.get(page) ??
|
|
6349
|
+
(answer ? this.#pageRows(answer.pageRequest, filterRequest, answer.response) : []),
|
|
6350
|
+
);
|
|
6351
|
+
}
|
|
6352
|
+
if (kept.length === 0) {
|
|
6353
|
+
this.#body.replaceChildren(...[...pages.values()].flat());
|
|
6354
|
+
} else {
|
|
6355
|
+
this.#body.prepend(...wanted.filter((page) => page < kept[0]).flatMap((page) => pages.get(page) ?? []));
|
|
6356
|
+
this.#body.append(
|
|
6357
|
+
...wanted.filter((page) => page > /** @type number */ (kept.at(-1))).flatMap((page) => pages.get(page) ?? []),
|
|
6358
|
+
);
|
|
6359
|
+
}
|
|
6360
|
+
this.#window = { first, last, pages };
|
|
6361
|
+
this.#total = answers.at(-1)?.response.size ?? this.#total;
|
|
6362
|
+
this.#body.parentElement?.setAttribute('aria-rowcount', String(this.#total + 1));
|
|
6363
|
+
this.#fitSpacers();
|
|
6364
|
+
if (anchor) {
|
|
6365
|
+
this.#wrapper.scrollTop += anchor.getBoundingClientRect().top - anchorTop;
|
|
6366
|
+
}
|
|
6367
|
+
await Rendering.waitForChildren(this.#body).catch(() => undefined);
|
|
6368
|
+
if (claim.stale) {
|
|
6369
|
+
return;
|
|
6370
|
+
}
|
|
6371
|
+
if (anchor) {
|
|
6372
|
+
// the elements in the new rows have rendered since, which can change their height
|
|
6373
|
+
this.#wrapper.scrollTop += anchor.getBoundingClientRect().top - anchorTop;
|
|
6374
|
+
}
|
|
6375
|
+
status.appending.setAttribute('hidden', '');
|
|
6376
|
+
this.#countInView();
|
|
6377
|
+
for (const { pageRequest, response } of answers) {
|
|
6378
|
+
this.dispatchEvent(
|
|
6379
|
+
new CustomEvent('load:success', {
|
|
6380
|
+
bubbles: true,
|
|
6381
|
+
cancelable: false,
|
|
6382
|
+
detail: { pageRequest, sortRequest, filterRequest, response },
|
|
6383
|
+
}),
|
|
6384
|
+
);
|
|
6385
|
+
}
|
|
6386
|
+
} catch (/** @type any */ error) {
|
|
6387
|
+
if (claim.stale) {
|
|
6388
|
+
return;
|
|
6389
|
+
}
|
|
6390
|
+
this.#windowFailed = true;
|
|
6391
|
+
status.appending.setAttribute('hidden', '');
|
|
6392
|
+
status.error.textContent = Localization.of().failure(error);
|
|
6393
|
+
status.failure.removeAttribute('hidden');
|
|
6394
|
+
this.dispatchEvent(
|
|
6395
|
+
new CustomEvent('load:failure', {
|
|
6396
|
+
bubbles: true,
|
|
6397
|
+
cancelable: false,
|
|
6398
|
+
detail: { pageRequest: { page: missing[0], size }, sortRequest, filterRequest, exception: error },
|
|
6399
|
+
}),
|
|
6400
|
+
);
|
|
6401
|
+
return;
|
|
6402
|
+
} finally {
|
|
6403
|
+
if (this.#shifting === claim) {
|
|
6404
|
+
this.#shifting = null;
|
|
6405
|
+
}
|
|
6406
|
+
}
|
|
6407
|
+
this.#reconcile(false);
|
|
6408
|
+
}
|
|
6409
|
+
/**
|
|
6410
|
+
* Asks again for the pages of the window and shows them where they are.
|
|
6411
|
+
* @returns {Promise<void>}
|
|
6412
|
+
*/
|
|
6413
|
+
async #reloadWindow() {
|
|
6414
|
+
const window = /** @type {{ first: number, last: number, pages: Map<number, Element[]> }} */ (this.#window);
|
|
6415
|
+
const status = /** @type TableStatus */ (this.#status);
|
|
6416
|
+
const { sortRequest, filterRequest } = this.#latestRequest;
|
|
6417
|
+
const size = this.#latestRequest.pageRequest.size;
|
|
6418
|
+
this.#requestedFilters = filterRequest;
|
|
6419
|
+
const claim = this.#loads.take();
|
|
6420
|
+
clearTimeout(this.#jump);
|
|
6421
|
+
this.#shifting = null;
|
|
6422
|
+
this.#windowFailed = false;
|
|
6423
|
+
status.appending.setAttribute('hidden', '');
|
|
6424
|
+
status.failure.setAttribute('hidden', '');
|
|
6425
|
+
this.setAttribute('aria-busy', 'true');
|
|
6426
|
+
const wanted = Array.from({ length: window.last - window.first + 1 }, (_, i) => window.first + i);
|
|
6427
|
+
try {
|
|
6428
|
+
const answers = await Promise.all(
|
|
6429
|
+
wanted.map(async (page) => {
|
|
6430
|
+
const pageRequest = { page, size };
|
|
6431
|
+
return { pageRequest, response: await this.#loader.load(pageRequest, sortRequest, filterRequest) };
|
|
6432
|
+
}),
|
|
6433
|
+
);
|
|
6434
|
+
if (claim.stale) {
|
|
6435
|
+
return;
|
|
6436
|
+
}
|
|
6437
|
+
const total = /** @type {{ response: TablePageResponse }} */ (answers.at(-1)).response.size;
|
|
6438
|
+
const pageCount = Math.ceil(total / size);
|
|
6439
|
+
if (!(window.first < pageCount)) {
|
|
6440
|
+
return await this.load({ page: 0, size }, sortRequest, filterRequest);
|
|
6441
|
+
}
|
|
6442
|
+
const shown = answers.filter((a) => a.pageRequest.page < pageCount);
|
|
6443
|
+
const pages = new Map(
|
|
6444
|
+
shown.map((a) => [a.pageRequest.page, this.#pageRows(a.pageRequest, filterRequest, a.response)]),
|
|
6445
|
+
);
|
|
6446
|
+
this.#body.replaceChildren(...[...pages.values()].flat());
|
|
6447
|
+
this.#window = { first: window.first, last: Math.min(window.last, pageCount - 1), pages };
|
|
6448
|
+
this.#total = total;
|
|
6449
|
+
this.#body.parentElement?.setAttribute('aria-rowcount', String(total + 1));
|
|
6450
|
+
this.#fitSpacers();
|
|
6451
|
+
await Rendering.waitForChildren(this.#body).catch(() => undefined);
|
|
6452
|
+
if (claim.stale) {
|
|
6453
|
+
return;
|
|
6454
|
+
}
|
|
6455
|
+
this.removeAttribute('aria-busy');
|
|
6456
|
+
this.#countInView();
|
|
6457
|
+
for (const { pageRequest, response } of shown) {
|
|
6458
|
+
this.dispatchEvent(
|
|
6459
|
+
new CustomEvent('load:success', {
|
|
6460
|
+
bubbles: true,
|
|
6461
|
+
cancelable: false,
|
|
6462
|
+
detail: { pageRequest, sortRequest, filterRequest, response },
|
|
6463
|
+
}),
|
|
6464
|
+
);
|
|
6465
|
+
}
|
|
6466
|
+
this.#reconcile(false);
|
|
6467
|
+
} catch (/** @type any */ error) {
|
|
6468
|
+
if (claim.stale) {
|
|
6469
|
+
return;
|
|
6470
|
+
}
|
|
6471
|
+
this.#fail(error, { pageRequest: { page: window.first, size }, sortRequest, filterRequest });
|
|
6472
|
+
throw error;
|
|
6473
|
+
}
|
|
6474
|
+
}
|
|
6475
|
+
#update(pageRequest, sortRequest, filterRequest, pageResponse) {
|
|
6476
|
+
this.#loading.setAttribute('hidden', '');
|
|
6477
|
+
if (this.#virtual) {
|
|
6478
|
+
this.#rowHeight = 0;
|
|
6479
|
+
this.#unlockColumns();
|
|
6480
|
+
}
|
|
6481
|
+
const rows = this.#pageRows(pageRequest, filterRequest, pageResponse);
|
|
6482
|
+
this.#body.replaceChildren(...rows);
|
|
5861
6483
|
this.#empty.toggleAttribute('hidden', pageResponse.data.length !== 0);
|
|
5862
6484
|
if (this.#emptyTemplate && pageResponse.data.length === 0) {
|
|
5863
6485
|
this.#emptyAuthors.replaceChildren(
|
|
@@ -5866,7 +6488,28 @@ class Table extends ParsedElement {
|
|
|
5866
6488
|
.render(),
|
|
5867
6489
|
);
|
|
5868
6490
|
}
|
|
5869
|
-
this.#
|
|
6491
|
+
if (this.#virtual) {
|
|
6492
|
+
this.#wrapper.scrollTop = 0;
|
|
6493
|
+
this.#total = pageResponse.size;
|
|
6494
|
+
this.#window =
|
|
6495
|
+
rows.length > 0 ? { first: pageRequest.page, last: pageRequest.page, pages: new Map([[pageRequest.page, rows]]) } : null;
|
|
6496
|
+
return;
|
|
6497
|
+
}
|
|
6498
|
+
if (this.#status) {
|
|
6499
|
+
this.#wrapper.scrollTop = 0;
|
|
6500
|
+
this.#appended = {
|
|
6501
|
+
next: pageRequest.page + 1,
|
|
6502
|
+
shown: pageResponse.data.length,
|
|
6503
|
+
total: pageResponse.size,
|
|
6504
|
+
last: pageResponse.data.length,
|
|
6505
|
+
};
|
|
6506
|
+
this.#status.count.textContent = Localization.of().t('table.loaded', {
|
|
6507
|
+
loaded: this.#appended.shown,
|
|
6508
|
+
total: this.#appended.total,
|
|
6509
|
+
});
|
|
6510
|
+
return;
|
|
6511
|
+
}
|
|
6512
|
+
this.#paginator.update({ current: pageRequest.page, total: Math.ceil(pageResponse.size / pageRequest.size) });
|
|
5870
6513
|
}
|
|
5871
6514
|
}
|
|
5872
6515
|
|
|
@@ -8833,6 +9476,9 @@ var en = {
|
|
|
8833
9476
|
'table.initial': 'Start searching to see results.',
|
|
8834
9477
|
'table.error': 'Error while loading data:',
|
|
8835
9478
|
'table.no-data': 'No elements found.',
|
|
9479
|
+
'table.loaded': 'Showing {loaded} of {total}',
|
|
9480
|
+
'table.range': 'Rows {from}-{to} of {total}',
|
|
9481
|
+
'table.retry': 'Retry',
|
|
8836
9482
|
'dropdown.empty': 'No results',
|
|
8837
9483
|
'select.remove': 'Remove',
|
|
8838
9484
|
'files.dropzone-label': 'Click or drop your files here',
|
|
@@ -8884,6 +9530,9 @@ var it = {
|
|
|
8884
9530
|
'table.initial': 'Avvia la ricerca per visualizzare i risultati.',
|
|
8885
9531
|
'table.error': 'Errore nel caricamento dei dati:',
|
|
8886
9532
|
'table.no-data': 'Nessun elemento trovato.',
|
|
9533
|
+
'table.loaded': 'Mostrati {loaded} di {total}',
|
|
9534
|
+
'table.range': 'Righe {from}-{to} di {total}',
|
|
9535
|
+
'table.retry': 'Riprova',
|
|
8887
9536
|
'dropdown.empty': 'Nessun risultato',
|
|
8888
9537
|
'select.remove': 'Rimuovi',
|
|
8889
9538
|
'files.dropzone-label': 'Clicca o trascina i file qui',
|
|
@@ -8935,6 +9584,9 @@ var es = {
|
|
|
8935
9584
|
'table.initial': 'Inicia la búsqueda para ver los resultados.',
|
|
8936
9585
|
'table.error': 'Error al cargar los datos:',
|
|
8937
9586
|
'table.no-data': 'No se encontraron elementos.',
|
|
9587
|
+
'table.loaded': 'Mostrando {loaded} de {total}',
|
|
9588
|
+
'table.range': 'Filas {from}-{to} de {total}',
|
|
9589
|
+
'table.retry': 'Reintentar',
|
|
8938
9590
|
'dropdown.empty': 'Sin resultados',
|
|
8939
9591
|
'select.remove': 'Eliminar',
|
|
8940
9592
|
'files.dropzone-label': 'Haz clic o arrastra tus archivos aquí',
|
|
@@ -8989,6 +9641,9 @@ var fr = {
|
|
|
8989
9641
|
'table.initial': 'Lancez la recherche pour voir les résultats.',
|
|
8990
9642
|
'table.error': 'Erreur lors du chargement des données :',
|
|
8991
9643
|
'table.no-data': 'Aucun élément trouvé.',
|
|
9644
|
+
'table.loaded': 'Affichage de {loaded} sur {total}',
|
|
9645
|
+
'table.range': 'Lignes {from} à {to} sur {total}',
|
|
9646
|
+
'table.retry': 'Réessayer',
|
|
8992
9647
|
'dropdown.empty': 'Aucun résultat',
|
|
8993
9648
|
'select.remove': 'Retirer',
|
|
8994
9649
|
'files.dropzone-label': 'Cliquez ou déposez vos fichiers ici',
|