@dxos/react-ui-editor 0.8.4-main.937b3ca → 0.8.4-main.9be5663bfe
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 +310 -388
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +310 -388
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Editor/Editor.d.ts +9 -15
- package/dist/types/src/components/Editor/Editor.d.ts.map +1 -1
- package/dist/types/src/components/Editor/Editor.stories.d.ts.map +1 -1
- package/dist/types/src/components/EditorContent/EditorContent.d.ts.map +1 -1
- package/dist/types/src/components/EditorMenuProvider/EditorMenuProvider.d.ts +1 -3
- package/dist/types/src/components/EditorMenuProvider/EditorMenuProvider.d.ts.map +1 -1
- package/dist/types/src/components/EditorMenuProvider/menu-presets.d.ts.map +1 -1
- package/dist/types/src/components/EditorMenuProvider/useEditorMenu.d.ts.map +1 -1
- package/dist/types/src/components/EditorPreviewProvider/EditorPreviewProvider.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/EditorToolbar.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/blocks.d.ts +3 -17
- package/dist/types/src/components/EditorToolbar/blocks.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/formatting.d.ts +3 -17
- package/dist/types/src/components/EditorToolbar/formatting.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/headings.d.ts +3 -17
- package/dist/types/src/components/EditorToolbar/headings.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/image.d.ts +3 -8
- package/dist/types/src/components/EditorToolbar/image.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/index.d.ts +0 -1
- package/dist/types/src/components/EditorToolbar/index.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/lists.d.ts +6 -0
- package/dist/types/src/components/EditorToolbar/lists.d.ts.map +1 -0
- package/dist/types/src/components/EditorToolbar/search.d.ts +3 -8
- package/dist/types/src/components/EditorToolbar/search.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/view-mode.d.ts +3 -17
- package/dist/types/src/components/EditorToolbar/view-mode.d.ts.map +1 -1
- package/dist/types/src/stories/Automerge.stories.d.ts +25 -24
- package/dist/types/src/stories/Automerge.stories.d.ts.map +1 -1
- 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/EditorToolbar.stories.d.ts +26 -26
- package/dist/types/src/stories/EditorToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Experimental.stories.d.ts +1 -1
- package/dist/types/src/stories/Markdown.stories.d.ts +1 -1
- package/dist/types/src/stories/Outliner.stories.d.ts +2 -2
- package/dist/types/src/stories/Outliner.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Popover.stories.d.ts +2 -2
- package/dist/types/src/stories/Popover.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/components/EditorStory.d.ts +3 -3
- package/dist/types/src/stories/components/EditorStory.d.ts.map +1 -1
- package/dist/types/src/stories/components/util.d.ts +3 -3
- package/dist/types/src/stories/components/util.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +24 -24
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util/react.d.ts +1 -4
- package/dist/types/src/util/react.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +45 -45
- package/src/components/Editor/Editor.stories.tsx +6 -7
- package/src/components/Editor/Editor.tsx +21 -27
- package/src/components/EditorContent/EditorContent.tsx +1 -2
- package/src/components/EditorMenuProvider/EditorMenuProvider.tsx +21 -28
- package/src/components/EditorMenuProvider/menu-presets.ts +1 -0
- package/src/components/EditorMenuProvider/useEditorMenu.ts +8 -1
- package/src/components/EditorPreviewProvider/EditorPreviewProvider.tsx +5 -7
- package/src/components/EditorToolbar/EditorToolbar.tsx +24 -61
- package/src/components/EditorToolbar/blocks.ts +53 -46
- package/src/components/EditorToolbar/formatting.ts +44 -46
- package/src/components/EditorToolbar/headings.ts +42 -49
- package/src/components/EditorToolbar/image.ts +16 -21
- package/src/components/EditorToolbar/index.ts +0 -1
- package/src/components/EditorToolbar/lists.ts +57 -0
- package/src/components/EditorToolbar/search.ts +16 -21
- package/src/components/EditorToolbar/view-mode.ts +34 -41
- package/src/stories/Automerge.stories.tsx +10 -12
- package/src/stories/Comments.stories.tsx +4 -5
- package/src/stories/EditorToolbar.stories.tsx +32 -17
- package/src/stories/Experimental.stories.tsx +6 -6
- package/src/stories/Markdown.stories.tsx +2 -2
- package/src/stories/Outliner.stories.tsx +4 -5
- package/src/stories/Popover.stories.tsx +9 -10
- package/src/stories/Preview.stories.tsx +60 -51
- package/src/stories/Tags.stories.tsx +5 -5
- package/src/stories/TextEditor.stories.tsx +2 -2
- package/src/stories/Theme.stories.tsx +2 -2
- package/src/stories/components/EditorStory.tsx +17 -12
- package/src/stories/components/util.tsx +49 -50
- package/src/translations.ts +29 -24
- package/src/util/react.tsx +2 -11
- package/dist/types/src/components/EditorToolbar/actions.d.ts +0 -24
- package/dist/types/src/components/EditorToolbar/actions.d.ts.map +0 -1
- package/dist/types/src/stories/CommandDialog.stories.d.ts +0 -14
- package/dist/types/src/stories/CommandDialog.stories.d.ts.map +0 -1
- package/src/components/EditorToolbar/actions.ts +0 -87
- package/src/stories/CommandDialog.stories.tsx +0 -81
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Completion } from '@codemirror/autocomplete';
|
|
6
6
|
import { type Extension } from '@codemirror/state';
|
|
7
|
-
import React, { type FC } from 'react';
|
|
8
7
|
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { random } from '@dxos/random';
|
|
9
|
+
import { Domino } from '@dxos/ui';
|
|
11
10
|
import {
|
|
12
11
|
type EditorSelectionState,
|
|
12
|
+
type RenderCallback,
|
|
13
13
|
decorateMarkdown,
|
|
14
14
|
folding,
|
|
15
15
|
formattingKeymap,
|
|
@@ -17,11 +17,11 @@ import {
|
|
|
17
17
|
linkTooltip,
|
|
18
18
|
table,
|
|
19
19
|
} from '@dxos/ui-editor';
|
|
20
|
-
import {
|
|
20
|
+
import { safeUrl } from '@dxos/util';
|
|
21
21
|
|
|
22
|
-
import {
|
|
22
|
+
import { str } from '../../util';
|
|
23
23
|
|
|
24
|
-
export const num = () =>
|
|
24
|
+
export const num = () => random.number.int({ min: 0, max: 9999 }).toLocaleString();
|
|
25
25
|
|
|
26
26
|
export const img = '';
|
|
27
27
|
|
|
@@ -41,11 +41,11 @@ export const content = {
|
|
|
41
41
|
// prettier-ignore
|
|
42
42
|
'### TaskList',
|
|
43
43
|
'',
|
|
44
|
-
`- [x] ${
|
|
45
|
-
`- [ ] ${
|
|
46
|
-
` - [ ] ${
|
|
47
|
-
` - [ ] ${
|
|
48
|
-
` - [x] ${
|
|
44
|
+
`- [x] ${random.lorem.sentences()}`,
|
|
45
|
+
`- [ ] ${random.lorem.sentences()}`,
|
|
46
|
+
` - [ ] ${random.lorem.sentences()}`,
|
|
47
|
+
` - [ ] ${random.lorem.sentences()}`,
|
|
48
|
+
` - [x] ${random.lorem.sentences()}`,
|
|
49
49
|
'',
|
|
50
50
|
),
|
|
51
51
|
|
|
@@ -53,11 +53,11 @@ export const content = {
|
|
|
53
53
|
// prettier-ignore
|
|
54
54
|
'### BulletList',
|
|
55
55
|
'',
|
|
56
|
-
`- ${
|
|
57
|
-
`- ${
|
|
58
|
-
` - ${
|
|
59
|
-
` - ${
|
|
60
|
-
`- ${
|
|
56
|
+
`- ${random.lorem.sentences()}`,
|
|
57
|
+
`- ${random.lorem.sentences()}`,
|
|
58
|
+
` - ${random.lorem.sentences()}`,
|
|
59
|
+
` - ${random.lorem.sentences()}`,
|
|
60
|
+
`- ${random.lorem.sentences()}`,
|
|
61
61
|
'',
|
|
62
62
|
),
|
|
63
63
|
|
|
@@ -65,17 +65,17 @@ export const content = {
|
|
|
65
65
|
// prettier-ignore
|
|
66
66
|
'### OrderedList (part 1)',
|
|
67
67
|
'',
|
|
68
|
-
`1. ${
|
|
69
|
-
`1. ${
|
|
70
|
-
`1. ${
|
|
71
|
-
` 1. ${
|
|
72
|
-
` 1. ${
|
|
73
|
-
` 1. ${
|
|
74
|
-
`1. ${
|
|
68
|
+
`1. ${random.lorem.sentences()}`,
|
|
69
|
+
`1. ${random.lorem.sentences()}`,
|
|
70
|
+
`1. ${random.lorem.sentences()}`,
|
|
71
|
+
` 1. ${random.lorem.sentences()}`,
|
|
72
|
+
` 1. ${random.lorem.sentences()}`,
|
|
73
|
+
` 1. ${random.lorem.sentences()}`,
|
|
74
|
+
`1. ${random.lorem.sentences()}`,
|
|
75
75
|
'',
|
|
76
76
|
'### OrderedList (part 2)',
|
|
77
77
|
'',
|
|
78
|
-
`1. ${
|
|
78
|
+
`1. ${random.lorem.sentences()}`,
|
|
79
79
|
'',
|
|
80
80
|
),
|
|
81
81
|
|
|
@@ -123,7 +123,7 @@ export const content = {
|
|
|
123
123
|
// prettier-ignore
|
|
124
124
|
'### Tables',
|
|
125
125
|
'',
|
|
126
|
-
`| ${
|
|
126
|
+
`| ${random.lorem.word().padStart(12)} | ${random.lorem.word().padStart(12)} | ${random.lorem.word().padStart(12)} |`,
|
|
127
127
|
`|-${''.padStart(12, '-')}-|-${''.padStart(12, '-')}-|-${''.padStart(12, '-')}-|`,
|
|
128
128
|
`| ${num().padStart(12)} | ${num().padStart(12)} | ${num().padStart(12)} |`,
|
|
129
129
|
`| ${num().padStart(12)} | ${num().padStart(12)} | ${num().padStart(12)} |`,
|
|
@@ -134,7 +134,9 @@ export const content = {
|
|
|
134
134
|
image: str('### Image', '', img),
|
|
135
135
|
|
|
136
136
|
headings: str(
|
|
137
|
-
...[1, 2, 3, 4, 5, 6]
|
|
137
|
+
...[1, 2, 3, 4, 5, 6]
|
|
138
|
+
.map((level) => ['#'.repeat(level) + ` Heading ${level}`, random.lorem.sentences(), ''])
|
|
139
|
+
.flat(),
|
|
138
140
|
),
|
|
139
141
|
|
|
140
142
|
formatting: str(
|
|
@@ -159,7 +161,7 @@ export const content = {
|
|
|
159
161
|
'',
|
|
160
162
|
),
|
|
161
163
|
|
|
162
|
-
paragraphs: str(...
|
|
164
|
+
paragraphs: str(...random.helpers.multiple(() => [random.lorem.paragraph(), ''], { count: 3 }).flat()),
|
|
163
165
|
|
|
164
166
|
footer: str('', '', '', '', ''),
|
|
165
167
|
};
|
|
@@ -204,30 +206,27 @@ export const links: Completion[] = [
|
|
|
204
206
|
export const names = ['adam', 'alice', 'alison', 'bob', 'carol', 'charlie', 'sayuri', 'shoko'];
|
|
205
207
|
|
|
206
208
|
const hover =
|
|
207
|
-
'rounded-
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
209
|
+
'rounded-xs text-base-surface-text text-primary-600 hover:text-primary-500 dark:text-primary-300 hover:dark:text-primary-200';
|
|
210
|
+
|
|
211
|
+
export const renderLinkTooltip: RenderCallback<{ url: string }> = (el, { url }) => {
|
|
212
|
+
el.appendChild(
|
|
213
|
+
Domino.of('a')
|
|
214
|
+
.attributes({ href: url, target: '_blank', rel: 'noreferrer', 'aria-label': 'Open link' })
|
|
215
|
+
.classNames(hover, 'flex items-center gap-2')
|
|
216
|
+
.text(safeUrl(url)?.toString() ?? url)
|
|
217
|
+
.append(Domino.svg('ph--arrow-square-out--regular')).root,
|
|
216
218
|
);
|
|
217
219
|
};
|
|
218
220
|
|
|
219
|
-
export const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
</a>
|
|
221
|
+
export const renderLinkButton: RenderCallback<{ url: string }> = (el, { url }) => {
|
|
222
|
+
el.appendChild(
|
|
223
|
+
Domino.of('span')
|
|
224
|
+
.attributes({ 'aria-hidden': 'true' })
|
|
225
|
+
.classNames(hover, 'ms-1 inline-block align-[-0.125em]')
|
|
226
|
+
.append(Domino.svg('ph--arrow-square-out--regular')).root,
|
|
226
227
|
);
|
|
227
228
|
};
|
|
228
229
|
|
|
229
|
-
export const renderLinkButton = createRenderer(LinkButton);
|
|
230
|
-
|
|
231
230
|
// Shared extensions.
|
|
232
231
|
export const defaultExtensions: Extension[] = [
|
|
233
232
|
decorateMarkdown({ renderLinkButton, selectionChangeDelay: 100 }),
|
|
@@ -245,18 +244,18 @@ export const allExtensions: Extension[] = [
|
|
|
245
244
|
];
|
|
246
245
|
|
|
247
246
|
// Long text for scrolling stories.
|
|
248
|
-
export const longText =
|
|
249
|
-
.multiple(() =>
|
|
247
|
+
export const longText = random.helpers
|
|
248
|
+
.multiple(() => random.lorem.paragraph({ min: 8, max: 16 }), { count: 20 })
|
|
250
249
|
.join('\n\n');
|
|
251
250
|
|
|
252
|
-
export const largeWithImages =
|
|
253
|
-
.multiple(() => [
|
|
251
|
+
export const largeWithImages = random.helpers
|
|
252
|
+
.multiple(() => [random.lorem.paragraph({ min: 12, max: 16 }), img], { count: 20 })
|
|
254
253
|
.flatMap((x) => x)
|
|
255
254
|
.join('\n\n');
|
|
256
255
|
|
|
257
256
|
export const headings = str(
|
|
258
257
|
...[1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 2, 3, 3, 2, 2, 6, 1]
|
|
259
|
-
.map((level) => ['#'.repeat(level) + ' ' +
|
|
258
|
+
.map((level) => ['#'.repeat(level) + ' ' + random.lorem.sentence(3), random.lorem.sentences(), ''])
|
|
260
259
|
.flat(),
|
|
261
260
|
);
|
|
262
261
|
|
package/src/translations.ts
CHANGED
|
@@ -10,30 +10,35 @@ export const translations = [
|
|
|
10
10
|
{
|
|
11
11
|
'en-US': {
|
|
12
12
|
[translationKey]: {
|
|
13
|
-
'
|
|
14
|
-
'
|
|
15
|
-
'
|
|
16
|
-
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
'
|
|
32
|
-
|
|
33
|
-
'
|
|
34
|
-
'
|
|
35
|
-
'
|
|
36
|
-
'
|
|
13
|
+
'comment.label': 'Create comment',
|
|
14
|
+
'image.label': 'Insert image',
|
|
15
|
+
'search.label': 'Search',
|
|
16
|
+
|
|
17
|
+
'block.label': 'Block',
|
|
18
|
+
'block.blockquote.label': 'Block quote',
|
|
19
|
+
'block.codeblock.label': 'Code block',
|
|
20
|
+
'block.table.label': 'Create table',
|
|
21
|
+
|
|
22
|
+
'formatting.label': 'Formatting',
|
|
23
|
+
'formatting.strong.label': 'Bold',
|
|
24
|
+
'formatting.emphasis.label': 'Italics',
|
|
25
|
+
'formatting.strikethrough.label': 'Strikethrough',
|
|
26
|
+
'formatting.code.label': 'Code',
|
|
27
|
+
'formatting.link.label': 'Link',
|
|
28
|
+
|
|
29
|
+
'list.bullet.label': 'Bullet list',
|
|
30
|
+
'list.ordered.label': 'Numbered list',
|
|
31
|
+
'list.task.label': 'Task list',
|
|
32
|
+
|
|
33
|
+
'heading.label': 'Heading level',
|
|
34
|
+
'heading-level.label_zero': 'Paragraph',
|
|
35
|
+
'heading-level.label_one': 'Heading level {{count}}',
|
|
36
|
+
'heading-level.label_other': 'Heading level {{count}}',
|
|
37
|
+
|
|
38
|
+
'view-mode.label': 'Editor view',
|
|
39
|
+
'view-mode.preview.label': 'Markdown',
|
|
40
|
+
'view-mode.source.label': 'Plain text',
|
|
41
|
+
'view-mode.readonly.label': 'Read only',
|
|
37
42
|
},
|
|
38
43
|
},
|
|
39
44
|
},
|
package/src/util/react.tsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, { type FC
|
|
5
|
+
import React, { type FC } from 'react';
|
|
6
6
|
import { createRoot } from 'react-dom/client';
|
|
7
7
|
|
|
8
8
|
import { ThemeProvider, Tooltip } from '@dxos/react-ui';
|
|
@@ -14,22 +14,13 @@ import { defaultTx } from '@dxos/ui-theme';
|
|
|
14
14
|
*/
|
|
15
15
|
export const str = (...lines: string[]) => lines.join('\n');
|
|
16
16
|
|
|
17
|
-
/** @deprecated */
|
|
18
|
-
// TODO(wittjosiah): Replace with portals which are lighter weight and inherit context from the main react tree.
|
|
19
|
-
export const renderRoot = <T extends Element>(root: T, node: ReactNode): T => {
|
|
20
|
-
createRoot(root).render(<ThemeProvider tx={defaultTx}>{node}</ThemeProvider>);
|
|
21
|
-
return root;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
17
|
/**
|
|
25
|
-
* Utility to create a renderer for a React component.
|
|
26
18
|
* @deprecated
|
|
27
19
|
*/
|
|
28
20
|
export const createRenderer =
|
|
29
21
|
<TProps extends object>(Component: FC<TProps>): RenderCallback<TProps> =>
|
|
30
22
|
(el, props) => {
|
|
31
|
-
|
|
32
|
-
el,
|
|
23
|
+
createRoot(el).render(
|
|
33
24
|
<ThemeProvider tx={defaultTx}>
|
|
34
25
|
<Tooltip.Provider>
|
|
35
26
|
<Component {...props} />
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { type EditorView } from '@codemirror/view';
|
|
2
|
-
import { type Node } from '@dxos/app-graph';
|
|
3
|
-
import { type MenuItemGroup, type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';
|
|
4
|
-
import { type MenuActionProperties } from '@dxos/ui-types';
|
|
5
|
-
import { type EditorToolbarState } from './useEditorToolbar';
|
|
6
|
-
export declare const createLists: (state: EditorToolbarState, getView: () => EditorView) => {
|
|
7
|
-
nodes: (Node.NodeArg<any, Record<string, any>> | Readonly<Omit<Readonly<{
|
|
8
|
-
id: string;
|
|
9
|
-
type: string;
|
|
10
|
-
cacheable?: string[];
|
|
11
|
-
properties: Readonly<MenuActionProperties>;
|
|
12
|
-
data: Node.ActionData<never>;
|
|
13
|
-
}>, "properties"> & {
|
|
14
|
-
properties: Readonly<MenuActionProperties>;
|
|
15
|
-
_actionContext?: Node.ActionContext;
|
|
16
|
-
}>)[];
|
|
17
|
-
edges: {
|
|
18
|
-
source: string;
|
|
19
|
-
target: string;
|
|
20
|
-
}[];
|
|
21
|
-
};
|
|
22
|
-
export declare const createEditorAction: (id: string, props: Partial<MenuActionProperties>, invoke: () => void) => Node.Action<MenuActionProperties>;
|
|
23
|
-
export declare const createEditorActionGroup: (id: string, props: Omit<ToolbarMenuActionGroupProperties, "icon">, icon?: string) => MenuItemGroup<ToolbarMenuActionGroupProperties>;
|
|
24
|
-
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../../../src/components/EditorToolbar/actions.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,gCAAgC,EAGtC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAI3D,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAQ7D,eAAO,MAAM,WAAW,GAAI,OAAO,kBAAkB,EAAE,SAAS,MAAM,UAAU;;;;;;;;;;;;;;;CAW/E,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,IAAI,MAAM,EAAE,OAAO,OAAO,CAAC,oBAAoB,CAAC,EAAE,QAAQ,MAAM,IAAI,KAM/F,IAAI,CAAC,MAAM,CAAC,oBAAoB,CACvC,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,IAAI,MAAM,EACV,OAAO,IAAI,CAAC,gCAAgC,EAAE,MAAM,CAAC,EACrD,OAAO,MAAM,KACZ,aAAa,CAAC,gCAAgC,CAShD,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { type StoryObj } from '@storybook/react-vite';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
declare const meta: {
|
|
4
|
-
title: string;
|
|
5
|
-
render: () => React.JSX.Element;
|
|
6
|
-
decorators: import("@storybook/react").Decorator[];
|
|
7
|
-
parameters: {
|
|
8
|
-
layout: string;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
export default meta;
|
|
12
|
-
type Story = StoryObj<typeof meta>;
|
|
13
|
-
export declare const Default: Story;
|
|
14
|
-
//# sourceMappingURL=CommandDialog.stories.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CommandDialog.stories.d.ts","sourceRoot":"","sources":["../../../../src/stories/CommandDialog.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAuC,MAAM,OAAO,CAAC;AA8D5D,QAAA,MAAM,IAAI;;;;;;;CAOqB,CAAC;AAEhC,eAAe,IAAI,CAAC;AAEpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAAU,CAAC"}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type EditorView } from '@codemirror/view';
|
|
6
|
-
|
|
7
|
-
import { type Node } from '@dxos/app-graph';
|
|
8
|
-
import {
|
|
9
|
-
type MenuItemGroup,
|
|
10
|
-
type ToolbarMenuActionGroupProperties,
|
|
11
|
-
createMenuAction,
|
|
12
|
-
createMenuItemGroup,
|
|
13
|
-
} from '@dxos/react-ui-menu';
|
|
14
|
-
import { List, addList, removeList } from '@dxos/ui-editor';
|
|
15
|
-
import { type MenuActionProperties } from '@dxos/ui-types';
|
|
16
|
-
|
|
17
|
-
import { translationKey } from '../../translations';
|
|
18
|
-
|
|
19
|
-
import { type EditorToolbarState } from './useEditorToolbar';
|
|
20
|
-
|
|
21
|
-
const listStyles = {
|
|
22
|
-
bullet: 'ph--list-bullets--regular',
|
|
23
|
-
ordered: 'ph--list-numbers--regular',
|
|
24
|
-
task: 'ph--list-checks--regular',
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const createLists = (state: EditorToolbarState, getView: () => EditorView) => {
|
|
28
|
-
const value = state.listStyle ?? '';
|
|
29
|
-
const listGroupAction = createListGroupAction(value);
|
|
30
|
-
const listActionsMap = createListActions(value, getView);
|
|
31
|
-
return {
|
|
32
|
-
nodes: [listGroupAction as Node.NodeArg<any>, ...listActionsMap],
|
|
33
|
-
edges: [
|
|
34
|
-
{ source: 'root', target: 'list' },
|
|
35
|
-
...listActionsMap.map(({ id }) => ({ source: listGroupAction.id, target: id })),
|
|
36
|
-
],
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export const createEditorAction = (id: string, props: Partial<MenuActionProperties>, invoke: () => void) => {
|
|
41
|
-
const { label = [`${id} label`, { ns: translationKey }], ...rest } = props;
|
|
42
|
-
|
|
43
|
-
return createMenuAction(id, invoke, {
|
|
44
|
-
label,
|
|
45
|
-
...rest,
|
|
46
|
-
}) as Node.Action<MenuActionProperties>;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const createEditorActionGroup = (
|
|
50
|
-
id: string,
|
|
51
|
-
props: Omit<ToolbarMenuActionGroupProperties, 'icon'>,
|
|
52
|
-
icon?: string,
|
|
53
|
-
): MenuItemGroup<ToolbarMenuActionGroupProperties> => {
|
|
54
|
-
const { label = [`${id} label`, { ns: translationKey }], ...rest } = props;
|
|
55
|
-
|
|
56
|
-
return createMenuItemGroup(id, {
|
|
57
|
-
label,
|
|
58
|
-
icon,
|
|
59
|
-
iconOnly: true,
|
|
60
|
-
...rest,
|
|
61
|
-
}) as MenuItemGroup<ToolbarMenuActionGroupProperties>;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const createListGroupAction = (value: string) =>
|
|
65
|
-
createEditorActionGroup('list', {
|
|
66
|
-
variant: 'toggleGroup',
|
|
67
|
-
selectCardinality: 'single',
|
|
68
|
-
value,
|
|
69
|
-
} as ToolbarMenuActionGroupProperties);
|
|
70
|
-
|
|
71
|
-
const createListActions = (value: string, getView: () => EditorView) =>
|
|
72
|
-
Object.entries(listStyles).map(([listStyle, icon]) => {
|
|
73
|
-
const checked = value === listStyle;
|
|
74
|
-
return createEditorAction(`list-${listStyle}`, { checked, icon }, () => {
|
|
75
|
-
const view = getView();
|
|
76
|
-
if (!view) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const listType = listStyle === 'ordered' ? List.Ordered : listStyle === 'bullet' ? List.Bullet : List.Task;
|
|
81
|
-
if (checked) {
|
|
82
|
-
removeList(listType)(view);
|
|
83
|
-
} else {
|
|
84
|
-
addList(listType)(view);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
});
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
-
import React, { type KeyboardEvent, useState } from 'react';
|
|
7
|
-
|
|
8
|
-
import { type Button, IconButton, Input } from '@dxos/react-ui';
|
|
9
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
10
|
-
import { editorWidth, join } from '@dxos/ui-editor';
|
|
11
|
-
import { mx } from '@dxos/ui-theme';
|
|
12
|
-
|
|
13
|
-
import { EditorStory } from './components';
|
|
14
|
-
|
|
15
|
-
// TODO(burdon): Reimplement with Popover.
|
|
16
|
-
const CommandDialog = ({ onAction }: { onAction: (action?: any) => void }) => {
|
|
17
|
-
const [text, setText] = useState('');
|
|
18
|
-
|
|
19
|
-
const handleInsert = () => {
|
|
20
|
-
// TODO(burdon): Use queue ref.
|
|
21
|
-
const link = ``;
|
|
22
|
-
onAction(text.length ? { type: 'insert', text: link } : undefined);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
|
|
26
|
-
switch (event.key) {
|
|
27
|
-
case 'Enter': {
|
|
28
|
-
handleInsert();
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
case 'Escape': {
|
|
32
|
-
onAction();
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
<div className='flex is-full justify-center'>
|
|
40
|
-
<div
|
|
41
|
-
className={mx(
|
|
42
|
-
'flex is-full p-2 gap-2 items-center bg-modalSurface border border-separator rounded-md',
|
|
43
|
-
editorWidth,
|
|
44
|
-
)}
|
|
45
|
-
>
|
|
46
|
-
<Input.Root>
|
|
47
|
-
<Input.TextInput
|
|
48
|
-
autoFocus={true}
|
|
49
|
-
placeholder='Ask a question...'
|
|
50
|
-
value={text}
|
|
51
|
-
onChange={(ev) => setText(ev.target.value)}
|
|
52
|
-
onKeyDown={handleKeyDown}
|
|
53
|
-
/>
|
|
54
|
-
</Input.Root>
|
|
55
|
-
<IconButton
|
|
56
|
-
icon='ph--x--regular'
|
|
57
|
-
label='Cancel'
|
|
58
|
-
iconOnly
|
|
59
|
-
variant='ghost'
|
|
60
|
-
classNames='pli-0'
|
|
61
|
-
onClick={() => onAction({ type: 'cancel' })}
|
|
62
|
-
/>
|
|
63
|
-
</div>
|
|
64
|
-
</div>
|
|
65
|
-
);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const meta = {
|
|
69
|
-
title: 'ui/react-ui-editor/CommandDialog',
|
|
70
|
-
render: () => <EditorStory text={join('# Command', '', '')} extensions={[]} />,
|
|
71
|
-
decorators: [withTheme],
|
|
72
|
-
parameters: {
|
|
73
|
-
layout: 'fullscreen',
|
|
74
|
-
},
|
|
75
|
-
} satisfies Meta<typeof Button>;
|
|
76
|
-
|
|
77
|
-
export default meta;
|
|
78
|
-
|
|
79
|
-
type Story = StoryObj<typeof meta>;
|
|
80
|
-
|
|
81
|
-
export const Default: Story = {};
|