@dxos/react-ui-editor 0.8.3-main.672df60 → 0.8.3-main.7f5a14c
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 +868 -260
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +911 -297
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +868 -260
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/EditorToolbar/util.d.ts +2 -2
- package/dist/types/src/components/Popover/CommandMenu.d.ts +34 -0
- package/dist/types/src/components/Popover/CommandMenu.d.ts.map +1 -0
- package/dist/types/src/components/Popover/RefPopover.d.ts +19 -6
- package/dist/types/src/components/Popover/RefPopover.d.ts.map +1 -1
- package/dist/types/src/components/Popover/index.d.ts +1 -0
- package/dist/types/src/components/Popover/index.d.ts.map +1 -1
- package/dist/types/src/defaults.d.ts.map +1 -1
- package/dist/types/src/extensions/command/menu.d.ts +40 -0
- package/dist/types/src/extensions/command/menu.d.ts.map +1 -1
- package/dist/types/src/extensions/factories.d.ts +1 -0
- package/dist/types/src/extensions/factories.d.ts.map +1 -1
- package/dist/types/src/extensions/index.d.ts +1 -0
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/dist/types/src/extensions/placeholder.d.ts +4 -0
- package/dist/types/src/extensions/placeholder.d.ts.map +1 -0
- package/dist/types/src/extensions/preview/preview.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextEditor.d.ts +8 -9
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
- package/dist/types/src/stories/CommandMenu.stories.d.ts +12 -0
- package/dist/types/src/stories/CommandMenu.stories.d.ts.map +1 -0
- package/dist/types/src/stories/Preview.stories.d.ts.map +1 -1
- package/package.json +31 -28
- package/src/components/Popover/CommandMenu.tsx +279 -0
- package/src/components/Popover/RefPopover.tsx +44 -22
- package/src/components/Popover/index.ts +1 -0
- package/src/defaults.ts +1 -0
- package/src/extensions/command/menu.ts +306 -4
- package/src/extensions/factories.ts +4 -1
- package/src/extensions/index.ts +1 -0
- package/src/extensions/outliner/outliner.ts +0 -3
- package/src/extensions/placeholder.ts +82 -0
- package/src/extensions/preview/preview.ts +3 -6
- package/src/hooks/useTextEditor.ts +11 -12
- package/src/stories/CommandMenu.stories.tsx +143 -0
- package/src/stories/Preview.stories.tsx +32 -30
@@ -35,14 +35,14 @@ var translations_default = [
|
|
35
35
|
|
36
36
|
// packages/ui/react-ui-editor/src/index.ts
|
37
37
|
import { EditorState as EditorState4 } from "@codemirror/state";
|
38
|
-
import { EditorView as
|
38
|
+
import { EditorView as EditorView26, keymap as keymap14 } from "@codemirror/view";
|
39
39
|
import { tags as tags2 } from "@lezer/highlight";
|
40
40
|
import { TextKind } from "@dxos/protocols/proto/dxos/echo/model/text";
|
41
41
|
|
42
42
|
// packages/ui/react-ui-editor/src/components/EditorToolbar/EditorToolbar.tsx
|
43
43
|
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
44
44
|
import { Rx } from "@effect-rx/rx-react";
|
45
|
-
import React3, { memo, useMemo as
|
45
|
+
import React3, { memo, useMemo as useMemo4 } from "react";
|
46
46
|
import { rxFromSignal } from "@dxos/app-graph";
|
47
47
|
import { ElevationProvider } from "@dxos/react-ui";
|
48
48
|
import { MenuProvider, ToolbarMenu, createGapSeparator, useMenuActions } from "@dxos/react-ui-menu";
|
@@ -1458,10 +1458,80 @@ var command = (options = {}) => {
|
|
1458
1458
|
};
|
1459
1459
|
|
1460
1460
|
// packages/ui/react-ui-editor/src/extensions/command/menu.ts
|
1461
|
-
import {
|
1461
|
+
import { RangeSetBuilder as RangeSetBuilder3, StateField as StateField3, StateEffect as StateEffect3, Prec } from "@codemirror/state";
|
1462
|
+
import { EditorView as EditorView8, ViewPlugin as ViewPlugin6, Decoration as Decoration5, keymap as keymap4 } from "@codemirror/view";
|
1463
|
+
import { useCallback, useMemo as useMemo2, useRef, useState } from "react";
|
1462
1464
|
import { addEventListener } from "@dxos/async";
|
1465
|
+
|
1466
|
+
// packages/ui/react-ui-editor/src/extensions/placeholder.ts
|
1467
|
+
import { Decoration as Decoration4, EditorView as EditorView7, WidgetType as WidgetType3, ViewPlugin as ViewPlugin5 } from "@codemirror/view";
|
1468
|
+
var Placeholder = class extends WidgetType3 {
|
1469
|
+
constructor(content) {
|
1470
|
+
super(), this.content = content;
|
1471
|
+
}
|
1472
|
+
toDOM(view) {
|
1473
|
+
const wrap = document.createElement("span");
|
1474
|
+
wrap.className = "cm-placeholder";
|
1475
|
+
wrap.style.pointerEvents = "none";
|
1476
|
+
wrap.appendChild(typeof this.content === "string" ? document.createTextNode(this.content) : typeof this.content === "function" ? this.content(view) : this.content.cloneNode(true));
|
1477
|
+
wrap.setAttribute("aria-hidden", "true");
|
1478
|
+
return wrap;
|
1479
|
+
}
|
1480
|
+
coordsAt(dom) {
|
1481
|
+
const rects = dom.firstChild ? clientRectsFor(dom.firstChild) : [];
|
1482
|
+
if (!rects.length) {
|
1483
|
+
return null;
|
1484
|
+
}
|
1485
|
+
const style = window.getComputedStyle(dom.parentNode);
|
1486
|
+
const rect = flattenRect(rects[0], style.direction !== "rtl");
|
1487
|
+
const lineHeight = parseInt(style.lineHeight);
|
1488
|
+
if (rect.bottom - rect.top > lineHeight * 1.5) {
|
1489
|
+
return {
|
1490
|
+
left: rect.left,
|
1491
|
+
right: rect.right,
|
1492
|
+
top: rect.top,
|
1493
|
+
bottom: rect.top + lineHeight
|
1494
|
+
};
|
1495
|
+
}
|
1496
|
+
return rect;
|
1497
|
+
}
|
1498
|
+
ignoreEvent() {
|
1499
|
+
return false;
|
1500
|
+
}
|
1501
|
+
};
|
1502
|
+
function multilinePlaceholder(content) {
|
1503
|
+
const plugin = ViewPlugin5.fromClass(class {
|
1504
|
+
constructor(view) {
|
1505
|
+
this.view = view;
|
1506
|
+
}
|
1507
|
+
get decorations() {
|
1508
|
+
const activeLine = this.view.state.doc.lineAt(this.view.state.selection.main.head);
|
1509
|
+
const isEmpty = activeLine.text.trim() === "";
|
1510
|
+
if (!isEmpty || !content) {
|
1511
|
+
return Decoration4.none;
|
1512
|
+
}
|
1513
|
+
const lineStart = activeLine.from;
|
1514
|
+
return Decoration4.set([
|
1515
|
+
Decoration4.widget({
|
1516
|
+
widget: new Placeholder(content),
|
1517
|
+
side: 1
|
1518
|
+
}).range(lineStart)
|
1519
|
+
]);
|
1520
|
+
}
|
1521
|
+
}, {
|
1522
|
+
decorations: (v) => v.decorations
|
1523
|
+
});
|
1524
|
+
return typeof content === "string" ? [
|
1525
|
+
plugin,
|
1526
|
+
EditorView7.contentAttributes.of({
|
1527
|
+
"aria-placeholder": content
|
1528
|
+
})
|
1529
|
+
] : plugin;
|
1530
|
+
}
|
1531
|
+
|
1532
|
+
// packages/ui/react-ui-editor/src/extensions/command/menu.ts
|
1463
1533
|
var floatingMenu = (options = {}) => [
|
1464
|
-
|
1534
|
+
ViewPlugin6.fromClass(class {
|
1465
1535
|
constructor(view) {
|
1466
1536
|
this.view = view;
|
1467
1537
|
const container = view.scrollDOM;
|
@@ -1526,7 +1596,7 @@ var floatingMenu = (options = {}) => [
|
|
1526
1596
|
this.rafId = requestAnimationFrame(this.updateButtonPosition.bind(this));
|
1527
1597
|
}
|
1528
1598
|
}),
|
1529
|
-
|
1599
|
+
EditorView8.theme({
|
1530
1600
|
".cm-ref-tag": {
|
1531
1601
|
position: "fixed",
|
1532
1602
|
padding: "0",
|
@@ -1536,9 +1606,6 @@ var floatingMenu = (options = {}) => [
|
|
1536
1606
|
"[data-has-focus] & .cm-ref-tag": {
|
1537
1607
|
opacity: "1"
|
1538
1608
|
},
|
1539
|
-
"[data-is-attention-source] & .cm-ref-tag": {
|
1540
|
-
opacity: "1"
|
1541
|
-
},
|
1542
1609
|
".cm-ref-tag button": {
|
1543
1610
|
display: "grid",
|
1544
1611
|
alignItems: "center",
|
@@ -1548,10 +1615,259 @@ var floatingMenu = (options = {}) => [
|
|
1548
1615
|
}
|
1549
1616
|
})
|
1550
1617
|
];
|
1618
|
+
var commandRangeEffect = StateEffect3.define();
|
1619
|
+
var commandMenuState = StateField3.define({
|
1620
|
+
create: () => null,
|
1621
|
+
update: (value, tr) => {
|
1622
|
+
let newValue = value;
|
1623
|
+
for (const effect of tr.effects) {
|
1624
|
+
if (effect.is(commandRangeEffect)) {
|
1625
|
+
newValue = effect.value;
|
1626
|
+
}
|
1627
|
+
}
|
1628
|
+
return newValue;
|
1629
|
+
}
|
1630
|
+
});
|
1631
|
+
var commandMenu = (options) => {
|
1632
|
+
const commandMenuPlugin = ViewPlugin6.fromClass(class {
|
1633
|
+
constructor(view) {
|
1634
|
+
this.view = view;
|
1635
|
+
this.decorations = Decoration5.none;
|
1636
|
+
}
|
1637
|
+
// TODO(wittjosiah): The decorations are repainted on every update, this occasionally causes menu to flicker.
|
1638
|
+
update(update2) {
|
1639
|
+
const builder = new RangeSetBuilder3();
|
1640
|
+
const selection = update2.view.state.selection.main;
|
1641
|
+
const { range: activeRange, trigger } = update2.view.state.field(commandMenuState) ?? {};
|
1642
|
+
const shouldShowWidget = activeRange && selection.head >= activeRange.from && selection.head <= activeRange.to;
|
1643
|
+
if (shouldShowWidget) {
|
1644
|
+
builder.add(activeRange.from, activeRange.to, Decoration5.mark({
|
1645
|
+
tagName: "dx-ref-tag",
|
1646
|
+
class: "cm-ref-tag",
|
1647
|
+
attributes: {
|
1648
|
+
"data-auto-trigger": "true",
|
1649
|
+
"data-trigger": trigger
|
1650
|
+
}
|
1651
|
+
}));
|
1652
|
+
}
|
1653
|
+
const activeRangeChanged = update2.transactions.some((tr) => tr.effects.some((effect) => effect.is(commandRangeEffect)));
|
1654
|
+
if (activeRange && activeRangeChanged && trigger) {
|
1655
|
+
const content = update2.view.state.sliceDoc(activeRange.from + 1, activeRange.to);
|
1656
|
+
options.onTextChange?.(trigger, content);
|
1657
|
+
}
|
1658
|
+
this.decorations = builder.finish();
|
1659
|
+
}
|
1660
|
+
}, {
|
1661
|
+
decorations: (v) => v.decorations
|
1662
|
+
});
|
1663
|
+
const triggers = Array.isArray(options.trigger) ? options.trigger : [
|
1664
|
+
options.trigger
|
1665
|
+
];
|
1666
|
+
const commandKeymap = keymap4.of([
|
1667
|
+
...triggers.map((trigger) => ({
|
1668
|
+
key: trigger,
|
1669
|
+
run: (view) => {
|
1670
|
+
const selection = view.state.selection.main;
|
1671
|
+
const line = view.state.doc.lineAt(selection.head);
|
1672
|
+
const shouldTrigger = line.text.trim() === "" || selection.head === line.from || selection.head > line.from && line.text[selection.head - line.from - 1] === " ";
|
1673
|
+
if (shouldTrigger) {
|
1674
|
+
view.dispatch({
|
1675
|
+
changes: {
|
1676
|
+
from: selection.head,
|
1677
|
+
insert: trigger
|
1678
|
+
},
|
1679
|
+
selection: {
|
1680
|
+
anchor: selection.head + 1,
|
1681
|
+
head: selection.head + 1
|
1682
|
+
},
|
1683
|
+
effects: commandRangeEffect.of({
|
1684
|
+
trigger,
|
1685
|
+
range: {
|
1686
|
+
from: selection.head,
|
1687
|
+
to: selection.head + 1
|
1688
|
+
}
|
1689
|
+
})
|
1690
|
+
});
|
1691
|
+
return true;
|
1692
|
+
}
|
1693
|
+
return false;
|
1694
|
+
}
|
1695
|
+
})),
|
1696
|
+
{
|
1697
|
+
key: "Enter",
|
1698
|
+
run: (view) => {
|
1699
|
+
const activeRange = view.state.field(commandMenuState)?.range;
|
1700
|
+
if (activeRange) {
|
1701
|
+
view.dispatch({
|
1702
|
+
changes: {
|
1703
|
+
from: activeRange.from,
|
1704
|
+
to: activeRange.to,
|
1705
|
+
insert: ""
|
1706
|
+
}
|
1707
|
+
});
|
1708
|
+
options.onEnter?.();
|
1709
|
+
return true;
|
1710
|
+
}
|
1711
|
+
return false;
|
1712
|
+
}
|
1713
|
+
},
|
1714
|
+
{
|
1715
|
+
key: "ArrowDown",
|
1716
|
+
run: (view) => {
|
1717
|
+
const activeRange = view.state.field(commandMenuState)?.range;
|
1718
|
+
if (activeRange) {
|
1719
|
+
options.onArrowDown?.();
|
1720
|
+
return true;
|
1721
|
+
}
|
1722
|
+
return false;
|
1723
|
+
}
|
1724
|
+
},
|
1725
|
+
{
|
1726
|
+
key: "ArrowUp",
|
1727
|
+
run: (view) => {
|
1728
|
+
const activeRange = view.state.field(commandMenuState)?.range;
|
1729
|
+
if (activeRange) {
|
1730
|
+
options.onArrowUp?.();
|
1731
|
+
return true;
|
1732
|
+
}
|
1733
|
+
return false;
|
1734
|
+
}
|
1735
|
+
}
|
1736
|
+
]);
|
1737
|
+
const updateListener = EditorView8.updateListener.of((update2) => {
|
1738
|
+
const { trigger, range: activeRange } = update2.view.state.field(commandMenuState) ?? {};
|
1739
|
+
if (!activeRange || !trigger) {
|
1740
|
+
return;
|
1741
|
+
}
|
1742
|
+
const selection = update2.view.state.selection.main;
|
1743
|
+
const firstChar = update2.view.state.doc.sliceString(activeRange.from, activeRange.from + 1);
|
1744
|
+
const shouldRemove = firstChar !== trigger || // Trigger deleted.
|
1745
|
+
selection.head < activeRange.from || // Cursor moved before the range.
|
1746
|
+
selection.head > activeRange.to + 1;
|
1747
|
+
const nextRange = shouldRemove ? null : update2.docChanged ? {
|
1748
|
+
from: activeRange.from,
|
1749
|
+
to: selection.head
|
1750
|
+
} : activeRange;
|
1751
|
+
if (nextRange !== activeRange) {
|
1752
|
+
update2.view.dispatch({
|
1753
|
+
effects: commandRangeEffect.of(nextRange ? {
|
1754
|
+
trigger,
|
1755
|
+
range: nextRange
|
1756
|
+
} : null)
|
1757
|
+
});
|
1758
|
+
}
|
1759
|
+
if (shouldRemove) {
|
1760
|
+
options.onDeactivate?.();
|
1761
|
+
}
|
1762
|
+
});
|
1763
|
+
return [
|
1764
|
+
multilinePlaceholder(options.placeholder ?? `Press '${Array.isArray(options.trigger) ? options.trigger[0] : options.trigger}' for commands`),
|
1765
|
+
Prec.highest(commandKeymap),
|
1766
|
+
updateListener,
|
1767
|
+
commandMenuState,
|
1768
|
+
commandMenuPlugin
|
1769
|
+
];
|
1770
|
+
};
|
1771
|
+
var useCommandMenu = ({ viewRef, trigger, placeholder: placeholder2, getGroups }) => {
|
1772
|
+
const triggerRef = useRef(null);
|
1773
|
+
const currentRef = useRef(null);
|
1774
|
+
const groupsRef = useRef([]);
|
1775
|
+
const [currentItem, setCurrentItem] = useState();
|
1776
|
+
const [open, setOpen] = useState(false);
|
1777
|
+
const [_, update2] = useState({});
|
1778
|
+
const handleOpenChange = useCallback(async (open2, trigger2) => {
|
1779
|
+
if (open2 && trigger2) {
|
1780
|
+
groupsRef.current = await getGroups(trigger2);
|
1781
|
+
}
|
1782
|
+
setOpen(open2);
|
1783
|
+
if (!open2) {
|
1784
|
+
triggerRef.current = null;
|
1785
|
+
setCurrentItem(void 0);
|
1786
|
+
viewRef.current?.dispatch({
|
1787
|
+
effects: [
|
1788
|
+
commandRangeEffect.of(null)
|
1789
|
+
]
|
1790
|
+
});
|
1791
|
+
}
|
1792
|
+
}, [
|
1793
|
+
getGroups
|
1794
|
+
]);
|
1795
|
+
const handleActivate = useCallback(async (event) => {
|
1796
|
+
const item = getItem(groupsRef.current, currentItem);
|
1797
|
+
if (item) {
|
1798
|
+
currentRef.current = item;
|
1799
|
+
}
|
1800
|
+
triggerRef.current = event.trigger;
|
1801
|
+
const triggerKey = event.trigger.getAttribute("data-trigger");
|
1802
|
+
if (!open && triggerKey) {
|
1803
|
+
await handleOpenChange(true, triggerKey);
|
1804
|
+
}
|
1805
|
+
}, [
|
1806
|
+
open,
|
1807
|
+
handleOpenChange
|
1808
|
+
]);
|
1809
|
+
const handleSelect = useCallback((item) => {
|
1810
|
+
const view = viewRef.current;
|
1811
|
+
if (!view) {
|
1812
|
+
return;
|
1813
|
+
}
|
1814
|
+
const selection = view.state.selection.main;
|
1815
|
+
void item.onSelect?.(view, selection.head);
|
1816
|
+
}, []);
|
1817
|
+
const serializedTrigger = Array.isArray(trigger) ? trigger.join(",") : trigger;
|
1818
|
+
const _commandMenu = useMemo2(() => commandMenu({
|
1819
|
+
trigger,
|
1820
|
+
placeholder: placeholder2,
|
1821
|
+
onArrowDown: () => {
|
1822
|
+
setCurrentItem((currentItem2) => {
|
1823
|
+
const next = getNextItem(groupsRef.current, currentItem2);
|
1824
|
+
currentRef.current = next;
|
1825
|
+
return next.id;
|
1826
|
+
});
|
1827
|
+
},
|
1828
|
+
onArrowUp: () => {
|
1829
|
+
setCurrentItem((currentItem2) => {
|
1830
|
+
const previous = getPreviousItem(groupsRef.current, currentItem2);
|
1831
|
+
currentRef.current = previous;
|
1832
|
+
return previous.id;
|
1833
|
+
});
|
1834
|
+
},
|
1835
|
+
onDeactivate: () => handleOpenChange(false),
|
1836
|
+
onEnter: () => {
|
1837
|
+
if (currentRef.current) {
|
1838
|
+
handleSelect(currentRef.current);
|
1839
|
+
}
|
1840
|
+
},
|
1841
|
+
onTextChange: async (trigger2, text) => {
|
1842
|
+
groupsRef.current = await getGroups(trigger2, text);
|
1843
|
+
const firstItem = groupsRef.current.filter((group) => group.items.length > 0)[0]?.items[0];
|
1844
|
+
if (firstItem) {
|
1845
|
+
setCurrentItem(firstItem.id);
|
1846
|
+
currentRef.current = firstItem;
|
1847
|
+
}
|
1848
|
+
update2({});
|
1849
|
+
}
|
1850
|
+
}), [
|
1851
|
+
handleOpenChange,
|
1852
|
+
getGroups,
|
1853
|
+
serializedTrigger,
|
1854
|
+
placeholder2
|
1855
|
+
]);
|
1856
|
+
return {
|
1857
|
+
commandMenu: _commandMenu,
|
1858
|
+
currentItem,
|
1859
|
+
groupsRef,
|
1860
|
+
ref: triggerRef,
|
1861
|
+
open,
|
1862
|
+
onActivate: handleActivate,
|
1863
|
+
onOpenChange: setOpen,
|
1864
|
+
onSelect: handleSelect
|
1865
|
+
};
|
1866
|
+
};
|
1551
1867
|
|
1552
1868
|
// packages/ui/react-ui-editor/src/extensions/command/typeahead.ts
|
1553
|
-
import { EditorSelection, Prec, RangeSetBuilder as
|
1554
|
-
import { Decoration as
|
1869
|
+
import { EditorSelection, Prec as Prec2, RangeSetBuilder as RangeSetBuilder4 } from "@codemirror/state";
|
1870
|
+
import { Decoration as Decoration6, keymap as keymap5, ViewPlugin as ViewPlugin7 } from "@codemirror/view";
|
1555
1871
|
var typeahead = ({ onComplete } = {}) => {
|
1556
1872
|
let hint;
|
1557
1873
|
const complete = (view) => {
|
@@ -1572,12 +1888,12 @@ var typeahead = ({ onComplete } = {}) => {
|
|
1572
1888
|
return true;
|
1573
1889
|
};
|
1574
1890
|
return [
|
1575
|
-
|
1891
|
+
ViewPlugin7.fromClass(class {
|
1576
1892
|
constructor() {
|
1577
|
-
this.decorations =
|
1893
|
+
this.decorations = Decoration6.none;
|
1578
1894
|
}
|
1579
1895
|
update(update2) {
|
1580
|
-
const builder = new
|
1896
|
+
const builder = new RangeSetBuilder4();
|
1581
1897
|
const selection = update2.view.state.selection.main;
|
1582
1898
|
const line = update2.view.state.doc.lineAt(selection.from);
|
1583
1899
|
if (selection.from === selection.to && selection.from === line.to) {
|
@@ -1586,7 +1902,7 @@ var typeahead = ({ onComplete } = {}) => {
|
|
1586
1902
|
line: str
|
1587
1903
|
});
|
1588
1904
|
if (hint) {
|
1589
|
-
builder.add(selection.from, selection.to,
|
1905
|
+
builder.add(selection.from, selection.to, Decoration6.widget({
|
1590
1906
|
widget: new Hint(hint)
|
1591
1907
|
}));
|
1592
1908
|
}
|
@@ -1597,7 +1913,7 @@ var typeahead = ({ onComplete } = {}) => {
|
|
1597
1913
|
decorations: (v) => v.decorations
|
1598
1914
|
}),
|
1599
1915
|
// Keys.
|
1600
|
-
|
1916
|
+
Prec2.highest(keymap5.of([
|
1601
1917
|
{
|
1602
1918
|
key: "Tab",
|
1603
1919
|
preventDefault: true,
|
@@ -1634,8 +1950,8 @@ var matchCompletion = (completion, word) => {
|
|
1634
1950
|
|
1635
1951
|
// packages/ui/react-ui-editor/src/extensions/comments.ts
|
1636
1952
|
import { invertedEffects } from "@codemirror/commands";
|
1637
|
-
import { StateEffect as
|
1638
|
-
import { hoverTooltip, keymap as
|
1953
|
+
import { StateEffect as StateEffect4, StateField as StateField4 } from "@codemirror/state";
|
1954
|
+
import { hoverTooltip, keymap as keymap7, Decoration as Decoration7, EditorView as EditorView10, ViewPlugin as ViewPlugin8 } from "@codemirror/view";
|
1639
1955
|
import sortBy from "lodash.sortby";
|
1640
1956
|
import { useEffect } from "react";
|
1641
1957
|
import { debounce as debounce2 } from "@dxos/async";
|
@@ -1644,7 +1960,7 @@ import { isNonNullable } from "@dxos/util";
|
|
1644
1960
|
|
1645
1961
|
// packages/ui/react-ui-editor/src/extensions/selection.ts
|
1646
1962
|
import { Transaction } from "@codemirror/state";
|
1647
|
-
import { EditorView as
|
1963
|
+
import { EditorView as EditorView9, keymap as keymap6 } from "@codemirror/view";
|
1648
1964
|
import { debounce } from "@dxos/async";
|
1649
1965
|
import { invariant as invariant3 } from "@dxos/invariant";
|
1650
1966
|
import { isNotFalsy } from "@dxos/util";
|
@@ -1655,7 +1971,7 @@ var createEditorStateTransaction = ({ scrollTo, selection }) => {
|
|
1655
1971
|
return {
|
1656
1972
|
selection,
|
1657
1973
|
scrollIntoView: !scrollTo,
|
1658
|
-
effects: scrollTo ?
|
1974
|
+
effects: scrollTo ? EditorView9.scrollIntoView(scrollTo, {
|
1659
1975
|
yMargin: 96
|
1660
1976
|
}) : void 0,
|
1661
1977
|
annotations: Transaction.userEvent.of(stateRestoreAnnotation)
|
@@ -1697,7 +2013,7 @@ var selectionState = ({ getState, setState } = {}) => {
|
|
1697
2013
|
// setStateDebounced(id, {});
|
1698
2014
|
// },
|
1699
2015
|
// }),
|
1700
|
-
|
2016
|
+
EditorView9.updateListener.of(({ view, transactions }) => {
|
1701
2017
|
const id = view.state.facet(documentId);
|
1702
2018
|
if (!id || transactions.some((tr) => tr.isUserEvent(stateRestoreAnnotation))) {
|
1703
2019
|
return;
|
@@ -1720,7 +2036,7 @@ var selectionState = ({ getState, setState } = {}) => {
|
|
1720
2036
|
}
|
1721
2037
|
}
|
1722
2038
|
}),
|
1723
|
-
getState &&
|
2039
|
+
getState && keymap6.of([
|
1724
2040
|
{
|
1725
2041
|
key: "ctrl-r",
|
1726
2042
|
run: (view) => {
|
@@ -1737,10 +2053,10 @@ var selectionState = ({ getState, setState } = {}) => {
|
|
1737
2053
|
|
1738
2054
|
// packages/ui/react-ui-editor/src/extensions/comments.ts
|
1739
2055
|
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/comments.ts";
|
1740
|
-
var setComments =
|
1741
|
-
var setSelection =
|
1742
|
-
var setCommentState =
|
1743
|
-
var commentsState =
|
2056
|
+
var setComments = StateEffect4.define();
|
2057
|
+
var setSelection = StateEffect4.define();
|
2058
|
+
var setCommentState = StateEffect4.define();
|
2059
|
+
var commentsState = StateField4.define({
|
1744
2060
|
create: (state) => ({
|
1745
2061
|
id: state.facet(documentId),
|
1746
2062
|
comments: [],
|
@@ -1778,7 +2094,7 @@ var commentsState = StateField3.define({
|
|
1778
2094
|
return value;
|
1779
2095
|
}
|
1780
2096
|
});
|
1781
|
-
var styles2 =
|
2097
|
+
var styles2 = EditorView10.theme({
|
1782
2098
|
".cm-comment, .cm-comment-current": {
|
1783
2099
|
margin: "0 -3px",
|
1784
2100
|
padding: "3px",
|
@@ -1791,14 +2107,14 @@ var styles2 = EditorView9.theme({
|
|
1791
2107
|
textDecoration: "underline"
|
1792
2108
|
}
|
1793
2109
|
});
|
1794
|
-
var createCommentMark = (id, isCurrent) =>
|
2110
|
+
var createCommentMark = (id, isCurrent) => Decoration7.mark({
|
1795
2111
|
class: isCurrent ? "cm-comment-current" : "cm-comment",
|
1796
2112
|
attributes: {
|
1797
2113
|
"data-testid": "cm-comment",
|
1798
2114
|
"data-comment-id": id
|
1799
2115
|
}
|
1800
2116
|
});
|
1801
|
-
var commentsDecorations =
|
2117
|
+
var commentsDecorations = EditorView10.decorations.compute([
|
1802
2118
|
commentsState
|
1803
2119
|
], (state) => {
|
1804
2120
|
const { selection: { current }, comments: comments2 } = state.field(commentsState);
|
@@ -1818,10 +2134,10 @@ var commentsDecorations = EditorView9.decorations.compute([
|
|
1818
2134
|
const mark = createCommentMark(comment.comment.id, comment.comment.id === current);
|
1819
2135
|
return mark.range(range.from, range.to);
|
1820
2136
|
}).filter(isNonNullable);
|
1821
|
-
return
|
2137
|
+
return Decoration7.set(decorations2);
|
1822
2138
|
});
|
1823
|
-
var commentClickedEffect =
|
1824
|
-
var handleCommentClick =
|
2139
|
+
var commentClickedEffect = StateEffect4.define();
|
2140
|
+
var handleCommentClick = EditorView10.domEventHandlers({
|
1825
2141
|
click: (event, view) => {
|
1826
2142
|
let target = event.target;
|
1827
2143
|
const editorRoot = view.dom;
|
@@ -1860,7 +2176,7 @@ var trackPastedComments = (onUpdate) => {
|
|
1860
2176
|
}
|
1861
2177
|
};
|
1862
2178
|
return [
|
1863
|
-
|
2179
|
+
EditorView10.domEventHandlers({
|
1864
2180
|
cut: handleTrack,
|
1865
2181
|
copy: handleTrack
|
1866
2182
|
}),
|
@@ -1882,7 +2198,7 @@ var trackPastedComments = (onUpdate) => {
|
|
1882
2198
|
return effects;
|
1883
2199
|
}),
|
1884
2200
|
// Handle paste or the undo of comment deletion.
|
1885
|
-
|
2201
|
+
EditorView10.updateListener.of((update2) => {
|
1886
2202
|
const restore = [];
|
1887
2203
|
for (let i = 0; i < update2.transactions.length; i++) {
|
1888
2204
|
const tr = update2.transactions[i];
|
@@ -1938,7 +2254,7 @@ var mapTrackedComment = (comment, changes) => ({
|
|
1938
2254
|
from: changes.mapPos(comment.from, 1),
|
1939
2255
|
to: changes.mapPos(comment.to, 1)
|
1940
2256
|
});
|
1941
|
-
var restoreCommentEffect =
|
2257
|
+
var restoreCommentEffect = StateEffect4.define({
|
1942
2258
|
map: mapTrackedComment
|
1943
2259
|
});
|
1944
2260
|
var createComment = (view) => {
|
@@ -1983,7 +2299,7 @@ var comments = (options = {}) => {
|
|
1983
2299
|
//
|
1984
2300
|
// Keymap.
|
1985
2301
|
//
|
1986
|
-
options.onCreate &&
|
2302
|
+
options.onCreate && keymap7.of([
|
1987
2303
|
{
|
1988
2304
|
key: shortcut,
|
1989
2305
|
run: callbackWrapper(createComment)
|
@@ -2024,7 +2340,7 @@ var comments = (options = {}) => {
|
|
2024
2340
|
//
|
2025
2341
|
// Track deleted ranges and update ranges for decorations.
|
2026
2342
|
//
|
2027
|
-
|
2343
|
+
EditorView10.updateListener.of(({ view, state, changes }) => {
|
2028
2344
|
let mod = false;
|
2029
2345
|
const { comments: comments2, ...value } = state.field(commentsState);
|
2030
2346
|
changes.iterChanges((from, to, from2, to2) => {
|
@@ -2056,7 +2372,7 @@ var comments = (options = {}) => {
|
|
2056
2372
|
//
|
2057
2373
|
// Track selection/proximity.
|
2058
2374
|
//
|
2059
|
-
|
2375
|
+
EditorView10.updateListener.of(({ view, state }) => {
|
2060
2376
|
let min = Infinity;
|
2061
2377
|
const { selection: { current, closest }, comments: comments2 } = state.field(commentsState);
|
2062
2378
|
const { head } = state.selection.main;
|
@@ -2110,7 +2426,7 @@ var scrollThreadIntoView = (view, id, center = true) => {
|
|
2110
2426
|
anchor: range.from
|
2111
2427
|
} : void 0,
|
2112
2428
|
effects: [
|
2113
|
-
needsScroll ?
|
2429
|
+
needsScroll ? EditorView10.scrollIntoView(range.from, center ? {
|
2114
2430
|
y: "center"
|
2115
2431
|
} : void 0) : [],
|
2116
2432
|
needsSelectionUpdate ? setSelection.of({
|
@@ -2140,7 +2456,7 @@ var ExternalCommentSync = class {
|
|
2140
2456
|
this.unsubscribe = subscribe(updateComments);
|
2141
2457
|
}
|
2142
2458
|
};
|
2143
|
-
var createExternalCommentSync = (id, subscribe, getComments) =>
|
2459
|
+
var createExternalCommentSync = (id, subscribe, getComments) => ViewPlugin8.fromClass(class {
|
2144
2460
|
constructor(view) {
|
2145
2461
|
return new ExternalCommentSync(view, id, subscribe, getComments);
|
2146
2462
|
}
|
@@ -2162,20 +2478,20 @@ var useComments = (view, id, comments2) => {
|
|
2162
2478
|
|
2163
2479
|
// packages/ui/react-ui-editor/src/extensions/debug.ts
|
2164
2480
|
import { syntaxTree } from "@codemirror/language";
|
2165
|
-
import { StateField as
|
2481
|
+
import { StateField as StateField5 } from "@codemirror/state";
|
2166
2482
|
var debugNodeLogger = (log9 = console.log) => {
|
2167
2483
|
const logTokens = (state) => syntaxTree(state).iterate({
|
2168
2484
|
enter: (node) => log9(node.type)
|
2169
2485
|
});
|
2170
|
-
return
|
2486
|
+
return StateField5.define({
|
2171
2487
|
create: (state) => logTokens(state),
|
2172
2488
|
update: (_, tr) => logTokens(tr.state)
|
2173
2489
|
});
|
2174
2490
|
};
|
2175
2491
|
|
2176
2492
|
// packages/ui/react-ui-editor/src/extensions/dnd.ts
|
2177
|
-
import { dropCursor, EditorView as
|
2178
|
-
var styles3 =
|
2493
|
+
import { dropCursor, EditorView as EditorView11 } from "@codemirror/view";
|
2494
|
+
var styles3 = EditorView11.theme({
|
2179
2495
|
".cm-dropCursor": {
|
2180
2496
|
borderLeft: "2px solid var(--dx-accentText)",
|
2181
2497
|
color: "var(--dx-accentText)",
|
@@ -2189,7 +2505,7 @@ var dropFile = (options = {}) => {
|
|
2189
2505
|
return [
|
2190
2506
|
styles3,
|
2191
2507
|
dropCursor(),
|
2192
|
-
|
2508
|
+
EditorView11.domEventHandlers({
|
2193
2509
|
drop: (event, view) => {
|
2194
2510
|
event.preventDefault();
|
2195
2511
|
const files = event.dataTransfer?.files;
|
@@ -2216,7 +2532,7 @@ import { bracketMatching, defaultHighlightStyle, syntaxHighlighting } from "@cod
|
|
2216
2532
|
import { searchKeymap } from "@codemirror/search";
|
2217
2533
|
import { EditorState } from "@codemirror/state";
|
2218
2534
|
import { oneDarkHighlightStyle } from "@codemirror/theme-one-dark";
|
2219
|
-
import { EditorView as
|
2535
|
+
import { EditorView as EditorView14, ViewPlugin as ViewPlugin9, drawSelection, dropCursor as dropCursor2, highlightActiveLine, keymap as keymap8, lineNumbers, placeholder, scrollPastEnd } from "@codemirror/view";
|
2220
2536
|
import defaultsDeep2 from "lodash.defaultsdeep";
|
2221
2537
|
import merge from "lodash.merge";
|
2222
2538
|
import { generateName } from "@dxos/display-name";
|
@@ -2224,10 +2540,10 @@ import { log as log5 } from "@dxos/log";
|
|
2224
2540
|
import { hexToHue, isNotFalsy as isNotFalsy2 } from "@dxos/util";
|
2225
2541
|
|
2226
2542
|
// packages/ui/react-ui-editor/src/extensions/focus.ts
|
2227
|
-
import { StateEffect as
|
2228
|
-
import { EditorView as
|
2229
|
-
var focusEffect =
|
2230
|
-
var focusField =
|
2543
|
+
import { StateEffect as StateEffect5, StateField as StateField6 } from "@codemirror/state";
|
2544
|
+
import { EditorView as EditorView12 } from "@codemirror/view";
|
2545
|
+
var focusEffect = StateEffect5.define();
|
2546
|
+
var focusField = StateField6.define({
|
2231
2547
|
create: () => false,
|
2232
2548
|
update: (value, tr) => {
|
2233
2549
|
for (const effect of tr.effects) {
|
@@ -2240,7 +2556,7 @@ var focusField = StateField5.define({
|
|
2240
2556
|
});
|
2241
2557
|
var focus = [
|
2242
2558
|
focusField,
|
2243
|
-
|
2559
|
+
EditorView12.domEventHandlers({
|
2244
2560
|
focus: (event, view) => {
|
2245
2561
|
setTimeout(() => view.dispatch({
|
2246
2562
|
effects: focusEffect.of(true)
|
@@ -2254,6 +2570,10 @@ var focus = [
|
|
2254
2570
|
})
|
2255
2571
|
];
|
2256
2572
|
|
2573
|
+
// packages/ui/react-ui-editor/src/defaults.ts
|
2574
|
+
import { EditorView as EditorView13 } from "@codemirror/view";
|
2575
|
+
import { mx as mx2 } from "@dxos/react-ui-theme";
|
2576
|
+
|
2257
2577
|
// packages/ui/react-ui-editor/src/styles/markdown.ts
|
2258
2578
|
import { mx } from "@dxos/react-ui-theme";
|
2259
2579
|
var headings = {
|
@@ -2495,6 +2815,31 @@ var defaultTheme = {
|
|
2495
2815
|
}
|
2496
2816
|
};
|
2497
2817
|
|
2818
|
+
// packages/ui/react-ui-editor/src/defaults.ts
|
2819
|
+
var editorWidth = "!mli-auto is-full max-is-[min(50rem,100%-4rem)]";
|
2820
|
+
var editorSlots = {
|
2821
|
+
scroll: {
|
2822
|
+
className: "pbs-2"
|
2823
|
+
},
|
2824
|
+
content: {
|
2825
|
+
className: editorWidth
|
2826
|
+
}
|
2827
|
+
};
|
2828
|
+
var editorGutter = EditorView13.theme({
|
2829
|
+
".cm-gutters": {
|
2830
|
+
background: "var(--dx-baseSurface)",
|
2831
|
+
paddingRight: "1rem"
|
2832
|
+
}
|
2833
|
+
});
|
2834
|
+
var editorMonospace = EditorView13.theme({
|
2835
|
+
".cm-content": {
|
2836
|
+
fontFamily: fontMono
|
2837
|
+
}
|
2838
|
+
});
|
2839
|
+
var editorWithToolbarLayout = "grid grid-cols-1 grid-rows-[min-content_1fr] data-[toolbar=disabled]:grid-rows-[1fr] justify-center content-start overflow-hidden";
|
2840
|
+
var stackItemContentEditorClassNames = (role) => mx2("attention-surface dx-focus-ring-inset data-[toolbar=disabled]:pbs-2", role === "section" ? "[&_.cm-scroller]:overflow-hidden [&_.cm-scroller]:min-bs-24" : "min-bs-0");
|
2841
|
+
var stackItemContentToolbarClassNames = (role) => mx2("relative z-[1] flex is-full bg-toolbarSurface border-be border-subduedSeparator", role === "section" && "sticky block-start-0 -mbe-px min-is-0");
|
2842
|
+
|
2498
2843
|
// packages/ui/react-ui-editor/src/extensions/factories.ts
|
2499
2844
|
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/factories.ts";
|
2500
2845
|
var preventNewline = EditorState.transactionFilter.of((tr) => tr.newDoc.lines > 1 ? [] : tr);
|
@@ -2519,10 +2864,10 @@ var createBasicExtensions = (_props) => {
|
|
2519
2864
|
const props = defaultsDeep2({}, _props, defaultBasicOptions);
|
2520
2865
|
return [
|
2521
2866
|
// NOTE: Doesn't catch errors in keymap functions.
|
2522
|
-
|
2867
|
+
EditorView14.exceptionSink.of((err) => {
|
2523
2868
|
log5.catch(err, void 0, {
|
2524
2869
|
F: __dxlog_file8,
|
2525
|
-
L:
|
2870
|
+
L: 100,
|
2526
2871
|
S: void 0,
|
2527
2872
|
C: (f, a) => f(...a)
|
2528
2873
|
});
|
@@ -2534,18 +2879,22 @@ var createBasicExtensions = (_props) => {
|
|
2534
2879
|
props.drawSelection && drawSelection({
|
2535
2880
|
cursorBlinkRate: 1200
|
2536
2881
|
}),
|
2537
|
-
props.editable !== void 0 &&
|
2882
|
+
props.editable !== void 0 && EditorView14.editable.of(props.editable),
|
2538
2883
|
props.focus && focus,
|
2539
2884
|
props.highlightActiveLine && highlightActiveLine(),
|
2540
2885
|
props.history && history(),
|
2541
|
-
props.lineNumbers &&
|
2542
|
-
|
2886
|
+
props.lineNumbers && [
|
2887
|
+
lineNumbers(),
|
2888
|
+
editorGutter
|
2889
|
+
],
|
2890
|
+
props.lineWrapping && EditorView14.lineWrapping,
|
2891
|
+
props.monospace && editorMonospace,
|
2543
2892
|
props.placeholder && placeholder(props.placeholder),
|
2544
2893
|
props.readOnly !== void 0 && EditorState.readOnly.of(props.readOnly),
|
2545
2894
|
props.scrollPastEnd && scrollPastEnd(),
|
2546
2895
|
props.tabSize && EditorState.tabSize.of(props.tabSize),
|
2547
2896
|
// https://codemirror.net/docs/ref/#view.KeyBinding
|
2548
|
-
|
2897
|
+
keymap8.of([
|
2549
2898
|
...(props.keymap && keymaps[props.keymap]) ?? [],
|
2550
2899
|
// NOTE: Tabs are also configured by markdown extension.
|
2551
2900
|
// https://codemirror.net/docs/ref/#commands.indentWithTab
|
@@ -2576,17 +2925,17 @@ var defaultThemeSlots = {
|
|
2576
2925
|
var createThemeExtensions = ({ themeMode, styles: styles4, syntaxHighlighting: _syntaxHighlighting, slots: _slots } = {}) => {
|
2577
2926
|
const slots = defaultsDeep2({}, _slots, defaultThemeSlots);
|
2578
2927
|
return [
|
2579
|
-
|
2580
|
-
|
2928
|
+
EditorView14.darkTheme.of(themeMode === "dark"),
|
2929
|
+
EditorView14.baseTheme(styles4 ? merge({}, defaultTheme, styles4) : defaultTheme),
|
2581
2930
|
// https://github.com/codemirror/theme-one-dark
|
2582
2931
|
_syntaxHighlighting && (themeMode === "dark" ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle)),
|
2583
|
-
slots.editor?.className &&
|
2932
|
+
slots.editor?.className && EditorView14.editorAttributes.of({
|
2584
2933
|
class: slots.editor.className
|
2585
2934
|
}),
|
2586
|
-
slots.content?.className &&
|
2935
|
+
slots.content?.className && EditorView14.contentAttributes.of({
|
2587
2936
|
class: slots.content.className
|
2588
2937
|
}),
|
2589
|
-
slots.scroll?.className &&
|
2938
|
+
slots.scroll?.className && ViewPlugin9.fromClass(class {
|
2590
2939
|
constructor(view) {
|
2591
2940
|
view.scrollDOM.classList.add(slots.scroll.className);
|
2592
2941
|
}
|
@@ -2617,7 +2966,7 @@ var createDataExtensions = ({ id, text, space, identity }) => {
|
|
2617
2966
|
|
2618
2967
|
// packages/ui/react-ui-editor/src/extensions/folding.tsx
|
2619
2968
|
import { codeFolding, foldGutter } from "@codemirror/language";
|
2620
|
-
import { EditorView as
|
2969
|
+
import { EditorView as EditorView15 } from "@codemirror/view";
|
2621
2970
|
import React2 from "react";
|
2622
2971
|
import { Icon } from "@dxos/react-ui";
|
2623
2972
|
var folding = (_props = {}) => [
|
@@ -2641,7 +2990,7 @@ var folding = (_props = {}) => [
|
|
2641
2990
|
}));
|
2642
2991
|
}
|
2643
2992
|
}),
|
2644
|
-
|
2993
|
+
EditorView15.theme({
|
2645
2994
|
".cm-foldGutter": {
|
2646
2995
|
opacity: 0.3,
|
2647
2996
|
transition: "opacity 0.3s",
|
@@ -2654,27 +3003,27 @@ var folding = (_props = {}) => [
|
|
2654
3003
|
];
|
2655
3004
|
|
2656
3005
|
// packages/ui/react-ui-editor/src/extensions/hashtag.tsx
|
2657
|
-
import { Decoration as
|
2658
|
-
import { getHashColor, mx as
|
2659
|
-
var TagWidget = class extends
|
3006
|
+
import { Decoration as Decoration8, EditorView as EditorView16, MatchDecorator, ViewPlugin as ViewPlugin10, WidgetType as WidgetType4 } from "@codemirror/view";
|
3007
|
+
import { getHashColor, mx as mx3 } from "@dxos/react-ui-theme";
|
3008
|
+
var TagWidget = class extends WidgetType4 {
|
2660
3009
|
constructor(_text) {
|
2661
3010
|
super(), this._text = _text;
|
2662
3011
|
}
|
2663
3012
|
toDOM() {
|
2664
3013
|
const span = document.createElement("span");
|
2665
|
-
span.className =
|
3014
|
+
span.className = mx3("cm-tag", getHashColor(this._text).tag);
|
2666
3015
|
span.textContent = this._text;
|
2667
3016
|
return span;
|
2668
3017
|
}
|
2669
3018
|
};
|
2670
3019
|
var tagMatcher = new MatchDecorator({
|
2671
3020
|
regexp: /#(\w+)\W/g,
|
2672
|
-
decoration: (match) =>
|
3021
|
+
decoration: (match) => Decoration8.replace({
|
2673
3022
|
widget: new TagWidget(match[1])
|
2674
3023
|
})
|
2675
3024
|
});
|
2676
3025
|
var hashtag = () => [
|
2677
|
-
|
3026
|
+
ViewPlugin10.fromClass(class {
|
2678
3027
|
constructor(view) {
|
2679
3028
|
this.tags = tagMatcher.createDeco(view);
|
2680
3029
|
}
|
@@ -2683,11 +3032,11 @@ var hashtag = () => [
|
|
2683
3032
|
}
|
2684
3033
|
}, {
|
2685
3034
|
decorations: (instance) => instance.tags,
|
2686
|
-
provide: (plugin) =>
|
2687
|
-
return view.plugin(plugin)?.tags ||
|
3035
|
+
provide: (plugin) => EditorView16.atomicRanges.of((view) => {
|
3036
|
+
return view.plugin(plugin)?.tags || Decoration8.none;
|
2688
3037
|
})
|
2689
3038
|
}),
|
2690
|
-
|
3039
|
+
EditorView16.theme({
|
2691
3040
|
".cm-tag": {
|
2692
3041
|
borderRadius: "4px",
|
2693
3042
|
marginRight: "6px",
|
@@ -2742,14 +3091,14 @@ var schemaLinter = (validate) => (view) => {
|
|
2742
3091
|
};
|
2743
3092
|
|
2744
3093
|
// packages/ui/react-ui-editor/src/extensions/listener.ts
|
2745
|
-
import { EditorView as
|
3094
|
+
import { EditorView as EditorView17 } from "@codemirror/view";
|
2746
3095
|
var listener = ({ onFocus, onChange }) => {
|
2747
3096
|
const extensions = [];
|
2748
|
-
onFocus && extensions.push(
|
3097
|
+
onFocus && extensions.push(EditorView17.focusChangeEffect.of((_, focusing) => {
|
2749
3098
|
onFocus(focusing);
|
2750
3099
|
return null;
|
2751
3100
|
}));
|
2752
|
-
onChange && extensions.push(
|
3101
|
+
onChange && extensions.push(EditorView17.updateListener.of((update2) => {
|
2753
3102
|
onChange(update2.state.doc.toString(), update2.state.facet(documentId));
|
2754
3103
|
}));
|
2755
3104
|
return extensions;
|
@@ -2759,8 +3108,8 @@ var listener = ({ onFocus, onChange }) => {
|
|
2759
3108
|
import { snippet } from "@codemirror/autocomplete";
|
2760
3109
|
import { syntaxTree as syntaxTree2 } from "@codemirror/language";
|
2761
3110
|
import { EditorSelection as EditorSelection2 } from "@codemirror/state";
|
2762
|
-
import { EditorView as
|
2763
|
-
import { useMemo as
|
3111
|
+
import { EditorView as EditorView18, keymap as keymap9 } from "@codemirror/view";
|
3112
|
+
import { useMemo as useMemo3 } from "react";
|
2764
3113
|
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;
|
2765
3114
|
var Inline = /* @__PURE__ */ function(Inline2) {
|
2766
3115
|
Inline2[Inline2["Strong"] = 0] = "Strong";
|
@@ -3647,7 +3996,7 @@ var toggleCodeblock = (target) => {
|
|
3647
3996
|
};
|
3648
3997
|
var formattingKeymap = (_options = {}) => {
|
3649
3998
|
return [
|
3650
|
-
|
3999
|
+
keymap9.of([
|
3651
4000
|
{
|
3652
4001
|
key: "meta-b",
|
3653
4002
|
run: toggleStrong
|
@@ -3848,7 +4197,7 @@ var getFormatting = (state) => {
|
|
3848
4197
|
};
|
3849
4198
|
};
|
3850
4199
|
var useFormattingState = (state) => {
|
3851
|
-
return
|
4200
|
+
return useMemo3(() => EditorView18.updateListener.of((update2) => {
|
3852
4201
|
if (update2.docChanged || update2.selectionSet) {
|
3853
4202
|
Object.entries(getFormatting(update2.state)).forEach(([key, active]) => {
|
3854
4203
|
state[key] = active;
|
@@ -3913,7 +4262,7 @@ import { markdownLanguage as markdownLanguage3, markdown } from "@codemirror/lan
|
|
3913
4262
|
import { syntaxHighlighting as syntaxHighlighting2 } from "@codemirror/language";
|
3914
4263
|
import { languages } from "@codemirror/language-data";
|
3915
4264
|
import { lintKeymap } from "@codemirror/lint";
|
3916
|
-
import { keymap as
|
4265
|
+
import { keymap as keymap10 } from "@codemirror/view";
|
3917
4266
|
import { isNotFalsy as isNotFalsy3 } from "@dxos/util";
|
3918
4267
|
|
3919
4268
|
// packages/ui/react-ui-editor/src/extensions/markdown/highlight.ts
|
@@ -4120,7 +4469,7 @@ var createMarkdownExtensions = (options = {}) => {
|
|
4120
4469
|
}),
|
4121
4470
|
// Custom styles.
|
4122
4471
|
syntaxHighlighting2(markdownHighlightStyle()),
|
4123
|
-
|
4472
|
+
keymap10.of([
|
4124
4473
|
// https://codemirror.net/docs/ref/#commands.indentWithTab
|
4125
4474
|
options.indentWithTab !== false && indentWithTab2,
|
4126
4475
|
// https://codemirror.net/docs/ref/#commands.defaultKeymap
|
@@ -4133,8 +4482,8 @@ var createMarkdownExtensions = (options = {}) => {
|
|
4133
4482
|
|
4134
4483
|
// packages/ui/react-ui-editor/src/extensions/markdown/debug.ts
|
4135
4484
|
import { syntaxTree as syntaxTree3 } from "@codemirror/language";
|
4136
|
-
import { StateField as
|
4137
|
-
var debugTree = (cb) =>
|
4485
|
+
import { StateField as StateField7 } from "@codemirror/state";
|
4486
|
+
var debugTree = (cb) => StateField7.define({
|
4138
4487
|
create: (state) => cb(convertTreeToJson(state)),
|
4139
4488
|
update: (value, tr) => cb(convertTreeToJson(tr.state))
|
4140
4489
|
});
|
@@ -4160,17 +4509,17 @@ var convertTreeToJson = (state) => {
|
|
4160
4509
|
|
4161
4510
|
// packages/ui/react-ui-editor/src/extensions/markdown/decorate.ts
|
4162
4511
|
import { syntaxTree as syntaxTree7 } from "@codemirror/language";
|
4163
|
-
import { RangeSetBuilder as
|
4164
|
-
import { EditorView as
|
4512
|
+
import { RangeSetBuilder as RangeSetBuilder6, StateEffect as StateEffect6 } from "@codemirror/state";
|
4513
|
+
import { EditorView as EditorView22, Decoration as Decoration11, WidgetType as WidgetType7, ViewPlugin as ViewPlugin12 } from "@codemirror/view";
|
4165
4514
|
import { invariant as invariant4 } from "@dxos/invariant";
|
4166
|
-
import { mx as
|
4515
|
+
import { mx as mx4 } from "@dxos/react-ui-theme";
|
4167
4516
|
|
4168
4517
|
// packages/ui/react-ui-editor/src/extensions/markdown/changes.ts
|
4169
4518
|
import { syntaxTree as syntaxTree4 } from "@codemirror/language";
|
4170
4519
|
import { Transaction as Transaction2 } from "@codemirror/state";
|
4171
|
-
import { ViewPlugin as
|
4520
|
+
import { ViewPlugin as ViewPlugin11 } from "@codemirror/view";
|
4172
4521
|
var adjustChanges = () => {
|
4173
|
-
return
|
4522
|
+
return ViewPlugin11.fromClass(class {
|
4174
4523
|
update(update2) {
|
4175
4524
|
const tree = syntaxTree4(update2.state);
|
4176
4525
|
const adjustments = [];
|
@@ -4311,13 +4660,13 @@ var getValidUrl = (str) => {
|
|
4311
4660
|
|
4312
4661
|
// packages/ui/react-ui-editor/src/extensions/markdown/image.ts
|
4313
4662
|
import { syntaxTree as syntaxTree5 } from "@codemirror/language";
|
4314
|
-
import { StateField as
|
4315
|
-
import { Decoration as
|
4663
|
+
import { StateField as StateField8 } from "@codemirror/state";
|
4664
|
+
import { Decoration as Decoration9, EditorView as EditorView19, WidgetType as WidgetType5 } from "@codemirror/view";
|
4316
4665
|
var image = (_options = {}) => {
|
4317
4666
|
return [
|
4318
|
-
|
4667
|
+
StateField8.define({
|
4319
4668
|
create: (state) => {
|
4320
|
-
return
|
4669
|
+
return Decoration9.set(buildDecorations(0, state.doc.length, state));
|
4321
4670
|
},
|
4322
4671
|
update: (value, tr) => {
|
4323
4672
|
if (!tr.docChanged && !tr.selection) {
|
@@ -4340,7 +4689,7 @@ var image = (_options = {}) => {
|
|
4340
4689
|
add: buildDecorations(from, to, tr.state)
|
4341
4690
|
});
|
4342
4691
|
},
|
4343
|
-
provide: (field) =>
|
4692
|
+
provide: (field) => EditorView19.decorations.from(field)
|
4344
4693
|
})
|
4345
4694
|
];
|
4346
4695
|
};
|
@@ -4358,7 +4707,7 @@ var buildDecorations = (from, to, state) => {
|
|
4358
4707
|
return;
|
4359
4708
|
}
|
4360
4709
|
preloadImage(url);
|
4361
|
-
decorations2.push(
|
4710
|
+
decorations2.push(Decoration9.replace({
|
4362
4711
|
block: true,
|
4363
4712
|
widget: new ImageWidget(url)
|
4364
4713
|
}).range(hide2 ? node.from : node.to, node.to));
|
@@ -4378,7 +4727,7 @@ var preloadImage = (url) => {
|
|
4378
4727
|
preloaded.add(url);
|
4379
4728
|
}
|
4380
4729
|
};
|
4381
|
-
var ImageWidget = class extends
|
4730
|
+
var ImageWidget = class extends WidgetType5 {
|
4382
4731
|
constructor(_url) {
|
4383
4732
|
super(), this._url = _url;
|
4384
4733
|
}
|
@@ -4399,10 +4748,10 @@ var ImageWidget = class extends WidgetType4 {
|
|
4399
4748
|
};
|
4400
4749
|
|
4401
4750
|
// packages/ui/react-ui-editor/src/extensions/markdown/styles.ts
|
4402
|
-
import { EditorView as
|
4751
|
+
import { EditorView as EditorView20 } from "@codemirror/view";
|
4403
4752
|
var bulletListIndentationWidth = 24;
|
4404
4753
|
var orderedListIndentationWidth = 36;
|
4405
|
-
var formattingStyles =
|
4754
|
+
var formattingStyles = EditorView20.theme({
|
4406
4755
|
/**
|
4407
4756
|
* Horizontal rule.
|
4408
4757
|
*/
|
@@ -4523,17 +4872,17 @@ var formattingStyles = EditorView18.theme({
|
|
4523
4872
|
|
4524
4873
|
// packages/ui/react-ui-editor/src/extensions/markdown/table.ts
|
4525
4874
|
import { syntaxTree as syntaxTree6 } from "@codemirror/language";
|
4526
|
-
import { RangeSetBuilder as
|
4527
|
-
import { Decoration as
|
4875
|
+
import { RangeSetBuilder as RangeSetBuilder5, StateField as StateField9 } from "@codemirror/state";
|
4876
|
+
import { Decoration as Decoration10, EditorView as EditorView21, WidgetType as WidgetType6 } from "@codemirror/view";
|
4528
4877
|
var table = (options = {}) => {
|
4529
|
-
return
|
4878
|
+
return StateField9.define({
|
4530
4879
|
create: (state) => update(state, options),
|
4531
4880
|
update: (_, tr) => update(tr.state, options),
|
4532
|
-
provide: (field) =>
|
4881
|
+
provide: (field) => EditorView21.decorations.from(field)
|
4533
4882
|
});
|
4534
4883
|
};
|
4535
4884
|
var update = (state, _options) => {
|
4536
|
-
const builder = new
|
4885
|
+
const builder = new RangeSetBuilder5();
|
4537
4886
|
const cursor = state.selection.main.head;
|
4538
4887
|
const tables = [];
|
4539
4888
|
const getTable = () => tables[tables.length - 1];
|
@@ -4574,19 +4923,19 @@ var update = (state, _options) => {
|
|
4574
4923
|
tables.forEach((table2) => {
|
4575
4924
|
const replace = state.readOnly || cursor < table2.from || cursor > table2.to;
|
4576
4925
|
if (replace) {
|
4577
|
-
builder.add(table2.from, table2.to,
|
4926
|
+
builder.add(table2.from, table2.to, Decoration10.replace({
|
4578
4927
|
block: true,
|
4579
4928
|
widget: new TableWidget(table2)
|
4580
4929
|
}));
|
4581
4930
|
} else {
|
4582
|
-
builder.add(table2.from, table2.to,
|
4931
|
+
builder.add(table2.from, table2.to, Decoration10.mark({
|
4583
4932
|
class: "cm-table"
|
4584
4933
|
}));
|
4585
4934
|
}
|
4586
4935
|
});
|
4587
4936
|
return builder.finish();
|
4588
4937
|
};
|
4589
|
-
var TableWidget = class extends
|
4938
|
+
var TableWidget = class extends WidgetType6 {
|
4590
4939
|
constructor(_table) {
|
4591
4940
|
super(), this._table = _table;
|
4592
4941
|
}
|
@@ -4627,14 +4976,14 @@ var Unicode = {
|
|
4627
4976
|
bulletSmall: "\u2219",
|
4628
4977
|
bulletSquare: "\u2B1D"
|
4629
4978
|
};
|
4630
|
-
var HorizontalRuleWidget = class extends
|
4979
|
+
var HorizontalRuleWidget = class extends WidgetType7 {
|
4631
4980
|
toDOM() {
|
4632
4981
|
const el = document.createElement("span");
|
4633
4982
|
el.className = "cm-hr";
|
4634
4983
|
return el;
|
4635
4984
|
}
|
4636
4985
|
};
|
4637
|
-
var LinkButton = class extends
|
4986
|
+
var LinkButton = class extends WidgetType7 {
|
4638
4987
|
constructor(url, render) {
|
4639
4988
|
super(), this.url = url, this.render = render;
|
4640
4989
|
}
|
@@ -4650,7 +4999,7 @@ var LinkButton = class extends WidgetType6 {
|
|
4650
4999
|
return el;
|
4651
5000
|
}
|
4652
5001
|
};
|
4653
|
-
var CheckboxWidget = class extends
|
5002
|
+
var CheckboxWidget = class extends WidgetType7 {
|
4654
5003
|
constructor(_checked) {
|
4655
5004
|
super(), this._checked = _checked;
|
4656
5005
|
}
|
@@ -4694,7 +5043,7 @@ var CheckboxWidget = class extends WidgetType6 {
|
|
4694
5043
|
return false;
|
4695
5044
|
}
|
4696
5045
|
};
|
4697
|
-
var TextWidget = class extends
|
5046
|
+
var TextWidget = class extends WidgetType7 {
|
4698
5047
|
constructor(text, className) {
|
4699
5048
|
super(), this.text = text, this.className = className;
|
4700
5049
|
}
|
@@ -4707,29 +5056,29 @@ var TextWidget = class extends WidgetType6 {
|
|
4707
5056
|
return el;
|
4708
5057
|
}
|
4709
5058
|
};
|
4710
|
-
var hide =
|
4711
|
-
var blockQuote =
|
5059
|
+
var hide = Decoration11.replace({});
|
5060
|
+
var blockQuote = Decoration11.line({
|
4712
5061
|
class: "cm-blockquote"
|
4713
5062
|
});
|
4714
|
-
var fencedCodeLine =
|
5063
|
+
var fencedCodeLine = Decoration11.line({
|
4715
5064
|
class: "cm-code cm-codeblock-line"
|
4716
5065
|
});
|
4717
|
-
var fencedCodeLineFirst =
|
4718
|
-
class:
|
5066
|
+
var fencedCodeLineFirst = Decoration11.line({
|
5067
|
+
class: mx4("cm-code cm-codeblock-line", "cm-codeblock-start")
|
4719
5068
|
});
|
4720
|
-
var fencedCodeLineLast =
|
4721
|
-
class:
|
5069
|
+
var fencedCodeLineLast = Decoration11.line({
|
5070
|
+
class: mx4("cm-code cm-codeblock-line", "cm-codeblock-end")
|
4722
5071
|
});
|
4723
5072
|
var commentBlockLine = fencedCodeLine;
|
4724
5073
|
var commentBlockLineFirst = fencedCodeLineFirst;
|
4725
5074
|
var commentBlockLineLast = fencedCodeLineLast;
|
4726
|
-
var horizontalRule =
|
5075
|
+
var horizontalRule = Decoration11.replace({
|
4727
5076
|
widget: new HorizontalRuleWidget()
|
4728
5077
|
});
|
4729
|
-
var checkedTask =
|
5078
|
+
var checkedTask = Decoration11.replace({
|
4730
5079
|
widget: new CheckboxWidget(true)
|
4731
5080
|
});
|
4732
|
-
var uncheckedTask =
|
5081
|
+
var uncheckedTask = Decoration11.replace({
|
4733
5082
|
widget: new CheckboxWidget(false)
|
4734
5083
|
});
|
4735
5084
|
var editingRange = (state, range, focus2) => {
|
@@ -4745,8 +5094,8 @@ var autoHideTags = /* @__PURE__ */ new Set([
|
|
4745
5094
|
"SuperscriptMark"
|
4746
5095
|
]);
|
4747
5096
|
var buildDecorations2 = (view, options, focus2) => {
|
4748
|
-
const deco = new
|
4749
|
-
const atomicDeco = new
|
5097
|
+
const deco = new RangeSetBuilder6();
|
5098
|
+
const atomicDeco = new RangeSetBuilder6();
|
4750
5099
|
const { state } = view;
|
4751
5100
|
const headerLevels = [];
|
4752
5101
|
const getHeaderLevels = (node, level) => {
|
@@ -4833,7 +5182,7 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
4833
5182
|
} else {
|
4834
5183
|
const num = headers.slice(from - 1).map((level2) => level2?.number ?? 0).join(".") + " ";
|
4835
5184
|
if (num.length) {
|
4836
|
-
atomicDeco.add(mark.from, mark.from + len,
|
5185
|
+
atomicDeco.add(mark.from, mark.from + len, Decoration11.replace({
|
4837
5186
|
widget: new TextWidget(num, theme.heading(level))
|
4838
5187
|
}));
|
4839
5188
|
}
|
@@ -4858,7 +5207,7 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
4858
5207
|
if (node.from === line.to - 1) {
|
4859
5208
|
return false;
|
4860
5209
|
}
|
4861
|
-
deco.add(line.from, line.from,
|
5210
|
+
deco.add(line.from, line.from, Decoration11.line({
|
4862
5211
|
class: "cm-list-item",
|
4863
5212
|
attributes: {
|
4864
5213
|
style: `padding-left: ${offset}px; text-indent: -${width}px;`
|
@@ -4875,7 +5224,7 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
4875
5224
|
const label = list.type === "OrderedList" ? `${++list.number}.` : Unicode.bulletSmall;
|
4876
5225
|
const line = state.doc.lineAt(node.from);
|
4877
5226
|
const to = state.doc.sliceString(node.to, node.to + 1) === " " ? node.to + 1 : node.to;
|
4878
|
-
atomicDeco.add(line.from, to,
|
5227
|
+
atomicDeco.add(line.from, to, Decoration11.replace({
|
4879
5228
|
widget: new TextWidget(label, list.type === "OrderedList" ? "cm-list-mark cm-list-mark-ordered" : "cm-list-mark cm-list-mark-bullet")
|
4880
5229
|
}));
|
4881
5230
|
break;
|
@@ -4962,7 +5311,7 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
4962
5311
|
if (!editing) {
|
4963
5312
|
atomicDeco.add(node.from, marks[0].to, hide);
|
4964
5313
|
}
|
4965
|
-
deco.add(marks[0].to, marks[1].from,
|
5314
|
+
deco.add(marks[0].to, marks[1].from, Decoration11.mark({
|
4966
5315
|
tagName: "a",
|
4967
5316
|
attributes: {
|
4968
5317
|
class: "cm-link",
|
@@ -4972,7 +5321,7 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
4972
5321
|
}
|
4973
5322
|
}));
|
4974
5323
|
if (!editing) {
|
4975
|
-
atomicDeco.add(marks[1].from, node.to, options.renderLinkButton ?
|
5324
|
+
atomicDeco.add(marks[1].from, node.to, options.renderLinkButton ? Decoration11.replace({
|
4976
5325
|
widget: new LinkButton(url, options.renderLinkButton)
|
4977
5326
|
}) : hide);
|
4978
5327
|
}
|
@@ -5027,10 +5376,10 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
5027
5376
|
atomicDeco: atomicDeco.finish()
|
5028
5377
|
};
|
5029
5378
|
};
|
5030
|
-
var forceUpdate =
|
5379
|
+
var forceUpdate = StateEffect6.define();
|
5031
5380
|
var decorateMarkdown = (options = {}) => {
|
5032
5381
|
return [
|
5033
|
-
|
5382
|
+
ViewPlugin12.fromClass(class {
|
5034
5383
|
constructor(view) {
|
5035
5384
|
({ deco: this.deco, atomicDeco: this.atomicDeco } = buildDecorations2(view, options, view.hasFocus));
|
5036
5385
|
}
|
@@ -5062,9 +5411,9 @@ var decorateMarkdown = (options = {}) => {
|
|
5062
5411
|
}
|
5063
5412
|
}, {
|
5064
5413
|
provide: (plugin) => [
|
5065
|
-
|
5066
|
-
|
5067
|
-
|
5414
|
+
EditorView22.atomicRanges.of((view) => view.plugin(plugin)?.atomicDeco ?? Decoration11.none),
|
5415
|
+
EditorView22.decorations.of((view) => view.plugin(plugin)?.atomicDeco ?? Decoration11.none),
|
5416
|
+
EditorView22.decorations.of((view) => view.plugin(plugin)?.deco ?? Decoration11.none)
|
5068
5417
|
]
|
5069
5418
|
}),
|
5070
5419
|
image(),
|
@@ -5155,7 +5504,7 @@ var mention = ({ debug, onSearch }) => {
|
|
5155
5504
|
};
|
5156
5505
|
|
5157
5506
|
// packages/ui/react-ui-editor/src/extensions/modes.ts
|
5158
|
-
import { keymap as
|
5507
|
+
import { keymap as keymap11 } from "@codemirror/view";
|
5159
5508
|
import { vim } from "@replit/codemirror-vim";
|
5160
5509
|
import { vscodeKeymap } from "@replit/codemirror-vscode-keymap";
|
5161
5510
|
import { Schema } from "effect";
|
@@ -5179,7 +5528,7 @@ var InputModeExtensions = {
|
|
5179
5528
|
editorInputMode.of({
|
5180
5529
|
type: "vscode"
|
5181
5530
|
}),
|
5182
|
-
|
5531
|
+
keymap11.of(vscodeKeymap)
|
5183
5532
|
],
|
5184
5533
|
vim: [
|
5185
5534
|
// https://github.com/replit/codemirror-vim
|
@@ -5188,7 +5537,7 @@ var InputModeExtensions = {
|
|
5188
5537
|
type: "vim",
|
5189
5538
|
noTabster: true
|
5190
5539
|
}),
|
5191
|
-
|
5540
|
+
keymap11.of([
|
5192
5541
|
{
|
5193
5542
|
key: "Alt-Escape",
|
5194
5543
|
run: (view) => {
|
@@ -5204,14 +5553,14 @@ var InputModeExtensions = {
|
|
5204
5553
|
import { indentMore } from "@codemirror/commands";
|
5205
5554
|
import { getIndentUnit } from "@codemirror/language";
|
5206
5555
|
import { EditorSelection as EditorSelection3 } from "@codemirror/state";
|
5207
|
-
import { keymap as
|
5556
|
+
import { keymap as keymap12 } from "@codemirror/view";
|
5208
5557
|
|
5209
5558
|
// packages/ui/react-ui-editor/src/extensions/outliner/selection.ts
|
5210
5559
|
import { Compartment, Facet as Facet3 } from "@codemirror/state";
|
5211
5560
|
|
5212
5561
|
// packages/ui/react-ui-editor/src/extensions/outliner/tree.ts
|
5213
5562
|
import { syntaxTree as syntaxTree9 } from "@codemirror/language";
|
5214
|
-
import { StateField as
|
5563
|
+
import { StateField as StateField10 } from "@codemirror/state";
|
5215
5564
|
import { Facet as Facet2 } from "@codemirror/state";
|
5216
5565
|
import { invariant as invariant5 } from "@dxos/invariant";
|
5217
5566
|
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/outliner/tree.ts";
|
@@ -5492,7 +5841,7 @@ var outlinerTree = (options = {}) => {
|
|
5492
5841
|
return tree;
|
5493
5842
|
};
|
5494
5843
|
return [
|
5495
|
-
|
5844
|
+
StateField10.define({
|
5496
5845
|
create: (state) => {
|
5497
5846
|
return buildTree(state);
|
5498
5847
|
},
|
@@ -5666,7 +6015,7 @@ var toggleTask = (view) => {
|
|
5666
6015
|
}
|
5667
6016
|
return true;
|
5668
6017
|
};
|
5669
|
-
var commands = () =>
|
6018
|
+
var commands = () => keymap12.of([
|
5670
6019
|
//
|
5671
6020
|
// Indentation.
|
5672
6021
|
//
|
@@ -5772,18 +6121,18 @@ var commands = () => keymap11.of([
|
|
5772
6121
|
]);
|
5773
6122
|
|
5774
6123
|
// packages/ui/react-ui-editor/src/extensions/outliner/outliner.ts
|
5775
|
-
import { Prec as
|
5776
|
-
import { Decoration as
|
5777
|
-
import { mx as
|
6124
|
+
import { Prec as Prec3 } from "@codemirror/state";
|
6125
|
+
import { Decoration as Decoration12, EditorView as EditorView23, ViewPlugin as ViewPlugin14 } from "@codemirror/view";
|
6126
|
+
import { mx as mx5 } from "@dxos/react-ui-theme";
|
5778
6127
|
|
5779
6128
|
// packages/ui/react-ui-editor/src/extensions/outliner/editor.ts
|
5780
6129
|
import { EditorSelection as EditorSelection4, EditorState as EditorState2 } from "@codemirror/state";
|
5781
|
-
import { ViewPlugin as
|
6130
|
+
import { ViewPlugin as ViewPlugin13 } from "@codemirror/view";
|
5782
6131
|
import { log as log7 } from "@dxos/log";
|
5783
6132
|
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/outliner/editor.ts";
|
5784
6133
|
var LIST_ITEM_REGEX = /^\s*- (\[ \]|\[x\])? /;
|
5785
6134
|
var initialize = () => {
|
5786
|
-
return
|
6135
|
+
return ViewPlugin13.fromClass(class {
|
5787
6136
|
constructor(view) {
|
5788
6137
|
const first = view.state.doc.lineAt(0);
|
5789
6138
|
const text = view.state.sliceDoc(first.from, first.to);
|
@@ -5968,7 +6317,7 @@ var editor = () => [
|
|
5968
6317
|
// packages/ui/react-ui-editor/src/extensions/outliner/outliner.ts
|
5969
6318
|
var outliner = (options = {}) => [
|
5970
6319
|
// Commands.
|
5971
|
-
|
6320
|
+
Prec3.highest(commands()),
|
5972
6321
|
// Selection.
|
5973
6322
|
selectionCompartment.of(selectionFacet.of([])),
|
5974
6323
|
// State.
|
@@ -5984,14 +6333,14 @@ var outliner = (options = {}) => [
|
|
5984
6333
|
listPaddingLeft: 8
|
5985
6334
|
}),
|
5986
6335
|
// Researve space for menu.
|
5987
|
-
|
6336
|
+
EditorView23.contentAttributes.of({
|
5988
6337
|
class: "is-full !mr-[3rem]"
|
5989
6338
|
})
|
5990
6339
|
];
|
5991
6340
|
var decorations = () => [
|
5992
|
-
|
6341
|
+
ViewPlugin14.fromClass(class {
|
5993
6342
|
constructor(view) {
|
5994
|
-
this.decorations =
|
6343
|
+
this.decorations = Decoration12.none;
|
5995
6344
|
this.updateDecorations(view.state, view);
|
5996
6345
|
}
|
5997
6346
|
update(update2) {
|
@@ -6013,18 +6362,18 @@ var decorations = () => [
|
|
6013
6362
|
const lineFrom = doc.lineAt(item.contentRange.from);
|
6014
6363
|
const lineTo = doc.lineAt(item.contentRange.to);
|
6015
6364
|
const isSelected = selection.includes(item.index) || item === current;
|
6016
|
-
decorations2.push(
|
6017
|
-
class:
|
6365
|
+
decorations2.push(Decoration12.line({
|
6366
|
+
class: mx5("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"))
|
6018
6367
|
}).range(line.from, line.from));
|
6019
6368
|
}
|
6020
6369
|
}
|
6021
|
-
this.decorations =
|
6370
|
+
this.decorations = Decoration12.set(decorations2);
|
6022
6371
|
}
|
6023
6372
|
}, {
|
6024
6373
|
decorations: (v) => v.decorations
|
6025
6374
|
}),
|
6026
6375
|
// Theme.
|
6027
|
-
|
6376
|
+
EditorView23.theme(Object.assign({
|
6028
6377
|
".cm-list-item": {
|
6029
6378
|
borderLeftWidth: "1px",
|
6030
6379
|
borderRightWidth: "1px",
|
@@ -6053,9 +6402,6 @@ var decorations = () => [
|
|
6053
6402
|
},
|
6054
6403
|
"[data-has-focus] & .cm-list-item-selected": {
|
6055
6404
|
borderColor: "var(--dx-separator)"
|
6056
|
-
},
|
6057
|
-
"[data-is-attention-source] & .cm-list-item-selected": {
|
6058
|
-
borderColor: "var(--dx-separator)"
|
6059
6405
|
}
|
6060
6406
|
}))
|
6061
6407
|
];
|
@@ -6063,28 +6409,25 @@ var decorations = () => [
|
|
6063
6409
|
// packages/ui/react-ui-editor/src/extensions/preview/preview.ts
|
6064
6410
|
import "@dxos/lit-ui/dx-ref-tag.pcss";
|
6065
6411
|
import { syntaxTree as syntaxTree10 } from "@codemirror/language";
|
6066
|
-
import { RangeSetBuilder as
|
6067
|
-
import { Decoration as
|
6412
|
+
import { RangeSetBuilder as RangeSetBuilder7, StateField as StateField11 } from "@codemirror/state";
|
6413
|
+
import { Decoration as Decoration13, EditorView as EditorView24, WidgetType as WidgetType8 } from "@codemirror/view";
|
6068
6414
|
var preview = (options = {}) => {
|
6069
6415
|
return [
|
6070
6416
|
// NOTE: Atomic block decorations must be created from a state field, now a widget, otherwise it results in the following error:
|
6071
6417
|
// "Block decorations may not be specified via plugins"
|
6072
|
-
|
6418
|
+
StateField11.define({
|
6073
6419
|
create: (state) => buildDecorations3(state, options),
|
6074
6420
|
update: (_, tr) => buildDecorations3(tr.state, options),
|
6075
6421
|
provide: (field) => [
|
6076
|
-
|
6077
|
-
|
6422
|
+
EditorView24.decorations.from(field),
|
6423
|
+
EditorView24.atomicRanges.of((view) => view.state.field(field))
|
6078
6424
|
]
|
6079
6425
|
}),
|
6080
|
-
|
6426
|
+
EditorView24.theme({
|
6081
6427
|
".cm-preview-block": {
|
6082
|
-
|
6083
|
-
|
6084
|
-
|
6085
|
-
borderRadius: "0.5rem",
|
6086
|
-
background: "var(--dx-modalSurface)",
|
6087
|
-
border: "1px solid var(--dx-separator)"
|
6428
|
+
"--dx-card-spacing-inline": "var(--dx-trimMd)",
|
6429
|
+
"--dx-card-spacing-block": "var(--dx-trimMd)",
|
6430
|
+
marginInline: "calc(-1*var(--dx-trimMd))"
|
6088
6431
|
}
|
6089
6432
|
})
|
6090
6433
|
];
|
@@ -6103,7 +6446,7 @@ var getLinkRef = (state, node) => {
|
|
6103
6446
|
}
|
6104
6447
|
};
|
6105
6448
|
var buildDecorations3 = (state, options) => {
|
6106
|
-
const builder = new
|
6449
|
+
const builder = new RangeSetBuilder7();
|
6107
6450
|
syntaxTree10(state).iterate({
|
6108
6451
|
enter: (node) => {
|
6109
6452
|
switch (node.name) {
|
@@ -6114,7 +6457,7 @@ var buildDecorations3 = (state, options) => {
|
|
6114
6457
|
case "Link": {
|
6115
6458
|
const link = getLinkRef(state, node.node);
|
6116
6459
|
if (link) {
|
6117
|
-
builder.add(node.from, node.to,
|
6460
|
+
builder.add(node.from, node.to, Decoration13.replace({
|
6118
6461
|
widget: new PreviewInlineWidget(options, link)
|
6119
6462
|
}));
|
6120
6463
|
}
|
@@ -6127,7 +6470,7 @@ var buildDecorations3 = (state, options) => {
|
|
6127
6470
|
case "Image": {
|
6128
6471
|
const link = getLinkRef(state, node.node);
|
6129
6472
|
if (options.renderBlock && link) {
|
6130
|
-
builder.add(node.from, node.to,
|
6473
|
+
builder.add(node.from, node.to, Decoration13.replace({
|
6131
6474
|
block: true,
|
6132
6475
|
// atomic: true,
|
6133
6476
|
widget: new PreviewBlockWidget(options, link)
|
@@ -6140,7 +6483,7 @@ var buildDecorations3 = (state, options) => {
|
|
6140
6483
|
});
|
6141
6484
|
return builder.finish();
|
6142
6485
|
};
|
6143
|
-
var PreviewInlineWidget = class extends
|
6486
|
+
var PreviewInlineWidget = class extends WidgetType8 {
|
6144
6487
|
constructor(_options, _link) {
|
6145
6488
|
super(), this._options = _options, this._link = _link;
|
6146
6489
|
}
|
@@ -6157,7 +6500,7 @@ var PreviewInlineWidget = class extends WidgetType7 {
|
|
6157
6500
|
return root;
|
6158
6501
|
}
|
6159
6502
|
};
|
6160
|
-
var PreviewBlockWidget = class extends
|
6503
|
+
var PreviewBlockWidget = class extends WidgetType8 {
|
6161
6504
|
constructor(_options, _link) {
|
6162
6505
|
super(), this._options = _options, this._link = _link;
|
6163
6506
|
}
|
@@ -6216,7 +6559,7 @@ var PreviewBlockWidget = class extends WidgetType7 {
|
|
6216
6559
|
};
|
6217
6560
|
|
6218
6561
|
// packages/ui/react-ui-editor/src/extensions/typewriter.ts
|
6219
|
-
import { keymap as
|
6562
|
+
import { keymap as keymap13 } from "@codemirror/view";
|
6220
6563
|
var defaultItems = [
|
6221
6564
|
"hello world!",
|
6222
6565
|
"this is a test.",
|
@@ -6226,7 +6569,7 @@ var typewriter = ({ delay = 75, items = defaultItems } = {}) => {
|
|
6226
6569
|
let t;
|
6227
6570
|
let idx = 0;
|
6228
6571
|
return [
|
6229
|
-
|
6572
|
+
keymap13.of([
|
6230
6573
|
{
|
6231
6574
|
// Reset.
|
6232
6575
|
key: "alt-meta-'",
|
@@ -6569,32 +6912,6 @@ var createViewMode = (state, onViewModeChange) => {
|
|
6569
6912
|
};
|
6570
6913
|
};
|
6571
6914
|
|
6572
|
-
// packages/ui/react-ui-editor/src/defaults.ts
|
6573
|
-
import { EditorView as EditorView23 } from "@codemirror/view";
|
6574
|
-
import { mx as mx5 } from "@dxos/react-ui-theme";
|
6575
|
-
var editorWidth = "!mli-auto is-full max-is-[min(50rem,100%-4rem)]";
|
6576
|
-
var editorSlots = {
|
6577
|
-
scroll: {
|
6578
|
-
className: "pbs-2"
|
6579
|
-
},
|
6580
|
-
content: {
|
6581
|
-
className: editorWidth
|
6582
|
-
}
|
6583
|
-
};
|
6584
|
-
var editorGutter = EditorView23.theme({
|
6585
|
-
".cm-gutters": {
|
6586
|
-
paddingRight: "1rem"
|
6587
|
-
}
|
6588
|
-
});
|
6589
|
-
var editorMonospace = EditorView23.theme({
|
6590
|
-
".cm-content": {
|
6591
|
-
fontFamily: fontMono
|
6592
|
-
}
|
6593
|
-
});
|
6594
|
-
var editorWithToolbarLayout = "grid grid-cols-1 grid-rows-[min-content_1fr] data-[toolbar=disabled]:grid-rows-[1fr] justify-center content-start overflow-hidden";
|
6595
|
-
var stackItemContentEditorClassNames = (role) => mx5("attention-surface dx-focus-ring-inset data-[toolbar=disabled]:pbs-2", role === "section" ? "[&_.cm-scroller]:overflow-hidden [&_.cm-scroller]:min-bs-24" : "min-bs-0");
|
6596
|
-
var stackItemContentToolbarClassNames = (role) => mx5("relative z-[1] flex is-full bg-toolbarSurface border-be border-subduedSeparator", role === "section" && "sticky block-start-0 -mbe-px min-is-0");
|
6597
|
-
|
6598
6915
|
// packages/ui/react-ui-editor/src/components/EditorToolbar/EditorToolbar.tsx
|
6599
6916
|
var createToolbar = ({ getView, state, customActions, ...features }) => {
|
6600
6917
|
return Rx.make((get2) => {
|
@@ -6650,7 +6967,7 @@ var createToolbar = ({ getView, state, customActions, ...features }) => {
|
|
6650
6967
|
});
|
6651
6968
|
};
|
6652
6969
|
var useEditorToolbarActionGraph = (props) => {
|
6653
|
-
const menuCreator =
|
6970
|
+
const menuCreator = useMemo4(() => createToolbar({
|
6654
6971
|
getView: props.getView,
|
6655
6972
|
state: props.state,
|
6656
6973
|
customActions: props.customActions,
|
@@ -6698,26 +7015,315 @@ var EditorToolbar = /* @__PURE__ */ memo(({ classNames, attendableId, role, ...p
|
|
6698
7015
|
}
|
6699
7016
|
});
|
6700
7017
|
|
6701
|
-
// packages/ui/react-ui-editor/src/components/Popover/
|
7018
|
+
// packages/ui/react-ui-editor/src/components/Popover/CommandMenu.tsx
|
6702
7019
|
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
7020
|
+
import React4, { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2 } from "react";
|
7021
|
+
import { Icon as Icon2, Popover, toLocalizedString, useThemeContext, useTranslation } from "@dxos/react-ui";
|
7022
|
+
var CommandMenu = ({ groups, currentItem, onSelect }) => {
|
7023
|
+
var _effect = _useSignals2();
|
7024
|
+
try {
|
7025
|
+
const { tx } = useThemeContext();
|
7026
|
+
const groupsWithItems = groups.filter((group) => group.items.length > 0);
|
7027
|
+
return /* @__PURE__ */ React4.createElement(Popover.Portal, null, /* @__PURE__ */ React4.createElement(Popover.Content, {
|
7028
|
+
align: "start",
|
7029
|
+
onOpenAutoFocus: (event) => event.preventDefault(),
|
7030
|
+
classNames: tx("menu.content", "menu--exotic-unfocusable", {
|
7031
|
+
elevation: "positioned"
|
7032
|
+
}, [
|
7033
|
+
"max-h-[300px] overflow-y-auto"
|
7034
|
+
])
|
7035
|
+
}, /* @__PURE__ */ React4.createElement(Popover.Viewport, {
|
7036
|
+
classNames: tx("menu.viewport", "menu__viewport--exotic-unfocusable", {})
|
7037
|
+
}, /* @__PURE__ */ React4.createElement("ul", null, groupsWithItems.map((group, index) => /* @__PURE__ */ React4.createElement(React4.Fragment, {
|
7038
|
+
key: group.id
|
7039
|
+
}, /* @__PURE__ */ React4.createElement(CommandGroup, {
|
7040
|
+
group,
|
7041
|
+
currentItem,
|
7042
|
+
onSelect
|
7043
|
+
}), index < groupsWithItems.length - 1 && /* @__PURE__ */ React4.createElement("div", {
|
7044
|
+
className: tx("menu.separator", "menu__item", {})
|
7045
|
+
})))))));
|
7046
|
+
} finally {
|
7047
|
+
_effect.f();
|
7048
|
+
}
|
7049
|
+
};
|
7050
|
+
var CommandGroup = ({ group, currentItem, onSelect }) => {
|
7051
|
+
var _effect = _useSignals2();
|
7052
|
+
try {
|
7053
|
+
const { tx } = useThemeContext();
|
7054
|
+
const { t } = useTranslation();
|
7055
|
+
return /* @__PURE__ */ React4.createElement(React4.Fragment, null, group.label && /* @__PURE__ */ React4.createElement("div", {
|
7056
|
+
className: tx("menu.groupLabel", "menu__group__label", {})
|
7057
|
+
}, /* @__PURE__ */ React4.createElement("span", null, toLocalizedString(group.label, t))), group.items.map((item) => /* @__PURE__ */ React4.createElement(CommandItem, {
|
7058
|
+
key: item.id,
|
7059
|
+
item,
|
7060
|
+
current: currentItem === item.id,
|
7061
|
+
onSelect
|
7062
|
+
})));
|
7063
|
+
} finally {
|
7064
|
+
_effect.f();
|
7065
|
+
}
|
7066
|
+
};
|
7067
|
+
var CommandItem = ({ item, current, onSelect }) => {
|
7068
|
+
var _effect = _useSignals2();
|
7069
|
+
try {
|
7070
|
+
const ref = useRef2(null);
|
7071
|
+
const { tx } = useThemeContext();
|
7072
|
+
const { t } = useTranslation();
|
7073
|
+
const handleSelect = useCallback2(() => onSelect(item), [
|
7074
|
+
item,
|
7075
|
+
onSelect
|
7076
|
+
]);
|
7077
|
+
useEffect2(() => {
|
7078
|
+
if (current && ref.current) {
|
7079
|
+
ref.current.scrollIntoView({
|
7080
|
+
behavior: "smooth",
|
7081
|
+
block: "nearest"
|
7082
|
+
});
|
7083
|
+
}
|
7084
|
+
}, [
|
7085
|
+
current
|
7086
|
+
]);
|
7087
|
+
return /* @__PURE__ */ React4.createElement("li", {
|
7088
|
+
ref,
|
7089
|
+
className: tx("menu.item", "menu__item--exotic-unfocusable", {}, [
|
7090
|
+
current && "bg-hoverSurface"
|
7091
|
+
]),
|
7092
|
+
onClick: handleSelect
|
7093
|
+
}, item.icon && /* @__PURE__ */ React4.createElement(Icon2, {
|
7094
|
+
icon: item.icon,
|
7095
|
+
size: 5
|
7096
|
+
}), /* @__PURE__ */ React4.createElement("span", {
|
7097
|
+
className: "grow truncate"
|
7098
|
+
}, toLocalizedString(item.label, t)));
|
7099
|
+
} finally {
|
7100
|
+
_effect.f();
|
7101
|
+
}
|
7102
|
+
};
|
7103
|
+
var getItem = (groups, id) => {
|
7104
|
+
return groups.flatMap((group) => group.items).find((item) => item.id === id);
|
7105
|
+
};
|
7106
|
+
var getNextItem = (groups, id) => {
|
7107
|
+
const items = groups.flatMap((group) => group.items);
|
7108
|
+
const index = items.findIndex((item) => item.id === id);
|
7109
|
+
return items[(index + 1) % items.length];
|
7110
|
+
};
|
7111
|
+
var getPreviousItem = (groups, id) => {
|
7112
|
+
const items = groups.flatMap((group) => group.items);
|
7113
|
+
const index = items.findIndex((item) => item.id === id);
|
7114
|
+
return items[(index - 1 + items.length) % items.length];
|
7115
|
+
};
|
7116
|
+
var filterItems = (groups, filter) => {
|
7117
|
+
return groups.map((group) => ({
|
7118
|
+
...group,
|
7119
|
+
items: group.items.filter(filter)
|
7120
|
+
}));
|
7121
|
+
};
|
7122
|
+
var insertAtCursor = (view, head, insert) => {
|
7123
|
+
view.dispatch({
|
7124
|
+
changes: {
|
7125
|
+
from: head,
|
7126
|
+
to: head,
|
7127
|
+
insert
|
7128
|
+
},
|
7129
|
+
selection: {
|
7130
|
+
anchor: head + insert.length,
|
7131
|
+
head: head + insert.length
|
7132
|
+
}
|
7133
|
+
});
|
7134
|
+
};
|
7135
|
+
var insertAtLineStart = (view, head, insert) => {
|
7136
|
+
const line = view.state.doc.lineAt(head);
|
7137
|
+
if (line.from === head) {
|
7138
|
+
insertAtCursor(view, head, insert);
|
7139
|
+
} else {
|
7140
|
+
insert = "\n" + insert;
|
7141
|
+
view.dispatch({
|
7142
|
+
changes: {
|
7143
|
+
from: line.to,
|
7144
|
+
to: line.to,
|
7145
|
+
insert
|
7146
|
+
},
|
7147
|
+
selection: {
|
7148
|
+
anchor: line.to + insert.length,
|
7149
|
+
head: line.to + insert.length
|
7150
|
+
}
|
7151
|
+
});
|
7152
|
+
}
|
7153
|
+
};
|
7154
|
+
var coreSlashCommands = {
|
7155
|
+
id: "markdown",
|
7156
|
+
label: "Markdown",
|
7157
|
+
items: [
|
7158
|
+
{
|
7159
|
+
id: "heading-1",
|
7160
|
+
label: "Heading 1",
|
7161
|
+
icon: "ph--text-h-one--regular",
|
7162
|
+
onSelect: (view, head) => insertAtLineStart(view, head, "# ")
|
7163
|
+
},
|
7164
|
+
{
|
7165
|
+
id: "heading-2",
|
7166
|
+
label: "Heading 2",
|
7167
|
+
icon: "ph--text-h-two--regular",
|
7168
|
+
onSelect: (view, head) => insertAtLineStart(view, head, "## ")
|
7169
|
+
},
|
7170
|
+
{
|
7171
|
+
id: "heading-3",
|
7172
|
+
label: "Heading 3",
|
7173
|
+
icon: "ph--text-h-three--regular",
|
7174
|
+
onSelect: (view, head) => insertAtLineStart(view, head, "### ")
|
7175
|
+
},
|
7176
|
+
{
|
7177
|
+
id: "heading-4",
|
7178
|
+
label: "Heading 4",
|
7179
|
+
icon: "ph--text-h-four--regular",
|
7180
|
+
onSelect: (view, head) => insertAtLineStart(view, head, "#### ")
|
7181
|
+
},
|
7182
|
+
{
|
7183
|
+
id: "heading-5",
|
7184
|
+
label: "Heading 5",
|
7185
|
+
icon: "ph--text-h-five--regular",
|
7186
|
+
onSelect: (view, head) => insertAtLineStart(view, head, "##### ")
|
7187
|
+
},
|
7188
|
+
{
|
7189
|
+
id: "heading-6",
|
7190
|
+
label: "Heading 6",
|
7191
|
+
icon: "ph--text-h-six--regular",
|
7192
|
+
onSelect: (view, head) => insertAtLineStart(view, head, "###### ")
|
7193
|
+
},
|
7194
|
+
{
|
7195
|
+
id: "bullet-list",
|
7196
|
+
label: "Bullet List",
|
7197
|
+
icon: "ph--list-bullets--regular",
|
7198
|
+
onSelect: (view, head) => insertAtLineStart(view, head, "- ")
|
7199
|
+
},
|
7200
|
+
{
|
7201
|
+
id: "numbered-list",
|
7202
|
+
label: "Numbered List",
|
7203
|
+
icon: "ph--list-numbers--regular",
|
7204
|
+
onSelect: (view, head) => insertAtLineStart(view, head, "1. ")
|
7205
|
+
},
|
7206
|
+
{
|
7207
|
+
id: "task-list",
|
7208
|
+
label: "Task List",
|
7209
|
+
icon: "ph--list-checks--regular",
|
7210
|
+
onSelect: (view, head) => insertAtLineStart(view, head, "- [ ] ")
|
7211
|
+
},
|
7212
|
+
{
|
7213
|
+
id: "quote",
|
7214
|
+
label: "Quote",
|
7215
|
+
icon: "ph--quotes--regular",
|
7216
|
+
onSelect: (view, head) => insertAtLineStart(view, head, "> ")
|
7217
|
+
},
|
7218
|
+
{
|
7219
|
+
id: "code-block",
|
7220
|
+
label: "Code Block",
|
7221
|
+
icon: "ph--code-block--regular",
|
7222
|
+
onSelect: (view, head) => insertAtLineStart(view, head, "```\n\n```")
|
7223
|
+
},
|
7224
|
+
{
|
7225
|
+
id: "table",
|
7226
|
+
label: "Table",
|
7227
|
+
icon: "ph--table--regular",
|
7228
|
+
onSelect: (view, head) => insertAtLineStart(view, head, "| | | |\n|---|---|---|\n| | | |")
|
7229
|
+
}
|
7230
|
+
]
|
7231
|
+
};
|
7232
|
+
var linkSlashCommands = {
|
7233
|
+
id: "link",
|
7234
|
+
label: "Link",
|
7235
|
+
items: [
|
7236
|
+
{
|
7237
|
+
id: "inline-link",
|
7238
|
+
label: "Inline link",
|
7239
|
+
icon: "ph--link--regular",
|
7240
|
+
onSelect: (view, head) => view.dispatch({
|
7241
|
+
changes: {
|
7242
|
+
from: head,
|
7243
|
+
insert: "@"
|
7244
|
+
},
|
7245
|
+
selection: {
|
7246
|
+
anchor: head + 1,
|
7247
|
+
head: head + 1
|
7248
|
+
},
|
7249
|
+
effects: commandRangeEffect.of({
|
7250
|
+
trigger: "@",
|
7251
|
+
range: {
|
7252
|
+
from: head,
|
7253
|
+
to: head + 1
|
7254
|
+
}
|
7255
|
+
})
|
7256
|
+
})
|
7257
|
+
},
|
7258
|
+
{
|
7259
|
+
id: "block-embed",
|
7260
|
+
label: "Block embed",
|
7261
|
+
icon: "ph--lego--regular",
|
7262
|
+
onSelect: (view, head) => view.dispatch({
|
7263
|
+
changes: {
|
7264
|
+
from: head,
|
7265
|
+
insert: "@@"
|
7266
|
+
},
|
7267
|
+
selection: {
|
7268
|
+
anchor: head + 2,
|
7269
|
+
head: head + 2
|
7270
|
+
},
|
7271
|
+
effects: commandRangeEffect.of({
|
7272
|
+
trigger: "@",
|
7273
|
+
range: {
|
7274
|
+
from: head,
|
7275
|
+
to: head + 2
|
7276
|
+
}
|
7277
|
+
})
|
7278
|
+
})
|
7279
|
+
}
|
7280
|
+
]
|
7281
|
+
};
|
7282
|
+
|
7283
|
+
// packages/ui/react-ui-editor/src/components/Popover/RefPopover.tsx
|
7284
|
+
import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking";
|
6703
7285
|
import { createContext } from "@radix-ui/react-context";
|
6704
|
-
import
|
7286
|
+
import React5, { useRef as useRef3, useState as useState2, useEffect as useEffect3, useCallback as useCallback3, forwardRef } from "react";
|
6705
7287
|
import { addEventListener as addEventListener2 } from "@dxos/async";
|
6706
|
-
import { Popover } from "@dxos/react-ui";
|
7288
|
+
import { Popover as Popover2 } from "@dxos/react-ui";
|
6707
7289
|
var customEventOptions = {
|
6708
7290
|
capture: true,
|
6709
7291
|
passive: false
|
6710
7292
|
};
|
7293
|
+
var RefPopover = /* @__PURE__ */ forwardRef(({ children, open, onOpenChange, modal, onActivate }, ref) => {
|
7294
|
+
var _effect = _useSignals3();
|
7295
|
+
try {
|
7296
|
+
const [rootRef, setRootRef] = useState2(null);
|
7297
|
+
useEffect3(() => {
|
7298
|
+
return rootRef && onActivate ? addEventListener2(rootRef, "dx-ref-tag-activate", onActivate, customEventOptions) : void 0;
|
7299
|
+
}, [
|
7300
|
+
rootRef,
|
7301
|
+
onActivate
|
7302
|
+
]);
|
7303
|
+
return /* @__PURE__ */ React5.createElement(Popover2.Root, {
|
7304
|
+
open,
|
7305
|
+
onOpenChange,
|
7306
|
+
modal
|
7307
|
+
}, /* @__PURE__ */ React5.createElement(Popover2.VirtualTrigger, {
|
7308
|
+
virtualRef: ref
|
7309
|
+
}), /* @__PURE__ */ React5.createElement("div", {
|
7310
|
+
role: "none",
|
7311
|
+
className: "contents",
|
7312
|
+
ref: setRootRef
|
7313
|
+
}, children));
|
7314
|
+
} finally {
|
7315
|
+
_effect.f();
|
7316
|
+
}
|
7317
|
+
});
|
6711
7318
|
var REF_POPOVER = "RefPopover";
|
6712
7319
|
var [RefPopoverContextProvider, useRefPopover] = createContext(REF_POPOVER, {});
|
6713
|
-
var
|
6714
|
-
var _effect =
|
7320
|
+
var PreviewProvider = ({ children, onLookup }) => {
|
7321
|
+
var _effect = _useSignals3();
|
6715
7322
|
try {
|
6716
|
-
const trigger =
|
6717
|
-
const [value, setValue] =
|
6718
|
-
const [
|
6719
|
-
const
|
6720
|
-
const handleDxRefTagActivate = useCallback((event) => {
|
7323
|
+
const trigger = useRef3(null);
|
7324
|
+
const [value, setValue] = useState2({});
|
7325
|
+
const [open, setOpen] = useState2(false);
|
7326
|
+
const handleDxRefTagActivate = useCallback3((event) => {
|
6721
7327
|
const { refId, label, trigger: dxTrigger } = event;
|
6722
7328
|
setValue((value2) => ({
|
6723
7329
|
...value2,
|
@@ -6740,37 +7346,25 @@ var RefPopoverProvider = ({ children, onLookup }) => {
|
|
6740
7346
|
}, [
|
6741
7347
|
onLookup
|
6742
7348
|
]);
|
6743
|
-
|
6744
|
-
return rootRef ? addEventListener2(rootRef, "dx-ref-tag-activate", handleDxRefTagActivate, customEventOptions) : void 0;
|
6745
|
-
}, [
|
6746
|
-
rootRef
|
6747
|
-
]);
|
6748
|
-
return /* @__PURE__ */ React4.createElement(RefPopoverContextProvider, {
|
7349
|
+
return /* @__PURE__ */ React5.createElement(RefPopoverContextProvider, {
|
6749
7350
|
pending: value.pending,
|
6750
7351
|
link: value.link,
|
6751
7352
|
target: value.target
|
6752
|
-
}, /* @__PURE__ */
|
7353
|
+
}, /* @__PURE__ */ React5.createElement(RefPopover, {
|
7354
|
+
ref: trigger,
|
6753
7355
|
open,
|
6754
|
-
onOpenChange: setOpen
|
6755
|
-
|
6756
|
-
|
6757
|
-
}), /* @__PURE__ */ React4.createElement("div", {
|
6758
|
-
role: "none",
|
6759
|
-
className: "contents",
|
6760
|
-
ref: setRootRef
|
6761
|
-
}, children)));
|
7356
|
+
onOpenChange: setOpen,
|
7357
|
+
onActivate: handleDxRefTagActivate
|
7358
|
+
}, children));
|
6762
7359
|
} finally {
|
6763
7360
|
_effect.f();
|
6764
7361
|
}
|
6765
7362
|
};
|
6766
|
-
var RefPopover = {
|
6767
|
-
Provider: RefPopoverProvider
|
6768
|
-
};
|
6769
7363
|
|
6770
7364
|
// packages/ui/react-ui-editor/src/components/Popover/RefDropdownMenu.tsx
|
6771
|
-
import { useSignals as
|
7365
|
+
import { useSignals as _useSignals4 } from "@preact-signals/safe-react/tracking";
|
6772
7366
|
import { createContext as createContext2 } from "@radix-ui/react-context";
|
6773
|
-
import
|
7367
|
+
import React6, { useRef as useRef4, useState as useState3, useEffect as useEffect4, useCallback as useCallback4 } from "react";
|
6774
7368
|
import { addEventListener as addEventListener3 } from "@dxos/async";
|
6775
7369
|
import { DropdownMenu } from "@dxos/react-ui";
|
6776
7370
|
var customEventOptions2 = {
|
@@ -6780,13 +7374,13 @@ var customEventOptions2 = {
|
|
6780
7374
|
var REF_DROPDOWN_MENU = "RefDropdownMenu";
|
6781
7375
|
var [RefDropdownMenuContextProvider, useRefDropdownMenu] = createContext2(REF_DROPDOWN_MENU, {});
|
6782
7376
|
var RefDropdownMenuProvider = ({ children, onLookup }) => {
|
6783
|
-
var _effect =
|
7377
|
+
var _effect = _useSignals4();
|
6784
7378
|
try {
|
6785
|
-
const trigger =
|
6786
|
-
const [value, setValue] =
|
6787
|
-
const [rootRef, setRootRef] =
|
6788
|
-
const [open, setOpen] =
|
6789
|
-
const handleDxRefTagActivate =
|
7379
|
+
const trigger = useRef4(null);
|
7380
|
+
const [value, setValue] = useState3({});
|
7381
|
+
const [rootRef, setRootRef] = useState3(null);
|
7382
|
+
const [open, setOpen] = useState3(false);
|
7383
|
+
const handleDxRefTagActivate = useCallback4((event) => {
|
6790
7384
|
const { refId, label, trigger: dxTrigger } = event;
|
6791
7385
|
setValue((value2) => ({
|
6792
7386
|
...value2,
|
@@ -6809,21 +7403,21 @@ var RefDropdownMenuProvider = ({ children, onLookup }) => {
|
|
6809
7403
|
}, [
|
6810
7404
|
onLookup
|
6811
7405
|
]);
|
6812
|
-
|
7406
|
+
useEffect4(() => {
|
6813
7407
|
return rootRef ? addEventListener3(rootRef, "dx-ref-tag-activate", handleDxRefTagActivate, customEventOptions2) : void 0;
|
6814
7408
|
}, [
|
6815
7409
|
rootRef
|
6816
7410
|
]);
|
6817
|
-
return /* @__PURE__ */
|
7411
|
+
return /* @__PURE__ */ React6.createElement(RefDropdownMenuContextProvider, {
|
6818
7412
|
pending: value.pending,
|
6819
7413
|
link: value.link,
|
6820
7414
|
target: value.target
|
6821
|
-
}, /* @__PURE__ */
|
7415
|
+
}, /* @__PURE__ */ React6.createElement(DropdownMenu.Root, {
|
6822
7416
|
open,
|
6823
7417
|
onOpenChange: setOpen
|
6824
|
-
}, /* @__PURE__ */
|
7418
|
+
}, /* @__PURE__ */ React6.createElement(DropdownMenu.VirtualTrigger, {
|
6825
7419
|
virtualRef: trigger
|
6826
|
-
}), /* @__PURE__ */
|
7420
|
+
}), /* @__PURE__ */ React6.createElement("div", {
|
6827
7421
|
role: "none",
|
6828
7422
|
className: "contents",
|
6829
7423
|
ref: setRootRef
|
@@ -6838,19 +7432,19 @@ var RefDropdownMenu = {
|
|
6838
7432
|
|
6839
7433
|
// packages/ui/react-ui-editor/src/hooks/useTextEditor.ts
|
6840
7434
|
import { EditorState as EditorState3 } from "@codemirror/state";
|
6841
|
-
import { EditorView as
|
7435
|
+
import { EditorView as EditorView25 } from "@codemirror/view";
|
6842
7436
|
import { useFocusableGroup } from "@fluentui/react-tabster";
|
6843
|
-
import { useCallback as
|
7437
|
+
import { useCallback as useCallback5, useEffect as useEffect5, useMemo as useMemo5, useRef as useRef5, useState as useState4 } from "react";
|
6844
7438
|
import { log as log8 } from "@dxos/log";
|
6845
7439
|
import { getProviderValue, isNotFalsy as isNotFalsy4 } from "@dxos/util";
|
6846
7440
|
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/useTextEditor.ts";
|
6847
7441
|
var instanceCount = 0;
|
6848
7442
|
var useTextEditor = (props = {}, deps = []) => {
|
6849
|
-
const { id, doc, initialValue, extensions, autoFocus, scrollTo, selection, moveToEndOfLine, debug } =
|
6850
|
-
const [instanceId] =
|
6851
|
-
const [view, setView] =
|
6852
|
-
const parentRef =
|
6853
|
-
|
7443
|
+
const { id, doc, initialValue, extensions, autoFocus, scrollTo, selection, moveToEndOfLine, debug } = useMemo5(() => getProviderValue(props), deps ?? []);
|
7444
|
+
const [instanceId] = useState4(() => `text-editor-${++instanceCount}`);
|
7445
|
+
const [view, setView] = useState4();
|
7446
|
+
const parentRef = useRef5(null);
|
7447
|
+
useEffect5(() => {
|
6854
7448
|
let view2;
|
6855
7449
|
if (parentRef.current) {
|
6856
7450
|
log8("create", {
|
@@ -6859,7 +7453,7 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
6859
7453
|
doc: initialValue?.length ?? 0
|
6860
7454
|
}, {
|
6861
7455
|
F: __dxlog_file13,
|
6862
|
-
L:
|
7456
|
+
L: 75,
|
6863
7457
|
S: void 0,
|
6864
7458
|
C: (f, a) => f(...a)
|
6865
7459
|
});
|
@@ -6882,20 +7476,20 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
6882
7476
|
id && documentId.of(id),
|
6883
7477
|
extensions,
|
6884
7478
|
// NOTE: This doesn't catch errors in keymap functions.
|
6885
|
-
|
7479
|
+
EditorView25.exceptionSink.of((err) => {
|
6886
7480
|
log8.catch(err, void 0, {
|
6887
7481
|
F: __dxlog_file13,
|
6888
|
-
L:
|
7482
|
+
L: 97,
|
6889
7483
|
S: void 0,
|
6890
7484
|
C: (f, a) => f(...a)
|
6891
7485
|
});
|
6892
7486
|
})
|
6893
7487
|
].filter(isNotFalsy4)
|
6894
7488
|
});
|
6895
|
-
view2 = new
|
7489
|
+
view2 = new EditorView25({
|
6896
7490
|
parent: parentRef.current,
|
6897
7491
|
state,
|
6898
|
-
scrollTo: scrollTo ?
|
7492
|
+
scrollTo: scrollTo ? EditorView25.scrollIntoView(scrollTo, {
|
6899
7493
|
yMargin: 96
|
6900
7494
|
}) : void 0,
|
6901
7495
|
dispatchTransactions: debug ? debugDispatcher : void 0
|
@@ -6917,14 +7511,14 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
6917
7511
|
id
|
6918
7512
|
}, {
|
6919
7513
|
F: __dxlog_file13,
|
6920
|
-
L:
|
7514
|
+
L: 134,
|
6921
7515
|
S: void 0,
|
6922
7516
|
C: (f, a) => f(...a)
|
6923
7517
|
});
|
6924
7518
|
view2?.destroy();
|
6925
7519
|
};
|
6926
7520
|
}, deps);
|
6927
|
-
|
7521
|
+
useEffect5(() => {
|
6928
7522
|
if (view) {
|
6929
7523
|
if (scrollTo || selection) {
|
6930
7524
|
if (selection && selection.anchor > view.state.doc.length) {
|
@@ -6934,7 +7528,7 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
6934
7528
|
selection
|
6935
7529
|
}, {
|
6936
7530
|
F: __dxlog_file13,
|
6937
|
-
L:
|
7531
|
+
L: 143,
|
6938
7532
|
S: void 0,
|
6939
7533
|
C: (f, a) => f(...a)
|
6940
7534
|
});
|
@@ -6951,7 +7545,7 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
6951
7545
|
scrollTo,
|
6952
7546
|
selection
|
6953
7547
|
]);
|
6954
|
-
|
7548
|
+
useEffect5(() => {
|
6955
7549
|
if (view && autoFocus) {
|
6956
7550
|
view.focus();
|
6957
7551
|
}
|
@@ -6965,7 +7559,7 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
6965
7559
|
Escape: view?.state.facet(editorInputMode).noTabster
|
6966
7560
|
}
|
6967
7561
|
});
|
6968
|
-
const handleKeyUp =
|
7562
|
+
const handleKeyUp = useCallback5((event) => {
|
6969
7563
|
const { key, target, currentTarget } = event;
|
6970
7564
|
if (target === currentTarget) {
|
6971
7565
|
switch (key) {
|
@@ -6989,17 +7583,19 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
6989
7583
|
};
|
6990
7584
|
};
|
6991
7585
|
export {
|
7586
|
+
CommandMenu,
|
6992
7587
|
Cursor,
|
6993
7588
|
EditorInputMode,
|
6994
7589
|
EditorInputModes,
|
6995
7590
|
EditorState4 as EditorState,
|
6996
7591
|
EditorToolbar,
|
6997
|
-
|
7592
|
+
EditorView26 as EditorView,
|
6998
7593
|
EditorViewMode,
|
6999
7594
|
EditorViewModes,
|
7000
7595
|
Inline,
|
7001
7596
|
InputModeExtensions,
|
7002
7597
|
List,
|
7598
|
+
PreviewProvider,
|
7003
7599
|
RefDropdownMenu,
|
7004
7600
|
RefPopover,
|
7005
7601
|
RemoteSelectionsDecorator,
|
@@ -7023,11 +7619,14 @@ export {
|
|
7023
7619
|
closeEffect,
|
7024
7620
|
command,
|
7025
7621
|
commandKeyBindings,
|
7622
|
+
commandMenu,
|
7623
|
+
commandRangeEffect,
|
7026
7624
|
commands,
|
7027
7625
|
commentClickedEffect,
|
7028
7626
|
comments,
|
7029
7627
|
commentsState,
|
7030
7628
|
convertTreeToJson,
|
7629
|
+
coreSlashCommands,
|
7031
7630
|
createBasicExtensions,
|
7032
7631
|
createComment,
|
7033
7632
|
createDataExtensions,
|
@@ -7055,6 +7654,7 @@ export {
|
|
7055
7654
|
editorSlots,
|
7056
7655
|
editorWidth,
|
7057
7656
|
editorWithToolbarLayout,
|
7657
|
+
filterItems,
|
7058
7658
|
flattenRect,
|
7059
7659
|
floatingMenu,
|
7060
7660
|
focus,
|
@@ -7063,15 +7663,21 @@ export {
|
|
7063
7663
|
formattingEquals,
|
7064
7664
|
formattingKeymap,
|
7065
7665
|
getFormatting,
|
7666
|
+
getItem,
|
7066
7667
|
getListItemContent,
|
7668
|
+
getNextItem,
|
7669
|
+
getPreviousItem,
|
7067
7670
|
getRange,
|
7068
7671
|
hashtag,
|
7069
7672
|
image,
|
7070
7673
|
indentItemLess,
|
7071
7674
|
indentItemMore,
|
7675
|
+
insertAtCursor,
|
7676
|
+
insertAtLineStart,
|
7072
7677
|
insertTable,
|
7073
7678
|
itemToJSON,
|
7074
|
-
|
7679
|
+
keymap14 as keymap,
|
7680
|
+
linkSlashCommands,
|
7075
7681
|
linkTooltip,
|
7076
7682
|
listItemToString,
|
7077
7683
|
listener,
|
@@ -7083,6 +7689,7 @@ export {
|
|
7083
7689
|
mention,
|
7084
7690
|
moveItemDown,
|
7085
7691
|
moveItemUp,
|
7692
|
+
multilinePlaceholder,
|
7086
7693
|
openCommand,
|
7087
7694
|
openEffect,
|
7088
7695
|
outliner,
|
@@ -7125,6 +7732,7 @@ export {
|
|
7125
7732
|
treeFacet,
|
7126
7733
|
typeahead,
|
7127
7734
|
typewriter,
|
7735
|
+
useCommandMenu,
|
7128
7736
|
useComments,
|
7129
7737
|
useEditorToolbarState,
|
7130
7738
|
useFormattingState,
|