This commit is contained in:
Vanessa 2023-08-09 22:55:34 +08:00
parent 7f21a05d84
commit 0f8e2969ee
4 changed files with 33 additions and 36 deletions

View File

@ -15,8 +15,8 @@ export const initBlockPopover = (app: App) => {
return; return;
} }
const aElement = hasClosestByAttribute(event.target, "data-type", "a", true) || const aElement = hasClosestByAttribute(event.target, "data-type", "a", true) ||
hasClosestByAttribute(event.target, "data-type", "url") ||
hasClosestByAttribute(event.target, "data-type", "tab-header") || hasClosestByAttribute(event.target, "data-type", "tab-header") ||
hasClosestByClassName(event.target, "av__celltext") ||
hasClosestByClassName(event.target, "ariaLabel") || hasClosestByClassName(event.target, "ariaLabel") ||
hasClosestByAttribute(event.target, "data-type", "inline-memo"); hasClosestByAttribute(event.target, "data-type", "inline-memo");
if (aElement) { if (aElement) {
@ -25,6 +25,9 @@ export const initBlockPopover = (app: App) => {
if (hasClosestByAttribute(event.target, "data-type", "fold", true)) { if (hasClosestByAttribute(event.target, "data-type", "fold", true)) {
tip = window.siyuan.languages.fold; tip = window.siyuan.languages.fold;
} }
if (aElement.classList.contains("av__celltext") && aElement.scrollWidth > aElement.parentElement.clientWidth - 11) {
tip = aElement.textContent;
}
if (!tip) { if (!tip) {
tip = aElement.getAttribute("data-href"); tip = aElement.getAttribute("data-href");
const title = aElement.getAttribute("data-title"); const title = aElement.getAttribute("data-title");
@ -159,8 +162,9 @@ const getTarget = (event: MouseEvent & { target: HTMLElement }, aElement: false
if (!popoverTargetElement) { if (!popoverTargetElement) {
popoverTargetElement = hasClosestByClassName(event.target, "popover__block") as HTMLElement; popoverTargetElement = hasClosestByClassName(event.target, "popover__block") as HTMLElement;
} }
if (!popoverTargetElement && aElement && aElement.getAttribute("data-href")?.startsWith("siyuan://blocks") && if (!popoverTargetElement && aElement && (
aElement.getAttribute("prevent-popover") !== "true") { (aElement.getAttribute("data-href")?.startsWith("siyuan://blocks") && aElement.getAttribute("prevent-popover") !== "true") ||
(aElement.classList.contains("av__celltext") && aElement.dataset.type === "url"))) {
popoverTargetElement = aElement; popoverTargetElement = aElement;
} }
if (!popoverTargetElement || window.siyuan.altIsPressed || if (!popoverTargetElement || window.siyuan.altIsPressed ||
@ -208,11 +212,12 @@ export const showPopover = async (app: App, showRef = false) => {
}); });
ids = postResponse.data; ids = postResponse.data;
} }
} else if ( } else if (popoverTargetElement.getAttribute("data-type")?.split(" ").includes("a")) {
popoverTargetElement.getAttribute("data-type")?.split(" ").includes("a") ||
popoverTargetElement.getAttribute("data-type")?.split(" ").includes("url")) {
// 以思源协议开头的链接 // 以思源协议开头的链接
ids = [getIdFromSYProtocol(popoverTargetElement.getAttribute("data-href"))]; ids = [getIdFromSYProtocol(popoverTargetElement.getAttribute("data-href"))];
} else if (popoverTargetElement.dataset.type === "url") {
// 在 database 的 url 列中以思源协议开头的链接
ids = [getIdFromSYProtocol(popoverTargetElement.textContent.trim())];
} else { } else {
// pdf // pdf
let targetId; let targetId;

View File

@ -116,16 +116,13 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
const linkElement = hasClosestByClassName(event.target, "av__celltext--url"); const linkElement = hasClosestByClassName(event.target, "av__celltext--url");
if (linkElement) { if (linkElement) {
// let prefix = ""; let prefix = "";
// if (linkElement.dataset.type === "phone") { if (linkElement.dataset.type === "phone") {
// prefix = "tel:"; prefix = "tel:";
// } else if (linkElement.dataset.type === "email") { } else if (linkElement.dataset.type === "email") {
// prefix = "mailto:"; prefix = "mailto:";
// } }
// window.open(prefix + linkElement.textContent.trim()); window.open(prefix + linkElement.textContent.trim());
let linkUrl = linkElement.getAttribute("data-href")
window.open(linkUrl.trim());
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return true; return true;

View File

@ -68,18 +68,8 @@ style="width: ${column.width || "200px"}">${getCalcValue(column) || '<svg><use x
let text = ""; let text = "";
if (cell.valueType === "text") { if (cell.valueType === "text") {
text = `<span class="av__celltext">${cell.value?.text.content || ""}</span>`; text = `<span class="av__celltext">${cell.value?.text.content || ""}</span>`;
} else if (cell.valueType === "url") { } else if (["url", "email", "phone"].includes(cell.valueType)) {
text = `<span class="av__celltext av__celltext--url" data-type="url" data-href="${cell.value ? cell.value[cell.valueType as "url"].content : ""}">${cell.value ? cell.value[cell.valueType as "url"].content : ""}</span>`; text = `<span class="av__celltext av__celltext--url" data-type="${cell.valueType}">${cell.value ? cell.value[cell.valueType as "url"].content : ""}</span>`;
if (cell.value && cell.value[cell.valueType as "url"].content) {
text += `<span data-type="copy" class="b3-tooltips b3-tooltips__n block__icon" aria-label="${window.siyuan.languages.copy}"><svg><use xlink:href="#iconCopy"></use></svg></span>`;
}
} else if (cell.valueType === "email") {
text = `<span class="av__celltext av__celltext--url" data-type="email" data-href="${cell.value ? "mailto:" + cell.value[cell.valueType as "url"].content : ""}">${cell.value ? cell.value[cell.valueType as "url"].content : ""}</span>`;
if (cell.value && cell.value[cell.valueType as "url"].content) {
text += `<span data-type="copy" class="b3-tooltips b3-tooltips__n block__icon" aria-label="${window.siyuan.languages.copy}"><svg><use xlink:href="#iconCopy"></use></svg></span>`;
}
} else if (cell.valueType === "phone") {
text = `<span class="av__celltext av__celltext--url" data-type="phone" data-href="${cell.value ? "tel:" + cell.value[cell.valueType as "url"].content : ""}">${cell.value ? cell.value[cell.valueType as "url"].content : ""}</span>`;
if (cell.value && cell.value[cell.valueType as "url"].content) { if (cell.value && cell.value[cell.valueType as "url"].content) {
text += `<span data-type="copy" class="b3-tooltips b3-tooltips__n block__icon" aria-label="${window.siyuan.languages.copy}"><svg><use xlink:href="#iconCopy"></use></svg></span>`; text += `<span data-type="copy" class="b3-tooltips b3-tooltips__n block__icon" aria-label="${window.siyuan.languages.copy}"><svg><use xlink:href="#iconCopy"></use></svg></span>`;
} }

View File

@ -1640,11 +1640,16 @@ export class WYSIWYG {
const range = getEditorRange(this.element); const range = getEditorRange(this.element);
// 需放在嵌入块之前否则嵌入块内的引用、链接、pdf 双链无法点击打开 https://ld246.com/article/1630479789513 // 需放在嵌入块之前否则嵌入块内的引用、链接、pdf 双链无法点击打开 https://ld246.com/article/1630479789513
const blockRefElement = hasClosestByAttribute(event.target, "data-type", "block-ref"); const blockRefElement = hasClosestByAttribute(event.target, "data-type", "block-ref");
let ifaElement = hasClosestByAttribute(event.target, "data-type", "a"); const aElement = hasClosestByAttribute(event.target, "data-type", "a") || hasClosestByAttribute(event.target, "data-type", "url");
const aElement = ifaElement ? ifaElement : hasClosestByAttribute(event.target, "data-type", "url") let aLink = ""
if (blockRefElement || if (aElement) {
(aElement && aElement.getAttribute("data-href").startsWith("siyuan://blocks/")) if (aElement.classList.contains("av__celltext")) {
) { aLink = aElement.textContent.trim()
} else {
aLink = aElement.getAttribute("data-href")
}
}
if (blockRefElement || aLink.startsWith("siyuan://blocks/")) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
hideElements(["dialog", "toolbar"], protyle); hideElements(["dialog", "toolbar"], protyle);
@ -1656,7 +1661,7 @@ export class WYSIWYG {
if (blockRefElement) { if (blockRefElement) {
refBlockId = blockRefElement.getAttribute("data-id"); refBlockId = blockRefElement.getAttribute("data-id");
} else if (aElement) { } else if (aElement) {
refBlockId = aElement.getAttribute("data-href").substring(16, 38); refBlockId = aLink.substring(16, 38);
} }
fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => { fetchPost("/api/block/checkBlockFold", {id: refBlockId}, (foldResponse) => {
@ -1666,7 +1671,7 @@ export class WYSIWYG {
hideKeyboardToolbar(); hideKeyboardToolbar();
/// #else /// #else
if (aElement) { if (aElement) {
window.open(aElement.getAttribute("data-href")); window.open(aLink);
return; return;
} }
if (event.shiftKey) { if (event.shiftKey) {
@ -1743,7 +1748,7 @@ export class WYSIWYG {
if (aElement && !event.altKey) { if (aElement && !event.altKey) {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
const linkAddress = Lute.UnEscapeHTMLStr(aElement.getAttribute("data-href")); const linkAddress = Lute.UnEscapeHTMLStr(aLink);
/// #if MOBILE /// #if MOBILE
openByMobile(linkAddress); openByMobile(linkAddress);
/// #else /// #else