@dxos/react-ui-editor 0.6.1-main.2c1a092 → 0.6.1-main.4211093

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.
@@ -35,7 +35,7 @@ import { TextKind } from "@dxos/protocols/proto/dxos/echo/model/text";
35
35
  import { EditorState as EditorState2 } from "@codemirror/state";
36
36
  import { EditorView as EditorView16 } from "@codemirror/view";
37
37
  import { useFocusableGroup } from "@fluentui/react-tabster";
38
- import React, { forwardRef, useCallback, useEffect as useEffect2, useImperativeHandle, useRef, useState as useState2 } from "react";
38
+ import React, { forwardRef, useCallback, useEffect as useEffect2, useImperativeHandle, useRef, useState as useState3 } from "react";
39
39
  import { log as log7 } from "@dxos/log";
40
40
  import { useDefaultValue } from "@dxos/react-ui";
41
41
  import { isNotFalsy as isNotFalsy4 } from "@dxos/util";
@@ -1350,11 +1350,14 @@ import { invertedEffects } from "@codemirror/commands";
1350
1350
  import { Facet as Facet4, StateEffect as StateEffect3, StateField as StateField4 } from "@codemirror/state";
1351
1351
  import { hoverTooltip, keymap as keymap4, Decoration as Decoration4, EditorView as EditorView7 } from "@codemirror/view";
1352
1352
  import sortBy from "lodash.sortby";
1353
- import { useEffect } from "react";
1353
+ import { useEffect, useMemo, useState } from "react";
1354
1354
  import { debounce } from "@dxos/async";
1355
1355
  import { log as log4 } from "@dxos/log";
1356
1356
  import { nonNullable } from "@dxos/util";
1357
1357
 
1358
+ // packages/ui/react-ui-editor/src/extensions/util/overlap.ts
1359
+ var overlap = (a, b) => a.from <= b.to && a.to >= b.from;
1360
+
1358
1361
  // packages/ui/react-ui-editor/src/styles/markdown.ts
1359
1362
  import { mx } from "@dxos/react-ui-theme";
