This commit is contained in:
Vanessa 2022-12-31 22:14:42 +08:00
parent 7688733364
commit 4ee566cbd9
30 changed files with 153 additions and 163 deletions

View file

@ -424,13 +424,8 @@ export class Asset extends Model {
</div> </div>
</div> <!-- outerContainer --> </div> <!-- outerContainer -->
<div id="printContainer"></div>`; <div id="printContainer"></div>`;
const localPDF = JSON.parse(localStorage.getItem(Constants.LOCAL_PDFTHEME) || "{}"); const localPDF = window.siyuan.storage[Constants.LOCAL_PDFTHEME]
let pdfTheme; const pdfTheme = window.siyuan.config.appearance.mode === 0 ? localPDF.light : localPDF.dark;
if (window.siyuan.config.appearance.mode === 0) {
pdfTheme = localPDF.light || "light";
} else {
pdfTheme = localPDF.dark || "dark";
}
const darkElement = this.element.querySelector("#pdfDark"); const darkElement = this.element.querySelector("#pdfDark");
const lightElement = this.element.querySelector("#pdfLight"); const lightElement = this.element.querySelector("#pdfLight");
if (pdfTheme === "dark") { if (pdfTheme === "dark") {
@ -448,7 +443,6 @@ export class Asset extends Model {
localPDF.dark = "light"; localPDF.dark = "light";
} }
this.element.firstElementChild.classList.remove("pdf__outer--dark"); this.element.firstElementChild.classList.remove("pdf__outer--dark");
localStorage.setItem(Constants.LOCAL_PDFTHEME, JSON.stringify(localPDF));
lightElement.classList.add("toggled"); lightElement.classList.add("toggled");
darkElement.classList.remove("toggled"); darkElement.classList.remove("toggled");
}); });
@ -459,7 +453,6 @@ export class Asset extends Model {
localPDF.dark = "dark"; localPDF.dark = "dark";
} }
this.element.firstElementChild.classList.add("pdf__outer--dark"); this.element.firstElementChild.classList.add("pdf__outer--dark");
localStorage.setItem(Constants.LOCAL_PDFTHEME, JSON.stringify(localPDF));
lightElement.classList.remove("toggled"); lightElement.classList.remove("toggled");
darkElement.classList.add("toggled"); darkElement.classList.add("toggled");
}); });

View file

