@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.mjs CHANGED
@@ -628,8 +628,9 @@ var BaseFigure = Image.extend({
628
628
  isolating: true,
629
629
  selectable: false,
630
630
  addOptions() {
631
+ const parentOptions = this.parent?.() || {};
631
632
  return {
632
- HTMLAttributes: {},
633
+ ...parentOptions,
633
634
  getImageById: void 0,
634
635
  onFigureClick: void 0
635
636
  };
@@ -1562,9 +1563,8 @@ function getRenderExtensions() {
1562
1563
  BasePromptContent,
1563
1564
  BaseVideo,
1564
1565
  BaseFigure,
1565
- // Need to update
1566
1566
  TableKit.configure({
1567
- table: { resizable: false }
1567
+ table: { resizable: false, renderWrapper: true }
1568
1568
  }),
1569
1569
  Mathematics.configure({
1570
1570
  katexOptions: {
@@ -2245,51 +2245,6 @@ var PromptContent = ({ children, isEmpty, placeholder }) => /* @__PURE__ */ jsx6
2245
2245
  }
2246
2246
  ) });
2247
2247
 
2248
- // src/extensions/views/components/table.tsx
2249
- import { useEffect, useRef, useState } from "react";
2250
- import { jsx as jsx67, jsxs as jsxs21 } from "react/jsx-runtime";
2251
- function Table({ children }) {
2252
- const wrapperRef = useRef(null);
2253
- const [undefinedColWidth, setUndefinedColWidth] = useState(void 0);
2254
- let colWidths = [];
2255
- if (Array.isArray(children) && children.length > 0) {
2256
- const firstRow = children[0];
2257
- if (firstRow?.props?.children) {
2258
- const cells = Array.isArray(firstRow.props.children) ? firstRow.props.children : [firstRow.props.children];
2259
- colWidths = cells.map((cell) => cell?.props?.node?.attrs?.colwidth?.[0]);
2260
- }
2261
- }
2262
- const definedWidths = colWidths.filter((w) => w !== void 0);
2263
- const totalDefinedWidth = definedWidths.reduce((total, width) => total + width, 0);
2264
- const undefinedCount = colWidths.filter((w) => w === void 0).length;
2265
- useEffect(() => {
2266
- if (wrapperRef.current && undefinedCount > 0) {
2267
- const containerWidth = wrapperRef.current.clientWidth;
2268
- const remainingSpace = containerWidth - totalDefinedWidth - 2;
2269
- const calculatedWidth = Math.floor(remainingSpace / undefinedCount);
2270
- setUndefinedColWidth(calculatedWidth > 0 ? calculatedWidth : void 0);
2271
- }
2272
- }, [totalDefinedWidth, undefinedCount]);
2273
- const tableWidth = undefinedCount > 0 && undefinedColWidth ? totalDefinedWidth + undefinedColWidth * undefinedCount + 2 : totalDefinedWidth > 0 ? totalDefinedWidth + 2 : void 0;
2274
- return /* @__PURE__ */ jsx67(
2275
- "div",
2276
- {
2277
- ref: wrapperRef,
2278
- className: "tableWrapper",
2279
- children: /* @__PURE__ */ jsxs21("table", { style: tableWidth ? { width: `${tableWidth}px` } : void 0, children: [
2280
- colWidths.length > 0 && /* @__PURE__ */ jsx67("colgroup", { children: colWidths.map((width, index) => /* @__PURE__ */ jsx67(
2281
- "col",
2282
- {
2283
- style: width ? { width: `${width}px` } : undefinedColWidth ? { width: `${undefinedColWidth}px` } : void 0
2284
- },
2285
- index
2286
- )) }),
2287
- /* @__PURE__ */ jsx67("tbody", { children })
2288
- ] })
2289
- }
2290
- );
2291
- }
2292
-
2293
2248
  // src/utils/detect-video-hosting.ts
2294
2249
  var VIDEO_PATTERNS = {
2295
2250
  youtube: /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=|shorts\/)?([a-zA-Z0-9_-]{11})/,
@@ -2362,22 +2317,22 @@ var detectVideoHosting = (src) => {
2362
2317
  };
2363
2318
 
2364
2319
  // src/extensions/views/components/video.tsx
2365
- import { jsx as jsx68, jsxs as jsxs22 } from "react/jsx-runtime";
2320
+ import { jsx as jsx67, jsxs as jsxs21 } from "react/jsx-runtime";
2366
2321
  var Video = ({ src, children }) => {
2367
2322
  const videoInfo = detectVideoHosting(src);
2368
2323
  if (!videoInfo?.embedUrl) {
2369
- return /* @__PURE__ */ jsxs22("div", { className: "video-node", children: [
2370
- /* @__PURE__ */ jsx68("div", { className: "video-error", children: /* @__PURE__ */ jsx68("span", { children: "Unsupported or invalid video URL" }) }),
2324
+ return /* @__PURE__ */ jsxs21("div", { className: "video-node", children: [
2325
+ /* @__PURE__ */ jsx67("div", { className: "video-error", children: /* @__PURE__ */ jsx67("span", { children: "Unsupported or invalid video URL" }) }),
2371
2326
  children
2372
2327
  ] });
2373
2328
  }
2374
- return /* @__PURE__ */ jsxs22(
2329
+ return /* @__PURE__ */ jsxs21(
2375
2330
  "div",
2376
2331
  {
2377
2332
  className: "video-node",
2378
2333
  "data-video": "",
2379
2334
  children: [
2380
- /* @__PURE__ */ jsx68("div", { className: "video-player-wrapper", children: /* @__PURE__ */ jsx68(
2335
+ /* @__PURE__ */ jsx67("div", { className: "video-player-wrapper", children: /* @__PURE__ */ jsx67(
2381
2336
  "iframe",
2382
2337
  {
2383
2338
  className: "video-iframe",
@@ -2394,10 +2349,10 @@ var Video = ({ src, children }) => {
2394
2349
  };
2395
2350
 
2396
2351
  // src/render/static-renderer-config.tsx
2397
- import { jsx as jsx69 } from "react/jsx-runtime";
2352
+ import { jsx as jsx68 } from "react/jsx-runtime";
2398
2353
  var getNodeMapping = (getImageById) => ({
2399
2354
  callout({ node, children }) {
2400
- return /* @__PURE__ */ jsx69(Callout, { ...node.attrs, children });
2355
+ return /* @__PURE__ */ jsx68(Callout, { ...node.attrs, children });
2401
2356
  },
2402
2357
  codeBlock({ node, children }) {
2403
2358
  const language = node.attrs.language || "";
@@ -2421,41 +2376,38 @@ var getNodeMapping = (getImageById) => ({
2421
2376
  console.warn(`Failed to highlight code for language "${language}":`, error);
2422
2377
  highlightedHtml = codeText.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
2423
2378
  }
2424
- return /* @__PURE__ */ jsx69(
2379
+ return /* @__PURE__ */ jsx68(
2425
2380
  CodeBlock,
2426
2381
  {
2427
2382
  language,
2428
2383
  isEditable: false,
2429
- children: /* @__PURE__ */ jsx69("code", { dangerouslySetInnerHTML: { __html: highlightedHtml } })
2384
+ children: /* @__PURE__ */ jsx68("code", { dangerouslySetInnerHTML: { __html: highlightedHtml } })
2430
2385
  }
2431
2386
  );
2432
2387
  },
2433
2388
  customQuote({ children }) {
2434
- return /* @__PURE__ */ jsx69(CustomQuote, { children });
2389
+ return /* @__PURE__ */ jsx68(CustomQuote, { children });
2435
2390
  },
2436
2391
  customQuoteText({ children }) {
2437
- return /* @__PURE__ */ jsx69(CustomQuoteText, { children });
2392
+ return /* @__PURE__ */ jsx68(CustomQuoteText, { children });
2438
2393
  },
2439
2394
  customQuoteAuthor({ children }) {
2440
- return /* @__PURE__ */ jsx69(CustomQuoteAuthor, { children });
2395
+ return /* @__PURE__ */ jsx68(CustomQuoteAuthor, { children });
2441
2396
  },
2442
2397
  customQuoteSign({ children }) {
2443
- return /* @__PURE__ */ jsx69(CustomQuoteSign, { children });
2398
+ return /* @__PURE__ */ jsx68(CustomQuoteSign, { children });
2444
2399
  },
2445
2400
  promptHeader({ children }) {
2446
- return /* @__PURE__ */ jsx69(PromptHeader, { children });
2401
+ return /* @__PURE__ */ jsx68(PromptHeader, { children });
2447
2402
  },
2448
2403
  promptContent({ children }) {
2449
- return /* @__PURE__ */ jsx69(PromptContent, { children });
2404
+ return /* @__PURE__ */ jsx68(PromptContent, { children });
2450
2405
  },
2451
2406
  video({ node }) {
2452
- return /* @__PURE__ */ jsx69(Video, { src: node.attrs.src });
2453
- },
2454
- table({ children }) {
2455
- return /* @__PURE__ */ jsx69(Table, { children });
2407
+ return /* @__PURE__ */ jsx68(Video, { src: node.attrs.src });
2456
2408
  },
2457
2409
  figure({ node }) {
2458
- return /* @__PURE__ */ jsx69(
2410
+ return /* @__PURE__ */ jsx68(
2459
2411
  Figure,
2460
2412
  {
2461
2413
  ...node.attrs,
@@ -2464,7 +2416,7 @@ var getNodeMapping = (getImageById) => ({
2464
2416
  );
2465
2417
  },
2466
2418
  image({ node }) {
2467
- return /* @__PURE__ */ jsx69(
2419
+ return /* @__PURE__ */ jsx68(
2468
2420
  Figure,
2469
2421
  {
2470
2422
  ...node.attrs,
@@ -2483,7 +2435,7 @@ var getNodeMapping = (getImageById) => ({
2483
2435
  } catch (error) {
2484
2436
  console.warn("KaTeX rendering error for inline math:", error);
2485
2437
  }
2486
- return /* @__PURE__ */ jsx69(
2438
+ return /* @__PURE__ */ jsx68(
2487
2439
  "span",
2488
2440
  {
2489
2441
  className: "react-renderer node-inlineMath",
@@ -2504,7 +2456,7 @@ var getNodeMapping = (getImageById) => ({
2504
2456
  } catch (error) {
2505
2457
  console.warn("KaTeX rendering error for block math:", error);
2506
2458
  }
2507
- return /* @__PURE__ */ jsx69("div", { className: "react-renderer node-blockMath", children: /* @__PURE__ */ jsx69(
2459
+ return /* @__PURE__ */ jsx68("div", { className: "react-renderer node-blockMath", children: /* @__PURE__ */ jsx68(
2508
2460
  "div",
2509
2461
  {
2510
2462
  className: "tiptap-mathematics-render",
@@ -2525,7 +2477,7 @@ var getNodeMapping = (getImageById) => ({
2525
2477
  } catch (error) {
2526
2478
  console.warn("KaTeX rendering error for inline latex:", error);
2527
2479
  }
2528
- return /* @__PURE__ */ jsx69(
2480
+ return /* @__PURE__ */ jsx68(
2529
2481
  "span",
2530
2482
  {
2531
2483
  className: "react-renderer node-inlineLatex inline-latex",
@@ -2538,33 +2490,33 @@ var getNodeMapping = (getImageById) => ({
2538
2490
  */
2539
2491
  calloutAlert({ node, children }) {
2540
2492
  const type = node.attrs.type || "info";
2541
- return /* @__PURE__ */ jsx69(Callout, { type, children });
2493
+ return /* @__PURE__ */ jsx68(Callout, { type, children });
2542
2494
  },
2543
2495
  calloutTip({ node, children }) {
2544
2496
  const type = node.attrs.type || "info";
2545
- return /* @__PURE__ */ jsx69(Callout, { type, children });
2497
+ return /* @__PURE__ */ jsx68(Callout, { type, children });
2546
2498
  },
2547
2499
  customQuoteV2({ children }) {
2548
- return /* @__PURE__ */ jsx69(CustomQuote, { children });
2500
+ return /* @__PURE__ */ jsx68(CustomQuote, { children });
2549
2501
  },
2550
2502
  promptV2Header({ children }) {
2551
- return /* @__PURE__ */ jsx69(PromptHeader, { children });
2503
+ return /* @__PURE__ */ jsx68(PromptHeader, { children });
2552
2504
  },
2553
2505
  promptV2Content({ children }) {
2554
- return /* @__PURE__ */ jsx69(PromptContent, { children });
2506
+ return /* @__PURE__ */ jsx68(PromptContent, { children });
2555
2507
  }
2556
2508
  });
2557
2509
  var nodeMapping = getNodeMapping();
2558
2510
  var markMapping = {
2559
2511
  "copyable-text"({ children }) {
2560
- return /* @__PURE__ */ jsx69(CopyableText2, { children });
2512
+ return /* @__PURE__ */ jsx68(CopyableText2, { children });
2561
2513
  }
2562
2514
  };
2563
2515
 
2564
2516
  // src/render/tiptap-render.tsx
2565
2517
  import "highlight.js/styles/github-dark.css";
2566
2518
  import "katex/dist/katex.min.css";
2567
- import { jsx as jsx70 } from "react/jsx-runtime";
2519
+ import { jsx as jsx69 } from "react/jsx-runtime";
2568
2520
  function renderTiptapToReact(content, getImageById) {
2569
2521
  let parsedContent;
2570
2522
  try {
@@ -2585,7 +2537,7 @@ function renderTiptapToReact(content, getImageById) {
2585
2537
  markMapping
2586
2538
  }
2587
2539
  });
2588
- return /* @__PURE__ */ jsx70(
2540
+ return /* @__PURE__ */ jsx69(
2589
2541
  "div",
2590
2542
  {
2591
2543
  className: "tiptap",
@@ -2597,7 +2549,39 @@ function renderTiptapToReact(content, getImageById) {
2597
2549
  function TiptapRender({ content, getImageById }) {
2598
2550
  return renderTiptapToReact(content, getImageById);
2599
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
+ }
2600
2583
  export {
2601
- TiptapRender
2584
+ TiptapRender,
2585
+ htmlToTiptapContent
2602
2586
  };
2603
2587
  //# sourceMappingURL=render.mjs.map