@dxos/react-ui-editor 0.8.4-main.b97322e → 0.8.4-main.c4373fc
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 +3082 -1957
- 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 +3082 -1957
- 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/{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 +15 -9
- package/dist/types/src/components/Editor/Editor.d.ts.map +1 -1
- 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 +5 -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 +1 -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 +10 -19
- 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/{command → command-dialog}/action.d.ts +1 -1
- package/dist/types/src/extensions/command-dialog/action.d.ts.map +1 -0
- package/dist/types/src/extensions/{command/command.d.ts → command-dialog/command-dialog.d.ts} +2 -2
- package/dist/types/src/extensions/command-dialog/command-dialog.d.ts.map +1 -0
- package/dist/types/src/extensions/{command → command-dialog}/hint.d.ts +2 -7
- package/dist/types/src/extensions/command-dialog/hint.d.ts.map +1 -0
- package/dist/types/src/extensions/command-dialog/index.d.ts +4 -0
- package/dist/types/src/extensions/command-dialog/index.d.ts.map +1 -0
- package/dist/types/src/extensions/{command → command-dialog}/state.d.ts +1 -1
- package/dist/types/src/extensions/command-dialog/state.d.ts.map +1 -0
- package/dist/types/src/extensions/command-dialog/typeahead.d.ts.map +1 -0
- package/dist/types/src/extensions/{command → command-menu}/command-menu.d.ts +3 -3
- package/dist/types/src/extensions/command-menu/command-menu.d.ts.map +1 -0
- package/dist/types/src/extensions/command-menu/index.d.ts +3 -0
- package/dist/types/src/extensions/command-menu/index.d.ts.map +1 -0
- package/dist/types/src/extensions/command-menu/placeholder.d.ts.map +1 -0
- package/dist/types/src/extensions/command-menu/useCommandMenu.d.ts +24 -0
- package/dist/types/src/extensions/command-menu/useCommandMenu.d.ts.map +1 -0
- 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 +8 -8
- package/dist/types/src/extensions/factories.d.ts.map +1 -1
- package/dist/types/src/extensions/floating-menu.d.ts.map +1 -0
- 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 +5 -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/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/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 +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 +2 -2
- 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/CommandMenu.stories.d.ts +10 -4
- package/dist/types/src/stories/CommandMenu.stories.d.ts.map +1 -1
- 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/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 +38 -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 +68 -60
- package/src/components/{Popover → CommandMenu}/CommandMenu.tsx +95 -26
- package/src/components/{Popover → CommandMenu}/index.ts +0 -2
- package/src/components/Editor/Editor.tsx +50 -15
- package/src/components/EditorToolbar/EditorToolbar.tsx +41 -30
- package/src/components/EditorToolbar/blocks.ts +21 -24
- 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 +16 -5
- package/src/components/EditorToolbar/view-mode.ts +11 -6
- package/src/components/index.ts +1 -1
- package/src/defaults.ts +5 -2
- package/src/extensions/autocomplete.ts +204 -54
- package/src/extensions/automerge/automerge.stories.tsx +31 -24
- 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/{command → command-dialog}/action.ts +2 -3
- package/src/extensions/{command/command.ts → command-dialog/command-dialog.ts} +4 -4
- package/src/extensions/{command → command-dialog}/hint.ts +2 -1
- package/src/extensions/command-dialog/index.ts +7 -0
- package/src/extensions/{command → command-dialog}/state.ts +4 -3
- package/src/extensions/{command → command-dialog}/typeahead.ts +2 -2
- package/src/extensions/{command → command-menu}/command-menu.ts +9 -9
- package/src/extensions/command-menu/index.ts +6 -0
- package/src/extensions/{command → command-menu}/placeholder.ts +1 -1
- package/src/extensions/{command → command-menu}/useCommandMenu.ts +35 -19
- package/src/extensions/comments.ts +18 -13
- package/src/extensions/dnd.ts +1 -1
- package/src/extensions/factories.ts +56 -31
- package/src/extensions/{command/floating-menu.ts → floating-menu.ts} +12 -19
- 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 +5 -1
- package/src/extensions/json.ts +1 -1
- package/src/extensions/markdown/action.ts +2 -1
- package/src/extensions/markdown/bundle.ts +27 -5
- 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 +3 -3
- 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/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/selection.ts +2 -2
- 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 +8 -20
- package/src/stories/CommandDialog.stories.tsx +89 -0
- package/src/stories/CommandMenu.stories.tsx +33 -34
- package/src/stories/Comments.stories.tsx +14 -10
- package/src/stories/EditorToolbar.stories.tsx +13 -12
- package/src/stories/Experimental.stories.tsx +17 -13
- package/src/stories/Markdown.stories.tsx +25 -21
- package/src/stories/Outliner.stories.tsx +46 -34
- package/src/stories/Preview.stories.tsx +34 -33
- package/src/stories/Tags.stories.tsx +81 -0
- package/src/stories/TextEditor.stories.tsx +45 -38
- package/src/stories/components/EditorStory.tsx +14 -15
- package/src/styles/theme.ts +15 -12
- 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 +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.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/command/action.d.ts.map +0 -1
- package/dist/types/src/extensions/command/command-menu.d.ts.map +0 -1
- package/dist/types/src/extensions/command/command.d.ts.map +0 -1
- package/dist/types/src/extensions/command/floating-menu.d.ts.map +0 -1
- 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.map +0 -1
- package/dist/types/src/extensions/command/state.d.ts.map +0 -1
- 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/src/components/Popover/RefDropdownMenu.tsx +0 -85
- package/src/components/Popover/RefPopover.tsx +0 -99
- package/src/extensions/command/index.ts +0 -10
- package/src/stories/Command.stories.tsx +0 -97
- /package/dist/types/src/extensions/{command → command-dialog}/typeahead.d.ts +0 -0
- /package/dist/types/src/extensions/{command → command-menu}/placeholder.d.ts +0 -0
- /package/dist/types/src/extensions/{command/floating-menu.d.ts → floating-menu.d.ts} +0 -0
|
@@ -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',
|
|
@@ -34,10 +35,14 @@ const createHeadingActions = (getView: () => EditorView) =>
|
|
|
34
35
|
'6': 'ph--text-h-six--regular',
|
|
35
36
|
}).map(([levelStr, icon]) => {
|
|
36
37
|
const level = parseInt(levelStr);
|
|
37
|
-
return createEditorAction(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
return createEditorAction(
|
|
39
|
+
`heading--${levelStr}`,
|
|
40
|
+
{
|
|
41
|
+
label: ['heading level label', { count: level, ns: translationKey }],
|
|
42
|
+
icon,
|
|
43
|
+
},
|
|
44
|
+
() => setHeading(level)(getView()),
|
|
45
|
+
);
|
|
41
46
|
});
|
|
42
47
|
|
|
43
48
|
const computeHeadingValue = (state: EditorToolbarState) => {
|
|
@@ -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,7 +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 {
|
|
10
|
+
import { type Live, live } from '@dxos/live-object';
|
|
11
11
|
import { type ThemedClassName } from '@dxos/react-ui';
|
|
12
12
|
import {
|
|
13
13
|
type ActionGraphProps,
|
|
@@ -53,13 +53,24 @@ export type EditorToolbarProps = ThemedClassName<
|
|
|
53
53
|
|
|
54
54
|
export type EditorToolbarItem = EditorAction | MenuItemGroup | MenuSeparator;
|
|
55
55
|
|
|
56
|
-
export const createEditorAction = (id: string, invoke: () => void
|
|
57
|
-
const { label = [`${id} label`, { ns: translationKey }], ...rest } =
|
|
58
|
-
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>;
|
|
59
62
|
};
|
|
60
63
|
|
|
61
64
|
export const createEditorActionGroup = (
|
|
62
65
|
id: string,
|
|
63
66
|
props: Omit<ToolbarMenuActionGroupProperties, 'icon'>,
|
|
64
67
|
icon?: string,
|
|
65
|
-
) =>
|
|
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,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
|
);
|
|
@@ -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
|
+
}
|
|
@@ -2,20 +2,20 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
|
|
7
5
|
import '@preact/signals-react';
|
|
8
6
|
|
|
9
7
|
import { Repo } from '@automerge/automerge-repo';
|
|
10
8
|
import { BroadcastChannelNetworkAdapter } from '@automerge/automerge-repo-network-broadcastchannel';
|
|
9
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
11
10
|
import React, { useEffect, useState } from 'react';
|
|
12
11
|
|
|
13
12
|
import { Obj, Ref, Type } from '@dxos/echo';
|
|
14
|
-
import { DocAccessor,
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
13
|
+
import { DocAccessor, Query, type Space, createDocAccessor, useQuery, useSpace } from '@dxos/react-client/echo';
|
|
14
|
+
import { type Identity, useIdentity } from '@dxos/react-client/halo';
|
|
15
|
+
import { type ClientRepeatedComponentProps, ClientRepeater } from '@dxos/react-client/testing';
|
|
17
16
|
import { useThemeContext } from '@dxos/react-ui';
|
|
18
|
-
import {
|
|
17
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
18
|
+
import { render } from '@dxos/storybook-utils';
|
|
19
19
|
|
|
20
20
|
import { editorSlots } from '../../defaults';
|
|
21
21
|
import { useTextEditor } from '../../hooks';
|
|
@@ -41,7 +41,7 @@ const Editor = ({ source, autoFocus, space, identity }: EditorProps) => {
|
|
|
41
41
|
() => ({
|
|
42
42
|
initialValue: DocAccessor.getValue(source),
|
|
43
43
|
extensions: [
|
|
44
|
-
createBasicExtensions({ placeholder: 'Type here...' }),
|
|
44
|
+
createBasicExtensions({ placeholder: 'Type here...', search: true }),
|
|
45
45
|
createThemeExtensions({ themeMode, slots: editorSlots }),
|
|
46
46
|
createDataExtensions({ id: 'test', text: source, space, identity }),
|
|
47
47
|
],
|
|
@@ -53,7 +53,7 @@ const Editor = ({ source, autoFocus, space, identity }: EditorProps) => {
|
|
|
53
53
|
return <div ref={parentRef} className='flex w-full' />;
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
-
const
|
|
56
|
+
const DefaultStory = () => {
|
|
57
57
|
const [object1, setObject1] = useState<DocAccessor<TestObject>>();
|
|
58
58
|
const [object2, setObject2] = useState<DocAccessor<TestObject>>();
|
|
59
59
|
|
|
@@ -88,16 +88,6 @@ const Story = () => {
|
|
|
88
88
|
);
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
export default {
|
|
92
|
-
title: 'ui/react-ui-editor/Automerge',
|
|
93
|
-
component: Editor,
|
|
94
|
-
decorators: [withTheme, withLayout({ fullscreen: true })],
|
|
95
|
-
render: () => <Story />,
|
|
96
|
-
parameters: {
|
|
97
|
-
translations,
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
|
|
101
91
|
const EchoStory = ({ spaceKey }: ClientRepeatedComponentProps) => {
|
|
102
92
|
const identity = useIdentity();
|
|
103
93
|
const space = useSpace(spaceKey);
|
|
@@ -105,8 +95,9 @@ const EchoStory = ({ spaceKey }: ClientRepeatedComponentProps) => {
|
|
|
105
95
|
const objects = useQuery(space, Query.type(Type.Expando, { type: 'test' }));
|
|
106
96
|
|
|
107
97
|
useEffect(() => {
|
|
108
|
-
|
|
109
|
-
|
|
98
|
+
const content = objects[0]?.content.target;
|
|
99
|
+
if (!source && content) {
|
|
100
|
+
const source = createDocAccessor(content, ['content']);
|
|
110
101
|
setSource(source);
|
|
111
102
|
}
|
|
112
103
|
}, [objects, source]);
|
|
@@ -118,17 +109,33 @@ const EchoStory = ({ spaceKey }: ClientRepeatedComponentProps) => {
|
|
|
118
109
|
return <Editor source={source} space={space} identity={identity ?? undefined} />;
|
|
119
110
|
};
|
|
120
111
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
112
|
+
const meta = {
|
|
113
|
+
title: 'ui/react-ui-editor/Automerge',
|
|
114
|
+
component: Editor as any,
|
|
115
|
+
render: render(DefaultStory),
|
|
124
116
|
decorators: [withTheme],
|
|
117
|
+
parameters: {
|
|
118
|
+
layout: 'fullscreen',
|
|
119
|
+
translations,
|
|
120
|
+
},
|
|
121
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
122
|
+
|
|
123
|
+
export default meta;
|
|
124
|
+
|
|
125
|
+
type Story = StoryObj<typeof meta>;
|
|
126
|
+
|
|
127
|
+
export const Default: Story = {
|
|
128
|
+
args: {},
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const WithEcho: Story = {
|
|
125
132
|
render: () => {
|
|
126
133
|
return (
|
|
127
134
|
<ClientRepeater
|
|
128
135
|
count={2}
|
|
129
136
|
component={EchoStory}
|
|
130
137
|
createSpace
|
|
131
|
-
|
|
138
|
+
onCreateSpace={async ({ space }) => {
|
|
132
139
|
space.db.add(
|
|
133
140
|
Obj.make(Type.Expando, {
|
|
134
141
|
type: 'test',
|