An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Refine automation controls and contextual removal buttons
Daniel4bea56ad433c
diff --git a/app/src/assets/scss/business/_av.scss b/app/src/assets/scss/business/_av.scssindex b6413443ba..67986df673 100644--- a/app/src/assets/scss/business/_av.scss+++ b/app/src/assets/scss/business/_av.scss@@ -3130,6 +3130,33 @@ img.av__cellassetimg {min-width: 0;}+ &-enabled,+ &-tools {+ align-self: flex-end;+ min-height: 28px;+ }++ &-remove {+ pointer-events: none;+ }++ &-row[data-condition]:hover > .av__automation-remove,+ &-row[data-condition]:focus-within > .av__automation-remove,+ &-action[data-index]:hover > .av__automation-row > .av__automation-remove,+ &-action[data-index]:focus-within > .av__automation-row > .av__automation-remove,+ &-field[data-field-id]:hover > .av__automation-row > .av__automation-remove,+ &-field[data-field-id]:focus-within > .av__automation-row > .av__automation-remove {+ opacity: 1;+ pointer-events: auto;+ }++ @media (hover: none), (any-pointer: coarse) {+ &-remove {+ opacity: 1;+ pointer-events: auto;+ }+ }+[data-conditions] {display: flex;flex-direction: column;diff --git a/app/src/protyle/render/av/automation.ts b/app/src/protyle/render/av/automation.tsindex 3b6cd45ee4..27f8e955bd 100644--- a/app/src/protyle/render/av/automation.ts+++ b/app/src/protyle/render/av/automation.ts@@ -41,8 +41,8 @@ const compatibleFields = (database: AVAttributeViewData, field: IAVColumn): IAVCconst optionHTML = (value: string, label: string, selected: string) =>`<option value="${escapeAttr(value)}"${value === selected ? " selected" : ""}>${escapeHtml(label)}</option>`;-const iconButton = (action: string, icon: string, label: string, warning = false) =>- `<svg class="b3-menu__action b3-menu__action--show${warning ? " b3-menu__action--warning" : ""} fn__pointer ariaLabel" data-action="${action}" role="button" tabindex="0" data-position="north" aria-label="${escapeAttr(label)}"><use xlink:href="#${icon}"></use></svg>`;+const iconButton = (action: string, icon: string, label: string, warning = false, contextual = false) =>+ `<svg class="b3-menu__action ${contextual ? "av__automation-remove" : "b3-menu__action--show"}${warning ? " b3-menu__action--warning" : ""} fn__pointer ariaLabel" data-action="${action}" role="button" tabindex="0" data-position="north" aria-label="${escapeAttr(label)}"><use xlink:href="#${icon}"></use></svg>`;export const openAutomationMenu = async (options: {protyle: IProtyle,@@ -220,7 +220,7 @@ export const openAutomationMenu = async (options: {host.innerHTML = `<div data-conditions></div><button class="b3-button b3-button--cancel" type="button" data-add-condition>${lang.addFilterCondition}</button>`;const render = () => {const list = host.querySelector<HTMLElement>("[data-conditions]");- list.innerHTML = filters.map((_, i) => `<div class="av__automation-row" data-condition="${i}"><div class="av__automation-filter" data-filter></div>${iconButton("remove-condition", "iconTrashcan", lang.delete, true)}</div>`).join("");+ list.innerHTML = filters.map((_, i) => `<div class="av__automation-row" data-condition="${i}"><div class="av__automation-filter" data-filter></div>${iconButton("remove-condition", "iconTrashcan", lang.delete, true, true)}</div>`).join("");list.querySelectorAll<HTMLElement>("[data-condition]").forEach(element => {const i = Number(element.dataset.condition);const filterRoot = element.querySelector<HTMLElement>("[data-filter]");@@ -304,8 +304,8 @@ export const openAutomationMenu = async (options: {return;}body.innerHTML = `<div class="ft__on-surface ft__smaller">${lang.automationTip}</div>-<div class="av__automation-row">${rule ? `<label class="av__automation-control fn__flex-1"><span class="ft__on-surface">${lang.automationRule}</span><select class="b3-select" data-rule>${rules.map((item, i) => optionHTML(String(i), item.name, String(index))).join("")}</select></label>` : ""}${iconButton("add-rule", "iconAdd", lang.new)}${rule ? iconButton("remove-rule", "iconTrashcan", lang.delete, true) : ""}</div>-${rule ? `<div class="av__automation-row"><label class="av__automation-control fn__flex-1"><span class="ft__on-surface">${lang.name}</span><input class="b3-text-field" data-name value="${escapeAttr(rule.name)}"></label><label class="av__automation-row"><span>${lang.enable}</span><input type="checkbox" class="b3-switch" data-enabled${rule.enabled ? " checked" : ""}></label></div>+<div class="av__automation-row">${rule ? `<label class="av__automation-control fn__flex-1"><span class="ft__on-surface">${lang.automationRule}</span><select class="b3-select" data-rule>${rules.map((item, i) => optionHTML(String(i), item.name, String(index))).join("")}</select></label>` : ""}<div class="av__automation-row av__automation-tools">${iconButton("add-rule", "iconAdd", lang.new)}${rule ? iconButton("remove-rule", "iconTrashcan", lang.delete, true) : ""}</div></div>+${rule ? `<div class="av__automation-row"><label class="av__automation-control fn__flex-1"><span class="ft__on-surface">${lang.name}</span><input class="b3-text-field" data-name value="${escapeAttr(rule.name)}"></label><label class="av__automation-row av__automation-enabled"><input type="checkbox" class="b3-switch ariaLabel" aria-label="${escapeAttr(lang.enable)}" data-position="north" data-enabled${rule.enabled ? " checked" : ""}></label></div><div class="ft__on-surface ft__smaller">${lang.automationAutoSaveTip}</div><div class="ft__on-surface ft__smaller fn__none" role="status" data-status></div><section class="av__automation-section"><div class="av__automation-row ft__b"><span class="ft__on-surface">1</span><span>${lang.automationWhen}</span></div>@@ -330,7 +330,7 @@ ${rule.trigger === "block" ? "" : `<div class="ft__on-surface ft__smaller">${lanconst actionsHost = body.querySelector<HTMLElement>("[data-actions]");actionsHost.innerHTML = rule.actions.map((action, i) => {const target = databases.get(targetID(action));- return `<div class="av__automation-action" data-index="${i}"><div class="av__automation-row"><span class="ft__b fn__flex-1">${lang.automationAction} ${i + 1}</span>${action.type === "collect" ? "" : iconButton("remove-action", "iconTrashcan", lang.delete, true)}</div>+ return `<div class="av__automation-action" data-index="${i}"><div class="av__automation-row"><span class="ft__b fn__flex-1">${lang.automationAction} ${i + 1}</span>${action.type === "collect" ? "" : iconButton("remove-action", "iconTrashcan", lang.delete, true, true)}</div>${action.type === "collect" ? `<div>${lang.automationCollectionAction}</div>` : `<div class="av__automation-columns"><label class="av__automation-control"><span class="ft__on-surface">${lang.automationOperation}</span><select class="b3-select" data-action-type>${optionHTML("edit", lang.editFields, action.type)}${optionHTML("add", lang.new, action.type)}</select></label><label class="av__automation-control"><span class="ft__on-surface">${action.type === "add" ? lang.database : lang.automationTarget}</span><select class="b3-select" data-target>${optionHTML("current", action.type === "add" ? lang.thisDatabase : lang.automationCurrentItem, action.target)}${optionHTML("related", action.type === "add" ? lang.relation : lang.relatedItems, action.target)}${optionHTML("filtered", action.type === "add" ? lang.database : lang.automationMatchingItems, action.target)}</select></label></div>`}${action.target === "related" ? `<select class="b3-select fn__block" data-relation aria-label="${lang.relation}">${optionHTML("", lang.selectRelation, action.relationKeyID || "")}${fieldsOf(database).filter(field => field.type === "relation" && field.relation?.avID).map(field => optionHTML(field.id, field.name, action.relationKeyID)).join("")}</select>` : action.target === "filtered" ? `<button type="button" class="b3-button b3-button--outline fn__block" data-action="database">${escapeHtml(target?.name || lang.select)} (${lang.database})</button>` : ""}@@ -355,7 +355,7 @@ ${target ? `${action.type === "edit" && action.target !== "current" ? `<div clasrow.className = "av__automation-field";row.dataset.fieldId = keyID;const compatible = action.type === "collect" ? [] : compatibleFields(database, field);- row.innerHTML = `<div class="av__automation-row"><span class="fn__flex-1">${escapeHtml(field?.name || `${lang.invalid}: ${keyID}`)}</span>${iconButton("remove-field", "iconClose", lang.delete, true)}</div>+ row.innerHTML = `<div class="av__automation-row"><span class="fn__flex-1">${escapeHtml(field?.name || `${lang.invalid}: ${keyID}`)}</span>${iconButton("remove-field", "iconClose", lang.delete, true, true)}</div>${field ? `<div class="av__automation-row"><label class="av__automation-control"><span class="ft__on-surface">${lang.automationValueMode}</span><select class="b3-select" data-mode>${optionHTML("static", lang.automationStaticValue, value.mode)}${compatible.length ? optionHTML("source", lang.automationSourceField, value.mode) : ""}${field.type === "date" ? optionHTML("currentTime", lang.automationTriggerTime, value.mode) : ""}${action.type !== "collect" && field.type === "relation" && field.relation?.avID === avID ? optionHTML("triggerItem", lang.automationTriggerItem, value.mode) : ""}</select></label><div class="av__automation-value" data-value></div></div>` : ""}`;fieldsHost.append(row);if (!field) {diff --git a/app/tests/automationPanel.test.js b/app/tests/automationPanel.test.jsindex 26a306dc29..6955903113 100644--- a/app/tests/automationPanel.test.js+++ b/app/tests/automationPanel.test.js@@ -81,10 +81,46 @@ const runCases = async (sources, css, mobile) => {assert.ok(sections[1].contains(get("[data-source-conditions]")));assert.ok(sections[2].contains(get("[data-actions]")));assert.equal(get("[data-rule]").labels[0].textContent.includes(lang.automationRule), true);- assert.equal(get("[data-enabled]").labels[0].textContent.trim(), lang.enable);+ assert.equal(get("[data-enabled]").labels[0].textContent.trim(), "");+ assert.equal(get("[data-enabled]").getAttribute("aria-label"), lang.enable);+ assert.ok(get("[data-enabled]").classList.contains("ariaLabel"), "the enable switch exposes its label as a tooltip");assert.equal(get("[data-trigger-field] option").textContent, lang.automationAnyField);assert.equal(get("[data-status]").textContent, lang.automationReady);assert.equal(transactions.length, 0, "opening settings must preserve the stored rule");+ const nameRect = get("[data-name]").getBoundingClientRect();+ const enabledRect = get("[data-enabled]").getBoundingClientRect();+ assert.ok(Math.abs((nameRect.top + nameRect.bottom) / 2 - (enabledRect.top + enabledRect.bottom) / 2) <= 1,+ "the enable switch aligns with the name input rather than its label");+ const ruleRect = get("[data-rule]").getBoundingClientRect();+ for (const action of ["add-rule", "remove-rule"]) {+ const button = get(`[data-action="${action}"]`).getBoundingClientRect();+ assert.ok(Math.abs((ruleRect.top + ruleRect.bottom) / 2 - (button.top + button.bottom) / 2) <= 1,+ "rule actions align with the selector rather than its label");+ }+ const removals = [+ ['[data-source-conditions] [data-condition="0"]', '[data-source-conditions] [data-action="remove-condition"]'],+ ['[data-actions] [data-index="0"]', '[data-actions] [data-action="remove-action"]'],+ ['[data-field-id="finished"]', '[data-actions] [data-action="remove-field"]'],+ ];+ assert.equal(matchMedia("(hover: none), (any-pointer: coarse)").matches, mobile, "touch devices have visible removal controls");+ for (const [rowSelector, buttonSelector] of removals) {+ const button = get(buttonSelector);+ button.scrollIntoView({block: "center"});+ await require("electron").ipcRenderer.invoke("automation-pointer", window.innerWidth - 2, 2);+ await tick();+ const before = button.getBoundingClientRect();+ assert.equal(getComputedStyle(button).opacity, mobile ? "1" : "0", "removal is contextual on desktop and visible on touch");+ button.focus();+ assert.equal(getComputedStyle(button).opacity, "1", "keyboard focus reveals the removal button");+ button.blur();+ const rowRect = get(rowSelector).getBoundingClientRect();+ await require("electron").ipcRenderer.invoke("automation-pointer", Math.round(rowRect.left + 8), Math.round(rowRect.top + 8));+ await tick();+ assert.equal(getComputedStyle(button).opacity, "1",+ `hovering the item's content reveals its removal button: ${rowSelector}, ${JSON.stringify(rowRect)}, ${Array.from(document.querySelectorAll(":hover"), item => item.className).join(" / ")}`);+ assert.equal(button.getBoundingClientRect().right, before.right, "revealing removal does not change its position");+ }+ await require("electron").ipcRenderer.invoke("automation-pointer", window.innerWidth - 2, 2);const originalConditions = structuredClone(database.automations.rules[0].conditions);await click('[data-source-conditions] [data-type="selectTrigger"]');assert.notEqual(get('[data-source-conditions] [data-type="selectDropdown"]').style.display, "none");@@ -288,6 +324,7 @@ if (process.versions.electron && process.type === "browser") {let code = 0;try {ipcMain.handle("automation-size", (_event, width, height) => win.setContentSize(width, height));+ ipcMain.handle("automation-pointer", (_event, x, y) => win.webContents.debugger.sendCommand("Input.dispatchMouseEvent", {type: "mouseMoved", x, y}));ipcMain.handle("automation-capture", async (_event, name) => {if (!process.env.SIYUAN_AUTOMATION_CAPTURE_DIR) return;assert.match(name, /^(desktop|mobile)-\d+-(daylight|midnight)(-actions|-conditions)?$/);@@ -310,6 +347,8 @@ if (process.versions.electron && process.type === "browser") {for (const name of ["daylight", "midnight"]) sources[name] = fs.readFileSync(path.join(__dirname, `../appearance/themes/${name}/theme.css`), "utf8");for (const mobile of [false, true]) {await win.loadURL("data:text/html,<html><body></body></html>");+ if (!win.webContents.debugger.isAttached()) win.webContents.debugger.attach("1.3");+ await win.webContents.debugger.sendCommand("Emulation.setTouchEmulationEnabled", {enabled: mobile});const css = sources.daylight + sass.compile(path.join(__dirname, `../src/assets/scss/${mobile ? "mobile" : "base"}.scss`), {logger: sass.Logger.silent}).css;await win.webContents.executeJavaScript(`(${runCases.toString()})(${JSON.stringify(sources)}, ${JSON.stringify(css)}, ${mobile})`);}