@difizen/libro-core 0.0.0-snapshot-20241017072317

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 (433) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +280 -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 +11 -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 +59 -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 +121 -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 +12 -0
  20. package/es/cell/libro-cell-contribution.d.ts.map +1 -0
  21. package/es/cell/libro-cell-contribution.js +47 -0
  22. package/es/cell/libro-cell-model.d.ts +29 -0
  23. package/es/cell/libro-cell-model.d.ts.map +1 -0
  24. package/es/cell/libro-cell-model.js +130 -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 +44 -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 +245 -0
  34. package/es/cell/libro-cell-view.d.ts +74 -0
  35. package/es/cell/libro-cell-view.d.ts.map +1 -0
  36. package/es/cell/libro-cell-view.js +239 -0
  37. package/es/cell/libro-edit-cell-view.d.ts +44 -0
  38. package/es/cell/libro-edit-cell-view.d.ts.map +1 -0
  39. package/es/cell/libro-edit-cell-view.js +256 -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 +34 -0
  44. package/es/cell/libro-executable-cell-view.d.ts.map +1 -0
  45. package/es/cell/libro-executable-cell-view.js +74 -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 +5 -0
  53. package/es/command/document-commands.d.ts.map +1 -0
  54. package/es/command/document-commands.js +21 -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 +40 -0
  61. package/es/command/libro-command-contribution.d.ts +13 -0
  62. package/es/command/libro-command-contribution.d.ts.map +1 -0
  63. package/es/command/libro-command-contribution.js +1842 -0
  64. package/es/command/libro-command-register.d.ts +21 -0
  65. package/es/command/libro-command-register.d.ts.map +1 -0
  66. package/es/command/libro-command-register.js +111 -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 +472 -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 +16 -0
  77. package/es/components/dnd-cell-item-render.d.ts.map +1 -0
  78. package/es/components/dnd-cell-item-render.js +364 -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 +140 -0
  82. package/es/components/dnd-component/default-dnd-content.d.ts +11 -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 +292 -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 +14 -0
  89. package/es/components/dnd-component/dnd-list.d.ts.map +1 -0
  90. package/es/components/dnd-component/dnd-list.js +182 -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/dnd-component/index.less +8 -0
  95. package/es/components/dnd-component/overscanIndices-getter.d.ts +22 -0
  96. package/es/components/dnd-component/overscanIndices-getter.d.ts.map +1 -0
  97. package/es/components/dnd-component/overscanIndices-getter.js +58 -0
  98. package/es/components/dnd-component/virtualized-manager.d.ts +19 -0
  99. package/es/components/dnd-component/virtualized-manager.d.ts.map +1 -0
  100. package/es/components/dnd-component/virtualized-manager.js +60 -0
  101. package/es/components/index.d.ts +6 -0
  102. package/es/components/index.d.ts.map +1 -0
  103. package/es/components/index.js +5 -0
  104. package/es/components/libro-component.d.ts +5 -0
  105. package/es/components/libro-component.d.ts.map +1 -0
  106. package/es/components/libro-component.js +35 -0
  107. package/es/components/libro-side-toolbar-menu.d.ts +21 -0
  108. package/es/components/libro-side-toolbar-menu.d.ts.map +1 -0
  109. package/es/components/libro-side-toolbar-menu.js +58 -0
  110. package/es/components/libro-view-header.d.ts +3 -0
  111. package/es/components/libro-view-header.d.ts.map +1 -0
  112. package/es/components/libro-view-header.js +37 -0
  113. package/es/components/libro-virtualized-render.d.ts +15 -0
  114. package/es/components/libro-virtualized-render.d.ts.map +1 -0
  115. package/es/components/libro-virtualized-render.js +174 -0
  116. package/es/content/index.d.ts +6 -0
  117. package/es/content/index.d.ts.map +1 -0
  118. package/es/content/index.js +5 -0
  119. package/es/content/libro-content-contribution.d.ts +11 -0
  120. package/es/content/libro-content-contribution.d.ts.map +1 -0
  121. package/es/content/libro-content-contribution.js +31 -0
  122. package/es/content/libro-content-module.d.ts +3 -0
  123. package/es/content/libro-content-module.d.ts.map +1 -0
  124. package/es/content/libro-content-module.js +6 -0
  125. package/es/content/libro-content-protocol.d.ts +13 -0
  126. package/es/content/libro-content-protocol.d.ts.map +1 -0
  127. package/es/content/libro-content-protocol.js +3 -0
  128. package/es/content/libro-content-service.d.ts +11 -0
  129. package/es/content/libro-content-service.d.ts.map +1 -0
  130. package/es/content/libro-content-service.js +63 -0
  131. package/es/content/libro-save-content-contribution.d.ts +6 -0
  132. package/es/content/libro-save-content-contribution.d.ts.map +1 -0
  133. package/es/content/libro-save-content-contribution.js +27 -0
  134. package/es/formatter/index.d.ts +6 -0
  135. package/es/formatter/index.d.ts.map +1 -0
  136. package/es/formatter/index.js +5 -0
  137. package/es/formatter/libro-formatter-json-contribution.d.ts +18 -0
  138. package/es/formatter/libro-formatter-json-contribution.d.ts.map +1 -0
  139. package/es/formatter/libro-formatter-json-contribution.js +41 -0
  140. package/es/formatter/libro-formatter-manager.d.ts +16 -0
  141. package/es/formatter/libro-formatter-manager.d.ts.map +1 -0
  142. package/es/formatter/libro-formatter-manager.js +86 -0
  143. package/es/formatter/libro-formatter-module.d.ts +3 -0
  144. package/es/formatter/libro-formatter-module.d.ts.map +1 -0
  145. package/es/formatter/libro-formatter-module.js +7 -0
  146. package/es/formatter/libro-formatter-protocol.d.ts +37 -0
  147. package/es/formatter/libro-formatter-protocol.d.ts.map +1 -0
  148. package/es/formatter/libro-formatter-protocol.js +18 -0
  149. package/es/formatter/libro-formatter-string-contribution.d.ts +18 -0
  150. package/es/formatter/libro-formatter-string-contribution.d.ts.map +1 -0
  151. package/es/formatter/libro-formatter-string-contribution.js +41 -0
  152. package/es/formatter/libro-formatter-trans-default-contribution.d.ts +7 -0
  153. package/es/formatter/libro-formatter-trans-default-contribution.d.ts.map +1 -0
  154. package/es/formatter/libro-formatter-trans-default-contribution.js +19 -0
  155. package/es/index.d.ts +26 -0
  156. package/es/index.d.ts.map +1 -0
  157. package/es/index.js +25 -0
  158. package/es/index.less +781 -0
  159. package/es/libro-context-key.d.ts +26 -0
  160. package/es/libro-context-key.d.ts.map +1 -0
  161. package/es/libro-context-key.js +84 -0
  162. package/es/libro-keybind-registry.d.ts +5 -0
  163. package/es/libro-keybind-registry.d.ts.map +1 -0
  164. package/es/libro-keybind-registry.js +68 -0
  165. package/es/libro-model.d.ts +145 -0
  166. package/es/libro-model.d.ts.map +1 -0
  167. package/es/libro-model.js +921 -0
  168. package/es/libro-protocol.d.ts +315 -0
  169. package/es/libro-protocol.d.ts.map +1 -0
  170. package/es/libro-protocol.js +47 -0
  171. package/es/libro-service.d.ts +69 -0
  172. package/es/libro-service.d.ts.map +1 -0
  173. package/es/libro-service.js +303 -0
  174. package/es/libro-setting-contribution.d.ts +5 -0
  175. package/es/libro-setting-contribution.d.ts.map +1 -0
  176. package/es/libro-setting-contribution.js +23 -0
  177. package/es/libro-setting.d.ts +12 -0
  178. package/es/libro-setting.d.ts.map +1 -0
  179. package/es/libro-setting.js +101 -0
  180. package/es/libro-view-tracker.d.ts +6 -0
  181. package/es/libro-view-tracker.d.ts.map +1 -0
  182. package/es/libro-view-tracker.js +13 -0
  183. package/es/libro-view.d.ts +170 -0
  184. package/es/libro-view.d.ts.map +1 -0
  185. package/es/libro-view.js +2077 -0
  186. package/es/libro-workspace-service.d.ts +17 -0
  187. package/es/libro-workspace-service.d.ts.map +1 -0
  188. package/es/libro-workspace-service.js +36 -0
  189. package/es/material-from-designer.d.ts +31 -0
  190. package/es/material-from-designer.d.ts.map +1 -0
  191. package/es/material-from-designer.js +697 -0
  192. package/es/module.d.ts +3 -0
  193. package/es/module.d.ts.map +1 -0
  194. package/es/module.js +71 -0
  195. package/es/output/index.d.ts +6 -0
  196. package/es/output/index.d.ts.map +1 -0
  197. package/es/output/index.js +5 -0
  198. package/es/output/output-area.d.ts +51 -0
  199. package/es/output/output-area.d.ts.map +1 -0
  200. package/es/output/output-area.js +399 -0
  201. package/es/output/output-contribution.d.ts +10 -0
  202. package/es/output/output-contribution.d.ts.map +1 -0
  203. package/es/output/output-contribution.js +36 -0
  204. package/es/output/output-model.d.ts +28 -0
  205. package/es/output/output-model.d.ts.map +1 -0
  206. package/es/output/output-model.js +105 -0
  207. package/es/output/output-module.d.ts +3 -0
  208. package/es/output/output-module.d.ts.map +1 -0
  209. package/es/output/output-module.js +6 -0
  210. package/es/output/output-protocol.d.ts +134 -0
  211. package/es/output/output-protocol.d.ts.map +1 -0
  212. package/es/output/output-protocol.js +16 -0
  213. package/es/settings/index.d.ts +5 -0
  214. package/es/settings/index.d.ts.map +1 -0
  215. package/es/settings/index.js +4 -0
  216. package/es/settings/index.less +3 -0
  217. package/es/settings/module.d.ts +3 -0
  218. package/es/settings/module.d.ts.map +1 -0
  219. package/es/settings/module.js +4 -0
  220. package/es/settings/setting-editor/configuration-panel-view.d.ts +13 -0
  221. package/es/settings/setting-editor/configuration-panel-view.d.ts.map +1 -0
  222. package/es/settings/setting-editor/configuration-panel-view.js +115 -0
  223. package/es/settings/setting-editor/configuration-render-contribution.d.ts +6 -0
  224. package/es/settings/setting-editor/configuration-render-contribution.d.ts.map +1 -0
  225. package/es/settings/setting-editor/configuration-render-contribution.js +77 -0
  226. package/es/settings/setting-editor/default-node-render.d.ts +9 -0
  227. package/es/settings/setting-editor/default-node-render.d.ts.map +1 -0
  228. package/es/settings/setting-editor/default-node-render.js +79 -0
  229. package/es/settings/setting-editor/index.d.ts +7 -0
  230. package/es/settings/setting-editor/index.d.ts.map +1 -0
  231. package/es/settings/setting-editor/index.js +6 -0
  232. package/es/settings/setting-editor/index.less +12 -0
  233. package/es/settings/setting-editor/module.d.ts +3 -0
  234. package/es/settings/setting-editor/module.d.ts.map +1 -0
  235. package/es/settings/setting-editor/module.js +11 -0
  236. package/es/settings/setting-editor/setting-editor-view.d.ts +15 -0
  237. package/es/settings/setting-editor/setting-editor-view.d.ts.map +1 -0
  238. package/es/settings/setting-editor/setting-editor-view.js +169 -0
  239. package/es/settings/setting-editor/setting-tree-service.d.ts +9 -0
  240. package/es/settings/setting-editor/setting-tree-service.d.ts.map +1 -0
  241. package/es/settings/setting-editor/setting-tree-service.js +118 -0
  242. package/es/settings/setting-editor/setting-tree-view.d.ts +19 -0
  243. package/es/settings/setting-editor/setting-tree-view.d.ts.map +1 -0
  244. package/es/settings/setting-editor/setting-tree-view.js +87 -0
  245. package/es/settings/settings-contribution.d.ts +7 -0
  246. package/es/settings/settings-contribution.d.ts.map +1 -0
  247. package/es/settings/settings-contribution.js +36 -0
  248. package/es/settings/settings-modal.d.ts +5 -0
  249. package/es/settings/settings-modal.d.ts.map +1 -0
  250. package/es/settings/settings-modal.js +53 -0
  251. package/es/settings/settings-modal.less +3 -0
  252. package/es/settings/settings-protocol.d.ts +4 -0
  253. package/es/settings/settings-protocol.d.ts.map +1 -0
  254. package/es/settings/settings-protocol.js +5 -0
  255. package/es/slot/index.d.ts +5 -0
  256. package/es/slot/index.d.ts.map +1 -0
  257. package/es/slot/index.js +4 -0
  258. package/es/slot/libro-slot-manager.d.ts +13 -0
  259. package/es/slot/libro-slot-manager.d.ts.map +1 -0
  260. package/es/slot/libro-slot-manager.js +66 -0
  261. package/es/slot/libro-slot-protocol.d.ts +19 -0
  262. package/es/slot/libro-slot-protocol.d.ts.map +1 -0
  263. package/es/slot/libro-slot-protocol.js +5 -0
  264. package/es/slot/libro-slot-view.d.ts +9 -0
  265. package/es/slot/libro-slot-view.d.ts.map +1 -0
  266. package/es/slot/libro-slot-view.js +81 -0
  267. package/es/slot/module.d.ts +3 -0
  268. package/es/slot/module.d.ts.map +1 -0
  269. package/es/slot/module.js +5 -0
  270. package/es/theme/libro-color-registry.d.ts +6 -0
  271. package/es/theme/libro-color-registry.d.ts.map +1 -0
  272. package/es/theme/libro-color-registry.js +515 -0
  273. package/es/toolbar/all-outputs-scroll-icon.d.ts +3 -0
  274. package/es/toolbar/all-outputs-scroll-icon.d.ts.map +1 -0
  275. package/es/toolbar/all-outputs-scroll-icon.js +10 -0
  276. package/es/toolbar/change-cell-to-selector.d.ts +5 -0
  277. package/es/toolbar/change-cell-to-selector.d.ts.map +1 -0
  278. package/es/toolbar/change-cell-to-selector.js +51 -0
  279. package/es/toolbar/hide-all-selector.d.ts +5 -0
  280. package/es/toolbar/hide-all-selector.d.ts.map +1 -0
  281. package/es/toolbar/hide-all-selector.js +99 -0
  282. package/es/toolbar/index.d.ts +4 -0
  283. package/es/toolbar/index.d.ts.map +1 -0
  284. package/es/toolbar/index.js +3 -0
  285. package/es/toolbar/index.less +59 -0
  286. package/es/toolbar/libro-toolbar-protocol.d.ts +4 -0
  287. package/es/toolbar/libro-toolbar-protocol.d.ts.map +1 -0
  288. package/es/toolbar/libro-toolbar-protocol.js +1 -0
  289. package/es/toolbar/libro-toolbar.d.ts +9 -0
  290. package/es/toolbar/libro-toolbar.d.ts.map +1 -0
  291. package/es/toolbar/libro-toolbar.js +275 -0
  292. package/es/toolbar/module.d.ts +3 -0
  293. package/es/toolbar/module.d.ts.map +1 -0
  294. package/es/toolbar/module.js +5 -0
  295. package/es/toolbar/restart-clear-outputs-contribution.d.ts +5 -0
  296. package/es/toolbar/restart-clear-outputs-contribution.d.ts.map +1 -0
  297. package/es/toolbar/restart-clear-outputs-contribution.js +23 -0
  298. package/es/toolbar/restart-clear-outputs-modal.d.ts +5 -0
  299. package/es/toolbar/restart-clear-outputs-modal.d.ts.map +1 -0
  300. package/es/toolbar/restart-clear-outputs-modal.js +30 -0
  301. package/es/toolbar/save-icon.d.ts +3 -0
  302. package/es/toolbar/save-icon.d.ts.map +1 -0
  303. package/es/toolbar/save-icon.js +54 -0
  304. package/es/toolbar/shutdown-contribution.d.ts +5 -0
  305. package/es/toolbar/shutdown-contribution.d.ts.map +1 -0
  306. package/es/toolbar/shutdown-contribution.js +23 -0
  307. package/es/toolbar/shutdown-modal.d.ts +5 -0
  308. package/es/toolbar/shutdown-modal.d.ts.map +1 -0
  309. package/es/toolbar/shutdown-modal.js +30 -0
  310. package/es/toolbar/side-toolar-more-select.d.ts +4 -0
  311. package/es/toolbar/side-toolar-more-select.d.ts.map +1 -0
  312. package/es/toolbar/side-toolar-more-select.js +161 -0
  313. package/es/typings/index.d.ts +1 -0
  314. package/es/virtualized-manager-helper.d.ts +11 -0
  315. package/es/virtualized-manager-helper.d.ts.map +1 -0
  316. package/es/virtualized-manager-helper.js +51 -0
  317. package/es/virtualized-manager.d.ts +23 -0
  318. package/es/virtualized-manager.d.ts.map +1 -0
  319. package/es/virtualized-manager.js +65 -0
  320. package/package.json +73 -0
  321. package/src/add-cell/index.less +38 -0
  322. package/src/add-cell/index.ts +3 -0
  323. package/src/add-cell/libro-add-cell-module.ts +9 -0
  324. package/src/add-cell/libro-add-cell-slot-contribution.ts +28 -0
  325. package/src/add-cell/libro-add-cell-view.tsx +99 -0
  326. package/src/cell/README.md +14 -0
  327. package/src/cell/index.ts +9 -0
  328. package/src/cell/libro-cell-contribution.ts +34 -0
  329. package/src/cell/libro-cell-model.ts +119 -0
  330. package/src/cell/libro-cell-module.ts +40 -0
  331. package/src/cell/libro-cell-protocol.ts +55 -0
  332. package/src/cell/libro-cell-service.ts +158 -0
  333. package/src/cell/libro-cell-view.tsx +156 -0
  334. package/src/cell/libro-edit-cell-view.tsx +205 -0
  335. package/src/cell/libro-executable-cell-model.ts +32 -0
  336. package/src/cell/libro-executable-cell-view.ts +86 -0
  337. package/src/cell/libro-markdown-cell-model.ts +20 -0
  338. package/src/collapse-service.ts +69 -0
  339. package/src/command/document-commands.ts +24 -0
  340. package/src/command/index.ts +6 -0
  341. package/src/command/kernel-command.ts +42 -0
  342. package/src/command/libro-command-contribution.ts +1346 -0
  343. package/src/command/libro-command-register.ts +168 -0
  344. package/src/command/module.ts +9 -0
  345. package/src/command/notebook-commands.ts +502 -0
  346. package/src/components/cell-protocol.ts +26 -0
  347. package/src/components/dnd-cell-item-render.tsx +465 -0
  348. package/src/components/dnd-component/custom-drag-layer.tsx +144 -0
  349. package/src/components/dnd-component/default-dnd-content.tsx +330 -0
  350. package/src/components/dnd-component/dnd-context.tsx +28 -0
  351. package/src/components/dnd-component/dnd-list.tsx +211 -0
  352. package/src/components/dnd-component/index.less +12 -0
  353. package/src/components/dnd-component/index.tsx +4 -0
  354. package/src/components/dnd-component/overscanIndices-getter.ts +92 -0
  355. package/src/components/dnd-component/virtualized-manager.ts +34 -0
  356. package/src/components/index.ts +5 -0
  357. package/src/components/libro-component.tsx +30 -0
  358. package/src/components/libro-side-toolbar-menu.tsx +82 -0
  359. package/src/components/libro-view-header.tsx +33 -0
  360. package/src/components/libro-virtualized-render.tsx +178 -0
  361. package/src/content/index.ts +5 -0
  362. package/src/content/libro-content-contribution.ts +16 -0
  363. package/src/content/libro-content-module.ts +17 -0
  364. package/src/content/libro-content-protocol.ts +14 -0
  365. package/src/content/libro-content-service.ts +48 -0
  366. package/src/content/libro-save-content-contribution.ts +12 -0
  367. package/src/formatter/index.ts +5 -0
  368. package/src/formatter/libro-formatter-json-contribution.ts +42 -0
  369. package/src/formatter/libro-formatter-manager.ts +85 -0
  370. package/src/formatter/libro-formatter-module.ts +19 -0
  371. package/src/formatter/libro-formatter-protocol.ts +63 -0
  372. package/src/formatter/libro-formatter-string-contribution.ts +41 -0
  373. package/src/formatter/libro-formatter-trans-default-contribution.ts +15 -0
  374. package/src/index.less +789 -0
  375. package/src/index.spec.ts +12 -0
  376. package/src/index.tsx +25 -0
  377. package/src/libro-context-key.ts +84 -0
  378. package/src/libro-keybind-registry.ts +43 -0
  379. package/src/libro-model.ts +710 -0
  380. package/src/libro-protocol.ts +435 -0
  381. package/src/libro-service.ts +234 -0
  382. package/src/libro-setting-contribution.ts +28 -0
  383. package/src/libro-setting.ts +110 -0
  384. package/src/libro-view-tracker.ts +9 -0
  385. package/src/libro-view.tsx +1532 -0
  386. package/src/libro-workspace-service.ts +28 -0
  387. package/src/material-from-designer.tsx +579 -0
  388. package/src/module.ts +121 -0
  389. package/src/output/index.ts +5 -0
  390. package/src/output/output-area.tsx +286 -0
  391. package/src/output/output-contribution.ts +14 -0
  392. package/src/output/output-model.tsx +70 -0
  393. package/src/output/output-module.ts +10 -0
  394. package/src/output/output-protocol.ts +168 -0
  395. package/src/settings/index.less +3 -0
  396. package/src/settings/index.ts +4 -0
  397. package/src/settings/module.ts +8 -0
  398. package/src/settings/setting-editor/configuration-panel-view.tsx +89 -0
  399. package/src/settings/setting-editor/configuration-render-contribution.ts +81 -0
  400. package/src/settings/setting-editor/default-node-render.tsx +65 -0
  401. package/src/settings/setting-editor/index.less +12 -0
  402. package/src/settings/setting-editor/index.ts +6 -0
  403. package/src/settings/setting-editor/module.ts +17 -0
  404. package/src/settings/setting-editor/setting-editor-view.tsx +93 -0
  405. package/src/settings/setting-editor/setting-tree-service.ts +82 -0
  406. package/src/settings/setting-editor/setting-tree-view.tsx +95 -0
  407. package/src/settings/settings-contribution.tsx +24 -0
  408. package/src/settings/settings-modal.less +3 -0
  409. package/src/settings/settings-modal.tsx +51 -0
  410. package/src/settings/settings-protocol.ts +7 -0
  411. package/src/slot/index.ts +4 -0
  412. package/src/slot/libro-slot-manager.ts +38 -0
  413. package/src/slot/libro-slot-protocol.ts +28 -0
  414. package/src/slot/libro-slot-view.tsx +48 -0
  415. package/src/slot/module.ts +9 -0
  416. package/src/theme/libro-color-registry.ts +386 -0
  417. package/src/toolbar/all-outputs-scroll-icon.tsx +19 -0
  418. package/src/toolbar/change-cell-to-selector.tsx +67 -0
  419. package/src/toolbar/hide-all-selector.tsx +126 -0
  420. package/src/toolbar/index.less +59 -0
  421. package/src/toolbar/index.ts +3 -0
  422. package/src/toolbar/libro-toolbar-protocol.ts +4 -0
  423. package/src/toolbar/libro-toolbar.tsx +231 -0
  424. package/src/toolbar/module.ts +11 -0
  425. package/src/toolbar/restart-clear-outputs-contribution.tsx +10 -0
  426. package/src/toolbar/restart-clear-outputs-modal.tsx +37 -0
  427. package/src/toolbar/save-icon.tsx +47 -0
  428. package/src/toolbar/shutdown-contribution.tsx +10 -0
  429. package/src/toolbar/shutdown-modal.tsx +37 -0
  430. package/src/toolbar/side-toolar-more-select.tsx +177 -0
  431. package/src/typings/index.d.ts +1 -0
  432. package/src/virtualized-manager-helper.ts +29 -0
  433. package/src/virtualized-manager.ts +47 -0
