@dxos/react-ui-editor 0.8.3 → 0.8.4-main.1da679c

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 (269) hide show
  1. package/dist/lib/browser/chunk-22UMM3QJ.mjs +22 -0
  2. package/dist/lib/browser/chunk-22UMM3QJ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +2502 -1384
  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 +72 -2
  7. package/dist/lib/browser/testing/index.mjs.map +4 -4
  8. package/dist/lib/browser/types/index.mjs +13 -0
  9. package/dist/lib/browser/types/index.mjs.map +7 -0
  10. package/dist/lib/node-esm/chunk-YXYQPV6R.mjs +24 -0
  11. package/dist/lib/node-esm/chunk-YXYQPV6R.mjs.map +7 -0
  12. package/dist/lib/node-esm/index.mjs +2504 -1387
  13. package/dist/lib/node-esm/index.mjs.map +4 -4
  14. package/dist/lib/node-esm/meta.json +1 -1
  15. package/dist/lib/node-esm/testing/index.mjs +72 -2
  16. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  17. package/dist/lib/node-esm/types/index.mjs +14 -0
  18. package/dist/lib/node-esm/types/index.mjs.map +7 -0
  19. package/dist/types/src/components/{Popover → CommandMenu}/CommandMenu.d.ts +10 -6
  20. package/dist/types/src/components/CommandMenu/CommandMenu.d.ts.map +1 -0
  21. package/dist/types/src/components/CommandMenu/index.d.ts +2 -0
  22. package/dist/types/src/components/CommandMenu/index.d.ts.map +1 -0
  23. package/dist/types/src/components/Editor/Editor.d.ts +19 -0
  24. package/dist/types/src/components/Editor/Editor.d.ts.map +1 -0
  25. package/dist/types/src/components/Editor/index.d.ts +2 -0
  26. package/dist/types/src/components/Editor/index.d.ts.map +1 -0
  27. package/dist/types/src/components/EditorToolbar/EditorToolbar.d.ts.map +1 -1
  28. package/dist/types/src/components/EditorToolbar/blocks.d.ts.map +1 -1
  29. package/dist/types/src/components/EditorToolbar/formatting.d.ts.map +1 -1
  30. package/dist/types/src/components/EditorToolbar/headings.d.ts.map +1 -1
  31. package/dist/types/src/components/EditorToolbar/image.d.ts.map +1 -1
  32. package/dist/types/src/components/EditorToolbar/lists.d.ts.map +1 -1
  33. package/dist/types/src/components/EditorToolbar/search.d.ts.map +1 -1
  34. package/dist/types/src/components/EditorToolbar/util.d.ts +6 -5
  35. package/dist/types/src/components/EditorToolbar/util.d.ts.map +1 -1
  36. package/dist/types/src/components/EditorToolbar/view-mode.d.ts +1 -1
  37. package/dist/types/src/components/EditorToolbar/view-mode.d.ts.map +1 -1
  38. package/dist/types/src/components/index.d.ts +2 -1
  39. package/dist/types/src/components/index.d.ts.map +1 -1
  40. package/dist/types/src/defaults.d.ts.map +1 -1
  41. package/dist/types/src/extensions/autocomplete.d.ts +20 -7
  42. package/dist/types/src/extensions/autocomplete.d.ts.map +1 -1
  43. package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
  44. package/dist/types/src/extensions/automerge/automerge.stories.d.ts +36 -45
  45. package/dist/types/src/extensions/automerge/automerge.stories.d.ts.map +1 -1
  46. package/dist/types/src/extensions/automerge/defs.d.ts +1 -1
  47. package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
  48. package/dist/types/src/extensions/automerge/sync.d.ts.map +1 -1
  49. package/dist/types/src/extensions/automerge/update-automerge.d.ts.map +1 -1
  50. package/dist/types/src/extensions/autoscroll.d.ts +10 -0
  51. package/dist/types/src/extensions/autoscroll.d.ts.map +1 -0
  52. package/dist/types/src/extensions/blast.d.ts.map +1 -1
  53. package/dist/types/src/extensions/command/action.d.ts +1 -1
  54. package/dist/types/src/extensions/command/action.d.ts.map +1 -1
  55. package/dist/types/src/extensions/command/command-menu.d.ts +1 -1
  56. package/dist/types/src/extensions/command/command-menu.d.ts.map +1 -1
  57. package/dist/types/src/extensions/command/command.d.ts.map +1 -1
  58. package/dist/types/src/extensions/command/floating-menu.d.ts.map +1 -1
  59. package/dist/types/src/extensions/command/hint.d.ts +2 -7
  60. package/dist/types/src/extensions/command/hint.d.ts.map +1 -1
  61. package/dist/types/src/extensions/command/index.d.ts +1 -1
  62. package/dist/types/src/extensions/command/index.d.ts.map +1 -1
  63. package/dist/types/src/extensions/command/state.d.ts +1 -1
  64. package/dist/types/src/extensions/command/state.d.ts.map +1 -1
  65. package/dist/types/src/extensions/command/typeahead.d.ts +7 -2
  66. package/dist/types/src/extensions/command/typeahead.d.ts.map +1 -1
  67. package/dist/types/src/extensions/command/useCommandMenu.d.ts +3 -4
  68. package/dist/types/src/extensions/command/useCommandMenu.d.ts.map +1 -1
  69. package/dist/types/src/extensions/comments.d.ts +1 -1
  70. package/dist/types/src/extensions/comments.d.ts.map +1 -1
  71. package/dist/types/src/extensions/dnd.d.ts.map +1 -1
  72. package/dist/types/src/extensions/factories.d.ts +15 -1
  73. package/dist/types/src/extensions/factories.d.ts.map +1 -1
  74. package/dist/types/src/extensions/index.d.ts +2 -0
  75. package/dist/types/src/extensions/index.d.ts.map +1 -1
  76. package/dist/types/src/extensions/markdown/action.d.ts.map +1 -1
  77. package/dist/types/src/extensions/markdown/bundle.d.ts +8 -2
  78. package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
  79. package/dist/types/src/extensions/markdown/changes.d.ts +1 -1
  80. package/dist/types/src/extensions/markdown/changes.d.ts.map +1 -1
  81. package/dist/types/src/extensions/markdown/decorate.d.ts +9 -1
  82. package/dist/types/src/extensions/markdown/decorate.d.ts.map +1 -1
  83. package/dist/types/src/extensions/markdown/formatting.d.ts +1 -1
  84. package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -1
  85. package/dist/types/src/extensions/markdown/formatting.test.d.ts.map +1 -1
  86. package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -1
  87. package/dist/types/src/extensions/markdown/image.d.ts.map +1 -1
  88. package/dist/types/src/extensions/markdown/link.d.ts.map +1 -1
  89. package/dist/types/src/extensions/modes.d.ts +0 -7
  90. package/dist/types/src/extensions/modes.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 +71 -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.map +1 -1
  111. package/dist/types/src/index.d.ts +1 -1
  112. package/dist/types/src/index.d.ts.map +1 -1
  113. package/dist/types/src/stories/Command.stories.d.ts +12 -4
  114. package/dist/types/src/stories/Command.stories.d.ts.map +1 -1
  115. package/dist/types/src/stories/CommandMenu.stories.d.ts +11 -4
  116. package/dist/types/src/stories/CommandMenu.stories.d.ts.map +1 -1
  117. package/dist/types/src/stories/Comments.stories.d.ts +21 -9
  118. package/dist/types/src/stories/Comments.stories.d.ts.map +1 -1
  119. package/dist/types/src/stories/EditorToolbar.stories.d.ts +40 -3
  120. package/dist/types/src/stories/EditorToolbar.stories.d.ts.map +1 -1
  121. package/dist/types/src/stories/Experimental.stories.d.ts +22 -12
  122. package/dist/types/src/stories/Experimental.stories.d.ts.map +1 -1
  123. package/dist/types/src/stories/Markdown.stories.d.ts +32 -42
  124. package/dist/types/src/stories/Markdown.stories.d.ts.map +1 -1
  125. package/dist/types/src/stories/Outliner.stories.d.ts +15 -20
  126. package/dist/types/src/stories/Outliner.stories.d.ts.map +1 -1
  127. package/dist/types/src/stories/Preview.stories.d.ts +21 -6
  128. package/dist/types/src/stories/Preview.stories.d.ts.map +1 -1
  129. package/dist/types/src/stories/Tags.stories.d.ts +17 -0
  130. package/dist/types/src/stories/Tags.stories.d.ts.map +1 -0
  131. package/dist/types/src/stories/TextEditor.stories.d.ts +38 -51
  132. package/dist/types/src/stories/TextEditor.stories.d.ts.map +1 -1
  133. package/dist/types/src/stories/components/EditorStory.d.ts +3 -6
  134. package/dist/types/src/stories/components/EditorStory.d.ts.map +1 -1
  135. package/dist/types/src/styles/theme.d.ts.map +1 -1
  136. package/dist/types/src/testing/PreviewPopover.d.ts +20 -0
  137. package/dist/types/src/testing/PreviewPopover.d.ts.map +1 -0
  138. package/dist/types/src/testing/index.d.ts +1 -0
  139. package/dist/types/src/testing/index.d.ts.map +1 -1
  140. package/dist/types/src/testing/util.d.ts +1 -0
  141. package/dist/types/src/testing/util.d.ts.map +1 -1
  142. package/dist/types/src/translations.d.ts +28 -29
  143. package/dist/types/src/translations.d.ts.map +1 -1
  144. package/dist/types/src/types/index.d.ts +2 -0
  145. package/dist/types/src/types/index.d.ts.map +1 -0
  146. package/dist/types/src/types/types.d.ts +21 -0
  147. package/dist/types/src/types/types.d.ts.map +1 -0
  148. package/dist/types/src/util/cursor.d.ts.map +1 -1
  149. package/dist/types/src/util/debug.d.ts +1 -1
  150. package/dist/types/src/util/debug.d.ts.map +1 -1
  151. package/dist/types/src/util/decorations.d.ts +4 -0
  152. package/dist/types/src/util/decorations.d.ts.map +1 -0
  153. package/dist/types/src/util/dom.d.ts +2 -12
  154. package/dist/types/src/util/dom.d.ts.map +1 -1
  155. package/dist/types/src/util/domino.d.ts +18 -0
  156. package/dist/types/src/util/domino.d.ts.map +1 -0
  157. package/dist/types/src/util/index.d.ts +2 -0
  158. package/dist/types/src/util/index.d.ts.map +1 -1
  159. package/dist/types/src/util/react.d.ts +1 -1
  160. package/dist/types/src/util/react.d.ts.map +1 -1
  161. package/dist/types/tsconfig.tsbuildinfo +1 -1
  162. package/package.json +65 -55
  163. package/src/components/{Popover → CommandMenu}/CommandMenu.tsx +93 -26
  164. package/src/components/{Popover → CommandMenu}/index.ts +0 -2
  165. package/src/components/Editor/Editor.tsx +39 -0
  166. package/src/components/Editor/index.ts +5 -0
  167. package/src/components/EditorToolbar/EditorToolbar.tsx +40 -30
  168. package/src/components/EditorToolbar/blocks.ts +22 -25
  169. package/src/components/EditorToolbar/formatting.ts +22 -25
  170. package/src/components/EditorToolbar/headings.ts +10 -5
  171. package/src/components/EditorToolbar/image.ts +8 -4
  172. package/src/components/EditorToolbar/lists.ts +16 -19
  173. package/src/components/EditorToolbar/search.ts +8 -4
  174. package/src/components/EditorToolbar/util.ts +21 -9
  175. package/src/components/EditorToolbar/view-mode.ts +12 -7
  176. package/src/components/index.ts +2 -1
  177. package/src/defaults.ts +5 -2
  178. package/src/extensions/autocomplete.ts +204 -54
  179. package/src/extensions/automerge/automerge.stories.tsx +26 -17
  180. package/src/extensions/automerge/automerge.ts +4 -3
  181. package/src/extensions/automerge/defs.ts +1 -1
  182. package/src/extensions/automerge/sync.ts +1 -1
  183. package/src/extensions/automerge/update-automerge.ts +1 -1
  184. package/src/extensions/autoscroll.ts +157 -0
  185. package/src/extensions/awareness/awareness.ts +2 -2
  186. package/src/extensions/blast.ts +3 -16
  187. package/src/extensions/command/action.ts +1 -2
  188. package/src/extensions/command/command-menu.ts +7 -6
  189. package/src/extensions/command/command.ts +3 -3
  190. package/src/extensions/command/floating-menu.ts +10 -15
  191. package/src/extensions/command/hint.ts +2 -1
  192. package/src/extensions/command/index.ts +1 -1
  193. package/src/extensions/command/placeholder.ts +1 -1
  194. package/src/extensions/command/state.ts +4 -3
  195. package/src/extensions/command/typeahead.ts +28 -15
  196. package/src/extensions/command/useCommandMenu.ts +6 -9
  197. package/src/extensions/comments.ts +18 -13
  198. package/src/extensions/dnd.ts +1 -1
  199. package/src/extensions/factories.ts +22 -15
  200. package/src/extensions/folding.tsx +2 -2
  201. package/src/extensions/index.ts +2 -0
  202. package/src/extensions/markdown/action.ts +2 -1
  203. package/src/extensions/markdown/bundle.ts +25 -3
  204. package/src/extensions/markdown/changes.ts +1 -1
  205. package/src/extensions/markdown/decorate.ts +23 -14
  206. package/src/extensions/markdown/formatting.test.ts +7 -7
  207. package/src/extensions/markdown/formatting.ts +16 -14
  208. package/src/extensions/markdown/highlight.ts +1 -1
  209. package/src/extensions/markdown/image.ts +3 -4
  210. package/src/extensions/markdown/link.ts +3 -0
  211. package/src/extensions/markdown/table.ts +7 -1
  212. package/src/extensions/mention.ts +1 -1
  213. package/src/extensions/modes.ts +0 -9
  214. package/src/extensions/outliner/outliner.test.ts +3 -2
  215. package/src/extensions/outliner/outliner.ts +6 -5
  216. package/src/extensions/outliner/selection.ts +1 -1
  217. package/src/extensions/outliner/tree.test.ts +2 -1
  218. package/src/extensions/outliner/tree.ts +2 -2
  219. package/src/extensions/preview/preview.ts +59 -62
  220. package/src/extensions/tags/extended-markdown.test.ts +261 -0
  221. package/src/extensions/tags/extended-markdown.ts +78 -0
  222. package/src/extensions/tags/index.ts +7 -0
  223. package/src/extensions/tags/streamer.ts +244 -0
  224. package/src/extensions/tags/xml-tags.ts +335 -0
  225. package/src/extensions/tags/xml-util.ts +94 -0
  226. package/src/hooks/useTextEditor.ts +3 -15
  227. package/src/index.ts +1 -1
  228. package/src/stories/Command.stories.tsx +24 -31
  229. package/src/stories/CommandMenu.stories.tsx +29 -30
  230. package/src/stories/Comments.stories.tsx +10 -6
  231. package/src/stories/EditorToolbar.stories.tsx +10 -11
  232. package/src/stories/Experimental.stories.tsx +12 -8
  233. package/src/stories/Markdown.stories.tsx +21 -17
  234. package/src/stories/Outliner.stories.tsx +42 -30
  235. package/src/stories/Preview.stories.tsx +34 -33
  236. package/src/stories/Tags.stories.tsx +81 -0
  237. package/src/stories/TextEditor.stories.tsx +41 -35
  238. package/src/stories/components/EditorStory.tsx +9 -10
  239. package/src/styles/theme.ts +11 -10
  240. package/src/testing/PreviewPopover.tsx +78 -0
  241. package/src/testing/index.ts +1 -0
  242. package/src/testing/util.ts +2 -0
  243. package/src/translations.ts +5 -3
  244. package/src/types/index.ts +5 -0
  245. package/src/types/types.ts +32 -0
  246. package/src/util/cursor.ts +2 -1
  247. package/src/util/debug.ts +2 -2
  248. package/src/util/decorations.ts +21 -0
  249. package/src/util/dom.ts +5 -27
  250. package/src/util/domino.ts +51 -0
  251. package/src/util/index.ts +2 -0
  252. package/src/util/react.tsx +1 -1
  253. package/dist/lib/node/index.cjs +0 -7754
  254. package/dist/lib/node/index.cjs.map +0 -7
  255. package/dist/lib/node/meta.json +0 -1
  256. package/dist/lib/node/testing/index.cjs +0 -29
  257. package/dist/lib/node/testing/index.cjs.map +0 -7
  258. package/dist/types/src/components/Popover/CommandMenu.d.ts.map +0 -1
  259. package/dist/types/src/components/Popover/RefDropdownMenu.d.ts +0 -21
  260. package/dist/types/src/components/Popover/RefDropdownMenu.d.ts.map +0 -1
  261. package/dist/types/src/components/Popover/RefPopover.d.ts +0 -34
  262. package/dist/types/src/components/Popover/RefPopover.d.ts.map +0 -1
  263. package/dist/types/src/components/Popover/index.d.ts +0 -4
  264. package/dist/types/src/components/Popover/index.d.ts.map +0 -1
  265. package/dist/types/src/types.d.ts +0 -14
  266. package/dist/types/src/types.d.ts.map +0 -1
  267. package/src/components/Popover/RefDropdownMenu.tsx +0 -79
  268. package/src/components/Popover/RefPopover.tsx +0 -99
  269. package/src/types.ts +0 -23
@@ -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,20 +7,21 @@ 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
- type MenuSeparator,
13
+ type ActionGraphProps,
14
+ type MenuActionProperties,
14
15
  type MenuItemGroup,
16
+ type MenuSeparator,
15
17
  type ToolbarMenuActionGroupProperties,
16
18
  createMenuAction,
17
19
  createMenuItemGroup,
18
- type ActionGraphProps,
19
- type MenuActionProperties,
20
20
  } from '@dxos/react-ui-menu';
21
21
 
22
- import type { EditorAction, EditorViewMode, Formatting } from '../../extensions';
22
+ import type { EditorAction, Formatting } from '../../extensions';
23
23
  import { translationKey } from '../../translations';
24
+ import { type EditorViewMode } from '../../types';
24
25
 
25
26
  export type EditorToolbarState = Formatting & Partial<{ viewMode: EditorViewMode }>;
26
27
 
@@ -52,13 +53,24 @@ export type EditorToolbarProps = ThemedClassName<
52
53
 
53
54
  export type EditorToolbarItem = EditorAction | MenuItemGroup | MenuSeparator;
54
55
 
55
- export const createEditorAction = (id: string, invoke: () => void, properties: Partial<MenuActionProperties>) => {
56
- const { label = [`${id} label`, { ns: translationKey }], ...rest } = properties;
57
- 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>;
58
62
  };
59
63
 
60
64
  export const createEditorActionGroup = (
61
65
  id: string,
62
66
  props: Omit<ToolbarMenuActionGroupProperties, 'icon'>,
63
67
  icon?: string,
64
- ) => 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,9 +5,10 @@
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
- import { type EditorViewMode } from '../../extensions';
10
8
  import { translationKey } from '../../translations';
9
+ import { type EditorViewMode } from '../../types';
10
+
11
+ import { type EditorToolbarState, createEditorAction, createEditorActionGroup } from './util';
11
12
 
12
13
  const createViewModeGroupAction = (value: string) =>
13
14
  createEditorActionGroup(
@@ -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,5 +2,6 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
+ export * from './Editor';
5
6
  export * from './EditorToolbar';
6
- export * from './Popover';
7
+ export * from './CommandMenu';
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
+ }
@@ -8,18 +8,19 @@ import '@preact/signals-react';
8
8
 
9
9
  import { Repo } from '@automerge/automerge-repo';
10
10
  import { BroadcastChannelNetworkAdapter } from '@automerge/automerge-repo-network-broadcastchannel';
11
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
11
12
  import React, { useEffect, useState } from 'react';
12
13
 
13
14
  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';
15
+ import { DocAccessor, Query, type Space, createDocAccessor, useQuery, useSpace } from '@dxos/react-client/echo';
16
+ import { type Identity, useIdentity } from '@dxos/react-client/halo';
17
+ import { type ClientRepeatedComponentProps, ClientRepeater } from '@dxos/react-client/testing';
17
18
  import { useThemeContext } from '@dxos/react-ui';
