Vanessa 2025-06-15 11:38:51 +08:00
parent 881b2ad819
commit 0aeb0bfea8
5 changed files with 64 additions and 6 deletions

View file

@ -352,6 +352,18 @@
word-break: break-all;
white-space: pre-wrap;
}
&--edit {
.av__cell {
min-height: 1.625em;
&[data-empty="true"]:after {
content: attr(aria-label);
position: absolute;
color: var(--b3-theme-on-surface-light);
}
}
}
}
&-add {

View file

@ -34,7 +34,7 @@ import {hideElements} from "../../ui/hideElements";
import {fetchPost, fetchSyncPost} from "../../../util/fetch";
import {scrollCenter} from "../../../util/highlightById";
import {escapeHtml} from "../../../util/escape";
import {openGalleryItemMenu} from "./gallery/util";
import {editGalleryItem, openGalleryItemMenu} from "./gallery/util";
export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLElement }) => {
if (isOnlyMeta(event)) {
@ -273,6 +273,7 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
event.stopPropagation();
return true;
} else if (type === "av-gallery-edit") {
editGalleryItem(target);
event.preventDefault();
event.stopPropagation();
return true;

View file

@ -237,7 +237,6 @@ const transformCellValue = (colType: TAVCol, value: IAVCellValue): IAVCellValue
return newValue;
};
export const genCellValue = (colType: TAVCol, value: string | any) => {
let cellValue: IAVCellValue = {
type: colType,
@ -521,7 +520,13 @@ export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[], type
} else if (type === "relation") {
openMenuPanel({protyle, blockElement, type: "relation", cellElements});
} else if (type === "rollup") {
openMenuPanel({protyle, blockElement, type: "rollup", cellElements, colId: getColId(cellElements[0], viewType)});
openMenuPanel({
protyle,
blockElement,
type: "rollup",
cellElements,
colId: getColId(cellElements[0], viewType)
});
}
if (viewType === "table" && !hasClosestByClassName(cellElements[0], "custom-attr")) {
cellElements[0].classList.add("av__cell--select");
@ -733,7 +738,7 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, va
return;
}
const cellId = item.dataset.id; // 刚创建时无 id更新需和 oldValue 保持一致
const colId = getColId(item, viewType)
const colId = getColId(item, viewType);
text += getCellText(item) + ((cellElements[elementIndex + 1] && item.nextElementSibling && item.nextElementSibling.isSameNode(cellElements[elementIndex + 1])) ? "\t" : "\n\n");
const oldValue = genCellValueByElement(type, item);
@ -1172,3 +1177,34 @@ export const addDragFill = (cellElement: Element) => {
cellElement.insertAdjacentHTML("beforeend", `<div aria-label="${window.siyuan.languages.dragFill}" class="av__drag-fill ariaLabel"></div>`);
}
};
export const cellValueIsEmpty = (value: IAVCellValue) => {
if (value.type === "checkbox") {
return false;
}
if (["text", "number", "block", "url", "phone", "email", "template"].includes(value.type)) {
return !value[value.type as "text"]?.content;
}
if (["mSelect", "mAsset", "select"].includes(value.type)) {
if (value[value.type as "mSelect"]?.length > 0) {
return false;
}
return true;
}
if (["date", "created", "updated"].includes(value.type)) {
return !value[value.type as "date"]?.isNotEmpty &&
!value[value.type as "date"]?.isNotEmpty2;
}
if (value.type === "relation") {
if (value.relation?.blockIDs && value.relation.blockIDs.length > 0) {
return false;
}
return true;
}
if (value.type === "rollup") {
if (value.rollup?.contents && value.rollup.contents.length > 0) {
return false;
}
return true;
}
};

View file

@ -3,7 +3,7 @@ import {Constants} from "../../../../constants";
import {fetchPost} from "../../../../util/fetch";
import {escapeAriaLabel, escapeAttr, escapeHtml} from "../../../../util/escape";
import {unicode2Emoji} from "../../../../emoji";
import {renderCell} from "../cell";
import {cellValueIsEmpty, renderCell} from "../cell";
import {focusBlock} from "../../../util/selection";
import {electronUndo} from "../../../undo";
import {addClearButton} from "../../../../util/addClearButton";
@ -95,8 +95,10 @@ export const renderGallery = (options: {
if (cell.valueType === "checkbox") {
checkClass = cell.value?.checkbox?.checked ? " av__cell-check" : " av__cell-uncheck";
}
const isEmpty = cellValueIsEmpty(cell.value);
galleryHTML += `<div class="av__cell${checkClass} ariaLabel"
aria-label="${escapeAttr(view.fields[fieldsIndex].name)}"
data-empty="${isEmpty}"
aria-label="${isEmpty ? window.siyuan.languages.edit + " " : ""}${escapeAttr(view.fields[fieldsIndex].name)}"
data-position="5west"
data-id="${cell.id}"
data-field-id="${view.fields[fieldsIndex].id}"

View file

@ -223,3 +223,10 @@ export const openGalleryItemMenu = (options: {
y: rect.bottom
});
};
export const editGalleryItem = (taget: Element) => {
const itemElement = hasClosestByClassName(taget, "av__gallery-item");
if (itemElement) {
itemElement.querySelector(".av__gallery-fields")?.classList.toggle("av__gallery-fields--edit");
}
};