Skip to content

yjs-widgets does not play well with Lumino widgets #8

@martinRenou

Description

@martinRenou

Issue

One cannot easily create a yjs-widgets based on Lumino. Because the node element that the Renderer provides is not yet attached:

class YJupyterCADWidget implements IJupyterYWidget {
  constructor(yModel: JupyterYModel, node: HTMLElement) {
    this.yModel = yModel;
    this.node = node;

    const widget = new LuminoWidget();

    // The following does not work! Because this.node is not yet attached to the DOM
    Widget.attach(widget, this.node);
  }

  yModel: JupyterYModel;
  node: HTMLElement;
}

Fix proposition

I would like to suggest modifying the JupyterYWidget to get closer to the logic we have in ipywidgets. Basically, the Widget class would be expected to have a node element that would either be a Lumino Widget:

  async renderModel(mimeModel: IRenderMime.IMimeModel): Promise<void> {
    const modelId = mimeModel.data[this._mimeType]!['model_id'];

    this._yModel = this._modelFactory.getYModel(modelId);
    if (!this._yModel) {
      return;
    }

    const widget = this._modelFactory.createYWidget(modelId);
    this.addWidget(widget.node)
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions