Vanessa 2023-12-06 16:51:45 +08:00
parent 450e862f92
commit ee21fd8d96
4 changed files with 16 additions and 28 deletions

View file

@ -292,6 +292,7 @@ export abstract class Constants {
copyID: {default: "", custom: ""}, copyID: {default: "", custom: ""},
copyProtocolInMd: {default: "", custom: ""}, copyProtocolInMd: {default: "", custom: ""},
netImg2LocalAsset: {default: "", custom: ""}, netImg2LocalAsset: {default: "", custom: ""},
netAssets2LocalAssets: {default: "", custom: ""},
optimizeTypography: {default: "", custom: ""}, optimizeTypography: {default: "", custom: ""},
hLayout: {default: "", custom: ""}, hLayout: {default: "", custom: ""},
vLayout: {default: "", custom: ""}, vLayout: {default: "", custom: ""},

View file

@ -9,34 +9,13 @@ import {hasClosestByClassName} from "../util/hasClosest";
import {reloadProtyle} from "../util/reload"; import {reloadProtyle} from "../util/reload";
import {resize} from "../util/resize"; import {resize} from "../util/resize";
export const netAssets2LocalAssets = (protyle: IProtyle) => { export const net2LocalAssets = (protyle: IProtyle, type: "Assets" | "Img") => {
if (protyle.element.querySelector(".wysiwygLoading")) { if (protyle.element.querySelector(".wysiwygLoading")) {
return; return;
} }
addLoading(protyle); addLoading(protyle);
hideElements(["toolbar"], protyle); hideElements(["toolbar"], protyle);
fetchPost("/api/format/netAssets2LocalAssets", { fetchPost(`/api/format/net${type}2LocalAssets`, {
id: protyle.block.rootID
}, () => {
/// #if MOBILE
reloadProtyle(protyle, false);
/// #else
getAllModels().editor.forEach(item => {
if (item.editor.protyle.block.rootID === protyle.block.rootID) {
reloadProtyle(item.editor.protyle, item.editor.protyle.element.isSameNode(protyle.element));
}
});
/// #endif
});
};
export const netImg2LocalAssets = (protyle: IProtyle) => {
if (protyle.element.querySelector(".wysiwygLoading")) {
return;
}
addLoading(protyle);
hideElements(["toolbar"], protyle);
fetchPost("/api/format/netImg2LocalAssets", {
id: protyle.block.rootID id: protyle.block.rootID
}, () => { }, () => {
/// #if MOBILE /// #if MOBILE

View file

@ -2,7 +2,7 @@ import {getIconByType} from "../../editor/getIcon";
import {fetchPost} from "../../util/fetch"; import {fetchPost} from "../../util/fetch";
import {Constants} from "../../constants"; import {Constants} from "../../constants";
import {MenuItem} from "../../menus/Menu"; import {MenuItem} from "../../menus/Menu";
import {fullscreen, netAssets2LocalAssets, netImg2LocalAssets} from "./action"; import {fullscreen, net2LocalAssets} from "./action";
import {openFileAttr} from "../../menus/commonMenuItem"; import {openFileAttr} from "../../menus/commonMenuItem";
import {setEditMode} from "../util/setEditMode"; import {setEditMode} from "../util/setEditMode";
import {RecordMedia} from "../util/RecordMedia"; import {RecordMedia} from "../util/RecordMedia";
@ -338,14 +338,15 @@ export class Breadcrumb {
icon: "iconTransform", icon: "iconTransform",
accelerator: window.siyuan.config.keymap.editor.general.netImg2LocalAsset.custom, accelerator: window.siyuan.config.keymap.editor.general.netImg2LocalAsset.custom,
click() { click() {
netImg2LocalAssets(protyle); net2LocalAssets(protyle, "Img");
} }
}).element); }).element);
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.netAssets2LocalAssets, label: window.siyuan.languages.netAssets2LocalAssets,
icon: "iconTransform", icon: "iconTransform",
accelerator: window.siyuan.config.keymap.editor.general.netAssets2LocalAssets.custom,
click() { click() {
netAssets2LocalAssets(protyle); net2LocalAssets(protyle, "Assets");
} }
}).element); }).element);
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({

View file

@ -6,7 +6,6 @@ import {
getSelectionOffset, getSelectionOffset,
setFirstNodeRange, setFirstNodeRange,
} from "../util/selection"; } from "../util/selection";
import {netImg2LocalAssets} from "../breadcrumb/action";
import {getContenteditableElement, hasNextSibling, hasPreviousSibling} from "./getBlock"; import {getContenteditableElement, hasNextSibling, hasPreviousSibling} from "./getBlock";
import {hasClosestByMatchTag} from "../util/hasClosest"; import {hasClosestByMatchTag} from "../util/hasClosest";
import {hideElements} from "../ui/hideElements"; import {hideElements} from "../ui/hideElements";
@ -16,6 +15,7 @@ import {transaction, updateTransaction} from "./transaction";
import {onGet} from "../util/onGet"; import {onGet} from "../util/onGet";
import {Constants} from "../../constants"; import {Constants} from "../../constants";
import * as dayjs from "dayjs"; import * as dayjs from "dayjs";
import {net2LocalAssets} from "../breadcrumb/action";
export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent, nodeElement?: HTMLElement) => { export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent, nodeElement?: HTMLElement) => {
if (matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) { if (matchHotKey(window.siyuan.config.keymap.editor.general.copyHPath.custom, event)) {
@ -30,7 +30,14 @@ export const commonHotkey = (protyle: IProtyle, event: KeyboardEvent, nodeElemen
} }
if (matchHotKey(window.siyuan.config.keymap.editor.general.netImg2LocalAsset.custom, event)) { if (matchHotKey(window.siyuan.config.keymap.editor.general.netImg2LocalAsset.custom, event)) {
netImg2LocalAssets(protyle); net2LocalAssets(protyle, "Img");
event.preventDefault();
event.stopPropagation();
return true;
}
if (matchHotKey(window.siyuan.config.keymap.editor.general.netAssets2LocalAssets.custom, event)) {
net2LocalAssets(protyle, "Assets");
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return true; return true;