1360
1363
  var headings = {
@@ -1520,7 +1523,7 @@ var commentsDecorations = EditorView7.decorations.compute([
1520
1523
  if (!range || range.from === range.to) {
1521
1524
  log4.warn("Invalid range:", range, {
1522
1525
  F: __dxlog_file6,
1523
- L: 132,
1526
+ L: 141,
1524
1527
  S: void 0,
1525
1528
  C: (f, a) => f(...a)
1526
1529
  });
@@ -1818,6 +1821,16 @@ var scrollThreadIntoView = (view, id, center = true) => {
1818
1821
  });
1819
1822
  }
1820
1823
  };
1824
+ var selectionOverlapsComment = (state2) => {
1825
+ const { selection } = state2;
1826
+ const commentState = state2.field(commentsState);
1827
+ for (const range of selection.ranges) {
1828
+ if (commentState.comments.some(({ range: commentRange }) => overlap(commentRange, range))) {
1829
+ return true;
1830
+ }
1831
+ }
1832
+ return false;
1833
+ };
1821
1834
  var useComments = (view, id, comments2) => {
1822
1835
  useEffect(() => {
1823
1836
  if (view) {
@@ -1836,6 +1849,18 @@ var useComments = (view, id, comments2) => {
1836
1849
  comments2
1837
1850
  ]);
1838
1851
  };
1852
+ var useCommentState = () => {
1853
+ const [comment, setComment] = useState(false);
1854
+ const observer = useMemo(() => EditorView7.updateListener.of((update2) => {
1855
+ if (update2.docChanged || update2.selectionSet) {
1856
+ setComment(() => selectionOverlapsComment(update2.state));
1857
+ }
1858
+ }), []);
1859
+ return [
1860
+ comment,
1861
+ observer
1862
+ ];
1863
+ };
1839
1864
 
1840
1865
  // packages/ui/react-ui-editor/src/extensions/doc.ts
1841
1866
  import { Facet as Facet5 } from "@codemirror/state";
@@ -2271,7 +2296,7 @@ import { snippet } from "@codemirror/autocomplete";
2271
2296
  import { syntaxTree } from "@codemirror/language";
2272
2297
  import { EditorSelection } from "@codemirror/state";
2273
2298
  import { EditorView as EditorView11, keymap as keymap6 } from "@codemirror/view";
2274
- import { useMemo, useState } from "react";
2299
+ import { useMemo as useMemo2, useState as useState2 } from "react";
2275
2300
  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;
2276
2301
  var Inline;
2277
2302
  (function(Inline2) {
@@ -3360,8 +3385,8 @@ var getFormatting = (state2) => {
3360
3385
  };
3361
3386
  };
3362
3387
  var useFormattingState = () => {
3363
- const [state2, setState] = useState();
3364
- const observer = useMemo(() => EditorView11.updateListener.of((update2) => {
3388
+ const [state2, setState] = useState2();
3389
+ const observer = useMemo2(() => EditorView11.updateListener.of((update2) => {
3365
3390
  if (update2.docChanged || update2.selectionSet) {
3366
3391
  setState((prevState) => {
3367
3392
  const newState = getFormatting(update2.state);
@@ -4515,7 +4540,7 @@ var TextEditor = /* @__PURE__ */ forwardRef(({
4515
4540
  debug,
4516
4541
  dataTestId
4517
4542
  }, forwardedRef) => {
4518
- const [instanceId] = useState2(() => `text-editor-${++instanceCount}`);
4543
+ const [instanceId] = useState3(() => `text-editor-${++instanceCount}`);
4519
4544
  const scrollTo = useDefaultValue(propsScrollTo, EditorView16.scrollIntoView(0, {
4520
4545
  yMargin: 0
4521
4546
  }));
@@ -4523,7 +4548,7 @@ var TextEditor = /* @__PURE__ */ forwardRef(({
4523
4548
  tabBehavior: "limited"
4524
4549
  });
4525
4550
  const rootRef = useRef(null);
4526
- const [view, setView] = useState2(null);
4551
+ const [view, setView] = useState3(null);
4527
4552
  useImperativeHandle(forwardedRef, () => view, [
4528
4553
  view
4529
4554
  ]);
@@ -4638,7 +4663,7 @@ var TextEditor = /* @__PURE__ */ forwardRef(({
4638
4663
  // packages/ui/react-ui-editor/src/components/Toolbar/Toolbar.tsx
4639
4664
  import { ChatText, Code, CodeBlock, Image, Link, ListBullets, ListChecks, ListNumbers, Paragraph, Quotes, TextStrikethrough, Table as Table2, TextB, TextHOne, TextHTwo, TextHThree, TextHFour, TextHFive, TextHSix, TextItalic, CaretDown, Check } from "@phosphor-icons/react";
4640
4665
  import { createContext } from "@radix-ui/react-context";
4641
- import React2, { useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
4666
+ import React2, { useEffect as useEffect3, useRef as useRef2, useState as useState4 } from "react";
4642
4667
  import { useDropzone } from "react-dropzone";
4643
4668
  import { DensityProvider, ElevationProvider, Toolbar as NaturalToolbar, Tooltip, useTranslation, DropdownMenu, Button } from "@dxos/react-ui";
4644
4669
  import { getSize } from "@dxos/react-ui-theme";
@@ -4711,8 +4736,8 @@ var MarkdownHeading = () => {
4711
4736
  const value = header ? header[1] : blockType === "paragraph" || !blockType ? "0" : void 0;
4712
4737
  const HeadingIcon = HeadingIcons[value ?? "0"];
4713
4738
  const suppressNextTooltip = useRef2(false);
4714
- const [tooltipOpen, setTooltipOpen] = useState3(false);
4715
- const [selectOpen, setSelectOpen] = useState3(false);
4739
+ const [tooltipOpen, setTooltipOpen] = useState4(false);
4740
+ const [selectOpen, setSelectOpen] = useState4(false);
4716
4741
  return /* @__PURE__ */ React2.createElement(Tooltip.Root, {
4717
4742
  open: tooltipOpen,
4718
4743
  onOpenChange: (nextOpen) => {
@@ -4924,7 +4949,7 @@ var MarkdownCustom = ({ onUpload } = {}) => {
4924
4949
  }, t("image label")));
4925
4950
  };
4926
4951
  var MarkdownActions = () => {
4927
- const { onAction } = useToolbarContext("MarkdownStyles");
4952
+ const { onAction, state: state2 } = useToolbarContext("MarkdownStyles");
4928
4953
  const { t } = useTranslation(translationKey);
4929
4954
  return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(ToolbarButton, {
4930
4955
  value: "comment",
@@ -4932,7 +4957,8 @@ var MarkdownActions = () => {
4932
4957
  "data-testid": "editor.toolbar.comment",
4933
4958
  onClick: () => onAction?.({
4934
4959
  type: "comment"
4935
- })
4960
+ }),
4961
+ disabled: !state2 || state2.comment
4936
4962
  }, t("comment label")));
4937
4963
  };
4938
4964
  var Toolbar = {
@@ -4953,14 +4979,14 @@ var useActionHandler = (view) => {
4953
4979
  import { EditorSelection as EditorSelection2, EditorState as EditorState3 } from "@codemirror/state";
4954
4980
  import { EditorView as EditorView17 } from "@codemirror/view";
4955
4981
  import { useFocusableGroup as useFocusableGroup2 } from "@fluentui/react-tabster";
4956
- import { useCallback as useCallback2, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef3, useState as useState4 } from "react";
4982
+ import { useCallback as useCallback2, useEffect as useEffect4, useMemo as useMemo3, useRef as useRef3, useState as useState5 } from "react";
4957
4983
  import { log as log8 } from "@dxos/log";
4958
4984
  import { isNotFalsy as isNotFalsy5 } from "@dxos/util";
4959
4985
  var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/useTextEditor.ts";
4960
4986
  var useTextEditor = (cb = () => ({}), deps = []) => {
4961
- let { id, doc, selection, extensions, autoFocus, scrollTo, debug } = useMemo2(cb, deps ?? []);
4987
+ let { id, doc, selection, extensions, autoFocus, scrollTo, debug } = useMemo3(cb, deps ?? []);
4962
4988
  const onUpdate = useRef3();
4963
- const [view, setView] = useState4();
4989
+ const [view, setView] = useState5();
4964
4990
  const parentRef = useRef3(null);
4965
4991
  useEffect4(() => {
4966
4992
  let view2;
@@ -5097,6 +5123,7 @@ export {
5097
5123
  callbackWrapper,
5098
5124
  command,
5099
5125
  comments,
5126
+ commentsState,
5100
5127
  createBasicExtensions,
5101
5128
  createComment,
5102
5129
  createDataExtensions,
@@ -5135,6 +5162,7 @@ export {
5135
5162
  removeList,
5136
5163
  removeStyle,
5137
5164
  scrollThreadIntoView,
5165
+ selectionOverlapsComment,
5138
5166
  setBlockquote,
5139
5167
  setComments,
5140
5168
  setHeading,
@@ -5154,6 +5182,7 @@ export {
5154
5182
  translations_default as translations,
5155
5183
  typewriter,
5156
5184
  useActionHandler,
5185
+ useCommentState,
5157
5186
  useComments,
5158
5187
  useFormattingState,
5159
5188
  useTextEditor,