@dxos/react-ui-editor 0.6.3-next.2f65b78 → 0.6.3-staging.0f23fb2

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.
@@ -1348,7 +1348,7 @@ var command = (options) => {
1348
1348
  // packages/ui/react-ui-editor/src/extensions/comments.ts
1349
1349
  import { invertedEffects } from "@codemirror/commands";
1350
1350
  import { Facet as Facet4, StateEffect as StateEffect3, StateField as StateField4 } from "@codemirror/state";
1351
- import { hoverTooltip, keymap as keymap4, Decoration as Decoration4, EditorView as EditorView7 } from "@codemirror/view";
1351
+ import { hoverTooltip, keymap as keymap4, Decoration as Decoration4, EditorView as EditorView7, ViewPlugin as ViewPlugin4 } from "@codemirror/view";
1352
1352
  import sortBy from "lodash.sortby";
1353
1353
  import { useEffect, useMemo, useState } from "react";
1354
1354
  import { debounce } from "@dxos/async";
@@ -1488,39 +1488,42 @@ var styles3 = EditorView7.baseTheme({
1488
1488
  borderRadius: "2px",
1489
1489
  transition: "background-color 0.1s ease"
1490
1490
  },
1491
- "&light .cm-comment, &light .cm-comment-current": {
1491
+ // Light theme.
1492
+ "&light .cm-comment": {
1493
+ backgroundColor: getToken("extend.colors.yellow.50"),
1492
1494
  mixBlendMode: "darken",
1493
1495
  borderColor: getToken("extend.colors.yellow.100")
1494
1496
  },
1495
- "&dark .cm-comment, &dark .cm-comment-current": {
1496
- mixBlendMode: "plus-lighter",
1497
- borderColor: getToken("extend.colors.yellow.900")
1498
- },
1499
- "&light .cm-comment": {
1500
- backgroundColor: getToken("extend.colors.yellow.50")
1501
- },
1502
1497
  "&light .cm-comment:hover": {
1503
1498
  backgroundColor: getToken("extend.colors.yellow.100")
1504
1499
  },
1505
1500
  "&light .cm-comment-current": {
1506
- backgroundColor: getToken("extend.colors.yellow.100")
1501
+ backgroundColor: getToken("extend.colors.primary.100"),
1502
+ borderColor: getToken("extend.colors.primary.200")
1507
1503
  },
1508
1504
  "&light .cm-comment-current:hover": {
1509
- backgroundColor: getToken("extend.colors.yellow.150")
1505
+ backgroundColor: getToken("extend.colors.primary.150"),
1506
+ borderColor: getToken("extend.colors.primary.250")
1510
1507
  },
1508
+ // Dark theme.
1511
1509
  "&dark .cm-comment": {
1512
1510
  color: getToken("extend.colors.yellow.50"),
1513
- backgroundColor: getToken("extend.colors.yellow.900")
1511
+ backgroundColor: getToken("extend.colors.yellow.800"),
1512
+ borderColor: getToken("extend.colors.yellow.700"),
1513
+ mixBlendMode: "plus-lighter"
1514
1514
  },
1515
1515
  "&dark .cm-comment:hover": {
1516
- backgroundColor: getToken("extend.colors.yellow.800")
1516
+ backgroundColor: getToken("extend.colors.yellow.700"),
1517
+ borderColor: getToken("extend.colors.yellow.650")
1517
1518
  },
1518
1519
  "&dark .cm-comment-current": {
1519
- color: getToken("extend.colors.yellow.100"),
1520
- backgroundColor: getToken("extend.colors.yellow.950")
1520
+ color: getToken("extend.colors.primary.50"),
1521
+ backgroundColor: getToken("extend.colors.primary.800"),
1522
+ borderColor: getToken("extend.colors.primary.700")
1521
1523
  },
1522
1524
  "&dark .cm-comment-current:hover": {
1523
- backgroundColor: getToken("extend.colors.yellow.900")
1525
+ backgroundColor: getToken("extend.colors.primary.700"),
1526
+ borderColor: getToken("extend.colors.primary.650")
1524
1527
  }
1525
1528
  });
1526
1529
  var createCommentMark = (id, isCurrent) => Decoration4.mark({
@@ -1539,7 +1542,7 @@ var commentsDecorations = EditorView7.decorations.compute([
1539
1542
  if (!range) {
1540
1543
  log4.warn("Invalid range:", range, {
1541
1544
  F: __dxlog_file6,
1542
- L: 159,
1545
+ L: 181,
1543
1546
  S: void 0,
1544
1547
  C: (f, a) => f(...a)
1545
1548
  });
@@ -1876,24 +1879,34 @@ var selectionOverlapsComment = (state2) => {
1876
1879
  var hasActiveSelection = (state2) => {
1877
1880
  return state2.selection.ranges.some((range) => !range.empty);
1878
1881
  };
1879
- var useComments = (view, id, comments2) => {
1880
- useEffect(() => {
1881
- if (view) {
1882
+ var ExternalCommentSync = class {
1883
+ constructor(view, id, subscribe, getThreads) {
1884
+ this.destroy = () => {
1885
+ this.unsubscribe();
1886
+ };
1887
+ const updateComments = () => {
1888
+ const threads = getThreads();
1889
+ const comments2 = threads.filter(nonNullable).filter((thread) => thread.anchor).map((thread) => ({
1890
+ id: thread.id,
1891
+ cursor: thread.anchor
1892
+ }));
1882
1893
  if (id === view.state.facet(documentId)) {
1883
- view.dispatch({
1894
+ queueMicrotask(() => view.dispatch({
1884
1895
  effects: setComments.of({
1885
1896
  id,
1886
- comments: comments2 ?? []
1897
+ comments: comments2
1887
1898
  })
1888
- });
1899
+ }));
1889
1900
  }
1890
- }
1891
- }, [
1892
- id,
1893
- view,
1894
- comments2
1895
- ]);
1901
+ };
1902
+ this.unsubscribe = subscribe(updateComments);
1903
+ }
1896
1904
  };
1905
+ var createExternalCommentSync = (id, subscribe, getThreads) => ViewPlugin4.fromClass(class {
1906
+ constructor(view) {
1907
+ return new ExternalCommentSync(view, id, subscribe, getThreads);
1908
+ }
1909
+ });
1897
1910
  var useCommentState = () => {
1898
1911
  const [state2, setState] = useState({
1899
1912
  comment: false,
@@ -1912,6 +1925,20 @@ var useCommentState = () => {
1912
1925
  observer
1913
1926
  ];
1914
1927
  };
1928
+ var useComments = (view, id, comments2) => {
1929
+ useEffect(() => {
1930
+ if (view) {
1931
+ if (id === view.state.facet(documentId)) {
1932
+ view.dispatch({
1933
+ effects: setComments.of({
1934
+ id,
1935
+ comments: comments2 ?? []
1936
+ })
1937
+ });
1938
+ }
1939
+ }
1940
+ });
1941
+ };
1915
1942
  var useCommentClickListener = (onCommentClick) => {
1916
1943
  const observer = useMemo(() => EditorView7.updateListener.of((update2) => {
1917
1944
  update2.transactions.forEach((transaction) => {
@@ -3713,7 +3740,7 @@ var markdownHighlightStyle = (readonly) => {
3713
3740
  // packages/ui/react-ui-editor/src/extensions/markdown/linkPaste.ts
3714
3741
  import { syntaxTree as syntaxTree2 } from "@codemirror/language";
3715
3742
  import { Transaction } from "@codemirror/state";
3716
- import { ViewPlugin as ViewPlugin4 } from "@codemirror/view";
3743
+ import { ViewPlugin as ViewPlugin5 } from "@codemirror/view";
3717
3744
  var VALID_PROTOCOLS = [
3718
3745
  "http:",
3719
3746
  "https:",
@@ -3750,7 +3777,7 @@ var isValidUrl = (str) => {
3750
3777
  }
3751
3778
  };
3752
3779
  var onNextUpdate = (callback) => setTimeout(callback, 0);
3753
- var linkPastePlugin = ViewPlugin4.fromClass(class {
3780
+ var linkPastePlugin = ViewPlugin5.fromClass(class {
3754
3781
  constructor(view) {
3755
3782
  this.view = view;
3756
3783
  }
@@ -3845,7 +3872,7 @@ var createMarkdownExtensions = ({ themeMode } = {}) => {
3845
3872
  // packages/ui/react-ui-editor/src/extensions/markdown/decorate.ts
3846
3873
  import { syntaxTree as syntaxTree3 } from "@codemirror/language";
3847
3874
  import { RangeSetBuilder as RangeSetBuilder2, StateEffect as StateEffect4 } from "@codemirror/state";
3848
- import { EditorView as EditorView12, Decoration as Decoration5, WidgetType as WidgetType3, ViewPlugin as ViewPlugin5 } from "@codemirror/view";
3875
+ import { EditorView as EditorView12, Decoration as Decoration5, WidgetType as WidgetType3, ViewPlugin as ViewPlugin6 } from "@codemirror/view";
3849
3876
  import { mx as mx2 } from "@dxos/react-ui-theme";
3850
3877
  var HorizontalRuleWidget = class extends WidgetType3 {
3851
3878
  toDOM() {
@@ -4061,7 +4088,7 @@ var buildDecorations = (view, options, focus) => {
4061
4088
  var forceUpdate = StateEffect4.define();
4062
4089
  var decorateMarkdown = (options = {}) => {
4063
4090
  return [
4064
- ViewPlugin5.fromClass(class {
4091
+ ViewPlugin6.fromClass(class {
4065
4092
  constructor(view) {
4066
4093
  ({ deco: this.deco, atomicDeco: this.atomicDeco } = buildDecorations(view, options, view.hasFocus));
4067
4094
  }
@@ -5192,6 +5219,7 @@ export {
5192
5219
  createBasicExtensions,
5193
5220
  createComment,
5194
5221
  createDataExtensions,
5222
+ createExternalCommentSync,
5195
5223
  createMarkdownExtensions,
5196
5224
  createThemeExtensions,
5197
5225
  decorateMarkdown,