@dxos/react-ui-editor 0.3.11-main.13264f1 → 0.3.11-main.1690b50
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 +146 -142
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/extensions/markdown/bundle.d.ts +2 -2
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/code.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/heading.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/hr.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/link.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/tasklist.d.ts.map +1 -1
- package/dist/types/src/styles/markdown.d.ts +2 -2
- package/dist/types/src/styles/markdown.d.ts.map +1 -1
- package/dist/types/src/themes/default.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +3 -3
- package/src/components/TextEditor/TextEditor.tsx +1 -1
- package/src/extensions/markdown/bundle.ts +3 -7
- package/src/extensions/markdown/code.ts +72 -49
- package/src/extensions/markdown/heading.ts +5 -6
- package/src/extensions/markdown/highlight.ts +9 -15
- package/src/extensions/markdown/hr.ts +2 -3
- package/src/extensions/markdown/link.ts +1 -2
- package/src/extensions/markdown/tasklist.ts +1 -2
- package/src/styles/markdown.ts +9 -10
- package/src/themes/default.ts +0 -2
|
@@ -674,10 +674,10 @@ var blast = (options = defaultOptions) => {
|
|
|
674
674
|
const getPoint = (view, pos) => {
|
|
675
675
|
const { left: x = 0, top: y = 0 } = view.coordsForChar(pos) ?? {};
|
|
676
676
|
const element = document.elementFromPoint(x, y);
|
|
677
|
-
const { offsetLeft: left = 0, offsetTop:
|
|
677
|
+
const { offsetLeft: left = 0, offsetTop: top2 = 0 } = view.scrollDOM.parentElement ?? {};
|
|
678
678
|
const point = {
|
|
679
679
|
x: x - left,
|
|
680
|
-
y: y -
|
|
680
|
+
y: y - top2
|
|
681
681
|
};
|
|
682
682
|
return {
|
|
683
683
|
element,
|
|
@@ -997,34 +997,15 @@ var cursorColor = cursorColors[random2.uint32() % cursorColors.length];
|
|
|
997
997
|
// packages/ui/react-ui-editor/src/styles/markdown.ts
|
|
998
998
|
import { mx } from "@dxos/react-ui-theme";
|
|
999
999
|
var headings = {
|
|
1000
|
-
1:
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
"mbs-4 mbe-2 font-medium text-inherit no-underline text-2xl",
|
|
1010
|
-
"-ml-[7px]"
|
|
1011
|
-
],
|
|
1012
|
-
4: [
|
|
1013
|
-
"mbs-4 mbe-2 font-medium text-inherit no-underline text-xl",
|
|
1014
|
-
"-ml-[6px]"
|
|
1015
|
-
],
|
|
1016
|
-
5: [
|
|
1017
|
-
"mbs-4 mbe-2 font-medium text-inherit no-underline text-lg",
|
|
1018
|
-
"-ml-[5px]"
|
|
1019
|
-
],
|
|
1020
|
-
6: [
|
|
1021
|
-
"mbs-4 mbe-2 font-medium text-inherit no-underline",
|
|
1022
|
-
"-ml-[4px]"
|
|
1023
|
-
]
|
|
1024
|
-
};
|
|
1025
|
-
var heading = (level, readonly) => {
|
|
1026
|
-
const [style, offset] = headings[level];
|
|
1027
|
-
return mx(style, readonly && offset);
|
|
1000
|
+
1: "mbs-4 mbe-2 font-medium text-inherit no-underline text-4xl",
|
|
1001
|
+
2: "mbs-4 mbe-2 font-medium text-inherit no-underline text-3xl",
|
|
1002
|
+
3: "mbs-4 mbe-2 font-medium text-inherit no-underline text-2xl",
|
|
1003
|
+
4: "mbs-4 mbe-2 font-medium text-inherit no-underline text-xl",
|
|
1004
|
+
5: "mbs-4 mbe-2 font-medium text-inherit no-underline text-lg",
|
|
1005
|
+
6: "mbs-4 mbe-2 font-medium text-inherit no-underline"
|
|
1006
|
+
};
|
|
1007
|
+
var heading = (level) => {
|
|
1008
|
+
return headings[level];
|
|
1028
1009
|
};
|
|
1029
1010
|
var light = "text-neutral-200 dark:text-neutral-800";
|
|
1030
1011
|
var mark = mx("!font-normal !no-underline !text-inherit opacity-40", light);
|
|
@@ -1518,7 +1499,7 @@ var markdownHighlightStyle = (readonly) => {
|
|
|
1518
1499
|
markdownTags.QuoteMark,
|
|
1519
1500
|
markdownTags.EmphasisMark
|
|
1520
1501
|
],
|
|
1521
|
-
class:
|
|
1502
|
+
class: mark
|
|
1522
1503
|
},
|
|
1523
1504
|
// E.g., code block language (after ```).
|
|
1524
1505
|
{
|
|
@@ -1526,7 +1507,7 @@ var markdownHighlightStyle = (readonly) => {
|
|
|
1526
1507
|
tags.function(tags.variableName),
|
|
1527
1508
|
tags.labelName
|
|
1528
1509
|
],
|
|
1529
|
-
class:
|
|
1510
|
+
class: codeMark
|
|
1530
1511
|
},
|
|
1531
1512
|
{
|
|
1532
1513
|
tag: [
|
|
@@ -1537,27 +1518,27 @@ var markdownHighlightStyle = (readonly) => {
|
|
|
1537
1518
|
// Headings.
|
|
1538
1519
|
{
|
|
1539
1520
|
tag: tags.heading1,
|
|
1540
|
-
class: heading(1
|
|
1521
|
+
class: heading(1)
|
|
1541
1522
|
},
|
|
1542
1523
|
{
|
|
1543
1524
|
tag: tags.heading2,
|
|
1544
|
-
class: heading(2
|
|
1525
|
+
class: heading(2)
|
|
1545
1526
|
},
|
|
1546
1527
|
{
|
|
1547
1528
|
tag: tags.heading3,
|
|
1548
|
-
class: heading(3
|
|
1529
|
+
class: heading(3)
|
|
1549
1530
|
},
|
|
1550
1531
|
{
|
|
1551
1532
|
tag: tags.heading4,
|
|
1552
|
-
class: heading(4
|
|
1533
|
+
class: heading(4)
|
|
1553
1534
|
},
|
|
1554
1535
|
{
|
|
1555
1536
|
tag: tags.heading5,
|
|
1556
|
-
class: heading(5
|
|
1537
|
+
class: heading(5)
|
|
1557
1538
|
},
|
|
1558
1539
|
{
|
|
1559
1540
|
tag: tags.heading6,
|
|
1560
|
-
class: heading(6
|
|
1541
|
+
class: heading(6)
|
|
1561
1542
|
},
|
|
1562
1543
|
// Emphasis.
|
|
1563
1544
|
{
|
|
@@ -1583,7 +1564,7 @@ var markdownHighlightStyle = (readonly) => {
|
|
|
1583
1564
|
// However, since `codeLanguages` is also defined, the `lezer` will not parse fenced code blocks,
|
|
1584
1565
|
// when a language is specified. In this case, the syntax highlighting extensions will colorize
|
|
1585
1566
|
// the code, but all other CSS properties will be inherited.
|
|
1586
|
-
// IMPORTANT: Therefore, the fenced code block will use the base editor font.
|
|
1567
|
+
// IMPORTANT: Therefore, the fenced code block will use the base editor font unless changed by an extension.
|
|
1587
1568
|
{
|
|
1588
1569
|
tag: [
|
|
1589
1570
|
markdownTags.CodeText,
|
|
@@ -1612,7 +1593,7 @@ var markdownHighlightStyle = (readonly) => {
|
|
|
1612
1593
|
};
|
|
1613
1594
|
|
|
1614
1595
|
// packages/ui/react-ui-editor/src/extensions/markdown/bundle.ts
|
|
1615
|
-
var markdownBundle = ({
|
|
1596
|
+
var markdownBundle = ({ themeMode, placeholder: _placeholder }) => {
|
|
1616
1597
|
return [
|
|
1617
1598
|
EditorState.allowMultipleSelections.of(true),
|
|
1618
1599
|
EditorState.tabSize.of(2),
|
|
@@ -1648,7 +1629,7 @@ var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
|
|
|
1648
1629
|
// https://github.com/codemirror/theme-one-dark
|
|
1649
1630
|
themeMode === "dark" ? syntaxHighlighting2(oneDarkHighlightStyle2) : syntaxHighlighting2(defaultHighlightStyle2),
|
|
1650
1631
|
// Custom styles.
|
|
1651
|
-
syntaxHighlighting2(markdownHighlightStyle(
|
|
1632
|
+
syntaxHighlighting2(markdownHighlightStyle()),
|
|
1652
1633
|
keymap4.of([
|
|
1653
1634
|
// https://codemirror.net/docs/ref/#commands.indentWithTab
|
|
1654
1635
|
indentWithTab,
|
|
@@ -1665,32 +1646,32 @@ var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
|
|
|
1665
1646
|
};
|
|
1666
1647
|
|
|
1667
1648
|
// packages/ui/react-ui-editor/src/extensions/markdown/code.ts
|
|
1668
|
-
import {
|
|
1649
|
+
import { syntaxTree } from "@codemirror/language";
|
|
1650
|
+
import { RangeSetBuilder } from "@codemirror/state";
|
|
1651
|
+
import { ViewPlugin as ViewPlugin3, EditorView as EditorView8, Decoration as Decoration3, WidgetType as WidgetType2 } from "@codemirror/view";
|
|
1669
1652
|
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
1670
|
-
var CODE_REGEX = /```[\s\S]*?```/gs;
|
|
1671
1653
|
var styles3 = EditorView8.baseTheme({
|
|
1672
|
-
"& .cm-
|
|
1654
|
+
"& .cm-code": {
|
|
1655
|
+
paddingInline: "1rem !important",
|
|
1673
1656
|
fontFamily: getToken("fontFamily.mono", []).join(",")
|
|
1674
1657
|
},
|
|
1675
|
-
|
|
1676
|
-
|
|
1658
|
+
"& .cm-codeblock": {
|
|
1659
|
+
display: "inline-block",
|
|
1660
|
+
width: "100%"
|
|
1677
1661
|
},
|
|
1678
|
-
|
|
1679
|
-
background: getToken("extend.colors.neutral.
|
|
1662
|
+
"&light .cm-codeblock, &light .cm-codeblock.cm-activeLine": {
|
|
1663
|
+
background: getToken("extend.colors.neutral.25")
|
|
1680
1664
|
},
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
paddingInline: "4px !important"
|
|
1665
|
+
"&dark .cm-codeblock, &dark .cm-codeblock.cm-activeLine": {
|
|
1666
|
+
background: getToken("extend.colors.neutral.850")
|
|
1684
1667
|
},
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
borderTopRightRadius: "4px"
|
|
1668
|
+
"& .cm-codeblock-first": {
|
|
1669
|
+
borderTopLeftRadius: ".5rem",
|
|
1670
|
+
borderTopRightRadius: ".5rem"
|
|
1689
1671
|
},
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
borderBottomRightRadius: "4px"
|
|
1672
|
+
"& .cm-codeblock-last": {
|
|
1673
|
+
borderBottomLeftRadius: ".5rem",
|
|
1674
|
+
borderBottomRightRadius: ".5rem"
|
|
1694
1675
|
}
|
|
1695
1676
|
});
|
|
1696
1677
|
var getLineRange = (lines, from, to) => {
|
|
@@ -1701,37 +1682,59 @@ var getLineRange = (lines, from, to) => {
|
|
|
1701
1682
|
end
|
|
1702
1683
|
];
|
|
1703
1684
|
};
|
|
1685
|
+
var LineWidget = class extends WidgetType2 {
|
|
1686
|
+
constructor(_className) {
|
|
1687
|
+
super();
|
|
1688
|
+
this._className = _className;
|
|
1689
|
+
}
|
|
1690
|
+
toDOM() {
|
|
1691
|
+
const el = document.createElement("span");
|
|
1692
|
+
el.innerHTML = " ";
|
|
1693
|
+
el.className = mx2("cm-code cm-codeblock", this._className);
|
|
1694
|
+
return el;
|
|
1695
|
+
}
|
|
1696
|
+
};
|
|
1697
|
+
var top = new LineWidget("cm-codeblock-first");
|
|
1698
|
+
var bottom = new LineWidget("cm-codeblock-last");
|
|
1699
|
+
var buildDecorations = (view) => {
|
|
1700
|
+
const builder = new RangeSetBuilder();
|
|
1701
|
+
const { state } = view;
|
|
1702
|
+
const blocks = view.viewportLineBlocks;
|
|
1703
|
+
const cursor = state.selection.main.head;
|
|
1704
|
+
for (const { from, to } of view.visibleRanges) {
|
|
1705
|
+
syntaxTree(state).iterate({
|
|
1706
|
+
enter: (node) => {
|
|
1707
|
+
if (node.name === "FencedCode") {
|
|
1708
|
+
const edit = !view.state.readOnly && cursor >= node.from && cursor <= node.to;
|
|
1709
|
+
const range = getLineRange(blocks, node.from, node.to);
|
|
1710
|
+
for (let i = range[0]; i <= range[1]; i++) {
|
|
1711
|
+
const block = blocks[i];
|
|
1712
|
+
if (!edit && (i === range[0] || i === range[1])) {
|
|
1713
|
+
builder.add(block.from, block.to, Decoration3.replace({
|
|
1714
|
+
widget: i === range[0] ? top : bottom
|
|
1715
|
+
}));
|
|
1716
|
+
} else {
|
|
1717
|
+
builder.add(block.from, block.from, Decoration3.line({
|
|
1718
|
+
class: mx2("cm-code cm-codeblock")
|
|
1719
|
+
}));
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
},
|
|
1724
|
+
from,
|
|
1725
|
+
to
|
|
1726
|
+
});
|
|
1727
|
+
}
|
|
1728
|
+
return builder.finish();
|
|
1729
|
+
};
|
|
1704
1730
|
var code2 = () => {
|
|
1705
|
-
const buildDecorations6 = (view) => {
|
|
1706
|
-
const decorations = [];
|
|
1707
|
-
const text = view.state.doc.sliceString(0);
|
|
1708
|
-
const matches = text.matchAll(CODE_REGEX);
|
|
1709
|
-
const blocks = view.viewportLineBlocks;
|
|
1710
|
-
for (const match of matches) {
|
|
1711
|
-
const range = getLineRange(blocks, match.index, match.index + match[0].length);
|
|
1712
|
-
for (let i = range[0]; i <= range[1]; i++) {
|
|
1713
|
-
const block = blocks[i];
|
|
1714
|
-
decorations.push(Decoration3.line({
|
|
1715
|
-
class: mx2("cm-codeblock", i === range[0] && "cm-codeblock-first", i === range[1] && "cm-codeblock-last")
|
|
1716
|
-
}).range(block.from));
|
|
1717
|
-
}
|
|
1718
|
-
}
|
|
1719
|
-
return Decoration3.set(decorations);
|
|
1720
|
-
};
|
|
1721
1731
|
return [
|
|
1722
1732
|
ViewPlugin3.fromClass(class {
|
|
1723
1733
|
constructor(view) {
|
|
1724
|
-
this.
|
|
1725
|
-
this.decorations = buildDecorations6(view);
|
|
1734
|
+
this.decorations = buildDecorations(view);
|
|
1726
1735
|
}
|
|
1727
1736
|
update(update2) {
|
|
1728
|
-
|
|
1729
|
-
// TODO(burdon): Generalize for other extensions.
|
|
1730
|
-
this.hasFocus !== update2.view.hasFocus || update2.startState.readOnly !== update2.view.state.readOnly || update2.docChanged || update2.viewportChanged
|
|
1731
|
-
) {
|
|
1732
|
-
this.hasFocus = update2.view.hasFocus;
|
|
1733
|
-
this.decorations = buildDecorations6(update2.view);
|
|
1734
|
-
}
|
|
1737
|
+
this.decorations = buildDecorations(update2.view);
|
|
1735
1738
|
}
|
|
1736
1739
|
}, {
|
|
1737
1740
|
decorations: (value) => value.decorations
|
|
@@ -1741,15 +1744,15 @@ var code2 = () => {
|
|
|
1741
1744
|
};
|
|
1742
1745
|
|
|
1743
1746
|
// packages/ui/react-ui-editor/src/extensions/markdown/heading.ts
|
|
1744
|
-
import { syntaxTree } from "@codemirror/language";
|
|
1745
|
-
import { RangeSetBuilder } from "@codemirror/state";
|
|
1747
|
+
import { syntaxTree as syntaxTree2 } from "@codemirror/language";
|
|
1748
|
+
import { RangeSetBuilder as RangeSetBuilder2 } from "@codemirror/state";
|
|
1746
1749
|
import { Decoration as Decoration4, ViewPlugin as ViewPlugin4 } from "@codemirror/view";
|
|
1747
|
-
var
|
|
1748
|
-
const builder = new
|
|
1750
|
+
var buildDecorations2 = (view) => {
|
|
1751
|
+
const builder = new RangeSetBuilder2();
|
|
1749
1752
|
const { state } = view;
|
|
1750
1753
|
const cursor = state.selection.main.head;
|
|
1751
1754
|
for (const { from, to } of view.visibleRanges) {
|
|
1752
|
-
|
|
1755
|
+
syntaxTree2(state).iterate({
|
|
1753
1756
|
enter: (node) => {
|
|
1754
1757
|
switch (node.name) {
|
|
1755
1758
|
case "ATXHeading1":
|
|
@@ -1759,8 +1762,10 @@ var buildDecorations = (view) => {
|
|
|
1759
1762
|
case "ATXHeading5":
|
|
1760
1763
|
case "ATXHeading6": {
|
|
1761
1764
|
const mark2 = node.node.getChild("HeaderMark");
|
|
1762
|
-
if (mark2
|
|
1763
|
-
|
|
1765
|
+
if (mark2) {
|
|
1766
|
+
if (view.state.readOnly || cursor < node.from || cursor > node.to) {
|
|
1767
|
+
builder.add(mark2.from, mark2.to + 1, Decoration4.replace({}));
|
|
1768
|
+
}
|
|
1764
1769
|
}
|
|
1765
1770
|
}
|
|
1766
1771
|
}
|
|
@@ -1775,28 +1780,28 @@ var heading2 = () => {
|
|
|
1775
1780
|
return [
|
|
1776
1781
|
ViewPlugin4.fromClass(class {
|
|
1777
1782
|
constructor(view) {
|
|
1778
|
-
this.decorations =
|
|
1783
|
+
this.decorations = buildDecorations2(view);
|
|
1779
1784
|
}
|
|
1780
1785
|
update(update2) {
|
|
1781
|
-
this.decorations =
|
|
1786
|
+
this.decorations = buildDecorations2(update2.view);
|
|
1782
1787
|
}
|
|
1783
1788
|
}, {
|
|
1784
|
-
decorations: (
|
|
1789
|
+
decorations: (value) => value.decorations
|
|
1785
1790
|
})
|
|
1786
1791
|
];
|
|
1787
1792
|
};
|
|
1788
1793
|
|
|
1789
1794
|
// packages/ui/react-ui-editor/src/extensions/markdown/hr.ts
|
|
1790
|
-
import { syntaxTree as
|
|
1791
|
-
import { RangeSetBuilder as
|
|
1792
|
-
import { Decoration as Decoration5, EditorView as EditorView9, ViewPlugin as ViewPlugin5, WidgetType as
|
|
1795
|
+
import { syntaxTree as syntaxTree3 } from "@codemirror/language";
|
|
1796
|
+
import { RangeSetBuilder as RangeSetBuilder3 } from "@codemirror/state";
|
|
1797
|
+
import { Decoration as Decoration5, EditorView as EditorView9, ViewPlugin as ViewPlugin5, WidgetType as WidgetType3 } from "@codemirror/view";
|
|
1793
1798
|
var styles4 = EditorView9.baseTheme({
|
|
1794
1799
|
"& .cm-hr": {
|
|
1795
1800
|
// Note that block-level decorations should not have vertical margins,
|
|
1796
1801
|
borderTop: `1px solid ${getToken("extend.colors.neutral.200")}`
|
|
1797
1802
|
}
|
|
1798
1803
|
});
|
|
1799
|
-
var HorizontalRuleWidget = class extends
|
|
1804
|
+
var HorizontalRuleWidget = class extends WidgetType3 {
|
|
1800
1805
|
toDOM() {
|
|
1801
1806
|
const el = document.createElement("div");
|
|
1802
1807
|
el.className = "cm-hr";
|
|
@@ -1806,12 +1811,12 @@ var HorizontalRuleWidget = class extends WidgetType2 {
|
|
|
1806
1811
|
var decoration = Decoration5.replace({
|
|
1807
1812
|
widget: new HorizontalRuleWidget()
|
|
1808
1813
|
});
|
|
1809
|
-
var
|
|
1810
|
-
const builder = new
|
|
1814
|
+
var buildDecorations3 = (view) => {
|
|
1815
|
+
const builder = new RangeSetBuilder3();
|
|
1811
1816
|
const { state } = view;
|
|
1812
1817
|
const cursor = state.selection.main.head;
|
|
1813
1818
|
for (const { from, to } of view.visibleRanges) {
|
|
1814
|
-
|
|
1819
|
+
syntaxTree3(state).iterate({
|
|
1815
1820
|
enter: (node) => {
|
|
1816
1821
|
if (node.name === "HorizontalRule") {
|
|
1817
1822
|
if (cursor <= node.from || cursor >= node.to) {
|
|
@@ -1827,28 +1832,28 @@ var buildDecorations2 = (view) => {
|
|
|
1827
1832
|
};
|
|
1828
1833
|
var hr = () => {
|
|
1829
1834
|
return [
|
|
1830
|
-
styles4,
|
|
1831
1835
|
ViewPlugin5.fromClass(class {
|
|
1832
1836
|
constructor(view) {
|
|
1833
|
-
this.decorations =
|
|
1837
|
+
this.decorations = buildDecorations3(view);
|
|
1834
1838
|
}
|
|
1835
1839
|
update(update2) {
|
|
1836
|
-
this.decorations =
|
|
1840
|
+
this.decorations = buildDecorations3(update2.view);
|
|
1837
1841
|
}
|
|
1838
1842
|
}, {
|
|
1839
|
-
decorations: (
|
|
1840
|
-
})
|
|
1843
|
+
decorations: (value) => value.decorations
|
|
1844
|
+
}),
|
|
1845
|
+
styles4
|
|
1841
1846
|
];
|
|
1842
1847
|
};
|
|
1843
1848
|
|
|
1844
1849
|
// packages/ui/react-ui-editor/src/extensions/markdown/image.ts
|
|
1845
|
-
import { syntaxTree as
|
|
1850
|
+
import { syntaxTree as syntaxTree4 } from "@codemirror/language";
|
|
1846
1851
|
import { StateField as StateField3 } from "@codemirror/state";
|
|
1847
|
-
import { Decoration as Decoration6, EditorView as EditorView10, WidgetType as
|
|
1852
|
+
import { Decoration as Decoration6, EditorView as EditorView10, WidgetType as WidgetType4 } from "@codemirror/view";
|
|
1848
1853
|
var image = (options = {}) => {
|
|
1849
1854
|
return StateField3.define({
|
|
1850
1855
|
create: (state) => {
|
|
1851
|
-
return Decoration6.set(
|
|
1856
|
+
return Decoration6.set(buildDecorations4(0, state.doc.length, state));
|
|
1852
1857
|
},
|
|
1853
1858
|
update: (value, tr) => {
|
|
1854
1859
|
if (!tr.docChanged && !tr.selection) {
|
|
@@ -1868,16 +1873,16 @@ var image = (options = {}) => {
|
|
|
1868
1873
|
filterFrom: from,
|
|
1869
1874
|
filterTo: to,
|
|
1870
1875
|
filter: () => false,
|
|
1871
|
-
add:
|
|
1876
|
+
add: buildDecorations4(from, to, tr.state)
|
|
1872
1877
|
});
|
|
1873
1878
|
},
|
|
1874
1879
|
provide: (field) => EditorView10.decorations.from(field)
|
|
1875
1880
|
});
|
|
1876
1881
|
};
|
|
1877
|
-
var
|
|
1882
|
+
var buildDecorations4 = (from, to, state) => {
|
|
1878
1883
|
const decorations = [];
|
|
1879
1884
|
const cursor = state.selection.main.head;
|
|
1880
|
-
|
|
1885
|
+
syntaxTree4(state).iterate({
|
|
1881
1886
|
enter: (node) => {
|
|
1882
1887
|
if (node.name === "Image") {
|
|
1883
1888
|
const urlNode = node.node.getChild("URL");
|
|
@@ -1896,7 +1901,7 @@ var buildDecorations3 = (from, to, state) => {
|
|
|
1896
1901
|
});
|
|
1897
1902
|
return decorations;
|
|
1898
1903
|
};
|
|
1899
|
-
var ImageWidget = class extends
|
|
1904
|
+
var ImageWidget = class extends WidgetType4 {
|
|
1900
1905
|
constructor(_url) {
|
|
1901
1906
|
super();
|
|
1902
1907
|
this._url = _url;
|
|
@@ -1914,23 +1919,23 @@ var ImageWidget = class extends WidgetType3 {
|
|
|
1914
1919
|
};
|
|
1915
1920
|
|
|
1916
1921
|
// packages/ui/react-ui-editor/src/extensions/markdown/link.ts
|
|
1917
|
-
import { syntaxTree as
|
|
1918
|
-
import { RangeSetBuilder as
|
|
1919
|
-
import { hoverTooltip as hoverTooltip2, Decoration as Decoration7, ViewPlugin as ViewPlugin6, WidgetType as
|
|
1922
|
+
import { syntaxTree as syntaxTree5 } from "@codemirror/language";
|
|
1923
|
+
import { RangeSetBuilder as RangeSetBuilder4 } from "@codemirror/state";
|
|
1924
|
+
import { hoverTooltip as hoverTooltip2, Decoration as Decoration7, ViewPlugin as ViewPlugin6, WidgetType as WidgetType5 } from "@codemirror/view";
|
|
1920
1925
|
import { tooltipContent } from "@dxos/react-ui-theme";
|
|
1921
1926
|
var link = (options = {}) => {
|
|
1922
1927
|
const extensions = [
|
|
1923
1928
|
ViewPlugin6.fromClass(class {
|
|
1924
1929
|
constructor(view) {
|
|
1925
|
-
this.decorations =
|
|
1930
|
+
this.decorations = buildDecorations5(view, options);
|
|
1926
1931
|
}
|
|
1927
1932
|
update(update2) {
|
|
1928
1933
|
if (update2.docChanged || update2.viewportChanged || update2.selectionSet) {
|
|
1929
|
-
this.decorations =
|
|
1934
|
+
this.decorations = buildDecorations5(update2.view, options);
|
|
1930
1935
|
}
|
|
1931
1936
|
}
|
|
1932
1937
|
}, {
|
|
1933
|
-
decorations: (
|
|
1938
|
+
decorations: (value) => value.decorations
|
|
1934
1939
|
})
|
|
1935
1940
|
];
|
|
1936
1941
|
if (options.onHover) {
|
|
@@ -1939,7 +1944,7 @@ var link = (options = {}) => {
|
|
|
1939
1944
|
// https://codemirror.net/docs/ref/#view.hoverTooltip
|
|
1940
1945
|
// https://github.com/codemirror/view/blob/main/src/tooltip.ts
|
|
1941
1946
|
hoverTooltip2((view, pos, side) => {
|
|
1942
|
-
const syntax =
|
|
1947
|
+
const syntax = syntaxTree5(view.state).resolveInner(pos, side);
|
|
1943
1948
|
let link2 = null;
|
|
1944
1949
|
for (let i = 0, node = syntax; !link2 && node && i < 5; node = node.parent, i++) {
|
|
1945
1950
|
link2 = node.name === "Link" ? node : null;
|
|
@@ -1971,7 +1976,7 @@ var link = (options = {}) => {
|
|
|
1971
1976
|
}
|
|
1972
1977
|
return extensions;
|
|
1973
1978
|
};
|
|
1974
|
-
var LinkButton = class extends
|
|
1979
|
+
var LinkButton = class extends WidgetType5 {
|
|
1975
1980
|
constructor(_url, _onAttach) {
|
|
1976
1981
|
super();
|
|
1977
1982
|
this._url = _url;
|
|
@@ -1986,7 +1991,7 @@ var LinkButton = class extends WidgetType4 {
|
|
|
1986
1991
|
return el;
|
|
1987
1992
|
}
|
|
1988
1993
|
};
|
|
1989
|
-
var LinkText = class extends
|
|
1994
|
+
var LinkText = class extends WidgetType5 {
|
|
1990
1995
|
constructor(_text, _url) {
|
|
1991
1996
|
super();
|
|
1992
1997
|
this._text = _text;
|
|
@@ -2015,12 +2020,12 @@ var LinkText = class extends WidgetType4 {
|
|
|
2015
2020
|
return link2;
|
|
2016
2021
|
}
|
|
2017
2022
|
};
|
|
2018
|
-
var
|
|
2019
|
-
const builder = new
|
|
2023
|
+
var buildDecorations5 = (view, options) => {
|
|
2024
|
+
const builder = new RangeSetBuilder4();
|
|
2020
2025
|
const { state } = view;
|
|
2021
2026
|
const cursor = state.selection.main.head;
|
|
2022
2027
|
for (const { from, to } of view.visibleRanges) {
|
|
2023
|
-
|
|
2028
|
+
syntaxTree5(state).iterate({
|
|
2024
2029
|
enter: (node) => {
|
|
2025
2030
|
if (node.name === "Link") {
|
|
2026
2031
|
const marks2 = node.node.getChildren("LinkMark");
|
|
@@ -2051,9 +2056,9 @@ var buildDecorations4 = (view, options) => {
|
|
|
2051
2056
|
};
|
|
2052
2057
|
|
|
2053
2058
|
// packages/ui/react-ui-editor/src/extensions/markdown/table.ts
|
|
2054
|
-
import { syntaxTree as
|
|
2055
|
-
import { RangeSetBuilder as
|
|
2056
|
-
import { Decoration as Decoration8, EditorView as EditorView11, WidgetType as
|
|
2059
|
+
import { syntaxTree as syntaxTree6 } from "@codemirror/language";
|
|
2060
|
+
import { RangeSetBuilder as RangeSetBuilder5, StateField as StateField4 } from "@codemirror/state";
|
|
2061
|
+
import { Decoration as Decoration8, EditorView as EditorView11, WidgetType as WidgetType6 } from "@codemirror/view";
|
|
2057
2062
|
var table = (options = {}) => {
|
|
2058
2063
|
return StateField4.define({
|
|
2059
2064
|
create: (state) => update(state, options),
|
|
@@ -2062,7 +2067,7 @@ var table = (options = {}) => {
|
|
|
2062
2067
|
});
|
|
2063
2068
|
};
|
|
2064
2069
|
var update = (state, options) => {
|
|
2065
|
-
const builder = new
|
|
2070
|
+
const builder = new RangeSetBuilder5();
|
|
2066
2071
|
const cursor = state.selection.main.head;
|
|
2067
2072
|
const tables = [];
|
|
2068
2073
|
const getTable = () => tables[tables.length - 1];
|
|
@@ -2070,7 +2075,7 @@ var update = (state, options) => {
|
|
|
2070
2075
|
const table2 = getTable();
|
|
2071
2076
|
return table2.rows?.[table2.rows.length - 1];
|
|
2072
2077
|
};
|
|
2073
|
-
|
|
2078
|
+
syntaxTree6(state).iterate({
|
|
2074
2079
|
enter: (node) => {
|
|
2075
2080
|
switch (node.name) {
|
|
2076
2081
|
case "Table": {
|
|
@@ -2111,7 +2116,7 @@ var update = (state, options) => {
|
|
|
2111
2116
|
});
|
|
2112
2117
|
return builder.finish();
|
|
2113
2118
|
};
|
|
2114
|
-
var TableWidget = class extends
|
|
2119
|
+
var TableWidget = class extends WidgetType6 {
|
|
2115
2120
|
constructor(_table) {
|
|
2116
2121
|
super();
|
|
2117
2122
|
this._table = _table;
|
|
@@ -2149,9 +2154,9 @@ var TableWidget = class extends WidgetType5 {
|
|
|
2149
2154
|
};
|
|
2150
2155
|
|
|
2151
2156
|
// packages/ui/react-ui-editor/src/extensions/markdown/tasklist.ts
|
|
2152
|
-
import { syntaxTree as
|
|
2153
|
-
import { RangeSetBuilder as
|
|
2154
|
-
import { EditorView as EditorView12, Decoration as Decoration9, WidgetType as
|
|
2157
|
+
import { syntaxTree as syntaxTree7 } from "@codemirror/language";
|
|
2158
|
+
import { RangeSetBuilder as RangeSetBuilder6 } from "@codemirror/state";
|
|
2159
|
+
import { EditorView as EditorView12, Decoration as Decoration9, WidgetType as WidgetType7, ViewPlugin as ViewPlugin7 } from "@codemirror/view";
|
|
2155
2160
|
var styles5 = EditorView12.baseTheme({
|
|
2156
2161
|
"& .cm-task": {
|
|
2157
2162
|
color: getToken("extend.colors.blue.500")
|
|
@@ -2161,7 +2166,7 @@ var styles5 = EditorView12.baseTheme({
|
|
|
2161
2166
|
marginRight: "4px"
|
|
2162
2167
|
}
|
|
2163
2168
|
});
|
|
2164
|
-
var CheckboxWidget = class extends
|
|
2169
|
+
var CheckboxWidget = class extends WidgetType7 {
|
|
2165
2170
|
constructor(_checked) {
|
|
2166
2171
|
super();
|
|
2167
2172
|
this._checked = _checked;
|
|
@@ -2204,12 +2209,12 @@ var checkedDecoration = Decoration9.replace({
|
|
|
2204
2209
|
var uncheckedDecoration = Decoration9.replace({
|
|
2205
2210
|
widget: new CheckboxWidget(false)
|
|
2206
2211
|
});
|
|
2207
|
-
var
|
|
2208
|
-
const builder = new
|
|
2212
|
+
var buildDecorations6 = (view) => {
|
|
2213
|
+
const builder = new RangeSetBuilder6();
|
|
2209
2214
|
const { state } = view;
|
|
2210
2215
|
const cursor = state.selection.main.head;
|
|
2211
2216
|
for (const { from, to } of view.visibleRanges) {
|
|
2212
|
-
|
|
2217
|
+
syntaxTree7(state).iterate({
|
|
2213
2218
|
enter: (node) => {
|
|
2214
2219
|
if (node.name === "TaskMarker") {
|
|
2215
2220
|
if (cursor < node.from || cursor > node.to) {
|
|
@@ -2231,15 +2236,15 @@ var tasklist = (options = {}) => {
|
|
|
2231
2236
|
return [
|
|
2232
2237
|
ViewPlugin7.fromClass(class {
|
|
2233
2238
|
constructor(view) {
|
|
2234
|
-
this.decorations =
|
|
2239
|
+
this.decorations = buildDecorations6(view);
|
|
2235
2240
|
}
|
|
2236
2241
|
update(update2) {
|
|
2237
2242
|
if (update2.docChanged || update2.viewportChanged || update2.selectionSet) {
|
|
2238
|
-
this.decorations =
|
|
2243
|
+
this.decorations = buildDecorations6(update2.view);
|
|
2239
2244
|
}
|
|
2240
2245
|
}
|
|
2241
2246
|
}, {
|
|
2242
|
-
decorations: (
|
|
2247
|
+
decorations: (value) => value.decorations
|
|
2243
2248
|
}),
|
|
2244
2249
|
styles5
|
|
2245
2250
|
];
|
|
@@ -2717,7 +2722,6 @@ var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, placeholder: placeh
|
|
|
2717
2722
|
extensions: [
|
|
2718
2723
|
markdownBundle({
|
|
2719
2724
|
themeMode,
|
|
2720
|
-
readonly,
|
|
2721
2725
|
placeholder: placeholder3
|
|
2722
2726
|
}),
|
|
2723
2727
|
...extensions
|