@difizen/libro-jupyter 0.0.2-alpha.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.
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/es/add-between-cell/add-between-cell-command-contribution.d.ts +14 -0
- package/es/add-between-cell/add-between-cell-command-contribution.d.ts.map +1 -0
- package/es/add-between-cell/add-between-cell-command-contribution.js +97 -0
- package/es/add-between-cell/add-between-cell.d.ts +5 -0
- package/es/add-between-cell/add-between-cell.d.ts.map +1 -0
- package/es/add-between-cell/add-between-cell.js +243 -0
- package/es/add-between-cell/index.d.ts +3 -0
- package/es/add-between-cell/index.d.ts.map +1 -0
- package/es/add-between-cell/index.js +2 -0
- package/es/add-between-cell/index.less +103 -0
- package/es/add-between-cell/module.d.ts +3 -0
- package/es/add-between-cell/module.d.ts.map +1 -0
- package/es/add-between-cell/module.js +8 -0
- package/es/cell/index.d.ts +3 -0
- package/es/cell/index.d.ts.map +1 -0
- package/es/cell/index.js +2 -0
- package/es/cell/jupyter-code-cell-model.d.ts +12 -0
- package/es/cell/jupyter-code-cell-model.d.ts.map +1 -0
- package/es/cell/jupyter-code-cell-model.js +56 -0
- package/es/cell/jupyter-code-cell-view.d.ts +18 -0
- package/es/cell/jupyter-code-cell-view.d.ts.map +1 -0
- package/es/cell/jupyter-code-cell-view.js +280 -0
- package/es/command/command-contribution.d.ts +10 -0
- package/es/command/command-contribution.d.ts.map +1 -0
- package/es/command/command-contribution.js +161 -0
- package/es/command/index.d.ts +3 -0
- package/es/command/index.d.ts.map +1 -0
- package/es/command/index.js +2 -0
- package/es/command/keybinding-contribution.d.ts +8 -0
- package/es/command/keybinding-contribution.d.ts.map +1 -0
- package/es/command/keybinding-contribution.js +37 -0
- package/es/components/cell-execution-tip.d.ts +6 -0
- package/es/components/cell-execution-tip.d.ts.map +1 -0
- package/es/components/cell-execution-tip.js +69 -0
- package/es/components/cell-input-bottom-blank.d.ts +5 -0
- package/es/components/cell-input-bottom-blank.d.ts.map +1 -0
- package/es/components/cell-input-bottom-blank.js +21 -0
- package/es/components/icons.d.ts +5 -0
- package/es/components/icons.d.ts.map +1 -0
- package/es/components/icons.js +154 -0
- package/es/components/index.d.ts +4 -0
- package/es/components/index.d.ts.map +1 -0
- package/es/components/index.js +3 -0
- package/es/components/index.less +82 -0
- package/es/config/config-contribution.d.ts +10 -0
- package/es/config/config-contribution.d.ts.map +1 -0
- package/es/config/config-contribution.js +50 -0
- package/es/config/config.d.ts +3 -0
- package/es/config/config.d.ts.map +1 -0
- package/es/config/config.js +11 -0
- package/es/config/index.d.ts +2 -0
- package/es/config/index.d.ts.map +1 -0
- package/es/config/index.js +1 -0
- package/es/configuration/index.d.ts +3 -0
- package/es/configuration/index.d.ts.map +1 -0
- package/es/configuration/index.js +2 -0
- package/es/configuration/libro-configuration-contribution.d.ts +5 -0
- package/es/configuration/libro-configuration-contribution.d.ts.map +1 -0
- package/es/configuration/libro-configuration-contribution.js +24 -0
- package/es/configuration/libro-configuration.d.ts +3 -0
- package/es/configuration/libro-configuration.d.ts.map +1 -0
- package/es/configuration/libro-configuration.js +12 -0
- package/es/contents/content-contribution.d.ts +7 -0
- package/es/contents/content-contribution.d.ts.map +1 -0
- package/es/contents/content-contribution.js +63 -0
- package/es/contents/index.d.ts +2 -0
- package/es/contents/index.d.ts.map +1 -0
- package/es/contents/index.js +1 -0
- package/es/file/file-name-alias.d.ts +7 -0
- package/es/file/file-name-alias.d.ts.map +1 -0
- package/es/file/file-name-alias.js +26 -0
- package/es/file/file-protocol.d.ts +8 -0
- package/es/file/file-protocol.d.ts.map +1 -0
- package/es/file/file-protocol.js +7 -0
- package/es/file/file-service.d.ts +31 -0
- package/es/file/file-service.d.ts.map +1 -0
- package/es/file/file-service.js +329 -0
- package/es/file/file-tree-label-provider.d.ts +13 -0
- package/es/file/file-tree-label-provider.d.ts.map +1 -0
- package/es/file/file-tree-label-provider.js +62 -0
- package/es/file/file-view/index.d.ts +14 -0
- package/es/file/file-view/index.d.ts.map +1 -0
- package/es/file/file-view/index.js +101 -0
- package/es/file/file-view/index.less +5 -0
- package/es/file/index.d.ts +7 -0
- package/es/file/index.d.ts.map +1 -0
- package/es/file/index.js +6 -0
- package/es/file/module.d.ts +3 -0
- package/es/file/module.d.ts.map +1 -0
- package/es/file/module.js +8 -0
- package/es/file/navigatable-view.d.ts +24 -0
- package/es/file/navigatable-view.d.ts.map +1 -0
- package/es/file/navigatable-view.js +151 -0
- package/es/file/open-handler-contribution.d.ts +11 -0
- package/es/file/open-handler-contribution.d.ts.map +1 -0
- package/es/file/open-handler-contribution.js +102 -0
- package/es/index.d.ts +32 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +31 -0
- package/es/keybind-instructions/index.d.ts +6 -0
- package/es/keybind-instructions/index.d.ts.map +1 -0
- package/es/keybind-instructions/index.js +5 -0
- package/es/keybind-instructions/index.less +177 -0
- package/es/keybind-instructions/keybind-instructions-contribution.d.ts +11 -0
- package/es/keybind-instructions/keybind-instructions-contribution.d.ts.map +1 -0
- package/es/keybind-instructions/keybind-instructions-contribution.js +84 -0
- package/es/keybind-instructions/keybind-instructions-icon.d.ts +3 -0
- package/es/keybind-instructions/keybind-instructions-icon.d.ts.map +1 -0
- package/es/keybind-instructions/keybind-instructions-icon.js +23 -0
- package/es/keybind-instructions/keybind-instructions-items.d.ts +14 -0
- package/es/keybind-instructions/keybind-instructions-items.d.ts.map +1 -0
- package/es/keybind-instructions/keybind-instructions-items.js +589 -0
- package/es/keybind-instructions/keybind-instructions-view.d.ts +16 -0
- package/es/keybind-instructions/keybind-instructions-view.d.ts.map +1 -0
- package/es/keybind-instructions/keybind-instructions-view.js +224 -0
- package/es/keybind-instructions/module.d.ts +3 -0
- package/es/keybind-instructions/module.d.ts.map +1 -0
- package/es/keybind-instructions/module.js +5 -0
- package/es/libro-jupyter-file-service.d.ts +106 -0
- package/es/libro-jupyter-file-service.d.ts.map +1 -0
- package/es/libro-jupyter-file-service.js +127 -0
- package/es/libro-jupyter-model.d.ts +49 -0
- package/es/libro-jupyter-model.d.ts.map +1 -0
- package/es/libro-jupyter-model.js +505 -0
- package/es/libro-jupyter-protocol.d.ts +38 -0
- package/es/libro-jupyter-protocol.d.ts.map +1 -0
- package/es/libro-jupyter-protocol.js +9 -0
- package/es/libro-jupyter-server-launch-manager.d.ts +11 -0
- package/es/libro-jupyter-server-launch-manager.d.ts.map +1 -0
- package/es/libro-jupyter-server-launch-manager.js +59 -0
- package/es/libro-jupyter-view.d.ts +10 -0
- package/es/libro-jupyter-view.d.ts.map +1 -0
- package/es/libro-jupyter-view.js +42 -0
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +48 -0
- package/es/output/index.d.ts +2 -0
- package/es/output/index.d.ts.map +1 -0
- package/es/output/index.js +1 -0
- package/es/output/libro-jupyter-outputarea.d.ts +8 -0
- package/es/output/libro-jupyter-outputarea.d.ts.map +1 -0
- package/es/output/libro-jupyter-outputarea.js +77 -0
- package/es/rendermime/assets/plotly.svg +31 -0
- package/es/rendermime/index.d.ts +5 -0
- package/es/rendermime/index.d.ts.map +1 -0
- package/es/rendermime/index.js +4 -0
- package/es/rendermime/index.less +22 -0
- package/es/rendermime/module.d.ts +3 -0
- package/es/rendermime/module.d.ts.map +1 -0
- package/es/rendermime/module.js +3 -0
- package/es/rendermime/plotly-render.d.ts +7 -0
- package/es/rendermime/plotly-render.d.ts.map +1 -0
- package/es/rendermime/plotly-render.js +30 -0
- package/es/rendermime/plotly-renderers.d.ts +58 -0
- package/es/rendermime/plotly-renderers.d.ts.map +1 -0
- package/es/rendermime/plotly-renderers.js +211 -0
- package/es/rendermime/plotly-rendermime-contribution.d.ts +12 -0
- package/es/rendermime/plotly-rendermime-contribution.d.ts.map +1 -0
- package/es/rendermime/plotly-rendermime-contribution.js +22 -0
- package/es/theme/color-registry.d.ts +6 -0
- package/es/theme/color-registry.d.ts.map +1 -0
- package/es/theme/color-registry.js +393 -0
- package/es/theme/index.d.ts +2 -0
- package/es/theme/index.d.ts.map +1 -0
- package/es/theme/index.js +1 -0
- package/es/toolbar/index.d.ts +6 -0
- package/es/toolbar/index.d.ts.map +1 -0
- package/es/toolbar/index.js +5 -0
- package/es/toolbar/index.less +194 -0
- package/es/toolbar/kernel-selector-dropdown.d.ts +13 -0
- package/es/toolbar/kernel-selector-dropdown.d.ts.map +1 -0
- package/es/toolbar/kernel-selector-dropdown.js +165 -0
- package/es/toolbar/kernel-status-and-selector.d.ts +18 -0
- package/es/toolbar/kernel-status-and-selector.d.ts.map +1 -0
- package/es/toolbar/kernel-status-and-selector.js +164 -0
- package/es/toolbar/run-selector.d.ts +3 -0
- package/es/toolbar/run-selector.d.ts.map +1 -0
- package/es/toolbar/run-selector.js +98 -0
- package/es/toolbar/save-file-error-contribution.d.ts +5 -0
- package/es/toolbar/save-file-error-contribution.d.ts.map +1 -0
- package/es/toolbar/save-file-error-contribution.js +23 -0
- package/es/toolbar/save-file-error.d.ts +5 -0
- package/es/toolbar/save-file-error.d.ts.map +1 -0
- package/es/toolbar/save-file-error.js +27 -0
- package/es/toolbar/side-toolbar-run-selector.d.ts +3 -0
- package/es/toolbar/side-toolbar-run-selector.d.ts.map +1 -0
- package/es/toolbar/side-toolbar-run-selector.js +67 -0
- package/es/toolbar/toolbar-contribution.d.ts +9 -0
- package/es/toolbar/toolbar-contribution.d.ts.map +1 -0
- package/es/toolbar/toolbar-contribution.js +67 -0
- package/es/typings/index.d.ts +31 -0
- package/es/utils/index.d.ts +11 -0
- package/es/utils/index.d.ts.map +1 -0
- package/es/utils/index.js +47 -0
- package/package.json +75 -0
- package/src/add-between-cell/add-between-cell-command-contribution.ts +63 -0
- package/src/add-between-cell/add-between-cell.tsx +201 -0
- package/src/add-between-cell/index.less +103 -0
- package/src/add-between-cell/index.ts +2 -0
- package/src/add-between-cell/module.ts +13 -0
- package/src/cell/index.ts +2 -0
- package/src/cell/jupyter-code-cell-model.ts +36 -0
- package/src/cell/jupyter-code-cell-view.tsx +221 -0
- package/src/command/command-contribution.ts +163 -0
- package/src/command/index.ts +2 -0
- package/src/command/keybinding-contribution.ts +25 -0
- package/src/components/cell-execution-tip.tsx +107 -0
- package/src/components/cell-input-bottom-blank.tsx +24 -0
- package/src/components/icons.tsx +117 -0
- package/src/components/index.less +82 -0
- package/src/components/index.ts +3 -0
- package/src/config/config-contribution.ts +21 -0
- package/src/config/config.ts +14 -0
- package/src/config/index.ts +1 -0
- package/src/configuration/index.ts +2 -0
- package/src/configuration/libro-configuration-contribution.ts +11 -0
- package/src/configuration/libro-configuration.ts +14 -0
- package/src/contents/content-contribution.ts +32 -0
- package/src/contents/index.ts +1 -0
- package/src/file/file-name-alias.ts +15 -0
- package/src/file/file-protocol.ts +7 -0
- package/src/file/file-service.ts +179 -0
- package/src/file/file-tree-label-provider.ts +42 -0
- package/src/file/file-view/index.less +5 -0
- package/src/file/file-view/index.tsx +90 -0
- package/src/file/index.ts +6 -0
- package/src/file/module.ts +19 -0
- package/src/file/navigatable-view.tsx +93 -0
- package/src/file/open-handler-contribution.ts +44 -0
- package/src/index.ts +32 -0
- package/src/keybind-instructions/index.less +177 -0
- package/src/keybind-instructions/index.ts +5 -0
- package/src/keybind-instructions/keybind-instructions-contribution.ts +47 -0
- package/src/keybind-instructions/keybind-instructions-icon.tsx +28 -0
- package/src/keybind-instructions/keybind-instructions-items.tsx +597 -0
- package/src/keybind-instructions/keybind-instructions-view.tsx +239 -0
- package/src/keybind-instructions/module.ts +11 -0
- package/src/libro-jupyter-file-service.ts +158 -0
- package/src/libro-jupyter-model.ts +289 -0
- package/src/libro-jupyter-protocol.ts +59 -0
- package/src/libro-jupyter-server-launch-manager.ts +36 -0
- package/src/libro-jupyter-view.tsx +24 -0
- package/src/module.ts +105 -0
- package/src/output/index.ts +1 -0
- package/src/output/libro-jupyter-outputarea.tsx +71 -0
- package/src/rendermime/assets/plotly.svg +31 -0
- package/src/rendermime/index.less +13 -0
- package/src/rendermime/index.ts +4 -0
- package/src/rendermime/module.ts +7 -0
- package/src/rendermime/plotly-render.tsx +35 -0
- package/src/rendermime/plotly-renderers.ts +191 -0
- package/src/rendermime/plotly-rendermime-contribution.ts +15 -0
- package/src/theme/color-registry.ts +301 -0
- package/src/theme/index.ts +1 -0
- package/src/toolbar/index.less +194 -0
- package/src/toolbar/index.ts +5 -0
- package/src/toolbar/kernel-selector-dropdown.tsx +204 -0
- package/src/toolbar/kernel-status-and-selector.tsx +195 -0
- package/src/toolbar/run-selector.tsx +110 -0
- package/src/toolbar/save-file-error-contribution.ts +10 -0
- package/src/toolbar/save-file-error.tsx +35 -0
- package/src/toolbar/side-toolbar-run-selector.tsx +77 -0
- package/src/toolbar/toolbar-contribution.tsx +62 -0
- package/src/typings/index.d.ts +31 -0
- package/src/utils/index.ts +65 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { red, green, gold, blue } from '@ant-design/colors';
|
|
2
|
+
import { LoadingOutlined, StopOutlined } from '@ant-design/icons';
|
|
3
|
+
import type { LibroView } from '@difizen/libro-core';
|
|
4
|
+
import { ServerManager } from '@difizen/libro-kernel';
|
|
5
|
+
import { useInject, ViewInstance } from '@difizen/mana-app';
|
|
6
|
+
import { l10n } from '@difizen/mana-l10n';
|
|
7
|
+
import { Badge } from 'antd';
|
|
8
|
+
|
|
9
|
+
import { LibroJupyterModel } from '../libro-jupyter-model.js';
|
|
10
|
+
|
|
11
|
+
import { KernelSelector } from './kernel-selector-dropdown.js';
|
|
12
|
+
|
|
13
|
+
import './index.less';
|
|
14
|
+
|
|
15
|
+
export interface ServerStatus {
|
|
16
|
+
category: string;
|
|
17
|
+
color: string;
|
|
18
|
+
text: string;
|
|
19
|
+
text_zh: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const statusToColor = {
|
|
23
|
+
canRunImmediate: green[5],
|
|
24
|
+
canRun: blue[5],
|
|
25
|
+
blocking: gold[5],
|
|
26
|
+
error: red[4],
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const jupyterServiceStatus: Record<string, ServerStatus> = {
|
|
30
|
+
loading: {
|
|
31
|
+
category: 'JupyterService',
|
|
32
|
+
color: statusToColor.blocking,
|
|
33
|
+
text: 'loading',
|
|
34
|
+
text_zh: l10n.t('加载中'),
|
|
35
|
+
},
|
|
36
|
+
failed: {
|
|
37
|
+
category: 'JupyterService',
|
|
38
|
+
color: statusToColor.error,
|
|
39
|
+
text: 'failed',
|
|
40
|
+
text_zh: l10n.t('加载失败'),
|
|
41
|
+
},
|
|
42
|
+
loaded: {
|
|
43
|
+
category: 'JupyterService',
|
|
44
|
+
color: statusToColor.canRunImmediate,
|
|
45
|
+
text: 'loaded',
|
|
46
|
+
text_zh: l10n.t('加载完成'),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const kernelStatus: Record<string, ServerStatus> = {
|
|
51
|
+
connecting: {
|
|
52
|
+
category: 'Kernel',
|
|
53
|
+
color: statusToColor.blocking,
|
|
54
|
+
text: 'connecting',
|
|
55
|
+
text_zh: l10n.t('正在连接'),
|
|
56
|
+
},
|
|
57
|
+
unknown: {
|
|
58
|
+
category: 'Kernel',
|
|
59
|
+
color: statusToColor.blocking,
|
|
60
|
+
text: 'unknown',
|
|
61
|
+
text_zh: l10n.t('未知'),
|
|
62
|
+
},
|
|
63
|
+
starting: {
|
|
64
|
+
category: 'Kernel',
|
|
65
|
+
color: statusToColor.blocking,
|
|
66
|
+
text: 'starting',
|
|
67
|
+
text_zh: l10n.t('启动中'),
|
|
68
|
+
},
|
|
69
|
+
idle: {
|
|
70
|
+
category: 'Kernel',
|
|
71
|
+
color: statusToColor.canRunImmediate,
|
|
72
|
+
text: 'idle',
|
|
73
|
+
text_zh: l10n.t('空闲'),
|
|
74
|
+
},
|
|
75
|
+
busy: {
|
|
76
|
+
category: 'Kernel',
|
|
77
|
+
color: statusToColor.canRun,
|
|
78
|
+
text: 'busy',
|
|
79
|
+
text_zh: l10n.t('忙碌'),
|
|
80
|
+
},
|
|
81
|
+
terminating: {
|
|
82
|
+
category: 'Kernel',
|
|
83
|
+
color: statusToColor.blocking,
|
|
84
|
+
text: 'terminating',
|
|
85
|
+
text_zh: l10n.t('终止中'),
|
|
86
|
+
},
|
|
87
|
+
restarting: {
|
|
88
|
+
category: 'Kernel',
|
|
89
|
+
color: statusToColor.blocking,
|
|
90
|
+
text: 'restarting',
|
|
91
|
+
text_zh: l10n.t('重启中'),
|
|
92
|
+
},
|
|
93
|
+
autorestarting: {
|
|
94
|
+
category: 'Kernel',
|
|
95
|
+
color: statusToColor.blocking,
|
|
96
|
+
text: 'autorestarting',
|
|
97
|
+
text_zh: l10n.t('自动重启中'),
|
|
98
|
+
},
|
|
99
|
+
dead: {
|
|
100
|
+
category: 'Kernel',
|
|
101
|
+
color: statusToColor.error,
|
|
102
|
+
text: 'dead',
|
|
103
|
+
text_zh: l10n.t('死亡'),
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const getServiceStatusInfo = (
|
|
108
|
+
serverManager: ServerManager | undefined,
|
|
109
|
+
libroModel: LibroJupyterModel | undefined,
|
|
110
|
+
): ServerStatus => {
|
|
111
|
+
if (!serverManager || serverManager.launching) {
|
|
112
|
+
return jupyterServiceStatus['loading'];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (
|
|
116
|
+
!libroModel ||
|
|
117
|
+
!(libroModel instanceof LibroJupyterModel) ||
|
|
118
|
+
libroModel.kernelConnecting === true ||
|
|
119
|
+
libroModel.kernelConnecting === undefined
|
|
120
|
+
) {
|
|
121
|
+
return kernelStatus['connecting'];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (!libroModel.kernelConnection) {
|
|
125
|
+
return {
|
|
126
|
+
color: statusToColor.blocking,
|
|
127
|
+
text: 'no kernel',
|
|
128
|
+
category: 'Kernel',
|
|
129
|
+
text_zh: l10n.t('无内核'),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return kernelStatus[libroModel.kernelConnection.status];
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export const KernelStatusSelector: React.FC = () => {
|
|
137
|
+
const libroView = useInject<LibroView>(ViewInstance);
|
|
138
|
+
const serverManager = useInject(ServerManager);
|
|
139
|
+
const libroModel = libroView?.model as LibroJupyterModel;
|
|
140
|
+
const { color, text, text_zh, category } = getServiceStatusInfo(
|
|
141
|
+
serverManager,
|
|
142
|
+
libroModel,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
if (serverManager.loaded) {
|
|
146
|
+
const showBadge =
|
|
147
|
+
(libroModel.kernelConnection && !libroModel.kernelConnection.isDisposed) ||
|
|
148
|
+
text === 'connecting';
|
|
149
|
+
const isKernelBusy = text === 'unknown' || text === 'busy';
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<div className="libro-kernel-and-container-status">
|
|
153
|
+
<div className="libro-kernel-status-and-selector">
|
|
154
|
+
<span className="kernel">kernel:</span>
|
|
155
|
+
<KernelSelector />
|
|
156
|
+
{showBadge &&
|
|
157
|
+
(isKernelBusy ? (
|
|
158
|
+
<Badge
|
|
159
|
+
className="libro-kernel-badge"
|
|
160
|
+
key="libro-kernel-badge"
|
|
161
|
+
color={kernelStatus['busy'].color}
|
|
162
|
+
text={kernelStatus['busy'].text_zh}
|
|
163
|
+
/>
|
|
164
|
+
) : (
|
|
165
|
+
<Badge
|
|
166
|
+
className="libro-kernel-badge"
|
|
167
|
+
key="libro-kernel-badge"
|
|
168
|
+
color={color}
|
|
169
|
+
text={text_zh}
|
|
170
|
+
/>
|
|
171
|
+
))}
|
|
172
|
+
</div>
|
|
173
|
+
</div>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return (
|
|
178
|
+
<div className="libro-kernel-and-container-status">
|
|
179
|
+
<div className="libro-container-and-service-status">
|
|
180
|
+
{text !== 'failed' && (
|
|
181
|
+
<>
|
|
182
|
+
<LoadingOutlined className="loading-icon" />
|
|
183
|
+
<span className="no-kernel">{l10n.t('Kernel 准备中...')}</span>
|
|
184
|
+
</>
|
|
185
|
+
)}
|
|
186
|
+
{text === 'failed' && category === 'JupyterService' && (
|
|
187
|
+
<>
|
|
188
|
+
<StopOutlined className="failed-icon" />
|
|
189
|
+
<span className="kernel-prepare-failed">{l10n.t('Kernel 准备失败')}</span>
|
|
190
|
+
</>
|
|
191
|
+
)}
|
|
192
|
+
</div>
|
|
193
|
+
</div>
|
|
194
|
+
);
|
|
195
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { PlayCircleOutlined } from '@ant-design/icons';
|
|
2
|
+
import type { LibroToolbarArags, LibroView } from '@difizen/libro-core';
|
|
3
|
+
import { NotebookCommands, ExecutableCellModel } from '@difizen/libro-core';
|
|
4
|
+
import {
|
|
5
|
+
useInject,
|
|
6
|
+
ToolbarInstance,
|
|
7
|
+
getOrigin,
|
|
8
|
+
CommandRegistry,
|
|
9
|
+
ViewInstance,
|
|
10
|
+
} from '@difizen/mana-app';
|
|
11
|
+
import type { Toolbar } from '@difizen/mana-app';
|
|
12
|
+
import { l10n } from '@difizen/mana-l10n';
|
|
13
|
+
import { Menu, Dropdown, Tooltip } from 'antd';
|
|
14
|
+
import type { MenuProps } from 'antd';
|
|
15
|
+
|
|
16
|
+
import type { LibroJupyterModel } from '../libro-jupyter-model.js';
|
|
17
|
+
|
|
18
|
+
export const RunSelector: React.FC = () => {
|
|
19
|
+
const libroView = useInject<LibroView>(ViewInstance);
|
|
20
|
+
const libroModel = libroView ? libroView.model : undefined;
|
|
21
|
+
const toolbar = useInject<Toolbar>(ToolbarInstance);
|
|
22
|
+
const data = toolbar.currentArgs as LibroToolbarArags;
|
|
23
|
+
const command = useInject(CommandRegistry);
|
|
24
|
+
const curCell = data?.[0];
|
|
25
|
+
const isRunVisible =
|
|
26
|
+
ExecutableCellModel.is(curCell?.model) && !curCell?.model.executing ? true : false;
|
|
27
|
+
const isKernelIdle = libroModel
|
|
28
|
+
? (libroModel as LibroJupyterModel).isKernelIdle
|
|
29
|
+
: false;
|
|
30
|
+
|
|
31
|
+
const handleChange: MenuProps['onClick'] = (e) => {
|
|
32
|
+
const args = getOrigin(data) || [];
|
|
33
|
+
if (e.key === 'runCell') {
|
|
34
|
+
command.executeCommand(NotebookCommands['RunCell'].id, ...args);
|
|
35
|
+
} else if (e.key === 'runAllCell') {
|
|
36
|
+
command.executeCommand(NotebookCommands['RunAllCells'].id, ...args);
|
|
37
|
+
} else if (e.key === 'runAllAbove') {
|
|
38
|
+
command.executeCommand(NotebookCommands['RunAllAbove'].id, ...args);
|
|
39
|
+
} else if (e.key === 'runAllBelow') {
|
|
40
|
+
command.executeCommand(NotebookCommands['RunAllBelow'].id, ...args);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const menu = (
|
|
45
|
+
<Menu
|
|
46
|
+
className="libro-run-menu-container"
|
|
47
|
+
onClick={handleChange}
|
|
48
|
+
items={[
|
|
49
|
+
{
|
|
50
|
+
key: 'runCell',
|
|
51
|
+
label: (
|
|
52
|
+
<>
|
|
53
|
+
<span className="libro-run-menu-label">{l10n.t('运行当前Cell')}</span>
|
|
54
|
+
<span className="libro-run-menu-keybind">Cmd + Enter</span>
|
|
55
|
+
</>
|
|
56
|
+
),
|
|
57
|
+
|
|
58
|
+
disabled: !isRunVisible,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
key: 'runAllCell',
|
|
62
|
+
label: (
|
|
63
|
+
<>
|
|
64
|
+
<span className="libro-run-menu-label">{l10n.t('运行全部')}</span>
|
|
65
|
+
<span className="libro-run-menu-keybind" />
|
|
66
|
+
</>
|
|
67
|
+
),
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
key: 'runAllAbove',
|
|
71
|
+
label: (
|
|
72
|
+
<>
|
|
73
|
+
<span className="libro-run-menu-label">{l10n.t('运行之前所有cell')}</span>
|
|
74
|
+
<span className="libro-run-menu-keybind">Cmd + F8</span>
|
|
75
|
+
</>
|
|
76
|
+
),
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
key: 'runAllBelow',
|
|
80
|
+
label: (
|
|
81
|
+
<>
|
|
82
|
+
<span className="libro-run-menu-label">
|
|
83
|
+
{l10n.t('运行当前及之后cell')}
|
|
84
|
+
</span>
|
|
85
|
+
<span className="libro-run-menu-keybind">Cmd + F10</span>
|
|
86
|
+
</>
|
|
87
|
+
),
|
|
88
|
+
},
|
|
89
|
+
]}
|
|
90
|
+
/>
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
if (isKernelIdle) {
|
|
94
|
+
return (
|
|
95
|
+
<Dropdown overlay={menu} placement="bottomLeft">
|
|
96
|
+
<PlayCircleOutlined />
|
|
97
|
+
</Dropdown>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<Tooltip
|
|
103
|
+
overlayClassName="libro-tooltip-placement-bottom"
|
|
104
|
+
placement="bottom"
|
|
105
|
+
title={l10n.t('kernel准备中,无法执行')}
|
|
106
|
+
>
|
|
107
|
+
<PlayCircleOutlined />
|
|
108
|
+
</Tooltip>
|
|
109
|
+
);
|
|
110
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ModalContribution, singleton } from '@difizen/mana-app';
|
|
2
|
+
|
|
3
|
+
import { SaveFileErrorModal } from './save-file-error.js';
|
|
4
|
+
|
|
5
|
+
@singleton({ contrib: ModalContribution })
|
|
6
|
+
export class SaveFileErrorContribution implements ModalContribution {
|
|
7
|
+
registerModal() {
|
|
8
|
+
return SaveFileErrorModal;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { LibroView } from '@difizen/libro-core';
|
|
2
|
+
import type { ModalItemProps, ModalItem } from '@difizen/mana-app';
|
|
3
|
+
import { useInject, ViewInstance } from '@difizen/mana-app';
|
|
4
|
+
import { Modal } from 'antd';
|
|
5
|
+
|
|
6
|
+
import type { LibroJupyterModel } from '../libro-jupyter-model.js';
|
|
7
|
+
|
|
8
|
+
export const SaveFileModalComponent: React.FC<ModalItemProps<void>> = ({
|
|
9
|
+
visible,
|
|
10
|
+
close,
|
|
11
|
+
}: ModalItemProps<void>) => {
|
|
12
|
+
const libroView = useInject<LibroView>(ViewInstance);
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<Modal
|
|
16
|
+
title="File Save Error"
|
|
17
|
+
open={visible}
|
|
18
|
+
onOk={() => close()}
|
|
19
|
+
onCancel={() => close()}
|
|
20
|
+
width={'400px'}
|
|
21
|
+
centered={true}
|
|
22
|
+
>
|
|
23
|
+
<p>{`File Save Error for: "${
|
|
24
|
+
libroView && libroView.model
|
|
25
|
+
? (libroView.model as LibroJupyterModel).currentFileContents.name
|
|
26
|
+
: ''
|
|
27
|
+
}"`}</p>
|
|
28
|
+
</Modal>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const SaveFileErrorModal: ModalItem = {
|
|
33
|
+
id: 'save-file-error',
|
|
34
|
+
component: SaveFileModalComponent,
|
|
35
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { PlayCircleOutlined } from '@ant-design/icons';
|
|
2
|
+
import type { LibroSideToolbarMenuItemType, LibroView } from '@difizen/libro-core';
|
|
3
|
+
import { NotebookCommands, LibroSideToolbarMenu } from '@difizen/libro-core';
|
|
4
|
+
import { useInject, ViewInstance } from '@difizen/mana-app';
|
|
5
|
+
import { l10n } from '@difizen/mana-l10n';
|
|
6
|
+
import { Popover, Tooltip } from 'antd';
|
|
7
|
+
|
|
8
|
+
import type { LibroJupyterModel } from '../libro-jupyter-model.js';
|
|
9
|
+
|
|
10
|
+
const items: LibroSideToolbarMenuItemType[] = [
|
|
11
|
+
{
|
|
12
|
+
id: NotebookCommands['RunCell'].id,
|
|
13
|
+
label: (
|
|
14
|
+
<>
|
|
15
|
+
<span className="libro-menu-item-label">{l10n.t('运行 Cell')}</span>
|
|
16
|
+
<span className="libro-menu-item-keybind">Cmd + Enter</span>
|
|
17
|
+
</>
|
|
18
|
+
),
|
|
19
|
+
|
|
20
|
+
group: 'runCell1',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: NotebookCommands['RunAllAbove'].id,
|
|
24
|
+
label: (
|
|
25
|
+
<>
|
|
26
|
+
<span className="libro-menu-item-label">{l10n.t('运行上方所有 Cell')}</span>
|
|
27
|
+
<span className="libro-menu-item-keybind">Cmd + F8</span>
|
|
28
|
+
</>
|
|
29
|
+
),
|
|
30
|
+
|
|
31
|
+
group: 'runCell2',
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: NotebookCommands['RunAllBelow'].id,
|
|
35
|
+
label: (
|
|
36
|
+
<>
|
|
37
|
+
<span className="libro-menu-item-label">
|
|
38
|
+
{l10n.t('运行当前及下方所有 Cell')}
|
|
39
|
+
</span>
|
|
40
|
+
<span className="libro-menu-item-keybind">Cmd + F10</span>
|
|
41
|
+
</>
|
|
42
|
+
),
|
|
43
|
+
|
|
44
|
+
group: 'runCell2',
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
export const SideToolbarRunSelector: React.FC = () => {
|
|
49
|
+
const libroView = useInject<LibroView>(ViewInstance);
|
|
50
|
+
const libroModel = libroView ? libroView.model : undefined;
|
|
51
|
+
const isKernelIdle = libroModel
|
|
52
|
+
? (libroModel as LibroJupyterModel).isKernelIdle
|
|
53
|
+
: false;
|
|
54
|
+
|
|
55
|
+
if (isKernelIdle) {
|
|
56
|
+
return (
|
|
57
|
+
<Popover
|
|
58
|
+
placement="leftTop"
|
|
59
|
+
content={<LibroSideToolbarMenu items={items} />}
|
|
60
|
+
trigger="hover"
|
|
61
|
+
overlayClassName="libro-popover-side-toolbar-menu libro-side-toolbar-run-select-menu"
|
|
62
|
+
>
|
|
63
|
+
<PlayCircleOutlined />
|
|
64
|
+
</Popover>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<Tooltip
|
|
70
|
+
overlayClassName="libro-tooltip-placement-right"
|
|
71
|
+
placement="right"
|
|
72
|
+
title={l10n.t('kernel准备中,无法执行')}
|
|
73
|
+
>
|
|
74
|
+
<PlayCircleOutlined />
|
|
75
|
+
</Tooltip>
|
|
76
|
+
);
|
|
77
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { KernelCommands, NotebookCommands } from '@difizen/libro-core';
|
|
2
|
+
import type { ToolbarRegistry } from '@difizen/mana-app';
|
|
3
|
+
import { singleton, inject, ToolbarContribution } from '@difizen/mana-app';
|
|
4
|
+
import { l10n } from '@difizen/mana-l10n';
|
|
5
|
+
|
|
6
|
+
import { Location } from '../components/icons.js';
|
|
7
|
+
import { KernelStatusAndSelectorProvider } from '../libro-jupyter-protocol.js';
|
|
8
|
+
|
|
9
|
+
import { RunSelector } from './run-selector.js';
|
|
10
|
+
import { SideToolbarRunSelector } from './side-toolbar-run-selector.js';
|
|
11
|
+
|
|
12
|
+
@singleton({ contrib: ToolbarContribution })
|
|
13
|
+
export class LibroJupyterToolbarContribution implements ToolbarContribution {
|
|
14
|
+
kernelStatusAndSelector: KernelStatusAndSelectorProvider;
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
@inject(KernelStatusAndSelectorProvider)
|
|
18
|
+
kernelStatusAndSelector: KernelStatusAndSelectorProvider,
|
|
19
|
+
) {
|
|
20
|
+
this.kernelStatusAndSelector = kernelStatusAndSelector;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
registerToolbarItems(registry: ToolbarRegistry): void {
|
|
24
|
+
registry.registerItem({
|
|
25
|
+
id: KernelCommands['ShowKernelStatusAndSelector'].id,
|
|
26
|
+
icon: this.kernelStatusAndSelector,
|
|
27
|
+
command: KernelCommands['ShowKernelStatusAndSelector'].id,
|
|
28
|
+
order: 'o',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
registry.registerItem({
|
|
32
|
+
id: NotebookCommands['SideToolbarRunSelect'].id,
|
|
33
|
+
command: NotebookCommands['SideToolbarRunSelect'].id,
|
|
34
|
+
icon: SideToolbarRunSelector,
|
|
35
|
+
showLabelInline: true,
|
|
36
|
+
group: ['sidetoolbar1'],
|
|
37
|
+
order: 'a',
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
registry.registerItem({
|
|
41
|
+
id: NotebookCommands['TopToolbarRunSelect'].id,
|
|
42
|
+
command: NotebookCommands['TopToolbarRunSelect'].id,
|
|
43
|
+
icon: RunSelector,
|
|
44
|
+
showLabelInline: true,
|
|
45
|
+
group: ['group2'],
|
|
46
|
+
order: 'a',
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
registry.registerItem({
|
|
50
|
+
id: NotebookCommands['SelectLastRunCell'].id,
|
|
51
|
+
icon: Location,
|
|
52
|
+
command: NotebookCommands['SelectLastRunCell'].id,
|
|
53
|
+
group: ['group2'],
|
|
54
|
+
order: 'b',
|
|
55
|
+
tooltip: (
|
|
56
|
+
<div className="libro-tooltip">
|
|
57
|
+
<span className="libro-tooltip-text">{l10n.t('定位正在执行的Cell')}</span>
|
|
58
|
+
</div>
|
|
59
|
+
),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
declare module '*.less';
|
|
2
|
+
|
|
3
|
+
declare module 'plotly.js' {
|
|
4
|
+
export type Frame = Record<string, any>;
|
|
5
|
+
export function addFrames(root: Plotly.Root, frames: Frame[]): Promise<void>;
|
|
6
|
+
export function animate(root: Plotly.Root): void;
|
|
7
|
+
export type Data = any;
|
|
8
|
+
export type Layout = any;
|
|
9
|
+
|
|
10
|
+
type PlotlyEvent =
|
|
11
|
+
| 'plotly_webglcontextlost'
|
|
12
|
+
| 'plotly_restyle'
|
|
13
|
+
| 'plotly_relayout'
|
|
14
|
+
| 'plotly_update'
|
|
15
|
+
| 'plotly_click'
|
|
16
|
+
| 'plotly_hover'
|
|
17
|
+
| 'plotly_unhover'
|
|
18
|
+
| 'plotly_selected'
|
|
19
|
+
| 'plotly_deselect'
|
|
20
|
+
| 'plotly_doubleclick';
|
|
21
|
+
|
|
22
|
+
export interface PlotlyHTMLElement extends HTMLElement {
|
|
23
|
+
_fullData: Data;
|
|
24
|
+
_fullLayout: Layout;
|
|
25
|
+
data: Data;
|
|
26
|
+
layout: Layout;
|
|
27
|
+
on(event: PlotlyEvent, callback: (update: any) => void): void;
|
|
28
|
+
}
|
|
29
|
+
export function react(node: HTMLElement, data: any, layout: any, config: any): void;
|
|
30
|
+
export function toImage(...args: any[]): Promise<string>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { CellModel } from '@difizen/libro-core';
|
|
2
|
+
import { duration } from 'moment';
|
|
3
|
+
|
|
4
|
+
import type { LibroJupyterModel } from '../libro-jupyter-model.js';
|
|
5
|
+
import type { ExecutedWithKernelCellModel } from '../libro-jupyter-protocol.js';
|
|
6
|
+
|
|
7
|
+
export const EXECUTE_INPUT = 'to_execute'; // 用户点击执行按钮的时间
|
|
8
|
+
export const EXECUTE_REPLY_START = 'shell.execute_reply.started'; // Kernel 开始执行任务时间在 metadata 中的 key
|
|
9
|
+
export const EXECUTE_REPLY_REPLY = 'shell.execute_reply.end'; // Kernel 结束执行任务时间在 metadata 中的 key
|
|
10
|
+
|
|
11
|
+
export function getDefaultKernel(): string {
|
|
12
|
+
return 'Python 3';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const isWaitingExecute = (model: CellModel) => {
|
|
16
|
+
const { executing, kernelExecuting } =
|
|
17
|
+
model as unknown as ExecutedWithKernelCellModel;
|
|
18
|
+
return !kernelExecuting && executing;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function formatTime(value: number): string {
|
|
22
|
+
const time = duration(value);
|
|
23
|
+
const hours = time.hours();
|
|
24
|
+
const minutes = time.minutes();
|
|
25
|
+
const seconds = time.seconds();
|
|
26
|
+
const milliseconds = ('000' + time.milliseconds()).substr(-3);
|
|
27
|
+
|
|
28
|
+
if (hours >= 1) {
|
|
29
|
+
return hours + 'h ' + minutes + 'min ' + seconds + 's ' + milliseconds + 'ms';
|
|
30
|
+
} else if (minutes >= 1) {
|
|
31
|
+
return minutes + 'min ' + seconds + 's ' + milliseconds + 'ms';
|
|
32
|
+
} else if (seconds >= 1) {
|
|
33
|
+
return seconds + 's ' + milliseconds + 'ms';
|
|
34
|
+
} else {
|
|
35
|
+
return milliseconds + 'ms';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function parseExecutionInfoFromModel(
|
|
40
|
+
model: CellModel,
|
|
41
|
+
): Record<string, string> | undefined {
|
|
42
|
+
const executionInfo: Record<string, string> = model.metadata['execution'] as Record<
|
|
43
|
+
string,
|
|
44
|
+
string
|
|
45
|
+
>;
|
|
46
|
+
if (executionInfo) {
|
|
47
|
+
const toExecuteTime = executionInfo[EXECUTE_INPUT]; // 用户点击执行按钮的时间
|
|
48
|
+
const executeStartTime = executionInfo[EXECUTE_REPLY_START]; // Kernel 开始执行任务时间
|
|
49
|
+
const executeFinishTime = executionInfo[EXECUTE_REPLY_REPLY]; // Kernel 结束执行任务时间
|
|
50
|
+
return {
|
|
51
|
+
toExecuteTime,
|
|
52
|
+
executeStartTime,
|
|
53
|
+
executeFinishTime,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function isKernelIdle(libroModel?: LibroJupyterModel): boolean {
|
|
60
|
+
return !!(
|
|
61
|
+
libroModel &&
|
|
62
|
+
libroModel.kernelConnection &&
|
|
63
|
+
libroModel.kernelConnection.status === 'idle'
|
|
64
|
+
);
|
|
65
|
+
}
|