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 column width adjustment interactions https://github.com/siyuan-note/siyuan/issues/12952
Daniel3ef0deaf6b51
diff --git a/app/appearance/langs/ar.json b/app/appearance/langs/ar.jsonindex 6447c4ea9c..45b53973af 100644--- a/app/appearance/langs/ar.json+++ b/app/appearance/langs/ar.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "توزيع عرض جميع الأعمدة بالتساوي",+ "sameWidthAsRightColumn": "بنفس عرض العمود الأيمن",+ "sameWidthAsLeftColumn": "بنفس عرض العمود الأيسر",+ "autoFitColWidth": "ضبط عرض العمود تلقائيًا",+ "sameWidthAsLeftColumnTip": "، بنفس عرض العمود الأيسر","autoFitAllColWidths": "ضبط عرض جميع الأعمدة تلقائيًا","searchPlaceholder": "بحث...","visibleViews": "طرق العرض الظاهرة",diff --git a/app/appearance/langs/de.json b/app/appearance/langs/de.jsonindex c9729a2645..cfd0e6609b 100644--- a/app/appearance/langs/de.json+++ b/app/appearance/langs/de.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "Alle Spaltenbreiten gleichmäßig verteilen",+ "sameWidthAsRightColumn": "Genauso breit wie die rechte Spalte",+ "sameWidthAsLeftColumn": "Genauso breit wie die linke Spalte",+ "autoFitColWidth": "Spaltenbreite automatisch anpassen",+ "sameWidthAsLeftColumnTip": ", genauso breit wie die linke Spalte","autoFitAllColWidths": "Alle Spaltenbreiten automatisch anpassen","searchPlaceholder": "Suchen...","visibleViews": "Sichtbare Ansichten",diff --git a/app/appearance/langs/en.json b/app/appearance/langs/en.jsonindex d960e4d50e..2ddc8a50ac 100644--- a/app/appearance/langs/en.json+++ b/app/appearance/langs/en.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "Distribute all column widths evenly",+ "sameWidthAsRightColumn": "Same width as the right column",+ "sameWidthAsLeftColumn": "Same width as the left column",+ "autoFitColWidth": "Auto-fit column width",+ "sameWidthAsLeftColumnTip": ", same width as the left column","autoFitAllColWidths": "Auto-fit all column widths","searchPlaceholder": "Search...","visibleViews": "Visible views",diff --git a/app/appearance/langs/es.json b/app/appearance/langs/es.jsonindex 69cd841674..edf7d36677 100644--- a/app/appearance/langs/es.json+++ b/app/appearance/langs/es.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "Distribuir uniformemente el ancho de todas las columnas",+ "sameWidthAsRightColumn": "Mismo ancho que la columna derecha",+ "sameWidthAsLeftColumn": "Mismo ancho que la columna izquierda",+ "autoFitColWidth": "Ajustar automáticamente el ancho de la columna",+ "sameWidthAsLeftColumnTip": ", mismo ancho que la columna izquierda","autoFitAllColWidths": "Ajustar automáticamente el ancho de todas las columnas","searchPlaceholder": "Buscar...","visibleViews": "Vistas visibles",diff --git a/app/appearance/langs/fr.json b/app/appearance/langs/fr.jsonindex 16edd6c187..4611550618 100644--- a/app/appearance/langs/fr.json+++ b/app/appearance/langs/fr.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "Répartir uniformément la largeur de toutes les colonnes",+ "sameWidthAsRightColumn": "Même largeur que la colonne de droite",+ "sameWidthAsLeftColumn": "Même largeur que la colonne de gauche",+ "autoFitColWidth": "Ajuster automatiquement la largeur de la colonne",+ "sameWidthAsLeftColumnTip": ", même largeur que la colonne de gauche","autoFitAllColWidths": "Ajuster automatiquement la largeur de toutes les colonnes","searchPlaceholder": "Recherche...","visibleViews": "Vues visibles",diff --git a/app/appearance/langs/he.json b/app/appearance/langs/he.jsonindex 6c3bdc7109..c5071c719b 100644--- a/app/appearance/langs/he.json+++ b/app/appearance/langs/he.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "פזר את רוחב כל העמודות באופן שווה",+ "sameWidthAsRightColumn": "רוחב זהה לעמודה הימנית",+ "sameWidthAsLeftColumn": "רוחב זהה לעמודה השמאלית",+ "autoFitColWidth": "התאם אוטומטית את רוחב העמודה",+ "sameWidthAsLeftColumnTip": ", רוחב זהה לעמודה השמאלית","autoFitAllColWidths": "התאם אוטומטית את רוחב כל העמודות","searchPlaceholder": "חפש...","visibleViews": "תצוגות גלויות",diff --git a/app/appearance/langs/hi.json b/app/appearance/langs/hi.jsonindex 6af3769715..df20f9442b 100644--- a/app/appearance/langs/hi.json+++ b/app/appearance/langs/hi.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "सभी स्तंभों की चौड़ाई समान रूप से बाँटें",+ "sameWidthAsRightColumn": "दाएँ स्तंभ जितनी चौड़ाई",+ "sameWidthAsLeftColumn": "बाएँ स्तंभ जितनी चौड़ाई",+ "autoFitColWidth": "स्तंभ की चौड़ाई अपने आप समायोजित करें",+ "sameWidthAsLeftColumnTip": ", बाएँ कॉलम जितनी चौड़ाई","autoFitAllColWidths": "सभी स्तंभों की चौड़ाई अपने आप समायोजित करें","searchPlaceholder": "खोजें...","visibleViews": "दिखाई देने वाले दृश्य",diff --git a/app/appearance/langs/id.json b/app/appearance/langs/id.jsonindex 526b62e26b..80018112e0 100644--- a/app/appearance/langs/id.json+++ b/app/appearance/langs/id.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "Distribusikan semua lebar kolom secara merata",+ "sameWidthAsRightColumn": "Sama lebar dengan kolom kanan",+ "sameWidthAsLeftColumn": "Sama lebar dengan kolom kiri",+ "autoFitColWidth": "Sesuaikan lebar kolom secara otomatis",+ "sameWidthAsLeftColumnTip": ", sama lebar dengan kolom kiri","autoFitAllColWidths": "Sesuaikan semua lebar kolom secara otomatis","searchPlaceholder": "Cari...","visibleViews": "Tampilan terlihat",diff --git a/app/appearance/langs/it.json b/app/appearance/langs/it.jsonindex 19bf1d5a98..c89a01d65a 100644--- a/app/appearance/langs/it.json+++ b/app/appearance/langs/it.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "Distribuisci uniformemente la larghezza di tutte le colonne",+ "sameWidthAsRightColumn": "Stessa larghezza della colonna a destra",+ "sameWidthAsLeftColumn": "Stessa larghezza della colonna a sinistra",+ "autoFitColWidth": "Adatta automaticamente la larghezza della colonna",+ "sameWidthAsLeftColumnTip": ", stessa larghezza della colonna a sinistra","autoFitAllColWidths": "Adatta automaticamente la larghezza di tutte le colonne","searchPlaceholder": "Cerca...","visibleViews": "Viste visibili",diff --git a/app/appearance/langs/ja.json b/app/appearance/langs/ja.jsonindex 55e197d0d5..2d29d86933 100644--- a/app/appearance/langs/ja.json+++ b/app/appearance/langs/ja.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "すべての列幅を均等にする",+ "sameWidthAsRightColumn": "右の列と同じ幅",+ "sameWidthAsLeftColumn": "左の列と同じ幅",+ "autoFitColWidth": "列幅を自動調整",+ "sameWidthAsLeftColumnTip": "、左の列と同じ幅","autoFitAllColWidths": "すべての列幅を自動調整","searchPlaceholder": "検索...","visibleViews": "表示中のビュー",diff --git a/app/appearance/langs/ko.json b/app/appearance/langs/ko.jsonindex fadbb1cf9f..02c775ef56 100644--- a/app/appearance/langs/ko.json+++ b/app/appearance/langs/ko.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "모든 열 너비를 균등하게 분배",+ "sameWidthAsRightColumn": "오른쪽 열과 같은 너비",+ "sameWidthAsLeftColumn": "왼쪽 열과 같은 너비",+ "autoFitColWidth": "열 너비 자동 맞춤",+ "sameWidthAsLeftColumnTip": ", 왼쪽 열과 같은 너비","autoFitAllColWidths": "모든 열 너비 자동 맞춤","searchPlaceholder": "검색...","visibleViews": "표시된 뷰",diff --git a/app/appearance/langs/nl.json b/app/appearance/langs/nl.jsonindex 5b3446c384..1aad779bef 100644--- a/app/appearance/langs/nl.json+++ b/app/appearance/langs/nl.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "Alle kolombreedtes gelijkmatig verdelen",+ "sameWidthAsRightColumn": "Even breed als de rechterkolom",+ "sameWidthAsLeftColumn": "Even breed als de linkerkolom",+ "autoFitColWidth": "Kolombreedte automatisch aanpassen",+ "sameWidthAsLeftColumnTip": ", even breed als de linkerkolom","autoFitAllColWidths": "Alle kolombreedtes automatisch aanpassen","searchPlaceholder": "Zoeken...","visibleViews": "Zichtbare weergaven",diff --git a/app/appearance/langs/pl.json b/app/appearance/langs/pl.jsonindex 06ba57dce8..d2abdda1f6 100644--- a/app/appearance/langs/pl.json+++ b/app/appearance/langs/pl.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "Rozłóż równomiernie szerokość wszystkich kolumn",+ "sameWidthAsRightColumn": "Taka sama szerokość jak prawa kolumna",+ "sameWidthAsLeftColumn": "Taka sama szerokość jak lewa kolumna",+ "autoFitColWidth": "Automatycznie dopasuj szerokość kolumny",+ "sameWidthAsLeftColumnTip": ", taka sama szerokość jak lewa kolumna","autoFitAllColWidths": "Automatycznie dopasuj szerokość wszystkich kolumn","searchPlaceholder": "Szukaj...","visibleViews": "Widoczne widoki",diff --git a/app/appearance/langs/pt-BR.json b/app/appearance/langs/pt-BR.jsonindex 5895cd8553..1017462d82 100644--- a/app/appearance/langs/pt-BR.json+++ b/app/appearance/langs/pt-BR.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "Distribuir uniformemente a largura de todas as colunas",+ "sameWidthAsRightColumn": "Mesma largura da coluna à direita",+ "sameWidthAsLeftColumn": "Mesma largura da coluna à esquerda",+ "autoFitColWidth": "Ajustar automaticamente a largura da coluna",+ "sameWidthAsLeftColumnTip": ", mesma largura da coluna à esquerda","autoFitAllColWidths": "Ajustar automaticamente a largura de todas as colunas","searchPlaceholder": "Pesquisar...","visibleViews": "Visualizações visíveis",diff --git a/app/appearance/langs/ru.json b/app/appearance/langs/ru.jsonindex 8232ae804e..7cb892da61 100644--- a/app/appearance/langs/ru.json+++ b/app/appearance/langs/ru.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "Равномерно распределить ширину всех столбцов",+ "sameWidthAsRightColumn": "Та же ширина, что у столбца справа",+ "sameWidthAsLeftColumn": "Та же ширина, что у столбца слева",+ "autoFitColWidth": "Автоматически подобрать ширину столбца",+ "sameWidthAsLeftColumnTip": ", такая же ширина, как у столбца слева","autoFitAllColWidths": "Автоматически подобрать ширину всех столбцов","searchPlaceholder": "Поиск...","visibleViews": "Отображаемые виды",diff --git a/app/appearance/langs/sk.json b/app/appearance/langs/sk.jsonindex 5416a68bf9..8729e126dc 100644--- a/app/appearance/langs/sk.json+++ b/app/appearance/langs/sk.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "Rovnomerne rozložiť šírku všetkých stĺpcov",+ "sameWidthAsRightColumn": "Rovnaká šírka ako pravý stĺpec",+ "sameWidthAsLeftColumn": "Rovnaká šírka ako ľavý stĺpec",+ "autoFitColWidth": "Automaticky prispôsobiť šírku stĺpca",+ "sameWidthAsLeftColumnTip": ", rovnaká šírka ako ľavý stĺpec","autoFitAllColWidths": "Automaticky prispôsobiť šírku všetkých stĺpcov","searchPlaceholder": "Vyhľadávanie...","visibleViews": "Viditeľné zobrazenia",diff --git a/app/appearance/langs/th.json b/app/appearance/langs/th.jsonindex da02c20e8e..f65358aec0 100644--- a/app/appearance/langs/th.json+++ b/app/appearance/langs/th.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "กระจายความกว้างของคอลัมน์ทั้งหมดให้เท่ากัน",+ "sameWidthAsRightColumn": "กว้างเท่ากับคอลัมน์ด้านขวา",+ "sameWidthAsLeftColumn": "กว้างเท่ากับคอลัมน์ด้านซ้าย",+ "autoFitColWidth": "ปรับความกว้างคอลัมน์โดยอัตโนมัติ",+ "sameWidthAsLeftColumnTip": ", กว้างเท่ากับคอลัมน์ด้านซ้าย","autoFitAllColWidths": "ปรับความกว้างของคอลัมน์ทั้งหมดโดยอัตโนมัติ","searchPlaceholder": "ค้นหา...","visibleViews": "มุมมองที่มองเห็น",diff --git a/app/appearance/langs/tr.json b/app/appearance/langs/tr.jsonindex bcd62533b5..5464911f80 100644--- a/app/appearance/langs/tr.json+++ b/app/appearance/langs/tr.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "Tüm sütun genişliklerini eşit dağıt",+ "sameWidthAsRightColumn": "Sağdaki sütunla aynı genişlikte",+ "sameWidthAsLeftColumn": "Soldaki sütunla aynı genişlikte",+ "autoFitColWidth": "Sütun genişliğini otomatik ayarla",+ "sameWidthAsLeftColumnTip": ", soldaki sütunla aynı genişlikte","autoFitAllColWidths": "Tüm sütun genişliklerini otomatik ayarla","searchPlaceholder": "Ara...","visibleViews": "Görünür görünümler",diff --git a/app/appearance/langs/uk.json b/app/appearance/langs/uk.jsonindex a0e082210a..b5afc76154 100644--- a/app/appearance/langs/uk.json+++ b/app/appearance/langs/uk.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "Рівномірно розподілити ширину всіх стовпців",+ "sameWidthAsRightColumn": "Така сама ширина, як у стовпця праворуч",+ "sameWidthAsLeftColumn": "Така сама ширина, як у стовпця ліворуч",+ "autoFitColWidth": "Автоматично підібрати ширину стовпця",+ "sameWidthAsLeftColumnTip": ", така сама ширина, як у стовпця ліворуч","autoFitAllColWidths": "Автоматично підібрати ширину всіх стовпців","searchPlaceholder": "Пошук...","visibleViews": "Видимі подання",diff --git a/app/appearance/langs/zh-CN.json b/app/appearance/langs/zh-CN.jsonindex 9ed06505ed..57d455d3fe 100644--- a/app/appearance/langs/zh-CN.json+++ b/app/appearance/langs/zh-CN.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "均分所有列宽",+ "sameWidthAsRightColumn": "与右侧列同宽",+ "sameWidthAsLeftColumn": "与左侧列同宽",+ "autoFitColWidth": "自动调整列宽",+ "sameWidthAsLeftColumnTip": ",与左侧列同宽","autoFitAllColWidths": "自动调整所有列宽","searchPlaceholder": "搜索...","visibleViews": "显示视图",diff --git a/app/appearance/langs/zh-TW.json b/app/appearance/langs/zh-TW.jsonindex b2e29c832c..97e99b6bcb 100644--- a/app/appearance/langs/zh-TW.json+++ b/app/appearance/langs/zh-TW.json@@ -1,4 +1,9 @@{+ "distributeAllColWidths": "均分所有欄寬",+ "sameWidthAsRightColumn": "與右側欄同寬",+ "sameWidthAsLeftColumn": "與左側欄同寬",+ "autoFitColWidth": "自動調整欄寬",+ "sameWidthAsLeftColumnTip": ",與左側欄同寬","autoFitAllColWidths": "自動調整所有列寬","searchPlaceholder": "搜索...","visibleViews": "顯示視圖",diff --git a/app/src/protyle/render/av/col.ts b/app/src/protyle/render/av/col.tsindex cac937f72b..d7243cf4dc 100644--- a/app/src/protyle/render/av/col.ts+++ b/app/src/protyle/render/av/col.ts@@ -21,7 +21,7 @@ import {getFieldsByData} from "./view";import {hasClosestByClassName} from "../../util/hasClosest";import {openFieldVisibility} from "./fieldVisibility";import {createEmptyAVValue, genAVAttributeRowHTML} from "./attributeValue";-import {getAVColumnTextMeasurer, getAVTableFitWidths} from "./columnWidth";+import {getAVColumnTextMeasurer, getAVDistributedColumnWidth, getAVTableFitWidths} from "./columnWidth";import {getAVData} from "./virtualScroll";export const getColId = (element: Element, viewType: TAVView) => {@@ -771,17 +771,7 @@ export const setFreezeColumn = (protyle: IProtyle, blockElement: Element, freezetransaction(protyle, [operation], [undoOperation]);};-export const autoFitAVColumns = (protyle: IProtyle, blockElement: HTMLElement, columnIDs?: string[]) => {- const data = getAVData(blockElement);- if (!data || data.viewType !== "table") {- return;- }- const widths = getAVTableFitWidths(- data.view as IAVTable,- getCellValueText,- getAVColumnTextMeasurer(blockElement),- columnIDs,- );+const setAVColumnWidths = (protyle: IProtyle, blockElement: HTMLElement, widths: Record<string, string>) => {const oldWidths: Record<string, string> = {};const newWidths: Record<string, string> = {};Object.entries(widths).forEach(([columnID, width]) => {@@ -812,6 +802,95 @@ export const autoFitAVColumns = (protyle: IProtyle, blockElement: HTMLElement, c}]);};+export const autoFitAVColumns = (protyle: IProtyle, blockElement: HTMLElement, columnIDs?: string[]) => {+ const data = getAVData(blockElement);+ if (!data || data.viewType !== "table") {+ return;+ }+ setAVColumnWidths(protyle, blockElement, getAVTableFitWidths(+ data.view as IAVTable,+ getCellValueText,+ getAVColumnTextMeasurer(blockElement),+ columnIDs,+ ));+};++const getAVColumnElementWidth = (element: HTMLElement) => {+ return Math.round(parseFloat(element.style.width) || element.getBoundingClientRect().width);+};++export const showAVColumnWidthMenu = (protyle: IProtyle, blockElement: HTMLElement,+ widthDragElement: HTMLElement, position: IPosition) => {+ const columnElement = widthDragElement.parentElement as HTMLElement;+ const headerElement = hasClosestByClassName(widthDragElement, "av__row--header") as HTMLElement;+ if (!columnElement || !headerElement) {+ return;+ }+ const columnElements = Array.from(headerElement.querySelectorAll<HTMLElement>(".av__cell--header"));+ const columnIndex = columnElements.indexOf(columnElement);+ const columnID = columnElement.dataset.colId;+ if (columnIndex < 0 || !columnID) {+ return;+ }+ const previousElement = columnIndex > 0 ? columnElements[columnIndex - 1] : undefined;+ const nextElement = columnIndex < columnElements.length - 1 ? columnElements[columnIndex + 1] : undefined;+ const setCurrentColumnWidth = (sourceElement?: HTMLElement) => {+ if (sourceElement) {+ setAVColumnWidths(protyle, blockElement, {+ [columnID]: `${getAVColumnElementWidth(sourceElement)}px`,+ });+ }+ };+ const menu = new Menu();+ menu.addItem({+ icon: "iconWidth",+ label: window.siyuan.languages.autoFitColWidth,+ click() {+ autoFitAVColumns(protyle, blockElement, [columnID]);+ }+ });+ menu.addItem({+ icon: "iconInsertLeft",+ label: window.siyuan.languages.sameWidthAsLeftColumn,+ disabled: !previousElement,+ click() {+ setCurrentColumnWidth(previousElement);+ }+ });+ menu.addItem({+ icon: "iconInsertRight",+ label: window.siyuan.languages.sameWidthAsRightColumn,+ disabled: !nextElement,+ click() {+ setCurrentColumnWidth(nextElement);+ }+ });+ menu.addItem({+ icon: "iconSpreadEven",+ label: window.siyuan.languages.distributeAllColWidths,+ click() {+ const width = `${getAVDistributedColumnWidth(columnElements.map(getAVColumnElementWidth))}px`;+ setAVColumnWidths(protyle, blockElement, Object.fromEntries(columnElements.map(item => [+ item.dataset.colId,+ width,+ ])));+ }+ });+ menu.addItem({+ icon: "iconRefresh",+ label: window.siyuan.languages.syncColWidth,+ click() {+ transaction(protyle, [{+ action: "syncAttrViewTableColWidth",+ keyID: columnID,+ avID: blockElement.dataset.avId,+ id: blockElement.getAttribute(Constants.CUSTOM_SY_AV_VIEW),+ }]);+ }+ });+ menu.open(position);+};+export const showColMenu = (protyle: IProtyle, blockElement: Element, cellElement: HTMLElement) => {const type = cellElement.getAttribute("data-dtype") as TAVCol;const colId = cellElement.getAttribute("data-col-id");diff --git a/app/src/protyle/render/av/columnWidth.test.ts b/app/src/protyle/render/av/columnWidth.test.tsindex 5f19c77a57..0501e42294 100644--- a/app/src/protyle/render/av/columnWidth.test.ts+++ b/app/src/protyle/render/av/columnWidth.test.ts@@ -1,6 +1,11 @@import {describe, it} from "node:test";import * as assert from "node:assert/strict";-import {getAVColumnFitWidth, getAVColumnResizeWidth, getAVTableFitWidths} from "./columnWidth";+import {+ getAVColumnFitWidth,+ getAVColumnResizeWidth,+ getAVDistributedColumnWidth,+ getAVTableFitWidths,+} from "./columnWidth";const measureText = (value: string) => value.length * 10;@@ -81,12 +86,20 @@ describe("getAVTableFitWidths", () => {describe("getAVColumnResizeWidth", () => {it("snaps to the previous visible column within the threshold", () => {- assert.deepEqual(getAVColumnResizeWidth(194, 200), {width: 200, snapped: true});- assert.deepEqual(getAVColumnResizeWidth(206, 200), {width: 200, snapped: true});- assert.deepEqual(getAVColumnResizeWidth(207, 200), {width: 207, snapped: false});+ assert.deepEqual(getAVColumnResizeWidth(195, 200), {width: 195, snapped: false});+ assert.deepEqual(getAVColumnResizeWidth(196, 200), {width: 200, snapped: true});+ assert.deepEqual(getAVColumnResizeWidth(204, 200), {width: 200, snapped: true});+ assert.deepEqual(getAVColumnResizeWidth(205, 200), {width: 205, snapped: false});});it("keeps manual resizing above the minimum width", () => {assert.deepEqual(getAVColumnResizeWidth(10), {width: 25, snapped: false});});});++describe("getAVDistributedColumnWidth", () => {+ it("preserves the total width while distributing columns evenly", () => {+ assert.equal(getAVDistributedColumnWidth([120, 240, 360]), 240);+ assert.equal(getAVDistributedColumnWidth([]), 25);+ });+});diff --git a/app/src/protyle/render/av/columnWidth.ts b/app/src/protyle/render/av/columnWidth.tsindex 94e67b3417..e6eb433819 100644--- a/app/src/protyle/render/av/columnWidth.ts+++ b/app/src/protyle/render/av/columnWidth.ts@@ -33,7 +33,7 @@ export const getAVColumnFitWidth = (name: string, type: TAVCol, values: string[]return `${Math.ceil(Math.min(480, Math.max(64, headerWidth, contentWidth)))}px`;};-export const getAVColumnResizeWidth = (width: number, previousWidth?: number, snapThreshold = 6) => {+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;const snapped = typeof normalizedPreviousWidth === "number" &&@@ -44,6 +44,13 @@ export const getAVColumnResizeWidth = (width: number, previousWidth?: number, sn};};+export const getAVDistributedColumnWidth = (widths: number[]) => {+ if (widths.length === 0) {+ return 25;+ }+ return Math.max(25, Math.round(widths.reduce((total, width) => total + width, 0) / widths.length));+};+export const getAVTableFitWidths = (view: IAVTable,getValueText: (value: IAVCellValue, column: IAVColumn, rowIndex: number) => string,diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.tsindex 6cb437492f..3c87256c7b 100644--- a/app/src/protyle/wysiwyg/index.ts+++ b/app/src/protyle/wysiwyg/index.ts@@ -108,7 +108,7 @@ import {commonClick} from "./commonClick";import {avClick, avContextmenu, updateAVName} from "../render/av/action";import {selectRow, stickyRow, updateHeader} from "../render/av/row";import {getAVSelectedItemIDs, getAVSelectedTableCells, updateAVRowSelect} from "../render/av/virtualScroll";-import {autoFitAVColumns, setFreezeColumn, showColMenu} from "../render/av/col";+import {autoFitAVColumns, setFreezeColumn, showAVColumnWidthMenu, showColMenu} from "../render/av/col";import {openViewMenu} from "../render/av/view";import {getAVCurrentViewID} from "../render/av/viewVisibility";import {checkFold} from "../../util/noRelyPCFunction";@@ -1379,7 +1379,8 @@ export class WYSIWYG {const avId = nodeElement.getAttribute("data-av-id");const blockID = nodeElement.dataset.nodeId;const dragElement = target.parentElement as HTMLElement;- const oldWidth = dragElement.clientWidth;+ const dragRect = dragElement.getBoundingClientRect();+ const oldWidth = Math.round(parseFloat(dragElement.style.width) || dragRect.width);const dragColId = dragElement.getAttribute("data-col-id");const bodyElement = hasClosestByClassName(target, "av__body") as HTMLElement;const headerElement = hasClosestByClassName(target, "av__row--header") as HTMLElement;@@ -1389,10 +1390,27 @@ export class WYSIWYG {}const headerCells = Array.from(headerElement.querySelectorAll<HTMLElement>(".av__cell--header"));const dragIndex = headerCells.indexOf(dragElement);- const previousWidth = dragIndex > 0 ? headerCells[dragIndex - 1].clientWidth : undefined;+ const previousElement = dragIndex > 0 ? headerCells[dragIndex - 1] : undefined;+ const previousWidth = previousElement ?+ Math.round(parseFloat(previousElement.style.width) || previousElement.getBoundingClientRect().width) :+ undefined;+ const columnElements: HTMLElement[] = [];+ scrollElement.querySelectorAll(".av__row, .av__row--footer").forEach(item => {+ const columnElement = item.querySelector<HTMLElement>(`[data-col-id="${dragColId}"]`);+ if (columnElement) {+ columnElements.push(columnElement);+ }+ });+ const initialDragRight = dragRect.right;+ const headerTop = headerElement.getBoundingClientRect().top;+ const bodyBottom = bodyElement.getBoundingClientRect().bottom;+ const guideHeight = Math.max(0,+ Math.round(Math.min(bodyBottom, contentRect.bottom, window.innerHeight) - headerTop));let newWidth: number;let resizeGuide: HTMLElement;let resizeTip: HTMLElement;+ let pendingResize: { width: number, snapped: boolean } | undefined;+ let resizeAnimationFrame: number | undefined;const clearResizePreview = () => {resizeGuide?.remove();resizeTip?.remove();@@ -1406,35 +1424,47 @@ export class WYSIWYG {resizeTip.className = "av__width-tip";document.body.appendChild(resizeTip);}- const dragRect = dragElement.getBoundingClientRect();- const headerRect = headerElement.getBoundingClientRect();- const bodyRect = bodyElement.getBoundingClientRect();- const guideBottom = Math.min(bodyRect.bottom, contentRect.bottom, window.innerHeight);+ const dragRight = Math.round(initialDragRight + newWidth - oldWidth);resizeGuide.classList.toggle("av__width-guide--snapped", snapped);- resizeGuide.style.left = `${Math.round(dragRect.right)}px`;- resizeGuide.style.top = `${Math.round(headerRect.top)}px`;- resizeGuide.style.height = `${Math.max(0, Math.round(guideBottom - headerRect.top))}px`;- resizeTip.style.left = `${Math.round(dragRect.right)}px`;- resizeTip.style.top = `${Math.round(headerRect.top)}px`;- resizeTip.textContent = `${newWidth}px`;+ resizeGuide.style.left = `${dragRight}px`;+ resizeGuide.style.top = `${Math.round(headerTop)}px`;+ resizeGuide.style.height = `${guideHeight}px`;+ resizeTip.style.left = `${dragRight}px`;+ resizeTip.style.top = `${Math.round(headerTop)}px`;+ resizeTip.textContent = `${newWidth}px${snapped ?+ window.siyuan.languages.sameWidthAsLeftColumnTip : ""}`;+ };+ const flushResize = () => {+ if (!pendingResize) {+ return;+ }+ const currentResize = pendingResize;+ pendingResize = undefined;+ newWidth = currentResize.width;+ columnElements.forEach(columnElement => {+ columnElement.style.width = newWidth + "px";+ });+ updateResizePreview(currentResize.snapped);};documentSelf.onmousemove = (moveEvent: MouseEvent) => {- const resizeWidth = getAVColumnResizeWidth(+ pendingResize = getAVColumnResizeWidth(oldWidth + (moveEvent.clientX - event.clientX),previousWidth,);- newWidth = resizeWidth.width;- scrollElement.querySelectorAll(".av__row, .av__row--footer").forEach(item => {- const columnElement = item.querySelector<HTMLElement>(`[data-col-id="${dragColId}"]`);- if (columnElement) {- columnElement.style.width = newWidth + "px";- }- });- updateResizePreview(resizeWidth.snapped);- stickyRow(nodeElement, protyle.contentElement, "bottom");+ if (resizeAnimationFrame === undefined) {+ resizeAnimationFrame = requestAnimationFrame(() => {+ resizeAnimationFrame = undefined;+ flushResize();+ });+ }};documentSelf.onmouseup = () => {+ if (resizeAnimationFrame !== undefined) {+ cancelAnimationFrame(resizeAnimationFrame);+ resizeAnimationFrame = undefined;+ }+ flushResize();clearResizePreview();documentSelf.onmousemove = null;documentSelf.onmouseup = null;@@ -1444,6 +1474,7 @@ export class WYSIWYG {if (!newWidth || newWidth === oldWidth) {return;}+ stickyRow(nodeElement, protyle.contentElement, "bottom");const viewID = nodeElement.getAttribute(Constants.CUSTOM_SY_AV_VIEW);transaction(protyle, [{action: "setAttrViewColWidth",@@ -3237,6 +3268,15 @@ export class WYSIWYG {if (!nodeElement) {return false;}+ const widthDragElement = hasClosestByClassName(target, "av__widthdrag") as HTMLElement;+ if (widthDragElement) {+ if (!protyle.disabled) {+ showAVColumnWidthMenu(protyle, nodeElement as HTMLElement, widthDragElement, {x, y});+ }+ event.stopPropagation();+ event.preventDefault();+ return;+ }const avCellElement = hasClosestByClassName(target, "av__cell");if (avCellElement) {if (avCellElement.classList.contains("av__cell--header")) {