@dxos/react-ui-editor 0.3.11-main.d3a2438 → 0.3.11-main.d46c1ca
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 +744 -896
- 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 +13 -14
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +16 -9
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +4 -4
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/comments.stories.d.ts +26 -0
- package/dist/types/src/components/TextEditor/comments.stories.d.ts.map +1 -0
- package/dist/types/src/extensions/autocomplete.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/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 +7 -9
- 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/semaphore.d.ts +7 -12
- package/dist/types/src/extensions/automerge/semaphore.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/update-automerge.d.ts +2 -2
- package/dist/types/src/extensions/awareness.d.ts +1 -1
- package/dist/types/src/extensions/awareness.d.ts.map +1 -1
- package/dist/types/src/extensions/basic.d.ts +4 -5
- package/dist/types/src/extensions/basic.d.ts.map +1 -1
- package/dist/types/src/extensions/code.d.ts.map +1 -1
- package/dist/types/src/extensions/comments.d.ts +32 -19
- package/dist/types/src/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/{util → extensions}/cursor.d.ts +10 -2
- package/dist/types/src/extensions/cursor.d.ts.map +1 -0
- package/dist/types/src/extensions/hr.d.ts.map +1 -1
- package/dist/types/src/extensions/index.d.ts +2 -1
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/bundle.d.ts +2 -5
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -1
- package/dist/types/src/extensions/mention.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/tasklist.d.ts.map +1 -1
- package/dist/types/src/hooks/awareness-provider.d.ts +7 -4
- package/dist/types/src/hooks/awareness-provider.d.ts.map +1 -1
- package/dist/types/src/hooks/defs.d.ts +25 -0
- package/dist/types/src/hooks/defs.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +2 -2
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextEditor.d.ts +17 -0
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextModel.d.ts +2 -32
- package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
- package/dist/types/src/styles/markdown.d.ts.map +1 -1
- package/dist/types/src/themes/default.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +7 -0
- package/dist/types/src/util.d.ts.map +1 -0
- package/package.json +33 -35
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +75 -80
- package/src/components/TextEditor/TextEditor.stories.tsx +10 -43
- package/src/components/TextEditor/TextEditor.tsx +106 -83
- package/src/components/TextEditor/comments.stories.tsx +357 -0
- package/src/extensions/autocomplete.ts +6 -3
- package/src/extensions/automerge/automerge.ts +40 -46
- package/src/extensions/automerge/cursor.ts +2 -1
- package/src/extensions/automerge/defs.ts +10 -31
- package/src/extensions/automerge/index.ts +0 -1
- package/src/extensions/automerge/semaphore.ts +23 -20
- package/src/extensions/automerge/update-automerge.ts +2 -2
- package/src/extensions/awareness.ts +40 -46
- package/src/extensions/basic.ts +22 -17
- package/src/extensions/code.ts +24 -18
- package/src/extensions/comments.ts +246 -238
- package/src/extensions/cursor.ts +50 -0
- package/src/extensions/hr.ts +49 -50
- package/src/extensions/image.ts +2 -2
- package/src/extensions/index.ts +2 -1
- package/src/extensions/link.ts +7 -7
- package/src/extensions/markdown/bundle.ts +18 -24
- package/src/extensions/markdown/highlight.ts +0 -8
- package/src/extensions/mention.ts +9 -2
- package/src/extensions/outliner.ts +12 -0
- package/src/extensions/table.ts +2 -2
- package/src/extensions/tasklist.ts +78 -86
- package/src/hooks/awareness-provider.ts +24 -20
- package/src/hooks/defs.ts +42 -0
- package/src/hooks/index.ts +3 -2
- package/src/hooks/useTextEditor.ts +29 -0
- package/src/hooks/useTextModel.ts +47 -59
- package/src/styles/markdown.ts +0 -2
- package/src/themes/default.ts +17 -50
- package/src/util.ts +41 -0
- package/dist/types/src/components/TextEditor/codemirror.stories.d.ts +0 -12
- package/dist/types/src/components/TextEditor/codemirror.stories.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/yjs.stories.d.ts +0 -12
- package/dist/types/src/components/TextEditor/yjs.stories.d.ts.map +0 -1
- package/dist/types/src/extensions/yjs/cursor.d.ts +0 -4
- package/dist/types/src/extensions/yjs/cursor.d.ts.map +0 -1
- package/dist/types/src/extensions/yjs/index.d.ts +0 -2
- package/dist/types/src/extensions/yjs/index.d.ts.map +0 -1
- package/dist/types/src/extensions/yjs/yjs.d.ts +0 -4
- package/dist/types/src/extensions/yjs/yjs.d.ts.map +0 -1
- package/dist/types/src/extensions/yjs/yjs.test.d.ts +0 -2
- package/dist/types/src/extensions/yjs/yjs.test.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge.d.ts +0 -3
- package/dist/types/src/hooks/automerge.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs.d.ts +0 -27
- package/dist/types/src/hooks/yjs.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -3
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/proto/gen/schema.d.ts +0 -15
- package/dist/types/src/testing/proto/gen/schema.d.ts.map +0 -1
- package/dist/types/src/testing/proto/index.d.ts +0 -2
- package/dist/types/src/testing/proto/index.d.ts.map +0 -1
- package/dist/types/src/testing/replicator.d.ts +0 -45
- package/dist/types/src/testing/replicator.d.ts.map +0 -1
- package/dist/types/src/util/cursor.d.ts.map +0 -1
- package/dist/types/src/util/index.d.ts +0 -3
- package/dist/types/src/util/index.d.ts.map +0 -1
- package/dist/types/src/util/util.d.ts +0 -5
- package/dist/types/src/util/util.d.ts.map +0 -1
- package/src/components/TextEditor/codemirror.stories.ts +0 -115
- package/src/components/TextEditor/yjs.stories.tsx +0 -56
- package/src/extensions/yjs/cursor.ts +0 -21
- package/src/extensions/yjs/index.ts +0 -5
- package/src/extensions/yjs/yjs.test.ts +0 -35
- package/src/extensions/yjs/yjs.ts +0 -16
- package/src/hooks/automerge.ts +0 -52
- package/src/hooks/yjs.ts +0 -178
- package/src/testing/index.ts +0 -6
- package/src/testing/proto/gen/schema.ts +0 -49
- package/src/testing/proto/index.ts +0 -5
- package/src/testing/proto/schema.proto +0 -15
- package/src/testing/replicator.ts +0 -184
- package/src/util/cursor.ts +0 -29
- package/src/util/index.ts +0 -6
- package/src/util/util.ts +0 -18
|
@@ -4,14 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
import '@dxosTheme';
|
|
6
6
|
|
|
7
|
-
import { EditorView } from '@codemirror/view';
|
|
7
|
+
import { type EditorView } from '@codemirror/view';
|
|
8
8
|
import { faker } from '@faker-js/faker';
|
|
9
9
|
import { ArrowSquareOut } from '@phosphor-icons/react';
|
|
10
10
|
import defaultsDeep from 'lodash.defaultsdeep';
|
|
11
|
-
import React, { type FC, StrictMode, useState } from 'react';
|
|
11
|
+
import React, { type FC, StrictMode, useRef, useState } from 'react';
|
|
12
12
|
import { createRoot } from 'react-dom/client';
|
|
13
13
|
|
|
14
14
|
import { TextObject } from '@dxos/echo-schema';
|
|
15
|
+
import { keySymbols, parseShortcut } from '@dxos/keyboard';
|
|
15
16
|
import { PublicKey } from '@dxos/keys';
|
|
16
17
|
import { fixedInsetFlexLayout, getSize, groupSurface, mx } from '@dxos/react-ui-theme';
|
|
17
18
|
import { withTheme } from '@dxos/storybook-utils';
|
|
@@ -25,7 +26,6 @@ import {
|
|
|
25
26
|
defaultOptions,
|
|
26
27
|
hr,
|
|
27
28
|
image,
|
|
28
|
-
listener,
|
|
29
29
|
link,
|
|
30
30
|
mention,
|
|
31
31
|
table,
|
|
@@ -33,8 +33,9 @@ import {
|
|
|
33
33
|
typewriter,
|
|
34
34
|
type CommentsOptions,
|
|
35
35
|
type LinkOptions,
|
|
36
|
+
useComments,
|
|
36
37
|
} from '../../extensions';
|
|
37
|
-
import { type
|
|
38
|
+
import { type Comment, useTextModel } from '../../hooks';
|
|
38
39
|
|
|
39
40
|
// Extensions:
|
|
40
41
|
// TODO(burdon): Table of contents.
|
|
@@ -54,8 +55,8 @@ const text = {
|
|
|
54
55
|
'- [x] decorator',
|
|
55
56
|
'- [ ] checkbox',
|
|
56
57
|
' - [ ] state',
|
|
57
|
-
'
|
|
58
|
-
'
|
|
58
|
+
' - [ ] indent',
|
|
59
|
+
' - [x] style',
|
|
59
60
|
'',
|
|
60
61
|
),
|
|
61
62
|
|
|
@@ -161,6 +162,8 @@ const links = [
|
|
|
161
162
|
{ label: 'StackEdit', apply: '[StackEdit](https://stackedit.io/app)' },
|
|
162
163
|
];
|
|
163
164
|
|
|
165
|
+
const names = ['adam', 'alice', 'alison', 'bob', 'carol', 'charlie', 'sayuri', 'shoko'];
|
|
166
|
+
|
|
164
167
|
const hover =
|
|
165
168
|
'rounded-sm text-base text-primary-600 hover:text-primary-500 dark:text-primary-300 hover:dark:text-primary-200';
|
|
166
169
|
|
|
@@ -182,15 +185,15 @@ const Key: FC<{ char: string }> = ({ char }) => (
|
|
|
182
185
|
</span>
|
|
183
186
|
);
|
|
184
187
|
|
|
185
|
-
const onCommentsHover: CommentsOptions['onHover'] = (el) => {
|
|
188
|
+
const onCommentsHover: CommentsOptions['onHover'] = (el, shortcut) => {
|
|
186
189
|
createRoot(el).render(
|
|
187
190
|
<StrictMode>
|
|
188
191
|
<div className='flex items-center gap-2 px-2 py-2 bg-neutral-700 text-white text-xs rounded'>
|
|
189
192
|
<div>Create comment</div>
|
|
190
|
-
{/* TODO(burdon): Unify shortcuts. */}
|
|
191
193
|
<div className='flex gap-1'>
|
|
192
|
-
|
|
193
|
-
|
|
194
|
+
{keySymbols(parseShortcut(shortcut)).map((char) => (
|
|
195
|
+
<Key key={char} char={char} />
|
|
196
|
+
))}
|
|
194
197
|
</div>
|
|
195
198
|
</div>
|
|
196
199
|
</StrictMode>,
|
|
@@ -201,7 +204,7 @@ const onRenderLink: LinkOptions['onRender'] = (el, url) => {
|
|
|
201
204
|
createRoot(el).render(
|
|
202
205
|
<StrictMode>
|
|
203
206
|
<a href={url} target='_blank' rel='noreferrer' className={hover}>
|
|
204
|
-
<ArrowSquareOut weight='bold' className={mx(getSize(4), 'inline-block leading-none mis-1 mb-
|
|
207
|
+
<ArrowSquareOut weight='bold' className={mx(getSize(4), 'inline-block leading-none mis-1 mb-[2px]')} />
|
|
205
208
|
</a>
|
|
206
209
|
</StrictMode>,
|
|
207
210
|
);
|
|
@@ -209,22 +212,24 @@ const onRenderLink: LinkOptions['onRender'] = (el, url) => {
|
|
|
209
212
|
|
|
210
213
|
type StoryProps = {
|
|
211
214
|
text?: string;
|
|
215
|
+
comments?: Comment[];
|
|
212
216
|
automerge?: boolean;
|
|
213
|
-
} & Pick<TextEditorProps, '
|
|
217
|
+
} & Pick<TextEditorProps, 'readonly' | 'placeholder' | 'slots' | 'extensions'>;
|
|
214
218
|
|
|
215
|
-
const Story = ({ text, automerge, ...props }: StoryProps) => {
|
|
219
|
+
const Story = ({ text, comments, automerge, placeholder = 'New document.', ...props }: StoryProps) => {
|
|
216
220
|
const [item] = useState({ text: new TextObject(text, undefined, undefined, { automerge }) });
|
|
221
|
+
const view = useRef<EditorView>(null);
|
|
217
222
|
const model = useTextModel({ text: item.text });
|
|
223
|
+
useComments(view.current, comments);
|
|
218
224
|
if (!model) {
|
|
219
225
|
return null;
|
|
220
226
|
}
|
|
221
227
|
|
|
222
228
|
return (
|
|
223
229
|
<div className={mx(fixedInsetFlexLayout, groupSurface)}>
|
|
224
|
-
<div className='flex justify-center
|
|
225
|
-
<div className='flex flex-col w-[800px]
|
|
226
|
-
<MarkdownEditor model={model} {...props} />
|
|
227
|
-
<div className='flex shrink-0 h-[300px]'></div>
|
|
230
|
+
<div className='flex h-full justify-center'>
|
|
231
|
+
<div className='flex flex-col h-full w-[800px]'>
|
|
232
|
+
<MarkdownEditor ref={view} model={model} placeholder={placeholder} {...props} />
|
|
228
233
|
</div>
|
|
229
234
|
</div>
|
|
230
235
|
</div>
|
|
@@ -238,7 +243,7 @@ export default {
|
|
|
238
243
|
render: Story,
|
|
239
244
|
};
|
|
240
245
|
|
|
241
|
-
const
|
|
246
|
+
const defaults = [
|
|
242
247
|
autocomplete({
|
|
243
248
|
onSearch: (text) => links.filter(({ label }) => label.toLowerCase().includes(text.toLowerCase())),
|
|
244
249
|
}),
|
|
@@ -246,40 +251,33 @@ const extensions = [
|
|
|
246
251
|
hr(),
|
|
247
252
|
image(),
|
|
248
253
|
link({ onRender: onRenderLink, onHover: onHoverLinkTooltip }),
|
|
254
|
+
// mention({
|
|
255
|
+
// onSearch: (text) => names.filter((name) => name.toLowerCase().startsWith(text.toLowerCase())),
|
|
256
|
+
// }),
|
|
249
257
|
table(),
|
|
250
258
|
tasklist(),
|
|
251
259
|
];
|
|
252
260
|
|
|
253
261
|
export const Default = {
|
|
254
|
-
render: () => <Story text={document} extensions={
|
|
262
|
+
render: () => <Story text={document} extensions={defaults} />,
|
|
255
263
|
};
|
|
256
264
|
|
|
257
265
|
export const Readonly = {
|
|
258
|
-
render: () => <Story text={document} extensions={
|
|
266
|
+
render: () => <Story text={document} extensions={defaults} readonly />,
|
|
259
267
|
};
|
|
260
268
|
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
export const Large = {
|
|
264
|
-
render: () => <Story text={str('# Large Document', '', large)} extensions={[]} />,
|
|
269
|
+
export const NoExtensions = {
|
|
270
|
+
render: () => <Story text={document} />,
|
|
265
271
|
};
|
|
266
272
|
|
|
273
|
+
const large = faker.helpers.multiple(() => faker.lorem.paragraph({ min: 8, max: 16 }), { count: 20 }).join('\n\n');
|
|
274
|
+
|
|
267
275
|
export const Empty = {
|
|
268
276
|
render: () => <Story />,
|
|
269
277
|
};
|
|
270
278
|
|
|
271
|
-
export const
|
|
272
|
-
render: () => <Story text={
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
// TODO(burdon): Cursor bug if no newline after BR (cursor down just loops back to start of each paragraph).
|
|
276
|
-
export const HorizontalRule = {
|
|
277
|
-
render: () => (
|
|
278
|
-
<Story
|
|
279
|
-
text={str('# Horizontal Rule', '', text.paragraphs, '---', '', text.paragraphs, '---', '', text.paragraphs)}
|
|
280
|
-
extensions={[hr()]}
|
|
281
|
-
/>
|
|
282
|
-
),
|
|
279
|
+
export const Scrolling = {
|
|
280
|
+
render: () => <Story text={str('# Large Document', '', large)} extensions={[]} />,
|
|
283
281
|
};
|
|
284
282
|
|
|
285
283
|
export const Links = {
|
|
@@ -295,34 +293,33 @@ export const Code = {
|
|
|
295
293
|
render: () => <Story text={str(text.code, text.footer)} extensions={[code()]} readonly />,
|
|
296
294
|
};
|
|
297
295
|
|
|
298
|
-
export const Table = {
|
|
299
|
-
render: () => <Story text={str(text.table, text.footer)} extensions={[table()]} />,
|
|
300
|
-
};
|
|
301
|
-
|
|
302
296
|
export const Image = {
|
|
303
297
|
render: () => <Story text={str(text.image, text.footer)} readonly extensions={[image()]} />,
|
|
304
298
|
};
|
|
305
299
|
|
|
306
|
-
export const
|
|
300
|
+
export const Lists = {
|
|
307
301
|
render: () => (
|
|
308
|
-
<Story
|
|
309
|
-
text={str(text.tasks, '', text.list, text.footer)}
|
|
310
|
-
extensions={[
|
|
311
|
-
tasklist(),
|
|
312
|
-
listener({
|
|
313
|
-
onChange: (text) => {
|
|
314
|
-
console.log(text);
|
|
315
|
-
},
|
|
316
|
-
}),
|
|
317
|
-
]}
|
|
318
|
-
/>
|
|
302
|
+
<Story text={str(text.tasks, '', text.list, '', text.numbered, text.footer)} extensions={[tasklist()]} />
|
|
319
303
|
),
|
|
320
304
|
};
|
|
321
305
|
|
|
306
|
+
export const Table = {
|
|
307
|
+
render: () => <Story text={str(text.table, text.footer)} extensions={[table()]} />,
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
// export const Outliner = {
|
|
311
|
+
// render: () => (
|
|
312
|
+
// <Story
|
|
313
|
+
// text={str('# Outliner', '', 'Block', ': this is a block', ': with multiple lines', text.footer)}
|
|
314
|
+
// extensions={[outliner()]}
|
|
315
|
+
// />
|
|
316
|
+
// ),
|
|
317
|
+
// };
|
|
318
|
+
|
|
322
319
|
export const Autocomplete = {
|
|
323
320
|
render: () => (
|
|
324
321
|
<Story
|
|
325
|
-
text={str('# Autocomplete', '', 'Press
|
|
322
|
+
text={str('# Autocomplete', '', 'Press Ctrl-Space...', text.footer)}
|
|
326
323
|
extensions={[
|
|
327
324
|
link({ onRender: onRenderLink }),
|
|
328
325
|
autocomplete({
|
|
@@ -333,8 +330,6 @@ export const Autocomplete = {
|
|
|
333
330
|
),
|
|
334
331
|
};
|
|
335
332
|
|
|
336
|
-
const names = ['adam', 'alice', 'alison', 'bob', 'carol', 'charlie', 'sayuri', 'shoko'];
|
|
337
|
-
|
|
338
333
|
export const Mention = {
|
|
339
334
|
render: () => (
|
|
340
335
|
<Story
|
|
@@ -350,18 +345,18 @@ export const Mention = {
|
|
|
350
345
|
|
|
351
346
|
export const Comments = {
|
|
352
347
|
render: () => {
|
|
353
|
-
const [
|
|
348
|
+
const [commentRanges, setCommentRanges] = useState<Comment[]>([]);
|
|
354
349
|
|
|
355
350
|
return (
|
|
356
351
|
<Story
|
|
357
352
|
text={str('# Comments', '', text.paragraphs, text.footer)}
|
|
358
|
-
comments={
|
|
353
|
+
comments={commentRanges}
|
|
359
354
|
extensions={[
|
|
360
355
|
comments({
|
|
361
356
|
onHover: onCommentsHover,
|
|
362
|
-
onCreate: (
|
|
357
|
+
onCreate: (range) => {
|
|
363
358
|
const id = PublicKey.random().toHex();
|
|
364
|
-
|
|
359
|
+
setCommentRanges((commentRanges) => [...commentRanges, { id, cursor: range }]);
|
|
365
360
|
return id;
|
|
366
361
|
},
|
|
367
362
|
onSelect: (state) => {
|
|
@@ -370,9 +365,9 @@ export const Comments = {
|
|
|
370
365
|
console.log(
|
|
371
366
|
'update',
|
|
372
367
|
JSON.stringify({
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
368
|
+
comments: state.comments.length,
|
|
369
|
+
active: state.selection.current?.slice(0, 8),
|
|
370
|
+
closest: state.selection.closest?.slice(0, 8),
|
|
376
371
|
}),
|
|
377
372
|
);
|
|
378
373
|
}
|
|
@@ -384,8 +379,24 @@ export const Comments = {
|
|
|
384
379
|
},
|
|
385
380
|
};
|
|
386
381
|
|
|
382
|
+
export const HorizontalRule = {
|
|
383
|
+
render: () => (
|
|
384
|
+
<Story
|
|
385
|
+
text={str('# Horizontal Rule', '', text.paragraphs, '---', text.paragraphs, '---', text.paragraphs)}
|
|
386
|
+
extensions={[hr()]}
|
|
387
|
+
/>
|
|
388
|
+
),
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
const typewriterItems = localStorage.getItem('dxos.org/plugin/markdown/typewriter')?.split(',');
|
|
392
|
+
|
|
387
393
|
export const Typewriter = {
|
|
388
|
-
render: () =>
|
|
394
|
+
render: () => (
|
|
395
|
+
<Story
|
|
396
|
+
text={str('# Typewriter', '', text.paragraphs, text.footer)}
|
|
397
|
+
extensions={[typewriter({ items: typewriterItems })]}
|
|
398
|
+
/>
|
|
399
|
+
),
|
|
389
400
|
};
|
|
390
401
|
|
|
391
402
|
export const Blast = {
|
|
@@ -393,9 +404,7 @@ export const Blast = {
|
|
|
393
404
|
<Story
|
|
394
405
|
text={str('# Blast', '', text.paragraphs, text.code, text.paragraphs)}
|
|
395
406
|
extensions={[
|
|
396
|
-
typewriter({
|
|
397
|
-
items: localStorage.getItem('dxos.composer.extension.demo')?.split(','),
|
|
398
|
-
}),
|
|
407
|
+
typewriter({ items: typewriterItems }),
|
|
399
408
|
blast(
|
|
400
409
|
defaultsDeep(
|
|
401
410
|
{
|
|
@@ -412,17 +421,3 @@ export const Blast = {
|
|
|
412
421
|
/>
|
|
413
422
|
),
|
|
414
423
|
};
|
|
415
|
-
|
|
416
|
-
export const Diagnostics = {
|
|
417
|
-
render: () => (
|
|
418
|
-
<Story
|
|
419
|
-
text={document}
|
|
420
|
-
extensions={[
|
|
421
|
-
// Cursor moved.
|
|
422
|
-
EditorView.updateListener.of((update) => {
|
|
423
|
-
console.log('update', update.view.state.selection.main.head);
|
|
424
|
-
}),
|
|
425
|
-
]}
|
|
426
|
-
/>
|
|
427
|
-
),
|
|
428
|
-
};
|
|
@@ -4,17 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
import '@dxosTheme';
|
|
6
6
|
|
|
7
|
-
import defaultsDeep from 'lodash.defaultsdeep';
|
|
8
7
|
import React, { useState } from 'react';
|
|
9
8
|
|
|
10
9
|
import { TextObject } from '@dxos/echo-schema';
|
|
11
10
|
import { fixedInsetFlexLayout, groupSurface, mx } from '@dxos/react-ui-theme';
|
|
12
11
|
import { withTheme } from '@dxos/storybook-utils';
|
|
13
12
|
|
|
14
|
-
import {
|
|
13
|
+
import { TextEditor, type TextEditorProps } from './TextEditor';
|
|
15
14
|
import { listener } from '../../extensions';
|
|
16
15
|
import { useTextModel } from '../../hooks';
|
|
17
|
-
import { textTheme } from '../../themes';
|
|
18
16
|
|
|
19
17
|
const initialText = [
|
|
20
18
|
'# TextEditor',
|
|
@@ -30,7 +28,7 @@ const Story = ({
|
|
|
30
28
|
text,
|
|
31
29
|
automerge,
|
|
32
30
|
...props
|
|
33
|
-
}: { text?: string; automerge?: boolean } & Pick<TextEditorProps, 'extensions' | 'slots'>) => {
|
|
31
|
+
}: { text?: string; automerge?: boolean } & Pick<TextEditorProps, 'extensions' | 'placeholder' | 'slots'>) => {
|
|
34
32
|
const [item] = useState({ text: new TextObject(text, undefined, undefined, { automerge }) });
|
|
35
33
|
const model = useTextModel({ text: item.text });
|
|
36
34
|
if (!model) {
|
|
@@ -39,10 +37,9 @@ const Story = ({
|
|
|
39
37
|
|
|
40
38
|
return (
|
|
41
39
|
<div className={mx(fixedInsetFlexLayout, groupSurface)}>
|
|
42
|
-
<div className='flex justify-center
|
|
40
|
+
<div className='flex justify-center'>
|
|
43
41
|
<div className='flex flex-col w-[800px] py-16'>
|
|
44
42
|
<TextEditor model={model} {...props} />
|
|
45
|
-
<div className='flex shrink-0 h-[300px]'></div>
|
|
46
43
|
</div>
|
|
47
44
|
</div>
|
|
48
45
|
</div>
|
|
@@ -57,49 +54,19 @@ export default {
|
|
|
57
54
|
};
|
|
58
55
|
|
|
59
56
|
export const Default = {
|
|
60
|
-
render: () =>
|
|
61
|
-
<Story
|
|
62
|
-
slots={defaultsDeep(
|
|
63
|
-
{ editor: { theme: textTheme, placeholder: 'Enter text...' } } satisfies TextEditorSlots,
|
|
64
|
-
defaultSlots,
|
|
65
|
-
)}
|
|
66
|
-
/>
|
|
67
|
-
),
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export const Listener = {
|
|
71
|
-
render: () => (
|
|
72
|
-
<Story
|
|
73
|
-
slots={defaultsDeep(
|
|
74
|
-
{ editor: { theme: textTheme, placeholder: 'Enter text...' } } satisfies TextEditorSlots,
|
|
75
|
-
defaultSlots,
|
|
76
|
-
)}
|
|
77
|
-
extensions={[listener({ onChange: (text) => console.log(text) })]}
|
|
78
|
-
/>
|
|
79
|
-
),
|
|
57
|
+
render: () => <Story placeholder='Enter text...' />,
|
|
80
58
|
};
|
|
81
59
|
|
|
82
60
|
export const Text = {
|
|
83
|
-
render: () =>
|
|
84
|
-
<Story
|
|
85
|
-
text={initialText}
|
|
86
|
-
slots={defaultsDeep(
|
|
87
|
-
{ editor: { theme: textTheme, placeholder: 'Enter text...' } } satisfies TextEditorSlots,
|
|
88
|
-
defaultSlots,
|
|
89
|
-
)}
|
|
90
|
-
/>
|
|
91
|
-
),
|
|
61
|
+
render: () => <Story text={initialText} placeholder='Enter text...' />,
|
|
92
62
|
};
|
|
93
63
|
|
|
94
64
|
export const Automerge = {
|
|
65
|
+
render: () => <Story text={initialText} placeholder='Enter text...' automerge />,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const Listener = {
|
|
95
69
|
render: () => (
|
|
96
|
-
<Story
|
|
97
|
-
automerge
|
|
98
|
-
text={initialText}
|
|
99
|
-
slots={defaultsDeep(
|
|
100
|
-
{ editor: { theme: textTheme, placeholder: 'Enter text...' } } satisfies TextEditorSlots,
|
|
101
|
-
defaultSlots,
|
|
102
|
-
)}
|
|
103
|
-
/>
|
|
70
|
+
<Story placeholder='Enter text...' extensions={[listener({ onChange: (text) => console.log(text) })]} />
|
|
104
71
|
),
|
|
105
72
|
};
|