Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
76b58e7
Add minimal Context interface for jupytergis widgets
brichet Jan 31, 2025
f20e098
Add a new widget to be include in Notebook cell output
brichet Jan 31, 2025
5624e3e
Fix the relative path issue when add a layer in cell output widget
brichet Jan 31, 2025
745d79b
Use context 'localPath' instaed of 'path' to avoid 'RTC:' in the path
brichet Jan 31, 2025
223b504
Handle the resize event of the cell output widget
brichet Feb 2, 2025
906e6ef
lint
brichet Feb 2, 2025
e448960
Use the model (IJupyterGISModel) instead of the context in the compon…
brichet Feb 3, 2025
765edb8
lint
brichet Feb 3, 2025
1adef39
Fix dependencies in '@jupytergis/jupytergis-lab' package
brichet Feb 3, 2025
6715005
Allow using the python API without file on disk
brichet Feb 3, 2025
464cf2c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 3, 2025
71deb9f
lint
brichet Feb 3, 2025
7f18130
Update Playwright Snapshots
github-actions[bot] Feb 3, 2025
b363a1d
Use the notebook or console path as temporary project path, when usin…
brichet Feb 4, 2025
761436e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 4, 2025
e374493
Rename widget for consistency, and remove console comands from cell o…
brichet Feb 4, 2025
953d127
Build again the widget if the path is updated, to add the toolbar if …
brichet Feb 4, 2025
0918536
Add the widget to the tracker after rebuilt, and fix the model path, …
brichet Feb 4, 2025
e55c1c1
Dispose of the widget when the model is disposed
brichet Feb 4, 2025
e7fe9ab
lint
brichet Feb 4, 2025
59e83c5
Do not dispose of the model when clearing cell output
brichet Feb 6, 2025
724318e
Dispose of the GIS widget when the yjs widget is disposed
brichet Feb 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/base/src/annotations/components/Annotation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Annotation = ({
* Update the model when it changes.
*/
rightPanelModel?.documentChanged.connect((_, widget) => {
setJgisModel(widget?.context.model);
setJgisModel(widget?.model);
});

const handleSubmit = () => {
Expand Down
40 changes: 17 additions & 23 deletions packages/base/src/annotations/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import {
IAnnotationModel,
IJupyterGISModel
} from '@jupytergis/schema';
import { DocumentRegistry } from '@jupyterlab/docregistry';
import { User } from '@jupyterlab/services';
import { ISignal, Signal } from '@lumino/signaling';

export class AnnotationModel implements IAnnotationModel {
constructor(options: AnnotationModel.IOptions) {
this.context = options.context;
this.model = options.model;
}

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

set context(
context: DocumentRegistry.IContext<IJupyterGISModel> | undefined
) {
this._context = context;
set model(model: IJupyterGISModel | undefined) {
this._model = model;

const state = this._context?.model.sharedModel.awareness.getLocalState();
const state = this._model?.sharedModel.awareness.getLocalState();
this._user = state?.user;

this._contextChanged.emit(void 0);
this._modelChanged.emit(void 0);
}

get context(): DocumentRegistry.IContext<IJupyterGISModel> | undefined {
return this._context;
get model(): IJupyterGISModel | undefined {
return this._model;
}

get contextChanged(): ISignal<this, void> {
return this._contextChanged;
get modelChanged(): ISignal<this, void> {
return this._modelChanged;
}

update(): void {
this._updateSignal.emit(null);
}

getAnnotation(id: string): IAnnotation | undefined {
const rawData = this._context?.model.sharedModel.getMetadata(id);
const rawData = this._model?.sharedModel.getMetadata(id);
if (rawData) {
return JSON.parse(rawData) as IAnnotation;
}
}

getAnnotationIds(): string[] {
const annotationIds: string[] = [];
for (const id in this._context?.model.sharedModel.metadata) {
for (const id in this._model?.sharedModel.metadata) {
if (id.startsWith('annotation')) {
annotationIds.push(id);
}
Expand All @@ -62,14 +59,14 @@ export class AnnotationModel implements IAnnotationModel {
}

addAnnotation(key: string, value: IAnnotation): void {
this._context?.model.sharedModel.setMetadata(
this._model?.sharedModel.setMetadata(
`annotation_${key}`,
JSON.stringify(value)
);
}

removeAnnotation(key: string): void {
this._context?.model.removeMetadata(key);
this._model?.removeMetadata(key);
}

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

this._context?.model.sharedModel.setMetadata(
id,
JSON.stringify(newAnnotation)
);
this._model?.sharedModel.setMetadata(id, JSON.stringify(newAnnotation));
}
}

private _context: DocumentRegistry.IContext<IJupyterGISModel> | undefined;
private _contextChanged = new Signal<this, void>(this);
private _model: IJupyterGISModel | undefined;
private _modelChanged = new Signal<this, void>(this);
private _updateSignal = new Signal<this, null>(this);
private _user?: User.IIdentity;
}

namespace AnnotationModel {
export interface IOptions {
context: DocumentRegistry.IContext<IJupyterGISModel> | undefined;
model: IJupyterGISModel | undefined;
}
}
Loading
Loading