Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/9294

Vanessa9c416cbcea6b
diff --git a/app/src/assets/scss/business/_av.scss b/app/src/assets/scss/business/_av.scss
index 6a3f0b941d..410cafeb6b 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 49610bdc99..bd363c8809 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 986c17e42a..90b4ae0efa 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 614865aba2..7e353edd97 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) || '<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>`;
}
} 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) {
text += `<span class="b3-chip b3-chip--info b3-chip--small" data-type="createdoc" >${window.siyuan.languages.new}</span>`;
} 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}"
${cell.valueType === "block" ? 'data-block-id="' + (cell.value.block.id || "") + '"' : ""}
+${cell.value?.isDetached ? ' data-detached="true"' : ""}
style="width: ${data.columns[index].width || "200px"};
${cell.bgColor ? `background-color:${cell.bgColor};` : ""}
${data.columns[index].wrap ? "" : "white-space: nowrap;"}