@cyberyozh/text-editor 0.1.12 → 0.1.13
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 +78 -5
- package/dist/editor.js.map +1 -1
- package/dist/editor.mjs +76 -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 +1 -1
- package/src/editor/dialogs/image-dialog/image-dialog.tsx +33 -2
- package/src/editor/editor.tsx +2 -2
- package/src/editor/index.ts +1 -0
- package/src/extensions/editor/figure.ts +20 -1
- package/src/render/index.ts +1 -0
- package/src/utils/html-to-tiptap-content.ts +41 -0
package/dist/render.mjs
CHANGED
|
@@ -2549,7 +2549,39 @@ function renderTiptapToReact(content, getImageById) {
|
|
|
2549
2549
|
function TiptapRender({ content, getImageById }) {
|
|
2550
2550
|
return renderTiptapToReact(content, getImageById);
|
|
2551
2551
|
}
|
|
2552
|
+
|
|
2553
|
+
// src/utils/html-to-tiptap-content.ts
|
|
2554
|
+
import { generateJSON } from "@tiptap/core";
|
|
2555
|
+
function isJSONContent(value) {
|
|
2556
|
+
return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
|
|
2557
|
+
}
|
|
2558
|
+
function htmlToTiptapContent(content) {
|
|
2559
|
+
if (isJSONContent(content)) {
|
|
2560
|
+
return content;
|
|
2561
|
+
}
|
|
2562
|
+
if (typeof content === "string") {
|
|
2563
|
+
try {
|
|
2564
|
+
const parsed = JSON.parse(content);
|
|
2565
|
+
if (isJSONContent(parsed)) {
|
|
2566
|
+
return parsed;
|
|
2567
|
+
}
|
|
2568
|
+
} catch {
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
if (!content || content.trim() === "") {
|
|
2572
|
+
return { type: "doc", content: [{ type: "paragraph" }] };
|
|
2573
|
+
}
|
|
2574
|
+
const sharedExtensions = getSharedExtensions();
|
|
2575
|
+
const extensions = [...sharedExtensions, BaseFigure];
|
|
2576
|
+
try {
|
|
2577
|
+
return generateJSON(content, extensions);
|
|
2578
|
+
} catch (error) {
|
|
2579
|
+
console.error("Failed to convert HTML to Tiptap content:", error);
|
|
2580
|
+
return { type: "doc", content: [{ type: "paragraph" }] };
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2552
2583
|
export {
|
|
2553
|
-
TiptapRender
|
|
2584
|
+
TiptapRender,
|
|
2585
|
+
htmlToTiptapContent
|
|
2554
2586
|
};
|
|
2555
2587
|
//# sourceMappingURL=render.mjs.map
|