Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve editor database attribute panel https://github.com/siyuan-note/siyuan/issues/18340

Danielec24aeeabdc8
diff --git a/app/src/assets/scss/business/_custom.scss b/app/src/assets/scss/business/_custom.scss
index 9125e675e0..0fbabe32a2 100644
--- a/app/src/assets/scss/business/_custom.scss
+++ b/app/src/assets/scss/business/_custom.scss
@@ -272,11 +272,6 @@
}
&__tabs {
- background-color: transparent;
- margin: 0 8px 4px;
- max-width: 100%;
- padding: 0;
-
.item {
background-color: transparent;
border: 0;
diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.ts
index 1bc4918f4b..7276145145 100644
--- a/app/src/protyle/render/av/action.ts
+++ b/app/src/protyle/render/av/action.ts
@@ -962,12 +962,54 @@ export const updateAttrViewCellAnimation = (cellElement: HTMLElement, value: IAV
}
};
-export const removeAttrViewColAnimation = (blockElement: Element, id: string) => {
- blockElement.querySelectorAll(`.av__cell[data-col-id="${id}"]`).forEach(item => {
- item.remove();
+export const updateAttrViewColAnimation = (protyle: IProtyle, avID: string, colID: string, headerValue: {
+ icon?: string,
+ name?: string,
+ pin?: boolean,
+ type?: TAVCol
+}) => {
+ protyle.wysiwyg.element.querySelectorAll<HTMLElement>(
+ `.av[data-av-id="${avID}"] .av__row--header .av__cell[data-col-id="${colID}"]`
+ ).forEach(item => {
+ updateAttrViewCellAnimation(item, undefined, headerValue);
+ });
+ document.querySelectorAll<HTMLElement>(
+ `.custom-attr [data-av-id="${avID}"] > .av__row[data-col-id="${colID}"]`
+ ).forEach(item => {
+ if (typeof headerValue.name !== "undefined") {
+ const nameElement = item.querySelector(".block__logo span");
+ if (nameElement) {
+ nameElement.textContent = headerValue.name;
+ }
+ }
+ if (typeof headerValue.icon !== "undefined") {
+ const iconElement = item.querySelector(".block__logoicon");
+ const type = item.querySelector<HTMLElement>(":scope > [data-type][data-col-id]")?.dataset.type as TAVCol;
+ if (iconElement && type) {
+ iconElement.outerHTML = headerValue.icon ?
+ unicode2Emoji(headerValue.icon, "block__logoicon", true) :
+ `<svg class="block__logoicon"><use xlink:href="#${getColIconByType(type)}"></use></svg>`;
+ }
+ }
});
};
+export const removeAttrViewColAnimation = (blockElement: Element, id: string) => {
+ const avID = blockElement.getAttribute("data-av-id");
+ if (avID) {
+ document.querySelectorAll(`.av[data-av-id="${avID}"] .av__cell[data-col-id="${id}"]`).forEach(item => {
+ item.remove();
+ });
+ document.querySelectorAll(`.custom-attr [data-av-id="${avID}"] > .av__row[data-col-id="${id}"]`).forEach(item => {
+ item.remove();
+ });
+ } else {
+ blockElement.querySelectorAll(`.av__cell[data-col-id="${id}"]`).forEach(item => {
+ item.remove();
+ });
+ }
+};
+
export const duplicateCompletely = (protyle: IProtyle, nodeElement: HTMLElement) => {
fetchPost("/api/av/duplicateAttributeViewBlock", {avID: nodeElement.getAttribute("data-av-id")}, (response) => {
nodeElement.classList.remove("protyle-wysiwyg--select");
diff --git a/app/src/protyle/render/av/asset.ts b/app/src/protyle/render/av/asset.ts
index 322e6b9198..ebbe1f2f1a 100644
--- a/app/src/protyle/render/av/asset.ts
+++ b/app/src/protyle/render/av/asset.ts
@@ -10,11 +10,11 @@ import {MenuItem} from "../../../menus/Menu";
import {copyPNGByLink, exportAsset, writeAssetToClipboard} from "../../../menus/util";
import {setPosition} from "../../../util/setPosition";
import {previewAttrViewImages} from "../../preview/image";
-import {genAVValueHTML} from "./blockAttr";
+import {genAVValueHTML} from "./attributeValue";
import {hideMessage, showMessage} from "../../../dialog/message";
import {fetchPost} from "../../../util/fetch";
import {hasClosestBlock} from "../../util/hasClosest";
-import {genCellValueByElement, getTypeByCellElement} from "./cell";
+import {genCellValueByElement, getTypeByCellElement, updateAttrViewCellInOtherElements} from "./cell";
import {writeText} from "../../util/compatibility";
import {escapeAriaLabel, escapeAttr, escapeHtml} from "../../../util/escape";
import {renameAsset} from "../../../editor/rename";
@@ -166,6 +166,7 @@ export const updateAssetCell = (options: {
} else {
updateAttrViewCellAnimation(item, cellValue);
}
+ updateAttrViewCellInOtherElements(options.protyle, avID, rowID, colId, cellValue, item);
});
cellDoOperations.push({
action: "doUpdateUpdated",
diff --git a/app/src/protyle/render/av/attributePanel.ts b/app/src/protyle/render/av/attributePanel.ts
index c78699c09f..ed5ef95c06 100644
--- a/app/src/protyle/render/av/attributePanel.ts
+++ b/app/src/protyle/render/av/attributePanel.ts
@@ -112,9 +112,13 @@ export class AVAttributePanel {
}
}
- public expand() {
+ public expand(avID?: string) {
+ if (avID) {
+ this.activeAvID = avID;
+ }
this.collapsed = false;
this.updateCollapsedState();
+ this.updateTabs();
}
public toggle() {
@@ -147,7 +151,7 @@ export class AVAttributePanel {
} else {
tabsElement?.remove();
}
- if (!databaseElements.some(item => item.dataset.avId === this.activeAvID)) {
+ if (databaseElements.length > 0 && !databaseElements.some(item => item.dataset.avId === this.activeAvID)) {
this.activeAvID = databaseElements[0]?.dataset.avId || "";
}
databaseElements.forEach(item => {
diff --git a/app/src/protyle/render/av/attributeValue.ts b/app/src/protyle/render/av/attributeValue.ts
new file mode 100644
index 0000000000..463fd460d9
--- /dev/null
+++ b/app/src/protyle/render/av/attributeValue.ts
@@ -0,0 +1,212 @@
+import {escapeAriaLabel, escapeAttr, escapeHtml} from "../../../util/escape";
+import * as dayjs from "dayjs";
+import {unicode2Emoji} from "../../../emoji";
+import {Constants} from "../../../constants";
+import {getCompressURL} from "../../../util/image";
+
+export 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) {
+ return content;
+ }
+ // 默认过滤危险标签和事件属性,避免数据库模板字段中的代码直接执行
+ return window.DOMPurify.sanitize(content);
+};
+
+const genAVRollupHTML = (value: IAVCellValue) => {
+ let html = "";
+ const dataValue: IAVCellDateValue = value[value.type as "date"];
+ switch (value.type) {
+ case "block":
+ if (value?.isDetached) {
+ html = `<span>${escapeHtml(value.block?.content || window.siyuan.languages.untitled)}</span>`;
+ } else {
+ html = `<span data-type="block-ref" data-id="${value.block.id}" data-subtype="s" class="av__celltext--ref">${escapeHtml(value.block?.content || window.siyuan.languages.untitled)}</span>`;
+ }
+ break;
+ case "text":
+ html = escapeHtml(value.text.content);
+ break;
+ case "number":
+ html = value.number.formattedContent || value.number.content.toString();
+ break;
+ case "date":
+ case "updated":
+ case "created":
+ if (dataValue.formattedContent) {
+ html = dataValue.formattedContent;
+ } else {
+ if (dataValue && dataValue.isNotEmpty) {
+ html = dayjs(dataValue.content).format(dataValue.isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm");
+ }
+ if (dataValue && dataValue.hasEndDate && dataValue.isNotEmpty && dataValue.isNotEmpty2) {
+ html = `<svg class="av__cellicon"><use xlink:href="#iconForward"></use></svg>${dayjs(dataValue.content2).format(dataValue.isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm")}`;
+ }
+ }
+ if (html) {
+ html = `<span class="av__celltext">${html}</span>`;
+ }
+ break;
+ case "url":
+ html = value.url.content ? `<a class="fn__a" href="${escapeAttr(value.url.content)}" target="_blank">${escapeHtml(value.url.content)}</a>` : "";
+ break;
+ case "phone":
+ html = value.phone.content ? `<a class="fn__a" href="tel:${escapeAttr(value.phone.content)}" target="_blank">${escapeHtml(value.phone.content)}</a>` : "";
+ break;
+ case "email":
+ html = value.email.content ? `<a class="fn__a" href="mailto:${escapeAttr(value.email.content)}" target="_blank">${escapeHtml(value.email.content)}</a>` : "";
+ break;
+ }
+ return html;
+};
+
+export const genAVValueHTML = (value: IAVCellValue) => {
+ let html = "";
+ switch (value.type) {
+ case "block":
+ html = `<input data-id="${value.block.id}" value="${escapeAttr(value.block.content)}" type="text" class="b3-text-field b3-text-field--text fn__flex-1" placeholder="${window.siyuan.languages.empty}">`;
+ break;
+ case "text":
+ html = `<textarea style="resize: vertical" rows="${(value.text?.content || "").split("\n").length}" class="b3-text-field b3-text-field--text fn__flex-1" placeholder="${window.siyuan.languages.empty}">${escapeHtml(value.text?.content || "")}</textarea>`;
+ break;
+ case "number":
+ html = `<input value="${value.number.isNotEmpty ? value.number.content : ""}" type="number" class="b3-text-field b3-text-field--text fn__flex-1" placeholder="${window.siyuan.languages.empty}">
+<span class="fn__space"></span><span class="fn__flex-center ft__on-surface b3-tooltips__w b3-tooltips" aria-label="${window.siyuan.languages.format}">${value.number.formattedContent || ""}</span><span class="fn__space"></span>`;
+ break;
+ case "mSelect":
+ case "select":
+ value.mSelect?.forEach((item, index) => {
+ if (value.type === "select" && index > 0) {
+ return;
+ }
+ html += `<span class="b3-chip b3-chip--middle" style="background-color:var(--b3-font-background${item.color});color:var(--b3-font-color${item.color})">${escapeHtml(item.content)}</span>`;
+ });
+ break;
+ case "mAsset":
+ value.mAsset?.forEach(item => {
+ if (item.type === "image") {
+ html += `<img loading="lazy" class="av__cellassetimg ariaLabel" aria-label="${escapeAriaLabel(item.content)}" src="${getCompressURL(item.content)}">`;
+ } else {
+ html += `<span class="b3-chip b3-chip--middle av__celltext--url ariaLabel" aria-label="${escapeAriaLabel(item.content)}" data-name="${escapeAttr(item.name)}" data-url="${escapeAttr(item.content)}">${escapeHtml(item.name || item.content)}</span>`;
+ }
+ });
+ break;
+ case "date":
+ html = `<span class="av__celltext" data-value='${JSON.stringify(value[value.type])}' placeholder="${window.siyuan.languages.empty}">`;
+ if (value[value.type] && value[value.type].isNotEmpty) {
+ html += dayjs(value[value.type].content).format(value[value.type].isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm");
+ }
+ if (value[value.type] && value[value.type].hasEndDate && value[value.type].isNotEmpty && value[value.type].isNotEmpty2) {
+ html += `<svg class="av__cellicon"><use xlink:href="#iconForward"></use></svg>${dayjs(value[value.type].content2).format(value[value.type].isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm")}`;
+ }
+ html += "</span>";
+ break;
+ case "created":
+ case "updated":
+ if (value[value.type].isNotEmpty) {
+ html = `<span data-content="${value[value.type].content}">${dayjs(value[value.type].content).format("YYYY-MM-DD HH:mm")}</span>`;
+ }
+ break;
+ case "url":
+ html = `<input value="${escapeAttr(value.url.content)}" class="b3-text-field b3-text-field--text fn__flex-1" placeholder="${window.siyuan.languages.empty}">
+<span class="fn__space"></span>
+<a ${value.url.content ? `href="${escapeAttr(value.url.content)}"` : ""} target="_blank" aria-label="${window.siyuan.languages.openBy}" class="block__icon block__icon--show fn__flex-center b3-tooltips__w b3-tooltips"><svg><use xlink:href="#iconLink"></use></svg></a>`;
+ break;
+ case "phone":
+ html = `<input value="${escapeAttr(value.phone.content)}" class="b3-text-field b3-text-field--text fn__flex-1" placeholder="${window.siyuan.languages.empty}">
+<span class="fn__space"></span>
+<a ${value.phone.content ? `href="tel:${escapeAttr(value.phone.content)}"` : ""} target="_blank" aria-label="${window.siyuan.languages.openBy}" class="block__icon block__icon--show fn__flex-center b3-tooltips__w b3-tooltips"><svg><use xlink:href="#iconPhone"></use></svg></a>`;
+ break;
+ case "checkbox":
+ html = `<svg class="av__checkbox"><use xlink:href="#icon${value.checkbox.checked ? "Check" : "Uncheck"}"></use></svg>`;
+ break;
+ case "template":
+ html = `<div class="fn__flex-1" placeholder="${window.siyuan.languages.empty}">${getAVTemplateHTML(value.template.content)}</div>`;
+ break;
+ case "email":
+ html = `<input value="${escapeAttr(value.email.content)}" class="b3-text-field b3-text-field--text fn__flex-1" placeholder="${window.siyuan.languages.empty}">
+<span class="fn__space"></span>
+<a ${value.email.content ? `href="mailto:${escapeAttr(value.email.content)}"` : ""} target="_blank" aria-label="${window.siyuan.languages.openBy}" class="block__icon block__icon--show fn__flex-center b3-tooltips__w b3-tooltips"><svg><use xlink:href="#iconEmail"></use></svg></a>`;
+ break;
+ case "relation":
+ value?.relation?.contents?.forEach((item, index) => {
+ if (item && item.block) {
+ const rowID = value.relation.blockIDs[index];
+ if (item?.isDetached) {
+ html += `<span data-row-id="${rowID}" class="av__cell--relation"><span><svg style="height: 26px"><use xlink:href="#iconLine"></use></svg><span class="fn__space--5"></span></span><span class="av__celltext">${Lute.EscapeHTMLStr(item.block.content || window.siyuan.languages.untitled)}</span></span>`;
+ } else {
+ html += `<span data-row-id="${rowID}" class="av__cell--relation" data-block-id="${item.block.id}"><span class="b3-menu__avemoji" data-unicode="${item.block.icon || ""}">${unicode2Emoji(item.block.icon || window.siyuan.storage[Constants.LOCAL_IMAGES].file)}</span><span data-type="block-ref" data-id="${item.block.id}" data-subtype="s" class="av__celltext av__celltext--ref">${Lute.EscapeHTMLStr(item.block.content || window.siyuan.languages.untitled)}</span></span>`;
+ }
+ }
+ });
+ if (html && html.endsWith(", ")) {
+ html = html.substring(0, html.length - 2);
+ }
+ break;
+ case "rollup":
+ value?.rollup?.contents?.forEach((item) => {
+ const rollupText = ["template", "select", "mSelect", "mAsset", "checkbox", "relation"].includes(item.type) ?
+ genAVValueHTML(item) : genAVRollupHTML(item);
+ if (rollupText) {
+ html += rollupText.replace("fn__flex-1", "") + ",&nbsp;";
+ }
+ });
+ if (html && html.endsWith(",&nbsp;")) {
+ html = html.substring(0, html.length - 7);
+ }
+ break;
+ }
+ return html;
+};
+
+export const genAVAttributeRowHTML = (options: {
+ nodeID: string,
+ avID: string,
+ keyID: string,
+ type: TAVCol,
+ name: string,
+ desc?: string,
+ icon?: string,
+ typeIcon: string,
+ selectOptions?: {
+ name: string,
+ color: string
+ }[],
+ value: IAVCellValue,
+ empty: boolean,
+}) => {
+ const value = options.value;
+ const textInputType = ["url", "text", "number", "email", "phone", "block"].includes(value.type);
+ const hasOwnPlaceholder = ["text", "number", "date", "url", "phone", "template", "email"].includes(value.type);
+ return `<div class="block__icons av__row" data-id="${options.nodeID}" data-col-id="${options.keyID}" data-empty="${options.empty}"${options.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(options.name)}<div class='ft__on-surface'>${escapeAriaLabel(options.desc || "")}</div>">
+ ${options.icon ? unicode2Emoji(options.icon, "block__logoicon", true) : `<svg class="block__logoicon"><use xlink:href="#${options.typeIcon}"></use></svg>`}
+ <span>${escapeHtml(options.name)}</span>
+ </div>
+ <div data-av-id="${options.avID}" data-col-id="${value.keyID}" data-row-id="${value.blockID}"${value.id ? ` data-id="${value.id}"` : ""} data-value="${escapeAttr(JSON.stringify(value))}" data-type="${value.type}"${value.isDetached ? ' data-detached="true"' : ""}
+data-options="${options.selectOptions ? escapeAttr(JSON.stringify(options.selectOptions)) : "[]"}"
+${hasOwnPlaceholder ? "" : `placeholder="${window.siyuan.languages.empty}"`}
+class="fn__flex-1 fn__flex${textInputType ? "" : " custom-attr__avvalue"}${["created", "updated"].includes(value.type) ? " custom-attr__avvalue--readonly" : ""}">${genAVValueHTML(value)}</div>
+</div>`;
+};
diff --git a/app/src/protyle/render/av/blockAttr.ts b/app/src/protyle/render/av/blockAttr.ts
index d854433e0c..cb17228e37 100644
--- a/app/src/protyle/render/av/blockAttr.ts
+++ b/app/src/protyle/render/av/blockAttr.ts
@@ -1,7 +1,6 @@
import {fetchPost} from "../../../util/fetch";
import {addCol, getColIconByType} from "./col";
-import {escapeAriaLabel, escapeAttr, escapeHtml} from "../../../util/escape";
-import * as dayjs from "dayjs";
+import {escapeAttr, escapeHtml} from "../../../util/escape";
import {cellValueIsEmpty, popTextCell, updateCellsValue} from "./cell";
import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "../../util/hasClosest";
import {openEmojiPanel, unicode2Emoji} from "../../../emoji";
@@ -16,9 +15,10 @@ import {webUtils} from "electron";
/// #endif
import {isBrowser} from "../../../util/functions";
import {Constants} from "../../../constants";
-import {getCompressURL, removeCompressURL} from "../../../util/image";
+import {removeCompressURL} from "../../../util/image";
import {openDatabaseRowByData} from "./openDatabaseRow";
import {confirmDialog} from "../../../dialog/confirmDialog";
+import {createEmptyAVValue, genAVAttributeRowHTML} from "./attributeValue";
interface IAVAttributeTableData {
avID: string;
@@ -42,181 +42,6 @@ interface IAVAttributeTableData {
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) {
- return content;
- }
- // 默认过滤危险标签和事件属性,避免数据库模板字段中的代码直接执行
- return window.DOMPurify.sanitize(content);
-};
-
-const genAVRollupHTML = (value: IAVCellValue) => {
- let html = "";
- const dataValue: IAVCellDateValue = value[value.type as "date"];
- switch (value.type) {
- case "block":
- if (value?.isDetached) {
- html = `<span>${escapeHtml(value.block?.content || window.siyuan.languages.untitled)}</span>`;
- } else {
- html = `<span data-type="block-ref" data-id="${value.block.id}" data-subtype="s" class="av__celltext--ref">${escapeHtml(value.block?.content || window.siyuan.languages.untitled)}</span>`;
- }
- break;
- case "text":
- html = escapeHtml(value.text.content);
- break;
- case "number":
- html = value.number.formattedContent || value.number.content.toString();
- break;
- case "date":
- case "updated":
- case "created":
- if (dataValue.formattedContent) {
- html = dataValue.formattedContent;
- } else {
- if (dataValue && dataValue.isNotEmpty) {
- html = dayjs(dataValue.content).format(dataValue.isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm");
- }
- if (dataValue && dataValue.hasEndDate && dataValue.isNotEmpty && dataValue.isNotEmpty2) {
- html = `<svg class="av__cellicon"><use xlink:href="#iconForward"></use></svg>${dayjs(dataValue.content2).format(dataValue.isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm")}`;
- }
- }
- if (html) {
- html = `<span class="av__celltext">${html}</span>`;
- }
- break;
- case "url":
- html = value.url.content ? `<a class="fn__a" href="${escapeAttr(value.url.content)}" target="_blank">${escapeHtml(value.url.content)}</a>` : "";
- break;
- case "phone":
- html = value.phone.content ? `<a class="fn__a" href="tel:${escapeAttr(value.phone.content)}" target="_blank">${escapeHtml(value.phone.content)}</a>` : "";
- break;
- case "email":
- html = value.email.content ? `<a class="fn__a" href="mailto:${escapeAttr(value.email.content)}" target="_blank">${escapeHtml(value.email.content)}</a>` : "";
- break;
- }
- return html;
-};
-
-export const genAVValueHTML = (value: IAVCellValue) => {
- let html = "";
- switch (value.type) {
- case "block":
- html = `<input data-id="${value.block.id}" value="${escapeAttr(value.block.content)}" type="text" class="b3-text-field b3-text-field--text fn__flex-1" placeholder="${window.siyuan.languages.empty}">`;
- break;
- case "text":
- html = `<textarea style="resize: vertical" rows="${(value.text?.content || "").split("\n").length}" class="b3-text-field b3-text-field--text fn__flex-1" placeholder="${window.siyuan.languages.empty}">${escapeHtml(value.text?.content || "")}</textarea>`;
- break;
- case "number":
- html = `<input value="${value.number.isNotEmpty ? value.number.content : ""}" type="number" class="b3-text-field b3-text-field--text fn__flex-1" placeholder="${window.siyuan.languages.empty}">
-<span class="fn__space"></span><span class="fn__flex-center ft__on-surface b3-tooltips__w b3-tooltips" aria-label="${window.siyuan.languages.format}">${value.number.formattedContent}</span><span class="fn__space"></span>`;
- break;
- case "mSelect":
- case "select":
- value.mSelect?.forEach((item, index) => {
- if (value.type === "select" && index > 0) {
- return;
- }
- html += `<span class="b3-chip b3-chip--middle" style="background-color:var(--b3-font-background${item.color});color:var(--b3-font-color${item.color})">${escapeHtml(item.content)}</span>`;
- });
- break;
- case "mAsset":
- value.mAsset?.forEach(item => {
- if (item.type === "image") {
- html += `<img loading="lazy" class="av__cellassetimg ariaLabel" aria-label="${escapeAriaLabel(item.content)}" src="${getCompressURL(item.content)}">`;
- } else {
- html += `<span class="b3-chip b3-chip--middle av__celltext--url ariaLabel" aria-label="${escapeAriaLabel(item.content)}" data-name="${escapeAttr(item.name)}" data-url="${escapeAttr(item.content)}">${escapeHtml(item.name || item.content)}</span>`;
- }
- });
- break;
- case "date":
- html = `<span class="av__celltext" data-value='${JSON.stringify(value[value.type])}' placeholder="${window.siyuan.languages.empty}">`;
- if (value[value.type] && value[value.type].isNotEmpty) {
- html += dayjs(value[value.type].content).format(value[value.type].isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm");
- }
- if (value[value.type] && value[value.type].hasEndDate && value[value.type].isNotEmpty && value[value.type].isNotEmpty2) {
- html += `<svg class="av__cellicon"><use xlink:href="#iconForward"></use></svg>${dayjs(value[value.type].content2).format(value[value.type].isNotTime ? "YYYY-MM-DD" : "YYYY-MM-DD HH:mm")}`;
- }
- html += "</span>";
- break;
- case "created":
- case "updated":
- if (value[value.type].isNotEmpty) {
- html = `<span data-content="${value[value.type].content}">${dayjs(value[value.type].content).format("YYYY-MM-DD HH:mm")}</span>`;
- }
- break;
- case "url":
- html = `<input value="${escapeAttr(value.url.content)}" class="b3-text-field b3-text-field--text fn__flex-1" placeholder="${window.siyuan.languages.empty}">
-<span class="fn__space"></span>
-<a ${value.url.content ? `href="${escapeAttr(value.url.content)}"` : ""} target="_blank" aria-label="${window.siyuan.languages.openBy}" class="block__icon block__icon--show fn__flex-center b3-tooltips__w b3-tooltips"><svg><use xlink:href="#iconLink"></use></svg></a>`;
- break;
- case "phone":
- html = `<input value="${escapeAttr(value.phone.content)}" class="b3-text-field b3-text-field--text fn__flex-1" placeholder="${window.siyuan.languages.empty}">
-<span class="fn__space"></span>
-<a ${value.phone.content ? `href="tel:${escapeAttr(value.phone.content)}"` : ""} target="_blank" aria-label="${window.siyuan.languages.openBy}" class="block__icon block__icon--show fn__flex-center b3-tooltips__w b3-tooltips"><svg><use xlink:href="#iconPhone"></use></svg></a>`;
- break;
- case "checkbox":
- html = `<svg class="av__checkbox"><use xlink:href="#icon${value.checkbox.checked ? "Check" : "Uncheck"}"></use></svg>`;
- break;
- case "template":
- html = `<div class="fn__flex-1" placeholder="${window.siyuan.languages.empty}">${getAVTemplateHTML(value.template.content)}</div>`;
- break;
- case "email":
- html = `<input value="${escapeAttr(value.email.content)}" class="b3-text-field b3-text-field--text fn__flex-1" placeholder="${window.siyuan.languages.empty}">
-<span class="fn__space"></span>
-<a ${value.email.content ? `href="mailto:${escapeAttr(value.email.content)}"` : ""} target="_blank" aria-label="${window.siyuan.languages.openBy}" class="block__icon block__icon--show fn__flex-center b3-tooltips__w b3-tooltips"><svg><use xlink:href="#iconEmail"></use></svg></a>`;
- break;
- case "relation":
- value?.relation?.contents?.forEach((item, index) => {
- if (item && item.block) {
- const rowID = value.relation.blockIDs[index];
- if (item?.isDetached) {
- html += `<span data-row-id="${rowID}" class="av__cell--relation"><span><svg style="height: 26px"><use xlink:href="#iconLine"></use></svg><span class="fn__space--5"></span></span><span class="av__celltext">${Lute.EscapeHTMLStr(item.block.content || window.siyuan.languages.untitled)}</span></span>`;
- } else {
- // data-block-id 用于更新 emoji
- html += `<span data-row-id="${rowID}" class="av__cell--relation" data-block-id="${item.block.id}"><span class="b3-menu__avemoji" data-unicode="${item.block.icon || ""}">${unicode2Emoji(item.block.icon || window.siyuan.storage[Constants.LOCAL_IMAGES].file)}</span><span data-type="block-ref" data-id="${item.block.id}" data-subtype="s" class="av__celltext av__celltext--ref">${Lute.EscapeHTMLStr(item.block.content || window.siyuan.languages.untitled)}</span></span>`;
- }
- }
- });
- if (html && html.endsWith(", ")) {
- html = html.substring(0, html.length - 2);
- }
- break;
- case "rollup":
- value?.rollup?.contents?.forEach((item) => {
- const rollupText = ["template", "select", "mSelect", "mAsset", "checkbox", "relation"].includes(item.type) ? genAVValueHTML(item) : genAVRollupHTML(item);
- if (rollupText) {
- html += rollupText.replace("fn__flex-1", "") + ",&nbsp;";
- }
- });
- if (html && html.endsWith(",&nbsp;")) {
- html = html.substring(0, html.length - 7);
- }
- break;
- }
- return html;
-};
-
let attributeViewRenderID = 0;
export const renderAVAttribute = (element: HTMLElement, id: string, protyle: IProtyle, cb?: (element: HTMLElement) => void,
@@ -265,17 +90,19 @@ export const renderAVAttribute = (element: HTMLElement, id: string, protyle: IPr
</div>`;
table.keyValues?.forEach(item => {
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="${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 += genAVAttributeRowHTML({
+ nodeID: id,
+ avID: table.avID,
+ keyID: item.key.id,
+ type: item.key.type,
+ name: item.key.name,
+ desc: item.key.desc,
+ icon: item.key.icon,
+ typeIcon: getColIconByType(item.key.type),
+ selectOptions: item.key.options,
+ value,
+ empty: cellValueIsEmpty(value),
+ });
});
innerHTML += `<div class="fn__hr"></div>
<button data-type="addColumn" class="b3-button b3-button--cancel"><svg><use xlink:href="#iconAdd"></use></svg>${window.siyuan.languages.newCol}</button>
@@ -418,16 +245,18 @@ class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone", "block"]
});
element.addEventListener("paste", (event) => {
const files = event.clipboardData.files;
- if (document.querySelector(".av__panel .b3-form__upload")) {
+ const assetCellElement = element.querySelector<HTMLElement>('.custom-attr__avvalue[data-type="mAsset"][data-active="true"]');
+ if (assetCellElement && document.querySelector(".av__panel .b3-form__upload")) {
+ event.preventDefault();
+ event.stopPropagation();
if (files && files.length > 0) {
uploadFiles(protyle, files);
} else {
const textPlain = event.clipboardData.getData("text/plain");
- const target = event.target as HTMLElement;
- const blockElement = hasClosestBlock(target);
- const cellsElement = hasClosestByAttribute(target, "data-type", "mAsset");
- if (blockElement && cellsElement && textPlain) {
- updateCellsValue(protyle, blockElement as HTMLElement, textPlain, [cellsElement], undefined, protyle.lute.Md2BlockDOM(textPlain));
+ const blockElement = hasClosestBlock(assetCellElement);
+ if (blockElement && textPlain) {
+ updateCellsValue(protyle, blockElement as HTMLElement, textPlain, [assetCellElement],
+ undefined, protyle.lute.Md2BlockDOM(textPlain));
document.querySelector(".av__panel")?.remove();
}
}
@@ -562,63 +391,19 @@ class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone", "block"]
attributeTableData.set(blockElement, table);
}
});
- element.querySelectorAll(".b3-text-field--text").forEach((item: HTMLInputElement) => {
- item.addEventListener("change", () => {
- let value;
- const type = item.parentElement.dataset.type;
- if (["url", "text", "email", "phone"].includes(type)) {
- value = {
- [type]: {
- content: item.value
- }
- };
- if (type !== "text") {
- const linkElement = item.parentElement.querySelector("a");
- if (item.value) {
- linkElement.setAttribute("href", (type === "url" ? "" : (type === "email" ? "mailto:" : "tel:")) + item.value);
- } else {
- linkElement.removeAttribute("href");
- }
- }
- } else if (type === "number") {
- if ("undefined" === item.value || !item.value) {
- value = {
- number: {
- content: null,
- isNotEmpty: false
- }
- };
- } else {
- value = {
- number: {
- content: parseFloat(item.value) || 0,
- isNotEmpty: true
- }
- };
- }
- } else if (type === "block") {
- value = {
- block: {
- content: item.value,
- id: item.parentElement.dataset.detached === "true" ? "" : item.dataset.id,
- },
- isDetached: item.parentElement.dataset.detached === "true"
- };
+ if (element.dataset.avInputBound !== "true") {
+ element.dataset.avInputBound = "true";
+ element.addEventListener("change", (event) => {
+ const item = event.target as HTMLInputElement | HTMLTextAreaElement;
+ if (!item.classList.contains("b3-text-field--text") || !item.parentElement.dataset.avId) {
+ return;
+ }
+ const blockElement = hasClosestBlock(item);
+ if (blockElement) {
+ updateCellsValue(protyle, blockElement as HTMLElement, item.value, [item.parentElement]);
}
- fetchPost("/api/av/setAttributeViewBlockAttr", {
- avID: item.parentElement.dataset.avId,
- keyID: item.parentElement.dataset.colId,
- itemID: item.parentElement.dataset.rowId,
- value
- }, (setResponse) => {
- if (type === "number") {
- item.parentElement.querySelector(".fn__flex-center").textContent = setResponse.data.value.number.formattedContent;
- } else if (type === "block" && !item.value) {
- item.value = setResponse.data.value.block.content;
- }
- });
});
- });
+ }
renderAttributeViewBacklinks(element, id, renderID, row, cb);
});
};
@@ -747,11 +532,12 @@ const openEdit = (protyle: IProtyle, element: HTMLElement, event: MouseEvent) =>
event.preventDefault();
break;
} else if (type === "mAsset") {
- element.querySelectorAll('.custom-attr__avvalue[data-type="mAsset"]').forEach(item => {
+ document.querySelectorAll('.custom-attr__avvalue[data-type="mAsset"][data-active="true"]').forEach(item => {
item.removeAttribute("data-active");
});
target.setAttribute("data-active", "true");
- target.focus();
+ target.tabIndex = -1;
+ target.focus({preventScroll: true});
popTextCell(protyle, [target], "mAsset");
event.stopPropagation();
event.preventDefault();
diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.ts
index 18da776fc1..eaa2450ac9 100644
--- a/app/src/protyle/render/av/cell.ts
+++ b/app/src/protyle/render/av/cell.ts
@@ -9,7 +9,7 @@ import {focusBlock, focusByRange} from "../../util/selection";
import * as dayjs from "dayjs";
import {unicode2Emoji} from "../../../emoji";
import {getColIconByType, getColId} from "./col";
-import {genAVValueHTML, getAVTemplateHTML} from "./blockAttr";
+import {genAVValueHTML, getAVTemplateHTML} from "./attributeValue";
import {Constants} from "../../../constants";
import {hintRef} from "../../hint/extend";
import {getAssetName, pathPosix} from "../../../util/pathName";
@@ -64,24 +64,31 @@ export const getCellText = (cellElement: HTMLElement | false) => {
};
export const genCellValueByElement = (colType: TAVCol, cellElement: HTMLElement) => {
+ if (cellElement.dataset.avId && cellElement.dataset.value) {
+ return JSON.parse(cellElement.dataset.value) as IAVCellValue;
+ }
const cellValue: IAVCellValue = {
type: colType,
id: cellElement.dataset.id,
};
if (colType === "number") {
- const value = cellElement.querySelector(".av__celltext").getAttribute("data-content");
+ const value = (cellElement.querySelector("input") as HTMLInputElement)?.value ||
+ cellElement.querySelector(".av__celltext")?.getAttribute("data-content");
cellValue.number = {
content: parseFloat(value) || 0,
isNotEmpty: !!value
};
} else if (["text", "block", "url", "phone", "email", "template"].includes(colType)) {
- const textElement = cellElement.querySelector(".av__celltext") as HTMLElement;
+ const inputElement = cellElement.querySelector("input, textarea") as HTMLInputElement | HTMLTextAreaElement;
+ const textElement = cellElement.querySelector(".av__celltext") as HTMLElement ||
+ cellElement.querySelector(":scope > .fn__flex-1") as HTMLElement;
cellValue[colType as "text"] = {
- content: colType === "url" ? textElement.dataset.href : textElement.textContent
+ content: inputElement ? inputElement.value :
+ (colType === "url" ? textElement?.dataset.href : textElement?.textContent) || ""
};
- if (colType === "block" && textElement.dataset.id) {
- cellValue.block.id = textElement.dataset.id;
- if (textElement.previousElementSibling?.classList.contains("b3-menu__avemoji")) {
+ if (colType === "block" && (inputElement?.dataset.id || textElement?.dataset.id)) {
+ cellValue.block.id = inputElement?.dataset.id || textElement.dataset.id;
+ if (textElement?.previousElementSibling?.classList.contains("b3-menu__avemoji")) {
const unicode = textElement.previousElementSibling.getAttribute("data-unicode");
if (unicode) {
cellValue.block.icon = unicode;
@@ -534,7 +541,9 @@ export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[], type
openMenuPanel({protyle, blockElement, type: "select", cellElements});
} else if (type === "mAsset") {
openMenuPanel({protyle, blockElement, type: "asset", cellElements});
- focusBlock(blockElement);
+ if (!hasClosestByClassName(cellElements[0], "custom-attr")) {
+ focusBlock(blockElement);
+ }
} else if (type === "date") {
openMenuPanel({protyle, blockElement, type: "date", cellElements});
} else if (type === "checkbox") {
@@ -918,9 +927,11 @@ export const updateCellsValue = async (protyle: IProtyle, nodeElement: HTMLEleme
});
if (isCustomAttr) {
item.innerHTML = genAVValueHTML(cellValue);
+ item.parentElement.dataset.empty = cellValueIsEmpty(cellValue).toString();
} else {
updateAttrViewCellAnimation(item, cellValue);
}
+ updateAttrViewCellInOtherElements(protyle, avID, rowID, colId, cellValue, item);
}
}
if (getOperations) {
@@ -942,6 +953,47 @@ export const updateCellsValue = async (protyle: IProtyle, nodeElement: HTMLEleme
return {text: text.substring(0, text.length - 2), json};
};
+export const updateAttrViewCellInOtherElements = (protyle: IProtyle, avID: string, rowID: string, colID: string,
+ value: IAVCellValue, sourceElement?: HTMLElement) => {
+ const updateCustomAttr = (cellElement: HTMLElement) => {
+ if (value.id) {
+ cellElement.dataset.id = value.id;
+ } else {
+ cellElement.removeAttribute("data-id");
+ }
+ cellElement.dataset.value = JSON.stringify(value);
+ cellElement.parentElement.dataset.empty = cellValueIsEmpty(value).toString();
+ };
+ if (sourceElement?.dataset.avId) {
+ updateCustomAttr(sourceElement);
+ }
+ protyle.wysiwyg.element.querySelectorAll<HTMLElement>(`.av[data-av-id="${avID}"]`).forEach(item => {
+ item.querySelectorAll<HTMLElement>(
+ `.av__row[data-id="${rowID}"] .av__cell[data-col-id="${colID}"], ` +
+ `.av__gallery-item[data-id="${rowID}"] .av__cell[data-field-id="${colID}"]`
+ ).forEach(cellElement => {
+ if (cellElement === sourceElement) {
+ return;
+ }
+ if (value.id) {
+ cellElement.dataset.id = value.id;
+ } else {
+ cellElement.removeAttribute("data-id");
+ }
+ updateAttrViewCellAnimation(cellElement, value);
+ });
+ });
+ document.querySelectorAll<HTMLElement>(
+ `.custom-attr [data-av-id="${avID}"] [data-row-id="${rowID}"][data-col-id="${colID}"]`
+ ).forEach(cellElement => {
+ if (cellElement === sourceElement) {
+ return;
+ }
+ updateCustomAttr(cellElement);
+ cellElement.innerHTML = genAVValueHTML(value);
+ });
+};
+
export const renderCellAttr = (cellElement: Element, value: IAVCellValue) => {
if (value.type === "checkbox") {
if (value.checkbox.checked) {
diff --git a/app/src/protyle/render/av/col.ts b/app/src/protyle/render/av/col.ts
index b60ad237de..c1d0ffccd3 100644
--- a/app/src/protyle/render/av/col.ts
+++ b/app/src/protyle/render/av/col.ts
@@ -2,10 +2,10 @@ import {Menu} from "../../../plugin/Menu";
import {transaction} from "../../wysiwyg/transaction";
import {fetchPost, fetchSyncPost} from "../../../util/fetch";
import {getDefaultOperatorByType, getEditableFilters, hasFilterForColumn} from "./filter";
-import {genCellValue} from "./cell";
+import {genCellValue, renderCell} from "./cell";
import {getPropertiesHTML, openMenuPanel} from "./openMenuPanel";
import {getLabelByNumberFormat} from "./number";
-import {removeAttrViewColAnimation, updateAttrViewCellAnimation} from "./action";
+import {removeAttrViewColAnimation, updateAttrViewCellAnimation, updateAttrViewColAnimation} from "./action";
import {openEmojiPanel, unicode2Emoji} from "../../../emoji";
import {focusBlock} from "../../util/selection";
import {toggleUpdateRelationBtn} from "./relation";
@@ -19,6 +19,7 @@ import {escapeAriaLabel, escapeAttr, escapeHtml} from "../../../util/escape";
import {getFieldsByData} from "./view";
import {hasClosestByClassName} from "../../util/hasClosest";
import {openFieldVisibility} from "./fieldVisibility";
+import {createEmptyAVValue, genAVAttributeRowHTML} from "./attributeValue";
export const getColId = (element: Element, viewType: TAVView) => {
if (viewType === "table" || hasClosestByClassName(element, "custom-attr")) {
@@ -279,7 +280,7 @@ export const bindEditEvent = (options: {
type: colData.type,
}]);
colData.name = newValue;
- updateAttrViewCellAnimation(options.protyle.wysiwyg.element.querySelector(`.av__row--header .av__cell[data-col-id="${colId}"]`), undefined, {name: newValue});
+ updateAttrViewColAnimation(options.protyle, avID, colId, {name: newValue});
});
nameElement.addEventListener("keydown", (event: KeyboardEvent) => {
if (event.isComposing) {
@@ -630,8 +631,8 @@ const addAttrViewColAnimation = (options: {
return;
}
const nodeId = options.blockElement.getAttribute("data-node-id");
- if (options.blockElement.classList.contains("av")) {
- options.blockElement.querySelectorAll(".av__row").forEach((item) => {
+ const insertTableColumn = (blockElement: Element) => {
+ blockElement.querySelectorAll(".av__row").forEach((item) => {
let previousElement;
if (options.previousID) {
previousElement = item.querySelector(`[data-col-id="${options.previousID}"]`);
@@ -651,21 +652,37 @@ const addAttrViewColAnimation = (options: {
<div class="av__widthdrag"></div>
</div>`;
} else {
- html = '<div class="av__cell" style="width: 200px"><span class="av__pulse"></span></div>';
+ const value = genCellValue(options.type, null);
+ html = `<div class="av__cell${options.type === "checkbox" ? " av__cell-uncheck" : ""}" data-col-id="${options.id}"
+data-wrap="false" data-dtype="${options.type}" data-align="" style="width: 200px">${renderCell(value,
+ parseInt(item.getAttribute("data-index")) || 0)}</div>`;
}
previousElement.insertAdjacentHTML("afterend", html);
});
+ };
+ if (options.blockElement.classList.contains("av")) {
+ insertTableColumn(options.blockElement);
} else {
- options.blockElement.querySelector(".fn__hr").insertAdjacentHTML("beforebegin", `<div class="block__icons av__row" data-id="${nodeId}" data-col-id="${options.id}">
- <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="${getColNameByType(options.type)}">
- <svg class="block__logoicon"><use xlink:href="#${getColIconByType(options.type)}"></use></svg>
- <span>${getColNameByType(options.type)}</span>
- </div>
- <div data-col-id="${options.id}" data-block-id="${nodeId}" data-type="${options.type}" data-options="[]" class="fn__flex-1 fn__flex">
- <div class="fn__flex-1"></div>
- </div>
-</div>`);
+ const rowID = options.blockElement.querySelector<HTMLElement>("[data-row-id]")?.dataset.rowId || nodeId;
+ const colData = options.data ? getFieldsByData(options.data).find(item => item.id === options.id) : undefined;
+ options.blockElement.querySelector(".fn__hr").insertAdjacentHTML("beforebegin", genAVAttributeRowHTML({
+ nodeID: nodeId,
+ avID: options.blockElement.getAttribute("data-av-id"),
+ keyID: options.id,
+ type: options.type,
+ name: options.name,
+ desc: colData?.desc,
+ icon: options.icon,
+ typeIcon: getColIconByType(options.type),
+ selectOptions: colData?.options,
+ value: createEmptyAVValue(options.id, options.type, rowID),
+ empty: true,
+ }));
+ options.protyle.wysiwyg.element.querySelectorAll(
+ `.av[data-av-id="${options.blockElement.getAttribute("data-av-id")}"]`
+ ).forEach(item => {
+ insertTableColumn(item);
+ });
}
const menuElement = document.querySelector(".av__panel .b3-menu") as HTMLElement;
if (menuElement && options.data && options.blockElement.classList.contains("av")) {
@@ -730,7 +747,7 @@ export const showColMenu = (protyle: IProtyle, blockElement: Element, cellElemen
name: oldValue,
type,
}]);
- updateAttrViewCellAnimation(blockElement.querySelector(`.av__row--header .av__cell[data-col-id="${colId}"]`), undefined, {name: newValue});
+ updateAttrViewColAnimation(protyle, avID, colId, {name: newValue});
}
const newDesc = menu.element.querySelector("textarea").value;
if (newDesc !== oldDesc) {
diff --git a/app/src/protyle/render/av/select.ts b/app/src/protyle/render/av/select.ts
index f038a0f023..05096443bf 100644
--- a/app/src/protyle/render/av/select.ts
+++ b/app/src/protyle/render/av/select.ts
@@ -5,9 +5,10 @@ import {confirmDialog} from "../../../dialog/confirmDialog";
import {upDownHint} from "../../../util/upDownHint";
import {bindEditEvent, getColId, getEditHTML} from "./col";
import {updateAttrViewCellAnimation} from "./action";
-import {genAVValueHTML, isCustomAttr} from "./blockAttr";
+import {isCustomAttr} from "./blockAttr";
+import {genAVValueHTML} from "./attributeValue";
import {escapeAriaLabel, escapeAttr, escapeHtml} from "../../../util/escape";
-import {genCellValueByElement, getTypeByCellElement} from "./cell";
+import {genCellValueByElement, getTypeByCellElement, updateAttrViewCellInOtherElements} from "./cell";
import * as dayjs from "dayjs";
import {getFieldsByData} from "./view";
import {getFieldIdByCellElement} from "./row";
@@ -126,6 +127,7 @@ export const removeCellOption = (protyle: IProtyle, cellElements: HTMLElement[],
} else {
updateAttrViewCellAnimation(item, cellValue);
}
+ updateAttrViewCellInOtherElements(protyle, avID, rowID, colId, cellValue, item);
});
doOperations.push({
action: "doUpdateUpdated",
@@ -237,6 +239,7 @@ export const setColOption = (protyle: IProtyle, data: IAV, target: HTMLElement,
} else {
updateAttrViewCellAnimation(cellElement, cellValues[index]);
}
+ updateAttrViewCellInOtherElements(protyle, data.id, rowID, colId, cellValues[index], cellElement);
});
menuElement.innerHTML = getSelectHTML(fields, cellElements, false, blockElement);
bindSelectEvent(protyle, data, menuElement, cellElements, blockElement);
@@ -357,6 +360,8 @@ export const setColOption = (protyle: IProtyle, data: IAV, target: HTMLElement,
} else {
updateAttrViewCellAnimation(cellElement, cellValues[index]);
}
+ updateAttrViewCellInOtherElements(protyle, data.id, rowID, colId,
+ cellValues[index], cellElement);
});
menuElement.innerHTML = getSelectHTML(fields, cellElements, false, blockElement);
bindSelectEvent(protyle, data, menuElement, cellElements, blockElement);
@@ -433,7 +438,7 @@ export const setColOption = (protyle: IProtyle, data: IAV, target: HTMLElement,
} else {
cellElements.forEach((cellElement: HTMLElement, cellIndex) => {
const rowID = getFieldIdByCellElement(cellElement, viewType);
- if (viewType === "table") {
+ if (viewType === "table" || isCustomAttr) {
cellElement = cellElements[cellIndex] = (blockElement.querySelector(`.av__row[data-id="${rowID}"] .av__cell[data-col-id="${cellElement.dataset.colId}"]`) ||
blockElement.querySelector(`.fn__flex-1[data-col-id="${cellElement.dataset.colId}"]`)) as HTMLElement;
} else {
@@ -451,6 +456,8 @@ export const setColOption = (protyle: IProtyle, data: IAV, target: HTMLElement,
} else {
updateAttrViewCellAnimation(cellElement, cellValues[cellIndex]);
}
+ updateAttrViewCellInOtherElements(protyle, data.id, rowID, colId,
+ cellValues[cellIndex], cellElement);
});
menuElement.innerHTML = getSelectHTML(fields, cellElements, false, blockElement);
bindSelectEvent(protyle, data, menuElement, cellElements, blockElement);
@@ -615,6 +622,7 @@ export const addColOptionOrCell = (protyle: IProtyle, data: IAV, cellElements: H
} else {
updateAttrViewCellAnimation(item, cellValue);
}
+ updateAttrViewCellInOtherElements(protyle, data.id, rowID, colId, cellValue, item);
});
if (currentElement.querySelector(".b3-menu__accelerator")) {
diff --git a/app/src/protyle/wysiwyg/commonClick.ts b/app/src/protyle/wysiwyg/commonClick.ts
index 90586b612a..9419fab505 100644
--- a/app/src/protyle/wysiwyg/commonClick.ts
+++ b/app/src/protyle/wysiwyg/commonClick.ts
@@ -48,9 +48,15 @@ export const commonClick = (event: MouseEvent & {
const avElement = hasClosestByClassName(event.target, "protyle-attr--av");
if (avElement) {
+ const avIDElement = event.target.closest("[data-av-id]") as HTMLElement;
+ const avID = avIDElement && avElement.contains(avIDElement) ? avIDElement.dataset.avId : "";
if (data) {
if (protyle.databaseAttributePanel) {
- protyle.databaseAttributePanel.toggle();
+ if (avID) {
+ protyle.databaseAttributePanel.expand(avID);
+ } else {
+ protyle.databaseAttributePanel.toggle();
+ }
} else {
openFileAttr(data, "av", protyle);
}
@@ -60,9 +66,17 @@ export const commonClick = (event: MouseEvent & {
if (!protyle.databaseAttributePanel) {
openAttr(avElement.parentElement.parentElement, "av", protyle);
} else if (blockID && protyle.block.showAll && blockID === protyle.block.id) {
- protyle.databaseAttributePanel?.toggle();
+ if (avID) {
+ protyle.databaseAttributePanel.expand(avID);
+ } else {
+ protyle.databaseAttributePanel.toggle();
+ }
} else if (blockID) {
- zoomOut({protyle, id: blockID});
+ zoomOut({
+ protyle,
+ id: blockID,
+ callback: avID ? () => protyle.databaseAttributePanel?.expand(avID) : undefined,
+ });
}
}
event.stopPropagation();