Skip to content

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

:bug: Respect document read-only mode in the database attribute panel https://github.com/siyuan-note/siyuan/issues/19674

Daniel0a5aefe557a5
diff --git a/app/src/assets/scss/business/_custom.scss b/app/src/assets/scss/business/_custom.scss
index 0961b898d7..8687822561 100644
--- a/app/src/assets/scss/business/_custom.scss
+++ b/app/src/assets/scss/business/_custom.scss
@@ -324,6 +324,25 @@
}
+.protyle-db-attr[data-readonly="true"],
+.custom-attr[data-readonly="true"] {
+ [data-type="toggle-empty"],
+ [data-type="remove"],
+ [data-type="addColumn"],
+ .av__row > .block__icon[draggable] {
+ display: none;
+ }
+
+ [data-type="editCol"],
+ .custom-attr__avvalue {
+ cursor: default;
+ }
+
+ .custom-attr__avvalue:hover {
+ background-color: transparent;
+ }
+}
+
.protyle-db-attr__body,
.protyle-db-row__body {
container-type: inline-size;
diff --git a/app/src/protyle/render/av/attributePanel.ts b/app/src/protyle/render/av/attributePanel.ts
index f1641a5017..3ec69ce724 100644
--- a/app/src/protyle/render/av/attributePanel.ts
+++ b/app/src/protyle/render/av/attributePanel.ts
@@ -58,6 +58,9 @@ export class AVAttributePanel {
this.element.addEventListener("click", (event) => {
const target = event.target as HTMLElement;
if (target.closest('[data-type="toggle-empty"]')) {
+ if (this.protyle.disabled) {
+ return;
+ }
this.showEmptyFields = !this.showEmptyFields;
this.updateEmptyState();
event.preventDefault();
@@ -123,7 +126,7 @@ export class AVAttributePanel {
}
this.element.dataset.rendered = "true";
this.updateTabs();
- this.updateEmptyState();
+ this.updateReadonly();
this.element.classList.toggle("fn__none", !renderedElement.querySelector("[data-av-id], .custom-attr__avbacklinks"));
const callbacks = this.renderCallbacks.splice(0);
callbacks.forEach(callback => callback(this.bodyElement));
@@ -164,6 +167,18 @@ export class AVAttributePanel {
}
}
+ public updateReadonly() {
+ this.element.dataset.readonly = String(Boolean(this.protyle.disabled));
+ this.bodyElement.dataset.readonly = this.element.dataset.readonly;
+ this.bodyElement.querySelectorAll<HTMLInputElement | HTMLTextAreaElement>("input, textarea").forEach(item => {
+ item.readOnly = Boolean(this.protyle.disabled);
+ });
+ this.element.querySelectorAll<HTMLElement>('[data-type="av-tab"]').forEach(item => {
+ item.draggable = !this.protyle.disabled;
+ });
+ this.updateEmptyState();
+ }
+
public hasDatabase(avID: string) {
return Boolean(this.bodyElement.querySelector(`[data-av-id="${avID}"]`));
}
@@ -389,6 +404,11 @@ export class AVAttributePanel {
}
event.preventDefault();
event.stopPropagation();
+ if (this.protyle.disabled) {
+ clearDragState();
+ this.updateTabs();
+ return;
+ }
const tabElements = Array.from(tabsElement.querySelectorAll<HTMLElement>('[data-type="av-tab"]'));
const avIDs = tabElements.map(item => item.dataset.id || "");
const index = avIDs.indexOf(draggedAvID);
@@ -453,13 +473,14 @@ export class AVAttributePanel {
}
private updateEmptyState() {
+ this.element.dataset.readonly = String(Boolean(this.protyle.disabled));
const hideEmpty = window.siyuan.config.editor.databaseAttrHideEmpty;
- if (!hideEmpty) {
+ if (!hideEmpty || this.protyle.disabled) {
this.showEmptyFields = false;
}
updateEmptyState(this.element, hideEmpty && !this.showEmptyFields);
const editElement = this.element.querySelector<HTMLElement>('[data-type="toggle-empty"]');
- editElement?.classList.toggle("fn__none", !hideEmpty || this.collapsed);
+ editElement?.classList.toggle("fn__none", !hideEmpty || this.collapsed || this.protyle.disabled);
editElement?.setAttribute("aria-label", window.siyuan.languages[
this.showEmptyFields ? "hideEmptyFields" : "displayEmptyFields"
]);
diff --git a/app/src/protyle/render/av/blockAttr.ts b/app/src/protyle/render/av/blockAttr.ts
index dda9295a6f..5ea5573f8f 100644
--- a/app/src/protyle/render/av/blockAttr.ts
+++ b/app/src/protyle/render/av/blockAttr.ts
@@ -188,6 +188,10 @@ export const renderAVAttribute = (element: HTMLElement, id: string, protyle: IPr
let dragBlockElement: HTMLElement;
let removeEditorRange: Range | undefined;
element.addEventListener("dragstart", (event: DragEvent) => {
+ if (protyle.disabled) {
+ event.preventDefault();
+ return;
+ }
const target = event.target as HTMLElement;
window.siyuan.dragElement = target.parentElement;
window.siyuan.dragElement.style.opacity = ".38";
@@ -259,6 +263,9 @@ export const renderAVAttribute = (element: HTMLElement, id: string, protyle: IPr
}
});
element.addEventListener("dragover", (event: DragEvent) => {
+ if (protyle.disabled) {
+ return;
+ }
const target = event.target as HTMLElement;
let targetElement: HTMLElement | false;
if (event.dataTransfer.types.includes("Files")) {
@@ -314,6 +321,9 @@ export const renderAVAttribute = (element: HTMLElement, id: string, protyle: IPr
}
});
element.addEventListener("paste", (event) => {
+ if (protyle.disabled) {
+ return;
+ }
const files = event.clipboardData.files;
const assetCellElement = element.querySelector<HTMLElement>('.custom-attr__avvalue[data-type="mAsset"][data-active="true"]');
if (assetCellElement && document.querySelector(".av__panel .b3-form__upload")) {
@@ -392,6 +402,9 @@ export const renderAVAttribute = (element: HTMLElement, id: string, protyle: IPr
}
const removeElement = hasClosestByAttribute(event.target as HTMLElement, "data-type", "remove");
if (removeElement) {
+ if (protyle.disabled) {
+ return;
+ }
const selection = document.getSelection();
const currentRange = selection?.rangeCount ? selection.getRangeAt(0) : undefined;
const editorRange = removeEditorRange || getEditorFocusRange(protyle.wysiwyg.element,
@@ -465,6 +478,9 @@ export const renderAVAttribute = (element: HTMLElement, id: string, protyle: IPr
const restoreEditorRange = () => restoreEditorFocusRange(protyle.wysiwyg.element,
editorRange);
confirmDialog(window.siyuan.languages.removeAV, window.siyuan.languages.confirmDelete + "?", () => {
+ if (protyle.disabled) {
+ return;
+ }
removeElement.setAttribute("disabled", "true");
transaction(protyle, doOperations, undoOperations.length > 0 ? undoOperations : undefined, {
callback: () => {
@@ -494,6 +510,10 @@ export const renderAVAttribute = (element: HTMLElement, id: string, protyle: IPr
element.innerHTML = html;
}
renderAVRichTextElements(element);
+ element.dataset.readonly = String(Boolean(protyle.disabled));
+ element.querySelectorAll<HTMLInputElement | HTMLTextAreaElement>("input, textarea").forEach(item => {
+ item.readOnly = Boolean(protyle.disabled);
+ });
tables.forEach((table: IAVAttributeTableData) => {
const blockElement = element.querySelector<HTMLElement>(`[data-attribute-id="${id}"][data-av-id="${table.avID}"]`);
if (blockElement) {
@@ -503,6 +523,9 @@ export const renderAVAttribute = (element: HTMLElement, id: string, protyle: IPr
if (element.dataset.avInputBound !== "true") {
element.dataset.avInputBound = "true";
element.addEventListener("change", (event) => {
+ if (protyle.disabled) {
+ return;
+ }
const item = event.target as HTMLInputElement | HTMLTextAreaElement;
if (!item.classList.contains("b3-text-field--text") || !item.parentElement.dataset.avId) {
return;
@@ -582,6 +605,19 @@ const renderAttributeViewBacklinks = (element: HTMLElement, id: string, renderID
const openEdit = (protyle: IProtyle, element: HTMLElement, event: MouseEvent) => {
let target = event.target as HTMLElement;
+ if (protyle.disabled) {
+ const assetElement = target.closest<HTMLElement>(".av__celltext--url, .av__cellassetimg");
+ if (event.type === "click" && assetElement) {
+ if (assetElement.tagName === "IMG") {
+ previewImages([removeCompressURL(assetElement.getAttribute("src"))]);
+ } else if (assetElement.dataset.url) {
+ openLink(protyle.app, assetElement.dataset.url, event, event.ctrlKey || event.metaKey);
+ }
+ event.preventDefault();
+ event.stopPropagation();
+ }
+ return;
+ }
const valueElement = hasClosestByClassName(target, "custom-attr__avvalue");
const blockElement = hasClosestBlock(valueElement || target);
if (!blockElement) {
diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts
index 0cf2bc916f..56c76d17ad 100644
--- a/app/src/protyle/util/onGet.ts
+++ b/app/src/protyle/util/onGet.ts
@@ -504,6 +504,7 @@ export const disabledProtyle = (protyle: IProtyle) => {
window.siyuan.menus.menu.remove();
hideElements(["gutter", "toolbar", "select", "hint", "util"], protyle);
protyle.disabled = true;
+ protyle.databaseAttributePanel?.updateReadonly();
if (protyle.title && protyle.title.editElement) {
protyle.title.editElement.setAttribute("contenteditable", "false");
protyle.title.editElement.style.userSelect = "text";
@@ -537,6 +538,7 @@ export const enableProtyle = (protyle: IProtyle) => {
return;
}
protyle.disabled = false;
+ protyle.databaseAttributePanel?.updateReadonly();
if (isMobile()) {
/// #if MOBILE
updateMobileTitleReadonly(protyle);