An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improve database relation value previews https://github.com/siyuan-note/siyuan/issues/13645
Daniel766ddc410429
diff --git a/app/src/block/popover.ts b/app/src/block/popover.tsindex ea43a8c3b7..afbe5b1bb0 100644--- a/app/src/block/popover.ts+++ b/app/src/block/popover.ts@@ -76,6 +76,7 @@ export const initBlockPopover = (app: App) => {hasClosestByAttribute(event.target, "data-type", "tab-header") ||hasClosestByAttribute(event.target, "data-type", "inline-memo") ||hasClosestByClassName(event.target, "av__calc--ashow") ||+ hasClosestByClassName(event.target, "av__relation-table-cell") ||hasClosestByClassName(event.target, "av__cell");if (aElement) {const aElementParent = aElement.parentElement;@@ -126,10 +127,15 @@ export const initBlockPopover = (app: App) => {tooltipClass = "href";} else if (aElement.classList.contains("av__calc--ashow") && aElement.clientWidth + 2 < aElement.scrollWidth) {tip = aElement.lastChild.textContent + " " + aElement.firstElementChild.textContent;- } else if (aElement.getAttribute("data-type") === "setRelationCell") {- const childElement = aElement.querySelector(".b3-menu__label");- if (childElement && childElement.clientWidth < childElement.scrollWidth) {- tip = childElement.textContent;+ } else if (aElement.classList.contains("av__relation-table-cell") ||+ aElement.getAttribute("data-type") === "setRelationCell") {+ const cellElement = aElement.classList.contains("av__relation-table-cell") ? aElement :+ hasClosestByClassName(event.target, "av__relation-table-cell") || null;+ const textElement = cellElement?.querySelector(".b3-menu__label, .av__celltext") as HTMLElement;+ if (cellElement && hasClosestByAttribute(cellElement, "data-type", "setRelationCell", true) &&+ (cellElement.clientWidth + 0.5 < cellElement.scrollWidth ||+ (textElement && textElement.clientWidth + 0.5 < textElement.scrollWidth))) {+ tip = Lute.EscapeHTMLStr(getCellText(cellElement));}} else if (aElement.classList.contains("protyle-attr--memo")) {tip = escapeHtml(tip);diff --git a/app/src/protyle/render/av/columnWidth.test.ts b/app/src/protyle/render/av/columnWidth.test.tsindex 0501e42294..bc34c23262 100644--- a/app/src/protyle/render/av/columnWidth.test.ts+++ b/app/src/protyle/render/av/columnWidth.test.ts@@ -2,6 +2,7 @@ import {describe, it} from "node:test";import * as assert from "node:assert/strict";import {getAVColumnFitWidth,+ getAVRelationColumnWidth,getAVColumnResizeWidth,getAVDistributedColumnWidth,getAVTableFitWidths,@@ -24,6 +25,16 @@ describe("getAVColumnFitWidth", () => {});});+describe("getAVRelationColumnWidth", () => {+ it("keeps relation previews compact", () => {+ assert.equal(getAVRelationColumnWidth("64px", "block", true), "120px");+ assert.equal(getAVRelationColumnWidth("480px", "block", true), "160px");+ assert.equal(getAVRelationColumnWidth("480px", "text", false), "160px");+ assert.equal(getAVRelationColumnWidth("480px", "relation", false), "200px");+ assert.equal(getAVRelationColumnWidth("120px", "date", false), "120px");+ });+});+describe("getAVTableFitWidths", () => {it("uses visible groups, field IDs and total line counts", () => {const columns = [diff --git a/app/src/protyle/render/av/columnWidth.ts b/app/src/protyle/render/av/columnWidth.tsindex e6eb433819..b2ffa634bc 100644--- a/app/src/protyle/render/av/columnWidth.ts+++ b/app/src/protyle/render/av/columnWidth.ts@@ -33,6 +33,13 @@ export const getAVColumnFitWidth = (name: string, type: TAVCol, values: string[]return `${Math.ceil(Math.min(480, Math.max(64, headerWidth, contentWidth)))}px`;};+export const getAVRelationColumnWidth = (fitWidth: string, type: TAVCol, primary: boolean) => {+ const width = parseFloat(fitWidth) || 64;+ const minWidth = primary ? 120 : 64;+ const maxWidth = ["relation", "rollup", "mAsset"].includes(type) ? 200 : 160;+ return `${Math.min(maxWidth, Math.max(minWidth, width))}px`;+};+export const getAVColumnResizeWidth = (width: number, previousWidth?: number, snapThreshold = 4) => {const limitedWidth = Math.max(Math.round(width), 25);const normalizedPreviousWidth = typeof previousWidth === "number" ? Math.round(previousWidth) : undefined;diff --git a/app/src/protyle/render/av/relation.ts b/app/src/protyle/render/av/relation.tsindex 6f464dd0b2..76a1dd91c3 100644--- a/app/src/protyle/render/av/relation.ts+++ b/app/src/protyle/render/av/relation.ts@@ -17,7 +17,7 @@ import {showMessage} from "../../../dialog/message";import {writeText} from "../../util/compatibility";import {Constants} from "../../../constants";import {openDatabaseRowByData} from "./openDatabaseRow";-import {getAVColumnTextMeasurer, getAVTableFitWidths} from "./columnWidth";+import {getAVColumnTextMeasurer, getAVRelationColumnWidth, getAVTableFitWidths} from "./columnWidth";import {getSearchAVFocus} from "./searchAVFocus";interface IAVItem {@@ -387,7 +387,7 @@ const getRelationGridTemplate = (columns: IAVColumn[], rows: IAVRow[],} as IAVTable, getCellValueText, measureText);return `32px ${columns.map((column, index) => {const width = widths[column.id] || "64px";- return index === 0 ? `${Math.max(240, parseFloat(width))}px` : width;+ return getAVRelationColumnWidth(width, column.type, index === 0);}).join(" ")}`;};