@lobehub/editor 1.0.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 (392) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +635 -0
  3. package/es/common/canUseDOM.d.ts +8 -0
  4. package/es/common/canUseDOM.js +9 -0
  5. package/es/common/sys.d.ts +17 -0
  6. package/es/common/sys.js +30 -0
  7. package/es/editor-kernel/data-source.d.ts +8 -0
  8. package/es/editor-kernel/data-source.js +30 -0
  9. package/es/editor-kernel/event.d.ts +3 -0
  10. package/es/editor-kernel/event.js +11 -0
  11. package/es/editor-kernel/index.d.ts +11 -0
  12. package/es/editor-kernel/index.js +14 -0
  13. package/es/editor-kernel/inode/helper.d.ts +11 -0
  14. package/es/editor-kernel/inode/helper.js +48 -0
  15. package/es/editor-kernel/inode/i-element-node.d.ts +5 -0
  16. package/es/editor-kernel/inode/i-element-node.js +1 -0
  17. package/es/editor-kernel/inode/i-node.d.ts +6 -0
  18. package/es/editor-kernel/inode/i-node.js +1 -0
  19. package/es/editor-kernel/inode/index.d.ts +5 -0
  20. package/es/editor-kernel/inode/index.js +5 -0
  21. package/es/editor-kernel/inode/paragraph-node.d.ts +6 -0
  22. package/es/editor-kernel/inode/paragraph-node.js +1 -0
  23. package/es/editor-kernel/inode/root-node.d.ts +7 -0
  24. package/es/editor-kernel/inode/root-node.js +1 -0
  25. package/es/editor-kernel/inode/text-node.d.ts +12 -0
  26. package/es/editor-kernel/inode/text-node.js +1 -0
  27. package/es/editor-kernel/kernel.d.ts +46 -0
  28. package/es/editor-kernel/kernel.js +273 -0
  29. package/es/editor-kernel/plugin.d.ts +7 -0
  30. package/es/editor-kernel/plugin.js +54 -0
  31. package/es/editor-kernel/react/LexicalErrorBoundary.d.ts +13 -0
  32. package/es/editor-kernel/react/LexicalErrorBoundary.js +26 -0
  33. package/es/editor-kernel/react/index.d.ts +5 -0
  34. package/es/editor-kernel/react/index.js +5 -0
  35. package/es/editor-kernel/react/react-context.d.ts +10 -0
  36. package/es/editor-kernel/react/react-context.js +25 -0
  37. package/es/editor-kernel/react/react-editor.d.ts +12 -0
  38. package/es/editor-kernel/react/react-editor.js +57 -0
  39. package/es/editor-kernel/react/useDecorators.d.ts +9 -0
  40. package/es/editor-kernel/react/useDecorators.js +69 -0
  41. package/es/editor-kernel/react/useLexicalEditor.d.ts +2 -0
  42. package/es/editor-kernel/react/useLexicalEditor.js +31 -0
  43. package/es/editor-kernel/react/useLexicalNodeSelection.d.ts +17 -0
  44. package/es/editor-kernel/react/useLexicalNodeSelection.js +99 -0
  45. package/es/editor-kernel/react/useToolbarState.d.ts +31 -0
  46. package/es/editor-kernel/react/useToolbarState.js +302 -0
  47. package/es/editor-kernel/react/useTranslation.d.ts +3 -0
  48. package/es/editor-kernel/react/useTranslation.js +19 -0
  49. package/es/editor-kernel/types.d.ts +189 -0
  50. package/es/editor-kernel/types.js +1 -0
  51. package/es/editor-kernel/utils.d.ts +25 -0
  52. package/es/editor-kernel/utils.js +69 -0
  53. package/es/index.d.ts +14 -0
  54. package/es/index.js +14 -0
  55. package/es/locale/index.d.ts +25 -0
  56. package/es/locale/index.js +24 -0
  57. package/es/plugins/codeblock/command/index.d.ts +20 -0
  58. package/es/plugins/codeblock/command/index.js +84 -0
  59. package/es/plugins/codeblock/index.d.ts +4 -0
  60. package/es/plugins/codeblock/index.js +4 -0
  61. package/es/plugins/codeblock/plugin/CodeHighlighterShiki.d.ts +24 -0
  62. package/es/plugins/codeblock/plugin/CodeHighlighterShiki.js +680 -0
  63. package/es/plugins/codeblock/plugin/FacadeShiki.d.ts +51 -0
  64. package/es/plugins/codeblock/plugin/FacadeShiki.js +348 -0
  65. package/es/plugins/codeblock/plugin/index.d.ts +18 -0
  66. package/es/plugins/codeblock/plugin/index.js +90 -0
  67. package/es/plugins/codeblock/plugin/invariant.d.ts +8 -0
  68. package/es/plugins/codeblock/plugin/invariant.js +17 -0
  69. package/es/plugins/codeblock/react/ReactCodeblockPlugin.d.ts +4 -0
  70. package/es/plugins/codeblock/react/ReactCodeblockPlugin.js +51 -0
  71. package/es/plugins/codeblock/react/index.d.ts +2 -0
  72. package/es/plugins/codeblock/react/index.js +1 -0
  73. package/es/plugins/codeblock/react/style.d.ts +6 -0
  74. package/es/plugins/codeblock/react/style.js +38 -0
  75. package/es/plugins/codeblock/react/type.d.ts +5 -0
  76. package/es/plugins/codeblock/react/type.js +1 -0
  77. package/es/plugins/codeblock/utils/language.d.ts +1 -0
  78. package/es/plugins/codeblock/utils/language.js +12 -0
  79. package/es/plugins/common/command/index.d.ts +7 -0
  80. package/es/plugins/common/command/index.js +31 -0
  81. package/es/plugins/common/data-source/json-data-source.d.ts +7 -0
  82. package/es/plugins/common/data-source/json-data-source.js +39 -0
  83. package/es/plugins/common/data-source/text-data-source.d.ts +6 -0
  84. package/es/plugins/common/data-source/text-data-source.js +54 -0
  85. package/es/plugins/common/index.d.ts +3 -0
  86. package/es/plugins/common/index.js +3 -0
  87. package/es/plugins/common/node/ElementDOMSlot.d.ts +5 -0
  88. package/es/plugins/common/node/ElementDOMSlot.js +59 -0
  89. package/es/plugins/common/node/LexicalLineBreakNode.d.ts +31 -0
  90. package/es/plugins/common/node/LexicalLineBreakNode.js +140 -0
  91. package/es/plugins/common/node/ParagraphNode.d.ts +7 -0
  92. package/es/plugins/common/node/ParagraphNode.js +47 -0
  93. package/es/plugins/common/plugin/index.d.ts +16 -0
  94. package/es/plugins/common/plugin/index.js +245 -0
  95. package/es/plugins/common/plugin/register.d.ts +4 -0
  96. package/es/plugins/common/plugin/register.js +230 -0
  97. package/es/plugins/common/react/Placeholder/index.d.ts +7 -0
  98. package/es/plugins/common/react/Placeholder/index.js +53 -0
  99. package/es/plugins/common/react/Placeholder/style.d.ts +4 -0
  100. package/es/plugins/common/react/Placeholder/style.js +12 -0
  101. package/es/plugins/common/react/ReactEditorContent.d.ts +4 -0
  102. package/es/plugins/common/react/ReactEditorContent.js +7 -0
  103. package/es/plugins/common/react/ReactPlainText.d.ts +4 -0
  104. package/es/plugins/common/react/ReactPlainText.js +100 -0
  105. package/es/plugins/common/react/index.d.ts +3 -0
  106. package/es/plugins/common/react/index.js +3 -0
  107. package/es/plugins/common/react/style.d.ts +18 -0
  108. package/es/plugins/common/react/style.js +38 -0
  109. package/es/plugins/common/react/type.d.ts +21 -0
  110. package/es/plugins/common/react/type.js +1 -0
  111. package/es/plugins/common/utils/index.d.ts +28 -0
  112. package/es/plugins/common/utils/index.js +96 -0
  113. package/es/plugins/file/command/index.d.ts +7 -0
  114. package/es/plugins/file/command/index.js +28 -0
  115. package/es/plugins/file/index.d.ts +3 -0
  116. package/es/plugins/file/index.js +3 -0
  117. package/es/plugins/file/node/FileNode.d.ts +36 -0
  118. package/es/plugins/file/node/FileNode.js +177 -0
  119. package/es/plugins/file/plugin/index.d.ts +14 -0
  120. package/es/plugins/file/plugin/index.js +116 -0
  121. package/es/plugins/file/react/ReactFilePlugin.d.ts +4 -0
  122. package/es/plugins/file/react/ReactFilePlugin.js +74 -0
  123. package/es/plugins/file/react/components/ReactFile.d.ts +10 -0
  124. package/es/plugins/file/react/components/ReactFile.js +65 -0
  125. package/es/plugins/file/react/index.d.ts +2 -0
  126. package/es/plugins/file/react/index.js +1 -0
  127. package/es/plugins/file/react/style.d.ts +3 -0
  128. package/es/plugins/file/react/style.js +11 -0
  129. package/es/plugins/file/react/type.d.ts +13 -0
  130. package/es/plugins/file/react/type.js +1 -0
  131. package/es/plugins/file/utils/index.d.ts +2 -0
  132. package/es/plugins/file/utils/index.js +45 -0
  133. package/es/plugins/hr/command/index.d.ts +3 -0
  134. package/es/plugins/hr/command/index.js +13 -0
  135. package/es/plugins/hr/index.d.ts +3 -0
  136. package/es/plugins/hr/index.js +3 -0
  137. package/es/plugins/hr/node/HorizontalRuleNode.d.ts +16 -0
  138. package/es/plugins/hr/node/HorizontalRuleNode.js +100 -0
  139. package/es/plugins/hr/plugin/index.d.ts +8 -0
  140. package/es/plugins/hr/plugin/index.js +70 -0
  141. package/es/plugins/hr/react/ReactHRPlugin.d.ts +4 -0
  142. package/es/plugins/hr/react/ReactHRPlugin.js +36 -0
  143. package/es/plugins/hr/react/components/HRNode.d.ts +10 -0
  144. package/es/plugins/hr/react/components/HRNode.js +45 -0
  145. package/es/plugins/hr/react/index.d.ts +2 -0
  146. package/es/plugins/hr/react/index.js +1 -0
  147. package/es/plugins/hr/react/style.d.ts +1 -0
  148. package/es/plugins/hr/react/style.js +8 -0
  149. package/es/plugins/hr/react/type.d.ts +3 -0
  150. package/es/plugins/hr/react/type.js +1 -0
  151. package/es/plugins/image/command/index.d.ts +8 -0
  152. package/es/plugins/image/command/index.js +46 -0
  153. package/es/plugins/image/index.d.ts +3 -0
  154. package/es/plugins/image/index.js +3 -0
  155. package/es/plugins/image/node/basie-image-node.d.ts +44 -0
  156. package/es/plugins/image/node/basie-image-node.js +151 -0
  157. package/es/plugins/image/node/image-node.d.ts +26 -0
  158. package/es/plugins/image/node/image-node.js +176 -0
  159. package/es/plugins/image/plugin/index.d.ts +13 -0
  160. package/es/plugins/image/plugin/index.js +74 -0
  161. package/es/plugins/image/react/ReactImagePlugin.d.ts +4 -0
  162. package/es/plugins/image/react/ReactImagePlugin.js +48 -0
  163. package/es/plugins/image/react/components/BrokenImage.d.ts +3 -0
  164. package/es/plugins/image/react/components/BrokenImage.js +18 -0
  165. package/es/plugins/image/react/components/Image.d.ts +7 -0
  166. package/es/plugins/image/react/components/Image.js +71 -0
  167. package/es/plugins/image/react/components/LazyImage.d.ts +8 -0
  168. package/es/plugins/image/react/components/LazyImage.js +99 -0
  169. package/es/plugins/image/react/components/useSupenseImage.d.ts +2 -0
  170. package/es/plugins/image/react/components/useSupenseImage.js +24 -0
  171. package/es/plugins/image/react/index.d.ts +2 -0
  172. package/es/plugins/image/react/index.js +1 -0
  173. package/es/plugins/image/react/style.d.ts +12 -0
  174. package/es/plugins/image/react/style.js +17 -0
  175. package/es/plugins/image/react/type.d.ts +6 -0
  176. package/es/plugins/image/react/type.js +1 -0
  177. package/es/plugins/link/command/index.d.ts +6 -0
  178. package/es/plugins/link/command/index.js +20 -0
  179. package/es/plugins/link/index.d.ts +3 -0
  180. package/es/plugins/link/index.js +3 -0
  181. package/es/plugins/link/node/LinkNode.d.ts +126 -0
  182. package/es/plugins/link/node/LinkNode.js +721 -0
  183. package/es/plugins/link/plugin/index.d.ts +8 -0
  184. package/es/plugins/link/plugin/index.js +94 -0
  185. package/es/plugins/link/react/ReactLinkPlugin.d.ts +4 -0
  186. package/es/plugins/link/react/ReactLinkPlugin.js +168 -0
  187. package/es/plugins/link/react/components/LinkEdit.d.ts +7 -0
  188. package/es/plugins/link/react/components/LinkEdit.js +138 -0
  189. package/es/plugins/link/react/components/Toolbar.d.ts +7 -0
  190. package/es/plugins/link/react/components/Toolbar.js +63 -0
  191. package/es/plugins/link/react/index.d.ts +2 -0
  192. package/es/plugins/link/react/index.js +1 -0
  193. package/es/plugins/link/react/style.d.ts +5 -0
  194. package/es/plugins/link/react/style.js +12 -0
  195. package/es/plugins/link/react/type.d.ts +9 -0
  196. package/es/plugins/link/react/type.js +1 -0
  197. package/es/plugins/link/utils/index.d.ts +4 -0
  198. package/es/plugins/link/utils/index.js +37 -0
  199. package/es/plugins/list/command/index.d.ts +1 -0
  200. package/es/plugins/list/command/index.js +1 -0
  201. package/es/plugins/list/index.d.ts +3 -0
  202. package/es/plugins/list/index.js +3 -0
  203. package/es/plugins/list/plugin/index.d.ts +5 -0
  204. package/es/plugins/list/plugin/index.js +193 -0
  205. package/es/plugins/list/react/ReactListPlugin.d.ts +4 -0
  206. package/es/plugins/list/react/ReactListPlugin.js +29 -0
  207. package/es/plugins/list/react/index.d.ts +2 -0
  208. package/es/plugins/list/react/index.js +1 -0
  209. package/es/plugins/list/react/style.d.ts +1 -0
  210. package/es/plugins/list/react/style.js +7 -0
  211. package/es/plugins/list/react/type.d.ts +3 -0
  212. package/es/plugins/list/react/type.js +1 -0
  213. package/es/plugins/list/utils/index.d.ts +5 -0
  214. package/es/plugins/list/utils/index.js +88 -0
  215. package/es/plugins/markdown/data-source/markdown-data-source.d.ts +10 -0
  216. package/es/plugins/markdown/data-source/markdown-data-source.js +64 -0
  217. package/es/plugins/markdown/data-source/markdown-writer-context.d.ts +12 -0
  218. package/es/plugins/markdown/data-source/markdown-writer-context.js +51 -0
  219. package/es/plugins/markdown/index.d.ts +2 -0
  220. package/es/plugins/markdown/index.js +2 -0
  221. package/es/plugins/markdown/plugin/index.d.ts +4 -0
  222. package/es/plugins/markdown/plugin/index.js +122 -0
  223. package/es/plugins/markdown/service/shortcut.d.ts +139 -0
  224. package/es/plugins/markdown/service/shortcut.js +401 -0
  225. package/es/plugins/markdown/utils/index.d.ts +12 -0
  226. package/es/plugins/markdown/utils/index.js +61 -0
  227. package/es/plugins/mention/command/index.d.ts +6 -0
  228. package/es/plugins/mention/command/index.js +19 -0
  229. package/es/plugins/mention/index.d.ts +3 -0
  230. package/es/plugins/mention/index.js +3 -0
  231. package/es/plugins/mention/node/MentionNode.d.ts +26 -0
  232. package/es/plugins/mention/node/MentionNode.js +143 -0
  233. package/es/plugins/mention/plugin/index.d.ts +11 -0
  234. package/es/plugins/mention/plugin/index.js +61 -0
  235. package/es/plugins/mention/plugin/register.d.ts +2 -0
  236. package/es/plugins/mention/plugin/register.js +46 -0
  237. package/es/plugins/mention/react/ReactMentionPlugin.d.ts +4 -0
  238. package/es/plugins/mention/react/ReactMentionPlugin.js +42 -0
  239. package/es/plugins/mention/react/components/Mention.d.ts +9 -0
  240. package/es/plugins/mention/react/components/Mention.js +39 -0
  241. package/es/plugins/mention/react/index.d.ts +2 -0
  242. package/es/plugins/mention/react/index.js +1 -0
  243. package/es/plugins/mention/react/style.d.ts +3 -0
  244. package/es/plugins/mention/react/style.js +11 -0
  245. package/es/plugins/mention/react/type.d.ts +8 -0
  246. package/es/plugins/mention/react/type.js +1 -0
  247. package/es/plugins/slash/index.d.ts +3 -0
  248. package/es/plugins/slash/index.js +3 -0
  249. package/es/plugins/slash/plugin/index.d.ts +23 -0
  250. package/es/plugins/slash/plugin/index.js +132 -0
  251. package/es/plugins/slash/react/ReactSlashOption.d.ts +4 -0
  252. package/es/plugins/slash/react/ReactSlashOption.js +7 -0
  253. package/es/plugins/slash/react/ReactSlashPlugin.d.ts +4 -0
  254. package/es/plugins/slash/react/ReactSlashPlugin.js +228 -0
  255. package/es/plugins/slash/react/components/SlashMenu.d.ts +8 -0
  256. package/es/plugins/slash/react/components/SlashMenu.js +72 -0
  257. package/es/plugins/slash/react/index.d.ts +4 -0
  258. package/es/plugins/slash/react/index.js +3 -0
  259. package/es/plugins/slash/react/style.d.ts +1 -0
  260. package/es/plugins/slash/react/style.js +9 -0
  261. package/es/plugins/slash/react/type.d.ts +82 -0
  262. package/es/plugins/slash/react/type.js +1 -0
  263. package/es/plugins/slash/react/utils.d.ts +5 -0
  264. package/es/plugins/slash/react/utils.js +20 -0
  265. package/es/plugins/slash/service/i-slash-service.d.ts +38 -0
  266. package/es/plugins/slash/service/i-slash-service.js +64 -0
  267. package/es/plugins/slash/utils/utils.d.ts +38 -0
  268. package/es/plugins/slash/utils/utils.js +192 -0
  269. package/es/plugins/table/command/index.d.ts +13 -0
  270. package/es/plugins/table/command/index.js +73 -0
  271. package/es/plugins/table/index.d.ts +3 -0
  272. package/es/plugins/table/index.js +3 -0
  273. package/es/plugins/table/node/index.d.ts +2 -0
  274. package/es/plugins/table/node/index.js +16 -0
  275. package/es/plugins/table/plugin/index.d.ts +5 -0
  276. package/es/plugins/table/plugin/index.js +85 -0
  277. package/es/plugins/table/react/TableActionMenu/index.d.ts +8 -0
  278. package/es/plugins/table/react/TableActionMenu/index.js +481 -0
  279. package/es/plugins/table/react/TableActionMenu/style.d.ts +1 -0
  280. package/es/plugins/table/react/TableActionMenu/style.js +7 -0
  281. package/es/plugins/table/react/TableActionMenu/utils.d.ts +9 -0
  282. package/es/plugins/table/react/TableActionMenu/utils.js +49 -0
  283. package/es/plugins/table/react/TableHoverActions/index.d.ts +7 -0
  284. package/es/plugins/table/react/TableHoverActions/index.js +268 -0
  285. package/es/plugins/table/react/TableHoverActions/style.d.ts +5 -0
  286. package/es/plugins/table/react/TableHoverActions/style.js +11 -0
  287. package/es/plugins/table/react/TableHoverActions/utils.d.ts +8 -0
  288. package/es/plugins/table/react/TableHoverActions/utils.js +43 -0
  289. package/es/plugins/table/react/TableResize/index.d.ts +10 -0
  290. package/es/plugins/table/react/TableResize/index.js +378 -0
  291. package/es/plugins/table/react/TableResize/style.d.ts +3 -0
  292. package/es/plugins/table/react/TableResize/style.js +10 -0
  293. package/es/plugins/table/react/TableResize/utils.d.ts +4 -0
  294. package/es/plugins/table/react/TableResize/utils.js +40 -0
  295. package/es/plugins/table/react/hooks.d.ts +1 -0
  296. package/es/plugins/table/react/hooks.js +22 -0
  297. package/es/plugins/table/react/index.d.ts +3 -0
  298. package/es/plugins/table/react/index.js +77 -0
  299. package/es/plugins/table/react/style.d.ts +1 -0
  300. package/es/plugins/table/react/style.js +8 -0
  301. package/es/plugins/table/react/type.d.ts +5 -0
  302. package/es/plugins/table/react/type.js +1 -0
  303. package/es/plugins/table/utils/index.d.ts +8 -0
  304. package/es/plugins/table/utils/index.js +83 -0
  305. package/es/plugins/upload/index.d.ts +3 -0
  306. package/es/plugins/upload/index.js +3 -0
  307. package/es/plugins/upload/plugin/index.d.ts +4 -0
  308. package/es/plugins/upload/plugin/index.js +82 -0
  309. package/es/plugins/upload/service/i-upload-service.d.ts +15 -0
  310. package/es/plugins/upload/service/i-upload-service.js +115 -0
  311. package/es/plugins/upload/utils/index.d.ts +1 -0
  312. package/es/plugins/upload/utils/index.js +20 -0
  313. package/es/react/ChatInput/ChatInput.d.ts +4 -0
  314. package/es/react/ChatInput/ChatInput.js +41 -0
  315. package/es/react/ChatInput/index.d.ts +2 -0
  316. package/es/react/ChatInput/index.js +2 -0
  317. package/es/react/ChatInput/style.d.ts +4 -0
  318. package/es/react/ChatInput/style.js +11 -0
  319. package/es/react/ChatInput/type.d.ts +10 -0
  320. package/es/react/ChatInput/type.js +1 -0
  321. package/es/react/ChatInputActionBar/ChatInputActionBar.d.ts +4 -0
  322. package/es/react/ChatInputActionBar/ChatInputActionBar.js +27 -0
  323. package/es/react/ChatInputActionBar/index.d.ts +2 -0
  324. package/es/react/ChatInputActionBar/index.js +2 -0
  325. package/es/react/ChatInputActionBar/style.d.ts +3 -0
  326. package/es/react/ChatInputActionBar/style.js +9 -0
  327. package/es/react/ChatInputActionBar/type.d.ts +7 -0
  328. package/es/react/ChatInputActionBar/type.js +1 -0
  329. package/es/react/ChatInputActions/ChatInputActions.d.ts +4 -0
  330. package/es/react/ChatInputActions/ChatInputActions.js +187 -0
  331. package/es/react/ChatInputActions/components/ChatInputActionsCollapse.d.ts +4 -0
  332. package/es/react/ChatInputActions/components/ChatInputActionsCollapse.js +97 -0
  333. package/es/react/ChatInputActions/index.d.ts +2 -0
  334. package/es/react/ChatInputActions/index.js +1 -0
  335. package/es/react/ChatInputActions/style.d.ts +4 -0
  336. package/es/react/ChatInputActions/style.js +10 -0
  337. package/es/react/ChatInputActions/type.d.ts +38 -0
  338. package/es/react/ChatInputActions/type.js +1 -0
  339. package/es/react/CodeLanguageSelect/CodeLanguageSelect.d.ts +4 -0
  340. package/es/react/CodeLanguageSelect/CodeLanguageSelect.js +96 -0
  341. package/es/react/CodeLanguageSelect/index.d.ts +2 -0
  342. package/es/react/CodeLanguageSelect/index.js +2 -0
  343. package/es/react/CodeLanguageSelect/style.d.ts +3 -0
  344. package/es/react/CodeLanguageSelect/style.js +9 -0
  345. package/es/react/CodeLanguageSelect/type.d.ts +2 -0
  346. package/es/react/CodeLanguageSelect/type.js +1 -0
  347. package/es/react/Editor/Editor.d.ts +4 -0
  348. package/es/react/Editor/Editor.js +78 -0
  349. package/es/react/Editor/index.d.ts +14 -0
  350. package/es/react/Editor/index.js +10 -0
  351. package/es/react/Editor/type.d.ts +24 -0
  352. package/es/react/Editor/type.js +1 -0
  353. package/es/react/Editor/useEditor.d.ts +3 -0
  354. package/es/react/Editor/useEditor.js +4 -0
  355. package/es/react/Editor/utils.d.ts +2 -0
  356. package/es/react/Editor/utils.js +3 -0
  357. package/es/react/EditorProvider/index.d.ts +20 -0
  358. package/es/react/EditorProvider/index.js +25 -0
  359. package/es/react/SendButton/SendButton.d.ts +4 -0
  360. package/es/react/SendButton/SendButton.js +77 -0
  361. package/es/react/SendButton/components/SendIcon.d.ts +6 -0
  362. package/es/react/SendButton/components/SendIcon.js +32 -0
  363. package/es/react/SendButton/components/StopIcon.d.ts +6 -0
  364. package/es/react/SendButton/components/StopIcon.js +61 -0
  365. package/es/react/SendButton/index.d.ts +2 -0
  366. package/es/react/SendButton/index.js +2 -0
  367. package/es/react/SendButton/style.d.ts +6 -0
  368. package/es/react/SendButton/style.js +15 -0
  369. package/es/react/SendButton/type.d.ts +6 -0
  370. package/es/react/SendButton/type.js +1 -0
  371. package/es/react/SlashMenu/SlashMenu.d.ts +4 -0
  372. package/es/react/SlashMenu/SlashMenu.js +68 -0
  373. package/es/react/SlashMenu/index.d.ts +2 -0
  374. package/es/react/SlashMenu/index.js +2 -0
  375. package/es/react/SlashMenu/style.d.ts +4 -0
  376. package/es/react/SlashMenu/style.js +11 -0
  377. package/es/react/SlashMenu/type.d.ts +8 -0
  378. package/es/react/SlashMenu/type.js +1 -0
  379. package/es/react/index.d.ts +8 -0
  380. package/es/react/index.js +8 -0
  381. package/es/types/global.d.ts +20 -0
  382. package/es/types/index.d.ts +2 -0
  383. package/es/types/index.js +2 -0
  384. package/es/types/kernel.d.ts +180 -0
  385. package/es/types/kernel.js +1 -0
  386. package/es/types/locale.d.ts +10 -0
  387. package/es/types/locale.js +1 -0
  388. package/package.json +66 -0
  389. package/patches/lexical+0.33.1.patch +88 -0
  390. package/react.d.ts +1 -0
  391. package/react.js +1 -0
  392. package/scripts/patch-lexical-package-json.js +20 -0
