@dxos/react-ui-editor 0.8.4-main.84f28bd → 0.8.4-main.ae835ea
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/dist/lib/browser/{chunk-22UMM3QJ.mjs → chunk-HL3YF6WC.mjs} +2 -2
- package/dist/lib/browser/chunk-HL3YF6WC.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +4225 -3369
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +71 -1
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node-esm/{chunk-YXYQPV6R.mjs → chunk-YJZGD3LY.mjs} +2 -2
- package/dist/lib/node-esm/chunk-YJZGD3LY.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +4225 -3369
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +71 -1
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/types/index.mjs +1 -1
- package/dist/types/src/components/Editor/Editor.d.ts +24 -9
- package/dist/types/src/components/Editor/Editor.d.ts.map +1 -1
- package/dist/types/src/components/Editor/Editor.stories.d.ts +27 -0
- package/dist/types/src/components/Editor/Editor.stories.d.ts.map +1 -0
- package/dist/types/src/components/EditorToolbar/EditorToolbar.d.ts +17 -2
- package/dist/types/src/components/EditorToolbar/EditorToolbar.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/blocks.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/formatting.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/headings.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/image.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/lists.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/search.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/util.d.ts +6 -20
- package/dist/types/src/components/EditorToolbar/util.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/view-mode.d.ts +1 -1
- package/dist/types/src/components/EditorToolbar/view-mode.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +0 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/defaults.d.ts.map +1 -1
- package/dist/types/src/extensions/autocomplete/autocomplete.d.ts +26 -0
- package/dist/types/src/extensions/autocomplete/autocomplete.d.ts.map +1 -0
- package/dist/types/src/extensions/autocomplete/index.d.ts +5 -0
- package/dist/types/src/extensions/autocomplete/index.d.ts.map +1 -0
- package/dist/types/src/extensions/autocomplete/match.d.ts +13 -0
- package/dist/types/src/extensions/autocomplete/match.d.ts.map +1 -0
- package/dist/types/src/extensions/autocomplete/placeholder.d.ts +20 -0
- package/dist/types/src/extensions/autocomplete/placeholder.d.ts.map +1 -0
- package/dist/types/src/extensions/autocomplete/typeahead.d.ts +10 -0
- package/dist/types/src/extensions/autocomplete/typeahead.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/automerge.d.ts +1 -1
- package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.stories.d.ts +10 -19
- package/dist/types/src/extensions/automerge/automerge.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/cursor.d.ts +1 -1
- package/dist/types/src/extensions/automerge/cursor.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/defs.d.ts +1 -1
- package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/sync.d.ts +3 -3
- package/dist/types/src/extensions/automerge/sync.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/update-automerge.d.ts +1 -1
- package/dist/types/src/extensions/automerge/update-automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/autoscroll.d.ts +10 -0
- package/dist/types/src/extensions/autoscroll.d.ts.map +1 -0
- package/dist/types/src/extensions/awareness/awareness-provider.d.ts +1 -1
- package/dist/types/src/extensions/awareness/awareness-provider.d.ts.map +1 -1
- package/dist/types/src/extensions/comments.d.ts +1 -1
- package/dist/types/src/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/extensions/dnd.d.ts.map +1 -1
- package/dist/types/src/extensions/factories.d.ts +20 -19
- package/dist/types/src/extensions/factories.d.ts.map +1 -1
- package/dist/types/src/extensions/focus.d.ts.map +1 -1
- package/dist/types/src/extensions/folding.d.ts.map +1 -1
- package/dist/types/src/extensions/index.d.ts +4 -1
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/dist/types/src/extensions/json.d.ts +1 -1
- package/dist/types/src/extensions/json.d.ts.map +1 -1
- package/dist/types/src/extensions/listener.d.ts +8 -6
- package/dist/types/src/extensions/listener.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/action.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/bundle.d.ts +8 -2
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/changes.d.ts +1 -1
- package/dist/types/src/extensions/markdown/changes.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/decorate.d.ts +9 -1
- package/dist/types/src/extensions/markdown/decorate.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/formatting.d.ts +2 -3
- package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/formatting.test.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/image.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/link.d.ts.map +1 -1
- package/dist/types/src/extensions/modes.d.ts +1 -1
- package/dist/types/src/extensions/modes.d.ts.map +1 -1
- package/dist/types/src/extensions/outliner/menu.d.ts +8 -0
- package/dist/types/src/extensions/outliner/menu.d.ts.map +1 -0
- package/dist/types/src/extensions/outliner/outliner.d.ts +1 -1
- package/dist/types/src/extensions/outliner/outliner.d.ts.map +1 -1
- package/dist/types/src/extensions/outliner/selection.d.ts.map +1 -1
- package/dist/types/src/extensions/outliner/tree.d.ts +2 -2
- package/dist/types/src/extensions/outliner/tree.d.ts.map +1 -1
- package/dist/types/src/extensions/popover/PopoverMenuProvider.d.ts +36 -0
- package/dist/types/src/extensions/popover/PopoverMenuProvider.d.ts.map +1 -0
- package/dist/types/src/extensions/popover/index.d.ts +8 -0
- package/dist/types/src/extensions/popover/index.d.ts.map +1 -0
- package/dist/types/src/extensions/popover/menu-presets.d.ts +4 -0
- package/dist/types/src/extensions/popover/menu-presets.d.ts.map +1 -0
- package/dist/types/src/extensions/popover/menu.d.ts +24 -0
- package/dist/types/src/extensions/popover/menu.d.ts.map +1 -0
- package/dist/types/src/extensions/popover/modal.d.ts +7 -0
- package/dist/types/src/extensions/popover/modal.d.ts.map +1 -0
- package/dist/types/src/extensions/popover/popover.d.ts +47 -0
- package/dist/types/src/extensions/popover/popover.d.ts.map +1 -0
- package/dist/types/src/extensions/popover/usePopoverMenu.d.ts +34 -0
- package/dist/types/src/extensions/popover/usePopoverMenu.d.ts.map +1 -0
- package/dist/types/src/extensions/popover/util.d.ts +8 -0
- package/dist/types/src/extensions/popover/util.d.ts.map +1 -0
- package/dist/types/src/extensions/preview/preview.d.ts +8 -8
- package/dist/types/src/extensions/preview/preview.d.ts.map +1 -1
- package/dist/types/src/extensions/state.d.ts +2 -0
- package/dist/types/src/extensions/state.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/extended-markdown.d.ts +10 -0
- package/dist/types/src/extensions/tags/extended-markdown.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/extended-markdown.test.d.ts +2 -0
- package/dist/types/src/extensions/tags/extended-markdown.test.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/index.d.ts +4 -0
- package/dist/types/src/extensions/tags/index.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/streamer.d.ts +12 -0
- package/dist/types/src/extensions/tags/streamer.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/xml-tags.d.ts +72 -0
- package/dist/types/src/extensions/tags/xml-tags.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/xml-util.d.ts +10 -0
- package/dist/types/src/extensions/tags/xml-util.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextEditor.d.ts +4 -8
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
- package/dist/types/src/stories/CommandDialog.stories.d.ts +14 -0
- package/dist/types/src/stories/CommandDialog.stories.d.ts.map +1 -0
- package/dist/types/src/stories/Comments.stories.d.ts +21 -10
- package/dist/types/src/stories/Comments.stories.d.ts.map +1 -1
- package/dist/types/src/stories/EditorToolbar.stories.d.ts +39 -3
- package/dist/types/src/stories/EditorToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Experimental.stories.d.ts +22 -13
- package/dist/types/src/stories/Experimental.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Markdown.stories.d.ts +32 -43
- package/dist/types/src/stories/Markdown.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Outliner.stories.d.ts +15 -21
- package/dist/types/src/stories/Outliner.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Popover.stories.d.ts +20 -0
- package/dist/types/src/stories/Popover.stories.d.ts.map +1 -0
- package/dist/types/src/stories/Preview.stories.d.ts +21 -7
- package/dist/types/src/stories/Preview.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Tags.stories.d.ts +16 -0
- package/dist/types/src/stories/Tags.stories.d.ts.map +1 -0
- package/dist/types/src/stories/TextEditor.stories.d.ts +37 -52
- package/dist/types/src/stories/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/stories/components/EditorStory.d.ts +6 -9
- package/dist/types/src/stories/components/EditorStory.d.ts.map +1 -1
- package/dist/types/src/styles/theme.d.ts.map +1 -1
- package/dist/types/src/testing/PreviewPopover.d.ts +20 -0
- package/dist/types/src/testing/PreviewPopover.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +1 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts +1 -0
- package/dist/types/src/testing/util.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +1 -1
- package/dist/types/src/types/types.d.ts +2 -2
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/src/util/cursor.d.ts.map +1 -1
- package/dist/types/src/util/debug.d.ts +1 -1
- package/dist/types/src/util/debug.d.ts.map +1 -1
- package/dist/types/src/util/decorations.d.ts +4 -0
- package/dist/types/src/util/decorations.d.ts.map +1 -0
- package/dist/types/src/util/dom.d.ts +2 -12
- package/dist/types/src/util/dom.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +1 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/react.d.ts +1 -1
- package/dist/types/src/util/react.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +71 -61
- package/src/components/Editor/Editor.stories.tsx +69 -0
- package/src/components/Editor/Editor.tsx +58 -15
- package/src/components/EditorToolbar/EditorToolbar.tsx +104 -93
- package/src/components/EditorToolbar/blocks.ts +22 -25
- package/src/components/EditorToolbar/formatting.ts +22 -25
- package/src/components/EditorToolbar/headings.ts +16 -9
- package/src/components/EditorToolbar/image.ts +8 -4
- package/src/components/EditorToolbar/lists.ts +16 -19
- package/src/components/EditorToolbar/search.ts +8 -4
- package/src/components/EditorToolbar/util.ts +18 -23
- package/src/components/EditorToolbar/view-mode.ts +11 -6
- package/src/components/index.ts +0 -1
- package/src/defaults.ts +5 -2
- package/src/extensions/autocomplete/autocomplete.ts +220 -0
- package/src/extensions/autocomplete/index.ts +8 -0
- package/src/extensions/autocomplete/match.ts +46 -0
- package/src/extensions/{command → autocomplete}/placeholder.ts +22 -18
- package/src/extensions/{command → autocomplete}/typeahead.ts +8 -50
- package/src/extensions/automerge/automerge.stories.tsx +31 -24
- package/src/extensions/automerge/automerge.ts +31 -11
- package/src/extensions/automerge/cursor.ts +1 -1
- package/src/extensions/automerge/defs.ts +1 -1
- package/src/extensions/automerge/sync.ts +9 -5
- package/src/extensions/automerge/update-automerge.ts +2 -2
- package/src/extensions/autoscroll.ts +157 -0
- package/src/extensions/awareness/awareness-provider.ts +2 -2
- package/src/extensions/awareness/awareness.ts +2 -2
- package/src/extensions/comments.ts +18 -13
- package/src/extensions/dnd.ts +1 -1
- package/src/extensions/factories.ts +55 -37
- package/src/extensions/focus.ts +5 -4
- package/src/extensions/folding.tsx +4 -6
- package/src/extensions/hashtag.tsx +2 -2
- package/src/extensions/index.ts +4 -1
- package/src/extensions/json.ts +1 -1
- package/src/extensions/listener.ts +14 -20
- package/src/extensions/markdown/action.ts +2 -1
- package/src/extensions/markdown/bundle.ts +40 -6
- package/src/extensions/markdown/changes.ts +1 -1
- package/src/extensions/markdown/decorate.ts +24 -14
- package/src/extensions/markdown/formatting.test.ts +6 -6
- package/src/extensions/markdown/formatting.ts +11 -11
- package/src/extensions/markdown/highlight.ts +1 -1
- package/src/extensions/markdown/image.ts +3 -4
- package/src/extensions/markdown/link.ts +3 -0
- package/src/extensions/markdown/table.ts +7 -1
- package/src/extensions/mention.ts +1 -1
- package/src/extensions/modes.ts +2 -2
- package/src/extensions/{command/floating-menu.ts → outliner/menu.ts} +16 -21
- package/src/extensions/outliner/outliner.test.ts +3 -2
- package/src/extensions/outliner/outliner.ts +7 -6
- package/src/extensions/outliner/selection.ts +1 -1
- package/src/extensions/outliner/tree.test.ts +2 -1
- package/src/extensions/outliner/tree.ts +2 -2
- package/src/extensions/popover/PopoverMenuProvider.tsx +220 -0
- package/src/extensions/popover/index.ts +12 -0
- package/src/extensions/popover/menu-presets.ts +124 -0
- package/src/extensions/popover/menu.ts +67 -0
- package/src/extensions/popover/modal.ts +24 -0
- package/src/extensions/popover/popover.ts +289 -0
- package/src/extensions/popover/usePopoverMenu.ts +173 -0
- package/src/extensions/popover/util.ts +29 -0
- package/src/extensions/preview/index.ts +1 -1
- package/src/extensions/preview/preview.ts +67 -67
- package/src/extensions/selection.ts +2 -2
- package/src/extensions/state.ts +7 -0
- package/src/extensions/tags/extended-markdown.test.ts +261 -0
- package/src/extensions/tags/extended-markdown.ts +78 -0
- package/src/extensions/tags/index.ts +7 -0
- package/src/extensions/tags/streamer.ts +243 -0
- package/src/extensions/tags/xml-tags.ts +393 -0
- package/src/extensions/tags/xml-util.ts +94 -0
- package/src/hooks/useTextEditor.ts +27 -39
- package/src/stories/CommandDialog.stories.tsx +78 -0
- package/src/stories/Comments.stories.tsx +14 -10
- package/src/stories/EditorToolbar.stories.tsx +17 -17
- package/src/stories/Experimental.stories.tsx +17 -13
- package/src/stories/Markdown.stories.tsx +25 -21
- package/src/stories/Outliner.stories.tsx +54 -35
- package/src/stories/Popover.stories.tsx +163 -0
- package/src/stories/Preview.stories.tsx +49 -41
- package/src/stories/Tags.stories.tsx +81 -0
- package/src/stories/TextEditor.stories.tsx +41 -60
- package/src/stories/components/EditorStory.tsx +17 -16
- package/src/styles/theme.ts +18 -15
- package/src/testing/PreviewPopover.tsx +80 -0
- package/src/testing/index.ts +1 -0
- package/src/testing/util.ts +2 -0
- package/src/translations.ts +1 -1
- package/src/types/types.ts +1 -1
- package/src/util/cursor.ts +2 -1
- package/src/util/debug.ts +2 -2
- package/src/util/decorations.ts +21 -0
- package/src/util/dom.ts +5 -27
- package/src/util/index.ts +1 -0
- package/src/util/react.tsx +1 -1
- package/dist/lib/browser/chunk-22UMM3QJ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YXYQPV6R.mjs.map +0 -7
- package/dist/types/src/components/Popover/CommandMenu.d.ts +0 -34
- package/dist/types/src/components/Popover/CommandMenu.d.ts.map +0 -1
- package/dist/types/src/components/Popover/RefDropdownMenu.d.ts +0 -21
- package/dist/types/src/components/Popover/RefDropdownMenu.d.ts.map +0 -1
- package/dist/types/src/components/Popover/RefPopover.d.ts +0 -34
- package/dist/types/src/components/Popover/RefPopover.d.ts.map +0 -1
- package/dist/types/src/components/Popover/index.d.ts +0 -4
- package/dist/types/src/components/Popover/index.d.ts.map +0 -1
- package/dist/types/src/extensions/autocomplete.d.ts +0 -13
- package/dist/types/src/extensions/autocomplete.d.ts.map +0 -1
- package/dist/types/src/extensions/command/action.d.ts +0 -17
- package/dist/types/src/extensions/command/action.d.ts.map +0 -1
- package/dist/types/src/extensions/command/command-menu.d.ts +0 -20
- package/dist/types/src/extensions/command/command-menu.d.ts.map +0 -1
- package/dist/types/src/extensions/command/command.d.ts +0 -6
- package/dist/types/src/extensions/command/command.d.ts.map +0 -1
- package/dist/types/src/extensions/command/floating-menu.d.ts +0 -7
- package/dist/types/src/extensions/command/floating-menu.d.ts.map +0 -1
- package/dist/types/src/extensions/command/hint.d.ts +0 -24
- package/dist/types/src/extensions/command/hint.d.ts.map +0 -1
- package/dist/types/src/extensions/command/index.d.ts +0 -7
- package/dist/types/src/extensions/command/index.d.ts.map +0 -1
- package/dist/types/src/extensions/command/placeholder.d.ts +0 -10
- package/dist/types/src/extensions/command/placeholder.d.ts.map +0 -1
- package/dist/types/src/extensions/command/state.d.ts +0 -16
- package/dist/types/src/extensions/command/state.d.ts.map +0 -1
- package/dist/types/src/extensions/command/typeahead.d.ts +0 -22
- package/dist/types/src/extensions/command/typeahead.d.ts.map +0 -1
- package/dist/types/src/extensions/command/useCommandMenu.d.ts +0 -26
- package/dist/types/src/extensions/command/useCommandMenu.d.ts.map +0 -1
- package/dist/types/src/stories/Command.stories.d.ts +0 -7
- package/dist/types/src/stories/Command.stories.d.ts.map +0 -1
- package/dist/types/src/stories/CommandMenu.stories.d.ts +0 -13
- package/dist/types/src/stories/CommandMenu.stories.d.ts.map +0 -1
- package/src/components/Popover/CommandMenu.tsx +0 -279
- package/src/components/Popover/RefDropdownMenu.tsx +0 -85
- package/src/components/Popover/RefPopover.tsx +0 -99
- package/src/components/Popover/index.ts +0 -7
- package/src/extensions/autocomplete.ts +0 -69
- package/src/extensions/command/action.ts +0 -56
- package/src/extensions/command/command-menu.ts +0 -210
- package/src/extensions/command/command.ts +0 -34
- package/src/extensions/command/hint.ts +0 -102
- package/src/extensions/command/index.ts +0 -10
- package/src/extensions/command/state.ts +0 -89
- package/src/extensions/command/useCommandMenu.ts +0 -118
- package/src/stories/Command.stories.tsx +0 -97
- package/src/stories/CommandMenu.stories.tsx +0 -159
|
@@ -4,27 +4,30 @@
|
|
|
4
4
|
//
|
|
5
5
|
|
|
6
6
|
import { type Extension } from '@codemirror/state';
|
|
7
|
-
import { Decoration, EditorView,
|
|
7
|
+
import { Decoration, EditorView, ViewPlugin, type ViewUpdate, WidgetType } from '@codemirror/view';
|
|
8
8
|
|
|
9
9
|
import { clientRectsFor, flattenRect } from '../../util';
|
|
10
10
|
|
|
11
11
|
type Content = string | HTMLElement | ((view: EditorView) => HTMLElement);
|
|
12
12
|
|
|
13
13
|
export type PlaceholderOptions = {
|
|
14
|
-
delay?: number;
|
|
15
14
|
content: Content;
|
|
15
|
+
delay?: number;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Shows a transient placeholder at the current cursor position.
|
|
20
|
+
*/
|
|
21
|
+
export const placeholder = ({ content, delay = 3_000 }: PlaceholderOptions): Extension => {
|
|
19
22
|
const plugin = ViewPlugin.fromClass(
|
|
20
23
|
class {
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
_timeout: ReturnType<typeof setTimeout> | undefined;
|
|
25
|
+
_decorations = Decoration.none;
|
|
23
26
|
|
|
24
27
|
update(update: ViewUpdate) {
|
|
25
|
-
if (this.
|
|
26
|
-
window.clearTimeout(this.
|
|
27
|
-
this.
|
|
28
|
+
if (this._timeout) {
|
|
29
|
+
window.clearTimeout(this._timeout);
|
|
30
|
+
this._timeout = undefined;
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
// Check if the active line (where cursor is) is empty.
|
|
@@ -33,10 +36,10 @@ export const placeholder = ({ delay = 3_000, content }: PlaceholderOptions): Ext
|
|
|
33
36
|
if (isEmpty) {
|
|
34
37
|
// Create widget decoration at the start of the current line.
|
|
35
38
|
const lineStart = activeLine.from;
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
39
|
+
this._timeout = setTimeout(() => {
|
|
40
|
+
this._decorations = Decoration.set([
|
|
38
41
|
Decoration.widget({
|
|
39
|
-
widget: new
|
|
42
|
+
widget: new PlaceholderWidget(content),
|
|
40
43
|
side: 1,
|
|
41
44
|
}).range(lineStart),
|
|
42
45
|
]);
|
|
@@ -45,18 +48,18 @@ export const placeholder = ({ delay = 3_000, content }: PlaceholderOptions): Ext
|
|
|
45
48
|
}, delay);
|
|
46
49
|
}
|
|
47
50
|
|
|
48
|
-
this.
|
|
51
|
+
this._decorations = Decoration.none;
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
destroy() {
|
|
52
|
-
if (this.
|
|
53
|
-
clearTimeout(this.
|
|
55
|
+
if (this._timeout) {
|
|
56
|
+
clearTimeout(this._timeout);
|
|
54
57
|
}
|
|
55
58
|
}
|
|
56
59
|
},
|
|
57
60
|
{
|
|
58
61
|
provide: (plugin) => {
|
|
59
|
-
return [EditorView.decorations.of((view) => view.plugin(plugin)?.
|
|
62
|
+
return [EditorView.decorations.of((view) => view.plugin(plugin)?._decorations ?? Decoration.none)];
|
|
60
63
|
},
|
|
61
64
|
},
|
|
62
65
|
);
|
|
@@ -66,7 +69,7 @@ export const placeholder = ({ delay = 3_000, content }: PlaceholderOptions): Ext
|
|
|
66
69
|
: plugin;
|
|
67
70
|
};
|
|
68
71
|
|
|
69
|
-
class
|
|
72
|
+
export class PlaceholderWidget extends WidgetType {
|
|
70
73
|
constructor(readonly content: Content) {
|
|
71
74
|
super();
|
|
72
75
|
}
|
|
@@ -75,6 +78,7 @@ class Placeholder extends WidgetType {
|
|
|
75
78
|
const wrap = document.createElement('span');
|
|
76
79
|
wrap.className = 'cm-placeholder';
|
|
77
80
|
wrap.style.pointerEvents = 'none';
|
|
81
|
+
wrap.setAttribute('aria-hidden', 'true');
|
|
78
82
|
wrap.appendChild(
|
|
79
83
|
typeof this.content === 'string'
|
|
80
84
|
? document.createTextNode(this.content)
|
|
@@ -82,7 +86,7 @@ class Placeholder extends WidgetType {
|
|
|
82
86
|
? this.content(view)
|
|
83
87
|
: this.content.cloneNode(true),
|
|
84
88
|
);
|
|
85
|
-
|
|
89
|
+
|
|
86
90
|
return wrap;
|
|
87
91
|
}
|
|
88
92
|
|
|
@@ -92,7 +96,7 @@ class Placeholder extends WidgetType {
|
|
|
92
96
|
return null;
|
|
93
97
|
}
|
|
94
98
|
|
|
95
|
-
const style =
|
|
99
|
+
const style = getComputedStyle(dom.parentNode as HTMLElement);
|
|
96
100
|
const rect = flattenRect(rects[0], style.direction !== 'rtl');
|
|
97
101
|
const lineHeight = parseInt(style.lineHeight);
|
|
98
102
|
if (rect.bottom - rect.top > lineHeight * 1.5) {
|
|
@@ -2,28 +2,27 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { EditorSelection, Prec, RangeSetBuilder
|
|
5
|
+
import { EditorSelection, type Extension, Prec, RangeSetBuilder } from '@codemirror/state';
|
|
6
6
|
import {
|
|
7
7
|
type Command,
|
|
8
8
|
Decoration,
|
|
9
9
|
type DecorationSet,
|
|
10
10
|
type EditorView,
|
|
11
|
-
keymap,
|
|
12
11
|
ViewPlugin,
|
|
13
12
|
type ViewUpdate,
|
|
13
|
+
keymap,
|
|
14
14
|
} from '@codemirror/view';
|
|
15
15
|
|
|
16
|
-
import {
|
|
16
|
+
import { type CompoetionContext } from './match';
|
|
17
|
+
import { PlaceholderWidget } from './placeholder';
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// TODO(burdon): Option to complete only at end of line?
|
|
19
|
+
// TODO(burdon): Option to complete only at end of line.
|
|
21
20
|
export type TypeaheadOptions = {
|
|
22
|
-
onComplete?: (context:
|
|
21
|
+
onComplete?: (context: CompoetionContext) => string | undefined;
|
|
23
22
|
};
|
|
24
23
|
|
|
25
24
|
/**
|
|
26
|
-
*
|
|
25
|
+
* Shows a completion placeholder.
|
|
27
26
|
*/
|
|
28
27
|
export const typeahead = ({ onComplete }: TypeaheadOptions = {}): Extension => {
|
|
29
28
|
let hint: string | undefined;
|
|
@@ -57,7 +56,7 @@ export const typeahead = ({ onComplete }: TypeaheadOptions = {}): Extension => {
|
|
|
57
56
|
const str = update.state.sliceDoc(line.from, selection.from);
|
|
58
57
|
hint = onComplete?.({ line: str });
|
|
59
58
|
if (hint) {
|
|
60
|
-
builder.add(selection.from, selection.to, Decoration.widget({ widget: new
|
|
59
|
+
builder.add(selection.from, selection.to, Decoration.widget({ widget: new PlaceholderWidget(hint) }));
|
|
61
60
|
}
|
|
62
61
|
}
|
|
63
62
|
|
|
@@ -86,44 +85,3 @@ export const typeahead = ({ onComplete }: TypeaheadOptions = {}): Extension => {
|
|
|
86
85
|
),
|
|
87
86
|
];
|
|
88
87
|
};
|
|
89
|
-
|
|
90
|
-
type CompletionOptions = {
|
|
91
|
-
default?: string;
|
|
92
|
-
minLength?: number;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Util to match current line to a static list of completions.
|
|
97
|
-
*/
|
|
98
|
-
export const staticCompletion =
|
|
99
|
-
(completions: string[], options: CompletionOptions = {}) =>
|
|
100
|
-
({ line }: TypeaheadContext) => {
|
|
101
|
-
if (line.length === 0 && options.default) {
|
|
102
|
-
return options.default;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const parts = line.split(/\s+/).filter(Boolean);
|
|
106
|
-
if (parts.length) {
|
|
107
|
-
const str = parts.at(-1)!;
|
|
108
|
-
if (str.length >= (options.minLength ?? 0)) {
|
|
109
|
-
for (const completion of completions) {
|
|
110
|
-
const match = matchCompletion(completion, str);
|
|
111
|
-
if (match) {
|
|
112
|
-
return match;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export const matchCompletion = (completion: string, str: string, minLength = 0): string | undefined => {
|
|
120
|
-
if (
|
|
121
|
-
str.length >= minLength &&
|
|
122
|
-
completion.length > str.length &&
|
|
123
|
-
completion.startsWith(str)
|
|
124
|
-
// TODO(burdon): If case insensitive, need to replace existing chars.
|
|
125
|
-
// completion.toLowerCase().startsWith(str.toLowerCase())
|
|
126
|
-
) {
|
|
127
|
-
return completion.slice(str.length);
|
|
128
|
-
}
|
|
129
|
-
};
|
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
|
|
7
5
|
import '@preact/signals-react';
|
|
8
6
|
|
|
9
7
|
import { Repo } from '@automerge/automerge-repo';
|
|
10
8
|
import { BroadcastChannelNetworkAdapter } from '@automerge/automerge-repo-network-broadcastchannel';
|
|
9
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
11
10
|
import React, { useEffect, useState } from 'react';
|
|
12
11
|
|
|
13
12
|
import { Obj, Ref, Type } from '@dxos/echo';
|
|
14
|
-
import { DocAccessor,
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
13
|
+
import { DocAccessor, Query, type Space, createDocAccessor, useQuery, useSpace } from '@dxos/react-client/echo';
|
|
14
|
+
import { type Identity, useIdentity } from '@dxos/react-client/halo';
|
|
15
|
+
import { type ClientRepeatedComponentProps, ClientRepeater } from '@dxos/react-client/testing';
|
|
17
16
|
import { useThemeContext } from '@dxos/react-ui';
|
|
18
|
-
import {
|
|
17
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
18
|
+
import { render } from '@dxos/storybook-utils';
|
|
19
19
|
|
|
20
20
|
import { editorSlots } from '../../defaults';
|
|
21
21
|
import { useTextEditor } from '../../hooks';
|
|
@@ -41,7 +41,7 @@ const Editor = ({ source, autoFocus, space, identity }: EditorProps) => {
|
|
|
41
41
|
() => ({
|
|
42
42
|
initialValue: DocAccessor.getValue(source),
|
|
43
43
|
extensions: [
|
|
44
|
-
createBasicExtensions({ placeholder: 'Type here...' }),
|
|
44
|
+
createBasicExtensions({ placeholder: 'Type here...', search: true }),
|
|
45
45
|
createThemeExtensions({ themeMode, slots: editorSlots }),
|
|
46
46
|
createDataExtensions({ id: 'test', text: source, space, identity }),
|
|
47
47
|
],
|
|
@@ -53,7 +53,7 @@ const Editor = ({ source, autoFocus, space, identity }: EditorProps) => {
|
|
|
53
53
|
return <div ref={parentRef} className='flex w-full' />;
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
-
const
|
|
56
|
+
const DefaultStory = () => {
|
|
57
57
|
const [object1, setObject1] = useState<DocAccessor<TestObject>>();
|
|
58
58
|
const [object2, setObject2] = useState<DocAccessor<TestObject>>();
|
|
59
59
|
|
|
@@ -88,16 +88,6 @@ const Story = () => {
|
|
|
88
88
|
);
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
export default {
|
|
92
|
-
title: 'ui/react-ui-editor/Automerge',
|
|
93
|
-
component: Editor,
|
|
94
|
-
decorators: [withTheme, withLayout({ fullscreen: true })],
|
|
95
|
-
render: () => <Story />,
|
|
96
|
-
parameters: {
|
|
97
|
-
translations,
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
|
|
101
91
|
const EchoStory = ({ spaceKey }: ClientRepeatedComponentProps) => {
|
|
102
92
|
const identity = useIdentity();
|
|
103
93
|
const space = useSpace(spaceKey);
|
|
@@ -105,8 +95,9 @@ const EchoStory = ({ spaceKey }: ClientRepeatedComponentProps) => {
|
|
|
105
95
|
const objects = useQuery(space, Query.type(Type.Expando, { type: 'test' }));
|
|
106
96
|
|
|
107
97
|
useEffect(() => {
|
|
108
|
-
|
|
109
|
-
|
|
98
|
+
const content = objects[0]?.content.target;
|
|
99
|
+
if (!source && content) {
|
|
100
|
+
const source = createDocAccessor(content, ['content']);
|
|
110
101
|
setSource(source);
|
|
111
102
|
}
|
|
112
103
|
}, [objects, source]);
|
|
@@ -118,17 +109,33 @@ const EchoStory = ({ spaceKey }: ClientRepeatedComponentProps) => {
|
|
|
118
109
|
return <Editor source={source} space={space} identity={identity ?? undefined} />;
|
|
119
110
|
};
|
|
120
111
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
112
|
+
const meta = {
|
|
113
|
+
title: 'ui/react-ui-editor/Automerge',
|
|
114
|
+
component: Editor as any,
|
|
115
|
+
render: render(DefaultStory),
|
|
124
116
|
decorators: [withTheme],
|
|
117
|
+
parameters: {
|
|
118
|
+
layout: 'fullscreen',
|
|
119
|
+
translations,
|
|
120
|
+
},
|
|
121
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
122
|
+
|
|
123
|
+
export default meta;
|
|
124
|
+
|
|
125
|
+
type Story = StoryObj<typeof meta>;
|
|
126
|
+
|
|
127
|
+
export const Default: Story = {
|
|
128
|
+
args: {},
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const WithEcho: Story = {
|
|
125
132
|
render: () => {
|
|
126
133
|
return (
|
|
127
134
|
<ClientRepeater
|
|
128
135
|
count={2}
|
|
129
136
|
component={EchoStory}
|
|
130
137
|
createSpace
|
|
131
|
-
|
|
138
|
+
onCreateSpace={async ({ space }) => {
|
|
132
139
|
space.db.add(
|
|
133
140
|
Obj.make(Type.Expando, {
|
|
134
141
|
type: 'test',
|
|
@@ -5,23 +5,27 @@
|
|
|
5
5
|
//
|
|
6
6
|
|
|
7
7
|
import { next as A } from '@automerge/automerge';
|
|
8
|
-
import { StateField,
|
|
8
|
+
import { type Extension, StateField, Transaction } from '@codemirror/state';
|
|
9
9
|
import { EditorView, ViewPlugin } from '@codemirror/view';
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { DocAccessor } from '@dxos/client/echo';
|
|
12
|
+
|
|
13
|
+
import { Cursor } from '../../util';
|
|
14
|
+
import { initialSync } from '../state';
|
|
12
15
|
|
|
13
16
|
import { cursorConverter } from './cursor';
|
|
14
|
-
import {
|
|
17
|
+
import { type State, isReconcile, updateHeadsEffect } from './defs';
|
|
15
18
|
import { Syncer } from './sync';
|
|
16
|
-
import { Cursor } from '../../util';
|
|
17
19
|
|
|
18
20
|
export const automerge = (accessor: DocAccessor): Extension => {
|
|
19
21
|
const syncState = StateField.define<State>({
|
|
20
|
-
create: () =>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
create: () => {
|
|
23
|
+
return {
|
|
24
|
+
path: accessor.path.slice(),
|
|
25
|
+
lastHeads: A.getHeads(accessor.handle.doc()!),
|
|
26
|
+
unreconciledTransactions: [],
|
|
27
|
+
};
|
|
28
|
+
},
|
|
25
29
|
|
|
26
30
|
update: (value, tr) => {
|
|
27
31
|
const result: State = {
|
|
@@ -63,6 +67,18 @@ export const automerge = (accessor: DocAccessor): Extension => {
|
|
|
63
67
|
class {
|
|
64
68
|
constructor(private readonly _view: EditorView) {
|
|
65
69
|
accessor.handle.addListener('change', this._handleChange);
|
|
70
|
+
|
|
71
|
+
requestAnimationFrame(() => {
|
|
72
|
+
const value = DocAccessor.getValue<string>(accessor);
|
|
73
|
+
const current = this._view.state.doc.toString();
|
|
74
|
+
if (value !== current) {
|
|
75
|
+
// TODO(burdon): This attempts to set the initial state, but creates problems.
|
|
76
|
+
// this._view.dispatch({
|
|
77
|
+
// changes: { from: 0, to: this._view.state.doc.length, insert: value },
|
|
78
|
+
// annotations: initialSync,
|
|
79
|
+
// });
|
|
80
|
+
}
|
|
81
|
+
});
|
|
66
82
|
}
|
|
67
83
|
|
|
68
84
|
destroy() {
|
|
@@ -76,9 +92,13 @@ export const automerge = (accessor: DocAccessor): Extension => {
|
|
|
76
92
|
),
|
|
77
93
|
|
|
78
94
|
// Reconcile local updates.
|
|
79
|
-
EditorView.updateListener.of(({ view, changes }) => {
|
|
95
|
+
EditorView.updateListener.of(({ view, changes, transactions }) => {
|
|
80
96
|
if (!changes.empty) {
|
|
81
|
-
|
|
97
|
+
// Only reconcile if it's not an initial sync (to avoid loops)
|
|
98
|
+
const isInitialSync = transactions.some((tr) => tr.annotation(Transaction.userEvent) === initialSync.value);
|
|
99
|
+
if (!isInitialSync) {
|
|
100
|
+
syncer.reconcile(view, true);
|
|
101
|
+
}
|
|
82
102
|
}
|
|
83
103
|
}),
|
|
84
104
|
];
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { type DocAccessor, fromCursor, toCursor } from '@dxos/client/echo';
|
|
5
6
|
import { log } from '@dxos/log';
|
|
6
|
-
import { type DocAccessor, fromCursor, toCursor } from '@dxos/react-client/echo';
|
|
7
7
|
|
|
8
8
|
import { type CursorConverter } from '../../util';
|
|
9
9
|
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
//
|
|
6
6
|
|
|
7
7
|
import { type Heads, type Prop } from '@automerge/automerge';
|
|
8
|
-
import { Annotation, StateEffect, type StateField, type
|
|
8
|
+
import { Annotation, type EditorState, StateEffect, type StateField, type Transaction } from '@codemirror/state';
|
|
9
9
|
|
|
10
10
|
export type State = {
|
|
11
11
|
path: Prop[];
|
|
@@ -8,9 +8,10 @@ import { next as A } from '@automerge/automerge';
|
|
|
8
8
|
import { type StateField } from '@codemirror/state';
|
|
9
9
|
import { type EditorView } from '@codemirror/view';
|
|
10
10
|
|
|
11
|
-
import { type IDocHandle } from '@dxos/
|
|
11
|
+
import { type IDocHandle } from '@dxos/client/echo';
|
|
12
|
+
import { log } from '@dxos/log';
|
|
12
13
|
|
|
13
|
-
import { getLastHeads, getPath, isReconcile, reconcileAnnotation,
|
|
14
|
+
import { type State, getLastHeads, getPath, isReconcile, reconcileAnnotation, updateHeads } from './defs';
|
|
14
15
|
import { updateAutomerge } from './update-automerge';
|
|
15
16
|
import { updateCodeMirror } from './update-codemirror';
|
|
16
17
|
|
|
@@ -27,7 +28,6 @@ export class Syncer {
|
|
|
27
28
|
) {}
|
|
28
29
|
|
|
29
30
|
reconcile(view: EditorView, editor: boolean): void {
|
|
30
|
-
// TODO(burdon): Better way to do mutex?
|
|
31
31
|
if (this._pending) {
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
@@ -41,7 +41,9 @@ export class Syncer {
|
|
|
41
41
|
this._pending = false;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
onEditorChange(view: EditorView): void {
|
|
44
|
+
private onEditorChange(view: EditorView): void {
|
|
45
|
+
log('onEditorChange');
|
|
46
|
+
|
|
45
47
|
// Apply the unreconciled transactions to the document.
|
|
46
48
|
const transactions = view.state.field(this._state).unreconciledTransactions.filter((tx) => !isReconcile(tx));
|
|
47
49
|
const newHeads = updateAutomerge(this._state, this._handle, transactions, view.state);
|
|
@@ -54,7 +56,9 @@ export class Syncer {
|
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
onAutomergeChange(view: EditorView): void {
|
|
59
|
+
private onAutomergeChange(view: EditorView): void {
|
|
60
|
+
log('onAutomergeChange');
|
|
61
|
+
|
|
58
62
|
// Get the diff between the updated state of the document and the heads and apply that to the codemirror doc.
|
|
59
63
|
const oldHeads = getLastHeads(view.state, this._state);
|
|
60
64
|
const newHeads = A.getHeads(this._handle.doc()!);
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
//
|
|
6
6
|
|
|
7
7
|
import { next as A, type Heads } from '@automerge/automerge';
|
|
8
|
-
import { type EditorState, type StateField, type
|
|
8
|
+
import { type EditorState, type StateField, type Text, type Transaction } from '@codemirror/state';
|
|
9
9
|
|
|
10
|
-
import { type IDocHandle } from '@dxos/
|
|
10
|
+
import { type IDocHandle } from '@dxos/client/echo';
|
|
11
11
|
|
|
12
12
|
import { type State } from './defs';
|
|
13
13
|
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { StateEffect } from '@codemirror/state';
|
|
6
|
+
import { EditorView, ViewPlugin } from '@codemirror/view';
|
|
7
|
+
|
|
8
|
+
import { Domino } from '@dxos/react-ui';
|
|
9
|
+
|
|
10
|
+
const lineHeight = 24;
|
|
11
|
+
|
|
12
|
+
export const scrollToBottomEffect = StateEffect.define<any>();
|
|
13
|
+
|
|
14
|
+
export type AutoScrollOptions = {
|
|
15
|
+
overscroll?: number;
|
|
16
|
+
throttle?: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Extension that supports pinning the scroll position and automatically scrolls to the bottom when content is added.
|
|
21
|
+
*/
|
|
22
|
+
// TODO(burdon): Reconcile with transcript-extension.
|
|
23
|
+
export const autoScroll = ({ overscroll = 4 * lineHeight, throttle = 2_000 }: Partial<AutoScrollOptions> = {}) => {
|
|
24
|
+
let isThrottled = false;
|
|
25
|
+
let isPinned = true;
|
|
26
|
+
let timeout: NodeJS.Timeout | undefined;
|
|
27
|
+
let buttonContainer: HTMLDivElement | undefined;
|
|
28
|
+
let lastScrollTop = 0;
|
|
29
|
+
let scrollCounter = 0;
|
|
30
|
+
|
|
31
|
+
const hideScrollbar = (view: EditorView) => {
|
|
32
|
+
view.scrollDOM.classList.add('cm-hide-scrollbar');
|
|
33
|
+
clearTimeout(timeout);
|
|
34
|
+
timeout = setTimeout(() => {
|
|
35
|
+
view.scrollDOM.classList.remove('cm-hide-scrollbar');
|
|
36
|
+
}, 1_000);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const scrollToBottom = (view: EditorView) => {
|
|
40
|
+
isPinned = true;
|
|
41
|
+
scrollCounter = 0;
|
|
42
|
+
buttonContainer?.classList.add('opacity-0');
|
|
43
|
+
requestAnimationFrame(() => {
|
|
44
|
+
hideScrollbar(view);
|
|
45
|
+
view.scrollDOM.scrollTo({
|
|
46
|
+
top: view.scrollDOM.scrollHeight,
|
|
47
|
+
behavior: 'smooth',
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return [
|
|
53
|
+
// Update listener for logging when scrolling is needed.
|
|
54
|
+
EditorView.updateListener.of((update) => {
|
|
55
|
+
// Listen for effects.
|
|
56
|
+
update.transactions.forEach((transaction) => {
|
|
57
|
+
for (const effect of transaction.effects) {
|
|
58
|
+
if (effect.is(scrollToBottomEffect)) {
|
|
59
|
+
scrollToBottom(update.view);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Maybe scroll if doc changed and pinned.
|
|
65
|
+
if (update.docChanged && isPinned && !isThrottled) {
|
|
66
|
+
const distanceFromBottom = calcDistance(update.view.scrollDOM);
|
|
67
|
+
if (distanceFromBottom >= overscroll) {
|
|
68
|
+
isThrottled = true;
|
|
69
|
+
requestAnimationFrame(() => {
|
|
70
|
+
scrollToBottom(update.view);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Reset throttle.
|
|
74
|
+
setTimeout(() => {
|
|
75
|
+
isThrottled = false;
|
|
76
|
+
scrollToBottom(update.view);
|
|
77
|
+
}, throttle);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}),
|
|
81
|
+
|
|
82
|
+
// Detect user scroll.
|
|
83
|
+
// NOTE: Multiple scroll events are triggered during programmatic smooth scrolling.
|
|
84
|
+
EditorView.domEventHandlers({
|
|
85
|
+
scroll: (event, view) => {
|
|
86
|
+
const scroller = view.scrollDOM;
|
|
87
|
+
// Suspect delta goes positive when rendering widgets, so count positive deltas.
|
|
88
|
+
// TODO(burdon): Detect user scroll directly (wheel, touch, keys, etc.)
|
|
89
|
+
if (lastScrollTop > scroller.scrollTop) {
|
|
90
|
+
scrollCounter++;
|
|
91
|
+
}
|
|
92
|
+
lastScrollTop = scroller.scrollTop;
|
|
93
|
+
const distanceFromBottom = calcDistance(scroller);
|
|
94
|
+
if (distanceFromBottom === 0) {
|
|
95
|
+
// Pin to bottom.
|
|
96
|
+
isPinned = true;
|
|
97
|
+
buttonContainer?.classList.add('opacity-0');
|
|
98
|
+
scrollCounter = 0;
|
|
99
|
+
} else if (scrollCounter > 3) {
|
|
100
|
+
// Break pin if user scrolls up.
|
|
101
|
+
isPinned = false;
|
|
102
|
+
buttonContainer?.classList.remove('opacity-0');
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
}),
|
|
106
|
+
|
|
107
|
+
// Scroll button.
|
|
108
|
+
ViewPlugin.fromClass(
|
|
109
|
+
class {
|
|
110
|
+
constructor(view: EditorView) {
|
|
111
|
+
const scroller = view.scrollDOM.parentElement;
|
|
112
|
+
buttonContainer = Domino.of('div')
|
|
113
|
+
.classNames(true && 'cm-scroll-button transition-opacity duration-300 opacity-0')
|
|
114
|
+
.children(
|
|
115
|
+
Domino.of('button')
|
|
116
|
+
.classNames('dx-button bg-accentSurface')
|
|
117
|
+
.data('density', 'fine')
|
|
118
|
+
.children(Domino.of<any>('dx-icon').attributes({ icon: 'ph--arrow-down--regular' }))
|
|
119
|
+
.on('click', () => {
|
|
120
|
+
scrollToBottom(view);
|
|
121
|
+
}),
|
|
122
|
+
)
|
|
123
|
+
.build();
|
|
124
|
+
scroller?.appendChild(buttonContainer);
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
),
|
|
128
|
+
|
|
129
|
+
// Styles.
|
|
130
|
+
EditorView.theme({
|
|
131
|
+
'.cm-scroller': {
|
|
132
|
+
paddingBottom: `${overscroll}px`,
|
|
133
|
+
scrollbarWidth: 'thin',
|
|
134
|
+
},
|
|
135
|
+
'.cm-scroller.cm-hide-scrollbar': {
|
|
136
|
+
scrollbarWidth: 'none',
|
|
137
|
+
},
|
|
138
|
+
'.cm-scroller.cm-hide-scrollbar::-webkit-scrollbar': {
|
|
139
|
+
display: 'none',
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
'.cm-scroll-button': {
|
|
143
|
+
position: 'absolute',
|
|
144
|
+
bottom: '0.5rem',
|
|
145
|
+
right: '1rem',
|
|
146
|
+
},
|
|
147
|
+
}),
|
|
148
|
+
];
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const calcDistance = (scroller: HTMLElement) => {
|
|
152
|
+
const scrollTop = scroller.scrollTop;
|
|
153
|
+
const scrollHeight = scroller.scrollHeight;
|
|
154
|
+
const clientHeight = scroller.clientHeight;
|
|
155
|
+
const distanceFromBottom = scrollHeight - (scrollTop + clientHeight);
|
|
156
|
+
return distanceFromBottom;
|
|
157
|
+
};
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { DeferredTask, Event, sleep } from '@dxos/async';
|
|
6
|
+
import { type Space } from '@dxos/client/echo';
|
|
7
|
+
import { type GossipMessage } from '@dxos/client/mesh';
|
|
6
8
|
import { Context } from '@dxos/context';
|
|
7
9
|
import { invariant } from '@dxos/invariant';
|
|
8
10
|
import { log } from '@dxos/log';
|
|
9
|
-
import { type Space } from '@dxos/react-client/echo';
|
|
10
|
-
import { type GossipMessage } from '@dxos/react-client/mesh';
|
|
11
11
|
|
|
12
12
|
import { type AwarenessInfo, type AwarenessPosition, type AwarenessProvider, type AwarenessState } from './awareness';
|
|
13
13
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Annotation, type Extension,
|
|
5
|
+
import { Annotation, type Extension, type Range, RangeSet } from '@codemirror/state';
|
|
6
6
|
import {
|
|
7
7
|
Decoration,
|
|
8
8
|
type DecorationSet,
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
import { Event } from '@dxos/async';
|
|
17
17
|
import { Context } from '@dxos/context';
|
|
18
18
|
|
|
19
|
-
import {
|
|
19
|
+
import { Cursor, type CursorConverter, singleValueFacet } from '../../util';
|
|
20
20
|
|
|
21
21
|
export interface AwarenessProvider {
|
|
22
22
|
remoteStateChange: Event<void>;
|