@dxos/react-ui-editor 0.8.3-staging.0fa589b → 0.8.4-main.1da679c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/chunk-22UMM3QJ.mjs +22 -0
- package/dist/lib/browser/chunk-22UMM3QJ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +2502 -1384
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +72 -2
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/browser/types/index.mjs +13 -0
- package/dist/lib/browser/types/index.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-YXYQPV6R.mjs +24 -0
- package/dist/lib/node-esm/chunk-YXYQPV6R.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +2504 -1387
- 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 +72 -2
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/lib/node-esm/types/index.mjs +14 -0
- package/dist/lib/node-esm/types/index.mjs.map +7 -0
- package/dist/types/src/components/{Popover → CommandMenu}/CommandMenu.d.ts +10 -6
- package/dist/types/src/components/CommandMenu/CommandMenu.d.ts.map +1 -0
- package/dist/types/src/components/CommandMenu/index.d.ts +2 -0
- package/dist/types/src/components/CommandMenu/index.d.ts.map +1 -0
- package/dist/types/src/components/Editor/Editor.d.ts +19 -0
- package/dist/types/src/components/Editor/Editor.d.ts.map +1 -0
- package/dist/types/src/components/Editor/index.d.ts +2 -0
- package/dist/types/src/components/Editor/index.d.ts.map +1 -0
- 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 +6 -5
- package/dist/types/src/components/EditorToolbar/util.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/view-mode.d.ts +1 -1
- package/dist/types/src/components/EditorToolbar/view-mode.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +2 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/defaults.d.ts.map +1 -1
- package/dist/types/src/extensions/autocomplete.d.ts +20 -7
- package/dist/types/src/extensions/autocomplete.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.stories.d.ts +36 -45
- package/dist/types/src/extensions/automerge/automerge.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/defs.d.ts +1 -1
- package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/sync.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/update-automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/autoscroll.d.ts +10 -0
- package/dist/types/src/extensions/autoscroll.d.ts.map +1 -0
- package/dist/types/src/extensions/blast.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/floating-menu.d.ts.map +1 -1
- package/dist/types/src/extensions/command/hint.d.ts +2 -7
- package/dist/types/src/extensions/command/hint.d.ts.map +1 -1
- package/dist/types/src/extensions/command/index.d.ts +1 -1
- package/dist/types/src/extensions/command/index.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 +7 -2
- package/dist/types/src/extensions/command/typeahead.d.ts.map +1 -1
- package/dist/types/src/extensions/command/useCommandMenu.d.ts +3 -4
- 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 +15 -1
- package/dist/types/src/extensions/factories.d.ts.map +1 -1
- package/dist/types/src/extensions/index.d.ts +2 -0
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/action.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/bundle.d.ts +8 -2
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/changes.d.ts +1 -1
- package/dist/types/src/extensions/markdown/changes.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/decorate.d.ts +9 -1
- package/dist/types/src/extensions/markdown/decorate.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/formatting.d.ts +1 -1
- package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/formatting.test.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/image.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/link.d.ts.map +1 -1
- package/dist/types/src/extensions/modes.d.ts +0 -7
- package/dist/types/src/extensions/modes.d.ts.map +1 -1
- package/dist/types/src/extensions/outliner/outliner.d.ts +1 -1
- package/dist/types/src/extensions/outliner/outliner.d.ts.map +1 -1
- package/dist/types/src/extensions/outliner/selection.d.ts.map +1 -1
- package/dist/types/src/extensions/outliner/tree.d.ts +2 -2
- package/dist/types/src/extensions/outliner/tree.d.ts.map +1 -1
- package/dist/types/src/extensions/preview/preview.d.ts +3 -6
- package/dist/types/src/extensions/preview/preview.d.ts.map +1 -1
- package/dist/types/src/extensions/tags/extended-markdown.d.ts +10 -0
- package/dist/types/src/extensions/tags/extended-markdown.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/extended-markdown.test.d.ts +2 -0
- package/dist/types/src/extensions/tags/extended-markdown.test.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/index.d.ts +4 -0
- package/dist/types/src/extensions/tags/index.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/streamer.d.ts +12 -0
- package/dist/types/src/extensions/tags/streamer.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/xml-tags.d.ts +71 -0
- package/dist/types/src/extensions/tags/xml-tags.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/xml-util.d.ts +10 -0
- package/dist/types/src/extensions/tags/xml-util.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.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 +11 -4
- 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 +40 -3
- 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/Tags.stories.d.ts +17 -0
- package/dist/types/src/stories/Tags.stories.d.ts.map +1 -0
- 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/PreviewPopover.d.ts +20 -0
- package/dist/types/src/testing/PreviewPopover.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +1 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts +1 -0
- package/dist/types/src/testing/util.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +28 -29
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +2 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/src/types/types.d.ts +21 -0
- package/dist/types/src/types/types.d.ts.map +1 -0
- package/dist/types/src/util/cursor.d.ts.map +1 -1
- package/dist/types/src/util/debug.d.ts +1 -1
- package/dist/types/src/util/debug.d.ts.map +1 -1
- package/dist/types/src/util/decorations.d.ts +4 -0
- package/dist/types/src/util/decorations.d.ts.map +1 -0
- package/dist/types/src/util/dom.d.ts +2 -12
- package/dist/types/src/util/dom.d.ts.map +1 -1
- package/dist/types/src/util/domino.d.ts +18 -0
- package/dist/types/src/util/domino.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +2 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/react.d.ts +1 -1
- package/dist/types/src/util/react.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +65 -55
- package/src/components/{Popover → CommandMenu}/CommandMenu.tsx +93 -26
- package/src/components/{Popover → CommandMenu}/index.ts +0 -2
- package/src/components/Editor/Editor.tsx +39 -0
- package/src/components/Editor/index.ts +5 -0
- package/src/components/EditorToolbar/EditorToolbar.tsx +40 -30
- package/src/components/EditorToolbar/blocks.ts +22 -25
- 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 +21 -9
- package/src/components/EditorToolbar/view-mode.ts +12 -7
- package/src/components/index.ts +2 -1
- package/src/defaults.ts +5 -2
- package/src/extensions/autocomplete.ts +204 -54
- package/src/extensions/automerge/automerge.stories.tsx +26 -17
- package/src/extensions/automerge/automerge.ts +4 -3
- package/src/extensions/automerge/defs.ts +1 -1
- package/src/extensions/automerge/sync.ts +1 -1
- package/src/extensions/automerge/update-automerge.ts +1 -1
- package/src/extensions/autoscroll.ts +157 -0
- package/src/extensions/awareness/awareness.ts +2 -2
- package/src/extensions/blast.ts +3 -16
- package/src/extensions/command/action.ts +1 -2
- package/src/extensions/command/command-menu.ts +7 -6
- package/src/extensions/command/command.ts +3 -3
- package/src/extensions/command/floating-menu.ts +10 -15
- package/src/extensions/command/hint.ts +2 -1
- package/src/extensions/command/index.ts +1 -1
- package/src/extensions/command/placeholder.ts +1 -1
- package/src/extensions/command/state.ts +4 -3
- package/src/extensions/command/typeahead.ts +28 -15
- package/src/extensions/command/useCommandMenu.ts +6 -9
- package/src/extensions/comments.ts +18 -13
- package/src/extensions/dnd.ts +1 -1
- package/src/extensions/factories.ts +22 -15
- package/src/extensions/folding.tsx +2 -2
- package/src/extensions/index.ts +2 -0
- package/src/extensions/markdown/action.ts +2 -1
- package/src/extensions/markdown/bundle.ts +25 -3
- package/src/extensions/markdown/changes.ts +1 -1
- package/src/extensions/markdown/decorate.ts +23 -14
- package/src/extensions/markdown/formatting.test.ts +7 -7
- package/src/extensions/markdown/formatting.ts +16 -14
- package/src/extensions/markdown/highlight.ts +1 -1
- package/src/extensions/markdown/image.ts +3 -4
- package/src/extensions/markdown/link.ts +3 -0
- package/src/extensions/markdown/table.ts +7 -1
- package/src/extensions/mention.ts +1 -1
- package/src/extensions/modes.ts +0 -9
- package/src/extensions/outliner/outliner.test.ts +3 -2
- package/src/extensions/outliner/outliner.ts +6 -5
- package/src/extensions/outliner/selection.ts +1 -1
- package/src/extensions/outliner/tree.test.ts +2 -1
- package/src/extensions/outliner/tree.ts +2 -2
- package/src/extensions/preview/preview.ts +59 -62
- package/src/extensions/tags/extended-markdown.test.ts +261 -0
- package/src/extensions/tags/extended-markdown.ts +78 -0
- package/src/extensions/tags/index.ts +7 -0
- package/src/extensions/tags/streamer.ts +244 -0
- package/src/extensions/tags/xml-tags.ts +335 -0
- package/src/extensions/tags/xml-util.ts +94 -0
- package/src/hooks/useTextEditor.ts +3 -15
- package/src/index.ts +1 -1
- package/src/stories/Command.stories.tsx +24 -31
- package/src/stories/CommandMenu.stories.tsx +29 -30
- package/src/stories/Comments.stories.tsx +10 -6
- package/src/stories/EditorToolbar.stories.tsx +10 -11
- package/src/stories/Experimental.stories.tsx +12 -8
- package/src/stories/Markdown.stories.tsx +21 -17
- package/src/stories/Outliner.stories.tsx +42 -30
- package/src/stories/Preview.stories.tsx +34 -33
- package/src/stories/Tags.stories.tsx +81 -0
- package/src/stories/TextEditor.stories.tsx +41 -35
- package/src/stories/components/EditorStory.tsx +9 -10
- package/src/styles/theme.ts +11 -10
- package/src/testing/PreviewPopover.tsx +78 -0
- package/src/testing/index.ts +1 -0
- package/src/testing/util.ts +2 -0
- package/src/translations.ts +5 -3
- package/src/types/index.ts +5 -0
- package/src/types/types.ts +32 -0
- package/src/util/cursor.ts +2 -1
- package/src/util/debug.ts +2 -2
- package/src/util/decorations.ts +21 -0
- package/src/util/dom.ts +5 -27
- package/src/util/domino.ts +51 -0
- package/src/util/index.ts +2 -0
- package/src/util/react.tsx +1 -1
- package/dist/lib/node/index.cjs +0 -7754
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/testing/index.cjs +0 -29
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/types/src/components/Popover/CommandMenu.d.ts.map +0 -1
- package/dist/types/src/components/Popover/RefDropdownMenu.d.ts +0 -21
- package/dist/types/src/components/Popover/RefDropdownMenu.d.ts.map +0 -1
- package/dist/types/src/components/Popover/RefPopover.d.ts +0 -34
- package/dist/types/src/components/Popover/RefPopover.d.ts.map +0 -1
- package/dist/types/src/components/Popover/index.d.ts +0 -4
- package/dist/types/src/components/Popover/index.d.ts.map +0 -1
- package/dist/types/src/types.d.ts +0 -14
- package/dist/types/src/types.d.ts.map +0 -1
- package/src/components/Popover/RefDropdownMenu.tsx +0 -79
- package/src/components/Popover/RefPopover.tsx +0 -99
- package/src/types.ts +0 -23
@@ -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
|
@@ -47,6 +48,7 @@ export const preventNewline = EditorState.transactionFilter.of((tr) => (tr.newDo
|
|
47
48
|
* https://codemirror.net/docs/extensions
|
48
49
|
* https://github.com/codemirror/basic-setup
|
49
50
|
* https://github.com/codemirror/basic-setup/blob/main/src/codemirror.ts
|
51
|
+
* https://github.com/codemirror/theme-one-dark
|
50
52
|
*/
|
51
53
|
export type BasicExtensionsOptions = {
|
52
54
|
allowMultipleSelections?: boolean;
|
@@ -82,8 +84,8 @@ const defaultBasicOptions: BasicExtensionsOptions = {
|
|
82
84
|
history: true,
|
83
85
|
keymap: 'standard',
|
84
86
|
lineWrapping: true,
|
85
|
-
search:
|
86
|
-
};
|
87
|
+
search: false,
|
88
|
+
} as const;
|
87
89
|
|
88
90
|
const keymaps: { [key: string]: readonly KeyBinding[] } = {
|
89
91
|
// https://codemirror.net/docs/ref/#commands.standardKeymap
|
@@ -93,7 +95,7 @@ const keymaps: { [key: string]: readonly KeyBinding[] } = {
|
|
93
95
|
};
|
94
96
|
|
95
97
|
export const createBasicExtensions = (_props?: BasicExtensionsOptions): Extension => {
|
96
|
-
const props
|
98
|
+
const props = defaultsDeep({}, _props, defaultBasicOptions);
|
97
99
|
return [
|
98
100
|
// NOTE: Doesn't catch errors in keymap functions.
|
99
101
|
EditorView.exceptionSink.of((err) => {
|
@@ -163,11 +165,19 @@ export type ThemeExtensionsOptions = {
|
|
163
165
|
};
|
164
166
|
};
|
165
167
|
|
166
|
-
const
|
168
|
+
export const grow: ThemeExtensionsOptions['slots'] = {
|
167
169
|
editor: {
|
168
|
-
className: '
|
170
|
+
className: 'is-full bs-full',
|
169
171
|
},
|
170
|
-
};
|
172
|
+
} as const;
|
173
|
+
|
174
|
+
export const fullWidth: ThemeExtensionsOptions['slots'] = {
|
175
|
+
editor: {
|
176
|
+
className: 'is-full',
|
177
|
+
},
|
178
|
+
} as const;
|
179
|
+
|
180
|
+
export const defaultThemeSlots = grow;
|
171
181
|
|
172
182
|
/**
|
173
183
|
* https://codemirror.net/examples/styling
|
@@ -175,23 +185,21 @@ const defaultThemeSlots = {
|
|
175
185
|
export const createThemeExtensions = ({
|
176
186
|
themeMode,
|
177
187
|
styles,
|
178
|
-
syntaxHighlighting:
|
188
|
+
syntaxHighlighting: syntaxHighlightingProps,
|
179
189
|
slots: _slots,
|
180
190
|
}: ThemeExtensionsOptions = {}): Extension => {
|
181
191
|
const slots = defaultsDeep({}, _slots, defaultThemeSlots);
|
182
192
|
return [
|
183
193
|
EditorView.darkTheme.of(themeMode === 'dark'),
|
184
194
|
EditorView.baseTheme(styles ? merge({}, defaultTheme, styles) : defaultTheme),
|
185
|
-
|
186
|
-
_syntaxHighlighting &&
|
187
|
-
(themeMode === 'dark' ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle)),
|
195
|
+
syntaxHighlightingProps && syntaxHighlighting(themeMode === 'dark' ? oneDarkHighlightStyle : defaultHighlightStyle),
|
188
196
|
slots.editor?.className && EditorView.editorAttributes.of({ class: slots.editor.className }),
|
189
197
|
slots.content?.className && EditorView.contentAttributes.of({ class: slots.content.className }),
|
190
198
|
slots.scroll?.className &&
|
191
199
|
ViewPlugin.fromClass(
|
192
200
|
class {
|
193
201
|
constructor(view: EditorView) {
|
194
|
-
view.scrollDOM.classList.add(slots.scroll.className);
|
202
|
+
view.scrollDOM.classList.add(...slots.scroll.className.split(/\s+/));
|
195
203
|
}
|
196
204
|
},
|
197
205
|
),
|
@@ -219,7 +227,6 @@ export const createDataExtensions = <T>({ id, text, space, identity }: DataExten
|
|
219
227
|
if (space && identity) {
|
220
228
|
const peerId = identity?.identityKey.toHex();
|
221
229
|
const hue = (identity?.profile?.data?.hue as HuePalette | undefined) ?? hexToHue(peerId ?? '0');
|
222
|
-
|
223
230
|
extensions.push(
|
224
231
|
awareness(
|
225
232
|
new SpaceAwarenessProvider({
|
@@ -227,9 +234,9 @@ export const createDataExtensions = <T>({ id, text, space, identity }: DataExten
|
|
227
234
|
channel: `awareness.${id}`,
|
228
235
|
peerId: identity.identityKey.toHex(),
|
229
236
|
info: {
|
230
|
-
displayName: identity.profile?.displayName ?? generateName(identity.identityKey.toHex()),
|
231
237
|
darkColor: `var(--dx-${hue}Cursor)`,
|
232
238
|
lightColor: `var(--dx-${hue}Cursor)`,
|
239
|
+
displayName: identity.profile?.displayName ?? generateName(identity.identityKey.toHex()),
|
233
240
|
},
|
234
241
|
}),
|
235
242
|
),
|
@@ -9,7 +9,7 @@ import React from 'react';
|
|
9
9
|
|
10
10
|
import { Icon } from '@dxos/react-ui';
|
11
11
|
|
12
|
-
import {
|
12
|
+
import { Domino, renderRoot } from '../util';
|
13
13
|
|
14
14
|
export type FoldingOptions = {};
|
15
15
|
|
@@ -26,7 +26,7 @@ export const folding = (_props: FoldingOptions = {}): Extension => [
|
|
26
26
|
foldGutter({
|
27
27
|
markerDOM: (open) => {
|
28
28
|
// TODO(burdon): Use sprite directly.
|
29
|
-
const el =
|
29
|
+
const el = Domino.of('div').classNames('flex h-full items-center').build();
|
30
30
|
return renderRoot(
|
31
31
|
el,
|
32
32
|
<Icon icon='ph--caret-right--bold' size={3} classNames={['mx-3 cursor-pointer', open && 'rotate-90']} />,
|
package/src/extensions/index.ts
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
|
5
5
|
export * from './annotations';
|
6
6
|
export * from './autocomplete';
|
7
|
+
export * from './autoscroll';
|
7
8
|
export * from './automerge';
|
8
9
|
export * from './awareness';
|
9
10
|
export * from './blast';
|
@@ -23,4 +24,5 @@ export * from './modes';
|
|
23
24
|
export * from './outliner';
|
24
25
|
export * from './preview';
|
25
26
|
export * from './selection';
|
27
|
+
export * from './tags';
|
26
28
|
export * from './typewriter';
|
@@ -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,20 +4,21 @@
|
|
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
|
-
import { type ThemeMode } from '@dxos/react-ui';
|
14
14
|
import { isNotFalsy } from '@dxos/util';
|
15
15
|
|
16
16
|
import { markdownHighlightStyle, markdownTagsExtensions } from './highlight';
|
17
17
|
|
18
18
|
export type MarkdownBundleOptions = {
|
19
|
-
|
19
|
+
extensions?: MarkdownConfig[];
|
20
20
|
indentWithTab?: boolean;
|
21
|
+
setextHeading?: boolean;
|
21
22
|
};
|
22
23
|
|
23
24
|
/**
|
@@ -51,6 +52,7 @@ export const createMarkdownExtensions = (options: MarkdownBundleOptions = {}): E
|
|
51
52
|
extensions: [
|
52
53
|
// GFM provided by default.
|
53
54
|
markdownTagsExtensions,
|
55
|
+
...(options.extensions ?? defaultExtensions()),
|
54
56
|
],
|
55
57
|
}),
|
56
58
|
|
@@ -69,3 +71,23 @@ export const createMarkdownExtensions = (options: MarkdownBundleOptions = {}): E
|
|
69
71
|
),
|
70
72
|
];
|
71
73
|
};
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Default customizations.
|
77
|
+
* https://github.com/lezer-parser/markdown/blob/main/src/markdown.ts
|
78
|
+
*/
|
79
|
+
export const defaultExtensions = (): MarkdownConfig[] => [noSetExtHeading, noHtml];
|
80
|
+
|
81
|
+
/**
|
82
|
+
* Remove SetextHeading (e.g., headings created from "---").
|
83
|
+
*/
|
84
|
+
const noSetExtHeading: MarkdownConfig = {
|
85
|
+
remove: ['SetextHeading'],
|
86
|
+
};
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Remove HTML and XML parsing.
|
90
|
+
*/
|
91
|
+
const noHtml: MarkdownConfig = {
|
92
|
+
remove: ['HTMLBlock', 'HTMLTag'],
|
93
|
+
};
|
@@ -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, Prec, 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.
|
@@ -233,7 +234,7 @@ const buildDecorations = (view: EditorView, options: DecorateOptions, focus: boo
|
|
233
234
|
const mark = node.node.firstChild!;
|
234
235
|
if (mark?.name === 'HeaderMark') {
|
235
236
|
const { from, to = 6 } = options.numberedHeadings ?? {};
|
236
|
-
const text =
|
237
|
+
const text = state.sliceDoc(node.from, node.to);
|
237
238
|
const len = text.match(/[#\s]+/)![0].length;
|
238
239
|
if (!from || level < from || level > to) {
|
239
240
|
atomicDeco.add(mark.from, mark.from + len, hide);
|
@@ -426,6 +427,9 @@ const buildDecorations = (view: EditorView, options: DecorateOptions, focus: boo
|
|
426
427
|
const editing = editingRange(state, node, focus);
|
427
428
|
if (urlNode && marks.length >= 2) {
|
428
429
|
const url = state.sliceDoc(urlNode.from, urlNode.to);
|
430
|
+
if (options.skip?.({ name: 'Link', url })) {
|
431
|
+
break;
|
432
|
+
}
|
429
433
|
if (!editing) {
|
430
434
|
atomicDeco.add(node.from, marks[0].to, hide);
|
431
435
|
}
|
@@ -493,15 +497,15 @@ const buildDecorations = (view: EditorView, options: DecorateOptions, focus: boo
|
|
493
497
|
tree.iterate({
|
494
498
|
from,
|
495
499
|
to,
|
496
|
-
enter: wrapWithCatch(enterNode),
|
497
|
-
leave: wrapWithCatch(leaveNode),
|
500
|
+
enter: wrapWithCatch(enterNode, 'decorate.enter'),
|
501
|
+
leave: wrapWithCatch(leaveNode, 'decorate.leave'),
|
498
502
|
});
|
499
503
|
}
|
500
504
|
} else {
|
501
505
|
// NOTE: If line numbering then we must iterate from the start of document.
|
502
506
|
tree.iterate({
|
503
|
-
enter: wrapWithCatch(enterNode),
|
504
|
-
leave: wrapWithCatch(leaveNode),
|
507
|
+
enter: wrapWithCatch(enterNode, 'decorate.enter'),
|
508
|
+
leave: wrapWithCatch(leaveNode, 'decorate.leave'),
|
505
509
|
});
|
506
510
|
}
|
507
511
|
|
@@ -513,15 +517,20 @@ const buildDecorations = (view: EditorView, options: DecorateOptions, focus: boo
|
|
513
517
|
|
514
518
|
const forceUpdate = StateEffect.define<null>();
|
515
519
|
|
520
|
+
export type NodeData = { name: 'Link'; url: string } | { name: 'Image'; url: string };
|
521
|
+
|
516
522
|
export interface DecorateOptions {
|
517
523
|
/**
|
518
524
|
* Prevents triggering decorations as the cursor moves through the document.
|
519
525
|
*/
|
520
526
|
selectionChangeDelay?: number;
|
521
527
|
numberedHeadings?: { from: number; to?: number };
|
522
|
-
renderLinkButton?: RenderCallback<{ url: string }>;
|
523
528
|
// TODO(burdon): Additional padding for each line.
|
524
529
|
listPaddingLeft?: number;
|
530
|
+
// TODO(burdon): Use consistently.
|
531
|
+
skip?: (node: NodeData) => boolean;
|
532
|
+
// TODO(burdon): Remove.
|
533
|
+
renderLinkButton?: RenderCallback<{ url: string }>;
|
525
534
|
}
|
526
535
|
|
527
536
|
export const decorateMarkdown = (options: DecorateOptions = {}) => {
|
@@ -577,9 +586,9 @@ export const decorateMarkdown = (options: DecorateOptions = {}) => {
|
|
577
586
|
},
|
578
587
|
{
|
579
588
|
provide: (plugin) => [
|
580
|
-
EditorView.
|
589
|
+
Prec.low(EditorView.decorations.of((view) => view.plugin(plugin)?.deco ?? Decoration.none)),
|
581
590
|
EditorView.decorations.of((view) => view.plugin(plugin)?.atomicDeco ?? Decoration.none),
|
582
|
-
EditorView.
|
591
|
+
EditorView.atomicRanges.of((view) => view.plugin(plugin)?.atomicDeco ?? Decoration.none),
|
583
592
|
],
|
584
593
|
},
|
585
594
|
),
|
@@ -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 = {
|
@@ -182,7 +182,7 @@ describe('removeStyle', () => {
|
|
182
182
|
|
183
183
|
testCommand('can remove code style', 'a `{variable}`', code, 'a {variable}');
|
184
184
|
|
185
|
-
// TODO(dmaretskyi): Flaky on CI
|
185
|
+
// TODO(dmaretskyi): Flaky on CI.
|
186
186
|
// testCommand(
|
187
187
|
// 'can remove emphasis across multiple blocks',
|
188
188
|
// '{*one*\n\n# *two*\n\n> 1. *three} four*\n',
|
@@ -7,16 +7,17 @@ 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, keymap } from '@codemirror/view';
|
17
|
-
import { type
|
18
|
-
import { useMemo } from 'react';
|
16
|
+
import { EditorView, type ViewUpdate, keymap } from '@codemirror/view';
|
17
|
+
import { type SyntaxNode, type SyntaxNodeRef } from '@lezer/common';
|
18
|
+
import { useCallback, useMemo } from 'react';
|
19
19
|
|
20
|
+
import { debounceAndThrottle } from '@dxos/async';
|
20
21
|
import { type Live } from '@dxos/live-object';
|
21
22
|
|
22
23
|
import { type EditorToolbarState } from '../../components';
|
@@ -1251,15 +1252,16 @@ export const getFormatting = (state: EditorState): Formatting => {
|
|
1251
1252
|
* Hook provides an extension to compute the current formatting state.
|
1252
1253
|
*/
|
1253
1254
|
export const useFormattingState = (state: Live<EditorToolbarState>): Extension => {
|
1254
|
-
|
1255
|
-
() =>
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
[],
|
1255
|
+
const handleUpdate = useCallback(
|
1256
|
+
debounceAndThrottle((update: ViewUpdate) => {
|
1257
|
+
if (update.docChanged || update.selectionSet) {
|
1258
|
+
Object.entries(getFormatting(update.state)).forEach(([key, active]) => {
|
1259
|
+
state[key as keyof Formatting] = active as any;
|
1260
|
+
});
|
1261
|
+
}
|
1262
|
+
}, 100),
|
1263
|
+
[state],
|
1264
1264
|
);
|
1265
|
+
|
1266
|
+
return useMemo(() => EditorView.updateListener.of(handleUpdate), [handleUpdate]);
|
1265
1267
|
};
|
@@ -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';
|
@@ -17,8 +17,7 @@ export const image = (_options: ImageOptions = {}): Extension => {
|
|
17
17
|
return [
|
18
18
|
StateField.define<DecorationSet>({
|
19
19
|
create: (state) => {
|
20
|
-
|
21
|
-
return Decoration.set(buildDecorations(0, state.doc.length, state));
|
20
|
+
return Decoration.set(buildDecorations(state, 0, state.doc.length));
|
22
21
|
},
|
23
22
|
update: (value: DecorationSet, tr: Transaction) => {
|
24
23
|
if (!tr.docChanged && !tr.selection) {
|
@@ -43,7 +42,7 @@ export const image = (_options: ImageOptions = {}): Extension => {
|
|
43
42
|
filterFrom: from,
|
44
43
|
filterTo: to,
|
45
44
|
filter: () => false,
|
46
|
-
add: buildDecorations(from, to
|
45
|
+
add: buildDecorations(tr.state, from, to),
|
47
46
|
});
|
48
47
|
},
|
49
48
|
provide: (field) => EditorView.decorations.from(field),
|
@@ -51,7 +50,7 @@ export const image = (_options: ImageOptions = {}): Extension => {
|
|
51
50
|
];
|
52
51
|
};
|
53
52
|
|
54
|
-
const buildDecorations = (
|
53
|
+
const buildDecorations = (state: EditorState, from: number, to: number) => {
|
55
54
|
const decorations: Range<Decoration>[] = [];
|
56
55
|
const cursor = state.selection.main.head;
|
57
56
|
syntaxTree(state).iterate({
|
@@ -94,7 +94,13 @@ const update = (state: EditorState, _options: TableOptions) => {
|
|
94
94
|
} else {
|
95
95
|
// Add class for styling.
|
96
96
|
// TODO(burdon): Apply to each line?
|
97
|
-
builder.add(
|
97
|
+
builder.add(
|
98
|
+
table.from,
|
99
|
+
table.to,
|
100
|
+
Decoration.mark({
|
101
|
+
class: 'cm-table',
|
102
|
+
}),
|
103
|
+
);
|
98
104
|
}
|
99
105
|
});
|
100
106
|
|
@@ -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';
|
package/src/extensions/modes.ts
CHANGED
@@ -6,18 +6,9 @@ import { type Extension } from '@codemirror/state';
|
|
6
6
|
import { keymap } from '@codemirror/view';
|
7
7
|
import { vim } from '@replit/codemirror-vim';
|
8
8
|
import { vscodeKeymap } from '@replit/codemirror-vscode-keymap';
|
9
|
-
import { Schema } from 'effect';
|
10
9
|
|
11
10
|
import { singleValueFacet } from '../util';
|
12
11
|
|
13
|
-
export const EditorViewModes = ['preview', 'readonly', 'source'] as const;
|
14
|
-
export const EditorViewMode = Schema.Union(...EditorViewModes.map((mode) => Schema.Literal(mode)));
|
15
|
-
export type EditorViewMode = Schema.Schema.Type<typeof EditorViewMode>;
|
16
|
-
|
17
|
-
export const EditorInputModes = ['default', 'vim', 'vscode'] as const;
|
18
|
-
export const EditorInputMode = Schema.Union(...EditorInputModes.map((mode) => Schema.Literal(mode)));
|
19
|
-
export type EditorInputMode = Schema.Schema.Type<typeof EditorInputMode>;
|
20
|
-
|
21
12
|
export type EditorInputConfig = {
|
22
13
|
type?: string;
|
23
14
|
noTabster?: boolean;
|
@@ -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).
|
@@ -37,7 +38,7 @@ export type OutlinerProps = {};
|
|
37
38
|
* - Constrains editor to outline structure.
|
38
39
|
* - Supports smart cut-and-paste.
|
39
40
|
*/
|
40
|
-
export const outliner = (
|
41
|
+
export const outliner = (_options: OutlinerProps = {}): Extension => [
|
41
42
|
// Commands.
|
42
43
|
Prec.highest(commands()),
|
43
44
|
|
@@ -158,7 +159,7 @@ const decorations = () => [
|
|
158
159
|
'.cm-list-item-focused': {
|
159
160
|
borderColor: 'var(--dx-accentFocusIndicator)',
|
160
161
|
},
|
161
|
-
'
|
162
|
+
'&:focus-within .cm-list-item-selected': {
|
162
163
|
borderColor: 'var(--dx-separator)',
|
163
164
|
},
|
164
165
|
}),
|
@@ -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
|
|
@@ -195,7 +195,7 @@ export type TreeOptions = {};
|
|
195
195
|
* This adds overhead relative to the markdown AST, but allows for efficient traversal of the list items.
|
196
196
|
* NOTE: Requires markdown parser to be enabled.
|
197
197
|
*/
|
198
|
-
export const outlinerTree = (
|
198
|
+
export const outlinerTree = (_options: TreeOptions = {}): Extension => {
|
199
199
|
const buildTree = (state: EditorState): Tree => {
|
200
200
|
let tree: Tree | undefined;
|
201
201
|
let parent: Item | undefined;
|