mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 17:10:12 +01:00
This commit is contained in:
parent
da0e656ba6
commit
b5c45cbb45
7 changed files with 98 additions and 42 deletions
|
|
@ -345,7 +345,11 @@ export const editor = {
|
||||||
getAllModels().editor.forEach((item) => {
|
getAllModels().editor.forEach((item) => {
|
||||||
reloadProtyle(item.editor.protyle, false);
|
reloadProtyle(item.editor.protyle, false);
|
||||||
setPadding(item.editor.protyle);
|
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");
|
item.editor.protyle.contentElement.setAttribute("data-fullwidth", "true");
|
||||||
} else {
|
} else {
|
||||||
item.editor.protyle.contentElement.removeAttribute("data-fullwidth");
|
item.editor.protyle.contentElement.removeAttribute("data-fullwidth");
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ export const openFileAttr = (attrs: IObject, focusName = "bookmark") => {
|
||||||
let hasAV = false;
|
let hasAV = false;
|
||||||
const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : null;
|
const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : null;
|
||||||
Object.keys(attrs).forEach(item => {
|
Object.keys(attrs).forEach(item => {
|
||||||
if ("custom-riff-decks" === item) {
|
if ("custom-riff-decks" === item || item.startsWith("custom-sy-")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (item === "custom-reminder-wechat") {
|
if (item === "custom-reminder-wechat") {
|
||||||
|
|
|
||||||
|
|
@ -324,17 +324,6 @@ export class Breadcrumb {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!protyle.disabled) {
|
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({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
label: window.siyuan.languages.netImg2LocalAsset,
|
label: window.siyuan.languages.netImg2LocalAsset,
|
||||||
icon: "iconTransform",
|
icon: "iconTransform",
|
||||||
|
|
@ -386,24 +375,30 @@ export class Breadcrumb {
|
||||||
reloadProtyle(protyle, !isMobile());
|
reloadProtyle(protyle, !isMobile());
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
if (!protyle.disabled) {
|
||||||
icon: "iconTrashcan",
|
|
||||||
label: window.siyuan.languages.delete,
|
|
||||||
click: () => {
|
|
||||||
deleteFile(protyle.notebookId, protyle.path);
|
|
||||||
}
|
|
||||||
}).element);
|
|
||||||
if (!isMobile()) {
|
|
||||||
window.siyuan.menus.menu.append(new MenuItem({
|
window.siyuan.menus.menu.append(new MenuItem({
|
||||||
icon: protyle.element.className.includes("fullscreen") ? "iconFullscreenExit" : "iconFullscreen",
|
label: window.siyuan.languages.optimizeTypography,
|
||||||
accelerator: window.siyuan.config.keymap.editor.general.fullscreen.custom,
|
accelerator: window.siyuan.config.keymap.editor.general.optimizeTypography.custom,
|
||||||
label: window.siyuan.languages.fullscreen,
|
icon: "iconFormat",
|
||||||
click: () => {
|
click: () => {
|
||||||
fullscreen(protyle.element);
|
hideElements(["toolbar"], protyle);
|
||||||
setPadding(protyle);
|
fetchPost("/api/format/autoSpace", {
|
||||||
|
id: protyle.block.rootID
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}).element);
|
}).element);
|
||||||
}
|
}
|
||||||
|
/// #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,
|
||||||
|
label: window.siyuan.languages.fullscreen,
|
||||||
|
click: () => {
|
||||||
|
fullscreen(protyle.element);
|
||||||
|
setPadding(protyle);
|
||||||
|
}
|
||||||
|
}).element);
|
||||||
|
/// #endif
|
||||||
const editSubmenu: IMenu[] = [{
|
const editSubmenu: IMenu[] = [{
|
||||||
current: !protyle.contentElement.classList.contains("fn__none"),
|
current: !protyle.contentElement.classList.contains("fn__none"),
|
||||||
label: window.siyuan.languages.wysiwyg,
|
label: window.siyuan.languages.wysiwyg,
|
||||||
|
|
@ -428,8 +423,54 @@ export class Breadcrumb {
|
||||||
type: "submenu",
|
type: "submenu",
|
||||||
submenu: editSubmenu
|
submenu: editSubmenu
|
||||||
}).element);
|
}).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(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) {
|
if (protyle?.app?.plugins) {
|
||||||
emitOpenMenu({
|
emitOpenMenu({
|
||||||
plugins: protyle.app.plugins,
|
plugins: protyle.app.plugins,
|
||||||
|
|
@ -469,12 +510,12 @@ export class Breadcrumb {
|
||||||
if (getSelection().rangeCount > 0) {
|
if (getSelection().rangeCount > 0) {
|
||||||
range = getSelection().getRangeAt(0);
|
range = getSelection().getRangeAt(0);
|
||||||
if (!protyle.wysiwyg.element.isEqualNode(range.startContainer) && !protyle.wysiwyg.element.contains(range.startContainer)) {
|
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
|
// https://github.com/siyuan-note/siyuan/issues/8807
|
||||||
blockElement = hasClosestBlock(protyle.wysiwyg.element.querySelector('[data-type="search-mark"]')) as Element;
|
blockElement = hasClosestBlock(protyle.wysiwyg.element.querySelector('[data-type="search-mark"]')) as Element;
|
||||||
} else {
|
} else {
|
||||||
blockElement = getNoContainerElement(protyle.wysiwyg.element.firstElementChild) || protyle.wysiwyg.element.firstElementChild;
|
blockElement = getNoContainerElement(protyle.wysiwyg.element.firstElementChild) || protyle.wysiwyg.element.firstElementChild;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
blockElement = hasClosestBlock(range.startContainer) as Element;
|
blockElement = hasClosestBlock(range.startContainer) as Element;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,6 @@ export class Protyle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setPadding(this.protyle);
|
|
||||||
if (options.backlinkData) {
|
if (options.backlinkData) {
|
||||||
this.protyle.block.rootID = options.blockId;
|
this.protyle.block.rootID = options.blockId;
|
||||||
renderBacklink(this.protyle, options.backlinkData);
|
renderBacklink(this.protyle, options.backlinkData);
|
||||||
|
|
@ -300,7 +299,7 @@ export class Protyle {
|
||||||
});
|
});
|
||||||
/// #endif
|
/// #endif
|
||||||
}
|
}
|
||||||
|
setPadding(this.protyle);
|
||||||
// 需等待 getDoc 完成后再执行,否则在无页签的时候 updatePanelByEditor 会执行2次
|
// 需等待 getDoc 完成后再执行,否则在无页签的时候 updatePanelByEditor 会执行2次
|
||||||
// 只能用 focusin,否则点击表格无法执行
|
// 只能用 focusin,否则点击表格无法执行
|
||||||
this.protyle.wysiwyg.element.addEventListener("focusin", () => {
|
this.protyle.wysiwyg.element.addEventListener("focusin", () => {
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,6 @@ import {fetchPost} from "../../util/fetch";
|
||||||
export const initUI = (protyle: IProtyle) => {
|
export const initUI = (protyle: IProtyle) => {
|
||||||
protyle.contentElement = document.createElement("div");
|
protyle.contentElement = document.createElement("div");
|
||||||
protyle.contentElement.className = "protyle-content";
|
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) {
|
if (protyle.options.render.background) {
|
||||||
protyle.contentElement.appendChild(protyle.background.element);
|
protyle.contentElement.appendChild(protyle.background.element);
|
||||||
}
|
}
|
||||||
|
|
@ -129,7 +124,11 @@ export const setPadding = (protyle: IProtyle) => {
|
||||||
let min24 = 24;
|
let min24 = 24;
|
||||||
if (!isMobile()) {
|
if (!isMobile()) {
|
||||||
let padding = (protyle.element.clientWidth - Constants.SIZE_EDITOR_WIDTH) / 2;
|
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) {
|
if (padding > Constants.SIZE_EDITOR_WIDTH) {
|
||||||
// 超宽屏调整 https://ld246.com/article/1668266637363
|
// 超宽屏调整 https://ld246.com/article/1668266637363
|
||||||
padding = protyle.element.clientWidth * .382 / 1.382;
|
padding = protyle.element.clientWidth * .382 / 1.382;
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,15 @@ export class WYSIWYG {
|
||||||
}
|
}
|
||||||
|
|
||||||
public renderCustom(ial: IObject) {
|
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);
|
const ialKeys = Object.keys(ial);
|
||||||
for (let i = 0; i < this.element.attributes.length; i++) {
|
for (let i = 0; i < this.element.attributes.length; i++) {
|
||||||
const oldKey = this.element.attributes[i].nodeName;
|
const oldKey = this.element.attributes[i].nodeName;
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import {hideElements} from "../ui/hideElements";
|
||||||
import {reloadProtyle} from "../util/reload";
|
import {reloadProtyle} from "../util/reload";
|
||||||
import {countBlockWord} from "../../layout/status";
|
import {countBlockWord} from "../../layout/status";
|
||||||
import {needLogin, needSubscribe} from "../../util/needSubscribe";
|
import {needLogin, needSubscribe} from "../../util/needSubscribe";
|
||||||
|
import {setPadding} from "../ui/initUI";
|
||||||
|
|
||||||
const removeTopElement = (updateElement: Element, protyle: IProtyle) => {
|
const removeTopElement = (updateElement: Element, protyle: IProtyle) => {
|
||||||
// 移动到其他文档中,该块需移除
|
// 移动到其他文档中,该块需移除
|
||||||
|
|
@ -424,7 +425,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo:
|
||||||
if (operation.action === "delete") {
|
if (operation.action === "delete") {
|
||||||
if (updateElements.length > 0) {
|
if (updateElements.length > 0) {
|
||||||
deleteBlock(updateElements, operation.id, protyle, isUndo);
|
deleteBlock(updateElements, operation.id, protyle, isUndo);
|
||||||
} else if (isUndo){
|
} else if (isUndo) {
|
||||||
zoomOut({
|
zoomOut({
|
||||||
protyle,
|
protyle,
|
||||||
id: protyle.block.rootID,
|
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.title.element.querySelector(".protyle-attr").innerHTML = nodeAttrHTML;
|
||||||
}
|
}
|
||||||
protyle.wysiwyg.renderCustom(attrsResult);
|
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 (data.new.icon !== data.old.icon) {
|
||||||
/// #if MOBILE
|
/// #if MOBILE
|
||||||
if (window.siyuan.mobile.editor.protyle.background.ial.icon !== data.new.icon) {
|
if (window.siyuan.mobile.editor.protyle.background.ial.icon !== data.new.icon) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue