mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-12 23:21:23 +08:00
This commit is contained in:
parent
09fb905764
commit
7bbbc8ae32
@ -174,7 +174,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
|
|||||||
if (customHTML) {
|
if (customHTML) {
|
||||||
customHTML = `<div class="b3-menu__separator"></div>${customHTML}`;
|
customHTML = `<div class="b3-menu__separator"></div>${customHTML}`;
|
||||||
}
|
}
|
||||||
const clearContext = "Clear context"
|
const clearContext = "Clear context";
|
||||||
menu.addItem({
|
menu.addItem({
|
||||||
iconHTML: "",
|
iconHTML: "",
|
||||||
type: "empty",
|
type: "empty",
|
||||||
@ -237,7 +237,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
|
|||||||
fillContent(protyle, response.data, elements);
|
fillContent(protyle, response.data, elements);
|
||||||
});
|
});
|
||||||
if (currentElement.dataset.action === clearContext) {
|
if (currentElement.dataset.action === clearContext) {
|
||||||
showMessage(window.siyuan.languages.clearContextSucc)
|
showMessage(window.siyuan.languages.clearContextSucc);
|
||||||
} else {
|
} else {
|
||||||
menu.close();
|
menu.close();
|
||||||
}
|
}
|
||||||
@ -272,7 +272,7 @@ export const AIActions = (elements: Element[], protyle: IProtyle) => {
|
|||||||
fillContent(protyle, response.data, elements);
|
fillContent(protyle, response.data, elements);
|
||||||
});
|
});
|
||||||
if (target.dataset.action === clearContext) {
|
if (target.dataset.action === clearContext) {
|
||||||
showMessage(window.siyuan.languages.clearContextSucc)
|
showMessage(window.siyuan.languages.clearContextSucc);
|
||||||
} else {
|
} else {
|
||||||
menu.close();
|
menu.close();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {getWorkspaceName} from "../util/noRelyPCFunction";
|
import {getWorkspaceName} from "../util/noRelyPCFunction";
|
||||||
import {isHuawei, isInAndroid, isInIOS, setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
|
import {isInAndroid, isInIOS, setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
|
||||||
import {exitSiYuan, processSync} from "../dialog/processSystem";
|
import {exitSiYuan, processSync} from "../dialog/processSystem";
|
||||||
import {goBack, goForward} from "../util/backForward";
|
import {goBack, goForward} from "../util/backForward";
|
||||||
import {syncGuide} from "../sync/syncGuide";
|
import {syncGuide} from "../sync/syncGuide";
|
||||||
@ -14,12 +14,12 @@ import {webFrame} from "electron";
|
|||||||
/// #endif
|
/// #endif
|
||||||
import {Constants} from "../constants";
|
import {Constants} from "../constants";
|
||||||
import {isBrowser, isWindow} from "../util/functions";
|
import {isBrowser, isWindow} from "../util/functions";
|
||||||
import {Menu} from "../plugin/Menu";
|
|
||||||
import {fetchPost} from "../util/fetch";
|
import {fetchPost} from "../util/fetch";
|
||||||
import {needSubscribe} from "../util/needSubscribe";
|
import {needSubscribe} from "../util/needSubscribe";
|
||||||
import * as dayjs from "dayjs";
|
import * as dayjs from "dayjs";
|
||||||
import {exportLayout} from "./util";
|
import {exportLayout} from "./util";
|
||||||
import {commandPanel} from "../boot/globalEvent/command/panel";
|
import {commandPanel} from "../boot/globalEvent/command/panel";
|
||||||
|
import {openTopBarMenu} from "../plugin/openTopBarMenu";
|
||||||
|
|
||||||
export const initBar = (app: App) => {
|
export const initBar = (app: App) => {
|
||||||
const toolbarElement = document.getElementById("toolbar");
|
const toolbarElement = document.getElementById("toolbar");
|
||||||
@ -179,7 +179,7 @@ export const initBar = (app: App) => {
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
} else if (targetId === "barPlugins") {
|
} else if (targetId === "barPlugins") {
|
||||||
openPlugin(app, target);
|
openTopBarMenu(app, target);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
} else if (targetId === "barCommand") {
|
} else if (targetId === "barCommand") {
|
||||||
@ -298,86 +298,3 @@ export const setZoom = (type: "zoomIn" | "zoomOut" | "restore") => {
|
|||||||
}
|
}
|
||||||
/// #endif
|
/// #endif
|
||||||
};
|
};
|
||||||
|
|
||||||
const openPlugin = (app: App, target: Element) => {
|
|
||||||
const menu = new Menu("topBarPlugin");
|
|
||||||
menu.addItem({
|
|
||||||
icon: "iconSettings",
|
|
||||||
label: window.siyuan.languages.manage,
|
|
||||||
ignore: isHuawei() || window.siyuan.config.readonly,
|
|
||||||
click() {
|
|
||||||
openSetting(app).element.querySelector('.b3-tab-bar [data-name="bazaar"]').dispatchEvent(new CustomEvent("click"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
menu.addSeparator(undefined, isHuawei() || window.siyuan.config.readonly);
|
|
||||||
let hasPlugin = false;
|
|
||||||
app.plugins.forEach((plugin) => {
|
|
||||||
// @ts-ignore
|
|
||||||
const hasSetting = plugin.setting || plugin.__proto__.hasOwnProperty("openSetting");
|
|
||||||
let hasTopBar = false;
|
|
||||||
plugin.topBarIcons.forEach(item => {
|
|
||||||
const hasUnpin = window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].includes(item.id);
|
|
||||||
const submenu = [{
|
|
||||||
icon: hasUnpin ? "iconPin" : "iconUnpin",
|
|
||||||
label: hasUnpin ? window.siyuan.languages.pin : window.siyuan.languages.unpin,
|
|
||||||
click() {
|
|
||||||
if (hasUnpin) {
|
|
||||||
window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].splice(window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].indexOf(item.id), 1);
|
|
||||||
item.classList.remove("fn__none");
|
|
||||||
} else {
|
|
||||||
window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].push(item.id);
|
|
||||||
window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN] = Array.from(new Set(window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN]));
|
|
||||||
item.classList.add("fn__none");
|
|
||||||
}
|
|
||||||
setStorageVal(Constants.LOCAL_PLUGINTOPUNPIN, window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN]);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
if (hasSetting) {
|
|
||||||
submenu.push({
|
|
||||||
icon: "iconSettings",
|
|
||||||
label: window.siyuan.languages.config,
|
|
||||||
click() {
|
|
||||||
plugin.openSetting();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const menuOption: IMenu = {
|
|
||||||
icon: "iconInfo",
|
|
||||||
label: item.getAttribute("aria-label"),
|
|
||||||
click() {
|
|
||||||
item.dispatchEvent(new CustomEvent("click"));
|
|
||||||
},
|
|
||||||
type: "submenu",
|
|
||||||
submenu
|
|
||||||
};
|
|
||||||
if (item.querySelector("use")) {
|
|
||||||
menuOption.icon = item.querySelector("use").getAttribute("xlink:href").replace("#", "");
|
|
||||||
} else {
|
|
||||||
const svgElement = item.querySelector("svg").cloneNode(true) as HTMLElement;
|
|
||||||
svgElement.classList.add("b3-menu__icon");
|
|
||||||
menuOption.iconHTML = svgElement.outerHTML;
|
|
||||||
}
|
|
||||||
menu.addItem(menuOption);
|
|
||||||
hasPlugin = true;
|
|
||||||
hasTopBar = true;
|
|
||||||
});
|
|
||||||
if (!hasTopBar && hasSetting) {
|
|
||||||
hasPlugin = true;
|
|
||||||
menu.addItem({
|
|
||||||
icon: "iconSettings",
|
|
||||||
label: plugin.displayName,
|
|
||||||
click() {
|
|
||||||
plugin.openSetting();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (!hasPlugin) {
|
|
||||||
window.siyuan.menus.menu.element.querySelector(".b3-menu__separator")?.remove();
|
|
||||||
}
|
|
||||||
let rect = target.getBoundingClientRect();
|
|
||||||
if (rect.width === 0) {
|
|
||||||
rect = document.querySelector("#barMore").getBoundingClientRect();
|
|
||||||
}
|
|
||||||
menu.open({x: rect.right, y: rect.bottom, isLeft: true});
|
|
||||||
};
|
|
||||||
|
@ -19,8 +19,8 @@ import {App} from "../../index";
|
|||||||
import {isHuawei, isInAndroid, isInIOS, isIPhone} from "../../protyle/util/compatibility";
|
import {isHuawei, isInAndroid, isInIOS, isIPhone} from "../../protyle/util/compatibility";
|
||||||
import {newFile} from "../../util/newFile";
|
import {newFile} from "../../util/newFile";
|
||||||
import {afterLoadPlugin} from "../../plugin/loader";
|
import {afterLoadPlugin} from "../../plugin/loader";
|
||||||
import {Menu} from "../../plugin/Menu";
|
|
||||||
import {commandPanel} from "../../boot/globalEvent/command/panel";
|
import {commandPanel} from "../../boot/globalEvent/command/panel";
|
||||||
|
import {openTopBarMenu} from "../../plugin/openTopBarMenu";
|
||||||
|
|
||||||
export const popMenu = () => {
|
export const popMenu = () => {
|
||||||
activeBlur();
|
activeBlur();
|
||||||
@ -121,14 +121,8 @@ export const initRightMenu = (app: App) => {
|
|||||||
</a>
|
</a>
|
||||||
</div>`;
|
</div>`;
|
||||||
processSync();
|
processSync();
|
||||||
const unPinsMenu: IMenu[] = [];
|
|
||||||
app.plugins.forEach(item => {
|
app.plugins.forEach(item => {
|
||||||
const unPinMenu = afterLoadPlugin(item);
|
afterLoadPlugin(item);
|
||||||
if (unPinMenu) {
|
|
||||||
unPinMenu.forEach(unpinItem => {
|
|
||||||
unPinsMenu.push(unpinItem);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
// 只能用 click,否则无法上下滚动 https://github.com/siyuan-note/siyuan/issues/6628
|
// 只能用 click,否则无法上下滚动 https://github.com/siyuan-note/siyuan/issues/6628
|
||||||
menuElement.addEventListener("click", (event) => {
|
menuElement.addEventListener("click", (event) => {
|
||||||
@ -186,11 +180,7 @@ export const initRightMenu = (app: App) => {
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
} else if (target.id === "menuPlugin") {
|
} else if (target.id === "menuPlugin") {
|
||||||
const menu = new Menu();
|
openTopBarMenu(app);
|
||||||
unPinsMenu.forEach(item => {
|
|
||||||
menu.addItem(item);
|
|
||||||
});
|
|
||||||
menu.fullscreen();
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
|
@ -114,18 +114,9 @@ export const afterLoadPlugin = (plugin: Plugin) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isWindow() || isMobile()) {
|
if (!isWindow() || isMobile()) {
|
||||||
const unPinMenu: IMenu[] = [];
|
|
||||||
plugin.topBarIcons.forEach(element => {
|
plugin.topBarIcons.forEach(element => {
|
||||||
if (isMobile()) {
|
if (isMobile()) {
|
||||||
if (window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].includes(element.id)) {
|
if (!window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].includes(element.id)) {
|
||||||
unPinMenu.push({
|
|
||||||
iconHTML: element.firstElementChild.outerHTML,
|
|
||||||
label: element.textContent.trim(),
|
|
||||||
click() {
|
|
||||||
element.dispatchEvent(new CustomEvent("click"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
document.querySelector("#menuAbout").after(element);
|
document.querySelector("#menuAbout").after(element);
|
||||||
}
|
}
|
||||||
} else if (!isWindow()) {
|
} else if (!isWindow()) {
|
||||||
@ -135,9 +126,6 @@ export const afterLoadPlugin = (plugin: Plugin) => {
|
|||||||
document.querySelector("#" + (element.getAttribute("data-position") === "right" ? "barPlugins" : "drag")).before(element);
|
document.querySelector("#" + (element.getAttribute("data-position") === "right" ? "barPlugins" : "drag")).before(element);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (isMobile() && unPinMenu.length > 0) {
|
|
||||||
return unPinMenu;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
resizeTopBar();
|
resizeTopBar();
|
||||||
|
115
app/src/plugin/openTopBarMenu.ts
Normal file
115
app/src/plugin/openTopBarMenu.ts
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
import {App} from "../index";
|
||||||
|
import {Menu} from "./Menu";
|
||||||
|
import {isHuawei, setStorageVal} from "../protyle/util/compatibility";
|
||||||
|
/// #if !MOBILE
|
||||||
|
import {openSetting} from "../config";
|
||||||
|
/// #endif
|
||||||
|
import {Constants} from "../constants";
|
||||||
|
|
||||||
|
export const openTopBarMenu = (app: App, target?: Element) => {
|
||||||
|
const menu = new Menu("topBarPlugin");
|
||||||
|
/// #if !MOBILE
|
||||||
|
menu.addItem({
|
||||||
|
icon: "iconSettings",
|
||||||
|
label: window.siyuan.languages.manage,
|
||||||
|
ignore: isHuawei() || window.siyuan.config.readonly,
|
||||||
|
click() {
|
||||||
|
openSetting(app).element.querySelector('.b3-tab-bar [data-name="bazaar"]').dispatchEvent(new CustomEvent("click"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menu.addSeparator(undefined, isHuawei() || window.siyuan.config.readonly);
|
||||||
|
/// #endif
|
||||||
|
let hasPlugin = false;
|
||||||
|
app.plugins.forEach((plugin) => {
|
||||||
|
// @ts-ignore
|
||||||
|
const hasSetting = plugin.setting || plugin.__proto__.hasOwnProperty("openSetting");
|
||||||
|
let hasTopBar = false;
|
||||||
|
plugin.topBarIcons.forEach(item => {
|
||||||
|
const hasUnpin = window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].includes(item.id);
|
||||||
|
const submenu = [{
|
||||||
|
icon: hasUnpin ? "iconPin" : "iconUnpin",
|
||||||
|
label: hasUnpin ? window.siyuan.languages.pin : window.siyuan.languages.unpin,
|
||||||
|
click() {
|
||||||
|
if (hasUnpin) {
|
||||||
|
window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].splice(window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].indexOf(item.id), 1);
|
||||||
|
item.classList.remove("fn__none");
|
||||||
|
} else {
|
||||||
|
window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].push(item.id);
|
||||||
|
window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN] = Array.from(new Set(window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN]));
|
||||||
|
item.classList.add("fn__none");
|
||||||
|
}
|
||||||
|
setStorageVal(Constants.LOCAL_PLUGINTOPUNPIN, window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN]);
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
if (hasSetting) {
|
||||||
|
submenu.push({
|
||||||
|
icon: "iconSettings",
|
||||||
|
label: window.siyuan.languages.config,
|
||||||
|
click() {
|
||||||
|
plugin.openSetting();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const itemLabel = target ? item.getAttribute("aria-label") : item.textContent.trim();
|
||||||
|
if (!target) {
|
||||||
|
submenu.push({
|
||||||
|
icon: "iconPlay",
|
||||||
|
label: itemLabel,
|
||||||
|
click() {
|
||||||
|
item.dispatchEvent(new CustomEvent("click"));
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const menuOption: IMenu = {
|
||||||
|
icon: "iconInfo",
|
||||||
|
label: itemLabel,
|
||||||
|
click: target ? () => {
|
||||||
|
item.dispatchEvent(new CustomEvent("click"));
|
||||||
|
} : undefined,
|
||||||
|
type: "submenu",
|
||||||
|
submenu
|
||||||
|
};
|
||||||
|
if (item.querySelector("use")) {
|
||||||
|
menuOption.icon = item.querySelector("use").getAttribute("xlink:href").replace("#", "");
|
||||||
|
} else {
|
||||||
|
const svgElement = item.querySelector("svg").cloneNode(true) as HTMLElement;
|
||||||
|
svgElement.classList.add("b3-menu__icon");
|
||||||
|
menuOption.iconHTML = svgElement.outerHTML;
|
||||||
|
}
|
||||||
|
menu.addItem(menuOption);
|
||||||
|
hasPlugin = true;
|
||||||
|
hasTopBar = true;
|
||||||
|
});
|
||||||
|
if (!hasTopBar && hasSetting) {
|
||||||
|
hasPlugin = true;
|
||||||
|
menu.addItem({
|
||||||
|
icon: "iconSettings",
|
||||||
|
label: plugin.displayName,
|
||||||
|
click() {
|
||||||
|
plugin.openSetting();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!hasPlugin) {
|
||||||
|
if (target) {
|
||||||
|
window.siyuan.menus.menu.element.querySelector(".b3-menu__separator")?.remove();
|
||||||
|
} else {
|
||||||
|
menu.addItem({
|
||||||
|
iconHTML: "",
|
||||||
|
type: "readonly",
|
||||||
|
label: window.siyuan.languages.emptyContent,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (target) {
|
||||||
|
let rect = target.getBoundingClientRect();
|
||||||
|
if (rect.width === 0) {
|
||||||
|
rect = document.querySelector("#barMore").getBoundingClientRect();
|
||||||
|
}
|
||||||
|
menu.open({x: rect.right, y: rect.bottom, isLeft: true});
|
||||||
|
} else {
|
||||||
|
menu.fullscreen();
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user