@dxos/react-ui-editor 0.3.11-main.668f0ff → 0.3.11-main.9bacd9f
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 +72 -73
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts +0 -3
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/index.d.ts +0 -1
- package/dist/types/src/components/TextEditor/extensions/index.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/link.d.ts +1 -0
- package/dist/types/src/components/TextEditor/extensions/link.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/listener.d.ts.map +1 -1
- package/package.json +21 -21
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +10 -12
- package/src/components/TextEditor/extensions/index.ts +0 -1
- package/src/components/TextEditor/extensions/link.ts +66 -10
- package/src/components/TextEditor/extensions/listener.ts +19 -23
- package/dist/types/src/components/TextEditor/extensions/tooltip.d.ts +0 -12
- package/dist/types/src/components/TextEditor/extensions/tooltip.d.ts.map +0 -1
- package/src/components/TextEditor/extensions/tooltip.ts +0 -61
|
@@ -1422,13 +1422,64 @@ var ImageWidget = class extends WidgetType3 {
|
|
|
1422
1422
|
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/link.ts
|
|
1423
1423
|
import { syntaxTree as syntaxTree2 } from "@codemirror/language";
|
|
1424
1424
|
import { RangeSetBuilder as RangeSetBuilder2, StateField as StateField5 } from "@codemirror/state";
|
|
1425
|
-
import { Decoration as Decoration5, EditorView as EditorView7, WidgetType as WidgetType4 } from "@codemirror/view";
|
|
1425
|
+
import { Decoration as Decoration5, EditorView as EditorView7, WidgetType as WidgetType4, hoverTooltip as hoverTooltip2 } from "@codemirror/view";
|
|
1426
|
+
import { tooltipContent } from "@dxos/react-ui-theme";
|
|
1427
|
+
var markdownLinkRegexp = /\[([^\]]+)]\(([^)]+)\)/;
|
|
1426
1428
|
var link = (options = {}) => {
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1429
|
+
const extensions = [
|
|
1430
|
+
StateField5.define({
|
|
1431
|
+
create: (state) => update2(state, options),
|
|
1432
|
+
update: (_, tr) => update2(tr.state, options),
|
|
1433
|
+
provide: (field) => EditorView7.decorations.from(field)
|
|
1434
|
+
})
|
|
1435
|
+
];
|
|
1436
|
+
if (options.onHover) {
|
|
1437
|
+
extensions.push(
|
|
1438
|
+
// https://codemirror.net/examples/tooltip
|
|
1439
|
+
// https://codemirror.net/docs/ref/#view.hoverTooltip
|
|
1440
|
+
// https://github.com/codemirror/view/blob/main/src/tooltip.ts
|
|
1441
|
+
hoverTooltip2((view, pos) => {
|
|
1442
|
+
const { from, text } = view.state.doc.lineAt(pos);
|
|
1443
|
+
const p = pos - from;
|
|
1444
|
+
let idx = 0;
|
|
1445
|
+
let match;
|
|
1446
|
+
do {
|
|
1447
|
+
match = text.substring(idx).match(markdownLinkRegexp);
|
|
1448
|
+
if (!match) {
|
|
1449
|
+
match = void 0;
|
|
1450
|
+
break;
|
|
1451
|
+
}
|
|
1452
|
+
idx = text.indexOf(match[0]);
|
|
1453
|
+
if (p >= idx && p < idx + match[0].length) {
|
|
1454
|
+
break;
|
|
1455
|
+
}
|
|
1456
|
+
idx += match[0].length;
|
|
1457
|
+
} while (true);
|
|
1458
|
+
if (!match) {
|
|
1459
|
+
return null;
|
|
1460
|
+
}
|
|
1461
|
+
const [, , url] = match ?? [];
|
|
1462
|
+
return {
|
|
1463
|
+
pos: idx + from,
|
|
1464
|
+
end: idx + from + match[0].length,
|
|
1465
|
+
above: true,
|
|
1466
|
+
create: () => {
|
|
1467
|
+
const el = document.createElement("div");
|
|
1468
|
+
el.className = tooltipContent({}, "pli-2 plb-1");
|
|
1469
|
+
options.onHover(el, url);
|
|
1470
|
+
return {
|
|
1471
|
+
dom: el,
|
|
1472
|
+
offset: {
|
|
1473
|
+
x: 0,
|
|
1474
|
+
y: 4
|
|
1475
|
+
}
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1478
|
+
};
|
|
1479
|
+
})
|
|
1480
|
+
);
|
|
1481
|
+
}
|
|
1482
|
+
return extensions;
|
|
1432
1483
|
};
|
|
1433
1484
|
var LinkButton = class extends WidgetType4 {
|
|
1434
1485
|
constructor(_pos, _url, _onAttach) {
|
|
@@ -1447,14 +1498,13 @@ var LinkButton = class extends WidgetType4 {
|
|
|
1447
1498
|
}
|
|
1448
1499
|
};
|
|
1449
1500
|
var LinkText = class extends WidgetType4 {
|
|
1450
|
-
constructor(
|
|
1501
|
+
constructor(_text, _url) {
|
|
1451
1502
|
super();
|
|
1452
|
-
this._pos = _pos;
|
|
1453
1503
|
this._text = _text;
|
|
1454
1504
|
this._url = _url;
|
|
1455
1505
|
}
|
|
1456
1506
|
eq(other) {
|
|
1457
|
-
return this.
|
|
1507
|
+
return this._url === other._url;
|
|
1458
1508
|
}
|
|
1459
1509
|
toDOM(view) {
|
|
1460
1510
|
const link2 = document.createElement("a");
|
|
@@ -1468,7 +1518,7 @@ var LinkText = class extends WidgetType4 {
|
|
|
1468
1518
|
link2.onclick = () => {
|
|
1469
1519
|
view.dispatch({
|
|
1470
1520
|
selection: {
|
|
1471
|
-
anchor:
|
|
1521
|
+
anchor: view.posAtDOM(link2)
|
|
1472
1522
|
}
|
|
1473
1523
|
});
|
|
1474
1524
|
};
|
|
@@ -1491,7 +1541,7 @@ var update2 = (state, options) => {
|
|
|
1491
1541
|
}
|
|
1492
1542
|
if (state.readOnly || cursor < node.from || cursor > node.to) {
|
|
1493
1543
|
builder.add(node.from, node.to, Decoration5.replace({
|
|
1494
|
-
widget: new LinkText(
|
|
1544
|
+
widget: new LinkText(text, options.link ? url : void 0)
|
|
1495
1545
|
}));
|
|
1496
1546
|
}
|
|
1497
1547
|
if (options.onRender) {
|
|
@@ -1507,24 +1557,18 @@ var update2 = (state, options) => {
|
|
|
1507
1557
|
};
|
|
1508
1558
|
|
|
1509
1559
|
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/listener.ts
|
|
1510
|
-
import { StateField as StateField6 } from "@codemirror/state";
|
|
1511
1560
|
import { EditorView as EditorView8 } from "@codemirror/view";
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
onFocus
|
|
1561
|
+
var listener = ({ onFocus, onChange }) => {
|
|
1562
|
+
const extensions = [];
|
|
1563
|
+
onFocus && extensions.push(EditorView8.focusChangeEffect.of((_, focused) => {
|
|
1515
1564
|
onFocus(focused);
|
|
1516
1565
|
return null;
|
|
1517
|
-
})
|
|
1518
|
-
onChange
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
}
|
|
1524
|
-
return null;
|
|
1525
|
-
}
|
|
1526
|
-
}) : void 0
|
|
1527
|
-
].filter(nonNullable2);
|
|
1566
|
+
}));
|
|
1567
|
+
onChange && extensions.push(EditorView8.updateListener.of((update4) => {
|
|
1568
|
+
onChange(update4.state.doc.toString());
|
|
1569
|
+
}));
|
|
1570
|
+
return extensions;
|
|
1571
|
+
};
|
|
1528
1572
|
|
|
1529
1573
|
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/markdown/bundle.ts
|
|
1530
1574
|
import { closeBrackets as closeBrackets2, closeBracketsKeymap } from "@codemirror/autocomplete";
|
|
@@ -1816,10 +1860,10 @@ var mermaid = () => {
|
|
|
1816
1860
|
|
|
1817
1861
|
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/table.ts
|
|
1818
1862
|
import { syntaxTree as syntaxTree3 } from "@codemirror/language";
|
|
1819
|
-
import { RangeSetBuilder as RangeSetBuilder3, StateField as
|
|
1863
|
+
import { RangeSetBuilder as RangeSetBuilder3, StateField as StateField6 } from "@codemirror/state";
|
|
1820
1864
|
import { Decoration as Decoration6, EditorView as EditorView10, WidgetType as WidgetType5 } from "@codemirror/view";
|
|
1821
1865
|
var table = (options = {}) => {
|
|
1822
|
-
return
|
|
1866
|
+
return StateField6.define({
|
|
1823
1867
|
create: (state) => update3(state, options),
|
|
1824
1868
|
update: (_, tr) => update3(tr.state, options),
|
|
1825
1869
|
provide: (field) => EditorView10.decorations.from(field)
|
|
@@ -1995,50 +2039,6 @@ var tasklist = (options = {}) => {
|
|
|
1995
2039
|
];
|
|
1996
2040
|
};
|
|
1997
2041
|
|
|
1998
|
-
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/tooltip.ts
|
|
1999
|
-
import { hoverTooltip as hoverTooltip2 } from "@codemirror/view";
|
|
2000
|
-
import { tooltipContent } from "@dxos/react-ui-theme";
|
|
2001
|
-
var markdownLinkRegexp = /\[([^\]]+)]\(([^)]+)\)/;
|
|
2002
|
-
var tooltip = ({ onHover, regexp = markdownLinkRegexp }) => hoverTooltip2((view, pos) => {
|
|
2003
|
-
const { from, text } = view.state.doc.lineAt(pos);
|
|
2004
|
-
const p = pos - from;
|
|
2005
|
-
let idx = 0;
|
|
2006
|
-
let match;
|
|
2007
|
-
do {
|
|
2008
|
-
match = text.substring(idx).match(regexp);
|
|
2009
|
-
if (!match) {
|
|
2010
|
-
match = void 0;
|
|
2011
|
-
break;
|
|
2012
|
-
}
|
|
2013
|
-
idx = text.indexOf(match[0]);
|
|
2014
|
-
if (p >= idx && p < idx + match[0].length) {
|
|
2015
|
-
break;
|
|
2016
|
-
}
|
|
2017
|
-
idx += match[0].length;
|
|
2018
|
-
} while (true);
|
|
2019
|
-
if (!match) {
|
|
2020
|
-
return null;
|
|
2021
|
-
}
|
|
2022
|
-
const [, , url] = match ?? [];
|
|
2023
|
-
return {
|
|
2024
|
-
pos: idx + from,
|
|
2025
|
-
end: idx + from + match[0].length,
|
|
2026
|
-
above: true,
|
|
2027
|
-
create: () => {
|
|
2028
|
-
const el = document.createElement("div");
|
|
2029
|
-
el.className = tooltipContent({}, "pli-2 plb-1");
|
|
2030
|
-
onHover(el, url);
|
|
2031
|
-
return {
|
|
2032
|
-
dom: el,
|
|
2033
|
-
offset: {
|
|
2034
|
-
x: 0,
|
|
2035
|
-
y: 4
|
|
2036
|
-
}
|
|
2037
|
-
};
|
|
2038
|
-
}
|
|
2039
|
-
};
|
|
2040
|
-
});
|
|
2041
|
-
|
|
2042
2042
|
// packages/ui/react-ui-editor/src/components/TextEditor/extensions/typewriter.ts
|
|
2043
2043
|
import { keymap as keymap5 } from "@codemirror/view";
|
|
2044
2044
|
var defaultItems = [
|
|
@@ -2589,7 +2589,6 @@ export {
|
|
|
2589
2589
|
tags2 as tags,
|
|
2590
2590
|
tasklist,
|
|
2591
2591
|
textTheme,
|
|
2592
|
-
tooltip,
|
|
2593
2592
|
typewriter,
|
|
2594
2593
|
useTextModel
|
|
2595
2594
|
};
|