Vanessa 2023-09-27 23:58:48 +08:00
parent 7a203eabdd
commit 9c416cbcea
4 changed files with 39 additions and 31 deletions

View file

@ -16,7 +16,7 @@
position: absolute; position: absolute;
z-index: 1; z-index: 1;
animation: 1s linear infinite keyframes-pulse; animation: 1s linear infinite keyframes-pulse;
background: linear-gradient(90deg,transparent 0,rgba(255,255,255,.4) 50%,transparent 100%); background: linear-gradient(90deg, transparent 0, rgba(255, 255, 255, .4) 50%, transparent 100%);
display: block; display: block;
height: 100%; height: 100%;
width: 100%; width: 100%;
@ -87,7 +87,8 @@
font-size: 87.5%; font-size: 87.5%;
&:hover { &:hover {
[data-type="block-ref"] { [data-type="block-ref"],
[data-type="createdoc"] {
display: block; display: block;
} }
@ -198,7 +199,8 @@
align-items: center; align-items: center;
transition: var(--b3-transition); transition: var(--b3-transition);
[data-type="block-ref"] { [data-type="block-ref"],
[data-type="createdoc"] {
display: none; display: none;
position: absolute; position: absolute;
right: 5px; right: 5px;

View file

@ -151,6 +151,35 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
return true; return true;
} }
const createDocElement = hasClosestByAttribute(event.target, "data-type", "createdoc");
if (createDocElement) {
fetchPost("/api/filetree/getHPathByPath", {
notebook: protyle.notebookId,
path: protyle.path,
}, (response) => {
fetchPost("/api/filetree/createDocWithMd", {
notebook: protyle.notebookId,
path: pathPosix().join(response.data, createDocElement.previousElementSibling.textContent.trim() || "Untitled"),
parentID: protyle.block.rootID,
markdown: ""
}, response => {
transaction(protyle, [{
action: "updateAttrViewCell",
id: createDocElement.parentElement.dataset.id,
avID: blockElement.getAttribute("data-av-id"),
keyID: createDocElement.parentElement.dataset.colId,
rowID: createDocElement.parentElement.parentElement.dataset.id,
data: {
isDetached: false
}
}]);
});
});
event.preventDefault();
event.stopPropagation();
return true;
}
const cellElement = hasClosestByClassName(event.target, "av__cell"); const cellElement = hasClosestByClassName(event.target, "av__cell");
if (cellElement && !cellElement.parentElement.classList.contains("av__row--header")) { if (cellElement && !cellElement.parentElement.classList.contains("av__row--header")) {
cellElement.parentElement.parentElement.querySelectorAll(".av__row--select").forEach(item => { cellElement.parentElement.parentElement.querySelectorAll(".av__row--select").forEach(item => {
@ -175,7 +204,7 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
if (addRowElement) { if (addRowElement) {
const avID = blockElement.getAttribute("data-av-id"); const avID = blockElement.getAttribute("data-av-id");
const srcIDs = [Lute.NewNodeID()]; const srcIDs = [Lute.NewNodeID()];
const previousID = addRowElement.getAttribute("data-id") || ""; const previousID = addRowElement.previousElementSibling.getAttribute("data-id") || "";
transaction(protyle, [{ transaction(protyle, [{
action: "insertAttrViewBlock", action: "insertAttrViewBlock",
avID, avID,
@ -193,30 +222,6 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
return true; return true;
} }
const createDocElement = hasClosestByAttribute(event.target, "data-type","createdoc");
if (createDocElement) {
// fetchPost("/api/filetree/createDocWithMd", {
// notebook: protyle.notebookId,
// path: pathPosix().join(pathString, realFileName),
// parentID: protyle.block.rootID,
// markdown: ""
// }, response => {
// transaction(protyle, [{
// action: "updateAttrViewCell",
// id: cellId,
// avID,
// keyID: colId,
// rowID,
// data: {
// isDetached: false
// }
// }]);
// });
event.preventDefault();
event.stopPropagation();
return true;
}
return false; return false;
}; };

View file

@ -343,7 +343,7 @@ export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[], type
if (!type) { if (!type) {
type = cellElements[0].parentElement.parentElement.firstElementChild.querySelector(`[data-col-id="${cellElements[0].getAttribute("data-col-id")}"]`).getAttribute("data-dtype") as TAVCol; type = cellElements[0].parentElement.parentElement.firstElementChild.querySelector(`[data-col-id="${cellElements[0].getAttribute("data-col-id")}"]`).getAttribute("data-dtype") as TAVCol;
} }
if (type === "block" && (cellElements.length > 0 || !cellElements[0].getAttribute("data-detached"))) { if (type === "block" && (cellElements.length > 1 || !cellElements[0].getAttribute("data-detached"))) {
return; return;
} }
const cellRect = cellElements[0].getBoundingClientRect(); const cellRect = cellElements[0].getBoundingClientRect();
@ -416,7 +416,7 @@ const updateCellValue = (protyle: IProtyle, type: TAVCol, cellElements: HTMLElem
content: (avMaskElement.querySelector(".b3-text-field") as HTMLInputElement).value content: (avMaskElement.querySelector(".b3-text-field") as HTMLInputElement).value
}; };
const oldValue: { content: string | number, isNotEmpty?: boolean } = { const oldValue: { content: string | number, isNotEmpty?: boolean } = {
content: item.textContent.trim() content: type === "block" ? item.firstElementChild.textContent.trim() : item.textContent.trim()
}; };
if (type === "number") { if (type === "number") {
oldValue.content = parseFloat(oldValue.content as string); oldValue.content = parseFloat(oldValue.content as string);

View file

@ -70,7 +70,7 @@ style="width: ${column.width || "200px"}">${getCalcValue(column) || '<svg><use x
text += `<span data-type="copy" class="b3-tooltips b3-tooltips__n block__icon" aria-label="${window.siyuan.languages.copy}"><svg><use xlink:href="#iconCopy"></use></svg></span>`; text += `<span data-type="copy" class="b3-tooltips b3-tooltips__n block__icon" aria-label="${window.siyuan.languages.copy}"><svg><use xlink:href="#iconCopy"></use></svg></span>`;
} }
} else if (cell.valueType === "block") { } else if (cell.valueType === "block") {
text = `<span class="av__celltext"${cell.value.isDetached ? ' data-detached="true""' : ""}>${cell.value.block.content || ""}</span>`; text = `<span class="av__celltext">${cell.value.block.content || ""}</span>`;
if (cell.value?.isDetached) { if (cell.value?.isDetached) {
text += `<span class="b3-chip b3-chip--info b3-chip--small" data-type="createdoc" >${window.siyuan.languages.new}</span>`; text += `<span class="b3-chip b3-chip--info b3-chip--small" data-type="createdoc" >${window.siyuan.languages.new}</span>`;
} else { } else {
@ -112,6 +112,7 @@ style="width: ${column.width || "200px"}">${getCalcValue(column) || '<svg><use x
} }
tableHTML += `<div class="av__cell" data-id="${cell.id}" data-col-id="${data.columns[index].id}" tableHTML += `<div class="av__cell" data-id="${cell.id}" data-col-id="${data.columns[index].id}"
${cell.valueType === "block" ? 'data-block-id="' + (cell.value.block.id || "") + '"' : ""} ${cell.valueType === "block" ? 'data-block-id="' + (cell.value.block.id || "") + '"' : ""}
${cell.value?.isDetached ? ' data-detached="true"' : ""}
style="width: ${data.columns[index].width || "200px"}; style="width: ${data.columns[index].width || "200px"};
${cell.bgColor ? `background-color:${cell.bgColor};` : ""} ${cell.bgColor ? `background-color:${cell.bgColor};` : ""}
${data.columns[index].wrap ? "" : "white-space: nowrap;"} ${data.columns[index].wrap ? "" : "white-space: nowrap;"}