♻️ attr

This commit is contained in:
Vanessa 2023-08-02 20:55:25 +08:00
parent 74a6c49f3f
commit 67c0fda4dd
11 changed files with 24 additions and 158 deletions

View file

@ -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 customHTML = "";
let notifyHTML = ""; let notifyHTML = "";
let hasAV = false; let hasAV = false;
@ -263,7 +263,7 @@ const genAttr = (attrs: IObject, focusName = "bookmark") => {
} else if (type === "remove") { } else if (type === "remove") {
fetchPost("/api/attr/setBlockAttrs", { fetchPost("/api/attr/setBlockAttrs", {
id: attrs.id, id: attrs.id,
attrs: {["custom-"+target.previousElementSibling.textContent]: ""} attrs: {["custom-" + target.previousElementSibling.textContent]: ""}
}); });
target.parentElement.parentElement.remove(); target.parentElement.parentElement.remove();
event.stopPropagation(); event.stopPropagation();
@ -285,7 +285,7 @@ const genAttr = (attrs: IObject, focusName = "bookmark") => {
click() { click() {
const bookmarkInputElement = target.parentElement.parentElement.querySelector("input"); const bookmarkInputElement = target.parentElement.parentElement.querySelector("input");
bookmarkInputElement.value = item; bookmarkInputElement.value = item;
bookmarkInputElement.dispatchEvent(new CustomEvent("change")); bookmarkInputElement.dispatchEvent(new CustomEvent("change"));
} }
}).element); }).element);
}); });
@ -350,147 +350,13 @@ const genAttr = (attrs: IObject, focusName = "bookmark") => {
}); });
}; };
export const openFileAttr = (attrs: IObject, id: string, focusName = "bookmark") => { export const openAttr = (nodeElement: Element, 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 += `<div class="protyle-attr--bookmark">${escapeHTML}</div>`;
// } else if (name === "name") {
// nodeAttrHTML += `<div class="protyle-attr--name"><svg><use xlink:href="#iconN"></use></svg>${escapeHTML}</div>`;
// } else if (name === "alias") {
// nodeAttrHTML += `<div class="protyle-attr--alias"><svg><use xlink:href="#iconA"></use></svg>${escapeHTML}</div>`;
// } else if (name === "memo") {
// nodeAttrHTML += `<div class="protyle-attr--memo b3-tooltips b3-tooltips__sw" aria-label="${escapeHTML}"><svg><use xlink:href="#iconM"></use></svg></div>`;
// }
// }
// });
// 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") => {
if (nodeElement.getAttribute("data-type") === "NodeThematicBreak") { if (nodeElement.getAttribute("data-type") === "NodeThematicBreak") {
return; return;
} }
const id = nodeElement.getAttribute("data-node-id"); const id = nodeElement.getAttribute("data-node-id");
fetchPost("/api/attr/getBlockAttrs", {id}, (response) => { fetchPost("/api/attr/getBlockAttrs", {id}, (response) => {
genAttr(response.data, focusName, openFileAttr(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 += `<div class="protyle-attr--bookmark">${escapeHTML}</div>`;
// } else if (name === "name") {
// nodeAttrHTML += `<div class="protyle-attr--name"><svg><use xlink:href="#iconN"></use></svg>${escapeHTML}</div>`;
// } else if (name === "alias") {
// nodeAttrHTML += `<div class="protyle-attr--alias"><svg><use xlink:href="#iconA"></use></svg>${escapeHTML}</div>`;
// } else if (name === "memo") {
// nodeAttrHTML += `<div class="protyle-attr--memo b3-tooltips b3-tooltips__sw" aria-label="${escapeHTML}"><svg><use xlink:href="#iconM"></use></svg></div>`;
// }
// } 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();
// }
);
}); });
}; };

View file

@ -365,7 +365,7 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
fetchPost("/api/block/getDocInfo", { fetchPost("/api/block/getDocInfo", {
id id
}, (response) => { }, (response) => {
openFileAttr(response.data.ial, id); openFileAttr(response.data.ial);
}); });
} }
}).element); }).element);

View file

@ -85,7 +85,7 @@ export class Breadcrumb {
fetchPost("/api/block/getDocInfo", { fetchPost("/api/block/getDocInfo", {
id: protyle.block.rootID id: protyle.block.rootID
}, (response) => { }, (response) => {
openFileAttr(response.data.ial, protyle.block.rootID); openFileAttr(response.data.ial);
}); });
} else { } else {
const targetRect = target.getBoundingClientRect(); const targetRect = target.getBoundingClientRect();

View file

@ -215,7 +215,7 @@ export class Gutter {
} }
foldElement.classList.remove("protyle-wysiwyg--hl"); foldElement.classList.remove("protyle-wysiwyg--hl");
} else if (window.siyuan.shiftIsPressed && !protyle.disabled) { } 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 { } else {
this.renderMenu(protyle, buttonElement); this.renderMenu(protyle, buttonElement);
// https://ld246.com/article/1648433751993 // https://ld246.com/article/1648433751993
@ -1496,7 +1496,7 @@ export class Gutter {
label: window.siyuan.languages.attr, label: window.siyuan.languages.attr,
accelerator: window.siyuan.config.keymap.editor.general.attr.custom + "/" + updateHotkeyTip("⇧Click"), accelerator: window.siyuan.config.keymap.editor.general.attr.custom + "/" + updateHotkeyTip("⇧Click"),
click() { click() {
openAttr(nodeElement, protyle); openAttr(nodeElement);
} }
}).element); }).element);
} }

