@dxos/react-ui-editor 0.3.11-next.ee2b64c → 0.4.0
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 +1178 -159
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/hooks.stories.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +8 -4
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +5 -3
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/comments.d.ts +5 -1
- package/dist/types/src/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/formatting.d.ts +55 -10
- package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/formatting.test.d.ts +3 -0
- package/dist/types/src/extensions/markdown/formatting.test.d.ts.map +1 -0
- package/dist/types/src/hooks/useActionHandler.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +3 -3
- package/src/components/TextEditor/hooks.stories.tsx +6 -1
- package/src/components/Toolbar/Toolbar.stories.tsx +16 -4
- package/src/components/Toolbar/Toolbar.tsx +128 -30
- package/src/extensions/comments.ts +2 -2
- package/src/extensions/markdown/formatting.test.ts +482 -0
- package/src/extensions/markdown/formatting.ts +1118 -69
- package/src/hooks/useActionHandler.ts +47 -16
|
@@ -7,13 +7,22 @@ import type { EditorView } from '@codemirror/view';
|
|
|
7
7
|
import type { ToolbarProps } from '../components';
|
|
8
8
|
import {
|
|
9
9
|
createComment,
|
|
10
|
-
insertCodeblock,
|
|
11
10
|
insertTable,
|
|
12
11
|
setHeading,
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
setStyle,
|
|
13
|
+
toggleStyle,
|
|
14
|
+
addLink,
|
|
15
|
+
removeLink,
|
|
16
|
+
Inline,
|
|
17
|
+
List,
|
|
18
|
+
addList,
|
|
19
|
+
removeList,
|
|
15
20
|
toggleList,
|
|
16
|
-
|
|
21
|
+
addBlockquote,
|
|
22
|
+
removeBlockquote,
|
|
23
|
+
addCodeblock,
|
|
24
|
+
removeCodeblock,
|
|
25
|
+
toggleBlockquote,
|
|
17
26
|
} from '../extensions';
|
|
18
27
|
|
|
19
28
|
export const useActionHandler = (view?: EditorView | null): ToolbarProps['onAction'] => {
|
|
@@ -22,32 +31,53 @@ export const useActionHandler = (view?: EditorView | null): ToolbarProps['onActi
|
|
|
22
31
|
return;
|
|
23
32
|
}
|
|
24
33
|
|
|
34
|
+
let inlineType, listType;
|
|
25
35
|
switch (action.type) {
|
|
26
36
|
case 'heading':
|
|
27
37
|
setHeading(parseInt(action.data))(view);
|
|
28
38
|
break;
|
|
29
39
|
|
|
30
|
-
case '
|
|
31
|
-
|
|
32
|
-
break;
|
|
33
|
-
case 'italic':
|
|
34
|
-
toggleItalic(view);
|
|
35
|
-
break;
|
|
40
|
+
case 'strong':
|
|
41
|
+
case 'emphasis':
|
|
36
42
|
case 'strikethrough':
|
|
37
|
-
|
|
43
|
+
case 'code':
|
|
44
|
+
inlineType =
|
|
45
|
+
action.type === 'strong'
|
|
46
|
+
? Inline.Strong
|
|
47
|
+
: action.type === 'emphasis'
|
|
48
|
+
? Inline.Emphasis
|
|
49
|
+
: action.type === 'strikethrough'
|
|
50
|
+
? Inline.Strikethrough
|
|
51
|
+
: Inline.Code;
|
|
52
|
+
(typeof action.data === 'boolean' ? setStyle(inlineType, action.data) : toggleStyle(inlineType))(view);
|
|
38
53
|
break;
|
|
39
54
|
|
|
40
|
-
case 'list':
|
|
41
|
-
|
|
55
|
+
case 'list-ordered':
|
|
56
|
+
case 'list-bullet':
|
|
57
|
+
case 'list-tasks':
|
|
58
|
+
listType =
|
|
59
|
+
action.type === 'list-ordered' ? List.Ordered : action.type === 'list-bullet' ? List.Bullet : List.Task;
|
|
60
|
+
(action.data === false
|
|
61
|
+
? removeList(listType)
|
|
62
|
+
: action.data === true
|
|
63
|
+
? addList(listType)
|
|
64
|
+
: toggleList(listType))(view);
|
|
42
65
|
break;
|
|
43
66
|
|
|
67
|
+
case 'blockquote':
|
|
68
|
+
(action.data === false ? removeBlockquote : action.data === true ? addBlockquote : toggleBlockquote)(view);
|
|
69
|
+
break;
|
|
44
70
|
case 'codeblock':
|
|
45
|
-
|
|
71
|
+
(action.data === false ? removeCodeblock : addCodeblock)(view);
|
|
46
72
|
break;
|
|
47
73
|
case 'table':
|
|
48
74
|
insertTable(view);
|
|
49
75
|
break;
|
|
50
76
|
|
|
77
|
+
case 'link':
|
|
78
|
+
(action.data === false ? removeLink : addLink)(view);
|
|
79
|
+
break;
|
|
80
|
+
|
|
51
81
|
case 'comment':
|
|
52
82
|
createComment(view);
|
|
53
83
|
break;
|
|
@@ -55,8 +85,9 @@ export const useActionHandler = (view?: EditorView | null): ToolbarProps['onActi
|
|
|
55
85
|
|
|
56
86
|
// TODO(burdon): Hack otherwise remains on heading selector.
|
|
57
87
|
setTimeout(() => {
|
|
58
|
-
view.
|
|
59
|
-
|
|
88
|
+
if (!view.hasFocus) {
|
|
89
|
+
view.focus();
|
|
90
|
+
}
|
|
60
91
|
});
|
|
61
92
|
};
|
|
62
93
|
};
|