@cyberyozh/text-editor 0.1.16 → 0.1.17

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.
@@ -642,6 +642,7 @@
642
642
  display: inline-block;
643
643
  position: relative;
644
644
  margin: 0 auto;
645
+ min-width: 0;
645
646
  }
646
647
  [data-resize-handle] {
647
648
  z-index: 10;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyberyozh/text-editor",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "Rich text editor library based on Tiptap for CyberYozh",
5
5
  "author": "CyberYozh",
6
6
  "license": "MIT",
@@ -54,7 +54,8 @@ export const Figure = BaseFigure.extend({
54
54
 
55
55
  const updateImageDimensions = (width: number, height: number) => {
56
56
  imageContainer.style.width = `${width}px`;
57
- imageContainer.style.height = `${height}px`;
57
+ imageContainer.style.aspectRatio = `${width} / ${height}`;
58
+ imageContainer.style.height = '';
58
59
  };
59
60
 
60
61
  const figure = document.createElement("figure");
@@ -70,7 +71,7 @@ export const Figure = BaseFigure.extend({
70
71
 
71
72
  if (attrs.width && attrs.height) {
72
73
  imageContainer.style.width = `${attrs.width}px`;
73
- imageContainer.style.height = `${attrs.height}px`;
74
+ imageContainer.style.aspectRatio = `${attrs.width} / ${attrs.height}`;
74
75
  }
75
76
 
76
77
  img.onload = () => {
@@ -81,19 +82,13 @@ export const Figure = BaseFigure.extend({
81
82
  }
82
83
 
83
84
  if (attrs.width && attrs.height && maxWidth && attrs.width > maxWidth) {
84
- const width = maxWidth;
85
- const height = Math.round((attrs.height / attrs.width) * maxWidth);
86
-
87
- imageContainer.style.width = `${width}px`;
88
- imageContainer.style.height = `${height}px`;
89
-
90
85
  const pos = getPos();
91
86
  if (typeof pos === "number") {
92
87
  editor
93
88
  .chain()
94
89
  .updateAttributes("image", {
95
- width: Math.round(width),
96
- height: Math.round(height),
90
+ width: maxWidth,
91
+ height: Math.round((attrs.height / attrs.width) * maxWidth),
97
92
  })
98
93
  .run();
99
94
  }
@@ -149,11 +144,13 @@ export const Figure = BaseFigure.extend({
149
144
  }
150
145
  },
151
146
  onUpdate: (updatedNode) => {
152
- if (updatedNode.attrs.width) {
153
- imageContainer.style.width = `${updatedNode.attrs.width}px`;
154
- }
155
- if (updatedNode.attrs.height) {
156
- imageContainer.style.height = `${updatedNode.attrs.height}px`;
147
+ const newWidth = updatedNode.attrs.width;
148
+ const newHeight = updatedNode.attrs.height;
149
+
150
+ if (newWidth) imageContainer.style.width = `${newWidth}px`;
151
+ if (newWidth && newHeight) {
152
+ imageContainer.style.aspectRatio = `${newWidth} / ${newHeight}`;
153
+ imageContainer.style.height = '';
157
154
  }
158
155
 
159
156
  const existingCaption = figure.querySelector("figcaption");
@@ -194,6 +191,8 @@ export const Figure = BaseFigure.extend({
194
191
  },
195
192
  });
196
193
 
194
+ imageContainer.style.height = '';
195
+
197
196
  figure.appendChild(resizableView.dom);
198
197
 
199
198
  if (attrs.caption) {
@@ -85,6 +85,7 @@
85
85
  display: inline-block;
86
86
  position: relative;
87
87
  margin: 0 auto;
88
+ min-width: 0;
88
89
  }
89
90
 
90
91
  [data-resize-handle] {