View file

@ -140,7 +140,7 @@ export class Title {
fetchPost("/api/block/getDocInfo", { fetchPost("/api/block/getDocInfo", {
id: protyle.block.rootID id: protyle.block.rootID
}, (response) => { }, (response) => {
openFileAttr(response.data.ial, protyle.block.rootID); openFileAttr(response.data.ial);
}); });
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
@ -179,7 +179,7 @@ export class Title {
fetchPost("/api/block/getDocInfo", { fetchPost("/api/block/getDocInfo", {
id: protyle.block.rootID id: protyle.block.rootID
}, (response) => { }, (response) => {
openFileAttr(response.data.ial, protyle.block.rootID); openFileAttr(response.data.ial);
}); });
} else { } else {
const iconRect = iconElement.getBoundingClientRect(); const iconRect = iconElement.getBoundingClientRect();

View file

@ -55,7 +55,7 @@ export const openTitleMenu = (protyle: IProtyle, position: {
label: window.siyuan.languages.attr, label: window.siyuan.languages.attr,
accelerator: window.siyuan.config.keymap.editor.general.attr.custom + "/" + updateHotkeyTip("⇧Click"), accelerator: window.siyuan.config.keymap.editor.general.attr.custom + "/" + updateHotkeyTip("⇧Click"),
click() { click() {
openFileAttr(response.data.ial, protyle.block.rootID); openFileAttr(response.data.ial);
} }
}).element); }).element);
} }

View file

@ -291,7 +291,7 @@ export const showColMenu = (protyle: IProtyle, blockElement: HTMLElement, cellEl
bind(element) { bind(element) {
element.querySelector("input").addEventListener("keydown", (event: KeyboardEvent) => { element.querySelector("input").addEventListener("keydown", (event: KeyboardEvent) => {
if (event.isComposing) { if (event.isComposing) {
return return;
} }
if (event.key === "Enter") { if (event.key === "Enter") {
menu.close(); menu.close();

View file

@ -374,7 +374,7 @@ export const getFiltersHTML = (data: IAVTable) => {
if (index !== filter.value.mSelect.length - 1) { if (index !== filter.value.mSelect.length - 1) {
selectContent += ", "; selectContent += ", ";
} }
}) });
if ("Contains" === filter.operator) { if ("Contains" === filter.operator) {
filterValue = `: ${selectContent}`; filterValue = `: ${selectContent}`;
} else if (filter.operator === "Does not contains") { } else if (filter.operator === "Does not contains") {

View file

@ -17,9 +17,9 @@ export const commonClick = (event: MouseEvent & {
/// #endif /// #endif
} else { } else {
if (data) { if (data) {
openFileAttr(data, protyle.block.rootID, "bookmark"); openFileAttr(data, "bookmark");
} else { } else {
openAttr(attrBookmarkElement.parentElement.parentElement, protyle, "bookmark"); openAttr(attrBookmarkElement.parentElement.parentElement, "bookmark");
} }
} }
event.stopPropagation(); event.stopPropagation();
@ -34,9 +34,9 @@ export const commonClick = (event: MouseEvent & {
/// #endif /// #endif
} else { } else {
if (data) { if (data) {
openFileAttr(data, protyle.block.rootID, "name"); openFileAttr(data, "name");
} else { } else {
openAttr(attrNameElement.parentElement.parentElement, protyle, "name"); openAttr(attrNameElement.parentElement.parentElement, "name");
} }
} }
event.stopPropagation(); event.stopPropagation();
@ -51,9 +51,9 @@ export const commonClick = (event: MouseEvent & {
/// #endif /// #endif
} else { } else {
if (data) { if (data) {
openFileAttr(data, protyle.block.rootID, "alias"); openFileAttr(data, "alias");
} else { } else {
openAttr(attrAliasElement.parentElement.parentElement, protyle, "alias"); openAttr(attrAliasElement.parentElement.parentElement, "alias");
} }
} }
event.stopPropagation(); event.stopPropagation();
@ -68,9 +68,9 @@ export const commonClick = (event: MouseEvent & {
/// #endif /// #endif
} else { } else {
if (data) { if (data) {
openFileAttr(data, protyle.block.rootID, "memo"); openFileAttr(data, "memo");
} else { } else {
openAttr(attrMemoElement.parentElement.parentElement, protyle, "memo"); openAttr(attrMemoElement.parentElement.parentElement, "memo");
} }
} }
event.stopPropagation(); event.stopPropagation();

View file

@ -1929,7 +1929,7 @@ export class WYSIWYG {
} }
hideElements(["gutter"], protyle); hideElements(["gutter"], protyle);
} else if (event.shiftKey) { } else if (event.shiftKey) {
openAttr(actionElement.parentElement, protyle); openAttr(actionElement.parentElement);
} else if (ctrlIsPressed) { } else if (ctrlIsPressed) {
zoomOut({protyle, id: actionElement.parentElement.getAttribute("data-node-id")}); zoomOut({protyle, id: actionElement.parentElement.getAttribute("data-node-id")});
} else { } else {

View file

@ -1042,7 +1042,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
} else { } else {
actionElement = topElement; actionElement = topElement;
} }
openAttr(actionElement, protyle); openAttr(actionElement);
} else { } else {
const oldHTML = topElement.outerHTML; const oldHTML = topElement.outerHTML;
const name = Lute.EscapeHTMLStr(selectText); const name = Lute.EscapeHTMLStr(selectText);