@dxos/react-ui-editor 0.8.4-main.b97322e → 0.8.4-main.c4373fc

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 (275) hide show
  1. package/dist/lib/browser/{chunk-22UMM3QJ.mjs → chunk-HL3YF6WC.mjs} +2 -2
  2. package/dist/lib/browser/chunk-HL3YF6WC.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +3082 -1957
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +71 -1
  7. package/dist/lib/browser/testing/index.mjs.map +4 -4
  8. package/dist/lib/browser/types/index.mjs +1 -1
  9. package/dist/lib/node-esm/{chunk-YXYQPV6R.mjs → chunk-YJZGD3LY.mjs} +2 -2
  10. package/dist/lib/node-esm/chunk-YJZGD3LY.mjs.map +7 -0
  11. package/dist/lib/node-esm/index.mjs +3082 -1957
  12. package/dist/lib/node-esm/index.mjs.map +4 -4
  13. package/dist/lib/node-esm/meta.json +1 -1
  14. package/dist/lib/node-esm/testing/index.mjs +71 -1
  15. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  16. package/dist/lib/node-esm/types/index.mjs +1 -1
  17. package/dist/types/src/components/{Popover → CommandMenu}/CommandMenu.d.ts +10 -6
  18. package/dist/types/src/components/CommandMenu/CommandMenu.d.ts.map +1 -0
  19. package/dist/types/src/components/CommandMenu/index.d.ts +2 -0
  20. package/dist/types/src/components/CommandMenu/index.d.ts.map +1 -0
  21. package/dist/types/src/components/Editor/Editor.d.ts +15 -9
  22. package/dist/types/src/components/Editor/Editor.d.ts.map +1 -1
  23. package/dist/types/src/components/EditorToolbar/EditorToolbar.d.ts.map +1 -1
  24. package/dist/types/src/components/EditorToolbar/blocks.d.ts.map +1 -1
  25. package/dist/types/src/components/EditorToolbar/formatting.d.ts.map +1 -1
  26. package/dist/types/src/components/EditorToolbar/headings.d.ts.map +1 -1
  27. package/dist/types/src/components/EditorToolbar/image.d.ts.map +1 -1
  28. package/dist/types/src/components/EditorToolbar/lists.d.ts.map +1 -1
  29. package/dist/types/src/components/EditorToolbar/search.d.ts.map +1 -1
  30. package/dist/types/src/components/EditorToolbar/util.d.ts +5 -5
  31. package/dist/types/src/components/EditorToolbar/util.d.ts.map +1 -1
  32. package/dist/types/src/components/EditorToolbar/view-mode.d.ts +1 -1
  33. package/dist/types/src/components/EditorToolbar/view-mode.d.ts.map +1 -1
  34. package/dist/types/src/components/index.d.ts +1 -1
  35. package/dist/types/src/components/index.d.ts.map +1 -1
  36. package/dist/types/src/defaults.d.ts.map +1 -1
  37. package/dist/types/src/extensions/autocomplete.d.ts +20 -7
  38. package/dist/types/src/extensions/autocomplete.d.ts.map +1 -1
  39. package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
  40. package/dist/types/src/extensions/automerge/automerge.stories.d.ts +10 -19
  41. package/dist/types/src/extensions/automerge/automerge.stories.d.ts.map +1 -1
  42. package/dist/types/src/extensions/automerge/defs.d.ts +1 -1
  43. package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
  44. package/dist/types/src/extensions/automerge/sync.d.ts.map +1 -1
  45. package/dist/types/src/extensions/automerge/update-automerge.d.ts.map +1 -1
  46. package/dist/types/src/extensions/autoscroll.d.ts +10 -0
  47. package/dist/types/src/extensions/autoscroll.d.ts.map +1 -0
  48. package/dist/types/src/extensions/{command → command-dialog}/action.d.ts +1 -1
  49. package/dist/types/src/extensions/command-dialog/action.d.ts.map +1 -0
  50. package/dist/types/src/extensions/{command/command.d.ts → command-dialog/command-dialog.d.ts} +2 -2
  51. package/dist/types/src/extensions/command-dialog/command-dialog.d.ts.map +1 -0
  52. package/dist/types/src/extensions/{command → command-dialog}/hint.d.ts +2 -7
  53. package/dist/types/src/extensions/command-dialog/hint.d.ts.map +1 -0
  54. package/dist/types/src/extensions/command-dialog/index.d.ts +4 -0
  55. package/dist/types/src/extensions/command-dialog/index.d.ts.map +1 -0
  56. package/dist/types/src/extensions/{command → command-dialog}/state.d.ts +1 -1
  57. package/dist/types/src/extensions/command-dialog/state.d.ts.map +1 -0
  58. package/dist/types/src/extensions/command-dialog/typeahead.d.ts.map +1 -0
  59. package/dist/types/src/extensions/{command → command-menu}/command-menu.d.ts +3 -3
  60. package/dist/types/src/extensions/command-menu/command-menu.d.ts.map +1 -0
  61. package/dist/types/src/extensions/command-menu/index.d.ts +3 -0
  62. package/dist/types/src/extensions/command-menu/index.d.ts.map +1 -0
  63. package/dist/types/src/extensions/command-menu/placeholder.d.ts.map +1 -0
  64. package/dist/types/src/extensions/command-menu/useCommandMenu.d.ts +24 -0
  65. package/dist/types/src/extensions/command-menu/useCommandMenu.d.ts.map +1 -0
  66. package/dist/types/src/extensions/comments.d.ts +1 -1
  67. package/dist/types/src/extensions/comments.d.ts.map +1 -1
  68. package/dist/types/src/extensions/dnd.d.ts.map +1 -1
  69. package/dist/types/src/extensions/factories.d.ts +8 -8
  70. package/dist/types/src/extensions/factories.d.ts.map +1 -1
  71. package/dist/types/src/extensions/floating-menu.d.ts.map +1 -0
  72. package/dist/types/src/extensions/focus.d.ts.map +1 -1
  73. package/dist/types/src/extensions/folding.d.ts.map +1 -1
  74. package/dist/types/src/extensions/index.d.ts +5 -1
  75. package/dist/types/src/extensions/index.d.ts.map +1 -1
  76. package/dist/types/src/extensions/json.d.ts +1 -1
  77. package/dist/types/src/extensions/json.d.ts.map +1 -1
  78. package/dist/types/src/extensions/markdown/action.d.ts.map +1 -1
  79. package/dist/types/src/extensions/markdown/bundle.d.ts +8 -2
  80. package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
  81. package/dist/types/src/extensions/markdown/changes.d.ts +1 -1
  82. package/dist/types/src/extensions/markdown/changes.d.ts.map +1 -1
  83. package/dist/types/src/extensions/markdown/decorate.d.ts +9 -1
  84. package/dist/types/src/extensions/markdown/decorate.d.ts.map +1 -1
  85. package/dist/types/src/extensions/markdown/formatting.d.ts +1 -1
  86. package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -1
  87. package/dist/types/src/extensions/markdown/formatting.test.d.ts.map +1 -1
  88. package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -1
  89. package/dist/types/src/extensions/markdown/image.d.ts.map +1 -1
  90. package/dist/types/src/extensions/markdown/link.d.ts.map +1 -1
  91. package/dist/types/src/extensions/outliner/outliner.d.ts +1 -1
  92. package/dist/types/src/extensions/outliner/outliner.d.ts.map +1 -1
  93. package/dist/types/src/extensions/outliner/selection.d.ts.map +1 -1
  94. package/dist/types/src/extensions/outliner/tree.d.ts +2 -2
  95. package/dist/types/src/extensions/outliner/tree.d.ts.map +1 -1
  96. package/dist/types/src/extensions/preview/preview.d.ts +3 -6
  97. package/dist/types/src/extensions/preview/preview.d.ts.map +1 -1
  98. package/dist/types/src/extensions/tags/extended-markdown.d.ts +10 -0
  99. package/dist/types/src/extensions/tags/extended-markdown.d.ts.map +1 -0
  100. package/dist/types/src/extensions/tags/extended-markdown.test.d.ts +2 -0
  101. package/dist/types/src/extensions/tags/extended-markdown.test.d.ts.map +1 -0
  102. package/dist/types/src/extensions/tags/index.d.ts +4 -0
  103. package/dist/types/src/extensions/tags/index.d.ts.map +1 -0
  104. package/dist/types/src/extensions/tags/streamer.d.ts +12 -0
  105. package/dist/types/src/extensions/tags/streamer.d.ts.map +1 -0
  106. package/dist/types/src/extensions/tags/xml-tags.d.ts +72 -0
  107. package/dist/types/src/extensions/tags/xml-tags.d.ts.map +1 -0
  108. package/dist/types/src/extensions/tags/xml-util.d.ts +10 -0
  109. package/dist/types/src/extensions/tags/xml-util.d.ts.map +1 -0
  110. package/dist/types/src/hooks/useTextEditor.d.ts +2 -2
  111. package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
  112. package/dist/types/src/stories/CommandDialog.stories.d.ts +14 -0
  113. package/dist/types/src/stories/CommandDialog.stories.d.ts.map +1 -0
  114. package/dist/types/src/stories/CommandMenu.stories.d.ts +10 -4
  115. package/dist/types/src/stories/CommandMenu.stories.d.ts.map +1 -1
  116. package/dist/types/src/stories/Comments.stories.d.ts +21 -10
  117. package/dist/types/src/stories/Comments.stories.d.ts.map +1 -1
  118. package/dist/types/src/stories/EditorToolbar.stories.d.ts +39 -3
  119. package/dist/types/src/stories/EditorToolbar.stories.d.ts.map +1 -1
  120. package/dist/types/src/stories/Experimental.stories.d.ts +22 -13
  121. package/dist/types/src/stories/Experimental.stories.d.ts.map +1 -1
  122. package/dist/types/src/stories/Markdown.stories.d.ts +32 -43
  123. package/dist/types/src/stories/Markdown.stories.d.ts.map +1 -1
  124. package/dist/types/src/stories/Outliner.stories.d.ts +15 -21
  125. package/dist/types/src/stories/Outliner.stories.d.ts.map +1 -1
  126. package/dist/types/src/stories/Preview.stories.d.ts +21 -7
  127. package/dist/types/src/stories/Preview.stories.d.ts.map +1 -1
  128. package/dist/types/src/stories/Tags.stories.d.ts +16 -0
  129. package/dist/types/src/stories/Tags.stories.d.ts.map +1 -0
  130. package/dist/types/src/stories/TextEditor.stories.d.ts +38 -52
  131. package/dist/types/src/stories/TextEditor.stories.d.ts.map +1 -1
  132. package/dist/types/src/stories/components/EditorStory.d.ts +6 -9
  133. package/dist/types/src/stories/components/EditorStory.d.ts.map +1 -1
  134. package/dist/types/src/styles/theme.d.ts.map +1 -1
  135. package/dist/types/src/testing/PreviewPopover.d.ts +20 -0
  136. package/dist/types/src/testing/PreviewPopover.d.ts.map +1 -0
  137. package/dist/types/src/testing/index.d.ts +1 -0
  138. package/dist/types/src/testing/index.d.ts.map +1 -1
  139. package/dist/types/src/testing/util.d.ts +1 -0
  140. package/dist/types/src/testing/util.d.ts.map +1 -1
  141. package/dist/types/src/translations.d.ts +1 -1
  142. package/dist/types/src/types/types.d.ts +2 -2
  143. package/dist/types/src/types/types.d.ts.map +1 -1
  144. package/dist/types/src/util/cursor.d.ts.map +1 -1
  145. package/dist/types/src/util/debug.d.ts +1 -1
  146. package/dist/types/src/util/debug.d.ts.map +1 -1
  147. package/dist/types/src/util/decorations.d.ts +4 -0
  148. package/dist/types/src/util/decorations.d.ts.map +1 -0
  149. package/dist/types/src/util/dom.d.ts +2 -12
  150. package/dist/types/src/util/dom.d.ts.map +1 -1
  151. package/dist/types/src/util/index.d.ts +1 -0
  152. package/dist/types/src/util/index.d.ts.map +1 -1
  153. package/dist/types/src/util/react.d.ts +1 -1
  154. package/dist/types/src/util/react.d.ts.map +1 -1
  155. package/dist/types/tsconfig.tsbuildinfo +1 -1
  156. package/package.json +68 -60
  157. package/src/components/{Popover → CommandMenu}/CommandMenu.tsx +95 -26
  158. package/src/components/{Popover → CommandMenu}/index.ts +0 -2
  159. package/src/components/Editor/Editor.tsx +50 -15
  160. package/src/components/EditorToolbar/EditorToolbar.tsx +41 -30
  161. package/src/components/EditorToolbar/blocks.ts +21 -24
  162. package/src/components/EditorToolbar/formatting.ts +22 -25
  163. package/src/components/EditorToolbar/headings.ts +10 -5
  164. package/src/components/EditorToolbar/image.ts +8 -4
  165. package/src/components/EditorToolbar/lists.ts +16 -19
  166. package/src/components/EditorToolbar/search.ts +8 -4
  167. package/src/components/EditorToolbar/util.ts +16 -5
  168. package/src/components/EditorToolbar/view-mode.ts +11 -6
  169. package/src/components/index.ts +1 -1
  170. package/src/defaults.ts +5 -2
  171. package/src/extensions/autocomplete.ts +204 -54
  172. package/src/extensions/automerge/automerge.stories.tsx +31 -24
  173. package/src/extensions/automerge/automerge.ts +4 -3
  174. package/src/extensions/automerge/defs.ts +1 -1
  175. package/src/extensions/automerge/sync.ts +1 -1
  176. package/src/extensions/automerge/update-automerge.ts +1 -1
  177. package/src/extensions/autoscroll.ts +157 -0
  178. package/src/extensions/awareness/awareness.ts +2 -2
  179. package/src/extensions/{command → command-dialog}/action.ts +2 -3
  180. package/src/extensions/{command/command.ts → command-dialog/command-dialog.ts} +4 -4
  181. package/src/extensions/{command → command-dialog}/hint.ts +2 -1
  182. package/src/extensions/command-dialog/index.ts +7 -0
  183. package/src/extensions/{command → command-dialog}/state.ts +4 -3
  184. package/src/extensions/{command → command-dialog}/typeahead.ts +2 -2
  185. package/src/extensions/{command → command-menu}/command-menu.ts +9 -9
  186. package/src/extensions/command-menu/index.ts +6 -0
  187. package/src/extensions/{command → command-menu}/placeholder.ts +1 -1
  188. package/src/extensions/{command → command-menu}/useCommandMenu.ts +35 -19
  189. package/src/extensions/comments.ts +18 -13
  190. package/src/extensions/dnd.ts +1 -1
  191. package/src/extensions/factories.ts +56 -31
  192. package/src/extensions/{command/floating-menu.ts → floating-menu.ts} +12 -19
  193. package/src/extensions/focus.ts +5 -4
  194. package/src/extensions/folding.tsx +4 -6
  195. package/src/extensions/hashtag.tsx +2 -2
  196. package/src/extensions/index.ts +5 -1
  197. package/src/extensions/json.ts +1 -1
  198. package/src/extensions/markdown/action.ts +2 -1
  199. package/src/extensions/markdown/bundle.ts +27 -5
  200. package/src/extensions/markdown/changes.ts +1 -1
  201. package/src/extensions/markdown/decorate.ts +24 -14
  202. package/src/extensions/markdown/formatting.test.ts +6 -6
  203. package/src/extensions/markdown/formatting.ts +3 -3
  204. package/src/extensions/markdown/highlight.ts +1 -1
  205. package/src/extensions/markdown/image.ts +3 -4
  206. package/src/extensions/markdown/link.ts +3 -0
  207. package/src/extensions/markdown/table.ts +7 -1
  208. package/src/extensions/mention.ts +1 -1
  209. package/src/extensions/outliner/outliner.test.ts +3 -2
  210. package/src/extensions/outliner/outliner.ts +6 -5
  211. package/src/extensions/outliner/selection.ts +1 -1
  212. package/src/extensions/outliner/tree.test.ts +2 -1
  213. package/src/extensions/outliner/tree.ts +2 -2
  214. package/src/extensions/preview/preview.ts +59 -62
  215. package/src/extensions/selection.ts +2 -2
  216. package/src/extensions/tags/extended-markdown.test.ts +261 -0
  217. package/src/extensions/tags/extended-markdown.ts +78 -0
  218. package/src/extensions/tags/index.ts +7 -0
  219. package/src/extensions/tags/streamer.ts +243 -0
  220. package/src/extensions/tags/xml-tags.ts +393 -0
  221. package/src/extensions/tags/xml-util.ts +94 -0
  222. package/src/hooks/useTextEditor.ts +8 -20
  223. package/src/stories/CommandDialog.stories.tsx +89 -0
  224. package/src/stories/CommandMenu.stories.tsx +33 -34
  225. package/src/stories/Comments.stories.tsx +14 -10
  226. package/src/stories/EditorToolbar.stories.tsx +13 -12
  227. package/src/stories/Experimental.stories.tsx +17 -13
  228. package/src/stories/Markdown.stories.tsx +25 -21
  229. package/src/stories/Outliner.stories.tsx +46 -34
  230. package/src/stories/Preview.stories.tsx +34 -33
  231. package/src/stories/Tags.stories.tsx +81 -0
  232. package/src/stories/TextEditor.stories.tsx +45 -38
  233. package/src/stories/components/EditorStory.tsx +14 -15
  234. package/src/styles/theme.ts +15 -12
  235. package/src/testing/PreviewPopover.tsx +78 -0
  236. package/src/testing/index.ts +1 -0
  237. package/src/testing/util.ts +2 -0
  238. package/src/translations.ts +1 -1
  239. package/src/types/types.ts +1 -1
  240. package/src/util/cursor.ts +2 -1
  241. package/src/util/debug.ts +2 -2
  242. package/src/util/decorations.ts +21 -0
  243. package/src/util/dom.ts +5 -27
  244. package/src/util/index.ts +1 -0
  245. package/src/util/react.tsx +1 -1
  246. package/dist/lib/browser/chunk-22UMM3QJ.mjs.map +0 -7
  247. package/dist/lib/node-esm/chunk-YXYQPV6R.mjs.map +0 -7
  248. package/dist/types/src/components/Popover/CommandMenu.d.ts.map +0 -1
  249. package/dist/types/src/components/Popover/RefDropdownMenu.d.ts +0 -21
  250. package/dist/types/src/components/Popover/RefDropdownMenu.d.ts.map +0 -1
  251. package/dist/types/src/components/Popover/RefPopover.d.ts +0 -34
  252. package/dist/types/src/components/Popover/RefPopover.d.ts.map +0 -1
  253. package/dist/types/src/components/Popover/index.d.ts +0 -4
  254. package/dist/types/src/components/Popover/index.d.ts.map +0 -1
  255. package/dist/types/src/extensions/command/action.d.ts.map +0 -1
  256. package/dist/types/src/extensions/command/command-menu.d.ts.map +0 -1
  257. package/dist/types/src/extensions/command/command.d.ts.map +0 -1
  258. package/dist/types/src/extensions/command/floating-menu.d.ts.map +0 -1
  259. package/dist/types/src/extensions/command/hint.d.ts.map +0 -1
  260. package/dist/types/src/extensions/command/index.d.ts +0 -7
  261. package/dist/types/src/extensions/command/index.d.ts.map +0 -1
  262. package/dist/types/src/extensions/command/placeholder.d.ts.map +0 -1
  263. package/dist/types/src/extensions/command/state.d.ts.map +0 -1
  264. package/dist/types/src/extensions/command/typeahead.d.ts.map +0 -1
  265. package/dist/types/src/extensions/command/useCommandMenu.d.ts +0 -26
  266. package/dist/types/src/extensions/command/useCommandMenu.d.ts.map +0 -1
  267. package/dist/types/src/stories/Command.stories.d.ts +0 -7
  268. package/dist/types/src/stories/Command.stories.d.ts.map +0 -1
  269. package/src/components/Popover/RefDropdownMenu.tsx +0 -85
  270. package/src/components/Popover/RefPopover.tsx +0 -99
  271. package/src/extensions/command/index.ts +0 -10
  272. package/src/stories/Command.stories.tsx +0 -97
  273. /package/dist/types/src/extensions/{command → command-dialog}/typeahead.d.ts +0 -0
  274. /package/dist/types/src/extensions/{command → command-menu}/placeholder.d.ts +0 -0
  275. /package/dist/types/src/extensions/{command/floating-menu.d.ts → floating-menu.d.ts} +0 -0
