@dxos/react-ui-editor 0.3.10-main.560f82b → 0.3.10-main.5e11230
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/index.mjs +328 -260
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/blast.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/comments.d.ts +1 -1
- package/dist/types/src/components/TextEditor/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/experimental.d.ts +1 -1
- package/dist/types/src/components/TextEditor/extensions/experimental.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/bundle.d.ts +7 -0
- package/dist/types/src/components/TextEditor/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/highlight.d.ts +3 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/highlight.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/themes/default.d.ts.map +1 -1
- package/package.json +20 -20
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +14 -12
- package/src/components/TextEditor/TextEditor.tsx +4 -22
- package/src/components/TextEditor/extensions/blast.ts +13 -1
- package/src/components/TextEditor/extensions/comments.ts +21 -39
- package/src/components/TextEditor/extensions/experimental.tsx +14 -35
- package/src/components/TextEditor/extensions/image.ts +4 -5
- package/src/components/TextEditor/extensions/link.ts +2 -2
- package/src/components/TextEditor/extensions/markdown/bundle.ts +35 -42
- package/src/components/TextEditor/extensions/markdown/highlight.ts +37 -11
- package/src/components/TextEditor/extensions/table.ts +47 -48
- package/src/components/TextEditor/extensions/tasklist.ts +8 -8
- package/src/components/TextEditor/themes/default.ts +37 -0
|
@@ -61,6 +61,7 @@ import defaultsDeep from "lodash.defaultsdeep";
|
|
|
61
61
|
import { invariant } from "@dxos/invariant";
|
|
62
62
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/components/TextEditor/extensions/blast.ts";
|
|
63
63
|
var defaultOptions = {
|
|
64
|
+
effect: 2,
|
|
64
65
|
maxParticles: 200,
|
|
65
66
|
particleGravity: 0.08,
|
|
66
67
|
particleAlphaFadeout: 0.996,
|
|
@@ -108,7 +109,15 @@ var blast = (options) => {
|
|
|
108
109
|
if (blaster) {
|
|
109
110
|
blaster.destroy();
|
|
110
111
|
}
|
|
111
|
-
blaster = new Blaster(update4.view.scrollDOM, defaultsDeep({
|
|
112
|
+
blaster = new Blaster(update4.view.scrollDOM, defaultsDeep({
|
|
113
|
+
particleGravity: 0.2,
|
|
114
|
+
particleShrinkRate: 0.995,
|
|
115
|
+
color: () => [
|
|
116
|
+
100 + Math.random() * 100,
|
|
117
|
+
0,
|
|
118
|
+
0
|
|
119
|
+
]
|
|
120
|
+
}, options, defaultOptions));
|
|
112
121
|
blaster.initialize();
|
|
113
122
|
blaster.start();
|
|
114
123
|
} else {
|
|
@@ -192,7 +201,7 @@ var Blaster = class {
|
|
|
192
201
|
initialize() {
|
|
193
202
|
invariant(!this._canvas && !this._ctx, void 0, {
|
|
194
203
|
F: __dxlog_file,
|
|
195
|
-
L:
|
|
204
|
+
L: 152,
|
|
196
205
|
S: this,
|
|
197
206
|
A: [
|
|
198
207
|
"!this._canvas && !this._ctx",
|
|
@@ -229,7 +238,7 @@ var Blaster = class {
|
|
|
229
238
|
start() {
|
|
230
239
|
invariant(this._canvas && this._ctx, void 0, {
|
|
231
240
|
F: __dxlog_file,
|
|
232
|
-
L:
|
|
241
|
+
L: 191,
|
|
233
242
|
S: this,
|
|
234
243
|
A: [
|
|
235
244
|
"this._canvas && this._ctx",
|
|
@@ -432,14 +441,26 @@ import { keymap as keymap4, Decoration, EditorView as EditorView3, MatchDecorato
|
|
|
432
441
|
import { debounce } from "@dxos/async";
|
|
433
442
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
434
443
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/components/TextEditor/extensions/comments.ts";
|
|
444
|
+
var styles = EditorView3.baseTheme({
|
|
445
|
+
"& .cm-bookmark": {
|
|
446
|
+
cursor: "pointer",
|
|
447
|
+
margin: "4px",
|
|
448
|
+
padding: "4px",
|
|
449
|
+
backgroundColor: "yellow"
|
|
450
|
+
},
|
|
451
|
+
"& .cm-bookmark-selected": {
|
|
452
|
+
backgroundColor: "orange"
|
|
453
|
+
}
|
|
454
|
+
});
|
|
435
455
|
var BookmarkWidget = class extends WidgetType {
|
|
436
|
-
constructor(_pos, _id) {
|
|
456
|
+
constructor(_pos, _id, _handleClick) {
|
|
437
457
|
super();
|
|
438
458
|
this._pos = _pos;
|
|
439
459
|
this._id = _id;
|
|
460
|
+
this._handleClick = _handleClick;
|
|
440
461
|
invariant2(this._id, void 0, {
|
|
441
462
|
F: __dxlog_file2,
|
|
442
|
-
L:
|
|
463
|
+
L: 37,
|
|
443
464
|
S: this,
|
|
444
465
|
A: [
|
|
445
466
|
"this._id",
|
|
@@ -453,21 +474,11 @@ var BookmarkWidget = class extends WidgetType {
|
|
|
453
474
|
toDOM() {
|
|
454
475
|
const span = document.createElement("span");
|
|
455
476
|
span.className = "cm-bookmark";
|
|
456
|
-
span.textContent = "\
|
|
477
|
+
span.textContent = "\xA7";
|
|
478
|
+
span.onclick = () => this._handleClick();
|
|
457
479
|
return span;
|
|
458
480
|
}
|
|
459
481
|
};
|
|
460
|
-
var styles = EditorView3.baseTheme({
|
|
461
|
-
"& .cm-bookmark": {
|
|
462
|
-
cursor: "pointer",
|
|
463
|
-
margin: "4px",
|
|
464
|
-
padding: "4px",
|
|
465
|
-
backgroundColor: "yellow"
|
|
466
|
-
},
|
|
467
|
-
"& .cm-bookmark-selected": {
|
|
468
|
-
backgroundColor: "orange"
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
482
|
var comments = (options = {}) => {
|
|
472
483
|
let active;
|
|
473
484
|
const bookmarkMatcher = new MatchDecorator({
|
|
@@ -476,7 +487,9 @@ var comments = (options = {}) => {
|
|
|
476
487
|
const id = match[1];
|
|
477
488
|
return Decoration.replace({
|
|
478
489
|
id,
|
|
479
|
-
widget: new BookmarkWidget(pos, id)
|
|
490
|
+
widget: new BookmarkWidget(pos, id, () => handleUpdate({
|
|
491
|
+
active: id
|
|
492
|
+
}))
|
|
480
493
|
});
|
|
481
494
|
}
|
|
482
495
|
});
|
|
@@ -493,7 +506,7 @@ var comments = (options = {}) => {
|
|
|
493
506
|
return view.plugin(plugin)?.bookmarks || Decoration.none;
|
|
494
507
|
})
|
|
495
508
|
});
|
|
496
|
-
const
|
|
509
|
+
const handleUpdate = debounce((data) => {
|
|
497
510
|
options.onUpdate?.(data);
|
|
498
511
|
}, 200);
|
|
499
512
|
return [
|
|
@@ -532,10 +545,13 @@ var comments = (options = {}) => {
|
|
|
532
545
|
const decorations = [];
|
|
533
546
|
const rangeSet = view.plugin(bookmarks)?.bookmarks;
|
|
534
547
|
let closest = Infinity;
|
|
535
|
-
const { from, to } =
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
548
|
+
const { from, to } = (
|
|
549
|
+
/* view.visibleRanges?.[0] ?? */
|
|
550
|
+
{
|
|
551
|
+
from: 0,
|
|
552
|
+
to: view.state.doc.length
|
|
553
|
+
}
|
|
554
|
+
);
|
|
539
555
|
rangeSet?.between(from, to, (from2, to2, value) => {
|
|
540
556
|
decorations.push({
|
|
541
557
|
from: from2,
|
|
@@ -549,7 +565,7 @@ var comments = (options = {}) => {
|
|
|
549
565
|
}
|
|
550
566
|
});
|
|
551
567
|
if (decorations.length) {
|
|
552
|
-
|
|
568
|
+
handleUpdate({
|
|
553
569
|
active,
|
|
554
570
|
items: decorations.map(({ from: from2, value: { spec: { id } } }) => ({
|
|
555
571
|
id,
|
|
@@ -576,13 +592,15 @@ var image = (options = {}) => {
|
|
|
576
592
|
};
|
|
577
593
|
var update = (state, options) => {
|
|
578
594
|
const builder = new RangeSetBuilder();
|
|
595
|
+
const cursor = state.selection.main.head;
|
|
579
596
|
syntaxTree(state).iterate({
|
|
580
597
|
enter: (node) => {
|
|
581
598
|
if (node.name === "Image") {
|
|
582
599
|
const urlNode = node.node.getChild("URL");
|
|
583
600
|
if (urlNode) {
|
|
601
|
+
const hide = state.readOnly || cursor < node.from || cursor > node.to;
|
|
584
602
|
const url = state.sliceDoc(urlNode.from, urlNode.to);
|
|
585
|
-
builder.add(
|
|
603
|
+
builder.add(hide ? node.from : node.to, node.to, Decoration2.replace({
|
|
586
604
|
widget: new ImageWidget(url)
|
|
587
605
|
}));
|
|
588
606
|
}
|
|
@@ -677,7 +695,7 @@ var update2 = (state, options) => {
|
|
|
677
695
|
if (!url) {
|
|
678
696
|
return false;
|
|
679
697
|
}
|
|
680
|
-
if (cursor < node.from || cursor > node.to) {
|
|
698
|
+
if (state.readOnly || cursor < node.from || cursor > node.to) {
|
|
681
699
|
builder.add(node.from, node.to, Decoration3.replace({
|
|
682
700
|
widget: new LinkText(node.from, text, options.link ? url : void 0)
|
|
683
701
|
}));
|
|
@@ -710,19 +728,20 @@ var listener = ({ onChange }) => {
|
|
|
710
728
|
|
|
711
729
|
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/markdown/bundle.ts
|
|
712
730
|
import { closeBrackets as closeBrackets2, closeBracketsKeymap } from "@codemirror/autocomplete";
|
|
713
|
-
import {
|
|
731
|
+
import { history, historyKeymap, indentWithTab, standardKeymap } from "@codemirror/commands";
|
|
714
732
|
import { markdownLanguage as markdownLanguage2, markdown } from "@codemirror/lang-markdown";
|
|
715
733
|
import { bracketMatching as bracketMatching2, defaultHighlightStyle as defaultHighlightStyle2, indentOnInput, syntaxHighlighting as syntaxHighlighting2 } from "@codemirror/language";
|
|
716
734
|
import { languages } from "@codemirror/language-data";
|
|
717
|
-
import {
|
|
735
|
+
import { searchKeymap } from "@codemirror/search";
|
|
718
736
|
import { EditorState } from "@codemirror/state";
|
|
719
737
|
import { oneDarkHighlightStyle as oneDarkHighlightStyle2 } from "@codemirror/theme-one-dark";
|
|
720
|
-
import { crosshairCursor, drawSelection, dropCursor, EditorView as EditorView6,
|
|
738
|
+
import { crosshairCursor, drawSelection, dropCursor, EditorView as EditorView6, keymap as keymap5, placeholder as placeholder2 } from "@codemirror/view";
|
|
721
739
|
|
|
722
740
|
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/markdown/highlight.ts
|
|
723
741
|
import { markdownLanguage } from "@codemirror/lang-markdown";
|
|
724
742
|
import { HighlightStyle } from "@codemirror/language";
|
|
725
743
|
import { tags, styleTags, Tag } from "@lezer/highlight";
|
|
744
|
+
import { Table } from "@lezer/markdown";
|
|
726
745
|
import get from "lodash.get";
|
|
727
746
|
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
728
747
|
|
|
@@ -786,188 +805,201 @@ var markdownTags = {
|
|
|
786
805
|
LinkReference: Tag.define(),
|
|
787
806
|
ListMark: Tag.define(),
|
|
788
807
|
QuoteMark: Tag.define(),
|
|
789
|
-
URL: Tag.define()
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
props: [
|
|
793
|
-
styleTags(markdownTags)
|
|
794
|
-
]
|
|
808
|
+
URL: Tag.define(),
|
|
809
|
+
// Custom.
|
|
810
|
+
TableCell: Tag.define()
|
|
795
811
|
};
|
|
796
|
-
|
|
797
|
-
{
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
tags.character,
|
|
803
|
-
tags.propertyName,
|
|
804
|
-
tags.macroName,
|
|
805
|
-
tags.color,
|
|
806
|
-
tags.constant(tags.name),
|
|
807
|
-
tags.standard(tags.name),
|
|
808
|
-
tags.definition(tags.name),
|
|
809
|
-
tags.separator,
|
|
810
|
-
tags.typeName,
|
|
811
|
-
tags.className,
|
|
812
|
-
tags.number,
|
|
813
|
-
tags.changed,
|
|
814
|
-
tags.annotation,
|
|
815
|
-
tags.modifier,
|
|
816
|
-
tags.self,
|
|
817
|
-
tags.namespace,
|
|
818
|
-
tags.operator,
|
|
819
|
-
tags.operatorKeyword,
|
|
820
|
-
tags.escape,
|
|
821
|
-
tags.regexp,
|
|
822
|
-
tags.special(tags.string),
|
|
823
|
-
tags.meta,
|
|
824
|
-
tags.comment,
|
|
825
|
-
tags.atom,
|
|
826
|
-
tags.bool,
|
|
827
|
-
tags.special(tags.variableName),
|
|
828
|
-
tags.processingInstruction,
|
|
829
|
-
tags.string,
|
|
830
|
-
tags.inserted,
|
|
831
|
-
tags.invalid
|
|
832
|
-
],
|
|
833
|
-
color: "inherit !important"
|
|
834
|
-
},
|
|
835
|
-
// Markdown marks.
|
|
836
|
-
{
|
|
837
|
-
tag: [
|
|
838
|
-
tags.meta,
|
|
839
|
-
tags.processingInstruction,
|
|
840
|
-
markdownTags.LinkLabel,
|
|
841
|
-
markdownTags.LinkReference,
|
|
842
|
-
markdownTags.ListMark
|
|
843
|
-
],
|
|
844
|
-
class: mark
|
|
845
|
-
},
|
|
846
|
-
// Markdown marks.
|
|
847
|
-
{
|
|
848
|
-
tag: [
|
|
849
|
-
markdownTags.CodeMark,
|
|
850
|
-
markdownTags.HeaderMark,
|
|
851
|
-
markdownTags.QuoteMark,
|
|
852
|
-
markdownTags.EmphasisMark
|
|
853
|
-
],
|
|
854
|
-
class: readonly ? "hidden" : mark
|
|
855
|
-
},
|
|
856
|
-
// E.g., code block language (after ```).
|
|
857
|
-
{
|
|
858
|
-
tag: [
|
|
859
|
-
tags.function(tags.variableName),
|
|
860
|
-
tags.labelName
|
|
861
|
-
],
|
|
862
|
-
class: readonly ? "hidden" : codeMark
|
|
863
|
-
},
|
|
864
|
-
// Headings.
|
|
865
|
-
{
|
|
866
|
-
tag: tags.heading1,
|
|
867
|
-
class: heading(1, readonly)
|
|
868
|
-
},
|
|
869
|
-
{
|
|
870
|
-
tag: tags.heading2,
|
|
871
|
-
class: heading(2, readonly)
|
|
872
|
-
},
|
|
873
|
-
{
|
|
874
|
-
tag: tags.heading3,
|
|
875
|
-
class: heading(3, readonly)
|
|
876
|
-
},
|
|
877
|
-
{
|
|
878
|
-
tag: tags.heading4,
|
|
879
|
-
class: heading(4, readonly)
|
|
880
|
-
},
|
|
881
|
-
{
|
|
882
|
-
tag: tags.heading5,
|
|
883
|
-
class: heading(5, readonly)
|
|
884
|
-
},
|
|
885
|
-
{
|
|
886
|
-
tag: tags.heading6,
|
|
887
|
-
class: heading(6, readonly)
|
|
888
|
-
},
|
|
889
|
-
// Emphasis.
|
|
890
|
-
{
|
|
891
|
-
tag: tags.emphasis,
|
|
892
|
-
class: italic
|
|
893
|
-
},
|
|
894
|
-
{
|
|
895
|
-
tag: tags.strong,
|
|
896
|
-
class: bold
|
|
897
|
-
},
|
|
898
|
-
{
|
|
899
|
-
tag: tags.strikethrough,
|
|
900
|
-
class: strikethrough
|
|
901
|
-
},
|
|
902
|
-
// Naked URLs.
|
|
903
|
-
{
|
|
904
|
-
tag: [
|
|
905
|
-
markdownTags.URL
|
|
906
|
-
],
|
|
907
|
-
class: inlineUrl
|
|
908
|
-
},
|
|
909
|
-
// NOTE: The `markdown` extension configures extensions for `lezer` to parse markdown tokens (incl. below).
|
|
910
|
-
// However, since `codeLanguages` is also defined, the `lezer` will not parse fenced code blocks,
|
|
911
|
-
// when a language is specified. In this case, the syntax highlighting extensions will colorize
|
|
912
|
-
// the code, but all other CSS properties will be inherited.
|
|
913
|
-
// IMPORTANT: Therefore, the fenced code block will use the base editor font.
|
|
914
|
-
{
|
|
915
|
-
tag: [
|
|
916
|
-
markdownTags.CodeText,
|
|
917
|
-
markdownTags.InlineCode
|
|
918
|
-
],
|
|
919
|
-
class: code
|
|
920
|
-
},
|
|
921
|
-
{
|
|
922
|
-
tag: [
|
|
923
|
-
markdownTags.QuoteMark
|
|
924
|
-
],
|
|
925
|
-
class: blockquote
|
|
926
|
-
},
|
|
927
|
-
{
|
|
928
|
-
tag: [
|
|
929
|
-
markdownTags.HorizontalRule
|
|
930
|
-
],
|
|
931
|
-
class: mx2(horizontalRule, readonly && "-indent-[100rem]")
|
|
932
|
-
}
|
|
933
|
-
], {
|
|
934
|
-
scope: markdownLanguage,
|
|
935
|
-
all: {
|
|
936
|
-
fontFamily: get(tokens, "fontFamily.body", []).join(",")
|
|
812
|
+
Table.defineNodes?.forEach((node) => {
|
|
813
|
+
switch (node?.name) {
|
|
814
|
+
case "TableCell": {
|
|
815
|
+
node.style = markdownTags.TableCell;
|
|
816
|
+
break;
|
|
817
|
+
}
|
|
937
818
|
}
|
|
938
819
|
});
|
|
820
|
+
var markdownTagsExtensions = [
|
|
821
|
+
Table,
|
|
822
|
+
{
|
|
823
|
+
props: [
|
|
824
|
+
styleTags(markdownTags)
|
|
825
|
+
]
|
|
826
|
+
}
|
|
827
|
+
];
|
|
828
|
+
var markdownHighlightStyle = (readonly) => {
|
|
829
|
+
return HighlightStyle.define([
|
|
830
|
+
{
|
|
831
|
+
tag: [
|
|
832
|
+
tags.keyword,
|
|
833
|
+
tags.name,
|
|
834
|
+
tags.deleted,
|
|
835
|
+
tags.character,
|
|
836
|
+
tags.propertyName,
|
|
837
|
+
tags.macroName,
|
|
838
|
+
tags.color,
|
|
839
|
+
tags.constant(tags.name),
|
|
840
|
+
tags.standard(tags.name),
|
|
841
|
+
tags.definition(tags.name),
|
|
842
|
+
tags.separator,
|
|
843
|
+
tags.typeName,
|
|
844
|
+
tags.className,
|
|
845
|
+
tags.number,
|
|
846
|
+
tags.changed,
|
|
847
|
+
tags.annotation,
|
|
848
|
+
tags.modifier,
|
|
849
|
+
tags.self,
|
|
850
|
+
tags.namespace,
|
|
851
|
+
tags.operator,
|
|
852
|
+
tags.operatorKeyword,
|
|
853
|
+
tags.escape,
|
|
854
|
+
tags.regexp,
|
|
855
|
+
tags.special(tags.string),
|
|
856
|
+
tags.meta,
|
|
857
|
+
tags.comment,
|
|
858
|
+
tags.atom,
|
|
859
|
+
tags.bool,
|
|
860
|
+
tags.special(tags.variableName),
|
|
861
|
+
tags.processingInstruction,
|
|
862
|
+
tags.string,
|
|
863
|
+
tags.inserted,
|
|
864
|
+
tags.invalid
|
|
865
|
+
],
|
|
866
|
+
color: "inherit !important"
|
|
867
|
+
},
|
|
868
|
+
// Markdown marks.
|
|
869
|
+
{
|
|
870
|
+
tag: [
|
|
871
|
+
tags.meta,
|
|
872
|
+
tags.processingInstruction,
|
|
873
|
+
markdownTags.LinkLabel,
|
|
874
|
+
markdownTags.LinkReference,
|
|
875
|
+
markdownTags.ListMark
|
|
876
|
+
],
|
|
877
|
+
class: mark
|
|
878
|
+
},
|
|
879
|
+
// Markdown marks.
|
|
880
|
+
{
|
|
881
|
+
tag: [
|
|
882
|
+
markdownTags.CodeMark,
|
|
883
|
+
markdownTags.HeaderMark,
|
|
884
|
+
markdownTags.QuoteMark,
|
|
885
|
+
markdownTags.EmphasisMark
|
|
886
|
+
],
|
|
887
|
+
class: readonly ? "hidden" : mark
|
|
888
|
+
},
|
|
889
|
+
// E.g., code block language (after ```).
|
|
890
|
+
{
|
|
891
|
+
tag: [
|
|
892
|
+
tags.function(tags.variableName),
|
|
893
|
+
tags.labelName
|
|
894
|
+
],
|
|
895
|
+
class: readonly ? "hidden" : codeMark
|
|
896
|
+
},
|
|
897
|
+
{
|
|
898
|
+
tag: [
|
|
899
|
+
tags.monospace
|
|
900
|
+
],
|
|
901
|
+
class: "font-mono"
|
|
902
|
+
},
|
|
903
|
+
// Headings.
|
|
904
|
+
{
|
|
905
|
+
tag: tags.heading1,
|
|
906
|
+
class: heading(1, readonly)
|
|
907
|
+
},
|
|
908
|
+
{
|
|
909
|
+
tag: tags.heading2,
|
|
910
|
+
class: heading(2, readonly)
|
|
911
|
+
},
|
|
912
|
+
{
|
|
913
|
+
tag: tags.heading3,
|
|
914
|
+
class: heading(3, readonly)
|
|
915
|
+
},
|
|
916
|
+
{
|
|
917
|
+
tag: tags.heading4,
|
|
918
|
+
class: heading(4, readonly)
|
|
919
|
+
},
|
|
920
|
+
{
|
|
921
|
+
tag: tags.heading5,
|
|
922
|
+
class: heading(5, readonly)
|
|
923
|
+
},
|
|
924
|
+
{
|
|
925
|
+
tag: tags.heading6,
|
|
926
|
+
class: heading(6, readonly)
|
|
927
|
+
},
|
|
928
|
+
// Emphasis.
|
|
929
|
+
{
|
|
930
|
+
tag: tags.emphasis,
|
|
931
|
+
class: italic
|
|
932
|
+
},
|
|
933
|
+
{
|
|
934
|
+
tag: tags.strong,
|
|
935
|
+
class: bold
|
|
936
|
+
},
|
|
937
|
+
{
|
|
938
|
+
tag: tags.strikethrough,
|
|
939
|
+
class: strikethrough
|
|
940
|
+
},
|
|
941
|
+
// Naked URLs.
|
|
942
|
+
{
|
|
943
|
+
tag: [
|
|
944
|
+
markdownTags.URL
|
|
945
|
+
],
|
|
946
|
+
class: inlineUrl
|
|
947
|
+
},
|
|
948
|
+
// NOTE: The `markdown` extension configures extensions for `lezer` to parse markdown tokens (incl. below).
|
|
949
|
+
// However, since `codeLanguages` is also defined, the `lezer` will not parse fenced code blocks,
|
|
950
|
+
// when a language is specified. In this case, the syntax highlighting extensions will colorize
|
|
951
|
+
// the code, but all other CSS properties will be inherited.
|
|
952
|
+
// IMPORTANT: Therefore, the fenced code block will use the base editor font.
|
|
953
|
+
{
|
|
954
|
+
tag: [
|
|
955
|
+
markdownTags.CodeText,
|
|
956
|
+
markdownTags.InlineCode
|
|
957
|
+
],
|
|
958
|
+
class: code
|
|
959
|
+
},
|
|
960
|
+
{
|
|
961
|
+
tag: [
|
|
962
|
+
markdownTags.QuoteMark
|
|
963
|
+
],
|
|
964
|
+
class: blockquote
|
|
965
|
+
},
|
|
966
|
+
// TODO(burdon): Replace with extension.
|
|
967
|
+
{
|
|
968
|
+
tag: [
|
|
969
|
+
markdownTags.HorizontalRule
|
|
970
|
+
],
|
|
971
|
+
class: mx2(horizontalRule, readonly && "-indent-[100rem]")
|
|
972
|
+
},
|
|
973
|
+
// TODO(burdon): Only if being edited.
|
|
974
|
+
{
|
|
975
|
+
tag: [
|
|
976
|
+
markdownTags.TableCell
|
|
977
|
+
],
|
|
978
|
+
class: "font-mono"
|
|
979
|
+
}
|
|
980
|
+
], {
|
|
981
|
+
scope: markdownLanguage,
|
|
982
|
+
all: {
|
|
983
|
+
fontFamily: get(tokens, "fontFamily.body", []).join(",")
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
};
|
|
939
987
|
|
|
940
988
|
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/markdown/bundle.ts
|
|
941
989
|
var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
|
|
942
990
|
return [
|
|
943
|
-
bracketMatching2(),
|
|
944
|
-
closeBrackets2(),
|
|
945
|
-
_placeholder && placeholder2(_placeholder),
|
|
946
991
|
EditorState.allowMultipleSelections.of(true),
|
|
992
|
+
EditorState.tabSize.of(2),
|
|
947
993
|
EditorView6.lineWrapping,
|
|
994
|
+
customKeymap(),
|
|
995
|
+
bracketMatching2(),
|
|
996
|
+
closeBrackets2(),
|
|
948
997
|
crosshairCursor(),
|
|
949
998
|
dropCursor(),
|
|
950
999
|
drawSelection(),
|
|
951
|
-
highlightActiveLine(),
|
|
952
|
-
highlightActiveLineGutter(),
|
|
953
|
-
highlightSelectionMatches(),
|
|
954
|
-
highlightSpecialChars(),
|
|
955
1000
|
history(),
|
|
956
1001
|
indentOnInput(),
|
|
957
|
-
|
|
958
|
-
// https://codemirror.net/docs/ref/#view.keymap
|
|
959
|
-
keymap5.of([
|
|
960
|
-
// https://codemirror.net/docs/ref/#commands.defaultKeymap
|
|
961
|
-
...defaultKeymap,
|
|
962
|
-
// https://codemirror.net/docs/ref/#commands.historyKeymap
|
|
963
|
-
...historyKeymap,
|
|
964
|
-
// https://codemirror.net/docs/ref/#autocomplete.closeBracketsKeymap
|
|
965
|
-
...closeBracketsKeymap,
|
|
966
|
-
// https://codemirror.net/docs/ref/#search.searchKeymap
|
|
967
|
-
...searchKeymap,
|
|
968
|
-
// https://codemirror.net/docs/ref/#commands.indentWithTab
|
|
969
|
-
indentWithTab
|
|
970
|
-
]),
|
|
1002
|
+
_placeholder && placeholder2(_placeholder),
|
|
971
1003
|
// Main extension.
|
|
972
1004
|
// https://github.com/codemirror/lang-markdown
|
|
973
1005
|
// https://codemirror.net/5/mode/markdown/index.html (demo).
|
|
@@ -982,8 +1014,8 @@ var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
|
|
|
982
1014
|
codeLanguages: languages,
|
|
983
1015
|
// Parser extensions.
|
|
984
1016
|
extensions: [
|
|
985
|
-
// GFM
|
|
986
|
-
|
|
1017
|
+
// GFM provided by default.
|
|
1018
|
+
markdownTagsExtensions
|
|
987
1019
|
]
|
|
988
1020
|
}),
|
|
989
1021
|
// https://github.com/codemirror/theme-one-dark
|
|
@@ -992,6 +1024,18 @@ var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
|
|
|
992
1024
|
syntaxHighlighting2(markdownHighlightStyle(readonly))
|
|
993
1025
|
].filter(Boolean);
|
|
994
1026
|
};
|
|
1027
|
+
var customKeymap = () => keymap5.of([
|
|
1028
|
+
// https://codemirror.net/docs/ref/#commands.indentWithTab
|
|
1029
|
+
indentWithTab,
|
|
1030
|
+
// https://codemirror.net/docs/ref/#commands.standardKeymap
|
|
1031
|
+
...standardKeymap,
|
|
1032
|
+
// https://codemirror.net/docs/ref/#commands.historyKeymap
|
|
1033
|
+
...historyKeymap,
|
|
1034
|
+
// https://codemirror.net/docs/ref/#autocomplete.closeBracketsKeymap
|
|
1035
|
+
...closeBracketsKeymap,
|
|
1036
|
+
// https://codemirror.net/docs/ref/#search.searchKeymap
|
|
1037
|
+
...searchKeymap
|
|
1038
|
+
]);
|
|
995
1039
|
|
|
996
1040
|
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/mention.ts
|
|
997
1041
|
import { autocompletion as autocompletion2 } from "@codemirror/autocomplete";
|
|
@@ -1029,50 +1073,49 @@ var table = (options = {}) => {
|
|
|
1029
1073
|
};
|
|
1030
1074
|
var update3 = (state, options) => {
|
|
1031
1075
|
const builder = new RangeSetBuilder3();
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
break;
|
|
1064
|
-
}
|
|
1065
|
-
case "TableDelimiter": {
|
|
1066
|
-
getTable().to = node.to;
|
|
1067
|
-
break;
|
|
1076
|
+
const cursor = state.selection.main.head;
|
|
1077
|
+
const tables = [];
|
|
1078
|
+
const getTable = () => tables[tables.length - 1];
|
|
1079
|
+
const getRow = () => {
|
|
1080
|
+
const table2 = getTable();
|
|
1081
|
+
return table2.rows?.[table2.rows.length - 1];
|
|
1082
|
+
};
|
|
1083
|
+
syntaxTree3(state).iterate({
|
|
1084
|
+
enter: (node) => {
|
|
1085
|
+
switch (node.name) {
|
|
1086
|
+
case "Table": {
|
|
1087
|
+
tables.push({
|
|
1088
|
+
from: node.from,
|
|
1089
|
+
to: node.to
|
|
1090
|
+
});
|
|
1091
|
+
break;
|
|
1092
|
+
}
|
|
1093
|
+
case "TableHeader": {
|
|
1094
|
+
getTable().header = [];
|
|
1095
|
+
break;
|
|
1096
|
+
}
|
|
1097
|
+
case "TableRow": {
|
|
1098
|
+
(getTable().rows ??= []).push([]);
|
|
1099
|
+
break;
|
|
1100
|
+
}
|
|
1101
|
+
case "TableCell": {
|
|
1102
|
+
const row = getRow();
|
|
1103
|
+
if (row) {
|
|
1104
|
+
row.push(state.sliceDoc(node.from, node.to));
|
|
1105
|
+
} else {
|
|
1106
|
+
getTable().header?.push(state.sliceDoc(node.from, node.to));
|
|
1068
1107
|
}
|
|
1108
|
+
break;
|
|
1069
1109
|
}
|
|
1070
1110
|
}
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1111
|
+
}
|
|
1112
|
+
});
|
|
1113
|
+
tables.forEach((table2) => {
|
|
1114
|
+
const hide = state.readOnly || cursor < table2.from || cursor > table2.to;
|
|
1115
|
+
hide && builder.add(table2.from, table2.to, Decoration4.replace({
|
|
1073
1116
|
widget: new TableWidget(table2)
|
|
1074
|
-
}))
|
|
1075
|
-
}
|
|
1117
|
+
}));
|
|
1118
|
+
});
|
|
1076
1119
|
return builder.finish();
|
|
1077
1120
|
};
|
|
1078
1121
|
var TableWidget = class extends WidgetType4 {
|
|
@@ -1087,11 +1130,11 @@ var TableWidget = class extends WidgetType4 {
|
|
|
1087
1130
|
const table2 = document.createElement("table");
|
|
1088
1131
|
{
|
|
1089
1132
|
const header = table2.appendChild(document.createElement("thead"));
|
|
1090
|
-
const
|
|
1133
|
+
const tr = header.appendChild(document.createElement("tr"));
|
|
1091
1134
|
this._table.header?.forEach((cell) => {
|
|
1092
1135
|
const th = document.createElement("th");
|
|
1093
1136
|
th.setAttribute("class", "cm-table-head");
|
|
1094
|
-
|
|
1137
|
+
tr.appendChild(th).textContent = cell;
|
|
1095
1138
|
});
|
|
1096
1139
|
}
|
|
1097
1140
|
{
|
|
@@ -1111,6 +1154,12 @@ var TableWidget = class extends WidgetType4 {
|
|
|
1111
1154
|
|
|
1112
1155
|
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/tasklist.ts
|
|
1113
1156
|
import { EditorView as EditorView8, Decoration as Decoration5, WidgetType as WidgetType5, MatchDecorator as MatchDecorator2, ViewPlugin as ViewPlugin2 } from "@codemirror/view";
|
|
1157
|
+
var styles2 = EditorView8.baseTheme({
|
|
1158
|
+
"& .cm-task-item": {
|
|
1159
|
+
paddingLeft: "4px",
|
|
1160
|
+
paddingRight: "8px"
|
|
1161
|
+
}
|
|
1162
|
+
});
|
|
1114
1163
|
var CheckboxWidget = class extends WidgetType5 {
|
|
1115
1164
|
constructor(_pos, _checked, _indent, _onCheck) {
|
|
1116
1165
|
super();
|
|
@@ -1145,12 +1194,6 @@ var CheckboxWidget = class extends WidgetType5 {
|
|
|
1145
1194
|
return false;
|
|
1146
1195
|
}
|
|
1147
1196
|
};
|
|
1148
|
-
var styles2 = EditorView8.baseTheme({
|
|
1149
|
-
"& .cm-task-item": {
|
|
1150
|
-
paddingLeft: "4px",
|
|
1151
|
-
paddingRight: "8px"
|
|
1152
|
-
}
|
|
1153
|
-
});
|
|
1154
1197
|
var tasklist = (options = {}) => {
|
|
1155
1198
|
const taskMatcher = new MatchDecorator2({
|
|
1156
1199
|
regexp: /^(\s*)- \[([ xX])\]\s/g,
|
|
@@ -1419,7 +1462,42 @@ var defaultTheme = {
|
|
|
1419
1462
|
height
|
|
1420
1463
|
};
|
|
1421
1464
|
return acc;
|
|
1422
|
-
}, {})
|
|
1465
|
+
}, {}),
|
|
1466
|
+
/**
|
|
1467
|
+
* Panels
|
|
1468
|
+
* https://github.com/codemirror/search/blob/main/src/search.ts#L745
|
|
1469
|
+
*
|
|
1470
|
+
* Find/replace panel.
|
|
1471
|
+
* <div class="cm-announced">...</div>
|
|
1472
|
+
* <div class="cm-scroller">...</div>
|
|
1473
|
+
* <div class="cm-panels cm-panels-bottom">
|
|
1474
|
+
* <div class="cm-search cm-panel">
|
|
1475
|
+
* <input class="cm-textfield" />
|
|
1476
|
+
* <button class="cm-button">...</button>
|
|
1477
|
+
* <label><input type="checkbox" />...</label>
|
|
1478
|
+
* </div>
|
|
1479
|
+
* </div
|
|
1480
|
+
*/
|
|
1481
|
+
"& .cm-panels": {
|
|
1482
|
+
border: `1px solid ${get2(tokens, "extend.colors.neutral.200")}`,
|
|
1483
|
+
borderBottom: "none"
|
|
1484
|
+
},
|
|
1485
|
+
"& .cm-panel": {
|
|
1486
|
+
background: get2(tokens, "extend.colors.neutral.50"),
|
|
1487
|
+
fontFamily: get2(tokens, "fontFamily.body", []).join(",")
|
|
1488
|
+
},
|
|
1489
|
+
"& .cm-button": {
|
|
1490
|
+
margin: "4px",
|
|
1491
|
+
fontFamily: get2(tokens, "fontFamily.body", []).join(","),
|
|
1492
|
+
background: get2(tokens, "extend.colors.neutral.100"),
|
|
1493
|
+
border: "none"
|
|
1494
|
+
},
|
|
1495
|
+
"& .cm-searchMatch": {
|
|
1496
|
+
backgroundColor: get2(tokens, "extend.colors.yellow.100")
|
|
1497
|
+
},
|
|
1498
|
+
"& .cm-searchMatch.cm-searchMatch-selected": {
|
|
1499
|
+
backgroundColor: get2(tokens, "extend.colors.primary.100")
|
|
1500
|
+
}
|
|
1423
1501
|
};
|
|
1424
1502
|
var textTheme = {
|
|
1425
1503
|
"& .cm-scroller": {
|
|
@@ -1507,6 +1585,7 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, editorMode,
|
|
|
1507
1585
|
// TODO(burdon): Factor out VIM mode?
|
|
1508
1586
|
editorMode === "vim" && vim(),
|
|
1509
1587
|
// Theme.
|
|
1588
|
+
// TODO(burdon): Make optional.
|
|
1510
1589
|
EditorView9.baseTheme(defaultTheme),
|
|
1511
1590
|
EditorView9.theme(slots?.editor?.theme ?? {}),
|
|
1512
1591
|
// TODO(burdon): themeMode doesn't change in storybooks.
|
|
@@ -1560,15 +1639,6 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, editorMode,
|
|
|
1560
1639
|
onKeyUp: handleKeyUp
|
|
1561
1640
|
});
|
|
1562
1641
|
});
|
|
1563
|
-
var maybeDebug = () => {
|
|
1564
|
-
const items = localStorage.getItem("dxos.composer.demo");
|
|
1565
|
-
if (items) {
|
|
1566
|
-
return demo({
|
|
1567
|
-
items: items.split(",")
|
|
1568
|
-
});
|
|
1569
|
-
}
|
|
1570
|
-
return [];
|
|
1571
|
-
};
|
|
1572
1642
|
var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], slots: _slots, ...props }, forwardedRef) => {
|
|
1573
1643
|
const { themeMode } = useThemeContext();
|
|
1574
1644
|
const slots = defaultsDeep2({}, _slots, defaultTextSlots);
|
|
@@ -1581,7 +1651,6 @@ var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], slots:
|
|
|
1581
1651
|
themeMode,
|
|
1582
1652
|
placeholder: slots?.editor?.placeholder
|
|
1583
1653
|
}),
|
|
1584
|
-
maybeDebug(),
|
|
1585
1654
|
...extensions
|
|
1586
1655
|
],
|
|
1587
1656
|
slots,
|
|
@@ -1600,7 +1669,6 @@ var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], sl
|
|
|
1600
1669
|
themeMode,
|
|
1601
1670
|
placeholder: slots?.editor?.placeholder
|
|
1602
1671
|
}),
|
|
1603
|
-
maybeDebug(),
|
|
1604
1672
|
...extensions
|
|
1605
1673
|
],
|
|
1606
1674
|
slots,
|
|
@@ -2123,7 +2191,7 @@ export {
|
|
|
2123
2191
|
markdownBundle,
|
|
2124
2192
|
markdownHighlightStyle,
|
|
2125
2193
|
markdownTags,
|
|
2126
|
-
|
|
2194
|
+
markdownTagsExtensions,
|
|
2127
2195
|
markdownTheme,
|
|
2128
2196
|
mention,
|
|
2129
2197
|
table,
|