@cyberyozh/text-editor 0.1.11 → 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/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
- export { TiptapRender };
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
- export { TiptapRender };
59
+ declare function htmlToTiptapContent(content: string | JSONContent$1): JSONContent$1;
60
+
61
+ export { TiptapRender, htmlToTiptapContent };
package/dist/render.js CHANGED
@@ -30,12 +30,13 @@ 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
 
37
38
  // src/render/tiptap-render.tsx
38
- var import_react3 = require("@tiptap/static-renderer/pm/react");
39
+ var import_react2 = require("@tiptap/static-renderer/pm/react");
39
40
 
40
41
  // src/extensions/render/get-render-extensions.ts
41
42
  var import_extension_mathematics = require("@tiptap/extension-mathematics");
@@ -664,8 +665,9 @@ var BaseFigure = import_extension_image.default.extend({
664
665
  isolating: true,
665
666
  selectable: false,
666
667
  addOptions() {
668
+ const parentOptions = this.parent?.() || {};
667
669
  return {
668
- HTMLAttributes: {},
670
+ ...parentOptions,
669
671
  getImageById: void 0,
670
672
  onFigureClick: void 0
671
673
  };
@@ -1598,9 +1600,8 @@ function getRenderExtensions() {
1598
1600
  BasePromptContent,
1599
1601
  BaseVideo,
1600
1602
  BaseFigure,
1601
- // Need to update
1602
1603
  import_extension_table.TableKit.configure({
1603
- table: { resizable: false }
1604
+ table: { resizable: false, renderWrapper: true }
1604
1605
  }),
1605
1606
  import_extension_mathematics.Mathematics.configure({
1606
1607
  katexOptions: {
@@ -2281,51 +2282,6 @@ var PromptContent = ({ children, isEmpty, placeholder }) => /* @__PURE__ */ (0,
2281
2282
  }
2282
2283
  ) });
2283
2284
 
2284
- // src/extensions/views/components/table.tsx
2285
- var import_react2 = require("react");
2286
- var import_jsx_runtime67 = require("react/jsx-runtime");
2287
- function Table({ children }) {
2288
- const wrapperRef = (0, import_react2.useRef)(null);
2289
- const [undefinedColWidth, setUndefinedColWidth] = (0, import_react2.useState)(void 0);
2290
- let colWidths = [];
2291
- if (Array.isArray(children) && children.length > 0) {
2292
- const firstRow = children[0];
2293
- if (firstRow?.props?.children) {
2294
- const cells = Array.isArray(firstRow.props.children) ? firstRow.props.children : [firstRow.props.children];
2295
- colWidths = cells.map((cell) => cell?.props?.node?.attrs?.colwidth?.[0]);
2296
- }
2297
- }
2298
- const definedWidths = colWidths.filter((w) => w !== void 0);
2299
- const totalDefinedWidth = definedWidths.reduce((total, width) => total + width, 0);
2300
- const undefinedCount = colWidths.filter((w) => w === void 0).length;
2301
- (0, import_react2.useEffect)(() => {
2302
- if (wrapperRef.current && undefinedCount > 0) {
2303
- const containerWidth = wrapperRef.current.clientWidth;
2304
- const remainingSpace = containerWidth - totalDefinedWidth - 2;
2305
- const calculatedWidth = Math.floor(remainingSpace / undefinedCount);
2306
- setUndefinedColWidth(calculatedWidth > 0 ? calculatedWidth : void 0);
2307
- }
2308
- }, [totalDefinedWidth, undefinedCount]);
2309
- const tableWidth = undefinedCount > 0 && undefinedColWidth ? totalDefinedWidth + undefinedColWidth * undefinedCount + 2 : totalDefinedWidth > 0 ? totalDefinedWidth + 2 : void 0;
2310
- return /* @__PURE__ */ (0, import_jsx_runtime67.jsx)(
2311
- "div",
2312
- {
2313
- ref: wrapperRef,
2314
- className: "tableWrapper",
2315
- children: /* @__PURE__ */ (0, import_jsx_runtime67.jsxs)("table", { style: tableWidth ? { width: `${tableWidth}px` } : void 0, children: [
2316
- colWidths.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime67.jsx)("colgroup", { children: colWidths.map((width, index) => /* @__PURE__ */ (0, import_jsx_runtime67.jsx)(
2317
- "col",
2318
- {
2319
- style: width ? { width: `${width}px` } : undefinedColWidth ? { width: `${undefinedColWidth}px` } : void 0
2320
- },
2321
- index
2322
- )) }),
2323
- /* @__PURE__ */ (0, import_jsx_runtime67.jsx)("tbody", { children })
2324
- ] })
2325
- }
2326
- );
2327
- }
2328
-
2329
2285
  // src/utils/detect-video-hosting.ts
2330
2286
  var VIDEO_PATTERNS = {
2331
2287
  youtube: /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=|shorts\/)?([a-zA-Z0-9_-]{11})/,
@@ -2398,22 +2354,22 @@ var detectVideoHosting = (src) => {
2398
2354
  };
2399
2355
 
2400
2356
  // src/extensions/views/components/video.tsx
2401
- var import_jsx_runtime68 = require("react/jsx-runtime");
2357
+ var import_jsx_runtime67 = require("react/jsx-runtime");
2402
2358
  var Video = ({ src, children }) => {
2403
2359
  const videoInfo = detectVideoHosting(src);
2404
2360
  if (!videoInfo?.embedUrl) {
2405
- return /* @__PURE__ */ (0, import_jsx_runtime68.jsxs)("div", { className: "video-node", children: [
2406
- /* @__PURE__ */ (0, import_jsx_runtime68.jsx)("div", { className: "video-error", children: /* @__PURE__ */ (0, import_jsx_runtime68.jsx)("span", { children: "Unsupported or invalid video URL" }) }),
2361
+ return /* @__PURE__ */ (0, import_jsx_runtime67.jsxs)("div", { className: "video-node", children: [
2362
+ /* @__PURE__ */ (0, import_jsx_runtime67.jsx)("div", { className: "video-error", children: /* @__PURE__ */ (0, import_jsx_runtime67.jsx)("span", { children: "Unsupported or invalid video URL" }) }),
2407
2363
  children
2408
2364
  ] });
2409
2365
  }
2410
- return /* @__PURE__ */ (0, import_jsx_runtime68.jsxs)(
2366
+ return /* @__PURE__ */ (0, import_jsx_runtime67.jsxs)(
2411
2367
  "div",
2412
2368
  {
2413
2369
  className: "video-node",
2414
2370
  "data-video": "",
2415
2371
  children: [
2416
- /* @__PURE__ */ (0, import_jsx_runtime68.jsx)("div", { className: "video-player-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
2372
+ /* @__PURE__ */ (0, import_jsx_runtime67.jsx)("div", { className: "video-player-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime67.jsx)(
2417
2373
  "iframe",
2418
2374
  {
2419
2375
  className: "video-iframe",
@@ -2430,10 +2386,10 @@ var Video = ({ src, children }) => {
2430
2386
  };
2431
2387
 
2432
2388
  // src/render/static-renderer-config.tsx
2433
- var import_jsx_runtime69 = require("react/jsx-runtime");
2389
+ var import_jsx_runtime68 = require("react/jsx-runtime");
2434
2390
  var getNodeMapping = (getImageById) => ({
2435
2391
  callout({ node, children }) {
2436
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(Callout, { ...node.attrs, children });
2392
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(Callout, { ...node.attrs, children });
2437
2393
  },
2438
2394
  codeBlock({ node, children }) {
2439
2395
  const language = node.attrs.language || "";
@@ -2457,41 +2413,38 @@ var getNodeMapping = (getImageById) => ({
2457
2413
  console.warn(`Failed to highlight code for language "${language}":`, error);
2458
2414
  highlightedHtml = codeText.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
2459
2415
  }
2460
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
2416
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
2461
2417
  CodeBlock,
2462
2418
  {
2463
2419
  language,
2464
2420
  isEditable: false,
2465
- children: /* @__PURE__ */ (0, import_jsx_runtime69.jsx)("code", { dangerouslySetInnerHTML: { __html: highlightedHtml } })
2421
+ children: /* @__PURE__ */ (0, import_jsx_runtime68.jsx)("code", { dangerouslySetInnerHTML: { __html: highlightedHtml } })
2466
2422
  }
2467
2423
  );
2468
2424
  },
2469
2425
  customQuote({ children }) {
2470
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(CustomQuote, { children });
2426
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(CustomQuote, { children });
2471
2427
  },
2472
2428
  customQuoteText({ children }) {
2473
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(CustomQuoteText, { children });
2429
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(CustomQuoteText, { children });
2474
2430
  },
2475
2431
  customQuoteAuthor({ children }) {
2476
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(CustomQuoteAuthor, { children });
2432
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(CustomQuoteAuthor, { children });
2477
2433
  },
2478
2434
  customQuoteSign({ children }) {
2479
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(CustomQuoteSign, { children });
2435
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(CustomQuoteSign, { children });
2480
2436
  },
2481
2437
  promptHeader({ children }) {
2482
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(PromptHeader, { children });
2438
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(PromptHeader, { children });
2483
2439
  },
2484
2440
  promptContent({ children }) {
2485
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(PromptContent, { children });
2441
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(PromptContent, { children });
2486
2442
  },
2487
2443
  video({ node }) {
2488
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(Video, { src: node.attrs.src });
2489
- },
2490
- table({ children }) {
2491
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(Table, { children });
2444
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(Video, { src: node.attrs.src });
2492
2445
  },
2493
2446
  figure({ node }) {
2494
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
2447
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
2495
2448
  Figure,
2496
2449
  {
2497
2450
  ...node.attrs,
@@ -2500,7 +2453,7 @@ var getNodeMapping = (getImageById) => ({
2500
2453
  );
2501
2454
  },
2502
2455
  image({ node }) {
2503
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
2456
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
2504
2457
  Figure,
2505
2458
  {
2506
2459
  ...node.attrs,
@@ -2519,7 +2472,7 @@ var getNodeMapping = (getImageById) => ({
2519
2472
  } catch (error) {
2520
2473
  console.warn("KaTeX rendering error for inline math:", error);
2521
2474
  }
2522
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
2475
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
2523
2476
  "span",
2524
2477
  {
2525
2478
  className: "react-renderer node-inlineMath",
@@ -2540,7 +2493,7 @@ var getNodeMapping = (getImageById) => ({
2540
2493
  } catch (error) {
2541
2494
  console.warn("KaTeX rendering error for block math:", error);
2542
2495
  }
2543
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)("div", { className: "react-renderer node-blockMath", children: /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
2496
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)("div", { className: "react-renderer node-blockMath", children: /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
2544
2497
  "div",
2545
2498
  {
2546
2499
  className: "tiptap-mathematics-render",
@@ -2561,7 +2514,7 @@ var getNodeMapping = (getImageById) => ({
2561
2514
  } catch (error) {
2562
2515
  console.warn("KaTeX rendering error for inline latex:", error);
2563
2516
  }
2564
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
2517
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
2565
2518
  "span",
2566
2519
  {
2567
2520
  className: "react-renderer node-inlineLatex inline-latex",
@@ -2574,33 +2527,33 @@ var getNodeMapping = (getImageById) => ({
2574
2527
  */
2575
2528
  calloutAlert({ node, children }) {
2576
2529
  const type = node.attrs.type || "info";
2577
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(Callout, { type, children });
2530
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(Callout, { type, children });
2578
2531
  },
2579
2532
  calloutTip({ node, children }) {
2580
2533
  const type = node.attrs.type || "info";
2581
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(Callout, { type, children });
2534
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(Callout, { type, children });
2582
2535
  },
2583
2536
  customQuoteV2({ children }) {
2584
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(CustomQuote, { children });
2537
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(CustomQuote, { children });
2585
2538
  },
2586
2539
  promptV2Header({ children }) {
2587
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(PromptHeader, { children });
2540
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(PromptHeader, { children });
2588
2541
  },
2589
2542
  promptV2Content({ children }) {
2590
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(PromptContent, { children });
2543
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(PromptContent, { children });
2591
2544
  }
2592
2545
  });
2593
2546
  var nodeMapping = getNodeMapping();
2594
2547
  var markMapping = {
2595
2548
  "copyable-text"({ children }) {
2596
- return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(CopyableText2, { children });
2549
+ return /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(CopyableText2, { children });
2597
2550
  }
2598
2551
  };
2599
2552
 
2600
2553
  // src/render/tiptap-render.tsx
2601
2554
  var import_github_dark = require("highlight.js/styles/github-dark.css");
2602
2555
  var import_katex_min = require("katex/dist/katex.min.css");
2603
- var import_jsx_runtime70 = require("react/jsx-runtime");
2556
+ var import_jsx_runtime69 = require("react/jsx-runtime");
2604
2557
  function renderTiptapToReact(content, getImageById) {
2605
2558
  let parsedContent;
2606
2559
  try {
@@ -2613,7 +2566,7 @@ function renderTiptapToReact(content, getImageById) {
2613
2566
  console.warn("Failed to parse Tiptap content:", error);
2614
2567
  parsedContent = { type: "doc", content: [{ type: "paragraph" }] };
2615
2568
  }
2616
- const rendered = (0, import_react3.renderToReactElement)({
2569
+ const rendered = (0, import_react2.renderToReactElement)({
2617
2570
  extensions: getRenderExtensions(),
2618
2571
  content: parsedContent,
2619
2572
  options: {
@@ -2621,7 +2574,7 @@ function renderTiptapToReact(content, getImageById) {
2621
2574
  markMapping
2622
2575
  }
2623
2576
  });
2624
- return /* @__PURE__ */ (0, import_jsx_runtime70.jsx)(
2577
+ return /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
2625
2578
  "div",
2626
2579
  {
2627
2580
  className: "tiptap",
@@ -2633,8 +2586,40 @@ function renderTiptapToReact(content, getImageById) {
2633
2586
  function TiptapRender({ content, getImageById }) {
2634
2587
  return renderTiptapToReact(content, getImageById);
2635
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
+ }
2636
2620
  // Annotate the CommonJS export names for ESM import in node:
2637
2621
  0 && (module.exports = {
2638
- TiptapRender
2622
+ TiptapRender,
2623
+ htmlToTiptapContent
2639
2624
  });
2640
2625
  //# sourceMappingURL=render.js.map