@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.
Files changed (267) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/es/add-between-cell/add-between-cell-command-contribution.d.ts +14 -0
  4. package/es/add-between-cell/add-between-cell-command-contribution.d.ts.map +1 -0
  5. package/es/add-between-cell/add-between-cell-command-contribution.js +97 -0
  6. package/es/add-between-cell/add-between-cell.d.ts +5 -0
  7. package/es/add-between-cell/add-between-cell.d.ts.map +1 -0
  8. package/es/add-between-cell/add-between-cell.js +243 -0
  9. package/es/add-between-cell/index.d.ts +3 -0
  10. package/es/add-between-cell/index.d.ts.map +1 -0
  11. package/es/add-between-cell/index.js +2 -0
  12. package/es/add-between-cell/index.less +103 -0
  13. package/es/add-between-cell/module.d.ts +3 -0
  14. package/es/add-between-cell/module.d.ts.map +1 -0
  15. package/es/add-between-cell/module.js +8 -0
  16. package/es/cell/index.d.ts +3 -0
  17. package/es/cell/index.d.ts.map +1 -0
  18. package/es/cell/index.js +2 -0
  19. package/es/cell/jupyter-code-cell-model.d.ts +12 -0
  20. package/es/cell/jupyter-code-cell-model.d.ts.map +1 -0
  21. package/es/cell/jupyter-code-cell-model.js +56 -0
  22. package/es/cell/jupyter-code-cell-view.d.ts +18 -0
  23. package/es/cell/jupyter-code-cell-view.d.ts.map +1 -0
  24. package/es/cell/jupyter-code-cell-view.js +280 -0
  25. package/es/command/command-contribution.d.ts +10 -0
  26. package/es/command/command-contribution.d.ts.map +1 -0
  27. package/es/command/command-contribution.js +161 -0
  28. package/es/command/index.d.ts +3 -0
  29. package/es/command/index.d.ts.map +1 -0
  30. package/es/command/index.js +2 -0
  31. package/es/command/keybinding-contribution.d.ts +8 -0
  32. package/es/command/keybinding-contribution.d.ts.map +1 -0
  33. package/es/command/keybinding-contribution.js +37 -0
  34. package/es/components/cell-execution-tip.d.ts +6 -0
  35. package/es/components/cell-execution-tip.d.ts.map +1 -0
  36. package/es/components/cell-execution-tip.js +69 -0
  37. package/es/components/cell-input-bottom-blank.d.ts +5 -0
  38. package/es/components/cell-input-bottom-blank.d.ts.map +1 -0
  39. package/es/components/cell-input-bottom-blank.js +21 -0
  40. package/es/components/icons.d.ts +5 -0
  41. package/es/components/icons.d.ts.map +1 -0
  42. package/es/components/icons.js +154 -0
  43. package/es/components/index.d.ts +4 -0
  44. package/es/components/index.d.ts.map +1 -0
  45. package/es/components/index.js +3 -0
  46. package/es/components/index.less +82 -0
  47. package/es/config/config-contribution.d.ts +10 -0
  48. package/es/config/config-contribution.d.ts.map +1 -0
  49. package/es/config/config-contribution.js +50 -0
  50. package/es/config/config.d.ts +3 -0
  51. package/es/config/config.d.ts.map +1 -0
  52. package/es/config/config.js +11 -0
  53. package/es/config/index.d.ts +2 -0
  54. package/es/config/index.d.ts.map +1 -0
  55. package/es/config/index.js +1 -0
  56. package/es/configuration/index.d.ts +3 -0
  57. package/es/configuration/index.d.ts.map +1 -0
  58. package/es/configuration/index.js +2 -0
  59. package/es/configuration/libro-configuration-contribution.d.ts +5 -0
  60. package/es/configuration/libro-configuration-contribution.d.ts.map +1 -0
  61. package/es/configuration/libro-configuration-contribution.js +24 -0
  62. package/es/configuration/libro-configuration.d.ts +3 -0
  63. package/es/configuration/libro-configuration.d.ts.map +1 -0
  64. package/es/configuration/libro-configuration.js +12 -0
  65. package/es/contents/content-contribution.d.ts +7 -0
  66. package/es/contents/content-contribution.d.ts.map +1 -0
  67. package/es/contents/content-contribution.js +63 -0
  68. package/es/contents/index.d.ts +2 -0
  69. package/es/contents/index.d.ts.map +1 -0
  70. package/es/contents/index.js +1 -0
  71. package/es/file/file-name-alias.d.ts +7 -0
  72. package/es/file/file-name-alias.d.ts.map +1 -0
  73. package/es/file/file-name-alias.js +26 -0
  74. package/es/file/file-protocol.d.ts +8 -0
  75. package/es/file/file-protocol.d.ts.map +1 -0
  76. package/es/file/file-protocol.js +7 -0
  77. package/es/file/file-service.d.ts +31 -0
  78. package/es/file/file-service.d.ts.map +1 -0
  79. package/es/file/file-service.js +329 -0
  80. package/es/file/file-tree-label-provider.d.ts +13 -0
  81. package/es/file/file-tree-label-provider.d.ts.map +1 -0
  82. package/es/file/file-tree-label-provider.js +62 -0
  83. package/es/file/file-view/index.d.ts +14 -0
  84. package/es/file/file-view/index.d.ts.map +1 -0
  85. package/es/file/file-view/index.js +101 -0
  86. package/es/file/file-view/index.less +5 -0
  87. package/es/file/index.d.ts +7 -0
  88. package/es/file/index.d.ts.map +1 -0
  89. package/es/file/index.js +6 -0
  90. package/es/file/module.d.ts +3 -0
  91. package/es/file/module.d.ts.map +1 -0
  92. package/es/file/module.js +8 -0
  93. package/es/file/navigatable-view.d.ts +24 -0
  94. package/es/file/navigatable-view.d.ts.map +1 -0
  95. package/es/file/navigatable-view.js +151 -0
  96. package/es/file/open-handler-contribution.d.ts +11 -0
  97. package/es/file/open-handler-contribution.d.ts.map +1 -0
  98. package/es/file/open-handler-contribution.js +102 -0
  99. package/es/index.d.ts +32 -0
  100. package/es/index.d.ts.map +1 -0
  101. package/es/index.js +31 -0
  102. package/es/keybind-instructions/index.d.ts +6 -0
  103. package/es/keybind-instructions/index.d.ts.map +1 -0
  104. package/es/keybind-instructions/index.js +5 -0
  105. package/es/keybind-instructions/index.less +177 -0
  106. package/es/keybind-instructions/keybind-instructions-contribution.d.ts +11 -0
  107. package/es/keybind-instructions/keybind-instructions-contribution.d.ts.map +1 -0
  108. package/es/keybind-instructions/keybind-instructions-contribution.js +84 -0
  109. package/es/keybind-instructions/keybind-instructions-icon.d.ts +3 -0
  110. package/es/keybind-instructions/keybind-instructions-icon.d.ts.map +1 -0
  111. package/es/keybind-instructions/keybind-instructions-icon.js +23 -0
  112. package/es/keybind-instructions/keybind-instructions-items.d.ts +14 -0
  113. package/es/keybind-instructions/keybind-instructions-items.d.ts.map +1 -0
  114. package/es/keybind-instructions/keybind-instructions-items.js +589 -0
  115. package/es/keybind-instructions/keybind-instructions-view.d.ts +16 -0
  116. package/es/keybind-instructions/keybind-instructions-view.d.ts.map +1 -0
  117. package/es/keybind-instructions/keybind-instructions-view.js +224 -0
  118. package/es/keybind-instructions/module.d.ts +3 -0
  119. package/es/keybind-instructions/module.d.ts.map +1 -0
  120. package/es/keybind-instructions/module.js +5 -0
  121. package/es/libro-jupyter-file-service.d.ts +106 -0
  122. package/es/libro-jupyter-file-service.d.ts.map +1 -0
  123. package/es/libro-jupyter-file-service.js +127 -0
  124. package/es/libro-jupyter-model.d.ts +49 -0
  125. package/es/libro-jupyter-model.d.ts.map +1 -0
  126. package/es/libro-jupyter-model.js +505 -0
  127. package/es/libro-jupyter-protocol.d.ts +38 -0
  128. package/es/libro-jupyter-protocol.d.ts.map +1 -0
  129. package/es/libro-jupyter-protocol.js +9 -0
  130. package/es/libro-jupyter-server-launch-manager.d.ts +11 -0
  131. package/es/libro-jupyter-server-launch-manager.d.ts.map +1 -0
  132. package/es/libro-jupyter-server-launch-manager.js +59 -0
  133. package/es/libro-jupyter-view.d.ts +10 -0
  134. package/es/libro-jupyter-view.d.ts.map +1 -0
  135. package/es/libro-jupyter-view.js +42 -0
  136. package/es/module.d.ts +3 -0
  137. package/es/module.d.ts.map +1 -0
  138. package/es/module.js +48 -0
  139. package/es/output/index.d.ts +2 -0
  140. package/es/output/index.d.ts.map +1 -0
  141. package/es/output/index.js +1 -0
  142. package/es/output/libro-jupyter-outputarea.d.ts +8 -0
  143. package/es/output/libro-jupyter-outputarea.d.ts.map +1 -0
  144. package/es/output/libro-jupyter-outputarea.js +77 -0
  145. package/es/rendermime/assets/plotly.svg +31 -0
  146. package/es/rendermime/index.d.ts +5 -0
  147. package/es/rendermime/index.d.ts.map +1 -0
  148. package/es/rendermime/index.js +4 -0
  149. package/es/rendermime/index.less +22 -0
  150. package/es/rendermime/module.d.ts +3 -0
  151. package/es/rendermime/module.d.ts.map +1 -0
  152. package/es/rendermime/module.js +3 -0
  153. package/es/rendermime/plotly-render.d.ts +7 -0
  154. package/es/rendermime/plotly-render.d.ts.map +1 -0
  155. package/es/rendermime/plotly-render.js +30 -0
  156. package/es/rendermime/plotly-renderers.d.ts +58 -0
  157. package/es/rendermime/plotly-renderers.d.ts.map +1 -0
  158. package/es/rendermime/plotly-renderers.js +211 -0
  159. package/es/rendermime/plotly-rendermime-contribution.d.ts +12 -0
  160. package/es/rendermime/plotly-rendermime-contribution.d.ts.map +1 -0
  161. package/es/rendermime/plotly-rendermime-contribution.js +22 -0
  162. package/es/theme/color-registry.d.ts +6 -0
  163. package/es/theme/color-registry.d.ts.map +1 -0
  164. package/es/theme/color-registry.js +393 -0
  165. package/es/theme/index.d.ts +2 -0
  166. package/es/theme/index.d.ts.map +1 -0
  167. package/es/theme/index.js +1 -0
  168. package/es/toolbar/index.d.ts +6 -0
  169. package/es/toolbar/index.d.ts.map +1 -0
  170. package/es/toolbar/index.js +5 -0
  171. package/es/toolbar/index.less +194 -0
  172. package/es/toolbar/kernel-selector-dropdown.d.ts +13 -0
  173. package/es/toolbar/kernel-selector-dropdown.d.ts.map +1 -0
  174. package/es/toolbar/kernel-selector-dropdown.js +165 -0
  175. package/es/toolbar/kernel-status-and-selector.d.ts +18 -0
  176. package/es/toolbar/kernel-status-and-selector.d.ts.map +1 -0
  177. package/es/toolbar/kernel-status-and-selector.js +164 -0
  178. package/es/toolbar/run-selector.d.ts +3 -0
  179. package/es/toolbar/run-selector.d.ts.map +1 -0
  180. package/es/toolbar/run-selector.js +98 -0
  181. package/es/toolbar/save-file-error-contribution.d.ts +5 -0
  182. package/es/toolbar/save-file-error-contribution.d.ts.map +1 -0
  183. package/es/toolbar/save-file-error-contribution.js +23 -0
  184. package/es/toolbar/save-file-error.d.ts +5 -0
  185. package/es/toolbar/save-file-error.d.ts.map +1 -0
  186. package/es/toolbar/save-file-error.js +27 -0
  187. package/es/toolbar/side-toolbar-run-selector.d.ts +3 -0
  188. package/es/toolbar/side-toolbar-run-selector.d.ts.map +1 -0
  189. package/es/toolbar/side-toolbar-run-selector.js +67 -0
  190. package/es/toolbar/toolbar-contribution.d.ts +9 -0
  191. package/es/toolbar/toolbar-contribution.d.ts.map +1 -0
  192. package/es/toolbar/toolbar-contribution.js +67 -0
  193. package/es/typings/index.d.ts +31 -0
  194. package/es/utils/index.d.ts +11 -0
  195. package/es/utils/index.d.ts.map +1 -0
  196. package/es/utils/index.js +47 -0
  197. package/package.json +75 -0
  198. package/src/add-between-cell/add-between-cell-command-contribution.ts +63 -0
  199. package/src/add-between-cell/add-between-cell.tsx +201 -0
  200. package/src/add-between-cell/index.less +103 -0
  201. package/src/add-between-cell/index.ts +2 -0
  202. package/src/add-between-cell/module.ts +13 -0
  203. package/src/cell/index.ts +2 -0
  204. package/src/cell/jupyter-code-cell-model.ts +36 -0
  205. package/src/cell/jupyter-code-cell-view.tsx +221 -0
  206. package/src/command/command-contribution.ts +163 -0
  207. package/src/command/index.ts +2 -0
  208. package/src/command/keybinding-contribution.ts +25 -0
  209. package/src/components/cell-execution-tip.tsx +107 -0
  210. package/src/components/cell-input-bottom-blank.tsx +24 -0
  211. package/src/components/icons.tsx +117 -0
  212. package/src/components/index.less +82 -0
  213. package/src/components/index.ts +3 -0
  214. package/src/config/config-contribution.ts +21 -0
  215. package/src/config/config.ts +14 -0
  216. package/src/config/index.ts +1 -0
  217. package/src/configuration/index.ts +2 -0
  218. package/src/configuration/libro-configuration-contribution.ts +11 -0
  219. package/src/configuration/libro-configuration.ts +14 -0
  220. package/src/contents/content-contribution.ts +32 -0
  221. package/src/contents/index.ts +1 -0
  222. package/src/file/file-name-alias.ts +15 -0
  223. package/src/file/file-protocol.ts +7 -0
  224. package/src/file/file-service.ts +179 -0
  225. package/src/file/file-tree-label-provider.ts +42 -0
  226. package/src/file/file-view/index.less +5 -0
  227. package/src/file/file-view/index.tsx +90 -0
  228. package/src/file/index.ts +6 -0
  229. package/src/file/module.ts +19 -0
  230. package/src/file/navigatable-view.tsx +93 -0
  231. package/src/file/open-handler-contribution.ts +44 -0
  232. package/src/index.ts +32 -0
  233. package/src/keybind-instructions/index.less +177 -0
  234. package/src/keybind-instructions/index.ts +5 -0
  235. package/src/keybind-instructions/keybind-instructions-contribution.ts +47 -0
  236. package/src/keybind-instructions/keybind-instructions-icon.tsx +28 -0
  237. package/src/keybind-instructions/keybind-instructions-items.tsx +597 -0
  238. package/src/keybind-instructions/keybind-instructions-view.tsx +239 -0
  239. package/src/keybind-instructions/module.ts +11 -0
  240. package/src/libro-jupyter-file-service.ts +158 -0
  241. package/src/libro-jupyter-model.ts +289 -0
  242. package/src/libro-jupyter-protocol.ts +59 -0
  243. package/src/libro-jupyter-server-launch-manager.ts +36 -0
  244. package/src/libro-jupyter-view.tsx +24 -0
  245. package/src/module.ts +105 -0
  246. package/src/output/index.ts +1 -0
  247. package/src/output/libro-jupyter-outputarea.tsx +71 -0
  248. package/src/rendermime/assets/plotly.svg +31 -0
  249. package/src/rendermime/index.less +13 -0
  250. package/src/rendermime/index.ts +4 -0
  251. package/src/rendermime/module.ts +7 -0
  252. package/src/rendermime/plotly-render.tsx +35 -0
  253. package/src/rendermime/plotly-renderers.ts +191 -0
  254. package/src/rendermime/plotly-rendermime-contribution.ts +15 -0
  255. package/src/theme/color-registry.ts +301 -0
  256. package/src/theme/index.ts +1 -0
  257. package/src/toolbar/index.less +194 -0
  258. package/src/toolbar/index.ts +5 -0
  259. package/src/toolbar/kernel-selector-dropdown.tsx +204 -0
  260. package/src/toolbar/kernel-status-and-selector.tsx +195 -0
  261. package/src/toolbar/run-selector.tsx +110 -0
  262. package/src/toolbar/save-file-error-contribution.ts +10 -0
  263. package/src/toolbar/save-file-error.tsx +35 -0
  264. package/src/toolbar/side-toolbar-run-selector.tsx +77 -0
  265. package/src/toolbar/toolbar-contribution.tsx +62 -0
  266. package/src/typings/index.d.ts +31 -0
  267. 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
+ }