@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/editor.js CHANGED
@@ -30,15 +30,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/editor/index.ts
31
31
  var editor_exports = {};
32
32
  __export(editor_exports, {
33
- Tiptap: () => Tiptap
33
+ Tiptap: () => Tiptap,
34
+ htmlToTiptapContent: () => htmlToTiptapContent
34
35
  });
35
36
  module.exports = __toCommonJS(editor_exports);
36
37
 
37
38
  // src/editor/editor.tsx
38
- var import_react37 = require("react");
39
+ var import_react36 = require("react");
39
40
  var import_state6 = require("@tiptap/pm/state");
40
41
  var import_model = require("@tiptap/pm/model");
41
- var import_react38 = require("@tiptap/react");
42
+ var import_react37 = require("@tiptap/react");
42
43
  var import_menus = require("@tiptap/react/menus");
43
44
  var import_github_dark = require("highlight.js/styles/github-dark.css");
44
45
  var import_katex_min = require("katex/dist/katex.min.css");
@@ -1928,14 +1929,39 @@ var ImageDialog = ({
1928
1929
  const [dragActive, setDragActive] = (0, import_react13.useState)(false);
1929
1930
  const inputRef = (0, import_react13.useRef)(null);
1930
1931
  const resolvedInitialUrl = initialAttrs ? resolveImageSrc({ fileId: initialAttrs.fileId, src: initialAttrs.src }, { getImageById }) : "";
1932
+ const getConstrainedDimensions = () => {
1933
+ if (!initialAttrs?.width || !initialAttrs?.height) {
1934
+ return { width: 0, height: 0 };
1935
+ }
1936
+ let maxWidth;
1937
+ try {
1938
+ const editorElement = document.querySelector(".tiptap-content-wrapper");
1939
+ if (editorElement && editorElement.clientWidth > 0) {
1940
+ maxWidth = editorElement.clientWidth - 32;
1941
+ }
1942
+ } catch {
1943
+ }
1944
+ if (maxWidth && initialAttrs.width > maxWidth) {
1945
+ const aspectRatio = initialAttrs.height / initialAttrs.width;
1946
+ return {
1947
+ width: maxWidth,
1948
+ height: Math.round(maxWidth * aspectRatio)
1949
+ };
1950
+ }
1951
+ return {
1952
+ width: initialAttrs.width,
1953
+ height: initialAttrs.height
1954
+ };
1955
+ };
1956
+ const constrainedDimensions = getConstrainedDimensions();
1931
1957
  const [formState, setFormState] = (0, import_react13.useState)({
1932
1958
  file: null,
1933
1959
  title: initialAttrs?.title || "",
1934
1960
  alt: initialAttrs?.alt || "",
1935
1961
  caption: initialAttrs?.caption || "",
1936
1962
  fileUrl: resolvedInitialUrl,
1937
- width: initialAttrs?.width || 0,
1938
- height: initialAttrs?.height || 0
1963
+ width: constrainedDimensions.width,
1964
+ height: constrainedDimensions.height
1939
1965
  });
1940
1966
  const handleSelectFile = (file) => {
1941
1967
  if (!file) return;
@@ -1943,15 +1969,34 @@ var ImageDialog = ({
1943
1969
  const img = new Image();
1944
1970
  img.src = imageUrl;
1945
1971
  img.onload = () => {
1946
- const { width, height } = img;
1972
+ const naturalWidth = img.width;
1973
+ const naturalHeight = img.height;
1974
+ const naturalAspectRatio = naturalHeight / naturalWidth;
1975
+ let maxWidth;
1976
+ try {
1977
+ const editorElement = document.querySelector(".tiptap-content-wrapper");
1978
+ if (editorElement && editorElement.clientWidth > 0) {
1979
+ maxWidth = editorElement.clientWidth - 32;
1980
+ }
1981
+ } catch {
1982
+ }
1983
+ let finalWidth;
1984
+ let finalHeight;
1985
+ if (maxWidth && naturalWidth > maxWidth) {
1986
+ finalWidth = maxWidth;
1987
+ finalHeight = Math.round(maxWidth * naturalAspectRatio);
1988
+ } else {
1989
+ finalWidth = naturalWidth;
1990
+ finalHeight = naturalHeight;
1991
+ }
1947
1992
  setFormState((prev) => ({
1948
1993
  ...prev,
1949
1994
  file,
1950
1995
  fileUrl: imageUrl,
1951
1996
  title: file.name,
1952
1997
  alt: file.name,
1953
- width,
1954
- height
1998
+ width: finalWidth,
1999
+ height: finalHeight
1955
2000
  }));
1956
2001
  };
1957
2002
  };
@@ -2019,7 +2064,9 @@ var ImageDialog = ({
2019
2064
  onImageEdit({
2020
2065
  alt: formState.alt,
2021
2066
  title: formState.title,
2022
- caption: formState.caption
2067
+ caption: formState.caption,
2068
+ width: formState.width || void 0,
2069
+ height: formState.height || void 0
2023
2070
  });
2024
2071
  handleClose();
2025
2072
  };
@@ -2657,7 +2704,7 @@ var import_extension_mathematics = require("@tiptap/extension-mathematics");
2657
2704
  var import_extension_table = require("@tiptap/extension-table");
2658
2705
 
2659
2706
  // src/extensions/editor/callout.ts
2660
- var import_react29 = require("@tiptap/react");
2707
+ var import_react28 = require("@tiptap/react");
2661
2708
 
2662
2709
  // src/utils/handle-exit-node.ts
2663
2710
  var import_state = require("@tiptap/pm/state");
@@ -3258,8 +3305,9 @@ var BaseFigure = import_extension_image.default.extend({
3258
3305
  isolating: true,
3259
3306
  selectable: false,
3260
3307
  addOptions() {
3308
+ const parentOptions = this.parent?.() || {};
3261
3309
  return {
3262
- HTMLAttributes: {},
3310
+ ...parentOptions,
3263
3311
  getImageById: void 0,
3264
3312
  onFigureClick: void 0
3265
3313
  };
@@ -3792,8 +3840,8 @@ var BaseLegacyFigure = import_extension_image2.default.extend({
3792
3840
  });
3793
3841
 
3794
3842
  // src/extensions/views/node-views/callout.tsx
3795
- var import_react20 = require("@tiptap/react");
3796
- var import_react21 = require("react");
3843
+ var import_react19 = require("@tiptap/react");
3844
+ var import_react20 = require("react");
3797
3845
 
3798
3846
  // src/icons/color/TiptapCalloutError.tsx
3799
3847
  var import_jsx_runtime71 = require("react/jsx-runtime");
@@ -4382,27 +4430,23 @@ var PromptContent = ({ children, isEmpty, placeholder }) => /* @__PURE__ */ (0,
4382
4430
  }
4383
4431
  ) });
4384
4432
 
4385
- // src/extensions/views/components/table.tsx
4386
- var import_react18 = require("react");
4387
- var import_jsx_runtime82 = require("react/jsx-runtime");
4388
-
4389
4433
  // src/extensions/views/components/video.tsx
4390
- var import_jsx_runtime83 = require("react/jsx-runtime");
4434
+ var import_jsx_runtime82 = require("react/jsx-runtime");
4391
4435
  var Video = ({ src, children }) => {
4392
4436
  const videoInfo = detectVideoHosting(src);
4393
4437
  if (!videoInfo?.embedUrl) {
4394
- return /* @__PURE__ */ (0, import_jsx_runtime83.jsxs)("div", { className: "video-node", children: [
4395
- /* @__PURE__ */ (0, import_jsx_runtime83.jsx)("div", { className: "video-error", children: /* @__PURE__ */ (0, import_jsx_runtime83.jsx)("span", { children: "Unsupported or invalid video URL" }) }),
4438
+ return /* @__PURE__ */ (0, import_jsx_runtime82.jsxs)("div", { className: "video-node", children: [
4439
+ /* @__PURE__ */ (0, import_jsx_runtime82.jsx)("div", { className: "video-error", children: /* @__PURE__ */ (0, import_jsx_runtime82.jsx)("span", { children: "Unsupported or invalid video URL" }) }),
4396
4440
  children
4397
4441
  ] });
4398
4442
  }
4399
- return /* @__PURE__ */ (0, import_jsx_runtime83.jsxs)(
4443
+ return /* @__PURE__ */ (0, import_jsx_runtime82.jsxs)(
4400
4444
  "div",
4401
4445
  {
4402
4446
  className: "video-node",
4403
4447
  "data-video": "",
4404
4448
  children: [
4405
- /* @__PURE__ */ (0, import_jsx_runtime83.jsx)("div", { className: "video-player-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(
4449
+ /* @__PURE__ */ (0, import_jsx_runtime82.jsx)("div", { className: "video-player-wrapper", children: /* @__PURE__ */ (0, import_jsx_runtime82.jsx)(
4406
4450
  "iframe",
4407
4451
  {
4408
4452
  className: "video-iframe",
@@ -4419,13 +4463,13 @@ var Video = ({ src, children }) => {
4419
4463
  };
4420
4464
 
4421
4465
  // src/editor/controls/emoji-picker.tsx
4422
- var import_react19 = require("react");
4466
+ var import_react18 = require("react");
4423
4467
  var import_emoji_picker_react = __toESM(require("emoji-picker-react"));
4424
- var import_jsx_runtime84 = require("react/jsx-runtime");
4468
+ var import_jsx_runtime83 = require("react/jsx-runtime");
4425
4469
  var EmojiPickerComponent = ({ isOpen, onClose, onEmojiSelect }) => {
4426
- const pickerRef = (0, import_react19.useRef)(null);
4470
+ const pickerRef = (0, import_react18.useRef)(null);
4427
4471
  const translations2 = useTiptapTranslations();
4428
- (0, import_react19.useEffect)(() => {
4472
+ (0, import_react18.useEffect)(() => {
4429
4473
  const handleClickOutside = (event) => {
4430
4474
  if (pickerRef.current && !pickerRef.current.contains(event.target)) {
4431
4475
  onClose();
@@ -4439,12 +4483,12 @@ var EmojiPickerComponent = ({ isOpen, onClose, onEmojiSelect }) => {
4439
4483
  };
4440
4484
  }, [isOpen, onClose]);
4441
4485
  if (!isOpen) return null;
4442
- return /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(
4486
+ return /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(
4443
4487
  "div",
4444
4488
  {
4445
4489
  ref: pickerRef,
4446
4490
  className: "tiptap__emoji-picker-wrapper",
4447
- children: /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(
4491
+ children: /* @__PURE__ */ (0, import_jsx_runtime83.jsx)(
4448
4492
  import_emoji_picker_react.default,
4449
4493
  {
4450
4494
  skinTonesDisabled: true,
@@ -4469,12 +4513,12 @@ var EmojiPickerComponent = ({ isOpen, onClose, onEmojiSelect }) => {
4469
4513
  };
4470
4514
 
4471
4515
  // src/extensions/views/node-views/callout.tsx
4472
- var import_jsx_runtime85 = require("react/jsx-runtime");
4516
+ var import_jsx_runtime84 = require("react/jsx-runtime");
4473
4517
  var CalloutView = (props) => {
4474
4518
  const type = props.node.attrs.type || "info";
4475
4519
  const bgColor = props.node.attrs.bgColor;
4476
4520
  const emoji = props.node.attrs.emoji;
4477
- const [showEmojiPicker, setShowEmojiPicker] = (0, import_react21.useState)(false);
4521
+ const [showEmojiPicker, setShowEmojiPicker] = (0, import_react20.useState)(false);
4478
4522
  const handleIconClick = (e) => {
4479
4523
  e.preventDefault();
4480
4524
  e.stopPropagation();
@@ -4484,23 +4528,23 @@ var CalloutView = (props) => {
4484
4528
  props.updateAttributes({ emoji: newEmoji });
4485
4529
  setShowEmojiPicker(false);
4486
4530
  };
4487
- return /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(import_react20.NodeViewWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
4531
+ return /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(import_react19.NodeViewWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(
4488
4532
  Callout,
4489
4533
  {
4490
4534
  type,
4491
4535
  bgColor,
4492
4536
  emoji,
4493
- iconWrapper: (icon) => /* @__PURE__ */ (0, import_jsx_runtime85.jsxs)("div", { className: "callout-icon-wrapper", children: [
4494
- /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
4537
+ iconWrapper: (icon) => /* @__PURE__ */ (0, import_jsx_runtime84.jsxs)("div", { className: "callout-icon-wrapper", children: [
4538
+ /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(
4495
4539
  "button",
4496
4540
  {
4497
4541
  className: "callout-icon-button",
4498
4542
  onClick: handleIconClick,
4499
4543
  type: "button",
4500
- children: /* @__PURE__ */ (0, import_jsx_runtime85.jsx)("div", { className: "callout-icon", children: icon })
4544
+ children: /* @__PURE__ */ (0, import_jsx_runtime84.jsx)("div", { className: "callout-icon", children: icon })
4501
4545
  }
4502
4546
  ),
4503
- /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
4547
+ /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(
4504
4548
  EmojiPickerComponent,
4505
4549
  {
4506
4550
  isOpen: showEmojiPicker,
@@ -4509,101 +4553,101 @@ var CalloutView = (props) => {
4509
4553
  }
4510
4554
  )
4511
4555
  ] }),
4512
- children: /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(import_react20.NodeViewContent, { as: "div" })
4556
+ children: /* @__PURE__ */ (0, import_jsx_runtime84.jsx)(import_react19.NodeViewContent, { as: "div" })
4513
4557
  }
4514
4558
  ) });
4515
4559
  };
4516
4560
 
4517
4561
  // src/extensions/views/node-views/code-block.tsx
4518
- var import_react22 = require("react");
4519
- var import_react23 = require("@tiptap/react");
4520
- var import_jsx_runtime86 = require("react/jsx-runtime");
4562
+ var import_react21 = require("react");
4563
+ var import_react22 = require("@tiptap/react");
4564
+ var import_jsx_runtime85 = require("react/jsx-runtime");
4521
4565
  var CodeBlockView = (props) => {
4522
- const [selectedLanguage, setSelectedLanguage] = (0, import_react22.useState)(props.node.attrs.language ?? "");
4566
+ const [selectedLanguage, setSelectedLanguage] = (0, import_react21.useState)(props.node.attrs.language ?? "");
4523
4567
  const translations2 = useTiptapTranslations();
4524
4568
  const handleLanguageChange = (language) => {
4525
4569
  props.updateAttributes({ language });
4526
4570
  setSelectedLanguage(language);
4527
4571
  };
4528
- return /* @__PURE__ */ (0, import_jsx_runtime86.jsx)(import_react23.NodeViewWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime86.jsx)(
4572
+ return /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(import_react22.NodeViewWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(
4529
4573
  CodeBlock,
4530
4574
  {
4531
4575
  language: selectedLanguage,
4532
4576
  isEditable: props.editor.isEditable,
4533
4577
  onLanguageChange: handleLanguageChange,
4534
4578
  translations: translations2,
4535
- children: /* @__PURE__ */ (0, import_jsx_runtime86.jsx)(import_react23.NodeViewContent, {})
4579
+ children: /* @__PURE__ */ (0, import_jsx_runtime85.jsx)(import_react22.NodeViewContent, {})
4536
4580
  }
4537
4581
  ) });
4538
4582
  };
4539
4583
 
4540
4584
  // src/extensions/views/node-views/copyable-text.tsx
4541
- var import_react24 = require("@tiptap/react");
4542
- var import_jsx_runtime87 = require("react/jsx-runtime");
4585
+ var import_react23 = require("@tiptap/react");
4586
+ var import_jsx_runtime86 = require("react/jsx-runtime");
4543
4587
  var CopyableTextView = () => {
4544
- return /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(CopyableText2, { children: /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(import_react24.MarkViewContent, {}) });
4588
+ return /* @__PURE__ */ (0, import_jsx_runtime86.jsx)(CopyableText2, { children: /* @__PURE__ */ (0, import_jsx_runtime86.jsx)(import_react23.MarkViewContent, {}) });
4545
4589
  };
4546
4590
 
4547
4591
  // src/extensions/views/node-views/custom-quote.tsx
4548
- var import_react25 = require("@tiptap/react");
4549
- var import_jsx_runtime88 = require("react/jsx-runtime");
4592
+ var import_react24 = require("@tiptap/react");
4593
+ var import_jsx_runtime87 = require("react/jsx-runtime");
4550
4594
  var CustomQuoteView = () => {
4551
- return /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(import_react25.NodeViewWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(CustomQuote, { children: /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(import_react25.NodeViewContent, {}) }) });
4595
+ return /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(import_react24.NodeViewWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(CustomQuote, { children: /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(import_react24.NodeViewContent, {}) }) });
4552
4596
  };
4553
4597
  var CustomQuoteTextView = (props) => {
4554
4598
  const isEmpty = !props.node.content.size;
4555
4599
  const translations2 = useTiptapTranslations();
4556
- return /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(import_react25.NodeViewWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(
4600
+ return /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(import_react24.NodeViewWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(
4557
4601
  CustomQuoteText,
4558
4602
  {
4559
4603
  isEmpty,
4560
4604
  placeholder: translations2.customQuote.textPlaceholder,
4561
- children: /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(import_react25.NodeViewContent, { className: isEmpty ? "is-empty" : "" })
4605
+ children: /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(import_react24.NodeViewContent, { className: isEmpty ? "is-empty" : "" })
4562
4606
  }
4563
4607
  ) });
4564
4608
  };
4565
4609
  var CustomQuoteAuthorView = (props) => {
4566
4610
  const isEmpty = !props.node.content.size;
4567
4611
  const translations2 = useTiptapTranslations();
4568
- return /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(import_react25.NodeViewWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(
4612
+ return /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(import_react24.NodeViewWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(
4569
4613
  CustomQuoteAuthor,
4570
4614
  {
4571
4615
  isEmpty,
4572
4616
  placeholder: translations2.customQuote.authorPlaceholder,
4573
- children: /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(import_react25.NodeViewContent, { className: isEmpty ? "is-empty" : "" })
4617
+ children: /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(import_react24.NodeViewContent, { className: isEmpty ? "is-empty" : "" })
4574
4618
  }
4575
4619
  ) });
4576
4620
  };
4577
4621
  var CustomQuoteSignView = (props) => {
4578
4622
  const isEmpty = !props.node.content.size;
4579
4623
  const translations2 = useTiptapTranslations();
4580
- return /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(import_react25.NodeViewWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(
4624
+ return /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(import_react24.NodeViewWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(
4581
4625
  CustomQuoteSign,
4582
4626
  {
4583
4627
  isEmpty,
4584
4628
  placeholder: translations2.customQuote.signPlaceholder,
4585
- children: /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(import_react25.NodeViewContent, { className: isEmpty ? "is-empty" : "" })
4629
+ children: /* @__PURE__ */ (0, import_jsx_runtime87.jsx)(import_react24.NodeViewContent, { className: isEmpty ? "is-empty" : "" })
4586
4630
  }
4587
4631
  ) });
4588
4632
  };
4589
4633
 
4590
4634
  // src/extensions/views/node-views/figure.tsx
4591
- var import_react26 = require("@tiptap/react");
4592
- var import_jsx_runtime89 = require("react/jsx-runtime");
4635
+ var import_react25 = require("@tiptap/react");
4636
+ var import_jsx_runtime88 = require("react/jsx-runtime");
4593
4637
  var FigureView = ({ node, getPos, editor }) => {
4594
- const { fileId, src, alt, title, caption, width, height, storageKey } = node.attrs;
4638
+ const { fileId, src, alt, title, caption, width, height } = node.attrs;
4595
4639
  const imageExtension = editor.extensionManager.extensions.find((ext) => ext.name === "image");
4596
4640
  const getImageById = imageExtension?.options.getImageById;
4597
4641
  const onFigureClick = imageExtension?.options.onFigureClick;
4598
4642
  const handleEditClick = () => {
4599
4643
  onFigureClick?.(node.attrs, getPos());
4600
4644
  };
4601
- return /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(
4602
- import_react26.NodeViewWrapper,
4645
+ return /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(
4646
+ import_react25.NodeViewWrapper,
4603
4647
  {
4604
4648
  className: "figure-node-view",
4605
4649
  "data-drag-handle": true,
4606
- children: /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(
4650
+ children: /* @__PURE__ */ (0, import_jsx_runtime88.jsx)(
4607
4651
  Figure,
4608
4652
  {
4609
4653
  fileId,
@@ -4623,40 +4667,40 @@ var FigureView = ({ node, getPos, editor }) => {
4623
4667
  };
4624
4668
 
4625
4669
  // src/extensions/views/node-views/prompt.tsx
4626
- var import_react27 = require("@tiptap/react");
4627
- var import_jsx_runtime90 = require("react/jsx-runtime");
4670
+ var import_react26 = require("@tiptap/react");
4671
+ var import_jsx_runtime89 = require("react/jsx-runtime");
4628
4672
  var PromptHeaderView = (props) => {
4629
4673
  const isEmpty = !props.node.content.size;
4630
4674
  const translations2 = useTiptapTranslations();
4631
- return /* @__PURE__ */ (0, import_jsx_runtime90.jsx)(import_react27.NodeViewWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime90.jsx)(
4675
+ return /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(import_react26.NodeViewWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(
4632
4676
  PromptHeader,
4633
4677
  {
4634
4678
  isEmpty,
4635
4679
  placeholder: translations2.prompt.headerPlaceholder,
4636
- children: /* @__PURE__ */ (0, import_jsx_runtime90.jsx)(import_react27.NodeViewContent, { className: isEmpty ? "is-empty" : "" })
4680
+ children: /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(import_react26.NodeViewContent, { className: isEmpty ? "is-empty" : "" })
4637
4681
  }
4638
4682
  ) });
4639
4683
  };
4640
4684
  var PromptContentView = (props) => {
4641
4685
  const isEmpty = !props.node.content.size;
4642
4686
  const translations2 = useTiptapTranslations();
4643
- return /* @__PURE__ */ (0, import_jsx_runtime90.jsx)(import_react27.NodeViewWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime90.jsx)(
4687
+ return /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(import_react26.NodeViewWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(
4644
4688
  PromptContent,
4645
4689
  {
4646
4690
  isEmpty,
4647
4691
  placeholder: translations2.prompt.contentPlaceholder,
4648
- children: /* @__PURE__ */ (0, import_jsx_runtime90.jsx)(import_react27.NodeViewContent, { className: isEmpty ? "is-empty" : "" })
4692
+ children: /* @__PURE__ */ (0, import_jsx_runtime89.jsx)(import_react26.NodeViewContent, { className: isEmpty ? "is-empty" : "" })
4649
4693
  }
4650
4694
  ) });
4651
4695
  };
4652
4696
 
4653
4697
  // src/extensions/views/node-views/video.tsx
4654
- var import_react28 = require("@tiptap/react");
4655
- var import_jsx_runtime91 = require("react/jsx-runtime");
4698
+ var import_react27 = require("@tiptap/react");
4699
+ var import_jsx_runtime90 = require("react/jsx-runtime");
4656
4700
  var VideoView = (props) => {
4657
4701
  const { src } = props.node.attrs;
4658
- return /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(import_react28.NodeViewWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(Video, { src, children: /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(
4659
- import_react28.NodeViewContent,
4702
+ return /* @__PURE__ */ (0, import_jsx_runtime90.jsx)(import_react27.NodeViewWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime90.jsx)(Video, { src, children: /* @__PURE__ */ (0, import_jsx_runtime90.jsx)(
4703
+ import_react27.NodeViewContent,
4660
4704
  {
4661
4705
  as: "div",
4662
4706
  className: "video-content"
@@ -4667,66 +4711,66 @@ var VideoView = (props) => {
4667
4711
  // src/extensions/editor/callout.ts
4668
4712
  var Callout2 = BaseCallout.extend({
4669
4713
  addNodeView() {
4670
- return (0, import_react29.ReactNodeViewRenderer)(CalloutView);
4714
+ return (0, import_react28.ReactNodeViewRenderer)(CalloutView);
4671
4715
  }
4672
4716
  });
4673
4717
  var LegacyBookAlert = BaseLegacyBookAlert.extend({
4674
4718
  addNodeView() {
4675
- return (0, import_react29.ReactNodeViewRenderer)(CalloutView);
4719
+ return (0, import_react28.ReactNodeViewRenderer)(CalloutView);
4676
4720
  }
4677
4721
  });
4678
4722
  var LegacyBookTip = BaseLegacyBookTip.extend({
4679
4723
  addNodeView() {
4680
- return (0, import_react29.ReactNodeViewRenderer)(CalloutView);
4724
+ return (0, import_react28.ReactNodeViewRenderer)(CalloutView);
4681
4725
  }
4682
4726
  });
4683
4727
 
4684
4728
  // src/extensions/editor/code-block.ts
4685
- var import_react30 = require("@tiptap/react");
4729
+ var import_react29 = require("@tiptap/react");
4686
4730
  var CodeBlock2 = BaseCodeBlock.extend({
4687
4731
  addNodeView() {
4688
- return (0, import_react30.ReactNodeViewRenderer)(CodeBlockView);
4732
+ return (0, import_react29.ReactNodeViewRenderer)(CodeBlockView);
4689
4733
  }
4690
4734
  });
4691
4735
 
4692
4736
  // src/extensions/editor/custom-quote.ts
4693
- var import_react31 = require("@tiptap/react");
4737
+ var import_react30 = require("@tiptap/react");
4694
4738
  var CustomQuote2 = BaseCustomQuote.extend({
4695
4739
  addNodeView() {
4696
- return (0, import_react31.ReactNodeViewRenderer)(CustomQuoteView);
4740
+ return (0, import_react30.ReactNodeViewRenderer)(CustomQuoteView);
4697
4741
  }
4698
4742
  });
4699
4743
  var CustomQuoteText2 = BaseCustomQuoteText.extend({
4700
4744
  addNodeView() {
4701
- return (0, import_react31.ReactNodeViewRenderer)(CustomQuoteTextView);
4745
+ return (0, import_react30.ReactNodeViewRenderer)(CustomQuoteTextView);
4702
4746
  }
4703
4747
  });
4704
4748
  var CustomQuoteAuthor2 = BaseCustomQuoteAuthor.extend({
4705
4749
  addNodeView() {
4706
- return (0, import_react31.ReactNodeViewRenderer)(CustomQuoteAuthorView);
4750
+ return (0, import_react30.ReactNodeViewRenderer)(CustomQuoteAuthorView);
4707
4751
  }
4708
4752
  });
4709
4753
  var CustomQuoteSign2 = BaseCustomQuoteSign.extend({
4710
4754
  addNodeView() {
4711
- return (0, import_react31.ReactNodeViewRenderer)(CustomQuoteSignView);
4755
+ return (0, import_react30.ReactNodeViewRenderer)(CustomQuoteSignView);
4712
4756
  }
4713
4757
  });
4714
4758
  var LegacySEQuote = BaseLegacySEQuote.extend({
4715
4759
  addNodeView() {
4716
- return (0, import_react31.ReactNodeViewRenderer)(CustomQuoteView);
4760
+ return (0, import_react30.ReactNodeViewRenderer)(CustomQuoteView);
4717
4761
  }
4718
4762
  });
4719
4763
 
4720
4764
  // src/extensions/editor/video.ts
4721
- var import_react32 = require("@tiptap/react");
4765
+ var import_react31 = require("@tiptap/react");
4722
4766
  var Video2 = BaseVideo.extend({
4723
4767
  addNodeView() {
4724
- return (0, import_react32.ReactNodeViewRenderer)(VideoView);
4768
+ return (0, import_react31.ReactNodeViewRenderer)(VideoView);
4725
4769
  }
4726
4770
  });
4727
4771
  var LegacyYouTube = BaseLegacyYouTube.extend({
4728
4772
  addNodeView() {
4729
- return (0, import_react32.ReactNodeViewRenderer)(VideoView);
4773
+ return (0, import_react31.ReactNodeViewRenderer)(VideoView);
4730
4774
  }
4731
4775
  });
4732
4776
 
@@ -5142,46 +5186,209 @@ function getSharedExtensions() {
5142
5186
  }
5143
5187
 
5144
5188
  // src/extensions/editor/copyable-text.ts
5145
- var import_react33 = require("@tiptap/react");
5189
+ var import_react32 = require("@tiptap/react");
5146
5190
  var CopyableText3 = CopyableText.extend({
5147
5191
  addMarkView() {
5148
- return (0, import_react33.ReactMarkViewRenderer)(CopyableTextView);
5192
+ return (0, import_react32.ReactMarkViewRenderer)(CopyableTextView);
5149
5193
  }
5150
5194
  });
5151
5195
 
5152
5196
  // src/extensions/editor/prompt.ts
5153
- var import_react34 = require("@tiptap/react");
5197
+ var import_react33 = require("@tiptap/react");
5154
5198
  var PromptHeader2 = BasePromptHeader.extend({
5155
5199
  addNodeView() {
5156
- return (0, import_react34.ReactNodeViewRenderer)(PromptHeaderView);
5200
+ return (0, import_react33.ReactNodeViewRenderer)(PromptHeaderView);
5157
5201
  }
5158
5202
  });
5159
5203
  var PromptContent2 = BasePromptContent.extend({
5160
5204
  addNodeView() {
5161
- return (0, import_react34.ReactNodeViewRenderer)(PromptContentView);
5205
+ return (0, import_react33.ReactNodeViewRenderer)(PromptContentView);
5162
5206
  }
5163
5207
  });
5164
5208
  var LegacyPromptSEHeader = BaseLegacyPromptSEHeader.extend({
5165
5209
  addNodeView() {
5166
- return (0, import_react34.ReactNodeViewRenderer)(PromptHeaderView);
5210
+ return (0, import_react33.ReactNodeViewRenderer)(PromptHeaderView);
5167
5211
  }
5168
5212
  });
5169
5213
  var LegacyPromptSEContent = BaseLegacyPromptSEContent.extend({
5170
5214
  addNodeView() {
5171
- return (0, import_react34.ReactNodeViewRenderer)(PromptContentView);
5215
+ return (0, import_react33.ReactNodeViewRenderer)(PromptContentView);
5172
5216
  }
5173
5217
  });
5174
5218
 
5175
5219
  // src/extensions/editor/figure.ts
5176
- var import_react35 = require("@tiptap/react");
5220
+ var import_react34 = require("@tiptap/react");
5221
+ var import_core17 = require("@tiptap/core");
5177
5222
  var Figure2 = BaseFigure.extend({
5178
5223
  addNodeView() {
5179
- return (0, import_react35.ReactNodeViewRenderer)(FigureView);
5224
+ const resizeOptions = this.options.resize;
5225
+ if (!resizeOptions) {
5226
+ return (0, import_react34.ReactNodeViewRenderer)(FigureView);
5227
+ }
5228
+ return (props) => {
5229
+ const { node, getPos, editor } = props;
5230
+ const attrs = node.attrs;
5231
+ const imageExtension = editor.extensionManager.extensions.find(
5232
+ (ext) => ext.name === "image"
5233
+ );
5234
+ const getImageById = imageExtension?.options.getImageById;
5235
+ let imgSrc = attrs.src;
5236
+ if (attrs.fileId && getImageById) {
5237
+ const resolvedSrc = getImageById(attrs.fileId);
5238
+ if (resolvedSrc) imgSrc = resolvedSrc;
5239
+ }
5240
+ let maxWidth;
5241
+ try {
5242
+ if (editor.view?.dom) {
5243
+ const contentWrapper = editor.view.dom.closest(".tiptap-content-wrapper");
5244
+ if (contentWrapper && contentWrapper.clientWidth > 0) {
5245
+ maxWidth = contentWrapper.clientWidth - 32;
5246
+ }
5247
+ }
5248
+ } catch {
5249
+ }
5250
+ let naturalAspectRatio;
5251
+ let maxHeight;
5252
+ const constrainDimensions = (w, h) => {
5253
+ let constrainedW = w;
5254
+ let constrainedH = h;
5255
+ if (maxWidth && maxHeight && naturalAspectRatio && w >= maxWidth) {
5256
+ constrainedW = maxWidth;
5257
+ constrainedH = maxHeight;
5258
+ }
5259
+ return { width: constrainedW, height: constrainedH };
5260
+ };
5261
+ const updateImageDimensions = (width, height) => {
5262
+ imageContainer.style.width = `${width}px`;
5263
+ imageContainer.style.height = `${height}px`;
5264
+ };
5265
+ const figure = document.createElement("figure");
5266
+ figure.setAttribute("data-drag-handle", "");
5267
+ const imageContainer = document.createElement("div");
5268
+ imageContainer.className = "figure-image-container";
5269
+ const img = document.createElement("img");
5270
+ img.src = imgSrc || "";
5271
+ if (attrs.alt) img.alt = attrs.alt;
5272
+ if (attrs.title) img.title = attrs.title;
5273
+ if (attrs.width && attrs.height) {
5274
+ imageContainer.style.width = `${attrs.width}px`;
5275
+ imageContainer.style.height = `${attrs.height}px`;
5276
+ }
5277
+ img.onload = () => {
5278
+ naturalAspectRatio = img.naturalHeight / img.naturalWidth;
5279
+ if (maxWidth && naturalAspectRatio) {
5280
+ maxHeight = Math.round(maxWidth * naturalAspectRatio);
5281
+ }
5282
+ if (attrs.width && attrs.height && maxWidth && attrs.width > maxWidth) {
5283
+ const width = maxWidth;
5284
+ const height = Math.round(attrs.height / attrs.width * maxWidth);
5285
+ imageContainer.style.width = `${width}px`;
5286
+ imageContainer.style.height = `${height}px`;
5287
+ const pos = getPos();
5288
+ if (typeof pos === "number") {
5289
+ editor.chain().updateAttributes("image", {
5290
+ width: Math.round(width),
5291
+ height: Math.round(height)
5292
+ }).run();
5293
+ }
5294
+ }
5295
+ };
5296
+ imageContainer.appendChild(img);
5297
+ if (editor.isEditable) {
5298
+ const editButton = document.createElement("button");
5299
+ editButton.type = "button";
5300
+ editButton.className = "figure-edit-button";
5301
+ editButton.contentEditable = "false";
5302
+ editButton.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="21" height="20" viewBox="0 0 21 20" fill="none"><path d="M2.52441 14.3751V17.5001H5.64941L14.8661 8.28346L11.7411 5.15846L2.52441 14.3751ZM17.2827 5.8668C17.6077 5.5418 17.6077 5.0168 17.2827 4.6918L15.3327 2.7418C15.0077 2.4168 14.4827 2.4168 14.1577 2.7418L12.6327 4.2668L15.7577 7.3918L17.2827 5.8668Z" fill="currentColor"/></svg>';
5303
+ editButton.addEventListener("click", () => {
5304
+ const onFigureClick = imageExtension?.options.onFigureClick;
5305
+ const pos = getPos();
5306
+ if (onFigureClick && typeof pos === "number") {
5307
+ onFigureClick(attrs, pos);
5308
+ }
5309
+ });
5310
+ imageContainer.appendChild(editButton);
5311
+ }
5312
+ const resizableView = new import_core17.ResizableNodeView({
5313
+ element: imageContainer,
5314
+ node,
5315
+ getPos,
5316
+ onResize: (w, h) => {
5317
+ const { width, height } = constrainDimensions(w, h);
5318
+ updateImageDimensions(width, height);
5319
+ },
5320
+ onCommit: (w, h) => {
5321
+ const { width, height } = constrainDimensions(w, h);
5322
+ const pos = getPos();
5323
+ if (typeof pos === "number") {
5324
+ updateImageDimensions(Math.round(width), Math.round(height));
5325
+ editor.chain().focus().setNodeSelection(pos).updateAttributes("image", {
5326
+ width: Math.round(width),
5327
+ height: Math.round(height)
5328
+ }).run();
5329
+ }
5330
+ },
5331
+ onUpdate: (updatedNode) => {
5332
+ if (updatedNode.attrs.width) {
5333
+ imageContainer.style.width = `${updatedNode.attrs.width}px`;
5334
+ }
5335
+ if (updatedNode.attrs.height) {
5336
+ imageContainer.style.height = `${updatedNode.attrs.height}px`;
5337
+ }
5338
+ const existingCaption = figure.querySelector("figcaption");
5339
+ if (updatedNode.attrs.caption && !existingCaption) {
5340
+ const figcaption = document.createElement("figcaption");
5341
+ figcaption.textContent = updatedNode.attrs.caption;
5342
+ figure.appendChild(figcaption);
5343
+ } else if (existingCaption) {
5344
+ if (updatedNode.attrs.caption) {
5345
+ existingCaption.textContent = updatedNode.attrs.caption;
5346
+ } else {
5347
+ existingCaption.remove();
5348
+ }
5349
+ }
5350
+ if (updatedNode.type !== node.type) return false;
5351
+ return true;
5352
+ },
5353
+ options: {
5354
+ directions: resizeOptions.directions || [
5355
+ "bottom-right",
5356
+ "bottom-left",
5357
+ "top-right",
5358
+ "top-left"
5359
+ ],
5360
+ min: {
5361
+ width: resizeOptions.minWidth || 100,
5362
+ height: resizeOptions.minHeight || 100
5363
+ },
5364
+ max: maxWidth && maxHeight ? { width: maxWidth, height: maxHeight } : void 0,
5365
+ preserveAspectRatio: true,
5366
+ className: {
5367
+ container: "tiptap-resize-container",
5368
+ wrapper: "tiptap-resize-wrapper",
5369
+ handle: "tiptap-resize-handle",
5370
+ resizing: "is-resizing"
5371
+ }
5372
+ }
5373
+ });
5374
+ figure.appendChild(resizableView.dom);
5375
+ if (attrs.caption) {
5376
+ const figcaption = document.createElement("figcaption");
5377
+ figcaption.textContent = attrs.caption;
5378
+ figure.appendChild(figcaption);
5379
+ }
5380
+ return {
5381
+ dom: figure,
5382
+ contentDOM: resizableView.contentDOM,
5383
+ update: resizableView.update.bind(resizableView),
5384
+ destroy: resizableView.destroy?.bind(resizableView)
5385
+ };
5386
+ };
5180
5387
  }
5181
5388
  });
5182
5389
  var LegacyFigure = BaseLegacyFigure.extend({
5183
5390
  addNodeView() {
5184
- return (0, import_react35.ReactNodeViewRenderer)(FigureView);
5391
+ return (0, import_react34.ReactNodeViewRenderer)(FigureView);
5185
5392
  }
5186
5393
  });
5187
5394
 
@@ -5210,8 +5417,14 @@ function getEditorExtensions(options) {
5210
5417
  PromptHeader2,
5211
5418
  PromptContent2,
5212
5419
  Video2,
5213
- // Configure with optional getImageById for URL resolution and onFigureClick callback
5214
- Figure2.configure({ getImageById, onFigureClick }),
5420
+ Figure2.configure({
5421
+ getImageById,
5422
+ onFigureClick,
5423
+ resize: {
5424
+ enabled: true,
5425
+ directions: ["top-left", "top-right", "bottom-left", "bottom-right"]
5426
+ }
5427
+ }),
5215
5428
  import_extension_mathematics.Mathematics.configure({
5216
5429
  katexOptions: {
5217
5430
  throwOnError: false
@@ -5352,8 +5565,8 @@ var createHandleKatexAdd = (editor, closeDialogCommand, savedPos) => {
5352
5565
 
5353
5566
  // src/editor/commands/suggestion.tsx
5354
5567
  var import_dom = require("@floating-ui/dom");
5355
- var import_core17 = require("@tiptap/core");
5356
- var import_react36 = require("@tiptap/react");
5568
+ var import_core18 = require("@tiptap/core");
5569
+ var import_react35 = require("@tiptap/react");
5357
5570
 
5358
5571
  // src/editor/commands/items.ts
5359
5572
  var getCommandItems = (translations2, hasImageHandlers) => [
@@ -5654,7 +5867,7 @@ var filterCommandItems = (items, query) => {
5654
5867
  };
5655
5868
 
5656
5869
  // src/editor/commands/suggestion.tsx
5657
- var import_jsx_runtime92 = require("react/jsx-runtime");
5870
+ var import_jsx_runtime91 = require("react/jsx-runtime");
5658
5871
  var component = null;
5659
5872
  var closeMenu = () => {
5660
5873
  if (component) {
@@ -5668,7 +5881,7 @@ var mapCommandMenuItemToCommandItem = (item) => {
5668
5881
  const IconComponent = item.icon;
5669
5882
  return {
5670
5883
  title: item.title,
5671
- icon: /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(IconComponent, {}),
5884
+ icon: /* @__PURE__ */ (0, import_jsx_runtime91.jsx)(IconComponent, {}),
5672
5885
  command: ({ editor, range }) => {
5673
5886
  editor.chain().focus().deleteRange(range).run();
5674
5887
  item.onClick(editor);
@@ -5686,7 +5899,7 @@ var createSuggestions = (translations2, hasImageHandlers) => ({
5686
5899
  render: () => {
5687
5900
  return {
5688
5901
  onStart: async (props) => {
5689
- component = new import_react36.ReactRenderer(CommandsList, {
5902
+ component = new import_react35.ReactRenderer(CommandsList, {
5690
5903
  props,
5691
5904
  editor: props.editor
5692
5905
  });
@@ -5696,7 +5909,7 @@ var createSuggestions = (translations2, hasImageHandlers) => ({
5696
5909
  component.element.style.position = "absolute";
5697
5910
  document.body.appendChild(component.element);
5698
5911
  const virtualElement = {
5699
- getBoundingClientRect: () => (0, import_core17.posToDOMRect)(
5912
+ getBoundingClientRect: () => (0, import_core18.posToDOMRect)(
5700
5913
  props.editor.view,
5701
5914
  props.editor.state.selection.from,
5702
5915
  props.editor.state.selection.to
@@ -5723,7 +5936,7 @@ var createSuggestions = (translations2, hasImageHandlers) => ({
5723
5936
  return;
5724
5937
  }
5725
5938
  const virtualElement = {
5726
- getBoundingClientRect: () => (0, import_core17.posToDOMRect)(
5939
+ getBoundingClientRect: () => (0, import_core18.posToDOMRect)(
5727
5940
  props.editor.view,
5728
5941
  props.editor.state.selection.from,
5729
5942
  props.editor.state.selection.to
@@ -6099,7 +6312,7 @@ function getTranslations(lang) {
6099
6312
  }
6100
6313
 
6101
6314
  // src/editor/editor.tsx
6102
- var import_jsx_runtime93 = require("react/jsx-runtime");
6315
+ var import_jsx_runtime92 = require("react/jsx-runtime");
6103
6316
  function TiptapContent({
6104
6317
  content,
6105
6318
  handleChange,
@@ -6109,12 +6322,12 @@ function TiptapContent({
6109
6322
  lang,
6110
6323
  error
6111
6324
  }) {
6112
- const [linkDialogContext, setLinkDialogContext] = (0, import_react37.useState)(null);
6113
- const [katexDialogContext, setKatexDialogContext] = (0, import_react37.useState)(
6325
+ const [linkDialogContext, setLinkDialogContext] = (0, import_react36.useState)(null);
6326
+ const [katexDialogContext, setKatexDialogContext] = (0, import_react36.useState)(
6114
6327
  null
6115
6328
  );
6116
- const [editFigureContext, setEditFigureContext] = (0, import_react37.useState)(null);
6117
- const [savedDialogCursorPos, setSavedDialogCursorPos] = (0, import_react37.useState)(void 0);
6329
+ const [editFigureContext, setEditFigureContext] = (0, import_react36.useState)(null);
6330
+ const [savedDialogCursorPos, setSavedDialogCursorPos] = (0, import_react36.useState)(void 0);
6118
6331
  const { activeDialog, closeDialogCommand, openDialogCommand } = useDialogCommand();
6119
6332
  const translations2 = useTiptapTranslations();
6120
6333
  let safeContent;
@@ -6123,7 +6336,7 @@ function TiptapContent({
6123
6336
  } catch {
6124
6337
  safeContent = { type: "doc", content: [{ type: "paragraph" }] };
6125
6338
  }
6126
- const editor = (0, import_react38.useEditor)(
6339
+ const editor = (0, import_react37.useEditor)(
6127
6340
  {
6128
6341
  editable: isEditable && !isDisabled,
6129
6342
  extensions: getEditorExtensions({
@@ -6165,7 +6378,7 @@ function TiptapContent({
6165
6378
  },
6166
6379
  [lang]
6167
6380
  );
6168
- (0, import_react37.useEffect)(() => {
6381
+ (0, import_react36.useEffect)(() => {
6169
6382
  if (activeDialog && editor && !editor.isDestroyed) {
6170
6383
  const pos = editor.state.selection.from;
6171
6384
  setSavedDialogCursorPos(pos);
@@ -6192,7 +6405,7 @@ function TiptapContent({
6192
6405
  const katexHandler = createHandleKatexAdd(editor, handleCloseDialog, savedDialogCursorPos);
6193
6406
  katexHandler(latex, katexDialogContext?.pos);
6194
6407
  };
6195
- (0, import_react37.useEffect)(() => {
6408
+ (0, import_react36.useEffect)(() => {
6196
6409
  if (!editor || editor.isDestroyed) return;
6197
6410
  editor.commands.setContent(safeContent, {
6198
6411
  emitUpdate: false
@@ -6211,16 +6424,16 @@ function TiptapContent({
6211
6424
  return true;
6212
6425
  };
6213
6426
  if (!editor) return null;
6214
- return /* @__PURE__ */ (0, import_jsx_runtime93.jsxs)(import_jsx_runtime93.Fragment, { children: [
6215
- /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(DragHandle, { editor }),
6216
- isEditable && !isDisabled && /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(TableMenu, { editor }),
6217
- isEditable && !isDisabled && /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
6427
+ return /* @__PURE__ */ (0, import_jsx_runtime92.jsxs)(import_jsx_runtime92.Fragment, { children: [
6428
+ /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(DragHandle, { editor }),
6429
+ isEditable && !isDisabled && /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(TableMenu, { editor }),
6430
+ isEditable && !isDisabled && /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
6218
6431
  import_menus.BubbleMenu,
6219
6432
  {
6220
6433
  shouldShow: shouldBubbleMenuShow,
6221
6434
  editor,
6222
6435
  options: { placement: "bottom", offset: 8, flip: true },
6223
- children: /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
6436
+ children: /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
6224
6437
  BubbleMenuContent,
6225
6438
  {
6226
6439
  editor,
@@ -6229,19 +6442,19 @@ function TiptapContent({
6229
6442
  )
6230
6443
  }
6231
6444
  ),
6232
- /* @__PURE__ */ (0, import_jsx_runtime93.jsxs)(
6445
+ /* @__PURE__ */ (0, import_jsx_runtime92.jsxs)(
6233
6446
  "div",
6234
6447
  {
6235
6448
  className: `tiptap-content-wrapper ${!!error ? "has-error" : ""} ${isDisabled ? "is-disabled" : ""}`,
6236
6449
  children: [
6237
- /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(import_react38.EditorContent, { editor }),
6238
- isEditable && !isDisabled && /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(CharacterCount, { editor })
6450
+ /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(import_react37.EditorContent, { editor }),
6451
+ isEditable && !isDisabled && /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(CharacterCount, { editor })
6239
6452
  ]
6240
6453
  }
6241
6454
  ),
6242
- !!error && /* @__PURE__ */ (0, import_jsx_runtime93.jsx)("p", { className: "tiptap-error-message", children: error }),
6243
- isEditable && /* @__PURE__ */ (0, import_jsx_runtime93.jsxs)(import_jsx_runtime93.Fragment, { children: [
6244
- activeDialog === "image" && /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
6455
+ !!error && /* @__PURE__ */ (0, import_jsx_runtime92.jsx)("p", { className: "tiptap-error-message", children: error }),
6456
+ isEditable && /* @__PURE__ */ (0, import_jsx_runtime92.jsxs)(import_jsx_runtime92.Fragment, { children: [
6457
+ activeDialog === "image" && /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
6245
6458
  ImageDialog,
6246
6459
  {
6247
6460
  open: true,
@@ -6254,7 +6467,7 @@ function TiptapContent({
6254
6467
  mode: editFigureContext ? "edit" : "add"
6255
6468
  }
6256
6469
  ),
6257
- activeDialog === "link" && /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
6470
+ activeDialog === "link" && /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
6258
6471
  AddLinkDialog,
6259
6472
  {
6260
6473
  open: true,
@@ -6263,7 +6476,7 @@ function TiptapContent({
6263
6476
  linkDialogContext
6264
6477
  }
6265
6478
  ),
6266
- activeDialog === "video" && /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
6479
+ activeDialog === "video" && /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
6267
6480
  AddVideoDialog,
6268
6481
  {
6269
6482
  open: true,
@@ -6271,7 +6484,7 @@ function TiptapContent({
6271
6484
  onVideoAdd: handleVideoAdd
6272
6485
  }
6273
6486
  ),
6274
- activeDialog === "katex" && /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
6487
+ activeDialog === "katex" && /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(
6275
6488
  AddKatexDialog,
6276
6489
  {
6277
6490
  open: true,
@@ -6286,10 +6499,42 @@ function TiptapContent({
6286
6499
  var Tiptap = (props) => {
6287
6500
  const { lang = "ru" } = props;
6288
6501
  const translations2 = getTranslations(lang);
6289
- return /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(TiptapTranslationsProvider, { translations: translations2, children: /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(DialogCommandProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(TiptapContent, { ...props }) }) });
6502
+ return /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(TiptapTranslationsProvider, { translations: translations2, children: /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(DialogCommandProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime92.jsx)(TiptapContent, { ...props }) }) });
6290
6503
  };
6504
+
6505
+ // src/utils/html-to-tiptap-content.ts
6506
+ var import_core19 = require("@tiptap/core");
6507
+ function isJSONContent(value) {
6508
+ return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
6509
+ }
6510
+ function htmlToTiptapContent(content) {
6511
+ if (isJSONContent(content)) {
6512
+ return content;
6513
+ }
6514
+ if (typeof content === "string") {
6515
+ try {
6516
+ const parsed = JSON.parse(content);
6517
+ if (isJSONContent(parsed)) {
6518
+ return parsed;
6519
+ }
6520
+ } catch {
6521
+ }
6522
+ }
6523
+ if (!content || content.trim() === "") {
6524
+ return { type: "doc", content: [{ type: "paragraph" }] };
6525
+ }
6526
+ const sharedExtensions = getSharedExtensions();
6527
+ const extensions = [...sharedExtensions, BaseFigure];
6528
+ try {
6529
+ return (0, import_core19.generateJSON)(content, extensions);
6530
+ } catch (error) {
6531
+ console.error("Failed to convert HTML to Tiptap content:", error);
6532
+ return { type: "doc", content: [{ type: "paragraph" }] };
6533
+ }
6534
+ }
6291
6535
  // Annotate the CommonJS export names for ESM import in node:
6292
6536
  0 && (module.exports = {
6293
- Tiptap
6537
+ Tiptap,
6538
+ htmlToTiptapContent
6294
6539
  });
6295
6540
  //# sourceMappingURL=editor.js.map