@zhenryx/react-editor 0.1.1 → 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 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,120 @@ 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
+ const width = Math.max(20, Math.min(4e3, Number(imageDialog.width) || 20));
1316
+ const height = Math.max(0, Number(imageDialog.height) || 0);
1317
+ img.setAttribute("src", src);
1318
+ img.setAttribute("alt", imageDialog.alt);
1319
+ img.setAttribute("data-kb-w", String(width));
1320
+ img.style.setProperty("--kbw", `${width}px`);
1321
+ if (imageDialog.lock || height <= 0) {
1322
+ img.removeAttribute("data-kb-h");
1323
+ img.style.removeProperty("--kbh");
1324
+ } else {
1325
+ img.setAttribute("data-kb-h", String(height));
1326
+ img.style.setProperty("--kbh", `${height}px`);
1327
+ }
1328
+ if (imageDialog.align === "none") img.removeAttribute("data-kb-align");
1329
+ else img.setAttribute("data-kb-align", imageDialog.align);
1330
+ if (imageDialog.caption && imageDialog.captionText.trim()) img.setAttribute("data-kb-caption", imageDialog.captionText.trim());
1331
+ else img.removeAttribute("data-kb-caption");
1332
+ setImageDialog(null);
1333
+ clearImageSelection();
1334
+ sync();
1335
+ const el = editorRef.current;
1336
+ if (el) {
1337
+ const md = htmlToMarkdown(el.innerHTML);
1338
+ el.innerHTML = renderMarkdown(md);
1339
+ lastMd.current = md;
1340
+ }
1341
+ }
1342
+ function resetImageSize() {
1343
+ const img = selectedImageRef.current;
1344
+ const containerWidth = editorRef.current?.clientWidth || 1;
1345
+ if (!img) return;
1346
+ const naturalWidth = Math.max(40, Math.min(containerWidth, img.naturalWidth || 640));
1347
+ setImageDialog((prev) => prev ? {
1348
+ ...prev,
1349
+ width: naturalWidth,
1350
+ height: calcImageHeight(naturalWidth),
1351
+ lock: true
1352
+ } : prev);
1353
+ }
1190
1354
  function toolButton(label, icon, onClick, opts = {}) {
1191
1355
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1192
1356
  type: "button",
@@ -1213,7 +1377,10 @@ function RichTextEditor({ markdown, onChange, onUploadImage, onSwitchToMarkdown,
1213
1377
  event.preventDefault();
1214
1378
  saveRange();
1215
1379
  },
1216
- onClick: (event) => openPopover(kind, event.currentTarget),
1380
+ onClick: (event) => {
1381
+ if (popover?.kind === kind) setPopover(null);
1382
+ else openPopover(kind, event.currentTarget);
1383
+ },
1217
1384
  children: [icon, /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1218
1385
  className: withCaret ? "rre-popover-label" : void 0,
1219
1386
  children: [label, withCaret ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
@@ -1538,12 +1705,250 @@ function RichTextEditor({ markdown, onChange, onUploadImage, onSwitchToMarkdown,
1538
1705
  "data-placeholder": placeholder,
1539
1706
  onInput: sync,
1540
1707
  onBlur: sync,
1541
- onPaste
1708
+ onPaste,
1709
+ onClick: (event) => {
1710
+ const img = event.target?.closest("img");
1711
+ if (img && editorRef.current?.contains(img)) {
1712
+ event.preventDefault();
1713
+ selectImage(img);
1714
+ }
1715
+ }
1542
1716
  })
1543
1717
  })
1544
1718
  })
1545
1719
  ]
1546
1720
  }),