@@ -0,0 +1,710 @@
1
+ /* eslint-disable @typescript-eslint/unified-signatures */
2
+ import type {
3
+ ICodeCell,
4
+ INotebookContent,
5
+ INotebookMetadata,
6
+ } from '@difizen/libro-common';
7
+ import type {
8
+ CellTypeAdaptor,
9
+ ISharedNotebook,
10
+ NotebookChange,
11
+ } from '@difizen/libro-shared-model';
12
+ import { createMutex, YNotebook } from '@difizen/libro-shared-model';
13
+ import { getOrigin, ConfigurationService } from '@difizen/mana-app';
14
+ import { Emitter } from '@difizen/mana-app';
15
+ import { prop } from '@difizen/mana-app';
16
+ import { inject, transient } from '@difizen/mana-app';
17
+ import { v4 } from 'uuid';
18
+
19
+ import { LibroContentService } from './content/index.js';
20
+ import { isCellView, NotebookOption } from './libro-protocol.js';
21
+ import type {
22
+ CellOptions,
23
+ CellViewChange,
24
+ DndListModel,
25
+ NotebookModel,
26
+ ScrollParams,
27
+ CellView,
28
+ MouseMode,
29
+ ICellContentChange,
30
+ } from './libro-protocol.js';
31
+ import { EnterEditModeWhenAddCell } from './libro-setting.js';
32
+ import { VirtualizedManagerHelper } from './virtualized-manager-helper.js';
33
+
34
+ @transient()
35
+ export class LibroModel implements NotebookModel, DndListModel {
36
+ @inject(NotebookOption) options: NotebookOption;
37
+ @inject(LibroContentService) libroContentService: LibroContentService;
38
+ @inject(VirtualizedManagerHelper) virtualizedManagerHelper: VirtualizedManagerHelper;
39
+ @inject(ConfigurationService) configurationService: ConfigurationService;
40
+
41
+ protected scrollToCellViewEmitter: Emitter;
42
+ get onScrollToCellView() {
43
+ return this.scrollToCellViewEmitter.event;
44
+ }
45
+
46
+ protected cellViewChangeEmitter: Emitter<CellViewChange> = new Emitter();
47
+ get onCellViewChanged() {
48
+ return this.cellViewChangeEmitter.event;
49
+ }
50
+
51
+ disposeScrollToCellViewEmitter() {
52
+ this.scrollToCellViewEmitter.dispose();
53
+ }
54
+
55
+ protected onCommandModeChangedEmitter: Emitter<boolean> = new Emitter();
56
+ get onCommandModeChanged() {
57
+ return this.onCommandModeChangedEmitter.event;
58
+ }
59
+
60
+ protected onChangedEmitter: Emitter<boolean> = new Emitter();
61
+ get onChanged() {
62
+ return this.onChangedEmitter.event;
63
+ }
64
+
65
+ protected onSourceChangedEmitter: Emitter<boolean> = new Emitter();
66
+ get onSourceChanged() {
67
+ return this.onSourceChangedEmitter.event;
68
+ }
69
+
70
+ protected onRestartEmitter: Emitter<void> = new Emitter();
71
+ get onRestart() {
72
+ return this.onRestartEmitter.event;
73
+ }
74
+
75
+ protected onCellContentChangedEmitter: Emitter<ICellContentChange> = new Emitter();
76
+ get onCellContentChanged() {
77
+ return this.onCellContentChangedEmitter.event;
78
+ }
79
+
80
+ onCellContentChange(change: ICellContentChange) {
81
+ this.onCellContentChangedEmitter.fire(change);
82
+ }
83
+
84
+ id: string;
85
+
86
+ version = 0;
87
+
88
+ /**
89
+ * The shared notebook model.
90
+ */
91
+ readonly sharedModel: ISharedNotebook;
92
+
93
+ /**
94
+ * A mutex to update the shared model.
95
+ */
96
+ protected readonly _modelDBMutex = createMutex();
97
+
98
+ @prop()
99
+ lastClipboardInteraction?: string;
100
+
101
+ clipboard?: CellView | CellView[];
102
+ @prop()
103
+ inputEditable = true;
104
+
105
+ @prop()
106
+ outputEditable = true;
107
+
108
+ @prop()
109
+ cellsEditable = true;
110
+
111
+ get executable() {
112
+ return this.outputEditable && this.runnable;
113
+ }
114
+
115
+ set executable(value: boolean) {
116
+ this.runnable = value;
117
+ }
118
+
119
+ @prop()
120
+ savable = true;
121
+
122
+ @prop()
123
+ runnable = true;
124
+
125
+ @prop()
126
+ commandMode = true;
127
+
128
+ @prop()
129
+ isEditMode = true;
130
+
131
+ @prop()
132
+ dndAreaNullEnable = false;
133
+
134
+ @prop()
135
+ dirty = false;
136
+
137
+ @prop()
138
+ cells: CellView[] = [];
139
+
140
+ getCells() {
141
+ return this.cells.filter((cell) => !!cell);
142
+ }
143
+
144
+ @prop()
145
+ active?: CellView;
146
+
147
+ @prop()
148
+ activeIndex = 0;
149
+
150
+ @prop()
151
+ hover: CellView | undefined = undefined;
152
+
153
+ @prop()
154
+ isInitialized = false;
155
+
156
+ @prop()
157
+ executeCount = 0;
158
+
159
+ @prop()
160
+ mouseMode: MouseMode;
161
+
162
+ @prop()
163
+ selections: CellView[] = [];
164
+
165
+ deletedCells: CellView[] = [];
166
+
167
+ metadata: INotebookMetadata = {};
168
+
169
+ @prop()
170
+ customParams: Record<string, any> = {};
171
+
172
+ @prop()
173
+ libroViewClass = '';
174
+
175
+ @prop()
176
+ canUndo = false;
177
+
178
+ @prop()
179
+ canRedo = false;
180
+
181
+ /**
182
+ * 默认为true,可以在metadata修改
183
+ */
184
+ @prop()
185
+ trusted = true;
186
+
187
+ canRun() {
188
+ return true;
189
+ }
190
+
191
+ getCustomKey(key: string) {
192
+ return this.customParams[key];
193
+ }
194
+
195
+ setCustomKey(key: string, val: any) {
196
+ this.customParams[key] = val;
197
+ // 备份到metadata
198
+ // 备份到metadata
199
+ this.metadata['customParams'] = this.customParams;
200
+ }
201
+
202
+ // 字体大小
203
+ @prop()
204
+ fontSize = 12;
205
+
206
+ // 主题
207
+ @prop()
208
+ theme = '';
209
+
210
+ cellViewCache = new Map<string, CellView>();
211
+
212
+ nbformat_minor = 4;
213
+ nbformat = 4;
214
+
215
+ cellTypeAdaptor?: CellTypeAdaptor;
216
+
217
+ constructor() {
218
+ this.id = v4();
219
+ this.sharedModel = YNotebook.create({
220
+ disableDocumentWideUndoRedo: false,
221
+ cellTypeAdaptor: this.cellTypeAdaptor,
222
+ });
223
+ this.scrollToCellViewEmitter = new Emitter<ScrollParams>();
224
+ this.sharedModel.changed(this.onSharedModelChanged);
225
+ this.sharedModel.undoChanged((value) => {
226
+ if (value !== this.canUndo) {
227
+ this.canUndo = value;
228
+ }
229
+ });
230
+ this.sharedModel.redoChanged((value) => {
231
+ if (value !== this.canRedo) {
232
+ this.canRedo = value;
233
+ }
234
+ });
235
+ }
236
+
237
+ protected onSharedModelChanged = (change: NotebookChange) => {
238
+ let currpos = 0;
239
+ change.cellsChange?.forEach((delta) => {
240
+ if (delta.insert !== null && delta.insert !== undefined) {
241
+ const cellViews = delta.insert.map((cell) => {
242
+ const view = this.cellViewCache.get(cell.id)!;
243
+ return view;
244
+ });
245
+ this.insertCellsView(cellViews, currpos);
246
+ currpos += delta.insert.length;
247
+ this.cellViewChangeEmitter.fire({
248
+ insert: { index: currpos, cells: cellViews },
249
+ });
250
+ } else if (delta.delete !== null && delta.delete !== undefined) {
251
+ const cellViews = this.cells.slice(currpos, currpos + delta.delete);
252
+ this.removeRange(currpos, currpos + delta.delete);
253
+ this.cellViewChangeEmitter.fire({
254
+ delete: { index: currpos, number: delta.delete, cells: cellViews },
255
+ });
256
+ } else if (delta.retain !== null && delta.retain !== undefined) {
257
+ currpos += delta.retain;
258
+ }
259
+ });
260
+ if (
261
+ (!this.inputEditable || !this.outputEditable || !this.cellsEditable) &&
262
+ !this.runnable &&
263
+ !this.isInitialized
264
+ ) {
265
+ this.selectCell(undefined);
266
+ return;
267
+ }
268
+ this.selectCell(this.cells[this.activeIndex]);
269
+
270
+ this.configurationService
271
+ .get(EnterEditModeWhenAddCell)
272
+ .then((value) => {
273
+ if (value) {
274
+ if (this.isEditMode) {
275
+ this.enterEditMode();
276
+ } else {
277
+ this.enterCommandMode();
278
+ }
279
+ }
280
+ return;
281
+ })
282
+ .catch(() => {
283
+ //
284
+ });
285
+ };
286
+
287
+ toString: () => string;
288
+ fromString: (value: string) => void;
289
+
290
+ /**
291
+ * Serialize the model to JSON.
292
+ */
293
+ toJSON(): INotebookContent {
294
+ return {
295
+ metadata: this.metadata,
296
+ nbformat_minor: this.nbformat_minor,
297
+ nbformat: this.nbformat,
298
+ cells: this.getCells().map((item) => item.toJSON()),
299
+ };
300
+ }
301
+
302
+ /**
303
+ * Deserialize the model from JSON.
304
+ *
305
+ * #### Notes
306
+ * Should emit a [contentChanged] signal.
307
+ */
308
+ fromJSON(value: INotebookContent) {
309
+ this.sharedModel.transact(() => {
310
+ const useId = value.nbformat === 4 && value.nbformat_minor >= 5;
311
+ const ycells = value.cells.map((cell) => {
312
+ if (!useId) {
313
+ delete cell.id;
314
+ }
315
+ return cell;
316
+ });
317
+ if (!ycells.length) {
318
+ // Create cell when notebook is empty
319
+ // (non collaborative)
320
+ ycells.push({ cell_type: 'code' } as ICodeCell);
321
+ }
322
+ this.sharedModel.insertCells(this.sharedModel.cells.length, ycells);
323
+ this.sharedModel.deleteCellRange(0, this.sharedModel.cells.length);
324
+ });
325
+ }
326
+
327
+ onChange() {
328
+ this.version++;
329
+ this.dirty = true;
330
+ this.onChangedEmitter.fire(true);
331
+ }
332
+
333
+ onSourceChange() {
334
+ this.dirty = true;
335
+ this.onSourceChangedEmitter.fire(true);
336
+ }
337
+
338
+ /**
339
+ * override this method to load notebook from server
340
+ * @returns
341
+ */
342
+ async loadNotebookContent(): Promise<INotebookContent> {
343
+ return this.libroContentService.loadLibroContent(this.options, this);
344
+ }
345
+
346
+ async saveNotebookContent(): Promise<void> {
347
+ return this.libroContentService.saveLibroContent(this.options, this);
348
+ }
349
+
350
+ async initialize(): Promise<CellOptions[]> {
351
+ this.cells = [];
352
+ getOrigin(this.sharedModel).transact(() => {
353
+ this.sharedModel.deleteCellRange(0, this.sharedModel.cells.length);
354
+ });
355
+ const content = await this.loadNotebookContent();
356
+ this.metadata = content.metadata;
357
+ if (this.metadata?.['customParams']) {
358
+ this.customParams = this.metadata?.['customParams'] as Record<string, any>;
359
+ }
360
+ if (this.metadata?.['trusted']) {
361
+ this.trusted = this.metadata?.['trusted'] as boolean;
362
+ }
363
+ this.nbformat = content.nbformat;
364
+ this.nbformat_minor = content.nbformat_minor;
365
+ return content.cells.map((cell) => {
366
+ return { cell };
367
+ });
368
+ }
369
+
370
+ protected toCellIndex(arg: string | number | CellView): number | undefined {
371
+ let index: number | undefined = undefined;
372
+ if (typeof arg === 'number') {
373
+ index = arg;
374
+ } else if (typeof arg === 'string') {
375
+ index = this.cells.findIndex((cell) => cell.id === arg);
376
+ } else if (isCellView(arg)) {
377
+ index = this.cells.findIndex((cell) => cell.id === arg.id);
378
+ }
379
+ return index;
380
+ }
381
+ selectCell = (cell: CellView | undefined) => {
382
+ if (!cell || this.active?.id === cell.id) {
383
+ return;
384
+ }
385
+ this.active = cell;
386
+ cell.focus(false);
387
+ const index = this.cells.findIndex((_cell) => _cell.id === cell.id);
388
+ if (index > -1) {
389
+ this.activeIndex = index;
390
+ }
391
+ };
392
+
393
+ hoverCell = (cell?: CellView) => {
394
+ this.hover = cell;
395
+ };
396
+
397
+ /**
398
+ * 自动滚动到可视范围内
399
+ */
400
+ scrollToView(cell: CellView, cellOffset = 0) {
401
+ const virtualizedManager = this.virtualizedManagerHelper.getOrCreate(this);
402
+ if (virtualizedManager.isVirtualized) {
403
+ const cellIndex = this.cells.findIndex((_cell) => _cell.id === cell.id);
404
+ this.scrollToCellViewEmitter.fire({ cellIndex, cellOffset });
405
+ return;
406
+ }
407
+
408
+ let target = document.getElementById(cell.id);
409
+ if (!target) {
410
+ return;
411
+ }
412
+
413
+ const _targetheight = target?.offsetHeight || 0;
414
+ let offsetTop = (target?.offsetTop || 0) + cellOffset;
415
+ while (
416
+ target?.offsetParent &&
417
+ !target?.offsetParent?.className?.includes('libro-view-content-left')
418
+ ) {
419
+ target = target?.offsetParent as HTMLElement;
420
+ offsetTop += target?.offsetTop || 0;
421
+ }
422
+ if (target?.offsetParent?.parentElement && _targetheight) {
423
+ const _height = target.offsetParent.parentElement.clientHeight;
424
+ const _scrollTop = target.offsetParent.parentElement.scrollTop;
425
+ if (offsetTop > _scrollTop && offsetTop + _targetheight < _height + _scrollTop) {
426
+ // 在可视范围内就不需要滚动
427
+ return;
428
+ }
429
+ if (offsetTop < _scrollTop) {
430
+ target.offsetParent.parentElement.scrollTop = offsetTop;
431
+ } else {
432
+ //目标cell的高度大于屏幕的高度
433
+ if (_targetheight >= _height) {
434
+ target.offsetParent.parentElement.scrollTop = offsetTop - _height / 2;
435
+ } else {
436
+ target.offsetParent.parentElement.scrollTop =
437
+ offsetTop + _targetheight - _height + 30; // 加缓冲向上不贴底部
438
+ }
439
+ }
440
+ }
441
+ }
442
+
443
+ addCell = (cell: CellView, position?: number, mode?: string) => {
444
+ this.insertCells([cell], position, mode);
445
+ };
446
+
447
+ async restart() {
448
+ this.onRestartEmitter.fire();
449
+ }
450
+
451
+ insertCells = (cells: CellView[], position?: number, mode?: string) => {
452
+ // 非初始化阶段才需要自动滚动
453
+ if (!this.isInitialized) {
454
+ this.activeIndex = 0;
455
+ } else if (mode === 'above' && position !== undefined) {
456
+ this.activeIndex = position;
457
+ } else {
458
+ if (position === this.cells.length) {
459
+ this.activeIndex = position;
460
+ } else {
461
+ this.activeIndex = this.activeIndex + cells.length;
462
+ }
463
+ }
464
+ this.isEditMode = true;
465
+
466
+ const cellData = cells.map((cell) => {
467
+ this.cellViewCache.set(cell.model.id, cell);
468
+ return cell.toJSON();
469
+ });
470
+ getOrigin(this.sharedModel).transact(() => {
471
+ const insertIndex = position ?? this.sharedModel.cells.length;
472
+ getOrigin(this.sharedModel).insertCells(insertIndex, cellData);
473
+ });
474
+ };
475
+
476
+ invertCell = (toAddcell: CellView, position: number) => {
477
+ if (this.activeIndex !== position) {
478
+ this.activeIndex = position;
479
+ }
480
+ const cellData = [toAddcell].map((_cell) => {
481
+ this.cellViewCache.set(_cell.model.id, _cell);
482
+ return _cell.toJSON();
483
+ });
484
+ this.isEditMode = true;
485
+ getOrigin(this.sharedModel).transact(() => {
486
+ const invertIndex = position ?? this.sharedModel.cells.length;
487
+ getOrigin(this.sharedModel).deleteCell(invertIndex);
488
+ getOrigin(this.sharedModel).insertCells(invertIndex, cellData);
489
+ });
490
+ };
491
+
492
+ splitCell = (newCells: CellView[], position: number) => {
493
+ const newActiveIndex = position + newCells.length - 1;
494
+ if (this.activeIndex !== newActiveIndex) {
495
+ this.activeIndex = newActiveIndex;
496
+ }
497
+ const cellData = newCells.map((_cell) => {
498
+ this.cellViewCache.set(_cell.model.id, _cell);
499
+ return _cell.toJSON();
500
+ });
501
+ getOrigin(this.sharedModel).transact(() => {
502
+ getOrigin(this.sharedModel).deleteCell(position);
503
+ getOrigin(this.sharedModel).insertCells(position, cellData);
504
+ });
505
+ //切分 Cell操作结束后进入编辑态
506
+ this.enterEditMode();
507
+ };
508
+
509
+ protected insertCellsView = (cell: CellView[], position?: number) => {
510
+ if (position === 0) {
511
+ // unshift 存在性能问题
512
+ // this.cells.unshift(...cell);
513
+
514
+ const arr = [...this.cells];
515
+ arr.splice(0, 0, ...cell);
516
+ this.cells = arr;
517
+
518
+ return;
519
+ }
520
+ if (position !== undefined) {
521
+ const _cells: CellView[] = [];
522
+ this.getCells().forEach((_cell, index) => {
523
+ _cells.push(_cell);
524
+ _cell.isAttached = true;
525
+ if (index + 1 === position) {
526
+ _cells.push(...cell);
527
+ }
528
+ });
529
+ this.cells = _cells;
530
+ } else {
531
+ this.cells.push(...cell);
532
+ }
533
+ };
534
+
535
+ removeRange(start: number, end: number) {
536
+ // this.cells.splice(start, end - start);
537
+ // 不使用splice的写法,除非设置了 ObservableConfig.async = true
538
+ const arr = [...this.cells];
539
+ arr.splice(start, end - start);
540
+ this.cells = arr;
541
+ }
542
+
543
+ deleteCell(id: string | number): boolean;
544
+ deleteCell(index: number): boolean;
545
+ deleteCell(cell: CellView): boolean;
546
+ deleteCell(arg: string | number | CellView) {
547
+ const index = this.toCellIndex(arg);
548
+ if (index === undefined) {
549
+ return false;
550
+ }
551
+ if (this.activeIndex === this.cells.length - 1) {
552
+ this.activeIndex = this.cells.length - 2;
553
+ } else {
554
+ this.activeIndex = index;
555
+ }
556
+ this.isEditMode = false;
557
+ getOrigin(this.sharedModel).transact(() => {
558
+ getOrigin(this.sharedModel).deleteCell(index);
559
+ });
560
+ return true;
561
+ }
562
+
563
+ /**
564
+ * 删除 cell 节点
565
+ * @param arg id、index、cell
566
+ * @returns
567
+ */
568
+ protected deleteCellView(arg: string | number | CellView) {
569
+ if (arg === this.active?.id) {
570
+ // 如果删除项正好是选中项,则清空active
571
+ this.active = undefined;
572
+ }
573
+ return this.doDeleteCell(arg);
574
+ }
575
+
576
+ protected doDeleteCell = (arg: string | number | CellView) => {
577
+ const index = this.toCellIndex(arg);
578
+ if (index !== undefined) {
579
+ const _cells: CellView[] = [];
580
+ this.getCells().forEach((item, _index) => {
581
+ if (index !== _index) {
582
+ _cells.push(item);
583
+ }
584
+ });
585
+ this.cells = _cells;
586
+ if (index !== this.cells.length) {
587
+ this.selectCell(this.cells[index]);
588
+ } else {
589
+ this.selectCell(this.cells[index - 1]);
590
+ }
591
+ return true;
592
+ }
593
+
594
+ return false;
595
+ };
596
+ exchangeCell(source: CellView, target: CellView): boolean;
597
+ exchangeCell(sourceIndex: number, targetIndex: number): boolean;
598
+ exchangeCell(sourceId: string, targetId: string): boolean;
599
+ exchangeCell(source: string | number | CellView, target: string | number | CellView) {
600
+ const sourceIndex = this.toCellIndex(source);
601
+ const targetIndex = this.toCellIndex(target);
602
+ if (sourceIndex === undefined || targetIndex === undefined) {
603
+ return false;
604
+ }
605
+ this.activeIndex = targetIndex;
606
+ this.isEditMode = false;
607
+ getOrigin(this.sharedModel).transact(() => {
608
+ getOrigin(this.sharedModel).moveCell(sourceIndex, targetIndex);
609
+ });
610
+ this.activeIndex = targetIndex;
611
+ return true;
612
+ }
613
+
614
+ exchangeCells(source: CellView[], targetIndex: number) {
615
+ const startIndex = this.toCellIndex(source[0]);
616
+ const endIndex = this.toCellIndex(source[source.length - 1]);
617
+ if (startIndex === undefined || endIndex === undefined) {
618
+ return false;
619
+ }
620
+ this.isEditMode = false;
621
+ const cellData = source.map((cell) => {
622
+ this.cellViewCache.set(cell.model.id, cell);
623
+ return cell.toJSON();
624
+ });
625
+
626
+ getOrigin(this.sharedModel).transact(() => {
627
+ if (targetIndex > endIndex) {
628
+ //往下交换cell
629
+ if (startIndex === this.activeIndex) {
630
+ //active在头
631
+ this.activeIndex = targetIndex - source.length;
632
+ } else {
633
+ //active在头尾
634
+ this.activeIndex = targetIndex - 1;
635
+ }
636
+ getOrigin(this.sharedModel).deleteCellRange(startIndex, endIndex + 1);
637
+ getOrigin(this.sharedModel).insertCells(targetIndex - source.length, cellData);
638
+ } else {
639
+ //往上交换cell
640
+ if (startIndex === this.activeIndex) {
641
+ //active在头
642
+ this.activeIndex = targetIndex - source.length;
643
+ } else {
644
+ //active在尾
645
+ this.activeIndex = targetIndex + 1;
646
+ }
647
+ getOrigin(this.sharedModel).deleteCellRange(startIndex, endIndex + 1);
648
+ getOrigin(this.sharedModel).insertCells(targetIndex, cellData);
649
+ }
650
+ });
651
+ return true;
652
+ }
653
+
654
+ /**
655
+ * 交换 cell 节点位置
656
+ * @param source id、index、cell
657
+ * @param target id、index、cell
658
+ * @returns
659
+ */
660
+ protected exchangeCellView(
661
+ source: string | number | CellView,
662
+ target: string | number | CellView,
663
+ ) {
664
+ const sourceIndex = this.toCellIndex(source);
665
+ const targetIndex = this.toCellIndex(target);
666
+ if (sourceIndex !== undefined && targetIndex !== undefined) {
667
+ // 交换位置
668
+ const sourceItem = this.cells[sourceIndex];
669
+ const cells = [...this.cells];
670
+ cells.splice(sourceIndex, 1);
671
+ cells.splice(targetIndex, 0, sourceItem);
672
+ this.cells = cells;
673
+ setTimeout(() => {
674
+ // 上下移动也需要调整可视区域范围
675
+ this.scrollToView(sourceItem);
676
+ }, 300);
677
+ return true;
678
+ }
679
+ return false;
680
+ }
681
+ /**
682
+ * 进入命令模式
683
+ */
684
+ enterCommandMode() {
685
+ if (this.active) {
686
+ this.commandMode = true;
687
+ this.onCommandModeChangedEmitter.fire(true);
688
+ this.active.blur();
689
+ }
690
+ }
691
+
692
+ enterEditMode() {
693
+ if (this.active) {
694
+ if (this.selections.length !== 0) {
695
+ this.selections = [];
696
+ }
697
+ this.commandMode = false;
698
+ this.onCommandModeChangedEmitter.fire(false);
699
+ this.active.focus(true);
700
+ }
701
+ }
702
+
703
+ undo() {
704
+ getOrigin(this.sharedModel).undo();
705
+ }
706
+
707
+ redo() {
708
+ getOrigin(this.sharedModel).redo();
709
+ }
710
+ }