This commit is contained in:
Vanessa 2022-10-17 11:43:33 +08:00
parent c5e3a6ecf4
commit 31d699ae7e
5 changed files with 98 additions and 91 deletions

View file

@ -205,6 +205,24 @@
position: relative;
padding-bottom: 40px;
&--enable {
.protyle-background__tags .item:hover svg {
opacity: 1;
}
.protyle-background__img:hover .protyle-icons {
opacity: .86;
}
&:hover > .protyle-background__iconw > .protyle-icons {
opacity: .86;
}
.protyle-background__icon:hover {
opacity: .86;
}
}
&__icon {
height: 80px;
width: 80px;
@ -222,10 +240,6 @@
float: left;
border-radius: 4px;
}
&:hover {
opacity: .96;
}
}
&__img {
@ -240,10 +254,6 @@
object-position: center;
}
&:hover .protyle-icons {
opacity: .86;
}
.protyle-icons {
bottom: 8px;
top: auto;
@ -283,10 +293,6 @@
&:hover {
color: var(--b3-theme-on-background);
svg {
opacity: 1;
}
}
&--1 {
@ -337,10 +343,6 @@
margin-top: 40px;
}
}
&:hover > .protyle-background__iconw > .protyle-icons {
opacity: .86;
}
}
.protyle-title {

View file

@ -138,34 +138,29 @@ export class Breadcrumb {
fetchPost("/api/block/getTreeStat", {id: id || protyle.block.id}, (response) => {
window.siyuan.menus.menu.remove();
if (!protyle.contentElement.classList.contains("fn__none")) {
if (!protyle.contentElement.classList.contains("fn__none") && !protyle.disabled) {
let uploadHTML = "";
if (!protyle.disabled) {
uploadHTML = '<input class="b3-form__upload" type="file" multiple="multiple"';
if (protyle.options.upload.accept) {
uploadHTML += ` accept="${protyle.options.upload.accept}">`;
} else {
uploadHTML += ">";
}
uploadHTML = '<input class="b3-form__upload" type="file" multiple="multiple"';
if (protyle.options.upload.accept) {
uploadHTML += ` accept="${protyle.options.upload.accept}">`;
} else {
uploadHTML += ">";
}
const uploadMenu = new MenuItem({
disabled: protyle.disabled,
icon: "iconDownload",
label: `${window.siyuan.languages.insertAsset}${uploadHTML}`,
}).element;
if (!protyle.disabled) {
uploadMenu.querySelector("input").addEventListener("change", (event: InputEvent & { target: HTMLInputElement }) => {
if (event.target.files.length === 0) {
return;
}
uploadFiles(protyle, event.target.files, event.target);
window.siyuan.menus.menu.remove();
});
}
uploadMenu.querySelector("input").addEventListener("change", (event: InputEvent & { target: HTMLInputElement }) => {
if (event.target.files.length === 0) {
return;
}
uploadFiles(protyle, event.target.files, event.target);
window.siyuan.menus.menu.remove();
});
window.siyuan.menus.menu.append(uploadMenu);
if (window.siyuan.config.system.container !== "android" || !window.JSAndroid) {
window.siyuan.menus.menu.append(new MenuItem({
disabled: protyle.disabled && (!this.mediaRecorder || (this.mediaRecorder && !this.mediaRecorder.isRecording)),
disabled: !this.mediaRecorder || (this.mediaRecorder && !this.mediaRecorder.isRecording),
current: this.mediaRecorder && this.mediaRecorder.isRecording,
icon: "iconRecord",
label: this.mediaRecorder?.isRecording ? window.siyuan.languages.endRecord : window.siyuan.languages.startRecord,
@ -207,55 +202,57 @@ export class Breadcrumb {
}).element);
}
}
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.uploadAssets2CDN,
icon: "iconCloud",
click() {
if (!needSubscribe()) {
fetchPost("/api/asset/uploadCloud", {id: protyle.block.parentID});
if (!protyle.disabled) {
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.uploadAssets2CDN,
icon: "iconCloud",
click() {
if (!needSubscribe()) {
fetchPost("/api/asset/uploadCloud", {id: protyle.block.parentID});
}
}
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.netImg2LocalAsset,
icon: "iconTransform",
accelerator: window.siyuan.config.keymap.editor.general.netImg2LocalAsset.custom,
click() {
netImg2LocalAssets(protyle);
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.optimizeTypography,
icon: "iconFormat",
click: () => {
hideElements(["toolbar"], protyle);
fetchPost("/api/format/autoSpace", {
id: protyle.block.rootID
}, () => {
/// #if MOBILE
fetchPost("/api/filetree/getDoc", {
id: protyle.block.id,
mode: 0,
size: Constants.SIZE_GET,
}, getResponse => {
onGet(getResponse, protyle, [Constants.CB_GET_FOCUS], saveScroll(protyle, true));
}).element);
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.netImg2LocalAsset,
icon: "iconTransform",
accelerator: window.siyuan.config.keymap.editor.general.netImg2LocalAsset.custom,
click() {
netImg2LocalAssets(protyle);
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.optimizeTypography,
icon: "iconFormat",
click: () => {
hideElements(["toolbar"], protyle);
fetchPost("/api/format/autoSpace", {
id: protyle.block.rootID
}, () => {
/// #if MOBILE
fetchPost("/api/filetree/getDoc", {
id: protyle.block.id,
mode: 0,
size: Constants.SIZE_GET,
}, getResponse => {
onGet(getResponse, protyle, [Constants.CB_GET_FOCUS], saveScroll(protyle, true));
});
/// #else
getAllModels().editor.forEach(item => {
if (item.editor.protyle.block.rootID === protyle.block.rootID) {
fetchPost("/api/filetree/getDoc", {
id: item.editor.protyle.block.rootID,
mode: 0,
size: Constants.SIZE_GET,
}, getResponse => {
onGet(getResponse, item.editor.protyle, [Constants.CB_GET_FOCUS], saveScroll(protyle, true));
});
}
});
/// #endif
});
/// #else
getAllModels().editor.forEach(item => {
if (item.editor.protyle.block.rootID === protyle.block.rootID) {
fetchPost("/api/filetree/getDoc", {
id: item.editor.protyle.block.rootID,
mode: 0,
size: Constants.SIZE_GET,
}, getResponse => {
onGet(getResponse, item.editor.protyle, [Constants.CB_GET_FOCUS], saveScroll(protyle, true));
});
}
});
/// #endif
});
}
}).element);
}
}).element);
}
if (!protyle.scroll?.element.classList.contains("fn__none")) {
window.siyuan.menus.menu.append(new MenuItem({
current: protyle.scroll.keepLazyLoad,

View file

@ -118,6 +118,9 @@ export class Background {
});
});
this.element.addEventListener(getEventName(), (event) => {
if (protyle.disabled) {
return;
}
let target = event.target as HTMLElement;
hideElements(["gutter"], protyle);

View file

@ -276,7 +276,7 @@ export class Title {
type: "submenu",
submenu: copySubMenu(protyle.block.rootID)
}).element);
if (!window.siyuan.config.readonly) {
if (protyle.disabled) {
window.siyuan.menus.menu.append(movePathToMenu(protyle.notebookId, protyle.path));
window.siyuan.menus.menu.append(new MenuItem({
icon: "iconTrashcan",
@ -285,8 +285,6 @@ export class Title {
deleteFile(protyle.notebookId, protyle.path, escapeHtml(this.editElement.textContent));
}
}).element);
}
if (!window.siyuan.config.readonly && !window.siyuan.config.editor.readOnly) {
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.attr,

View file

@ -276,6 +276,7 @@ const setHTML = (options: { content: string, action?: string[], unScroll?: boole
/** 禁用编辑器 */
export const disabledProtyle = (protyle: IProtyle) => {
window.siyuan.menus.menu.remove();
hideElements(["gutter", "toolbar", "select", "hint", "util"], protyle);
protyle.disabled = true;
if (protyle.title) {
@ -283,6 +284,9 @@ export const disabledProtyle = (protyle: IProtyle) => {
titleElement.setAttribute("contenteditable", "false");
titleElement.style.userSelect = "text";
}
if (protyle.background) {
protyle.background.element.classList.remove("protyle-background--enable");
}
protyle.wysiwyg.element.style.userSelect = "text";
protyle.wysiwyg.element.setAttribute("contenteditable", "false");
protyle.wysiwyg.element.querySelectorAll('[contenteditable="true"][spellcheck="false"]').forEach(item => {
@ -294,16 +298,19 @@ export const disabledProtyle = (protyle: IProtyle) => {
export const enableProtyle = (protyle: IProtyle) => {
protyle.disabled = false;
if (navigator && navigator.maxTouchPoints > 1 && ["MacIntel", "iPhone"].includes(navigator.platform)) {
// iPhoneiPad 端输入 contenteditable 为 true 时会在块中间插入 span
// iPhoneiPad 端 protyle.wysiwyg.element contenteditable 为 true 时,输入会在块中间插入 span 导致保存失败 https://ld246.com/article/1643473862873/comment/1643813765839#comments
} else {
if (protyle.title) {
const titleElement = protyle.title.element.querySelector(".protyle-title__input") as HTMLElement;
titleElement.setAttribute("contenteditable", "true");
titleElement.style.userSelect = "";
}
protyle.wysiwyg.element.setAttribute("contenteditable", "true");
protyle.wysiwyg.element.style.userSelect = "";
}
if (protyle.title) {
const titleElement = protyle.title.element.querySelector(".protyle-title__input") as HTMLElement;
titleElement.setAttribute("contenteditable", "true");
titleElement.style.userSelect = "";
}
if (protyle.background) {
protyle.background.element.classList.add("protyle-background--enable");
}
protyle.wysiwyg.element.querySelectorAll('[contenteditable="false"][spellcheck="false"]').forEach(item => {
if (!hasClosestByClassName(item, "protyle-wysiwyg__embed")) {
item.setAttribute("contenteditable", "true");