@datalayer/lexical-loro 0.2.4 → 0.2.5

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 (399) hide show
  1. package/lib/App.d.ts +2 -0
  2. package/lib/App.js +141 -0
  3. package/lib/Editor.d.ts +2 -0
  4. package/lib/Editor.js +115 -0
  5. package/lib/Settings.d.ts +2 -0
  6. package/lib/Settings.js +57 -0
  7. package/lib/appSettings.d.ts +36 -0
  8. package/lib/appSettings.js +48 -0
  9. package/lib/collab/loro/Bindings.d.ts +41 -0
  10. package/lib/collab/loro/Bindings.js +99 -0
  11. package/lib/collab/loro/Debug.d.ts +33 -0
  12. package/lib/collab/loro/Debug.js +452 -0
  13. package/lib/collab/loro/LexicalCollaborationContext.d.ts +19 -0
  14. package/lib/collab/loro/LexicalCollaborationContext.js +52 -0
  15. package/lib/collab/loro/LexicalCollaborationPlugin.d.ts +24 -0
  16. package/lib/collab/loro/LexicalCollaborationPlugin.js +83 -0
  17. package/lib/collab/loro/State.d.ts +53 -0
  18. package/lib/collab/loro/State.js +94 -0
  19. package/lib/collab/loro/components/LoroCollaborationUI.d.ts +13 -0
  20. package/lib/collab/loro/components/LoroCollaborationUI.js +9 -0
  21. package/lib/collab/loro/components/LoroCollaborators.d.ts +8 -0
  22. package/lib/collab/loro/components/LoroCollaborators.js +102 -0
  23. package/lib/collab/loro/components/index.d.ts +2 -0
  24. package/lib/collab/loro/components/index.js +6 -0
  25. package/lib/collab/loro/index.d.ts +6 -0
  26. package/lib/collab/loro/index.js +10 -0
  27. package/lib/collab/loro/integrators/BaseIntegrator.d.ts +14 -0
  28. package/lib/collab/loro/integrators/BaseIntegrator.js +5 -0
  29. package/lib/collab/loro/integrators/CounterIntegrator.d.ts +23 -0
  30. package/lib/collab/loro/integrators/CounterIntegrator.js +44 -0
  31. package/lib/collab/loro/integrators/ListIntegrator.d.ts +23 -0
  32. package/lib/collab/loro/integrators/ListIntegrator.js +53 -0
  33. package/lib/collab/loro/integrators/MapIntegrator.d.ts +24 -0
  34. package/lib/collab/loro/integrators/MapIntegrator.js +235 -0
  35. package/lib/collab/loro/integrators/TextIntegrator.d.ts +25 -0
  36. package/lib/collab/loro/integrators/TextIntegrator.js +55 -0
  37. package/lib/collab/loro/integrators/TreeIntegrator.d.ts +36 -0
  38. package/lib/collab/loro/integrators/TreeIntegrator.js +251 -0
  39. package/lib/collab/loro/nodes/NodeFactory.d.ts +15 -0
  40. package/lib/collab/loro/nodes/NodeFactory.js +101 -0
  41. package/lib/collab/loro/nodes/NodesMapper.d.ts +120 -0
  42. package/lib/collab/loro/nodes/NodesMapper.js +277 -0
  43. package/lib/collab/loro/propagators/DecoratorNodePropagator.d.ts +60 -0
  44. package/lib/collab/loro/propagators/DecoratorNodePropagator.js +306 -0
  45. package/lib/collab/loro/propagators/ElementNodePropagator.d.ts +62 -0
  46. package/lib/collab/loro/propagators/ElementNodePropagator.js +326 -0
  47. package/lib/collab/loro/propagators/LineBreakNodePropagator.d.ts +57 -0
  48. package/lib/collab/loro/propagators/LineBreakNodePropagator.js +200 -0
  49. package/lib/collab/loro/propagators/RootNodePropagator.d.ts +55 -0
  50. package/lib/collab/loro/propagators/RootNodePropagator.js +174 -0
  51. package/lib/collab/loro/propagators/TextNodePropagator.d.ts +60 -0
  52. package/lib/collab/loro/propagators/TextNodePropagator.js +440 -0
  53. package/lib/collab/loro/propagators/index.d.ts +49 -0
  54. package/lib/collab/loro/propagators/index.js +30 -0
  55. package/lib/collab/loro/provider/websocket.d.ts +116 -0
  56. package/lib/collab/loro/provider/websocket.js +911 -0
  57. package/lib/collab/loro/servers/index.d.ts +0 -0
  58. package/lib/collab/loro/servers/index.js +4 -0
  59. package/lib/collab/loro/servers/ws/callback.d.ts +5 -0
  60. package/lib/collab/loro/servers/ws/callback.js +89 -0
  61. package/lib/collab/loro/servers/ws/server.d.ts +2 -0
  62. package/lib/collab/loro/servers/ws/server.js +29 -0
  63. package/lib/collab/loro/servers/ws/utils.d.ts +40 -0
  64. package/lib/collab/loro/servers/ws/utils.js +517 -0
  65. package/lib/collab/loro/sync/SyncCursors.d.ts +32 -0
  66. package/lib/collab/loro/sync/SyncCursors.js +475 -0
  67. package/lib/collab/loro/sync/SyncLexicalToLoro.d.ts +4 -0
  68. package/lib/collab/loro/sync/SyncLexicalToLoro.js +113 -0
  69. package/lib/collab/loro/sync/SyncLoroToLexical.d.ts +5 -0
  70. package/lib/collab/loro/sync/SyncLoroToLexical.js +100 -0
  71. package/lib/collab/loro/types/LexicalNodeData.d.ts +32 -0
  72. package/lib/collab/loro/types/LexicalNodeData.js +75 -0
  73. package/lib/collab/loro/useCollaboration.d.ts +12 -0
  74. package/lib/collab/loro/useCollaboration.js +260 -0
  75. package/lib/collab/loro/utils/InitialContent.d.ts +64 -0
  76. package/lib/collab/loro/utils/InitialContent.js +113 -0
  77. package/lib/collab/loro/utils/LexicalToLoro.d.ts +18 -0
  78. package/lib/collab/loro/utils/LexicalToLoro.js +100 -0
  79. package/lib/collab/loro/utils/Utils.d.ts +44 -0
  80. package/lib/collab/loro/utils/Utils.js +157 -0
  81. package/lib/collab/loro/wsProvider.d.ts +8 -0
  82. package/lib/collab/loro/wsProvider.js +35 -0
  83. package/lib/collab/utils/invariant.d.ts +1 -0
  84. package/lib/collab/utils/invariant.js +15 -0
  85. package/lib/collab/utils/simpleDiffWithCursor.d.ts +5 -0
  86. package/lib/collab/utils/simpleDiffWithCursor.js +35 -0
  87. package/lib/collab/yjs/Bindings.d.ts +23 -0
  88. package/lib/collab/yjs/Bindings.js +26 -0
  89. package/lib/collab/yjs/Debug.d.ts +23 -0
  90. package/lib/collab/yjs/Debug.js +213 -0
  91. package/lib/collab/yjs/LexicalCollaborationContext.d.ts +10 -0
  92. package/lib/collab/yjs/LexicalCollaborationContext.js +37 -0
  93. package/lib/collab/yjs/LexicalCollaborationPlugin.d.ts +21 -0
  94. package/lib/collab/yjs/LexicalCollaborationPlugin.js +63 -0
  95. package/lib/collab/yjs/State.d.ts +51 -0
  96. package/lib/collab/yjs/State.js +35 -0
  97. package/lib/collab/yjs/nodes/AnyCollabNode.d.ts +5 -0
  98. package/lib/collab/yjs/nodes/AnyCollabNode.js +1 -0
  99. package/lib/collab/yjs/nodes/CollabDecoratorNode.d.ts +22 -0
  100. package/lib/collab/yjs/nodes/CollabDecoratorNode.js +64 -0
  101. package/lib/collab/yjs/nodes/CollabElementNode.d.ts +40 -0
  102. package/lib/collab/yjs/nodes/CollabElementNode.js +462 -0
  103. package/lib/collab/yjs/nodes/CollabLineBreakNode.d.ts +19 -0
  104. package/lib/collab/yjs/nodes/CollabLineBreakNode.js +44 -0
  105. package/lib/collab/yjs/nodes/CollabTextNode.d.ts +25 -0
  106. package/lib/collab/yjs/nodes/CollabTextNode.js +103 -0
  107. package/lib/collab/yjs/provider/websocket.d.ts +88 -0
  108. package/lib/collab/yjs/provider/websocket.js +415 -0
  109. package/lib/collab/yjs/servers/index.d.ts +0 -0
  110. package/lib/collab/yjs/servers/index.js +0 -0
  111. package/lib/collab/yjs/servers/ws/callback.d.ts +5 -0
  112. package/lib/collab/yjs/servers/ws/callback.js +72 -0
  113. package/lib/collab/yjs/servers/ws/server.d.ts +2 -0
  114. package/lib/collab/yjs/servers/ws/server.js +25 -0
  115. package/lib/collab/yjs/servers/ws/utils.d.ts +49 -0
  116. package/lib/collab/yjs/servers/ws/utils.js +284 -0
  117. package/lib/collab/yjs/sync/SyncCursors.d.ts +39 -0
  118. package/lib/collab/yjs/sync/SyncCursors.js +351 -0
  119. package/lib/collab/yjs/sync/SyncEditorStates.d.ts +10 -0
  120. package/lib/collab/yjs/sync/SyncEditorStates.js +200 -0
  121. package/lib/collab/yjs/useCollaboration.d.ts +12 -0
  122. package/lib/collab/yjs/useCollaboration.js +255 -0
  123. package/lib/collab/yjs/utils/Utils.d.ts +25 -0
  124. package/lib/collab/yjs/utils/Utils.js +402 -0
  125. package/lib/collab/yjs/wsProvider.d.ts +3 -0
  126. package/lib/collab/yjs/wsProvider.js +21 -0
  127. package/lib/commenting/index.d.ts +41 -0
  128. package/lib/commenting/index.js +328 -0
  129. package/lib/context/FlashMessageContext.d.ts +7 -0
  130. package/lib/context/FlashMessageContext.js +24 -0
  131. package/lib/context/SettingsContext.d.ts +12 -0
  132. package/lib/context/SettingsContext.js +38 -0
  133. package/lib/context/SharedHistoryContext.d.ts +11 -0
  134. package/lib/context/SharedHistoryContext.js +11 -0
  135. package/lib/context/ToolbarContext.d.ts +65 -0
  136. package/lib/context/ToolbarContext.js +84 -0
  137. package/lib/demo.d.ts +12 -0
  138. package/lib/demo.js +45 -0
  139. package/lib/hooks/useFlashMessage.d.ts +2 -0
  140. package/lib/hooks/useFlashMessage.js +8 -0
  141. package/lib/hooks/useModal.d.ts +5 -0
  142. package/lib/hooks/useModal.js +26 -0
  143. package/lib/hooks/useReport.d.ts +1 -0
  144. package/lib/hooks/useReport.js +50 -0
  145. package/lib/index.d.ts +1 -0
  146. package/lib/index.js +5 -0
  147. package/lib/nodes/AutocompleteNode.d.ts +27 -0
  148. package/lib/nodes/AutocompleteNode.js +60 -0
  149. package/lib/nodes/CounterComponent.d.ts +6 -0
  150. package/lib/nodes/CounterComponent.js +137 -0
  151. package/lib/nodes/CounterNode.d.ts +23 -0
  152. package/lib/nodes/CounterNode.js +47 -0
  153. package/lib/nodes/DateTimeNode/DateTimeComponent.d.ts +8 -0
  154. package/lib/nodes/DateTimeNode/DateTimeComponent.js +119 -0
  155. package/lib/nodes/DateTimeNode/DateTimeNode.d.ts +27 -0
  156. package/lib/nodes/DateTimeNode/DateTimeNode.js +82 -0
  157. package/lib/nodes/EmojiNode.d.ts +18 -0
  158. package/lib/nodes/EmojiNode.js +54 -0
  159. package/lib/nodes/EquationComponent.d.ts +9 -0
  160. package/lib/nodes/EquationComponent.js +75 -0
  161. package/lib/nodes/EquationNode.d.ts +26 -0
  162. package/lib/nodes/EquationNode.js +109 -0
  163. package/lib/nodes/ExcalidrawNode/ExcalidrawComponent.d.ts +8 -0
  164. package/lib/nodes/ExcalidrawNode/ExcalidrawComponent.js +110 -0
  165. package/lib/nodes/ExcalidrawNode/ExcalidrawImage.d.ts +50 -0
  166. package/lib/nodes/ExcalidrawNode/ExcalidrawImage.js +55 -0
  167. package/lib/nodes/ExcalidrawNode/index.d.ts +32 -0
  168. package/lib/nodes/ExcalidrawNode/index.js +117 -0
  169. package/lib/nodes/FigmaNode.d.ts +20 -0
  170. package/lib/nodes/FigmaNode.js +52 -0
  171. package/lib/nodes/ImageComponent.d.ts +16 -0
  172. package/lib/nodes/ImageComponent.js +272 -0
  173. package/lib/nodes/ImageNode.d.ts +50 -0
  174. package/lib/nodes/ImageNode.js +151 -0
  175. package/lib/nodes/InlineImageNode/InlineImageComponent.d.ts +26 -0
  176. package/lib/nodes/InlineImageNode/InlineImageComponent.js +161 -0
  177. package/lib/nodes/InlineImageNode/InlineImageNode.d.ts +59 -0
  178. package/lib/nodes/InlineImageNode/InlineImageNode.js +162 -0
  179. package/lib/nodes/KeywordNode.d.ts +14 -0
  180. package/lib/nodes/KeywordNode.js +37 -0
  181. package/lib/nodes/LayoutContainerNode.d.ts +24 -0
  182. package/lib/nodes/LayoutContainerNode.js +95 -0
  183. package/lib/nodes/LayoutItemNode.d.ts +16 -0
  184. package/lib/nodes/LayoutItemNode.js +69 -0
  185. package/lib/nodes/MentionNode.d.ts +20 -0
  186. package/lib/nodes/MentionNode.js +85 -0
  187. package/lib/nodes/PageBreakNode/index.d.ts +17 -0
  188. package/lib/nodes/PageBreakNode/index.js +83 -0
  189. package/lib/nodes/PlaygroundNodes.d.ts +3 -0
  190. package/lib/nodes/PlaygroundNodes.js +75 -0
  191. package/lib/nodes/PollComponent.d.ts +9 -0
  192. package/lib/nodes/PollComponent.js +85 -0
  193. package/lib/nodes/PollNode.d.ts +43 -0
  194. package/lib/nodes/PollNode.js +153 -0
  195. package/lib/nodes/SpecialTextNode.d.ts +24 -0
  196. package/lib/nodes/SpecialTextNode.js +54 -0
  197. package/lib/nodes/StickyComponent.d.ts +10 -0
  198. package/lib/nodes/StickyComponent.js +162 -0
  199. package/lib/nodes/StickyNode.d.ts +31 -0
  200. package/lib/nodes/StickyNode.js +76 -0
  201. package/lib/nodes/TweetNode.d.ts +21 -0
  202. package/lib/nodes/TweetNode.js +119 -0
  203. package/lib/nodes/YouTubeNode.d.ts +22 -0
  204. package/lib/nodes/YouTubeNode.js +84 -0
  205. package/lib/plugins/ActionsPlugin/index.d.ts +5 -0
  206. package/lib/plugins/ActionsPlugin/index.js +168 -0
  207. package/lib/plugins/AutoEmbedPlugin/index.d.ts +19 -0
  208. package/lib/plugins/AutoEmbedPlugin/index.js +158 -0
  209. package/lib/plugins/AutoLinkPlugin/index.d.ts +2 -0
  210. package/lib/plugins/AutoLinkPlugin/index.js +15 -0
  211. package/lib/plugins/AutocompletePlugin/index.d.ts +10 -0
  212. package/lib/plugins/AutocompletePlugin/index.js +2477 -0
  213. package/lib/plugins/CodeActionMenuPlugin/components/CopyButton/index.d.ts +7 -0
  214. package/lib/plugins/CodeActionMenuPlugin/components/CopyButton/index.js +46 -0
  215. package/lib/plugins/CodeActionMenuPlugin/components/PrettierButton/index.d.ts +17 -0
  216. package/lib/plugins/CodeActionMenuPlugin/components/PrettierButton/index.js +115 -0
  217. package/lib/plugins/CodeActionMenuPlugin/index.d.ts +5 -0
  218. package/lib/plugins/CodeActionMenuPlugin/index.js +104 -0
  219. package/lib/plugins/CodeActionMenuPlugin/utils.d.ts +1 -0
  220. package/lib/plugins/CodeActionMenuPlugin/utils.js +22 -0
  221. package/lib/plugins/CodeHighlightPrismPlugin/index.d.ts +2 -0
  222. package/lib/plugins/CodeHighlightPrismPlugin/index.js +14 -0
  223. package/lib/plugins/CodeHighlightShikiPlugin/index.d.ts +2 -0
  224. package/lib/plugins/CodeHighlightShikiPlugin/index.js +14 -0
  225. package/lib/plugins/CollapsiblePlugin/CollapsibleContainerNode.d.ts +25 -0
  226. package/lib/plugins/CollapsiblePlugin/CollapsibleContainerNode.js +135 -0
  227. package/lib/plugins/CollapsiblePlugin/CollapsibleContentNode.d.ts +16 -0
  228. package/lib/plugins/CollapsiblePlugin/CollapsibleContentNode.js +83 -0
  229. package/lib/plugins/CollapsiblePlugin/CollapsibleTitleNode.d.ts +16 -0
  230. package/lib/plugins/CollapsiblePlugin/CollapsibleTitleNode.js +85 -0
  231. package/lib/plugins/CollapsiblePlugin/CollapsibleUtils.d.ts +2 -0
  232. package/lib/plugins/CollapsiblePlugin/CollapsibleUtils.js +12 -0
  233. package/lib/plugins/CollapsiblePlugin/index.d.ts +3 -0
  234. package/lib/plugins/CollapsiblePlugin/index.js +132 -0
  235. package/lib/plugins/CommentPlugin/index.d.ts +9 -0
  236. package/lib/plugins/CommentPlugin/index.js +460 -0
  237. package/lib/plugins/ComponentPickerPlugin/index.d.ts +2 -0
  238. package/lib/plugins/ComponentPickerPlugin/index.js +276 -0
  239. package/lib/plugins/ContextMenuPlugin/index.d.ts +2 -0
  240. package/lib/plugins/ContextMenuPlugin/index.js +112 -0
  241. package/lib/plugins/CounterPlugin/index.d.ts +3 -0
  242. package/lib/plugins/CounterPlugin/index.js +24 -0
  243. package/lib/plugins/DateTimePlugin/index.d.ts +8 -0
  244. package/lib/plugins/DateTimePlugin/index.js +28 -0
  245. package/lib/plugins/DebugPlugin/index.d.ts +3 -0
  246. package/lib/plugins/DebugPlugin/index.js +219 -0
  247. package/lib/plugins/DocsPlugin/index.d.ts +2 -0
  248. package/lib/plugins/DocsPlugin/index.js +4 -0
  249. package/lib/plugins/DragDropPastePlugin/index.d.ts +1 -0
  250. package/lib/plugins/DragDropPastePlugin/index.js +37 -0
  251. package/lib/plugins/DraggableBlockPlugin/index.d.ts +12 -0
  252. package/lib/plugins/DraggableBlockPlugin/index.js +36 -0
  253. package/lib/plugins/EmojiPickerPlugin/index.d.ts +1 -0
  254. package/lib/plugins/EmojiPickerPlugin/index.js +84 -0
  255. package/lib/plugins/EmojisPlugin/index.d.ts +2 -0
  256. package/lib/plugins/EmojisPlugin/index.js +56 -0
  257. package/lib/plugins/EquationsPlugin/index.d.ts +14 -0
  258. package/lib/plugins/EquationsPlugin/index.js +34 -0
  259. package/lib/plugins/ExcalidrawPlugin/index.d.ts +5 -0
  260. package/lib/plugins/ExcalidrawPlugin/index.js +44 -0
  261. package/lib/plugins/FigmaPlugin/index.d.ts +4 -0
  262. package/lib/plugins/FigmaPlugin/index.js +24 -0
  263. package/lib/plugins/FloatingLinkEditorPlugin/index.d.ts +15 -0
  264. package/lib/plugins/FloatingLinkEditorPlugin/index.js +280 -0
  265. package/lib/plugins/FloatingTextFormatToolbarPlugin/index.d.ts +7 -0
  266. package/lib/plugins/FloatingTextFormatToolbarPlugin/index.js +219 -0
  267. package/lib/plugins/ImagesPlugin/index.d.ts +24 -0
  268. package/lib/plugins/ImagesPlugin/index.js +195 -0
  269. package/lib/plugins/InlineImagePlugin/index.d.ts +17 -0
  270. package/lib/plugins/InlineImagePlugin/index.js +180 -0
  271. package/lib/plugins/KeywordsPlugin/index.d.ts +2 -0
  272. package/lib/plugins/KeywordsPlugin/index.js +35 -0
  273. package/lib/plugins/LayoutPlugin/InsertLayoutDialog.d.ts +6 -0
  274. package/lib/plugins/LayoutPlugin/InsertLayoutDialog.js +21 -0
  275. package/lib/plugins/LayoutPlugin/LayoutPlugin.d.ts +7 -0
  276. package/lib/plugins/LayoutPlugin/LayoutPlugin.js +135 -0
  277. package/lib/plugins/LinkPlugin/index.d.ts +6 -0
  278. package/lib/plugins/LinkPlugin/index.js +11 -0
  279. package/lib/plugins/MarkdownShortcutPlugin/index.d.ts +2 -0
  280. package/lib/plugins/MarkdownShortcutPlugin/index.js +6 -0
  281. package/lib/plugins/MarkdownTransformers/index.d.ts +8 -0
  282. package/lib/plugins/MarkdownTransformers/index.js +238 -0
  283. package/lib/plugins/MaxLengthPlugin/index.d.ts +3 -0
  284. package/lib/plugins/MaxLengthPlugin/index.js +41 -0
  285. package/lib/plugins/MentionsPlugin/index.d.ts +2 -0
  286. package/lib/plugins/MentionsPlugin/index.js +564 -0
  287. package/lib/plugins/PageBreakPlugin/index.d.ts +4 -0
  288. package/lib/plugins/PageBreakPlugin/index.js +31 -0
  289. package/lib/plugins/PasteLogPlugin/index.d.ts +2 -0
  290. package/lib/plugins/PasteLogPlugin/index.js +27 -0
  291. package/lib/plugins/PollPlugin/index.d.ts +8 -0
  292. package/lib/plugins/PollPlugin/index.js +38 -0
  293. package/lib/plugins/ShortcutsPlugin/index.d.ts +6 -0
  294. package/lib/plugins/ShortcutsPlugin/index.js +116 -0
  295. package/lib/plugins/ShortcutsPlugin/shortcuts.d.ts +59 -0
  296. package/lib/plugins/ShortcutsPlugin/shortcuts.js +173 -0
  297. package/lib/plugins/SpecialTextPlugin/index.d.ts +2 -0
  298. package/lib/plugins/SpecialTextPlugin/index.js +50 -0
  299. package/lib/plugins/SpeechToTextPlugin/index.d.ts +5 -0
  300. package/lib/plugins/SpeechToTextPlugin/index.js +86 -0
  301. package/lib/plugins/StickyPlugin/index.d.ts +2 -0
  302. package/lib/plugins/StickyPlugin/index.js +16 -0
  303. package/lib/plugins/TabFocusPlugin/index.d.ts +1 -0
  304. package/lib/plugins/TabFocusPlugin/index.js +38 -0
  305. package/lib/plugins/TableActionMenuPlugin/index.d.ts +5 -0
  306. package/lib/plugins/TableActionMenuPlugin/index.js +492 -0
  307. package/lib/plugins/TableCellResizer/index.d.ts +3 -0
  308. package/lib/plugins/TableCellResizer/index.js +297 -0
  309. package/lib/plugins/TableHoverActionsPlugin/index.d.ts +4 -0
  310. package/lib/plugins/TableHoverActionsPlugin/index.js +188 -0
  311. package/lib/plugins/TableOfContentsPlugin/index.d.ts +2 -0
  312. package/lib/plugins/TableOfContentsPlugin/index.js +116 -0
  313. package/lib/plugins/TablePlugin.d.ts +31 -0
  314. package/lib/plugins/TablePlugin.js +63 -0
  315. package/lib/plugins/TestRecorderPlugin/index.d.ts +3 -0
  316. package/lib/plugins/TestRecorderPlugin/index.js +346 -0
  317. package/lib/plugins/ToolbarPlugin/fontSize.d.ts +9 -0
  318. package/lib/plugins/ToolbarPlugin/fontSize.js +84 -0
  319. package/lib/plugins/ToolbarPlugin/index.d.ts +9 -0
  320. package/lib/plugins/ToolbarPlugin/index.js +500 -0
  321. package/lib/plugins/ToolbarPlugin/utils.d.ts +26 -0
  322. package/lib/plugins/ToolbarPlugin/utils.js +247 -0
  323. package/lib/plugins/TreeViewPlugin/index.d.ts +2 -0
  324. package/lib/plugins/TreeViewPlugin/index.js +7 -0
  325. package/lib/plugins/TwitterPlugin/index.d.ts +4 -0
  326. package/lib/plugins/TwitterPlugin/index.js +24 -0
  327. package/lib/plugins/TypingPerfPlugin/index.d.ts +2 -0
  328. package/lib/plugins/TypingPerfPlugin/index.js +97 -0
  329. package/lib/plugins/YouTubePlugin/index.d.ts +4 -0
  330. package/lib/plugins/YouTubePlugin/index.js +24 -0
  331. package/lib/server/validation.d.ts +1 -0
  332. package/lib/server/validation.js +115 -0
  333. package/lib/setupEnv.d.ts +2 -0
  334. package/lib/setupEnv.js +29 -0
  335. package/lib/themes/CommentEditorTheme.d.ts +4 -0
  336. package/lib/themes/CommentEditorTheme.js +11 -0
  337. package/lib/themes/PlaygroundEditorTheme.d.ts +4 -0
  338. package/lib/themes/PlaygroundEditorTheme.js +124 -0
  339. package/lib/themes/StickyEditorTheme.d.ts +4 -0
  340. package/lib/themes/StickyEditorTheme.js +11 -0
  341. package/lib/tyes.dt.d.ts +12 -0
  342. package/lib/tyes.dt.js +4 -0
  343. package/lib/ui/Button.d.ts +12 -0
  344. package/lib/ui/Button.js +6 -0
  345. package/lib/ui/ColorPicker.d.ts +14 -0
  346. package/lib/ui/ColorPicker.js +219 -0
  347. package/lib/ui/ContentEditable.d.ts +9 -0
  348. package/lib/ui/ContentEditable.js +6 -0
  349. package/lib/ui/Dialog.d.ts +10 -0
  350. package/lib/ui/Dialog.js +8 -0
  351. package/lib/ui/DropDown.d.ts +18 -0
  352. package/lib/ui/DropDown.js +133 -0
  353. package/lib/ui/DropdownColorPicker.d.ts +13 -0
  354. package/lib/ui/DropdownColorPicker.js +6 -0
  355. package/lib/ui/EquationEditor.d.ts +8 -0
  356. package/lib/ui/EquationEditor.js +11 -0
  357. package/lib/ui/ExcalidrawModal.d.ts +42 -0
  358. package/lib/ui/ExcalidrawModal.js +103 -0
  359. package/lib/ui/FileInput.d.ts +10 -0
  360. package/lib/ui/FileInput.js +5 -0
  361. package/lib/ui/FlashMessage.d.ts +7 -0
  362. package/lib/ui/FlashMessage.js +6 -0
  363. package/lib/ui/ImageResizer.d.ts +17 -0
  364. package/lib/ui/ImageResizer.js +171 -0
  365. package/lib/ui/KatexEquationAlterer.d.ts +8 -0
  366. package/lib/ui/KatexEquationAlterer.js +23 -0
  367. package/lib/ui/KatexRenderer.d.ts +6 -0
  368. package/lib/ui/KatexRenderer.js +24 -0
  369. package/lib/ui/Modal.d.ts +9 -0
  370. package/lib/ui/Modal.js +48 -0
  371. package/lib/ui/Select.d.ts +8 -0
  372. package/lib/ui/Select.js +5 -0
  373. package/lib/ui/Switch.d.ts +8 -0
  374. package/lib/ui/Switch.js +6 -0
  375. package/lib/ui/TextInput.d.ts +13 -0
  376. package/lib/ui/TextInput.js +7 -0
  377. package/lib/utils/docSerialization.d.ts +3 -0
  378. package/lib/utils/docSerialization.js +60 -0
  379. package/lib/utils/emoji-list.d.ts +20 -0
  380. package/lib/utils/emoji-list.js +16609 -0
  381. package/lib/utils/getDOMRangeRect.d.ts +8 -0
  382. package/lib/utils/getDOMRangeRect.js +26 -0
  383. package/lib/utils/getSelectedNode.d.ts +2 -0
  384. package/lib/utils/getSelectedNode.js +28 -0
  385. package/lib/utils/getThemeSelector.d.ts +2 -0
  386. package/lib/utils/getThemeSelector.js +14 -0
  387. package/lib/utils/isMobileWidth.d.ts +7 -0
  388. package/lib/utils/isMobileWidth.js +11 -0
  389. package/lib/utils/joinClasses.d.ts +1 -0
  390. package/lib/utils/joinClasses.js +7 -0
  391. package/lib/utils/setFloatingElemPosition.d.ts +1 -0
  392. package/lib/utils/setFloatingElemPosition.js +59 -0
  393. package/lib/utils/setFloatingElemPositionForLinkEditor.d.ts +1 -0
  394. package/lib/utils/setFloatingElemPositionForLinkEditor.js +36 -0
  395. package/lib/utils/swipe.d.ts +4 -0
  396. package/lib/utils/swipe.js +94 -0
  397. package/lib/utils/url.d.ts +2 -0
  398. package/lib/utils/url.js +31 -0
  399. package/package.json +1 -1
