mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-20 00:20: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) {
|
if (getResponse.data.isSyncing) {
|
||||||
disabledForeverProtyle(protyle);
|
disabledForeverProtyle(protyle);
|
||||||
} else {
|
} else {
|
||||||
setReadonlyByConfig(protyle);
|
setReadonlyByConfig(protyle, true);
|
||||||
}
|
}
|
||||||
protyle.contentElement.scrollTop = backStack.scrollTop;
|
protyle.contentElement.scrollTop = backStack.scrollTop;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ export class Protyle {
|
||||||
break;
|
break;
|
||||||
case "readonly":
|
case "readonly":
|
||||||
window.siyuan.config.editor.readOnly = data.data;
|
window.siyuan.config.editor.readOnly = data.data;
|
||||||
setReadonlyByConfig(this.protyle);
|
setReadonlyByConfig(this.protyle, true);
|
||||||
break;
|
break;
|
||||||
case "heading2doc":
|
case "heading2doc":
|
||||||
case "li2doc":
|
case "li2doc":
|
||||||
|
|
|
||||||
|
|
@ -399,7 +399,7 @@ export const updateAttrViewCellAnimation = (cellElement: HTMLElement, value: IAV
|
||||||
if (headerValue) {
|
if (headerValue) {
|
||||||
updateHeaderCell(cellElement, headerValue);
|
updateHeaderCell(cellElement, headerValue);
|
||||||
} else {
|
} 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
|
isNotEmpty: !!value
|
||||||
};
|
};
|
||||||
} else if (["text", "block", "url", "phone", "email", "template"].includes(colType)) {
|
} else if (["text", "block", "url", "phone", "email", "template"].includes(colType)) {
|
||||||
|
const textElement = cellElement.querySelector(".av__celltext") as HTMLElement;
|
||||||
cellValue[colType as "text"] = {
|
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") {
|
} else if (colType === "mSelect" || colType === "select") {
|
||||||
const mSelect: IAVCellSelectValue[] = [];
|
const mSelect: IAVCellSelectValue[] = [];
|
||||||
cellElement.querySelectorAll(".b3-chip").forEach((item: HTMLElement) => {
|
cellElement.querySelectorAll(".b3-chip").forEach((item: HTMLElement) => {
|
||||||
|
|
@ -513,7 +517,7 @@ export const updateCellsValue = (protyle: IProtyle, nodeElement: HTMLElement, va
|
||||||
return text;
|
return text;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const renderCell = (cellValue: IAVCellValue, wrap: boolean) => {
|
export const renderCell = (cellValue: IAVCellValue) => {
|
||||||
let text = "";
|
let text = "";
|
||||||
if (["text", "template"].includes(cellValue.type)) {
|
if (["text", "template"].includes(cellValue.type)) {
|
||||||
text = `<span class="av__celltext">${cellValue ? (cellValue[cellValue.type as "text"].content || "") : ""}</span>`;
|
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>`;
|
text += `<svg class="av__checkbox"><use xlink:href="#icon${cellValue?.checkbox?.checked ? "Check" : "Uncheck"}"></use></svg>`;
|
||||||
} else if (cellValue.type === "rollup") {
|
} else if (cellValue.type === "rollup") {
|
||||||
cellValue?.rollup?.contents?.forEach((item) => {
|
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) {
|
if (rollupText) {
|
||||||
text += rollupText + ", ";
|
text += rollupText + ", ";
|
||||||
}
|
}
|
||||||
|
|
@ -668,3 +672,60 @@ export const getPositionByCellElement = (cellElement: HTMLElement) => {
|
||||||
}
|
}
|
||||||
return {rowIndex, celIndex};
|
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"};
|
style="width: ${data.columns[index].width || "200px"};
|
||||||
${cell.valueType === "number" ? "text-align: right;" : ""}
|
${cell.valueType === "number" ? "text-align: right;" : ""}
|
||||||
${cell.bgColor ? `background-color:${cell.bgColor};` : ""}
|
${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) {
|
if (pinIndex === index) {
|
||||||
tableHTML += "</div>";
|
tableHTML += "</div>";
|
||||||
|
|
|
||||||
|
|
@ -109,12 +109,12 @@ ${(item.getAttribute("data-block-id") || item.dataset.dtype === "block") ? ' dat
|
||||||
response.data.filters.forEach((item: IAVFilter) => {
|
response.data.filters.forEach((item: IAVFilter) => {
|
||||||
const sideRowCellElement = sideRow.querySelector(`.av__cell[data-col-id="${item.column}"]`) as HTMLElement;
|
const sideRowCellElement = sideRow.querySelector(`.av__cell[data-col-id="${item.column}"]`) as HTMLElement;
|
||||||
currentRow.querySelector(`.av__cell[data-col-id="${item.column}"]`).innerHTML =
|
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) => {
|
response.data.sorts.forEach((item: IAVSort) => {
|
||||||
const sideRowCellElement = sideRow.querySelector(`.av__cell[data-col-id="${item.column}"]`) as HTMLElement;
|
const sideRowCellElement = sideRow.querySelector(`.av__cell[data-col-id="${item.column}"]`) as HTMLElement;
|
||||||
currentRow.querySelector(`.av__cell[data-col-id="${item.column}"]`).innerHTML =
|
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");
|
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 {avRender} from "../render/av/render";
|
||||||
import {checkFold} from "../../util/noRelyPCFunction";
|
import {checkFold} from "../../util/noRelyPCFunction";
|
||||||
import {
|
import {
|
||||||
|
dragFillCellsValue,
|
||||||
genCellValueByElement,
|
genCellValueByElement,
|
||||||
getCellText,
|
getCellText,
|
||||||
getPositionByCellElement,
|
getPositionByCellElement,
|
||||||
|
|
@ -453,7 +454,7 @@ export class WYSIWYG {
|
||||||
}
|
}
|
||||||
const originData: { [key: string]: IAVCellValue[] } = {}
|
const originData: { [key: string]: IAVCellValue[] } = {}
|
||||||
let lastOriginCellElement
|
let lastOriginCellElement
|
||||||
const lastOriginCellId: string[] = []
|
const originCellIds: string[] = []
|
||||||
nodeElement.querySelectorAll(".av__cell--active").forEach((item: HTMLElement, index: number) => {
|
nodeElement.querySelectorAll(".av__cell--active").forEach((item: HTMLElement, index: number) => {
|
||||||
const rowElement = hasClosestByClassName(item, "av__row");
|
const rowElement = hasClosestByClassName(item, "av__row");
|
||||||
if (rowElement) {
|
if (rowElement) {
|
||||||
|
|
@ -462,7 +463,7 @@ export class WYSIWYG {
|
||||||
}
|
}
|
||||||
originData[rowElement.dataset.id].push(genCellValueByElement(getTypeByCellElement(item), item));
|
originData[rowElement.dataset.id].push(genCellValueByElement(getTypeByCellElement(item), item));
|
||||||
lastOriginCellElement = item
|
lastOriginCellElement = item
|
||||||
lastOriginCellId.push(item.dataset.id)
|
originCellIds.push(item.dataset.id)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const dragFillCellIndex = getPositionByCellElement(lastOriginCellElement);
|
const dragFillCellIndex = getPositionByCellElement(lastOriginCellElement);
|
||||||
|
|
@ -478,7 +479,7 @@ export class WYSIWYG {
|
||||||
if (moveCellElement && moveCellElement.dataset.id) {
|
if (moveCellElement && moveCellElement.dataset.id) {
|
||||||
const newIndex = getPositionByCellElement(moveCellElement);
|
const newIndex = getPositionByCellElement(moveCellElement);
|
||||||
nodeElement.querySelectorAll(".av__cell--active").forEach((item: HTMLElement) => {
|
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");
|
item.classList.remove("av__cell--active");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -506,14 +507,12 @@ export class WYSIWYG {
|
||||||
documentSelf.onselectstart = null;
|
documentSelf.onselectstart = null;
|
||||||
documentSelf.onselect = null;
|
documentSelf.onselect = null;
|
||||||
if (lastCellElement) {
|
if (lastCellElement) {
|
||||||
nodeElement.querySelector(".av__drag-fill")?.remove();
|
dragFillCellsValue(protyle, nodeElement, originData, originCellIds);
|
||||||
selectRow(nodeElement.querySelector(".av__firstcol"), "unselectAll");
|
|
||||||
focusBlock(nodeElement);
|
|
||||||
lastCellElement.insertAdjacentHTML("beforeend", `<div aria-label="${window.siyuan.languages.dragFill}" class="av__drag-fill ariaLabel"></div>`);
|
lastCellElement.insertAdjacentHTML("beforeend", `<div aria-label="${window.siyuan.languages.dragFill}" class="av__drag-fill ariaLabel"></div>`);
|
||||||
this.preventClick = true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
this.preventClick = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// av cell select
|
// av cell select
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue