-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
173 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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,25 @@ | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
|
||
import { URLExt } from "@jupyterlab/coreutils"; | ||
|
||
import { INotebookPathOpener } from "./tokens"; | ||
|
||
/** | ||
* A class to open path in new browser tabs in the Notebook application. | ||
*/ | ||
class DefaultNotebookPathOpener implements INotebookPathOpener { | ||
/** | ||
* Open a path in a new browser tab. | ||
*/ | ||
open(options: INotebookPathOpener.IOpenOptions): WindowProxy | null { | ||
const { route, path, searchParams, target, features } = options; | ||
const url = new URL(URLExt.join(route, path ?? ''), window.location.origin); | ||
if (searchParams) { | ||
url.search = searchParams.toString(); | ||
} | ||
return window.open(url, target, features); | ||
} | ||
} | ||
|
||
export const defaultNotebookPathOpener = new DefaultNotebookPathOpener(); |
This file contains 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
This file contains 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,29 +1,54 @@ | ||
import { Token } from '@lumino/coreutils'; | ||
|
||
import { NotebookShell } from './shell'; | ||
|
||
/** | ||
* The INotebookPathOpener interface. | ||
*/ | ||
export interface INotebookPathOpener { | ||
open: (route: string, path?: string) => void; | ||
/** | ||
* Open a path in the application. | ||
* | ||
* @param options - The options used to open the path. | ||
*/ | ||
open: (options: INotebookPathOpener.IOpenOptions) => WindowProxy | null; | ||
} | ||
|
||
export namespace INotebookPathOpener { | ||
export interface IOpenOptions { | ||
/** | ||
* The base route, which should include the base URL | ||
*/ | ||
route: string | ||
|
||
/** | ||
* The path to open in the application, e.g `setup.py`, or `notebooks/example.ipynb` | ||
*/ | ||
path?: string, | ||
|
||
/** | ||
* The extra search params to use in the URL. | ||
*/ | ||
searchParams?: URLSearchParams; | ||
|
||
/** | ||
* Name of the browsing context the resource is being loaded into. | ||
* See https://developer.mozilla.org/en-US/docs/Web/API/Window/open for more details. | ||
*/ | ||
target?: string; | ||
|
||
/** | ||
* | ||
* See https://developer.mozilla.org/en-US/docs/Web/API/Window/open for more details. | ||
*/ | ||
features?: string; | ||
} | ||
} | ||
|
||
/** | ||
* The INotebookPathOpener token. | ||
* The main purpose of this token is to allow other extensions or downstream application | ||
* to override the default behavior of opening a notebook in a new tab. | ||
* It also allows to pass the path open as a search parame, or other options to the window.open call. | ||
*/ | ||
export const INotebookPathOpener = new Token<INotebookPathOpener>( | ||
'@jupyter-notebook/application:INotebookPathOpener' | ||
); | ||
|
||
/** | ||
* The Jupyter Notebook application shell interface. | ||
*/ | ||
export interface INotebookShell extends NotebookShell {} | ||
|
||
/** | ||
* The Jupyter Notebook application shell token. | ||
*/ | ||
export const INotebookShell = new Token<INotebookShell>( | ||
'@jupyter-notebook/application:INotebookShell' | ||
); |
This file contains 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
This file contains 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
Oops, something went wrong.