Vanessa 2025-08-10 12:10:39 +08:00
parent aaf1d9896a
commit 2cd76dc288
11 changed files with 25 additions and 43 deletions

View file

@ -605,7 +605,7 @@
white-space: nowrap; white-space: nowrap;
} }
&[data-block-id] > .block__icon[data-type="copy"] { &[data-dtype="block"] > .block__icon[data-type="copy"] {
display: none; display: none;
} }

View file

@ -823,7 +823,7 @@
} }
} }
.av__row .av__cell[data-block-id] > .block__icon[data-type="copy"] { .av__row .av__cell[data-dtype="block"] > .block__icon[data-type="copy"] {
display: flex; display: flex;
} }
} }

View file

@ -439,7 +439,7 @@ ${genHintItemHTML(item)}
if (!rowElement) { if (!rowElement) {
return; return;
} }
const previousID = cellElement.dataset.blockId; const previousID = rowElement.dataset.id;
const avID = nodeElement.getAttribute("data-av-id"); const avID = nodeElement.getAttribute("data-av-id");
let tempElement = document.createElement("div"); let tempElement = document.createElement("div");
tempElement.innerHTML = value.replace(/<mark>/g, "").replace(/<\/mark>/g, ""); tempElement.innerHTML = value.replace(/<mark>/g, "").replace(/<\/mark>/g, "");

View file

