@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,51 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import type { CodeNode } from '@lexical/code';
9
+ import type { LexicalEditor, LexicalNode, NodeKey } from 'lexical';
10
+ export type ColorReplacements = Record<string, string>;
11
+ export type ScopedColorReplacements = Record<string, ColorReplacements>;
12
+ export type AllColorReplacements = ColorReplacements | ScopedColorReplacements;
13
+ /**
14
+ * Creates a simple color replacement map
15
+ * @param replacements - Object mapping from old color to new color
16
+ * @returns ColorReplacements object
17
+ */
18
+ export declare function createColorReplacements(replacements: Record<string, string>): ColorReplacements;
19
+ /**
20
+ * Creates scoped color replacements for multiple themes
21
+ * @param scopedReplacements - Object mapping theme names to their color replacements
22
+ * @returns ScopedColorReplacements object
23
+ */
24
+ export declare function createScopedColorReplacements(scopedReplacements: Record<string, Record<string, string>>): ScopedColorReplacements;
25
+ /**
26
+ * Validates that a color value is a valid CSS color
27
+ * @param color - The color string to validate
28
+ * @returns true if the color is valid
29
+ */
30
+ export declare function isValidColor(color: string): boolean;
31
+ export declare function isCodeLanguageLoaded(language: string): boolean;
32
+ export declare function loadCodeLanguage(language: string, editor?: LexicalEditor, codeNodeKey?: NodeKey): void;
33
+ export declare function isCodeThemeLoaded(theme: string): boolean;
34
+ export declare function loadCodeTheme(theme: string, editor?: LexicalEditor, codeNodeKey?: NodeKey): Promise<void>;
35
+ export declare function getCodeLanguageOptions(): [string, string][];
36
+ export declare function getCodeThemeOptions(): [string, string][];
37
+ export declare function normalizeCodeLanguage(language: string): string;
38
+ export declare function $getHighlightNodes(codeNode: CodeNode, language: string, colorReplacements?: {
39
+ current?: AllColorReplacements;
40
+ }): LexicalNode[];
41
+ /**
42
+ * Extended version of $getHighlightNodes with additional options
43
+ * @param codeNode - The CodeNode to highlight
44
+ * @param language - The programming language
45
+ * @param options - Additional highlighting options
46
+ */
47
+ export interface HighlightOptions {
48
+ colorReplacements?: AllColorReplacements;
49
+ theme?: string;
50
+ }
51
+ export declare function $getHighlightNodesWithOptions(codeNode: CodeNode, language: string, options?: HighlightOptions): LexicalNode[];
@@ -0,0 +1,348 @@
1
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
2
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
3
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
4
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
5
+ /**
6
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
7
+ *
8
+ * This source code is licensed under the MIT license found in the
9
+ * LICENSE file in the root directory of this source tree.
10
+ *
11
+ */
12
+
13
+ import { $createCodeHighlightNode, $isCodeNode } from '@lexical/code';
14
+ import { createHighlighterCoreSync, isSpecialLang, isSpecialTheme, stringifyTokenStyle } from '@shikijs/core';
15
+ import { createJavaScriptRegexEngine } from '@shikijs/engine-javascript';
16
+ import { $createLineBreakNode, $createTabNode, $getNodeByKey } from 'lexical';
17
+ import { bundledLanguagesInfo, bundledThemesInfo } from 'shiki';
18
+
19
+ // Color replacements types for Shiki
20
+
21
+ var shiki = createHighlighterCoreSync({
22
+ engine: createJavaScriptRegexEngine(),
23
+ langs: [],
24
+ themes: []
25
+ });
26
+ function getDiffedLanguage(language) {
27
+ var DIFF_LANGUAGE_REGEX = /^diff-([\w-]+)/i;
28
+ var diffLanguageMatch = DIFF_LANGUAGE_REGEX.exec(language);
29
+ return diffLanguageMatch ? diffLanguageMatch[1] : null;
30
+ }
31
+
32
+ /**
33
+ * Type guard to check if color replacements are scoped by theme
34
+ */
35
+ function isScopedColorReplacements(colorReplacements) {
36
+ // Check if any of the keys correspond to known theme names
37
+ // or if the values are objects rather than strings
38
+ var firstValue = Object.values(colorReplacements)[0];
39
+ return _typeof(firstValue) === 'object' && firstValue !== null;
40
+ }
41
+
42
+ /**
43
+ * Resolves color replacements for a specific theme
44
+ * @param colorReplacements - The color replacements configuration
45
+ * @param theme - The current theme name
46
+ * @returns The resolved color replacements for the current theme
47
+ */
48
+ function resolveColorReplacements(colorReplacements, theme) {
49
+ // Check if this is a scoped color replacements object
50
+ if (isScopedColorReplacements(colorReplacements)) {
51
+ // Return the color replacements for the specific theme, or empty object if not found
52
+ return colorReplacements[theme] || {};
53
+ }
54
+
55
+ // Return the simple color replacements object as-is
56
+ return colorReplacements;
57
+ }
58
+
59
+ /**
60
+ * Creates a simple color replacement map
61
+ * @param replacements - Object mapping from old color to new color
62
+ * @returns ColorReplacements object
63
+ */
64
+ export function createColorReplacements(replacements) {
65
+ return replacements;
66
+ }
67
+
68
+ /**
69
+ * Creates scoped color replacements for multiple themes
70
+ * @param scopedReplacements - Object mapping theme names to their color replacements
71
+ * @returns ScopedColorReplacements object
72
+ */
73
+ export function createScopedColorReplacements(scopedReplacements) {
74
+ return scopedReplacements;
75
+ }
76
+
77
+ /**
78
+ * Validates that a color value is a valid CSS color
79
+ * @param color - The color string to validate
80
+ * @returns true if the color is valid
81
+ */
82
+ export function isValidColor(color) {
83
+ // Basic validation for common color formats
84
+ var hexColorRegex = /^#[\dA-Fa-f]{3,8}$/;
85
+ var rgbColorRegex = /^rgb\((?:\s*\d+\s*,){2}\s*\d+\s*\)$/;
86
+ var rgbaColorRegex = /^rgba\((?:\s*\d+\s*,){3}\s*[\d.]+\s*\)$/;
87
+ var hslColorRegex = /^hsl\(\s*\d+(?:\s*,\s*\d+%){2}\s*\)$/;
88
+ var hslaColorRegex = /^hsla\(\s*\d+(?:\s*,\s*\d+%){2}\s*,\s*[\d.]+\s*\)$/;
89
+ var cssVariableRegex = /^var\(--[\w-]+\)$/;
90
+ return hexColorRegex.test(color) || rgbColorRegex.test(color) || rgbaColorRegex.test(color) || hslColorRegex.test(color) || hslaColorRegex.test(color) || cssVariableRegex.test(color);
91
+ }
92
+ export function isCodeLanguageLoaded(language) {
93
+ var diffedLanguage = getDiffedLanguage(language);
94
+ var langId = diffedLanguage || language;
95
+
96
+ // handle shiki Hard-coded languages ['ansi', '', 'plaintext', 'txt', 'text', 'plain']
97
+ if (isSpecialLang(langId)) {
98
+ return true;
99
+ }
100
+
101
+ // note: getLoadedLanguages() also returns aliases
102
+ return shiki.getLoadedLanguages().includes(langId);
103
+ }
104
+ export function loadCodeLanguage(language, editor, codeNodeKey) {
105
+ var diffedLanguage = getDiffedLanguage(language);
106
+ var langId = diffedLanguage ? diffedLanguage : language;
107
+ if (!isCodeLanguageLoaded(langId)) {
108
+ var languageInfo = bundledLanguagesInfo.find(function (desc) {
109
+ return desc.id === langId || desc.aliases && desc.aliases.includes(langId);
110
+ });
111
+ if (languageInfo) {
112
+ // in case we arrive here concurrently (not yet loaded language is loaded twice)
113
+ // shiki's synchronous checks make sure to load it only once
114
+ shiki.loadLanguage(languageInfo.import()).then(function () {
115
+ // here we know that the language is loaded
116
+ // make sure the code is highlighed with the correct language
117
+ if (editor && codeNodeKey) {
118
+ editor.update(function () {
119
+ var codeNode = $getNodeByKey(codeNodeKey);
120
+ if ($isCodeNode(codeNode) && codeNode.getLanguage() === language && !codeNode.getIsSyntaxHighlightSupported()) {
121
+ codeNode.setIsSyntaxHighlightSupported(true);
122
+ }
123
+ });
124
+ }
125
+ });
126
+ }
127
+ }
128
+ }
129
+ function _isCodeThemeLoaded(theme) {
130
+ var themeId = theme;
131
+
132
+ // handle shiki special theme ['none']
133
+ if (isSpecialTheme(themeId)) {
134
+ return true;
135
+ }
136
+ return shiki.getLoadedThemes().includes(themeId);
137
+ }
138
+ export function isCodeThemeLoaded(theme) {
139
+ var themes = theme.split(' ');
140
+ return themes.every(function (t) {
141
+ return _isCodeThemeLoaded(t);
142
+ });
143
+ }
144
+ function _loadCodeTheme(_x, _x2, _x3) {
145
+ return _loadCodeTheme2.apply(this, arguments);
146
+ }
147
+ function _loadCodeTheme2() {
148
+ _loadCodeTheme2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(theme, editor, codeNodeKey) {
149
+ var themeInfo;
150
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
151
+ while (1) switch (_context.prev = _context.next) {
152
+ case 0:
153
+ if (!isCodeThemeLoaded(theme)) {
154
+ themeInfo = bundledThemesInfo.find(function (info) {
155
+ return info.id === theme;
156
+ });
157
+ if (themeInfo) {
158
+ shiki.loadTheme(themeInfo.import()).then(function () {
159
+ if (editor && codeNodeKey) {
160
+ editor.update(function () {
161
+ var codeNode = $getNodeByKey(codeNodeKey);
162
+ if ($isCodeNode(codeNode)) {
163
+ codeNode.markDirty();
164
+ }
165
+ });
166
+ }
167
+ });
168
+ }
169
+ }
170
+ case 1:
171
+ case "end":
172
+ return _context.stop();
173
+ }
174
+ }, _callee);
175
+ }));
176
+ return _loadCodeTheme2.apply(this, arguments);
177
+ }
178
+ export function loadCodeTheme(_x4, _x5, _x6) {
179
+ return _loadCodeTheme3.apply(this, arguments);
180
+ }
181
+ function _loadCodeTheme3() {
182
+ _loadCodeTheme3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(theme, editor, codeNodeKey) {
183
+ var themes;
184
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
185
+ while (1) switch (_context2.prev = _context2.next) {
186
+ case 0:
187
+ themes = theme.split(' ');
188
+ _context2.next = 3;
189
+ return Promise.all(themes.map(function (t) {
190
+ return _loadCodeTheme(t, editor, codeNodeKey);
191
+ }));
192
+ case 3:
193
+ case "end":
194
+ return _context2.stop();
195
+ }
196
+ }, _callee2);
197
+ }));
198
+ return _loadCodeTheme3.apply(this, arguments);
199
+ }
200
+ export function getCodeLanguageOptions() {
201
+ return bundledLanguagesInfo.map(function (i) {
202
+ return [i.id, i.name];
203
+ });
204
+ }
205
+ export function getCodeThemeOptions() {
206
+ return bundledThemesInfo.map(function (i) {
207
+ return [i.id, i.displayName];
208
+ });
209
+ }
210
+ export function normalizeCodeLanguage(language) {
211
+ var langId = language;
212
+ var languageInfo = bundledLanguagesInfo.find(function (desc) {
213
+ return desc.id === langId || desc.aliases && desc.aliases.includes(langId);
214
+ });
215
+ if (languageInfo) {
216
+ return languageInfo.id;
217
+ }
218
+ return language;
219
+ }
220
+ function getTokenStyleObject(token) {
221
+ var style = '';
222
+ if (token.color) {
223
+ style += "color: ".concat(token.color, ";");
224
+ }
225
+ if (token.bgColor) {
226
+ style += "background-color: ".concat(token.bgColor, ";");
227
+ }
228
+ return style;
229
+ }
230
+ function mapTokensToLexicalStructure(tokens, diff, colorReplacements) {
231
+ var nodes = [];
232
+ tokens.forEach(function (line, idx) {
233
+ if (idx) {
234
+ nodes.push($createLineBreakNode());
235
+ }
236
+ line.forEach(function (token, tidx) {
237
+ var text = token.content;
238
+
239
+ // implement diff-xxxx languages
240
+ if (diff && tidx === 0 && text.length > 0) {
241
+ var prefixes = ['+', '-', '>', '<', ' '];
242
+ var prefixTypes = ['inserted', 'deleted', 'inserted', 'deleted', 'unchanged'];
243
+ var prefixIndex = prefixes.indexOf(text[0]);
244
+ if (prefixIndex !== -1) {
245
+ nodes.push($createCodeHighlightNode(prefixes[prefixIndex], prefixTypes[prefixIndex]));
246
+ text = text.slice(1);
247
+ }
248
+ }
249
+ var parts = text.split('\t');
250
+ parts.forEach(function (part, pidx) {
251
+ if (pidx) {
252
+ nodes.push($createTabNode());
253
+ }
254
+ if (part !== '') {
255
+ var _token$htmlStyle, _token$htmlStyle2;
256
+ var node = $createCodeHighlightNode(part);
257
+ if ((_token$htmlStyle = token.htmlStyle) !== null && _token$htmlStyle !== void 0 && _token$htmlStyle['--shiki-light'] && colorReplacements !== null && colorReplacements !== void 0 && colorReplacements['light']) {
258
+ var newColor = colorReplacements['light'][token.htmlStyle['--shiki-light'].toLowerCase()];
259
+ if (newColor) {
260
+ token.htmlStyle['--shiki-light'] = newColor;
261
+ }
262
+ }
263
+ if ((_token$htmlStyle2 = token.htmlStyle) !== null && _token$htmlStyle2 !== void 0 && _token$htmlStyle2['--shiki-dark'] && colorReplacements !== null && colorReplacements !== void 0 && colorReplacements['dark']) {
264
+ var _newColor = colorReplacements['dark'][token.htmlStyle['--shiki-dark'].toLowerCase()];
265
+ if (_newColor) {
266
+ token.htmlStyle['--shiki-dark'] = _newColor;
267
+ }
268
+ }
269
+ var style = stringifyTokenStyle(token.htmlStyle || getTokenStyleObject(token));
270
+ node.setStyle(style);
271
+ nodes.push(node);
272
+ }
273
+ });
274
+ });
275
+ });
276
+ return nodes;
277
+ }
278
+ export function $getHighlightNodes(codeNode, language, colorReplacements) {
279
+ var DIFF_LANGUAGE_REGEX = /^diff-([\w-]+)/i;
280
+ var diffLanguageMatch = DIFF_LANGUAGE_REGEX.exec(language);
281
+ var code = codeNode.getTextContent();
282
+ var theme = codeNode.getTheme() || 'poimandres';
283
+ var themes = theme.split(' ');
284
+
285
+ // Build the options for codeToTokens
286
+ var options = themes.length > 1 ? {
287
+ defaultColor: false,
288
+ lang: diffLanguageMatch ? diffLanguageMatch[1] : language,
289
+ themes: {
290
+ dark: themes[1],
291
+ light: themes[0]
292
+ }
293
+ } : {
294
+ lang: language,
295
+ theme: themes[0]
296
+ };
297
+ var newColorReplacements = {};
298
+ if (colorReplacements !== null && colorReplacements !== void 0 && colorReplacements.current && themes.length > 1) {
299
+ if (colorReplacements.current[themes[0]]) {
300
+ newColorReplacements['light'] = colorReplacements.current[themes[0]];
301
+ }
302
+ if (colorReplacements.current[themes[1]]) {
303
+ newColorReplacements['dark'] = colorReplacements.current[themes[1]];
304
+ }
305
+ } else if (colorReplacements !== null && colorReplacements !== void 0 && colorReplacements.current) {
306
+ options.colorReplacements = resolveColorReplacements(colorReplacements.current, themes[0]);
307
+ }
308
+ var tokensResult = shiki.codeToTokens(code, options);
309
+ var tokens = tokensResult.tokens;
310
+ // let style = '';
311
+ // if (bg) {
312
+ // style += `background-color: ${bg};`;
313
+ // }
314
+ // if (fg) {
315
+ // style += `color: ${fg};`;
316
+ // }
317
+ // if (codeNode.getStyle() !== style) {
318
+ // codeNode.setStyle(style);
319
+ // }
320
+ return mapTokensToLexicalStructure(tokens, !!diffLanguageMatch, newColorReplacements);
321
+ }
322
+
323
+ /**
324
+ * Extended version of $getHighlightNodes with additional options
325
+ * @param codeNode - The CodeNode to highlight
326
+ * @param language - The programming language
327
+ * @param options - Additional highlighting options
328
+ */
329
+
330
+ export function $getHighlightNodesWithOptions(codeNode, language, options) {
331
+ // If theme is provided in options, temporarily override the CodeNode's theme
332
+ var originalGetTheme = codeNode.getTheme;
333
+ if (options !== null && options !== void 0 && options.theme) {
334
+ codeNode.getTheme = function () {
335
+ return options.theme;
336
+ };
337
+ }
338
+ try {
339
+ return $getHighlightNodes(codeNode, language, {
340
+ current: options === null || options === void 0 ? void 0 : options.colorReplacements
341
+ });
342
+ } finally {
343
+ // Restore original getTheme method
344
+ if (options !== null && options !== void 0 && options.theme) {
345
+ codeNode.getTheme = originalGetTheme;
346
+ }
347
+ }
348
+ }
@@ -0,0 +1,18 @@
1
+ import { IEditorPluginConstructor } from "../../../types";
2
+ import { AllColorReplacements } from './FacadeShiki';
3
+ export interface CodeblockPluginOptions {
4
+ /** Color replacements configuration for customizing theme colors */
5
+ colorReplacements?: {
6
+ current?: AllColorReplacements;
7
+ };
8
+ /** Shiki theme name to use for syntax highlighting */
9
+ shikiTheme?: string | {
10
+ dark: string;
11
+ light: string;
12
+ };
13
+ /** Custom CSS theme configuration */
14
+ theme?: {
15
+ code?: string;
16
+ };
17
+ }
18
+ export declare const CodeblockPlugin: IEditorPluginConstructor<CodeblockPluginOptions>;
@@ -0,0 +1,90 @@
1
+ var _class;
2
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
5
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
7
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
8
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
9
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
10
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
11
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
12
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
13
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
15
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
16
+ import { $createCodeNode, $isCodeHighlightNode, $isCodeNode, CodeHighlightNode, CodeNode } from '@lexical/code';
17
+ import { TabNode } from 'lexical';
18
+ import { KernelPlugin } from "../../../editor-kernel/plugin";
19
+ import { IMarkdownShortCutService } from "../../markdown";
20
+ import { CustomShikiTokenizer, registerCodeCommand } from "../command";
21
+ import { getCodeLanguageByInput } from "../utils/language";
22
+ import { registerCodeHighlighting, toCodeTheme } from "./CodeHighlighterShiki";
23
+ export var CodeblockPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
24
+ _inherits(CodeblockPlugin, _KernelPlugin);
25
+ var _super = _createSuper(CodeblockPlugin);
26
+ function CodeblockPlugin(kernel) {
27
+ var _config$theme, _this$config, _this$config3, _kernel$requireServic, _kernel$requireServic2, _kernel$requireServic3, _kernel$requireServic4, _kernel$requireServic5;
28
+ var _this;
29
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
30
+ _classCallCheck(this, CodeblockPlugin);
31
+ _this = _super.call(this);
32
+ // Register the code block plugin
33
+ _this.kernel = kernel;
34
+ _this.config = config;
35
+ kernel.registerNodes([CodeNode, CodeHighlightNode]);
36
+ kernel.registerThemes({
37
+ code: ((_config$theme = config.theme) === null || _config$theme === void 0 ? void 0 : _config$theme.code) || 'editor-code'
38
+ });
39
+ if ((_this$config = _this.config) !== null && _this$config !== void 0 && _this$config.shikiTheme) {
40
+ var _this$config2;
41
+ CustomShikiTokenizer.defaultTheme = (_this$config2 = _this.config) === null || _this$config2 === void 0 ? void 0 : _this$config2.shikiTheme;
42
+ }
43
+ if ((_this$config3 = _this.config) !== null && _this$config3 !== void 0 && _this$config3.colorReplacements) {
44
+ var _this$config4;
45
+ CustomShikiTokenizer.defaultColorReplacements = (_this$config4 = _this.config) === null || _this$config4 === void 0 ? void 0 : _this$config4.colorReplacements;
46
+ }
47
+ (_kernel$requireServic = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic === void 0 || _kernel$requireServic.registerMarkdownShortCut({
48
+ regExp: /^(```|···)(.+)?$/,
49
+ replace: function replace(parentNode, _, match) {
50
+ var code = $createCodeNode(getCodeLanguageByInput(match[2]), toCodeTheme(CustomShikiTokenizer));
51
+ parentNode.replace(code);
52
+ code.selectStart();
53
+ },
54
+ trigger: 'enter',
55
+ type: 'element'
56
+ });
57
+ (_kernel$requireServic2 = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic2 === void 0 || _kernel$requireServic2.registerMarkdownWriter(CodeNode.getType(), function (ctx, node) {
58
+ if ($isCodeNode(node)) {
59
+ ctx.wrap('```' + (node.getLanguage() || '') + '\n', '\n```\n');
60
+ }
61
+ });
62
+ (_kernel$requireServic3 = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic3 === void 0 || _kernel$requireServic3.registerMarkdownWriter(TabNode.getType(), function (ctx) {
63
+ ctx.appendLine(' ');
64
+ });
65
+ (_kernel$requireServic4 = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic4 === void 0 || _kernel$requireServic4.registerMarkdownWriter(CodeHighlightNode.getType(), function (ctx, node) {
66
+ if ($isCodeHighlightNode(node)) {
67
+ ctx.appendLine(node.getTextContent());
68
+ }
69
+ });
70
+ (_kernel$requireServic5 = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic5 === void 0 || _kernel$requireServic5.registerMarkdownWriter('linebreak', function (ctx, node) {
71
+ if ($isCodeNode(node.getParent())) {
72
+ ctx.appendLine('\n');
73
+ }
74
+ });
75
+ return _this;
76
+ }
77
+ _createClass(CodeblockPlugin, [{
78
+ key: "onInit",
79
+ value: function onInit(editor) {
80
+ var _this$config5;
81
+ if ((_this$config5 = this.config) !== null && _this$config5 !== void 0 && _this$config5.shikiTheme) {
82
+ this.register(registerCodeHighlighting(editor, CustomShikiTokenizer));
83
+ } else {
84
+ this.register(registerCodeHighlighting(editor));
85
+ }
86
+ this.register(registerCodeCommand(editor));
87
+ }
88
+ }]);
89
+ return CodeblockPlugin;
90
+ }(KernelPlugin), _defineProperty(_class, "pluginName", 'CodeblockPlugin'), _class);
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ export default function invariant(cond?: boolean, message?: string): asserts cond;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+
9
+ // invariant(condition, message) will refine types based on "condition", and
10
+ // if "condition" is false will throw an error. This function is special-cased
11
+ // in flow itself, so we can't name it anything else.
12
+ export default function invariant(cond, message) {
13
+ if (cond) {
14
+ return;
15
+ }
16
+ throw new Error('Internal Lexical error: invariant() is meant to be replaced at compile ' + 'time. There is no runtime version. Error: ' + message);
17
+ }
@@ -0,0 +1,4 @@
1
+ import { type FC } from 'react';
2
+ import type { ReactCodeblockPluginProps } from './type';
3
+ export declare const ReactCodeblockPlugin: FC<ReactCodeblockPluginProps>;
4
+ export default ReactCodeblockPlugin;
@@ -0,0 +1,51 @@
1
+ 'use client';
2
+
3
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
+ 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."); }
5
+ 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); }
6
+ 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; }
7
+ 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; } }
8
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
9
+ import { usePrevious } from 'ahooks';
10
+ import { useEffect, useLayoutEffect, useRef } from 'react';
11
+ import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
12
+ import { MarkdownPlugin } from "../../markdown";
13
+ import { CodeblockPlugin } from "../plugin";
14
+ import { colorReplacements, useStyles } from "./style";
15
+ export var ReactCodeblockPlugin = function ReactCodeblockPlugin(_ref) {
16
+ var theme = _ref.theme,
17
+ shikiTheme = _ref.shikiTheme;
18
+ var _useLexicalComposerCo = useLexicalComposerContext(),
19
+ _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
20
+ editor = _useLexicalComposerCo2[0];
21
+ var _useStyles = useStyles(),
22
+ styles = _useStyles.styles,
23
+ token = _useStyles.theme;
24
+ var isDarkMode = token.isDarkMode;
25
+ var prevStyles = usePrevious(styles);
26
+ var colorReplacementsRef = useRef(colorReplacements);
27
+ useLayoutEffect(function () {
28
+ editor.registerPlugin(MarkdownPlugin);
29
+ editor.registerPlugin(CodeblockPlugin, {
30
+ colorReplacements: colorReplacementsRef,
31
+ shikiTheme: shikiTheme || {
32
+ dark: 'slack-dark',
33
+ light: 'slack-ochin'
34
+ },
35
+ theme: theme || styles
36
+ });
37
+ }, []);
38
+ useEffect(function () {
39
+ if (prevStyles !== null && prevStyles !== void 0 && prevStyles.code) {
40
+ var _editor$getRootElemen;
41
+ (_editor$getRootElemen = editor.getRootElement()) === null || _editor$getRootElemen === void 0 || _editor$getRootElemen.querySelectorAll('.' + (prevStyles === null || prevStyles === void 0 ? void 0 : prevStyles.code)).forEach(function (node) {
42
+ node.classList.remove(prevStyles.code);
43
+ node.classList.add(styles.code);
44
+ });
45
+ }
46
+ editor.updateTheme('code', styles.code);
47
+ }, [styles, isDarkMode, prevStyles]);
48
+ return null;
49
+ };
50
+ ReactCodeblockPlugin.displayName = 'ReactCodeblockPlugin';
51
+ export default ReactCodeblockPlugin;
@@ -0,0 +1,2 @@
1
+ export { default as ReactCodeblockPlugin } from './ReactCodeblockPlugin';
2
+ export type * from './type';
@@ -0,0 +1 @@
1
+ export { default as ReactCodeblockPlugin } from "./ReactCodeblockPlugin";
@@ -0,0 +1,6 @@
1
+ import { AllColorReplacements } from "../plugin/FacadeShiki";
2
+ export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<{
3
+ code: import("antd-style").SerializedStyles;
4
+ noBackground: import("antd-style").SerializedStyles;
5
+ }>;
6
+ export declare const colorReplacements: AllColorReplacements;