@dxos/react-ui-editor 0.3.10-main.279fbbe → 0.3.10-main.33e06eb
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 +111 -25
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/comments.d.ts +10 -6
- package/dist/types/src/components/TextEditor/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/demo.d.ts +10 -0
- package/dist/types/src/components/TextEditor/extensions/demo.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/extensions/index.d.ts +1 -0
- package/dist/types/src/components/TextEditor/extensions/index.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/listener.d.ts +4 -2
- package/dist/types/src/components/TextEditor/extensions/listener.d.ts.map +1 -1
- package/package.json +20 -19
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +4 -2
- package/src/components/TextEditor/TextEditor.tsx +18 -4
- package/src/components/TextEditor/extensions/comments.ts +48 -31
- package/src/components/TextEditor/extensions/demo.ts +66 -0
- package/src/components/TextEditor/extensions/index.ts +1 -0
- package/src/components/TextEditor/extensions/listener.ts +2 -2
|
@@ -54,8 +54,66 @@ var basicBundle = ({ themeMode, placeholder: _placeholder }) => [
|
|
|
54
54
|
themeMode === "dark" ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle)
|
|
55
55
|
].filter(Boolean);
|
|
56
56
|
|
|
57
|
+
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/demo.ts
|
|
58
|
+
import { keymap as keymap2 } from "@codemirror/view";
|
|
59
|
+
var defaultItems = [
|
|
60
|
+
"hello world!",
|
|
61
|
+
"this is a test.",
|
|
62
|
+
"this is [DXOS](https://dxos.org)"
|
|
63
|
+
];
|
|
64
|
+
var demo = ({ delay = 75, items = defaultItems } = {}) => {
|
|
65
|
+
let t;
|
|
66
|
+
let idx = 0;
|
|
67
|
+
return [
|
|
68
|
+
keymap2.of([
|
|
69
|
+
{
|
|
70
|
+
// Reset.
|
|
71
|
+
key: "alt-meta-'",
|
|
72
|
+
run: (view) => {
|
|
73
|
+
clearTimeout(t);
|
|
74
|
+
idx = 0;
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
// Next prompt.
|
|
80
|
+
// TODO(burdon): Press 1-9 to select prompt?
|
|
81
|
+
key: "shift-meta-'",
|
|
82
|
+
run: (view) => {
|
|
83
|
+
clearTimeout(t);
|
|
84
|
+
const text = items[idx++];
|
|
85
|
+
if (idx === items?.length) {
|
|
86
|
+
idx = 0;
|
|
87
|
+
}
|
|
88
|
+
let i = 0;
|
|
89
|
+
const insert = (d = 0) => {
|
|
90
|
+
t = setTimeout(() => {
|
|
91
|
+
const pos = view.state.selection.main.head;
|
|
92
|
+
view.dispatch({
|
|
93
|
+
changes: {
|
|
94
|
+
from: pos,
|
|
95
|
+
insert: text[i++]
|
|
96
|
+
},
|
|
97
|
+
selection: {
|
|
98
|
+
anchor: pos + 1
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
if (i < text.length) {
|
|
102
|
+
insert(Math.random() * delay * (text[i] === " " ? 2 : 1));
|
|
103
|
+
}
|
|
104
|
+
}, d);
|
|
105
|
+
};
|
|
106
|
+
insert();
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
])
|
|
111
|
+
];
|
|
112
|
+
};
|
|
113
|
+
|
|
57
114
|
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/comments.ts
|
|
58
|
-
import { Decoration, EditorView as EditorView2,
|
|
115
|
+
import { keymap as keymap3, Decoration, EditorView as EditorView2, MatchDecorator, ViewPlugin, WidgetType } from "@codemirror/view";
|
|
116
|
+
import { debounce } from "@dxos/async";
|
|
59
117
|
import { invariant } from "@dxos/invariant";
|
|
60
118
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/components/TextEditor/extensions/comments.ts";
|
|
61
119
|
var BookmarkWidget = class extends WidgetType {
|
|
@@ -65,7 +123,7 @@ var BookmarkWidget = class extends WidgetType {
|
|
|
65
123
|
this._id = _id;
|
|
66
124
|
invariant(this._id, void 0, {
|
|
67
125
|
F: __dxlog_file,
|
|
68
|
-
L:
|
|
126
|
+
L: 41,
|
|
69
127
|
S: this,
|
|
70
128
|
A: [
|
|
71
129
|
"this._id",
|
|
@@ -76,7 +134,6 @@ var BookmarkWidget = class extends WidgetType {
|
|
|
76
134
|
eq(other) {
|
|
77
135
|
return this._id === other._id;
|
|
78
136
|
}
|
|
79
|
-
// TODO(burdon): Click to select.
|
|
80
137
|
toDOM() {
|
|
81
138
|
const span = document.createElement("span");
|
|
82
139
|
span.className = "cm-bookmark";
|
|
@@ -90,9 +147,13 @@ var styles = EditorView2.baseTheme({
|
|
|
90
147
|
margin: "4px",
|
|
91
148
|
padding: "4px",
|
|
92
149
|
backgroundColor: "yellow"
|
|
150
|
+
},
|
|
151
|
+
"& .cm-bookmark-selected": {
|
|
152
|
+
backgroundColor: "orange"
|
|
93
153
|
}
|
|
94
154
|
});
|
|
95
155
|
var comments = (options = {}) => {
|
|
156
|
+
let active;
|
|
96
157
|
const bookmarkMatcher = new MatchDecorator({
|
|
97
158
|
regexp: /\[\^(\w+)\]/g,
|
|
98
159
|
decoration: (match, view, pos) => {
|
|
@@ -116,10 +177,13 @@ var comments = (options = {}) => {
|
|
|
116
177
|
return view.plugin(plugin)?.bookmarks || Decoration.none;
|
|
117
178
|
})
|
|
118
179
|
});
|
|
180
|
+
const doUpdate = debounce((data) => {
|
|
181
|
+
options.onUpdate?.(data);
|
|
182
|
+
}, 200);
|
|
119
183
|
return [
|
|
120
|
-
|
|
184
|
+
keymap3.of([
|
|
121
185
|
{
|
|
122
|
-
key: options?.key ?? "
|
|
186
|
+
key: options?.key ?? "shift-meta-c",
|
|
123
187
|
run: (view) => {
|
|
124
188
|
const id = options.onCreate?.();
|
|
125
189
|
if (id) {
|
|
@@ -143,30 +207,40 @@ var comments = (options = {}) => {
|
|
|
143
207
|
bookmarks,
|
|
144
208
|
// Monitor cursor movement.
|
|
145
209
|
EditorView2.updateListener.of((update2) => {
|
|
210
|
+
active = void 0;
|
|
211
|
+
if (!options.onUpdate) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
146
214
|
const view = update2.view;
|
|
147
215
|
const pos = view.state.selection.main.head;
|
|
148
216
|
const decorations = [];
|
|
149
217
|
const rangeSet = view.plugin(bookmarks)?.bookmarks;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
218
|
+
let closest = Infinity;
|
|
219
|
+
const { from, to } = view.visibleRanges?.[0] ?? {
|
|
220
|
+
from: 0,
|
|
221
|
+
to: view.state.doc.length
|
|
222
|
+
};
|
|
223
|
+
rangeSet?.between(from, to, (from2, to2, value) => {
|
|
224
|
+
decorations.push({
|
|
225
|
+
from: from2,
|
|
226
|
+
to: to2,
|
|
227
|
+
value
|
|
228
|
+
});
|
|
229
|
+
const d = Math.min(Math.abs(pos - from2), Math.abs(pos - to2));
|
|
230
|
+
if (d < closest) {
|
|
231
|
+
active = value.spec.id;
|
|
232
|
+
closest = d;
|
|
157
233
|
}
|
|
158
234
|
});
|
|
159
235
|
if (decorations.length) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
});
|
|
169
|
-
}
|
|
236
|
+
doUpdate({
|
|
237
|
+
active,
|
|
238
|
+
items: decorations.map(({ from: from2, value: { spec: { id } } }) => ({
|
|
239
|
+
id,
|
|
240
|
+
pos: from2,
|
|
241
|
+
location: view.coordsAtPos(from2)
|
|
242
|
+
}))
|
|
243
|
+
});
|
|
170
244
|
}
|
|
171
245
|
}),
|
|
172
246
|
styles
|
|
@@ -262,7 +336,7 @@ var link = (options = {}) => {
|
|
|
262
336
|
|
|
263
337
|
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/listener.ts
|
|
264
338
|
import { StateField as StateField2 } from "@codemirror/state";
|
|
265
|
-
var listener = (onChange) => StateField2.define({
|
|
339
|
+
var listener = ({ onChange }) => StateField2.define({
|
|
266
340
|
create: () => null,
|
|
267
341
|
update: (_value, transaction) => {
|
|
268
342
|
if (transaction.docChanged && onChange) {
|
|
@@ -281,7 +355,7 @@ import { languages } from "@codemirror/language-data";
|
|
|
281
355
|
import { highlightSelectionMatches, searchKeymap } from "@codemirror/search";
|
|
282
356
|
import { EditorState } from "@codemirror/state";
|
|
283
357
|
import { oneDarkHighlightStyle as oneDarkHighlightStyle2 } from "@codemirror/theme-one-dark";
|
|
284
|
-
import { crosshairCursor, drawSelection, dropCursor, EditorView as EditorView4, highlightActiveLine, highlightActiveLineGutter, highlightSpecialChars, keymap as
|
|
358
|
+
import { crosshairCursor, drawSelection, dropCursor, EditorView as EditorView4, highlightActiveLine, highlightActiveLineGutter, highlightSpecialChars, keymap as keymap4, placeholder as placeholder2, rectangularSelection } from "@codemirror/view";
|
|
285
359
|
|
|
286
360
|
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/markdown/highlight.ts
|
|
287
361
|
import { markdownLanguage } from "@codemirror/lang-markdown";
|
|
@@ -491,7 +565,7 @@ var markdownBundle = ({ themeMode, placeholder: _placeholder }) => {
|
|
|
491
565
|
indentOnInput(),
|
|
492
566
|
rectangularSelection(),
|
|
493
567
|
// TODO(burdon): Review.
|
|
494
|
-
|
|
568
|
+
keymap4.of([
|
|
495
569
|
...closeBracketsKeymap,
|
|
496
570
|
...defaultKeymap,
|
|
497
571
|
// ...foldKeymap,
|
|
@@ -926,6 +1000,15 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, extensions = [], slots
|
|
|
926
1000
|
onKeyUp: handleKeyUp
|
|
927
1001
|
});
|
|
928
1002
|
});
|
|
1003
|
+
var maybeDebug = () => {
|
|
1004
|
+
const items = localStorage.getItem("dxos.composer.demo");
|
|
1005
|
+
if (items) {
|
|
1006
|
+
return demo({
|
|
1007
|
+
items: items.split(",")
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
return [];
|
|
1011
|
+
};
|
|
929
1012
|
var TextEditor = /* @__PURE__ */ forwardRef(({ extensions = [], slots: _slots, ...props }, forwardedRef) => {
|
|
930
1013
|
const { themeMode } = useThemeContext();
|
|
931
1014
|
const slots = defaultsDeep({}, _slots, defaultTextSlots);
|
|
@@ -936,6 +1019,7 @@ var TextEditor = /* @__PURE__ */ forwardRef(({ extensions = [], slots: _slots, .
|
|
|
936
1019
|
themeMode,
|
|
937
1020
|
placeholder: slots?.editor?.placeholder
|
|
938
1021
|
}),
|
|
1022
|
+
maybeDebug(),
|
|
939
1023
|
...extensions
|
|
940
1024
|
],
|
|
941
1025
|
slots,
|
|
@@ -952,6 +1036,7 @@ var MarkdownEditor = /* @__PURE__ */ forwardRef(({ extensions = [], slots: _slot
|
|
|
952
1036
|
themeMode,
|
|
953
1037
|
placeholder: slots?.editor?.placeholder
|
|
954
1038
|
}),
|
|
1039
|
+
maybeDebug(),
|
|
955
1040
|
...extensions
|
|
956
1041
|
],
|
|
957
1042
|
slots,
|
|
@@ -1465,6 +1550,7 @@ export {
|
|
|
1465
1550
|
defaultSlots,
|
|
1466
1551
|
defaultTextSlots,
|
|
1467
1552
|
defaultTheme,
|
|
1553
|
+
demo,
|
|
1468
1554
|
link,
|
|
1469
1555
|
listener,
|
|
1470
1556
|
markdownBundle,
|