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