@dxos/react-ui-editor 0.8.3 → 0.8.4-main.1f223c7
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 +22 -0
- package/dist/lib/browser/chunk-22UMM3QJ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +2498 -1380
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +72 -2
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/browser/types/index.mjs +13 -0
- package/dist/lib/browser/types/index.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-YXYQPV6R.mjs +24 -0
- package/dist/lib/node-esm/chunk-YXYQPV6R.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +2500 -1383
- 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 +72 -2
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/types/index.mjs +14 -0
- package/dist/lib/node-esm/types/index.mjs.map +7 -0
- package/dist/types/src/components/{Popover → CommandMenu}/CommandMenu.d.ts +10 -6
- package/dist/types/src/components/CommandMenu/CommandMenu.d.ts.map +1 -0
- package/dist/types/src/components/CommandMenu/index.d.ts +2 -0
- package/dist/types/src/components/CommandMenu/index.d.ts.map +1 -0
- package/dist/types/src/components/Editor/Editor.d.ts +19 -0
- package/dist/types/src/components/Editor/Editor.d.ts.map +1 -0
- package/dist/types/src/components/Editor/index.d.ts +2 -0
- package/dist/types/src/components/Editor/index.d.ts.map +1 -0
- 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 -5
- 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 +2 -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.d.ts +20 -7
- package/dist/types/src/extensions/autocomplete.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.stories.d.ts +36 -45
- package/dist/types/src/extensions/automerge/automerge.stories.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.map +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/blast.d.ts.map +1 -1
- package/dist/types/src/extensions/command/action.d.ts +1 -1
- package/dist/types/src/extensions/command/action.d.ts.map +1 -1
- package/dist/types/src/extensions/command/command-menu.d.ts +1 -1
- package/dist/types/src/extensions/command/command-menu.d.ts.map +1 -1
- package/dist/types/src/extensions/command/command.d.ts.map +1 -1
- package/dist/types/src/extensions/command/floating-menu.d.ts.map +1 -1
- package/dist/types/src/extensions/command/hint.d.ts +2 -7
- package/dist/types/src/extensions/command/hint.d.ts.map +1 -1
- package/dist/types/src/extensions/command/index.d.ts +1 -1
- package/dist/types/src/extensions/command/index.d.ts.map +1 -1
- package/dist/types/src/extensions/command/state.d.ts +1 -1
- package/dist/types/src/extensions/command/state.d.ts.map +1 -1
- package/dist/types/src/extensions/command/typeahead.d.ts +7 -2
- package/dist/types/src/extensions/command/typeahead.d.ts.map +1 -1
- package/dist/types/src/extensions/command/useCommandMenu.d.ts +3 -4
- package/dist/types/src/extensions/command/useCommandMenu.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 +15 -1
- package/dist/types/src/extensions/factories.d.ts.map +1 -1
- package/dist/types/src/extensions/index.d.ts +2 -0
- package/dist/types/src/extensions/index.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 +1 -1
- 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 +0 -7
- package/dist/types/src/extensions/modes.d.ts.map +1 -1
- 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/preview/preview.d.ts +3 -6
- package/dist/types/src/extensions/preview/preview.d.ts.map +1 -1
- 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 +71 -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.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/stories/Command.stories.d.ts +12 -4
- package/dist/types/src/stories/Command.stories.d.ts.map +1 -1
- package/dist/types/src/stories/CommandMenu.stories.d.ts +11 -4
- package/dist/types/src/stories/CommandMenu.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Comments.stories.d.ts +21 -9
- package/dist/types/src/stories/Comments.stories.d.ts.map +1 -1
- package/dist/types/src/stories/EditorToolbar.stories.d.ts +40 -3
- package/dist/types/src/stories/EditorToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Experimental.stories.d.ts +22 -12
- package/dist/types/src/stories/Experimental.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Markdown.stories.d.ts +32 -42
- package/dist/types/src/stories/Markdown.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Outliner.stories.d.ts +15 -20
- package/dist/types/src/stories/Outliner.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Preview.stories.d.ts +21 -6
- package/dist/types/src/stories/Preview.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Tags.stories.d.ts +17 -0
- package/dist/types/src/stories/Tags.stories.d.ts.map +1 -0
- package/dist/types/src/stories/TextEditor.stories.d.ts +38 -51
- package/dist/types/src/stories/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/stories/components/EditorStory.d.ts +3 -6
- 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 +28 -29
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +2 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/src/types/types.d.ts +21 -0
- package/dist/types/src/types/types.d.ts.map +1 -0
- 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/domino.d.ts +18 -0
- package/dist/types/src/util/domino.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +2 -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 +64 -55
- package/src/components/{Popover → CommandMenu}/CommandMenu.tsx +93 -26
- package/src/components/{Popover → CommandMenu}/index.ts +0 -2
- package/src/components/Editor/Editor.tsx +39 -0
- package/src/components/Editor/index.ts +5 -0
- package/src/components/EditorToolbar/EditorToolbar.tsx +40 -30
- package/src/components/EditorToolbar/blocks.ts +22 -25
- package/src/components/EditorToolbar/formatting.ts +22 -25
- package/src/components/EditorToolbar/headings.ts +10 -5
- 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 +21 -9
- package/src/components/EditorToolbar/view-mode.ts +12 -7
- package/src/components/index.ts +2 -1
- package/src/defaults.ts +5 -2
- package/src/extensions/autocomplete.ts +204 -54
- package/src/extensions/automerge/automerge.stories.tsx +26 -17
- package/src/extensions/automerge/automerge.ts +4 -3
- package/src/extensions/automerge/defs.ts +1 -1
- package/src/extensions/automerge/sync.ts +1 -1
- package/src/extensions/automerge/update-automerge.ts +1 -1
- package/src/extensions/autoscroll.ts +157 -0
- package/src/extensions/awareness/awareness.ts +2 -2
- package/src/extensions/blast.ts +3 -16
- package/src/extensions/command/action.ts +1 -2
- package/src/extensions/command/command-menu.ts +7 -6
- package/src/extensions/command/command.ts +3 -3
- package/src/extensions/command/floating-menu.ts +10 -15
- package/src/extensions/command/hint.ts +2 -1
- package/src/extensions/command/index.ts +1 -1
- package/src/extensions/command/placeholder.ts +1 -1
- package/src/extensions/command/state.ts +4 -3
- package/src/extensions/command/typeahead.ts +28 -15
- package/src/extensions/command/useCommandMenu.ts +6 -9
- package/src/extensions/comments.ts +18 -13
- package/src/extensions/dnd.ts +1 -1
- package/src/extensions/factories.ts +22 -15
- package/src/extensions/folding.tsx +2 -2
- package/src/extensions/index.ts +2 -0
- package/src/extensions/markdown/action.ts +2 -1
- package/src/extensions/markdown/bundle.ts +25 -3
- package/src/extensions/markdown/changes.ts +1 -1
- package/src/extensions/markdown/decorate.ts +23 -14
- package/src/extensions/markdown/formatting.test.ts +7 -7
- package/src/extensions/markdown/formatting.ts +16 -14
- 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 +0 -9
- package/src/extensions/outliner/outliner.test.ts +3 -2
- package/src/extensions/outliner/outliner.ts +6 -5
- 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/preview/preview.ts +59 -62
- 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 +244 -0
- package/src/extensions/tags/xml-tags.ts +335 -0
- package/src/extensions/tags/xml-util.ts +94 -0
- package/src/hooks/useTextEditor.ts +3 -15
- package/src/index.ts +1 -1
- package/src/stories/Command.stories.tsx +24 -31
- package/src/stories/CommandMenu.stories.tsx +29 -30
- package/src/stories/Comments.stories.tsx +10 -6
- package/src/stories/EditorToolbar.stories.tsx +10 -11
- package/src/stories/Experimental.stories.tsx +12 -8
- package/src/stories/Markdown.stories.tsx +21 -17
- package/src/stories/Outliner.stories.tsx +42 -30
- package/src/stories/Preview.stories.tsx +34 -33
- package/src/stories/Tags.stories.tsx +81 -0
- package/src/stories/TextEditor.stories.tsx +41 -35
- package/src/stories/components/EditorStory.tsx +9 -10
- package/src/styles/theme.ts +11 -10
- package/src/testing/PreviewPopover.tsx +78 -0
- package/src/testing/index.ts +1 -0
- package/src/testing/util.ts +2 -0
- package/src/translations.ts +5 -3
- package/src/types/index.ts +5 -0
- package/src/types/types.ts +32 -0
- 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/domino.ts +51 -0
- package/src/util/index.ts +2 -0
- package/src/util/react.tsx +1 -1
- package/dist/lib/node/index.cjs +0 -7754
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/testing/index.cjs +0 -29
- package/dist/lib/node/testing/index.cjs.map +0 -7
- 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/types.d.ts +0 -14
- package/dist/types/src/types.d.ts.map +0 -1
- package/src/components/Popover/RefDropdownMenu.tsx +0 -79
- package/src/components/Popover/RefPopover.tsx +0 -99
- package/src/types.ts +0 -23
@@ -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,20 +7,21 @@ 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 {
|
10
|
+
import { type Live, live } from '@dxos/live-object';
|
11
11
|
import { type ThemedClassName } from '@dxos/react-ui';
|
12
12
|
import {
|
13
|
-
type
|
13
|
+
type ActionGraphProps,
|
14
|
+
type MenuActionProperties,
|
14
15
|
type MenuItemGroup,
|
16
|
+
type MenuSeparator,
|
15
17
|
type ToolbarMenuActionGroupProperties,
|
16
18
|
createMenuAction,
|
17
19
|
createMenuItemGroup,
|
18
|
-
type ActionGraphProps,
|
19
|
-
type MenuActionProperties,
|
20
20
|
} from '@dxos/react-ui-menu';
|
21
21
|
|
22
|
-
import type { EditorAction,
|
22
|
+
import type { EditorAction, Formatting } from '../../extensions';
|
23
23
|
import { translationKey } from '../../translations';
|
24
|
+
import { type EditorViewMode } from '../../types';
|
24
25
|
|
25
26
|
export type EditorToolbarState = Formatting & Partial<{ viewMode: EditorViewMode }>;
|
26
27
|
|
@@ -52,13 +53,24 @@ export type EditorToolbarProps = ThemedClassName<
|
|
52
53
|
|
53
54
|
export type EditorToolbarItem = EditorAction | MenuItemGroup | MenuSeparator;
|
54
55
|
|
55
|
-
export const createEditorAction = (id: string, invoke: () => void
|
56
|
-
const { label = [`${id} label`, { ns: translationKey }], ...rest } =
|
57
|
-
return createMenuAction(id, invoke, {
|
56
|
+
export const createEditorAction = (id: string, props: Partial<MenuActionProperties>, invoke: () => void) => {
|
57
|
+
const { label = [`${id} label`, { ns: translationKey }], ...rest } = props;
|
58
|
+
return createMenuAction(id, invoke, {
|
59
|
+
label,
|
60
|
+
...rest,
|
61
|
+
}) as Action<MenuActionProperties>;
|
58
62
|
};
|
59
63
|
|
60
64
|
export const createEditorActionGroup = (
|
61
65
|
id: string,
|
62
66
|
props: Omit<ToolbarMenuActionGroupProperties, 'icon'>,
|
63
67
|
icon?: string,
|
64
|
-
) =>
|
68
|
+
) => {
|
69
|
+
const { label = [`${id} label`, { ns: translationKey }], ...rest } = props;
|
70
|
+
return createMenuItemGroup(id, {
|
71
|
+
label,
|
72
|
+
icon,
|
73
|
+
iconOnly: true,
|
74
|
+
...rest,
|
75
|
+
});
|
76
|
+
};
|
@@ -5,9 +5,10 @@
|
|
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
|
-
import { type EditorViewMode } from '../../extensions';
|
10
8
|
import { translationKey } from '../../translations';
|
9
|
+
import { type EditorViewMode } from '../../types';
|
10
|
+
|
11
|
+
import { type EditorToolbarState, createEditorAction, createEditorActionGroup } from './util';
|
11
12
|
|
12
13
|
const createViewModeGroupAction = (value: string) =>
|
13
14
|
createEditorActionGroup(
|
@@ -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
|
);
|
@@ -1,69 +1,219 @@
|
|
1
1
|
//
|
2
|
-
// Copyright
|
2
|
+
// Copyright 2025 DXOS.org
|
3
3
|
//
|
4
4
|
|
5
|
+
import { type Extension, Prec } from '@codemirror/state';
|
5
6
|
import {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
type
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
import { type Extension } from '@codemirror/state';
|
15
|
-
import { keymap } from '@codemirror/view';
|
16
|
-
|
17
|
-
export type AutocompleteResult = Completion;
|
7
|
+
Decoration,
|
8
|
+
type DecorationSet,
|
9
|
+
EditorView,
|
10
|
+
ViewPlugin,
|
11
|
+
type ViewUpdate,
|
12
|
+
WidgetType,
|
13
|
+
keymap,
|
14
|
+
} from '@codemirror/view';
|
18
15
|
|
19
16
|
export type AutocompleteOptions = {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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;
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
+
};
|
28
38
|
|
29
39
|
/**
|
30
|
-
*
|
40
|
+
* Creates an autocomplete extension that shows inline suggestions.
|
41
|
+
* Pressing Tab will complete the suggestion.
|
31
42
|
*/
|
32
|
-
export const autocomplete = ({
|
33
|
-
const
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
export const autocomplete = ({ fireIfEmpty, onSubmit, onSuggest, onCancel }: AutocompleteOptions): Extension => {
|
44
|
+
const suggest = ViewPlugin.fromClass(
|
45
|
+
class {
|
46
|
+
_decorations: DecorationSet;
|
47
|
+
_currentSuggestion: string | null = null;
|
48
|
+
|
49
|
+
constructor(view: EditorView) {
|
50
|
+
this._decorations = this.computeDecorations(view);
|
51
|
+
}
|
52
|
+
|
53
|
+
update(update: ViewUpdate) {
|
54
|
+
if (update.docChanged || update.selectionSet) {
|
55
|
+
this._decorations = this.computeDecorations(update.view);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
private computeDecorations(view: EditorView): DecorationSet {
|
60
|
+
const text = view.state.doc.toString();
|
61
|
+
const suggestions = onSuggest?.(text) ?? [];
|
62
|
+
if (!suggestions.length) {
|
63
|
+
this._currentSuggestion = null;
|
64
|
+
return Decoration.none;
|
65
|
+
}
|
66
|
+
|
67
|
+
// Get the first suggestion.
|
68
|
+
this._currentSuggestion = suggestions[0];
|
69
|
+
const suffix = this._currentSuggestion.slice(text.length);
|
70
|
+
if (!suffix) {
|
71
|
+
return Decoration.none;
|
72
|
+
}
|
73
|
+
|
74
|
+
// Always show ghost text at the end of the document.
|
75
|
+
return Decoration.set([
|
76
|
+
Decoration.widget({
|
77
|
+
widget: new InlineSuggestionWidget(suffix),
|
78
|
+
side: 1,
|
79
|
+
}).range(view.state.doc.length),
|
80
|
+
]);
|
81
|
+
}
|
82
|
+
|
83
|
+
completeSuggestion(view: EditorView): boolean {
|
84
|
+
if (!this._currentSuggestion) {
|
85
|
+
return false;
|
86
|
+
}
|
87
|
+
|
88
|
+
const text = view.state.doc.toString();
|
89
|
+
const suffix = this._currentSuggestion.slice(text.length);
|
90
|
+
if (!suffix) {
|
91
|
+
return false;
|
92
|
+
}
|
93
|
+
|
94
|
+
view.dispatch({
|
95
|
+
changes: {
|
96
|
+
from: view.state.doc.length,
|
97
|
+
insert: suffix,
|
98
|
+
},
|
99
|
+
selection: {
|
100
|
+
anchor: view.state.doc.length + suffix.length,
|
101
|
+
},
|
102
|
+
});
|
103
|
+
|
104
|
+
return true;
|
105
|
+
}
|
106
|
+
},
|
107
|
+
{
|
108
|
+
decorations: (v) => v._decorations,
|
109
|
+
},
|
110
|
+
);
|
111
|
+
|
112
|
+
return [
|
113
|
+
suggest,
|
114
|
+
EditorView.theme({
|
115
|
+
'.cm-inline-suggestion': {
|
116
|
+
opacity: 0.4,
|
117
|
+
},
|
46
118
|
}),
|
47
|
-
];
|
48
119
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
return
|
57
|
-
}
|
58
|
-
|
59
|
-
return {
|
60
|
-
from: match.from,
|
61
|
-
options: onSearch(match.text.toLowerCase()),
|
62
|
-
};
|
120
|
+
Prec.highest(
|
121
|
+
keymap.of([
|
122
|
+
{
|
123
|
+
key: 'Tab',
|
124
|
+
preventDefault: true,
|
125
|
+
run: (view) => {
|
126
|
+
const plugin = view.plugin(suggest);
|
127
|
+
return plugin?.completeSuggestion(view) ?? false;
|
128
|
+
},
|
63
129
|
},
|
64
|
-
|
65
|
-
|
66
|
-
|
130
|
+
{
|
131
|
+
key: 'ArrowRight',
|
132
|
+
preventDefault: true,
|
133
|
+
run: (view) => {
|
134
|
+
// Only complete if cursor is at the end
|
135
|
+
if (view.state.selection.main.head !== view.state.doc.length) {
|
136
|
+
return false;
|
137
|
+
}
|
138
|
+
|
139
|
+
const plugin = view.plugin(suggest);
|
140
|
+
return plugin?.completeSuggestion(view) ?? false;
|
141
|
+
},
|
142
|
+
},
|
143
|
+
{
|
144
|
+
key: 'Enter',
|
145
|
+
preventDefault: true,
|
146
|
+
run: (view) => {
|
147
|
+
const text = view.state.doc.toString().trim();
|
148
|
+
if (onSubmit && (fireIfEmpty || text.length > 0)) {
|
149
|
+
const reset = onSubmit(text);
|
150
|
+
|
151
|
+
// Clear the document after calling onEnter.
|
152
|
+
if (reset) {
|
153
|
+
view.dispatch({
|
154
|
+
changes: {
|
155
|
+
from: 0,
|
156
|
+
to: view.state.doc.length,
|
157
|
+
insert: '',
|
158
|
+
},
|
159
|
+
});
|
160
|
+
}
|
161
|
+
}
|
67
162
|
|
68
|
-
|
163
|
+
return true;
|
164
|
+
},
|
165
|
+
},
|
166
|
+
{
|
167
|
+
key: 'Shift-Enter',
|
168
|
+
preventDefault: true,
|
169
|
+
run: (view) => {
|
170
|
+
view.dispatch({
|
171
|
+
changes: {
|
172
|
+
from: view.state.selection.main.head,
|
173
|
+
insert: '\n',
|
174
|
+
},
|
175
|
+
selection: {
|
176
|
+
anchor: view.state.selection.main.head + 1,
|
177
|
+
head: view.state.selection.main.head + 1,
|
178
|
+
},
|
179
|
+
});
|
180
|
+
return true;
|
181
|
+
},
|
182
|
+
},
|
183
|
+
{
|
184
|
+
key: 'Escape',
|
185
|
+
preventDefault: true,
|
186
|
+
run: (view) => {
|
187
|
+
// Clear the entire document.
|
188
|
+
view.dispatch({
|
189
|
+
changes: {
|
190
|
+
from: 0,
|
191
|
+
to: view.state.doc.length,
|
192
|
+
insert: '',
|
193
|
+
},
|
194
|
+
});
|
195
|
+
onCancel?.();
|
196
|
+
return true;
|
197
|
+
},
|
198
|
+
},
|
199
|
+
]),
|
200
|
+
),
|
201
|
+
];
|
69
202
|
};
|
203
|
+
|
204
|
+
class InlineSuggestionWidget extends WidgetType {
|
205
|
+
constructor(private suffix: string) {
|
206
|
+
super();
|
207
|
+
}
|
208
|
+
|
209
|
+
override toDOM(): HTMLSpanElement {
|
210
|
+
const span = document.createElement('span');
|
211
|
+
span.textContent = this.suffix;
|
212
|
+
span.className = 'cm-inline-suggestion';
|
213
|
+
return span;
|
214
|
+
}
|
215
|
+
|
216
|
+
override eq(other: InlineSuggestionWidget): boolean {
|
217
|
+
return other.suffix === this.suffix;
|
218
|
+
}
|
219
|
+
}
|
@@ -8,18 +8,19 @@ import '@preact/signals-react';
|
|
8
8
|
|
9
9
|
import { Repo } from '@automerge/automerge-repo';
|
10
10
|
import { BroadcastChannelNetworkAdapter } from '@automerge/automerge-repo-network-broadcastchannel';
|
11
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
11
12
|
import React, { useEffect, useState } from 'react';
|
12
13
|
|
13
14
|
import { Obj, Ref, Type } from '@dxos/echo';
|
14
|
-
import { DocAccessor,
|
15
|
-
import {
|
16
|
-
import {
|
15
|
+
import { DocAccessor, Query, type Space, createDocAccessor, useQuery, useSpace } from '@dxos/react-client/echo';
|
16
|
+
import { type Identity, useIdentity } from '@dxos/react-client/halo';
|
17
|
+
import { type ClientRepeatedComponentProps, ClientRepeater } from '@dxos/react-client/testing';
|
17
18
|
import { useThemeContext } from '@dxos/react-ui';
|
18
|
-
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
19
|
+
import { render, withLayout, withTheme } from '@dxos/storybook-utils';
|
19
20
|
|
20
21
|
import { editorSlots } from '../../defaults';
|
21
22
|
import { useTextEditor } from '../../hooks';
|
22
|
-
import translations from '../../translations';
|
23
|
+
import { translations } from '../../translations';
|
23
24
|
import { createBasicExtensions, createDataExtensions, createThemeExtensions } from '../factories';
|
24
25
|
|
25
26
|
const initialContent = 'Hello world!';
|
@@ -41,7 +42,7 @@ const Editor = ({ source, autoFocus, space, identity }: EditorProps) => {
|
|
41
42
|
() => ({
|
42
43
|
initialValue: DocAccessor.getValue(source),
|
43
44
|
extensions: [
|
44
|
-
createBasicExtensions({ placeholder: 'Type here...' }),
|
45
|
+
createBasicExtensions({ placeholder: 'Type here...', search: true }),
|
45
46
|
createThemeExtensions({ themeMode, slots: editorSlots }),
|
46
47
|
createDataExtensions({ id: 'test', text: source, space, identity }),
|
47
48
|
],
|
@@ -53,7 +54,7 @@ const Editor = ({ source, autoFocus, space, identity }: EditorProps) => {
|
|
53
54
|
return <div ref={parentRef} className='flex w-full' />;
|
54
55
|
};
|
55
56
|
|
56
|
-
const
|
57
|
+
const DefaultStory = () => {
|
57
58
|
const [object1, setObject1] = useState<DocAccessor<TestObject>>();
|
58
59
|
const [object2, setObject2] = useState<DocAccessor<TestObject>>();
|
59
60
|
|
@@ -88,14 +89,6 @@ const Story = () => {
|
|
88
89
|
);
|
89
90
|
};
|
90
91
|
|
91
|
-
export default {
|
92
|
-
title: 'ui/react-ui-editor/Automerge',
|
93
|
-
component: Editor,
|
94
|
-
decorators: [withTheme, withLayout({ fullscreen: true })],
|
95
|
-
render: () => <Story />,
|
96
|
-
parameters: { translations },
|
97
|
-
};
|
98
|
-
|
99
92
|
const EchoStory = ({ spaceKey }: ClientRepeatedComponentProps) => {
|
100
93
|
const identity = useIdentity();
|
101
94
|
const space = useSpace(spaceKey);
|
@@ -116,9 +109,25 @@ const EchoStory = ({ spaceKey }: ClientRepeatedComponentProps) => {
|
|
116
109
|
return <Editor source={source} space={space} identity={identity ?? undefined} />;
|
117
110
|
};
|
118
111
|
|
119
|
-
|
112
|
+
const meta = {
|
113
|
+
title: 'ui/react-ui-editor/Automerge',
|
114
|
+
component: Editor as any,
|
115
|
+
render: render(DefaultStory),
|
116
|
+
decorators: [withTheme, withLayout({ fullscreen: true })],
|
117
|
+
parameters: {
|
118
|
+
translations,
|
119
|
+
},
|
120
|
+
} satisfies Meta<typeof DefaultStory>;
|
121
|
+
|
122
|
+
export default meta;
|
123
|
+
|
124
|
+
type Story = StoryObj<typeof meta>;
|
125
|
+
|
126
|
+
export const Default: Story = {
|
127
|
+
args: {},
|
128
|
+
};
|
120
129
|
|
121
|
-
export const WithEcho = {
|
130
|
+
export const WithEcho: Story = {
|
122
131
|
decorators: [withTheme],
|
123
132
|
render: () => {
|
124
133
|
return (
|
@@ -5,15 +5,16 @@
|
|
5
5
|
//
|
6
6
|
|
7
7
|
import { next as A } from '@automerge/automerge';
|
8
|
-
import {
|
8
|
+
import { type Extension, StateField } from '@codemirror/state';
|
9
9
|
import { EditorView, ViewPlugin } from '@codemirror/view';
|
10
10
|
|
11
11
|
import { type DocAccessor } from '@dxos/react-client/echo';
|
12
12
|
|
13
|
+
import { Cursor } from '../../util';
|
14
|
+
|
13
15
|
import { cursorConverter } from './cursor';
|
14
|
-
import {
|
16
|
+
import { type State, isReconcile, updateHeadsEffect } from './defs';
|
15
17
|
import { Syncer } from './sync';
|
16
|
-
import { Cursor } from '../../util';
|
17
18
|
|
18
19
|
export const automerge = (accessor: DocAccessor): Extension => {
|
19
20
|
const syncState = StateField.define<State>({
|
@@ -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[];
|
@@ -10,7 +10,7 @@ import { type EditorView } from '@codemirror/view';
|
|
10
10
|
|
11
11
|
import { type IDocHandle } from '@dxos/react-client/echo';
|
12
12
|
|
13
|
-
import { getLastHeads, getPath, isReconcile, reconcileAnnotation,
|
13
|
+
import { type State, getLastHeads, getPath, isReconcile, reconcileAnnotation, updateHeads } from './defs';
|
14
14
|
import { updateAutomerge } from './update-automerge';
|
15
15
|
import { updateCodeMirror } from './update-codemirror';
|
16
16
|
|
@@ -5,7 +5,7 @@
|
|
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
10
|
import { type IDocHandle } from '@dxos/react-client/echo';
|
11
11
|
|