@dxos/react-ui-editor 0.9.1-main.c7dcc2e112 → 0.10.0
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/index.mjs +32 -42
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +32 -42
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Editor/Editor.d.ts +1 -1
- package/dist/types/src/components/Editor/Editor.d.ts.map +1 -1
- package/dist/types/src/components/Editor/Editor.stories.d.ts.map +1 -1
- package/dist/types/src/components/EditorMenuProvider/menu-presets.d.ts.map +1 -1
- package/dist/types/src/components/EditorPreviewProvider/EditorPreviewProvider.d.ts +4 -2
- package/dist/types/src/components/EditorPreviewProvider/EditorPreviewProvider.d.ts.map +1 -1
- package/dist/types/src/extensions/Assistant.stories.d.ts +2 -2
- package/dist/types/src/extensions/Assistant.stories.d.ts.map +1 -1
- package/dist/types/src/hooks/useBasicMarkdownExtensions.d.ts +3 -1
- package/dist/types/src/hooks/useBasicMarkdownExtensions.d.ts.map +1 -1
- package/dist/types/src/stories/EditorToolbar.stories.d.ts +2 -2
- package/dist/types/src/stories/EditorToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Outliner.stories.d.ts +2 -2
- package/dist/types/src/stories/Outliner.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Popover.stories.d.ts +2 -2
- package/dist/types/src/stories/Popover.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Widgets.stories.d.ts +25 -0
- package/dist/types/src/stories/Widgets.stories.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +53 -51
- package/src/components/Editor/Editor.stories.tsx +3 -2
- package/src/components/Editor/Editor.tsx +2 -2
- package/src/components/EditorMenuProvider/menu-presets.ts +29 -23
- package/src/components/EditorPreviewProvider/EditorPreviewProvider.tsx +4 -3
- package/src/extensions/Assistant.stories.tsx +4 -4
- package/src/hooks/useBasicMarkdownExtensions.ts +5 -2
- package/src/stories/Automerge.stories.tsx +8 -8
- package/src/stories/EditorToolbar.stories.tsx +2 -2
- package/src/stories/Outliner.stories.tsx +2 -2
- package/src/stories/Popover.stories.tsx +3 -3
- package/src/stories/Widgets.stories.tsx +241 -0
- package/src/stories/components/util.tsx +1 -1
- package/dist/types/src/stories/Preview.stories.d.ts +0 -26
- package/dist/types/src/stories/Preview.stories.d.ts.map +0 -1
- package/dist/types/src/stories/Tags.stories.d.ts +0 -16
- package/dist/types/src/stories/Tags.stories.d.ts.map +0 -1
- package/src/stories/Preview.stories.tsx +0 -253
- package/src/stories/Tags.stories.tsx +0 -104
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-editor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Text editor components.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"src"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@automerge/automerge": "3.3.0-fragments.
|
|
38
|
+
"@automerge/automerge": "3.3.0-fragments.2",
|
|
39
39
|
"@codemirror/autocomplete": "^6.20.2",
|
|
40
40
|
"@codemirror/commands": "^6.10.3",
|
|
41
41
|
"@codemirror/lang-html": "^6.4.11",
|
|
@@ -69,77 +69,79 @@
|
|
|
69
69
|
"lodash.merge": "^4.6.2",
|
|
70
70
|
"lodash.sortby": "^4.7.0",
|
|
71
71
|
"style-mod": "^4.1.0",
|
|
72
|
-
"@dxos/app-graph": "0.
|
|
73
|
-
"@dxos/
|
|
74
|
-
"@dxos/
|
|
75
|
-
"@dxos/
|
|
76
|
-
"@dxos/
|
|
77
|
-
"@dxos/echo-client": "0.
|
|
78
|
-
"@dxos/
|
|
79
|
-
"@dxos/echo": "0.
|
|
80
|
-
"@dxos/
|
|
81
|
-
"@dxos/effect": "0.
|
|
82
|
-
"@dxos/log": "0.
|
|
83
|
-
"@dxos/
|
|
84
|
-
"@dxos/
|
|
85
|
-
"@dxos/
|
|
86
|
-
"@dxos/react-
|
|
87
|
-
"@dxos/
|
|
88
|
-
"@dxos/
|
|
89
|
-
"@dxos/ui-
|
|
90
|
-
"@dxos/ui
|
|
91
|
-
"@dxos/
|
|
72
|
+
"@dxos/app-graph": "0.10.0",
|
|
73
|
+
"@dxos/async": "0.10.0",
|
|
74
|
+
"@dxos/context": "0.10.0",
|
|
75
|
+
"@dxos/debug": "0.10.0",
|
|
76
|
+
"@dxos/echo": "0.10.0",
|
|
77
|
+
"@dxos/echo-client": "0.10.0",
|
|
78
|
+
"@dxos/client": "0.10.0",
|
|
79
|
+
"@dxos/echo-doc": "0.10.0",
|
|
80
|
+
"@dxos/invariant": "0.10.0",
|
|
81
|
+
"@dxos/effect": "0.10.0",
|
|
82
|
+
"@dxos/log": "0.10.0",
|
|
83
|
+
"@dxos/lit-ui": "0.10.0",
|
|
84
|
+
"@dxos/keys": "0.10.0",
|
|
85
|
+
"@dxos/protocols": "0.10.0",
|
|
86
|
+
"@dxos/react-hooks": "0.10.0",
|
|
87
|
+
"@dxos/display-name": "0.10.0",
|
|
88
|
+
"@dxos/react-ui-menu": "0.10.0",
|
|
89
|
+
"@dxos/react-ui-mosaic": "0.10.0",
|
|
90
|
+
"@dxos/ui": "0.10.0",
|
|
91
|
+
"@dxos/ui-editor": "0.10.0",
|
|
92
|
+
"@dxos/util": "0.10.0",
|
|
93
|
+
"@dxos/ui-theme": "0.10.0"
|
|
92
94
|
},
|
|
93
95
|
"devDependencies": {
|
|
94
|
-
"@automerge/automerge": "3.3.0-fragments.
|
|
95
|
-
"@automerge/automerge-repo": "2.6.0-subduction.
|
|
96
|
-
"@automerge/automerge-repo-network-broadcastchannel": "2.6.0-subduction.
|
|
96
|
+
"@automerge/automerge": "3.3.0-fragments.2",
|
|
97
|
+
"@automerge/automerge-repo": "2.6.0-subduction.37",
|
|
98
|
+
"@automerge/automerge-repo-network-broadcastchannel": "2.6.0-subduction.37",
|
|
97
99
|
"@effect-atom/atom-react": "^0.5.0",
|
|
98
100
|
"@effect/ai": "0.36.0",
|
|
99
|
-
"@effect/platform": "0.96.
|
|
101
|
+
"@effect/platform": "0.96.2",
|
|
100
102
|
"@types/chai": "^4.2.15",
|
|
101
103
|
"@types/chai-dom": "^1.11.0",
|
|
102
104
|
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
103
105
|
"@types/lodash.merge": "^4.6.6",
|
|
104
106
|
"@types/lodash.sortby": "^4.7.7",
|
|
105
|
-
"@types/react": "~19.2.
|
|
107
|
+
"@types/react": "~19.2.17",
|
|
106
108
|
"@types/react-dom": "~19.2.3",
|
|
107
109
|
"@types/react-test-renderer": "^17.0.2",
|
|
108
110
|
"chai": "^4.4.1",
|
|
109
111
|
"chai-dom": "^1.11.0",
|
|
110
|
-
"effect": "3.21.
|
|
112
|
+
"effect": "3.21.4",
|
|
111
113
|
"happy-dom": "^20.0.0",
|
|
112
114
|
"jsdom": "^29.1.1",
|
|
113
115
|
"mocha": "^10.6.0",
|
|
114
|
-
"react": "~19.2.
|
|
115
|
-
"react-dom": "~19.2.
|
|
116
|
-
"react-test-renderer": "~19.2.
|
|
116
|
+
"react": "~19.2.7",
|
|
117
|
+
"react-dom": "~19.2.7",
|
|
118
|
+
"react-test-renderer": "~19.2.7",
|
|
117
119
|
"vite": "^8.0.16",
|
|
118
120
|
"vite-plugin-top-level-await": "^1.6.0",
|
|
119
121
|
"vite-plugin-wasm": "^3.6.0",
|
|
120
|
-
"@dxos/ai": "0.
|
|
121
|
-
"@dxos/config": "0.
|
|
122
|
-
"@dxos/keyboard": "0.
|
|
123
|
-
"@dxos/echo": "0.
|
|
124
|
-
"@dxos/random": "0.
|
|
125
|
-
"@dxos/react-client": "0.
|
|
126
|
-
"@dxos/react-ui": "0.
|
|
127
|
-
"@dxos/react-ui
|
|
128
|
-
"@dxos/
|
|
129
|
-
"@dxos/
|
|
130
|
-
"@dxos/storybook-utils": "0.
|
|
131
|
-
"@dxos/ui-theme": "0.
|
|
132
|
-
"@dxos/ui-types": "0.
|
|
122
|
+
"@dxos/ai": "0.10.0",
|
|
123
|
+
"@dxos/config": "0.10.0",
|
|
124
|
+
"@dxos/keyboard": "0.10.0",
|
|
125
|
+
"@dxos/echo": "0.10.0",
|
|
126
|
+
"@dxos/random": "0.10.0",
|
|
127
|
+
"@dxos/react-client": "0.10.0",
|
|
128
|
+
"@dxos/react-ui-attention": "0.10.0",
|
|
129
|
+
"@dxos/react-ui": "0.10.0",
|
|
130
|
+
"@dxos/react-ui-syntax-highlighter": "0.10.0",
|
|
131
|
+
"@dxos/schema": "0.10.0",
|
|
132
|
+
"@dxos/storybook-utils": "0.10.0",
|
|
133
|
+
"@dxos/ui-theme": "0.10.0",
|
|
134
|
+
"@dxos/ui-types": "0.10.0"
|
|
133
135
|
},
|
|
134
136
|
"peerDependencies": {
|
|
135
137
|
"@effect-atom/atom-react": "^0.5.0",
|
|
136
|
-
"@effect/platform": "0.96.
|
|
137
|
-
"effect": "3.21.
|
|
138
|
-
"react": "~19.2.
|
|
139
|
-
"react-dom": "~19.2.
|
|
140
|
-
"@dxos/react-client": "0.
|
|
141
|
-
"@dxos/ui-theme": "0.
|
|
142
|
-
"@dxos/react-ui": "0.
|
|
138
|
+
"@effect/platform": "0.96.2",
|
|
139
|
+
"effect": "3.21.4",
|
|
140
|
+
"react": "~19.2.7",
|
|
141
|
+
"react-dom": "~19.2.7",
|
|
142
|
+
"@dxos/react-client": "0.10.0",
|
|
143
|
+
"@dxos/ui-theme": "0.10.0",
|
|
144
|
+
"@dxos/react-ui": "0.10.0"
|
|
143
145
|
},
|
|
144
146
|
"publishConfig": {
|
|
145
147
|
"access": "public"
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import { type Decorator, type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
import React, { useMemo } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { createObject } from '@dxos/echo-client';
|
|
9
|
+
import { Doc } from '@dxos/echo-doc';
|
|
9
10
|
import { random } from '@dxos/random';
|
|
10
11
|
import { useThemeContext } from '@dxos/react-ui';
|
|
11
12
|
import { withAttention } from '@dxos/react-ui-attention/testing';
|
|
@@ -36,7 +37,7 @@ const withExtensions: Decorator<EditorViewProps> = (Story, { args }) => {
|
|
|
36
37
|
createThemeExtensions({ themeMode }),
|
|
37
38
|
createMarkdownExtensions(),
|
|
38
39
|
decorateMarkdown(),
|
|
39
|
-
automerge(
|
|
40
|
+
automerge(Doc.createAccessor(createObject(Text.make({ content: args.initialValue })), ['content'])),
|
|
40
41
|
],
|
|
41
42
|
[themeMode],
|
|
42
43
|
);
|
|
@@ -176,12 +176,12 @@ export const Editor = {
|
|
|
176
176
|
};
|
|
177
177
|
|
|
178
178
|
export type {
|
|
179
|
+
EditorContentProps,
|
|
179
180
|
EditorController,
|
|
180
181
|
EditorRootProps,
|
|
181
|
-
EditorContentProps,
|
|
182
|
-
EditorViewProps,
|
|
183
182
|
EditorToolbarProps,
|
|
184
183
|
EditorToolbarState,
|
|
184
|
+
EditorViewProps,
|
|
185
185
|
};
|
|
186
186
|
|
|
187
187
|
export { createEditorController };
|
|
@@ -2,11 +2,36 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { type EditorView } from '@codemirror/view';
|
|
6
|
+
|
|
5
7
|
import { insertAtLineStart } from '@dxos/ui-editor';
|
|
6
8
|
|
|
7
9
|
import { type EditorMenuGroup } from './menu';
|
|
8
10
|
import { popoverRangeEffect } from './popover';
|
|
9
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Re-open the popover in link-query ("@") mode at the cursor, seeding the same query shape the user
|
|
14
|
+
* would get by typing the trigger manually: a single "@" for an inline link, "@@" for a block embed.
|
|
15
|
+
* The consumer's `@` handler (e.g. plugin-markdown's link query) renders the object picker and, on
|
|
16
|
+
* selection, replaces this range with the corresponding markdown link.
|
|
17
|
+
*
|
|
18
|
+
* Deferred to the next frame: selecting a slash-menu item deletes the "/" range, which closes the
|
|
19
|
+
* popover; opening synchronously races that close (`onActivate` reads a stale open state) and the
|
|
20
|
+
* picker never appears.
|
|
21
|
+
*/
|
|
22
|
+
const openLinkQuery = (view: EditorView, insert: '@' | '@@'): void => {
|
|
23
|
+
requestAnimationFrame(() => {
|
|
24
|
+
const { head } = view.state.selection.main;
|
|
25
|
+
const to = head + insert.length;
|
|
26
|
+
view.dispatch({
|
|
27
|
+
changes: { from: head, insert },
|
|
28
|
+
selection: { anchor: to, head: to },
|
|
29
|
+
// The popover trigger is the single "@"; a second "@" lives in the query range and switches to block mode.
|
|
30
|
+
effects: popoverRangeEffect.of({ trigger: '@', range: { from: head, to } }),
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
10
35
|
export const formattingCommands: EditorMenuGroup = {
|
|
11
36
|
id: 'markdown',
|
|
12
37
|
label: 'Markdown',
|
|
@@ -94,32 +119,13 @@ export const linkSlashCommands: EditorMenuGroup = {
|
|
|
94
119
|
id: 'inline-link',
|
|
95
120
|
label: 'Inline link',
|
|
96
121
|
icon: 'ph--link--regular',
|
|
97
|
-
onSelect: ({ view
|
|
98
|
-
view.dispatch({
|
|
99
|
-
changes: { from: head, insert: '@' },
|
|
100
|
-
selection: { anchor: head + 1, head: head + 1 },
|
|
101
|
-
effects: popoverRangeEffect.of({
|
|
102
|
-
trigger: '@',
|
|
103
|
-
range: { from: head, to: head + 1 },
|
|
104
|
-
}),
|
|
105
|
-
});
|
|
106
|
-
},
|
|
122
|
+
onSelect: ({ view }) => openLinkQuery(view, '@'),
|
|
107
123
|
},
|
|
108
124
|
{
|
|
109
|
-
id: '
|
|
110
|
-
label: '
|
|
125
|
+
id: 'inline-object',
|
|
126
|
+
label: 'Inline object',
|
|
111
127
|
icon: 'ph--lego--regular',
|
|
112
|
-
onSelect: ({ view
|
|
113
|
-
// Seed the same query shape as typing "@@" manually.
|
|
114
|
-
view.dispatch({
|
|
115
|
-
changes: { from: head, insert: '@@' },
|
|
116
|
-
selection: { anchor: head + 2, head: head + 2 },
|
|
117
|
-
effects: popoverRangeEffect.of({
|
|
118
|
-
trigger: '@',
|
|
119
|
-
range: { from: head, to: head + 2 },
|
|
120
|
-
}),
|
|
121
|
-
});
|
|
122
|
-
},
|
|
128
|
+
onSelect: ({ view }) => openLinkQuery(view, '@@'),
|
|
123
129
|
},
|
|
124
130
|
],
|
|
125
131
|
};
|
|
@@ -7,7 +7,7 @@ import React, { type PropsWithChildren, type RefObject, useCallback, useEffect,
|
|
|
7
7
|
|
|
8
8
|
import { addEventListener } from '@dxos/async';
|
|
9
9
|
import { DX_ANCHOR_ACTIVATE, type DxAnchorActivate, Popover } from '@dxos/react-ui';
|
|
10
|
-
import { type PreviewLinkRef, type PreviewLinkTarget } from '@dxos/ui-
|
|
10
|
+
import { type PreviewLinkRef, type PreviewLinkTarget } from '@dxos/ui-types';
|
|
11
11
|
|
|
12
12
|
type EditorPreviewPopoverValue = Partial<{
|
|
13
13
|
link: PreviewLinkRef;
|
|
@@ -22,9 +22,10 @@ export type EditorPreviewProviderProps = PropsWithChildren<{
|
|
|
22
22
|
}>;
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* Standalone anchor-preview popover for use outside Composer (storybook, tests).
|
|
26
|
+
* In Composer, PreviewPlugin listens on window for DX_ANCHOR_ACTIVATE events and
|
|
27
|
+
* dispatches LayoutOperation.UpdatePopover instead; this provider is not needed there.
|
|
26
28
|
*/
|
|
27
|
-
// TOOD(burdon): Reconcile with PreviewPlugin.
|
|
28
29
|
export const EditorPreviewProvider = ({ children, onLookup }: EditorPreviewProviderProps) => {
|
|
29
30
|
const triggerRef = useRef<HTMLElement | null>(null);
|
|
30
31
|
const [value, setValue] = useState<EditorPreviewPopoverValue>({});
|
|
@@ -19,7 +19,7 @@ import { trim } from '@dxos/util';
|
|
|
19
19
|
import { translations } from '#translations';
|
|
20
20
|
|
|
21
21
|
import { Editor, type EditorViewProps } from '../components';
|
|
22
|
-
import {
|
|
22
|
+
import { type AssistantOptions, assistant } from './assistant-extension';
|
|
23
23
|
|
|
24
24
|
// TODO(burdon): Factor out.
|
|
25
25
|
const useTestGenerate = () => {
|
|
@@ -27,7 +27,7 @@ const useTestGenerate = () => {
|
|
|
27
27
|
useEffect(() => {
|
|
28
28
|
let disposed = false;
|
|
29
29
|
const rt = ManagedRuntime.make(
|
|
30
|
-
AiService.model('
|
|
30
|
+
AiService.model('com.anthropic.model.claude-haiku-4-5.default').pipe(
|
|
31
31
|
Layer.provide(AiServiceTestingPreset('edge-remote')),
|
|
32
32
|
Layer.orDie,
|
|
33
33
|
),
|
|
@@ -56,9 +56,9 @@ const useTestGenerate = () => {
|
|
|
56
56
|
return generate;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
type
|
|
59
|
+
type StoryArgs = Pick<EditorViewProps, 'value'>;
|
|
60
60
|
|
|
61
|
-
const DefaultStory = (props:
|
|
61
|
+
const DefaultStory = (props: StoryArgs) => {
|
|
62
62
|
const { themeMode } = useThemeContext();
|
|
63
63
|
const generate = useTestGenerate();
|
|
64
64
|
const extensions = useMemo(
|
|
@@ -18,6 +18,8 @@ export type UseBasicMarkdownExtensionsOptions = {
|
|
|
18
18
|
placeholder?: string;
|
|
19
19
|
/** Enables markdown visual decorations. Pass `false` to disable. Defaults to `true`. */
|
|
20
20
|
decorate?: boolean;
|
|
21
|
+
/** Renders the editor read-only (selectable but not editable). Defaults to `false`. */
|
|
22
|
+
readonly?: boolean;
|
|
21
23
|
/**
|
|
22
24
|
* Extra extensions appended to the returned array.
|
|
23
25
|
* Callers must memoize this array — it is used as a dependency of {@link useMemo}.
|
|
@@ -39,17 +41,18 @@ export type UseBasicMarkdownExtensionsOptions = {
|
|
|
39
41
|
export const useBasicMarkdownExtensions = ({
|
|
40
42
|
placeholder,
|
|
41
43
|
decorate = true,
|
|
44
|
+
readonly = false,
|
|
42
45
|
extensions,
|
|
43
46
|
}: UseBasicMarkdownExtensionsOptions = {}): Extension[] => {
|
|
44
47
|
const { themeMode } = useThemeContext();
|
|
45
48
|
return useMemo(
|
|
46
49
|
() => [
|
|
47
|
-
createBasicExtensions({ placeholder }),
|
|
50
|
+
createBasicExtensions({ placeholder, readOnly: readonly }),
|
|
48
51
|
createThemeExtensions({ syntaxHighlighting: true, themeMode }),
|
|
49
52
|
createMarkdownExtensions(),
|
|
50
53
|
...(decorate ? [decorateMarkdown()] : []),
|
|
51
54
|
...(extensions ?? []),
|
|
52
55
|
],
|
|
53
|
-
[placeholder, themeMode, decorate, extensions],
|
|
56
|
+
[placeholder, themeMode, decorate, readonly, extensions],
|
|
54
57
|
);
|
|
55
58
|
};
|
|
@@ -8,7 +8,7 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
|
8
8
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
9
9
|
|
|
10
10
|
import { Obj, Query, Ref } from '@dxos/echo';
|
|
11
|
-
import {
|
|
11
|
+
import { Doc } from '@dxos/echo-doc';
|
|
12
12
|
import { TestSchema } from '@dxos/echo/testing';
|
|
13
13
|
import { log } from '@dxos/log';
|
|
14
14
|
import { type Messenger } from '@dxos/protocols';
|
|
@@ -16,7 +16,7 @@ import { useQuery, useSpace } from '@dxos/react-client/echo';
|
|
|
16
16
|
import { type Identity, useIdentity } from '@dxos/react-client/halo';
|
|
17
17
|
import { useClientStory, withMultiClientProvider } from '@dxos/react-client/testing';
|
|
18
18
|
import { Button, useThemeContext } from '@dxos/react-ui';
|
|
19
|
-
import { withLayout, withTheme
|
|
19
|
+
import { Loading, withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
20
20
|
import { createBasicExtensions, createDataExtensions, createThemeExtensions } from '@dxos/ui-editor';
|
|
21
21
|
|
|
22
22
|
import { translations } from '#translations';
|
|
@@ -30,7 +30,7 @@ type TestObject = {
|
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
type EditorProps = {
|
|
33
|
-
source:
|
|
33
|
+
source: Doc.Accessor;
|
|
34
34
|
messenger?: Messenger;
|
|
35
35
|
identity?: Identity;
|
|
36
36
|
autoFocus?: boolean;
|
|
@@ -41,7 +41,7 @@ const Editor = ({ source, messenger, identity, autoFocus }: EditorProps) => {
|
|
|
41
41
|
const { parentRef } = useTextEditor(
|
|
42
42
|
() => ({
|
|
43
43
|
autoFocus,
|
|
44
|
-
initialValue:
|
|
44
|
+
initialValue: Doc.getValue(source),
|
|
45
45
|
extensions: [
|
|
46
46
|
createBasicExtensions({ placeholder: 'Type here...', search: true }),
|
|
47
47
|
createThemeExtensions({ themeMode, slots: { scroller: { className: 'p-2' } } }),
|
|
@@ -55,8 +55,8 @@ const Editor = ({ source, messenger, identity, autoFocus }: EditorProps) => {
|
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
const DefaultStory = () => {
|
|
58
|
-
const [object1, setObject1] = useState<
|
|
59
|
-
const [object2, setObject2] = useState<
|
|
58
|
+
const [object1, setObject1] = useState<Doc.Accessor<TestObject>>();
|
|
59
|
+
const [object2, setObject2] = useState<Doc.Accessor<TestObject>>();
|
|
60
60
|
|
|
61
61
|
useEffect(() => {
|
|
62
62
|
queueMicrotask(async () => {
|
|
@@ -97,7 +97,7 @@ const EchoStory = () => {
|
|
|
97
97
|
const space = useSpace(spaceId);
|
|
98
98
|
const objects = useQuery(space?.db, Query.type(TestSchema.Expando, { type: 'test' }));
|
|
99
99
|
|
|
100
|
-
const [source, setSource] = useState<
|
|
100
|
+
const [source, setSource] = useState<Doc.Accessor>();
|
|
101
101
|
const init = useCallback(() => {
|
|
102
102
|
const content = objects[0]?.content.target;
|
|
103
103
|
if (!content) {
|
|
@@ -108,7 +108,7 @@ const EchoStory = () => {
|
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
setSource(
|
|
111
|
+
setSource(Doc.createAccessor(content, ['content']));
|
|
112
112
|
}, [objects]);
|
|
113
113
|
|
|
114
114
|
useEffect(() => {
|
|
@@ -23,9 +23,9 @@ import { translations } from '#translations';
|
|
|
23
23
|
import { Editor } from '../components';
|
|
24
24
|
import { type UseTextEditorProps } from '../hooks';
|
|
25
25
|
|
|
26
|
-
type
|
|
26
|
+
type StoryArgs = { placeholder?: string; viewMode?: EditorViewMode } & UseTextEditorProps;
|
|
27
27
|
|
|
28
|
-
const DefaultStory = ({ autoFocus, initialValue, placeholder, viewMode = 'source' }:
|
|
28
|
+
const DefaultStory = ({ autoFocus, initialValue, placeholder, viewMode = 'source' }: StoryArgs) => {
|
|
29
29
|
const { themeMode } = useThemeContext();
|
|
30
30
|
|
|
31
31
|
const extensions = useMemo(
|
|
@@ -12,11 +12,11 @@ import { deleteItem, hashtag, join, listItemToString, outliner, treeFacet } from
|
|
|
12
12
|
import { type EditorController, type EditorMenuGroup, EditorMenuProvider } from '../components';
|
|
13
13
|
import { EditorStory } from './components';
|
|
14
14
|
|
|
15
|
-
type
|
|
15
|
+
type StoryArgs = {
|
|
16
16
|
text?: string;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
const DefaultStory = ({ text }:
|
|
19
|
+
const DefaultStory = ({ text }: StoryArgs) => {
|
|
20
20
|
const [controller, setController] = useState<EditorController | null>(null);
|
|
21
21
|
|
|
22
22
|
const extensions = useMemo(() => [outliner(), hashtag()], []);
|
|
@@ -43,9 +43,9 @@ const placeholder = (trigger: string[]) => {
|
|
|
43
43
|
return Domino.of('div').append(pressEl, ...triggerEls, forCommandsEl).root;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
type
|
|
46
|
+
type StoryArgs = Omit<UseEditorMenuProps, 'viewRef'> & { text: string };
|
|
47
47
|
|
|
48
|
-
const DefaultStory = ({ text, ...props }:
|
|
48
|
+
const DefaultStory = ({ text, ...props }: StoryArgs) => {
|
|
49
49
|
const [controller, setController] = useState<EditorController | null>(null);
|
|
50
50
|
const { groupsRef, extension, ...menuProps } = useEditorMenu(props);
|
|
51
51
|
const getView = useCallback(() => controller?.view ?? null, [controller]);
|
|
@@ -57,7 +57,7 @@ const DefaultStory = ({ text, ...props }: DefaultStoryProps) => {
|
|
|
57
57
|
);
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
const LinkStory = (args:
|
|
60
|
+
const LinkStory = (args: StoryArgs) => {
|
|
61
61
|
const { space } = useClientStory();
|
|
62
62
|
|
|
63
63
|
const getMenu = useCallback<NonNullable<UseEditorMenuProps['getMenu']>>(
|