Skip to content

Commit 931f5b3

Browse files
committed
default tile layout; scroll mode toggle; trim dashboard
1 parent f44a33c commit 931f5b3

File tree

7 files changed

+89
-28
lines changed

7 files changed

+89
-28
lines changed

src/commands.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ export namespace CommandIDs {
2121
export const setTileSize = 'dashboard:set-tile-size';
2222
export const saveToMetadata = 'dashboard:save-to-metadata';
2323
export const openFromMetadata = 'dashboard:open-from-metadata';
24+
export const toggleWidgetMode = 'dashboard:toggle-widget-mode';
25+
export const toggleInfiniteScroll = 'dashboard:toggle-infinite-scroll';
26+
export const trimDashboard = 'dashboard:trim-dashboard';
2427
}

src/dashboard.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export class Dashboard extends Widget {
146146
event.dropAction = 'copy';
147147
const source = event.source as DashboardWidget;
148148
const pos = source?.pos;
149-
if (pos) {
149+
if (pos && source.mode === 'grid-edit') {
150150
pos.left = event.offsetX + this.node.scrollLeft;
151151
pos.top = event.offsetY + this.node.scrollTop;
152152
(this.layout as DashboardLayout).drawDropZone(pos, '#2b98f0');
@@ -243,7 +243,7 @@ export class Dashboard extends Widget {
243243

244244
private _evtScroll(_event: Event): void {
245245
const model = this.model;
246-
246+
247247
if (model.scrollMode !== 'infinite') {
248248
return;
249249
}
@@ -421,7 +421,7 @@ export class Dashboard extends Widget {
421421
* Namespace for DashboardArea options.
422422
*/
423423
export namespace Dashboard {
424-
export type Mode = 'edit' | 'present' | 'grid';
424+
export type Mode = 'free-edit' | 'present' | 'grid-edit';
425425

426426
export type ScrollMode = 'infinite' | 'constrained';
427427

@@ -589,9 +589,9 @@ export namespace DashboardDocument {
589589
value={value}
590590
aria-label={'Mode'}
591591
>
592-
<option value="present">Present</option>
593-
<option value="edit">Free Layout</option>
594-
<option value="grid">Tile Layout</option>
592+
<option value='present'>Present</option>
593+
{/* <option value="free-edit">Free Layout</option> */}
594+
<option value='grid-edit'>Edit</option>
595595
</HTMLSelect>
596596
);
597597
}

src/index.ts

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,18 @@ const extension: JupyterFrontEndPlugin<IDashboardTracker> = {
178178
rank: 6,
179179
});
180180

181+
app.contextMenu.addItem({
182+
command: CommandIDs.toggleInfiniteScroll,
183+
selector: '.pr-JupyterDashboard',
184+
rank: 7,
185+
});
186+
187+
app.contextMenu.addItem({
188+
command: CommandIDs.trimDashboard,
189+
selector: '.pr-JupyterDashboard',
190+
rank: 8,
191+
});
192+
181193
app.contextMenu.addItem({
182194
command: CommandIDs.deleteOutput,
183195
selector: '.pr-EditableWidget',
@@ -191,11 +203,17 @@ const extension: JupyterFrontEndPlugin<IDashboardTracker> = {
191203
});
192204

193205
app.contextMenu.addItem({
194-
type: 'separator',
206+
command: CommandIDs.toggleWidgetMode,
195207
selector: '.pr-EditableWidget',
196208
rank: 2,
197209
});
198210

211+
app.contextMenu.addItem({
212+
type: 'separator',
213+
selector: '.pr-EditableWidget',
214+
rank: 3,
215+
});
216+
199217
app.contextMenu.addItem({
200218
command: CommandIDs.openFromMetadata,
201219
selector: '.jp-Notebook',
@@ -372,6 +390,7 @@ function addCommands(
372390
widget.fitContent();
373391
}
374392
},
393+
isVisible: (args) => outputTracker.currentWidget.mode === 'free-edit',
375394
isToggled: (args) => outputTracker.currentWidget.fitToContent,
376395
});
377396

@@ -398,7 +417,7 @@ function addCommands(
398417
execute: (args) => {
399418
const dashboard = dashboardTracker.currentWidget;
400419
if (dashboard.model.mode === 'present') {
401-
dashboard.model.mode = 'edit';
420+
dashboard.model.mode = 'free-edit';
402421
} else {
403422
dashboard.model.mode = 'present';
404423
}
@@ -585,7 +604,6 @@ function addCommands(
585604
cellId: metadata.id,
586605
pos: metadata.pos
587606
};
588-
console.log('widget added', widgetInfo);
589607
widgetstore.addWidget(widgetInfo);
590608
}
591609
}
@@ -616,7 +634,44 @@ function addCommands(
616634
}
617635
return false;
618636
}
619-
})
637+
});
638+
639+
commands.addCommand(CommandIDs.toggleWidgetMode, {
640+
label: 'Snap to Grid',
641+
isToggled: (args) => {
642+
const widget = outputTracker.currentWidget;
643+
return widget.mode === 'grid-edit';
644+
},
645+
execute: (args) => {
646+
const widget = outputTracker.currentWidget;
647+
if (widget.mode === 'grid-edit') {
648+
widget.mode = 'free-edit';
649+
} else if (widget.mode === 'free-edit') {
650+
widget.mode = 'grid-edit';
651+
}
652+
}
653+
});
654+
655+
commands.addCommand(CommandIDs.toggleInfiniteScroll, {
656+
label: 'Infinite Scroll',
657+
isToggled: (args) => dashboardTracker.currentWidget?.model.scrollMode === 'infinite',
658+
execute: (args) => {
659+
const dashboard = dashboardTracker.currentWidget;
660+
if (dashboard.model.scrollMode === 'infinite') {
661+
dashboard.model.scrollMode = 'constrained';
662+
} else {
663+
dashboard.model.scrollMode = 'infinite';
664+
}
665+
}
666+
});
667+
668+
commands.addCommand(CommandIDs.trimDashboard, {
669+
label: 'Trim Dashboard',
670+
execute: (args) => {
671+
const dashboard = dashboardTracker.currentWidget;
672+
(dashboard.layout as DashboardLayout).trimDashboard();
673+
}
674+
});
620675
}
621676

