@dxos/react-ui-editor 0.4.7 → 0.4.8-main.00e6f19
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 +2633 -2705
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +18 -34
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +79 -5
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +0 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.d.ts +1 -1
- package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.stories.d.ts +1 -2
- package/dist/types/src/extensions/automerge/automerge.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/cursor.d.ts +1 -1
- package/dist/types/src/extensions/automerge/cursor.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/defs.d.ts +1 -15
- package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/index.d.ts +0 -1
- package/dist/types/src/extensions/automerge/index.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/sync.d.ts +2 -1
- package/dist/types/src/extensions/automerge/sync.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/update-automerge.d.ts +2 -1
- package/dist/types/src/extensions/automerge/update-automerge.d.ts.map +1 -1
- package/dist/types/src/{hooks → extensions/awareness}/awareness-provider.d.ts +1 -1
- package/dist/types/src/extensions/awareness/awareness-provider.d.ts.map +1 -0
- package/dist/types/src/extensions/awareness/awareness.d.ts.map +1 -0
- package/dist/types/src/extensions/awareness/index.d.ts +3 -0
- package/dist/types/src/extensions/awareness/index.d.ts.map +1 -0
- package/dist/types/src/extensions/comments.d.ts +2 -2
- package/dist/types/src/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/extensions/cursor-line-margin.d.ts +6 -7
- package/dist/types/src/extensions/cursor-line-margin.d.ts.map +1 -1
- package/dist/types/src/extensions/cursor.d.ts +1 -1
- package/dist/types/src/extensions/cursor.d.ts.map +1 -1
- package/dist/types/src/extensions/doc.d.ts +3 -0
- package/dist/types/src/extensions/doc.d.ts.map +1 -0
- package/dist/types/src/extensions/factories.d.ts +49 -0
- package/dist/types/src/extensions/factories.d.ts.map +1 -0
- package/dist/types/src/extensions/index.d.ts +4 -1
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/bundle.d.ts +5 -4
- package/dist/types/src/extensions/markdown/bundle.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/table.d.ts +2 -2
- package/dist/types/src/extensions/markdown/table.d.ts.map +1 -1
- package/dist/types/src/extensions/modes.d.ts +1 -0
- package/dist/types/src/extensions/modes.d.ts.map +1 -1
- package/dist/types/src/extensions/state.d.ts +20 -0
- package/dist/types/src/extensions/state.d.ts.map +1 -0
- package/dist/types/src/extensions/types.d.ts +9 -0
- package/dist/types/src/extensions/types.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +1 -4
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useDocAccessor.d.ts +7 -0
- package/dist/types/src/hooks/useDocAccessor.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextEditor.d.ts +3 -44
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextEditor.stories.d.ts +6 -1
- package/dist/types/src/hooks/useTextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/themes/default.d.ts +0 -3
- package/dist/types/src/themes/default.d.ts.map +1 -1
- package/package.json +24 -27
- package/src/components/TextEditor/TextEditor.stories.tsx +520 -23
- package/src/components/TextEditor/TextEditor.tsx +44 -155
- package/src/components/Toolbar/Toolbar.stories.tsx +42 -42
- package/src/extensions/automerge/automerge.stories.tsx +16 -17
- package/src/extensions/automerge/automerge.ts +2 -1
- package/src/extensions/automerge/cursor.ts +1 -1
- package/src/extensions/automerge/defs.ts +1 -22
- package/src/extensions/automerge/index.ts +0 -1
- package/src/extensions/automerge/sync.ts +2 -9
- package/src/extensions/automerge/update-automerge.ts +2 -1
- package/src/{hooks → extensions/awareness}/awareness-provider.ts +1 -1
- package/src/extensions/{awareness.ts → awareness/awareness.ts} +1 -1
- package/src/extensions/awareness/index.ts +6 -0
- package/src/extensions/command/state.ts +1 -1
- package/src/extensions/comments.ts +9 -5
- package/src/extensions/cursor-line-margin.ts +17 -18
- package/src/extensions/cursor.ts +1 -1
- package/src/extensions/doc.ts +14 -0
- package/src/extensions/factories.ts +167 -0
- package/src/extensions/index.ts +4 -1
- package/src/extensions/markdown/bundle.ts +11 -28
- package/src/extensions/markdown/decorate.ts +2 -4
- package/src/extensions/markdown/formatting.ts +15 -10
- package/src/extensions/markdown/image.ts +1 -0
- package/src/extensions/markdown/table.ts +11 -3
- package/src/extensions/modes.ts +3 -1
- package/src/extensions/state.ts +90 -0
- package/src/extensions/types.ts +16 -0
- package/src/hooks/index.ts +1 -5
- package/src/hooks/useDocAccessor.ts +21 -0
- package/src/hooks/useTextEditor.stories.tsx +40 -35
- package/src/hooks/useTextEditor.ts +11 -120
- package/src/index.ts +1 -1
- package/src/themes/default.ts +1 -28
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts +0 -103
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +0 -1
- package/dist/types/src/extensions/awareness.d.ts.map +0 -1
- package/dist/types/src/extensions/outliner.d.ts +0 -4
- package/dist/types/src/extensions/outliner.d.ts.map +0 -1
- package/dist/types/src/hooks/awareness-provider.d.ts.map +0 -1
- package/dist/types/src/hooks/defs.d.ts +0 -20
- package/dist/types/src/hooks/defs.d.ts.map +0 -1
- package/dist/types/src/hooks/useEditorView.d.ts +0 -20
- package/dist/types/src/hooks/useEditorView.d.ts.map +0 -1
- package/dist/types/src/hooks/useTextModel.d.ts +0 -33
- package/dist/types/src/hooks/useTextModel.d.ts.map +0 -1
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +0 -524
- package/src/extensions/outliner.ts +0 -12
- package/src/hooks/defs.ts +0 -30
- package/src/hooks/useEditorView.ts +0 -32
- package/src/hooks/useTextModel.ts +0 -121
- /package/dist/types/src/extensions/{awareness.d.ts → awareness/awareness.d.ts} +0 -0
|
@@ -4,45 +4,283 @@
|
|
|
4
4
|
|
|
5
5
|
import '@dxosTheme';
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import { ArrowSquareOut, X } from '@phosphor-icons/react';
|
|
8
|
+
import { type EditorView } from 'codemirror';
|
|
9
|
+
import defaultsDeep from 'lodash.defaultsdeep';
|
|
10
|
+
import React, { type FC, type KeyboardEvent, StrictMode, useMemo, useRef, useState } from 'react';
|
|
11
|
+
import { createRoot } from 'react-dom/client';
|
|
8
12
|
|
|
9
13
|
import { TextObject } from '@dxos/echo-schema';
|
|
10
|
-
import {
|
|
14
|
+
import { keySymbols, parseShortcut } from '@dxos/keyboard';
|
|
15
|
+
import { PublicKey } from '@dxos/keys';
|
|
16
|
+
import { faker } from '@dxos/random';
|
|
17
|
+
import { Button, DensityProvider, Input, ThemeProvider, useThemeContext } from '@dxos/react-ui';
|
|
18
|
+
import { baseSurface, defaultTx, getSize, mx, textBlockWidth } from '@dxos/react-ui-theme';
|
|
11
19
|
import { withTheme } from '@dxos/storybook-utils';
|
|
12
20
|
|
|
13
21
|
import { TextEditor, type TextEditorProps } from './TextEditor';
|
|
14
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
EditorModes,
|
|
24
|
+
annotations,
|
|
25
|
+
autocomplete,
|
|
26
|
+
blast,
|
|
27
|
+
command,
|
|
28
|
+
comments,
|
|
29
|
+
createBasicExtensions,
|
|
30
|
+
createDataExtensions,
|
|
31
|
+
createMarkdownExtensions,
|
|
32
|
+
createThemeExtensions,
|
|
33
|
+
decorateMarkdown,
|
|
34
|
+
defaultOptions,
|
|
35
|
+
dnd,
|
|
36
|
+
formattingKeymap,
|
|
37
|
+
image,
|
|
38
|
+
linkTooltip,
|
|
39
|
+
listener,
|
|
40
|
+
mention,
|
|
41
|
+
state,
|
|
42
|
+
table,
|
|
43
|
+
typewriter,
|
|
44
|
+
useComments,
|
|
45
|
+
type CommandAction,
|
|
46
|
+
type CommandOptions,
|
|
47
|
+
type Comment,
|
|
48
|
+
type CommentsOptions,
|
|
49
|
+
type SelectionState,
|
|
50
|
+
} from '../../extensions';
|
|
51
|
+
import { useDocAccessor } from '../../hooks';
|
|
15
52
|
import translations from '../../translations';
|
|
16
53
|
|
|
17
|
-
|
|
18
|
-
|
|
54
|
+
faker.seed(101);
|
|
55
|
+
|
|
56
|
+
const str = (...lines: string[]) => lines.join('\n');
|
|
57
|
+
|
|
58
|
+
const num = () => faker.number.int({ min: 0, max: 9999 }).toLocaleString();
|
|
59
|
+
|
|
60
|
+
const img = '';
|
|
61
|
+
|
|
62
|
+
const text = {
|
|
63
|
+
tasks: str(
|
|
64
|
+
//
|
|
65
|
+
'## Tasks',
|
|
66
|
+
'',
|
|
67
|
+
'- [x] decorator',
|
|
68
|
+
'- [ ] checkbox',
|
|
69
|
+
' - [ ] state',
|
|
70
|
+
' - [ ] indent',
|
|
71
|
+
' - [x] style',
|
|
72
|
+
'',
|
|
73
|
+
),
|
|
74
|
+
|
|
75
|
+
list: str(
|
|
76
|
+
//
|
|
77
|
+
'## List',
|
|
78
|
+
'',
|
|
79
|
+
'- new york',
|
|
80
|
+
'- london',
|
|
81
|
+
'- tokyo',
|
|
82
|
+
'',
|
|
83
|
+
),
|
|
84
|
+
|
|
85
|
+
numbered: str(
|
|
86
|
+
//
|
|
87
|
+
'## Numbered',
|
|
88
|
+
'',
|
|
89
|
+
'1. one',
|
|
90
|
+
'2. two',
|
|
91
|
+
'3. three',
|
|
92
|
+
'',
|
|
93
|
+
),
|
|
94
|
+
|
|
95
|
+
code: str(
|
|
96
|
+
'## Code',
|
|
97
|
+
'',
|
|
98
|
+
'```',
|
|
99
|
+
'$ ls -las',
|
|
100
|
+
'```',
|
|
101
|
+
'',
|
|
102
|
+
'```tsx',
|
|
103
|
+
'const Component = () => {',
|
|
104
|
+
' const x = 100;',
|
|
105
|
+
'',
|
|
106
|
+
' return () => <div>Test</div>;',
|
|
107
|
+
'};',
|
|
108
|
+
'```',
|
|
109
|
+
'',
|
|
110
|
+
),
|
|
111
|
+
|
|
112
|
+
links: str(
|
|
113
|
+
'## Links',
|
|
114
|
+
'',
|
|
115
|
+
'This is a naked link https://dxos.org within a sentence.',
|
|
116
|
+
'',
|
|
117
|
+
'Take a look at [DXOS](https://dxos.org) and how to [get started](https://docs.dxos.org/guide/getting-started.html).',
|
|
118
|
+
'',
|
|
119
|
+
),
|
|
120
|
+
|
|
121
|
+
table: str(
|
|
122
|
+
'# Table',
|
|
123
|
+
'',
|
|
124
|
+
`| ${faker.lorem.word().padStart(12)} | ${faker.lorem.word().padStart(12)} | ${faker.lorem.word().padStart(12)} |`,
|
|
125
|
+
`|-${''.padStart(12, '-')}-|-${''.padStart(12, '-')}-|-${''.padStart(12, '-')}-|`,
|
|
126
|
+
`| ${num().padStart(12)} | ${num().padStart(12)} | ${num().padStart(12)} |`,
|
|
127
|
+
`| ${num().padStart(12)} | ${num().padStart(12)} | ${num().padStart(12)} |`,
|
|
128
|
+
`| ${num().padStart(12)} | ${num().padStart(12)} | ${num().padStart(12)} |`,
|
|
129
|
+
'',
|
|
130
|
+
),
|
|
131
|
+
|
|
132
|
+
image: str('# Image', '', img),
|
|
133
|
+
|
|
134
|
+
headings: str(
|
|
135
|
+
...[1, 2, 3, 4, 5, 6].map((level) => ['#'.repeat(level) + ` Heading ${level}`, faker.lorem.sentences(), '']).flat(),
|
|
136
|
+
),
|
|
137
|
+
|
|
138
|
+
paragraphs: str(...faker.helpers.multiple(() => [faker.lorem.paragraph(), ''], { count: 3 }).flat()),
|
|
139
|
+
|
|
140
|
+
footer: str('', '', '', '', ''),
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const document = str(
|
|
144
|
+
'# Markdown',
|
|
145
|
+
'',
|
|
146
|
+
'> This is a block quote.',
|
|
147
|
+
'',
|
|
148
|
+
'> This is a long wrapping block quote. Neque reiciendis ullam quae error labore sit, at, et, nulla, aut at nostrum omnis quas nostrum, at consectetur vitae eos asperiores non omnis ullam in beatae at vitae deserunt asperiores sapiente.',
|
|
19
149
|
'',
|
|
20
|
-
'This is
|
|
21
|
-
'
|
|
22
|
-
'
|
|
150
|
+
'> This is',
|
|
151
|
+
'> a multi-line',
|
|
152
|
+
'> block quote.',
|
|
23
153
|
'',
|
|
24
|
-
'https://dxos.org',
|
|
25
|
-
|
|
154
|
+
'This is all about https://dxos.org and related technologies.',
|
|
155
|
+
'',
|
|
156
|
+
'This this is **bold**, ~~strikethrough~~, _italic_, and `f(INLINE)`.',
|
|
157
|
+
'',
|
|
158
|
+
'---',
|
|
159
|
+
text.links,
|
|
160
|
+
'---',
|
|
161
|
+
text.list,
|
|
162
|
+
'---',
|
|
163
|
+
text.tasks,
|
|
164
|
+
'---',
|
|
165
|
+
text.numbered,
|
|
166
|
+
'---',
|
|
167
|
+
text.code,
|
|
168
|
+
'---',
|
|
169
|
+
text.headings,
|
|
170
|
+
'---',
|
|
171
|
+
text.table,
|
|
172
|
+
'---',
|
|
173
|
+
text.image,
|
|
174
|
+
text.footer,
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
const links = [
|
|
178
|
+
{ label: 'DXOS', apply: '[DXOS](https://dxos.org)' },
|
|
179
|
+
{ label: 'GitHub', apply: '[DXOS GitHub](https://github.com/dxos)' },
|
|
180
|
+
{ label: 'Automerge', apply: '[Automerge](https://automerge.org/)' },
|
|
181
|
+
{ label: 'IPFS', apply: '[Protocol Labs](https://docs.ipfs.tech)' },
|
|
182
|
+
{ label: 'StackEdit', apply: '[StackEdit](https://stackedit.io/app)' },
|
|
183
|
+
];
|
|
184
|
+
|
|
185
|
+
const names = ['adam', 'alice', 'alison', 'bob', 'carol', 'charlie', 'sayuri', 'shoko'];
|
|
186
|
+
|
|
187
|
+
const hover =
|
|
188
|
+
'rounded-sm text-base text-primary-600 hover:text-primary-500 dark:text-primary-300 hover:dark:text-primary-200';
|
|
189
|
+
|
|
190
|
+
const renderLinkTooltip = (el: Element, url: string) => {
|
|
191
|
+
const web = new URL(url);
|
|
192
|
+
createRoot(el).render(
|
|
193
|
+
<StrictMode>
|
|
194
|
+
<a href={url} target='_blank' rel='noreferrer' className={hover}>
|
|
195
|
+
{web.origin}
|
|
196
|
+
<ArrowSquareOut weight='bold' className={mx(getSize(4), 'inline-block leading-none mis-1')} />
|
|
197
|
+
</a>
|
|
198
|
+
</StrictMode>,
|
|
199
|
+
);
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const Key: FC<{ char: string }> = ({ char }) => (
|
|
203
|
+
<span className='flex justify-center items-center w-[24px] h-[24px] rounded text-xs bg-neutral-200 text-black'>
|
|
204
|
+
{char}
|
|
205
|
+
</span>
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
const onCommentsHover: CommentsOptions['onHover'] = (el, shortcut) => {
|
|
209
|
+
createRoot(el).render(
|
|
210
|
+
<StrictMode>
|
|
211
|
+
<div className='flex items-center gap-2 px-2 py-2 bg-neutral-700 text-white text-xs rounded'>
|
|
212
|
+
<div>Create comment</div>
|
|
213
|
+
<div className='flex gap-1'>
|
|
214
|
+
{keySymbols(parseShortcut(shortcut)).map((char) => (
|
|
215
|
+
<Key key={char} char={char} />
|
|
216
|
+
))}
|
|
217
|
+
</div>
|
|
218
|
+
</div>
|
|
219
|
+
</StrictMode>,
|
|
220
|
+
);
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const renderLinkButton = (el: Element, url: string) => {
|
|
224
|
+
createRoot(el).render(
|
|
225
|
+
<StrictMode>
|
|
226
|
+
<a href={url} target='_blank' rel='noreferrer' className={hover}>
|
|
227
|
+
<ArrowSquareOut weight='bold' className={mx(getSize(4), 'inline-block leading-none mis-1 mb-[2px]')} />
|
|
228
|
+
</a>
|
|
229
|
+
</StrictMode>,
|
|
230
|
+
);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
//
|
|
234
|
+
// Story
|
|
235
|
+
//
|
|
236
|
+
|
|
237
|
+
type StoryProps = {
|
|
238
|
+
id?: string;
|
|
239
|
+
text?: string;
|
|
240
|
+
comments?: Comment[];
|
|
241
|
+
readonly?: boolean;
|
|
242
|
+
placeholder?: string;
|
|
243
|
+
} & Pick<TextEditorProps, 'extensions'>;
|
|
26
244
|
|
|
27
245
|
const Story = ({
|
|
246
|
+
id = 'editor-' + PublicKey.random().toHex().slice(0, 8),
|
|
28
247
|
text,
|
|
29
|
-
|
|
248
|
+
comments,
|
|
249
|
+
extensions: _extensions = [],
|
|
250
|
+
readonly,
|
|
251
|
+
placeholder = 'New document.',
|
|
30
252
|
...props
|
|
31
|
-
}:
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
253
|
+
}: StoryProps) => {
|
|
254
|
+
const { accessor } = useDocAccessor(new TextObject(text));
|
|
255
|
+
|
|
256
|
+
const viewRef = useRef<EditorView>(null);
|
|
257
|
+
useComments(viewRef.current, id, comments);
|
|
258
|
+
|
|
259
|
+
const { themeMode } = useThemeContext();
|
|
260
|
+
const extensions = useMemo(
|
|
261
|
+
() => [
|
|
262
|
+
createBasicExtensions({ readonly, placeholder }),
|
|
263
|
+
createMarkdownExtensions({ themeMode }),
|
|
264
|
+
createThemeExtensions({
|
|
265
|
+
themeMode,
|
|
266
|
+
slots: {
|
|
267
|
+
editor: { className: 'min-bs-dvh px-8 bg-white dark:bg-black' },
|
|
268
|
+
},
|
|
269
|
+
}),
|
|
270
|
+
createDataExtensions({ id, text: accessor }),
|
|
271
|
+
_extensions,
|
|
272
|
+
],
|
|
273
|
+
[_extensions],
|
|
274
|
+
);
|
|
37
275
|
|
|
38
276
|
return (
|
|
39
277
|
<TextEditor
|
|
40
|
-
model={model}
|
|
41
|
-
slots={{
|
|
42
|
-
root: { className: mx(textBlockWidth, 'min-bs-dvh') },
|
|
43
|
-
editor: { className: 'min-bs-dvh p-2 bg-white dark:bg-black' },
|
|
44
|
-
}}
|
|
45
278
|
{...props}
|
|
279
|
+
id={id}
|
|
280
|
+
ref={viewRef}
|
|
281
|
+
doc={text}
|
|
282
|
+
extensions={extensions}
|
|
283
|
+
className={mx(textBlockWidth, 'min-bs-dvh')}
|
|
46
284
|
/>
|
|
47
285
|
);
|
|
48
286
|
};
|
|
@@ -55,6 +293,265 @@ export default {
|
|
|
55
293
|
parameters: { translations, layout: 'fullscreen' },
|
|
56
294
|
};
|
|
57
295
|
|
|
296
|
+
const defaults = [
|
|
297
|
+
autocomplete({
|
|
298
|
+
onSearch: (text) => links.filter(({ label }) => label.toLowerCase().includes(text.toLowerCase())),
|
|
299
|
+
}),
|
|
300
|
+
decorateMarkdown({ renderLinkButton }),
|
|
301
|
+
formattingKeymap(),
|
|
302
|
+
image(),
|
|
303
|
+
table(),
|
|
304
|
+
linkTooltip(renderLinkTooltip),
|
|
305
|
+
];
|
|
306
|
+
|
|
58
307
|
export const Default = {
|
|
59
|
-
render: () => <Story text={
|
|
308
|
+
render: () => <Story text={document} extensions={defaults} />,
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
export const Readonly = {
|
|
312
|
+
render: () => <Story text={document} extensions={defaults} readonly />,
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
export const NoExtensions = {
|
|
316
|
+
render: () => <Story text={document} />,
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
const large = faker.helpers.multiple(() => faker.lorem.paragraph({ min: 8, max: 16 }), { count: 20 }).join('\n\n');
|
|
320
|
+
|
|
321
|
+
const largeWithImages = faker.helpers
|
|
322
|
+
.multiple(() => [faker.lorem.paragraph({ min: 12, max: 16 }), img], { count: 20 })
|
|
323
|
+
.flatMap((x) => x)
|
|
324
|
+
.join('\n\n');
|
|
325
|
+
|
|
326
|
+
export const Empty = {
|
|
327
|
+
render: () => <Story />,
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
const global = new Map<string, SelectionState>();
|
|
331
|
+
|
|
332
|
+
export const Scrolling = {
|
|
333
|
+
render: () => (
|
|
334
|
+
<Story
|
|
335
|
+
text={str('# Large Document', '', large)}
|
|
336
|
+
extensions={state({
|
|
337
|
+
setState: (id, state) => global.set(id, state),
|
|
338
|
+
getState: (id) => global.get(id),
|
|
339
|
+
})}
|
|
340
|
+
/>
|
|
341
|
+
),
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
export const ScrollingWithImages = {
|
|
345
|
+
render: () => <Story text={str('# Large Document', '', largeWithImages)} extensions={[image()]} />,
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
export const Links = {
|
|
349
|
+
render: () => <Story text={str(text.links, text.footer)} extensions={[linkTooltip(renderLinkTooltip)]} />,
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
export const Image = {
|
|
353
|
+
render: () => <Story text={str(text.image, text.footer)} extensions={[image()]} />,
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
export const Code = {
|
|
357
|
+
render: () => <Story text={str(text.code, text.footer)} extensions={[decorateMarkdown()]} />,
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
export const Lists = {
|
|
361
|
+
render: () => (
|
|
362
|
+
<Story text={str(text.tasks, '', text.list, '', text.numbered, text.footer)} extensions={[decorateMarkdown()]} />
|
|
363
|
+
),
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
export const Table = {
|
|
367
|
+
render: () => <Story text={str(text.table, text.footer)} extensions={[table()]} />,
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
export const Autocomplete = {
|
|
371
|
+
render: () => (
|
|
372
|
+
<Story
|
|
373
|
+
text={str('# Autocomplete', '', 'Press Ctrl-Space...', text.footer)}
|
|
374
|
+
extensions={[
|
|
375
|
+
decorateMarkdown({ renderLinkButton }),
|
|
376
|
+
autocomplete({
|
|
377
|
+
onSearch: (text) => links.filter(({ label }) => label.toLowerCase().includes(text.toLowerCase())),
|
|
378
|
+
}),
|
|
379
|
+
]}
|
|
380
|
+
/>
|
|
381
|
+
),
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
export const Mention = {
|
|
385
|
+
render: () => (
|
|
386
|
+
<Story
|
|
387
|
+
text={str('# Mention', '', 'Type @...', text.footer)}
|
|
388
|
+
extensions={[
|
|
389
|
+
mention({
|
|
390
|
+
onSearch: (text) => names.filter((name) => name.toLowerCase().startsWith(text.toLowerCase())),
|
|
391
|
+
}),
|
|
392
|
+
]}
|
|
393
|
+
/>
|
|
394
|
+
),
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
const CommandDialog: FC<{ onClose: (action?: CommandAction) => void }> = ({ onClose }) => {
|
|
398
|
+
const [text, setText] = useState('');
|
|
399
|
+
const handleInsert = () => {
|
|
400
|
+
onClose(text.length ? { insert: text + '\n' } : undefined);
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
|
404
|
+
switch (event.key) {
|
|
405
|
+
case 'Enter': {
|
|
406
|
+
handleInsert();
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
case 'Escape': {
|
|
410
|
+
onClose();
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
return (
|
|
417
|
+
<DensityProvider density='fine'>
|
|
418
|
+
<div className={mx('flex items-center p-2 gap-2 border rounded-md', baseSurface)}>
|
|
419
|
+
<Input.Root>
|
|
420
|
+
<Input.TextInput
|
|
421
|
+
autoFocus={true}
|
|
422
|
+
placeholder='Enter command.'
|
|
423
|
+
value={text}
|
|
424
|
+
onChange={({ target: { value } }) => setText(value)}
|
|
425
|
+
onKeyDown={handleKeyDown}
|
|
426
|
+
/>
|
|
427
|
+
</Input.Root>
|
|
428
|
+
<Button variant='ghost' classNames='pli-0' onClick={() => onClose()}>
|
|
429
|
+
<X className={getSize(5)} />
|
|
430
|
+
</Button>
|
|
431
|
+
</div>
|
|
432
|
+
</DensityProvider>
|
|
433
|
+
);
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
const renderCommandDialog: CommandOptions['onRender'] = (el, onClose) => {
|
|
437
|
+
createRoot(el).render(
|
|
438
|
+
<StrictMode>
|
|
439
|
+
<ThemeProvider tx={defaultTx}>
|
|
440
|
+
<CommandDialog onClose={onClose} />
|
|
441
|
+
</ThemeProvider>
|
|
442
|
+
</StrictMode>,
|
|
443
|
+
);
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
export const Command = {
|
|
447
|
+
render: () => (
|
|
448
|
+
<Story
|
|
449
|
+
text={str('# Command', '')}
|
|
450
|
+
extensions={[command({ onRender: renderCommandDialog, onHint: () => 'Press / for commands.' })]}
|
|
451
|
+
/>
|
|
452
|
+
),
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
export const Comments = {
|
|
456
|
+
render: () => {
|
|
457
|
+
const [_comments, setComments] = useState<Comment[]>([]);
|
|
458
|
+
return (
|
|
459
|
+
<Story
|
|
460
|
+
text={str('# Comments', '', text.paragraphs, text.footer)}
|
|
461
|
+
comments={_comments}
|
|
462
|
+
extensions={[
|
|
463
|
+
comments({
|
|
464
|
+
onHover: onCommentsHover,
|
|
465
|
+
onCreate: ({ cursor }) => {
|
|
466
|
+
const id = PublicKey.random().toHex();
|
|
467
|
+
setComments((commentRanges) => [...commentRanges, { id, cursor }]);
|
|
468
|
+
return id;
|
|
469
|
+
},
|
|
470
|
+
onSelect: (state) => {
|
|
471
|
+
const debug = false;
|
|
472
|
+
if (debug) {
|
|
473
|
+
console.log(
|
|
474
|
+
'update',
|
|
475
|
+
JSON.stringify({
|
|
476
|
+
comments: state.comments.length,
|
|
477
|
+
active: state.selection.current?.slice(0, 8),
|
|
478
|
+
closest: state.selection.closest?.slice(0, 8),
|
|
479
|
+
}),
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
}),
|
|
484
|
+
]}
|
|
485
|
+
/>
|
|
486
|
+
);
|
|
487
|
+
},
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
export const Vim = {
|
|
491
|
+
render: () => (
|
|
492
|
+
<Story
|
|
493
|
+
text={str('# Vim Mode', '', 'The distant future. The year 2000.', '', text.paragraphs)}
|
|
494
|
+
extensions={[defaults, EditorModes.vim]}
|
|
495
|
+
/>
|
|
496
|
+
),
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
export const Annotations = {
|
|
500
|
+
render: () => <Story text={str('# Annotations', '', large)} extensions={[annotations({ match: /volup/gi })]} />,
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
export const DND = {
|
|
504
|
+
render: () => <Story text={str('# DND', '')} extensions={[dnd()]} />,
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
const typewriterItems = localStorage.getItem('dxos.org/plugin/markdown/typewriter')?.split(',');
|
|
508
|
+
|
|
509
|
+
export const Listener = {
|
|
510
|
+
render: () => (
|
|
511
|
+
<Story
|
|
512
|
+
text={str('# Listener', '', text.footer)}
|
|
513
|
+
extensions={[
|
|
514
|
+
listener({
|
|
515
|
+
onFocus: (focusing) => {
|
|
516
|
+
console.log({ focusing });
|
|
517
|
+
},
|
|
518
|
+
onChange: (text) => {
|
|
519
|
+
console.log({ text });
|
|
520
|
+
},
|
|
521
|
+
}),
|
|
522
|
+
]}
|
|
523
|
+
/>
|
|
524
|
+
),
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
export const Typewriter = {
|
|
528
|
+
render: () => (
|
|
529
|
+
<Story
|
|
530
|
+
text={str('# Typewriter', '', text.paragraphs, text.footer)}
|
|
531
|
+
extensions={[typewriter({ items: typewriterItems })]}
|
|
532
|
+
/>
|
|
533
|
+
),
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
export const Blast = {
|
|
537
|
+
render: () => (
|
|
538
|
+
<Story
|
|
539
|
+
text={str('# Blast', '', text.paragraphs, text.code, text.paragraphs)}
|
|
540
|
+
extensions={[
|
|
541
|
+
typewriter({ items: typewriterItems }),
|
|
542
|
+
blast(
|
|
543
|
+
defaultsDeep(
|
|
544
|
+
{
|
|
545
|
+
effect: 2,
|
|
546
|
+
particleGravity: 0.2,
|
|
547
|
+
particleShrinkRate: 0.995,
|
|
548
|
+
color: () => [faker.number.int({ min: 100, max: 200 }), 0, 0],
|
|
549
|
+
// color: () => [faker.number.int(256), faker.number.int(256), faker.number.int(256)],
|
|
550
|
+
},
|
|
551
|
+
defaultOptions,
|
|
552
|
+
),
|
|
553
|
+
),
|
|
554
|
+
]}
|
|
555
|
+
/>
|
|
556
|
+
),
|
|
60
557
|
};
|