@dxos/react-ui-editor 0.4.1 → 0.4.2-main.0e5b9e5
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 +237 -181
- 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 +4 -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/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/automerge.stories.d.ts +2 -2
- package/dist/types/src/components/TextEditor/automerge.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/annotations.d.ts +6 -0
- package/dist/types/src/extensions/annotations.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/{semaphore.d.ts → sync.d.ts} +6 -5
- package/dist/types/src/extensions/automerge/sync.d.ts.map +1 -0
- package/dist/types/src/extensions/index.d.ts +1 -0
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +17 -4
- package/src/components/TextEditor/TextEditor.stories.tsx +8 -2
- package/src/components/TextEditor/TextEditor.tsx +1 -0
- package/src/components/TextEditor/automerge.stories.tsx +39 -47
- package/src/components/Toolbar/Toolbar.stories.tsx +1 -1
- package/src/extensions/annotations.ts +78 -0
- package/src/extensions/automerge/automerge.ts +5 -21
- package/src/extensions/automerge/{semaphore.ts → sync.ts} +32 -34
- package/src/extensions/index.ts +1 -0
- package/src/hooks/useTextModel.ts +5 -5
- package/dist/types/src/extensions/automerge/semaphore.d.ts.map +0 -1
|
@@ -8,14 +8,114 @@ import { tags as tags2 } from "@lezer/highlight";
|
|
|
8
8
|
|
|
9
9
|
// packages/ui/react-ui-editor/src/components/TextEditor/TextEditor.tsx
|
|
10
10
|
import { EditorState as EditorState2 } from "@codemirror/state";
|
|
11
|
-
import { EditorView as
|
|
11
|
+
import { EditorView as EditorView15 } from "@codemirror/view";
|
|
12
12
|
import { vim } from "@replit/codemirror-vim";
|
|
13
13
|
import defaultsDeep2 from "lodash.defaultsdeep";
|
|
14
14
|
import React, { forwardRef, useCallback, useEffect as useEffect2, useImperativeHandle, useRef, useState as useState2 } from "react";
|
|
15
15
|
import { log as log2 } from "@dxos/log";
|
|
16
16
|
import { useThemeContext } from "@dxos/react-ui";
|
|
17
17
|
import { focusRing, mx as mx3 } from "@dxos/react-ui-theme";
|
|
18
|
-
import { isNotFalsy as
|
|
18
|
+
import { isNotFalsy as isNotFalsy4 } from "@dxos/util";
|
|
19
|
+
|
|
20
|
+
// packages/ui/react-ui-editor/src/extensions/annotations.ts
|
|
21
|
+
import { StateField } from "@codemirror/state";
|
|
22
|
+
import { Decoration, EditorView } from "@codemirror/view";
|
|
23
|
+
import { isNotFalsy } from "@dxos/util";
|
|
24
|
+
|
|
25
|
+
// packages/ui/react-ui-editor/src/extensions/cursor.ts
|
|
26
|
+
import { Facet } from "@codemirror/state";
|
|
27
|
+
var defaultCursorConverter = {
|
|
28
|
+
toCursor: (position) => position.toString(),
|
|
29
|
+
fromCursor: (cursor) => parseInt(cursor)
|
|
30
|
+
};
|
|
31
|
+
var Cursor = class _Cursor {
|
|
32
|
+
static {
|
|
33
|
+
this.converter = Facet.define({
|
|
34
|
+
combine: (providers) => providers[0] ?? defaultCursorConverter
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
static {
|
|
38
|
+
this.getCursorFromRange = (state, range) => {
|
|
39
|
+
const cursorConverter2 = state.facet(_Cursor.converter);
|
|
40
|
+
const from = cursorConverter2.toCursor(range.from);
|
|
41
|
+
const to = cursorConverter2.toCursor(range.to, -1);
|
|
42
|
+
return [
|
|
43
|
+
from,
|
|
44
|
+
to
|
|
45
|
+
].join(":");
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
static {
|
|
49
|
+
this.getRangeFromCursor = (state, cursor) => {
|
|
50
|
+
const cursorConverter2 = state.facet(_Cursor.converter);
|
|
51
|
+
const parts = cursor.split(":");
|
|
52
|
+
const from = cursorConverter2.fromCursor(parts[0]);
|
|
53
|
+
const to = cursorConverter2.fromCursor(parts[1]);
|
|
54
|
+
return from !== void 0 && to !== void 0 ? {
|
|
55
|
+
from,
|
|
56
|
+
to
|
|
57
|
+
} : void 0;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// packages/ui/react-ui-editor/src/extensions/annotations.ts
|
|
63
|
+
var annotationMark = Decoration.mark({
|
|
64
|
+
class: "cm-annotation"
|
|
65
|
+
});
|
|
66
|
+
var annotations = (options = {}) => {
|
|
67
|
+
const match = (state) => {
|
|
68
|
+
const annotations2 = [];
|
|
69
|
+
const text = state.doc.toString();
|
|
70
|
+
if (options.match) {
|
|
71
|
+
const matches = text.matchAll(options.match);
|
|
72
|
+
for (const match2 of matches) {
|
|
73
|
+
const from = match2.index;
|
|
74
|
+
const to = from + match2[0].length;
|
|
75
|
+
const cursor = Cursor.getCursorFromRange(state, {
|
|
76
|
+
from,
|
|
77
|
+
to
|
|
78
|
+
});
|
|
79
|
+
annotations2.push({
|
|
80
|
+
cursor
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return annotations2;
|
|
85
|
+
};
|
|
86
|
+
const annotationsState = StateField.define({
|
|
87
|
+
create: (state) => {
|
|
88
|
+
return match(state);
|
|
89
|
+
},
|
|
90
|
+
update: (value, tr) => {
|
|
91
|
+
if (!tr.changes.empty) {
|
|
92
|
+
return match(tr.state);
|
|
93
|
+
}
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return [
|
|
98
|
+
annotationsState,
|
|
99
|
+
EditorView.decorations.compute([
|
|
100
|
+
annotationsState
|
|
101
|
+
], (state) => {
|
|
102
|
+
const annotations2 = state.field(annotationsState);
|
|
103
|
+
const decorations = annotations2.map((annotation) => {
|
|
104
|
+
const range = Cursor.getRangeFromCursor(state, annotation.cursor);
|
|
105
|
+
return range && annotationMark.range(range.from, range.to);
|
|
106
|
+
}).filter(isNotFalsy);
|
|
107
|
+
return Decoration.set(decorations);
|
|
108
|
+
}),
|
|
109
|
+
styles
|
|
110
|
+
];
|
|
111
|
+
};
|
|
112
|
+
var styles = EditorView.baseTheme({
|
|
113
|
+
".cm-annotation": {
|
|
114
|
+
textDecoration: "underline",
|
|
115
|
+
textDecorationStyle: "wavy",
|
|
116
|
+
textDecorationColor: "red"
|
|
117
|
+
}
|
|
118
|
+
});
|
|
19
119
|
|
|
20
120
|
// packages/ui/react-ui-editor/src/extensions/autocomplete.ts
|
|
21
121
|
import { autocompletion, completionKeymap } from "@codemirror/autocomplete";
|
|
@@ -54,9 +154,8 @@ var autocomplete = ({ onSearch }) => {
|
|
|
54
154
|
};
|
|
55
155
|
|
|
56
156
|
// packages/ui/react-ui-editor/src/extensions/automerge/automerge.ts
|
|
57
|
-
import {
|
|
58
|
-
import {
|
|
59
|
-
import { EditorView, ViewPlugin } from "@codemirror/view";
|
|
157
|
+
import { StateField as StateField2 } from "@codemirror/state";
|
|
158
|
+
import { EditorView as EditorView2, ViewPlugin } from "@codemirror/view";
|
|
60
159
|
import { next as A4 } from "@dxos/automerge/automerge";
|
|
61
160
|
|
|
62
161
|
// packages/ui/react-ui-editor/src/extensions/automerge/cursor.ts
|
|
@@ -108,7 +207,7 @@ var isReconcile = (tr) => {
|
|
|
108
207
|
return !!tr.annotation(reconcileAnnotation);
|
|
109
208
|
};
|
|
110
209
|
|
|
111
|
-
// packages/ui/react-ui-editor/src/extensions/automerge/
|
|
210
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/sync.ts
|
|
112
211
|
import { next as A3 } from "@dxos/automerge/automerge";
|
|
113
212
|
|
|
114
213
|
// packages/ui/react-ui-editor/src/extensions/automerge/update-automerge.ts
|
|
@@ -249,40 +348,42 @@ var charPath = (textPath, candidatePath) => {
|
|
|
249
348
|
return null;
|
|
250
349
|
};
|
|
251
350
|
|
|
252
|
-
// packages/ui/react-ui-editor/src/extensions/automerge/
|
|
253
|
-
var
|
|
351
|
+
// packages/ui/react-ui-editor/src/extensions/automerge/sync.ts
|
|
352
|
+
var Syncer = class {
|
|
254
353
|
// prettier-ignore
|
|
255
354
|
constructor(_handle, _state) {
|
|
256
355
|
this._handle = _handle;
|
|
257
356
|
this._state = _state;
|
|
258
|
-
this.
|
|
357
|
+
this._pending = false;
|
|
259
358
|
}
|
|
260
|
-
reconcile(view) {
|
|
261
|
-
if (
|
|
262
|
-
|
|
263
|
-
this.doReconcile(view);
|
|
264
|
-
this._inReconcile = false;
|
|
359
|
+
reconcile(view, editor) {
|
|
360
|
+
if (this._pending) {
|
|
361
|
+
return;
|
|
265
362
|
}
|
|
363
|
+
this._pending = true;
|
|
364
|
+
if (editor) {
|
|
365
|
+
this.onEditorChange(view);
|
|
366
|
+
} else {
|
|
367
|
+
this.onAutomergeChange(view);
|
|
368
|
+
}
|
|
369
|
+
this._pending = false;
|
|
266
370
|
}
|
|
267
|
-
|
|
268
|
-
const path = getPath(view.state, this._state);
|
|
269
|
-
const oldHeads = getLastHeads(view.state, this._state);
|
|
270
|
-
let selection = view.state.selection;
|
|
371
|
+
onEditorChange(view) {
|
|
271
372
|
const transactions = view.state.field(this._state).unreconciledTransactions.filter((tx) => !isReconcile(tx));
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
const inverted = tr.changes.invert(tr.startState.doc);
|
|
275
|
-
selection = selection.map(inverted);
|
|
373
|
+
const newHeads = updateAutomerge(this._state, this._handle, transactions, view.state);
|
|
374
|
+
if (newHeads) {
|
|
276
375
|
view.dispatch({
|
|
277
|
-
|
|
278
|
-
annotations: reconcileAnnotation.of(
|
|
376
|
+
effects: updateHeads(newHeads),
|
|
377
|
+
annotations: reconcileAnnotation.of(false)
|
|
279
378
|
});
|
|
280
379
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
380
|
+
}
|
|
381
|
+
onAutomergeChange(view) {
|
|
382
|
+
const oldHeads = getLastHeads(view.state, this._state);
|
|
383
|
+
const newHeads = A3.getHeads(this._handle.docSync());
|
|
285
384
|
const diff = A3.equals(oldHeads, newHeads) ? [] : A3.diff(this._handle.docSync(), oldHeads, newHeads);
|
|
385
|
+
const selection = view.state.selection;
|
|
386
|
+
const path = getPath(view.state, this._state);
|
|
286
387
|
updateCodeMirror(view, selection, path, diff);
|
|
287
388
|
view.dispatch({
|
|
288
389
|
effects: updateHeads(newHeads),
|
|
@@ -291,46 +392,9 @@ var PatchSemaphore = class {
|
|
|
291
392
|
}
|
|
292
393
|
};
|
|
293
394
|
|
|
294
|
-
// packages/ui/react-ui-editor/src/extensions/cursor.ts
|
|
295
|
-
import { Facet } from "@codemirror/state";
|
|
296
|
-
var defaultCursorConverter = {
|
|
297
|
-
toCursor: (position) => position.toString(),
|
|
298
|
-
fromCursor: (cursor) => parseInt(cursor)
|
|
299
|
-
};
|
|
300
|
-
var Cursor = class _Cursor {
|
|
301
|
-
static {
|
|
302
|
-
this.converter = Facet.define({
|
|
303
|
-
combine: (providers) => providers[0] ?? defaultCursorConverter
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
static {
|
|
307
|
-
this.getCursorFromRange = (state, range) => {
|
|
308
|
-
const cursorConverter2 = state.facet(_Cursor.converter);
|
|
309
|
-
const from = cursorConverter2.toCursor(range.from);
|
|
310
|
-
const to = cursorConverter2.toCursor(range.to, -1);
|
|
311
|
-
return [
|
|
312
|
-
from,
|
|
313
|
-
to
|
|
314
|
-
].join(":");
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
static {
|
|
318
|
-
this.getRangeFromCursor = (state, cursor) => {
|
|
319
|
-
const cursorConverter2 = state.facet(_Cursor.converter);
|
|
320
|
-
const parts = cursor.split(":");
|
|
321
|
-
const from = cursorConverter2.fromCursor(parts[0]);
|
|
322
|
-
const to = cursorConverter2.fromCursor(parts[1]);
|
|
323
|
-
return from !== void 0 && to !== void 0 ? {
|
|
324
|
-
from,
|
|
325
|
-
to
|
|
326
|
-
} : void 0;
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
};
|
|
330
|
-
|
|
331
395
|
// packages/ui/react-ui-editor/src/extensions/automerge/automerge.ts
|
|
332
396
|
var automerge = ({ handle, path }) => {
|
|
333
|
-
const syncState =
|
|
397
|
+
const syncState = StateField2.define({
|
|
334
398
|
create: () => ({
|
|
335
399
|
path: path.slice(),
|
|
336
400
|
lastHeads: A4.getHeads(handle.docSync()),
|
|
@@ -359,7 +423,7 @@ var automerge = ({ handle, path }) => {
|
|
|
359
423
|
return result;
|
|
360
424
|
}
|
|
361
425
|
});
|
|
362
|
-
const
|
|
426
|
+
const syncer = new Syncer(handle, syncState);
|
|
363
427
|
return [
|
|
364
428
|
Cursor.converter.of(cursorConverter(handle, path)),
|
|
365
429
|
syncState,
|
|
@@ -373,32 +437,21 @@ var automerge = ({ handle, path }) => {
|
|
|
373
437
|
handle.removeListener("change", this._handleChange.bind(this));
|
|
374
438
|
}
|
|
375
439
|
_handleChange() {
|
|
376
|
-
|
|
440
|
+
syncer.reconcile(this._view, false);
|
|
377
441
|
}
|
|
378
442
|
}),
|
|
379
443
|
// Reconcile local updates.
|
|
380
|
-
|
|
444
|
+
EditorView2.updateListener.of(({ view, changes }) => {
|
|
381
445
|
if (!changes.empty) {
|
|
382
|
-
|
|
383
|
-
}
|
|
384
|
-
}),
|
|
385
|
-
// TODO(burdon): Record undo transactions.
|
|
386
|
-
// See https://github.com/yjs/y-codemirror.next/tree/main
|
|
387
|
-
// https://codemirror.net/examples/inverted-effect
|
|
388
|
-
invertedEffects.of((tr) => {
|
|
389
|
-
const effects = [];
|
|
390
|
-
if (!tr.changes.empty) {
|
|
391
|
-
tr.changes.iterChanges((fromA, toA, fromB, toB, inserted) => {
|
|
392
|
-
});
|
|
446
|
+
syncer.reconcile(view, true);
|
|
393
447
|
}
|
|
394
|
-
return effects;
|
|
395
448
|
})
|
|
396
449
|
];
|
|
397
450
|
};
|
|
398
451
|
|
|
399
452
|
// packages/ui/react-ui-editor/src/extensions/awareness.ts
|
|
400
453
|
import { Annotation as Annotation2, Facet as Facet2, RangeSet } from "@codemirror/state";
|
|
401
|
-
import { Decoration, EditorView as
|
|
454
|
+
import { Decoration as Decoration2, EditorView as EditorView3, ViewPlugin as ViewPlugin2, WidgetType } from "@codemirror/view";
|
|
402
455
|
import { Event } from "@dxos/async";
|
|
403
456
|
import { Context } from "@dxos/context";
|
|
404
457
|
var dummyProvider = {
|
|
@@ -421,7 +474,7 @@ var awareness = (provider = dummyProvider) => {
|
|
|
421
474
|
ViewPlugin2.fromClass(RemoteSelectionsDecorator, {
|
|
422
475
|
decorations: (value) => value.decorations
|
|
423
476
|
}),
|
|
424
|
-
|
|
477
|
+
styles2
|
|
425
478
|
];
|
|
426
479
|
};
|
|
427
480
|
var RemoteSelectionsDecorator = class {
|
|
@@ -481,7 +534,7 @@ var RemoteSelectionsDecorator = class {
|
|
|
481
534
|
decorations.push({
|
|
482
535
|
from: start,
|
|
483
536
|
to: end,
|
|
484
|
-
value:
|
|
537
|
+
value: Decoration2.mark({
|
|
485
538
|
attributes: {
|
|
486
539
|
style: `background-color: ${lightColor}`
|
|
487
540
|
},
|
|
@@ -492,7 +545,7 @@ var RemoteSelectionsDecorator = class {
|
|
|
492
545
|
decorations.push({
|
|
493
546
|
from: start,
|
|
494
547
|
to: startLine.from + startLine.length,
|
|
495
|
-
value:
|
|
548
|
+
value: Decoration2.mark({
|
|
496
549
|
attributes: {
|
|
497
550
|
style: `background-color: ${color}`
|
|
498
551
|
},
|
|
@@ -502,7 +555,7 @@ var RemoteSelectionsDecorator = class {
|
|
|
502
555
|
decorations.push({
|
|
503
556
|
from: endLine.from,
|
|
504
557
|
to: end,
|
|
505
|
-
value:
|
|
558
|
+
value: Decoration2.mark({
|
|
506
559
|
attributes: {
|
|
507
560
|
style: `background-color: ${color}`
|
|
508
561
|
},
|
|
@@ -514,7 +567,7 @@ var RemoteSelectionsDecorator = class {
|
|
|
514
567
|
decorations.push({
|
|
515
568
|
from: linePos,
|
|
516
569
|
to: linePos,
|
|
517
|
-
value:
|
|
570
|
+
value: Decoration2.line({
|
|
518
571
|
attributes: {
|
|
519
572
|
style: `background-color: ${color}`,
|
|
520
573
|
class: "cm-collab-selectionLine"
|
|
@@ -526,14 +579,14 @@ var RemoteSelectionsDecorator = class {
|
|
|
526
579
|
decorations.push({
|
|
527
580
|
from: head,
|
|
528
581
|
to: head,
|
|
529
|
-
value:
|
|
582
|
+
value: Decoration2.widget({
|
|
530
583
|
side: head - anchor > 0 ? -1 : 1,
|
|
531
584
|
block: false,
|
|
532
585
|
widget: new RemoteCaretWidget(state.info.displayName ?? "Anonymous", color)
|
|
533
586
|
})
|
|
534
587
|
});
|
|
535
588
|
}
|
|
536
|
-
this.decorations =
|
|
589
|
+
this.decorations = Decoration2.set(decorations, true);
|
|
537
590
|
}
|
|
538
591
|
};
|
|
539
592
|
var RemoteCaretWidget = class extends WidgetType {
|
|
@@ -572,7 +625,7 @@ var RemoteCaretWidget = class extends WidgetType {
|
|
|
572
625
|
return true;
|
|
573
626
|
}
|
|
574
627
|
};
|
|
575
|
-
var
|
|
628
|
+
var styles2 = EditorView3.baseTheme({
|
|
576
629
|
".cm-collab-selection": {},
|
|
577
630
|
".cm-collab-selectionLine": {
|
|
578
631
|
padding: 0,
|
|
@@ -636,10 +689,10 @@ import { closeBrackets } from "@codemirror/autocomplete";
|
|
|
636
689
|
import { history } from "@codemirror/commands";
|
|
637
690
|
import { bracketMatching, defaultHighlightStyle, syntaxHighlighting } from "@codemirror/language";
|
|
638
691
|
import { oneDarkHighlightStyle } from "@codemirror/theme-one-dark";
|
|
639
|
-
import { drawSelection, EditorView as
|
|
640
|
-
import { isNotFalsy } from "@dxos/util";
|
|
692
|
+
import { drawSelection, EditorView as EditorView4, highlightActiveLine, placeholder } from "@codemirror/view";
|
|
693
|
+
import { isNotFalsy as isNotFalsy2 } from "@dxos/util";
|
|
641
694
|
var createBasicBundle = ({ themeMode, placeholder: _placeholder, lineWrapping = true } = {}) => [
|
|
642
|
-
lineWrapping &&
|
|
695
|
+
lineWrapping && EditorView4.lineWrapping,
|
|
643
696
|
// https://codemirror.net/docs/ref/#codemirror.minimalSetup
|
|
644
697
|
bracketMatching(),
|
|
645
698
|
closeBrackets(),
|
|
@@ -649,10 +702,10 @@ var createBasicBundle = ({ themeMode, placeholder: _placeholder, lineWrapping =
|
|
|
649
702
|
_placeholder && placeholder(_placeholder),
|
|
650
703
|
// https://github.com/codemirror/theme-one-dark
|
|
651
704
|
themeMode === "dark" ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle)
|
|
652
|
-
].filter(
|
|
705
|
+
].filter(isNotFalsy2);
|
|
653
706
|
|
|
654
707
|
// packages/ui/react-ui-editor/src/extensions/blast.ts
|
|
655
|
-
import { EditorView as
|
|
708
|
+
import { EditorView as EditorView5, keymap as keymap2 } from "@codemirror/view";
|
|
656
709
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
657
710
|
import { invariant } from "@dxos/invariant";
|
|
658
711
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/blast.ts";
|
|
@@ -700,7 +753,7 @@ var blast = (options = defaultOptions) => {
|
|
|
700
753
|
};
|
|
701
754
|
return [
|
|
702
755
|
// Cursor moved.
|
|
703
|
-
|
|
756
|
+
EditorView5.updateListener.of((update2) => {
|
|
704
757
|
if (blaster?.node !== update2.view.scrollDOM) {
|
|
705
758
|
if (blaster) {
|
|
706
759
|
blaster.destroy();
|
|
@@ -962,9 +1015,9 @@ var random = (min, max) => {
|
|
|
962
1015
|
};
|
|
963
1016
|
|
|
964
1017
|
// packages/ui/react-ui-editor/src/extensions/comments.ts
|
|
965
|
-
import { invertedEffects
|
|
966
|
-
import { Facet as Facet3, StateEffect as StateEffect2, StateField as
|
|
967
|
-
import { hoverTooltip, keymap as keymap3, Decoration as
|
|
1018
|
+
import { invertedEffects } from "@codemirror/commands";
|
|
1019
|
+
import { Facet as Facet3, StateEffect as StateEffect2, StateField as StateField3 } from "@codemirror/state";
|
|
1020
|
+
import { hoverTooltip, keymap as keymap3, Decoration as Decoration3, EditorView as EditorView6 } from "@codemirror/view";
|
|
968
1021
|
import sortBy from "lodash.sortby";
|
|
969
1022
|
import { useEffect } from "react";
|
|
970
1023
|
import { debounce } from "@dxos/async";
|
|
@@ -1073,7 +1126,7 @@ var logChanges = (trs) => {
|
|
|
1073
1126
|
};
|
|
1074
1127
|
|
|
1075
1128
|
// packages/ui/react-ui-editor/src/extensions/comments.ts
|
|
1076
|
-
var
|
|
1129
|
+
var styles3 = EditorView6.baseTheme({
|
|
1077
1130
|
"&light .cm-comment, &light .cm-comment-current": {
|
|
1078
1131
|
mixBlendMode: "darken"
|
|
1079
1132
|
},
|
|
@@ -1095,10 +1148,10 @@ var styles2 = EditorView5.baseTheme({
|
|
|
1095
1148
|
backgroundColor: getToken("extend.colors.yellow.950")
|
|
1096
1149
|
}
|
|
1097
1150
|
});
|
|
1098
|
-
var commentMark =
|
|
1151
|
+
var commentMark = Decoration3.mark({
|
|
1099
1152
|
class: "cm-comment"
|
|
1100
1153
|
});
|
|
1101
|
-
var commentCurrentMark =
|
|
1154
|
+
var commentCurrentMark = Decoration3.mark({
|
|
1102
1155
|
class: "cm-comment-current"
|
|
1103
1156
|
});
|
|
1104
1157
|
var focusComment = (view, id, center = true) => {
|
|
@@ -1114,7 +1167,7 @@ var focusComment = (view, id, center = true) => {
|
|
|
1114
1167
|
},
|
|
1115
1168
|
effects: [
|
|
1116
1169
|
//
|
|
1117
|
-
|
|
1170
|
+
EditorView6.scrollIntoView(range.from, center ? {
|
|
1118
1171
|
y: "center"
|
|
1119
1172
|
} : void 0),
|
|
1120
1173
|
setSelection.of({
|
|
@@ -1127,7 +1180,7 @@ var focusComment = (view, id, center = true) => {
|
|
|
1127
1180
|
var setComments = StateEffect2.define();
|
|
1128
1181
|
var setSelection = StateEffect2.define();
|
|
1129
1182
|
var setCommentState = StateEffect2.define();
|
|
1130
|
-
var commentsState =
|
|
1183
|
+
var commentsState = StateField3.define({
|
|
1131
1184
|
create: () => ({
|
|
1132
1185
|
comments: [],
|
|
1133
1186
|
selection: {}
|
|
@@ -1163,7 +1216,7 @@ var commentsState = StateField2.define({
|
|
|
1163
1216
|
return value;
|
|
1164
1217
|
}
|
|
1165
1218
|
});
|
|
1166
|
-
var commentsDecorations =
|
|
1219
|
+
var commentsDecorations = EditorView6.decorations.compute([
|
|
1167
1220
|
commentsState
|
|
1168
1221
|
], (state) => {
|
|
1169
1222
|
const { selection: { current }, comments: comments2 } = state.field(commentsState);
|
|
@@ -1179,7 +1232,7 @@ var commentsDecorations = EditorView5.decorations.compute([
|
|
|
1179
1232
|
return commentMark.range(range.from, range.to);
|
|
1180
1233
|
}
|
|
1181
1234
|
}).filter(nonNullable);
|
|
1182
|
-
return
|
|
1235
|
+
return Decoration3.set(decorations);
|
|
1183
1236
|
});
|
|
1184
1237
|
var trackPastedComments = (onUpdate) => {
|
|
1185
1238
|
let tracked = null;
|
|
@@ -1201,12 +1254,12 @@ var trackPastedComments = (onUpdate) => {
|
|
|
1201
1254
|
}
|
|
1202
1255
|
};
|
|
1203
1256
|
return [
|
|
1204
|
-
|
|
1257
|
+
EditorView6.domEventHandlers({
|
|
1205
1258
|
cut: handleTrack,
|
|
1206
1259
|
copy: handleTrack
|
|
1207
1260
|
}),
|
|
1208
1261
|
// Track deleted comments.
|
|
1209
|
-
|
|
1262
|
+
invertedEffects.of((tr) => {
|
|
1210
1263
|
const { comments: comments2 } = tr.startState.field(commentsState);
|
|
1211
1264
|
const effects = [];
|
|
1212
1265
|
tr.changes.iterChangedRanges((fromA, toA) => {
|
|
@@ -1223,7 +1276,7 @@ var trackPastedComments = (onUpdate) => {
|
|
|
1223
1276
|
return effects;
|
|
1224
1277
|
}),
|
|
1225
1278
|
// Handle paste or the undo of comment deletion.
|
|
1226
|
-
|
|
1279
|
+
EditorView6.updateListener.of((update2) => {
|
|
1227
1280
|
const restore = [];
|
|
1228
1281
|
for (let i = 0; i < update2.transactions.length; i++) {
|
|
1229
1282
|
const tr = update2.transactions[i];
|
|
@@ -1330,7 +1383,7 @@ var comments = (options = {}) => {
|
|
|
1330
1383
|
optionsFacet.of(options),
|
|
1331
1384
|
commentsState,
|
|
1332
1385
|
commentsDecorations,
|
|
1333
|
-
|
|
1386
|
+
styles3,
|
|
1334
1387
|
//
|
|
1335
1388
|
// Keymap.
|
|
1336
1389
|
//
|
|
@@ -1373,7 +1426,7 @@ var comments = (options = {}) => {
|
|
|
1373
1426
|
//
|
|
1374
1427
|
// Track deleted ranges and update ranges for decorations.
|
|
1375
1428
|
//
|
|
1376
|
-
|
|
1429
|
+
EditorView6.updateListener.of(({ view, state, changes }) => {
|
|
1377
1430
|
let mod = false;
|
|
1378
1431
|
const { comments: comments2, ...value } = state.field(commentsState);
|
|
1379
1432
|
changes.iterChanges((from, to, from2, to2) => {
|
|
@@ -1405,7 +1458,7 @@ var comments = (options = {}) => {
|
|
|
1405
1458
|
//
|
|
1406
1459
|
// Track selection/proximity.
|
|
1407
1460
|
//
|
|
1408
|
-
|
|
1461
|
+
EditorView6.updateListener.of(({ view, state }) => {
|
|
1409
1462
|
let min = Infinity;
|
|
1410
1463
|
const { selection: { current, closest }, comments: comments2 } = state.field(commentsState);
|
|
1411
1464
|
const { head } = state.selection.main;
|
|
@@ -1454,14 +1507,14 @@ var useComments = (view, comments2 = []) => {
|
|
|
1454
1507
|
};
|
|
1455
1508
|
|
|
1456
1509
|
// packages/ui/react-ui-editor/src/extensions/listener.ts
|
|
1457
|
-
import { EditorView as
|
|
1510
|
+
import { EditorView as EditorView7 } from "@codemirror/view";
|
|
1458
1511
|
var listener = ({ onFocus, onChange }) => {
|
|
1459
1512
|
const extensions = [];
|
|
1460
|
-
onFocus && extensions.push(
|
|
1513
|
+
onFocus && extensions.push(EditorView7.focusChangeEffect.of((_, focused) => {
|
|
1461
1514
|
onFocus(focused);
|
|
1462
1515
|
return null;
|
|
1463
1516
|
}));
|
|
1464
|
-
onChange && extensions.push(
|
|
1517
|
+
onChange && extensions.push(EditorView7.updateListener.of((update2) => {
|
|
1465
1518
|
onChange(update2.state.doc.toString());
|
|
1466
1519
|
}));
|
|
1467
1520
|
return extensions;
|
|
@@ -1476,8 +1529,8 @@ import { languages } from "@codemirror/language-data";
|
|
|
1476
1529
|
import { searchKeymap } from "@codemirror/search";
|
|
1477
1530
|
import { EditorState } from "@codemirror/state";
|
|
1478
1531
|
import { oneDarkHighlightStyle as oneDarkHighlightStyle2 } from "@codemirror/theme-one-dark";
|
|
1479
|
-
import { crosshairCursor, drawSelection as drawSelection2, dropCursor, EditorView as
|
|
1480
|
-
import { isNotFalsy as
|
|
1532
|
+
import { crosshairCursor, drawSelection as drawSelection2, dropCursor, EditorView as EditorView8, highlightActiveLine as highlightActiveLine2, keymap as keymap4, placeholder as placeholder2 } from "@codemirror/view";
|
|
1533
|
+
import { isNotFalsy as isNotFalsy3 } from "@dxos/util";
|
|
1481
1534
|
|
|
1482
1535
|
// packages/ui/react-ui-editor/src/extensions/markdown/highlight.ts
|
|
1483
1536
|
import { markdownLanguage as markdownLanguage2 } from "@codemirror/lang-markdown";
|
|
@@ -1670,7 +1723,7 @@ var markdownHighlightStyle = (readonly) => {
|
|
|
1670
1723
|
// packages/ui/react-ui-editor/src/extensions/markdown/bundle.ts
|
|
1671
1724
|
var createMarkdownExtensions = ({ themeMode, placeholder: _placeholder, lineWrapping = true } = {}) => {
|
|
1672
1725
|
return [
|
|
1673
|
-
lineWrapping &&
|
|
1726
|
+
lineWrapping && EditorView8.lineWrapping,
|
|
1674
1727
|
EditorState.allowMultipleSelections.of(true),
|
|
1675
1728
|
EditorState.tabSize.of(2),
|
|
1676
1729
|
// https://github.com/codemirror/basic-setup
|
|
@@ -1717,15 +1770,15 @@ var createMarkdownExtensions = ({ themeMode, placeholder: _placeholder, lineWrap
|
|
|
1717
1770
|
// https://codemirror.net/docs/ref/#commands.standardKeymap
|
|
1718
1771
|
...standardKeymap
|
|
1719
1772
|
])
|
|
1720
|
-
].filter(
|
|
1773
|
+
].filter(isNotFalsy3);
|
|
1721
1774
|
};
|
|
1722
1775
|
|
|
1723
1776
|
// packages/ui/react-ui-editor/src/extensions/markdown/code.ts
|
|
1724
1777
|
import { syntaxTree } from "@codemirror/language";
|
|
1725
1778
|
import { RangeSetBuilder } from "@codemirror/state";
|
|
1726
|
-
import { ViewPlugin as ViewPlugin3, EditorView as
|
|
1779
|
+
import { ViewPlugin as ViewPlugin3, EditorView as EditorView9, Decoration as Decoration4, WidgetType as WidgetType2 } from "@codemirror/view";
|
|
1727
1780
|
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
1728
|
-
var
|
|
1781
|
+
var styles4 = EditorView9.baseTheme({
|
|
1729
1782
|
"& .cm-code": {
|
|
1730
1783
|
fontFamily: getToken("fontFamily.mono", []).join(",")
|
|
1731
1784
|
},
|
|
@@ -1802,11 +1855,11 @@ var buildDecorations = (view) => {
|
|
|
1802
1855
|
for (let i = range[0]; i <= range[1]; i++) {
|
|
1803
1856
|
const block = blocks[i];
|
|
1804
1857
|
if (!edit && (i === range[0] || i === range[1])) {
|
|
1805
|
-
builder.add(block.from, block.to,
|
|
1858
|
+
builder.add(block.from, block.to, Decoration4.replace({
|
|
1806
1859
|
widget: i === range[0] ? top : bottom
|
|
1807
1860
|
}));
|
|
1808
1861
|
} else {
|
|
1809
|
-
builder.add(block.from, block.from,
|
|
1862
|
+
builder.add(block.from, block.from, Decoration4.line({
|
|
1810
1863
|
class: mx2("cm-code cm-codeblock", i === range[0] && "cm-codeblock-first", i === range[1] && "cm-codeblock-last")
|
|
1811
1864
|
}));
|
|
1812
1865
|
}
|
|
@@ -1831,7 +1884,7 @@ var code2 = () => {
|
|
|
1831
1884
|
}, {
|
|
1832
1885
|
decorations: (value) => value.decorations
|
|
1833
1886
|
}),
|
|
1834
|
-
|
|
1887
|
+
styles4
|
|
1835
1888
|
];
|
|
1836
1889
|
};
|
|
1837
1890
|
|
|
@@ -1839,7 +1892,7 @@ var code2 = () => {
|
|
|
1839
1892
|
import { snippet } from "@codemirror/autocomplete";
|
|
1840
1893
|
import { syntaxTree as syntaxTree2 } from "@codemirror/language";
|
|
1841
1894
|
import { RangeSetBuilder as RangeSetBuilder2, EditorSelection } from "@codemirror/state";
|
|
1842
|
-
import { Decoration as
|
|
1895
|
+
import { Decoration as Decoration5, EditorView as EditorView10, keymap as keymap5, ViewPlugin as ViewPlugin4 } from "@codemirror/view";
|
|
1843
1896
|
import { useState, useMemo } from "react";
|
|
1844
1897
|
var compareFormatting = (a, b) => a.blockType === b.blockType && a.strong === b.strong && a.emphasis === b.emphasis && a.strikethrough === b.strikethrough && a.code === b.code && a.link === b.link && a.listStyle === b.listStyle && a.blockQuote === b.blockQuote;
|
|
1845
1898
|
var Inline;
|
|
@@ -2681,7 +2734,7 @@ var styling = () => {
|
|
|
2681
2734
|
const replace = (node, marks) => {
|
|
2682
2735
|
if (cursor <= node.from || cursor >= node.to) {
|
|
2683
2736
|
for (const mark2 of marks) {
|
|
2684
|
-
builder.add(mark2.from, mark2.to,
|
|
2737
|
+
builder.add(mark2.from, mark2.to, Decoration5.replace({}));
|
|
2685
2738
|
}
|
|
2686
2739
|
}
|
|
2687
2740
|
};
|
|
@@ -2911,7 +2964,7 @@ var getFormatting = (state) => {
|
|
|
2911
2964
|
};
|
|
2912
2965
|
var useFormattingState = () => {
|
|
2913
2966
|
const [state, setState] = useState(null);
|
|
2914
|
-
const observer = useMemo(() =>
|
|
2967
|
+
const observer = useMemo(() => EditorView10.updateListener.of((update2) => {
|
|
2915
2968
|
if (update2.docChanged || update2.selectionSet) {
|
|
2916
2969
|
const newState = getFormatting(update2.state);
|
|
2917
2970
|
if (!state || !compareFormatting(state, newState)) {
|
|
@@ -2928,7 +2981,7 @@ var useFormattingState = () => {
|
|
|
2928
2981
|
// packages/ui/react-ui-editor/src/extensions/markdown/heading.ts
|
|
2929
2982
|
import { syntaxTree as syntaxTree3 } from "@codemirror/language";
|
|
2930
2983
|
import { RangeSetBuilder as RangeSetBuilder3 } from "@codemirror/state";
|
|
2931
|
-
import { Decoration as
|
|
2984
|
+
import { Decoration as Decoration6, ViewPlugin as ViewPlugin5 } from "@codemirror/view";
|
|
2932
2985
|
var buildDecorations2 = (view) => {
|
|
2933
2986
|
const builder = new RangeSetBuilder3();
|
|
2934
2987
|
const { state } = view;
|
|
@@ -2946,7 +2999,7 @@ var buildDecorations2 = (view) => {
|
|
|
2946
2999
|
const mark2 = node.node.getChild("HeaderMark");
|
|
2947
3000
|
if (mark2) {
|
|
2948
3001
|
if (!view.hasFocus || view.state.readOnly || cursor < node.from || cursor > node.to) {
|
|
2949
|
-
builder.add(mark2.from, mark2.to + 1,
|
|
3002
|
+
builder.add(mark2.from, mark2.to + 1, Decoration6.replace({}));
|
|
2950
3003
|
}
|
|
2951
3004
|
}
|
|
2952
3005
|
}
|
|
@@ -2976,8 +3029,8 @@ var heading2 = () => {
|
|
|
2976
3029
|
// packages/ui/react-ui-editor/src/extensions/markdown/hr.ts
|
|
2977
3030
|
import { syntaxTree as syntaxTree4 } from "@codemirror/language";
|
|
2978
3031
|
import { RangeSetBuilder as RangeSetBuilder4 } from "@codemirror/state";
|
|
2979
|
-
import { Decoration as
|
|
2980
|
-
var
|
|
3032
|
+
import { Decoration as Decoration7, EditorView as EditorView11, ViewPlugin as ViewPlugin6, WidgetType as WidgetType3 } from "@codemirror/view";
|
|
3033
|
+
var styles5 = EditorView11.baseTheme({
|
|
2981
3034
|
"& .cm-hr": {
|
|
2982
3035
|
// Note that block-level decorations should not have vertical margins,
|
|
2983
3036
|
borderTop: `1px solid ${getToken("extend.colors.neutral.200")}`
|
|
@@ -2990,7 +3043,7 @@ var HorizontalRuleWidget = class extends WidgetType3 {
|
|
|
2990
3043
|
return el;
|
|
2991
3044
|
}
|
|
2992
3045
|
};
|
|
2993
|
-
var decoration =
|
|
3046
|
+
var decoration = Decoration7.replace({
|
|
2994
3047
|
widget: new HorizontalRuleWidget()
|
|
2995
3048
|
});
|
|
2996
3049
|
var buildDecorations3 = (view) => {
|
|
@@ -3024,18 +3077,18 @@ var hr = () => {
|
|
|
3024
3077
|
}, {
|
|
3025
3078
|
decorations: (value) => value.decorations
|
|
3026
3079
|
}),
|
|
3027
|
-
|
|
3080
|
+
styles5
|
|
3028
3081
|
];
|
|
3029
3082
|
};
|
|
3030
3083
|
|
|
3031
3084
|
// packages/ui/react-ui-editor/src/extensions/markdown/image.ts
|
|
3032
3085
|
import { syntaxTree as syntaxTree5 } from "@codemirror/language";
|
|
3033
|
-
import { StateField as
|
|
3034
|
-
import { Decoration as
|
|
3086
|
+
import { StateField as StateField4 } from "@codemirror/state";
|
|
3087
|
+
import { Decoration as Decoration8, EditorView as EditorView12, WidgetType as WidgetType4 } from "@codemirror/view";
|
|
3035
3088
|
var image = (options = {}) => {
|
|
3036
|
-
return
|
|
3089
|
+
return StateField4.define({
|
|
3037
3090
|
create: (state) => {
|
|
3038
|
-
return
|
|
3091
|
+
return Decoration8.set(buildDecorations4(0, state.doc.length, state));
|
|
3039
3092
|
},
|
|
3040
3093
|
update: (value, tr) => {
|
|
3041
3094
|
if (!tr.docChanged && !tr.selection) {
|
|
@@ -3058,7 +3111,7 @@ var image = (options = {}) => {
|
|
|
3058
3111
|
add: buildDecorations4(from, to, tr.state)
|
|
3059
3112
|
});
|
|
3060
3113
|
},
|
|
3061
|
-
provide: (field) =>
|
|
3114
|
+
provide: (field) => EditorView12.decorations.from(field)
|
|
3062
3115
|
});
|
|
3063
3116
|
};
|
|
3064
3117
|
var buildDecorations4 = (from, to, state) => {
|
|
@@ -3071,7 +3124,7 @@ var buildDecorations4 = (from, to, state) => {
|
|
|
3071
3124
|
if (urlNode) {
|
|
3072
3125
|
const hide = state.readOnly || cursor < node.from || cursor > node.to;
|
|
3073
3126
|
const url = state.sliceDoc(urlNode.from, urlNode.to);
|
|
3074
|
-
decorations.push(
|
|
3127
|
+
decorations.push(Decoration8.replace({
|
|
3075
3128
|
block: true,
|
|
3076
3129
|
widget: new ImageWidget(url)
|
|
3077
3130
|
}).range(hide ? node.from : node.to, node.to));
|
|
@@ -3103,7 +3156,7 @@ var ImageWidget = class extends WidgetType4 {
|
|
|
3103
3156
|
// packages/ui/react-ui-editor/src/extensions/markdown/link.ts
|
|
3104
3157
|
import { syntaxTree as syntaxTree6 } from "@codemirror/language";
|
|
3105
3158
|
import { RangeSetBuilder as RangeSetBuilder5 } from "@codemirror/state";
|
|
3106
|
-
import { hoverTooltip as hoverTooltip2, Decoration as
|
|
3159
|
+
import { hoverTooltip as hoverTooltip2, Decoration as Decoration9, ViewPlugin as ViewPlugin7, WidgetType as WidgetType5 } from "@codemirror/view";
|
|
3107
3160
|
import { tooltipContent } from "@dxos/react-ui-theme";
|
|
3108
3161
|
var link = (options = {}) => {
|
|
3109
3162
|
const extensions = [
|
|
@@ -3218,12 +3271,12 @@ var buildDecorations5 = (view, options) => {
|
|
|
3218
3271
|
return false;
|
|
3219
3272
|
}
|
|
3220
3273
|
if (!view.hasFocus || state.readOnly || cursor < node.from || cursor > node.to) {
|
|
3221
|
-
builder.add(node.from, node.to,
|
|
3274
|
+
builder.add(node.from, node.to, Decoration9.replace({
|
|
3222
3275
|
widget: new LinkText(text, options.link ? url : void 0)
|
|
3223
3276
|
}));
|
|
3224
3277
|
}
|
|
3225
3278
|
if (options.onRender) {
|
|
3226
|
-
builder.add(node.to, node.to,
|
|
3279
|
+
builder.add(node.to, node.to, Decoration9.replace({
|
|
3227
3280
|
widget: new LinkButton(url, options.onRender)
|
|
3228
3281
|
}));
|
|
3229
3282
|
}
|
|
@@ -3239,13 +3292,13 @@ var buildDecorations5 = (view, options) => {
|
|
|
3239
3292
|
|
|
3240
3293
|
// packages/ui/react-ui-editor/src/extensions/markdown/table.ts
|
|
3241
3294
|
import { syntaxTree as syntaxTree7 } from "@codemirror/language";
|
|
3242
|
-
import { RangeSetBuilder as RangeSetBuilder6, StateField as
|
|
3243
|
-
import { Decoration as
|
|
3295
|
+
import { RangeSetBuilder as RangeSetBuilder6, StateField as StateField5 } from "@codemirror/state";
|
|
3296
|
+
import { Decoration as Decoration10, EditorView as EditorView13, WidgetType as WidgetType6 } from "@codemirror/view";
|
|
3244
3297
|
var table = (options = {}) => {
|
|
3245
|
-
return
|
|
3298
|
+
return StateField5.define({
|
|
3246
3299
|
create: (state) => update(state, options),
|
|
3247
3300
|
update: (_, tr) => update(tr.state, options),
|
|
3248
|
-
provide: (field) =>
|
|
3301
|
+
provide: (field) => EditorView13.decorations.from(field)
|
|
3249
3302
|
});
|
|
3250
3303
|
};
|
|
3251
3304
|
var update = (state, options) => {
|
|
@@ -3289,10 +3342,10 @@ var update = (state, options) => {
|
|
|
3289
3342
|
});
|
|
3290
3343
|
tables.forEach((table2) => {
|
|
3291
3344
|
const hide = state.readOnly || cursor < table2.from || cursor > table2.to;
|
|
3292
|
-
hide && builder.add(table2.from, table2.to,
|
|
3345
|
+
hide && builder.add(table2.from, table2.to, Decoration10.replace({
|
|
3293
3346
|
widget: new TableWidget(table2)
|
|
3294
3347
|
}));
|
|
3295
|
-
builder.add(table2.from, table2.to,
|
|
3348
|
+
builder.add(table2.from, table2.to, Decoration10.mark({
|
|
3296
3349
|
class: "cm-table"
|
|
3297
3350
|
}));
|
|
3298
3351
|
});
|
|
@@ -3338,8 +3391,8 @@ var TableWidget = class extends WidgetType6 {
|
|
|
3338
3391
|
// packages/ui/react-ui-editor/src/extensions/markdown/tasklist.ts
|
|
3339
3392
|
import { syntaxTree as syntaxTree8 } from "@codemirror/language";
|
|
3340
3393
|
import { RangeSetBuilder as RangeSetBuilder7 } from "@codemirror/state";
|
|
3341
|
-
import { EditorView as
|
|
3342
|
-
var
|
|
3394
|
+
import { EditorView as EditorView14, Decoration as Decoration11, WidgetType as WidgetType7, ViewPlugin as ViewPlugin8 } from "@codemirror/view";
|
|
3395
|
+
var styles6 = EditorView14.baseTheme({
|
|
3343
3396
|
"& .cm-task": {
|
|
3344
3397
|
color: getToken("extend.colors.blue.500")
|
|
3345
3398
|
},
|
|
@@ -3385,10 +3438,10 @@ var CheckboxWidget = class extends WidgetType7 {
|
|
|
3385
3438
|
return false;
|
|
3386
3439
|
}
|
|
3387
3440
|
};
|
|
3388
|
-
var checkedDecoration =
|
|
3441
|
+
var checkedDecoration = Decoration11.replace({
|
|
3389
3442
|
widget: new CheckboxWidget(true)
|
|
3390
3443
|
});
|
|
3391
|
-
var uncheckedDecoration =
|
|
3444
|
+
var uncheckedDecoration = Decoration11.replace({
|
|
3392
3445
|
widget: new CheckboxWidget(false)
|
|
3393
3446
|
});
|
|
3394
3447
|
var buildDecorations6 = (view) => {
|
|
@@ -3401,7 +3454,7 @@ var buildDecorations6 = (view) => {
|
|
|
3401
3454
|
if (node.name === "TaskMarker") {
|
|
3402
3455
|
if (cursor < node.from || cursor > node.to) {
|
|
3403
3456
|
const checked = state.doc.sliceString(node.from + 1, node.to - 1) === "x";
|
|
3404
|
-
builder.add(node.from - 2, node.from - 1,
|
|
3457
|
+
builder.add(node.from - 2, node.from - 1, Decoration11.mark({
|
|
3405
3458
|
class: "cm-task"
|
|
3406
3459
|
}));
|
|
3407
3460
|
builder.add(node.from, node.to, checked ? checkedDecoration : uncheckedDecoration);
|
|
@@ -3428,7 +3481,7 @@ var tasklist = (options = {}) => {
|
|
|
3428
3481
|
}, {
|
|
3429
3482
|
decorations: (value) => value.decorations
|
|
3430
3483
|
}),
|
|
3431
|
-
|
|
3484
|
+
styles6
|
|
3432
3485
|
];
|
|
3433
3486
|
};
|
|
3434
3487
|
|
|
@@ -3801,27 +3854,27 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, autoFocus, s
|
|
|
3801
3854
|
selection,
|
|
3802
3855
|
extensions: [
|
|
3803
3856
|
// TODO(burdon): Doesn't catch errors in keymap functions.
|
|
3804
|
-
|
|
3857
|
+
EditorView15.exceptionSink.of((err) => {
|
|
3805
3858
|
log2.catch(err, void 0, {
|
|
3806
3859
|
F: __dxlog_file3,
|
|
3807
|
-
L:
|
|
3860
|
+
L: 135,
|
|
3808
3861
|
S: void 0,
|
|
3809
3862
|
C: (f, a) => f(...a)
|
|
3810
3863
|
});
|
|
3811
3864
|
}),
|
|
3812
3865
|
// Theme.
|
|
3813
3866
|
// TODO(burdon): Make configurable.
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3867
|
+
EditorView15.baseTheme(defaultTheme),
|
|
3868
|
+
EditorView15.theme(theme ?? {}),
|
|
3869
|
+
EditorView15.darkTheme.of(themeMode === "dark"),
|
|
3870
|
+
EditorView15.editorAttributes.of({
|
|
3818
3871
|
class: slots.editor?.className ?? ""
|
|
3819
3872
|
}),
|
|
3820
|
-
|
|
3873
|
+
EditorView15.contentAttributes.of({
|
|
3821
3874
|
class: slots.content?.className ?? ""
|
|
3822
3875
|
}),
|
|
3823
3876
|
// State.
|
|
3824
|
-
|
|
3877
|
+
EditorView15.editable.of(!readonly),
|
|
3825
3878
|
EditorState2.readOnly.of(!!readonly),
|
|
3826
3879
|
// Storage and replication.
|
|
3827
3880
|
// NOTE: This must come before user extensions.
|
|
@@ -3830,9 +3883,9 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, autoFocus, s
|
|
|
3830
3883
|
editorMode === "vim" && vim(),
|
|
3831
3884
|
// Custom.
|
|
3832
3885
|
...extensions
|
|
3833
|
-
].filter(
|
|
3886
|
+
].filter(isNotFalsy4)
|
|
3834
3887
|
});
|
|
3835
|
-
const newView = new
|
|
3888
|
+
const newView = new EditorView15({
|
|
3836
3889
|
state,
|
|
3837
3890
|
parent: rootRef.current,
|
|
3838
3891
|
scrollTo,
|
|
@@ -4243,8 +4296,8 @@ var SpaceAwarenessProvider = class {
|
|
|
4243
4296
|
};
|
|
4244
4297
|
|
|
4245
4298
|
// packages/ui/react-ui-editor/src/hooks/defs.ts
|
|
4246
|
-
import { StateField as
|
|
4247
|
-
var modelState =
|
|
4299
|
+
import { StateField as StateField6 } from "@codemirror/state";
|
|
4300
|
+
var modelState = StateField6.define({
|
|
4248
4301
|
create: () => void 0,
|
|
4249
4302
|
update: (model) => model
|
|
4250
4303
|
});
|
|
@@ -4311,10 +4364,10 @@ var useEditorView = () => {
|
|
|
4311
4364
|
|
|
4312
4365
|
// packages/ui/react-ui-editor/src/hooks/useTextEditor.ts
|
|
4313
4366
|
import { EditorSelection as EditorSelection2, EditorState as EditorState3 } from "@codemirror/state";
|
|
4314
|
-
import { EditorView as
|
|
4367
|
+
import { EditorView as EditorView16 } from "@codemirror/view";
|
|
4315
4368
|
import { useEffect as useEffect3, useRef as useRef2, useState as useState4 } from "react";
|
|
4316
4369
|
import { log as log4 } from "@dxos/log";
|
|
4317
|
-
import { isNotFalsy as
|
|
4370
|
+
import { isNotFalsy as isNotFalsy5 } from "@dxos/util";
|
|
4318
4371
|
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/useTextEditor.ts";
|
|
4319
4372
|
var useTextEditor = ({ autoFocus, scrollTo, debug, doc, selection, extensions } = {}) => {
|
|
4320
4373
|
const onUpdate = useRef2();
|
|
@@ -4327,7 +4380,7 @@ var useTextEditor = ({ autoFocus, scrollTo, debug, doc, selection, extensions }
|
|
|
4327
4380
|
selection,
|
|
4328
4381
|
extensions: [
|
|
4329
4382
|
// TODO(burdon): Doesn't catch errors in keymap functions.
|
|
4330
|
-
|
|
4383
|
+
EditorView16.exceptionSink.of((err) => {
|
|
4331
4384
|
log4.catch(err, void 0, {
|
|
4332
4385
|
F: __dxlog_file5,
|
|
4333
4386
|
L: 57,
|
|
@@ -4336,12 +4389,12 @@ var useTextEditor = ({ autoFocus, scrollTo, debug, doc, selection, extensions }
|
|
|
4336
4389
|
});
|
|
4337
4390
|
}),
|
|
4338
4391
|
extensions,
|
|
4339
|
-
|
|
4392
|
+
EditorView16.updateListener.of(() => {
|
|
4340
4393
|
onUpdate.current?.();
|
|
4341
4394
|
})
|
|
4342
|
-
].filter(
|
|
4395
|
+
].filter(isNotFalsy5)
|
|
4343
4396
|
});
|
|
4344
|
-
const view2 = new
|
|
4397
|
+
const view2 = new EditorView16({
|
|
4345
4398
|
parent: parentRef.current,
|
|
4346
4399
|
scrollTo,
|
|
4347
4400
|
state,
|
|
@@ -4398,22 +4451,22 @@ var createDataExtensions = ({ readonly = false } = {}) => {
|
|
|
4398
4451
|
return [
|
|
4399
4452
|
//
|
|
4400
4453
|
EditorState3.readOnly.of(readonly),
|
|
4401
|
-
|
|
4454
|
+
EditorView16.editable.of(!readonly)
|
|
4402
4455
|
];
|
|
4403
4456
|
};
|
|
4404
4457
|
var createThemeExtensions = ({ theme, themeMode, slots } = {}) => {
|
|
4405
4458
|
return [
|
|
4406
4459
|
//
|
|
4407
|
-
|
|
4408
|
-
theme &&
|
|
4409
|
-
|
|
4410
|
-
|
|
4460
|
+
EditorView16.baseTheme(defaultTheme),
|
|
4461
|
+
theme && EditorView16.theme(theme),
|
|
4462
|
+
EditorView16.darkTheme.of(themeMode === "dark"),
|
|
4463
|
+
EditorView16.editorAttributes.of({
|
|
4411
4464
|
class: slots?.editor?.className ?? ""
|
|
4412
4465
|
}),
|
|
4413
|
-
|
|
4466
|
+
EditorView16.contentAttributes.of({
|
|
4414
4467
|
class: slots?.content?.className ?? ""
|
|
4415
4468
|
})
|
|
4416
|
-
].filter(
|
|
4469
|
+
].filter(isNotFalsy5);
|
|
4417
4470
|
};
|
|
4418
4471
|
|
|
4419
4472
|
// packages/ui/react-ui-editor/src/hooks/useTextModel.ts
|
|
@@ -4444,9 +4497,12 @@ var useInMemoryTextModel = ({ id, defaultContent }) => {
|
|
|
4444
4497
|
};
|
|
4445
4498
|
};
|
|
4446
4499
|
var createModel = ({ space, identity, text }) => {
|
|
4500
|
+
if (!text) {
|
|
4501
|
+
return void 0;
|
|
4502
|
+
}
|
|
4447
4503
|
invariant3(isAutomergeObject(text), void 0, {
|
|
4448
4504
|
F: __dxlog_file6,
|
|
4449
|
-
L:
|
|
4505
|
+
L: 54,
|
|
4450
4506
|
S: void 0,
|
|
4451
4507
|
A: [
|
|
4452
4508
|
"isAutomergeObject(text)",
|
|
@@ -4468,7 +4524,6 @@ var createModel = ({ space, identity, text }) => {
|
|
|
4468
4524
|
peerId: identity?.identityKey.toHex() ?? "Anonymous"
|
|
4469
4525
|
});
|
|
4470
4526
|
const extensions = [
|
|
4471
|
-
//
|
|
4472
4527
|
modelState.init(() => model),
|
|
4473
4528
|
automerge({
|
|
4474
4529
|
handle: doc.handle,
|
|
@@ -4510,6 +4565,7 @@ export {
|
|
|
4510
4565
|
addLink,
|
|
4511
4566
|
addList,
|
|
4512
4567
|
addStyle,
|
|
4568
|
+
annotations,
|
|
4513
4569
|
autocomplete,
|
|
4514
4570
|
automerge,
|
|
4515
4571
|
awareness,
|