@zhenryx/react-editor 0.1.2 → 0.1.3

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/index.mjs CHANGED
@@ -1311,16 +1311,18 @@ function RichTextEditor({ markdown, onChange, onUploadImage, onSwitchToMarkdown,
1311
1311
  setError("图片地址不合法");
1312
1312
  return;
1313
1313
  }
1314
+ const width = Math.max(20, Math.min(4e3, Number(imageDialog.width) || 20));
1315
+ const height = Math.max(0, Number(imageDialog.height) || 0);
1314
1316
  img.setAttribute("src", src);
1315
1317
  img.setAttribute("alt", imageDialog.alt);
1316
- img.setAttribute("data-kb-w", String(imageDialog.width));
1317
- img.style.setProperty("--kbw", `${imageDialog.width}px`);
1318
- if (imageDialog.lock || !imageDialog.height) {
1318
+ img.setAttribute("data-kb-w", String(width));
1319
+ img.style.setProperty("--kbw", `${width}px`);
1320
+ if (imageDialog.lock || height <= 0) {
1319
1321
  img.removeAttribute("data-kb-h");
1320
1322
  img.style.removeProperty("--kbh");
1321
1323
  } else {
1322
- img.setAttribute("data-kb-h", String(imageDialog.height));
1323
- img.style.setProperty("--kbh", `${imageDialog.height}px`);
1324
+ img.setAttribute("data-kb-h", String(height));
1325
+ img.style.setProperty("--kbh", `${height}px`);
1324
1326
  }
1325
1327
  if (imageDialog.align === "none") img.removeAttribute("data-kb-align");
1326
1328
  else img.setAttribute("data-kb-align", imageDialog.align);
@@ -1796,13 +1798,25 @@ function RichTextEditor({ markdown, onChange, onUploadImage, onSwitchToMarkdown,
1796
1798
  min: 20,
1797
1799
  max: 4e3,
1798
1800
  value: imageDialog.width,
1801
+ onFocus: (event) => event.currentTarget.select(),
1799
1802
  onChange: (event) => {
1800
- const width = Math.max(20, Math.min(4e3, Number(event.target.value) || 20));
1803
+ const raw = event.target.value;
1804
+ const width = raw === "" ? "" : Math.max(0, Math.min(4e3, Number(raw) || 0));
1801
1805
  setImageDialog({
1802
1806
  ...imageDialog,
1803
1807
  width,
1804
- height: imageDialog.lock ? calcImageHeight(width) : imageDialog.height
1808
+ height: imageDialog.lock ? width === "" || width < 20 ? "" : calcImageHeight(width) : imageDialog.height
1805
1809
  });
1810
+ },
1811
+ onBlur: () => {
1812
+ if (imageDialog.width !== "" && Number(imageDialog.width) < 20) {
1813
+ const width = 20;
1814
+ setImageDialog({
1815
+ ...imageDialog,
1816
+ width,
1817
+ height: imageDialog.lock ? calcImageHeight(width) : imageDialog.height
1818
+ });
1819
+ }
1806
1820
  }
1807
1821
  })]
1808
1822
  }),
@@ -1811,12 +1825,22 @@ function RichTextEditor({ markdown, onChange, onUploadImage, onSwitchToMarkdown,
1811
1825
  children: [/* @__PURE__ */ jsx("span", { children: "高度(px)" }), /* @__PURE__ */ jsx("input", {
1812
1826
  type: "number",
1813
1827
  min: 1,
1814
- value: imageDialog.height || "",
1828
+ value: imageDialog.height,
1815
1829
  readOnly: imageDialog.lock,
1816
- onChange: (event) => setImageDialog({
1817
- ...imageDialog,
1818
- height: Math.max(1, Number(event.target.value) || 1)
1819
- })
1830
+ onFocus: (event) => event.currentTarget.select(),
1831
+ onChange: (event) => {
1832
+ const raw = event.target.value;
1833
+ setImageDialog({
1834
+ ...imageDialog,
1835
+ height: raw === "" ? "" : Math.max(0, Number(raw) || 0)
1836
+ });
1837
+ },
1838
+ onBlur: () => {
1839
+ if (imageDialog.height !== "" && Number(imageDialog.height) < 1) setImageDialog({
1840
+ ...imageDialog,
1841
+ height: 1
1842
+ });
1843
+ }
1820
1844
  })]
1821
1845
  }),
1822
1846
  /* @__PURE__ */ jsxs("div", {
@@ -1828,7 +1852,7 @@ function RichTextEditor({ markdown, onChange, onUploadImage, onSwitchToMarkdown,
1828
1852
  onClick: () => setImageDialog({
1829
1853
  ...imageDialog,
1830
1854
  lock: !imageDialog.lock,
1831
- height: !imageDialog.lock ? calcImageHeight(imageDialog.width) : imageDialog.height
1855
+ height: !imageDialog.lock ? calcImageHeight(Number(imageDialog.width) || 20) : imageDialog.height
1832
1856
  }),
1833
1857
  children: /* @__PURE__ */ jsxs("svg", {
1834
1858
  width: "15",