@jupyterlab/application 0.19.1-alpha.0 → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +34 -0
- package/lib/index.d.ts +241 -241
- package/lib/index.js +283 -283
- package/lib/layoutrestorer.d.ts +205 -205
- package/lib/layoutrestorer.js +423 -423
- package/lib/mimerenderers.d.ts +22 -22
- package/lib/mimerenderers.js +137 -134
- package/lib/router.d.ts +204 -204
- package/lib/router.js +145 -145
- package/lib/shell.d.ts +277 -277
- package/lib/shell.js +857 -854
- package/package.json +13 -10
package/lib/router.js
CHANGED
|
@@ -1,145 +1,145 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*-----------------------------------------------------------------------------
|
|
3
|
-
| Copyright (c) Jupyter Development Team.
|
|
4
|
-
| Distributed under the terms of the Modified BSD License.
|
|
5
|
-
|----------------------------------------------------------------------------*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const coreutils_1 = require("@jupyterlab/coreutils");
|
|
8
|
-
const coreutils_2 = require("@phosphor/coreutils");
|
|
9
|
-
const disposable_1 = require("@phosphor/disposable");
|
|
10
|
-
const signaling_1 = require("@phosphor/signaling");
|
|
11
|
-
/* tslint:disable */
|
|
12
|
-
/**
|
|
13
|
-
* The URL Router token.
|
|
14
|
-
*/
|
|
15
|
-
exports.IRouter = new coreutils_2.Token('@jupyterlab/application:IRouter');
|
|
16
|
-
/**
|
|
17
|
-
* A static class that routes URLs within the application.
|
|
18
|
-
*/
|
|
19
|
-
class Router {
|
|
20
|
-
/**
|
|
21
|
-
* Create a URL router.
|
|
22
|
-
*/
|
|
23
|
-
constructor(options) {
|
|
24
|
-
/**
|
|
25
|
-
* If a matching rule's command resolves with the `stop` token during routing,
|
|
26
|
-
* no further matches will execute.
|
|
27
|
-
*/
|
|
28
|
-
this.stop = new coreutils_2.Token('@jupyterlab/application:Router#stop');
|
|
29
|
-
this._routed = new signaling_1.Signal(this);
|
|
30
|
-
this._rules = new Map();
|
|
31
|
-
this.base = options.base;
|
|
32
|
-
this.commands = options.commands;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Returns the parsed current URL of the application.
|
|
36
|
-
*/
|
|
37
|
-
get current() {
|
|
38
|
-
const { base } = this;
|
|
39
|
-
const parsed = coreutils_1.URLExt.parse(window.location.href);
|
|
40
|
-
const { search, hash } = parsed;
|
|
41
|
-
const path = parsed.pathname.replace(base, '/');
|
|
42
|
-
const request = path + search + hash;
|
|
43
|
-
return { hash, path, request, search };
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* A signal emitted when the router routes a route.
|
|
47
|
-
*/
|
|
48
|
-
get routed() {
|
|
49
|
-
return this._routed;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Navigate to a new path within the application.
|
|
53
|
-
*
|
|
54
|
-
* @param path - The new path or empty string if redirecting to root.
|
|
55
|
-
*
|
|
56
|
-
* @param options - The navigation options.
|
|
57
|
-
*/
|
|
58
|
-
navigate(path, options = {}) {
|
|
59
|
-
const { base } = this;
|
|
60
|
-
const { history } = window;
|
|
61
|
-
const { hard, silent } = options;
|
|
62
|
-
const url = path && path.indexOf(base) === 0 ? path : coreutils_1.URLExt.join(base, path);
|
|
63
|
-
if (silent) {
|
|
64
|
-
history.replaceState({}, '', url);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
history.pushState({}, '', url);
|
|
68
|
-
}
|
|
69
|
-
if (hard) {
|
|
70
|
-
return this.reload();
|
|
71
|
-
}
|
|
72
|
-
// Because a `route()` call may still be in the stack after having received
|
|
73
|
-
// a `stop` token, wait for the next stack frame before calling `route()`.
|
|
74
|
-
requestAnimationFrame(() => {
|
|
75
|
-
this.route();
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Register to route a path pattern to a command.
|
|
80
|
-
*
|
|
81
|
-
* @param options - The route registration options.
|
|
82
|
-
*
|
|
83
|
-
* @returns A disposable that removes the registered rule from the router.
|
|
84
|
-
*/
|
|
85
|
-
register(options) {
|
|
86
|
-
const { command, pattern } = options;
|
|
87
|
-
const rank = 'rank' in options ? options.rank : 100;
|
|
88
|
-
const rules = this._rules;
|
|
89
|
-
rules.set(pattern, { command, rank });
|
|
90
|
-
return new disposable_1.DisposableDelegate(() => {
|
|
91
|
-
rules.delete(pattern);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Cause a hard reload of the document.
|
|
96
|
-
*/
|
|
97
|
-
reload() {
|
|
98
|
-
window.location.reload();
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Route a specific path to an action.
|
|
102
|
-
*
|
|
103
|
-
* #### Notes
|
|
104
|
-
* If a pattern is matched, its command will be invoked with arguments that
|
|
105
|
-
* match the `IRouter.ILocation` interface.
|
|
106
|
-
*/
|
|
107
|
-
route() {
|
|
108
|
-
const { commands, current, stop } = this;
|
|
109
|
-
const { request } = current;
|
|
110
|
-
const routed = this._routed;
|
|
111
|
-
const rules = this._rules;
|
|
112
|
-
const matches = [];
|
|
113
|
-
// Collect all rules that match the URL.
|
|
114
|
-
rules.forEach((rule, pattern) => {
|
|
115
|
-
if (request.match(pattern)) {
|
|
116
|
-
matches.push(rule);
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
// Order the matching rules by rank and enqueue them.
|
|
120
|
-
const queue = matches.sort((a, b) => b.rank - a.rank);
|
|
121
|
-
// Process each enqueued command sequentially and short-circuit if a promise
|
|
122
|
-
// resolves with the `stop` token.
|
|
123
|
-
(function next() {
|
|
124
|
-
if (!queue.length) {
|
|
125
|
-
routed.emit(current);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const { command } = queue.pop();
|
|
129
|
-
commands
|
|
130
|
-
.execute(command, current)
|
|
131
|
-
.then(result => {
|
|
132
|
-
if (result === stop) {
|
|
133
|
-
queue.length = 0;
|
|
134
|
-
console.log(`Routing ${request} was short-circuited by ${command}`);
|
|
135
|
-
}
|
|
136
|
-
next();
|
|
137
|
-
})
|
|
138
|
-
.catch(reason => {
|
|
139
|
-
console.warn(`Routing ${request} to ${command} failed`, reason);
|
|
140
|
-
next();
|
|
141
|
-
});
|
|
142
|
-
})();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
exports.Router = Router;
|
|
1
|
+
"use strict";
|
|
2
|
+
/*-----------------------------------------------------------------------------
|
|
3
|
+
| Copyright (c) Jupyter Development Team.
|
|
4
|
+
| Distributed under the terms of the Modified BSD License.
|
|
5
|
+
|----------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const coreutils_1 = require("@jupyterlab/coreutils");
|
|
8
|
+
const coreutils_2 = require("@phosphor/coreutils");
|
|
9
|
+
const disposable_1 = require("@phosphor/disposable");
|
|
10
|
+
const signaling_1 = require("@phosphor/signaling");
|
|
11
|
+
/* tslint:disable */
|
|
12
|
+
/**
|
|
13
|
+
* The URL Router token.
|
|
14
|
+
*/
|
|
15
|
+
exports.IRouter = new coreutils_2.Token('@jupyterlab/application:IRouter');
|
|
16
|
+
/**
|
|
17
|
+
* A static class that routes URLs within the application.
|
|
18
|
+
*/
|
|
19
|
+
class Router {
|
|
20
|
+
/**
|
|
21
|
+
* Create a URL router.
|
|
22
|
+
*/
|
|
23
|
+
constructor(options) {
|
|
24
|
+
/**
|
|
25
|
+
* If a matching rule's command resolves with the `stop` token during routing,
|
|
26
|
+
* no further matches will execute.
|
|
27
|
+
*/
|
|
28
|
+
this.stop = new coreutils_2.Token('@jupyterlab/application:Router#stop');
|
|
29
|
+
this._routed = new signaling_1.Signal(this);
|
|
30
|
+
this._rules = new Map();
|
|
31
|
+
this.base = options.base;
|
|
32
|
+
this.commands = options.commands;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Returns the parsed current URL of the application.
|
|
36
|
+
*/
|
|
37
|
+
get current() {
|
|
38
|
+
const { base } = this;
|
|
39
|
+
const parsed = coreutils_1.URLExt.parse(window.location.href);
|
|
40
|
+
const { search, hash } = parsed;
|
|
41
|
+
const path = parsed.pathname.replace(base, '/');
|
|
42
|
+
const request = path + search + hash;
|
|
43
|
+
return { hash, path, request, search };
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A signal emitted when the router routes a route.
|
|
47
|
+
*/
|
|
48
|
+
get routed() {
|
|
49
|
+
return this._routed;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Navigate to a new path within the application.
|
|
53
|
+
*
|
|
54
|
+
* @param path - The new path or empty string if redirecting to root.
|
|
55
|
+
*
|
|
56
|
+
* @param options - The navigation options.
|
|
57
|
+
*/
|
|
58
|
+
navigate(path, options = {}) {
|
|
59
|
+
const { base } = this;
|
|
60
|
+
const { history } = window;
|
|
61
|
+
const { hard, silent } = options;
|
|
62
|
+
const url = path && path.indexOf(base) === 0 ? path : coreutils_1.URLExt.join(base, path);
|
|
63
|
+
if (silent) {
|
|
64
|
+
history.replaceState({}, '', url);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
history.pushState({}, '', url);
|
|
68
|
+
}
|
|
69
|
+
if (hard) {
|
|
70
|
+
return this.reload();
|
|
71
|
+
}
|
|
72
|
+
// Because a `route()` call may still be in the stack after having received
|
|
73
|
+
// a `stop` token, wait for the next stack frame before calling `route()`.
|
|
74
|
+
requestAnimationFrame(() => {
|
|
75
|
+
this.route();
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Register to route a path pattern to a command.
|
|
80
|
+
*
|
|
81
|
+
* @param options - The route registration options.
|
|
82
|
+
*
|
|
83
|
+
* @returns A disposable that removes the registered rule from the router.
|
|
84
|
+
*/
|
|
85
|
+
register(options) {
|
|
86
|
+
const { command, pattern } = options;
|
|
87
|
+
const rank = 'rank' in options ? options.rank : 100;
|
|
88
|
+
const rules = this._rules;
|
|
89
|
+
rules.set(pattern, { command, rank });
|
|
90
|
+
return new disposable_1.DisposableDelegate(() => {
|
|
91
|
+
rules.delete(pattern);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Cause a hard reload of the document.
|
|
96
|
+
*/
|
|
97
|
+
reload() {
|
|
98
|
+
window.location.reload();
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Route a specific path to an action.
|
|
102
|
+
*
|
|
103
|
+
* #### Notes
|
|
104
|
+
* If a pattern is matched, its command will be invoked with arguments that
|
|
105
|
+
* match the `IRouter.ILocation` interface.
|
|
106
|
+
*/
|
|
107
|
+
route() {
|
|
108
|
+
const { commands, current, stop } = this;
|
|
109
|
+
const { request } = current;
|
|
110
|
+
const routed = this._routed;
|
|
111
|
+
const rules = this._rules;
|
|
112
|
+
const matches = [];
|
|
113
|
+
// Collect all rules that match the URL.
|
|
114
|
+
rules.forEach((rule, pattern) => {
|
|
115
|
+
if (request.match(pattern)) {
|
|
116
|
+
matches.push(rule);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
// Order the matching rules by rank and enqueue them.
|
|
120
|
+
const queue = matches.sort((a, b) => b.rank - a.rank);
|
|
121
|
+
// Process each enqueued command sequentially and short-circuit if a promise
|
|
122
|
+
// resolves with the `stop` token.
|
|
123
|
+
(function next() {
|
|
124
|
+
if (!queue.length) {
|
|
125
|
+
routed.emit(current);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const { command } = queue.pop();
|
|
129
|
+
commands
|
|
130
|
+
.execute(command, current)
|
|
131
|
+
.then(result => {
|
|
132
|
+
if (result === stop) {
|
|
133
|
+
queue.length = 0;
|
|
134
|
+
console.log(`Routing ${request} was short-circuited by ${command}`);
|
|
135
|
+
}
|
|
136
|
+
next();
|
|
137
|
+
})
|
|
138
|
+
.catch(reason => {
|
|
139
|
+
console.warn(`Routing ${request} to ${command} failed`, reason);
|
|
140
|
+
next();
|
|
141
|
+
});
|
|
142
|
+
})();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.Router = Router;
|