@blocklet/editor-lite 2.6.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 (550) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +33 -0
  3. package/lib/blocklet-editor-viewer.d.ts +4 -0
  4. package/lib/blocklet-editor-viewer.js +12 -0
  5. package/lib/blocklet-editor.d.ts +2 -0
  6. package/lib/blocklet-editor.js +12 -0
  7. package/lib/components/Loading.d.ts +4 -0
  8. package/lib/components/Loading.js +13 -0
  9. package/lib/components/SelectionPopper.d.ts +14 -0
  10. package/lib/components/SelectionPopper.js +73 -0
  11. package/lib/components/animateText.d.ts +3 -0
  12. package/lib/components/animateText.js +29 -0
  13. package/lib/components/createPortal.d.ts +2 -0
  14. package/lib/components/createPortal.js +16 -0
  15. package/lib/config.d.ts +37 -0
  16. package/lib/config.js +12 -0
  17. package/lib/ext/AIPlugin/AIIcon.d.ts +5 -0
  18. package/lib/ext/AIPlugin/AIIcon.js +7 -0
  19. package/lib/ext/AIPlugin/Arrow.d.ts +1 -0
  20. package/lib/ext/AIPlugin/Arrow.js +5 -0
  21. package/lib/ext/AIPlugin/TextGeneration.d.ts +6 -0
  22. package/lib/ext/AIPlugin/TextGeneration.js +131 -0
  23. package/lib/ext/AIPlugin/Writing.d.ts +1 -0
  24. package/lib/ext/AIPlugin/Writing.js +7 -0
  25. package/lib/ext/AIPlugin/index.d.ts +9 -0
  26. package/lib/ext/AIPlugin/index.js +180 -0
  27. package/lib/ext/AIPlugin/utils.d.ts +6 -0
  28. package/lib/ext/AIPlugin/utils.js +44 -0
  29. package/lib/ext/AITranslationPlugin/index.d.ts +9 -0
  30. package/lib/ext/AITranslationPlugin/index.js +124 -0
  31. package/lib/ext/AITranslationPlugin/selection.d.ts +3 -0
  32. package/lib/ext/AITranslationPlugin/selection.js +45 -0
  33. package/lib/ext/AITranslationPlugin/translation.d.ts +3 -0
  34. package/lib/ext/AITranslationPlugin/translation.js +67 -0
  35. package/lib/ext/AITranslationPlugin/types.d.ts +49 -0
  36. package/lib/ext/AITranslationPlugin/types.js +1 -0
  37. package/lib/ext/AITranslationPlugin/utils.d.ts +46 -0
  38. package/lib/ext/AITranslationPlugin/utils.js +343 -0
  39. package/lib/ext/Aide/Aide.d.ts +4 -0
  40. package/lib/ext/Aide/Aide.js +30 -0
  41. package/lib/ext/Aide/Delayed.d.ts +7 -0
  42. package/lib/ext/Aide/Delayed.js +12 -0
  43. package/lib/ext/Aide/Input.d.ts +6 -0
  44. package/lib/ext/Aide/Input.js +49 -0
  45. package/lib/ext/Aide/Menu.d.ts +4 -0
  46. package/lib/ext/Aide/Menu.js +29 -0
  47. package/lib/ext/Aide/Output.d.ts +4 -0
  48. package/lib/ext/Aide/Output.js +14 -0
  49. package/lib/ext/Aide/Templates.d.ts +4 -0
  50. package/lib/ext/Aide/Templates.js +34 -0
  51. package/lib/ext/Aide/builtin-templates.d.ts +3 -0
  52. package/lib/ext/Aide/builtin-templates.js +48 -0
  53. package/lib/ext/Aide/context.d.ts +47 -0
  54. package/lib/ext/Aide/context.js +114 -0
  55. package/lib/ext/Aide/external-templates/Breadcrumb.d.ts +10 -0
  56. package/lib/ext/Aide/external-templates/Breadcrumb.js +11 -0
  57. package/lib/ext/Aide/external-templates/Output.d.ts +8 -0
  58. package/lib/ext/Aide/external-templates/Output.js +22 -0
  59. package/lib/ext/Aide/external-templates/Search.d.ts +6 -0
  60. package/lib/ext/Aide/external-templates/Search.js +14 -0
  61. package/lib/ext/Aide/external-templates/Tags.d.ts +4 -0
  62. package/lib/ext/Aide/external-templates/Tags.js +44 -0
  63. package/lib/ext/Aide/external-templates/Template.d.ts +7 -0
  64. package/lib/ext/Aide/external-templates/Template.js +110 -0
  65. package/lib/ext/Aide/external-templates/Templates.d.ts +6 -0
  66. package/lib/ext/Aide/external-templates/Templates.js +61 -0
  67. package/lib/ext/Aide/external-templates/index.d.ts +4 -0
  68. package/lib/ext/Aide/external-templates/index.js +83 -0
  69. package/lib/ext/Aide/external-templates/parameter-field.d.ts +6 -0
  70. package/lib/ext/Aide/external-templates/parameter-field.js +92 -0
  71. package/lib/ext/Aide/hooks.d.ts +7 -0
  72. package/lib/ext/Aide/hooks.js +14 -0
  73. package/lib/ext/Aide/index.d.ts +2 -0
  74. package/lib/ext/Aide/index.js +2 -0
  75. package/lib/ext/Aide/types.d.ts +84 -0
  76. package/lib/ext/Aide/types.js +25 -0
  77. package/lib/ext/Aide/withAiAvailable.d.ts +5 -0
  78. package/lib/ext/Aide/withAiAvailable.js +11 -0
  79. package/lib/ext/Alert/AlertComponent.d.ts +10 -0
  80. package/lib/ext/Alert/AlertComponent.js +38 -0
  81. package/lib/ext/Alert/AlertNode.d.ts +28 -0
  82. package/lib/ext/Alert/AlertNode.js +105 -0
  83. package/lib/ext/Alert/AlertPlugin.d.ts +11 -0
  84. package/lib/ext/Alert/AlertPlugin.js +41 -0
  85. package/lib/ext/BilibiliPlugin/BilibiliNode.d.ts +31 -0
  86. package/lib/ext/BilibiliPlugin/BilibiliNode.js +95 -0
  87. package/lib/ext/BilibiliPlugin/BilibiliVideo.d.ts +6 -0
  88. package/lib/ext/BilibiliPlugin/BilibiliVideo.js +24 -0
  89. package/lib/ext/BilibiliPlugin/config.d.ts +2 -0
  90. package/lib/ext/BilibiliPlugin/config.js +40 -0
  91. package/lib/ext/BilibiliPlugin/index.d.ts +5 -0
  92. package/lib/ext/BilibiliPlugin/index.js +20 -0
  93. package/lib/ext/BlockletEmbedPlugin/BlockletEmbed.d.ts +7 -0
  94. package/lib/ext/BlockletEmbedPlugin/BlockletEmbed.js +51 -0
  95. package/lib/ext/BlockletEmbedPlugin/BlockletEmbedNode.d.ts +30 -0
  96. package/lib/ext/BlockletEmbedPlugin/BlockletEmbedNode.js +96 -0
  97. package/lib/ext/BlockletEmbedPlugin/index.d.ts +12 -0
  98. package/lib/ext/BlockletEmbedPlugin/index.js +76 -0
  99. package/lib/ext/BlurTextPlugin.d.ts +1 -0
  100. package/lib/ext/BlurTextPlugin.js +40 -0
  101. package/lib/ext/BookmarkPlugin/Bookmark.d.ts +7 -0
  102. package/lib/ext/BookmarkPlugin/Bookmark.js +175 -0
  103. package/lib/ext/BookmarkPlugin/BookmarkNode.d.ts +35 -0
  104. package/lib/ext/BookmarkPlugin/BookmarkNode.js +110 -0
  105. package/lib/ext/BookmarkPlugin/index.d.ts +11 -0
  106. package/lib/ext/BookmarkPlugin/index.js +45 -0
  107. package/lib/ext/BusyPlugin.d.ts +9 -0
  108. package/lib/ext/BusyPlugin.js +17 -0
  109. package/lib/ext/CharacterCountPlugin/index.d.ts +10 -0
  110. package/lib/ext/CharacterCountPlugin/index.js +39 -0
  111. package/lib/ext/CharacterCountPlugin/useCharacterCount.d.ts +11 -0
  112. package/lib/ext/CharacterCountPlugin/useCharacterCount.js +49 -0
  113. package/lib/ext/CharacterLimitPlugin/index.d.ts +9 -0
  114. package/lib/ext/CharacterLimitPlugin/index.js +49 -0
  115. package/lib/ext/CheckboxPlugin.d.ts +3 -0
  116. package/lib/ext/CheckboxPlugin.js +75 -0
  117. package/lib/ext/CodeCopyPlugin/CodeCopyPlugin.d.ts +2 -0
  118. package/lib/ext/CodeCopyPlugin/CodeCopyPlugin.js +90 -0
  119. package/lib/ext/CodeCopyPlugin/copy.svg +1 -0
  120. package/lib/ext/CodeCopyPlugin/index.d.ts +1 -0
  121. package/lib/ext/CodeCopyPlugin/index.js +1 -0
  122. package/lib/ext/CodeCopyPlugin/style.css +12 -0
  123. package/lib/ext/ContentLocale.d.ts +7 -0
  124. package/lib/ext/ContentLocale.js +15 -0
  125. package/lib/ext/CustomOnChangePlugin/index.d.ts +5 -0
  126. package/lib/ext/CustomOnChangePlugin/index.js +17 -0
  127. package/lib/ext/CustomOnChangePlugin/styles.css +14 -0
  128. package/lib/ext/CustomOnChangePlugin/utils.d.ts +30 -0
  129. package/lib/ext/CustomOnChangePlugin/utils.js +148 -0
  130. package/lib/ext/EditorHolderPlugin/EditorHolderContext.d.ts +13 -0
  131. package/lib/ext/EditorHolderPlugin/EditorHolderContext.js +15 -0
  132. package/lib/ext/EditorHolderPlugin/EditorHolderPlugin.d.ts +1 -0
  133. package/lib/ext/EditorHolderPlugin/EditorHolderPlugin.js +11 -0
  134. package/lib/ext/EditorHolderPlugin/index.d.ts +2 -0
  135. package/lib/ext/EditorHolderPlugin/index.js +2 -0
  136. package/lib/ext/EditorReadyPlugin.d.ts +3 -0
  137. package/lib/ext/EditorReadyPlugin.js +15 -0
  138. package/lib/ext/FilePlugin/FileNode.d.ts +44 -0
  139. package/lib/ext/FilePlugin/FileNode.js +195 -0
  140. package/lib/ext/FilePlugin/FilePlugin.d.ts +7 -0
  141. package/lib/ext/FilePlugin/FilePlugin.js +27 -0
  142. package/lib/ext/FilePlugin/index.d.ts +2 -0
  143. package/lib/ext/FilePlugin/index.js +2 -0
  144. package/lib/ext/HeadingsIdPlugin.d.ts +1 -0
  145. package/lib/ext/HeadingsIdPlugin.js +67 -0
  146. package/lib/ext/ImagePathFixerPlugin.d.ts +1 -0
  147. package/lib/ext/ImagePathFixerPlugin.js +31 -0
  148. package/lib/ext/InlineTranslationPlugin/EditorTranslator.d.ts +42 -0
  149. package/lib/ext/InlineTranslationPlugin/EditorTranslator.js +199 -0
  150. package/lib/ext/InlineTranslationPlugin/InlineTranslationPlugin.d.ts +12 -0
  151. package/lib/ext/InlineTranslationPlugin/InlineTranslationPlugin.js +232 -0
  152. package/lib/ext/InlineTranslationPlugin/TranslationNode.d.ts +23 -0
  153. package/lib/ext/InlineTranslationPlugin/TranslationNode.js +49 -0
  154. package/lib/ext/InlineTranslationPlugin/index.d.ts +4 -0
  155. package/lib/ext/InlineTranslationPlugin/index.js +4 -0
  156. package/lib/ext/InlineTranslationPlugin/store.d.ts +50 -0
  157. package/lib/ext/InlineTranslationPlugin/store.js +94 -0
  158. package/lib/ext/InlineTranslationPlugin/types.d.ts +1 -0
  159. package/lib/ext/InlineTranslationPlugin/types.js +1 -0
  160. package/lib/ext/LexicalEditorRefPlugin.d.ts +14 -0
  161. package/lib/ext/LexicalEditorRefPlugin.js +26 -0
  162. package/lib/ext/OnContentChangePlugin.d.ts +14 -0
  163. package/lib/ext/OnContentChangePlugin.js +35 -0
  164. package/lib/ext/PasteSlackImagePlugin/index.d.ts +2 -0
  165. package/lib/ext/PasteSlackImagePlugin/index.js +22 -0
  166. package/lib/ext/PostLinkEmbedPlugin/PostLinkNode.d.ts +32 -0
  167. package/lib/ext/PostLinkEmbedPlugin/PostLinkNode.js +140 -0
  168. package/lib/ext/PostLinkEmbedPlugin/fixInvalidPostLinkNodes.d.ts +1 -0
  169. package/lib/ext/PostLinkEmbedPlugin/fixInvalidPostLinkNodes.js +15 -0
  170. package/lib/ext/PostLinkEmbedPlugin/index.d.ts +21 -0
  171. package/lib/ext/PostLinkEmbedPlugin/index.js +148 -0
  172. package/lib/ext/RemoveListPlugin.d.ts +1 -0
  173. package/lib/ext/RemoveListPlugin.js +63 -0
  174. package/lib/ext/SafeAreaPlugin.d.ts +12 -0
  175. package/lib/ext/SafeAreaPlugin.js +56 -0
  176. package/lib/ext/SelectBlockPlugin.d.ts +1 -0
  177. package/lib/ext/SelectBlockPlugin.js +95 -0
  178. package/lib/ext/ShortcutPlugin/CtrlsShortcutPlugin.d.ts +6 -0
  179. package/lib/ext/ShortcutPlugin/CtrlsShortcutPlugin.js +17 -0
  180. package/lib/ext/ShortcutPlugin/index.d.ts +1 -0
  181. package/lib/ext/ShortcutPlugin/index.js +1 -0
  182. package/lib/ext/TemplatePlugin.d.ts +8 -0
  183. package/lib/ext/TemplatePlugin.js +170 -0
  184. package/lib/ext/VideoPathFixerPlugin.d.ts +1 -0
  185. package/lib/ext/VideoPathFixerPlugin.js +31 -0
  186. package/lib/ext/VideoPlugin/VideoComponent.d.ts +5 -0
  187. package/lib/ext/VideoPlugin/VideoComponent.js +5 -0
  188. package/lib/ext/VideoPlugin/VideoNode.d.ts +37 -0
  189. package/lib/ext/VideoPlugin/VideoNode.js +97 -0
  190. package/lib/ext/VideoPlugin/VideoPlugin.d.ts +7 -0
  191. package/lib/ext/VideoPlugin/VideoPlugin.js +26 -0
  192. package/lib/ext/VideoPlugin/index.d.ts +2 -0
  193. package/lib/ext/VideoPlugin/index.js +2 -0
  194. package/lib/ext/common.d.ts +15 -0
  195. package/lib/ext/common.js +62 -0
  196. package/lib/ext/nodes/GithubComp.d.ts +3 -0
  197. package/lib/ext/nodes/GithubComp.js +20 -0
  198. package/lib/ext/nodes/GithubNode.d.ts +28 -0
  199. package/lib/ext/nodes/GithubNode.js +94 -0
  200. package/lib/ext/nodes/util.d.ts +5 -0
  201. package/lib/ext/nodes/util.js +1 -0
  202. package/lib/ext/translation/translation-utils.d.ts +16 -0
  203. package/lib/ext/translation/translation-utils.js +63 -0
  204. package/lib/ext/utils.d.ts +21 -0
  205. package/lib/ext/utils.js +88 -0
  206. package/lib/global.d.ts +1 -0
  207. package/lib/index.d.ts +4 -0
  208. package/lib/index.js +5 -0
  209. package/lib/lexical-utils/index.d.ts +46 -0
  210. package/lib/lexical-utils/index.js +243 -0
  211. package/lib/libs/sort-array-by-key.d.ts +4 -0
  212. package/lib/libs/sort-array-by-key.js +68 -0
  213. package/lib/libs/utm.d.ts +9 -0
  214. package/lib/libs/utm.js +43 -0
  215. package/lib/main/appSettings.d.ts +11 -0
  216. package/lib/main/appSettings.js +20 -0
  217. package/lib/main/context/SharedAutocompleteContext.d.ts +16 -0
  218. package/lib/main/context/SharedAutocompleteContext.js +35 -0
  219. package/lib/main/context/SharedHistoryContext.d.ts +17 -0
  220. package/lib/main/context/SharedHistoryContext.js +11 -0
  221. package/lib/main/editor-root.d.ts +2 -0
  222. package/lib/main/editor-root.js +46 -0
  223. package/lib/main/editor.d.ts +21 -0
  224. package/lib/main/editor.js +99 -0
  225. package/lib/main/hooks/hooks.d.ts +15 -0
  226. package/lib/main/hooks/hooks.js +49 -0
  227. package/lib/main/hooks/medium-zoom.d.ts +9 -0
  228. package/lib/main/hooks/medium-zoom.js +34 -0
  229. package/lib/main/hooks/use-mobile.d.ts +4 -0
  230. package/lib/main/hooks/use-mobile.js +6 -0
  231. package/lib/main/hooks/useBeforeUnload.d.ts +1 -0
  232. package/lib/main/hooks/useBeforeUnload.js +15 -0
  233. package/lib/main/hooks/useHasNodes.d.ts +1 -0
  234. package/lib/main/hooks/useHasNodes.js +8 -0
  235. package/lib/main/hooks/useIsFocused.d.ts +1 -0
  236. package/lib/main/hooks/useIsFocused.js +20 -0
  237. package/lib/main/hooks/useModal.d.ts +12 -0
  238. package/lib/main/hooks/useModal.js +33 -0
  239. package/lib/main/hooks/useReport.d.ts +8 -0
  240. package/lib/main/hooks/useReport.js +48 -0
  241. package/lib/main/hooks/useResponsiveTable.d.ts +5 -0
  242. package/lib/main/hooks/useResponsiveTable.js +31 -0
  243. package/lib/main/hooks/useTranslationListener.d.ts +4 -0
  244. package/lib/main/hooks/useTranslationListener.js +94 -0
  245. package/lib/main/icons.d.ts +3 -0
  246. package/lib/main/icons.js +25 -0
  247. package/lib/main/images/emoji/1F600.png +0 -0
  248. package/lib/main/images/emoji/1F641.png +0 -0
  249. package/lib/main/images/emoji/1F642.png +0 -0
  250. package/lib/main/images/emoji/2764.png +0 -0
  251. package/lib/main/images/excalidraw.svg +3 -0
  252. package/lib/main/images/icons/arrow-clockwise.svg +1 -0
  253. package/lib/main/images/icons/arrow-counterclockwise.svg +1 -0
  254. package/lib/main/images/icons/bg-color.svg +1 -0
  255. package/lib/main/images/icons/camera.svg +1 -0
  256. package/lib/main/images/icons/caret-right-fill.svg +1 -0
  257. package/lib/main/images/icons/chat-left-text.svg +1 -0
  258. package/lib/main/images/icons/chat-right-dots.svg +1 -0
  259. package/lib/main/images/icons/chat-right-text.svg +1 -0
  260. package/lib/main/images/icons/chat-right.svg +1 -0
  261. package/lib/main/images/icons/chat-square-quote.svg +1 -0
  262. package/lib/main/images/icons/chevron-down.svg +1 -0
  263. package/lib/main/images/icons/clipboard.svg +1 -0
  264. package/lib/main/images/icons/close.svg +1 -0
  265. package/lib/main/images/icons/code.svg +1 -0
  266. package/lib/main/images/icons/comments.svg +1 -0
  267. package/lib/main/images/icons/copy.svg +1 -0
  268. package/lib/main/images/icons/diagram-2.svg +1 -0
  269. package/lib/main/images/icons/download.svg +1 -0
  270. package/lib/main/images/icons/draggable-block-menu.svg +1 -0
  271. package/lib/main/images/icons/dropdown-more.svg +1 -0
  272. package/lib/main/images/icons/figma.svg +1 -0
  273. package/lib/main/images/icons/file-image.svg +1 -0
  274. package/lib/main/images/icons/filetype-gif.svg +1 -0
  275. package/lib/main/images/icons/font-color.svg +1 -0
  276. package/lib/main/images/icons/font-family.svg +1 -0
  277. package/lib/main/images/icons/gear.svg +1 -0
  278. package/lib/main/images/icons/horizontal-rule.svg +1 -0
  279. package/lib/main/images/icons/indent.svg +1 -0
  280. package/lib/main/images/icons/journal-code.svg +1 -0
  281. package/lib/main/images/icons/journal-text.svg +1 -0
  282. package/lib/main/images/icons/justify.svg +1 -0
  283. package/lib/main/images/icons/link.svg +1 -0
  284. package/lib/main/images/icons/list-ol.svg +1 -0
  285. package/lib/main/images/icons/list-ul.svg +1 -0
  286. package/lib/main/images/icons/lock-fill.svg +1 -0
  287. package/lib/main/images/icons/lock.svg +1 -0
  288. package/lib/main/images/icons/markdown.svg +1 -0
  289. package/lib/main/images/icons/mic.svg +1 -0
  290. package/lib/main/images/icons/outdent.svg +1 -0
  291. package/lib/main/images/icons/paint-bucket.svg +1 -0
  292. package/lib/main/images/icons/palette.svg +1 -0
  293. package/lib/main/images/icons/pencil-fill.svg +1 -0
  294. package/lib/main/images/icons/plug-fill.svg +1 -0
  295. package/lib/main/images/icons/plug.svg +1 -0
  296. package/lib/main/images/icons/plus-slash-minus.svg +1 -0
  297. package/lib/main/images/icons/plus.svg +1 -0
  298. package/lib/main/images/icons/prettier-error.svg +1 -0
  299. package/lib/main/images/icons/prettier.svg +1 -0
  300. package/lib/main/images/icons/send.svg +1 -0
  301. package/lib/main/images/icons/square-check.svg +1 -0
  302. package/lib/main/images/icons/sticky.svg +1 -0
  303. package/lib/main/images/icons/success.svg +1 -0
  304. package/lib/main/images/icons/table.svg +1 -0
  305. package/lib/main/images/icons/text-center.svg +1 -0
  306. package/lib/main/images/icons/text-left.svg +1 -0
  307. package/lib/main/images/icons/text-paragraph.svg +1 -0
  308. package/lib/main/images/icons/text-right.svg +1 -0
  309. package/lib/main/images/icons/trash.svg +1 -0
  310. package/lib/main/images/icons/trash3.svg +1 -0
  311. package/lib/main/images/icons/tweet.svg +1 -0
  312. package/lib/main/images/icons/type-bold.svg +1 -0
  313. package/lib/main/images/icons/type-h1.svg +1 -0
  314. package/lib/main/images/icons/type-h2.svg +1 -0
  315. package/lib/main/images/icons/type-h3.svg +1 -0
  316. package/lib/main/images/icons/type-h4.svg +1 -0
  317. package/lib/main/images/icons/type-h5.svg +1 -0
  318. package/lib/main/images/icons/type-h6.svg +1 -0
  319. package/lib/main/images/icons/type-italic.svg +1 -0
  320. package/lib/main/images/icons/type-strikethrough.svg +1 -0
  321. package/lib/main/images/icons/type-subscript.svg +1 -0
  322. package/lib/main/images/icons/type-superscript.svg +1 -0
  323. package/lib/main/images/icons/type-underline.svg +1 -0
  324. package/lib/main/images/icons/upload.svg +1 -0
  325. package/lib/main/images/icons/user.svg +1 -0
  326. package/lib/main/images/icons/youtube.svg +1 -0
  327. package/lib/main/images/landscape.jpg +0 -0
  328. package/lib/main/index.css +257 -0
  329. package/lib/main/index.d.ts +28 -0
  330. package/lib/main/index.js +52 -0
  331. package/lib/main/nodes/EmojiNode.d.ts +25 -0
  332. package/lib/main/nodes/EmojiNode.js +57 -0
  333. package/lib/main/nodes/EquationNode.d.ts +31 -0
  334. package/lib/main/nodes/EquationNode.js +65 -0
  335. package/lib/main/nodes/ExcalidrawNode/ExcalidrawComponent.d.ts +13 -0
  336. package/lib/main/nodes/ExcalidrawNode/ExcalidrawComponent.js +155 -0
  337. package/lib/main/nodes/ExcalidrawNode/ExcalidrawImage.d.ts +58 -0
  338. package/lib/main/nodes/ExcalidrawNode/ExcalidrawImage.js +60 -0
  339. package/lib/main/nodes/ExcalidrawNode/ExcalidrawModal.css +75 -0
  340. package/lib/main/nodes/ExcalidrawNode/ExcalidrawModal.d.ts +49 -0
  341. package/lib/main/nodes/ExcalidrawNode/ExcalidrawModal.js +197 -0
  342. package/lib/main/nodes/ExcalidrawNode/index.d.ts +30 -0
  343. package/lib/main/nodes/ExcalidrawNode/index.js +95 -0
  344. package/lib/main/nodes/ExcalidrawNode/utils.d.ts +5 -0
  345. package/lib/main/nodes/ExcalidrawNode/utils.js +71 -0
  346. package/lib/main/nodes/FigmaNode.d.ts +30 -0
  347. package/lib/main/nodes/FigmaNode.js +59 -0
  348. package/lib/main/nodes/ImageComponent.d.ts +27 -0
  349. package/lib/main/nodes/ImageComponent.js +432 -0
  350. package/lib/main/nodes/ImageNode.css +51 -0
  351. package/lib/main/nodes/ImageNode.d.ts +74 -0
  352. package/lib/main/nodes/ImageNode.js +151 -0
  353. package/lib/main/nodes/KeywordNode.d.ts +25 -0
  354. package/lib/main/nodes/KeywordNode.js +52 -0
  355. package/lib/main/nodes/MentionNode.d.ts +27 -0
  356. package/lib/main/nodes/MentionNode.js +88 -0
  357. package/lib/main/nodes/PlaygroundNodes.d.ts +10 -0
  358. package/lib/main/nodes/PlaygroundNodes.js +70 -0
  359. package/lib/main/nodes/TweetNode.d.ts +31 -0
  360. package/lib/main/nodes/TweetNode.js +126 -0
  361. package/lib/main/nodes/YouTubeNode.d.ts +32 -0
  362. package/lib/main/nodes/YouTubeNode.js +94 -0
  363. package/lib/main/plugins/AutoEmbedPlugin/index.d.ts +27 -0
  364. package/lib/main/plugins/AutoEmbedPlugin/index.js +353 -0
  365. package/lib/main/plugins/AutoEmbedPlugin/urlParseCache.d.ts +2 -0
  366. package/lib/main/plugins/AutoEmbedPlugin/urlParseCache.js +14 -0
  367. package/lib/main/plugins/AutoLinkPlugin/index.d.ts +9 -0
  368. package/lib/main/plugins/AutoLinkPlugin/index.js +39 -0
  369. package/lib/main/plugins/ClickableLinkPlugin/index.d.ts +8 -0
  370. package/lib/main/plugins/ClickableLinkPlugin/index.js +141 -0
  371. package/lib/main/plugins/CodeActionMenuPlugin/components/CopyButton/index.d.ts +7 -0
  372. package/lib/main/plugins/CodeActionMenuPlugin/components/CopyButton/index.js +44 -0
  373. package/lib/main/plugins/CodeActionMenuPlugin/index.css +46 -0
  374. package/lib/main/plugins/CodeActionMenuPlugin/index.d.ts +12 -0
  375. package/lib/main/plugins/CodeActionMenuPlugin/index.js +100 -0
  376. package/lib/main/plugins/CodeActionMenuPlugin/utils.d.ts +2 -0
  377. package/lib/main/plugins/CodeActionMenuPlugin/utils.js +18 -0
  378. package/lib/main/plugins/CodeHighlightPlugin/index.d.ts +9 -0
  379. package/lib/main/plugins/CodeHighlightPlugin/index.js +17 -0
  380. package/lib/main/plugins/CollapsiblePlugin/Collapsible.css +61 -0
  381. package/lib/main/plugins/CollapsiblePlugin/CollapsibleContainerNode.d.ts +30 -0
  382. package/lib/main/plugins/CollapsiblePlugin/CollapsibleContainerNode.js +120 -0
  383. package/lib/main/plugins/CollapsiblePlugin/CollapsibleContentNode.d.ts +24 -0
  384. package/lib/main/plugins/CollapsiblePlugin/CollapsibleContentNode.js +90 -0
  385. package/lib/main/plugins/CollapsiblePlugin/CollapsibleTitleNode.d.ts +24 -0
  386. package/lib/main/plugins/CollapsiblePlugin/CollapsibleTitleNode.js +95 -0
  387. package/lib/main/plugins/CollapsiblePlugin/CollapsibleUtils.d.ts +9 -0
  388. package/lib/main/plugins/CollapsiblePlugin/CollapsibleUtils.js +15 -0
  389. package/lib/main/plugins/CollapsiblePlugin/index.d.ts +11 -0
  390. package/lib/main/plugins/CollapsiblePlugin/index.js +147 -0
  391. package/lib/main/plugins/ComponentPickerPlugin/index.d.ts +12 -0
  392. package/lib/main/plugins/ComponentPickerPlugin/index.js +438 -0
  393. package/lib/main/plugins/DragDropPastePlugin/index.d.ts +8 -0
  394. package/lib/main/plugins/DragDropPastePlugin/index.js +32 -0
  395. package/lib/main/plugins/DraggableBlockPlugin/index.css +36 -0
  396. package/lib/main/plugins/DraggableBlockPlugin/index.d.ts +12 -0
  397. package/lib/main/plugins/DraggableBlockPlugin/index.js +288 -0
  398. package/lib/main/plugins/EmojisPlugin/index.d.ts +9 -0
  399. package/lib/main/plugins/EmojisPlugin/index.js +63 -0
  400. package/lib/main/plugins/ExcalidrawPlugin/index.d.ts +3 -0
  401. package/lib/main/plugins/ExcalidrawPlugin/index.js +30 -0
  402. package/lib/main/plugins/FigmaPlugin/index.d.ts +11 -0
  403. package/lib/main/plugins/FigmaPlugin/index.js +27 -0
  404. package/lib/main/plugins/FloatingLinkEditorPlugin/index.css +39 -0
  405. package/lib/main/plugins/FloatingLinkEditorPlugin/index.d.ts +12 -0
  406. package/lib/main/plugins/FloatingLinkEditorPlugin/index.js +181 -0
  407. package/lib/main/plugins/FloatingTextFormatToolbarPlugin/ColorPickerButton.d.ts +5 -0
  408. package/lib/main/plugins/FloatingTextFormatToolbarPlugin/ColorPickerButton.js +24 -0
  409. package/lib/main/plugins/FloatingTextFormatToolbarPlugin/index.css +128 -0
  410. package/lib/main/plugins/FloatingTextFormatToolbarPlugin/index.d.ts +12 -0
  411. package/lib/main/plugins/FloatingTextFormatToolbarPlugin/index.js +216 -0
  412. package/lib/main/plugins/HorizontalRulePlugin/index.d.ts +8 -0
  413. package/lib/main/plugins/HorizontalRulePlugin/index.js +30 -0
  414. package/lib/main/plugins/ImagesPlugin/index.d.ts +15 -0
  415. package/lib/main/plugins/ImagesPlugin/index.js +36 -0
  416. package/lib/main/plugins/LexicalTypeaheadMenuPlugin/index.d.ts +64 -0
  417. package/lib/main/plugins/LexicalTypeaheadMenuPlugin/index.js +493 -0
  418. package/lib/main/plugins/MarkdownShortcutPlugin/index.d.ts +9 -0
  419. package/lib/main/plugins/MarkdownShortcutPlugin/index.js +22 -0
  420. package/lib/main/plugins/MarkdownTransformers/index.d.ts +12 -0
  421. package/lib/main/plugins/MarkdownTransformers/index.js +185 -0
  422. package/lib/main/plugins/MaxLengthPlugin/index.d.ts +10 -0
  423. package/lib/main/plugins/MaxLengthPlugin/index.js +43 -0
  424. package/lib/main/plugins/MentionsPlugin/HighlightStyle.d.ts +2 -0
  425. package/lib/main/plugins/MentionsPlugin/HighlightStyle.js +13 -0
  426. package/lib/main/plugins/MentionsPlugin/index.d.ts +9 -0
  427. package/lib/main/plugins/MentionsPlugin/index.js +175 -0
  428. package/lib/main/plugins/TabFocusPlugin/index.d.ts +8 -0
  429. package/lib/main/plugins/TabFocusPlugin/index.js +41 -0
  430. package/lib/main/plugins/TableActionMenuPlugin/index.d.ts +12 -0
  431. package/lib/main/plugins/TableActionMenuPlugin/index.js +486 -0
  432. package/lib/main/plugins/TableCellResizer/index.css +20 -0
  433. package/lib/main/plugins/TableCellResizer/index.d.ts +3 -0
  434. package/lib/main/plugins/TableCellResizer/index.js +295 -0
  435. package/lib/main/plugins/TableOfContentsPlugin/index.css +87 -0
  436. package/lib/main/plugins/TableOfContentsPlugin/index.d.ts +2 -0
  437. package/lib/main/plugins/TableOfContentsPlugin/index.js +106 -0
  438. package/lib/main/plugins/TablePlugin.d.ts +38 -0
  439. package/lib/main/plugins/TablePlugin.js +63 -0
  440. package/lib/main/plugins/ToolbarPlugin/index.d.ts +8 -0
  441. package/lib/main/plugins/ToolbarPlugin/index.js +467 -0
  442. package/lib/main/plugins/TreeViewPlugin/index.d.ts +9 -0
  443. package/lib/main/plugins/TreeViewPlugin/index.js +14 -0
  444. package/lib/main/plugins/TwitterPlugin/index.d.ts +11 -0
  445. package/lib/main/plugins/TwitterPlugin/index.js +27 -0
  446. package/lib/main/plugins/TypingPerfPlugin/index.d.ts +9 -0
  447. package/lib/main/plugins/TypingPerfPlugin/index.js +100 -0
  448. package/lib/main/plugins/YouTubePlugin/index.d.ts +11 -0
  449. package/lib/main/plugins/YouTubePlugin/index.js +27 -0
  450. package/lib/main/server/validation.d.ts +8 -0
  451. package/lib/main/server/validation.js +119 -0
  452. package/lib/main/setupEnv.d.ts +8 -0
  453. package/lib/main/setupEnv.js +25 -0
  454. package/lib/main/style/editable.css +476 -0
  455. package/lib/main/styled-editor-content.d.ts +5 -0
  456. package/lib/main/styled-editor-content.js +206 -0
  457. package/lib/main/themes/code-highlight/index.d.ts +32 -0
  458. package/lib/main/themes/code-highlight/index.js +58 -0
  459. package/lib/main/themes/customTheme.d.ts +2 -0
  460. package/lib/main/themes/customTheme.js +324 -0
  461. package/lib/main/themes/defaultTheme.d.ts +10 -0
  462. package/lib/main/themes/defaultTheme.js +554 -0
  463. package/lib/main/themes/table/index.d.ts +3 -0
  464. package/lib/main/themes/table/index.js +20 -0
  465. package/lib/main/themes/table/table.css +214 -0
  466. package/lib/main/ui/Button.css +36 -0
  467. package/lib/main/ui/Button.d.ts +18 -0
  468. package/lib/main/ui/Button.js +13 -0
  469. package/lib/main/ui/ColorPicker.css +89 -0
  470. package/lib/main/ui/ColorPicker.d.ts +28 -0
  471. package/lib/main/ui/ColorPicker.js +206 -0
  472. package/lib/main/ui/ContentEditable.d.ts +2 -0
  473. package/lib/main/ui/ContentEditable.js +15 -0
  474. package/lib/main/ui/Dialog.css +17 -0
  475. package/lib/main/ui/Dialog.d.ts +16 -0
  476. package/lib/main/ui/Dialog.js +15 -0
  477. package/lib/main/ui/DropDown.d.ts +25 -0
  478. package/lib/main/ui/DropDown.js +146 -0
  479. package/lib/main/ui/FileInput.d.ts +17 -0
  480. package/lib/main/ui/FileInput.js +5 -0
  481. package/lib/main/ui/FrameMockup/browser.css +52 -0
  482. package/lib/main/ui/FrameMockup/browser.d.ts +13 -0
  483. package/lib/main/ui/FrameMockup/browser.js +22 -0
  484. package/lib/main/ui/FrameMockup/index.d.ts +113 -0
  485. package/lib/main/ui/FrameMockup/index.js +61 -0
  486. package/lib/main/ui/ImageEnhancer.d.ts +29 -0
  487. package/lib/main/ui/ImageEnhancer.js +113 -0
  488. package/lib/main/ui/ImageResizer.d.ts +24 -0
  489. package/lib/main/ui/ImageResizer.js +154 -0
  490. package/lib/main/ui/Input.css +30 -0
  491. package/lib/main/ui/Modal.css +62 -0
  492. package/lib/main/ui/Modal.d.ts +15 -0
  493. package/lib/main/ui/Modal.js +50 -0
  494. package/lib/main/ui/Placeholder.d.ts +6 -0
  495. package/lib/main/ui/Placeholder.js +20 -0
  496. package/lib/main/ui/TextInput.d.ts +20 -0
  497. package/lib/main/ui/TextInput.js +14 -0
  498. package/lib/main/utils/getDOMRangeRect.d.ts +8 -0
  499. package/lib/main/utils/getDOMRangeRect.js +22 -0
  500. package/lib/main/utils/getSelectedNode.d.ts +2 -0
  501. package/lib/main/utils/getSelectedNode.js +22 -0
  502. package/lib/main/utils/guard.d.ts +14 -0
  503. package/lib/main/utils/guard.js +36 -0
  504. package/lib/main/utils/images.d.ts +10 -0
  505. package/lib/main/utils/images.js +16 -0
  506. package/lib/main/utils/join-classes.d.ts +8 -0
  507. package/lib/main/utils/join-classes.js +10 -0
  508. package/lib/main/utils/point.d.ts +21 -0
  509. package/lib/main/utils/point.js +42 -0
  510. package/lib/main/utils/prevent-duplicate-upload.d.ts +2 -0
  511. package/lib/main/utils/prevent-duplicate-upload.js +25 -0
  512. package/lib/main/utils/rect.d.ts +45 -0
  513. package/lib/main/utils/rect.js +98 -0
  514. package/lib/main/utils/sanitizeUrl.d.ts +8 -0
  515. package/lib/main/utils/sanitizeUrl.js +17 -0
  516. package/lib/main/utils/setFloatingElemPosition.d.ts +1 -0
  517. package/lib/main/utils/setFloatingElemPosition.js +32 -0
  518. package/lib/main/utils/swipe.d.ts +11 -0
  519. package/lib/main/utils/swipe.js +98 -0
  520. package/lib/main/viewer/index.d.ts +5 -0
  521. package/lib/main/viewer/index.js +25 -0
  522. package/lib/main/viewer/types.d.ts +14 -0
  523. package/lib/main/viewer/types.js +1 -0
  524. package/lib/main/viewer/viewer.d.ts +3 -0
  525. package/lib/main/viewer/viewer.js +31 -0
  526. package/lib/shared/canUseDOM.d.ts +8 -0
  527. package/lib/shared/canUseDOM.js +10 -0
  528. package/lib/shared/environment.d.ts +24 -0
  529. package/lib/shared/environment.js +21 -0
  530. package/lib/shared/getDOMSelection.d.ts +9 -0
  531. package/lib/shared/getDOMSelection.js +10 -0
  532. package/lib/shared/invariant.d.ts +8 -0
  533. package/lib/shared/invariant.js +16 -0
  534. package/lib/shared/useLayoutEffect.d.ts +10 -0
  535. package/lib/shared/useLayoutEffect.js +11 -0
  536. package/lib/types.d.ts +19 -0
  537. package/lib/types.js +1 -0
  538. package/lib/vendor/LexicalCharacterLimitPlugin/LexicalCharacterLimitPlugin.d.ts +15 -0
  539. package/lib/vendor/LexicalCharacterLimitPlugin/LexicalCharacterLimitPlugin.js +45 -0
  540. package/lib/vendor/LexicalCharacterLimitPlugin/index.d.ts +1 -0
  541. package/lib/vendor/LexicalCharacterLimitPlugin/index.js +1 -0
  542. package/lib/vendor/LexicalCharacterLimitPlugin/useCharacterLimit.d.ts +16 -0
  543. package/lib/vendor/LexicalCharacterLimitPlugin/useCharacterLimit.js +208 -0
  544. package/lib/vendor/history/LexicalHistoryPlugin.d.ts +14 -0
  545. package/lib/vendor/history/LexicalHistoryPlugin.js +15 -0
  546. package/lib/vendor/history/history/index.d.ts +63 -0
  547. package/lib/vendor/history/history/index.js +351 -0
  548. package/lib/vendor/history/useHistory.d.ts +10 -0
  549. package/lib/vendor/history/useHistory.js +15 -0
  550. package/package.json +109 -0
