Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from TCOTC/dev-menu-id
Browse files Browse the repository at this point in the history
TCOTC authored Sep 19, 2024

Verified

This commit was signed with the committer’s verified signature.
sirreal Jon Surrell
2 parents 71ecbb1 + de5d4b6 commit dc65f47
Showing 3 changed files with 29 additions and 19 deletions.
6 changes: 3 additions & 3 deletions app/src/menus/Menu.ts
Original file line number Diff line number Diff line change
@@ -181,6 +181,9 @@ export class MenuItem {
if (options.disabled) {
this.element.setAttribute("disabled", "disabled");
}
if (options.id) {
this.element.setAttribute("data-id", options.id);
}
if (options.type === "separator") {
this.element.classList.add("b3-menu__separator");
return;
@@ -207,9 +210,6 @@ export class MenuItem {
}
});
}
if (options.id) {
this.element.setAttribute("data-id", options.id);
}
if (options.type === "readonly") {
this.element.classList.add("b3-menu__item--readonly");
}
6 changes: 6 additions & 0 deletions app/src/menus/commonMenuItem.ts
Original file line number Diff line number Diff line change
@@ -372,6 +372,7 @@ export const openAttr = (nodeElement: Element, focusName = "bookmark", protyle?:

export const copySubMenu = (id: string, accelerator = true, focusElement?: Element) => {
return [{
id: "copyBlockRef",
iconHTML: "",
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyBlockRef.custom : undefined,
label: window.siyuan.languages.copyBlockRef,
@@ -384,6 +385,7 @@ export const copySubMenu = (id: string, accelerator = true, focusElement?: Eleme
}
}
}, {
id: "copyBlockEmbed",
iconHTML: "",
label: window.siyuan.languages.copyBlockEmbed,
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyBlockEmbed.custom : undefined,
@@ -394,6 +396,7 @@ export const copySubMenu = (id: string, accelerator = true, focusElement?: Eleme
}
}
}, {
id: "copyProtocol",
iconHTML: "",
label: window.siyuan.languages.copyProtocol,
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyProtocol.custom : undefined,
@@ -404,6 +407,7 @@ export const copySubMenu = (id: string, accelerator = true, focusElement?: Eleme
}
}
}, {
id: "copyProtocolInMd",
iconHTML: "",
label: window.siyuan.languages.copyProtocolInMd,
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyProtocolInMd.custom : undefined,
@@ -416,6 +420,7 @@ export const copySubMenu = (id: string, accelerator = true, focusElement?: Eleme
}
}
}, {
id: "copyHPath",
iconHTML: "",
label: window.siyuan.languages.copyHPath,
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyHPath.custom : undefined,
@@ -427,6 +432,7 @@ export const copySubMenu = (id: string, accelerator = true, focusElement?: Eleme
});
}
}, {
id: "copyID",
iconHTML: "",
label: window.siyuan.languages.copyID,
accelerator: accelerator ? window.siyuan.config.keymap.editor.general.copyID.custom : undefined,
36 changes: 20 additions & 16 deletions app/src/protyle/gutter/index.ts
Original file line number Diff line number Diff line change
@@ -783,7 +783,7 @@ export class Gutter {
}
}).element);

