Skip to content
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

Resize widgets when resizing cells or document #157

Merged
merged 2 commits into from
Jan 1, 2022
Merged
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
15 changes: 15 additions & 0 deletions .github/workflows/binder-on-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Binder Badge
on:
pull_request_target:
types: [opened]

jobs:
binder:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: jupyterlab/maintainer-tools/.github/actions/binder-link@v1
with:
github_token: ${{ secrets.github_token }}
url_path: lab/tree/examples
37 changes: 37 additions & 0 deletions packages/jupyterlab-gridstack/src/editor/gridstack/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ export class GridStackLayout extends Layout {
}
);

this._grid.on(
'resize',
(
event: Event,
item?: GridItemHTMLElement | GridStackNode | GridStackNode[]
) => {
if (item && (item as GridItemHTMLElement).gridstackNode) {
this._onResize(event, (item as GridItemHTMLElement).gridstackNode!);
}
}
);

this._grid.on('resizestop', (event, elem) => {
window.dispatchEvent(new Event('resize'));
});
Expand Down Expand Up @@ -121,6 +133,11 @@ export class GridStackLayout extends Layout {
* Handle `resize-request` messages sent to the widget.
*/
protected onResize(msg: Message): void {
// Using timeout to wait until the resize stop
// rerendering all the widgets every time uses
// too much resources
clearTimeout(this._resizeTimeout);
this._resizeTimeout = setTimeout(this._onResizeStops, 500);
this._prepareGrid();
}

Expand Down Expand Up @@ -323,6 +340,25 @@ export class GridStackLayout extends Layout {
});
}

/**
* Handle resize event messages sent from gridstack.
*/
private _onResize(event: Event, item: GridStackNode): void {
const widget = this._gridItems.find((value) => value.cellId === item.id);
if (widget) {
MessageLoop.sendMessage(widget, Widget.Msg.UpdateRequest);
}
}

/**
* Handle resize-stop event messages in the layout.
*/
private _onResizeStops = (): void => {
this._gridItems.forEach((item) => {
MessageLoop.sendMessage(item, Widget.Msg.UpdateRequest);
});
};

/**
* Update background size style to fit new grid parameters
*/
Expand Down Expand Up @@ -352,4 +388,5 @@ export class GridStackLayout extends Layout {
private _gridItems: GridStackItemWidget[] = [];
private _gridItemChanged = new Signal<this, GridStackNode[]>(this);
private _helperMessage: HTMLElement;
private _resizeTimeout = 0;
}