@dxos/react-ui-editor 0.8.2-main.12df754 → 0.8.2-main.30e4dbb
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 +1178 -1110
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs.map +2 -2
- package/dist/lib/node/index.cjs +1386 -1319
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs.map +2 -2
- package/dist/lib/node-esm/index.mjs +1178 -1110
- 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.map +2 -2
- package/dist/types/src/components/EditorToolbar/EditorToolbar.d.ts +1 -1
- package/dist/types/src/components/EditorToolbar/EditorToolbar.d.ts.map +1 -1
- package/dist/types/src/{stories/InputMode.stories.d.ts → components/EditorToolbar/EditorToolbar.stories.d.ts} +3 -7
- package/dist/types/src/components/EditorToolbar/EditorToolbar.stories.d.ts.map +1 -0
- package/dist/types/src/components/EditorToolbar/blocks.d.ts +4 -3
- package/dist/types/src/components/EditorToolbar/blocks.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/comment.d.ts +4 -3
- package/dist/types/src/components/EditorToolbar/comment.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/formatting.d.ts +4 -3
- package/dist/types/src/components/EditorToolbar/formatting.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/headings.d.ts +4 -3
- package/dist/types/src/components/EditorToolbar/headings.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/image.d.ts +16 -0
- package/dist/types/src/components/EditorToolbar/image.d.ts.map +1 -0
- package/dist/types/src/components/EditorToolbar/lists.d.ts +4 -3
- package/dist/types/src/components/EditorToolbar/lists.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/search.d.ts +17 -0
- package/dist/types/src/components/EditorToolbar/search.d.ts.map +1 -0
- package/dist/types/src/components/EditorToolbar/util.d.ts +11 -17
- package/dist/types/src/components/EditorToolbar/util.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/view-mode.d.ts +4 -3
- package/dist/types/src/components/EditorToolbar/view-mode.d.ts.map +1 -1
- package/dist/types/src/defaults.d.ts.map +1 -1
- package/dist/types/src/extensions/annotations.d.ts.map +1 -1
- 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/cursor.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/update-automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/update-codemirror.d.ts.map +1 -1
- package/dist/types/src/extensions/awareness/awareness.d.ts.map +1 -1
- package/dist/types/src/extensions/blast.d.ts.map +1 -1
- package/dist/types/src/extensions/command/command.d.ts.map +1 -1
- package/dist/types/src/extensions/command/hint.d.ts.map +1 -1
- package/dist/types/src/extensions/command/menu.d.ts.map +1 -1
- package/dist/types/src/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/extensions/debug.d.ts.map +1 -1
- package/dist/types/src/extensions/dnd.d.ts.map +1 -1
- package/dist/types/src/extensions/factories.d.ts.map +1 -1
- package/dist/types/src/extensions/folding.d.ts.map +1 -1
- package/dist/types/src/extensions/listener.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/changes.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/debug.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/decorate.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/formatting.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/markdown/table.d.ts.map +1 -1
- package/dist/types/src/extensions/mention.d.ts.map +1 -1
- package/dist/types/src/extensions/modes.d.ts +5 -5
- package/dist/types/src/extensions/modes.d.ts.map +1 -1
- package/dist/types/src/extensions/preview/preview.d.ts.map +1 -1
- package/dist/types/src/extensions/selection.d.ts.map +1 -1
- package/dist/types/src/extensions/typewriter.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +0 -1
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
- package/dist/types/src/stories/story-utils.d.ts.map +1 -1
- package/dist/types/src/testing/RefPopover.d.ts.map +1 -1
- package/dist/types/src/util/cursor.d.ts.map +1 -1
- package/dist/types/src/util/debug.d.ts.map +1 -1
- package/dist/types/src/util/dom.d.ts.map +1 -1
- package/dist/types/src/util/facet.d.ts.map +1 -1
- package/dist/types/src/util/react.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +30 -28
- package/src/components/EditorToolbar/EditorToolbar.stories.tsx +90 -0
- package/src/components/EditorToolbar/EditorToolbar.tsx +30 -31
- package/src/components/EditorToolbar/blocks.ts +27 -6
- package/src/components/EditorToolbar/comment.ts +11 -4
- package/src/components/EditorToolbar/formatting.ts +34 -7
- package/src/components/EditorToolbar/headings.ts +9 -8
- package/src/components/EditorToolbar/image.ts +16 -0
- package/src/components/EditorToolbar/lists.ts +26 -7
- package/src/components/EditorToolbar/search.ts +19 -0
- package/src/components/EditorToolbar/util.ts +14 -14
- package/src/components/EditorToolbar/view-mode.ts +9 -8
- package/src/extensions/modes.ts +5 -6
- package/src/extensions/preview/preview.ts +1 -1
- package/src/hooks/index.ts +0 -1
- package/src/testing/RefPopover.tsx +4 -4
- package/dist/types/src/hooks/useActionHandler.d.ts +0 -4
- package/dist/types/src/hooks/useActionHandler.d.ts.map +0 -1
- package/dist/types/src/stories/InputMode.stories.d.ts.map +0 -1
- package/src/hooks/useActionHandler.ts +0 -12
- package/src/stories/InputMode.stories.tsx +0 -124
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dxos/react-ui-editor",
|
3
|
-
"version": "0.8.2-main.
|
3
|
+
"version": "0.8.2-main.30e4dbb",
|
4
4
|
"description": "Document editing experience within a DXOS shell.",
|
5
5
|
"homepage": "https://dxos.org",
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
@@ -50,27 +50,28 @@
|
|
50
50
|
"@replit/codemirror-vim": "^6.2.1",
|
51
51
|
"@replit/codemirror-vscode-keymap": "^6.0.2",
|
52
52
|
"codemirror": "^6.0.1",
|
53
|
+
"effect": "3.14.21",
|
53
54
|
"lib0": "^0.2.65",
|
54
55
|
"lodash.defaultsdeep": "^4.6.1",
|
55
56
|
"lodash.get": "^4.4.2",
|
56
57
|
"lodash.merge": "^4.6.2",
|
57
58
|
"lodash.sortby": "^4.7.0",
|
58
59
|
"style-mod": "^4.1.0",
|
59
|
-
"@dxos/app-graph": "0.8.2-main.
|
60
|
-
"@dxos/async": "0.8.2-main.
|
61
|
-
"@dxos/
|
62
|
-
"@dxos/
|
63
|
-
"@dxos/
|
64
|
-
"@dxos/
|
65
|
-
"@dxos/
|
66
|
-
"@dxos/invariant": "0.8.2-main.
|
67
|
-
"@dxos/
|
68
|
-
"@dxos/
|
69
|
-
"@dxos/
|
70
|
-
"@dxos/protocols": "0.8.2-main.
|
71
|
-
"@dxos/react-hooks": "0.8.2-main.
|
72
|
-
"@dxos/react-ui-menu": "0.8.2-main.
|
73
|
-
"@dxos/util": "0.8.2-main.
|
60
|
+
"@dxos/app-graph": "0.8.2-main.30e4dbb",
|
61
|
+
"@dxos/async": "0.8.2-main.30e4dbb",
|
62
|
+
"@dxos/automerge": "0.8.2-main.30e4dbb",
|
63
|
+
"@dxos/context": "0.8.2-main.30e4dbb",
|
64
|
+
"@dxos/debug": "0.8.2-main.30e4dbb",
|
65
|
+
"@dxos/display-name": "0.8.2-main.30e4dbb",
|
66
|
+
"@dxos/echo-schema": "0.8.2-main.30e4dbb",
|
67
|
+
"@dxos/invariant": "0.8.2-main.30e4dbb",
|
68
|
+
"@dxos/lit-ui": "0.8.2-main.30e4dbb",
|
69
|
+
"@dxos/live-object": "0.8.2-main.30e4dbb",
|
70
|
+
"@dxos/log": "0.8.2-main.30e4dbb",
|
71
|
+
"@dxos/protocols": "0.8.2-main.30e4dbb",
|
72
|
+
"@dxos/react-hooks": "0.8.2-main.30e4dbb",
|
73
|
+
"@dxos/react-ui-menu": "0.8.2-main.30e4dbb",
|
74
|
+
"@dxos/util": "0.8.2-main.30e4dbb"
|
74
75
|
},
|
75
76
|
"devDependencies": {
|
76
77
|
"@phosphor-icons/react": "^2.1.5",
|
@@ -94,23 +95,24 @@
|
|
94
95
|
"vite": "5.4.7",
|
95
96
|
"vite-plugin-top-level-await": "^1.4.1",
|
96
97
|
"vite-plugin-wasm": "^3.3.0",
|
97
|
-
"@dxos/automerge": "0.8.2-main.
|
98
|
-
"@dxos/config": "0.8.2-main.
|
99
|
-
"@dxos/echo-signals": "0.8.2-main.
|
100
|
-
"@dxos/keyboard": "0.8.2-main.
|
101
|
-
"@dxos/
|
102
|
-
"@dxos/react-
|
103
|
-
"@dxos/
|
104
|
-
"@dxos/
|
105
|
-
"@dxos/
|
98
|
+
"@dxos/automerge": "0.8.2-main.30e4dbb",
|
99
|
+
"@dxos/config": "0.8.2-main.30e4dbb",
|
100
|
+
"@dxos/echo-signals": "0.8.2-main.30e4dbb",
|
101
|
+
"@dxos/keyboard": "0.8.2-main.30e4dbb",
|
102
|
+
"@dxos/random": "0.8.2-main.30e4dbb",
|
103
|
+
"@dxos/react-client": "0.8.2-main.30e4dbb",
|
104
|
+
"@dxos/react-ui": "0.8.2-main.30e4dbb",
|
105
|
+
"@dxos/react-ui-theme": "0.8.2-main.30e4dbb",
|
106
|
+
"@dxos/storybook-utils": "0.8.2-main.30e4dbb"
|
106
107
|
},
|
107
108
|
"peerDependencies": {
|
108
109
|
"@phosphor-icons/react": "^2.1.5",
|
110
|
+
"effect": "^3.13.3",
|
109
111
|
"react": "~18.2.0",
|
110
112
|
"react-dom": "~18.2.0",
|
111
|
-
"@dxos/react-client": "0.8.2-main.
|
112
|
-
"@dxos/react-ui": "0.8.2-main.
|
113
|
-
"@dxos/react-ui-theme": "0.8.2-main.
|
113
|
+
"@dxos/react-client": "0.8.2-main.30e4dbb",
|
114
|
+
"@dxos/react-ui": "0.8.2-main.30e4dbb",
|
115
|
+
"@dxos/react-ui-theme": "0.8.2-main.30e4dbb"
|
114
116
|
},
|
115
117
|
"publishConfig": {
|
116
118
|
"access": "public"
|
@@ -0,0 +1,90 @@
|
|
1
|
+
//
|
2
|
+
// Copyright 2024 DXOS.org
|
3
|
+
//
|
4
|
+
|
5
|
+
import '@dxos-theme';
|
6
|
+
|
7
|
+
import React, { useCallback, useState } from 'react';
|
8
|
+
|
9
|
+
import { invariant } from '@dxos/invariant';
|
10
|
+
import { useThemeContext } from '@dxos/react-ui';
|
11
|
+
import { attentionSurface, mx } from '@dxos/react-ui-theme';
|
12
|
+
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
13
|
+
|
14
|
+
import { EditorToolbar, useEditorToolbarState } from '..';
|
15
|
+
import {
|
16
|
+
type EditorInputMode,
|
17
|
+
decorateMarkdown,
|
18
|
+
createMarkdownExtensions,
|
19
|
+
formattingKeymap,
|
20
|
+
useFormattingState,
|
21
|
+
createBasicExtensions,
|
22
|
+
createThemeExtensions,
|
23
|
+
InputModeExtensions,
|
24
|
+
type EditorViewMode,
|
25
|
+
} from '../../extensions';
|
26
|
+
import { useTextEditor, type UseTextEditorProps } from '../../hooks';
|
27
|
+
import translations from '../../translations';
|
28
|
+
|
29
|
+
type StoryProps = { placeholder?: string } & UseTextEditorProps;
|
30
|
+
|
31
|
+
const DefaultStory = ({ autoFocus, initialValue, placeholder }: StoryProps) => {
|
32
|
+
const { themeMode } = useThemeContext();
|
33
|
+
const toolbarState = useEditorToolbarState({ viewMode: 'source' });
|
34
|
+
const viewMode = toolbarState.viewMode;
|
35
|
+
const trackFormatting = useFormattingState(toolbarState);
|
36
|
+
// TODO(wittjosiah): Provide way to change the input mode.
|
37
|
+
const [editorInputMode, _setEditorInputMode] = useState<EditorInputMode>('default');
|
38
|
+
const { parentRef, view } = useTextEditor(
|
39
|
+
() => ({
|
40
|
+
autoFocus,
|
41
|
+
initialValue,
|
42
|
+
moveToEndOfLine: true,
|
43
|
+
extensions: [
|
44
|
+
editorInputMode ? InputModeExtensions[editorInputMode] : [],
|
45
|
+
createBasicExtensions({ placeholder, lineWrapping: true, readOnly: viewMode === 'readonly' }),
|
46
|
+
createMarkdownExtensions({ themeMode }),
|
47
|
+
createThemeExtensions({ themeMode, syntaxHighlighting: true }),
|
48
|
+
viewMode === 'source' ? [] : decorateMarkdown(),
|
49
|
+
formattingKeymap(),
|
50
|
+
trackFormatting,
|
51
|
+
],
|
52
|
+
}),
|
53
|
+
[editorInputMode, viewMode, themeMode, placeholder],
|
54
|
+
);
|
55
|
+
|
56
|
+
const getView = useCallback(() => {
|
57
|
+
invariant(view);
|
58
|
+
return view;
|
59
|
+
}, [view]);
|
60
|
+
|
61
|
+
const handleViewModeChange = useCallback((mode: EditorViewMode) => {
|
62
|
+
toolbarState.viewMode = mode;
|
63
|
+
}, []);
|
64
|
+
|
65
|
+
// TODO(marijn): This doesn't update the state on view changes.
|
66
|
+
// Also not sure if view is even guaranteed to exist at this point.
|
67
|
+
return (
|
68
|
+
<div role='none' className={mx('fixed inset-0 flex flex-col')}>
|
69
|
+
{toolbarState && <EditorToolbar state={toolbarState} getView={getView} viewMode={handleViewModeChange} />}
|
70
|
+
<div role='none' className='grow overflow-hidden'>
|
71
|
+
<div className={attentionSurface} ref={parentRef} />
|
72
|
+
</div>
|
73
|
+
</div>
|
74
|
+
);
|
75
|
+
};
|
76
|
+
|
77
|
+
export const Default = {
|
78
|
+
args: {
|
79
|
+
autoFocus: true,
|
80
|
+
placeholder: 'Text...',
|
81
|
+
initialValue: '# Demo\n\nThis is a document.\n\n',
|
82
|
+
},
|
83
|
+
};
|
84
|
+
|
85
|
+
export default {
|
86
|
+
title: 'ui/react-ui-editor/EditorToolbar',
|
87
|
+
render: DefaultStory,
|
88
|
+
decorators: [withTheme, withLayout({ fullscreen: true })],
|
89
|
+
parameters: { translations, layout: 'fullscreen' },
|
90
|
+
};
|
@@ -2,63 +2,60 @@
|
|
2
2
|
// Copyright 2024 DXOS.org
|
3
3
|
//
|
4
4
|
|
5
|
-
import React, { useCallback } from 'react';
|
5
|
+
import React, { memo, useCallback } from 'react';
|
6
6
|
|
7
7
|
import { type NodeArg } from '@dxos/app-graph';
|
8
8
|
import { ElevationProvider } from '@dxos/react-ui';
|
9
|
-
import {
|
10
|
-
type MenuActionHandler,
|
11
|
-
MenuProvider,
|
12
|
-
ToolbarMenu,
|
13
|
-
createGapSeparator,
|
14
|
-
useMenuActions,
|
15
|
-
} from '@dxos/react-ui-menu';
|
9
|
+
import { MenuProvider, ToolbarMenu, createGapSeparator, useMenuActions } from '@dxos/react-ui-menu';
|
16
10
|
import { textBlockWidth } from '@dxos/react-ui-theme';
|
17
11
|
|
18
12
|
import { createBlocks } from './blocks';
|
19
13
|
import { createComment } from './comment';
|
20
14
|
import { createFormatting } from './formatting';
|
21
15
|
import { createHeadings } from './headings';
|
16
|
+
import { createImageUpload } from './image';
|
22
17
|
import { createLists } from './lists';
|
23
|
-
import {
|
24
|
-
|
25
|
-
type EditorToolbarFeatureFlags,
|
26
|
-
type EditorToolbarProps,
|
27
|
-
editorToolbarSearch,
|
28
|
-
} from './util';
|
18
|
+
import { createSearch } from './search';
|
19
|
+
import { type EditorToolbarActionGraphProps, type EditorToolbarFeatureFlags, type EditorToolbarProps } from './util';
|
29
20
|
import { createViewMode } from './view-mode';
|
30
21
|
import { stackItemContentToolbarClassNames } from '../../defaults';
|
31
22
|
|
32
23
|
const createToolbar = ({
|
24
|
+
getView,
|
33
25
|
state,
|
34
26
|
customActions,
|
35
27
|
...features
|
36
|
-
}: EditorToolbarFeatureFlags & Pick<EditorToolbarActionGraphProps, 'state' | 'customActions'>): {
|
28
|
+
}: EditorToolbarFeatureFlags & Pick<EditorToolbarActionGraphProps, 'getView' | 'state' | 'customActions'>): {
|
37
29
|
nodes: NodeArg<any>[];
|
38
30
|
edges: { source: string; target: string }[];
|
39
31
|
} => {
|
40
32
|
const nodes = [];
|
41
33
|
const edges = [];
|
42
34
|
if (features.headings ?? true) {
|
43
|
-
const headings = createHeadings(state);
|
35
|
+
const headings = createHeadings(state, getView);
|
44
36
|
nodes.push(...headings.nodes);
|
45
37
|
edges.push(...headings.edges);
|
46
38
|
}
|
47
39
|
if (features.formatting ?? true) {
|
48
|
-
const formatting = createFormatting(state);
|
40
|
+
const formatting = createFormatting(state, getView);
|
49
41
|
nodes.push(...formatting.nodes);
|
50
42
|
edges.push(...formatting.edges);
|
51
43
|
}
|
52
44
|
if (features.lists ?? true) {
|
53
|
-
const lists = createLists(state);
|
45
|
+
const lists = createLists(state, getView);
|
54
46
|
nodes.push(...lists.nodes);
|
55
47
|
edges.push(...lists.edges);
|
56
48
|
}
|
57
49
|
if (features.blocks ?? true) {
|
58
|
-
const blocks = createBlocks(state);
|
50
|
+
const blocks = createBlocks(state, getView);
|
59
51
|
nodes.push(...blocks.nodes);
|
60
52
|
edges.push(...blocks.edges);
|
61
53
|
}
|
54
|
+
if (features.image) {
|
55
|
+
const image = createImageUpload(features.image);
|
56
|
+
nodes.push(...image.nodes);
|
57
|
+
edges.push(...image.edges);
|
58
|
+
}
|
62
59
|
if (customActions) {
|
63
60
|
const custom = customActions();
|
64
61
|
nodes.push(...custom.nodes);
|
@@ -67,31 +64,33 @@ const createToolbar = ({
|
|
67
64
|
const editorToolbarGap = createGapSeparator();
|
68
65
|
nodes.push(...editorToolbarGap.nodes);
|
69
66
|
edges.push(...editorToolbarGap.edges);
|
70
|
-
if (features.comment
|
71
|
-
const comment = createComment(state);
|
67
|
+
if (features.comment) {
|
68
|
+
const comment = createComment(state, getView);
|
72
69
|
nodes.push(...comment.nodes);
|
73
70
|
edges.push(...comment.edges);
|
74
71
|
}
|
75
72
|
if (features.search ?? true) {
|
76
|
-
|
77
|
-
|
73
|
+
const search = createSearch(getView);
|
74
|
+
nodes.push(...search.nodes);
|
75
|
+
edges.push(...search.edges);
|
78
76
|
}
|
79
|
-
if (features.viewMode
|
80
|
-
const viewMode = createViewMode(state);
|
77
|
+
if (features.viewMode) {
|
78
|
+
const viewMode = createViewMode(state, features.viewMode);
|
81
79
|
nodes.push(...viewMode.nodes);
|
82
80
|
edges.push(...viewMode.edges);
|
83
81
|
}
|
84
82
|
return { nodes, edges };
|
85
83
|
};
|
86
84
|
|
87
|
-
|
85
|
+
// TODO(wittjosiah): Toolbar re-rendering is causing this graph to be recreated and breaking reactivity in some cases.
|
86
|
+
// E.g. for toolbar dropdowns which use active icon, the icon is not updated when the active item changes.
|
87
|
+
// This is currently only happening in the markdown plugin usage and should be reproduced in an editor story.
|
88
|
+
const useEditorToolbarActionGraph = (props: EditorToolbarProps) => {
|
88
89
|
const menuCreator = useCallback(() => createToolbar(props), [props]);
|
89
|
-
|
90
|
-
|
91
|
-
return { resolveGroupItems, onAction: onAction as MenuActionHandler };
|
90
|
+
return useMenuActions(menuCreator);
|
92
91
|
};
|
93
92
|
|
94
|
-
export const EditorToolbar = ({ classNames, attendableId, role, ...props }: EditorToolbarProps) => {
|
93
|
+
export const EditorToolbar = memo(({ classNames, attendableId, role, ...props }: EditorToolbarProps) => {
|
95
94
|
const menuProps = useEditorToolbarActionGraph(props);
|
96
95
|
return (
|
97
96
|
<div role='none' className={stackItemContentToolbarClassNames(role)}>
|
@@ -102,4 +101,4 @@ export const EditorToolbar = ({ classNames, attendableId, role, ...props }: Edit
|
|
102
101
|
</ElevationProvider>
|
103
102
|
</div>
|
104
103
|
);
|
105
|
-
};
|
104
|
+
});
|
@@ -2,11 +2,13 @@
|
|
2
2
|
// Copyright 2025 DXOS.org
|
3
3
|
//
|
4
4
|
|
5
|
+
import { type EditorView } from '@codemirror/view';
|
6
|
+
|
5
7
|
import { type NodeArg } from '@dxos/app-graph';
|
6
8
|
import { type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';
|
7
9
|
|
8
10
|
import { createEditorAction, createEditorActionGroup, type EditorToolbarState } from './util';
|
9
|
-
import {
|
11
|
+
import { removeBlockquote, addBlockquote, removeCodeblock, addCodeblock, insertTable } from '../../extensions';
|
10
12
|
|
11
13
|
const createBlockGroupAction = (value: string) =>
|
12
14
|
createEditorActionGroup('block', {
|
@@ -15,22 +17,41 @@ const createBlockGroupAction = (value: string) =>
|
|
15
17
|
value,
|
16
18
|
} as ToolbarMenuActionGroupProperties);
|
17
19
|
|
18
|
-
const createBlockActions = (value: string, blankLine?: boolean) =>
|
20
|
+
const createBlockActions = (value: string, getView: () => EditorView, blankLine?: boolean) =>
|
19
21
|
Object.entries({
|
20
22
|
blockquote: 'ph--quotes--regular',
|
21
23
|
codeblock: 'ph--code-block--regular',
|
22
24
|
table: 'ph--table--regular',
|
23
25
|
}).map(([type, icon]) => {
|
26
|
+
const checked = type === value;
|
24
27
|
return createEditorAction(
|
25
|
-
|
26
|
-
|
28
|
+
type,
|
29
|
+
() => {
|
30
|
+
const view = getView();
|
31
|
+
if (!view) {
|
32
|
+
return;
|
33
|
+
}
|
34
|
+
|
35
|
+
switch (type) {
|
36
|
+
case 'blockquote':
|
37
|
+
checked ? removeBlockquote(view) : addBlockquote(view);
|
38
|
+
break;
|
39
|
+
case 'codeblock':
|
40
|
+
checked ? removeCodeblock(view) : addCodeblock(view);
|
41
|
+
break;
|
42
|
+
case 'table':
|
43
|
+
insertTable(view);
|
44
|
+
break;
|
45
|
+
}
|
46
|
+
},
|
47
|
+
{ checked, ...(type === 'table' && { disabled: !!blankLine }), icon },
|
27
48
|
);
|
28
49
|
});
|
29
50
|
|
30
|
-
export const createBlocks = (state: EditorToolbarState) => {
|
51
|
+
export const createBlocks = (state: EditorToolbarState, getView: () => EditorView) => {
|
31
52
|
const value = state?.blockQuote ? 'blockquote' : state.blockType ?? '';
|
32
53
|
const blockGroupAction = createBlockGroupAction(value);
|
33
|
-
const blockActions = createBlockActions(value, state.blankLine);
|
54
|
+
const blockActions = createBlockActions(value, getView, state.blankLine);
|
34
55
|
return {
|
35
56
|
nodes: [blockGroupAction as NodeArg<any>, ...blockActions],
|
36
57
|
edges: [
|
@@ -2,9 +2,12 @@
|
|
2
2
|
// Copyright 2025 DXOS.org
|
3
3
|
//
|
4
4
|
|
5
|
+
import { type EditorView } from '@codemirror/view';
|
6
|
+
|
5
7
|
import { type Label } from '@dxos/react-ui';
|
6
8
|
|
7
9
|
import { createEditorAction, type EditorToolbarState } from './util';
|
10
|
+
import { createComment as nativeCreateComment } from '../../extensions';
|
8
11
|
import { translationKey } from '../../translations';
|
9
12
|
|
10
13
|
const commentLabel = (comment?: boolean, selection?: boolean) =>
|
@@ -14,10 +17,14 @@ const commentLabel = (comment?: boolean, selection?: boolean) =>
|
|
14
17
|
? 'select text to comment label'
|
15
18
|
: 'comment label';
|
16
19
|
|
17
|
-
const createCommentAction = (label: Label) =>
|
18
|
-
createEditorAction(
|
20
|
+
const createCommentAction = (label: Label, getView: () => EditorView) =>
|
21
|
+
createEditorAction('comment', () => nativeCreateComment(getView()), {
|
22
|
+
testId: 'editor.toolbar.comment',
|
23
|
+
icon: 'ph--chat-text--regular',
|
24
|
+
label,
|
25
|
+
});
|
19
26
|
|
20
|
-
export const createComment = (state: EditorToolbarState) => ({
|
21
|
-
nodes: [createCommentAction([commentLabel(state.comment, state.selection), { ns: translationKey }])],
|
27
|
+
export const createComment = (state: EditorToolbarState, getView: () => EditorView) => ({
|
28
|
+
nodes: [createCommentAction([commentLabel(state.comment, state.selection), { ns: translationKey }], getView)],
|
22
29
|
edges: [{ source: 'root', target: 'comment' }],
|
23
30
|
});
|
@@ -2,11 +2,13 @@
|
|
2
2
|
// Copyright 2025 DXOS.org
|
3
3
|
//
|
4
4
|
|
5
|
+
import { type EditorView } from '@codemirror/view';
|
6
|
+
|
5
7
|
import { type NodeArg } from '@dxos/app-graph';
|
6
8
|
import { type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';
|
7
9
|
|
8
10
|
import { createEditorAction, createEditorActionGroup, type EditorToolbarState } from './util';
|
9
|
-
import {
|
11
|
+
import { addLink, Inline, removeLink, setStyle, type Formatting } from '../../extensions';
|
10
12
|
|
11
13
|
const formats = {
|
12
14
|
strong: 'ph--text-b--regular',
|
@@ -23,14 +25,39 @@ const createFormattingGroup = (formatting: Formatting) =>
|
|
23
25
|
value: Object.keys(formats).filter((key) => !!formatting[key as keyof Formatting]),
|
24
26
|
} as ToolbarMenuActionGroupProperties);
|
25
27
|
|
26
|
-
const createFormattingActions = (formatting: Formatting) =>
|
27
|
-
Object.entries(formats).map(([type, icon]) =>
|
28
|
-
|
29
|
-
|
28
|
+
const createFormattingActions = (formatting: Formatting, getView: () => EditorView) =>
|
29
|
+
Object.entries(formats).map(([type, icon]) => {
|
30
|
+
const checked = !!formatting[type as keyof Formatting];
|
31
|
+
return createEditorAction(
|
32
|
+
type,
|
33
|
+
() => {
|
34
|
+
const view = getView();
|
35
|
+
if (!view) {
|
36
|
+
return;
|
37
|
+
}
|
38
|
+
|
39
|
+
if (type === 'link') {
|
40
|
+
checked ? removeLink(view) : addLink()(view);
|
41
|
+
return;
|
42
|
+
}
|
43
|
+
|
44
|
+
const inlineType =
|
45
|
+
type === 'strong'
|
46
|
+
? Inline.Strong
|
47
|
+
: type === 'emphasis'
|
48
|
+
? Inline.Emphasis
|
49
|
+
: type === 'strikethrough'
|
50
|
+
? Inline.Strikethrough
|
51
|
+
: Inline.Code;
|
52
|
+
setStyle(inlineType, !checked)(view);
|
53
|
+
},
|
54
|
+
{ checked, icon },
|
55
|
+
);
|
56
|
+
});
|
30
57
|
|
31
|
-
export const createFormatting = (state: EditorToolbarState) => {
|
58
|
+
export const createFormatting = (state: EditorToolbarState, getView: () => EditorView) => {
|
32
59
|
const formattingGroupAction = createFormattingGroup(state);
|
33
|
-
const formattingActions = createFormattingActions(state);
|
60
|
+
const formattingActions = createFormattingActions(state, getView);
|
34
61
|
return {
|
35
62
|
nodes: [formattingGroupAction as NodeArg<any>, ...formattingActions],
|
36
63
|
edges: [
|
@@ -2,10 +2,13 @@
|
|
2
2
|
// Copyright 2025 DXOS.org
|
3
3
|
//
|
4
4
|
|
5
|
+
import { type EditorView } from '@codemirror/view';
|
6
|
+
|
5
7
|
import { type NodeArg } from '@dxos/app-graph';
|
6
8
|
import { type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';
|
7
9
|
|
8
10
|
import { createEditorAction, createEditorActionGroup, type EditorToolbarState } from './util';
|
11
|
+
import { setHeading } from '../../extensions';
|
9
12
|
import { translationKey } from '../../translations';
|
10
13
|
|
11
14
|
const createHeadingGroupAction = (value: string) =>
|
@@ -20,7 +23,7 @@ const createHeadingGroupAction = (value: string) =>
|
|
20
23
|
'ph--text-h--regular',
|
21
24
|
);
|
22
25
|
|
23
|
-
const createHeadingActions = (
|
26
|
+
const createHeadingActions = (getView: () => EditorView) =>
|
24
27
|
Object.entries({
|
25
28
|
'0': 'ph--paragraph--regular',
|
26
29
|
'1': 'ph--text-h-one--regular',
|
@@ -31,12 +34,10 @@ const createHeadingActions = (value: string) =>
|
|
31
34
|
'6': 'ph--text-h-six--regular',
|
32
35
|
}).map(([levelStr, icon]) => {
|
33
36
|
const level = parseInt(levelStr);
|
34
|
-
return createEditorAction(
|
35
|
-
|
37
|
+
return createEditorAction(`heading--${levelStr}`, () => setHeading(level)(getView()), {
|
38
|
+
label: ['heading level label', { count: level, ns: translationKey }],
|
36
39
|
icon,
|
37
|
-
|
38
|
-
`heading--${levelStr}`,
|
39
|
-
);
|
40
|
+
});
|
40
41
|
});
|
41
42
|
|
42
43
|
const computeHeadingValue = (state: EditorToolbarState) => {
|
@@ -45,10 +46,10 @@ const computeHeadingValue = (state: EditorToolbarState) => {
|
|
45
46
|
return header ? header[1] : blockType === 'paragraph' || !blockType ? '0' : '';
|
46
47
|
};
|
47
48
|
|
48
|
-
export const createHeadings = (state: EditorToolbarState) => {
|
49
|
+
export const createHeadings = (state: EditorToolbarState, getView: () => EditorView) => {
|
49
50
|
const headingValue = computeHeadingValue(state);
|
50
51
|
const headingGroupAction = createHeadingGroupAction(headingValue);
|
51
|
-
const headingActions = createHeadingActions(
|
52
|
+
const headingActions = createHeadingActions(getView);
|
52
53
|
return {
|
53
54
|
nodes: [headingGroupAction as NodeArg<any>, ...headingActions],
|
54
55
|
edges: [
|
@@ -0,0 +1,16 @@
|
|
1
|
+
//
|
2
|
+
// Copyright 2025 DXOS.org
|
3
|
+
//
|
4
|
+
|
5
|
+
import { createEditorAction } from './util';
|
6
|
+
|
7
|
+
const createImageUploadAction = (onImageUpload: () => void) =>
|
8
|
+
createEditorAction('image', onImageUpload, {
|
9
|
+
testId: 'editor.toolbar.image',
|
10
|
+
icon: 'ph--image-square--regular',
|
11
|
+
});
|
12
|
+
|
13
|
+
export const createImageUpload = (onImageUpload: () => void) => ({
|
14
|
+
nodes: [createImageUploadAction(onImageUpload)],
|
15
|
+
edges: [{ source: 'root', target: 'image' }],
|
16
|
+
});
|
@@ -2,11 +2,13 @@
|
|
2
2
|
// Copyright 2025 DXOS.org
|
3
3
|
//
|
4
4
|
|
5
|
+
import { type EditorView } from '@codemirror/view';
|
6
|
+
|
5
7
|
import { type NodeArg } from '@dxos/app-graph';
|
6
8
|
import { type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';
|
7
9
|
|
8
10
|
import { createEditorAction, createEditorActionGroup, type EditorToolbarState } from './util';
|
9
|
-
import {
|
11
|
+
import { addList, List, removeList } from '../../extensions';
|
10
12
|
|
11
13
|
const listStyles = {
|
12
14
|
bullet: 'ph--list-bullets--regular',
|
@@ -21,15 +23,32 @@ const createListGroupAction = (value: string) =>
|
|
21
23
|
value,
|
22
24
|
} as ToolbarMenuActionGroupProperties);
|
23
25
|
|
24
|
-
const createListActions = (value: string) =>
|
25
|
-
Object.entries(listStyles).map(([listStyle, icon]) =>
|
26
|
-
|
27
|
-
|
26
|
+
const createListActions = (value: string, getView: () => EditorView) =>
|
27
|
+
Object.entries(listStyles).map(([listStyle, icon]) => {
|
28
|
+
const checked = value === listStyle;
|
29
|
+
return createEditorAction(
|
30
|
+
`list-${listStyle}`,
|
31
|
+
() => {
|
32
|
+
const view = getView();
|
33
|
+
if (!view) {
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
|
37
|
+
const listType = listStyle === 'ordered' ? List.Ordered : listStyle === 'bullet' ? List.Bullet : List.Task;
|
38
|
+
if (checked) {
|
39
|
+
removeList(listType)(view);
|
40
|
+
} else {
|
41
|
+
addList(listType)(view);
|
42
|
+
}
|
43
|
+
},
|
44
|
+
{ checked, icon },
|
45
|
+
);
|
46
|
+
});
|
28
47
|
|
29
|
-
export const createLists = (state: EditorToolbarState) => {
|
48
|
+
export const createLists = (state: EditorToolbarState, getView: () => EditorView) => {
|
30
49
|
const value = state.listStyle ?? '';
|
31
50
|
const listGroupAction = createListGroupAction(value);
|
32
|
-
const listActionsMap = createListActions(value);
|
51
|
+
const listActionsMap = createListActions(value, getView);
|
33
52
|
return {
|
34
53
|
nodes: [listGroupAction as NodeArg<any>, ...listActionsMap],
|
35
54
|
edges: [
|
@@ -0,0 +1,19 @@
|
|
1
|
+
//
|
2
|
+
// Copyright 2025 DXOS.org
|
3
|
+
//
|
4
|
+
|
5
|
+
import { openSearchPanel } from '@codemirror/search';
|
6
|
+
import { type EditorView } from '@codemirror/view';
|
7
|
+
|
8
|
+
import { createEditorAction } from './util';
|
9
|
+
|
10
|
+
const createSearchAction = (getView: () => EditorView) =>
|
11
|
+
createEditorAction('search', () => openSearchPanel(getView()), {
|
12
|
+
testId: 'editor.toolbar.search',
|
13
|
+
icon: 'ph--magnifying-glass--regular',
|
14
|
+
});
|
15
|
+
|
16
|
+
export const createSearch = (getView: () => EditorView) => ({
|
17
|
+
nodes: [createSearchAction(getView)],
|
18
|
+
edges: [{ source: 'root', target: 'search' }],
|
19
|
+
});
|