mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-02 06:48:49 +01:00
This commit is contained in:
parent
014ce033c3
commit
29b9f5c1e5
2 changed files with 95 additions and 40 deletions
|
|
@ -1,12 +1,12 @@
|
|||
import {closePanel} from "../util/closePanel";
|
||||
import {openMobileFileById} from "../editor";
|
||||
import {getCurrentEditor, openMobileFileById} from "../editor";
|
||||
import {Constants} from "../../constants";
|
||||
import {fetchPost} from "../../util/fetch";
|
||||
import {getIconByType} from "../../editor/getIcon";
|
||||
import {preventScroll} from "../../protyle/scroll/preventScroll";
|
||||
import {openModel} from "./model";
|
||||
import {getDisplayName, getNotebookIcon, getNotebookName, movePathTo, pathPosix} from "../../util/pathName";
|
||||
import {filterMenu, getKeyByLiElement, initCriteriaMenu, moreMenu, queryMenu} from "../../search/menu";
|
||||
import {getKeyByLiElement, initCriteriaMenu, moreMenu, queryMenu} from "../../search/menu";
|
||||
import {setStorageVal} from "../../protyle/util/compatibility";
|
||||
import {escapeGreat, escapeHtml} from "../../util/escape";
|
||||
import {unicode2Emoji} from "../../emoji";
|
||||
|
|
@ -208,7 +208,7 @@ ${unicode2Emoji(childItem.ial.icon, "b3-list-item__graphic", true)}
|
|||
};
|
||||
|
||||
let toolbarSearchTimeout = 0;
|
||||
const updateSearchResult = (config: ISearchOption, element: Element, rmCurrentCriteria = false) => {
|
||||
export const updateSearchResult = (config: ISearchOption, element: Element, rmCurrentCriteria = false) => {
|
||||
clearTimeout(toolbarSearchTimeout);
|
||||
toolbarSearchTimeout = window.setTimeout(() => {
|
||||
if (rmCurrentCriteria) {
|
||||
|
|
@ -370,6 +370,24 @@ const initSearchEvent = (app: App, element: Element, config: ISearchOption) => {
|
|||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
} else if (type === "currentPath" && !target.hasAttribute("disabled")) {
|
||||
const editProtyle = getCurrentEditor().protyle;
|
||||
fetchPost("/api/filetree/getHPathsByPaths", {paths: [editProtyle.path]}, (response) => {
|
||||
config.idPath = [pathPosix().join(editProtyle.notebookId, editProtyle.path)];
|
||||
config.hPath = response.data[0];
|
||||
const searchPathElement = element.querySelector("#searchPath");
|
||||
searchPathElement.classList.remove("fn__none");
|
||||
searchPathElement.innerHTML = `<div class="b3-chip b3-chip--middle">${escapeHtml(config.hPath)}<svg data-type="remove-path" class="b3-chip__close"><use xlink:href="#iconCloseRound"></use></svg></div>`;
|
||||
|
||||
const includeElement = element.querySelector('[data-type="include"]');
|
||||
includeElement.classList.remove("toolbar__icon--active");
|
||||
includeElement.removeAttribute("disabled");
|
||||
config.page = 1;
|
||||
updateSearchResult(config, element, true);
|
||||
});
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
} else if (type === "path") {
|
||||
movePathTo((toPath, toNotebook) => {
|
||||
fetchPost("/api/filetree/getHPathsByPaths", {paths: toPath}, (response) => {
|
||||
|
|
@ -392,7 +410,7 @@ const initSearchEvent = (app: App, element: Element, config: ISearchOption) => {
|
|||
|
||||
const searchPathElement = element.querySelector("#searchPath");
|
||||
searchPathElement.classList.remove("fn__none");
|
||||
element.querySelector("#searchPath").innerHTML = `<div class="b3-chip b3-chip--middle">${escapeHtml(config.hPath)}<svg data-type="remove-path" class="b3-chip__close"><use xlink:href="#iconCloseRound"></use></svg></div>`;
|
||||
searchPathElement.innerHTML = `<div class="b3-chip b3-chip--middle">${escapeHtml(config.hPath)}<svg data-type="remove-path" class="b3-chip__close"><use xlink:href="#iconCloseRound"></use></svg></div>`;
|
||||
|
||||
const includeElement = element.querySelector('[data-type="include"]');
|
||||
includeElement.classList.add("toolbar__icon--active");
|
||||
|
|
@ -471,22 +489,6 @@ const initSearchEvent = (app: App, element: Element, config: ISearchOption) => {
|
|||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
} else if (type === "filter") {
|
||||
filterMenu(config, () => {
|
||||
updateSearchResult(config, element, true);
|
||||
});
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
} else if (type === "query") {
|
||||
queryMenu(config, () => {
|
||||
config.page = 1;
|
||||
updateSearchResult(config, element, true);
|
||||
});
|
||||
window.siyuan.menus.menu.fullscreen();
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
} else if (type === "replace-all") {
|
||||
replace(element, config, true);
|
||||
event.stopPropagation();
|
||||
|
|
@ -629,10 +631,9 @@ export const popSearch = (app: App, config = window.siyuan.storage[Constants.LOC
|
|||
<div class="toolbar">
|
||||
<span class="fn__flex-1"></span>
|
||||
<svg data-type="toggle-replace" class="toolbar__icon${config.hasReplace ? " toolbar__icon--active" : ""}"><use xlink:href="#iconReplace"></use></svg>
|
||||
<svg data-type="query" class="toolbar__icon"><use xlink:href="#iconRegex"></use></svg>
|
||||
<svg data-type="filter" class="toolbar__icon"><use xlink:href="#iconFilter"></use></svg>
|
||||
<svg ${enableIncludeChild ? "" : "disabled"} data-type="include" class="toolbar__icon${includeChild ? " toolbar__icon--active" : ""}"><use xlink:href="#iconCopy"></use></svg>
|
||||
<svg data-type="path" class="toolbar__icon"><use xlink:href="#iconFolder"></use></svg>
|
||||
<svg ${document.querySelector("#empty").classList.contains("fn__none") ? "" : "disabled"} data-type="currentPath" class="toolbar__icon"><use xlink:href="#iconFocus"></use></svg>
|
||||
<svg data-type="expand" class="toolbar__icon${config.group === 0 ? " fn__none" : ""}"><use xlink:href="#iconExpand"></use></svg>
|
||||
<svg data-type="contract" class="toolbar__icon${config.group === 0 ? " fn__none" : ""}"><use xlink:href="#iconContract"></use></svg>
|
||||
<svg data-type="more" class="toolbar__icon"><use xlink:href="#iconMore"></use></svg>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import {fetchPost} from "../util/fetch";
|
|||
import {escapeHtml} from "../util/escape";
|
||||
import {setStorageVal} from "../protyle/util/compatibility";
|
||||
import {confirmDialog} from "../dialog/confirmDialog";
|
||||
import {updateSearchResult} from "../mobile/menu/search";
|
||||
|
||||
export const filterMenu = (config: ISearchOption, cb: () => void) => {
|
||||
const filterDialog = new Dialog({
|
||||
|
|
@ -150,7 +151,7 @@ export const queryMenu = (config: ISearchOption, cb: () => void) => {
|
|||
window.siyuan.menus.menu.remove();
|
||||
window.siyuan.menus.menu.element.setAttribute("data-name", "searchMethod");
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
iconHTML: Constants.ZWSP,
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.keyword,
|
||||
current: config.method === 0,
|
||||
click() {
|
||||
|
|
@ -159,7 +160,7 @@ export const queryMenu = (config: ISearchOption, cb: () => void) => {
|
|||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
iconHTML: Constants.ZWSP,
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.querySyntax,
|
||||
current: config.method === 1,
|
||||
click() {
|
||||
|
|
@ -168,7 +169,7 @@ export const queryMenu = (config: ISearchOption, cb: () => void) => {
|
|||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
iconHTML: Constants.ZWSP,
|
||||
iconHTML: "",
|
||||
label: "SQL",
|
||||
current: config.method === 2,
|
||||
click() {
|
||||
|
|
@ -177,7 +178,7 @@ export const queryMenu = (config: ISearchOption, cb: () => void) => {
|
|||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
iconHTML: Constants.ZWSP,
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.regex,
|
||||
current: config.method === 3,
|
||||
click() {
|
||||
|
|
@ -323,8 +324,61 @@ export const moreMenu = async (config: ISearchOption,
|
|||
}
|
||||
window.siyuan.menus.menu.remove();
|
||||
window.siyuan.menus.menu.element.setAttribute("data-name", "searchMore");
|
||||
/// #if MOBILE
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.type,
|
||||
click() {
|
||||
filterMenu(config, () => {
|
||||
updateSearchResult(config, element, true);
|
||||
});
|
||||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.searchMethod,
|
||||
type: "submenu",
|
||||
submenu: [{
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.keyword,
|
||||
current: config.method === 0,
|
||||
click() {
|
||||
config.method = 0;
|
||||
config.page = 1;
|
||||
updateSearchResult(config, element, true);
|
||||
}
|
||||
}, {
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.querySyntax,
|
||||
current: config.method === 1,
|
||||
click() {
|
||||
config.method = 1;
|
||||
config.page = 1;
|
||||
updateSearchResult(config, element, true);
|
||||
}
|
||||
}, {
|
||||
iconHTML: "",
|
||||
label: "SQL",
|
||||
current: config.method === 2,
|
||||
click() {
|
||||
config.method = 2;
|
||||
config.page = 1;
|
||||
updateSearchResult(config, element, true);
|
||||
}
|
||||
}, {
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.regex,
|
||||
current: config.method === 3,
|
||||
click() {
|
||||
config.method = 3;
|
||||
config.page = 1;
|
||||
updateSearchResult(config, element, true);
|
||||
}
|
||||
}]
|
||||
}).element);
|
||||
/// #endif
|
||||
const sortMenu = [{
|
||||
iconHTML: Constants.ZWSP,
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.type,
|
||||
current: config.sort === 0,
|
||||
click() {
|
||||
|
|
@ -332,7 +386,7 @@ export const moreMenu = async (config: ISearchOption,
|
|||
cb();
|
||||
}
|
||||
}, {
|
||||
iconHTML: Constants.ZWSP,
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.createdASC,
|
||||
current: config.sort === 1,
|
||||
click() {
|
||||
|
|
@ -340,7 +394,7 @@ export const moreMenu = async (config: ISearchOption,
|
|||
cb();
|
||||
}
|
||||
}, {
|
||||
iconHTML: Constants.ZWSP,
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.createdDESC,
|
||||
current: config.sort === 2,
|
||||
click() {
|
||||
|
|
@ -348,7 +402,7 @@ export const moreMenu = async (config: ISearchOption,
|
|||
cb();
|
||||
}
|
||||
}, {
|
||||
iconHTML: Constants.ZWSP,
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.modifiedASC,
|
||||
current: config.sort === 3,
|
||||
click() {
|
||||
|
|
@ -356,7 +410,7 @@ export const moreMenu = async (config: ISearchOption,
|
|||
cb();
|
||||
}
|
||||
}, {
|
||||
iconHTML: Constants.ZWSP,
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.modifiedDESC,
|
||||
current: config.sort === 4,
|
||||
click() {
|
||||
|
|
@ -364,7 +418,7 @@ export const moreMenu = async (config: ISearchOption,
|
|||
cb();
|
||||
}
|
||||
}, {
|
||||
iconHTML: Constants.ZWSP,
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.sortByRankAsc,
|
||||
current: config.sort === 6,
|
||||
click() {
|
||||
|
|
@ -372,7 +426,7 @@ export const moreMenu = async (config: ISearchOption,
|
|||
cb();
|
||||
}
|
||||
}, {
|
||||
iconHTML: Constants.ZWSP,
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.sortByRankDesc,
|
||||
current: config.sort === 7,
|
||||
click() {
|
||||
|
|
@ -382,7 +436,7 @@ export const moreMenu = async (config: ISearchOption,
|
|||
}];
|
||||
if (config.group === 1) {
|
||||
sortMenu.push({
|
||||
iconHTML: Constants.ZWSP,
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.sortByContent,
|
||||
current: config.sort === 5,
|
||||
click() {
|
||||
|
|
@ -392,17 +446,17 @@ export const moreMenu = async (config: ISearchOption,
|
|||
});
|
||||
}
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
iconHTML: Constants.ZWSP,
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.sort,
|
||||
type: "submenu",
|
||||
submenu: sortMenu,
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
iconHTML: Constants.ZWSP,
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.group,
|
||||
type: "submenu",
|
||||
submenu: [{
|
||||
iconHTML: Constants.ZWSP,
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.noGroupBy,
|
||||
current: config.group === 0,
|
||||
click() {
|
||||
|
|
@ -419,7 +473,7 @@ export const moreMenu = async (config: ISearchOption,
|
|||
cb();
|
||||
}
|
||||
}, {
|
||||
iconHTML: Constants.ZWSP,
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.groupByDoc,
|
||||
current: config.group === 1,
|
||||
click() {
|
||||
|
|
@ -440,13 +494,13 @@ export const moreMenu = async (config: ISearchOption,
|
|||
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.saveCriterion,
|
||||
iconHTML: Constants.ZWSP,
|
||||
iconHTML: "",
|
||||
click() {
|
||||
saveCriterion(config, criteriaData, element);
|
||||
}
|
||||
}).element);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
iconHTML: Constants.ZWSP,
|
||||
iconHTML: "",
|
||||
label: window.siyuan.languages.removeCriterion,
|
||||
click() {
|
||||
removeCriterion();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue