mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-06 00:38:49 +01:00
This commit is contained in:
parent
dce9d4da54
commit
846fdf7c6e
6 changed files with 130 additions and 48 deletions
|
|
@ -42,6 +42,7 @@ import {removeLink} from "../protyle/toolbar/Link";
|
|||
import {alignImgCenter, alignImgLeft} from "../protyle/wysiwyg/commonHotkey";
|
||||
import {renameTag} from "../util/noRelyPCFunction";
|
||||
import {hideElements} from "../protyle/ui/hideElements";
|
||||
import {emitOpenMenu} from "../plugin/EventBus";
|
||||
|
||||
export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
|
||||
const nodeElement = hasClosestBlock(element);
|
||||
|
|
@ -271,6 +272,19 @@ export const refMenu = (protyle: IProtyle, element: HTMLElement) => {
|
|||
focusByWbr(nodeElement, protyle.toolbar.range);
|
||||
}
|
||||
}).element);
|
||||
|
||||
if (protyle?.app?.plugins) {
|
||||
emitOpenMenu({
|
||||
plugins: protyle.app.plugins,
|
||||
type: "open-menu-blockref",
|
||||
detail: {
|
||||
protyle,
|
||||
element: element,
|
||||
},
|
||||
separatorPosition: "top",
|
||||
});
|
||||
}
|
||||
|
||||
const rect = element.getBoundingClientRect();
|
||||
window.siyuan.menus.menu.popup({
|
||||
x: rect.left,
|
||||
|
|
@ -715,6 +729,18 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme
|
|||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||
openMenu(protyle.app, imgSrc, false, false);
|
||||
}
|
||||
if (protyle?.app?.plugins) {
|
||||
emitOpenMenu({
|
||||
plugins: protyle.app.plugins,
|
||||
type: "open-menu-image",
|
||||
detail: {
|
||||
protyle,
|
||||
element: assetElement,
|
||||
},
|
||||
separatorPosition: "top",
|
||||
});
|
||||
}
|
||||
|
||||
window.siyuan.menus.menu.popup({x: position.clientX, y: position.clientY});
|
||||
const textElements = window.siyuan.menus.menu.element.querySelectorAll("textarea");
|
||||
textElements[0].focus();
|
||||
|
|
@ -876,6 +902,18 @@ export const linkMenu = (protyle: IProtyle, linkElement: HTMLElement, focusText
|
|||
focusByWbr(nodeElement, protyle.toolbar.range);
|
||||
}
|
||||
}).element);
|
||||
|
||||
if (protyle?.app?.plugins) {
|
||||
emitOpenMenu({
|
||||
plugins: protyle.app.plugins,
|
||||
type: "open-menu-link",
|
||||
detail: {
|
||||
protyle,
|
||||
element: linkElement,
|
||||
},
|
||||
separatorPosition: "top",
|
||||
});
|
||||
}
|
||||
const rect = linkElement.getBoundingClientRect();
|
||||
window.siyuan.menus.menu.popup({
|
||||
x: rect.left,
|
||||
|
|
@ -995,6 +1033,19 @@ export const tagMenu = (protyle: IProtyle, tagElement: HTMLElement) => {
|
|||
focusByWbr(nodeElement, protyle.toolbar.range);
|
||||
}
|
||||
}).element);
|
||||
|
||||
if (protyle?.app?.plugins) {
|
||||
emitOpenMenu({
|
||||
plugins: protyle.app.plugins,
|
||||
type: "open-menu-tag",
|
||||
detail: {
|
||||
protyle,
|
||||
element: tagElement,
|
||||
},
|
||||
separatorPosition: "top",
|
||||
});
|
||||
}
|
||||
|
||||
const rect = tagElement.getBoundingClientRect();
|
||||
window.siyuan.menus.menu.popup({
|
||||
x: rect.left,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import {MenuItem, subMenu} from "../menus/Menu";
|
||||
|
||||
export class EventBus<DetailType = any> {
|
||||
private eventTarget: EventTarget;
|
||||
|
||||
|
|
@ -21,3 +23,30 @@ export class EventBus<DetailType = any> {
|
|||
return this.eventTarget.dispatchEvent(new CustomEvent(type, {detail}));
|
||||
}
|
||||
}
|
||||
|
||||
export const emitOpenMenu = (options: {
|
||||
plugins: import("./index").Plugin[],
|
||||
type: TEventBus,
|
||||
detail: any,
|
||||
separatorPosition?: "top" | "bottom",
|
||||
}) => {
|
||||
const pluginSubMenu = new subMenu();
|
||||
options.detail.menu = pluginSubMenu;
|
||||
options.plugins.forEach((plugin) => {
|
||||
plugin.eventBus.emit(options.type, options.detail);
|
||||
});
|
||||
if (pluginSubMenu.menus.length > 0) {
|
||||
if (options.separatorPosition === "top") {
|
||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||
}
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.plugin,
|
||||
icon: "iconPlugin",
|
||||
type: "submenu",
|
||||
submenu: pluginSubMenu.menus,
|
||||
}).element);
|
||||
if (options.separatorPosition === "bottom") {
|
||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {hasClosestBlock, hasClosestByAttribute, hasClosestByMatchTag, hasClosestByTag} from "../util/hasClosest";
|
||||
import {getIconByType} from "../../editor/getIcon";
|
||||
import {iframeMenu, setFold, tableMenu, videoMenu, zoomOut} from "../../menus/protyle";
|
||||
import {MenuItem, subMenu} from "../../menus/Menu";
|
||||
import {MenuItem} from "../../menus/Menu";
|
||||
import {copySubMenu, openAttr, openWechatNotify} from "../../menus/commonMenuItem";
|
||||
import {copyPlainText, updateHotkeyTip, writeText} from "../util/compatibility";
|
||||
import {
|
||||
|
|
@ -41,6 +41,7 @@ import {hideTooltip} from "../../dialog/tooltip";
|
|||
import {appearanceMenu} from "../toolbar/Font";
|
||||
import {setPosition} from "../../util/setPosition";
|
||||
import {avRender} from "../render/av/render";
|
||||
import {emitOpenMenu} from "../../plugin/EventBus";
|
||||
|
||||
export class Gutter {
|
||||
public element: HTMLElement;
|
||||
|
|
@ -726,22 +727,16 @@ export class Gutter {
|
|||
}).element);
|
||||
}
|
||||
|
||||
const pluginSubMenu = new subMenu();
|
||||
protyle.app?.plugins?.forEach((plugin) => {
|
||||
plugin.eventBus.emit("click-blockicon", {
|
||||
protyle,
|
||||
menu: pluginSubMenu,
|
||||
blockElements: selectsElement,
|
||||
if (protyle?.app?.plugins) {
|
||||
emitOpenMenu({
|
||||
plugins:protyle.app.plugins,
|
||||
type: "click-blockicon",
|
||||
detail: {
|
||||
protyle,
|
||||
blockElements: selectsElement,
|
||||
},
|
||||
separatorPosition: "top",
|
||||
});
|
||||
});
|
||||
if (pluginSubMenu.menus.length > 0) {
|
||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.plugin,
|
||||
icon: "iconPlugin",
|
||||
type: "submenu",
|
||||
submenu: pluginSubMenu.menus,
|
||||
}).element);
|
||||
}
|
||||
|
||||
return window.siyuan.menus.menu;
|
||||
|
|
@ -1547,23 +1542,19 @@ export class Gutter {
|
|||
}
|
||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||
}
|
||||
const pluginSubMenu = new subMenu();
|
||||
protyle.app?.plugins?.forEach((plugin) => {
|
||||
plugin.eventBus.emit("click-blockicon", {
|
||||
protyle,
|
||||
menu: pluginSubMenu,
|
||||
blockElements: [nodeElement]
|
||||
|
||||
if (protyle?.app?.plugins) {
|
||||
emitOpenMenu({
|
||||
plugins:protyle.app.plugins,
|
||||
type: "click-blockicon",
|
||||
detail: {
|
||||
protyle,
|
||||
blockElements: [nodeElement]
|
||||
},
|
||||
separatorPosition: "bottom",
|
||||
});
|
||||
});
|
||||
if (pluginSubMenu.menus.length > 0) {
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.plugin,
|
||||
icon: "iconPlugin",
|
||||
type: "submenu",
|
||||
submenu: pluginSubMenu.menus,
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||
}
|
||||
|
||||
let updateHTML = nodeElement.getAttribute("updated") || "";
|
||||
if (updateHTML) {
|
||||
updateHTML = `${window.siyuan.languages.modifiedAt} ${dayjs(updateHTML).format("YYYY-MM-DD HH:mm:ss")}<br>`;
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import {makeCard, quickMakeCard} from "../../card/makeCard";
|
|||
import {viewCards} from "../../card/viewCards";
|
||||
import {getNotebookName, pathPosix} from "../../util/pathName";
|
||||
import {commonClick} from "../wysiwyg/commonClick";
|
||||
import {emitOpenMenu} from "../../plugin/EventBus";
|
||||
|
||||
export class Title {
|
||||
public element: HTMLElement;
|
||||
|
|
@ -401,22 +402,16 @@ export class Title {
|
|||
submenu: riffCardMenu,
|
||||
}).element);
|
||||
|
||||
const pluginSubMenu = new subMenu();
|
||||
protyle.app?.plugins?.forEach((plugin) => {
|
||||
plugin.eventBus.emit("click-editortitleicon", {
|
||||
protyle,
|
||||
menu: pluginSubMenu,
|
||||
data: response.data,
|
||||
if (protyle?.app?.plugins) {
|
||||
emitOpenMenu({
|
||||
plugins:protyle.app.plugins,
|
||||
type: "click-editortitleicon",
|
||||
detail: {
|
||||
protyle,
|
||||
data: response.data,
|
||||
},
|
||||
separatorPosition: "top",
|
||||
});
|
||||
});
|
||||
if (pluginSubMenu.menus.length > 0) {
|
||||
window.siyuan.menus.menu.append(new MenuItem({ type: "separator" }).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.plugin,
|
||||
icon: "iconPlugin",
|
||||
type: "submenu",
|
||||
submenu: pluginSubMenu.menus,
|
||||
}).element);
|
||||
}
|
||||
|
||||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import {openEditorTab} from "../../../menus/util";
|
|||
import {copySubMenu} from "../../../menus/commonMenuItem";
|
||||
import {popTextCell, showHeaderCellMenu} from "./cell";
|
||||
import {getColIconByType} from "./col";
|
||||
import {emitOpenMenu} from "../../../plugin/EventBus";
|
||||
|
||||
export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLElement }) => {
|
||||
const blockElement = hasClosestBlock(event.target);
|
||||
|
|
@ -143,6 +144,17 @@ export const avContextmenu = (protyle: IProtyle, event: MouseEvent & { detail: a
|
|||
type: "submenu",
|
||||
submenu: editAttrSubmenu
|
||||
});
|
||||
if (protyle?.app?.plugins) {
|
||||
emitOpenMenu({
|
||||
plugins: protyle.app.plugins,
|
||||
type: "open-menu-av",
|
||||
detail: {
|
||||
protyle,
|
||||
element: hasClosestByClassName(target, "av__cell"),
|
||||
},
|
||||
separatorPosition: "top",
|
||||
});
|
||||
}
|
||||
menu.open({
|
||||
x: event.clientX,
|
||||
y: event.clientY,
|
||||
|
|
|
|||
8
app/src/types/index.d.ts
vendored
8
app/src/types/index.d.ts
vendored
|
|
@ -25,8 +25,12 @@ type TOperation =
|
|||
| "updateAttrViewCell"
|
||||
type TBazaarType = "templates" | "icons" | "widgets" | "themes" | "plugins"
|
||||
type TCardType = "doc" | "notebook" | "all"
|
||||
type TEventBus = "ws-main" | "click-blockicon" | "click-editorcontent" | "click-pdf" |
|
||||
"click-editortitleicon" | "open-noneditableblock" | "loaded-protyle"
|
||||
type TEventBus = "ws-main" |
|
||||
"click-blockicon" | "click-editorcontent" | "click-pdf" | "click-editortitleicon" |
|
||||
"open-noneditableblock" |
|
||||
"open-menu-blockref" | "open-menu-fileannotationref" | "open-menu-tag" | "open-menu-link" | "open-menu-image" |
|
||||
"open-menu-av" | "open-menu-content" |
|
||||
"loaded-protyle"
|
||||
type TAVCol = "text" | "date" | "number" | "relation" | "rollup" | "select" | "block"
|
||||
|
||||
declare module "blueimp-md5"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue