Skip to content

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

:sparkles: Support document navigation in automation collection scopes https://github.com/siyuan-note/siyuan/issues/20639

Daniel944ac856955a
diff --git a/app/src/assets/scss/business/_av.scss b/app/src/assets/scss/business/_av.scss
index 2be6ad34a2..54b4c5d286 100644
--- a/app/src/assets/scss/business/_av.scss
+++ b/app/src/assets/scss/business/_av.scss
@@ -3147,6 +3147,12 @@ img.av__cellassetimg {
text-align: left;
}
+ &-source-list {
+ display: flex;
+ flex-direction: column;
+ gap: 4px;
+ }
+
&-enabled,
&-tools {
align-self: flex-end;
@@ -3200,6 +3206,12 @@ img.av__cellassetimg {
}
}
+ &-source-row {
+ flex-wrap: nowrap;
+ column-gap: 0;
+ min-height: 24px;
+ }
+
&-row[data-condition] {
flex-wrap: nowrap;
align-items: flex-start;
diff --git a/app/src/protyle/render/av/blockCollection.ts b/app/src/protyle/render/av/blockCollection.ts
index f9dfc998cf..b9707587e7 100644
--- a/app/src/protyle/render/av/blockCollection.ts
+++ b/app/src/protyle/render/av/blockCollection.ts
@@ -8,6 +8,7 @@ import {isMobile} from "../../../util/functions";
import {movePathTo} from "../../../util/pathName";
import {transaction} from "../../wysiwyg/transaction";
import {waitForPendingTransactions} from "../../util/transactionQueue";
+import {openLink} from "../../../editor/openLink";
export const collectionSourceIncomplete = (source: AVAutomationBlockSourceInput) => !source ||
!(source.notebookIDs?.length || source.documentIDs?.length) ||
@@ -25,7 +26,7 @@ export const mountBlockCollectionSource = (host: HTMLElement, source: AVAutomati
};
const names = new Map<string, string>();
let revision = 0;
- const removeButton = (kind: string, index: number) => `<button type="button" class="block__icon" data-remove="${kind}" data-index="${index}" aria-label="${escapeAttr(lang.delete)}"><svg><use xlink:href="#iconClose"></use></svg></button>`;
+ const removeButton = (kind: string, index: number) => `<svg class="b3-menu__action b3-menu__action--show b3-menu__action--warning fn__pointer ariaLabel" data-remove="${kind}" data-index="${index}" role="button" tabindex="0" data-position="north" aria-label="${escapeAttr(lang.delete)}"><use xlink:href="#iconClose"></use></svg>`;
const render = async () => {
const version = ++revision;
await Promise.all((source.documentIDs || []).map(async id => {
@@ -41,7 +42,7 @@ export const mountBlockCollectionSource = (host: HTMLElement, source: AVAutomati
host.innerHTML = `<div class="av__automation-action">
<div class="ft__on-surface ft__smaller">${lang.automationCollectionTip}</div>
<button type="button" class="b3-button b3-button--outline av__automation-source-action" data-scope>${lang.automationCollectionScope}</button>
-${notebooks.length || documents.length ? `<div>${notebooks.map((id, i) => `<div class="av__automation-row"><span class="fn__flex-1 ft__breakword">${escapeHtml(window.siyuan.notebooks.find(box => box.id === id)?.name || id)}</span>${removeButton("notebook", i)}</div>`).join("")}${documents.map((id, i) => `<div class="av__automation-row"><span class="fn__flex-1 ft__breakword">${escapeHtml(names.get(id) || id)}</span>${removeButton("document", i)}</div>`).join("")}</div>` : ""}
+${notebooks.length || documents.length ? `<div class="av__automation-source-list">${notebooks.map((id, i) => `<div class="av__automation-row av__automation-source-row"><svg class="block__logoicon ft__on-surface"><use xlink:href="#iconNotebook"></use></svg><span class="fn__flex-1 ft__breakword">${escapeHtml(window.siyuan.notebooks.find(box => box.id === id)?.name || id)}</span>${removeButton("notebook", i)}</div>`).join("")}${documents.map((id, i) => `<div class="av__automation-row av__automation-source-row"><span class="b3-list-item__icon fn__pointer popover__block" data-id="${escapeAttr(id)}"><svg><use xlink:href="#iconFile"></use></svg></span><a href="siyuan://blocks/${escapeAttr(id)}" class="fn__flex-1 ft__breakword">${escapeHtml(names.get(id) || id)}</a>${removeButton("document", i)}</div>`).join("")}</div>` : ""}
<label class="av__automation-control"><span>${lang.automationCollectionTags}</span><input class="b3-text-field" data-tags value="${escapeAttr((source.tags || []).join(", "))}"></label>
<button type="button" class="b3-button b3-button--cancel av__automation-source-action" data-types><svg><use xlink:href="#iconDown"></use></svg><span>${lang.automationCollectionTypes}: ${escapeHtml((source.types || []).map(type => types[type] || type).join(", ") || lang.all)}</span></button>
${attributes.map((attr, i) => `<div class="av__automation-control" data-attribute="${i}"><div class="av__automation-row"><input class="b3-text-field fn__flex-1" data-attr-name aria-label="${escapeAttr(lang.attr)}" placeholder="custom-name" value="${escapeAttr(attr.name)}">${removeButton("attribute", i)}</div><div class="av__automation-row"><select class="b3-select" data-attr-operator aria-label="${escapeAttr(lang.filter)}">${Object.entries({equals: lang.filterOperatorIs, contains: lang.filterOperatorContains, exists: lang.automationAttrExists, notExists: lang.automationAttrNotExists}).map(([operator, label]) => `<option value="${operator}"${attr.operator === operator ? " selected" : ""}>${label}</option>`).join("")}</select>${["equals", "contains"].includes(attr.operator) ? `<input class="b3-text-field fn__flex-1" data-attr-value aria-label="${escapeAttr(lang.text)}" value="${escapeAttr(attr.value || "")}">` : ""}</div></div>`).join("")}
@@ -50,7 +51,13 @@ ${attributes.map((attr, i) => `<div class="av__automation-control" data-attribut
onResize();
};
host.addEventListener("click", event => {
- const target = (event.target as Element).closest<HTMLElement>("button");
+ const link = (event.target as Element).closest<HTMLAnchorElement>("a[href]");
+ if (link) {
+ event.preventDefault();
+ openLink(protyle.app, link.getAttribute("href"), event, event.ctrlKey || event.metaKey);
+ return;
+ }
+ const target = (event.target as Element).closest<HTMLElement>("button, [data-remove]");
if (!target) { return; }
if (target.hasAttribute("data-scope")) {
movePathTo({title: lang.automationCollectionScope, flashcard: false, sourceNotebookIds: [protyle.notebookId],
@@ -94,6 +101,14 @@ ${attributes.map((attr, i) => `<div class="av__automation-control" data-attribut
save();
void render();
});
+ host.addEventListener("keydown", event => {
+ const target = (event.target as Element).closest<SVGElement>("[data-remove]");
+ if (target && (event.key === "Enter" || event.key === " ")) {
+ event.preventDefault();
+ event.stopPropagation();
+ target.dispatchEvent(new MouseEvent("click", {bubbles: true}));
+ }
+ });
host.addEventListener("change", event => {
const target = event.target as HTMLInputElement;
if (target.hasAttribute("data-tags")) {