@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,201 @@
1
+ import { DisplayWrapComponent } from '@difizen/libro-common';
2
+ import type { BetweenCellProvider, LibroView } from '@difizen/libro-core';
3
+ import { CellService } from '@difizen/libro-core';
4
+ import { CommandRegistry, useInject, ViewInstance } from '@difizen/mana-app';
5
+ import { l10n } from '@difizen/mana-l10n';
6
+ import { Tooltip, Popover, Menu } from 'antd';
7
+ import type { MenuProps } from 'antd';
8
+ import { useEffect, useRef, useState, forwardRef } from 'react';
9
+
10
+ import { LibroAddBetweenCellCommand } from './add-between-cell-command-contribution.js';
11
+
12
+ import './index.less';
13
+
14
+ const AddCellOutlined: React.FC = () => (
15
+ <svg
16
+ width="18px"
17
+ height="18px"
18
+ viewBox="0 0 18 18"
19
+ version="1.1"
20
+ xmlns="http://www.w3.org/2000/svg"
21
+ xmlnsXlink="http://www.w3.org/1999/xlink"
22
+ >
23
+ <g id="页面-1" stroke="none" strokeWidth="1" fill="#6982A9" fillRule="evenodd">
24
+ <g id="2.0-添加-cell" transform="translate(-1539.000000, -240.000000)">
25
+ <g id="Icon/01-Line/add备份-3" transform="translate(1539.937500, 240.562500)">
26
+ <path
27
+ d="M15.9375,7.546875 C16.040625,7.546875 16.125,7.63125 16.125,7.734375 L16.125,9.140625 C16.125,9.24375 16.040625,9.328125 15.9375,9.328125 L8.953125,9.328125 L8.953125,16.6875 C8.953125,16.7910534 8.86917839,16.875 8.765625,16.875 L7.359375,16.875 C7.25582161,16.875 7.171875,16.7910534 7.171875,16.6875 L7.171875,9.328125 L0.1875,9.328125 C0.084375,9.328125 0,9.24375 0,9.140625 L0,7.734375 C0,7.63125 0.084375,7.546875 0.1875,7.546875 L7.171875,7.546875 L7.171875,0.1875 C7.171875,0.0839466094 7.25582161,0 7.359375,0 L8.765625,0 C8.86917839,0 8.953125,0.0839466094 8.953125,0.1875 L8.953125,7.546875 L15.9375,7.546875 Z"
28
+ id="path-1"
29
+ fill="currentColor"
30
+ />
31
+ </g>
32
+ </g>
33
+ </g>
34
+ </svg>
35
+ );
36
+
37
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
38
+ export const LibroCommonBetweenCellContent: BetweenCellProvider = forwardRef(
39
+ function LibroCommonBetweenCellContent(props, _ref) {
40
+ // eslint-disable-next-line react/prop-types
41
+ const { addCell, index } = props;
42
+ const { cellsMeta } = useInject<CellService>(CellService);
43
+ const anchorRef = useRef<HTMLDivElement>(null);
44
+ const gutterRef = useRef<HTMLDivElement>(null);
45
+ const [position, setPosition] = useState({ top: 0, left: 0 });
46
+ const [GutterVisible, setGutterVisible] = useState(false);
47
+ const [tooltipVisible, setTooltipVisible] = useState(false);
48
+ const [menuVisible, setMenuVisible] = useState(false);
49
+ const command = useInject(CommandRegistry);
50
+
51
+ const innerOpenTooltip = () => {
52
+ if (menuVisible) {
53
+ return;
54
+ }
55
+ setTooltipVisible(true);
56
+ };
57
+
58
+ //====== delay ========
59
+ const delayRef = useRef<any>();
60
+
61
+ const clearDelay = () => {
62
+ clearTimeout(delayRef.current);
63
+ };
64
+
65
+ const openTooltip = (_nextOpen: boolean, delay = 0.5) => {
66
+ clearDelay();
67
+
68
+ if (delay === 0) {
69
+ innerOpenTooltip();
70
+ } else {
71
+ delayRef.current = setTimeout(() => {
72
+ innerOpenTooltip();
73
+ }, delay * 1000);
74
+ }
75
+ };
76
+
77
+ const closeTooltip = () => {
78
+ clearDelay();
79
+ setTooltipVisible(false);
80
+ };
81
+
82
+ // eslint-disable-next-line react-hooks/exhaustive-deps
83
+ useEffect(() => closeTooltip, []);
84
+
85
+ const items: MenuProps['items'] = cellsMeta
86
+ .filter((item) => item.type !== 'raw')
87
+ .sort((a, b) => a.order.localeCompare(b.order))
88
+ .map((item) => {
89
+ return {
90
+ label: item.name,
91
+ key: item.type,
92
+ onClick: async () => {
93
+ command.executeCommand(
94
+ LibroAddBetweenCellCommand.AddBetweenCell.id,
95
+ item.type,
96
+ addCell,
97
+ index,
98
+ );
99
+ anchorRef.current?.blur();
100
+ setMenuVisible(false);
101
+ },
102
+ };
103
+ });
104
+
105
+ return (
106
+ <div className="libro-add-between-cell">
107
+ <Popover
108
+ content={<Menu items={items} />}
109
+ trigger="click"
110
+ getPopupContainer={(trigger) => anchorRef.current ?? trigger}
111
+ placement="bottomLeft"
112
+ overlayClassName="libro-add-cell-menu"
113
+ destroyTooltipOnHide
114
+ open={menuVisible}
115
+ >
116
+ <div
117
+ tabIndex={10}
118
+ className="libro-add-between-cell-anchor"
119
+ style={{
120
+ position: 'fixed',
121
+ top: position.top + 5,
122
+ left: position.left + 5,
123
+ width: 1,
124
+ height: 1,
125
+ zIndex: 1000,
126
+ }}
127
+ ref={anchorRef}
128
+ onBlur={(e) => {
129
+ if (!anchorRef.current?.contains(e.relatedTarget)) {
130
+ setMenuVisible(false);
131
+ }
132
+ setGutterVisible(false);
133
+ closeTooltip();
134
+ }}
135
+ />
136
+ </Popover>
137
+ <div
138
+ ref={gutterRef}
139
+ className="libro-add-between-cell-area"
140
+ onMouseEnter={() => {
141
+ setGutterVisible(true);
142
+ }}
143
+ onMouseLeave={() => {
144
+ closeTooltip();
145
+ if (menuVisible) {
146
+ setGutterVisible(true);
147
+ return;
148
+ }
149
+
150
+ setGutterVisible(false);
151
+ }}
152
+ onMouseUp={(e) => {
153
+ closeTooltip();
154
+ setGutterVisible(true);
155
+ setMenuVisible(true);
156
+ setPosition({ top: e.clientY, left: e.clientX });
157
+ anchorRef.current?.focus();
158
+ }}
159
+ >
160
+ {GutterVisible && (
161
+ <>
162
+ <Tooltip
163
+ title={l10n.t('添加 Cell')}
164
+ open={tooltipVisible}
165
+ overlayClassName="libro-add-between-cell-tooltip"
166
+ destroyTooltipOnHide
167
+ >
168
+ <span
169
+ className="libro-add-between-cell-icon"
170
+ onMouseEnter={() => {
171
+ openTooltip(true);
172
+ }}
173
+ onMouseLeave={() => {
174
+ closeTooltip();
175
+ if (menuVisible) {
176
+ setGutterVisible(true);
177
+ }
178
+ }}
179
+ >
180
+ <AddCellOutlined />
181
+ </span>
182
+ </Tooltip>
183
+ <div className="libro-cell-divider" />
184
+ </>
185
+ )}
186
+ </div>
187
+ </div>
188
+ );
189
+ },
190
+ );
191
+
192
+ export const LibroWrappedBetweenCellContent: BetweenCellProvider = (props) => {
193
+ // eslint-disable-next-line react/prop-types
194
+ const { index, addCell } = props;
195
+ const instance = useInject<LibroView>(ViewInstance);
196
+ return (
197
+ <DisplayWrapComponent mode={instance.model.readOnly}>
198
+ <LibroCommonBetweenCellContent index={index} addCell={addCell} />
199
+ </DisplayWrapComponent>
200
+ );
201
+ };
@@ -0,0 +1,103 @@
1
+ @ant-prefix: ant;
2
+
3
+ .libro-add-between-cell {
4
+ position: relative;
5
+ .@{ant-prefix}-popover-arrow {
6
+ display: none;
7
+ }
8
+ .@{ant-prefix}-popover {
9
+ padding: 0;
10
+ max-width: unset;
11
+ }
12
+
13
+ .@{ant-prefix}-popover-inner {
14
+ border-radius: 8px;
15
+ background-color: var(--mana-libro-add-between-popover-background-color);
16
+ padding: 0;
17
+ }
18
+
19
+ .@{ant-prefix}-popover-inner-content {
20
+ padding: 0;
21
+ width: unset;
22
+ max-width: unset;
23
+ }
24
+
25
+ .libro-add-cell-menu {
26
+ z-index: 1000;
27
+ }
28
+
29
+ .@{ant-prefix}-menu {
30
+ border-radius: 8px !important;
31
+ background-color: var(--mana-libro-add-between-popover-background-color) !important;
32
+ }
33
+
34
+ .@{ant-prefix}-menu-vertical {
35
+ border-right: unset !important;
36
+ }
37
+
38
+ .@{ant-prefix}-menu-item {
39
+ height: 32px !important;
40
+ line-height: 32px !important;
41
+ }
42
+ .@{ant-prefix}-menu-item:hover {
43
+ background-color: var(--mana-libro-add-between-hover-color) !important;
44
+ }
45
+
46
+ .@{ant-prefix}-menu-title-content {
47
+ color: var(--mana-libro-add-between-menu-label-color);
48
+ }
49
+
50
+ .@{ant-prefix}-menu-item-selected {
51
+ background-color: var(--mana-libro-add-between-hover-color) !important;
52
+ }
53
+ }
54
+
55
+ .libro-cell-divider {
56
+ width: 100%;
57
+ height: 4px;
58
+ background-color: var(--mana-libro-add-between-divider-color);
59
+ border-radius: 2px;
60
+ }
61
+
62
+ .libro-add-between-cell-icon {
63
+ z-index: 20;
64
+ margin-right: 10px;
65
+ margin-left: 30px;
66
+ height: 18px;
67
+ line-height: 18px;
68
+ text-align: center;
69
+
70
+ svg {
71
+ color: var(--mana-libro-add-between-icon-color);
72
+
73
+ &:hover {
74
+ color: var(--mana-libro-add-between-icon-hover-color);
75
+ }
76
+ }
77
+ }
78
+
79
+ .libro-add-between-cell-area {
80
+ position: absolute;
81
+ top: -16px;
82
+ z-index: 10;
83
+ display: flex;
84
+ align-items: center;
85
+ width: 100%;
86
+ height: 16px;
87
+ cursor: pointer;
88
+ }
89
+
90
+ .libro-add-between-cell-tooltip {
91
+ .@{ant-prefix}-tooltip-inner {
92
+ font-weight: 400;
93
+ font-size: 14px;
94
+ line-height: 22px;
95
+ text-align: center;
96
+ border-radius: 6px;
97
+ }
98
+ }
99
+
100
+ .libro-add-between-cell-anchor:focus {
101
+ outline: none;
102
+ cursor: pointer;
103
+ }
@@ -0,0 +1,2 @@
1
+ export * from './module.js';
2
+ export * from './add-between-cell-command-contribution.js';
@@ -0,0 +1,13 @@
1
+ import { BetweenCellProvider } from '@difizen/libro-core';
2
+ import { ManaModule } from '@difizen/mana-app';
3
+
4
+ import { LibroAddBetweenCellCommandContribution } from './add-between-cell-command-contribution.js';
5
+ import { LibroWrappedBetweenCellContent } from './add-between-cell.js';
6
+
7
+ export const LibroBetweenCellModule = ManaModule.create().register(
8
+ {
9
+ token: BetweenCellProvider,
10
+ useValue: LibroWrappedBetweenCellContent,
11
+ },
12
+ LibroAddBetweenCellCommandContribution,
13
+ );
@@ -0,0 +1,2 @@
1
+ export * from './jupyter-code-cell-model.js';
2
+ export * from './jupyter-code-cell-view.js';
@@ -0,0 +1,36 @@
1
+ import { LibroCodeCellModel } from '@difizen/libro-codemirror-code-cell';
2
+ import type { ICellMetadata } from '@difizen/libro-common';
3
+ import { CellOptions } from '@difizen/libro-core';
4
+ import { inject, transient } from '@difizen/mana-app';
5
+ import { prop, ViewManager } from '@difizen/mana-app';
6
+
7
+ import type {
8
+ ExecutedWithKernelCellModel,
9
+ CodeCellMetadata,
10
+ } from '../libro-jupyter-protocol.js';
11
+
12
+ @transient()
13
+ export class JupyterCodeCellModel
14
+ extends LibroCodeCellModel
15
+ implements ExecutedWithKernelCellModel
16
+ {
17
+ @prop()
18
+ override metadata: Partial<CodeCellMetadata | ICellMetadata>;
19
+ @prop()
20
+ kernelExecuting = false;
21
+
22
+ constructor(
23
+ @inject(CellOptions) options: CellOptions,
24
+ @inject(ViewManager) viewManager: ViewManager,
25
+ ) {
26
+ super(options, viewManager);
27
+ this.metadata = options.cell?.metadata || {};
28
+ }
29
+
30
+ override clearExecution = () => {
31
+ this.executeCount = null;
32
+ this.executing = false;
33
+ this.kernelExecuting = false;
34
+ this.metadata.execution = {};
35
+ };
36
+ }
@@ -0,0 +1,221 @@
1
+ import { CodeEditorView } from '@difizen/libro-code-editor';
2
+ import type {
3
+ CodeEditorViewOptions,
4
+ CompletionProvider,
5
+ CompletionProviderOption,
6
+ TooltipProvider,
7
+ TooltipProviderOption,
8
+ } from '@difizen/libro-code-editor';
9
+ import { codeMirrorEditorFactory } from '@difizen/libro-codemirror';
10
+ import { CellEditorMemo, LibroCodeCellView } from '@difizen/libro-codemirror-code-cell';
11
+ import type { CellViewOptions } from '@difizen/libro-core';
12
+ import { CellService } from '@difizen/libro-core';
13
+ import { KernelError } from '@difizen/libro-kernel';
14
+ import { inject, transient } from '@difizen/mana-app';
15
+ import { view, ViewInstance, ViewManager, ViewOption } from '@difizen/mana-app';
16
+ import { getOrigin, useInject, watch } from '@difizen/mana-app';
17
+ import { l10n } from '@difizen/mana-l10n';
18
+ import { forwardRef } from 'react';
19
+
20
+ import { LibroJupyterModel } from '../libro-jupyter-model.js';
21
+ import type { ExecutionMeta } from '../libro-jupyter-protocol.js';
22
+
23
+ import type { JupyterCodeCellModel } from './jupyter-code-cell-model.js';
24
+
25
+ const JupyterCodeCellComponent = forwardRef<HTMLDivElement>(
26
+ function JupyterCodeCellComponent(_props, ref) {
27
+ const instance = useInject<JupyterCodeCellView>(ViewInstance);
28
+ return (
29
+ <div
30
+ className={instance.className}
31
+ ref={ref}
32
+ tabIndex={10}
33
+ onBlur={instance.blur}
34
+ >
35
+ <CellEditorMemo />
36
+ </div>
37
+ );
38
+ },
39
+ );
40
+
41
+ @transient()
42
+ @view('jupyter-code-cell-view')
43
+ export class JupyterCodeCellView extends LibroCodeCellView {
44
+ override view = JupyterCodeCellComponent;
45
+ declare model: JupyterCodeCellModel;
46
+
47
+ constructor(
48
+ @inject(ViewOption) options: CellViewOptions,
49
+ @inject(CellService) cellService: CellService,
50
+ @inject(ViewManager) viewManager: ViewManager,
51
+ ) {
52
+ super(options, cellService, viewManager);
53
+ }
54
+
55
+ override clearExecution = () => {
56
+ this.model.clearExecution();
57
+ this.outputArea.clear();
58
+ };
59
+
60
+ override onViewMount() {
61
+ const option: CodeEditorViewOptions = {
62
+ ...this.options,
63
+ factory: (editorOption) =>
64
+ codeMirrorEditorFactory({
65
+ ...editorOption,
66
+ config: {
67
+ ...editorOption.config,
68
+ ...{ readOnly: this.parent.model.readOnly },
69
+ },
70
+ }),
71
+ model: this.model,
72
+ tooltipProvider: this.tooltipProvider,
73
+ completionProvider: this.completionProvider,
74
+ lspProvider: undefined,
75
+ };
76
+ this.viewManager
77
+ .getOrCreateView<CodeEditorView, CodeEditorViewOptions>(CodeEditorView, option)
78
+ .then((editorView) => {
79
+ this.editorView = editorView;
80
+ this.editorViewReadyDeferred.resolve();
81
+ watch(this.parent.model, 'readOnly', () => {
82
+ this.editorView?.editor?.setOption('readOnly', this.parent.model.readOnly);
83
+ });
84
+ this.editorView.onModalChange((val) => (this.hasModal = val));
85
+ return;
86
+ })
87
+ .catch(() => {
88
+ //
89
+ });
90
+ }
91
+
92
+ tooltipProvider: TooltipProvider = async (option: TooltipProviderOption) => {
93
+ const cellContent = this.model.value;
94
+ const kernelConnection = getOrigin(
95
+ (this.parent.model as LibroJupyterModel).kernelConnection,
96
+ );
97
+ if (!kernelConnection) {
98
+ alert(l10n.t('Kernel Connection 还没有建立'));
99
+ return null;
100
+ }
101
+ const reply = await kernelConnection.requestInspect({
102
+ code: cellContent,
103
+ cursor_pos: option.cursorPosition,
104
+ detail_level: 1,
105
+ });
106
+
107
+ const value = reply.content;
108
+
109
+ if (value.status !== 'ok' || !value.found) {
110
+ return null;
111
+ }
112
+ return value.data['text/plain'] as string;
113
+ };
114
+
115
+ completionProvider: CompletionProvider = async (option: CompletionProviderOption) => {
116
+ const cellContent = this.model.value;
117
+ const kernelConnection = getOrigin(
118
+ (this.parent.model as LibroJupyterModel).kernelConnection,
119
+ );
120
+ if (!kernelConnection) {
121
+ alert(l10n.t('Kernel Connection 还没有建立'));
122
+ throw new Error(l10n.t('Kernel Connection 还没有建立'));
123
+ }
124
+ const reply = await kernelConnection.requestComplete({
125
+ code: cellContent,
126
+ cursor_pos: option.cursorPosition,
127
+ });
128
+
129
+ const value = reply.content;
130
+
131
+ if (value.status === 'abort') {
132
+ throw new Error('abort');
133
+ }
134
+
135
+ if (value.status === 'error') {
136
+ throw new Error(value.ename);
137
+ }
138
+
139
+ return {
140
+ matches: value.matches,
141
+ cursor_start: value.cursor_start,
142
+ cursor_end: value.cursor_end,
143
+ metadata: value.metadata,
144
+ };
145
+ };
146
+
147
+ override async run() {
148
+ const libroModel = this.parent.model;
149
+
150
+ if (
151
+ !libroModel ||
152
+ !(libroModel instanceof LibroJupyterModel) ||
153
+ !libroModel.kernelConnection ||
154
+ libroModel.kernelConnection.isDisposed
155
+ ) {
156
+ return false;
157
+ }
158
+
159
+ const kernelConnection = getOrigin(libroModel.kernelConnection);
160
+ const cellContent = this.model.value;
161
+ const cellModel = this.model;
162
+
163
+ try {
164
+ this.clearExecution();
165
+ const future = kernelConnection.requestExecute({
166
+ code: cellContent,
167
+ });
168
+
169
+ let startTimeStr = '';
170
+ cellModel.executing = true;
171
+
172
+ cellModel.metadata['execution'] = {
173
+ 'shell.execute_reply.started': '',
174
+ 'shell.execute_reply.end': '',
175
+ to_execute: new Date().toISOString(),
176
+ } as ExecutionMeta;
177
+
178
+ // Handle iopub messages
179
+ future.onIOPub = (msg: any) => {
180
+ cellModel.msgChangeEmitter.fire(msg);
181
+ if (msg.header.msg_type === 'execute_input') {
182
+ cellModel.kernelExecuting = true;
183
+ startTimeStr = msg.header.date as string;
184
+ const meta = cellModel.metadata['execution'] as ExecutionMeta;
185
+ if (meta) {
186
+ meta['shell.execute_reply.started'] = startTimeStr;
187
+ }
188
+ }
189
+ };
190
+ // Handle the execute reply.
191
+ future.onReply = (msg: any) => {
192
+ cellModel.msgChangeEmitter.fire(msg);
193
+ };
194
+
195
+ const msgPromise = await future.done;
196
+ cellModel.executing = false;
197
+ cellModel.kernelExecuting = false;
198
+
199
+ startTimeStr = msgPromise.metadata['started'] as string;
200
+ const endTimeStr = msgPromise.header.date;
201
+
202
+ cellModel.metadata['execution']['shell.execute_reply.started'] = startTimeStr;
203
+ cellModel.metadata['execution']['shell.execute_reply.end'] = endTimeStr;
204
+
205
+ if (!msgPromise) {
206
+ return true;
207
+ }
208
+
209
+ if (msgPromise.content.status === 'ok') {
210
+ return true;
211
+ } else {
212
+ throw new KernelError(msgPromise.content);
213
+ }
214
+ } catch (reason: any) {
215
+ if (reason.message.startsWith('Canceled')) {
216
+ return false;
217
+ }
218
+ throw reason;
219
+ }
220
+ }
221
+ }