@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,1339 @@
1
+ import type { CommandRegistry } from '@difizen/mana-app';
2
+ import {
3
+ inject,
4
+ ModalService,
5
+ singleton,
6
+ CommandContribution,
7
+ } from '@difizen/mana-app';
8
+ import { equals } from '@difizen/mana-app';
9
+ import { v4 } from 'uuid';
10
+
11
+ import { LibroCellView, ExecutableCellModel } from '../cell/index.js';
12
+ import type { LibroEditorCellView } from '../cell/index.js';
13
+ import { LirboContextKey } from '../libro-context-key.js';
14
+ import type { CellView, NotebookView } from '../libro-protocol.js';
15
+ import { LibroToolbarArea } from '../libro-protocol.js';
16
+ import { LibroService } from '../libro-service.js';
17
+ import { LibroView } from '../libro-view.js';
18
+ import { RestartClearOutputModal } from '../toolbar/restart-clear-outputs-modal.js';
19
+ import { ShutdownModal } from '../toolbar/shutdown-modal.js';
20
+
21
+ import { DocumentCommands } from './document-commands.js';
22
+ import { LibroCommandRegister } from './libro-command-register.js';
23
+ import { NotebookCommands } from './notebook-commands.js';
24
+
25
+ @singleton({ contrib: CommandContribution })
26
+ export class LibroCommandContribution implements CommandContribution {
27
+ protected readonly modalService: ModalService;
28
+ protected readonly libroCommand: LibroCommandRegister;
29
+ protected readonly libroService: LibroService;
30
+ protected readonly lirboContextKey: LirboContextKey;
31
+
32
+ constructor(
33
+ @inject(ModalService) modalService: ModalService,
34
+ @inject(LibroCommandRegister) libroCommand: LibroCommandRegister,
35
+ @inject(LibroService) libroService: LibroService,
36
+ @inject(LirboContextKey) lirboContextKey: LirboContextKey,
37
+ ) {
38
+ this.libroCommand = libroCommand;
39
+ this.modalService = modalService;
40
+ this.libroService = libroService;
41
+ this.lirboContextKey = lirboContextKey;
42
+ }
43
+
44
+ registerCommands(command: CommandRegistry): void {
45
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['EnterEditMode'], {
46
+ execute: async () => {
47
+ this.libroService.active?.enterEditMode();
48
+ },
49
+ isEnabled: (_cell, libro) => {
50
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
51
+ return false;
52
+ }
53
+ return true;
54
+ },
55
+ });
56
+ this.libroCommand.registerLibroCommand(
57
+ command,
58
+ NotebookCommands['EnterCommandMode'],
59
+ {
60
+ execute: () => {
61
+ this.libroService.active?.enterCommandMode(true);
62
+ },
63
+ },
64
+ );
65
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['SelectAll'], {
66
+ execute: (cell, libro) => {
67
+ if (
68
+ !cell ||
69
+ !libro ||
70
+ !(cell instanceof LibroCellView) ||
71
+ !(libro instanceof LibroView)
72
+ ) {
73
+ return;
74
+ }
75
+ libro.selectAllCell();
76
+ },
77
+ });
78
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['RunCell'], {
79
+ execute: async (cell, libro) => {
80
+ if (
81
+ !cell ||
82
+ !libro ||
83
+ !(cell instanceof LibroCellView) ||
84
+ !(libro instanceof LibroView)
85
+ ) {
86
+ return;
87
+ }
88
+ libro.runCell(cell);
89
+ },
90
+ isEnabled: (_cell, libro) => {
91
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
92
+ return false;
93
+ }
94
+ return true;
95
+ },
96
+ });
97
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['RunAllCells'], {
98
+ execute: async (_cell, libro) => {
99
+ if (!libro || !(libro instanceof LibroView)) {
100
+ return;
101
+ }
102
+ libro.runAllCell();
103
+ },
104
+ });
105
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['RunAllAbove'], {
106
+ execute: async (cell, libro) => {
107
+ if (
108
+ !cell ||
109
+ !libro ||
110
+ !(cell instanceof LibroCellView) ||
111
+ !(libro instanceof LibroView)
112
+ ) {
113
+ return;
114
+ }
115
+ libro.runAllAbove(cell);
116
+ },
117
+ });
118
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['RunAllBelow'], {
119
+ execute: async (cell, libro) => {
120
+ if (
121
+ !cell ||
122
+ !libro ||
123
+ !(cell instanceof LibroCellView) ||
124
+ !(libro instanceof LibroView)
125
+ ) {
126
+ return;
127
+ }
128
+ libro.runAllBelow(cell);
129
+ },
130
+ });
131
+ this.libroCommand.registerLibroCommand(
132
+ command,
133
+ NotebookCommands['RunCellAndSelectNext'],
134
+ {
135
+ execute: async (cell, libro) => {
136
+ if (
137
+ !cell ||
138
+ !libro ||
139
+ !(cell instanceof LibroCellView) ||
140
+ !(libro instanceof LibroView)
141
+ ) {
142
+ return;
143
+ }
144
+ libro.runCellandSelectNext(cell);
145
+ },
146
+ isEnabled: (_cell, libro) => {
147
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
148
+ return false;
149
+ }
150
+ return true;
151
+ },
152
+ },
153
+ );
154
+ this.libroCommand.registerLibroCommand(
155
+ command,
156
+ NotebookCommands['RunCellAndInsertBelow'],
157
+ {
158
+ execute: async (cell, libro) => {
159
+ if (
160
+ !cell ||
161
+ !libro ||
162
+ !(cell instanceof LibroCellView) ||
163
+ !(libro instanceof LibroView)
164
+ ) {
165
+ return;
166
+ }
167
+ libro.runCellandInsertBelow(cell);
168
+ },
169
+ isEnabled: (_cell, libro) => {
170
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
171
+ return false;
172
+ }
173
+ return true;
174
+ },
175
+ },
176
+ );
177
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['Interrupt'], {
178
+ execute: async (_cell, libro) => {
179
+ if (!libro || !(libro instanceof LibroView)) {
180
+ return false;
181
+ }
182
+ if (libro.model.interrupt) {
183
+ libro.model.interrupt();
184
+ }
185
+ return;
186
+ },
187
+ isEnabled: (_cell, libro) => {
188
+ if (!libro || !(libro instanceof LibroView)) {
189
+ return false;
190
+ }
191
+ return (
192
+ libro.model
193
+ .getCells()
194
+ .findIndex(
195
+ (item) => ExecutableCellModel.is(item.model) && item.model.executing,
196
+ ) >= 0
197
+ );
198
+ },
199
+ isVisible: (_cell, libro, path) => {
200
+ if (!libro || !(libro instanceof LibroView)) {
201
+ return false;
202
+ }
203
+ return (
204
+ !libro?.model.quickEditMode &&
205
+ !libro?.model.readOnly &&
206
+ path === LibroToolbarArea.HeaderCenter
207
+ );
208
+ },
209
+ });
210
+ this.libroCommand.registerLibroCommand(
211
+ command,
212
+ NotebookCommands['RestartClearOutput'],
213
+ {
214
+ execute: async (_cell, libro) => {
215
+ if (!libro || !(libro instanceof LibroView)) {
216
+ return false;
217
+ }
218
+ this.modalService.openModal(RestartClearOutputModal, libro);
219
+ return;
220
+ },
221
+ isVisible: (_cell, libro, path) => {
222
+ if (!libro || !(libro instanceof LibroView)) {
223
+ return false;
224
+ }
225
+ return (
226
+ !libro?.model.quickEditMode &&
227
+ !libro?.model.readOnly &&
228
+ path === LibroToolbarArea.HeaderCenter
229
+ );
230
+ },
231
+ },
232
+ );
233
+ this.libroCommand.registerLibroCommand(
234
+ command,
235
+ NotebookCommands['CloseAndShutdown'],
236
+ {
237
+ execute: async (_cell, libro) => {
238
+ if (!libro || !(libro instanceof LibroView)) {
239
+ return false;
240
+ }
241
+ this.modalService.openModal(ShutdownModal, libro);
242
+ return;
243
+ },
244
+ isVisible: () => false,
245
+ // isVisible: (cell, libro, path) => {
246
+ // if (!libro || !(libro instanceof LibroView)) return false;
247
+ // if (path !== LibroToolbarArea.HeaderCenter || libro.model.quickEditMode) return false;
248
+ // return true;
249
+ // },
250
+ },
251
+ );
252
+ this.libroCommand.registerLibroCommand(
253
+ command,
254
+ NotebookCommands['InsertCellBelow'],
255
+ {
256
+ execute: async (cell, libro) => {
257
+ if (!libro || !(libro instanceof LibroView)) {
258
+ return;
259
+ }
260
+ if (!cell || !(cell instanceof LibroCellView)) {
261
+ libro.addCell(
262
+ { id: v4(), cell: { cell_type: 'code', source: '', metadata: {} } },
263
+ 0,
264
+ );
265
+ } else {
266
+ const cellIndex = libro.model.cells.findIndex((item) => equals(item, cell));
267
+ libro.addCell(
268
+ {
269
+ id: v4(),
270
+ cell: { cell_type: cell.model.type, source: '', metadata: {} },
271
+ },
272
+ cellIndex + 1,
273
+ );
274
+ }
275
+ },
276
+ // isVisible: () => false,
277
+ isVisible: (_cell, libro, path) => {
278
+ if (!libro || !(libro instanceof LibroView)) {
279
+ return false;
280
+ }
281
+ return !libro?.model.readOnly && path === LibroToolbarArea.CellRight;
282
+ },
283
+ isEnabled: (_cell, libro) => {
284
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
285
+ return false;
286
+ }
287
+ return true;
288
+ },
289
+ },
290
+ );
291
+ this.libroCommand.registerLibroCommand(
292
+ command,
293
+ NotebookCommands['InsertCellAbove'],
294
+ {
295
+ execute: async (cell, libro) => {
296
+ if (
297
+ !cell ||
298
+ !libro ||
299
+ !(cell instanceof LibroCellView) ||
300
+ !(libro instanceof LibroView)
301
+ ) {
302
+ return;
303
+ }
304
+ const cellIndex = libro.model.cells.findIndex((item) => equals(item, cell));
305
+ if (cellIndex > -1) {
306
+ libro.addCellAbove(
307
+ {
308
+ id: v4(),
309
+ cell: { cell_type: cell.model.type, source: '', metadata: {} },
310
+ },
311
+ cellIndex,
312
+ );
313
+ }
314
+ },
315
+ isEnabled: (_cell, libro) => {
316
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
317
+ return false;
318
+ }
319
+ return true;
320
+ },
321
+ },
322
+ );
323
+
324
+ command.registerCommand(NotebookCommands['InsertCellBottom'], {
325
+ execute: async (libro, targetType) => {
326
+ if (!libro || !(libro instanceof LibroView)) {
327
+ return;
328
+ }
329
+ const nextIndex = libro.model.cells.length;
330
+ libro.addCell(
331
+ {
332
+ cell: {
333
+ cell_type: targetType,
334
+ metadata: {},
335
+ source: '',
336
+ },
337
+ },
338
+ nextIndex,
339
+ );
340
+ },
341
+ });
342
+
343
+ this.libroCommand.registerLibroCommand(
344
+ command,
345
+ NotebookCommands['MoveCursorDown'],
346
+ {
347
+ execute: async (cell, libro) => {
348
+ if (
349
+ !cell ||
350
+ !libro ||
351
+ !(cell instanceof LibroCellView) ||
352
+ !(libro instanceof LibroView)
353
+ ) {
354
+ return;
355
+ }
356
+ libro.moveCursorDown(cell);
357
+ },
358
+ },
359
+ );
360
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['MoveCursorUp'], {
361
+ execute: async (cell, libro) => {
362
+ if (
363
+ !cell ||
364
+ !libro ||
365
+ !(cell instanceof LibroCellView) ||
366
+ !(libro instanceof LibroView)
367
+ ) {
368
+ return;
369
+ }
370
+ libro.moveCursorUp(cell);
371
+ },
372
+ });
373
+ this.libroCommand.registerLibroCommand(
374
+ command,
375
+ NotebookCommands['MergeCellBelow'],
376
+ {
377
+ execute: async (cell, libro) => {
378
+ if (
379
+ !cell ||
380
+ !libro ||
381
+ !(cell instanceof LibroCellView) ||
382
+ !(libro instanceof LibroView)
383
+ ) {
384
+ return;
385
+ }
386
+ libro.mergeCellBelow(cell);
387
+ },
388
+ isEnabled: (_cell, libro) => {
389
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
390
+ return false;
391
+ }
392
+ return true;
393
+ },
394
+ },
395
+ );
396
+ this.libroCommand.registerLibroCommand(
397
+ command,
398
+ NotebookCommands['MergeCellAbove'],
399
+ {
400
+ execute: async (cell, libro) => {
401
+ if (
402
+ !cell ||
403
+ !libro ||
404
+ !(cell instanceof LibroCellView) ||
405
+ !(libro instanceof LibroView)
406
+ ) {
407
+ return;
408
+ }
409
+ libro.mergeCellAbove(cell);
410
+ },
411
+ isEnabled: (_cell, libro) => {
412
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
413
+ return false;
414
+ }
415
+ return true;
416
+ },
417
+ },
418
+ );
419
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['MergeCells'], {
420
+ execute: async (cell, libro) => {
421
+ if (
422
+ !cell ||
423
+ !libro ||
424
+ !(cell instanceof LibroCellView) ||
425
+ !(libro instanceof LibroView)
426
+ ) {
427
+ return;
428
+ }
429
+ libro.mergeCells(cell);
430
+ },
431
+ isEnabled: (_cell, libro) => {
432
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
433
+ return false;
434
+ }
435
+ return true;
436
+ },
437
+ });
438
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['DeleteCell'], {
439
+ execute: async (cell, libro) => {
440
+ if (
441
+ !cell ||
442
+ !libro ||
443
+ !(cell instanceof LibroCellView) ||
444
+ !(libro instanceof LibroView)
445
+ ) {
446
+ return;
447
+ }
448
+ libro.deleteCell(cell);
449
+ },
450
+ isVisible: (_cell, libro, path) => {
451
+ if (!libro || !(libro instanceof LibroView)) {
452
+ return false;
453
+ }
454
+ return !libro?.model.readOnly && path === LibroToolbarArea.CellRight;
455
+ },
456
+ isEnabled: (_cell, libro) => {
457
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
458
+ return false;
459
+ }
460
+ return true;
461
+ },
462
+ });
463
+ this.libroCommand.registerLibroCommand(
464
+ command,
465
+ NotebookCommands['ClearCellOutput'],
466
+ {
467
+ execute: async (cell, libro) => {
468
+ if (
469
+ !cell ||
470
+ !libro ||
471
+ !(cell instanceof LibroCellView) ||
472
+ !(libro instanceof LibroView)
473
+ ) {
474
+ return;
475
+ }
476
+ libro.clearOutputs(cell);
477
+ },
478
+ isEnabled: (_cell, libro) => {
479
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
480
+ return false;
481
+ }
482
+ return true;
483
+ },
484
+ },
485
+ );
486
+ this.libroCommand.registerLibroCommand(
487
+ command,
488
+ NotebookCommands['ClearAllCellOutput'],
489
+ {
490
+ execute: async (cell, libro) => {
491
+ if (
492
+ !cell ||
493
+ !libro ||
494
+ !(cell instanceof LibroCellView) ||
495
+ !(libro instanceof LibroView)
496
+ ) {
497
+ return;
498
+ }
499
+ libro.clearAllOutputs();
500
+ },
501
+ isVisible: (_cell, libro, path) => {
502
+ if (!libro || !(libro instanceof LibroView)) {
503
+ return false;
504
+ }
505
+ return !libro?.model.readOnly && path === LibroToolbarArea.HeaderCenter;
506
+ },
507
+ isEnabled: (_cell, libro) => {
508
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
509
+ return false;
510
+ }
511
+ return true;
512
+ },
513
+ },
514
+ );
515
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['MoveCellUp'], {
516
+ execute: async (cell, libro) => {
517
+ if (
518
+ !cell ||
519
+ !libro ||
520
+ !(cell instanceof LibroCellView) ||
521
+ !(libro instanceof LibroView)
522
+ ) {
523
+ return;
524
+ }
525
+ libro.moveUpCell(cell);
526
+ },
527
+ isVisible: (_cell, _libro, path) => {
528
+ return path === LibroToolbarArea.CellRight;
529
+ },
530
+ isEnabled: (cell, libro) => {
531
+ if (
532
+ !cell ||
533
+ !libro ||
534
+ !(cell instanceof LibroCellView) ||
535
+ !(libro instanceof LibroView) ||
536
+ libro.model.readOnly
537
+ ) {
538
+ return false;
539
+ }
540
+ const cellIndex = libro.model
541
+ .getCells()
542
+ .findIndex((item) => equals(item, cell));
543
+ return cellIndex > 0;
544
+ },
545
+ });
546
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['MoveCellDown'], {
547
+ execute: async (cell, libro) => {
548
+ if (
549
+ !cell ||
550
+ !libro ||
551
+ !(cell instanceof LibroCellView) ||
552
+ !(libro instanceof LibroView)
553
+ ) {
554
+ return;
555
+ }
556
+ libro.moveDownCell(cell);
557
+ },
558
+ isEnabled: (cell, libro) => {
559
+ if (
560
+ !cell ||
561
+ !libro ||
562
+ !(cell instanceof LibroCellView) ||
563
+ !(libro instanceof LibroView) ||
564
+ libro.model.readOnly
565
+ ) {
566
+ return false;
567
+ }
568
+ const cellIndex = libro.model
569
+ .getCells()
570
+ .findIndex((item) => equals(item, cell));
571
+ return cellIndex !== libro.model.getCells().length - 1;
572
+ },
573
+ isVisible: (_cell, _libro, path) => {
574
+ return path === LibroToolbarArea.CellRight;
575
+ },
576
+ });
577
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['CopyCell'], {
578
+ execute: async (cell, libro) => {
579
+ if (
580
+ !cell ||
581
+ !libro ||
582
+ !(cell instanceof LibroCellView) ||
583
+ !(libro instanceof LibroView)
584
+ ) {
585
+ return;
586
+ }
587
+ libro.copyCell(cell);
588
+ },
589
+ isVisible: () => false,
590
+ // isVisible: (cell, libro, path) => {
591
+ // if (
592
+ // ![LibroToolbarArea.CellRight, LibroToolbarArea.HeaderCenter].find(item => item === path)
593
+ // ) {
594
+ // return false;
595
+ // }
596
+ // return true;
597
+ // },
598
+ isEnabled: (_cell, libro) => {
599
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
600
+ return false;
601
+ }
602
+ return true;
603
+ },
604
+ });
605
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['CutCell'], {
606
+ execute: async (cell, libro) => {
607
+ if (
608
+ !cell ||
609
+ !libro ||
610
+ !(cell instanceof LibroCellView) ||
611
+ !(libro instanceof LibroView)
612
+ ) {
613
+ return;
614
+ }
615
+ libro.cutCell(cell);
616
+ },
617
+ isVisible: () => false,
618
+ // isVisible: (cell, libro, path) => {
619
+ // if (
620
+ // ![LibroToolbarArea.CellRight, LibroToolbarArea.HeaderCenter].find(item => item === path)
621
+ // ) {
622
+ // return false;
623
+ // }
624
+ // return true;
625
+ // },
626
+ isEnabled: (_cell, libro) => {
627
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
628
+ return false;
629
+ }
630
+ return true;
631
+ },
632
+ });
633
+ this.libroCommand.registerLibroCommand(
634
+ command,
635
+ NotebookCommands['PasteCellAbove'],
636
+ {
637
+ execute: async (cell, libro) => {
638
+ if (
639
+ !cell ||
640
+ !libro ||
641
+ !(cell instanceof LibroCellView) ||
642
+ !(libro instanceof LibroView)
643
+ ) {
644
+ return;
645
+ }
646
+ libro.pasteCellAbove(cell);
647
+ },
648
+ isEnabled: (_cell, libro) => {
649
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
650
+ return false;
651
+ }
652
+ return true;
653
+ },
654
+ },
655
+ );
656
+ this.libroCommand.registerLibroCommand(
657
+ command,
658
+ NotebookCommands['PasteCellBelow'],
659
+ {
660
+ execute: async (cell, libro) => {
661
+ if (
662
+ !cell ||
663
+ !libro ||
664
+ !(cell instanceof LibroCellView) ||
665
+ !(libro instanceof LibroView)
666
+ ) {
667
+ return;
668
+ }
669
+ libro.pasteCell(cell);
670
+ },
671
+ isVisible: () => false,
672
+ // isVisible: (cell, libro, path) => {
673
+ // if (
674
+ // ![LibroToolbarArea.CellRight, LibroToolbarArea.HeaderCenter].find(item => item === path)
675
+ // ) {
676
+ // return false;
677
+ // }
678
+ // return true;
679
+ // },
680
+ isEnabled: (_cell, libro) => {
681
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
682
+ return false;
683
+ }
684
+ return !!libro.model.lastClipboardInteraction;
685
+ },
686
+ },
687
+ );
688
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['HideCellCode'], {
689
+ execute: async (cell, libro) => {
690
+ if (
691
+ !cell ||
692
+ !libro ||
693
+ !(cell instanceof LibroCellView) ||
694
+ !(libro instanceof LibroView)
695
+ ) {
696
+ return;
697
+ }
698
+ libro.hideCellCode(cell);
699
+ },
700
+ isVisible: (_cell, _libro, path) => {
701
+ if (path === LibroToolbarArea.HeaderCenter) {
702
+ return true;
703
+ }
704
+ return false;
705
+ },
706
+ });
707
+ this.libroCommand.registerLibroCommand(
708
+ command,
709
+ NotebookCommands['HideOrShowCellCode'],
710
+ {
711
+ execute: async (cell, libro) => {
712
+ if (
713
+ !cell ||
714
+ !libro ||
715
+ !(cell instanceof LibroCellView) ||
716
+ !(libro instanceof LibroView)
717
+ ) {
718
+ return;
719
+ }
720
+ libro.hideOrShowCellCode(cell);
721
+ },
722
+ },
723
+ );
724
+ this.libroCommand.registerLibroCommand(
725
+ command,
726
+ NotebookCommands['HideCellOutputs'],
727
+ {
728
+ execute: async (cell, libro) => {
729
+ if (
730
+ !cell ||
731
+ !libro ||
732
+ !(cell instanceof LibroCellView) ||
733
+ !(libro instanceof LibroView)
734
+ ) {
735
+ return;
736
+ }
737
+ libro.hideOutputs(cell);
738
+ },
739
+ isVisible: (cell, _libro, path) => {
740
+ if (
741
+ cell &&
742
+ cell instanceof LibroCellView &&
743
+ ExecutableCellModel.is(cell.model) &&
744
+ path === LibroToolbarArea.CellRight
745
+ ) {
746
+ return true;
747
+ }
748
+ return false;
749
+ },
750
+ },
751
+ );
752
+ this.libroCommand.registerLibroCommand(
753
+ command,
754
+ NotebookCommands['HideOrShowOutputs'],
755
+ {
756
+ execute: async (cell, libro) => {
757
+ if (
758
+ !cell ||
759
+ !libro ||
760
+ !(cell instanceof LibroCellView) ||
761
+ !(libro instanceof LibroView)
762
+ ) {
763
+ return;
764
+ }
765
+ libro.hideOrShowOutputs(cell);
766
+ },
767
+ },
768
+ );
769
+ this.libroCommand.registerLibroCommand(
770
+ command,
771
+ NotebookCommands['HideAllCellCode'],
772
+ {
773
+ execute: async (cell, libro) => {
774
+ if (
775
+ !cell ||
776
+ !libro ||
777
+ !(cell instanceof LibroCellView) ||
778
+ !(libro instanceof LibroView)
779
+ ) {
780
+ return;
781
+ }
782
+ libro.hideAllCellCode();
783
+ },
784
+ },
785
+ );
786
+ this.libroCommand.registerLibroCommand(
787
+ command,
788
+ NotebookCommands['HideAllCellOutput'],
789
+ {
790
+ execute: async (cell, libro) => {
791
+ if (
792
+ !cell ||
793
+ !libro ||
794
+ !(cell instanceof LibroCellView) ||
795
+ !(libro instanceof LibroView)
796
+ ) {
797
+ return;
798
+ }
799
+ libro.hideAllOutputs();
800
+ },
801
+ },
802
+ );
803
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['HideAllCell'], {
804
+ execute: () => {
805
+ //
806
+ },
807
+ isVisible: (_cell, libro, path) => {
808
+ if (!libro || !(libro instanceof LibroView)) {
809
+ return false;
810
+ }
811
+ return !libro?.model.readOnly && path === LibroToolbarArea.HeaderCenter;
812
+ },
813
+ isEnabled: (_cell, libro) => {
814
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
815
+ return false;
816
+ }
817
+ return true;
818
+ },
819
+ });
820
+ this.libroCommand.registerLibroCommand(
821
+ command,
822
+ NotebookCommands['ShowCellOutputs'],
823
+ {
824
+ execute: async (cell, libro) => {
825
+ if (
826
+ !cell ||
827
+ !libro ||
828
+ !(cell instanceof LibroCellView) ||
829
+ !(libro instanceof LibroView)
830
+ ) {
831
+ return;
832
+ }
833
+ libro.showCellOutputs(cell);
834
+ },
835
+ },
836
+ );
837
+ this.libroCommand.registerLibroCommand(
838
+ command,
839
+ NotebookCommands['ShowAllCellOutputs'],
840
+ {
841
+ execute: async (cell, libro) => {
842
+ if (
843
+ !cell ||
844
+ !libro ||
845
+ !(cell instanceof LibroCellView) ||
846
+ !(libro instanceof LibroView)
847
+ ) {
848
+ return;
849
+ }
850
+ libro.showAllCellOutputs();
851
+ },
852
+ },
853
+ );
854
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['ShowCellCode'], {
855
+ execute: async (cell, libro) => {
856
+ if (
857
+ !cell ||
858
+ !libro ||
859
+ !(cell instanceof LibroCellView) ||
860
+ !(libro instanceof LibroView)
861
+ ) {
862
+ return;
863
+ }
864
+ libro.showCellCode(cell);
865
+ },
866
+ });
867
+ this.libroCommand.registerLibroCommand(
868
+ command,
869
+ NotebookCommands['ShowAllCellCode'],
870
+ {
871
+ execute: async (cell, libro) => {
872
+ if (
873
+ !cell ||
874
+ !libro ||
875
+ !(cell instanceof LibroCellView) ||
876
+ !(libro instanceof LibroView)
877
+ ) {
878
+ return;
879
+ }
880
+ libro.showAllCellCode();
881
+ },
882
+ },
883
+ );
884
+ this.libroCommand.registerLibroCommand(
885
+ command,
886
+ NotebookCommands['ExtendMarkedCellsAbove'],
887
+ {
888
+ execute: async (cell, libro) => {
889
+ if (
890
+ !cell ||
891
+ !libro ||
892
+ !(cell instanceof LibroCellView) ||
893
+ !(libro instanceof LibroView)
894
+ ) {
895
+ return;
896
+ }
897
+ libro.extendSelectionAbove();
898
+ },
899
+ },
900
+ );
901
+ this.libroCommand.registerLibroCommand(
902
+ command,
903
+ NotebookCommands['ExtendMarkedCellsTop'],
904
+ {
905
+ execute: async (cell, libro) => {
906
+ if (
907
+ !cell ||
908
+ !libro ||
909
+ !(cell instanceof LibroCellView) ||
910
+ !(libro instanceof LibroView)
911
+ ) {
912
+ return;
913
+ }
914
+ libro.extendSelectionToTop();
915
+ },
916
+ },
917
+ );
918
+ this.libroCommand.registerLibroCommand(
919
+ command,
920
+ NotebookCommands['ExtendMarkedCellsBelow'],
921
+ {
922
+ execute: async (cell, libro) => {
923
+ if (
924
+ !cell ||
925
+ !libro ||
926
+ !(cell instanceof LibroCellView) ||
927
+ !(libro instanceof LibroView)
928
+ ) {
929
+ return;
930
+ }
931
+ libro.extendSelectionBelow();
932
+ },
933
+ },
934
+ );
935
+ this.libroCommand.registerLibroCommand(
936
+ command,
937
+ NotebookCommands['ExtendMarkedCellsBottom'],
938
+ {
939
+ execute: async (cell, libro) => {
940
+ if (
941
+ !cell ||
942
+ !libro ||
943
+ !(cell instanceof LibroCellView) ||
944
+ !(libro instanceof LibroView)
945
+ ) {
946
+ return;
947
+ }
948
+ libro.extendSelectionToBottom();
949
+ },
950
+ },
951
+ );
952
+ command.registerCommand(NotebookCommands['ChangeCellTo'], {
953
+ execute: async (cell, libro, _path, targetType) => {
954
+ if (
955
+ !cell ||
956
+ !libro ||
957
+ !(cell instanceof LibroCellView) ||
958
+ !(libro instanceof LibroView)
959
+ ) {
960
+ return;
961
+ }
962
+
963
+ if (targetType) {
964
+ libro.invertCell(cell, targetType);
965
+ }
966
+ },
967
+ isVisible: (_cell, libro, path) => {
968
+ if (!libro || !(libro instanceof LibroView)) {
969
+ return false;
970
+ }
971
+ return !libro?.model.readOnly && path === LibroToolbarArea.HeaderCenter;
972
+ },
973
+ isEnabled: (_cell, libro) => {
974
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
975
+ return false;
976
+ }
977
+ return true;
978
+ },
979
+ });
980
+ this.libroCommand.registerLibroCommand(
981
+ command,
982
+ NotebookCommands['ChangeCellToCode'],
983
+ {
984
+ execute: (cell: CellView | undefined, libro: NotebookView | undefined) => {
985
+ if (
986
+ !cell ||
987
+ !libro ||
988
+ !(cell instanceof LibroCellView) ||
989
+ !(libro instanceof LibroView)
990
+ ) {
991
+ return;
992
+ }
993
+ libro.invertCell(cell, 'code');
994
+ },
995
+ isEnabled: (_cell, libro) => {
996
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
997
+ return false;
998
+ }
999
+ return true;
1000
+ },
1001
+ },
1002
+ );
1003
+ this.libroCommand.registerLibroCommand(
1004
+ command,
1005
+ NotebookCommands['ChangeCellToMarkdown'],
1006
+ {
1007
+ execute: (cell: CellView | undefined, libro: NotebookView | undefined) => {
1008
+ if (
1009
+ !cell ||
1010
+ !libro ||
1011
+ !(cell instanceof LibroCellView) ||
1012
+ !(libro instanceof LibroView)
1013
+ ) {
1014
+ return;
1015
+ }
1016
+ libro.invertCell(cell, 'markdown');
1017
+ },
1018
+ isEnabled: (_cell, libro) => {
1019
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
1020
+ return false;
1021
+ }
1022
+ return true;
1023
+ },
1024
+ },
1025
+ );
1026
+ this.libroCommand.registerLibroCommand(
1027
+ command,
1028
+ NotebookCommands['EnableOutputScrolling'],
1029
+ {
1030
+ execute: (cell: CellView | undefined, libro: NotebookView | undefined) => {
1031
+ if (
1032
+ !cell ||
1033
+ !libro ||
1034
+ !(cell instanceof LibroCellView) ||
1035
+ !(libro instanceof LibroView)
1036
+ ) {
1037
+ return;
1038
+ }
1039
+ libro.enableOutputScrolling(cell);
1040
+ },
1041
+ },
1042
+ );
1043
+ this.libroCommand.registerLibroCommand(
1044
+ command,
1045
+ NotebookCommands['DisableOutputScrolling'],
1046
+ {
1047
+ execute: (cell: CellView | undefined, libro: NotebookView | undefined) => {
1048
+ if (
1049
+ !cell ||
1050
+ !libro ||
1051
+ !(cell instanceof LibroCellView) ||
1052
+ !(libro instanceof LibroView)
1053
+ ) {
1054
+ return;
1055
+ }
1056
+ libro.disableOutputScrolling(cell);
1057
+ },
1058
+ },
1059
+ );
1060
+ this.libroCommand.registerLibroCommand(command, DocumentCommands['Save'], {
1061
+ execute: async (_cell, libro) => {
1062
+ if (!libro || !(libro instanceof LibroView)) {
1063
+ return;
1064
+ }
1065
+ libro.save();
1066
+ },
1067
+ isVisible: (_cell, libro, path) => {
1068
+ if (!libro || !(libro instanceof LibroView)) {
1069
+ return false;
1070
+ }
1071
+ return !libro?.model.readOnly && path === LibroToolbarArea.HeaderCenter;
1072
+ },
1073
+ isEnabled: (_cell, libro) => {
1074
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
1075
+ return false;
1076
+ }
1077
+ return true;
1078
+ },
1079
+ });
1080
+ // this.libroCommand.registerLibroCommand(command, DocumentCommands['OpenSettings'], {
1081
+ // execute: async () => {
1082
+ // this.modalService.openModal(SettingsModal);
1083
+ // },
1084
+ // isVisible: (cell, libro, path) => {
1085
+ // return path === LibroToolbarArea.HeaderCenter;
1086
+ // },
1087
+ // });
1088
+ this.libroCommand.registerLibroCommand(
1089
+ command,
1090
+ NotebookCommands['UndoCellAction'],
1091
+ {
1092
+ execute: async (_cell, libro) => {
1093
+ if (!libro || !(libro instanceof LibroView)) {
1094
+ return;
1095
+ }
1096
+
1097
+ libro.model.undo();
1098
+ },
1099
+ isVisible: (_cell, libro, path) => {
1100
+ if (!libro || !(libro instanceof LibroView)) {
1101
+ return false;
1102
+ }
1103
+ return !libro?.model.readOnly && path === LibroToolbarArea.HeaderCenter;
1104
+ },
1105
+ isEnabled: (_cell, libro) => {
1106
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
1107
+ return false;
1108
+ }
1109
+
1110
+ return libro.model.canUndo ?? false;
1111
+ },
1112
+ },
1113
+ );
1114
+ this.libroCommand.registerLibroCommand(
1115
+ command,
1116
+ NotebookCommands['RedoCellAction'],
1117
+ {
1118
+ execute: async (_cell, libro) => {
1119
+ if (!libro || !(libro instanceof LibroView)) {
1120
+ return;
1121
+ }
1122
+ libro.model.redo();
1123
+ },
1124
+ isVisible: (_cell, libro, path) => {
1125
+ if (!libro || !(libro instanceof LibroView)) {
1126
+ return false;
1127
+ }
1128
+ return !libro?.model.readOnly && path === LibroToolbarArea.HeaderCenter;
1129
+ },
1130
+ isEnabled: (_cell, libro) => {
1131
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
1132
+ return false;
1133
+ }
1134
+ return libro.model.canRedo ?? false;
1135
+ },
1136
+ },
1137
+ );
1138
+ this.libroCommand.registerLibroCommand(
1139
+ command,
1140
+ NotebookCommands['SplitCellAntCursor'],
1141
+ {
1142
+ execute: (cell: CellView | undefined, libro: NotebookView | undefined) => {
1143
+ if (
1144
+ !cell ||
1145
+ !libro ||
1146
+ !(cell instanceof LibroCellView) ||
1147
+ !(libro instanceof LibroView)
1148
+ ) {
1149
+ return;
1150
+ }
1151
+ libro.splitCell(cell);
1152
+ },
1153
+ isEnabled: (_cell, libro) => {
1154
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
1155
+ return false;
1156
+ }
1157
+ return true;
1158
+ },
1159
+ },
1160
+ );
1161
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['Redo'], {
1162
+ execute: async (cell) => {
1163
+ if (!cell || !(cell instanceof LibroCellView)) {
1164
+ return;
1165
+ }
1166
+ (cell as LibroEditorCellView).redo();
1167
+ },
1168
+ isEnabled: (_cell, libro) => {
1169
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
1170
+ return false;
1171
+ }
1172
+ return true;
1173
+ },
1174
+ });
1175
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['Undo'], {
1176
+ execute: async (cell) => {
1177
+ if (!cell || !(cell instanceof LibroCellView)) {
1178
+ return;
1179
+ }
1180
+ (cell as LibroEditorCellView).undo();
1181
+ },
1182
+ isEnabled: (_cell, libro) => {
1183
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
1184
+ return false;
1185
+ }
1186
+ return true;
1187
+ },
1188
+ });
1189
+ this.libroCommand.registerLibroCommand(
1190
+ command,
1191
+ NotebookCommands['ChangeCellToHeading1'],
1192
+ {
1193
+ execute: (cell, libro) => {
1194
+ if (
1195
+ !cell ||
1196
+ !libro ||
1197
+ !(cell instanceof LibroCellView) ||
1198
+ !(libro instanceof LibroView)
1199
+ ) {
1200
+ return;
1201
+ }
1202
+ libro.setMarkdownHeader(cell, 1);
1203
+ },
1204
+ isEnabled: (_cell, libro) => {
1205
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
1206
+ return false;
1207
+ }
1208
+ return true;
1209
+ },
1210
+ },
1211
+ );
1212
+ this.libroCommand.registerLibroCommand(
1213
+ command,
1214
+ NotebookCommands['ChangeCellToHeading2'],
1215
+ {
1216
+ execute: (cell, libro) => {
1217
+ if (
1218
+ !cell ||
1219
+ !libro ||
1220
+ !(cell instanceof LibroCellView) ||
1221
+ !(libro instanceof LibroView)
1222
+ ) {
1223
+ return;
1224
+ }
1225
+ libro.setMarkdownHeader(cell, 2);
1226
+ },
1227
+ isEnabled: (_cell, libro) => {
1228
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
1229
+ return false;
1230
+ }
1231
+ return true;
1232
+ },
1233
+ },
1234
+ );
1235
+ this.libroCommand.registerLibroCommand(
1236
+ command,
1237
+ NotebookCommands['ChangeCellToHeading3'],
1238
+ {
1239
+ execute: (cell, libro) => {
1240
+ if (
1241
+ !cell ||
1242
+ !libro ||
1243
+ !(cell instanceof LibroCellView) ||
1244
+ !(libro instanceof LibroView)
1245
+ ) {
1246
+ return;
1247
+ }
1248
+ libro.setMarkdownHeader(cell, 3);
1249
+ },
1250
+ isEnabled: (_cell, libro) => {
1251
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
1252
+ return false;
1253
+ }
1254
+ return true;
1255
+ },
1256
+ },
1257
+ );
1258
+ this.libroCommand.registerLibroCommand(
1259
+ command,
1260
+ NotebookCommands['ChangeCellToHeading4'],
1261
+ {
1262
+ execute: (cell, libro) => {
1263
+ if (
1264
+ !cell ||
1265
+ !libro ||
1266
+ !(cell instanceof LibroCellView) ||
1267
+ !(libro instanceof LibroView)
1268
+ ) {
1269
+ return;
1270
+ }
1271
+ libro.setMarkdownHeader(cell, 4);
1272
+ },
1273
+ isEnabled: (_cell, libro) => {
1274
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
1275
+ return false;
1276
+ }
1277
+ return true;
1278
+ },
1279
+ },
1280
+ );
1281
+ this.libroCommand.registerLibroCommand(
1282
+ command,
1283
+ NotebookCommands['ChangeCellToHeading5'],
1284
+ {
1285
+ execute: (cell, libro) => {
1286
+ if (
1287
+ !cell ||
1288
+ !libro ||
1289
+ !(cell instanceof LibroCellView) ||
1290
+ !(libro instanceof LibroView)
1291
+ ) {
1292
+ return;
1293
+ }
1294
+ libro.setMarkdownHeader(cell, 5);
1295
+ },
1296
+ isEnabled: (_cell, libro) => {
1297
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
1298
+ return false;
1299
+ }
1300
+ return true;
1301
+ },
1302
+ },
1303
+ );
1304
+ this.libroCommand.registerLibroCommand(
1305
+ command,
1306
+ NotebookCommands['ChangeCellToHeading6'],
1307
+ {
1308
+ execute: (cell, libro) => {
1309
+ if (
1310
+ !cell ||
1311
+ !libro ||
1312
+ !(cell instanceof LibroCellView) ||
1313
+ !(libro instanceof LibroView)
1314
+ ) {
1315
+ return;
1316
+ }
1317
+ libro.setMarkdownHeader(cell, 6);
1318
+ },
1319
+ isEnabled: (_cell, libro) => {
1320
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
1321
+ return false;
1322
+ }
1323
+ return true;
1324
+ },
1325
+ },
1326
+ );
1327
+
1328
+ this.libroCommand.registerLibroCommand(command, NotebookCommands['More'], {
1329
+ execute: async (_cell, libro) => {
1330
+ if (!libro || !(libro instanceof LibroView)) {
1331
+ return;
1332
+ }
1333
+ },
1334
+ isVisible: (_cell, _libro, path) => {
1335
+ return path === LibroToolbarArea.CellRight;
1336
+ },
1337
+ });
1338
+ }
1339
+ }