@cyberyozh/text-editor 0.1.12 → 0.1.14
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.d.mts +4 -1
- package/dist/editor.d.ts +4 -1
- package/dist/editor.js +80 -5
- package/dist/editor.js.map +1 -1
- package/dist/editor.mjs +78 -4
- package/dist/editor.mjs.map +1 -1
- package/dist/render.d.mts +4 -1
- package/dist/render.d.ts +4 -1
- package/dist/render.js +35 -2
- package/dist/render.js.map +1 -1
- package/dist/render.mjs +33 -1
- package/dist/render.mjs.map +1 -1
- package/package.json +35 -35
- package/src/editor/dialogs/image-dialog/image-dialog.tsx +34 -2
- package/src/editor/editor.tsx +2 -2
- package/src/editor/index.ts +1 -0
- package/src/extensions/editor/figure.ts +21 -1
- package/src/render/index.ts +1 -0
- package/src/utils/html-to-tiptap-content.ts +41 -0
package/dist/render.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
+
import { JSONContent as JSONContent$1 } from '@tiptap/core';
|
|
2
3
|
|
|
3
4
|
type JSONContent = Record<string, any>;
|
|
4
5
|
interface TiptapRenderProps {
|
|
@@ -55,4 +56,6 @@ interface TiptapRenderProps {
|
|
|
55
56
|
*/
|
|
56
57
|
declare function TiptapRender({ content, getImageById }: TiptapRenderProps): ReactNode;
|
|
57
58
|
|
|
58
|
-
|
|
59
|
+
declare function htmlToTiptapContent(content: string | JSONContent$1): JSONContent$1;
|
|
60
|
+
|
|
61
|
+
export { TiptapRender, htmlToTiptapContent };
|
package/dist/render.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
+
import { JSONContent as JSONContent$1 } from '@tiptap/core';
|
|
2
3
|
|
|
3
4
|
type JSONContent = Record<string, any>;
|
|
4
5
|
interface TiptapRenderProps {
|
|
@@ -55,4 +56,6 @@ interface TiptapRenderProps {
|
|
|
55
56
|
*/
|
|
56
57
|
declare function TiptapRender({ content, getImageById }: TiptapRenderProps): ReactNode;
|
|
57
58
|
|
|
58
|
-
|
|
59
|
+
declare function htmlToTiptapContent(content: string | JSONContent$1): JSONContent$1;
|
|
60
|
+
|
|
61
|
+
export { TiptapRender, htmlToTiptapContent };
|
package/dist/render.js
CHANGED
|
@@ -30,7 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/render/index.ts
|
|
31
31
|
var render_exports = {};
|
|
32
32
|
__export(render_exports, {
|
|
33
|
-
TiptapRender: () => TiptapRender
|
|
33
|
+
TiptapRender: () => TiptapRender,
|
|
34
|
+
htmlToTiptapContent: () => htmlToTiptapContent
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(render_exports);
|
|
36
37
|
|
|
@@ -2585,8 +2586,40 @@ function renderTiptapToReact(content, getImageById) {
|
|
|
2585
2586
|
function TiptapRender({ content, getImageById }) {
|
|
2586
2587
|
return renderTiptapToReact(content, getImageById);
|
|
2587
2588
|
}
|
|
2589
|
+
|
|
2590
|
+
// src/utils/html-to-tiptap-content.ts
|
|
2591
|
+
var import_core16 = require("@tiptap/core");
|
|
2592
|
+
function isJSONContent(value) {
|
|
2593
|
+
return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
|
|
2594
|
+
}
|
|
2595
|
+
function htmlToTiptapContent(content) {
|
|
2596
|
+
if (isJSONContent(content)) {
|
|
2597
|
+
return content;
|
|
2598
|
+
}
|
|
2599
|
+
if (typeof content === "string") {
|
|
2600
|
+
try {
|
|
2601
|
+
const parsed = JSON.parse(content);
|
|
2602
|
+
if (isJSONContent(parsed)) {
|
|
2603
|
+
return parsed;
|
|
2604
|
+
}
|
|
2605
|
+
} catch {
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
if (!content || content.trim() === "") {
|
|
2609
|
+
return { type: "doc", content: [{ type: "paragraph" }] };
|
|
2610
|
+
}
|
|
2611
|
+
const sharedExtensions = getSharedExtensions();
|
|
2612
|
+
const extensions = [...sharedExtensions, BaseFigure];
|
|
2613
|
+
try {
|
|
2614
|
+
return (0, import_core16.generateJSON)(content, extensions);
|
|
2615
|
+
} catch (error) {
|
|
2616
|
+
console.error("Failed to convert HTML to Tiptap content:", error);
|
|
2617
|
+
return { type: "doc", content: [{ type: "paragraph" }] };
|
|
2618
|
+
}
|
|
2619
|
+
}
|
|
2588
2620
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2589
2621
|
0 && (module.exports = {
|
|
2590
|
-
TiptapRender
|
|
2622
|
+
TiptapRender,
|
|
2623
|
+
htmlToTiptapContent
|
|
2591
2624
|
});
|
|
2592
2625
|
//# sourceMappingURL=render.js.map
|