@ -355,7 +355,7 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
} }
const menu = new Menu(); const menu = new Menu();
const rowElements = blockElement.querySelectorAll(".av__row--select:not(.av__row--header), .av__gallery-item--select"); const rowElements = blockElement.querySelectorAll(".av__row--select:not(.av__row--header), .av__gallery-item--select");
const keyCellElement = rowElements[0].querySelector(".av__cell[data-block-id]") as HTMLElement; const keyCellElement = rowElements[0].querySelector('.av__cell[data-dtype="block"]') as HTMLElement;
const ids = Array.from(rowElements).map(item => item.getAttribute("data-id")); const ids = Array.from(rowElements).map(item => item.getAttribute("data-id"));
if (rowElements.length === 1 && keyCellElement.getAttribute("data-detached") !== "true") { if (rowElements.length === 1 && keyCellElement.getAttribute("data-detached") !== "true") {
/// #if !MOBILE /// #if !MOBILE
@ -569,7 +569,7 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
const sourceIds: string[] = []; const sourceIds: string[] = [];
rowElements.forEach(item => { rowElements.forEach(item => {
const rowId = item.getAttribute("data-id"); const rowId = item.getAttribute("data-id");
const blockValue = genCellValueByElement("block", item.querySelector(".av__cell[data-block-id]")); const blockValue = genCellValueByElement("block", item.querySelector('.av__cell[data-dtype="block"]'));
srcs.push({ srcs.push({
content: blockValue.block.content, content: blockValue.block.content,
id: rowId, id: rowId,

View file

@ -23,9 +23,9 @@ const genAVRollupHTML = (value: IAVCellValue) => {
switch (value.type) { switch (value.type) {
case "block": case "block":
if (value?.isDetached) { if (value?.isDetached) {
html = `<span data-id="${value.block?.id}">${value.block?.content || window.siyuan.languages.untitled}</span>`; html = `<span>${value.block?.content || window.siyuan.languages.untitled}</span>`;
} else { } else {
html = `<span data-type="block-ref" data-id="${value.block?.id}" data-subtype="s" class="av__celltext--ref">${value.block?.content || window.siyuan.languages.untitled}</span>`; html = `<span data-type="block-ref" data-id="${value.block.id}" data-subtype="s" class="av__celltext--ref">${value.block?.content || window.siyuan.languages.untitled}</span>`;
} }
break; break;
case "text": case "text":
@ -62,7 +62,7 @@ export const genAVValueHTML = (value: IAVCellValue) => {
let html = ""; let html = "";
switch (value.type) { switch (value.type) {
case "block": case "block":
html = `<input value="${escapeAttr(value.block.content)}" type="text" class="b3-text-field b3-text-field--text fn__flex-1" placeholder="${window.siyuan.languages.empty}">`; 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; break;
case "text": 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}">${value.text?.content || ""}</textarea>`; 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}">${value.text?.content || ""}</textarea>`;
@ -130,7 +130,7 @@ export const genAVValueHTML = (value: IAVCellValue) => {
value?.relation?.contents?.forEach((item) => { value?.relation?.contents?.forEach((item) => {
if (item && item.block) { if (item && item.block) {
if (item?.isDetached) { if (item?.isDetached) {
html += `<span class="av__cell--relation"><span> </span><span class="av__celltext" data-id="${item.block?.id}">${Lute.EscapeHTMLStr(item.block.content || window.siyuan.languages.untitled)}</span></span>`; html += `<span class="av__cell--relation"><span> </span><span class="av__celltext">${Lute.EscapeHTMLStr(item.block.content || window.siyuan.languages.untitled)}</span></span>`;
} else { } else {
// data-block-id 用于更新 emoji // data-block-id 用于更新 emoji
html += `<span 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>`; html += `<span 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>`;
@ -198,7 +198,7 @@ export const renderAVAttribute = (element: HTMLElement, id: string, protyle: IPr
${item.key.icon ? unicode2Emoji(item.key.icon, "block__logoicon", true) : `<svg class="block__logoicon"><use xlink:href="#${getColIconByType(item.key.type)}"></use></svg>`} ${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> <span>${escapeHtml(item.key.name)}</span>
</div> </div>
<div data-av-id="${table.avID}" data-col-id="${item.values[0].keyID}" data-block-id="${item.values[0].blockID}" data-id="${item.values[0].id}" data-type="${item.values[0].type}" <div data-av-id="${table.avID}" data-col-id="${item.values[0].keyID}" data-row-id="${item.values[0].blockID}" data-id="${item.values[0].id}" data-type="${item.values[0].type}"
data-options="${item.key?.options ? escapeAttr(JSON.stringify(item.key.options)) : "[]"}" data-options="${item.key?.options ? escapeAttr(JSON.stringify(item.key.options)) : "[]"}"
${["text", "number", "date", "url", "phone", "template", "email"].includes(item.values[0].type) ? "" : `placeholder="${window.siyuan.languages.empty}"`} ${["text", "number", "date", "url", "phone", "template", "email"].includes(item.values[0].type) ? "" : `placeholder="${window.siyuan.languages.empty}"`}
class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone", "block"].includes(item.values[0].type) ? "" : " custom-attr__avvalue"}${["created", "updated"].includes(item.values[0].type) ? " custom-attr__avvalue--readonly" : ""}">${genAVValueHTML(item.values[0])}</div> class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone", "block"].includes(item.values[0].type) ? "" : " custom-attr__avvalue"}${["created", "updated"].includes(item.values[0].type) ? " custom-attr__avvalue--readonly" : ""}">${genAVValueHTML(item.values[0])}</div>
@ -424,7 +424,7 @@ class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone", "block"]
value = { value = {
block: { block: {
content: item.value, content: item.value,
id: item.parentElement.dataset.blockId, id: item.dataset.id,
}, },
isDetached: false isDetached: false
}; };
@ -432,7 +432,7 @@ class="fn__flex-1 fn__flex${["url", "text", "number", "email", "phone", "block"]
fetchPost("/api/av/setAttributeViewBlockAttr", { fetchPost("/api/av/setAttributeViewBlockAttr", {
avID: item.parentElement.dataset.avId, avID: item.parentElement.dataset.avId,
keyID: item.parentElement.dataset.colId, keyID: item.parentElement.dataset.colId,
rowID: item.parentElement.dataset.blockId, rowID: item.parentElement.dataset.rowId,
value value
}, (setResponse) => { }, (setResponse) => {
if (type === "number") { if (type === "number") {

View file

@ -909,13 +909,10 @@ export const renderCellAttr = (cellElement: Element, value: IAVCellValue) => {
cellElement.classList.add("av__cell-uncheck"); cellElement.classList.add("av__cell-uncheck");
} }
} else if (value.type === "block") { } else if (value.type === "block") {
if (value.block.id) {
// 不能设置为空,否则编辑后会临时无 id
cellElement.setAttribute("data-block-id", value.block.id);
}
if (value.isDetached) { if (value.isDetached) {
cellElement.setAttribute("data-detached", "true"); cellElement.setAttribute("data-detached", "true");
} else { } else {
cellElement.querySelector(".av__celltext").setAttribute("data-id", value.block.id);
cellElement.removeAttribute("data-detached"); cellElement.removeAttribute("data-detached");
} }
} }
@ -1032,7 +1029,7 @@ const renderRollup = (cellValue: IAVCellValue) => {
} }
} else if (cellValue.type === "block") { } else if (cellValue.type === "block") {
if (cellValue?.isDetached) { if (cellValue?.isDetached) {
text = `<span class="av__celltext" data-id="${cellValue.block?.id}">${Lute.EscapeHTMLStr(cellValue.block?.content || window.siyuan.languages.untitled)}</span>`; text = `<span class="av__celltext">${Lute.EscapeHTMLStr(cellValue.block?.content || window.siyuan.languages.untitled)}</span>`;
} else { } else {
text = `<span data-type="block-ref" data-id="${cellValue.block?.id}" data-subtype="s" class="av__celltext av__celltext--ref">${Lute.EscapeHTMLStr(cellValue.block?.content || window.siyuan.languages.untitled)}</span>`; text = `<span data-type="block-ref" data-id="${cellValue.block?.id}" data-subtype="s" class="av__celltext av__celltext--ref">${Lute.EscapeHTMLStr(cellValue.block?.content || window.siyuan.languages.untitled)}</span>`;
} }

View file

@ -4,7 +4,6 @@ import {fetchPost} from "../../../../util/fetch";
import {setPage} from "../row"; import {setPage} from "../row";
import {Constants} from "../../../../constants"; import {Constants} from "../../../../constants";
import {clearSelect} from "../../../util/clearSelect"; import {clearSelect} from "../../../util/clearSelect";
import {hasClosestByClassName} from "../../../util/hasClosest";
export const insertGalleryItemAnimation = (options: { export const insertGalleryItemAnimation = (options: {
blockElement: HTMLElement; blockElement: HTMLElement;
@ -39,19 +38,11 @@ ${fieldType === "block" ? ' data-detached="true"' : ""}>${renderCell(genCellValu
clearSelect(["galleryItem"], options.blockElement); clearSelect(["galleryItem"], options.blockElement);
let html = ""; let html = "";
const coverClass = sideItemElement?.querySelector(".av__gallery-cover")?.className || "fn__none"; const coverClass = sideItemElement?.querySelector(".av__gallery-cover")?.className || "fn__none";
options.srcIDs.forEach((id) => { options.srcIDs.forEach(() => {
const blockCellElement = options.blockElement.querySelector(`[data-block-id="${id}"]`);
if (!blockCellElement) {
html += `<div class="av__gallery-item" data-type="ghost"> html += `<div class="av__gallery-item" 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="${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="av__gallery-fields">${cellsHTML}</div>
</div>`; </div>`;
} else {
const galleryItemElement = hasClosestByClassName(blockCellElement, "av__gallery-item");
if (galleryItemElement) {
galleryItemElement.classList.add("av__gallery-item--select");
}
}
}); });
if (sideItemElement) { if (sideItemElement) {
sideItemElement.insertAdjacentHTML("afterend", html); sideItemElement.insertAdjacentHTML("afterend", html);

View file

@ -72,8 +72,7 @@ data-empty="${isEmpty}"
aria-label="${ariaLabel}" aria-label="${ariaLabel}"
data-position="5west" data-position="5west"
data-id="${cell.id}" data-id="${cell.id}"
data-field-id="${data.fields[fieldsIndex].id}" data-field-id="${data.fields[fieldsIndex].id}"
${cell.valueType === "block" ? 'data-block-id="' + (cell.value.block.id || "") + '"' : ""}
data-dtype="${cell.valueType}" data-dtype="${cell.valueType}"
${cell.value?.isDetached ? ' data-detached="true"' : ""} ${cell.value?.isDetached ? ' data-detached="true"' : ""}
style="${cell.bgColor ? `background-color:${cell.bgColor};` : ""} style="${cell.bgColor ? `background-color:${cell.bgColor};` : ""}

View file

@ -192,8 +192,8 @@ style="width: ${column.width || "200px"}">${getCalcValue(column) || `<svg><use x
if (cell.valueType === "checkbox") { if (cell.valueType === "checkbox") {
checkClass = cell.value?.checkbox?.checked ? " av__cell-check" : " av__cell-uncheck"; checkClass = cell.value?.checkbox?.checked ? " av__cell-check" : " av__cell-uncheck";
} }
contentHTML += `<div class="av__cell${checkClass}" data-id="${cell.id}" data-col-id="${data.columns[index].id}" contentHTML += `<div class="av__cell${checkClass}" data-id="${cell.id}" data-col-id="${data.columns[index].id}"
${cell.valueType === "block" ? 'data-block-id="' + (cell.value.block.id || "") + '"' : ""} data-wrap="${data.columns[index].wrap}" data-wrap="${data.columns[index].wrap}"
data-dtype="${data.columns[index].type}" data-dtype="${data.columns[index].type}"
${cell.value?.isDetached ? ' data-detached="true"' : ""} ${cell.value?.isDetached ? ' data-detached="true"' : ""}
style="width: ${data.columns[index].width || "200px"}; style="width: ${data.columns[index].width || "200px"};
@ -725,7 +725,7 @@ export const refreshAV = (protyle: IProtyle, operation: IOperation) => {
}); });
} }
if (operation.srcs.length === 1) { if (operation.srcs.length === 1) {
const popCellElement = item.querySelector(`.av__body${groupQuery} .av__cell[data-block-id="${operation.srcs[0].id}"]`) as HTMLElement; const popCellElement = item.querySelector(`.av__body${groupQuery} [data-id="${operation.srcs[0].id}"] .av__cell[data-dtype="block"]`) as HTMLElement;
if (popCellElement) { if (popCellElement) {
popTextCell(protyle, [popCellElement], "block"); popTextCell(protyle, [popCellElement], "block");
} }

View file

@ -154,16 +154,10 @@ ${colType === "block" ? ' data-detached="true"' : ""}>${renderCell(genCellValue(
}); });
let html = ""; let html = "";
clearSelect(["cell", "row"], options.blockElement); clearSelect(["cell", "row"], options.blockElement);
options.srcIDs.forEach((id) => { options.srcIDs.forEach(() => {
const blockCellElement = options.blockElement.querySelector(`[data-block-id="${id}"]`); html += `<div class="av__row" data-type="ghost">
if (!blockCellElement) {
html += `<div class="av__row" data-type="ghost">
${cellsHTML} ${cellsHTML}
</div>`; </div>`;
} else {
addDragFill(blockCellElement);
blockCellElement.classList.add("av__cell--select");
}
}); });
previousElement.insertAdjacentHTML("afterend", html); previousElement.insertAdjacentHTML("afterend", html);
fetchPost("/api/av/getAttributeViewAddingBlockDefaultValues", { fetchPost("/api/av/getAttributeViewAddingBlockDefaultValues", {
@ -357,10 +351,10 @@ export const deleteRow = (blockElement: HTMLElement, protyle: IProtyle) => {
const undoOperations: IOperation[] = []; const undoOperations: IOperation[] = [];
const blockIds: string[] = []; const blockIds: string[] = [];
rowElements.forEach(item => { rowElements.forEach(item => {
blockIds.push(item.querySelector(".av__cell[data-block-id]").getAttribute("data-block-id")); blockIds.push(item.getAttribute("data-id"));
}); });
rowElements.forEach(item => { rowElements.forEach(item => {
const blockValue = genCellValueByElement("block", item.querySelector(".av__cell[data-block-id]")); const blockValue = genCellValueByElement("block", item.querySelector('.av__cell[data-dtype="block"]'));
undoOperations.push({ undoOperations.push({
action: "insertAttrViewBlock", action: "insertAttrViewBlock",
avID, avID,

View file

@ -19,6 +19,7 @@ import {updateCellsValue} from "../render/av/cell";
import {input} from "../wysiwyg/input"; import {input} from "../wysiwyg/input";
import {fetchPost} from "../../util/fetch"; import {fetchPost} from "../../util/fetch";
import {isIncludeCell} from "./table"; import {isIncludeCell} from "./table";
import {getFieldIdByCellElement} from "../render/av/row";
const processAV = (range: Range, html: string, protyle: IProtyle, blockElement: HTMLElement) => { const processAV = (range: Range, html: string, protyle: IProtyle, blockElement: HTMLElement) => {
const tempElement = document.createElement("template"); const tempElement = document.createElement("template");
@ -111,7 +112,7 @@ const processAV = (range: Range, html: string, protyle: IProtyle, blockElement:
const selectCellElement = blockElement.querySelector(".av__cell--select") as HTMLElement; const selectCellElement = blockElement.querySelector(".av__cell--select") as HTMLElement;
if (selectCellElement) { if (selectCellElement) {
const sourceId = contenteditableElement.firstElementChild.getAttribute("data-id"); const sourceId = contenteditableElement.firstElementChild.getAttribute("data-id");
const previousID = selectCellElement.dataset.blockId; const previousID = getFieldIdByCellElement(selectCellElement, blockElement.getAttribute("data-av-type") as TAVView);
transaction(protyle, [{ transaction(protyle, [{
action: "replaceAttrViewBlock", action: "replaceAttrViewBlock",
avID, avID,