mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-18 15:40:12 +01:00
This commit is contained in:
parent
25678e401f
commit
5fbc57a55a
2 changed files with 43 additions and 120 deletions
|
|
@ -670,7 +670,6 @@ export const refreshAV = (protyle: IProtyle, operation: IOperation) => {
|
||||||
const avID = operation.action === "setAttrViewName" ? operation.id : operation.avID;
|
const avID = operation.action === "setAttrViewName" ? operation.id : operation.avID;
|
||||||
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${avID}"]`)).forEach((item: HTMLElement) => {
|
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${avID}"]`)).forEach((item: HTMLElement) => {
|
||||||
item.removeAttribute("data-render");
|
item.removeAttribute("data-render");
|
||||||
const updateRow = item.querySelector('[data-need-update="true"]');
|
|
||||||
if (operation.action === "sortAttrViewCol" || operation.action === "sortAttrViewRow") {
|
if (operation.action === "sortAttrViewCol" || operation.action === "sortAttrViewRow") {
|
||||||
item.querySelectorAll(".av__cell--active").forEach((item: HTMLElement) => {
|
item.querySelectorAll(".av__cell--active").forEach((item: HTMLElement) => {
|
||||||
item.classList.remove("av__cell--active");
|
item.classList.remove("av__cell--active");
|
||||||
|
|
@ -707,10 +706,6 @@ export const refreshAV = (protyle: IProtyle, operation: IOperation) => {
|
||||||
renderAVAttribute(attrElement.parentElement, attrElement.dataset.nodeId, protyle);
|
renderAVAttribute(attrElement.parentElement, attrElement.dataset.nodeId, protyle);
|
||||||
} else {
|
} else {
|
||||||
if (operation.action === "insertAttrViewBlock") {
|
if (operation.action === "insertAttrViewBlock") {
|
||||||
if (updateRow && !item.querySelector(`[data-id="${updateRow.getAttribute("data-id")}"]`)) {
|
|
||||||
showMessage(window.siyuan.languages.insertRowTip);
|
|
||||||
document.querySelector(".av__mask")?.remove();
|
|
||||||
}
|
|
||||||
if (item.getAttribute("data-av-type") === "gallery") {
|
if (item.getAttribute("data-av-type") === "gallery") {
|
||||||
operation.srcs.forEach(srcItem => {
|
operation.srcs.forEach(srcItem => {
|
||||||
const filesElement = item.querySelector(`.av__gallery-item[data-id="${srcItem.id}"]`)?.querySelector(".av__gallery-fields");
|
const filesElement = item.querySelector(`.av__gallery-item[data-id="${srcItem.id}"]`)?.querySelector(".av__gallery-fields");
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import {focusBlock} from "../../util/selection";
|
||||||
import {Menu} from "../../../plugin/Menu";
|
import {Menu} from "../../../plugin/Menu";
|
||||||
import {transaction} from "../../wysiwyg/transaction";
|
import {transaction} from "../../wysiwyg/transaction";
|
||||||
import {
|
import {
|
||||||
addDragFill,
|
addDragFill, genCellValue,
|
||||||
genCellValueByElement,
|
genCellValueByElement,
|
||||||
getTypeByCellElement,
|
getTypeByCellElement,
|
||||||
popTextCell,
|
popTextCell,
|
||||||
|
|
@ -122,39 +122,48 @@ export const insertAttrViewBlockAnimation = (options: {
|
||||||
groupID?: string
|
groupID?: string
|
||||||
}) => {
|
}) => {
|
||||||
(options.blockElement.querySelector('[data-type="av-search"]') as HTMLInputElement).value = "";
|
(options.blockElement.querySelector('[data-type="av-search"]') as HTMLInputElement).value = "";
|
||||||
const avId = options.blockElement.getAttribute("data-av-id");
|
const hasSort = options.blockElement.querySelector('.av__views [data-type="av-sort"]').classList.contains("block__icon--active");
|
||||||
|
const hasMore = !options.blockElement.querySelector('[data-type="av-load-more"]').classList.contains("fn__none");
|
||||||
|
if (hasMore && hasSort) {
|
||||||
|
showMessage(window.siyuan.languages.insertRowTip);
|
||||||
|
}
|
||||||
const groupQuery = options.groupID ? `.av__body[data-group-id="${options.groupID}"] ` : "";
|
const groupQuery = options.groupID ? `.av__body[data-group-id="${options.groupID}"] ` : "";
|
||||||
let previousElement = options.blockElement.querySelector(`.av__row[data-id="${options.previousId}"]`) || options.blockElement.querySelector(groupQuery + ".av__row--header");
|
let previousElement = options.blockElement.querySelector(`.av__row[data-id="${options.previousId}"]`) || options.blockElement.querySelector(groupQuery + ".av__row--header");
|
||||||
// 有排序需要加入最后一行
|
// 有排序需要加入最后一行
|
||||||
if (options.blockElement.querySelector('.av__views [data-type="av-sort"]').classList.contains("block__icon--active")) {
|
if (hasSort) {
|
||||||
previousElement = options.blockElement.querySelector(groupQuery + ".av__row--util").previousElementSibling;
|
previousElement = options.blockElement.querySelector(groupQuery + ".av__row--util").previousElementSibling;
|
||||||
}
|
}
|
||||||
let colHTML = '<div class="av__colsticky"><div class="av__firstcol"><svg><use xlink:href="#iconUncheck"></use></svg></div></div>';
|
|
||||||
|
let cellsHTML = '<div class="av__colsticky"><div class="av__firstcol"><svg><use xlink:href="#iconUncheck"></use></svg></div></div>';
|
||||||
const pinIndex = previousElement.querySelectorAll(".av__colsticky .av__cell").length - 1;
|
const pinIndex = previousElement.querySelectorAll(".av__colsticky .av__cell").length - 1;
|
||||||
if (pinIndex > -1) {
|
if (pinIndex > -1) {
|
||||||
colHTML = '<div class="av__colsticky"><div class="av__firstcol"><svg><use xlink:href="#iconUncheck"></use></svg></div>';
|
cellsHTML = '<div class="av__colsticky"><div class="av__firstcol"><svg><use xlink:href="#iconUncheck"></use></svg></div>';
|
||||||
}
|
}
|
||||||
|
const avId = options.blockElement.getAttribute("data-av-id");
|
||||||
previousElement.querySelectorAll(".av__cell").forEach((item: HTMLElement, index) => {
|
previousElement.querySelectorAll(".av__cell").forEach((item: HTMLElement, index) => {
|
||||||
let lineNumber = "";
|
let lineNumber = 1;
|
||||||
if (getTypeByCellElement(item) === "lineNumber") {
|
const colType = getTypeByCellElement(item);
|
||||||
|
if (colType === "lineNumber") {
|
||||||
const lineNumberValue = item.querySelector(".av__celltext")?.getAttribute("data-value");
|
const lineNumberValue = item.querySelector(".av__celltext")?.getAttribute("data-value");
|
||||||
if (lineNumberValue) {
|
if (lineNumberValue) {
|
||||||
lineNumber = (parseInt(lineNumberValue) + 1).toString();
|
lineNumber = parseInt(lineNumberValue) + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
colHTML += `<div class="av__cell" data-col-id="${item.dataset.colId}"
|
cellsHTML += `<div class="av__cell${colType === "checkbox" ? " av__cell-uncheck" : ""}" data-col-id="${item.dataset.colId}"
|
||||||
|
data-wrap="${item.dataset.wrap}"
|
||||||
|
data-dtype="${item.dataset.dtype}"
|
||||||
style="width: ${item.style.width};${item.dataset.dtype === "number" ? "text-align: right;" : ""}"
|
style="width: ${item.style.width};${item.dataset.dtype === "number" ? "text-align: right;" : ""}"
|
||||||
${getTypeByCellElement(item) === "block" ? ' data-detached="true"' : ""}><span class="${avId ? "av__celltext" : "av__pulse"}">${lineNumber}</span></div>`;
|
${colType === "block" ? ' data-detached="true"' : ""}>${renderCell(genCellValue(colType, null), lineNumber)}</div>`;
|
||||||
if (pinIndex === index) {
|
if (pinIndex === index) {
|
||||||
colHTML += "</div>";
|
cellsHTML += "</div>";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let html = "";
|
let html = "";
|
||||||
options.srcIDs.forEach((id) => {
|
options.srcIDs.forEach((id) => {
|
||||||
const blockCellElement = options.blockElement.querySelector(`[data-block-id="${id}"]`);
|
const blockCellElement = options.blockElement.querySelector(`[data-block-id="${id}"]`);
|
||||||
if (!blockCellElement) {
|
if (!blockCellElement) {
|
||||||
html += `<div class="av__row" data-type="ghost" data-id="${id}" data-avid="${avId}" data-previous-id="${options.previousId}">
|
html += `<div class="av__row" data-type="ghost">
|
||||||
${colHTML}
|
${cellsHTML}
|
||||||
</div>`;
|
</div>`;
|
||||||
} else {
|
} else {
|
||||||
clearSelect(["cell"], options.blockElement);
|
clearSelect(["cell"], options.blockElement);
|
||||||
|
|
@ -163,112 +172,31 @@ ${getTypeByCellElement(item) === "block" ? ' data-detached="true"' : ""}><span c
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
previousElement.insertAdjacentHTML("afterend", html);
|
previousElement.insertAdjacentHTML("afterend", html);
|
||||||
if (avId) {
|
fetchPost("/api/av/getAttributeViewAddingBlockDefaultValues", {
|
||||||
const currentRow = previousElement.nextElementSibling;
|
avID: avId,
|
||||||
if (options.blockElement.querySelector('.av__views [data-type="av-sort"]').classList.contains("block__icon--active") &&
|
viewID: options.blockElement.getAttribute(Constants.CUSTOM_SY_AV_VIEW),
|
||||||
!options.blockElement.querySelector('[data-type="av-load-more"]').classList.contains("fn__none")) {
|
groupID: options.groupID,
|
||||||
currentRow.setAttribute("data-need-update", "true");
|
previousID: options.previousId,
|
||||||
}
|
}, (response) => {
|
||||||
const sideRow = previousElement.classList.contains("av__row--header") ? currentRow.nextElementSibling : previousElement;
|
let popCellElement: HTMLElement;
|
||||||
fetchPost("/api/av/getAttributeViewAddingBlockDefaultValues", {
|
options.blockElement.querySelectorAll('[data-type="ghost"]').forEach(rowItem => {
|
||||||
avID: avId,
|
const updateIds = Object.keys(response.data.values);
|
||||||
viewID: options.blockElement.getAttribute(Constants.CUSTOM_SY_AV_VIEW),
|
rowItem.querySelectorAll(".av__cell").forEach((cellItem: HTMLElement) => {
|
||||||
groupID: options.groupID,
|
if (!popCellElement && cellItem.getAttribute("data-detached") === "true") {
|
||||||
previousID: options.previousId,
|
popCellElement = cellItem;
|
||||||
}, (response) => {
|
|
||||||
// https://github.com/siyuan-note/siyuan/issues/10517
|
|
||||||
let hideTextCell = false;
|
|
||||||
response.data.filters.find((item: IAVFilter) => {
|
|
||||||
const headerElement = options.blockElement.querySelector(`.av__cell--header[data-col-id="${item.column}"]`);
|
|
||||||
if (!headerElement) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
const filterType = headerElement.getAttribute("data-dtype");
|
if (updateIds.includes(cellItem.dataset.colId)) {
|
||||||
if (item.value && filterType !== item.value.type) {
|
const cellValue = response.data.values[cellItem.dataset.colId];
|
||||||
return;
|
cellItem.innerHTML = renderCell(cellValue);
|
||||||
}
|
renderCellAttr(cellItem, cellValue);
|
||||||
if (["relation", "rollup", "template"].includes(filterType)) {
|
|
||||||
hideTextCell = true;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据后台计算出显示与否的结果进行标识,以便于在 refreshAV 中更新 UI
|
|
||||||
if (["created", "updated"].includes(filterType)) {
|
|
||||||
currentRow.setAttribute("data-need-update", "true");
|
|
||||||
} else {
|
|
||||||
response.data.sorts.find((sortItem: IAVSort) => {
|
|
||||||
if (sortItem.column === item.column) {
|
|
||||||
currentRow.setAttribute("data-need-update", "true");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// 当空或非空外,需要根据值进行判断
|
|
||||||
let isRenderValue = true;
|
|
||||||
if (item.operator !== "Is empty" && item.operator !== "Is not empty") {
|
|
||||||
switch (item.value.type) {
|
|
||||||
case "select":
|
|
||||||
case "mSelect":
|
|
||||||
if (!item.value.mSelect || item.value.mSelect.length === 0) {
|
|
||||||
isRenderValue = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "block":
|
|
||||||
if (!item.value.block || !item.value.block.content) {
|
|
||||||
isRenderValue = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "number":
|
|
||||||
if (!item.value.number || !item.value.number.isNotEmpty) {
|
|
||||||
isRenderValue = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "date":
|
|
||||||
case "created":
|
|
||||||
case "updated":
|
|
||||||
if (!item.value[item.value.type] || !item.value[item.value.type].isNotEmpty) {
|
|
||||||
isRenderValue = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "mAsset":
|
|
||||||
if (!item.value.mAsset || item.value.mAsset.length === 0) {
|
|
||||||
isRenderValue = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "checkbox":
|
|
||||||
if (!item.value.checkbox) {
|
|
||||||
isRenderValue = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "text":
|
|
||||||
case "url":
|
|
||||||
case "phone":
|
|
||||||
case "email":
|
|
||||||
if (!item.value[item.value.type] || !item.value[item.value.type].content) {
|
|
||||||
isRenderValue = false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (sideRow.classList.contains("av__row") && isRenderValue) {
|
|
||||||
const sideRowCellElement = sideRow.querySelector(`.av__cell[data-col-id="${item.column}"]`) as HTMLElement;
|
|
||||||
const cellElement = currentRow.querySelector(`.av__cell[data-col-id="${item.column}"]`);
|
|
||||||
const cellValue = genCellValueByElement(getTypeByCellElement(sideRowCellElement), sideRowCellElement);
|
|
||||||
const iconElement = cellElement.querySelector(".b3-menu__avemoji");
|
|
||||||
cellElement.innerHTML = renderCell(cellValue, 0, iconElement ? !iconElement.classList.contains("fn__none") : false);
|
|
||||||
renderCellAttr(cellElement, cellValue);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (hideTextCell) {
|
|
||||||
currentRow.remove();
|
|
||||||
showMessage(window.siyuan.languages.insertRowTip);
|
|
||||||
} else if (options.srcIDs.length === 1) {
|
|
||||||
popTextCell(options.protyle, [currentRow.querySelector('.av__cell[data-detached="true"]')], "block");
|
|
||||||
}
|
|
||||||
setPage(options.blockElement);
|
|
||||||
});
|
});
|
||||||
}
|
if (options.srcIDs.length === 1 && !(hasMore && hasSort)) {
|
||||||
setPage(options.blockElement);
|
popTextCell(options.protyle, [popCellElement], "block");
|
||||||
|
}
|
||||||
|
setPage(options.blockElement);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const stickyRow = (blockElement: HTMLElement, elementRect: DOMRect, status: "top" | "bottom" | "all") => {
|
export const stickyRow = (blockElement: HTMLElement, elementRect: DOMRect, status: "top" | "bottom" | "all") => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue