ritext 1.0.29 → 1.2.1
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/index.d.mts +32 -10
- package/dist/index.d.ts +32 -10
- package/dist/index.js +61 -3
- package/dist/index.mjs +62 -4
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,27 +1,49 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode, ComponentPropsWithoutRef } from 'react';
|
|
3
|
+
import { Extensions, JSONContent, Editor as Editor$1 } from '@tiptap/react';
|
|
1
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
3
|
-
import { Extensions } from '@tiptap/react';
|
|
4
5
|
|
|
5
|
-
interface
|
|
6
|
+
interface EditorRef {
|
|
7
|
+
editor: Editor$1 | null;
|
|
8
|
+
insert: (value: string) => void;
|
|
9
|
+
insertAtEnd: (value: string) => void;
|
|
10
|
+
replaceSelection: (value: string) => void;
|
|
11
|
+
focus: () => void;
|
|
12
|
+
getHTML: () => string;
|
|
13
|
+
setContent: (value: string) => void;
|
|
14
|
+
clear: () => void;
|
|
15
|
+
}
|
|
16
|
+
type OutputType = "html" | "json" | "text";
|
|
17
|
+
type ContentValue = string | JSONContent;
|
|
18
|
+
type EditorProps = {
|
|
6
19
|
children?: ReactNode;
|
|
7
20
|
extensions?: Extensions;
|
|
8
21
|
className?: string;
|
|
9
22
|
dragHandler?: boolean;
|
|
10
23
|
showBubbleMenu?: boolean;
|
|
11
|
-
|
|
12
|
-
|
|
24
|
+
content?: ContentValue;
|
|
25
|
+
output?: OutputType;
|
|
26
|
+
onContentChange?: (value: string | JSONContent) => void;
|
|
27
|
+
};
|
|
13
28
|
|
|
14
|
-
|
|
29
|
+
declare const Editor: react.ForwardRefExoticComponent<EditorProps & react.RefAttributes<EditorRef>>;
|
|
30
|
+
|
|
31
|
+
interface Props$2 {
|
|
15
32
|
className?: string;
|
|
16
33
|
buttonClassName?: string;
|
|
17
34
|
dropdownContainerClassName?: string;
|
|
18
35
|
dropdownItemClassName?: string;
|
|
19
36
|
}
|
|
20
|
-
declare const Toolbar: ({ className, buttonClassName, dropdownContainerClassName, dropdownItemClassName }: Props$
|
|
37
|
+
declare const Toolbar: ({ className, buttonClassName, dropdownContainerClassName, dropdownItemClassName }: Props$2) => react_jsx_runtime.JSX.Element | null;
|
|
21
38
|
|
|
22
|
-
interface Props {
|
|
39
|
+
interface Props$1 {
|
|
23
40
|
className?: string;
|
|
24
41
|
}
|
|
25
|
-
declare const Content: ({ className }: Props) => react_jsx_runtime.JSX.Element;
|
|
42
|
+
declare const Content: ({ className }: Props$1) => react_jsx_runtime.JSX.Element;
|
|
43
|
+
|
|
44
|
+
type Props = ComponentPropsWithoutRef<"div"> & {
|
|
45
|
+
content?: string | null;
|
|
46
|
+
};
|
|
47
|
+
declare const Renderer: ({ content, ...props }: Props) => react_jsx_runtime.JSX.Element | null;
|
|
26
48
|
|
|
27
|
-
export { Content, Editor, Toolbar };
|
|
49
|
+
export { Content, Editor, type EditorRef, Renderer, Toolbar };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,27 +1,49 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode, ComponentPropsWithoutRef } from 'react';
|
|
3
|
+
import { Extensions, JSONContent, Editor as Editor$1 } from '@tiptap/react';
|
|
1
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
3
|
-
import { Extensions } from '@tiptap/react';
|
|
4
5
|
|
|
5
|
-
interface
|
|
6
|
+
interface EditorRef {
|
|
7
|
+
editor: Editor$1 | null;
|
|
8
|
+
insert: (value: string) => void;
|
|
9
|
+
insertAtEnd: (value: string) => void;
|
|
10
|
+
replaceSelection: (value: string) => void;
|
|
11
|
+
focus: () => void;
|
|
12
|
+
getHTML: () => string;
|
|
13
|
+
setContent: (value: string) => void;
|
|
14
|
+
clear: () => void;
|
|
15
|
+
}
|
|
16
|
+
type OutputType = "html" | "json" | "text";
|
|
17
|
+
type ContentValue = string | JSONContent;
|
|
18
|
+
type EditorProps = {
|
|
6
19
|
children?: ReactNode;
|
|
7
20
|
extensions?: Extensions;
|
|
8
21
|
className?: string;
|
|
9
22
|
dragHandler?: boolean;
|
|
10
23
|
showBubbleMenu?: boolean;
|
|
11
|
-
|
|
12
|
-
|
|
24
|
+
content?: ContentValue;
|
|
25
|
+
output?: OutputType;
|
|
26
|
+
onContentChange?: (value: string | JSONContent) => void;
|
|
27
|
+
};
|
|
13
28
|
|
|
14
|
-
|
|
29
|
+
declare const Editor: react.ForwardRefExoticComponent<EditorProps & react.RefAttributes<EditorRef>>;
|
|
30
|
+
|
|
31
|
+
interface Props$2 {
|
|
15
32
|
className?: string;
|
|
16
33
|
buttonClassName?: string;
|
|
17
34
|
dropdownContainerClassName?: string;
|
|
18
35
|
dropdownItemClassName?: string;
|
|
19
36
|
}
|
|
20
|
-
declare const Toolbar: ({ className, buttonClassName, dropdownContainerClassName, dropdownItemClassName }: Props$
|
|
37
|
+
declare const Toolbar: ({ className, buttonClassName, dropdownContainerClassName, dropdownItemClassName }: Props$2) => react_jsx_runtime.JSX.Element | null;
|
|
21
38
|
|
|
22
|
-
interface Props {
|
|
39
|
+
interface Props$1 {
|
|
23
40
|
className?: string;
|
|
24
41
|
}
|
|
25
|
-
declare const Content: ({ className }: Props) => react_jsx_runtime.JSX.Element;
|
|
42
|
+
declare const Content: ({ className }: Props$1) => react_jsx_runtime.JSX.Element;
|
|
43
|
+
|
|
44
|
+
type Props = ComponentPropsWithoutRef<"div"> & {
|
|
45
|
+
content?: string | null;
|
|
46
|
+
};
|
|
47
|
+
declare const Renderer: ({ content, ...props }: Props) => react_jsx_runtime.JSX.Element | null;
|
|
26
48
|
|
|
27
|
-
export { Content, Editor, Toolbar };
|
|
49
|
+
export { Content, Editor, type EditorRef, Renderer, Toolbar };
|
package/dist/index.js
CHANGED
|
@@ -61,6 +61,7 @@ var src_exports = {};
|
|
|
61
61
|
__export(src_exports, {
|
|
62
62
|
Content: () => Content_default,
|
|
63
63
|
Editor: () => Editor_default,
|
|
64
|
+
Renderer: () => Renderer_default,
|
|
64
65
|
Toolbar: () => Toolbar_default
|
|
65
66
|
});
|
|
66
67
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -316,19 +317,66 @@ var EditorProvider = ({ children, value }) => {
|
|
|
316
317
|
|
|
317
318
|
// src/lib/Editor.tsx
|
|
318
319
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
319
|
-
var Editor = ({ children, extensions = [], className, dragHandler = true, showBubbleMenu = true }) => {
|
|
320
|
+
var Editor = (0, import_react6.forwardRef)(({ children, extensions = [], className, dragHandler = true, showBubbleMenu = true, content, onContentChange, output }, ref) => {
|
|
320
321
|
const stableExtensions = (0, import_react6.useMemo)(() => extensions, [extensions]);
|
|
321
322
|
const editor = (0, import_react7.useEditor)({
|
|
322
323
|
extensions: stableExtensions,
|
|
323
|
-
immediatelyRender: false
|
|
324
|
+
immediatelyRender: false,
|
|
325
|
+
content,
|
|
326
|
+
onUpdate: ({ editor: editor2 }) => {
|
|
327
|
+
if (!onContentChange) return;
|
|
328
|
+
const out = output === "json" ? editor2.getJSON() : output === "text" ? editor2.getText() : editor2.getHTML();
|
|
329
|
+
onContentChange(out);
|
|
330
|
+
}
|
|
324
331
|
}, [stableExtensions]);
|
|
325
332
|
const value = (0, import_react6.useMemo)(() => ({ editor }), [editor]);
|
|
333
|
+
(0, import_react6.useImperativeHandle)(
|
|
334
|
+
ref,
|
|
335
|
+
() => ({
|
|
336
|
+
editor,
|
|
337
|
+
insert: (val) => {
|
|
338
|
+
if (!editor) return;
|
|
339
|
+
editor.chain().focus().insertContent(val).run();
|
|
340
|
+
},
|
|
341
|
+
insertAtEnd: (val) => {
|
|
342
|
+
if (!editor) return;
|
|
343
|
+
const end = editor.state.doc.content.size;
|
|
344
|
+
editor.commands.insertContentAt(end, val);
|
|
345
|
+
editor.commands.focus(end);
|
|
346
|
+
},
|
|
347
|
+
replaceSelection: (val) => {
|
|
348
|
+
if (!editor) return;
|
|
349
|
+
const { from, to } = editor.state.selection;
|
|
350
|
+
editor.commands.insertContentAt({ from, to }, val);
|
|
351
|
+
editor.chain().focus().run();
|
|
352
|
+
},
|
|
353
|
+
focus: () => {
|
|
354
|
+
if (!editor) return;
|
|
355
|
+
editor.chain().focus().run();
|
|
356
|
+
},
|
|
357
|
+
getHTML: () => {
|
|
358
|
+
var _a, _b;
|
|
359
|
+
return (_b = (_a = editor == null ? void 0 : editor.getHTML) == null ? void 0 : _a.call(editor)) != null ? _b : "";
|
|
360
|
+
},
|
|
361
|
+
setContent: (val) => {
|
|
362
|
+
if (!editor) return;
|
|
363
|
+
editor.commands.setContent(val);
|
|
364
|
+
},
|
|
365
|
+
clear: () => {
|
|
366
|
+
var _a, _b;
|
|
367
|
+
if (!editor) return;
|
|
368
|
+
(_b = (_a = editor.commands).clearContent) == null ? void 0 : _b.call(_a);
|
|
369
|
+
}
|
|
370
|
+
}),
|
|
371
|
+
[editor]
|
|
372
|
+
);
|
|
326
373
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(EditorProvider, { value: __spreadProps(__spreadValues({}, value), { dragHandler }), children: [
|
|
327
374
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className, children }),
|
|
328
375
|
value.editor && dragHandler && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(RiDragHandler_default, { editor: value.editor }),
|
|
329
376
|
value.editor && showBubbleMenu && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(BubbleMenu_default, { editor: value.editor })
|
|
330
377
|
] });
|
|
331
|
-
};
|
|
378
|
+
});
|
|
379
|
+
Editor.displayName = "Editor";
|
|
332
380
|
var Editor_default = Editor;
|
|
333
381
|
|
|
334
382
|
// src/lib/Toolbar.tsx
|
|
@@ -382,9 +430,19 @@ var Content = ({ className }) => {
|
|
|
382
430
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_react8.EditorContent, { editor, className: (0, import_tailwind_merge3.twMerge)(`focus:outline-none [&_.tiptap]:focus:outline-none [&_.tiptap]:min-h-50 ${dragHandler ? "[&_.tiptap]:p-[10px_20px_10px_50px]" : "[&_.tiptap]:p-[10px_20px]"}`, className) });
|
|
383
431
|
};
|
|
384
432
|
var Content_default = Content;
|
|
433
|
+
|
|
434
|
+
// src/lib/Renderer.tsx
|
|
435
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
436
|
+
var Renderer = (_a) => {
|
|
437
|
+
var _b = _a, { content } = _b, props = __objRest(_b, ["content"]);
|
|
438
|
+
if (!content) return null;
|
|
439
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", __spreadValues({ dangerouslySetInnerHTML: { __html: content } }, props));
|
|
440
|
+
};
|
|
441
|
+
var Renderer_default = Renderer;
|
|
385
442
|
// Annotate the CommonJS export names for ESM import in node:
|
|
386
443
|
0 && (module.exports = {
|
|
387
444
|
Content,
|
|
388
445
|
Editor,
|
|
446
|
+
Renderer,
|
|
389
447
|
Toolbar
|
|
390
448
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
Tooltip_default
|
|
9
9
|
} from "./chunk-LLHBVRQR.mjs";
|
|
10
10
|
import {
|
|
11
|
+
__objRest,
|
|
11
12
|
__spreadProps,
|
|
12
13
|
__spreadValues
|
|
13
14
|
} from "./chunk-WNQUEZJF.mjs";
|
|
@@ -16,7 +17,7 @@ import {
|
|
|
16
17
|
import "@siamf/react-color-pick/dist/index.css";
|
|
17
18
|
|
|
18
19
|
// src/lib/Editor.tsx
|
|
19
|
-
import { useMemo } from "react";
|
|
20
|
+
import { forwardRef, useMemo, useImperativeHandle } from "react";
|
|
20
21
|
import { useEditor as useEditor2 } from "@tiptap/react";
|
|
21
22
|
|
|
22
23
|
// src/lib/internal_com/RiDragHandler.tsx
|
|
@@ -115,19 +116,66 @@ var BubbleMenu_default = BubbleMenu;
|
|
|
115
116
|
|
|
116
117
|
// src/lib/Editor.tsx
|
|
117
118
|
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
118
|
-
var Editor = ({ children, extensions = [], className, dragHandler = true, showBubbleMenu = true }) => {
|
|
119
|
+
var Editor = forwardRef(({ children, extensions = [], className, dragHandler = true, showBubbleMenu = true, content, onContentChange, output }, ref) => {
|
|
119
120
|
const stableExtensions = useMemo(() => extensions, [extensions]);
|
|
120
121
|
const editor = useEditor2({
|
|
121
122
|
extensions: stableExtensions,
|
|
122
|
-
immediatelyRender: false
|
|
123
|
+
immediatelyRender: false,
|
|
124
|
+
content,
|
|
125
|
+
onUpdate: ({ editor: editor2 }) => {
|
|
126
|
+
if (!onContentChange) return;
|
|
127
|
+
const out = output === "json" ? editor2.getJSON() : output === "text" ? editor2.getText() : editor2.getHTML();
|
|
128
|
+
onContentChange(out);
|
|
129
|
+
}
|
|
123
130
|
}, [stableExtensions]);
|
|
124
131
|
const value = useMemo(() => ({ editor }), [editor]);
|
|
132
|
+
useImperativeHandle(
|
|
133
|
+
ref,
|
|
134
|
+
() => ({
|
|
135
|
+
editor,
|
|
136
|
+
insert: (val) => {
|
|
137
|
+
if (!editor) return;
|
|
138
|
+
editor.chain().focus().insertContent(val).run();
|
|
139
|
+
},
|
|
140
|
+
insertAtEnd: (val) => {
|
|
141
|
+
if (!editor) return;
|
|
142
|
+
const end = editor.state.doc.content.size;
|
|
143
|
+
editor.commands.insertContentAt(end, val);
|
|
144
|
+
editor.commands.focus(end);
|
|
145
|
+
},
|
|
146
|
+
replaceSelection: (val) => {
|
|
147
|
+
if (!editor) return;
|
|
148
|
+
const { from, to } = editor.state.selection;
|
|
149
|
+
editor.commands.insertContentAt({ from, to }, val);
|
|
150
|
+
editor.chain().focus().run();
|
|
151
|
+
},
|
|
152
|
+
focus: () => {
|
|
153
|
+
if (!editor) return;
|
|
154
|
+
editor.chain().focus().run();
|
|
155
|
+
},
|
|
156
|
+
getHTML: () => {
|
|
157
|
+
var _a, _b;
|
|
158
|
+
return (_b = (_a = editor == null ? void 0 : editor.getHTML) == null ? void 0 : _a.call(editor)) != null ? _b : "";
|
|
159
|
+
},
|
|
160
|
+
setContent: (val) => {
|
|
161
|
+
if (!editor) return;
|
|
162
|
+
editor.commands.setContent(val);
|
|
163
|
+
},
|
|
164
|
+
clear: () => {
|
|
165
|
+
var _a, _b;
|
|
166
|
+
if (!editor) return;
|
|
167
|
+
(_b = (_a = editor.commands).clearContent) == null ? void 0 : _b.call(_a);
|
|
168
|
+
}
|
|
169
|
+
}),
|
|
170
|
+
[editor]
|
|
171
|
+
);
|
|
125
172
|
return /* @__PURE__ */ jsxs2(EditorProvider, { value: __spreadProps(__spreadValues({}, value), { dragHandler }), children: [
|
|
126
173
|
/* @__PURE__ */ jsx3("div", { className, children }),
|
|
127
174
|
value.editor && dragHandler && /* @__PURE__ */ jsx3(RiDragHandler_default, { editor: value.editor }),
|
|
128
175
|
value.editor && showBubbleMenu && /* @__PURE__ */ jsx3(BubbleMenu_default, { editor: value.editor })
|
|
129
176
|
] });
|
|
130
|
-
};
|
|
177
|
+
});
|
|
178
|
+
Editor.displayName = "Editor";
|
|
131
179
|
var Editor_default = Editor;
|
|
132
180
|
|
|
133
181
|
// src/lib/Toolbar.tsx
|
|
@@ -181,8 +229,18 @@ var Content = ({ className }) => {
|
|
|
181
229
|
return /* @__PURE__ */ jsx5(EditorContent, { editor, className: twMerge2(`focus:outline-none [&_.tiptap]:focus:outline-none [&_.tiptap]:min-h-50 ${dragHandler ? "[&_.tiptap]:p-[10px_20px_10px_50px]" : "[&_.tiptap]:p-[10px_20px]"}`, className) });
|
|
182
230
|
};
|
|
183
231
|
var Content_default = Content;
|
|
232
|
+
|
|
233
|
+
// src/lib/Renderer.tsx
|
|
234
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
235
|
+
var Renderer = (_a) => {
|
|
236
|
+
var _b = _a, { content } = _b, props = __objRest(_b, ["content"]);
|
|
237
|
+
if (!content) return null;
|
|
238
|
+
return /* @__PURE__ */ jsx6("div", __spreadValues({ dangerouslySetInnerHTML: { __html: content } }, props));
|
|
239
|
+
};
|
|
240
|
+
var Renderer_default = Renderer;
|
|
184
241
|
export {
|
|
185
242
|
Content_default as Content,
|
|
186
243
|
Editor_default as Editor,
|
|
244
|
+
Renderer_default as Renderer,
|
|
187
245
|
Toolbar_default as Toolbar
|
|
188
246
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ritext",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Ritext is a modern WYSIWYG rich text editor built with Tailwind CSS, powered by Tiptap. It offers a customizable UI and functional layer that lets you design your own editor controls and toolbars with clean, composable React components—no heavy UI, no extra dependencies beyond Tiptap.",
|
|
5
5
|
"homepage": "https://ritext.vercel.app/",
|
|
6
6
|
"main": "dist/index.js",
|