@jupyterlab/tooltip 4.0.0-alpha.2 → 4.0.0-alpha.20
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/lib/tokens.d.ts +1 -1
- package/lib/tokens.js +0 -1
- package/lib/tokens.js.map +1 -1
- package/lib/widget.js +8 -2
- package/lib/widget.js.map +1 -1
- package/package.json +12 -11
- package/src/index.ts +9 -0
- package/src/tokens.ts +55 -0
- package/src/widget.ts +289 -0
- package/style/index.css +1 -1
- package/style/index.js +1 -1
package/lib/tokens.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface ITooltipManager {
|
|
|
17
17
|
invoke(options: ITooltipManager.IOptions): void;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
* A namespace for `
|
|
20
|
+
* A namespace for `ITooltipManager` interface specifications.
|
|
21
21
|
*/
|
|
22
22
|
export declare namespace ITooltipManager {
|
|
23
23
|
/**
|
package/lib/tokens.js
CHANGED
package/lib/tokens.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAK3D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG1C
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAK3D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG1C;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,KAAK,CACtC,qCAAqC,CACtC,CAAC"}
|
package/lib/widget.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright (c) Jupyter Development Team.
|
|
2
2
|
// Distributed under the terms of the Modified BSD License.
|
|
3
|
-
import { HoverBox } from '@jupyterlab/
|
|
3
|
+
import { HoverBox } from '@jupyterlab/ui-components';
|
|
4
4
|
import { MimeModel } from '@jupyterlab/rendermime';
|
|
5
5
|
import { PanelLayout, Widget } from '@lumino/widgets';
|
|
6
6
|
/**
|
|
@@ -181,15 +181,21 @@ export class Tooltip extends Widget {
|
|
|
181
181
|
const anchor = editor.getCoordinateForPosition(position);
|
|
182
182
|
const style = window.getComputedStyle(this.node);
|
|
183
183
|
const paddingLeft = parseInt(style.paddingLeft, 10) || 0;
|
|
184
|
+
const host = editor.host.closest('.jp-MainAreaWidget > .lm-Widget') ||
|
|
185
|
+
editor.host;
|
|
184
186
|
// Calculate the geometry of the tooltip.
|
|
185
187
|
HoverBox.setGeometry({
|
|
186
188
|
anchor,
|
|
187
|
-
host
|
|
189
|
+
host,
|
|
188
190
|
maxHeight: MAX_HEIGHT,
|
|
189
191
|
minHeight: MIN_HEIGHT,
|
|
190
192
|
node: this.node,
|
|
191
193
|
offset: { horizontal: -1 * paddingLeft },
|
|
192
194
|
privilege: 'below',
|
|
195
|
+
outOfViewDisplay: {
|
|
196
|
+
top: 'stick-inside',
|
|
197
|
+
bottom: 'stick-inside'
|
|
198
|
+
},
|
|
193
199
|
style: style
|
|
194
200
|
});
|
|
195
201
|
}
|
package/lib/widget.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget.js","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"widget.js","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,2DAA2D;AAE3D,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD,OAAO,EAGL,SAAS,EACV,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;GAEG;AACH,M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AAC,WAAY,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;QAE1D,MAAM,IAAI,GACP,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,iCAAiC,CAAiB;YACvE,MAAM,CAAC,IAAI,CAAC;QAEd,yCAAyC;QACzC,QAAQ,CAAC,WAAW,CAAC;YACnB,MAAM;YACN,IAAI;YACJ,SAAS,EAAE,UAAU;YACrB,SAAS,EAAE,UAAU;YACrB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,GAAG,WAAW,EAAE;YACxC,SAAS,EAAE,OAAO;YAClB,gBAAgB,EAAE;gBAChB,GAAG,EAAE,cAAc;gBACnB,MAAM,EAAE,cAAc;aACvB;YACD,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;CAMF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyterlab/tooltip",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.20",
|
|
4
4
|
"description": "JupyterLab - Tooltip Widget",
|
|
5
5
|
"homepage": "https://github.com/jupyterlab/jupyterlab",
|
|
6
6
|
"bugs": {
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"lib/*.js.map",
|
|
28
28
|
"lib/*.js",
|
|
29
29
|
"style/*.css",
|
|
30
|
-
"style/index.js"
|
|
30
|
+
"style/index.js",
|
|
31
|
+
"src/**/*.{ts,tsx}"
|
|
31
32
|
],
|
|
32
33
|
"scripts": {
|
|
33
34
|
"build": "tsc -b",
|
|
@@ -36,18 +37,18 @@
|
|
|
36
37
|
"watch": "tsc -b --watch"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"@jupyterlab/
|
|
40
|
-
"@jupyterlab/
|
|
41
|
-
"@jupyterlab/
|
|
42
|
-
"@jupyterlab/
|
|
43
|
-
"@lumino/coreutils": "^
|
|
44
|
-
"@lumino/messaging": "^
|
|
45
|
-
"@lumino/widgets": "^
|
|
40
|
+
"@jupyterlab/codeeditor": "^4.0.0-alpha.20",
|
|
41
|
+
"@jupyterlab/rendermime": "^4.0.0-alpha.20",
|
|
42
|
+
"@jupyterlab/services": "^7.0.0-alpha.20",
|
|
43
|
+
"@jupyterlab/ui-components": "^4.0.0-alpha.35",
|
|
44
|
+
"@lumino/coreutils": "^2.0.0-rc.0",
|
|
45
|
+
"@lumino/messaging": "^2.0.0-rc.0",
|
|
46
|
+
"@lumino/widgets": "^2.0.0-rc.0"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"rimraf": "~3.0.0",
|
|
49
|
-
"typedoc": "~0.
|
|
50
|
-
"typescript": "~
|
|
50
|
+
"typedoc": "~0.23.25",
|
|
51
|
+
"typescript": "~5.0.0-beta"
|
|
51
52
|
},
|
|
52
53
|
"publishConfig": {
|
|
53
54
|
"access": "public"
|
package/src/index.ts
ADDED
package/src/tokens.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { CodeEditor } from '@jupyterlab/codeeditor';
|
|
5
|
+
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
|
6
|
+
import { Kernel } from '@jupyterlab/services';
|
|
7
|
+
import { Token } from '@lumino/coreutils';
|
|
8
|
+
import { Widget } from '@lumino/widgets';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The tooltip manager token.
|
|
12
|
+
*/
|
|
13
|
+
export const ITooltipManager = new Token<ITooltipManager>(
|
|
14
|
+
'@jupyterlab/tooltip:ITooltipManager'
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A manager to register tooltips with parent widgets.
|
|
19
|
+
*/
|
|
20
|
+
export interface ITooltipManager {
|
|
21
|
+
/**
|
|
22
|
+
* Invoke a tooltip.
|
|
23
|
+
*/
|
|
24
|
+
invoke(options: ITooltipManager.IOptions): void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A namespace for `ITooltipManager` interface specifications.
|
|
29
|
+
*/
|
|
30
|
+
export namespace ITooltipManager {
|
|
31
|
+
/**
|
|
32
|
+
* An interface for tooltip-compatible objects.
|
|
33
|
+
*/
|
|
34
|
+
export interface IOptions {
|
|
35
|
+
/**
|
|
36
|
+
* The referent anchor the tooltip follows.
|
|
37
|
+
*/
|
|
38
|
+
readonly anchor: Widget;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The referent editor for the tooltip.
|
|
42
|
+
*/
|
|
43
|
+
readonly editor: CodeEditor.IEditor;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The kernel the tooltip communicates with to populate itself.
|
|
47
|
+
*/
|
|
48
|
+
readonly kernel: Kernel.IKernelConnection;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The renderer the tooltip uses to render API responses.
|
|
52
|
+
*/
|
|
53
|
+
readonly rendermime: IRenderMimeRegistry;
|
|
54
|
+
}
|
|
55
|
+
}
|
package/src/widget.ts
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { HoverBox } from '@jupyterlab/ui-components';
|
|
5
|
+
import { CodeEditor } from '@jupyterlab/codeeditor';
|
|
6
|
+
import {
|
|
7
|
+
IRenderMime,
|
|
8
|
+
IRenderMimeRegistry,
|
|
9
|
+
MimeModel
|
|
10
|
+
} from '@jupyterlab/rendermime';
|
|
11
|
+
import { JSONObject } from '@lumino/coreutils';
|
|
12
|
+
import { Message } from '@lumino/messaging';
|
|
13
|
+
import { PanelLayout, Widget } from '@lumino/widgets';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The class name added to each tooltip.
|
|
17
|
+
*/
|
|
18
|
+
const TOOLTIP_CLASS = 'jp-Tooltip';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The class name added to the tooltip content.
|
|
22
|
+
*/
|
|
23
|
+
const CONTENT_CLASS = 'jp-Tooltip-content';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The class added to the body when a tooltip exists on the page.
|
|
27
|
+
*/
|
|
28
|
+
const BODY_CLASS = 'jp-mod-tooltip';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The minimum height of a tooltip widget.
|
|
32
|
+
*/
|
|
33
|
+
const MIN_HEIGHT = 20;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The maximum height of a tooltip widget.
|
|
37
|
+
*/
|
|
38
|
+
const MAX_HEIGHT = 250;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A flag to indicate that event handlers are caught in the capture phase.
|
|
42
|
+
*/
|
|
43
|
+
const USE_CAPTURE = true;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A tooltip widget.
|
|
47
|
+
*/
|
|
48
|
+
export class Tooltip extends Widget {
|
|
49
|
+
/**
|
|
50
|
+
* Instantiate a tooltip.
|
|
51
|
+
*/
|
|
52
|
+
constructor(options: Tooltip.IOptions) {
|
|
53
|
+
super();
|
|
54
|
+
|
|
55
|
+
const layout = (this.layout = new PanelLayout());
|
|
56
|
+
const model = new MimeModel({ data: options.bundle });
|
|
57
|
+
|
|
58
|
+
this.anchor = options.anchor;
|
|
59
|
+
this.addClass(TOOLTIP_CLASS);
|
|
60
|
+
this.hide();
|
|
61
|
+
this._editor = options.editor;
|
|
62
|
+
this._position = options.position;
|
|
63
|
+
this._rendermime = options.rendermime;
|
|
64
|
+
|
|
65
|
+
const mimeType = this._rendermime.preferredMimeType(options.bundle, 'any');
|
|
66
|
+
|
|
67
|
+
if (!mimeType) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
this._content = this._rendermime.createRenderer(mimeType);
|
|
72
|
+
this._content
|
|
73
|
+
.renderModel(model)
|
|
74
|
+
.then(() => this._setGeometry())
|
|
75
|
+
.catch(error => console.error('tooltip rendering failed', error));
|
|
76
|
+
this._content.addClass(CONTENT_CLASS);
|
|
77
|
+
layout.addWidget(this._content);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The anchor widget that the tooltip widget tracks.
|
|
82
|
+
*/
|
|
83
|
+
readonly anchor: Widget;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Dispose of the resources held by the widget.
|
|
87
|
+
*/
|
|
88
|
+
dispose(): void {
|
|
89
|
+
if (this._content) {
|
|
90
|
+
this._content.dispose();
|
|
91
|
+
this._content = null;
|
|
92
|
+
}
|
|
93
|
+
super.dispose();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Handle the DOM events for the widget.
|
|
98
|
+
*
|
|
99
|
+
* @param event - The DOM event sent to the widget.
|
|
100
|
+
*
|
|
101
|
+
* #### Notes
|
|
102
|
+
* This method implements the DOM `EventListener` interface and is
|
|
103
|
+
* called in response to events on the dock panel's node. It should
|
|
104
|
+
* not be called directly by user code.
|
|
105
|
+
*/
|
|
106
|
+
handleEvent(event: Event): void {
|
|
107
|
+
if (this.isHidden || this.isDisposed) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const { node } = this;
|
|
112
|
+
const target = event.target as HTMLElement;
|
|
113
|
+
|
|
114
|
+
switch (event.type) {
|
|
115
|
+
case 'keydown':
|
|
116
|
+
if (node.contains(target)) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
this.dispose();
|
|
120
|
+
break;
|
|
121
|
+
case 'mousedown':
|
|
122
|
+
if (node.contains(target)) {
|
|
123
|
+
this.activate();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
this.dispose();
|
|
127
|
+
break;
|
|
128
|
+
case 'scroll':
|
|
129
|
+
this._evtScroll(event as MouseEvent);
|
|
130
|
+
break;
|
|
131
|
+
default:
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Handle `'activate-request'` messages.
|
|
138
|
+
*/
|
|
139
|
+
protected onActivateRequest(msg: Message): void {
|
|
140
|
+
this.node.tabIndex = 0;
|
|
141
|
+
this.node.focus();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Handle `'after-attach'` messages.
|
|
146
|
+
*/
|
|
147
|
+
protected onAfterAttach(msg: Message): void {
|
|
148
|
+
document.body.classList.add(BODY_CLASS);
|
|
149
|
+
document.addEventListener('keydown', this, USE_CAPTURE);
|
|
150
|
+
document.addEventListener('mousedown', this, USE_CAPTURE);
|
|
151
|
+
this.anchor.node.addEventListener('scroll', this, USE_CAPTURE);
|
|
152
|
+
this.update();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Handle `before-detach` messages for the widget.
|
|
157
|
+
*/
|
|
158
|
+
protected onBeforeDetach(msg: Message): void {
|
|
159
|
+
document.body.classList.remove(BODY_CLASS);
|
|
160
|
+
document.removeEventListener('keydown', this, USE_CAPTURE);
|
|
161
|
+
document.removeEventListener('mousedown', this, USE_CAPTURE);
|
|
162
|
+
this.anchor.node.removeEventListener('scroll', this, USE_CAPTURE);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Handle `'update-request'` messages.
|
|
167
|
+
*/
|
|
168
|
+
protected onUpdateRequest(msg: Message): void {
|
|
169
|
+
if (this.isHidden) {
|
|
170
|
+
this.show();
|
|
171
|
+
}
|
|
172
|
+
this._setGeometry();
|
|
173
|
+
super.onUpdateRequest(msg);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Handle scroll events for the widget
|
|
178
|
+
*/
|
|
179
|
+
private _evtScroll(event: MouseEvent) {
|
|
180
|
+
// All scrolls except scrolls in the actual hover box node may cause the
|
|
181
|
+
// referent editor that anchors the node to move, so the only scroll events
|
|
182
|
+
// that can safely be ignored are ones that happen inside the hovering node.
|
|
183
|
+
if (this.node.contains(event.target as HTMLElement)) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
this.update();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Find the position of the first character of the current token.
|
|
192
|
+
*/
|
|
193
|
+
private _getTokenPosition(): CodeEditor.IPosition | undefined {
|
|
194
|
+
const editor = this._editor;
|
|
195
|
+
const cursor = editor.getCursorPosition();
|
|
196
|
+
const end = editor.getOffsetAt(cursor);
|
|
197
|
+
const line = editor.getLine(cursor.line);
|
|
198
|
+
|
|
199
|
+
if (!line) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const tokens = line.substring(0, end).split(/\W+/);
|
|
204
|
+
const last = tokens[tokens.length - 1];
|
|
205
|
+
const start = last ? end - last.length : end;
|
|
206
|
+
return editor.getPositionAt(start);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Set the geometry of the tooltip widget.
|
|
211
|
+
*/
|
|
212
|
+
private _setGeometry(): void {
|
|
213
|
+
// determine position for hover box placement
|
|
214
|
+
const position = this._position ? this._position : this._getTokenPosition();
|
|
215
|
+
|
|
216
|
+
if (!position) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const editor = this._editor;
|
|
221
|
+
|
|
222
|
+
const anchor = editor.getCoordinateForPosition(position);
|
|
223
|
+
const style = window.getComputedStyle(this.node);
|
|
224
|
+
const paddingLeft = parseInt(style.paddingLeft!, 10) || 0;
|
|
225
|
+
|
|
226
|
+
const host =
|
|
227
|
+
(editor.host.closest('.jp-MainAreaWidget > .lm-Widget') as HTMLElement) ||
|
|
228
|
+
editor.host;
|
|
229
|
+
|
|
230
|
+
// Calculate the geometry of the tooltip.
|
|
231
|
+
HoverBox.setGeometry({
|
|
232
|
+
anchor,
|
|
233
|
+
host,
|
|
234
|
+
maxHeight: MAX_HEIGHT,
|
|
235
|
+
minHeight: MIN_HEIGHT,
|
|
236
|
+
node: this.node,
|
|
237
|
+
offset: { horizontal: -1 * paddingLeft },
|
|
238
|
+
privilege: 'below',
|
|
239
|
+
outOfViewDisplay: {
|
|
240
|
+
top: 'stick-inside',
|
|
241
|
+
bottom: 'stick-inside'
|
|
242
|
+
},
|
|
243
|
+
style: style
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
private _content: IRenderMime.IRenderer | null = null;
|
|
248
|
+
private _editor: CodeEditor.IEditor;
|
|
249
|
+
private _position: CodeEditor.IPosition | undefined;
|
|
250
|
+
private _rendermime: IRenderMimeRegistry;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* A namespace for tooltip widget statics.
|
|
255
|
+
*/
|
|
256
|
+
export namespace Tooltip {
|
|
257
|
+
/**
|
|
258
|
+
* Instantiation options for a tooltip widget.
|
|
259
|
+
*/
|
|
260
|
+
export interface IOptions {
|
|
261
|
+
/**
|
|
262
|
+
* The anchor widget that the tooltip widget tracks.
|
|
263
|
+
*/
|
|
264
|
+
anchor: Widget;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* The data that populates the tooltip widget.
|
|
268
|
+
*/
|
|
269
|
+
bundle: JSONObject;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* The editor referent of the tooltip model.
|
|
273
|
+
*/
|
|
274
|
+
editor: CodeEditor.IEditor;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* The rendermime instance used by the tooltip model.
|
|
278
|
+
*/
|
|
279
|
+
rendermime: IRenderMimeRegistry;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Position at which the tooltip should be placed.
|
|
283
|
+
*
|
|
284
|
+
* If not given, the position of the first character
|
|
285
|
+
* in the current token will be used.
|
|
286
|
+
*/
|
|
287
|
+
position?: CodeEditor.IPosition;
|
|
288
|
+
}
|
|
289
|
+
}
|
package/style/index.css
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
/* This file was auto-generated by ensurePackage() in @jupyterlab/buildutils */
|
|
7
7
|
@import url('~@lumino/widgets/style/index.css');
|
|
8
|
-
@import url('~@jupyterlab/
|
|
8
|
+
@import url('~@jupyterlab/ui-components/style/index.css');
|
|
9
9
|
@import url('~@jupyterlab/codeeditor/style/index.css');
|
|
10
10
|
@import url('~@jupyterlab/rendermime/style/index.css');
|
|
11
11
|
|
package/style/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
/* This file was auto-generated by ensurePackage() in @jupyterlab/buildutils */
|
|
7
7
|
import '@lumino/widgets/style/index.js';
|
|
8
|
-
import '@jupyterlab/
|
|
8
|
+
import '@jupyterlab/ui-components/style/index.js';
|
|
9
9
|
import '@jupyterlab/codeeditor/style/index.js';
|
|
10
10
|
import '@jupyterlab/rendermime/style/index.js';
|
|
11
11
|
|