This commit is contained in:
Vanessa 2023-03-22 11:56:58 +08:00
parent b92ac264ca
commit 97882c4304
7 changed files with 45 additions and 45 deletions

View file

@ -9,21 +9,13 @@ export const ai = {
</div> </div>
<div class="fn__flex-1"> <div class="fn__flex-1">
<div data-type="openai"> <div data-type="openai">
<label class="fn__flex b3-label">
<div class="fn__flex-1">
${window.siyuan.languages.apiKey}
<div class="b3-label__text">${window.siyuan.languages.apiKeyTip}</div>
</div>
<span class="fn__space"></span>
<input class="b3-text-field fn__flex-center" id="apiKey" value="${window.siyuan.config.ai.openAI.apiKey}"/>
</label>
<label class="fn__flex b3-label"> <label class="fn__flex b3-label">
<div class="fn__flex-1"> <div class="fn__flex-1">
${window.siyuan.languages.apiTimeout} ${window.siyuan.languages.apiTimeout}
<div class="b3-label__text">${window.siyuan.languages.apiTimeoutTip}</div> <div class="b3-label__text">${window.siyuan.languages.apiTimeoutTip}</div>
</div> </div>
<span class="fn__space"></span> <span class="fn__space"></span>
<input class="b3-text-field fn__flex-center" type="number" step="1" min="5" max="600" id="apiTimeout" value="${window.siyuan.config.ai.openAI.apiTimeout}"/> <input class="b3-text-field fn__flex-center fn__size200" type="number" step="1" min="5" max="600" id="apiTimeout" value="${window.siyuan.config.ai.openAI.apiTimeout}"/>
</label> </label>
<label class="fn__flex b3-label"> <label class="fn__flex b3-label">
<div class="fn__flex-1"> <div class="fn__flex-1">
@ -31,23 +23,31 @@ export const ai = {
<div class="b3-label__text">${window.siyuan.languages.apiMaxTokensTip}</div> <div class="b3-label__text">${window.siyuan.languages.apiMaxTokensTip}</div>
</div> </div>
<span class="fn__space"></span> <span class="fn__space"></span>
<input class="b3-text-field fn__flex-center" type="number" step="1" min="0" id="apiMaxTokens" max="4096" value="${window.siyuan.config.ai.openAI.apiMaxTokens}"/> <input class="b3-text-field fn__flex-center fn__size200" type="number" step="1" min="0" id="apiMaxTokens" max="4096" value="${window.siyuan.config.ai.openAI.apiMaxTokens}"/>
</label>
<label class="fn__flex b3-label">
<div class="fn__flex-1">
${window.siyuan.languages.apiKey}
<div class="b3-label__text">${window.siyuan.languages.apiKeyTip}</div>
<div class="fn__hr"></div>
<input class="b3-text-field fn__block" id="apiKey" value="${window.siyuan.config.ai.openAI.apiKey}"/>
</div>
</label> </label>
<label class="fn__flex b3-label"> <label class="fn__flex b3-label">
<div class="fn__flex-1"> <div class="fn__flex-1">
${window.siyuan.languages.apiProxy} ${window.siyuan.languages.apiProxy}
<div class="b3-label__text">${window.siyuan.languages.apiProxyTip}</div> <div class="b3-label__text">${window.siyuan.languages.apiProxyTip}</div>
<span class="fn__hr"></span>
<input class="b3-text-field fn__block" id="apiProxy" value="${window.siyuan.config.ai.openAI.apiProxy}"/>
</div> </div>
<span class="fn__space"></span>
<input class="b3-text-field fn__flex-center" id="apiProxy" value="${window.siyuan.config.ai.openAI.apiProxy}"/>
</label> </label>
<label class="fn__flex b3-label"> <label class="fn__flex b3-label">
<div class="fn__flex-1"> <div class="fn__flex-1">
${window.siyuan.languages.apiBaseURL} ${window.siyuan.languages.apiBaseURL}
<div class="b3-label__text">${window.siyuan.languages.apiBaseURLTip}</div> <div class="b3-label__text">${window.siyuan.languages.apiBaseURLTip}</div>
<span class="fn__hr"></span>
<input class="b3-text-field fn__block" id="apiBaseURL" value="${window.siyuan.config.ai.openAI.apiBaseURL}"/>
</div> </div>
<span class="fn__space"></span>
<input class="b3-text-field fn__flex-center" id="apiBaseURL" value="${window.siyuan.config.ai.openAI.apiBaseURL}"/>
</label> </label>
</div> </div>
</div> </div>

View file

@ -9,7 +9,7 @@ export const flashcard = {
<div class="b3-label__text">${window.siyuan.languages.flashcardNewCardLimitTip}</div> <div class="b3-label__text">${window.siyuan.languages.flashcardNewCardLimitTip}</div>
</div> </div>
<span class="fn__space"></span> <span class="fn__space"></span>
<input class="b3-text-field fn__flex-center" id="newCardLimit" step="1" min="1" type="number"${window.siyuan.config.flashcard.newCardLimit ? " checked" : "" } value="${window.siyuan.config.flashcard.newCardLimit}"/> <input class="b3-text-field fn__flex-center fn__size200" id="newCardLimit" step="1" min="1" type="number"${window.siyuan.config.flashcard.newCardLimit ? " checked" : "" } value="${window.siyuan.config.flashcard.newCardLimit}"/>
</label> </label>
<label class="fn__flex b3-label"> <label class="fn__flex b3-label">
<div class="fn__flex-1"> <div class="fn__flex-1">
@ -17,7 +17,7 @@ export const flashcard = {
<div class="b3-label__text">${window.siyuan.languages.flashcardReviewCardLimitTip}</div> <div class="b3-label__text">${window.siyuan.languages.flashcardReviewCardLimitTip}</div>
</div> </div>
<span class="fn__space"></span> <span class="fn__space"></span>
<input class="b3-text-field fn__flex-center" id="reviewCardLimit" step="1" min="1" type="number"${window.siyuan.config.flashcard.reviewCardLimit ? " checked" : ""} value="${window.siyuan.config.flashcard.reviewCardLimit}"/> <input class="b3-text-field fn__flex-center fn__size200" id="reviewCardLimit" step="1" min="1" type="number"${window.siyuan.config.flashcard.reviewCardLimit ? " checked" : ""} value="${window.siyuan.config.flashcard.reviewCardLimit}"/>
</label> </label>
<label class="fn__flex b3-label"> <label class="fn__flex b3-label">
<div class="fn__flex-1"> <div class="fn__flex-1">

View file

@ -65,10 +65,10 @@ export abstract class Constants {
// localstorage // localstorage
public static readonly LOCAL_ZOOM = "local-zoom"; public static readonly LOCAL_ZOOM = "local-zoom";
public static readonly LOCAL_SEARCHEDATA = "local-searchedata"; public static readonly LOCAL_SEARCHDATA = "local-searchdata";
public static readonly LOCAL_SEARCHEKEYS = "local-searchekeys"; public static readonly LOCAL_SEARCHKEYS = "local-searchkeys";
public static readonly LOCAL_SEARCHKEY = "local-searchkey"; // only mobile
public static readonly LOCAL_DOCINFO = "local-docinfo"; // only mobile public static readonly LOCAL_DOCINFO = "local-docinfo"; // only mobile
public static readonly LOCAL_SEARCHEKEY = "local-searchkey"; // only mobile
public static readonly LOCAL_DAILYNOTEID = "local-dailynoteid"; // string public static readonly LOCAL_DAILYNOTEID = "local-dailynoteid"; // string
public static readonly LOCAL_HISTORYNOTEID = "local-historynoteid"; // string public static readonly LOCAL_HISTORYNOTEID = "local-historynoteid"; // string
public static readonly LOCAL_CODELANG = "local-codelang"; // string public static readonly LOCAL_CODELANG = "local-codelang"; // string

View file

@ -38,15 +38,15 @@ export const toolbarSearchEvent = () => {
onRecentBlocks(response.data.blocks, response.data.matchedRootCount,response.data.matchedBlockCount); onRecentBlocks(response.data.blocks, response.data.matchedRootCount,response.data.matchedBlockCount);
}); });
} }
window.siyuan.storage[Constants.LOCAL_SEARCHEKEY] = inputElement.value; window.siyuan.storage[Constants.LOCAL_SEARCHKEY] = inputElement.value;
setStorageVal(Constants.LOCAL_SEARCHEKEY, window.siyuan.storage[Constants.LOCAL_SEARCHEKEY]); setStorageVal(Constants.LOCAL_SEARCHKEY, window.siyuan.storage[Constants.LOCAL_SEARCHKEY]);
}, Constants.TIMEOUT_SEARCH); }, Constants.TIMEOUT_SEARCH);
}; };
const initToolbarSearch = () => { const initToolbarSearch = () => {
const inputElement = document.getElementById("toolbarSearch") as HTMLInputElement; const inputElement = document.getElementById("toolbarSearch") as HTMLInputElement;
inputElement.focus(); inputElement.focus();
inputElement.value = window.siyuan.storage[Constants.LOCAL_SEARCHEKEY] || ""; inputElement.value = window.siyuan.storage[Constants.LOCAL_SEARCHKEY] || "";
inputElement.addEventListener("compositionend", (event: InputEvent) => { inputElement.addEventListener("compositionend", (event: InputEvent) => {
if (event && event.isComposing) { if (event && event.isComposing) {
return; return;

View file

@ -144,7 +144,7 @@ export const getLocalStorage = (cb: () => void) => {
window.siyuan.storage = response.data; window.siyuan.storage = response.data;
// 历史数据迁移 // 历史数据迁移
const defaultStorage: any = {}; const defaultStorage: any = {};
defaultStorage[Constants.LOCAL_SEARCHEKEYS] = { defaultStorage[Constants.LOCAL_SEARCHKEYS] = {
keys: [], keys: [],
replaceKeys: [], replaceKeys: [],
col: "", col: "",
@ -180,7 +180,7 @@ export const getLocalStorage = (cb: () => void) => {
action: [] action: []
}; };
defaultStorage[Constants.LOCAL_FONTSTYLES] = []; defaultStorage[Constants.LOCAL_FONTSTYLES] = [];
defaultStorage[Constants.LOCAL_SEARCHEDATA] = { defaultStorage[Constants.LOCAL_SEARCHDATA] = {
sort: 0, sort: 0,
group: 0, group: 0,
hasReplace: false, hasReplace: false,
@ -205,16 +205,16 @@ export const getLocalStorage = (cb: () => void) => {
} }
}; };
defaultStorage[Constants.LOCAL_ZOOM] = 1; defaultStorage[Constants.LOCAL_ZOOM] = 1;
defaultStorage[Constants.LOCAL_SEARCHEKEY] = ""; defaultStorage[Constants.LOCAL_SEARCHKEY] = "";
[Constants.LOCAL_EXPORTIMG, Constants.LOCAL_SEARCHEKEYS, Constants.LOCAL_PDFTHEME, Constants.LOCAL_BAZAAR, Constants.LOCAL_EXPORTWORD, [Constants.LOCAL_EXPORTIMG, Constants.LOCAL_SEARCHKEYS, Constants.LOCAL_PDFTHEME, Constants.LOCAL_BAZAAR, Constants.LOCAL_EXPORTWORD,
Constants.LOCAL_EXPORTPDF, Constants.LOCAL_DOCINFO, Constants.LOCAL_FONTSTYLES, Constants.LOCAL_SEARCHEDATA, Constants.LOCAL_EXPORTPDF, Constants.LOCAL_DOCINFO, Constants.LOCAL_FONTSTYLES, Constants.LOCAL_SEARCHDATA,
Constants.LOCAL_ZOOM, Constants.LOCAL_SEARCHEKEY, Constants.LOCAL_LAYOUTS].forEach((key) => { Constants.LOCAL_ZOOM, Constants.LOCAL_SEARCHKEY, Constants.LOCAL_LAYOUTS].forEach((key) => {
if (typeof response.data[key] === "string") { if (typeof response.data[key] === "string") {
try { try {
window.siyuan.storage[key] = Object.assign(defaultStorage[key], JSON.parse(response.data[key])); window.siyuan.storage[key] = Object.assign(defaultStorage[key], JSON.parse(response.data[key]));
} catch (e) { } catch (e) {
window.siyuan.storage[key] = key === Constants.LOCAL_SEARCHEKEY ? (response.data[key] || "") : defaultStorage[key]; window.siyuan.storage[key] = key === Constants.LOCAL_SEARCHKEY ? (response.data[key] || "") : defaultStorage[key];
} }
} else if (typeof response.data[key] === "undefined") { } else if (typeof response.data[key] === "undefined") {
window.siyuan.storage[key] = defaultStorage[key]; window.siyuan.storage[key] = defaultStorage[key];

View file

@ -45,7 +45,7 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
if (exitDialog) { if (exitDialog) {
return; return;
} }
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHEDATA]; const localData = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
let hPath = ""; let hPath = "";
let idPath: string[] = []; let idPath: string[] = [];
if (notebookId) { if (notebookId) {

View file

@ -21,15 +21,15 @@ import {hasClosestByClassName} from "../protyle/util/hasClosest";
import {setStorageVal} from "../protyle/util/compatibility"; import {setStorageVal} from "../protyle/util/compatibility";
const saveKeyList = (type: "keys" | "replaceKeys", value: string) => { const saveKeyList = (type: "keys" | "replaceKeys", value: string) => {
let list: string[] = window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS][type]; let list: string[] = window.siyuan.storage[Constants.LOCAL_SEARCHKEYS][type];
list.splice(0, 0, value); list.splice(0, 0, value);
list = Array.from(new Set(list)); list = Array.from(new Set(list));
if (list.length > window.siyuan.config.search.limit) { if (list.length > window.siyuan.config.search.limit) {
list.splice(window.siyuan.config.search.limit, list.length - window.siyuan.config.search.limit); list.splice(window.siyuan.config.search.limit, list.length - window.siyuan.config.search.limit);
} }
// new Set 后需重新赋值 // new Set 后需重新赋值
window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS][type] = list; window.siyuan.storage[Constants.LOCAL_SEARCHKEYS][type] = list;
setStorageVal(Constants.LOCAL_SEARCHEKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS]); setStorageVal(Constants.LOCAL_SEARCHKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHKEYS]);
}; };
export const openGlobalSearch = (text: string, replace: boolean) => { export const openGlobalSearch = (text: string, replace: boolean) => {
@ -53,7 +53,7 @@ export const openGlobalSearch = (text: string, replace: boolean) => {
icon: "iconSearch", icon: "iconSearch",
title: window.siyuan.languages.search, title: window.siyuan.languages.search,
callback(tab) { callback(tab) {
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHEDATA]; const localData = window.siyuan.storage[Constants.LOCAL_SEARCHDATA];
const asset = new Search({ const asset = new Search({
tab, tab,
config: { config: {
@ -95,7 +95,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
enableIncludeChild = true; enableIncludeChild = true;
} }
}); });
const data = window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS]; const data = window.siyuan.storage[Constants.LOCAL_SEARCHKEYS];
element.innerHTML = `<div class="fn__flex-column" style="height: 100%;${closeCB ? "border-radius: 4px;overflow: hidden;" : ""}"> element.innerHTML = `<div class="fn__flex-column" style="height: 100%;${closeCB ? "border-radius: 4px;overflow: hidden;" : ""}">
<div class="b3-form__icon search__header"> <div class="b3-form__icon search__header">
<span class="fn__a" id="searchHistoryBtn"> <span class="fn__a" id="searchHistoryBtn">
@ -228,7 +228,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
const documentSelf = document; const documentSelf = document;
const nextElement = dragElement.nextElementSibling as HTMLElement; const nextElement = dragElement.nextElementSibling as HTMLElement;
const previousElement = dragElement.previousElementSibling as HTMLElement; const previousElement = dragElement.previousElementSibling as HTMLElement;
const direction = window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS][closeCB ? "layout" : "layoutTab"] === 1 ? "lr" : "tb"; const direction = window.siyuan.storage[Constants.LOCAL_SEARCHKEYS][closeCB ? "layout" : "layoutTab"] === 1 ? "lr" : "tb";
const x = event[direction === "lr" ? "clientX" : "clientY"]; const x = event[direction === "lr" ? "clientX" : "clientY"];
const previousSize = direction === "lr" ? previousElement.clientWidth : previousElement.clientHeight; const previousSize = direction === "lr" ? previousElement.clientWidth : previousElement.clientHeight;
const nextSize = direction === "lr" ? nextElement.clientWidth : nextElement.clientHeight; const nextSize = direction === "lr" ? nextElement.clientWidth : nextElement.clientHeight;
@ -253,8 +253,8 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
documentSelf.ondragstart = null; documentSelf.ondragstart = null;
documentSelf.onselectstart = null; documentSelf.onselectstart = null;
documentSelf.onselect = null; documentSelf.onselect = null;
window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS][direction === "lr" ? (closeCB ? "col" : "colTab") : (closeCB ? "row" : "rowTab")] = nextElement[direction === "lr" ? "clientWidth" : "clientHeight"] + "px"; window.siyuan.storage[Constants.LOCAL_SEARCHKEYS][direction === "lr" ? (closeCB ? "col" : "colTab") : (closeCB ? "row" : "rowTab")] = nextElement[direction === "lr" ? "clientWidth" : "clientHeight"] + "px";
setStorageVal(Constants.LOCAL_SEARCHEKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS]); setStorageVal(Constants.LOCAL_SEARCHKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHKEYS]);
if (direction === "lr") { if (direction === "lr") {
setPadding(edit.protyle); setPadding(edit.protyle);
} }
@ -405,7 +405,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
event.preventDefault(); event.preventDefault();
break; break;
} else if (target.id === "searchHistoryBtn") { } else if (target.id === "searchHistoryBtn") {
const list = window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS]; const list = window.siyuan.storage[Constants.LOCAL_SEARCHKEYS];
if (!list.keys || list.keys.length === 0) { if (!list.keys || list.keys.length === 0) {
return; return;
} }
@ -425,7 +425,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
event.preventDefault(); event.preventDefault();
return; return;
} else if (target.id === "replaceHistoryBtn") { } else if (target.id === "replaceHistoryBtn") {
const list = window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS]; const list = window.siyuan.storage[Constants.LOCAL_SEARCHKEYS];
if (!list.replaceKeys || list.replaceKeys.length === 0) { if (!list.replaceKeys || list.replaceKeys.length === 0) {
return; return;
} }
@ -714,7 +714,7 @@ const addConfigMoreMenu = async (config: ISearchOption, edit: Protyle, element:
} }
}] }]
}).element); }).element);
const localData = window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS]; const localData = window.siyuan.storage[Constants.LOCAL_SEARCHKEYS];
const isPopover = hasClosestByClassName(element, "b3-dialog__container"); const isPopover = hasClosestByClassName(element, "b3-dialog__container");
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.layout, label: window.siyuan.languages.layout,
@ -737,7 +737,7 @@ const addConfigMoreMenu = async (config: ISearchOption, edit: Protyle, element:
} else { } else {
localData.layoutTab = 0; localData.layoutTab = 0;
} }
setStorageVal(Constants.LOCAL_SEARCHEKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS]); setStorageVal(Constants.LOCAL_SEARCHKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHKEYS]);
} }
}, { }, {
label: window.siyuan.languages.leftRightLayout, label: window.siyuan.languages.leftRightLayout,
@ -757,7 +757,7 @@ const addConfigMoreMenu = async (config: ISearchOption, edit: Protyle, element:
} else { } else {
localData.layoutTab = 1; localData.layoutTab = 1;
} }
setStorageVal(Constants.LOCAL_SEARCHEKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS]); setStorageVal(Constants.LOCAL_SEARCHKEYS, window.siyuan.storage[Constants.LOCAL_SEARCHKEYS]);
} }
}] }]
}).element); }).element);
@ -930,8 +930,8 @@ const updateConfig = (element: Element, item: ISearchOption, config: ISearchOpti
} }
element.querySelector("#searchSyntaxCheck").setAttribute("aria-label", methodTip); element.querySelector("#searchSyntaxCheck").setAttribute("aria-label", methodTip);
Object.assign(config, item); Object.assign(config, item);
window.siyuan.storage[Constants.LOCAL_SEARCHEDATA] = Object.assign({}, config); window.siyuan.storage[Constants.LOCAL_SEARCHDATA] = Object.assign({}, config);
setStorageVal(Constants.LOCAL_SEARCHEDATA, window.siyuan.storage[Constants.LOCAL_SEARCHEDATA]); setStorageVal(Constants.LOCAL_SEARCHDATA, window.siyuan.storage[Constants.LOCAL_SEARCHDATA]);
inputEvent(element, config, undefined, edit); inputEvent(element, config, undefined, edit);
window.siyuan.menus.menu.remove(); window.siyuan.menus.menu.remove();
}; };