This commit is contained in:
parent
006cc6df8d
commit
320110d57e
6 changed files with 80 additions and 65 deletions
|
@ -1,4 +1,6 @@
|
|||
{
|
||||
"tempUnlock": "临时解锁",
|
||||
"cancelTempUnlock": "取消临时解锁",
|
||||
"addFilter": "添加筛选条件",
|
||||
"removeFilters": "清空筛选规则",
|
||||
"checked": "已完成",
|
||||
|
|
|
@ -316,7 +316,7 @@ export const editor = {
|
|||
fontFamily: fontFamilyElement.value,
|
||||
emoji: window.siyuan.config.editor.emoji
|
||||
}, response => {
|
||||
editor.onSetEditor(response.data);
|
||||
editor._onSetEditor(response.data);
|
||||
});
|
||||
};
|
||||
editor.element.querySelectorAll("input.b3-switch, select.b3-select, input.b3-slider").forEach((item) => {
|
||||
|
@ -336,13 +336,16 @@ export const editor = {
|
|||
});
|
||||
});
|
||||
},
|
||||
onSetEditor: (editorData: IEditor) => {
|
||||
if (editorData.readOnly !== window.siyuan.config.editor.readOnly) {
|
||||
_onSetEditor: (editorData: IEditor) => {
|
||||
const changeReadonly = editorData.readOnly !== window.siyuan.config.editor.readOnly
|
||||
if (changeReadonly) {
|
||||
editor.setReadonly(editorData.readOnly);
|
||||
}
|
||||
window.siyuan.config.editor = editorData;
|
||||
getAllModels().editor.forEach((item) => {
|
||||
reloadProtyle(item.editor.protyle, false);
|
||||
if (!changeReadonly) {
|
||||
reloadProtyle(item.editor.protyle, false);
|
||||
}
|
||||
let isFullWidth = item.editor.protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_FULLWIDTH);
|
||||
if (!isFullWidth) {
|
||||
isFullWidth = window.siyuan.config.editor.fullWidth ? "true" : "false";
|
||||
|
|
|
@ -94,9 +94,9 @@ const focusStack = (backStack: IBackStack) => {
|
|||
} else {
|
||||
let readOnly = window.siyuan.config.readonly ? "true" : "false";
|
||||
if (readOnly === "false") {
|
||||
readOnly = protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_READONLY);
|
||||
if (!readOnly) {
|
||||
readOnly = window.siyuan.config.editor.readOnly ? "true" : "false";
|
||||
readOnly = window.siyuan.config.editor.readOnly ? "true" : "false";
|
||||
if (readOnly === "false") {
|
||||
readOnly = protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_READONLY);
|
||||
}
|
||||
}
|
||||
if (readOnly === "true") {
|
||||
|
|
|
@ -20,7 +20,7 @@ import {setPanelFocus} from "../../layout/util";
|
|||
/// #if !BROWSER
|
||||
import {ipcRenderer} from "electron";
|
||||
/// #endif
|
||||
import {onGet} from "../util/onGet";
|
||||
import {disabledProtyle, enableProtyle, onGet} from "../util/onGet";
|
||||
import {hideElements} from "../ui/hideElements";
|
||||
import {confirmDialog} from "../../dialog/confirmDialog";
|
||||
import {reloadProtyle} from "../util/reload";
|
||||
|
@ -45,8 +45,8 @@ export class Breadcrumb {
|
|||
'<div class="protyle-breadcrumb__bar"></div>'}
|
||||
<span class="protyle-breadcrumb__space"></span>
|
||||
<button class="protyle-breadcrumb__icon fn__none" data-type="exit-focus">${window.siyuan.languages.exitFocus}</button>
|
||||
<button class="block__icon block__icon--show fn__flex-center ariaLabel" aria-label="${window.siyuan.languages.lockEdit}" data-type="readonly"><svg><use xlink:href="#iconUnlock"></use></svg></button>
|
||||
<span class="fn__space"></span>
|
||||
<button class="block__icon block__icon--show fn__flex-center ariaLabel${window.siyuan.config.readonly ? " fn__none" : ""}" aria-label="${window.siyuan.languages.lockEdit}" data-type="readonly"><svg><use xlink:href="#iconUnlock"></use></svg></button>
|
||||
<span class="fn__space${window.siyuan.config.readonly ? " fn__none" : ""}"></span>
|
||||
<button class="block__icon block__icon--show fn__flex-center ariaLabel" data-type="doc" aria-label="${isMac() ? window.siyuan.languages.gutterTip2 : window.siyuan.languages.gutterTip2.replace("⇧", "Shift+")}"><svg><use xlink:href="#iconFile"></use></svg></button>
|
||||
<span class="fn__space"></span>
|
||||
<button class="block__icon block__icon--show fn__flex-center ariaLabel" data-type="more" aria-label="${window.siyuan.languages.more}"><svg><use xlink:href="#iconMore"></use></svg></button>
|
||||
|
@ -107,10 +107,23 @@ export class Breadcrumb {
|
|||
event.preventDefault();
|
||||
break;
|
||||
} else if (type === "readonly") {
|
||||
fetchPost("/api/attr/setBlockAttrs", {
|
||||
id: protyle.block.rootID,
|
||||
attrs: {[Constants.CUSTOM_SY_READONLY]: target.querySelector("use").getAttribute("xlink:href") === "#iconUnlock" ? "true" : "false"}
|
||||
});
|
||||
if (!window.siyuan.config.readonly) {
|
||||
const isReadonly = target.querySelector("use").getAttribute("xlink:href") !== "#iconUnlock"
|
||||
if (window.siyuan.config.editor.readOnly) {
|
||||
if (isReadonly) {
|
||||
enableProtyle(protyle);
|
||||
} else {
|
||||
disabledProtyle(protyle);
|
||||
}
|
||||
} else {
|
||||
fetchPost("/api/attr/setBlockAttrs", {
|
||||
id: protyle.block.rootID,
|
||||
attrs: {
|
||||
[Constants.CUSTOM_SY_READONLY]: isReadonly ? "false" : "true"
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
|
@ -426,43 +439,45 @@ export class Breadcrumb {
|
|||
type: "submenu",
|
||||
submenu: editSubmenu
|
||||
}).element);
|
||||
const isCustomReadonly = protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_READONLY);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.editReadonly,
|
||||
icon: "iconLock",
|
||||
type: "submenu",
|
||||
submenu: [{
|
||||
iconHTML: "",
|
||||
current: isCustomReadonly === "true",
|
||||
label: window.siyuan.languages.enable,
|
||||
click() {
|
||||
fetchPost("/api/attr/setBlockAttrs", {
|
||||
id: protyle.block.rootID,
|
||||
attrs: {[Constants.CUSTOM_SY_READONLY]: "true"}
|
||||
});
|
||||
}
|
||||
}, {
|
||||
iconHTML: "",
|
||||
current: isCustomReadonly === "false",
|
||||
label: window.siyuan.languages.disable,
|
||||
click() {
|
||||
fetchPost("/api/attr/setBlockAttrs", {
|
||||
id: protyle.block.rootID,
|
||||
attrs: {[Constants.CUSTOM_SY_READONLY]: "false"}
|
||||
});
|
||||
}
|
||||
}, {
|
||||
iconHTML: "",
|
||||
current: !isCustomReadonly,
|
||||
label: window.siyuan.languages.default,
|
||||
click() {
|
||||
fetchPost("/api/attr/setBlockAttrs", {
|
||||
id: protyle.block.rootID,
|
||||
attrs: {[Constants.CUSTOM_SY_READONLY]: ""}
|
||||
});
|
||||
}
|
||||
}]
|
||||
}).element);
|
||||
if (!window.siyuan.config.editor.readOnly && !window.siyuan.config.readonly) {
|
||||
const isCustomReadonly = protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_READONLY);
|
||||
window.siyuan.menus.menu.append(new MenuItem({
|
||||
label: window.siyuan.languages.editReadonly,
|
||||
icon: "iconLock",
|
||||
type: "submenu",
|
||||
submenu: [{
|
||||
iconHTML: "",
|
||||
current: isCustomReadonly === "true",
|
||||
label: window.siyuan.languages.enable,
|
||||
click() {
|
||||
fetchPost("/api/attr/setBlockAttrs", {
|
||||
id: protyle.block.rootID,
|
||||
attrs: {[Constants.CUSTOM_SY_READONLY]: "true"}
|
||||
});
|
||||
}
|
||||
}, {
|
||||
iconHTML: "",
|
||||
current: isCustomReadonly === "false",
|
||||
label: window.siyuan.languages.disable,
|
||||
click() {
|
||||
fetchPost("/api/attr/setBlockAttrs", {
|
||||
id: protyle.block.rootID,
|
||||
attrs: {[Constants.CUSTOM_SY_READONLY]: "false"}
|
||||
});
|
||||
}
|
||||
}, {
|
||||
iconHTML: "",
|
||||
current: !isCustomReadonly,
|
||||
label: window.siyuan.languages.default,
|
||||
click() {
|
||||
fetchPost("/api/attr/setBlockAttrs", {
|
||||
id: protyle.block.rootID,
|
||||
attrs: {[Constants.CUSTOM_SY_READONLY]: ""}
|
||||
});
|
||||
}
|
||||
}]
|
||||
}).element);
|
||||
}
|
||||
/// #if !MOBILE
|
||||
if (!protyle.disabled) {
|
||||
const isCustomFullWidth = protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_FULLWIDTH);
|
||||
|
|
|
@ -123,13 +123,8 @@ export class Protyle {
|
|||
});
|
||||
break;
|
||||
case "readonly":
|
||||
if (!this.protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_READONLY)) {
|
||||
if (data.data) {
|
||||
disabledProtyle(this.protyle);
|
||||
} else {
|
||||
enableProtyle(this.protyle);
|
||||
}
|
||||
}
|
||||
window.siyuan.config.editor.readOnly = data.data;
|
||||
reloadProtyle(this.protyle, false);
|
||||
break;
|
||||
case "heading2doc":
|
||||
case "li2doc":
|
||||
|
@ -392,7 +387,7 @@ export class Protyle {
|
|||
insertHTML(html, this.protyle, isBlock, useProtyleRange);
|
||||
}
|
||||
|
||||
public transaction( doOperations: IOperation[], undoOperations?: IOperation[]) {
|
||||
transaction(this.protyle, doOperations, undoOperations);
|
||||
public transaction(doOperations: IOperation[], undoOperations?: IOperation[]) {
|
||||
transaction(this.protyle, doOperations, undoOperations);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -242,9 +242,9 @@ const setHTML = (options: {
|
|||
protyle.element.removeAttribute("disabled-forever");
|
||||
let readOnly = window.siyuan.config.readonly ? "true" : "false";
|
||||
if (readOnly === "false") {
|
||||
readOnly = protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_READONLY);
|
||||
if (!readOnly) {
|
||||
readOnly = window.siyuan.config.editor.readOnly ? "true" : "false";
|
||||
readOnly = window.siyuan.config.editor.readOnly ? "true" : "false";
|
||||
if (readOnly === "false") {
|
||||
readOnly = protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_READONLY);
|
||||
}
|
||||
}
|
||||
if (readOnly === "true") {
|
||||
|
@ -339,7 +339,7 @@ export const disabledProtyle = (protyle: IProtyle) => {
|
|||
});
|
||||
if (protyle.breadcrumb) {
|
||||
protyle.breadcrumb.element.parentElement.querySelector('[data-type="readonly"] use').setAttribute("xlink:href", "#iconLock");
|
||||
protyle.breadcrumb.element.parentElement.querySelector('[data-type="readonly"]').setAttribute("aria-label", window.siyuan.languages.unlockEdit);
|
||||
protyle.breadcrumb.element.parentElement.querySelector('[data-type="readonly"]').setAttribute("aria-label", window.siyuan.config.editor.readOnly ? window.siyuan.languages.tempUnlock : window.siyuan.languages.unlockEdit);
|
||||
}
|
||||
hideTooltip();
|
||||
};
|
||||
|
@ -373,7 +373,7 @@ export const enableProtyle = (protyle: IProtyle) => {
|
|||
});
|
||||
if (protyle.breadcrumb) {
|
||||
protyle.breadcrumb.element.parentElement.querySelector('[data-type="readonly"] use').setAttribute("xlink:href", "#iconUnlock");
|
||||
protyle.breadcrumb.element.parentElement.querySelector('[data-type="readonly"]').setAttribute("aria-label", window.siyuan.languages.lockEdit);
|
||||
protyle.breadcrumb.element.parentElement.querySelector('[data-type="readonly"]').setAttribute("aria-label", window.siyuan.config.editor.readOnly ? window.siyuan.languages.cancelTempUnlock : window.siyuan.languages.lockEdit);
|
||||
}
|
||||
hideTooltip();
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue