Browse Source

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

Vanessa 1 year ago
parent
commit
220e0b137f

+ 1 - 0
app/src/constants.ts

@@ -58,6 +58,7 @@ export abstract class Constants {
     // custom
     public static readonly CUSTOM_SY_READONLY: string = "custom-sy-readonly";
     public static readonly CUSTOM_SY_FULLWIDTH: string = "custom-sy-fullwidth";
+    public static readonly CUSTOM_SY_AV_VIEW: string = "custom-sy-av-view";
     public static readonly CUSTOM_REMINDER_WECHAT: string = "custom-reminder-wechat";
     public static readonly CUSTOM_RIFF_DECKS: string = "custom-riff-decks";
 

+ 1 - 0
app/src/protyle/render/av/asset.ts

@@ -341,6 +341,7 @@ export const dragUpload = (files: string[], protyle: IProtyle, cellElement: HTML
             fetchPost("/api/av/renderAttributeView", {
                 id: avID,
                 pageSize: parseInt(blockElement.getAttribute("data-page-size")) || undefined,
+                viewID: blockElement.getAttribute(Constants.CUSTOM_SY_AV_VIEW)
             }, (response) => {
                 updateAssetCell({
                     protyle,

+ 4 - 1
app/src/protyle/render/av/cell.ts

@@ -335,7 +335,10 @@ export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[], type
         inputElement.select();
         inputElement.focus();
         if (type === "template") {
-            fetchPost("/api/av/renderAttributeView", {id: blockElement.dataset.avId}, (response) => {
+            fetchPost("/api/av/renderAttributeView", {
+                id: blockElement.dataset.avId,
+                viewID: blockElement.getAttribute(Constants.CUSTOM_SY_AV_VIEW)
+            }, (response) => {
                 response.data.view.columns.find((item: IAVColumn) => {
                     if (item.id === cellElements[0].dataset.colId) {
                         inputElement.value = item.template;

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

@@ -10,6 +10,7 @@ import {openEmojiPanel, unicode2Emoji} from "../../../emoji";
 import {focusBlock} from "../../util/selection";
 import {toggleUpdateRelationBtn} from "./relation";
 import {bindRollupData, getRollupHTML} from "./rollup";
+import {Constants} from "../../../constants";
 
 export const duplicateCol = (options: {
     protyle: IProtyle,
@@ -18,6 +19,7 @@ export const duplicateCol = (options: {
     colId: string,
     newValue: string,
     icon: string
+    viewID: string
 }) => {
     const id = Lute.NewNodeID();
     const nameMatch = options.newValue.match(/^(.*) \((\d+)\)$/);
@@ -27,7 +29,10 @@ export const duplicateCol = (options: {
         options.newValue = `${options.newValue} (1)`;
     }
     if (["select", "mSelect", "rollup"].includes(options.type)) {
-        fetchPost("/api/av/renderAttributeView", {id: options.avID}, (response) => {
+        fetchPost("/api/av/renderAttributeView", {
+            id: options.avID,
+            viewID: options.viewID
+        }, (response) => {
             const data = response.data as IAV;
             let colOptions;
             data.view.columns.find((item) => {
@@ -747,6 +752,7 @@ export const showColMenu = (protyle: IProtyle, blockElement: Element, cellElemen
                 label: window.siyuan.languages.duplicate,
                 click() {
                     duplicateCol({
+                        viewID: blockElement.getAttribute(Constants.CUSTOM_SY_AV_VIEW),
                         protyle,
                         type,
                         avID,

+ 4 - 2
app/src/protyle/render/av/openMenuPanel.ts

@@ -55,6 +55,7 @@ export const openMenuPanel = (options: {
     fetchPost("/api/av/renderAttributeView", {
         id: avID,
         pageSize: parseInt(options.blockElement.getAttribute("data-page-size")) || undefined,
+        viewID: options.blockElement.getAttribute(Constants.CUSTOM_SY_AV_VIEW)
     }, (response) => {
         const isCustomAttr = !options.blockElement.classList.contains("av");
         const data = response.data as IAV;
@@ -714,7 +715,7 @@ export const openMenuPanel = (options: {
                         id,
                         blockID
                     }]);
-                    options.blockElement.setAttribute("custom-sy-av-view", id)
+                    options.blockElement.setAttribute(Constants.CUSTOM_SY_AV_VIEW, id)
                     avPanelElement.remove();
                     event.preventDefault();
                     event.stopPropagation();
@@ -995,7 +996,8 @@ export const openMenuPanel = (options: {
                         avID,
                         colId,
                         icon: colData.icon,
-                        newValue: colData.name
+                        newValue: colData.name,
+                        viewID: data.viewID,
                     });
                     avPanelElement.remove();
                     event.preventDefault();

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

@@ -49,18 +49,18 @@ export const avRender = (element: Element, protyle: IProtyle, cb?: () => void, v
             }
             const created = protyle.options.history?.created;
             const snapshot = protyle.options.history?.snapshot;
-            let newViewID = e.getAttribute("custom-sy-av-view") || "";
+            let newViewID = e.getAttribute(Constants.CUSTOM_SY_AV_VIEW) || "";
             if (typeof viewID === "string") {
                 newViewID = viewID;
                 fetchPost("/api/av/setDatabaseBlockView", {id: e.dataset.nodeId, viewID});
-                e.setAttribute("custom-sy-av-view", newViewID);
+                e.setAttribute(Constants.CUSTOM_SY_AV_VIEW, newViewID);
             }
             fetchPost(created ? "/api/av/renderHistoryAttributeView" : (snapshot ? "/api/av/renderSnapshotAttributeView" : "/api/av/renderAttributeView"), {
                 id: e.getAttribute("data-av-id"),
                 created,
                 snapshot,
                 pageSize: parseInt(e.dataset.pageSize) || undefined,
-                viewID: newViewID || e.getAttribute("custom-sy-av-view")
+                viewID: newViewID
             }, (response) => {
                 const data = response.data.view as IAVTable;
                 if (!e.dataset.pageSize) {

+ 3 - 2
app/src/protyle/render/av/view.ts

@@ -4,6 +4,7 @@ import {transaction} from "../../wysiwyg/transaction";
 import {openMenuPanel} from "./openMenuPanel";
 import {removeBlock} from "../../wysiwyg/remove";
 import {getEditorRange} from "../../util/selection";
+import {Constants} from "../../../constants";
 
 export const openViewMenu = (options: { protyle: IProtyle, blockElement: HTMLElement, element: HTMLElement }) => {
     const menu = new Menu("av-view");
@@ -56,7 +57,7 @@ export const openViewMenu = (options: { protyle: IProtyle, blockElement: HTMLEle
                 id,
                 blockID: options.blockElement.dataset.nodeId
             }]);
-            options.blockElement.setAttribute("custom-sy-av-view", id)
+            options.blockElement.setAttribute(Constants.CUSTOM_SY_AV_VIEW, id)
         }
     });
     menu.addItem({
@@ -210,5 +211,5 @@ export const addView = (protyle: IProtyle, blockElement: Element) => {
         id,
         blockID: blockElement.getAttribute("data-node-id")
     }]);
-    blockElement.setAttribute("custom-sy-av-view", id);
+    blockElement.setAttribute(Constants.CUSTOM_SY_AV_VIEW, id);
 };