@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.css +8 -0
- package/dist/editor.css.map +1 -1
- package/dist/editor.d.mts +5 -0
- package/dist/editor.d.ts +5 -0
- package/dist/editor.js +22 -9
- package/dist/editor.js.map +1 -1
- package/dist/editor.mjs +23 -10
- package/dist/editor.mjs.map +1 -1
- package/dist/styles/index.css +8 -0
- package/package.json +1 -5
- package/src/editor/editor.tsx +36 -16
- package/src/styles/editor/states.css +11 -0
package/dist/styles/index.css
CHANGED
|
@@ -1889,6 +1889,14 @@
|
|
|
1889
1889
|
outline: none;
|
|
1890
1890
|
background-color: transparent;
|
|
1891
1891
|
}
|
|
1892
|
+
.tiptap-content-wrapper.is-disabled {
|
|
1893
|
+
opacity: 0.6;
|
|
1894
|
+
cursor: not-allowed;
|
|
1895
|
+
pointer-events: none;
|
|
1896
|
+
}
|
|
1897
|
+
.tiptap-content-wrapper.is-disabled .ProseMirror {
|
|
1898
|
+
background-color: var(--tiptap-color-grey-1, #f5f5f5);
|
|
1899
|
+
}
|
|
1892
1900
|
|
|
1893
1901
|
/* src/styles/editor/callout-menu.css */
|
|
1894
1902
|
.tiptap__drag-handle-color-menu {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyberyozh/text-editor",
|
|
3
|
-
"version": "0.1.
|
|
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",
|
|
@@ -42,10 +42,6 @@
|
|
|
42
42
|
"release": "npm run build && changeset publish",
|
|
43
43
|
"release:complete": "git add . && git commit -m \"chore: release v$(node -p \"require('./package.json').version\")\" && npm run release && git push --follow-tags"
|
|
44
44
|
},
|
|
45
|
-
"peerDependencies": {
|
|
46
|
-
"react": "^18.0.0 || ^19.0.0",
|
|
47
|
-
"react-dom": "^18.0.0 || ^19.0.0"
|
|
48
|
-
},
|
|
49
45
|
"dependencies": {
|
|
50
46
|
"@floating-ui/dom": "^1.7.4",
|
|
51
47
|
"@tiptap/core": "^3.10.6",
|
package/src/editor/editor.tsx
CHANGED
|
@@ -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";
|
|
@@ -39,6 +39,11 @@ import { getTranslations, type SupportedLanguage } from "../utils/get-translatio
|
|
|
39
39
|
|
|
40
40
|
interface TiptapProps {
|
|
41
41
|
isEditable?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* When true, makes the editor completely disabled (non-editable with disabled styling)
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
isDisabled?: boolean;
|
|
42
47
|
content: string;
|
|
43
48
|
handleChange?: (value: JSONContent) => void;
|
|
44
49
|
/**
|
|
@@ -70,6 +75,7 @@ function TiptapContent({
|
|
|
70
75
|
handleChange,
|
|
71
76
|
imageHandlers,
|
|
72
77
|
isEditable = true,
|
|
78
|
+
isDisabled = false,
|
|
73
79
|
lang,
|
|
74
80
|
error,
|
|
75
81
|
}: TiptapProps) {
|
|
@@ -94,11 +100,11 @@ function TiptapContent({
|
|
|
94
100
|
|
|
95
101
|
const editor = useEditor(
|
|
96
102
|
{
|
|
97
|
-
editable: isEditable,
|
|
103
|
+
editable: isEditable && !isDisabled,
|
|
98
104
|
extensions: getEditorExtensions({
|
|
99
105
|
translations,
|
|
100
106
|
suggestion: createSuggestions(translations, !!imageHandlers),
|
|
101
|
-
isEditable,
|
|
107
|
+
isEditable: isEditable && !isDisabled,
|
|
102
108
|
getImageById: imageHandlers?.getImage,
|
|
103
109
|
onKatexClick: (latex, pos) => {
|
|
104
110
|
setKatexDialogContext({ latex, pos });
|
|
@@ -151,6 +157,14 @@ function TiptapContent({
|
|
|
151
157
|
katexHandler(latex, katexDialogContext?.pos);
|
|
152
158
|
};
|
|
153
159
|
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
if (!editor || editor.isDestroyed) return;
|
|
162
|
+
|
|
163
|
+
editor.commands.setContent(safeContent, {
|
|
164
|
+
emitUpdate: false,
|
|
165
|
+
});
|
|
166
|
+
}, [content, editor]);
|
|
167
|
+
|
|
154
168
|
if (!editor) return null;
|
|
155
169
|
|
|
156
170
|
const shouldBubbleMenuShow = ({ state }: { state: EditorState }) => {
|
|
@@ -171,22 +185,28 @@ function TiptapContent({
|
|
|
171
185
|
|
|
172
186
|
return (
|
|
173
187
|
<>
|
|
174
|
-
<DragHandle editor={editor} />
|
|
175
|
-
{isEditable && <TableMenu editor={editor} />}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
options={{ placement: "bottom", offset: 8, flip: true }}
|
|
180
|
-
>
|
|
181
|
-
<BubbleMenuContent
|
|
188
|
+
{!isDisabled && <DragHandle editor={editor} />}
|
|
189
|
+
{isEditable && !isDisabled && <TableMenu editor={editor} />}
|
|
190
|
+
{!isDisabled && (
|
|
191
|
+
<BubbleMenu
|
|
192
|
+
shouldShow={shouldBubbleMenuShow}
|
|
182
193
|
editor={editor}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
194
|
+
options={{ placement: "bottom", offset: 8, flip: true }}
|
|
195
|
+
>
|
|
196
|
+
<BubbleMenuContent
|
|
197
|
+
editor={editor}
|
|
198
|
+
onLinkClick={(selectedText, url) => setLinkDialogContext({ selectedText, url })}
|
|
199
|
+
/>
|
|
200
|
+
</BubbleMenu>
|
|
201
|
+
)}
|
|
186
202
|
|
|
187
|
-
<div
|
|
203
|
+
<div
|
|
204
|
+
className={`tiptap-content-wrapper ${!!error ? "has-error" : ""} ${
|
|
205
|
+
isDisabled ? "is-disabled" : ""
|
|
206
|
+
}`}
|
|
207
|
+
>
|
|
188
208
|
<EditorContent editor={editor} />
|
|
189
|
-
{isEditable && <CharacterCountComponent editor={editor} />}
|
|
209
|
+
{isEditable && !isDisabled && <CharacterCountComponent editor={editor} />}
|
|
190
210
|
</div>
|
|
191
211
|
{!!error && <p className="tiptap-error-message">{error}</p>}
|
|
192
212
|
|
|
@@ -41,3 +41,14 @@
|
|
|
41
41
|
outline: none;
|
|
42
42
|
background-color: transparent;
|
|
43
43
|
}
|
|
44
|
+
|
|
45
|
+
/* Disabled state styles */
|
|
46
|
+
.tiptap-content-wrapper.is-disabled {
|
|
47
|
+
opacity: 0.6;
|
|
48
|
+
cursor: not-allowed;
|
|
49
|
+
pointer-events: none;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.tiptap-content-wrapper.is-disabled .ProseMirror {
|
|
53
|
+
background-color: var(--tiptap-color-grey-1, #f5f5f5);
|
|
54
|
+
}
|