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 attribute panel https://github.com/siyuan-note/siyuan/issues/18321
Danielc5d2d96717c3
diff --git a/app/src/assets/scss/business/_custom.scss b/app/src/assets/scss/business/_custom.scssindex e75baba755..9ced2078c7 100644--- a/app/src/assets/scss/business/_custom.scss+++ b/app/src/assets/scss/business/_custom.scss@@ -267,12 +267,81 @@display: none;}+ &--hide-empty &__body > [data-av-id] .av__row[data-empty="true"]:not([data-primary="true"]) {+ display: none;+ }++ &__tabs {+ align-items: center;+ display: flex;+ gap: 4px;+ margin: 0 8px 4px;+ max-width: 100%;+ overflow-x: auto;+ padding: 4px 0;++ .b3-button {+ flex-shrink: 0;+ max-width: 220px;+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ }+ }+&__body > [data-type="NodeAttributeView"] > .fn__hr--b {display: none;}- .custom-attr__avheader {- padding-left: 40px;+}++.protyle-db-attr__body,+.protyle-db-row__body {+ container-type: inline-size;++ & > [data-av-id] {+ display: grid;+ gap: 0 24px;+ grid-template-columns: repeat(2, minmax(0, 1fr));++ .custom-attr__avheader,+ .fn__hr,+ .b3-button[data-type="addColumn"],+ .fn__hr--b {+ grid-column: 1 / -1;+ }+ }++ & > [data-av-id] {+ .custom-attr__avheader {+ padding-left: 0;+ }++ .block__icons {+ padding-left: 0;+ position: relative;+ }++ .block__icons > .block__icon:first-child {+ left: -24px;+ position: absolute;+ }++ .block__logo:not(.popover__block) {+ margin-left: 0;+ padding-left: 0;+ }++ .b3-button[data-type="addColumn"] {+ margin-left: 0;+ }+ }+}++@container (max-width: 900px) {+ .protyle-db-attr__body > [data-av-id],+ .protyle-db-row__body > [data-av-id] {+ grid-template-columns: minmax(0, 1fr);}}diff --git a/app/src/editor/databaseRow.ts b/app/src/editor/databaseRow.tsindex 1cbbf3c86d..9821da92b0 100644--- a/app/src/editor/databaseRow.ts+++ b/app/src/editor/databaseRow.ts@@ -3,6 +3,7 @@ import {Tab} from "../layout/Tab";import {App} from "../index";import {renderAVAttribute} from "../protyle/render/av/blockAttr";import {Protyle} from "../protyle";+import {getEditorHorizontalPadding} from "../protyle/ui/padding";export const newDatabaseRowModel = (options: {app: App,@@ -19,7 +20,21 @@ export const newDatabaseRowModel = (options: {let customModel: Custom;let contextProtyle: IProtyle;let ghostProtyle: Protyle;+ let resizeObserver: ResizeObserver;let destroyed = false;+ const updateLayout = (custom: Custom) => {+ const width = custom.element.clientWidth;+ const padding = getEditorHorizontalPadding(width, window.siyuan.config.editor.fullWidth);+ const titleElement = custom.element.querySelector<HTMLElement>(".protyle-db-row__title");+ const bodyElement = custom.element.querySelector<HTMLElement>(".protyle-db-row__body");+ if (titleElement) {+ titleElement.style.margin = `16px ${padding.right}px 0 ${padding.left}px`;+ titleElement.style.padding = "8px 0";+ }+ if (bodyElement) {+ bodyElement.style.margin = `8px ${padding.right}px 8px ${padding.left}px`;+ }+ };const render = (custom: Custom) => {const previousBodyElement = custom.element.querySelector<HTMLElement>(".protyle-db-row__body");if (!previousBodyElement || !contextProtyle) {@@ -28,6 +43,7 @@ export const newDatabaseRowModel = (options: {const bodyElement = document.createElement("div");bodyElement.className = "custom-attr protyle-db-row__body";previousBodyElement.replaceWith(bodyElement);+ updateLayout(custom);renderAVAttribute(bodyElement, options.data.itemID, contextProtyle, undefined,{avID: options.data.avID, itemID: options.data.itemID, valueID: options.data.valueID});};@@ -47,6 +63,9 @@ export const newDatabaseRowModel = (options: {</div></div>`;custom.element.querySelector(".protyle-db-row__title span").textContent = options.data.title || window.siyuan.languages.untitled;+ updateLayout(custom);+ resizeObserver = new ResizeObserver(() => updateLayout(custom));+ resizeObserver.observe(custom.element);ghostProtyle = new Protyle(options.app, document.createElement("div"), {blockId: options.data.blockID,notebookId: options.data.notebookId,@@ -61,6 +80,7 @@ export const newDatabaseRowModel = (options: {},destroy() {destroyed = true;+ resizeObserver?.disconnect();ghostProtyle?.destroy();},update() {diff --git a/app/src/protyle/render/av/attributePanel.ts b/app/src/protyle/render/av/attributePanel.tsindex 4b727c108f..7d445df6a9 100644--- a/app/src/protyle/render/av/attributePanel.ts+++ b/app/src/protyle/render/av/attributePanel.ts@@ -7,6 +7,8 @@ export class AVAttributePanel {private targetID = "";private renderToken = 0;private collapsed: boolean;+ private activeAvID = "";+ private hideEmpty = false;constructor(protyle: IProtyle) {this.protyle = protyle;@@ -14,21 +16,33 @@ export class AVAttributePanel {this.element = document.createElement("div");this.element.className = "protyle-db-attr fn__none";this.element.innerHTML = `<button type="button" class="protyle-db-attr__header fn__flex" data-type="toggle" aria-expanded="${!this.collapsed}" aria-label="${window.siyuan.languages.database}">- <span class="block__icon block__icon--show fn__flex-center"><svg><use xlink:href="#iconRight"></use></svg></span>+ <span class="block__icon block__icon--show fn__flex-center"><svg><use xlink:href="#iconPlay"></use></svg></span><span class="block__logo fn__flex-1"><svg class="block__logoicon"><use xlink:href="#iconDatabase"></use></svg><span>${window.siyuan.languages.database}</span></span>+ <span class="block__icon block__icon--show ariaLabel" data-type="hideEmpty" data-position="north" aria-label="${window.siyuan.languages.hideEmptyFields}"><svg><use xlink:href="#iconEye"></use></svg></span></button>`;this.bodyElement = document.createElement("div");this.bodyElement.className = "custom-attr protyle-db-attr__body";this.element.appendChild(this.bodyElement);this.element.addEventListener("click", (event) => {const target = event.target as HTMLElement;- if (target.closest('[data-type="toggle"]')) {+ if (target.closest('[data-type="hideEmpty"]')) {+ this.hideEmpty = !this.hideEmpty;+ this.updateEmptyState();+ event.preventDefault();+ event.stopPropagation();+ } else if (target.closest('[data-type="av-tab"]')) {+ this.activeAvID = (target.closest('[data-type="av-tab"]') as HTMLElement).dataset.id || "";+ this.updateTabs();+ event.preventDefault();+ event.stopPropagation();+ } else if (target.closest('[data-type="toggle"]')) {this.toggle();event.preventDefault();event.stopPropagation();}});this.updateCollapsedState();+ this.updateEmptyState();}public render(force = false) {@@ -49,7 +63,9 @@ export class AVAttributePanel {return;}this.element.dataset.rendered = "true";- this.element.classList.toggle("fn__none", renderedElement.childElementCount === 0);+ this.updateTabs();+ this.updateEmptyState();+ this.element.classList.toggle("fn__none", !renderedElement.querySelector("[data-av-id], .custom-attr__avbacklinks"));});}@@ -61,6 +77,24 @@ export class AVAttributePanel {return Boolean(this.bodyElement.querySelector(`[data-av-id="${avID}"]`));}+ public hasItem(itemID: string) {+ return Boolean(itemID && this.bodyElement.querySelector(`[data-row-id="${itemID}"]`));+ }++ public refreshForOperation(operation: IOperation) {+ if (!operation.avID) {+ return;+ }+ if (operation.action === "insertAttrViewBlock" && operation.srcs?.some(item => item.id === this.targetID)) {+ this.refresh();+ return;+ }+ if (operation.action === "removeAttrViewBlock" &&+ (this.hasDatabase(operation.avID) || operation.srcIDs?.some(item => this.hasItem(item)))) {+ this.refresh();+ }+ }+public expand() {this.collapsed = false;this.updateCollapsedState();@@ -76,6 +110,44 @@ export class AVAttributePanel {const toggleElement = this.element.querySelector('[data-type="toggle"]');toggleElement?.setAttribute("aria-expanded", (!this.collapsed).toString());const useElement = toggleElement?.querySelector("use");- useElement?.setAttribute("xlink:href", this.collapsed ? "#iconRight" : "#iconDown");+ useElement?.setAttribute("xlink:href", "#iconPlay");+ useElement?.setAttribute("style", this.collapsed ? "" : "transform:rotate(90deg)");+ }++ private updateTabs() {+ const databaseElements = Array.from(this.bodyElement.querySelectorAll<HTMLElement>(":scope > [data-av-id]"));+ let tabsElement = this.bodyElement.querySelector<HTMLElement>(":scope > .protyle-db-attr__tabs");+ if (databaseElements.length > 1) {+ if (!tabsElement) {+ tabsElement = document.createElement("div");+ tabsElement.className = "protyle-db-attr__tabs";+ this.bodyElement.prepend(tabsElement);+ }+ tabsElement.innerHTML = databaseElements.map(item => {+ const title = item.querySelector(".custom-attr__avheader .block__logo span")?.textContent || window.siyuan.languages.database;+ return `<button type="button" class="b3-button${item.dataset.avId === this.activeAvID ? " b3-button--outline" : ""}" data-type="av-tab" data-id="${item.dataset.avId}">${Lute.EscapeHTMLStr(title)}</button>`;+ }).join("");+ } else {+ tabsElement?.remove();+ }+ if (!databaseElements.some(item => item.dataset.avId === this.activeAvID)) {+ this.activeAvID = databaseElements[0]?.dataset.avId || "";+ }+ databaseElements.forEach(item => {+ item.classList.toggle("fn__none", databaseElements.length > 1 && item.dataset.avId !== this.activeAvID);+ });+ if (tabsElement) {+ tabsElement.querySelectorAll("[data-type=\"av-tab\"]").forEach(item => {+ item.classList.toggle("b3-button--outline", item.getAttribute("data-id") === this.activeAvID);+ });+ }+ }++ private updateEmptyState() {+ this.element.classList.toggle("protyle-db-attr--hide-empty", this.hideEmpty);+ const useElement = this.element.querySelector('[data-type="hideEmpty"] use');+ useElement?.setAttribute("xlink:href", this.hideEmpty ? "#iconEyeoff" : "#iconEye");+ const toggleElement = this.element.querySelector('[data-type="hideEmpty"]');+ toggleElement?.setAttribute("aria-label", this.hideEmpty ? window.siyuan.languages.displayEmptyFields : window.siyuan.languages.hideEmptyFields);}}diff --git a/app/src/protyle/render/av/blockAttr.ts b/app/src/protyle/render/av/blockAttr.tsindex ee8f766d54..d854433e0c 100644--- a/app/src/protyle/render/av/blockAttr.ts+++ b/app/src/protyle/render/av/blockAttr.ts@@ -2,7 +2,7 @@ import {fetchPost} from "../../../util/fetch";import {addCol, getColIconByType} from "./col";import {escapeAriaLabel, escapeAttr, escapeHtml} from "../../../util/escape";import * as dayjs from "dayjs";-import {popTextCell, updateCellsValue} from "./cell";+import {cellValueIsEmpty, popTextCell, updateCellsValue} from "./cell";import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "../../util/hasClosest";import {openEmojiPanel, unicode2Emoji} from "../../../emoji";import {transaction} from "../../wysiwyg/transaction";@@ -18,6 +18,50 @@ import {isBrowser} from "../../../util/functions";import {Constants} from "../../../constants";import {getCompressURL, removeCompressURL} from "../../../util/image";import {openDatabaseRowByData} from "./openDatabaseRow";+import {confirmDialog} from "../../../dialog/confirmDialog";++interface IAVAttributeTableData {+ avID: string;+ blockIDs: string[];+ itemPositions?: {+ viewID: string;+ previousID: string;+ groups?: {+ groupID: string;+ previousID: string;+ }[];+ }[];+ keyValues: {+ key: {+ id: string;+ type: TAVCol;+ };+ values: IAVCellValue[];+ }[];+}++const attributeTableData = new WeakMap<HTMLElement, IAVAttributeTableData>();++const createEmptyAVValue = (keyID: string, type: TAVCol, blockID?: string) => ({+ type,+ keyID,+ blockID,+ block: {id: "", content: ""},+ text: {content: ""},+ number: {content: 0, isNotEmpty: false, formattedContent: ""},+ url: {content: ""},+ phone: {content: ""},+ email: {content: ""},+ template: {content: ""},+ date: {isNotEmpty: false, isNotEmpty2: false},+ created: {isNotEmpty: false},+ updated: {isNotEmpty: false},+ checkbox: {checked: false},+ mSelect: [],+ mAsset: [],+ relation: {blockIDs: [], contents: []},+ rollup: {contents: []},+} as IAVCellValue);export const getAVTemplateHTML = (content: string) => {if (window.siyuan.config.editor.allowHTMLBLockScript) {@@ -204,31 +248,33 @@ export const renderAVAttribute = (element: HTMLElement, id: string, protyle: IPrblockID: string,isDetached?: boolean,type: TAVCol & IAVCellValue- } []+ }[]}[],blockIDs: string[],avID: stringavName: string}) => {+ const primaryValue = table.keyValues.find(item => item.key.type === "block")?.values[0] || table.keyValues[0]?.values[0];let innerHTML = `<div class="custom-attr__avheader"><div class="block__logo block__logo--icon popover__block" style="max-width:calc(100% - 40px)" data-id='${JSON.stringify(table.blockIDs)}'><svg class="block__logoicon"><use xlink:href="#iconDatabase"></use></svg><span class="fn__ellipsis">${table.avName || window.siyuan.languages.database}</span></div><div class="fn__flex-1"></div>- <span data-type="remove" data-row-id="${table.keyValues && table.keyValues[0].values[0].blockID}" class="block__icon block__icon--warning block__icon--show b3-tooltips__w b3-tooltips" aria-label="${window.siyuan.languages.removeAV}"><svg><use xlink:href="#iconTrashcan"></use></svg></span>+ <span data-type="remove" data-row-id="${primaryValue?.blockID || ""}" class="block__icon block__icon--warning block__icon--show b3-tooltips__w b3-tooltips" aria-label="${window.siyuan.languages.removeAV}"><svg><use xlink:href="#iconTrashcan"></use></svg></span></div>`;table.keyValues?.forEach(item => {- innerHTML += `<div class="block__icons av__row" data-id="${id}" data-col-id="${item.key.id}">+ const value = item.values[0] || createEmptyAVValue(item.key.id, item.key.type, primaryValue?.blockID);+ innerHTML += `<div class="block__icons av__row" data-id="${id}" data-col-id="${item.key.id}" data-empty="${cellValueIsEmpty(value)}"${item.key.type === "block" ? ' data-primary="true"' : ""}><div class="block__icon" draggable="true"><svg><use xlink:href="#iconDrag"></use></svg></div><div class="block__logo block__logo--icon ariaLabel fn__pointer" data-type="editCol" data-position="parentW" aria-label="${escapeAriaLabel(item.key.name)}<div class='ft__on-surface'>${escapeAriaLabel(item.key.desc)}</div>">${item.key.icon ? unicode2Emoji(item.key.icon, "block__logoicon", true) : `<svg class="block__logoicon"><use xlink:href="#${getColIconByType(item.key.type)}"></use></svg>`}<span>${escapeHtml(item.key.name)}</span></div>- <div data-av-id="${table.avID}" data-col-id="${item.values[0].keyID}" data-row-id="${item.values[0].blockID}" data-id="${item.values[0].id}" data-type="${item.values[0].type}"${item.values[0].isDetached ? ' data-detached="true"' : ""}-data-options="${item.key?.options ? escapeAttr(JSON.stringify(item.key.options)) : "[]"}"-${["text", "number", "date", "url", "phone", "template", "email"].includes(item.values[0].type) ? "" : `placeholder="${window.siyuan.languages.empty}"`}-class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone", "block"].includes(item.values[0].type) ? "" : " custom-attr__avvalue"}${["created", "updated"].includes(item.values[0].type) ? " custom-attr__avvalue--readonly" : ""}">${genAVValueHTML(item.values[0])}</div>+ <div data-av-id="${table.avID}" data-col-id="${value.keyID}" data-row-id="${value.blockID}" data-id="${value.id}" data-type="${value.type}"${value.isDetached ? ' data-detached="true"' : ""}+data-options="${item.key?.options ? escapeAttr(JSON.stringify(item.key.options)) : "[]"}"+${["text", "number", "date", "url", "phone", "template", "email"].includes(value.type) ? "" : `placeholder="${window.siyuan.languages.empty}"`}+class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone", "block"].includes(value.type) ? "" : " custom-attr__avvalue"}${["created", "updated"].includes(value.type) ? " custom-attr__avvalue--readonly" : ""}">${genAVValueHTML(value)}</div></div>`;});innerHTML += `<div class="fn__hr"></div>@@ -419,24 +465,86 @@ class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone", "block"]if (removeElement) {const blockElement = hasClosestBlock(removeElement);if (blockElement) {- transaction(protyle, [{+ const table = attributeTableData.get(blockElement as HTMLElement);+ const rowID = removeElement.dataset.rowId;+ const avID = blockElement.dataset.avId;+ const primaryKeyValues = table?.keyValues.find(item => item.key.type === "block");+ const primaryValue = primaryKeyValues?.values.find(item => item.blockID === rowID) || primaryKeyValues?.values[0];+ if (!table || !rowID || !avID || !primaryValue || !table.blockIDs[0]) {+ event.stopPropagation();+ return;+ }+ const isDetached = primaryValue?.isDetached === true || !primaryValue?.block?.id;+ const restoreBlockID = primaryValue?.block?.id || Lute.NewNodeID();+ const undoOperations: IOperation[] = [];+ undoOperations.push({+ action: "insertAttrViewBlock",+ avID,+ blockID: table.blockIDs[0],+ ignoreDefaultFill: true,+ srcs: [{+ itemID: rowID,+ id: restoreBlockID,+ isDetached,+ content: primaryValue.block?.content || "",+ }],+ });+ table.keyValues.forEach(item => {+ const value = item.values.find(itemValue => itemValue.blockID === rowID) || item.values[0];+ if (!value || item.key.type === "rollup") {+ return;+ }+ const valueData = JSON.parse(JSON.stringify(value)) as IAVCellValue;+ undoOperations.push({+ action: "updateAttrViewCell",+ avID,+ keyID: item.key.id,+ rowID,+ data: valueData,+ });+ });+ table.itemPositions?.forEach(position => {+ undoOperations.push({+ action: "sortAttrViewRow",+ avID,+ viewID: position.viewID,+ id: rowID,+ previousID: position.previousID,+ });+ position.groups?.forEach(group => {+ undoOperations.push({+ action: "sortAttrViewRow",+ avID,+ viewID: position.viewID,+ id: rowID,+ previousID: group.previousID,+ groupID: group.groupID,+ targetGroupID: group.groupID,+ });+ });+ });+ const doOperations: IOperation[] = [{action: "removeAttrViewBlock",- srcIDs: [removeElement.dataset.rowId],- avID: blockElement.dataset.avId,- }, {- action: "doUpdateUpdated",- id: removeElement.dataset.rowId,- data: dayjs().format("YYYYMMDDHHmmss"),- }]);- blockElement.remove();- if (!element.innerHTML) {- window.siyuan.dialogs.find(item => {- if (item.element.getAttribute("data-key") === Constants.DIALOG_ATTR) {- item.destroy();- return true;+ srcIDs: [rowID],+ avID,+ }];+ confirmDialog(window.siyuan.languages.removeAV, window.siyuan.languages.confirmDelete + "?", () => {+ removeElement.setAttribute("disabled", "true");+ transaction(protyle, doOperations, undoOperations.length > 0 ? undoOperations : undefined, {+ callback: () => {+ blockElement.remove();+ protyle.databaseAttributePanel?.refresh();+ if (!element.querySelector("[data-av-id]")) {+ window.siyuan.dialogs.find(item => {+ if (item.element.getAttribute("data-key") === Constants.DIALOG_ATTR) {+ item.destroy();+ return true;+ }+ });+ }}});- }+ }, undefined, true);}event.stopPropagation();return;@@ -448,6 +556,12 @@ class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone", "block"]});element.innerHTML = html;}+ tables.forEach((table: IAVAttributeTableData) => {+ const blockElement = element.querySelector<HTMLElement>(`[data-node-id="${id}"][data-av-id="${table.avID}"]`);+ if (blockElement) {+ attributeTableData.set(blockElement, table);+ }+ });element.querySelectorAll(".b3-text-field--text").forEach((item: HTMLInputElement) => {item.addEventListener("change", () => {let value;diff --git a/app/src/protyle/ui/initUI.ts b/app/src/protyle/ui/initUI.tsindex 2ffb05148b..f698307b48 100644--- a/app/src/protyle/ui/initUI.ts+++ b/app/src/protyle/ui/initUI.ts@@ -24,6 +24,7 @@ import {} from "../util/hasClosest";import {hideElements} from "./hideElements";import {AVAttributePanel} from "../render/av/attributePanel";+import {getEditorHorizontalPadding} from "./padding";export const initUI = (protyle: IProtyle) => {protyle.contentElement = document.createElement("div");@@ -364,19 +365,9 @@ export const getPadding = (protyle: IProtyle) => {if (!isFullWidth) {isFullWidth = window.siyuan.config.editor.fullWidth ? "true" : "false";}- let padding = (protyle.element.clientWidth - Constants.SIZE_EDITOR_WIDTH) / 2;- if (isFullWidth === "false" && padding > 96) {- if (padding > Constants.SIZE_EDITOR_WIDTH) {- // 超宽屏调整 https://ld246.com/article/1668266637363- padding = protyle.element.clientWidth * .382 / 1.382;- }- padding = Math.ceil(padding);- left = padding;- right = padding;- } else if (protyle.element.clientWidth > Constants.SIZE_EDITOR_WIDTH) {- left = 96;- right = 96;- }+ const padding = getEditorHorizontalPadding(protyle.element.clientWidth, isFullWidth !== "false");+ left = padding.left;+ right = padding.right;}return {left, right, bottom, top: 16diff --git a/app/src/protyle/ui/padding.ts b/app/src/protyle/ui/padding.tsnew file mode 100644index 0000000000..a71502902a--- /dev/null+++ b/app/src/protyle/ui/padding.ts@@ -0,0 +1,20 @@+import {Constants} from "../../constants";++/** 计算编辑器内容区域的水平边距。 */+export const getEditorHorizontalPadding = (width: number, fullWidth: boolean) => {+ let left = 24;+ let right = 16;+ let padding = (width - Constants.SIZE_EDITOR_WIDTH) / 2;+ if (!fullWidth && padding > 96) {+ if (padding > Constants.SIZE_EDITOR_WIDTH) {+ padding = width * .382 / 1.382;+ }+ padding = Math.ceil(padding);+ left = padding;+ right = padding;+ } else if (width > Constants.SIZE_EDITOR_WIDTH) {+ left = 96;+ right = 96;+ }+ return {left, right};+};diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.tsindex 16a8652579..179c2e25ef 100644--- a/app/src/protyle/wysiwyg/transaction.ts+++ b/app/src/protyle/wysiwyg/transaction.ts@@ -1130,6 +1130,7 @@ export const onTransaction = (protyle: IProtyle, operations: IOperation[], isUnd"foldAttrViewGroup", "hideAttrViewAllGroups", "setAttrViewFitImage", "setAttrViewDisplayFieldName","insertAttrViewBlock", "setAttrViewColDateFillSpecificTime", "setAttrViewFillColBackgroundColor", "setAttrViewUpdatedIncludeTime","setAttrViewCreatedIncludeTime"].includes(operation.action)) {+ protyle.databaseAttributePanel?.refreshForOperation(operation);// 撤销 transaction 会进行推送,需使用推送来进行刷新最新数据 https://github.com/siyuan-note/siyuan/issues/13607if (!isUndo) {refreshAV(protyle, operation);diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.goindex aed1feaf60..0eec4c8431 100644--- a/kernel/model/attribute_view.go+++ b/kernel/model/attribute_view.go@@ -2072,10 +2072,57 @@ func SearchAttributeView(keyword string, excludeAvIDs []string, currentAvID, cur}type BlockAttributeViewKeys struct {- AvID string `json:"avID"`- AvName string `json:"avName"`- BlockIDs []string `json:"blockIDs"`- KeyValues []*av.KeyValues `json:"keyValues"`+ AvID string `json:"avID"`+ AvName string `json:"avName"`+ BlockIDs []string `json:"blockIDs"`+ KeyValues []*av.KeyValues `json:"keyValues"`+ ItemPositions []*AttributeViewItemPosition `json:"itemPositions"`+}++type AttributeViewItemPosition struct {+ ViewID string `json:"viewID"`+ PreviousID string `json:"previousID"`+ Groups []*AttributeViewGroupItemPosition `json:"groups"`+}++type AttributeViewGroupItemPosition struct {+ GroupID string `json:"groupID"`+ PreviousID string `json:"previousID"`+}++func getAttributeViewItemPositions(attrView *av.AttributeView, itemID string) (ret []*AttributeViewItemPosition) {+ for _, view := range attrView.Views {+ previousID, found := getAttributeViewPreviousItemID(view.ItemIDs, itemID)+ if !found {+ continue+ }++ position := &AttributeViewItemPosition{ViewID: view.ID, PreviousID: previousID}+ for _, group := range view.Groups {+ groupPreviousID, groupFound := getAttributeViewPreviousItemID(group.GroupItemIDs, itemID)+ if groupFound {+ position.Groups = append(position.Groups, &AttributeViewGroupItemPosition{+ GroupID: group.ID, PreviousID: groupPreviousID,+ })+ }+ }+ ret = append(ret, position)+ }+ return+}++func getAttributeViewPreviousItemID(itemIDs []string, itemID string) (previousID string, found bool) {+ for i, currentID := range itemIDs {+ if currentID != itemID {+ continue+ }+ if 0 < i {+ previousID = itemIDs[i-1]+ }+ found = true+ return+ }+ return}type AttributeViewBacklinkRelation struct {@@ -2381,10 +2428,11 @@ func GetAttributeViewItemKeys(avID, itemID, valueID string) (ret []*BlockAttribu})ret = append(ret, &BlockAttributeViewKeys{- AvID: avID,- AvName: getAttrViewName(attrView),- BlockIDs: treenode.GetMirrorAttrViewBlockIDs(avID),- KeyValues: keyValues,+ AvID: avID,+ AvName: getAttrViewName(attrView),+ BlockIDs: treenode.GetMirrorAttrViewBlockIDs(avID),+ KeyValues: keyValues,+ ItemPositions: getAttributeViewItemPositions(attrView, itemID),})return}@@ -2501,10 +2549,11 @@ func GetBlockAttributeViewKeys(nodeID string) (ret []*BlockAttributeViewKeys) {}ret = append(ret, &BlockAttributeViewKeys{- AvID: avID,- AvName: getAttrViewName(attrView),- BlockIDs: blockIDs,- KeyValues: keyValues,+ AvID: avID,+ AvName: getAttrViewName(attrView),+ BlockIDs: blockIDs,+ KeyValues: keyValues,+ ItemPositions: getAttributeViewItemPositions(attrView, itemID),})}return@@ -4932,9 +4981,17 @@ func sortAttributeViewRow(operation *Operation) (err error) {return}- view, err := getAttrViewViewByBlockID(attrView, operation.BlockID)- if err != nil {- return+ var view *av.View+ if "" != operation.ViewID {+ view = attrView.GetView(operation.ViewID)+ if nil == view {+ return av.ErrViewNotFound+ }+ } else {+ view, err = getAttrViewViewByBlockID(attrView, operation.BlockID)+ if err != nil {+ return+ }}var itemID stringdiff --git a/kernel/model/publish_access.go b/kernel/model/publish_access.goindex 4d79191e7f..a04b8cfc0d 100644--- a/kernel/model/publish_access.go+++ b/kernel/model/publish_access.go@@ -420,6 +420,7 @@ func FilterBlockAttributeViewKeysByPublishAccess(c *gin.Context, publishAccess P}}if accessable {+ blockAttributeViewKey.ItemPositions = nilret = append(ret, blockAttributeViewKey)}}