Skip to content

Commit

Permalink
Makes drawio collaborative sharing the mxCells as string, and makes I…
Browse files Browse the repository at this point in the history
…CommandPalette an optional dependency (see #98)
  • Loading branch information
hbcarlos committed Aug 24, 2021
1 parent 0f528bc commit 7d94ba0
Show file tree
Hide file tree
Showing 7 changed files with 431 additions and 498 deletions.
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,25 @@
"watch:src": "tsc -w"
},
"dependencies": {
"@jupyterlab/application": "^3.1.0-alpha.8",
"@jupyterlab/apputils": "^3.1.0-alpha.8",
"@jupyterlab/coreutils": "^5.1.0-alpha.8",
"@jupyterlab/docregistry": "^3.1.0-alpha.8",
"@jupyterlab/filebrowser": "^3.1.0-alpha.8",
"@jupyterlab/launcher": "^3.1.0-alpha.8",
"@jupyterlab/mainmenu": "^3.1.0-alpha.8",
"@jupyterlab/observables": "^4.1.0-alpha.8",
"@jupyterlab/services": "^6.1.0-alpha.8",
"@jupyterlab/shared-models": "^3.1.0-alpha.8",
"@jupyterlab/ui-components": "^3.1.0-alpha.8",
"@jupyterlab/application": "^3.1.0-alpha.13",
"@jupyterlab/apputils": "^3.1.0-alpha.13",
"@jupyterlab/coreutils": "^5.1.0-alpha.13",
"@jupyterlab/docregistry": "^3.1.0-alpha.13",
"@jupyterlab/filebrowser": "^3.1.0-alpha.13",
"@jupyterlab/launcher": "^3.1.0-alpha.13",
"@jupyterlab/mainmenu": "^3.1.0-alpha.13",
"@jupyterlab/observables": "^4.1.0-alpha.13",
"@jupyterlab/services": "^6.1.0-alpha.13",
"@jupyterlab/shared-models": "^3.1.0-alpha.13",
"@jupyterlab/ui-components": "^3.1.0-alpha.13",
"@lumino/commands": "^1.12.0",
"@lumino/coreutils": "^1.5.3",
"@lumino/signaling": "^1.4.3",
"@lumino/widgets": "^1.19.0",
"fast-xml-parser": "^3.19.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"yjs": "^13.5.3"
"yjs": "^13.5.6"
},
"devDependencies": {
"@jupyterlab/builder": "^3.1.0-alpha.8",
Expand Down
69 changes: 38 additions & 31 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function activate(
browserFactory: IFileBrowserFactory,
restorer: ILayoutRestorer | null,
menu: IMainMenu,
palette: ICommandPalette,
palette: ICommandPalette | null,
launcher: ILauncher | null
): IDrawioTracker {
const { commands } = app;
Expand Down Expand Up @@ -158,19 +158,26 @@ function activate(
tracker.currentWidget === app.shell.currentWidget,
execute: () => {
const wdg = app.shell.currentWidget as DrawIODocumentWidget;
const name = wdg.context.path.split('/').pop().split('.')[0] + ".svg";
let path = wdg.context.path.split('/').slice(0, -1).join();

const name =
wdg.context.path
.split('/')
.pop()
.split('.')[0] + '.svg';
const path = wdg.context.path
.split('/')
.slice(0, -1)
.join();

commands
.execute('docmanager:new-untitled', {
name,
path,
type: 'file',
ext: '.svg'
})
.then( model => {
model.name = name
model.path = path ? path + "/" + name : name;
.then(model => {
model.name = name;
model.path = path ? path + '/' + name : name;
model.content = wdg.getSVG();
model.format = 'text';
app.serviceManager.contents.save(model.path, model);
Expand Down Expand Up @@ -211,13 +218,13 @@ function addMenus(
tracker: IDrawioTracker
): void {
const diagram = new JupyterLabMenu({ commands });
diagram.menu.title.label = 'Diagram';
diagram.title.label = 'Diagram';

// FILE MENU
// Add new text file creation to the file menu.
menu.fileMenu.newMenu.addGroup([{ command: 'drawio:create-new' }], 40);
const fileMenu = new JupyterLabMenu({ commands });
fileMenu.menu.title.label = 'File';
fileMenu.title.label = 'File';
fileMenu.addGroup([{ command: 'drawio:create-new' }], 0);
fileMenu.addGroup(
[
Expand All @@ -236,7 +243,7 @@ function addMenus(
} as any);

const editMenu = new JupyterLabMenu({ commands });
editMenu.menu.title.label = 'Edit';
editMenu.title.label = 'Edit';
editMenu.addGroup(
[{ command: 'drawio:command/undo' }, { command: 'drawio:command/redo' }],
0
Expand Down Expand Up @@ -280,7 +287,7 @@ function addMenus(

// View MENU
const viewMenu = new JupyterLabMenu({ commands });
viewMenu.menu.title.label = 'View';
viewMenu.title.label = 'View';
viewMenu.addGroup(
[
{ command: 'drawio:command/formatPanel' },
Expand Down Expand Up @@ -325,7 +332,7 @@ function addMenus(

// Arrange MENU
const arrangeMenu = new JupyterLabMenu({ commands });
arrangeMenu.menu.title.label = 'Arrange';
arrangeMenu.title.label = 'Arrange';
arrangeMenu.addGroup(
[
{ command: 'drawio:command/toFront' },
Expand All @@ -335,22 +342,22 @@ function addMenus(
);

const direction = new JupyterLabMenu({ commands });
direction.menu.title.label = 'Direction';
direction.title.label = 'Direction';
direction.addGroup(
[{ command: 'drawio:command/flipH' }, { command: 'drawio:command/flipV' }],
0
);
direction.addGroup([{ command: 'drawio:command/rotation' }], 1);
arrangeMenu.addGroup(
[
{ type: 'submenu', submenu: direction.menu },
{ type: 'submenu', submenu: direction },
{ command: 'drawio:command/turn' }
],
1
);

const align = new JupyterLabMenu({ commands });
align.menu.title.label = 'Diagram Align';
align.title.label = 'Diagram Align';
align.addGroup(
[
{ command: 'drawio:command/alignCellsLeft' },
Expand All @@ -369,7 +376,7 @@ function addMenus(
);

const distribute = new JupyterLabMenu({ commands });
distribute.menu.title.label = 'Distribute';
distribute.title.label = 'Distribute';
distribute.addGroup(
[
{ command: 'drawio:command/horizontal' },
Expand All @@ -379,14 +386,14 @@ function addMenus(
);
arrangeMenu.addGroup(
[
{ type: 'submenu', submenu: align.menu },
{ type: 'submenu', submenu: distribute.menu }
{ type: 'submenu', submenu: align },
{ type: 'submenu', submenu: distribute }
],
2
);

const navigation = new JupyterLabMenu({ commands });
navigation.menu.title.label = 'Navigation';
navigation.title.label = 'Navigation';
navigation.addGroup([{ command: 'drawio:command/home' }], 0);
navigation.addGroup(
[
Expand All @@ -405,7 +412,7 @@ function addMenus(
navigation.addGroup([{ command: 'drawio:command/collapsible' }], 3);

const insert = new JupyterLabMenu({ commands });
insert.menu.title.label = 'Insert';
insert.title.label = 'Insert';
insert.addGroup(
[
{ command: 'drawio:command/insertLink' },
Expand All @@ -415,7 +422,7 @@ function addMenus(
);

const layout = new JupyterLabMenu({ commands });
layout.menu.title.label = 'Layout';
layout.title.label = 'Layout';
layout.addGroup(
[
{ command: 'drawio:command/horizontalFlow' },
Expand All @@ -440,9 +447,9 @@ function addMenus(
);
arrangeMenu.addGroup(
[
{ type: 'submenu', submenu: navigation.menu },
{ type: 'submenu', submenu: insert.menu },
{ type: 'submenu', submenu: layout.menu }
{ type: 'submenu', submenu: navigation },
{ type: 'submenu', submenu: insert },
{ type: 'submenu', submenu: layout }
],
3
);
Expand All @@ -466,7 +473,7 @@ function addMenus(

// Extras MENU
const extrasMenu = new JupyterLabMenu({ commands });
extrasMenu.menu.title.label = 'Extras';
extrasMenu.title.label = 'Extras';
extrasMenu.addGroup(
[
{ command: 'drawio:command/copyConnect' },
Expand All @@ -478,16 +485,16 @@ function addMenus(

diagram.addGroup(
[
{ type: 'submenu', submenu: fileMenu.menu },
{ type: 'submenu', submenu: editMenu.menu },
{ type: 'submenu', submenu: viewMenu.menu },
{ type: 'submenu', submenu: arrangeMenu.menu },
{ type: 'submenu', submenu: extrasMenu.menu },
{ type: 'submenu', submenu: fileMenu },
{ type: 'submenu', submenu: editMenu },
{ type: 'submenu', submenu: viewMenu },
{ type: 'submenu', submenu: arrangeMenu },
{ type: 'submenu', submenu: extrasMenu },
{ command: 'drawio:command/about' }
],
0
);
menu.addMenu(diagram.menu, { rank: 60 });
menu.addMenu(diagram, { rank: 60 });
}

function addCommands(app: JupyterFrontEnd, tracker: IDrawioTracker): void {
Expand Down
Loading

0 comments on commit 7d94ba0

Please sign in to comment.