-
${window.siyuan.languages.bookmark}
-
+ height: "80vh",
+ content: `
+
+
+
+ ${window.siyuan.languages.attr}
+
-
-
-
-
-
-
- ${notifyHTML}
- ${customHTML}
-
-
-
-
-
+
+
+ ${window.siyuan.languages.database}
+
+
+
+
+ ${window.siyuan.languages.custom}
+
+
+
+
+
+
+
+
+
+ ${notifyHTML}
+
+
+ ${avHTML}
+
+
+ ${customHTML}
+
+
+
+
+
+
+
+
+
`,
destroyCallback() {
focusByRange(range);
@@ -229,19 +267,32 @@ const genAttr = (attrs: IObject, focusName = "bookmark", cb: (dialog: Dialog, rm
(dialog.element.querySelector('.b3-text-field[data-name="alias"]') as HTMLInputElement).value = attrs.alias || "";
const removeAttrs: string[] = [];
dialog.element.addEventListener("click", (event) => {
- const target = event.target as HTMLElement;
- const actionElement = hasClosestByClassName(target, "block__icon");
- if (!actionElement) {
+ let target = event.target as HTMLElement;
+ if (typeof event.detail === "string" && event.detail === "confirm") {
+ cb(dialog, removeAttrs);
return;
}
- switch (actionElement.getAttribute("data-action")) {
- case "remove":
- if (actionElement.previousElementSibling.tagName === "SPAN") {
- removeAttrs.push(actionElement.parentElement.parentElement.querySelector("textarea").getAttribute("data-name"));
+ while (!target.isSameNode(dialog.element)) {
+ const type = target.dataset.action
+ if (target.classList.contains("item--full")) {
+ target.parentElement.querySelector('.item--focus').classList.remove("item--focus")
+ target.classList.add("item--focus")
+ dialog.element.querySelectorAll(".custom-attr").forEach((item: HTMLElement) => {
+ if (item.dataset.type === target.dataset.type) {
+ item.classList.remove("fn__none")
+ } else {
+ item.classList.add("fn__none")
+ }
+ })
+ } else if (type === "remove") {
+ if (target.previousElementSibling.tagName === "SPAN") {
+ removeAttrs.push(target.parentElement.parentElement.querySelector("textarea").getAttribute("data-name"));
}
- actionElement.parentElement.parentElement.remove();
+ target.parentElement.parentElement.remove();
+ event.stopPropagation()
+ event.preventDefault()
break;
- case "bookmark":
+ } else if (type === "bookmark") {
fetchPost("/api/attr/getBookmarkLabels", {}, (response) => {
window.siyuan.menus.menu.remove();
if (response.data.length === 0) {
@@ -255,7 +306,7 @@ const genAttr = (attrs: IObject, focusName = "bookmark", cb: (dialog: Dialog, rm
window.siyuan.menus.menu.append(new MenuItem({
label: item,
click() {
- actionElement.parentElement.parentElement.querySelector("input").value = item;
+ target.parentElement.parentElement.querySelector("input").value = item;
}
}).element);
});
@@ -264,12 +315,11 @@ const genAttr = (attrs: IObject, focusName = "bookmark", cb: (dialog: Dialog, rm
window.siyuan.menus.menu.element.classList.add("b3-menu--list");
window.siyuan.menus.menu.popup({x: event.clientX, y: event.clientY + 16, w: 16});
});
+ event.stopPropagation()
+ event.preventDefault()
break;
- }
- });
- const btnsElement = dialog.element.querySelectorAll(".b3-button");
- btnsElement[0].addEventListener("click", () => {
- dialog.element.querySelector(".custom-attr").insertAdjacentHTML("beforeend", `
+ } else if (type === "addCustom") {
+ target.parentElement.insertAdjacentHTML("beforebegin", `
`);
- const inputElements = dialog.element.querySelectorAll(".b3-text-field") as NodeListOf
;
- inputElements[inputElements.length - 2].focus();
- bindAttrInput(inputElements[inputElements.length - 1], btnsElement[2]);
- bindAttrInput(inputElements[inputElements.length - 2], btnsElement[2]);
- });
- btnsElement[1].addEventListener("click", () => {
- dialog.destroy();
- });
- btnsElement[2].addEventListener("click", () => {
- cb(dialog, removeAttrs);
+ const inputElements = dialog.element.querySelectorAll(".b3-text-field") as NodeListOf;
+ inputElements[inputElements.length - 2].focus();
+ bindAttrInput(inputElements[inputElements.length - 1], dialog.element);
+ bindAttrInput(inputElements[inputElements.length - 2], dialog.element);
+ event.stopPropagation()
+ event.preventDefault()
+ break;
+ } else if (type === "closeDialog") {
+ dialog.destroy();
+ } else if (type === "confirm") {
+ cb(dialog, removeAttrs);
+ }
+ target = target.parentElement;
+ }
});
dialog.element.querySelectorAll(".b3-text-field").forEach((item: HTMLInputElement) => {
if (focusName === item.getAttribute("data-name")) {
item.focus();
}
- bindAttrInput(item, btnsElement[2]);
+ bindAttrInput(item, dialog.element);
});
};