Skip to content

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

:sparkles: Support hiding the primary field in database gallery views https://github.com/siyuan-note/siyuan/issues/15175

Danielca5baad2f7d7
diff --git a/app/src/assets/scss/business/_av.scss b/app/src/assets/scss/business/_av.scss
index dd7d3fb056..01f26a763e 100644
--- a/app/src/assets/scss/business/_av.scss
+++ b/app/src/assets/scss/business/_av.scss
@@ -381,6 +381,10 @@
flex-direction: column;
position: relative;
+ &--empty {
+ min-height: 32px;
+ }
+
&::before {
transition: background 100ms ease-out;
content: "";
diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.ts
index 0cb51370f8..3c3236b805 100644
--- a/app/src/protyle/render/av/action.ts
+++ b/app/src/protyle/render/av/action.ts
@@ -17,7 +17,7 @@ import {
} from "./cell";
import {addCol, getColIconByType, getColNameByType, showColMenu} from "./col";
import {deleteRow, duplicateRows, insertRows, selectRow, setPageSize, updateHeader} from "./row";
-import {getAVSelectedItems, resetAVRowSelect, updateAVRowSelect} from "./virtualScroll";
+import {getAVPrimaryCell, getAVSelectedItems, resetAVRowSelect, updateAVRowSelect} from "./virtualScroll";
import {emitOpenMenu} from "../../../plugin/EventBus";
import {openMenuPanel} from "./openMenuPanel";
import {hintRef} from "../../hint/extend";
@@ -57,10 +57,85 @@ const isDetachedDatabaseCell = (cellElement: HTMLElement) => {
return cellElement.dataset.detached === "true" || !cellElement.querySelector(".av__celltext--ref");
};
+const getPrimaryRowInfo = (blockElement: HTMLElement, rowElement: HTMLElement) => {
+ const cellElement = rowElement.querySelector('.av__cell[data-dtype="block"]') as HTMLElement;
+ if (cellElement) {
+ const value = genCellValueByElement("block", cellElement);
+ return {
+ cellElement,
+ value,
+ valueID: cellElement.dataset.id,
+ fieldID: cellElement.dataset.fieldId || cellElement.dataset.colId,
+ content: value.block?.content || "",
+ blockID: value.block?.id || "",
+ isDetached: isDetachedDatabaseCell(cellElement),
+ };
+ }
+ const cell = getAVPrimaryCell(blockElement, rowElement.dataset.id);
+ if (!cell?.value) {
+ return;
+ }
+ return {
+ value: cell.value,
+ valueID: cell.id,
+ fieldID: cell.value.keyID,
+ content: cell.value.block?.content || "",
+ blockID: cell.value.block?.id || "",
+ isDetached: cell.value.isDetached === true || !cell.value.block?.id,
+ };
+};
+
+const unbindDatabaseRow = (protyle: IProtyle, blockElement: HTMLElement, rowElement: HTMLElement,
+ primaryInfo: NonNullable<ReturnType<typeof getPrimaryRowInfo>>) => {
+ if (primaryInfo.cellElement) {
+ updateCellsValue(protyle, blockElement, {content: primaryInfo.content}, [primaryInfo.cellElement]);
+ return;
+ }
+ if (!primaryInfo.fieldID || !primaryInfo.valueID) {
+ return;
+ }
+ const newUpdated = dayjs().format("YYYYMMDDHHmmss");
+ const value: IAVCellValue = {
+ type: "block",
+ id: primaryInfo.valueID,
+ isDetached: true,
+ block: {
+ content: primaryInfo.content,
+ },
+ };
+ transaction(protyle, [{
+ action: "updateAttrViewCell",
+ id: primaryInfo.valueID,
+ avID: blockElement.dataset.avId,
+ keyID: primaryInfo.fieldID,
+ rowID: rowElement.dataset.id,
+ data: value,
+ }, {
+ action: "doUpdateUpdated",
+ id: blockElement.dataset.nodeId,
+ data: newUpdated,
+ }], [{
+ action: "updateAttrViewCell",
+ id: primaryInfo.valueID,
+ avID: blockElement.dataset.avId,
+ keyID: primaryInfo.fieldID,
+ rowID: rowElement.dataset.id,
+ data: primaryInfo.value,
+ }, {
+ action: "doUpdateUpdated",
+ id: blockElement.dataset.nodeId,
+ data: blockElement.getAttribute("updated"),
+ }]);
+ blockElement.setAttribute("updated", newUpdated);
+};
+
const openDatabaseRow = (protyle: IProtyle, target: HTMLElement, blockElement: HTMLElement) => {
- const cellElement = hasClosestByClassName(target, "av__cell") as HTMLElement;
const rowElement = hasClosestByClassName(target, "av__row") || hasClosestByClassName(target, "av__gallery-item");
- if (!cellElement || !rowElement) {
+ if (!rowElement) {
+ return;
+ }
+ const primaryInfo = getPrimaryRowInfo(blockElement, rowElement as HTMLElement);
+ if (!primaryInfo) {
return;
}
openDatabaseRowByData(protyle, {
@@ -68,10 +143,10 @@ const openDatabaseRow = (protyle: IProtyle, target: HTMLElement, blockElement: H
databaseBlockID: blockElement.dataset.nodeId,
notebookID: protyle.notebookId,
itemID: rowElement.getAttribute("data-id"),
- valueID: cellElement.dataset.id,
- title: cellElement.querySelector(".av__celltext")?.textContent.trim(),
- boundBlockID: cellElement.querySelector<HTMLElement>(".av__celltext--ref")?.dataset.id,
- isDetached: isDetachedDatabaseCell(cellElement),
+ valueID: primaryInfo.valueID,
+ title: primaryInfo.content.trim(),
+ boundBlockID: primaryInfo.blockID,
+ isDetached: primaryInfo.isDetached,
});
};
@@ -184,6 +259,11 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
event.preventDefault();
event.stopPropagation();
return true;
+ } else if (type === "av-gallery-open") {
+ openDatabaseRow(protyle, target, blockElement);
+ event.preventDefault();
+ event.stopPropagation();
+ return true;
} else if (type === "av-row-update" && !protyle.disabled) {
updateDatabaseRow(protyle, target);
event.preventDefault();
@@ -213,6 +293,12 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
event.preventDefault();
event.stopPropagation();
return true;
+ } else if (viewType === "gallery" && target.classList.contains("av__gallery-cover") &&
+ (hasClosestByClassName(target, "av__gallery-item") as HTMLElement)?.classList.contains("av__gallery-item--primary-hidden")) {
+ openDatabaseRow(protyle, target, blockElement);
+ event.preventDefault();
+ event.stopPropagation();
+ return true;
} else if (type === "set-page-size" && !protyle.disabled) {
setPageSize({
target,
@@ -527,9 +613,14 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
const menu = new Menu();
const rowElements = blockElement.querySelectorAll(".av__row--select:not(.av__row--header), .av__gallery-item--select");
const selectedItems = getAVSelectedItems(blockElement);
- const keyCellElement = rowElements[0].querySelector('.av__cell[data-dtype="block"]') as HTMLElement;
- const ids = Array.from(rowElements).map(item => item.querySelector('[data-dtype="block"] .av__celltext').getAttribute("data-id"));
- if (rowElements.length === 1 && keyCellElement.getAttribute("data-detached") !== "true") {
+ const primaryRows = Array.from(rowElements)
+ .map(item => getPrimaryRowInfo(blockElement, item as HTMLElement))
+ .filter((item): item is NonNullable<ReturnType<typeof getPrimaryRowInfo>> => Boolean(item));
+ if (primaryRows.length !== rowElements.length) {
+ return false;
+ }
+ const ids = primaryRows.map(item => item.blockID);
+ if (rowElements.length === 1 && !primaryRows[0].isDetached) {
/// #if !MOBILE
const blockId = ids[0];
const openSubmenus = openEditorTab(protyle.app, [blockId], undefined, undefined, true);
@@ -553,8 +644,8 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
/// #endif
}
let hasBlock = false;
- rowElements.forEach((item) => {
- if (item.querySelector('.av__cell[data-dtype="block"]').getAttribute("data-detached") !== "true") {
+ primaryRows.forEach((item) => {
+ if (!item.isDetached) {
hasBlock = true;
}
});
@@ -564,11 +655,11 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
label: window.siyuan.languages.copyKeyContent,
click() {
let text = "";
- rowElements.forEach((item, i) => {
+ primaryRows.forEach((item, i) => {
if (rowElements.length > 1) {
text += "- ";
}
- text += item.querySelector('.av__cell[data-dtype="block"] .av__celltext').textContent.trim();
+ text += item.content.trim();
if (ids.length > 1 && i !== ids.length - 1) {
text += "\n";
}
@@ -607,11 +698,11 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
for (let i = 0; i < ids.length; i++) {
const id = ids[i];
let content = "";
- const cellElement = rowElements[i].querySelector(".av__cell[data-dtype='block']");
- if (cellElement.getAttribute("data-detached") === "true") {
- content = cellElement.querySelector(".av__celltext").textContent;
+ const primaryInfo = primaryRows[i];
+ if (primaryInfo.isDetached) {
+ content = primaryInfo.content;
} else {
- content = `((${id} '${cellElement.querySelector(".av__celltext").textContent.replace(/[\n]+/g, " ")}'))`;
+ content = `((${id} '${primaryInfo.content.replace(/[\n]+/g, " ")}'))`;
}
if (ids.length > 1) {
text += "- ";
@@ -633,9 +724,9 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
if (ids.length > 1) {
text += "- ";
}
- const cellElement = rowElements[index].querySelector(".av__cell[data-dtype='block']");
- if (cellElement.getAttribute("data-detached") === "true") {
- text += cellElement.querySelector(".av__celltext").textContent;
+ const primaryInfo = primaryRows[index];
+ if (primaryInfo.isDetached) {
+ text += primaryInfo.content;
} else {
text += `{{select * from blocks where id='${id}'}}`;
}
@@ -655,9 +746,9 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
if (ids.length > 1) {
text += "- ";
}
- const cellElement = rowElements[index].querySelector(".av__cell[data-dtype='block']");
- if (cellElement.getAttribute("data-detached") === "true") {
- text += cellElement.querySelector(".av__celltext").textContent;
+ const primaryInfo = primaryRows[index];
+ if (primaryInfo.isDetached) {
+ text += primaryInfo.content;
} else {
text += `siyuan://blocks/${id}`;
}
@@ -676,11 +767,11 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
for (let i = 0; i < ids.length; i++) {
const id = ids[i];
let content = "";
- const cellElement = rowElements[i].querySelector(".av__cell[data-dtype='block']");
- if (cellElement.getAttribute("data-detached") === "true") {
- content = cellElement.querySelector(".av__celltext").textContent;
+ const primaryInfo = primaryRows[i];
+ if (primaryInfo.isDetached) {
+ content = primaryInfo.content;
} else {
- content = `[${cellElement.querySelector(".av__celltext").textContent.replace(/[\n]+/g, " ")}](siyuan://blocks/${id})`;
+ content = `[${primaryInfo.content.replace(/[\n]+/g, " ")}](siyuan://blocks/${id})`;
}
if (ids.length > 1) {
text += "- ";
@@ -701,9 +792,9 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
for (let i = 0; i < ids.length; i++) {
const id = ids[i];
let content = "";
- const cellElement = rowElements[i].querySelector(".av__cell[data-dtype='block']");
- if (cellElement.getAttribute("data-detached") === "true") {
- content = cellElement.querySelector(".av__celltext").textContent;
+ const primaryInfo = primaryRows[i];
+ if (primaryInfo.isDetached) {
+ content = primaryInfo.content;
} else {
const response = await fetchSyncPost("/api/filetree/getHPathByID", {id});
if (response.code !== 0 || typeof response.data !== "string") {
@@ -732,9 +823,9 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
if (ids.length > 1) {
text += "- ";
}
- const cellElement = rowElements[index].querySelector(".av__cell[data-dtype='block']");
- if (cellElement.getAttribute("data-detached") === "true") {
- text += cellElement.querySelector(".av__celltext").textContent;
+ const primaryInfo = primaryRows[index];
+ if (primaryInfo.isDetached) {
+ text += primaryInfo.content;
} else {
text += id;
}
@@ -803,14 +894,14 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
openSearchAV(blockElement.getAttribute("data-av-id"), rowElements[0] as HTMLElement, (listItemElement) => {
const srcs: IOperationSrcs[] = [];
const sourceIds: string[] = [];
- rowElements.forEach(item => {
+ rowElements.forEach((item, index) => {
const rowId = item.getAttribute("data-id");
- const blockValue = genCellValueByElement("block", item.querySelector('.av__cell[data-dtype="block"]'));
+ const primaryInfo = primaryRows[index];
srcs.push({
itemID: Lute.NewNodeID(),
- content: blockValue.block.content,
- id: blockValue.block.id || "",
- isDetached: blockValue.isDetached,
+ content: primaryInfo.content,
+ id: primaryInfo.blockID,
+ isDetached: primaryInfo.isDetached,
});
sourceIds.push(rowId);
});
@@ -838,7 +929,7 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
}
});
if (rowElements.length === 1) {
- if (keyCellElement.getAttribute("data-detached") !== "true") {
+ if (!primaryRows[0].isDetached) {
menu.addSeparator({id: "separator_1"});
}
menu.addItem({
@@ -912,15 +1003,18 @@ ${window.siyuan.languages[avType === "table" ? "insertRowAfter" : "insertItemAft
}
});
menu.addSeparator({id: "separator_2"});
- if (keyCellElement.getAttribute("data-detached") !== "true") {
+ if (!primaryRows[0].isDetached) {
menu.addItem({
id: "unbindBlock",
label: window.siyuan.languages.unbindBlock,
icon: "iconLinkOff",
click() {
- updateCellsValue(protyle, blockElement, {
- content: keyCellElement.querySelector(".av__celltext").textContent,
- }, [keyCellElement]);
+ unbindDatabaseRow(
+ protyle,
+ blockElement,
+ rowElements[0] as HTMLElement,
+ primaryRows[0]
+ );
}
});
}
diff --git a/app/src/protyle/render/av/col.ts b/app/src/protyle/render/av/col.ts
index 02a8b1f3d2..3cbfcb406c 100644
--- a/app/src/protyle/render/av/col.ts
+++ b/app/src/protyle/render/av/col.ts
@@ -205,13 +205,15 @@ export const getEditHTML = (options: {
<span class="fn__space fn__flex-1"></span>
<input type="checkbox" data-type="wrap" class="b3-switch b3-switch--menu"${colData.wrap ? " checked" : ""}>
</label>`;
- if (colData.type !== "block") {
- html += `${options.isCustomAttr ? "" : `<button class="b3-menu__item" data-type="${colData.hidden ? "showCol" : "hideCol"}">
+ if (colData.type !== "block" || options.data.viewType === "gallery") {
+ html += options.isCustomAttr ? "" : `<button class="b3-menu__item" data-type="${colData.hidden ? "showCol" : "hideCol"}">
<svg class="b3-menu__icon"><use xlink:href="#${colData.hidden ? "iconEye" : "iconEyeoff"}"></use></svg>
<span class="b3-menu__label">${colData.hidden ? window.siyuan.languages.showCol : window.siyuan.languages.hide}</span>
<svg class="b3-menu__action ariaLabel" data-position="4west" aria-label="${window.siyuan.languages.fieldVisibility}" data-type="fieldVisibility"><use xlink:href="#iconEdit"></use></svg>
-</button>`}
-<button class="b3-menu__item${colData.type === "relation" ? " fn__none" : ""}" data-type="duplicateCol">
+</button>`;
+ }
+ if (colData.type !== "block") {
+ html += `<button class="b3-menu__item${colData.type === "relation" ? " fn__none" : ""}" data-type="duplicateCol">
<svg class="b3-menu__icon" style=""><use xlink:href="#iconCopy"></use></svg>
<span class="b3-menu__label">${window.siyuan.languages.duplicate}</span>
</button>
@@ -1089,6 +1091,7 @@ export const showColMenu = (protyle: IProtyle, blockElement: Element, cellElemen
protyle,
blockElement,
colId,
+ fieldType: type,
});
});
}
@@ -1377,7 +1380,10 @@ export const removeCol = (options: {
if (options.isCustomAttr) {
options.avPanelElement.remove();
} else {
- options.menuElement.innerHTML = getPropertiesHTML(options.fields);
+ options.menuElement.innerHTML = getPropertiesHTML(
+ options.fields,
+ options.blockElement.getAttribute("data-av-type") as TAVView
+ );
setPosition(options.menuElement,
options.tabRect.right - options.menuElement.clientWidth, options.tabRect.bottom,
options.tabRect.height, 0, true);
diff --git a/app/src/protyle/render/av/fieldVisibility.ts b/app/src/protyle/render/av/fieldVisibility.ts
index ba8591efb3..70ff0f3893 100644
--- a/app/src/protyle/render/av/fieldVisibility.ts
+++ b/app/src/protyle/render/av/fieldVisibility.ts
@@ -33,6 +33,13 @@ const fetchFieldViews = async (avID: string, colId: string) => {
return response.data.views as IAVFieldView[];
};
+const getSupportedFieldViews = (views: IAVFieldView[] | undefined, fieldType?: TAVCol) => {
+ if (!views) {
+ return;
+ }
+ return fieldType === "block" ? views.filter(view => view.type === "gallery") : views;
+};
+
const setFieldVisibility = (options: {
protyle: IProtyle;
avID: string;
@@ -152,6 +159,7 @@ export const openFieldVisibility = async (options: {
protyle: IProtyle;
blockElement: Element;
colId: string;
+ fieldType?: TAVCol;
}) => {
document.querySelector(".av__panel")?.remove();
const menu = window.siyuan.menus.menu;
@@ -161,7 +169,7 @@ export const openFieldVisibility = async (options: {
const previousWidth = menuElement.style.width;
const previousRemoveCB = menu.removeCB;
const avID = options.blockElement.getAttribute("data-av-id");
- const views = await fetchFieldViews(avID, options.colId);
+ const views = getSupportedFieldViews(await fetchFieldViews(avID, options.colId), options.fieldType);
if (!views || menuElement.classList.contains("fn__none") || menuElement.lastElementChild !== previousItemsElement) {
return;
}
@@ -260,7 +268,7 @@ export const openFieldVisibilityPanel = async (options: {
options.blockElement.querySelector(".layout-tab-bar .item--focus")?.getAttribute("data-id");
const panelRect = options.menuElement.getBoundingClientRect();
const previousItemsElement = options.menuElement.firstElementChild;
- const views = await fetchFieldViews(avID, options.colId);
+ const views = getSupportedFieldViews(await fetchFieldViews(avID, options.colId), options.field.type);
if (!views || !options.menuElement.isConnected ||
options.menuElement.firstElementChild !== previousItemsElement) {
return;
diff --git a/app/src/protyle/render/av/gallery/item.ts b/app/src/protyle/render/av/gallery/item.ts
index b3ed19ee09..8e7f83d66c 100644
--- a/app/src/protyle/render/av/gallery/item.ts
+++ b/app/src/protyle/render/av/gallery/item.ts
@@ -58,10 +58,13 @@ ${fieldType === "block" ? ' data-detached="true"' : ""}>${renderCell(genCellValu
clearSelect(["galleryItem"], options.blockElement);
let html = "";
const coverClass = sideItemElement?.querySelector(".av__gallery-cover")?.className || "fn__none";
+ const fieldsClass = sideItemElement?.querySelector(".av__gallery-fields")?.className || "av__gallery-fields";
+ const emptyClass = coverClass === "fn__none" && fieldsClass.includes("fn__none") ?
+ " av__gallery-item--empty" : "";
options.srcIDs.forEach(() => {
- html += `<div class="av__gallery-item" data-type="ghost">
+ html += `<div class="av__gallery-item${emptyClass}" data-type="ghost">
<div class="${coverClass}"><span style="width: 100%;height: 100%;border-radius: var(--b3-border-radius) var(--b3-border-radius) 0 0;" class="av__pulse"></span></div>
- <div class="av__gallery-fields">${cellsHTML}</div>
+ <div class="${fieldsClass}">${cellsHTML}</div>
</div>`;
});
if (sideItemElement) {
diff --git a/app/src/protyle/render/av/openMenuPanel.ts b/app/src/protyle/render/av/openMenuPanel.ts
index 2754d05450..b7bc6080cb 100644
--- a/app/src/protyle/render/av/openMenuPanel.ts
+++ b/app/src/protyle/render/av/openMenuPanel.ts
@@ -134,7 +134,7 @@ export const openMenuPanel = (options: {
if (options.type === "config") {
html = getViewHTML(data);
} else if (options.type === "properties") {
- html = getPropertiesHTML(fields);
+ html = getPropertiesHTML(fields, data.viewType);
} else if (options.type === "sorts") {
html = getSortsHTML(fields, data.view.sorts);
} else if (options.type === "switcher") {
@@ -519,7 +519,7 @@ export const openMenuPanel = (options: {
}
});
}
- menuElement.innerHTML = getPropertiesHTML(fields);
+ menuElement.innerHTML = getPropertiesHTML(fields, data.viewType);
return;
}
// 分组项拖拽排序
@@ -802,7 +802,7 @@ export const openMenuPanel = (options: {
// 复制列后点击返回到属性面板,宽度不一致,需重新计算
tabRect = options.blockElement.querySelector(".av__views").getBoundingClientRect();
menuElement.classList.remove("av__filter-panel");
- menuElement.innerHTML = getPropertiesHTML(fields);
+ menuElement.innerHTML = getPropertiesHTML(fields, data.viewType);
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);
window.siyuan.menus.menu.remove();
event.preventDefault();
@@ -1251,7 +1251,7 @@ export const openMenuPanel = (options: {
});
if (doOperations.length > 0) {
transaction(options.protyle, doOperations, undoOperations);
- menuElement.innerHTML = getPropertiesHTML(fields);
+ menuElement.innerHTML = getPropertiesHTML(fields, data.viewType);
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);
}
event.preventDefault();
@@ -1261,7 +1261,7 @@ export const openMenuPanel = (options: {
const doOperations: IOperation[] = [];
const undoOperations: IOperation[] = [];
fields.forEach((item: IAVColumn) => {
- if (!item.hidden && item.type !== "block") {
+ if (!item.hidden && (item.type !== "block" || data.viewType === "gallery")) {
doOperations.push({
action: "setAttrViewColHidden",
id: item.id,
@@ -1283,7 +1283,7 @@ export const openMenuPanel = (options: {
});
if (doOperations.length > 0) {
transaction(options.protyle, doOperations, undoOperations);
- menuElement.innerHTML = getPropertiesHTML(fields);
+ menuElement.innerHTML = getPropertiesHTML(fields, data.viewType);
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);
}
event.preventDefault();
@@ -1485,7 +1485,7 @@ export const openMenuPanel = (options: {
});
bindEditEvent({protyle: options.protyle, data, menuElement, isCustomAttr, blockID});
} else {
- menuElement.innerHTML = getPropertiesHTML(fields);
+ menuElement.innerHTML = getPropertiesHTML(fields, data.viewType);
}
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);
event.preventDefault();
@@ -1519,7 +1519,7 @@ export const openMenuPanel = (options: {
});
bindEditEvent({protyle: options.protyle, data, menuElement, isCustomAttr, blockID});
} else {
- menuElement.innerHTML = getPropertiesHTML(fields);
+ menuElement.innerHTML = getPropertiesHTML(fields, data.viewType);
}
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);
event.preventDefault();
@@ -2013,7 +2013,7 @@ export const openMenuPanel = (options: {
}
};
-export const getPropertiesHTML = (fields: IAVColumn[]) => {
+export const getPropertiesHTML = (fields: IAVColumn[], viewType: TAVView) => {
let showHTML = "";
let hideHTML = "";
fields.forEach((item: IAVColumn) => {
@@ -2034,7 +2034,7 @@ export const getPropertiesHTML = (fields: IAVColumn[]) => {
${item.icon ? unicode2Emoji(item.icon, "b3-menu__icon", true) : `<svg class="b3-menu__icon"><use xlink:href="#${getColIconByType(item.type)}"></use></svg>`}
${escapeHtml(item.name) || "&nbsp;"}
</div>
- <svg class="b3-menu__action${item.type === "block" ? " fn__none" : ""}" data-type="hideCol"><use xlink:href="#iconEyeoff"></use></svg>
+ <svg class="b3-menu__action${item.type === "block" && viewType !== "gallery" ? " fn__none" : ""}" data-type="hideCol"><use xlink:href="#iconEyeoff"></use></svg>
<svg class="b3-menu__icon b3-menu__icon--small"><use xlink:href="#iconRight"></use></svg>
</button>`;
}
diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.ts
index 9bab3995de..b468d8cdfe 100644
--- a/app/src/protyle/render/av/render.ts
+++ b/app/src/protyle/render/av/render.ts
@@ -836,15 +836,12 @@ export const refreshAV = (protyle: IProtyle, operation: IOperation) => {
if (!positionElement) {
return;
}
- const editElement = galleryItem.querySelector<HTMLElement>('[data-type="av-gallery-edit"]');
- const moreElement = galleryItem.querySelector<HTMLElement>('[data-type="av-gallery-more"]');
- if (!editElement || !moreElement) {
- return;
- }
positionElement.classList.toggle("fn__none", Boolean(operation.data));
- editElement.classList.toggle("protyle-icon--first", Boolean(operation.data));
- moreElement.classList.toggle("protyle-icon--first",
- Boolean(operation.data) && editElement.classList.contains("fn__none"));
+ const actionElements =
+ Array.from(galleryItem.querySelectorAll<HTMLElement>(".av__gallery-actions .protyle-icon"));
+ actionElements.forEach(actionElement => actionElement.classList.remove("protyle-icon--first"));
+ actionElements.find(actionElement => !actionElement.classList.contains("fn__none"))
+ ?.classList.add("protyle-icon--first");
});
});
return;
diff --git a/app/src/protyle/render/av/row.ts b/app/src/protyle/render/av/row.ts
index e6398485e7..efa1a5a5f1 100644
--- a/app/src/protyle/render/av/row.ts
+++ b/app/src/protyle/render/av/row.ts
@@ -20,17 +20,26 @@ import {getColIconByType, getColNameByType} from "./col";
import {unicode2Emoji} from "../../../emoji";
import {escapeAttr} from "../../../util/escape";
import {getCompressURL} from "../../../util/image";
-import {getAVSelectStat, getAvBodyData, resetAVRowSelect, updateAVRowSelect} from "./virtualScroll";
+import {
+ getAVPrimaryCell,
+ getAVSelectStat,
+ getAvBodyData,
+ resetAVRowSelect,
+ updateAVRowSelect
+} from "./virtualScroll";
import {getCardCoverHTML, getCardCoverSource} from "./cover";
-const getGalleryActionsHTML = (data: IAVGallery | IAVKanban, row: IAVGalleryItem) => {
+const getGalleryActionsHTML = (data: IAVGallery | IAVKanban, row: IAVGalleryItem, primaryHidden = false) => {
const canPosition = Boolean(row.coverURL && !row.coverURL.startsWith("background") && getCardCoverSource(data));
const positionHTML = canPosition ? `<span class="protyle-icon protyle-icon--first ariaLabel${data.fitImage ? " fn__none" : ""}" data-position="4north" aria-label="${window.siyuan.languages.dragPosition}" data-type="av-cover-position"><svg><use xlink:href="#iconMove"></use></svg></span>` : "";
const editFirst = !canPosition || data.fitImage;
- const moreFirst = editFirst && data.displayEmptyFields;
+ const openFirst = editFirst && data.displayEmptyFields;
+ const openHTML = primaryHidden ? `<span class="protyle-icon${openFirst ? " protyle-icon--first" : ""} ariaLabel" data-position="4north" aria-label="${window.siyuan.languages.openBy}" data-type="av-gallery-open"><svg><use xlink:href="#iconOpen"></use></svg></span>` : "";
+ const moreFirst = editFirst && data.displayEmptyFields && !primaryHidden;
return `<div class="av__gallery-actions">
${positionHTML}
<span class="protyle-icon${editFirst ? " protyle-icon--first" : ""} ariaLabel${data.displayEmptyFields ? " fn__none" : ""}" data-position="4north" aria-label="${window.siyuan.languages.displayEmptyFields}" data-type="av-gallery-edit"><svg><use xlink:href="#iconEdit"></use></svg></span>
+ ${openHTML}
<span class="protyle-icon${moreFirst ? " protyle-icon--first" : ""} protyle-icon--last ariaLabel" data-position="4north" aria-label="${window.siyuan.languages.more}" data-type="av-gallery-more"><svg><use xlink:href="#iconMore"></use></svg></span>
</div>`;
};
@@ -45,22 +54,25 @@ export const getRowHTML = (options: {
let html = "";
if (options.type === "gallery") {
const galleryRow = options.row as IAVGalleryItem;
- const kanbanData = options.data as IAVGallery;
- html += `<div data-id="${galleryRow.id}" data-index="${options.rowIndex}" draggable="true" class="av__gallery-item">`;
- if (kanbanData.coverFrom !== 0) {
- const coverClass = "av__gallery-cover av__gallery-cover--" + kanbanData.cardAspectRatio;
+ const galleryData = options.data as IAVGallery;
+ const primaryHidden = galleryData.fields.find(field => field.type === "block")?.hidden === true;
+ const hasVisibleFields = galleryData.fields.some(field => !field.hidden);
+ const emptyClass = !hasVisibleFields && galleryData.coverFrom === 0 ? " av__gallery-item--empty" : "";
+ html += `<div data-id="${galleryRow.id}" data-index="${options.rowIndex}" draggable="true" class="av__gallery-item${primaryHidden ? " av__gallery-item--primary-hidden" : ""}${emptyClass}">`;
+ if (galleryData.coverFrom !== 0) {
+ const coverClass = "av__gallery-cover av__gallery-cover--" + galleryData.cardAspectRatio;
if (galleryRow.coverURL) {
html += getCardCoverHTML(coverClass, galleryRow.coverURL, getCompressURL(galleryRow.coverURL),
- kanbanData.fitImage, getCardCoverSource(kanbanData), galleryRow.coverPosition);
+ galleryData.fitImage, getCardCoverSource(galleryData), galleryRow.coverPosition);
} else if (galleryRow.coverContent) {
html += `<div class="${coverClass}"><div class="av__gallery-content">${galleryRow.coverContent}</div><div></div></div>`;
} else {
html += `<div class="${coverClass}"></div>`;
}
}
- html += '<div class="av__gallery-fields">';
+ html += `<div class="av__gallery-fields${hasVisibleFields ? "" : " fn__none"}">`;
galleryRow.values.forEach((cell, fieldsIndex) => {
- if (kanbanData.fields[fieldsIndex].hidden) {
+ if (galleryData.fields[fieldsIndex].hidden) {
return;
}
let checkClass = "";
@@ -69,43 +81,43 @@ export const getRowHTML = (options: {
}
const isEmpty = cellValueIsEmpty(cell.value);
// NOTE: innerHTML 中不能换行否则 https://github.com/siyuan-note/siyuan/issues/15132
- let ariaLabel = escapeAttr(kanbanData.fields[fieldsIndex].name) || getColNameByType(kanbanData.fields[fieldsIndex].type);
- if (kanbanData.fields[fieldsIndex].desc) {
- ariaLabel += escapeAttr(`<div class="ft__on-surface">${kanbanData.fields[fieldsIndex].desc}</div>`);
+ let ariaLabel = escapeAttr(galleryData.fields[fieldsIndex].name) || getColNameByType(galleryData.fields[fieldsIndex].type);
+ if (galleryData.fields[fieldsIndex].desc) {
+ ariaLabel += escapeAttr(`<div class="ft__on-surface">${galleryData.fields[fieldsIndex].desc}</div>`);
}
- if (cell.valueType === "checkbox" && !kanbanData.displayFieldName) {
- cell.value.checkbox.content = kanbanData.fields[fieldsIndex].name || getColNameByType(kanbanData.fields[fieldsIndex].type);
+ if (cell.valueType === "checkbox" && !galleryData.displayFieldName) {
+ cell.value.checkbox.content = galleryData.fields[fieldsIndex].name || getColNameByType(galleryData.fields[fieldsIndex].type);
}
- const cellHTML = `<div class="av__cell${checkClass}${kanbanData.displayFieldName ? "" : " ariaLabel"}"
-data-wrap="${kanbanData.fields[fieldsIndex].wrap}"
+ const cellHTML = `<div class="av__cell${checkClass}${galleryData.displayFieldName ? "" : " ariaLabel"}"
+data-wrap="${galleryData.fields[fieldsIndex].wrap}"
aria-label="${ariaLabel}"
data-position="5west"
data-id="${cell.id}"
-data-field-id="${kanbanData.fields[fieldsIndex].id}"
+data-field-id="${galleryData.fields[fieldsIndex].id}"
data-dtype="${cell.valueType}"
${cell.value?.isDetached ? ' data-detached="true"' : ""}
style="${cell.bgColor ? `background-color:${cell.bgColor};` : ""}
-${cell.color ? `color:${cell.color};` : ""}">${renderCell(cell.value, options.rowIndex, kanbanData.showIcon, "gallery", kanbanData.fields[fieldsIndex].options)}</div>`;
- if (kanbanData.displayFieldName) {
+${cell.color ? `color:${cell.color};` : ""}">${renderCell(cell.value, options.rowIndex, galleryData.showIcon, "gallery", galleryData.fields[fieldsIndex].options)}</div>`;
+ if (galleryData.displayFieldName) {
html += `<div class="av__gallery-field av__gallery-field--name" data-empty="${isEmpty}">
<div class="av__gallery-name">
- ${kanbanData.fields[fieldsIndex].icon ? unicode2Emoji(kanbanData.fields[fieldsIndex].icon, undefined, true) : `<svg><use xlink:href="#${getColIconByType(kanbanData.fields[fieldsIndex].type)}"></use></svg>`}${Lute.EscapeHTMLStr(kanbanData.fields[fieldsIndex].name)}
- ${kanbanData.fields[fieldsIndex].desc ? `<svg aria-label="${kanbanData.fields[fieldsIndex].desc}" data-position="north" class="ariaLabel"><use xlink:href="#iconInfo"></use></svg>` : ""}
+ ${galleryData.fields[fieldsIndex].icon ? unicode2Emoji(galleryData.fields[fieldsIndex].icon, undefined, true) : `<svg><use xlink:href="#${getColIconByType(galleryData.fields[fieldsIndex].type)}"></use></svg>`}${Lute.EscapeHTMLStr(galleryData.fields[fieldsIndex].name)}
+ ${galleryData.fields[fieldsIndex].desc ? `<svg aria-label="${galleryData.fields[fieldsIndex].desc}" data-position="north" class="ariaLabel"><use xlink:href="#iconInfo"></use></svg>` : ""}
</div>
${cellHTML}
</div>`;
} else {
html += `<div class="av__gallery-field" data-empty="${isEmpty}">
<div class="av__gallery-tip">
- ${kanbanData.fields[fieldsIndex].icon ? unicode2Emoji(kanbanData.fields[fieldsIndex].icon, undefined, true) : `<svg><use xlink:href="#${getColIconByType(kanbanData.fields[fieldsIndex].type)}"></use></svg>`}${window.siyuan.languages.edit} ${Lute.EscapeHTMLStr(kanbanData.fields[fieldsIndex].name)}
+ ${galleryData.fields[fieldsIndex].icon ? unicode2Emoji(galleryData.fields[fieldsIndex].icon, undefined, true) : `<svg><use xlink:href="#${getColIconByType(galleryData.fields[fieldsIndex].type)}"></use></svg>`}${window.siyuan.languages.edit} ${Lute.EscapeHTMLStr(galleryData.fields[fieldsIndex].name)}
</div>
${cellHTML}
</div>`;
}
});
html += `</div>
- ${getGalleryActionsHTML(kanbanData, galleryRow)}
+ ${getGalleryActionsHTML(galleryData, galleryRow, primaryHidden)}
</div>`;
return html;
}
@@ -794,14 +806,22 @@ export const deleteRow = (blockElement: HTMLElement, protyle: IProtyle) => {
if (rowElements.length === 0) {
return;
}
+ const primaryValues = Array.from(rowElements).map((item: HTMLElement) => {
+ const cellElement = item.querySelector('.av__cell[data-dtype="block"]') as HTMLElement;
+ return cellElement ? genCellValueByElement("block", cellElement) :
+ getAVPrimaryCell(blockElement, item.dataset.id)?.value;
+ });
+ if (primaryValues.some(value => !value)) {
+ return;
+ }
const avID = blockElement.getAttribute("data-av-id");
const undoOperations: IOperation[] = [];
const blockIds: string[] = [];
rowElements.forEach(item => {
blockIds.push(item.getAttribute("data-id"));
});
- rowElements.forEach(item => {
- const blockValue = genCellValueByElement("block", item.querySelector('.av__cell[data-dtype="block"]'));
+ rowElements.forEach((item, index) => {
+ const blockValue = primaryValues[index];
const itemID = Lute.NewNodeID();
// 撤销会使用新的条目 ID 恢复该行,重做时需要同时删除这个新条目。
blockIds.push(itemID);
diff --git a/app/src/protyle/render/av/virtualScroll.ts b/app/src/protyle/render/av/virtualScroll.ts
index 7c959fcbf4..3f3145ad10 100644
--- a/app/src/protyle/render/av/virtualScroll.ts
+++ b/app/src/protyle/render/av/virtualScroll.ts
@@ -484,8 +484,10 @@ export const getAVSelectedItems = (blockElement: HTMLElement): { itemID: string,
bodyElement.querySelectorAll(".av__row--select:not(.av__row--header), .av__gallery-item--select").forEach((item: HTMLElement) => {
const itemID = item.dataset.id;
const blockCell = item.querySelector('.av__cell[data-dtype="block"]') as HTMLElement;
- if (itemID && blockCell) {
- selectedItems.set(itemID, blockCell.dataset.detached === "true");
+ const primaryCell = getAVPrimaryCell(blockElement, itemID);
+ if (itemID && (blockCell || primaryCell)) {
+ selectedItems.set(itemID, blockCell ?
+ blockCell.dataset.detached === "true" : primaryCell.value?.isDetached === true);
}
});
});
@@ -496,6 +498,30 @@ export const getAVData = (blockElement: HTMLElement) => {
return blockDataStore.get(blockElement);
};
+export const getAVPrimaryCell = (blockElement: HTMLElement, itemID: string) => {
+ const data = blockDataStore.get(blockElement);
+ if (!data || !itemID) {
+ return;
+ }
+ let primaryCell: IAVCell;
+ const findPrimaryCell = (view: IAVView) => {
+ if (view.groups?.length > 0) {
+ return view.groups.some(findPrimaryCell);
+ }
+ const items: Array<IAVRow | IAVGalleryItem> =
+ (view as IAVTable).rows || (view as IAVGallery).cards || [];
+ const item = items.find((row: IAVRow | IAVGalleryItem) => row.id === itemID);
+ if (!item) {
+ return false;
+ }
+ const cells = "cells" in item ? item.cells : item.values;
+ primaryCell = cells.find((cell: IAVCell) => cell.valueType === "block" || cell.value?.type === "block");
+ return true;
+ };
+ findPrimaryCell(data.view);
+ return primaryCell;
+};
+
export const setAVData = (blockElement: HTMLElement, data: IAV) => {
blockDataStore.set(blockElement, data);
};