Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 46 additions & 28 deletions nbdime/webapp/templates/diff.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
{% extends "nbdimepage.html" %}
{% extends "nbdimepage.html" %} {% block nbdimeheader %}

{% block nbdimeheader %}
<div id="nbdime-header" class="nbdime-Diff">
<h3>Notebook Diff</h3>
Enter notebook filenames or URLs in the form below to get started.

<div id="nbdime-header" class="nbdime-Diff">
<h3>Notebook Diff</h3>
Enter notebook filenames or URLs in the form below to get started.
<form id="nbdime-diff-form" class="nbdime-forms">
<fieldset>
<legend>Please input filenames/URLs of notebooks to diff:</legend>
<label>Base:</label>
<input
id="diff-base"
type="text"
name="base"
value="{{ config_data['base']|e }}"
/>
<label>Remote:</label>
<input
id="diff-remote"
type="text"
name="remote"
value="{{ config_data['remote']|e }}"
/>
<input
id="nbdime-run-diff"
type="submit"
name="diff"
value="Diff files"
/>
</fieldset>
</form>
<!-- nbdime-forms -->
<div id="nbdime-header-buttonrow">
<button id="nbdime-trust" style="display: none">Trust outputs</button>
<button id="nbdime-close" type="checkbox" style="display: none">
Close tool
</button>
<button id="nbdime-export" type="checkbox" style="display: none">
Export diff
</button>
</div>
<div id="nbdime-header-banner">
<span id="nbdime-header-base">Base</span>
<span id="nbdime-header-remote">Remote</span>
</div>
</div>
<!-- ndime-header -->

<form id="nbdime-diff-form" class="nbdime-forms">
<fieldset>
<legend>Please input filenames/URLs of notebooks to diff:</legend>
<label>Base:</label>
<input id="diff-base" type="text" name="base" value="{{ config_data['base']|e }}" />
<label>Remote:</label>
<input id="diff-remote" type="text" name="remote" value="{{ config_data['remote']|e }}" />
<input id="nbdime-run-diff" type="submit" name="diff" value="Diff files" />
</fieldset>
</form> <!-- nbdime-forms -->
<div id="nbdime-header-buttonrow">
<input id="nbdime-hide-unchanged" type="checkbox"><label for="cbox1">Hide unchanged cells</label></input>
<button id="nbdime-trust" style="display: none">Trust outputs</button>
<button id="nbdime-close" type="checkbox" style="display: none">Close tool</button>
<button id="nbdime-export" type="checkbox" style="display: none">Export diff</button>
</div>
<div id=nbdime-header-banner>
<span id="nbdime-header-base">Base</span>
<span id="nbdime-header-remote">Remote</span>
</div>
</div> <!-- ndime-header -->

{% endblock %}
{% endblock %}
1 change: 1 addition & 0 deletions packages/nbdime/src/diff/widget/fold-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/nbdime/src/diff/widget/fold-up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/nbdime/src/diff/widget/fold.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
222 changes: 222 additions & 0 deletions packages/nbdime/src/diff/widget/linked-cells.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
import { Panel, Widget } from "@lumino/widgets";
import type { CellDiffWidget } from "./";
import { LabIcon } from "@jupyterlab/ui-components";

import foldDown from "./fold-down.svg";
import foldUp from "./fold-up.svg";
import fold from "./fold.svg";

export const foldDownIcon = new LabIcon({
name: "nbdime:fold-down",
svgstr: foldDown
});

export const foldUpIcon = new LabIcon({
name: "nbdime:fold-up",
svgstr: foldUp
});

export const foldIcon = new LabIcon({
name: "nbdime:fold",
svgstr: fold
});

export interface ILinkedListCell {
_next: ILinkedListCell | null;
_prev: ILinkedListCell | null;
displayed: boolean;
lazy: boolean;
expandUp: () => void;
expandDown: () => void;
}

