@dxos/react-ui-editor 0.8.4-main.74a063c4e0 → 0.8.4-main.765dc60934
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/LICENSE +102 -5
- package/README.md +1 -1
- package/dist/lib/browser/index.mjs +549 -426
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/translations.mjs +39 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +549 -426
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/translations.mjs +41 -0
- package/dist/lib/node-esm/translations.mjs.map +7 -0
- package/dist/types/src/components/Editor/Editor.d.ts +36 -25
- package/dist/types/src/components/Editor/Editor.d.ts.map +1 -1
- package/dist/types/src/components/Editor/Editor.stories.d.ts +4 -4
- package/dist/types/src/components/Editor/Editor.stories.d.ts.map +1 -1
- package/dist/types/src/components/{EditorContent/EditorContent.d.ts → Editor/EditorView.d.ts} +5 -5
- package/dist/types/src/components/Editor/EditorView.d.ts.map +1 -0
- package/dist/types/src/components/Editor/controller.d.ts.map +1 -0
- package/dist/types/src/components/EditorMenuProvider/EditorMenuProvider.d.ts.map +1 -1
- package/dist/types/src/components/EditorMenuProvider/menu.d.ts.map +1 -1
- package/dist/types/src/components/EditorMenuProvider/popover.d.ts +2 -1
- package/dist/types/src/components/EditorMenuProvider/popover.d.ts.map +1 -1
- package/dist/types/src/components/EditorMenuProvider/useEditorMenu.d.ts.map +1 -1
- package/dist/types/src/components/EditorPreviewProvider/EditorPreviewProvider.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/EditorToolbar.d.ts +2 -2
- package/dist/types/src/components/EditorToolbar/EditorToolbar.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/blocks.d.ts +1 -1
- package/dist/types/src/components/EditorToolbar/blocks.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/formatting.d.ts +1 -1
- package/dist/types/src/components/EditorToolbar/formatting.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/headings.d.ts +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/index.d.ts +1 -1
- package/dist/types/src/components/EditorToolbar/index.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/lists.d.ts +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/types.d.ts +6 -0
- package/dist/types/src/components/EditorToolbar/types.d.ts.map +1 -0
- package/dist/types/src/components/EditorToolbar/view-mode.d.ts +2 -2
- package/dist/types/src/components/EditorToolbar/view-mode.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +0 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/extensions/Assistant.stories.d.ts +10 -0
- package/dist/types/src/extensions/Assistant.stories.d.ts.map +1 -0
- package/dist/types/src/extensions/assistant-extension.d.ts +24 -0
- package/dist/types/src/extensions/assistant-extension.d.ts.map +1 -0
- package/dist/types/src/extensions/index.d.ts +2 -0
- package/dist/types/src/extensions/index.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +1 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useBasicMarkdownExtensions.d.ts +25 -0
- package/dist/types/src/hooks/useBasicMarkdownExtensions.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/stories/Automerge.stories.d.ts +24 -24
- package/dist/types/src/stories/Automerge.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Comments.stories.d.ts +1 -1
- package/dist/types/src/stories/Comments.stories.d.ts.map +1 -1
- package/dist/types/src/stories/EditorToolbar.stories.d.ts +27 -25
- package/dist/types/src/stories/EditorToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Experimental.stories.d.ts +2 -2
- package/dist/types/src/stories/Experimental.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Markdown.stories.d.ts +1 -1
- package/dist/types/src/stories/Markdown.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Outliner.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Popover.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Preview.stories.d.ts +1 -1
- package/dist/types/src/stories/Preview.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Tags.stories.d.ts.map +1 -1
- package/dist/types/src/stories/TextEditor.stories.d.ts +1 -1
- package/dist/types/src/stories/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Theme.stories.d.ts.map +1 -1
- package/dist/types/src/stories/components/EditorStory.d.ts +1 -1
- package/dist/types/src/stories/components/EditorStory.d.ts.map +1 -1
- package/dist/types/src/stories/components/util.d.ts +2 -1
- package/dist/types/src/stories/components/util.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +24 -24
- package/dist/types/src/translations.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 +56 -47
- package/src/components/Editor/Editor.stories.tsx +10 -15
- package/src/components/Editor/Editor.tsx +54 -53
- package/src/components/Editor/EditorView.tsx +102 -0
- package/src/components/EditorMenuProvider/EditorMenuProvider.tsx +1 -1
- package/src/components/EditorMenuProvider/popover.ts +3 -1
- package/src/components/EditorPreviewProvider/EditorPreviewProvider.tsx +1 -1
- package/src/components/EditorToolbar/EditorToolbar.tsx +9 -7
- package/src/components/EditorToolbar/blocks.ts +3 -2
- package/src/components/EditorToolbar/formatting.ts +3 -2
- package/src/components/EditorToolbar/headings.ts +3 -2
- package/src/components/EditorToolbar/image.ts +1 -1
- package/src/components/EditorToolbar/index.ts +2 -2
- package/src/components/EditorToolbar/lists.ts +3 -2
- package/src/components/EditorToolbar/search.ts +1 -1
- package/src/components/EditorToolbar/types.ts +8 -0
- package/src/components/EditorToolbar/view-mode.ts +4 -3
- package/src/components/index.ts +0 -3
- package/src/extensions/Assistant.stories.tsx +112 -0
- package/src/extensions/assistant-extension.tsx +223 -0
- package/src/extensions/index.ts +5 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useBasicMarkdownExtensions.ts +55 -0
- package/src/index.ts +1 -4
- package/src/stories/Automerge.stories.tsx +9 -5
- package/src/stories/Comments.stories.tsx +2 -1
- package/src/stories/EditorToolbar.stories.tsx +35 -78
- package/src/stories/Experimental.stories.tsx +7 -7
- package/src/stories/Theme.stories.tsx +2 -2
- package/src/stories/components/EditorStory.tsx +9 -7
- package/src/stories/components/util.tsx +2 -2
- package/src/util/react.tsx +1 -1
- package/dist/types/src/components/EditorContent/EditorContent.d.ts.map +0 -1
- package/dist/types/src/components/EditorContent/controller.d.ts.map +0 -1
- package/dist/types/src/components/EditorContent/index.d.ts +0 -3
- package/dist/types/src/components/EditorContent/index.d.ts.map +0 -1
- package/dist/types/src/components/EditorToolbar/useEditorToolbar.d.ts +0 -11
- package/dist/types/src/components/EditorToolbar/useEditorToolbar.d.ts.map +0 -1
- package/src/components/EditorContent/EditorContent.tsx +0 -82
- package/src/components/EditorContent/index.ts +0 -6
- package/src/components/EditorToolbar/useEditorToolbar.ts +0 -20
- /package/dist/types/src/components/{EditorContent → Editor}/controller.d.ts +0 -0
- /package/src/components/{EditorContent → Editor}/controller.ts +0 -0
|
@@ -2,104 +2,61 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { RegistryContext, useAtomValue } from '@effect-atom/atom-react';
|
|
6
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
7
|
-
import React, {
|
|
6
|
+
import React, { useMemo } from 'react';
|
|
8
7
|
|
|
9
|
-
import {
|
|
10
|
-
import { Panel, useThemeContext } from '@dxos/react-ui';
|
|
8
|
+
import { useThemeContext } from '@dxos/react-ui';
|
|
11
9
|
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
12
10
|
import { withRegistry } from '@dxos/storybook-utils';
|
|
13
11
|
import {
|
|
14
|
-
type EditorInputMode,
|
|
15
|
-
type EditorViewMode,
|
|
16
|
-
InputModeExtensions,
|
|
17
12
|
createBasicExtensions,
|
|
18
13
|
createMarkdownExtensions,
|
|
19
14
|
createThemeExtensions,
|
|
20
15
|
decorateMarkdown,
|
|
21
16
|
documentSlots,
|
|
22
17
|
formattingKeymap,
|
|
23
|
-
formattingListener,
|
|
24
18
|
} from '@dxos/ui-editor';
|
|
19
|
+
import { type EditorViewMode } from '@dxos/ui-editor/types';
|
|
25
20
|
|
|
26
|
-
import {
|
|
27
|
-
import { type UseTextEditorProps, useTextEditor } from '../hooks';
|
|
28
|
-
import { translations } from '../translations';
|
|
21
|
+
import { translations } from '#translations';
|
|
29
22
|
|
|
30
|
-
|
|
23
|
+
import { Editor } from '../components';
|
|
24
|
+
import { type UseTextEditorProps } from '../hooks';
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
const { themeMode } = useThemeContext();
|
|
34
|
-
const registry = useContext(RegistryContext);
|
|
35
|
-
|
|
36
|
-
const toolbarState = useEditorToolbar({ viewMode: 'source' });
|
|
37
|
-
const { viewMode } = useAtomValue(toolbarState);
|
|
38
|
-
|
|
39
|
-
const updateToolbarState = useCallback(
|
|
40
|
-
(formatting: EditorToolbarState) => {
|
|
41
|
-
registry.update(toolbarState, (state) => ({ ...state, ...formatting }));
|
|
42
|
-
},
|
|
43
|
-
[registry, toolbarState],
|
|
44
|
-
);
|
|
26
|
+
type DefaultStoryProps = { placeholder?: string; viewMode?: EditorViewMode } & UseTextEditorProps;
|
|
45
27
|
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
const { parentRef, view } = useTextEditor(
|
|
49
|
-
() => ({
|
|
50
|
-
autoFocus,
|
|
51
|
-
initialValue,
|
|
52
|
-
selectionEnd: true,
|
|
53
|
-
extensions: [
|
|
54
|
-
editorInputMode ? InputModeExtensions[editorInputMode] : [],
|
|
55
|
-
createBasicExtensions({
|
|
56
|
-
placeholder,
|
|
57
|
-
lineWrapping: true,
|
|
58
|
-
readOnly: viewMode === 'readonly',
|
|
59
|
-
search: true,
|
|
60
|
-
}),
|
|
61
|
-
createThemeExtensions({
|
|
62
|
-
themeMode,
|
|
63
|
-
syntaxHighlighting: true,
|
|
64
|
-
slots: documentSlots,
|
|
65
|
-
}),
|
|
66
|
-
createMarkdownExtensions(),
|
|
67
|
-
viewMode === 'source' ? [] : decorateMarkdown(),
|
|
68
|
-
formattingKeymap(),
|
|
69
|
-
formattingListener(updateToolbarState),
|
|
70
|
-
],
|
|
71
|
-
}),
|
|
72
|
-
[editorInputMode, viewMode, themeMode, placeholder],
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const getView = useCallback(() => {
|
|
76
|
-
invariant(view);
|
|
77
|
-
return view;
|
|
78
|
-
}, [view]);
|
|
28
|
+
const DefaultStory = ({ autoFocus, initialValue, placeholder, viewMode = 'source' }: DefaultStoryProps) => {
|
|
29
|
+
const { themeMode } = useThemeContext();
|
|
79
30
|
|
|
80
|
-
const
|
|
81
|
-
(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
31
|
+
const extensions = useMemo(
|
|
32
|
+
() => [
|
|
33
|
+
createBasicExtensions({
|
|
34
|
+
placeholder,
|
|
35
|
+
lineWrapping: true,
|
|
36
|
+
readOnly: viewMode === 'readonly',
|
|
37
|
+
search: true,
|
|
38
|
+
}),
|
|
39
|
+
createThemeExtensions({
|
|
40
|
+
themeMode,
|
|
41
|
+
syntaxHighlighting: true,
|
|
42
|
+
slots: documentSlots,
|
|
43
|
+
}),
|
|
44
|
+
createMarkdownExtensions(),
|
|
45
|
+
viewMode === 'source' ? [] : decorateMarkdown(),
|
|
46
|
+
formattingKeymap(),
|
|
47
|
+
],
|
|
48
|
+
[viewMode, themeMode, placeholder],
|
|
85
49
|
);
|
|
86
50
|
|
|
87
51
|
return (
|
|
88
|
-
<
|
|
89
|
-
|
|
90
|
-
<
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
/>
|
|
97
|
-
</Panel.Toolbar>
|
|
98
|
-
)}
|
|
99
|
-
<Panel.Content>
|
|
100
|
-
<div role='none' className='dx-container dx-document bg-base-surface' ref={parentRef} />
|
|
101
|
-
</Panel.Content>
|
|
102
|
-
</Panel.Root>
|
|
52
|
+
<Editor.Root extensions={extensions} viewMode={viewMode}>
|
|
53
|
+
<Editor.Content>
|
|
54
|
+
<Editor.Toolbar classNames='dx-document' />
|
|
55
|
+
<div className='dx-container dx-document bg-base-surface'>
|
|
56
|
+
<Editor.View autoFocus={autoFocus} initialValue={initialValue} selectionEnd />
|
|
57
|
+
</div>
|
|
58
|
+
</Editor.Content>
|
|
59
|
+
</Editor.Root>
|
|
103
60
|
);
|
|
104
61
|
};
|
|
105
62
|
|
|
@@ -9,7 +9,7 @@ import React from 'react';
|
|
|
9
9
|
import { log } from '@dxos/log';
|
|
10
10
|
import { random } from '@dxos/random';
|
|
11
11
|
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
12
|
-
import { blast, defaultOptions, dropFile, join,
|
|
12
|
+
import { blast, defaultOptions, dropFile, join, snippets } from '@dxos/ui-editor';
|
|
13
13
|
|
|
14
14
|
import { EditorStory, content } from './components';
|
|
15
15
|
|
|
@@ -27,16 +27,16 @@ export default meta;
|
|
|
27
27
|
type Story = StoryObj<typeof meta>;
|
|
28
28
|
|
|
29
29
|
//
|
|
30
|
-
//
|
|
30
|
+
// Snippets
|
|
31
31
|
//
|
|
32
32
|
|
|
33
|
-
const
|
|
33
|
+
const snippetItems = localStorage.getItem('org.dxos.testing.snippets')?.split(',');
|
|
34
34
|
|
|
35
|
-
export const
|
|
35
|
+
export const Snippets: Story = {
|
|
36
36
|
render: () => (
|
|
37
37
|
<EditorStory
|
|
38
|
-
text={join('#
|
|
39
|
-
extensions={[
|
|
38
|
+
text={join('# Snippets', '', content.paragraphs, content.footer)}
|
|
39
|
+
extensions={[snippets({ items: snippetItems })]}
|
|
40
40
|
/>
|
|
41
41
|
),
|
|
42
42
|
};
|
|
@@ -50,7 +50,7 @@ export const Blast: Story = {
|
|
|
50
50
|
<EditorStory
|
|
51
51
|
text={join('# Blast', '', content.paragraphs, content.codeblocks, content.paragraphs)}
|
|
52
52
|
extensions={[
|
|
53
|
-
|
|
53
|
+
snippets({ items: snippetItems }),
|
|
54
54
|
blast(
|
|
55
55
|
defaultsDeep(
|
|
56
56
|
{
|
|
@@ -34,10 +34,10 @@ const DefaultStory = () => {
|
|
|
34
34
|
return (
|
|
35
35
|
<div className='w-full grid grid-cols-2 gap-2'>
|
|
36
36
|
<Editor.Root>
|
|
37
|
-
<Editor.
|
|
37
|
+
<Editor.View classNames='p-2' extensions={ext1} initialValue={createText(false)} />
|
|
38
38
|
</Editor.Root>
|
|
39
39
|
<Editor.Root>
|
|
40
|
-
<Editor.
|
|
40
|
+
<Editor.View classNames='p-2' extensions={ext2} initialValue={createText(true)} />
|
|
41
41
|
</Editor.Root>
|
|
42
42
|
</div>
|
|
43
43
|
);
|
|
@@ -12,7 +12,7 @@ import { PublicKey } from '@dxos/keys';
|
|
|
12
12
|
import { log } from '@dxos/log';
|
|
13
13
|
import { useMergeRefs, useThemeContext } from '@dxos/react-ui';
|
|
14
14
|
import { useAttentionAttributes } from '@dxos/react-ui-attention';
|
|
15
|
-
import {
|
|
15
|
+
import { Syntax } from '@dxos/react-ui-syntax-highlighter';
|
|
16
16
|
import {
|
|
17
17
|
type DebugNode,
|
|
18
18
|
type ThemeExtensionsOptions,
|
|
@@ -77,12 +77,14 @@ export const EditorStory = forwardRef<EditorController, EditorStoryProps>(
|
|
|
77
77
|
</pre>
|
|
78
78
|
)}
|
|
79
79
|
{(debug === 'tree' || debug === 'raw+tree') && (
|
|
80
|
-
<
|
|
81
|
-
<
|
|
82
|
-
<
|
|
83
|
-
<
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
<Syntax.Root data={tree}>
|
|
81
|
+
<Syntax.Content>
|
|
82
|
+
<Syntax.Filter />
|
|
83
|
+
<Syntax.Viewport>
|
|
84
|
+
<Syntax.Code classNames='p-1 text-xs' />
|
|
85
|
+
</Syntax.Viewport>
|
|
86
|
+
</Syntax.Content>
|
|
87
|
+
</Syntax.Root>
|
|
86
88
|
)}
|
|
87
89
|
</div>
|
|
88
90
|
)}
|
|
@@ -9,7 +9,6 @@ import { random } from '@dxos/random';
|
|
|
9
9
|
import { Domino } from '@dxos/ui';
|
|
10
10
|
import {
|
|
11
11
|
type EditorSelectionState,
|
|
12
|
-
type RenderCallback,
|
|
13
12
|
decorateMarkdown,
|
|
14
13
|
folding,
|
|
15
14
|
formattingKeymap,
|
|
@@ -17,6 +16,7 @@ import {
|
|
|
17
16
|
linkTooltip,
|
|
18
17
|
table,
|
|
19
18
|
} from '@dxos/ui-editor';
|
|
19
|
+
import { type RenderCallback } from '@dxos/ui-editor/types';
|
|
20
20
|
import { safeUrl } from '@dxos/util';
|
|
21
21
|
|
|
22
22
|
import { str } from '../../util';
|
|
@@ -206,7 +206,7 @@ export const links: Completion[] = [
|
|
|
206
206
|
export const names = ['adam', 'alice', 'alison', 'bob', 'carol', 'charlie', 'sayuri', 'shoko'];
|
|
207
207
|
|
|
208
208
|
const hover =
|
|
209
|
-
'rounded-xs text-base-
|
|
209
|
+
'rounded-xs text-base-foreground text-primary-600 hover:text-primary-500 dark:text-primary-300 hover:dark:text-primary-200';
|
|
210
210
|
|
|
211
211
|
export const renderLinkTooltip: RenderCallback<{ url: string }> = (el, { url }) => {
|
|
212
212
|
el.appendChild(
|
package/src/util/react.tsx
CHANGED
|
@@ -6,7 +6,7 @@ import React, { type FC } from 'react';
|
|
|
6
6
|
import { createRoot } from 'react-dom/client';
|
|
7
7
|
|
|
8
8
|
import { ThemeProvider, Tooltip } from '@dxos/react-ui';
|
|
9
|
-
import { type RenderCallback } from '@dxos/ui-editor';
|
|
9
|
+
import { type RenderCallback } from '@dxos/ui-editor/types';
|
|
10
10
|
import { defaultTx } from '@dxos/ui-theme';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EditorContent.d.ts","sourceRoot":"","sources":["../../../../../src/components/EditorContent/EditorContent.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAqD,MAAM,OAAO,CAAC;AAE1E,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAItD,OAAO,EAAE,KAAK,kBAAkB,EAAiB,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,KAAK,gBAAgB,EAA0B,MAAM,cAAc,CAAC;AAE7E,MAAM,MAAM,kBAAkB,GAAG,eAAe,CAC9C;IACE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC,GAAG,kBAAkB,CACvB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa;gBAXV,OAAO;YACX,MAAM;eACH,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI;;;;;;;;;;;;0CA8DrC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../../../src/components/EditorContent/controller.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,IAAI,IAAI,UAAU,GAAG,IAAI,CAAC;IAC9B,OAAO,EAAE,MAAM,MAAM,CAAC;IACtB,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACjD,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,eAAO,MAAM,cAAc,EAAE,gBAO5B,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,MAAM,UAAU,GAAG,IAAI,KAAG,gBA2BhE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/EditorContent/index.ts"],"names":[],"mappings":"AAIA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Atom } from '@effect-atom/atom-react';
|
|
2
|
-
import { type EditorViewMode, type Formatting } from '@dxos/ui-editor';
|
|
3
|
-
export type EditorToolbarState = {
|
|
4
|
-
viewMode?: EditorViewMode;
|
|
5
|
-
} & Formatting;
|
|
6
|
-
/**
|
|
7
|
-
* Creates an atom for editor toolbar state.
|
|
8
|
-
* @deprecated Use Editor.Root
|
|
9
|
-
*/
|
|
10
|
-
export declare const useEditorToolbar: (initialState?: EditorToolbarState) => Atom.Writable<EditorToolbarState>;
|
|
11
|
-
//# sourceMappingURL=useEditorToolbar.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useEditorToolbar.d.ts","sourceRoot":"","sources":["../../../../../src/components/EditorToolbar/useEditorToolbar.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAG/C,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGvE,MAAM,MAAM,kBAAkB,GAAG;IAAE,QAAQ,CAAC,EAAE,cAAc,CAAA;CAAE,GAAG,UAAU,CAAC;AAE5E;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,eAAc,kBAAuB,KAAG,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAGxG,CAAC"}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Transaction } from '@codemirror/state';
|
|
6
|
-
import { EditorView } from '@codemirror/view';
|
|
7
|
-
import React, { forwardRef, useEffect, useImperativeHandle } from 'react';
|
|
8
|
-
|
|
9
|
-
import { type ThemedClassName } from '@dxos/react-ui';
|
|
10
|
-
import { initialSync } from '@dxos/ui-editor';
|
|
11
|
-
import { mx } from '@dxos/ui-theme';
|
|
12
|
-
|
|
13
|
-
import { type UseTextEditorProps, useTextEditor } from '../../hooks';
|
|
14
|
-
import { type EditorController, createEditorController } from './controller';
|
|
15
|
-
|
|
16
|
-
export type EditorContentProps = ThemedClassName<
|
|
17
|
-
{
|
|
18
|
-
focusable?: boolean;
|
|
19
|
-
value?: string;
|
|
20
|
-
onChange?: (value: string) => void;
|
|
21
|
-
} & UseTextEditorProps
|
|
22
|
-
>;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Minimal text editor.
|
|
26
|
-
* NOTE: This shouold not be used with the automerge extension.
|
|
27
|
-
* @deprecated Use Editor.Content
|
|
28
|
-
*/
|
|
29
|
-
export const EditorContent = forwardRef<EditorController, EditorContentProps>(
|
|
30
|
-
({ classNames, id, extensions, selectionEnd, focusable = true, value, onChange, ...props }, forwardedRef) => {
|
|
31
|
-
const { parentRef, focusAttributes, view } = useTextEditor(
|
|
32
|
-
() => ({
|
|
33
|
-
id,
|
|
34
|
-
initialValue: value,
|
|
35
|
-
selectionEnd,
|
|
36
|
-
extensions: [
|
|
37
|
-
extensions ?? [],
|
|
38
|
-
EditorView.updateListener.of(({ view, docChanged, transactions }) => {
|
|
39
|
-
const isInitialSync = transactions.some((tr) => tr.annotation(Transaction.userEvent) === initialSync.value);
|
|
40
|
-
if (!isInitialSync && docChanged) {
|
|
41
|
-
onChange?.(view.state.doc.toString());
|
|
42
|
-
}
|
|
43
|
-
}),
|
|
44
|
-
],
|
|
45
|
-
...props,
|
|
46
|
-
}),
|
|
47
|
-
[id, extensions, selectionEnd, onChange],
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
// External controller.
|
|
51
|
-
useImperativeHandle(forwardedRef, () => {
|
|
52
|
-
return createEditorController(view);
|
|
53
|
-
}, [id, view]);
|
|
54
|
-
|
|
55
|
-
// Set initial value and cursor position.
|
|
56
|
-
useEffect(() => {
|
|
57
|
-
requestAnimationFrame(() => {
|
|
58
|
-
view?.dispatch({
|
|
59
|
-
annotations: initialSync,
|
|
60
|
-
changes: value ? [{ from: 0, to: view?.state.doc.length ?? 0, insert: value ?? '' }] : [],
|
|
61
|
-
selection: selectionEnd ? { anchor: view?.state.doc.length ?? 0 } : undefined,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
if (selectionEnd) {
|
|
65
|
-
view?.focus();
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}, [view, value, selectionEnd]);
|
|
69
|
-
|
|
70
|
-
return (
|
|
71
|
-
<div
|
|
72
|
-
role='none'
|
|
73
|
-
className={mx(
|
|
74
|
-
'w-full outline-hidden focus:border-accent-surface focus-within:border-neutral-focus-indicator',
|
|
75
|
-
classNames,
|
|
76
|
-
)}
|
|
77
|
-
ref={parentRef}
|
|
78
|
-
{...(focusable ? focusAttributes : {})}
|
|
79
|
-
/>
|
|
80
|
-
);
|
|
81
|
-
},
|
|
82
|
-
);
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Atom } from '@effect-atom/atom-react';
|
|
6
|
-
import { useMemo } from 'react';
|
|
7
|
-
|
|
8
|
-
import { type EditorViewMode, type Formatting } from '@dxos/ui-editor';
|
|
9
|
-
|
|
10
|
-
// TODO(burdon): Move to extensions.
|
|
11
|
-
export type EditorToolbarState = { viewMode?: EditorViewMode } & Formatting;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Creates an atom for editor toolbar state.
|
|
15
|
-
* @deprecated Use Editor.Root
|
|
16
|
-
*/
|
|
17
|
-
export const useEditorToolbar = (initialState: EditorToolbarState = {}): Atom.Writable<EditorToolbarState> => {
|
|
18
|
-
// TODO(wittjosiah): Including initialState in the deps causes reactivity issues.
|
|
19
|
-
return useMemo(() => Atom.make<EditorToolbarState>(initialState), []);
|
|
20
|
-
};
|
|
File without changes
|
|
File without changes
|