@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/editor.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { JSONContent } from '@tiptap/react';
3
3
  export { JSONContent } from '@tiptap/react';
4
+ import { JSONContent as JSONContent$1 } from '@tiptap/core';
4
5
 
5
6
  interface ImageUploadResult {
6
7
  fileId?: string;
@@ -48,4 +49,6 @@ interface TiptapProps {
48
49
  }
49
50
  declare const Tiptap: (props: TiptapProps) => react_jsx_runtime.JSX.Element;
50
51
 
51
- export { Tiptap, type SupportedLanguage as TiptapSupportedLanguages };
52
+ declare function htmlToTiptapContent(content: string | JSONContent$1): JSONContent$1;
53
+
54
+ export { Tiptap, type SupportedLanguage as TiptapSupportedLanguages, htmlToTiptapContent };
package/dist/editor.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { JSONContent } from '@tiptap/react';
3
3
  export { JSONContent } from '@tiptap/react';
4
+ import { JSONContent as JSONContent$1 } from '@tiptap/core';
4
5
 
5
6
  interface ImageUploadResult {
6
7
  fileId?: string;
@@ -48,4 +49,6 @@ interface TiptapProps {
48
49
  }
49
50
  declare const Tiptap: (props: TiptapProps) => react_jsx_runtime.JSX.Element;
50
51
 
51
- export { Tiptap, type SupportedLanguage as TiptapSupportedLanguages };
52
+ declare function htmlToTiptapContent(content: string | JSONContent$1): JSONContent$1;
53
+
54
+ export { Tiptap, type SupportedLanguage as TiptapSupportedLanguages, htmlToTiptapContent };
package/dist/editor.js CHANGED
@@ -30,7 +30,8 @@ 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
 
@@ -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;
@@ -2018,6 +2044,7 @@ var ImageDialog = ({
2018
2044
  setIsUploading(true);
2019
2045
  try {
2020
2046
  const result = await uploadHandler(formState.file);
2047
+ console.log("\u{1F440} ~ handleAddImage ~ result:", result);
2021
2048
  onImageAdd({
2022
2049
  fileId: result.fileId,
2023
2050
  src: result.fileUrl,
@@ -2038,7 +2065,9 @@ var ImageDialog = ({
2038
2065
  onImageEdit({
2039
2066
  alt: formState.alt,
2040
2067
  title: formState.title,
2041
- caption: formState.caption
2068
+ caption: formState.caption,
2069
+ width: formState.width || void 0,
2070
+ height: formState.height || void 0
2042
2071
  });
2043
2072
  handleClose();
2044
2073
  };
@@ -5251,6 +5280,19 @@ var Figure2 = BaseFigure.extend({
5251
5280
  if (maxWidth && naturalAspectRatio) {
5252
5281
  maxHeight = Math.round(maxWidth * naturalAspectRatio);
5253
5282
  }
5283
+ if (attrs.width && attrs.height && maxWidth && attrs.width > maxWidth) {
5284
+ const width = maxWidth;
5285
+ const height = Math.round(attrs.height / attrs.width * maxWidth);
5286
+ imageContainer.style.width = `${width}px`;
5287
+ imageContainer.style.height = `${height}px`;
5288
+ const pos = getPos();
5289
+ if (typeof pos === "number") {
5290
+ editor.chain().updateAttributes("image", {
5291
+ width: Math.round(width),
5292
+ height: Math.round(height)
5293
+ }).run();
5294
+ }
5295
+ }
5254
5296
  };
5255
5297
  imageContainer.appendChild(img);
5256
5298
  if (editor.isEditable) {
@@ -5270,6 +5312,7 @@ var Figure2 = BaseFigure.extend({
5270
5312
  }
5271
5313
  const resizableView = new import_core17.ResizableNodeView({
5272
5314
  element: imageContainer,
5315
+ editor,
5273
5316
  node,
5274
5317
  getPos,
5275
5318
  onResize: (w, h) => {
@@ -6460,8 +6503,40 @@ var Tiptap = (props) => {
6460
6503
  const translations2 = getTranslations(lang);
6461
6504
  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 }) }) });
6462
6505
  };
6506
+
6507
+ // src/utils/html-to-tiptap-content.ts
6508
+ var import_core19 = require("@tiptap/core");
6509
+ function isJSONContent(value) {
6510
+ return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
6511
+ }
6512
+ function htmlToTiptapContent(content) {
6513
+ if (isJSONContent(content)) {
6514
+ return content;
6515
+ }
6516
+ if (typeof content === "string") {
6517
+ try {
6518
+ const parsed = JSON.parse(content);
6519
+ if (isJSONContent(parsed)) {
6520
+ return parsed;
6521
+ }
6522
+ } catch {
6523
+ }
6524
+ }
6525
+ if (!content || content.trim() === "") {
6526
+ return { type: "doc", content: [{ type: "paragraph" }] };
6527
+ }
6528
+ const sharedExtensions = getSharedExtensions();
6529
+ const extensions = [...sharedExtensions, BaseFigure];
6530
+ try {
6531
+ return (0, import_core19.generateJSON)(content, extensions);
6532
+ } catch (error) {
6533
+ console.error("Failed to convert HTML to Tiptap content:", error);
6534
+ return { type: "doc", content: [{ type: "paragraph" }] };
6535
+ }
6536
+ }
6463
6537
  // Annotate the CommonJS export names for ESM import in node:
6464
6538
  0 && (module.exports = {
6465
- Tiptap
6539
+ Tiptap,
6540
+ htmlToTiptapContent
6466
6541
  });
6467
6542
  //# sourceMappingURL=editor.js.map