diff --git a/app/src/menus/commonMenuItem.ts b/app/src/menus/commonMenuItem.ts index da16bb834..d538e4b99 100644 --- a/app/src/menus/commonMenuItem.ts +++ b/app/src/menus/commonMenuItem.ts @@ -149,7 +149,7 @@ export const openFileWechatNotify = (protyle: IProtyle) => { }); }; -const genAttr = (attrs: IObject, focusName = "bookmark") => { +export const openFileAttr = (attrs: IObject, focusName = "bookmark") => { let customHTML = ""; let notifyHTML = ""; let hasAV = false; @@ -263,7 +263,7 @@ const genAttr = (attrs: IObject, focusName = "bookmark") => { } else if (type === "remove") { fetchPost("/api/attr/setBlockAttrs", { id: attrs.id, - attrs: {["custom-"+target.previousElementSibling.textContent]: ""} + attrs: {["custom-" + target.previousElementSibling.textContent]: ""} }); target.parentElement.parentElement.remove(); event.stopPropagation(); @@ -285,7 +285,7 @@ const genAttr = (attrs: IObject, focusName = "bookmark") => { click() { const bookmarkInputElement = target.parentElement.parentElement.querySelector("input"); bookmarkInputElement.value = item; - bookmarkInputElement.dispatchEvent(new CustomEvent("change")); + bookmarkInputElement.dispatchEvent(new CustomEvent("change")); } }).element); }); @@ -350,147 +350,13 @@ const genAttr = (attrs: IObject, focusName = "bookmark") => { }); }; -export const openFileAttr = (attrs: IObject, id: string, focusName = "bookmark") => { - genAttr(attrs, focusName, - // (dialog) => { - // let nodeAttrHTML = ""; - // let errorTip = ""; - // const attrsResult: IObject = {}; - // dialog.element.querySelectorAll(".b3-text-field").forEach((item: HTMLInputElement) => { - // let name = item.getAttribute("data-name"); - // if (!name) { - // if (item.tagName === "INPUT") { - // return; - // } - // name = "custom-" + (item.parentElement.querySelector(".b3-text-field") as HTMLInputElement).value; - // } - // if (item.value.trim()) { - // if (!isValidAttrName(name)) { - // errorTip += name.replace(/^custom-/, "") + ", "; - // return; - // } - // attrsResult[name] = item.value; - // const escapeHTML = Lute.EscapeHTMLStr(item.value); - // if (name === "bookmark") { - // nodeAttrHTML += `
${escapeHTML}
`; - // } else if (name === "name") { - // nodeAttrHTML += `
${escapeHTML}
`; - // } else if (name === "alias") { - // nodeAttrHTML += `
${escapeHTML}
`; - // } else if (name === "memo") { - // nodeAttrHTML += `
`; - // } - // } - // }); - // if (errorTip) { - // showMessage(errorTip.substr(0, errorTip.length - 2) + " " + window.siyuan.languages.invalid); - // } - // /// #if !MOBILE - // getAllModels().editor.forEach(item => { - // if (item.editor.protyle.block.rootID === id) { - // const refElement = item.editor.protyle.title.element.querySelector(".protyle-attr--refcount"); - // if (refElement) { - // nodeAttrHTML += refElement.outerHTML; - // } - // item.editor.protyle.title.element.querySelector(".protyle-attr").innerHTML = nodeAttrHTML; - // item.editor.protyle.wysiwyg.renderCustom(attrsResult); - // } - // // https://github.com/siyuan-note/siyuan/issues/6398 - // item.editor.protyle.wysiwyg.element.querySelectorAll(`[data-type~="block-ref"][data-id="${id}"][data-subtype="d"]`).forEach(item => { - // fetchPost("/api/block/getRefText", {id: id}, (response) => { - // item.innerHTML = response.data; - // }); - // }); - // }); - // /// #endif - // fetchPost("/api/attr/resetBlockAttrs", {id, attrs: attrsResult}, () => { - // /// #if !MOBILE - // if (attrsResult.bookmark !== attrs.bookmark) { - // const bookmark = getDockByType("bookmark").data.bookmark; - // if (bookmark instanceof Bookmark) { - // bookmark.update(); - // } - // } - // /// #endif - // }); - // dialog.destroy(); - // } - ); -}; - -export const openAttr = (nodeElement: Element, protyle: IProtyle, focusName = "bookmark") => { +export const openAttr = (nodeElement: Element, focusName = "bookmark") => { if (nodeElement.getAttribute("data-type") === "NodeThematicBreak") { return; } const id = nodeElement.getAttribute("data-node-id"); fetchPost("/api/attr/getBlockAttrs", {id}, (response) => { - genAttr(response.data, focusName, - // (dialog, removeAttrs) => { - // let nodeAttrHTML = ""; - // const oldHTML = nodeElement.outerHTML; - // let errorTip = ""; - // dialog.element.querySelectorAll(".b3-text-field").forEach((item: HTMLInputElement) => { - // let name = item.getAttribute("data-name"); - // if (!name) { - // if (item.tagName === "INPUT") { - // return; - // } - // name = "custom-" + (item.parentElement.querySelector(".b3-text-field") as HTMLInputElement).value; - // } - // if (item.value.trim()) { - // if (!isValidAttrName(name)) { - // errorTip += name.replace(/^custom-/, "") + ", "; - // return; - // } - // if (removeAttrs.includes(name)) { - // removeAttrs.find((rmAttr, index) => { - // if (rmAttr === name) { - // removeAttrs.splice(index, 1); - // return true; - // } - // }); - // } - // const escapeHTML = Lute.EscapeHTMLStr(item.value); - // nodeElement.setAttribute(name, escapeHTML); - // if (name === "bookmark") { - // /// #if !MOBILE - // if (escapeHTML !== response.data.bookmark) { - // const bookmark = getDockByType("bookmark").data.bookmark; - // if (bookmark instanceof Bookmark) { - // setTimeout(() => { - // bookmark.update(); - // }, 219); - // } - // } - // /// #endif - // nodeAttrHTML += `
${escapeHTML}
`; - // } else if (name === "name") { - // nodeAttrHTML += `
${escapeHTML}
`; - // } else if (name === "alias") { - // nodeAttrHTML += `
${escapeHTML}
`; - // } else if (name === "memo") { - // nodeAttrHTML += `
`; - // } - // } else { - // nodeElement.removeAttribute(name); - // } - // }); - // removeAttrs.forEach(item => { - // nodeElement.removeAttribute(item); - // }); - // if (errorTip) { - // showMessage(errorTip.substr(0, errorTip.length - 2) + " " + window.siyuan.languages.invalid); - // } - // const refElement = nodeElement.lastElementChild.querySelector(".protyle-attr--refcount"); - // if (refElement) { - // nodeAttrHTML += refElement.outerHTML; - // } - // nodeElement.lastElementChild.innerHTML = nodeAttrHTML + Constants.ZWSP; - // nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss")); - // updateTransaction(protyle, id, nodeElement.outerHTML, oldHTML); - // dialog.destroy(); - // } - ); + openFileAttr(response.data, focusName); }); }; diff --git a/app/src/menus/navigation.ts b/app/src/menus/navigation.ts index a5412bd36..b70d57082 100644 --- a/app/src/menus/navigation.ts +++ b/app/src/menus/navigation.ts @@ -365,7 +365,7 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l fetchPost("/api/block/getDocInfo", { id }, (response) => { - openFileAttr(response.data.ial, id); + openFileAttr(response.data.ial); }); } }).element); diff --git a/app/src/protyle/breadcrumb/index.ts b/app/src/protyle/breadcrumb/index.ts index f369f6e96..be22e5f07 100644 --- a/app/src/protyle/breadcrumb/index.ts +++ b/app/src/protyle/breadcrumb/index.ts @@ -85,7 +85,7 @@ export class Breadcrumb { fetchPost("/api/block/getDocInfo", { id: protyle.block.rootID }, (response) => { - openFileAttr(response.data.ial, protyle.block.rootID); + openFileAttr(response.data.ial); }); } else { const targetRect = target.getBoundingClientRect(); diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts index 039d52db6..a86f5922b 100644 --- a/app/src/protyle/gutter/index.ts +++ b/app/src/protyle/gutter/index.ts @@ -215,7 +215,7 @@ export class Gutter { } foldElement.classList.remove("protyle-wysiwyg--hl"); } else if (window.siyuan.shiftIsPressed && !protyle.disabled) { - openAttr(protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`), protyle); + openAttr(protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`)); } else { this.renderMenu(protyle, buttonElement); // https://ld246.com/article/1648433751993 @@ -1496,7 +1496,7 @@ export class Gutter { label: window.siyuan.languages.attr, accelerator: window.siyuan.config.keymap.editor.general.attr.custom + "/" + updateHotkeyTip("⇧Click"), click() { - openAttr(nodeElement, protyle); + openAttr(nodeElement); } }).element); } diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts index 3931f7686..700f72f92 100644 --- a/app/src/protyle/header/Title.ts +++ b/app/src/protyle/header/Title.ts @@ -140,7 +140,7 @@ export class Title { fetchPost("/api/block/getDocInfo", { id: protyle.block.rootID }, (response) => { - openFileAttr(response.data.ial, protyle.block.rootID); + openFileAttr(response.data.ial); }); event.preventDefault(); event.stopPropagation(); @@ -179,7 +179,7 @@ export class Title { fetchPost("/api/block/getDocInfo", { id: protyle.block.rootID }, (response) => { - openFileAttr(response.data.ial, protyle.block.rootID); + openFileAttr(response.data.ial); }); } else { const iconRect = iconElement.getBoundingClientRect(); diff --git a/app/src/protyle/header/openTitleMenu.ts b/app/src/protyle/header/openTitleMenu.ts index d906c59ce..d2d6c7d37 100644 --- a/app/src/protyle/header/openTitleMenu.ts +++ b/app/src/protyle/header/openTitleMenu.ts @@ -55,7 +55,7 @@ export const openTitleMenu = (protyle: IProtyle, position: { label: window.siyuan.languages.attr, accelerator: window.siyuan.config.keymap.editor.general.attr.custom + "/" + updateHotkeyTip("⇧Click"), click() { - openFileAttr(response.data.ial, protyle.block.rootID); + openFileAttr(response.data.ial); } }).element); } diff --git a/app/src/protyle/render/av/col.ts b/app/src/protyle/render/av/col.ts index 24e7945c4..ecef77e2d 100644 --- a/app/src/protyle/render/av/col.ts +++ b/app/src/protyle/render/av/col.ts @@ -291,7 +291,7 @@ export const showColMenu = (protyle: IProtyle, blockElement: HTMLElement, cellEl bind(element) { element.querySelector("input").addEventListener("keydown", (event: KeyboardEvent) => { if (event.isComposing) { - return + return; } if (event.key === "Enter") { menu.close(); diff --git a/app/src/protyle/render/av/filter.ts b/app/src/protyle/render/av/filter.ts index 224ef8540..4bb62cbd0 100644 --- a/app/src/protyle/render/av/filter.ts +++ b/app/src/protyle/render/av/filter.ts @@ -374,7 +374,7 @@ export const getFiltersHTML = (data: IAVTable) => { if (index !== filter.value.mSelect.length - 1) { selectContent += ", "; } - }) + }); if ("Contains" === filter.operator) { filterValue = `: ${selectContent}`; } else if (filter.operator === "Does not contains") { diff --git a/app/src/protyle/wysiwyg/commonClick.ts b/app/src/protyle/wysiwyg/commonClick.ts index 8110455e0..a6851cfa0 100644 --- a/app/src/protyle/wysiwyg/commonClick.ts +++ b/app/src/protyle/wysiwyg/commonClick.ts @@ -17,9 +17,9 @@ export const commonClick = (event: MouseEvent & { /// #endif } else { if (data) { - openFileAttr(data, protyle.block.rootID, "bookmark"); + openFileAttr(data, "bookmark"); } else { - openAttr(attrBookmarkElement.parentElement.parentElement, protyle, "bookmark"); + openAttr(attrBookmarkElement.parentElement.parentElement, "bookmark"); } } event.stopPropagation(); @@ -34,9 +34,9 @@ export const commonClick = (event: MouseEvent & { /// #endif } else { if (data) { - openFileAttr(data, protyle.block.rootID, "name"); + openFileAttr(data, "name"); } else { - openAttr(attrNameElement.parentElement.parentElement, protyle, "name"); + openAttr(attrNameElement.parentElement.parentElement, "name"); } } event.stopPropagation(); @@ -51,9 +51,9 @@ export const commonClick = (event: MouseEvent & { /// #endif } else { if (data) { - openFileAttr(data, protyle.block.rootID, "alias"); + openFileAttr(data, "alias"); } else { - openAttr(attrAliasElement.parentElement.parentElement, protyle, "alias"); + openAttr(attrAliasElement.parentElement.parentElement, "alias"); } } event.stopPropagation(); @@ -68,9 +68,9 @@ export const commonClick = (event: MouseEvent & { /// #endif } else { if (data) { - openFileAttr(data, protyle.block.rootID, "memo"); + openFileAttr(data, "memo"); } else { - openAttr(attrMemoElement.parentElement.parentElement, protyle, "memo"); + openAttr(attrMemoElement.parentElement.parentElement, "memo"); } } event.stopPropagation(); diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index 4dd7fc68e..e574a1c6d 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -1929,7 +1929,7 @@ export class WYSIWYG { } hideElements(["gutter"], protyle); } else if (event.shiftKey) { - openAttr(actionElement.parentElement, protyle); + openAttr(actionElement.parentElement); } else if (ctrlIsPressed) { zoomOut({protyle, id: actionElement.parentElement.getAttribute("data-node-id")}); } else { diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index 3ec5b881d..10d072325 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -1042,7 +1042,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { } else { actionElement = topElement; } - openAttr(actionElement, protyle); + openAttr(actionElement); } else { const oldHTML = topElement.outerHTML; const name = Lute.EscapeHTMLStr(selectText);