@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
|
@@ -7,8 +7,9 @@ import { type EditorView } from '@codemirror/view';
|
|
|
7
7
|
import { type NodeArg } from '@dxos/app-graph';
|
|
8
8
|
import { type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
|
|
10
|
+
import { type Formatting, Inline, addLink, removeLink, setStyle } from '../../extensions';
|
|
11
|
+
|
|
12
|
+
import { type EditorToolbarState, createEditorAction, createEditorActionGroup } from './util';
|
|
12
13
|
|
|
13
14
|
const formats = {
|
|
14
15
|
strong: 'ph--text-b--regular',
|
|
@@ -28,31 +29,27 @@ const createFormattingGroup = (formatting: Formatting) =>
|
|
|
28
29
|
const createFormattingActions = (formatting: Formatting, getView: () => EditorView) =>
|
|
29
30
|
Object.entries(formats).map(([type, icon]) => {
|
|
30
31
|
const checked = !!formatting[type as keyof Formatting];
|
|
31
|
-
return createEditorAction(
|
|
32
|
-
|
|
33
|
-
()
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
32
|
+
return createEditorAction(type, { checked, icon }, () => {
|
|
33
|
+
const view = getView();
|
|
34
|
+
if (!view) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
if (type === 'link') {
|
|
39
|
+
checked ? removeLink(view) : addLink()(view);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
43
42
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
{ checked, icon },
|
|
55
|
-
);
|
|
43
|
+
const inlineType =
|
|
44
|
+
type === 'strong'
|
|
45
|
+
? Inline.Strong
|
|
46
|
+
: type === 'emphasis'
|
|
47
|
+
? Inline.Emphasis
|
|
48
|
+
: type === 'strikethrough'
|
|
49
|
+
? Inline.Strikethrough
|
|
50
|
+
: Inline.Code;
|
|
51
|
+
setStyle(inlineType, !checked)(view);
|
|
52
|
+
});
|
|
56
53
|
});
|
|
57
54
|
|
|
58
55
|
export const createFormatting = (state: EditorToolbarState, getView: () => EditorView) => {
|
|
@@ -7,10 +7,11 @@ import { type EditorView } from '@codemirror/view';
|
|
|
7
7
|
import { type NodeArg } from '@dxos/app-graph';
|
|
8
8
|
import { type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';
|
|
9
9
|
|
|
10
|
-
import { createEditorAction, createEditorActionGroup, type EditorToolbarState } from './util';
|
|
11
10
|
import { setHeading } from '../../extensions';
|
|
12
11
|
import { translationKey } from '../../translations';
|
|
13
12
|
|
|
13
|
+
import { type EditorToolbarState, createEditorAction, createEditorActionGroup } from './util';
|
|
14
|
+
|
|
14
15
|
const createHeadingGroupAction = (value: string) =>
|
|
15
16
|
createEditorActionGroup(
|
|
16
17
|
'heading',
|
|
@@ -18,12 +19,13 @@ const createHeadingGroupAction = (value: string) =>
|
|
|
18
19
|
variant: 'dropdownMenu',
|
|
19
20
|
applyActive: true,
|
|
20
21
|
selectCardinality: 'single',
|
|
22
|
+
// TODO(wittjosiah): Remove? Not sure this does anything.
|
|
21
23
|
value,
|
|
22
24
|
} as ToolbarMenuActionGroupProperties,
|
|
23
25
|
'ph--text-h--regular',
|
|
24
26
|
);
|
|
25
27
|
|
|
26
|
-
const createHeadingActions = (getView: () => EditorView) =>
|
|
28
|
+
const createHeadingActions = (currentLevel: string, getView: () => EditorView) =>
|
|
27
29
|
Object.entries({
|
|
28
30
|
'0': 'ph--paragraph--regular',
|
|
29
31
|
'1': 'ph--text-h-one--regular',
|
|
@@ -34,22 +36,27 @@ const createHeadingActions = (getView: () => EditorView) =>
|
|
|
34
36
|
'6': 'ph--text-h-six--regular',
|
|
35
37
|
}).map(([levelStr, icon]) => {
|
|
36
38
|
const level = parseInt(levelStr);
|
|
37
|
-
return createEditorAction(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
return createEditorAction(
|
|
40
|
+
`heading--${levelStr}`,
|
|
41
|
+
{
|
|
42
|
+
label: ['heading level label', { count: level, ns: translationKey }],
|
|
43
|
+
icon,
|
|
44
|
+
checked: levelStr === currentLevel,
|
|
45
|
+
},
|
|
46
|
+
() => setHeading(level)(getView()),
|
|
47
|
+
);
|
|
41
48
|
});
|
|
42
49
|
|
|
43
50
|
const computeHeadingValue = (state: EditorToolbarState) => {
|
|
44
51
|
const blockType = state ? state.blockType : 'paragraph';
|
|
45
|
-
const
|
|
46
|
-
return
|
|
52
|
+
const heading = blockType && /heading(\d)/.exec(blockType);
|
|
53
|
+
return heading ? heading[1] : blockType === 'paragraph' || !blockType ? '0' : '';
|
|
47
54
|
};
|
|
48
55
|
|
|
49
56
|
export const createHeadings = (state: EditorToolbarState, getView: () => EditorView) => {
|
|
50
57
|
const headingValue = computeHeadingValue(state);
|
|
51
58
|
const headingGroupAction = createHeadingGroupAction(headingValue);
|
|
52
|
-
const headingActions = createHeadingActions(getView);
|
|
59
|
+
const headingActions = createHeadingActions(headingValue, getView);
|
|
53
60
|
return {
|
|
54
61
|
nodes: [headingGroupAction as NodeArg<any>, ...headingActions],
|
|
55
62
|
edges: [
|
|
@@ -5,10 +5,14 @@
|
|
|
5
5
|
import { createEditorAction } from './util';
|
|
6
6
|
|
|
7
7
|
const createImageUploadAction = (onImageUpload: () => void) =>
|
|
8
|
-
createEditorAction(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
createEditorAction(
|
|
9
|
+
'image',
|
|
10
|
+
{
|
|
11
|
+
testId: 'editor.toolbar.image',
|
|
12
|
+
icon: 'ph--image-square--regular',
|
|
13
|
+
},
|
|
14
|
+
onImageUpload,
|
|
15
|
+
);
|
|
12
16
|
|
|
13
17
|
export const createImageUpload = (onImageUpload: () => void) => ({
|
|
14
18
|
nodes: [createImageUploadAction(onImageUpload)],
|
|
@@ -7,8 +7,9 @@ import { type EditorView } from '@codemirror/view';
|
|
|
7
7
|
import { type NodeArg } from '@dxos/app-graph';
|
|
8
8
|
import { type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
|
|
10
|
+
import { List, addList, removeList } from '../../extensions';
|
|
11
|
+
|
|
12
|
+
import { type EditorToolbarState, createEditorAction, createEditorActionGroup } from './util';
|
|
12
13
|
|
|
13
14
|
const listStyles = {
|
|
14
15
|
bullet: 'ph--list-bullets--regular',
|
|
@@ -26,23 +27,19 @@ const createListGroupAction = (value: string) =>
|
|
|
26
27
|
const createListActions = (value: string, getView: () => EditorView) =>
|
|
27
28
|
Object.entries(listStyles).map(([listStyle, icon]) => {
|
|
28
29
|
const checked = value === listStyle;
|
|
29
|
-
return createEditorAction(
|
|
30
|
-
|
|
31
|
-
()
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
{ checked, icon },
|
|
45
|
-
);
|
|
30
|
+
return createEditorAction(`list-${listStyle}`, { checked, icon }, () => {
|
|
31
|
+
const view = getView();
|
|
32
|
+
if (!view) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const listType = listStyle === 'ordered' ? List.Ordered : listStyle === 'bullet' ? List.Bullet : List.Task;
|
|
37
|
+
if (checked) {
|
|
38
|
+
removeList(listType)(view);
|
|
39
|
+
} else {
|
|
40
|
+
addList(listType)(view);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
46
43
|
});
|
|
47
44
|
|
|
48
45
|
export const createLists = (state: EditorToolbarState, getView: () => EditorView) => {
|
|
@@ -8,10 +8,14 @@ import { type EditorView } from '@codemirror/view';
|
|
|
8
8
|
import { createEditorAction } from './util';
|
|
9
9
|
|
|
10
10
|
const createSearchAction = (getView: () => EditorView) =>
|
|
11
|
-
createEditorAction(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
createEditorAction(
|
|
12
|
+
'search',
|
|
13
|
+
{
|
|
14
|
+
testId: 'editor.toolbar.search',
|
|
15
|
+
icon: 'ph--magnifying-glass--regular',
|
|
16
|
+
},
|
|
17
|
+
() => openSearchPanel(getView()),
|
|
18
|
+
);
|
|
15
19
|
|
|
16
20
|
export const createSearch = (getView: () => EditorView) => ({
|
|
17
21
|
nodes: [createSearchAction(getView)],
|
|
@@ -7,8 +7,7 @@ import { type Rx } from '@effect-rx/rx-react';
|
|
|
7
7
|
import { useMemo } from 'react';
|
|
8
8
|
|
|
9
9
|
import { type Action } from '@dxos/app-graph';
|
|
10
|
-
import {
|
|
11
|
-
import { type ThemedClassName } from '@dxos/react-ui';
|
|
10
|
+
import { type Live, live } from '@dxos/live-object';
|
|
12
11
|
import {
|
|
13
12
|
type ActionGraphProps,
|
|
14
13
|
type MenuActionProperties,
|
|
@@ -23,23 +22,12 @@ import type { EditorAction, Formatting } from '../../extensions';
|
|
|
23
22
|
import { translationKey } from '../../translations';
|
|
24
23
|
import { type EditorViewMode } from '../../types';
|
|
25
24
|
|
|
26
|
-
export type EditorToolbarState =
|
|
25
|
+
export type EditorToolbarState = { viewMode?: EditorViewMode } & Formatting;
|
|
27
26
|
|
|
28
|
-
export const useEditorToolbarState = (initialState: Partial<EditorToolbarState> = {}) => {
|
|
27
|
+
export const useEditorToolbarState = (initialState: Partial<EditorToolbarState> = {}): Live<EditorToolbarState> => {
|
|
29
28
|
return useMemo(() => live<EditorToolbarState>(initialState), []);
|
|
30
29
|
};
|
|
31
30
|
|
|
32
|
-
export type EditorToolbarFeatureFlags = Partial<{
|
|
33
|
-
headings: boolean;
|
|
34
|
-
formatting: boolean;
|
|
35
|
-
lists: boolean;
|
|
36
|
-
blocks: boolean;
|
|
37
|
-
search: boolean;
|
|
38
|
-
// TODO(wittjosiah): Factor out. Depend on plugin-level capabilities.
|
|
39
|
-
image: () => void;
|
|
40
|
-
viewMode: (mode: EditorViewMode) => void;
|
|
41
|
-
}>;
|
|
42
|
-
|
|
43
31
|
export type EditorToolbarActionGraphProps = {
|
|
44
32
|
state: Live<EditorToolbarState>;
|
|
45
33
|
getView: () => EditorView;
|
|
@@ -47,19 +35,26 @@ export type EditorToolbarActionGraphProps = {
|
|
|
47
35
|
customActions?: Rx.Rx<ActionGraphProps>;
|
|
48
36
|
};
|
|
49
37
|
|
|
50
|
-
export type EditorToolbarProps = ThemedClassName<
|
|
51
|
-
EditorToolbarActionGraphProps & EditorToolbarFeatureFlags & { attendableId?: string; role?: string }
|
|
52
|
-
>;
|
|
53
|
-
|
|
54
38
|
export type EditorToolbarItem = EditorAction | MenuItemGroup | MenuSeparator;
|
|
55
39
|
|
|
56
|
-
export const createEditorAction = (id: string, invoke: () => void
|
|
57
|
-
const { label = [`${id} label`, { ns: translationKey }], ...rest } =
|
|
58
|
-
return createMenuAction(id, invoke, {
|
|
40
|
+
export const createEditorAction = (id: string, props: Partial<MenuActionProperties>, invoke: () => void) => {
|
|
41
|
+
const { label = [`${id} label`, { ns: translationKey }], ...rest } = props;
|
|
42
|
+
return createMenuAction(id, invoke, {
|
|
43
|
+
label,
|
|
44
|
+
...rest,
|
|
45
|
+
}) as Action<MenuActionProperties>;
|
|
59
46
|
};
|
|
60
47
|
|
|
61
48
|
export const createEditorActionGroup = (
|
|
62
49
|
id: string,
|
|
63
50
|
props: Omit<ToolbarMenuActionGroupProperties, 'icon'>,
|
|
64
51
|
icon?: string,
|
|
65
|
-
) =>
|
|
52
|
+
) => {
|
|
53
|
+
const { label = [`${id} label`, { ns: translationKey }], ...rest } = props;
|
|
54
|
+
return createMenuItemGroup(id, {
|
|
55
|
+
label,
|
|
56
|
+
icon,
|
|
57
|
+
iconOnly: true,
|
|
58
|
+
...rest,
|
|
59
|
+
});
|
|
60
|
+
};
|
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
import { type NodeArg } from '@dxos/app-graph';
|
|
6
6
|
import { type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';
|
|
7
7
|
|
|
8
|
-
import { createEditorAction, createEditorActionGroup, type EditorToolbarState } from './util';
|
|
9
8
|
import { translationKey } from '../../translations';
|
|
10
9
|
import { type EditorViewMode } from '../../types';
|
|
11
10
|
|
|
11
|
+
import { type EditorToolbarState, createEditorAction, createEditorActionGroup } from './util';
|
|
12
|
+
|
|
12
13
|
const createViewModeGroupAction = (value: string) =>
|
|
13
14
|
createEditorActionGroup(
|
|
14
15
|
'viewMode',
|
|
@@ -28,11 +29,15 @@ const createViewModeActions = (value: string, onViewModeChange: (mode: EditorVie
|
|
|
28
29
|
readonly: 'ph--pencil-slash--regular',
|
|
29
30
|
}).map(([viewMode, icon]) => {
|
|
30
31
|
const checked = viewMode === value;
|
|
31
|
-
return createEditorAction(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
return createEditorAction(
|
|
33
|
+
`view-mode--${viewMode}`,
|
|
34
|
+
{
|
|
35
|
+
label: [`${viewMode} mode label`, { ns: translationKey }],
|
|
36
|
+
checked,
|
|
37
|
+
icon,
|
|
38
|
+
},
|
|
39
|
+
() => onViewModeChange(viewMode as EditorViewMode),
|
|
40
|
+
);
|
|
36
41
|
});
|
|
37
42
|
|
|
38
43
|
export const createViewMode = (state: EditorToolbarState, onViewModeChange: (mode: EditorViewMode) => void) => {
|
package/src/components/index.ts
CHANGED
package/src/defaults.ts
CHANGED
|
@@ -28,7 +28,9 @@ export const editorSlots: ThemeExtensionsOptions['slots'] = {
|
|
|
28
28
|
|
|
29
29
|
export const editorGutter = EditorView.theme({
|
|
30
30
|
'.cm-gutters': {
|
|
31
|
-
|
|
31
|
+
// NOTE: Color required to cover content if scrolling horizontally.
|
|
32
|
+
// TODO(burdon): Non-transparent background clips the focus ring.
|
|
33
|
+
background: 'var(--dx-baseSurface) !important',
|
|
32
34
|
paddingRight: '1rem',
|
|
33
35
|
},
|
|
34
36
|
});
|
|
@@ -42,8 +44,9 @@ export const editorMonospace = EditorView.theme({
|
|
|
42
44
|
export const editorWithToolbarLayout =
|
|
43
45
|
'grid grid-cols-1 grid-rows-[min-content_1fr] data-[toolbar=disabled]:grid-rows-[1fr] justify-center content-start overflow-hidden';
|
|
44
46
|
|
|
47
|
+
// NOTE: Padding is added to the editor to account for the focus ring (since otherwise the CM gutter will clip it)
|
|
45
48
|
export const stackItemContentEditorClassNames = (role?: string) =>
|
|
46
49
|
mx(
|
|
47
|
-
'
|
|
50
|
+
'p-0.5 dx-focus-ring-inset attention-surface data-[toolbar=disabled]:pbs-2',
|
|
48
51
|
role === 'section' ? '[&_.cm-scroller]:overflow-hidden [&_.cm-scroller]:min-bs-24' : 'min-bs-0',
|
|
49
52
|
);
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Extension, Prec } from '@codemirror/state';
|
|
6
|
+
import {
|
|
7
|
+
Decoration,
|
|
8
|
+
type DecorationSet,
|
|
9
|
+
EditorView,
|
|
10
|
+
ViewPlugin,
|
|
11
|
+
type ViewUpdate,
|
|
12
|
+
WidgetType,
|
|
13
|
+
keymap,
|
|
14
|
+
} from '@codemirror/view';
|
|
15
|
+
|
|
16
|
+
export type AutocompleteOptions = {
|
|
17
|
+
fireIfEmpty?: boolean;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Callback triggered when Enter is pressed.
|
|
21
|
+
* @param text The current text in the editor
|
|
22
|
+
* @returns true if the editor should reset the document.
|
|
23
|
+
*/
|
|
24
|
+
onSubmit?: (text: string) => boolean | void;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Function that returns a list of suggestions based on the current text.
|
|
28
|
+
* @param text The current text before the cursor
|
|
29
|
+
* @returns Array of suggestion strings
|
|
30
|
+
*/
|
|
31
|
+
onSuggest?: (text: string) => string[];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* ESC pressed.
|
|
35
|
+
*/
|
|
36
|
+
onCancel?: () => void;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Creates an autocomplete extension that shows inline suggestions.
|
|
41
|
+
* Pressing Tab will complete the suggestion.
|
|
42
|
+
*/
|
|
43
|
+
// TODO(burdon): Reconcile with typeahead.
|
|
44
|
+
export const autocomplete = ({ fireIfEmpty, onSubmit, onSuggest, onCancel }: AutocompleteOptions = {}): Extension => {
|
|
45
|
+
const suggest = ViewPlugin.fromClass(
|
|
46
|
+
class {
|
|
47
|
+
_decorations: DecorationSet;
|
|
48
|
+
_currentSuggestion: string | null = null;
|
|
49
|
+
|
|
50
|
+
constructor(view: EditorView) {
|
|
51
|
+
this._decorations = this.computeDecorations(view);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
update(update: ViewUpdate) {
|
|
55
|
+
if (update.docChanged || update.selectionSet) {
|
|
56
|
+
this._decorations = this.computeDecorations(update.view);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private computeDecorations(view: EditorView): DecorationSet {
|
|
61
|
+
const text = view.state.doc.toString();
|
|
62
|
+
const suggestions = onSuggest?.(text) ?? [];
|
|
63
|
+
if (!suggestions.length) {
|
|
64
|
+
this._currentSuggestion = null;
|
|
65
|
+
return Decoration.none;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Get the first suggestion.
|
|
69
|
+
this._currentSuggestion = suggestions[0];
|
|
70
|
+
const suffix = this._currentSuggestion.slice(text.length);
|
|
71
|
+
if (!suffix) {
|
|
72
|
+
return Decoration.none;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Always show ghost text at the end of the document.
|
|
76
|
+
return Decoration.set([
|
|
77
|
+
Decoration.widget({
|
|
78
|
+
widget: new InlineSuggestionWidget(suffix),
|
|
79
|
+
side: 1,
|
|
80
|
+
}).range(view.state.doc.length),
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
completeSuggestion(view: EditorView): boolean {
|
|
85
|
+
if (!this._currentSuggestion) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const text = view.state.doc.toString();
|
|
90
|
+
const suffix = this._currentSuggestion.slice(text.length);
|
|
91
|
+
if (!suffix) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
view.dispatch({
|
|
96
|
+
changes: {
|
|
97
|
+
from: view.state.doc.length,
|
|
98
|
+
insert: suffix,
|
|
99
|
+
},
|
|
100
|
+
selection: {
|
|
101
|
+
anchor: view.state.doc.length + suffix.length,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
decorations: (v) => v._decorations,
|
|
110
|
+
},
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
return [
|
|
114
|
+
suggest,
|
|
115
|
+
EditorView.theme({
|
|
116
|
+
'.cm-inline-suggestion': {
|
|
117
|
+
opacity: 0.4,
|
|
118
|
+
},
|
|
119
|
+
}),
|
|
120
|
+
|
|
121
|
+
Prec.highest(
|
|
122
|
+
keymap.of([
|
|
123
|
+
{
|
|
124
|
+
key: 'Tab',
|
|
125
|
+
preventDefault: true,
|
|
126
|
+
run: (view) => {
|
|
127
|
+
const plugin = view.plugin(suggest);
|
|
128
|
+
return plugin?.completeSuggestion(view) ?? false;
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
key: 'ArrowRight',
|
|
133
|
+
preventDefault: true,
|
|
134
|
+
run: (view) => {
|
|
135
|
+
// Only complete if cursor is at the end
|
|
136
|
+
if (view.state.selection.main.head !== view.state.doc.length) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const plugin = view.plugin(suggest);
|
|
141
|
+
return plugin?.completeSuggestion(view) ?? false;
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
key: 'Enter',
|
|
146
|
+
preventDefault: true,
|
|
147
|
+
run: (view) => {
|
|
148
|
+
const text = view.state.doc.toString().trim();
|
|
149
|
+
if (onSubmit && (fireIfEmpty || text.length > 0)) {
|
|
150
|
+
const reset = onSubmit(text);
|
|
151
|
+
|
|
152
|
+
// Clear the document after calling onEnter.
|
|
153
|
+
if (reset) {
|
|
154
|
+
view.dispatch({
|
|
155
|
+
changes: {
|
|
156
|
+
from: 0,
|
|
157
|
+
to: view.state.doc.length,
|
|
158
|
+
insert: '',
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return true;
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
key: 'Shift-Enter',
|
|
169
|
+
preventDefault: true,
|
|
170
|
+
run: (view) => {
|
|
171
|
+
view.dispatch({
|
|
172
|
+
changes: {
|
|
173
|
+
from: view.state.selection.main.head,
|
|
174
|
+
insert: '\n',
|
|
175
|
+
},
|
|
176
|
+
selection: {
|
|
177
|
+
anchor: view.state.selection.main.head + 1,
|
|
178
|
+
head: view.state.selection.main.head + 1,
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
return true;
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
key: 'Escape',
|
|
186
|
+
preventDefault: true,
|
|
187
|
+
run: (view) => {
|
|
188
|
+
// Clear the entire document.
|
|
189
|
+
view.dispatch({
|
|
190
|
+
changes: {
|
|
191
|
+
from: 0,
|
|
192
|
+
to: view.state.doc.length,
|
|
193
|
+
insert: '',
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
onCancel?.();
|
|
197
|
+
return true;
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
]),
|
|
201
|
+
),
|
|
202
|
+
];
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
class InlineSuggestionWidget extends WidgetType {
|
|
206
|
+
constructor(private suffix: string) {
|
|
207
|
+
super();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
override toDOM(): HTMLSpanElement {
|
|
211
|
+
const span = document.createElement('span');
|
|
212
|
+
span.textContent = this.suffix;
|
|
213
|
+
span.className = 'cm-inline-suggestion';
|
|
214
|
+
return span;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
override eq(other: InlineSuggestionWidget): boolean {
|
|
218
|
+
return other.suffix === this.suffix;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
export type CompoetionContext = { line: string };
|
|
6
|
+
|
|
7
|
+
export type CompletionOptions = {
|
|
8
|
+
default?: string;
|
|
9
|
+
minLength?: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Util to match current line to a static list of completions.
|
|
14
|
+
*/
|
|
15
|
+
export const staticCompletion =
|
|
16
|
+
(completions: string[], options: CompletionOptions = {}) =>
|
|
17
|
+
({ line }: CompoetionContext) => {
|
|
18
|
+
if (line.length === 0 && options.default) {
|
|
19
|
+
return options.default;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const parts = line.split(/\s+/).filter(Boolean);
|
|
23
|
+
if (parts.length) {
|
|
24
|
+
const str = parts.at(-1)!;
|
|
25
|
+
if (str.length >= (options.minLength ?? 0)) {
|
|
26
|
+
for (const completion of completions) {
|
|
27
|
+
const match = matchCompletion(completion, str);
|
|
28
|
+
if (match) {
|
|
29
|
+
return match;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const matchCompletion = (completion: string, str: string, minLength = 0): string | undefined => {
|
|
37
|
+
if (
|
|
38
|
+
str.length >= minLength &&
|
|
39
|
+
completion.length > str.length &&
|
|
40
|
+
completion.startsWith(str)
|
|
41
|
+
// TODO(burdon): If case insensitive, need to replace existing chars.
|
|
42
|
+
// completion.toLowerCase().startsWith(str.toLowerCase())
|
|
43
|
+
) {
|
|
44
|
+
return completion.slice(str.length);
|
|
45
|
+
}
|
|
46
|
+
};
|