mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
This commit is contained in:
parent
1544786bb6
commit
52498a5287
7 changed files with 76 additions and 16 deletions
|
|
@ -92,7 +92,7 @@ const focusStack = (backStack: IBackStack) => {
|
|||
if (getResponse.data.isSyncing) {
|
||||
disabledForeverProtyle(protyle);
|
||||
} else {
|
||||
setReadonlyByConfig(protyle);
|
||||
setReadonlyByConfig(protyle, true);
|
||||
}
|
||||
protyle.contentElement.scrollTop = backStack.scrollTop;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ export class Protyle {
|
|||
break;
|
||||
case "readonly":
|
||||
window.siyuan.config.editor.readOnly = data.data;
|
||||
setReadonlyByConfig(this.protyle);
|
||||
setReadonlyByConfig(this.protyle, true);
|
||||
break;
|
||||
case "heading2doc":
|
||||
case "li2doc":
|
||||
|
|
|
|||
|
|
@ -399,7 +399,7 @@ export const updateAttrViewCellAnimation = (cellElement: HTMLElement, value: IAV
|
|||
if (headerValue) {
|
||||
updateHeaderCell(cellElement, headerValue);
|
||||
} else {
|
||||
cellElement.innerHTML = renderCell(value, cellElement.dataset.wrap === "true");
|
||||
cellElement.innerHTML = renderCell(value);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -46,9 +46,13 @@ export const genCellValueByElement = (colType: TAVCol, cellElement: HTMLElement)
|
|||
isNotEmpty: !!value
|
||||
};
|
||||
} else if (["text", "block", "url", "phone", "email", "template"].includes(colType)) {
|
||||
const textElement = cellElement.querySelector(".av__celltext") as HTMLElement;
|
||||
cellValue[colType as "text"] = {
|
||||
content: cellElement.querySelector(".av__celltext").textContent
|
||||
content: textElement.textContent
|
||||
};
|
||||
if (colType === "block" && textElement.dataset.id) {
|
||||
cellValue.block.id = textElement.dataset.id;
|
||||
}
|
||||
} else if (colType === "mSelect" || colType === "select") {
|
||||
const mSelect: IAVCellSelectValue[] = [];
|
||||
cellElement.querySelectorAll(".b3-chip").forEach((item: HTMLElement) => {
|
||||
|
|
@ -513,7 +517,7 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, va
|
|||
return text;
|
||||
};
|
||||
|
||||
export const renderCell = (cellValue: IAVCellValue, wrap: boolean) => {
|
||||
export const renderCell = (cellValue: IAVCellValue) => {
|
||||
let text = "";
|
||||
if (["text", "template"].includes(cellValue.type)) {
|
||||
text = `<span class="av__celltext">${cellValue ? (cellValue[cellValue.type as "text"].content || "") : ""}</span>`;
|
||||
|
|
@ -568,7 +572,7 @@ export const renderCell = (cellValue: IAVCellValue, wrap: boolean) => {
|
|||
text += `<svg class="av__checkbox"><use xlink:href="#icon${cellValue?.checkbox?.checked ? "Check" : "Uncheck"}"></use></svg>`;
|
||||
} else if (cellValue.type === "rollup") {
|
||||
cellValue?.rollup?.contents?.forEach((item) => {
|
||||
const rollupText = ["select", "mSelect", "mAsset", "checkbox", "relation"].includes(item.type) ? renderCell(item, wrap) : renderRollup(item);
|
||||
const rollupText = ["select", "mSelect", "mAsset", "checkbox", "relation"].includes(item.type) ? renderCell(item) : renderRollup(item);
|
||||
if (rollupText) {
|
||||
text += rollupText + ", ";
|
||||
}
|
||||
|
|
@ -668,3 +672,60 @@ export const getPositionByCellElement = (cellElement: HTMLElement) => {
|
|||
}
|
||||
return {rowIndex, celIndex};
|
||||
};
|
||||
|
||||
export const dragFillCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, originData: {
|
||||
[key: string]: IAVCellValue[]
|
||||
}, originCellIds: string[]) => {
|
||||
nodeElement.querySelector(".av__drag-fill")?.remove();
|
||||
const newData: { [key: string]: Array<IAVCellValue & { colId?: string, element?: HTMLElement }> } = {};
|
||||
nodeElement.querySelectorAll(".av__cell--active").forEach((item: HTMLElement) => {
|
||||
if (originCellIds.includes(item.dataset.id)) {
|
||||
return;
|
||||
}
|
||||
const rowElement = hasClosestByClassName(item, "av__row");
|
||||
if (!rowElement) {
|
||||
return;
|
||||
}
|
||||
if (!newData[rowElement.dataset.id]) {
|
||||
newData[rowElement.dataset.id] = [];
|
||||
}
|
||||
const value: IAVCellValue & {
|
||||
colId?: string,
|
||||
element?: HTMLElement
|
||||
} = genCellValueByElement(getTypeByCellElement(item), item)
|
||||
value.colId = item.dataset.colId;
|
||||
value.element = item;
|
||||
newData[rowElement.dataset.id].push(value);
|
||||
})
|
||||
const doOperations: IOperation[] = [];
|
||||
const undoOperations: IOperation[] = [];
|
||||
const avID = nodeElement.dataset.avId
|
||||
const originKeys = Object.keys(originData);
|
||||
Object.keys(newData).forEach((rowID, index) => {
|
||||
newData[rowID].forEach((item, cellIndex) => {
|
||||
if (["rollup", "template", "created", "updated"].includes(item.type)) {
|
||||
return;
|
||||
}
|
||||
const data = originData[originKeys[index % originKeys.length]][cellIndex]
|
||||
doOperations.push({
|
||||
action: "updateAttrViewCell",
|
||||
id: item.id,
|
||||
avID,
|
||||
keyID: item.colId,
|
||||
rowID,
|
||||
data
|
||||
});
|
||||
undoOperations.push({
|
||||
action: "updateAttrViewCell",
|
||||
id: item.id,
|
||||
avID,
|
||||
keyID: item.colId,
|
||||
rowID,
|
||||
data: item
|
||||
});
|
||||
item.element.innerHTML = renderCell(data);
|
||||
})
|
||||
});
|
||||
focusBlock(nodeElement);
|
||||
transaction(protyle, doOperations, undoOperations);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ ${cell.value?.isDetached ? ' data-detached="true"' : ""}
|
|||
style="width: ${data.columns[index].width || "200px"};
|
||||
${cell.valueType === "number" ? "text-align: right;" : ""}
|
||||
${cell.bgColor ? `background-color:${cell.bgColor};` : ""}
|
||||
${cell.color ? `color:${cell.color};` : ""}">${renderCell(cell.value, data.columns[index].wrap)}</div>`;
|
||||
${cell.color ? `color:${cell.color};` : ""}">${renderCell(cell.value)}</div>`;
|
||||
|
||||
if (pinIndex === index) {
|
||||
tableHTML += "</div>";
|
||||
|
|
|
|||
|
|
@ -109,12 +109,12 @@ ${(item.getAttribute("data-block-id") || item.dataset.dtype === "block") ? ' dat
|
|||
response.data.filters.forEach((item: IAVFilter) => {
|
||||
const sideRowCellElement = sideRow.querySelector(`.av__cell[data-col-id="${item.column}"]`) as HTMLElement;
|
||||
currentRow.querySelector(`.av__cell[data-col-id="${item.column}"]`).innerHTML =
|
||||
renderCell(genCellValueByElement(getTypeByCellElement(sideRowCellElement), sideRowCellElement), sideRowCellElement.dataset.wrap === "true");
|
||||
renderCell(genCellValueByElement(getTypeByCellElement(sideRowCellElement), sideRowCellElement));
|
||||
});
|
||||
response.data.sorts.forEach((item: IAVSort) => {
|
||||
const sideRowCellElement = sideRow.querySelector(`.av__cell[data-col-id="${item.column}"]`) as HTMLElement;
|
||||
currentRow.querySelector(`.av__cell[data-col-id="${item.column}"]`).innerHTML =
|
||||
renderCell(genCellValueByElement(getTypeByCellElement(sideRowCellElement), sideRowCellElement), sideRowCellElement.dataset.wrap === "true");
|
||||
renderCell(genCellValueByElement(getTypeByCellElement(sideRowCellElement), sideRowCellElement));
|
||||
});
|
||||
popTextCell(protyle, [currentRow.querySelector('.av__cell[data-detached="true"]')], "block");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ import {openViewMenu} from "../render/av/view";
|
|||
import {avRender} from "../render/av/render";
|
||||
import {checkFold} from "../../util/noRelyPCFunction";
|
||||
import {
|
||||
dragFillCellsValue,
|
||||
genCellValueByElement,
|
||||
getCellText,
|
||||
getPositionByCellElement,
|
||||
|
|
@ -453,7 +454,7 @@ export class WYSIWYG {
|
|||
}
|
||||
const originData: { [key: string]: IAVCellValue[] } = {}
|
||||
let lastOriginCellElement
|
||||
const lastOriginCellId: string[] = []
|
||||
const originCellIds: string[] = []
|
||||
nodeElement.querySelectorAll(".av__cell--active").forEach((item: HTMLElement, index: number) => {
|
||||
const rowElement = hasClosestByClassName(item, "av__row");
|
||||
if (rowElement) {
|
||||
|
|
@ -462,7 +463,7 @@ export class WYSIWYG {
|
|||
}
|
||||
originData[rowElement.dataset.id].push(genCellValueByElement(getTypeByCellElement(item), item));
|
||||
lastOriginCellElement = item
|
||||
lastOriginCellId.push(item.dataset.id)
|
||||
originCellIds.push(item.dataset.id)
|
||||
}
|
||||
});
|
||||
const dragFillCellIndex = getPositionByCellElement(lastOriginCellElement);
|
||||
|
|
@ -478,7 +479,7 @@ export class WYSIWYG {
|
|||
if (moveCellElement && moveCellElement.dataset.id) {
|
||||
const newIndex = getPositionByCellElement(moveCellElement);
|
||||
nodeElement.querySelectorAll(".av__cell--active").forEach((item: HTMLElement) => {
|
||||
if (!lastOriginCellId.includes(item.dataset.id)) {
|
||||
if (!originCellIds.includes(item.dataset.id)) {
|
||||
item.classList.remove("av__cell--active");
|
||||
}
|
||||
});
|
||||
|
|
@ -506,14 +507,12 @@ export class WYSIWYG {
|
|||
documentSelf.onselectstart = null;
|
||||
documentSelf.onselect = null;
|
||||
if (lastCellElement) {
|
||||
nodeElement.querySelector(".av__drag-fill")?.remove();
|
||||
selectRow(nodeElement.querySelector(".av__firstcol"), "unselectAll");
|
||||
focusBlock(nodeElement);
|
||||
dragFillCellsValue(protyle, nodeElement, originData, originCellIds);
|
||||
lastCellElement.insertAdjacentHTML("beforeend", `<div aria-label="${window.siyuan.languages.dragFill}" class="av__drag-fill ariaLabel"></div>`);
|
||||
this.preventClick = true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
this.preventClick = true;
|
||||
return false;
|
||||
}
|
||||
// av cell select
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue