@dxos/react-ui-editor 0.8.4-main.d05673bc65 → 0.8.4-main.dfabb4ec29
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 +754 -731
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/translations.mjs +39 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +754 -731
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/translations.mjs +41 -0
- package/dist/lib/node-esm/translations.mjs.map +7 -0
- package/dist/types/src/components/Editor/Editor.d.ts +36 -25
- package/dist/types/src/components/Editor/Editor.d.ts.map +1 -1
- package/dist/types/src/components/Editor/Editor.stories.d.ts +4 -4
- package/dist/types/src/components/Editor/Editor.stories.d.ts.map +1 -1
- package/dist/types/src/components/{EditorContent/EditorContent.d.ts → Editor/EditorView.d.ts} +5 -5
- package/dist/types/src/components/Editor/EditorView.d.ts.map +1 -0
- package/dist/types/src/components/Editor/controller.d.ts.map +1 -0
- package/dist/types/src/components/EditorMenuProvider/EditorMenuProvider.d.ts +1 -3
- package/dist/types/src/components/EditorMenuProvider/EditorMenuProvider.d.ts.map +1 -1
- package/dist/types/src/components/EditorMenuProvider/menu-presets.d.ts.map +1 -1
- package/dist/types/src/components/EditorMenuProvider/menu.d.ts.map +1 -1
- package/dist/types/src/components/EditorMenuProvider/popover.d.ts +2 -1
- package/dist/types/src/components/EditorMenuProvider/popover.d.ts.map +1 -1
- package/dist/types/src/components/EditorMenuProvider/useEditorMenu.d.ts.map +1 -1
- package/dist/types/src/components/EditorPreviewProvider/EditorPreviewProvider.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/EditorToolbar.d.ts +2 -2
- package/dist/types/src/components/EditorToolbar/EditorToolbar.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/blocks.d.ts +4 -19
- package/dist/types/src/components/EditorToolbar/blocks.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/formatting.d.ts +4 -19
- package/dist/types/src/components/EditorToolbar/formatting.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/headings.d.ts +4 -19
- package/dist/types/src/components/EditorToolbar/headings.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/image.d.ts +3 -9
- package/dist/types/src/components/EditorToolbar/image.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/index.d.ts +1 -2
- package/dist/types/src/components/EditorToolbar/index.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/lists.d.ts +6 -0
- package/dist/types/src/components/EditorToolbar/lists.d.ts.map +1 -0
- package/dist/types/src/components/EditorToolbar/search.d.ts +3 -9
- package/dist/types/src/components/EditorToolbar/search.d.ts.map +1 -1
- package/dist/types/src/components/EditorToolbar/types.d.ts +6 -0
- package/dist/types/src/components/EditorToolbar/types.d.ts.map +1 -0
- package/dist/types/src/components/EditorToolbar/view-mode.d.ts +5 -20
- package/dist/types/src/components/EditorToolbar/view-mode.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +0 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/extensions/Assistant.stories.d.ts +10 -0
- package/dist/types/src/extensions/Assistant.stories.d.ts.map +1 -0
- package/dist/types/src/extensions/assistant-extension.d.ts +24 -0
- package/dist/types/src/extensions/assistant-extension.d.ts.map +1 -0
- package/dist/types/src/extensions/index.d.ts +2 -0
- package/dist/types/src/extensions/index.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +1 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useBasicMarkdownExtensions.d.ts +25 -0
- package/dist/types/src/hooks/useBasicMarkdownExtensions.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/stories/Automerge.stories.d.ts +24 -24
- package/dist/types/src/stories/Automerge.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Comments.stories.d.ts +1 -1
- package/dist/types/src/stories/Comments.stories.d.ts.map +1 -1
- package/dist/types/src/stories/EditorToolbar.stories.d.ts +28 -26
- package/dist/types/src/stories/EditorToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Experimental.stories.d.ts +2 -2
- package/dist/types/src/stories/Experimental.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Markdown.stories.d.ts +1 -1
- package/dist/types/src/stories/Markdown.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Outliner.stories.d.ts +2 -2
- package/dist/types/src/stories/Outliner.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Popover.stories.d.ts +2 -2
- package/dist/types/src/stories/Popover.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Preview.stories.d.ts +1 -1
- package/dist/types/src/stories/Preview.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Tags.stories.d.ts.map +1 -1
- package/dist/types/src/stories/TextEditor.stories.d.ts +1 -1
- package/dist/types/src/stories/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Theme.stories.d.ts.map +1 -1
- package/dist/types/src/stories/components/EditorStory.d.ts +2 -2
- package/dist/types/src/stories/components/EditorStory.d.ts.map +1 -1
- package/dist/types/src/stories/components/util.d.ts +2 -1
- package/dist/types/src/stories/components/util.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +24 -24
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/util/react.d.ts +1 -1
- package/dist/types/src/util/react.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +57 -48
- package/src/components/Editor/Editor.stories.tsx +15 -21
- package/src/components/Editor/Editor.tsx +54 -53
- package/src/components/Editor/EditorView.tsx +102 -0
- package/src/components/EditorMenuProvider/EditorMenuProvider.tsx +3 -5
- package/src/components/EditorMenuProvider/menu-presets.ts +1 -0
- package/src/components/EditorMenuProvider/popover.ts +3 -1
- package/src/components/EditorMenuProvider/useEditorMenu.ts +2 -1
- package/src/components/EditorPreviewProvider/EditorPreviewProvider.tsx +1 -1
- package/src/components/EditorToolbar/EditorToolbar.tsx +29 -48
- package/src/components/EditorToolbar/blocks.ts +54 -46
- package/src/components/EditorToolbar/formatting.ts +44 -45
- package/src/components/EditorToolbar/headings.ts +44 -50
- package/src/components/EditorToolbar/image.ts +16 -21
- package/src/components/EditorToolbar/index.ts +2 -3
- package/src/components/EditorToolbar/lists.ts +58 -0
- package/src/components/EditorToolbar/search.ts +16 -21
- package/src/components/EditorToolbar/types.ts +8 -0
- package/src/components/EditorToolbar/view-mode.ts +37 -43
- package/src/components/index.ts +0 -3
- package/src/extensions/Assistant.stories.tsx +112 -0
- package/src/extensions/assistant-extension.tsx +223 -0
- package/src/extensions/index.ts +5 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useBasicMarkdownExtensions.ts +55 -0
- package/src/index.ts +1 -4
- package/src/stories/Automerge.stories.tsx +4 -3
- package/src/stories/Comments.stories.tsx +2 -2
- package/src/stories/EditorToolbar.stories.tsx +36 -64
- package/src/stories/Experimental.stories.tsx +10 -10
- package/src/stories/Outliner.stories.tsx +3 -4
- package/src/stories/Popover.stories.tsx +6 -7
- package/src/stories/Preview.stories.tsx +6 -7
- package/src/stories/Theme.stories.tsx +2 -2
- package/src/stories/components/EditorStory.tsx +17 -8
- package/src/stories/components/util.tsx +37 -35
- package/src/translations.ts +29 -24
- package/src/util/react.tsx +1 -1
- package/dist/types/src/components/EditorContent/EditorContent.d.ts.map +0 -1
- package/dist/types/src/components/EditorContent/controller.d.ts.map +0 -1
- package/dist/types/src/components/EditorContent/index.d.ts +0 -3
- package/dist/types/src/components/EditorContent/index.d.ts.map +0 -1
- package/dist/types/src/components/EditorToolbar/actions.d.ts +0 -25
- package/dist/types/src/components/EditorToolbar/actions.d.ts.map +0 -1
- package/dist/types/src/components/EditorToolbar/useEditorToolbar.d.ts +0 -11
- package/dist/types/src/components/EditorToolbar/useEditorToolbar.d.ts.map +0 -1
- package/dist/types/src/stories/CommandDialog.stories.d.ts +0 -14
- package/dist/types/src/stories/CommandDialog.stories.d.ts.map +0 -1
- package/src/components/EditorContent/EditorContent.tsx +0 -83
- package/src/components/EditorContent/index.ts +0 -6
- package/src/components/EditorToolbar/actions.ts +0 -87
- package/src/components/EditorToolbar/useEditorToolbar.ts +0 -20
- package/src/stories/CommandDialog.stories.tsx +0 -81
- /package/dist/types/src/components/{EditorContent → Editor}/controller.d.ts +0 -0
- /package/src/components/{EditorContent → Editor}/controller.ts +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-editor",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.dfabb4ec29",
|
|
4
4
|
"description": "Text editor components.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -12,24 +12,30 @@
|
|
|
12
12
|
"author": "DXOS.org",
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"type": "module",
|
|
15
|
+
"imports": {
|
|
16
|
+
"#translations": "./src/translations.ts"
|
|
17
|
+
},
|
|
15
18
|
"exports": {
|
|
16
19
|
".": {
|
|
17
20
|
"source": "./src/index.ts",
|
|
18
21
|
"types": "./dist/types/src/index.d.ts",
|
|
19
22
|
"browser": "./dist/lib/browser/index.mjs",
|
|
20
23
|
"node": "./dist/lib/node-esm/index.mjs"
|
|
24
|
+
},
|
|
25
|
+
"./translations": {
|
|
26
|
+
"source": "./src/translations.ts",
|
|
27
|
+
"types": "./dist/types/src/translations.d.ts",
|
|
28
|
+
"browser": "./dist/lib/browser/translations.mjs",
|
|
29
|
+
"node": "./dist/lib/node-esm/translations.mjs"
|
|
21
30
|
}
|
|
22
31
|
},
|
|
23
32
|
"types": "dist/types/src/index.d.ts",
|
|
24
|
-
"typesVersions": {
|
|
25
|
-
"*": {}
|
|
26
|
-
},
|
|
27
33
|
"files": [
|
|
28
34
|
"dist",
|
|
29
35
|
"src"
|
|
30
36
|
],
|
|
31
37
|
"dependencies": {
|
|
32
|
-
"@automerge/automerge": "3.2.
|
|
38
|
+
"@automerge/automerge": "3.2.6",
|
|
33
39
|
"@codemirror/autocomplete": "^6.19.0",
|
|
34
40
|
"@codemirror/commands": "^6.8.1",
|
|
35
41
|
"@codemirror/lang-html": "^6.4.11",
|
|
@@ -44,7 +50,7 @@
|
|
|
44
50
|
"@codemirror/search": "^6.5.11",
|
|
45
51
|
"@codemirror/state": "^6.5.2",
|
|
46
52
|
"@codemirror/theme-one-dark": "^6.1.3",
|
|
47
|
-
"@codemirror/view": "^6.38.
|
|
53
|
+
"@codemirror/view": "^6.38.5",
|
|
48
54
|
"@fluentui/react-tabster": "9.26.11",
|
|
49
55
|
"@lezer/common": "^1.2.2",
|
|
50
56
|
"@lezer/generator": "^1.7.1",
|
|
@@ -63,31 +69,33 @@
|
|
|
63
69
|
"lodash.merge": "^4.6.2",
|
|
64
70
|
"lodash.sortby": "^4.7.0",
|
|
65
71
|
"style-mod": "^4.1.0",
|
|
66
|
-
"@dxos/
|
|
67
|
-
"@dxos/
|
|
68
|
-
"@dxos/
|
|
69
|
-
"@dxos/
|
|
70
|
-
"@dxos/
|
|
71
|
-
"@dxos/
|
|
72
|
-
"@dxos/echo": "0.8.4-main.
|
|
73
|
-
"@dxos/
|
|
74
|
-
"@dxos/
|
|
75
|
-
"@dxos/
|
|
76
|
-
"@dxos/
|
|
77
|
-
"@dxos/protocols": "0.8.4-main.
|
|
78
|
-
"@dxos/react-hooks": "0.8.4-main.
|
|
79
|
-
"@dxos/react-ui-menu": "0.8.4-main.
|
|
80
|
-
"@dxos/react-ui-mosaic": "0.8.4-main.
|
|
81
|
-
"@dxos/ui
|
|
82
|
-
"@dxos/
|
|
83
|
-
"@dxos/
|
|
84
|
-
"@dxos/
|
|
72
|
+
"@dxos/app-graph": "0.8.4-main.dfabb4ec29",
|
|
73
|
+
"@dxos/async": "0.8.4-main.dfabb4ec29",
|
|
74
|
+
"@dxos/context": "0.8.4-main.dfabb4ec29",
|
|
75
|
+
"@dxos/client": "0.8.4-main.dfabb4ec29",
|
|
76
|
+
"@dxos/display-name": "0.8.4-main.dfabb4ec29",
|
|
77
|
+
"@dxos/effect": "0.8.4-main.dfabb4ec29",
|
|
78
|
+
"@dxos/echo": "0.8.4-main.dfabb4ec29",
|
|
79
|
+
"@dxos/echo-db": "0.8.4-main.dfabb4ec29",
|
|
80
|
+
"@dxos/lit-ui": "0.8.4-main.dfabb4ec29",
|
|
81
|
+
"@dxos/invariant": "0.8.4-main.dfabb4ec29",
|
|
82
|
+
"@dxos/log": "0.8.4-main.dfabb4ec29",
|
|
83
|
+
"@dxos/protocols": "0.8.4-main.dfabb4ec29",
|
|
84
|
+
"@dxos/react-hooks": "0.8.4-main.dfabb4ec29",
|
|
85
|
+
"@dxos/react-ui-menu": "0.8.4-main.dfabb4ec29",
|
|
86
|
+
"@dxos/react-ui-mosaic": "0.8.4-main.dfabb4ec29",
|
|
87
|
+
"@dxos/ui": "0.8.4-main.dfabb4ec29",
|
|
88
|
+
"@dxos/debug": "0.8.4-main.dfabb4ec29",
|
|
89
|
+
"@dxos/ui-editor": "0.8.4-main.dfabb4ec29",
|
|
90
|
+
"@dxos/util": "0.8.4-main.dfabb4ec29",
|
|
91
|
+
"@dxos/ui-theme": "0.8.4-main.dfabb4ec29"
|
|
85
92
|
},
|
|
86
93
|
"devDependencies": {
|
|
87
|
-
"@automerge/automerge": "3.2.
|
|
88
|
-
"@automerge/automerge-repo": "2.
|
|
89
|
-
"@automerge/automerge-repo-network-broadcastchannel": "2.
|
|
94
|
+
"@automerge/automerge": "3.2.6",
|
|
95
|
+
"@automerge/automerge-repo": "2.6.0-subduction.17",
|
|
96
|
+
"@automerge/automerge-repo-network-broadcastchannel": "2.6.0-subduction.17",
|
|
90
97
|
"@effect-atom/atom-react": "^0.5.0",
|
|
98
|
+
"@effect/ai": "0.33.2",
|
|
91
99
|
"@effect/platform": "0.94.4",
|
|
92
100
|
"@types/chai": "^4.2.15",
|
|
93
101
|
"@types/chai-dom": "^1.11.0",
|
|
@@ -99,39 +107,40 @@
|
|
|
99
107
|
"@types/react-test-renderer": "^17.0.2",
|
|
100
108
|
"chai": "^4.4.1",
|
|
101
109
|
"chai-dom": "^1.11.0",
|
|
102
|
-
"effect": "3.
|
|
110
|
+
"effect": "3.20.0",
|
|
103
111
|
"happy-dom": "^20.0.0",
|
|
104
112
|
"jsdom": "^27.0.0",
|
|
105
113
|
"mocha": "^10.6.0",
|
|
106
114
|
"react": "~19.2.3",
|
|
107
115
|
"react-dom": "~19.2.3",
|
|
108
116
|
"react-test-renderer": "~19.2.0",
|
|
109
|
-
"vite": "^
|
|
117
|
+
"vite": "^8.0.10",
|
|
110
118
|
"vite-plugin-top-level-await": "^1.6.0",
|
|
111
|
-
"vite-plugin-wasm": "^3.
|
|
112
|
-
"@dxos/echo
|
|
113
|
-
"@dxos/
|
|
114
|
-
"@dxos/
|
|
115
|
-
"@dxos/
|
|
116
|
-
"@dxos/
|
|
117
|
-
"@dxos/random": "0.8.4-main.
|
|
118
|
-
"@dxos/react-
|
|
119
|
-
"@dxos/react-ui
|
|
120
|
-
"@dxos/react-ui-
|
|
121
|
-
"@dxos/
|
|
122
|
-
"@dxos/ui-
|
|
123
|
-
"@dxos/ui-
|
|
124
|
-
"@dxos/
|
|
119
|
+
"vite-plugin-wasm": "^3.6.0",
|
|
120
|
+
"@dxos/echo": "0.8.4-main.dfabb4ec29",
|
|
121
|
+
"@dxos/ai": "0.8.4-main.dfabb4ec29",
|
|
122
|
+
"@dxos/config": "0.8.4-main.dfabb4ec29",
|
|
123
|
+
"@dxos/keyboard": "0.8.4-main.dfabb4ec29",
|
|
124
|
+
"@dxos/echo-atom": "0.8.4-main.dfabb4ec29",
|
|
125
|
+
"@dxos/random": "0.8.4-main.dfabb4ec29",
|
|
126
|
+
"@dxos/react-client": "0.8.4-main.dfabb4ec29",
|
|
127
|
+
"@dxos/react-ui": "0.8.4-main.dfabb4ec29",
|
|
128
|
+
"@dxos/react-ui-attention": "0.8.4-main.dfabb4ec29",
|
|
129
|
+
"@dxos/storybook-utils": "0.8.4-main.dfabb4ec29",
|
|
130
|
+
"@dxos/ui-theme": "0.8.4-main.dfabb4ec29",
|
|
131
|
+
"@dxos/ui-types": "0.8.4-main.dfabb4ec29",
|
|
132
|
+
"@dxos/schema": "0.8.4-main.dfabb4ec29",
|
|
133
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.dfabb4ec29"
|
|
125
134
|
},
|
|
126
135
|
"peerDependencies": {
|
|
127
136
|
"@effect-atom/atom-react": "^0.5.0",
|
|
128
137
|
"@effect/platform": "0.94.4",
|
|
129
|
-
"effect": "3.
|
|
138
|
+
"effect": "3.20.0",
|
|
130
139
|
"react": "~19.2.3",
|
|
131
140
|
"react-dom": "~19.2.3",
|
|
132
|
-
"@dxos/react-
|
|
133
|
-
"@dxos/react-
|
|
134
|
-
"@dxos/ui-theme": "0.8.4-main.
|
|
141
|
+
"@dxos/react-client": "0.8.4-main.dfabb4ec29",
|
|
142
|
+
"@dxos/react-ui": "0.8.4-main.dfabb4ec29",
|
|
143
|
+
"@dxos/ui-theme": "0.8.4-main.dfabb4ec29"
|
|
135
144
|
},
|
|
136
145
|
"publishConfig": {
|
|
137
146
|
"access": "public"
|
|
@@ -6,10 +6,10 @@ import { type Decorator, type Meta, type StoryObj } from '@storybook/react-vite'
|
|
|
6
6
|
import React, { useMemo } from 'react';
|
|
7
7
|
|
|
8
8
|
import { createDocAccessor, createObject } from '@dxos/echo-db';
|
|
9
|
-
import {
|
|
9
|
+
import { random } from '@dxos/random';
|
|
10
10
|
import { useThemeContext } from '@dxos/react-ui';
|
|
11
|
-
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
12
11
|
import { withAttention } from '@dxos/react-ui-attention/testing';
|
|
12
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
13
13
|
import { Text } from '@dxos/schema';
|
|
14
14
|
import {
|
|
15
15
|
automerge,
|
|
@@ -20,21 +20,15 @@ import {
|
|
|
20
20
|
} from '@dxos/ui-editor';
|
|
21
21
|
|
|
22
22
|
import { createMenuGroup } from '../EditorMenuProvider';
|
|
23
|
+
import { Editor, type EditorViewProps } from './Editor';
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// TODO(burdon): PreviewPopoverProvider (MarkdownStream, Preview story).
|
|
27
|
-
// TODO(burdon): Adapt Markdown plugin to use new Editor (plan first to check fit).
|
|
28
|
-
// TODO(burdon): Remove redundant hooks and simplify props.
|
|
29
|
-
|
|
30
|
-
faker.seed(1234);
|
|
25
|
+
random.seed(1234);
|
|
31
26
|
|
|
32
27
|
const initialValue = ['# Blue Monday', '', 'How does it **feel**?', ''].join('\n');
|
|
33
28
|
|
|
34
|
-
const items =
|
|
29
|
+
const items = random.helpers.multiple(random.commerce.productName, { count: 10 }).sort();
|
|
35
30
|
|
|
36
|
-
|
|
37
|
-
const withExtensions: Decorator<EditorContentProps> = (Story, { args }) => {
|
|
31
|
+
const withExtensions: Decorator<EditorViewProps> = (Story, { args }) => {
|
|
38
32
|
const { themeMode } = useThemeContext();
|
|
39
33
|
const extensions = useMemo(
|
|
40
34
|
() => [
|
|
@@ -42,7 +36,7 @@ const withExtensions: Decorator<EditorContentProps> = (Story, { args }) => {
|
|
|
42
36
|
createThemeExtensions({ themeMode }),
|
|
43
37
|
createMarkdownExtensions(),
|
|
44
38
|
decorateMarkdown(),
|
|
45
|
-
automerge(createDocAccessor(createObject(Text.make(args.initialValue)), ['content'])),
|
|
39
|
+
automerge(createDocAccessor(createObject(Text.make({ content: args.initialValue })), ['content'])),
|
|
46
40
|
],
|
|
47
41
|
[themeMode],
|
|
48
42
|
);
|
|
@@ -52,7 +46,7 @@ const withExtensions: Decorator<EditorContentProps> = (Story, { args }) => {
|
|
|
52
46
|
|
|
53
47
|
const meta = {
|
|
54
48
|
title: 'ui/react-ui-editor/Editor',
|
|
55
|
-
component: Editor.
|
|
49
|
+
component: Editor.View,
|
|
56
50
|
decorators: [withExtensions, withTheme(), withLayout({ layout: 'column' }), withAttention()],
|
|
57
51
|
parameters: {
|
|
58
52
|
layout: 'fullscreen',
|
|
@@ -60,16 +54,16 @@ const meta = {
|
|
|
60
54
|
args: {
|
|
61
55
|
initialValue,
|
|
62
56
|
},
|
|
63
|
-
} satisfies Meta<typeof Editor.
|
|
57
|
+
} satisfies Meta<typeof Editor.View>;
|
|
64
58
|
|
|
65
59
|
export default meta;
|
|
66
60
|
|
|
67
|
-
type Story = StoryObj<
|
|
61
|
+
type Story = StoryObj<EditorViewProps>;
|
|
68
62
|
|
|
69
63
|
export const Default: Story = {
|
|
70
64
|
render: (args) => (
|
|
71
65
|
<Editor.Root>
|
|
72
|
-
<Editor.
|
|
66
|
+
<Editor.View {...args} />
|
|
73
67
|
</Editor.Root>
|
|
74
68
|
),
|
|
75
69
|
};
|
|
@@ -78,7 +72,7 @@ export const WithToolbar: Story = {
|
|
|
78
72
|
render: (args) => (
|
|
79
73
|
<Editor.Root>
|
|
80
74
|
<Editor.Toolbar />
|
|
81
|
-
<Editor.
|
|
75
|
+
<Editor.View {...args} />
|
|
82
76
|
</Editor.Root>
|
|
83
77
|
),
|
|
84
78
|
};
|
|
@@ -86,10 +80,10 @@ export const WithToolbar: Story = {
|
|
|
86
80
|
export const WithPopover: Story = {
|
|
87
81
|
render: (args) => (
|
|
88
82
|
<Editor.Root trigger={['@']} getMenu={({ text }) => [createMenuGroup({ items, filter: text })]}>
|
|
89
|
-
<Editor.
|
|
83
|
+
<Editor.Content>
|
|
90
84
|
<Editor.Toolbar />
|
|
91
|
-
<Editor.
|
|
92
|
-
</Editor.
|
|
85
|
+
<Editor.View {...args} />
|
|
86
|
+
</Editor.Content>
|
|
93
87
|
</Editor.Root>
|
|
94
88
|
),
|
|
95
89
|
};
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Extension } from '@codemirror/state';
|
|
6
|
+
import { Atom } from '@effect-atom/atom-react';
|
|
6
7
|
import { createContext } from '@radix-ui/react-context';
|
|
7
8
|
import React, { type PropsWithChildren, forwardRef, useCallback, useImperativeHandle, useMemo, useState } from 'react';
|
|
8
9
|
|
|
@@ -12,18 +13,23 @@ import { mx } from '@dxos/ui-theme';
|
|
|
12
13
|
import { isNonNullable } from '@dxos/util';
|
|
13
14
|
|
|
14
15
|
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
type
|
|
18
|
-
|
|
19
|
-
} from '../
|
|
20
|
-
import { EditorMenuProvider, type UseEditorMenuProps, useEditorMenu } from '../EditorMenuProvider';
|
|
16
|
+
EditorMenuProvider,
|
|
17
|
+
type EditorMenuProviderProps,
|
|
18
|
+
type UseEditorMenuProps,
|
|
19
|
+
useEditorMenu,
|
|
20
|
+
} from '../EditorMenuProvider';
|
|
21
21
|
import {
|
|
22
22
|
type EditorToolbarState,
|
|
23
23
|
EditorToolbar as NaturalEditorToolbar,
|
|
24
24
|
type EditorToolbarProps as NaturalEditorToolbarProps,
|
|
25
|
-
useEditorToolbar,
|
|
26
25
|
} from '../EditorToolbar';
|
|
26
|
+
import {
|
|
27
|
+
type EditorController,
|
|
28
|
+
EditorView as NaturalEditorContent,
|
|
29
|
+
type EditorViewProps as NaturalEditorContentProps,
|
|
30
|
+
createEditorController,
|
|
31
|
+
noopController,
|
|
32
|
+
} from './EditorView';
|
|
27
33
|
|
|
28
34
|
//
|
|
29
35
|
// Context
|
|
@@ -33,16 +39,26 @@ type EditorContextValue = {
|
|
|
33
39
|
controller?: EditorController;
|
|
34
40
|
setController: (controller: EditorController) => void;
|
|
35
41
|
extensions?: Extension[];
|
|
36
|
-
|
|
42
|
+
state: Atom.Writable<EditorToolbarState>;
|
|
43
|
+
};
|
|
37
44
|
|
|
38
45
|
const [EditorContextProvider, useEditorContext] = createContext<EditorContextValue>('Editor');
|
|
39
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Access the editor context. Must be used within `Editor.Root`.
|
|
49
|
+
*/
|
|
50
|
+
export { useEditorContext };
|
|
51
|
+
|
|
40
52
|
//
|
|
41
53
|
// Root
|
|
42
54
|
//
|
|
43
55
|
|
|
44
56
|
type EditorRootProps = PropsWithChildren<
|
|
45
|
-
Pick<EditorContextValue, 'extensions'> &
|
|
57
|
+
Pick<EditorContextValue, 'extensions'> &
|
|
58
|
+
Omit<UseEditorMenuProps, 'viewRef'> &
|
|
59
|
+
Pick<EditorMenuProviderProps, 'numItems'> & {
|
|
60
|
+
viewMode?: EditorToolbarState['viewMode'];
|
|
61
|
+
}
|
|
46
62
|
>;
|
|
47
63
|
|
|
48
64
|
/**
|
|
@@ -50,11 +66,9 @@ type EditorRootProps = PropsWithChildren<
|
|
|
50
66
|
* Provides context for all child components and manages the editor controller state.
|
|
51
67
|
*/
|
|
52
68
|
const EditorRoot = forwardRef<EditorController | null, EditorRootProps>(
|
|
53
|
-
({ children, extensions: extensionsProp, viewMode, ...props }, forwardedRef) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const [controller, setController] = useState<EditorController>();
|
|
57
|
-
useImperativeHandle(forwardedRef, () => controller ?? noopController, [controller]);
|
|
69
|
+
({ children, extensions: extensionsProp, viewMode, numItems, ...props }, forwardedRef) => {
|
|
70
|
+
// TODO(wittjosiah): Including initialState in the deps causes reactivity issues.
|
|
71
|
+
const state = useMemo(() => Atom.make<EditorToolbarState>({ viewMode }), [viewMode]);
|
|
58
72
|
|
|
59
73
|
// TODO(burdon): Consider lighter-weight approach if EditorMenuProvider is not needed.
|
|
60
74
|
const { groupsRef, extension, ...menuProps } = useEditorMenu(props);
|
|
@@ -63,6 +77,10 @@ const EditorRoot = forwardRef<EditorController | null, EditorRootProps>(
|
|
|
63
77
|
[extension, extensionsProp],
|
|
64
78
|
);
|
|
65
79
|
|
|
80
|
+
// External controller.
|
|
81
|
+
const [controller, setController] = useState<EditorController>(noopController);
|
|
82
|
+
useImperativeHandle(forwardedRef, () => controller, [controller]);
|
|
83
|
+
|
|
66
84
|
return (
|
|
67
85
|
<EditorContextProvider
|
|
68
86
|
controller={controller}
|
|
@@ -70,7 +88,7 @@ const EditorRoot = forwardRef<EditorController | null, EditorRootProps>(
|
|
|
70
88
|
extensions={extensions}
|
|
71
89
|
state={state}
|
|
72
90
|
>
|
|
73
|
-
<EditorMenuProvider view={controller?.view} groups={groupsRef.current} {...menuProps}>
|
|
91
|
+
<EditorMenuProvider view={controller?.view} groups={groupsRef.current} numItems={numItems} {...menuProps}>
|
|
74
92
|
{children}
|
|
75
93
|
</EditorMenuProvider>
|
|
76
94
|
</EditorContextProvider>
|
|
@@ -81,41 +99,36 @@ const EditorRoot = forwardRef<EditorController | null, EditorRootProps>(
|
|
|
81
99
|
EditorRoot.displayName = 'Editor.Root';
|
|
82
100
|
|
|
83
101
|
//
|
|
84
|
-
//
|
|
102
|
+
// Content
|
|
85
103
|
//
|
|
86
104
|
|
|
87
|
-
const
|
|
105
|
+
const EDITOR_CONTENT_NAME = 'Editor.Content';
|
|
88
106
|
|
|
89
|
-
type
|
|
107
|
+
type EditorContentProps = ThemedClassName<PropsWithChildren<{}>>;
|
|
90
108
|
|
|
91
109
|
/**
|
|
92
|
-
*
|
|
110
|
+
* Content component that wraps the toolbar and editor view area.
|
|
93
111
|
*/
|
|
94
|
-
const
|
|
95
|
-
return (
|
|
96
|
-
<div role='none' className={mx('grid grid-rows-[min-content_1fr] h-full overflow-hidden', classNames)}>
|
|
97
|
-
{children}
|
|
98
|
-
</div>
|
|
99
|
-
);
|
|
112
|
+
const EditorContent = ({ classNames, children }: EditorContentProps) => {
|
|
113
|
+
return <div className={mx('grid grid-rows-[min-content_1fr] h-full overflow-hidden', classNames)}>{children}</div>;
|
|
100
114
|
};
|
|
101
115
|
|
|
102
|
-
|
|
116
|
+
EditorContent.displayName = EDITOR_CONTENT_NAME;
|
|
103
117
|
|
|
104
118
|
//
|
|
105
|
-
//
|
|
119
|
+
// View
|
|
106
120
|
//
|
|
107
121
|
|
|
108
|
-
const
|
|
122
|
+
const EDITOR_VIEW_NAME = 'Editor.View';
|
|
109
123
|
|
|
110
|
-
type
|
|
124
|
+
type EditorViewProps = Omit<NaturalEditorContentProps, 'ref'>;
|
|
111
125
|
|
|
112
126
|
/**
|
|
113
|
-
*
|
|
127
|
+
* View component that renders the actual CodeMirror editor.
|
|
114
128
|
* Automatically registers the editor controller with the context.
|
|
115
129
|
*/
|
|
116
|
-
const
|
|
117
|
-
const { extensions: additionalExtensions = [], setController } = useEditorContext(
|
|
118
|
-
|
|
130
|
+
const EditorView = ({ extensions: providedExtensions, ...props }: EditorViewProps) => {
|
|
131
|
+
const { extensions: additionalExtensions = [], setController } = useEditorContext(EDITOR_VIEW_NAME);
|
|
119
132
|
const extensions = useMemo(
|
|
120
133
|
() => [additionalExtensions, providedExtensions].filter(isNonNullable).flat(),
|
|
121
134
|
[providedExtensions, additionalExtensions],
|
|
@@ -124,7 +137,7 @@ const EditorContent = ({ extensions: providedExtensions, ...props }: EditorConte
|
|
|
124
137
|
return <NaturalEditorContent {...props} extensions={extensions} ref={setController} />;
|
|
125
138
|
};
|
|
126
139
|
|
|
127
|
-
|
|
140
|
+
EditorView.displayName = EDITOR_VIEW_NAME;
|
|
128
141
|
|
|
129
142
|
//
|
|
130
143
|
// Toolbar
|
|
@@ -140,8 +153,6 @@ type EditorToolbarProps = Omit<NaturalEditorToolbarProps, 'getView' | 'state'>;
|
|
|
140
153
|
*/
|
|
141
154
|
const EditorToolbar = (props: EditorToolbarProps) => {
|
|
142
155
|
const { controller, state } = useEditorContext(EDITOR_TOOLBAR_NAME);
|
|
143
|
-
|
|
144
|
-
// TODO(burdon): Fix invariant.
|
|
145
156
|
const getView = useCallback(() => {
|
|
146
157
|
invariant(controller?.view);
|
|
147
158
|
return controller?.view;
|
|
@@ -156,30 +167,20 @@ EditorToolbar.displayName = EDITOR_TOOLBAR_NAME;
|
|
|
156
167
|
// Editor
|
|
157
168
|
//
|
|
158
169
|
|
|
159
|
-
/**
|
|
160
|
-
* Compound editor component following the Radix UI pattern.
|
|
161
|
-
*
|
|
162
|
-
* @example
|
|
163
|
-
* ```tsx
|
|
164
|
-
* EditorMenuGroup.Root>
|
|
165
|
-
* EditorMenuGroup.Toolbar />
|
|
166
|
-
* EditorMenuGroup.Viewport>
|
|
167
|
-
* EditorMenuGroup.Content extensions={[...]} />
|
|
168
|
-
* </Editor.Viewport>
|
|
169
|
-
* </Editor.Root>
|
|
170
|
-
* ```
|
|
171
|
-
*/
|
|
172
170
|
export const Editor = {
|
|
173
171
|
Root: EditorRoot,
|
|
174
|
-
Viewport: EditorViewport,
|
|
175
|
-
Content: EditorContent,
|
|
176
172
|
Toolbar: EditorToolbar,
|
|
173
|
+
Content: EditorContent,
|
|
174
|
+
View: EditorView,
|
|
177
175
|
};
|
|
178
176
|
|
|
179
177
|
export type {
|
|
180
178
|
EditorController,
|
|
181
179
|
EditorRootProps,
|
|
182
|
-
EditorViewportProps,
|
|
183
180
|
EditorContentProps,
|
|
184
|
-
|
|
181
|
+
EditorViewProps,
|
|
182
|
+
EditorToolbarProps,
|
|
183
|
+
EditorToolbarState,
|
|
185
184
|
};
|
|
185
|
+
|
|
186
|
+
export { createEditorController };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Transaction } from '@codemirror/state';
|
|
6
|
+
import { EditorView as NaturalEditorView } from '@codemirror/view';
|
|
7
|
+
import React, { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
|
|
8
|
+
|
|
9
|
+
import { type ThemedClassName } from '@dxos/react-ui';
|
|
10
|
+
import { initialSync } from '@dxos/ui-editor';
|
|
11
|
+
import { mx } from '@dxos/ui-theme';
|
|
12
|
+
|
|
13
|
+
import { type UseTextEditorProps, useTextEditor } from '../../hooks';
|
|
14
|
+
import { type EditorController, createEditorController, noopController } from './controller';
|
|
15
|
+
|
|
16
|
+
export type EditorViewProps = ThemedClassName<
|
|
17
|
+
{
|
|
18
|
+
focusable?: boolean;
|
|
19
|
+
value?: string;
|
|
20
|
+
onChange?: (value: string) => void;
|
|
21
|
+
} & UseTextEditorProps
|
|
22
|
+
>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Minimal text editor.
|
|
26
|
+
* NOTE: This shouold not be used with the automerge extension.
|
|
27
|
+
*/
|
|
28
|
+
// TODO(burdon): Move controller to Root component, then make composable.
|
|
29
|
+
export const EditorView = forwardRef<EditorController, EditorViewProps>(
|
|
30
|
+
({ classNames, id, extensions, selectionEnd, focusable = true, value, onChange, ...props }, forwardedRef) => {
|
|
31
|
+
// Hold the latest onChange in a ref so callers may pass an inline callback
|
|
32
|
+
// without forcing the underlying editor to be destroyed and recreated on
|
|
33
|
+
// every render — which would blur the focused input on each keystroke.
|
|
34
|
+
const onChangeRef = useRef(onChange);
|
|
35
|
+
onChangeRef.current = onChange;
|
|
36
|
+
|
|
37
|
+
const { parentRef, focusAttributes, view } = useTextEditor(
|
|
38
|
+
() => ({
|
|
39
|
+
id,
|
|
40
|
+
initialValue: value,
|
|
41
|
+
selectionEnd,
|
|
42
|
+
extensions: [
|
|
43
|
+
extensions ?? [],
|
|
44
|
+
NaturalEditorView.updateListener.of(({ view, docChanged, transactions }) => {
|
|
45
|
+
const isInitialSync = transactions.some((tr) => tr.annotation(Transaction.userEvent) === initialSync.value);
|
|
46
|
+
if (!isInitialSync && docChanged) {
|
|
47
|
+
onChangeRef.current?.(view.state.doc.toString());
|
|
48
|
+
}
|
|
49
|
+
}),
|
|
50
|
+
],
|
|
51
|
+
...props,
|
|
52
|
+
}),
|
|
53
|
+
[id, extensions, selectionEnd],
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
// External controller.
|
|
57
|
+
useImperativeHandle(forwardedRef, () => {
|
|
58
|
+
return createEditorController(view);
|
|
59
|
+
}, [id, view]);
|
|
60
|
+
|
|
61
|
+
// Sync the editor doc to the controlled `value` prop, but only when they
|
|
62
|
+
// disagree. After internal typing the prop will already match the editor's
|
|
63
|
+
// doc, and dispatching anyway would race fast keystrokes — a stale rAF
|
|
64
|
+
// closure can replace doc content with an older value, dropping characters.
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (!view) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const next = value ?? '';
|
|
70
|
+
if (view.state.doc.toString() === next) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
requestAnimationFrame(() => {
|
|
74
|
+
if (view.state.doc.toString() === next) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
view.dispatch({
|
|
78
|
+
annotations: initialSync,
|
|
79
|
+
changes: [{ from: 0, to: view.state.doc.length, insert: next }],
|
|
80
|
+
selection: selectionEnd ? { anchor: next.length } : undefined,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
if (selectionEnd) {
|
|
84
|
+
view.focus();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}, [view, value, selectionEnd]);
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<div
|
|
91
|
+
className={mx(
|
|
92
|
+
'w-full outline-hidden focus:border-accent-surface focus-within:border-neutral-focus-indicator',
|
|
93
|
+
classNames,
|
|
94
|
+
)}
|
|
95
|
+
{...(focusable ? focusAttributes : {})}
|
|
96
|
+
ref={parentRef}
|
|
97
|
+
/>
|
|
98
|
+
);
|
|
99
|
+
},
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
export { type EditorController, createEditorController, noopController };
|
|
@@ -36,9 +36,7 @@ export type EditorMenuProviderProps = PropsWithChildren<{
|
|
|
36
36
|
}>;
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* Implements the Popover and listens for the `dx-anchor-activate` event from the
|
|
40
|
-
* `popover` extension's decoration.
|
|
41
|
-
*
|
|
39
|
+
* Implements the Popover and listens for the `dx-anchor-activate` event from the `popover` extension's decoration.
|
|
42
40
|
* NOTE: We don't use DropdownMenu because the command menu needs to manage focus explicitly.
|
|
43
41
|
* I.e., focus must remain in the editor while displaying the menu (for type-ahead).
|
|
44
42
|
*/
|
|
@@ -139,7 +137,7 @@ export const EditorMenuProvider = ({
|
|
|
139
137
|
</Popover.Portal>
|
|
140
138
|
|
|
141
139
|
{/* Content */}
|
|
142
|
-
<div
|
|
140
|
+
<div className='contents' ref={setRoot}>
|
|
143
141
|
{children}
|
|
144
142
|
</div>
|
|
145
143
|
</Popover.Root>
|
|
@@ -221,7 +219,7 @@ const MenuItem = ({ item, current, onSelect }: MenuItemProps) => {
|
|
|
221
219
|
|
|
222
220
|
return (
|
|
223
221
|
<li ref={listRef} className={tx('menu.item', {}, [current && 'bg-hover-surface'])} onClick={handleSelect}>
|
|
224
|
-
{item.icon && <Icon icon={item.icon}
|
|
222
|
+
{item.icon && <Icon icon={item.icon} />}
|
|
225
223
|
<span className='grow truncate'>{toLocalizedString(item.label, t)}</span>
|
|
226
224
|
</li>
|
|
227
225
|
);
|
|
@@ -110,6 +110,7 @@ export const linkSlashCommands: EditorMenuGroup = {
|
|
|
110
110
|
label: 'Block embed',
|
|
111
111
|
icon: 'ph--lego--regular',
|
|
112
112
|
onSelect: ({ view, head }) => {
|
|
113
|
+
// Seed the same query shape as typing "@@" manually.
|
|
113
114
|
view.dispatch({
|
|
114
115
|
changes: { from: head, insert: '@@' },
|
|
115
116
|
selection: { anchor: head + 2, head: head + 2 },
|
|
@@ -13,7 +13,8 @@ import {
|
|
|
13
13
|
keymap,
|
|
14
14
|
} from '@codemirror/view';
|
|
15
15
|
|
|
16
|
-
import { type PlaceholderOptions,
|
|
16
|
+
import { type PlaceholderOptions, modalStateField, placeholder } from '@dxos/ui-editor';
|
|
17
|
+
import { type Range } from '@dxos/ui-editor/types';
|
|
17
18
|
import { isNonNullable, isTruthy } from '@dxos/util';
|
|
18
19
|
|
|
19
20
|
const DELIMITERS = [' ', ':'];
|
|
@@ -52,6 +53,7 @@ export const popover = (options: PopoverOptions = {}): Extension => {
|
|
|
52
53
|
placeholder({
|
|
53
54
|
// TODO(burdon): Translations.
|
|
54
55
|
content: `Press '${Array.isArray(options.trigger) ? options.trigger[0] : options.trigger}' for commands`,
|
|
56
|
+
focusOnly: true,
|
|
55
57
|
...options.placeholder,
|
|
56
58
|
}),
|
|
57
59
|
].filter(isTruthy);
|
|
@@ -62,7 +62,8 @@ export const useEditorMenu = ({
|
|
|
62
62
|
const getMenuOptions = useCallback<NonNullable<UseEditorMenuProps['getMenu']>>(
|
|
63
63
|
async ({ text, trigger, ...props }) => {
|
|
64
64
|
const groups = (await getMenu?.({ text, trigger, ...props })) ?? [];
|
|
65
|
-
|
|
65
|
+
// The "@" menu can use "@@" as syntax for block embeds, so it owns its own query filtering.
|
|
66
|
+
return filter && trigger !== '@'
|
|
66
67
|
? filterMenuGroups(groups, (item) =>
|
|
67
68
|
text ? (item.label as string).toLowerCase().startsWith(text.toLowerCase()) : true,
|
|
68
69
|
)
|
|
@@ -68,7 +68,7 @@ export const EditorPreviewProvider = ({ children, onLookup }: EditorPreviewProvi
|
|
|
68
68
|
<EditorPreviewContextProvider pending={value.pending} link={value.link} target={value.target}>
|
|
69
69
|
<Popover.Root open={open} onOpenChange={setOpen}>
|
|
70
70
|
<Popover.VirtualTrigger virtualRef={triggerRef as unknown as RefObject<HTMLButtonElement>} />
|
|
71
|
-
<div
|
|
71
|
+
<div className='contents' ref={setRoot}>
|
|
72
72
|
{children}
|
|
73
73
|
</div>
|
|
74
74
|
</Popover.Root>
|