This commit is contained in:
Vanessa 2023-07-13 23:18:09 +08:00
parent 2ee0155ee0
commit ca891b6440
3 changed files with 28 additions and 28 deletions

View File

@ -55,20 +55,20 @@ export const genCellValue = (colType: TAVCol, value: string | {
}; };
const toggleEmpty = (element: HTMLElement, show: boolean) => { const toggleEmpty = (element: HTMLElement, show: boolean) => {
const menuElement = hasClosestByClassName(element, "b3-menu") const menuElement = hasClosestByClassName(element, "b3-menu");
if (menuElement) { if (menuElement) {
menuElement.querySelectorAll("input, .b3-chip").forEach(inputElement => { menuElement.querySelectorAll("input, .b3-chip").forEach(inputElement => {
const menuItemElement = hasClosestByClassName(inputElement, "b3-menu__item") const menuItemElement = hasClosestByClassName(inputElement, "b3-menu__item");
if (menuItemElement) { if (menuItemElement) {
if (show) { if (show) {
menuItemElement.classList.remove("fn__none") menuItemElement.classList.remove("fn__none");
} else { } else {
menuItemElement.classList.add("fn__none") menuItemElement.classList.add("fn__none");
} }
} }
}) });
} }
} };
export const setFilter = (options: { export const setFilter = (options: {
filter: IAVFilter, filter: IAVFilter,
@ -84,16 +84,16 @@ export const setFilter = (options: {
if (textElement) { if (textElement) {
cellValue = genCellValue(options.filter.value.type, textElement.value); cellValue = genCellValue(options.filter.value.type, textElement.value);
} else { } else {
const mSelect: { color: string, content: string }[] = [] const mSelect: { color: string, content: string }[] = [];
window.siyuan.menus.menu.element.querySelectorAll('svg').forEach(item => { window.siyuan.menus.menu.element.querySelectorAll("svg").forEach(item => {
if (item.firstElementChild.getAttribute("xlink:href") === "#iconCheck") { if (item.firstElementChild.getAttribute("xlink:href") === "#iconCheck") {
const chipElement = item.nextElementSibling.firstElementChild as HTMLElement const chipElement = item.nextElementSibling.firstElementChild as HTMLElement;
mSelect.push({ mSelect.push({
color: chipElement.dataset.color, color: chipElement.dataset.color,
content: chipElement.dataset.name content: chipElement.dataset.name
}) });
} }
}) });
cellValue = genCellValue(options.filter.value.type, mSelect); cellValue = genCellValue(options.filter.value.type, mSelect);
} }
const newFilter: IAVFilter = { const newFilter: IAVFilter = {
@ -188,12 +188,12 @@ export const setFilter = (options: {
}); });
if (options.filter.value.type === "select" || options.filter.value.type === "mSelect") { if (options.filter.value.type === "select" || options.filter.value.type === "mSelect") {
colData.options?.forEach((option) => { colData.options?.forEach((option) => {
let icon = "iconUncheck" let icon = "iconUncheck";
options.filter.value.mSelect.find((optionItem) => { options.filter.value.mSelect.find((optionItem) => {
if (optionItem.content === option.name) { if (optionItem.content === option.name) {
icon = "iconCheck" icon = "iconCheck";
} }
}) });
menu.addItem({ menu.addItem({
icon, icon,
label: `<span class="b3-chip b3-chip--middle" data-name="${option.name}" data-color="${option.color}" style="margin:3px 0;background-color:var(--b3-font-background${option.color});color:var(--b3-font-color${option.color})"> label: `<span class="b3-chip b3-chip--middle" data-name="${option.name}" data-color="${option.color}" style="margin:3px 0;background-color:var(--b3-font-background${option.color});color:var(--b3-font-color${option.color})">
@ -201,15 +201,15 @@ export const setFilter = (options: {
</span>`, </span>`,
bind(element) { bind(element) {
element.addEventListener("click", () => { element.addEventListener("click", () => {
const useElement = element.querySelector("use") const useElement = element.querySelector("use");
if (useElement.getAttribute("xlink:href") === "#iconUncheck") { if (useElement.getAttribute("xlink:href") === "#iconUncheck") {
useElement.setAttribute("xlink:href", "#iconCheck"); useElement.setAttribute("xlink:href", "#iconCheck");
} else { } else {
useElement.setAttribute("xlink:href", "#iconUncheck"); useElement.setAttribute("xlink:href", "#iconUncheck");
} }
}) });
} }
}) });
}); });
} else if (options.filter.value.type === "text") { } else if (options.filter.value.type === "text") {
menu.addItem({ menu.addItem({
@ -250,7 +250,7 @@ export const setFilter = (options: {
}); });
const selectElement = (window.siyuan.menus.menu.element.querySelector(".b3-select") as HTMLSelectElement); const selectElement = (window.siyuan.menus.menu.element.querySelector(".b3-select") as HTMLSelectElement);
selectElement.addEventListener("change", () => { selectElement.addEventListener("change", () => {
toggleEmpty(selectElement, selectElement.value !== "Is empty" && selectElement.value !== "Is not empty") toggleEmpty(selectElement, selectElement.value !== "Is empty" && selectElement.value !== "Is not empty");
}); });
const textElement = window.siyuan.menus.menu.element.querySelector(".b3-text-field") as HTMLInputElement; const textElement = window.siyuan.menus.menu.element.querySelector(".b3-text-field") as HTMLInputElement;
if (textElement) { if (textElement) {
@ -265,7 +265,7 @@ export const setFilter = (options: {
} }
}); });
} }
toggleEmpty(selectElement, selectElement.value !== "Is empty" && selectElement.value !== "Is not empty") toggleEmpty(selectElement, selectElement.value !== "Is empty" && selectElement.value !== "Is not empty");
menu.open({x: rectTarget.left, y: rectTarget.bottom}); menu.open({x: rectTarget.left, y: rectTarget.bottom});
if (textElement) { if (textElement) {
textElement.select(); textElement.select();

View File

@ -388,15 +388,15 @@ export const addSelectColAndCell = (protyle: IProtyle, data: IAV, options: {
id: Lute.NewNodeID(), id: Lute.NewNodeID(),
value: genCellValue(colData.type, ""), value: genCellValue(colData.type, ""),
valueType: colData.type valueType: colData.type
} };
} else { } else {
let hasSelected = false let hasSelected = false;
cellData.value.mSelect.find((item) => { cellData.value.mSelect.find((item) => {
if (item.content === currentElement.dataset.name) { if (item.content === currentElement.dataset.name) {
hasSelected = true hasSelected = true;
return true; return true;
} }
}) });
if (hasSelected) { if (hasSelected) {
menuElement.querySelector("input").focus(); menuElement.querySelector("input").focus();
return; return;

View File

@ -13,7 +13,7 @@ import {addLoading, setPadding} from "../protyle/ui/initUI";
import {getIconByType} from "../editor/getIcon"; import {getIconByType} from "../editor/getIcon";
import {unicode2Emoji} from "../emoji"; import {unicode2Emoji} from "../emoji";
import {hasClosestByClassName} from "../protyle/util/hasClosest"; import {hasClosestByClassName} from "../protyle/util/hasClosest";
import {isCtrl, setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility"; import {setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
import {newFileByName} from "../util/newFile"; import {newFileByName} from "../util/newFile";
import {matchHotKey} from "../protyle/util/hotKey"; import {matchHotKey} from "../protyle/util/hotKey";
import {filterMenu, getKeyByLiElement, initCriteriaMenu, moreMenu, queryMenu, saveCriterion} from "./menu"; import {filterMenu, getKeyByLiElement, initCriteriaMenu, moreMenu, queryMenu, saveCriterion} from "./menu";
@ -294,7 +294,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
paragraph: window.siyuan.config.search.paragraph, paragraph: window.siyuan.config.search.paragraph,
embedBlock: window.siyuan.config.search.embedBlock, embedBlock: window.siyuan.config.search.embedBlock,
} }
}, config, edit, app); }, config, edit);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;
@ -323,7 +323,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
config.removed = false; config.removed = false;
criteriaData.find(item => { criteriaData.find(item => {
if (item.name === target.innerText.trim()) { if (item.name === target.innerText.trim()) {
updateConfig(element, item, config, edit, app); updateConfig(element, item, config, edit);
return true; return true;
} }
}); });
@ -483,7 +483,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
paragraph: window.siyuan.config.search.paragraph, paragraph: window.siyuan.config.search.paragraph,
embedBlock: window.siyuan.config.search.embedBlock, embedBlock: window.siyuan.config.search.embedBlock,
} }
}, config, edit, app); }, config, edit);
}, () => { }, () => {
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHKEYS]; const localData = window.siyuan.storage[Constants.LOCAL_SEARCHKEYS];
const isPopover = hasClosestByClassName(element, "b3-dialog__container"); const isPopover = hasClosestByClassName(element, "b3-dialog__container");
@ -855,7 +855,7 @@ const getQueryTip = (method: number) => {
return methodTip; return methodTip;
}; };
const updateConfig = (element: Element, item: ISearchOption, config: ISearchOption, edit: Protyle, app: App) => { const updateConfig = (element: Element, item: ISearchOption, config: ISearchOption, edit: Protyle) => {
const dialogElement = hasClosestByClassName(element, "b3-dialog--open"); const dialogElement = hasClosestByClassName(element, "b3-dialog--open");
if (dialogElement && dialogElement.getAttribute("data-key") === window.siyuan.config.keymap.general.search.custom) { if (dialogElement && dialogElement.getAttribute("data-key") === window.siyuan.config.keymap.general.search.custom) {
// https://github.com/siyuan-note/siyuan/issues/6828 // https://github.com/siyuan-note/siyuan/issues/6828