Skip to content

Commit

Permalink
Merge pull request #23 from TCOTC/dev-menu-id
Browse files Browse the repository at this point in the history
  • Loading branch information
TCOTC authored Sep 19, 2024
2 parents 71ecbb1 + de5d4b6 commit dc65f47
Show file tree
Hide file tree
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
Expand Up @@ -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;
Expand All @@ -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");
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/menus/commonMenuItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
36 changes: 20 additions & 16 deletions app/src/protyle/gutter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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",
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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");
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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")))) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit dc65f47

Please sign in to comment.