@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.
Files changed (25) hide show
  1. package/dist/lib/browser/index.mjs +1178 -159
  2. package/dist/lib/browser/index.mjs.map +3 -3
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
  5. package/dist/types/src/components/TextEditor/hooks.stories.d.ts.map +1 -1
  6. package/dist/types/src/components/Toolbar/Toolbar.d.ts +8 -4
  7. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
  8. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +5 -3
  9. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
  10. package/dist/types/src/extensions/comments.d.ts +5 -1
  11. package/dist/types/src/extensions/comments.d.ts.map +1 -1
  12. package/dist/types/src/extensions/markdown/formatting.d.ts +55 -10
  13. package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -1
  14. package/dist/types/src/extensions/markdown/formatting.test.d.ts +3 -0
  15. package/dist/types/src/extensions/markdown/formatting.test.d.ts.map +1 -0
  16. package/dist/types/src/hooks/useActionHandler.d.ts.map +1 -1
  17. package/package.json +24 -24
  18. package/src/components/TextEditor/MarkdownEditor.stories.tsx +3 -3
  19. package/src/components/TextEditor/hooks.stories.tsx +6 -1
  20. package/src/components/Toolbar/Toolbar.stories.tsx +16 -4
  21. package/src/components/Toolbar/Toolbar.tsx +128 -30
  22. package/src/extensions/comments.ts +2 -2
  23. package/src/extensions/markdown/formatting.test.ts +482 -0
  24. package/src/extensions/markdown/formatting.ts +1118 -69
  25. 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
- toggleBold,
14
- toggleItalic,
12
+ setStyle,
13
+ toggleStyle,
14
+ addLink,
15
+ removeLink,
16
+ Inline,
17
+ List,
18
+ addList,
19
+ removeList,
15
20
  toggleList,
16
- toggleStrikethrough,
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 'bold':
31
- toggleBold(view);
32
- break;
33
- case 'italic':
34
- toggleItalic(view);
35
- break;
40
+ case 'strong':
41
+ case 'emphasis':
36
42
  case 'strikethrough':
37
- toggleStrikethrough(view);
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
- toggleList(view);
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
- insertCodeblock(view);
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.focus();
59
- view.dispatch({ selection: view.state.selection });
88
+ if (!view.hasFocus) {
89
+ view.focus();
90
+ }
60
91
  });
61
92
  };
62
93
  };