@dxos/react-ui-editor 0.8.4-main.5acf9ea → 0.8.4-main.5ea62a8
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 +768 -452
- 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-esm/index.mjs +768 -452
- 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/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 +2 -2
- 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/Popover/CommandMenu.d.ts.map +1 -1
- package/dist/types/src/defaults.d.ts.map +1 -1
- package/dist/types/src/extensions/autocomplete.d.ts +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/automerge.stories.d.ts +9 -18
- 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/command/action.d.ts +1 -1
- package/dist/types/src/extensions/command/action.d.ts.map +1 -1
- package/dist/types/src/extensions/command/command-menu.d.ts +1 -1
- package/dist/types/src/extensions/command/command-menu.d.ts.map +1 -1
- package/dist/types/src/extensions/command/command.d.ts.map +1 -1
- package/dist/types/src/extensions/command/hint.d.ts.map +1 -1
- package/dist/types/src/extensions/command/state.d.ts +1 -1
- package/dist/types/src/extensions/command/state.d.ts.map +1 -1
- package/dist/types/src/extensions/command/typeahead.d.ts.map +1 -1
- package/dist/types/src/extensions/command/useCommandMenu.d.ts +1 -1
- package/dist/types/src/extensions/command/useCommandMenu.d.ts.map +1 -1
- package/dist/types/src/extensions/comments.d.ts +1 -1
- package/dist/types/src/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/extensions/dnd.d.ts.map +1 -1
- package/dist/types/src/extensions/factories.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/action.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/bundle.d.ts +2 -0
- 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/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/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 +1 -1
- package/dist/types/src/extensions/outliner/tree.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
- package/dist/types/src/stories/Command.stories.d.ts +12 -4
- package/dist/types/src/stories/Command.stories.d.ts.map +1 -1
- package/dist/types/src/stories/CommandMenu.stories.d.ts +10 -3
- package/dist/types/src/stories/CommandMenu.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Comments.stories.d.ts +21 -9
- package/dist/types/src/stories/Comments.stories.d.ts.map +1 -1
- package/dist/types/src/stories/EditorToolbar.stories.d.ts +39 -2
- package/dist/types/src/stories/EditorToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Experimental.stories.d.ts +22 -12
- package/dist/types/src/stories/Experimental.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Markdown.stories.d.ts +32 -42
- package/dist/types/src/stories/Markdown.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Outliner.stories.d.ts +15 -20
- package/dist/types/src/stories/Outliner.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Preview.stories.d.ts +21 -6
- package/dist/types/src/stories/Preview.stories.d.ts.map +1 -1
- package/dist/types/src/stories/TextEditor.stories.d.ts +38 -51
- package/dist/types/src/stories/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/stories/components/EditorStory.d.ts +3 -6
- package/dist/types/src/stories/components/EditorStory.d.ts.map +1 -1
- package/dist/types/src/styles/theme.d.ts.map +1 -1
- package/dist/types/src/testing/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/util/cursor.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +44 -44
- package/src/components/Editor/Editor.tsx +1 -1
- package/src/components/EditorToolbar/EditorToolbar.tsx +40 -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/Popover/CommandMenu.tsx +3 -3
- package/src/components/Popover/RefDropdownMenu.tsx +1 -1
- package/src/components/Popover/RefPopover.tsx +4 -4
- package/src/defaults.ts +5 -2
- package/src/extensions/autocomplete.ts +3 -3
- package/src/extensions/automerge/automerge.stories.tsx +25 -18
- 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/awareness/awareness.ts +2 -2
- package/src/extensions/command/action.ts +1 -1
- package/src/extensions/command/command-menu.ts +4 -3
- package/src/extensions/command/command.ts +3 -3
- package/src/extensions/command/hint.ts +2 -1
- package/src/extensions/command/placeholder.ts +1 -1
- package/src/extensions/command/state.ts +4 -3
- package/src/extensions/command/typeahead.ts +2 -2
- package/src/extensions/command/useCommandMenu.ts +2 -1
- package/src/extensions/comments.ts +13 -12
- package/src/extensions/dnd.ts +1 -1
- package/src/extensions/factories.ts +4 -3
- package/src/extensions/markdown/action.ts +2 -1
- package/src/extensions/markdown/bundle.ts +4 -1
- package/src/extensions/markdown/changes.ts +1 -1
- package/src/extensions/markdown/decorate.ts +7 -6
- 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/mention.ts +1 -1
- package/src/extensions/outliner/outliner.test.ts +3 -2
- package/src/extensions/outliner/outliner.ts +4 -3
- package/src/extensions/outliner/selection.ts +1 -1
- package/src/extensions/outliner/tree.test.ts +2 -1
- package/src/extensions/outliner/tree.ts +1 -1
- package/src/hooks/useTextEditor.ts +3 -3
- package/src/stories/Command.stories.tsx +12 -8
- package/src/stories/CommandMenu.stories.tsx +16 -14
- package/src/stories/Comments.stories.tsx +10 -6
- package/src/stories/EditorToolbar.stories.tsx +7 -7
- package/src/stories/Experimental.stories.tsx +12 -8
- package/src/stories/Markdown.stories.tsx +21 -17
- package/src/stories/Outliner.stories.tsx +14 -10
- package/src/stories/Preview.stories.tsx +27 -25
- package/src/stories/TextEditor.stories.tsx +36 -32
- package/src/stories/components/EditorStory.tsx +8 -9
- package/src/styles/theme.ts +8 -6
- package/src/testing/util.ts +2 -0
- package/src/translations.ts +1 -1
- package/src/util/cursor.ts +2 -1
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
|
);
|
@@ -3,12 +3,12 @@
|
|
3
3
|
//
|
4
4
|
|
5
5
|
import {
|
6
|
-
autocompletion,
|
7
|
-
completionKeymap,
|
8
|
-
type CompletionSource,
|
9
6
|
type Completion,
|
10
7
|
type CompletionContext,
|
11
8
|
type CompletionResult,
|
9
|
+
type CompletionSource,
|
10
|
+
autocompletion,
|
11
|
+
completionKeymap,
|
12
12
|
} from '@codemirror/autocomplete';
|
13
13
|
import { markdownLanguage } from '@codemirror/lang-markdown';
|
14
14
|
import { type Extension } from '@codemirror/state';
|
@@ -8,14 +8,15 @@ import '@preact/signals-react';
|
|
8
8
|
|
9
9
|
import { Repo } from '@automerge/automerge-repo';
|
10
10
|
import { BroadcastChannelNetworkAdapter } from '@automerge/automerge-repo-network-broadcastchannel';
|
11
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
11
12
|
import React, { useEffect, useState } from 'react';
|
12
13
|
|
13
14
|
import { Obj, Ref, Type } from '@dxos/echo';
|
14
|
-
import { DocAccessor,
|
15
|
-
import {
|
16
|
-
import {
|
15
|
+
import { DocAccessor, Query, type Space, createDocAccessor, useQuery, useSpace } from '@dxos/react-client/echo';
|
16
|
+
import { type Identity, useIdentity } from '@dxos/react-client/halo';
|
17
|
+
import { type ClientRepeatedComponentProps, ClientRepeater } from '@dxos/react-client/testing';
|
17
18
|
import { useThemeContext } from '@dxos/react-ui';
|
18
|
-
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
19
|
+
import { render, withLayout, withTheme } from '@dxos/storybook-utils';
|
19
20
|
|
20
21
|
import { editorSlots } from '../../defaults';
|
21
22
|
import { useTextEditor } from '../../hooks';
|
@@ -41,7 +42,7 @@ const Editor = ({ source, autoFocus, space, identity }: EditorProps) => {
|
|
41
42
|
() => ({
|
42
43
|
initialValue: DocAccessor.getValue(source),
|
43
44
|
extensions: [
|
44
|
-
createBasicExtensions({ placeholder: 'Type here...' }),
|
45
|
+
createBasicExtensions({ placeholder: 'Type here...', search: true }),
|
45
46
|
createThemeExtensions({ themeMode, slots: editorSlots }),
|
46
47
|
createDataExtensions({ id: 'test', text: source, space, identity }),
|
47
48
|
],
|
@@ -53,7 +54,7 @@ const Editor = ({ source, autoFocus, space, identity }: EditorProps) => {
|
|
53
54
|
return <div ref={parentRef} className='flex w-full' />;
|
54
55
|
};
|
55
56
|
|
56
|
-
const
|
57
|
+
const DefaultStory = () => {
|
57
58
|
const [object1, setObject1] = useState<DocAccessor<TestObject>>();
|
58
59
|
const [object2, setObject2] = useState<DocAccessor<TestObject>>();
|
59
60
|
|
@@ -88,16 +89,6 @@ const Story = () => {
|
|
88
89
|
);
|
89
90
|
};
|
90
91
|
|
91
|
-
export default {
|
92
|
-
title: 'ui/react-ui-editor/Automerge',
|
93
|
-
component: Editor,
|
94
|
-
decorators: [withTheme, withLayout({ fullscreen: true })],
|
95
|
-
render: () => <Story />,
|
96
|
-
parameters: {
|
97
|
-
translations,
|
98
|
-
},
|
99
|
-
};
|
100
|
-
|
101
92
|
const EchoStory = ({ spaceKey }: ClientRepeatedComponentProps) => {
|
102
93
|
const identity = useIdentity();
|
103
94
|
const space = useSpace(spaceKey);
|
@@ -118,9 +109,25 @@ const EchoStory = ({ spaceKey }: ClientRepeatedComponentProps) => {
|
|
118
109
|
return <Editor source={source} space={space} identity={identity ?? undefined} />;
|
119
110
|
};
|
120
111
|
|
121
|
-
|
112
|
+
const meta = {
|
113
|
+
title: 'ui/react-ui-editor/Automerge',
|
114
|
+
component: Editor as any,
|
115
|
+
render: render(DefaultStory),
|
116
|
+
decorators: [withTheme, withLayout({ fullscreen: true })],
|
117
|
+
parameters: {
|
118
|
+
translations,
|
119
|
+
},
|
120
|
+
} satisfies Meta<typeof DefaultStory>;
|
121
|
+
|
122
|
+
export default meta;
|
123
|
+
|
124
|
+
type Story = StoryObj<typeof meta>;
|
125
|
+
|
126
|
+
export const Default: Story = {
|
127
|
+
args: {},
|
128
|
+
};
|
122
129
|
|
123
|
-
export const WithEcho = {
|
130
|
+
export const WithEcho: Story = {
|
124
131
|
decorators: [withTheme],
|
125
132
|
render: () => {
|
126
133
|
return (
|
@@ -5,15 +5,16 @@
|
|
5
5
|
//
|
6
6
|
|
7
7
|
import { next as A } from '@automerge/automerge';
|
8
|
-
import {
|
8
|
+
import { type Extension, StateField } from '@codemirror/state';
|
9
9
|
import { EditorView, ViewPlugin } from '@codemirror/view';
|
10
10
|
|
11
11
|
import { type DocAccessor } from '@dxos/react-client/echo';
|
12
12
|
|
13
|
+
import { Cursor } from '../../util';
|
14
|
+
|
13
15
|
import { cursorConverter } from './cursor';
|
14
|
-
import {
|
16
|
+
import { type State, isReconcile, updateHeadsEffect } from './defs';
|
15
17
|
import { Syncer } from './sync';
|
16
|
-
import { Cursor } from '../../util';
|
17
18
|
|
18
19
|
export const automerge = (accessor: DocAccessor): Extension => {
|
19
20
|
const syncState = StateField.define<State>({
|
@@ -5,7 +5,7 @@
|
|
5
5
|
//
|
6
6
|
|
7
7
|
import { type Heads, type Prop } from '@automerge/automerge';
|
8
|
-
import { Annotation, StateEffect, type StateField, type
|
8
|
+
import { Annotation, type EditorState, StateEffect, type StateField, type Transaction } from '@codemirror/state';
|
9
9
|
|
10
10
|
export type State = {
|
11
11
|
path: Prop[];
|
@@ -10,7 +10,7 @@ import { type EditorView } from '@codemirror/view';
|
|
10
10
|
|
11
11
|
import { type IDocHandle } from '@dxos/react-client/echo';
|
12
12
|
|
13
|
-
import { getLastHeads, getPath, isReconcile, reconcileAnnotation,
|
13
|
+
import { type State, getLastHeads, getPath, isReconcile, reconcileAnnotation, updateHeads } from './defs';
|
14
14
|
import { updateAutomerge } from './update-automerge';
|
15
15
|
import { updateCodeMirror } from './update-codemirror';
|
16
16
|
|
@@ -5,7 +5,7 @@
|
|
5
5
|
//
|
6
6
|
|
7
7
|
import { next as A, type Heads } from '@automerge/automerge';
|
8
|
-
import { type EditorState, type StateField, type
|
8
|
+
import { type EditorState, type StateField, type Text, type Transaction } from '@codemirror/state';
|
9
9
|
|
10
10
|
import { type IDocHandle } from '@dxos/react-client/echo';
|
11
11
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
// Copyright 2024 DXOS.org
|
3
3
|
//
|
4
4
|
|
5
|
-
import { Annotation, type Extension,
|
5
|
+
import { Annotation, type Extension, type Range, RangeSet } from '@codemirror/state';
|
6
6
|
import {
|
7
7
|
Decoration,
|
8
8
|
type DecorationSet,
|
@@ -16,7 +16,7 @@ import {
|
|
16
16
|
import { Event } from '@dxos/async';
|
17
17
|
import { Context } from '@dxos/context';
|
18
18
|
|
19
|
-
import {
|
19
|
+
import { Cursor, type CursorConverter, singleValueFacet } from '../../util';
|
20
20
|
|
21
21
|
export interface AwarenessProvider {
|
22
22
|
remoteStateChange: Event<void>;
|
@@ -3,7 +3,7 @@
|
|
3
3
|
//
|
4
4
|
|
5
5
|
import { StateEffect } from '@codemirror/state';
|
6
|
-
import { type
|
6
|
+
import { type Command, type EditorView, type KeyBinding } from '@codemirror/view';
|
7
7
|
|
8
8
|
import { commandState } from './state';
|
9
9
|
|
@@ -2,12 +2,13 @@
|
|
2
2
|
// Copyright 2024 DXOS.org
|
3
3
|
//
|
4
4
|
|
5
|
-
import {
|
6
|
-
import { EditorView, ViewPlugin, type ViewUpdate,
|
5
|
+
import { Prec, RangeSetBuilder, StateEffect, StateField } from '@codemirror/state';
|
6
|
+
import { Decoration, type DecorationSet, EditorView, ViewPlugin, type ViewUpdate, keymap } from '@codemirror/view';
|
7
7
|
|
8
|
-
import { placeholder, type PlaceholderOptions } from './placeholder';
|
9
8
|
import { type Range } from '../../types';
|
10
9
|
|
10
|
+
import { type PlaceholderOptions, placeholder } from './placeholder';
|
11
|
+
|
11
12
|
export type CommandMenuOptions = {
|
12
13
|
trigger: string | string[];
|
13
14
|
placeholder?: Partial<PlaceholderOptions>;
|
@@ -2,14 +2,14 @@
|
|
2
2
|
// Copyright 2024 DXOS.org
|
3
3
|
//
|
4
4
|
|
5
|
-
import {
|
5
|
+
import { type Extension, Prec } from '@codemirror/state';
|
6
6
|
import { EditorView, keymap } from '@codemirror/view';
|
7
7
|
|
8
8
|
import { isNonNullable } from '@dxos/util';
|
9
9
|
|
10
10
|
import { closeEffect, commandKeyBindings } from './action';
|
11
|
-
import {
|
12
|
-
import { commandConfig, commandState
|
11
|
+
import { type HintOptions, hint } from './hint';
|
12
|
+
import { type PopupOptions, commandConfig, commandState } from './state';
|
13
13
|
|
14
14
|
// TODO(burdon): Create knowledge base for CM notes and ideas.
|
15
15
|
// https://discuss.codemirror.net/t/inline-code-hints-like-vscode/5533/4
|
@@ -6,9 +6,10 @@
|
|
6
6
|
import { RangeSetBuilder } from '@codemirror/state';
|
7
7
|
import { Decoration, EditorView, ViewPlugin, type ViewUpdate, WidgetType } from '@codemirror/view';
|
8
8
|
|
9
|
-
import { commandState } from './state';
|
10
9
|
import { clientRectsFor, flattenRect } from '../../util';
|
11
10
|
|
11
|
+
import { commandState } from './state';
|
12
|
+
|
12
13
|
export type HintOptions = {
|
13
14
|
delay?: number;
|
14
15
|
onHint?: () => string | undefined;
|
@@ -4,7 +4,7 @@
|
|
4
4
|
//
|
5
5
|
|
6
6
|
import { type Extension } from '@codemirror/state';
|
7
|
-
import { Decoration, EditorView,
|
7
|
+
import { Decoration, EditorView, ViewPlugin, type ViewUpdate, WidgetType } from '@codemirror/view';
|
8
8
|
|
9
9
|
import { clientRectsFor, flattenRect } from '../../util';
|
10
10
|
|
@@ -3,13 +3,14 @@
|
|
3
3
|
//
|
4
4
|
|
5
5
|
import { StateField } from '@codemirror/state';
|
6
|
-
import {
|
6
|
+
import { type EditorView, type Tooltip, type TooltipView, showTooltip } from '@codemirror/view';
|
7
7
|
|
8
|
-
import { closeEffect, type Action, openEffect } from './action';
|
9
|
-
import { type CommandOptions } from './command';
|
10
8
|
import { type RenderCallback } from '../../types';
|
11
9
|
import { singleValueFacet } from '../../util';
|
12
10
|
|
11
|
+
import { type Action, closeEffect, openEffect } from './action';
|
12
|
+
import { type CommandOptions } from './command';
|
13
|
+
|
13
14
|
export const commandConfig = singleValueFacet<CommandOptions>();
|
14
15
|
|
15
16
|
export type PopupOptions = {
|
@@ -2,15 +2,15 @@
|
|
2
2
|
// Copyright 2025 DXOS.org
|
3
3
|
//
|
4
4
|
|
5
|
-
import { EditorSelection, Prec, RangeSetBuilder
|
5
|
+
import { EditorSelection, type Extension, Prec, RangeSetBuilder } from '@codemirror/state';
|
6
6
|
import {
|
7
7
|
type Command,
|
8
8
|
Decoration,
|
9
9
|
type DecorationSet,
|
10
10
|
type EditorView,
|
11
|
-
keymap,
|
12
11
|
ViewPlugin,
|
13
12
|
type ViewUpdate,
|
13
|
+
keymap,
|
14
14
|
} from '@codemirror/view';
|
15
15
|
|
16
16
|
import { Hint } from './hint';
|
@@ -8,9 +8,10 @@ import { type RefObject, useCallback, useMemo, useRef, useState } from 'react';
|
|
8
8
|
import { type DxRefTag, type DxRefTagActivate } from '@dxos/lit-ui';
|
9
9
|
import { type MaybePromise } from '@dxos/util';
|
10
10
|
|
11
|
+
import { type CommandMenuGroup, type CommandMenuItem, getItem, getNextItem, getPreviousItem } from '../../components';
|
12
|
+
|
11
13
|
import { commandMenu, commandRangeEffect } from './command-menu';
|
12
14
|
import { type PlaceholderOptions } from './placeholder';
|
13
|
-
import { getItem, getNextItem, getPreviousItem, type CommandMenuGroup, type CommandMenuItem } from '../../components';
|
14
15
|
|
15
16
|
export type UseCommandMenuOptions = {
|
16
17
|
viewRef: RefObject<EditorView | undefined>;
|
@@ -5,25 +5,26 @@
|
|
5
5
|
import { invertedEffects } from '@codemirror/commands';
|
6
6
|
import { type ChangeDesc, type Extension, StateEffect, StateField, type Text } from '@codemirror/state';
|
7
7
|
import {
|
8
|
-
hoverTooltip,
|
9
|
-
keymap,
|
10
8
|
type Command,
|
11
9
|
Decoration,
|
12
10
|
EditorView,
|
13
|
-
type Rect,
|
14
11
|
type PluginValue,
|
12
|
+
type Rect,
|
15
13
|
ViewPlugin,
|
14
|
+
hoverTooltip,
|
15
|
+
keymap,
|
16
16
|
} from '@codemirror/view';
|
17
17
|
import sortBy from 'lodash.sortby';
|
18
18
|
import { useEffect } from 'react';
|
19
19
|
|
20
|
-
import {
|
20
|
+
import { type CleanupFn, debounce } from '@dxos/async';
|
21
21
|
import { log } from '@dxos/log';
|
22
22
|
import { isNonNullable } from '@dxos/util';
|
23
23
|
|
24
|
+
import { type Comment, type Range, type RenderCallback } from '../types';
|
25
|
+
import { Cursor, callbackWrapper, singleValueFacet } from '../util';
|
26
|
+
|
24
27
|
import { documentId } from './selection';
|
25
|
-
import { type RenderCallback, type Comment, type Range } from '../types';
|
26
|
-
import { Cursor, singleValueFacet, callbackWrapper } from '../util';
|
27
28
|
|
28
29
|
//
|
29
30
|
// State management.
|
@@ -98,16 +99,16 @@ export const commentsState = StateField.define<CommentsState>({
|
|
98
99
|
*/
|
99
100
|
const styles = EditorView.theme({
|
100
101
|
'.cm-comment, .cm-comment-current': {
|
101
|
-
|
102
|
-
|
103
|
-
|
102
|
+
padding: '3px 0',
|
103
|
+
backgroundColor: 'var(--dx-cmCommentSurface)',
|
104
|
+
},
|
105
|
+
'.cm-comment > span, .cm-comment-current > span': {
|
106
|
+
boxDecorationBreak: 'clone',
|
107
|
+
boxShadow: '0 0 1px 3px var(--dx-cmCommentSurface)',
|
104
108
|
backgroundColor: 'var(--dx-cmCommentSurface)',
|
105
109
|
color: 'var(--dx-cmComment)',
|
106
110
|
cursor: 'pointer',
|
107
111
|
},
|
108
|
-
'.cm-comment:hover, .cm-comment-current': {
|
109
|
-
textDecoration: 'underline',
|
110
|
-
},
|
111
112
|
});
|
112
113
|
|
113
114
|
const createCommentMark = (id: string, isCurrent: boolean) =>
|
package/src/extensions/dnd.ts
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
//
|
4
4
|
|
5
5
|
import type { Extension } from '@codemirror/state';
|
6
|
-
import {
|
6
|
+
import { EditorView, dropCursor } from '@codemirror/view';
|
7
7
|
|
8
8
|
export type DNDOptions = { onDrop?: (view: EditorView, event: { files: FileList }) => void };
|
9
9
|
|
@@ -31,11 +31,12 @@ import { type ThemeMode } from '@dxos/react-ui';
|
|
31
31
|
import { type HuePalette } from '@dxos/react-ui-theme';
|
32
32
|
import { hexToHue, isNotFalsy } from '@dxos/util';
|
33
33
|
|
34
|
+
import { editorGutter, editorMonospace } from '../defaults';
|
35
|
+
import { type ThemeStyles, defaultTheme } from '../styles';
|
36
|
+
|
34
37
|
import { automerge } from './automerge';
|
35
38
|
import { SpaceAwarenessProvider, awareness } from './awareness';
|
36
39
|
import { focus } from './focus';
|
37
|
-
import { editorGutter, editorMonospace } from '../defaults';
|
38
|
-
import { type ThemeStyles, defaultTheme } from '../styles';
|
39
40
|
|
40
41
|
//
|
41
42
|
// Basic
|
@@ -82,7 +83,7 @@ const defaultBasicOptions: BasicExtensionsOptions = {
|
|
82
83
|
history: true,
|
83
84
|
keymap: 'standard',
|
84
85
|
lineWrapping: true,
|
85
|
-
search:
|
86
|
+
search: false,
|
86
87
|
} as const;
|
87
88
|
|
88
89
|
const keymaps: { [key: string]: readonly KeyBinding[] } = {
|
@@ -7,6 +7,8 @@ import { type EditorView } from '@codemirror/view';
|
|
7
7
|
import { type Action } from '@dxos/app-graph';
|
8
8
|
import { type MenuActionProperties } from '@dxos/react-ui-menu';
|
9
9
|
|
10
|
+
import { createComment } from '../comments';
|
11
|
+
|
10
12
|
import {
|
11
13
|
Inline,
|
12
14
|
List,
|
@@ -25,7 +27,6 @@ import {
|
|
25
27
|
toggleList,
|
26
28
|
toggleStyle,
|
27
29
|
} from './formatting';
|
28
|
-
import { createComment } from '../comments';
|
29
30
|
|
30
31
|
export type PayloadType =
|
31
32
|
| 'view-mode'
|
@@ -4,11 +4,12 @@
|
|
4
4
|
|
5
5
|
import { completionKeymap } from '@codemirror/autocomplete';
|
6
6
|
import { defaultKeymap, indentWithTab } from '@codemirror/commands';
|
7
|
-
import {
|
7
|
+
import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
|
8
8
|
import { syntaxHighlighting } from '@codemirror/language';
|
9
9
|
import { languages } from '@codemirror/language-data';
|
10
10
|
import { type Extension } from '@codemirror/state';
|
11
11
|
import { keymap } from '@codemirror/view';
|
12
|
+
import { type MarkdownConfig } from '@lezer/markdown';
|
12
13
|
|
13
14
|
import { type ThemeMode } from '@dxos/react-ui';
|
14
15
|
import { isNotFalsy } from '@dxos/util';
|
@@ -17,6 +18,7 @@ import { markdownHighlightStyle, markdownTagsExtensions } from './highlight';
|
|
17
18
|
|
18
19
|
export type MarkdownBundleOptions = {
|
19
20
|
themeMode?: ThemeMode;
|
21
|
+
extensions?: MarkdownConfig[];
|
20
22
|
indentWithTab?: boolean;
|
21
23
|
};
|
22
24
|
|
@@ -51,6 +53,7 @@ export const createMarkdownExtensions = (options: MarkdownBundleOptions = {}): E
|
|
51
53
|
extensions: [
|
52
54
|
// GFM provided by default.
|
53
55
|
markdownTagsExtensions,
|
56
|
+
...(options.extensions ?? []),
|
54
57
|
],
|
55
58
|
}),
|
56
59
|
|
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
import { syntaxTree } from '@codemirror/language';
|
6
6
|
import { type ChangeSpec, Transaction } from '@codemirror/state';
|
7
|
-
import { ViewPlugin, type ViewUpdate
|
7
|
+
import { type PluginValue, ViewPlugin, type ViewUpdate } from '@codemirror/view';
|
8
8
|
|
9
9
|
/**
|
10
10
|
* Monitors and augments changes.
|
@@ -3,20 +3,21 @@
|
|
3
3
|
//
|
4
4
|
|
5
5
|
import { syntaxTree } from '@codemirror/language';
|
6
|
-
import {
|
7
|
-
import {
|
6
|
+
import { type EditorState, RangeSetBuilder, StateEffect } from '@codemirror/state';
|
7
|
+
import { Decoration, type DecorationSet, EditorView, ViewPlugin, type ViewUpdate, WidgetType } from '@codemirror/view';
|
8
8
|
import { type SyntaxNodeRef } from '@lezer/common';
|
9
9
|
|
10
10
|
import { invariant } from '@dxos/invariant';
|
11
11
|
import { mx } from '@dxos/react-ui-theme';
|
12
12
|
|
13
|
+
import { type HeadingLevel, theme } from '../../styles';
|
14
|
+
import { type RenderCallback } from '../../types';
|
15
|
+
import { wrapWithCatch } from '../../util';
|
16
|
+
|
13
17
|
import { adjustChanges } from './changes';
|
14
18
|
import { image } from './image';
|
15
|
-
import {
|
19
|
+
import { bulletListIndentationWidth, formattingStyles, orderedListIndentationWidth } from './styles';
|
16
20
|
import { table } from './table';
|
17
|
-
import { theme, type HeadingLevel } from '../../styles';
|
18
|
-
import { type RenderCallback } from '../../types';
|
19
|
-
import { wrapWithCatch } from '../../util';
|
20
21
|
|
21
22
|
/**
|
22
23
|
* Unicode characters.
|
@@ -7,21 +7,21 @@ import { EditorState, type StateCommand } from '@codemirror/state';
|
|
7
7
|
import { describe, expect, test } from 'vitest';
|
8
8
|
|
9
9
|
import {
|
10
|
+
type Formatting,
|
11
|
+
Inline,
|
12
|
+
List,
|
10
13
|
addBlockquote,
|
11
14
|
addCodeblock,
|
12
15
|
addLink,
|
13
16
|
addList,
|
14
17
|
addStyle,
|
15
18
|
getFormatting,
|
16
|
-
removeStyle,
|
17
|
-
removeLink,
|
18
|
-
removeList,
|
19
19
|
removeBlockquote,
|
20
20
|
removeCodeblock,
|
21
|
+
removeLink,
|
22
|
+
removeList,
|
23
|
+
removeStyle,
|
21
24
|
setHeading,
|
22
|
-
Inline,
|
23
|
-
List,
|
24
|
-
type Formatting,
|
25
25
|
} from './formatting';
|
26
26
|
|
27
27
|
export const emptyFormatting: Formatting = {
|
@@ -7,14 +7,14 @@ import { syntaxTree } from '@codemirror/language';
|
|
7
7
|
import {
|
8
8
|
type ChangeSpec,
|
9
9
|
EditorSelection,
|
10
|
-
type Extension,
|
11
10
|
type EditorState,
|
11
|
+
type Extension,
|
12
12
|
type Line,
|
13
13
|
type StateCommand,
|
14
14
|
type Text,
|
15
15
|
} from '@codemirror/state';
|
16
|
-
import { EditorView,
|
17
|
-
import { type
|
16
|
+
import { EditorView, type ViewUpdate, keymap } from '@codemirror/view';
|
17
|
+
import { type SyntaxNode, type SyntaxNodeRef } from '@lezer/common';
|
18
18
|
import { useCallback, useMemo } from 'react';
|
19
19
|
|
20
20
|
import { debounceAndThrottle } from '@dxos/async';
|
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
import { markdownLanguage } from '@codemirror/lang-markdown';
|
6
6
|
import { HighlightStyle } from '@codemirror/language';
|
7
|
-
import {
|
7
|
+
import { Tag, styleTags, tags } from '@lezer/highlight';
|
8
8
|
import { type MarkdownConfig, Table } from '@lezer/markdown';
|
9
9
|
|
10
10
|
import { fontBody, theme } from '../../styles';
|
@@ -2,7 +2,7 @@
|
|
2
2
|
// Copyright 2023 DXOS.org
|
3
3
|
//
|
4
4
|
|
5
|
-
import {
|
5
|
+
import { type CompletionContext, type CompletionResult, autocompletion } from '@codemirror/autocomplete';
|
6
6
|
import type { Extension } from '@codemirror/state';
|
7
7
|
|
8
8
|
import { log } from '@dxos/log';
|
@@ -6,11 +6,12 @@ import { EditorSelection, EditorState } from '@codemirror/state';
|
|
6
6
|
import { EditorView } from '@codemirror/view';
|
7
7
|
import { describe, test } from 'vitest';
|
8
8
|
|
9
|
-
import { indentItemLess, indentItemMore, moveItemDown, moveItemUp } from './commands';
|
10
|
-
import { listItemToString, outlinerTree, treeFacet } from './tree';
|
11
9
|
import { str } from '../../testing';
|
12
10
|
import { createMarkdownExtensions } from '../markdown';
|
13
11
|
|
12
|
+
import { indentItemLess, indentItemMore, moveItemDown, moveItemUp } from './commands';
|
13
|
+
import { listItemToString, outlinerTree, treeFacet } from './tree';
|
14
|
+
|
14
15
|
const lines = [
|
15
16
|
'- [ ] 1',
|
16
17
|
'- [ ] 2',
|
@@ -7,12 +7,13 @@ import { Decoration, type DecorationSet, EditorView, ViewPlugin, type ViewUpdate
|
|
7
7
|
|
8
8
|
import { mx } from '@dxos/react-ui-theme';
|
9
9
|
|
10
|
+
import { floatingMenu } from '../command';
|
11
|
+
import { decorateMarkdown } from '../markdown';
|
12
|
+
|
10
13
|
import { commands } from './commands';
|
11
14
|
import { editor } from './editor';
|
12
|
-
import { selectionCompartment,
|
15
|
+
import { selectionCompartment, selectionEquals, selectionFacet } from './selection';
|
13
16
|
import { outlinerTree, treeFacet } from './tree';
|
14
|
-
import { floatingMenu } from '../command';
|
15
|
-
import { decorateMarkdown } from '../markdown';
|
16
17
|
|
17
18
|
// ISSUES:
|
18
19
|
// TODO(burdon): Remove requirement for continuous lines to be indented (so that user's can't accidentally delete them and break the layout).
|
@@ -3,7 +3,7 @@
|
|
3
3
|
//
|
4
4
|
|
5
5
|
import { Compartment, type EditorState, Facet, type SelectionRange } from '@codemirror/state';
|
6
|
-
import { type
|
6
|
+
import { type Command, type EditorView } from '@codemirror/view';
|
7
7
|
|
8
8
|
import { treeFacet } from './tree';
|
9
9
|
|
@@ -6,10 +6,11 @@ import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
|
|
6
6
|
import { EditorState } from '@codemirror/state';
|
7
7
|
import { beforeEach, describe, test } from 'vitest';
|
8
8
|
|
9
|
-
import { outlinerTree, treeFacet, listItemToString, type Item } from './tree';
|
10
9
|
import { str } from '../../testing';
|
11
10
|
import { type Range } from '../../types';
|
12
11
|
|
12
|
+
import { type Item, listItemToString, outlinerTree, treeFacet } from './tree';
|
13
|
+
|
13
14
|
const lines = [
|
14
15
|
'- [ ] 1',
|
15
16
|
'- [ ] 2',
|
@@ -3,7 +3,7 @@
|
|
3
3
|
//
|
4
4
|
|
5
5
|
import { syntaxTree } from '@codemirror/language';
|
6
|
-
import {
|
6
|
+
import { type EditorState, type Extension, StateField, type Transaction } from '@codemirror/state';
|
7
7
|
import { Facet } from '@codemirror/state';
|
8
8
|
import { type SyntaxNode } from '@lezer/common';
|
9
9
|
|
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
import { EditorState, type EditorStateConfig, type Text } from '@codemirror/state';
|
6
6
|
import { EditorView } from '@codemirror/view';
|
7
|
-
import {
|
7
|
+
import { type TabsterTypes, useFocusableGroup } from '@fluentui/react-tabster';
|
8
8
|
import {
|
9
9
|
type DependencyList,
|
10
10
|
type KeyboardEventHandler,
|
@@ -17,9 +17,9 @@ import {
|
|
17
17
|
} from 'react';
|
18
18
|
|
19
19
|
import { log } from '@dxos/log';
|
20
|
-
import { getProviderValue, isNotFalsy
|
20
|
+
import { type MaybeProvider, getProviderValue, isNotFalsy } from '@dxos/util';
|
21
21
|
|
22
|
-
import { type EditorSelection,
|
22
|
+
import { type EditorSelection, createEditorStateTransaction, documentId, editorInputMode } from '../extensions';
|
23
23
|
import { debugDispatcher } from '../util';
|
24
24
|
|
25
25
|
let instanceCount = 0;
|