mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 09:30:14 +01:00
This commit is contained in:
parent
eb93255cf3
commit
7486e1a6e2
3 changed files with 37 additions and 4 deletions
|
|
@ -13,6 +13,10 @@ import {focusByRange} from "../../util/selection";
|
||||||
import {writeText} from "../../util/compatibility";
|
import {writeText} from "../../util/compatibility";
|
||||||
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 {Constants} from "../../../constants";
|
||||||
|
import {openAsset} from "../../../editor/util";
|
||||||
|
import {getSearch, isMobile} from "../../../util/functions";
|
||||||
|
|
||||||
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);
|
||||||
|
|
@ -127,7 +131,16 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
|
||||||
} else if (linkElement.classList.contains("b3-chip")) {
|
} else if (linkElement.classList.contains("b3-chip")) {
|
||||||
linkAddress = linkElement.dataset.url;
|
linkAddress = linkElement.dataset.url;
|
||||||
}
|
}
|
||||||
|
const suffix = pathPosix().extname(linkAddress);
|
||||||
|
if (isLocalPath(linkAddress) && !isMobile() && (
|
||||||
|
[".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);
|
window.open(linkAddress);
|
||||||
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -68,11 +68,11 @@ export const getAssetHTML = (data: IAVTable, cellElements: HTMLElement[]) => {
|
||||||
}
|
}
|
||||||
let contentHTML;
|
let contentHTML;
|
||||||
if (item.type === "image") {
|
if (item.type === "image") {
|
||||||
contentHTML = `<span class="fn__flex-1">
|
contentHTML = `<span data-type="openAssetItem" class="fn__flex-1">
|
||||||
<img style="max-height: 180px;max-width: 360px;border-radius: var(--b3-border-radius);margin: 4px 0;" src="${item.content}"/>
|
<img style="max-height: 180px;max-width: 360px;border-radius: var(--b3-border-radius);margin: 4px 0;" src="${item.content}"/>
|
||||||
</span>`;
|
</span>`;
|
||||||
} else {
|
} else {
|
||||||
contentHTML = `<span class="fn__ellipsis b3-menu__label" style="max-width: 360px">${item.name}</span>`;
|
contentHTML = `<span data-type="openAssetItem" class="fn__ellipsis b3-menu__label" style="max-width: 360px">${item.name}</span>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
html += `<button class="b3-menu__item" draggable="true" data-name="${item.name}" data-type="${item.type}" data-content="${item.content}">
|
html += `<button class="b3-menu__item" draggable="true" data-name="${item.name}" data-type="${item.type}" data-content="${item.content}">
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,11 @@ import {removeAttrViewColAnimation, updateAttrViewCellAnimation} from "./action"
|
||||||
import {addAssetLink, bindAssetEvent, editAssetItem, getAssetHTML, updateAssetCell} from "./asset";
|
import {addAssetLink, bindAssetEvent, editAssetItem, getAssetHTML, updateAssetCell} from "./asset";
|
||||||
import {Constants} from "../../../constants";
|
import {Constants} from "../../../constants";
|
||||||
import {hideElements} from "../../ui/hideElements";
|
import {hideElements} from "../../ui/hideElements";
|
||||||
import {pathPosix} from "../../../util/pathName";
|
import {isLocalPath, pathPosix} from "../../../util/pathName";
|
||||||
import {openEmojiPanel, unicode2Emoji} from "../../../emoji";
|
import {openEmojiPanel, unicode2Emoji} from "../../../emoji";
|
||||||
|
import {getSearch, isMobile} from "../../../util/functions";
|
||||||
|
import {openAsset} from "../../../editor/util";
|
||||||
|
import {previewImage} from "../../preview/image";
|
||||||
|
|
||||||
export const openMenuPanel = (options: {
|
export const openMenuPanel = (options: {
|
||||||
protyle: IProtyle,
|
protyle: IProtyle,
|
||||||
|
|
@ -741,6 +744,23 @@ export const openMenuPanel = (options: {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
|
} else if (type === "openAssetItem") {
|
||||||
|
const assetLink = target.parentElement.dataset.content;
|
||||||
|
const suffix = pathPosix().extname(assetLink)
|
||||||
|
if (isLocalPath(assetLink) && !isMobile() && (
|
||||||
|
[".pdf"].concat(Constants.SIYUAN_ASSETS_AUDIO).concat(Constants.SIYUAN_ASSETS_VIDEO).includes(suffix) && (
|
||||||
|
suffix !== ".pdf" || ( suffix === ".pdf" && !assetLink.startsWith("file://"))
|
||||||
|
)
|
||||||
|
)) {
|
||||||
|
openAsset(options.protyle.app, assetLink.trim(), parseInt(getSearch("page", assetLink)), "right");
|
||||||
|
} else if (Constants.SIYUAN_ASSETS_IMAGE.includes(suffix)) {
|
||||||
|
previewImage(assetLink);
|
||||||
|
} else {
|
||||||
|
window.open(assetLink);
|
||||||
|
}
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
break;
|
||||||
} else if (type === "editAssetItem") {
|
} else if (type === "editAssetItem") {
|
||||||
editAssetItem(options.protyle, data, options.cellElements, target.parentElement);
|
editAssetItem(options.protyle, data, options.cellElements, target.parentElement);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue