@dxos/react-ui-editor 0.6.1 → 0.6.2-main.000b1cc

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.
@@ -1481,39 +1481,57 @@ var commentsState = StateField4.define({
1481
1481
  }
1482
1482
  });
1483
1483
  var styles3 = EditorView7.baseTheme({
1484
+ ".cm-comment, .cm-comment-current": {
1485
+ cursor: "pointer",
1486
+ borderWidth: "1px",
1487
+ borderStyle: "solid",
1488
+ borderRadius: "2px",
1489
+ transition: "background-color 0.1s ease"
1490
+ },
1484
1491
  "&light .cm-comment, &light .cm-comment-current": {
1485
- mixBlendMode: "darken"
1492
+ mixBlendMode: "darken",
1493
+ borderColor: getToken("extend.colors.yellow.100")
1486
1494
  },
1487
1495
  "&dark .cm-comment, &dark .cm-comment-current": {
1488
- mixBlendMode: "plus-lighter"
1496
+ mixBlendMode: "plus-lighter",
1497
+ borderColor: getToken("extend.colors.yellow.900")
1489
1498
  },
1490
1499
  "&light .cm-comment": {
1491
1500
  backgroundColor: getToken("extend.colors.yellow.50")
1492
1501
  },
1502
+ "&light .cm-comment:hover": {
1503
+ backgroundColor: getToken("extend.colors.yellow.100")
1504
+ },
1493
1505
  "&light .cm-comment-current": {
1494
1506
  backgroundColor: getToken("extend.colors.yellow.100")
1495
1507
  },
1508
+ "&light .cm-comment-current:hover": {
1509
+ backgroundColor: getToken("extend.colors.yellow.150")
1510
+ },
1496
1511
  "&dark .cm-comment": {
1497
1512
  color: getToken("extend.colors.yellow.50"),
1498
1513
  backgroundColor: getToken("extend.colors.yellow.900")
1499
1514
  },
1515
+ "&dark .cm-comment:hover": {
1516
+ backgroundColor: getToken("extend.colors.yellow.800")
1517
+ },
1500
1518
  "&dark .cm-comment-current": {
1501
1519
  color: getToken("extend.colors.yellow.100"),
1502
1520
  backgroundColor: getToken("extend.colors.yellow.950")
1521
+ },
1522
+ "&dark .cm-comment-current:hover": {
1523
+ backgroundColor: getToken("extend.colors.yellow.900")
1503
1524
  }
1504
1525
  });
