mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-26 10:16:10 +01:00
This commit is contained in:
parent
037c6451d7
commit
7753e0fd89
12 changed files with 119 additions and 17 deletions
|
|
@ -517,6 +517,34 @@ export abstract class Constants {
|
|||
}
|
||||
};
|
||||
|
||||
public static readonly SIYUAN_DEFAULT_REPLACETYPES: {
|
||||
[key: string]: boolean;
|
||||
} = {
|
||||
"text": true,
|
||||
"img-text": true,
|
||||
"img-title": true,
|
||||
"img-src": true,
|
||||
"a-text": true,
|
||||
"a-title": true,
|
||||
"a-href": true,
|
||||
"code": true,
|
||||
"em": true,
|
||||
"strong": true,
|
||||
"inline-math": true,
|
||||
"inline-memo": true,
|
||||
"kbd": true,
|
||||
"mark": true,
|
||||
"s": true,
|
||||
"sub": true,
|
||||
"sup": true,
|
||||
"tag": true,
|
||||
"u": true,
|
||||
"doc-title": true,
|
||||
"code-block": true,
|
||||
"math-block": true,
|
||||
"html-block": true
|
||||
}
|
||||
|
||||
// image
|
||||
public static readonly SIYUAN_IMAGE_VIP: string = `<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
|
||||
<path fill="#ffd00f" d="M2.288 12.643l23.487 12.853c0.286 0.153 0.477 0.45 0.477 0.791 0 0.082-0.011 0.161-0.032 0.237l0.001-0.006c-0.119 0.395-0.479 0.678-0.905 0.678-0.004 0-0.009-0-0.013-0h-19.439c-0.958 0-1.766-0.684-1.885-1.595l-1.691-12.956z"></path>
|
||||
|
|
|
|||
|
|
@ -232,7 +232,8 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => {
|
|||
k: localData.k,
|
||||
r: localData.r,
|
||||
page: 1,
|
||||
types: Object.assign({}, localData.types)
|
||||
types: Object.assign({}, localData.types),
|
||||
replaceTypes: Object.assign({}, localData.replaceTypes)
|
||||
});
|
||||
/// #else
|
||||
openSearch({
|
||||
|
|
@ -262,7 +263,8 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => {
|
|||
k: localData.k,
|
||||
r: localData.r,
|
||||
page: 1,
|
||||
types: Object.assign({}, localData.types)
|
||||
types: Object.assign({}, localData.types),
|
||||
replaceTypes: Object.assign({}, localData.replaceTypes)
|
||||
});
|
||||
/// #else
|
||||
openSearch({
|
||||
|
|
@ -556,7 +558,8 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
|
|||
k: localData.k,
|
||||
r: localData.r,
|
||||
page: 1,
|
||||
types: Object.assign({}, localData.types)
|
||||
types: Object.assign({}, localData.types),
|
||||
replaceTypes: Object.assign({}, localData.replaceTypes)
|
||||
});
|
||||
/// #else
|
||||
openSearch({
|
||||
|
|
@ -591,7 +594,8 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
|
|||
k: localData.k,
|
||||
r: localData.r,
|
||||
page: 1,
|
||||
types: Object.assign({}, localData.types)
|
||||
types: Object.assign({}, localData.types),
|
||||
replaceTypes: Object.assign({}, localData.replaceTypes)
|
||||
});
|
||||
/// #else
|
||||
openSearch({
|
||||
|
|
|
|||
|
|
@ -53,7 +53,8 @@ export class MobileTags {
|
|||
k: `#${labelName}#`,
|
||||
r: "",
|
||||
page: 1,
|
||||
types: Object.assign({}, searchOption.types)
|
||||
types: Object.assign({}, searchOption.types),
|
||||
replaceTypes: Object.assign({}, searchOption.replaceTypes)
|
||||
});
|
||||
},
|
||||
blockExtHTML: window.siyuan.config.readonly ? undefined : '<span class="b3-list-item__action"><svg><use xlink:href="#iconMore"></use></svg></span>',
|
||||
|
|
|
|||
|
|
@ -497,7 +497,8 @@ const initSearchEvent = (app: App, element: Element, config: ISearchOption) => {
|
|||
paragraph: window.siyuan.config.search.paragraph,
|
||||
embedBlock: window.siyuan.config.search.embedBlock,
|
||||
databaseBlock: window.siyuan.config.search.databaseBlock,
|
||||
}
|
||||
},
|
||||
replaceTypes: Constants.SIYUAN_DEFAULT_REPLACETYPES,
|
||||
}, config);
|
||||
});
|
||||
window.siyuan.menus.menu.fullscreen();
|
||||
|
|
|
|||
|
|
@ -372,7 +372,8 @@ export class Background {
|
|||
k: `#${target.textContent}#`,
|
||||
r: "",
|
||||
page: 1,
|
||||
types: Object.assign({}, searchOption.types)
|
||||
types: Object.assign({}, searchOption.types),
|
||||
replaceTypes: Object.assign({}, searchOption.replaceTypes)
|
||||
});
|
||||
/// #endif
|
||||
event.preventDefault();
|
||||
|
|
|
|||
|
|
@ -184,7 +184,8 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
|
|||
k: localData.k,
|
||||
r: localData.r,
|
||||
page: 1,
|
||||
types: Object.assign({}, localData.types)
|
||||
types: Object.assign({}, localData.types),
|
||||
replaceTypes: Object.assign({}, localData.replaceTypes)
|
||||
});
|
||||
/// #else
|
||||
openSearch({
|
||||
|
|
|
|||
|
|
@ -238,7 +238,8 @@ export const getLocalStorage = (cb: () => void) => {
|
|||
paragraph: window.siyuan.config.search.paragraph,
|
||||
embedBlock: window.siyuan.config.search.embedBlock,
|
||||
databaseBlock: window.siyuan.config.search.databaseBlock,
|
||||
}
|
||||
},
|
||||
replaceTypes: Constants.SIYUAN_DEFAULT_REPLACETYPES,
|
||||
};
|
||||
defaultStorage[Constants.LOCAL_ZOOM] = 1;
|
||||
|
||||
|
|
@ -262,6 +263,9 @@ export const getLocalStorage = (cb: () => void) => {
|
|||
} else if (typeof response.data[key] === "undefined") {
|
||||
window.siyuan.storage[key] = defaultStorage[key];
|
||||
}
|
||||
if (!window.siyuan.storage[Constants.LOCAL_SEARCHDATA].replaceTypes) {
|
||||
window.siyuan.storage[Constants.LOCAL_SEARCHDATA].replaceTypes = Constants.SIYUAN_DEFAULT_REPLACETYPES;
|
||||
}
|
||||
});
|
||||
cb();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1922,7 +1922,8 @@ export class WYSIWYG {
|
|||
k: `#${tagElement.textContent}#`,
|
||||
r: "",
|
||||
page: 1,
|
||||
types: Object.assign({}, searchOption.types)
|
||||
types: Object.assign({}, searchOption.types),
|
||||
replaceTypes: Object.assign({}, searchOption.replaceTypes)
|
||||
});
|
||||
/// #endif
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -151,6 +151,40 @@ export const filterMenu = (config: ISearchOption, cb: () => void) => {
|
|||
});
|
||||
};
|
||||
|
||||
export const replaceFilterMenu = (config: ISearchOption) => {
|
||||
let html = "";
|
||||
Object.keys(Constants.SIYUAN_DEFAULT_REPLACETYPES).forEach((key) => {
|
||||
html += `<label class="fn__flex b3-label">
|
||||
<span class="fn__space"></span>
|
||||
<div class="fn__flex-1 fn__flex-center">
|
||||
${window.siyuan.languages[key]}
|
||||
</div>
|
||||
<span class="fn__space"></span>
|
||||
<input class="b3-switch fn__flex-center" data-type="${key}" type="checkbox"${config.replaceTypes[key] ? " checked" : ""}>
|
||||
</label>`;
|
||||
})
|
||||
const filterDialog = new Dialog({
|
||||
title: window.siyuan.languages.type,
|
||||
content: `<div class="b3-dialog__content">${html}</div>
|
||||
<div class="b3-dialog__action">
|
||||
<button class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button><div class="fn__space"></div>
|
||||
<button class="b3-button b3-button--text">${window.siyuan.languages.confirm}</button>
|
||||
</div>`,
|
||||
width: isMobile() ? "92vw" : "520px",
|
||||
height: "70vh",
|
||||
});
|
||||
const btnsElement = filterDialog.element.querySelectorAll(".b3-button");
|
||||
btnsElement[0].addEventListener("click", () => {
|
||||
filterDialog.destroy();
|
||||
});
|
||||
btnsElement[1].addEventListener("click", () => {
|
||||
filterDialog.element.querySelectorAll(".b3-switch").forEach((item: HTMLInputElement) => {
|
||||
config.replaceTypes[item.getAttribute("data-type") as TSearchFilter] = item.checked;
|
||||
});
|
||||
filterDialog.destroy();
|
||||
});
|
||||
};
|
||||
|
||||
export const queryMenu = (config: ISearchOption, cb: () => void) => {
|
||||
if (!window.siyuan.menus.menu.element.classList.contains("fn__none") &&
|
||||
window.siyuan.menus.menu.element.getAttribute("data-name") === "searchMethod") {
|
||||
|
|
|
|||
|
|
@ -109,6 +109,7 @@ export const openSearch = async (options: {
|
|||
group: localData.group,
|
||||
sort: localData.sort,
|
||||
types: Object.assign({}, localData.types),
|
||||
replaceTypes: Object.assign({}, localData.replaceTypes),
|
||||
page: options.key ? 1 : localData.page
|
||||
};
|
||||
const edit = genSearch(options.app, config, dialog.element.querySelector(".b3-dialog__body"), () => {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,15 @@ import {unicode2Emoji} from "../emoji";
|
|||
import {hasClosestByClassName} from "../protyle/util/hasClosest";
|
||||
import {isNotCtrl, setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
|
||||
import {newFileByName} from "../util/newFile";
|
||||
import {filterMenu, getKeyByLiElement, initCriteriaMenu, moreMenu, queryMenu, saveCriterion} from "./menu";
|
||||
import {
|
||||
filterMenu,
|
||||
getKeyByLiElement,
|
||||
initCriteriaMenu,
|
||||
moreMenu,
|
||||
queryMenu,
|
||||
replaceFilterMenu,
|
||||
saveCriterion
|
||||
} from "./menu";
|
||||
import {App} from "../index";
|
||||
import {
|
||||
assetFilterMenu,
|
||||
|
|
@ -215,6 +223,7 @@ export const openGlobalSearch = (app: App, text: string, replace: boolean) => {
|
|||
group: localData.group,
|
||||
sort: localData.sort,
|
||||
types: Object.assign({}, localData.types),
|
||||
replaceTypes: Object.assign({}, localData.replaceTypes),
|
||||
removed: localData.removed,
|
||||
page: 1
|
||||
},
|
||||
|
|
@ -323,10 +332,15 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
</div>
|
||||
<div class="fn__space"></div>
|
||||
<svg class="fn__rotate fn__none svg" style="padding: 0 8px;align-self: center;margin-right: 8px"><use xlink:href="#iconRefresh"></use></svg>
|
||||
<button id="replaceAllBtn" class="b3-button b3-button--small b3-button--outline fn__flex-center">${window.siyuan.languages.replaceAll}</button>
|
||||
<div class="fn__space"></div>
|
||||
<span class="fn__space"></span>
|
||||
<span id="replaceFilter" aria-label="${window.siyuan.languages.type}" class="block__icon ariaLabel fn__flex-center" data-position="9bottom">
|
||||
<svg><use xlink:href="#iconFilter"></use></svg>
|
||||
</span>
|
||||
<span class="fn__space"></span>
|
||||
<button id="replaceBtn" class="b3-button b3-button--small b3-button--outline fn__flex-center">↵ ${window.siyuan.languages.replace}</button>
|
||||
<div class="fn__space"></div>
|
||||
<button id="replaceAllBtn" class="b3-button b3-button--small b3-button--outline fn__flex-center">${window.siyuan.languages.replaceAll}</button>
|
||||
<div class="fn__space"></div>
|
||||
</div>
|
||||
<div id="criteria" class="search__header"></div>
|
||||
<div class="search__layout${(closeCB ? data.layout === 1 : data.layoutTab === 1) ? " search__layout--row" : ""}">
|
||||
|
|
@ -462,7 +476,8 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
paragraph: window.siyuan.config.search.paragraph,
|
||||
embedBlock: window.siyuan.config.search.embedBlock,
|
||||
databaseBlock: window.siyuan.config.search.databaseBlock,
|
||||
}
|
||||
},
|
||||
replaceTypes: Constants.SIYUAN_DEFAULT_REPLACETYPES,
|
||||
}, config, edit);
|
||||
element.querySelector(".b3-chip--current")?.classList.remove("b3-chip--current");
|
||||
event.stopPropagation();
|
||||
|
|
@ -677,7 +692,8 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
paragraph: window.siyuan.config.search.paragraph,
|
||||
embedBlock: window.siyuan.config.search.embedBlock,
|
||||
databaseBlock: window.siyuan.config.search.databaseBlock,
|
||||
}
|
||||
},
|
||||
replaceTypes: Constants.SIYUAN_DEFAULT_REPLACETYPES,
|
||||
}, config, edit);
|
||||
element.querySelector("#criteria .b3-chip--current")?.classList.remove("b3-chip--current");
|
||||
}, () => {
|
||||
|
|
@ -746,6 +762,12 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
} else if (target.id === "replaceFilter") {
|
||||
window.siyuan.menus.menu.remove();
|
||||
replaceFilterMenu(config);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
} else if (type === "assetPrevious") {
|
||||
if (!target.getAttribute("disabled")) {
|
||||
let currentPage = parseInt(assetsElement.querySelector("#searchAssetResult .fn__flex-center").textContent.split("/")[0]);
|
||||
|
|
@ -1137,7 +1159,8 @@ export const replace = (element: Element, config: ISearchOption, edit: Protyle,
|
|||
groupBy: config.group,
|
||||
orderBy: config.sort,
|
||||
page: config.page,
|
||||
ids: isAll ? [] : [currentList.getAttribute("data-node-id")]
|
||||
ids: isAll ? [] : [currentList.getAttribute("data-node-id")],
|
||||
replaceTypes: config.replaceTypes
|
||||
}, (response) => {
|
||||
loadElement.classList.add("fn__none");
|
||||
if (response.code === 1) {
|
||||
|
|
|
|||
5
app/src/types/index.d.ts
vendored
5
app/src/types/index.d.ts
vendored
|
|
@ -264,7 +264,10 @@ interface ISearchOption {
|
|||
htmlBlock: boolean
|
||||
embedBlock: boolean
|
||||
databaseBlock: boolean
|
||||
}
|
||||
},
|
||||
replaceTypes: {
|
||||
[key: string]: boolean;
|
||||
},
|
||||
}
|
||||
|
||||
interface ITextOption {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue