jupyter-specta 0.1.3 → 0.1.4
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/create_notebook_panel.d.ts +7 -1
- package/lib/create_notebook_panel.js +37 -1
- package/lib/document/factory.js +3 -2
- package/lib/document/plugin.js +1 -5
- package/lib/extension_plugins.js +6 -3
- package/lib/layout/{plugin.js → index.js} +4 -4
- package/lib/metadata/index.d.ts +3 -0
- package/lib/metadata/index.js +14 -0
- package/lib/specta_cell_output.d.ts +3 -1
- package/lib/specta_cell_output.js +6 -4
- package/lib/specta_model.d.ts +5 -2
- package/lib/specta_model.js +41 -27
- package/lib/specta_widget.js +5 -4
- package/lib/specta_widget_factory.d.ts +1 -2
- package/lib/specta_widget_factory.js +2 -1
- package/lib/token.d.ts +6 -1
- package/lib/tool.d.ts +5 -3
- package/lib/tool.js +42 -10
- package/lib/topbar/{plugin.js → index.js} +2 -4
- package/package.json +6 -3
- package/schema/app-meta.json +39 -0
- package/schema/cell-meta.json +37 -0
- /package/lib/layout/{plugin.d.ts → index.d.ts} +0 -0
- /package/lib/topbar/{plugin.d.ts → index.d.ts} +0 -0
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import { ISessionContext } from '@jupyterlab/apputils';
|
|
1
2
|
import { IEditorServices } from '@jupyterlab/codeeditor';
|
|
2
|
-
import { DocumentRegistry } from '@jupyterlab/docregistry';
|
|
3
|
+
import { Context, DocumentRegistry } from '@jupyterlab/docregistry';
|
|
3
4
|
import { INotebookModel, NotebookPanel } from '@jupyterlab/notebook';
|
|
4
5
|
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
|
6
|
+
import { ServiceManager } from '@jupyterlab/services';
|
|
7
|
+
export declare function createNotebookContext(options: {
|
|
8
|
+
manager: ServiceManager.IManager;
|
|
9
|
+
kernelPreference: ISessionContext.IKernelPreference;
|
|
10
|
+
}): Promise<Context<INotebookModel>>;
|
|
5
11
|
export declare function createNotebookPanel(options: {
|
|
6
12
|
context: DocumentRegistry.IContext<INotebookModel>;
|
|
7
13
|
rendermime: IRenderMimeRegistry;
|
|
@@ -1,4 +1,40 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Context } from '@jupyterlab/docregistry';
|
|
2
|
+
import { Notebook, NotebookModelFactory, NotebookPanel } from '@jupyterlab/notebook';
|
|
3
|
+
import { UUID } from '@lumino/coreutils';
|
|
4
|
+
class CustomContext extends Context {
|
|
5
|
+
/**
|
|
6
|
+
* Save the document contents to disk.
|
|
7
|
+
*/
|
|
8
|
+
async save() {
|
|
9
|
+
await this.ready;
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
async saveAs() {
|
|
13
|
+
await this.ready;
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
async revert() {
|
|
17
|
+
await this.ready;
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export async function createNotebookContext(options) {
|
|
22
|
+
const factory = new NotebookModelFactory({
|
|
23
|
+
disableDocumentWideUndoRedo: false
|
|
24
|
+
});
|
|
25
|
+
const { manager, kernelPreference } = options;
|
|
26
|
+
const path = UUID.uuid4() + '.ipynb';
|
|
27
|
+
await manager.ready;
|
|
28
|
+
await manager.kernelspecs.ready;
|
|
29
|
+
const context = new CustomContext({
|
|
30
|
+
manager,
|
|
31
|
+
factory,
|
|
32
|
+
path,
|
|
33
|
+
kernelPreference: kernelPreference
|
|
34
|
+
});
|
|
35
|
+
await context.sessionContext.initialize();
|
|
36
|
+
return context;
|
|
37
|
+
}
|
|
2
38
|
export function createNotebookPanel(options) {
|
|
3
39
|
const { context, rendermime, editorServices } = options;
|
|
4
40
|
const editorFactory = editorServices.factoryService.newInlineEditor;
|
package/lib/document/factory.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ABCWidgetFactory } from '@jupyterlab/docregistry';
|
|
|
2
2
|
import { ReactWidget } from '@jupyterlab/ui-components';
|
|
3
3
|
import { Panel } from '@lumino/widgets';
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import { isSpectaApp } from '../tool';
|
|
5
|
+
import { isSpectaApp, readSpectaConfig } from '../tool';
|
|
6
6
|
import { TopbarElement } from '../topbar/widget';
|
|
7
7
|
import { NotebookSpectaDocWidget } from './widget';
|
|
8
8
|
export class NotebookGridWidgetFactory extends ABCWidgetFactory {
|
|
@@ -13,7 +13,8 @@ export class NotebookGridWidgetFactory extends ABCWidgetFactory {
|
|
|
13
13
|
createNewWidget(context) {
|
|
14
14
|
const content = new Panel();
|
|
15
15
|
content.addClass('jp-specta-notebook-panel');
|
|
16
|
-
|
|
16
|
+
const spectaConfig = readSpectaConfig(context.model.metadata);
|
|
17
|
+
if (!isSpectaApp() && !spectaConfig.hideTopbar) {
|
|
17
18
|
// Not a specta app, add topbar to document widget
|
|
18
19
|
const topbar = ReactWidget.create(React.createElement(TopbarElement, null));
|
|
19
20
|
content.addWidget(topbar);
|
package/lib/document/plugin.js
CHANGED
|
@@ -6,12 +6,9 @@ import { IDocumentManager } from '@jupyterlab/docmanager';
|
|
|
6
6
|
import { createFileBrowser, hideAppLoadingIndicator, isSpectaApp, registerDocumentFactory } from '../tool';
|
|
7
7
|
import { ISpectaDocTracker, ISpectaLayoutRegistry } from '../token';
|
|
8
8
|
import { IKernelSpecManager } from '@jupyterlab/services';
|
|
9
|
-
import { PageConfig } from '@jupyterlab/coreutils';
|
|
10
9
|
const activate = (app, rendermime, tracker, editorServices, contentFactory, spectaLayoutRegistry) => {
|
|
11
|
-
var _a;
|
|
12
10
|
const namespace = 'specta';
|
|
13
11
|
const spectaTracker = new WidgetTracker({ namespace });
|
|
14
|
-
const spectaConfig = JSON.parse((_a = PageConfig.getOption('spectaConfig')) !== null && _a !== void 0 ? _a : '{}');
|
|
15
12
|
registerDocumentFactory({
|
|
16
13
|
factoryName: 'specta',
|
|
17
14
|
app,
|
|
@@ -20,8 +17,7 @@ const activate = (app, rendermime, tracker, editorServices, contentFactory, spec
|
|
|
20
17
|
editorServices,
|
|
21
18
|
contentFactory,
|
|
22
19
|
spectaTracker,
|
|
23
|
-
spectaLayoutRegistry
|
|
24
|
-
spectaConfig
|
|
20
|
+
spectaLayoutRegistry
|
|
25
21
|
});
|
|
26
22
|
return spectaTracker;
|
|
27
23
|
};
|
package/lib/extension_plugins.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { spectaDocument, spectaOpener } from './document/plugin';
|
|
2
|
-
import { spectaLayoutRegistry } from './layout
|
|
3
|
-
import {
|
|
2
|
+
import { spectaLayoutRegistry } from './layout';
|
|
3
|
+
import { appMeta, cellMeta } from './metadata';
|
|
4
|
+
import { topbarPlugin } from './topbar';
|
|
4
5
|
export * from './tool';
|
|
5
6
|
export * from './token';
|
|
6
7
|
export default [
|
|
7
8
|
spectaDocument,
|
|
8
9
|
spectaOpener,
|
|
9
10
|
spectaLayoutRegistry,
|
|
10
|
-
topbarPlugin
|
|
11
|
+
topbarPlugin,
|
|
12
|
+
appMeta,
|
|
13
|
+
cellMeta
|
|
11
14
|
];
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { SpectaLayoutRegistry } from './layout_registry';
|
|
2
2
|
import { ISpectaLayoutRegistry } from '../token';
|
|
3
|
-
import {
|
|
3
|
+
import { readSpectaConfig } from '../tool';
|
|
4
4
|
export const spectaLayoutRegistry = {
|
|
5
5
|
id: 'specta:layout-registry',
|
|
6
6
|
autoStart: true,
|
|
7
7
|
provides: ISpectaLayoutRegistry,
|
|
8
8
|
activate: (app) => {
|
|
9
|
-
var _a
|
|
9
|
+
var _a;
|
|
10
10
|
const layoutRegistry = new SpectaLayoutRegistry();
|
|
11
|
-
const spectaConfig =
|
|
12
|
-
const defaultLayout = (
|
|
11
|
+
const spectaConfig = readSpectaConfig();
|
|
12
|
+
const defaultLayout = (_a = spectaConfig.defaultLayout) !== null && _a !== void 0 ? _a : 'default';
|
|
13
13
|
layoutRegistry.setSelectedLayout(defaultLayout);
|
|
14
14
|
return layoutRegistry;
|
|
15
15
|
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import * as nbformat from '@jupyterlab/nbformat';
|
|
2
2
|
import { Panel, Widget } from '@lumino/widgets';
|
|
3
|
+
import { ISpectaCellConfig } from './token';
|
|
3
4
|
export interface ICellInfo {
|
|
4
5
|
hidden?: boolean;
|
|
5
6
|
cellModel?: nbformat.ICell;
|
|
6
7
|
}
|
|
7
8
|
export declare class SpectaCellOutput extends Panel {
|
|
8
|
-
constructor({ cellIdentity, cell, sourceCell, info }: {
|
|
9
|
+
constructor({ cellIdentity, cell, sourceCell, info, cellConfig }: {
|
|
9
10
|
cellIdentity: string;
|
|
10
11
|
cell: Widget;
|
|
11
12
|
sourceCell?: Widget;
|
|
12
13
|
info: ICellInfo;
|
|
14
|
+
cellConfig: Required<ISpectaCellConfig>;
|
|
13
15
|
});
|
|
14
16
|
readonly cellIdentity: string;
|
|
15
17
|
get cellOutput(): Widget;
|
|
@@ -3,7 +3,7 @@ import { Panel } from '@lumino/widgets';
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { RandomSkeleton } from './components/cellSkeleton';
|
|
5
5
|
export class SpectaCellOutput extends Panel {
|
|
6
|
-
constructor({ cellIdentity, cell, sourceCell, info }) {
|
|
6
|
+
constructor({ cellIdentity, cell, sourceCell, info, cellConfig }) {
|
|
7
7
|
var _a;
|
|
8
8
|
super();
|
|
9
9
|
this._info = {};
|
|
@@ -23,9 +23,11 @@ export class SpectaCellOutput extends Panel {
|
|
|
23
23
|
this.cellIdentity = cellIdentity;
|
|
24
24
|
this._info = info !== null && info !== void 0 ? info : {};
|
|
25
25
|
if (((_a = info.cellModel) === null || _a === void 0 ? void 0 : _a.cell_type) === 'code') {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
if (cellConfig.showOutput) {
|
|
27
|
+
this._placeholder = ReactWidget.create(React.createElement(RandomSkeleton, null));
|
|
28
|
+
this._placeholder.addClass('specta-cell-placeholder');
|
|
29
|
+
this.addWidget(this._placeholder);
|
|
30
|
+
}
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
get cellOutput() {
|
package/lib/specta_model.d.ts
CHANGED
|
@@ -17,14 +17,17 @@ export declare class AppModel {
|
|
|
17
17
|
dispose(): void;
|
|
18
18
|
get rendermime(): IRenderMimeRegistry;
|
|
19
19
|
get cells(): CellList | undefined;
|
|
20
|
-
get context(): DocumentRegistry.IContext<INotebookModel
|
|
20
|
+
get context(): DocumentRegistry.IContext<INotebookModel> | undefined;
|
|
21
21
|
get panel(): NotebookPanel | undefined;
|
|
22
22
|
initialize(): Promise<void>;
|
|
23
23
|
createCell(cellModel: ICellModel): SpectaCellOutput;
|
|
24
24
|
executeCell(cell: ICellModel, outputWrapper: SpectaCellOutput): Promise<IExecuteReplyMsg | undefined>;
|
|
25
25
|
private _notebookPanel?;
|
|
26
|
-
private _context
|
|
26
|
+
private _context?;
|
|
27
|
+
private _notebookModelJson;
|
|
27
28
|
private _isDisposed;
|
|
29
|
+
private _manager;
|
|
30
|
+
private _kernelPreference;
|
|
28
31
|
}
|
|
29
32
|
export declare namespace AppModel {
|
|
30
33
|
interface IOptions {
|
package/lib/specta_model.js
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import { CodeCell, MarkdownCell, RawCell } from '@jupyterlab/cells';
|
|
2
2
|
import { OutputAreaModel, SimplifiedOutputArea } from '@jupyterlab/outputarea';
|
|
3
|
-
import { createNotebookPanel } from './create_notebook_panel';
|
|
3
|
+
import { createNotebookContext, createNotebookPanel } from './create_notebook_panel';
|
|
4
4
|
import { SpectaCellOutput } from './specta_cell_output';
|
|
5
5
|
import { PromiseDelegate } from '@lumino/coreutils';
|
|
6
|
-
import {
|
|
6
|
+
import { readCellConfig } from './tool';
|
|
7
7
|
export const VIEW = 'grid_default';
|
|
8
8
|
export class AppModel {
|
|
9
9
|
constructor(options) {
|
|
10
10
|
this.options = options;
|
|
11
11
|
this._isDisposed = false;
|
|
12
|
-
this.
|
|
12
|
+
this._notebookModelJson = options.context.model.toJSON();
|
|
13
|
+
this._kernelPreference = {
|
|
14
|
+
shouldStart: true,
|
|
15
|
+
canStart: true,
|
|
16
|
+
shutdownOnDispose: true,
|
|
17
|
+
name: options.context.model.defaultKernelName,
|
|
18
|
+
autoStartDefault: true,
|
|
19
|
+
language: options.context.model.defaultKernelLanguage
|
|
20
|
+
};
|
|
21
|
+
this._manager = options.manager;
|
|
13
22
|
}
|
|
14
23
|
/**
|
|
15
24
|
* Whether the handler is disposed.
|
|
@@ -40,9 +49,13 @@ export class AppModel {
|
|
|
40
49
|
return this._notebookPanel;
|
|
41
50
|
}
|
|
42
51
|
async initialize() {
|
|
43
|
-
var _a
|
|
52
|
+
var _a;
|
|
44
53
|
const pd = new PromiseDelegate();
|
|
45
|
-
|
|
54
|
+
this._context = await createNotebookContext({
|
|
55
|
+
manager: this._manager,
|
|
56
|
+
kernelPreference: this._kernelPreference
|
|
57
|
+
});
|
|
58
|
+
this._context.model.fromJSON(this._notebookModelJson);
|
|
46
59
|
const connectKernel = () => {
|
|
47
60
|
pd.resolve();
|
|
48
61
|
this._notebookPanel = createNotebookPanel({
|
|
@@ -52,7 +65,7 @@ export class AppModel {
|
|
|
52
65
|
});
|
|
53
66
|
this.options.tracker.widgetAdded.emit(this._notebookPanel);
|
|
54
67
|
};
|
|
55
|
-
const kernel = (
|
|
68
|
+
const kernel = (_a = this._context.sessionContext.session) === null || _a === void 0 ? void 0 : _a.kernel;
|
|
56
69
|
if (kernel) {
|
|
57
70
|
const status = kernel.status;
|
|
58
71
|
if (status !== 'unknown') {
|
|
@@ -73,41 +86,40 @@ export class AppModel {
|
|
|
73
86
|
return pd.promise;
|
|
74
87
|
}
|
|
75
88
|
createCell(cellModel) {
|
|
76
|
-
var _a, _b;
|
|
77
89
|
let item;
|
|
78
90
|
const cellModelJson = cellModel.toJSON();
|
|
79
91
|
const info = {
|
|
80
92
|
cellModel: cellModelJson
|
|
81
93
|
};
|
|
94
|
+
const cellConfig = readCellConfig(cellModelJson);
|
|
82
95
|
switch (cellModel.type) {
|
|
83
96
|
case 'code': {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
let sourceCell;
|
|
98
|
+
if (cellConfig.showSource) {
|
|
99
|
+
sourceCell = new CodeCell({
|
|
100
|
+
model: cellModel,
|
|
101
|
+
rendermime: this.options.rendermime,
|
|
102
|
+
contentFactory: this.options.contentFactory,
|
|
103
|
+
editorConfig: {
|
|
104
|
+
lineNumbers: false,
|
|
105
|
+
lineWrap: false,
|
|
106
|
+
tabFocusable: false,
|
|
107
|
+
editable: false
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
sourceCell.syncEditable = false;
|
|
111
|
+
sourceCell.readOnly = true;
|
|
112
|
+
}
|
|
97
113
|
const outputareamodel = new OutputAreaModel({ trusted: true });
|
|
98
114
|
const out = new SimplifiedOutputArea({
|
|
99
115
|
model: outputareamodel,
|
|
100
116
|
rendermime: this.options.rendermime
|
|
101
117
|
});
|
|
102
|
-
const tags = ((_b = (_a = cellModel === null || cellModel === void 0 ? void 0 : cellModel.metadata) === null || _a === void 0 ? void 0 : _a.tags) !== null && _b !== void 0 ? _b : []);
|
|
103
|
-
let sourceCell;
|
|
104
|
-
if (tags.includes(SPECTA_CELL_VISIBLE_TAG)) {
|
|
105
|
-
sourceCell = codeCell;
|
|
106
|
-
}
|
|
107
118
|
item = new SpectaCellOutput({
|
|
108
119
|
cellIdentity: cellModel.id,
|
|
109
120
|
cell: out,
|
|
110
121
|
sourceCell,
|
|
122
|
+
cellConfig,
|
|
111
123
|
info
|
|
112
124
|
});
|
|
113
125
|
break;
|
|
@@ -127,7 +139,8 @@ export class AppModel {
|
|
|
127
139
|
item = new SpectaCellOutput({
|
|
128
140
|
cellIdentity: cellModel.id,
|
|
129
141
|
cell: markdownCell,
|
|
130
|
-
info
|
|
142
|
+
info,
|
|
143
|
+
cellConfig
|
|
131
144
|
});
|
|
132
145
|
break;
|
|
133
146
|
}
|
|
@@ -143,7 +156,8 @@ export class AppModel {
|
|
|
143
156
|
item = new SpectaCellOutput({
|
|
144
157
|
cellIdentity: cellModel.id,
|
|
145
158
|
cell: rawCell,
|
|
146
|
-
info
|
|
159
|
+
info,
|
|
160
|
+
cellConfig
|
|
147
161
|
});
|
|
148
162
|
break;
|
|
149
163
|
}
|
package/lib/specta_widget.js
CHANGED
|
@@ -56,9 +56,9 @@ export class AppWidget extends Panel {
|
|
|
56
56
|
super.dispose();
|
|
57
57
|
}
|
|
58
58
|
async render() {
|
|
59
|
-
var _a, _b, _c, _d;
|
|
59
|
+
var _a, _b, _c, _d, _e;
|
|
60
60
|
const cellList = (_a = this._model.cells) !== null && _a !== void 0 ? _a : [];
|
|
61
|
-
const layout = (_c = (_b = this._spectaAppConfig) === null || _b === void 0 ? void 0 : _b.
|
|
61
|
+
const layout = (_c = (_b = this._spectaAppConfig) === null || _b === void 0 ? void 0 : _b.defaultLayout) !== null && _c !== void 0 ? _c : 'default';
|
|
62
62
|
for (const cell of cellList) {
|
|
63
63
|
const src = cell.sharedModel.source;
|
|
64
64
|
if (src.length === 0) {
|
|
@@ -84,7 +84,7 @@ export class AppWidget extends Panel {
|
|
|
84
84
|
await spectaLayout.render({
|
|
85
85
|
host: this._host,
|
|
86
86
|
items: this._outputs,
|
|
87
|
-
notebook: this._model.context.model.toJSON(),
|
|
87
|
+
notebook: (_e = this._model.context) === null || _e === void 0 ? void 0 : _e.model.toJSON(),
|
|
88
88
|
readyCallback
|
|
89
89
|
});
|
|
90
90
|
}
|
|
@@ -93,6 +93,7 @@ export class AppWidget extends Panel {
|
|
|
93
93
|
super.onCloseRequest(msg);
|
|
94
94
|
}
|
|
95
95
|
_onSelectedLayoutChanged(sender, args) {
|
|
96
|
+
var _a;
|
|
96
97
|
const currentEls = [...this._host.widgets];
|
|
97
98
|
currentEls.forEach(el => {
|
|
98
99
|
var _a;
|
|
@@ -101,7 +102,7 @@ export class AppWidget extends Panel {
|
|
|
101
102
|
args.layout.render({
|
|
102
103
|
host: this._host,
|
|
103
104
|
items: this._outputs,
|
|
104
|
-
notebook: this._model.context.model.toJSON(),
|
|
105
|
+
notebook: (_a = this._model.context) === null || _a === void 0 ? void 0 : _a.model.toJSON(),
|
|
105
106
|
readyCallback: async () => { }
|
|
106
107
|
});
|
|
107
108
|
}
|
|
@@ -4,7 +4,7 @@ import { DocumentRegistry } from '@jupyterlab/docregistry';
|
|
|
4
4
|
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
|
5
5
|
import { ServiceManager } from '@jupyterlab/services';
|
|
6
6
|
import { AppWidget } from './specta_widget';
|
|
7
|
-
import {
|
|
7
|
+
import { ISpectaLayoutRegistry } from './token';
|
|
8
8
|
export declare class SpectaWidgetFactory {
|
|
9
9
|
constructor(options: SpectaWidgetFactory.IOptions);
|
|
10
10
|
createNew(options: {
|
|
@@ -21,6 +21,5 @@ export declare namespace SpectaWidgetFactory {
|
|
|
21
21
|
mimeTypeService: IEditorMimeTypeService;
|
|
22
22
|
editorServices: IEditorServices;
|
|
23
23
|
spectaLayoutRegistry: ISpectaLayoutRegistry;
|
|
24
|
-
spectaConfig: ISpectaAppConfig;
|
|
25
24
|
}
|
|
26
25
|
}
|
|
@@ -2,6 +2,7 @@ import { StaticNotebook } from '@jupyterlab/notebook';
|
|
|
2
2
|
import { AppModel } from './specta_model';
|
|
3
3
|
import { AppWidget } from './specta_widget';
|
|
4
4
|
import { UUID } from '@lumino/coreutils';
|
|
5
|
+
import { readSpectaConfig } from './tool';
|
|
5
6
|
export class SpectaWidgetFactory {
|
|
6
7
|
constructor(options) {
|
|
7
8
|
this._options = options;
|
|
@@ -27,7 +28,7 @@ export class SpectaWidgetFactory {
|
|
|
27
28
|
label: '',
|
|
28
29
|
model,
|
|
29
30
|
layoutRegistry: this._options.spectaLayoutRegistry,
|
|
30
|
-
spectaConfig:
|
|
31
|
+
spectaConfig: readSpectaConfig(context.model.metadata)
|
|
31
32
|
});
|
|
32
33
|
return panel;
|
|
33
34
|
}
|
package/lib/token.d.ts
CHANGED
|
@@ -38,7 +38,12 @@ export interface ITopbarConfig {
|
|
|
38
38
|
}
|
|
39
39
|
export interface ISpectaAppConfig {
|
|
40
40
|
topBar?: ITopbarConfig;
|
|
41
|
-
|
|
41
|
+
defaultLayout?: string;
|
|
42
|
+
hideTopbar?: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface ISpectaCellConfig {
|
|
45
|
+
showSource?: boolean;
|
|
46
|
+
showOutput?: boolean;
|
|
42
47
|
}
|
|
43
48
|
export declare const ISpectaLayoutRegistry: Token<ISpectaLayoutRegistry>;
|
|
44
49
|
export declare const ISpectaDocTracker: Token<IWidgetTracker<Widget>>;
|
package/lib/tool.d.ts
CHANGED
|
@@ -5,8 +5,9 @@ import { INotebookTracker, NotebookPanel } from '@jupyterlab/notebook';
|
|
|
5
5
|
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
|
6
6
|
import { VoilaFileBrowser } from '@voila-dashboards/voila';
|
|
7
7
|
import { IDocumentManager } from '@jupyterlab/docmanager';
|
|
8
|
-
import { ISpectaAppConfig, ISpectaLayoutRegistry } from './token';
|
|
9
|
-
|
|
8
|
+
import { ISpectaAppConfig, ISpectaCellConfig, ISpectaLayoutRegistry } from './token';
|
|
9
|
+
import { INotebookMetadata } from '@jupyterlab/nbformat';
|
|
10
|
+
import { ICell } from '@jupyterlab/nbformat';
|
|
10
11
|
export declare function registerDocumentFactory(options: {
|
|
11
12
|
factoryName: string;
|
|
12
13
|
app: JupyterFrontEnd;
|
|
@@ -16,10 +17,11 @@ export declare function registerDocumentFactory(options: {
|
|
|
16
17
|
contentFactory: NotebookPanel.IContentFactory;
|
|
17
18
|
spectaTracker: WidgetTracker;
|
|
18
19
|
spectaLayoutRegistry: ISpectaLayoutRegistry;
|
|
19
|
-
spectaConfig: ISpectaAppConfig;
|
|
20
20
|
}): void;
|
|
21
21
|
export declare function createFileBrowser(options: {
|
|
22
22
|
docManager: IDocumentManager;
|
|
23
23
|
}): VoilaFileBrowser;
|
|
24
24
|
export declare function hideAppLoadingIndicator(): void;
|
|
25
25
|
export declare function isSpectaApp(): boolean;
|
|
26
|
+
export declare function readSpectaConfig(nbMetadata?: INotebookMetadata): ISpectaAppConfig;
|
|
27
|
+
export declare function readCellConfig(cell?: ICell): Required<ISpectaCellConfig>;
|
package/lib/tool.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
|
|
2
2
|
import { FilterFileBrowserModel } from '@jupyterlab/filebrowser';
|
|
3
|
+
import { NotebookModelFactory } from '@jupyterlab/notebook';
|
|
3
4
|
import { VoilaFileBrowser } from '@voila-dashboards/voila';
|
|
4
5
|
import { NotebookGridWidgetFactory } from './document/factory';
|
|
5
6
|
import { SpectaWidgetFactory } from './specta_widget_factory';
|
|
6
|
-
export const SPECTA_CELL_VISIBLE_TAG = 'specta:visible';
|
|
7
7
|
export function registerDocumentFactory(options) {
|
|
8
|
-
const { factoryName, app, rendermime, tracker, editorServices, contentFactory, spectaTracker, spectaLayoutRegistry
|
|
8
|
+
const { factoryName, app, rendermime, tracker, editorServices, contentFactory, spectaTracker, spectaLayoutRegistry } = options;
|
|
9
9
|
const spectaWidgetFactory = new SpectaWidgetFactory({
|
|
10
10
|
manager: app.serviceManager,
|
|
11
11
|
rendermime,
|
|
@@ -13,21 +13,28 @@ export function registerDocumentFactory(options) {
|
|
|
13
13
|
contentFactory,
|
|
14
14
|
mimeTypeService: editorServices.mimeTypeService,
|
|
15
15
|
editorServices,
|
|
16
|
-
spectaLayoutRegistry
|
|
17
|
-
spectaConfig
|
|
16
|
+
spectaLayoutRegistry
|
|
18
17
|
});
|
|
19
18
|
const widgetFactory = new NotebookGridWidgetFactory({
|
|
20
19
|
name: factoryName,
|
|
21
20
|
modelName: 'notebook',
|
|
22
|
-
fileTypes: ['
|
|
23
|
-
spectaWidgetFactory
|
|
24
|
-
preferKernel: true,
|
|
25
|
-
canStartKernel: true,
|
|
26
|
-
autoStartDefault: true,
|
|
27
|
-
shutdownOnClose: true
|
|
21
|
+
fileTypes: ['ipynb'],
|
|
22
|
+
spectaWidgetFactory
|
|
28
23
|
});
|
|
29
24
|
// Registering the widget factory
|
|
30
25
|
app.docRegistry.addWidgetFactory(widgetFactory);
|
|
26
|
+
// Creating and registering the model factory for our custom DocumentModelAdd commentMore actions
|
|
27
|
+
const modelFactory = new NotebookModelFactory({});
|
|
28
|
+
app.docRegistry.addModelFactory(modelFactory);
|
|
29
|
+
// register the filetype
|
|
30
|
+
app.docRegistry.addFileType({
|
|
31
|
+
name: 'ipynb',
|
|
32
|
+
displayName: 'IPYNB',
|
|
33
|
+
mimeTypes: ['text/json'],
|
|
34
|
+
extensions: ['.ipynb', '.IPYNB'],
|
|
35
|
+
fileFormat: 'json',
|
|
36
|
+
contentType: 'notebook'
|
|
37
|
+
});
|
|
31
38
|
widgetFactory.widgetCreated.connect((sender, widget) => {
|
|
32
39
|
widget.context.pathChanged.connect(() => {
|
|
33
40
|
spectaTracker.save(widget);
|
|
@@ -83,3 +90,28 @@ export function hideAppLoadingIndicator() {
|
|
|
83
90
|
export function isSpectaApp() {
|
|
84
91
|
return !!document.querySelector('meta[name="specta-config"]');
|
|
85
92
|
}
|
|
93
|
+
export function readSpectaConfig(nbMetadata) {
|
|
94
|
+
var _a;
|
|
95
|
+
let rawConfig = PageConfig.getOption('spectaConfig');
|
|
96
|
+
if (!rawConfig || rawConfig.length === 0) {
|
|
97
|
+
rawConfig = '{}';
|
|
98
|
+
}
|
|
99
|
+
const spectaConfig = JSON.parse(rawConfig);
|
|
100
|
+
const spectaMetadata = ((_a = nbMetadata === null || nbMetadata === void 0 ? void 0 : nbMetadata.specta) !== null && _a !== void 0 ? _a : {});
|
|
101
|
+
return Object.assign(Object.assign({}, spectaConfig), spectaMetadata);
|
|
102
|
+
}
|
|
103
|
+
export function readCellConfig(cell) {
|
|
104
|
+
var _a, _b;
|
|
105
|
+
const metaData = ((_b = (_a = cell === null || cell === void 0 ? void 0 : cell.metadata) === null || _a === void 0 ? void 0 : _a.specta) !== null && _b !== void 0 ? _b : {});
|
|
106
|
+
const spectaCellConfig = {
|
|
107
|
+
showSource: false,
|
|
108
|
+
showOutput: true
|
|
109
|
+
};
|
|
110
|
+
if (metaData.showSource && metaData.showSource === 'Yes') {
|
|
111
|
+
spectaCellConfig.showSource = true;
|
|
112
|
+
}
|
|
113
|
+
if (metaData.showOutput && metaData.showOutput === 'No') {
|
|
114
|
+
spectaCellConfig.showOutput = false;
|
|
115
|
+
}
|
|
116
|
+
return spectaCellConfig;
|
|
117
|
+
}
|
|
@@ -2,9 +2,8 @@ import { IThemeManager } from '@jupyterlab/apputils';
|
|
|
2
2
|
import { ReactWidget } from '@jupyterlab/ui-components';
|
|
3
3
|
import { TopbarElement } from './widget';
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import { isSpectaApp } from '../tool';
|
|
5
|
+
import { isSpectaApp, readSpectaConfig } from '../tool';
|
|
6
6
|
import { ISpectaLayoutRegistry } from '../token';
|
|
7
|
-
import { PageConfig } from '@jupyterlab/coreutils';
|
|
8
7
|
/**
|
|
9
8
|
* Initialization data for the voila_topbar extension.
|
|
10
9
|
*/
|
|
@@ -14,12 +13,11 @@ export const topbarPlugin = {
|
|
|
14
13
|
autoStart: true,
|
|
15
14
|
requires: [IThemeManager, ISpectaLayoutRegistry],
|
|
16
15
|
activate: (app, themeManager, layoutRegistry) => {
|
|
17
|
-
var _a;
|
|
18
16
|
const isSpecta = isSpectaApp();
|
|
19
17
|
if (!isSpecta) {
|
|
20
18
|
return;
|
|
21
19
|
}
|
|
22
|
-
const config =
|
|
20
|
+
const config = readSpectaConfig();
|
|
23
21
|
const widget = ReactWidget.create(React.createElement(TopbarElement, { config: config.topBar, themeManager: themeManager, layoutRegistry: layoutRegistry }));
|
|
24
22
|
widget.id = 'specta-topbar-widget';
|
|
25
23
|
widget.addClass('specta-topbar-element');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jupyter-specta",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://github.com/trungleduc/specta",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
|
|
17
17
|
"style/**/*.{css,js,eot,gif,html,jpg,json,png,svg,woff2,ttf}",
|
|
18
|
-
"dist/**/*.{js,js.map,.txt}"
|
|
18
|
+
"dist/**/*.{js,js.map,.txt}",
|
|
19
|
+
"schema/*.json"
|
|
19
20
|
],
|
|
20
21
|
"main": "lib/extension_plugins.js",
|
|
21
22
|
"types": "lib/extension_plugins.d.ts",
|
|
@@ -29,6 +30,7 @@
|
|
|
29
30
|
"build:lib": "tsc",
|
|
30
31
|
"build:labextension": "jupyter labextension build .",
|
|
31
32
|
"build:labextension:dev": "jupyter labextension build --development True .",
|
|
33
|
+
"build:lab": "npm run clean && npm run build:lib && npm run build:labextension",
|
|
32
34
|
"build:app": "npm run clean && npm run build:lib && cd app && NODE_OPTIONS=--max-old-space-size=4096 NODE_ENV=production webpack --mode production",
|
|
33
35
|
"build:app:dev": "npm run clean && npm run build:lib && cd app && webpack",
|
|
34
36
|
"build:all": "npm run build:app && npm run build:labextension",
|
|
@@ -233,6 +235,7 @@
|
|
|
233
235
|
},
|
|
234
236
|
"jupyterlab": {
|
|
235
237
|
"extension": true,
|
|
236
|
-
"outputDir": "specta/labextension"
|
|
238
|
+
"outputDir": "specta/labextension",
|
|
239
|
+
"schemaDir": "schema"
|
|
237
240
|
}
|
|
238
241
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "object",
|
|
3
|
+
"title": "Metadata Form example",
|
|
4
|
+
"description": "Settings of the metadata form extension.",
|
|
5
|
+
"jupyter.lab.metadataforms": [
|
|
6
|
+
{
|
|
7
|
+
"id": "jupyter-specta:app-meta",
|
|
8
|
+
"label": "Specta App Config",
|
|
9
|
+
"metadataSchema": {
|
|
10
|
+
"type": "object",
|
|
11
|
+
"properties": {
|
|
12
|
+
"/specta/hideTopbar": {
|
|
13
|
+
"title": "Hide top bar",
|
|
14
|
+
"type": "boolean",
|
|
15
|
+
"enum": [true, false],
|
|
16
|
+
"default": false
|
|
17
|
+
},
|
|
18
|
+
"/specta/defaultLayout": {
|
|
19
|
+
"title": "Page layout",
|
|
20
|
+
"type": "string",
|
|
21
|
+
"enum": ["default", "article"],
|
|
22
|
+
"default": "default"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"metadataOptions": {
|
|
27
|
+
"/specta/hideTopbar": {
|
|
28
|
+
"metadataLevel": "notebook",
|
|
29
|
+
"writeDefault": false
|
|
30
|
+
},
|
|
31
|
+
"/specta/defaultLayout": {
|
|
32
|
+
"metadataLevel": "notebook",
|
|
33
|
+
"writeDefault": false
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
"additionalProperties": false
|
|
39
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "object",
|
|
3
|
+
"title": "Metadata Form example",
|
|
4
|
+
"description": "Settings of the metadata form extension.",
|
|
5
|
+
"jupyter.lab.metadataforms": [
|
|
6
|
+
{
|
|
7
|
+
"id": "jupyter-specta:cell-meta",
|
|
8
|
+
"label": "Specta Cell Config",
|
|
9
|
+
"metadataSchema": {
|
|
10
|
+
"type": "object",
|
|
11
|
+
"properties": {
|
|
12
|
+
"/specta/showSource": {
|
|
13
|
+
"title": "Show cell source",
|
|
14
|
+
"type": "string",
|
|
15
|
+
"enum": ["Yes", "No"],
|
|
16
|
+
"default": "No"
|
|
17
|
+
},
|
|
18
|
+
"/specta/showOutput": {
|
|
19
|
+
"title": "Show output placeholder",
|
|
20
|
+
"type": "string",
|
|
21
|
+
"enum": ["Yes", "No"],
|
|
22
|
+
"default": "Yes"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"metadataOptions": {
|
|
27
|
+
"/specta/showSource": {
|
|
28
|
+
"writeDefault": false
|
|
29
|
+
},
|
|
30
|
+
"/specta/showOutput": {
|
|
31
|
+
"writeDefault": false
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"additionalProperties": false
|
|
37
|
+
}
|
|
File without changes
|
|
File without changes
|