1505
- var commentMark = Decoration4.mark({
1506
- class: "cm-comment",
1507
- attributes: {
1508
- "data-testid": "cm-comment"
1509
- }
1510
- });
1511
- var commentCurrentMark = Decoration4.mark({
1512
- class: "cm-comment-current",
1513
- attributes: {
1514
- "data-testid": "cm-comment"
1515
- }
1516
- });
1526
+ var createCommentMark = (id, isCurrent) => {
1527
+ return Decoration4.mark({
1528
+ class: isCurrent ? "cm-comment-current" : "cm-comment",
1529
+ attributes: {
1530
+ "data-testid": "cm-comment",
1531
+ "data-comment-id": id
1532
+ }
1533
+ });
1534
+ };
1517
1535
  var commentsDecorations = EditorView7.decorations.compute([
1518
1536
  commentsState
1519
1537
  ], (state2) => {
@@ -1523,7 +1541,7 @@ var commentsDecorations = EditorView7.decorations.compute([
1523
1541
  if (!range) {
1524
1542
  log4.warn("Invalid range:", range, {
1525
1543
  F: __dxlog_file6,
1526
- L: 141,
1544
+ L: 160,
1527
1545
  S: void 0,
1528
1546
  C: (f, a) => f(...a)
1529
1547
  });
@@ -1531,14 +1549,31 @@ var commentsDecorations = EditorView7.decorations.compute([
1531
1549
  } else if (range.from === range.to) {
1532
1550
  return void 0;
1533
1551
  }
1534
- if (comment.comment.id === current) {
1535
- return commentCurrentMark.range(range.from, range.to);
1536
- } else {
1537
- return commentMark.range(range.from, range.to);
1538
- }
1552
+ const mark2 = createCommentMark(comment.comment.id, comment.comment.id === current);
1553
+ return mark2.range(range.from, range.to);
1539
1554
  }).filter(nonNullable);
1540
1555
  return Decoration4.set(decorations);
1541
1556
  });
1557
+ var commentClickedEffect = StateEffect3.define();
1558
+ var handleCommentClick = EditorView7.domEventHandlers({
1559
+ click: (event, view) => {
1560
+ let target = event.target;
1561
+ const editorRoot = view.dom;
1562
+ while (target && target !== editorRoot && !target.hasAttribute("data-comment-id")) {
1563
+ target = target.parentElement;
1564
+ }
1565
+ if (target && target !== editorRoot) {
1566
+ const commentId = target.getAttribute("data-comment-id");
1567
+ if (commentId) {
1568
+ view.dispatch({
1569
+ effects: commentClickedEffect.of(commentId)
1570
+ });
1571
+ return true;
1572
+ }
1573
+ }
1574
+ return false;
1575
+ }
1576
+ });
1542
1577
  var trackPastedComments = (onUpdate) => {
1543
1578
  let tracked = null;
1544
1579
  const handleTrack = (event, view) => {
@@ -1689,6 +1724,7 @@ var comments = (options = {}) => {
1689
1724
  documentId.of(options.id),
1690
1725
  commentsState,
1691
1726
  commentsDecorations,
1727
+ handleCommentClick,
1692
1728
  styles3,
1693
1729
  //
1694
1730
  // Keymap.
@@ -1833,6 +1869,9 @@ var selectionOverlapsComment = (state2) => {
1833
1869
  }
1834
1870
  return false;
1835
1871
  };
1872
+ var hasActiveSelection = (state2) => {
1873
+ return state2.selection.ranges.some((range) => !range.empty);
1874
+ };
1836
1875
  var useComments = (view, id, comments2) => {
1837
1876
  useEffect(() => {
1838
1877
  if (view) {
@@ -1852,17 +1891,37 @@ var useComments = (view, id, comments2) => {
1852
1891
  ]);
1853
1892
  };
1854
1893
  var useCommentState = () => {
1855
- const [comment, setComment] = useState(false);
1894
+ const [state2, setState] = useState({
1895
+ comment: false,
1896
+ selection: false
1897
+ });
1856
1898
  const observer = useMemo(() => EditorView7.updateListener.of((update2) => {
1857
1899
  if (update2.docChanged || update2.selectionSet) {
1858
- setComment(() => selectionOverlapsComment(update2.state));
1900
+ setState({
1901
+ comment: selectionOverlapsComment(update2.state),
1902
+ selection: hasActiveSelection(update2.state)
1903
+ });
1859
1904
  }
1860
1905
  }), []);
1861
1906
  return [
1862
- comment,
1907
+ state2,
1863
1908
  observer
1864
1909
  ];
1865
1910
  };
1911
+ var useCommentClickListener = (onCommentClick) => {
1912
+ const observer = useMemo(() => EditorView7.updateListener.of((update2) => {
1913
+ update2.transactions.forEach((transaction) => {
1914
+ transaction.effects.forEach((effect) => {
1915
+ if (effect.is(commentClickedEffect)) {
1916
+ onCommentClick(effect.value);
1917
+ }
1918
+ });
1919
+ });
1920
+ }), [
1921
+ onCommentClick
1922
+ ]);
1923
+ return observer;
1924
+ };
1866
1925
 
1867
1926
  // packages/ui/react-ui-editor/src/extensions/doc.ts
1868
1927
  import { Facet as Facet5 } from "@codemirror/state";
@@ -4960,7 +5019,7 @@ var MarkdownActions = () => {
4960
5019
  onClick: () => onAction?.({
4961
5020
  type: "comment"
4962
5021
  }),
4963
- disabled: !state2 || state2.comment
5022
+ disabled: !state2 || state2.comment || !state2.selection
4964
5023
  }, t("comment label")));
4965
5024
  };
4966
5025
  var Toolbar = {
@@ -5184,6 +5243,7 @@ export {
5184
5243
  translations_default as translations,
5185
5244
  typewriter,
5186
5245
  useActionHandler,
5246
+ useCommentClickListener,
5187
5247
  useCommentState,
5188
5248
  useComments,
5189
5249
  useFormattingState,