1721
+ imageSel && selectedImageRef.current && !imageDialog ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1722
+ className: "rre-img-tool",
1723
+ style: {
1724
+ left: imageSel.left,
1725
+ top: imageSel.top,
1726
+ width: imageSel.width,
1727
+ height: imageSel.height
1728
+ },
1729
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1730
+ type: "button",
1731
+ className: "rre-img-edit",
1732
+ onMouseDown: (event) => event.preventDefault(),
1733
+ onClick: openImageDialog,
1734
+ children: "编辑"
1735
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1736
+ className: "rre-img-handle",
1737
+ title: "点击并拖拽以改变尺寸",
1738
+ onPointerDown: startImageResize
1739
+ })]
1740
+ }) : null,
1741
+ imageDialog ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1742
+ className: "rre-img-dialog-mask",
1743
+ onMouseDown: (event) => {
1744
+ if (event.target === event.currentTarget) setImageDialog(null);
1745
+ },
1746
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1747
+ className: "rre-img-dialog",
1748
+ role: "dialog",
1749
+ "aria-modal": "true",
1750
+ "aria-label": "图像属性",
1751
+ children: [
1752
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1753
+ className: "rre-img-dialog-head",
1754
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("b", { children: "图像属性" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1755
+ type: "button",
1756
+ onClick: () => setImageDialog(null),
1757
+ "aria-label": "关闭",
1758
+ title: "关闭",
1759
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
1760
+ width: "14",
1761
+ height: "14",
1762
+ viewBox: "0 0 24 24",
1763
+ fill: "none",
1764
+ stroke: "currentColor",
1765
+ strokeWidth: "2",
1766
+ strokeLinecap: "round",
1767
+ "aria-hidden": "true",
1768
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "m6 6 12 12M18 6 6 18" })
1769
+ })
1770
+ })]
1771
+ }),
1772
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1773
+ className: "rre-img-field",
1774
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "图片 URL" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1775
+ value: imageDialog.url,
1776
+ onChange: (event) => setImageDialog({
1777
+ ...imageDialog,
1778
+ url: event.target.value
1779
+ })
1780
+ })]
1781
+ }),
1782
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1783
+ className: "rre-img-field",
1784
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "替换文本" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1785
+ value: imageDialog.alt,
1786
+ onChange: (event) => setImageDialog({
1787
+ ...imageDialog,
1788
+ alt: event.target.value
1789
+ })
1790
+ })]
1791
+ }),
1792
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1793
+ className: "rre-img-size",
1794
+ children: [
1795
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1796
+ className: "rre-img-field",
1797
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "宽度(px)" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1798
+ type: "number",
1799
+ min: 20,
1800
+ max: 4e3,
1801
+ value: imageDialog.width,
1802
+ onFocus: (event) => event.currentTarget.select(),
1803
+ onChange: (event) => {
1804
+ const raw = event.target.value;
1805
+ const width = raw === "" ? "" : Math.max(0, Math.min(4e3, Number(raw) || 0));
1806
+ setImageDialog({
1807
+ ...imageDialog,
1808
+ width,
1809
+ height: imageDialog.lock ? width === "" || width < 20 ? "" : calcImageHeight(width) : imageDialog.height
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
+ }
1821
+ }
1822
+ })]
1823
+ }),
1824
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1825
+ className: "rre-img-field",
1826
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "高度(px)" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1827
+ type: "number",
1828
+ min: 1,
1829
+ value: imageDialog.height,
1830
+ readOnly: imageDialog.lock,
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
+ }
1845
+ })]
1846
+ }),
1847
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1848
+ className: "rre-img-size-tools",
1849
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1850
+ type: "button",
1851
+ className: imageDialog.lock ? "is-on" : "",
1852
+ title: imageDialog.lock ? "解锁比例" : "锁定比例",
1853
+ onClick: () => setImageDialog({
1854
+ ...imageDialog,
1855
+ lock: !imageDialog.lock,
1856
+ height: !imageDialog.lock ? calcImageHeight(Number(imageDialog.width) || 20) : imageDialog.height
1857
+ }),
1858
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
1859
+ width: "15",
1860
+ height: "15",
1861
+ viewBox: "0 0 24 24",
1862
+ fill: "none",
1863
+ stroke: "currentColor",
1864
+ strokeWidth: "1.8",
1865
+ strokeLinecap: "round",
1866
+ strokeLinejoin: "round",
1867
+ "aria-hidden": "true",
1868
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
1869
+ x: "5",
1870
+ y: "10",
1871
+ width: "14",
1872
+ height: "10",
1873
+ rx: "2"
1874
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M8.5 10V7.5a3.5 3.5 0 0 1 7 0V10" })]
1875
+ })
1876
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1877
+ type: "button",
1878
+ title: "恢复原始尺寸",
1879
+ onClick: resetImageSize,
1880
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
1881
+ width: "15",
1882
+ height: "15",
1883
+ viewBox: "0 0 24 24",
1884
+ fill: "none",
1885
+ stroke: "currentColor",
1886
+ strokeWidth: "1.8",
1887
+ strokeLinecap: "round",
1888
+ strokeLinejoin: "round",
1889
+ "aria-hidden": "true",
1890
+ 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" })]
1891
+ })
1892
+ })]
1893
+ })
1894
+ ]
1895
+ }),
1896
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1897
+ className: "rre-img-align",
1898
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "对齐方式" }), [
1899
+ ["none", "无"],
1900
+ ["left", "左对齐"],
1901
+ ["center", "居中"],
1902
+ ["right", "右对齐"]
1903
+ ].map(([value, label]) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1904
+ type: "radio",
1905
+ name: "rre-img-align",
1906
+ checked: imageDialog.align === value,
1907
+ onChange: () => setImageDialog({
1908
+ ...imageDialog,
1909
+ align: value
1910
+ })
1911
+ }), label] }, value))]
1912
+ }),
1913
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1914
+ className: "rre-img-caption-toggle",
1915
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1916
+ type: "checkbox",
1917
+ checked: imageDialog.caption,
1918
+ onChange: (event) => setImageDialog({
1919
+ ...imageDialog,
1920
+ caption: event.target.checked
1921
+ })
1922
+ }), "带标题图像"]
1923
+ }),
1924
+ imageDialog.caption ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1925
+ className: "rre-img-field",
1926
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "图注" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1927
+ value: imageDialog.captionText,
1928
+ onChange: (event) => setImageDialog({
1929
+ ...imageDialog,
1930
+ captionText: event.target.value
1931
+ }),
1932
+ placeholder: "图片下方的说明文字"
1933
+ })]
1934
+ }) : null,
1935
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1936
+ className: "rre-img-dialog-foot",
1937
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1938
+ type: "button",
1939
+ className: "rre-btn",
1940
+ onClick: () => setImageDialog(null),
1941
+ children: "取消"
1942
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1943
+ type: "button",
1944
+ className: "rre-btn rre-btn-primary",
1945
+ onClick: applyImageDialog,
1946
+ children: "确定"
1947
+ })]
1948
+ })
1949
+ ]
1950
+ })
1951
+ }) : null,
1547
1952
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1548
1953
  ref: imageRef,
1549
1954
  type: "file",
@@ -2255,7 +2660,7 @@ function MarkdownEditor({ markdown, onChange, onUploadImage, renderMarkdown = de
2255
2660
  setError("");
2256
2661
  try {
2257
2662
  const url = await onUploadImage(file);
2258
- insertAtCursor(`![${file.name.replace(/\.[^.]+$/, "")}](${url})`, "", file.name);
2663
+ insertAtCursor(`![${file.name.replace(/\.[^.]+$/, "")}](${url} "kbw=640")`, "", file.name);
2259
2664
  } catch (err) {
2260
2665
  setError(err instanceof Error ? err.message : "图片上传失败");
2261
2666
  } finally {