@holoviz/panel 1.10.0 → 1.11.0-b.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundled/bootstraptemplate/bootstrap.css +4 -0
- package/dist/bundled/deckglplot/@deck.gl/carto@^9.1.14/dist.min.js +8 -8
- package/dist/bundled/deckglplot/maplibre-gl/dist/maplibre-gl.js +2 -2
- package/dist/bundled/fastbasetemplate/fast.css +8 -1
- package/dist/bundled/filedropper/filepond@^4/dist/filepond.css +1 -1
- package/dist/bundled/filedropper/filepond@^4/dist/filepond.esm.min.js +2 -2
- package/dist/bundled/licenses/index.json +6 -6
- package/dist/bundled/reacttemplate/react.css +4 -0
- package/dist/bundled/theme/fast.css +0 -18
- package/dist/bundled/vanillatemplate/vanilla.css +4 -0
- package/dist/css/progress.css +24 -19
- package/dist/lib/models/comm_manager.d.ts +4 -0
- package/dist/lib/models/comm_manager.js +76 -18
- package/dist/lib/models/comm_manager.js.map +1 -1
- package/dist/lib/models/data.d.ts +1 -0
- package/dist/lib/models/data.js +47 -18
- package/dist/lib/models/data.js.map +1 -1
- package/dist/lib/models/html.d.ts +12 -2
- package/dist/lib/models/html.js +95 -20
- package/dist/lib/models/html.js.map +1 -1
- package/dist/lib/models/icon.js +2 -0
- package/dist/lib/models/icon.js.map +1 -1
- package/dist/lib/models/location.js +3 -0
- package/dist/lib/models/location.js.map +1 -1
- package/dist/lib/models/plotly.d.ts +15 -1
- package/dist/lib/models/plotly.js +99 -33
- package/dist/lib/models/plotly.js.map +1 -1
- package/dist/lib/models/react_component.js +65 -26
- package/dist/lib/models/react_component.js.map +1 -1
- package/dist/lib/models/reactive_esm.d.ts +13 -0
- package/dist/lib/models/reactive_esm.js +25 -0
- package/dist/lib/models/reactive_esm.js.map +1 -1
- package/dist/lib/models/reactive_html.js +32 -16
- package/dist/lib/models/reactive_html.js.map +1 -1
- package/dist/lib/models/resources.d.ts +4 -3
- package/dist/lib/models/resources.js +104 -24
- package/dist/lib/models/resources.js.map +1 -1
- package/dist/lib/models/tabs.d.ts +2 -0
- package/dist/lib/models/tabs.js +11 -0
- package/dist/lib/models/tabs.js.map +1 -1
- package/dist/lib/models/tabulator.d.ts +32 -4
- package/dist/lib/models/tabulator.js +279 -101
- package/dist/lib/models/tabulator.js.map +1 -1
- package/dist/lib/models/vega.d.ts +20 -3
- package/dist/lib/models/vega.js +123 -55
- package/dist/lib/models/vega.js.map +1 -1
- package/dist/lib/styles/progress.css.js +22 -16
- package/dist/panel.js +1004 -353
- package/dist/panel.js.map +1 -1
- package/dist/panel.json +1 -1
- package/dist/panel.min.js +24 -24
- package/package.json +1 -1
- package/dist/css/katex.css +0 -3
- package/dist/dts/styles/katex.css.d.ts +0 -4
- package/dist/lib/styles/katex.css.d.ts +0 -2
- package/dist/lib/styles/katex.css.js +0 -1
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { display, undisplay } from "@bokehjs/core/dom";
|
|
2
2
|
import { sum } from "@bokehjs/core/util/arrayable";
|
|
3
|
-
import {
|
|
3
|
+
import { delay, paint } from "@bokehjs/core/util/defer";
|
|
4
4
|
import { isArray, isBoolean, isFunction, isString, isNumber } from "@bokehjs/core/util/types";
|
|
5
5
|
import { ModelEvent } from "@bokehjs/core/bokeh_events";
|
|
6
6
|
import { div } from "@bokehjs/core/dom";
|
|
7
7
|
import { Enum } from "@bokehjs/core/kinds";
|
|
8
8
|
import { Model } from "@bokehjs/model";
|
|
9
9
|
import { ColumnDataSource } from "@bokehjs/models/sources/column_data_source";
|
|
10
|
+
import { ColumnsStreamedEvent } from "@bokehjs/document/events";
|
|
10
11
|
import { debounce } from "debounce";
|
|
11
12
|
import { cell_formatter } from "./cell_formatters";
|
|
12
13
|
import { comm_settings } from "./comm_manager";
|
|
13
|
-
import { transform_cds_to_records } from "./data";
|
|
14
|
+
import { transform_cds_rows_to_records, transform_cds_to_records } from "./data";
|
|
14
15
|
import { HTMLBox, HTMLBoxView } from "./layout";
|
|
15
16
|
import { schedule_when, transformJsPlaceholders } from "./util";
|
|
16
17
|
import tabulator_css from "styles/models/tabulator.css";
|
|
@@ -124,7 +125,7 @@ function summarize(grouped, columns, aggregators, depth = 0) {
|
|
|
124
125
|
}
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
|
-
else {
|
|
128
|
+
else if (agg) {
|
|
128
129
|
summary[column.field] = val;
|
|
129
130
|
}
|
|
130
131
|
}
|
|
@@ -171,7 +172,7 @@ function group_data(records, columns, indexes, aggregators) {
|
|
|
171
172
|
}
|
|
172
173
|
}
|
|
173
174
|
else {
|
|
174
|
-
aggs.push("
|
|
175
|
+
aggs.push("");
|
|
175
176
|
}
|
|
176
177
|
}
|
|
177
178
|
summarize(grouped, columns, aggs);
|
|
@@ -382,6 +383,30 @@ function clone_column(group) {
|
|
|
382
383
|
}
|
|
383
384
|
return { ...group, columns: group_columns };
|
|
384
385
|
}
|
|
386
|
+
const set_cache = new WeakMap();
|
|
387
|
+
/** Tabulator queries membership once per row, so index arrays are looked up as sets. */
|
|
388
|
+
function as_set(indices) {
|
|
389
|
+
let indices_set = set_cache.get(indices);
|
|
390
|
+
if (indices_set === undefined) {
|
|
391
|
+
indices_set = new Set(indices);
|
|
392
|
+
set_cache.set(indices, indices_set);
|
|
393
|
+
}
|
|
394
|
+
return indices_set;
|
|
395
|
+
}
|
|
396
|
+
/** Dicts with numeric keys deserialize as Maps, empty ones as plain objects. */
|
|
397
|
+
function lookup(mapping, key) {
|
|
398
|
+
if (mapping == null) {
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
return mapping instanceof Map ? (mapping.get(key) ?? null) : (mapping[key] ?? null);
|
|
402
|
+
}
|
|
403
|
+
function stream_length(data) {
|
|
404
|
+
const columns = data instanceof Map ? [...data.values()] : Object.values(data);
|
|
405
|
+
for (const column of columns) {
|
|
406
|
+
return column.shape != null ? column.shape[0] : column.length;
|
|
407
|
+
}
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
385
410
|
/** Ignore Tabulator redraw after `after_resize` when `this.el` client size changes by at most this many pixels per axis. */
|
|
386
411
|
const EL_CLIENT_RESIZE_EPSILON_PX = 3;
|
|
387
412
|
/**
|
|
@@ -390,6 +415,7 @@ const EL_CLIENT_RESIZE_EPSILON_PX = 3;
|
|
|
390
415
|
* ready chain pending forever, which would otherwise block every later redraw.
|
|
391
416
|
*/
|
|
392
417
|
const ROOT_READY_TIMEOUT_MS = 250;
|
|
418
|
+
const RESIZE_BLOCKED_FRAMES = 10;
|
|
393
419
|
export class DataTabulatorView extends HTMLBoxView {
|
|
394
420
|
tabulator;
|
|
395
421
|
columns = new Map();
|
|
@@ -403,13 +429,18 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
403
429
|
_selection_updating = false;
|
|
404
430
|
_selection_pending = true;
|
|
405
431
|
_last_selected_row = null;
|
|
406
|
-
_initializing;
|
|
432
|
+
_initializing = true;
|
|
407
433
|
_lastVerticalScrollbarTopPosition = 0;
|
|
408
434
|
_lastHorizontalScrollbarLeftPosition = 0;
|
|
409
|
-
|
|
435
|
+
/** Bumped when `cell_styles` changes; cells styled with an older version are restyled when visible. */
|
|
436
|
+
_styles_version = 0;
|
|
437
|
+
_styled_cells = new WeakMap();
|
|
410
438
|
_building = false;
|
|
411
439
|
_pending_data = false;
|
|
440
|
+
/** A data update in flight; its `renderComplete` must not run `postUpdate` a second time. */
|
|
441
|
+
_updating_data = false;
|
|
412
442
|
_redrawing = false;
|
|
443
|
+
_resized_columns = new Map();
|
|
413
444
|
/** Coalesced resize redraw; waits for `this.root.ready` (Bokeh view async chain) before redrawing. */
|
|
414
445
|
_resize_pending = false;
|
|
415
446
|
_resize_flush = null;
|
|
@@ -445,19 +476,13 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
445
476
|
if (this.tabulator == null) {
|
|
446
477
|
return;
|
|
447
478
|
}
|
|
448
|
-
|
|
479
|
+
const expanded = as_set(this.model.expanded);
|
|
480
|
+
// The first cell is the cell of the frozen _index column, the second
|
|
481
|
+
// holds the expand icon, which must follow changes made from Python.
|
|
449
482
|
for (const row of this.tabulator.rowManager.getRows()) {
|
|
450
|
-
if (row.cells.length >
|
|
483
|
+
if (row.cells.length > 1) {
|
|
451
484
|
row.cells[0].layoutElement();
|
|
452
|
-
|
|
453
|
-
}
|
|
454
|
-
// Make sure the expand icon is changed when expanded is
|
|
455
|
-
// changed from Python.
|
|
456
|
-
for (const row of this.tabulator.rowManager.getRows()) {
|
|
457
|
-
if (row.cells.length > 0) {
|
|
458
|
-
const index = row.data._index;
|
|
459
|
-
const icon = this.model.expanded.includes(index) ? "▼" : "►";
|
|
460
|
-
row.cells[1].element.innerText = icon;
|
|
485
|
+
row.cells[1].element.innerText = expanded.has(row.data._index) ? "▼" : "►";
|
|
461
486
|
}
|
|
462
487
|
}
|
|
463
488
|
// If content is embedded, views may not have been
|
|
@@ -468,18 +493,12 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
468
493
|
}
|
|
469
494
|
});
|
|
470
495
|
this.on_change(cell_styles, () => {
|
|
471
|
-
|
|
472
|
-
this.record_scroll();
|
|
473
|
-
this._updating_scroll = true;
|
|
474
|
-
this.tabulator.redraw(true);
|
|
475
|
-
this._updating_scroll = false;
|
|
476
|
-
}
|
|
477
|
-
this.restore_scroll();
|
|
496
|
+
this._styles_version += 1;
|
|
478
497
|
this.setStyles();
|
|
479
498
|
});
|
|
480
499
|
this.on_change(hidden_columns, () => {
|
|
481
500
|
this.setHidden();
|
|
482
|
-
this.tabulator.redraw(
|
|
501
|
+
this.tabulator.columnManager.redraw(false);
|
|
483
502
|
});
|
|
484
503
|
this.on_change(page_size, () => this.setPageSize());
|
|
485
504
|
this.on_change(page, () => {
|
|
@@ -493,7 +512,7 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
493
512
|
this.on_change(sorters, () => this.setSorters());
|
|
494
513
|
this.on_change(theme_classes, () => this.setCSSClasses(this.tabulator.element));
|
|
495
514
|
this.on_change(this.model.source.properties.data, () => {
|
|
496
|
-
if (this.tabulator
|
|
515
|
+
if (this.tabulator == null) {
|
|
497
516
|
return;
|
|
498
517
|
}
|
|
499
518
|
this._restore_scroll = "horizontal";
|
|
@@ -501,26 +520,38 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
501
520
|
// The scroll event of a scroll just before may not have been handled yet.
|
|
502
521
|
this.record_scroll();
|
|
503
522
|
this._updating_scroll = true;
|
|
504
|
-
|
|
523
|
+
this._updating_data = true;
|
|
524
|
+
void this.setData().finally(() => {
|
|
525
|
+
this._updating_data = false;
|
|
526
|
+
}).then(() => {
|
|
505
527
|
this._selection_updating = false;
|
|
528
|
+
this.refitColumns();
|
|
506
529
|
this.postUpdate();
|
|
507
530
|
this.restore_scroll();
|
|
508
531
|
});
|
|
509
532
|
});
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
this.
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
});
|
|
533
|
+
// The streaming signal carries no payload; the document event also tells how
|
|
534
|
+
// many rows were streamed and the rollover, which decide whether rows can be appended.
|
|
535
|
+
const doc = this.model.document;
|
|
536
|
+
if (doc != null) {
|
|
537
|
+
doc.on_change(this._on_document_change);
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
this.connect(this.model.source.streaming, () => this.addData(null, null));
|
|
541
|
+
}
|
|
542
|
+
this.connect(this.model.source.patching, (indices) => this.updateOrAddData(indices));
|
|
521
543
|
this.connect(this.model.source.selected.change, () => this.setSelection());
|
|
522
544
|
this.connect(this.model.source.selected.properties.indices.change, () => this.setSelection());
|
|
523
545
|
}
|
|
546
|
+
disconnect_signals() {
|
|
547
|
+
this.model.document?.remove_on_change(this._on_document_change);
|
|
548
|
+
super.disconnect_signals();
|
|
549
|
+
}
|
|
550
|
+
_on_document_change = (event) => {
|
|
551
|
+
if (event instanceof ColumnsStreamedEvent && event.model === this.model.source && event.attr === "data") {
|
|
552
|
+
this.addData(event.data, event.rollover ?? null);
|
|
553
|
+
}
|
|
554
|
+
};
|
|
524
555
|
get groupBy() {
|
|
525
556
|
const groupby = (data) => {
|
|
526
557
|
const groups = [];
|
|
@@ -537,19 +568,36 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
537
568
|
if (this.model.sorters.length > 0) {
|
|
538
569
|
sorters.push({ column: "_index", dir: "asc" });
|
|
539
570
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
}
|
|
544
|
-
sorters.push(sort);
|
|
571
|
+
// Copy, the model array must not be reversed in place.
|
|
572
|
+
for (const sort of [...this.model.sorters].reverse()) {
|
|
573
|
+
sorters.push(sort.column === undefined ? { ...sort, column: sort.field } : sort);
|
|
545
574
|
}
|
|
546
575
|
return sorters;
|
|
547
576
|
}
|
|
548
577
|
invalidate_render() {
|
|
549
578
|
this.tabulator?.destroy();
|
|
550
579
|
this.tabulator = null;
|
|
580
|
+
this._resized_columns.clear();
|
|
551
581
|
this.rerender_();
|
|
552
582
|
}
|
|
583
|
+
refitColumns(field) {
|
|
584
|
+
if (this._building || this.tabulator == null || !this.model.layout.startsWith("fit_data")) {
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
if (field != null && this.model.layout !== "fit_data_stretch") {
|
|
588
|
+
// Measuring a single column costs a fraction of re-measuring them all.
|
|
589
|
+
const column = this.tabulator.getColumn(field);
|
|
590
|
+
if (column != null && !this._resized_columns.has(field) && column.getDefinition().width == null) {
|
|
591
|
+
column.setWidth(true);
|
|
592
|
+
}
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
this.tabulator.columnManager.layoutRefresh(true);
|
|
596
|
+
// The refit discards the widths of columns the user has dragged.
|
|
597
|
+
for (const [name, width] of this._resized_columns) {
|
|
598
|
+
this.tabulator.getColumn(name)?.setWidth(width);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
553
601
|
redraw(columns = true, rows = true) {
|
|
554
602
|
if (this._building || this.tabulator == null || this._redrawing) {
|
|
555
603
|
return;
|
|
@@ -614,6 +662,7 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
614
662
|
});
|
|
615
663
|
}
|
|
616
664
|
async _flush_resize_when_root_ready() {
|
|
665
|
+
let blocked = 0;
|
|
617
666
|
while (true) {
|
|
618
667
|
if (!this._resize_pending) {
|
|
619
668
|
return;
|
|
@@ -633,7 +682,9 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
633
682
|
this.is_drawing ||
|
|
634
683
|
this._has_active_editor() ||
|
|
635
684
|
!this.stylesheets_settled) {
|
|
636
|
-
|
|
685
|
+
// `root.ready` is usually already resolved, so a blocking condition that persists
|
|
686
|
+
// would otherwise spin this loop; back off once it outlasts a few frames.
|
|
687
|
+
await (blocked++ < RESIZE_BLOCKED_FRAMES ? paint() : delay(ROOT_READY_TIMEOUT_MS));
|
|
637
688
|
continue;
|
|
638
689
|
}
|
|
639
690
|
this._resize_pending = false;
|
|
@@ -653,11 +704,14 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
653
704
|
this.record_scroll();
|
|
654
705
|
this._updating_scroll = true;
|
|
655
706
|
this.redraw(true, true);
|
|
707
|
+
this._updating_scroll = false;
|
|
708
|
+
this._pending_scroll_restores += 1;
|
|
656
709
|
requestAnimationFrame(() => {
|
|
657
710
|
this._initializing = false;
|
|
658
711
|
if (this._selection_pending) {
|
|
659
712
|
this.setSelection();
|
|
660
713
|
}
|
|
714
|
+
this._pending_scroll_restores -= 1;
|
|
661
715
|
this.restore_scroll();
|
|
662
716
|
this.recompute_page_size();
|
|
663
717
|
});
|
|
@@ -762,20 +816,20 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
762
816
|
// Rendering callbacks
|
|
763
817
|
this.tabulator.on("selectableRowsCheck", (row) => {
|
|
764
818
|
const selectable = this.model.selectable_rows;
|
|
765
|
-
return (selectable == null) || selectable.
|
|
819
|
+
return (selectable == null) || as_set(selectable).has(row._row.data._index);
|
|
766
820
|
});
|
|
767
821
|
this.tabulator.on("tooltips", (cell) => {
|
|
768
822
|
return `${cell.getColumn().getField()}: ${cell.getValue()}`;
|
|
769
823
|
});
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
}, 50, false));
|
|
824
|
+
// Rows scrolled back into view reuse their elements, so restyle them when `cell_styles` changed since.
|
|
825
|
+
this.tabulator.on("scrollVertical", () => this.setStyles());
|
|
773
826
|
// Sync state with model
|
|
774
827
|
this.tabulator.on("rowSelectionChanged", (data, rows, selected, deselected) => {
|
|
775
828
|
this.rowSelectionChanged(data, rows, selected, deselected);
|
|
776
829
|
});
|
|
777
830
|
this.tabulator.on("rowClick", (e, row) => this.rowClicked(e, row));
|
|
778
831
|
this.tabulator.on("cellEdited", (cell) => this.cellEdited(cell));
|
|
832
|
+
this.tabulator.on("columnResized", (column) => this._resized_columns.set(column.getField(), column.getWidth()));
|
|
779
833
|
this.tabulator.on("dataFiltering", (filters) => {
|
|
780
834
|
this.record_scroll();
|
|
781
835
|
this.model.filters = filters;
|
|
@@ -797,7 +851,7 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
797
851
|
this.updatePage(pageno);
|
|
798
852
|
});
|
|
799
853
|
this.tabulator.on("renderComplete", () => {
|
|
800
|
-
if (this._building) {
|
|
854
|
+
if (this._building || this._updating_data) {
|
|
801
855
|
return;
|
|
802
856
|
}
|
|
803
857
|
this.postUpdate();
|
|
@@ -840,7 +894,10 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
840
894
|
this._initializing = this._building = false;
|
|
841
895
|
this.setVisibility();
|
|
842
896
|
if (this._pending_data) {
|
|
843
|
-
|
|
897
|
+
this._updating_data = true;
|
|
898
|
+
void this.setData().finally(() => {
|
|
899
|
+
this._updating_data = false;
|
|
900
|
+
}).then(() => this.postUpdate());
|
|
844
901
|
}
|
|
845
902
|
this._request_resize_redraw();
|
|
846
903
|
}
|
|
@@ -942,7 +999,8 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
942
999
|
}
|
|
943
1000
|
getConfiguration() {
|
|
944
1001
|
// Only use selectable mode if explicitly requested otherwise manually handle selections
|
|
945
|
-
|
|
1002
|
+
// Tabulator only skips marking rows as selectable (class and hover styling) for exactly false
|
|
1003
|
+
const selectableRows = this.model.select_mode === "toggle" ? true : (this.model.select_mode === false ? false : NaN);
|
|
946
1004
|
const configuration = {
|
|
947
1005
|
...transformJsPlaceholders(this.model.configuration),
|
|
948
1006
|
index: "_index",
|
|
@@ -959,9 +1017,12 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
959
1017
|
popupContainer: this.model.container_popup && this.container,
|
|
960
1018
|
groupBy: this.groupBy,
|
|
961
1019
|
frozenRows: (row) => {
|
|
962
|
-
return (this.model.frozen_rows.length > 0) ? this.model.frozen_rows.
|
|
1020
|
+
return (this.model.frozen_rows.length > 0) ? as_set(this.model.frozen_rows).has(row._row.data._index) : false;
|
|
1021
|
+
},
|
|
1022
|
+
rowFormatter: (row) => {
|
|
1023
|
+
this._style_row(row);
|
|
1024
|
+
this._render_row(row, false);
|
|
963
1025
|
},
|
|
964
|
-
rowFormatter: (row) => this._render_row(row, false),
|
|
965
1026
|
};
|
|
966
1027
|
if (this.model.max_height != null) {
|
|
967
1028
|
configuration.maxHeight = this.model.max_height;
|
|
@@ -1020,7 +1081,7 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
1020
1081
|
}
|
|
1021
1082
|
_render_row(row, resize = true) {
|
|
1022
1083
|
const index = row._row?.data._index;
|
|
1023
|
-
if (!this.model.expanded.
|
|
1084
|
+
if (!as_set(this.model.expanded).has(index)) {
|
|
1024
1085
|
return;
|
|
1025
1086
|
}
|
|
1026
1087
|
const model = this.get_child(index);
|
|
@@ -1030,8 +1091,6 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
1030
1091
|
}
|
|
1031
1092
|
schedule_when(() => {
|
|
1032
1093
|
const rowEl = row.getElement();
|
|
1033
|
-
const style = getComputedStyle(this.tabulator.element.children[1].children[0]);
|
|
1034
|
-
const bg = style.backgroundColor;
|
|
1035
1094
|
const neg_margin = rowEl.style.paddingLeft ? `-${rowEl.style.paddingLeft}` : "0";
|
|
1036
1095
|
const prev_child = rowEl.children[rowEl.children.length - 1];
|
|
1037
1096
|
let viewEl;
|
|
@@ -1042,6 +1101,7 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
1042
1101
|
}
|
|
1043
1102
|
}
|
|
1044
1103
|
else {
|
|
1104
|
+
const bg = getComputedStyle(this.tabulator.element.children[1].children[0]).backgroundColor;
|
|
1045
1105
|
viewEl = div({ class: "row-content", style: { background_color: bg, margin_left: neg_margin, max_width: "100%", overflow_x: "hidden" } });
|
|
1046
1106
|
rowEl.appendChild(viewEl);
|
|
1047
1107
|
}
|
|
@@ -1067,8 +1127,7 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
1067
1127
|
}
|
|
1068
1128
|
_expand_render(cell) {
|
|
1069
1129
|
const index = cell._cell.row.data._index;
|
|
1070
|
-
|
|
1071
|
-
return icon;
|
|
1130
|
+
return as_set(this.model.expanded).has(index) ? "▼" : "►";
|
|
1072
1131
|
}
|
|
1073
1132
|
_update_expand(cell) {
|
|
1074
1133
|
const index = cell._cell.row.data._index;
|
|
@@ -1318,12 +1377,48 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
1318
1377
|
return this.tabulator.setData(data);
|
|
1319
1378
|
}
|
|
1320
1379
|
}
|
|
1321
|
-
|
|
1380
|
+
/** Whether rows can be added or updated in place rather than rebuilding the whole table. */
|
|
1381
|
+
get can_update_in_place() {
|
|
1382
|
+
return (this.tabulator != null &&
|
|
1383
|
+
this.tabulator.initialized &&
|
|
1384
|
+
!this._initializing &&
|
|
1385
|
+
!this._building &&
|
|
1386
|
+
!this._pending_data &&
|
|
1387
|
+
!this.model.configuration.dataTree);
|
|
1388
|
+
}
|
|
1389
|
+
/**
|
|
1390
|
+
* Appends the streamed rows. Rolling over drops leading rows and shifts every
|
|
1391
|
+
* `_index`, so that case (and anything out of sync) rebuilds the table.
|
|
1392
|
+
*/
|
|
1393
|
+
addData(streamed, rollover) {
|
|
1394
|
+
if (this.tabulator == null) {
|
|
1395
|
+
return;
|
|
1396
|
+
}
|
|
1322
1397
|
const rows = this.tabulator.rowManager.getRows();
|
|
1323
1398
|
const last_row = rows[rows.length - 1];
|
|
1324
1399
|
const start = ((last_row?.data._index) || 0);
|
|
1400
|
+
const total = this.model.source.get_length() ?? 0;
|
|
1401
|
+
const n_streamed = streamed == null ? null : stream_length(streamed);
|
|
1402
|
+
const append = (n_streamed != null &&
|
|
1403
|
+
this.can_update_in_place &&
|
|
1404
|
+
rows.length + n_streamed === total &&
|
|
1405
|
+
(rollover == null || total <= rollover));
|
|
1325
1406
|
this._updating_page = true;
|
|
1326
|
-
|
|
1407
|
+
let update;
|
|
1408
|
+
if (append) {
|
|
1409
|
+
this._updating_data = true;
|
|
1410
|
+
try {
|
|
1411
|
+
this._append_rows(transform_cds_to_records(this.model.source, true, rows.length));
|
|
1412
|
+
}
|
|
1413
|
+
finally {
|
|
1414
|
+
this._updating_data = false;
|
|
1415
|
+
}
|
|
1416
|
+
update = Promise.resolve();
|
|
1417
|
+
}
|
|
1418
|
+
else {
|
|
1419
|
+
update = this.setData();
|
|
1420
|
+
}
|
|
1421
|
+
void update.then(() => {
|
|
1327
1422
|
if (this.model.follow) {
|
|
1328
1423
|
if (this.model.pagination) {
|
|
1329
1424
|
this.tabulator.setPage(Math.ceil(this.tabulator.rowManager.getDataCount() / (this.model.page_size || 20)));
|
|
@@ -1335,6 +1430,40 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
1335
1430
|
this._updating_page = false;
|
|
1336
1431
|
});
|
|
1337
1432
|
}
|
|
1433
|
+
/**
|
|
1434
|
+
* Tabulator's `addData` copies the active rows array and, with pagination,
|
|
1435
|
+
* refreshes the whole data pipeline once per added row, which makes appending
|
|
1436
|
+
* a batch slower than rebuilding the table. This appends rows the way
|
|
1437
|
+
* `RowManager.addRows` does but refreshes once.
|
|
1438
|
+
*/
|
|
1439
|
+
_append_rows(records) {
|
|
1440
|
+
const manager = this.tabulator.rowManager;
|
|
1441
|
+
// With pagination Tabulator places new rows on the current page unless the
|
|
1442
|
+
// preceding row is given explicitly.
|
|
1443
|
+
let after = this.model.pagination == null ? undefined : manager.rows[manager.rows.length - 1];
|
|
1444
|
+
const { setActiveRows, refreshActiveData } = manager;
|
|
1445
|
+
manager.setActiveRows = () => { };
|
|
1446
|
+
manager.refreshActiveData = () => { };
|
|
1447
|
+
try {
|
|
1448
|
+
for (const record of records) {
|
|
1449
|
+
const row = manager.addRow(record, false, after, true);
|
|
1450
|
+
manager.dispatch("row-added", row, record, false, after);
|
|
1451
|
+
if (after !== undefined) {
|
|
1452
|
+
after = row;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
finally {
|
|
1457
|
+
manager.setActiveRows = setActiveRows;
|
|
1458
|
+
manager.refreshActiveData = refreshActiveData;
|
|
1459
|
+
}
|
|
1460
|
+
manager.setActiveRows(manager.activeRows);
|
|
1461
|
+
manager.refreshActiveData(false, false, true);
|
|
1462
|
+
manager.regenerateRowPositions();
|
|
1463
|
+
if (manager.displayRowsCount) {
|
|
1464
|
+
manager._clearPlaceholder();
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1338
1467
|
postUpdate() {
|
|
1339
1468
|
this.setSelection();
|
|
1340
1469
|
this.setStyles();
|
|
@@ -1343,20 +1472,52 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
1343
1472
|
this.restore_scroll(restore !== "vertical", restore !== "horizontal");
|
|
1344
1473
|
this._restore_scroll = false;
|
|
1345
1474
|
}
|
|
1346
|
-
|
|
1475
|
+
/** Updates the patched rows in place; patches touching most rows rebuild the table instead. */
|
|
1476
|
+
updateOrAddData(indices) {
|
|
1347
1477
|
// To avoid double updating the tabulator data
|
|
1348
|
-
if (this._tabulator_cell_updating) {
|
|
1478
|
+
if (this._tabulator_cell_updating || this.tabulator == null) {
|
|
1349
1479
|
return;
|
|
1350
1480
|
}
|
|
1481
|
+
const rows = this.tabulator.rowManager.getRows().length;
|
|
1482
|
+
if (this.can_update_in_place &&
|
|
1483
|
+
// Tabulator does not regroup rows whose data is updated in place.
|
|
1484
|
+
!this.tabulator.options.groupBy &&
|
|
1485
|
+
isArray(indices) &&
|
|
1486
|
+
indices.length > 0 &&
|
|
1487
|
+
indices.length * 2 < rows &&
|
|
1488
|
+
indices.every(isNumber)) {
|
|
1489
|
+
const records = transform_cds_rows_to_records(this.model.source, indices, true);
|
|
1490
|
+
if (records.length === indices.length) {
|
|
1491
|
+
// Rows updated in place are not re-sorted or re-filtered, refreshing
|
|
1492
|
+
// the filter re-runs the filter and sort stages of the data pipeline.
|
|
1493
|
+
const refresh = this.tabulator.getSorters().length > 0 || this.tabulator.getFilters(true).length > 0;
|
|
1494
|
+
this.tabulator.updateData(records).then(() => {
|
|
1495
|
+
if (refresh) {
|
|
1496
|
+
this.tabulator.refreshFilter();
|
|
1497
|
+
}
|
|
1498
|
+
}).catch(() => this.replaceData());
|
|
1499
|
+
return;
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
this.replaceData();
|
|
1503
|
+
}
|
|
1504
|
+
replaceData() {
|
|
1505
|
+
const inds = this.model.source.selected.indices;
|
|
1506
|
+
this.record_scroll();
|
|
1507
|
+
this._updating_scroll = true;
|
|
1351
1508
|
// Temporarily set minHeight to avoid "scroll-to-top" issues caused
|
|
1352
1509
|
// by Tabulator JS entirely destroying the table when .setData is called.
|
|
1353
1510
|
// Inspired by https://github.com/olifolkerd/tabulator/issues/4155
|
|
1354
1511
|
const prev_minheight = this.tabulator.element.style.minHeight;
|
|
1355
1512
|
this.tabulator.element.style.minHeight = `${this.tabulator.element.offsetHeight}px`;
|
|
1356
|
-
const data =
|
|
1513
|
+
const data = this.getData();
|
|
1357
1514
|
this.tabulator.setData(data).then(() => {
|
|
1358
1515
|
this.tabulator.element.style.minHeight = prev_minheight;
|
|
1359
1516
|
});
|
|
1517
|
+
this._updating_scroll = false;
|
|
1518
|
+
// Restore indices since updating data may have reset checkbox column
|
|
1519
|
+
this.model.source.selected.indices = inds;
|
|
1520
|
+
this.restore_scroll();
|
|
1360
1521
|
}
|
|
1361
1522
|
setFrozen() {
|
|
1362
1523
|
for (const row of this.model.frozen_rows) {
|
|
@@ -1380,41 +1541,54 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
1380
1541
|
}
|
|
1381
1542
|
this.tabulator.setSort(this.sorters);
|
|
1382
1543
|
}
|
|
1544
|
+
/** Styles the rendered rows; rows rendered later are styled by the `rowFormatter`. */
|
|
1383
1545
|
setStyles() {
|
|
1384
|
-
|
|
1385
|
-
if (this.tabulator == null || this.tabulator.getDataCount() == 0 || style_data == null || !style_data.size) {
|
|
1546
|
+
if (this.tabulator == null || this.tabulator.rowManager.renderer == null) {
|
|
1386
1547
|
return;
|
|
1387
1548
|
}
|
|
1388
|
-
|
|
1389
|
-
for (const
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1549
|
+
// Chained so frozen rows, which sit outside the scrolled rows, are included.
|
|
1550
|
+
for (const row of this.tabulator.rowManager.getVisibleRows(true, true)) {
|
|
1551
|
+
if (row.type === "row") {
|
|
1552
|
+
this._style_row(row.getComponent());
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
_style_row(row) {
|
|
1557
|
+
const version = this._styles_version;
|
|
1558
|
+
const index = row._row?.data._index;
|
|
1559
|
+
const row_style = index == null ? null : lookup(this.model.cell_styles.data, index);
|
|
1560
|
+
for (const cell of row._row?.cells ?? []) {
|
|
1561
|
+
const element = cell.element;
|
|
1562
|
+
if (element == null) {
|
|
1393
1563
|
continue;
|
|
1394
1564
|
}
|
|
1395
|
-
const
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1565
|
+
const styled = this._styled_cells.get(element);
|
|
1566
|
+
if (styled != null && styled.version === version) {
|
|
1567
|
+
continue;
|
|
1568
|
+
}
|
|
1569
|
+
if (styled != null) {
|
|
1570
|
+
for (const prop of styled.props) {
|
|
1571
|
+
element.style.removeProperty(prop);
|
|
1572
|
+
}
|
|
1573
|
+
this._styled_cells.delete(element);
|
|
1574
|
+
}
|
|
1575
|
+
const style = lookup(row_style, cell.column.field);
|
|
1576
|
+
const props = [];
|
|
1577
|
+
for (const s of style ?? []) {
|
|
1578
|
+
let prop, value;
|
|
1579
|
+
if (isArray(s)) {
|
|
1580
|
+
[prop, value] = s;
|
|
1581
|
+
}
|
|
1582
|
+
else if (!s.includes(":")) {
|
|
1400
1583
|
continue;
|
|
1401
1584
|
}
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
let prop, value;
|
|
1405
|
-
if (isArray(s)) {
|
|
1406
|
-
[prop, value] = s;
|
|
1407
|
-
}
|
|
1408
|
-
else if (!s.includes(":")) {
|
|
1409
|
-
continue;
|
|
1410
|
-
}
|
|
1411
|
-
else {
|
|
1412
|
-
[prop, value] = s.split(":");
|
|
1413
|
-
}
|
|
1414
|
-
element.style.setProperty(prop, value.trimLeft());
|
|
1415
|
-
this._applied_styles = true;
|
|
1585
|
+
else {
|
|
1586
|
+
[prop, value] = s.split(":");
|
|
1416
1587
|
}
|
|
1588
|
+
element.style.setProperty(prop, value.trimLeft());
|
|
1589
|
+
props.push(prop);
|
|
1417
1590
|
}
|
|
1591
|
+
this._styled_cells.set(element, { version, props });
|
|
1418
1592
|
}
|
|
1419
1593
|
}
|
|
1420
1594
|
setHidden() {
|
|
@@ -1466,10 +1640,13 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
1466
1640
|
this._selection_updating = true;
|
|
1467
1641
|
this.tabulator.deselectRow();
|
|
1468
1642
|
this.tabulator.selectRow(indices);
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1643
|
+
// Scroll once, to the last selected row that is displayed (e.g. on the current page).
|
|
1644
|
+
const displayed = new Set(this.tabulator.rowManager.getDisplayRows());
|
|
1645
|
+
for (let i = indices.length - 1; i >= 0; i--) {
|
|
1646
|
+
const row = this.tabulator.rowManager.findRow(indices[i]);
|
|
1647
|
+
if (row && displayed.has(row)) {
|
|
1648
|
+
this.tabulator.scrollToRow(indices[i], "center", false).catch(() => { });
|
|
1649
|
+
break;
|
|
1473
1650
|
}
|
|
1474
1651
|
}
|
|
1475
1652
|
this._selection_updating = false;
|
|
@@ -1591,14 +1768,12 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
1591
1768
|
this._selection_updating = false;
|
|
1592
1769
|
}
|
|
1593
1770
|
_filter_selected(indices) {
|
|
1594
|
-
const
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
this.model.selectable_rows.indexOf(ind) >= 0) {
|
|
1598
|
-
filtered.push(ind);
|
|
1599
|
-
}
|
|
1771
|
+
const selectable = this.model.selectable_rows;
|
|
1772
|
+
if (selectable == null) {
|
|
1773
|
+
return [...indices];
|
|
1600
1774
|
}
|
|
1601
|
-
|
|
1775
|
+
const selectable_set = as_set(selectable);
|
|
1776
|
+
return indices.filter((ind) => selectable_set.has(ind));
|
|
1602
1777
|
}
|
|
1603
1778
|
rowSelectionChanged(data, _row, selected, deselected) {
|
|
1604
1779
|
if (this._selection_updating ||
|
|
@@ -1634,7 +1809,9 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
1634
1809
|
const index = cell.getData()._index;
|
|
1635
1810
|
const value = cell._cell.value;
|
|
1636
1811
|
const key = `${field}:${index}`;
|
|
1637
|
-
|
|
1812
|
+
const column = this.model.source.get_column(field);
|
|
1813
|
+
const nullable = Array.isArray(column) || column instanceof Float64Array || column instanceof Float32Array;
|
|
1814
|
+
if (nullable && (column_def.validator === "numeric" || column_def.validator === "integer") && value === "") {
|
|
1638
1815
|
// setValue below re-triggers cellEdited recursively for the actual
|
|
1639
1816
|
// (NaN) edit. By then cell._cell.oldValue has already been overwritten
|
|
1640
1817
|
// with this now-discarded "" attempt, so the true pre-edit value is
|
|
@@ -1658,6 +1835,7 @@ export class DataTabulatorView extends HTMLBoxView {
|
|
|
1658
1835
|
comm_settings.debounce = true;
|
|
1659
1836
|
this._tabulator_cell_updating = false;
|
|
1660
1837
|
}
|
|
1838
|
+
this.refitColumns(field);
|
|
1661
1839
|
this.tabulator.scrollToRow(index, "top", false);
|
|
1662
1840
|
}
|
|
1663
1841
|
}
|