@cyberyozh/text-editor 0.1.5 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyberyozh/text-editor",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Rich text editor library based on Tiptap for CyberYozh",
5
5
  "author": "CyberYozh",
6
6
  "license": "MIT",
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
 
3
- import { useState } from "react";
3
+ import { useState, useEffect } from "react";
4
4
 
5
5
  import { EditorState, NodeSelection } from "@tiptap/pm/state";
6
6
  import { Slice } from "@tiptap/pm/model";
@@ -157,6 +157,14 @@ function TiptapContent({
157
157
  katexHandler(latex, katexDialogContext?.pos);
158
158
  };
159
159
 
160
+ useEffect(() => {
161
+ if (!editor || editor.isDestroyed) return;
162
+
163
+ editor.commands.setContent(safeContent, {
164
+ emitUpdate: false,
165
+ });
166
+ }, [content, editor]);
167
+
160
168
  if (!editor) return null;
161
169
 
162
170
  const shouldBubbleMenuShow = ({ state }: { state: EditorState }) => {
@@ -192,7 +200,11 @@ function TiptapContent({
192
200
  </BubbleMenu>
193
201
  )}
194
202
 
195
- <div className={`tiptap-content-wrapper ${!!error ? "has-error" : ""} ${isDisabled ? "is-disabled" : ""}`}>
203
+ <div
204
+ className={`tiptap-content-wrapper ${!!error ? "has-error" : ""} ${
205
+ isDisabled ? "is-disabled" : ""
206
+ }`}
207
+ >
196
208
  <EditorContent editor={editor} />
197
209
  {isEditable && !isDisabled && <CharacterCountComponent editor={editor} />}
198
210
  </div>