@holoviz/panel 1.10.0-b.1 → 1.10.0-b.2
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/licenses/index.json +2 -2
- package/dist/css/codeeditor_mui.css +11 -0
- package/dist/css/dataframe_mui.css +46 -0
- package/dist/css/filedropper_mui.css +33 -0
- package/dist/css/json_mui.css +38 -0
- package/dist/css/jsoneditor_mui.css +114 -0
- package/dist/css/loading.css +9 -1
- package/dist/css/markdown_mui.css +45 -0
- package/dist/css/models/tabulator.css +4 -0
- package/dist/css/tabulator_mui.css +186 -0
- package/dist/css/terminal_mui.css +5 -0
- package/dist/css/texteditor_mui.css +76 -0
- package/dist/dts/styles/codeeditor_mui.css.d.ts +4 -0
- package/dist/dts/styles/dataframe_mui.css.d.ts +4 -0
- package/dist/dts/styles/filedropper_mui.css.d.ts +5 -0
- package/dist/dts/styles/json_mui.css.d.ts +4 -0
- package/dist/dts/styles/jsoneditor_mui.css.d.ts +4 -0
- package/dist/dts/styles/markdown_mui.css.d.ts +4 -0
- package/dist/dts/styles/tabulator_mui.css.d.ts +4 -0
- package/dist/dts/styles/terminal_mui.css.d.ts +4 -0
- package/dist/dts/styles/texteditor_mui.css.d.ts +4 -0
- package/dist/lib/models/anywidget_component.d.ts +1 -1
- package/dist/lib/models/anywidget_component.js +13 -14
- package/dist/lib/models/anywidget_component.js.map +1 -1
- package/dist/lib/models/cell_formatters.d.ts +9 -0
- package/dist/lib/models/cell_formatters.js +174 -0
- package/dist/lib/models/cell_formatters.js.map +1 -0
- package/dist/lib/models/html.d.ts +42 -2
- package/dist/lib/models/html.js +287 -22
- package/dist/lib/models/html.js.map +1 -1
- package/dist/lib/models/index.d.ts +1 -1
- package/dist/lib/models/index.js +1 -1
- package/dist/lib/models/index.js.map +1 -1
- package/dist/lib/models/layout.d.ts +17 -6
- package/dist/lib/models/layout.js +75 -45
- package/dist/lib/models/layout.js.map +1 -1
- package/dist/lib/models/react_component.d.ts +12 -2
- package/dist/lib/models/react_component.js +468 -370
- package/dist/lib/models/react_component.js.map +1 -1
- package/dist/lib/models/reactive_esm.d.ts +59 -5
- package/dist/lib/models/reactive_esm.js +347 -211
- package/dist/lib/models/reactive_esm.js.map +1 -1
- package/dist/lib/models/resources.js +11 -4
- package/dist/lib/models/resources.js.map +1 -1
- package/dist/lib/models/tabulator.d.ts +25 -3
- package/dist/lib/models/tabulator.js +100 -74
- package/dist/lib/models/tabulator.js.map +1 -1
- package/dist/lib/models/vtk/util.d.ts +1 -1
- package/dist/lib/models/vtk/vtkaxes.js +25 -7
- package/dist/lib/models/vtk/vtkaxes.js.map +1 -1
- package/dist/lib/styles/codeeditor_mui.css.d.ts +2 -0
- package/dist/lib/styles/codeeditor_mui.css.js +1 -0
- package/dist/lib/styles/dataframe_mui.css.d.ts +2 -0
- package/dist/lib/styles/dataframe_mui.css.js +1 -0
- package/dist/lib/styles/filedropper_mui.css.d.ts +3 -0
- package/dist/lib/styles/filedropper_mui.css.js +2 -0
- package/dist/lib/styles/json_mui.css.d.ts +2 -0
- package/dist/lib/styles/json_mui.css.js +1 -0
- package/dist/lib/styles/jsoneditor_mui.css.d.ts +2 -0
- package/dist/lib/styles/jsoneditor_mui.css.js +1 -0
- package/dist/lib/styles/loading.css.js +4 -1
- package/dist/lib/styles/markdown_mui.css.d.ts +2 -0
- package/dist/lib/styles/markdown_mui.css.js +1 -0
- package/dist/lib/styles/models/tabulator.css.js +1 -1
- package/dist/lib/styles/tabulator_mui.css.d.ts +2 -0
- package/dist/lib/styles/tabulator_mui.css.js +75 -0
- package/dist/lib/styles/terminal_mui.css.d.ts +2 -0
- package/dist/lib/styles/terminal_mui.css.js +1 -0
- package/dist/lib/styles/texteditor_mui.css.d.ts +2 -0
- package/dist/lib/styles/texteditor_mui.css.js +1 -0
- package/dist/panel.js +1776 -7483
- package/dist/panel.js.map +1 -1
- package/dist/panel.json +1 -1
- package/dist/panel.min.js +45 -50
- package/package.json +3 -4
|
@@ -16,7 +16,7 @@ import { isArray } from "@bokehjs/core/util/types";
|
|
|
16
16
|
import { UIElementView } from "@bokehjs/models/ui/ui_element";
|
|
17
17
|
import { serializeEvent } from "./event-to-object";
|
|
18
18
|
import { DOMEvent } from "./html";
|
|
19
|
-
import { HTMLBox, HTMLBoxView, set_size } from "./layout";
|
|
19
|
+
import { HTMLBox, HTMLBoxView, rerender_view, set_size } from "./layout";
|
|
20
20
|
import { resources } from "./resources";
|
|
21
21
|
import { convertUndefined, formatError } from "./util";
|
|
22
22
|
import esm_css from "styles/models/esm.css";
|
|
@@ -24,6 +24,21 @@ import esm_css from "styles/models/esm.css";
|
|
|
24
24
|
// its keys are logical (class name plus source length), so two Panel
|
|
25
25
|
// versions on one page must not be able to satisfy each other from it.
|
|
26
26
|
const MODULE_CACHE = new Map();
|
|
27
|
+
// Transpiled source by model type and module cache key, so instances of one
|
|
28
|
+
// component class do not each run sucrase over the same source.
|
|
29
|
+
const COMPILE_CACHE = new Map();
|
|
30
|
+
// Interns ESM sources so cache keys stay short and cannot collide, unlike
|
|
31
|
+
// keys derived from the source length.
|
|
32
|
+
const SOURCE_IDS = new Map();
|
|
33
|
+
const DECLARED_IMPORTMAPS = new Set();
|
|
34
|
+
function source_id(source) {
|
|
35
|
+
let id = SOURCE_IDS.get(source);
|
|
36
|
+
if (id === undefined) {
|
|
37
|
+
id = SOURCE_IDS.size;
|
|
38
|
+
SOURCE_IDS.set(source, id);
|
|
39
|
+
}
|
|
40
|
+
return id;
|
|
41
|
+
}
|
|
27
42
|
export class DataEvent extends ModelEvent {
|
|
28
43
|
data;
|
|
29
44
|
constructor(data) {
|
|
@@ -49,7 +64,31 @@ ESMEvent = ESMEvent_1 = __decorate([
|
|
|
49
64
|
server_event("esm_event")
|
|
50
65
|
], ESMEvent);
|
|
51
66
|
export { ESMEvent };
|
|
67
|
+
const PROXY_METHODS = new Set(["get_child", "send_msg", "send_event", "off", "on"]);
|
|
52
68
|
export function model_getter(target, name) {
|
|
69
|
+
const model = target.model;
|
|
70
|
+
if (PROXY_METHODS.has(name)) {
|
|
71
|
+
// Cached so the methods are stable across accesses, e.g. as hook
|
|
72
|
+
// dependencies, instead of a new closure per property read.
|
|
73
|
+
let method = target._proxy_methods.get(name);
|
|
74
|
+
if (method === undefined) {
|
|
75
|
+
method = proxy_method(target, name);
|
|
76
|
+
target._proxy_methods.set(name, method);
|
|
77
|
+
}
|
|
78
|
+
return method;
|
|
79
|
+
}
|
|
80
|
+
else if (Reflect.has(model.data, name)) {
|
|
81
|
+
if (name in model.data.attributes && !target.accessed_properties.includes(name)) {
|
|
82
|
+
target.accessed_properties.push(name);
|
|
83
|
+
}
|
|
84
|
+
return Reflect.get(model.data, name);
|
|
85
|
+
}
|
|
86
|
+
else if (Reflect.has(model, name)) {
|
|
87
|
+
return Reflect.get(model, name);
|
|
88
|
+
}
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
function proxy_method(target, name) {
|
|
53
92
|
const model = target.model;
|
|
54
93
|
if (name === "get_child") {
|
|
55
94
|
return (child) => {
|
|
@@ -136,16 +175,7 @@ export function model_getter(target, name) {
|
|
|
136
175
|
}
|
|
137
176
|
};
|
|
138
177
|
}
|
|
139
|
-
|
|
140
|
-
if (name in model.data.attributes && !target.accessed_properties.includes(name)) {
|
|
141
|
-
target.accessed_properties.push(name);
|
|
142
|
-
}
|
|
143
|
-
return Reflect.get(model.data, name);
|
|
144
|
-
}
|
|
145
|
-
else if (Reflect.has(model, name)) {
|
|
146
|
-
return Reflect.get(model, name);
|
|
147
|
-
}
|
|
148
|
-
return undefined;
|
|
178
|
+
throw new Error(`unknown proxy method '${name}'`);
|
|
149
179
|
}
|
|
150
180
|
export function model_setter(target, name, value) {
|
|
151
181
|
const model = target.model;
|
|
@@ -174,6 +204,29 @@ function init_model_setter(target, name, value) {
|
|
|
174
204
|
}
|
|
175
205
|
return false;
|
|
176
206
|
}
|
|
207
|
+
function render_esm_view(view) {
|
|
208
|
+
if (view.is_destroyed) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const output = view.render_fn({
|
|
212
|
+
view, model: view.model_proxy, data: view.model.data, el: view.container,
|
|
213
|
+
});
|
|
214
|
+
Promise.resolve(output).then((out) => {
|
|
215
|
+
if (out instanceof Element) {
|
|
216
|
+
view.container.replaceChildren(out);
|
|
217
|
+
}
|
|
218
|
+
view.after_rendered();
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
// Resolved values of render module promises, so a view whose module has
|
|
222
|
+
// already loaded can render synchronously instead of a microtask later.
|
|
223
|
+
const RESOLVED_MODULES = new WeakMap();
|
|
224
|
+
function track_module(module) {
|
|
225
|
+
module.then((value) => RESOLVED_MODULES.set(module, value), () => { });
|
|
226
|
+
return module;
|
|
227
|
+
}
|
|
228
|
+
const ESM_RENDER_MODULE = track_module(Promise.resolve({ default: { render: render_esm_view } }));
|
|
229
|
+
const PENDING_FINISHED = new Set();
|
|
177
230
|
export class ReactiveESMView extends HTMLBoxView {
|
|
178
231
|
container;
|
|
179
232
|
accessed_properties = [];
|
|
@@ -196,6 +249,9 @@ export class ReactiveESMView extends HTMLBoxView {
|
|
|
196
249
|
_stale_children = false;
|
|
197
250
|
_mounted = new Map();
|
|
198
251
|
_update_children_chain = Promise.resolve();
|
|
252
|
+
_layout_pending = false;
|
|
253
|
+
_proxy_methods = new Map();
|
|
254
|
+
_last_size = null;
|
|
199
255
|
initialize() {
|
|
200
256
|
super.initialize();
|
|
201
257
|
this._module_cache = MODULE_CACHE;
|
|
@@ -236,22 +292,19 @@ export class ReactiveESMView extends HTMLBoxView {
|
|
|
236
292
|
for (const cp of child_props) {
|
|
237
293
|
this.connect(cp.change, () => this.update_children());
|
|
238
294
|
}
|
|
239
|
-
this.
|
|
240
|
-
if (this.model.render_policy !== "manual") {
|
|
241
|
-
this.render_esm();
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
this.model.on_event(ESMEvent, (event) => {
|
|
245
|
-
for (const cb of this._event_handlers) {
|
|
246
|
-
cb(event.data);
|
|
247
|
-
}
|
|
248
|
-
});
|
|
295
|
+
this.model._event_views.add(this);
|
|
249
296
|
}
|
|
250
297
|
disconnect_signals() {
|
|
251
298
|
super.disconnect_signals();
|
|
252
299
|
this._child_callbacks = new Map();
|
|
300
|
+
this.model._event_views.delete(this);
|
|
253
301
|
this.model.disconnect_watchers(this);
|
|
254
302
|
}
|
|
303
|
+
_dispatch_event(data) {
|
|
304
|
+
for (const cb of this._event_handlers) {
|
|
305
|
+
cb(data);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
255
308
|
_on_mounted() { }
|
|
256
309
|
/**
|
|
257
310
|
* Bokeh walks the whole view tree from `r_after_render`, but ESM components
|
|
@@ -296,7 +349,10 @@ export class ReactiveESMView extends HTMLBoxView {
|
|
|
296
349
|
if (!isArray(children)) {
|
|
297
350
|
children = [children];
|
|
298
351
|
}
|
|
299
|
-
|
|
352
|
+
const mounted = this._mounted.get(child);
|
|
353
|
+
// The size check skips the full scan while children are still mounting,
|
|
354
|
+
// which would otherwise make mounting a list quadratic in its length.
|
|
355
|
+
if (mounted.size >= children.length && children.every((model) => mounted.has(model.id))) {
|
|
300
356
|
this._on_mounted();
|
|
301
357
|
for (const cb of this._lifecycle_handlers.get("mounted") || []) {
|
|
302
358
|
cb(child);
|
|
@@ -379,7 +435,39 @@ export class ReactiveESMView extends HTMLBoxView {
|
|
|
379
435
|
get is_managed() {
|
|
380
436
|
return this.parent instanceof LayoutDOMView && !(this.parent instanceof ReactiveESMView);
|
|
381
437
|
}
|
|
438
|
+
/**
|
|
439
|
+
* Renders a child without laying it out and schedules a single layout pass
|
|
440
|
+
* instead. Children mount one at a time (e.g. once per React
|
|
441
|
+
* `componentDidMount`), and a child's `compute_layout` lays out, and so
|
|
442
|
+
* measures, the whole tree; doing that per child is quadratic in the
|
|
443
|
+
* number of children.
|
|
444
|
+
*/
|
|
445
|
+
render_child(view) {
|
|
446
|
+
rerender_view(view, false);
|
|
447
|
+
this.schedule_layout();
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Lays out once all synchronous work queued in the current task (such as
|
|
451
|
+
* a React commit mounting every child) has run. A pass that happens in the
|
|
452
|
+
* meantime, e.g. `_on_mounted`'s, makes the scheduled one a no-op.
|
|
453
|
+
*/
|
|
454
|
+
schedule_layout() {
|
|
455
|
+
if (this._layout_pending) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
this._layout_pending = true;
|
|
459
|
+
queueMicrotask(() => {
|
|
460
|
+
if (!this._layout_pending || this.is_destroyed) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
this.compute_layout();
|
|
464
|
+
// `finish()` may already have run and found the layout missing, and
|
|
465
|
+
// nothing else re-checks once it exists.
|
|
466
|
+
this.notify_finished();
|
|
467
|
+
});
|
|
468
|
+
}
|
|
382
469
|
compute_layout() {
|
|
470
|
+
this._layout_pending = false;
|
|
383
471
|
if (this.is_managed) {
|
|
384
472
|
super.compute_layout();
|
|
385
473
|
return;
|
|
@@ -408,6 +496,17 @@ export class ReactiveESMView extends HTMLBoxView {
|
|
|
408
496
|
})();
|
|
409
497
|
// Override private property
|
|
410
498
|
this._is_displayed = displayed;
|
|
499
|
+
// `after_resize` lays out the whole root whenever this reports a change.
|
|
500
|
+
// Reporting only actual size changes lets the first sibling's root pass,
|
|
501
|
+
// which visits every view, absorb the resize callbacks of all the others;
|
|
502
|
+
// always reporting one made initial render quadratic in sibling count.
|
|
503
|
+
const width = displayed ? this.el.offsetWidth : 0;
|
|
504
|
+
const height = displayed ? this.el.offsetHeight : 0;
|
|
505
|
+
const last = this._last_size;
|
|
506
|
+
if (last != null && last[0] === width && last[1] === height) {
|
|
507
|
+
return false;
|
|
508
|
+
}
|
|
509
|
+
this._last_size = [width, height];
|
|
411
510
|
return true;
|
|
412
511
|
}
|
|
413
512
|
after_rendered() {
|
|
@@ -434,7 +533,10 @@ export class ReactiveESMView extends HTMLBoxView {
|
|
|
434
533
|
(this._lifecycle_handlers.get(lf) || []).splice(0);
|
|
435
534
|
}
|
|
436
535
|
this.model.disconnect_watchers(this);
|
|
437
|
-
|
|
536
|
+
// The view is passed rather than looked up by id: `Bokeh.index` lookups
|
|
537
|
+
// walk every view on the page and pick the first view of a model that
|
|
538
|
+
// is displayed more than once.
|
|
539
|
+
const render_promise = this.model.render_module.then((mod) => mod.default.render(this));
|
|
438
540
|
this._await_ready(render_promise);
|
|
439
541
|
}
|
|
440
542
|
render_children() {
|
|
@@ -449,7 +551,7 @@ export class ReactiveESMView extends HTMLBoxView {
|
|
|
449
551
|
const parent = view.el.parentNode;
|
|
450
552
|
if (parent) {
|
|
451
553
|
this._child_rendered.set(view, false);
|
|
452
|
-
this.
|
|
554
|
+
this.render_child(view);
|
|
453
555
|
this._child_rendered.set(view, true);
|
|
454
556
|
}
|
|
455
557
|
}
|
|
@@ -465,19 +567,45 @@ export class ReactiveESMView extends HTMLBoxView {
|
|
|
465
567
|
return false;
|
|
466
568
|
}
|
|
467
569
|
for (const child_view of this.child_views) {
|
|
468
|
-
if (
|
|
570
|
+
if (this._child_rendered.has(child_view) && !child_view.has_finished()) {
|
|
469
571
|
return false;
|
|
470
572
|
}
|
|
471
573
|
}
|
|
472
574
|
return true;
|
|
473
575
|
}
|
|
576
|
+
/**
|
|
577
|
+
* Each notification makes the root walk the whole tree in `has_finished`,
|
|
578
|
+
* and every component and child reports finishing separately, so loading
|
|
579
|
+
* N components would walk the tree N times. Notifications issued in the
|
|
580
|
+
* same task are coalesced into one per root.
|
|
581
|
+
*/
|
|
582
|
+
notify_finished() {
|
|
583
|
+
if (this.is_root) {
|
|
584
|
+
super.notify_finished();
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
const root = this.root;
|
|
588
|
+
if (PENDING_FINISHED.has(root)) {
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
PENDING_FINISHED.add(root);
|
|
592
|
+
queueMicrotask(() => {
|
|
593
|
+
PENDING_FINISHED.delete(root);
|
|
594
|
+
if (!root.is_destroyed) {
|
|
595
|
+
root.notify_finished();
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
}
|
|
474
599
|
invalidate_layout() {
|
|
475
600
|
if (this.is_managed) {
|
|
476
601
|
super.invalidate_layout();
|
|
477
602
|
return;
|
|
478
603
|
}
|
|
604
|
+
// Deferred so that the children of one parent, which each invalidate on
|
|
605
|
+
// render, do not interleave DOM writes with the measurements of their
|
|
606
|
+
// own layout passes, forcing a reflow per child.
|
|
479
607
|
this.update_layout();
|
|
480
|
-
this.
|
|
608
|
+
this.schedule_layout();
|
|
481
609
|
}
|
|
482
610
|
remove() {
|
|
483
611
|
super.remove();
|
|
@@ -504,17 +632,21 @@ export class ReactiveESMView extends HTMLBoxView {
|
|
|
504
632
|
}
|
|
505
633
|
}
|
|
506
634
|
}
|
|
507
|
-
|
|
635
|
+
/**
|
|
636
|
+
* Maps each child model to the name of the children property holding it,
|
|
637
|
+
* built once per update pass rather than searched per child view.
|
|
638
|
+
*/
|
|
639
|
+
_child_names() {
|
|
640
|
+
const names = new Map();
|
|
508
641
|
for (const child of this.model.children) {
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
return child;
|
|
642
|
+
const models = this.model.data[child];
|
|
643
|
+
for (const model of isArray(models) ? models : [models]) {
|
|
644
|
+
if (model != null && !names.has(model)) {
|
|
645
|
+
names.set(model, child);
|
|
514
646
|
}
|
|
515
647
|
}
|
|
516
648
|
}
|
|
517
|
-
return
|
|
649
|
+
return names;
|
|
518
650
|
}
|
|
519
651
|
/**
|
|
520
652
|
* A children property can trigger more than one update pass for the same
|
|
@@ -532,32 +664,42 @@ export class ReactiveESMView extends HTMLBoxView {
|
|
|
532
664
|
this._update_children_chain = run.then(() => undefined, () => undefined);
|
|
533
665
|
return run;
|
|
534
666
|
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
child_view.el.remove();
|
|
541
|
-
}
|
|
542
|
-
}
|
|
667
|
+
/**
|
|
668
|
+
* Groups newly created child views by the children property they belong to.
|
|
669
|
+
*/
|
|
670
|
+
_group_new_views(created) {
|
|
671
|
+
const names = this._child_names();
|
|
543
672
|
const new_views = new Map();
|
|
544
673
|
for (const child_view of this.child_views) {
|
|
545
|
-
if (!
|
|
674
|
+
if (!created.has(child_view)) {
|
|
546
675
|
continue;
|
|
547
676
|
}
|
|
548
|
-
const child =
|
|
549
|
-
if (
|
|
677
|
+
const child = names.get(child_view.model);
|
|
678
|
+
if (child == null) {
|
|
550
679
|
continue;
|
|
551
680
|
}
|
|
552
|
-
|
|
553
|
-
|
|
681
|
+
const views = new_views.get(child);
|
|
682
|
+
if (views == null) {
|
|
683
|
+
new_views.set(child, [child_view]);
|
|
554
684
|
}
|
|
555
685
|
else {
|
|
556
|
-
|
|
686
|
+
views.push(child_view);
|
|
557
687
|
}
|
|
558
688
|
}
|
|
689
|
+
return new_views;
|
|
690
|
+
}
|
|
691
|
+
async _update_children_pass() {
|
|
692
|
+
const created_children = new Set(await this.build_child_views());
|
|
693
|
+
const all_views = this.child_views;
|
|
694
|
+
if (this.model.render_policy !== "manual") {
|
|
695
|
+
for (const child_view of all_views) {
|
|
696
|
+
child_view.el.remove();
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
const new_views = this._group_new_views(created_children);
|
|
700
|
+
const current = new Set(all_views);
|
|
559
701
|
for (const view of this._child_rendered.keys()) {
|
|
560
|
-
if (!
|
|
702
|
+
if (!current.has(view)) {
|
|
561
703
|
this._child_rendered.delete(view);
|
|
562
704
|
}
|
|
563
705
|
}
|
|
@@ -605,8 +747,10 @@ export class ReactiveESM extends HTMLBox {
|
|
|
605
747
|
render_module = null;
|
|
606
748
|
sucrase_transforms = ["typescript"];
|
|
607
749
|
_destroyer = null;
|
|
608
|
-
|
|
609
|
-
|
|
750
|
+
// Keyed by the watched path; `orig` is the callback the caller passed,
|
|
751
|
+
// `cb` the wrapper actually connected to `signal`.
|
|
752
|
+
_esm_watchers = new Map();
|
|
753
|
+
_event_views = new Set();
|
|
610
754
|
constructor(attrs) {
|
|
611
755
|
super(attrs);
|
|
612
756
|
}
|
|
@@ -622,171 +766,159 @@ export class ReactiveESM extends HTMLBox {
|
|
|
622
766
|
super.connect_signals();
|
|
623
767
|
this.connect(this.properties.esm.change, () => this.recompile());
|
|
624
768
|
this.connect(this.properties.importmap.change, () => this.recompile());
|
|
769
|
+
// Registered once per model: `on_event` cannot be undone, so views
|
|
770
|
+
// subscribe through `_event_views` instead.
|
|
771
|
+
this.on_event(ESMEvent, (event) => {
|
|
772
|
+
for (const view of this._event_views) {
|
|
773
|
+
view._dispatch_event(event.data);
|
|
774
|
+
}
|
|
775
|
+
});
|
|
625
776
|
}
|
|
626
|
-
|
|
627
|
-
|
|
777
|
+
/**
|
|
778
|
+
* Resolves a possibly dotted property path to the property's change
|
|
779
|
+
* signal and the model owning it, falling back to the component model's
|
|
780
|
+
* own properties.
|
|
781
|
+
*/
|
|
782
|
+
_resolve_watch(prop) {
|
|
783
|
+
const path = prop.split(".");
|
|
628
784
|
let target = this.data;
|
|
629
|
-
let
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
target = target[propPath[i]];
|
|
785
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
786
|
+
if (target != null && target.properties != null && path[i] in target.properties) {
|
|
787
|
+
target = target[path[i]];
|
|
633
788
|
}
|
|
634
789
|
else {
|
|
635
|
-
// Break if any level of the path is invalid
|
|
636
790
|
target = null;
|
|
637
791
|
break;
|
|
638
792
|
}
|
|
639
793
|
}
|
|
640
|
-
|
|
641
|
-
|
|
794
|
+
const name = path[path.length - 1];
|
|
795
|
+
if (target != null && target.properties != null && name in target.properties) {
|
|
796
|
+
return { target, name, signal: target.property(name).change };
|
|
797
|
+
}
|
|
798
|
+
else if (prop in this.properties) {
|
|
799
|
+
return { target: this, name: prop, signal: this.property(prop).change };
|
|
800
|
+
}
|
|
801
|
+
return null;
|
|
802
|
+
}
|
|
803
|
+
watch(view, prop, cb, force = false) {
|
|
804
|
+
const resolved = this._resolve_watch(prop);
|
|
805
|
+
if (resolved == null) {
|
|
806
|
+
return;
|
|
642
807
|
}
|
|
808
|
+
const { target, name, signal } = resolved;
|
|
809
|
+
const orig = cb;
|
|
643
810
|
// Handle reset of param.Event properties
|
|
644
|
-
if (!force && target === this.data &&
|
|
645
|
-
const
|
|
811
|
+
if (!force && target === this.data && this.events.includes(name)) {
|
|
812
|
+
const event_cb = cb;
|
|
646
813
|
cb = () => {
|
|
647
|
-
if (
|
|
648
|
-
|
|
649
|
-
this.data.setv({ [
|
|
814
|
+
if (this.data[name]) {
|
|
815
|
+
event_cb();
|
|
816
|
+
this.data.setv({ [name]: false });
|
|
650
817
|
}
|
|
651
818
|
};
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
orig_cb();
|
|
679
|
-
view.render_children();
|
|
680
|
-
view._update_children();
|
|
681
|
-
view.invalidate_layout();
|
|
682
|
-
// Collect ready promises from all newly rendered descendants
|
|
683
|
-
const collect_ready = (v) => {
|
|
684
|
-
const promises = [v.ready];
|
|
685
|
-
for (const child of v.child_views || []) {
|
|
686
|
-
promises.push(...collect_ready(child));
|
|
687
|
-
}
|
|
688
|
-
return promises;
|
|
689
|
-
};
|
|
690
|
-
const all_ready = [];
|
|
691
|
-
for (const child_view of view.child_views) {
|
|
692
|
-
all_ready.push(...collect_ready(child_view));
|
|
693
|
-
}
|
|
694
|
-
if (all_ready.length > 0) {
|
|
695
|
-
Promise.all(all_ready).then(() => resolve_ready());
|
|
696
|
-
}
|
|
697
|
-
else {
|
|
698
|
-
resolve_ready();
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
else {
|
|
702
|
-
orig_cb();
|
|
819
|
+
}
|
|
820
|
+
if (target === this.data && this.children.includes(name)) {
|
|
821
|
+
const children_cb = cb;
|
|
822
|
+
cb = async () => {
|
|
823
|
+
if (view == null) {
|
|
824
|
+
children_cb();
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
view._stale_children = true;
|
|
828
|
+
// The view connected `update_children` to this signal before any
|
|
829
|
+
// watcher, so the pass handling this change is already queued.
|
|
830
|
+
await view._update_children_chain;
|
|
831
|
+
if (this.render_policy !== "manual") {
|
|
832
|
+
children_cb();
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
let resolve_ready;
|
|
836
|
+
view.root._await_ready(new Promise((r) => { resolve_ready = r; }));
|
|
837
|
+
children_cb();
|
|
838
|
+
view.render_children();
|
|
839
|
+
view._update_children();
|
|
840
|
+
view.invalidate_layout();
|
|
841
|
+
const collect_ready = (v) => {
|
|
842
|
+
const promises = [v.ready];
|
|
843
|
+
for (const child of v.child_views || []) {
|
|
844
|
+
promises.push(...collect_ready(child));
|
|
703
845
|
}
|
|
846
|
+
return promises;
|
|
704
847
|
};
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
848
|
+
const all_ready = [];
|
|
849
|
+
for (const child_view of view.child_views) {
|
|
850
|
+
all_ready.push(...collect_ready(child_view));
|
|
851
|
+
}
|
|
852
|
+
if (all_ready.length > 0) {
|
|
853
|
+
Promise.all(all_ready).then(() => resolve_ready());
|
|
854
|
+
}
|
|
855
|
+
else {
|
|
856
|
+
resolve_ready();
|
|
857
|
+
}
|
|
858
|
+
};
|
|
710
859
|
}
|
|
711
|
-
|
|
712
|
-
|
|
860
|
+
signal.connect(cb);
|
|
861
|
+
const watchers = this._esm_watchers.get(prop);
|
|
862
|
+
const watcher = { view, orig, cb, signal };
|
|
863
|
+
if (watchers == null) {
|
|
864
|
+
this._esm_watchers.set(prop, [watcher]);
|
|
713
865
|
}
|
|
714
866
|
else {
|
|
715
|
-
|
|
867
|
+
watchers.push(watcher);
|
|
716
868
|
}
|
|
717
869
|
}
|
|
718
870
|
unwatch(view, prop, cb) {
|
|
719
|
-
|
|
871
|
+
const watchers = this._esm_watchers.get(prop);
|
|
872
|
+
if (watchers == null) {
|
|
720
873
|
return false;
|
|
721
874
|
}
|
|
722
|
-
|
|
875
|
+
let disconnected = false;
|
|
723
876
|
const remaining = [];
|
|
724
|
-
for (const
|
|
725
|
-
if (
|
|
726
|
-
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
// Update or delete watcher list
|
|
730
|
-
if (remaining.length > 0) {
|
|
731
|
-
this._esm_watchers[prop] = remaining;
|
|
732
|
-
}
|
|
733
|
-
else {
|
|
734
|
-
delete this._esm_watchers[prop];
|
|
735
|
-
}
|
|
736
|
-
// Resolve nested properties
|
|
737
|
-
const propPath = prop.split(".");
|
|
738
|
-
let target = this.data;
|
|
739
|
-
let resolvedProp = null;
|
|
740
|
-
for (let i = 0; i < propPath.length - 1; i++) {
|
|
741
|
-
if (target && target.properties && propPath[i] in target.properties) {
|
|
742
|
-
target = target[propPath[i]];
|
|
877
|
+
for (const watcher of watchers) {
|
|
878
|
+
if (watcher.view === view && watcher.orig === cb) {
|
|
879
|
+
disconnected = watcher.signal.disconnect(watcher.cb) || disconnected;
|
|
743
880
|
}
|
|
744
881
|
else {
|
|
745
|
-
|
|
746
|
-
target = null;
|
|
747
|
-
break;
|
|
882
|
+
remaining.push(watcher);
|
|
748
883
|
}
|
|
749
884
|
}
|
|
750
|
-
if (
|
|
751
|
-
|
|
752
|
-
}
|
|
753
|
-
if (this._event_callbacks.has(cb)) {
|
|
754
|
-
cb = this._event_callbacks.get(cb);
|
|
755
|
-
this._event_callbacks.delete(cb);
|
|
756
|
-
}
|
|
757
|
-
// Detach watcher if property is found
|
|
758
|
-
if (resolvedProp && target) {
|
|
759
|
-
return target.property(resolvedProp).change.disconnect(cb);
|
|
885
|
+
if (remaining.length > 0) {
|
|
886
|
+
this._esm_watchers.set(prop, remaining);
|
|
760
887
|
}
|
|
761
|
-
else
|
|
762
|
-
|
|
888
|
+
else {
|
|
889
|
+
this._esm_watchers.delete(prop);
|
|
763
890
|
}
|
|
764
|
-
return
|
|
891
|
+
return disconnected;
|
|
765
892
|
}
|
|
766
893
|
disconnect_watchers(view) {
|
|
767
|
-
for (const
|
|
768
|
-
const prop = this.data.properties[p];
|
|
894
|
+
for (const [prop, watchers] of this._esm_watchers) {
|
|
769
895
|
const remaining = [];
|
|
770
|
-
for (const
|
|
771
|
-
if (
|
|
772
|
-
|
|
896
|
+
for (const watcher of watchers) {
|
|
897
|
+
if (watcher.view === view) {
|
|
898
|
+
watcher.signal.disconnect(watcher.cb);
|
|
773
899
|
}
|
|
774
900
|
else {
|
|
775
|
-
remaining.push(
|
|
901
|
+
remaining.push(watcher);
|
|
776
902
|
}
|
|
777
903
|
}
|
|
778
904
|
if (remaining.length > 0) {
|
|
779
|
-
this._esm_watchers
|
|
905
|
+
this._esm_watchers.set(prop, remaining);
|
|
780
906
|
}
|
|
781
907
|
else {
|
|
782
|
-
|
|
908
|
+
this._esm_watchers.delete(prop);
|
|
783
909
|
}
|
|
784
910
|
}
|
|
785
911
|
}
|
|
786
912
|
async _declare_importmap() {
|
|
787
913
|
await resources.ensure_shim(this.external_resources?.shim);
|
|
788
914
|
if (this.importmap) {
|
|
789
|
-
|
|
915
|
+
// Every instance of a component class carries the same map, and
|
|
916
|
+
// es-module-shims re-resolves the whole map on each addition.
|
|
917
|
+
const key = JSON.stringify(this.importmap);
|
|
918
|
+
if (!DECLARED_IMPORTMAPS.has(key)) {
|
|
919
|
+
DECLARED_IMPORTMAPS.add(key);
|
|
920
|
+
resources.add_import_map(this.importmap);
|
|
921
|
+
}
|
|
790
922
|
}
|
|
791
923
|
}
|
|
792
924
|
_run_initializer(initialize) {
|
|
@@ -803,40 +935,31 @@ export class ReactiveESM extends HTMLBox {
|
|
|
803
935
|
if (this.compile_error) {
|
|
804
936
|
return;
|
|
805
937
|
}
|
|
806
|
-
|
|
807
|
-
|
|
938
|
+
this.render_module = this._render_module();
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* The module whose `default.render(view)` renders a view of this model.
|
|
942
|
+
*/
|
|
943
|
+
_render_module() {
|
|
944
|
+
return ESM_RENDER_MODULE;
|
|
945
|
+
}
|
|
946
|
+
_cached_module(key, load) {
|
|
947
|
+
let module = MODULE_CACHE.get(key);
|
|
948
|
+
if (module == null) {
|
|
949
|
+
module = track_module(load());
|
|
950
|
+
MODULE_CACHE.set(key, module);
|
|
808
951
|
}
|
|
809
|
-
|
|
810
|
-
const code = this._render_code();
|
|
811
|
-
const render_url = URL.createObjectURL(new Blob([code], { type: "text/javascript" }));
|
|
812
|
-
this.render_module = resources.import_module(render_url, this.external_resources?.shim);
|
|
813
|
-
MODULE_CACHE.set(this._render_cache_key, this.render_module);
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
_render_code() {
|
|
817
|
-
return `
|
|
818
|
-
function render(id) {
|
|
819
|
-
const view = Bokeh.index.find_one_by_id(id)
|
|
820
|
-
if (view == null) {
|
|
821
|
-
return null
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
const output = view.render_fn({
|
|
825
|
-
view: view, model: view.model_proxy, data: view.model.data, el: view.container
|
|
826
|
-
})
|
|
827
|
-
|
|
828
|
-
Promise.resolve(output).then((out) => {
|
|
829
|
-
if (out instanceof Element) {
|
|
830
|
-
view.container.replaceChildren(out)
|
|
831
|
-
}
|
|
832
|
-
view.after_rendered()
|
|
833
|
-
})
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
export default {render}`;
|
|
952
|
+
return module;
|
|
837
953
|
}
|
|
838
|
-
get
|
|
839
|
-
return
|
|
954
|
+
get resolved_render_module() {
|
|
955
|
+
return this.render_module == null ? null : RESOLVED_MODULES.get(this.render_module) ?? null;
|
|
956
|
+
}
|
|
957
|
+
_import_source(code) {
|
|
958
|
+
const url = URL.createObjectURL(new Blob([code], { type: "text/javascript" }));
|
|
959
|
+
const module = resources.import_module(url, this.external_resources?.shim);
|
|
960
|
+
// Fetched by the time the import settles, and otherwise held until unload.
|
|
961
|
+
module.finally(() => URL.revokeObjectURL(url)).catch(() => { });
|
|
962
|
+
return module;
|
|
840
963
|
}
|
|
841
964
|
compile() {
|
|
842
965
|
if (this.bundle != null) {
|
|
@@ -866,21 +989,36 @@ export default {render}`;
|
|
|
866
989
|
}
|
|
867
990
|
return compiled;
|
|
868
991
|
}
|
|
992
|
+
get _module_cache_key() {
|
|
993
|
+
if (this.bundle === "url") {
|
|
994
|
+
return this.esm;
|
|
995
|
+
}
|
|
996
|
+
return this.bundle || `${this.class_name}-${source_id(this.esm)}`;
|
|
997
|
+
}
|
|
869
998
|
async recompile() {
|
|
870
999
|
this.compile_error = null;
|
|
871
|
-
const
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
1000
|
+
const use_cache = (!this.dev || this.bundle);
|
|
1001
|
+
// Not computed in dev mode, where every edit would be interned.
|
|
1002
|
+
const cache_key = use_cache ? this._module_cache_key : "";
|
|
1003
|
+
const compile_key = `${this.type}:${cache_key}`;
|
|
1004
|
+
let source = use_cache ? COMPILE_CACHE.get(compile_key) ?? null : null;
|
|
1005
|
+
if (source === null) {
|
|
1006
|
+
source = this.compile();
|
|
1007
|
+
if (source === null) {
|
|
1008
|
+
this.compiled_module = Promise.resolve(null);
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
if (use_cache) {
|
|
1012
|
+
COMPILE_CACHE.set(compile_key, source);
|
|
1013
|
+
}
|
|
875
1014
|
}
|
|
1015
|
+
const compiled = source;
|
|
876
1016
|
this.compiled = compiled;
|
|
877
1017
|
// Awaiting the import map here would leave compiled_module holding the
|
|
878
1018
|
// previous module for a tick, and a view handling the same esm change
|
|
879
1019
|
// awaits that property, so it has to be replaced synchronously.
|
|
880
1020
|
const declared = this._declare_importmap();
|
|
881
1021
|
let esm_module;
|
|
882
|
-
const use_cache = (!this.dev || this.bundle);
|
|
883
|
-
const cache_key = (this.bundle === "url") ? this.esm : (this.bundle || `${this.class_name}-${this.esm.length}`);
|
|
884
1022
|
let resolve;
|
|
885
1023
|
if (use_cache && MODULE_CACHE.has(cache_key)) {
|
|
886
1024
|
const cached = MODULE_CACHE.get(cache_key);
|
|
@@ -890,14 +1028,12 @@ export default {render}`;
|
|
|
890
1028
|
if (use_cache) {
|
|
891
1029
|
MODULE_CACHE.set(cache_key, new Promise((res) => { resolve = res; }));
|
|
892
1030
|
}
|
|
893
|
-
let url;
|
|
894
1031
|
if (this.bundle === "url") {
|
|
895
|
-
|
|
1032
|
+
esm_module = declared.then(() => resources.import_module(this.esm, this.external_resources?.shim));
|
|
896
1033
|
}
|
|
897
1034
|
else {
|
|
898
|
-
|
|
1035
|
+
esm_module = declared.then(() => this._import_source(compiled));
|
|
899
1036
|
}
|
|
900
|
-
esm_module = declared.then(() => resources.import_module(url, this.external_resources?.shim));
|
|
901
1037
|
}
|
|
902
1038
|
this.compiled_module = (esm_module).then((mod) => {
|
|
903
1039
|
if (resolve) {
|