mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 17:40:13 +01:00
This commit is contained in:
parent
cb85bb8080
commit
a708969984
2 changed files with 24 additions and 40 deletions
|
|
@ -2,7 +2,7 @@ import {fetchPost} from "../util/fetch";
|
||||||
import {setPosition} from "../util/setPosition";
|
import {setPosition} from "../util/setPosition";
|
||||||
import {hasClosestByAttribute, hasClosestByClassName} from "../protyle/util/hasClosest";
|
import {hasClosestByAttribute, hasClosestByClassName} from "../protyle/util/hasClosest";
|
||||||
import * as dayjs from "dayjs";
|
import * as dayjs from "dayjs";
|
||||||
import {writeText} from "../protyle/util/compatibility";
|
import {setStorageVal, writeText} from "../protyle/util/compatibility";
|
||||||
import {getAllModels} from "../layout/getAll";
|
import {getAllModels} from "../layout/getAll";
|
||||||
/// #if !BROWSER
|
/// #if !BROWSER
|
||||||
import {NativeImage} from "electron";
|
import {NativeImage} from "electron";
|
||||||
|
|
@ -109,14 +109,22 @@ export const initAnno = (file: string, element: HTMLElement, annoId: string, pdf
|
||||||
documentSelf.onselect = null;
|
documentSelf.onselect = null;
|
||||||
rectAnnoElement.classList.remove("toggled");
|
rectAnnoElement.classList.remove("toggled");
|
||||||
pdfConfig.mainContainer.classList.remove("rect-to-annotation");
|
pdfConfig.mainContainer.classList.remove("rect-to-annotation");
|
||||||
rectResizeElement.setAttribute("data-render", "true");
|
|
||||||
const utilElement = element.querySelector(".pdf__util") as HTMLElement;
|
const coords = getHightlightCoordsByRect(pdf, window.siyuan.storage[Constants.LOCAL_PDFTHEME].annoColor || "var(--b3-pdf-background1)", rectResizeElement,
|
||||||
utilElement.classList.remove("pdf__util--hide", "fn__none");
|
rectResizeElement.style.backgroundColor ? "text" : "border");
|
||||||
const targetRect = rectResizeElement.getBoundingClientRect();
|
rectResizeElement.classList.add("fn__none");
|
||||||
setPosition(utilElement, targetRect.left,
|
if (coords) {
|
||||||
targetRect.top + targetRect.height + 4);
|
coords.forEach((item, index) => {
|
||||||
rectElement = null;
|
const newElement = showHighlight(item, pdf);
|
||||||
utilElement.classList.add("pdf__util--hide");
|
if (index === 0) {
|
||||||
|
rectElement = newElement;
|
||||||
|
copyAnno(`${pdf.appConfig.file.replace(location.origin, "").substr(1)}/${rectElement.getAttribute("data-node-id")}`,
|
||||||
|
pdf.appConfig.file.replace(location.origin, "").substr(8).replace(/-\d{14}-\w{7}.pdf$/, ""));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
rectElement = null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -127,6 +135,8 @@ export const initAnno = (file: string, element: HTMLElement, annoId: string, pdf
|
||||||
const type = target.getAttribute("data-type");
|
const type = target.getAttribute("data-type");
|
||||||
if (target.classList.contains("color__square")) {
|
if (target.classList.contains("color__square")) {
|
||||||
const color = target.style.backgroundColor;
|
const color = target.style.backgroundColor;
|
||||||
|
window.siyuan.storage[Constants.LOCAL_PDFTHEME].annoColor = color;
|
||||||
|
setStorageVal(Constants.LOCAL_PDFTHEME, window.siyuan.storage[Constants.LOCAL_PDFTHEME]);
|
||||||
if (rectElement) {
|
if (rectElement) {
|
||||||
const config = getConfig(pdf);
|
const config = getConfig(pdf);
|
||||||
const annoItem = config[rectElement.getAttribute("data-node-id")];
|
const annoItem = config[rectElement.getAttribute("data-node-id")];
|
||||||
|
|
@ -144,14 +154,7 @@ export const initAnno = (file: string, element: HTMLElement, annoId: string, pdf
|
||||||
data: JSON.stringify(config),
|
data: JSON.stringify(config),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let coords;
|
const coords = getHightlightCoordsByRange(pdf, color);
|
||||||
if (pdfConfig.mainContainer.lastElementChild.classList.contains("fn__none")) {
|
|
||||||
coords = getHightlightCoordsByRange(pdf, color);
|
|
||||||
} else {
|
|
||||||
coords = getHightlightCoordsByRect(pdf, color, pdfConfig.mainContainer.lastElementChild,
|
|
||||||
pdfConfig.mainContainer.lastElementChild.style.backgroundColor ? "text" : "border");
|
|
||||||
pdfConfig.mainContainer.lastElementChild.classList.add("fn__none");
|
|
||||||
}
|
|
||||||
if (coords) {
|
if (coords) {
|
||||||
coords.forEach((item, index) => {
|
coords.forEach((item, index) => {
|
||||||
const newElement = showHighlight(item, pdf);
|
const newElement = showHighlight(item, pdf);
|
||||||
|
|
@ -170,7 +173,6 @@ export const initAnno = (file: string, element: HTMLElement, annoId: string, pdf
|
||||||
break;
|
break;
|
||||||
} else if (target.classList.contains("pdf__rect")) {
|
} else if (target.classList.contains("pdf__rect")) {
|
||||||
showToolbar(element, undefined, target);
|
showToolbar(element, undefined, target);
|
||||||
pdfConfig.mainContainer.lastElementChild.classList.add("fn__none");
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
processed = true;
|
processed = true;
|
||||||
|
|
@ -230,36 +232,18 @@ export const initAnno = (file: string, element: HTMLElement, annoId: string, pdf
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const rectIsResize = !pdfConfig.mainContainer.lastElementChild.classList.contains(
|
|
||||||
"fn__none");
|
|
||||||
let isShow = false;
|
let isShow = false;
|
||||||
const selection = window.getSelection();
|
const selection = window.getSelection();
|
||||||
if (selection.rangeCount > 0) {
|
if (selection.rangeCount > 0) {
|
||||||
const range = selection.getRangeAt(0);
|
const range = selection.getRangeAt(0);
|
||||||
if (range.toString() !== "" &&
|
if (range.toString() !== "" &&
|
||||||
hasClosestByClassName(range.commonAncestorContainer, "pdfViewer")) {
|
hasClosestByClassName(range.commonAncestorContainer, "pdfViewer")) {
|
||||||
if (rectIsResize) {
|
showToolbar(element, range);
|
||||||
range.collapse(true);
|
isShow = true;
|
||||||
} else {
|
|
||||||
showToolbar(element, range);
|
|
||||||
isShow = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isShow) {
|
if (!isShow) {
|
||||||
if (rectIsResize) {
|
hideToolbar(element);
|
||||||
if (!hasClosestByClassName(event.target as HTMLElement, "pdf__util") &&
|
|
||||||
!hasClosestByClassName(event.target as HTMLElement, "pdf__resize") &&
|
|
||||||
pdfConfig.mainContainer.lastElementChild.getAttribute(
|
|
||||||
"data-render") !== "true") {
|
|
||||||
hideToolbar(element);
|
|
||||||
pdfConfig.mainContainer.lastElementChild.classList.add("fn__none");
|
|
||||||
}
|
|
||||||
pdfConfig.mainContainer.lastElementChild.removeAttribute("data-render");
|
|
||||||
} else {
|
|
||||||
hideToolbar(element);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ export const getLocalStorage = (cb: () => void) => {
|
||||||
rowTab: "",
|
rowTab: "",
|
||||||
layoutTab: 0
|
layoutTab: 0
|
||||||
};
|
};
|
||||||
defaultStorage[Constants.LOCAL_PDFTHEME] = {light: "light", dark: "dark"};
|
defaultStorage[Constants.LOCAL_PDFTHEME] = {light: "light", dark: "dark", annoColor: "var(--b3-pdf-background1)"};
|
||||||
defaultStorage[Constants.LOCAL_BAZAAR] = {
|
defaultStorage[Constants.LOCAL_BAZAAR] = {
|
||||||
theme: "0",
|
theme: "0",
|
||||||
template: "0",
|
template: "0",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue