@dxos/react-ui-editor 0.4.8-main.97e86fe → 0.4.8-main.a4c603b
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 +941 -776
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts +103 -0
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +34 -18
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +5 -79
- package/dist/types/src/components/TextEditor/TextEditor.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 -1
- 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 +15 -1
- package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/index.d.ts +1 -0
- package/dist/types/src/extensions/automerge/index.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/sync.d.ts +1 -2
- package/dist/types/src/extensions/automerge/sync.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/update-automerge.d.ts +1 -2
- package/dist/types/src/extensions/automerge/update-automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/awareness.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 +7 -6
- 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/index.d.ts +1 -3
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/bundle.d.ts +4 -5
- 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/outliner.d.ts +4 -0
- package/dist/types/src/extensions/outliner.d.ts.map +1 -0
- package/dist/types/src/{extensions/awareness → hooks}/awareness-provider.d.ts +1 -1
- package/dist/types/src/hooks/awareness-provider.d.ts.map +1 -0
- package/dist/types/src/hooks/defs.d.ts +20 -0
- package/dist/types/src/hooks/defs.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +4 -1
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useEditorView.d.ts +20 -0
- package/dist/types/src/hooks/useEditorView.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextEditor.d.ts +44 -3
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextEditor.stories.d.ts +0 -6
- package/dist/types/src/hooks/useTextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextModel.d.ts +33 -0
- package/dist/types/src/hooks/useTextModel.d.ts.map +1 -0
- package/dist/types/src/themes/default.d.ts +3 -0
- package/dist/types/src/themes/default.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +524 -0
- package/src/components/TextEditor/TextEditor.stories.tsx +23 -508
- package/src/components/TextEditor/TextEditor.tsx +149 -37
- package/src/components/Toolbar/Toolbar.stories.tsx +42 -42
- package/src/extensions/automerge/automerge.stories.tsx +17 -16
- package/src/extensions/automerge/automerge.ts +1 -2
- package/src/extensions/automerge/cursor.ts +1 -1
- package/src/extensions/automerge/defs.ts +22 -1
- package/src/extensions/automerge/index.ts +1 -0
- package/src/extensions/automerge/sync.ts +9 -2
- package/src/extensions/automerge/update-automerge.ts +1 -2
- package/src/extensions/{awareness/awareness.ts → awareness.ts} +1 -1
- package/src/extensions/command/state.ts +1 -1
- package/src/extensions/comments.ts +5 -9
- package/src/extensions/cursor-line-margin.ts +18 -17
- package/src/extensions/cursor.ts +1 -1
- package/src/extensions/index.ts +1 -3
- package/src/extensions/markdown/bundle.ts +28 -11
- package/src/extensions/markdown/decorate.ts +4 -2
- package/src/extensions/markdown/formatting.ts +10 -15
- package/src/extensions/markdown/image.ts +0 -1
- package/src/extensions/markdown/table.ts +3 -11
- package/src/extensions/outliner.ts +12 -0
- package/src/{extensions/awareness → hooks}/awareness-provider.ts +1 -1
- package/src/hooks/defs.ts +30 -0
- package/src/hooks/index.ts +5 -1
- package/src/hooks/useEditorView.ts +32 -0
- package/src/hooks/useTextEditor.stories.tsx +34 -39
- package/src/hooks/useTextEditor.ts +120 -11
- package/src/hooks/useTextModel.ts +121 -0
- package/src/index.ts +1 -1
- package/src/themes/default.ts +28 -1
- package/dist/types/src/extensions/awareness/awareness-provider.d.ts.map +0 -1
- package/dist/types/src/extensions/awareness/awareness.d.ts.map +0 -1
- package/dist/types/src/extensions/awareness/index.d.ts +0 -3
- package/dist/types/src/extensions/awareness/index.d.ts.map +0 -1
- package/dist/types/src/extensions/doc.d.ts +0 -3
- package/dist/types/src/extensions/doc.d.ts.map +0 -1
- package/dist/types/src/extensions/factories.d.ts +0 -49
- package/dist/types/src/extensions/factories.d.ts.map +0 -1
- package/dist/types/src/extensions/types.d.ts +0 -9
- package/dist/types/src/extensions/types.d.ts.map +0 -1
- package/dist/types/src/hooks/useDocAccessor.d.ts +0 -7
- package/dist/types/src/hooks/useDocAccessor.d.ts.map +0 -1
- package/src/extensions/awareness/index.ts +0 -6
- package/src/extensions/doc.ts +0 -14
- package/src/extensions/factories.ts +0 -167
- package/src/extensions/types.ts +0 -16
- package/src/hooks/useDocAccessor.ts +0 -21
- /package/dist/types/src/extensions/{awareness/awareness.d.ts → awareness.d.ts} +0 -0
|
@@ -4,281 +4,45 @@
|
|
|
4
4
|
|
|
5
5
|
import '@dxosTheme';
|
|
6
6
|
|
|
7
|
-
import {
|
|
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';
|
|
7
|
+
import React, { useState } from 'react';
|
|
12
8
|
|
|
13
9
|
import { TextObject } from '@dxos/echo-schema';
|
|
14
|
-
import {
|
|
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';
|
|
10
|
+
import { mx, textBlockWidth } from '@dxos/react-ui-theme';
|
|
19
11
|
import { withTheme } from '@dxos/storybook-utils';
|
|
20
12
|
|
|
21
13
|
import { TextEditor, type TextEditorProps } from './TextEditor';
|
|
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';
|
|
14
|
+
import { useTextModel } from '../../hooks';
|
|
50
15
|
import translations from '../../translations';
|
|
51
16
|
|
|
52
|
-
|
|
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.',
|
|
17
|
+
const initialText = [
|
|
18
|
+
'# TextEditor',
|
|
153
19
|
'',
|
|
154
|
-
'This
|
|
20
|
+
'This is the basic plain text editor within minimal formatting.',
|
|
21
|
+
'You can add custom styles and create custom extensions.',
|
|
22
|
+
'Or use the MarkdownEditor to edit documents.',
|
|
155
23
|
'',
|
|
156
|
-
'
|
|
157
|
-
|
|
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'>;
|
|
24
|
+
'https://dxos.org',
|
|
25
|
+
].join('\n');
|
|
242
26
|
|
|
243
27
|
const Story = ({
|
|
244
|
-
id = 'test',
|
|
245
28
|
text,
|
|
246
|
-
|
|
247
|
-
extensions: _extensions = [],
|
|
248
|
-
readonly,
|
|
249
|
-
placeholder = 'New document.',
|
|
29
|
+
automerge,
|
|
250
30
|
...props
|
|
251
|
-
}:
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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
|
-
);
|
|
31
|
+
}: { text?: string; automerge?: boolean } & Pick<TextEditorProps, 'extensions' | 'placeholder' | 'slots'>) => {
|
|
32
|
+
const [item] = useState({ text: new TextObject(text, undefined, undefined, { automerge }) });
|
|
33
|
+
const model = useTextModel({ text: item.text });
|
|
34
|
+
if (!model) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
273
37
|
|
|
274
38
|
return (
|
|
275
39
|
<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
|
+
}}
|
|
276
45
|
{...props}
|
|
277
|
-
id={id}
|
|
278
|
-
ref={viewRef}
|
|
279
|
-
doc={text}
|
|
280
|
-
extensions={extensions}
|
|
281
|
-
className={mx(textBlockWidth, 'min-bs-dvh')}
|
|
282
46
|
/>
|
|
283
47
|
);
|
|
284
48
|
};
|
|
@@ -291,255 +55,6 @@ export default {
|
|
|
291
55
|
parameters: { translations, layout: 'fullscreen' },
|
|
292
56
|
};
|
|
293
57
|
|
|
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
|
-
|
|
305
58
|
export const Default = {
|
|
306
|
-
render: () => <Story text={
|
|
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
|
-
),
|
|
59
|
+
render: () => <Story text={initialText} placeholder='Enter text...' />,
|
|
545
60
|
};
|