@dxos/react-ui-editor 0.8.2 → 0.8.3-main.7f5a14c
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 +936 -274
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +981 -314
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +936 -274
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/EditorToolbar/util.d.ts +2 -2
- package/dist/types/src/components/Popover/CommandMenu.d.ts +34 -0
- package/dist/types/src/components/Popover/CommandMenu.d.ts.map +1 -0
- package/dist/types/src/components/Popover/RefPopover.d.ts +19 -6
- package/dist/types/src/components/Popover/RefPopover.d.ts.map +1 -1
- package/dist/types/src/components/Popover/index.d.ts +1 -0
- package/dist/types/src/components/Popover/index.d.ts.map +1 -1
- package/dist/types/src/defaults.d.ts.map +1 -1
- package/dist/types/src/extensions/command/menu.d.ts +40 -0
- package/dist/types/src/extensions/command/menu.d.ts.map +1 -1
- package/dist/types/src/extensions/factories.d.ts +1 -0
- package/dist/types/src/extensions/factories.d.ts.map +1 -1
- package/dist/types/src/extensions/hashtag.d.ts +3 -0
- package/dist/types/src/extensions/hashtag.d.ts.map +1 -0
- package/dist/types/src/extensions/index.d.ts +2 -0
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/dist/types/src/extensions/json.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/debug.d.ts +2 -2
- package/dist/types/src/extensions/markdown/debug.d.ts.map +1 -1
- package/dist/types/src/extensions/outliner/outliner.d.ts +1 -3
- package/dist/types/src/extensions/outliner/outliner.d.ts.map +1 -1
- package/dist/types/src/extensions/placeholder.d.ts +4 -0
- package/dist/types/src/extensions/placeholder.d.ts.map +1 -0
- package/dist/types/src/extensions/preview/preview.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextEditor.d.ts +8 -9
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
- package/dist/types/src/stories/Command.stories.d.ts +1 -1
- package/dist/types/src/stories/Command.stories.d.ts.map +1 -1
- package/dist/types/src/stories/CommandMenu.stories.d.ts +12 -0
- package/dist/types/src/stories/CommandMenu.stories.d.ts.map +1 -0
- package/dist/types/src/stories/Comments.stories.d.ts +1 -1
- package/dist/types/src/stories/Comments.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Experimental.stories.d.ts +1 -1
- package/dist/types/src/stories/Experimental.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Markdown.stories.d.ts +1 -1
- package/dist/types/src/stories/Markdown.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Outliner.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Preview.stories.d.ts +1 -1
- package/dist/types/src/stories/Preview.stories.d.ts.map +1 -1
- package/dist/types/src/stories/TextEditor.stories.d.ts +1 -1
- package/dist/types/src/stories/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/stories/components/EditorStory.d.ts +43 -0
- package/dist/types/src/stories/components/EditorStory.d.ts.map +1 -0
- package/dist/types/src/stories/components/index.d.ts +3 -0
- package/dist/types/src/stories/components/index.d.ts.map +1 -0
- package/dist/types/src/stories/{util.d.ts → components/util.d.ts} +3 -18
- package/dist/types/src/stories/components/util.d.ts.map +1 -0
- package/package.json +31 -27
- package/src/components/Popover/CommandMenu.tsx +279 -0
- package/src/components/Popover/RefPopover.tsx +44 -22
- package/src/components/Popover/index.ts +1 -0
- package/src/defaults.ts +1 -0
- package/src/extensions/command/menu.ts +334 -23
- package/src/extensions/factories.ts +4 -1
- package/src/extensions/hashtag.tsx +68 -0
- package/src/extensions/index.ts +2 -0
- package/src/extensions/json.ts +2 -1
- package/src/extensions/markdown/debug.ts +2 -2
- package/src/extensions/outliner/outliner.ts +6 -8
- package/src/extensions/placeholder.ts +82 -0
- package/src/extensions/preview/preview.ts +3 -6
- package/src/hooks/useTextEditor.ts +11 -12
- package/src/stories/Command.stories.tsx +1 -1
- package/src/stories/CommandMenu.stories.tsx +143 -0
- package/src/stories/Comments.stories.tsx +2 -2
- package/src/stories/Experimental.stories.tsx +2 -2
- package/src/stories/Markdown.stories.tsx +2 -2
- package/src/stories/Outliner.stories.tsx +19 -7
- package/src/stories/Preview.stories.tsx +34 -32
- package/src/stories/TextEditor.stories.tsx +3 -3
- package/src/stories/components/EditorStory.tsx +135 -0
- package/src/stories/components/index.ts +6 -0
- package/src/stories/{util.tsx → components/util.tsx} +5 -100
- package/dist/types/src/stories/util.d.ts.map +0 -1
@@ -4,38 +4,23 @@
|
|
4
4
|
|
5
5
|
import { type Completion } from '@codemirror/autocomplete';
|
6
6
|
import { type Extension } from '@codemirror/state';
|
7
|
-
import { type
|
8
|
-
import React, { type ReactNode, useEffect, useState, type FC } from 'react';
|
7
|
+
import React, { type FC } from 'react';
|
9
8
|
|
10
|
-
import { Expando } from '@dxos/echo-schema';
|
11
|
-
import { PublicKey } from '@dxos/keys';
|
12
|
-
import { live } from '@dxos/live-object';
|
13
9
|
import { faker } from '@dxos/random';
|
14
|
-
import {
|
15
|
-
import { useThemeContext, Icon } from '@dxos/react-ui';
|
16
|
-
import { JsonFilter } from '@dxos/react-ui-syntax-highlighter';
|
10
|
+
import { Icon } from '@dxos/react-ui';
|
17
11
|
import { mx } from '@dxos/react-ui-theme';
|
18
12
|
|
19
|
-
import { editorSlots, editorGutter } from '../defaults';
|
20
13
|
import {
|
21
|
-
type DebugNode,
|
22
14
|
type EditorSelectionState,
|
23
|
-
createDataExtensions,
|
24
|
-
createBasicExtensions,
|
25
|
-
createMarkdownExtensions,
|
26
|
-
createThemeExtensions,
|
27
15
|
decorateMarkdown,
|
28
|
-
debugTree,
|
29
16
|
folding,
|
30
17
|
formattingKeymap,
|
31
18
|
image,
|
32
19
|
linkTooltip,
|
33
20
|
table,
|
34
|
-
|
35
|
-
} from '
|
36
|
-
import {
|
37
|
-
import { str } from '../testing';
|
38
|
-
import { createRenderer } from '../util';
|
21
|
+
} from '../../extensions';
|
22
|
+
import { str } from '../../testing';
|
23
|
+
import { createRenderer } from '../../util';
|
39
24
|
|
40
25
|
export const num = () => faker.number.int({ min: 0, max: 9999 }).toLocaleString();
|
41
26
|
|
@@ -244,83 +229,3 @@ export const headings = str(
|
|
244
229
|
);
|
245
230
|
|
246
231
|
export const global = new Map<string, EditorSelectionState>();
|
247
|
-
|
248
|
-
// Type definitions
|
249
|
-
export type DebugMode = 'raw' | 'tree' | 'raw+tree';
|
250
|
-
|
251
|
-
export type StoryProps = {
|
252
|
-
id?: string;
|
253
|
-
debug?: DebugMode;
|
254
|
-
debugCustom?: (view: EditorView) => ReactNode;
|
255
|
-
text?: string;
|
256
|
-
readOnly?: boolean;
|
257
|
-
placeholder?: string;
|
258
|
-
lineNumbers?: boolean;
|
259
|
-
onReady?: (view: EditorView) => void;
|
260
|
-
} & Pick<UseTextEditorProps, 'scrollTo' | 'selection' | 'extensions'> &
|
261
|
-
Pick<ThemeExtensionsOptions, 'slots'>;
|
262
|
-
|
263
|
-
// Default story component
|
264
|
-
export const EditorStory = ({
|
265
|
-
id = 'editor-' + PublicKey.random().toHex().slice(0, 8),
|
266
|
-
debug,
|
267
|
-
debugCustom,
|
268
|
-
text,
|
269
|
-
readOnly,
|
270
|
-
placeholder = 'New document.',
|
271
|
-
lineNumbers,
|
272
|
-
scrollTo,
|
273
|
-
selection,
|
274
|
-
extensions,
|
275
|
-
slots = editorSlots,
|
276
|
-
onReady,
|
277
|
-
}: StoryProps) => {
|
278
|
-
const [object] = useState(createObject(live(Expando, { content: text ?? '' })));
|
279
|
-
const { themeMode } = useThemeContext();
|
280
|
-
const [tree, setTree] = useState<DebugNode>();
|
281
|
-
const { parentRef, focusAttributes, view } = useTextEditor(
|
282
|
-
() => ({
|
283
|
-
id,
|
284
|
-
initialValue: text,
|
285
|
-
extensions: [
|
286
|
-
createDataExtensions({ id, text: createDocAccessor(object, ['content']) }),
|
287
|
-
createBasicExtensions({ readOnly, placeholder, lineNumbers, scrollPastEnd: true }),
|
288
|
-
createMarkdownExtensions({ themeMode }),
|
289
|
-
createThemeExtensions({
|
290
|
-
themeMode,
|
291
|
-
syntaxHighlighting: true,
|
292
|
-
slots,
|
293
|
-
}),
|
294
|
-
editorGutter,
|
295
|
-
extensions || [],
|
296
|
-
debug ? debugTree(setTree) : [],
|
297
|
-
],
|
298
|
-
scrollTo,
|
299
|
-
selection,
|
300
|
-
}),
|
301
|
-
[object, extensions, themeMode],
|
302
|
-
);
|
303
|
-
|
304
|
-
useEffect(() => {
|
305
|
-
if (view) {
|
306
|
-
onReady?.(view);
|
307
|
-
}
|
308
|
-
}, [view]);
|
309
|
-
|
310
|
-
return (
|
311
|
-
<div className={mx('w-full h-full grid overflow-hidden', debug && 'grid-cols-[1fr_600px]')}>
|
312
|
-
<div role='none' className='flex overflow-hidden' ref={parentRef} {...focusAttributes} />
|
313
|
-
{debug && (
|
314
|
-
<div className='grid h-full auto-rows-fr border-l border-separator divide-y divide-separator overflow-hidden'>
|
315
|
-
{view && debugCustom?.(view)}
|
316
|
-
{(debug === 'raw' || debug === 'raw+tree') && (
|
317
|
-
<pre className='p-1 text-xs text-green-800 dark:text-green-200 overflow-auto'>
|
318
|
-
{view?.state.doc.toString()}
|
319
|
-
</pre>
|
320
|
-
)}
|
321
|
-
{(debug === 'tree' || debug === 'raw+tree') && <JsonFilter data={tree} classNames='p-1 text-xs' />}
|
322
|
-
</div>
|
323
|
-
)}
|
324
|
-
</div>
|
325
|
-
);
|
326
|
-
};
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../../src/stories/util.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,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