@difizen/libro-core 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 (312) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/es/add-cell/index.d.ts +4 -0
  4. package/es/add-cell/index.d.ts.map +1 -0
  5. package/es/add-cell/index.js +3 -0
  6. package/es/add-cell/index.less +38 -0
  7. package/es/add-cell/libro-add-cell-module.d.ts +3 -0
  8. package/es/add-cell/libro-add-cell-module.d.ts.map +1 -0
  9. package/es/add-cell/libro-add-cell-module.js +4 -0
  10. package/es/add-cell/libro-add-cell-slot-contribution.d.ts +12 -0
  11. package/es/add-cell/libro-add-cell-slot-contribution.d.ts.map +1 -0
  12. package/es/add-cell/libro-add-cell-slot-contribution.js +53 -0
  13. package/es/add-cell/libro-add-cell-view.d.ts +21 -0
  14. package/es/add-cell/libro-add-cell-view.d.ts.map +1 -0
  15. package/es/add-cell/libro-add-cell-view.js +129 -0
  16. package/es/cell/index.d.ts +10 -0
  17. package/es/cell/index.d.ts.map +1 -0
  18. package/es/cell/index.js +9 -0
  19. package/es/cell/libro-cell-contribution.d.ts +13 -0
  20. package/es/cell/libro-cell-contribution.d.ts.map +1 -0
  21. package/es/cell/libro-cell-contribution.js +41 -0
  22. package/es/cell/libro-cell-model.d.ts +19 -0
  23. package/es/cell/libro-cell-model.d.ts.map +1 -0
  24. package/es/cell/libro-cell-model.js +103 -0
  25. package/es/cell/libro-cell-module.d.ts +10 -0
  26. package/es/cell/libro-cell-module.d.ts.map +1 -0
  27. package/es/cell/libro-cell-module.js +30 -0
  28. package/es/cell/libro-cell-protocol.d.ts +42 -0
  29. package/es/cell/libro-cell-protocol.d.ts.map +1 -0
  30. package/es/cell/libro-cell-protocol.js +11 -0
  31. package/es/cell/libro-cell-service.d.ts +28 -0
  32. package/es/cell/libro-cell-service.d.ts.map +1 -0
  33. package/es/cell/libro-cell-service.js +242 -0
  34. package/es/cell/libro-cell-view.d.ts +65 -0
  35. package/es/cell/libro-cell-view.d.ts.map +1 -0
  36. package/es/cell/libro-cell-view.js +191 -0
  37. package/es/cell/libro-edit-cell-view.d.ts +32 -0
  38. package/es/cell/libro-edit-cell-view.d.ts.map +1 -0
  39. package/es/cell/libro-edit-cell-view.js +72 -0
  40. package/es/cell/libro-executable-cell-model.d.ts +14 -0
  41. package/es/cell/libro-executable-cell-model.d.ts.map +1 -0
  42. package/es/cell/libro-executable-cell-model.js +7 -0
  43. package/es/cell/libro-executable-cell-view.d.ts +27 -0
  44. package/es/cell/libro-executable-cell-view.d.ts.map +1 -0
  45. package/es/cell/libro-executable-cell-view.js +66 -0
  46. package/es/cell/libro-markdown-cell-model.d.ts +9 -0
  47. package/es/cell/libro-markdown-cell-model.d.ts.map +1 -0
  48. package/es/cell/libro-markdown-cell-model.js +7 -0
  49. package/es/collapse-service.d.ts +36 -0
  50. package/es/collapse-service.d.ts.map +1 -0
  51. package/es/collapse-service.js +55 -0
  52. package/es/command/document-commands.d.ts +6 -0
  53. package/es/command/document-commands.d.ts.map +1 -0
  54. package/es/command/document-commands.js +13 -0
  55. package/es/command/index.d.ts +7 -0
  56. package/es/command/index.d.ts.map +1 -0
  57. package/es/command/index.js +6 -0
  58. package/es/command/kernel-command.d.ts +5 -0
  59. package/es/command/kernel-command.d.ts.map +1 -0
  60. package/es/command/kernel-command.js +39 -0
  61. package/es/command/libro-command-contribution.d.ts +14 -0
  62. package/es/command/libro-command-contribution.d.ts.map +1 -0
  63. package/es/command/libro-command-contribution.js +1751 -0
  64. package/es/command/libro-command-register.d.ts +22 -0
  65. package/es/command/libro-command-register.d.ts.map +1 -0
  66. package/es/command/libro-command-register.js +105 -0
  67. package/es/command/module.d.ts +3 -0
  68. package/es/command/module.d.ts.map +1 -0
  69. package/es/command/module.js +4 -0
  70. package/es/command/notebook-commands.d.ts +6 -0
  71. package/es/command/notebook-commands.d.ts.map +1 -0
  72. package/es/command/notebook-commands.js +468 -0
  73. package/es/components/cell-protocol.d.ts +20 -0
  74. package/es/components/cell-protocol.d.ts.map +1 -0
  75. package/es/components/cell-protocol.js +4 -0
  76. package/es/components/dnd-cell-item-render.d.ts +12 -0
  77. package/es/components/dnd-cell-item-render.d.ts.map +1 -0
  78. package/es/components/dnd-cell-item-render.js +253 -0
  79. package/es/components/dnd-component/custom-drag-layer.d.ts +9 -0
  80. package/es/components/dnd-component/custom-drag-layer.d.ts.map +1 -0
  81. package/es/components/dnd-component/custom-drag-layer.js +141 -0
  82. package/es/components/dnd-component/default-dnd-content.d.ts +10 -0
  83. package/es/components/dnd-component/default-dnd-content.d.ts.map +1 -0
  84. package/es/components/dnd-component/default-dnd-content.js +257 -0
  85. package/es/components/dnd-component/dnd-context.d.ts +3 -0
  86. package/es/components/dnd-component/dnd-context.d.ts.map +1 -0
  87. package/es/components/dnd-component/dnd-context.js +20 -0
  88. package/es/components/dnd-component/dnd-list.d.ts +10 -0
  89. package/es/components/dnd-component/dnd-list.d.ts.map +1 -0
  90. package/es/components/dnd-component/dnd-list.js +115 -0
  91. package/es/components/dnd-component/index.d.ts +5 -0
  92. package/es/components/dnd-component/index.d.ts.map +1 -0
  93. package/es/components/dnd-component/index.js +4 -0
  94. package/es/components/index.d.ts +6 -0
  95. package/es/components/index.d.ts.map +1 -0
  96. package/es/components/index.js +5 -0
  97. package/es/components/libro-component.d.ts +5 -0
  98. package/es/components/libro-component.d.ts.map +1 -0
  99. package/es/components/libro-component.js +35 -0
  100. package/es/components/libro-side-toolbar-menu.d.ts +21 -0
  101. package/es/components/libro-side-toolbar-menu.d.ts.map +1 -0
  102. package/es/components/libro-side-toolbar-menu.js +58 -0
  103. package/es/components/libro-view-header.d.ts +3 -0
  104. package/es/components/libro-view-header.d.ts.map +1 -0
  105. package/es/components/libro-view-header.js +37 -0
  106. package/es/configuration/libro-configuration-contribution.d.ts +5 -0
  107. package/es/configuration/libro-configuration-contribution.d.ts.map +1 -0
  108. package/es/configuration/libro-configuration-contribution.js +24 -0
  109. package/es/configuration/libro-configuration.d.ts +10 -0
  110. package/es/configuration/libro-configuration.d.ts.map +1 -0
  111. package/es/configuration/libro-configuration.js +81 -0
  112. package/es/content/index.d.ts +5 -0
  113. package/es/content/index.d.ts.map +1 -0
  114. package/es/content/index.js +4 -0
  115. package/es/content/libro-content-contribution.d.ts +11 -0
  116. package/es/content/libro-content-contribution.d.ts.map +1 -0
  117. package/es/content/libro-content-contribution.js +32 -0
  118. package/es/content/libro-content-module.d.ts +3 -0
  119. package/es/content/libro-content-module.d.ts.map +1 -0
  120. package/es/content/libro-content-module.js +5 -0
  121. package/es/content/libro-content-protocol.d.ts +8 -0
  122. package/es/content/libro-content-protocol.d.ts.map +1 -0
  123. package/es/content/libro-content-protocol.js +2 -0
  124. package/es/content/libro-content-service.d.ts +9 -0
  125. package/es/content/libro-content-service.d.ts.map +1 -0
  126. package/es/content/libro-content-service.js +35 -0
  127. package/es/index.d.ts +20 -0
  128. package/es/index.d.ts.map +1 -0
  129. package/es/index.js +19 -0
  130. package/es/index.less +682 -0
  131. package/es/libro-context-key.d.ts +22 -0
  132. package/es/libro-context-key.d.ts.map +1 -0
  133. package/es/libro-context-key.js +80 -0
  134. package/es/libro-keybind-registry.d.ts +5 -0
  135. package/es/libro-keybind-registry.d.ts.map +1 -0
  136. package/es/libro-keybind-registry.js +68 -0
  137. package/es/libro-model.d.ts +129 -0
  138. package/es/libro-model.d.ts.map +1 -0
  139. package/es/libro-model.js +803 -0
  140. package/es/libro-protocol.d.ts +241 -0
  141. package/es/libro-protocol.d.ts.map +1 -0
  142. package/es/libro-protocol.js +34 -0
  143. package/es/libro-service.d.ts +34 -0
  144. package/es/libro-service.d.ts.map +1 -0
  145. package/es/libro-service.js +180 -0
  146. package/es/libro-view-tracker.d.ts +6 -0
  147. package/es/libro-view-tracker.d.ts.map +1 -0
  148. package/es/libro-view-tracker.js +13 -0
  149. package/es/libro-view.d.ts +151 -0
  150. package/es/libro-view.d.ts.map +1 -0
  151. package/es/libro-view.js +1963 -0
  152. package/es/material-from-designer.d.ts +27 -0
  153. package/es/material-from-designer.d.ts.map +1 -0
  154. package/es/material-from-designer.js +550 -0
  155. package/es/module.d.ts +3 -0
  156. package/es/module.d.ts.map +1 -0
  157. package/es/module.js +55 -0
  158. package/es/output/index.d.ts +6 -0
  159. package/es/output/index.d.ts.map +1 -0
  160. package/es/output/index.js +5 -0
  161. package/es/output/output-area.d.ts +51 -0
  162. package/es/output/output-area.d.ts.map +1 -0
  163. package/es/output/output-area.js +346 -0
  164. package/es/output/output-contribution.d.ts +11 -0
  165. package/es/output/output-contribution.d.ts.map +1 -0
  166. package/es/output/output-contribution.js +31 -0
  167. package/es/output/output-model.d.ts +27 -0
  168. package/es/output/output-model.d.ts.map +1 -0
  169. package/es/output/output-model.js +95 -0
  170. package/es/output/output-module.d.ts +3 -0
  171. package/es/output/output-module.d.ts.map +1 -0
  172. package/es/output/output-module.js +6 -0
  173. package/es/output/output-protocol.d.ts +130 -0
  174. package/es/output/output-protocol.d.ts.map +1 -0
  175. package/es/output/output-protocol.js +18 -0
  176. package/es/slot/index.d.ts +5 -0
  177. package/es/slot/index.d.ts.map +1 -0
  178. package/es/slot/index.js +4 -0
  179. package/es/slot/libro-slot-manager.d.ts +13 -0
  180. package/es/slot/libro-slot-manager.d.ts.map +1 -0
  181. package/es/slot/libro-slot-manager.js +57 -0
  182. package/es/slot/libro-slot-protocol.d.ts +19 -0
  183. package/es/slot/libro-slot-protocol.d.ts.map +1 -0
  184. package/es/slot/libro-slot-protocol.js +5 -0
  185. package/es/slot/libro-slot-view.d.ts +9 -0
  186. package/es/slot/libro-slot-view.d.ts.map +1 -0
  187. package/es/slot/libro-slot-view.js +81 -0
  188. package/es/slot/module.d.ts +3 -0
  189. package/es/slot/module.d.ts.map +1 -0
  190. package/es/slot/module.js +5 -0
  191. package/es/theme/libro-color-registry.d.ts +6 -0
  192. package/es/theme/libro-color-registry.d.ts.map +1 -0
  193. package/es/theme/libro-color-registry.js +494 -0
  194. package/es/toolbar/change-cell-to-selector.d.ts +5 -0
  195. package/es/toolbar/change-cell-to-selector.d.ts.map +1 -0
  196. package/es/toolbar/change-cell-to-selector.js +48 -0
  197. package/es/toolbar/hide-all-selector.d.ts +5 -0
  198. package/es/toolbar/hide-all-selector.d.ts.map +1 -0
  199. package/es/toolbar/hide-all-selector.js +99 -0
  200. package/es/toolbar/index.d.ts +4 -0
  201. package/es/toolbar/index.d.ts.map +1 -0
  202. package/es/toolbar/index.js +3 -0
  203. package/es/toolbar/index.less +59 -0
  204. package/es/toolbar/libro-toolbar-protocol.d.ts +4 -0
  205. package/es/toolbar/libro-toolbar-protocol.d.ts.map +1 -0
  206. package/es/toolbar/libro-toolbar-protocol.js +1 -0
  207. package/es/toolbar/libro-toolbar.d.ts +8 -0
  208. package/es/toolbar/libro-toolbar.d.ts.map +1 -0
  209. package/es/toolbar/libro-toolbar.js +223 -0
  210. package/es/toolbar/module.d.ts +3 -0
  211. package/es/toolbar/module.d.ts.map +1 -0
  212. package/es/toolbar/module.js +5 -0
  213. package/es/toolbar/restart-clear-outputs-contribution.d.ts +5 -0
  214. package/es/toolbar/restart-clear-outputs-contribution.d.ts.map +1 -0
  215. package/es/toolbar/restart-clear-outputs-contribution.js +23 -0
  216. package/es/toolbar/restart-clear-outputs-modal.d.ts +6 -0
  217. package/es/toolbar/restart-clear-outputs-modal.d.ts.map +1 -0
  218. package/es/toolbar/restart-clear-outputs-modal.js +30 -0
  219. package/es/toolbar/save-icon.d.ts +3 -0
  220. package/es/toolbar/save-icon.d.ts.map +1 -0
  221. package/es/toolbar/save-icon.js +54 -0
  222. package/es/toolbar/shutdown-contribution.d.ts +5 -0
  223. package/es/toolbar/shutdown-contribution.d.ts.map +1 -0
  224. package/es/toolbar/shutdown-contribution.js +23 -0
  225. package/es/toolbar/shutdown-modal.d.ts +6 -0
  226. package/es/toolbar/shutdown-modal.d.ts.map +1 -0
  227. package/es/toolbar/shutdown-modal.js +30 -0
  228. package/es/toolbar/side-toolar-more-select.d.ts +4 -0
  229. package/es/toolbar/side-toolar-more-select.d.ts.map +1 -0
  230. package/es/toolbar/side-toolar-more-select.js +161 -0
  231. package/es/typings/index.d.ts +1 -0
  232. package/package.json +70 -0
  233. package/src/add-cell/index.less +38 -0
  234. package/src/add-cell/index.ts +3 -0
  235. package/src/add-cell/libro-add-cell-module.ts +9 -0
  236. package/src/add-cell/libro-add-cell-slot-contribution.ts +31 -0
  237. package/src/add-cell/libro-add-cell-view.tsx +101 -0
  238. package/src/cell/README.md +14 -0
  239. package/src/cell/index.ts +9 -0
  240. package/src/cell/libro-cell-contribution.ts +38 -0
  241. package/src/cell/libro-cell-model.ts +61 -0
  242. package/src/cell/libro-cell-module.ts +40 -0
  243. package/src/cell/libro-cell-protocol.ts +53 -0
  244. package/src/cell/libro-cell-service.ts +157 -0
  245. package/src/cell/libro-cell-view.tsx +128 -0
  246. package/src/cell/libro-edit-cell-view.tsx +60 -0
  247. package/src/cell/libro-executable-cell-model.ts +32 -0
  248. package/src/cell/libro-executable-cell-view.ts +74 -0
  249. package/src/cell/libro-markdown-cell-model.ts +20 -0
  250. package/src/collapse-service.ts +69 -0
  251. package/src/command/document-commands.ts +18 -0
  252. package/src/command/index.ts +6 -0
  253. package/src/command/kernel-command.ts +41 -0
  254. package/src/command/libro-command-contribution.ts +1339 -0
  255. package/src/command/libro-command-register.ts +171 -0
  256. package/src/command/module.ts +9 -0
  257. package/src/command/notebook-commands.ts +498 -0
  258. package/src/components/cell-protocol.ts +22 -0
  259. package/src/components/dnd-cell-item-render.tsx +308 -0
  260. package/src/components/dnd-component/custom-drag-layer.tsx +145 -0
  261. package/src/components/dnd-component/default-dnd-content.tsx +275 -0
  262. package/src/components/dnd-component/dnd-context.tsx +28 -0
  263. package/src/components/dnd-component/dnd-list.tsx +116 -0
  264. package/src/components/dnd-component/index.tsx +4 -0
  265. package/src/components/index.ts +5 -0
  266. package/src/components/libro-component.tsx +30 -0
  267. package/src/components/libro-side-toolbar-menu.tsx +82 -0
  268. package/src/components/libro-view-header.tsx +33 -0
  269. package/src/configuration/libro-configuration-contribution.ts +29 -0
  270. package/src/configuration/libro-configuration.ts +88 -0
  271. package/src/content/index.ts +4 -0
  272. package/src/content/libro-content-contribution.ts +17 -0
  273. package/src/content/libro-content-module.ts +9 -0
  274. package/src/content/libro-content-protocol.ts +8 -0
  275. package/src/content/libro-content-service.ts +30 -0
  276. package/src/index.less +682 -0
  277. package/src/index.tsx +19 -0
  278. package/src/libro-context-key.ts +80 -0
  279. package/src/libro-keybind-registry.ts +43 -0
  280. package/src/libro-model.ts +614 -0
  281. package/src/libro-protocol.ts +322 -0
  282. package/src/libro-service.ts +121 -0
  283. package/src/libro-view-tracker.ts +9 -0
  284. package/src/libro-view.tsx +1399 -0
  285. package/src/material-from-designer.tsx +457 -0
  286. package/src/module.ts +90 -0
  287. package/src/output/index.ts +5 -0
  288. package/src/output/output-area.tsx +255 -0
  289. package/src/output/output-contribution.ts +18 -0
  290. package/src/output/output-model.tsx +66 -0
  291. package/src/output/output-module.ts +10 -0
  292. package/src/output/output-protocol.ts +164 -0
  293. package/src/slot/index.ts +4 -0
  294. package/src/slot/libro-slot-manager.ts +37 -0
  295. package/src/slot/libro-slot-protocol.ts +28 -0
  296. package/src/slot/libro-slot-view.tsx +51 -0
  297. package/src/slot/module.ts +9 -0
  298. package/src/theme/libro-color-registry.ts +371 -0
  299. package/src/toolbar/change-cell-to-selector.tsx +58 -0
  300. package/src/toolbar/hide-all-selector.tsx +126 -0
  301. package/src/toolbar/index.less +59 -0
  302. package/src/toolbar/index.ts +3 -0
  303. package/src/toolbar/libro-toolbar-protocol.ts +4 -0
  304. package/src/toolbar/libro-toolbar.tsx +192 -0
  305. package/src/toolbar/module.ts +11 -0
  306. package/src/toolbar/restart-clear-outputs-contribution.tsx +10 -0
  307. package/src/toolbar/restart-clear-outputs-modal.tsx +37 -0
  308. package/src/toolbar/save-icon.tsx +47 -0
  309. package/src/toolbar/shutdown-contribution.tsx +10 -0
  310. package/src/toolbar/shutdown-modal.tsx +37 -0
  311. package/src/toolbar/side-toolar-more-select.tsx +172 -0
  312. package/src/typings/index.d.ts +1 -0
