https://github.com/davidbrochart/yjs-widgets
a JupyterLab extension for widgets based on Yjs
https://github.com/davidbrochart/yjs-widgets
Last synced: 11 months ago
JSON representation
a JupyterLab extension for widgets based on Yjs
- Host: GitHub
- URL: https://github.com/davidbrochart/yjs-widgets
- Owner: davidbrochart
- License: bsd-3-clause
- Created: 2023-03-30T13:08:01.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-27T16:49:28.000Z (over 1 year ago)
- Last Synced: 2024-08-27T18:33:48.500Z (over 1 year ago)
- Language: TypeScript
- Size: 243 KB
- Stars: 4
- Watchers: 4
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# JupyterLab extension for widgets based on Yjs
## Requirements
- JupyterLab == 4.0.0b0
## Installation
You can install yjs-widgets using pip:
```bash
pip install yjs-widgets
```
## Usage
```typescript
import { IJupyterYModel } from './types';
import { JupyterYModel } from './model';
import { IJupyterYWidgetManager } from './notebookrenderer/types';
import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
class MyWidget {
constructor(yModel: IJupyterYModel, node: HTMLElement) {
this.yModel = yModel;
this.node = node;
yModel.sharedModel.attrsChanged.connect(() => {
this._attrsChanged();
});
node.textContent = 'Hello world!';
}
_attrsChanged(): void {
const foo: string = this.yModel.sharedModel.getAttr('foo') as string;
const bar: string = this.yModel.sharedModel.getAttr('bar') as string;
this.node.textContent = `foo=${foo}, bar=${bar}`;
}
yModel: IJupyterYModel;
node: HTMLElement;
}
export const foo: JupyterFrontEndPlugin = {
id: 'foo:bar',
autoStart: true,
requires: [IJupyterYWidgetManager],
activate: (app: JupyterFrontEnd, wm: IJupyterYWidgetManager): void => {
wm.registerWidget('MyWidget', JupyterYModel, MyWidget);
}
};
```
## Contributing
yjs-widgets is an open-source project, and contributions are always welcome. If you would like to contribute, please fork the repository and submit a pull request.
See [CONTRIBUTING](CONTRIBUTING.md) for dev installation instructions.
## License
yjs-widgets is licensed under the BSD 3-Clause License. See the LICENSE file for more information.