Skip to content

Commit

Permalink
feat(fullscreen): auto extend size of new output view cell
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Apr 18, 2024
1 parent fe790ae commit ce8287c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { TrameJupyterWebSocket } from './websocket';
import { ContextManager } from './manager';
import { Registry } from './registry';
import { getExtensionLocation } from './location';
import { updateOutputs } from './utils';

/**
* A notebook widget extension that creates a kernel manager each time a notebook is opened.
Expand All @@ -34,7 +35,6 @@ export class WidgetExtension
context: DocumentRegistry.IContext<INotebookModel>
): IDisposable {
const manager = new ContextManager(context, this._endpoint, this._www);

return manager;
}
}
Expand Down Expand Up @@ -70,6 +70,9 @@ const plugin: JupyterFrontEndPlugin<void> = {
});
}

// Enable fullscreen output if any
updateOutputs();

return {
createWebSocket: () => {
return new TrameJupyterWebSocket(childWindow, comm!);
Expand Down
36 changes: 36 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export function updateOutputs() {
const full = document.querySelectorAll<HTMLElement>(
'.jp-LinkedOutputView iframe[id^=trame]'
);
const all = document.querySelectorAll<HTMLElement>('iframe[id^=trame]');
const visibleInFullScreen: Record<string, boolean> = {};
const moveToFullScreen: Array<HTMLElement> = [];

for (let i = 0; i < full.length; i++) {
const iframe = full[i];
visibleInFullScreen[iframe.id] = true;
moveToFullScreen.push(iframe);
}
for (let i = 0; i < all.length; i++) {
const iframe = all[i];
if (moveToFullScreen.includes(iframe)) {
continue;
}
if (visibleInFullScreen[iframe.id]) {
iframe.style.display = 'none';
} else {
iframe.style.display = 'block';
}
}
for (let i = 0; i < moveToFullScreen.length; i++) {
const iframe = moveToFullScreen[i];
iframe.style.width = '100%';
iframe.style.height = '100%';
if (iframe?.parentElement) {
iframe.parentElement.style.padding = '0';
}
if (iframe?.parentElement?.parentElement) {
iframe.parentElement.parentElement.style.height = '100%';
}
}
}
4 changes: 2 additions & 2 deletions src/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ type WebsocketMessage<T> = { data: T };

function toBuffer(msgpack: any) {
if (msgpack.buffer) {
if (msgpack.buffer.byteLength != msgpack.length) {
console.warn("toBuffer: deep copy")
if (msgpack.buffer.byteLength !== msgpack.length) {
console.warn('toBuffer: deep copy');
const tmp = new Uint8Array(msgpack.length);
tmp.set(msgpack);
return tmp.buffer;
Expand Down

0 comments on commit ce8287c

Please sign in to comment.