An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Improve image tooltips with file metadata https://github.com/siyuan-note/siyuan/issues/19973
Daniel72b62a4d5f50
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100744-br924ar.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100744-br924ar.syindex 027d30791c..bcba3165a9 100644--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100744-br924ar.sy+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20200924100744-br924ar.sy@@ -6,7 +6,7 @@"id": "20200924100744-br924ar","title": "Assets","type": "doc",- "updated": "20260930092955"+ "updated": "20260930093600"},"Children": [{@@ -439,6 +439,20 @@}]},+ {+ "ID": "20260930093600-gqubib2",+ "Type": "NodeParagraph",+ "Properties": {+ "id": "20260930093600-gqubib2",+ "updated": "20260930093600"+ },+ "Children": [+ {+ "Type": "NodeText",+ "Data": "Hover over an image to see its file name, format, loaded original dimensions, title, and tooltip text, even if it has no title. Local workspace images also show file size when available. File size is omitted for remote and encrypted notebook images."+ }+ ]+ },{"ID": "20210115224203-q8bj2gd","Type": "NodeHeading",diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200915214115-42b8zma.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200915214115-42b8zma.syindex 004022d195..a2781475af 100644--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200915214115-42b8zma.sy+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20200915214115-42b8zma.sy@@ -6,7 +6,7 @@"id": "20200915214115-42b8zma","title": "资源文件","type": "doc",- "updated": "20260930092955"+ "updated": "20260930093600"},"Children": [{@@ -439,6 +439,20 @@}]},+ {+ "ID": "20260930093600-1i30uia",+ "Type": "NodeParagraph",+ "Properties": {+ "id": "20260930093600-1i30uia",+ "updated": "20260930093600"+ },+ "Children": [+ {+ "Type": "NodeText",+ "Data": "鼠标悬浮图片可查看文件名、格式、已加载图片的原始尺寸、标题和提示文本,无标题的图片也会显示这些信息。本地工作空间图片还会显示可获取的文件大小。网络图片和加密笔记本图片不显示文件大小。"+ }+ ]+ },{"ID": "20210115222011-bzsftun","Type": "NodeHeading",diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123038-4umgpxy.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123038-4umgpxy.syindex e516b7d28a..1a6046d714 100644--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123038-4umgpxy.sy+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20211226123038-4umgpxy.sy@@ -6,7 +6,7 @@"id": "20211226123038-4umgpxy","title": "資料文件","type": "doc",- "updated": "20260930092955"+ "updated": "20260930093600"},"Children": [{@@ -435,6 +435,20 @@}]},+ {+ "ID": "20260930093600-c7ee53e",+ "Type": "NodeParagraph",+ "Properties": {+ "id": "20260930093600-c7ee53e",+ "updated": "20260930093600"+ },+ "Children": [+ {+ "Type": "NodeText",+ "Data": "滑鼠懸停圖片可查看檔名、格式、已載入圖片的原始尺寸、標題和提示文字,無標題的圖片也會顯示這些資訊。本機工作空間圖片還會顯示可取得的檔案大小。網路圖片和加密筆記本圖片不顯示檔案大小。"+ }+ ]+ },{"ID": "20211226123051-5250xg7","Type": "NodeHeading",diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-1m5un7l.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-1m5un7l.syindex 42afaddf07..f9c38cbf9c 100644--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-1m5un7l.sy+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-1m5un7l.sy@@ -7,7 +7,7 @@"id": "20240530101000-1m5un7l","title": "アセット","type": "doc",- "updated": "20260930092955"+ "updated": "20260930093600"},"Children": [{@@ -384,7 +384,7 @@{"Type": "NodeTextMark","TextMarkType": "kbd",- "TextMarkTextContent": "エディター"+ "TextMarkTextContent": "エディタ"},{"Type": "NodeText",@@ -421,7 +421,7 @@{"Type": "NodeTextMark","TextMarkType": "kbd",- "TextMarkTextContent": "エディター"+ "TextMarkTextContent": "エディタ"},{"Type": "NodeText",@@ -430,7 +430,7 @@{"Type": "NodeTextMark","TextMarkType": "kbd",- "TextMarkTextContent": "画像のツールチップテキストを表示"+ "TextMarkTextContent": "画像のツールチップのテキストを表示"},{"Type": "NodeText",@@ -438,6 +438,20 @@}]},+ {+ "ID": "20260930093600-nnyntle",+ "Type": "NodeParagraph",+ "Properties": {+ "id": "20260930093600-nnyntle",+ "updated": "20260930093600"+ },+ "Children": [+ {+ "Type": "NodeText",+ "Data": "画像にマウスを合わせると、タイトルがなくてもファイル名、形式、読み込み済み画像の元のサイズ、タイトル、ツールチップテキストを確認できます。ローカルワークスペースの画像では、取得できる場合にファイルサイズも表示されます。ネットワーク画像と暗号化ノートブックの画像ではファイルサイズは表示されません。"+ }+ ]+ },{"ID": "20240530101000-m2u22gy","Type": "NodeHeading",diff --git a/app/src/block/popover.test.ts b/app/src/block/popover.test.tsindex 811ea224a4..e75f93c1b6 100644--- a/app/src/block/popover.test.ts+++ b/app/src/block/popover.test.ts@@ -11,6 +11,7 @@ const browserCases = async (source: string) => {const check = require("node:assert/strict");const requests: ((response: unknown) => void)[] = [];let tooltip = "";+ const assetRequests: {path: string, signal: AbortSignal, receive: (response: unknown) => void}[] = [];class Panel {element = document.createElement("div");editors: {protyle: IProtyle}[] = [];@@ -38,6 +39,14 @@ const browserCases = async (source: string) => {fetchSyncPost: () => new Promise(resolve => requests.push(resolve)),hideTooltip: () => {},showTooltip: (text: string) => { tooltip = text; },+ fetchPost: (_url: string, body: {path: string}, receive: (response: unknown) => void,+ _before: unknown, _after: unknown, signal: AbortSignal) => {+ assetRequests.push({path: body.path, receive, signal});+ },+ isLocalPath: (value: string) => value.startsWith("assets/"),+ getAssetExtension: (value: string) => require("node:path").posix.extname(value),+ getAssetName: (value: string) => require("node:path").posix.basename(value, require("node:path").posix.extname(value))+ .replace(/-\d{14}-\w{7}$/, ""),Constants: {TIMEOUT_INPUT: 5},isTouchDevice: () => false,isEncryptedBox: () => false,@@ -153,6 +162,36 @@ const browserCases = async (source: string) => {image.title = image.alt;image.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));check.equal(tooltip, "<literal> description");++ image.title = "";+ image.alt = "";+ image.setAttribute("data-src", "assets/photo%20%3Cname%3E-20260930090000-abcdefg.png");+ Object.defineProperties(image, {naturalWidth: {value: 1920}, naturalHeight: {value: 1080}});+ image.style.width = "100px";+ image.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));+ check.equal(tooltip, 'photo <name>.png<div class="fn__hr"></div>PNG · 1920 × 1080');+ check.equal(assetRequests.length, 1);+ assetRequests[0].receive({code: 0, data: {hSize: "2 MiB"}});+ check.match(tooltip, /PNG · 1920 × 1080 · 2 MiB$/);+ image.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));+ document.body.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));+ check.equal(assetRequests[1].signal.aborted, true);+ tooltip = "later target";+ assetRequests[1].receive({code: 0, data: {hSize: "stale"}});+ check.equal(tooltip, "later target");+ image.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));+ const unavailable = tooltip;+ assetRequests[2].receive({code: 1, data: null});+ check.equal(tooltip, unavailable);+ image.setAttribute("data-src", "https://example.com/photo.webp");+ image.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));+ check.match(tooltip, /photo.webp.*WEBP · 1920 × 1080/);+ check.equal(assetRequests.length, 3);+ image.setAttribute("data-src", "assets/encrypted.png?box=encrypted");+ image.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));+ check.equal(assetRequests.length, 3);+ check.equal(image.title, "");+ check.equal(image.alt, "");return "Popover interaction cases passed";};diff --git a/app/src/block/popover.ts b/app/src/block/popover.tsindex 279139d5ad..0eff8bb8da 100644--- a/app/src/block/popover.ts+++ b/app/src/block/popover.ts@@ -120,6 +120,23 @@ export const initBlockPopover = (app: App) => {let tooltipPositionOverride = isListItemAction ? "north" : undefined;let tip = image ? getImageTooltip(image) : isListItemAction ? window.siyuan.languages.listItemActionTip :aElement.getAttribute("aria-label") || "";+ const imagePath = image?.getAttribute("data-src") || image?.getAttribute("src") || "";+ if (image && !window.siyuan.isPublish && isLocalPath(imagePath) && !/[?&]box=/.test(imagePath) &&+ !isEncryptedBox(image.closest("[data-notebook-id]")?.getAttribute("data-notebook-id"))) {+ tooltipAbortController = new AbortController();+ const capturedController = tooltipAbortController;+ fetchPost("/api/asset/statAsset", {path: imagePath}, (response) => {+ if (capturedController.signal.aborted || !image.isConnected) {+ return;+ }+ if (response.code === 0 && response.data) {+ showTooltip(getImageTooltip(image, response.data.hSize), image, undefined, event);+ }+ if (tooltipAbortController === capturedController) {+ tooltipAbortController = null;+ }+ }, undefined, undefined, capturedController.signal);+ }if (aElement.classList.contains("av__cell") && !aElement.classList.contains("ariaLabel")) {if (aElement.classList.contains("av__cell--header")) {const textElement = aElement.querySelector(".av__celltext");diff --git a/app/src/protyle/render/imageTooltip.ts b/app/src/protyle/render/imageTooltip.tsindex ff55bc8ac6..68c3cd8319 100644--- a/app/src/protyle/render/imageTooltip.ts+++ b/app/src/protyle/render/imageTooltip.ts@@ -1,5 +1,23 @@import {escapeHtml} from "../../util/escape";+import {getAssetExtension, getAssetName} from "../../util/pathName";-export const getImageTooltip = (image: HTMLImageElement) => {- return Array.from(new Set([image.title, image.alt].filter(Boolean))).map(text => escapeHtml(text)).join("<br>");+export const getImageTooltip = (image: HTMLImageElement, size?: string) => {+ const source = image.getAttribute("data-src") || image.getAttribute("src") || "";+ const path = source.split(/[?#]/)[0];+ const inline = /^(data|blob):/.test(path);+ const extension = inline ? "" : getAssetExtension(path);+ let name = inline ? "" : getAssetName(path) + extension;+ try {+ name = decodeURIComponent(name);+ } catch (error) {+ // 非 URL 编码的文件名保留原文。+ }+ const text = Array.from(new Set([name, image.title, image.alt].filter(Boolean)))+ .map(value => escapeHtml(value)).join("<br>");+ const format = /^data:image\/([\w.+-]+)/.exec(source)?.[1].replace(/\+xml$/, "").toUpperCase() ||+ extension.substring(1).toUpperCase();+ // 原始尺寸不受编辑器缩放和图片排版宽度影响。+ const dimensions = image.naturalWidth && image.naturalHeight ? `${image.naturalWidth} × ${image.naturalHeight}` : "";+ const information = [format, dimensions, size].filter(Boolean).map(value => escapeHtml(value)).join(" · ");+ return text + (text && information ? '<div class="fn__hr"></div>' : "") + information;};