@zhenryx/react-editor 0.1.0 → 0.1.2

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 CHANGED
@@ -77,7 +77,26 @@ function inlineToMd(node) {
77
77
  }
78
78
  case "IMG": {
79
79
  const src = el.getAttribute("src") || "";
80
- return src ? `![${el.getAttribute("alt") || ""}](${src})` : "";
80
+ if (!src) return "";
81
+ const alt = el.getAttribute("alt") || "";
82
+ const width = Number(el.getAttribute("data-kb-w") || "");
83
+ const height = Number(el.getAttribute("data-kb-h") || "");
84
+ const align = el.getAttribute("data-kb-align") || "";
85
+ const caption = (el.getAttribute("data-kb-caption") || el.closest("figure")?.querySelector("figcaption")?.textContent || "").trim();
86
+ const tokens = [];
87
+ if (Number.isInteger(width) && width >= 20 && width <= 4e3) tokens.push(`kbw=${width}`);
88
+ if (Number.isInteger(height) && height > 0) tokens.push(`kbh=${height}`);
89
+ if (/^(left|center|right)$/.test(align)) tokens.push(`kba=${align}`);
90
+ if (caption) tokens.push(`kbc=${encodeURIComponent(caption)}`);
91
+ return `![${alt}](${src}${tokens.length ? ` "${tokens.join(" ")}"` : ""})`;
92
+ }
93
+ case "FIGURE": {
94
+ const img = el.querySelector("img");
95
+ return img ? `
96
+
97
+ ${inlineToMd(img)}
98
+
99
+ ` : "";
81
100
  }
82
101
  case "UL":
83
102
  case "OL": return `\n\n${listToMd(el)}`;
@@ -147,7 +166,7 @@ function blockToMd(el) {
147
166
  }
148
167
  case "P":
149
168
  case "DIV": {
150
- if (Array.from(el.children).some((child) => /^(P|DIV|H[1-6]|UL|OL|LI|BLOCKQUOTE|PRE|TABLE|HR)$/.test(child.tagName))) return Array.from(el.childNodes).map(nodeToMd).join("");
169
+ if (Array.from(el.children).some((child) => /^(P|DIV|H[1-6]|UL|OL|LI|BLOCKQUOTE|PRE|TABLE|HR|FIGURE)$/.test(child.tagName))) return Array.from(el.childNodes).map(nodeToMd).join("");
151
170
  const content = inlineToMd(el).trim();
152
171
  const align = (el.style.textAlign || "").toLowerCase();
153
172
  if (/^(left|center|right|justify)$/.test(align) && content) return `\n\n<span style="display: block; text-align: ${align}">${content}</span>\n\n`;
@@ -172,9 +191,10 @@ function nodeToMd(node) {
172
191
  }
173
192
  if (el.classList.contains("kb-code")) {
174
193
  const pre = el.querySelector("pre");
175
- if (pre) return preToMd(pre, el.querySelector(".kb-code-lang")?.textContent?.trim() || "");
194
+ const extra = Array.from(el.children).filter((child) => child.tagName !== "PRE" && !child.classList.contains("kb-code-lang")).map((child) => nodeToMd(child)).join("");
195
+ return (pre ? preToMd(pre, el.querySelector(".kb-code-lang")?.textContent?.trim() || "") : "") + extra;
176
196
  }
177
- if (/^(P|DIV|H[1-6]|UL|OL|BLOCKQUOTE|PRE|TABLE|HR)$/.test(el.tagName)) return blockToMd(el);
197
+ if (/^(P|DIV|H[1-6]|UL|OL|BLOCKQUOTE|PRE|TABLE|HR|FIGURE)$/.test(el.tagName)) return blockToMd(el);
178
198
  return inlineToMd(el);
179
199
  }
180
200
  /** contentEditable 的 innerHTML → Markdown */