@@ -7,8 +7,9 @@ import { type EditorView } from '@codemirror/view';
7
7
  import { type NodeArg } from '@dxos/app-graph';
8
8
  import { type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';
9
9
 
10
- import { createEditorAction, createEditorActionGroup, type EditorToolbarState } from './util';
11
- import { addLink, Inline, removeLink, setStyle, type Formatting } from '../../extensions';
10
+ import { type Formatting, Inline, addLink, removeLink, setStyle } from '../../extensions';
11
+
12
+ import { type EditorToolbarState, createEditorAction, createEditorActionGroup } from './util';
12
13
 
13
14
  const formats = {
14
15
  strong: 'ph--text-b--regular',
@@ -28,31 +29,27 @@ const createFormattingGroup = (formatting: Formatting) =>
28
29
  const createFormattingActions = (formatting: Formatting, getView: () => EditorView) =>
29
30
  Object.entries(formats).map(([type, icon]) => {
30
31
  const checked = !!formatting[type as keyof Formatting];
31
- return createEditorAction(
32
- type,
33
- () => {
34
- const view = getView();
35
- if (!view) {
36
- return;
37
- }
32
+ return createEditorAction(type, { checked, icon }, () => {
33
+ const view = getView();
34
+ if (!view) {
35
+ return;
36
+ }
38
37
 
39
- if (type === 'link') {
40
- checked ? removeLink(view) : addLink()(view);
41
- return;
42
- }
38
+ if (type === 'link') {
39
+ checked ? removeLink(view) : addLink()(view);
40
+ return;
41
+ }
43
42
 
44
- const inlineType =
45
- type === 'strong'
46
- ? Inline.Strong
47
- : type === 'emphasis'
48
- ? Inline.Emphasis
49
- : type === 'strikethrough'
50
- ? Inline.Strikethrough
51
- : Inline.Code;
52
- setStyle(inlineType, !checked)(view);
53
- },
54
- { checked, icon },
55
- );
43
+ const inlineType =
44
+ type === 'strong'
45
+ ? Inline.Strong
46
+ : type === 'emphasis'
47
+ ? Inline.Emphasis
48
+ : type === 'strikethrough'
49
+ ? Inline.Strikethrough
50
+ : Inline.Code;
51
+ setStyle(inlineType, !checked)(view);
52
+ });
56
53
  });
57
54
 
58
55
  export const createFormatting = (state: EditorToolbarState, getView: () => EditorView) => {
@@ -7,10 +7,11 @@ import { type EditorView } from '@codemirror/view';
7
7
  import { type NodeArg } from '@dxos/app-graph';
8
8
  import { type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';
9
9
 
10
- import { createEditorAction, createEditorActionGroup, type EditorToolbarState } from './util';
11
10
  import { setHeading } from '../../extensions';
12
11
  import { translationKey } from '../../translations';
13
12
 
13
+ import { type EditorToolbarState, createEditorAction, createEditorActionGroup } from './util';
14
+
14
15
  const createHeadingGroupAction = (value: string) =>
15
16
  createEditorActionGroup(
16
17
  'heading',
@@ -34,10 +35,14 @@ const createHeadingActions = (getView: () => EditorView) =>
34
35
  '6': 'ph--text-h-six--regular',
35
36
  }).map(([levelStr, icon]) => {
36
37
  const level = parseInt(levelStr);
37
- return createEditorAction(`heading--${levelStr}`, () => setHeading(level)(getView()), {
38
- label: ['heading level label', { count: level, ns: translationKey }],
39
- icon,
40
- });
38
+ return createEditorAction(
39
+ `heading--${levelStr}`,
40
+ {
41
+ label: ['heading level label', { count: level, ns: translationKey }],
42
+ icon,
43
+ },
44
+ () => setHeading(level)(getView()),
45
+ );
41
46
  });
42
47
 
43
48
  const computeHeadingValue = (state: EditorToolbarState) => {
@@ -5,10 +5,14 @@
5
5
  import { createEditorAction } from './util';
6
6
 
7
7
  const createImageUploadAction = (onImageUpload: () => void) =>
8
- createEditorAction('image', onImageUpload, {
9
- testId: 'editor.toolbar.image',
10
- icon: 'ph--image-square--regular',
11
- });
8
+ createEditorAction(
9
+ 'image',
10
+ {
11
+ testId: 'editor.toolbar.image',
12
+ icon: 'ph--image-square--regular',
13
+ },
14
+ onImageUpload,
15
+ );
12
16
 
13
17
  export const createImageUpload = (onImageUpload: () => void) => ({
14
18
  nodes: [createImageUploadAction(onImageUpload)],
@@ -7,8 +7,9 @@ import { type EditorView } from '@codemirror/view';
7
7
  import { type NodeArg } from '@dxos/app-graph';
8
8
  import { type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';
9
9
 
10
- import { createEditorAction, createEditorActionGroup, type EditorToolbarState } from './util';
11
- import { addList, List, removeList } from '../../extensions';
10
+ import { List, addList, removeList } from '../../extensions';
11
+
12
+ import { type EditorToolbarState, createEditorAction, createEditorActionGroup } from './util';
12
13
 
13
14
  const listStyles = {
14
15
  bullet: 'ph--list-bullets--regular',
@@ -26,23 +27,19 @@ const createListGroupAction = (value: string) =>
26
27
  const createListActions = (value: string, getView: () => EditorView) =>
27
28
  Object.entries(listStyles).map(([listStyle, icon]) => {
28
29
  const checked = value === listStyle;
29
- return createEditorAction(
30
- `list-${listStyle}`,
31
- () => {
32
- const view = getView();
33
- if (!view) {
34
- return;
35
- }
36
-
37
- const listType = listStyle === 'ordered' ? List.Ordered : listStyle === 'bullet' ? List.Bullet : List.Task;
38
- if (checked) {
39
- removeList(listType)(view);
40
- } else {
41
- addList(listType)(view);
42
- }
43
- },
44
- { checked, icon },
45
- );
30
+ return createEditorAction(`list-${listStyle}`, { checked, icon }, () => {
31
+ const view = getView();
32
+ if (!view) {
33
+ return;
34
+ }
35
+
36
+ const listType = listStyle === 'ordered' ? List.Ordered : listStyle === 'bullet' ? List.Bullet : List.Task;
37
+ if (checked) {
38
+ removeList(listType)(view);
39
+ } else {
40
+ addList(listType)(view);
41
+ }
42
+ });
46
43
  });
47
44
 
48
45
  export const createLists = (state: EditorToolbarState, getView: () => EditorView) => {
@@ -8,10 +8,14 @@ import { type EditorView } from '@codemirror/view';
8
8
  import { createEditorAction } from './util';
9
9
 
10
10
  const createSearchAction = (getView: () => EditorView) =>
11
- createEditorAction('search', () => openSearchPanel(getView()), {
12
- testId: 'editor.toolbar.search',
13
- icon: 'ph--magnifying-glass--regular',
14
- });
11
+ createEditorAction(
12
+ 'search',
13
+ {
14
+ testId: 'editor.toolbar.search',
15
+ icon: 'ph--magnifying-glass--regular',
16
+ },
17
+ () => openSearchPanel(getView()),
18
+ );
15
19
 
16
20
  export const createSearch = (getView: () => EditorView) => ({
17
21
  nodes: [createSearchAction(getView)],
@@ -7,7 +7,7 @@ import { type Rx } from '@effect-rx/rx-react';
7
7
  import { useMemo } from 'react';
8
8
 
9
9
  import { type Action } from '@dxos/app-graph';
10
- import { live, type Live } from '@dxos/live-object';
10
+ import { type Live, live } from '@dxos/live-object';
11
11
  import { type ThemedClassName } from '@dxos/react-ui';
12
12
  import {
13
13
  type ActionGraphProps,
@@ -53,13 +53,24 @@ export type EditorToolbarProps = ThemedClassName<
53
53
 
54
54
  export type EditorToolbarItem = EditorAction | MenuItemGroup | MenuSeparator;
55
55
 
56
- export const createEditorAction = (id: string, invoke: () => void, properties: Partial<MenuActionProperties>) => {
57
- const { label = [`${id} label`, { ns: translationKey }], ...rest } = properties;
58
- return createMenuAction(id, invoke, { label, ...rest }) as Action<MenuActionProperties>;
56
+ export const createEditorAction = (id: string, props: Partial<MenuActionProperties>, invoke: () => void) => {
57
+ const { label = [`${id} label`, { ns: translationKey }], ...rest } = props;
58
+ return createMenuAction(id, invoke, {
59
+ label,
60
+ ...rest,
61
+ }) as Action<MenuActionProperties>;
59
62
  };
60
63
 
61
64
  export const createEditorActionGroup = (
62
65
  id: string,
63
66
  props: Omit<ToolbarMenuActionGroupProperties, 'icon'>,
64
67
  icon?: string,
65
- ) => createMenuItemGroup(id, { icon, iconOnly: true, ...props });
68
+ ) => {
69
+ const { label = [`${id} label`, { ns: translationKey }], ...rest } = props;
70
+ return createMenuItemGroup(id, {
71
+ label,
72
+ icon,
73
+ iconOnly: true,
74
+ ...rest,
75
+ });
76
+ };
@@ -5,10 +5,11 @@
5
5
  import { type NodeArg } from '@dxos/app-graph';
6
6
  import { type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';
7
7
 
8
- import { createEditorAction, createEditorActionGroup, type EditorToolbarState } from './util';
9
8
  import { translationKey } from '../../translations';
10
9
  import { type EditorViewMode } from '../../types';
11
10
 
11
+ import { type EditorToolbarState, createEditorAction, createEditorActionGroup } from './util';
12
+
12
13
  const createViewModeGroupAction = (value: string) =>
13
14
  createEditorActionGroup(
14
15
  'viewMode',
@@ -28,11 +29,15 @@ const createViewModeActions = (value: string, onViewModeChange: (mode: EditorVie
28
29
  readonly: 'ph--pencil-slash--regular',
29
30
  }).map(([viewMode, icon]) => {
30
31
  const checked = viewMode === value;
31
- return createEditorAction(`view-mode--${viewMode}`, () => onViewModeChange(viewMode as EditorViewMode), {
32
- label: [`${viewMode} mode label`, { ns: translationKey }],
33
- checked,
34
- icon,
35
- });
32
+ return createEditorAction(
33
+ `view-mode--${viewMode}`,
34
+ {
35
+ label: [`${viewMode} mode label`, { ns: translationKey }],
36
+ checked,
37
+ icon,
38
+ },
39
+ () => onViewModeChange(viewMode as EditorViewMode),
40
+ );
36
41
  });
37
42
 
38
43
  export const createViewMode = (state: EditorToolbarState, onViewModeChange: (mode: EditorViewMode) => void) => {
@@ -2,6 +2,6 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
+ export * from './CommandMenu';
5
6
  export * from './Editor';
6
7
  export * from './EditorToolbar';
7
- export * from './Popover';
package/src/defaults.ts CHANGED
@@ -28,7 +28,9 @@ export const editorSlots: ThemeExtensionsOptions['slots'] = {
28
28
 
29
29
  export const editorGutter = EditorView.theme({
30
30
  '.cm-gutters': {
31
- background: 'var(--dx-baseSurface)',
31
+ // NOTE: Color required to cover content if scrolling horizontally.
32
+ // TODO(burdon): Non-transparent background clips the focus ring.
33
+ background: 'var(--dx-baseSurface) !important',
32
34
  paddingRight: '1rem',
33
35
  },
34
36
  });
@@ -42,8 +44,9 @@ export const editorMonospace = EditorView.theme({
42
44
  export const editorWithToolbarLayout =
43
45
  'grid grid-cols-1 grid-rows-[min-content_1fr] data-[toolbar=disabled]:grid-rows-[1fr] justify-center content-start overflow-hidden';
44
46
 
47
+ // NOTE: Padding is added to the editor to account for the focus ring (since otherwise the CM gutter will clip it)
45
48
  export const stackItemContentEditorClassNames = (role?: string) =>
46
49
  mx(
47
- 'attention-surface dx-focus-ring-inset data-[toolbar=disabled]:pbs-2',
50
+ 'p-0.5 dx-focus-ring-inset attention-surface data-[toolbar=disabled]:pbs-2',
48
51
  role === 'section' ? '[&_.cm-scroller]:overflow-hidden [&_.cm-scroller]:min-bs-24' : 'min-bs-0',
49
52
  );
@@ -1,69 +1,219 @@
1
1
  //
2
- // Copyright 2023 DXOS.org
2
+ // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ import { type Extension, Prec } from '@codemirror/state';
5
6
  import {
6
- autocompletion,
7
- completionKeymap,
8
- type CompletionSource,
9
- type Completion,
10
- type CompletionContext,
11
- type CompletionResult,
12
- } from '@codemirror/autocomplete';
13
- import { markdownLanguage } from '@codemirror/lang-markdown';
14
- import { type Extension } from '@codemirror/state';
15
- import { keymap } from '@codemirror/view';
16
-
17
- export type AutocompleteResult = Completion;
7
+ Decoration,
8
+ type DecorationSet,
9
+ EditorView,
10
+ ViewPlugin,
11
+ type ViewUpdate,
12
+ WidgetType,
13
+ keymap,
14
+ } from '@codemirror/view';
18
15
 
19
16
  export type AutocompleteOptions = {
20
- activateOnTyping?: boolean;
21
- override?: CompletionSource[];
22
- onSearch?: (text: string) => Completion[];
23
- };
17
+ fireIfEmpty?: boolean;
18
+
19
+ /**
20
+ * Callback triggered when Enter is pressed.
21
+ * @param text The current text in the editor
22
+ * @returns true if the editor should reset the document.
23
+ */
24
+ onSubmit?: (text: string) => boolean | void;
24
25
 
25
- // https://codemirror.net/examples/autocompletion
26
- // https://codemirror.net/docs/ref/#autocomplete.autocompletion
27
- // https://codemirror.net/docs/ref/#autocomplete.Completion
26
+ /**
27
+ * Function that returns a list of suggestions based on the current text.
28
+ * @param text The current text before the cursor
29
+ * @returns Array of suggestion strings
30
+ */
31
+ onSuggest?: (text: string) => string[];
32
+
33
+ /**
34
+ * ESC pressed.
35
+ */
36
+ onCancel?: () => void;
37
+ };
28
38
 
29
39
  /**
30
- * Autocomplete extension.
40
+ * Creates an autocomplete extension that shows inline suggestions.
41
+ * Pressing Tab will complete the suggestion.
31
42
  */
32
- export const autocomplete = ({ activateOnTyping, override, onSearch }: AutocompleteOptions = {}): Extension => {
33
- const extensions: Extension[] = [
34
- // https://codemirror.net/docs/ref/#view.keymap
35
- // https://discuss.codemirror.net/t/how-can-i-replace-the-default-autocompletion-keymap-v6/3322
36
- // TODO(burdon): Set custom keymap.
37
- keymap.of(completionKeymap),
38
-
39
- // https://codemirror.net/examples/autocompletion
40
- // https://codemirror.net/docs/ref/#autocomplete.autocompletion
41
- autocompletion({
42
- override,
43
- activateOnTyping,
44
- // closeOnBlur: false,
45
- // tooltipClass: () => 'rounded-be pbe-1 border-separator',
43
+ export const autocomplete = ({ fireIfEmpty, onSubmit, onSuggest, onCancel }: AutocompleteOptions = {}): Extension => {
44
+ const suggest = ViewPlugin.fromClass(
45
+ class {
46
+ _decorations: DecorationSet;
47
+ _currentSuggestion: string | null = null;
48
+
49
+ constructor(view: EditorView) {
50
+ this._decorations = this.computeDecorations(view);
51
+ }
52
+
53
+ update(update: ViewUpdate) {
54
+ if (update.docChanged || update.selectionSet) {
55
+ this._decorations = this.computeDecorations(update.view);
56
+ }
57
+ }
58
+
59
+ private computeDecorations(view: EditorView): DecorationSet {
60
+ const text = view.state.doc.toString();
61
+ const suggestions = onSuggest?.(text) ?? [];
62
+ if (!suggestions.length) {
63
+ this._currentSuggestion = null;
64
+ return Decoration.none;
65
+ }
66
+
67
+ // Get the first suggestion.
68
+ this._currentSuggestion = suggestions[0];
69
+ const suffix = this._currentSuggestion.slice(text.length);
70
+ if (!suffix) {
71
+ return Decoration.none;
72
+ }
73
+
74
+ // Always show ghost text at the end of the document.
75
+ return Decoration.set([
76
+ Decoration.widget({
77
+ widget: new InlineSuggestionWidget(suffix),
78
+ side: 1,
79
+ }).range(view.state.doc.length),
80
+ ]);
81
+ }
82
+
83
+ completeSuggestion(view: EditorView): boolean {
84
+ if (!this._currentSuggestion) {
85
+ return false;
86
+ }
87
+
88
+ const text = view.state.doc.toString();
89
+ const suffix = this._currentSuggestion.slice(text.length);
90
+ if (!suffix) {
91
+ return false;
92
+ }
93
+
94
+ view.dispatch({
95
+ changes: {
96
+ from: view.state.doc.length,
97
+ insert: suffix,
98
+ },
99
+ selection: {
100
+ anchor: view.state.doc.length + suffix.length,
101
+ },
102
+ });
103
+
104
+ return true;
105
+ }
106
+ },
107
+ {
108
+ decorations: (v) => v._decorations,
109
+ },
110
+ );
111
+
112
+ return [
113
+ suggest,
114
+ EditorView.theme({
115
+ '.cm-inline-suggestion': {
116
+ opacity: 0.4,
117
+ },
46
118
  }),
47
- ];
48
119
 
49
- if (onSearch) {
50
- extensions.push(
51
- // TODO(burdon): Optional decoration via addToOptions.
52
- markdownLanguage.data.of({
53
- autocomplete: (context: CompletionContext): CompletionResult | null => {
54
- const match = context.matchBefore(/\w*/);
55
- if (!match || (match.from === match.to && !context.explicit)) {
56
- return null;
57
- }
58
-
59
- return {
60
- from: match.from,
61
- options: onSearch(match.text.toLowerCase()),
62
- };
120
+ Prec.highest(
121
+ keymap.of([
122
+ {
123
+ key: 'Tab',
124
+ preventDefault: true,
125
+ run: (view) => {
126
+ const plugin = view.plugin(suggest);
127
+ return plugin?.completeSuggestion(view) ?? false;
128
+ },
63
129
  },
64
- }),
65
- );
66
- }
130
+ {
131
+ key: 'ArrowRight',
132
+ preventDefault: true,
133
+ run: (view) => {
134
+ // Only complete if cursor is at the end
135
+ if (view.state.selection.main.head !== view.state.doc.length) {
136
+ return false;
137
+ }
138
+
139
+ const plugin = view.plugin(suggest);
140
+ return plugin?.completeSuggestion(view) ?? false;
141
+ },
142
+ },
143
+ {
144
+ key: 'Enter',
145
+ preventDefault: true,
146
+ run: (view) => {
147
+ const text = view.state.doc.toString().trim();
148
+ if (onSubmit && (fireIfEmpty || text.length > 0)) {
149
+ const reset = onSubmit(text);
150
+
151
+ // Clear the document after calling onEnter.
152
+ if (reset) {
153
+ view.dispatch({
154
+ changes: {
155
+ from: 0,
156
+ to: view.state.doc.length,
157
+ insert: '',
158
+ },
159
+ });
160
+ }
161
+ }
67
162
 
68
- return extensions;
163
+ return true;
164
+ },
165
+ },
166
+ {
167
+ key: 'Shift-Enter',
168
+ preventDefault: true,
169
+ run: (view) => {
170
+ view.dispatch({
171
+ changes: {
172
+ from: view.state.selection.main.head,
173
+ insert: '\n',
174
+ },
175
+ selection: {
176
+ anchor: view.state.selection.main.head + 1,
177
+ head: view.state.selection.main.head + 1,
178
+ },
179
+ });
180
+ return true;
181
+ },
182
+ },
183
+ {
184
+ key: 'Escape',
185
+ preventDefault: true,
186
+ run: (view) => {
187
+ // Clear the entire document.
188
+ view.dispatch({
189
+ changes: {
190
+ from: 0,
191
+ to: view.state.doc.length,
192
+ insert: '',
193
+ },
194
+ });
195
+ onCancel?.();
196
+ return true;
197
+ },
198
+ },
199
+ ]),
200
+ ),
201
+ ];
69
202
  };
203
+
204
+ class InlineSuggestionWidget extends WidgetType {
205
+ constructor(private suffix: string) {
206
+ super();
207
+ }
208
+
209
+ override toDOM(): HTMLSpanElement {
210
+ const span = document.createElement('span');
211
+ span.textContent = this.suffix;
212
+ span.className = 'cm-inline-suggestion';
213
+ return span;
214
+ }
215
+
216
+ override eq(other: InlineSuggestionWidget): boolean {
217
+ return other.suffix === this.suffix;
218
+ }
219
+ }
@@ -2,20 +2,20 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
7
5
  import '@preact/signals-react';
8
6
 
9
7
  import { Repo } from '@automerge/automerge-repo';
10
8
  import { BroadcastChannelNetworkAdapter } from '@automerge/automerge-repo-network-broadcastchannel';
9
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
11
10
  import React, { useEffect, useState } from 'react';
12
11
 
13
12
  import { Obj, Ref, Type } from '@dxos/echo';
14
- import { DocAccessor, createDocAccessor, useQuery, useSpace, type Space, Query } from '@dxos/react-client/echo';
15
- import { useIdentity, type Identity } from '@dxos/react-client/halo';
16
- import { ClientRepeater, type ClientRepeatedComponentProps } from '@dxos/react-client/testing';
13
+ import { DocAccessor, Query, type Space, createDocAccessor, useQuery, useSpace } from '@dxos/react-client/echo';
14
+ import { type Identity, useIdentity } from '@dxos/react-client/halo';
15
+ import { type ClientRepeatedComponentProps, ClientRepeater } from '@dxos/react-client/testing';
17
16
  import { useThemeContext } from '@dxos/react-ui';
18
- import { withLayout, withTheme } from '@dxos/storybook-utils';
17
+ import { withTheme } from '@dxos/react-ui/testing';
18
+ import { render } from '@dxos/storybook-utils';
19
19
 
20
20
  import { editorSlots } from '../../defaults';
21
21
  import { useTextEditor } from '../../hooks';
@@ -41,7 +41,7 @@ const Editor = ({ source, autoFocus, space, identity }: EditorProps) => {
41
41
  () => ({
42
42
  initialValue: DocAccessor.getValue(source),
43
43
  extensions: [
44
- createBasicExtensions({ placeholder: 'Type here...' }),
44
+ createBasicExtensions({ placeholder: 'Type here...', search: true }),
45
45
  createThemeExtensions({ themeMode, slots: editorSlots }),
46
46
  createDataExtensions({ id: 'test', text: source, space, identity }),
47
47
  ],
@@ -53,7 +53,7 @@ const Editor = ({ source, autoFocus, space, identity }: EditorProps) => {
53
53
  return <div ref={parentRef} className='flex w-full' />;
54
54
  };
55
55
 
56
- const Story = () => {
56
+ const DefaultStory = () => {
57
57
  const [object1, setObject1] = useState<DocAccessor<TestObject>>();
58
58
  const [object2, setObject2] = useState<DocAccessor<TestObject>>();
59
59
 
@@ -88,16 +88,6 @@ const Story = () => {
88
88
  );
89
89
  };
90
90
 
91
- export default {
92
- title: 'ui/react-ui-editor/Automerge',
93
- component: Editor,
94
- decorators: [withTheme, withLayout({ fullscreen: true })],
95
- render: () => <Story />,
96
- parameters: {
97
- translations,
98
- },
99
- };
100
-
101
91
  const EchoStory = ({ spaceKey }: ClientRepeatedComponentProps) => {
102
92
  const identity = useIdentity();
103
93
  const space = useSpace(spaceKey);
@@ -105,8 +95,9 @@ const EchoStory = ({ spaceKey }: ClientRepeatedComponentProps) => {
105
95
  const objects = useQuery(space, Query.type(Type.Expando, { type: 'test' }));
106
96
 
107
97
  useEffect(() => {
108
- if (!source && objects.length) {
109
- const source = createDocAccessor(objects[0].content, ['content']);
98
+ const content = objects[0]?.content.target;
99
+ if (!source && content) {
100
+ const source = createDocAccessor(content, ['content']);
110
101
  setSource(source);
111
102
  }
112
103
  }, [objects, source]);
@@ -118,17 +109,33 @@ const EchoStory = ({ spaceKey }: ClientRepeatedComponentProps) => {
118
109
  return <Editor source={source} space={space} identity={identity ?? undefined} />;
119
110
  };
120
111
 
121
- export const Default = {};
122
-
123
- export const WithEcho = {
112
+ const meta = {
113
+ title: 'ui/react-ui-editor/Automerge',
114
+ component: Editor as any,
115
+ render: render(DefaultStory),
124
116
  decorators: [withTheme],
117
+ parameters: {
118
+ layout: 'fullscreen',
119
+ translations,
120
+ },
121
+ } satisfies Meta<typeof DefaultStory>;
122
+
123
+ export default meta;
124
+
125
+ type Story = StoryObj<typeof meta>;
126
+
127
+ export const Default: Story = {
128
+ args: {},
129
+ };
130
+
131
+ export const WithEcho: Story = {
125
132
  render: () => {
126
133
  return (
127
134
  <ClientRepeater
128
135
  count={2}
129
136
  component={EchoStory}
130
137
  createSpace
131
- onSpaceCreated={async ({ space }) => {
138
+ onCreateSpace={async ({ space }) => {
132
139
  space.db.add(
133
140
  Obj.make(Type.Expando, {
134
141
  type: 'test',