@dxos/react-ui-editor 0.6.2 → 0.6.3-main.0308ae2

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";
@@ -1539,7 +1539,7 @@ var commentsDecorations = EditorView7.decorations.compute([
1539
1539
  if (!range) {
1540
1540
  log4.warn("Invalid range:", range, {
1541
1541
  F: __dxlog_file6,
1542
- L: 159,
1542
+ L: 169,
1543
1543
  S: void 0,
1544
1544
  C: (f, a) => f(...a)
1545
1545
  });
@@ -1876,24 +1876,34 @@ var selectionOverlapsComment = (state2) => {
1876
1876
  var hasActiveSelection = (state2) => {
1877
1877
  return state2.selection.ranges.some((range) => !range.empty);
1878
1878
  };
1879
- var useComments = (view, id, comments2) => {
1880
- useEffect(() => {
1881
- if (view) {
1879
+ var ExternalCommentSync = class {
1880
+ constructor(view, id, subscribe, getThreads) {
1881
+ this.destroy = () => {
1882
+ this.unsubscribe();
1883
+ };
1884
+ const updateComments = () => {
1885
+ const threads = getThreads();
1886
+ const comments2 = threads.filter(nonNullable).filter((thread) => thread.anchor).map((thread) => ({
1887
+ id: thread.id,
1888
+ cursor: thread.anchor
1889
+ }));
1882
1890
  if (id === view.state.facet(documentId)) {
1883
- view.dispatch({
1891
+ queueMicrotask(() => view.dispatch({
1884
1892
  effects: setComments.of({
1885
1893
  id,
1886
- comments: comments2 ?? []
1894
+ comments: comments2
1887
1895
  })
1888
- });
1896
+ }));
1889
1897
  }
1890
- }
1891
- }, [
1892
- id,
1893
- view,
1894
- comments2
1895
- ]);
1898
+ };
1899
+ this.unsubscribe = subscribe(updateComments);
1900
+ }
1896
1901
  };
1902
+ var createExternalCommentSync = (id, subscribe, getThreads) => ViewPlugin4.fromClass(class {
1903
+ constructor(view) {
1904
+ return new ExternalCommentSync(view, id, subscribe, getThreads);
1905
+ }
1906
+ });
1897
1907
  var useCommentState = () => {
1898
1908
  const [state2, setState] = useState({
1899
1909
  comment: false,
@@ -1912,6 +1922,20 @@ var useCommentState = () => {
1912
1922
  observer
1913
1923
  ];
1914
1924
  };
1925
+ var useComments = (view, id, comments2) => {
1926
+ useEffect(() => {
1927
+ if (view) {
1928
+ if (id === view.state.facet(documentId)) {
1929
+ view.dispatch({
1930
+ effects: setComments.of({
1931
+ id,
1932
+ comments: comments2 ?? []
1933
+ })
1934
+ });
1935
+ }
1936
+ }
1937
+ });
1938
+ };
1915
1939
  var useCommentClickListener = (onCommentClick) => {
1916
1940
  const observer = useMemo(() => EditorView7.updateListener.of((update2) => {
1917
1941
  update2.transactions.forEach((transaction) => {
@@ -3713,7 +3737,7 @@ var markdownHighlightStyle = (readonly) => {
3713
3737
  // packages/ui/react-ui-editor/src/extensions/markdown/linkPaste.ts
3714
3738
  import { syntaxTree as syntaxTree2 } from "@codemirror/language";
3715
3739
  import { Transaction } from "@codemirror/state";
3716
- import { ViewPlugin as ViewPlugin4 } from "@codemirror/view";
3740
+ import { ViewPlugin as ViewPlugin5 } from "@codemirror/view";
3717
3741
  var VALID_PROTOCOLS = [
3718
3742
  "http:",
3719
3743
  "https:",
@@ -3750,7 +3774,7 @@ var isValidUrl = (str) => {
3750
3774
  }
3751
3775
  };
3752
3776
  var onNextUpdate = (callback) => setTimeout(callback, 0);
3753
- var linkPastePlugin = ViewPlugin4.fromClass(class {
3777
+ var linkPastePlugin = ViewPlugin5.fromClass(class {
3754
3778
  constructor(view) {
3755
3779
  this.view = view;
3756
3780
  }
@@ -3845,7 +3869,7 @@ var createMarkdownExtensions = ({ themeMode } = {}) => {
3845
3869
  // packages/ui/react-ui-editor/src/extensions/markdown/decorate.ts
3846
3870
  import { syntaxTree as syntaxTree3 } from "@codemirror/language";
3847
3871
  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";
3872
+ import { EditorView as EditorView12, Decoration as Decoration5, WidgetType as WidgetType3, ViewPlugin as ViewPlugin6 } from "@codemirror/view";
3849
3873
  import { mx as mx2 } from "@dxos/react-ui-theme";
3850
3874
  var HorizontalRuleWidget = class extends WidgetType3 {
3851
3875
  toDOM() {
@@ -4061,7 +4085,7 @@ var buildDecorations = (view, options, focus) => {
4061
4085
  var forceUpdate = StateEffect4.define();
4062
4086
  var decorateMarkdown = (options = {}) => {
4063
4087
  return [
4064
- ViewPlugin5.fromClass(class {
4088
+ ViewPlugin6.fromClass(class {
4065
4089
  constructor(view) {
4066
4090
  ({ deco: this.deco, atomicDeco: this.atomicDeco } = buildDecorations(view, options, view.hasFocus));
4067
4091
  }
@@ -5192,6 +5216,7 @@ export {
5192
5216
  createBasicExtensions,
5193
5217
  createComment,
5194
5218
  createDataExtensions,
5219
+ createExternalCommentSync,
5195
5220
  createMarkdownExtensions,
5196
5221
  createThemeExtensions,
5197
5222
  decorateMarkdown,