Skip to content

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

:art: Support database filter composition https://github.com/siyuan-note/siyuan/issues/10550

Daniel7d952d6d1572
diff --git a/app/src/assets/scss/business/_av.scss b/app/src/assets/scss/business/_av.scss
index f785ad494c..7d516bc277 100644
--- a/app/src/assets/scss/business/_av.scss
+++ b/app/src/assets/scss/business/_av.scss
@@ -998,6 +998,20 @@
}
}
+ // 分组行尾“更多”按钮与底部下拉箭头统一尺寸
+ .av__filter-group-item > .b3-menu__action {
+ flex-shrink: 0;
+ align-self: center;
+ }
+
+ .av__filter-arrow {
+ width: 10px;
+ height: 10px;
+ flex-shrink: 0;
+ align-self: center;
+ margin-left: 4px;
+ }
+
&__item[data-type="nobg"] {
cursor: auto;
}
@@ -1042,6 +1056,14 @@
}
}
+ .av__filter-field {
+ max-width: 120px;
+ }
+
+ .av__filter-num {
+ width: 50px;
+ }
+
.av__field-wrapper {
display: flex;
align-items: center;
@@ -1067,6 +1089,12 @@
}
}
+ .av__field-wrapper .b3-menu__icon {
+ margin-right: 0;
+ width: 16px;
+ height: 16px;
+ }
+
.b3-menu__item.av__filter-row:hover {
background-color: transparent;
}
@@ -1138,6 +1166,30 @@
overflow: hidden;
}
+ // 触发器内已选 chip
+ .av__select-chip {
+ margin: 1px 2px;
+ }
+
+ // 下拉面板内的选项 chip
+ .av__select-option {
+ margin: 2px 0;
+ cursor: pointer;
+ width: 100%;
+ box-sizing: border-box;
+ overflow: hidden;
+
+ svg {
+ width: 12px;
+ height: 12px;
+ flex-shrink: 0;
+ }
+
+ .fn__ellipsis {
+ min-width: 0;
+ }
+ }
+
// 下拉内搜索框,复用 input 的外观但占满宽度
.av__select-dropdown .b3-text-field {
margin: 0 0 4px 0;
diff --git a/app/src/protyle/render/av/filter.ts b/app/src/protyle/render/av/filter.ts
index 1d51bb4044..cd204d9234 100644
--- a/app/src/protyle/render/av/filter.ts
+++ b/app/src/protyle/render/av/filter.ts
@@ -260,7 +260,7 @@ export const getFiltersHTML = (data: IAV) => {
${childrenHTML}
<div class="av__filter-group-actions">${addConditionBtn}</div>
</div>
- <svg class="b3-menu__action ariaLabel" data-position="4west" data-type="moreFilter" data-path="${path}" aria-label="${window.siyuan.languages.more}" style="flex-shrink:0;align-self:center;"><use xlink:href="#iconMore"></use></svg>
+ <svg class="b3-menu__action ariaLabel" data-position="4west" data-type="moreFilter" data-path="${path}" aria-label="${window.siyuan.languages.more}"><use xlink:href="#iconMore"></use></svg>
</div>`;
}
@@ -275,12 +275,12 @@ export const getFiltersHTML = (data: IAV) => {
return "";
}
const iconHTML = colData.icon
- ? unicode2Emoji(colData.icon, "b3-menu__icon", true).replace(/<(img|span)/, '<$1 style="height:16px;width:16px;margin-right:0;"')
- : `<svg class="b3-menu__icon" style="margin-right:0;"><use xlink:href="#${getColIconByType(colData.type)}"></use></svg>`;
+ ? unicode2Emoji(colData.icon, "b3-menu__icon", true)
+ : `<svg class="b3-menu__icon"><use xlink:href="#${getColIconByType(colData.type)}"></use></svg>`;
const fieldOptions = fields.filter((f: IAVColumn) => f.type !== "lineNumber").map((f: IAVColumn) =>
`<option value="${f.id}" ${f.id === node.column ? "selected" : ""}>${escapeHtml(f.name)}</option>`
).join("");
- const fieldSelect = `<select class="b3-select fn__flex-1" data-type="fieldSelect" data-path="${path}" style="max-width:120px;">${fieldOptions}</select>`;
+ const fieldSelect = `<select class="b3-select fn__flex-1 av__filter-field" data-type="fieldSelect" data-path="${path}">${fieldOptions}</select>`;
const fieldWrapper = `<span class="av__field-wrapper ariaLabel" data-position="4west" aria-label="${escapeAttr(colData.name)}">${iconHTML}${fieldSelect}</span>`;
const inlineHTML = genInlineFilterHTML(node, colData, path);
const leafAndOrHTML = 0 === index ? genWhenLabel() : 1 === index ? genAndOrSelect(groupPath, groupCombination) : genAndOrLabel(groupCombination);
@@ -308,8 +308,8 @@ export const getFiltersHTML = (data: IAV) => {
${html}
<button class="b3-menu__item" data-type="addFilterCondition" data-path="" data-depth="0">
<svg class="b3-menu__icon"><use xlink:href="#iconAdd"></use></svg>
- <span class="b3-menu__label" style="flex:none;">${window.siyuan.languages.addFilterCondition}</span>
- <svg style="width:10px;height:10px;flex-shrink:0;align-self:center;margin-left:4px;"><use xlink:href="#iconDown"></use></svg>
+ <span class="b3-menu__label fn__flex-shrink">${window.siyuan.languages.addFilterCondition}</span>
+ <svg class="av__filter-arrow"><use xlink:href="#iconDown"></use></svg>
</button>
<button class="b3-menu__item b3-menu__item--warning${leafCount > 0 ? "" : " fn__none"}" data-type="removeFilters">
<svg class="b3-menu__icon"><use xlink:href="#iconTrashcan"></use></svg>
@@ -471,7 +471,7 @@ const genInlineFilterHTML = (filter: IAVFilter, colData: IAVColumn, path: string
valueHTML = `<input class="b3-text-field b3-text-field--text fn__flex-1" value="${escapeHtml(content)}" data-type="filterValue" data-path="${path}">`;
} else if (valueType === "number") {
const content = filterValue?.number?.isNotEmpty ? filterValue.number.content : "";
- valueHTML = `<input class="b3-text-field b3-text-field--text" style="width:50px;" value="${content}" data-type="filterValue" data-path="${path}">`;
+ valueHTML = `<input class="b3-text-field b3-text-field--text av__filter-num" value="${content}" data-type="filterValue" data-path="${path}">`;
} else if (valueType === "checkbox") {
const isChecked = filterValue?.checkbox?.checked;
valueHTML = `<select class="b3-select" data-type="filterValue" data-path="${path}"><option value="true" ${isChecked ? "selected" : ""}>${window.siyuan.languages.checked}</option><option value="false" ${!isChecked ? "selected" : ""}>${window.siyuan.languages.unchecked}</option></select>`;
@@ -507,7 +507,7 @@ const genInlineDateHTML = (filter: IAVFilter, valueType: TAVCol, path: string):
<option value="1"${relativeDate?.direction === 1 ? " selected" : ""}>${window.siyuan.languages.nextDate}</option>
<option value="0"${showToday ? " selected" : ""}>${window.siyuan.languages.current}</option>
</select>`;
- const relCount = `<input type="number" min="1" step="1" value="${relativeDate?.count || 1}" class="b3-text-field b3-text-field--text" data-type="relCount${suffix}" data-path="${path}" style="width:50px;${(!relativeDate || showToday) ? "display:none;" : ""}">`;
+ const relCount = `<input type="number" min="1" step="1" value="${relativeDate?.count || 1}" class="b3-text-field b3-text-field--text av__filter-num" data-type="relCount${suffix}" data-path="${path}" style="${(!relativeDate || showToday) ? "display:none;" : ""}">`;
const relUnit = `<select class="b3-select" data-type="relUnit${suffix}" data-path="${path}" style="${(!relativeDate || showToday) ? "display:none;" : ""}">
<option value="0"${relativeDate?.unit === 0 ? " selected" : ""}>${window.siyuan.languages.day}</option>
<option value="1"${(!relativeDate || relativeDate?.unit === 1) ? " selected" : ""}>${window.siyuan.languages.week}</option>
@@ -531,7 +531,7 @@ const genInlineSelectHTML = (filter: IAVFilter, colData: IAVColumn, path: string
// 触发器:显示已选值的 chip(与表格单元格样式一致),无选中时显示 placeholder + 下拉箭头
const selectedChips = selectedValues.map((item: IAVCellSelectValue) => {
- return `<span class="b3-chip b3-chip--middle" style="margin:1px 2px;background-color:var(--b3-font-background${item.color});color:var(--b3-font-color${item.color})">${escapeHtml(item.content)}</span>`;
+ return `<span class="b3-chip b3-chip--middle av__select-chip" style="background-color:var(--b3-font-background${item.color});color:var(--b3-font-color${item.color})">${escapeHtml(item.content)}</span>`;
}).join("");
const triggerContent = selectedChips || `<span class="ft__on-surface fn__ellipsis">${placeholder}</span>`;
const trigger = `<span class="av__select-trigger" data-type="selectTrigger" data-path="${path}">${triggerContent}<svg class="av__select-trigger-arrow"><use xlink:href="#iconDown"></use></svg></span>`;
@@ -542,9 +542,9 @@ const genInlineSelectHTML = (filter: IAVFilter, colData: IAVColumn, path: string
: "";
const chips = options.map((option: { name: string; color: string; desc?: string }) => {
const selected = selectedValues.some((s: IAVCellSelectValue) => s.content === option.name);
- return `<span class="b3-chip b3-chip--middle${selected ? " b3-chip--primary" : ""}" data-name="${escapeAttr(option.name)}" data-color="${option.color}" data-type="selectOption" data-path="${path}" style="margin:2px 0;cursor:pointer;width:100%;box-sizing:border-box;overflow:hidden;background-color:var(--b3-font-background${option.color});color:var(--b3-font-color${option.color})">
-<svg class="icon" style="height:12px;width:12px;flex-shrink:0;"><use xlink:href="#${selected ? "iconCheck" : "iconUncheck"}"></use></svg>
-<span class="fn__ellipsis" style="min-width:0;">${escapeHtml(option.name)}</span>
+ return `<span class="b3-chip b3-chip--middle${selected ? " b3-chip--primary" : ""} av__select-option" data-name="${escapeAttr(option.name)}" data-color="${option.color}" data-type="selectOption" data-path="${path}" style="background-color:var(--b3-font-background${option.color});color:var(--b3-font-color${option.color})">
+<svg class="icon"><use xlink:href="#${selected ? "iconCheck" : "iconUncheck"}"></use></svg>
+<span class="fn__ellipsis">${escapeHtml(option.name)}</span>
</span>`;
}).join("");
const dropdown = `<div class="av__select-dropdown" data-type="selectDropdown" data-path="${path}" data-single="${isSingle ? "true" : "false"}" style="display:none;">
@@ -880,7 +880,7 @@ export const bindInlineFilterEvents = (panelElement: HTMLElement, data: IAV, pro
if (u && u.getAttribute("xlink:href") === "#iconCheck") {
const name = c.dataset.name;
const color = c.dataset.color;
- selectedChips.push(`<span class="b3-chip b3-chip--middle" style="margin:1px 2px;background-color:var(--b3-font-background${color});color:var(--b3-font-color${color})">${escapeHtml(name)}</span>`);
+ selectedChips.push(`<span class="b3-chip b3-chip--middle av__select-chip" style="background-color:var(--b3-font-background${color});color:var(--b3-font-color${color})">${escapeHtml(name)}</span>`);
}
});
const contentHTML = selectedChips.join("") || `<span class="ft__on-surface fn__ellipsis">${placeholderStr}</span>`;