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