@dxos/react-ui-editor 0.3.11-main.5cbcf4e → 0.3.11-main.5e05862

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.
@@ -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,28 +31,51 @@ 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);
40
+ case 'strong':
41
+ case 'emphasis':
42
+ case 'strikethrough':
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);
32
53
  break;
33
- case 'italic':
34
- toggleItalic(view);
54
+
55
+ case 'link':
56
+ (action.data === false ? removeLink : addLink)(view);
35
57
  break;
36
- case 'strikethrough':
37
- toggleStrikethrough(view);
58
+
59
+ case 'list-ordered':
60
+ case 'list-bullet':
61
+ case 'list-tasks':
62
+ listType =
63
+ action.type === 'list-ordered' ? List.Ordered : action.type === 'list-bullet' ? List.Bullet : List.Task;
64
+ (action.data === false
65
+ ? removeList(listType)
66
+ : action.data === true
67
+ ? addList(listType)
68
+ : toggleList(listType))(view);
38
69
  break;
39
70
 
40
- case 'list':
41
- toggleList(view);
71
+ case 'blockquote':
72
+ (action.data === false ? removeBlockquote : action.data === true ? addBlockquote : toggleBlockquote)(view);
42
73
  break;
43
74
 
44
75
  case 'codeblock':
45
- insertCodeblock(view);
76
+ (action.data === false ? removeCodeblock : addCodeblock)(view);
46
77
  break;
78
+
47
79
  case 'table':
48
80
  insertTable(view);
49
81
  break;
@@ -55,8 +87,9 @@ export const useActionHandler = (view?: EditorView | null): ToolbarProps['onActi
55
87
 
56
88
  // TODO(burdon): Hack otherwise remains on heading selector.
57
89
  setTimeout(() => {
58
- view.focus();
59
- view.dispatch({ selection: view.state.selection });
90
+ if (!view.hasFocus) {
91
+ view.focus();
92
+ }
60
93
  });
61
94
  };
62
95
  };