Skip to content

Commit

Permalink
Fix support for copying cells and creating new views in JupyterLab (#…
Browse files Browse the repository at this point in the history
…3652)

* Fix support for copying cells and creating new views in JupyterLab

* Ensure views are synced
  • Loading branch information
philippjfr authored Jun 27, 2022
1 parent 33df87c commit aff35e4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
9 changes: 9 additions & 0 deletions panel/_templates/doc_nb_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
var docs_json = {{ docs_json }};
var render_items = {{ render_items }};
root.Bokeh.embed.embed_items_notebook(docs_json, render_items);
for (const render_item of render_items) {
for (const root_id of render_item.root_ids) {
const id_el = document.getElementById(root_id)
if (id_el.children.length && (id_el.children[0].className === 'bk-root')) {
const root_el = id_el.children[0]
root_el.id = root_el.id + '-rendered'
}
}
}
}
if (root.Bokeh !== undefined && root.Bokeh.Panel !== undefined{% for reqs in requirements %} && ({% for req in reqs %}{% if loop.index0 > 0 %}||{% endif %} root['{{ req }}'] !== undefined{% endfor %}){% endfor %}{% if ipywidget %}&& (root.Bokeh.Models.registered_names().indexOf("ipywidgets_bokeh.widget.IPyWidget") > -1){% endif %}) {
embed_document(root);
Expand Down
23 changes: 22 additions & 1 deletion panel/models/comm_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,20 @@ export class CommManager extends Model {
console.log("Could not find comm manager on window.PyViz, ensure the extension is loaded.")
else {
this.ns = (window as any).PyViz
this.ns.comm_manager.register_target(this.plot_id, this.comm_id, (msg: any) => this.msg_handler(msg))
this.ns.comm_manager.register_target(this.plot_id, this.comm_id, (msg: any) => {
for (const view of this.ns.shared_views.get(this.plot_id)) {
if (view !== this)
view.msg_handler(msg)
}
this.msg_handler(msg)
})
this._client_comm = this.ns.comm_manager.get_client_comm(this.plot_id, this.client_comm_id, (msg: any) => this.on_ack(msg));
if (this.ns.shared_views == null)
this.ns.shared_views = new Map()
if (this.ns.shared_views.has(this.plot_id))
this.ns.shared_views.get(this.plot_id).push(this)
else
this.ns.shared_views.set(this.plot_id, [this])
}
}

Expand Down Expand Up @@ -87,6 +99,15 @@ export class CommManager extends Model {
this._event_buffer = [];
const message = Message.create('PATCH-DOC', {}, patch)
this._client_comm.send(message)
for (const view of this.ns.shared_views.get(this.plot_id)) {
if (view !== this)
view.document.apply_json_patch(patch, [], this.id)
}
}

disconnect_signals(): void {
super.disconnect_signals()
this.ns.shared_views.shared_views.delete(this.plot_id)
}

on_ack(msg: any) {
Expand Down

0 comments on commit aff35e4

Please sign in to comment.