@dxos/react-ui-editor 0.4.8-main.aa7abac → 0.4.8-main.beadd4b

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.
@@ -33,7 +33,7 @@ import { Doc, YText, YXmlFragment } from "@dxos/text-model";
33
33
  import { EditorState as EditorState2 } from "@codemirror/state";
34
34
  import { EditorView as EditorView17 } from "@codemirror/view";
35
35
  import { useFocusableGroup } from "@fluentui/react-tabster";
36
- import React, { forwardRef, useCallback, useEffect as useEffect2, useImperativeHandle, useRef, useState } from "react";
36
+ import React, { forwardRef, useCallback, useEffect as useEffect2, useImperativeHandle, useRef, useState as useState2 } from "react";
37
37
  import { log as log9 } from "@dxos/log";
38
38
  import { isNotFalsy as isNotFalsy4 } from "@dxos/util";
39
39
 
@@ -1832,14 +1832,14 @@ var focusComment = (view, id, center = true) => {
1832
1832
  });
1833
1833
  }
1834
1834
  };
1835
- var useComments = (view, id, comments2) => {
1835
+ var useComments = (view, id, comments2 = []) => {
1836
1836
  useEffect(() => {
1837
1837
  if (view) {
1838
1838
  if (id === view.state.facet(documentId)) {
1839
1839
  view.dispatch({
1840
1840
  effects: setComments.of({
1841
1841
  id,
1842
- comments: comments2 ?? []
1842
+ comments: comments2
1843
1843
  })
1844
1844
  });
1845
1845
  }
@@ -2797,9 +2797,8 @@ import { snippet } from "@codemirror/autocomplete";
2797
2797
  import { syntaxTree as syntaxTree2 } from "@codemirror/language";
2798
2798
  import { EditorSelection } from "@codemirror/state";
2799
2799
  import { EditorView as EditorView13, keymap as keymap6 } from "@codemirror/view";
2800
- import { useMemo } from "react";
2801
- import { useStateRef } from "@dxos/react-async";
2802
- 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;
2800
+ import { useState, useMemo } from "react";
2801
+ var compareFormatting = (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;
2803
2802
  var Inline;
2804
2803
  (function(Inline2) {
2805
2804
  Inline2[Inline2["Strong"] = 0] = "Strong";
@@ -3866,11 +3865,11 @@ var getFormatting = (state2) => {
3866
3865
  };
3867
3866
  };
3868
3867
  var useFormattingState = () => {
3869
- const [state2, setState, stateRef] = useStateRef();
3868
+ const [state2, setState] = useState(null);
3870
3869
  const observer = useMemo(() => EditorView13.updateListener.of((update2) => {
3871
3870
  if (update2.docChanged || update2.selectionSet) {
3872
3871
  const newState = getFormatting(update2.state);
3873
- if (!stateRef.current || !formattingEquals(stateRef.current, newState)) {
3872
+ if (!state2 || !compareFormatting(state2, newState)) {
3874
3873
  setState(newState);
3875
3874
  }
3876
3875
  }
@@ -4316,12 +4315,12 @@ var instanceCount = 0;
4316
4315
  var TextEditor = /* @__PURE__ */ forwardRef(({ id, doc, selection, extensions, className, autoFocus, scrollTo = EditorView17.scrollIntoView(0, {
4317
4316
  yMargin: 0
4318
4317
  }), moveToEndOfLine, debug, dataTestId }, forwardedRef) => {
4319
- const [instanceId] = useState(() => `text-editor-${++instanceCount}`);
4318
+ const [instanceId] = useState2(() => `text-editor-${++instanceCount}`);
4320
4319
  const tabsterDOMAttribute = useFocusableGroup({
4321
4320
  tabBehavior: "limited"
4322
4321
  });
4323
4322
  const rootRef = useRef(null);
4324
- const [view, setView] = useState(null);
4323
+ const [view, setView] = useState2(null);
4325
4324
  useImperativeHandle(forwardedRef, () => view, [
4326
4325
  view
4327
4326
  ]);
@@ -4334,7 +4333,7 @@ var TextEditor = /* @__PURE__ */ forwardRef(({ id, doc, selection, extensions, c
4334
4333
  autoFocus
4335
4334
  ]);
4336
4335
  useEffect2(() => {
4337
- log9("create", {
4336
+ log9("updating", {
4338
4337
  id,
4339
4338
  instanceId
4340
4339
  }, {
@@ -4394,16 +4393,8 @@ var TextEditor = /* @__PURE__ */ forwardRef(({ id, doc, selection, extensions, c
4394
4393
  }
4395
4394
  setView(view2);
4396
4395
  return () => {
4397
- log9("destroy", {
4398
- id,
4399
- instanceId
4400
- }, {
4401
- F: __dxlog_file12,
4402
- L: 150,
4403
- S: void 0,
4404
- C: (f, a) => f(...a)
4405
- });
4406
4396
  view2?.destroy();
4397
+ setView(null);
4407
4398
  };
4408
4399
  }, [
4409
4400
  doc,
@@ -4433,9 +4424,9 @@ var TextEditor = /* @__PURE__ */ forwardRef(({ id, doc, selection, extensions, c
4433
4424
  });
4434
4425
 
4435
4426
  // packages/ui/react-ui-editor/src/components/Toolbar/Toolbar.tsx
4436
- import { ChatText, Code, CodeBlock, Image, Link, ListBullets, ListChecks, ListNumbers, Paragraph, Quotes, TextStrikethrough, Table as Table2, TextB, TextHOne, TextHTwo, TextHThree, TextHFour, TextHFive, TextHSix, TextItalic } from "@phosphor-icons/react";
4427
+ import { ChatText, Code, CodeBlock, Image, Link, ListBullets, ListChecks, ListNumbers, Paragraph, TextStrikethrough, Table as Table2, TextB, TextHOne, TextHTwo, TextHThree, TextHFour, TextHFive, TextHSix, TextItalic, Quotes } from "@phosphor-icons/react";
4437
4428
  import { createContext } from "@radix-ui/react-context";
4438
- import React2, { useEffect as useEffect3, useRef as useRef2, useState as useState2 } from "react";
4429
+ import React2, { useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
4439
4430
  import { useDropzone } from "react-dropzone";
4440
4431
  import { DensityProvider, ElevationProvider, Select, Toolbar as NaturalToolbar, Tooltip, useTranslation } from "@dxos/react-ui";
4441
4432
  import { getSize } from "@dxos/react-ui-theme";
@@ -4508,8 +4499,8 @@ var MarkdownHeading = () => {
4508
4499
  const value = header ? header[1] : blockType === "paragraph" || !blockType ? "0" : void 0;
4509
4500
  const HeadingIcon = HeadingIcons[value ?? "0"];
4510
4501
  const suppressNextTooltip = useRef2(false);
4511
- const [tooltipOpen, setTooltipOpen] = useState2(false);
4512
- const [selectOpen, setSelectOpen] = useState2(false);
4502
+ const [tooltipOpen, setTooltipOpen] = useState3(false);
4503
+ const [selectOpen, setSelectOpen] = useState3(false);
4513
4504
  return /* @__PURE__ */ React2.createElement(Tooltip.Root, {
4514
4505
  open: tooltipOpen,
4515
4506
  onOpenChange: (nextOpen) => {
@@ -4733,13 +4724,13 @@ var MarkdownCustom = ({ onUpload } = {}) => {
4733
4724
  var MarkdownActions = () => {
4734
4725
  const { onAction } = useToolbarContext("MarkdownStyles");
4735
4726
  const { t } = useTranslation(translationKey);
4736
- return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(ToolbarButton, {
4727
+ return /* @__PURE__ */ React2.createElement(ToolbarButton, {
4737
4728
  value: "comment",
4738
4729
  Icon: ChatText,
4739
4730
  onClick: () => onAction?.({
4740
4731
  type: "comment"
4741
4732
  })
4742
- }, t("comment label")));
4733
+ }, t("comment label"));
4743
4734
  };
4744
4735
  var Toolbar = {
4745
4736
  Root: ToolbarRoot,
@@ -4820,26 +4811,18 @@ var useDocAccessor = (text) => {
4820
4811
  // packages/ui/react-ui-editor/src/hooks/useTextEditor.ts
4821
4812
  import { EditorSelection as EditorSelection2, EditorState as EditorState3 } from "@codemirror/state";
4822
4813
  import { EditorView as EditorView18 } from "@codemirror/view";
4823
- import { useEffect as useEffect4, useMemo as useMemo3, useRef as useRef3, useState as useState3 } from "react";
4814
+ import { useEffect as useEffect4, useMemo as useMemo3, useRef as useRef3, useState as useState4 } from "react";
4824
4815
  import { log as log10 } from "@dxos/log";
4825
4816
  import { isNotFalsy as isNotFalsy5 } from "@dxos/util";
4826
4817
  var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/useTextEditor.ts";
4827
4818
  var useTextEditor = (cb = () => ({}), deps = []) => {
4828
4819
  let { id, doc, selection, extensions, autoFocus, scrollTo, debug } = useMemo3(cb, deps ?? []);
4829
4820
  const onUpdate = useRef3();
4830
- const [view, setView] = useState3();
4821
+ const [view, setView] = useState4();
4831
4822
  const parentRef = useRef3(null);
4832
4823
  useEffect4(() => {
4833
4824
  let view2;
4834
4825
  if (parentRef.current) {
4835
- log10("create", {
4836
- id
4837
- }, {
4838
- F: __dxlog_file13,
4839
- L: 36,
4840
- S: void 0,
4841
- C: (f, a) => f(...a)
4842
- });
4843
4826
  const state2 = EditorState3.create({
4844
4827
  doc,
4845
4828
  selection,
@@ -4849,7 +4832,7 @@ var useTextEditor = (cb = () => ({}), deps = []) => {
4849
4832
  EditorView18.exceptionSink.of((err) => {
4850
4833
  log10.catch(err, void 0, {
4851
4834
  F: __dxlog_file13,
4852
- L: 46,
4835
+ L: 44,
4853
4836
  S: void 0,
4854
4837
  C: (f, a) => f(...a)
4855
4838
  });
@@ -4876,14 +4859,6 @@ var useTextEditor = (cb = () => ({}), deps = []) => {
4876
4859
  setView(view2);
4877
4860
  }
4878
4861
  return () => {
4879
- log10("destroy", {
4880
- id
4881
- }, {
4882
- F: __dxlog_file13,
4883
- L: 74,
4884
- S: void 0,
4885
- C: (f, a) => f(...a)
4886
- });
4887
4862
  view2?.destroy();
4888
4863
  };
4889
4864
  }, deps);
@@ -4946,6 +4921,7 @@ export {
4946
4921
  callbackWrapper,
4947
4922
  command,
4948
4923
  comments,
4924
+ compareFormatting,
4949
4925
  createBasicExtensions,
4950
4926
  createComment,
4951
4927
  createDataExtensions,
@@ -4963,7 +4939,6 @@ export {
4963
4939
  editorWithToolbarLayout,
4964
4940
  focusComment,
4965
4941
  focusEvent,
4966
- formattingEquals,
4967
4942
  formattingKeymap,
4968
4943
  getFormatting,
4969
4944
  getToken,