@ -78,8 +78,8 @@ export const makeCard = (nodeElement: Element[]) => {
focusByRange(range); focusByRange(range);
} }
}); });
dialog.element.setAttribute("data-key", "makeCard") dialog.element.setAttribute("data-key", "makeCard");
dialog.element.style.zIndex = "199" dialog.element.style.zIndex = "199";
dialog.element.addEventListener("click", (event) => { dialog.element.addEventListener("click", (event) => {
let target = event.target as HTMLElement; let target = event.target as HTMLElement;
while (target && !target.isSameNode(dialog.element)) { while (target && !target.isSameNode(dialog.element)) {
@ -224,7 +224,7 @@ const viewCards = (deckID: string, title: string) => {
if (response.data.pageCount > 1) { if (response.data.pageCount > 1) {
nextElement.removeAttribute("disabled"); nextElement.removeAttribute("disabled");
} }
dialog.element.style.zIndex = "200" dialog.element.style.zIndex = "200";
dialog.element.addEventListener("click", (event) => { dialog.element.addEventListener("click", (event) => {
let target = event.target as HTMLElement; let target = event.target as HTMLElement;
while (target && !dialog.element.isSameNode(target)) { while (target && !dialog.element.isSameNode(target)) {

View file

@ -15,19 +15,7 @@ import {isBrowser} from "../util/functions";
export const bazaar = { export const bazaar = {
element: undefined as Element, element: undefined as Element,
genHTML() { genHTML() {
const localSortString = localStorage.getItem(Constants.LOCAL_BAZAAR); const localSort = window.siyuan.storage[Constants.LOCAL_BAZAAR];
let localSort;
if (!localSortString) {
localSort = {
theme: "0",
template: "0",
icon: "0",
widget: "0",
};
localStorage.setItem(Constants.LOCAL_BAZAAR, JSON.stringify(localSort));
} else {
localSort = JSON.parse(localSortString);
}
const loadingHTML = `<div style="height: ${bazaar.element.clientHeight - 72}px;display: flex;align-items: center;justify-content: center;"><img src="/stage/loading-pure.svg"></div>`; const loadingHTML = `<div style="height: ${bazaar.element.clientHeight - 72}px;display: flex;align-items: center;justify-content: center;"><img src="/stage/loading-pure.svg"></div>`;
return `<div class="fn__flex-column" style="height: 100%"> return `<div class="fn__flex-column" style="height: 100%">
<div class="layout-tab-bar fn__flex"> <div class="layout-tab-bar fn__flex">
@ -609,7 +597,7 @@ export const bazaar = {
}); });
} else { } else {
// sort // sort
const localSort = JSON.parse(localStorage.getItem(Constants.LOCAL_BAZAAR)); const localSort = window.siyuan.storage[Constants.LOCAL_BAZAAR];
const panelElement = selectElement.parentElement.parentElement; const panelElement = selectElement.parentElement.parentElement;
let html = ""; let html = "";
if (selectElement.value === "0") { // 更新时间降序 if (selectElement.value === "0") { // 更新时间降序
@ -638,7 +626,6 @@ export const bazaar = {
}); });
} }
localSort[selectElement.parentElement.parentElement.getAttribute("data-type")] = selectElement.value; localSort[selectElement.parentElement.parentElement.getAttribute("data-type")] = selectElement.value;
localStorage.setItem(Constants.LOCAL_BAZAAR, JSON.stringify(localSort));
panelElement.querySelector(".b3-cards").innerHTML = html; panelElement.querySelector(".b3-cards").innerHTML = html;
} }
}); });
@ -667,7 +654,7 @@ export const bazaar = {
bazaar.data[bazaarType] = response.data.packages; bazaar.data[bazaarType] = response.data.packages;
element.innerHTML = `<div class="b3-cards">${html}</div>`; element.innerHTML = `<div class="b3-cards">${html}</div>`;
const localSort = JSON.parse(localStorage.getItem(Constants.LOCAL_BAZAAR)); const localSort = window.siyuan.storage[Constants.LOCAL_BAZAAR];
if (localSort[bazaarType.replace("s", "")] === "1") { if (localSort[bazaarType.replace("s", "")] === "1") {
html = ""; html = "";
Array.from(element.querySelectorAll(".b3-card")).sort((a, b) => { Array.from(element.querySelectorAll(".b3-card")).sort((a, b) => {

View file

@ -59,11 +59,11 @@ export abstract class Constants {
// localstorage // localstorage
public static readonly LOCAL_SEARCHEDATA = "local-searchedata"; public static readonly LOCAL_SEARCHEDATA = "local-searchedata";
public static readonly LOCAL_SEARCHEKEYS = "local-searchekeys"; // "keys", "col", "row", "replaceKeys", "layout" public static readonly LOCAL_SEARCHEKEYS = "local-searchekeys";
public static readonly LOCAL_DOCINFO = "local-docinfo"; // only mobile public static readonly LOCAL_DOCINFO = "local-docinfo"; // only mobile
public static readonly LOCAL_DAILYNOTEID = "local-dailynoteid"; public static readonly LOCAL_DAILYNOTEID = "local-dailynoteid"; // string
public static readonly LOCAL_HISTORYNOTEID = "local-historynoteid"; public static readonly LOCAL_HISTORYNOTEID = "local-historynoteid"; // string
public static readonly LOCAL_CODELANG = "local-codelang"; public static readonly LOCAL_CODELANG = "local-codelang"; // string
public static readonly LOCAL_FONTSTYLES = "local-fontstyles"; public static readonly LOCAL_FONTSTYLES = "local-fontstyles";
public static readonly LOCAL_EXPORTPDF = "local-exportpdf"; public static readonly LOCAL_EXPORTPDF = "local-exportpdf";
public static readonly LOCAL_EXPORTWORD = "local-exportword"; public static readonly LOCAL_EXPORTWORD = "local-exportword";

View file

@ -25,7 +25,7 @@ const renderDoc = (element: HTMLElement, currentPage: number) => {
const opElement = element.querySelector('.b3-select[data-type="opselect"]') as HTMLSelectElement; const opElement = element.querySelector('.b3-select[data-type="opselect"]') as HTMLSelectElement;
const typeElement = element.querySelector('.b3-select[data-type="typeselect"]') as HTMLSelectElement; const typeElement = element.querySelector('.b3-select[data-type="typeselect"]') as HTMLSelectElement;
const notebookElement = element.querySelector('.b3-select[data-type="notebookselect"]') as HTMLSelectElement; const notebookElement = element.querySelector('.b3-select[data-type="notebookselect"]') as HTMLSelectElement;
localStorage.setItem(Constants.LOCAL_HISTORYNOTEID, notebookElement.value); window.siyuan.storage[Constants.LOCAL_HISTORYNOTEID] = notebookElement.value;
const docElement = element.querySelector('.history__text[data-type="docPanel"]'); const docElement = element.querySelector('.history__text[data-type="docPanel"]');
const assetElement = element.querySelector('.history__text[data-type="assetPanel"]'); const assetElement = element.querySelector('.history__text[data-type="assetPanel"]');
const mdElement = element.querySelector('.history__text[data-type="mdPanel"]') as HTMLTextAreaElement; const mdElement = element.querySelector('.history__text[data-type="mdPanel"]') as HTMLTextAreaElement;
@ -211,7 +211,7 @@ export const openHistory = () => {
return; return;
} }
const currentNotebookId = localStorage.getItem(Constants.LOCAL_HISTORYNOTEID); const currentNotebookId = window.siyuan.storage[Constants.LOCAL_HISTORYNOTEID];
let notebookSelectHTML = ""; let notebookSelectHTML = "";
window.siyuan.notebooks.forEach((item) => { window.siyuan.notebooks.forEach((item) => {
if (!item.closed) { if (!item.closed) {

View file

@ -122,9 +122,9 @@ class App {
}), }),
menus: new Menus() menus: new Menus()
}; };
setLocalStorage();
fetchPost("/api/system/getConf", {}, response => { fetchPost("/api/system/getConf", {}, response => {
window.siyuan.config = response.data.conf; window.siyuan.config = response.data.conf;
setLocalStorage();
fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages) => { fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages) => {
window.siyuan.languages = lauguages; window.siyuan.languages = lauguages;
bootSync(); bootSync();

View file

@ -455,10 +455,10 @@ export const zoomOut = (protyle: IProtyle, id: string, focusId?: string, isPushB
} }
} }
if (window.siyuan.mobileEditor) { if (window.siyuan.mobileEditor) {
localStorage.setItem(Constants.LOCAL_DOCINFO, JSON.stringify({ window.siyuan.storage[Constants.LOCAL_DOCINFO] = {
id, id,
action: id === protyle.block.rootID ? [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT] : [Constants.CB_GET_ALL] action: id === protyle.block.rootID ? [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT] : [Constants.CB_GET_ALL]
})); };
if (isPushBack) { if (isPushBack) {
pushBack(); pushBack();
} }

View file

@ -14,7 +14,7 @@ import {hideElements} from "../protyle/ui/hideElements";
import {pushBack} from "./util/MobileBackFoward"; import {pushBack} from "./util/MobileBackFoward";
export const openMobileFileById = (id: string, action = [Constants.CB_GET_HL]) => { export const openMobileFileById = (id: string, action = [Constants.CB_GET_HL]) => {
localStorage.setItem(Constants.LOCAL_DOCINFO, JSON.stringify({id, action})); window.siyuan.storage[Constants.LOCAL_DOCINFO] = {id, action};
if (window.siyuan.mobileEditor) { if (window.siyuan.mobileEditor) {
hideElements(["toolbar", "hint", "util"], window.siyuan.mobileEditor.protyle); hideElements(["toolbar", "hint", "util"], window.siyuan.mobileEditor.protyle);
if (window.siyuan.mobileEditor.protyle.contentElement.classList.contains("fn__none")) { if (window.siyuan.mobileEditor.protyle.contentElement.classList.contains("fn__none")) {

View file

@ -44,10 +44,10 @@ class App {
window.siyuan.menus.menu.remove(); window.siyuan.menus.menu.remove();
} }
}); });
setLocalStorage();
fetchPost("/api/system/getConf", {}, confResponse => { fetchPost("/api/system/getConf", {}, confResponse => {
confResponse.data.conf.keymap = Constants.SIYUAN_KEYMAP; confResponse.data.conf.keymap = Constants.SIYUAN_KEYMAP;
window.siyuan.config = confResponse.data.conf; window.siyuan.config = confResponse.data.conf;
setLocalStorage();
fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages) => { fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages) => {
window.siyuan.languages = lauguages; window.siyuan.languages = lauguages;
document.title = window.siyuan.languages.siyuanNote; document.title = window.siyuan.languages.siyuanNote;

View file

@ -12,10 +12,10 @@ const forwardStack: IBackStack[] = [];
const focusStack = (backStack: IBackStack) => { const focusStack = (backStack: IBackStack) => {
const protyle = window.siyuan.mobileEditor.protyle; const protyle = window.siyuan.mobileEditor.protyle;
localStorage.setItem(Constants.LOCAL_DOCINFO, JSON.stringify({ window.siyuan.storage[Constants.LOCAL_DOCINFO] = {
id: backStack.id, id: backStack.id,
action: backStack.callback, action: backStack.callback,
})); };
hideElements(["toolbar", "hint", "util"], window.siyuan.mobileEditor.protyle); hideElements(["toolbar", "hint", "util"], window.siyuan.mobileEditor.protyle);
if (protyle.contentElement.classList.contains("fn__none")) { if (protyle.contentElement.classList.contains("fn__none")) {
setEditMode(protyle, "wysiwyg"); setEditMode(protyle, "wysiwyg");

View file

@ -127,7 +127,7 @@ export const initFramework = () => {
}); });
initEditorName(); initEditorName();
if (getOpenNotebookCount() > 0) { if (getOpenNotebookCount() > 0) {
const localDoc = JSON.parse(localStorage.getItem(Constants.LOCAL_DOCINFO) || '{"id": ""}'); const localDoc = window.siyuan.storage[Constants.LOCAL_DOCINFO];
fetchPost("/api/block/checkBlockExist", {id: localDoc.id}, existResponse => { fetchPost("/api/block/checkBlockExist", {id: localDoc.id}, existResponse => {
if (existResponse.data) { if (existResponse.data) {
openMobileFileById(localDoc.id, localDoc.action); openMobileFileById(localDoc.id, localDoc.action);

View file

@ -1,5 +1,5 @@
import {fetchPost} from "../../util/fetch"; import {fetchPost} from "../../util/fetch";
import {getEventName, openByMobile, writeText} from "../../protyle/util/compatibility"; import {exportLocalStorage, getEventName, openByMobile, writeText} from "../../protyle/util/compatibility";
import {popSearch} from "./search"; import {popSearch} from "./search";
import {initAppearance} from "../settings/appearance"; import {initAppearance} from "../settings/appearance";
import {closePanel} from "./closePanel"; import {closePanel} from "./closePanel";
@ -172,7 +172,9 @@ ${accountHTML}
event.stopPropagation(); event.stopPropagation();
break; break;
} else if (target.id === "menuSafeQuit") { } else if (target.id === "menuSafeQuit") {
exportLocalStorage(() => {
exitSiYuan(); exitSiYuan();
});
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
break; break;
@ -439,9 +441,11 @@ ${accountHTML}
event.stopPropagation(); event.stopPropagation();
break; break;
} else if (target.id === "menuLock") { } else if (target.id === "menuLock") {
exportLocalStorage(() => {
fetchPost("/api/system/logoutAuth", {}, () => { fetchPost("/api/system/logoutAuth", {}, () => {
window.location.href = "/"; window.location.href = "/";
}); });
});
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
break; break;
@ -457,6 +461,7 @@ ${accountHTML}
event.stopPropagation(); event.stopPropagation();
break; break;
} else if (target.id === "menuSyncNow") { } else if (target.id === "menuSyncNow") {
exportLocalStorage();
syncGuide(); syncGuide();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();

View file

@ -37,17 +37,14 @@ export const toolbarSearchEvent = () => {
onRecentBlocks(response.data.blocks, response.data.matchedRootCount,response.data.matchedBlockCount); onRecentBlocks(response.data.blocks, response.data.matchedRootCount,response.data.matchedBlockCount);
}); });
} }
const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEDATA) || "{}"); window.siyuan.storage[Constants.LOCAL_SEARCHEDATA].k = inputElement.value;
localData.k = inputElement.value;
localStorage.setItem(Constants.LOCAL_SEARCHEDATA, JSON.stringify(localData));
}, 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();
const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEDATA) || "{}"); inputElement.value = window.siyuan.storage[Constants.LOCAL_SEARCHEDATA].k;
inputElement.value = localData.k || "";
inputElement.addEventListener("compositionend", (event: InputEvent) => { inputElement.addEventListener("compositionend", (event: InputEvent) => {
if (event && event.isComposing) { if (event && event.isComposing) {
return; return;

View file

@ -26,7 +26,7 @@ export const saveExport = (option: { type: string, id: string }) => {
renderPDF(option.id); renderPDF(option.id);
} }
} else if (option.type === "word") { } else if (option.type === "word") {
const localData = localStorage.getItem(Constants.LOCAL_EXPORTWORD); const localData = window.siyuan.storage[Constants.LOCAL_EXPORTWORD];
const wordDialog = new Dialog({ const wordDialog = new Dialog({
title: "Word " + window.siyuan.languages.config, title: "Word " + window.siyuan.languages.config,
content: `<div class="b3-dialog__content"> content: `<div class="b3-dialog__content">
@ -35,14 +35,14 @@ export const saveExport = (option: { type: string, id: string }) => {
${window.siyuan.languages.exportPDF4} ${window.siyuan.languages.exportPDF4}
</div> </div>
<span class="fn__space"></span> <span class="fn__space"></span>
<input id="removeAssets" class="b3-switch" type="checkbox" ${localData === "true" ? "checked" : ""}> <input id="removeAssets" class="b3-switch" type="checkbox" ${localData.removeAssets ? "checked" : ""}>
</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.exportPDF6} ${window.siyuan.languages.exportPDF6}
</div> </div>
<span class="fn__space"></span> <span class="fn__space"></span>
<input id="mergeSubdocs" class="b3-switch" type="checkbox" ${localData === "true" ? "checked" : ""}> <input id="mergeSubdocs" class="b3-switch" type="checkbox" ${localData.mergeSubdocs ? "checked" : ""}>
</label> </label>
</div> </div>
<div class="b3-dialog__action"> <div class="b3-dialog__action">
@ -58,7 +58,6 @@ export const saveExport = (option: { type: string, id: string }) => {
btnsElement[1].addEventListener("click", () => { btnsElement[1].addEventListener("click", () => {
const removeAssets = (wordDialog.element.querySelector("#removeAssets") as HTMLInputElement).checked; const removeAssets = (wordDialog.element.querySelector("#removeAssets") as HTMLInputElement).checked;
const mergeSubdocs = (wordDialog.element.querySelector("#mergeSubdocs") as HTMLInputElement).checked; const mergeSubdocs = (wordDialog.element.querySelector("#mergeSubdocs") as HTMLInputElement).checked;
localStorage.setItem(Constants.LOCAL_EXPORTWORD, JSON.stringify({removeAssets, mergeSubdocs}));
getExportPath(option, removeAssets, mergeSubdocs); getExportPath(option, removeAssets, mergeSubdocs);
wordDialog.destroy(); wordDialog.destroy();
}); });
@ -71,15 +70,7 @@ export const saveExport = (option: { type: string, id: string }) => {
/// #if !BROWSER /// #if !BROWSER
let originalZoomFactor = 1; let originalZoomFactor = 1;
const renderPDF = (id: string) => { const renderPDF = (id: string) => {
const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_EXPORTPDF) || JSON.stringify({ const localData = window.siyuan.storage[Constants.LOCAL_EXPORTPDF];
landscape: false,
marginType: "0",
scale: 1,
pageSize: "A4",
removeAssets: true,
keepFold: false,
mergeSubdocs: false,
}));
const servePath = window.location.protocol + "//" + window.location.host; const servePath = window.location.protocol + "//" + window.location.host;
const isDefault = (window.siyuan.config.appearance.mode === 1 && window.siyuan.config.appearance.themeDark === "midnight") || (window.siyuan.config.appearance.mode === 0 && window.siyuan.config.appearance.themeLight === "daylight"); const isDefault = (window.siyuan.config.appearance.mode === 1 && window.siyuan.config.appearance.themeDark === "midnight") || (window.siyuan.config.appearance.mode === 0 && window.siyuan.config.appearance.themeLight === "daylight");
let themeStyle = ""; let themeStyle = "";

View file

@ -591,7 +591,7 @@ export class Gutter {
click() { click() {
let html = ""; let html = "";
selectsElement.forEach(item => { selectsElement.forEach(item => {
item.querySelectorAll('[spellcheck]').forEach(editItem => { item.querySelectorAll("[spellcheck]").forEach(editItem => {
const cloneNode = editItem.cloneNode(true) as HTMLElement; const cloneNode = editItem.cloneNode(true) as HTMLElement;
cloneNode.querySelectorAll('[data-type="backslash"]').forEach(slashItem => { cloneNode.querySelectorAll('[data-type="backslash"]').forEach(slashItem => {
slashItem.firstElementChild.remove(); slashItem.firstElementChild.remove();
@ -980,7 +980,7 @@ export class Gutter {
accelerator: window.siyuan.config.keymap.editor.general.copyPlainText.custom, accelerator: window.siyuan.config.keymap.editor.general.copyPlainText.custom,
click() { click() {
let text = ""; let text = "";
nodeElement.querySelectorAll('[spellcheck]').forEach(item => { nodeElement.querySelectorAll("[spellcheck]").forEach(item => {
const cloneNode = item.cloneNode(true) as HTMLElement; const cloneNode = item.cloneNode(true) as HTMLElement;
cloneNode.querySelectorAll('[data-type="backslash"]').forEach(slashItem => { cloneNode.querySelectorAll('[data-type="backslash"]').forEach(slashItem => {
slashItem.firstElementChild.remove(); slashItem.firstElementChild.remove();

View file

@ -556,7 +556,7 @@ ${unicode2Emoji(emoji.unicode, true)}</button>`;
} }
let textContent = value; let textContent = value;
if (value === "```") { if (value === "```") {
textContent = value + (localStorage.getItem(Constants.LOCAL_CODELANG) || "") + Lute.Caret + "\n```"; textContent = value + window.siyuan.storage[Constants.LOCAL_CODELANG] + Lute.Caret + "\n```";
} }
const editableElement = getContenteditableElement(nodeElement); const editableElement = getContenteditableElement(nodeElement);
if (value === "![]()") { // https://github.com/siyuan-note/siyuan/issues/4586 1 if (value === "![]()") { // https://github.com/siyuan-note/siyuan/issues/4586 1

View file

@ -9,7 +9,7 @@ export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN) =
let isPreview = false; let isPreview = false;
if (element.classList.contains("code-block")) { if (element.classList.contains("code-block")) {
// 编辑器内代码块编辑渲染 // 编辑器内代码块编辑渲染
codeElements = element.querySelectorAll('[spellcheck]'); codeElements = element.querySelectorAll("[spellcheck]");
} else { } else {
if (element.classList.contains("item__readme")) { if (element.classList.contains("item__readme")) {
// bazaar reademe // bazaar reademe
@ -22,7 +22,7 @@ export const highlightRender = (element: Element, cdn = Constants.PROTYLE_CDN) =
codeElements = element.querySelectorAll(".code-block code"); codeElements = element.querySelectorAll(".code-block code");
isPreview = true; isPreview = true;
} else { } else {
codeElements = element.querySelectorAll('.code-block [spellcheck]'); codeElements = element.querySelectorAll(".code-block [spellcheck]");
} }
} }
if (codeElements.length === 0) { if (codeElements.length === 0) {

View file

@ -46,7 +46,7 @@ export const fontMenu = (protyle: IProtyle) => {
const element = document.createElement("div"); const element = document.createElement("div");
element.classList.add("protyle-font"); element.classList.add("protyle-font");
let lastColorHTML = ""; let lastColorHTML = "";
const lastFonts = JSON.parse(localStorage.getItem(Constants.LOCAL_FONTSTYLES) || "[]"); const lastFonts = window.siyuan.storage[Constants.LOCAL_FONTSTYLES];
if (lastFonts.length > 0) { if (lastFonts.length > 0) {
lastColorHTML = `<div style="margin-bottom: 2px" class="fn__flex"> lastColorHTML = `<div style="margin-bottom: 2px" class="fn__flex">
${window.siyuan.languages.lastUsed}<span class="fn__space"></span> ${window.siyuan.languages.lastUsed}<span class="fn__space"></span>
@ -136,14 +136,13 @@ export const fontMenu = (protyle: IProtyle) => {
}; };
export const fontEvent = (protyle: IProtyle, type?: string, color?: string) => { export const fontEvent = (protyle: IProtyle, type?: string, color?: string) => {
let localFontStyles = JSON.parse(localStorage.getItem(Constants.LOCAL_FONTSTYLES) || "[]"); let localFontStyles = window.siyuan.storage[Constants.LOCAL_FONTSTYLES];
if (type) { if (type) {
localFontStyles.splice(0, 0, `${type}${Constants.ZWSP}${color}`); localFontStyles.splice(0, 0, `${type}${Constants.ZWSP}${color}`);
localFontStyles = [...new Set(localFontStyles)]; localFontStyles = [...new Set(localFontStyles)];
if (localFontStyles.length > 8) { if (localFontStyles.length > 8) {
localFontStyles.splice(7, 1); localFontStyles.splice(7, 1);
} }
localStorage.setItem(Constants.LOCAL_FONTSTYLES, JSON.stringify(localFontStyles));
} else { } else {
if (localFontStyles.length === 0) { if (localFontStyles.length === 0) {
type = "color"; type = "color";

View file

@ -1162,7 +1162,7 @@ export class Toolbar {
if (event.key === "Enter") { if (event.key === "Enter") {
const activeText = this.subElement.querySelector(".b3-list-item--focus").textContent; const activeText = this.subElement.querySelector(".b3-list-item--focus").textContent;
languageElement.textContent = activeText === window.siyuan.languages.clear ? "" : activeText; languageElement.textContent = activeText === window.siyuan.languages.clear ? "" : activeText;
localStorage.setItem(Constants.LOCAL_CODELANG, languageElement.textContent); window.siyuan.storage[Constants.LOCAL_CODELANG] = languageElement.textContent;
const editElement = getContenteditableElement(nodeElement); const editElement = getContenteditableElement(nodeElement);
const lineNumber = nodeElement.getAttribute("linenumber"); const lineNumber = nodeElement.getAttribute("linenumber");
if (lineNumber === "true" || (lineNumber !== "false" && window.siyuan.config.editor.codeSyntaxHighlightLineNum)) { if (lineNumber === "true" || (lineNumber !== "false" && window.siyuan.config.editor.codeSyntaxHighlightLineNum)) {
@ -1226,7 +1226,7 @@ export class Toolbar {
return; return;
} }
languageElement.textContent = listElement.textContent === window.siyuan.languages.clear ? "" : listElement.textContent; languageElement.textContent = listElement.textContent === window.siyuan.languages.clear ? "" : listElement.textContent;
localStorage.setItem(Constants.LOCAL_CODELANG, languageElement.textContent); window.siyuan.storage[Constants.LOCAL_CODELANG] = languageElement.textContent;
const nodeElement = hasClosestBlock(languageElement); const nodeElement = hasClosestBlock(languageElement);
if (nodeElement) { if (nodeElement) {
const editElement = getContenteditableElement(nodeElement); const editElement = getContenteditableElement(nodeElement);

View file

@ -141,21 +141,79 @@ export const hotKey2Electron = (key: string) => {
export const setLocalStorage = () => { export const setLocalStorage = () => {
fetchPost("/api/storage/getLocalStorage", undefined, (response) => { fetchPost("/api/storage/getLocalStorage", undefined, (response) => {
if (response.data) { window.siyuan.storage = response.data;
localStorage.clear(); // 历史数据迁移
Object.keys(response.data).forEach(item => { const defaultStorage: any = {};
if (item !== "setItem" && item !== "removeItem") { defaultStorage[Constants.LOCAL_SEARCHEKEYS] = {
localStorage.setItem(item, response.data[item]); keys: [],
replaceKeys: [],
col: "",
row: "",
layout: 0
};
defaultStorage[Constants.LOCAL_PDFTHEME] = {light: "light", dark: "dark"};
defaultStorage[Constants.LOCAL_BAZAAR] = {
theme: "0",
template: "0",
icon: "0",
widget: "0",
};
defaultStorage[Constants.LOCAL_EXPORTWORD] = {removeAssets: false, mergeSubdocs: false};
defaultStorage[Constants.LOCAL_EXPORTPDF] = {
landscape: false,
marginType: "0",
scale: 1,
pageSize: "A4",
removeAssets: true,
keepFold: false,
mergeSubdocs: false,
};
defaultStorage[Constants.LOCAL_DOCINFO] = {
id: "",
action: []
};
defaultStorage[Constants.LOCAL_FONTSTYLES] = [];
defaultStorage[Constants.LOCAL_SEARCHEDATA] = {
sort: 0,
group: 0,
hasReplace: false,
method: 0,
hPath: "",
idPath: [],
k: "",
r: "",
types: {
document: window.siyuan.config.search.document,
heading: window.siyuan.config.search.heading,
list: window.siyuan.config.search.list,
listItem: window.siyuan.config.search.listItem,
codeBlock: window.siyuan.config.search.codeBlock,
htmlBlock: window.siyuan.config.search.htmlBlock,
mathBlock: window.siyuan.config.search.mathBlock,
table: window.siyuan.config.search.table,
blockquote: window.siyuan.config.search.blockquote,
superBlock: window.siyuan.config.search.superBlock,
paragraph: window.siyuan.config.search.paragraph,
}
};
[Constants.LOCAL_SEARCHEKEYS, Constants.LOCAL_PDFTHEME, Constants.LOCAL_BAZAAR, Constants.LOCAL_EXPORTWORD,
Constants.LOCAL_EXPORTPDF, Constants.LOCAL_DOCINFO, Constants.LOCAL_FONTSTYLES, Constants.LOCAL_SEARCHEDATA].forEach((key) => {
if (typeof response.data[key] === "string") {
try {
window.siyuan.storage[key] = Object.assign(defaultStorage[key], JSON.parse(response.data[key]));
} catch (e) {
window.siyuan.storage[key] = defaultStorage[key];
}
} else if (typeof response.data[key] === "undefined") {
window.siyuan.storage[key] = defaultStorage[key];
} }
}); });
} else {
exportLocalStorage();
}
}); });
}; };
export const exportLocalStorage = (cb?: () => void) => { export const exportLocalStorage = (cb?: () => void) => {
fetchPost("/api/storage/setLocalStorage", {val: localStorage}, () => { fetchPost("/api/storage/setLocalStorage", {val: window.siyuan.storage}, () => {
if (cb) { if (cb) {
cb(); cb();
} }

View file

@ -36,7 +36,7 @@ export const processPasteCode = (html: string, text: string) => {
if (isCode) { if (isCode) {
const code = text || html; const code = text || html;
if (/\n/.test(code) || pres.length === 1) { if (/\n/.test(code) || pres.length === 1) {
return `<div data-type="NodeCodeBlock" class="code-block" data-node-id="${Lute.NewNodeID()}"><div class="protyle-action"><span class="protyle-action--first protyle-action__language" contenteditable="false">${localStorage.getItem(Constants.LOCAL_CODELANG) || ""}</span><span class="fn__flex-1"></span><span class="protyle-icon protyle-icon--first protyle-action__copy"><svg><use xlink:href="#iconCopy"></use></svg></span><span class="protyle-icon protyle-icon--last protyle-action__menu"><svg><use xlink:href="#iconMore"></use></svg></span></div><div contenteditable="true" spellcheck="${window.siyuan.config.editor.spellcheck}">${code.replace(/&/g, "&amp;").replace(/</g, "&lt;")}<wbr></div><div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div></div>`; return `<div data-type="NodeCodeBlock" class="code-block" data-node-id="${Lute.NewNodeID()}"><div class="protyle-action"><span class="protyle-action--first protyle-action__language" contenteditable="false">${window.siyuan.storage[Constants.LOCAL_CODELANG]}</span><span class="fn__flex-1"></span><span class="protyle-icon protyle-icon--first protyle-action__copy"><svg><use xlink:href="#iconCopy"></use></svg></span><span class="protyle-icon protyle-icon--last protyle-action__menu"><svg><use xlink:href="#iconMore"></use></svg></span></div><div contenteditable="true" spellcheck="${window.siyuan.config.editor.spellcheck}">${code.replace(/&/g, "&amp;").replace(/</g, "&lt;")}<wbr></div><div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div></div>`;
} else { } else {
return code; return code;
} }

View file

@ -244,10 +244,10 @@ export const enter = (blockElement: HTMLElement, range: Range, protyle: IProtyle
blockElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${blockElement.getAttribute("data-node-id")}"]`); blockElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${blockElement.getAttribute("data-node-id")}"]`);
const languageElement = blockElement.querySelector(".protyle-action__language"); const languageElement = blockElement.querySelector(".protyle-action__language");
if (languageElement) { if (languageElement) {
if (localStorage.getItem(Constants.LOCAL_CODELANG) && languageElement.textContent === "") { if (window.siyuan.storage[Constants.LOCAL_CODELANG] && languageElement.textContent === "") {
languageElement.textContent = localStorage.getItem(Constants.LOCAL_CODELANG); languageElement.textContent = window.siyuan.storage[Constants.LOCAL_CODELANG];
} else { } else {
localStorage.setItem(Constants.LOCAL_CODELANG, languageElement.textContent); window.siyuan.storage[Constants.LOCAL_CODELANG] = languageElement.textContent;
} }
highlightRender(blockElement); highlightRender(blockElement);
} else { } else {

View file

@ -170,8 +170,8 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range:
if (realType === "NodeCodeBlock") { if (realType === "NodeCodeBlock") {
const languageElement = realElement.querySelector(".protyle-action__language"); const languageElement = realElement.querySelector(".protyle-action__language");
if (languageElement) { if (languageElement) {
if (localStorage.getItem(Constants.LOCAL_CODELANG) && languageElement.textContent === "") { if (window.siyuan.storage[Constants.LOCAL_CODELANG] && languageElement.textContent === "") {
languageElement.textContent = localStorage.getItem(Constants.LOCAL_CODELANG); languageElement.textContent = window.siyuan.storage[Constants.LOCAL_CODELANG];
} }
highlightRender(realElement); highlightRender(realElement);
} else if (tempElement.content.childElementCount === 1) { } else if (tempElement.content.childElementCount === 1) {

View file

@ -1248,7 +1248,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
const id = nodeElement.getAttribute("data-node-id"); const id = nodeElement.getAttribute("data-node-id");
const html = nodeElement.outerHTML; const html = nodeElement.outerHTML;
const editElement = getContenteditableElement(nodeElement); const editElement = getContenteditableElement(nodeElement);
editElement.innerHTML = "```" + (localStorage.getItem(Constants.LOCAL_CODELANG) || "") + "\n" + editElement.textContent + "<wbr>\n```"; editElement.innerHTML = "```" + window.siyuan.storage[Constants.LOCAL_CODELANG] + "\n" + editElement.textContent + "<wbr>\n```";
const newHTML = protyle.lute.SpinBlockDOM(nodeElement.outerHTML); const newHTML = protyle.lute.SpinBlockDOM(nodeElement.outerHTML);
nodeElement.outerHTML = newHTML; nodeElement.outerHTML = newHTML;
const newNodeElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`); const newNodeElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`);

View file

@ -45,22 +45,7 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
if (exitDialog) { if (exitDialog) {
return; return;
} }
const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEDATA) || "{}"); const localData = window.siyuan.storage[Constants.LOCAL_SEARCHEDATA];
if (!localData.types) {
localData.types = {
document: window.siyuan.config.search.document,
heading: window.siyuan.config.search.heading,
list: window.siyuan.config.search.list,
listItem: window.siyuan.config.search.listItem,
codeBlock: window.siyuan.config.search.codeBlock,
htmlBlock: window.siyuan.config.search.htmlBlock,
mathBlock: window.siyuan.config.search.mathBlock,
table: window.siyuan.config.search.table,
blockquote: window.siyuan.config.search.blockquote,
superBlock: window.siyuan.config.search.superBlock,
paragraph: window.siyuan.config.search.paragraph,
};
}
let hPath = ""; let hPath = "";
let idPath: string[] = []; let idPath: string[] = [];
if (notebookId) { if (notebookId) {
@ -75,8 +60,8 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
idPath[0] = pathPosix().join(idPath[0], searchPath); idPath[0] = pathPosix().join(idPath[0], searchPath);
} }
} else if (window.siyuan.config.keymap.general.globalSearch.custom === hotkey) { } else if (window.siyuan.config.keymap.general.globalSearch.custom === hotkey) {
hPath = localData.hPath || ""; hPath = localData.hPath;
idPath = localData.idPath || []; idPath = localData.idPath;
// 历史原因2.5.2 之前为 string https://github.com/siyuan-note/siyuan/issues/6902 // 历史原因2.5.2 之前为 string https://github.com/siyuan-note/siyuan/issues/6902
if (typeof idPath === "string") { if (typeof idPath === "string") {
idPath = [idPath]; idPath = [idPath];
@ -103,13 +88,13 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
dialog.element.setAttribute("data-key", hotkey); dialog.element.setAttribute("data-key", hotkey);
const edit = genSearch({ const edit = genSearch({
k: key || localData.k, k: key || localData.k,
r: localData.r || "", r: localData.r,
hasReplace: hotkey === window.siyuan.config.keymap.general.replace.custom, hasReplace: hotkey === window.siyuan.config.keymap.general.replace.custom,
method: localData.method || 0, method: localData.method,
hPath, hPath,
idPath, idPath,
group: localData.group || 0, group: localData.group,
sort: localData.sort || 0, sort: localData.sort,
types: localData.types types: localData.types
}, dialog.element.querySelector(".b3-dialog__container").lastElementChild, () => { }, dialog.element.querySelector(".b3-dialog__container").lastElementChild, () => {
dialog.destroy(); dialog.destroy();

View file

@ -20,15 +20,12 @@ import {Dialog} from "../dialog";
import {hasClosestByClassName} from "../protyle/util/hasClosest"; import {hasClosestByClassName} from "../protyle/util/hasClosest";
const saveKeyList = (type: "keys" | "replaceKeys", value: string) => { const saveKeyList = (type: "keys" | "replaceKeys", value: string) => {
const searchKeys = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEKEYS) || "{}"); let list: string[] = window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS][type];
let list: string[] = 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);
} }
searchKeys[type] = list;
localStorage.setItem(Constants.LOCAL_SEARCHEKEYS, JSON.stringify(searchKeys));
}; };
export const openGlobalSearch = (text: string, replace: boolean) => { export const openGlobalSearch = (text: string, replace: boolean) => {
@ -52,33 +49,18 @@ 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 = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEDATA) || "{}"); const localData = window.siyuan.storage[Constants.LOCAL_SEARCHEDATA];
if (!localData.types) {
localData.types = {
document: window.siyuan.config.search.document,
heading: window.siyuan.config.search.heading,
list: window.siyuan.config.search.list,
listItem: window.siyuan.config.search.listItem,
codeBlock: window.siyuan.config.search.codeBlock,
htmlBlock: window.siyuan.config.search.htmlBlock,
mathBlock: window.siyuan.config.search.mathBlock,
table: window.siyuan.config.search.table,
blockquote: window.siyuan.config.search.blockquote,
superBlock: window.siyuan.config.search.superBlock,
paragraph: window.siyuan.config.search.paragraph,
};
}
const asset = new Search({ const asset = new Search({
tab, tab,
config: { config: {
k: text, k: text,
r: "", r: "",
hasReplace: false, hasReplace: false,
method: localData.method || 0, method: localData.method,
hPath: "", hPath: "",
idPath: [], idPath: [],
group: localData.group || 0, group: localData.group,
sort: localData.sort || 0, sort: localData.sort,
types: localData.types types: localData.types
} }
}); });
@ -109,7 +91,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
enableIncludeChild = true; enableIncludeChild = true;
} }
}); });
const data = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEKEYS) || "{}"); const data = window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS];
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">
@ -225,7 +207,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 = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEKEYS) || "{}").layout === 1 ? "lr" : "tb"; const direction = window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS].layout === 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;
@ -250,9 +232,7 @@ 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;
const json = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEKEYS) || "{}"); window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS][direction === "lr" ? "col" : "row"] = nextElement[direction === "lr" ? "clientWidth" : "clientHeight"] + "px";
json[direction === "lr" ? "col" : "row"] = nextElement[direction === "lr" ? "clientWidth" : "clientHeight"] + "px";
localStorage.setItem(Constants.LOCAL_SEARCHEKEYS, JSON.stringify(json));
if (direction === "lr") { if (direction === "lr") {
setPadding(edit.protyle); setPadding(edit.protyle);
} }
@ -403,7 +383,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 = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEKEYS) || "{}"); const list = window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS];
if (!list.keys || list.keys.length === 0) { if (!list.keys || list.keys.length === 0) {
return; return;
} }
@ -423,7 +403,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 = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEKEYS) || "{}"); const list = window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS];
if (!list.replaceKeys || list.replaceKeys.length === 0) { if (!list.replaceKeys || list.replaceKeys.length === 0) {
return; return;
} }
@ -704,10 +684,7 @@ const addConfigMoreMenu = async (config: ISearchOption, edit: Protyle, element:
} }
}] }]
}).element); }).element);
const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEKEYS) || "{}"); const localData = window.siyuan.storage[Constants.LOCAL_SEARCHEKEYS];
if (typeof localData.layout === "undefined") {
localData.layout = 0;
}
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.layout, label: window.siyuan.languages.layout,
type: "submenu", type: "submenu",
@ -725,7 +702,6 @@ const addConfigMoreMenu = async (config: ISearchOption, edit: Protyle, element:
} }
setPadding(edit.protyle); setPadding(edit.protyle);
localData.layout = 0; localData.layout = 0;
localStorage.setItem(Constants.LOCAL_SEARCHEKEYS, JSON.stringify(localData));
} }
}, { }, {
label: window.siyuan.languages.leftRightLayout, label: window.siyuan.languages.leftRightLayout,
@ -741,7 +717,6 @@ const addConfigMoreMenu = async (config: ISearchOption, edit: Protyle, element:
} }
setPadding(edit.protyle); setPadding(edit.protyle);
localData.layout = 1; localData.layout = 1;
localStorage.setItem(Constants.LOCAL_SEARCHEKEYS, JSON.stringify(localData));
} }
}] }]
}).element); }).element);
@ -892,9 +867,8 @@ const updateConfig = (element: Element, item: ISearchOption, config: ISearchOpti
} }
(element.querySelector("#searchInput") as HTMLInputElement).value = item.k; (element.querySelector("#searchInput") as HTMLInputElement).value = item.k;
(element.querySelector("#replaceInput") as HTMLInputElement).value = item.r; (element.querySelector("#replaceInput") as HTMLInputElement).value = item.r;
Object.assign(config, item); window.siyuan.storage[Constants.LOCAL_SEARCHEDATA] = Object.assign({}, config, item);
inputEvent(element, config, undefined, edit); inputEvent(element, config, undefined, edit);
localStorage.setItem(Constants.LOCAL_SEARCHEDATA, JSON.stringify(config));
window.siyuan.menus.menu.remove(); window.siyuan.menus.menu.remove();
}; };

View file

@ -57,6 +57,7 @@ interface ICard {
name: string name: string
size: number size: number
} }
interface ISearchOption { interface ISearchOption {
name?: string name?: string
sort: number, // 0按块类型默认1按创建时间升序2按创建时间降序3按更新时间升序4按更新时间降序5按内容顺序仅在按文档分组时6按相关度升序7按相关度降序 sort: number, // 0按块类型默认1按创建时间升序2按创建时间降序3按更新时间升序4按更新时间降序5按内容顺序仅在按文档分组时6按相关度升序7按相关度降序
@ -149,6 +150,7 @@ interface INotebook {
} }
interface ISiyuan { interface ISiyuan {
storage?: { [key: string]: any },
printWin?: import("electron").BrowserWindow printWin?: import("electron").BrowserWindow
transactionsTimeout?: number, transactionsTimeout?: number,
transactions?: { transactions?: {

View file

@ -53,13 +53,8 @@ export const loadAssets = (data: IAppearance) => {
getAllModels().graph.forEach(item => { getAllModels().graph.forEach(item => {
item.searchGraph(false); item.searchGraph(false);
}); });
const localPDF = JSON.parse(localStorage.getItem(Constants.LOCAL_PDFTHEME) || "{}"); const pdfTheme = window.siyuan.config.appearance.mode === 0 ? window.siyuan.storage[Constants.LOCAL_PDFTHEME].light :
let pdfTheme: string; window.siyuan.storage[Constants.LOCAL_PDFTHEME].dark;
if (window.siyuan.config.appearance.mode === 0) {
pdfTheme = localPDF.light || "light";
} else {
pdfTheme = localPDF.dark || "dark";
}
document.querySelectorAll(".pdf__outer").forEach(item => { document.querySelectorAll(".pdf__outer").forEach(item => {
const darkElement = item.querySelector("#pdfDark"); const darkElement = item.querySelector("#pdfDark");
const lightElement = item.querySelector("#pdfLight"); const lightElement = item.querySelector("#pdfLight");

View file

@ -34,7 +34,7 @@ export const newDailyNote = () => {
}); });
return; return;
} }
const localNotebookId = localStorage.getItem(Constants.LOCAL_DAILYNOTEID); const localNotebookId = window.siyuan.storage[Constants.LOCAL_DAILYNOTEID];
if (localNotebookId && getNotebookName(localNotebookId) && !isMobile()) { if (localNotebookId && getNotebookName(localNotebookId) && !isMobile()) {
fetchPost("/api/filetree/createDailyNote", { fetchPost("/api/filetree/createDailyNote", {
notebook: localNotebookId, notebook: localNotebookId,
@ -66,7 +66,7 @@ export const newDailyNote = () => {
}); });
btnsElement[1].addEventListener("click", () => { btnsElement[1].addEventListener("click", () => {
const notebook = selectElement.value; const notebook = selectElement.value;
localStorage.setItem(Constants.LOCAL_DAILYNOTEID, notebook); window.siyuan.storage[Constants.LOCAL_DAILYNOTEID] = notebook;
fetchPost("/api/filetree/createDailyNote", { fetchPost("/api/filetree/createDailyNote", {
notebook, notebook,
app: Constants.SIYUAN_APPID, app: Constants.SIYUAN_APPID,

View file

@ -292,7 +292,7 @@ const initBar = () => {
notebook: item.id, notebook: item.id,
app: Constants.SIYUAN_APPID, app: Constants.SIYUAN_APPID,
}); });
localStorage.setItem(Constants.LOCAL_DAILYNOTEID, item.id); window.siyuan.storage[Constants.LOCAL_DAILYNOTEID] = item.id;
} }
}).element); }).element);
} }
@ -380,11 +380,15 @@ const initWindow = () => {
return; return;
} }
const msgId = showMessage(window.siyuan.languages.exporting, -1); const msgId = showMessage(window.siyuan.languages.exporting, -1);
localStorage.setItem(Constants.LOCAL_EXPORTPDF, JSON.stringify(Object.assign(ipcData.pdfOptions, { window.siyuan.storage[Constants.LOCAL_EXPORTPDF] = {
removeAssets: ipcData.removeAssets, removeAssets: ipcData.removeAssets,
keepFold: ipcData.keepFold, keepFold: ipcData.keepFold,
mergeSubdocs: ipcData.mergeSubdocs, mergeSubdocs: ipcData.mergeSubdocs,
}))); landscape: ipcData.pdfOptions.landscape,
marginType: ipcData.pdfOptions.marginType,
pageSize: ipcData.pdfOptions.pageSize,
scale: ipcData.pdfOptions.scale,
};
try { try {
if (window.siyuan.config.export.addFooter) { if (window.siyuan.config.export.addFooter) {
ipcData.pdfOptions.displayHeaderFooter = true; ipcData.pdfOptions.displayHeaderFooter = true;