mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-23 18:10:12 +01:00
This commit is contained in:
parent
41a7c5d63f
commit
c56c69e0e0
18 changed files with 121 additions and 39 deletions
|
|
@ -4,9 +4,51 @@ import {fetchPost} from "../util/fetch";
|
|||
import {confirmDialog} from "../dialog/confirmDialog";
|
||||
import {setPadding} from "../protyle/ui/initUI";
|
||||
import {reloadProtyle} from "../protyle/util/reload";
|
||||
import {disabledProtyle, enableProtyle} from "../protyle/util/onGet";
|
||||
|
||||
export const editor = {
|
||||
element: undefined as Element,
|
||||
setMode: (readOnly?: boolean) => {
|
||||
const target = document.querySelector("#barReadonly");
|
||||
if (typeof readOnly === "undefined") {
|
||||
readOnly = target.getAttribute("aria-label") === `${window.siyuan.languages.use} ${window.siyuan.languages.editReadonly}`
|
||||
}
|
||||
window.siyuan.config.editor.readOnly = readOnly;
|
||||
if (readOnly) {
|
||||
target.setAttribute("aria-label", `${window.siyuan.languages.use} ${window.siyuan.languages.editMode}`);
|
||||
target.querySelector('use').setAttribute("xlink:href", "#iconPreview");
|
||||
} else {
|
||||
target.setAttribute("aria-label", `${window.siyuan.languages.use} ${window.siyuan.languages.editReadonly}`);
|
||||
target.querySelector('use').setAttribute("xlink:href", "#iconEdit");
|
||||
}
|
||||
fetchPost("/api/setting/setEditor", window.siyuan.config.editor, () => {
|
||||
const allModels = getAllModels()
|
||||
allModels.editor.forEach(editor => {
|
||||
if (readOnly) { disabledProtyle(editor.editor.protyle);
|
||||
} else {
|
||||
enableProtyle(editor.editor.protyle);
|
||||
}
|
||||
});
|
||||
allModels.backlink.forEach(backlink => {
|
||||
backlink.editors.forEach(editor => {
|
||||
if (readOnly) {
|
||||
disabledProtyle(editor.protyle);
|
||||
} else {
|
||||
enableProtyle(editor.protyle);
|
||||
}
|
||||
})
|
||||
});
|
||||
window.siyuan.blockPanels.forEach(item => {
|
||||
item.editors.forEach(editor => {
|
||||
if (readOnly) {
|
||||
disabledProtyle(editor.protyle);
|
||||
} else {
|
||||
enableProtyle(editor.protyle);
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
},
|
||||
genHTML: () => {
|
||||
let fontFamilyHTML = "";
|
||||
fontFamilyHTML = '<select id="fontFamily" class="b3-select fn__flex-center fn__size200"></select>';
|
||||
|
|
@ -208,8 +250,11 @@ export const editor = {
|
|||
});
|
||||
});
|
||||
},
|
||||
onSetEditor: (editor: IEditor) => {
|
||||
window.siyuan.config.editor = editor;
|
||||
onSetEditor: (editorData: IEditor) => {
|
||||
if (editorData.readOnly !== window.siyuan.config.editor.readOnly) {
|
||||
editor.setMode(editorData.readOnly);
|
||||
}
|
||||
window.siyuan.config.editor = editorData;
|
||||
getAllModels().editor.forEach((item) => {
|
||||
reloadProtyle(item.editor.protyle);
|
||||
setPadding(item.editor.protyle);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue