@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/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