jupyterlab-pioneer 1.3.0 → 1.5.0

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.
Files changed (2) hide show
  1. package/lib/producer.js +39 -26
  2. package/package.json +1 -1
package/lib/producer.js CHANGED
@@ -7,7 +7,8 @@ class ActiveCellChangeEventProducer {
7
7
  if (cell && notebookPanel.content.widgets) {
8
8
  const activatedCell = {
9
9
  id: cell === null || cell === void 0 ? void 0 : cell.model.id,
10
- index: notebookPanel.content.widgets.findIndex(value => value === cell)
10
+ index: notebookPanel.content.widgets.findIndex(value => value === cell),
11
+ type: cell === null || cell === void 0 ? void 0 : cell.model.type
11
12
  };
12
13
  const event = {
13
14
  eventName: ActiveCellChangeEventProducer.id,
@@ -35,7 +36,8 @@ class CellAddEventProducer {
35
36
  if (args.type === 'add') {
36
37
  const addedCell = {
37
38
  id: args.newValues[0].id,
38
- index: args.newIndex
39
+ index: args.newIndex,
40
+ type: args.newValues[0].type
39
41
  };
40
42
  const event = {
41
43
  eventName: CellAddEventProducer.id,
@@ -68,7 +70,8 @@ class CellEditEventProducer {
68
70
  eventTime: Date.now(),
69
71
  eventInfo: {
70
72
  index: notebookPanel.content.widgets.findIndex(value => value === cell),
71
- doc: (_b = (_a = editor === null || editor === void 0 ? void 0 : editor.state) === null || _a === void 0 ? void 0 : _a.doc) === null || _b === void 0 ? void 0 : _b.toJSON() // send entire cell content if this is a new cell
73
+ doc: (_b = (_a = editor === null || editor === void 0 ? void 0 : editor.state) === null || _a === void 0 ? void 0 : _a.doc) === null || _b === void 0 ? void 0 : _b.toJSON(),
74
+ type: cell === null || cell === void 0 ? void 0 : cell.model.type
72
75
  }
73
76
  };
74
77
  pioneer.exporters.forEach(async (exporter) => {
@@ -88,7 +91,8 @@ class CellEditEventProducer {
88
91
  eventTime: Date.now(),
89
92
  eventInfo: {
90
93
  index: notebookPanel.content.widgets.findIndex(value => value === cell),
91
- changes: v.changes.toJSON() // send changes
94
+ changes: v.changes.toJSON(),
95
+ type: cell === null || cell === void 0 ? void 0 : cell.model.type
92
96
  }
93
97
  };
94
98
  pioneer.exporters.forEach(async (exporter) => {
@@ -122,7 +126,8 @@ class CellExecuteEventProducer {
122
126
  if (notebookPanel.content === args.notebook) {
123
127
  const executedCell = {
124
128
  id: args.cell.model.id,
125
- index: args.notebook.widgets.findIndex(value => value == args.cell)
129
+ index: args.notebook.widgets.findIndex(value => value == args.cell),
130
+ type: args.cell.model.type
126
131
  };
127
132
  const event = {
128
133
  eventName: CellExecuteEventProducer.id,
@@ -149,9 +154,11 @@ class CellRemoveEventProducer {
149
154
  listen(notebookPanel, pioneer) {
150
155
  var _a;
151
156
  (_a = notebookPanel.content.model) === null || _a === void 0 ? void 0 : _a.cells.changed.connect(async (_, args) => {
157
+ var _a;
152
158
  if (args.type === 'remove') {
153
159
  const removedCell = {
154
- index: args.oldIndex
160
+ index: args.oldIndex,
161
+ type: (_a = notebookPanel.content.model) === null || _a === void 0 ? void 0 : _a.cells.get(args.oldIndex).type
155
162
  };
156
163
  const event = {
157
164
  eventName: CellRemoveEventProducer.id,
@@ -175,12 +182,13 @@ export { CellRemoveEventProducer };
175
182
  class ClipboardCopyEventProducer {
176
183
  listen(notebookPanel, pioneer) {
177
184
  notebookPanel.node.addEventListener('copy', async () => {
178
- var _a, _b;
185
+ var _a, _b, _c;
179
186
  const cell = {
180
187
  id: (_a = notebookPanel.content.activeCell) === null || _a === void 0 ? void 0 : _a.model.id,
181
- index: notebookPanel.content.widgets.findIndex(value => value === notebookPanel.content.activeCell)
188
+ index: notebookPanel.content.widgets.findIndex(value => value === notebookPanel.content.activeCell),
189
+ type: (_b = notebookPanel.content.activeCell) === null || _b === void 0 ? void 0 : _b.model.type
182
190
  };
183
- const text = (_b = document.getSelection()) === null || _b === void 0 ? void 0 : _b.toString();
191
+ const text = (_c = document.getSelection()) === null || _c === void 0 ? void 0 : _c.toString();
184
192
  const event = {
185
193
  eventName: ClipboardCopyEventProducer.id,
186
194
  eventTime: Date.now(),
@@ -191,7 +199,7 @@ class ClipboardCopyEventProducer {
191
199
  };
192
200
  pioneer.exporters.forEach(async (exporter) => {
193
201
  var _a, _b, _c;
194
- if ((_a = exporter.activeEvents) === null || _a === void 0 ? void 0 : _a.map(o => o.name).includes(CellRemoveEventProducer.id)) {
202
+ if ((_a = exporter.activeEvents) === null || _a === void 0 ? void 0 : _a.map(o => o.name).includes(ClipboardCopyEventProducer.id)) {
195
203
  await pioneer.publishEvent(notebookPanel, event, exporter, (_c = (_b = exporter.activeEvents) === null || _b === void 0 ? void 0 : _b.find(o => o.name == ClipboardCopyEventProducer.id)) === null || _c === void 0 ? void 0 : _c.logWholeNotebook);
196
204
  }
197
205
  });
@@ -203,12 +211,13 @@ export { ClipboardCopyEventProducer };
203
211
  class ClipboardCutEventProducer {
204
212
  listen(notebookPanel, pioneer) {
205
213
  notebookPanel.node.addEventListener('cut', async () => {
206
- var _a, _b;
214
+ var _a, _b, _c;
207
215
  const cell = {
208
216
  id: (_a = notebookPanel.content.activeCell) === null || _a === void 0 ? void 0 : _a.model.id,
209
- index: notebookPanel.content.widgets.findIndex(value => value === notebookPanel.content.activeCell)
217
+ index: notebookPanel.content.widgets.findIndex(value => value === notebookPanel.content.activeCell),
218
+ type: (_b = notebookPanel.content.activeCell) === null || _b === void 0 ? void 0 : _b.model.type
210
219
  };
211
- const text = (_b = document.getSelection()) === null || _b === void 0 ? void 0 : _b.toString();
220
+ const text = (_c = document.getSelection()) === null || _c === void 0 ? void 0 : _c.toString();
212
221
  const event = {
213
222
  eventName: ClipboardCutEventProducer.id,
214
223
  eventTime: Date.now(),
@@ -219,7 +228,7 @@ class ClipboardCutEventProducer {
219
228
  };
220
229
  pioneer.exporters.forEach(async (exporter) => {
221
230
  var _a, _b, _c;
222
- if ((_a = exporter.activeEvents) === null || _a === void 0 ? void 0 : _a.map(o => o.name).includes(CellRemoveEventProducer.id)) {
231
+ if ((_a = exporter.activeEvents) === null || _a === void 0 ? void 0 : _a.map(o => o.name).includes(ClipboardCutEventProducer.id)) {
223
232
  await pioneer.publishEvent(notebookPanel, event, exporter, (_c = (_b = exporter.activeEvents) === null || _b === void 0 ? void 0 : _b.find(o => o.name == ClipboardCutEventProducer.id)) === null || _c === void 0 ? void 0 : _c.logWholeNotebook);
224
233
  }
225
234
  });
@@ -231,10 +240,11 @@ export { ClipboardCutEventProducer };
231
240
  class ClipboardPasteEventProducer {
232
241
  listen(notebookPanel, pioneer) {
233
242
  notebookPanel.node.addEventListener('paste', async (e) => {
234
- var _a;
243
+ var _a, _b;
235
244
  const cell = {
236
245
  id: (_a = notebookPanel.content.activeCell) === null || _a === void 0 ? void 0 : _a.model.id,
237
- index: notebookPanel.content.widgets.findIndex(value => value === notebookPanel.content.activeCell)
246
+ index: notebookPanel.content.widgets.findIndex(value => value === notebookPanel.content.activeCell),
247
+ type: (_b = notebookPanel.content.activeCell) === null || _b === void 0 ? void 0 : _b.model.type
238
248
  };
239
249
  const text = (e.clipboardData || window.clipboardData).getData('text');
240
250
  const event = {
@@ -247,7 +257,7 @@ class ClipboardPasteEventProducer {
247
257
  };
248
258
  pioneer.exporters.forEach(async (exporter) => {
249
259
  var _a, _b, _c;
250
- if ((_a = exporter.activeEvents) === null || _a === void 0 ? void 0 : _a.map(o => o.name).includes(CellRemoveEventProducer.id)) {
260
+ if ((_a = exporter.activeEvents) === null || _a === void 0 ? void 0 : _a.map(o => o.name).includes(ClipboardPasteEventProducer.id)) {
251
261
  await pioneer.publishEvent(notebookPanel, event, exporter, (_c = (_b = exporter.activeEvents) === null || _b === void 0 ? void 0 : _b.find(o => o.name == ClipboardPasteEventProducer.id)) === null || _c === void 0 ? void 0 : _c.logWholeNotebook);
252
262
  }
253
263
  });
@@ -268,7 +278,7 @@ class NotebookHiddenEventProducer {
268
278
  };
269
279
  pioneer.exporters.forEach(async (exporter) => {
270
280
  var _a, _b, _c;
271
- if ((_a = exporter.activeEvents) === null || _a === void 0 ? void 0 : _a.map(o => o.name).includes(CellRemoveEventProducer.id)) {
281
+ if ((_a = exporter.activeEvents) === null || _a === void 0 ? void 0 : _a.map(o => o.name).includes(NotebookHiddenEventProducer.id)) {
272
282
  await pioneer.publishEvent(notebookPanel, event, exporter, (_c = (_b = exporter.activeEvents) === null || _b === void 0 ? void 0 : _b.find(o => o.name == NotebookHiddenEventProducer.id)) === null || _c === void 0 ? void 0 : _c.logWholeNotebook);
273
283
  }
274
284
  });
@@ -293,7 +303,7 @@ class NotebookOpenEventProducer {
293
303
  };
294
304
  pioneer.exporters.forEach(async (exporter) => {
295
305
  var _a, _b, _c;
296
- if ((_a = exporter.activeEvents) === null || _a === void 0 ? void 0 : _a.map(o => o.name).includes(CellRemoveEventProducer.id)) {
306
+ if ((_a = exporter.activeEvents) === null || _a === void 0 ? void 0 : _a.map(o => o.name).includes(NotebookOpenEventProducer.id)) {
297
307
  await pioneer.publishEvent(notebookPanel, event, exporter, (_c = (_b = exporter.activeEvents) === null || _b === void 0 ? void 0 : _b.find(o => o.name == NotebookOpenEventProducer.id)) === null || _c === void 0 ? void 0 : _c.logWholeNotebook);
298
308
  this.produced = true;
299
309
  }
@@ -314,7 +324,7 @@ class NotebookSaveEventProducer {
314
324
  };
315
325
  pioneer.exporters.forEach(async (exporter) => {
316
326
  var _a, _b, _c;
317
- if ((_a = exporter.activeEvents) === null || _a === void 0 ? void 0 : _a.map(o => o.name).includes(CellRemoveEventProducer.id)) {
327
+ if ((_a = exporter.activeEvents) === null || _a === void 0 ? void 0 : _a.map(o => o.name).includes(NotebookSaveEventProducer.id)) {
318
328
  await pioneer.publishEvent(notebookPanel, event, exporter, (_c = (_b = exporter.activeEvents) === null || _b === void 0 ? void 0 : _b.find(o => o.name == NotebookSaveEventProducer.id)) === null || _c === void 0 ? void 0 : _c.logWholeNotebook);
319
329
  }
320
330
  });
@@ -330,13 +340,14 @@ const getVisibleCells = (notebookPanel) => {
330
340
  const cell = notebookPanel.content.widgets[index];
331
341
  const cellTop = cell.node.offsetTop;
332
342
  const cellBottom = cell.node.offsetTop + cell.node.offsetHeight;
333
- const viewTop = notebookPanel.content.node.scrollTop;
334
- const viewBottom = notebookPanel.content.node.scrollTop +
335
- notebookPanel.content.node.clientHeight;
343
+ const viewTop = notebookPanel.node.getElementsByClassName('jp-WindowedPanel-outer')[0].scrollTop;
344
+ const viewBottom = notebookPanel.content.node.getElementsByClassName('jp-WindowedPanel-outer')[0].scrollTop +
345
+ notebookPanel.content.node.getElementsByClassName('jp-WindowedPanel-outer')[0].clientHeight;
336
346
  if (cellTop <= viewBottom && cellBottom >= viewTop) {
337
347
  visibleCells.push({
338
348
  id: cell.model.id,
339
- index: index
349
+ index: index,
350
+ type: cell.model.type
340
351
  });
341
352
  }
342
353
  }
@@ -347,7 +358,9 @@ class NotebookScrollEventProducer {
347
358
  this.timeout = 0;
348
359
  }
349
360
  listen(notebookPanel, pioneer) {
350
- notebookPanel.content.node.addEventListener('scroll', async (e) => {
361
+ notebookPanel.node
362
+ .getElementsByClassName('jp-WindowedPanel-outer')[0]
363
+ .addEventListener('scroll', async (e) => {
351
364
  e.stopPropagation();
352
365
  clearTimeout(this.timeout);
353
366
  await new Promise(resolve => (this.timeout = window.setTimeout(resolve, 1500))); // wait 1.5 seconds before preceding
@@ -360,7 +373,7 @@ class NotebookScrollEventProducer {
360
373
  };
361
374
  pioneer.exporters.forEach(async (exporter) => {
362
375
  var _a, _b, _c;
363
- if ((_a = exporter.activeEvents) === null || _a === void 0 ? void 0 : _a.map(o => o.name).includes(CellRemoveEventProducer.id)) {
376
+ if ((_a = exporter.activeEvents) === null || _a === void 0 ? void 0 : _a.map(o => o.name).includes(NotebookScrollEventProducer.id)) {
364
377
  await pioneer.publishEvent(notebookPanel, event, exporter, (_c = (_b = exporter.activeEvents) === null || _b === void 0 ? void 0 : _b.find(o => o.name == NotebookScrollEventProducer.id)) === null || _c === void 0 ? void 0 : _c.logWholeNotebook);
365
378
  }
366
379
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jupyterlab-pioneer",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "A JupyterLab extension.",
5
5
  "keywords": [
6
6
  "jupyter",