@dxos/react-ui-editor 0.8.3-main.7f5a14c → 0.8.3-staging.0fa589b
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 +371 -375
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +502 -511
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +371 -375
- 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/EditorToolbar.d.ts.map +1 -1
- package/dist/types/src/components/Popover/RefDropdownMenu.d.ts.map +1 -1
- package/dist/types/src/components/Popover/RefPopover.d.ts.map +1 -1
- package/dist/types/src/defaults.d.ts +0 -1
- package/dist/types/src/defaults.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/command/action.d.ts.map +1 -1
- package/dist/types/src/extensions/command/command-menu.d.ts +20 -0
- package/dist/types/src/extensions/command/command-menu.d.ts.map +1 -0
- package/dist/types/src/extensions/command/command.d.ts.map +1 -1
- package/dist/types/src/extensions/command/floating-menu.d.ts +7 -0
- package/dist/types/src/extensions/command/floating-menu.d.ts.map +1 -0
- package/dist/types/src/extensions/command/hint.d.ts +5 -2
- package/dist/types/src/extensions/command/hint.d.ts.map +1 -1
- package/dist/types/src/extensions/command/index.d.ts +3 -1
- package/dist/types/src/extensions/command/index.d.ts.map +1 -1
- package/dist/types/src/extensions/command/placeholder.d.ts +10 -0
- package/dist/types/src/extensions/command/placeholder.d.ts.map +1 -0
- package/dist/types/src/extensions/command/state.d.ts +1 -1
- package/dist/types/src/extensions/command/state.d.ts.map +1 -1
- package/dist/types/src/extensions/command/useCommandMenu.d.ts +26 -0
- package/dist/types/src/extensions/command/useCommandMenu.d.ts.map +1 -0
- package/dist/types/src/extensions/index.d.ts +0 -1
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/extensions/outliner/tree.d.ts.map +1 -1
- package/dist/types/src/extensions/preview/preview.d.ts +12 -19
- package/dist/types/src/extensions/preview/preview.d.ts.map +1 -1
- package/dist/types/src/stories/CommandMenu.stories.d.ts +5 -4
- package/dist/types/src/stories/CommandMenu.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Preview.stories.d.ts.map +1 -1
- package/dist/types/src/util/dom.d.ts +5 -0
- package/dist/types/src/util/dom.d.ts.map +1 -1
- package/dist/types/src/util/react.d.ts +2 -4
- package/dist/types/src/util/react.d.ts.map +1 -1
- package/package.json +31 -31
- package/src/components/EditorToolbar/EditorToolbar.tsx +5 -9
- package/src/components/Popover/RefDropdownMenu.tsx +5 -3
- package/src/components/Popover/RefPopover.tsx +5 -3
- package/src/defaults.ts +0 -6
- package/src/extensions/automerge/automerge.stories.tsx +5 -5
- package/src/extensions/command/action.ts +9 -2
- package/src/extensions/command/command-menu.ts +210 -0
- package/src/extensions/command/command.ts +8 -8
- package/src/extensions/command/floating-menu.ts +133 -0
- package/src/extensions/command/hint.ts +29 -9
- package/src/extensions/command/index.ts +3 -1
- package/src/extensions/command/placeholder.ts +113 -0
- package/src/extensions/command/state.ts +1 -2
- package/src/extensions/command/useCommandMenu.ts +118 -0
- package/src/extensions/index.ts +0 -1
- package/src/extensions/markdown/bundle.ts +0 -2
- package/src/extensions/outliner/tree.test.ts +13 -10
- package/src/extensions/outliner/tree.ts +5 -3
- package/src/extensions/preview/preview.ts +11 -86
- package/src/stories/Command.stories.tsx +1 -1
- package/src/stories/CommandMenu.stories.tsx +35 -19
- package/src/stories/Preview.stories.tsx +134 -57
- package/src/stories/components/util.tsx +2 -2
- package/src/util/dom.ts +20 -0
- package/src/util/react.tsx +3 -20
- package/dist/types/src/extensions/command/menu.d.ts +0 -47
- package/dist/types/src/extensions/command/menu.d.ts.map +0 -1
- package/dist/types/src/extensions/placeholder.d.ts +0 -4
- package/dist/types/src/extensions/placeholder.d.ts.map +0 -1
- package/src/extensions/command/menu.ts +0 -439
- package/src/extensions/placeholder.ts +0 -82
@@ -37,7 +37,7 @@ 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 EditorView27, 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
|
|
@@ -48,7 +48,6 @@ 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";
|
51
|
-
import { textBlockWidth } from "@dxos/react-ui-theme";
|
52
51
|
|
53
52
|
// packages/ui/react-ui-editor/src/components/EditorToolbar/util.ts
|
54
53
|
import { useMemo } from "react";
|
@@ -519,17 +518,14 @@ var clientRectsFor = (dom) => {
|
|
519
518
|
return [];
|
520
519
|
}
|
521
520
|
};
|
522
|
-
|
523
|
-
// packages/ui/react-ui-editor/src/util/react.tsx
|
524
|
-
import React from "react";
|
525
|
-
import { createRoot } from "react-dom/client";
|
526
|
-
import { ThemeProvider, Tooltip } from "@dxos/react-ui";
|
527
|
-
import { defaultTx } from "@dxos/react-ui-theme";
|
528
521
|
var createElement = (tag, options, children) => {
|
529
522
|
const el = document.createElement(tag);
|
530
523
|
if (options?.className) {
|
531
524
|
el.className = options.className;
|
532
525
|
}
|
526
|
+
if (options?.text) {
|
527
|
+
el.textContent = options.text;
|
528
|
+
}
|
533
529
|
if (children) {
|
534
530
|
el.append(...Array.isArray(children) ? children : [
|
535
531
|
children
|
@@ -537,6 +533,12 @@ var createElement = (tag, options, children) => {
|
|
537
533
|
}
|
538
534
|
return el;
|
539
535
|
};
|
536
|
+
|
537
|
+
// packages/ui/react-ui-editor/src/util/react.tsx
|
538
|
+
import React from "react";
|
539
|
+
import { createRoot } from "react-dom/client";
|
540
|
+
import { ThemeProvider, Tooltip } from "@dxos/react-ui";
|
541
|
+
import { defaultTx } from "@dxos/react-ui-theme";
|
540
542
|
var renderRoot = (root, node) => {
|
541
543
|
createRoot(root).render(/* @__PURE__ */ React.createElement(ThemeProvider, {
|
542
544
|
tx: defaultTx
|
@@ -1360,6 +1362,7 @@ var closeCommand = (view) => {
|
|
1360
1362
|
var commandKeyBindings = [
|
1361
1363
|
{
|
1362
1364
|
key: "/",
|
1365
|
+
preventDefault: true,
|
1363
1366
|
run: openCommand
|
1364
1367
|
},
|
1365
1368
|
{
|
@@ -1369,37 +1372,55 @@ var commandKeyBindings = [
|
|
1369
1372
|
];
|
1370
1373
|
|
1371
1374
|
// packages/ui/react-ui-editor/src/extensions/command/command.ts
|
1375
|
+
import { Prec } from "@codemirror/state";
|
1372
1376
|
import { EditorView as EditorView6, keymap as keymap3 } from "@codemirror/view";
|
1377
|
+
import { isNonNullable } from "@dxos/util";
|
1373
1378
|
|
1374
1379
|
// packages/ui/react-ui-editor/src/extensions/command/hint.ts
|
1375
1380
|
import { RangeSetBuilder as RangeSetBuilder2 } from "@codemirror/state";
|
1376
1381
|
import { Decoration as Decoration3, EditorView as EditorView5, ViewPlugin as ViewPlugin4, WidgetType as WidgetType2 } from "@codemirror/view";
|
1377
|
-
var
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1382
|
+
var hint = ({ delay = 3e3, onHint }) => {
|
1383
|
+
return ViewPlugin4.fromClass(class {
|
1384
|
+
constructor() {
|
1385
|
+
this.decorations = Decoration3.none;
|
1386
|
+
}
|
1387
|
+
update(update2) {
|
1388
|
+
if (this.timeout) {
|
1389
|
+
clearTimeout(this.timeout);
|
1390
|
+
this.timeout = void 0;
|
1391
|
+
}
|
1392
|
+
const builder = new RangeSetBuilder2();
|
1393
|
+
const cState = update2.view.state.field(commandState, false);
|
1394
|
+
if (!cState?.tooltip) {
|
1395
|
+
const selection = update2.view.state.selection.main;
|
1396
|
+
const line = update2.view.state.doc.lineAt(selection.from);
|
1397
|
+
if (selection.from === selection.to && line.from === line.to) {
|
1398
|
+
this.timeout = setTimeout(() => {
|
1399
|
+
const hint2 = onHint?.();
|
1400
|
+
if (hint2) {
|
1401
|
+
const builder2 = new RangeSetBuilder2();
|
1402
|
+
builder2.add(selection.from, selection.to, Decoration3.widget({
|
1403
|
+
widget: new Hint(hint2)
|
1404
|
+
}));
|
1405
|
+
this.decorations = builder2.finish();
|
1406
|
+
update2.view.update([]);
|
1407
|
+
}
|
1408
|
+
}, delay);
|
1393
1409
|
}
|
1394
1410
|
}
|
1411
|
+
this.decorations = builder.finish();
|
1395
1412
|
}
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1413
|
+
destroy() {
|
1414
|
+
if (this.timeout) {
|
1415
|
+
clearTimeout(this.timeout);
|
1416
|
+
}
|
1417
|
+
}
|
1418
|
+
}, {
|
1419
|
+
provide: (plugin) => [
|
1420
|
+
EditorView5.decorations.of((view) => view.plugin(plugin)?.decorations ?? Decoration3.none)
|
1421
|
+
]
|
1422
|
+
});
|
1423
|
+
};
|
1403
1424
|
var Hint = class extends WidgetType2 {
|
1404
1425
|
constructor(content) {
|
1405
1426
|
super(), this.content = content;
|
@@ -1442,31 +1463,70 @@ var Hint = class extends WidgetType2 {
|
|
1442
1463
|
// packages/ui/react-ui-editor/src/extensions/command/command.ts
|
1443
1464
|
var command = (options = {}) => {
|
1444
1465
|
return [
|
1445
|
-
keymap3.of(commandKeyBindings),
|
1466
|
+
Prec.highest(keymap3.of(commandKeyBindings)),
|
1446
1467
|
commandConfig.of(options),
|
1447
1468
|
commandState,
|
1448
|
-
options.onHint
|
1449
|
-
|
1450
|
-
}) : [],
|
1451
|
-
EditorView6.focusChangeEffect.of((_, focusing) => {
|
1452
|
-
return focusing ? closeEffect.of(null) : null;
|
1453
|
-
}),
|
1469
|
+
options.onHint && hint(options),
|
1470
|
+
EditorView6.focusChangeEffect.of((_, focusing) => focusing ? closeEffect.of(null) : null),
|
1454
1471
|
EditorView6.theme({
|
1455
1472
|
".cm-tooltip": {
|
1456
1473
|
background: "transparent"
|
1457
1474
|
}
|
1458
1475
|
})
|
1459
|
-
];
|
1476
|
+
].filter(isNonNullable);
|
1460
1477
|
};
|
1461
1478
|
|
1462
|
-
// packages/ui/react-ui-editor/src/extensions/command/menu.ts
|
1463
|
-
import { RangeSetBuilder as RangeSetBuilder3, StateField as StateField3, StateEffect as StateEffect3, Prec } from "@codemirror/state";
|
1479
|
+
// packages/ui/react-ui-editor/src/extensions/command/command-menu.ts
|
1480
|
+
import { RangeSetBuilder as RangeSetBuilder3, StateField as StateField3, StateEffect as StateEffect3, Prec as Prec2 } from "@codemirror/state";
|
1464
1481
|
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";
|
1466
|
-
import { addEventListener } from "@dxos/async";
|
1467
1482
|
|
1468
|
-
// packages/ui/react-ui-editor/src/extensions/placeholder.ts
|
1483
|
+
// packages/ui/react-ui-editor/src/extensions/command/placeholder.ts
|
1469
1484
|
import { Decoration as Decoration4, EditorView as EditorView7, WidgetType as WidgetType3, ViewPlugin as ViewPlugin5 } from "@codemirror/view";
|
1485
|
+
var placeholder = ({ delay = 3e3, content }) => {
|
1486
|
+
const plugin = ViewPlugin5.fromClass(class {
|
1487
|
+
constructor() {
|
1488
|
+
this.decorations = Decoration4.none;
|
1489
|
+
}
|
1490
|
+
update(update2) {
|
1491
|
+
if (this.timeout) {
|
1492
|
+
window.clearTimeout(this.timeout);
|
1493
|
+
this.timeout = void 0;
|
1494
|
+
}
|
1495
|
+
const activeLine = update2.view.state.doc.lineAt(update2.view.state.selection.main.head);
|
1496
|
+
const isEmpty = activeLine.text.trim() === "";
|
1497
|
+
if (isEmpty) {
|
1498
|
+
const lineStart = activeLine.from;
|
1499
|
+
this.timeout = setTimeout(() => {
|
1500
|
+
this.decorations = Decoration4.set([
|
1501
|
+
Decoration4.widget({
|
1502
|
+
widget: new Placeholder(content),
|
1503
|
+
side: 1
|
1504
|
+
}).range(lineStart)
|
1505
|
+
]);
|
1506
|
+
update2.view.update([]);
|
1507
|
+
}, delay);
|
1508
|
+
}
|
1509
|
+
this.decorations = Decoration4.none;
|
1510
|
+
}
|
1511
|
+
destroy() {
|
1512
|
+
if (this.timeout) {
|
1513
|
+
clearTimeout(this.timeout);
|
1514
|
+
}
|
1515
|
+
}
|
1516
|
+
}, {
|
1517
|
+
provide: (plugin2) => {
|
1518
|
+
return [
|
1519
|
+
EditorView7.decorations.of((view) => view.plugin(plugin2)?.decorations ?? Decoration4.none)
|
1520
|
+
];
|
1521
|
+
}
|
1522
|
+
});
|
1523
|
+
return typeof content === "string" ? [
|
1524
|
+
plugin,
|
1525
|
+
EditorView7.contentAttributes.of({
|
1526
|
+
"aria-placeholder": content
|
1527
|
+
})
|
1528
|
+
] : plugin;
|
1529
|
+
};
|
1470
1530
|
var Placeholder = class extends WidgetType3 {
|
1471
1531
|
constructor(content) {
|
1472
1532
|
super(), this.content = content;
|
@@ -1501,135 +1561,8 @@ var Placeholder = class extends WidgetType3 {
|
|
1501
1561
|
return false;
|
1502
1562
|
}
|
1503
1563
|
};
|
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
1564
|
|
1534
|
-
// packages/ui/react-ui-editor/src/extensions/command/menu.ts
|
1535
|
-
var floatingMenu = (options = {}) => [
|
1536
|
-
ViewPlugin6.fromClass(class {
|
1537
|
-
constructor(view) {
|
1538
|
-
this.view = view;
|
1539
|
-
const container = view.scrollDOM;
|
1540
|
-
if (getComputedStyle(container).position === "static") {
|
1541
|
-
container.style.position = "relative";
|
1542
|
-
}
|
1543
|
-
{
|
1544
|
-
const icon = document.createElement("dx-icon");
|
1545
|
-
icon.setAttribute("icon", options.icon ?? "ph--dots-three-vertical--regular");
|
1546
|
-
const button = document.createElement("button");
|
1547
|
-
button.appendChild(icon);
|
1548
|
-
this.tag = document.createElement("dx-ref-tag");
|
1549
|
-
this.tag.classList.add("cm-ref-tag");
|
1550
|
-
this.tag.appendChild(button);
|
1551
|
-
}
|
1552
|
-
container.appendChild(this.tag);
|
1553
|
-
const handler = () => this.scheduleUpdate();
|
1554
|
-
this.cleanup = addEventListener(container, "scroll", handler);
|
1555
|
-
this.scheduleUpdate();
|
1556
|
-
}
|
1557
|
-
destroy() {
|
1558
|
-
this.cleanup?.();
|
1559
|
-
this.tag.remove();
|
1560
|
-
if (this.rafId != null) {
|
1561
|
-
cancelAnimationFrame(this.rafId);
|
1562
|
-
}
|
1563
|
-
}
|
1564
|
-
update(update2) {
|
1565
|
-
this.tag.dataset.focused = update2.view.hasFocus ? "true" : "false";
|
1566
|
-
if (!update2.view.hasFocus) {
|
1567
|
-
return;
|
1568
|
-
}
|
1569
|
-
if (update2.transactions.some((tr) => tr.effects.some((effect) => effect.is(openEffect)))) {
|
1570
|
-
this.tag.style.display = "none";
|
1571
|
-
this.tag.classList.add("opacity-10");
|
1572
|
-
} else if (update2.transactions.some((tr) => tr.effects.some((effect) => effect.is(closeEffect)))) {
|
1573
|
-
this.tag.style.display = "block";
|
1574
|
-
} else if (update2.docChanged || update2.focusChanged || update2.geometryChanged || update2.selectionSet || update2.viewportChanged) {
|
1575
|
-
this.scheduleUpdate();
|
1576
|
-
}
|
1577
|
-
}
|
1578
|
-
updateButtonPosition() {
|
1579
|
-
const { x, width } = this.view.contentDOM.getBoundingClientRect();
|
1580
|
-
const pos = this.view.state.selection.main.head;
|
1581
|
-
const line = this.view.lineBlockAt(pos);
|
1582
|
-
const coords = this.view.coordsAtPos(line.from);
|
1583
|
-
if (!coords) {
|
1584
|
-
return;
|
1585
|
-
}
|
1586
|
-
const lineHeight = coords.bottom - coords.top;
|
1587
|
-
const dy = (lineHeight - (options.height ?? 32)) / 2;
|
1588
|
-
const offsetTop = coords.top + dy;
|
1589
|
-
const offsetLeft = x + width + (options.padding ?? 8);
|
1590
|
-
this.tag.style.top = `${offsetTop}px`;
|
1591
|
-
this.tag.style.left = `${offsetLeft}px`;
|
1592
|
-
this.tag.style.display = "block";
|
1593
|
-
}
|
1594
|
-
scheduleUpdate() {
|
1595
|
-
if (this.rafId != null) {
|
1596
|
-
cancelAnimationFrame(this.rafId);
|
1597
|
-
}
|
1598
|
-
this.rafId = requestAnimationFrame(this.updateButtonPosition.bind(this));
|
1599
|
-
}
|
1600
|
-
}),
|
1601
|
-
EditorView8.theme({
|
1602
|
-
".cm-ref-tag": {
|
1603
|
-
position: "fixed",
|
1604
|
-
padding: "0",
|
1605
|
-
border: "none",
|
1606
|
-
opacity: "0"
|
1607
|
-
},
|
1608
|
-
"[data-has-focus] & .cm-ref-tag": {
|
1609
|
-
opacity: "1"
|
1610
|
-
},
|
1611
|
-
".cm-ref-tag button": {
|
1612
|
-
display: "grid",
|
1613
|
-
alignItems: "center",
|
1614
|
-
justifyContent: "center",
|
1615
|
-
width: "2rem",
|
1616
|
-
height: "2rem"
|
1617
|
-
}
|
1618
|
-
})
|
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
|
-
});
|
1565
|
+
// packages/ui/react-ui-editor/src/extensions/command/command-menu.ts
|
1633
1566
|
var commandMenu = (options) => {
|
1634
1567
|
const commandMenuPlugin = ViewPlugin6.fromClass(class {
|
1635
1568
|
constructor(view) {
|
@@ -1668,11 +1601,11 @@ var commandMenu = (options) => {
|
|
1668
1601
|
const commandKeymap = keymap4.of([
|
1669
1602
|
...triggers.map((trigger) => ({
|
1670
1603
|
key: trigger,
|
1604
|
+
preventDefault: true,
|
1671
1605
|
run: (view) => {
|
1672
1606
|
const selection = view.state.selection.main;
|
1673
1607
|
const line = view.state.doc.lineAt(selection.head);
|
1674
|
-
|
1675
|
-
if (shouldTrigger) {
|
1608
|
+
if (line.text.trim() === "" || selection.head === line.from || selection.head > line.from && line.text[selection.head - line.from - 1] === " ") {
|
1676
1609
|
view.dispatch({
|
1677
1610
|
changes: {
|
1678
1611
|
from: selection.head,
|
@@ -1759,27 +1692,134 @@ var commandMenu = (options) => {
|
|
1759
1692
|
});
|
1760
1693
|
}
|
1761
1694
|
if (shouldRemove) {
|
1762
|
-
options.
|
1695
|
+
options.onClose?.();
|
1763
1696
|
}
|
1764
1697
|
});
|
1765
1698
|
return [
|
1766
|
-
|
1767
|
-
|
1699
|
+
Prec2.highest(commandKeymap),
|
1700
|
+
placeholder(Object.assign({
|
1701
|
+
content: `Press '${Array.isArray(options.trigger) ? options.trigger[0] : options.trigger}' for commands`
|
1702
|
+
}, options.placeholder)),
|
1768
1703
|
updateListener,
|
1769
1704
|
commandMenuState,
|
1770
1705
|
commandMenuPlugin
|
1771
1706
|
];
|
1772
1707
|
};
|
1773
|
-
var
|
1708
|
+
var commandRangeEffect = StateEffect3.define();
|
1709
|
+
var commandMenuState = StateField3.define({
|
1710
|
+
create: () => null,
|
1711
|
+
update: (value, tr) => {
|
1712
|
+
let newValue = value;
|
1713
|
+
for (const effect of tr.effects) {
|
1714
|
+
if (effect.is(commandRangeEffect)) {
|
1715
|
+
newValue = effect.value;
|
1716
|
+
}
|
1717
|
+
}
|
1718
|
+
return newValue;
|
1719
|
+
}
|
1720
|
+
});
|
1721
|
+
|
1722
|
+
// packages/ui/react-ui-editor/src/extensions/command/floating-menu.ts
|
1723
|
+
import { EditorView as EditorView9, ViewPlugin as ViewPlugin7 } from "@codemirror/view";
|
1724
|
+
import { addEventListener } from "@dxos/async";
|
1725
|
+
var floatingMenu = (options = {}) => [
|
1726
|
+
ViewPlugin7.fromClass(class {
|
1727
|
+
constructor(view) {
|
1728
|
+
this.view = view;
|
1729
|
+
const container = view.scrollDOM;
|
1730
|
+
if (getComputedStyle(container).position === "static") {
|
1731
|
+
container.style.position = "relative";
|
1732
|
+
}
|
1733
|
+
{
|
1734
|
+
const icon = document.createElement("dx-icon");
|
1735
|
+
icon.setAttribute("icon", options.icon ?? "ph--dots-three-vertical--regular");
|
1736
|
+
const button = document.createElement("button");
|
1737
|
+
button.appendChild(icon);
|
1738
|
+
this.tag = document.createElement("dx-ref-tag");
|
1739
|
+
this.tag.classList.add("cm-ref-tag");
|
1740
|
+
this.tag.appendChild(button);
|
1741
|
+
}
|
1742
|
+
container.appendChild(this.tag);
|
1743
|
+
const handler = () => this.scheduleUpdate();
|
1744
|
+
this.cleanup = addEventListener(container, "scroll", handler);
|
1745
|
+
this.scheduleUpdate();
|
1746
|
+
}
|
1747
|
+
destroy() {
|
1748
|
+
this.cleanup?.();
|
1749
|
+
this.tag.remove();
|
1750
|
+
if (this.rafId != null) {
|
1751
|
+
cancelAnimationFrame(this.rafId);
|
1752
|
+
}
|
1753
|
+
}
|
1754
|
+
update(update2) {
|
1755
|
+
this.tag.dataset.focused = update2.view.hasFocus ? "true" : "false";
|
1756
|
+
if (!update2.view.hasFocus) {
|
1757
|
+
return;
|
1758
|
+
}
|
1759
|
+
if (update2.transactions.some((tr) => tr.effects.some((effect) => effect.is(openEffect)))) {
|
1760
|
+
this.tag.style.display = "none";
|
1761
|
+
this.tag.classList.add("opacity-10");
|
1762
|
+
} else if (update2.transactions.some((tr) => tr.effects.some((effect) => effect.is(closeEffect)))) {
|
1763
|
+
this.tag.style.display = "block";
|
1764
|
+
} else if (update2.docChanged || update2.focusChanged || update2.geometryChanged || update2.selectionSet || update2.viewportChanged) {
|
1765
|
+
this.scheduleUpdate();
|
1766
|
+
}
|
1767
|
+
}
|
1768
|
+
updateButtonPosition() {
|
1769
|
+
const { x, width } = this.view.contentDOM.getBoundingClientRect();
|
1770
|
+
const pos = this.view.state.selection.main.head;
|
1771
|
+
const line = this.view.lineBlockAt(pos);
|
1772
|
+
const coords = this.view.coordsAtPos(line.from);
|
1773
|
+
if (!coords) {
|
1774
|
+
return;
|
1775
|
+
}
|
1776
|
+
const lineHeight = coords.bottom - coords.top;
|
1777
|
+
const dy = (lineHeight - (options.height ?? 32)) / 2;
|
1778
|
+
const offsetTop = coords.top + dy;
|
1779
|
+
const offsetLeft = x + width + (options.padding ?? 8);
|
1780
|
+
this.tag.style.top = `${offsetTop}px`;
|
1781
|
+
this.tag.style.left = `${offsetLeft}px`;
|
1782
|
+
this.tag.style.display = "block";
|
1783
|
+
}
|
1784
|
+
scheduleUpdate() {
|
1785
|
+
if (this.rafId != null) {
|
1786
|
+
cancelAnimationFrame(this.rafId);
|
1787
|
+
}
|
1788
|
+
this.rafId = requestAnimationFrame(this.updateButtonPosition.bind(this));
|
1789
|
+
}
|
1790
|
+
}),
|
1791
|
+
EditorView9.theme({
|
1792
|
+
".cm-ref-tag": {
|
1793
|
+
position: "fixed",
|
1794
|
+
padding: "0",
|
1795
|
+
border: "none",
|
1796
|
+
opacity: "0"
|
1797
|
+
},
|
1798
|
+
"[data-has-focus] & .cm-ref-tag": {
|
1799
|
+
opacity: "1"
|
1800
|
+
},
|
1801
|
+
".cm-ref-tag button": {
|
1802
|
+
display: "grid",
|
1803
|
+
alignItems: "center",
|
1804
|
+
justifyContent: "center",
|
1805
|
+
width: "2rem",
|
1806
|
+
height: "2rem"
|
1807
|
+
}
|
1808
|
+
})
|
1809
|
+
];
|
1810
|
+
|
1811
|
+
// packages/ui/react-ui-editor/src/extensions/command/useCommandMenu.ts
|
1812
|
+
import { useCallback, useMemo as useMemo2, useRef, useState } from "react";
|
1813
|
+
var useCommandMenu = ({ viewRef, trigger, placeholder: placeholder3, getMenu }) => {
|
1774
1814
|
const triggerRef = useRef(null);
|
1775
1815
|
const currentRef = useRef(null);
|
1776
1816
|
const groupsRef = useRef([]);
|
1777
1817
|
const [currentItem, setCurrentItem] = useState();
|
1778
1818
|
const [open, setOpen] = useState(false);
|
1779
|
-
const [_,
|
1819
|
+
const [_, refresh] = useState({});
|
1780
1820
|
const handleOpenChange = useCallback(async (open2, trigger2) => {
|
1781
1821
|
if (open2 && trigger2) {
|
1782
|
-
groupsRef.current = await
|
1822
|
+
groupsRef.current = await getMenu(trigger2);
|
1783
1823
|
}
|
1784
1824
|
setOpen(open2);
|
1785
1825
|
if (!open2) {
|
@@ -1792,7 +1832,7 @@ var useCommandMenu = ({ viewRef, trigger, placeholder: placeholder2, getGroups }
|
|
1792
1832
|
});
|
1793
1833
|
}
|
1794
1834
|
}, [
|
1795
|
-
|
1835
|
+
getMenu
|
1796
1836
|
]);
|
1797
1837
|
const handleActivate = useCallback(async (event) => {
|
1798
1838
|
const item = getItem(groupsRef.current, currentItem);
|
@@ -1817,43 +1857,45 @@ var useCommandMenu = ({ viewRef, trigger, placeholder: placeholder2, getGroups }
|
|
1817
1857
|
void item.onSelect?.(view, selection.head);
|
1818
1858
|
}, []);
|
1819
1859
|
const serializedTrigger = Array.isArray(trigger) ? trigger.join(",") : trigger;
|
1820
|
-
const _commandMenu = useMemo2(() =>
|
1821
|
-
|
1822
|
-
|
1823
|
-
|
1824
|
-
|
1825
|
-
|
1826
|
-
|
1827
|
-
|
1828
|
-
|
1829
|
-
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1837
|
-
|
1838
|
-
|
1839
|
-
|
1840
|
-
|
1841
|
-
|
1842
|
-
|
1843
|
-
|
1844
|
-
|
1845
|
-
|
1846
|
-
|
1847
|
-
|
1848
|
-
|
1860
|
+
const _commandMenu = useMemo2(() => {
|
1861
|
+
return commandMenu({
|
1862
|
+
trigger,
|
1863
|
+
placeholder: placeholder3,
|
1864
|
+
onClose: () => handleOpenChange(false),
|
1865
|
+
onArrowDown: () => {
|
1866
|
+
setCurrentItem((currentItem2) => {
|
1867
|
+
const next = getNextItem(groupsRef.current, currentItem2);
|
1868
|
+
currentRef.current = next;
|
1869
|
+
return next.id;
|
1870
|
+
});
|
1871
|
+
},
|
1872
|
+
onArrowUp: () => {
|
1873
|
+
setCurrentItem((currentItem2) => {
|
1874
|
+
const previous = getPreviousItem(groupsRef.current, currentItem2);
|
1875
|
+
currentRef.current = previous;
|
1876
|
+
return previous.id;
|
1877
|
+
});
|
1878
|
+
},
|
1879
|
+
onEnter: () => {
|
1880
|
+
if (currentRef.current) {
|
1881
|
+
handleSelect(currentRef.current);
|
1882
|
+
}
|
1883
|
+
},
|
1884
|
+
onTextChange: async (trigger2, text) => {
|
1885
|
+
groupsRef.current = await getMenu(trigger2, text);
|
1886
|
+
const firstItem = groupsRef.current.filter((group) => group.items.length > 0)[0]?.items[0];
|
1887
|
+
if (firstItem) {
|
1888
|
+
setCurrentItem(firstItem.id);
|
1889
|
+
currentRef.current = firstItem;
|
1890
|
+
}
|
1891
|
+
refresh({});
|
1849
1892
|
}
|
1850
|
-
|
1851
|
-
|
1852
|
-
}), [
|
1893
|
+
});
|
1894
|
+
}, [
|
1853
1895
|
handleOpenChange,
|
1854
|
-
|
1896
|
+
getMenu,
|
1855
1897
|
serializedTrigger,
|
1856
|
-
|
1898
|
+
placeholder3
|
1857
1899
|
]);
|
1858
1900
|
return {
|
1859
1901
|
commandMenu: _commandMenu,
|
@@ -1868,12 +1910,12 @@ var useCommandMenu = ({ viewRef, trigger, placeholder: placeholder2, getGroups }
|
|
1868
1910
|
};
|
1869
1911
|
|
1870
1912
|
// packages/ui/react-ui-editor/src/extensions/command/typeahead.ts
|
1871
|
-
import { EditorSelection, Prec as
|
1872
|
-
import { Decoration as Decoration6, keymap as keymap5, ViewPlugin as
|
1913
|
+
import { EditorSelection, Prec as Prec3, RangeSetBuilder as RangeSetBuilder4 } from "@codemirror/state";
|
1914
|
+
import { Decoration as Decoration6, keymap as keymap5, ViewPlugin as ViewPlugin8 } from "@codemirror/view";
|
1873
1915
|
var typeahead = ({ onComplete } = {}) => {
|
1874
|
-
let
|
1916
|
+
let hint2;
|
1875
1917
|
const complete = (view) => {
|
1876
|
-
if (!
|
1918
|
+
if (!hint2) {
|
1877
1919
|
return false;
|
1878
1920
|
}
|
1879
1921
|
const selection = view.state.selection.main;
|
@@ -1882,15 +1924,15 @@ var typeahead = ({ onComplete } = {}) => {
|
|
1882
1924
|
{
|
1883
1925
|
from: selection.from,
|
1884
1926
|
to: selection.to,
|
1885
|
-
insert:
|
1927
|
+
insert: hint2
|
1886
1928
|
}
|
1887
1929
|
],
|
1888
|
-
selection: EditorSelection.cursor(selection.from +
|
1930
|
+
selection: EditorSelection.cursor(selection.from + hint2.length)
|
1889
1931
|
});
|
1890
1932
|
return true;
|
1891
1933
|
};
|
1892
1934
|
return [
|
1893
|
-
|
1935
|
+
ViewPlugin8.fromClass(class {
|
1894
1936
|
constructor() {
|
1895
1937
|
this.decorations = Decoration6.none;
|
1896
1938
|
}
|
@@ -1900,12 +1942,12 @@ var typeahead = ({ onComplete } = {}) => {
|
|
1900
1942
|
const line = update2.view.state.doc.lineAt(selection.from);
|
1901
1943
|
if (selection.from === selection.to && selection.from === line.to) {
|
1902
1944
|
const str = update2.state.sliceDoc(line.from, selection.from);
|
1903
|
-
|
1945
|
+
hint2 = onComplete?.({
|
1904
1946
|
line: str
|
1905
1947
|
});
|
1906
|
-
if (
|
1948
|
+
if (hint2) {
|
1907
1949
|
builder.add(selection.from, selection.to, Decoration6.widget({
|
1908
|
-
widget: new Hint(
|
1950
|
+
widget: new Hint(hint2)
|
1909
1951
|
}));
|
1910
1952
|
}
|
1911
1953
|
}
|
@@ -1915,7 +1957,7 @@ var typeahead = ({ onComplete } = {}) => {
|
|
1915
1957
|
decorations: (v) => v.decorations
|
1916
1958
|
}),
|
1917
1959
|
// Keys.
|
1918
|
-
|
1960
|
+
Prec3.highest(keymap5.of([
|
1919
1961
|
{
|
1920
1962
|
key: "Tab",
|
1921
1963
|
preventDefault: true,
|
@@ -1953,16 +1995,16 @@ var matchCompletion = (completion, word) => {
|
|
1953
1995
|
// packages/ui/react-ui-editor/src/extensions/comments.ts
|
1954
1996
|
import { invertedEffects } from "@codemirror/commands";
|
1955
1997
|
import { StateEffect as StateEffect4, StateField as StateField4 } from "@codemirror/state";
|
1956
|
-
import { hoverTooltip, keymap as keymap7, Decoration as Decoration7, EditorView as
|
1998
|
+
import { hoverTooltip, keymap as keymap7, Decoration as Decoration7, EditorView as EditorView11, ViewPlugin as ViewPlugin9 } from "@codemirror/view";
|
1957
1999
|
import sortBy from "lodash.sortby";
|
1958
2000
|
import { useEffect } from "react";
|
1959
2001
|
import { debounce as debounce2 } from "@dxos/async";
|
1960
2002
|
import { log as log4 } from "@dxos/log";
|
1961
|
-
import { isNonNullable } from "@dxos/util";
|
2003
|
+
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
1962
2004
|
|
1963
2005
|
// packages/ui/react-ui-editor/src/extensions/selection.ts
|
1964
2006
|
import { Transaction } from "@codemirror/state";
|
1965
|
-
import { EditorView as
|
2007
|
+
import { EditorView as EditorView10, keymap as keymap6 } from "@codemirror/view";
|
1966
2008
|
import { debounce } from "@dxos/async";
|
1967
2009
|
import { invariant as invariant3 } from "@dxos/invariant";
|
1968
2010
|
import { isNotFalsy } from "@dxos/util";
|
@@ -1973,7 +2015,7 @@ var createEditorStateTransaction = ({ scrollTo, selection }) => {
|
|
1973
2015
|
return {
|
1974
2016
|
selection,
|
1975
2017
|
scrollIntoView: !scrollTo,
|
1976
|
-
effects: scrollTo ?
|
2018
|
+
effects: scrollTo ? EditorView10.scrollIntoView(scrollTo, {
|
1977
2019
|
yMargin: 96
|
1978
2020
|
}) : void 0,
|
1979
2021
|
annotations: Transaction.userEvent.of(stateRestoreAnnotation)
|
@@ -2015,7 +2057,7 @@ var selectionState = ({ getState, setState } = {}) => {
|
|
2015
2057
|
// setStateDebounced(id, {});
|
2016
2058
|
// },
|
2017
2059
|
// }),
|
2018
|
-
|
2060
|
+
EditorView10.updateListener.of(({ view, transactions }) => {
|
2019
2061
|
const id = view.state.facet(documentId);
|
2020
2062
|
if (!id || transactions.some((tr) => tr.isUserEvent(stateRestoreAnnotation))) {
|
2021
2063
|
return;
|
@@ -2083,7 +2125,7 @@ var commentsState = StateField4.define({
|
|
2083
2125
|
comment,
|
2084
2126
|
range
|
2085
2127
|
};
|
2086
|
-
}).filter(
|
2128
|
+
}).filter(isNonNullable2);
|
2087
2129
|
return {
|
2088
2130
|
...value,
|
2089
2131
|
comments: commentStates
|
@@ -2096,7 +2138,7 @@ var commentsState = StateField4.define({
|
|
2096
2138
|
return value;
|
2097
2139
|
}
|
2098
2140
|
});
|
2099
|
-
var styles2 =
|
2141
|
+
var styles2 = EditorView11.theme({
|
2100
2142
|
".cm-comment, .cm-comment-current": {
|
2101
2143
|
margin: "0 -3px",
|
2102
2144
|
padding: "3px",
|
@@ -2116,7 +2158,7 @@ var createCommentMark = (id, isCurrent) => Decoration7.mark({
|
|
2116
2158
|
"data-comment-id": id
|
2117
2159
|
}
|
2118
2160
|
});
|
2119
|
-
var commentsDecorations =
|
2161
|
+
var commentsDecorations = EditorView11.decorations.compute([
|
2120
2162
|
commentsState
|
2121
2163
|
], (state) => {
|
2122
2164
|
const { selection: { current }, comments: comments2 } = state.field(commentsState);
|
@@ -2135,11 +2177,11 @@ var commentsDecorations = EditorView10.decorations.compute([
|
|
2135
2177
|
}
|
2136
2178
|
const mark = createCommentMark(comment.comment.id, comment.comment.id === current);
|
2137
2179
|
return mark.range(range.from, range.to);
|
2138
|
-
}).filter(
|
2180
|
+
}).filter(isNonNullable2);
|
2139
2181
|
return Decoration7.set(decorations2);
|
2140
2182
|
});
|
2141
2183
|
var commentClickedEffect = StateEffect4.define();
|
2142
|
-
var handleCommentClick =
|
2184
|
+
var handleCommentClick = EditorView11.domEventHandlers({
|
2143
2185
|
click: (event, view) => {
|
2144
2186
|
let target = event.target;
|
2145
2187
|
const editorRoot = view.dom;
|
@@ -2178,7 +2220,7 @@ var trackPastedComments = (onUpdate) => {
|
|
2178
2220
|
}
|
2179
2221
|
};
|
2180
2222
|
return [
|
2181
|
-
|
2223
|
+
EditorView11.domEventHandlers({
|
2182
2224
|
cut: handleTrack,
|
2183
2225
|
copy: handleTrack
|
2184
2226
|
}),
|
@@ -2200,7 +2242,7 @@ var trackPastedComments = (onUpdate) => {
|
|
2200
2242
|
return effects;
|
2201
2243
|
}),
|
2202
2244
|
// Handle paste or the undo of comment deletion.
|
2203
|
-
|
2245
|
+
EditorView11.updateListener.of((update2) => {
|
2204
2246
|
const restore = [];
|
2205
2247
|
for (let i = 0; i < update2.transactions.length; i++) {
|
2206
2248
|
const tr = update2.transactions[i];
|
@@ -2342,7 +2384,7 @@ var comments = (options = {}) => {
|
|
2342
2384
|
//
|
2343
2385
|
// Track deleted ranges and update ranges for decorations.
|
2344
2386
|
//
|
2345
|
-
|
2387
|
+
EditorView11.updateListener.of(({ view, state, changes }) => {
|
2346
2388
|
let mod = false;
|
2347
2389
|
const { comments: comments2, ...value } = state.field(commentsState);
|
2348
2390
|
changes.iterChanges((from, to, from2, to2) => {
|
@@ -2374,7 +2416,7 @@ var comments = (options = {}) => {
|
|
2374
2416
|
//
|
2375
2417
|
// Track selection/proximity.
|
2376
2418
|
//
|
2377
|
-
|
2419
|
+
EditorView11.updateListener.of(({ view, state }) => {
|
2378
2420
|
let min = Infinity;
|
2379
2421
|
const { selection: { current, closest }, comments: comments2 } = state.field(commentsState);
|
2380
2422
|
const { head } = state.selection.main;
|
@@ -2408,7 +2450,7 @@ var comments = (options = {}) => {
|
|
2408
2450
|
}
|
2409
2451
|
}),
|
2410
2452
|
options.onUpdate && trackPastedComments(options.onUpdate)
|
2411
|
-
].filter(
|
2453
|
+
].filter(isNonNullable2);
|
2412
2454
|
};
|
2413
2455
|
var scrollThreadIntoView = (view, id, center = true) => {
|
2414
2456
|
const comment = view.state.field(commentsState).comments.find((range2) => range2.comment.id === id);
|
@@ -2428,7 +2470,7 @@ var scrollThreadIntoView = (view, id, center = true) => {
|
|
2428
2470
|
anchor: range.from
|
2429
2471
|
} : void 0,
|
2430
2472
|
effects: [
|
2431
|
-
needsScroll ?
|
2473
|
+
needsScroll ? EditorView11.scrollIntoView(range.from, center ? {
|
2432
2474
|
y: "center"
|
2433
2475
|
} : void 0) : [],
|
2434
2476
|
needsSelectionUpdate ? setSelection.of({
|
@@ -2458,7 +2500,7 @@ var ExternalCommentSync = class {
|
|
2458
2500
|
this.unsubscribe = subscribe(updateComments);
|
2459
2501
|
}
|
2460
2502
|
};
|
2461
|
-
var createExternalCommentSync = (id, subscribe, getComments) =>
|
2503
|
+
var createExternalCommentSync = (id, subscribe, getComments) => ViewPlugin9.fromClass(class {
|
2462
2504
|
constructor(view) {
|
2463
2505
|
return new ExternalCommentSync(view, id, subscribe, getComments);
|
2464
2506
|
}
|
@@ -2492,8 +2534,8 @@ var debugNodeLogger = (log9 = console.log) => {
|
|
2492
2534
|
};
|
2493
2535
|
|
2494
2536
|
// packages/ui/react-ui-editor/src/extensions/dnd.ts
|
2495
|
-
import { dropCursor, EditorView as
|
2496
|
-
var styles3 =
|
2537
|
+
import { dropCursor, EditorView as EditorView12 } from "@codemirror/view";
|
2538
|
+
var styles3 = EditorView12.theme({
|
2497
2539
|
".cm-dropCursor": {
|
2498
2540
|
borderLeft: "2px solid var(--dx-accentText)",
|
2499
2541
|
color: "var(--dx-accentText)",
|
@@ -2507,7 +2549,7 @@ var dropFile = (options = {}) => {
|
|
2507
2549
|
return [
|
2508
2550
|
styles3,
|
2509
2551
|
dropCursor(),
|
2510
|
-
|
2552
|
+
EditorView12.domEventHandlers({
|
2511
2553
|
drop: (event, view) => {
|
2512
2554
|
event.preventDefault();
|
2513
2555
|
const files = event.dataTransfer?.files;
|
@@ -2534,7 +2576,7 @@ import { bracketMatching, defaultHighlightStyle, syntaxHighlighting } from "@cod
|
|
2534
2576
|
import { searchKeymap } from "@codemirror/search";
|
2535
2577
|
import { EditorState } from "@codemirror/state";
|
2536
2578
|
import { oneDarkHighlightStyle } from "@codemirror/theme-one-dark";
|
2537
|
-
import { EditorView as
|
2579
|
+
import { EditorView as EditorView15, ViewPlugin as ViewPlugin10, drawSelection, dropCursor as dropCursor2, highlightActiveLine, keymap as keymap8, lineNumbers, placeholder as placeholder2, scrollPastEnd } from "@codemirror/view";
|
2538
2580
|
import defaultsDeep2 from "lodash.defaultsdeep";
|
2539
2581
|
import merge from "lodash.merge";
|
2540
2582
|
import { generateName } from "@dxos/display-name";
|
@@ -2543,7 +2585,7 @@ import { hexToHue, isNotFalsy as isNotFalsy2 } from "@dxos/util";
|
|
2543
2585
|
|
2544
2586
|
// packages/ui/react-ui-editor/src/extensions/focus.ts
|
2545
2587
|
import { StateEffect as StateEffect5, StateField as StateField6 } from "@codemirror/state";
|
2546
|
-
import { EditorView as
|
2588
|
+
import { EditorView as EditorView13 } from "@codemirror/view";
|
2547
2589
|
var focusEffect = StateEffect5.define();
|
2548
2590
|
var focusField = StateField6.define({
|
2549
2591
|
create: () => false,
|
@@ -2558,7 +2600,7 @@ var focusField = StateField6.define({
|
|
2558
2600
|
});
|
2559
2601
|
var focus = [
|
2560
2602
|
focusField,
|
2561
|
-
|
2603
|
+
EditorView13.domEventHandlers({
|
2562
2604
|
focus: (event, view) => {
|
2563
2605
|
setTimeout(() => view.dispatch({
|
2564
2606
|
effects: focusEffect.of(true)
|
@@ -2573,7 +2615,7 @@ var focus = [
|
|
2573
2615
|
];
|
2574
2616
|
|
2575
2617
|
// packages/ui/react-ui-editor/src/defaults.ts
|
2576
|
-
import { EditorView as
|
2618
|
+
import { EditorView as EditorView14 } from "@codemirror/view";
|
2577
2619
|
import { mx as mx2 } from "@dxos/react-ui-theme";
|
2578
2620
|
|
2579
2621
|
// packages/ui/react-ui-editor/src/styles/markdown.ts
|
@@ -2827,20 +2869,19 @@ var editorSlots = {
|
|
2827
2869
|
className: editorWidth
|
2828
2870
|
}
|
2829
2871
|
};
|
2830
|
-
var editorGutter =
|
2872
|
+
var editorGutter = EditorView14.theme({
|
2831
2873
|
".cm-gutters": {
|
2832
2874
|
background: "var(--dx-baseSurface)",
|
2833
2875
|
paddingRight: "1rem"
|
2834
2876
|
}
|
2835
2877
|
});
|
2836
|
-
var editorMonospace =
|
2878
|
+
var editorMonospace = EditorView14.theme({
|
2837
2879
|
".cm-content": {
|
2838
2880
|
fontFamily: fontMono
|
2839
2881
|
}
|
2840
2882
|
});
|
2841
2883
|
var editorWithToolbarLayout = "grid grid-cols-1 grid-rows-[min-content_1fr] data-[toolbar=disabled]:grid-rows-[1fr] justify-center content-start overflow-hidden";
|
2842
2884
|
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
2885
|
|
2845
2886
|
// packages/ui/react-ui-editor/src/extensions/factories.ts
|
2846
2887
|
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/factories.ts";
|
@@ -2866,7 +2907,7 @@ var createBasicExtensions = (_props) => {
|
|
2866
2907
|
const props = defaultsDeep2({}, _props, defaultBasicOptions);
|
2867
2908
|
return [
|
2868
2909
|
// NOTE: Doesn't catch errors in keymap functions.
|
2869
|
-
|
2910
|
+
EditorView15.exceptionSink.of((err) => {
|
2870
2911
|
log5.catch(err, void 0, {
|
2871
2912
|
F: __dxlog_file8,
|
2872
2913
|
L: 100,
|
@@ -2881,7 +2922,7 @@ var createBasicExtensions = (_props) => {
|
|
2881
2922
|
props.drawSelection && drawSelection({
|
2882
2923
|
cursorBlinkRate: 1200
|
2883
2924
|
}),
|
2884
|
-
props.editable !== void 0 &&
|
2925
|
+
props.editable !== void 0 && EditorView15.editable.of(props.editable),
|
2885
2926
|
props.focus && focus,
|
2886
2927
|
props.highlightActiveLine && highlightActiveLine(),
|
2887
2928
|
props.history && history(),
|
@@ -2889,9 +2930,9 @@ var createBasicExtensions = (_props) => {
|
|
2889
2930
|
lineNumbers(),
|
2890
2931
|
editorGutter
|
2891
2932
|
],
|
2892
|
-
props.lineWrapping &&
|
2933
|
+
props.lineWrapping && EditorView15.lineWrapping,
|
2893
2934
|
props.monospace && editorMonospace,
|
2894
|
-
props.placeholder &&
|
2935
|
+
props.placeholder && placeholder2(props.placeholder),
|
2895
2936
|
props.readOnly !== void 0 && EditorState.readOnly.of(props.readOnly),
|
2896
2937
|
props.scrollPastEnd && scrollPastEnd(),
|
2897
2938
|
props.tabSize && EditorState.tabSize.of(props.tabSize),
|
@@ -2927,17 +2968,17 @@ var defaultThemeSlots = {
|
|
2927
2968
|
var createThemeExtensions = ({ themeMode, styles: styles4, syntaxHighlighting: _syntaxHighlighting, slots: _slots } = {}) => {
|
2928
2969
|
const slots = defaultsDeep2({}, _slots, defaultThemeSlots);
|
2929
2970
|
return [
|
2930
|
-
|
2931
|
-
|
2971
|
+
EditorView15.darkTheme.of(themeMode === "dark"),
|
2972
|
+
EditorView15.baseTheme(styles4 ? merge({}, defaultTheme, styles4) : defaultTheme),
|
2932
2973
|
// https://github.com/codemirror/theme-one-dark
|
2933
2974
|
_syntaxHighlighting && (themeMode === "dark" ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle)),
|
2934
|
-
slots.editor?.className &&
|
2975
|
+
slots.editor?.className && EditorView15.editorAttributes.of({
|
2935
2976
|
class: slots.editor.className
|
2936
2977
|
}),
|
2937
|
-
slots.content?.className &&
|
2978
|
+
slots.content?.className && EditorView15.contentAttributes.of({
|
2938
2979
|
class: slots.content.className
|
2939
2980
|
}),
|
2940
|
-
slots.scroll?.className &&
|
2981
|
+
slots.scroll?.className && ViewPlugin10.fromClass(class {
|
2941
2982
|
constructor(view) {
|
2942
2983
|
view.scrollDOM.classList.add(slots.scroll.className);
|
2943
2984
|
}
|
@@ -2968,7 +3009,7 @@ var createDataExtensions = ({ id, text, space, identity }) => {
|
|
2968
3009
|
|
2969
3010
|
// packages/ui/react-ui-editor/src/extensions/folding.tsx
|
2970
3011
|
import { codeFolding, foldGutter } from "@codemirror/language";
|
2971
|
-
import { EditorView as
|
3012
|
+
import { EditorView as EditorView16 } from "@codemirror/view";
|
2972
3013
|
import React2 from "react";
|
2973
3014
|
import { Icon } from "@dxos/react-ui";
|
2974
3015
|
var folding = (_props = {}) => [
|
@@ -2992,7 +3033,7 @@ var folding = (_props = {}) => [
|
|
2992
3033
|
}));
|
2993
3034
|
}
|
2994
3035
|
}),
|
2995
|
-
|
3036
|
+
EditorView16.theme({
|
2996
3037
|
".cm-foldGutter": {
|
2997
3038
|
opacity: 0.3,
|
2998
3039
|
transition: "opacity 0.3s",
|
@@ -3005,7 +3046,7 @@ var folding = (_props = {}) => [
|
|
3005
3046
|
];
|
3006
3047
|
|
3007
3048
|
// packages/ui/react-ui-editor/src/extensions/hashtag.tsx
|
3008
|
-
import { Decoration as Decoration8, EditorView as
|
3049
|
+
import { Decoration as Decoration8, EditorView as EditorView17, MatchDecorator, ViewPlugin as ViewPlugin11, WidgetType as WidgetType4 } from "@codemirror/view";
|
3009
3050
|
import { getHashColor, mx as mx3 } from "@dxos/react-ui-theme";
|
3010
3051
|
var TagWidget = class extends WidgetType4 {
|
3011
3052
|
constructor(_text) {
|
@@ -3025,7 +3066,7 @@ var tagMatcher = new MatchDecorator({
|
|
3025
3066
|
})
|
3026
3067
|
});
|
3027
3068
|
var hashtag = () => [
|
3028
|
-
|
3069
|
+
ViewPlugin11.fromClass(class {
|
3029
3070
|
constructor(view) {
|
3030
3071
|
this.tags = tagMatcher.createDeco(view);
|
3031
3072
|
}
|
@@ -3034,11 +3075,11 @@ var hashtag = () => [
|
|
3034
3075
|
}
|
3035
3076
|
}, {
|
3036
3077
|
decorations: (instance) => instance.tags,
|
3037
|
-
provide: (plugin) =>
|
3078
|
+
provide: (plugin) => EditorView17.atomicRanges.of((view) => {
|
3038
3079
|
return view.plugin(plugin)?.tags || Decoration8.none;
|
3039
3080
|
})
|
3040
3081
|
}),
|
3041
|
-
|
3082
|
+
EditorView17.theme({
|
3042
3083
|
".cm-tag": {
|
3043
3084
|
borderRadius: "4px",
|
3044
3085
|
marginRight: "6px",
|
@@ -3093,14 +3134,14 @@ var schemaLinter = (validate) => (view) => {
|
|
3093
3134
|
};
|
3094
3135
|
|
3095
3136
|
// packages/ui/react-ui-editor/src/extensions/listener.ts
|
3096
|
-
import { EditorView as
|
3137
|
+
import { EditorView as EditorView18 } from "@codemirror/view";
|
3097
3138
|
var listener = ({ onFocus, onChange }) => {
|
3098
3139
|
const extensions = [];
|
3099
|
-
onFocus && extensions.push(
|
3140
|
+
onFocus && extensions.push(EditorView18.focusChangeEffect.of((_, focusing) => {
|
3100
3141
|
onFocus(focusing);
|
3101
3142
|
return null;
|
3102
3143
|
}));
|
3103
|
-
onChange && extensions.push(
|
3144
|
+
onChange && extensions.push(EditorView18.updateListener.of((update2) => {
|
3104
3145
|
onChange(update2.state.doc.toString(), update2.state.facet(documentId));
|
3105
3146
|
}));
|
3106
3147
|
return extensions;
|
@@ -3110,7 +3151,7 @@ var listener = ({ onFocus, onChange }) => {
|
|
3110
3151
|
import { snippet } from "@codemirror/autocomplete";
|
3111
3152
|
import { syntaxTree as syntaxTree2 } from "@codemirror/language";
|
3112
3153
|
import { EditorSelection as EditorSelection2 } from "@codemirror/state";
|
3113
|
-
import { EditorView as
|
3154
|
+
import { EditorView as EditorView19, keymap as keymap9 } from "@codemirror/view";
|
3114
3155
|
import { useMemo as useMemo3 } from "react";
|
3115
3156
|
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;
|
3116
3157
|
var Inline = /* @__PURE__ */ function(Inline2) {
|
@@ -4199,7 +4240,7 @@ var getFormatting = (state) => {
|
|
4199
4240
|
};
|
4200
4241
|
};
|
4201
4242
|
var useFormattingState = (state) => {
|
4202
|
-
return useMemo3(() =>
|
4243
|
+
return useMemo3(() => EditorView19.updateListener.of((update2) => {
|
4203
4244
|
if (update2.docChanged || update2.selectionSet) {
|
4204
4245
|
Object.entries(getFormatting(update2.state)).forEach(([key, active]) => {
|
4205
4246
|
state[key] = active;
|
@@ -4263,7 +4304,6 @@ import { defaultKeymap as defaultKeymap2, indentWithTab as indentWithTab2 } from
|
|
4263
4304
|
import { markdownLanguage as markdownLanguage3, markdown } from "@codemirror/lang-markdown";
|
4264
4305
|
import { syntaxHighlighting as syntaxHighlighting2 } from "@codemirror/language";
|
4265
4306
|
import { languages } from "@codemirror/language-data";
|
4266
|
-
import { lintKeymap } from "@codemirror/lint";
|
4267
4307
|
import { keymap as keymap10 } from "@codemirror/view";
|
4268
4308
|
import { isNotFalsy as isNotFalsy3 } from "@dxos/util";
|
4269
4309
|
|
@@ -4476,8 +4516,7 @@ var createMarkdownExtensions = (options = {}) => {
|
|
4476
4516
|
options.indentWithTab !== false && indentWithTab2,
|
4477
4517
|
// https://codemirror.net/docs/ref/#commands.defaultKeymap
|
4478
4518
|
...defaultKeymap2,
|
4479
|
-
...completionKeymap2
|
4480
|
-
...lintKeymap
|
4519
|
+
...completionKeymap2
|
4481
4520
|
].filter(isNotFalsy3))
|
4482
4521
|
];
|
4483
4522
|
};
|
@@ -4512,16 +4551,16 @@ var convertTreeToJson = (state) => {
|
|
4512
4551
|
// packages/ui/react-ui-editor/src/extensions/markdown/decorate.ts
|
4513
4552
|
import { syntaxTree as syntaxTree7 } from "@codemirror/language";
|
4514
4553
|
import { RangeSetBuilder as RangeSetBuilder6, StateEffect as StateEffect6 } from "@codemirror/state";
|
4515
|
-
import { EditorView as
|
4554
|
+
import { EditorView as EditorView23, Decoration as Decoration11, WidgetType as WidgetType7, ViewPlugin as ViewPlugin13 } from "@codemirror/view";
|
4516
4555
|
import { invariant as invariant4 } from "@dxos/invariant";
|
4517
4556
|
import { mx as mx4 } from "@dxos/react-ui-theme";
|
4518
4557
|
|
4519
4558
|
// packages/ui/react-ui-editor/src/extensions/markdown/changes.ts
|
4520
4559
|
import { syntaxTree as syntaxTree4 } from "@codemirror/language";
|
4521
4560
|
import { Transaction as Transaction2 } from "@codemirror/state";
|
4522
|
-
import { ViewPlugin as
|
4561
|
+
import { ViewPlugin as ViewPlugin12 } from "@codemirror/view";
|
4523
4562
|
var adjustChanges = () => {
|
4524
|
-
return
|
4563
|
+
return ViewPlugin12.fromClass(class {
|
4525
4564
|
update(update2) {
|
4526
4565
|
const tree = syntaxTree4(update2.state);
|
4527
4566
|
const adjustments = [];
|
@@ -4663,7 +4702,7 @@ var getValidUrl = (str) => {
|
|
4663
4702
|
// packages/ui/react-ui-editor/src/extensions/markdown/image.ts
|
4664
4703
|
import { syntaxTree as syntaxTree5 } from "@codemirror/language";
|
4665
4704
|
import { StateField as StateField8 } from "@codemirror/state";
|
4666
|
-
import { Decoration as Decoration9, EditorView as
|
4705
|
+
import { Decoration as Decoration9, EditorView as EditorView20, WidgetType as WidgetType5 } from "@codemirror/view";
|
4667
4706
|
var image = (_options = {}) => {
|
4668
4707
|
return [
|
4669
4708
|
StateField8.define({
|
@@ -4691,7 +4730,7 @@ var image = (_options = {}) => {
|
|
4691
4730
|
add: buildDecorations(from, to, tr.state)
|
4692
4731
|
});
|
4693
4732
|
},
|
4694
|
-
provide: (field) =>
|
4733
|
+
provide: (field) => EditorView20.decorations.from(field)
|
4695
4734
|
})
|
4696
4735
|
];
|
4697
4736
|
};
|
@@ -4750,10 +4789,10 @@ var ImageWidget = class extends WidgetType5 {
|
|
4750
4789
|
};
|
4751
4790
|
|
4752
4791
|
// packages/ui/react-ui-editor/src/extensions/markdown/styles.ts
|
4753
|
-
import { EditorView as
|
4792
|
+
import { EditorView as EditorView21 } from "@codemirror/view";
|
4754
4793
|
var bulletListIndentationWidth = 24;
|
4755
4794
|
var orderedListIndentationWidth = 36;
|
4756
|
-
var formattingStyles =
|
4795
|
+
var formattingStyles = EditorView21.theme({
|
4757
4796
|
/**
|
4758
4797
|
* Horizontal rule.
|
4759
4798
|
*/
|
@@ -4875,12 +4914,12 @@ var formattingStyles = EditorView20.theme({
|
|
4875
4914
|
// packages/ui/react-ui-editor/src/extensions/markdown/table.ts
|
4876
4915
|
import { syntaxTree as syntaxTree6 } from "@codemirror/language";
|
4877
4916
|
import { RangeSetBuilder as RangeSetBuilder5, StateField as StateField9 } from "@codemirror/state";
|
4878
|
-
import { Decoration as Decoration10, EditorView as
|
4917
|
+
import { Decoration as Decoration10, EditorView as EditorView22, WidgetType as WidgetType6 } from "@codemirror/view";
|
4879
4918
|
var table = (options = {}) => {
|
4880
4919
|
return StateField9.define({
|
4881
4920
|
create: (state) => update(state, options),
|
4882
4921
|
update: (_, tr) => update(tr.state, options),
|
4883
|
-
provide: (field) =>
|
4922
|
+
provide: (field) => EditorView22.decorations.from(field)
|
4884
4923
|
});
|
4885
4924
|
};
|
4886
4925
|
var update = (state, _options) => {
|
@@ -5381,7 +5420,7 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
5381
5420
|
var forceUpdate = StateEffect6.define();
|
5382
5421
|
var decorateMarkdown = (options = {}) => {
|
5383
5422
|
return [
|
5384
|
-
|
5423
|
+
ViewPlugin13.fromClass(class {
|
5385
5424
|
constructor(view) {
|
5386
5425
|
({ deco: this.deco, atomicDeco: this.atomicDeco } = buildDecorations2(view, options, view.hasFocus));
|
5387
5426
|
}
|
@@ -5413,9 +5452,9 @@ var decorateMarkdown = (options = {}) => {
|
|
5413
5452
|
}
|
5414
5453
|
}, {
|
5415
5454
|
provide: (plugin) => [
|
5416
|
-
|
5417
|
-
|
5418
|
-
|
5455
|
+
EditorView23.atomicRanges.of((view) => view.plugin(plugin)?.atomicDeco ?? Decoration11.none),
|
5456
|
+
EditorView23.decorations.of((view) => view.plugin(plugin)?.atomicDeco ?? Decoration11.none),
|
5457
|
+
EditorView23.decorations.of((view) => view.plugin(plugin)?.deco ?? Decoration11.none)
|
5419
5458
|
]
|
5420
5459
|
}),
|
5421
5460
|
image(),
|
@@ -5660,6 +5699,7 @@ var traverse = (root, cb) => {
|
|
5660
5699
|
return value;
|
5661
5700
|
}
|
5662
5701
|
}
|
5702
|
+
return void 0;
|
5663
5703
|
};
|
5664
5704
|
return t(root, root.type === "root" ? -1 : 0);
|
5665
5705
|
};
|
@@ -5717,7 +5757,7 @@ var outlinerTree = (options = {}) => {
|
|
5717
5757
|
case "BulletList": {
|
5718
5758
|
invariant5(current, void 0, {
|
5719
5759
|
F: __dxlog_file11,
|
5720
|
-
L:
|
5760
|
+
L: 219,
|
5721
5761
|
S: void 0,
|
5722
5762
|
A: [
|
5723
5763
|
"current",
|
@@ -5734,7 +5774,7 @@ var outlinerTree = (options = {}) => {
|
|
5734
5774
|
case "ListItem": {
|
5735
5775
|
invariant5(parent, void 0, {
|
5736
5776
|
F: __dxlog_file11,
|
5737
|
-
L:
|
5777
|
+
L: 228,
|
5738
5778
|
S: void 0,
|
5739
5779
|
A: [
|
5740
5780
|
"parent",
|
@@ -5776,7 +5816,7 @@ var outlinerTree = (options = {}) => {
|
|
5776
5816
|
case "ListMark": {
|
5777
5817
|
invariant5(current, void 0, {
|
5778
5818
|
F: __dxlog_file11,
|
5779
|
-
L:
|
5819
|
+
L: 272,
|
5780
5820
|
S: void 0,
|
5781
5821
|
A: [
|
5782
5822
|
"current",
|
@@ -5790,7 +5830,7 @@ var outlinerTree = (options = {}) => {
|
|
5790
5830
|
case "Task": {
|
5791
5831
|
invariant5(current, void 0, {
|
5792
5832
|
F: __dxlog_file11,
|
5793
|
-
L:
|
5833
|
+
L: 278,
|
5794
5834
|
S: void 0,
|
5795
5835
|
A: [
|
5796
5836
|
"current",
|
@@ -5803,7 +5843,7 @@ var outlinerTree = (options = {}) => {
|
|
5803
5843
|
case "TaskMarker": {
|
5804
5844
|
invariant5(current, void 0, {
|
5805
5845
|
F: __dxlog_file11,
|
5806
|
-
L:
|
5846
|
+
L: 283,
|
5807
5847
|
S: void 0,
|
5808
5848
|
A: [
|
5809
5849
|
"current",
|
@@ -5819,7 +5859,7 @@ var outlinerTree = (options = {}) => {
|
|
5819
5859
|
if (node.name === "BulletList") {
|
5820
5860
|
invariant5(parent, void 0, {
|
5821
5861
|
F: __dxlog_file11,
|
5822
|
-
L:
|
5862
|
+
L: 291,
|
5823
5863
|
S: void 0,
|
5824
5864
|
A: [
|
5825
5865
|
"parent",
|
@@ -5833,7 +5873,7 @@ var outlinerTree = (options = {}) => {
|
|
5833
5873
|
});
|
5834
5874
|
invariant5(tree, void 0, {
|
5835
5875
|
F: __dxlog_file11,
|
5836
|
-
L:
|
5876
|
+
L: 298,
|
5837
5877
|
S: void 0,
|
5838
5878
|
A: [
|
5839
5879
|
"tree",
|
@@ -6123,18 +6163,18 @@ var commands = () => keymap12.of([
|
|
6123
6163
|
]);
|
6124
6164
|
|
6125
6165
|
// packages/ui/react-ui-editor/src/extensions/outliner/outliner.ts
|
6126
|
-
import { Prec as
|
6127
|
-
import { Decoration as Decoration12, EditorView as
|
6166
|
+
import { Prec as Prec4 } from "@codemirror/state";
|
6167
|
+
import { Decoration as Decoration12, EditorView as EditorView24, ViewPlugin as ViewPlugin15 } from "@codemirror/view";
|
6128
6168
|
import { mx as mx5 } from "@dxos/react-ui-theme";
|
6129
6169
|
|
6130
6170
|
// packages/ui/react-ui-editor/src/extensions/outliner/editor.ts
|
6131
6171
|
import { EditorSelection as EditorSelection4, EditorState as EditorState2 } from "@codemirror/state";
|
6132
|
-
import { ViewPlugin as
|
6172
|
+
import { ViewPlugin as ViewPlugin14 } from "@codemirror/view";
|
6133
6173
|
import { log as log7 } from "@dxos/log";
|
6134
6174
|
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/outliner/editor.ts";
|
6135
6175
|
var LIST_ITEM_REGEX = /^\s*- (\[ \]|\[x\])? /;
|
6136
6176
|
var initialize = () => {
|
6137
|
-
return
|
6177
|
+
return ViewPlugin14.fromClass(class {
|
6138
6178
|
constructor(view) {
|
6139
6179
|
const first = view.state.doc.lineAt(0);
|
6140
6180
|
const text = view.state.sliceDoc(first.from, first.to);
|
@@ -6319,7 +6359,7 @@ var editor = () => [
|
|
6319
6359
|
// packages/ui/react-ui-editor/src/extensions/outliner/outliner.ts
|
6320
6360
|
var outliner = (options = {}) => [
|
6321
6361
|
// Commands.
|
6322
|
-
|
6362
|
+
Prec4.highest(commands()),
|
6323
6363
|
// Selection.
|
6324
6364
|
selectionCompartment.of(selectionFacet.of([])),
|
6325
6365
|
// State.
|
@@ -6335,12 +6375,12 @@ var outliner = (options = {}) => [
|
|
6335
6375
|
listPaddingLeft: 8
|
6336
6376
|
}),
|
6337
6377
|
// Researve space for menu.
|
6338
|
-
|
6378
|
+
EditorView24.contentAttributes.of({
|
6339
6379
|
class: "is-full !mr-[3rem]"
|
6340
6380
|
})
|
6341
6381
|
];
|
6342
6382
|
var decorations = () => [
|
6343
|
-
|
6383
|
+
ViewPlugin15.fromClass(class {
|
6344
6384
|
constructor(view) {
|
6345
6385
|
this.decorations = Decoration12.none;
|
6346
6386
|
this.updateDecorations(view.state, view);
|
@@ -6375,7 +6415,7 @@ var decorations = () => [
|
|
6375
6415
|
decorations: (v) => v.decorations
|
6376
6416
|
}),
|
6377
6417
|
// Theme.
|
6378
|
-
|
6418
|
+
EditorView24.theme(Object.assign({
|
6379
6419
|
".cm-list-item": {
|
6380
6420
|
borderLeftWidth: "1px",
|
6381
6421
|
borderRightWidth: "1px",
|
@@ -6412,7 +6452,7 @@ var decorations = () => [
|
|
6412
6452
|
import "@dxos/lit-ui/dx-ref-tag.pcss";
|
6413
6453
|
import { syntaxTree as syntaxTree10 } from "@codemirror/language";
|
6414
6454
|
import { RangeSetBuilder as RangeSetBuilder7, StateField as StateField11 } from "@codemirror/state";
|
6415
|
-
import { Decoration as Decoration13, EditorView as
|
6455
|
+
import { Decoration as Decoration13, EditorView as EditorView25, WidgetType as WidgetType8 } from "@codemirror/view";
|
6416
6456
|
var preview = (options = {}) => {
|
6417
6457
|
return [
|
6418
6458
|
// NOTE: Atomic block decorations must be created from a state field, now a widget, otherwise it results in the following error:
|
@@ -6421,16 +6461,9 @@ var preview = (options = {}) => {
|
|
6421
6461
|
create: (state) => buildDecorations3(state, options),
|
6422
6462
|
update: (_, tr) => buildDecorations3(tr.state, options),
|
6423
6463
|
provide: (field) => [
|
6424
|
-
|
6425
|
-
|
6464
|
+
EditorView25.decorations.from(field),
|
6465
|
+
EditorView25.atomicRanges.of((view) => view.state.field(field))
|
6426
6466
|
]
|
6427
|
-
}),
|
6428
|
-
EditorView24.theme({
|
6429
|
-
".cm-preview-block": {
|
6430
|
-
"--dx-card-spacing-inline": "var(--dx-trimMd)",
|
6431
|
-
"--dx-card-spacing-block": "var(--dx-trimMd)",
|
6432
|
-
marginInline: "calc(-1*var(--dx-trimMd))"
|
6433
|
-
}
|
6434
6467
|
})
|
6435
6468
|
];
|
6436
6469
|
};
|
@@ -6471,7 +6504,7 @@ var buildDecorations3 = (state, options) => {
|
|
6471
6504
|
//
|
6472
6505
|
case "Image": {
|
6473
6506
|
const link = getLinkRef(state, node.node);
|
6474
|
-
if (options.
|
6507
|
+
if (options.addBlockContainer && options.removeBlockContainer && link) {
|
6475
6508
|
builder.add(node.from, node.to, Decoration13.replace({
|
6476
6509
|
block: true,
|
6477
6510
|
// atomic: true,
|
@@ -6514,50 +6547,13 @@ var PreviewBlockWidget = class extends WidgetType8 {
|
|
6514
6547
|
}
|
6515
6548
|
toDOM(view) {
|
6516
6549
|
const root = document.createElement("div");
|
6517
|
-
root.classList.add("cm-preview-block");
|
6518
|
-
|
6519
|
-
const pos = view.posAtDOM(root);
|
6520
|
-
const node = syntaxTree10(view.state).resolve(pos + 1).node.parent;
|
6521
|
-
if (!node) {
|
6522
|
-
return;
|
6523
|
-
}
|
6524
|
-
const link = getLinkRef(view.state, node);
|
6525
|
-
if (link?.ref !== action.link.ref) {
|
6526
|
-
return;
|
6527
|
-
}
|
6528
|
-
switch (action.type) {
|
6529
|
-
// TODO(burdon): Should we dispatch to the view or mutate the document? (i.e., handle externally?)
|
6530
|
-
// Insert ref text.
|
6531
|
-
case "insert": {
|
6532
|
-
view.dispatch({
|
6533
|
-
changes: {
|
6534
|
-
from: node.from,
|
6535
|
-
to: node.to,
|
6536
|
-
insert: action.target.text
|
6537
|
-
}
|
6538
|
-
});
|
6539
|
-
break;
|
6540
|
-
}
|
6541
|
-
// Remove ref.
|
6542
|
-
case "delete": {
|
6543
|
-
view.dispatch({
|
6544
|
-
changes: {
|
6545
|
-
from: node.from,
|
6546
|
-
to: node.to
|
6547
|
-
}
|
6548
|
-
});
|
6549
|
-
break;
|
6550
|
-
}
|
6551
|
-
}
|
6552
|
-
};
|
6553
|
-
this._options.renderBlock(root, {
|
6554
|
-
readonly: view.state.readOnly,
|
6555
|
-
link: this._link,
|
6556
|
-
onAction: handleAction,
|
6557
|
-
onLookup: this._options.onLookup
|
6558
|
-
}, view);
|
6550
|
+
root.classList.add("cm-preview-block", "density-coarse");
|
6551
|
+
this._options.addBlockContainer?.(this._link, root);
|
6559
6552
|
return root;
|
6560
6553
|
}
|
6554
|
+
destroy() {
|
6555
|
+
this._options.removeBlockContainer?.(this._link);
|
6556
|
+
}
|
6561
6557
|
};
|
6562
6558
|
|
6563
6559
|
// packages/ui/react-ui-editor/src/extensions/typewriter.ts
|
@@ -6998,20 +6994,15 @@ var EditorToolbar = /* @__PURE__ */ memo(({ classNames, attendableId, role, ...p
|
|
6998
6994
|
var _effect = _useSignals();
|
6999
6995
|
try {
|
7000
6996
|
const menuProps = useEditorToolbarActionGraph(props);
|
7001
|
-
return /* @__PURE__ */ React3.createElement(
|
7002
|
-
role: "none",
|
7003
|
-
className: stackItemContentToolbarClassNames(role)
|
7004
|
-
}, /* @__PURE__ */ React3.createElement(ElevationProvider, {
|
6997
|
+
return /* @__PURE__ */ React3.createElement(ElevationProvider, {
|
7005
6998
|
elevation: role === "section" ? "positioned" : "base"
|
7006
6999
|
}, /* @__PURE__ */ React3.createElement(MenuProvider, {
|
7007
7000
|
...menuProps,
|
7008
7001
|
attendableId
|
7009
7002
|
}, /* @__PURE__ */ React3.createElement(ToolbarMenu, {
|
7010
|
-
classNames
|
7011
|
-
|
7012
|
-
|
7013
|
-
]
|
7014
|
-
}))));
|
7003
|
+
classNames,
|
7004
|
+
textBlockWidth: true
|
7005
|
+
})));
|
7015
7006
|
} finally {
|
7016
7007
|
_effect.f();
|
7017
7008
|
}
|
@@ -7297,7 +7288,10 @@ var RefPopover = /* @__PURE__ */ forwardRef(({ children, open, onOpenChange, mod
|
|
7297
7288
|
try {
|
7298
7289
|
const [rootRef, setRootRef] = useState2(null);
|
7299
7290
|
useEffect3(() => {
|
7300
|
-
|
7291
|
+
if (!rootRef || !onActivate) {
|
7292
|
+
return;
|
7293
|
+
}
|
7294
|
+
return addEventListener2(rootRef, "dx-ref-tag-activate", onActivate, customEventOptions);
|
7301
7295
|
}, [
|
7302
7296
|
rootRef,
|
7303
7297
|
onActivate
|
@@ -7406,7 +7400,10 @@ var RefDropdownMenuProvider = ({ children, onLookup }) => {
|
|
7406
7400
|
onLookup
|
7407
7401
|
]);
|
7408
7402
|
useEffect4(() => {
|
7409
|
-
|
7403
|
+
if (!rootRef) {
|
7404
|
+
return;
|
7405
|
+
}
|
7406
|
+
return addEventListener3(rootRef, "dx-ref-tag-activate", handleDxRefTagActivate, customEventOptions2);
|
7410
7407
|
}, [
|
7411
7408
|
rootRef
|
7412
7409
|
]);
|
@@ -7434,7 +7431,7 @@ var RefDropdownMenu = {
|
|
7434
7431
|
|
7435
7432
|
// packages/ui/react-ui-editor/src/hooks/useTextEditor.ts
|
7436
7433
|
import { EditorState as EditorState3 } from "@codemirror/state";
|
7437
|
-
import { EditorView as
|
7434
|
+
import { EditorView as EditorView26 } from "@codemirror/view";
|
7438
7435
|
import { useFocusableGroup } from "@fluentui/react-tabster";
|
7439
7436
|
import { useCallback as useCallback5, useEffect as useEffect5, useMemo as useMemo5, useRef as useRef5, useState as useState4 } from "react";
|
7440
7437
|
import { log as log8 } from "@dxos/log";
|
@@ -7478,7 +7475,7 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
7478
7475
|
id && documentId.of(id),
|
7479
7476
|
extensions,
|
7480
7477
|
// NOTE: This doesn't catch errors in keymap functions.
|
7481
|
-
|
7478
|
+
EditorView26.exceptionSink.of((err) => {
|
7482
7479
|
log8.catch(err, void 0, {
|
7483
7480
|
F: __dxlog_file13,
|
7484
7481
|
L: 97,
|
@@ -7488,10 +7485,10 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
7488
7485
|
})
|
7489
7486
|
].filter(isNotFalsy4)
|
7490
7487
|
});
|
7491
|
-
view2 = new
|
7488
|
+
view2 = new EditorView26({
|
7492
7489
|
parent: parentRef.current,
|
7493
7490
|
state,
|
7494
|
-
scrollTo: scrollTo ?
|
7491
|
+
scrollTo: scrollTo ? EditorView26.scrollIntoView(scrollTo, {
|
7495
7492
|
yMargin: 96
|
7496
7493
|
}) : void 0,
|
7497
7494
|
dispatchTransactions: debug ? debugDispatcher : void 0
|
@@ -7591,7 +7588,7 @@ export {
|
|
7591
7588
|
EditorInputModes,
|
7592
7589
|
EditorState4 as EditorState,
|
7593
7590
|
EditorToolbar,
|
7594
|
-
|
7591
|
+
EditorView27 as EditorView,
|
7595
7592
|
EditorViewMode,
|
7596
7593
|
EditorViewModes,
|
7597
7594
|
Inline,
|
@@ -7666,6 +7663,7 @@ export {
|
|
7666
7663
|
formattingKeymap,
|
7667
7664
|
getFormatting,
|
7668
7665
|
getItem,
|
7666
|
+
getLinkRef,
|
7669
7667
|
getListItemContent,
|
7670
7668
|
getNextItem,
|
7671
7669
|
getPreviousItem,
|
@@ -7691,7 +7689,6 @@ export {
|
|
7691
7689
|
mention,
|
7692
7690
|
moveItemDown,
|
7693
7691
|
moveItemUp,
|
7694
|
-
multilinePlaceholder,
|
7695
7692
|
openCommand,
|
7696
7693
|
openEffect,
|
7697
7694
|
outliner,
|
@@ -7715,7 +7712,6 @@ export {
|
|
7715
7712
|
setStyle,
|
7716
7713
|
singleValueFacet,
|
7717
7714
|
stackItemContentEditorClassNames,
|
7718
|
-
stackItemContentToolbarClassNames,
|
7719
7715
|
staticCompletion,
|
7720
7716
|
table,
|
7721
7717
|
tags2 as tags,
|