@difizen/libro-jupyter 0.1.17 → 0.1.19
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/es/cell/jupyter-code-cell-view.d.ts +2 -9
- package/es/cell/jupyter-code-cell-view.d.ts.map +1 -1
- package/es/cell/jupyter-code-cell-view.js +62 -108
- package/es/components/cell-execution-tip.js +2 -2
- package/es/file/file-command.d.ts +6 -0
- package/es/file/file-command.d.ts.map +1 -1
- package/es/file/file-command.js +45 -2
- package/es/file/file-view/index.d.ts +12 -0
- package/es/file/file-view/index.d.ts.map +1 -1
- package/es/file/file-view/index.js +137 -4
- package/es/file/navigatable-view.js +1 -1
- package/es/libro-jupyter-model.d.ts.map +1 -1
- package/es/libro-jupyter-model.js +18 -2
- package/es/libro-jupyter-protocol.d.ts +1 -0
- package/es/libro-jupyter-protocol.d.ts.map +1 -1
- package/es/libro-jupyter-protocol.js +2 -1
- package/es/libro-jupyter-view.d.ts +3 -1
- package/es/libro-jupyter-view.d.ts.map +1 -1
- package/es/module.js +3 -3
- package/package.json +17 -16
- package/src/cell/jupyter-code-cell-view.tsx +12 -60
- package/src/components/cell-execution-tip.tsx +2 -2
- package/src/file/file-command.tsx +46 -6
- package/src/file/file-view/index.tsx +90 -0
- package/src/file/navigatable-view.tsx +1 -1
- package/src/libro-jupyter-model.ts +17 -0
- package/src/libro-jupyter-protocol.ts +2 -0
- package/src/libro-jupyter-view.tsx +3 -0
- package/src/module.ts +2 -2
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ExclamationCircleFilled, FolderFilled } from '@ant-design/icons';
|
|
2
|
+
import { ContentsManager } from '@difizen/libro-kernel';
|
|
3
|
+
import type { IContentsModel } from '@difizen/libro-kernel';
|
|
2
4
|
import type { TreeNode, ViewOpenHandler } from '@difizen/mana-app';
|
|
3
5
|
import { FileTreeViewFactory } from '@difizen/mana-app';
|
|
4
6
|
import {
|
|
@@ -39,7 +41,9 @@ const noVerifyFileType = ['.ipynb', '.py'];
|
|
|
39
41
|
@view(FileTreeViewFactory, FileTreeModule)
|
|
40
42
|
export class FileView extends FileTreeView {
|
|
41
43
|
@inject(OpenerService) protected openService: OpenerService;
|
|
44
|
+
@inject(ContentsManager) protected contentsManager: ContentsManager;
|
|
42
45
|
@inject(CommandRegistry) protected command: CommandRegistry;
|
|
46
|
+
uploadInput?: HTMLInputElement;
|
|
43
47
|
override id = FileTreeViewFactory;
|
|
44
48
|
override className = 'libro-jupyter-file-tree';
|
|
45
49
|
|
|
@@ -64,6 +68,92 @@ export class FileView extends FileTreeView {
|
|
|
64
68
|
this.toDispose.push(this.model.onOpenNode(this.openNode));
|
|
65
69
|
}
|
|
66
70
|
|
|
71
|
+
override onViewMount(): void {
|
|
72
|
+
super.onViewMount?.();
|
|
73
|
+
if (!this.container?.current) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const container = this.container.current;
|
|
77
|
+
const input = document.createElement('input');
|
|
78
|
+
input.type = 'file';
|
|
79
|
+
input.multiple = true;
|
|
80
|
+
input.onclick = this.onInputClicked;
|
|
81
|
+
input.onchange = this.onInputChanged;
|
|
82
|
+
input.style.display = 'none';
|
|
83
|
+
container.appendChild(input);
|
|
84
|
+
this.uploadInput = input;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
uploadSubmit = (basePath?: string) => {
|
|
88
|
+
if (this.uploadInput) {
|
|
89
|
+
this.uploadInput.setAttribute('data-path', basePath || '');
|
|
90
|
+
this.uploadInput.click();
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Perform the actual upload.
|
|
95
|
+
*/
|
|
96
|
+
protected async doUpload(file: File, basePath: string): Promise<IContentsModel> {
|
|
97
|
+
// Gather the file model parameters.
|
|
98
|
+
let path = basePath;
|
|
99
|
+
path = path ? path + '/' + file.name : file.name;
|
|
100
|
+
const name = file.name;
|
|
101
|
+
const type = 'file';
|
|
102
|
+
const format = 'base64';
|
|
103
|
+
|
|
104
|
+
const uploadInner = async (blob: Blob, chunk?: number): Promise<IContentsModel> => {
|
|
105
|
+
const reader = new FileReader();
|
|
106
|
+
reader.readAsDataURL(blob);
|
|
107
|
+
await new Promise((resolve, reject) => {
|
|
108
|
+
reader.onload = resolve;
|
|
109
|
+
reader.onerror = (event) => reject(`Failed to upload "${file.name}":` + event);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// remove header https://stackoverflow.com/a/24289420/907060
|
|
113
|
+
const content = (reader.result as string).split(',')[1];
|
|
114
|
+
|
|
115
|
+
const model: Partial<IContentsModel> = {
|
|
116
|
+
type,
|
|
117
|
+
format,
|
|
118
|
+
name,
|
|
119
|
+
chunk,
|
|
120
|
+
content,
|
|
121
|
+
};
|
|
122
|
+
return await this.contentsManager.save(path, model);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
return await uploadInner(file);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
onInputChanged = () => {
|
|
129
|
+
if (!this.uploadInput) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
let path = this.uploadInput.getAttribute('data-path') || '';
|
|
133
|
+
if (!path) {
|
|
134
|
+
path = this.model.location?.path.toString() || '';
|
|
135
|
+
}
|
|
136
|
+
if (!path) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const files = Array.prototype.slice.call(this.uploadInput.files) as File[];
|
|
140
|
+
const pending = files.map((file) => this.doUpload(file, path));
|
|
141
|
+
Promise.all(pending)
|
|
142
|
+
.then(() => {
|
|
143
|
+
this.model.refresh();
|
|
144
|
+
return;
|
|
145
|
+
})
|
|
146
|
+
.catch((error) => {
|
|
147
|
+
console.error('Upload Error:', error);
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
onInputClicked = () => {
|
|
152
|
+
if (this.uploadInput) {
|
|
153
|
+
this.uploadInput.value = '';
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
67
157
|
openNode = async (treeNode: TreeNode) => {
|
|
68
158
|
if (FileStatNode.is(treeNode) && !treeNode.fileStat.isDirectory) {
|
|
69
159
|
if (
|
|
@@ -141,7 +141,7 @@ export class LibroNavigatableView
|
|
|
141
141
|
return;
|
|
142
142
|
}
|
|
143
143
|
this.libroView = libroView;
|
|
144
|
-
this.libroView.model.
|
|
144
|
+
this.libroView.model.onChanged(() => {
|
|
145
145
|
this.dirty = true;
|
|
146
146
|
this.dirtyEmitter.fire();
|
|
147
147
|
if (this.autoSave === 'on') {
|
|
@@ -3,6 +3,7 @@ import type { VirtualizedManager } from '@difizen/libro-core';
|
|
|
3
3
|
import {
|
|
4
4
|
ContentsManager,
|
|
5
5
|
ExecutableNotebookModel,
|
|
6
|
+
isDisplayDataMsg,
|
|
6
7
|
LibroKernelConnectionManager,
|
|
7
8
|
ServerConnection,
|
|
8
9
|
ServerManager,
|
|
@@ -16,6 +17,7 @@ import { l10n } from '@difizen/mana-l10n';
|
|
|
16
17
|
|
|
17
18
|
import {
|
|
18
19
|
ExecutedWithKernelCellModel,
|
|
20
|
+
libroArgsMimetype,
|
|
19
21
|
LibroFileService,
|
|
20
22
|
} from './libro-jupyter-protocol.js';
|
|
21
23
|
import { SaveFileErrorModal } from './toolbar/save-file-error.js';
|
|
@@ -81,6 +83,21 @@ export class LibroJupyterModel extends LibroModel implements ExecutableNotebookM
|
|
|
81
83
|
this.modalService = modalService;
|
|
82
84
|
this.dndAreaNullEnable = true;
|
|
83
85
|
this.virtualizedManager = virtualizedManagerHelper.getOrCreate(this);
|
|
86
|
+
this.kcReady
|
|
87
|
+
.then(() => {
|
|
88
|
+
this.kernelConnection?.futureMessage((msg) => {
|
|
89
|
+
if (isDisplayDataMsg(msg) && libroArgsMimetype in msg.content.data) {
|
|
90
|
+
this.metadata = {
|
|
91
|
+
...this.metadata,
|
|
92
|
+
args: msg.content.data[libroArgsMimetype],
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return;
|
|
97
|
+
})
|
|
98
|
+
.catch(() => {
|
|
99
|
+
return;
|
|
100
|
+
});
|
|
84
101
|
}
|
|
85
102
|
|
|
86
103
|
get isKernelIdle() {
|
|
@@ -5,10 +5,13 @@ import { LibroView, notebookViewFactoryId } from '@difizen/libro-core';
|
|
|
5
5
|
import { URI, view, ViewOption } from '@difizen/mana-app';
|
|
6
6
|
import { inject, transient } from '@difizen/mana-app';
|
|
7
7
|
|
|
8
|
+
import type { LibroJupyterModel } from './libro-jupyter-model.js';
|
|
9
|
+
|
|
8
10
|
@transient()
|
|
9
11
|
@view(notebookViewFactoryId)
|
|
10
12
|
export class LibroJupyterView extends LibroView {
|
|
11
13
|
uri: URI;
|
|
14
|
+
declare model: LibroJupyterModel;
|
|
12
15
|
constructor(
|
|
13
16
|
@inject(ViewOption) options: NotebookOption,
|
|
14
17
|
@inject(CollapseServiceFactory) collapseServiceFactory: CollapseServiceFactory,
|
package/src/module.ts
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
LibroToolbarModule,
|
|
16
16
|
} from '@difizen/libro-core';
|
|
17
17
|
import { LibroKernelManageModule } from '@difizen/libro-kernel';
|
|
18
|
-
import {
|
|
18
|
+
import { LibroLanguageClientModule } from '@difizen/libro-language-client';
|
|
19
19
|
import { MarkdownCellModule } from '@difizen/libro-markdown-cell';
|
|
20
20
|
import {
|
|
21
21
|
DisplayDataOutputModule,
|
|
@@ -102,7 +102,6 @@ export const LibroJupyterModule = ManaModule.create()
|
|
|
102
102
|
LibroSearchModule,
|
|
103
103
|
SearchCodeCellModule,
|
|
104
104
|
LibroAddCellModule,
|
|
105
|
-
LibroLSPModule,
|
|
106
105
|
LibroE2EditorModule,
|
|
107
106
|
CodeMirrorEditorModule,
|
|
108
107
|
// custom module
|
|
@@ -110,4 +109,5 @@ export const LibroJupyterModule = ManaModule.create()
|
|
|
110
109
|
KeybindInstructionsModule,
|
|
111
110
|
PlotlyModule,
|
|
112
111
|
LibroJupyterFileModule,
|
|
112
|
+
LibroLanguageClientModule,
|
|
113
113
|
);
|