@jupyterlab/apputils 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.
@@ -1,108 +1,108 @@
1
- import { Message } from '@phosphor/messaging';
2
- import { Widget } from '@phosphor/widgets';
3
- import { Toolbar } from './toolbar';
4
- /**
5
- * A widget meant to be contained in the JupyterLab main area.
6
- *
7
- * #### Notes
8
- * Mirrors all of the `title` attributes of the content.
9
- * This widget is `closable` by default.
10
- * This widget is automatically disposed when closed.
11
- * This widget ensures its own focus when activated.
12
- */
13
- export declare class MainAreaWidget<T extends Widget = Widget> extends Widget {
14
- /**
15
- * Construct a new main area widget.
16
- *
17
- * @param options - The options for initializing the widget.
18
- */
19
- constructor(options: MainAreaWidget.IOptions<T>);
20
- /**
21
- * The content hosted by the widget.
22
- */
23
- readonly content: T;
24
- /**
25
- * The toolbar hosted by the widget.
26
- */
27
- readonly toolbar: Toolbar;
28
- /**
29
- * Whether the content widget or an error is revealed.
30
- */
31
- readonly isRevealed: boolean;
32
- /**
33
- * A promise that resolves when the widget is revealed.
34
- */
35
- readonly revealed: Promise<void>;
36
- /**
37
- * Handle `'activate-request'` messages.
38
- */
39
- protected onActivateRequest(msg: Message): void;
40
- /**
41
- * Handle `'close-request'` messages.
42
- */
43
- protected onCloseRequest(msg: Message): void;
44
- /**
45
- * Update the title based on the attributes of the child widget.
46
- */
47
- private _updateTitle;
48
- /**
49
- * Update the content title based on attributes of the main widget.
50
- */
51
- private _updateContentTitle;
52
- /**
53
- * Give focus to the content.
54
- */
55
- private _focusContent;
56
- private _content;
57
- private _toolbar;
58
- private _changeGuard;
59
- private _spinner;
60
- private _isRevealed;
61
- private _revealed;
62
- }
63
- /**
64
- * The namespace for the `MainAreaWidget` class statics.
65
- */
66
- export declare namespace MainAreaWidget {
67
- /**
68
- * An options object for creating a main area widget.
69
- */
70
- interface IOptions<T extends Widget = Widget> extends Widget.IOptions {
71
- /**
72
- * The child widget to wrap.
73
- */
74
- content: T;
75
- /**
76
- * The toolbar to use for the widget. Defaults to an empty toolbar.
77
- */
78
- toolbar?: Toolbar;
79
- /**
80
- * An optional promise for when the content is ready to be revealed.
81
- */
82
- reveal?: Promise<any>;
83
- }
84
- /**
85
- * An options object for main area widget subclasses providing their own
86
- * default content.
87
- *
88
- * #### Notes
89
- * This makes it easier to have a subclass that provides its own default
90
- * content. This can go away once we upgrade to TypeScript 2.8 and have an
91
- * easy way to make a single property optional, ala
92
- * https://stackoverflow.com/a/46941824
93
- */
94
- interface IOptionsOptionalContent<T extends Widget = Widget> extends Widget.IOptions {
95
- /**
96
- * The child widget to wrap.
97
- */
98
- content?: T;
99
- /**
100
- * The toolbar to use for the widget. Defaults to an empty toolbar.
101
- */
102
- toolbar?: Toolbar;
103
- /**
104
- * An optional promise for when the content is ready to be revealed.
105
- */
106
- reveal?: Promise<any>;
107
- }
108
- }
1
+ import { Message } from '@phosphor/messaging';
2
+ import { Widget } from '@phosphor/widgets';
3
+ import { Toolbar } from './toolbar';
4
+ /**
5
+ * A widget meant to be contained in the JupyterLab main area.
6
+ *
7
+ * #### Notes
8
+ * Mirrors all of the `title` attributes of the content.
9
+ * This widget is `closable` by default.
10
+ * This widget is automatically disposed when closed.
11
+ * This widget ensures its own focus when activated.
12
+ */
13
+ export declare class MainAreaWidget<T extends Widget = Widget> extends Widget {
14
+ /**
15
+ * Construct a new main area widget.
16
+ *
17
+ * @param options - The options for initializing the widget.
18
+ */
19
+ constructor(options: MainAreaWidget.IOptions<T>);
20
+ /**
21
+ * The content hosted by the widget.
22
+ */
23
+ readonly content: T;
24
+ /**
25
+ * The toolbar hosted by the widget.
26
+ */
27
+ readonly toolbar: Toolbar;
28
+ /**
29
+ * Whether the content widget or an error is revealed.
30
+ */
31
+ readonly isRevealed: boolean;
32
+ /**
33
+ * A promise that resolves when the widget is revealed.
34
+ */
35
+ readonly revealed: Promise<void>;
36
+ /**
37
+ * Handle `'activate-request'` messages.
38
+ */
39
+ protected onActivateRequest(msg: Message): void;
40
+ /**
41
+ * Handle `'close-request'` messages.
42
+ */
43
+ protected onCloseRequest(msg: Message): void;
44
+ /**
45
+ * Update the title based on the attributes of the child widget.
46
+ */
47
+ private _updateTitle;
48
+ /**
49
+ * Update the content title based on attributes of the main widget.
50
+ */
51
+ private _updateContentTitle;
52
+ /**
53
+ * Give focus to the content.
54
+ */
55
+ private _focusContent;
56
+ private _content;
57
+ private _toolbar;
58
+ private _changeGuard;
59
+ private _spinner;
60
+ private _isRevealed;
61
+ private _revealed;
62
+ }
63
+ /**
64
+ * The namespace for the `MainAreaWidget` class statics.
65
+ */
66
+ export declare namespace MainAreaWidget {
67
+ /**
68
+ * An options object for creating a main area widget.
69
+ */
70
+ interface IOptions<T extends Widget = Widget> extends Widget.IOptions {
71
+ /**
72
+ * The child widget to wrap.
73
+ */
74
+ content: T;
75
+ /**
76
+ * The toolbar to use for the widget. Defaults to an empty toolbar.
77
+ */
78
+ toolbar?: Toolbar;
79
+ /**
80
+ * An optional promise for when the content is ready to be revealed.
81
+ */
82
+ reveal?: Promise<any>;
83
+ }
84
+ /**
85
+ * An options object for main area widget subclasses providing their own
86
+ * default content.
87
+ *
88
+ * #### Notes
89
+ * This makes it easier to have a subclass that provides its own default
90
+ * content. This can go away once we upgrade to TypeScript 2.8 and have an
91
+ * easy way to make a single property optional, ala
92
+ * https://stackoverflow.com/a/46941824
93
+ */
94
+ interface IOptionsOptionalContent<T extends Widget = Widget> extends Widget.IOptions {
95
+ /**
96
+ * The child widget to wrap.
97
+ */
98
+ content?: T;
99
+ /**
100
+ * The toolbar to use for the widget. Defaults to an empty toolbar.
101
+ */
102
+ toolbar?: Toolbar;
103
+ /**
104
+ * An optional promise for when the content is ready to be revealed.
105
+ */
106
+ reveal?: Promise<any>;
107
+ }
108
+ }
@@ -1,184 +1,184 @@
1
- "use strict";
2
- // Copyright (c) Jupyter Development Team.
3
- // Distributed under the terms of the Modified BSD License.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- const coreutils_1 = require("@phosphor/coreutils");
6
- const widgets_1 = require("@phosphor/widgets");
7
- const spinner_1 = require("./spinner");
8
- const toolbar_1 = require("./toolbar");
9
- /**
10
- * A widget meant to be contained in the JupyterLab main area.
11
- *
12
- * #### Notes
13
- * Mirrors all of the `title` attributes of the content.
14
- * This widget is `closable` by default.
15
- * This widget is automatically disposed when closed.
16
- * This widget ensures its own focus when activated.
17
- */
18
- class MainAreaWidget extends widgets_1.Widget {
19
- /**
20
- * Construct a new main area widget.
21
- *
22
- * @param options - The options for initializing the widget.
23
- */
24
- constructor(options) {
25
- super(options);
26
- this._changeGuard = false;
27
- this._spinner = new spinner_1.Spinner();
28
- this._isRevealed = false;
29
- this.addClass('jp-MainAreaWidget');
30
- this.id = coreutils_1.UUID.uuid4();
31
- const content = (this._content = options.content);
32
- const toolbar = (this._toolbar = options.toolbar || new toolbar_1.Toolbar());
33
- const spinner = this._spinner;
34
- const layout = (this.layout = new widgets_1.BoxLayout({ spacing: 0 }));
35
- layout.direction = 'top-to-bottom';
36
- widgets_1.BoxLayout.setStretch(toolbar, 0);
37
- widgets_1.BoxLayout.setStretch(content, 1);
38
- layout.addWidget(toolbar);
39
- layout.addWidget(content);
40
- if (!content.id) {
41
- content.id = coreutils_1.UUID.uuid4();
42
- }
43
- content.node.tabIndex = -1;
44
- this._updateTitle();
45
- content.title.changed.connect(this._updateTitle, this);
46
- this.title.closable = true;
47
- this.title.changed.connect(this._updateContentTitle, this);
48
- if (options.reveal) {
49
- this.node.appendChild(spinner.node);
50
- this._revealed = options.reveal
51
- .then(() => {
52
- if (content.isDisposed) {
53
- this.dispose();
54
- return;
55
- }
56
- content.disposed.connect(() => this.dispose());
57
- const active = document.activeElement === spinner.node;
58
- this.node.removeChild(spinner.node);
59
- spinner.dispose();
60
- this._isRevealed = true;
61
- if (active) {
62
- this._focusContent();
63
- }
64
- })
65
- .catch(e => {
66
- // Show a revealed promise error.
67
- const error = new widgets_1.Widget();
68
- // Show the error to the user.
69
- const pre = document.createElement('pre');
70
- pre.textContent = String(e);
71
- error.node.appendChild(pre);
72
- widgets_1.BoxLayout.setStretch(error, 1);
73
- this.node.removeChild(spinner.node);
74
- spinner.dispose();
75
- content.dispose();
76
- this._content = null;
77
- toolbar.dispose();
78
- this._toolbar = null;
79
- layout.addWidget(error);
80
- this._isRevealed = true;
81
- throw error;
82
- });
83
- }
84
- else {
85
- // Handle no reveal promise.
86
- spinner.dispose();
87
- content.disposed.connect(() => this.dispose());
88
- this._isRevealed = true;
89
- this._revealed = Promise.resolve(undefined);
90
- }
91
- }
92
- /**
93
- * The content hosted by the widget.
94
- */
95
- get content() {
96
- return this._content;
97
- }
98
- /**
99
- * The toolbar hosted by the widget.
100
- */
101
- get toolbar() {
102
- return this._toolbar;
103
- }
104
- /**
105
- * Whether the content widget or an error is revealed.
106
- */
107
- get isRevealed() {
108
- return this._isRevealed;
109
- }
110
- /**
111
- * A promise that resolves when the widget is revealed.
112
- */
113
- get revealed() {
114
- return this._revealed;
115
- }
116
- /**
117
- * Handle `'activate-request'` messages.
118
- */
119
- onActivateRequest(msg) {
120
- if (this._isRevealed) {
121
- if (this._content) {
122
- this._focusContent();
123
- }
124
- }
125
- else {
126
- this._spinner.node.focus();
127
- }
128
- }
129
- /**
130
- * Handle `'close-request'` messages.
131
- */
132
- onCloseRequest(msg) {
133
- this.dispose();
134
- }
135
- /**
136
- * Update the title based on the attributes of the child widget.
137
- */
138
- _updateTitle() {
139
- if (this._changeGuard) {
140
- return;
141
- }
142
- this._changeGuard = true;
143
- const content = this.content;
144
- this.title.label = content.title.label;
145
- this.title.mnemonic = content.title.mnemonic;
146
- this.title.iconClass = content.title.iconClass;
147
- this.title.iconLabel = content.title.iconLabel;
148
- this.title.caption = content.title.caption;
149
- this.title.className = content.title.className;
150
- this.title.dataset = content.title.dataset;
151
- this._changeGuard = false;
152
- }
153
- /**
154
- * Update the content title based on attributes of the main widget.
155
- */
156
- _updateContentTitle() {
157
- if (this._changeGuard) {
158
- return;
159
- }
160
- this._changeGuard = true;
161
- const content = this.content;
162
- content.title.label = this.title.label;
163
- content.title.mnemonic = this.title.mnemonic;
164
- content.title.iconClass = this.title.iconClass;
165
- content.title.iconLabel = this.title.iconLabel;
166
- content.title.caption = this.title.caption;
167
- content.title.className = this.title.className;
168
- content.title.dataset = this.title.dataset;
169
- this._changeGuard = false;
170
- }
171
- /**
172
- * Give focus to the content.
173
- */
174
- _focusContent() {
175
- // Focus the content node if we aren't already focused on it or a
176
- // descendent.
177
- if (!this.content.node.contains(document.activeElement)) {
178
- this.content.node.focus();
179
- }
180
- // Activate the content asynchronously (which may change the focus).
181
- this.content.activate();
182
- }
183
- }
184
- exports.MainAreaWidget = MainAreaWidget;
1
+ "use strict";
2
+ // Copyright (c) Jupyter Development Team.
3
+ // Distributed under the terms of the Modified BSD License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ const coreutils_1 = require("@phosphor/coreutils");
6
+ const widgets_1 = require("@phosphor/widgets");
7
+ const spinner_1 = require("./spinner");
8
+ const toolbar_1 = require("./toolbar");
9
+ /**
10
+ * A widget meant to be contained in the JupyterLab main area.
11
+ *
12
+ * #### Notes
13
+ * Mirrors all of the `title` attributes of the content.
14
+ * This widget is `closable` by default.
15
+ * This widget is automatically disposed when closed.
16
+ * This widget ensures its own focus when activated.
17
+ */
18
+ class MainAreaWidget extends widgets_1.Widget {
19
+ /**
20
+ * Construct a new main area widget.
21
+ *
22
+ * @param options - The options for initializing the widget.
23
+ */
24
+ constructor(options) {
25
+ super(options);
26
+ this._changeGuard = false;
27
+ this._spinner = new spinner_1.Spinner();
28
+ this._isRevealed = false;
29
+ this.addClass('jp-MainAreaWidget');
30
+ this.id = coreutils_1.UUID.uuid4();
31
+ const content = (this._content = options.content);
32
+ const toolbar = (this._toolbar = options.toolbar || new toolbar_1.Toolbar());
33
+ const spinner = this._spinner;
34
+ const layout = (this.layout = new widgets_1.BoxLayout({ spacing: 0 }));
35
+ layout.direction = 'top-to-bottom';
36
+ widgets_1.BoxLayout.setStretch(toolbar, 0);
37
+ widgets_1.BoxLayout.setStretch(content, 1);
38
+ layout.addWidget(toolbar);
39
+ layout.addWidget(content);
40
+ if (!content.id) {
41
+ content.id = coreutils_1.UUID.uuid4();
42
+ }
43
+ content.node.tabIndex = -1;
44
+ this._updateTitle();
45
+ content.title.changed.connect(this._updateTitle, this);
46
+ this.title.closable = true;
47
+ this.title.changed.connect(this._updateContentTitle, this);
48
+ if (options.reveal) {
49
+ this.node.appendChild(spinner.node);
50
+ this._revealed = options.reveal
51
+ .then(() => {
52
+ if (content.isDisposed) {
53
+ this.dispose();
54
+ return;
55
+ }
56
+ content.disposed.connect(() => this.dispose());
57
+ const active = document.activeElement === spinner.node;
58
+ this.node.removeChild(spinner.node);
59
+ spinner.dispose();
60
+ this._isRevealed = true;
61
+ if (active) {
62
+ this._focusContent();
63
+ }
64
+ })
65
+ .catch(e => {
66
+ // Show a revealed promise error.
67
+ const error = new widgets_1.Widget();
68
+ // Show the error to the user.
69
+ const pre = document.createElement('pre');
70
+ pre.textContent = String(e);
71
+ error.node.appendChild(pre);
72
+ widgets_1.BoxLayout.setStretch(error, 1);
73
+ this.node.removeChild(spinner.node);
74
+ spinner.dispose();
75
+ content.dispose();
76
+ this._content = null;
77
+ toolbar.dispose();
78
+ this._toolbar = null;
79
+ layout.addWidget(error);
80
+ this._isRevealed = true;
81
+ throw error;
82
+ });
83
+ }
84
+ else {
85
+ // Handle no reveal promise.
86
+ spinner.dispose();
87
+ content.disposed.connect(() => this.dispose());
88
+ this._isRevealed = true;
89
+ this._revealed = Promise.resolve(undefined);
90
+ }
91
+ }
92
+ /**
93
+ * The content hosted by the widget.
94
+ */
95
+ get content() {
96
+ return this._content;
97
+ }
98
+ /**
99
+ * The toolbar hosted by the widget.
100
+ */
101
+ get toolbar() {
102
+ return this._toolbar;
103
+ }
104
+ /**
105
+ * Whether the content widget or an error is revealed.
106
+ */
107
+ get isRevealed() {
108
+ return this._isRevealed;
109
+ }
110
+ /**
111
+ * A promise that resolves when the widget is revealed.
112
+ */
113
+ get revealed() {
114
+ return this._revealed;
115
+ }
116
+ /**
117
+ * Handle `'activate-request'` messages.
118
+ */
119
+ onActivateRequest(msg) {
120
+ if (this._isRevealed) {
121
+ if (this._content) {
122
+ this._focusContent();
123
+ }
124
+ }
125
+ else {
126
+ this._spinner.node.focus();
127
+ }
128
+ }
129
+ /**
130
+ * Handle `'close-request'` messages.
131
+ */
132
+ onCloseRequest(msg) {
133
+ this.dispose();
134
+ }
135
+ /**
136
+ * Update the title based on the attributes of the child widget.
137
+ */
138
+ _updateTitle() {
139
+ if (this._changeGuard) {
140
+ return;
141
+ }
142
+ this._changeGuard = true;
143
+ const content = this.content;
144
+ this.title.label = content.title.label;
145
+ this.title.mnemonic = content.title.mnemonic;
146
+ this.title.iconClass = content.title.iconClass;
147
+ this.title.iconLabel = content.title.iconLabel;
148
+ this.title.caption = content.title.caption;
149
+ this.title.className = content.title.className;
150
+ this.title.dataset = content.title.dataset;
151
+ this._changeGuard = false;
152
+ }
153
+ /**
154
+ * Update the content title based on attributes of the main widget.
155
+ */
156
+ _updateContentTitle() {
157
+ if (this._changeGuard) {
158
+ return;
159
+ }
160
+ this._changeGuard = true;
161
+ const content = this.content;
162
+ content.title.label = this.title.label;
163
+ content.title.mnemonic = this.title.mnemonic;
164
+ content.title.iconClass = this.title.iconClass;
165
+ content.title.iconLabel = this.title.iconLabel;
166
+ content.title.caption = this.title.caption;
167
+ content.title.className = this.title.className;
168
+ content.title.dataset = this.title.dataset;
169
+ this._changeGuard = false;
170
+ }
171
+ /**
172
+ * Give focus to the content.
173
+ */
174
+ _focusContent() {
175
+ // Focus the content node if we aren't already focused on it or a
176
+ // descendent.
177
+ if (!this.content.node.contains(document.activeElement)) {
178
+ this.content.node.focus();
179
+ }
180
+ // Activate the content asynchronously (which may change the focus).
181
+ this.content.activate();
182
+ }
183
+ }
184
+ exports.MainAreaWidget = MainAreaWidget;
@@ -1,44 +1,44 @@
1
- export interface ISanitizer {
2
- /**
3
- * Sanitize an HTML string.
4
- *
5
- * @param dirty - The dirty text.
6
- *
7
- * @param options - The optional sanitization options.
8
- *
9
- * @returns The sanitized string.
10
- */
11
- sanitize(dirty: string, options?: ISanitizer.IOptions): string;
12
- }
13
- /**
14
- * The namespace for `ISanitizer` related interfaces.
15
- */
16
- export declare namespace ISanitizer {
17
- /**
18
- * The options used to sanitize.
19
- */
20
- interface IOptions {
21
- /**
22
- * The allowed tags.
23
- */
24
- allowedTags?: string[];
25
- /**
26
- * The allowed attributes for a given tag.
27
- */
28
- allowedAttributes?: {
29
- [key: string]: string[];
30
- };
31
- /**
32
- * The allowed style values for a given tag.
33
- */
34
- allowedStyles?: {
35
- [key: string]: {
36
- [key: string]: RegExp[];
37
- };
38
- };
39
- }
40
- }
41
- /**
42
- * The default instance of an `ISanitizer` meant for use by user code.
43
- */
44
- export declare const defaultSanitizer: ISanitizer;
1
+ export interface ISanitizer {
2
+ /**
3
+ * Sanitize an HTML string.
4
+ *
5
+ * @param dirty - The dirty text.
6
+ *
7
+ * @param options - The optional sanitization options.
8
+ *
9
+ * @returns The sanitized string.
10
+ */
11
+ sanitize(dirty: string, options?: ISanitizer.IOptions): string;
12
+ }
13
+ /**
14
+ * The namespace for `ISanitizer` related interfaces.
15
+ */
16
+ export declare namespace ISanitizer {
17
+ /**
18
+ * The options used to sanitize.
19
+ */
20
+ interface IOptions {
21
+ /**
22
+ * The allowed tags.
23
+ */
24
+ allowedTags?: string[];
25
+ /**
26
+ * The allowed attributes for a given tag.
27
+ */
28
+ allowedAttributes?: {
29
+ [key: string]: string[];
30
+ };
31
+ /**
32
+ * The allowed style values for a given tag.
33
+ */
34
+ allowedStyles?: {
35
+ [key: string]: {
36
+ [key: string]: RegExp[];
37
+ };
38
+ };
39
+ }
40
+ }
41
+ /**
42
+ * The default instance of an `ISanitizer` meant for use by user code.
43
+ */
44
+ export declare const defaultSanitizer: ISanitizer;