|
1 |
| -import { Widget } from '@phosphor/widgets'; |
2 | 1 | import * as React from 'react';
|
3 |
| -import * as ReactDOM from 'react-dom'; |
4 | 2 | import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
5 | 3 |
|
6 | 4 | import { getRefValue, IDiffContext } from './model';
|
7 | 5 | import { Diff, isDiffSupported, RenderMimeProvider } from './Diff';
|
8 | 6 | import { JupyterFrontEnd } from '@jupyterlab/application';
|
9 |
| -import { showDialog } from '@jupyterlab/apputils'; |
| 7 | +import { ReactWidget, showDialog } from '@jupyterlab/apputils'; |
10 | 8 | import { PathExt } from '@jupyterlab/coreutils';
|
11 | 9 | import { style } from 'typestyle';
|
12 | 10 |
|
13 |
| -export class DiffWidget extends Widget { |
14 |
| - private readonly _renderMime: IRenderMimeRegistry; |
15 |
| - private readonly _path: string; |
16 |
| - private readonly _diffContext: IDiffContext; |
17 |
| - |
18 |
| - constructor( |
19 |
| - renderMime: IRenderMimeRegistry, |
20 |
| - path: string, |
21 |
| - gitContext: IDiffContext |
22 |
| - ) { |
23 |
| - super(); |
24 |
| - this._renderMime = renderMime; |
25 |
| - this._path = path; |
26 |
| - this._diffContext = gitContext; |
27 |
| - |
28 |
| - this.title.label = PathExt.basename(path); |
29 |
| - this.title.iconClass = style({ |
30 |
| - backgroundImage: 'var(--jp-icon-diff)' |
31 |
| - }); |
32 |
| - this.title.closable = true; |
33 |
| - this.addClass('jp-git-diff-parent-diff-widget'); |
34 |
| - |
35 |
| - ReactDOM.render( |
36 |
| - <RenderMimeProvider value={this._renderMime}> |
37 |
| - <Diff path={this._path} diffContext={this._diffContext} /> |
38 |
| - </RenderMimeProvider>, |
39 |
| - this.node |
40 |
| - ); |
41 |
| - } |
42 |
| - |
43 |
| - onUpdateRequest(): void { |
44 |
| - ReactDOM.unmountComponentAtNode(this.node); |
45 |
| - ReactDOM.render( |
46 |
| - <RenderMimeProvider value={this._renderMime}> |
47 |
| - <Diff path={this._path} diffContext={this._diffContext} /> |
48 |
| - </RenderMimeProvider>, |
49 |
| - this.node |
50 |
| - ); |
51 |
| - } |
52 |
| -} |
53 |
| - |
54 | 11 | /**
|
55 | 12 | * Method to open a main menu panel to show the diff of a given Notebook file.
|
56 | 13 | * If one already exists, just activates the existing one.
|
@@ -78,8 +35,19 @@ export function openDiffView(
|
78 | 35 | mainAreaItem = mainAreaItems.next();
|
79 | 36 | }
|
80 | 37 | if (!mainAreaItem) {
|
81 |
| - const nbDiffWidget = new DiffWidget(renderMime, path, diffContext); |
| 38 | + const nbDiffWidget = ReactWidget.create( |
| 39 | + <RenderMimeProvider value={renderMime}> |
| 40 | + <Diff path={path} diffContext={diffContext} /> |
| 41 | + </RenderMimeProvider> |
| 42 | + ); |
82 | 43 | nbDiffWidget.id = id;
|
| 44 | + nbDiffWidget.title.label = PathExt.basename(path); |
| 45 | + nbDiffWidget.title.iconClass = style({ |
| 46 | + backgroundImage: 'var(--jp-icon-diff)' |
| 47 | + }); |
| 48 | + nbDiffWidget.title.closable = true; |
| 49 | + nbDiffWidget.addClass('jp-git-diff-parent-diff-widget'); |
| 50 | + |
83 | 51 | app.shell.add(nbDiffWidget, 'main');
|
84 | 52 | app.shell.activateById(nbDiffWidget.id);
|
85 | 53 | }
|
|
0 commit comments