An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Isolate conditional color option selections https://github.com/siyuan-note/siyuan/issues/19894
Danieldefbebdc5a1d
diff --git a/app/src/protyle/render/av/filter.ts b/app/src/protyle/render/av/filter.tsindex 912ae7eea5..0703888399 100644--- a/app/src/protyle/render/av/filter.ts+++ b/app/src/protyle/render/av/filter.ts@@ -798,7 +798,7 @@ ${genRelationFilterTriggerContent(avID, selectedBlockIDs, path)}<svg class="av__// readInlineValue 从叶子行内 DOM 读取值,按类型返回 { value, relativeDate, relativeDate2 }。// 修正点①:date 用 data-type 精确定位,废弃全局 textElements 索引。-const readInlineValue = (rowElement: HTMLElement, valueType: TAVCol, operator: string, filter: IAVFilter): { newValue: IAVCellValue, relativeDate: IAVRelativeDate, relativeDate2: IAVRelativeDate } => {+const readInlineValue = (rowElement: HTMLElement, valueType: TAVCol, operator: string, filter: IAVFilter, menuElement: HTMLElement): { newValue: IAVCellValue, relativeDate: IAVRelativeDate, relativeDate2: IAVRelativeDate } => {let newValue: IAVCellValue = filter.value;let relativeDate: IAVRelativeDate = filter.relativeDate;let relativeDate2: IAVRelativeDate = filter.relativeDate2;@@ -869,10 +869,10 @@ const readInlineValue = (rowElement: HTMLElement, valueType: TAVCol, operator: srelativeDate2 = undefined;}} else if (valueType === "select" || valueType === "mSelect") {- // 扫描下拉面板内选中的 chip(#iconCheck)。下拉在行外(fixed 定位),用 path 全局查找+ // 下拉位于行外,按路径在当前筛选编辑器内读取选中的选项。const path = rowElement.dataset.path;const mSelect: IAVCellSelectValue[] = [];- const dropdown = document.querySelector(`[data-type="selectDropdown"][data-path="${path}"]`);+ const dropdown = menuElement.querySelector(`[data-type="selectDropdown"][data-path="${path}"]`);const searchRoot = dropdown || rowElement; // 兜底:兼容旧结构searchRoot.querySelectorAll('[data-type="selectOption"]').forEach((option: HTMLElement) => {const useEl = option.querySelector(".av__select-option-check use");@@ -972,7 +972,7 @@ export const bindInlineFilterEvents = (panelElement: HTMLElement, data: IAV, proconst {type: valueType} = resolveFilterValueType(filter, colData);const operatorSel = rowElement.querySelector('[data-type="operation"]') as HTMLSelectElement;const operator = (operatorSel?.value || filter.operator) as TAVFilterOperator;- const {newValue, relativeDate, relativeDate2} = readInlineValue(rowElement, valueType, operator, filter);+ const {newValue, relativeDate, relativeDate2} = readInlineValue(rowElement, valueType, operator, filter, menuElement);const quantifierSel = rowElement.querySelector('[data-type="quantifier"]') as HTMLSelectElement;const newFilter: IAVFilter = {column: filter.column,diff --git a/app/src/protyle/render/av/filterEditor.test.ts b/app/src/protyle/render/av/filterEditor.test.tsindex 4b5e2862c6..779e20160d 100644--- a/app/src/protyle/render/av/filterEditor.test.ts+++ b/app/src/protyle/render/av/filterEditor.test.ts@@ -4,6 +4,43 @@ import {test} from "node:test";import {runInNewContext} from "node:vm";import {ModuleKind, ScriptTarget, transpileModule} from "typescript";+test("selection conditions with the same path read only their own editor options", () => {+ const methods = {} as typeof import("./filter");+ runInNewContext(transpileModule(readFileSync("src/protyle/render/av/filter.ts", "utf8"), {+ compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2022},+ }).outputText, {+ exports: methods,+ document: {querySelector: () => assert.fail("must not read another condition's options")},+ require: (name: string) => ({+ "./view": {getFieldsByData: () => [{id: "choice", type: "mSelect"}]},+ "./cell": {genCellValue: (type: string, mSelect: IAVCellSelectValue[]) => ({type, mSelect})},+ })[name] || {},+ });+ for (const selected of [[], ["own option"]]) {+ const listeners = new Map<string, (event: unknown) => void>();+ const row = {dataset: {path: "0"}, querySelector: (selector: string) =>+ selector === '[data-type="operation"]' ? {value: "Contains"} : null};+ const dropdown = {querySelectorAll: () => selected.map(name => ({+ dataset: {name, color: "1"},+ querySelector: () => ({getAttribute: () => "#iconCheck"}),+ }))};+ const panel = {+ dataset: {}, innerHTML: "",+ querySelector: (selector: string) => selector.includes("selectDropdown") ? dropdown : row,+ addEventListener: (type: string, listener: (event: unknown) => void) => listeners.set(type, listener),+ };+ const data = {view: {filters: [{column: "choice", operator: "Is not empty", value: {type: "mSelect"}}]}} as IAV;+ methods.bindInlineFilterEvents(panel as unknown as HTMLElement, data, {} as IProtyle, "block", "database", {+ root: panel as unknown as HTMLElement, save() {}, render: () => "updated",+ });+ listeners.get("change")({target: {+ dataset: {type: "operation", path: "0"}, value: "Contains", closest: () => panel,+ }});+ assert.equal(data.view.filters[0].operator, "Contains");+ assert.deepEqual(Array.from(data.view.filters[0].value.mSelect || [], item => item.content), selected);+ }+});+test("nested color conditions do not change the parent view filter, including capture events", () => {const methods = {} as typeof import("./filter");const fields = [{id: "text", type: "text"}];