@@ -0,0 +1,284 @@
1
+ import * as Y from 'yjs';
2
+ import * as syncProtocol from 'y-protocols/sync';
3
+ import * as awarenessProtocol from 'y-protocols/awareness';
4
+ import * as encoding from 'lib0/encoding';
5
+ import * as decoding from 'lib0/decoding';
6
+ import * as map from 'lib0/map';
7
+ import * as eventloop from 'lib0/eventloop';
8
+ import * as yleveldb from 'y-leveldb';
9
+ import { callbackIntegrator, isCallbackSet } from './callback';
10
+ const CALLBACK_DEBOUNCE_WAIT = parseInt(process.env.CALLBACK_DEBOUNCE_WAIT || '2000');
11
+ const CALLBACK_DEBOUNCE_MAXWAIT = parseInt(process.env.CALLBACK_DEBOUNCE_MAXWAIT || '10000');
12
+ const debouncer = eventloop.createDebouncer(CALLBACK_DEBOUNCE_WAIT, CALLBACK_DEBOUNCE_MAXWAIT);
13
+ const wsReadyStateConnecting = 0;
14
+ const wsReadyStateOpen = 1;
15
+ const wsReadyStateClosing = 2; // eslint-disable-line
16
+ const wsReadyStateClosed = 3; // eslint-disable-line
17
+ // disable gc when using snapshots!
18
+ const gcEnabled = process.env.GC !== 'false' && process.env.GC !== '0';
19
+ const persistenceDir = process.env.YPERSISTENCE;
20
+ /**
21
+ * @type {{bindState: function(string,WSSharedDoc):void, writeState:function(string,WSSharedDoc):Promise<any>, provider: any}|null}
22
+ */
23
+ let persistence = null;
24
+ if (typeof persistenceDir === 'string') {
25
+ console.info('Persisting documents to "' + persistenceDir + '"');
26
+ // @ts-ignore
27
+ const ldb = new yleveldb.LeveldbPersistence(persistenceDir);
28
+ persistence = {
29
+ provider: ldb,
30
+ bindState: async (docName, ydoc) => {
31
+ const persistedYdoc = await ldb.getYDoc(docName);
32
+ const newUpdates = Y.encodeStateAsUpdate(ydoc);
33
+ ldb.storeUpdate(docName, newUpdates);
34
+ Y.applyUpdate(ydoc, Y.encodeStateAsUpdate(persistedYdoc));
35
+ ydoc.on('update', update => {
36
+ ldb.storeUpdate(docName, update);
37
+ });
38
+ },
39
+ writeState: async (docName, ydoc) => { }
40
+ };
41
+ }
42
+ /**
43
+ * @param {{bindState: function(string,WSSharedDoc):void,
44
+ * writeState:function(string,WSSharedDoc):Promise<any>,provider:any}|null} persistence_
45
+ */
46
+ export const setPersistence = persistence_ => {
47
+ persistence = persistence_;
48
+ };
49
+ /**
50
+ * @return {null|{bindState: function(string,WSSharedDoc):void,
51
+ * writeState:function(string,WSSharedDoc):Promise<any>}|null} used persistence layer
52
+ */
53
+ export const getPersistence = () => persistence;
54
+ /**
55
+ * @type {Map<string,WSSharedDoc>}
56
+ */
57
+ export const docs = new Map();
58
+ const messageSync = 0;
59
+ const messageAwareness = 1;
60
+ // const messageAuth = 2
61
+ /**
62
+ * @param {Uint8Array} update
63
+ * @param {any} _origin
64
+ * @param {WSSharedDoc} doc
65
+ * @param {any} _tr
66
+ */
67
+ const updateIntegrator = (update, _origin, doc, _tr) => {
68
+ const encoder = encoding.createEncoder();
69
+ encoding.writeVarUint(encoder, messageSync);
70
+ syncProtocol.writeUpdate(encoder, update);
71
+ const message = encoding.toUint8Array(encoder);
72
+ doc.conns.forEach((_, conn) => send(doc, conn, message));
73
+ };
74
+ /**
75
+ * @type {(ydoc: Y.Doc) => Promise<void>}
76
+ */
77
+ let contentInitializor = _ydoc => Promise.resolve();
78
+ /**
79
+ * This function is called once every time a Yjs document is created. You can
80
+ * use it to pull data from an external source or initialize content.
81
+ *
82
+ * @param {(ydoc: Y.Doc) => Promise<void>} f
83
+ */
84
+ export const setContentInitializor = (f) => {
85
+ contentInitializor = f;
86
+ };
87
+ export class WSSharedDoc extends Y.Doc {
88
+ name = '';
89
+ conns = null;
90
+ awareness = null;
91
+ whenInitialized = null;
92
+ /**
93
+ * @param {string} name
94
+ */
95
+ constructor(name) {
96
+ super({ gc: gcEnabled });
97
+ this.name = name;
98
+ /**
99
+ * Maps from conn to set of controlled user ids. Delete all user ids from awareness when this conn is closed
100
+ * @type {Map<Object, Set<number>>}
101
+ */
102
+ this.conns = new Map();
103
+ /**
104
+ * @type {awarenessProtocol.Awareness}
105
+ */
106
+ this.awareness = new awarenessProtocol.Awareness(this);
107
+ this.awareness.setLocalState(null);
108
+ /**
109
+ * @param {{ added: Array<number>, updated: Array<number>, removed: Array<number> }} changes
110
+ * @param {Object | null} conn Origin is the connection that made the change
111
+ */
112
+ const awarenessChangeIntegrator = ({ added, updated, removed }, conn) => {
113
+ const changedClients = added.concat(updated, removed);
114
+ if (conn !== null) {
115
+ const connControlledIDs = /** @type {Set<number>} */ (this.conns.get(conn));
116
+ if (connControlledIDs !== undefined) {
117
+ added.forEach(clientID => { connControlledIDs.add(clientID); });
118
+ removed.forEach(clientID => { connControlledIDs.delete(clientID); });
119
+ }
120
+ }
121
+ // broadcast awareness update
122
+ const encoder = encoding.createEncoder();
123
+ encoding.writeVarUint(encoder, messageAwareness);
124
+ encoding.writeVarUint8Array(encoder, awarenessProtocol.encodeAwarenessUpdate(this.awareness, changedClients));
125
+ const buff = encoding.toUint8Array(encoder);
126
+ this.conns.forEach((_, c) => {
127
+ send(this, c, buff);
128
+ });
129
+ };
130
+ this.awareness.on('update', awarenessChangeIntegrator);
131
+ this.on('update', /** @type {any} */ (updateIntegrator));
132
+ if (isCallbackSet) {
133
+ this.on('update', (_update, _origin, doc) => {
134
+ debouncer(() => callbackIntegrator(/** @type {WSSharedDoc} */ (doc)));
135
+ });
136
+ }
137
+ this.whenInitialized = contentInitializor(this);
138
+ }
139
+ }
140
+ /**
141
+ * Gets a Y.Doc by name, whether in memory or on disk
142
+ *
143
+ * @param {string} docname - the name of the Y.Doc to find or create
144
+ * @param {boolean} gc - whether to allow gc on the doc (applies only when created)
145
+ * @return {WSSharedDoc}
146
+ */
147
+ export const getYDoc = (docname, gc = true) => map.setIfUndefined(docs, docname, () => {
148
+ const doc = new WSSharedDoc(docname);
149
+ doc.gc = gc;
150
+ if (persistence !== null) {
151
+ persistence.bindState(docname, doc);
152
+ }
153
+ docs.set(docname, doc);
154
+ return doc;
155
+ });
156
+ /**
157
+ * @param {any} conn
158
+ * @param {WSSharedDoc} doc
159
+ * @param {Uint8Array} message
160
+ */
161
+ const messageListener = (conn, doc, message) => {
162
+ try {
163
+ const encoder = encoding.createEncoder();
164
+ const decoder = decoding.createDecoder(message);
165
+ const messageType = decoding.readVarUint(decoder);
166
+ switch (messageType) {
167
+ case messageSync:
168
+ encoding.writeVarUint(encoder, messageSync);
169
+ syncProtocol.readSyncMessage(decoder, encoder, doc, conn);
170
+ // If the `encoder` only contains the type of reply message and no
171
+ // message, there is no need to send the message. When `encoder` only
172
+ // contains the type of reply, its length is 1.
173
+ if (encoding.length(encoder) > 1) {
174
+ send(doc, conn, encoding.toUint8Array(encoder));
175
+ }
176
+ break;
177
+ case messageAwareness: {
178
+ awarenessProtocol.applyAwarenessUpdate(doc.awareness, decoding.readVarUint8Array(decoder), conn);
179
+ break;
180
+ }
181
+ }
182
+ }
183
+ catch (err) {
184
+ console.error(err);
185
+ // @ts-ignore
186
+ doc.emit('error', [err]);
187
+ }
188
+ };
189
+ /**
190
+ * @param {WSSharedDoc} doc
191
+ * @param {any} conn
192
+ */
193
+ const closeConn = (doc, conn) => {
194
+ if (doc.conns.has(conn)) {
195
+ /**
196
+ * @type {Set<number>}
197
+ */
198
+ // @ts-ignore
199
+ const controlledIds = doc.conns.get(conn);
200
+ doc.conns.delete(conn);
201
+ awarenessProtocol.removeAwarenessStates(doc.awareness, Array.from(controlledIds), null);
202
+ if (doc.conns.size === 0 && persistence !== null) {
203
+ // if persisted, we store state and destroy ydocument
204
+ persistence.writeState(doc.name, doc).then(() => {
205
+ doc.destroy();
206
+ });
207
+ docs.delete(doc.name);
208
+ }
209
+ }
210
+ conn.close();
211
+ };
212
+ /**
213
+ * @param {WSSharedDoc} doc
214
+ * @param {import('ws').WebSocket} conn
215
+ * @param {Uint8Array} m
216
+ */
217
+ const send = (doc, conn, m) => {
218
+ if (conn.readyState !== wsReadyStateConnecting && conn.readyState !== wsReadyStateOpen) {
219
+ closeConn(doc, conn);
220
+ }
221
+ try {
222
+ conn.send(m, {}, err => { err != null && closeConn(doc, conn); });
223
+ }
224
+ catch (e) {
225
+ closeConn(doc, conn);
226
+ }
227
+ };
228
+ const pingTimeout = 30000;
229
+ /**
230
+ * @param {import('ws').WebSocket} conn
231
+ * @param {import('http').IncomingMessage} req
232
+ * @param {any} opts
233
+ */
234
+ export const setupWSConnection = (conn, req, { docName = (req.url || '').slice(1).split('?')[0], gc = true } = {}) => {
235
+ conn.binaryType = 'arraybuffer';
236
+ // get doc, initialize if it does not exist yet
237
+ const doc = getYDoc(docName, gc);
238
+ doc.conns.set(conn, new Set());
239
+ // listen and reply to events
240
+ conn.on('message', /** @param {ArrayBuffer} message */ /** @param {ArrayBuffer} message */ message => messageListener(conn, doc, new Uint8Array(message)));
241
+ // Check if connection is still alive
242
+ let pongReceived = true;
243
+ const pingInterval = setInterval(() => {
244
+ if (!pongReceived) {
245
+ if (doc.conns.has(conn)) {
246
+ closeConn(doc, conn);
247
+ }
248
+ clearInterval(pingInterval);
249
+ }
250
+ else if (doc.conns.has(conn)) {
251
+ pongReceived = false;
252
+ try {
253
+ conn.ping();
254
+ }
255
+ catch (e) {
256
+ closeConn(doc, conn);
257
+ clearInterval(pingInterval);
258
+ }
259
+ }
260
+ }, pingTimeout);
261
+ conn.on('close', () => {
262
+ closeConn(doc, conn);
263
+ clearInterval(pingInterval);
264
+ });
265
+ conn.on('pong', () => {
266
+ pongReceived = true;
267
+ });
268
+ // put the following in a variables in a block so the interval handlers don't keep in in
269
+ // scope
270
+ {
271
+ // send sync step 1
272
+ const encoder = encoding.createEncoder();
273
+ encoding.writeVarUint(encoder, messageSync);
274
+ syncProtocol.writeSyncStep1(encoder, doc);
275
+ send(doc, conn, encoding.toUint8Array(encoder));
276
+ const awarenessStates = doc.awareness.getStates();
277
+ if (awarenessStates.size > 0) {
278
+ const encoder = encoding.createEncoder();
279
+ encoding.writeVarUint(encoder, messageAwareness);
280
+ encoding.writeVarUint8Array(encoder, awarenessProtocol.encodeAwarenessUpdate(doc.awareness, Array.from(awarenessStates.keys())));
281
+ send(doc, conn, encoding.toUint8Array(encoder));
282
+ }
283
+ }
284
+ };
@@ -0,0 +1,39 @@
1
+ import type { BaseSelection, NodeKey } from 'lexical';
2
+ import type { Binding } from '../Bindings';
3
+ import { UserState, Provider } from '../State';
4
+ import { AnyCollabNode } from '../nodes/AnyCollabNode';
5
+ /*****************************************************************************/
6
+ export type CursorSelection = {
7
+ anchor: {
8
+ key: NodeKey;
9
+ offset: number;
10
+ };
11
+ caret: HTMLElement;
12
+ color: string;
13
+ focus: {
14
+ key: NodeKey;
15
+ offset: number;
16
+ };
17
+ name: HTMLSpanElement;
18
+ selections: Array<HTMLElement>;
19
+ };
20
+ export type Cursor = {
21
+ color: string;
22
+ name: string;
23
+ selection: null | CursorSelection;
24
+ };
25
+ export type SyncCursorPositionsOptions = {
26
+ getAwarenessStates?: (binding: Binding, provider: Provider) => Map<number, UserState>;
27
+ };
28
+ export type SyncCursorPositionsFn = (binding: Binding, provider: Provider, options?: SyncCursorPositionsOptions) => void;
29
+ /*****************************************************************************/
30
+ export declare function $syncLocalCursorPosition(binding: Binding, provider: Provider): void;
31
+ /*****************************************************************************/
32
+ export declare function getAnchorAndFocusCollabNodesForUserState(binding: Binding, userState: UserState): {
33
+ anchorCollabNode: AnyCollabNode;
34
+ anchorOffset: number;
35
+ focusCollabNode: AnyCollabNode;
36
+ focusOffset: number;
37
+ };
38
+ export declare function syncCursorPositions(binding: Binding, provider: Provider, options?: SyncCursorPositionsOptions): void;
39
+ export declare function syncLexicalSelectionToYjs(binding: Binding, provider: Provider, prevSelection: null | BaseSelection, nextSelection: null | BaseSelection): void;
@@ -0,0 +1,351 @@
1
+ import { $getNodeByKey, $getSelection, $isElementNode, $isLineBreakNode, $isRangeSelection, $isTextNode, } from 'lexical';
2
+ import { createDOMRange, createRectsFromDOMRange } from '@lexical/selection';
3
+ import { compareRelativePositions, createAbsolutePositionFromRelativePosition, createRelativePositionFromTypeIndex, } from 'yjs';
4
+ import invariant from '../../utils/invariant';
5
+ import { getPositionFromElementAndOffset } from '../utils/Utils';
6
+ import { CollabElementNode } from '../nodes/CollabElementNode';
7
+ import { CollabTextNode } from '../nodes/CollabTextNode';
8
+ /*****************************************************************************/
9
+ function $setPoint(point, key, offset) {
10
+ if (point.key !== key || point.offset !== offset) {
11
+ let anchorNode = $getNodeByKey(key);
12
+ if (anchorNode !== null &&
13
+ !$isElementNode(anchorNode) &&
14
+ !$isTextNode(anchorNode)) {
15
+ const parent = anchorNode.getParentOrThrow();
16
+ key = parent.getKey();
17
+ offset = anchorNode.getIndexWithinParent();
18
+ anchorNode = parent;
19
+ }
20
+ point.set(key, offset, $isElementNode(anchorNode) ? 'element' : 'text');
21
+ }
22
+ }
23
+ /*****************************************************************************/
24
+ export function $syncLocalCursorPosition(binding, provider) {
25
+ const awareness = provider.awareness;
26
+ const localState = awareness.getLocalState();
27
+ if (localState === null) {
28
+ return;
29
+ }
30
+ const { anchorCollabNode, anchorOffset, focusCollabNode, focusOffset } = getAnchorAndFocusCollabNodesForUserState(binding, localState);
31
+ if (anchorCollabNode !== null && focusCollabNode !== null) {
32
+ const anchorKey = anchorCollabNode.getKey();
33
+ const focusKey = focusCollabNode.getKey();
34
+ const selection = $getSelection();
35
+ if (!$isRangeSelection(selection)) {
36
+ return;
37
+ }
38
+ $setPoint(selection.anchor, anchorKey, anchorOffset);
39
+ $setPoint(selection.focus, focusKey, focusOffset);
40
+ }
41
+ }
42
+ /*****************************************************************************/
43
+ function createRelativePosition(point, binding) {
44
+ const collabNodeMap = binding.collabNodeMap;
45
+ const collabNode = collabNodeMap.get(point.key);
46
+ if (collabNode === undefined) {
47
+ return null;
48
+ }
49
+ let offset = point.offset;
50
+ let sharedType = collabNode.getSharedType();
51
+ if (collabNode instanceof CollabTextNode) {
52
+ sharedType = collabNode._parent._xmlText;
53
+ const currentOffset = collabNode.getOffset();
54
+ if (currentOffset === -1) {
55
+ return null;
56
+ }
57
+ offset = currentOffset + 1 + offset;
58
+ }
59
+ else if (collabNode instanceof CollabElementNode &&
60
+ point.type === 'element') {
61
+ const parent = point.getNode();
62
+ invariant($isElementNode(parent), 'Element point must be an element node');
63
+ let accumulatedOffset = 0;
64
+ let i = 0;
65
+ let node = parent.getFirstChild();
66
+ while (node !== null && i++ < offset) {
67
+ if ($isTextNode(node)) {
68
+ accumulatedOffset += node.getTextContentSize() + 1;
69
+ }
70
+ else {
71
+ accumulatedOffset++;
72
+ }
73
+ node = node.getNextSibling();
74
+ }
75
+ offset = accumulatedOffset;
76
+ }
77
+ return createRelativePositionFromTypeIndex(sharedType, offset);
78
+ }
79
+ function createAbsolutePosition(relativePosition, binding) {
80
+ return createAbsolutePositionFromRelativePosition(relativePosition, binding.doc);
81
+ }
82
+ function shouldUpdatePosition(currentPos, pos) {
83
+ if (currentPos == null) {
84
+ if (pos != null) {
85
+ return true;
86
+ }
87
+ }
88
+ else if (pos == null || !compareRelativePositions(currentPos, pos)) {
89
+ return true;
90
+ }
91
+ return false;
92
+ }
93
+ function createCursor(name, color) {
94
+ return {
95
+ color: color,
96
+ name: name,
97
+ selection: null,
98
+ };
99
+ }
100
+ function destroySelection(binding, selection) {
101
+ const cursorsContainer = binding.cursorsContainer;
102
+ if (cursorsContainer !== null) {
103
+ const selections = selection.selections;
104
+ const selectionsLength = selections.length;
105
+ for (let i = 0; i < selectionsLength; i++) {
106
+ cursorsContainer.removeChild(selections[i]);
107
+ }
108
+ }
109
+ }
110
+ function destroyCursor(binding, cursor) {
111
+ const selection = cursor.selection;
112
+ if (selection !== null) {
113
+ destroySelection(binding, selection);
114
+ }
115
+ }
116
+ function createCursorSelection(cursor, anchorKey, anchorOffset, focusKey, focusOffset) {
117
+ const color = cursor.color;
118
+ const caret = document.createElement('span');
119
+ caret.style.cssText = `position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${color};z-index:10;`;
120
+ const name = document.createElement('span');
121
+ name.textContent = cursor.name;
122
+ name.style.cssText = `position:absolute;left:-2px;top:-16px;background-color:${color};color:#fff;line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`;
123
+ caret.appendChild(name);
124
+ return {
125
+ anchor: {
126
+ key: anchorKey,
127
+ offset: anchorOffset,
128
+ },
129
+ caret,
130
+ color,
131
+ focus: {
132
+ key: focusKey,
133
+ offset: focusOffset,
134
+ },
135
+ name,
136
+ selections: [],
137
+ };
138
+ }
139
+ function updateCursor(binding, cursor, nextSelection, nodeMap) {
140
+ const editor = binding.editor;
141
+ const rootElement = editor.getRootElement();
142
+ const cursorsContainer = binding.cursorsContainer;
143
+ if (cursorsContainer === null || rootElement === null) {
144
+ return;
145
+ }
146
+ const cursorsContainerOffsetParent = cursorsContainer.offsetParent;
147
+ if (cursorsContainerOffsetParent === null) {
148
+ return;
149
+ }
150
+ const containerRect = cursorsContainerOffsetParent.getBoundingClientRect();
151
+ const prevSelection = cursor.selection;
152
+ if (nextSelection === null) {
153
+ if (prevSelection === null) {
154
+ return;
155
+ }
156
+ else {
157
+ cursor.selection = null;
158
+ destroySelection(binding, prevSelection);
159
+ return;
160
+ }
161
+ }
162
+ else {
163
+ cursor.selection = nextSelection;
164
+ }
165
+ const caret = nextSelection.caret;
166
+ const color = nextSelection.color;
167
+ const selections = nextSelection.selections;
168
+ const anchor = nextSelection.anchor;
169
+ const focus = nextSelection.focus;
170
+ const anchorKey = anchor.key;
171
+ const focusKey = focus.key;
172
+ const anchorNode = nodeMap.get(anchorKey);
173
+ const focusNode = nodeMap.get(focusKey);
174
+ if (anchorNode == null || focusNode == null) {
175
+ return;
176
+ }
177
+ let selectionRects;
178
+ // In the case of a collapsed selection on a linebreak, we need
179
+ // to improvise as the browser will return nothing here as <br>
180
+ // apparently take up no visual space :/
181
+ // This won't work in all cases, but it's better than just showing
182
+ // nothing all the time.
183
+ if (anchorNode === focusNode && $isLineBreakNode(anchorNode)) {
184
+ const brRect = editor.getElementByKey(anchorKey).getBoundingClientRect();
185
+ selectionRects = [brRect];
186
+ }
187
+ else {
188
+ const range = createDOMRange(editor, anchorNode, anchor.offset, focusNode, focus.offset);
189
+ if (range === null) {
190
+ return;
191
+ }
192
+ selectionRects = createRectsFromDOMRange(editor, range);
193
+ }
194
+ const selectionsLength = selections.length;
195
+ const selectionRectsLength = selectionRects.length;
196
+ for (let i = 0; i < selectionRectsLength; i++) {
197
+ const selectionRect = selectionRects[i];
198
+ let selection = selections[i];
199
+ if (selection === undefined) {
200
+ selection = document.createElement('span');
201
+ selections[i] = selection;
202
+ const selectionBg = document.createElement('span');
203
+ selection.appendChild(selectionBg);
204
+ cursorsContainer.appendChild(selection);
205
+ }
206
+ const top = selectionRect.top - containerRect.top;
207
+ const left = selectionRect.left - containerRect.left;
208
+ const style = `position:absolute;top:${top}px;left:${left}px;height:${selectionRect.height}px;width:${selectionRect.width}px;pointer-events:none;z-index:5;`;
209
+ selection.style.cssText = style;
210
+ selection.firstChild.style.cssText = `${style}left:0;top:0;background-color:${color};opacity:0.3;`;
211
+ if (i === selectionRectsLength - 1) {
212
+ if (caret.parentNode !== selection) {
213
+ selection.appendChild(caret);
214
+ }
215
+ }
216
+ }
217
+ for (let i = selectionsLength - 1; i >= selectionRectsLength; i--) {
218
+ const selection = selections[i];
219
+ cursorsContainer.removeChild(selection);
220
+ selections.pop();
221
+ }
222
+ }
223
+ function getCollabNodeAndOffset(
224
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
225
+ sharedType, offset) {
226
+ const collabNode = sharedType._collabNode;
227
+ if (collabNode === undefined) {
228
+ return [null, 0];
229
+ }
230
+ if (collabNode instanceof CollabElementNode) {
231
+ const { node, offset: collabNodeOffset } = getPositionFromElementAndOffset(collabNode, offset, true);
232
+ if (node === null) {
233
+ return [collabNode, 0];
234
+ }
235
+ else {
236
+ return [node, collabNodeOffset];
237
+ }
238
+ }
239
+ return [null, 0];
240
+ }
241
+ function getAwarenessStatesDefault(_binding, provider) {
242
+ return provider.awareness.getStates();
243
+ }
244
+ /*****************************************************************************/
245
+ export function getAnchorAndFocusCollabNodesForUserState(binding, userState) {
246
+ const { anchorPos, focusPos } = userState;
247
+ let anchorCollabNode = null;
248
+ let anchorOffset = 0;
249
+ let focusCollabNode = null;
250
+ let focusOffset = 0;
251
+ if (anchorPos !== null && focusPos !== null) {
252
+ const anchorAbsPos = createAbsolutePosition(anchorPos, binding);
253
+ const focusAbsPos = createAbsolutePosition(focusPos, binding);
254
+ if (anchorAbsPos !== null && focusAbsPos !== null) {
255
+ [anchorCollabNode, anchorOffset] = getCollabNodeAndOffset(anchorAbsPos.type, anchorAbsPos.index);
256
+ [focusCollabNode, focusOffset] = getCollabNodeAndOffset(focusAbsPos.type, focusAbsPos.index);
257
+ }
258
+ }
259
+ return {
260
+ anchorCollabNode,
261
+ anchorOffset,
262
+ focusCollabNode,
263
+ focusOffset,
264
+ };
265
+ }
266
+ export function syncCursorPositions(binding, provider, options) {
267
+ const { getAwarenessStates = getAwarenessStatesDefault } = options ?? {};
268
+ const awarenessStates = Array.from(getAwarenessStates(binding, provider));
269
+ const localClientID = binding.clientID;
270
+ const cursors = binding.cursors;
271
+ const editor = binding.editor;
272
+ const nodeMap = editor._editorState._nodeMap;
273
+ const visitedClientIDs = new Set();
274
+ for (let i = 0; i < awarenessStates.length; i++) {
275
+ const awarenessState = awarenessStates[i];
276
+ const [clientID, awareness] = awarenessState;
277
+ if (clientID !== localClientID) {
278
+ visitedClientIDs.add(clientID);
279
+ const { name, color, focusing } = awareness;
280
+ let selection = null;
281
+ let cursor = cursors.get(clientID);
282
+ if (cursor === undefined) {
283
+ cursor = createCursor(name, color);
284
+ cursors.set(clientID, cursor);
285
+ }
286
+ if (focusing) {
287
+ const { anchorCollabNode, anchorOffset, focusCollabNode, focusOffset } = getAnchorAndFocusCollabNodesForUserState(binding, awareness);
288
+ if (anchorCollabNode !== null && focusCollabNode !== null) {
289
+ const anchorKey = anchorCollabNode.getKey();
290
+ const focusKey = focusCollabNode.getKey();
291
+ selection = cursor.selection;
292
+ if (selection === null) {
293
+ selection = createCursorSelection(cursor, anchorKey, anchorOffset, focusKey, focusOffset);
294
+ }
295
+ else {
296
+ const anchor = selection.anchor;
297
+ const focus = selection.focus;
298
+ anchor.key = anchorKey;
299
+ anchor.offset = anchorOffset;
300
+ focus.key = focusKey;
301
+ focus.offset = focusOffset;
302
+ }
303
+ }
304
+ }
305
+ updateCursor(binding, cursor, selection, nodeMap);
306
+ }
307
+ }
308
+ const allClientIDs = Array.from(cursors.keys());
309
+ for (let i = 0; i < allClientIDs.length; i++) {
310
+ const clientID = allClientIDs[i];
311
+ if (!visitedClientIDs.has(clientID)) {
312
+ const cursor = cursors.get(clientID);
313
+ if (cursor !== undefined) {
314
+ destroyCursor(binding, cursor);
315
+ cursors.delete(clientID);
316
+ }
317
+ }
318
+ }
319
+ }
320
+ export function syncLexicalSelectionToYjs(binding, provider, prevSelection, nextSelection) {
321
+ const awareness = provider.awareness;
322
+ const localState = awareness.getLocalState();
323
+ if (localState === null) {
324
+ return;
325
+ }
326
+ const { anchorPos: currentAnchorPos, focusPos: currentFocusPos, name, color, focusing, awarenessData, } = localState;
327
+ let anchorPos = null;
328
+ let focusPos = null;
329
+ if (nextSelection === null ||
330
+ (currentAnchorPos !== null && !nextSelection.is(prevSelection))) {
331
+ if (prevSelection === null) {
332
+ return;
333
+ }
334
+ }
335
+ if ($isRangeSelection(nextSelection)) {
336
+ anchorPos = createRelativePosition(nextSelection.anchor, binding);
337
+ focusPos = createRelativePosition(nextSelection.focus, binding);
338
+ }
339
+ if (shouldUpdatePosition(currentAnchorPos, anchorPos) ||
340
+ shouldUpdatePosition(currentFocusPos, focusPos)) {
341
+ awareness.setLocalState({
342
+ ...localState,
343
+ anchorPos,
344
+ awarenessData,
345
+ color,
346
+ focusPos,
347
+ focusing,
348
+ name,
349
+ });
350
+ }
351
+ }
@@ -0,0 +1,10 @@
1
+ import type { EditorState, NodeKey } from 'lexical';
2
+ import { Text as YText, YEvent } from 'yjs';
3
+ import { Binding } from '../Bindings';
4
+ import { Provider } from '../State';
5
+ import { SyncCursorPositionsFn } from './SyncCursors';
6
+ /*****************************************************************************/
7
+ type IntentionallyMarkedAsDirtyElement = boolean;
8
+ export declare function syncYjsUpdatesToLexical(binding: Binding, provider: Provider, events: Array<YEvent<YText>>, isFromUndoManger: boolean, syncCursorPositionsFn?: SyncCursorPositionsFn): void;
9
+ export declare function syncLexicalUpdatesToYjs(binding: Binding, provider: Provider, prevEditorState: EditorState, currEditorState: EditorState, dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement>, dirtyLeaves: Set<NodeKey>, normalizedNodes: Set<NodeKey>, tags: Set<string>): void;
10
+ export {};