Skip to content

Commit 1854bd2

Browse files
committed
final changes before external demo
1 parent f004907 commit 1854bd2

File tree

8 files changed

+214
-102
lines changed

8 files changed

+214
-102
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
"@lumino/dragdrop": "^1.6.2",
5454
"@lumino/widgets": "^1.13.2",
5555
"husky": "^4.2.5",
56-
"lint-staged": "^10.2.11"
56+
"lint-staged": "^10.2.11",
57+
"react-dom": "^16.13.1"
5758
},
5859
"devDependencies": {
5960
"@typescript-eslint/eslint-plugin": "^2.25.0",

src/button.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export class DashboardButton
3636
const callback = (): void => {
3737
const widgetFactory = this._app.docRegistry.getWidgetFactory('dashboard');
3838
const dashboard = widgetFactory.createNew(context);
39-
console.log('new dashboard doc', dashboard);
4039

4140
const currentNotebook = this._tracker.currentWidget;
4241

src/custom_layout.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,6 @@ export class DashboardLayout extends Layout {
203203
widget.mode = 'present';
204204
}
205205
this.attachWidget(widget);
206-
// if (widget.mode !== 'grid') {
207-
// this._moveWidget(widget, _pos, false);
208-
// this._outputTracker.add(widget);
209-
// }
210206

211207
const { id, notebookId, cellId } = widget;
212208

@@ -618,14 +614,19 @@ export class DashboardLayout extends Layout {
618614
});
619615
switch (newMode) {
620616
case 'present':
617+
this.canvas.style.backgroundPosition = null;
618+
this.canvas.style.backgroundSize = null;
621619
this._canvas.classList.remove(FREE_LAYOUT_CLASS);
622620
this._canvas.classList.remove(TILED_LAYOUT_CLASS);
623621
break;
624622
case 'edit':
623+
this.canvas.style.backgroundPosition = null;
624+
this.canvas.style.backgroundSize = null;
625625
this._canvas.classList.remove(TILED_LAYOUT_CLASS);
626626
this._canvas.classList.add(FREE_LAYOUT_CLASS);
627627
break;
628628
case 'grid':
629+
this.gridSize = this._gridSize;
629630
this._canvas.classList.remove(FREE_LAYOUT_CLASS);
630631
this.canvas.classList.add(TILED_LAYOUT_CLASS);
631632
break;
@@ -723,6 +724,7 @@ export class DashboardLayout extends Layout {
723724
each(this, (_widget) => {
724725
const widget = _widget as DashboardWidget;
725726
const { left, top, width, height } = widget.pos;
727+
726728
if (left + width > maxWidth) {
727729
maxWidth = left + width;
728730
}

src/dashboard.ts renamed to src/dashboard.tsx

Lines changed: 110 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ import { NotebookPanel } from '@jupyterlab/notebook';
22

33
import { CodeCell, MarkdownCell, Cell } from '@jupyterlab/cells';
44

5+
import * as React from 'react';
6+
57
import {
68
WidgetTracker,
79
CommandToolbarButton,
810
IWidgetTracker,
11+
Toolbar,
12+
ReactWidget,
913
} from '@jupyterlab/apputils';
1014

1115
import { CommandRegistry } from '@lumino/commands';
@@ -37,12 +41,20 @@ import { IDashboardModel, DashboardModel } from './model';
3741

3842
import { CommandIDs } from './commands';
3943

44+
import { HTMLSelect } from '@jupyterlab/ui-components';
45+
4046
// HTML element classes
4147

4248
const DASHBOARD_CLASS = 'pr-JupyterDashboard';
4349

4450
const DROP_TARGET_CLASS = 'pr-DropTarget';
4551

52+
const TOOLBAR_MODE_SWITCHER_CLASS = 'pr-ToolbarModeSwitcher';
53+
54+
const TOOLBAR_SELECT_CLASS = 'pr-ToolbarSelector';
55+
56+
const TOOLBAR_CLASS = 'pr-DashboardToolbar';
57+
4658
export const IDashboardTracker = new Token<IDashboardTracker>(
4759
'jupyterlab-interactive-dashboard-editor'
4860
);
@@ -387,6 +399,63 @@ export namespace Dashboard {
387399
}
388400
}
389401

402+
export class DashboardDocument extends DocumentWidget<Dashboard> {
403+
constructor(options: DashboardDocument.IOptions) {
404+
let { content, reveal } = options;
405+
const { context, commandRegistry } = options;
406+
const model = context.model as DashboardModel;
407+
content = content || new Dashboard({ ...options, model, context });
408+
reveal = Promise.all([reveal, context.ready]);
409+
super({
410+
...options,
411+
content: content as Dashboard,
412+
reveal,
413+
});
414+
415+
// Build the toolbar
416+
417+
this.toolbar.addClass(TOOLBAR_CLASS);
418+
419+
const commands = commandRegistry;
420+
const { save, undo, redo, cut, copy, paste, runOutput } = CommandIDs;
421+
422+
const args = { toolbar: true, dashboardId: content.id };
423+
424+
const makeToolbarButton = (
425+
id: string,
426+
tooltip: string
427+
): CommandToolbarButton => {
428+
const button = new CommandToolbarButton({ args, commands, id });
429+
button.node.title = tooltip;
430+
return button;
431+
};
432+
433+
const saveButton = makeToolbarButton(save, 'Save');
434+
const undoButton = makeToolbarButton(undo, 'Undo');
435+
const redoButton = makeToolbarButton(redo, 'Redo');
436+
const cutButton = makeToolbarButton(cut, 'Cut the selected outputs');
437+
const copyButton = makeToolbarButton(copy, 'Copy the selected outputs');
438+
const pasteButton = makeToolbarButton(
439+
paste,
440+
'Paste outputs from the clipboard'
441+
);
442+
const runButton = makeToolbarButton(runOutput, 'Run the selected outputs');
443+
444+
this.toolbar.addItem(save, saveButton);
445+
this.toolbar.addItem(undo, undoButton);
446+
this.toolbar.addItem(redo, redoButton);
447+
this.toolbar.addItem(cut, cutButton);
448+
this.toolbar.addItem(copy, copyButton);
449+
this.toolbar.addItem(paste, pasteButton);
450+
this.toolbar.addItem(runOutput, runButton);
451+
this.toolbar.addItem('spacer', Toolbar.createSpacerItem());
452+
this.toolbar.addItem(
453+
'switchMode',
454+
new DashboardDocument.DashboardModeSwitcher(content as Dashboard)
455+
);
456+
}
457+
}
458+
390459
export namespace DashboardDocument {
391460
export interface IOptions extends DocumentWidget.IOptionsOptionalContent {
392461
/**
@@ -419,83 +488,53 @@ export namespace DashboardDocument {
419488
*/
420489
dashboardHeight?: number;
421490
}
422-
}
423491

424-
export class DashboardDocument extends DocumentWidget<Dashboard> {
425-
constructor(options: DashboardDocument.IOptions) {
426-
let { content, reveal } = options;
427-
const { context, commandRegistry } = options;
428-
const model = context.model as DashboardModel;
429-
content = content || new Dashboard({ ...options, model, context });
430-
reveal = Promise.all([reveal, context.ready]);
431-
super({
432-
...options,
433-
content: content as Dashboard,
434-
reveal,
435-
});
436-
437-
// Build the toolbar
438-
439-
const commands = commandRegistry;
440-
const {
441-
save,
442-
undo,
443-
redo,
444-
cut,
445-
copy,
446-
paste,
447-
runOutput,
448-
startFullscreen,
449-
toggleMode,
450-
} = CommandIDs;
451-
452-
const args = { toolbar: true, dashboardId: content.id };
492+
export class DashboardModeSwitcher extends ReactWidget {
493+
constructor(dashboard: Dashboard) {
494+
super();
495+
this.addClass(TOOLBAR_MODE_SWITCHER_CLASS);
496+
this._dashboard = dashboard;
453497

454-
this.toolbar.addItem(
455-
'save',
456-
new CommandToolbarButton({ args, commands, id: save })
457-
);
458-
this.toolbar.addItem(
459-
'undo',
460-
new CommandToolbarButton({ args, commands, id: undo })
461-
);
462-
this.toolbar.addItem(
463-
'redo',
464-
new CommandToolbarButton({ args, commands, id: redo })
465-
);
466-
this.toolbar.addItem(
467-
'cut',
468-
new CommandToolbarButton({ args, commands, id: cut })
469-
);
470-
this.toolbar.addItem(
471-
'copy',
472-
new CommandToolbarButton({ args, commands, id: copy })
473-
);
474-
this.toolbar.addItem(
475-
'paste',
476-
new CommandToolbarButton({ args, commands, id: paste })
477-
);
478-
this.toolbar.addItem(
479-
'runOutput',
480-
new CommandToolbarButton({ args, commands, id: runOutput })
481-
);
482-
this.toolbar.addItem(
483-
'startFullscreen',
484-
new CommandToolbarButton({ args, commands, id: startFullscreen })
485-
);
486-
this.toolbar.addItem(
487-
'toggleMode',
488-
new CommandToolbarButton({ args, commands, id: toggleMode })
489-
);
498+
if (dashboard.model) {
499+
this.update();
500+
}
490501

491-
// Listen to toggle the icon on the mode switch button.
492-
context.ready.then(() => {
493-
model.stateChanged.connect((_sender, change) => {
502+
dashboard.model.stateChanged.connect((_sender, change) => {
494503
if (change.name === 'mode') {
495-
commandRegistry.notifyCommandChanged(toggleMode);
504+
this.update();
496505
}
497506
}, this);
498-
});
507+
}
508+
509+
private _handleChange(
510+
that: DashboardModeSwitcher
511+
): (event: React.ChangeEvent<HTMLSelectElement>) => void {
512+
return (event: React.ChangeEvent<HTMLSelectElement>): void => {
513+
that.dashboard.model.mode = event.target.value as Dashboard.Mode;
514+
};
515+
}
516+
517+
render(): JSX.Element {
518+
const value = this._dashboard.model.mode;
519+
return (
520+
<HTMLSelect
521+
className={TOOLBAR_SELECT_CLASS}
522+
onChange={this._handleChange(this)}
523+
value={value}
524+
aria-label={'Mode'}
525+
>
526+
<option value="present">Present</option>
527+
<option value="edit">Free Layout</option>
528+
<option value="grid">Tile Layout</option>
529+
</HTMLSelect>
530+
);
531+
}
532+
533+
get dashboard(): Dashboard {
534+
return this._dashboard;
535+
}
536+
537+
private _dashboard: Dashboard;
499538
}
500539
}
501540

src/index.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@ const extension: JupyterFrontEndPlugin<IDashboardTracker> = {
152152
rank: 2,
153153
});
154154

155-
app.contextMenu.addItem({
156-
command: CommandIDs.toggleMode,
157-
selector: '.pr-JupyterDashboard',
158-
rank: 3,
159-
});
155+
// app.contextMenu.addItem({
156+
// command: CommandIDs.toggleMode,
157+
// selector: '.pr-JupyterDashboard',
158+
// rank: 3,
159+
// });
160160

161161
app.contextMenu.addItem({
162162
command: CommandIDs.cut,
@@ -176,11 +176,11 @@ const extension: JupyterFrontEndPlugin<IDashboardTracker> = {
176176
rank: 6,
177177
});
178178

179-
app.contextMenu.addItem({
180-
command: CommandIDs.enableGrid,
181-
selector: '.pr-JupyterDashboard',
182-
rank: 7,
183-
});
179+
// app.contextMenu.addItem({
180+
// command: CommandIDs.enableGrid,
181+
// selector: '.pr-JupyterDashboard',
182+
// rank: 7,
183+
// });
184184

185185
app.contextMenu.addItem({
186186
command: CommandIDs.deleteOutput,
@@ -222,12 +222,12 @@ const extension: JupyterFrontEndPlugin<IDashboardTracker> = {
222222
selector: '.pr-JupyterDashboard',
223223
});
224224

225-
app.commands.addKeyBinding({
226-
command: CommandIDs.toggleMode,
227-
args: {},
228-
keys: ['I'],
229-
selector: '.pr-JupyterDashboard',
230-
});
225+
// app.commands.addKeyBinding({
226+
// command: CommandIDs.toggleMode,
227+
// args: {},
228+
// keys: ['I'],
229+
// selector: '.pr-JupyterDashboard',
230+
// });
231231

232232
app.commands.addKeyBinding({
233233
command: CommandIDs.cut,

src/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ export class DashboardModel extends DocumentModel implements IDashboardModel {
213213
if (oldValue === newValue) {
214214
return;
215215
}
216-
this.triggerStateChange({ name: 'mode', oldValue, newValue });
217216
this._mode = newValue;
217+
this.triggerStateChange({ name: 'mode', oldValue, newValue });
218218
}
219219

220220
get metadata(): IObservableJSON {

0 commit comments

Comments
 (0)