Vanessa 2023-09-08 21:59:18 +08:00
parent da0e656ba6
commit b5c45cbb45
7 changed files with 98 additions and 42 deletions

View file

@ -345,7 +345,11 @@ export const editor = {
getAllModels().editor.forEach((item) => {
reloadProtyle(item.editor.protyle, false);
setPadding(item.editor.protyle);
if (window.siyuan.config.editor.fullWidth) {
let isFullWidth = item.editor.protyle.wysiwyg.element.getAttribute("custom-sy-fullwidth");
if (!isFullWidth) {
isFullWidth = window.siyuan.config.editor.fullWidth ? "true" : "false";
}
if (isFullWidth === "true") {
item.editor.protyle.contentElement.setAttribute("data-fullwidth", "true");
} else {
item.editor.protyle.contentElement.removeAttribute("data-fullwidth");

View file

@ -155,7 +155,7 @@ export const openFileAttr = (attrs: IObject, focusName = "bookmark") => {
let hasAV = false;
const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : null;
Object.keys(attrs).forEach(item => {
if ("custom-riff-decks" === item) {
if ("custom-riff-decks" === item || item.startsWith("custom-sy-")) {
return;
}
if (item === "custom-reminder-wechat") {

View file

@ -324,17 +324,6 @@ export class Breadcrumb {
}
}
if (!protyle.disabled) {
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.optimizeTypography,
accelerator: window.siyuan.config.keymap.editor.general.optimizeTypography.custom,
icon: "iconFormat",
click: () => {
hideElements(["toolbar"], protyle);
fetchPost("/api/format/autoSpace", {
id: protyle.block.rootID
});
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.netImg2LocalAsset,
icon: "iconTransform",
@ -386,14 +375,20 @@ export class Breadcrumb {
reloadProtyle(protyle, !isMobile());
}
}).element);
if (!protyle.disabled) {
window.siyuan.menus.menu.append(new MenuItem({
icon: "iconTrashcan",
label: window.siyuan.languages.delete,
label: window.siyuan.languages.optimizeTypography,
accelerator: window.siyuan.config.keymap.editor.general.optimizeTypography.custom,
icon: "iconFormat",
click: () => {
deleteFile(protyle.notebookId, protyle.path);
hideElements(["toolbar"], protyle);
fetchPost("/api/format/autoSpace", {
id: protyle.block.rootID
});
}
}).element);
if (!isMobile()) {
}
/// #if !MOBILE
window.siyuan.menus.menu.append(new MenuItem({
icon: protyle.element.className.includes("fullscreen") ? "iconFullscreenExit" : "iconFullscreen",
accelerator: window.siyuan.config.keymap.editor.general.fullscreen.custom,
@ -403,7 +398,7 @@ export class Breadcrumb {
setPadding(protyle);
}
}).element);
}
/// #endif
const editSubmenu: IMenu[] = [{
current: !protyle.contentElement.classList.contains("fn__none"),
label: window.siyuan.languages.wysiwyg,
@ -428,8 +423,54 @@ export class Breadcrumb {
type: "submenu",
submenu: editSubmenu
}).element);
/// #if !MOBILE
if (!protyle.disabled) {
const isCustomFullWidth = protyle.wysiwyg.element.getAttribute("custom-sy-fullwidth");
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.fullWidth,
type: "submenu",
submenu: [{
iconHTML: "",
current: isCustomFullWidth === "true",
label: window.siyuan.languages.use,
click() {
fetchPost("/api/attr/setBlockAttrs", {
id: protyle.block.rootID,
attrs: {"custom-sy-fullwidth": "true"}
});
}
}, {
iconHTML: "",
current: isCustomFullWidth === "false",
label: window.siyuan.languages.close,
click() {
fetchPost("/api/attr/setBlockAttrs", {
id: protyle.block.rootID,
attrs: {"custom-sy-fullwidth": "false"}
});
}
}, {
iconHTML: "",
current: !isCustomFullWidth,
label: window.siyuan.languages.default,
click() {
fetchPost("/api/attr/setBlockAttrs", {
id: protyle.block.rootID,
attrs: {"custom-sy-fullwidth": ""}
});
}
}]
}).element);
}
/// #endif
window.siyuan.menus.menu.append(exportMd(protyle.block.showAll ? protyle.block.id : protyle.block.rootID));
window.siyuan.menus.menu.append(new MenuItem({
icon: "iconTrashcan",
label: window.siyuan.languages.delete,
click: () => {
deleteFile(protyle.notebookId, protyle.path);
}
}).element);
if (protyle?.app?.plugins) {
emitOpenMenu({
plugins: protyle.app.plugins,
@ -469,7 +510,7 @@ export class Breadcrumb {
if (getSelection().rangeCount > 0) {
range = getSelection().getRangeAt(0);
if (!protyle.wysiwyg.element.isEqualNode(range.startContainer) && !protyle.wysiwyg.element.contains(range.startContainer)) {
if (protyle.element.id ==="searchPreview") {
if (protyle.element.id === "searchPreview") {
// https://github.com/siyuan-note/siyuan/issues/8807
blockElement = hasClosestBlock(protyle.wysiwyg.element.querySelector('[data-type="search-mark"]')) as Element;
} else {

View file

@ -204,7 +204,6 @@ export class Protyle {
}
}
});
setPadding(this.protyle);
if (options.backlinkData) {
this.protyle.block.rootID = options.blockId;
renderBacklink(this.protyle, options.backlinkData);
@ -300,7 +299,7 @@ export class Protyle {
});
/// #endif
}
setPadding(this.protyle);
// 需等待 getDoc 完成后再执行,否则在无页签的时候 updatePanelByEditor 会执行2次
// 只能用 focusin否则点击表格无法执行
this.protyle.wysiwyg.element.addEventListener("focusin", () => {

View file

@ -11,11 +11,6 @@ import {fetchPost} from "../../util/fetch";
export const initUI = (protyle: IProtyle) => {
protyle.contentElement = document.createElement("div");
protyle.contentElement.className = "protyle-content";
if (window.siyuan.config.editor.fullWidth) {
protyle.contentElement.setAttribute("data-fullwidth", "true");
} else {
protyle.contentElement.removeAttribute("data-fullwidth");
}
if (protyle.options.render.background) {
protyle.contentElement.appendChild(protyle.background.element);
}
@ -129,7 +124,11 @@ export const setPadding = (protyle: IProtyle) => {
let min24 = 24;
if (!isMobile()) {
let padding = (protyle.element.clientWidth - Constants.SIZE_EDITOR_WIDTH) / 2;
if (!window.siyuan.config.editor.fullWidth && padding > 96) {
let isFullWidth = protyle.wysiwyg.element.getAttribute("custom-sy-fullwidth");
if (!isFullWidth) {
isFullWidth = window.siyuan.config.editor.fullWidth ? "true" : "false";
}
if (isFullWidth === "false" && padding > 96) {
if (padding > Constants.SIZE_EDITOR_WIDTH) {
// 超宽屏调整 https://ld246.com/article/1668266637363
padding = protyle.element.clientWidth * .382 / 1.382;

View file

@ -108,6 +108,15 @@ export class WYSIWYG {
}
public renderCustom(ial: IObject) {
let isFullWidth = ial["custom-sy-fullwidth"];
if (!isFullWidth) {
isFullWidth = window.siyuan.config.editor.fullWidth ? "true" : "false";
}
if (isFullWidth ==="true") {
this.element.parentElement.setAttribute("data-fullwidth", "true");
} else {
this.element.parentElement.removeAttribute("data-fullwidth");
}
const ialKeys = Object.keys(ial);
for (let i = 0; i < this.element.attributes.length; i++) {
const oldKey = this.element.attributes[i].nodeName;

View file

@ -18,6 +18,7 @@ import {hideElements} from "../ui/hideElements";
import {reloadProtyle} from "../util/reload";
import {countBlockWord} from "../../layout/status";
import {needLogin, needSubscribe} from "../../util/needSubscribe";
import {setPadding} from "../ui/initUI";
const removeTopElement = (updateElement: Element, protyle: IProtyle) => {
// 移动到其他文档中,该块需移除
@ -424,7 +425,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo:
if (operation.action === "delete") {
if (updateElements.length > 0) {
deleteBlock(updateElements, operation.id, protyle, isUndo);
} else if (isUndo){
} else if (isUndo) {
zoomOut({
protyle,
id: protyle.block.rootID,
@ -503,6 +504,9 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo:
protyle.title.element.querySelector(".protyle-attr").innerHTML = nodeAttrHTML;
}
protyle.wysiwyg.renderCustom(attrsResult);
if (data.new["custom-sy-fullwidth"] !== data.old["custom-sy-fullwidth"]) {
setPadding(protyle);
}
if (data.new.icon !== data.old.icon) {
/// #if MOBILE
if (window.siyuan.mobile.editor.protyle.background.ial.icon !== data.new.icon) {