@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,721 @@
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
+ 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); } }
9
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
11
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
12
+ 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); }
13
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
14
+ 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); }; }
15
+ 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); }
16
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
17
+ 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; } }
18
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
19
+ 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; }
20
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
21
+ 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); }
22
+ /* eslint-disable @typescript-eslint/no-use-before-define */
23
+ import { $findMatchingParent, addClassNamesToElement, isHTMLAnchorElement } from '@lexical/utils';
24
+ import { $applyNodeReplacement, $getSelection, $isElementNode, $isNodeSelection, $isRangeSelection, $normalizeSelection__EXPERIMENTAL, $setSelection, ElementNode, createCommand } from 'lexical';
25
+ import { assert } from "../../../editor-kernel/utils";
26
+ var SUPPORTED_URL_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'sms:', 'tel:']);
27
+ export var HOVER_LINK_COMMAND = createCommand('HOVER_LINK_COMMAND');
28
+ export var HOVER_OUT_LINK_COMMAND = createCommand('HOVER_OUT_LINK_COMMAND');
29
+
30
+ /** @noInheritDoc */
31
+ export var LinkNode = /*#__PURE__*/function (_ElementNode) {
32
+ _inherits(LinkNode, _ElementNode);
33
+ var _super = _createSuper(LinkNode);
34
+ function LinkNode() {
35
+ var _this;
36
+ var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
37
+ var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
38
+ var key = arguments.length > 2 ? arguments[2] : undefined;
39
+ _classCallCheck(this, LinkNode);
40
+ _this = _super.call(this, key);
41
+ /** @internal */
42
+ _defineProperty(_assertThisInitialized(_this), "__url", void 0);
43
+ /** @internal */
44
+ _defineProperty(_assertThisInitialized(_this), "__target", void 0);
45
+ /** @internal */
46
+ _defineProperty(_assertThisInitialized(_this), "__rel", void 0);
47
+ /** @internal */
48
+ _defineProperty(_assertThisInitialized(_this), "__title", void 0);
49
+ var _attributes$target = attributes.target,
50
+ target = _attributes$target === void 0 ? null : _attributes$target,
51
+ _attributes$rel = attributes.rel,
52
+ rel = _attributes$rel === void 0 ? null : _attributes$rel,
53
+ _attributes$title = attributes.title,
54
+ title = _attributes$title === void 0 ? null : _attributes$title;
55
+ _this.__url = url;
56
+ _this.__target = target;
57
+ _this.__rel = rel;
58
+ _this.__title = title;
59
+ return _this;
60
+ }
61
+ _createClass(LinkNode, [{
62
+ key: "createDOM",
63
+ value: function createDOM(config, editor) {
64
+ var _this2 = this;
65
+ var element = document.createElement('a');
66
+ this.updateLinkDOM(null, element, config);
67
+ addClassNamesToElement(element, config.theme.link);
68
+ element.addEventListener('mouseenter', function (event) {
69
+ if (event.target instanceof HTMLElement) {
70
+ event.target.classList.add('hover');
71
+ editor.dispatchCommand(HOVER_LINK_COMMAND, {
72
+ event: event,
73
+ linkNode: _this2
74
+ });
75
+ }
76
+ });
77
+ element.addEventListener('mouseleave', function (event) {
78
+ if (event.target instanceof HTMLElement) {
79
+ event.target.classList.remove('hover');
80
+ editor.dispatchCommand(HOVER_OUT_LINK_COMMAND, {
81
+ event: event
82
+ });
83
+ }
84
+ });
85
+ return element;
86
+ }
87
+ }, {
88
+ key: "updateLinkDOM",
89
+ value: function updateLinkDOM(prevNode, anchor,
90
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
91
+ _config) {
92
+ if (isHTMLAnchorElement(anchor)) {
93
+ if (!prevNode || prevNode.__url !== this.__url) {
94
+ anchor.href = this.sanitizeUrl(this.__url);
95
+ }
96
+ var _iterator = _createForOfIteratorHelper(['target', 'rel', 'title']),
97
+ _step;
98
+ try {
99
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
100
+ var attr = _step.value;
101
+ var key = "__".concat(attr);
102
+ var value = this[key];
103
+ if (!prevNode || prevNode[key] !== value) {
104
+ if (value) {
105
+ anchor[attr] = value;
106
+ } else {
107
+ anchor.removeAttribute(attr);
108
+ }
109
+ }
110
+ }
111
+ } catch (err) {
112
+ _iterator.e(err);
113
+ } finally {
114
+ _iterator.f();
115
+ }
116
+ }
117
+ }
118
+ }, {
119
+ key: "updateDOM",
120
+ value: function updateDOM(prevNode, anchor, config) {
121
+ this.updateLinkDOM(prevNode, anchor, config);
122
+ return false;
123
+ }
124
+ }, {
125
+ key: "updateFromJSON",
126
+ value: function updateFromJSON(serializedNode) {
127
+ return _get(_getPrototypeOf(LinkNode.prototype), "updateFromJSON", this).call(this, serializedNode).setURL(serializedNode.url).setRel(serializedNode.rel || null).setTarget(serializedNode.target || null).setTitle(serializedNode.title || null);
128
+ }
129
+ }, {
130
+ key: "sanitizeUrl",
131
+ value: function sanitizeUrl(url) {
132
+ // eslint-disable-next-line no-param-reassign
133
+ url = formatUrl(url);
134
+ try {
135
+ var parsedUrl = new URL(formatUrl(url));
136
+ // eslint-disable-next-line no-script-url
137
+ if (!SUPPORTED_URL_PROTOCOLS.has(parsedUrl.protocol)) {
138
+ return 'about:blank';
139
+ }
140
+ } catch (_unused) {
141
+ return url;
142
+ }
143
+ return url;
144
+ }
145
+ }, {
146
+ key: "exportJSON",
147
+ value: function exportJSON() {
148
+ return _objectSpread(_objectSpread({}, _get(_getPrototypeOf(LinkNode.prototype), "exportJSON", this).call(this)), {}, {
149
+ rel: this.getRel(),
150
+ target: this.getTarget(),
151
+ title: this.getTitle(),
152
+ url: this.getURL()
153
+ });
154
+ }
155
+ }, {
156
+ key: "getURL",
157
+ value: function getURL() {
158
+ return this.getLatest().__url;
159
+ }
160
+ }, {
161
+ key: "setURL",
162
+ value: function setURL(url) {
163
+ var writable = this.getWritable();
164
+ writable.__url = url;
165
+ return writable;
166
+ }
167
+ }, {
168
+ key: "getTarget",
169
+ value: function getTarget() {
170
+ return this.getLatest().__target;
171
+ }
172
+ }, {
173
+ key: "setTarget",
174
+ value: function setTarget(target) {
175
+ var writable = this.getWritable();
176
+ writable.__target = target;
177
+ return writable;
178
+ }
179
+ }, {
180
+ key: "getRel",
181
+ value: function getRel() {
182
+ return this.getLatest().__rel;
183
+ }
184
+ }, {
185
+ key: "setRel",
186
+ value: function setRel(rel) {
187
+ var writable = this.getWritable();
188
+ writable.__rel = rel;
189
+ return writable;
190
+ }
191
+ }, {
192
+ key: "getTitle",
193
+ value: function getTitle() {
194
+ return this.getLatest().__title;
195
+ }
196
+ }, {
197
+ key: "setTitle",
198
+ value: function setTitle(title) {
199
+ var writable = this.getWritable();
200
+ writable.__title = title;
201
+ return writable;
202
+ }
203
+ }, {
204
+ key: "insertNewAfter",
205
+ value: function insertNewAfter(_) {
206
+ var restoreSelection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
207
+ var linkNode = $createLinkNode(this.__url, {
208
+ rel: this.__rel,
209
+ target: this.__target,
210
+ title: this.__title
211
+ });
212
+ this.insertAfter(linkNode, restoreSelection);
213
+ return linkNode;
214
+ }
215
+ }, {
216
+ key: "canInsertTextBefore",
217
+ value: function canInsertTextBefore() {
218
+ return false;
219
+ }
220
+ }, {
221
+ key: "canInsertTextAfter",
222
+ value: function canInsertTextAfter() {
223
+ return false;
224
+ }
225
+ }, {
226
+ key: "canBeEmpty",
227
+ value: function canBeEmpty() {
228
+ return false;
229
+ }
230
+ }, {
231
+ key: "isInline",
232
+ value: function isInline() {
233
+ return true;
234
+ }
235
+ }, {
236
+ key: "extractWithChild",
237
+ value: function extractWithChild(child, selection) {
238
+ if (!$isRangeSelection(selection)) {
239
+ return false;
240
+ }
241
+ var anchorNode = selection.anchor.getNode();
242
+ var focusNode = selection.focus.getNode();
243
+ return this.isParentOf(anchorNode) && this.isParentOf(focusNode) && selection.getTextContent().length > 0;
244
+ }
245
+ }, {
246
+ key: "isEmailURI",
247
+ value: function isEmailURI() {
248
+ return this.__url.startsWith('mailto:');
249
+ }
250
+ }, {
251
+ key: "isWebSiteURI",
252
+ value: function isWebSiteURI() {
253
+ return this.__url.startsWith('https://') || this.__url.startsWith('http://');
254
+ }
255
+ }], [{
256
+ key: "getType",
257
+ value: function getType() {
258
+ return 'link';
259
+ }
260
+ }, {
261
+ key: "clone",
262
+ value: function clone(node) {
263
+ return new LinkNode(node.__url, {
264
+ rel: node.__rel,
265
+ target: node.__target,
266
+ title: node.__title
267
+ }, node.__key);
268
+ }
269
+ }, {
270
+ key: "importDOM",
271
+ value: function importDOM() {
272
+ return {
273
+ a: function a() {
274
+ return {
275
+ conversion: $convertAnchorElement,
276
+ priority: 1
277
+ };
278
+ }
279
+ };
280
+ }
281
+ }, {
282
+ key: "importJSON",
283
+ value: function importJSON(serializedNode) {
284
+ return $createLinkNode().updateFromJSON(serializedNode);
285
+ }
286
+ }]);
287
+ return LinkNode;
288
+ }(ElementNode);
289
+ function $convertAnchorElement(domNode) {
290
+ var node = null;
291
+ if (isHTMLAnchorElement(domNode)) {
292
+ var content = domNode.textContent;
293
+ if (content !== null && content !== '' || domNode.children.length > 0) {
294
+ node = $createLinkNode(domNode.getAttribute('href') || '', {
295
+ rel: domNode.getAttribute('rel'),
296
+ target: domNode.getAttribute('target'),
297
+ title: domNode.getAttribute('title')
298
+ });
299
+ }
300
+ }
301
+ return {
302
+ node: node
303
+ };
304
+ }
305
+
306
+ /**
307
+ * Takes a URL and creates a LinkNode.
308
+ * @param url - The URL the LinkNode should direct to.
309
+ * @param attributes - Optional HTML a tag attributes \\{ target, rel, title \\}
310
+ * @returns The LinkNode.
311
+ */
312
+ export function $createLinkNode() {
313
+ var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
314
+ var attributes = arguments.length > 1 ? arguments[1] : undefined;
315
+ return $applyNodeReplacement(new LinkNode(url, attributes));
316
+ }
317
+
318
+ /**
319
+ * Determines if node is a LinkNode.
320
+ * @param node - The node to be checked.
321
+ * @returns true if node is a LinkNode, false otherwise.
322
+ */
323
+ export function $isLinkNode(node) {
324
+ return node instanceof LinkNode;
325
+ }
326
+ // Custom node type to override `canInsertTextAfter` that will
327
+ // allow typing within the link
328
+ export var AutoLinkNode = /*#__PURE__*/function (_LinkNode) {
329
+ _inherits(AutoLinkNode, _LinkNode);
330
+ var _super2 = _createSuper(AutoLinkNode);
331
+ function AutoLinkNode() {
332
+ var _this3;
333
+ var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
334
+ var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
335
+ var key = arguments.length > 2 ? arguments[2] : undefined;
336
+ _classCallCheck(this, AutoLinkNode);
337
+ _this3 = _super2.call(this, url, attributes, key);
338
+ /** @internal */
339
+ /** Indicates whether the autolink was ever unlinked. **/
340
+ _defineProperty(_assertThisInitialized(_this3), "__isUnlinked", void 0);
341
+ _this3.__isUnlinked = attributes.isUnlinked !== undefined && attributes.isUnlinked !== null ? attributes.isUnlinked : false;
342
+ return _this3;
343
+ }
344
+ _createClass(AutoLinkNode, [{
345
+ key: "getIsUnlinked",
346
+ value: function getIsUnlinked() {
347
+ return this.__isUnlinked;
348
+ }
349
+ }, {
350
+ key: "setIsUnlinked",
351
+ value: function setIsUnlinked(value) {
352
+ var self = this.getWritable();
353
+ self.__isUnlinked = value;
354
+ return self;
355
+ }
356
+ }, {
357
+ key: "createDOM",
358
+ value: function createDOM(config, editor) {
359
+ if (this.__isUnlinked) {
360
+ return document.createElement('span');
361
+ } else {
362
+ return _get(_getPrototypeOf(AutoLinkNode.prototype), "createDOM", this).call(this, config, editor);
363
+ }
364
+ }
365
+ }, {
366
+ key: "updateDOM",
367
+ value: function updateDOM(prevNode, anchor, config) {
368
+ return _get(_getPrototypeOf(AutoLinkNode.prototype), "updateDOM", this).call(this, prevNode, anchor, config) || prevNode.__isUnlinked !== this.__isUnlinked;
369
+ }
370
+ }, {
371
+ key: "updateFromJSON",
372
+ value: function updateFromJSON(serializedNode) {
373
+ return _get(_getPrototypeOf(AutoLinkNode.prototype), "updateFromJSON", this).call(this, serializedNode).setIsUnlinked(serializedNode.isUnlinked || false);
374
+ }
375
+ }, {
376
+ key: "exportJSON",
377
+ value: function exportJSON() {
378
+ return _objectSpread(_objectSpread({}, _get(_getPrototypeOf(AutoLinkNode.prototype), "exportJSON", this).call(this)), {}, {
379
+ isUnlinked: this.__isUnlinked
380
+ });
381
+ }
382
+ }, {
383
+ key: "insertNewAfter",
384
+ value: function insertNewAfter(selection) {
385
+ var restoreSelection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
386
+ var element = this.getParentOrThrow().insertNewAfter(selection, restoreSelection);
387
+ if ($isElementNode(element)) {
388
+ var linkNode = $createAutoLinkNode(this.__url, {
389
+ isUnlinked: this.__isUnlinked,
390
+ rel: this.__rel,
391
+ target: this.__target,
392
+ title: this.__title
393
+ });
394
+ element.append(linkNode);
395
+ return linkNode;
396
+ }
397
+ return null;
398
+ }
399
+ }], [{
400
+ key: "getType",
401
+ value: function getType() {
402
+ return 'autolink';
403
+ }
404
+ }, {
405
+ key: "clone",
406
+ value: function clone(node) {
407
+ return new AutoLinkNode(node.__url, {
408
+ isUnlinked: node.__isUnlinked,
409
+ rel: node.__rel,
410
+ target: node.__target,
411
+ title: node.__title
412
+ }, node.__key);
413
+ }
414
+ }, {
415
+ key: "importJSON",
416
+ value: function importJSON(serializedNode) {
417
+ return $createAutoLinkNode().updateFromJSON(serializedNode);
418
+ }
419
+ }, {
420
+ key: "importDOM",
421
+ value: function importDOM() {
422
+ // TODO: Should link node should handle the import over autolink?
423
+ return null;
424
+ }
425
+ }]);
426
+ return AutoLinkNode;
427
+ }(LinkNode);
428
+
429
+ /**
430
+ * Takes a URL and creates an AutoLinkNode. AutoLinkNodes are generally automatically generated
431
+ * during typing, which is especially useful when a button to generate a LinkNode is not practical.
432
+ * @param url - The URL the LinkNode should direct to.
433
+ * @param attributes - Optional HTML a tag attributes. \\{ target, rel, title \\}
434
+ * @returns The LinkNode.
435
+ */
436
+ export function $createAutoLinkNode() {
437
+ var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
438
+ var attributes = arguments.length > 1 ? arguments[1] : undefined;
439
+ return $applyNodeReplacement(new AutoLinkNode(url, attributes));
440
+ }
441
+
442
+ /**
443
+ * Determines if node is an AutoLinkNode.
444
+ * @param node - The node to be checked.
445
+ * @returns true if node is an AutoLinkNode, false otherwise.
446
+ */
447
+ export function $isAutoLinkNode(node) {
448
+ return node instanceof AutoLinkNode;
449
+ }
450
+ export var TOGGLE_LINK_COMMAND = createCommand('TOGGLE_LINK_COMMAND');
451
+ function $getPointNode(point, offset) {
452
+ if (point.type === 'element') {
453
+ var node = point.getNode();
454
+ assert($isElementNode(node), '$getPointNode: element point is not an ElementNode');
455
+ var childNode = node.getChildren()[point.offset + offset];
456
+ return childNode || null;
457
+ }
458
+ return null;
459
+ }
460
+
461
+ /**
462
+ * Preserve the logical start/end of a RangeSelection in situations where
463
+ * the point is an element that may be reparented in the callback.
464
+ *
465
+ * @param $fn The function to run
466
+ * @returns The result of the callback
467
+ */
468
+ function $withSelectedNodes($fn) {
469
+ var initialSelection = $getSelection();
470
+ if (!$isRangeSelection(initialSelection)) {
471
+ return $fn();
472
+ }
473
+ var normalized = $normalizeSelection__EXPERIMENTAL(initialSelection);
474
+ var isBackwards = normalized.isBackward();
475
+ var anchorNode = $getPointNode(normalized.anchor, isBackwards ? -1 : 0);
476
+ var focusNode = $getPointNode(normalized.focus, isBackwards ? 0 : -1);
477
+ var rval = $fn();
478
+ if (anchorNode || focusNode) {
479
+ var updatedSelection = $getSelection();
480
+ if ($isRangeSelection(updatedSelection)) {
481
+ var finalSelection = updatedSelection.clone();
482
+ if (anchorNode) {
483
+ var anchorParent = anchorNode.getParent();
484
+ if (anchorParent) {
485
+ finalSelection.anchor.set(anchorParent.getKey(), anchorNode.getIndexWithinParent() + (isBackwards ? 1 : 0), 'element');
486
+ }
487
+ }
488
+ if (focusNode) {
489
+ var focusParent = focusNode.getParent();
490
+ if (focusParent) {
491
+ finalSelection.focus.set(focusParent.getKey(), focusNode.getIndexWithinParent() + (isBackwards ? 0 : 1), 'element');
492
+ }
493
+ }
494
+ $setSelection($normalizeSelection__EXPERIMENTAL(finalSelection));
495
+ }
496
+ }
497
+ return rval;
498
+ }
499
+
500
+ /**
501
+ * Generates or updates a LinkNode. It can also delete a LinkNode if the URL is null,
502
+ * but saves any children and brings them up to the parent node.
503
+ * @param url - The URL the link directs to.
504
+ * @param attributes - Optional HTML a tag attributes. \\{ target, rel, title \\}
505
+ */
506
+ export function $toggleLink(url) {
507
+ var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
508
+ var target = attributes.target,
509
+ title = attributes.title;
510
+ var rel = attributes.rel === undefined ? 'noreferrer' : attributes.rel;
511
+ var selection = $getSelection();
512
+ if (selection === null || !$isRangeSelection(selection) && !$isNodeSelection(selection)) {
513
+ return;
514
+ }
515
+ if ($isNodeSelection(selection)) {
516
+ var _nodes = selection.getNodes();
517
+ if (_nodes.length === 0) {
518
+ return;
519
+ }
520
+
521
+ // Handle all selected nodes
522
+ _nodes.forEach(function (node) {
523
+ if (url === null) {
524
+ // Remove link
525
+ var linkParent = $findMatchingParent(node, function (parent) {
526
+ return !$isAutoLinkNode(parent) && $isLinkNode(parent);
527
+ });
528
+ if (linkParent) {
529
+ linkParent.insertBefore(node);
530
+ if (linkParent.getChildren().length === 0) {
531
+ linkParent.remove();
532
+ }
533
+ }
534
+ } else {
535
+ // Add/Update link
536
+ var existingLink = $findMatchingParent(node, function (parent) {
537
+ return !$isAutoLinkNode(parent) && $isLinkNode(parent);
538
+ });
539
+ if (existingLink) {
540
+ existingLink.setURL(url);
541
+ if (target !== undefined) {
542
+ existingLink.setTarget(target);
543
+ }
544
+ if (rel !== undefined) {
545
+ existingLink.setRel(rel);
546
+ }
547
+ } else {
548
+ var linkNode = $createLinkNode(url, {
549
+ rel: rel,
550
+ target: target
551
+ });
552
+ node.insertBefore(linkNode);
553
+ linkNode.append(node);
554
+ }
555
+ }
556
+ });
557
+ return;
558
+ }
559
+
560
+ // Handle RangeSelection
561
+ var nodes = selection.extract();
562
+ if (url === null) {
563
+ // Remove LinkNodes
564
+ nodes.forEach(function (node) {
565
+ var parentLink = $findMatchingParent(node, function (parent) {
566
+ return !$isAutoLinkNode(parent) && $isLinkNode(parent);
567
+ });
568
+ if (parentLink) {
569
+ var children = parentLink.getChildren();
570
+ var _iterator2 = _createForOfIteratorHelper(children),
571
+ _step2;
572
+ try {
573
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
574
+ var child = _step2.value;
575
+ parentLink.insertBefore(child);
576
+ }
577
+ } catch (err) {
578
+ _iterator2.e(err);
579
+ } finally {
580
+ _iterator2.f();
581
+ }
582
+ parentLink.remove();
583
+ }
584
+ });
585
+ return;
586
+ }
587
+ var updatedNodes = new Set();
588
+ var updateLinkNode = function updateLinkNode(linkNode) {
589
+ if (updatedNodes.has(linkNode.getKey())) {
590
+ return;
591
+ }
592
+ updatedNodes.add(linkNode.getKey());
593
+ linkNode.setURL(url);
594
+ if (target !== undefined) {
595
+ linkNode.setTarget(target);
596
+ }
597
+ if (rel !== undefined) {
598
+ linkNode.setRel(rel);
599
+ }
600
+ if (title !== undefined) {
601
+ linkNode.setTitle(title);
602
+ }
603
+ };
604
+ // Add or merge LinkNodes
605
+ if (nodes.length === 1) {
606
+ var firstNode = nodes[0];
607
+ // if the first node is a LinkNode or if its
608
+ // parent is a LinkNode, we update the URL, target and rel.
609
+ var linkNode = $getAncestor(firstNode, $isLinkNode);
610
+ if (linkNode !== null) {
611
+ return updateLinkNode(linkNode);
612
+ }
613
+ }
614
+ $withSelectedNodes(function () {
615
+ var linkNode = null;
616
+ var _iterator3 = _createForOfIteratorHelper(nodes),
617
+ _step3;
618
+ try {
619
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
620
+ var node = _step3.value;
621
+ if (!node.isAttached()) {
622
+ continue;
623
+ }
624
+ var parentLinkNode = $getAncestor(node, $isLinkNode);
625
+ if (parentLinkNode) {
626
+ updateLinkNode(parentLinkNode);
627
+ continue;
628
+ }
629
+ if ($isElementNode(node)) {
630
+ if (!node.isInline()) {
631
+ // Ignore block nodes, if there are any children we will see them
632
+ // later and wrap in a new LinkNode
633
+ continue;
634
+ }
635
+ if ($isLinkNode(node)) {
636
+ // If it's not an autolink node and we don't already have a LinkNode
637
+ // in this block then we can update it and re-use it
638
+ if (!$isAutoLinkNode(node) && (linkNode === null || !linkNode.getParentOrThrow().isParentOf(node))) {
639
+ updateLinkNode(node);
640
+ linkNode = node;
641
+ continue;
642
+ }
643
+ // Unwrap LinkNode, we already have one or it's an AutoLinkNode
644
+ var _iterator4 = _createForOfIteratorHelper(node.getChildren()),
645
+ _step4;
646
+ try {
647
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
648
+ var child = _step4.value;
649
+ node.insertBefore(child);
650
+ }
651
+ } catch (err) {
652
+ _iterator4.e(err);
653
+ } finally {
654
+ _iterator4.f();
655
+ }
656
+ node.remove();
657
+ continue;
658
+ }
659
+ }
660
+ var prevLinkNode = node.getPreviousSibling();
661
+ if ($isLinkNode(prevLinkNode) && prevLinkNode.is(linkNode)) {
662
+ prevLinkNode.append(node);
663
+ continue;
664
+ }
665
+ linkNode = $createLinkNode(url, {
666
+ rel: rel,
667
+ target: target,
668
+ title: title
669
+ });
670
+ node.insertAfter(linkNode);
671
+ linkNode.append(node);
672
+ }
673
+ } catch (err) {
674
+ _iterator3.e(err);
675
+ } finally {
676
+ _iterator3.f();
677
+ }
678
+ });
679
+ }
680
+ /** @deprecated renamed to {@link $toggleLink} by @lexical/eslint-plugin rules-of-lexical */
681
+ export var toggleLink = $toggleLink;
682
+ function $getAncestor(node, predicate) {
683
+ var parent = node;
684
+ while (parent !== null && parent.getParent() !== null && !predicate(parent)) {
685
+ parent = parent.getParentOrThrow();
686
+ }
687
+ return predicate(parent) ? parent : null;
688
+ }
689
+ var PHONE_NUMBER_REGEX = /^\+?[\d\s()-]{5,}$/;
690
+
691
+ /**
692
+ * Formats a URL string by adding appropriate protocol if missing
693
+ *
694
+ * @param url - URL to format
695
+ * @returns Formatted URL with appropriate protocol
696
+ */
697
+ export function formatUrl(url) {
698
+ // Check if URL already has a protocol
699
+ if (/^[a-z][\d+.a-z-]*:/i.test(url)) {
700
+ // URL already has a protocol, leave it as is
701
+ return url;
702
+ }
703
+ // Check if it's a relative path (starting with '/', '.', or '#')
704
+ else if (/^[#./]/.test(url)) {
705
+ // Relative path, leave it as is
706
+ return url;
707
+ }
708
+
709
+ // Check for email address
710
+ else if (url.includes('@')) {
711
+ return "mailto:".concat(url);
712
+ }
713
+
714
+ // Check for phone number
715
+ else if (PHONE_NUMBER_REGEX.test(url)) {
716
+ return "tel:".concat(url);
717
+ }
718
+
719
+ // For everything else, return with https:// prefix
720
+ return "https://".concat(url);
721
+ }