Skip to content

Commit dd46462

Browse files
Floating side panels
1 parent 7e3e845 commit dd46462

File tree

20 files changed

+3834
-3344
lines changed

20 files changed

+3834
-3344
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,8 @@
7272
"rimraf": "^3.0.2",
7373
"typescript": "^5",
7474
"webpack": "^5.76.3"
75+
},
76+
"dependencies": {
77+
"react-rnd": "^10.5.2"
7578
}
7679
}

packages/base/src/Lumino.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Widget } from '@lumino/widgets';
2+
import * as React from 'react';
3+
4+
type LuminoProps = {
5+
id?: string;
6+
height?: string | number;
7+
children: Widget;
8+
};
9+
10+
export const Lumino = (props: LuminoProps) => {
11+
const ref = React.useRef<HTMLDivElement>(null);
12+
const { children, id, height } = props;
13+
React.useEffect(() => {
14+
if (ref && ref.current) {
15+
try {
16+
Widget.attach(children, ref.current);
17+
} catch (e) {
18+
console.warn('Exception while attaching Lumino widget.', e);
19+
}
20+
return () => {
21+
try {
22+
if (children.isAttached || children.node.isConnected) {
23+
children.dispose();
24+
Widget.detach(children);
25+
}
26+
} catch (e) {
27+
// no-op.
28+
// console.debug('Exception while detaching Lumino widget.', e);
29+
}
30+
};
31+
}
32+
}, [ref, children]);
33+
return (
34+
<div id={id} ref={ref} style={{ height: height, minHeight: height }} />
35+
);
36+
};
37+
38+
Lumino.defaultProps = {
39+
id: 'lumino-id',
40+
height: '100%',
41+
};
42+
43+
export default Lumino;

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@ import { showDialog, Dialog } from '@jupyterlab/apputils';
99
import { Button } from '@jupyterlab/ui-components';
1010
import React, { useMemo, useState } from 'react';
1111

12-
import { IControlPanelModel } from '@/src/types';
1312
import { Message } from './Message';
1413

1514
export interface IAnnotationProps {
1615
itemId: string;
1716
annotationModel: IAnnotationModel;
18-
rightPanelModel?: IControlPanelModel;
17+
rightPanelModel?: IJupyterGISModel;
1918
children?: JSX.Element[] | JSX.Element;
2019
}
2120

@@ -26,20 +25,10 @@ const Annotation: React.FC<IAnnotationProps> = ({
2625
children,
2726
}) => {
2827
const [messageContent, setMessageContent] = useState('');
29-
const [jgisModel, setJgisModel] = useState<IJupyterGISModel | undefined>(
30-
rightPanelModel?.jGISModel,
31-
);
32-
28+
const jgisModel = rightPanelModel;
3329
const annotation = annotationModel.getAnnotation(itemId);
3430
const contents = useMemo(() => annotation?.contents ?? [], [annotation]);
3531

36-
/**
37-
* Update the model when it changes.
38-
*/
39-
rightPanelModel?.documentChanged.connect((_, widget) => {
40-
setJgisModel(widget?.model);
41-
});
42-
4332
const handleSubmit = () => {
4433
annotationModel.addContent(itemId, messageContent);
4534
setMessageContent('');

0 commit comments

Comments
 (0)