UNPKG

5.49 kBTypeScriptView Raw
1import { ServerConnection, ServiceManager } from '@jupyterlab/services';
2import { ITranslator } from '@jupyterlab/translation';
3import { CommandRegistry } from '@lumino/commands';
4import { ReadonlyPartialJSONObject, Token } from '@lumino/coreutils';
5import { IDisposable } from '@lumino/disposable';
6import { ISignal } from '@lumino/signaling';
7import { JupyterFrontEnd } from './frontend';
8/**
9 * A token for which a plugin can provide to respond to connection failures
10 * to the application server.
11 */
12export declare const IConnectionLost: Token<IConnectionLost>;
13/**
14 * A function that handles a connection to the server being lost.
15 *
16 * #### Notes
17 * The default implementation shows a simple dialog upon connection
18 * failures, but it may be overridden by extensions to perform other
19 * actions.
20 */
21export type IConnectionLost = (manager: ServiceManager.IManager, err: ServerConnection.NetworkError, translator?: ITranslator) => Promise<void>;
22/**
23 * The application status token.
24 */
25export declare const ILabStatus: Token<ILabStatus>;
26/**
27 * An interface for JupyterLab-like application status functionality.
28 */
29export interface ILabStatus {
30 /**
31 * A signal for when application changes its busy status.
32 */
33 readonly busySignal: ISignal<JupyterFrontEnd<any, any>, boolean>;
34 /**
35 * A signal for when application changes its dirty status.
36 */
37 readonly dirtySignal: ISignal<JupyterFrontEnd<any, any>, boolean>;
38 /**
39 * Whether the application is busy.
40 */
41 readonly isBusy: boolean;
42 /**
43 * Whether the application is dirty.
44 */
45 readonly isDirty: boolean;
46 /**
47 * Set the application state to busy.
48 *
49 * @returns A disposable used to clear the busy state for the caller.
50 */
51 setBusy(): IDisposable;
52 /**
53 * Set the application state to dirty.
54 *
55 * @returns A disposable used to clear the dirty state for the caller.
56 */
57 setDirty(): IDisposable;
58}
59/**
60 * The URL Router token.
61 */
62export declare const IRouter: Token<IRouter>;
63/**
64 * A static class that routes URLs within the application.
65 */
66export interface IRouter {
67 /**
68 * The base URL for the router.
69 */
70 readonly base: string;
71 /**
72 * The command registry used by the router.
73 */
74 readonly commands: CommandRegistry;
75 /**
76 * The parsed current URL of the application.
77 */
78 readonly current: IRouter.ILocation;
79 /**
80 * A signal emitted when the router routes a route.
81 */
82 readonly routed: ISignal<IRouter, IRouter.ILocation>;
83 /**
84 * If a matching rule's command resolves with the `stop` token during routing,
85 * no further matches will execute.
86 */
87 readonly stop: Token<void>;
88 /**
89 * Navigate to a new path within the application.
90 *
91 * @param path - The new path or empty string if redirecting to root.
92 *
93 * @param options - The navigation options.
94 */
95 navigate(path: string, options?: IRouter.INavOptions): void;
96 /**
97 * Register a rule that maps a path pattern to a command.
98 *
99 * @param options - The route registration options.
100 *
101 * @returns A disposable that removes the registered rule from the router.
102 */
103 register(options: IRouter.IRegisterOptions): IDisposable;
104 /**
105 * Cause a hard reload of the document.
106 */
107 reload(): void;
108 /**
109 * Route a specific path to an action.
110 *
111 * @param url - The URL string that will be routed.
112 *
113 * #### Notes
114 * If a pattern is matched, its command will be invoked with arguments that
115 * match the `IRouter.ILocation` interface.
116 */
117 route(url: string): void;
118}
119/**
120 * A namespace for the `IRouter` specification.
121 */
122export declare namespace IRouter {
123 /**
124 * The parsed location currently being routed.
125 */
126 interface ILocation extends ReadonlyPartialJSONObject {
127 /**
128 * The location hash.
129 */
130 hash: string;
131 /**
132 * The path that matched a routing pattern.
133 */
134 path: string;
135 /**
136 * The request being routed with the router `base` omitted.
137 *
138 * #### Notes
139 * This field includes the query string and hash, if they exist.
140 */
141 request: string;
142 /**
143 * The search element, including leading question mark (`'?'`), if any,
144 * of the path.
145 */
146 search?: string;
147 }
148 /**
149 * The options passed into a navigation request.
150 */
151 interface INavOptions {
152 /**
153 * Whether the navigation should be hard URL change instead of an HTML
154 * history API change.
155 */
156 hard?: boolean;
157 /**
158 * Should the routing stage be skipped when navigating? This will simply rewrite the URL
159 * and push the new state to the history API, no routing commands will be triggered.
160 */
161 skipRouting?: boolean;
162 }
163 /**
164 * The specification for registering a route with the router.
165 */
166 interface IRegisterOptions {
167 /**
168 * The command string that will be invoked upon matching.
169 */
170 command: string;
171 /**
172 * The regular expression that will be matched against URLs.
173 */
174 pattern: RegExp;
175 /**
176 * The rank order of the registered rule. A lower rank denotes a higher
177 * priority. The default rank is `100`.
178 */
179 rank?: number;
180 }
181}