class LinkedListCell extends Panel implements ILinkedListCell {
renderFunc: () => CellDiffWidget;
displayed: boolean;
_next: ILinkedListCell | null;
_prev: ILinkedListCell | null;
lazy: boolean;

constructor(renderFunc: () => CellDiffWidget) {
super();
this._next = null;
this._prev = null;
this.renderFunc = renderFunc;
this.displayed = true;
this.renderCell();
this.addClass("linked-cell");
this.lazy = false;
}

protected renderCell() {
this.addWidget(this.renderFunc());
this.displayed = true;
}

get next() {
return this._next;
}

set next(nextCell) {
this._next = nextCell;
if (nextCell === null) {
return;
}

if (nextCell.lazy) {
nextCell.expandDown();
}
}

get prev() {
return this._prev;
}

set prev(prevCell) {
this._prev = prevCell;
if (prevCell === null) {
return;
}
prevCell._next = this as ILinkedListCell;
if (prevCell.lazy) {
prevCell.expandUp();
}
}

expandUp(): void {
return;
}

expandDown(): void {
return;
}
}

class LazyDisplayLinkedListCell extends LinkedListCell {
expandButton: HTMLDivElement;
expandButtonDisplayed: boolean;

// Path: packages/nbdime/src/diff/widget/wrapper_cells.ts
constructor(renderFunc: () => CellDiffWidget) {
super(renderFunc);
this.expandButton = document.createElement("div");
this.expandButton.className = "jp-expand-output-wrapper";
this.expandButtonDisplayed = false;
this.addClass("lazy-linked-cell");
this.lazy = true;
}

set prev(prevCell: LinkedListCell | LazyDisplayLinkedListCell) {
this._prev = prevCell;
prevCell.next = this;
}

set next(nextCell: LinkedListCell | LazyDisplayLinkedListCell) {
this._next = nextCell;
}

protected renderCell() {
this.displayed = false;
}

expandUp(): void {
if (this.displayed) {
return;
}
if (this.expandButtonDisplayed) {
this._setupFoldButton();
} else {
this._setupExpandUpButton();
}
}

expandDown(): void {
if (this.displayed) {
return;
}
if (this.expandButtonDisplayed) {
this._setupFoldButton();
} else {
this._setupExpandDownButton();
}
}

_setupFoldButton() {
this.expandButton.innerHTML = "";
const button = this.createButton("Fold");
button.onclick = (e) => {
e.preventDefault();
this.showLazyCellUp();
};
this.expandButton.appendChild(button);
const widget = new Widget({ node: this.expandButton });
this.addWidget(widget);
}

_setupExpandUpButton() {
const button = this.createButton("Up");
button.onclick = (e) => {
e.preventDefault();
this.showLazyCellUp();
};
this.expandButton.appendChild(button);
const widget = new Widget({ node: this.expandButton });
this.addWidget(widget);
}

_setupExpandDownButton() {
const button = this.createButton("Down");
button.onclick = (e) => {
e.preventDefault();
this.showLazyCellDown();
};
this.expandButton.appendChild(button);
const widget = new Widget({ node: this.expandButton });
this.addWidget(widget);
}

createButton(direction: "Up" | "Down" | "Fold"): HTMLAnchorElement {
this.expandButton.innerHTML = "";
const button = document.createElement("a");
button.title = `Expand ${direction}`;
button.setAttribute("aria-label", `Expand ${direction}`);
let icon = this.buttonSvg(direction);
icon.element({
container: button,
})
this.expandButtonDisplayed = true;
return button;
}

buttonSvg(direction: "Up" | "Down" | "Fold"): LabIcon {
if (direction === "Up") {
return foldUpIcon;
} else if (direction === "Down") {
return foldDownIcon;
} else {
return foldIcon;
}
}

showLazyCellUp() {
this.showLazyCell();
if (this._prev) {
this._prev.expandUp();
}
}

showLazyCellDown() {
this.showLazyCell();
if (this._next) {
this._next.expandDown();
}
}

showLazyCell() {
this.addWidget(this.renderFunc());
this.displayed = true;
this.expandButton.remove();
}
}

export { LinkedListCell, LazyDisplayLinkedListCell };
Loading