@@ -0,0 +1,467 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import styled from '@emotion/styled';
3
+ import { $createCodeNode, $isCodeNode, CODE_LANGUAGE_FRIENDLY_NAME_MAP, CODE_LANGUAGE_MAP, getLanguageFriendlyName, } from '@lexical/code';
4
+ import { $isLinkNode, TOGGLE_LINK_COMMAND } from '@lexical/link';
5
+ import { $isListNode, INSERT_CHECK_LIST_COMMAND, INSERT_ORDERED_LIST_COMMAND, INSERT_UNORDERED_LIST_COMMAND, ListNode, REMOVE_LIST_COMMAND, } from '@lexical/list';
6
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
7
+ import { $isDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode';
8
+ import { $createHeadingNode, $createQuoteNode, $isHeadingNode } from '@lexical/rich-text';
9
+ import { $getSelectionStyleValueForProperty, $patchStyleText, $selectAll, $setBlocksType, } from '@lexical/selection';
10
+ import { $findMatchingParent, $getNearestBlockElementAncestorOrThrow, $getNearestNodeOfType, mergeRegister, } from '@lexical/utils';
11
+ import { $createParagraphNode, $getNodeByKey, $getSelection, $isRangeSelection, $isRootOrShadowRoot, $isTextNode, CAN_REDO_COMMAND, CAN_UNDO_COMMAND, COMMAND_PRIORITY_CRITICAL, FORMAT_ELEMENT_COMMAND, FORMAT_TEXT_COMMAND, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, SELECTION_CHANGE_COMMAND, } from 'lexical';
12
+ import { useCallback, useEffect, useState } from 'react';
13
+ import { Box, useTheme } from '@mui/material';
14
+ import { useEditorConfig } from '../../../config';
15
+ import { IS_APPLE } from '../../../shared/environment';
16
+ import useHasNodes from '../../hooks/useHasNodes';
17
+ import useModal from '../../hooks/useModal';
18
+ // import catTypingGif from "../../images/cat-typing.gif";
19
+ import ColorPicker from '../../ui/ColorPicker';
20
+ import DropDown, { DropDownItem } from '../../ui/DropDown';
21
+ import { getSelectedNode } from '../../utils/getSelectedNode';
22
+ import { sanitizeUrl } from '../../utils/sanitizeUrl';
23
+ // import { EmbedConfigs } from "../AutoEmbedPlugin";
24
+ // import { INSERT_COLLAPSIBLE_COMMAND } from "../CollapsiblePlugin";
25
+ // import { INSERT_EXCALIDRAW_COMMAND } from "../ExcalidrawPlugin";
26
+ import { INSERT_IMAGE_COMMAND } from '../ImagesPlugin';
27
+ import { uploadFile, INSERT_COMPONENT_COMMAND } from '../ComponentPickerPlugin';
28
+ // import { InsertNewTableDialog, InsertTableDialog } from "../TablePlugin";
29
+ const blockTypeToBlockName = {
30
+ bullet: 'Bulleted List',
31
+ check: 'Check List',
32
+ code: 'Code Block',
33
+ h1: 'Heading 1',
34
+ h2: 'Heading 2',
35
+ h3: 'Heading 3',
36
+ h4: 'Heading 4',
37
+ h5: 'Heading 5',
38
+ h6: 'Heading 6',
39
+ number: 'Numbered List',
40
+ paragraph: 'Normal',
41
+ quote: 'Quote',
42
+ };
43
+ function getCodeLanguageOptions() {
44
+ const options = [];
45
+ for (const [lang, friendlyName] of Object.entries(CODE_LANGUAGE_FRIENDLY_NAME_MAP)) {
46
+ options.push([lang, friendlyName]);
47
+ }
48
+ return options;
49
+ }
50
+ const CODE_LANGUAGE_OPTIONS = getCodeLanguageOptions();
51
+ function dropDownActiveClass(active) {
52
+ if (active)
53
+ return 'active dropdown-item-active';
54
+ return '';
55
+ }
56
+ function BlockFormatDropDown({ editor, blockType, disabled = false, }) {
57
+ const hasNodes = useHasNodes();
58
+ const formatParagraph = () => {
59
+ editor.update(() => {
60
+ const selection = $getSelection();
61
+ $setBlocksType(selection, () => $createParagraphNode());
62
+ });
63
+ };
64
+ const formatHeading = (headingSize) => {
65
+ if (blockType !== headingSize) {
66
+ editor.update(() => {
67
+ const selection = $getSelection();
68
+ $setBlocksType(selection, () => $createHeadingNode(headingSize));
69
+ });
70
+ }
71
+ };
72
+ const formatBulletList = () => {
73
+ if (blockType !== 'bullet') {
74
+ editor.dispatchCommand(INSERT_UNORDERED_LIST_COMMAND, undefined);
75
+ }
76
+ else {
77
+ editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);
78
+ }
79
+ };
80
+ const formatCheckList = () => {
81
+ if (blockType !== 'check') {
82
+ editor.dispatchCommand(INSERT_CHECK_LIST_COMMAND, undefined);
83
+ }
84
+ else {
85
+ editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);
86
+ }
87
+ };
88
+ const formatNumberedList = () => {
89
+ if (blockType !== 'number') {
90
+ editor.dispatchCommand(INSERT_ORDERED_LIST_COMMAND, undefined);
91
+ }
92
+ else {
93
+ editor.dispatchCommand(REMOVE_LIST_COMMAND, undefined);
94
+ }
95
+ };
96
+ const formatQuote = () => {
97
+ if (blockType !== 'quote') {
98
+ editor.update(() => {
99
+ const selection = $getSelection();
100
+ $setBlocksType(selection, () => $createQuoteNode());
101
+ });
102
+ }
103
+ };
104
+ const formatCode = () => {
105
+ if (blockType !== 'code') {
106
+ editor.update(() => {
107
+ let selection = $getSelection();
108
+ if (selection !== null) {
109
+ if (selection.isCollapsed()) {
110
+ $setBlocksType(selection, () => $createCodeNode());
111
+ }
112
+ else {
113
+ const textContent = selection.getTextContent();
114
+ const codeNode = $createCodeNode();
115
+ selection.insertNodes([codeNode]);
116
+ selection = $getSelection();
117
+ if ($isRangeSelection(selection))
118
+ selection.insertRawText(textContent);
119
+ }
120
+ }
121
+ });
122
+ }
123
+ };
124
+ const icons = {
125
+ paragraph: 'tabler:letter-case',
126
+ h1: 'tabler:h-1',
127
+ h2: 'tabler:h-2',
128
+ h3: 'tabler:h-3',
129
+ bullet: 'tabler:list',
130
+ number: 'tabler:list-numbers',
131
+ check: 'tabler:list-details',
132
+ quote: 'tabler:quote',
133
+ code: 'tabler:code',
134
+ };
135
+ return (_jsxs(DropDown, { disabled: disabled, buttonClassName: "toolbar-item", buttonIconClassName: "iconify", buttonIconData: icons[blockType], buttonLabel: blockTypeToBlockName[blockType], buttonAriaLabel: "Formatting options for text style", children: [_jsxs(DropDownItem, { className: `item ${dropDownActiveClass(blockType === 'paragraph')}`, onClick: formatParagraph, children: [_jsx("i", { className: "iconify", "data-icon": icons.paragraph }), _jsx("span", { className: "text", children: "Normal" })] }), hasNodes('heading') && (_jsxs(DropDownItem, { className: `item ${dropDownActiveClass(blockType === 'h1')}`, onClick: () => formatHeading('h1'), children: [_jsx("i", { className: "iconify", "data-icon": icons.h1 }), _jsx("span", { className: "text", children: "Heading 1" })] })), hasNodes('heading') && (_jsxs(DropDownItem, { className: `item ${dropDownActiveClass(blockType === 'h2')}`, onClick: () => formatHeading('h2'), children: [_jsx("i", { className: "iconify", "data-icon": icons.h2 }), _jsx("span", { className: "text", children: "Heading 2" })] })), hasNodes('heading') && (_jsxs(DropDownItem, { className: `item ${dropDownActiveClass(blockType === 'h3')}`, onClick: () => formatHeading('h3'), children: [_jsx("i", { className: "iconify", "data-icon": icons.h3 }), _jsx("span", { className: "text", children: "Heading 3" })] })), hasNodes('list') && (_jsxs(DropDownItem, { className: `item ${dropDownActiveClass(blockType === 'bullet')}`, onClick: formatBulletList, children: [_jsx("i", { className: "iconify", "data-icon": icons.bullet }), _jsx("span", { className: "text", children: "Bullet List" })] })), hasNodes('list') && (_jsxs(DropDownItem, { className: `item ${dropDownActiveClass(blockType === 'number')}`, onClick: formatNumberedList, children: [_jsx("i", { className: "iconify", "data-icon": icons.number }), _jsx("span", { className: "text", children: "Numbered List" })] })), hasNodes('list') && (_jsxs(DropDownItem, { className: `item ${dropDownActiveClass(blockType === 'check')}`, onClick: formatCheckList, children: [_jsx("i", { className: "iconify", "data-icon": icons.check }), _jsx("span", { className: "text", children: "Check List" })] })), hasNodes('quote') && (_jsxs(DropDownItem, { className: `item ${dropDownActiveClass(blockType === 'quote')}`, onClick: formatQuote, children: [_jsx("i", { className: "iconify", "data-icon": icons.quote }), _jsx("span", { className: "text", children: "Quote" })] })), hasNodes('code') && (_jsxs(DropDownItem, { className: `item ${dropDownActiveClass(blockType === 'code')}`, onClick: formatCode, children: [_jsx("i", { className: "iconify", "data-icon": icons.code }), _jsx("span", { className: "text", children: "Code Block" })] }))] }));
136
+ }
137
+ function Divider() {
138
+ const theme = useTheme();
139
+ return _jsx("div", { className: "divider", style: { backgroundColor: theme.palette.divider } });
140
+ }
141
+ export default function ToolbarPlugin() {
142
+ const [editor] = useLexicalComposerContext();
143
+ const [activeEditor, setActiveEditor] = useState(editor);
144
+ const [blockType, setBlockType] = useState('paragraph');
145
+ const [selectedElementKey, setSelectedElementKey] = useState(null);
146
+ const [fontColor, setFontColor] = useState('#000');
147
+ const [bgColor, setBgColor] = useState('#fff');
148
+ const [isLink, setIsLink] = useState(false);
149
+ const [isBold, setIsBold] = useState(false);
150
+ const [isItalic, setIsItalic] = useState(false);
151
+ const [isUnderline, setIsUnderline] = useState(false);
152
+ const [isStrikethrough, setIsStrikethrough] = useState(false);
153
+ const [isSubscript, setIsSubscript] = useState(false);
154
+ const [isSuperscript, setIsSuperscript] = useState(false);
155
+ const [isCode, setIsCode] = useState(false);
156
+ const [canUndo, setCanUndo] = useState(false);
157
+ const [canRedo, setCanRedo] = useState(false);
158
+ const [modal, showModal] = useModal();
159
+ const [codeLanguage, setCodeLanguage] = useState('');
160
+ const [isEditable, setIsEditable] = useState(() => editor.isEditable());
161
+ const hasNodes = useHasNodes();
162
+ const updateToolbar = useCallback(() => {
163
+ const selection = $getSelection();
164
+ if ($isRangeSelection(selection)) {
165
+ const anchorNode = selection.anchor.getNode();
166
+ let element = anchorNode.getKey() === 'root'
167
+ ? anchorNode
168
+ : $findMatchingParent(anchorNode, (e) => {
169
+ const parent = e.getParent();
170
+ return parent !== null && $isRootOrShadowRoot(parent);
171
+ });
172
+ if (element === null) {
173
+ element = anchorNode.getTopLevelElementOrThrow();
174
+ }
175
+ const elementKey = element.getKey();
176
+ const elementDOM = activeEditor.getElementByKey(elementKey);
177
+ // Update text format
178
+ setIsBold(selection.hasFormat('bold'));
179
+ setIsItalic(selection.hasFormat('italic'));
180
+ setIsUnderline(selection.hasFormat('underline'));
181
+ setIsStrikethrough(selection.hasFormat('strikethrough'));
182
+ setIsSubscript(selection.hasFormat('subscript'));
183
+ setIsSuperscript(selection.hasFormat('superscript'));
184
+ setIsCode(selection.hasFormat('code'));
185
+ // Update links
186
+ const node = getSelectedNode(selection);
187
+ const parent = node.getParent();
188
+ if ($isLinkNode(parent) || $isLinkNode(node)) {
189
+ setIsLink(true);
190
+ }
191
+ else {
192
+ setIsLink(false);
193
+ }
194
+ if (elementDOM !== null) {
195
+ setSelectedElementKey(elementKey);
196
+ if ($isListNode(element)) {
197
+ const parentList = $getNearestNodeOfType(anchorNode, ListNode);
198
+ const type = parentList ? parentList.getListType() : element.getListType();
199
+ setBlockType(type);
200
+ }
201
+ else {
202
+ const type = $isHeadingNode(element) ? element.getTag() : element.getType();
203
+ if (type in blockTypeToBlockName) {
204
+ setBlockType(type);
205
+ }
206
+ if ($isCodeNode(element)) {
207
+ const language = element.getLanguage();
208
+ setCodeLanguage(language ? CODE_LANGUAGE_MAP[language] || language : '');
209
+ return;
210
+ }
211
+ }
212
+ }
213
+ // Handle buttons
214
+ if ($getSelectionStyleValueForProperty(selection, 'color', '#000')) {
215
+ setFontColor($getSelectionStyleValueForProperty(selection, 'color', '#000'));
216
+ }
217
+ if ($getSelectionStyleValueForProperty(selection, 'background-color', '#fff')) {
218
+ setBgColor($getSelectionStyleValueForProperty(selection, 'background-color', '#fff'));
219
+ }
220
+ }
221
+ }, [activeEditor]);
222
+ useEffect(() => {
223
+ return editor.registerCommand(SELECTION_CHANGE_COMMAND, (_payload, newEditor) => {
224
+ updateToolbar();
225
+ setActiveEditor(newEditor);
226
+ return false;
227
+ }, COMMAND_PRIORITY_CRITICAL);
228
+ }, [editor, updateToolbar]);
229
+ useEffect(() => {
230
+ return mergeRegister(editor.registerEditableListener((editable) => {
231
+ setIsEditable(editable);
232
+ }), activeEditor.registerUpdateListener((payload) => {
233
+ if (!payload)
234
+ return;
235
+ const { editorState } = payload;
236
+ editorState.read(() => {
237
+ updateToolbar();
238
+ });
239
+ }), activeEditor.registerCommand(CAN_UNDO_COMMAND, (payload) => {
240
+ setCanUndo(payload);
241
+ return false;
242
+ }, COMMAND_PRIORITY_CRITICAL), activeEditor.registerCommand(CAN_REDO_COMMAND, (payload) => {
243
+ setCanRedo(payload);
244
+ return false;
245
+ }, COMMAND_PRIORITY_CRITICAL));
246
+ }, [activeEditor, editor, updateToolbar]);
247
+ const applyStyleText = useCallback((styles) => {
248
+ activeEditor.update(() => {
249
+ const selection = $getSelection();
250
+ if ($isRangeSelection(selection)) {
251
+ $patchStyleText(selection, styles);
252
+ }
253
+ });
254
+ }, [activeEditor]);
255
+ const clearFormatting = useCallback(() => {
256
+ activeEditor.update(() => {
257
+ const selection = $getSelection();
258
+ if ($isRangeSelection(selection)) {
259
+ $selectAll(selection);
260
+ selection.getNodes().forEach((node) => {
261
+ if ($isTextNode(node)) {
262
+ node.setFormat(0);
263
+ node.setStyle('');
264
+ $getNearestBlockElementAncestorOrThrow(node).setFormat('');
265
+ }
266
+ if ($isDecoratorBlockNode(node)) {
267
+ node.setFormat('');
268
+ }
269
+ });
270
+ }
271
+ });
272
+ }, [activeEditor]);
273
+ const onFontColorSelect = useCallback((value) => {
274
+ applyStyleText({ color: value });
275
+ }, [applyStyleText]);
276
+ const onBgColorSelect = useCallback((value) => {
277
+ applyStyleText({ 'background-color': value });
278
+ }, [applyStyleText]);
279
+ const insertLink = useCallback(() => {
280
+ if (!isLink) {
281
+ editor.dispatchCommand(TOGGLE_LINK_COMMAND, sanitizeUrl('https://'));
282
+ }
283
+ else {
284
+ editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
285
+ }
286
+ }, [editor, isLink]);
287
+ const onCodeLanguageSelect = useCallback((value) => {
288
+ activeEditor.update(() => {
289
+ if (selectedElementKey !== null) {
290
+ const node = $getNodeByKey(selectedElementKey);
291
+ if ($isCodeNode(node)) {
292
+ node.setLanguage(value);
293
+ }
294
+ }
295
+ });
296
+ }, [activeEditor, selectedElementKey]);
297
+ const insertGifOnClick = (payload) => {
298
+ activeEditor.dispatchCommand(INSERT_IMAGE_COMMAND, payload);
299
+ };
300
+ const { toolbar: toolbarConfig, minimalMode } = useEditorConfig();
301
+ const defaultItems = minimalMode
302
+ ? ['component', 'block', 'bold', 'italic', 'underline', 'media', 'code', 'link']
303
+ : [
304
+ 'component',
305
+ 'block',
306
+ 'align',
307
+ 'bold',
308
+ 'italic',
309
+ 'underline',
310
+ 'media',
311
+ 'code',
312
+ 'link',
313
+ 'color',
314
+ 'bgcolor',
315
+ 'strikethrough',
316
+ ];
317
+ const items = toolbarConfig?.items ?? defaultItems;
318
+ const menus = [];
319
+ for (const item of items) {
320
+ switch (item) {
321
+ case 'component': {
322
+ menus.push(_jsx(FormatButton, { disabled: !isEditable, onClick: () => {
323
+ // add '/' to editor
324
+ editor.dispatchCommand(INSERT_COMPONENT_COMMAND, '/');
325
+ }, className: "toolbar-item spaced", title: "Component Picker", "aria-label": "Open component picker", children: _jsx("i", { className: "iconify", "data-icon": "tabler:circle-plus" }) }, item));
326
+ break;
327
+ }
328
+ case 'block': {
329
+ // minimalMode 不需要 'block', 但需要 'code (block)'
330
+ if (blockType in blockTypeToBlockName && activeEditor === editor && !minimalMode) {
331
+ menus.push(_jsx(BlockFormatDropDown, { disabled: !isEditable, blockType: blockType, editor: editor }, "block")
332
+ // <Divider key="block-divider" />
333
+ );
334
+ }
335
+ if (blockType === 'code') {
336
+ menus.push(_jsx(DropDown, { disabled: !isEditable, buttonClassName: "toolbar-item code-language", buttonLabel: getLanguageFriendlyName(codeLanguage), buttonAriaLabel: "Select language", children: CODE_LANGUAGE_OPTIONS.map(([value, name]) => {
337
+ return (_jsx(DropDownItem, { className: `item ${dropDownActiveClass(value === codeLanguage)}`, onClick: () => onCodeLanguageSelect(value), children: _jsx("span", { className: "text", children: name }) }, value));
338
+ }) }, "block-code"));
339
+ }
340
+ break;
341
+ }
342
+ case 'bold': {
343
+ if (blockType !== 'code') {
344
+ menus.push(_jsx(FormatButton, { disabled: !isEditable, onClick: () => {
345
+ activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, 'bold');
346
+ }, className: `toolbar-item spaced ${isBold ? 'active' : ''}`, title: IS_APPLE ? 'Bold (⌘B)' : 'Bold (Ctrl+B)', "aria-label": `Format text as bold. Shortcut: ${IS_APPLE ? '⌘B' : 'Ctrl+B'}`, children: _jsx("i", { className: "iconify", "data-icon": "tabler:bold" }) }, item));
347
+ }
348
+ break;
349
+ }
350
+ case 'italic': {
351
+ if (blockType !== 'code') {
352
+ menus.push(_jsx(FormatButton, { disabled: !isEditable, onClick: () => {
353
+ activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, 'italic');
354
+ }, className: `toolbar-item spaced ${isItalic ? 'active' : ''}`, title: IS_APPLE ? 'Italic (⌘I)' : 'Italic (Ctrl+I)', "aria-label": `Format text as italics. Shortcut: ${IS_APPLE ? '⌘I' : 'Ctrl+I'}`, children: _jsx("i", { className: "iconify", "data-icon": "tabler:italic" }) }, item));
355
+ }
356
+ break;
357
+ }
358
+ case 'underline': {
359
+ if (blockType !== 'code') {
360
+ menus.push(_jsx(FormatButton, { disabled: !isEditable, onClick: () => {
361
+ activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, 'underline');
362
+ }, className: `toolbar-item spaced ${isUnderline ? 'active' : ''}`, title: IS_APPLE ? 'Underline (⌘U)' : 'Underline (Ctrl+U)', "aria-label": `Format text to underlined. Shortcut: ${IS_APPLE ? '⌘U' : 'Ctrl+U'}`, children: _jsx("i", { className: "iconify", "data-icon": "tabler:underline" }) }, item));
363
+ }
364
+ break;
365
+ }
366
+ case 'code': {
367
+ if (blockType !== 'code') {
368
+ menus.push(_jsx(FormatButton, { disabled: !isEditable, onClick: () => {
369
+ activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, 'code');
370
+ }, className: `toolbar-item code ${isCode ? 'active' : ''}`, title: "Insert code block", "aria-label": "Insert code block", children: _jsx("i", { className: "iconify", "data-icon": "tabler:code" }) }, item));
371
+ }
372
+ break;
373
+ }
374
+ case 'link': {
375
+ if (hasNodes('link') && blockType !== 'code') {
376
+ menus.push(_jsx(FormatButton, { disabled: !isEditable, onClick: insertLink, className: `toolbar-item spaced link ${isLink ? 'active' : ''}`, "aria-label": "Insert link", title: "Insert link", children: _jsx("i", { className: "iconify", "data-icon": "tabler:link" }) }, item));
377
+ }
378
+ break;
379
+ }
380
+ case 'color': {
381
+ if (blockType !== 'code') {
382
+ menus.push(_jsx(ColorPicker, { disabled: !isEditable, buttonClassName: "toolbar-item color-picker", buttonAriaLabel: "Formatting text color", buttonIconClassName: "iconify", buttonIconData: "tabler:text-color", color: fontColor, onChange: onFontColorSelect, title: "text color" }, item));
383
+ }
384
+ break;
385
+ }
386
+ case 'bgcolor': {
387
+ if (blockType !== 'code') {
388
+ menus.push(_jsx(ColorPicker, { disabled: !isEditable, buttonClassName: "toolbar-item color-picker", buttonAriaLabel: "Formatting background color", buttonIconClassName: "iconify", buttonIconData: "tabler:bucket-droplet", color: bgColor, onChange: onBgColorSelect, title: "bg color" }, item));
389
+ }
390
+ break;
391
+ }
392
+ case 'strikethrough': {
393
+ if (blockType !== 'code') {
394
+ menus.push(_jsxs(DropDown, { disabled: !isEditable, buttonClassName: "toolbar-item spaced text-format-additional", buttonLabel: "", buttonAriaLabel: "Formatting options for additional text styles", buttonIconData: "tabler:adjustments", buttonIconClassName: "iconify", children: [_jsxs(DropDownItem, { onClick: () => {
395
+ activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, 'strikethrough');
396
+ }, className: `item ${dropDownActiveClass(isStrikethrough)}`, title: "Strikethrough", "aria-label": "Format text with a strikethrough", children: [_jsx("i", { className: "iconify", "data-icon": "tabler:strikethrough" }), _jsx("span", { className: "text", children: "Strikethrough" })] }), _jsxs(DropDownItem, { onClick: () => {
397
+ activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, 'subscript');
398
+ }, className: `item ${dropDownActiveClass(isSubscript)}`, title: "Subscript", "aria-label": "Format text with a subscript", children: [_jsx("i", { className: "iconify", "data-icon": "tabler:subscript" }), _jsx("span", { className: "text", children: "Subscript" })] }), _jsxs(DropDownItem, { onClick: () => {
399
+ activeEditor.dispatchCommand(FORMAT_TEXT_COMMAND, 'superscript');
400
+ }, className: `item ${dropDownActiveClass(isSuperscript)}`, title: "Superscript", "aria-label": "Format text with a superscript", children: [_jsx("i", { className: "iconify", "data-icon": "tabler:superscript" }), _jsx("span", { className: "text", children: "Superscript" })] }), _jsxs(DropDownItem, { onClick: clearFormatting, className: "item", title: "Clear text formatting", "aria-label": "Clear all text formatting", children: [_jsx("i", { className: "iconify", "data-icon": "tabler:clear-formatting" }), _jsx("span", { className: "text", children: "Clear Formatting" })] })] }, item));
401
+ }
402
+ break;
403
+ }
404
+ case 'align': {
405
+ const icons = {
406
+ left: 'tabler:align-left',
407
+ center: 'tabler:align-center',
408
+ right: 'tabler:align-right',
409
+ justify: 'tabler:align-justified',
410
+ outdent: 'tabler:indent-decrease',
411
+ indent: 'tabler:indent-increase',
412
+ };
413
+ menus.push(_jsxs(DropDown, { disabled: !isEditable, buttonIconClassName: "iconify", buttonIconData: icons.left, buttonClassName: "toolbar-item spaced alignment", buttonAriaLabel: "Formatting options for text alignment", children: [_jsxs(DropDownItem, { onClick: () => {
414
+ activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'left');
415
+ }, className: "item", children: [_jsx("i", { className: "iconify", "data-icon": icons.left }), _jsx("span", { className: "text", children: "Left Align" })] }), _jsxs(DropDownItem, { onClick: () => {
416
+ activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'center');
417
+ }, className: "item", children: [_jsx("i", { className: "iconify", "data-icon": icons.center }), _jsx("span", { className: "text", children: "Center Align" })] }), _jsxs(DropDownItem, { onClick: () => {
418
+ activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'right');
419
+ }, className: "item", children: [_jsx("i", { className: "iconify", "data-icon": icons.right }), _jsx("span", { className: "text", children: "Right Align" })] }), _jsxs(DropDownItem, { onClick: () => {
420
+ activeEditor.dispatchCommand(FORMAT_ELEMENT_COMMAND, 'justify');
421
+ }, className: "item", children: [_jsx("i", { className: "iconify", "data-icon": icons.justify }), _jsx("span", { className: "text", children: "Justify Align" })] }), _jsx(Divider, {}), _jsxs(DropDownItem, { onClick: () => {
422
+ activeEditor.dispatchCommand(OUTDENT_CONTENT_COMMAND, undefined);
423
+ }, className: "item", children: [_jsx("i", { className: "iconify", "data-icon": icons.outdent }), _jsx("span", { className: "text", children: "Outdent" })] }), _jsxs(DropDownItem, { onClick: () => {
424
+ activeEditor.dispatchCommand(INDENT_CONTENT_COMMAND, undefined);
425
+ }, className: "item", children: [_jsx("i", { className: "iconify", "data-icon": icons.indent }), _jsx("span", { className: "text", children: "Indent" })] })] }, item));
426
+ break;
427
+ }
428
+ case 'media': {
429
+ if (blockType !== 'code') {
430
+ menus.push(_jsx(FormatButton, { disabled: !isEditable, onClick: () => {
431
+ uploadFile(editor);
432
+ }, className: `toolbar-item spaced ${isCode ? 'active' : ''}`, title: "Upload Image", "aria-label": "Upload Image", children: _jsx("i", { className: "iconify", "data-icon": "tabler:photo" }) }, item));
433
+ }
434
+ break;
435
+ }
436
+ default:
437
+ console.warn(`Unsupported toolbar item ${item}`);
438
+ }
439
+ }
440
+ if (menus.length === 0) {
441
+ return null;
442
+ }
443
+ return (_jsxs(Box, { className: "toolbar", sx: {
444
+ position: 'sticky',
445
+ top: 0,
446
+ zIndex: 10,
447
+ height: 'auto',
448
+ bgcolor: 'background.paper',
449
+ '& button.toolbar-item, & button.toolbar-item .text': {
450
+ color: 'text.primary',
451
+ },
452
+ '& button.toolbar-item.active': {
453
+ backgroundColor: 'action.selected',
454
+ },
455
+ '& .toolbar-item:hover:not([disabled])': {
456
+ backgroundColor: 'action.hover',
457
+ },
458
+ }, children: [menus, modal] }));
459
+ }
460
+ const FormatButton = styled.button `
461
+ display: flex;
462
+ align-items: center;
463
+ font-size: 20px;
464
+ .iconify {
465
+ opacity: 0.6;
466
+ }
467
+ `;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import type { JSX } from 'react';
9
+ export default function TreeViewPlugin(): JSX.Element;
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ *
8
+ */
9
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
10
+ import { TreeView } from '@lexical/react/LexicalTreeView';
11
+ export default function TreeViewPlugin() {
12
+ const [editor] = useLexicalComposerContext();
13
+ return (_jsx(TreeView, { viewClassName: "tree-view-output", treeTypeButtonClassName: "debug-treetype-button", timeTravelPanelClassName: "debug-timetravel-panel", timeTravelButtonClassName: "debug-timetravel-button", timeTravelPanelSliderClassName: "debug-timetravel-panel-slider", timeTravelPanelButtonClassName: "debug-timetravel-panel-button", editor: editor }));
14
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import { LexicalCommand } from 'lexical';
9
+ import { type JSX } from 'react';
10
+ export declare const INSERT_TWEET_COMMAND: LexicalCommand<string>;
11
+ export default function TwitterPlugin(): JSX.Element | null;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
9
+ import { $insertNodeToNearestRoot } from '@lexical/utils';
10
+ import { COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
11
+ import { useEffect } from 'react';
12
+ import { $createTweetNode, TweetNode } from '../../nodes/TweetNode';
13
+ export const INSERT_TWEET_COMMAND = createCommand('INSERT_TWEET_COMMAND');
14
+ export default function TwitterPlugin() {
15
+ const [editor] = useLexicalComposerContext();
16
+ useEffect(() => {
17
+ if (!editor.hasNodes([TweetNode])) {
18
+ throw new Error('TwitterPlugin: TweetNode not registered on editor');
19
+ }
20
+ return editor.registerCommand(INSERT_TWEET_COMMAND, (payload) => {
21
+ const tweetNode = $createTweetNode(payload);
22
+ $insertNodeToNearestRoot(tweetNode);
23
+ return true;
24
+ }, COMMAND_PRIORITY_EDITOR);
25
+ }, [editor]);
26
+ return null;
27
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import { type JSX } from 'react';
9
+ export default function TypingPerfPlugin(): JSX.Element | null;
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import { useEffect } from 'react';
9
+ import useReport from '../../hooks/useReport';
10
+ const validInputTypes = new Set([
11
+ 'insertText',
12
+ 'insertCompositionText',
13
+ 'insertFromComposition',
14
+ 'insertLineBreak',
15
+ 'insertParagraph',
16
+ 'deleteCompositionText',
17
+ 'deleteContentBackward',
18
+ 'deleteByComposition',
19
+ 'deleteContent',
20
+ 'deleteContentForward',
21
+ 'deleteWordBackward',
22
+ 'deleteWordForward',
23
+ 'deleteHardLineBackward',
24
+ 'deleteSoftLineBackward',
25
+ 'deleteHardLineForward',
26
+ 'deleteSoftLineForward',
27
+ ]);
28
+ export default function TypingPerfPlugin() {
29
+ const report = useReport();
30
+ useEffect(() => {
31
+ let start = 0;
32
+ let timerId;
33
+ let keyPressTimerId;
34
+ let log = [];
35
+ let invalidatingEvent = false;
36
+ const measureEventEnd = function logKeyPress() {
37
+ if (keyPressTimerId != null) {
38
+ if (invalidatingEvent) {
39
+ invalidatingEvent = false;
40
+ }
41
+ else {
42
+ log.push(performance.now() - start);
43
+ }
44
+ clearTimeout(keyPressTimerId);
45
+ keyPressTimerId = null;
46
+ }
47
+ };
48
+ const measureEventStart = function measureEvent() {
49
+ if (timerId != null) {
50
+ clearTimeout(timerId);
51
+ timerId = null;
52
+ }
53
+ // We use a setTimeout(0) instead of requestAnimationFrame, due to
54
+ // inconsistencies between the sequencing of rAF in different browsers.
55
+ keyPressTimerId = setTimeout(measureEventEnd, 0);
56
+ // Schedule a timer to report the results.
57
+ timerId = setTimeout(() => {
58
+ const total = log.reduce((a, b) => a + b, 0);
59
+ const reportedText = `Typing Perf: ${Math.round((total / log.length) * 100) / 100}ms`;
60
+ report(reportedText);
61
+ log = [];
62
+ }, 2000);
63
+ // Make the time after we do the previous logic, so we don't measure the overhead
64
+ // for it all.
65
+ start = performance.now();
66
+ };
67
+ const beforeInputHandler = function beforeInputHandler(event) {
68
+ if (!validInputTypes.has(event.inputType) || invalidatingEvent) {
69
+ invalidatingEvent = false;
70
+ return;
71
+ }
72
+ measureEventStart();
73
+ };
74
+ const keyDownHandler = function keyDownHandler(event) {
75
+ const { keyCode } = event;
76
+ if (keyCode === 8 || keyCode === 13) {
77
+ measureEventStart();
78
+ }
79
+ };
80
+ const pasteHandler = function pasteHandler() {
81
+ invalidatingEvent = true;
82
+ };
83
+ const cutHandler = function cutHandler() {
84
+ invalidatingEvent = true;
85
+ };
86
+ window.addEventListener('keydown', keyDownHandler, true);
87
+ window.addEventListener('selectionchange', measureEventEnd, true);
88
+ window.addEventListener('beforeinput', beforeInputHandler, true);
89
+ window.addEventListener('paste', pasteHandler, true);
90
+ window.addEventListener('cut', cutHandler, true);
91
+ return () => {
92
+ window.removeEventListener('keydown', keyDownHandler, true);
93
+ window.removeEventListener('selectionchange', measureEventEnd, true);
94
+ window.removeEventListener('beforeinput', beforeInputHandler, true);
95
+ window.removeEventListener('paste', pasteHandler, true);
96
+ window.removeEventListener('cut', cutHandler, true);
97
+ };
98
+ }, [report]);
99
+ return null;
100
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import { LexicalCommand } from 'lexical';
9
+ import { type JSX } from 'react';
10
+ export declare const INSERT_YOUTUBE_COMMAND: LexicalCommand<string>;
11
+ export default function YouTubePlugin(): JSX.Element | null;