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