Skip to content

Commit f5c86a2

Browse files
Widget with toolbar and sidepanel in cell output (#679)
* Widget with toolbar and sidepanel in cell output * typo * fix panels * fix panels * fix types in export form * use `JupyterCadDocumentWidgetFactory` class * use model * Try getting path right * Workaround for path * use `JupyterCadOutputwidget` * Add logic to notebook renderer * fix * Hid non relevant commands in notebook * Clear the mess * Update Playwright Snapshots * fix renaming file --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent a777c33 commit f5c86a2

26 files changed

+424
-208
lines changed

examples/Notebook.ipynb

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
},
1919
{
2020
"cell_type": "code",
21-
"execution_count": null,
21+
"execution_count": 10,
2222
"id": "050e5936-f9e1-44ff-8bc9-a8556d7643ee",
2323
"metadata": {},
2424
"outputs": [],
2525
"source": [
26-
"from jupytercad import CadDocument"
26+
"from jupytercad_lab import CadDocument"
2727
]
2828
},
2929
{
3030
"cell_type": "code",
31-
"execution_count": null,
31+
"execution_count": 11,
3232
"id": "9821d466-6ae7-418f-aea7-9d67153da7d6",
3333
"metadata": {},
3434
"outputs": [],
@@ -38,10 +38,26 @@
3838
},
3939
{
4040
"cell_type": "code",
41-
"execution_count": null,
41+
"execution_count": 12,
4242
"id": "e30499f0-6732-4611-a25e-46b27e606b08",
4343
"metadata": {},
44-
"outputs": [],
44+
"outputs": [
45+
{
46+
"data": {
47+
"application/vnd.jupyter.ywidget-view+json": {
48+
"model_id": "c586b4fc0d474786bd7fbf9635e15421",
49+
"version_major": 2,
50+
"version_minor": 0
51+
},
52+
"text/plain": [
53+
"<jupytercad_lab.notebook.cad_document.CadDocument object at 0x110fc7410>"
54+
]
55+
},
56+
"execution_count": 12,
57+
"metadata": {},
58+
"output_type": "execute_result"
59+
}
60+
],
4561
"source": [
4662
"doc.add_cone().add_sphere(radius=0.8).cut(color='#ff0000')"
4763
]
@@ -254,7 +270,7 @@
254270
"name": "python",
255271
"nbconvert_exporter": "python",
256272
"pygments_lexer": "ipython3",
257-
"version": "3.12.2"
273+
"version": "3.12.0"
258274
}
259275
},
260276
"nbformat": 4,

packages/base/src/annotation/model.ts

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import {
44
IAnnotationModel,
55
IJupyterCadModel
66
} from '@jupytercad/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<IJupyterCadModel> | undefined
26-
) {
27-
this._context = context;
23+
set model(model: IJupyterCadModel | 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<IJupyterCadModel> | undefined {
36-
return this._context;
32+
get model(): IJupyterCadModel | 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<IJupyterCadModel> | undefined;
95-
private _contextChanged = new Signal<this, void>(this);
88+
private _model: IJupyterCadModel | 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<IJupyterCadModel> | undefined;
96+
model: IJupyterCadModel | undefined;
10397
}
10498
}

0 commit comments

Comments
 (0)