window.siyuan.menus.menu.append(new MenuItem({id: "separator", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({id: "separator1", type: "separator"}).element);
const appearanceElement = new MenuItem({
label: window.siyuan.languages.appearance,
icon: "iconFont",
@@ -813,7 +813,7 @@ export class Gutter {
this.genWidths(selectsElement, protyle);
// this.genHeights(selectsElement, protyle);
if (!window.siyuan.config.readonly) {
window.siyuan.menus.menu.append(new MenuItem({id: "separator", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({id: "separator2", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({
id: "quickMakeCard",
label: window.siyuan.languages.quickMakeCard,
@@ -1182,6 +1182,7 @@ export class Gutter {
}

const copyMenu = (copySubMenu(id, true, nodeElement) as IMenu[]).concat([{
id: "copyPlainText",
iconHTML: "",
label: window.siyuan.languages.copyPlainText,
accelerator: window.siyuan.config.keymap.editor.general.copyPlainText.custom,
@@ -1190,6 +1191,7 @@ export class Gutter {
focusBlock(nodeElement);
}
}, {
id: "copyMirror",
iconHTML: "",
label: type === "NodeAttributeView" ? window.siyuan.languages.copyMirror : window.siyuan.languages.copy,
accelerator: "⌘C",
@@ -1202,6 +1204,7 @@ export class Gutter {
document.execCommand("copy");
}
}, {
id: "duplicateMirror",
iconHTML: "",
label: type === "NodeAttributeView" ? window.siyuan.languages.duplicateMirror : window.siyuan.languages.duplicate,
accelerator: window.siyuan.config.keymap.editor.general.duplicate.custom,
@@ -1212,6 +1215,7 @@ export class Gutter {
}]);
if (type === "NodeAttributeView") {
copyMenu.push({
id: "duplicateCompletely",
iconHTML: "",
label: window.siyuan.languages.duplicateCompletely,
accelerator: window.siyuan.config.keymap.editor.general.duplicateCompletely.custom,
@@ -1276,7 +1280,7 @@ export class Gutter {
}).element);
}
if (type === "NodeSuperBlock" && !protyle.disabled) {
window.siyuan.menus.menu.append(new MenuItem({id: "separator", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({id: "separator3", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({
id: "superBlock",
label: window.siyuan.languages.cancel + " " + window.siyuan.languages.superBlock,
@@ -1288,7 +1292,7 @@ export class Gutter {
}
}).element);
} else if (type === "NodeCodeBlock" && !protyle.disabled && !nodeElement.getAttribute("data-subtype")) {
window.siyuan.menus.menu.append(new MenuItem({id: "separator", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({id: "separator4", type: "separator"}).element);
const linewrap = nodeElement.getAttribute("linewrap");
const ligatures = nodeElement.getAttribute("ligatures");
const linenumber = nodeElement.getAttribute("linenumber");
@@ -1361,7 +1365,7 @@ export class Gutter {
}]
}).element);
} else if (type === "NodeCodeBlock" && !protyle.disabled && ["echarts", "mindmap"].includes(nodeElement.getAttribute("data-subtype"))) {
window.siyuan.menus.menu.append(new MenuItem({id: "separator", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({id: "separator5", type: "separator"}).element);
const height = (nodeElement as HTMLElement).style.height;
let html = nodeElement.outerHTML;
window.siyuan.menus.menu.append(new MenuItem({
@@ -1401,7 +1405,7 @@ export class Gutter {
}
const cellElement = hasClosestByMatchTag(range.startContainer, "TD") || hasClosestByMatchTag(range.startContainer, "TH");
if (cellElement) {
window.siyuan.menus.menu.append(new MenuItem({id: "separator", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({id: "separator6", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({
id: "table",
type: "submenu",
@@ -1411,7 +1415,7 @@ export class Gutter {
}).element);
}
} else if (type === "NodeAttributeView" && !protyle.disabled) {
window.siyuan.menus.menu.append(new MenuItem({id: "separator", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({id: "separator7", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({
id: "exportCSV",
icon: "iconDatabase",
@@ -1426,7 +1430,7 @@ export class Gutter {
}
}).element);
} else if ((type === "NodeVideo" || type === "NodeAudio") && !protyle.disabled) {
window.siyuan.menus.menu.append(new MenuItem({id: "separator", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({id: "separator8", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({
id: "assetSubMenu",
type: "submenu",
@@ -1435,7 +1439,7 @@ export class Gutter {
submenu: videoMenu(protyle, nodeElement, type)
}).element);
} else if (type === "NodeIFrame" && !protyle.disabled) {
window.siyuan.menus.menu.append(new MenuItem({id: "separator", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({id: "separator9", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({
id: "assetSubMenu",
type: "submenu",
@@ -1444,7 +1448,7 @@ export class Gutter {
submenu: iframeMenu(protyle, nodeElement)
}).element);
} else if (type === "NodeHTMLBlock" && !protyle.disabled) {
window.siyuan.menus.menu.append(new MenuItem({id: "separator", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({id: "separator10", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({
id: "HTML",
icon: "iconHTML5",
@@ -1454,7 +1458,7 @@ export class Gutter {
}
}).element);
} else if (type === "NodeBlockQueryEmbed" && !protyle.disabled) {
window.siyuan.menus.menu.append(new MenuItem({id: "separator", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({id: "separator11", type: "separator"}).element);
const breadcrumb = nodeElement.getAttribute("breadcrumb");
window.siyuan.menus.menu.append(new MenuItem({
id: "assetSubMenu",
@@ -1517,7 +1521,7 @@ export class Gutter {
}]
}).element);
} else if (type === "NodeHeading" && !protyle.disabled) {
window.siyuan.menus.menu.append(new MenuItem({id: "separator", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({id: "separator12", type: "separator"}).element);
const headingSubMenu = [];
if (subType !== "h1") {
headingSubMenu.push(this.genHeadingTransform(protyle, id, 1));
@@ -1600,7 +1604,7 @@ export class Gutter {
}
}).element);
}
window.siyuan.menus.menu.append(new MenuItem({id: "separator", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({id: "separator13", type: "separator"}).element);
if (!protyle.options.backlinkData) {
window.siyuan.menus.menu.append(new MenuItem({
id: "enter",
@@ -1675,7 +1679,7 @@ export class Gutter {
}
}).element);

window.siyuan.menus.menu.append(new MenuItem({id: "separator", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({id: "separator14", type: "separator"}).element);

if (type !== "NodeThematicBreak") {
window.siyuan.menus.menu.append(new MenuItem({
@@ -1729,7 +1733,7 @@ export class Gutter {
this.genWidths([nodeElement], protyle);
// this.genHeights([nodeElement], protyle);
}
window.siyuan.menus.menu.append(new MenuItem({id: "separator", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({id: "separator15", type: "separator"}).element);
if (!["NodeThematicBreak", "NodeBlockQueryEmbed", "NodeIFrame", "NodeHTMLBlock", "NodeWidget", "NodeVideo", "NodeAudio"].includes(type) &&
getContenteditableElement(nodeElement)?.textContent.trim() !== "" &&
(type !== "NodeCodeBlock" || (type === "NodeCodeBlock" && !nodeElement.getAttribute("data-subtype")))) {
@@ -1763,7 +1767,7 @@ export class Gutter {
makeCard(protyle.app, [id]);
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({id: "separator", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({id: "separator16", type: "separator"}).element);
}

if (protyle?.app?.plugins) {

0 comments on commit dc65f47

Please sign in to comment.