@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,193 @@
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 { $createListNode, $isListItemNode, $isListNode, ListItemNode, ListNode, registerList, registerListStrictIndentTransform } from '@lexical/list';
17
+ import { $getNearestNodeOfType } from '@lexical/utils';
18
+ import { cx } from 'antd-style';
19
+ import { $createParagraphNode, $getSelection, $isRangeSelection, $isRootNode, $isTextNode, COMMAND_PRIORITY_EDITOR, COMMAND_PRIORITY_LOW, INDENT_CONTENT_COMMAND, INSERT_TAB_COMMAND, KEY_BACKSPACE_COMMAND, KEY_TAB_COMMAND, OUTDENT_CONTENT_COMMAND } from 'lexical';
20
+ import { KernelPlugin } from "../../../editor-kernel/plugin";
21
+ import { IMarkdownShortCutService } from "../../markdown";
22
+ import { $indentOverTab, listReplace } from "../utils";
23
+ var ORDERED_LIST_REGEX = /^(\s*)(\d+)\.\s/;
24
+ var UNORDERED_LIST_REGEX = /^(\s*)[*+-]\s/;
25
+ var CHECK_LIST_REGEX = /^(\s*)(?:-\s)?\s?(\[(\s|x)?])\s/i;
26
+
27
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
28
+
29
+ export var ListPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
30
+ _inherits(ListPlugin, _KernelPlugin);
31
+ var _super = _createSuper(ListPlugin);
32
+ function ListPlugin(kernel, config) {
33
+ var _kernel$requireServic, _kernel$requireServic2, _kernel$requireServic3, _kernel$requireServic4, _kernel$requireServic5;
34
+ var _this;
35
+ _classCallCheck(this, ListPlugin);
36
+ _this = _super.call(this);
37
+ // Register the list nodes
38
+ _this.kernel = kernel;
39
+ kernel.registerNodes([ListNode, ListItemNode]);
40
+ // Register themes for list nodes
41
+ kernel.registerThemes({
42
+ // Define themes for list nodes here
43
+ list: {
44
+ listitem: 'editor_listItem',
45
+ nested: {
46
+ listitem: 'editor_listItemNested'
47
+ },
48
+ ol: cx('editor_listOrdered', config === null || config === void 0 ? void 0 : config.theme),
49
+ olDepth: ['editor_listOrdered dp1', 'editor_listOrdered dp2', 'editor_listOrdered dp3', 'editor_listOrdered dp4', 'editor_listOrdered dp5'],
50
+ ul: cx('editor_listUnordered', config === null || config === void 0 ? void 0 : config.theme)
51
+ }
52
+ });
53
+ (_kernel$requireServic = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic === void 0 || _kernel$requireServic.registerMarkdownShortCut({
54
+ regExp: UNORDERED_LIST_REGEX,
55
+ replace: listReplace('bullet'),
56
+ type: 'element'
57
+ });
58
+ (_kernel$requireServic2 = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic2 === void 0 || _kernel$requireServic2.registerMarkdownShortCut({
59
+ regExp: ORDERED_LIST_REGEX,
60
+ replace: listReplace('number'),
61
+ type: 'element'
62
+ });
63
+ (_kernel$requireServic3 = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic3 === void 0 || _kernel$requireServic3.registerMarkdownShortCut({
64
+ regExp: CHECK_LIST_REGEX,
65
+ replace: listReplace('check'),
66
+ type: 'element'
67
+ });
68
+ (_kernel$requireServic4 = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic4 === void 0 || _kernel$requireServic4.registerMarkdownWriter(ListNode.getType(), function (ctx, node) {
69
+ if ($isListNode(node)) {
70
+ ctx.wrap('', '\n');
71
+ }
72
+ });
73
+ var getLevel = function getLevel(node) {
74
+ if (!node) return 0;
75
+ if ($isRootNode(node.getParent())) {
76
+ return 0;
77
+ }
78
+ var parent = node.getParent();
79
+ if (!parent) {
80
+ return 0;
81
+ }
82
+ return getLevel($getNearestNodeOfType(parent, ListNode)) + 1;
83
+ };
84
+ (_kernel$requireServic5 = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic5 === void 0 || _kernel$requireServic5.registerMarkdownWriter(ListItemNode.getType(), function (ctx, node) {
85
+ var parent = node.getParent();
86
+ if ($isListItemNode(node) && $isListNode(parent)) {
87
+ if ($isListNode(node.getFirstChild())) {
88
+ return;
89
+ }
90
+ var level = getLevel(parent);
91
+ var prefix = ' '.repeat(level);
92
+ switch (parent.getListType()) {
93
+ case 'bullet':
94
+ {
95
+ ctx.wrap(prefix + '- ', '\n');
96
+ break;
97
+ }
98
+ case 'number':
99
+ {
100
+ ctx.wrap("".concat(prefix).concat(node.getValue(), ". "), '\n');
101
+ break;
102
+ }
103
+ case 'check':
104
+ {
105
+ ctx.wrap("".concat(prefix, "[").concat(node.getChecked() ? 'x' : ' ', "] "), '\n');
106
+ break;
107
+ }
108
+ default:
109
+ {
110
+ break;
111
+ }
112
+ }
113
+ }
114
+ });
115
+ return _this;
116
+ }
117
+ _createClass(ListPlugin, [{
118
+ key: "onInit",
119
+ value: function onInit(editor) {
120
+ this.register(registerList(editor));
121
+ this.register(registerListStrictIndentTransform(editor));
122
+ this.registerClears(editor.registerCommand(KEY_TAB_COMMAND, function (event) {
123
+ var selection = $getSelection();
124
+ if (!$isRangeSelection(selection)) {
125
+ return false;
126
+ }
127
+ event.preventDefault();
128
+ var command = $indentOverTab(selection) ? event.shiftKey ? OUTDENT_CONTENT_COMMAND : INDENT_CONTENT_COMMAND : INSERT_TAB_COMMAND;
129
+ return editor.dispatchCommand(command, undefined);
130
+ }, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_BACKSPACE_COMMAND, function (event) {
131
+ var _listItemNode$getPare;
132
+ var selection = $getSelection();
133
+ if (!$isRangeSelection(selection) || !selection.isCollapsed()) {
134
+ return false;
135
+ }
136
+ var anchor = selection.anchor;
137
+ if (anchor.offset !== 0) {
138
+ return false;
139
+ }
140
+ var anchorNode = anchor.getNode();
141
+ var listItemNode;
142
+ if ($isTextNode(anchorNode)) {
143
+ // Do not handle non-leading text nodes
144
+ if (anchorNode.getPreviousSibling()) {
145
+ return false;
146
+ }
147
+ var parent = anchorNode.getParentOrThrow();
148
+ if (!$isListItemNode(parent)) {
149
+ return false;
150
+ }
151
+ listItemNode = parent;
152
+ }
153
+ if (!listItemNode || !$isRootNode((_listItemNode$getPare = listItemNode.getParent()) === null || _listItemNode$getPare === void 0 ? void 0 : _listItemNode$getPare.getParent())) {
154
+ return false;
155
+ }
156
+ var listNode = listItemNode.getParentOrThrow();
157
+ queueMicrotask(function () {
158
+ editor.update(function () {
159
+ // Add null check since listItemNode might be undefined in this closure
160
+ if (!listItemNode) return;
161
+ var newlistNode;
162
+ var isFirst = listItemNode.getPreviousSibling() === null;
163
+ if (isFirst) {
164
+ var _p = listItemNode.replace($createParagraphNode(), true);
165
+ _p.select(0, 0);
166
+ return;
167
+ }
168
+ var next = listItemNode.getNextSibling();
169
+ if (next) {
170
+ newlistNode = $createListNode(listNode.getListType(), listItemNode.getValue());
171
+ }
172
+ while (next && newlistNode) {
173
+ next.remove();
174
+ newlistNode.append(next);
175
+ next = next.getNextSibling();
176
+ }
177
+ var p = listItemNode.replace($createParagraphNode(), true);
178
+ p.remove();
179
+ listNode.insertAfter(p);
180
+ if (newlistNode) {
181
+ p.insertAfter(newlistNode);
182
+ }
183
+ p.select(0, 0);
184
+ });
185
+ });
186
+ event.stopImmediatePropagation();
187
+ event.preventDefault();
188
+ return true;
189
+ }, COMMAND_PRIORITY_LOW));
190
+ }
191
+ }]);
192
+ return ListPlugin;
193
+ }(KernelPlugin), _defineProperty(_class, "pluginName", 'ListPlugin'), _class);
@@ -0,0 +1,4 @@
1
+ import { type FC } from 'react';
2
+ import { ReactListPluginProps } from './type';
3
+ declare const ReactListPlugin: FC<ReactListPluginProps>;
4
+ export default ReactListPlugin;
@@ -0,0 +1,29 @@
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 { useLayoutEffect } from 'react';
10
+ import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
11
+ import { MarkdownPlugin } from "../../markdown";
12
+ import { ListPlugin } from "../plugin";
13
+ import { useStyles } from "./style";
14
+ var ReactListPlugin = function ReactListPlugin() {
15
+ var _useLexicalComposerCo = useLexicalComposerContext(),
16
+ _useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
17
+ editor = _useLexicalComposerCo2[0];
18
+ var _useStyles = useStyles(),
19
+ styles = _useStyles.styles;
20
+ useLayoutEffect(function () {
21
+ editor.registerPlugin(MarkdownPlugin);
22
+ editor.registerPlugin(ListPlugin, {
23
+ theme: styles
24
+ });
25
+ }, []);
26
+ return null;
27
+ };
28
+ ReactListPlugin.displayName = 'ReactListPlugin';
29
+ export default ReactListPlugin;
@@ -0,0 +1,2 @@
1
+ export { default as ReactListPlugin } from './ReactListPlugin';
2
+ export type * from './type';
@@ -0,0 +1 @@
1
+ export { default as ReactListPlugin } from "./ReactListPlugin";
@@ -0,0 +1 @@
1
+ export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<import("antd-style").SerializedStyles>;
@@ -0,0 +1,7 @@
1
+ var _templateObject;
2
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
+ import { createStyles } from 'antd-style';
4
+ export var useStyles = createStyles(function (_ref) {
5
+ var css = _ref.css;
6
+ return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n .editor_listUnordered&,\n .editor_listOrdered& {\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n margin-inline-start: 1em;\n padding-inline-start: 0;\n list-style-position: outside;\n\n > .editor_listUnordered,\n > ol {\n margin-block: 0;\n }\n\n > .editor_listItem {\n margin-inline-start: 1em;\n }\n }\n\n .editor_listOrdered& {\n list-style: auto;\n }\n\n .editor_listUnordered& {\n list-style-type: none;\n\n > .editor_listItem:not(:has(ul)) {\n &::before {\n content: '-';\n display: inline-block;\n margin-inline: -1em 0.5em;\n opacity: 0.5;\n }\n }\n }\n\n .editor_listItem {\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.33em);\n font-family: var(--listitem-marker-font-family);\n font-size: var(--listitem-marker-font-size);\n background-color: var(--listitem-marker-background-color);\n\n &::marker {\n font-family: var(--listitem-marker-font-family);\n font-size: var(--listitem-marker-font-size);\n color: var(--listitem-marker-color);\n background-color: var(--listitem-marker-background-color);\n }\n\n p {\n display: inline;\n }\n\n .editor_listUnordered,\n .editor_listOrdered {\n margin: 0;\n }\n }\n\n .editor_listItemNested {\n list-style-type: none;\n }\n "])));
7
+ });
@@ -0,0 +1,3 @@
1
+ export interface ReactListPluginProps {
2
+ className?: string;
3
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { ListType } from '@lexical/list';
2
+ import { RangeSelection } from 'lexical';
3
+ import { ElementTransformer } from "../../markdown/service/shortcut";
4
+ export declare const listReplace: (listType: ListType) => ElementTransformer['replace'];
5
+ export declare function $indentOverTab(selection: RangeSelection): boolean;
@@ -0,0 +1,88 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ 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); }
4
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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
+ import { $createListItemNode, $createListNode, $isListNode } from '@lexical/list';
8
+ import { $filter, $getNearestBlockElementAncestorOrThrow } from '@lexical/utils';
9
+ import { $createRangeSelection, $isBlockElementNode, $normalizeSelection__EXPERIMENTAL } from 'lexical';
10
+ // Amount of spaces that define indentation level
11
+ // TODO: should be an option
12
+ var LIST_INDENT_SIZE = 4;
13
+ function getIndent(whitespaces) {
14
+ var tabs = whitespaces.match(/\t/g);
15
+ var spaces = whitespaces.match(/ /g);
16
+ var indent = 0;
17
+ if (tabs) {
18
+ indent += tabs.length;
19
+ }
20
+ if (spaces) {
21
+ indent += Math.floor(spaces.length / LIST_INDENT_SIZE);
22
+ }
23
+ return indent;
24
+ }
25
+ export var listReplace = function listReplace(listType) {
26
+ return function (parentNode, children, match, isImport) {
27
+ var previousNode = parentNode.getPreviousSibling();
28
+ var nextNode = parentNode.getNextSibling();
29
+ var listItem = $createListItemNode(listType === 'check' ? match[3] === 'x' : undefined);
30
+ if ($isListNode(nextNode) && nextNode.getListType() === listType) {
31
+ var firstChild = nextNode.getFirstChild();
32
+ if (firstChild !== null) {
33
+ firstChild.insertBefore(listItem);
34
+ } else {
35
+ // should never happen, but let's handle gracefully, just in case.
36
+ nextNode.append(listItem);
37
+ }
38
+ parentNode.remove();
39
+ } else if ($isListNode(previousNode) && previousNode.getListType() === listType) {
40
+ previousNode.append(listItem);
41
+ parentNode.remove();
42
+ } else {
43
+ var list = $createListNode(listType, listType === 'number' ? Number(match[2]) : undefined);
44
+ list.append(listItem);
45
+ parentNode.replace(list);
46
+ }
47
+ listItem.append.apply(listItem, _toConsumableArray(children));
48
+ if (!isImport) {
49
+ listItem.select(0, 0);
50
+ }
51
+ var indent = getIndent(match[1]);
52
+ if (indent) {
53
+ listItem.setIndent(indent);
54
+ }
55
+ };
56
+ };
57
+ export function $indentOverTab(selection) {
58
+ // const handled = new Set();
59
+ var nodes = selection.getNodes();
60
+ var canIndentBlockNodes = $filter(nodes, function (node) {
61
+ if ($isBlockElementNode(node) && node.canIndent()) {
62
+ return node;
63
+ }
64
+ return null;
65
+ });
66
+ // 1. If selection spans across canIndent block nodes: indent
67
+ if (canIndentBlockNodes.length > 0) {
68
+ return true;
69
+ }
70
+ // 2. If first (anchor/focus) is at block start: indent
71
+ var anchor = selection.anchor;
72
+ var focus = selection.focus;
73
+ var first = focus.isBefore(anchor) ? focus : anchor;
74
+ var firstNode = first.getNode();
75
+ var firstBlock = $getNearestBlockElementAncestorOrThrow(firstNode);
76
+ if (firstBlock.canIndent()) {
77
+ var firstBlockKey = firstBlock.getKey();
78
+ var selectionAtStart = $createRangeSelection();
79
+ selectionAtStart.anchor.set(firstBlockKey, 0, 'element');
80
+ selectionAtStart.focus.set(firstBlockKey, 0, 'element');
81
+ selectionAtStart = $normalizeSelection__EXPERIMENTAL(selectionAtStart);
82
+ if (selectionAtStart.anchor.is(first)) {
83
+ return true;
84
+ }
85
+ }
86
+ // 3. Else: tab
87
+ return false;
88
+ }
@@ -0,0 +1,10 @@
1
+ import { LexicalEditor } from 'lexical';
2
+ import { DataSource } from "../../../editor-kernel";
3
+ import { MarkdownShortCutService } from '../service/shortcut';
4
+ export default class MarkdownDataSource extends DataSource {
5
+ protected dataType: string;
6
+ protected markdownService: MarkdownShortCutService;
7
+ constructor(dataType: string, markdownService: MarkdownShortCutService);
8
+ read(): void;
9
+ write(editor: LexicalEditor): any;
10
+ }
@@ -0,0 +1,64 @@
1
+ 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); }
2
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ 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); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ 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); }
7
+ 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); }
8
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
9
+ 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); }; }
10
+ 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); }
11
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
12
+ 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; } }
13
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
14
+ import { $getRoot, $isElementNode } from 'lexical';
15
+ import { DataSource } from "../../../editor-kernel";
16
+ import { MarkdownWriterContext } from "./markdown-writer-context";
17
+ var MarkdownDataSource = /*#__PURE__*/function (_DataSource) {
18
+ _inherits(MarkdownDataSource, _DataSource);
19
+ var _super = _createSuper(MarkdownDataSource);
20
+ function MarkdownDataSource(dataType, markdownService) {
21
+ var _this;
22
+ _classCallCheck(this, MarkdownDataSource);
23
+ _this = _super.call(this, dataType);
24
+ _this.dataType = dataType;
25
+ _this.markdownService = markdownService;
26
+ return _this;
27
+ }
28
+ _createClass(MarkdownDataSource, [{
29
+ key: "read",
30
+ value: function read() {
31
+ throw new Error('MarkdownDataSource not implemented yet!');
32
+ }
33
+ }, {
34
+ key: "write",
35
+ value: function write(editor) {
36
+ var _this2 = this;
37
+ return editor.getEditorState().read(function () {
38
+ var rootNode = $getRoot();
39
+ var rootCtx = new MarkdownWriterContext();
40
+ var processChild = function processChild(parentCtx, child) {
41
+ var writer = _this2.markdownService.markdownWriters[child.getType()];
42
+ var currentCtx = parentCtx;
43
+ if ($isElementNode(child)) {
44
+ currentCtx = currentCtx.newChild();
45
+ }
46
+ if (writer) {
47
+ writer(currentCtx, child);
48
+ }
49
+ if ($isElementNode(child)) {
50
+ child.getChildren().forEach(function (child) {
51
+ return processChild(currentCtx, child);
52
+ });
53
+ }
54
+ };
55
+ rootNode.getChildren().forEach(function (child) {
56
+ return processChild(rootCtx, child);
57
+ });
58
+ return rootCtx.toString();
59
+ });
60
+ }
61
+ }]);
62
+ return MarkdownDataSource;
63
+ }(DataSource);
64
+ export { MarkdownDataSource as default };
@@ -0,0 +1,12 @@
1
+ import { IMarkdownWriterContext } from '../service/shortcut';
2
+ export declare class MarkdownWriterContext implements IMarkdownWriterContext {
3
+ private before;
4
+ private after;
5
+ private children;
6
+ private processor?;
7
+ appendLine(line: string): void;
8
+ newChild(): MarkdownWriterContext;
9
+ wrap(before: string, after: string): void;
10
+ addProcessor(processor: (before: string, content: string, after: string) => string): void;
11
+ toString(): string;
12
+ }
@@ -0,0 +1,51 @@
1
+ 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); }
2
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ 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); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ 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; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ 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); }
8
+ export var MarkdownWriterContext = /*#__PURE__*/function () {
9
+ function MarkdownWriterContext() {
10
+ _classCallCheck(this, MarkdownWriterContext);
11
+ _defineProperty(this, "before", '');
12
+ _defineProperty(this, "after", '');
13
+ _defineProperty(this, "children", []);
14
+ _defineProperty(this, "processor", void 0);
15
+ }
16
+ _createClass(MarkdownWriterContext, [{
17
+ key: "appendLine",
18
+ value: function appendLine(line) {
19
+ this.children.push(line);
20
+ }
21
+ }, {
22
+ key: "newChild",
23
+ value: function newChild() {
24
+ var child = new MarkdownWriterContext();
25
+ this.children.push(child);
26
+ return child;
27
+ }
28
+ }, {
29
+ key: "wrap",
30
+ value: function wrap(before, after) {
31
+ this.before = before;
32
+ this.after = after;
33
+ }
34
+ }, {
35
+ key: "addProcessor",
36
+ value: function addProcessor(processor) {
37
+ this.processor = processor;
38
+ }
39
+ }, {
40
+ key: "toString",
41
+ value: function toString() {
42
+ var content = this.before + this.children.map(function (child) {
43
+ return child.toString();
44
+ }).join('') + this.after;
45
+ return this.processor ? this.processor(this.before, this.children.map(function (child) {
46
+ return child.toString();
47
+ }).join(''), this.after) : content;
48
+ }
49
+ }]);
50
+ return MarkdownWriterContext;
51
+ }();
@@ -0,0 +1,2 @@
1
+ export { MarkdownPlugin } from './plugin';
2
+ export { IMarkdownShortCutService } from './service/shortcut';
@@ -0,0 +1,2 @@
1
+ export { MarkdownPlugin } from "./plugin";
2
+ export { IMarkdownShortCutService } from "./service/shortcut";
@@ -0,0 +1,4 @@
1
+ import { IEditorPluginConstructor } from "../../../types";
2
+ export interface MarkdownPluginOptions {
3
+ }
4
+ export declare const MarkdownPlugin: IEditorPluginConstructor<MarkdownPluginOptions>;
@@ -0,0 +1,122 @@
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 { $isCodeNode } from '@lexical/code';
17
+ import { $getNodeByKey, $getSelection, $isRangeSelection, $isTextNode, COLLABORATION_TAG, COMMAND_PRIORITY_CRITICAL, HISTORIC_TAG, KEY_ENTER_COMMAND } from 'lexical';
18
+ import { KernelPlugin } from "../../../editor-kernel/plugin";
19
+ import MarkdownDataSource from "../data-source/markdown-data-source";
20
+ import { IMarkdownShortCutService, MarkdownShortCutService } from "../service/shortcut";
21
+ import { canContainTransformableMarkdown } from "../utils";
22
+
23
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
24
+
25
+ export var MarkdownPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
26
+ _inherits(MarkdownPlugin, _KernelPlugin);
27
+ var _super = _createSuper(MarkdownPlugin);
28
+ function MarkdownPlugin(kernel) {
29
+ var _this;
30
+ _classCallCheck(this, MarkdownPlugin);
31
+ _this = _super.call(this);
32
+ _defineProperty(_assertThisInitialized(_this), "service", new MarkdownShortCutService());
33
+ _this.kernel = kernel;
34
+ kernel.registerService(IMarkdownShortCutService, _this.service);
35
+ // @todo To be implemented
36
+ kernel.registerDataSource(new MarkdownDataSource('markdown', _this.service));
37
+ return _this;
38
+ }
39
+ _createClass(MarkdownPlugin, [{
40
+ key: "onInit",
41
+ value: function onInit(editor) {
42
+ var _this2 = this;
43
+ this.register(editor.registerUpdateListener(function (_ref) {
44
+ var tags = _ref.tags,
45
+ dirtyLeaves = _ref.dirtyLeaves,
46
+ editorState = _ref.editorState,
47
+ prevEditorState = _ref.prevEditorState;
48
+ // Ignore updates from collaboration and undo/redo (as changes already calculated)
49
+ if (tags.has(COLLABORATION_TAG) || tags.has(HISTORIC_TAG)) {
50
+ return;
51
+ }
52
+
53
+ // If editor is still composing (i.e. backticks) we must wait before the user confirms the key
54
+ if (editor.isComposing()) {
55
+ return;
56
+ }
57
+ var selection = editorState.read($getSelection);
58
+ var prevSelection = prevEditorState.read($getSelection);
59
+
60
+ // We expect selection to be a collapsed range and not match previous one (as we want
61
+ // to trigger transforms only as user types)
62
+ if (!$isRangeSelection(prevSelection) || !$isRangeSelection(selection) || !selection.isCollapsed() || selection.is(prevSelection)) {
63
+ return;
64
+ }
65
+ var anchorKey = selection.anchor.key;
66
+ var anchorOffset = selection.anchor.offset;
67
+ var anchorNode = editorState._nodeMap.get(anchorKey);
68
+ if (!$isTextNode(anchorNode) || !dirtyLeaves.has(anchorKey) || anchorOffset !== 1 && anchorOffset > prevSelection.anchor.offset + 1) {
69
+ return;
70
+ }
71
+ editor.update(function () {
72
+ if (!canContainTransformableMarkdown(anchorNode)) {
73
+ return;
74
+ }
75
+ var parentNode = anchorNode.getParent();
76
+ if (parentNode === null || $isCodeNode(parentNode)) {
77
+ return;
78
+ }
79
+ _this2.service.runTransformers(parentNode, anchorNode, selection.anchor.offset);
80
+ });
81
+ }));
82
+ this.register(editor.registerCommand(KEY_ENTER_COMMAND, function (payload) {
83
+ var ret = editor.read(function () {
84
+ var selection = $getSelection();
85
+ if (!$isRangeSelection(selection) || !selection.isCollapsed()) {
86
+ return false;
87
+ }
88
+ var anchorKey = selection.anchor.key;
89
+ var anchorNode = $getNodeByKey(anchorKey);
90
+ if (!anchorNode) return false;
91
+ return {
92
+ anchorNode: anchorNode,
93
+ offset: selection.anchor.offset
94
+ };
95
+ });
96
+ if (!ret) return false;
97
+ var anchorNode = ret.anchorNode,
98
+ offset = ret.offset;
99
+ if (!canContainTransformableMarkdown(anchorNode)) {
100
+ return false;
101
+ }
102
+ var parentNode = anchorNode.getParent();
103
+ if (parentNode === null || $isCodeNode(parentNode)) {
104
+ return false;
105
+ }
106
+ if (_this2.service.testTransformers(parentNode, anchorNode, offset, 'enter')) {
107
+ queueMicrotask(function () {
108
+ editor.update(function () {
109
+ _this2.service.runTransformers(parentNode, anchorNode, offset, 'enter');
110
+ });
111
+ });
112
+ payload === null || payload === void 0 || payload.stopPropagation();
113
+ payload === null || payload === void 0 || payload.stopImmediatePropagation();
114
+ payload === null || payload === void 0 || payload.preventDefault();
115
+ return true;
116
+ }
117
+ return false;
118
+ }, COMMAND_PRIORITY_CRITICAL));
119
+ }
120
+ }]);
121
+ return MarkdownPlugin;
122
+ }(KernelPlugin), _defineProperty(_class, "pluginName", 'MarkdownPlugin'), _class);