🎨 Clean code

This commit is contained in:
Daniel 2024-04-16 09:01:56 +08:00
parent 26984f39df
commit 94d3ccfa9f
No known key found for this signature in database
GPG Key ID: 86211BA83DF03017
12 changed files with 39 additions and 39 deletions

View File

@ -713,8 +713,8 @@ app.whenReady().then(() => {
}), new MenuItem({ }), new MenuItem({
role: "selectAll", label: langs.selectAll role: "selectAll", label: langs.selectAll
})]; })];
const menu = Menu.buildFromTemplate(template) const menu = Menu.buildFromTemplate(template);
menu.popup({window: BrowserWindow.fromWebContents(event.sender)}) menu.popup({window: BrowserWindow.fromWebContents(event.sender)});
}); });
ipcMain.on("siyuan-open-folder", (event, filePath) => { ipcMain.on("siyuan-open-folder", (event, filePath) => {
shell.showItemInFolder(filePath); shell.showItemInFolder(filePath);

View File

@ -328,7 +328,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
srcIDs: sourceIds, srcIDs: sourceIds,
avID, avID,
}]); }]);
focusByRange(range) focusByRange(range);
}); });
} else { } else {
const selectElement: Element[] = []; const selectElement: Element[] = [];
@ -363,7 +363,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
srcIDs: sourceIds, srcIDs: sourceIds,
avID, avID,
}]); }]);
focusByRange(range) focusByRange(range);
}); });
} }
event.preventDefault(); event.preventDefault();

View File

@ -160,7 +160,7 @@ export const openOutline = async (protyle: IProtyle) => {
} }
}), false, false); }), false, false);
newWnd.element.style.width = "200px"; newWnd.element.style.width = "200px";
newWnd.element.classList.remove("fn__flex-1") newWnd.element.classList.remove("fn__flex-1");
switchWnd(newWnd, wnd); switchWnd(newWnd, wnd);
fixWndFlex1(newWnd.parent); fixWndFlex1(newWnd.parent);
saveLayout(); saveLayout();

View File

@ -910,7 +910,7 @@ export const adjustLayout = (layout: Layout = window.siyuan.layout.centerLayout.
export const fixWndFlex1 = (layout: Layout) => { export const fixWndFlex1 = (layout: Layout) => {
if (layout.children.length < 2) { if (layout.children.length < 2) {
return return;
} }
if (layout.children[layout.children.length - 2].element.classList.contains("fn__flex-1")) { if (layout.children[layout.children.length - 2].element.classList.contains("fn__flex-1")) {
return; return;
@ -919,27 +919,27 @@ export const fixWndFlex1 = (layout: Layout) => {
if (index !== layout.children.length - 2) { if (index !== layout.children.length - 2) {
if (layout.direction === "lr") { if (layout.direction === "lr") {
if (item.element.classList.contains("fn__flex-1")) { if (item.element.classList.contains("fn__flex-1")) {
item.element.style.width = item.element.clientWidth + "px" item.element.style.width = item.element.clientWidth + "px";
item.element.classList.remove("fn__flex-1") item.element.classList.remove("fn__flex-1");
} }
} else { } else {
if (item.element.classList.contains("fn__flex-1")) { if (item.element.classList.contains("fn__flex-1")) {
item.element.style.height = item.element.clientHeight + "px" item.element.style.height = item.element.clientHeight + "px";
item.element.classList.remove("fn__flex-1") item.element.classList.remove("fn__flex-1");
} }
} }
} }
}) });
const flex1Element = layout.children[layout.children.length - 2].element const flex1Element = layout.children[layout.children.length - 2].element;
if (layout.direction === "lr") { if (layout.direction === "lr") {
if (flex1Element.style.width) { if (flex1Element.style.width) {
flex1Element.style.width = "" flex1Element.style.width = "";
flex1Element.classList.add("fn__flex-1") flex1Element.classList.add("fn__flex-1");
} }
} else { } else {
if (flex1Element.style.height) { if (flex1Element.style.height) {
flex1Element.style.height = "" flex1Element.style.height = "";
flex1Element.classList.add("fn__flex-1") flex1Element.classList.add("fn__flex-1");
} }
} }
} };

View File

@ -811,7 +811,7 @@ export class Gutter {
}); });
} }
}).element); }).element);
const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : undefined const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : undefined;
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.addToDatabase, label: window.siyuan.languages.addToDatabase,
accelerator: window.siyuan.config.keymap.general.addToDatabase.custom, accelerator: window.siyuan.config.keymap.general.addToDatabase.custom,
@ -1279,7 +1279,7 @@ export class Gutter {
}); });
} }
}).element); }).element);
const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : undefined const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : undefined;
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.addToDatabase, label: window.siyuan.languages.addToDatabase,
accelerator: window.siyuan.config.keymap.general.addToDatabase.custom, accelerator: window.siyuan.config.keymap.general.addToDatabase.custom,

View File

@ -45,7 +45,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
}).element); }).element);
if (!protyle.disabled) { if (!protyle.disabled) {
window.siyuan.menus.menu.append(movePathToMenu([protyle.path])); window.siyuan.menus.menu.append(movePathToMenu([protyle.path]));
const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : undefined const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : undefined;
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.addToDatabase, label: window.siyuan.languages.addToDatabase,
accelerator: window.siyuan.config.keymap.general.addToDatabase.custom, accelerator: window.siyuan.config.keymap.general.addToDatabase.custom,

View File

@ -589,7 +589,7 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, va
return; return;
} }
if (type === "block" && !item.dataset.detached) { if (type === "block" && !item.dataset.detached) {
const newId = Lute.NewNodeID() const newId = Lute.NewNodeID();
doOperations.push({ doOperations.push({
action: "unbindAttrViewBlock", action: "unbindAttrViewBlock",
id: rowID, id: rowID,

View File

@ -57,17 +57,17 @@ const toggleEmpty = (element: HTMLElement, operator: string, type: TAVCol) => {
const filterSelect = (key: string) => { const filterSelect = (key: string) => {
window.siyuan.menus.menu.element.querySelectorAll(".b3-menu__item").forEach((item) => { window.siyuan.menus.menu.element.querySelectorAll(".b3-menu__item").forEach((item) => {
const nameElement = item.querySelector(".b3-chip.b3-chip--middle") as HTMLElement const nameElement = item.querySelector(".b3-chip.b3-chip--middle") as HTMLElement;
if (nameElement) { if (nameElement) {
const itemName = nameElement.dataset.name.toLowerCase() const itemName = nameElement.dataset.name.toLowerCase();
if (!key || (key.indexOf(itemName) > -1 || itemName.indexOf(key) > -1)) { if (!key || (key.indexOf(itemName) > -1 || itemName.indexOf(key) > -1)) {
item.classList.remove("fn__none"); item.classList.remove("fn__none");
} else { } else {
item.classList.add("fn__none"); item.classList.add("fn__none");
} }
} }
}) });
} };
export const setFilter = async (options: { export const setFilter = async (options: {
filter: IAVFilter, filter: IAVFilter,
@ -332,7 +332,7 @@ export const setFilter = async (options: {
type: "readonly", type: "readonly",
label: `<input class="b3-text-field fn__block" style="margin: 4px 0" placeholder="${window.siyuan.languages.search}">`, label: `<input class="b3-text-field fn__block" style="margin: 4px 0" placeholder="${window.siyuan.languages.search}">`,
bind(element) { bind(element) {
const selectSearchElement = element.querySelector("input") const selectSearchElement = element.querySelector("input");
selectSearchElement.addEventListener("keydown", (event: KeyboardEvent) => { selectSearchElement.addEventListener("keydown", (event: KeyboardEvent) => {
if (event.isComposing) { if (event.isComposing) {
return; return;
@ -344,18 +344,18 @@ export const setFilter = async (options: {
} }
currentElement.dispatchEvent(new CustomEvent("click")); currentElement.dispatchEvent(new CustomEvent("click"));
} }
}) });
selectSearchElement.addEventListener("input", (event: InputEvent) => { selectSearchElement.addEventListener("input", (event: InputEvent) => {
if (event.isComposing) { if (event.isComposing) {
return; return;
} }
filterSelect(selectSearchElement.value.toLowerCase()); filterSelect(selectSearchElement.value.toLowerCase());
}) });
selectSearchElement.addEventListener("compositionend", () => { selectSearchElement.addEventListener("compositionend", () => {
filterSelect(selectSearchElement.value.toLowerCase()); filterSelect(selectSearchElement.value.toLowerCase());
}) });
} }
}) });
} }
colData.options?.forEach((option) => { colData.options?.forEach((option) => {
let icon = "iconUncheck"; let icon = "iconUncheck";

View File

@ -125,7 +125,7 @@ export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN) =
}; };
export const lineNumberRender = (block: HTMLElement) => { export const lineNumberRender = (block: HTMLElement) => {
const lineNumber = block.parentElement.getAttribute("lineNumber") const lineNumber = block.parentElement.getAttribute("lineNumber");
if (lineNumber === "false") { if (lineNumber === "false") {
return; return;
} }

View File

@ -145,20 +145,20 @@ const genUploadedLabel = (responseText: string, protyle: IProtyle) => {
}); });
if ((nodeElement && nodeElement.classList.contains("av"))) { if ((nodeElement && nodeElement.classList.contains("av"))) {
const cellElements: HTMLElement[] = [] const cellElements: HTMLElement[] = [];
nodeElement.querySelectorAll(".av__row--select:not(.av__row--header)").forEach(item => { nodeElement.querySelectorAll(".av__row--select:not(.av__row--header)").forEach(item => {
item.querySelectorAll(".av__cell").forEach((cellItem: HTMLElement) => { item.querySelectorAll(".av__cell").forEach((cellItem: HTMLElement) => {
if (getTypeByCellElement(cellItem) === "mAsset") { if (getTypeByCellElement(cellItem) === "mAsset") {
cellElements.push(cellItem); cellElements.push(cellItem);
} }
}) });
}) });
if (cellElements.length === 0) { if (cellElements.length === 0) {
protyle.wysiwyg.element.querySelectorAll(".av__cell--active").forEach((item: HTMLElement) => { protyle.wysiwyg.element.querySelectorAll(".av__cell--active").forEach((item: HTMLElement) => {
if (getTypeByCellElement(item) === "mAsset") { if (getTypeByCellElement(item) === "mAsset") {
cellElements.push(item); cellElements.push(item);
} }
}) });
} }
if (cellElements.length > 0) { if (cellElements.length > 0) {
updateCellsValue(protyle, nodeElement, avAssets, cellElements); updateCellsValue(protyle, nodeElement, avAssets, cellElements);
@ -170,12 +170,12 @@ const genUploadedLabel = (responseText: string, protyle: IProtyle) => {
} }
if (document.querySelector(".av__panel")) { if (document.querySelector(".av__panel")) {
const cellElements: HTMLElement[] = [] const cellElements: HTMLElement[] = [];
protyle.wysiwyg.element.querySelectorAll(".av__cell--active").forEach((item: HTMLElement) => { protyle.wysiwyg.element.querySelectorAll(".av__cell--active").forEach((item: HTMLElement) => {
if (getTypeByCellElement(item) === "mAsset") { if (getTypeByCellElement(item) === "mAsset") {
cellElements.push(item); cellElements.push(item);
} }
}) });
if (cellElements.length > 0) { if (cellElements.length > 0) {
const blockElement = hasClosestBlock(cellElements[0]); const blockElement = hasClosestBlock(cellElements[0]);
if (blockElement) { if (blockElement) {

View File

@ -532,7 +532,7 @@ export const focusBlock = (element: Element, parentElement?: HTMLElement, toStar
range.collapse(true); range.collapse(true);
setRange = true; setRange = true;
} else if (type === "NodeAttributeView") { } else if (type === "NodeAttributeView") {
const cursorElement = element.querySelector(".av__cursor") const cursorElement = element.querySelector(".av__cursor");
if (cursorElement) { if (cursorElement) {
range.setStart(cursorElement.firstChild, 0); range.setStart(cursorElement.firstChild, 0);
setRange = true; setRange = true;

View File

@ -20,7 +20,7 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range:
return; return;
} }
if (blockElement.classList.contains("av")) { if (blockElement.classList.contains("av")) {
const avCursorElement = hasClosestByClassName(range.startContainer, "av__cursor") const avCursorElement = hasClosestByClassName(range.startContainer, "av__cursor");
if (avCursorElement) { if (avCursorElement) {
range.startContainer.textContent = Constants.ZWSP; range.startContainer.textContent = Constants.ZWSP;
} else { } else {