@@ -869,6 +889,9 @@ function RichTextEditor({ markdown, onChange, onUploadImage, onSwitchToMarkdown,
869
889
  const [busy, setBusy] = (0, react.useState)(false);
870
890
  const [error, setError] = (0, react.useState)("");
871
891
  const [popover, setPopover] = (0, react.useState)(null);
892
+ const selectedImageRef = (0, react.useRef)(null);
893
+ const [imageSel, setImageSel] = (0, react.useState)(null);
894
+ const [imageDialog, setImageDialog] = (0, react.useState)(null);
872
895
  const [videoUrl, setVideoUrl] = (0, react.useState)("");
873
896
  const [formulaText, setFormulaText] = (0, react.useState)("");
874
897
  const [wide, setWide] = (0, react.useState)(false);
@@ -883,6 +906,9 @@ function RichTextEditor({ markdown, onChange, onUploadImage, onSwitchToMarkdown,
883
906
  if (lastMd.current === markdown) return;
884
907
  el.innerHTML = renderMarkdown(markdown);
885
908
  lastMd.current = markdown;
909
+ selectedImageRef.current = null;
910
+ setImageSel(null);
911
+ setImageDialog(null);
886
912
  refreshHeadings();
887
913
  }, [markdown]);
888
914
  (0, react.useEffect)(() => {
@@ -903,6 +929,28 @@ function RichTextEditor({ markdown, onChange, onUploadImage, onSwitchToMarkdown,
903
929
  document.addEventListener("mousedown", onDown);
904
930
  return () => document.removeEventListener("mousedown", onDown);
905
931
  }, [popover]);
932
+ (0, react.useEffect)(() => {
933
+ if (!imageSel) return;
934
+ const onScroll = () => updateImageRect();
935
+ const onResize = () => updateImageRect();
936
+ window.addEventListener("scroll", onScroll, true);
937
+ window.addEventListener("resize", onResize);
938
+ return () => {
939
+ window.removeEventListener("scroll", onScroll, true);
940
+ window.removeEventListener("resize", onResize);
941
+ };
942
+ }, [imageSel]);
943
+ (0, react.useEffect)(() => {
944
+ if (!imageSel) return;
945
+ const onDown = (event) => {
946
+ const target = event.target;
947
+ if (target?.closest(".rre-img-tool") || target?.closest(".rre-img-dialog")) return;
948
+ if (target?.closest("img")) return;
949
+ clearImageSelection();
950
+ };
951
+ document.addEventListener("mousedown", onDown);
952
+ return () => document.removeEventListener("mousedown", onDown);
953
+ }, [imageSel]);
906
954
  (0, react.useEffect)(() => {
907
955
  if (!markdown.trim()) return;
908
956
  const timer = window.setTimeout(() => {
@@ -1176,7 +1224,9 @@ function RichTextEditor({ markdown, onChange, onUploadImage, onSwitchToMarkdown,
1176
1224
  try {
1177
1225
  const src = safeRichHref(await onUploadImage(file));
1178
1226
  if (!src) throw new Error("图片地址不合法");
1179
- insertHtml(`<img src="${src}" alt="${escapeHtml(file.name.replace(/\.[^.]+$/, ""))}">`);
1227
+ const contentWidth = editorRef.current?.clientWidth || 860;
1228
+ const defaultWidth = Math.max(120, Math.round(contentWidth * .75));
1229
+ insertHtml(`<img src="${src}" alt="${escapeHtml(file.name.replace(/\.[^.]+$/, ""))}" data-kb-w="${defaultWidth}" style="--kbw:${defaultWidth}px">`);
1180
1230
  } catch (err) {
1181
1231
  setError(err instanceof Error ? err.message : "图片上传失败");
1182
1232
  } finally {
@@ -1187,6 +1237,118 @@ function RichTextEditor({ markdown, onChange, onUploadImage, onSwitchToMarkdown,
1187
1237
  const row = "<tr><td>内容</td><td>内容</td><td>内容</td></tr>";
1188
1238
  insertHtml(`<table><thead><tr><th>列 1</th><th>列 2</th><th>列 3</th></tr></thead><tbody>${row}${row}</tbody></table><p><br></p>`);
1189
1239
  }
1240
+ function clearImageSelection() {
1241
+ selectedImageRef.current = null;
1242
+ setImageSel(null);
1243
+ }
1244
+ function updateImageRect() {
1245
+ const img = selectedImageRef.current;
1246
+ if (!img) return;
1247
+ const rect = img.getBoundingClientRect();
1248
+ setImageSel({
1249
+ left: Math.round(rect.left),
1250
+ top: Math.round(rect.top),
1251
+ width: Math.round(rect.width),
1252
+ height: Math.round(rect.height)
1253
+ });
1254
+ }
1255
+ function selectImage(img) {
1256
+ selectedImageRef.current = img;
1257
+ updateImageRect();
1258
+ }
1259
+ function calcImageHeight(widthPx) {
1260
+ const img = selectedImageRef.current;
1261
+ if (!img || !img.naturalWidth) return 0;
1262
+ return Math.max(1, Math.round(img.naturalHeight / img.naturalWidth * widthPx));
1263
+ }
1264
+ function startImageResize(event) {
1265
+ const img = selectedImageRef.current;
1266
+ const container = editorRef.current;
1267
+ if (!img || !container) return;
1268
+ event.preventDefault();
1269
+ event.stopPropagation();
1270
+ const startX = event.clientX;
1271
+ const startWidth = img.getBoundingClientRect().width;
1272
+ const containerWidth = container.clientWidth || 1;
1273
+ const onMove = (moveEvent) => {
1274
+ const next = Math.max(40, Math.min(containerWidth, Math.round(startWidth + moveEvent.clientX - startX)));
1275
+ img.setAttribute("data-kb-w", String(next));
1276
+ img.style.setProperty("--kbw", `${next}px`);
1277
+ updateImageRect();
1278
+ };
1279
+ const onUp = () => {
1280
+ document.removeEventListener("pointermove", onMove);
1281
+ document.removeEventListener("pointerup", onUp);
1282
+ sync();
1283
+ };
1284
+ document.addEventListener("pointermove", onMove);
1285
+ document.addEventListener("pointerup", onUp);
1286
+ }
1287
+ function openImageDialog() {
1288
+ const img = selectedImageRef.current;
1289
+ if (!img) return;
1290
+ const widthAttr = Number(img.getAttribute("data-kb-w") || "");
1291
+ const width = Number.isInteger(widthAttr) && widthAttr >= 20 ? widthAttr : Math.max(40, Math.round(img.getBoundingClientRect().width));
1292
+ const heightAttr = Number(img.getAttribute("data-kb-h") || "");
1293
+ const alignRaw = img.getAttribute("data-kb-align") || "";
1294
+ const align = /^(left|center|right)$/.test(alignRaw) ? alignRaw : "none";
1295
+ const caption = (img.getAttribute("data-kb-caption") || "").trim();
1296
+ setImageDialog({
1297
+ url: img.getAttribute("src") || "",
1298
+ alt: img.getAttribute("alt") || "",
1299
+ width,
1300
+ height: Number.isInteger(heightAttr) && heightAttr > 0 ? heightAttr : calcImageHeight(width),
1301
+ lock: !(Number.isInteger(heightAttr) && heightAttr > 0),
1302
+ align,
1303
+ caption: Boolean(caption),
1304
+ captionText: caption
1305
+ });
1306
+ }
1307
+ function applyImageDialog() {
1308
+ const img = selectedImageRef.current;
1309
+ if (!img || !imageDialog) return;
1310
+ const src = safeRichHref(imageDialog.url.trim());
1311
+ if (!src) {
1312
+ setError("图片地址不合法");
1313
+ return;
1314
+ }
1315
+ img.setAttribute("src", src);
1316
+ img.setAttribute("alt", imageDialog.alt);
1317
+ img.setAttribute("data-kb-w", String(imageDialog.width));
1318
+ img.style.setProperty("--kbw", `${imageDialog.width}px`);
1319
+ if (imageDialog.lock || !imageDialog.height) {
1320
+ img.removeAttribute("data-kb-h");
1321
+ img.style.removeProperty("--kbh");
1322
+ } else {
1323
+ img.setAttribute("data-kb-h", String(imageDialog.height));
1324
+ img.style.setProperty("--kbh", `${imageDialog.height}px`);
1325
+ }
1326
+ if (imageDialog.align === "none") img.removeAttribute("data-kb-align");
1327
+ else img.setAttribute("data-kb-align", imageDialog.align);
1328
+ if (imageDialog.caption && imageDialog.captionText.trim()) img.setAttribute("data-kb-caption", imageDialog.captionText.trim());
1329
+ else img.removeAttribute("data-kb-caption");
1330
+ setImageDialog(null);
1331
+ clearImageSelection();
1332
+ sync();
1333
+ const el = editorRef.current;
1334
+ if (el) {
1335
+ const md = htmlToMarkdown(el.innerHTML);
1336
+ el.innerHTML = renderMarkdown(md);
1337
+ lastMd.current = md;
1338
+ }
1339
+ }
1340
+ function resetImageSize() {
1341
+ const img = selectedImageRef.current;
1342
+ const containerWidth = editorRef.current?.clientWidth || 1;
1343
+ if (!img) return;
1344
+ const naturalWidth = Math.max(40, Math.min(containerWidth, img.naturalWidth || 640));
1345
+ setImageDialog((prev) => prev ? {
1346
+ ...prev,
1347
+ width: naturalWidth,
1348
+ height: calcImageHeight(naturalWidth),
1349
+ lock: true
1350
+ } : prev);
1351
+ }
1190
1352
  function toolButton(label, icon, onClick, opts = {}) {
1191
1353
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1192
1354
  type: "button",
@@ -1213,7 +1375,10 @@ function RichTextEditor({ markdown, onChange, onUploadImage, onSwitchToMarkdown,
1213
1375
  event.preventDefault();
1214
1376
  saveRange();
1215
1377
  },
1216
- onClick: (event) => openPopover(kind, event.currentTarget),
1378
+ onClick: (event) => {
1379
+ if (popover?.kind === kind) setPopover(null);
1380
+ else openPopover(kind, event.currentTarget);
1381
+ },
1217
1382
  children: [icon, /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1218
1383
  className: withCaret ? "rre-popover-label" : void 0,
1219
1384
  children: [label, withCaret ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
@@ -1538,12 +1703,228 @@ function RichTextEditor({ markdown, onChange, onUploadImage, onSwitchToMarkdown,
1538
1703
  "data-placeholder": placeholder,
1539
1704
  onInput: sync,
1540
1705
  onBlur: sync,
1541
- onPaste
1706
+ onPaste,
1707
+ onClick: (event) => {
1708
+ const img = event.target?.closest("img");
1709
+ if (img && editorRef.current?.contains(img)) {
1710
+ event.preventDefault();
1711
+ selectImage(img);
1712
+ }
1713
+ }
1542
1714
  })
1543
1715
  })
1544
1716
  })
1545
1717
  ]
1546
1718
  }),
1719
+ imageSel && selectedImageRef.current && !imageDialog ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1720
+ className: "rre-img-tool",
1721
+ style: {
1722
+ left: imageSel.left,
1723
+ top: imageSel.top,
1724
+ width: imageSel.width,
1725
+ height: imageSel.height
1726
+ },
1727
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1728
+ type: "button",
1729
+ className: "rre-img-edit",
1730
+ onMouseDown: (event) => event.preventDefault(),
1731
+ onClick: openImageDialog,
1732
+ children: "编辑"
1733
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1734
+ className: "rre-img-handle",
1735
+ title: "点击并拖拽以改变尺寸",
1736
+ onPointerDown: startImageResize
1737
+ })]
1738
+ }) : null,
1739
+ imageDialog ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1740
+ className: "rre-img-dialog-mask",
1741
+ onMouseDown: (event) => {
1742
+ if (event.target === event.currentTarget) setImageDialog(null);
1743
+ },
1744
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1745
+ className: "rre-img-dialog",
1746
+ role: "dialog",
1747
+ "aria-modal": "true",
1748
+ "aria-label": "图像属性",
1749
+ children: [
1750
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1751
+ className: "rre-img-dialog-head",
1752
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("b", { children: "图像属性" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1753
+ type: "button",
1754
+ onClick: () => setImageDialog(null),
1755
+ "aria-label": "关闭",
1756
+ title: "关闭",
1757
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
1758
+ width: "14",
1759
+ height: "14",
1760
+ viewBox: "0 0 24 24",
1761
+ fill: "none",
1762
+ stroke: "currentColor",
1763
+ strokeWidth: "2",
1764
+ strokeLinecap: "round",
1765
+ "aria-hidden": "true",
1766
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "m6 6 12 12M18 6 6 18" })
1767
+ })
1768
+ })]
1769
+ }),
1770
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1771
+ className: "rre-img-field",
1772
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "图片 URL" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1773
+ value: imageDialog.url,
1774
+ onChange: (event) => setImageDialog({
1775
+ ...imageDialog,
1776
+ url: event.target.value
1777
+ })
1778
+ })]
1779
+ }),
1780
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1781
+ className: "rre-img-field",
1782
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "替换文本" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1783
+ value: imageDialog.alt,
1784
+ onChange: (event) => setImageDialog({
1785
+ ...imageDialog,
1786
+ alt: event.target.value
1787
+ })
1788
+ })]
1789
+ }),
1790
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1791
+ className: "rre-img-size",
1792
+ children: [
1793
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1794
+ className: "rre-img-field",
1795
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "宽度(px)" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1796
+ type: "number",
1797
+ min: 20,
1798
+ max: 4e3,
1799
+ value: imageDialog.width,
1800
+ onChange: (event) => {
1801
+ const width = Math.max(20, Math.min(4e3, Number(event.target.value) || 20));
1802
+ setImageDialog({
1803
+ ...imageDialog,
1804
+ width,
1805
+ height: imageDialog.lock ? calcImageHeight(width) : imageDialog.height
1806
+ });
1807
+ }
1808
+ })]
1809
+ }),
1810
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1811
+ className: "rre-img-field",
1812
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "高度(px)" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1813
+ type: "number",
1814
+ min: 1,
1815
+ value: imageDialog.height || "",
1816
+ readOnly: imageDialog.lock,
1817
+ onChange: (event) => setImageDialog({
1818
+ ...imageDialog,
1819
+ height: Math.max(1, Number(event.target.value) || 1)
1820
+ })
1821
+ })]
1822
+ }),
1823
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1824
+ className: "rre-img-size-tools",
1825
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1826
+ type: "button",
1827
+ className: imageDialog.lock ? "is-on" : "",
1828
+ title: imageDialog.lock ? "解锁比例" : "锁定比例",
1829
+ onClick: () => setImageDialog({
1830
+ ...imageDialog,
1831
+ lock: !imageDialog.lock,
1832
+ height: !imageDialog.lock ? calcImageHeight(imageDialog.width) : imageDialog.height
1833
+ }),
1834
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
1835
+ width: "15",
1836
+ height: "15",
1837
+ viewBox: "0 0 24 24",
1838
+ fill: "none",
1839
+ stroke: "currentColor",
1840
+ strokeWidth: "1.8",
1841
+ strokeLinecap: "round",
1842
+ strokeLinejoin: "round",
1843
+ "aria-hidden": "true",
1844
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
1845
+ x: "5",
1846
+ y: "10",
1847
+ width: "14",
1848
+ height: "10",
1849
+ rx: "2"
1850
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M8.5 10V7.5a3.5 3.5 0 0 1 7 0V10" })]
1851
+ })
1852
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1853
+ type: "button",
1854
+ title: "恢复原始尺寸",
1855
+ onClick: resetImageSize,
1856
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
1857
+ width: "15",
1858
+ height: "15",
1859
+ viewBox: "0 0 24 24",
1860
+ fill: "none",
1861
+ stroke: "currentColor",
1862
+ strokeWidth: "1.8",
1863
+ strokeLinecap: "round",
1864
+ strokeLinejoin: "round",
1865
+ "aria-hidden": "true",
1866
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M20 12a8 8 0 1 1-2.3-5.7" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M20 4v5h-5" })]
1867
+ })
1868
+ })]
1869
+ })
1870
+ ]
1871
+ }),
1872
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1873
+ className: "rre-img-align",
1874
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "对齐方式" }), [
1875
+ ["none", "无"],
1876
+ ["left", "左对齐"],
1877
+ ["center", "居中"],
1878
+ ["right", "右对齐"]
1879
+ ].map(([value, label]) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1880
+ type: "radio",
1881
+ name: "rre-img-align",
1882
+ checked: imageDialog.align === value,
1883
+ onChange: () => setImageDialog({
1884
+ ...imageDialog,
1885
+ align: value
1886
+ })
1887
+ }), label] }, value))]
1888
+ }),
1889
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1890
+ className: "rre-img-caption-toggle",
1891
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1892
+ type: "checkbox",
1893
+ checked: imageDialog.caption,
1894
+ onChange: (event) => setImageDialog({
1895
+ ...imageDialog,
1896
+ caption: event.target.checked
1897
+ })
1898
+ }), "带标题图像"]
1899
+ }),
1900
+ imageDialog.caption ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1901
+ className: "rre-img-field",
1902
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "图注" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1903
+ value: imageDialog.captionText,
1904
+ onChange: (event) => setImageDialog({
1905
+ ...imageDialog,
1906
+ captionText: event.target.value
1907
+ }),
1908
+ placeholder: "图片下方的说明文字"
1909
+ })]
1910
+ }) : null,
1911
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1912
+ className: "rre-img-dialog-foot",
1913
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1914
+ type: "button",
1915
+ className: "rre-btn",
1916
+ onClick: () => setImageDialog(null),
1917
+ children: "取消"
1918
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1919
+ type: "button",
1920
+ className: "rre-btn rre-btn-primary",
1921
+ onClick: applyImageDialog,
1922
+ children: "确定"
1923
+ })]
1924
+ })
1925
+ ]
1926
+ })
1927
+ }) : null,
1547
1928
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1548
1929
  ref: imageRef,
1549
1930
  type: "file",
@@ -2255,7 +2636,7 @@ function MarkdownEditor({ markdown, onChange, onUploadImage, renderMarkdown = de
2255
2636
  setError("");
2256
2637
  try {
2257
2638
  const url = await onUploadImage(file);
2258
- insertAtCursor(`![${file.name.replace(/\.[^.]+$/, "")}](${url})`, "", file.name);
2639
+ insertAtCursor(`![${file.name.replace(/\.[^.]+$/, "")}](${url} "kbw=640")`, "", file.name);
2259
2640
  } catch (err) {
2260
2641
  setError(err instanceof Error ? err.message : "图片上传失败");
2261
2642
  } finally {