Skip to content

Commit

Permalink
🎨 fix #10327
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Feb 9, 2024
1 parent 6a34c3b commit 8d4f4f9
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions app/src/asset/anno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,25 +309,44 @@ const setRelation = (pdf: any) => {
</div>`,
width: "520px",
});

const addRelation = () => {
if (/\d{14}-\w{7}/.test(inputElement.value)) {
if (!configItem.ids.includes(inputElement.value)) {
configItem.ids.push(inputElement.value);
updateRelation(pdf, config);
rectElement.dataset.relations = configItem.ids;
dialog.element.querySelector(".b3-list").innerHTML = getRelationHTML(configItem.ids);
}
inputElement.value = "";
} else {
showMessage("ID " + window.siyuan.languages.invalid);
}
}

const updateRelation = (pdf: any, config: any) => {
fetchPost("/api/asset/setFileAnnotation", {
path: pdf.appConfig.file.replace(location.origin, "").substr(1) + ".sya",
data: JSON.stringify(config),
});
}

const inputElement = dialog.element.querySelector(".b3-text-field") as HTMLInputElement
inputElement.focus();

inputElement.addEventListener("keydown", (event) => {
if (event.isComposing) {
return
}
if (event.key === "Enter") {
addRelation();
}
})
dialog.element.addEventListener("click", (event) => {
let target = event.target as HTMLElement;
while (target && !target.classList.contains("b3-dialog__content")) {
const type = target.getAttribute("data-type");
if (type === "add") {
if (/\d{14}-\w{7}/.test(inputElement.value)) {
if (!configItem.ids.includes(inputElement.value)) {
configItem.ids.push(inputElement.value);
updateRelation(pdf, config);
rectElement.dataset.relations = configItem.ids;
dialog.element.querySelector(".b3-list").innerHTML = getRelationHTML(configItem.ids);
}
inputElement.value = "";
} else {
showMessage("ID " + window.siyuan.languages.invalid);
}
addRelation();
event.preventDefault();
event.stopPropagation();
break;
Expand All @@ -342,13 +361,6 @@ const setRelation = (pdf: any) => {
});
}

const updateRelation = (pdf: any, config: any) => {
fetchPost("/api/asset/setFileAnnotation", {
path: pdf.appConfig.file.replace(location.origin, "").substr(1) + ".sya",
data: JSON.stringify(config),
});
}

const hideToolbar = (element: HTMLElement) => {
element.querySelector(".pdf__util").classList.add("fn__none");
};
Expand Down

0 comments on commit 8d4f4f9

Please sign in to comment.