622677
/**

src/layout.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ export class DashboardLayout extends Layout {
5656

5757
this._canvas = DashboardLayout.makeCanvas(this._width, this._height);
5858

59-
if (mode === 'edit') {
59+
if (mode === 'free-edit') {
6060
this._canvas.classList.add(FREE_LAYOUT_CLASS);
61-
} else if (mode === 'grid') {
61+
} else if (mode === 'grid-edit') {
6262
this._canvas.classList.add(TILED_LAYOUT_CLASS);
6363
}
6464

@@ -122,6 +122,9 @@ export class DashboardLayout extends Layout {
122122
onAfterAttach(msg: Message): void {
123123
super.onAfterAttach(msg);
124124
this._dashboard = this.parent as Dashboard;
125+
if (this.mode === 'grid-edit') {
126+
this.setTileSize(this.tileSize);
127+
}
125128
}
126129

127130
/**
@@ -364,7 +367,7 @@ export class DashboardLayout extends Layout {
364367
top = Math.max(top, 0);
365368

366369
// Snap to grid if in grid mode.
367-
if (this._mode === 'grid') {
370+
if (widget.mode === 'grid-edit') {
368371
left = Private.mround(left, this._tileSize);
369372
top = Private.mround(top, this._tileSize);
370373
width = Math.max(Private.mround(width, this._tileSize), this._tileSize);
@@ -747,13 +750,13 @@ export class DashboardLayout extends Layout {
747750
this._canvas.classList.remove(FREE_LAYOUT_CLASS);
748751
this._canvas.classList.remove(TILED_LAYOUT_CLASS);
749752
break;
750-
case 'edit':
753+
case 'free-edit':
751754
this.canvas.style.backgroundPosition = null;
752755
this.canvas.style.backgroundSize = null;
753756
this._canvas.classList.remove(TILED_LAYOUT_CLASS);
754757
this._canvas.classList.add(FREE_LAYOUT_CLASS);
755758
break;
756-
case 'grid':
759+
case 'grid-edit':
757760
this.setTileSize(this._tileSize);
758761
this._canvas.classList.remove(FREE_LAYOUT_CLASS);
759762
this.canvas.classList.add(TILED_LAYOUT_CLASS);
@@ -848,7 +851,7 @@ export class DashboardLayout extends Layout {
848851

849852
let { left, top, width, height } = pos;
850853

851-
if (this.mode === 'grid') {
854+
if (this.mode === 'grid-edit') {
852855
width = Math.max(Private.mround(width, this._tileSize), this._tileSize);
853856
height = Math.max(Private.mround(height, this._tileSize), this._tileSize);
854857
left = Private.mround(left, this._tileSize);
@@ -892,7 +895,7 @@ export class DashboardLayout extends Layout {
892895
* contain all the widgets ("trims" excess dashboard to the right and
893896
* bottom of the content).
894897
*/
895-
trimCanvas(): void {
898+
trimDashboard(): void {
896899
const model = (this.parent as Dashboard).model;
897900
let maxWidth = 0;
898901
let maxHeight = 0;
@@ -1007,7 +1010,7 @@ export namespace DashboardLayout {
10071010
/**
10081011
* The default size of a single tile in tiled layout.
10091012
*/
1010-
export const DEFAULT_TILE_SIZE = 50;
1013+
export const DEFAULT_TILE_SIZE = 32;
10111014
}
10121015

10131016
/**

src/model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ export class DashboardModel extends DocumentModel implements IDashboardModel {
366366

367367
private _metadata: IObservableJSON = new ObservableJSON();
368368
private _loaded = new Signal<this, void>(this);
369-
private _mode: Dashboard.Mode = 'edit';
369+
private _mode: Dashboard.Mode = 'grid-edit';
370370
private _scrollMode: Dashboard.ScrollMode = 'constrained';
371371
private _path: string;
372372
private _restore: boolean = false;

src/widget.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,10 @@ export class DashboardWidget extends Widget {
363363
this.node.style.width = `${width}px`;
364364
this.node.style.height = `${height}px`;
365365

366-
if (this.mode === 'grid') {
366+
if (this.mode === 'grid-edit') {
367367
(this.parent.layout as DashboardLayout).drawDropZone(this.pos, '#2b98f0');
368368
}
369-
if (this.mode !== 'grid' && this._fitToContent && !event.altKey) {
369+
if (this.mode === 'free-edit' && this._fitToContent && !event.altKey) {
370370
this.fitContent();
371371
}
372372
}
@@ -594,7 +594,7 @@ export class DashboardWidget extends Widget {
594594
} else {
595595
this.addClass(EDITABLE_WIDGET_CLASS);
596596
}
597-
if (newMode === 'grid') {
597+
if (newMode === 'grid-edit') {
598598
if (this.parent) {
599599
(this.parent as Dashboard).updateWidget(this, this.pos);
600600
}
@@ -635,9 +635,9 @@ export class DashboardWidget extends Widget {
635635
private _cell: CodeCell | MarkdownCell | null = null;
636636
private _cellId: string;
637637
private _ready = new Signal<this, void>(this);
638-
private _fitToContent = true;
638+
private _fitToContent = false;
639639
private _mouseMode: DashboardWidget.MouseMode = 'none';
640-
private _mode: Dashboard.Mode = 'edit';
640+
private _mode: Dashboard.Mode = 'grid-edit';
641641
private _drag: Drag | null = null;
642642
private _clickData: {
643643
pressX: number;

style/index.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@
8484

8585
.pr-Canvas.pr-TiledLayout {
8686
background-image: linear-gradient(45deg, rgba(160,160,160,.15) 25%, transparent 25%), linear-gradient(-45deg, rgba(160,160,160,.15) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, rgba(160,160,160,.15) 75%), linear-gradient(-45deg, transparent 75%, rgba(160,160,160,.15) 70%);
87-
background-size: 100px 100px;
88-
background-position: 0 0, 0 50px, 50px -50px, -50px 0px;
87+
background-size: 64px 64px;
88+
background-position: 0 0, 0 32px, 32px -32px, -32px 0px;
8989
}
9090

9191
.pr-OnboardingGif {
@@ -113,7 +113,6 @@ select.pr-ToolbarSelector.jp-mod-styled {
113113
display: block;
114114
box-shadow: none;
115115
border: none;
116-
/* top: 5px !important; */
117116
}
118117

119118
.pr-ToolbarSelector.jp-mod-styled select {
@@ -127,5 +126,6 @@ select.pr-ToolbarSelector.jp-mod-styled {
127126
}
128127

129128
.pr-DragImage {
130-
box-shadow: var(--jp-elevation-z2);
129+
box-shadow: var(--jp-elevation-z1);
130+
border: var(--jp-border-width) solid var(--jp-brand-color1);
131131
}

0 commit comments

Comments
 (0)