From 9c416cbcea6bf387db63be4baf457133df156368 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 27 Sep 2023 23:58:48 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/9294 --- app/src/assets/scss/business/_av.scss | 8 ++-- app/src/protyle/render/av/action.ts | 55 +++++++++++++++------------ app/src/protyle/render/av/cell.ts | 4 +- app/src/protyle/render/av/render.ts | 3 +- 4 files changed, 39 insertions(+), 31 deletions(-) diff --git a/app/src/assets/scss/business/_av.scss b/app/src/assets/scss/business/_av.scss index 6a3f0b941d5..410cafeb6bb 100644 --- a/app/src/assets/scss/business/_av.scss +++ b/app/src/assets/scss/business/_av.scss @@ -16,7 +16,7 @@ position: absolute; z-index: 1; 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; height: 100%; width: 100%; @@ -87,7 +87,8 @@ font-size: 87.5%; &:hover { - [data-type="block-ref"] { + [data-type="block-ref"], + [data-type="createdoc"] { display: block; } @@ -198,7 +199,8 @@ align-items: center; transition: var(--b3-transition); - [data-type="block-ref"] { + [data-type="block-ref"], + [data-type="createdoc"] { display: none; position: absolute; right: 5px; diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.ts index 49610bdc998..bd363c8809c 100644 --- a/app/src/protyle/render/av/action.ts +++ b/app/src/protyle/render/av/action.ts @@ -151,6 +151,35 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle 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"); if (cellElement && !cellElement.parentElement.classList.contains("av__row--header")) { cellElement.parentElement.parentElement.querySelectorAll(".av__row--select").forEach(item => { @@ -175,7 +204,7 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle if (addRowElement) { const avID = blockElement.getAttribute("data-av-id"); const srcIDs = [Lute.NewNodeID()]; - const previousID = addRowElement.getAttribute("data-id") || ""; + const previousID = addRowElement.previousElementSibling.getAttribute("data-id") || ""; transaction(protyle, [{ action: "insertAttrViewBlock", avID, @@ -193,30 +222,6 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle 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; }; diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.ts index 986c17e42ae..90b4ae0efaa 100644 --- a/app/src/protyle/render/av/cell.ts +++ b/app/src/protyle/render/av/cell.ts @@ -343,7 +343,7 @@ export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[], type if (!type) { 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; } 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 }; const oldValue: { content: string | number, isNotEmpty?: boolean } = { - content: item.textContent.trim() + content: type === "block" ? item.firstElementChild.textContent.trim() : item.textContent.trim() }; if (type === "number") { oldValue.content = parseFloat(oldValue.content as string); diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.ts index 614865aba24..7e353edd97f 100644 --- a/app/src/protyle/render/av/render.ts +++ b/app/src/protyle/render/av/render.ts @@ -70,7 +70,7 @@ style="width: ${column.width || "200px"}">${getCalcValue(column) || '`; } } else if (cell.valueType === "block") { - text = `${cell.value.block.content || ""}`; + text = `${cell.value.block.content || ""}`; if (cell.value?.isDetached) { text += `${window.siyuan.languages.new}`; } else { @@ -112,6 +112,7 @@ style="width: ${column.width || "200px"}">${getCalcValue(column) || '