@cyberyozh/text-editor 0.1.4 → 0.1.6

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.
package/dist/editor.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/editor/editor.tsx
2
- import { useState as useState12 } from "react";
2
+ import { useState as useState12, useEffect as useEffect9 } from "react";
3
3
  import { NodeSelection } from "@tiptap/pm/state";
4
4
  import { Slice } from "@tiptap/pm/model";
5
5
  import { useEditor, EditorContent } from "@tiptap/react";
@@ -5958,6 +5958,7 @@ function TiptapContent({
5958
5958
  handleChange,
5959
5959
  imageHandlers,
5960
5960
  isEditable = true,
5961
+ isDisabled = false,
5961
5962
  lang,
5962
5963
  error
5963
5964
  }) {
@@ -5976,11 +5977,11 @@ function TiptapContent({
5976
5977
  }
5977
5978
  const editor = useEditor(
5978
5979
  {
5979
- editable: isEditable,
5980
+ editable: isEditable && !isDisabled,
5980
5981
  extensions: getEditorExtensions({
5981
5982
  translations: translations2,
5982
5983
  suggestion: createSuggestions(translations2, !!imageHandlers),
5983
- isEditable,
5984
+ isEditable: isEditable && !isDisabled,
5984
5985
  getImageById: imageHandlers?.getImage,
5985
5986
  onKatexClick: (latex, pos) => {
5986
5987
  setKatexDialogContext({ latex, pos });
@@ -6029,6 +6030,12 @@ function TiptapContent({
6029
6030
  const katexHandler = createHandleKatexAdd(editor, handleCloseDialog);
6030
6031
  katexHandler(latex, katexDialogContext?.pos);
6031
6032
  };
6033
+ useEffect9(() => {
6034
+ if (!editor || editor.isDestroyed) return;
6035
+ editor.commands.setContent(safeContent, {
6036
+ emitUpdate: false
6037
+ });
6038
+ }, [content, editor]);
6032
6039
  if (!editor) return null;
6033
6040
  const shouldBubbleMenuShow = ({ state }) => {
6034
6041
  if (state.selection instanceof NodeSelection) {
@@ -6043,9 +6050,9 @@ function TiptapContent({
6043
6050
  return true;
6044
6051
  };
6045
6052
  return /* @__PURE__ */ jsxs35(Fragment3, { children: [
6046
- /* @__PURE__ */ jsx92(DragHandle, { editor }),
6047
- isEditable && /* @__PURE__ */ jsx92(TableMenu, { editor }),
6048
- /* @__PURE__ */ jsx92(
6053
+ !isDisabled && /* @__PURE__ */ jsx92(DragHandle, { editor }),
6054
+ isEditable && !isDisabled && /* @__PURE__ */ jsx92(TableMenu, { editor }),
6055
+ !isDisabled && /* @__PURE__ */ jsx92(
6049
6056
  BubbleMenu,
6050
6057
  {
6051
6058
  shouldShow: shouldBubbleMenuShow,
@@ -6060,10 +6067,16 @@ function TiptapContent({
6060
6067
  )
6061
6068
  }
6062
6069
  ),
6063
- /* @__PURE__ */ jsxs35("div", { className: `tiptap-content-wrapper ${!!error ? "has-error" : ""}`, children: [
6064
- /* @__PURE__ */ jsx92(EditorContent, { editor }),
6065
- isEditable && /* @__PURE__ */ jsx92(CharacterCount, { editor })
6066
- ] }),
6070
+ /* @__PURE__ */ jsxs35(
6071
+ "div",
6072
+ {
6073
+ className: `tiptap-content-wrapper ${!!error ? "has-error" : ""} ${isDisabled ? "is-disabled" : ""}`,
6074
+ children: [
6075
+ /* @__PURE__ */ jsx92(EditorContent, { editor }),
6076
+ isEditable && !isDisabled && /* @__PURE__ */ jsx92(CharacterCount, { editor })
6077
+ ]
6078
+ }
6079
+ ),
6067
6080
  !!error && /* @__PURE__ */ jsx92("p", { className: "tiptap-error-message", children: error }),
6068
6081
  activeDialog === "image" && isEditable && /* @__PURE__ */ jsx92(
6069
6082
  ImageDialog,