-
Notifications
You must be signed in to change notification settings - Fork 185
Make Cells Display Lazily When Diffing Unchanged Cells #636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gwincr11
wants to merge
7
commits into
jupyter:main
Choose a base branch
from
gwincr11:cg-refactor-widget
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8b14e74
Make Cells Display Lazily When Diffing Unchanged Cells
gwincr11 4d981cc
remove debug code
gwincr11 737cd05
move colors to variables
gwincr11 2a76a91
working on passing classes in
gwincr11 bd607d7
working on typescript interface
gwincr11 3f9c36b
setup with new typescript version and build
gwincr11 6248748
updating css variables
gwincr11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 %} | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.