18
- import { withLayout, withTheme } from '@dxos/storybook-utils';
19
+ import { render, withLayout, withTheme } from '@dxos/storybook-utils';
19
20
 
20
21
  import { editorSlots } from '../../defaults';
21
22
  import { useTextEditor } from '../../hooks';
22
- import translations from '../../translations';
23
+ import { translations } from '../../translations';
23
24
  import { createBasicExtensions, createDataExtensions, createThemeExtensions } from '../factories';
24
25
 
25
26
  const initialContent = 'Hello world!';
@@ -41,7 +42,7 @@ const Editor = ({ source, autoFocus, space, identity }: EditorProps) => {
41
42
  () => ({
42
43
  initialValue: DocAccessor.getValue(source),
43
44
  extensions: [
44
- createBasicExtensions({ placeholder: 'Type here...' }),
45
+ createBasicExtensions({ placeholder: 'Type here...', search: true }),
45
46
  createThemeExtensions({ themeMode, slots: editorSlots }),
46
47
  createDataExtensions({ id: 'test', text: source, space, identity }),
47
48
  ],
@@ -53,7 +54,7 @@ const Editor = ({ source, autoFocus, space, identity }: EditorProps) => {
53
54
  return <div ref={parentRef} className='flex w-full' />;
54
55
  };
55
56
 
56
- const Story = () => {
57
+ const DefaultStory = () => {
57
58
  const [object1, setObject1] = useState<DocAccessor<TestObject>>();
58
59
  const [object2, setObject2] = useState<DocAccessor<TestObject>>();
59
60
 
@@ -88,14 +89,6 @@ const Story = () => {
88
89
  );
89
90
  };
90
91
 
91
- export default {
92
- title: 'ui/react-ui-editor/Automerge',
93
- component: Editor,
94
- decorators: [withTheme, withLayout({ fullscreen: true })],
95
- render: () => <Story />,
96
- parameters: { translations },
97
- };
98
-
99
92
  const EchoStory = ({ spaceKey }: ClientRepeatedComponentProps) => {
100
93
  const identity = useIdentity();
101
94
  const space = useSpace(spaceKey);
@@ -116,9 +109,25 @@ const EchoStory = ({ spaceKey }: ClientRepeatedComponentProps) => {
116
109
  return <Editor source={source} space={space} identity={identity ?? undefined} />;
117
110
  };
118
111
 
119
- export const Default = {};
112
+ const meta = {
113
+ title: 'ui/react-ui-editor/Automerge',
114
+ component: Editor as any,
115
+ render: render(DefaultStory),
116
+ decorators: [withTheme, withLayout({ fullscreen: true })],
117
+ parameters: {
118
+ translations,
119
+ },
120
+ } satisfies Meta<typeof DefaultStory>;
121
+
122
+ export default meta;
123
+
124
+ type Story = StoryObj<typeof meta>;
125
+
126
+ export const Default: Story = {
127
+ args: {},
128
+ };
120
129
 
121
- export const WithEcho = {
130
+ export const WithEcho: Story = {
122
131
  decorators: [withTheme],
123
132
  render: () => {
124
133
  return (
@@ -5,15 +5,16 @@
5
5
  //
6
6
 
7
7
  import { next as A } from '@automerge/automerge';
8
- import { StateField, type Extension } from '@codemirror/state';
8
+ import { type Extension, StateField } from '@codemirror/state';
9
9
  import { EditorView, ViewPlugin } from '@codemirror/view';
10
10
 
11
11
  import { type DocAccessor } from '@dxos/react-client/echo';
12
12
 
13
+ import { Cursor } from '../../util';
14
+
13
15
  import { cursorConverter } from './cursor';
14
- import { updateHeadsEffect, isReconcile, type State } from './defs';
16
+ import { type State, isReconcile, updateHeadsEffect } from './defs';
15
17
  import { Syncer } from './sync';
16
- import { Cursor } from '../../util';
17
18
 
18
19
  export const automerge = (accessor: DocAccessor): Extension => {
19
20
  const syncState = StateField.define<State>({
@@ -5,7 +5,7 @@
5
5
  //
6
6
 
7
7
  import { type Heads, type Prop } from '@automerge/automerge';
8
- import { Annotation, StateEffect, type StateField, type EditorState, type Transaction } from '@codemirror/state';
8
+ import { Annotation, type EditorState, StateEffect, type StateField, type Transaction } from '@codemirror/state';
9
9
 
10
10
  export type State = {
11
11
  path: Prop[];
@@ -10,7 +10,7 @@ import { type EditorView } from '@codemirror/view';
10
10
 
11
11
  import { type IDocHandle } from '@dxos/react-client/echo';
12
12
 
13
- import { getLastHeads, getPath, isReconcile, reconcileAnnotation, type State, updateHeads } from './defs';
13
+ import { type State, getLastHeads, getPath, isReconcile, reconcileAnnotation, updateHeads } from './defs';
14
14
  import { updateAutomerge } from './update-automerge';
15
15
  import { updateCodeMirror } from './update-codemirror';
16
16
 
@@ -5,7 +5,7 @@
5
5
  //
6
6
 
7
7
  import { next as A, type Heads } from '@automerge/automerge';
8
- import { type EditorState, type StateField, type Transaction, type Text } from '@codemirror/state';
8
+ import { type EditorState, type StateField, type Text, type Transaction } from '@codemirror/state';
9
9
 
10
10
  import { type IDocHandle } from '@dxos/react-client/echo';
11
11