@@ -0,0 +1,680 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
4
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
5
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
6
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
7
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
+ /**
9
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
10
+ *
11
+ * This source code is licensed under the MIT license found in the
12
+ * LICENSE file in the root directory of this source tree.
13
+ *
14
+ */
15
+ import { $getEndOfCodeInLine, $getFirstCodeNodeOfLine, $getLastCodeNodeOfLine, $getStartOfCodeInLine, $isCodeHighlightNode, $isCodeNode, CodeHighlightNode, CodeNode, DEFAULT_CODE_LANGUAGE } from '@lexical/code';
16
+ import { mergeRegister } from '@lexical/utils';
17
+ import { $createLineBreakNode, $createPoint, $createTabNode, $createTextNode, $getCaretRange, $getCaretRangeInDirection, $getNodeByKey, $getSelection, $getSiblingCaret, $getTextPointCaret, $insertNodes, $isLineBreakNode, $isRangeSelection, $isTabNode, $isTextNode, $normalizeCaret, $setSelectionFromCaretRange, COMMAND_PRIORITY_LOW, INDENT_CONTENT_COMMAND, INSERT_TAB_COMMAND, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_TAB_COMMAND, MOVE_TO_END, MOVE_TO_START, OUTDENT_CONTENT_COMMAND, TextNode } from 'lexical';
18
+ import { $getHighlightNodes, isCodeLanguageLoaded, isCodeThemeLoaded, loadCodeLanguage, loadCodeTheme } from "./FacadeShiki";
19
+ import invariant from "./invariant";
20
+ var DEFAULT_CODE_THEME = 'slack-ochin';
21
+ export var ShikiTokenizer = {
22
+ $tokenize: function $tokenize(codeNode, language) {
23
+ return $getHighlightNodes(codeNode, language || this.defaultLanguage, this.defaultColorReplacements);
24
+ },
25
+ defaultColorReplacements: undefined,
26
+ defaultLanguage: DEFAULT_CODE_LANGUAGE,
27
+ defaultTheme: DEFAULT_CODE_THEME
28
+ };
29
+ export function toCodeTheme(tokenizer) {
30
+ if (typeof tokenizer.defaultTheme === 'string') {
31
+ return tokenizer.defaultTheme;
32
+ }
33
+ return tokenizer.defaultTheme.light + ' ' + tokenizer.defaultTheme.dark;
34
+ }
35
+ function $textNodeTransform(node, editor, tokenizer) {
36
+ // Since CodeNode has flat children structure we only need to check
37
+ // if node's parent is a code node and run highlighting if so
38
+ var parentNode = node.getParent();
39
+ if ($isCodeNode(parentNode)) {
40
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
41
+ codeNodeTransform(parentNode, editor, tokenizer);
42
+ } else if ($isCodeHighlightNode(node)) {
43
+ // When code block converted into paragraph or other element
44
+ // code highlight nodes converted back to normal text
45
+ node.replace($createTextNode(node.__text));
46
+ }
47
+ }
48
+ function updateCodeGutter(node, editor) {
49
+ var codeElement = editor.getElementByKey(node.getKey());
50
+ if (codeElement === null) {
51
+ return;
52
+ }
53
+ var children = node.getChildren();
54
+ var childrenLength = children.length;
55
+ // @ts-ignore: internal field
56
+ if (childrenLength === codeElement.__cachedChildrenLength) {
57
+ // Avoid updating the attribute if the children length hasn't changed.
58
+ return;
59
+ }
60
+ // @ts-ignore:: internal field
61
+ codeElement.__cachedChildrenLength = childrenLength;
62
+ var gutter = '1';
63
+ var count = 1;
64
+ for (var i = 0; i < childrenLength; i++) {
65
+ if ($isLineBreakNode(children[i])) {
66
+ gutter += '\n' + ++count;
67
+ }
68
+ }
69
+ codeElement.dataset.gutter = gutter;
70
+ }
71
+
72
+ // Using `skipTransforms` to prevent extra transforms since reformatting the code
73
+ // will not affect code block content itself.
74
+ //
75
+ // Using extra cache (`nodesCurrentlyHighlighting`) since both CodeNode and CodeHighlightNode
76
+ // transforms might be called at the same time (e.g. new CodeHighlight node inserted) and
77
+ // in both cases we'll rerun whole reformatting over CodeNode, which is redundant.
78
+ // Especially when pasting code into CodeBlock.
79
+
80
+ var nodesCurrentlyHighlighting = new Set();
81
+ function codeNodeTransform(node, editor, tokenizer) {
82
+ var nodeKey = node.getKey();
83
+
84
+ // When new code block inserted it might not have language selected
85
+ var language = node.getLanguage();
86
+ if (!language) {
87
+ language = tokenizer.defaultLanguage;
88
+ node.setLanguage(language);
89
+ }
90
+ var theme = node.getTheme();
91
+ if (!theme) {
92
+ theme = toCodeTheme(tokenizer);
93
+ node.setTheme(theme);
94
+ }
95
+
96
+ // dynamic import of themes
97
+ var inFlight = false;
98
+ if (!isCodeThemeLoaded(theme)) {
99
+ loadCodeTheme(theme, editor, nodeKey);
100
+ inFlight = true;
101
+ }
102
+
103
+ // dynamic import of languages
104
+ if (isCodeLanguageLoaded(language)) {
105
+ if (!node.getIsSyntaxHighlightSupported()) {
106
+ node.setIsSyntaxHighlightSupported(true);
107
+ }
108
+ } else {
109
+ if (node.getIsSyntaxHighlightSupported()) {
110
+ node.setIsSyntaxHighlightSupported(false);
111
+ }
112
+ loadCodeLanguage(language, editor, nodeKey);
113
+ inFlight = true;
114
+ }
115
+ if (inFlight) {
116
+ return;
117
+ }
118
+ if (nodesCurrentlyHighlighting.has(nodeKey)) {
119
+ return;
120
+ }
121
+ nodesCurrentlyHighlighting.add(nodeKey);
122
+
123
+ // Using nested update call to pass `skipTransforms` since we don't want
124
+ // each individual CodeHighlightNode to be transformed again as it's already
125
+ // in its final state
126
+ editor.update(function () {
127
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
128
+ $updateAndRetainSelection(nodeKey, function () {
129
+ var currentNode = $getNodeByKey(nodeKey);
130
+ if (!$isCodeNode(currentNode) || !currentNode.isAttached()) {
131
+ return false;
132
+ }
133
+ var lang = currentNode.getLanguage() || tokenizer.defaultLanguage;
134
+ var highlightNodes = tokenizer.$tokenize(currentNode, lang);
135
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
136
+ var diffRange = getDiffRange(currentNode.getChildren(), highlightNodes);
137
+ var from = diffRange.from,
138
+ to = diffRange.to,
139
+ nodesForReplacement = diffRange.nodesForReplacement;
140
+ if (from !== to || nodesForReplacement.length) {
141
+ node.splice(from, to - from, nodesForReplacement);
142
+ return true;
143
+ }
144
+ return false;
145
+ });
146
+ }, {
147
+ onUpdate: function onUpdate() {
148
+ nodesCurrentlyHighlighting.delete(nodeKey);
149
+ },
150
+ skipTransforms: true
151
+ });
152
+ }
153
+
154
+ // Wrapping update function into selection retainer, that tries to keep cursor at the same
155
+ // position as before.
156
+ function $updateAndRetainSelection(nodeKey, updateFn) {
157
+ var node = $getNodeByKey(nodeKey);
158
+ if (!$isCodeNode(node) || !node.isAttached()) {
159
+ return;
160
+ }
161
+ var selection = $getSelection();
162
+ // If it's not range selection (or null selection) there's no need to change it,
163
+ // but we can still run highlighting logic
164
+ if (!$isRangeSelection(selection)) {
165
+ updateFn();
166
+ return;
167
+ }
168
+ var anchor = selection.anchor;
169
+ var anchorOffset = anchor.offset;
170
+ var isNewLineAnchor = anchor.type === 'element' && $isLineBreakNode(node.getChildAtIndex(anchor.offset - 1));
171
+ var textOffset = 0;
172
+
173
+ // Calculating previous text offset (all text node prior to anchor + anchor own text offset)
174
+ if (!isNewLineAnchor) {
175
+ var anchorNode = anchor.getNode();
176
+ textOffset = anchorOffset + anchorNode.getPreviousSiblings().reduce(function (offset, _node) {
177
+ return offset + _node.getTextContentSize();
178
+ }, 0);
179
+ }
180
+ var hasChanges = updateFn();
181
+ if (!hasChanges) {
182
+ return;
183
+ }
184
+
185
+ // Non-text anchors only happen for line breaks, otherwise
186
+ // selection will be within text node (code highlight node)
187
+ if (isNewLineAnchor) {
188
+ anchor.getNode().select(anchorOffset, anchorOffset);
189
+ return;
190
+ }
191
+
192
+ // If it was non-element anchor then we walk through child nodes
193
+ // and looking for a position of original text offset
194
+ node.getChildren().some(function (_node) {
195
+ var isText = $isTextNode(_node);
196
+ if (isText || $isLineBreakNode(_node)) {
197
+ var textContentSize = _node.getTextContentSize();
198
+ if (isText && textContentSize >= textOffset) {
199
+ _node.select(textOffset, textOffset);
200
+ return true;
201
+ }
202
+ textOffset -= textContentSize;
203
+ }
204
+ return false;
205
+ });
206
+ }
207
+
208
+ // Finds minimal diff range between two nodes lists. It returns from/to range boundaries of prevNodes
209
+ // that needs to be replaced with `nodes` (subset of nextNodes) to make prevNodes equal to nextNodes.
210
+ function getDiffRange(prevNodes, nextNodes) {
211
+ var leadingMatch = 0;
212
+ while (leadingMatch < prevNodes.length) {
213
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
214
+ if (!isEqual(prevNodes[leadingMatch], nextNodes[leadingMatch])) {
215
+ break;
216
+ }
217
+ leadingMatch++;
218
+ }
219
+ var prevNodesLength = prevNodes.length;
220
+ var nextNodesLength = nextNodes.length;
221
+ var maxTrailingMatch = Math.min(prevNodesLength, nextNodesLength) - leadingMatch;
222
+ var trailingMatch = 0;
223
+ while (trailingMatch < maxTrailingMatch) {
224
+ trailingMatch++;
225
+ if (
226
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
227
+ !isEqual(prevNodes[prevNodesLength - trailingMatch], nextNodes[nextNodesLength - trailingMatch])) {
228
+ trailingMatch--;
229
+ break;
230
+ }
231
+ }
232
+ var from = leadingMatch;
233
+ var to = prevNodesLength - trailingMatch;
234
+ var nodesForReplacement = nextNodes.slice(leadingMatch, nextNodesLength - trailingMatch);
235
+ return {
236
+ from: from,
237
+ nodesForReplacement: nodesForReplacement,
238
+ to: to
239
+ };
240
+ }
241
+ function isEqual(nodeA, nodeB) {
242
+ // Only checking for code highlight nodes, tabs and linebreaks. If it's regular text node
243
+ // returning false so that it's transformed into code highlight node
244
+ return $isCodeHighlightNode(nodeA) && $isCodeHighlightNode(nodeB) && nodeA.__text === nodeB.__text && nodeA.__highlightType === nodeB.__highlightType && nodeA.__style === nodeB.__style || $isTabNode(nodeA) && $isTabNode(nodeB) || $isLineBreakNode(nodeA) && $isLineBreakNode(nodeB);
245
+ }
246
+
247
+ /**
248
+ * Returns a boolean.
249
+ * Check that the selection span is within a single CodeNode.
250
+ * This is used to guard against executing handlers that can only be
251
+ * applied in a single CodeNode context
252
+ */
253
+ function $isSelectionInCode(selection) {
254
+ if (!$isRangeSelection(selection)) {
255
+ return false;
256
+ }
257
+ var anchorNode = selection.anchor.getNode();
258
+ var maybeAnchorCodeNode = $isCodeNode(anchorNode) ? anchorNode : anchorNode.getParent();
259
+ var focusNode = selection.focus.getNode();
260
+ var maybeFocusCodeNode = $isCodeNode(focusNode) ? focusNode : focusNode.getParent();
261
+ return $isCodeNode(maybeAnchorCodeNode) && maybeAnchorCodeNode.is(maybeFocusCodeNode);
262
+ }
263
+
264
+ /**
265
+ * Returns an Array of code lines
266
+ * Take the sequence of LineBreakNode | TabNode | CodeHighlightNode forming
267
+ * the selection and split it by LineBreakNode.
268
+ * If the selection ends at the start of the last line, it is considered empty.
269
+ * Empty lines are discarded.
270
+ */
271
+ function $getCodeLines(selection) {
272
+ var nodes = selection.getNodes();
273
+ var lines = [];
274
+ if (nodes.length === 1 && $isCodeNode(nodes[0])) {
275
+ return lines;
276
+ }
277
+ var lastLine = [];
278
+ var _iterator = _createForOfIteratorHelper(nodes),
279
+ _step;
280
+ try {
281
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
282
+ var node = _step.value;
283
+ invariant($isCodeHighlightNode(node) || $isTabNode(node) || $isLineBreakNode(node), 'Expected selection to be inside CodeBlock and consisting of CodeHighlightNode, TabNode and LineBreakNode');
284
+ if ($isLineBreakNode(node)) {
285
+ if (lastLine.length > 0) {
286
+ lines.push(lastLine);
287
+ lastLine = [];
288
+ }
289
+ } else {
290
+ lastLine.push(node);
291
+ }
292
+ }
293
+ } catch (err) {
294
+ _iterator.e(err);
295
+ } finally {
296
+ _iterator.f();
297
+ }
298
+ if (lastLine.length > 0) {
299
+ var selectionEnd = selection.isBackward() ? selection.anchor : selection.focus;
300
+
301
+ // Discard the last line if the selection ends exactly at the
302
+ // start of the line (no real selection)
303
+ var lastPoint = $createPoint(lastLine[0].getKey(), 0, 'text');
304
+ if (!selectionEnd.is(lastPoint)) {
305
+ lines.push(lastLine);
306
+ }
307
+ }
308
+ return lines;
309
+ }
310
+ function $handleTab(shiftKey) {
311
+ var selection = $getSelection();
312
+ if (!$isRangeSelection(selection) || !$isSelectionInCode(selection)) {
313
+ return null;
314
+ }
315
+ var indentOrOutdent = !shiftKey ? INDENT_CONTENT_COMMAND : OUTDENT_CONTENT_COMMAND;
316
+ var tabOrOutdent = !shiftKey ? INSERT_TAB_COMMAND : OUTDENT_CONTENT_COMMAND;
317
+ var anchor = selection.anchor;
318
+ var focus = selection.focus;
319
+
320
+ // 1. early decision when there is no real selection
321
+ if (anchor.is(focus)) {
322
+ return tabOrOutdent;
323
+ }
324
+
325
+ // 2. If only empty lines or multiple non-empty lines are selected: indent/outdent
326
+ var codeLines = $getCodeLines(selection);
327
+ if (codeLines.length !== 1) {
328
+ return indentOrOutdent;
329
+ }
330
+ var codeLine = codeLines[0];
331
+ var codeLineLength = codeLine.length;
332
+ invariant(codeLineLength !== 0, '$getCodeLines only extracts non-empty lines');
333
+
334
+ // Take into account the direction of the selection
335
+ var selectionFirst;
336
+ var selectionLast;
337
+ if (selection.isBackward()) {
338
+ selectionFirst = focus;
339
+ selectionLast = anchor;
340
+ } else {
341
+ selectionFirst = anchor;
342
+ selectionLast = focus;
343
+ }
344
+
345
+ // find boundary elements of the line
346
+ // since codeLine only contains TabNode | CodeHighlightNode
347
+ // the result of these functions should is of Type TabNode | CodeHighlightNode
348
+ var firstOfLine = $getFirstCodeNodeOfLine(codeLine[0]);
349
+ var lastOfLine = $getLastCodeNodeOfLine(codeLine[0]);
350
+ var anchorOfLine = $createPoint(firstOfLine.getKey(), 0, 'text');
351
+ var focusOfLine = $createPoint(lastOfLine.getKey(), lastOfLine.getTextContentSize(), 'text');
352
+
353
+ // 3. multiline because selection started strictly before the line
354
+ if (selectionFirst.isBefore(anchorOfLine)) {
355
+ return indentOrOutdent;
356
+ }
357
+
358
+ // 4. multiline because the selection stops strictly after the line
359
+ if (focusOfLine.isBefore(selectionLast)) {
360
+ return indentOrOutdent;
361
+ }
362
+
363
+ // The selection if within the line.
364
+ // 4. If it does not touch both borders, it needs a tab
365
+ if (anchorOfLine.isBefore(selectionFirst) || selectionLast.isBefore(focusOfLine)) {
366
+ return tabOrOutdent;
367
+ }
368
+
369
+ // 5. Selection is matching a full line on non-empty code
370
+ return indentOrOutdent;
371
+ }
372
+ function $handleMultilineIndent(type) {
373
+ var selection = $getSelection();
374
+ if (!$isRangeSelection(selection) || !$isSelectionInCode(selection)) {
375
+ return false;
376
+ }
377
+ var codeLines = $getCodeLines(selection);
378
+ var codeLinesLength = codeLines.length;
379
+
380
+ // Special Indent case
381
+ // Selection is collapsed at the beginning of a line
382
+ if (codeLinesLength === 0 && selection.isCollapsed()) {
383
+ if (type === INDENT_CONTENT_COMMAND) {
384
+ selection.insertNodes([$createTabNode()]);
385
+ }
386
+ return true;
387
+ }
388
+
389
+ // Special Indent case
390
+ // Selection is matching only one LineBreak
391
+ if (codeLinesLength === 0 && type === INDENT_CONTENT_COMMAND && selection.getTextContent() === '\n') {
392
+ var tabNode = $createTabNode();
393
+ var lineBreakNode = $createLineBreakNode();
394
+ var direction = selection.isBackward() ? 'previous' : 'next';
395
+ selection.insertNodes([tabNode, lineBreakNode]);
396
+ $setSelectionFromCaretRange($getCaretRangeInDirection($getCaretRange($getTextPointCaret(tabNode, 'next', 0), $normalizeCaret($getSiblingCaret(lineBreakNode, 'next'))), direction));
397
+ return true;
398
+ }
399
+
400
+ // Indent Non Empty Lines
401
+ for (var i = 0; i < codeLinesLength; i++) {
402
+ var line = codeLines[i];
403
+ // a line here is never empty
404
+ if (line.length > 0) {
405
+ var firstOfLine = line[0];
406
+
407
+ // make sure to consider the first node on the first line
408
+ // because the line might not be fully selected
409
+ if (i === 0) {
410
+ firstOfLine = $getFirstCodeNodeOfLine(firstOfLine);
411
+ }
412
+ if (type === INDENT_CONTENT_COMMAND) {
413
+ var _tabNode = $createTabNode();
414
+ firstOfLine.insertBefore(_tabNode);
415
+ // First real code line may need selection adjustment
416
+ // when firstOfLine is at the selection boundary
417
+ if (i === 0) {
418
+ var anchorKey = selection.isBackward() ? 'focus' : 'anchor';
419
+ var anchorLine = $createPoint(firstOfLine.getKey(), 0, 'text');
420
+ if (selection[anchorKey].is(anchorLine)) {
421
+ selection[anchorKey].set(_tabNode.getKey(), 0, 'text');
422
+ }
423
+ }
424
+ } else if ($isTabNode(firstOfLine)) {
425
+ firstOfLine.remove();
426
+ }
427
+ }
428
+ }
429
+ return true;
430
+ }
431
+ function $handleShiftLines(type, event) {
432
+ // We only care about the alt+arrow keys
433
+ var selection = $getSelection();
434
+ if (!$isRangeSelection(selection)) {
435
+ return false;
436
+ }
437
+
438
+ // I'm not quite sure why, but it seems like calling anchor.getNode() collapses the selection here
439
+ // So first, get the anchor and the focus, then get their nodes
440
+ var anchor = selection.anchor,
441
+ focus = selection.focus;
442
+ var anchorOffset = anchor.offset;
443
+ var focusOffset = focus.offset;
444
+ var anchorNode = anchor.getNode();
445
+ var focusNode = focus.getNode();
446
+ var arrowIsUp = type === KEY_ARROW_UP_COMMAND;
447
+
448
+ // Ensure the selection is within the codeblock
449
+ if (!$isSelectionInCode(selection) || !($isCodeHighlightNode(anchorNode) || $isTabNode(anchorNode)) || !($isCodeHighlightNode(focusNode) || $isTabNode(focusNode))) {
450
+ return false;
451
+ }
452
+ if (!event.altKey) {
453
+ // Handle moving selection out of the code block, given there are no
454
+ // siblings that can natively take the selection.
455
+ if (selection.isCollapsed()) {
456
+ var _codeNode = anchorNode.getParentOrThrow();
457
+ if (arrowIsUp && anchorOffset === 0 && anchorNode.getPreviousSibling() === null) {
458
+ var codeNodeSibling = _codeNode.getPreviousSibling();
459
+ if (codeNodeSibling === null) {
460
+ _codeNode.selectPrevious();
461
+ event.preventDefault();
462
+ return true;
463
+ }
464
+ } else if (!arrowIsUp && anchorOffset === anchorNode.getTextContentSize() && anchorNode.getNextSibling() === null) {
465
+ var _codeNodeSibling = _codeNode.getNextSibling();
466
+ if (_codeNodeSibling === null) {
467
+ _codeNode.selectNext();
468
+ event.preventDefault();
469
+ return true;
470
+ }
471
+ }
472
+ }
473
+ return false;
474
+ }
475
+ var start;
476
+ var end;
477
+ if (anchorNode.isBefore(focusNode)) {
478
+ start = $getFirstCodeNodeOfLine(anchorNode);
479
+ end = $getLastCodeNodeOfLine(focusNode);
480
+ } else {
481
+ start = $getFirstCodeNodeOfLine(focusNode);
482
+ end = $getLastCodeNodeOfLine(anchorNode);
483
+ }
484
+ if (start === null || end === null) {
485
+ return false;
486
+ }
487
+ var range = start.getNodesBetween(end);
488
+ var _iterator2 = _createForOfIteratorHelper(range),
489
+ _step2;
490
+ try {
491
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
492
+ var node = _step2.value;
493
+ if (!$isCodeHighlightNode(node) && !$isTabNode(node) && !$isLineBreakNode(node)) {
494
+ return false;
495
+ }
496
+ }
497
+
498
+ // After this point, we know the selection is within the codeblock. We may not be able to
499
+ // actually move the lines around, but we want to return true either way to prevent
500
+ // the event's default behavior
501
+ } catch (err) {
502
+ _iterator2.e(err);
503
+ } finally {
504
+ _iterator2.f();
505
+ }
506
+ event.preventDefault();
507
+ event.stopPropagation(); // required to stop cursor movement under Firefox
508
+
509
+ var linebreak = arrowIsUp ? start.getPreviousSibling() : end.getNextSibling();
510
+ if (!$isLineBreakNode(linebreak)) {
511
+ return true;
512
+ }
513
+ var sibling = arrowIsUp ? linebreak.getPreviousSibling() : linebreak.getNextSibling();
514
+ if (sibling === null) {
515
+ return true;
516
+ }
517
+ var maybeInsertionPoint = $isCodeHighlightNode(sibling) || $isTabNode(sibling) || $isLineBreakNode(sibling) ? arrowIsUp ? $getFirstCodeNodeOfLine(sibling) : $getLastCodeNodeOfLine(sibling) : null;
518
+ var insertionPoint = maybeInsertionPoint !== null ? maybeInsertionPoint : sibling;
519
+ linebreak.remove();
520
+ range.forEach(function (node) {
521
+ return node.remove();
522
+ });
523
+ if (type === KEY_ARROW_UP_COMMAND) {
524
+ range.forEach(function (node) {
525
+ return insertionPoint.insertBefore(node);
526
+ });
527
+ insertionPoint.insertBefore(linebreak);
528
+ } else {
529
+ insertionPoint.insertAfter(linebreak);
530
+ insertionPoint = linebreak;
531
+ range.forEach(function (node) {
532
+ insertionPoint.insertAfter(node);
533
+ insertionPoint = node;
534
+ });
535
+ }
536
+ selection.setTextNodeRange(anchorNode, anchorOffset, focusNode, focusOffset);
537
+ return true;
538
+ }
539
+ function $handleMoveTo(type, event) {
540
+ var selection = $getSelection();
541
+ if (!$isRangeSelection(selection)) {
542
+ return false;
543
+ }
544
+ var anchor = selection.anchor,
545
+ focus = selection.focus;
546
+ var anchorNode = anchor.getNode();
547
+ var focusNode = focus.getNode();
548
+ var isMoveToStart = type === MOVE_TO_START;
549
+
550
+ // Ensure the selection is within the codeblock
551
+ if (!$isSelectionInCode(selection) || !($isCodeHighlightNode(anchorNode) || $isTabNode(anchorNode)) || !($isCodeHighlightNode(focusNode) || $isTabNode(focusNode))) {
552
+ return false;
553
+ }
554
+ if (isMoveToStart) {
555
+ var start = $getStartOfCodeInLine(focusNode, focus.offset);
556
+ if (start !== null) {
557
+ var node = start.node,
558
+ offset = start.offset;
559
+ if ($isLineBreakNode(node)) {
560
+ node.selectNext(0, 0);
561
+ } else {
562
+ selection.setTextNodeRange(node, offset, node, offset);
563
+ }
564
+ } else {
565
+ focusNode.getParentOrThrow().selectStart();
566
+ }
567
+ } else {
568
+ var _node2 = $getEndOfCodeInLine(focusNode);
569
+ _node2.select();
570
+ }
571
+ event.preventDefault();
572
+ event.stopPropagation();
573
+ return true;
574
+ }
575
+ export function registerCodeHighlighting(editor, tokenizer) {
576
+ if (!editor.hasNodes([CodeNode, CodeHighlightNode])) {
577
+ throw new Error('CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor');
578
+ }
579
+
580
+ // eslint-disable-next-line eqeqeq
581
+ if (tokenizer == null) {
582
+ // eslint-disable-next-line no-param-reassign
583
+ tokenizer = ShikiTokenizer;
584
+ }
585
+ var registrations = [];
586
+
587
+ // Only register the mutation listener if not in headless mode
588
+ if (editor._headless !== true) {
589
+ registrations.push(editor.registerMutationListener(CodeNode, function (mutations) {
590
+ editor.update(function () {
591
+ var _iterator3 = _createForOfIteratorHelper(mutations),
592
+ _step3;
593
+ try {
594
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
595
+ var _step3$value = _slicedToArray(_step3.value, 2),
596
+ key = _step3$value[0],
597
+ type = _step3$value[1];
598
+ if (type !== 'destroyed') {
599
+ var node = $getNodeByKey(key);
600
+ if (node !== null) {
601
+ updateCodeGutter(node, editor);
602
+ }
603
+ }
604
+ }
605
+ } catch (err) {
606
+ _iterator3.e(err);
607
+ } finally {
608
+ _iterator3.f();
609
+ }
610
+ });
611
+ }, {
612
+ skipInitialization: false
613
+ }));
614
+ }
615
+
616
+ // Add the rest of the registrations
617
+ registrations.push(editor.registerNodeTransform(CodeNode, function (node) {
618
+ return codeNodeTransform(node, editor, tokenizer);
619
+ }), editor.registerNodeTransform(TextNode, function (node) {
620
+ return $textNodeTransform(node, editor, tokenizer);
621
+ }), editor.registerNodeTransform(CodeHighlightNode, function (node) {
622
+ return $textNodeTransform(node, editor, tokenizer);
623
+ }), editor.registerCommand(KEY_TAB_COMMAND, function (event) {
624
+ var command = $handleTab(event.shiftKey);
625
+ if (command === null) {
626
+ return false;
627
+ }
628
+ event.preventDefault();
629
+ editor.dispatchCommand(command, undefined);
630
+ return true;
631
+ }, COMMAND_PRIORITY_LOW), editor.registerCommand(INSERT_TAB_COMMAND, function () {
632
+ var selection = $getSelection();
633
+ if (!$isSelectionInCode(selection)) {
634
+ return false;
635
+ }
636
+ $insertNodes([$createTabNode()]);
637
+ return true;
638
+ }, COMMAND_PRIORITY_LOW), editor.registerCommand(INDENT_CONTENT_COMMAND, function () {
639
+ return $handleMultilineIndent(INDENT_CONTENT_COMMAND);
640
+ }, COMMAND_PRIORITY_LOW), editor.registerCommand(OUTDENT_CONTENT_COMMAND, function () {
641
+ return $handleMultilineIndent(OUTDENT_CONTENT_COMMAND);
642
+ }, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ARROW_UP_COMMAND, function (event) {
643
+ var selection = $getSelection();
644
+ if (!$isRangeSelection(selection)) {
645
+ return false;
646
+ }
647
+ var anchor = selection.anchor;
648
+ var anchorNode = anchor.getNode();
649
+ if (!$isSelectionInCode(selection)) {
650
+ return false;
651
+ }
652
+ // If at the start of a code block, prevent selection from moving out
653
+ if (selection.isCollapsed() && anchor.offset === 0 && anchorNode.getPreviousSibling() === null && $isCodeNode(anchorNode.getParentOrThrow())) {
654
+ event.preventDefault();
655
+ return true;
656
+ }
657
+ return $handleShiftLines(KEY_ARROW_UP_COMMAND, event);
658
+ }, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ARROW_DOWN_COMMAND, function (event) {
659
+ var selection = $getSelection();
660
+ if (!$isRangeSelection(selection)) {
661
+ return false;
662
+ }
663
+ var anchor = selection.anchor;
664
+ var anchorNode = anchor.getNode();
665
+ if (!$isSelectionInCode(selection)) {
666
+ return false;
667
+ }
668
+ // If at the end of a code block, prevent selection from moving out
669
+ if (selection.isCollapsed() && anchor.offset === anchorNode.getTextContentSize() && anchorNode.getNextSibling() === null && $isCodeNode(anchorNode.getParentOrThrow())) {
670
+ event.preventDefault();
671
+ return true;
672
+ }
673
+ return $handleShiftLines(KEY_ARROW_DOWN_COMMAND, event);
674
+ }, COMMAND_PRIORITY_LOW), editor.registerCommand(MOVE_TO_START, function (event) {
675
+ return $handleMoveTo(MOVE_TO_START, event);
676
+ }, COMMAND_PRIORITY_LOW), editor.registerCommand(MOVE_TO_END, function (event) {
677
+ return $handleMoveTo(MOVE_TO_END, event);
678
+ }, COMMAND_PRIORITY_LOW));
679
+ return mergeRegister.apply(void 0, registrations);
680
+ }