@datalayer/lexical-loro 0.0.3 → 0.1.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.
- package/README.md +24 -137
- package/lib/App.d.ts +2 -0
- package/lib/App.js +141 -0
- package/lib/Editor.d.ts +2 -0
- package/lib/Editor.js +111 -0
- package/lib/Settings.d.ts +2 -0
- package/lib/Settings.js +57 -0
- package/lib/appSettings.d.ts +36 -0
- package/lib/appSettings.js +44 -0
- package/lib/collab/loro/Bindings.d.ts +41 -0
- package/lib/collab/loro/Bindings.js +95 -0
- package/lib/collab/loro/Debug.d.ts +33 -0
- package/lib/collab/loro/Debug.js +448 -0
- package/lib/collab/loro/LexicalCollaborationContext.d.ts +19 -0
- package/lib/collab/loro/LexicalCollaborationContext.js +48 -0
- package/lib/collab/loro/LexicalCollaborationPlugin.d.ts +24 -0
- package/lib/collab/loro/LexicalCollaborationPlugin.js +83 -0
- package/lib/collab/loro/State.d.ts +53 -0
- package/lib/collab/loro/State.js +90 -0
- package/lib/collab/loro/components/LoroCollaborationUI.d.ts +13 -0
- package/lib/collab/loro/components/LoroCollaborationUI.js +9 -0
- package/lib/collab/loro/components/LoroCollaborators.d.ts +8 -0
- package/lib/collab/loro/components/LoroCollaborators.js +97 -0
- package/lib/collab/loro/components/index.d.ts +2 -0
- package/lib/collab/loro/components/index.js +2 -0
- package/lib/collab/loro/index.d.ts +6 -0
- package/lib/collab/loro/index.js +6 -0
- package/lib/collab/loro/integrators/BaseIntegrator.d.ts +14 -0
- package/lib/collab/loro/integrators/BaseIntegrator.js +1 -0
- package/lib/collab/loro/integrators/CounterIntegrator.d.ts +23 -0
- package/lib/collab/loro/integrators/CounterIntegrator.js +40 -0
- package/lib/collab/loro/integrators/ListIntegrator.d.ts +23 -0
- package/lib/collab/loro/integrators/ListIntegrator.js +49 -0
- package/lib/collab/loro/integrators/MapIntegrator.d.ts +24 -0
- package/lib/collab/loro/integrators/MapIntegrator.js +177 -0
- package/lib/collab/loro/integrators/TextIntegrator.d.ts +25 -0
- package/lib/collab/loro/integrators/TextIntegrator.js +51 -0
- package/lib/collab/loro/integrators/TreeIntegrator.d.ts +25 -0
- package/lib/collab/loro/integrators/TreeIntegrator.js +201 -0
- package/lib/collab/loro/nodes/NodeFactory.d.ts +8 -0
- package/lib/collab/loro/nodes/NodeFactory.js +105 -0
- package/lib/collab/loro/nodes/NodesMapper.d.ts +111 -0
- package/lib/collab/loro/nodes/NodesMapper.js +258 -0
- package/lib/collab/loro/propagators/DecoratorNodePropagator.d.ts +60 -0
- package/lib/collab/loro/propagators/DecoratorNodePropagator.js +302 -0
- package/lib/collab/loro/propagators/ElementNodePropagator.d.ts +62 -0
- package/lib/collab/loro/propagators/ElementNodePropagator.js +335 -0
- package/lib/collab/loro/propagators/LineBreakNodePropagator.d.ts +57 -0
- package/lib/collab/loro/propagators/LineBreakNodePropagator.js +196 -0
- package/lib/collab/loro/propagators/RootNodePropagator.d.ts +55 -0
- package/lib/collab/loro/propagators/RootNodePropagator.js +168 -0
- package/lib/collab/loro/propagators/TextNodePropagator.d.ts +60 -0
- package/lib/collab/loro/propagators/TextNodePropagator.js +434 -0
- package/lib/collab/loro/propagators/index.d.ts +49 -0
- package/lib/collab/loro/propagators/index.js +32 -0
- package/lib/collab/loro/provider/websocket.d.ts +116 -0
- package/lib/collab/loro/provider/websocket.js +907 -0
- package/lib/collab/loro/servers/index.d.ts +0 -0
- package/lib/collab/loro/servers/index.js +0 -0
- package/lib/collab/loro/servers/ws/callback.d.ts +5 -0
- package/lib/collab/loro/servers/ws/callback.js +85 -0
- package/lib/collab/loro/servers/ws/server.d.ts +2 -0
- package/lib/collab/loro/servers/ws/server.js +25 -0
- package/lib/collab/loro/servers/ws/utils.d.ts +40 -0
- package/lib/collab/loro/servers/ws/utils.js +513 -0
- package/lib/collab/loro/sync/SyncCursors.d.ts +32 -0
- package/lib/collab/loro/sync/SyncCursors.js +435 -0
- package/lib/collab/loro/sync/SyncLexicalToLoro.d.ts +4 -0
- package/lib/collab/loro/sync/SyncLexicalToLoro.js +80 -0
- package/lib/collab/loro/sync/SyncLoroToLexical.d.ts +5 -0
- package/lib/collab/loro/sync/SyncLoroToLexical.js +96 -0
- package/lib/collab/loro/types/LexicalNodeData.d.ts +32 -0
- package/lib/collab/loro/types/LexicalNodeData.js +71 -0
- package/lib/collab/loro/useCollaboration.d.ts +12 -0
- package/lib/collab/loro/useCollaboration.js +248 -0
- package/lib/collab/loro/utils/InitialContent.d.ts +64 -0
- package/lib/collab/loro/utils/InitialContent.js +109 -0
- package/lib/collab/loro/utils/LexicalToLoro.d.ts +18 -0
- package/lib/collab/loro/utils/LexicalToLoro.js +96 -0
- package/lib/collab/loro/utils/Utils.d.ts +44 -0
- package/lib/collab/loro/utils/Utils.js +153 -0
- package/lib/collab/loro/wsProvider.d.ts +8 -0
- package/lib/collab/loro/wsProvider.js +31 -0
- package/lib/collab/utils/invariant.d.ts +1 -0
- package/lib/collab/utils/invariant.js +11 -0
- package/lib/collab/utils/simpleDiffWithCursor.d.ts +5 -0
- package/lib/collab/utils/simpleDiffWithCursor.js +31 -0
- package/lib/collab/yjs/Bindings.d.ts +23 -0
- package/lib/collab/yjs/Bindings.js +26 -0
- package/lib/collab/yjs/Debug.d.ts +23 -0
- package/lib/collab/yjs/Debug.js +213 -0
- package/lib/collab/yjs/LexicalCollaborationContext.d.ts +10 -0
- package/lib/collab/yjs/LexicalCollaborationContext.js +37 -0
- package/lib/collab/yjs/LexicalCollaborationPlugin.d.ts +21 -0
- package/lib/collab/yjs/LexicalCollaborationPlugin.js +63 -0
- package/lib/collab/yjs/State.d.ts +51 -0
- package/lib/collab/yjs/State.js +35 -0
- package/lib/collab/yjs/nodes/AnyCollabNode.d.ts +5 -0
- package/lib/collab/yjs/nodes/AnyCollabNode.js +1 -0
- package/lib/collab/yjs/nodes/CollabDecoratorNode.d.ts +22 -0
- package/lib/collab/yjs/nodes/CollabDecoratorNode.js +64 -0
- package/lib/collab/yjs/nodes/CollabElementNode.d.ts +40 -0
- package/lib/collab/yjs/nodes/CollabElementNode.js +462 -0
- package/lib/collab/yjs/nodes/CollabLineBreakNode.d.ts +19 -0
- package/lib/collab/yjs/nodes/CollabLineBreakNode.js +44 -0
- package/lib/collab/yjs/nodes/CollabTextNode.d.ts +25 -0
- package/lib/collab/yjs/nodes/CollabTextNode.js +103 -0
- package/lib/collab/yjs/provider/websocket.d.ts +88 -0
- package/lib/collab/yjs/provider/websocket.js +415 -0
- package/lib/collab/yjs/servers/index.d.ts +0 -0
- package/lib/collab/yjs/servers/index.js +0 -0
- package/lib/collab/yjs/servers/ws/callback.d.ts +5 -0
- package/lib/collab/yjs/servers/ws/callback.js +72 -0
- package/lib/collab/yjs/servers/ws/server.d.ts +2 -0
- package/lib/collab/yjs/servers/ws/server.js +25 -0
- package/lib/collab/yjs/servers/ws/utils.d.ts +49 -0
- package/lib/collab/yjs/servers/ws/utils.js +284 -0
- package/lib/collab/yjs/sync/SyncCursors.d.ts +39 -0
- package/lib/collab/yjs/sync/SyncCursors.js +351 -0
- package/lib/collab/yjs/sync/SyncEditorStates.d.ts +10 -0
- package/lib/collab/yjs/sync/SyncEditorStates.js +200 -0
- package/lib/collab/yjs/useCollaboration.d.ts +12 -0
- package/lib/collab/yjs/useCollaboration.js +255 -0
- package/lib/collab/yjs/utils/Utils.d.ts +25 -0
- package/lib/collab/yjs/utils/Utils.js +402 -0
- package/lib/collab/yjs/wsProvider.d.ts +3 -0
- package/lib/collab/yjs/wsProvider.js +21 -0
- package/lib/commenting/index.d.ts +41 -0
- package/lib/commenting/index.js +324 -0
- package/lib/context/FlashMessageContext.d.ts +7 -0
- package/lib/context/FlashMessageContext.js +24 -0
- package/lib/context/SettingsContext.d.ts +12 -0
- package/lib/context/SettingsContext.js +38 -0
- package/lib/context/SharedHistoryContext.d.ts +11 -0
- package/lib/context/SharedHistoryContext.js +11 -0
- package/lib/context/ToolbarContext.d.ts +65 -0
- package/lib/context/ToolbarContext.js +84 -0
- package/lib/demo.d.ts +12 -0
- package/lib/demo.js +41 -0
- package/lib/hooks/useFlashMessage.d.ts +2 -0
- package/lib/hooks/useFlashMessage.js +4 -0
- package/lib/hooks/useModal.d.ts +5 -0
- package/lib/hooks/useModal.js +26 -0
- package/lib/hooks/useReport.d.ts +1 -0
- package/lib/hooks/useReport.js +46 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -5
- package/lib/nodes/AutocompleteNode.d.ts +27 -0
- package/lib/nodes/AutocompleteNode.js +56 -0
- package/lib/nodes/CounterComponent.d.ts +6 -0
- package/lib/nodes/CounterComponent.js +137 -0
- package/lib/nodes/CounterNode.d.ts +23 -0
- package/lib/nodes/CounterNode.js +47 -0
- package/lib/nodes/DateTimeNode/DateTimeComponent.d.ts +8 -0
- package/lib/nodes/DateTimeNode/DateTimeComponent.js +119 -0
- package/lib/nodes/DateTimeNode/DateTimeNode.d.ts +27 -0
- package/lib/nodes/DateTimeNode/DateTimeNode.js +82 -0
- package/lib/nodes/EmojiNode.d.ts +18 -0
- package/lib/nodes/EmojiNode.js +50 -0
- package/lib/nodes/EquationComponent.d.ts +9 -0
- package/lib/nodes/EquationComponent.js +75 -0
- package/lib/nodes/EquationNode.d.ts +26 -0
- package/lib/nodes/EquationNode.js +109 -0
- package/lib/nodes/ExcalidrawNode/ExcalidrawComponent.d.ts +8 -0
- package/lib/nodes/ExcalidrawNode/ExcalidrawComponent.js +110 -0
- package/lib/nodes/ExcalidrawNode/ExcalidrawImage.d.ts +50 -0
- package/lib/nodes/ExcalidrawNode/ExcalidrawImage.js +55 -0
- package/lib/nodes/ExcalidrawNode/index.d.ts +32 -0
- package/lib/nodes/ExcalidrawNode/index.js +117 -0
- package/lib/nodes/FigmaNode.d.ts +20 -0
- package/lib/nodes/FigmaNode.js +52 -0
- package/lib/nodes/ImageComponent.d.ts +16 -0
- package/lib/nodes/ImageComponent.js +272 -0
- package/lib/nodes/ImageNode.d.ts +50 -0
- package/lib/nodes/ImageNode.js +151 -0
- package/lib/nodes/InlineImageNode/InlineImageComponent.d.ts +26 -0
- package/lib/nodes/InlineImageNode/InlineImageComponent.js +161 -0
- package/lib/nodes/InlineImageNode/InlineImageNode.d.ts +59 -0
- package/lib/nodes/InlineImageNode/InlineImageNode.js +162 -0
- package/lib/nodes/KeywordNode.d.ts +14 -0
- package/lib/nodes/KeywordNode.js +33 -0
- package/lib/nodes/LayoutContainerNode.d.ts +24 -0
- package/lib/nodes/LayoutContainerNode.js +91 -0
- package/lib/nodes/LayoutItemNode.d.ts +16 -0
- package/lib/nodes/LayoutItemNode.js +65 -0
- package/lib/nodes/MentionNode.d.ts +20 -0
- package/lib/nodes/MentionNode.js +81 -0
- package/lib/nodes/PageBreakNode/index.d.ts +17 -0
- package/lib/nodes/PageBreakNode/index.js +83 -0
- package/lib/nodes/PlaygroundNodes.d.ts +3 -0
- package/lib/nodes/PlaygroundNodes.js +71 -0
- package/lib/nodes/PollComponent.d.ts +9 -0
- package/lib/nodes/PollComponent.js +85 -0
- package/lib/nodes/PollNode.d.ts +43 -0
- package/lib/nodes/PollNode.js +153 -0
- package/lib/nodes/SpecialTextNode.d.ts +24 -0
- package/lib/nodes/SpecialTextNode.js +50 -0
- package/lib/nodes/StickyComponent.d.ts +10 -0
- package/lib/nodes/StickyComponent.js +162 -0
- package/lib/nodes/StickyNode.d.ts +31 -0
- package/lib/nodes/StickyNode.js +76 -0
- package/lib/nodes/TweetNode.d.ts +21 -0
- package/lib/nodes/TweetNode.js +119 -0
- package/lib/nodes/YouTubeNode.d.ts +22 -0
- package/lib/nodes/YouTubeNode.js +84 -0
- package/lib/plugins/ActionsPlugin/index.d.ts +5 -0
- package/lib/plugins/ActionsPlugin/index.js +168 -0
- package/lib/plugins/AutoEmbedPlugin/index.d.ts +19 -0
- package/lib/plugins/AutoEmbedPlugin/index.js +158 -0
- package/lib/plugins/AutoLinkPlugin/index.d.ts +2 -0
- package/lib/plugins/AutoLinkPlugin/index.js +15 -0
- package/lib/plugins/AutocompletePlugin/index.d.ts +10 -0
- package/lib/plugins/AutocompletePlugin/index.js +2473 -0
- package/lib/plugins/CodeActionMenuPlugin/components/CopyButton/index.d.ts +7 -0
- package/lib/plugins/CodeActionMenuPlugin/components/CopyButton/index.js +42 -0
- package/lib/plugins/CodeActionMenuPlugin/components/PrettierButton/index.d.ts +17 -0
- package/lib/plugins/CodeActionMenuPlugin/components/PrettierButton/index.js +111 -0
- package/lib/plugins/CodeActionMenuPlugin/index.d.ts +5 -0
- package/lib/plugins/CodeActionMenuPlugin/index.js +104 -0
- package/lib/plugins/CodeActionMenuPlugin/utils.d.ts +1 -0
- package/lib/plugins/CodeActionMenuPlugin/utils.js +18 -0
- package/lib/plugins/CodeHighlightPrismPlugin/index.d.ts +2 -0
- package/lib/plugins/CodeHighlightPrismPlugin/index.js +10 -0
- package/lib/plugins/CodeHighlightShikiPlugin/index.d.ts +2 -0
- package/lib/plugins/CodeHighlightShikiPlugin/index.js +10 -0
- package/lib/plugins/CollapsiblePlugin/CollapsibleContainerNode.d.ts +25 -0
- package/lib/plugins/CollapsiblePlugin/CollapsibleContainerNode.js +131 -0
- package/lib/plugins/CollapsiblePlugin/CollapsibleContentNode.d.ts +16 -0
- package/lib/plugins/CollapsiblePlugin/CollapsibleContentNode.js +79 -0
- package/lib/plugins/CollapsiblePlugin/CollapsibleTitleNode.d.ts +16 -0
- package/lib/plugins/CollapsiblePlugin/CollapsibleTitleNode.js +81 -0
- package/lib/plugins/CollapsiblePlugin/CollapsibleUtils.d.ts +2 -0
- package/lib/plugins/CollapsiblePlugin/CollapsibleUtils.js +8 -0
- package/lib/plugins/CollapsiblePlugin/index.d.ts +3 -0
- package/lib/plugins/CollapsiblePlugin/index.js +128 -0
- package/lib/plugins/CommentPlugin/index.d.ts +9 -0
- package/lib/plugins/CommentPlugin/index.js +460 -0
- package/lib/plugins/ComponentPickerPlugin/index.d.ts +2 -0
- package/lib/plugins/ComponentPickerPlugin/index.js +276 -0
- package/lib/plugins/ContextMenuPlugin/index.d.ts +2 -0
- package/lib/plugins/ContextMenuPlugin/index.js +112 -0
- package/lib/plugins/CounterPlugin/index.d.ts +3 -0
- package/lib/plugins/CounterPlugin/index.js +20 -0
- package/lib/plugins/DatalayerPlugin/index.d.ts +2 -0
- package/lib/plugins/DatalayerPlugin/index.js +218 -0
- package/lib/plugins/DateTimePlugin/index.d.ts +8 -0
- package/lib/plugins/DateTimePlugin/index.js +24 -0
- package/lib/plugins/DocsPlugin/index.d.ts +2 -0
- package/lib/plugins/DocsPlugin/index.js +4 -0
- package/lib/plugins/DragDropPastePlugin/index.d.ts +1 -0
- package/lib/plugins/DragDropPastePlugin/index.js +33 -0
- package/lib/plugins/DraggableBlockPlugin/index.d.ts +12 -0
- package/lib/plugins/DraggableBlockPlugin/index.js +36 -0
- package/lib/plugins/EmojiPickerPlugin/index.d.ts +1 -0
- package/lib/plugins/EmojiPickerPlugin/index.js +80 -0
- package/lib/plugins/EmojisPlugin/index.d.ts +2 -0
- package/lib/plugins/EmojisPlugin/index.js +52 -0
- package/lib/plugins/EquationsPlugin/index.d.ts +14 -0
- package/lib/plugins/EquationsPlugin/index.js +34 -0
- package/lib/plugins/ExcalidrawPlugin/index.d.ts +5 -0
- package/lib/plugins/ExcalidrawPlugin/index.js +44 -0
- package/lib/plugins/FigmaPlugin/index.d.ts +4 -0
- package/lib/plugins/FigmaPlugin/index.js +20 -0
- package/lib/plugins/FloatingLinkEditorPlugin/index.d.ts +15 -0
- package/lib/plugins/FloatingLinkEditorPlugin/index.js +280 -0
- package/lib/plugins/FloatingTextFormatToolbarPlugin/index.d.ts +7 -0
- package/lib/plugins/FloatingTextFormatToolbarPlugin/index.js +219 -0
- package/lib/plugins/ImagesPlugin/index.d.ts +24 -0
- package/lib/plugins/ImagesPlugin/index.js +195 -0
- package/lib/plugins/InlineImagePlugin/index.d.ts +17 -0
- package/lib/plugins/InlineImagePlugin/index.js +180 -0
- package/lib/plugins/KeywordsPlugin/index.d.ts +2 -0
- package/lib/plugins/KeywordsPlugin/index.js +31 -0
- package/lib/plugins/LayoutPlugin/InsertLayoutDialog.d.ts +6 -0
- package/lib/plugins/LayoutPlugin/InsertLayoutDialog.js +21 -0
- package/lib/plugins/LayoutPlugin/LayoutPlugin.d.ts +7 -0
- package/lib/plugins/LayoutPlugin/LayoutPlugin.js +131 -0
- package/lib/plugins/LinkPlugin/index.d.ts +6 -0
- package/lib/plugins/LinkPlugin/index.js +11 -0
- package/lib/plugins/MarkdownShortcutPlugin/index.d.ts +2 -0
- package/lib/plugins/MarkdownShortcutPlugin/index.js +6 -0
- package/lib/plugins/MarkdownTransformers/index.d.ts +8 -0
- package/lib/plugins/MarkdownTransformers/index.js +234 -0
- package/lib/plugins/MaxLengthPlugin/index.d.ts +3 -0
- package/lib/plugins/MaxLengthPlugin/index.js +37 -0
- package/lib/plugins/MentionsPlugin/index.d.ts +2 -0
- package/lib/plugins/MentionsPlugin/index.js +564 -0
- package/lib/plugins/PageBreakPlugin/index.d.ts +4 -0
- package/lib/plugins/PageBreakPlugin/index.js +27 -0
- package/lib/plugins/PasteLogPlugin/index.d.ts +2 -0
- package/lib/plugins/PasteLogPlugin/index.js +27 -0
- package/lib/plugins/PollPlugin/index.d.ts +8 -0
- package/lib/plugins/PollPlugin/index.js +38 -0
- package/lib/plugins/ShortcutsPlugin/index.d.ts +6 -0
- package/lib/plugins/ShortcutsPlugin/index.js +112 -0
- package/lib/plugins/ShortcutsPlugin/shortcuts.d.ts +59 -0
- package/lib/plugins/ShortcutsPlugin/shortcuts.js +169 -0
- package/lib/plugins/SpecialTextPlugin/index.d.ts +2 -0
- package/lib/plugins/SpecialTextPlugin/index.js +46 -0
- package/lib/plugins/SpeechToTextPlugin/index.d.ts +5 -0
- package/lib/plugins/SpeechToTextPlugin/index.js +82 -0
- package/lib/plugins/StickyPlugin/index.d.ts +2 -0
- package/lib/plugins/StickyPlugin/index.js +12 -0
- package/lib/plugins/TabFocusPlugin/index.d.ts +1 -0
- package/lib/plugins/TabFocusPlugin/index.js +34 -0
- package/lib/plugins/TableActionMenuPlugin/index.d.ts +5 -0
- package/lib/plugins/TableActionMenuPlugin/index.js +492 -0
- package/lib/plugins/TableCellResizer/index.d.ts +3 -0
- package/lib/plugins/TableCellResizer/index.js +297 -0
- package/lib/plugins/TableHoverActionsPlugin/index.d.ts +4 -0
- package/lib/plugins/TableHoverActionsPlugin/index.js +188 -0
- package/lib/plugins/TableOfContentsPlugin/index.d.ts +2 -0
- package/lib/plugins/TableOfContentsPlugin/index.js +116 -0
- package/lib/plugins/TablePlugin.d.ts +31 -0
- package/lib/plugins/TablePlugin.js +63 -0
- package/lib/plugins/TestRecorderPlugin/index.d.ts +3 -0
- package/lib/plugins/TestRecorderPlugin/index.js +346 -0
- package/lib/plugins/ToolbarPlugin/fontSize.d.ts +9 -0
- package/lib/plugins/ToolbarPlugin/fontSize.js +80 -0
- package/lib/plugins/ToolbarPlugin/index.d.ts +9 -0
- package/lib/plugins/ToolbarPlugin/index.js +500 -0
- package/lib/plugins/ToolbarPlugin/utils.d.ts +26 -0
- package/lib/plugins/ToolbarPlugin/utils.js +243 -0
- package/lib/plugins/TreeViewPlugin/index.d.ts +2 -0
- package/lib/plugins/TreeViewPlugin/index.js +7 -0
- package/lib/plugins/TwitterPlugin/index.d.ts +4 -0
- package/lib/plugins/TwitterPlugin/index.js +20 -0
- package/lib/plugins/TypingPerfPlugin/index.d.ts +2 -0
- package/lib/plugins/TypingPerfPlugin/index.js +93 -0
- package/lib/plugins/YouTubePlugin/index.d.ts +4 -0
- package/lib/plugins/YouTubePlugin/index.js +20 -0
- package/lib/server/validation.d.ts +1 -0
- package/lib/server/validation.js +111 -0
- package/lib/setupEnv.d.ts +2 -0
- package/lib/setupEnv.js +25 -0
- package/lib/themes/CommentEditorTheme.d.ts +4 -0
- package/lib/themes/CommentEditorTheme.js +7 -0
- package/lib/themes/PlaygroundEditorTheme.d.ts +4 -0
- package/lib/themes/PlaygroundEditorTheme.js +120 -0
- package/lib/themes/StickyEditorTheme.d.ts +4 -0
- package/lib/themes/StickyEditorTheme.js +7 -0
- package/lib/tyes.dt.d.ts +12 -0
- package/lib/tyes.dt.js +0 -0
- package/lib/ui/Button.d.ts +12 -0
- package/lib/ui/Button.js +6 -0
- package/lib/ui/ColorPicker.d.ts +14 -0
- package/lib/ui/ColorPicker.js +219 -0
- package/lib/ui/ContentEditable.d.ts +9 -0
- package/lib/ui/ContentEditable.js +6 -0
- package/lib/ui/Dialog.d.ts +10 -0
- package/lib/ui/Dialog.js +8 -0
- package/lib/ui/DropDown.d.ts +18 -0
- package/lib/ui/DropDown.js +133 -0
- package/lib/ui/DropdownColorPicker.d.ts +13 -0
- package/lib/ui/DropdownColorPicker.js +6 -0
- package/lib/ui/EquationEditor.d.ts +8 -0
- package/lib/ui/EquationEditor.js +11 -0
- package/lib/ui/ExcalidrawModal.d.ts +42 -0
- package/lib/ui/ExcalidrawModal.js +103 -0
- package/lib/ui/FileInput.d.ts +10 -0
- package/lib/ui/FileInput.js +5 -0
- package/lib/ui/FlashMessage.d.ts +7 -0
- package/lib/ui/FlashMessage.js +6 -0
- package/lib/ui/ImageResizer.d.ts +17 -0
- package/lib/ui/ImageResizer.js +171 -0
- package/lib/ui/KatexEquationAlterer.d.ts +8 -0
- package/lib/ui/KatexEquationAlterer.js +23 -0
- package/lib/ui/KatexRenderer.d.ts +6 -0
- package/lib/ui/KatexRenderer.js +24 -0
- package/lib/ui/Modal.d.ts +9 -0
- package/lib/ui/Modal.js +48 -0
- package/lib/ui/Select.d.ts +8 -0
- package/lib/ui/Select.js +5 -0
- package/lib/ui/Switch.d.ts +8 -0
- package/lib/ui/Switch.js +6 -0
- package/lib/ui/TextInput.d.ts +13 -0
- package/lib/ui/TextInput.js +7 -0
- package/lib/utils/docSerialization.d.ts +3 -0
- package/lib/utils/docSerialization.js +56 -0
- package/lib/utils/emoji-list.d.ts +20 -0
- package/lib/utils/emoji-list.js +16605 -0
- package/lib/utils/getDOMRangeRect.d.ts +8 -0
- package/lib/utils/getDOMRangeRect.js +22 -0
- package/lib/utils/getSelectedNode.d.ts +2 -0
- package/lib/utils/getSelectedNode.js +24 -0
- package/lib/utils/getThemeSelector.d.ts +2 -0
- package/lib/utils/getThemeSelector.js +10 -0
- package/lib/utils/isMobileWidth.d.ts +7 -0
- package/lib/utils/isMobileWidth.js +7 -0
- package/lib/utils/joinClasses.d.ts +1 -0
- package/lib/utils/joinClasses.js +3 -0
- package/lib/utils/setFloatingElemPosition.d.ts +1 -0
- package/lib/utils/setFloatingElemPosition.js +55 -0
- package/lib/utils/setFloatingElemPositionForLinkEditor.d.ts +1 -0
- package/lib/utils/setFloatingElemPositionForLinkEditor.js +32 -0
- package/lib/utils/swipe.d.ts +4 -0
- package/lib/utils/swipe.js +90 -0
- package/lib/utils/url.d.ts +2 -0
- package/lib/utils/url.js +27 -0
- package/package.json +84 -50
- package/lib/LoroCollaborativePlugin.d.ts +0 -16
- package/lib/LoroCollaborativePlugin.js +0 -2503
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ObservableV2 } from 'lib0/observable';
|
|
2
|
+
import * as awarenessProtocol from 'y-protocols/awareness';
|
|
3
|
+
export declare const messageSync = 0;
|
|
4
|
+
export declare const messageQueryAwareness = 3;
|
|
5
|
+
export declare const messageAwareness = 1;
|
|
6
|
+
export declare const messageAuth = 2;
|
|
7
|
+
/**
|
|
8
|
+
* Websocket Provider for Yjs. Creates a websocket connection to sync the shared document.
|
|
9
|
+
* The document name is attached to the provided url. I.e. the following example
|
|
10
|
+
* creates a websocket connection to http://localhost:1234/my-document-name
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* import * as Y from 'yjs'
|
|
14
|
+
* import { WebsocketProvider } from 'y-websocket'
|
|
15
|
+
* const doc = new Y.Doc()
|
|
16
|
+
* const provider = new WebsocketProvider('http://localhost:1234', 'my-document-name', doc)
|
|
17
|
+
*
|
|
18
|
+
* @extends {ObservableV2<{ 'connection-close': (event: CloseEvent | null, provider: WebsocketProvider) => any, 'status': (event: { status: 'connected' | 'disconnected' | 'connecting' }) => any, 'connection-error': (event: Event, provider: WebsocketProvider) => any, 'sync': (state: boolean) => any }>}
|
|
19
|
+
*/
|
|
20
|
+
export declare class WebsocketProvider extends ObservableV2<any> {
|
|
21
|
+
serverUrl: string;
|
|
22
|
+
roomname: string;
|
|
23
|
+
doc: any;
|
|
24
|
+
_WS: any;
|
|
25
|
+
protocols: any[];
|
|
26
|
+
params: {};
|
|
27
|
+
awareness: any;
|
|
28
|
+
ws: any;
|
|
29
|
+
wsconnected: boolean;
|
|
30
|
+
wsconnecting: boolean;
|
|
31
|
+
bcconnected: boolean;
|
|
32
|
+
disableBc: boolean;
|
|
33
|
+
bcChannel: string;
|
|
34
|
+
maxBackoffTime: number;
|
|
35
|
+
wsUnsuccessfulReconnects: number;
|
|
36
|
+
messageIntegrators: any[];
|
|
37
|
+
_synced: boolean;
|
|
38
|
+
wsLastMessageReceived: number;
|
|
39
|
+
shouldConnect: boolean;
|
|
40
|
+
_checkInterval: any;
|
|
41
|
+
_resyncInterval: any;
|
|
42
|
+
_updateIntegrator: any;
|
|
43
|
+
_awarenessUpdateIntegrator: any;
|
|
44
|
+
_exitIntegrator: any;
|
|
45
|
+
_bcSubscriber: any;
|
|
46
|
+
/**
|
|
47
|
+
* @param {string} serverUrl
|
|
48
|
+
* @param {string} roomname
|
|
49
|
+
* @param {Y.Doc} doc
|
|
50
|
+
* @param {object} opts
|
|
51
|
+
* @param {boolean} [opts.connect]
|
|
52
|
+
* @param {awarenessProtocol.Awareness} [opts.awareness]
|
|
53
|
+
* @param {Object<string,string>} [opts.params] specify url parameters
|
|
54
|
+
* @param {Array<string>} [opts.protocols] specify websocket protocols
|
|
55
|
+
* @param {typeof WebSocket} [opts.WebSocketPolyfill] Optionall provide a WebSocket polyfill
|
|
56
|
+
* @param {number} [opts.resyncInterval] Request server state every `resyncInterval` milliseconds
|
|
57
|
+
* @param {number} [opts.maxBackoffTime] Maximum amount of time to wait before trying to reconnect (we try to reconnect using exponential backoff)
|
|
58
|
+
* @param {boolean} [opts.disableBc] Disable cross-tab BroadcastChannel communication
|
|
59
|
+
*/
|
|
60
|
+
constructor(serverUrl: any, roomname: any, doc: any, { connect, awareness, params, protocols, WebSocketPolyfill, resyncInterval, maxBackoffTime, disableBc }?: {
|
|
61
|
+
connect?: boolean;
|
|
62
|
+
awareness?: awarenessProtocol.Awareness;
|
|
63
|
+
params?: {};
|
|
64
|
+
protocols?: any[];
|
|
65
|
+
WebSocketPolyfill?: {
|
|
66
|
+
new (url: string | URL, protocols?: string | string[]): WebSocket;
|
|
67
|
+
prototype: WebSocket;
|
|
68
|
+
readonly CONNECTING: 0;
|
|
69
|
+
readonly OPEN: 1;
|
|
70
|
+
readonly CLOSING: 2;
|
|
71
|
+
readonly CLOSED: 3;
|
|
72
|
+
};
|
|
73
|
+
resyncInterval?: number;
|
|
74
|
+
maxBackoffTime?: number;
|
|
75
|
+
disableBc?: boolean;
|
|
76
|
+
});
|
|
77
|
+
get url(): string;
|
|
78
|
+
/**
|
|
79
|
+
* @type {boolean}
|
|
80
|
+
*/
|
|
81
|
+
get synced(): boolean;
|
|
82
|
+
set synced(state: boolean);
|
|
83
|
+
destroy(): void;
|
|
84
|
+
connectBc(): void;
|
|
85
|
+
disconnectBc(): void;
|
|
86
|
+
disconnect(): void;
|
|
87
|
+
connect(): void;
|
|
88
|
+
}
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import { ObservableV2 } from 'lib0/observable';
|
|
2
|
+
import * as syncProtocol from 'y-protocols/sync';
|
|
3
|
+
import * as authProtocol from 'y-protocols/auth';
|
|
4
|
+
import * as bc from 'lib0/broadcastchannel';
|
|
5
|
+
import * as time from 'lib0/time';
|
|
6
|
+
import * as encoding from 'lib0/encoding';
|
|
7
|
+
import * as decoding from 'lib0/decoding';
|
|
8
|
+
import * as awarenessProtocol from 'y-protocols/awareness';
|
|
9
|
+
import * as math from 'lib0/math';
|
|
10
|
+
import * as url from 'lib0/url';
|
|
11
|
+
import * as env from 'lib0/environment';
|
|
12
|
+
export const messageSync = 0;
|
|
13
|
+
export const messageQueryAwareness = 3;
|
|
14
|
+
export const messageAwareness = 1;
|
|
15
|
+
export const messageAuth = 2;
|
|
16
|
+
/**
|
|
17
|
+
* encoder, decoder, provider, emitSynced, messageType
|
|
18
|
+
* @type {Array<function(encoding.Encoder, decoding.Decoder, WebsocketProvider, boolean, number):void>}
|
|
19
|
+
*/
|
|
20
|
+
const messageIntegrators = [];
|
|
21
|
+
messageIntegrators[messageSync] = (encoder, decoder, provider, emitSynced, _messageType) => {
|
|
22
|
+
encoding.writeVarUint(encoder, messageSync);
|
|
23
|
+
const syncMessageType = syncProtocol.readSyncMessage(decoder, encoder, provider.doc, provider);
|
|
24
|
+
if (emitSynced && syncMessageType === syncProtocol.messageYjsSyncStep2 &&
|
|
25
|
+
!provider.synced) {
|
|
26
|
+
provider.synced = true;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
messageIntegrators[messageQueryAwareness] = (encoder, _decoder, provider, _emitSynced, _messageType) => {
|
|
30
|
+
encoding.writeVarUint(encoder, messageAwareness);
|
|
31
|
+
encoding.writeVarUint8Array(encoder, awarenessProtocol.encodeAwarenessUpdate(provider.awareness, Array.from(provider.awareness.getStates().keys())));
|
|
32
|
+
};
|
|
33
|
+
messageIntegrators[messageAwareness] = (_encoder, decoder, provider, _emitSynced, _messageType) => {
|
|
34
|
+
awarenessProtocol.applyAwarenessUpdate(provider.awareness, decoding.readVarUint8Array(decoder), provider);
|
|
35
|
+
};
|
|
36
|
+
messageIntegrators[messageAuth] = (_encoder, decoder, provider, _emitSynced, _messageType) => {
|
|
37
|
+
authProtocol.readAuthMessage(decoder, provider.doc, (_ydoc, reason) => permissionDeniedIntegrator(provider, reason));
|
|
38
|
+
};
|
|
39
|
+
// @todo - this should depend on awareness.outdatedTime
|
|
40
|
+
const messageReconnectTimeout = 30000;
|
|
41
|
+
/**
|
|
42
|
+
* @param {WebsocketProvider} provider
|
|
43
|
+
* @param {string} reason
|
|
44
|
+
*/
|
|
45
|
+
const permissionDeniedIntegrator = (provider, reason) => console.warn(`Permission denied to access ${provider.url}.\n${reason}`);
|
|
46
|
+
/**
|
|
47
|
+
* @param {WebsocketProvider} provider
|
|
48
|
+
* @param {Uint8Array} buf
|
|
49
|
+
* @param {boolean} emitSynced
|
|
50
|
+
* @return {encoding.Encoder}
|
|
51
|
+
*/
|
|
52
|
+
const readMessage = (provider, buf, emitSynced) => {
|
|
53
|
+
const decoder = decoding.createDecoder(buf);
|
|
54
|
+
const encoder = encoding.createEncoder();
|
|
55
|
+
const messageType = decoding.readVarUint(decoder);
|
|
56
|
+
const messageIntegrator = provider.messageIntegrators[messageType];
|
|
57
|
+
if ( /** @type {any} */(messageIntegrator)) {
|
|
58
|
+
messageIntegrator(encoder, decoder, provider, emitSynced, messageType);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
console.error('Unable to compute message');
|
|
62
|
+
}
|
|
63
|
+
return encoder;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Outsource this function so that a new websocket connection is created immediately.
|
|
67
|
+
* I suspect that the `ws.onclose` event is not always fired if there are network issues.
|
|
68
|
+
*
|
|
69
|
+
* @param {WebsocketProvider} provider
|
|
70
|
+
* @param {WebSocket} ws
|
|
71
|
+
* @param {CloseEvent | null} event
|
|
72
|
+
*/
|
|
73
|
+
const closeWebsocketConnection = (provider, ws, event) => {
|
|
74
|
+
if (ws === provider.ws) {
|
|
75
|
+
provider.emit('connection-close', [event, provider]);
|
|
76
|
+
provider.ws = null;
|
|
77
|
+
ws.close();
|
|
78
|
+
provider.wsconnecting = false;
|
|
79
|
+
if (provider.wsconnected) {
|
|
80
|
+
provider.wsconnected = false;
|
|
81
|
+
provider.synced = false;
|
|
82
|
+
// update awareness (all users except local left)
|
|
83
|
+
awarenessProtocol.removeAwarenessStates(provider.awareness, Array.from(provider.awareness.getStates().keys()).filter((client) => client !== provider.doc.clientID), provider);
|
|
84
|
+
provider.emit('status', [{
|
|
85
|
+
status: 'disconnected'
|
|
86
|
+
}]);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
provider.wsUnsuccessfulReconnects++;
|
|
90
|
+
}
|
|
91
|
+
// Start with no reconnect timeout and increase timeout by
|
|
92
|
+
// using exponential backoff starting with 100ms
|
|
93
|
+
setTimeout(setupWS, math.min(math.pow(2, provider.wsUnsuccessfulReconnects) * 100, provider.maxBackoffTime), provider);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* @param {WebsocketProvider} provider
|
|
98
|
+
*/
|
|
99
|
+
const setupWS = (provider) => {
|
|
100
|
+
if (provider.shouldConnect && provider.ws === null) {
|
|
101
|
+
const websocket = new provider._WS(provider.url, provider.protocols);
|
|
102
|
+
websocket.binaryType = 'arraybuffer';
|
|
103
|
+
provider.ws = websocket;
|
|
104
|
+
provider.wsconnecting = true;
|
|
105
|
+
provider.wsconnected = false;
|
|
106
|
+
provider.synced = false;
|
|
107
|
+
websocket.onmessage = (event) => {
|
|
108
|
+
provider.wsLastMessageReceived = time.getUnixTime();
|
|
109
|
+
const encoder = readMessage(provider, new Uint8Array(event.data), true);
|
|
110
|
+
if (encoding.length(encoder) > 1) {
|
|
111
|
+
websocket.send(encoding.toUint8Array(encoder));
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
websocket.onerror = (event) => {
|
|
115
|
+
provider.emit('connection-error', [event, provider]);
|
|
116
|
+
};
|
|
117
|
+
websocket.onclose = (event) => {
|
|
118
|
+
closeWebsocketConnection(provider, websocket, event);
|
|
119
|
+
};
|
|
120
|
+
websocket.onopen = () => {
|
|
121
|
+
provider.wsLastMessageReceived = time.getUnixTime();
|
|
122
|
+
provider.wsconnecting = false;
|
|
123
|
+
provider.wsconnected = true;
|
|
124
|
+
provider.wsUnsuccessfulReconnects = 0;
|
|
125
|
+
provider.emit('status', [{
|
|
126
|
+
status: 'connected'
|
|
127
|
+
}]);
|
|
128
|
+
// always send sync step 1 when connected
|
|
129
|
+
const encoder = encoding.createEncoder();
|
|
130
|
+
encoding.writeVarUint(encoder, messageSync);
|
|
131
|
+
syncProtocol.writeSyncStep1(encoder, provider.doc);
|
|
132
|
+
websocket.send(encoding.toUint8Array(encoder));
|
|
133
|
+
// broadcast local awareness state
|
|
134
|
+
if (provider.awareness.getLocalState() !== null) {
|
|
135
|
+
const encoderAwarenessState = encoding.createEncoder();
|
|
136
|
+
encoding.writeVarUint(encoderAwarenessState, messageAwareness);
|
|
137
|
+
encoding.writeVarUint8Array(encoderAwarenessState, awarenessProtocol.encodeAwarenessUpdate(provider.awareness, [
|
|
138
|
+
provider.doc.clientID
|
|
139
|
+
]));
|
|
140
|
+
websocket.send(encoding.toUint8Array(encoderAwarenessState));
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
provider.emit('status', [{
|
|
144
|
+
status: 'connecting'
|
|
145
|
+
}]);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* @param {WebsocketProvider} provider
|
|
150
|
+
* @param {ArrayBuffer} buf
|
|
151
|
+
*/
|
|
152
|
+
const broadcastMessage = (provider, buf) => {
|
|
153
|
+
const ws = provider.ws;
|
|
154
|
+
if (provider.wsconnected && ws && ws.readyState === ws.OPEN) {
|
|
155
|
+
ws.send(buf);
|
|
156
|
+
}
|
|
157
|
+
if (provider.bcconnected) {
|
|
158
|
+
bc.publish(provider.bcChannel, buf, provider);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Websocket Provider for Yjs. Creates a websocket connection to sync the shared document.
|
|
163
|
+
* The document name is attached to the provided url. I.e. the following example
|
|
164
|
+
* creates a websocket connection to http://localhost:1234/my-document-name
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* import * as Y from 'yjs'
|
|
168
|
+
* import { WebsocketProvider } from 'y-websocket'
|
|
169
|
+
* const doc = new Y.Doc()
|
|
170
|
+
* const provider = new WebsocketProvider('http://localhost:1234', 'my-document-name', doc)
|
|
171
|
+
*
|
|
172
|
+
* @extends {ObservableV2<{ 'connection-close': (event: CloseEvent | null, provider: WebsocketProvider) => any, 'status': (event: { status: 'connected' | 'disconnected' | 'connecting' }) => any, 'connection-error': (event: Event, provider: WebsocketProvider) => any, 'sync': (state: boolean) => any }>}
|
|
173
|
+
*/
|
|
174
|
+
export class WebsocketProvider extends ObservableV2 {
|
|
175
|
+
serverUrl = '';
|
|
176
|
+
roomname = '';
|
|
177
|
+
doc = null;
|
|
178
|
+
_WS = null;
|
|
179
|
+
protocols = [];
|
|
180
|
+
params = {};
|
|
181
|
+
awareness = null;
|
|
182
|
+
ws = null;
|
|
183
|
+
wsconnected = false;
|
|
184
|
+
wsconnecting = false;
|
|
185
|
+
bcconnected = false;
|
|
186
|
+
disableBc = false;
|
|
187
|
+
bcChannel = '';
|
|
188
|
+
maxBackoffTime = 2500;
|
|
189
|
+
wsUnsuccessfulReconnects = 0;
|
|
190
|
+
messageIntegrators = [];
|
|
191
|
+
_synced = false;
|
|
192
|
+
wsLastMessageReceived = 0;
|
|
193
|
+
shouldConnect = false;
|
|
194
|
+
_checkInterval = null;
|
|
195
|
+
_resyncInterval = null;
|
|
196
|
+
_updateIntegrator = null;
|
|
197
|
+
_awarenessUpdateIntegrator = null;
|
|
198
|
+
_exitIntegrator = null;
|
|
199
|
+
_bcSubscriber = null;
|
|
200
|
+
/**
|
|
201
|
+
* @param {string} serverUrl
|
|
202
|
+
* @param {string} roomname
|
|
203
|
+
* @param {Y.Doc} doc
|
|
204
|
+
* @param {object} opts
|
|
205
|
+
* @param {boolean} [opts.connect]
|
|
206
|
+
* @param {awarenessProtocol.Awareness} [opts.awareness]
|
|
207
|
+
* @param {Object<string,string>} [opts.params] specify url parameters
|
|
208
|
+
* @param {Array<string>} [opts.protocols] specify websocket protocols
|
|
209
|
+
* @param {typeof WebSocket} [opts.WebSocketPolyfill] Optionall provide a WebSocket polyfill
|
|
210
|
+
* @param {number} [opts.resyncInterval] Request server state every `resyncInterval` milliseconds
|
|
211
|
+
* @param {number} [opts.maxBackoffTime] Maximum amount of time to wait before trying to reconnect (we try to reconnect using exponential backoff)
|
|
212
|
+
* @param {boolean} [opts.disableBc] Disable cross-tab BroadcastChannel communication
|
|
213
|
+
*/
|
|
214
|
+
constructor(serverUrl, roomname, doc, { connect = true, awareness = new awarenessProtocol.Awareness(doc), params = {}, protocols = [], WebSocketPolyfill = WebSocket, resyncInterval = -1, maxBackoffTime = 2500, disableBc = false } = {}) {
|
|
215
|
+
super();
|
|
216
|
+
// ensure that serverUrl does not end with /
|
|
217
|
+
while (serverUrl[serverUrl.length - 1] === '/') {
|
|
218
|
+
serverUrl = serverUrl.slice(0, serverUrl.length - 1);
|
|
219
|
+
}
|
|
220
|
+
this.serverUrl = serverUrl;
|
|
221
|
+
this.bcChannel = serverUrl + '/' + roomname;
|
|
222
|
+
this.maxBackoffTime = maxBackoffTime;
|
|
223
|
+
/**
|
|
224
|
+
* The specified url parameters. This can be safely updated. The changed parameters will be used
|
|
225
|
+
* when a new connection is established.
|
|
226
|
+
* @type {Object<string,string>}
|
|
227
|
+
*/
|
|
228
|
+
this.params = params;
|
|
229
|
+
this.protocols = protocols;
|
|
230
|
+
this.roomname = roomname;
|
|
231
|
+
this.doc = doc;
|
|
232
|
+
this._WS = WebSocketPolyfill;
|
|
233
|
+
this.awareness = awareness;
|
|
234
|
+
this.wsconnected = false;
|
|
235
|
+
this.wsconnecting = false;
|
|
236
|
+
this.bcconnected = false;
|
|
237
|
+
this.disableBc = disableBc;
|
|
238
|
+
this.wsUnsuccessfulReconnects = 0;
|
|
239
|
+
this.messageIntegrators = messageIntegrators.slice();
|
|
240
|
+
/**
|
|
241
|
+
* @type {boolean}
|
|
242
|
+
*/
|
|
243
|
+
this._synced = false;
|
|
244
|
+
/**
|
|
245
|
+
* @type {WebSocket?}
|
|
246
|
+
*/
|
|
247
|
+
this.ws = null;
|
|
248
|
+
this.wsLastMessageReceived = 0;
|
|
249
|
+
/**
|
|
250
|
+
* Whether to connect to other peers or not
|
|
251
|
+
* @type {boolean}
|
|
252
|
+
*/
|
|
253
|
+
this.shouldConnect = connect;
|
|
254
|
+
/**
|
|
255
|
+
* @type {number}
|
|
256
|
+
*/
|
|
257
|
+
this._resyncInterval = 0;
|
|
258
|
+
if (resyncInterval > 0) {
|
|
259
|
+
this._resyncInterval = /** @type {any} */ (setInterval(() => {
|
|
260
|
+
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
|
261
|
+
// resend sync step 1
|
|
262
|
+
const encoder = encoding.createEncoder();
|
|
263
|
+
encoding.writeVarUint(encoder, messageSync);
|
|
264
|
+
syncProtocol.writeSyncStep1(encoder, doc);
|
|
265
|
+
this.ws.send(encoding.toUint8Array(encoder));
|
|
266
|
+
}
|
|
267
|
+
}, resyncInterval));
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* @param {ArrayBuffer} data
|
|
271
|
+
* @param {any} origin
|
|
272
|
+
*/
|
|
273
|
+
this._bcSubscriber = (data, origin) => {
|
|
274
|
+
if (origin !== this) {
|
|
275
|
+
const encoder = readMessage(this, new Uint8Array(data), false);
|
|
276
|
+
if (encoding.length(encoder) > 1) {
|
|
277
|
+
bc.publish(this.bcChannel, encoding.toUint8Array(encoder), this);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
/**
|
|
282
|
+
* Listens to Yjs updates and sends them to remote peers (ws and broadcastchannel)
|
|
283
|
+
* @param {Uint8Array} update
|
|
284
|
+
* @param {any} origin
|
|
285
|
+
*/
|
|
286
|
+
this._updateIntegrator = (update, origin) => {
|
|
287
|
+
if (origin !== this) {
|
|
288
|
+
const encoder = encoding.createEncoder();
|
|
289
|
+
encoding.writeVarUint(encoder, messageSync);
|
|
290
|
+
syncProtocol.writeUpdate(encoder, update);
|
|
291
|
+
broadcastMessage(this, encoding.toUint8Array(encoder));
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
this.doc.on('update', this._updateIntegrator);
|
|
295
|
+
/**
|
|
296
|
+
* @param {any} changed
|
|
297
|
+
* @param {any} _origin
|
|
298
|
+
*/
|
|
299
|
+
this._awarenessUpdateIntegrator = ({ added, updated, removed }, _origin) => {
|
|
300
|
+
const changedClients = added.concat(updated).concat(removed);
|
|
301
|
+
const encoder = encoding.createEncoder();
|
|
302
|
+
encoding.writeVarUint(encoder, messageAwareness);
|
|
303
|
+
encoding.writeVarUint8Array(encoder, awarenessProtocol.encodeAwarenessUpdate(awareness, changedClients));
|
|
304
|
+
broadcastMessage(this, encoding.toUint8Array(encoder));
|
|
305
|
+
};
|
|
306
|
+
this._exitIntegrator = () => {
|
|
307
|
+
awarenessProtocol.removeAwarenessStates(this.awareness, [doc.clientID], 'app closed');
|
|
308
|
+
};
|
|
309
|
+
if (env.isNode && typeof process !== 'undefined') {
|
|
310
|
+
process.on('exit', this._exitIntegrator);
|
|
311
|
+
}
|
|
312
|
+
awareness.on('update', this._awarenessUpdateIntegrator);
|
|
313
|
+
this._checkInterval = /** @type {any} */ (setInterval(() => {
|
|
314
|
+
if (this.wsconnected &&
|
|
315
|
+
messageReconnectTimeout <
|
|
316
|
+
time.getUnixTime() - this.wsLastMessageReceived) {
|
|
317
|
+
// no message received in a long time - not even your own awareness
|
|
318
|
+
// updates (which are updated every 15 seconds)
|
|
319
|
+
closeWebsocketConnection(this, /** @type {WebSocket} */ (this.ws), null);
|
|
320
|
+
}
|
|
321
|
+
}, messageReconnectTimeout / 10));
|
|
322
|
+
if (connect) {
|
|
323
|
+
this.connect();
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
get url() {
|
|
327
|
+
const encodedParams = url.encodeQueryParams(this.params);
|
|
328
|
+
return this.serverUrl + '/' + this.roomname +
|
|
329
|
+
(encodedParams.length === 0 ? '' : '?' + encodedParams);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* @type {boolean}
|
|
333
|
+
*/
|
|
334
|
+
get synced() {
|
|
335
|
+
return this._synced;
|
|
336
|
+
}
|
|
337
|
+
set synced(state) {
|
|
338
|
+
if (this._synced !== state) {
|
|
339
|
+
this._synced = state;
|
|
340
|
+
super.emit('synced', [state]);
|
|
341
|
+
super.emit('sync', [state]);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
destroy() {
|
|
345
|
+
if (this._resyncInterval !== 0) {
|
|
346
|
+
clearInterval(this._resyncInterval);
|
|
347
|
+
}
|
|
348
|
+
clearInterval(this._checkInterval);
|
|
349
|
+
this.disconnect();
|
|
350
|
+
if (env.isNode && typeof process !== 'undefined') {
|
|
351
|
+
process.off('exit', this._exitIntegrator);
|
|
352
|
+
}
|
|
353
|
+
this.awareness.off('update', this._awarenessUpdateIntegrator);
|
|
354
|
+
this.doc.off('update', this._updateIntegrator);
|
|
355
|
+
super.destroy();
|
|
356
|
+
}
|
|
357
|
+
connectBc() {
|
|
358
|
+
if (this.disableBc) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
if (!this.bcconnected) {
|
|
362
|
+
bc.subscribe(this.bcChannel, this._bcSubscriber);
|
|
363
|
+
this.bcconnected = true;
|
|
364
|
+
}
|
|
365
|
+
// send sync step1 to bc
|
|
366
|
+
// write sync step 1
|
|
367
|
+
const encoderSync = encoding.createEncoder();
|
|
368
|
+
encoding.writeVarUint(encoderSync, messageSync);
|
|
369
|
+
syncProtocol.writeSyncStep1(encoderSync, this.doc);
|
|
370
|
+
bc.publish(this.bcChannel, encoding.toUint8Array(encoderSync), this);
|
|
371
|
+
// broadcast local state
|
|
372
|
+
const encoderState = encoding.createEncoder();
|
|
373
|
+
encoding.writeVarUint(encoderState, messageSync);
|
|
374
|
+
syncProtocol.writeSyncStep2(encoderState, this.doc);
|
|
375
|
+
bc.publish(this.bcChannel, encoding.toUint8Array(encoderState), this);
|
|
376
|
+
// write queryAwareness
|
|
377
|
+
const encoderAwarenessQuery = encoding.createEncoder();
|
|
378
|
+
encoding.writeVarUint(encoderAwarenessQuery, messageQueryAwareness);
|
|
379
|
+
bc.publish(this.bcChannel, encoding.toUint8Array(encoderAwarenessQuery), this);
|
|
380
|
+
// broadcast local awareness state
|
|
381
|
+
const encoderAwarenessState = encoding.createEncoder();
|
|
382
|
+
encoding.writeVarUint(encoderAwarenessState, messageAwareness);
|
|
383
|
+
encoding.writeVarUint8Array(encoderAwarenessState, awarenessProtocol.encodeAwarenessUpdate(this.awareness, [
|
|
384
|
+
this.doc.clientID
|
|
385
|
+
]));
|
|
386
|
+
bc.publish(this.bcChannel, encoding.toUint8Array(encoderAwarenessState), this);
|
|
387
|
+
}
|
|
388
|
+
disconnectBc() {
|
|
389
|
+
// broadcast message with local awareness state set to null (indicating disconnect)
|
|
390
|
+
const encoder = encoding.createEncoder();
|
|
391
|
+
encoding.writeVarUint(encoder, messageAwareness);
|
|
392
|
+
encoding.writeVarUint8Array(encoder, awarenessProtocol.encodeAwarenessUpdate(this.awareness, [
|
|
393
|
+
this.doc.clientID
|
|
394
|
+
], new Map()));
|
|
395
|
+
broadcastMessage(this, encoding.toUint8Array(encoder));
|
|
396
|
+
if (this.bcconnected) {
|
|
397
|
+
bc.unsubscribe(this.bcChannel, this._bcSubscriber);
|
|
398
|
+
this.bcconnected = false;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
disconnect() {
|
|
402
|
+
this.shouldConnect = false;
|
|
403
|
+
this.disconnectBc();
|
|
404
|
+
if (this.ws !== null) {
|
|
405
|
+
closeWebsocketConnection(this, this.ws, null);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
connect() {
|
|
409
|
+
this.shouldConnect = true;
|
|
410
|
+
if (!this.wsconnected && this.ws === null) {
|
|
411
|
+
setupWS(this);
|
|
412
|
+
this.connectBc();
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import http from 'http';
|
|
2
|
+
import * as number from 'lib0/number';
|
|
3
|
+
const CALLBACK_URL = process.env.CALLBACK_URL ? new URL(process.env.CALLBACK_URL) : null;
|
|
4
|
+
const CALLBACK_TIMEOUT = number.parseInt(process.env.CALLBACK_TIMEOUT || '5000');
|
|
5
|
+
const CALLBACK_OBJECTS = process.env.CALLBACK_OBJECTS ? JSON.parse(process.env.CALLBACK_OBJECTS) : {};
|
|
6
|
+
export const isCallbackSet = !!CALLBACK_URL;
|
|
7
|
+
/**
|
|
8
|
+
* @param {import('./utils.js').WSSharedDoc} doc
|
|
9
|
+
*/
|
|
10
|
+
export const callbackIntegrator = (doc) => {
|
|
11
|
+
const room = doc.name;
|
|
12
|
+
const dataToSend = {
|
|
13
|
+
room,
|
|
14
|
+
data: {}
|
|
15
|
+
};
|
|
16
|
+
const sharedObjectList = Object.keys(CALLBACK_OBJECTS);
|
|
17
|
+
sharedObjectList.forEach(sharedObjectName => {
|
|
18
|
+
const sharedObjectType = CALLBACK_OBJECTS[sharedObjectName];
|
|
19
|
+
dataToSend.data[sharedObjectName] = {
|
|
20
|
+
type: sharedObjectType,
|
|
21
|
+
content: getContent(sharedObjectName, sharedObjectType, doc).toJSON()
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
if (CALLBACK_URL) {
|
|
25
|
+
callbackRequest(CALLBACK_URL, CALLBACK_TIMEOUT, dataToSend);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* @param {URL} url
|
|
30
|
+
* @param {number} timeout
|
|
31
|
+
* @param {Object} data
|
|
32
|
+
*/
|
|
33
|
+
const callbackRequest = (url, timeout, data) => {
|
|
34
|
+
data = JSON.stringify(data);
|
|
35
|
+
const options = {
|
|
36
|
+
hostname: url.hostname,
|
|
37
|
+
port: url.port,
|
|
38
|
+
path: url.pathname,
|
|
39
|
+
timeout,
|
|
40
|
+
method: 'POST',
|
|
41
|
+
headers: {
|
|
42
|
+
'Content-Type': 'application/json',
|
|
43
|
+
'Content-Length': Buffer.byteLength(data)
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const req = http.request(options);
|
|
47
|
+
req.on('timeout', () => {
|
|
48
|
+
console.warn('Callback request timed out.');
|
|
49
|
+
req.abort();
|
|
50
|
+
});
|
|
51
|
+
req.on('error', (e) => {
|
|
52
|
+
console.error('Callback request error.', e);
|
|
53
|
+
req.abort();
|
|
54
|
+
});
|
|
55
|
+
req.write(data);
|
|
56
|
+
req.end();
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* @param {string} objName
|
|
60
|
+
* @param {string} objType
|
|
61
|
+
* @param {import('./utils.js').WSSharedDoc} doc
|
|
62
|
+
*/
|
|
63
|
+
const getContent = (objName, objType, doc) => {
|
|
64
|
+
switch (objType) {
|
|
65
|
+
case 'Array': return doc.getArray(objName);
|
|
66
|
+
case 'Map': return doc.getMap(objName);
|
|
67
|
+
case 'Text': return doc.getText(objName);
|
|
68
|
+
case 'XmlFragment': return doc.getXmlFragment(objName);
|
|
69
|
+
case 'XmlElement': return doc.getXmlElement(objName);
|
|
70
|
+
default: return {};
|
|
71
|
+
}
|
|
72
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { WebSocketServer } from 'ws';
|
|
3
|
+
import http from 'http';
|
|
4
|
+
import * as number from 'lib0/number';
|
|
5
|
+
import { setupWSConnection } from './utils';
|
|
6
|
+
const wss = new WebSocketServer({ noServer: true });
|
|
7
|
+
const host = process.env.HOST || 'localhost';
|
|
8
|
+
const port = number.parseInt(process.env.PORT || '1234');
|
|
9
|
+
const server = http.createServer((_request, response) => {
|
|
10
|
+
response.writeHead(200, { 'Content-Type': 'text/plain' });
|
|
11
|
+
response.end('okay');
|
|
12
|
+
});
|
|
13
|
+
wss.on('connection', setupWSConnection);
|
|
14
|
+
server.on('upgrade', (request, socket, head) => {
|
|
15
|
+
// You may check auth of request here..
|
|
16
|
+
// Call `wss.HandleUpgrade` *after* you checked whether the client has access
|
|
17
|
+
// (e.g. by checking cookies, or url parameters).
|
|
18
|
+
// See https://github.com/websockets/ws#client-authentication
|
|
19
|
+
wss.handleUpgrade(request, socket, head, /** @param {any} ws */ /** @param {any} ws */ ws => {
|
|
20
|
+
wss.emit('connection', ws, request);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
server.listen(port, host, () => {
|
|
24
|
+
console.log(`running at '${host}' on port ${port}`);
|
|
25
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as Y from 'yjs';
|
|
2
|
+
/**
|
|
3
|
+
* @param {{bindState: function(string,WSSharedDoc):void,
|
|
4
|
+
* writeState:function(string,WSSharedDoc):Promise<any>,provider:any}|null} persistence_
|
|
5
|
+
*/
|
|
6
|
+
export declare const setPersistence: (persistence_: any) => void;
|
|
7
|
+
/**
|
|
8
|
+
* @return {null|{bindState: function(string,WSSharedDoc):void,
|
|
9
|
+
* writeState:function(string,WSSharedDoc):Promise<any>}|null} used persistence layer
|
|
10
|
+
*/
|
|
11
|
+
export declare const getPersistence: () => any;
|
|
12
|
+
/**
|
|
13
|
+
* @type {Map<string,WSSharedDoc>}
|
|
14
|
+
*/
|
|
15
|
+
export declare const docs: Map<any, any>;
|
|
16
|
+
/**
|
|
17
|
+
* This function is called once every time a Yjs document is created. You can
|
|
18
|
+
* use it to pull data from an external source or initialize content.
|
|
19
|
+
*
|
|
20
|
+
* @param {(ydoc: Y.Doc) => Promise<void>} f
|
|
21
|
+
*/
|
|
22
|
+
export declare const setContentInitializor: (f: any) => void;
|
|
23
|
+
export declare class WSSharedDoc extends Y.Doc {
|
|
24
|
+
name: string;
|
|
25
|
+
conns: any;
|
|
26
|
+
awareness: any;
|
|
27
|
+
whenInitialized: any;
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} name
|
|
30
|
+
*/
|
|
31
|
+
constructor(name: any);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Gets a Y.Doc by name, whether in memory or on disk
|
|
35
|
+
*
|
|
36
|
+
* @param {string} docname - the name of the Y.Doc to find or create
|
|
37
|
+
* @param {boolean} gc - whether to allow gc on the doc (applies only when created)
|
|
38
|
+
* @return {WSSharedDoc}
|
|
39
|
+
*/
|
|
40
|
+
export declare const getYDoc: (docname: any, gc?: boolean) => WSSharedDoc;
|
|
41
|
+
/**
|
|
42
|
+
* @param {import('ws').WebSocket} conn
|
|
43
|
+
* @param {import('http').IncomingMessage} req
|
|
44
|
+
* @param {any} opts
|
|
45
|
+
*/
|
|
46
|
+
export declare const setupWSConnection: (conn: any, req: any, { docName, gc }?: {
|
|
47
|
+
docName?: any;
|
|
48
|
+
gc?: boolean;
|
|
49
|
+
}) => void;
|