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

Daniel7174bdea7186
diff --git a/app/src/assets/scss/business/_av.scss b/app/src/assets/scss/business/_av.scss
index d1d719534f..3e34d58d44 100644
--- a/app/src/assets/scss/business/_av.scss
+++ b/app/src/assets/scss/business/_av.scss
@@ -929,20 +929,6 @@
}
}
- .av__filter-andor {
- margin: 0;
- flex-shrink: 0;
- box-sizing: border-box;
- height: 28px;
- line-height: 20px;
- font-size: 14px;
- padding: 0 20px 0 6px;
- display: inline-flex;
- align-items: center;
- color: var(--b3-theme-on-background);
- border: 1px solid transparent;
- }
-
.av__filter-group-left {
flex-shrink: 0;
display: flex;
@@ -1029,11 +1015,11 @@
margin-bottom: 0;
}
+ // 筛选面板内的下拉/输入控件统一为菜单底色(与面板背景融合)
.av__filter-row .b3-select,
- .av__filter-row .b3-text-field--text {
- border: 1px solid var(--b3-theme-surface-lighter);
- border-radius: var(--b3-border-radius);
- background-color: var(--b3-menu-background) !important;
+ .av__filter-row .b3-text-field--text,
+ .av__filter-group-left .b3-select {
+ background-color: var(--b3-menu-background);
}
.av__field-wrapper {
@@ -1041,24 +1027,23 @@
align-items: center;
flex-shrink: 0;
height: 28px;
- background: transparent;
border: 1px solid var(--b3-theme-surface-lighter);
border-radius: var(--b3-border-radius);
padding: 0 4px 0 6px;
gap: 2px;
box-sizing: border-box;
- background-color: var(--b3-menu-background) !important;
+ background-color: var(--b3-menu-background);
}
+ // 字段选择器嵌入描边容器内,去掉自身细线避免双重描边
.av__field-wrapper .b3-select {
- border: 0;
- background-color: transparent !important;
- }
+ box-shadow: none;
+ background-color: transparent;
- .av__filter-group-left .b3-select {
- background-color: var(--b3-menu-background) !important;
- border: 1px solid var(--b3-theme-surface-lighter);
- border-radius: var(--b3-border-radius);
+ &:hover,
+ &:focus {
+ box-shadow: none;
+ }
}
.b3-menu__item.av__filter-row:hover {
@@ -1075,29 +1060,6 @@
color: var(--b3-theme-on-surface) !important;
}
- .av__filter-select {
- margin: 0;
- flex-shrink: 0;
- min-width: 60px;
- height: 28px;
- line-height: 20px;
- font-size: 14px;
- box-shadow: none;
- padding-left: 6px;
- background: transparent url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="%23888" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>') no-repeat right 6px center;
- padding-right: 20px;
- }
-
- .av__filter-input {
- margin: 0;
- box-shadow: none;
- background: transparent;
- flex: 1;
- min-width: 60px;
- height: 28px;
- font-size: 14px;
- }
-
.av__filter-value {
display: inline-flex;
align-items: center;
@@ -1118,15 +1080,6 @@
flex-wrap: wrap;
}
- .av__filter-date-input {
- margin: 0;
- box-shadow: none;
- background: transparent;
- height: 28px;
- line-height: 20px;
- font-size: 14px;
- }
-
.av__filter-date-col {
display: inline-flex;
flex-direction: column;
diff --git a/app/src/protyle/render/av/filter.ts b/app/src/protyle/render/av/filter.ts
index 0aef7cd85c..c840719642 100644
--- a/app/src/protyle/render/av/filter.ts
+++ b/app/src/protyle/render/av/filter.ts
@@ -220,13 +220,13 @@ export const getFiltersHTML = (data: IAV) => {
document.body.removeChild(measureEl);
const andOrControlWidth = andOrTextWidth + 28;
const genAndOrSelect = (groupPath: string, combination: string) =>
- `<select class="b3-select av__filter-select" data-type="toggleCombination" data-path="${groupPath}" style="min-width:0;width:${andOrControlWidth}px;"><option value="and" ${combination === "and" ? "selected" : ""}>${window.siyuan.languages.filterCombinationAnd}</option><option value="or" ${combination === "or" ? "selected" : ""}>${window.siyuan.languages.filterCombinationOr}</option></select>`;
+ `<select class="b3-select" data-type="toggleCombination" data-path="${groupPath}" style="width:${andOrControlWidth}px;"><option value="and" ${combination === "and" ? "selected" : ""}>${window.siyuan.languages.filterCombinationAnd}</option><option value="or" ${combination === "or" ? "selected" : ""}>${window.siyuan.languages.filterCombinationOr}</option></select>`;
const genWhenLabel = () =>
- `<span class="av__filter-andor" style="width:${andOrControlWidth}px;">${window.siyuan.languages.filterWhen}</span>`;
+ `<span class="ft__on-surface" style="width:${andOrControlWidth}px;height:28px;line-height:28px;display:inline-block;">${window.siyuan.languages.filterWhen}</span>`;
const genAndOrLabel = (combination: string) =>
- `<span class="av__filter-andor" style="width:${andOrControlWidth}px;">${combination === "or" ? window.siyuan.languages.filterCombinationOr : window.siyuan.languages.filterCombinationAnd}</span>`;
+ `<span class="ft__on-surface" style="width:${andOrControlWidth}px;height:28px;line-height:28px;display:inline-block;">${combination === "or" ? window.siyuan.languages.filterCombinationOr : window.siyuan.languages.filterCombinationAnd}</span>`;
const genNodeHTML = (node: IAVFilter, path: string, depth: number, groupPath: string, groupCombination: string, index: number = 0): string => {
if (!node) {
@@ -279,7 +279,7 @@ export const getFiltersHTML = (data: IAV) => {
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 av__filter-select" data-type="fieldSelect" data-path="${path}" style="min-width:80px;max-width:120px;padding-left:0;">${fieldOptions}</select>`;
+ const fieldSelect = `<select class="b3-select fn__flex-1" data-type="fieldSelect" data-path="${path}" style="max-width:120px;">${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);
@@ -447,11 +447,11 @@ const genInlineFilterHTML = (filter: IAVFilter, colData: IAVColumn, path: string
const valueHidden = isEmptyOp ? " fn__none" : "";
// 操作符 select
- const operatorSelect = `<select class="b3-select av__filter-select" data-type="operation" data-path="${path}">${getOperatorSelectByType(valueType, operator)}</select>`;
+ const operatorSelect = `<select class="b3-select" data-type="operation" data-path="${path}">${getOperatorSelectByType(valueType, operator)}</select>`;
// 量化器 select(rollup/mAsset 才有)
const quantifierSelect = (isRollup || valueType === "mAsset")
- ? `<select class="b3-select av__filter-select" data-type="quantifier" data-path="${path}">
+ ? `<select class="b3-select" data-type="quantifier" data-path="${path}">
<option ${(!filter.quantifier || filter.quantifier === "Any") ? "selected" : ""} value="Any">${window.siyuan.languages.filterQuantifierAny}</option>
<option ${filter.quantifier === "All" ? "selected" : ""} value="All">${window.siyuan.languages.filterQuantifierAll}</option>
<option ${filter.quantifier === "None" ? "selected" : ""} value="None">${window.siyuan.languages.filterQuantifierNone}</option>
@@ -464,16 +464,16 @@ const genInlineFilterHTML = (filter: IAVFilter, colData: IAVColumn, path: string
const filterValue = filter.value;
if (["text", "url", "block", "email", "phone", "template"].includes(valueType)) {
const content = filterValue?.[valueType as "text"]?.content || "";
- valueHTML = `<input class="b3-text-field b3-text-field--text av__filter-input" value="${escapeHtml(content)}" data-type="filterValue" data-path="${path}">`;
+ 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 === "mAsset") {
const content = filterValue?.mAsset?.[0]?.content || "";
- valueHTML = `<input class="b3-text-field b3-text-field--text av__filter-input" value="${escapeHtml(content)}" data-type="filterValue" data-path="${path}">`;
+ 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 av__filter-input" style="min-width:50px;" value="${content}" data-type="filterValue" data-path="${path}">`;
+ valueHTML = `<input class="b3-text-field b3-text-field--text" style="width:50px;" value="${content}" data-type="filterValue" data-path="${path}">`;
} else if (valueType === "checkbox") {
const isChecked = filterValue?.checkbox?.checked;
- valueHTML = `<select class="b3-select av__filter-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>`;
+ 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>`;
} else if (["date", "created", "updated"].includes(valueType)) {
valueHTML = genInlineDateHTML(filter, valueType, path);
} else if (valueType === "select" || valueType === "mSelect") {
@@ -482,7 +482,7 @@ const genInlineFilterHTML = (filter: IAVFilter, colData: IAVColumn, path: string
extraHTML = dropdown; // 下拉面板放 valueContainer 外,fixed 定位不影响行宽
} else if (valueType === "relation") {
const content = filterValue?.relation?.blockIDs?.[0] || "";
- valueHTML = `<input class="b3-text-field b3-text-field--text av__filter-input" value="${escapeHtml(content)}" data-type="filterValue" data-type-rel="relation" data-path="${path}">`;
+ valueHTML = `<input class="b3-text-field b3-text-field--text fn__flex-1" value="${escapeHtml(content)}" data-type="filterValue" data-type-rel="relation" data-path="${path}">`;
}
return `${quantifierSelect}${operatorSelect}<span class="av__filter-value${valueHidden}" data-type="valueContainer" data-path="${path}">${valueHTML}</span>${extraHTML}`;
@@ -496,18 +496,18 @@ const genInlineDateHTML = (filter: IAVFilter, valueType: TAVCol, path: string):
const isBetween = filter.operator === "Is between";
const dateBlock = (suffix: "" | "2", relativeDate: IAVRelativeDate, dateVal: any, showToday: boolean): string => {
- const dateTypeSel = `<select class="b3-select av__filter-select" data-type="dateType${suffix}" data-path="${path}">
+ const dateTypeSel = `<select class="b3-select" data-type="dateType${suffix}" data-path="${path}">
<option value="time"${!relativeDate ? " selected" : ""}>${window.siyuan.languages.includeTime}</option>
<option value="custom"${relativeDate ? " selected" : ""}>${window.siyuan.languages.relativeToToday}</option>
</select>`;
- const absDate = `<input value="${(dateVal && (dateVal.isNotEmpty || (suffix === "2" ? dateVal.isNotEmpty2 : valueType !== "date"))) ? dayjs(suffix === "2" ? dateVal.content2 : dateVal.content).format("YYYY-MM-DD") : ""}" type="date" max="9999-12-31" class="b3-text-field b3-text-field--text av__filter-date-input" data-type="absDate${suffix}" data-path="${path}" style="${relativeDate ? "display:none;" : ""}">`;
- const relDir = `<select class="b3-select av__filter-select" data-type="dataDirection${suffix}" data-path="${path}" style="${!relativeDate ? "display:none;" : ""}">
+ const absDate = `<input value="${(dateVal && (dateVal.isNotEmpty || (suffix === "2" ? dateVal.isNotEmpty2 : valueType !== "date"))) ? dayjs(suffix === "2" ? dateVal.content2 : dateVal.content).format("YYYY-MM-DD") : ""}" type="date" max="9999-12-31" class="b3-text-field b3-text-field--text" data-type="absDate${suffix}" data-path="${path}" style="${relativeDate ? "display:none;" : ""}">`;
+ const relDir = `<select class="b3-select" data-type="dataDirection${suffix}" data-path="${path}" style="${!relativeDate ? "display:none;" : ""}">
<option value="-1"${relativeDate?.direction === -1 ? " selected" : ""}>${window.siyuan.languages.pastDate}</option>
<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 av__filter-date-input" data-type="relCount${suffix}" data-path="${path}" style="width:50px;${(!relativeDate || showToday) ? "display:none;" : ""}">`;
- const relUnit = `<select class="b3-select av__filter-select" data-type="relUnit${suffix}" data-path="${path}" style="${(!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" data-type="relCount${suffix}" data-path="${path}" style="width:50px;${(!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>
<option value="2"${relativeDate?.unit === 2 ? " selected" : ""}>${window.siyuan.languages.month}</option>
diff --git a/app/src/protyle/render/av/openMenuPanel.ts b/app/src/protyle/render/av/openMenuPanel.ts
index de85104fd7..3d974edf16 100644
--- a/app/src/protyle/render/av/openMenuPanel.ts
+++ b/app/src/protyle/render/av/openMenuPanel.ts
@@ -269,11 +269,10 @@ export const openMenuPanel = (options: {
data: oldFilters,
blockID
}]);
- menuElement.querySelectorAll(`[data-type="toggleCombination"][data-path="${path}"]`).forEach((sel: HTMLSelectElement) => {
- if (sel !== select) {
- sel.value = (select as HTMLSelectElement).value;
- }
- });
+ // 重渲染以同步所有只读且/或标签(index >= 2 的节点显示的是只读 span)
+ menuElement.innerHTML = getFiltersHTML(data);
+ bindInlineFilterEvents(avPanelElement as HTMLElement, data, options.protyle, blockID, avID);
+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
event.stopPropagation();
});
// 多选排序