@dxos/ui-editor 0.8.4-main.ef1bc66f44 → 0.8.4-main.fcfe5033a5
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/chunk-D724USEC.mjs +34 -0
- package/dist/lib/browser/chunk-D724USEC.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1488 -716
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node-esm/chunk-JRVJWKQF.mjs +36 -0
- package/dist/lib/node-esm/chunk-JRVJWKQF.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1488 -716
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/types/index.mjs +1 -1
- package/dist/types/src/defaults.d.ts +4 -10
- package/dist/types/src/defaults.d.ts.map +1 -1
- package/dist/types/src/extensions/auto-scroll.d.ts +8 -0
- package/dist/types/src/extensions/auto-scroll.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/extensions/factories.d.ts +2 -2
- package/dist/types/src/extensions/factories.d.ts.map +1 -1
- package/dist/types/src/extensions/folding.d.ts.map +1 -1
- package/dist/types/src/extensions/index.d.ts +3 -2
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/action.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/bundle.d.ts +3 -0
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/decorate.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/link.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/styles.d.ts.map +1 -1
- package/dist/types/src/extensions/outliner/outliner.d.ts.map +1 -1
- package/dist/types/src/extensions/preview/preview.d.ts +2 -0
- package/dist/types/src/extensions/preview/preview.d.ts.map +1 -1
- package/dist/types/src/extensions/scroll-past-end.d.ts +3 -0
- package/dist/types/src/extensions/scroll-past-end.d.ts.map +1 -0
- package/dist/types/src/extensions/scroller.d.ts +63 -0
- package/dist/types/src/extensions/scroller.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/extended-markdown.d.ts.map +1 -1
- package/dist/types/src/extensions/tags/fader.d.ts +12 -0
- package/dist/types/src/extensions/tags/fader.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/index.d.ts +2 -1
- package/dist/types/src/extensions/tags/index.d.ts.map +1 -1
- package/dist/types/src/extensions/tags/wire.d.ts +23 -0
- package/dist/types/src/extensions/tags/wire.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/wire.test.d.ts +2 -0
- package/dist/types/src/extensions/tags/wire.test.d.ts.map +1 -0
- package/dist/types/src/extensions/tags/xml-tags.d.ts +36 -9
- package/dist/types/src/extensions/tags/xml-tags.d.ts.map +1 -1
- package/dist/types/src/styles/index.d.ts +0 -2
- package/dist/types/src/styles/index.d.ts.map +1 -1
- package/dist/types/src/styles/theme.d.ts +15 -0
- package/dist/types/src/styles/theme.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +2 -2
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/src/util/cursor.d.ts +1 -1
- package/dist/types/src/util/cursor.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +30 -30
- package/src/defaults.ts +30 -20
- package/src/extensions/annotations.ts +1 -1
- package/src/extensions/auto-scroll.ts +179 -0
- package/src/extensions/automerge/automerge.test.tsx +2 -2
- package/src/extensions/automerge/automerge.ts +5 -7
- package/src/extensions/blocks.ts +5 -5
- package/src/extensions/comments.ts +5 -6
- package/src/extensions/dnd.ts +2 -2
- package/src/extensions/factories.ts +13 -14
- package/src/extensions/folding.ts +5 -22
- package/src/extensions/index.ts +3 -2
- package/src/extensions/markdown/action.ts +0 -1
- package/src/extensions/markdown/bundle.ts +23 -9
- package/src/extensions/markdown/decorate.ts +15 -12
- package/src/extensions/markdown/highlight.ts +15 -7
- package/src/extensions/markdown/link.ts +27 -33
- package/src/extensions/markdown/parser.test.ts +0 -1
- package/src/extensions/markdown/styles.ts +42 -9
- package/src/extensions/markdown/table.ts +24 -2
- package/src/extensions/outliner/outliner.test.ts +0 -1
- package/src/extensions/outliner/outliner.ts +3 -4
- package/src/extensions/outliner/tree.test.ts +0 -1
- package/src/extensions/preview/preview.ts +55 -8
- package/src/extensions/scroll-past-end.ts +32 -0
- package/src/extensions/scroller.ts +245 -0
- package/src/extensions/selection.ts +1 -1
- package/src/extensions/tags/extended-markdown.test.ts +120 -2
- package/src/extensions/tags/extended-markdown.ts +80 -1
- package/src/extensions/tags/fader.ts +195 -0
- package/src/extensions/tags/index.ts +2 -1
- package/src/extensions/tags/wire.test.ts +65 -0
- package/src/extensions/tags/wire.ts +459 -0
- package/src/extensions/tags/xml-tags.ts +211 -34
- package/src/extensions/tags/xml-util.test.ts +111 -23
- package/src/styles/index.ts +0 -2
- package/src/styles/theme.ts +116 -34
- package/src/types/types.ts +10 -2
- package/src/util/cursor.ts +1 -2
- package/dist/lib/browser/chunk-HL3YF6WC.mjs +0 -22
- package/dist/lib/browser/chunk-HL3YF6WC.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-YJZGD3LY.mjs +0 -24
- package/dist/lib/node-esm/chunk-YJZGD3LY.mjs.map +0 -7
- package/dist/types/src/extensions/autoscroll.d.ts +0 -20
- package/dist/types/src/extensions/autoscroll.d.ts.map +0 -1
- package/dist/types/src/extensions/scrolling.d.ts +0 -78
- package/dist/types/src/extensions/scrolling.d.ts.map +0 -1
- package/dist/types/src/extensions/tags/streamer.d.ts +0 -12
- package/dist/types/src/extensions/tags/streamer.d.ts.map +0 -1
- package/dist/types/src/styles/markdown.d.ts +0 -8
- package/dist/types/src/styles/markdown.d.ts.map +0 -1
- package/dist/types/src/styles/tokens.d.ts +0 -3
- package/dist/types/src/styles/tokens.d.ts.map +0 -1
- package/src/extensions/autoscroll.ts +0 -165
- package/src/extensions/scrolling.ts +0 -189
- package/src/extensions/tags/streamer.ts +0 -243
- package/src/styles/markdown.ts +0 -26
- package/src/styles/tokens.ts +0 -17
|
@@ -3,27 +3,44 @@ import {
|
|
|
3
3
|
EditorInputModes,
|
|
4
4
|
EditorViewMode,
|
|
5
5
|
EditorViewModes
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-D724USEC.mjs";
|
|
7
7
|
|
|
8
8
|
// src/index.ts
|
|
9
|
-
import { EditorState as
|
|
10
|
-
import { EditorView as
|
|
9
|
+
import { EditorState as EditorState4 } from "@codemirror/state";
|
|
10
|
+
import { EditorView as EditorView32, keymap as keymap15 } from "@codemirror/view";
|
|
11
11
|
import { tags as tags2 } from "@lezer/highlight";
|
|
12
12
|
import { TextKind } from "@dxos/protocols/proto/dxos/echo/model/text";
|
|
13
13
|
|
|
14
14
|
// src/defaults.ts
|
|
15
15
|
import { mx } from "@dxos/ui-theme";
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
var editorClassNames = (role) => mx("dx-attention-surface p-0.5 data-[toolbar=disabled]:pt-2 dx-focus-ring-inset", role === "section" ? "[&_.cm-scroller]:overflow-hidden [&_.cm-scroller]:min-h-24" : "dx-container overflow-hidden");
|
|
17
|
+
var documentSlots = {
|
|
18
|
+
content: {
|
|
19
|
+
/**
|
|
20
|
+
* CodeMirror content width.
|
|
21
|
+
* 40rem = 640px. Corresponds to initial plank width (Google docs, Stashpad, etc.)
|
|
22
|
+
* 50rem = 800px. Maximum content width for solo mode.
|
|
23
|
+
* NOTE: Max width - 4rem = 2rem left/right margin (or 2rem gutter plus 1rem left/right margin).
|
|
24
|
+
*/
|
|
25
|
+
className: mx(
|
|
26
|
+
// NOTE: Container for widget sizing (must have `max-w-[100cqi]`).
|
|
27
|
+
"dx-size-container",
|
|
28
|
+
// Wider margin for web (vs. mobile).
|
|
29
|
+
"pointer-fine:max-w-[min(50rem,100%-4rem)] pointer-coarse:max-w-[min(50rem,100%-2rem)]",
|
|
30
|
+
"mx-auto! w-full"
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var compactSlots = {
|
|
35
|
+
content: {
|
|
36
|
+
className: "mx-2!"
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var mobileSlots = {
|
|
21
40
|
content: {
|
|
22
|
-
className:
|
|
41
|
+
className: "mx-2!"
|
|
23
42
|
}
|
|
24
43
|
};
|
|
25
|
-
var editorWithToolbarLayout = "grid grid-cols-1 grid-rows-[min-content_1fr] data-[toolbar=disabled]:grid-rows-[1fr] justify-center content-start overflow-hidden";
|
|
26
|
-
var stackItemContentEditorClassNames = (role) => mx("p-0.5 dx-focus-ring-inset attention-surface data-[toolbar=disabled]:pbs-2", role === "section" ? "[&_.cm-scroller]:overflow-hidden [&_.cm-scroller]:min-bs-24" : "min-bs-0");
|
|
27
44
|
|
|
28
45
|
// src/extensions/annotations.ts
|
|
29
46
|
import { RangeSetBuilder } from "@codemirror/state";
|
|
@@ -58,7 +75,7 @@ var annotations = ({ match } = {}) => {
|
|
|
58
75
|
".cm-annotation": {
|
|
59
76
|
textDecoration: "underline",
|
|
60
77
|
textDecorationStyle: "wavy",
|
|
61
|
-
textDecorationColor: "var(--
|
|
78
|
+
textDecorationColor: "var(--color-error-text)"
|
|
62
79
|
}
|
|
63
80
|
})
|
|
64
81
|
];
|
|
@@ -207,7 +224,7 @@ var singleValueFacet = (defaultValue) => Facet.define({
|
|
|
207
224
|
var overlap = (a, b) => a.from <= b.to && a.to >= b.from;
|
|
208
225
|
var defaultCursorConverter = {
|
|
209
226
|
toCursor: (position) => position.toString(),
|
|
210
|
-
fromCursor: (
|
|
227
|
+
fromCursor: (cursor) => parseInt(cursor)
|
|
211
228
|
};
|
|
212
229
|
var Cursor = class _Cursor {
|
|
213
230
|
static converter = singleValueFacet(defaultCursorConverter);
|
|
@@ -220,9 +237,9 @@ var Cursor = class _Cursor {
|
|
|
220
237
|
to
|
|
221
238
|
].join(":");
|
|
222
239
|
};
|
|
223
|
-
static getRangeFromCursor = (state,
|
|
240
|
+
static getRangeFromCursor = (state, cursor) => {
|
|
224
241
|
const cursorConverter2 = state.facet(_Cursor.converter);
|
|
225
|
-
const parts =
|
|
242
|
+
const parts = cursor.split(":");
|
|
226
243
|
const from = cursorConverter2.fromCursor(parts[0]);
|
|
227
244
|
const to = cursorConverter2.fromCursor(parts[1]);
|
|
228
245
|
return from !== void 0 && to !== void 0 ? {
|
|
@@ -501,228 +518,295 @@ var typeahead = ({ onComplete } = {}) => {
|
|
|
501
518
|
];
|
|
502
519
|
};
|
|
503
520
|
|
|
504
|
-
// src/extensions/
|
|
521
|
+
// src/extensions/auto-scroll.ts
|
|
505
522
|
import { StateEffect as StateEffect2 } from "@codemirror/state";
|
|
506
523
|
import { EditorView as EditorView5, ViewPlugin as ViewPlugin6 } from "@codemirror/view";
|
|
507
|
-
import {
|
|
524
|
+
import { addEventListener, combine, throttle } from "@dxos/async";
|
|
508
525
|
import { Domino } from "@dxos/ui";
|
|
526
|
+
import { getSize } from "@dxos/ui-theme";
|
|
509
527
|
|
|
510
|
-
// src/extensions/
|
|
528
|
+
// src/extensions/scroller.ts
|
|
511
529
|
import { StateEffect } from "@codemirror/state";
|
|
512
530
|
import { EditorView as EditorView4, ViewPlugin as ViewPlugin5 } from "@codemirror/view";
|
|
513
|
-
|
|
514
|
-
var
|
|
515
|
-
|
|
531
|
+
import { log as log2 } from "@dxos/log";
|
|
532
|
+
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/ui-editor/src/extensions/scroller.ts";
|
|
533
|
+
var scrollerLineEffect = StateEffect.define();
|
|
534
|
+
var scrollerCrawlEffect = StateEffect.define();
|
|
535
|
+
var scrollToLine = (view, options) => {
|
|
536
|
+
view.dispatch({
|
|
537
|
+
effects: scrollerLineEffect.of(options)
|
|
538
|
+
});
|
|
539
|
+
};
|
|
540
|
+
var scroller = ({ overScroll = 0 } = {}) => {
|
|
541
|
+
const scrollPlugin = ViewPlugin5.fromClass(class ScrollerPlugin {
|
|
516
542
|
view;
|
|
543
|
+
crawler;
|
|
517
544
|
constructor(view) {
|
|
518
545
|
this.view = view;
|
|
546
|
+
this.crawler = createCrawler(this.view);
|
|
519
547
|
}
|
|
520
548
|
// No-op.
|
|
521
549
|
destroy() {
|
|
550
|
+
this.crawler.cancel();
|
|
522
551
|
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
const scroller = this.view.scrollDOM;
|
|
530
|
-
const targetLine = Math.max(0, lineNumber - 1);
|
|
531
|
-
if (behavior === "instant") {
|
|
532
|
-
requestAnimationFrame(() => {
|
|
533
|
-
this.view.dispatch({
|
|
534
|
-
selection: {
|
|
535
|
-
anchor: doc.line(targetLine + 1).from
|
|
536
|
-
},
|
|
537
|
-
scrollIntoView: true
|
|
538
|
-
});
|
|
539
|
-
});
|
|
540
|
-
return;
|
|
541
|
-
}
|
|
542
|
-
if (targetLine >= doc.lines) {
|
|
543
|
-
const targetScrollTop2 = scroller.scrollHeight - scroller.clientHeight + (animOffset || 0);
|
|
544
|
-
this.animateScroll(scroller, targetScrollTop2);
|
|
545
|
-
return;
|
|
546
|
-
}
|
|
547
|
-
const lineStart = doc.line(targetLine + 1).from;
|
|
548
|
-
const coords = this.view.coordsAtPos(lineStart);
|
|
549
|
-
if (!coords) {
|
|
550
|
-
return;
|
|
551
|
-
}
|
|
552
|
-
const currentScrollTop = scroller.scrollTop;
|
|
553
|
-
const scrollerRect = scroller.getBoundingClientRect();
|
|
554
|
-
const maxScrollTop = scroller.scrollHeight - scroller.clientHeight;
|
|
555
|
-
let targetScrollTop;
|
|
556
|
-
if (animPosition === "end") {
|
|
557
|
-
targetScrollTop = currentScrollTop + coords.bottom - scrollerRect.bottom + animOffset;
|
|
552
|
+
cancel() {
|
|
553
|
+
this.crawler.cancel();
|
|
554
|
+
}
|
|
555
|
+
crawl(start = false) {
|
|
556
|
+
if (start) {
|
|
557
|
+
this.crawler.scroll();
|
|
558
558
|
} else {
|
|
559
|
-
|
|
559
|
+
this.crawler.cancel();
|
|
560
560
|
}
|
|
561
|
-
const clampedScrollTop = Math.max(0, Math.min(targetScrollTop, maxScrollTop));
|
|
562
|
-
this.animateScroll(scroller, clampedScrollTop);
|
|
563
561
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
562
|
+
scroll({ line, offset = 0, position, behavior = "instant" }) {
|
|
563
|
+
const { scrollTop, scrollHeight, clientHeight } = this.view.scrollDOM;
|
|
564
|
+
const scrollerRect = this.view.scrollDOM.getBoundingClientRect();
|
|
565
|
+
const doc = this.view.state.doc;
|
|
566
|
+
let targetScrollTop = scrollHeight - clientHeight + offset;
|
|
567
|
+
if (line >= 0 && line <= doc.lines - 1) {
|
|
568
|
+
const lineStart = doc.line(line + 1).from;
|
|
569
|
+
const coords = this.view.coordsAtPos(lineStart);
|
|
570
|
+
if (coords) {
|
|
571
|
+
const currentScrollTop = scrollTop;
|
|
572
|
+
const maxScrollTop = scrollHeight - clientHeight;
|
|
573
|
+
if (position === "end") {
|
|
574
|
+
targetScrollTop = currentScrollTop + coords.bottom - scrollerRect.bottom + offset;
|
|
575
|
+
} else {
|
|
576
|
+
targetScrollTop = currentScrollTop + coords.top - scrollerRect.top + offset;
|
|
577
|
+
}
|
|
578
|
+
targetScrollTop = Math.max(0, Math.min(targetScrollTop, maxScrollTop));
|
|
579
|
+
}
|
|
570
580
|
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
581
|
+
requestAnimationFrame(() => {
|
|
582
|
+
this.view.scrollDOM.scrollTo({
|
|
583
|
+
top: targetScrollTop
|
|
584
|
+
});
|
|
574
585
|
});
|
|
575
586
|
}
|
|
576
587
|
});
|
|
577
588
|
return [
|
|
578
589
|
scrollPlugin,
|
|
579
|
-
//
|
|
590
|
+
// Listen for effect.s
|
|
580
591
|
EditorView4.updateListener.of((update2) => {
|
|
581
592
|
update2.transactions.forEach((transaction) => {
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
const
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
});
|
|
593
|
+
try {
|
|
594
|
+
const plugin = update2.view.plugin(scrollPlugin);
|
|
595
|
+
if (plugin) {
|
|
596
|
+
for (const effect of transaction.effects) {
|
|
597
|
+
if (effect.is(scrollerCrawlEffect)) {
|
|
598
|
+
plugin.crawl(effect.value);
|
|
599
|
+
} else if (effect.is(scrollerLineEffect)) {
|
|
600
|
+
plugin.scroll(effect.value);
|
|
601
|
+
}
|
|
592
602
|
}
|
|
593
603
|
}
|
|
604
|
+
} catch (err) {
|
|
605
|
+
log2.catch(err, void 0, {
|
|
606
|
+
F: __dxlog_file2,
|
|
607
|
+
L: 146,
|
|
608
|
+
S: void 0,
|
|
609
|
+
C: (f, a) => f(...a)
|
|
610
|
+
});
|
|
594
611
|
}
|
|
595
612
|
});
|
|
613
|
+
}),
|
|
614
|
+
// Styles.
|
|
615
|
+
EditorView4.theme({
|
|
616
|
+
".cm-content": {
|
|
617
|
+
paddingBottom: `${overScroll}px`
|
|
618
|
+
},
|
|
619
|
+
".cm-scroller": {
|
|
620
|
+
overflowY: "scroll",
|
|
621
|
+
overflowAnchor: "none",
|
|
622
|
+
paddingBottom: "0"
|
|
623
|
+
},
|
|
624
|
+
".cm-scroller.cm-hide-scrollbar::-webkit-scrollbar": {
|
|
625
|
+
display: "none"
|
|
626
|
+
},
|
|
627
|
+
".cm-scroller::-webkit-scrollbar-thumb": {
|
|
628
|
+
background: "transparent",
|
|
629
|
+
transition: "background 0.15s"
|
|
630
|
+
},
|
|
631
|
+
"&:hover .cm-scroller::-webkit-scrollbar-thumb": {
|
|
632
|
+
background: "var(--color-scrollbar-thumb)"
|
|
633
|
+
},
|
|
634
|
+
".cm-scroll-button": {
|
|
635
|
+
position: "absolute",
|
|
636
|
+
bottom: "0.5rem",
|
|
637
|
+
right: "1rem"
|
|
638
|
+
}
|
|
596
639
|
})
|
|
597
640
|
];
|
|
598
641
|
};
|
|
599
|
-
|
|
600
|
-
view.
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
642
|
+
function createCrawler(view, accel = 0.15, maxVelocity = 1, snapThreshold = 0.5) {
|
|
643
|
+
const el = view.scrollDOM;
|
|
644
|
+
let currentTop = 0;
|
|
645
|
+
let velocity = 0;
|
|
646
|
+
let rafId = null;
|
|
647
|
+
function frame() {
|
|
648
|
+
const targetTop = el.scrollHeight - el.clientHeight;
|
|
649
|
+
const delta = targetTop - currentTop;
|
|
650
|
+
const absDelta = Math.abs(delta);
|
|
651
|
+
if (absDelta < snapThreshold && Math.abs(velocity) < snapThreshold) {
|
|
652
|
+
el.scrollTop = targetTop;
|
|
653
|
+
currentTop = targetTop;
|
|
654
|
+
velocity = 0;
|
|
655
|
+
rafId = null;
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
const stoppingDistance = velocity * velocity / (2 * accel);
|
|
659
|
+
const direction = Math.sign(delta);
|
|
660
|
+
if (velocity !== 0 && (absDelta <= stoppingDistance || direction !== Math.sign(velocity))) {
|
|
661
|
+
velocity -= Math.sign(velocity) * Math.min(accel, Math.abs(velocity));
|
|
662
|
+
} else {
|
|
663
|
+
velocity += direction * accel;
|
|
664
|
+
velocity = Math.sign(velocity) * Math.min(Math.abs(velocity), maxVelocity);
|
|
665
|
+
}
|
|
666
|
+
currentTop += velocity;
|
|
667
|
+
el.scrollTop = currentTop;
|
|
668
|
+
rafId = requestAnimationFrame(frame);
|
|
669
|
+
}
|
|
670
|
+
return {
|
|
671
|
+
scroll: () => {
|
|
672
|
+
if (rafId === null) {
|
|
673
|
+
currentTop = el.scrollTop;
|
|
674
|
+
rafId = requestAnimationFrame(frame);
|
|
675
|
+
}
|
|
676
|
+
},
|
|
677
|
+
cancel: () => {
|
|
678
|
+
if (rafId !== null) {
|
|
679
|
+
cancelAnimationFrame(rafId);
|
|
680
|
+
rafId = null;
|
|
681
|
+
velocity = 0;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
}
|
|
607
686
|
|
|
608
|
-
// src/extensions/
|
|
609
|
-
var
|
|
610
|
-
var autoScroll = (
|
|
687
|
+
// src/extensions/auto-scroll.ts
|
|
688
|
+
var autoScrollEffect = StateEffect2.define();
|
|
689
|
+
var autoScroll = (_ = {}) => {
|
|
611
690
|
let buttonContainer;
|
|
612
|
-
let hideTimeout;
|
|
613
|
-
let lastScrollTop = 0;
|
|
614
691
|
let isPinned = true;
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
clearTimeout(hideTimeout);
|
|
622
|
-
hideTimeout = setTimeout(() => {
|
|
623
|
-
view.scrollDOM.classList.remove("cm-hide-scrollbar");
|
|
624
|
-
}, 1e3);
|
|
625
|
-
};
|
|
626
|
-
const scrollToBottom = (view, behavior) => {
|
|
627
|
-
setPinned(true);
|
|
628
|
-
hideScrollbar(view);
|
|
629
|
-
const line = view.state.doc.lineAt(view.state.doc.length);
|
|
630
|
-
view.dispatch({
|
|
631
|
-
selection: {
|
|
632
|
-
anchor: line.to,
|
|
633
|
-
head: line.to
|
|
634
|
-
},
|
|
635
|
-
effects: scrollToLineEffect.of({
|
|
636
|
-
line: line.number,
|
|
637
|
-
options: {
|
|
638
|
-
position: "end",
|
|
639
|
-
offset: threshold,
|
|
640
|
-
behavior
|
|
641
|
-
}
|
|
642
|
-
})
|
|
643
|
-
});
|
|
692
|
+
let jumpPending = false;
|
|
693
|
+
let enabled = true;
|
|
694
|
+
let firstUpdate = true;
|
|
695
|
+
const setPinned = (pinned) => {
|
|
696
|
+
buttonContainer?.classList.toggle("opacity-0", pinned);
|
|
697
|
+
isPinned = pinned;
|
|
644
698
|
};
|
|
645
|
-
const checkDistance = debounce((view) => {
|
|
646
|
-
const scrollerRect = view.scrollDOM.getBoundingClientRect();
|
|
647
|
-
const coords = view.coordsAtPos(view.state.doc.length);
|
|
648
|
-
const distanceFromBottom = coords ? coords.bottom - scrollerRect.bottom : 0;
|
|
649
|
-
setPinned(distanceFromBottom < 0);
|
|
650
|
-
}, 1e3);
|
|
651
|
-
const triggerUpdate = debounce((view) => scrollToBottom(view), throttleDelay);
|
|
652
699
|
return [
|
|
653
|
-
// Update listener for
|
|
654
|
-
EditorView5.updateListener.of((
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
700
|
+
// Update listener for scrolling when content changes.
|
|
701
|
+
EditorView5.updateListener.of((update2) => {
|
|
702
|
+
const { view, heightChanged, state, startState } = update2;
|
|
703
|
+
for (const tr of update2.transactions) {
|
|
704
|
+
for (const effect of tr.effects) {
|
|
705
|
+
if (effect.is(autoScrollEffect)) {
|
|
706
|
+
enabled = effect.value;
|
|
707
|
+
if (enabled) {
|
|
708
|
+
setPinned(true);
|
|
709
|
+
view.dispatch({
|
|
710
|
+
effects: scrollerCrawlEffect.of(true)
|
|
711
|
+
});
|
|
712
|
+
} else {
|
|
713
|
+
view.dispatch({
|
|
714
|
+
effects: scrollerCrawlEffect.of(false)
|
|
715
|
+
});
|
|
716
|
+
}
|
|
659
717
|
}
|
|
660
718
|
}
|
|
661
|
-
}
|
|
662
|
-
if (
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
719
|
+
}
|
|
720
|
+
if (!enabled) {
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
if (isPinned && (firstUpdate || startState.doc.length === 0) && state.doc.length > 0) {
|
|
724
|
+
firstUpdate = false;
|
|
725
|
+
jumpPending = true;
|
|
726
|
+
requestAnimationFrame(() => {
|
|
727
|
+
view.scrollDOM.scrollTop = view.scrollDOM.scrollHeight;
|
|
728
|
+
jumpPending = false;
|
|
729
|
+
});
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
firstUpdate = false;
|
|
733
|
+
if (jumpPending) {
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
if (heightChanged) {
|
|
737
|
+
if (isPinned) {
|
|
738
|
+
const { scrollTop, scrollHeight, clientHeight } = view.scrollDOM;
|
|
739
|
+
const delta = scrollHeight - scrollTop - clientHeight;
|
|
740
|
+
if (delta > 0) {
|
|
741
|
+
setPinned(true);
|
|
742
|
+
view.dispatch({
|
|
743
|
+
effects: scrollerCrawlEffect.of(true)
|
|
744
|
+
});
|
|
745
|
+
} else if (delta < -1) {
|
|
746
|
+
setPinned(false);
|
|
747
|
+
}
|
|
748
|
+
} else {
|
|
749
|
+
if (state.doc.length === 0) {
|
|
750
|
+
setPinned(true);
|
|
673
751
|
}
|
|
674
|
-
} else if (distanceFromBottom < 0) {
|
|
675
|
-
setPinned(false);
|
|
676
752
|
}
|
|
677
753
|
}
|
|
678
754
|
}),
|
|
679
|
-
// Detect user scroll.
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
755
|
+
// Detect user scroll and unpin (or re-pin if scrolled to the bottom).
|
|
756
|
+
ViewPlugin6.fromClass(class {
|
|
757
|
+
cleanup;
|
|
758
|
+
constructor(view) {
|
|
759
|
+
this.cleanup = createUserScrollDetector(view.scrollDOM, throttle(() => {
|
|
760
|
+
requestAnimationFrame(() => {
|
|
761
|
+
const { scrollTop, scrollHeight, clientHeight } = view.scrollDOM;
|
|
762
|
+
const delta = scrollHeight - scrollTop - clientHeight;
|
|
763
|
+
const pinned = delta === 0;
|
|
764
|
+
setPinned(pinned);
|
|
765
|
+
if (!pinned) {
|
|
766
|
+
view.dispatch({
|
|
767
|
+
effects: scrollerCrawlEffect.of(false)
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
});
|
|
771
|
+
}, 500));
|
|
772
|
+
}
|
|
773
|
+
destroy() {
|
|
774
|
+
this.cleanup();
|
|
690
775
|
}
|
|
691
776
|
}),
|
|
692
777
|
// Scroll button.
|
|
693
778
|
ViewPlugin6.fromClass(class {
|
|
694
779
|
constructor(view) {
|
|
695
|
-
const icon = Domino.of("dx-icon").attributes({
|
|
780
|
+
const icon = Domino.of("dx-icon").classNames(getSize(4)).attributes({
|
|
696
781
|
icon: "ph--arrow-down--regular"
|
|
697
782
|
});
|
|
698
|
-
const button = Domino.of("button").classNames("dx-button bg-
|
|
783
|
+
const button = Domino.of("button").classNames("dx-button bg-accent-surface").attributes({
|
|
699
784
|
"data-density": "fine"
|
|
700
|
-
}).
|
|
701
|
-
|
|
785
|
+
}).append(icon).on("click", () => {
|
|
786
|
+
setPinned(true);
|
|
787
|
+
view.dispatch({
|
|
788
|
+
effects: scrollerLineEffect.of({
|
|
789
|
+
line: -1,
|
|
790
|
+
position: "end",
|
|
791
|
+
behavior: "smooth"
|
|
792
|
+
})
|
|
793
|
+
});
|
|
702
794
|
});
|
|
703
|
-
buttonContainer = Domino.of("div").classNames("cm-scroll-button transition-opacity duration-300 opacity-0").
|
|
795
|
+
buttonContainer = Domino.of("div").classNames("cm-scroll-button transition-opacity duration-300 opacity-0").append(button).root;
|
|
704
796
|
view.scrollDOM.parentElement.appendChild(buttonContainer);
|
|
705
797
|
}
|
|
706
|
-
}),
|
|
707
|
-
// Styles.
|
|
708
|
-
EditorView5.theme({
|
|
709
|
-
".cm-scroller": {
|
|
710
|
-
scrollbarWidth: "thin"
|
|
711
|
-
},
|
|
712
|
-
".cm-scroller.cm-hide-scrollbar": {
|
|
713
|
-
scrollbarWidth: "none"
|
|
714
|
-
},
|
|
715
|
-
".cm-scroller.cm-hide-scrollbar::-webkit-scrollbar": {
|
|
716
|
-
display: "none"
|
|
717
|
-
},
|
|
718
|
-
".cm-scroll-button": {
|
|
719
|
-
position: "absolute",
|
|
720
|
-
bottom: "0.5rem",
|
|
721
|
-
right: "1rem"
|
|
722
|
-
}
|
|
723
798
|
})
|
|
724
799
|
];
|
|
725
800
|
};
|
|
801
|
+
function createUserScrollDetector(element, onUserScroll) {
|
|
802
|
+
return combine(addEventListener(element, "wheel", () => onUserScroll(), {
|
|
803
|
+
passive: true
|
|
804
|
+
}), addEventListener(element, "pointerdown", (event) => {
|
|
805
|
+
if (event.clientX > element.getBoundingClientRect().right - (element.offsetWidth - element.clientWidth)) {
|
|
806
|
+
onUserScroll();
|
|
807
|
+
}
|
|
808
|
+
}));
|
|
809
|
+
}
|
|
726
810
|
|
|
727
811
|
// src/extensions/automerge/automerge.ts
|
|
728
812
|
import { next as A3 } from "@automerge/automerge";
|
|
@@ -736,15 +820,15 @@ var initialSync = Transaction.userEvent.of("initial.sync");
|
|
|
736
820
|
|
|
737
821
|
// src/extensions/automerge/cursor.ts
|
|
738
822
|
import { fromCursor, toCursor } from "@dxos/echo-db";
|
|
739
|
-
import { log as
|
|
740
|
-
var
|
|
823
|
+
import { log as log3 } from "@dxos/log";
|
|
824
|
+
var __dxlog_file3 = "/__w/dxos/dxos/packages/ui/ui-editor/src/extensions/automerge/cursor.ts";
|
|
741
825
|
var cursorConverter = (accessor) => ({
|
|
742
826
|
toCursor: (pos, assoc) => {
|
|
743
827
|
try {
|
|
744
828
|
return toCursor(accessor, pos, assoc);
|
|
745
829
|
} catch (err) {
|
|
746
|
-
|
|
747
|
-
F:
|
|
830
|
+
log3.catch(err, void 0, {
|
|
831
|
+
F: __dxlog_file3,
|
|
748
832
|
L: 15,
|
|
749
833
|
S: void 0,
|
|
750
834
|
C: (f, a) => f(...a)
|
|
@@ -752,12 +836,12 @@ var cursorConverter = (accessor) => ({
|
|
|
752
836
|
return "";
|
|
753
837
|
}
|
|
754
838
|
},
|
|
755
|
-
fromCursor: (
|
|
839
|
+
fromCursor: (cursor) => {
|
|
756
840
|
try {
|
|
757
|
-
return fromCursor(accessor,
|
|
841
|
+
return fromCursor(accessor, cursor);
|
|
758
842
|
} catch (err) {
|
|
759
|
-
|
|
760
|
-
F:
|
|
843
|
+
log3.catch(err, void 0, {
|
|
844
|
+
F: __dxlog_file3,
|
|
761
845
|
L: 24,
|
|
762
846
|
S: void 0,
|
|
763
847
|
C: (f, a) => f(...a)
|
|
@@ -782,7 +866,7 @@ var isReconcile = (tr) => {
|
|
|
782
866
|
|
|
783
867
|
// src/extensions/automerge/sync.ts
|
|
784
868
|
import { next as A2 } from "@automerge/automerge";
|
|
785
|
-
import { log as
|
|
869
|
+
import { log as log4 } from "@dxos/log";
|
|
786
870
|
|
|
787
871
|
// src/extensions/automerge/update-automerge.ts
|
|
788
872
|
import { next as A } from "@automerge/automerge";
|
|
@@ -923,7 +1007,7 @@ var charPath = (textPath, candidatePath) => {
|
|
|
923
1007
|
};
|
|
924
1008
|
|
|
925
1009
|
// src/extensions/automerge/sync.ts
|
|
926
|
-
var
|
|
1010
|
+
var __dxlog_file4 = "/__w/dxos/dxos/packages/ui/ui-editor/src/extensions/automerge/sync.ts";
|
|
927
1011
|
var Syncer = class {
|
|
928
1012
|
_handle;
|
|
929
1013
|
_state;
|
|
@@ -946,8 +1030,8 @@ var Syncer = class {
|
|
|
946
1030
|
this._pending = false;
|
|
947
1031
|
}
|
|
948
1032
|
onEditorChange(view) {
|
|
949
|
-
|
|
950
|
-
F:
|
|
1033
|
+
log4("onEditorChange", void 0, {
|
|
1034
|
+
F: __dxlog_file4,
|
|
951
1035
|
L: 45,
|
|
952
1036
|
S: this,
|
|
953
1037
|
C: (f, a) => f(...a)
|
|
@@ -962,8 +1046,8 @@ var Syncer = class {
|
|
|
962
1046
|
}
|
|
963
1047
|
}
|
|
964
1048
|
onAutomergeChange(view) {
|
|
965
|
-
|
|
966
|
-
F:
|
|
1049
|
+
log4("onAutomergeChange", void 0, {
|
|
1050
|
+
F: __dxlog_file4,
|
|
967
1051
|
L: 60,
|
|
968
1052
|
S: this,
|
|
969
1053
|
C: (f, a) => f(...a)
|
|
@@ -1029,6 +1113,17 @@ var automerge = (accessor) => {
|
|
|
1029
1113
|
const value = DocAccessor.getValue(accessor);
|
|
1030
1114
|
const current = this._view.state.doc.toString();
|
|
1031
1115
|
if (value !== current) {
|
|
1116
|
+
this._view.dispatch({
|
|
1117
|
+
changes: {
|
|
1118
|
+
from: 0,
|
|
1119
|
+
to: this._view.state.doc.length,
|
|
1120
|
+
insert: value
|
|
1121
|
+
},
|
|
1122
|
+
annotations: [
|
|
1123
|
+
initialSync,
|
|
1124
|
+
reconcileAnnotation.of(true)
|
|
1125
|
+
]
|
|
1126
|
+
});
|
|
1032
1127
|
}
|
|
1033
1128
|
});
|
|
1034
1129
|
}
|
|
@@ -1056,7 +1151,7 @@ import { Annotation as Annotation2, RangeSet } from "@codemirror/state";
|
|
|
1056
1151
|
import { Decoration as Decoration5, EditorView as EditorView7, ViewPlugin as ViewPlugin8, WidgetType as WidgetType3 } from "@codemirror/view";
|
|
1057
1152
|
import { Event } from "@dxos/async";
|
|
1058
1153
|
import { Context } from "@dxos/context";
|
|
1059
|
-
var
|
|
1154
|
+
var __dxlog_file5 = "/__w/dxos/dxos/packages/ui/ui-editor/src/extensions/awareness/awareness.ts";
|
|
1060
1155
|
var dummyProvider = {
|
|
1061
1156
|
remoteStateChange: new Event(),
|
|
1062
1157
|
open: () => {
|
|
@@ -1080,7 +1175,7 @@ var awareness = (provider = dummyProvider) => {
|
|
|
1080
1175
|
};
|
|
1081
1176
|
var RemoteSelectionsDecorator = class {
|
|
1082
1177
|
_ctx = new Context(void 0, {
|
|
1083
|
-
F:
|
|
1178
|
+
F: __dxlog_file5,
|
|
1084
1179
|
L: 80
|
|
1085
1180
|
});
|
|
1086
1181
|
_cursorConverter;
|
|
@@ -1293,8 +1388,8 @@ var styles = EditorView7.theme({
|
|
|
1293
1388
|
import { DeferredTask, Event as Event2, sleep } from "@dxos/async";
|
|
1294
1389
|
import { Context as Context2 } from "@dxos/context";
|
|
1295
1390
|
import { invariant } from "@dxos/invariant";
|
|
1296
|
-
import { log as
|
|
1297
|
-
var
|
|
1391
|
+
import { log as log5 } from "@dxos/log";
|
|
1392
|
+
var __dxlog_file6 = "/__w/dxos/dxos/packages/ui/ui-editor/src/extensions/awareness/awareness-provider.ts";
|
|
1298
1393
|
var DEBOUNCE_INTERVAL = 100;
|
|
1299
1394
|
var SpaceAwarenessProvider = class {
|
|
1300
1395
|
_remoteStates = /* @__PURE__ */ new Map();
|
|
@@ -1314,7 +1409,7 @@ var SpaceAwarenessProvider = class {
|
|
|
1314
1409
|
}
|
|
1315
1410
|
open() {
|
|
1316
1411
|
this._ctx = new Context2(void 0, {
|
|
1317
|
-
F:
|
|
1412
|
+
F: __dxlog_file6,
|
|
1318
1413
|
L: 57
|
|
1319
1414
|
});
|
|
1320
1415
|
this._postTask = new DeferredTask(this._ctx, async () => {
|
|
@@ -1341,10 +1436,10 @@ var SpaceAwarenessProvider = class {
|
|
|
1341
1436
|
void this._messenger.postMessage(this._channel, {
|
|
1342
1437
|
kind: "query"
|
|
1343
1438
|
}).catch((err) => {
|
|
1344
|
-
|
|
1439
|
+
log5.debug("failed to query awareness", {
|
|
1345
1440
|
err
|
|
1346
1441
|
}, {
|
|
1347
|
-
F:
|
|
1442
|
+
F: __dxlog_file6,
|
|
1348
1443
|
L: 91,
|
|
1349
1444
|
S: this,
|
|
1350
1445
|
C: (f, a) => f(...a)
|
|
@@ -1361,7 +1456,7 @@ var SpaceAwarenessProvider = class {
|
|
|
1361
1456
|
}
|
|
1362
1457
|
update(position) {
|
|
1363
1458
|
invariant(this._postTask, void 0, {
|
|
1364
|
-
F:
|
|
1459
|
+
F: __dxlog_file6,
|
|
1365
1460
|
L: 106,
|
|
1366
1461
|
S: this,
|
|
1367
1462
|
A: [
|
|
@@ -1378,7 +1473,7 @@ var SpaceAwarenessProvider = class {
|
|
|
1378
1473
|
}
|
|
1379
1474
|
_handleQueryMessage() {
|
|
1380
1475
|
invariant(this._postTask, void 0, {
|
|
1381
|
-
F:
|
|
1476
|
+
F: __dxlog_file6,
|
|
1382
1477
|
L: 117,
|
|
1383
1478
|
S: this,
|
|
1384
1479
|
A: [
|
|
@@ -1390,7 +1485,7 @@ var SpaceAwarenessProvider = class {
|
|
|
1390
1485
|
}
|
|
1391
1486
|
_handlePostMessage(message) {
|
|
1392
1487
|
invariant(message.kind === "post", void 0, {
|
|
1393
|
-
F:
|
|
1488
|
+
F: __dxlog_file6,
|
|
1394
1489
|
L: 122,
|
|
1395
1490
|
S: this,
|
|
1396
1491
|
A: [
|
|
@@ -1406,9 +1501,9 @@ var SpaceAwarenessProvider = class {
|
|
|
1406
1501
|
// src/extensions/blast.ts
|
|
1407
1502
|
import { EditorView as EditorView8, keymap as keymap3 } from "@codemirror/view";
|
|
1408
1503
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
1409
|
-
import { throttle } from "@dxos/async";
|
|
1504
|
+
import { throttle as throttle2 } from "@dxos/async";
|
|
1410
1505
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
1411
|
-
var
|
|
1506
|
+
var __dxlog_file7 = "/__w/dxos/dxos/packages/ui/ui-editor/src/extensions/blast.ts";
|
|
1412
1507
|
var defaultOptions = {
|
|
1413
1508
|
effect: 2,
|
|
1414
1509
|
maxParticles: 200,
|
|
@@ -1527,7 +1622,7 @@ var Blaster = class {
|
|
|
1527
1622
|
}
|
|
1528
1623
|
initialize() {
|
|
1529
1624
|
invariant2(!this._canvas && !this._ctx, void 0, {
|
|
1530
|
-
F:
|
|
1625
|
+
F: __dxlog_file7,
|
|
1531
1626
|
L: 142,
|
|
1532
1627
|
S: this,
|
|
1533
1628
|
A: [
|
|
@@ -1564,7 +1659,7 @@ var Blaster = class {
|
|
|
1564
1659
|
}
|
|
1565
1660
|
start() {
|
|
1566
1661
|
invariant2(this._canvas && this._ctx, void 0, {
|
|
1567
|
-
F:
|
|
1662
|
+
F: __dxlog_file7,
|
|
1568
1663
|
L: 181,
|
|
1569
1664
|
S: this,
|
|
1570
1665
|
A: [
|
|
@@ -1598,11 +1693,11 @@ var Blaster = class {
|
|
|
1598
1693
|
this.drawParticles();
|
|
1599
1694
|
requestAnimationFrame(this.loop.bind(this));
|
|
1600
1695
|
}
|
|
1601
|
-
shake =
|
|
1696
|
+
shake = throttle2(({ time }) => {
|
|
1602
1697
|
this._shakeTime = this._shakeTimeMax || time;
|
|
1603
1698
|
this._shakeTimeMax = time;
|
|
1604
1699
|
}, 100);
|
|
1605
|
-
spawn =
|
|
1700
|
+
spawn = throttle2(({ element, point }) => {
|
|
1606
1701
|
const color = getRGBComponents(element, this._options.color);
|
|
1607
1702
|
const numParticles = random(this._options.particleNumRange.min, this._options.particleNumRange.max);
|
|
1608
1703
|
const dir = this._lastPoint.x === point.x ? 0 : this._lastPoint.x < point.x ? 1 : -1;
|
|
@@ -1776,11 +1871,11 @@ var blocks = () => [
|
|
|
1776
1871
|
".cm-line.block-line": {
|
|
1777
1872
|
paddingLeft: "0.75rem",
|
|
1778
1873
|
paddingRight: "0.75rem",
|
|
1779
|
-
borderLeft: "1px solid var(--
|
|
1780
|
-
borderRight: "1px solid var(--
|
|
1874
|
+
borderLeft: "1px solid var(--color-subdued-separator)",
|
|
1875
|
+
borderRight: "1px solid var(--color-subdued-separator)"
|
|
1781
1876
|
},
|
|
1782
1877
|
".cm-line.block-single": {
|
|
1783
|
-
border: "1px solid var(--
|
|
1878
|
+
border: "1px solid var(--color-subdued-separator)",
|
|
1784
1879
|
borderRadius: "6px",
|
|
1785
1880
|
paddingTop: "0.5rem",
|
|
1786
1881
|
paddingBottom: "0.5rem",
|
|
@@ -1788,7 +1883,7 @@ var blocks = () => [
|
|
|
1788
1883
|
marginBottom: "0.5rem"
|
|
1789
1884
|
},
|
|
1790
1885
|
".cm-line.block-first": {
|
|
1791
|
-
borderTop: "1px solid var(--
|
|
1886
|
+
borderTop: "1px solid var(--color-subdued-separator)",
|
|
1792
1887
|
borderTopLeftRadius: "6px",
|
|
1793
1888
|
borderTopRightRadius: "6px",
|
|
1794
1889
|
paddingTop: "0.5rem",
|
|
@@ -1796,7 +1891,7 @@ var blocks = () => [
|
|
|
1796
1891
|
},
|
|
1797
1892
|
".cm-line.block-middle": {},
|
|
1798
1893
|
".cm-line.block-last": {
|
|
1799
|
-
borderBottom: "1px solid var(--
|
|
1894
|
+
borderBottom: "1px solid var(--color-subdued-separator)",
|
|
1800
1895
|
borderBottomLeftRadius: "6px",
|
|
1801
1896
|
borderBottomRightRadius: "6px",
|
|
1802
1897
|
paddingBottom: "0.5rem",
|
|
@@ -1808,8 +1903,8 @@ var blocks = () => [
|
|
|
1808
1903
|
// src/extensions/bookmarks.ts
|
|
1809
1904
|
import { Prec as Prec3, StateEffect as StateEffect4, StateField as StateField2 } from "@codemirror/state";
|
|
1810
1905
|
import { keymap as keymap4 } from "@codemirror/view";
|
|
1811
|
-
import { log as
|
|
1812
|
-
var
|
|
1906
|
+
import { log as log6 } from "@dxos/log";
|
|
1907
|
+
var __dxlog_file8 = "/__w/dxos/dxos/packages/ui/ui-editor/src/extensions/bookmarks.ts";
|
|
1813
1908
|
var addBookmark = StateEffect4.define();
|
|
1814
1909
|
var removeBookmark = StateEffect4.define();
|
|
1815
1910
|
var clearBookmarks = StateEffect4.define();
|
|
@@ -1821,8 +1916,8 @@ var bookmarks = () => {
|
|
|
1821
1916
|
key: "Mod-ArrowUp",
|
|
1822
1917
|
run: (view) => {
|
|
1823
1918
|
const bookmarks2 = view.state.field(bookmarksField);
|
|
1824
|
-
|
|
1825
|
-
F:
|
|
1919
|
+
log6("up", bookmarks2, {
|
|
1920
|
+
F: __dxlog_file8,
|
|
1826
1921
|
L: 29,
|
|
1827
1922
|
S: void 0,
|
|
1828
1923
|
C: (f, a) => f(...a)
|
|
@@ -1834,8 +1929,8 @@ var bookmarks = () => {
|
|
|
1834
1929
|
key: "Mod-ArrowDown",
|
|
1835
1930
|
run: (view) => {
|
|
1836
1931
|
const bookmarks2 = view.state.field(bookmarksField);
|
|
1837
|
-
|
|
1838
|
-
F:
|
|
1932
|
+
log6("down", bookmarks2, {
|
|
1933
|
+
F: __dxlog_file8,
|
|
1839
1934
|
L: 37,
|
|
1840
1935
|
S: void 0,
|
|
1841
1936
|
C: (f, a) => f(...a)
|
|
@@ -1879,19 +1974,19 @@ import { invertedEffects } from "@codemirror/commands";
|
|
|
1879
1974
|
import { StateEffect as StateEffect5, StateField as StateField3 } from "@codemirror/state";
|
|
1880
1975
|
import { Decoration as Decoration7, EditorView as EditorView11, ViewPlugin as ViewPlugin10, hoverTooltip, keymap as keymap6 } from "@codemirror/view";
|
|
1881
1976
|
import sortBy from "lodash.sortby";
|
|
1882
|
-
import { debounce as
|
|
1883
|
-
import { log as
|
|
1977
|
+
import { debounce as debounce2 } from "@dxos/async";
|
|
1978
|
+
import { log as log7 } from "@dxos/log";
|
|
1884
1979
|
import { isNonNullable } from "@dxos/util";
|
|
1885
1980
|
|
|
1886
1981
|
// src/extensions/selection.ts
|
|
1887
1982
|
import { Transaction as Transaction3 } from "@codemirror/state";
|
|
1888
1983
|
import { EditorView as EditorView10, keymap as keymap5 } from "@codemirror/view";
|
|
1889
|
-
import { debounce
|
|
1984
|
+
import { debounce } from "@dxos/async";
|
|
1890
1985
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
1891
1986
|
import { isTruthy } from "@dxos/util";
|
|
1892
|
-
var
|
|
1987
|
+
var __dxlog_file9 = "/__w/dxos/dxos/packages/ui/ui-editor/src/extensions/selection.ts";
|
|
1893
1988
|
var documentId = singleValueFacet();
|
|
1894
|
-
var stateRestoreAnnotation = "dxos.
|
|
1989
|
+
var stateRestoreAnnotation = "org.dxos.cm.state-restore";
|
|
1895
1990
|
var createEditorStateTransaction = ({ scrollTo, selection }) => {
|
|
1896
1991
|
return {
|
|
1897
1992
|
selection,
|
|
@@ -1905,7 +2000,7 @@ var createEditorStateTransaction = ({ scrollTo, selection }) => {
|
|
|
1905
2000
|
var createEditorStateStore = (keyPrefix) => ({
|
|
1906
2001
|
getState: (id) => {
|
|
1907
2002
|
invariant3(id, void 0, {
|
|
1908
|
-
F:
|
|
2003
|
+
F: __dxlog_file9,
|
|
1909
2004
|
L: 47,
|
|
1910
2005
|
S: void 0,
|
|
1911
2006
|
A: [
|
|
@@ -1918,7 +2013,7 @@ var createEditorStateStore = (keyPrefix) => ({
|
|
|
1918
2013
|
},
|
|
1919
2014
|
setState: (id, state) => {
|
|
1920
2015
|
invariant3(id, void 0, {
|
|
1921
|
-
F:
|
|
2016
|
+
F: __dxlog_file9,
|
|
1922
2017
|
L: 53,
|
|
1923
2018
|
S: void 0,
|
|
1924
2019
|
A: [
|
|
@@ -1930,7 +2025,7 @@ var createEditorStateStore = (keyPrefix) => ({
|
|
|
1930
2025
|
}
|
|
1931
2026
|
});
|
|
1932
2027
|
var selectionState = ({ getState, setState } = {}) => {
|
|
1933
|
-
const setStateDebounced =
|
|
2028
|
+
const setStateDebounced = debounce(setState, 1e3);
|
|
1934
2029
|
return [
|
|
1935
2030
|
// TODO(burdon): Track scrolling (currently only updates when cursor moves).
|
|
1936
2031
|
// EditorView.domEventHandlers({
|
|
@@ -1977,7 +2072,7 @@ var selectionState = ({ getState, setState } = {}) => {
|
|
|
1977
2072
|
};
|
|
1978
2073
|
|
|
1979
2074
|
// src/extensions/comments.ts
|
|
1980
|
-
var
|
|
2075
|
+
var __dxlog_file10 = "/__w/dxos/dxos/packages/ui/ui-editor/src/extensions/comments.ts";
|
|
1981
2076
|
var setComments = StateEffect5.define();
|
|
1982
2077
|
var setSelection = StateEffect5.define();
|
|
1983
2078
|
var setCommentState = StateEffect5.define();
|
|
@@ -2022,14 +2117,14 @@ var commentsState = StateField3.define({
|
|
|
2022
2117
|
var styles2 = EditorView11.theme({
|
|
2023
2118
|
".cm-comment, .cm-comment-current": {
|
|
2024
2119
|
padding: "3px 0",
|
|
2025
|
-
color: "var(--
|
|
2026
|
-
backgroundColor: "var(--
|
|
2120
|
+
color: "var(--color-cm-comment-text)",
|
|
2121
|
+
backgroundColor: "var(--color-cm-comment-surface)"
|
|
2027
2122
|
},
|
|
2028
2123
|
".cm-comment > span, .cm-comment-current > span": {
|
|
2029
2124
|
boxDecorationBreak: "clone",
|
|
2030
|
-
boxShadow: "0 0 1px 3px var(--
|
|
2031
|
-
backgroundColor: "var(--
|
|
2032
|
-
color: "var(--
|
|
2125
|
+
boxShadow: "0 0 1px 3px var(--color-cm-comment-surface)",
|
|
2126
|
+
backgroundColor: "var(--color-cm-comment-surface)",
|
|
2127
|
+
color: "var(--color-cm-comment-text)",
|
|
2033
2128
|
cursor: "pointer"
|
|
2034
2129
|
}
|
|
2035
2130
|
});
|
|
@@ -2047,9 +2142,9 @@ var commentsDecorations = EditorView11.decorations.compute([
|
|
|
2047
2142
|
const decorations2 = sortBy(comments2 ?? [], (range) => range.range.from)?.flatMap((comment) => {
|
|
2048
2143
|
const range = comment.range;
|
|
2049
2144
|
if (!range) {
|
|
2050
|
-
|
|
2051
|
-
F:
|
|
2052
|
-
L:
|
|
2145
|
+
log7.warn("Invalid range:", range, {
|
|
2146
|
+
F: __dxlog_file10,
|
|
2147
|
+
L: 139,
|
|
2053
2148
|
S: void 0,
|
|
2054
2149
|
C: (f, a) => f(...a)
|
|
2055
2150
|
});
|
|
@@ -2165,10 +2260,10 @@ var trackPastedComments = (onUpdate) => {
|
|
|
2165
2260
|
const { comments: comments2 } = update2.startState.field(commentsState);
|
|
2166
2261
|
const exists = comments2.some((c) => c.comment.id === comment.id && c.range.from < c.range.to);
|
|
2167
2262
|
if (!exists) {
|
|
2168
|
-
const
|
|
2263
|
+
const cursor = Cursor.getCursorFromRange(update2.state, comment);
|
|
2169
2264
|
onUpdate({
|
|
2170
2265
|
id: comment.id,
|
|
2171
|
-
cursor
|
|
2266
|
+
cursor
|
|
2172
2267
|
});
|
|
2173
2268
|
}
|
|
2174
2269
|
}
|
|
@@ -2197,13 +2292,13 @@ var createComment = (view) => {
|
|
|
2197
2292
|
}
|
|
2198
2293
|
});
|
|
2199
2294
|
}
|
|
2200
|
-
const
|
|
2295
|
+
const cursor = Cursor.getCursorFromRange(view.state, {
|
|
2201
2296
|
from,
|
|
2202
2297
|
to
|
|
2203
2298
|
});
|
|
2204
|
-
if (
|
|
2299
|
+
if (cursor) {
|
|
2205
2300
|
options.onCreate?.({
|
|
2206
|
-
cursor
|
|
2301
|
+
cursor,
|
|
2207
2302
|
from,
|
|
2208
2303
|
location: view.coordsAtPos(from)
|
|
2209
2304
|
});
|
|
@@ -2214,7 +2309,7 @@ var createComment = (view) => {
|
|
|
2214
2309
|
var optionsFacet = singleValueFacet();
|
|
2215
2310
|
var comments = (options = {}) => {
|
|
2216
2311
|
const { key: shortcut = "meta-'" } = options;
|
|
2217
|
-
const handleSelect =
|
|
2312
|
+
const handleSelect = debounce2((state) => options.onSelect?.(state), 200);
|
|
2218
2313
|
return [
|
|
2219
2314
|
optionsFacet.of(options),
|
|
2220
2315
|
options.id ? documentId.of(options.id) : void 0,
|
|
@@ -2392,9 +2487,9 @@ var createExternalCommentSync = (id, subscribe, getComments) => ViewPlugin10.fro
|
|
|
2392
2487
|
// src/extensions/debug.ts
|
|
2393
2488
|
import { syntaxTree } from "@codemirror/language";
|
|
2394
2489
|
import { StateField as StateField4 } from "@codemirror/state";
|
|
2395
|
-
var debugNodeLogger = (
|
|
2490
|
+
var debugNodeLogger = (log12 = console.log) => {
|
|
2396
2491
|
const logTokens = (state) => syntaxTree(state).iterate({
|
|
2397
|
-
enter: (node) =>
|
|
2492
|
+
enter: (node) => log12(node.type)
|
|
2398
2493
|
});
|
|
2399
2494
|
return StateField4.define({
|
|
2400
2495
|
create: (state) => logTokens(state),
|
|
@@ -2429,8 +2524,8 @@ var dropFile = (options = {}) => {
|
|
|
2429
2524
|
};
|
|
2430
2525
|
var styles3 = EditorView12.theme({
|
|
2431
2526
|
".cm-dropCursor": {
|
|
2432
|
-
borderLeft: "2px solid var(--
|
|
2433
|
-
color: "var(--
|
|
2527
|
+
borderLeft: "2px solid var(--color-accent-text)",
|
|
2528
|
+
color: "var(--color-accent-text)",
|
|
2434
2529
|
padding: "0 4px"
|
|
2435
2530
|
},
|
|
2436
2531
|
".cm-dropCursor:after": {
|
|
@@ -2444,47 +2539,66 @@ import { defaultKeymap, history, historyKeymap, indentWithTab, standardKeymap }
|
|
|
2444
2539
|
import { HighlightStyle, bracketMatching, syntaxHighlighting } from "@codemirror/language";
|
|
2445
2540
|
import { searchKeymap } from "@codemirror/search";
|
|
2446
2541
|
import { EditorState } from "@codemirror/state";
|
|
2447
|
-
import { EditorView as
|
|
2542
|
+
import { EditorView as EditorView16, ViewPlugin as ViewPlugin12, drawSelection, dropCursor as dropCursor2, highlightActiveLine, keymap as keymap7, lineNumbers, placeholder as placeholder2 } from "@codemirror/view";
|
|
2448
2543
|
import { vscodeDarkStyle, vscodeLightStyle } from "@uiw/codemirror-theme-vscode";
|
|
2449
2544
|
import defaultsDeep2 from "lodash.defaultsdeep";
|
|
2450
2545
|
import { generateName } from "@dxos/display-name";
|
|
2451
|
-
import { log as
|
|
2546
|
+
import { log as log8 } from "@dxos/log";
|
|
2452
2547
|
import { hexToHue, isTruthy as isTruthy2 } from "@dxos/util";
|
|
2453
2548
|
|
|
2454
|
-
// src/styles/
|
|
2549
|
+
// src/styles/theme.ts
|
|
2550
|
+
import { EditorView as EditorView13 } from "@codemirror/view";
|
|
2455
2551
|
import { mx as mx3 } from "@dxos/ui-theme";
|
|
2456
2552
|
var headings = {
|
|
2457
|
-
1:
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2553
|
+
1: {
|
|
2554
|
+
className: "text-3xl",
|
|
2555
|
+
fontSize: "var(--text-3xl)",
|
|
2556
|
+
lineHeight: "var(--text-4xl--line-height)"
|
|
2557
|
+
},
|
|
2558
|
+
2: {
|
|
2559
|
+
className: "text-2xl",
|
|
2560
|
+
fontSize: "var(--text-2xl)",
|
|
2561
|
+
lineHeight: "var(--text-3xl--line-height)"
|
|
2562
|
+
},
|
|
2563
|
+
3: {
|
|
2564
|
+
className: "text-xl",
|
|
2565
|
+
fontSize: "var(--text-xl)",
|
|
2566
|
+
lineHeight: "var(--text-2xl--line-height)"
|
|
2567
|
+
},
|
|
2568
|
+
4: {
|
|
2569
|
+
className: "text-lg",
|
|
2570
|
+
fontSize: "var(--text-lg)",
|
|
2571
|
+
lineHeight: "var(--text-xl--line-height)"
|
|
2572
|
+
},
|
|
2573
|
+
5: {
|
|
2574
|
+
className: "text-base",
|
|
2575
|
+
fontSize: "var(--text-base)",
|
|
2576
|
+
lineHeight: "var(--text-lg--line-height)"
|
|
2577
|
+
},
|
|
2578
|
+
6: {
|
|
2579
|
+
className: "text-base",
|
|
2580
|
+
fontSize: "var(--text-base)",
|
|
2581
|
+
lineHeight: "var(--text-base--line-height)"
|
|
2582
|
+
}
|
|
2463
2583
|
};
|
|
2584
|
+
var fontBody = '"Inter Variable", ui-sans-serif, system-ui, sans-serif';
|
|
2585
|
+
var fontMono = '"JetBrains Mono Variable", ui-monospace, "Cascadia Code", "Source Code Pro", monospace';
|
|
2464
2586
|
var markdownTheme = {
|
|
2465
|
-
code: "font-mono
|
|
2466
|
-
codeMark: "font-mono
|
|
2467
|
-
mark: "
|
|
2468
|
-
heading: (level) => {
|
|
2469
|
-
|
|
2470
|
-
|
|
2587
|
+
code: "font-mono! cm-code-inline",
|
|
2588
|
+
codeMark: "font-mono! cm-code-mark",
|
|
2589
|
+
mark: "font-mono!",
|
|
2590
|
+
heading: (level) => ({
|
|
2591
|
+
className: mx3(headings[level].className, "font-light text-(--color-cm-heading-number)"),
|
|
2592
|
+
color: "var(--color-cm-heading) !important",
|
|
2593
|
+
lineHeight: headings[level].lineHeight,
|
|
2594
|
+
fontSize: headings[level].fontSize,
|
|
2595
|
+
fontWeight: "100 !important"
|
|
2596
|
+
})
|
|
2471
2597
|
};
|
|
2472
|
-
|
|
2473
|
-
// src/styles/theme.ts
|
|
2474
|
-
import { EditorView as EditorView13 } from "@codemirror/view";
|
|
2475
|
-
|
|
2476
|
-
// src/styles/tokens.ts
|
|
2477
|
-
import { tokens } from "@dxos/ui-theme";
|
|
2478
|
-
import { get } from "@dxos/util";
|
|
2479
|
-
var getToken = (path, defaultValue) => {
|
|
2480
|
-
const value = get(tokens, path, defaultValue);
|
|
2481
|
-
return value?.toString() ?? "";
|
|
2482
|
-
};
|
|
2483
|
-
var fontBody = getToken("fontFamily.body");
|
|
2484
|
-
var fontMono = getToken("fontFamily.mono");
|
|
2485
|
-
|
|
2486
|
-
// src/styles/theme.ts
|
|
2487
2598
|
var baseTheme = EditorView13.baseTheme({
|
|
2599
|
+
/**
|
|
2600
|
+
* Outer frame.
|
|
2601
|
+
*/
|
|
2488
2602
|
"&": {},
|
|
2489
2603
|
"&.cm-focused": {
|
|
2490
2604
|
outline: "none"
|
|
@@ -2493,7 +2607,18 @@ var baseTheme = EditorView13.baseTheme({
|
|
|
2493
2607
|
* Scroller
|
|
2494
2608
|
*/
|
|
2495
2609
|
".cm-scroller": {
|
|
2496
|
-
|
|
2610
|
+
overflowAnchor: "none"
|
|
2611
|
+
},
|
|
2612
|
+
".cm-scroller::-webkit-scrollbar": {
|
|
2613
|
+
width: "8px"
|
|
2614
|
+
},
|
|
2615
|
+
".cm-scroller::-webkit-scrollbar-track": {},
|
|
2616
|
+
".cm-scroller::-webkit-scrollbar-thumb": {
|
|
2617
|
+
background: "transparent",
|
|
2618
|
+
transition: "background 0.15s"
|
|
2619
|
+
},
|
|
2620
|
+
"&:hover .cm-scroller::-webkit-scrollbar-thumb": {
|
|
2621
|
+
background: "var(--color-scrollbar-thumb)"
|
|
2497
2622
|
},
|
|
2498
2623
|
/**
|
|
2499
2624
|
* Content
|
|
@@ -2501,7 +2626,6 @@ var baseTheme = EditorView13.baseTheme({
|
|
|
2501
2626
|
*/
|
|
2502
2627
|
".cm-content": {
|
|
2503
2628
|
padding: "unset",
|
|
2504
|
-
lineHeight: "24px",
|
|
2505
2629
|
color: "unset"
|
|
2506
2630
|
},
|
|
2507
2631
|
/**
|
|
@@ -2515,8 +2639,8 @@ var baseTheme = EditorView13.baseTheme({
|
|
|
2515
2639
|
".cm-gutter": {},
|
|
2516
2640
|
".cm-gutter.cm-lineNumbers": {
|
|
2517
2641
|
paddingRight: "4px",
|
|
2518
|
-
borderRight: "1px solid var(--
|
|
2519
|
-
color: "var(--
|
|
2642
|
+
borderRight: "1px solid var(--color-subdued-separator)",
|
|
2643
|
+
color: "var(--color-subdued)"
|
|
2520
2644
|
},
|
|
2521
2645
|
".cm-gutter.cm-lineNumbers .cm-gutterElement": {
|
|
2522
2646
|
minWidth: "40px"
|
|
@@ -2525,36 +2649,43 @@ var baseTheme = EditorView13.baseTheme({
|
|
|
2525
2649
|
* Height is set to match the corresponding line (which may have wrapped).
|
|
2526
2650
|
*/
|
|
2527
2651
|
".cm-gutterElement": {
|
|
2528
|
-
lineHeight:
|
|
2652
|
+
lineHeight: 1.5,
|
|
2529
2653
|
fontSize: "12px"
|
|
2530
2654
|
},
|
|
2531
2655
|
/**
|
|
2532
2656
|
* Line.
|
|
2533
2657
|
*/
|
|
2534
2658
|
".cm-line": {
|
|
2535
|
-
lineHeight:
|
|
2659
|
+
lineHeight: 1.5,
|
|
2536
2660
|
paddingInline: 0
|
|
2537
2661
|
},
|
|
2662
|
+
/**
|
|
2663
|
+
* Force all inline children to inherit line-height to prevent monospace font metrics
|
|
2664
|
+
* (JetBrains Mono ascent/descent) from inflating the line box beyond 24px.
|
|
2665
|
+
*/
|
|
2666
|
+
".cm-line *": {
|
|
2667
|
+
lineHeight: "inherit"
|
|
2668
|
+
},
|
|
2538
2669
|
".cm-activeLine": {
|
|
2539
|
-
background: "var(--
|
|
2670
|
+
background: "var(--color-cm-active-line)"
|
|
2540
2671
|
},
|
|
2541
2672
|
/**
|
|
2542
2673
|
* Cursor (layer).
|
|
2543
2674
|
*/
|
|
2544
2675
|
".cm-cursor, .cm-dropCursor": {
|
|
2545
|
-
borderLeft: "2px solid var(--
|
|
2676
|
+
borderLeft: "2px solid var(--color-cm-cursor)"
|
|
2546
2677
|
},
|
|
2547
2678
|
".cm-placeholder": {
|
|
2548
|
-
color: "var(--
|
|
2679
|
+
color: "var(--color-placeholder)"
|
|
2549
2680
|
},
|
|
2550
2681
|
/**
|
|
2551
2682
|
* Selection (layer).
|
|
2552
2683
|
*/
|
|
2553
2684
|
".cm-selectionBackground": {
|
|
2554
|
-
background: "var(--
|
|
2685
|
+
background: "var(--color-cm-selection)"
|
|
2555
2686
|
},
|
|
2556
2687
|
"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground": {
|
|
2557
|
-
background: "var(--
|
|
2688
|
+
background: "var(--color-cm-focused-selection)"
|
|
2558
2689
|
},
|
|
2559
2690
|
/**
|
|
2560
2691
|
* Search.
|
|
@@ -2564,8 +2695,8 @@ var baseTheme = EditorView13.baseTheme({
|
|
|
2564
2695
|
margin: "0 -3px",
|
|
2565
2696
|
padding: "3px",
|
|
2566
2697
|
borderRadius: "3px",
|
|
2567
|
-
background: "var(--
|
|
2568
|
-
color: "var(--
|
|
2698
|
+
background: "var(--color-cm-highlight-surface)",
|
|
2699
|
+
color: "var(--color-cm-highlight)"
|
|
2569
2700
|
},
|
|
2570
2701
|
".cm-searchMatch-selected": {
|
|
2571
2702
|
textDecoration: "underline"
|
|
@@ -2576,20 +2707,29 @@ var baseTheme = EditorView13.baseTheme({
|
|
|
2576
2707
|
".cm-link": {
|
|
2577
2708
|
textDecorationLine: "underline",
|
|
2578
2709
|
textDecorationThickness: "1px",
|
|
2579
|
-
textDecorationColor: "var(--
|
|
2710
|
+
textDecorationColor: "var(--color-separator)",
|
|
2580
2711
|
textUnderlineOffset: "2px",
|
|
2581
2712
|
borderRadius: ".125rem"
|
|
2582
2713
|
},
|
|
2583
2714
|
".cm-link > span": {
|
|
2584
|
-
color: "var(--
|
|
2715
|
+
color: "var(--color-accent-text)"
|
|
2716
|
+
},
|
|
2717
|
+
".cm-link > span:hover": {
|
|
2718
|
+
color: "var(--color-accent-text-hover)"
|
|
2585
2719
|
},
|
|
2586
2720
|
/**
|
|
2587
2721
|
* Tooltip.
|
|
2588
2722
|
*/
|
|
2589
2723
|
".cm-tooltip": {
|
|
2590
|
-
background: "var(--
|
|
2724
|
+
background: "var(--color-modal-surface)"
|
|
2591
2725
|
},
|
|
2592
2726
|
".cm-tooltip-below": {},
|
|
2727
|
+
".cm-tooltip-hover": {
|
|
2728
|
+
background: "var(--color-modal-surface)",
|
|
2729
|
+
border: "1px solid var(--color-separator)",
|
|
2730
|
+
borderRadius: "4px",
|
|
2731
|
+
overflow: "hidden"
|
|
2732
|
+
},
|
|
2593
2733
|
/**
|
|
2594
2734
|
* Autocomplete.
|
|
2595
2735
|
* https://github.com/codemirror/autocomplete/blob/main/src/completion.ts
|
|
@@ -2597,7 +2737,7 @@ var baseTheme = EditorView13.baseTheme({
|
|
|
2597
2737
|
".cm-tooltip.cm-tooltip-autocomplete": {
|
|
2598
2738
|
marginTop: "6px",
|
|
2599
2739
|
marginLeft: "-10px",
|
|
2600
|
-
border: "2px solid var(--
|
|
2740
|
+
border: "2px solid var(--color-separator)",
|
|
2601
2741
|
borderRadius: "4px"
|
|
2602
2742
|
},
|
|
2603
2743
|
".cm-tooltip.cm-tooltip-autocomplete > ul": {
|
|
@@ -2607,12 +2747,12 @@ var baseTheme = EditorView13.baseTheme({
|
|
|
2607
2747
|
padding: "4px"
|
|
2608
2748
|
},
|
|
2609
2749
|
".cm-tooltip.cm-tooltip-autocomplete > ul > li[aria-selected]": {
|
|
2610
|
-
background: "var(--
|
|
2611
|
-
color: "var(--
|
|
2750
|
+
background: "var(--color-active-surface)",
|
|
2751
|
+
color: "var(--color-base-surface-text)"
|
|
2612
2752
|
},
|
|
2613
2753
|
".cm-tooltip.cm-tooltip-autocomplete > ul > completion-section": {
|
|
2614
2754
|
paddingLeft: "4px !important",
|
|
2615
|
-
color: "var(--
|
|
2755
|
+
color: "var(--color-base-surface-text)"
|
|
2616
2756
|
},
|
|
2617
2757
|
/**
|
|
2618
2758
|
* Completion info.
|
|
@@ -2621,17 +2761,17 @@ var baseTheme = EditorView13.baseTheme({
|
|
|
2621
2761
|
width: "360px !important",
|
|
2622
2762
|
margin: "-10px 1px 0 1px",
|
|
2623
2763
|
padding: "8px !important",
|
|
2624
|
-
borderColor: "var(--
|
|
2764
|
+
borderColor: "var(--color-separator)"
|
|
2625
2765
|
},
|
|
2626
2766
|
".cm-completionIcon": {
|
|
2627
2767
|
display: "none"
|
|
2628
2768
|
},
|
|
2629
2769
|
".cm-completionLabel": {
|
|
2630
|
-
color: "var(--
|
|
2770
|
+
color: "var(--color-description)",
|
|
2631
2771
|
padding: "0 4px"
|
|
2632
2772
|
},
|
|
2633
2773
|
".cm-completionMatchedText": {
|
|
2634
|
-
color: "var(--
|
|
2774
|
+
color: "var(--color-base-surface-text)",
|
|
2635
2775
|
textDecoration: "none !important"
|
|
2636
2776
|
},
|
|
2637
2777
|
/**
|
|
@@ -2655,7 +2795,7 @@ var baseTheme = EditorView13.baseTheme({
|
|
|
2655
2795
|
backgroundColor: "var(--surface-bg)"
|
|
2656
2796
|
},
|
|
2657
2797
|
".cm-panel input, .cm-panel button, .cm-panel label": {
|
|
2658
|
-
color: "var(--
|
|
2798
|
+
color: "var(--color-subdued)",
|
|
2659
2799
|
fontSize: "14px",
|
|
2660
2800
|
all: "unset",
|
|
2661
2801
|
margin: "3px !important",
|
|
@@ -2663,10 +2803,10 @@ var baseTheme = EditorView13.baseTheme({
|
|
|
2663
2803
|
outline: "1px solid transparent"
|
|
2664
2804
|
},
|
|
2665
2805
|
".cm-panel input, .cm-panel button": {
|
|
2666
|
-
backgroundColor: "var(--
|
|
2806
|
+
backgroundColor: "var(--color-input-surface)"
|
|
2667
2807
|
},
|
|
2668
2808
|
".cm-panel input:focus, .cm-panel button:focus": {
|
|
2669
|
-
outline: "1px solid var(--
|
|
2809
|
+
outline: "1px solid var(--color-neutral-focus-indicator)"
|
|
2670
2810
|
},
|
|
2671
2811
|
".cm-panel label": {
|
|
2672
2812
|
display: "inline-flex",
|
|
@@ -2679,33 +2819,33 @@ var baseTheme = EditorView13.baseTheme({
|
|
|
2679
2819
|
height: "8px",
|
|
2680
2820
|
marginRight: "6px !important",
|
|
2681
2821
|
padding: "2px !important",
|
|
2682
|
-
color: "var(--
|
|
2822
|
+
color: "var(--color-neutral-focus-indicator)"
|
|
2683
2823
|
},
|
|
2684
2824
|
".cm-panel button": {
|
|
2685
2825
|
"&:hover": {
|
|
2686
|
-
|
|
2826
|
+
// TODO(burdon): Replace with layer and @apply bg-accent-surface-hover
|
|
2827
|
+
backgroundColor: "var(--color-accent-surface-hover) !important"
|
|
2687
2828
|
},
|
|
2688
2829
|
"&:active": {
|
|
2689
|
-
backgroundColor: "var(--
|
|
2830
|
+
backgroundColor: "var(--color-accent-surface-hover)"
|
|
2690
2831
|
}
|
|
2691
2832
|
},
|
|
2692
2833
|
".cm-panel.cm-search": {
|
|
2693
2834
|
padding: "4px",
|
|
2694
|
-
borderTop: "1px solid var(--
|
|
2835
|
+
borderTop: "1px solid var(--color-separator)"
|
|
2695
2836
|
}
|
|
2696
2837
|
});
|
|
2697
2838
|
var editorGutter = EditorView13.theme({
|
|
2698
2839
|
".cm-gutters": {
|
|
2699
2840
|
// NOTE: Non-transparent background required to cover content if scrolling horizontally.
|
|
2700
|
-
background: "var(--
|
|
2841
|
+
background: "var(--color-base-surface) !important",
|
|
2701
2842
|
paddingRight: "1rem"
|
|
2702
2843
|
}
|
|
2703
2844
|
});
|
|
2704
2845
|
var createFontTheme = ({ monospace } = {}) => EditorView13.theme({
|
|
2705
|
-
//
|
|
2846
|
+
// Main content.
|
|
2706
2847
|
".cm-scroller": {
|
|
2707
|
-
fontFamily: monospace ? fontMono : fontBody
|
|
2708
|
-
fontSize: "16px"
|
|
2848
|
+
fontFamily: monospace ? fontMono : fontBody
|
|
2709
2849
|
},
|
|
2710
2850
|
// Maintain defaults for UI components.
|
|
2711
2851
|
".cm-content, .cm-gutters, .cm-panel": {
|
|
@@ -2745,9 +2885,32 @@ var focus = [
|
|
|
2745
2885
|
})
|
|
2746
2886
|
];
|
|
2747
2887
|
|
|
2888
|
+
// src/extensions/scroll-past-end.ts
|
|
2889
|
+
import { EditorView as EditorView15, ViewPlugin as ViewPlugin11 } from "@codemirror/view";
|
|
2890
|
+
var scrollPastEndPlugin = ViewPlugin11.fromClass(class {
|
|
2891
|
+
height = 1e3;
|
|
2892
|
+
attrs = {
|
|
2893
|
+
style: "padding-bottom: 1000px"
|
|
2894
|
+
};
|
|
2895
|
+
update({ view }) {
|
|
2896
|
+
const lastLineBlock = view.lineBlockAt(view.state.doc.length);
|
|
2897
|
+
const height = view.dom.clientHeight - lastLineBlock.height - view.documentPadding.top - 0.5;
|
|
2898
|
+
if (height >= 0 && height !== this.height) {
|
|
2899
|
+
this.height = height;
|
|
2900
|
+
this.attrs = {
|
|
2901
|
+
style: `padding-bottom: ${height}px`
|
|
2902
|
+
};
|
|
2903
|
+
}
|
|
2904
|
+
}
|
|
2905
|
+
});
|
|
2906
|
+
var scrollPastEnd = () => [
|
|
2907
|
+
scrollPastEndPlugin,
|
|
2908
|
+
EditorView15.contentAttributes.of((view) => view.plugin(scrollPastEndPlugin)?.attrs ?? null)
|
|
2909
|
+
];
|
|
2910
|
+
|
|
2748
2911
|
// src/extensions/factories.ts
|
|
2749
|
-
var
|
|
2750
|
-
var tabbable =
|
|
2912
|
+
var __dxlog_file11 = "/__w/dxos/dxos/packages/ui/ui-editor/src/extensions/factories.ts";
|
|
2913
|
+
var tabbable = EditorView16.contentAttributes.of({
|
|
2751
2914
|
tabindex: "0"
|
|
2752
2915
|
});
|
|
2753
2916
|
var filterChars = (chars) => {
|
|
@@ -2800,10 +2963,10 @@ var createBasicExtensions = (propsProp) => {
|
|
|
2800
2963
|
const props = defaultsDeep2({}, propsProp, defaultBasicOptions);
|
|
2801
2964
|
return [
|
|
2802
2965
|
// NOTE: Doesn't catch errors in keymap functions.
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
F:
|
|
2806
|
-
L:
|
|
2966
|
+
EditorView16.exceptionSink.of((err) => {
|
|
2967
|
+
log8.catch(err, void 0, {
|
|
2968
|
+
F: __dxlog_file11,
|
|
2969
|
+
L: 130,
|
|
2807
2970
|
S: void 0,
|
|
2808
2971
|
C: (f, a) => f(...a)
|
|
2809
2972
|
});
|
|
@@ -2815,7 +2978,7 @@ var createBasicExtensions = (propsProp) => {
|
|
|
2815
2978
|
props.drawSelection && drawSelection({
|
|
2816
2979
|
cursorBlinkRate: 1200
|
|
2817
2980
|
}),
|
|
2818
|
-
props.editable !== void 0 &&
|
|
2981
|
+
props.editable !== void 0 && EditorView16.editable.of(props.editable),
|
|
2819
2982
|
props.focus && focus,
|
|
2820
2983
|
props.highlightActiveLine && highlightActiveLine(),
|
|
2821
2984
|
props.history && history(),
|
|
@@ -2823,7 +2986,7 @@ var createBasicExtensions = (propsProp) => {
|
|
|
2823
2986
|
lineNumbers(),
|
|
2824
2987
|
editorGutter
|
|
2825
2988
|
],
|
|
2826
|
-
props.lineWrapping &&
|
|
2989
|
+
props.lineWrapping && EditorView16.lineWrapping,
|
|
2827
2990
|
props.placeholder && placeholder2(props.placeholder),
|
|
2828
2991
|
props.readOnly !== void 0 && EditorState.readOnly.of(props.readOnly),
|
|
2829
2992
|
props.scrollPastEnd && scrollPastEnd(),
|
|
@@ -2855,12 +3018,12 @@ var createBasicExtensions = (propsProp) => {
|
|
|
2855
3018
|
};
|
|
2856
3019
|
var grow = {
|
|
2857
3020
|
editor: {
|
|
2858
|
-
className: "
|
|
3021
|
+
className: "h-full w-full"
|
|
2859
3022
|
}
|
|
2860
3023
|
};
|
|
2861
3024
|
var fullWidth = {
|
|
2862
3025
|
editor: {
|
|
2863
|
-
className: "
|
|
3026
|
+
className: "w-full"
|
|
2864
3027
|
}
|
|
2865
3028
|
};
|
|
2866
3029
|
var defaultThemeSlots = grow;
|
|
@@ -2872,20 +3035,22 @@ var createThemeExtensions = ({ monospace, themeMode, slots: slotsProp, syntaxHig
|
|
|
2872
3035
|
const slots = defaultsDeep2({}, slotsProp, defaultThemeSlots);
|
|
2873
3036
|
return [
|
|
2874
3037
|
baseTheme,
|
|
2875
|
-
|
|
3038
|
+
EditorView16.darkTheme.of(themeMode === "dark"),
|
|
2876
3039
|
createFontTheme({
|
|
2877
3040
|
monospace
|
|
2878
3041
|
}),
|
|
2879
3042
|
syntaxHighlightingProp && syntaxHighlighting(HighlightStyle.define(themeMode === "dark" ? defaultStyles.dark : defaultStyles.light)),
|
|
2880
|
-
slots.editor?.className &&
|
|
3043
|
+
slots.editor?.className && EditorView16.editorAttributes.of({
|
|
2881
3044
|
class: slots.editor.className
|
|
2882
3045
|
}),
|
|
2883
|
-
slots.content?.className &&
|
|
3046
|
+
slots.content?.className && EditorView16.contentAttributes.of({
|
|
2884
3047
|
class: slots.content.className
|
|
2885
3048
|
}),
|
|
2886
|
-
slots.
|
|
3049
|
+
slots.scroller?.className && ViewPlugin12.fromClass(class {
|
|
2887
3050
|
constructor(view) {
|
|
2888
|
-
|
|
3051
|
+
if (slots.scroller?.className) {
|
|
3052
|
+
view.scrollDOM.classList.add(...slots.scroller.className.split(/\s+/));
|
|
3053
|
+
}
|
|
2889
3054
|
}
|
|
2890
3055
|
})
|
|
2891
3056
|
].filter(isTruthy2);
|
|
@@ -2903,8 +3068,8 @@ var createDataExtensions = ({ id, text, messenger, identity }) => {
|
|
|
2903
3068
|
channel: `awareness.${id}`,
|
|
2904
3069
|
peerId: identity.identityKey.toHex(),
|
|
2905
3070
|
info: {
|
|
2906
|
-
darkColor: `var(--
|
|
2907
|
-
lightColor: `var(--
|
|
3071
|
+
darkColor: `var(--color-${hue}-border)`,
|
|
3072
|
+
lightColor: `var(--color-${hue}-border)`,
|
|
2908
3073
|
displayName: identity.profile?.displayName ?? generateName(identity.identityKey.toHex())
|
|
2909
3074
|
}
|
|
2910
3075
|
})));
|
|
@@ -2914,7 +3079,7 @@ var createDataExtensions = ({ id, text, messenger, identity }) => {
|
|
|
2914
3079
|
|
|
2915
3080
|
// src/extensions/folding.ts
|
|
2916
3081
|
import { codeFolding, foldGutter } from "@codemirror/language";
|
|
2917
|
-
import { EditorView as
|
|
3082
|
+
import { EditorView as EditorView17 } from "@codemirror/view";
|
|
2918
3083
|
import { Domino as Domino2, mx as mx4 } from "@dxos/ui";
|
|
2919
3084
|
var folding = () => {
|
|
2920
3085
|
return [
|
|
@@ -2922,13 +3087,14 @@ var folding = () => {
|
|
|
2922
3087
|
placeholderDOM: () => Domino2.of("span").root
|
|
2923
3088
|
}),
|
|
2924
3089
|
foldGutter({
|
|
3090
|
+
// NOTE: We can't animate since the element is remounted on state change.
|
|
2925
3091
|
markerDOM: (open) => {
|
|
2926
|
-
return Domino2.of("div").classNames("flex
|
|
3092
|
+
return Domino2.of("div").classNames("flex h-full justify-center items-center").append(Domino2.of("svg", Domino2.SVG).classNames(mx4("w-4 h-4 cursor-pointer", open && "rotate-90")).append(Domino2.of("use", Domino2.SVG).attributes({
|
|
2927
3093
|
href: Domino2.icon("ph--caret-right--regular")
|
|
2928
3094
|
}))).root;
|
|
2929
3095
|
}
|
|
2930
3096
|
}),
|
|
2931
|
-
|
|
3097
|
+
EditorView17.theme({
|
|
2932
3098
|
".cm-foldGutter": {
|
|
2933
3099
|
opacity: 0.3,
|
|
2934
3100
|
transition: "opacity 0.3s",
|
|
@@ -2942,7 +3108,7 @@ var folding = () => {
|
|
|
2942
3108
|
};
|
|
2943
3109
|
|
|
2944
3110
|
// src/extensions/hashtag.ts
|
|
2945
|
-
import { Decoration as Decoration8, EditorView as
|
|
3111
|
+
import { Decoration as Decoration8, EditorView as EditorView18, MatchDecorator, ViewPlugin as ViewPlugin13, WidgetType as WidgetType4 } from "@codemirror/view";
|
|
2946
3112
|
import { getHashStyles, mx as mx5 } from "@dxos/ui-theme";
|
|
2947
3113
|
var TagWidget = class extends WidgetType4 {
|
|
2948
3114
|
_text;
|
|
@@ -2963,7 +3129,7 @@ var tagMatcher = new MatchDecorator({
|
|
|
2963
3129
|
})
|
|
2964
3130
|
});
|
|
2965
3131
|
var hashtag = () => [
|
|
2966
|
-
|
|
3132
|
+
ViewPlugin13.fromClass(class {
|
|
2967
3133
|
tags;
|
|
2968
3134
|
constructor(view) {
|
|
2969
3135
|
this.tags = tagMatcher.createDeco(view);
|
|
@@ -2973,11 +3139,11 @@ var hashtag = () => [
|
|
|
2973
3139
|
}
|
|
2974
3140
|
}, {
|
|
2975
3141
|
decorations: (instance) => instance.tags,
|
|
2976
|
-
provide: (plugin) =>
|
|
3142
|
+
provide: (plugin) => EditorView18.atomicRanges.of((view) => {
|
|
2977
3143
|
return view.plugin(plugin)?.tags || Decoration8.none;
|
|
2978
3144
|
})
|
|
2979
3145
|
}),
|
|
2980
|
-
|
|
3146
|
+
EditorView18.theme({
|
|
2981
3147
|
".cm-tag": {
|
|
2982
3148
|
borderRadius: "4px",
|
|
2983
3149
|
marginRight: "6px",
|
|
@@ -3032,18 +3198,18 @@ var schemaLinter = (validate) => (view) => {
|
|
|
3032
3198
|
};
|
|
3033
3199
|
|
|
3034
3200
|
// src/extensions/listener.ts
|
|
3035
|
-
import { EditorView as
|
|
3201
|
+
import { EditorView as EditorView19 } from "@codemirror/view";
|
|
3036
3202
|
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
3037
3203
|
var listener = ({ onFocus, onChange }) => {
|
|
3038
3204
|
return [
|
|
3039
|
-
onFocus &&
|
|
3205
|
+
onFocus && EditorView19.focusChangeEffect.of((state, focusing) => {
|
|
3040
3206
|
onFocus({
|
|
3041
3207
|
id: state.facet(documentId),
|
|
3042
3208
|
focusing
|
|
3043
3209
|
});
|
|
3044
3210
|
return null;
|
|
3045
3211
|
}),
|
|
3046
|
-
onChange &&
|
|
3212
|
+
onChange && EditorView19.updateListener.of(({ state, docChanged }) => {
|
|
3047
3213
|
if (docChanged) {
|
|
3048
3214
|
onChange({
|
|
3049
3215
|
id: state.facet(documentId),
|
|
@@ -3058,7 +3224,7 @@ var listener = ({ onFocus, onChange }) => {
|
|
|
3058
3224
|
import { snippet } from "@codemirror/autocomplete";
|
|
3059
3225
|
import { syntaxTree as syntaxTree2 } from "@codemirror/language";
|
|
3060
3226
|
import { EditorSelection as EditorSelection2 } from "@codemirror/state";
|
|
3061
|
-
import { EditorView as
|
|
3227
|
+
import { EditorView as EditorView20, keymap as keymap8 } from "@codemirror/view";
|
|
3062
3228
|
import { debounceAndThrottle } from "@dxos/async";
|
|
3063
3229
|
var formattingEquals = (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;
|
|
3064
3230
|
var Inline = /* @__PURE__ */ (function(Inline2) {
|
|
@@ -4147,7 +4313,7 @@ var getFormatting = (state) => {
|
|
|
4147
4313
|
};
|
|
4148
4314
|
};
|
|
4149
4315
|
var formattingListener = (onStateChange, delay = 100) => {
|
|
4150
|
-
return
|
|
4316
|
+
return EditorView20.updateListener.of(debounceAndThrottle((update2) => {
|
|
4151
4317
|
if (update2.docChanged || update2.selectionSet) {
|
|
4152
4318
|
onStateChange(getFormatting(update2.state));
|
|
4153
4319
|
}
|
|
@@ -4208,8 +4374,7 @@ import { completionKeymap } from "@codemirror/autocomplete";
|
|
|
4208
4374
|
import { defaultKeymap as defaultKeymap2, indentWithTab as indentWithTab2 } from "@codemirror/commands";
|
|
4209
4375
|
import { jsonLanguage } from "@codemirror/lang-json";
|
|
4210
4376
|
import { markdown, markdownLanguage as markdownLanguage2 } from "@codemirror/lang-markdown";
|
|
4211
|
-
import {
|
|
4212
|
-
import { LanguageDescription, syntaxHighlighting as syntaxHighlighting2 } from "@codemirror/language";
|
|
4377
|
+
import { foldNodeProp, syntaxHighlighting as syntaxHighlighting2 } from "@codemirror/language";
|
|
4213
4378
|
import { languages } from "@codemirror/language-data";
|
|
4214
4379
|
import { keymap as keymap9 } from "@codemirror/view";
|
|
4215
4380
|
import { isTruthy as isTruthy3 } from "@dxos/util";
|
|
@@ -4330,30 +4495,38 @@ var markdownHighlightStyle = (_options = {}) => {
|
|
|
4330
4495
|
],
|
|
4331
4496
|
class: "font-mono"
|
|
4332
4497
|
},
|
|
4333
|
-
// Headings
|
|
4498
|
+
// Headings — use CSS properties only (no class:) so CodeMirror generates scoped CSS via
|
|
4499
|
+
// StyleModule that overrides vscodeDarkStyle's t.heading rule. When class: is present,
|
|
4500
|
+
// HighlightStyle silently ignores all other CSS properties (they're mutually exclusive).
|
|
4501
|
+
// Font sizes use Tailwind v4 CSS variables so nothing is hardcoded.
|
|
4502
|
+
{
|
|
4503
|
+
tag: tags.heading,
|
|
4504
|
+
color: "var(--color-cm-heading) !important",
|
|
4505
|
+
fontWeight: "300"
|
|
4506
|
+
},
|
|
4334
4507
|
{
|
|
4335
4508
|
tag: tags.heading1,
|
|
4336
|
-
|
|
4509
|
+
...markdownTheme.heading(1)
|
|
4337
4510
|
},
|
|
4338
4511
|
{
|
|
4339
4512
|
tag: tags.heading2,
|
|
4340
|
-
|
|
4513
|
+
...markdownTheme.heading(2)
|
|
4341
4514
|
},
|
|
4342
4515
|
{
|
|
4343
4516
|
tag: tags.heading3,
|
|
4344
|
-
|
|
4517
|
+
...markdownTheme.heading(3)
|
|
4345
4518
|
},
|
|
4346
4519
|
{
|
|
4347
4520
|
tag: tags.heading4,
|
|
4348
|
-
|
|
4521
|
+
...markdownTheme.heading(4)
|
|
4349
4522
|
},
|
|
4350
4523
|
{
|
|
4351
4524
|
tag: tags.heading5,
|
|
4352
|
-
|
|
4525
|
+
...markdownTheme.heading(5)
|
|
4353
4526
|
},
|
|
4354
4527
|
{
|
|
4355
4528
|
tag: tags.heading6,
|
|
4356
|
-
|
|
4529
|
+
...markdownTheme.heading(6)
|
|
4357
4530
|
},
|
|
4358
4531
|
// Emphasis.
|
|
4359
4532
|
{
|
|
@@ -4408,15 +4581,23 @@ var createMarkdownExtensions = (options = {}) => {
|
|
|
4408
4581
|
// https://github.com/lezer-parser/markdown?tab=readme-ov-file#github-flavored-markdown
|
|
4409
4582
|
base: markdownLanguage2,
|
|
4410
4583
|
// Languages for syntax highlighting fenced code blocks.
|
|
4584
|
+
// Caller-supplied languages are checked first so they can override defaults.
|
|
4411
4585
|
defaultCodeLanguage: jsonLanguage,
|
|
4412
|
-
codeLanguages:
|
|
4586
|
+
codeLanguages: [
|
|
4587
|
+
...options.codeLanguages ?? [],
|
|
4588
|
+
...languages
|
|
4589
|
+
],
|
|
4413
4590
|
// Don't complete HTML tags.
|
|
4414
4591
|
completeHTMLTags: false,
|
|
4415
4592
|
// Parser extensions.
|
|
4416
4593
|
extensions: [
|
|
4417
4594
|
// GFM provided by default.
|
|
4418
4595
|
markdownTagsExtensions,
|
|
4419
|
-
...options.extensions ?? defaultExtensions()
|
|
4596
|
+
...options.extensions ?? defaultExtensions(),
|
|
4597
|
+
// Disable folding for fenced code blocks by overriding foldNodeProp.
|
|
4598
|
+
// Note: returning null from foldService does not prevent syntaxFolding fallback,
|
|
4599
|
+
// so we must override the node prop directly on the FencedCode node type.
|
|
4600
|
+
noFencedCodeFolding
|
|
4420
4601
|
]
|
|
4421
4602
|
}),
|
|
4422
4603
|
// Custom styles.
|
|
@@ -4431,18 +4612,13 @@ var createMarkdownExtensions = (options = {}) => {
|
|
|
4431
4612
|
].filter(isTruthy3))
|
|
4432
4613
|
];
|
|
4433
4614
|
};
|
|
4434
|
-
var
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
]
|
|
4440
|
-
|
|
4441
|
-
"xml",
|
|
4442
|
-
"xhtml"
|
|
4443
|
-
],
|
|
4444
|
-
load: async () => xml()
|
|
4445
|
-
});
|
|
4615
|
+
var noFencedCodeFolding = {
|
|
4616
|
+
props: [
|
|
4617
|
+
foldNodeProp.add({
|
|
4618
|
+
FencedCode: () => null
|
|
4619
|
+
})
|
|
4620
|
+
]
|
|
4621
|
+
};
|
|
4446
4622
|
var defaultExtensions = () => [
|
|
4447
4623
|
noSetExtHeading,
|
|
4448
4624
|
noHtml
|
|
@@ -4462,19 +4638,19 @@ var debugTree = (cb) => StateField6.define({
|
|
|
4462
4638
|
update: (value, tr) => cb(convertTreeToJson(tr.state))
|
|
4463
4639
|
});
|
|
4464
4640
|
var convertTreeToJson = (state) => {
|
|
4465
|
-
const treeToJson = (
|
|
4641
|
+
const treeToJson = (cursor) => {
|
|
4466
4642
|
const node = {
|
|
4467
|
-
type:
|
|
4468
|
-
from:
|
|
4469
|
-
to:
|
|
4470
|
-
text: state.doc.slice(
|
|
4643
|
+
type: cursor.type.name,
|
|
4644
|
+
from: cursor.from,
|
|
4645
|
+
to: cursor.to,
|
|
4646
|
+
text: state.doc.slice(cursor.from, cursor.to).toString(),
|
|
4471
4647
|
children: []
|
|
4472
4648
|
};
|
|
4473
|
-
if (
|
|
4649
|
+
if (cursor.firstChild()) {
|
|
4474
4650
|
do {
|
|
4475
|
-
node.children.push(treeToJson(
|
|
4476
|
-
} while (
|
|
4477
|
-
|
|
4651
|
+
node.children.push(treeToJson(cursor));
|
|
4652
|
+
} while (cursor.nextSibling());
|
|
4653
|
+
cursor.parent();
|
|
4478
4654
|
}
|
|
4479
4655
|
return node;
|
|
4480
4656
|
};
|
|
@@ -4484,16 +4660,15 @@ var convertTreeToJson = (state) => {
|
|
|
4484
4660
|
// src/extensions/markdown/decorate.ts
|
|
4485
4661
|
import { syntaxTree as syntaxTree7 } from "@codemirror/language";
|
|
4486
4662
|
import { Prec as Prec4, RangeSetBuilder as RangeSetBuilder5, StateEffect as StateEffect7 } from "@codemirror/state";
|
|
4487
|
-
import { Decoration as Decoration11, EditorView as
|
|
4663
|
+
import { Decoration as Decoration11, EditorView as EditorView24, ViewPlugin as ViewPlugin15, WidgetType as WidgetType7 } from "@codemirror/view";
|
|
4488
4664
|
import { invariant as invariant4 } from "@dxos/invariant";
|
|
4489
|
-
import { mx as mx6 } from "@dxos/ui-theme";
|
|
4490
4665
|
|
|
4491
4666
|
// src/extensions/markdown/changes.ts
|
|
4492
4667
|
import { syntaxTree as syntaxTree4 } from "@codemirror/language";
|
|
4493
4668
|
import { Transaction as Transaction4 } from "@codemirror/state";
|
|
4494
|
-
import { ViewPlugin as
|
|
4669
|
+
import { ViewPlugin as ViewPlugin14 } from "@codemirror/view";
|
|
4495
4670
|
var adjustChanges = () => {
|
|
4496
|
-
return
|
|
4671
|
+
return ViewPlugin14.fromClass(class {
|
|
4497
4672
|
update(update2) {
|
|
4498
4673
|
const tree = syntaxTree4(update2.state);
|
|
4499
4674
|
const adjustments = [];
|
|
@@ -4635,7 +4810,7 @@ var getValidUrl = (str) => {
|
|
|
4635
4810
|
// src/extensions/markdown/image.ts
|
|
4636
4811
|
import { syntaxTree as syntaxTree5 } from "@codemirror/language";
|
|
4637
4812
|
import { StateField as StateField7 } from "@codemirror/state";
|
|
4638
|
-
import { Decoration as Decoration9, EditorView as
|
|
4813
|
+
import { Decoration as Decoration9, EditorView as EditorView21, WidgetType as WidgetType5 } from "@codemirror/view";
|
|
4639
4814
|
var image = (_options = {}) => {
|
|
4640
4815
|
return [
|
|
4641
4816
|
StateField7.define({
|
|
@@ -4646,10 +4821,10 @@ var image = (_options = {}) => {
|
|
|
4646
4821
|
if (!tr.docChanged && !tr.selection) {
|
|
4647
4822
|
return value;
|
|
4648
4823
|
}
|
|
4649
|
-
const
|
|
4824
|
+
const cursor = tr.state.selection.main.head;
|
|
4650
4825
|
const oldCursor = tr.changes.mapPos(tr.startState.selection.main.head);
|
|
4651
|
-
let from = Math.min(
|
|
4652
|
-
let to = Math.max(
|
|
4826
|
+
let from = Math.min(cursor, oldCursor);
|
|
4827
|
+
let to = Math.max(cursor, oldCursor);
|
|
4653
4828
|
tr.changes.iterChangedRanges((fromA, toA, fromB, toB) => {
|
|
4654
4829
|
from = Math.min(from, fromB);
|
|
4655
4830
|
to = Math.max(to, toB);
|
|
@@ -4663,19 +4838,19 @@ var image = (_options = {}) => {
|
|
|
4663
4838
|
add: buildDecorations(tr.state, from, to)
|
|
4664
4839
|
});
|
|
4665
4840
|
},
|
|
4666
|
-
provide: (field) =>
|
|
4841
|
+
provide: (field) => EditorView21.decorations.from(field)
|
|
4667
4842
|
})
|
|
4668
4843
|
];
|
|
4669
4844
|
};
|
|
4670
4845
|
var buildDecorations = (state, from, to) => {
|
|
4671
4846
|
const decorations2 = [];
|
|
4672
|
-
const
|
|
4847
|
+
const cursor = state.selection.main.head;
|
|
4673
4848
|
syntaxTree5(state).iterate({
|
|
4674
4849
|
enter: (node) => {
|
|
4675
4850
|
if (node.name === "Image") {
|
|
4676
4851
|
const urlNode = node.node.getChild("URL");
|
|
4677
4852
|
if (urlNode) {
|
|
4678
|
-
const hide2 = state.readOnly ||
|
|
4853
|
+
const hide2 = state.readOnly || cursor < node.from || cursor > node.to || !state.field(focusField);
|
|
4679
4854
|
const url = state.sliceDoc(urlNode.from, urlNode.to);
|
|
4680
4855
|
if (url.match(/^https?:\/\//) === null && url.match(/^file?:\/\//) === null) {
|
|
4681
4856
|
return;
|
|
@@ -4723,10 +4898,10 @@ var ImageWidget = class extends WidgetType5 {
|
|
|
4723
4898
|
};
|
|
4724
4899
|
|
|
4725
4900
|
// src/extensions/markdown/styles.ts
|
|
4726
|
-
import { EditorView as
|
|
4901
|
+
import { EditorView as EditorView22 } from "@codemirror/view";
|
|
4727
4902
|
var bulletListIndentationWidth = 24;
|
|
4728
4903
|
var orderedListIndentationWidth = 36;
|
|
4729
|
-
var formattingStyles =
|
|
4904
|
+
var formattingStyles = EditorView22.theme({
|
|
4730
4905
|
/**
|
|
4731
4906
|
* Horizontal rule.
|
|
4732
4907
|
*/
|
|
@@ -4735,7 +4910,7 @@ var formattingStyles = EditorView21.theme({
|
|
|
4735
4910
|
width: "100%",
|
|
4736
4911
|
height: "0",
|
|
4737
4912
|
verticalAlign: "middle",
|
|
4738
|
-
borderTop: "1px solid var(--
|
|
4913
|
+
borderTop: "1px solid var(--color-cm-separator)",
|
|
4739
4914
|
opacity: 0.5
|
|
4740
4915
|
},
|
|
4741
4916
|
/**
|
|
@@ -4758,19 +4933,44 @@ var formattingStyles = EditorView21.theme({
|
|
|
4758
4933
|
* Blockquote.
|
|
4759
4934
|
*/
|
|
4760
4935
|
"& .cm-blockquote": {
|
|
4761
|
-
background: "var(--
|
|
4762
|
-
borderLeft: "2px solid var(--
|
|
4936
|
+
background: "var(--color-cm-codeblock)",
|
|
4937
|
+
borderLeft: "2px solid var(--color-cm-separator)",
|
|
4763
4938
|
paddingLeft: "1rem",
|
|
4764
|
-
margin:
|
|
4939
|
+
margin: 0
|
|
4765
4940
|
},
|
|
4766
4941
|
/**
|
|
4767
4942
|
* Code and codeblocks.
|
|
4768
4943
|
*/
|
|
4944
|
+
"& code": {
|
|
4945
|
+
fontFamily: fontMono,
|
|
4946
|
+
color: "var(--color-cm-code)",
|
|
4947
|
+
whiteSpace: "nowrap"
|
|
4948
|
+
},
|
|
4769
4949
|
"& .cm-code": {
|
|
4770
|
-
fontFamily: fontMono
|
|
4950
|
+
fontFamily: fontMono,
|
|
4951
|
+
color: "var(--color-cm-code)"
|
|
4952
|
+
},
|
|
4953
|
+
// Inline code spans (triggered by backticks) use `cm-code-inline` + `font-mono`.
|
|
4954
|
+
// Different monospace font metrics can slightly overflow the fixed CodeMirror line box,
|
|
4955
|
+
// so constrain them to the target 24px height.
|
|
4956
|
+
"& .cm-code-inline": {
|
|
4957
|
+
fontFamily: fontMono,
|
|
4958
|
+
height: "24px",
|
|
4959
|
+
// display: 'inline-flex',
|
|
4960
|
+
alignItems: "center",
|
|
4961
|
+
overflow: "hidden",
|
|
4962
|
+
whiteSpace: "nowrap",
|
|
4963
|
+
color: "var(--color-cm-code-inline)"
|
|
4964
|
+
},
|
|
4965
|
+
"& .cm-code-mark": {
|
|
4966
|
+
fontFamily: fontMono,
|
|
4967
|
+
height: "24px",
|
|
4968
|
+
display: "inline-flex",
|
|
4969
|
+
alignItems: "center",
|
|
4970
|
+
overflow: "hidden"
|
|
4771
4971
|
},
|
|
4772
4972
|
"& .cm-codeblock-line": {
|
|
4773
|
-
background: "var(--
|
|
4973
|
+
background: "var(--color-cm-codeblock)",
|
|
4774
4974
|
paddingInline: "1rem !important"
|
|
4775
4975
|
},
|
|
4776
4976
|
"& .cm-codeblock-start": {
|
|
@@ -4799,16 +4999,24 @@ var formattingStyles = EditorView21.theme({
|
|
|
4799
4999
|
*/
|
|
4800
5000
|
".cm-table *": {
|
|
4801
5001
|
fontFamily: fontMono,
|
|
5002
|
+
lineHeight: 1.5,
|
|
4802
5003
|
textDecoration: "none !important"
|
|
4803
5004
|
},
|
|
4804
5005
|
".cm-table-head": {
|
|
4805
5006
|
padding: "2px 16px 2px 0px",
|
|
5007
|
+
overflowWrap: "break-word",
|
|
5008
|
+
whiteSpace: "pre-wrap",
|
|
5009
|
+
wordBreak: "keep-all",
|
|
4806
5010
|
textAlign: "left",
|
|
4807
|
-
|
|
4808
|
-
|
|
5011
|
+
color: "var(--color-subdued)",
|
|
5012
|
+
borderBottom: "1px solid var(--color-cm-separator)"
|
|
4809
5013
|
},
|
|
4810
5014
|
".cm-table-cell": {
|
|
4811
|
-
padding: "2px 16px 2px 0px"
|
|
5015
|
+
padding: "2px 16px 2px 0px",
|
|
5016
|
+
overflowWrap: "break-word",
|
|
5017
|
+
whiteSpace: "pre-wrap",
|
|
5018
|
+
wordBreak: "keep-all",
|
|
5019
|
+
verticalAlign: "top"
|
|
4812
5020
|
},
|
|
4813
5021
|
/**
|
|
4814
5022
|
* Image.
|
|
@@ -4824,12 +5032,12 @@ var formattingStyles = EditorView21.theme({
|
|
|
4824
5032
|
},
|
|
4825
5033
|
".cm-image-with-loader": {
|
|
4826
5034
|
display: "block",
|
|
4827
|
-
opacity:
|
|
5035
|
+
opacity: 0,
|
|
4828
5036
|
transitionDuration: "350ms",
|
|
4829
5037
|
transitionProperty: "opacity"
|
|
4830
5038
|
},
|
|
4831
5039
|
".cm-image-with-loader.cm-loaded-image": {
|
|
4832
|
-
opacity:
|
|
5040
|
+
opacity: 1
|
|
4833
5041
|
},
|
|
4834
5042
|
".cm-image-wrapper": {
|
|
4835
5043
|
"grid-template-columns": "1fr",
|
|
@@ -4848,17 +5056,17 @@ var formattingStyles = EditorView21.theme({
|
|
|
4848
5056
|
// src/extensions/markdown/table.ts
|
|
4849
5057
|
import { syntaxTree as syntaxTree6 } from "@codemirror/language";
|
|
4850
5058
|
import { RangeSetBuilder as RangeSetBuilder4, StateField as StateField8 } from "@codemirror/state";
|
|
4851
|
-
import { Decoration as Decoration10, EditorView as
|
|
5059
|
+
import { Decoration as Decoration10, EditorView as EditorView23, WidgetType as WidgetType6 } from "@codemirror/view";
|
|
4852
5060
|
var table = (options = {}) => {
|
|
4853
5061
|
return StateField8.define({
|
|
4854
5062
|
create: (state) => update(state, options),
|
|
4855
5063
|
update: (_, tr) => update(tr.state, options),
|
|
4856
|
-
provide: (field) =>
|
|
5064
|
+
provide: (field) => EditorView23.decorations.from(field)
|
|
4857
5065
|
});
|
|
4858
5066
|
};
|
|
4859
5067
|
var update = (state, _options) => {
|
|
4860
5068
|
const builder = new RangeSetBuilder4();
|
|
4861
|
-
const
|
|
5069
|
+
const cursor = state.selection.main.head;
|
|
4862
5070
|
const tables = [];
|
|
4863
5071
|
const getTable = () => tables[tables.length - 1];
|
|
4864
5072
|
const getRow = () => {
|
|
@@ -4896,7 +5104,7 @@ var update = (state, _options) => {
|
|
|
4896
5104
|
}
|
|
4897
5105
|
});
|
|
4898
5106
|
tables.forEach((table2) => {
|
|
4899
|
-
const replace = state.readOnly ||
|
|
5107
|
+
const replace = state.readOnly || cursor < table2.from || cursor > table2.to;
|
|
4900
5108
|
if (replace) {
|
|
4901
5109
|
builder.add(table2.from, table2.to, Decoration10.replace({
|
|
4902
5110
|
block: true,
|
|
@@ -4910,6 +5118,26 @@ var update = (state, _options) => {
|
|
|
4910
5118
|
});
|
|
4911
5119
|
return builder.finish();
|
|
4912
5120
|
};
|
|
5121
|
+
var renderCellContent = (el, text) => {
|
|
5122
|
+
const parts = text.split(/(`[^`\n]+`|\*\*[^*\n]+\*\*|__[^_\n]+__|\*[^*\n]+\*|_[^_\n]+_)/);
|
|
5123
|
+
for (const part of parts) {
|
|
5124
|
+
if (part.length > 2 && part.startsWith("`") && part.endsWith("`")) {
|
|
5125
|
+
const code = document.createElement("code");
|
|
5126
|
+
code.textContent = part.slice(1, -1);
|
|
5127
|
+
el.appendChild(code);
|
|
5128
|
+
} else if (part.startsWith("**") && part.endsWith("**") || part.startsWith("__") && part.endsWith("__")) {
|
|
5129
|
+
const strong = document.createElement("strong");
|
|
5130
|
+
strong.textContent = part.slice(2, -2);
|
|
5131
|
+
el.appendChild(strong);
|
|
5132
|
+
} else if (part.startsWith("*") && part.endsWith("*") || part.startsWith("_") && part.endsWith("_")) {
|
|
5133
|
+
const em = document.createElement("em");
|
|
5134
|
+
em.textContent = part.slice(1, -1);
|
|
5135
|
+
el.appendChild(em);
|
|
5136
|
+
} else {
|
|
5137
|
+
el.appendChild(document.createTextNode(part));
|
|
5138
|
+
}
|
|
5139
|
+
}
|
|
5140
|
+
};
|
|
4913
5141
|
var TableWidget = class extends WidgetType6 {
|
|
4914
5142
|
_table;
|
|
4915
5143
|
constructor(_table) {
|
|
@@ -4929,7 +5157,7 @@ var TableWidget = class extends WidgetType6 {
|
|
|
4929
5157
|
this._table.header?.forEach((cell) => {
|
|
4930
5158
|
const th = document.createElement("th");
|
|
4931
5159
|
th.setAttribute("class", "cm-table-head");
|
|
4932
|
-
tr.appendChild(th)
|
|
5160
|
+
renderCellContent(tr.appendChild(th), cell);
|
|
4933
5161
|
});
|
|
4934
5162
|
const body = table2.appendChild(document.createElement("tbody"));
|
|
4935
5163
|
this._table.rows?.forEach((row) => {
|
|
@@ -4937,7 +5165,7 @@ var TableWidget = class extends WidgetType6 {
|
|
|
4937
5165
|
row.forEach((cell) => {
|
|
4938
5166
|
const td = document.createElement("td");
|
|
4939
5167
|
td.setAttribute("class", "cm-table-cell");
|
|
4940
|
-
tr2.appendChild(td)
|
|
5168
|
+
renderCellContent(tr2.appendChild(td), cell);
|
|
4941
5169
|
});
|
|
4942
5170
|
});
|
|
4943
5171
|
return div;
|
|
@@ -4945,7 +5173,7 @@ var TableWidget = class extends WidgetType6 {
|
|
|
4945
5173
|
};
|
|
4946
5174
|
|
|
4947
5175
|
// src/extensions/markdown/decorate.ts
|
|
4948
|
-
var
|
|
5176
|
+
var __dxlog_file12 = "/__w/dxos/dxos/packages/ui/ui-editor/src/extensions/markdown/decorate.ts";
|
|
4949
5177
|
var Unicode = {
|
|
4950
5178
|
emDash: "\u2014",
|
|
4951
5179
|
bullet: "\u2022",
|
|
@@ -4968,7 +5196,6 @@ var LinkButton = class extends WidgetType7 {
|
|
|
4968
5196
|
eq(other) {
|
|
4969
5197
|
return this.url === other.url;
|
|
4970
5198
|
}
|
|
4971
|
-
// TODO(burdon): Create icon and link directly without react?
|
|
4972
5199
|
toDOM(view) {
|
|
4973
5200
|
const el = document.createElement("span");
|
|
4974
5201
|
this.render(el, {
|
|
@@ -5045,10 +5272,10 @@ var fencedCodeLine = Decoration11.line({
|
|
|
5045
5272
|
class: "cm-code cm-codeblock-line"
|
|
5046
5273
|
});
|
|
5047
5274
|
var fencedCodeLineFirst = Decoration11.line({
|
|
5048
|
-
class:
|
|
5275
|
+
class: "cm-code cm-codeblock-line cm-codeblock-start"
|
|
5049
5276
|
});
|
|
5050
5277
|
var fencedCodeLineLast = Decoration11.line({
|
|
5051
|
-
class:
|
|
5278
|
+
class: "cm-code cm-codeblock-line cm-codeblock-end"
|
|
5052
5279
|
});
|
|
5053
5280
|
var commentBlockLine = fencedCodeLine;
|
|
5054
5281
|
var commentBlockLineFirst = fencedCodeLineFirst;
|
|
@@ -5081,8 +5308,8 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
|
5081
5308
|
const headerLevels = [];
|
|
5082
5309
|
const getHeaderLevels = (node, level) => {
|
|
5083
5310
|
invariant4(level > 0, void 0, {
|
|
5084
|
-
F:
|
|
5085
|
-
L:
|
|
5311
|
+
F: __dxlog_file12,
|
|
5312
|
+
L: 177,
|
|
5086
5313
|
S: void 0,
|
|
5087
5314
|
A: [
|
|
5088
5315
|
"level > 0",
|
|
@@ -5120,8 +5347,8 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
|
5120
5347
|
};
|
|
5121
5348
|
const getCurrentListLevel = () => {
|
|
5122
5349
|
invariant4(listLevels.length, void 0, {
|
|
5123
|
-
F:
|
|
5124
|
-
L:
|
|
5350
|
+
F: __dxlog_file12,
|
|
5351
|
+
L: 199,
|
|
5125
5352
|
S: void 0,
|
|
5126
5353
|
A: [
|
|
5127
5354
|
"listLevels.length",
|
|
@@ -5165,13 +5392,13 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
|
5165
5392
|
deco: hide
|
|
5166
5393
|
});
|
|
5167
5394
|
} else {
|
|
5168
|
-
const num = headers.slice(from - 1).map((level2) => level2?.number ?? 0).join(".") + " ";
|
|
5395
|
+
const num = headers.slice(from - 1).map((level2) => level2?.number ?? 0).join(".") + "). ";
|
|
5169
5396
|
if (num.length) {
|
|
5170
5397
|
atomicDecoRanges.push({
|
|
5171
5398
|
from: mark.from,
|
|
5172
5399
|
to: mark.from + len,
|
|
5173
5400
|
deco: Decoration11.replace({
|
|
5174
|
-
widget: new TextWidget(num, markdownTheme.heading(level))
|
|
5401
|
+
widget: new TextWidget(num, markdownTheme.heading(level).className)
|
|
5175
5402
|
})
|
|
5176
5403
|
});
|
|
5177
5404
|
}
|
|
@@ -5348,11 +5575,11 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
|
5348
5575
|
}
|
|
5349
5576
|
decoRanges.push({
|
|
5350
5577
|
from: marks[0].to,
|
|
5351
|
-
to: marks[1].from,
|
|
5578
|
+
to: !editing && options.renderLinkButton ? node.to : marks[1].from,
|
|
5352
5579
|
deco: Decoration11.mark({
|
|
5353
5580
|
tagName: "a",
|
|
5354
5581
|
attributes: {
|
|
5355
|
-
class: "cm-link",
|
|
5582
|
+
class: options.renderLinkButton ? "cm-link cm-link-with-button" : "cm-link",
|
|
5356
5583
|
href: url,
|
|
5357
5584
|
rel: "noreferrer",
|
|
5358
5585
|
target: "_blank"
|
|
@@ -5430,8 +5657,11 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
|
5430
5657
|
deco.add(from, to, d);
|
|
5431
5658
|
}
|
|
5432
5659
|
const atomicDeco = new RangeSetBuilder5();
|
|
5433
|
-
for (const { from, to, deco:
|
|
5434
|
-
|
|
5660
|
+
for (const { from, to, deco: deco2 } of atomicDecoRanges) {
|
|
5661
|
+
if (from < to && state.doc.lineAt(from).number !== state.doc.lineAt(to).number) {
|
|
5662
|
+
continue;
|
|
5663
|
+
}
|
|
5664
|
+
atomicDeco.add(from, to, deco2);
|
|
5435
5665
|
}
|
|
5436
5666
|
return {
|
|
5437
5667
|
deco: deco.finish(),
|
|
@@ -5441,7 +5671,7 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
|
5441
5671
|
var forceUpdate = StateEffect7.define();
|
|
5442
5672
|
var decorateMarkdown = (options = {}) => {
|
|
5443
5673
|
return [
|
|
5444
|
-
|
|
5674
|
+
ViewPlugin15.fromClass(class {
|
|
5445
5675
|
deco;
|
|
5446
5676
|
atomicDeco;
|
|
5447
5677
|
pendingUpdate;
|
|
@@ -5476,9 +5706,9 @@ var decorateMarkdown = (options = {}) => {
|
|
|
5476
5706
|
}
|
|
5477
5707
|
}, {
|
|
5478
5708
|
provide: (plugin) => [
|
|
5479
|
-
Prec4.low(
|
|
5480
|
-
|
|
5481
|
-
|
|
5709
|
+
Prec4.low(EditorView24.decorations.of((view) => view.plugin(plugin)?.deco ?? Decoration11.none)),
|
|
5710
|
+
EditorView24.decorations.of((view) => view.plugin(plugin)?.atomicDeco ?? Decoration11.none),
|
|
5711
|
+
EditorView24.atomicRanges.of((view) => view.plugin(plugin)?.atomicDeco ?? Decoration11.none)
|
|
5482
5712
|
]
|
|
5483
5713
|
}),
|
|
5484
5714
|
image(),
|
|
@@ -5510,8 +5740,7 @@ var linkTooltip = (renderTooltip) => {
|
|
|
5510
5740
|
return {
|
|
5511
5741
|
pos: link.from,
|
|
5512
5742
|
end: link.to,
|
|
5513
|
-
|
|
5514
|
-
// above: true,
|
|
5743
|
+
above: true,
|
|
5515
5744
|
create: () => {
|
|
5516
5745
|
const el = document.createElement("div");
|
|
5517
5746
|
el.className = tooltipContent({});
|
|
@@ -5527,16 +5756,13 @@ var linkTooltip = (renderTooltip) => {
|
|
|
5527
5756
|
};
|
|
5528
5757
|
}
|
|
5529
5758
|
};
|
|
5530
|
-
}, {
|
|
5531
|
-
// NOTE: 0 = default of 300ms.
|
|
5532
|
-
hoverTime: 1
|
|
5533
5759
|
});
|
|
5534
5760
|
};
|
|
5535
5761
|
|
|
5536
5762
|
// src/extensions/mention.ts
|
|
5537
5763
|
import { autocompletion } from "@codemirror/autocomplete";
|
|
5538
|
-
import { log as
|
|
5539
|
-
var
|
|
5764
|
+
import { log as log9 } from "@dxos/log";
|
|
5765
|
+
var __dxlog_file13 = "/__w/dxos/dxos/packages/ui/ui-editor/src/extensions/mention.ts";
|
|
5540
5766
|
var mention = ({ debug, onSearch }) => {
|
|
5541
5767
|
return autocompletion({
|
|
5542
5768
|
// TODO(burdon): Not working.
|
|
@@ -5548,10 +5774,10 @@ var mention = ({ debug, onSearch }) => {
|
|
|
5548
5774
|
icons: false,
|
|
5549
5775
|
override: [
|
|
5550
5776
|
(context) => {
|
|
5551
|
-
|
|
5777
|
+
log9.info("completion context", {
|
|
5552
5778
|
context
|
|
5553
5779
|
}, {
|
|
5554
|
-
F:
|
|
5780
|
+
F: __dxlog_file13,
|
|
5555
5781
|
L: 27,
|
|
5556
5782
|
S: void 0,
|
|
5557
5783
|
C: (f, a) => f(...a)
|
|
@@ -5634,7 +5860,7 @@ import { syntaxTree as syntaxTree9 } from "@codemirror/language";
|
|
|
5634
5860
|
import { StateField as StateField10 } from "@codemirror/state";
|
|
5635
5861
|
import { Facet as Facet2 } from "@codemirror/state";
|
|
5636
5862
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
5637
|
-
var
|
|
5863
|
+
var __dxlog_file14 = "/__w/dxos/dxos/packages/ui/ui-editor/src/extensions/outliner/tree.ts";
|
|
5638
5864
|
var itemToJSON = ({ type, index, level, lineRange, contentRange, children }) => {
|
|
5639
5865
|
return {
|
|
5640
5866
|
type,
|
|
@@ -5789,7 +6015,7 @@ var outlinerTree = (_options = {}) => {
|
|
|
5789
6015
|
}
|
|
5790
6016
|
case "BulletList": {
|
|
5791
6017
|
invariant5(current, void 0, {
|
|
5792
|
-
F:
|
|
6018
|
+
F: __dxlog_file14,
|
|
5793
6019
|
L: 219,
|
|
5794
6020
|
S: void 0,
|
|
5795
6021
|
A: [
|
|
@@ -5806,7 +6032,7 @@ var outlinerTree = (_options = {}) => {
|
|
|
5806
6032
|
}
|
|
5807
6033
|
case "ListItem": {
|
|
5808
6034
|
invariant5(parent, void 0, {
|
|
5809
|
-
F:
|
|
6035
|
+
F: __dxlog_file14,
|
|
5810
6036
|
L: 228,
|
|
5811
6037
|
S: void 0,
|
|
5812
6038
|
A: [
|
|
@@ -5848,7 +6074,7 @@ var outlinerTree = (_options = {}) => {
|
|
|
5848
6074
|
}
|
|
5849
6075
|
case "ListMark": {
|
|
5850
6076
|
invariant5(current, void 0, {
|
|
5851
|
-
F:
|
|
6077
|
+
F: __dxlog_file14,
|
|
5852
6078
|
L: 272,
|
|
5853
6079
|
S: void 0,
|
|
5854
6080
|
A: [
|
|
@@ -5862,7 +6088,7 @@ var outlinerTree = (_options = {}) => {
|
|
|
5862
6088
|
}
|
|
5863
6089
|
case "Task": {
|
|
5864
6090
|
invariant5(current, void 0, {
|
|
5865
|
-
F:
|
|
6091
|
+
F: __dxlog_file14,
|
|
5866
6092
|
L: 278,
|
|
5867
6093
|
S: void 0,
|
|
5868
6094
|
A: [
|
|
@@ -5875,7 +6101,7 @@ var outlinerTree = (_options = {}) => {
|
|
|
5875
6101
|
}
|
|
5876
6102
|
case "TaskMarker": {
|
|
5877
6103
|
invariant5(current, void 0, {
|
|
5878
|
-
F:
|
|
6104
|
+
F: __dxlog_file14,
|
|
5879
6105
|
L: 283,
|
|
5880
6106
|
S: void 0,
|
|
5881
6107
|
A: [
|
|
@@ -5891,7 +6117,7 @@ var outlinerTree = (_options = {}) => {
|
|
|
5891
6117
|
leave: (node) => {
|
|
5892
6118
|
if (node.name === "BulletList") {
|
|
5893
6119
|
invariant5(parent, void 0, {
|
|
5894
|
-
F:
|
|
6120
|
+
F: __dxlog_file14,
|
|
5895
6121
|
L: 291,
|
|
5896
6122
|
S: void 0,
|
|
5897
6123
|
A: [
|
|
@@ -5905,7 +6131,7 @@ var outlinerTree = (_options = {}) => {
|
|
|
5905
6131
|
}
|
|
5906
6132
|
});
|
|
5907
6133
|
invariant5(tree, void 0, {
|
|
5908
|
-
F:
|
|
6134
|
+
F: __dxlog_file14,
|
|
5909
6135
|
L: 298,
|
|
5910
6136
|
S: void 0,
|
|
5911
6137
|
A: [
|
|
@@ -6197,17 +6423,17 @@ var commands = () => keymap11.of([
|
|
|
6197
6423
|
|
|
6198
6424
|
// src/extensions/outliner/outliner.ts
|
|
6199
6425
|
import { Prec as Prec5 } from "@codemirror/state";
|
|
6200
|
-
import { Decoration as Decoration12, EditorView as
|
|
6201
|
-
import { mx as
|
|
6426
|
+
import { Decoration as Decoration12, EditorView as EditorView26, ViewPlugin as ViewPlugin18 } from "@codemirror/view";
|
|
6427
|
+
import { mx as mx6 } from "@dxos/ui-theme";
|
|
6202
6428
|
|
|
6203
6429
|
// src/extensions/outliner/editor.ts
|
|
6204
6430
|
import { EditorSelection as EditorSelection4, EditorState as EditorState2 } from "@codemirror/state";
|
|
6205
|
-
import { ViewPlugin as
|
|
6206
|
-
import { log as
|
|
6207
|
-
var
|
|
6431
|
+
import { ViewPlugin as ViewPlugin16 } from "@codemirror/view";
|
|
6432
|
+
import { log as log10 } from "@dxos/log";
|
|
6433
|
+
var __dxlog_file15 = "/__w/dxos/dxos/packages/ui/ui-editor/src/extensions/outliner/editor.ts";
|
|
6208
6434
|
var LIST_ITEM_REGEX = /^\s*- (\[ \]|\[x\])? /;
|
|
6209
6435
|
var initialize = () => {
|
|
6210
|
-
return
|
|
6436
|
+
return ViewPlugin16.fromClass(class {
|
|
6211
6437
|
constructor(view) {
|
|
6212
6438
|
const first = view.state.doc.lineAt(0);
|
|
6213
6439
|
const text = view.state.sliceDoc(first.from, first.to);
|
|
@@ -6336,7 +6562,7 @@ var editor = () => [
|
|
|
6336
6562
|
cancel = true;
|
|
6337
6563
|
return;
|
|
6338
6564
|
}
|
|
6339
|
-
|
|
6565
|
+
log10("change", {
|
|
6340
6566
|
item,
|
|
6341
6567
|
line: {
|
|
6342
6568
|
from: line.from,
|
|
@@ -6355,7 +6581,7 @@ var editor = () => [
|
|
|
6355
6581
|
length: insert.length
|
|
6356
6582
|
}
|
|
6357
6583
|
}, {
|
|
6358
|
-
F:
|
|
6584
|
+
F: __dxlog_file15,
|
|
6359
6585
|
L: 164,
|
|
6360
6586
|
S: void 0,
|
|
6361
6587
|
C: (f, a) => f(...a)
|
|
@@ -6363,10 +6589,10 @@ var editor = () => [
|
|
|
6363
6589
|
}
|
|
6364
6590
|
});
|
|
6365
6591
|
if (changes.length > 0) {
|
|
6366
|
-
|
|
6592
|
+
log10("modified,", {
|
|
6367
6593
|
changes
|
|
6368
6594
|
}, {
|
|
6369
|
-
F:
|
|
6595
|
+
F: __dxlog_file15,
|
|
6370
6596
|
L: 175,
|
|
6371
6597
|
S: void 0,
|
|
6372
6598
|
C: (f, a) => f(...a)
|
|
@@ -6377,8 +6603,8 @@ var editor = () => [
|
|
|
6377
6603
|
}
|
|
6378
6604
|
];
|
|
6379
6605
|
} else if (cancel) {
|
|
6380
|
-
|
|
6381
|
-
F:
|
|
6606
|
+
log10("cancel", void 0, {
|
|
6607
|
+
F: __dxlog_file15,
|
|
6382
6608
|
L: 178,
|
|
6383
6609
|
S: void 0,
|
|
6384
6610
|
C: (f, a) => f(...a)
|
|
@@ -6390,10 +6616,10 @@ var editor = () => [
|
|
|
6390
6616
|
];
|
|
6391
6617
|
|
|
6392
6618
|
// src/extensions/outliner/menu.ts
|
|
6393
|
-
import { EditorView as
|
|
6394
|
-
import { addEventListener } from "@dxos/async";
|
|
6619
|
+
import { EditorView as EditorView25, ViewPlugin as ViewPlugin17 } from "@codemirror/view";
|
|
6620
|
+
import { addEventListener as addEventListener2 } from "@dxos/async";
|
|
6395
6621
|
var menu = (options = {}) => [
|
|
6396
|
-
|
|
6622
|
+
ViewPlugin17.fromClass(class {
|
|
6397
6623
|
view;
|
|
6398
6624
|
tag;
|
|
6399
6625
|
rafId;
|
|
@@ -6413,7 +6639,7 @@ var menu = (options = {}) => [
|
|
|
6413
6639
|
}
|
|
6414
6640
|
container.appendChild(this.tag);
|
|
6415
6641
|
const handler = () => this.scheduleUpdate();
|
|
6416
|
-
this.cleanup =
|
|
6642
|
+
this.cleanup = addEventListener2(container, "scroll", handler);
|
|
6417
6643
|
this.scheduleUpdate();
|
|
6418
6644
|
}
|
|
6419
6645
|
destroy() {
|
|
@@ -6455,7 +6681,7 @@ var menu = (options = {}) => [
|
|
|
6455
6681
|
this.rafId = requestAnimationFrame(this.updateButtonPosition.bind(this));
|
|
6456
6682
|
}
|
|
6457
6683
|
}),
|
|
6458
|
-
|
|
6684
|
+
EditorView25.theme({
|
|
6459
6685
|
".cm-popover-trigger": {
|
|
6460
6686
|
position: "fixed",
|
|
6461
6687
|
padding: "0",
|
|
@@ -6491,12 +6717,12 @@ var outliner = (_options = {}) => [
|
|
|
6491
6717
|
listPaddingLeft: 8
|
|
6492
6718
|
}),
|
|
6493
6719
|
// Researve space for menu.
|
|
6494
|
-
|
|
6495
|
-
class: "
|
|
6720
|
+
EditorView26.contentAttributes.of({
|
|
6721
|
+
class: "w-full !mr-[3rem]"
|
|
6496
6722
|
})
|
|
6497
6723
|
];
|
|
6498
6724
|
var decorations = () => [
|
|
6499
|
-
|
|
6725
|
+
ViewPlugin18.fromClass(class {
|
|
6500
6726
|
decorations = Decoration12.none;
|
|
6501
6727
|
constructor(view) {
|
|
6502
6728
|
this.updateDecorations(view.state, view);
|
|
@@ -6521,7 +6747,7 @@ var decorations = () => [
|
|
|
6521
6747
|
const lineTo = doc.lineAt(item.contentRange.to);
|
|
6522
6748
|
const isSelected = selection.includes(item.index) || item === current;
|
|
6523
6749
|
decorations2.push(Decoration12.line({
|
|
6524
|
-
class:
|
|
6750
|
+
class: mx6("cm-list-item", lineFrom.number === line.number && "cm-list-item-start", lineTo.number === line.number && "cm-list-item-end", isSelected && (hasFocus ? "cm-list-item-focused" : "cm-list-item-selected"))
|
|
6525
6751
|
}).range(line.from, line.from));
|
|
6526
6752
|
}
|
|
6527
6753
|
}
|
|
@@ -6531,7 +6757,7 @@ var decorations = () => [
|
|
|
6531
6757
|
decorations: (v) => v.decorations
|
|
6532
6758
|
}),
|
|
6533
6759
|
// Theme.
|
|
6534
|
-
|
|
6760
|
+
EditorView26.theme(Object.assign({
|
|
6535
6761
|
".cm-list-item": {
|
|
6536
6762
|
borderLeftWidth: "1px",
|
|
6537
6763
|
borderRightWidth: "1px",
|
|
@@ -6556,38 +6782,67 @@ var decorations = () => [
|
|
|
6556
6782
|
marginBottom: "2px"
|
|
6557
6783
|
},
|
|
6558
6784
|
".cm-list-item-focused": {
|
|
6559
|
-
borderColor: "var(--
|
|
6785
|
+
borderColor: "var(--color-neutral-focus-indicator)"
|
|
6560
6786
|
},
|
|
6561
6787
|
"&:focus-within .cm-list-item-selected": {
|
|
6562
|
-
borderColor: "var(--
|
|
6788
|
+
borderColor: "var(--color-separator)"
|
|
6563
6789
|
}
|
|
6564
6790
|
}))
|
|
6565
6791
|
];
|
|
6566
6792
|
|
|
6567
6793
|
// src/extensions/preview/preview.ts
|
|
6568
6794
|
import { syntaxTree as syntaxTree10 } from "@codemirror/language";
|
|
6569
|
-
import { RangeSetBuilder as RangeSetBuilder6, StateField as StateField11 } from "@codemirror/state";
|
|
6570
|
-
import { Decoration as Decoration13, EditorView as
|
|
6795
|
+
import { RangeSetBuilder as RangeSetBuilder6, StateEffect as StateEffect9, StateField as StateField11 } from "@codemirror/state";
|
|
6796
|
+
import { Decoration as Decoration13, EditorView as EditorView27, ViewPlugin as ViewPlugin19, WidgetType as WidgetType8 } from "@codemirror/view";
|
|
6797
|
+
import { DXN, Entity } from "@dxos/echo";
|
|
6798
|
+
var labelResolvedEffect = StateEffect9.define();
|
|
6571
6799
|
var preview = (options = {}) => {
|
|
6800
|
+
const viewRef = {
|
|
6801
|
+
current: void 0
|
|
6802
|
+
};
|
|
6572
6803
|
return [
|
|
6573
6804
|
// NOTE: Atomic block decorations must be created from a state field, now a widget, otherwise it results in the following error:
|
|
6574
6805
|
// "Block decorations may not be specified via plugins".
|
|
6575
6806
|
StateField11.define({
|
|
6576
|
-
create: (state) => buildDecorations3(state, options),
|
|
6807
|
+
create: (state) => buildDecorations3(state, options, viewRef),
|
|
6577
6808
|
update: (decorations2, tr) => {
|
|
6578
|
-
if (tr.docChanged) {
|
|
6579
|
-
return buildDecorations3(tr.state, options);
|
|
6809
|
+
if (tr.docChanged || tr.effects.some((effect) => effect.is(labelResolvedEffect))) {
|
|
6810
|
+
return buildDecorations3(tr.state, options, viewRef);
|
|
6580
6811
|
}
|
|
6581
6812
|
return decorations2.map(tr.changes);
|
|
6582
6813
|
},
|
|
6583
6814
|
provide: (field) => [
|
|
6584
|
-
|
|
6585
|
-
|
|
6815
|
+
EditorView27.decorations.from(field),
|
|
6816
|
+
EditorView27.atomicRanges.of((view) => view.state.field(field))
|
|
6586
6817
|
]
|
|
6818
|
+
}),
|
|
6819
|
+
ViewPlugin19.define((view) => {
|
|
6820
|
+
viewRef.current = view;
|
|
6821
|
+
return {
|
|
6822
|
+
destroy() {
|
|
6823
|
+
viewRef.current = void 0;
|
|
6824
|
+
}
|
|
6825
|
+
};
|
|
6587
6826
|
})
|
|
6588
6827
|
];
|
|
6589
6828
|
};
|
|
6590
|
-
var
|
|
6829
|
+
var resolveLabel = (db, dxnStr, viewRef) => {
|
|
6830
|
+
const dxn = DXN.tryParse(dxnStr);
|
|
6831
|
+
if (!dxn) {
|
|
6832
|
+
return;
|
|
6833
|
+
}
|
|
6834
|
+
const ref = db.makeRef(dxn);
|
|
6835
|
+
const target = ref.target;
|
|
6836
|
+
if (target) {
|
|
6837
|
+
return Entity.getLabel(target);
|
|
6838
|
+
}
|
|
6839
|
+
void ref.tryLoad().then(() => {
|
|
6840
|
+
viewRef.current?.dispatch({
|
|
6841
|
+
effects: labelResolvedEffect.of(void 0)
|
|
6842
|
+
});
|
|
6843
|
+
});
|
|
6844
|
+
};
|
|
6845
|
+
var buildDecorations3 = (state, options, viewRef) => {
|
|
6591
6846
|
const builder = new RangeSetBuilder6();
|
|
6592
6847
|
syntaxTree10(state).iterate({
|
|
6593
6848
|
enter: (node) => {
|
|
@@ -6599,8 +6854,13 @@ var buildDecorations3 = (state, options) => {
|
|
|
6599
6854
|
case "Link": {
|
|
6600
6855
|
const link = getLinkRef(state, node.node);
|
|
6601
6856
|
if (link) {
|
|
6857
|
+
const resolved = options.db ? resolveLabel(options.db, link.dxn, viewRef) : void 0;
|
|
6858
|
+
const displayLink = resolved ? {
|
|
6859
|
+
...link,
|
|
6860
|
+
label: resolved
|
|
6861
|
+
} : link;
|
|
6602
6862
|
builder.add(node.from, node.to, Decoration13.replace({
|
|
6603
|
-
widget: new PreviewInlineWidget(options,
|
|
6863
|
+
widget: new PreviewInlineWidget(options, displayLink),
|
|
6604
6864
|
side: 1
|
|
6605
6865
|
}));
|
|
6606
6866
|
}
|
|
@@ -6676,7 +6936,7 @@ var PreviewBlockWidget = class extends WidgetType8 {
|
|
|
6676
6936
|
}
|
|
6677
6937
|
toDOM(_view) {
|
|
6678
6938
|
const root = document.createElement("div");
|
|
6679
|
-
root.classList.add("cm-preview-block", "density-fine");
|
|
6939
|
+
root.classList.add("cm-preview-block", "dx-density-fine");
|
|
6680
6940
|
this._options.addBlockContainer?.({
|
|
6681
6941
|
link: this._link,
|
|
6682
6942
|
el: root
|
|
@@ -6692,7 +6952,7 @@ var PreviewBlockWidget = class extends WidgetType8 {
|
|
|
6692
6952
|
};
|
|
6693
6953
|
|
|
6694
6954
|
// src/extensions/replacer.ts
|
|
6695
|
-
import { EditorView as
|
|
6955
|
+
import { EditorView as EditorView28 } from "@codemirror/view";
|
|
6696
6956
|
var defaultReplacements = [
|
|
6697
6957
|
{
|
|
6698
6958
|
input: "--",
|
|
@@ -6755,7 +7015,7 @@ var replacer = ({ replacements = defaultReplacements } = {}) => {
|
|
|
6755
7015
|
const sortedReplacements = [
|
|
6756
7016
|
...replacements
|
|
6757
7017
|
].sort((a, b) => b.input.length - a.input.length);
|
|
6758
|
-
return
|
|
7018
|
+
return EditorView28.inputHandler.of((view, from, to, insert) => {
|
|
6759
7019
|
if (insert.length !== 1) {
|
|
6760
7020
|
return false;
|
|
6761
7021
|
}
|
|
@@ -6839,6 +7099,7 @@ var submit = ({ fireIfEmpty = false, onSubmit } = {}) => {
|
|
|
6839
7099
|
// src/extensions/tags/extended-markdown.ts
|
|
6840
7100
|
import { xmlLanguage } from "@codemirror/lang-xml";
|
|
6841
7101
|
import { parseMixed } from "@lezer/common";
|
|
7102
|
+
var escapeRegExpSource = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
6842
7103
|
var extendedMarkdown = ({ registry } = {}) => {
|
|
6843
7104
|
return [
|
|
6844
7105
|
createMarkdownExtensions({
|
|
@@ -6850,25 +7111,77 @@ var extendedMarkdown = ({ registry } = {}) => {
|
|
|
6850
7111
|
{
|
|
6851
7112
|
name: "SetextHeading",
|
|
6852
7113
|
parse: () => false
|
|
6853
|
-
}
|
|
7114
|
+
},
|
|
7115
|
+
// Custom XML block parser that keeps registered tags as a single HTMLBlock
|
|
7116
|
+
// even when their content contains blank lines.
|
|
7117
|
+
...xmlBlockParsers(registry)
|
|
6854
7118
|
]
|
|
6855
7119
|
}
|
|
6856
7120
|
]
|
|
6857
7121
|
})
|
|
6858
7122
|
];
|
|
6859
7123
|
};
|
|
6860
|
-
var
|
|
7124
|
+
var xmlBlockParsers = (registry) => {
|
|
6861
7125
|
const customTags = Object.keys(registry ?? {});
|
|
6862
|
-
|
|
6863
|
-
|
|
6864
|
-
|
|
6865
|
-
|
|
6866
|
-
|
|
6867
|
-
|
|
6868
|
-
|
|
6869
|
-
|
|
6870
|
-
|
|
6871
|
-
|
|
7126
|
+
if (customTags.length === 0) {
|
|
7127
|
+
return [];
|
|
7128
|
+
}
|
|
7129
|
+
const tagPattern = customTags.map(escapeRegExpSource).join("|");
|
|
7130
|
+
const selfClosePattern = new RegExp(`^\\s*<(${tagPattern})(\\s[^>]*)?\\/>\\s*$`);
|
|
7131
|
+
const openPattern = new RegExp(`^\\s*<(${tagPattern})(\\s[^>]*)?\\/?>`);
|
|
7132
|
+
return [
|
|
7133
|
+
{
|
|
7134
|
+
name: "XMLBlock",
|
|
7135
|
+
before: "HTMLBlock",
|
|
7136
|
+
parse: (cx, line) => {
|
|
7137
|
+
const match = openPattern.exec(line.text);
|
|
7138
|
+
if (!match) {
|
|
7139
|
+
return false;
|
|
7140
|
+
}
|
|
7141
|
+
if (selfClosePattern.test(line.text)) {
|
|
7142
|
+
const end2 = cx.lineStart + line.text.length;
|
|
7143
|
+
cx.addElement(cx.elt("HTMLBlock", cx.lineStart, end2));
|
|
7144
|
+
cx.nextLine();
|
|
7145
|
+
return true;
|
|
7146
|
+
}
|
|
7147
|
+
if (match[0].trimEnd().endsWith("/>")) {
|
|
7148
|
+
return false;
|
|
7149
|
+
}
|
|
7150
|
+
const tagName = match[1];
|
|
7151
|
+
const closeTag = `</${tagName}>`;
|
|
7152
|
+
const start = cx.lineStart;
|
|
7153
|
+
if (line.text.includes(closeTag)) {
|
|
7154
|
+
cx.addElement(cx.elt("HTMLBlock", start, start + line.text.length));
|
|
7155
|
+
cx.nextLine();
|
|
7156
|
+
return true;
|
|
7157
|
+
}
|
|
7158
|
+
let end = cx.lineStart + line.text.length;
|
|
7159
|
+
while (cx.nextLine()) {
|
|
7160
|
+
end = cx.lineStart + line.text.length;
|
|
7161
|
+
if (line.text.includes(closeTag)) {
|
|
7162
|
+
cx.addElement(cx.elt("HTMLBlock", start, end));
|
|
7163
|
+
cx.nextLine();
|
|
7164
|
+
return true;
|
|
7165
|
+
}
|
|
7166
|
+
}
|
|
7167
|
+
cx.addElement(cx.elt("HTMLBlock", start, end));
|
|
7168
|
+
return true;
|
|
7169
|
+
}
|
|
7170
|
+
}
|
|
7171
|
+
];
|
|
7172
|
+
};
|
|
7173
|
+
var mixedParser = (registry) => {
|
|
7174
|
+
const customTags = Object.keys(registry ?? {});
|
|
7175
|
+
const tagPattern = new RegExp(`<(${customTags.join("|")})`);
|
|
7176
|
+
return parseMixed((node, input) => {
|
|
7177
|
+
switch (node.name) {
|
|
7178
|
+
// Ignore XML inside of fenced and inline code.
|
|
7179
|
+
case "FencedCode":
|
|
7180
|
+
case "InlineCode": {
|
|
7181
|
+
return null;
|
|
7182
|
+
}
|
|
7183
|
+
// Parse multi-line HTML blocks.
|
|
7184
|
+
// case 'XMLBlock':
|
|
6872
7185
|
case "HTMLBlock": {
|
|
6873
7186
|
return {
|
|
6874
7187
|
parser: xmlLanguage.parser
|
|
@@ -6890,212 +7203,560 @@ var mixedParser = (registry) => {
|
|
|
6890
7203
|
});
|
|
6891
7204
|
};
|
|
6892
7205
|
|
|
6893
|
-
// src/extensions/tags/
|
|
6894
|
-
import { StateEffect as
|
|
6895
|
-
import { Decoration as Decoration14, EditorView as
|
|
6896
|
-
|
|
6897
|
-
|
|
6898
|
-
var
|
|
6899
|
-
var
|
|
6900
|
-
|
|
6901
|
-
|
|
6902
|
-
|
|
6903
|
-
|
|
6904
|
-
|
|
6905
|
-
|
|
6906
|
-
|
|
6907
|
-
|
|
6908
|
-
|
|
6909
|
-
|
|
7206
|
+
// src/extensions/tags/fader.ts
|
|
7207
|
+
import { StateEffect as StateEffect10, StateField as StateField12 } from "@codemirror/state";
|
|
7208
|
+
import { Decoration as Decoration14, EditorView as EditorView29, ViewPlugin as ViewPlugin20 } from "@codemirror/view";
|
|
7209
|
+
var DEFAULT_REMOVAL_DELAY = 5e3;
|
|
7210
|
+
var DEFAULT_COALESCE_WINDOW = 100;
|
|
7211
|
+
var CLEANUP_INTERVAL = 1e3;
|
|
7212
|
+
var fader = (options = {}) => {
|
|
7213
|
+
const removalDelay = DEFAULT_REMOVAL_DELAY;
|
|
7214
|
+
const coalesceWindow = options.coalesce ?? DEFAULT_COALESCE_WINDOW;
|
|
7215
|
+
let lastCount = -1;
|
|
7216
|
+
const log12 = (expiries) => {
|
|
7217
|
+
if (expiries.length !== lastCount) {
|
|
7218
|
+
lastCount = expiries.length;
|
|
7219
|
+
}
|
|
7220
|
+
};
|
|
7221
|
+
const dequeue = StateEffect10.define();
|
|
7222
|
+
const fadeField = StateField12.define({
|
|
7223
|
+
create: () => ({
|
|
7224
|
+
decorations: Decoration14.none,
|
|
7225
|
+
expiries: [],
|
|
7226
|
+
batchStart: 0
|
|
7227
|
+
}),
|
|
7228
|
+
update: ({ decorations: decorations2, expiries, batchStart }, tr) => {
|
|
6910
7229
|
for (const effect of tr.effects) {
|
|
6911
|
-
if (effect.is(
|
|
6912
|
-
|
|
7230
|
+
if (effect.is(dequeue)) {
|
|
7231
|
+
const now2 = effect.value;
|
|
7232
|
+
let removeCount = 0;
|
|
7233
|
+
while (removeCount < expiries.length && expiries[removeCount] <= now2) {
|
|
7234
|
+
removeCount++;
|
|
7235
|
+
}
|
|
7236
|
+
if (removeCount > 0) {
|
|
7237
|
+
expiries = expiries.slice(removeCount);
|
|
7238
|
+
let skipped = 0;
|
|
7239
|
+
decorations2 = decorations2.update({
|
|
7240
|
+
filter: () => {
|
|
7241
|
+
if (skipped < removeCount) {
|
|
7242
|
+
skipped++;
|
|
7243
|
+
return false;
|
|
7244
|
+
}
|
|
7245
|
+
return true;
|
|
7246
|
+
}
|
|
7247
|
+
});
|
|
7248
|
+
}
|
|
6913
7249
|
}
|
|
6914
7250
|
}
|
|
6915
|
-
if (tr.docChanged) {
|
|
6916
|
-
|
|
7251
|
+
if (!tr.docChanged) {
|
|
7252
|
+
log12(expiries);
|
|
7253
|
+
return {
|
|
7254
|
+
decorations: decorations2,
|
|
7255
|
+
expiries,
|
|
7256
|
+
batchStart
|
|
7257
|
+
};
|
|
6917
7258
|
}
|
|
6918
|
-
|
|
6919
|
-
|
|
7259
|
+
let isReset = tr.state.doc.length === 0;
|
|
7260
|
+
if (!isReset && tr.startState.doc.length > 0) {
|
|
7261
|
+
tr.changes.iterChanges((fromA, toA) => {
|
|
7262
|
+
if (fromA === 0 && toA === tr.startState.doc.length) {
|
|
7263
|
+
isReset = true;
|
|
7264
|
+
}
|
|
7265
|
+
});
|
|
7266
|
+
}
|
|
7267
|
+
if (isReset) {
|
|
7268
|
+
log12([]);
|
|
7269
|
+
return {
|
|
7270
|
+
decorations: Decoration14.none,
|
|
7271
|
+
expiries: [],
|
|
7272
|
+
batchStart: 0
|
|
7273
|
+
};
|
|
7274
|
+
}
|
|
7275
|
+
const now = Date.now();
|
|
7276
|
+
const add = [];
|
|
7277
|
+
tr.changes.iterChanges((fromA, toA, fromB, toB, inserted) => {
|
|
7278
|
+
if (toA === tr.startState.doc.length && inserted.length > 0) {
|
|
7279
|
+
add.push({
|
|
7280
|
+
from: fromB,
|
|
7281
|
+
to: toB
|
|
7282
|
+
});
|
|
7283
|
+
}
|
|
7284
|
+
});
|
|
7285
|
+
if (add.length > 0) {
|
|
7286
|
+
const canCoalesce = expiries.length > 0 && batchStart > 0 && now - batchStart < coalesceWindow;
|
|
7287
|
+
if (canCoalesce) {
|
|
7288
|
+
let lastFrom = -1;
|
|
7289
|
+
let lastTo = -1;
|
|
7290
|
+
decorations2.between(0, tr.state.doc.length, (from, to) => {
|
|
7291
|
+
lastFrom = from;
|
|
7292
|
+
lastTo = to;
|
|
7293
|
+
});
|
|
7294
|
+
if (lastFrom >= 0) {
|
|
7295
|
+
decorations2 = decorations2.update({
|
|
7296
|
+
filter: (from, to) => !(from === lastFrom && to === lastTo)
|
|
7297
|
+
});
|
|
7298
|
+
const mergedFrom = Math.min(lastFrom, add[0].from);
|
|
7299
|
+
const mergedTo = add[add.length - 1].to;
|
|
7300
|
+
decorations2 = decorations2.update({
|
|
7301
|
+
add: [
|
|
7302
|
+
Decoration14.mark({
|
|
7303
|
+
class: "cm-fader"
|
|
7304
|
+
}).range(mergedFrom, mergedTo)
|
|
7305
|
+
]
|
|
7306
|
+
});
|
|
7307
|
+
expiries = [
|
|
7308
|
+
...expiries.slice(0, -1),
|
|
7309
|
+
now + removalDelay
|
|
7310
|
+
];
|
|
7311
|
+
}
|
|
7312
|
+
} else {
|
|
7313
|
+
batchStart = now;
|
|
7314
|
+
expiries = [
|
|
7315
|
+
...expiries,
|
|
7316
|
+
now + removalDelay
|
|
7317
|
+
];
|
|
7318
|
+
decorations2 = decorations2.update({
|
|
7319
|
+
add: add.map(({ from, to }) => Decoration14.mark({
|
|
7320
|
+
class: "cm-fader"
|
|
7321
|
+
}).range(from, to))
|
|
7322
|
+
});
|
|
7323
|
+
}
|
|
7324
|
+
}
|
|
7325
|
+
log12(expiries);
|
|
7326
|
+
return {
|
|
7327
|
+
decorations: decorations2,
|
|
7328
|
+
expiries,
|
|
7329
|
+
batchStart
|
|
7330
|
+
};
|
|
7331
|
+
},
|
|
7332
|
+
provide: (f) => EditorView29.decorations.from(f, (value) => value.decorations)
|
|
6920
7333
|
});
|
|
6921
|
-
const
|
|
7334
|
+
const cleanup = ViewPlugin20.fromClass(class {
|
|
6922
7335
|
view;
|
|
6923
|
-
timer;
|
|
7336
|
+
#timer;
|
|
6924
7337
|
constructor(view) {
|
|
6925
7338
|
this.view = view;
|
|
7339
|
+
this.#schedule();
|
|
6926
7340
|
}
|
|
6927
|
-
update(
|
|
6928
|
-
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
6933
|
-
|
|
6934
|
-
|
|
7341
|
+
update() {
|
|
7342
|
+
this.#schedule();
|
|
7343
|
+
}
|
|
7344
|
+
#schedule() {
|
|
7345
|
+
const { expiries } = this.view.state.field(fadeField);
|
|
7346
|
+
if (expiries.length === 0) {
|
|
7347
|
+
clearTimeout(this.#timer);
|
|
7348
|
+
this.#timer = void 0;
|
|
7349
|
+
return;
|
|
6935
7350
|
}
|
|
7351
|
+
if (this.#timer !== void 0) {
|
|
7352
|
+
return;
|
|
7353
|
+
}
|
|
7354
|
+
const delay = Math.max(CLEANUP_INTERVAL, expiries[0] - Date.now());
|
|
7355
|
+
this.#timer = setTimeout(() => {
|
|
7356
|
+
this.#timer = void 0;
|
|
7357
|
+
this.view.dispatch({
|
|
7358
|
+
effects: dequeue.of(Date.now())
|
|
7359
|
+
});
|
|
7360
|
+
}, delay);
|
|
6936
7361
|
}
|
|
6937
7362
|
destroy() {
|
|
6938
|
-
clearTimeout(this
|
|
7363
|
+
clearTimeout(this.#timer);
|
|
6939
7364
|
}
|
|
6940
7365
|
});
|
|
6941
|
-
const cursorDecoration = StateField12.define({
|
|
6942
|
-
create: () => Decoration14.none,
|
|
6943
|
-
update: (_decorations, tr) => {
|
|
6944
|
-
const show = tr.state.field(showCursor);
|
|
6945
|
-
if (!show) {
|
|
6946
|
-
return Decoration14.none;
|
|
6947
|
-
}
|
|
6948
|
-
const endPos = tr.state.doc.length;
|
|
6949
|
-
return Decoration14.set([
|
|
6950
|
-
Decoration14.widget({
|
|
6951
|
-
widget: new CursorWidget(),
|
|
6952
|
-
side: 1
|
|
6953
|
-
}).range(endPos)
|
|
6954
|
-
]);
|
|
6955
|
-
},
|
|
6956
|
-
provide: (f) => EditorView28.decorations.from(f)
|
|
6957
|
-
});
|
|
6958
7366
|
return [
|
|
6959
|
-
|
|
6960
|
-
|
|
6961
|
-
|
|
7367
|
+
fadeField,
|
|
7368
|
+
cleanup,
|
|
7369
|
+
EditorView29.theme({
|
|
7370
|
+
".cm-fader": {
|
|
7371
|
+
animation: "fader 1s ease-out forwards"
|
|
7372
|
+
},
|
|
7373
|
+
"@keyframes fader": {
|
|
7374
|
+
"0%": {
|
|
7375
|
+
textShadow: "0 0 16px rgba(100, 200, 255, 1), 0 0 32px rgba(100, 200, 255, 0.6)"
|
|
7376
|
+
},
|
|
7377
|
+
"100%": {}
|
|
7378
|
+
}
|
|
7379
|
+
})
|
|
6962
7380
|
];
|
|
6963
7381
|
};
|
|
6964
|
-
|
|
6965
|
-
|
|
6966
|
-
|
|
6967
|
-
|
|
6968
|
-
|
|
6969
|
-
|
|
6970
|
-
|
|
6971
|
-
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
6975
|
-
const
|
|
6976
|
-
const
|
|
6977
|
-
const
|
|
6978
|
-
const
|
|
6979
|
-
|
|
6980
|
-
|
|
6981
|
-
|
|
6982
|
-
|
|
7382
|
+
|
|
7383
|
+
// src/extensions/tags/wire.ts
|
|
7384
|
+
import { Annotation as Annotation3, ChangeSet as ChangeSet2, EditorState as EditorState3, StateEffect as StateEffect11, StateField as StateField13 } from "@codemirror/state";
|
|
7385
|
+
import { Decoration as Decoration15, EditorView as EditorView30, ViewPlugin as ViewPlugin21, WidgetType as WidgetType9 } from "@codemirror/view";
|
|
7386
|
+
import { Domino as Domino3 } from "@dxos/ui";
|
|
7387
|
+
var wireBypass = Annotation3.define();
|
|
7388
|
+
var DEFAULT_RATE = 200;
|
|
7389
|
+
var CURSOR_LINGER = 3e3;
|
|
7390
|
+
var wire = (options = {}) => {
|
|
7391
|
+
const rate = options.rate ?? DEFAULT_RATE;
|
|
7392
|
+
const interval = 1e3 / rate;
|
|
7393
|
+
const streamingTags = options.streamingTags ?? /* @__PURE__ */ new Set();
|
|
7394
|
+
const suppressAppend = StateEffect11.define();
|
|
7395
|
+
const insertChunk = StateEffect11.define();
|
|
7396
|
+
const bufferField = StateField13.define({
|
|
7397
|
+
create: () => ({
|
|
7398
|
+
text: "",
|
|
7399
|
+
insertAt: 0
|
|
7400
|
+
}),
|
|
7401
|
+
update: (value, tr) => {
|
|
7402
|
+
let { text, insertAt } = value;
|
|
6983
7403
|
for (const effect of tr.effects) {
|
|
6984
|
-
if (effect.is(
|
|
6985
|
-
|
|
6986
|
-
|
|
6987
|
-
|
|
7404
|
+
if (effect.is(suppressAppend)) {
|
|
7405
|
+
text += effect.value.text;
|
|
7406
|
+
if (text.length === effect.value.text.length) {
|
|
7407
|
+
insertAt = effect.value.from;
|
|
7408
|
+
}
|
|
7409
|
+
}
|
|
7410
|
+
if (effect.is(insertChunk)) {
|
|
7411
|
+
text = text.slice(effect.value.text.length);
|
|
7412
|
+
insertAt = effect.value.from + effect.value.text.length;
|
|
7413
|
+
}
|
|
7414
|
+
}
|
|
7415
|
+
if (tr.docChanged) {
|
|
7416
|
+
let isReset = tr.state.doc.length === 0;
|
|
7417
|
+
if (!isReset && tr.startState.doc.length > 0) {
|
|
7418
|
+
tr.changes.iterChanges((fromA, toA) => {
|
|
7419
|
+
if (fromA === 0 && toA === tr.startState.doc.length) {
|
|
7420
|
+
isReset = true;
|
|
7421
|
+
}
|
|
6988
7422
|
});
|
|
6989
7423
|
}
|
|
7424
|
+
if (isReset) {
|
|
7425
|
+
return {
|
|
7426
|
+
text: "",
|
|
7427
|
+
insertAt: 0
|
|
7428
|
+
};
|
|
7429
|
+
}
|
|
7430
|
+
if (!tr.effects.some((effect) => effect.is(insertChunk))) {
|
|
7431
|
+
insertAt = tr.changes.mapPos(Math.min(insertAt, tr.startState.doc.length));
|
|
7432
|
+
}
|
|
6990
7433
|
}
|
|
6991
|
-
|
|
6992
|
-
|
|
7434
|
+
return {
|
|
7435
|
+
text,
|
|
7436
|
+
insertAt
|
|
7437
|
+
};
|
|
7438
|
+
}
|
|
7439
|
+
});
|
|
7440
|
+
const filter = EditorState3.transactionFilter.of((tr) => {
|
|
7441
|
+
if (!tr.docChanged) {
|
|
7442
|
+
return tr;
|
|
7443
|
+
}
|
|
7444
|
+
if (tr.annotation(wireBypass) || tr.effects.some((effect) => effect.is(insertChunk))) {
|
|
7445
|
+
return tr;
|
|
7446
|
+
}
|
|
7447
|
+
let appendedText = "";
|
|
7448
|
+
let appendFrom = -1;
|
|
7449
|
+
let isAppendOnly = true;
|
|
7450
|
+
tr.changes.iterChanges((fromA, toA, _fromB, _toB, inserted) => {
|
|
7451
|
+
if (toA === tr.startState.doc.length && fromA === toA && inserted.length > 0) {
|
|
7452
|
+
appendedText += inserted.sliceString(0);
|
|
7453
|
+
if (appendFrom === -1) {
|
|
7454
|
+
appendFrom = fromA;
|
|
7455
|
+
}
|
|
7456
|
+
} else {
|
|
7457
|
+
isAppendOnly = false;
|
|
6993
7458
|
}
|
|
6994
|
-
|
|
6995
|
-
|
|
6996
|
-
|
|
6997
|
-
|
|
6998
|
-
|
|
6999
|
-
|
|
7000
|
-
|
|
7459
|
+
});
|
|
7460
|
+
if (!isAppendOnly || appendedText.length === 0) {
|
|
7461
|
+
return tr;
|
|
7462
|
+
}
|
|
7463
|
+
return {
|
|
7464
|
+
changes: ChangeSet2.empty(tr.startState.doc.length),
|
|
7465
|
+
effects: suppressAppend.of({
|
|
7466
|
+
from: appendFrom,
|
|
7467
|
+
text: appendedText
|
|
7468
|
+
})
|
|
7469
|
+
};
|
|
7470
|
+
});
|
|
7471
|
+
const drainPlugin = ViewPlugin21.fromClass(class {
|
|
7472
|
+
view;
|
|
7473
|
+
#timer;
|
|
7474
|
+
#activeStreamTag = null;
|
|
7475
|
+
constructor(view) {
|
|
7476
|
+
this.view = view;
|
|
7477
|
+
this.#start();
|
|
7478
|
+
}
|
|
7479
|
+
update(update2) {
|
|
7480
|
+
const buffer = update2.state.field(bufferField);
|
|
7481
|
+
if (buffer.text.length === 0) {
|
|
7482
|
+
this.#activeStreamTag = null;
|
|
7001
7483
|
}
|
|
7002
|
-
if (
|
|
7003
|
-
|
|
7484
|
+
if (buffer.text.length > 0 && this.#timer === void 0) {
|
|
7485
|
+
this.#start();
|
|
7004
7486
|
}
|
|
7005
|
-
|
|
7006
|
-
|
|
7007
|
-
|
|
7487
|
+
}
|
|
7488
|
+
#start() {
|
|
7489
|
+
this.#timer = setInterval(() => {
|
|
7490
|
+
const { text, insertAt } = this.view.state.field(bufferField);
|
|
7491
|
+
if (text.length === 0) {
|
|
7492
|
+
clearInterval(this.#timer);
|
|
7493
|
+
this.#timer = void 0;
|
|
7008
7494
|
return;
|
|
7009
7495
|
}
|
|
7010
|
-
|
|
7011
|
-
|
|
7012
|
-
|
|
7013
|
-
}).range(fromB, toB));
|
|
7496
|
+
const result = flushable(text, streamingTags, this.#activeStreamTag);
|
|
7497
|
+
if (result.count === 0) {
|
|
7498
|
+
return;
|
|
7014
7499
|
}
|
|
7015
|
-
|
|
7016
|
-
|
|
7017
|
-
|
|
7018
|
-
|
|
7500
|
+
if (result.enterTag) {
|
|
7501
|
+
this.#activeStreamTag = result.enterTag;
|
|
7502
|
+
}
|
|
7503
|
+
if (result.exitTag) {
|
|
7504
|
+
this.#activeStreamTag = null;
|
|
7505
|
+
}
|
|
7506
|
+
const chunk = text.slice(0, result.count);
|
|
7507
|
+
this.view.dispatch({
|
|
7508
|
+
changes: {
|
|
7509
|
+
from: insertAt,
|
|
7510
|
+
insert: chunk
|
|
7511
|
+
},
|
|
7512
|
+
effects: insertChunk.of({
|
|
7513
|
+
from: insertAt,
|
|
7514
|
+
text: chunk
|
|
7515
|
+
})
|
|
7516
|
+
});
|
|
7517
|
+
}, interval);
|
|
7518
|
+
}
|
|
7519
|
+
destroy() {
|
|
7520
|
+
clearInterval(this.#timer);
|
|
7521
|
+
}
|
|
7522
|
+
});
|
|
7523
|
+
return [
|
|
7524
|
+
bufferField,
|
|
7525
|
+
filter,
|
|
7526
|
+
drainPlugin,
|
|
7527
|
+
options.cursor && wireCursor(bufferField)
|
|
7528
|
+
].filter(Boolean);
|
|
7529
|
+
};
|
|
7530
|
+
var wireCursor = (bufferField) => {
|
|
7531
|
+
const hideCursor = StateEffect11.define();
|
|
7532
|
+
const visibilityField = StateField13.define({
|
|
7533
|
+
create: () => ({
|
|
7534
|
+
visible: false,
|
|
7535
|
+
insertAt: 0,
|
|
7536
|
+
lastNonWsAt: 0
|
|
7537
|
+
}),
|
|
7538
|
+
update: (value, tr) => {
|
|
7539
|
+
const { text, insertAt } = tr.state.field(bufferField);
|
|
7540
|
+
if (text.length > 0) {
|
|
7541
|
+
let lastNonWsAt = tr.changes.mapPos(Math.min(value.lastNonWsAt, tr.startState.doc.length));
|
|
7542
|
+
if (tr.docChanged) {
|
|
7543
|
+
tr.changes.iterChanges((_fromA, _toA, _fromB, _toB, inserted) => {
|
|
7544
|
+
const chunk = inserted.sliceString(0);
|
|
7545
|
+
if (chunk.trim().length > 0) {
|
|
7546
|
+
lastNonWsAt = _fromB + chunk.length;
|
|
7547
|
+
}
|
|
7548
|
+
});
|
|
7549
|
+
}
|
|
7550
|
+
return {
|
|
7551
|
+
visible: true,
|
|
7552
|
+
insertAt,
|
|
7553
|
+
lastNonWsAt
|
|
7554
|
+
};
|
|
7555
|
+
}
|
|
7556
|
+
for (const effect of tr.effects) {
|
|
7557
|
+
if (effect.is(hideCursor)) {
|
|
7558
|
+
return {
|
|
7559
|
+
...value,
|
|
7560
|
+
visible: false
|
|
7561
|
+
};
|
|
7562
|
+
}
|
|
7563
|
+
}
|
|
7564
|
+
return value;
|
|
7565
|
+
}
|
|
7566
|
+
});
|
|
7567
|
+
const decorationField = StateField13.define({
|
|
7568
|
+
create: () => Decoration15.none,
|
|
7569
|
+
update: (_decorations, tr) => {
|
|
7570
|
+
const { visible, insertAt, lastNonWsAt } = tr.state.field(visibilityField);
|
|
7571
|
+
if (!visible) {
|
|
7572
|
+
return Decoration15.none;
|
|
7573
|
+
}
|
|
7574
|
+
const { text } = tr.state.field(bufferField);
|
|
7575
|
+
const cursorAt = text.length > 0 ? insertAt : lastNonWsAt;
|
|
7576
|
+
const pos = Math.min(cursorAt, tr.state.doc.length);
|
|
7577
|
+
return Decoration15.set([
|
|
7578
|
+
Decoration15.widget({
|
|
7579
|
+
widget: new CursorWidget(),
|
|
7580
|
+
side: 1
|
|
7581
|
+
}).range(pos)
|
|
7582
|
+
]);
|
|
7019
7583
|
},
|
|
7020
|
-
provide: (
|
|
7584
|
+
provide: (field) => EditorView30.decorations.from(field)
|
|
7021
7585
|
});
|
|
7022
|
-
const timerPlugin =
|
|
7586
|
+
const timerPlugin = ViewPlugin21.fromClass(class {
|
|
7023
7587
|
view;
|
|
7024
|
-
|
|
7025
|
-
_timers = /* @__PURE__ */ new Map();
|
|
7588
|
+
#timer;
|
|
7026
7589
|
constructor(view) {
|
|
7027
7590
|
this.view = view;
|
|
7028
7591
|
}
|
|
7029
7592
|
update(update2) {
|
|
7030
|
-
|
|
7031
|
-
|
|
7032
|
-
|
|
7033
|
-
|
|
7034
|
-
|
|
7035
|
-
|
|
7036
|
-
|
|
7037
|
-
const key = `${fromB}-${toB}`;
|
|
7038
|
-
if (this._timers.has(key)) {
|
|
7039
|
-
clearTimeout(this._timers.get(key));
|
|
7040
|
-
}
|
|
7041
|
-
const totalDelay = FADE_IN_DURATION + removalDelay;
|
|
7042
|
-
const id = setTimeout(() => {
|
|
7593
|
+
const { text } = update2.state.field(bufferField);
|
|
7594
|
+
const { visible } = update2.state.field(visibilityField);
|
|
7595
|
+
if (text.length > 0) {
|
|
7596
|
+
clearTimeout(this.#timer);
|
|
7597
|
+
this.#timer = void 0;
|
|
7598
|
+
} else if (visible && this.#timer === void 0) {
|
|
7599
|
+
this.#timer = setTimeout(() => {
|
|
7043
7600
|
this.view.dispatch({
|
|
7044
|
-
effects:
|
|
7045
|
-
from: fromB,
|
|
7046
|
-
to: toB
|
|
7047
|
-
})
|
|
7601
|
+
effects: hideCursor.of(null)
|
|
7048
7602
|
});
|
|
7049
|
-
this
|
|
7050
|
-
},
|
|
7051
|
-
|
|
7052
|
-
});
|
|
7603
|
+
this.#timer = void 0;
|
|
7604
|
+
}, CURSOR_LINGER);
|
|
7605
|
+
}
|
|
7053
7606
|
}
|
|
7054
7607
|
destroy() {
|
|
7055
|
-
|
|
7056
|
-
clearTimeout(id);
|
|
7057
|
-
}
|
|
7058
|
-
this._timers.clear();
|
|
7608
|
+
clearTimeout(this.#timer);
|
|
7059
7609
|
}
|
|
7060
7610
|
});
|
|
7061
7611
|
return [
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
7065
|
-
".cm-line > span": {
|
|
7066
|
-
opacity: "0.8"
|
|
7067
|
-
},
|
|
7068
|
-
".cm-fade-in": {
|
|
7069
|
-
animation: "fade-in 3s ease-out forwards"
|
|
7070
|
-
},
|
|
7071
|
-
"@keyframes fade-in": {
|
|
7072
|
-
"0%": {
|
|
7073
|
-
opacity: "0"
|
|
7074
|
-
},
|
|
7075
|
-
"80%": {
|
|
7076
|
-
opacity: "1"
|
|
7077
|
-
},
|
|
7078
|
-
"100%": {
|
|
7079
|
-
opacity: "0.8"
|
|
7080
|
-
}
|
|
7081
|
-
}
|
|
7082
|
-
})
|
|
7612
|
+
visibilityField,
|
|
7613
|
+
decorationField,
|
|
7614
|
+
timerPlugin
|
|
7083
7615
|
];
|
|
7084
7616
|
};
|
|
7617
|
+
var CursorWidget = class extends WidgetType9 {
|
|
7618
|
+
toDOM() {
|
|
7619
|
+
const inner = Domino3.of("span").text("\u2217").style({
|
|
7620
|
+
animation: "blink 1s infinite",
|
|
7621
|
+
animationDelay: "250ms"
|
|
7622
|
+
});
|
|
7623
|
+
return Domino3.of("span").style({
|
|
7624
|
+
opacity: "0.8"
|
|
7625
|
+
}).append(inner).root;
|
|
7626
|
+
}
|
|
7627
|
+
};
|
|
7628
|
+
var OPENING_TAG_NAME = /^<([a-zA-Z][\w-]*)/;
|
|
7629
|
+
var escapeRegExpSource2 = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
7630
|
+
var flushable = (buffer, streamingTags, activeStreamTag) => {
|
|
7631
|
+
if (buffer.length === 0) {
|
|
7632
|
+
return {
|
|
7633
|
+
count: 0
|
|
7634
|
+
};
|
|
7635
|
+
}
|
|
7636
|
+
if (activeStreamTag) {
|
|
7637
|
+
const closeTag = `</${activeStreamTag}>`;
|
|
7638
|
+
if (buffer.startsWith(closeTag)) {
|
|
7639
|
+
return {
|
|
7640
|
+
count: closeTag.length,
|
|
7641
|
+
exitTag: true
|
|
7642
|
+
};
|
|
7643
|
+
}
|
|
7644
|
+
if (buffer[0] === "<") {
|
|
7645
|
+
return {
|
|
7646
|
+
count: xmlElementLength(buffer)
|
|
7647
|
+
};
|
|
7648
|
+
}
|
|
7649
|
+
return {
|
|
7650
|
+
count: 1
|
|
7651
|
+
};
|
|
7652
|
+
}
|
|
7653
|
+
const ch = buffer[0];
|
|
7654
|
+
if (ch === "<") {
|
|
7655
|
+
const nameMatch = buffer.match(OPENING_TAG_NAME);
|
|
7656
|
+
if (nameMatch && streamingTags.has(nameMatch[1])) {
|
|
7657
|
+
const close = buffer.indexOf(">");
|
|
7658
|
+
if (close === -1) {
|
|
7659
|
+
return {
|
|
7660
|
+
count: 0
|
|
7661
|
+
};
|
|
7662
|
+
}
|
|
7663
|
+
if (buffer[close - 1] === "/") {
|
|
7664
|
+
return {
|
|
7665
|
+
count: close + 1
|
|
7666
|
+
};
|
|
7667
|
+
}
|
|
7668
|
+
return {
|
|
7669
|
+
count: close + 1,
|
|
7670
|
+
enterTag: nameMatch[1]
|
|
7671
|
+
};
|
|
7672
|
+
}
|
|
7673
|
+
return {
|
|
7674
|
+
count: xmlElementLength(buffer)
|
|
7675
|
+
};
|
|
7676
|
+
}
|
|
7677
|
+
if (ch === "!" && buffer.length > 1 && buffer[1] === "[") {
|
|
7678
|
+
return {
|
|
7679
|
+
count: linkLength(buffer, 1)
|
|
7680
|
+
};
|
|
7681
|
+
}
|
|
7682
|
+
if (ch === "[") {
|
|
7683
|
+
return {
|
|
7684
|
+
count: linkLength(buffer, 0)
|
|
7685
|
+
};
|
|
7686
|
+
}
|
|
7687
|
+
return {
|
|
7688
|
+
count: 1
|
|
7689
|
+
};
|
|
7690
|
+
};
|
|
7691
|
+
var xmlElementLength = (buffer) => {
|
|
7692
|
+
const close = buffer.indexOf(">");
|
|
7693
|
+
if (close === -1) {
|
|
7694
|
+
return 0;
|
|
7695
|
+
}
|
|
7696
|
+
if (buffer[close - 1] === "/") {
|
|
7697
|
+
return close + 1;
|
|
7698
|
+
}
|
|
7699
|
+
if (buffer[1] === "/") {
|
|
7700
|
+
return close + 1;
|
|
7701
|
+
}
|
|
7702
|
+
const nameMatch = buffer.match(OPENING_TAG_NAME);
|
|
7703
|
+
if (!nameMatch) {
|
|
7704
|
+
return 1;
|
|
7705
|
+
}
|
|
7706
|
+
const tagName = nameMatch[1];
|
|
7707
|
+
let depth = 0;
|
|
7708
|
+
const tagPattern = new RegExp(`<(/?)${escapeRegExpSource2(tagName)}(\\s[^>]*)?>`, "g");
|
|
7709
|
+
let match;
|
|
7710
|
+
while ((match = tagPattern.exec(buffer)) !== null) {
|
|
7711
|
+
const isSelfClosing = match[0].endsWith("/>");
|
|
7712
|
+
const isClosing = match[1] === "/";
|
|
7713
|
+
if (isSelfClosing) {
|
|
7714
|
+
if (depth === 0) {
|
|
7715
|
+
return match.index + match[0].length;
|
|
7716
|
+
}
|
|
7717
|
+
} else if (isClosing) {
|
|
7718
|
+
depth--;
|
|
7719
|
+
if (depth === 0) {
|
|
7720
|
+
return match.index + match[0].length;
|
|
7721
|
+
}
|
|
7722
|
+
} else {
|
|
7723
|
+
depth++;
|
|
7724
|
+
}
|
|
7725
|
+
}
|
|
7726
|
+
return 0;
|
|
7727
|
+
};
|
|
7728
|
+
var linkLength = (buffer, offset) => {
|
|
7729
|
+
const bracketClose = buffer.indexOf("]", offset + 1);
|
|
7730
|
+
if (bracketClose === -1) {
|
|
7731
|
+
return 0;
|
|
7732
|
+
}
|
|
7733
|
+
if (bracketClose + 1 >= buffer.length) {
|
|
7734
|
+
return 0;
|
|
7735
|
+
}
|
|
7736
|
+
if (buffer[bracketClose + 1] !== "(") {
|
|
7737
|
+
return 1;
|
|
7738
|
+
}
|
|
7739
|
+
const parenClose = buffer.indexOf(")", bracketClose + 2);
|
|
7740
|
+
if (parenClose === -1) {
|
|
7741
|
+
return 0;
|
|
7742
|
+
}
|
|
7743
|
+
return parenClose + 1;
|
|
7744
|
+
};
|
|
7085
7745
|
|
|
7086
7746
|
// src/extensions/tags/xml-tags.ts
|
|
7087
7747
|
import { syntaxTree as syntaxTree11 } from "@codemirror/language";
|
|
7088
|
-
import { Prec as Prec7, RangeSetBuilder as RangeSetBuilder7, StateEffect as
|
|
7089
|
-
import { Decoration as
|
|
7748
|
+
import { Prec as Prec7, RangeSetBuilder as RangeSetBuilder7, StateEffect as StateEffect12, StateField as StateField14 } from "@codemirror/state";
|
|
7749
|
+
import { Decoration as Decoration16, EditorView as EditorView31, ViewPlugin as ViewPlugin22, WidgetType as WidgetType10, keymap as keymap13 } from "@codemirror/view";
|
|
7090
7750
|
import { invariant as invariant7 } from "@dxos/invariant";
|
|
7091
|
-
import { log as
|
|
7751
|
+
import { log as log11 } from "@dxos/log";
|
|
7752
|
+
import { Domino as Domino4 } from "@dxos/ui";
|
|
7092
7753
|
|
|
7093
7754
|
// src/extensions/tags/xml-util.ts
|
|
7094
7755
|
import { invariant as invariant6 } from "@dxos/invariant";
|
|
7095
|
-
var
|
|
7756
|
+
var __dxlog_file16 = "/__w/dxos/dxos/packages/ui/ui-editor/src/extensions/tags/xml-util.ts";
|
|
7096
7757
|
var nodeToJson = (state, node) => {
|
|
7097
7758
|
invariant6(node.type.name === "Element", "Node is not an Element", {
|
|
7098
|
-
F:
|
|
7759
|
+
F: __dxlog_file16,
|
|
7099
7760
|
L: 18,
|
|
7100
7761
|
S: void 0,
|
|
7101
7762
|
A: [
|
|
@@ -7159,17 +7820,19 @@ var nodeToJson = (state, node) => {
|
|
|
7159
7820
|
};
|
|
7160
7821
|
|
|
7161
7822
|
// src/extensions/tags/xml-tags.ts
|
|
7162
|
-
var
|
|
7163
|
-
var navigatePreviousEffect =
|
|
7164
|
-
var navigateNextEffect =
|
|
7823
|
+
var __dxlog_file17 = "/__w/dxos/dxos/packages/ui/ui-editor/src/extensions/tags/xml-tags.ts";
|
|
7824
|
+
var navigatePreviousEffect = StateEffect12.define();
|
|
7825
|
+
var navigateNextEffect = StateEffect12.define();
|
|
7165
7826
|
var getXmlTextChild = (children) => {
|
|
7166
7827
|
const child = children?.[0];
|
|
7167
7828
|
return typeof child === "string" ? child : null;
|
|
7168
7829
|
};
|
|
7169
|
-
var
|
|
7170
|
-
var
|
|
7171
|
-
var
|
|
7172
|
-
var
|
|
7830
|
+
var xmlWidgetId = (explicit, fallback) => typeof explicit === "string" && explicit.length > 0 ? explicit : fallback;
|
|
7831
|
+
var escapeRegExpSource3 = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
7832
|
+
var xmlTagContextEffect = StateEffect12.define();
|
|
7833
|
+
var xmlTagResetEffect = StateEffect12.define();
|
|
7834
|
+
var xmlTagUpdateEffect = StateEffect12.define();
|
|
7835
|
+
var widgetContextStateField = StateField14.define({
|
|
7173
7836
|
create: () => void 0,
|
|
7174
7837
|
update: (value, tr) => {
|
|
7175
7838
|
for (const effect of tr.effects) {
|
|
@@ -7180,7 +7843,7 @@ var widgetContextStateField = StateField13.define({
|
|
|
7180
7843
|
return value;
|
|
7181
7844
|
}
|
|
7182
7845
|
});
|
|
7183
|
-
var widgetStateMapStateField =
|
|
7846
|
+
var widgetStateMapStateField = StateField14.define({
|
|
7184
7847
|
create: () => ({}),
|
|
7185
7848
|
update: (map, tr) => {
|
|
7186
7849
|
for (const effect of tr.effects) {
|
|
@@ -7189,12 +7852,12 @@ var widgetStateMapStateField = StateField13.define({
|
|
|
7189
7852
|
}
|
|
7190
7853
|
if (effect.is(xmlTagUpdateEffect)) {
|
|
7191
7854
|
const { id, value } = effect.value;
|
|
7192
|
-
|
|
7855
|
+
log11("widget updated", {
|
|
7193
7856
|
id,
|
|
7194
7857
|
value
|
|
7195
7858
|
}, {
|
|
7196
|
-
F:
|
|
7197
|
-
L:
|
|
7859
|
+
F: __dxlog_file17,
|
|
7860
|
+
L: 184,
|
|
7198
7861
|
S: void 0,
|
|
7199
7862
|
C: (f, a) => f(...a)
|
|
7200
7863
|
});
|
|
@@ -7208,28 +7871,37 @@ var widgetStateMapStateField = StateField13.define({
|
|
|
7208
7871
|
return map;
|
|
7209
7872
|
}
|
|
7210
7873
|
});
|
|
7211
|
-
var
|
|
7874
|
+
var XML_WIDGET_DATA_ATTR = "data-xml-widget";
|
|
7875
|
+
var xmlTags = ({ registry, setWidgets, bookmarks: bookmarks2, paragraphToWidgetGapRem } = {}) => {
|
|
7212
7876
|
const notifier = createWidgetMap(setWidgets);
|
|
7213
7877
|
const widgetDecorationsField = createWidgetDecorationsField(registry, notifier);
|
|
7878
|
+
const paragraphGapTheme = paragraphToWidgetGapRem != null && paragraphToWidgetGapRem > 0 ? EditorView31.baseTheme({
|
|
7879
|
+
[`& .cm-content > .cm-line:not(:has([${XML_WIDGET_DATA_ATTR}])) + .cm-line:has([${XML_WIDGET_DATA_ATTR}])`]: {
|
|
7880
|
+
marginTop: `${paragraphToWidgetGapRem}rem`
|
|
7881
|
+
}
|
|
7882
|
+
}) : null;
|
|
7214
7883
|
return [
|
|
7215
7884
|
widgetContextStateField,
|
|
7216
7885
|
widgetStateMapStateField,
|
|
7217
7886
|
widgetDecorationsField,
|
|
7218
7887
|
createWidgetUpdatePlugin(widgetDecorationsField, notifier),
|
|
7219
7888
|
createNavigationEffectPlugin(widgetDecorationsField, bookmarks2),
|
|
7220
|
-
bookmarks2?.length ? Prec7.highest(keyHandlers) : []
|
|
7889
|
+
bookmarks2?.length ? Prec7.highest(keyHandlers) : [],
|
|
7890
|
+
...paragraphGapTheme ? [
|
|
7891
|
+
paragraphGapTheme
|
|
7892
|
+
] : []
|
|
7221
7893
|
];
|
|
7222
7894
|
};
|
|
7223
7895
|
var createWidgetMap = (setWidgets) => {
|
|
7224
7896
|
const widgets = /* @__PURE__ */ new Map();
|
|
7225
7897
|
const notifier = {
|
|
7226
7898
|
mounted: (state) => {
|
|
7227
|
-
|
|
7899
|
+
log11("widget mounted", {
|
|
7228
7900
|
id: state.id,
|
|
7229
7901
|
tag: state.props._tag
|
|
7230
7902
|
}, {
|
|
7231
|
-
F:
|
|
7232
|
-
L:
|
|
7903
|
+
F: __dxlog_file17,
|
|
7904
|
+
L: 261,
|
|
7233
7905
|
S: void 0,
|
|
7234
7906
|
C: (f, a) => f(...a)
|
|
7235
7907
|
});
|
|
@@ -7240,12 +7912,12 @@ var createWidgetMap = (setWidgets) => {
|
|
|
7240
7912
|
},
|
|
7241
7913
|
unmounted: (id) => {
|
|
7242
7914
|
const state = widgets.get(id);
|
|
7243
|
-
|
|
7915
|
+
log11("widget unmounted", {
|
|
7244
7916
|
id,
|
|
7245
7917
|
tag: state?.props._tag
|
|
7246
7918
|
}, {
|
|
7247
|
-
F:
|
|
7248
|
-
L:
|
|
7919
|
+
F: __dxlog_file17,
|
|
7920
|
+
L: 267,
|
|
7249
7921
|
S: void 0,
|
|
7250
7922
|
C: (f, a) => f(...a)
|
|
7251
7923
|
});
|
|
@@ -7278,7 +7950,7 @@ var keyHandlers = keymap13.of([
|
|
|
7278
7950
|
}
|
|
7279
7951
|
]);
|
|
7280
7952
|
var createNavigationEffectPlugin = (widgetDecorationsField, bookmarks2) => {
|
|
7281
|
-
return
|
|
7953
|
+
return EditorView31.updateListener.of((update2) => {
|
|
7282
7954
|
update2.transactions.forEach((transaction) => {
|
|
7283
7955
|
for (const effect of transaction.effects) {
|
|
7284
7956
|
if (effect.is(navigatePreviousEffect)) {
|
|
@@ -7306,11 +7978,9 @@ var createNavigationEffectPlugin = (widgetDecorationsField, bookmarks2) => {
|
|
|
7306
7978
|
anchor: line.from,
|
|
7307
7979
|
head: line.from
|
|
7308
7980
|
},
|
|
7309
|
-
effects:
|
|
7310
|
-
line: line.number,
|
|
7311
|
-
|
|
7312
|
-
offset: -16
|
|
7313
|
-
}
|
|
7981
|
+
effects: scrollerLineEffect.of({
|
|
7982
|
+
line: line.number - 1,
|
|
7983
|
+
offset: -16
|
|
7314
7984
|
})
|
|
7315
7985
|
});
|
|
7316
7986
|
continue;
|
|
@@ -7341,11 +8011,9 @@ var createNavigationEffectPlugin = (widgetDecorationsField, bookmarks2) => {
|
|
|
7341
8011
|
anchor: line.to,
|
|
7342
8012
|
head: line.to
|
|
7343
8013
|
},
|
|
7344
|
-
effects:
|
|
7345
|
-
line: line.number,
|
|
7346
|
-
|
|
7347
|
-
offset: -16
|
|
7348
|
-
}
|
|
8014
|
+
effects: scrollerLineEffect.of({
|
|
8015
|
+
line: line.number - 1,
|
|
8016
|
+
offset: -16
|
|
7349
8017
|
})
|
|
7350
8018
|
});
|
|
7351
8019
|
} else {
|
|
@@ -7355,11 +8023,9 @@ var createNavigationEffectPlugin = (widgetDecorationsField, bookmarks2) => {
|
|
|
7355
8023
|
anchor: line.to,
|
|
7356
8024
|
head: line.to
|
|
7357
8025
|
},
|
|
7358
|
-
effects:
|
|
7359
|
-
line: line.number,
|
|
7360
|
-
|
|
7361
|
-
position: "end"
|
|
7362
|
-
}
|
|
8026
|
+
effects: scrollerLineEffect.of({
|
|
8027
|
+
line: line.number - 1,
|
|
8028
|
+
position: "end"
|
|
7363
8029
|
})
|
|
7364
8030
|
});
|
|
7365
8031
|
}
|
|
@@ -7369,7 +8035,7 @@ var createNavigationEffectPlugin = (widgetDecorationsField, bookmarks2) => {
|
|
|
7369
8035
|
});
|
|
7370
8036
|
});
|
|
7371
8037
|
};
|
|
7372
|
-
var createWidgetUpdatePlugin = (widgetDecorationsField, notifier) =>
|
|
8038
|
+
var createWidgetUpdatePlugin = (widgetDecorationsField, notifier) => ViewPlugin22.fromClass(class {
|
|
7373
8039
|
update(update2) {
|
|
7374
8040
|
const widgetStateMap = update2.state.field(widgetStateMapStateField);
|
|
7375
8041
|
const { decorations: decorations2 } = update2.state.field(widgetDecorationsField);
|
|
@@ -7396,19 +8062,25 @@ var createWidgetUpdatePlugin = (widgetDecorationsField, notifier) => ViewPlugin1
|
|
|
7396
8062
|
}
|
|
7397
8063
|
}
|
|
7398
8064
|
});
|
|
7399
|
-
var createWidgetDecorationsField = (registry = {}, notifier) =>
|
|
8065
|
+
var createWidgetDecorationsField = (registry = {}, notifier) => StateField14.define({
|
|
7400
8066
|
create: (state) => {
|
|
7401
8067
|
return buildDecorations4(state, {
|
|
7402
8068
|
from: 0,
|
|
7403
8069
|
to: state.doc.length
|
|
7404
8070
|
}, registry, notifier);
|
|
7405
8071
|
},
|
|
7406
|
-
update: ({ from, decorations: decorations2 }, tr) => {
|
|
8072
|
+
update: ({ from, streamingFrom, decorations: decorations2 }, tr) => {
|
|
7407
8073
|
for (const effect of tr.effects) {
|
|
7408
8074
|
if (effect.is(xmlTagResetEffect)) {
|
|
8075
|
+
if (tr.docChanged) {
|
|
8076
|
+
return buildDecorations4(tr.state, {
|
|
8077
|
+
from: 0,
|
|
8078
|
+
to: tr.state.doc.length
|
|
8079
|
+
}, registry, notifier);
|
|
8080
|
+
}
|
|
7409
8081
|
return {
|
|
7410
8082
|
from: 0,
|
|
7411
|
-
decorations:
|
|
8083
|
+
decorations: Decoration16.none
|
|
7412
8084
|
};
|
|
7413
8085
|
}
|
|
7414
8086
|
}
|
|
@@ -7416,12 +8088,12 @@ var createWidgetDecorationsField = (registry = {}, notifier) => StateField13.def
|
|
|
7416
8088
|
const { state } = tr;
|
|
7417
8089
|
const reset = tr.changes.touchesRange(0, from);
|
|
7418
8090
|
if (reset) {
|
|
7419
|
-
|
|
8091
|
+
log11("document reset", {
|
|
7420
8092
|
from,
|
|
7421
8093
|
to: state.doc.length
|
|
7422
8094
|
}, {
|
|
7423
|
-
F:
|
|
7424
|
-
L:
|
|
8095
|
+
F: __dxlog_file17,
|
|
8096
|
+
L: 429,
|
|
7425
8097
|
S: void 0,
|
|
7426
8098
|
C: (f, a) => f(...a)
|
|
7427
8099
|
});
|
|
@@ -7430,13 +8102,17 @@ var createWidgetDecorationsField = (registry = {}, notifier) => StateField13.def
|
|
|
7430
8102
|
to: state.doc.length
|
|
7431
8103
|
}, registry, notifier);
|
|
7432
8104
|
} else {
|
|
8105
|
+
const rebuildFrom = streamingFrom ?? from;
|
|
7433
8106
|
const result = buildDecorations4(state, {
|
|
7434
|
-
from,
|
|
8107
|
+
from: rebuildFrom,
|
|
7435
8108
|
to: state.doc.length
|
|
7436
8109
|
}, registry, notifier);
|
|
7437
8110
|
return {
|
|
7438
8111
|
from: result.from,
|
|
8112
|
+
streamingFrom: result.streamingFrom,
|
|
7439
8113
|
decorations: decorations2.update({
|
|
8114
|
+
// Remove old streaming decorations — they are rebuilt each tick.
|
|
8115
|
+
filter: (_f, _t, deco) => !deco.spec.streaming,
|
|
7440
8116
|
add: decorationSetToArray(result.decorations)
|
|
7441
8117
|
})
|
|
7442
8118
|
};
|
|
@@ -7444,12 +8120,13 @@ var createWidgetDecorationsField = (registry = {}, notifier) => StateField13.def
|
|
|
7444
8120
|
}
|
|
7445
8121
|
return {
|
|
7446
8122
|
from,
|
|
8123
|
+
streamingFrom,
|
|
7447
8124
|
decorations: decorations2
|
|
7448
8125
|
};
|
|
7449
8126
|
},
|
|
7450
8127
|
provide: (field) => [
|
|
7451
|
-
|
|
7452
|
-
|
|
8128
|
+
EditorView31.decorations.from(field, (v) => v.decorations),
|
|
8129
|
+
EditorView31.atomicRanges.of((view) => view.state.field(field).decorations || Decoration16.none)
|
|
7453
8130
|
]
|
|
7454
8131
|
});
|
|
7455
8132
|
var buildDecorations4 = (state, range, registry, notifier) => {
|
|
@@ -7460,10 +8137,11 @@ var buildDecorations4 = (state, range, registry, notifier) => {
|
|
|
7460
8137
|
if (!tree || tree.type.name === "Program" && tree.length === 0) {
|
|
7461
8138
|
return {
|
|
7462
8139
|
from: range.from,
|
|
7463
|
-
decorations:
|
|
8140
|
+
decorations: Decoration16.none
|
|
7464
8141
|
};
|
|
7465
8142
|
}
|
|
7466
8143
|
let last = range.from;
|
|
8144
|
+
let streamingFrom;
|
|
7467
8145
|
tree.iterate({
|
|
7468
8146
|
from: range.from,
|
|
7469
8147
|
to: range.to,
|
|
@@ -7476,21 +8154,26 @@ var buildDecorations4 = (state, range, registry, notifier) => {
|
|
|
7476
8154
|
if (args) {
|
|
7477
8155
|
const def = registry[args._tag];
|
|
7478
8156
|
if (def) {
|
|
8157
|
+
if (def.streaming && !node.node.getChild("CloseTag")) {
|
|
8158
|
+
return false;
|
|
8159
|
+
}
|
|
7479
8160
|
const { block, factory, Component } = def;
|
|
7480
|
-
const widgetState = args.id ? widgetStateMap[args.id] : void 0;
|
|
7481
8161
|
const nodeRange = {
|
|
7482
8162
|
from: node.node.from,
|
|
7483
8163
|
to: node.node.to
|
|
7484
8164
|
};
|
|
8165
|
+
const widgetId = xmlWidgetId(args.id, def.streaming ? `cm-xml-${nodeRange.from}` : `cm-xml-${nodeRange.from}-${nodeRange.to}`);
|
|
8166
|
+
const widgetState = widgetStateMap[widgetId];
|
|
7485
8167
|
const props = {
|
|
7486
|
-
|
|
8168
|
+
id: widgetId,
|
|
7487
8169
|
range: nodeRange,
|
|
8170
|
+
context,
|
|
7488
8171
|
...args,
|
|
7489
8172
|
...widgetState
|
|
7490
8173
|
};
|
|
7491
|
-
const widget = factory ? factory(props) : Component ?
|
|
8174
|
+
const widget = factory ? factory(props) ?? void 0 : Component ? new PlaceholderWidget2(widgetId, Component, props, notifier) : void 0;
|
|
7492
8175
|
if (widget) {
|
|
7493
|
-
builder.add(nodeRange.from, nodeRange.to,
|
|
8176
|
+
builder.add(nodeRange.from, nodeRange.to, Decoration16.replace({
|
|
7494
8177
|
widget,
|
|
7495
8178
|
block,
|
|
7496
8179
|
atomic: true,
|
|
@@ -7502,9 +8185,9 @@ var buildDecorations4 = (state, range, registry, notifier) => {
|
|
|
7502
8185
|
}
|
|
7503
8186
|
}
|
|
7504
8187
|
} catch (err) {
|
|
7505
|
-
|
|
7506
|
-
F:
|
|
7507
|
-
L:
|
|
8188
|
+
log11.catch(err, void 0, {
|
|
8189
|
+
F: __dxlog_file17,
|
|
8190
|
+
L: 538,
|
|
7508
8191
|
S: void 0,
|
|
7509
8192
|
C: (f, a) => f(...a)
|
|
7510
8193
|
});
|
|
@@ -7514,8 +8197,65 @@ var buildDecorations4 = (state, range, registry, notifier) => {
|
|
|
7514
8197
|
}
|
|
7515
8198
|
}
|
|
7516
8199
|
});
|
|
8200
|
+
const streamingTagNames = Object.entries(registry).filter(([, def]) => def.streaming).map(([name]) => name).sort((a, b) => b.length - a.length);
|
|
8201
|
+
if (streamingTagNames.length > 0) {
|
|
8202
|
+
const tailText = state.sliceDoc(range.from, range.to);
|
|
8203
|
+
const streamingPattern = streamingTagNames.map(escapeRegExpSource3).join("|");
|
|
8204
|
+
const tagPattern = new RegExp(`<(${streamingPattern})(\\s[^>]*)?>`, "g");
|
|
8205
|
+
let match;
|
|
8206
|
+
while ((match = tagPattern.exec(tailText)) !== null) {
|
|
8207
|
+
const tagName = match[1];
|
|
8208
|
+
const closeTag = `</${tagName}>`;
|
|
8209
|
+
const afterOpen = match.index + match[0].length;
|
|
8210
|
+
if (tailText.indexOf(closeTag, afterOpen) === -1) {
|
|
8211
|
+
const absoluteFrom = range.from + match.index;
|
|
8212
|
+
const contentFrom = range.from + afterOpen;
|
|
8213
|
+
const innerText = state.sliceDoc(contentFrom, range.to).trim();
|
|
8214
|
+
const def = registry[tagName];
|
|
8215
|
+
const props = {
|
|
8216
|
+
_tag: tagName,
|
|
8217
|
+
context,
|
|
8218
|
+
range: {
|
|
8219
|
+
from: absoluteFrom,
|
|
8220
|
+
to: range.to
|
|
8221
|
+
},
|
|
8222
|
+
children: innerText ? [
|
|
8223
|
+
innerText
|
|
8224
|
+
] : void 0
|
|
8225
|
+
};
|
|
8226
|
+
const attrPattern = /(\w+)="([^"]*)"/g;
|
|
8227
|
+
let attrMatch;
|
|
8228
|
+
while ((attrMatch = attrPattern.exec(match[0])) !== null) {
|
|
8229
|
+
props[attrMatch[1]] = attrMatch[2];
|
|
8230
|
+
}
|
|
8231
|
+
const widgetId = xmlWidgetId(props.id, `cm-xml-${absoluteFrom}`);
|
|
8232
|
+
const widgetState = widgetStateMap[widgetId];
|
|
8233
|
+
const mergedProps = {
|
|
8234
|
+
...props,
|
|
8235
|
+
id: widgetId,
|
|
8236
|
+
...widgetState
|
|
8237
|
+
};
|
|
8238
|
+
const widget = def.factory ? def.factory(mergedProps) ?? void 0 : def.Component ? new PlaceholderWidget2(widgetId, def.Component, mergedProps, notifier, true) : void 0;
|
|
8239
|
+
if (widget) {
|
|
8240
|
+
builder.add(absoluteFrom, range.to, Decoration16.replace({
|
|
8241
|
+
widget,
|
|
8242
|
+
block: def.block,
|
|
8243
|
+
atomic: true,
|
|
8244
|
+
inclusive: true,
|
|
8245
|
+
tag: tagName,
|
|
8246
|
+
streaming: true,
|
|
8247
|
+
contentFrom
|
|
8248
|
+
}));
|
|
8249
|
+
streamingFrom = absoluteFrom;
|
|
8250
|
+
last = absoluteFrom;
|
|
8251
|
+
}
|
|
8252
|
+
break;
|
|
8253
|
+
}
|
|
8254
|
+
}
|
|
8255
|
+
}
|
|
7517
8256
|
return {
|
|
7518
8257
|
from: last,
|
|
8258
|
+
streamingFrom,
|
|
7519
8259
|
decorations: builder.finish()
|
|
7520
8260
|
};
|
|
7521
8261
|
};
|
|
@@ -7524,12 +8264,14 @@ var PlaceholderWidget2 = class extends WidgetType10 {
|
|
|
7524
8264
|
Component;
|
|
7525
8265
|
props;
|
|
7526
8266
|
notifier;
|
|
7527
|
-
|
|
7528
|
-
|
|
7529
|
-
|
|
8267
|
+
streaming;
|
|
8268
|
+
#root = null;
|
|
8269
|
+
#view;
|
|
8270
|
+
constructor(id, Component, props, notifier, streaming) {
|
|
8271
|
+
super(), this.id = id, this.Component = Component, this.props = props, this.notifier = notifier, this.streaming = streaming;
|
|
7530
8272
|
invariant7(id, void 0, {
|
|
7531
|
-
F:
|
|
7532
|
-
L:
|
|
8273
|
+
F: __dxlog_file17,
|
|
8274
|
+
L: 641,
|
|
7533
8275
|
S: this,
|
|
7534
8276
|
A: [
|
|
7535
8277
|
"id",
|
|
@@ -7538,27 +8280,50 @@ var PlaceholderWidget2 = class extends WidgetType10 {
|
|
|
7538
8280
|
});
|
|
7539
8281
|
}
|
|
7540
8282
|
get root() {
|
|
7541
|
-
return this
|
|
8283
|
+
return this.#root;
|
|
7542
8284
|
}
|
|
7543
8285
|
eq(other) {
|
|
8286
|
+
if (this.streaming) {
|
|
8287
|
+
return false;
|
|
8288
|
+
}
|
|
7544
8289
|
return this.id === other.id;
|
|
7545
8290
|
}
|
|
7546
8291
|
ignoreEvent() {
|
|
7547
8292
|
return true;
|
|
7548
8293
|
}
|
|
7549
|
-
toDOM(
|
|
7550
|
-
this
|
|
8294
|
+
toDOM(view) {
|
|
8295
|
+
this.#view = view;
|
|
8296
|
+
this.#root = Domino4.of("div").classNames("min-h-[24px]").attributes({
|
|
8297
|
+
[XML_WIDGET_DATA_ATTR]: ""
|
|
8298
|
+
}).root;
|
|
8299
|
+
const props = Object.assign({}, this.props, {
|
|
8300
|
+
view
|
|
8301
|
+
});
|
|
7551
8302
|
this.notifier.mounted({
|
|
7552
8303
|
id: this.id,
|
|
7553
|
-
root: this
|
|
7554
|
-
props
|
|
8304
|
+
root: this.#root,
|
|
8305
|
+
props,
|
|
7555
8306
|
Component: this.Component
|
|
7556
8307
|
});
|
|
7557
|
-
return this
|
|
8308
|
+
return this.#root;
|
|
8309
|
+
}
|
|
8310
|
+
updateDOM(dom) {
|
|
8311
|
+
this.#root = dom;
|
|
8312
|
+
const props = Object.assign({}, this.props, {
|
|
8313
|
+
view: this.#view
|
|
8314
|
+
});
|
|
8315
|
+
this.notifier.mounted({
|
|
8316
|
+
id: this.id,
|
|
8317
|
+
root: this.#root,
|
|
8318
|
+
props,
|
|
8319
|
+
Component: this.Component
|
|
8320
|
+
});
|
|
8321
|
+
return true;
|
|
7558
8322
|
}
|
|
7559
8323
|
destroy(_dom) {
|
|
7560
8324
|
this.notifier.unmounted(this.id);
|
|
7561
|
-
this
|
|
8325
|
+
this.#root = null;
|
|
8326
|
+
this.#view = void 0;
|
|
7562
8327
|
}
|
|
7563
8328
|
};
|
|
7564
8329
|
|
|
@@ -7622,8 +8387,8 @@ export {
|
|
|
7622
8387
|
Cursor,
|
|
7623
8388
|
EditorInputMode,
|
|
7624
8389
|
EditorInputModes,
|
|
7625
|
-
|
|
7626
|
-
|
|
8390
|
+
EditorState4 as EditorState,
|
|
8391
|
+
EditorView32 as EditorView,
|
|
7627
8392
|
EditorViewMode,
|
|
7628
8393
|
EditorViewModes,
|
|
7629
8394
|
Inline,
|
|
@@ -7634,6 +8399,7 @@ export {
|
|
|
7634
8399
|
SpaceAwarenessProvider,
|
|
7635
8400
|
TextKind,
|
|
7636
8401
|
Tree,
|
|
8402
|
+
XML_WIDGET_DATA_ATTR,
|
|
7637
8403
|
addBlockquote,
|
|
7638
8404
|
addBookmark,
|
|
7639
8405
|
addCodeblock,
|
|
@@ -7642,6 +8408,7 @@ export {
|
|
|
7642
8408
|
addStyle,
|
|
7643
8409
|
annotations,
|
|
7644
8410
|
autoScroll,
|
|
8411
|
+
autoScrollEffect,
|
|
7645
8412
|
autocomplete,
|
|
7646
8413
|
automerge,
|
|
7647
8414
|
awareness,
|
|
@@ -7655,9 +8422,11 @@ export {
|
|
|
7655
8422
|
commentClickedEffect,
|
|
7656
8423
|
comments,
|
|
7657
8424
|
commentsState,
|
|
8425
|
+
compactSlots,
|
|
7658
8426
|
convertTreeToJson,
|
|
7659
8427
|
createBasicExtensions,
|
|
7660
8428
|
createComment,
|
|
8429
|
+
createCrawler,
|
|
7661
8430
|
createDataExtensions,
|
|
7662
8431
|
createEditorStateStore,
|
|
7663
8432
|
createEditorStateTransaction,
|
|
@@ -7677,12 +8446,12 @@ export {
|
|
|
7677
8446
|
defaultThemeSlots,
|
|
7678
8447
|
deleteItem,
|
|
7679
8448
|
documentId,
|
|
8449
|
+
documentSlots,
|
|
7680
8450
|
dropFile,
|
|
8451
|
+
editorClassNames,
|
|
7681
8452
|
editorInputMode,
|
|
7682
|
-
editorSlots,
|
|
7683
|
-
editorWidth,
|
|
7684
|
-
editorWithToolbarLayout,
|
|
7685
8453
|
extendedMarkdown,
|
|
8454
|
+
fader,
|
|
7686
8455
|
filterChars,
|
|
7687
8456
|
flattenRect,
|
|
7688
8457
|
focus,
|
|
@@ -7718,6 +8487,7 @@ export {
|
|
|
7718
8487
|
markdownTagsExtensions,
|
|
7719
8488
|
matchCompletion,
|
|
7720
8489
|
mention,
|
|
8490
|
+
mobileSlots,
|
|
7721
8491
|
modalStateEffect,
|
|
7722
8492
|
modalStateField,
|
|
7723
8493
|
moveItemDown,
|
|
@@ -7737,10 +8507,12 @@ export {
|
|
|
7737
8507
|
removeList,
|
|
7738
8508
|
removeStyle,
|
|
7739
8509
|
replacer,
|
|
8510
|
+
scrollPastEnd,
|
|
7740
8511
|
scrollThreadIntoView,
|
|
7741
|
-
scrollToBottomEffect,
|
|
7742
8512
|
scrollToLine,
|
|
7743
|
-
|
|
8513
|
+
scroller,
|
|
8514
|
+
scrollerCrawlEffect,
|
|
8515
|
+
scrollerLineEffect,
|
|
7744
8516
|
selectionState,
|
|
7745
8517
|
setBlockquote,
|
|
7746
8518
|
setComments,
|
|
@@ -7748,10 +8520,7 @@ export {
|
|
|
7748
8520
|
setSelection,
|
|
7749
8521
|
setStyle,
|
|
7750
8522
|
singleValueFacet,
|
|
7751
|
-
smoothScroll,
|
|
7752
|
-
stackItemContentEditorClassNames,
|
|
7753
8523
|
staticCompletion,
|
|
7754
|
-
streamer,
|
|
7755
8524
|
submit,
|
|
7756
8525
|
tabbable,
|
|
7757
8526
|
table,
|
|
@@ -7770,7 +8539,10 @@ export {
|
|
|
7770
8539
|
treeFacet,
|
|
7771
8540
|
typeahead,
|
|
7772
8541
|
typewriter,
|
|
8542
|
+
wire,
|
|
8543
|
+
wireBypass,
|
|
7773
8544
|
wrapWithCatch,
|
|
8545
|
+
xmlElementLength,
|
|
7774
8546
|
xmlTagContextEffect,
|
|
7775
8547
|
xmlTagResetEffect,
|
|
7776
8548
|
xmlTagUpdateEffect,
|