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: Support auto-fitting all database column widths https://github.com/siyuan-note/siyuan/issues/12952
Danielbe3c4b5f1e83
diff --git a/app/appearance/langs/ar.json b/app/appearance/langs/ar.jsonindex 1ad0eab553..0c14e224a4 100644--- a/app/appearance/langs/ar.json+++ b/app/appearance/langs/ar.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "ضبط عرض جميع الأعمدة تلقائيًا","searchPlaceholder": "بحث...","visibleViews": "طرق العرض الظاهرة","hiddenViews": "طرق العرض المخفية",diff --git a/app/appearance/langs/de.json b/app/appearance/langs/de.jsonindex 27168f4fb0..fe34b0b844 100644--- a/app/appearance/langs/de.json+++ b/app/appearance/langs/de.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "Alle Spaltenbreiten automatisch anpassen","searchPlaceholder": "Suchen...","visibleViews": "Sichtbare Ansichten","hiddenViews": "Ausgeblendete Ansichten",diff --git a/app/appearance/langs/en.json b/app/appearance/langs/en.jsonindex 0c55d141af..4e7991da48 100644--- a/app/appearance/langs/en.json+++ b/app/appearance/langs/en.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "Auto-fit all column widths","searchPlaceholder": "Search...","visibleViews": "Visible views","hiddenViews": "Hidden views",diff --git a/app/appearance/langs/es.json b/app/appearance/langs/es.jsonindex 2c4f29f576..fd65bfe388 100644--- a/app/appearance/langs/es.json+++ b/app/appearance/langs/es.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "Ajustar automáticamente el ancho de todas las columnas","searchPlaceholder": "Buscar...","visibleViews": "Vistas visibles","hiddenViews": "Vistas ocultas",diff --git a/app/appearance/langs/fr.json b/app/appearance/langs/fr.jsonindex 6b102e3cba..1c8d385d1c 100644--- a/app/appearance/langs/fr.json+++ b/app/appearance/langs/fr.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "Ajuster automatiquement la largeur de toutes les colonnes","searchPlaceholder": "Recherche...","visibleViews": "Vues visibles","hiddenViews": "Vues masquées",diff --git a/app/appearance/langs/he.json b/app/appearance/langs/he.jsonindex b3d106de6c..fcf657fe60 100644--- a/app/appearance/langs/he.json+++ b/app/appearance/langs/he.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "התאם אוטומטית את רוחב כל העמודות","searchPlaceholder": "חפש...","visibleViews": "תצוגות גלויות","hiddenViews": "תצוגות מוסתרות",diff --git a/app/appearance/langs/hi.json b/app/appearance/langs/hi.jsonindex ee799399d0..62dab5e040 100644--- a/app/appearance/langs/hi.json+++ b/app/appearance/langs/hi.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "सभी स्तंभों की चौड़ाई अपने आप समायोजित करें","searchPlaceholder": "खोजें...","visibleViews": "दिखाई देने वाले दृश्य","hiddenViews": "छिपे हुए दृश्य",diff --git a/app/appearance/langs/id.json b/app/appearance/langs/id.jsonindex dd16b77795..30712ad7d9 100644--- a/app/appearance/langs/id.json+++ b/app/appearance/langs/id.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "Sesuaikan semua lebar kolom secara otomatis","searchPlaceholder": "Cari...","visibleViews": "Tampilan terlihat","hiddenViews": "Tampilan tersembunyi",diff --git a/app/appearance/langs/it.json b/app/appearance/langs/it.jsonindex 553dc75566..a0663b25e2 100644--- a/app/appearance/langs/it.json+++ b/app/appearance/langs/it.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "Adatta automaticamente la larghezza di tutte le colonne","searchPlaceholder": "Cerca...","visibleViews": "Viste visibili","hiddenViews": "Viste nascoste",diff --git a/app/appearance/langs/ja.json b/app/appearance/langs/ja.jsonindex 8dc0573412..31e073ba8e 100644--- a/app/appearance/langs/ja.json+++ b/app/appearance/langs/ja.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "すべての列幅を自動調整","searchPlaceholder": "検索...","visibleViews": "表示中のビュー","hiddenViews": "非表示のビュー",diff --git a/app/appearance/langs/ko.json b/app/appearance/langs/ko.jsonindex def5fcb944..b263418273 100644--- a/app/appearance/langs/ko.json+++ b/app/appearance/langs/ko.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "모든 열 너비 자동 맞춤","searchPlaceholder": "검색...","visibleViews": "표시된 뷰","hiddenViews": "숨겨진 뷰",diff --git a/app/appearance/langs/nl.json b/app/appearance/langs/nl.jsonindex 377f61ee1b..aa0f7b7431 100644--- a/app/appearance/langs/nl.json+++ b/app/appearance/langs/nl.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "Alle kolombreedtes automatisch aanpassen","searchPlaceholder": "Zoeken...","visibleViews": "Zichtbare weergaven","hiddenViews": "Verborgen weergaven",diff --git a/app/appearance/langs/pl.json b/app/appearance/langs/pl.jsonindex 8fc58c449b..26c2b2e47c 100644--- a/app/appearance/langs/pl.json+++ b/app/appearance/langs/pl.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "Automatycznie dopasuj szerokość wszystkich kolumn","searchPlaceholder": "Szukaj...","visibleViews": "Widoczne widoki","hiddenViews": "Ukryte widoki",diff --git a/app/appearance/langs/pt-BR.json b/app/appearance/langs/pt-BR.jsonindex 2ba17cc6bb..1974dd692d 100644--- a/app/appearance/langs/pt-BR.json+++ b/app/appearance/langs/pt-BR.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "Ajustar automaticamente a largura de todas as colunas","searchPlaceholder": "Pesquisar...","visibleViews": "Visualizações visíveis","hiddenViews": "Visualizações ocultas",diff --git a/app/appearance/langs/ru.json b/app/appearance/langs/ru.jsonindex ab9845143c..3f1ef10f5b 100644--- a/app/appearance/langs/ru.json+++ b/app/appearance/langs/ru.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "Автоматически подобрать ширину всех столбцов","searchPlaceholder": "Поиск...","visibleViews": "Отображаемые виды","hiddenViews": "Скрытые виды",diff --git a/app/appearance/langs/sk.json b/app/appearance/langs/sk.jsonindex 8336d1aff6..1edc9da88f 100644--- a/app/appearance/langs/sk.json+++ b/app/appearance/langs/sk.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "Automaticky prispôsobiť šírku všetkých stĺpcov","searchPlaceholder": "Vyhľadávanie...","visibleViews": "Viditeľné zobrazenia","hiddenViews": "Skryté zobrazenia",diff --git a/app/appearance/langs/th.json b/app/appearance/langs/th.jsonindex 676655ca3b..515d11ee0b 100644--- a/app/appearance/langs/th.json+++ b/app/appearance/langs/th.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "ปรับความกว้างของคอลัมน์ทั้งหมดโดยอัตโนมัติ","searchPlaceholder": "ค้นหา...","visibleViews": "มุมมองที่มองเห็น","hiddenViews": "มุมมองที่ซ่อนอยู่",diff --git a/app/appearance/langs/tr.json b/app/appearance/langs/tr.jsonindex bcd66559da..2fb8158f16 100644--- a/app/appearance/langs/tr.json+++ b/app/appearance/langs/tr.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "Tüm sütun genişliklerini otomatik ayarla","searchPlaceholder": "Ara...","visibleViews": "Görünür görünümler","hiddenViews": "Gizli görünümler",diff --git a/app/appearance/langs/uk.json b/app/appearance/langs/uk.jsonindex b9ebf207d4..1d65ddfdf0 100644--- a/app/appearance/langs/uk.json+++ b/app/appearance/langs/uk.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "Автоматично підібрати ширину всіх стовпців","searchPlaceholder": "Пошук...","visibleViews": "Видимі подання","hiddenViews": "Приховані подання",diff --git a/app/appearance/langs/zh-CN.json b/app/appearance/langs/zh-CN.jsonindex 75d688ca82..4dbc70be03 100644--- a/app/appearance/langs/zh-CN.json+++ b/app/appearance/langs/zh-CN.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "自动调整所有列宽","searchPlaceholder": "搜索...","visibleViews": "显示视图","hiddenViews": "隐藏视图",diff --git a/app/appearance/langs/zh-TW.json b/app/appearance/langs/zh-TW.jsonindex ffd48f5354..07fcc2036e 100644--- a/app/appearance/langs/zh-TW.json+++ b/app/appearance/langs/zh-TW.json@@ -1,4 +1,5 @@{+ "autoFitAllColWidths": "自動調整所有列寬","searchPlaceholder": "搜索...","visibleViews": "顯示視圖","hiddenViews": "隱藏視圖",diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.tsindex 75e9e8e8cf..80a5e91f9e 100644--- a/app/src/protyle/render/av/cell.ts+++ b/app/src/protyle/render/av/cell.ts@@ -1194,7 +1194,7 @@ export const renderCell = (cellValue: IAVCellValue, rowIndex = 0, showIcon = trureturn text;};-const getCellValueText = (value: IAVCellValue, column?: IAVColumn, rowIndex = 0) => {+export const getCellValueText = (value: IAVCellValue, column?: IAVColumn, rowIndex = 0) => {const cellElement = document.createElement("div");cellElement.innerHTML = renderCell(value, rowIndex, true, "table", column?.options, column?.dateFormat);return getCellText(cellElement);diff --git a/app/src/protyle/render/av/col.ts b/app/src/protyle/render/av/col.tsindex d4bc9fcb00..4d46ad7f7c 100644--- a/app/src/protyle/render/av/col.ts+++ b/app/src/protyle/render/av/col.ts@@ -2,7 +2,7 @@ import {Menu} from "../../../plugin/Menu";import {transaction} from "../../wysiwyg/transaction";import {fetchPost, fetchSyncPost} from "../../../util/fetch";import {getDefaultOperatorByType, getEditableFilters, hasFilterForColumn} from "./filter";-import {genCellValue, renderCell} from "./cell";+import {genCellValue, getCellValueText, renderCell} from "./cell";import {getPropertiesHTML, openMenuPanel} from "./openMenuPanel";import {getLabelByNumberFormat} from "./number";import {getDefaultDateFormat, getLabelByDateFormat} from "./dateFormat";@@ -21,6 +21,8 @@ import {getFieldsByData} from "./view";import {hasClosestByClassName} from "../../util/hasClosest";import {openFieldVisibility} from "./fieldVisibility";import {createEmptyAVValue, genAVAttributeRowHTML} from "./attributeValue";+import {getAVColumnTextMeasurer, getAVTableFitWidths} from "./columnWidth";+import {getAVData} from "./virtualScroll";export const getColId = (element: Element, viewType: TAVView) => {if (viewType === "table" || hasClosestByClassName(element, "custom-attr")) {@@ -1119,6 +1121,49 @@ export const showColMenu = (protyle: IProtyle, blockElement: Element, cellElemen}});}+ menu.addItem({+ icon: "iconWidth",+ label: window.siyuan.languages.autoFitAllColWidths,+ click() {+ const data = getAVData(blockElement as HTMLElement);+ if (!data || data.viewType !== "table") {+ return;+ }+ const widths = getAVTableFitWidths(+ data.view as IAVTable,+ getCellValueText,+ getAVColumnTextMeasurer(blockElement as HTMLElement),+ );+ const oldWidths: Record<string, string> = {};+ const newWidths: Record<string, string> = {};+ Object.entries(widths).forEach(([columnID, width]) => {+ const headerElement = blockElement.querySelector<HTMLElement>(+ `.av__row--header .av__cell[data-col-id="${columnID}"]`,+ );+ if (!headerElement || headerElement.style.width === width) {+ return;+ }+ oldWidths[columnID] = headerElement.style.width || "200px";+ newWidths[columnID] = width;+ });+ if (Object.keys(newWidths).length === 0) {+ return;+ }+ const operation = {+ action: "setAttrViewColsWidth" as TOperation,+ avID,+ blockID,+ viewID,+ };+ transaction(protyle, [{+ ...operation,+ data: newWidths,+ }], [{+ ...operation,+ data: oldWidths,+ }]);+ }+ });menu.addItem({icon: "iconRefresh",label: window.siyuan.languages.syncColWidth,diff --git a/app/src/protyle/render/av/columnWidth.test.ts b/app/src/protyle/render/av/columnWidth.test.tsnew file mode 100644index 0000000000..3084ddbe22--- /dev/null+++ b/app/src/protyle/render/av/columnWidth.test.ts@@ -0,0 +1,71 @@+import {describe, it} from "node:test";+import * as assert from "node:assert/strict";+import {getAVColumnFitWidth, getAVTableFitWidths} from "./columnWidth";++const measureText = (value: string) => value.length * 10;++describe("getAVColumnFitWidth", () => {+ it("calculates compact widths from measured content", () => {+ assert.equal(getAVColumnFitWidth("优先级", "select", ["P1", "P2", "P3"], measureText), "72px");+ assert.equal(getAVColumnFitWidth(+ "URL", "url", ["https://github.com/siyuan-note/siyuan/issues/10767"], measureText), "480px");+ assert.equal(getAVColumnFitWidth("日期", "date", ["2026-07-30"], measureText), "120px");+ assert.equal(getAVColumnFitWidth(+ "标题", "text", ["A very long title that should not make the field excessively wide"], measureText), "480px");+ });++ it("uses select padding for multi-select columns", () => {+ assert.equal(getAVColumnFitWidth("P", "mSelect", ["Long"], measureText), "72px");+ });+});++describe("getAVTableFitWidths", () => {+ it("uses visible groups, field IDs and total line counts", () => {+ const columns = [+ {id: "title", name: "Title", type: "text", hidden: false},+ {id: "priority", name: "P", type: "mSelect", hidden: false},+ {id: "number", name: "No", type: "lineNumber", hidden: false},+ {id: "hidden", name: "Hidden", type: "text", hidden: true},+ ] as IAVColumn[];+ const visibleGroup = {+ columns,+ rows: [{+ id: "row-1",+ cells: [+ {value: {keyID: "priority", type: "mSelect", text: {content: "Long"}}},+ {value: {keyID: "title", type: "text", text: {content: "Content"}}},+ ],+ }],+ groups: [],+ groupHidden: 0,+ rowCount: 12345,+ } as IAVTable;+ const hiddenGroup = {+ columns,+ rows: [{+ id: "row-2",+ cells: [{value: {keyID: "title", type: "text", text: {content: "Ignored long content"}}}],+ }],+ groups: [],+ groupHidden: 2,+ rowCount: 1,+ } as IAVTable;+ const view = {+ columns,+ rows: [],+ groups: [visibleGroup, hiddenGroup],+ rowCount: 12346,+ } as unknown as IAVTable;+ const widths = getAVTableFitWidths(+ view,+ value => value.text?.content || "",+ measureText,+ );++ assert.deepEqual(widths, {+ title: "92px",+ priority: "72px",+ number: "70px",+ });+ });+});diff --git a/app/src/protyle/render/av/columnWidth.ts b/app/src/protyle/render/av/columnWidth.tsnew file mode 100644index 0000000000..efda808b52--- /dev/null+++ b/app/src/protyle/render/av/columnWidth.ts@@ -0,0 +1,80 @@+const getEstimatedTextWidth = (value: string) => {+ return Array.from(value.trim().replace(/[\r\n]+/g, " ")).reduce((width, character) => {+ if (/[\u2E80-\u9FFF\uAC00-\uD7AF]/u.test(character)) {+ return width + 14;+ }+ if (/\s/u.test(character)) {+ return width + 4;+ }+ if (/[A-ZMW@#%&]/u.test(character)) {+ return width + 9;+ }+ return width + 7;+ }, 0);+};++export const getAVColumnTextMeasurer = (blockElement: HTMLElement) => {+ const canvas = document.createElement("canvas");+ const context = canvas.getContext("2d");+ const cellElement = blockElement.querySelector<HTMLElement>(".av__cell");+ if (!context || !cellElement) {+ return getEstimatedTextWidth;+ }+ const style = getComputedStyle(cellElement);+ context.font = `${style.fontStyle} ${style.fontWeight} ${style.fontSize} ${style.fontFamily}`;+ return (value: string) => context.measureText(value.trim().replace(/[\r\n]+/g, " ")).width;+};++export const getAVColumnFitWidth = (name: string, type: TAVCol, values: string[],+ measureText = getEstimatedTextWidth) => {+ const headerWidth = measureText(name) + 42;+ const contentPadding = ["select", "mSelect"].includes(type) ? 32 : 20;+ const contentWidth = values.reduce((width, value) => Math.max(width, measureText(value) + contentPadding), 0);+ return `${Math.ceil(Math.min(480, Math.max(64, headerWidth, contentWidth)))}px`;+};++export const getAVTableFitWidths = (+ view: IAVTable,+ getValueText: (value: IAVCellValue, column: IAVColumn, rowIndex: number) => string,+ measureText = getEstimatedTextWidth,+) => {+ const visibleColumns = view.columns.filter(column => !column.hidden);+ const values = new Map(visibleColumns.map(column => [column.id, [] as string[]]));+ const collect = (table: IAVTable) => {+ if (table.groups?.length > 0) {+ (table.groups as IAVTable[]).forEach(group => {+ if (group.groupHidden === 0) {+ collect(group);+ }+ });+ return;+ }+ visibleColumns.forEach(column => {+ if (column.type === "lineNumber") {+ values.get(column.id)?.push((table.rowCount || table.rows.length).toString());+ }+ });+ const columnIndexes = new Map(visibleColumns.map(column => [+ column.id,+ table.columns.findIndex(item => item.id === column.id),+ ]));+ table.rows.forEach((row, rowIndex) => {+ visibleColumns.forEach(column => {+ if (column.type === "lineNumber") {+ return;+ }+ const columnIndex = columnIndexes.get(column.id);+ const cell = row.cells.find(item => item.value?.keyID === column.id) ||+ (typeof columnIndex === "number" && columnIndex > -1 ? row.cells[columnIndex] : undefined);+ if (cell) {+ values.get(column.id)?.push(getValueText(cell.value, column, rowIndex));+ }+ });+ });+ };+ collect(view);+ return Object.fromEntries(visibleColumns.map(column => [+ column.id,+ getAVColumnFitWidth(column.name, column.type, values.get(column.id) || [], measureText),+ ]));+};diff --git a/app/src/protyle/render/av/paste.test.ts b/app/src/protyle/render/av/paste.test.tsindex 6e60130c6b..5a3b37d073 100644--- a/app/src/protyle/render/av/paste.test.ts+++ b/app/src/protyle/render/av/paste.test.ts@@ -2,7 +2,6 @@ import {describe, it} from "node:test";import * as assert from "node:assert/strict";import {getAVPasteMatrixWidth,- getAVPasteColumnWidth,getUniqueAVPasteColumnName,inferAVPasteColumnType,isAVPasteHeaderCandidate,@@ -77,13 +76,4 @@ describe("AV paste matrix helpers", () => {assert.equal(shouldShowAVPasteSkeleton([Array(100)]), true);});- it("calculates compact widths from measured content", () => {- const measureText = (value: string) => value.length * 10;- assert.equal(getAVPasteColumnWidth("优先级", "select", ["P1", "P2", "P3"], measureText), "72px");- assert.equal(getAVPasteColumnWidth(- "URL", "url", ["https://github.com/siyuan-note/siyuan/issues/10767"], measureText), "480px");- assert.equal(getAVPasteColumnWidth("日期", "date", ["2026-07-30"], measureText), "120px");- assert.equal(getAVPasteColumnWidth(- "标题", "text", ["A very long title that should not make the field excessively wide"], measureText), "480px");- });});diff --git a/app/src/protyle/render/av/paste.ts b/app/src/protyle/render/av/paste.tsindex f1af62fe9a..09d846e843 100644--- a/app/src/protyle/render/av/paste.ts+++ b/app/src/protyle/render/av/paste.ts@@ -80,41 +80,6 @@ export const shouldShowAVPasteSkeleton = (rows: unknown[][]) => {return rows.reduce((count, row) => count + row.length, 0) >= 100;};-const getEstimatedTextWidth = (value: string) => {- return Array.from(value.trim().replace(/[\r\n]+/g, " ")).reduce((width, character) => {- if (/[\u2E80-\u9FFF\uAC00-\uD7AF]/u.test(character)) {- return width + 14;- }- if (/\s/u.test(character)) {- return width + 4;- }- if (/[A-ZMW@#%&]/u.test(character)) {- return width + 9;- }- return width + 7;- }, 0);-};--export const getAVPasteTextMeasurer = (blockElement: HTMLElement) => {- const canvas = document.createElement("canvas");- const context = canvas.getContext("2d");- const cellElement = blockElement.querySelector<HTMLElement>(".av__cell");- if (!context || !cellElement) {- return getEstimatedTextWidth;- }- const style = getComputedStyle(cellElement);- context.font = `${style.fontStyle} ${style.fontWeight} ${style.fontSize} ${style.fontFamily}`;- return (value: string) => context.measureText(value.trim().replace(/[\r\n]+/g, " ")).width;-};--export const getAVPasteColumnWidth = (name: string, type: TAVCol, values: string[],- measureText = getEstimatedTextWidth) => {- const headerWidth = measureText(name) + 42;- const contentPadding = type === "select" ? 32 : 20;- const contentWidth = values.reduce((width, value) => Math.max(width, measureText(value) + contentPadding), 0);- return `${Math.ceil(Math.min(480, Math.max(64, headerWidth, contentWidth)))}px`;-};-export const showAVPasteSkeleton = (blockElement: HTMLElement, columnCount: number) => {if (blockElement.querySelector(".av__paste-skeleton")) {return false;diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.tsindex d87f2c722e..fdb943b901 100644--- a/app/src/protyle/render/av/render.ts+++ b/app/src/protyle/render/av/render.ts@@ -798,8 +798,24 @@ export const refreshAV = (protyle: IProtyle, operation: IOperation) => {if (!cellElement || cellElement.style.width === operation.data) {return;}- item.querySelectorAll(".av__row").forEach(rowItem => {- (rowItem.querySelector(`[data-col-id="${operation.id}"]`) as HTMLElement).style.width = operation.data;+ item.querySelectorAll(".av__row, .av__row--footer").forEach(rowItem => {+ const columnElement = rowItem.querySelector(`[data-col-id="${operation.id}"]`) as HTMLElement;+ if (columnElement) {+ columnElement.style.width = operation.data;+ }+ });+ });+ return;+ }+ if (operation.action === "setAttrViewColsWidth") {+ getAVElements(protyle, operation.avID, operation.viewID).forEach((item) => {+ item.querySelectorAll(".av__row, .av__row--footer").forEach(rowItem => {+ Object.entries(operation.data as Record<string, string>).forEach(([columnID, width]) => {+ const columnElement = rowItem.querySelector(`[data-col-id="${columnID}"]`) as HTMLElement;+ if (columnElement) {+ columnElement.style.width = width;+ }+ });});});return;diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.tsindex 27d08d561c..b9ba138c3a 100644--- a/app/src/protyle/util/insertHTML.ts+++ b/app/src/protyle/util/insertHTML.ts@@ -39,9 +39,7 @@ import {setFold} from "./blockFold";import {removeFoldHeading} from "./heading";import {AV_PASTE_READONLY_TYPES,- getAVPasteColumnWidth,getAVPasteMatrixWidth,- getAVPasteTextMeasurer,getUniqueAVPasteColumnName,inferAVPasteColumnType,isAVPasteHeaderCandidate,@@ -49,6 +47,7 @@ import {shouldShowAVPasteSkeleton,showAVPasteSkeleton,} from "../render/av/paste";+import {getAVColumnFitWidth, getAVColumnTextMeasurer} from "../render/av/columnWidth";import {Dialog} from "../../dialog";import {isMobile} from "../../util/functions";import {getCrossBlockMergeRemoveElement} from "../wysiwyg/removeRange";@@ -346,7 +345,7 @@ const pasteAVMatrix = async (options: {const usedNames = new Set(options.columns.map(column => column.name));const changedCellColumnIDs = new Set<string>();const targetColumns: IAVPasteTargetColumn[] = [];- const measureText = getAVPasteTextMeasurer(options.blockElement);+ const measureText = getAVColumnTextMeasurer(options.blockElement);let previousColumnID = visibleColumns[visibleColumns.length - 1].id;for (let sourceIndex = 0; sourceIndex < sourceWidth; sourceIndex++) {@@ -364,7 +363,7 @@ const pasteAVMatrix = async (options: {? inferredType: currentColumn.type;const compactWidth = options.header && (!oldColumn.width || oldColumn.width === "200px")- ? getAVPasteColumnWidth(nextName, nextType, sourceValues, measureText)+ ? getAVColumnFitWidth(nextName, nextType, sourceValues, measureText): oldColumn.width;const typeChanged = oldColumn.type !== nextType;currentColumn.name = nextName;@@ -435,7 +434,7 @@ const pasteAVMatrix = async (options: {const name = headerName ? headerName : getUniqueAVPasteColumnName(baseName, usedNames);const type = options.header ? inferredType : "text";const column = genAVPasteColumn(id, name, type);- column.width = getAVPasteColumnWidth(name, type, sourceValues, measureText);+ column.width = getAVColumnFitWidth(name, type, sourceValues, measureText);const previousIndex = view.columns.findIndex(item => item.id === previousColumnID);view.columns.splice(previousIndex + 1, 0, column);rows.forEach(row => {diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.tsindex d1cfffa3c4..ee0afadae2 100644--- a/app/src/protyle/wysiwyg/transaction.ts+++ b/app/src/protyle/wysiwyg/transaction.ts@@ -1182,7 +1182,7 @@ export const onTransaction = (protyle: IProtyle, operations: IOperation[], isUnd}if (["addAttrViewCol", "updateAttrViewCol", "updateAttrViewColOptions","updateAttrViewColOption", "updateAttrViewCell", "sortAttrViewRow", "sortAttrViewCol", "setAttrViewColHidden",- "setAttrViewColWrap", "setAttrViewColWidth", "setAttrViewColAlign", "removeAttrViewColOption", "setAttrViewName", "setAttrViewFilters",+ "setAttrViewColWrap", "setAttrViewColWidth", "setAttrViewColsWidth", "setAttrViewColAlign", "removeAttrViewColOption", "setAttrViewName", "setAttrViewFilters","setAttrViewSorts", "setAttrViewNewItemTemplates", "setAttrViewColCalc", "removeAttrViewCol", "updateAttrViewColNumberFormat", "setAttrViewColDateFormat", "removeAttrViewBlock","replaceAttrViewBlock", "updateAttrViewColTemplate", "setAttrViewColPin", "addAttrViewView", "setAttrViewColIcon","removeAttrViewView", "setAttrViewViewName", "setAttrViewViewIcon", "duplicateAttrViewView", "duplicateAttrViewRow", "sortAttrViewView",diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.tsindex eb615fcd0f..eafabaab50 100644--- a/app/src/types/index.d.ts+++ b/app/src/types/index.d.ts@@ -31,6 +31,7 @@ type TOperation =| "setAttrViewColHidden"| "setAttrViewColWrap"| "setAttrViewColWidth"+ | "setAttrViewColsWidth"| "setAttrViewColAlign"| "updateAttrViewColOptions"| "removeAttrViewColOption"diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.goindex 25bcf9b1d1..b6413975d3 100644--- a/kernel/model/attribute_view.go+++ b/kernel/model/attribute_view.go@@ -6111,6 +6111,47 @@ func setAttributeViewColWidth(operation *Operation) (err error) {return}+func (tx *Transaction) doSetAttrViewColumnsWidth(operation *Operation) (ret *TxErr) {+ err := setAttributeViewColsWidth(operation)+ if err != nil {+ return &TxErr{code: TxErrHandleAttributeView, id: operation.AvID, msg: err.Error()}+ }+ return+}++func setAttributeViewColsWidth(operation *Operation) (err error) {+ widthData, ok := operation.Data.(map[string]any)+ if !ok {+ return fmt.Errorf("invalid attribute view column widths")+ }+ widths := map[string]string{}+ for id, value := range widthData {+ width, valueOK := value.(string)+ if !valueOK {+ return fmt.Errorf("invalid width for attribute view column [%s]", id)+ }+ widths[id] = width+ }++ attrView, err := av.ParseAttributeView(operation.AvID)+ if err != nil {+ return err+ }+ view, err := getAttrViewViewByBlockID(attrView, operation.BlockID)+ if err != nil {+ return err+ }+ if av.LayoutTypeTable != view.LayoutType {+ return nil+ }+ for _, column := range view.Table.Columns {+ if width, found := widths[column.ID]; found {+ column.Width = width+ }+ }+ return av.SaveAttributeView(attrView)+}+func (tx *Transaction) doSetAttrViewColumnAlign(operation *Operation) (ret *TxErr) {err := setAttributeViewColAlign(operation)if err != nil {diff --git a/kernel/model/transaction.go b/kernel/model/transaction.goindex 9c70e1d678..72f9537aa7 100644--- a/kernel/model/transaction.go+++ b/kernel/model/transaction.go@@ -301,6 +301,8 @@ func performTx(tx *Transaction) (ret *TxErr) {ret = tx.doSetAttrViewPageSize(op)case "setAttrViewColWidth":ret = tx.doSetAttrViewColumnWidth(op)+ case "setAttrViewColsWidth":+ ret = tx.doSetAttrViewColumnsWidth(op)case "setAttrViewColAlign":ret = tx.doSetAttrViewColumnAlign(op)case "setAttrViewColWrap":