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

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 as useState2 } from "react";
36
+ import React, { forwardRef, useCallback, useEffect as useEffect2, useImperativeHandle, useRef, useState } from "react";
37
37
  import { log as log9 } from "@dxos/log";
38
38
  import { isNotFalsy as isNotFalsy4 } from "@dxos/util";
39
39
 
@@ -475,13 +475,13 @@ var automerge = (accessor) => {
475
475
  ViewPlugin.fromClass(class {
476
476
  constructor(_view) {
477
477
  this._view = _view;
478
- accessor.handle.addListener("change", this._handleChange.bind(this));
478
+ this._handleChange = () => {
479
+ syncer.reconcile(this._view, false);
480
+ };
481
+ accessor.handle.addListener("change", this._handleChange);
479
482
  }
480
483
  destroy() {
481
- accessor.handle.removeListener("change", this._handleChange.bind(this));
482
- }
483
- _handleChange() {
484
- syncer.reconcile(this._view, false);
484
+ accessor.handle.removeListener("change", this._handleChange);
485
485
  }
486
486
  }),
487
487
  // Reconcile local updates.
@@ -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,8 +2797,9 @@ 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 { 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;
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;
2802
2803
  var Inline;
2803
2804
  (function(Inline2) {
2804
2805
  Inline2[Inline2["Strong"] = 0] = "Strong";
@@ -3865,11 +3866,11 @@ var getFormatting = (state2) => {
3865
3866
  };
3866
3867
  };
3867
3868
  var useFormattingState = () => {
3868
- const [state2, setState] = useState(null);
3869
+ const [state2, setState, stateRef] = useStateRef();
3869
3870
  const observer = useMemo(() => EditorView13.updateListener.of((update2) => {
3870
3871
  if (update2.docChanged || update2.selectionSet) {
3871
3872
  const newState = getFormatting(update2.state);
3872
- if (!state2 || !compareFormatting(state2, newState)) {
3873
+ if (!stateRef.current || !formattingEquals(stateRef.current, newState)) {
3873
3874
  setState(newState);
3874
3875
  }
3875
3876
  }
@@ -4315,12 +4316,12 @@ var instanceCount = 0;
4315
4316
  var TextEditor = /* @__PURE__ */ forwardRef(({ id, doc, selection, extensions, className, autoFocus, scrollTo = EditorView17.scrollIntoView(0, {
4316
4317
  yMargin: 0
4317
4318
  }), moveToEndOfLine, debug, dataTestId }, forwardedRef) => {
4318
- const [instanceId] = useState2(() => `text-editor-${++instanceCount}`);
4319
+ const [instanceId] = useState(() => `text-editor-${++instanceCount}`);
4319
4320
  const tabsterDOMAttribute = useFocusableGroup({
4320
4321
  tabBehavior: "limited"
4321
4322
  });
4322
4323
  const rootRef = useRef(null);
4323
- const [view, setView] = useState2(null);
4324
+ const [view, setView] = useState(null);
4324
4325
  useImperativeHandle(forwardedRef, () => view, [
4325
4326
  view
4326
4327
  ]);
@@ -4333,7 +4334,7 @@ var TextEditor = /* @__PURE__ */ forwardRef(({ id, doc, selection, extensions, c
4333
4334
  autoFocus
4334
4335
  ]);
4335
4336
  useEffect2(() => {
4336
- log9("updating", {
4337
+ log9("create", {
4337
4338
  id,
4338
4339
  instanceId
4339
4340
  }, {
@@ -4393,8 +4394,16 @@ var TextEditor = /* @__PURE__ */ forwardRef(({ id, doc, selection, extensions, c
4393
4394
  }
4394
4395
  setView(view2);
4395
4396
  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
+ });
4396
4406
  view2?.destroy();
4397
- setView(null);
4398
4407
  };
4399
4408
  }, [
4400
4409
  doc,
@@ -4424,9 +4433,9 @@ var TextEditor = /* @__PURE__ */ forwardRef(({ id, doc, selection, extensions, c
4424
4433
  });
4425
4434
 
4426
4435
  // packages/ui/react-ui-editor/src/components/Toolbar/Toolbar.tsx
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";
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";
4428
4437
  import { createContext } from "@radix-ui/react-context";
4429
- import React2, { useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
4438
+ import React2, { useEffect as useEffect3, useRef as useRef2, useState as useState2 } from "react";
4430
4439
  import { useDropzone } from "react-dropzone";
4431
4440
  import { DensityProvider, ElevationProvider, Select, Toolbar as NaturalToolbar, Tooltip, useTranslation } from "@dxos/react-ui";
4432
4441
  import { getSize } from "@dxos/react-ui-theme";
@@ -4499,8 +4508,8 @@ var MarkdownHeading = () => {
4499
4508
  const value = header ? header[1] : blockType === "paragraph" || !blockType ? "0" : void 0;
4500
4509
  const HeadingIcon = HeadingIcons[value ?? "0"];
4501
4510
  const suppressNextTooltip = useRef2(false);
4502
- const [tooltipOpen, setTooltipOpen] = useState3(false);
4503
- const [selectOpen, setSelectOpen] = useState3(false);
4511
+ const [tooltipOpen, setTooltipOpen] = useState2(false);
4512
+ const [selectOpen, setSelectOpen] = useState2(false);
4504
4513
  return /* @__PURE__ */ React2.createElement(Tooltip.Root, {
4505
4514
  open: tooltipOpen,
4506
4515
  onOpenChange: (nextOpen) => {
@@ -4724,13 +4733,14 @@ var MarkdownCustom = ({ onUpload } = {}) => {
4724
4733
  var MarkdownActions = () => {
4725
4734
  const { onAction } = useToolbarContext("MarkdownStyles");
4726
4735
  const { t } = useTranslation(translationKey);
4727
- return /* @__PURE__ */ React2.createElement(ToolbarButton, {
4736
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(ToolbarButton, {
4728
4737
  value: "comment",
4729
4738
  Icon: ChatText,
4739
+ "data-testid": "editor.toolbar.comment",
4730
4740
  onClick: () => onAction?.({
4731
4741
  type: "comment"
4732
4742
  })
4733
- }, t("comment label"));
4743
+ }, t("comment label")));
4734
4744
  };
4735
4745
  var Toolbar = {
4736
4746
  Root: ToolbarRoot,
@@ -4811,18 +4821,26 @@ var useDocAccessor = (text) => {
4811
4821
  // packages/ui/react-ui-editor/src/hooks/useTextEditor.ts
4812
4822
  import { EditorSelection as EditorSelection2, EditorState as EditorState3 } from "@codemirror/state";
4813
4823
  import { EditorView as EditorView18 } from "@codemirror/view";
4814
- import { useEffect as useEffect4, useMemo as useMemo3, useRef as useRef3, useState as useState4 } from "react";
4824
+ import { useEffect as useEffect4, useMemo as useMemo3, useRef as useRef3, useState as useState3 } from "react";
4815
4825
  import { log as log10 } from "@dxos/log";
4816
4826
  import { isNotFalsy as isNotFalsy5 } from "@dxos/util";
4817
4827
  var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/useTextEditor.ts";
4818
4828
  var useTextEditor = (cb = () => ({}), deps = []) => {
4819
4829
  let { id, doc, selection, extensions, autoFocus, scrollTo, debug } = useMemo3(cb, deps ?? []);
4820
4830
  const onUpdate = useRef3();
4821
- const [view, setView] = useState4();
4831
+ const [view, setView] = useState3();
4822
4832
  const parentRef = useRef3(null);
4823
4833
  useEffect4(() => {
4824
4834
  let view2;
4825
4835
  if (parentRef.current) {
4836
+ log10("create", {
4837
+ id
4838
+ }, {
4839
+ F: __dxlog_file13,
4840
+ L: 36,
4841
+ S: void 0,
4842
+ C: (f, a) => f(...a)
4843
+ });
4826
4844
  const state2 = EditorState3.create({
4827
4845
  doc,
4828
4846
  selection,
@@ -4832,7 +4850,7 @@ var useTextEditor = (cb = () => ({}), deps = []) => {
4832
4850
  EditorView18.exceptionSink.of((err) => {
4833
4851
  log10.catch(err, void 0, {
4834
4852
  F: __dxlog_file13,
4835
- L: 44,
4853
+ L: 46,
4836
4854
  S: void 0,
4837
4855
  C: (f, a) => f(...a)
4838
4856
  });
@@ -4859,6 +4877,14 @@ var useTextEditor = (cb = () => ({}), deps = []) => {
4859
4877
  setView(view2);
4860
4878
  }
4861
4879
  return () => {
4880
+ log10("destroy", {
4881
+ id
4882
+ }, {
4883
+ F: __dxlog_file13,
4884
+ L: 74,
4885
+ S: void 0,
4886
+ C: (f, a) => f(...a)
4887
+ });
4862
4888
  view2?.destroy();
4863
4889
  };
4864
4890
  }, deps);
@@ -4921,7 +4947,6 @@ export {
4921
4947
  callbackWrapper,
4922
4948
  command,
4923
4949
  comments,
4924
- compareFormatting,
4925
4950
  createBasicExtensions,
4926
4951
  createComment,
4927
4952
  createDataExtensions,
@@ -4939,6 +4964,7 @@ export {
4939
4964
  editorWithToolbarLayout,
4940
4965
  focusComment,
4941
4966
  focusEvent,
4967
+ formattingEquals,
4942
4968
  formattingKeymap,
4943
4969
  getFormatting,
4944
4970
  getToken,