@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
|
@@ -3,20 +3,21 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { syntaxTree } from '@codemirror/language';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { type EditorState, Prec, RangeSetBuilder, StateEffect } from '@codemirror/state';
|
|
7
|
+
import { Decoration, type DecorationSet, EditorView, ViewPlugin, type ViewUpdate, WidgetType } from '@codemirror/view';
|
|
8
8
|
import { type SyntaxNodeRef } from '@lezer/common';
|
|
9
9
|
|
|
10
10
|
import { invariant } from '@dxos/invariant';
|
|
11
11
|
import { mx } from '@dxos/react-ui-theme';
|
|
12
12
|
|
|
13
|
+
import { type HeadingLevel, theme } from '../../styles';
|
|
14
|
+
import { type RenderCallback } from '../../types';
|
|
15
|
+
import { wrapWithCatch } from '../../util';
|
|
16
|
+
|
|
13
17
|
import { adjustChanges } from './changes';
|
|
14
18
|
import { image } from './image';
|
|
15
|
-
import {
|
|
19
|
+
import { bulletListIndentationWidth, formattingStyles, orderedListIndentationWidth } from './styles';
|
|
16
20
|
import { table } from './table';
|
|
17
|
-
import { theme, type HeadingLevel } from '../../styles';
|
|
18
|
-
import { type RenderCallback } from '../../types';
|
|
19
|
-
import { wrapWithCatch } from '../../util';
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* Unicode characters.
|
|
@@ -233,7 +234,7 @@ const buildDecorations = (view: EditorView, options: DecorateOptions, focus: boo
|
|
|
233
234
|
const mark = node.node.firstChild!;
|
|
234
235
|
if (mark?.name === 'HeaderMark') {
|
|
235
236
|
const { from, to = 6 } = options.numberedHeadings ?? {};
|
|
236
|
-
const text =
|
|
237
|
+
const text = state.sliceDoc(node.from, node.to);
|
|
237
238
|
const len = text.match(/[#\s]+/)![0].length;
|
|
238
239
|
if (!from || level < from || level > to) {
|
|
239
240
|
atomicDeco.add(mark.from, mark.from + len, hide);
|
|
@@ -426,6 +427,9 @@ const buildDecorations = (view: EditorView, options: DecorateOptions, focus: boo
|
|
|
426
427
|
const editing = editingRange(state, node, focus);
|
|
427
428
|
if (urlNode && marks.length >= 2) {
|
|
428
429
|
const url = state.sliceDoc(urlNode.from, urlNode.to);
|
|
430
|
+
if (options.skip?.({ name: 'Link', url })) {
|
|
431
|
+
break;
|
|
432
|
+
}
|
|
429
433
|
if (!editing) {
|
|
430
434
|
atomicDeco.add(node.from, marks[0].to, hide);
|
|
431
435
|
}
|
|
@@ -443,6 +447,7 @@ const buildDecorations = (view: EditorView, options: DecorateOptions, focus: boo
|
|
|
443
447
|
},
|
|
444
448
|
}),
|
|
445
449
|
);
|
|
450
|
+
|
|
446
451
|
if (!editing) {
|
|
447
452
|
atomicDeco.add(
|
|
448
453
|
marks[1].from,
|
|
@@ -493,15 +498,15 @@ const buildDecorations = (view: EditorView, options: DecorateOptions, focus: boo
|
|
|
493
498
|
tree.iterate({
|
|
494
499
|
from,
|
|
495
500
|
to,
|
|
496
|
-
enter: wrapWithCatch(enterNode),
|
|
497
|
-
leave: wrapWithCatch(leaveNode),
|
|
501
|
+
enter: wrapWithCatch(enterNode, 'decorate.enter'),
|
|
502
|
+
leave: wrapWithCatch(leaveNode, 'decorate.leave'),
|
|
498
503
|
});
|
|
499
504
|
}
|
|
500
505
|
} else {
|
|
501
506
|
// NOTE: If line numbering then we must iterate from the start of document.
|
|
502
507
|
tree.iterate({
|
|
503
|
-
enter: wrapWithCatch(enterNode),
|
|
504
|
-
leave: wrapWithCatch(leaveNode),
|
|
508
|
+
enter: wrapWithCatch(enterNode, 'decorate.enter'),
|
|
509
|
+
leave: wrapWithCatch(leaveNode, 'decorate.leave'),
|
|
505
510
|
});
|
|
506
511
|
}
|
|
507
512
|
|
|
@@ -513,15 +518,20 @@ const buildDecorations = (view: EditorView, options: DecorateOptions, focus: boo
|
|
|
513
518
|
|
|
514
519
|
const forceUpdate = StateEffect.define<null>();
|
|
515
520
|
|
|
521
|
+
export type NodeData = { name: 'Link'; url: string } | { name: 'Image'; url: string };
|
|
522
|
+
|
|
516
523
|
export interface DecorateOptions {
|
|
517
524
|
/**
|
|
518
525
|
* Prevents triggering decorations as the cursor moves through the document.
|
|
519
526
|
*/
|
|
520
527
|
selectionChangeDelay?: number;
|
|
521
528
|
numberedHeadings?: { from: number; to?: number };
|
|
522
|
-
renderLinkButton?: RenderCallback<{ url: string }>;
|
|
523
529
|
// TODO(burdon): Additional padding for each line.
|
|
524
530
|
listPaddingLeft?: number;
|
|
531
|
+
// TODO(burdon): Use consistently.
|
|
532
|
+
skip?: (node: NodeData) => boolean;
|
|
533
|
+
// TODO(burdon): Remove.
|
|
534
|
+
renderLinkButton?: RenderCallback<{ url: string }>;
|
|
525
535
|
}
|
|
526
536
|
|
|
527
537
|
export const decorateMarkdown = (options: DecorateOptions = {}) => {
|
|
@@ -577,9 +587,9 @@ export const decorateMarkdown = (options: DecorateOptions = {}) => {
|
|
|
577
587
|
},
|
|
578
588
|
{
|
|
579
589
|
provide: (plugin) => [
|
|
580
|
-
EditorView.
|
|
590
|
+
Prec.low(EditorView.decorations.of((view) => view.plugin(plugin)?.deco ?? Decoration.none)),
|
|
581
591
|
EditorView.decorations.of((view) => view.plugin(plugin)?.atomicDeco ?? Decoration.none),
|
|
582
|
-
EditorView.
|
|
592
|
+
EditorView.atomicRanges.of((view) => view.plugin(plugin)?.atomicDeco ?? Decoration.none),
|
|
583
593
|
],
|
|
584
594
|
},
|
|
585
595
|
),
|
|
@@ -7,21 +7,21 @@ import { EditorState, type StateCommand } from '@codemirror/state';
|
|
|
7
7
|
import { describe, expect, test } from 'vitest';
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
|
+
type Formatting,
|
|
11
|
+
Inline,
|
|
12
|
+
List,
|
|
10
13
|
addBlockquote,
|
|
11
14
|
addCodeblock,
|
|
12
15
|
addLink,
|
|
13
16
|
addList,
|
|
14
17
|
addStyle,
|
|
15
18
|
getFormatting,
|
|
16
|
-
removeStyle,
|
|
17
|
-
removeLink,
|
|
18
|
-
removeList,
|
|
19
19
|
removeBlockquote,
|
|
20
20
|
removeCodeblock,
|
|
21
|
+
removeLink,
|
|
22
|
+
removeList,
|
|
23
|
+
removeStyle,
|
|
21
24
|
setHeading,
|
|
22
|
-
Inline,
|
|
23
|
-
List,
|
|
24
|
-
type Formatting,
|
|
25
25
|
} from './formatting';
|
|
26
26
|
|
|
27
27
|
export const emptyFormatting: Formatting = {
|
|
@@ -7,18 +7,16 @@ import { syntaxTree } from '@codemirror/language';
|
|
|
7
7
|
import {
|
|
8
8
|
type ChangeSpec,
|
|
9
9
|
EditorSelection,
|
|
10
|
-
type Extension,
|
|
11
10
|
type EditorState,
|
|
11
|
+
type Extension,
|
|
12
12
|
type Line,
|
|
13
13
|
type StateCommand,
|
|
14
14
|
type Text,
|
|
15
15
|
} from '@codemirror/state';
|
|
16
|
-
import { EditorView,
|
|
17
|
-
import { type
|
|
18
|
-
import { useCallback, useMemo } from 'react';
|
|
16
|
+
import { EditorView, type ViewUpdate, keymap } from '@codemirror/view';
|
|
17
|
+
import { type SyntaxNode, type SyntaxNodeRef } from '@lezer/common';
|
|
19
18
|
|
|
20
19
|
import { debounceAndThrottle } from '@dxos/async';
|
|
21
|
-
import { type Live } from '@dxos/live-object';
|
|
22
20
|
|
|
23
21
|
import { type EditorToolbarState } from '../../components';
|
|
24
22
|
|
|
@@ -1251,17 +1249,19 @@ export const getFormatting = (state: EditorState): Formatting => {
|
|
|
1251
1249
|
/**
|
|
1252
1250
|
* Hook provides an extension to compute the current formatting state.
|
|
1253
1251
|
*/
|
|
1254
|
-
export const
|
|
1255
|
-
|
|
1252
|
+
export const formattingListener = (stateProvider: () => EditorToolbarState | undefined, delay = 100): Extension => {
|
|
1253
|
+
return EditorView.updateListener.of(
|
|
1256
1254
|
debounceAndThrottle((update: ViewUpdate) => {
|
|
1257
1255
|
if (update.docChanged || update.selectionSet) {
|
|
1256
|
+
const state = stateProvider();
|
|
1257
|
+
if (!state) {
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1258
1261
|
Object.entries(getFormatting(update.state)).forEach(([key, active]) => {
|
|
1259
1262
|
state[key as keyof Formatting] = active as any;
|
|
1260
1263
|
});
|
|
1261
1264
|
}
|
|
1262
|
-
},
|
|
1263
|
-
[state],
|
|
1265
|
+
}, delay),
|
|
1264
1266
|
);
|
|
1265
|
-
|
|
1266
|
-
return useMemo(() => EditorView.updateListener.of(handleUpdate), [handleUpdate]);
|
|
1267
1267
|
};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { markdownLanguage } from '@codemirror/lang-markdown';
|
|
6
6
|
import { HighlightStyle } from '@codemirror/language';
|
|
7
|
-
import {
|
|
7
|
+
import { Tag, styleTags, tags } from '@lezer/highlight';
|
|
8
8
|
import { type MarkdownConfig, Table } from '@lezer/markdown';
|
|
9
9
|
|
|
10
10
|
import { fontBody, theme } from '../../styles';
|
|
@@ -17,8 +17,7 @@ export const image = (_options: ImageOptions = {}): Extension => {
|
|
|
17
17
|
return [
|
|
18
18
|
StateField.define<DecorationSet>({
|
|
19
19
|
create: (state) => {
|
|
20
|
-
|
|
21
|
-
return Decoration.set(buildDecorations(0, state.doc.length, state));
|
|
20
|
+
return Decoration.set(buildDecorations(state, 0, state.doc.length));
|
|
22
21
|
},
|
|
23
22
|
update: (value: DecorationSet, tr: Transaction) => {
|
|
24
23
|
if (!tr.docChanged && !tr.selection) {
|
|
@@ -43,7 +42,7 @@ export const image = (_options: ImageOptions = {}): Extension => {
|
|
|
43
42
|
filterFrom: from,
|
|
44
43
|
filterTo: to,
|
|
45
44
|
filter: () => false,
|
|
46
|
-
add: buildDecorations(from, to
|
|
45
|
+
add: buildDecorations(tr.state, from, to),
|
|
47
46
|
});
|
|
48
47
|
},
|
|
49
48
|
provide: (field) => EditorView.decorations.from(field),
|
|
@@ -51,7 +50,7 @@ export const image = (_options: ImageOptions = {}): Extension => {
|
|
|
51
50
|
];
|
|
52
51
|
};
|
|
53
52
|
|
|
54
|
-
const buildDecorations = (
|
|
53
|
+
const buildDecorations = (state: EditorState, from: number, to: number) => {
|
|
55
54
|
const decorations: Range<Decoration>[] = [];
|
|
56
55
|
const cursor = state.selection.main.head;
|
|
57
56
|
syntaxTree(state).iterate({
|
|
@@ -94,7 +94,13 @@ const update = (state: EditorState, _options: TableOptions) => {
|
|
|
94
94
|
} else {
|
|
95
95
|
// Add class for styling.
|
|
96
96
|
// TODO(burdon): Apply to each line?
|
|
97
|
-
builder.add(
|
|
97
|
+
builder.add(
|
|
98
|
+
table.from,
|
|
99
|
+
table.to,
|
|
100
|
+
Decoration.mark({
|
|
101
|
+
class: 'cm-table',
|
|
102
|
+
}),
|
|
103
|
+
);
|
|
98
104
|
}
|
|
99
105
|
});
|
|
100
106
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { type CompletionContext, type CompletionResult, autocompletion } from '@codemirror/autocomplete';
|
|
6
6
|
import type { Extension } from '@codemirror/state';
|
|
7
7
|
|
|
8
8
|
import { log } from '@dxos/log';
|
package/src/extensions/modes.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { singleValueFacet } from '../util';
|
|
|
11
11
|
|
|
12
12
|
export type EditorInputConfig = {
|
|
13
13
|
type?: string;
|
|
14
|
-
|
|
14
|
+
ignoreEscape?: boolean;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export const editorInputMode = singleValueFacet<EditorInputConfig>({});
|
|
@@ -26,7 +26,7 @@ export const InputModeExtensions: { [mode: string]: Extension } = {
|
|
|
26
26
|
vim: [
|
|
27
27
|
// https://github.com/replit/codemirror-vim
|
|
28
28
|
vim(),
|
|
29
|
-
editorInputMode.of({ type: 'vim',
|
|
29
|
+
editorInputMode.of({ type: 'vim', ignoreEscape: true }),
|
|
30
30
|
keymap.of([
|
|
31
31
|
{
|
|
32
32
|
key: 'Alt-Escape',
|
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { type Extension } from '@codemirror/state';
|
|
5
6
|
import { EditorView, ViewPlugin, type ViewUpdate } from '@codemirror/view';
|
|
6
7
|
|
|
7
8
|
import { type CleanupFn, addEventListener } from '@dxos/async';
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export type FloatingMenuOptions = {
|
|
10
|
+
export type MenuOptions = {
|
|
12
11
|
icon?: string;
|
|
13
12
|
height?: number;
|
|
14
13
|
padding?: number;
|
|
15
14
|
};
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
// TODO(burdon): Replace with popover.
|
|
17
|
+
export const menu = (options: MenuOptions = {}): Extension => [
|
|
18
18
|
ViewPlugin.fromClass(
|
|
19
19
|
class {
|
|
20
20
|
view: EditorView;
|
|
@@ -34,12 +34,10 @@ export const floatingMenu = (options: FloatingMenuOptions = {}) => [
|
|
|
34
34
|
{
|
|
35
35
|
const icon = document.createElement('dx-icon');
|
|
36
36
|
icon.setAttribute('icon', options.icon ?? 'ph--dots-three-vertical--regular');
|
|
37
|
-
const button = document.createElement('button');
|
|
38
|
-
button.appendChild(icon);
|
|
39
37
|
|
|
40
|
-
this.tag = document.createElement('dx-
|
|
41
|
-
this.tag.classList.add('cm-
|
|
42
|
-
this.tag.appendChild(
|
|
38
|
+
this.tag = document.createElement('dx-anchor');
|
|
39
|
+
this.tag.classList.add('cm-popover-trigger');
|
|
40
|
+
this.tag.appendChild(icon);
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
container.appendChild(this.tag);
|
|
@@ -65,12 +63,12 @@ export const floatingMenu = (options: FloatingMenuOptions = {}) => [
|
|
|
65
63
|
}
|
|
66
64
|
|
|
67
65
|
// TODO(burdon): Timer to fade in/out.
|
|
68
|
-
if (update.transactions.some((tr) => tr.effects.some((effect) => effect.is(openEffect)))) {
|
|
66
|
+
/*if (update.transactions.some((tr) => tr.effects.some((effect) => effect.is(openEffect)))) {
|
|
69
67
|
this.tag.style.display = 'none';
|
|
70
68
|
this.tag.classList.add('opacity-10');
|
|
71
69
|
} else if (update.transactions.some((tr) => tr.effects.some((effect) => effect.is(closeEffect)))) {
|
|
72
|
-
this.tag.style.display = '
|
|
73
|
-
} else if (
|
|
70
|
+
this.tag.style.display = '';
|
|
71
|
+
} else */ if (
|
|
74
72
|
update.docChanged ||
|
|
75
73
|
update.focusChanged ||
|
|
76
74
|
update.geometryChanged ||
|
|
@@ -99,7 +97,7 @@ export const floatingMenu = (options: FloatingMenuOptions = {}) => [
|
|
|
99
97
|
|
|
100
98
|
this.tag.style.top = `${offsetTop}px`;
|
|
101
99
|
this.tag.style.left = `${offsetLeft}px`;
|
|
102
|
-
this.tag.style.display = '
|
|
100
|
+
this.tag.style.display = '';
|
|
103
101
|
}
|
|
104
102
|
|
|
105
103
|
scheduleUpdate() {
|
|
@@ -113,21 +111,18 @@ export const floatingMenu = (options: FloatingMenuOptions = {}) => [
|
|
|
113
111
|
),
|
|
114
112
|
|
|
115
113
|
EditorView.theme({
|
|
116
|
-
'.cm-
|
|
114
|
+
'.cm-popover-trigger': {
|
|
117
115
|
position: 'fixed',
|
|
118
116
|
padding: '0',
|
|
119
117
|
border: 'none',
|
|
120
118
|
opacity: '0',
|
|
121
|
-
},
|
|
122
|
-
'[data-has-focus] & .cm-ref-tag': {
|
|
123
|
-
opacity: '1',
|
|
124
|
-
},
|
|
125
|
-
'.cm-ref-tag button': {
|
|
126
119
|
display: 'grid',
|
|
127
|
-
|
|
128
|
-
justifyContent: 'center',
|
|
120
|
+
placeContent: 'center',
|
|
129
121
|
width: '2rem',
|
|
130
122
|
height: '2rem',
|
|
131
123
|
},
|
|
124
|
+
'&:focus-within .cm-popover-trigger': {
|
|
125
|
+
opacity: '1',
|
|
126
|
+
},
|
|
132
127
|
}),
|
|
133
128
|
];
|
|
@@ -6,11 +6,12 @@ import { EditorSelection, EditorState } from '@codemirror/state';
|
|
|
6
6
|
import { EditorView } from '@codemirror/view';
|
|
7
7
|
import { describe, test } from 'vitest';
|
|
8
8
|
|
|
9
|
-
import { indentItemLess, indentItemMore, moveItemDown, moveItemUp } from './commands';
|
|
10
|
-
import { listItemToString, outlinerTree, treeFacet } from './tree';
|
|
11
9
|
import { str } from '../../testing';
|
|
12
10
|
import { createMarkdownExtensions } from '../markdown';
|
|
13
11
|
|
|
12
|
+
import { indentItemLess, indentItemMore, moveItemDown, moveItemUp } from './commands';
|
|
13
|
+
import { listItemToString, outlinerTree, treeFacet } from './tree';
|
|
14
|
+
|
|
14
15
|
const lines = [
|
|
15
16
|
'- [ ] 1',
|
|
16
17
|
'- [ ] 2',
|
|
@@ -7,12 +7,13 @@ import { Decoration, type DecorationSet, EditorView, ViewPlugin, type ViewUpdate
|
|
|
7
7
|
|
|
8
8
|
import { mx } from '@dxos/react-ui-theme';
|
|
9
9
|
|
|
10
|
+
import { decorateMarkdown } from '../markdown';
|
|
11
|
+
|
|
10
12
|
import { commands } from './commands';
|
|
11
13
|
import { editor } from './editor';
|
|
12
|
-
import {
|
|
14
|
+
import { menu } from './menu';
|
|
15
|
+
import { selectionCompartment, selectionEquals, selectionFacet } from './selection';
|
|
13
16
|
import { outlinerTree, treeFacet } from './tree';
|
|
14
|
-
import { floatingMenu } from '../command';
|
|
15
|
-
import { decorateMarkdown } from '../markdown';
|
|
16
17
|
|
|
17
18
|
// ISSUES:
|
|
18
19
|
// TODO(burdon): Remove requirement for continuous lines to be indented (so that user's can't accidentally delete them and break the layout).
|
|
@@ -37,7 +38,7 @@ export type OutlinerProps = {};
|
|
|
37
38
|
* - Constrains editor to outline structure.
|
|
38
39
|
* - Supports smart cut-and-paste.
|
|
39
40
|
*/
|
|
40
|
-
export const outliner = (
|
|
41
|
+
export const outliner = (_options: OutlinerProps = {}): Extension => [
|
|
41
42
|
// Commands.
|
|
42
43
|
Prec.highest(commands()),
|
|
43
44
|
|
|
@@ -51,7 +52,7 @@ export const outliner = (options: OutlinerProps = {}): Extension => [
|
|
|
51
52
|
editor(),
|
|
52
53
|
|
|
53
54
|
// Floating menu.
|
|
54
|
-
|
|
55
|
+
menu(),
|
|
55
56
|
|
|
56
57
|
// Line decorations.
|
|
57
58
|
decorations(),
|
|
@@ -158,7 +159,7 @@ const decorations = () => [
|
|
|
158
159
|
'.cm-list-item-focused': {
|
|
159
160
|
borderColor: 'var(--dx-accentFocusIndicator)',
|
|
160
161
|
},
|
|
161
|
-
'
|
|
162
|
+
'&:focus-within .cm-list-item-selected': {
|
|
162
163
|
borderColor: 'var(--dx-separator)',
|
|
163
164
|
},
|
|
164
165
|
}),
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { Compartment, type EditorState, Facet, type SelectionRange } from '@codemirror/state';
|
|
6
|
-
import { type
|
|
6
|
+
import { type Command, type EditorView } from '@codemirror/view';
|
|
7
7
|
|
|
8
8
|
import { treeFacet } from './tree';
|
|
9
9
|
|
|
@@ -6,10 +6,11 @@ import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
|
|
|
6
6
|
import { EditorState } from '@codemirror/state';
|
|
7
7
|
import { beforeEach, describe, test } from 'vitest';
|
|
8
8
|
|
|
9
|
-
import { outlinerTree, treeFacet, listItemToString, type Item } from './tree';
|
|
10
9
|
import { str } from '../../testing';
|
|
11
10
|
import { type Range } from '../../types';
|
|
12
11
|
|
|
12
|
+
import { type Item, listItemToString, outlinerTree, treeFacet } from './tree';
|
|
13
|
+
|
|
13
14
|
const lines = [
|
|
14
15
|
'- [ ] 1',
|
|
15
16
|
'- [ ] 2',
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { syntaxTree } from '@codemirror/language';
|
|
6
|
-
import {
|
|
6
|
+
import { type EditorState, type Extension, StateField, type Transaction } from '@codemirror/state';
|
|
7
7
|
import { Facet } from '@codemirror/state';
|
|
8
8
|
import { type SyntaxNode } from '@lezer/common';
|
|
9
9
|
|
|
@@ -195,7 +195,7 @@ export type TreeOptions = {};
|
|
|
195
195
|
* This adds overhead relative to the markdown AST, but allows for efficient traversal of the list items.
|
|
196
196
|
* NOTE: Requires markdown parser to be enabled.
|
|
197
197
|
*/
|
|
198
|
-
export const outlinerTree = (
|
|
198
|
+
export const outlinerTree = (_options: TreeOptions = {}): Extension => {
|
|
199
199
|
const buildTree = (state: EditorState): Tree => {
|
|
200
200
|
let tree: Tree | undefined;
|
|
201
201
|
let parent: Item | undefined;
|