Vanessa 2025-07-27 19:10:43 +08:00
parent 48c64f98f4
commit 6d7637850a
7 changed files with 74 additions and 30 deletions

View file

@ -279,6 +279,7 @@ export class Gutter {
content: "" content: ""
}], }],
blockID: id, blockID: id,
groupID: rowElement.parentElement.getAttribute("data-group-id"),
}, { }, {
action: "doUpdateUpdated", action: "doUpdateUpdated",
id, id,

View file

@ -157,7 +157,7 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
event.stopPropagation(); event.stopPropagation();
return true; return true;
} else if (type === "av-add-more") { } else if (type === "av-add-more") {
insertRows(blockElement, protyle, 1, undefined); insertRows({blockElement, protyle, count: 1, previousID: ""});
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return true; return true;
@ -210,10 +210,14 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
event.stopPropagation(); event.stopPropagation();
return true; return true;
} else if (type === "av-add-bottom") { } else if (type === "av-add-bottom") {
insertRows(blockElement, protyle, 1, const bodyElement = hasClosestByClassName(target, "av__body");
blockElement.querySelector(".av__row--util")?.previousElementSibling?.getAttribute("data-id") || insertRows({
target.previousElementSibling?.getAttribute("data-id") || undefined blockElement, protyle,
); count: 1,
previousID: blockElement.querySelector(".av__row--util")?.previousElementSibling?.getAttribute("data-id") ||
target.previousElementSibling?.getAttribute("data-id") || undefined,
groupID: bodyElement ? bodyElement.getAttribute("data-group-id") : ""
});
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return true; return true;
@ -582,7 +586,8 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
avID, avID,
ignoreFillFilter: true, ignoreFillFilter: true,
srcs, srcs,
blockID: listItemElement.dataset.blockId blockID: listItemElement.dataset.blockId,
groupID: rowElement.parentElement.getAttribute("data-group-id")
}, { }, {
action: "doUpdateUpdated", action: "doUpdateUpdated",
id: listItemElement.dataset.blockId, id: listItemElement.dataset.blockId,
@ -611,12 +616,24 @@ ${window.siyuan.languages[avType === "table" ? "insertRowBefore" : "insertItemBe
if (document.activeElement === inputElement) { if (document.activeElement === inputElement) {
return; return;
} }
insertRows(blockElement, protyle, parseInt(inputElement.value), rowElements[0].previousElementSibling.getAttribute("data-id")); insertRows({
blockElement,
protyle,
count: parseInt(inputElement.value),
previousID: rowElements[0].previousElementSibling.getAttribute("data-id"),
groupID: rowElements[0].parentElement.getAttribute("data-group-id")
});
menu.close(); menu.close();
}); });
inputElement.addEventListener("keydown", (event: KeyboardEvent) => { inputElement.addEventListener("keydown", (event: KeyboardEvent) => {
if (!event.isComposing && event.key === "Enter") { if (!event.isComposing && event.key === "Enter") {
insertRows(blockElement, protyle, parseInt(inputElement.value), rowElements[0].previousElementSibling.getAttribute("data-id")); insertRows({
blockElement,
protyle,
count: parseInt(inputElement.value),
previousID: rowElements[0].previousElementSibling.getAttribute("data-id"),
groupID: rowElements[0].parentElement.getAttribute("data-group-id")
});
menu.close(); menu.close();
} }
}); });
@ -634,12 +651,24 @@ ${window.siyuan.languages[avType === "table" ? "insertRowAfter" : "insertItemAft
if (document.activeElement === inputElement) { if (document.activeElement === inputElement) {
return; return;
} }
insertRows(blockElement, protyle, parseInt(inputElement.value), rowElements[0].getAttribute("data-id")); insertRows({
blockElement,
protyle,
count: parseInt(inputElement.value),
previousID: rowElements[0].getAttribute("data-id"),
groupID: rowElements[0].parentElement.getAttribute("data-group-id")
});
menu.close(); menu.close();
}); });
inputElement.addEventListener("keydown", (event: KeyboardEvent) => { inputElement.addEventListener("keydown", (event: KeyboardEvent) => {
if (!event.isComposing && event.key === "Enter") { if (!event.isComposing && event.key === "Enter") {
insertRows(blockElement, protyle, parseInt(inputElement.value), rowElements[0].getAttribute("data-id")); insertRows({
blockElement,
protyle,
count: parseInt(inputElement.value),
previousID: rowElements[0].getAttribute("data-id"),
groupID: rowElements[0].parentElement.getAttribute("data-group-id")
});
menu.close(); menu.close();
} }
}); });

View file

@ -420,6 +420,7 @@ draggable="true">${genSelectItemHTML("selected", targetId, !target.querySelector
const blockID = target.querySelector(".popover__block").getAttribute("data-id"); const blockID = target.querySelector(".popover__block").getAttribute("data-id");
const content = target.querySelector("b").textContent; const content = target.querySelector("b").textContent;
const rowId = Lute.NewNodeID(); const rowId = Lute.NewNodeID();
const bodyElement = hasClosestByClassName(cellElements[0], "av__body");
transaction(protyle, [{ transaction(protyle, [{
action: "insertAttrViewBlock", action: "insertAttrViewBlock",
ignoreFillFilter: true, ignoreFillFilter: true,
@ -430,6 +431,7 @@ draggable="true">${genSelectItemHTML("selected", targetId, !target.querySelector
content content
}], }],
blockID, blockID,
groupID: bodyElement ? bodyElement.getAttribute("data-group-id") : "",
}, { }, {
action: "doUpdateUpdated", action: "doUpdateUpdated",
id: blockID, id: blockID,

View file

@ -239,7 +239,7 @@ const renderGroupTable = (options: ITableOptions) => {
<svg class="${group.groupFolded ? "" : "av__group-arrow--open"}"><use xlink:href="#iconRight"></use></svg> <svg class="${group.groupFolded ? "" : "av__group-arrow--open"}"><use xlink:href="#iconRight"></use></svg>
</div><span class="fn__space"></span>${group.name}<span class="${group.rows.length === 0 ? "fn__none" : "counter"}">${group.rows.length}</span> </div><span class="fn__space"></span>${group.name}<span class="${group.rows.length === 0 ? "fn__none" : "counter"}">${group.rows.length}</span>
</div> </div>
<div class="av__body${group.groupFolded ? " fn__none" : ""}">${getTableHTMLs(group, options.blockElement).contentHTML}</div>`; <div data-group-id="${group.id}" class="av__body${group.groupFolded ? " fn__none" : ""}">${getTableHTMLs(group, options.blockElement).contentHTML}</div>`;
} }
}); });
if (options.renderAll) { if (options.renderAll) {

View file

@ -84,7 +84,7 @@ export const updateHeader = (rowElement: HTMLElement) => {
} }
const counterElement = blockElement.querySelector(".av__counter"); const counterElement = blockElement.querySelector(".av__counter");
const allCount = blockElement.querySelectorAll(".av__row--select:not(.av__row--header)").length const allCount = blockElement.querySelectorAll(".av__row--select:not(.av__row--header)").length;
if (allCount === 0) { if (allCount === 0) {
counterElement.classList.add("fn__none"); counterElement.classList.add("fn__none");
return; return;
@ -432,7 +432,8 @@ export const deleteRow = (blockElement: HTMLElement, protyle: IProtyle) => {
isDetached: blockValue.isDetached, isDetached: blockValue.isDetached,
content: blockValue.block.content content: blockValue.block.content
}], }],
blockID: blockElement.dataset.nodeId blockID: blockElement.dataset.nodeId,
groupID: item.parentElement.getAttribute("data-group-id")
}); });
}); });
const newUpdated = dayjs().format("YYYYMMDDHHmmss"); const newUpdated = dayjs().format("YYYYMMDDHHmmss");
@ -458,11 +459,17 @@ export const deleteRow = (blockElement: HTMLElement, protyle: IProtyle) => {
blockElement.setAttribute("updated", newUpdated); blockElement.setAttribute("updated", newUpdated);
}; };
export const insertRows = (blockElement: HTMLElement, protyle: IProtyle, count: number, previousID: string) => { export const insertRows = (options: {
const avID = blockElement.getAttribute("data-av-id"); blockElement: HTMLElement,
protyle: IProtyle,
count: number,
previousID: string,
groupID?: string
}) => {
const avID = options.blockElement.getAttribute("data-av-id");
const srcIDs: string[] = []; const srcIDs: string[] = [];
const srcs: IOperationSrcs[] = []; const srcs: IOperationSrcs[] = [];
new Array(count).fill(0).forEach(() => { new Array(options.count).fill(0).forEach(() => {
const newNodeID = Lute.NewNodeID(); const newNodeID = Lute.NewNodeID();
srcIDs.push(newNodeID); srcIDs.push(newNodeID);
srcs.push({ srcs.push({
@ -472,15 +479,16 @@ export const insertRows = (blockElement: HTMLElement, protyle: IProtyle, count:
}); });
}); });
const newUpdated = dayjs().format("YYYYMMDDHHmmss"); const newUpdated = dayjs().format("YYYYMMDDHHmmss");
transaction(protyle, [{ transaction(options.protyle, [{
action: "insertAttrViewBlock", action: "insertAttrViewBlock",
avID, avID,
previousID, previousID: options.previousID,
srcs, srcs,
blockID: blockElement.dataset.nodeId, blockID: options.blockElement.dataset.nodeId,
groupID: options.groupID
}, { }, {
action: "doUpdateUpdated", action: "doUpdateUpdated",
id: blockElement.dataset.nodeId, id: options.blockElement.dataset.nodeId,
data: newUpdated, data: newUpdated,
}], [{ }], [{
action: "removeAttrViewBlock", action: "removeAttrViewBlock",
@ -488,18 +496,18 @@ export const insertRows = (blockElement: HTMLElement, protyle: IProtyle, count:
avID, avID,
}, { }, {
action: "doUpdateUpdated", action: "doUpdateUpdated",
id: blockElement.dataset.nodeId, id: options.blockElement.dataset.nodeId,
data: blockElement.getAttribute("updated") data: options.blockElement.getAttribute("updated")
}]); }]);
if (blockElement.getAttribute("data-av-type") === "gallery") { if (options.blockElement.getAttribute("data-av-type") === "gallery") {
insertGalleryItemAnimation({ insertGalleryItemAnimation({
blockElement, blockElement: options.blockElement,
protyle, protyle: options.protyle,
srcIDs, srcIDs,
previousId: previousID previousId: options.previousID
}); });
} else { } else {
insertAttrViewBlockAnimation(protyle, blockElement, srcIDs, previousID, avID); insertAttrViewBlockAnimation(options.protyle, options.blockElement, srcIDs, options.previousID, avID);
} }
blockElement.setAttribute("updated", newUpdated); options.blockElement.setAttribute("updated", newUpdated);
}; };

View file

@ -1109,7 +1109,8 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
avID, avID,
previousID, previousID,
srcs, srcs,
blockID: blockElement.dataset.nodeId blockID: blockElement.dataset.nodeId,
groupID: targetElement.parentElement.getAttribute("data-group-id")
}, { }, {
action: "doUpdateUpdated", action: "doUpdateUpdated",
id: blockElement.dataset.nodeId, id: blockElement.dataset.nodeId,
@ -1169,7 +1170,8 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
avID, avID,
previousID, previousID,
srcs, srcs,
blockID: blockElement.dataset.nodeId blockID: blockElement.dataset.nodeId,
groupID: targetElement.parentElement.getAttribute("data-group-id")
}, { }, {
action: "doUpdateUpdated", action: "doUpdateUpdated",
id: blockElement.dataset.nodeId, id: blockElement.dataset.nodeId,
@ -1290,6 +1292,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
previousID, previousID,
srcs, srcs,
blockID: blockElement.dataset.nodeId, blockID: blockElement.dataset.nodeId,
groupID: targetElement.parentElement.getAttribute("data-group-id")
}, { }, {
action: "doUpdateUpdated", action: "doUpdateUpdated",
id: blockElement.dataset.nodeId, id: blockElement.dataset.nodeId,

View file

@ -552,6 +552,7 @@ interface IOperation {
blockIDs?: string[] // add/removeFlashcards 专享 blockIDs?: string[] // add/removeFlashcards 专享
removeDest?: boolean // removeAttrViewCol 专享 removeDest?: boolean // removeAttrViewCol 专享
layout?: string // addAttrViewView 专享 layout?: string // addAttrViewView 专享
groupID?: string // insertAttrViewBlock 专享
} }
interface IOperationSrcs { interface IOperationSrcs {