瀏覽代碼

:art: https://github.com/siyuan-note/siyuan/issues/9888

Vanessa 1 年之前
父節點
當前提交
23c9cbae9c
共有 3 個文件被更改,包括 33 次插入11 次删除
  1. 7 2
      app/src/protyle/render/av/col.ts
  2. 3 1
      app/src/protyle/render/av/openMenuPanel.ts
  3. 23 8
      app/src/protyle/render/av/relation.ts

+ 7 - 2
app/src/protyle/render/av/col.ts

@@ -149,7 +149,7 @@ export const getEditHTML = (options: {
 </button>`;
 </button>`;
     } else if (colData.type === "relation") {
     } else if (colData.type === "relation") {
         const isSelf = colData.relation?.avID === options.data.id;
         const isSelf = colData.relation?.avID === options.data.id;
-        html += `<button class="b3-menu__item" data-type="goSearchAV" data-av-id="${colData.relation?.avID}" data-old-value='${JSON.stringify(colData.relation || {})}'>
+        html += `<button class="b3-menu__item" data-type="goSearchAV" data-av-id="${colData.relation?.avID || ""}" data-old-value='${JSON.stringify(colData.relation || {})}'>
     <span class="b3-menu__label">${window.siyuan.languages.relatedTo}</span>
     <span class="b3-menu__label">${window.siyuan.languages.relatedTo}</span>
     <span class="b3-menu__accelerator">${isSelf ? window.siyuan.languages.thisDatabase : ""}</span>
     <span class="b3-menu__accelerator">${isSelf ? window.siyuan.languages.thisDatabase : ""}</span>
     <svg class="b3-menu__icon b3-menu__icon--small"><use xlink:href="#iconRight"></use></svg>
     <svg class="b3-menu__icon b3-menu__icon--small"><use xlink:href="#iconRight"></use></svg>
@@ -219,6 +219,9 @@ export const bindEditEvent = (options: {
     const colData = options.data.view.columns.find((item: IAVColumn) => item.id === colId);
     const colData = options.data.view.columns.find((item: IAVColumn) => item.id === colId);
     const nameElement = options.menuElement.querySelector('[data-type="name"]') as HTMLInputElement;
     const nameElement = options.menuElement.querySelector('[data-type="name"]') as HTMLInputElement;
     nameElement.addEventListener("blur", () => {
     nameElement.addEventListener("blur", () => {
+        if (colData.type === "relation") {
+            return;
+        }
         const newValue = nameElement.value;
         const newValue = nameElement.value;
         if (newValue === colData.name) {
         if (newValue === colData.name) {
             return;
             return;
@@ -352,7 +355,6 @@ export const bindEditEvent = (options: {
                 toggleUpdateRelationBtn(options.menuElement, avID);
                 toggleUpdateRelationBtn(options.menuElement, avID);
             });
             });
         } else {
         } else {
-            openSearchAV(avID, goSearchElement);
             toggleUpdateRelationBtn(options.menuElement, avID);
             toggleUpdateRelationBtn(options.menuElement, avID);
         }
         }
     }
     }
@@ -468,6 +470,9 @@ export const showColMenu = (protyle: IProtyle, blockElement: Element, cellElemen
     const avID = blockElement.getAttribute("data-av-id");
     const avID = blockElement.getAttribute("data-av-id");
     const oldValue = cellElement.querySelector(".av__celltext").textContent.trim();
     const oldValue = cellElement.querySelector(".av__celltext").textContent.trim();
     const menu = new Menu("av-header-cell", () => {
     const menu = new Menu("av-header-cell", () => {
+        if (type === "relation") {
+            return;
+        }
         const newValue = (window.siyuan.menus.menu.element.querySelector(".b3-text-field") as HTMLInputElement).value;
         const newValue = (window.siyuan.menus.menu.element.querySelector(".b3-text-field") as HTMLInputElement).value;
         if (newValue === oldValue) {
         if (newValue === oldValue) {
             return;
             return;

+ 3 - 1
app/src/protyle/render/av/openMenuPanel.ts

@@ -766,7 +766,9 @@ export const openMenuPanel = (options: {
                     updateRelation({
                     updateRelation({
                         protyle: options.protyle,
                         protyle: options.protyle,
                         avElement: avPanelElement,
                         avElement: avPanelElement,
-                        avID
+                        avID,
+                        colsData: data.view.columns,
+                        blockElement: options.blockElement,
                     });
                     });
                     event.preventDefault();
                     event.preventDefault();
                     event.stopPropagation();
                     event.stopPropagation();

+ 23 - 8
app/src/protyle/render/av/relation.ts

@@ -5,6 +5,8 @@ import {fetchPost} from "../../../util/fetch";
 import {escapeHtml} from "../../../util/escape";
 import {escapeHtml} from "../../../util/escape";
 import {transaction} from "../../wysiwyg/transaction";
 import {transaction} from "../../wysiwyg/transaction";
 import {updateCellsValue} from "./cell";
 import {updateCellsValue} from "./cell";
+import {updateAttrViewCellAnimation} from "./action";
+import {focusBlock} from "../../util/selection";
 
 
 const genSearchList = (element: Element, keyword: string, avId: string, cb?: () => void) => {
 const genSearchList = (element: Element, keyword: string, avId: string, cb?: () => void) => {
     fetchPost("/api/av/searchAttributeView", {keyword}, (response) => {
     fetchPost("/api/av/searchAttributeView", {keyword}, (response) => {
@@ -102,31 +104,44 @@ export const openSearchAV = (avId: string, target: HTMLElement) => {
 export const updateRelation = (options: {
 export const updateRelation = (options: {
     protyle: IProtyle,
     protyle: IProtyle,
     avID: string,
     avID: string,
-    avElement: Element
+    avElement: Element,
+    colsData: IAVColumn[],
+    blockElement: Element,
 }) => {
 }) => {
     const inputElement = options.avElement.querySelector('input[data-type="colName"]') as HTMLInputElement;
     const inputElement = options.avElement.querySelector('input[data-type="colName"]') as HTMLInputElement;
     const goSearchAVElement = options.avElement.querySelector('.b3-menu__item[data-type="goSearchAV"]') as HTMLElement;
     const goSearchAVElement = options.avElement.querySelector('.b3-menu__item[data-type="goSearchAV"]') as HTMLElement;
-    const oldValue = JSON.parse(goSearchAVElement.dataset.oldValue) as IAVCellRelationValue;
     const newAVId = goSearchAVElement.getAttribute("data-av-id")
     const newAVId = goSearchAVElement.getAttribute("data-av-id")
     const colId = options.avElement.querySelector(".b3-menu__item").getAttribute("data-col-id")
     const colId = options.avElement.querySelector(".b3-menu__item").getAttribute("data-col-id")
+    let colData: IAVColumn;
+    options.colsData.find(item => {
+        if (item.id === colId) {
+            colData = item
+            return true;
+        }
+    })
+    const colNewName = (options.avElement.querySelector('[data-type="name"]') as HTMLInputElement).value;
     transaction(options.protyle, [{
     transaction(options.protyle, [{
         action: "updateAttrViewColRelation",
         action: "updateAttrViewColRelation",
         avID: options.avID,
         avID: options.avID,
         keyID: colId,
         keyID: colId,
-        id: newAVId || oldValue.avID,
-        backRelationKeyID: oldValue.avID === newAVId ? oldValue.backKeyID : Lute.NewNodeID(),
+        id: newAVId || colData.relation.avID,
+        backRelationKeyID: colData.relation.avID === newAVId ? colData.relation.backKeyID : Lute.NewNodeID(),
         isTwoWay: (options.avElement.querySelector(".b3-switch") as HTMLInputElement).checked,
         isTwoWay: (options.avElement.querySelector(".b3-switch") as HTMLInputElement).checked,
         name: inputElement.value,
         name: inputElement.value,
+        format: colNewName
     }], [{
     }], [{
         action: "updateAttrViewColRelation",
         action: "updateAttrViewColRelation",
         avID: options.avID,
         avID: options.avID,
         keyID: colId,
         keyID: colId,
-        id: oldValue.avID,
-        backRelationKeyID: oldValue.backKeyID,
-        isTwoWay: oldValue.isTwoWay,
-        name: inputElement.dataset.oldValue
+        id: colData.relation.avID,
+        backRelationKeyID: colData.relation.backKeyID,
+        isTwoWay: colData.relation.isTwoWay,
+        name: inputElement.dataset.oldValue,
+        format: colData.name
     }]);
     }]);
     options.avElement.remove();
     options.avElement.remove();
+    updateAttrViewCellAnimation(options.blockElement.querySelector(`.av__row--header .av__cell[data-col-id="${colId}"]`), undefined, {name: colNewName});
+    focusBlock(options.blockElement);
 }
 }
 
 
 export const toggleUpdateRelationBtn = (menuItemsElement: HTMLElement, avId: string, resetData = false) => {
 export const toggleUpdateRelationBtn = (menuItemsElement: HTMLElement, avId: string, resetData = false) => {