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/11093

Vanessa643078387734
diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts
index 0821df3dba..c227ba77c0 100644
--- a/app/src/boot/globalEvent/keydown.ts
+++ b/app/src/boot/globalEvent/keydown.ts
@@ -310,14 +310,15 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
if (!isFileFocus && matchHotKey(window.siyuan.config.keymap.general.addToDatabase.custom, event)) {
if (protyle.title?.editElement.contains(range.startContainer)) {
openSearchAV("", protyle.breadcrumb.element, (listItemElement) => {
- const sourceIds: string[] = [protyle.block.rootID];
const avID = listItemElement.dataset.avId;
transaction(protyle, [{
action: "insertAttrViewBlock",
avID,
ignoreFillFilter: true,
- srcIDs: sourceIds,
- isDetached: false,
+ srcs: [{
+ id: protyle.block.rootID,
+ isDetached: false
+ }],
blockID: listItemElement.dataset.nodeId
}, {
action: "doUpdateUpdated",
@@ -325,7 +326,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
data: dayjs().format("YYYYMMDDHHmmss"),
}], [{
action: "removeAttrViewBlock",
- srcIDs: sourceIds,
+ srcIDs: [protyle.block.rootID],
avID,
}]);
focusByRange(range);
@@ -342,17 +343,21 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
}
}
openSearchAV("", selectElement[0] as HTMLElement, (listItemElement) => {
- const sourceIds: string[] = [];
+ const srcIDs: string[] = [];
+ const srcs: IOperationSrcs[] = [];
selectElement.forEach(item => {
- sourceIds.push(item.getAttribute("data-node-id"));
+ srcIDs.push(item.getAttribute("data-node-id"));
+ srcs.push({
+ id: item.getAttribute("data-node-id"),
+ isDetached: false
+ });
});
const avID = listItemElement.dataset.avId;
transaction(protyle, [{
action: "insertAttrViewBlock",
avID,
ignoreFillFilter: true,
- srcIDs: sourceIds,
- isDetached: false,
+ srcs,
blockID: listItemElement.dataset.blockId
}, {
action: "doUpdateUpdated",
@@ -360,7 +365,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
data: dayjs().format("YYYYMMDDHHmmss"),
}], [{
action: "removeAttrViewBlock",
- srcIDs: sourceIds,
+ srcIDs,
avID,
}]);
focusByRange(range);
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index b0f735e7f6..4579fed4ca 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -101,7 +101,7 @@ export class Gutter {
if (item.querySelector("iframe")) {
const embedElement = genEmptyElement();
embedElement.classList.add("protyle-wysiwyg--select");
- getContenteditableElement(embedElement).innerHTML = `<svg class="svg"><use xlink:href="${ buttonElement.querySelector("use").getAttribute("xlink:href")}"></use></svg> ${getLangByType(type)}`;
+ getContenteditableElement(embedElement).innerHTML = `<svg class="svg"><use xlink:href="${buttonElement.querySelector("use").getAttribute("xlink:href")}"></use></svg> ${getLangByType(type)}`;
ghostElement.append(embedElement);
} else {
ghostElement.append(item.cloneNode(true));
@@ -235,8 +235,11 @@ export class Gutter {
action: "insertAttrViewBlock",
avID,
previousID,
- srcIDs,
- isDetached: true,
+ srcs: [{
+ id: srcIDs[0],
+ isDetached: true,
+ content: ""
+ }],
blockID: id,
}, {
action: "doUpdateUpdated",
@@ -817,17 +820,21 @@ export class Gutter {
icon: "iconDatabase",
click: () => {
openSearchAV("", selectsElement[0] as HTMLElement, (listItemElement) => {
- const sourceIds: string[] = [];
+ const srcIDs: string[] = [];
+ const srcs: IOperationSrcs[] = [];
selectsElement.forEach(item => {
- sourceIds.push(item.getAttribute("data-node-id"));
+ srcIDs.push(item.getAttribute("data-node-id"));
+ srcs.push({
+ id:item.getAttribute("data-node-id"),
+ isDetached: false,
+ });
});
const avID = listItemElement.dataset.avId;
transaction(protyle, [{
action: "insertAttrViewBlock",
avID,
- srcIDs: sourceIds,
+ srcs,
ignoreFillFilter: true,
- isDetached: false,
blockID: listItemElement.dataset.blockId
}, {
action: "doUpdateUpdated",
@@ -835,7 +842,7 @@ export class Gutter {
data: dayjs().format("YYYYMMDDHHmmss"),
}], [{
action: "removeAttrViewBlock",
- srcIDs: sourceIds,
+ srcIDs,
avID,
}]);
focusByRange(range);
@@ -1285,14 +1292,15 @@ export class Gutter {
icon: "iconDatabase",
click: () => {
openSearchAV("", nodeElement as HTMLElement, (listItemElement) => {
- const sourceIds: string[] = [id];
const avID = listItemElement.dataset.avId;
transaction(protyle, [{
action: "insertAttrViewBlock",
avID,
- srcIDs: sourceIds,
+ srcs:[{
+ id,
+ isDetached: false
+ }],
ignoreFillFilter: true,
- isDetached: false,
blockID: listItemElement.dataset.blockId
}, {
action: "doUpdateUpdated",
@@ -1300,7 +1308,7 @@ export class Gutter {
data: dayjs().format("YYYYMMDDHHmmss"),
}], [{
action: "removeAttrViewBlock",
- srcIDs: sourceIds,
+ srcIDs: [id],
avID,
}]);
focusByRange(range);
diff --git a/app/src/protyle/header/openTitleMenu.ts b/app/src/protyle/header/openTitleMenu.ts
index 287e65448f..e46d2e44f8 100644
--- a/app/src/protyle/header/openTitleMenu.ts
+++ b/app/src/protyle/header/openTitleMenu.ts
@@ -52,14 +52,15 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
icon: "iconDatabase",
click: () => {
openSearchAV("", protyle.breadcrumb.element, (listItemElement) => {
- const sourceIds: string[] = [response.data.rootID];
const avID = listItemElement.dataset.avId;
transaction(protyle, [{
action: "insertAttrViewBlock",
avID,
ignoreFillFilter: true,
- srcIDs: sourceIds,
- isDetached: false,
+ srcs: [{
+ id: response.data.rootID,
+ isDetached: false
+ }],
blockID: listItemElement.dataset.nodeId
}, {
action: "doUpdateUpdated",
@@ -67,7 +68,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
data: dayjs().format("YYYYMMDDHHmmss"),
}], [{
action: "removeAttrViewBlock",
- srcIDs: sourceIds,
+ srcIDs: [response.data.rootID],
avID,
}]);
focusByRange(range);
diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.ts
index c6931adda3..b6fe38ec0f 100644
--- a/app/src/protyle/render/av/action.ts
+++ b/app/src/protyle/render/av/action.ts
@@ -4,7 +4,7 @@ import {transaction} from "../../wysiwyg/transaction";
import {openEditorTab} from "../../../menus/util";
import {copySubMenu} from "../../../menus/commonMenuItem";
import {
- addDragFill,
+ addDragFill, genCellValueByElement,
getCellText,
getTypeByCellElement,
popTextCell,
@@ -277,13 +277,15 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
icon: "iconDatabase",
click() {
openSearchAV(blockElement.getAttribute("data-av-id"), rowElements[0] as HTMLElement, (listItemElement) => {
- const srcs: { id: string, content: string }[] = [];
+ const srcs: IOperationSrcs[] = [];
const sourceIds: string[] = [];
rowElements.forEach(item => {
- const rowId = item.getAttribute("data-id")
+ const rowId = item.getAttribute("data-id")
+ const blockValue = genCellValueByElement("block", item.querySelector(".av__cell[data-block-id]"));
srcs.push({
- content: item.querySelector(".av__cell[data-block-id] .av__celltext").textContent.trim(),
- id: rowId
+ content: blockValue.block.content,
+ id: rowId,
+ isDetached: blockValue.isDetached,
});
sourceIds.push(rowId);
})
@@ -293,7 +295,6 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
avID,
ignoreFillFilter: true,
srcs,
- isDetached: false,
blockID: listItemElement.dataset.nodeId
}, {
action: "doUpdateUpdated",
diff --git a/app/src/protyle/render/av/row.ts b/app/src/protyle/render/av/row.ts
index 639f8ca164..4107b1f64b 100644
--- a/app/src/protyle/render/av/row.ts
+++ b/app/src/protyle/render/av/row.ts
@@ -319,12 +319,16 @@ export const deleteRow = (blockElement: HTMLElement, protyle: IProtyle) => {
blockIds.push(item.querySelector(".av__cell[data-block-id]").getAttribute("data-block-id"));
});
rowElements.forEach(item => {
+ const blockValue = genCellValueByElement("block", item.querySelector(".av__cell[data-block-id]"));
undoOperations.push({
action: "insertAttrViewBlock",
avID,
previousID: item.previousElementSibling?.getAttribute("data-id") || "",
- srcIDs: [item.getAttribute("data-id")],
- isDetached: item.querySelector('.av__cell[data-detached="true"]') ? true : false,
+ srcs: [{
+ id: item.getAttribute("data-id"),
+ isDetached: blockValue.isDetached,
+ content: blockValue.block.content
+ }],
blockID: blockElement.dataset.nodeId
});
});
@@ -354,16 +358,22 @@ export const deleteRow = (blockElement: HTMLElement, protyle: IProtyle) => {
export const insertRows = (blockElement: HTMLElement, protyle: IProtyle, count: number, previousID: string) => {
const avID = blockElement.getAttribute("data-av-id");
const srcIDs: string[] = [];
+ const srcs: IOperationSrcs[] = [];
new Array(count).fill(0).forEach(() => {
- srcIDs.push(Lute.NewNodeID());
+ const newNodeID = Lute.NewNodeID();
+ srcIDs.push(newNodeID);
+ srcs.push({
+ id: newNodeID,
+ isDetached: true,
+ content: "",
+ });
});
const newUpdated = dayjs().format("YYYYMMDDHHmmss");
transaction(protyle, [{
action: "insertAttrViewBlock",
avID,
previousID,
- srcIDs,
- isDetached: true,
+ srcs,
blockID: blockElement.dataset.nodeId,
}, {
action: "doUpdateUpdated",
diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.ts
index ca4746f670..1b6aa772a6 100644
--- a/app/src/protyle/util/editorCommonEvent.ts
+++ b/app/src/protyle/util/editorCommonEvent.ts
@@ -799,6 +799,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
}
const sourceIds: string [] = [];
+ const srcs: IOperationSrcs[] = [];
sourceElements.forEach(item => {
item.classList.remove("protyle-wysiwyg--select", "protyle-wysiwyg--hl");
item.removeAttribute("select-start");
@@ -807,7 +808,12 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
item.querySelectorAll('[data-type="search-mark"]').forEach(markItem => {
markItem.outerHTML = markItem.innerHTML;
});
- sourceIds.push(item.getAttribute("data-node-id"));
+ const id = item.getAttribute("data-node-id")
+ sourceIds.push(id);
+ srcs.push({
+ id,
+ isDetached: false,
+ })
});
hideElements(["gutter"], protyle);
@@ -900,8 +906,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
action: "insertAttrViewBlock",
avID,
previousID,
- srcIDs: sourceIds,
- isDetached: false,
+ srcs,
blockID: blockElement.dataset.nodeId
}, {
action: "doUpdateUpdated",
@@ -967,12 +972,18 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {
}
const avID = blockElement.getAttribute("data-av-id");
const newUpdated = dayjs().format("YYYYMMDDHHmmss");
+ const srcs: IOperationSrcs[] = [];
+ ids.forEach(id => {
+ srcs.push({
+ id,
+ isDetached: false,
+ });
+ });
transaction(protyle, [{
action: "insertAttrViewBlock",
avID,
previousID,
- srcIDs: ids,
- isDetached: false,
+ srcs,
blockID: blockElement.dataset.nodeId,
}, {
action: "doUpdateUpdated",
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts
index a41140c066..e3e6274fb8 100644
--- a/app/src/types/index.d.ts
+++ b/app/src/types/index.d.ts
@@ -480,13 +480,20 @@ interface IOperation {
isDetached?: boolean // insertAttrViewBlock 专享
ignoreFillFilter?: boolean // insertAttrViewBlock 专享
srcIDs?: string[] // removeAttrViewBlock 专享
- srcs?: { id: string, content: string }[] // insertAttrViewBlock 专享
+ srcs?: IOperationSrcs[] // insertAttrViewBlock 专享
name?: string // addAttrViewCol 专享
type?: TAVCol // addAttrViewCol 专享
deckID?: string // add/removeFlashcards 专享
blockIDs?: string[] // add/removeFlashcards 专享
}
+interface IOperationSrcs {
+ id: string,
+ content?: string,
+ isDetached: boolean
+}
+
+
interface IObject {
[key: string]: string;
}