mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 17:10:12 +01:00
This commit is contained in:
parent
b87510558c
commit
4ccee1a4d8
5 changed files with 43 additions and 15 deletions
|
|
@ -26,6 +26,7 @@ import {getAllTabs} from "./layout/getAll";
|
||||||
import {getLocalStorage} from "./protyle/util/compatibility";
|
import {getLocalStorage} from "./protyle/util/compatibility";
|
||||||
import {updateEditModeElement} from "./layout/topBar";
|
import {updateEditModeElement} from "./layout/topBar";
|
||||||
import {getSearch} from "./util/functions";
|
import {getSearch} from "./util/functions";
|
||||||
|
import {hideAllElements} from "./protyle/ui/hideElements";
|
||||||
|
|
||||||
class App {
|
class App {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
@ -50,6 +51,7 @@ class App {
|
||||||
case "readonly":
|
case "readonly":
|
||||||
window.siyuan.config.editor.readOnly = data.data;
|
window.siyuan.config.editor.readOnly = data.data;
|
||||||
updateEditModeElement();
|
updateEditModeElement();
|
||||||
|
hideAllElements(["util"]);
|
||||||
break;
|
break;
|
||||||
case "progress":
|
case "progress":
|
||||||
progressLoading(data);
|
progressLoading(data);
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ export const initFramework = () => {
|
||||||
editIconElement.setAttribute("xlink:href", "#iconEdit");
|
editIconElement.setAttribute("xlink:href", "#iconEdit");
|
||||||
}
|
}
|
||||||
editElement.addEventListener(getEventName(), () => {
|
editElement.addEventListener(getEventName(), () => {
|
||||||
window.siyuan.config.editor.readOnly = editIconElement.getAttribute("xlink:href") === "#iconEdit";
|
window.siyuan.config.editor.readOnly = !window.siyuan.config.editor.readOnly;
|
||||||
fetchPost("/api/setting/setEditor", window.siyuan.config.editor);
|
fetchPost("/api/setting/setEditor", window.siyuan.config.editor);
|
||||||
});
|
});
|
||||||
document.getElementById("toolbarSync").addEventListener(getEventName(), () => {
|
document.getElementById("toolbarSync").addEventListener(getEventName(), () => {
|
||||||
|
|
|
||||||
|
|
@ -879,17 +879,17 @@ export class Toolbar {
|
||||||
<span class="fn__flex-1"></span>
|
<span class="fn__flex-1"></span>
|
||||||
<button data-type="refresh" class="block__icon b3-tooltips b3-tooltips__nw${(isPin && !this.subElement.querySelector('[data-type="refresh"]').classList.contains("block__icon--active")) ? "" : " block__icon--active"}${types.includes("NodeBlockQueryEmbed") ? " fn__none" : ""}" aria-label="${window.siyuan.languages.refresh}"><svg><use xlink:href="#iconRefresh"></use></svg></button>
|
<button data-type="refresh" class="block__icon b3-tooltips b3-tooltips__nw${(isPin && !this.subElement.querySelector('[data-type="refresh"]').classList.contains("block__icon--active")) ? "" : " block__icon--active"}${types.includes("NodeBlockQueryEmbed") ? " fn__none" : ""}" aria-label="${window.siyuan.languages.refresh}"><svg><use xlink:href="#iconRefresh"></use></svg></button>
|
||||||
<span class="fn__space"></span>
|
<span class="fn__space"></span>
|
||||||
<button data-type="before" class="block__icon b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages["insert-before"]}"><svg><use xlink:href="#iconBefore"></use></svg></button>
|
<button data-type="before" class="block__icon b3-tooltips b3-tooltips__nw${protyle.disabled ? " fn__none" : ""}" aria-label="${window.siyuan.languages["insert-before"]}"><svg><use xlink:href="#iconBefore"></use></svg></button>
|
||||||
<span class="fn__space"></span>
|
<span class="fn__space${protyle.disabled ? " fn__none" : ""}"></span>
|
||||||
<button data-type="after" class="block__icon b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages["insert-after"]}"><svg><use xlink:href="#iconAfter"></use></svg></button>
|
<button data-type="after" class="block__icon b3-tooltips b3-tooltips__nw${protyle.disabled ? " fn__none" : ""}" aria-label="${window.siyuan.languages["insert-after"]}"><svg><use xlink:href="#iconAfter"></use></svg></button>
|
||||||
<span class="fn__space"></span>
|
<span class="fn__space${protyle.disabled ? " fn__none" : ""}"></span>
|
||||||
<button data-type="export" class="block__icon b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.export} ${window.siyuan.languages.image}"><svg><use xlink:href="#iconImage"></use></svg></button>
|
<button data-type="export" class="block__icon b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.export} ${window.siyuan.languages.image}"><svg><use xlink:href="#iconImage"></use></svg></button>
|
||||||
<span class="fn__space"></span>
|
<span class="fn__space"></span>
|
||||||
<button data-type="pin" class="block__icon b3-tooltips b3-tooltips__nw${isPin ? " block__icon--active" : ""}" aria-label="${window.siyuan.languages.pin}"><svg><use xlink:href="#iconPin"></use></svg></button>
|
<button data-type="pin" class="block__icon b3-tooltips b3-tooltips__nw${isPin ? " block__icon--active" : ""}" aria-label="${window.siyuan.languages.pin}"><svg><use xlink:href="#iconPin"></use></svg></button>
|
||||||
<span class="fn__space"></span>
|
<span class="fn__space"></span>
|
||||||
<button data-type="close" class="block__icon b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.close}"><svg style="width: 10px"><use xlink:href="#iconClose"></use></svg></button>
|
<button data-type="close" class="block__icon b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.close}"><svg style="width: 10px"><use xlink:href="#iconClose"></use></svg></button>
|
||||||
</div>
|
</div>
|
||||||
<textarea spellcheck="false" class="b3-text-field b3-text-field--text fn__block" placeholder="${placeholder}" style="${isMobile() ? "" : "width:" + Math.max(480, renderElement.clientWidth * 0.7) + "px"};max-height:50vh"></textarea></div>`;
|
<textarea ${protyle.disabled ? " readonly" : ""} spellcheck="false" class="b3-text-field b3-text-field--text fn__block" placeholder="${placeholder}" style="${isMobile() ? "" : "width:" + Math.max(480, renderElement.clientWidth * 0.7) + "px"};max-height:50vh"></textarea></div>`;
|
||||||
const autoHeight = () => {
|
const autoHeight = () => {
|
||||||
textElement.style.height = textElement.scrollHeight + "px";
|
textElement.style.height = textElement.scrollHeight + "px";
|
||||||
if (isMobile()) {
|
if (isMobile()) {
|
||||||
|
|
@ -1091,7 +1091,7 @@ export class Toolbar {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.subElementCloseCB = () => {
|
this.subElementCloseCB = () => {
|
||||||
if (!renderElement.parentElement) {
|
if (!renderElement.parentElement || protyle.disabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let inlineLastNode: Element;
|
let inlineLastNode: Element;
|
||||||
|
|
@ -1204,8 +1204,10 @@ export class Toolbar {
|
||||||
} else {
|
} else {
|
||||||
autoHeight();
|
autoHeight();
|
||||||
}
|
}
|
||||||
|
if (!protyle.disabled) {
|
||||||
textElement.select();
|
textElement.select();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public showCodeLanguage(protyle: IProtyle, languageElement: HTMLElement) {
|
public showCodeLanguage(protyle: IProtyle, languageElement: HTMLElement) {
|
||||||
const nodeElement = hasClosestBlock(languageElement);
|
const nodeElement = hasClosestBlock(languageElement);
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,9 @@
|
||||||
|
/// #if MOBILE
|
||||||
|
import {getCurrentEditor} from "../../mobile/editor";
|
||||||
|
/// #else
|
||||||
|
import {getAllModels} from "../../layout/getAll";
|
||||||
|
/// #endif
|
||||||
|
|
||||||
// "gutter", "toolbar", "select", "hint", "util", "dialog"
|
// "gutter", "toolbar", "select", "hint", "util", "dialog"
|
||||||
export const hideElements = (panels: string[], protyle?: IProtyle, focusHide = false) => {
|
export const hideElements = (panels: string[], protyle?: IProtyle, focusHide = false) => {
|
||||||
if (!protyle) {
|
if (!protyle) {
|
||||||
|
|
@ -44,7 +50,7 @@ export const hideElements = (panels: string[], protyle?: IProtyle, focusHide = f
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// "toolbar", "pdfutil", "gutter"
|
// "toolbar", "pdfutil", "gutter", "util"
|
||||||
export const hideAllElements = (types: string[]) => {
|
export const hideAllElements = (types: string[]) => {
|
||||||
if (types.includes("toolbar")) {
|
if (types.includes("toolbar")) {
|
||||||
document.querySelectorAll(".protyle-toolbar").forEach((item: HTMLElement) => {
|
document.querySelectorAll(".protyle-toolbar").forEach((item: HTMLElement) => {
|
||||||
|
|
@ -52,6 +58,24 @@ export const hideAllElements = (types: string[]) => {
|
||||||
item.style.display = "";
|
item.style.display = "";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (types.includes("util")) {
|
||||||
|
/// #if MOBILE
|
||||||
|
const editor = getCurrentEditor()
|
||||||
|
editor.protyle.toolbar.subElement.classList.add("fn__none");
|
||||||
|
if (editor.protyle.toolbar.subElementCloseCB) {
|
||||||
|
editor.protyle.toolbar.subElementCloseCB();
|
||||||
|
editor.protyle.toolbar.subElementCloseCB = undefined;
|
||||||
|
}
|
||||||
|
/// #else
|
||||||
|
getAllModels().editor.forEach(item => {
|
||||||
|
item.editor.protyle.toolbar.subElement.classList.add("fn__none");
|
||||||
|
if (item.editor.protyle.toolbar.subElementCloseCB) {
|
||||||
|
item.editor.protyle.toolbar.subElementCloseCB();
|
||||||
|
item.editor.protyle.toolbar.subElementCloseCB = undefined;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
/// #endif
|
||||||
|
}
|
||||||
if (types.includes("pdfutil")) {
|
if (types.includes("pdfutil")) {
|
||||||
document.querySelectorAll(".pdf__util").forEach(item => {
|
document.querySelectorAll(".pdf__util").forEach(item => {
|
||||||
item.classList.add("fn__none");
|
item.classList.add("fn__none");
|
||||||
|
|
|
||||||
|
|
@ -1208,12 +1208,12 @@ export class WYSIWYG {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
protyle.toolbar.range = getEditorRange(protyle.element);
|
protyle.toolbar.range = getEditorRange(protyle.element);
|
||||||
if (target.tagName === "SPAN" && !protyle.disabled) { // https://ld246.com/article/1665141518103
|
if (target.tagName === "SPAN") { // https://ld246.com/article/1665141518103
|
||||||
const types = protyle.toolbar.getCurrentType(protyle.toolbar.range);
|
const types = protyle.toolbar.getCurrentType(protyle.toolbar.range);
|
||||||
if (types.length > 0) {
|
if (types.length > 0) {
|
||||||
removeSearchMark(target);
|
removeSearchMark(target);
|
||||||
}
|
}
|
||||||
if (types.includes("block-ref")) {
|
if (types.includes("block-ref") && !protyle.disabled) {
|
||||||
refMenu(protyle, target);
|
refMenu(protyle, target);
|
||||||
// 阻止 popover
|
// 阻止 popover
|
||||||
target.setAttribute("prevent-popover", "true");
|
target.setAttribute("prevent-popover", "true");
|
||||||
|
|
@ -1221,16 +1221,16 @@ export class WYSIWYG {
|
||||||
target.removeAttribute("prevent-popover");
|
target.removeAttribute("prevent-popover");
|
||||||
}, 620);
|
}, 620);
|
||||||
return false;
|
return false;
|
||||||
} else if (types.includes("file-annotation-ref")) {
|
} else if (types.includes("file-annotation-ref") && !protyle.disabled) {
|
||||||
protyle.toolbar.showFileAnnotationRef(protyle, target);
|
protyle.toolbar.showFileAnnotationRef(protyle, target);
|
||||||
return false;
|
return false;
|
||||||
} else if (types.includes("tag")) {
|
} else if (types.includes("tag") && !protyle.disabled) {
|
||||||
tagMenu(protyle, target);
|
tagMenu(protyle, target);
|
||||||
return false;
|
return false;
|
||||||
} else if (types.includes("inline-memo")) {
|
} else if (types.includes("inline-memo")) {
|
||||||
protyle.toolbar.showRender(protyle, target);
|
protyle.toolbar.showRender(protyle, target);
|
||||||
return false;
|
return false;
|
||||||
} else if (types.includes("a")) {
|
} else if (types.includes("a") && !protyle.disabled) {
|
||||||
linkMenu(protyle, target);
|
linkMenu(protyle, target);
|
||||||
if (window.siyuan.config.editor.floatWindowMode === 0 &&
|
if (window.siyuan.config.editor.floatWindowMode === 0 &&
|
||||||
target.getAttribute("data-href")?.startsWith("siyuan://blocks")) {
|
target.getAttribute("data-href")?.startsWith("siyuan://blocks")) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue