jupyterlab-pioneer 0.1.4 → 0.1.6
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/index.d.ts +10 -4
- package/lib/index.js +25 -5
- package/lib/producer.d.ts +3 -3
- package/lib/producer.js +36 -32
- package/lib/router.d.ts +2 -9
- package/lib/router.js +8 -20
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { JupyterFrontEndPlugin } from '@jupyterlab/application';
|
|
2
|
+
import { NotebookPanel } from '@jupyterlab/notebook';
|
|
2
3
|
import { Token } from '@lumino/coreutils';
|
|
3
|
-
import { Router } from './router';
|
|
4
4
|
export declare const IJupyterLabPioneer: Token<IJupyterLabPioneer>;
|
|
5
5
|
export interface IJupyterLabPioneer {
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Send event data to exporters defined in the configuration file.
|
|
8
|
+
*
|
|
9
|
+
* @param {NotebookPanel} notebookPanel The notebook panel the extension currently listens to.
|
|
10
|
+
* @param {Object} eventDetail An object containing event details
|
|
11
|
+
* @param {Boolean} logNotebookContent A boolean indicating whether to log the entire notebook or not
|
|
12
|
+
*/
|
|
13
|
+
publishEvent(notebookPanel: NotebookPanel, eventDetail: Object, logNotebookContent?: Boolean): Promise<void>;
|
|
7
14
|
}
|
|
8
15
|
declare class JupyterLabPioneer implements IJupyterLabPioneer {
|
|
9
|
-
|
|
10
|
-
constructor();
|
|
16
|
+
publishEvent(notebookPanel: NotebookPanel, eventDetail: Object, logNotebookContent?: Boolean): Promise<void>;
|
|
11
17
|
}
|
|
12
18
|
declare const plugin: JupyterFrontEndPlugin<JupyterLabPioneer>;
|
|
13
19
|
export default plugin;
|
package/lib/index.js
CHANGED
|
@@ -1,13 +1,33 @@
|
|
|
1
1
|
import { INotebookTracker } from '@jupyterlab/notebook';
|
|
2
2
|
import { Token } from '@lumino/coreutils';
|
|
3
3
|
import { requestAPI } from './handler';
|
|
4
|
-
import { Router } from './router';
|
|
4
|
+
// import { Router } from './router';
|
|
5
5
|
import { producerCollection } from './producer';
|
|
6
6
|
const PLUGIN_ID = 'jupyterlab-pioneer:plugin';
|
|
7
7
|
export const IJupyterLabPioneer = new Token(PLUGIN_ID);
|
|
8
8
|
class JupyterLabPioneer {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
async publishEvent(notebookPanel, eventDetail, logNotebookContent) {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
if (!notebookPanel) {
|
|
12
|
+
throw Error('router is listening to a null notebook panel');
|
|
13
|
+
}
|
|
14
|
+
// Construct data
|
|
15
|
+
const requestBody = {
|
|
16
|
+
eventDetail: eventDetail,
|
|
17
|
+
notebookState: {
|
|
18
|
+
sessionID: (_a = notebookPanel === null || notebookPanel === void 0 ? void 0 : notebookPanel.sessionContext.session) === null || _a === void 0 ? void 0 : _a.id,
|
|
19
|
+
notebookPath: notebookPanel === null || notebookPanel === void 0 ? void 0 : notebookPanel.context.path,
|
|
20
|
+
notebookContent: logNotebookContent
|
|
21
|
+
? (_b = notebookPanel === null || notebookPanel === void 0 ? void 0 : notebookPanel.model) === null || _b === void 0 ? void 0 : _b.toJSON()
|
|
22
|
+
: null // decide whether to log the entire notebook
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
// Send data to exporters
|
|
26
|
+
const response = await requestAPI('export', {
|
|
27
|
+
method: 'POST',
|
|
28
|
+
body: JSON.stringify(requestBody)
|
|
29
|
+
});
|
|
30
|
+
console.log(response);
|
|
11
31
|
}
|
|
12
32
|
}
|
|
13
33
|
const plugin = {
|
|
@@ -21,8 +41,8 @@ const plugin = {
|
|
|
21
41
|
const config = await requestAPI('config');
|
|
22
42
|
const pioneer = new JupyterLabPioneer();
|
|
23
43
|
notebookTracker.widgetAdded.connect(async (_, notebookPanel) => {
|
|
24
|
-
await notebookPanel.
|
|
25
|
-
await
|
|
44
|
+
await notebookPanel.revealed;
|
|
45
|
+
await notebookPanel.sessionContext.ready;
|
|
26
46
|
producerCollection.forEach(producer => {
|
|
27
47
|
if (config.activeEvents.includes(producer.id)) {
|
|
28
48
|
new producer().listen(notebookPanel, pioneer, config.logNotebookContentEvents.includes(producer.id));
|
package/lib/producer.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { IJupyterLabPioneer } from './index';
|
|
|
3
3
|
export declare class NotebookOpenEventProducer {
|
|
4
4
|
static id: string;
|
|
5
5
|
private produced;
|
|
6
|
-
listen(
|
|
6
|
+
listen(notebookPanel: NotebookPanel, pioneer: IJupyterLabPioneer, logNotebookContentEvent: boolean): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
export declare class NotebookScrollProducer {
|
|
9
9
|
static id: string;
|
|
@@ -16,7 +16,7 @@ export declare class NotebookVisibleEventProducer {
|
|
|
16
16
|
}
|
|
17
17
|
export declare class NotebookHiddenEventProducer {
|
|
18
18
|
static id: string;
|
|
19
|
-
listen(
|
|
19
|
+
listen(notebookPanel: NotebookPanel, pioneer: IJupyterLabPioneer, logNotebookContentEvent: boolean): void;
|
|
20
20
|
}
|
|
21
21
|
export declare class ClipboardCopyEventProducer {
|
|
22
22
|
static id: string;
|
|
@@ -40,7 +40,7 @@ export declare class NotebookSaveEventProducer {
|
|
|
40
40
|
}
|
|
41
41
|
export declare class CellExecuteEventProducer {
|
|
42
42
|
static id: string;
|
|
43
|
-
listen(
|
|
43
|
+
listen(notebookPanel: NotebookPanel, pioneer: IJupyterLabPioneer, logNotebookContentEvent: boolean): void;
|
|
44
44
|
}
|
|
45
45
|
export declare class CellAddEventProducer {
|
|
46
46
|
static id: string;
|
package/lib/producer.js
CHANGED
|
@@ -4,7 +4,7 @@ class NotebookOpenEventProducer {
|
|
|
4
4
|
constructor() {
|
|
5
5
|
this.produced = false;
|
|
6
6
|
}
|
|
7
|
-
async listen(
|
|
7
|
+
async listen(notebookPanel, pioneer, logNotebookContentEvent) {
|
|
8
8
|
if (!this.produced) {
|
|
9
9
|
const event = {
|
|
10
10
|
eventName: NotebookOpenEventProducer.id,
|
|
@@ -13,7 +13,7 @@ class NotebookOpenEventProducer {
|
|
|
13
13
|
environ: await requestAPI('environ')
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
-
await pioneer.
|
|
16
|
+
await pioneer.publishEvent(notebookPanel, event, logNotebookContentEvent);
|
|
17
17
|
this.produced = true;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -54,7 +54,7 @@ class NotebookScrollProducer {
|
|
|
54
54
|
cells: getVisibleCells(notebookPanel)
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
|
-
await pioneer.
|
|
57
|
+
await pioneer.publishEvent(notebookPanel, event, logNotebookContentEvent);
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -63,7 +63,7 @@ export { NotebookScrollProducer };
|
|
|
63
63
|
class NotebookVisibleEventProducer {
|
|
64
64
|
listen(notebookPanel, pioneer, logNotebookContentEvent) {
|
|
65
65
|
document.addEventListener('visibilitychange', async () => {
|
|
66
|
-
if (document.visibilityState === 'visible') {
|
|
66
|
+
if (document.visibilityState === 'visible' && document.contains(notebookPanel.node)) {
|
|
67
67
|
const event = {
|
|
68
68
|
eventName: NotebookVisibleEventProducer.id,
|
|
69
69
|
eventTime: Date.now(),
|
|
@@ -71,7 +71,7 @@ class NotebookVisibleEventProducer {
|
|
|
71
71
|
cells: getVisibleCells(notebookPanel)
|
|
72
72
|
}
|
|
73
73
|
};
|
|
74
|
-
await pioneer.
|
|
74
|
+
await pioneer.publishEvent(notebookPanel, event, logNotebookContentEvent);
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
77
|
}
|
|
@@ -79,14 +79,15 @@ class NotebookVisibleEventProducer {
|
|
|
79
79
|
NotebookVisibleEventProducer.id = 'NotebookVisibleEvent';
|
|
80
80
|
export { NotebookVisibleEventProducer };
|
|
81
81
|
class NotebookHiddenEventProducer {
|
|
82
|
-
listen(
|
|
82
|
+
listen(notebookPanel, pioneer, logNotebookContentEvent) {
|
|
83
83
|
document.addEventListener('visibilitychange', async (e) => {
|
|
84
|
-
if (document.visibilityState === 'hidden') {
|
|
84
|
+
if (document.visibilityState === 'hidden' && document.contains(notebookPanel.node)) {
|
|
85
85
|
const event = {
|
|
86
86
|
eventName: NotebookHiddenEventProducer.id,
|
|
87
|
-
eventTime: Date.now()
|
|
87
|
+
eventTime: Date.now(),
|
|
88
|
+
eventInfo: null
|
|
88
89
|
};
|
|
89
|
-
await pioneer.
|
|
90
|
+
await pioneer.publishEvent(notebookPanel, event, logNotebookContentEvent);
|
|
90
91
|
}
|
|
91
92
|
});
|
|
92
93
|
}
|
|
@@ -110,7 +111,7 @@ class ClipboardCopyEventProducer {
|
|
|
110
111
|
selection: text
|
|
111
112
|
}
|
|
112
113
|
};
|
|
113
|
-
await pioneer.
|
|
114
|
+
await pioneer.publishEvent(notebookPanel, event, logNotebookContentEvent);
|
|
114
115
|
});
|
|
115
116
|
}
|
|
116
117
|
}
|
|
@@ -133,7 +134,7 @@ class ClipboardCutEventProducer {
|
|
|
133
134
|
selection: text
|
|
134
135
|
}
|
|
135
136
|
};
|
|
136
|
-
await pioneer.
|
|
137
|
+
await pioneer.publishEvent(notebookPanel, event, logNotebookContentEvent);
|
|
137
138
|
});
|
|
138
139
|
}
|
|
139
140
|
}
|
|
@@ -156,7 +157,7 @@ class ClipboardPasteEventProducer {
|
|
|
156
157
|
selection: text
|
|
157
158
|
}
|
|
158
159
|
};
|
|
159
|
-
await pioneer.
|
|
160
|
+
await pioneer.publishEvent(notebookPanel, event, logNotebookContentEvent);
|
|
160
161
|
});
|
|
161
162
|
}
|
|
162
163
|
}
|
|
@@ -177,7 +178,7 @@ class ActiveCellChangeEventProducer {
|
|
|
177
178
|
cells: [activatedCell] // activated cell
|
|
178
179
|
}
|
|
179
180
|
};
|
|
180
|
-
await pioneer.
|
|
181
|
+
await pioneer.publishEvent(notebookPanel, event, logNotebookContentEvent);
|
|
181
182
|
}
|
|
182
183
|
});
|
|
183
184
|
}
|
|
@@ -190,9 +191,10 @@ class NotebookSaveEventProducer {
|
|
|
190
191
|
if (saveState.match('completed')) {
|
|
191
192
|
const event = {
|
|
192
193
|
eventName: NotebookSaveEventProducer.id,
|
|
193
|
-
eventTime: Date.now()
|
|
194
|
+
eventTime: Date.now(),
|
|
195
|
+
eventInfo: null
|
|
194
196
|
};
|
|
195
|
-
await pioneer.
|
|
197
|
+
await pioneer.publishEvent(notebookPanel, event, logNotebookContentEvent);
|
|
196
198
|
}
|
|
197
199
|
});
|
|
198
200
|
}
|
|
@@ -200,22 +202,24 @@ class NotebookSaveEventProducer {
|
|
|
200
202
|
NotebookSaveEventProducer.id = 'NotebookSaveEvent';
|
|
201
203
|
export { NotebookSaveEventProducer };
|
|
202
204
|
class CellExecuteEventProducer {
|
|
203
|
-
listen(
|
|
205
|
+
listen(notebookPanel, pioneer, logNotebookContentEvent) {
|
|
204
206
|
NotebookActions.executed.connect(async (_, args) => {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
207
|
+
if (notebookPanel.content === args.notebook) {
|
|
208
|
+
const executedCell = {
|
|
209
|
+
id: args.cell.model.id,
|
|
210
|
+
index: args.notebook.widgets.findIndex(value => value == args.cell)
|
|
211
|
+
};
|
|
212
|
+
const event = {
|
|
213
|
+
eventName: CellExecuteEventProducer.id,
|
|
214
|
+
eventTime: Date.now(),
|
|
215
|
+
eventInfo: {
|
|
216
|
+
cells: [executedCell],
|
|
217
|
+
success: args.success,
|
|
218
|
+
kernelError: args.success ? null : args.error
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
await pioneer.publishEvent(notebookPanel, event, logNotebookContentEvent);
|
|
222
|
+
}
|
|
219
223
|
});
|
|
220
224
|
}
|
|
221
225
|
}
|
|
@@ -237,7 +241,7 @@ class CellAddEventProducer {
|
|
|
237
241
|
cells: [addedCell]
|
|
238
242
|
}
|
|
239
243
|
};
|
|
240
|
-
await pioneer.
|
|
244
|
+
await pioneer.publishEvent(notebookPanel, event, logNotebookContentEvent);
|
|
241
245
|
}
|
|
242
246
|
});
|
|
243
247
|
}
|
|
@@ -260,7 +264,7 @@ class CellRemoveEventProducer {
|
|
|
260
264
|
cells: [removedCell]
|
|
261
265
|
}
|
|
262
266
|
};
|
|
263
|
-
await pioneer.
|
|
267
|
+
await pioneer.publishEvent(notebookPanel, event, logNotebookContentEvent);
|
|
264
268
|
}
|
|
265
269
|
});
|
|
266
270
|
}
|
package/lib/router.d.ts
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import { NotebookPanel } from '@jupyterlab/notebook';
|
|
2
2
|
export declare class Router {
|
|
3
|
-
private sessionID?;
|
|
4
|
-
private notebookPanel?;
|
|
5
|
-
/**
|
|
6
|
-
* Load notebookPanel.
|
|
7
|
-
*
|
|
8
|
-
* @param {NotebookPanel} notebookPanel
|
|
9
|
-
*/
|
|
10
|
-
loadNotebookPanel(notebookPanel: NotebookPanel): Promise<void>;
|
|
11
3
|
/**
|
|
12
4
|
* Send event data to exporters defined in the configuration file.
|
|
13
5
|
*
|
|
6
|
+
* @param {NotebookPanel} notebookPanel The notebook panel the extension currently listens to.
|
|
14
7
|
* @param {Object} eventDetail An object containing event details
|
|
15
8
|
* @param {Boolean} logNotebookContent A boolean indicating whether to log the entire notebook or not
|
|
16
9
|
*/
|
|
17
|
-
publishEvent(eventDetail: Object, logNotebookContent?: Boolean): Promise<void>;
|
|
10
|
+
publishEvent(notebookPanel: NotebookPanel, eventDetail: Object, logNotebookContent?: Boolean): Promise<void>;
|
|
18
11
|
}
|
package/lib/router.js
CHANGED
|
@@ -1,37 +1,25 @@
|
|
|
1
1
|
import { requestAPI } from './handler';
|
|
2
2
|
export class Router {
|
|
3
|
-
/**
|
|
4
|
-
* Load notebookPanel.
|
|
5
|
-
*
|
|
6
|
-
* @param {NotebookPanel} notebookPanel
|
|
7
|
-
*/
|
|
8
|
-
async loadNotebookPanel(notebookPanel) {
|
|
9
|
-
this.notebookPanel = notebookPanel;
|
|
10
|
-
}
|
|
11
3
|
/**
|
|
12
4
|
* Send event data to exporters defined in the configuration file.
|
|
13
5
|
*
|
|
6
|
+
* @param {NotebookPanel} notebookPanel The notebook panel the extension currently listens to.
|
|
14
7
|
* @param {Object} eventDetail An object containing event details
|
|
15
8
|
* @param {Boolean} logNotebookContent A boolean indicating whether to log the entire notebook or not
|
|
16
9
|
*/
|
|
17
|
-
async publishEvent(eventDetail, logNotebookContent) {
|
|
18
|
-
var _a, _b
|
|
19
|
-
if (!
|
|
20
|
-
throw Error('router
|
|
21
|
-
}
|
|
22
|
-
// Check if session id received is equal to the stored session id
|
|
23
|
-
if (!this.sessionID ||
|
|
24
|
-
this.sessionID !== ((_b = (_a = this.notebookPanel) === null || _a === void 0 ? void 0 : _a.sessionContext.session) === null || _b === void 0 ? void 0 : _b.id)) {
|
|
25
|
-
this.sessionID = (_d = (_c = this.notebookPanel) === null || _c === void 0 ? void 0 : _c.sessionContext.session) === null || _d === void 0 ? void 0 : _d.id;
|
|
10
|
+
async publishEvent(notebookPanel, eventDetail, logNotebookContent) {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
if (!notebookPanel) {
|
|
13
|
+
throw Error('router is listening to a null notebook panel');
|
|
26
14
|
}
|
|
27
15
|
// Construct data
|
|
28
16
|
const requestBody = {
|
|
29
17
|
eventDetail: eventDetail,
|
|
30
18
|
notebookState: {
|
|
31
|
-
sessionID:
|
|
32
|
-
notebookPath:
|
|
19
|
+
sessionID: (_a = notebookPanel === null || notebookPanel === void 0 ? void 0 : notebookPanel.sessionContext.session) === null || _a === void 0 ? void 0 : _a.id,
|
|
20
|
+
notebookPath: notebookPanel === null || notebookPanel === void 0 ? void 0 : notebookPanel.context.path,
|
|
33
21
|
notebookContent: logNotebookContent
|
|
34
|
-
? (
|
|
22
|
+
? (_b = notebookPanel === null || notebookPanel === void 0 ? void 0 : notebookPanel.model) === null || _b === void 0 ? void 0 : _b.toJSON()
|
|
35
23
|
: null // decide whether to log the entire notebook
|
|
36
24
|
}
|
|
37
25
|
};
|