Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:sparkles: Improve relation selection field visibility and column widths https://github.com/siyuan-note/siyuan/issues/19904

Danield9acc8272a3a
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20240208172514-9dsv6na.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20240208172514-9dsv6na.sy
index ba8c22f43c..5801bed0f5 100644
--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20240208172514-9dsv6na.sy
+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20240208172514-9dsv6na.sy
@@ -7,7 +7,7 @@
"id": "20240208172514-9dsv6na",
"title": "Database",
"type": "doc",
- "updated": "20260927123058"
+ "updated": "20260927185714"
},
"Children": [
{
@@ -2883,7 +2883,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20240208172555-hv2afdr",
- "updated": "20250615172312"
+ "updated": "20260927185714"
},
"Children": [
{
@@ -3004,6 +3004,20 @@
}
]
},
+ {
+ "ID": "20260927185714-cye5231",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20260927185714-cye5231",
+ "updated": "20260927185714"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "In the relation selection panel, use the Fields button to hide unnecessary fields and set column widths in pixels. The primary key always remains visible. You can also drag column boundaries in the header to resize them. These display preferences are remembered for each related database and do not change its views or stored values."
+ }
+ ]
+ },
{
"ID": "20240208173416-t51ome2",
"Type": "NodeHeading",
diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20240208113259-nykkvaq.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20240208113259-nykkvaq.sy
index 61509b5c48..817d8d197b 100644
--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20240208113259-nykkvaq.sy
+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20240208113259-nykkvaq.sy
@@ -7,7 +7,7 @@
"id": "20240208113259-nykkvaq",
"title": "数据库",
"type": "doc",
- "updated": "20260927123058"
+ "updated": "20260927185714"
},
"Children": [
{
@@ -2883,7 +2883,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20240208120825-ktzju1z",
- "updated": "20250615173511"
+ "updated": "20260927185714"
},
"Children": [
{
@@ -3004,6 +3004,20 @@
}
]
},
+ {
+ "ID": "20260927185714-ufwobnu",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20260927185714-ufwobnu",
+ "updated": "20260927185714"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "在关联选择面板中,点击字段按钮可隐藏不需要的字段,并输入列宽(像素)。主键始终显示,也可以拖动表头的列边界调整宽度。这些显示偏好按关联数据库保存,不会改变数据库的视图或已存储的字段值。"
+ }
+ ]
+ },
{
"ID": "20240208120846-72y7j0d",
"Type": "NodeHeading",
diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20240208171522-y7dxcno.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20240208171522-y7dxcno.sy
index b9e8144905..321e95d1bb 100644
--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20240208171522-y7dxcno.sy
+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20240208171522-y7dxcno.sy
@@ -7,7 +7,7 @@
"id": "20240208171522-y7dxcno",
"title": "資料庫",
"type": "doc",
- "updated": "20260927123058"
+ "updated": "20260927185714"
},
"Children": [
{
@@ -2883,7 +2883,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20240208171620-5ek5rxs",
- "updated": "20250615173721"
+ "updated": "20260927185714"
},
"Children": [
{
@@ -3004,6 +3004,20 @@
}
]
},
+ {
+ "ID": "20260927185714-02x2w1t",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20260927185714-02x2w1t",
+ "updated": "20260927185714"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "在關聯選擇面板中,點擊欄位按鈕可隱藏不需要的欄位,並輸入欄寬(像素)。主鍵一律顯示,也可以拖曳表頭的欄位邊界調整寬度。這些顯示偏好依關聯資料庫儲存,不會變更資料庫的檢視或已儲存的欄位值。"
+ }
+ ]
+ },
{
"ID": "20240208172038-fewwv8i",
"Type": "NodeHeading",
diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-3eaevtp.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-3eaevtp.sy
index 0df4d6c11e..d66f967fba 100644
--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-3eaevtp.sy
+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-3eaevtp.sy
@@ -8,7 +8,7 @@
"id": "20240530101000-3eaevtp",
"title": "データベース",
"type": "doc",
- "updated": "20260927123058"
+ "updated": "20260927185714"
},
"Children": [
{
@@ -2887,7 +2887,7 @@
"Properties": {
"ID": "20240530101000-x6r9yyj",
"id": "20240530101000-jgap8im",
- "updated": "20250615173941"
+ "updated": "20260927185714"
},
"Children": [
{
@@ -3011,6 +3011,20 @@
}
]
},
+ {
+ "ID": "20260927185714-ltaooa0",
+ "Type": "NodeParagraph",
+ "Properties": {
+ "id": "20260927185714-ltaooa0",
+ "updated": "20260927185714"
+ },
+ "Children": [
+ {
+ "Type": "NodeText",
+ "Data": "リレーション選択パネルのフィールドボタンで、不要なフィールドを非表示にしたり、列幅をピクセル単位で指定したりできます。主キーは常に表示されます。ヘッダーの列境界をドラッグして幅を調整することもできます。表示設定は関連先のデータベースごとに保存され、データベースのビューや保存済みの値には影響しません。"
+ }
+ ]
+ },
{
"ID": "20240530101000-yinvvxy",
"Type": "NodeHeading",
diff --git a/app/src/assets/scss/business/_av.scss b/app/src/assets/scss/business/_av.scss
index f3dd20184c..810af0968b 100644
--- a/app/src/assets/scss/business/_av.scss
+++ b/app/src/assets/scss/business/_av.scss
@@ -2563,6 +2563,28 @@ img.av__cellassetimg {
min-width: 0;
}
+ .av__relation-fields {
+ max-height: 180px;
+ overflow: auto;
+ padding: 8px;
+ }
+
+ .av__relation-field {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ margin-bottom: 8px;
+
+ label {
+ min-width: 0;
+ align-items: center;
+ }
+
+ .b3-text-field {
+ width: 80px;
+ }
+ }
+
.av__relation-table {
border-radius: 0 0 var(--b3-border-radius-b) var(--b3-border-radius-b);
overflow: auto;
@@ -2588,6 +2610,15 @@ img.av__cellassetimg {
.av__relation-table-cell {
font-weight: 600;
+ position: relative;
+
+ &.av__relation-table-primary {
+ position: sticky;
+ }
+
+ .av__widthdrag {
+ right: 0;
+ }
> svg {
height: 14px;
diff --git a/app/src/protyle/render/av/columnWidth.test.ts b/app/src/protyle/render/av/columnWidth.test.ts
index bc34c23262..1b69c198f9 100644
--- a/app/src/protyle/render/av/columnWidth.test.ts
+++ b/app/src/protyle/render/av/columnWidth.test.ts
@@ -27,8 +27,8 @@ 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("64px", "block", true), "240px");
+ assert.equal(getAVRelationColumnWidth("480px", "block", true), "400px");
assert.equal(getAVRelationColumnWidth("480px", "text", false), "160px");
assert.equal(getAVRelationColumnWidth("480px", "relation", false), "200px");
assert.equal(getAVRelationColumnWidth("120px", "date", false), "120px");
diff --git a/app/src/protyle/render/av/columnWidth.ts b/app/src/protyle/render/av/columnWidth.ts
index b2ffa634bc..691b7c4c4b 100644
--- a/app/src/protyle/render/av/columnWidth.ts
+++ b/app/src/protyle/render/av/columnWidth.ts
@@ -35,8 +35,8 @@ export const getAVColumnFitWidth = (name: string, type: TAVCol, values: string[]
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;
+ const minWidth = primary ? 240 : 64;
+ const maxWidth = primary ? 400 : ["relation", "rollup", "mAsset"].includes(type) ? 200 : 160;
return `${Math.min(maxWidth, Math.max(minWidth, width))}px`;
};
diff --git a/app/src/protyle/render/av/relation.ts b/app/src/protyle/render/av/relation.ts
index 3b48cae150..f690cfe725 100644
--- a/app/src/protyle/render/av/relation.ts
+++ b/app/src/protyle/render/av/relation.ts
@@ -24,6 +24,7 @@ import {getAVTemplateHTML} from "./attributeValue";
import {hasAVRenderTemplateResult} from "./cellValue";
import {renderAVRichTextElements} from "./richText";
import {getFileTreeIconHTML} from "../../../emoji/fileTreeIcon";
+import {bindRelationLayout} from "./relationLayout";
interface IAVItem {
avID: string;
@@ -417,9 +418,10 @@ const genRelationHeaderHTML = (columns: IAVColumn[], gridTemplate: string) => {
let html = `<div class="av__relation-table-header" data-relation-type="header" style="grid-template-columns:${gridTemplate}">
<span class="av__relation-table-check"></span>`;
columns.forEach((column, index) => {
- html += `<span class="av__relation-table-cell${index === 0 ? " av__relation-table-primary" : ""}">
+ html += `<span data-relation-column="${escapeAttr(column.id)}" class="av__relation-table-cell${index === 0 ? " av__relation-table-primary" : ""}">
<svg><use xlink:href="#${getColIconByType(column.type)}"></use></svg>
<span class="fn__ellipsis">${escapeHtml(column.name)}</span>
+ <span class="av__widthdrag"></span>
</span>`;
});
return html + "</div>";
@@ -443,7 +445,7 @@ style="grid-template-columns:${gridTemplate}">
const useRenderedContent = hasAVRenderTemplateResult(primaryValue, column.renderTemplate);
const content = useRenderedContent ? getAVTemplateHTML(primaryValue.renderedContent || "") :
Lute.EscapeHTMLStr(primaryValue.block?.content || window.siyuan.languages.untitled);
- html += `<span class="av__relation-table-cell av__relation-table-primary" data-row-id="${escapeAttr(row.id)}"
+ html += `<span data-relation-column="${escapeAttr(column.id)}" class="av__relation-table-cell av__relation-table-primary" data-row-id="${escapeAttr(row.id)}"
data-value-id="${escapeAttr(primaryCell.id || "")}"
style="${primaryCell.bgColor ? `background-color:${primaryCell.bgColor};` : ""}${primaryCell.color ? `color:${primaryCell.color};` : ""}">
${selected ? '<svg class="b3-menu__icon fn__grab"><use xlink:href="#iconDrag"></use></svg>' : ""}
@@ -456,7 +458,7 @@ style="${primaryCell.bgColor ? `background-color:${primaryCell.bgColor};` : ""}$
data-position="north" aria-label="${window.siyuan.languages.openBy}"><svg><use xlink:href="#iconOpen"></use></svg></button>` : ""}
</span>`;
} else {
- html += `<div class="av__relation-table-cell"
+ html += `<div data-relation-column="${escapeAttr(column.id)}" class="av__relation-table-cell"
style="${cell?.bgColor ? `background-color:${cell.bgColor};` : ""}${cell?.color ? `color:${cell.color};` : ""}">${cell?.value ?
renderCell(cell.value, 0, false, "table", column.options, column.dateFormat, column.renderTemplate) : ""}</div>`;
}
@@ -644,6 +646,7 @@ export const bindRelationEvent = (options: {
listElement.querySelector('[data-relation-type="loader"]').insertAdjacentHTML("beforebegin", footerHTML);
}
};
+ const updateLayout = bindRelationLayout(relationElement, relationElement.dataset.avId, resize);
const renderPage = (data: {
columns: IAVColumn[],
selectedRows: IAVRow[],
@@ -676,6 +679,7 @@ ${genRelationLoaderHTML(state.loading, state.loaderVisible)}`;
}
}
renderAVRichTextElements(listElement);
+ updateLayout(state.columns, gridTemplate);
renderFooter(!!listElement.querySelector('[data-relation-type="candidate"]'));
if (!listElement.querySelector(".b3-menu__item--current")) {
listElement.querySelector('[data-type="setRelationCell"]')?.classList.add("b3-menu__item--current");
@@ -888,6 +892,7 @@ export const getRelationHTML = (data: IAV, cellElements?: HTMLElement[]) => {
});
if (colRelationData && colRelationData.avID) {
return `<div data-av-id="${colRelationData.avID}" data-source-av-id="${data.id}" data-key-id="${colId}" class="fn__flex-column av__relation">
+<div>
<div class="b3-menu__item" data-type="nobg">
<div class="b3-form__icona fn__flex-1" style="overflow: visible">
<input spellcheck="false" class="b3-text-field fn__block" style="min-width: 190px"/>
@@ -895,6 +900,10 @@ export const getRelationHTML = (data: IAV, cellElements?: HTMLElement[]) => {
</div>
<span class="fn__space"></span>
<span style="color: var(--b3-protyle-inline-blockref-color);max-width: 200px" data-id="" class="popover__block fn__pointer fn__ellipsis"></span>
+ <span class="fn__space"></span>
+ <button type="button" class="block__icon" data-type="relationFields" aria-expanded="false" aria-label="${window.siyuan.languages.fields}"><svg><use xlink:href="#iconSettings"></use></svg></button>
+</div>
+<div class="av__relation-fields fn__none"></div>
</div>
<div class="b3-menu__items av__relation-table">
${genRelationLoaderHTML(true, false)}
@@ -924,13 +933,13 @@ const getRelationValue = (menuElement: HTMLElement) => {
const genCreatedRelationRowHTML = (menuElement: HTMLElement, rowID: string, content: string) => {
const headerElement = menuElement.querySelector('[data-relation-type="header"]') as HTMLElement;
- const columnCount = headerElement?.querySelectorAll(".av__relation-table-cell").length || 1;
- let cellsHTML = `<span class="av__relation-table-cell av__relation-table-primary" data-row-id="${rowID}">
+ const columns = headerElement?.querySelectorAll<HTMLElement>(".av__relation-table-cell");
+ let cellsHTML = `<span data-relation-column="${escapeAttr(columns?.[0]?.dataset.relationColumn || "")}" class="av__relation-table-cell av__relation-table-primary" data-row-id="${rowID}">
<svg class="b3-menu__icon fn__grab"><use xlink:href="#iconDrag"></use></svg>
<span class="b3-menu__label fn__ellipsis" data-id="">${Lute.EscapeHTMLStr(content)}</span>
</span>`;
- for (let i = 1; i < columnCount; i++) {
- cellsHTML += '<span class="av__relation-table-cell"></span>';
+ for (let i = 1; i < (columns?.length || 1); i++) {
+ cellsHTML += `<span data-relation-column="${escapeAttr(columns[i].dataset.relationColumn)}" class="av__relation-table-cell${columns[i].classList.contains("fn__none") ? " fn__none" : ""}"></span>`;
}
return `<div data-row-id="${rowID}" data-position="west" data-type="setRelationCell"
data-relation-type="selected" class="b3-menu__item av__relation-table-row" draggable="true"
diff --git a/app/src/protyle/render/av/relationLayout.ts b/app/src/protyle/render/av/relationLayout.ts
new file mode 100644
index 0000000000..401deb33a3
--- /dev/null
+++ b/app/src/protyle/render/av/relationLayout.ts
@@ -0,0 +1,113 @@
+import {escapeAttr, escapeHtml} from "../../../util/escape";
+import {setStorageVal} from "../../util/compatibility";
+
+const STORAGE_KEY = "local-av-relation-layout";
+
+interface IRelationLayout {
+ hidden: string[];
+ widths: Record<string, number>;
+}
+
+export const bindRelationLayout = (root: HTMLElement, databaseID: string, onResize: () => void) => {
+ const saved = window.siyuan.storage[STORAGE_KEY]?.[databaseID] as IRelationLayout | undefined;
+ const layout: IRelationLayout = {hidden: [...(saved?.hidden || [])], widths: {...saved?.widths}};
+ const fields = root.querySelector<HTMLElement>(".av__relation-fields");
+ const button = root.querySelector<HTMLButtonElement>('[data-type="relationFields"]');
+ let columns: IAVColumn[] = [];
+ let defaultWidths: string[] = [];
+ const widthOf = (index: number) => {
+ const width = layout.widths[columns[index].id];
+ return Number.isFinite(width) ? `${Math.max(64, Math.min(800, width))}px` : defaultWidths[index];
+ };
+ const apply = () => {
+ const template = ["32px", ...columns.map((column, index) =>
+ index > 0 && layout.hidden.includes(column.id) ? "" : index === 0 ?
+ `min(${widthOf(index)}, calc(100vw - 96px))` : widthOf(index)).filter(Boolean)].join(" ");
+ root.querySelectorAll<HTMLElement>(".av__relation-table-header, .av__relation-table-row").forEach(row => {
+ row.style.gridTemplateColumns = template;
+ row.querySelectorAll<HTMLElement>("[data-relation-column]").forEach(cell => {
+ cell.classList.toggle("fn__none", cell.dataset.relationColumn !== columns[0]?.id &&
+ layout.hidden.includes(cell.dataset.relationColumn));
+ });
+ });
+ };
+ const save = () => {
+ const value = {...window.siyuan.storage[STORAGE_KEY], [databaseID]: layout};
+ window.siyuan.storage[STORAGE_KEY] = value;
+ setStorageVal(STORAGE_KEY, value);
+ };
+ const renderFields = () => {
+ fields.innerHTML = columns.map((column, index) => `<div class="av__relation-field">
+<label class="fn__flex fn__flex-1"><input type="checkbox" class="b3-switch" data-column="${escapeAttr(column.id)}"
+${index === 0 ? "checked disabled" : layout.hidden.includes(column.id) ? "" : "checked"}>
+<span class="fn__space"></span><span class="fn__ellipsis">${escapeHtml(column.name)}</span></label>
+<input type="number" class="b3-text-field" min="64" max="800" step="1" value="${parseFloat(widthOf(index))}"
+data-width="${escapeAttr(column.id)}" aria-label="${escapeAttr(column.name + " " + window.siyuan.languages.width)}">
+</div>`).join("");
+ };
+ button.addEventListener("click", event => {
+ event.stopPropagation();
+ fields.classList.toggle("fn__none");
+ button.setAttribute("aria-expanded", String(!fields.classList.contains("fn__none")));
+ renderFields();
+ onResize();
+ });
+ fields.addEventListener("click", event => event.stopPropagation());
+ fields.addEventListener("keydown", event => event.stopPropagation());
+ fields.addEventListener("change", event => {
+ event.stopPropagation();
+ const input = event.target as HTMLInputElement;
+ if (input.dataset.column) {
+ layout.hidden = layout.hidden.filter(id => id !== input.dataset.column);
+ if (!input.checked) {
+ layout.hidden.push(input.dataset.column);
+ }
+ } else if (input.dataset.width) {
+ if (!Number.isFinite(input.valueAsNumber)) {
+ renderFields();
+ return;
+ }
+ layout.widths[input.dataset.width] = Math.max(64, Math.min(800, Math.round(input.valueAsNumber)));
+ input.value = String(layout.widths[input.dataset.width]);
+ }
+ apply();
+ save();
+ onResize();
+ });
+ root.addEventListener("pointerdown", event => {
+ const handle = (event.target as HTMLElement).closest<HTMLElement>(".av__widthdrag");
+ if (!handle || event.button !== 0) {
+ return;
+ }
+ event.preventDefault();
+ event.stopPropagation();
+ const cell = handle.parentElement;
+ const id = cell.dataset.relationColumn;
+ const initialWidth = cell.getBoundingClientRect().width;
+ const initialX = event.clientX;
+ handle.setPointerCapture(event.pointerId);
+ handle.classList.add("av__widthdrag--active");
+ const move = (moveEvent: PointerEvent) => {
+ layout.widths[id] = Math.max(64, Math.min(800, Math.round(initialWidth + moveEvent.clientX - initialX)));
+ apply();
+ };
+ const finish = () => {
+ handle.removeEventListener("pointermove", move);
+ handle.removeEventListener("lostpointercapture", finish);
+ handle.classList.remove("av__widthdrag--active");
+ renderFields();
+ save();
+ onResize();
+ };
+ handle.addEventListener("pointermove", move);
+ handle.addEventListener("lostpointercapture", finish);
+ });
+ return (nextColumns: IAVColumn[], gridTemplate: string) => {
+ columns = nextColumns;
+ defaultWidths = gridTemplate.split(" ").slice(1);
+ apply();
+ if (!fields.classList.contains("fn__none")) {
+ renderFields();
+ }
+ };
+};
diff --git a/app/tests/avRelationTemplate.test.js b/app/tests/avRelationTemplate.test.js
index 728e2d1927..05c777ce02 100644
--- a/app/tests/avRelationTemplate.test.js
+++ b/app/tests/avRelationTemplate.test.js
@@ -15,6 +15,7 @@ const runCases = sources => {
return content;
}};
const dependencies = {
+ "../../util/compatibility": {setStorageVal: () => {}},
"../../../util/escape": {escapeAttr: escape, escapeHtml: escape},
"../../../emoji/fileTreeIcon": {getFileTreeIconHTML: () => ""},
"../../../util/hostCapabilities": {getHostCapabilities: () => ({remoteKernel: true})},
@@ -65,6 +66,35 @@ const runCases = sources => {
}
assert.ok(sanitized.includes(""));
assert.ok(sanitized.some(content => content.includes("<b>Formatted</b>")));
+ window.siyuan.storage = {};
+ const {bindRelationLayout} = load("./relationLayout");
+ const root = document.createElement("div");
+ root.innerHTML = '<button data-type="relationFields"></button><div class="av__relation-fields fn__none"></div>' +
+ '<div class="av__relation-table-header"><span data-relation-column="primary"></span><span data-relation-column="other"></span></div>' +
+ '<div class="av__relation-table-row"><span data-relation-column="primary">Entry</span><span data-relation-column="other">Value</span></div>';
+ const columns = [{id: "primary", name: "Title"}, {id: "other", name: "Other"}];
+ const update = bindRelationLayout(root, "database", () => {});
+ update(columns, "32px 240px 160px");
+ root.querySelector("button").click();
+ assert.equal(root.querySelector('[data-column="primary"]').disabled, true);
+ const other = root.querySelector('[data-column="other"]');
+ other.checked = false;
+ other.dispatchEvent(new Event("change", {bubbles: true}));
+ assert.equal(root.querySelectorAll('[data-relation-column="other"].fn__none').length, 2);
+ const width = root.querySelector('[data-width="primary"]');
+ width.value = "360";
+ width.dispatchEvent(new Event("change", {bubbles: true}));
+ assert.equal(window.siyuan.storage["local-av-relation-layout"].database.widths.primary, 360);
+ assert.deepEqual(window.siyuan.storage["local-av-relation-layout"].database.hidden, ["other"]);
+ update(columns, "32px 240px 160px");
+ assert.match(root.querySelector(".av__relation-table-row").style.gridTemplateColumns, /360px/);
+ const reopened = root.cloneNode(true);
+ bindRelationLayout(reopened, "database", () => {})(columns, "32px 240px 160px");
+ assert.equal(reopened.querySelectorAll('[data-relation-column="other"].fn__none').length, 2);
+ assert.match(reopened.querySelector(".av__relation-table-row").style.gridTemplateColumns, /360px/);
+ const independent = root.cloneNode(true);
+ bindRelationLayout(independent, "another", () => {})(columns, "32px 240px 160px");
+ assert.equal(independent.querySelectorAll('[data-relation-column="other"].fn__none').length, 0);
};
const runElectron = async () => {
@@ -76,7 +106,7 @@ const runElectron = async () => {
let exitCode = 0;
try {
const ts = require("typescript");
- const sources = Object.fromEntries(["cell", "cellValue", "attributeValue"].map(name => ["./" + name,
+ const sources = Object.fromEntries(["cell", "cellValue", "attributeValue", "relationLayout"].map(name => ["./" + name,
ts.transpileModule(readFileSync(path.join(__dirname, `../src/protyle/render/av/${name}.ts`), "utf8"),
{compilerOptions: {module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020}}).outputText]));
await win.loadURL("data:text/html,<html><body></body></html>");