@dxos/react-ui-editor 0.8.2-main.fbd8ed0 → 0.8.2-staging.4d6ad0f
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 +1731 -926
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +3 -64
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/index.cjs +1912 -1111
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +3 -75
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/lib/node-esm/index.mjs +1731 -926
- 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 +3 -64
- package/dist/lib/node-esm/testing/index.mjs.map +4 -4
- package/dist/types/src/components/EditorToolbar/EditorToolbar.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/util.d.ts +4 -6
- package/dist/types/src/components/EditorToolbar/util.d.ts.map +1 -1
- package/dist/types/src/components/Popover/RefDropdownMenu.d.ts +21 -0
- package/dist/types/src/components/Popover/RefDropdownMenu.d.ts.map +1 -0
- package/dist/types/src/{testing → components/Popover}/RefPopover.d.ts +1 -1
- package/dist/types/src/components/Popover/RefPopover.d.ts.map +1 -0
- package/dist/types/src/components/Popover/index.d.ts +3 -0
- package/dist/types/src/components/Popover/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/defaults.d.ts +2 -5
- package/dist/types/src/defaults.d.ts.map +1 -1
- package/dist/types/src/extensions/annotations.d.ts +4 -1
- package/dist/types/src/extensions/annotations.d.ts.map +1 -1
- package/dist/types/src/extensions/autocomplete.d.ts +1 -2
- package/dist/types/src/extensions/autocomplete.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/sync.d.ts.map +1 -1
- package/dist/types/src/extensions/awareness/awareness-provider.d.ts.map +1 -1
- package/dist/types/src/extensions/awareness/awareness.d.ts.map +1 -1
- package/dist/types/src/extensions/command/command.d.ts +1 -2
- package/dist/types/src/extensions/command/command.d.ts.map +1 -1
- package/dist/types/src/extensions/command/hint.d.ts +14 -2
- package/dist/types/src/extensions/command/hint.d.ts.map +1 -1
- package/dist/types/src/extensions/command/index.d.ts +2 -0
- package/dist/types/src/extensions/command/index.d.ts.map +1 -1
- package/dist/types/src/extensions/command/menu.d.ts +7 -8
- package/dist/types/src/extensions/command/menu.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 +17 -0
- package/dist/types/src/extensions/command/typeahead.d.ts.map +1 -0
- package/dist/types/src/extensions/comments.d.ts +2 -12
- package/dist/types/src/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/extensions/factories.d.ts +4 -0
- 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/json.d.ts +7 -0
- package/dist/types/src/extensions/json.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/{editorAction.d.ts → action.d.ts} +1 -1
- package/dist/types/src/extensions/markdown/action.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/bundle.d.ts +2 -1
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/index.d.ts +1 -2
- package/dist/types/src/extensions/markdown/index.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/styles.d.ts.map +1 -1
- package/dist/types/src/extensions/outliner/commands.d.ts +9 -0
- package/dist/types/src/extensions/outliner/commands.d.ts.map +1 -0
- package/dist/types/src/extensions/outliner/editor.d.ts +5 -0
- package/dist/types/src/extensions/outliner/editor.d.ts.map +1 -0
- package/dist/types/src/extensions/outliner/editor.test.d.ts +2 -0
- package/dist/types/src/extensions/outliner/editor.test.d.ts.map +1 -0
- package/dist/types/src/extensions/outliner/index.d.ts +3 -0
- package/dist/types/src/extensions/outliner/index.d.ts.map +1 -0
- package/dist/types/src/extensions/outliner/outliner.d.ts +10 -0
- package/dist/types/src/extensions/outliner/outliner.d.ts.map +1 -0
- package/dist/types/src/extensions/outliner/outliner.test.d.ts +2 -0
- package/dist/types/src/extensions/outliner/outliner.test.d.ts.map +1 -0
- package/dist/types/src/extensions/outliner/selection.d.ts +12 -0
- package/dist/types/src/extensions/outliner/selection.d.ts.map +1 -0
- package/dist/types/src/extensions/outliner/tree.d.ts +79 -0
- package/dist/types/src/extensions/outliner/tree.d.ts.map +1 -0
- package/dist/types/src/extensions/outliner/tree.test.d.ts +2 -0
- package/dist/types/src/extensions/outliner/tree.test.d.ts.map +1 -0
- package/dist/types/src/stories/Command.stories.d.ts +7 -0
- package/dist/types/src/stories/Command.stories.d.ts.map +1 -0
- package/dist/types/src/stories/{TextEditorComments.stories.d.ts → Comments.stories.d.ts} +3 -3
- package/dist/types/src/stories/Comments.stories.d.ts.map +1 -0
- package/dist/types/src/stories/EditorToolbar.stories.d.ts +12 -0
- package/dist/types/src/stories/EditorToolbar.stories.d.ts.map +1 -0
- package/dist/types/src/stories/{TextEditorSpecial.stories.d.ts → Experimental.stories.d.ts} +3 -6
- package/dist/types/src/stories/Experimental.stories.d.ts.map +1 -0
- package/dist/types/src/stories/Markdown.stories.d.ts +46 -0
- package/dist/types/src/stories/Markdown.stories.d.ts.map +1 -0
- package/dist/types/src/stories/Outliner.stories.d.ts +26 -0
- package/dist/types/src/stories/Outliner.stories.d.ts.map +1 -0
- package/dist/types/src/stories/Preview.stories.d.ts +10 -0
- package/dist/types/src/stories/Preview.stories.d.ts.map +1 -0
- package/dist/types/src/stories/{TextEditorBasic.stories.d.ts → TextEditor.stories.d.ts} +9 -39
- package/dist/types/src/stories/TextEditor.stories.d.ts.map +1 -0
- package/dist/types/src/stories/{story-utils.d.ts → util.d.ts} +6 -6
- package/dist/types/src/stories/util.d.ts.map +1 -0
- package/dist/types/src/styles/theme.d.ts.map +1 -1
- package/dist/types/src/styles/tokens.d.ts.map +1 -1
- package/dist/types/src/testing/index.d.ts +1 -1
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts +2 -0
- package/dist/types/src/testing/util.d.ts.map +1 -0
- package/package.json +40 -34
- package/src/components/EditorToolbar/EditorToolbar.tsx +81 -57
- package/src/components/EditorToolbar/index.ts +7 -1
- package/src/components/EditorToolbar/util.ts +3 -4
- package/src/components/Popover/RefDropdownMenu.tsx +77 -0
- package/src/{testing → components/Popover}/RefPopover.tsx +5 -4
- package/src/components/Popover/index.ts +6 -0
- package/src/components/index.ts +1 -0
- package/src/defaults.ts +10 -13
- package/src/extensions/annotations.ts +41 -64
- package/src/extensions/autocomplete.ts +5 -6
- package/src/extensions/automerge/automerge.stories.tsx +2 -7
- package/src/extensions/automerge/automerge.test.tsx +3 -2
- package/src/extensions/automerge/sync.ts +3 -3
- package/src/extensions/awareness/awareness-provider.ts +4 -4
- package/src/extensions/awareness/awareness.ts +7 -7
- package/src/extensions/blast.ts +9 -9
- package/src/extensions/command/command.ts +1 -3
- package/src/extensions/command/hint.ts +7 -7
- package/src/extensions/command/index.ts +2 -0
- package/src/extensions/command/menu.ts +43 -49
- package/src/extensions/command/typeahead.ts +116 -0
- package/src/extensions/comments.ts +4 -69
- package/src/extensions/factories.ts +13 -0
- package/src/extensions/index.ts +2 -0
- package/src/extensions/json.ts +56 -0
- package/src/extensions/markdown/bundle.ts +13 -9
- package/src/extensions/markdown/decorate.ts +7 -7
- package/src/extensions/markdown/image.ts +2 -2
- package/src/extensions/markdown/index.ts +1 -2
- package/src/extensions/markdown/styles.ts +2 -1
- package/src/extensions/markdown/table.ts +3 -3
- package/src/extensions/outliner/commands.ts +242 -0
- package/src/extensions/outliner/editor.test.ts +33 -0
- package/src/extensions/outliner/editor.ts +180 -0
- package/src/extensions/outliner/index.ts +6 -0
- package/src/extensions/outliner/outliner.test.ts +99 -0
- package/src/extensions/outliner/outliner.ts +162 -0
- package/src/extensions/outliner/selection.ts +50 -0
- package/src/extensions/outliner/tree.test.ts +164 -0
- package/src/extensions/outliner/tree.ts +315 -0
- package/src/extensions/preview/preview.ts +5 -5
- package/src/stories/Command.stories.tsx +97 -0
- package/src/stories/{TextEditorComments.stories.tsx → Comments.stories.tsx} +13 -14
- package/src/{components/EditorToolbar → stories}/EditorToolbar.stories.tsx +26 -20
- package/src/stories/{TextEditorSpecial.stories.tsx → Experimental.stories.tsx} +9 -30
- package/src/stories/Markdown.stories.tsx +121 -0
- package/src/stories/Outliner.stories.tsx +108 -0
- package/src/stories/{TextEditorPreview.stories.tsx → Preview.stories.tsx} +46 -136
- package/src/stories/TextEditor.stories.tsx +256 -0
- package/src/stories/{story-utils.tsx → util.tsx} +21 -22
- package/src/styles/theme.ts +12 -5
- package/src/styles/tokens.ts +1 -2
- package/src/testing/index.ts +1 -1
- package/src/testing/util.ts +5 -0
- package/dist/types/src/components/EditorToolbar/EditorToolbar.stories.d.ts +0 -53
- package/dist/types/src/components/EditorToolbar/EditorToolbar.stories.d.ts.map +0 -1
- package/dist/types/src/components/EditorToolbar/comment.d.ts +0 -18
- package/dist/types/src/components/EditorToolbar/comment.d.ts.map +0 -1
- package/dist/types/src/extensions/markdown/editorAction.d.ts.map +0 -1
- package/dist/types/src/extensions/markdown/outliner.d.ts +0 -12
- package/dist/types/src/extensions/markdown/outliner.d.ts.map +0 -1
- package/dist/types/src/stories/TextEditorBasic.stories.d.ts.map +0 -1
- package/dist/types/src/stories/TextEditorComments.stories.d.ts.map +0 -1
- package/dist/types/src/stories/TextEditorPreview.stories.d.ts +0 -13
- package/dist/types/src/stories/TextEditorPreview.stories.d.ts.map +0 -1
- package/dist/types/src/stories/TextEditorSpecial.stories.d.ts.map +0 -1
- package/dist/types/src/stories/story-utils.d.ts.map +0 -1
- package/dist/types/src/testing/RefPopover.d.ts.map +0 -1
- package/src/components/EditorToolbar/comment.ts +0 -30
- package/src/extensions/markdown/outliner.ts +0 -235
- package/src/stories/TextEditorBasic.stories.tsx +0 -333
- /package/src/extensions/markdown/{editorAction.ts → action.ts} +0 -0
@@ -5,7 +5,7 @@
|
|
5
5
|
import { type Completion } from '@codemirror/autocomplete';
|
6
6
|
import { type Extension } from '@codemirror/state';
|
7
7
|
import { type EditorView } from '@codemirror/view';
|
8
|
-
import React, { useEffect, useState, type FC } from 'react';
|
8
|
+
import React, { type ReactNode, useEffect, useState, type FC } from 'react';
|
9
9
|
|
10
10
|
import { Expando } from '@dxos/echo-schema';
|
11
11
|
import { PublicKey } from '@dxos/keys';
|
@@ -13,9 +13,10 @@ import { live } from '@dxos/live-object';
|
|
13
13
|
import { faker } from '@dxos/random';
|
14
14
|
import { createDocAccessor, createObject } from '@dxos/react-client/echo';
|
15
15
|
import { useThemeContext, Icon } from '@dxos/react-ui';
|
16
|
+
import { JsonFilter } from '@dxos/react-ui-syntax-highlighter';
|
16
17
|
import { mx } from '@dxos/react-ui-theme';
|
17
18
|
|
18
|
-
import {
|
19
|
+
import { editorSlots, editorGutter } from '../defaults';
|
19
20
|
import {
|
20
21
|
type DebugNode,
|
21
22
|
type EditorSelectionState,
|
@@ -30,13 +31,12 @@ import {
|
|
30
31
|
image,
|
31
32
|
linkTooltip,
|
32
33
|
table,
|
34
|
+
type ThemeExtensionsOptions,
|
33
35
|
} from '../extensions';
|
34
36
|
import { useTextEditor, type UseTextEditorProps } from '../hooks';
|
37
|
+
import { str } from '../testing';
|
35
38
|
import { createRenderer } from '../util';
|
36
39
|
|
37
|
-
// Utility functions
|
38
|
-
export const str = (...lines: string[]) => lines.join('\n');
|
39
|
-
|
40
40
|
export const num = () => faker.number.int({ min: 0, max: 9999 }).toLocaleString();
|
41
41
|
|
42
42
|
export const img = '';
|
@@ -251,24 +251,28 @@ export type DebugMode = 'raw' | 'tree' | 'raw+tree';
|
|
251
251
|
export type StoryProps = {
|
252
252
|
id?: string;
|
253
253
|
debug?: DebugMode;
|
254
|
+
debugCustom?: (view: EditorView) => ReactNode;
|
254
255
|
text?: string;
|
255
256
|
readOnly?: boolean;
|
256
257
|
placeholder?: string;
|
257
258
|
lineNumbers?: boolean;
|
258
259
|
onReady?: (view: EditorView) => void;
|
259
|
-
} & Pick<UseTextEditorProps, 'scrollTo' | 'selection' | 'extensions'
|
260
|
+
} & Pick<UseTextEditorProps, 'scrollTo' | 'selection' | 'extensions'> &
|
261
|
+
Pick<ThemeExtensionsOptions, 'slots'>;
|
260
262
|
|
261
263
|
// Default story component
|
262
|
-
export const
|
264
|
+
export const EditorStory = ({
|
263
265
|
id = 'editor-' + PublicKey.random().toHex().slice(0, 8),
|
264
266
|
debug,
|
267
|
+
debugCustom,
|
265
268
|
text,
|
266
|
-
extensions,
|
267
269
|
readOnly,
|
268
270
|
placeholder = 'New document.',
|
271
|
+
lineNumbers,
|
269
272
|
scrollTo,
|
270
273
|
selection,
|
271
|
-
|
274
|
+
extensions,
|
275
|
+
slots = editorSlots,
|
272
276
|
onReady,
|
273
277
|
}: StoryProps) => {
|
274
278
|
const [object] = useState(createObject(live(Expando, { content: text ?? '' })));
|
@@ -285,11 +289,7 @@ export const DefaultStory = ({
|
|
285
289
|
createThemeExtensions({
|
286
290
|
themeMode,
|
287
291
|
syntaxHighlighting: true,
|
288
|
-
slots
|
289
|
-
content: {
|
290
|
-
className: editorContent,
|
291
|
-
},
|
292
|
-
},
|
292
|
+
slots,
|
293
293
|
}),
|
294
294
|
editorGutter,
|
295
295
|
extensions || [],
|
@@ -308,18 +308,17 @@ export const DefaultStory = ({
|
|
308
308
|
}, [view]);
|
309
309
|
|
310
310
|
return (
|
311
|
-
<div className='
|
312
|
-
<div role='none' className='flex
|
311
|
+
<div className={mx('w-full h-full grid overflow-hidden', debug && 'grid-cols-[1fr_600px]')}>
|
312
|
+
<div role='none' className='flex overflow-hidden' ref={parentRef} {...focusAttributes} />
|
313
313
|
{debug && (
|
314
|
-
<div className='
|
314
|
+
<div className='grid h-full auto-rows-fr border-l border-separator divide-y divide-separator overflow-hidden'>
|
315
|
+
{view && debugCustom?.(view)}
|
315
316
|
{(debug === 'raw' || debug === 'raw+tree') && (
|
316
|
-
<pre className='p-1
|
317
|
-
|
318
|
-
{(debug === 'tree' || debug === 'raw+tree') && (
|
319
|
-
<pre className='p-1 font-mono text-xs text-green-800 dark:text-green-200'>
|
320
|
-
{JSON.stringify(tree, null, 2)}
|
317
|
+
<pre className='p-1 text-xs text-green-800 dark:text-green-200 overflow-auto'>
|
318
|
+
{view?.state.doc.toString()}
|
321
319
|
</pre>
|
322
320
|
)}
|
321
|
+
{(debug === 'tree' || debug === 'raw+tree') && <JsonFilter data={tree} classNames='p-1 text-xs' />}
|
323
322
|
</div>
|
324
323
|
)}
|
325
324
|
</div>
|
package/src/styles/theme.ts
CHANGED
@@ -167,18 +167,25 @@ export const defaultTheme: ThemeStyles = {
|
|
167
167
|
'.cm-tooltip.cm-tooltip-autocomplete': {
|
168
168
|
marginTop: '4px',
|
169
169
|
marginLeft: '-3px',
|
170
|
+
borderColor: 'var(--dx-separator)',
|
171
|
+
borderTop: 'none',
|
170
172
|
},
|
171
173
|
'.cm-tooltip.cm-tooltip-autocomplete > ul': {
|
172
174
|
maxHeight: '20em',
|
173
175
|
},
|
174
|
-
'.cm-tooltip.cm-tooltip-autocomplete > ul > li': {
|
175
|
-
|
176
|
+
'.cm-tooltip.cm-tooltip-autocomplete > ul > li': {
|
177
|
+
padding: '4px',
|
178
|
+
},
|
179
|
+
'.cm-tooltip.cm-tooltip-autocomplete > ul > li[aria-selected]': {
|
180
|
+
background: 'var(--dx-hoverSurface)',
|
181
|
+
},
|
176
182
|
'.cm-tooltip.cm-tooltip-autocomplete > ul > completion-section': {
|
177
183
|
paddingLeft: '4px !important',
|
178
184
|
borderBottom: 'none !important',
|
179
185
|
color: 'var(--dx-accentText)',
|
180
186
|
},
|
181
|
-
|
187
|
+
|
188
|
+
'.cm-completionInfo': {
|
182
189
|
width: '360px !important',
|
183
190
|
margin: '-10px 1px 0 1px',
|
184
191
|
padding: '8px !important',
|
@@ -229,7 +236,7 @@ export const defaultTheme: ThemeStyles = {
|
|
229
236
|
backgroundColor: 'var(--dx-input)',
|
230
237
|
},
|
231
238
|
'.cm-panel input:focus, .cm-panel button:focus': {
|
232
|
-
outline: '1px solid var(--dx-
|
239
|
+
outline: '1px solid var(--dx-neutralFocusIndicator)',
|
233
240
|
},
|
234
241
|
'.cm-panel label': {
|
235
242
|
display: 'inline-flex',
|
@@ -242,7 +249,7 @@ export const defaultTheme: ThemeStyles = {
|
|
242
249
|
height: '8px',
|
243
250
|
marginRight: '6px !important',
|
244
251
|
padding: '2px !important',
|
245
|
-
color: 'var(--dx-
|
252
|
+
color: 'var(--dx-neutralFocusIndicator)',
|
246
253
|
},
|
247
254
|
'.cm-panel button': {
|
248
255
|
'&:hover': {
|
package/src/styles/tokens.ts
CHANGED
package/src/testing/index.ts
CHANGED
@@ -1,53 +0,0 @@
|
|
1
|
-
import '@dxos-theme';
|
2
|
-
import React from 'react';
|
3
|
-
import { type UseTextEditorProps } from '../../hooks';
|
4
|
-
type StoryProps = {
|
5
|
-
placeholder?: string;
|
6
|
-
} & UseTextEditorProps;
|
7
|
-
export declare const Default: {
|
8
|
-
args: {
|
9
|
-
autoFocus: boolean;
|
10
|
-
placeholder: string;
|
11
|
-
initialValue: string;
|
12
|
-
};
|
13
|
-
};
|
14
|
-
declare const _default: {
|
15
|
-
title: string;
|
16
|
-
render: ({ autoFocus, initialValue, placeholder }: StoryProps) => React.JSX.Element;
|
17
|
-
decorators: import("@storybook/react").Decorator[];
|
18
|
-
parameters: {
|
19
|
-
translations: {
|
20
|
-
'en-US': {
|
21
|
-
"react-ui-editor": {
|
22
|
-
'strong label': string;
|
23
|
-
'emphasis label': string;
|
24
|
-
'strikethrough label': string;
|
25
|
-
'code label': string;
|
26
|
-
'link label': string;
|
27
|
-
'list-bullet label': string;
|
28
|
-
'list-ordered label': string;
|
29
|
-
'list-task label': string;
|
30
|
-
'blockquote label': string;
|
31
|
-
'codeblock label': string;
|
32
|
-
'comment label': string;
|
33
|
-
'selection overlaps existing comment label': string;
|
34
|
-
'select text to comment label': string;
|
35
|
-
'image label': string;
|
36
|
-
'heading label': string;
|
37
|
-
'table label': string;
|
38
|
-
'heading level label_zero': string;
|
39
|
-
'heading level label_one': string;
|
40
|
-
'heading level label_other': string;
|
41
|
-
'view mode label': string;
|
42
|
-
'preview mode label': string;
|
43
|
-
'readonly mode label': string;
|
44
|
-
'search label': string;
|
45
|
-
'source mode label': string;
|
46
|
-
};
|
47
|
-
};
|
48
|
-
}[];
|
49
|
-
layout: string;
|
50
|
-
};
|
51
|
-
};
|
52
|
-
export default _default;
|
53
|
-
//# sourceMappingURL=EditorToolbar.stories.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"EditorToolbar.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/EditorToolbar/EditorToolbar.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,KAAgC,MAAM,OAAO,CAAC;AAmBrD,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGrE,KAAK,UAAU,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,kBAAkB,CAAC;AAgDhE,eAAO,MAAM,OAAO;;;;;;CAMnB,CAAC;;;uDApD8D,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsD1E,wBAKE"}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import { type EditorView } from '@codemirror/view';
|
2
|
-
import { type EditorToolbarState } from './util';
|
3
|
-
export declare const createComment: (state: EditorToolbarState, getView: () => EditorView) => {
|
4
|
-
nodes: Readonly<Omit<Readonly<{
|
5
|
-
id: string;
|
6
|
-
type: string;
|
7
|
-
cacheable?: string[];
|
8
|
-
properties: Readonly<import("@dxos/react-ui-menu").MenuActionProperties>;
|
9
|
-
data: import("@dxos/app-graph").ActionData;
|
10
|
-
}>, "properties"> & {
|
11
|
-
properties: Readonly<import("@dxos/react-ui-menu").MenuActionProperties>;
|
12
|
-
}>[];
|
13
|
-
edges: {
|
14
|
-
source: string;
|
15
|
-
target: string;
|
16
|
-
}[];
|
17
|
-
};
|
18
|
-
//# sourceMappingURL=comment.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"comment.d.ts","sourceRoot":"","sources":["../../../../../src/components/EditorToolbar/comment.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD,OAAO,EAAsB,KAAK,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAkBrE,eAAO,MAAM,aAAa,GAAI,OAAO,kBAAkB,EAAE,SAAS,MAAM,UAAU;;;;;;;;;;;;;;CAGhF,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"editorAction.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/markdown/editorAction.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAsBhE,MAAM,MAAM,WAAW,GACnB,WAAW,GACX,YAAY,GACZ,QAAQ,GACR,WAAW,GACX,SAAS,GACT,SAAS,GACT,OAAO,GACP,UAAU,GACV,MAAM,GACN,MAAM,GACN,aAAa,GACb,cAAc,GACd,WAAW,GACX,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,eAAe,GACf,OAAO,CAAC;AAEZ,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,oBAAoB,GAAG,mBAAmB,CAAC,CAAC;AAE9E,MAAM,MAAM,oBAAoB,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,mBAAmB,KAAK,IAAI,CAAC;AAE5F,eAAO,MAAM,oBAAoB,EAAE,oBAyDlC,CAAC"}
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import { type Extension } from '@codemirror/state';
|
2
|
-
/**
|
3
|
-
* Outliner extension.
|
4
|
-
* - Store outline as a standard markdown document with task and list markers.
|
5
|
-
* - Support continuation lines and rich formatting (with Shift+Enter).
|
6
|
-
* - Constrain editor to outline structure.
|
7
|
-
* - Support smart cut-and-paste.
|
8
|
-
* - Support extracted links.
|
9
|
-
* - Drag/drop lines or move them via shortcuts.
|
10
|
-
*/
|
11
|
-
export declare const outliner: () => Extension;
|
12
|
-
//# sourceMappingURL=outliner.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"outliner.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/markdown/outliner.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,SAAS,EAMf,MAAM,mBAAmB,CAAC;AA0B3B;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ,QAAO,SAyJ3B,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"TextEditorBasic.stories.d.ts","sourceRoot":"","sources":["../../../../src/stories/TextEditorBasic.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAKrB,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAyB,KAAK,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAEzE,OAAO,EACL,YAAY,EAcb,MAAM,eAAe,CAAC;AAevB,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,YAAY,CAKnC,CAAC;AAEF,eAAe,IAAI,CAAC;AAMpB,eAAO,MAAM,OAAO;;CAEnB,CAAC;AAMF,eAAO,MAAM,UAAU;;CAEtB,CAAC;AAMF,eAAO,MAAM,KAAK;;CAEjB,CAAC;AAMF,eAAO,MAAM,QAAQ;;CAEpB,CAAC;AAMF,eAAO,MAAM,YAAY;;CAExB,CAAC;AAMF,eAAO,MAAM,GAAG;;CAOf,CAAC;AAMF,eAAO,MAAM,OAAO;;CAEnB,CAAC;AAEF,eAAO,MAAM,SAAS;;CAUrB,CAAC;AAEF,eAAO,MAAM,mBAAmB;;CAI/B,CAAC;AAEF,eAAO,MAAM,QAAQ;;CAepB,CAAC;AAMF,eAAO,MAAM,UAAU;;CAQtB,CAAC;AAEF,eAAO,MAAM,QAAQ;;CAIpB,CAAC;AAEF,eAAO,MAAM,KAAK;;CAIjB,CAAC;AAEF,eAAO,MAAM,KAAK;;CAEjB,CAAC;AAEF,eAAO,MAAM,IAAI;;CAEhB,CAAC;AAEF,eAAO,MAAM,KAAK;;CAOjB,CAAC;AAMF,eAAO,MAAM,UAAU;;CAEtB,CAAC;AAMF,eAAO,MAAM,WAAW;;CAEvB,CAAC;AAMF,eAAO,MAAM,QAAQ;;CAIpB,CAAC;AAMF,eAAO,MAAM,QAAQ;;CAqBpB,CAAC;AAMF,eAAO,MAAM,KAAK;;CAEjB,CAAC;AAMF,eAAO,MAAM,YAAY;;CAWxB,CAAC;AAMF,eAAO,MAAM,UAAU;;CAQtB,CAAC;AAMF,eAAO,MAAM,YAAY;;CAcxB,CAAC;AAMF,eAAO,MAAM,OAAO;;CAWnB,CAAC;AAMF,eAAO,MAAM,MAAM;;CAQlB,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"TextEditorComments.stories.d.ts","sourceRoot":"","sources":["../../../../src/stories/TextEditorComments.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAGrB,OAAO,KAAkB,MAAM,OAAO,CAAC;AAIvC,OAAO,EAAyB,KAAK,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAEzE,OAAO,EAAE,YAAY,EAA0B,MAAM,eAAe,CAAC;AAKrE,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,YAAY,CAKnC,CAAC;AAEF,eAAe,IAAI,CAAC;AAMpB,eAAO,MAAM,QAAQ;;CAsCpB,CAAC;AAyBF,eAAO,MAAM,WAAW;;CAIvB,CAAC"}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import '@dxos-theme';
|
2
|
-
import React from 'react';
|
3
|
-
import { type Meta } from '@dxos/storybook-utils';
|
4
|
-
import { DefaultStory } from './story-utils';
|
5
|
-
declare const meta: Meta<typeof DefaultStory>;
|
6
|
-
export default meta;
|
7
|
-
export declare const Preview: {
|
8
|
-
render: () => React.JSX.Element;
|
9
|
-
};
|
10
|
-
export declare const Command: {
|
11
|
-
render: () => React.JSX.Element;
|
12
|
-
};
|
13
|
-
//# sourceMappingURL=TextEditorPreview.stories.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"TextEditorPreview.stories.d.ts","sourceRoot":"","sources":["../../../../src/stories/TextEditorPreview.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,KAA2D,MAAM,OAAO,CAAC;AAKhF,OAAO,EAAyB,KAAK,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAO,MAAM,eAAe,CAAC;AAelD,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,YAAY,CAKnC,CAAC;AAEF,eAAe,IAAI,CAAC;AAMpB,eAAO,MAAM,OAAO;;CA8BnB,CAAC;AAwFF,eAAO,MAAM,OAAO;;CAwBnB,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"TextEditorSpecial.stories.d.ts","sourceRoot":"","sources":["../../../../src/stories/TextEditorSpecial.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAGrB,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAyB,KAAK,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAgB,MAAM,eAAe,CAAC;AAG3D,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,YAAY,CAKnC,CAAC;AAEF,eAAe,IAAI,CAAC;AAMpB,eAAO,MAAM,QAAQ;;CAgBpB,CAAC;AAQF,eAAO,MAAM,UAAU;;CAOtB,CAAC;AAMF,eAAO,MAAM,KAAK;;CAqBjB,CAAC;AAMF,eAAO,MAAM,GAAG;;CAaf,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"story-utils.d.ts","sourceRoot":"","sources":["../../../../src/stories/story-utils.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAuC,MAAM,OAAO,CAAC;AAW5D,OAAO,EAEL,KAAK,oBAAoB,EAY1B,MAAM,eAAe,CAAC;AACvB,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAIlE,eAAO,MAAM,GAAG,GAAI,GAAG,OAAO,MAAM,EAAE,WAAqB,CAAC;AAE5D,eAAO,MAAM,GAAG,cAAiE,CAAC;AAElF,eAAO,MAAM,GAAG,yDAAyD,CAAC;AAE1E,eAAO,MAAM,IAAI,QAOhB,CAAC;AAGF,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;CA+FnB,CAAC;AAGF,eAAO,MAAM,IAAI,QAwBhB,CAAC;AAGF,eAAO,MAAM,KAAK,EAAE,UAAU,EAM7B,CAAC;AAEF,eAAO,MAAM,KAAK,UAA4E,CAAC;AAe/F,eAAO,MAAM,iBAAiB;SAVD,MAAM;EAUyB,CAAC;AAU7D,eAAO,MAAM,gBAAgB;SARD,MAAM;EAQwB,CAAC;AAG3D,eAAO,MAAM,iBAAiB,EAAE,SAAS,EAIxC,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,SAAS,EAOpC,CAAC;AAGF,eAAO,MAAM,QAAQ,QAEN,CAAC;AAEhB,eAAO,MAAM,eAAe,QAGb,CAAC;AAEhB,eAAO,MAAM,QAAQ,QAIpB,CAAC;AAEF,eAAO,MAAM,MAAM,mCAA0C,CAAC;AAG9D,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,UAAU,CAAC;AAEpD,MAAM,MAAM,UAAU,GAAG;IACvB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;CACtC,GAAG,IAAI,CAAC,kBAAkB,EAAE,UAAU,GAAG,WAAW,GAAG,YAAY,CAAC,CAAC;AAGtE,eAAO,MAAM,YAAY,GAAI,oGAW1B,UAAU,sBAsDZ,CAAC"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"RefPopover.d.ts","sourceRoot":"","sources":["../../../../src/testing/RefPopover.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAA4D,MAAM,OAAO,CAAC;AAMhH,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,iBAAiB,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAKhG,KAAK,eAAe,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,MAAM,EAAE,iBAAiB,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAEtG,QAAA,MAAkC,aAAa;UAFR,cAAc;YAAU,iBAAiB;aAAW,OAAO;EAEA,CAAC;AAEnG,KAAK,uBAAuB,GAAG,iBAAiB,CAAC;IAAE,QAAQ,CAAC,EAAE,aAAa,CAAA;CAAE,CAAC,CAAC;AA+C/E,eAAO,MAAM,UAAU;uCA7C6B,uBAAuB;CA+C1E,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB,YAAY,EAAE,uBAAuB,EAAE,eAAe,EAAE,CAAC"}
|
@@ -1,30 +0,0 @@
|
|
1
|
-
//
|
2
|
-
// Copyright 2025 DXOS.org
|
3
|
-
//
|
4
|
-
|
5
|
-
import { type EditorView } from '@codemirror/view';
|
6
|
-
|
7
|
-
import { type Label } from '@dxos/react-ui';
|
8
|
-
|
9
|
-
import { createEditorAction, type EditorToolbarState } from './util';
|
10
|
-
import { createComment as nativeCreateComment } from '../../extensions';
|
11
|
-
import { translationKey } from '../../translations';
|
12
|
-
|
13
|
-
const commentLabel = (comment?: boolean, selection?: boolean) =>
|
14
|
-
comment
|
15
|
-
? 'selection overlaps existing comment label'
|
16
|
-
: selection === false
|
17
|
-
? 'select text to comment label'
|
18
|
-
: 'comment label';
|
19
|
-
|
20
|
-
const createCommentAction = (label: Label, getView: () => EditorView) =>
|
21
|
-
createEditorAction('comment', () => nativeCreateComment(getView()), {
|
22
|
-
testId: 'editor.toolbar.comment',
|
23
|
-
icon: 'ph--chat-text--regular',
|
24
|
-
label,
|
25
|
-
});
|
26
|
-
|
27
|
-
export const createComment = (state: EditorToolbarState, getView: () => EditorView) => ({
|
28
|
-
nodes: [createCommentAction([commentLabel(state.comment, state.selection), { ns: translationKey }], getView)],
|
29
|
-
edges: [{ source: 'root', target: 'comment' }],
|
30
|
-
});
|
@@ -1,235 +0,0 @@
|
|
1
|
-
//
|
2
|
-
// Copyright 2025 DXOS.org
|
3
|
-
//
|
4
|
-
|
5
|
-
import { syntaxTree } from '@codemirror/language';
|
6
|
-
import {
|
7
|
-
type ChangeSpec,
|
8
|
-
type Extension,
|
9
|
-
type Line,
|
10
|
-
StateField,
|
11
|
-
type Transaction,
|
12
|
-
EditorState,
|
13
|
-
type Range,
|
14
|
-
} from '@codemirror/state';
|
15
|
-
import { Decoration, type DecorationSet, EditorView } from '@codemirror/view';
|
16
|
-
|
17
|
-
import { log } from '@dxos/log';
|
18
|
-
import { mx } from '@dxos/react-ui-theme';
|
19
|
-
|
20
|
-
// TODO(burdon): Cut-and-paste.
|
21
|
-
// TODO(burdon): Toggle list/task mode (in gutter?)
|
22
|
-
// TODO(burdon): Convert to task object and insert link (menu button).
|
23
|
-
// TOOD(burdon): Continuation lines and rich formatting?
|
24
|
-
|
25
|
-
const indentLevel = 2;
|
26
|
-
const matchTaskMarker = /^\s*- (\[ \]|\[x\])? /;
|
27
|
-
|
28
|
-
/**
|
29
|
-
* Get the starting position of text on the given line.
|
30
|
-
*/
|
31
|
-
const getLineInfo = (line: Line) => {
|
32
|
-
const match = line.text.match(matchTaskMarker);
|
33
|
-
const start = line.from + (match?.[0]?.length ?? 0);
|
34
|
-
return {
|
35
|
-
match, // TODO(burdon): Indicate task or list marker.
|
36
|
-
start,
|
37
|
-
};
|
38
|
-
};
|
39
|
-
|
40
|
-
/**
|
41
|
-
* Outliner extension.
|
42
|
-
* - Store outline as a standard markdown document with task and list markers.
|
43
|
-
* - Support continuation lines and rich formatting (with Shift+Enter).
|
44
|
-
* - Constrain editor to outline structure.
|
45
|
-
* - Support smart cut-and-paste.
|
46
|
-
* - Support extracted links.
|
47
|
-
* - Drag/drop lines or move them via shortcuts.
|
48
|
-
*/
|
49
|
-
export const outliner = (): Extension => [
|
50
|
-
EditorState.transactionFilter.of((tr) => {
|
51
|
-
// Don't allow cursor before marker.
|
52
|
-
if (!tr.docChanged) {
|
53
|
-
const pos = tr.selection?.ranges[tr.selection?.mainIndex]?.from;
|
54
|
-
if (pos != null) {
|
55
|
-
const { match, start } = getLineInfo(tr.startState.doc.lineAt(pos));
|
56
|
-
if (match) {
|
57
|
-
if (pos < start) {
|
58
|
-
return [{ selection: { anchor: start, head: start } }];
|
59
|
-
}
|
60
|
-
}
|
61
|
-
}
|
62
|
-
|
63
|
-
return tr;
|
64
|
-
}
|
65
|
-
|
66
|
-
const changes: ChangeSpec[] = [];
|
67
|
-
tr.changes.iterChanges((fromA, toA, fromB, toB, insert) => {
|
68
|
-
// NOTE: Task markers are atomic so will be deleted when backspace is pressed.
|
69
|
-
// NOTE: CM inserts 2 or 6 spaces when deleting a list or task marker to create a continuation.
|
70
|
-
// - [ ] <- backspace here deletes the task marker.
|
71
|
-
// - [ ] <- backspace here inserts 6 spaces (creates continuation).
|
72
|
-
// - [ ] <- backspace here deletes the task marker.
|
73
|
-
|
74
|
-
const line = tr.startState.doc.lineAt(fromA);
|
75
|
-
const isTaskMarker = line.text.match(matchTaskMarker);
|
76
|
-
if (isTaskMarker) {
|
77
|
-
const { start } = getLineInfo(line);
|
78
|
-
|
79
|
-
// Detect and cancel replacement of task marker with continuation indent.
|
80
|
-
const replace = start === toA && toA - fromA === insert.length;
|
81
|
-
if (replace) {
|
82
|
-
log.info('delete line');
|
83
|
-
changes.push({ from: line.from - 1, to: toA });
|
84
|
-
return;
|
85
|
-
}
|
86
|
-
|
87
|
-
// Detect deletion of marker.
|
88
|
-
if (fromB === toB) {
|
89
|
-
if (toA === line.to) {
|
90
|
-
const line = tr.state.doc.lineAt(fromA);
|
91
|
-
if (line.text.match(/^\s*$/)) {
|
92
|
-
if (line.from === 0) {
|
93
|
-
// Don't delete first line.
|
94
|
-
log.info('skip');
|
95
|
-
changes.push({ from: 0, to: 0 });
|
96
|
-
return;
|
97
|
-
} else {
|
98
|
-
// Delete indent and marker.
|
99
|
-
log.info('delete line');
|
100
|
-
changes.push({ from: line.from - 1, to: toA });
|
101
|
-
return;
|
102
|
-
}
|
103
|
-
}
|
104
|
-
}
|
105
|
-
return;
|
106
|
-
}
|
107
|
-
|
108
|
-
// Check appropriate indentation relative to previous line.
|
109
|
-
if (insert.length === indentLevel) {
|
110
|
-
if (line.number === 1) {
|
111
|
-
log.info('skip');
|
112
|
-
changes.push({ from: 0, to: 0 });
|
113
|
-
return;
|
114
|
-
} else {
|
115
|
-
const getIndent = (text: string) => (text.match(/^\s*/)?.[0]?.length ?? 0) / indentLevel;
|
116
|
-
const currentIndent = getIndent(line.text);
|
117
|
-
const indentPrevious = getIndent(tr.state.doc.lineAt(fromA - 1).text);
|
118
|
-
if (currentIndent > indentPrevious) {
|
119
|
-
log.info('skip');
|
120
|
-
changes.push({ from: 0, to: 0 });
|
121
|
-
return;
|
122
|
-
}
|
123
|
-
}
|
124
|
-
}
|
125
|
-
|
126
|
-
// TODO(burdon): Detect pressing ENTER on empty line that is indented.
|
127
|
-
// Don't allow empty line.
|
128
|
-
// if (start === line.to && insert.toString() === '\n') {
|
129
|
-
// log.info('skip');
|
130
|
-
// changes.push({ from: 0, to: 0 });
|
131
|
-
// return;
|
132
|
-
// }
|
133
|
-
|
134
|
-
log.info('change', {
|
135
|
-
line: { from: line.from, to: line.to },
|
136
|
-
start,
|
137
|
-
a: [fromA, toA],
|
138
|
-
b: [fromB, toB],
|
139
|
-
insert: { text: insert.toString(), length: insert.length },
|
140
|
-
});
|
141
|
-
}
|
142
|
-
});
|
143
|
-
|
144
|
-
if (changes.length > 0) {
|
145
|
-
return [{ changes }];
|
146
|
-
}
|
147
|
-
|
148
|
-
return tr;
|
149
|
-
}),
|
150
|
-
|
151
|
-
StateField.define<DecorationSet>({
|
152
|
-
create: (state) => {
|
153
|
-
return Decoration.set(buildDecorations(0, state.doc.length, state));
|
154
|
-
},
|
155
|
-
update: (value: DecorationSet, tr: Transaction) => {
|
156
|
-
const from = 0;
|
157
|
-
const to = tr.state.doc.length;
|
158
|
-
return value.map(tr.changes).update({
|
159
|
-
filterFrom: 0,
|
160
|
-
filterTo: tr.state.doc.length,
|
161
|
-
filter: () => false,
|
162
|
-
add: buildDecorations(from, to, tr.state),
|
163
|
-
});
|
164
|
-
},
|
165
|
-
provide: (field) => EditorView.decorations.from(field),
|
166
|
-
}),
|
167
|
-
|
168
|
-
// TODO(burdon): Increase indent padding by configuring decorate extension.
|
169
|
-
// TODO(burdon): Hover to select entire group.
|
170
|
-
EditorView.theme({
|
171
|
-
'.cm-list-item-start': {
|
172
|
-
borderTop: '1px solid var(--dx-separator)',
|
173
|
-
borderLeft: '1px solid var(--dx-separator)',
|
174
|
-
borderRight: '1px solid var(--dx-separator)',
|
175
|
-
borderTopLeftRadius: '4px',
|
176
|
-
borderTopRightRadius: '4px',
|
177
|
-
paddingTop: '4px',
|
178
|
-
marginTop: '8px',
|
179
|
-
},
|
180
|
-
'.cm-list-item-end': {
|
181
|
-
borderLeft: '1px solid var(--dx-separator)',
|
182
|
-
borderRight: '1px solid var(--dx-separator)',
|
183
|
-
borderBottom: '1px solid var(--dx-separator)',
|
184
|
-
borderBottomLeftRadius: '4px',
|
185
|
-
borderBottomRightRadius: '4px',
|
186
|
-
paddingBottom: '4px',
|
187
|
-
marginBottom: '8px',
|
188
|
-
},
|
189
|
-
'.cm-list-item-continuation': {
|
190
|
-
borderLeft: '1px solid var(--dx-separator)',
|
191
|
-
borderRight: '1px solid var(--dx-separator)',
|
192
|
-
|
193
|
-
// TODO(burdon): Should match parent indentation.
|
194
|
-
paddingLeft: '24px',
|
195
|
-
},
|
196
|
-
|
197
|
-
// TODO(burdon): Set via options to decorate extension.
|
198
|
-
'.cm-list-item-continuation.cm-codeblock-start': {
|
199
|
-
borderRadius: '0',
|
200
|
-
},
|
201
|
-
}),
|
202
|
-
];
|
203
|
-
|
204
|
-
/**
|
205
|
-
* Add line decorations.
|
206
|
-
*/
|
207
|
-
const buildDecorations = (from: number, to: number, state: EditorState) => {
|
208
|
-
const decorations: Range<Decoration>[] = [];
|
209
|
-
syntaxTree(state).iterate({
|
210
|
-
enter: (node) => {
|
211
|
-
if (node.name === 'ListItem') {
|
212
|
-
const sub = node.node.getChild('BulletList');
|
213
|
-
const lineStart = state.doc.lineAt(node.from);
|
214
|
-
const lineEnd = sub ? state.doc.lineAt(state.doc.lineAt(sub.from).from - 1) : state.doc.lineAt(node.to);
|
215
|
-
|
216
|
-
decorations.push(
|
217
|
-
Decoration.line({
|
218
|
-
class: mx('cm-list-item-start', lineStart.number === lineEnd.number && 'cm-list-item-end'),
|
219
|
-
}).range(lineStart.from, lineStart.from),
|
220
|
-
);
|
221
|
-
|
222
|
-
for (let i = lineStart.from + 1; i < lineEnd.from; i++) {
|
223
|
-
decorations.push(Decoration.line({ class: mx('cm-list-item-continuation') }).range(i, i));
|
224
|
-
}
|
225
|
-
|
226
|
-
// TODO(burdon): Need to sort.
|
227
|
-
if (lineStart.number !== lineEnd.number) {
|
228
|
-
decorations.push(Decoration.line({ class: mx('cm-list-item-end') }).range(lineEnd.from, lineEnd.from));
|
229
|
-
}
|
230
|
-
}
|
231
|
-
},
|
232
|
-
});
|
233
|
-
|
234
|
-
return decorations;
|
235
|
-
};
|