Skip to content

Commit 8397252

Browse files
committed
fix backward incompatible change to make tsc consistent
1 parent e49d4b8 commit 8397252

File tree

4 files changed

+5632
-3881
lines changed

4 files changed

+5632
-3881
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,4 @@
186186
"value-no-vendor-prefix": null
187187
}
188188
}
189-
}
189+
}

src/editor.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
import { DocumentRegistry, DocumentWidget } from '@jupyterlab/docregistry';
1616

17-
import { MainMenu, JupyterLabMenu } from '@jupyterlab/mainmenu';
17+
import { MainMenu } from '@jupyterlab/mainmenu';
18+
19+
import { RankedMenu } from '@jupyterlab/ui-components';
1820

1921
import { IChangedArgs, PathExt } from '@jupyterlab/coreutils';
2022

@@ -60,31 +62,31 @@ export class DrawIODocumentWidget extends DocumentWidget<DrawIOWidget> {
6062

6163
//TODO:
6264
// Add toolbar actions to change the default style of arrows and conections.
63-
this._menuView = new JupyterLabMenu({ commands: this._commands });
64-
this._menuView.menu.title.caption = 'View (Space+Drag to Scroll)';
65-
this._menuView.menu.title.icon = formatPanelIcon;
66-
this._menubar.addMenu(this._menuView.menu, { rank: 1 });
65+
this._menuView = new RankedMenu({ commands: this._commands });
66+
this._menuView.rootMenu.title.caption = 'View (Space+Drag to Scroll)';
67+
this._menuView.rootMenu.title.icon = formatPanelIcon;
68+
this._menubar.addMenu(this._menuView.rootMenu, true, { rank: 1 });
6769

68-
this._menuZoom = new JupyterLabMenu({ commands: this._commands });
70+
this._menuZoom = new RankedMenu({ commands: this._commands });
6971
//TODO: Change label to a view percentage
70-
this._menuZoom.menu.title.label = 'Zoom';
71-
this._menuZoom.menu.title.caption = 'Zoom (Alt+Mousewheel)';
72-
this._menubar.addMenu(this._menuZoom.menu, { rank: 2 });
72+
this._menuZoom.rootMenu.title.label = 'Zoom';
73+
this._menuZoom.rootMenu.title.caption = 'Zoom (Alt+Mousewheel)';
74+
this._menubar.addMenu(this._menuZoom.rootMenu, true, { rank: 2 });
7375

74-
this._menuInsert = new JupyterLabMenu({ commands: this._commands });
75-
this._menuInsert.menu.title.caption = 'Insert';
76-
this._menuInsert.menu.title.icon = plusIcon;
77-
this._menubar.addMenu(this._menuInsert.menu, { rank: 2 });
76+
this._menuInsert = new RankedMenu({ commands: this._commands });
77+
this._menuInsert.rootMenu.title.caption = 'Insert';
78+
this._menuInsert.rootMenu.title.icon = plusIcon;
79+
this._menubar.addMenu(this._menuInsert.rootMenu, true, { rank: 2 });
7880

7981
this.context.ready.then(async value => {
8082
await this.content.ready.promise;
8183

82-
this._onTitleChanged();
84+
this._onDrawIOTitleChanged();
8385
this._addToolbarItems();
8486
this.content.setContent(this.context.model.toString());
8587
this._handleDirtyStateNew();
8688

87-
this.context.pathChanged.connect(this._onTitleChanged, this);
89+
this.context.pathChanged.connect(this._onDrawIOTitleChanged, this);
8890
//this.context.model.contentChanged.connect(this._onContentChanged, this);
8991
this.context.model.stateChanged.connect(
9092
this._onModelStateChangedNew,
@@ -159,8 +161,10 @@ export class DrawIODocumentWidget extends DocumentWidget<DrawIOWidget> {
159161

160162
/**
161163
* Handle a change to the title.
164+
* changed since the base class method renamed as onTitlechanged
162165
*/
163-
private _onTitleChanged(): void {
166+
167+
private _onDrawIOTitleChanged(): void {
164168
this.title.label = PathExt.basename(this.context.localPath);
165169
}
166170

@@ -272,9 +276,9 @@ export class DrawIODocumentWidget extends DocumentWidget<DrawIOWidget> {
272276

273277
private _commands: CommandRegistry;
274278
private _menubar: MainMenu;
275-
private _menuView: JupyterLabMenu;
276-
private _menuZoom: JupyterLabMenu;
277-
private _menuInsert: JupyterLabMenu;
279+
private _menuView: RankedMenu;
280+
private _menuZoom: RankedMenu;
281+
private _menuInsert: RankedMenu;
278282
}
279283

280284
export namespace DrawIODocumentWidget {

src/index.ts

Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ import {
2424
IWidgetTracker
2525
} from '@jupyterlab/apputils';
2626

27-
import { IMainMenu, JupyterLabMenu } from '@jupyterlab/mainmenu';
27+
import { IMainMenu } from '@jupyterlab/mainmenu';
2828

29-
import { IFileBrowserFactory } from '@jupyterlab/filebrowser';
29+
import { RankedMenu } from '@jupyterlab/ui-components';
30+
31+
import { IFileBrowserFactory, IDefaultFileBrowser } from '@jupyterlab/filebrowser';
3032

3133
import { ILauncher } from '@jupyterlab/launcher';
3234

@@ -73,9 +75,15 @@ const extension: JupyterFrontEndPlugin<IDrawioTracker> = {
7375

7476
export default extension;
7577

78+
namespace CommandIDs {
79+
export const redo = 'drawio:command/redo';
80+
export const undo = 'drawio:command/undo';
81+
}
82+
7683
function activate(
7784
app: JupyterFrontEnd,
78-
browserFactory: IFileBrowserFactory,
85+
// browserFactory: IFileBrowserFactory,
86+
defaultBrowser :IDefaultFileBrowser,
7987
restorer: ILayoutRestorer,
8088
menu: IMainMenu,
8189
palette: ICommandPalette,
@@ -101,7 +109,7 @@ function activate(
101109
});
102110

103111
factory.widgetCreated.connect((sender, widget) => {
104-
widget.title.icon = 'jp-MaterialIcon jp-ImageIcon'; // TODO change
112+
widget.title.iconClass = 'jp-MaterialIcon jp-ImageIcon'; // TODO change
105113

106114
// Notify the instance tracker if restore data needs to update.
107115
widget.context.pathChanged.connect(() => {
@@ -128,7 +136,7 @@ function activate(
128136
iconClass: 'jp-MaterialIcon jp-ImageIcon',
129137
caption: 'Create a new diagram file',
130138
execute: () => {
131-
const cwd = browserFactory.defaultBrowser.model.path;
139+
const cwd = defaultBrowser.model.path;
132140
commands
133141
.execute('docmanager:new-untitled', {
134142
path: cwd,
@@ -151,7 +159,7 @@ function activate(
151159
tracker.currentWidget !== null &&
152160
tracker.currentWidget === app.shell.currentWidget,
153161
execute: () => {
154-
const cwd = browserFactory.defaultBrowser.model.path;
162+
const cwd = defaultBrowser.model.path;
155163
commands
156164
.execute('docmanager:new-untitled', {
157165
path: cwd,
@@ -177,7 +185,7 @@ function activate(
177185
}
178186

179187
if (menu) {
180-
addMenus(commands, menu, tracker);
188+
addMenus(app, commands, menu, tracker);
181189
}
182190

183191
addCommands(app, tracker);
@@ -195,18 +203,19 @@ function activate(
195203
}
196204

197205
function addMenus(
206+
app: JupyterFrontEnd,
198207
commands: CommandRegistry,
199208
menu: IMainMenu,
200209
tracker: IDrawioTracker
201210
): void {
202-
const diagram = new JupyterLabMenu({ commands });
203-
diagram.menu.title.label = 'Diagram';
211+
const diagram = new RankedMenu({ commands });
212+
diagram.rootMenu.title.label = 'Diagram';
204213

205214
// FILE MENU
206215
// Add new text file creation to the file menu.
207216
menu.fileMenu.newMenu.addGroup([{ command: 'drawio:create-new' }], 40);
208-
const fileMenu = new JupyterLabMenu({ commands });
209-
fileMenu.menu.title.label = 'File';
217+
const fileMenu = new RankedMenu({ commands });
218+
fileMenu.rootMenu.title.label = 'File';
210219
fileMenu.addGroup([{ command: 'drawio:create-new' }], 0);
211220
fileMenu.addGroup(
212221
[
@@ -216,18 +225,18 @@ function addMenus(
216225
],
217226
1
218227
);
228+
const isEnabled = () =>
229+
tracker.currentWidget !== null &&
230+
tracker.currentWidget === app.shell.currentWidget;
219231

220232
// Edit MENU
221-
menu.editMenu.undoers.add({
222-
tracker,
223-
undo: (widget: any) => widget.execute('undo'),
224-
redo: (widget: any) => widget.execute('redo')
225-
} as any);
233+
menu.editMenu.undoers.undo.add({id: CommandIDs.undo, isEnabled});
234+
menu.editMenu.undoers.undo.add({id: CommandIDs.redo, isEnabled});
226235

227-
const editMenu = new JupyterLabMenu({ commands });
228-
editMenu.menu.title.label = 'Edit';
236+
const editMenu = new RankedMenu({ commands });
237+
editMenu.rootMenu.title.label = 'Edit';
229238
editMenu.addGroup(
230-
[{ command: 'drawio:command/undo' }, { command: 'drawio:command/redo' }],
239+
[{ command: CommandIDs.undo }, { command: CommandIDs.redo }],
231240
0
232241
);
233242
editMenu.addGroup(
@@ -268,8 +277,8 @@ function addMenus(
268277
editMenu.addGroup([{ command: 'drawio:command/lockUnlock' }], 7);
269278

270279
// View MENU
271-
const viewMenu = new JupyterLabMenu({ commands });
272-
viewMenu.menu.title.label = 'View';
280+
const viewMenu = new RankedMenu({ commands });
281+
viewMenu.rootMenu.title.label = 'View';
273282
viewMenu.addGroup(
274283
[
275284
{ command: 'drawio:command/formatPanel' },
@@ -313,8 +322,8 @@ function addMenus(
313322
);
314323

315324
// Arrange MENU
316-
const arrangeMenu = new JupyterLabMenu({ commands });
317-
arrangeMenu.menu.title.label = 'Arrange';
325+
const arrangeMenu = new RankedMenu({ commands });
326+
arrangeMenu.rootMenu.title.label = 'Arrange';
318327
arrangeMenu.addGroup(
319328
[
320329
{ command: 'drawio:command/toFront' },
@@ -323,23 +332,23 @@ function addMenus(
323332
0
324333
);
325334

326-
const direction = new JupyterLabMenu({ commands });
327-
direction.menu.title.label = 'Direction';
335+
const direction = new RankedMenu({ commands });
336+
direction.rootMenu.title.label = 'Direction';
328337
direction.addGroup(
329338
[{ command: 'drawio:command/flipH' }, { command: 'drawio:command/flipV' }],
330339
0
331340
);
332341
direction.addGroup([{ command: 'drawio:command/rotation' }], 1);
333342
arrangeMenu.addGroup(
334343
[
335-
{ type: 'submenu', submenu: direction.menu },
344+
{ type: 'submenu', submenu: direction.rootMenu },
336345
{ command: 'drawio:command/turn' }
337346
],
338347
1
339348
);
340349

341-
const align = new JupyterLabMenu({ commands });
342-
align.menu.title.label = 'Diagram Align';
350+
const align = new RankedMenu({ commands });
351+
align.rootMenu.title.label = 'Diagram Align';
343352
align.addGroup(
344353
[
345354
{ command: 'drawio:command/alignCellsLeft' },
@@ -357,8 +366,8 @@ function addMenus(
357366
1
358367
);
359368

360-
const distribute = new JupyterLabMenu({ commands });
361-
distribute.menu.title.label = 'Distribute';
369+
const distribute = new RankedMenu({ commands });
370+
distribute.rootMenu.title.label = 'Distribute';
362371
distribute.addGroup(
363372
[
364373
{ command: 'drawio:command/horizontal' },
@@ -368,14 +377,14 @@ function addMenus(
368377
);
369378
arrangeMenu.addGroup(
370379
[
371-
{ type: 'submenu', submenu: align.menu },
372-
{ type: 'submenu', submenu: distribute.menu }
380+
{ type: 'submenu', submenu: align.rootMenu },
381+
{ type: 'submenu', submenu: distribute.rootMenu }
373382
],
374383
2
375384
);
376385

377-
const navigation = new JupyterLabMenu({ commands });
378-
navigation.menu.title.label = 'Navigation';
386+
const navigation = new RankedMenu({ commands });
387+
navigation.rootMenu.title.label = 'Navigation';
379388
navigation.addGroup([{ command: 'drawio:command/home' }], 0);
380389
navigation.addGroup(
381390
[
@@ -393,8 +402,8 @@ function addMenus(
393402
);
394403
navigation.addGroup([{ command: 'drawio:command/collapsible' }], 3);
395404

396-
const insert = new JupyterLabMenu({ commands });
397-
insert.menu.title.label = 'Insert';
405+
const insert = new RankedMenu({ commands });
406+
insert.rootMenu.title.label = 'Insert';
398407
insert.addGroup(
399408
[
400409
{ command: 'drawio:command/insertLink' },
@@ -403,8 +412,8 @@ function addMenus(
403412
0
404413
);
405414

406-
const layout = new JupyterLabMenu({ commands });
407-
layout.menu.title.label = 'Layout';
415+
const layout = new RankedMenu({ commands });
416+
layout.rootMenu.title.label = 'Layout';
408417
layout.addGroup(
409418
[
410419
{ command: 'drawio:command/horizontalFlow' },
@@ -429,9 +438,9 @@ function addMenus(
429438
);
430439
arrangeMenu.addGroup(
431440
[
432-
{ type: 'submenu', submenu: navigation.menu },
433-
{ type: 'submenu', submenu: insert.menu },
434-
{ type: 'submenu', submenu: layout.menu }
441+
{ type: 'submenu', submenu: navigation.rootMenu },
442+
{ type: 'submenu', submenu: insert.rootMenu },
443+
{ type: 'submenu', submenu: layout.rootMenu }
435444
],
436445
3
437446
);
@@ -454,8 +463,8 @@ function addMenus(
454463
);
455464

456465
// Extras MENU
457-
const extrasMenu = new JupyterLabMenu({ commands });
458-
extrasMenu.menu.title.label = 'Extras';
466+
const extrasMenu = new RankedMenu({ commands });
467+
extrasMenu.rootMenu.title.label = 'Extras';
459468
extrasMenu.addGroup(
460469
[
461470
{ command: 'drawio:command/copyConnect' },
@@ -467,16 +476,16 @@ function addMenus(
467476

468477
diagram.addGroup(
469478
[
470-
{ type: 'submenu', submenu: fileMenu.menu },
471-
{ type: 'submenu', submenu: editMenu.menu },
472-
{ type: 'submenu', submenu: viewMenu.menu },
473-
{ type: 'submenu', submenu: arrangeMenu.menu },
474-
{ type: 'submenu', submenu: extrasMenu.menu },
479+
{ type: 'submenu', submenu: fileMenu.rootMenu },
480+
{ type: 'submenu', submenu: editMenu.rootMenu },
481+
{ type: 'submenu', submenu: viewMenu.rootMenu },
482+
{ type: 'submenu', submenu: arrangeMenu.rootMenu },
483+
{ type: 'submenu', submenu: extrasMenu.rootMenu },
475484
{ command: 'drawio:command/about' }
476485
],
477486
0
478487
);
479-
menu.addMenu(diagram.menu, { rank: 60 });
488+
menu.addMenu(diagram.rootMenu, true, { rank: 60 });
480489
}
481490

482491
function addCommands(app: JupyterFrontEnd, tracker: IDrawioTracker): void {
@@ -571,7 +580,7 @@ function addCommands(app: JupyterFrontEnd, tracker: IDrawioTracker): void {
571580
}
572581
});
573582
});
574-
app.commands.addCommand('drawio:command/undo', {
583+
app.commands.addCommand(CommandIDs.undo, {
575584
label: 'Undo',
576585
caption: 'Undo (Ctrl+Z)',
577586
icon: undoIcon,
@@ -596,7 +605,7 @@ function addCommands(app: JupyterFrontEnd, tracker: IDrawioTracker): void {
596605
}
597606
}
598607
});
599-
app.commands.addCommand('drawio:command/redo', {
608+
app.commands.addCommand(CommandIDs.redo, {
600609
label: 'Redo',
601610
caption: 'Redo (Ctrl+Shift+Z)',
602611
icon: redoIcon,

0 commit comments

Comments
 (0)