mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-21 19:41:05 +08:00
This commit is contained in:
parent
377c6e2c60
commit
835a4eab3f
@ -13,10 +13,10 @@ import {hintRef} from "../../hint/extend";
|
|||||||
import {focusByRange} from "../../util/selection";
|
import {focusByRange} from "../../util/selection";
|
||||||
import {showMessage} from "../../../dialog/message";
|
import {showMessage} from "../../../dialog/message";
|
||||||
import {previewImage} from "../../preview/image";
|
import {previewImage} from "../../preview/image";
|
||||||
import {isLocalPath, pathPosix} from "../../../util/pathName";
|
import {pathPosix} from "../../../util/pathName";
|
||||||
import {Constants} from "../../../constants";
|
import {Constants} from "../../../constants";
|
||||||
/// #if !MOBILE
|
/// #if !MOBILE
|
||||||
import {openAsset} from "../../../editor/util";
|
import {openAsset, openBy} from "../../../editor/util";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {getSearch} from "../../../util/functions";
|
import {getSearch} from "../../../util/functions";
|
||||||
import {unicode2Emoji} from "../../../emoji";
|
import {unicode2Emoji} from "../../../emoji";
|
||||||
@ -25,21 +25,83 @@ import * as dayjs from "dayjs";
|
|||||||
import {openCalcMenu} from "./calc";
|
import {openCalcMenu} from "./calc";
|
||||||
import {avRender} from "./render";
|
import {avRender} from "./render";
|
||||||
import {addView, openViewMenu} from "./view";
|
import {addView, openViewMenu} from "./view";
|
||||||
import {writeText} from "../../util/compatibility";
|
import {isOnlyMeta, openByMobile, writeText} from "../../util/compatibility";
|
||||||
|
|
||||||
export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLElement }) => {
|
export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLElement }) => {
|
||||||
const blockElement = hasClosestBlock(event.target);
|
const blockElement = hasClosestBlock(event.target);
|
||||||
if (!blockElement) {
|
if (!blockElement) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
const loadMoreElement = hasClosestByAttribute(event.target, "data-type", "av-load-more");
|
||||||
|
if (loadMoreElement) {
|
||||||
|
(blockElement.querySelector(".av__row--footer") as HTMLElement).style.transform = "";
|
||||||
|
blockElement.removeAttribute("data-render");
|
||||||
|
blockElement.dataset.pageSize = (parseInt(blockElement.dataset.pageSize) + parseInt(blockElement.querySelector('[data-type="set-page-size"]').getAttribute("data-size"))).toString();
|
||||||
|
avRender(blockElement, protyle);
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const firstColElement = hasClosestByClassName(event.target, "av__firstcol");
|
||||||
|
if (firstColElement) {
|
||||||
|
window.siyuan.menus.menu.remove();
|
||||||
|
selectRow(firstColElement, "toggle");
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const urlElement = hasClosestByClassName(event.target, "av__celltext--url");
|
||||||
|
if (urlElement) {
|
||||||
|
let linkAddress = urlElement.textContent.trim();
|
||||||
|
if (urlElement.dataset.type === "phone") {
|
||||||
|
linkAddress = "tel:" + linkAddress;
|
||||||
|
} else if (urlElement.dataset.type === "email") {
|
||||||
|
linkAddress = "mailto:" + linkAddress;
|
||||||
|
} else if (urlElement.classList.contains("b3-chip")) {
|
||||||
|
linkAddress = urlElement.dataset.url;
|
||||||
|
}
|
||||||
|
/// #if !MOBILE
|
||||||
|
const suffix = pathPosix().extname(linkAddress);
|
||||||
|
const ctrlIsPressed = isOnlyMeta(event);
|
||||||
|
if (Constants.SIYUAN_ASSETS_EXTS.includes(suffix)) {
|
||||||
|
if (event.altKey) {
|
||||||
|
openAsset(protyle.app, linkAddress.trim(), parseInt(getSearch("page", linkAddress)));
|
||||||
|
} else if (!ctrlIsPressed && !event.shiftKey) {
|
||||||
|
openAsset(protyle.app, linkAddress.trim(), parseInt(getSearch("page", linkAddress)), "right");
|
||||||
|
}
|
||||||
|
} else if (!ctrlIsPressed && !event.shiftKey && !event.altKey) {
|
||||||
|
openByMobile(linkAddress);
|
||||||
|
}
|
||||||
|
/// #if !BROWSER
|
||||||
|
if (ctrlIsPressed) {
|
||||||
|
openBy(linkAddress, "folder");
|
||||||
|
} else if (event.shiftKey) {
|
||||||
|
openBy(linkAddress, "app");
|
||||||
|
}
|
||||||
|
/// #endif
|
||||||
|
/// #else
|
||||||
|
openByMobile(linkAddress);
|
||||||
|
/// #endif
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const imgElement = hasClosestByClassName(event.target, "av__cellassetimg");
|
||||||
|
if (imgElement) {
|
||||||
|
previewImage((imgElement as HTMLImageElement).src);
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (event.shiftKey) {
|
if (event.shiftKey) {
|
||||||
const rowElement = hasClosestByClassName(event.target, "av__row");
|
const rowElement = hasClosestByClassName(event.target, "av__row");
|
||||||
if (rowElement && !rowElement.classList.contains("av__row--header")) {
|
if (rowElement && !rowElement.classList.contains("av__row--header")) {
|
||||||
selectRow(rowElement.querySelector(".av__firstcol"), "toggle");
|
selectRow(rowElement.querySelector(".av__firstcol"), "toggle");
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const copyElement = hasClosestByAttribute(event.target, "data-type", "copy");
|
const copyElement = hasClosestByAttribute(event.target, "data-type", "copy");
|
||||||
if (copyElement) {
|
if (copyElement) {
|
||||||
writeText(getCellText(hasClosestByClassName(copyElement, "av__cell")));
|
writeText(getCellText(hasClosestByClassName(copyElement, "av__cell")));
|
||||||
@ -159,14 +221,6 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
return true;
|
return true;
|
||||||
} else if (type === "av-load-more") {
|
|
||||||
(blockElement.querySelector(".av__row--footer") as HTMLElement).style.transform = "";
|
|
||||||
blockElement.removeAttribute("data-render");
|
|
||||||
blockElement.dataset.pageSize = (parseInt(blockElement.dataset.pageSize) + parseInt(blockElement.querySelector('[data-type="set-page-size"]').getAttribute("data-size"))).toString();
|
|
||||||
avRender(blockElement, protyle);
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
return true;
|
|
||||||
} else if (type === "set-page-size") {
|
} else if (type === "set-page-size") {
|
||||||
setPageSize({
|
setPageSize({
|
||||||
target,
|
target,
|
||||||
@ -207,44 +261,6 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
return true;
|
return true;
|
||||||
} else if (target.classList.contains("av__firstcol")) {
|
|
||||||
window.siyuan.menus.menu.remove();
|
|
||||||
selectRow(target, "toggle");
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
return true;
|
|
||||||
} else if (target.classList.contains("av__celltext--url")) {
|
|
||||||
let linkAddress = target.textContent.trim();
|
|
||||||
if (target.dataset.type === "phone") {
|
|
||||||
linkAddress = "tel:" + linkAddress;
|
|
||||||
} else if (target.dataset.type === "email") {
|
|
||||||
linkAddress = "mailto:" + linkAddress;
|
|
||||||
} else if (target.classList.contains("b3-chip")) {
|
|
||||||
linkAddress = target.dataset.url;
|
|
||||||
}
|
|
||||||
/// #if !MOBILE
|
|
||||||
const suffix = pathPosix().extname(linkAddress);
|
|
||||||
if (isLocalPath(linkAddress) && (
|
|
||||||
[".pdf"].concat(Constants.SIYUAN_ASSETS_AUDIO).concat(Constants.SIYUAN_ASSETS_VIDEO).includes(suffix) && (
|
|
||||||
suffix !== ".pdf" || (suffix === ".pdf" && !linkAddress.startsWith("file://"))
|
|
||||||
)
|
|
||||||
)) {
|
|
||||||
openAsset(protyle.app, linkAddress.trim(), parseInt(getSearch("page", linkAddress)), "right");
|
|
||||||
} else {
|
|
||||||
window.open(linkAddress);
|
|
||||||
}
|
|
||||||
/// #else
|
|
||||||
window.open(linkAddress);
|
|
||||||
/// #endif
|
|
||||||
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
return true;
|
|
||||||
} else if (target.classList.contains("av__cellassetimg")) {
|
|
||||||
previewImage((target as HTMLImageElement).src);
|
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
return true;
|
|
||||||
} else if (target.classList.contains("av__cell--header")) {
|
} else if (target.classList.contains("av__cell--header")) {
|
||||||
showColMenu(protyle, blockElement, target);
|
showColMenu(protyle, blockElement, target);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
Loading…
Reference in New Issue
Block a user