Skip to content

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

:bug: Align automation menus and preserve scope previews https://github.com/siyuan-note/siyuan/issues/20645

Danielbd52c97fecba
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20240208172514-9dsv6na.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20240208172514-9dsv6na.sy
index ea9e69c7a5..3890f82410 100644
--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20240208172514-9dsv6na.sy
+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-xaduj2o/20240208172514-9dsv6na.sy
@@ -7,7 +7,7 @@
"id": "20240208172514-9dsv6na",
"title": "Database",
"type": "doc",
- "updated": "20261018000619"
+ "updated": "20261018120429"
},
"Children": [
{
@@ -4540,12 +4540,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261015141042-nrq3k5z",
- "updated": "20261017200709"
+ "updated": "20261018120429"
},
"Children": [
{
"Type": "NodeText",
- "Data": "Choose the Block matches conditions trigger and select notebooks or documents in Watch scope (includes subdocuments). Notebook and document scopes are combined. Block types, tags, and custom attributes use separate Chip groups; add conditions with each group's add button, and remove them with the Chip's close button. The block type picker supports search and repeated selections. Click a tag or attribute Chip to edit it; Enter confirms tags, while attribute changes remain drafts until confirmed, and Escape or Cancel discards them. Tags are trimmed and deduplicated. Block types use OR. Tags and custom attributes each default to Match all; choose Match any separately when needed. The three groups still use AND, and an empty group adds no restriction. Custom attributes support equality, contains, exists, and does not exist; the last two do not need a value. Match any requires automation format 3, while existing rules keep their Match all behavior."
+ "Data": "Choose the Block matches conditions trigger, then use the add button under Watch scope (includes subdocuments) to select notebooks or documents. Click a document title to preview it in a floating window while keeping automation settings open; its icon also supports hover preview. Notebook and document scopes are combined. Block types, tags, and custom attributes use separate Chip groups; add conditions with each group's add button, and remove them with the Chip's close button. The block type picker supports search and repeated selections. Click a tag or attribute Chip to edit it; Enter confirms tags, while attribute changes remain drafts until confirmed, and Escape or Cancel discards them. Tags are trimmed and deduplicated. Block types use OR. Tags and custom attributes each default to Match all; choose Match any separately when needed. The three groups still use AND, and an empty group adds no restriction. Custom attributes support equality, contains, exists, and does not exist; the last two do not need a value. Match any requires automation format 3, while existing rules keep their Match all behavior."
}
]
},
diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20240208113259-nykkvaq.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20240208113259-nykkvaq.sy
index 135751b256..ad9efc7e6d 100644
--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20240208113259-nykkvaq.sy
+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180321-hbvl5c2/20240208113259-nykkvaq.sy
@@ -7,7 +7,7 @@
"id": "20240208113259-nykkvaq",
"title": "数据库",
"type": "doc",
- "updated": "20261018000619"
+ "updated": "20261018120429"
},
"Children": [
{
@@ -4540,12 +4540,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261015141042-ux38r6d",
- "updated": "20261017200709"
+ "updated": "20261018120429"
},
"Children": [
{
"Type": "NodeText",
- "Data": "选择「普通块符合条件」触发器,在「监听范围(包含子文档)」中选择笔记本或文档,范围取并集。块类型、标签和自定义属性分别使用 Chip 分组,通过各组的添加按钮配置,点击 Chip 的关闭图标移除。块类型列表支持搜索和连续多选;点击标签或属性 Chip 可编辑,标签按回车确认,属性先作为草稿编辑,确认后才保存,按 Esc 或取消不影响现有条件。标签会去除首尾空格并自动去重。块类型取任一匹配;标签和属性分别默认为「全部满足」,可独立改为「任一满足」。三个分组之间仍须全部满足,空分组不限制。属性支持等于、包含、存在和不存在,后两者不需要属性值。「任一满足」需要自动化格式 3,已有规则保留全部满足的行为。"
+ "Data": "选择「普通块符合条件」触发器,通过「监听范围(包含子文档)」下的添加按钮选择笔记本或文档,范围取并集。点击文档标题可在浮窗中预览,保留自动化设置;也可将鼠标悬停在图标上预览。块类型、标签和自定义属性分别使用 Chip 分组,通过各组的添加按钮配置,点击 Chip 的关闭图标移除。块类型列表支持搜索和连续多选;点击标签或属性 Chip 可编辑,标签按回车确认,属性先作为草稿编辑,确认后才保存,按 Esc 或取消不影响现有条件。标签会去除首尾空格并自动去重。块类型取任一匹配;标签和属性分别默认为「全部满足」,可独立改为「任一满足」。三个分组之间仍须全部满足,空分组不限制。属性支持等于、包含、存在和不存在,后两者不需要属性值。「任一满足」需要自动化格式 3,已有规则保留全部满足的行为。"
}
]
},
diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20240208171522-y7dxcno.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20240208171522-y7dxcno.sy
index a588372011..73aad63766 100644
--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20240208171522-y7dxcno.sy
+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226121203-rjjngpz/20240208171522-y7dxcno.sy
@@ -7,7 +7,7 @@
"id": "20240208171522-y7dxcno",
"title": "資料庫",
"type": "doc",
- "updated": "20261018000619"
+ "updated": "20261018120429"
},
"Children": [
{
@@ -4540,12 +4540,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261015141042-155k3zl",
- "updated": "20261017200709"
+ "updated": "20261018120429"
},
"Children": [
{
"Type": "NodeText",
- "Data": "選擇「普通區塊符合條件」觸發器,在「監聽範圍(包含子文件)」中選擇筆記本或文件,範圍取聯集。區塊類型、標籤和自訂屬性分別使用 Chip 分組,透過各組的新增按鈕設定,點擊 Chip 的關閉圖示移除。區塊類型列表支援搜尋和連續多選;點擊標籤或屬性 Chip 可編輯,標籤按 Enter 確認,屬性先作為草稿編輯,確認後才儲存,按 Esc 或取消不影響既有條件。標籤會去除首尾空白並自動去重。區塊類型取任一匹配;標籤和屬性分別預設為「全部滿足」,可獨立改為「任一滿足」。三個分組之間仍須全部滿足,空分組不限制。屬性支援等於、包含、存在和不存在,後兩者不需要屬性值。「任一滿足」需要自動化格式 3,既有規則保留全部滿足的行為。"
+ "Data": "選擇「普通區塊符合條件」觸發器,透過「監聽範圍(包含子文件)」下的新增按鈕選擇筆記本或文件,範圍取聯集。點擊文件標題可在浮動視窗中預覽,保留自動化設定;也可將滑鼠移到圖示上預覽。區塊類型、標籤和自訂屬性分別使用 Chip 分組,透過各組的新增按鈕設定,點擊 Chip 的關閉圖示移除。區塊類型列表支援搜尋和連續多選;點擊標籤或屬性 Chip 可編輯,標籤按 Enter 確認,屬性先作為草稿編輯,確認後才儲存,按 Esc 或取消不影響既有條件。標籤會去除首尾空白並自動去重。區塊類型取任一匹配;標籤和屬性分別預設為「全部滿足」,可獨立改為「任一滿足」。三個分組之間仍須全部滿足,空分組不限制。屬性支援等於、包含、存在和不存在,後兩者不需要屬性值。「任一滿足」需要自動化格式 3,既有規則保留全部滿足的行為。"
}
]
},
diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-3eaevtp.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-3eaevtp.sy
index b5c360306d..229f9c7337 100644
--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-3eaevtp.sy
+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-g3ugxml/20240530101000-3eaevtp.sy
@@ -8,7 +8,7 @@
"id": "20240530101000-3eaevtp",
"title": "データベース",
"type": "doc",
- "updated": "20261018000619"
+ "updated": "20261018120429"
},
"Children": [
{
@@ -4550,12 +4550,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20261015141042-qt2jps9",
- "updated": "20261017200709"
+ "updated": "20261018120429"
},
"Children": [
{
"Type": "NodeText",
- "Data": "「通常ブロックが条件に一致」トリガーを選び、「監視範囲(子文書を含む)」でノートブックや文書を指定します。範囲は和集合です。ブロック種類・タグ・カスタム属性はそれぞれ Chip で管理し、各組の追加ボタンで条件を加え、閉じるボタンで削除します。種類の一覧は検索と連続した複数選択に対応します。タグや属性の Chip を押すと編集でき、タグは Enter で確定します。属性は確定するまで下書きとして保持し、Esc またはキャンセルで既存条件を変えずに取り消せます。タグの前後の空白と重複は除去します。種類は OR、タグと属性はそれぞれ既定で「すべてに一致」で、「いずれかに一致」に個別に変更できます。三つの組の間は AND のままで、空の組は制限しません。属性は等しい・含む・存在する・存在しないを使え、後二者は値が不要です。「いずれかに一致」には自動化形式 3 が必要で、既存ルールの AND 動作は維持します。"
+ "Data": "「通常ブロックが条件に一致」トリガーを選び、「監視範囲(子文書を含む)」の下にある追加ボタンでノートブックや文書を指定します。文書名を押すと、自動化設定を開いたままフローティングウィンドウでプレビューできます。アイコンへのマウスオーバーでもプレビューできます。範囲は和集合です。ブロック種類・タグ・カスタム属性はそれぞれ Chip で管理し、各組の追加ボタンで条件を加え、閉じるボタンで削除します。種類の一覧は検索と連続した複数選択に対応します。タグや属性の Chip を押すと編集でき、タグは Enter で確定します。属性は確定するまで下書きとして保持し、Esc またはキャンセルで既存条件を変えずに取り消せます。タグの前後の空白と重複は除去します。種類は OR、タグと属性はそれぞれ既定で「すべてに一致」で、「いずれかに一致」に個別に変更できます。三つの組の間は AND のままで、空の組は制限しません。属性は等しい・含む・存在する・存在しないを使え、後二者は値が不要です。「いずれかに一致」には自動化形式 3 が必要で、既存ルールの AND 動作は維持します。"
}
]
},
diff --git a/app/src/assets/scss/business/_av.scss b/app/src/assets/scss/business/_av.scss
index aa3ab6cc36..c96e4c6306 100644
--- a/app/src/assets/scss/business/_av.scss
+++ b/app/src/assets/scss/business/_av.scss
@@ -3339,3 +3339,21 @@ img.av__cellassetimg {
max-height: 60vh;
overflow: auto;
}
+
+.av__automation-menu {
+ > .b3-text-field {
+ flex-shrink: 0;
+ margin: 0 8px 4px;
+ }
+}
+
+.av__automation-menu-list {
+ display: flex;
+ flex-direction: column;
+ min-height: 0;
+ overflow: auto;
+
+ > .b3-list-item {
+ flex-shrink: 0;
+ }
+}
diff --git a/app/src/protyle/render/av/automationRules.ts b/app/src/protyle/render/av/automationRules.ts
index 51dee5627d..2a6adbe985 100644
--- a/app/src/protyle/render/av/automationRules.ts
+++ b/app/src/protyle/render/av/automationRules.ts
@@ -17,9 +17,9 @@ export const openAutomationRules = (target: HTMLElement, rules: RuleSummary[], c
let menu: Menu;
toggleMenu({target, build: () => {
menu = new Menu();
- menu.addItem({type: "empty", label: `<div class="b3-menu__filter fn__flex-column">
+ menu.addItem({type: "empty", label: `<div class="b3-menu__filter av__automation-menu fn__flex-column">
<input class="b3-text-field" data-search placeholder="${escapeAttr(lang.searchPlaceholder)}" aria-label="${escapeAttr(lang.search)}">
-<div class="fn__hr"></div><div class="b3-list b3-list--background fn__flex-1" data-rules></div></div>`, bind: element => {
+<div class="b3-list b3-list--background av__automation-menu-list fn__flex-1" data-rules></div></div>`, bind: element => {
const search = element.querySelector<HTMLInputElement>("[data-search]");
const list = element.querySelector<HTMLElement>("[data-rules]");
const render = () => {
diff --git a/app/src/protyle/render/av/blockCollection.ts b/app/src/protyle/render/av/blockCollection.ts
index b2a3101b55..b70bc772c2 100644
--- a/app/src/protyle/render/av/blockCollection.ts
+++ b/app/src/protyle/render/av/blockCollection.ts
@@ -6,8 +6,8 @@ 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";
import {mountCollectionConditions} from "./collectionConditions";
+import {BlockPanel} from "../../../block/Panel";
export const collectionSourceIncomplete = (source: AVAutomationBlockSourceInput) => !source ||
!(source.notebookIDs?.length || source.documentIDs?.length) ||
@@ -34,17 +34,20 @@ export const mountBlockCollectionSource = (host: HTMLElement, source: AVAutomati
const documents = source.documentIDs || [];
host.innerHTML = `<div class="av__automation-action">
<div class="ft__on-surface ft__smaller av__automation-tip" data-collection-removal-tip>${lang.automationCollectionTip}</div>
-<button type="button" class="b3-button b3-button--outline b3-button--wrap av__automation-source-action" data-scope>${lang.automationCollectionScope}</button>
-${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 av__automation-notebook-name">${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 av__automation-document-name">${escapeHtml(names.get(id) || id)}</a>${removeButton("document", i)}</div>`).join("")}</div>` : ""}
+<div class="av__automation-control" data-scope-control><span class="av__automation-control-label">${lang.automationCollectionScope}</span>
+${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 av__automation-notebook-name">${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><button type="button" class="b3-button b3-button--cancel b3-button--wrap fn__flex-1 av__automation-source-action av__automation-document-name" data-preview-document="${escapeAttr(id)}">${escapeHtml(names.get(id) || id)}</button>${removeButton("document", i)}</div>`).join("")}</div>` : ""}
+<button type="button" class="b3-button b3-button--cancel b3-button--wrap av__automation-source-action" data-scope><svg><use xlink:href="#iconAdd"></use></svg><span>${escapeHtml(`${lang.addAttr} - ${lang.automationCollectionScope}`)}</span></button></div>
</div>`;
host.firstElementChild.append(conditions);
onResize();
};
host.addEventListener("click", event => {
- const link = (event.target as Element).closest<HTMLAnchorElement>("a[href]");
- if (link) {
+ const preview = (event.target as Element).closest<HTMLElement>("[data-preview-document]");
+ if (preview) {
event.preventDefault();
- openLink(protyle.app, link.getAttribute("href"), event, event.ctrlKey || event.metaKey);
+ event.stopPropagation();
+ window.siyuan.blockPanels.push(new BlockPanel({app: protyle.app, targetElement: preview,
+ isBacklink: false, refDefs: [{refID: preview.dataset.previewDocument}]}));
return;
}
const target = (event.target as Element).closest<HTMLElement>("button, [data-remove]");
diff --git a/app/src/protyle/render/av/collectionConditions.ts b/app/src/protyle/render/av/collectionConditions.ts
index 6da3d1f497..8770fc6182 100644
--- a/app/src/protyle/render/av/collectionConditions.ts
+++ b/app/src/protyle/render/av/collectionConditions.ts
@@ -93,7 +93,7 @@ export const mountCollectionConditions = (host: HTMLElement, source: AVAutomatio
let menu: Menu;
toggleMenu({target, build: () => {
menu = new Menu();
- menu.addItem({type: "empty", label: `<div class="b3-menu__filter fn__flex-column"><input class="b3-text-field" data-type-search placeholder="${escapeAttr(lang.searchPlaceholder)}" aria-label="${escapeAttr(lang.search)}"><div class="fn__hr"></div><div class="b3-list b3-list--background fn__flex-1" data-type-list>${Object.entries(types).map(([type, label]) => `<button type="button" class="b3-list-item" data-collection-type="${escapeAttr(type)}"><span class="b3-list-item__text">${escapeHtml(label)}</span><svg class="b3-menu__checked"><use xlink:href="#iconSelect"></use></svg></button>`).join("")}</div>${addButton("data-custom-callout", `${lang.callout} - ${lang.custom}`)}</div>`, bind: element => {
+ menu.addItem({type: "empty", label: `<div class="b3-menu__filter av__automation-menu fn__flex-column"><input class="b3-text-field" data-type-search placeholder="${escapeAttr(lang.searchPlaceholder)}" aria-label="${escapeAttr(lang.search)}"><div class="b3-list b3-list--background av__automation-menu-list fn__flex-1" data-type-list>${Object.entries(types).map(([type, label]) => `<button type="button" class="b3-list-item" data-collection-type="${escapeAttr(type)}"><span class="b3-list-item__text">${escapeHtml(label)}</span><svg class="b3-menu__checked"><use xlink:href="#iconSelect"></use></svg></button>`).join("")}<button type="button" class="b3-list-item" data-custom-callout><svg class="b3-list-item__graphic"><use xlink:href="#iconAdd"></use></svg><span class="b3-list-item__text">${escapeHtml(`${lang.callout} - ${lang.custom}`)}</span></button></div></div>`, bind: element => {
const search = element.querySelector<HTMLInputElement>("[data-type-search]");
const list = element.querySelector<HTMLElement>("[data-type-list]");
const refresh = () => {
diff --git a/app/tests/automationPanel.test.js b/app/tests/automationPanel.test.js
index f0350285d5..2360998984 100644
--- a/app/tests/automationPanel.test.js
+++ b/app/tests/automationPanel.test.js
@@ -36,11 +36,13 @@ const runCases = async (sources, css, mobile) => {
const transactions = [];
const templatePreviews = [];
const searches = [];
+ const scopePreviews = [];
+ const scopeRequests = [];
let fieldMenu;
let collectionTypeInput;
let nextID = 0;
window.Lute = {NewNodeID: () => `generated-${++nextID}`};
- window.siyuan = {languages: lang, config: {}, notebooks: [], zIndex: 0, dialogs: [], storage: {},
+ window.siyuan = {languages: lang, config: {}, notebooks: [], zIndex: 0, dialogs: [], storage: {}, blockPanels: [],
menus: {menu: {element: document.createElement("div"), remove() {}}}};
const mocks = {
"menus/menuToggle": {toggleMenu: options => {options.build(); options.show();}},
@@ -71,6 +73,8 @@ const runCases = async (sources, css, mobile) => {
"dialog/anchoredInput": {getAnchoredInputMask() {}},
"block/panelOwnership": {getDialogBlockPanel() {}, destroyDialogBlockPanels() {}},
"dialog/inputDialog": {openInputDialog: options => { collectionTypeInput = options; }},
+ "block/Panel": {BlockPanel: class {constructor(options) {scopePreviews.push(options);}}},
+ "util/pathName": {movePathTo: options => scopeRequests.push(options)},
"util/fetch": {fetchSyncPost: async (url, request) => url.includes("previewAttributeViewTemplate") ?
(templatePreviews.push(request), {code: 0, data: {type: "date", date: {content: 1792713600000, isNotEmpty: true, isNotTime: true}}}) : url.includes("getHPathByID") ? {code: 0, data: "/Tasks"} :
url.includes("reviewAttributeViewCollection") ? {code: 0, data: {ruleVersion: "snapshot", matched: 7, unmatched: 7, unknown: 6, hasMore: false,
@@ -122,6 +126,14 @@ const runCases = async (sources, css, mobile) => {
};
const click = async selector => {get(selector).dispatchEvent(new MouseEvent("click", {bubbles: true})); await tick();};
const latest = () => transactions.at(-1).perform[0].data.rules[0];
+ const assertSearchAlignment = (popup, inputSelector, listSelector) => {
+ const input = popup.querySelector(inputSelector).getBoundingClientRect();
+ const list = popup.querySelector(listSelector);
+ const row = list.querySelector(".b3-list-item:not(.fn__none)").getBoundingClientRect();
+ assert.ok(Math.abs(input.left - row.left) <= 1, "search and list entries share their left edge");
+ assert.ok(Math.abs(input.right - row.right - (list.offsetWidth - list.clientWidth)) <= 1,
+ `search and entries share their right inset: ${input.right}/${row.right}`);
+ };
const assertChipActionSpacing = (listSelector, buttonSelector) => {
const chips = Array.from(get(listSelector).querySelectorAll(".b3-chip"));
assert.ok(chips.length > 0, "spacing checks require visible chips");
@@ -160,6 +172,7 @@ const runCases = async (sources, css, mobile) => {
}
await click('[data-action="rules"]');
const rulePopup = fieldMenu.element;
+ assertSearchAlignment(rulePopup, "[data-search]", "[data-rules]");
rulePopup.querySelector("[data-rename]").click();
const renameInput = rulePopup.querySelector("[data-rules] input");
renameInput.value = "Cancelled";
@@ -460,6 +473,35 @@ const runCases = async (sources, css, mobile) => {
assert.equal(get("[data-source-conditions]").closest("section").textContent.includes(lang.automationBlockConditions), true);
assert.equal(menu.querySelector("[data-add-condition]"), null);
assert.ok(get("[data-scope]"));
+ assert.equal(get("[data-scope-control] > .av__automation-control-label").textContent, lang.automationCollectionScope);
+ assert.equal(get("[data-scope-control] > .av__automation-control-label").closest("button"), null);
+ assert.ok(get("[data-scope]").textContent.includes(lang.addAttr), "scope has its own add button like the other groups");
+ assert.ok(get("[data-scope]").compareDocumentPosition(get(".av__automation-source-list")) & Node.DOCUMENT_POSITION_PRECEDING,
+ "the add scope action follows existing entries");
+ const writesBeforeScopePreview = transactions.length;
+ const sourceButton = get("[data-preview-document]");
+ assert.equal(sourceButton.tagName, "BUTTON");
+ await click("[data-preview-document]");
+ sourceButton.focus();
+ assert.equal(document.activeElement, sourceButton, "scope document titles are keyboard focusable");
+ await require("electron").ipcRenderer.invoke("automation-enter");
+ await tick();
+ assert.equal(scopePreviews.length, 2, "scope documents support pointer and native keyboard button activation");
+ assert.equal(scopePreviews[0].targetElement, sourceButton);
+ assert.deepEqual(scopePreviews[0].refDefs, [{refID: "document"}]);
+ assert.equal(scopePreviews[0].isBacklink, false);
+ assert.equal(menu.isConnected, true, "preview preserves the automation panel");
+ assert.ok(menu.querySelector("[data-trigger]"));
+ assert.equal(transactions.length, writesBeforeScopePreview, "preview does not change collection configuration");
+ assert.equal(get(".popover__block").dataset.id, "document", "the document icon keeps its hover preview");
+ await click("[data-scope]");
+ scopeRequests[0].cb(["/", "/new-document.sy", "/new-document.sy"], ["notebook", "notebook", "notebook"]);
+ await tick();
+ assert.deepEqual(latest().blockSource.notebookIDs, ["notebook"]);
+ assert.deepEqual(latest().blockSource.documentIDs, ["document", "new-document"], "scope additions retain existing entries and deduplicate");
+ await click('[data-remove="document"][data-index="1"]');
+ await click('[data-remove="notebook"]');
+ assert.deepEqual(latest().blockSource.documentIDs, ["document"]);
assert.equal(get('[data-action="preview-collection"]').disabled, true);
assert.equal(get("[data-status]").textContent, lang.automationReady);
get("[data-enabled]").click();
@@ -500,6 +542,34 @@ const runCases = async (sources, css, mobile) => {
}
await click("[data-types] svg");
const typePopup = fieldMenu.element;
+ const typeList = typePopup.querySelector("[data-type-list]");
+ const customCallout = typePopup.querySelector("[data-custom-callout]");
+ assert.equal(typeList.lastElementChild, customCallout, "custom callout is the final scrollable list entry");
+ for (const width of mobile ? [360, 740] : [420, 1000]) {
+ await require("electron").ipcRenderer.invoke("automation-size", width, 900);
+ for (const name of ["daylight", "midnight"]) {
+ theme.textContent = sources[name];
+ for (const size of [16, 24]) {
+ typePopup.style.fontSize = `${size}px`;
+ typeList.scrollTop = 0;
+ await tick();
+ assertSearchAlignment(typePopup, "[data-type-search]", "[data-type-list]");
+ const first = typeList.firstElementChild.getBoundingClientRect();
+ for (const item of typeList.children) {
+ assert.ok(Math.abs(item.getBoundingClientRect().width - first.width) <= 1, "all type rows stretch to the same full width");
+ }
+ assert.ok(typeList.scrollHeight > typeList.clientHeight, "long type lists scroll inside the popup");
+ assert.ok(customCallout.getBoundingClientRect().top > typeList.getBoundingClientRect().bottom,
+ "custom callout is not pinned below the search list");
+ typeList.scrollTop = typeList.scrollHeight;
+ assert.ok(customCallout.getBoundingClientRect().bottom <= typeList.getBoundingClientRect().bottom + 1,
+ "the final custom action is reachable by scrolling");
+ }
+ typeList.scrollTop = 0;
+ await require("electron").ipcRenderer.invoke("automation-capture", `${mobile ? "mobile" : "desktop"}-${width}-${name}-types`);
+ }
+ }
+ typePopup.style.fontSize = "";
typePopup.querySelector('[data-collection-type="l"]').click();
assert.deepEqual(latest().blockSource.types, ["l"]);
assertChipActionSpacing("[data-type-chips]", "[data-types]");
@@ -672,10 +742,16 @@ 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-enter", () => {
+ win.webContents.focus();
+ win.webContents.sendInputEvent({type: "keyDown", keyCode: "ENTER"});
+ win.webContents.sendInputEvent({type: "char", keyCode: "\r"});
+ win.webContents.sendInputEvent({type: "keyUp", keyCode: "ENTER"});
+ });
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|-collection|-review|-review-confirm)?$/);
+ assert.match(name, /^(desktop|mobile)-\d+-(daylight|midnight)(-actions|-conditions|-collection|-review|-review-confirm|-types)?$/);
win.webContents.invalidate();
await new Promise(resolve => setTimeout(resolve, 150));
fs.writeFileSync(path.join(process.env.SIYUAN_AUTOMATION_CAPTURE_DIR, name + ".png"), (await win.webContents.capturePage()).toPNG());