Skip to content

Commit 2669fad

Browse files
brichetpre-commit-ci[bot]github-actions[bot]
authored
Widget with toolbar and sidepanel in cell output (#419)
* Add minimal Context interface for jupytergis widgets * Add a new widget to be include in Notebook cell output * Fix the relative path issue when add a layer in cell output widget * Use context 'localPath' instaed of 'path' to avoid 'RTC:' in the path * Handle the resize event of the cell output widget * lint * Use the model (IJupyterGISModel) instead of the context in the components and tracker * lint * Fix dependencies in '@jupytergis/jupytergis-lab' package * Allow using the python API without file on disk * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * lint * Update Playwright Snapshots * Use the notebook or console path as temporary project path, when using the API without file * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Rename widget for consistency, and remove console comands from cell output widget * Build again the widget if the path is updated, to add the toolbar if necessary * Add the widget to the tracker after rebuilt, and fix the model path, that can be updated between the model creation and the widget creation. * Dispose of the widget when the model is disposed * lint * Do not dispose of the model when clearing cell output * Dispose of the GIS widget when the yjs widget is disposed --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 5b5eb2c commit 2669fad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+457
-312
lines changed

packages/base/src/annotations/components/Annotation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const Annotation = ({
3636
* Update the model when it changes.
3737
*/
3838
rightPanelModel?.documentChanged.connect((_, widget) => {
39-
setJgisModel(widget?.context.model);
39+
setJgisModel(widget?.model);
4040
});
4141

4242
const handleSubmit = () => {

packages/base/src/annotations/model.ts

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import {
44
IAnnotationModel,
55
IJupyterGISModel
66
} from '@jupytergis/schema';
7-
import { DocumentRegistry } from '@jupyterlab/docregistry';
87
import { User } from '@jupyterlab/services';
98
import { ISignal, Signal } from '@lumino/signaling';
109

1110
export class AnnotationModel implements IAnnotationModel {
1211
constructor(options: AnnotationModel.IOptions) {
13-
this.context = options.context;
12+
this.model = options.model;
1413
}
1514

1615
get updateSignal(): ISignal<this, null> {
@@ -21,39 +20,37 @@ export class AnnotationModel implements IAnnotationModel {
2120
return this._user;
2221
}
2322

24-
set context(
25-
context: DocumentRegistry.IContext<IJupyterGISModel> | undefined
26-
) {
27-
this._context = context;
23+
set model(model: IJupyterGISModel | undefined) {
24+
this._model = model;
2825

29-
const state = this._context?.model.sharedModel.awareness.getLocalState();
26+
const state = this._model?.sharedModel.awareness.getLocalState();
3027
this._user = state?.user;
3128

32-
this._contextChanged.emit(void 0);
29+
this._modelChanged.emit(void 0);
3330
}
3431

35-
get context(): DocumentRegistry.IContext<IJupyterGISModel> | undefined {
36-
return this._context;
32+
get model(): IJupyterGISModel | undefined {
33+
return this._model;
3734
}
3835

39-
get contextChanged(): ISignal<this, void> {
40-
return this._contextChanged;
36+
get modelChanged(): ISignal<this, void> {
37+
return this._modelChanged;
4138
}
4239

4340
update(): void {
4441
this._updateSignal.emit(null);
4542
}
4643

4744
getAnnotation(id: string): IAnnotation | undefined {
48-
const rawData = this._context?.model.sharedModel.getMetadata(id);
45+
const rawData = this._model?.sharedModel.getMetadata(id);
4946
if (rawData) {
5047
return JSON.parse(rawData) as IAnnotation;
5148
}
5249
}
5350

5451
getAnnotationIds(): string[] {
5552
const annotationIds: string[] = [];
56-
for (const id in this._context?.model.sharedModel.metadata) {
53+
for (const id in this._model?.sharedModel.metadata) {
5754
if (id.startsWith('annotation')) {
5855
annotationIds.push(id);
5956
}
@@ -62,14 +59,14 @@ export class AnnotationModel implements IAnnotationModel {
6259
}
6360

6461
addAnnotation(key: string, value: IAnnotation): void {
65-
this._context?.model.sharedModel.setMetadata(
62+
this._model?.sharedModel.setMetadata(
6663
`annotation_${key}`,
6764
JSON.stringify(value)
6865
);
6966
}
7067

7168
removeAnnotation(key: string): void {
72-
this._context?.model.removeMetadata(key);
69+
this._model?.removeMetadata(key);
7370
}
7471

7572
addContent(id: string, value: string): void {
@@ -84,21 +81,18 @@ export class AnnotationModel implements IAnnotationModel {
8481
contents: [...currentAnnotation.contents, newContent]
8582
};
8683

87-
this._context?.model.sharedModel.setMetadata(
88-
id,
89-
JSON.stringify(newAnnotation)
90-
);
84+
this._model?.sharedModel.setMetadata(id, JSON.stringify(newAnnotation));
9185
}
9286
}
9387

94-
private _context: DocumentRegistry.IContext<IJupyterGISModel> | undefined;
95-
private _contextChanged = new Signal<this, void>(this);
88+
private _model: IJupyterGISModel | undefined;
89+
private _modelChanged = new Signal<this, void>(this);
9690
private _updateSignal = new Signal<this, null>(this);
9791
private _user?: User.IIdentity;
9892
}
9993

10094
namespace AnnotationModel {
10195
export interface IOptions {
102-
context: DocumentRegistry.IContext<IJupyterGISModel> | undefined;
96+
model: IJupyterGISModel | undefined;
10397
}
10498
}

0 commit comments

Comments
 (0)