Skip to content

Commit 59360f3

Browse files
committedDec 20, 2024
1 parent 20b4579 commit 59360f3

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed
 

‎app/src/boot/compatibleVersion.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export const img3115 = (imgElement: HTMLElement) => {
2+
// 移除 3.1.15 以前 .img width 样式
3+
if (imgElement.style.minWidth) {
4+
// 居中需要 minWidth 样式,不能移除 style 属性
5+
imgElement.style.width = "";
6+
} else {
7+
imgElement.removeAttribute("style");
8+
}
9+
}

‎app/src/menus/protyle.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {Menu} from "../plugin/Menu";
5959
import {getFirstBlock} from "../protyle/wysiwyg/getBlock";
6060
import {popSearch} from "../mobile/menu/search";
6161
import {showMessage} from "../dialog/message";
62+
import {img3115} from "../boot/compatibleVersion";
6263

6364
const renderAssetList = (element: Element, k: string, position: IPosition, exts: string[] = []) => {
6465
fetchPost("/api/search/searchAsset", {
@@ -1188,8 +1189,7 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme
11881189
rangeElement.value = "0";
11891190
rangeElement.parentElement.setAttribute("aria-label", inputElement.value ? (inputElement.value + "px") : window.siyuan.languages.default);
11901191

1191-
// 历史兼容
1192-
assetElement.removeAttribute("style");
1192+
img3115(assetElement)
11931193
imgElement.parentElement.style.width = inputElement.value ? (inputElement.value + "px") : "";
11941194
imgElement.style.height = "";
11951195
});
@@ -1220,8 +1220,7 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme
12201220
bind(element) {
12211221
rangeElement = element.querySelector("input");
12221222
rangeElement.addEventListener("input", () => {
1223-
// 历史兼容
1224-
assetElement.removeAttribute("style");
1223+
img3115(assetElement)
12251224
imgElement.parentElement.style.width = rangeElement.value + "%";
12261225
imgElement.style.height = "";
12271226
rangeElement.parentElement.setAttribute("aria-label", `${rangeElement.value}%`);
@@ -1255,8 +1254,7 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme
12551254
rangeHeightElement.parentElement.setAttribute("aria-label", inputElement.value ? (inputElement.value + "px") : window.siyuan.languages.default);
12561255

12571256
imgElement.style.height = inputElement.value ? (inputElement.value + "px") : "";
1258-
// 历史兼容
1259-
assetElement.removeAttribute("style");
1257+
img3115(assetElement)
12601258
imgElement.parentElement.style.width = "";
12611259
});
12621260
inputElement.addEventListener("blur", () => {
@@ -1286,8 +1284,7 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme
12861284
bind(element) {
12871285
rangeHeightElement = element.querySelector("input");
12881286
rangeHeightElement.addEventListener("input", () => {
1289-
// 历史兼容
1290-
assetElement.removeAttribute("style");
1287+
img3115(assetElement)
12911288
imgElement.parentElement.style.width = "";
12921289
imgElement.style.height = rangeHeightElement.value + "vh";
12931290
rangeHeightElement.parentElement.setAttribute("aria-label", `${rangeHeightElement.value}%`);
@@ -1828,8 +1825,7 @@ const genImageWidthMenu = (label: string, imgElement: HTMLElement, protyle: IPro
18281825
label,
18291826
click() {
18301827
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
1831-
// 历史兼容
1832-
imgElement.parentElement.parentElement.removeAttribute("style");
1828+
img3115(imgElement.parentElement.parentElement)
18331829
imgElement.parentElement.style.width = label === window.siyuan.languages.default ? "" : label;
18341830
imgElement.style.height = "";
18351831
updateTransaction(protyle, id, nodeElement.outerHTML, html);
@@ -1845,8 +1841,7 @@ const genImageHeightMenu = (label: string, imgElement: HTMLElement, protyle: IPr
18451841
click() {
18461842
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
18471843
imgElement.style.height = label === window.siyuan.languages.default ? "" : parseInt(label) + "vh";
1848-
// 历史兼容
1849-
imgElement.parentElement.parentElement.removeAttribute("style");
1844+
img3115(imgElement.parentElement.parentElement)
18501845
imgElement.parentElement.style.width = "";
18511846
updateTransaction(protyle, id, nodeElement.outerHTML, html);
18521847
focusBlock(nodeElement);

‎app/src/protyle/wysiwyg/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ import {openEmojiPanel, unicode2Emoji} from "../../emoji";
9595
import {openLink} from "../../editor/openLink";
9696
import {mathRender} from "../render/mathRender";
9797
import {editAssetItem} from "../render/av/asset";
98+
import {img3115} from "../../boot/compatibleVersion";
9899

99100
export class WYSIWYG {
100101
public lastHTMLs: { [key: string]: string } = {};
@@ -669,14 +670,17 @@ export class WYSIWYG {
669670
const dragElement = target.previousElementSibling as HTMLElement;
670671
const dragWidth = dragElement.clientWidth;
671672
const dragHeight = dragElement.clientHeight;
673+
674+
const imgElement = dragElement.parentElement.parentElement
675+
if (dragElement.tagName === "IMG") {
676+
img3115(imgElement)
677+
}
672678
documentSelf.onmousemove = (moveEvent: MouseEvent) => {
673679
if (dragElement.tagName === "IMG") {
674680
dragElement.style.height = "";
675-
// 历史兼容
676-
dragElement.parentElement.parentElement.removeAttribute("style");
677681
}
678682
if (moveEvent.clientX > x - dragWidth + 8 && moveEvent.clientX < mostRight) {
679-
const multiple = ((dragElement.tagName === "IMG" && !dragElement.parentElement.parentElement.style.minWidth && nodeElement.style.textAlign !== "center") || !isCenter) ? 1 : 2;
683+
const multiple = ((dragElement.tagName === "IMG" && !imgElement.style.minWidth && nodeElement.style.textAlign !== "center") || !isCenter) ? 1 : 2;
680684
if (dragElement.tagName === "IMG") {
681685
dragElement.parentElement.style.width = Math.max(17, dragWidth + (moveEvent.clientX - x) * multiple) + "px";
682686
} else {
@@ -1484,7 +1488,7 @@ export class WYSIWYG {
14841488
}
14851489
});
14861490
tableSelectElement.removeAttribute("style");
1487-
if (getSelection().rangeCount>0) {
1491+
if (getSelection().rangeCount > 0) {
14881492
const range = getSelection().getRangeAt(0);
14891493
if (nodeElement.contains(range.startContainer)) {
14901494
range.insertNode(document.createElement("wbr"));

0 commit comments

Comments
 (0)
Please sign in to comment.