@@ -0,0 +1,171 @@
1
+ import type {
2
+ Command,
3
+ CommandHandler,
4
+ CommandHandlerWithContext,
5
+ CommandRegistry,
6
+ KeybindingRegistry,
7
+ } from '@difizen/mana-app';
8
+ import { inject, singleton } from '@difizen/mana-app';
9
+
10
+ import type { CellView, NotebookView } from '../libro-protocol.js';
11
+ import { LibroContextKeys } from '../libro-protocol.js';
12
+ import { LibroService } from '../libro-service.js';
13
+
14
+ export interface GeneralLibroCommandHandler extends CommandHandler {
15
+ execute: (
16
+ cell?: CellView,
17
+ libro?: NotebookView,
18
+ position?: string,
19
+ options?: any,
20
+ ) => void;
21
+ isVisible?: (
22
+ cell?: CellView,
23
+ libro?: NotebookView,
24
+ position?: string,
25
+ options?: any,
26
+ ) => boolean;
27
+ isEnabled?: (
28
+ cell?: CellView,
29
+ libro?: NotebookView,
30
+ position?: string,
31
+ options?: any,
32
+ ) => boolean;
33
+ isActive?: (
34
+ cell?: CellView,
35
+ libro?: NotebookView,
36
+ position?: string,
37
+ options?: any,
38
+ ) => boolean;
39
+ }
40
+
41
+ @singleton()
42
+ export class LibroCommandRegister {
43
+ protected readonly libroService: LibroService;
44
+ constructor(@inject(LibroService) libroService: LibroService) {
45
+ this.libroService = libroService;
46
+ }
47
+ registerKeybinds(
48
+ keybindings: KeybindingRegistry,
49
+ commands: Record<
50
+ string,
51
+ Command & {
52
+ keybind?: string | string[];
53
+ when?: string;
54
+ preventDefault?: boolean;
55
+ stopPropagation?: boolean;
56
+ }
57
+ >,
58
+ needActive = true,
59
+ needFocus = true,
60
+ ) {
61
+ const keys = Object.keys(commands);
62
+ for (const key of keys) {
63
+ const command = commands[key];
64
+ if (command.keybind) {
65
+ const needFocusStr = needFocus ? LibroContextKeys.focus : '';
66
+ const needActiveStr = needActive ? LibroContextKeys.active : '';
67
+ const when = [needFocusStr, needActiveStr, command.when]
68
+ .filter(Boolean)
69
+ .join(' && ');
70
+ if (command.keybind instanceof Array) {
71
+ command.keybind.forEach((keybind) => {
72
+ keybindings.registerKeybinding({
73
+ command: command.id,
74
+ keybinding: keybind,
75
+ when: when,
76
+ preventDefault: command.preventDefault,
77
+ stopPropagation: command.stopPropagation,
78
+ });
79
+ });
80
+ } else {
81
+ keybindings.registerKeybinding({
82
+ command: command.id,
83
+ keybinding: command.keybind,
84
+ when: when,
85
+ preventDefault: command.preventDefault,
86
+ stopPropagation: command.stopPropagation,
87
+ });
88
+ }
89
+ }
90
+ }
91
+ }
92
+ toGeneralCommandArgs = (
93
+ ctx: LibroCommandRegister,
94
+ cell?: CellView,
95
+ libro?: NotebookView,
96
+ position?: string,
97
+ options?: any,
98
+ ): [CellView | undefined, NotebookView | undefined, string | undefined, any] => {
99
+ const libroView = libro || ctx.libroService.active;
100
+ const cellView = cell || libroView?.model?.active;
101
+ return [cellView, libroView, position, options];
102
+ };
103
+ registerLibroCommand(
104
+ registry: CommandRegistry,
105
+ command: Command,
106
+ handler: GeneralLibroCommandHandler,
107
+ ) {
108
+ const commandHandler: CommandHandlerWithContext<LibroCommandRegister> = {
109
+ execute: (
110
+ ctx,
111
+ cell?: CellView,
112
+ libro?: NotebookView,
113
+ position?: string,
114
+ options?: any,
115
+ ) => {
116
+ return handler.execute(
117
+ ...this.toGeneralCommandArgs(ctx, cell, libro, position, options),
118
+ );
119
+ },
120
+ };
121
+ if (handler.isEnabled) {
122
+ commandHandler.isEnabled = (
123
+ ctx,
124
+ cell?: CellView,
125
+ libro?: NotebookView,
126
+ position?: string,
127
+ options?: any,
128
+ ) => {
129
+ if (!handler.isEnabled) {
130
+ return true;
131
+ }
132
+ return handler.isEnabled(
133
+ ...this.toGeneralCommandArgs(ctx, cell, libro, position, options),
134
+ );
135
+ };
136
+ }
137
+ if (handler.isVisible) {
138
+ commandHandler.isVisible = (
139
+ ctx,
140
+ cell?: CellView,
141
+ libro?: NotebookView,
142
+ position?: string,
143
+ options?: any,
144
+ ) => {
145
+ if (!handler.isVisible) {
146
+ return true;
147
+ }
148
+ return handler.isVisible(
149
+ ...this.toGeneralCommandArgs(ctx, cell, libro, position, options),
150
+ );
151
+ };
152
+ }
153
+ if (handler.isActive) {
154
+ commandHandler.isActive = (
155
+ ctx,
156
+ cell?: CellView,
157
+ libro?: NotebookView,
158
+ position?: string,
159
+ options?: any,
160
+ ) => {
161
+ if (!handler.isActive) {
162
+ return false;
163
+ }
164
+ return handler.isActive(
165
+ ...this.toGeneralCommandArgs(ctx, cell, libro, position, options),
166
+ );
167
+ };
168
+ }
169
+ registry.registerCommandWithContext(command, this, commandHandler);
170
+ }
171
+ }
@@ -0,0 +1,9 @@
1
+ import { ManaModule } from '@difizen/mana-app';
2
+
3
+ import { LibroCommandContribution } from './libro-command-contribution.js';
4
+ import { LibroCommandRegister } from './libro-command-register.js';
5
+
6
+ export const LibroCommandModule = ManaModule.create().register(
7
+ LibroCommandContribution,
8
+ LibroCommandRegister,
9
+ );
@@ -0,0 +1,498 @@
1
+ import {
2
+ PlusOutlined,
3
+ PlayCircleOutlined,
4
+ CopyOutlined,
5
+ ScissorOutlined,
6
+ SnippetsOutlined,
7
+ PauseCircleOutlined,
8
+ EyeOutlined,
9
+ EyeInvisibleOutlined,
10
+ // ReloadOutlined,
11
+ PoweroffOutlined,
12
+ } from '@ant-design/icons';
13
+ import type { Command } from '@difizen/mana-app';
14
+ import { l10n } from '@difizen/mana-l10n';
15
+
16
+ import {
17
+ Undo,
18
+ Redo,
19
+ Reload,
20
+ ClearOutlined,
21
+ MoveUpOutlined,
22
+ MoveDownOutlined,
23
+ DeleteOutlined,
24
+ MoreOutlined,
25
+ } from '../material-from-designer.js';
26
+
27
+ export const NotebookCommands: Record<
28
+ string,
29
+ Command & { keybind?: string | string[] | undefined; when?: string | undefined }
30
+ > = {
31
+ //#region libro command
32
+ ChangeCellTo: {
33
+ id: 'notebook:change-cell-to',
34
+ },
35
+
36
+ Interrupt: {
37
+ id: 'notebook:interrupt',
38
+ label: `Interrupt`,
39
+ icon: PauseCircleOutlined,
40
+ },
41
+
42
+ //#endregion
43
+
44
+ //#region jupyterlab command
45
+ ChangeCellToCode: {
46
+ id: 'notebook:change-cell-to-code',
47
+ label: `Change to Code Cell Type`,
48
+ keybind: 'Y',
49
+ when: 'commandMode',
50
+ },
51
+ ChangeCellToHeading1: {
52
+ id: 'notebook:change-cell-to-heading-1',
53
+ label: `Change to Heading 1`,
54
+ keybind: '1',
55
+ when: 'commandMode',
56
+ },
57
+ ChangeCellToHeading2: {
58
+ id: 'notebook:change-cell-to-heading-2',
59
+ label: `Change to Heading 1`,
60
+ keybind: '2',
61
+ when: 'commandMode',
62
+ },
63
+ ChangeCellToHeading3: {
64
+ id: 'notebook:change-cell-to-heading-3',
65
+ label: `Change to Heading 1`,
66
+ keybind: '3',
67
+ when: 'commandMode',
68
+ },
69
+ ChangeCellToHeading4: {
70
+ id: 'notebook:change-cell-to-heading-4',
71
+ label: `Change to Heading 1`,
72
+ keybind: '4',
73
+ when: 'commandMode',
74
+ },
75
+ ChangeCellToHeading5: {
76
+ id: 'notebook:change-cell-to-heading-5',
77
+ label: `Change to Heading 1`,
78
+ keybind: '5',
79
+ when: 'commandMode',
80
+ },
81
+ ChangeCellToHeading6: {
82
+ id: 'notebook:change-cell-to-heading-6',
83
+ label: `Change to Heading 1`,
84
+ keybind: '6',
85
+ when: 'commandMode',
86
+ },
87
+ ChangeCellToMarkdown: {
88
+ id: 'notebook:change-cell-to-markdown',
89
+ label: `Change to Markdown Cell Type`,
90
+ keybind: 'M',
91
+ when: 'commandMode',
92
+ },
93
+ ChangeCellToRaw: {
94
+ id: 'notebook:change-cell-to-raw',
95
+ label: `Change to Raw Cell Type`,
96
+ keybind: 'R',
97
+ when: 'commandMode',
98
+ },
99
+ ClearAllCellOutput: {
100
+ id: 'notebook:clear-all-cell-outputs',
101
+ label: `Clear Outputs of All Cells`,
102
+ icon: ClearOutlined,
103
+ },
104
+ ClearCellOutput: {
105
+ id: 'notebook:clear-cell-outputs',
106
+ label: `Clear Cell Output`,
107
+ },
108
+ CloseAndShutdown: {
109
+ id: 'notebook:close-and-shutdown',
110
+ label: `Close and Shut Down Notebook`,
111
+ icon: PoweroffOutlined,
112
+ },
113
+ // TODO: 确定命令含义
114
+ CollapseAllHeadings: {
115
+ id: 'notebook:collapse-all-headings',
116
+ label: `Collapse All Headings`,
117
+ keybind: 'ctrlcmd+shift+left',
118
+ },
119
+ CopyCell: {
120
+ id: 'notebook:copy-cell',
121
+ label: `Copy Cells`,
122
+ keybind: 'C',
123
+ icon: CopyOutlined,
124
+ when: 'commandMode',
125
+ },
126
+ // TODO: 确定命令含义
127
+ CopyToClipboard: {
128
+ id: 'notebook:copy-to-clipboard',
129
+ label: `Copy Output to Clipboard`,
130
+ },
131
+ // TODO: 确定命令含义
132
+ CreateOutputView: {
133
+ id: 'notebook:create-output-view',
134
+ label: `Create New View for Cell Output`,
135
+ },
136
+ CutCell: {
137
+ id: 'notebook:cut-cell',
138
+ label: `Cut Cells`,
139
+ keybind: 'x',
140
+ icon: ScissorOutlined,
141
+ when: 'commandMode',
142
+ },
143
+ DeleteCell: {
144
+ id: 'notebook:delete-cell',
145
+ label: `Delete Cells`,
146
+ icon: DeleteOutlined,
147
+ keybind: 'D D',
148
+ when: 'commandMode',
149
+ },
150
+ DeselectAll: {
151
+ id: 'notebook:deselect-all',
152
+ label: `Deselect All Cells`,
153
+ },
154
+ DisableOutputScrolling: {
155
+ id: 'notebook:disable-output-scrolling',
156
+ label: `Disable Scrolling for Outputs`,
157
+ },
158
+ DuplicateBelow: {
159
+ id: 'notebook:duplicate-below',
160
+ label: `Duplicate Cells Below`,
161
+ },
162
+ EnableOutputScrolling: {
163
+ id: 'notebook:enable-output-scrolling',
164
+ label: `Enable Scrolling for Outputs`,
165
+ },
166
+ EnterCommandMode: {
167
+ id: 'notebook:enter-command-mode',
168
+ label: `Enter Command Mode`,
169
+ keybind: 'esc',
170
+ },
171
+ EnterEditMode: {
172
+ id: 'notebook:enter-edit-mode',
173
+ label: `Enter Edit Mode`,
174
+ keybind: 'enter',
175
+ when: 'commandMode',
176
+ },
177
+
178
+ ExpandAllHeadings: {
179
+ id: 'notebook:expand-all-headings',
180
+ label: `Expand All Headings`,
181
+ keybind: 'ctrlcmd+shift+right',
182
+ when: 'commandMode',
183
+ },
184
+
185
+ ExportToFormat: {
186
+ id: 'notebook:export-to-format',
187
+ label: `Save and Export Notebook to the given format`,
188
+ },
189
+
190
+ ExtendMarkedCellsAbove: {
191
+ id: 'notebook:extend-marked-cells-above',
192
+ label: `Extend Selection Above`,
193
+ keybind: ['shift+up', 'shift+K'],
194
+ when: 'commandMode',
195
+ },
196
+ ExtendMarkedCellsBelow: {
197
+ id: 'notebook:extend-marked-cells-below',
198
+ label: `Extend Selection Below`,
199
+ keybind: ['shift+down', 'shift+J'],
200
+ when: 'commandMode',
201
+ },
202
+ //TODO:
203
+ ExtendMarkedCellsBottom: {
204
+ id: 'notebook:extend-marked-cells-bottom',
205
+ label: `Extend Selection to Bottom`,
206
+ keybind: 'shift+end',
207
+ when: 'commandMode',
208
+ },
209
+ //TODO:
210
+ ExtendMarkedCellsTop: {
211
+ id: 'notebook:extend-marked-cells-top',
212
+ label: `Extend Selection to Top`,
213
+ keybind: 'shift+home',
214
+ when: 'commandMode',
215
+ },
216
+ HideAllCell: {
217
+ id: 'notebook:hide-all-cell',
218
+ },
219
+ HideAllCellCode: {
220
+ id: 'notebook:hide-all-cell-code',
221
+ label: `Collapse All Code`,
222
+ },
223
+ HideAllCellOutput: {
224
+ id: 'notebook:hide-all-cell-output',
225
+ label: `Collapse All Outputs`,
226
+ },
227
+ HideCellCode: {
228
+ id: 'notebook:hide-cell-code',
229
+ label: `Collapse Selected Code`,
230
+ },
231
+ HideOrShowCellCode: {
232
+ id: 'notebook:hide-or-show-cell-code',
233
+ label: `Hide or show Selected Code`,
234
+ keybind: `ctrlcmd+'`,
235
+ },
236
+ HideCellOutputs: {
237
+ id: 'notebook:hide-cell-outputs',
238
+ label: `Collapse Selected Outputs`,
239
+ icon: EyeInvisibleOutlined,
240
+ },
241
+ HideOrShowOutputs: {
242
+ id: 'notebook:hide-or-show-outputs',
243
+ label: `Hide or show Selected outputs`,
244
+ keybind: 'ctrlcmd+o',
245
+ },
246
+ InsertCellAbove: {
247
+ id: 'notebook:insert-cell-above',
248
+ label: `Insert Cell Above`,
249
+ keybind: 'A',
250
+ when: 'commandMode',
251
+ },
252
+ InsertCellBelow: {
253
+ id: 'notebook:insert-cell-below',
254
+ label: `Insert Cell Below`,
255
+ keybind: 'B',
256
+ icon: PlusOutlined,
257
+ when: 'commandMode',
258
+ },
259
+ InsertHeadingAbove: {
260
+ id: 'notebook:insert-heading-above',
261
+ label: `Insert Heading Above Current Heading`,
262
+ keybind: 'shift+A',
263
+ when: 'commandMode',
264
+ },
265
+ InsertHeadingBelow: {
266
+ id: 'notebook:insert-heading-below',
267
+ label: `Insert Heading Below Current Heading`,
268
+ keybind: 'shift+B',
269
+ when: 'commandMode',
270
+ },
271
+ MergeCellAbove: {
272
+ id: 'notebook:merge-cell-above',
273
+ label: `Merge Cell Above`,
274
+ keybind: 'ctrlcmd+backspace',
275
+ when: 'commandMode',
276
+ },
277
+ MergeCellBelow: {
278
+ id: 'notebook:merge-cell-below',
279
+ label: `Merge Cell Below`,
280
+ keybind: 'ctrlcmd+shift+M',
281
+ when: 'commandMode',
282
+ },
283
+ MergeCells: {
284
+ id: 'notebook:merge-cells',
285
+ label: `Merge Selected Cells`,
286
+ keybind: 'shift+M',
287
+ when: 'commandMode',
288
+ },
289
+ MoveCellDown: {
290
+ id: 'notebook:move-cell-down',
291
+ label: `Move Cells Down`,
292
+ keybind: 'ctrlcmd+shift+down',
293
+ icon: MoveDownOutlined,
294
+ when: 'commandMode',
295
+ },
296
+ MoveCellUp: {
297
+ id: 'notebook:move-cell-up',
298
+ label: `Move Cells Up`,
299
+ keybind: 'ctrlcmd+shift+up',
300
+ icon: MoveUpOutlined,
301
+ when: 'commandMode',
302
+ },
303
+ MoveCursorDown: {
304
+ id: 'notebook:move-cursor-down',
305
+ label: `Select Cell Below`,
306
+ keybind: ['down', 'J'],
307
+ when: 'commandMode',
308
+ },
309
+ MoveCursorUp: {
310
+ id: 'notebook:move-cursor-up',
311
+ label: `Select Cell Above`,
312
+ keybind: ['up', 'K'],
313
+ when: 'commandMode',
314
+ },
315
+
316
+ MoveCursorHeadingAboveOrCollapse: {
317
+ id: 'notebook:move-cursor-heading-above-or-collapse',
318
+ label: `Select Heading Above or Collapse Heading`,
319
+ keybind: 'left',
320
+ when: 'commandMode',
321
+ },
322
+ MoveCursorHeadingBelowOrExpand: {
323
+ id: 'notebook:move-cursor-heading-below-or-expand',
324
+ label: `Select Heading Below or Expand Heading`,
325
+ keybind: 'right',
326
+ when: 'commandMode',
327
+ },
328
+ PasteAndReplaceCell: {
329
+ id: 'notebook:paste-and-replace-cell',
330
+ label: `Paste Cells and Replace`,
331
+ },
332
+ PasteCellAbove: {
333
+ id: 'notebook:paste-cell-above',
334
+ label: `Paste Cells Above`,
335
+ },
336
+ PasteCellBelow: {
337
+ id: 'notebook:paste-cell-below',
338
+ label: `Paste Cells Below`,
339
+ keybind: 'V',
340
+ icon: SnippetsOutlined,
341
+ when: 'commandMode',
342
+ },
343
+ Redo: {
344
+ id: 'notebook:redo',
345
+ label: `Redo`,
346
+ },
347
+ RedoCellAction: {
348
+ id: 'notebook:redo-cell-action',
349
+ label: `Redo Cell Operation`,
350
+ icon: Redo,
351
+ keybind: 'shift+Z',
352
+ when: 'commandMode',
353
+ },
354
+ RenderAllMarkdown: {
355
+ id: 'notebook:render-all-markdown',
356
+ label: `Render All Markdown Cells`,
357
+ },
358
+ ReplaceSelection: {
359
+ id: 'notebook:replace-selection',
360
+ label: `Replace Selection in Notebook Cell`,
361
+ },
362
+ RestartAndRunToSelected: {
363
+ id: 'notebook:restart-and-run-to-selected',
364
+ label: l10n.t('Restart and Run up to Selected Cell…'),
365
+ },
366
+ RestartClearOutput: {
367
+ id: 'notebook:restart-clear-output',
368
+ label: l10n.t('Restart and Clear Outputs of All Cells…'),
369
+ icon: Reload,
370
+ },
371
+ RestartRunAll: {
372
+ id: 'notebook:restart-run-all',
373
+ label: l10n.t('Restart and Run All Cells…'),
374
+ },
375
+ RunAllAbove: {
376
+ id: 'notebook:run-all-above',
377
+ label: `Run All Above Selected Cell`,
378
+ },
379
+ RunAllBelow: {
380
+ id: 'notebook:run-all-below',
381
+ label: `Run All Below Selected Cell`,
382
+ },
383
+ RunAllCells: {
384
+ id: 'notebook:run-all-cells',
385
+ label: `Run All Cells`,
386
+ },
387
+ RunCell: {
388
+ id: 'notebook:run-cell',
389
+ icon: PlayCircleOutlined,
390
+ // label: `Run Selected Cells and Don't Advance`,
391
+ keybind: 'ctrlcmd+enter',
392
+ },
393
+ TopToolbarRunSelect: {
394
+ id: 'notebook:top-toolbar-run-select',
395
+ },
396
+ SideToolbarRunSelect: {
397
+ id: 'notebook:side-toolbar-run-select',
398
+ },
399
+ RunCellAndInsertBelow: {
400
+ id: 'notebook:run-cell-and-insert-below',
401
+ label: `Run Selected Cells and Insert Below`,
402
+ keybind: 'alt+enter',
403
+ },
404
+ RunCellAndSelectNext: {
405
+ id: 'notebook:run-cell-and-select-next',
406
+ label: `Run Selected Cells and Select Below`,
407
+ keybind: 'shift+enter',
408
+ },
409
+ // TODO: 确认是否保留
410
+ RunInConsole: {
411
+ id: 'notebook:run-in-console',
412
+ label: `Run Selected Text or Current Line in Console`,
413
+ },
414
+ // TODO:
415
+ SelectAll: {
416
+ id: 'notebook:select-all',
417
+ label: `Select All Cells`,
418
+ keybind: 'ctrlcmd+A',
419
+ when: 'commandMode',
420
+ },
421
+ SelectLastRunCell: {
422
+ id: 'notebook:select-last-run-cell',
423
+ label: `Select current running or last run cell`,
424
+ },
425
+ // TODO: 确认命令含义
426
+ SetSideBySideRatio: {
427
+ id: 'notebook:set-side-by-side-ratio',
428
+ label: `Set Side by Side Ratio`,
429
+ },
430
+ ShowAllCell: {
431
+ id: 'notebook:show-all-cell',
432
+ label: `Expand All Cell`,
433
+ },
434
+ ShowAllCellCode: {
435
+ id: 'notebook:show-all-cell-code',
436
+ label: `Expand All Code`,
437
+ },
438
+ ShowAllCellOutputs: {
439
+ id: 'notebook:show-all-cell-outputs',
440
+ label: `Expand All Outputs`,
441
+ icon: EyeOutlined,
442
+ },
443
+ ShowCellCode: {
444
+ id: 'notebook:show-cell-code',
445
+ label: `Expand Selected Code`,
446
+ },
447
+ ShowCellOutputs: {
448
+ id: 'notebook:show-cell-outputs',
449
+ label: `Expand Selected Outputs`,
450
+ },
451
+ SplitCellAntCursor: {
452
+ id: 'notebook:split-cell-at-cursor',
453
+ label: `Split Cell`,
454
+ keybind: 'ctrlcmd+shift+-',
455
+ },
456
+ ToggleAllCellLineNumbers: {
457
+ id: 'notebook:toggle-all-cell-line-numbers',
458
+ label: `Show Line Numbers`,
459
+ keybind: 'shift+L',
460
+ },
461
+ ToggleAutoclosingBrackets: {
462
+ id: 'notebook:toggle-autoclosing-brackets',
463
+ label: `Auto Close Brackets for All Notebook Cell Types`,
464
+ },
465
+ ToggleHeadingCollapse: {
466
+ id: 'notebook:toggle-heading-collapse',
467
+ label: `Toggle Collapse Notebook Heading`,
468
+ },
469
+ ToggleRenderSideBySideCurrent: {
470
+ id: 'notebook:toggle-render-side-by-side-current',
471
+ label: `Render Side-by-Side`,
472
+ keybind: 'shift+R',
473
+ when: 'commandMode',
474
+ },
475
+ Trust: {
476
+ id: 'notebook:trust',
477
+ label: `Trust Notebook`,
478
+ },
479
+ Undo: {
480
+ id: 'notebook:undo',
481
+ label: `Undo`,
482
+ },
483
+ UndoCellAction: {
484
+ id: 'notebook:undo-cell-action',
485
+ label: `Undo Cell Operation`,
486
+ keybind: 'Z',
487
+ icon: Undo,
488
+ when: 'commandMode',
489
+ },
490
+ More: {
491
+ id: 'notebook:more',
492
+ icon: MoreOutlined,
493
+ },
494
+ InsertCellBottom: {
495
+ id: 'notebook:insert-cell-bottom',
496
+ },
497
+ //#endregion
498
+ };
@@ -0,0 +1,22 @@
1
+ import type React from 'react';
2
+
3
+ import type { CellOptions, CellView } from '../libro-protocol.js';
4
+
5
+ export type CellExecutionTimeProvider = React.FC<{ cell: CellView }>;
6
+
7
+ export const CellExecutionTimeProvider = Symbol('CellExecutionTimeProvider');
8
+
9
+ export type CellInputBottonBlankProvider = React.FC<{ cell: CellView }>;
10
+
11
+ export const CellInputBottonBlankProvider = Symbol('CellInputBottonBlankProvider');
12
+
13
+ export type CellOutputVisulizationProvider = React.FC<{ cell: CellView }>;
14
+
15
+ export const CellOutputVisulizationProvider = Symbol('CellOutputVisulizationProvider');
16
+
17
+ export type BetweenCellProvider = React.FC<{
18
+ index: number;
19
+ addCell: (option: CellOptions, position?: number | undefined) => Promise<void>;
20
+ }>;
21
+
22
+ export const BetweenCellProvider = Symbol('BetweenCellProvider');