Vanessa 2023-04-28 10:30:27 +08:00
parent 9edcd3f3a7
commit 9cb6e9ec25
10 changed files with 198 additions and 118 deletions

View file

@ -3,13 +3,15 @@ import {getInstanceById, getWndByLayout} from "../layout/util";
import {Tab} from "../layout/Tab"; import {Tab} from "../layout/Tab";
import {Custom} from "../layout/dock/Custom"; import {Custom} from "../layout/dock/Custom";
import {Dialog} from "../dialog"; import {Dialog} from "../dialog";
import {genCardHTML} from "./openCard"; import {bindCardEvent, genCardHTML} from "./openCard";
import {fetchPost} from "../util/fetch"; import {fetchPost} from "../util/fetch";
import {Protyle} from "../protyle";
export const newCardTab = (options: { export const newCardTab = (options: {
type: TCardType, cardType: TCardType,
id: string, id: string,
dialog: Dialog dialog: Dialog,
title?: string
}) => { }) => {
let wnd: Wnd; let wnd: Wnd;
const element = document.querySelector(".layout__wnd--active"); const element = document.querySelector(".layout__wnd--active");
@ -19,6 +21,7 @@ export const newCardTab = (options: {
if (!wnd) { if (!wnd) {
wnd = getWndByLayout(window.siyuan.layout.centerLayout); wnd = getWndByLayout(window.siyuan.layout.centerLayout);
} }
let editor: Protyle
const tab = new Tab({ const tab = new Tab({
icon: "iconRiffCard", icon: "iconRiffCard",
title: window.siyuan.languages.spaceRepetition, title: window.siyuan.languages.spaceRepetition,
@ -27,23 +30,39 @@ export const newCardTab = (options: {
type: "card", type: "card",
tab, tab,
data: { data: {
type: options.type, title: options.title,
cardType: options.cardType,
id: options.id id: options.id
}, },
init(element) { init(element) {
fetchPost(options.type === "all" ? "/api/riff/getRiffDueCards" : fetchPost(options.cardType === "all" ? "/api/riff/getRiffDueCards" :
(options.type === "doc" ? "/api/riff/getTreeRiffDueCards" : "/api/riff/getNotebookRiffDueCards"), { (options.cardType === "doc" ? "/api/riff/getTreeRiffDueCards" : "/api/riff/getNotebookRiffDueCards"), {
rootID: options.id, rootID: options.id,
deckID: options.id, deckID: options.id,
notebook: options.id, notebook: options.id,
}, (response) => { }, (response) => {
element.innerHTML = genCardHTML({ element.innerHTML = genCardHTML({
id: options.id, id: options.id,
cardType: options.type, cardType: options.cardType,
blocks: response.data, blocks: response.data.cards,
isTab: true, isTab: true,
}); });
editor = bindCardEvent({
element,
id: options.id,
title: options.title,
cardType: options.cardType,
blocks: response.data.cards,
dialog: options.dialog,
})
}); });
},
destroy() {
editor.destroy();
},
resize(){
editor.resize();
} }
}); });
tab.addModel(custom); tab.addModel(custom);

View file

@ -33,8 +33,8 @@ export const genCardHTML = (options: {
<svg><use xlink:href="#iconCloseRound"></use></svg> <svg><use xlink:href="#iconCloseRound"></use></svg>
</div>` : `<div data-type="fullscreen" class="b3-tooltips b3-tooltips__sw block__icon block__icon--show" aria-label="${window.siyuan.languages.fullscreen}"> </div>` : `<div data-type="fullscreen" class="b3-tooltips b3-tooltips__sw block__icon block__icon--show" aria-label="${window.siyuan.languages.fullscreen}">
<svg><use xlink:href="#iconFullscreen"></use></svg> <svg><use xlink:href="#iconFullscreen"></use></svg>
</div><div class="fn__space"></div> </div><div class="fn__space${options.isTab ? " fn__none" : ""}"></div>
<div data-type="sticktab" class="b3-tooltips b3-tooltips__sw block__icon block__icon--show" aria-label="${window.siyuan.languages.openInNewTab}"> <div data-type="sticktab" class="b3-tooltips b3-tooltips__sw block__icon block__icon--show${options.isTab ? " fn__none" : ""}" aria-label="${window.siyuan.languages.openInNewTab}">
<svg><use xlink:href="#iconLayoutRight"></use></svg> <svg><use xlink:href="#iconLayoutRight"></use></svg>
</div>`} </div>`}
</div> </div>
@ -54,35 +54,35 @@ export const genCardHTML = (options: {
<div class="fn__flex card__action fn__none"> <div class="fn__flex card__action fn__none">
<div> <div>
<span>${window.siyuan.languages.nextRound}</span> <span>${window.siyuan.languages.nextRound}</span>
<button data-type="-3" aria-label="0" class="b3-button b3-button--cancel b3-tooltips__s b3-tooltips"> <button data-type="-3" aria-label="0" class="b3-button b3-button--cancel b3-tooltips__n b3-tooltips">
<div>💤</div> <div>💤</div>
${window.siyuan.languages.skip} (0) ${window.siyuan.languages.skip} (0)
</button> </button>
</div> </div>
<div> <div>
<span></span> <span></span>
<button data-type="0" aria-label="1 / j" class="b3-button b3-button--error b3-tooltips__s b3-tooltips"> <button data-type="0" aria-label="1 / j" class="b3-button b3-button--error b3-tooltips__n b3-tooltips">
<div>🙈</div> <div>🙈</div>
${window.siyuan.languages.cardRatingAgain} (1) ${window.siyuan.languages.cardRatingAgain} (1)
</button> </button>
</div> </div>
<div> <div>
<span></span> <span></span>
<button data-type="1" aria-label="2 / k" class="b3-button b3-button--warning b3-tooltips__s b3-tooltips"> <button data-type="1" aria-label="2 / k" class="b3-button b3-button--warning b3-tooltips__n b3-tooltips">
<div>😬</div> <div>😬</div>
${window.siyuan.languages.cardRatingHard} (2) ${window.siyuan.languages.cardRatingHard} (2)
</button> </button>
</div> </div>
<div> <div>
<span></span> <span></span>
<button data-type="2" aria-label="3 / l" class="b3-button b3-button--info b3-tooltips__s b3-tooltips"> <button data-type="2" aria-label="3 / l" class="b3-button b3-button--info b3-tooltips__n b3-tooltips">
<div>😊</div> <div>😊</div>
${window.siyuan.languages.cardRatingGood} (3) ${window.siyuan.languages.cardRatingGood} (3)
</button> </button>
</div> </div>
<div> <div>
<span></span> <span></span>
<button data-type="3" aria-label="4 / ;" class="b3-button b3-button--success b3-tooltips__s b3-tooltips"> <button data-type="3" aria-label="4 / ;" class="b3-button b3-button--success b3-tooltips__n b3-tooltips">
<div>🌈</div> <div>🌈</div>
${window.siyuan.languages.cardRatingEasy} (4) ${window.siyuan.languages.cardRatingEasy} (4)
</button> </button>
@ -91,44 +91,16 @@ export const genCardHTML = (options: {
</div>`; </div>`;
}; };
export const openCard = () => { export const bindCardEvent = (options: {
fetchPost("/api/riff/getRiffDueCards", {deckID: ""}, (cardsResponse) => { element: Element,
openCardByData(cardsResponse.data, "all"); title?: string,
}); blocks: ICard[],
}; cardType: TCardType,
id?: string,
export const openCardByData = (cardsData: { dialog: Dialog,
cards: ICard[], }) => {
unreviewedCount: number
}, cardType: TCardType, id?: string, title?: string) => {
const exit = window.siyuan.dialogs.find(item => {
if (item.element.getAttribute("data-key") === window.siyuan.config.keymap.general.riffCard.custom) {
item.destroy();
return true;
}
});
if (exit) {
return;
}
let blocks = cardsData.cards;
let index = 0; let index = 0;
const dialog = new Dialog({ const editor = new Protyle(options.element.querySelector("[data-type='render']") as HTMLElement, {
content: genCardHTML({id, cardType, blocks, isTab: false}),
width: isMobile() ? "100vw" : "80vw",
height: isMobile() ? "100vh" : "70vh",
destroyCallback() {
if (editor) {
editor.destroy();
if (window.siyuan.mobile) {
window.siyuan.mobile.popEditor = null;
}
}
}
});
(dialog.element.querySelector(".b3-dialog__scrim") as HTMLElement).style.backgroundColor = "var(--b3-theme-background)";
(dialog.element.querySelector(".b3-dialog__container") as HTMLElement).style.maxWidth = "1024px";
const editor = new Protyle(dialog.element.querySelector("[data-type='render']") as HTMLElement, {
blockId: "", blockId: "",
action: [Constants.CB_GET_ALL], action: [Constants.CB_GET_ALL],
render: { render: {
@ -145,20 +117,20 @@ export const openCardByData = (cardsData: {
if (window.siyuan.config.editor.readOnly) { if (window.siyuan.config.editor.readOnly) {
disabledProtyle(editor.protyle); disabledProtyle(editor.protyle);
} }
if (blocks.length > 0) { if (options.blocks.length > 0) {
fetchPost("/api/filetree/getDoc", { fetchPost("/api/filetree/getDoc", {
id: blocks[index].blockID, id: options.blocks[index].blockID,
mode: 0, mode: 0,
size: Constants.SIZE_GET_MAX size: Constants.SIZE_GET_MAX
}, (response) => { }, (response) => {
onGet(response, editor.protyle, [Constants.CB_GET_ALL, Constants.CB_GET_HTML]); onGet(response, editor.protyle, [Constants.CB_GET_ALL, Constants.CB_GET_HTML]);
}); });
} }
(dialog.element.firstElementChild as HTMLElement).style.zIndex = "200"; (options.element.firstElementChild as HTMLElement).style.zIndex = "200";
dialog.element.setAttribute("data-key", window.siyuan.config.keymap.general.riffCard.custom); options.element.setAttribute("data-key", window.siyuan.config.keymap.general.riffCard.custom);
const countElement = dialog.element.querySelector('[data-type="count"]'); const countElement = options.element.querySelector('[data-type="count"]');
const actionElements = dialog.element.querySelectorAll(".card__action"); const actionElements = options.element.querySelectorAll(".card__action");
const filterElement = dialog.element.querySelector('[data-type="filter"]'); const filterElement = options.element.querySelector('[data-type="filter"]');
const fetchNewRound = () => { const fetchNewRound = () => {
const currentCardType = filterElement.getAttribute("data-cardtype"); const currentCardType = filterElement.getAttribute("data-cardtype");
fetchPost(currentCardType === "all" ? "/api/riff/getRiffDueCards" : fetchPost(currentCardType === "all" ? "/api/riff/getRiffDueCards" :
@ -168,14 +140,14 @@ export const openCardByData = (cardsData: {
notebook: filterElement.getAttribute("data-id"), notebook: filterElement.getAttribute("data-id"),
}, (treeCards) => { }, (treeCards) => {
index = 0; index = 0;
blocks = treeCards.data.cards; options.blocks = treeCards.data.cards;
if (blocks.length > 0) { if (options.blocks.length > 0) {
nextCard({ nextCard({
countElement, countElement,
editor, editor,
actionElements, actionElements,
index, index,
blocks blocks: options.blocks
}); });
} else { } else {
allDone(countElement, editor, actionElements); allDone(countElement, editor, actionElements);
@ -183,7 +155,7 @@ export const openCardByData = (cardsData: {
}); });
}; };
dialog.element.addEventListener("click", (event) => { options.element.addEventListener("click", (event: MouseEvent) => {
const target = event.target as HTMLElement; const target = event.target as HTMLElement;
let type = ""; let type = "";
if (typeof event.detail === "string") { if (typeof event.detail === "string") {
@ -205,8 +177,8 @@ export const openCardByData = (cardsData: {
} else { } else {
const fullscreenElement = hasClosestByAttribute(target, "data-type", "fullscreen"); const fullscreenElement = hasClosestByAttribute(target, "data-type", "fullscreen");
if (fullscreenElement) { if (fullscreenElement) {
fullscreen(dialog.element.querySelector(".card__main"), fullscreen(options.element.querySelector(".card__main"),
dialog.element.querySelector('[data-type="fullscreen"]')); options.element.querySelector('[data-type="fullscreen"]'));
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
return; return;
@ -214,9 +186,10 @@ export const openCardByData = (cardsData: {
const sticktabElement = hasClosestByAttribute(target, "data-type", "sticktab"); const sticktabElement = hasClosestByAttribute(target, "data-type", "sticktab");
if (sticktabElement) { if (sticktabElement) {
newCardTab({ newCardTab({
type: filterElement.getAttribute("data-cardtype") as TCardType, cardType: filterElement.getAttribute("data-cardtype") as TCardType,
id: filterElement.getAttribute("data-id"), id: filterElement.getAttribute("data-id"),
dialog, dialog: options.dialog,
title: options.title
}); });
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
@ -224,7 +197,7 @@ export const openCardByData = (cardsData: {
} }
const closeElement = hasClosestByAttribute(target, "data-type", "close"); const closeElement = hasClosestByAttribute(target, "data-type", "close");
if (closeElement) { if (closeElement) {
dialog.destroy(); options.dialog.destroy();
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
return; return;
@ -253,16 +226,16 @@ export const openCardByData = (cardsData: {
}, [], undefined, window.siyuan.languages.specifyPath, true); }, [], undefined, window.siyuan.languages.specifyPath, true);
} }
}).element); }).element);
if (title || response.data.length > 0) { if (options.title || response.data.length > 0) {
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element); window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
} }
if (title) { if (options.title) {
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
iconHTML: Constants.ZWSP, iconHTML: Constants.ZWSP,
label: escapeHtml(title), label: escapeHtml(options.title),
click() { click() {
filterElement.setAttribute("data-id", id); filterElement.setAttribute("data-id", options.id);
filterElement.setAttribute("data-cardtype", cardType); filterElement.setAttribute("data-cardtype", options.cardType);
fetchNewRound(); fetchNewRound();
}, },
}).element); }).element);
@ -301,7 +274,7 @@ export const openCardByData = (cardsData: {
type = buttonElement.getAttribute("data-type"); type = buttonElement.getAttribute("data-type");
} }
} }
if (!type || !blocks[index]) { if (!type || !options.blocks[index]) {
return; return;
} }
event.preventDefault(); event.preventDefault();
@ -315,7 +288,7 @@ export const openCardByData = (cardsData: {
actionElements[0].classList.add("fn__none"); actionElements[0].classList.add("fn__none");
actionElements[1].querySelectorAll(".b3-button").forEach((element, btnIndex) => { actionElements[1].querySelectorAll(".b3-button").forEach((element, btnIndex) => {
if (btnIndex !== 0) { if (btnIndex !== 0) {
element.previousElementSibling.textContent = blocks[index].nextDues[btnIndex - 1]; element.previousElementSibling.textContent = options.blocks[index].nextDues[btnIndex - 1];
} }
}); });
actionElements[1].classList.remove("fn__none"); actionElements[1].classList.remove("fn__none");
@ -332,17 +305,17 @@ export const openCardByData = (cardsData: {
editor, editor,
actionElements, actionElements,
index, index,
blocks blocks: options.blocks
}); });
} }
return; return;
} }
if (["0", "1", "2", "3", "-3"].includes(type) && actionElements[0].classList.contains("fn__none")) { if (["0", "1", "2", "3", "-3"].includes(type) && actionElements[0].classList.contains("fn__none")) {
fetchPost(type === "-3" ? "/api/riff/skipReviewRiffCard" : "/api/riff/reviewRiffCard", { fetchPost(type === "-3" ? "/api/riff/skipReviewRiffCard" : "/api/riff/reviewRiffCard", {
deckID: blocks[index].deckID, deckID: options.blocks[index].deckID,
cardID: blocks[index].cardID, cardID: options.blocks[index].cardID,
rating: parseInt(type), rating: parseInt(type),
reviewedCards: blocks reviewedCards: options.blocks
}, () => { }, () => {
/// #if MOBILE /// #if MOBILE
if (type !== "-3" && if (type !== "-3" &&
@ -352,18 +325,18 @@ export const openCardByData = (cardsData: {
} }
/// #endif /// #endif
index++; index++;
if (index > blocks.length - 1) { if (index > options.blocks.length - 1) {
const currentCardType = filterElement.getAttribute("data-cardtype"); const currentCardType = filterElement.getAttribute("data-cardtype");
fetchPost(currentCardType === "all" ? "/api/riff/getRiffDueCards" : fetchPost(currentCardType === "all" ? "/api/riff/getRiffDueCards" :
(currentCardType === "doc" ? "/api/riff/getTreeRiffDueCards" : "/api/riff/getNotebookRiffDueCards"), { (currentCardType === "doc" ? "/api/riff/getTreeRiffDueCards" : "/api/riff/getNotebookRiffDueCards"), {
rootID: filterElement.getAttribute("data-id"), rootID: filterElement.getAttribute("data-id"),
deckID: filterElement.getAttribute("data-id"), deckID: filterElement.getAttribute("data-id"),
notebook: filterElement.getAttribute("data-id"), notebook: filterElement.getAttribute("data-id"),
reviewedCards: blocks reviewedCards: options.blocks
}, (result) => { }, (result) => {
index = 0; index = 0;
blocks = result.data.cards; options.blocks = result.data.cards;
if (blocks.length === 0) { if (options.blocks.length === 0) {
if (result.data.unreviewedCount > 0) { if (result.data.unreviewedCount > 0) {
newRound(countElement, editor, actionElements, result.data.unreviewedCount); newRound(countElement, editor, actionElements, result.data.unreviewedCount);
} else { } else {
@ -375,7 +348,7 @@ export const openCardByData = (cardsData: {
editor, editor,
actionElements, actionElements,
index, index,
blocks blocks: options.blocks
}); });
} }
}); });
@ -386,11 +359,57 @@ export const openCardByData = (cardsData: {
editor, editor,
actionElements, actionElements,
index, index,
blocks blocks: options.blocks
}); });
}); });
} }
}); });
return editor;
};
export const openCard = () => {
fetchPost("/api/riff/getRiffDueCards", {deckID: ""}, (cardsResponse) => {
openCardByData(cardsResponse.data, "all");
});
};
export const openCardByData = (cardsData: {
cards: ICard[],
unreviewedCount: number
}, cardType: TCardType, id?: string, title?: string) => {
const exit = window.siyuan.dialogs.find(item => {
if (item.element.getAttribute("data-key") === window.siyuan.config.keymap.general.riffCard.custom) {
item.destroy();
return true;
}
});
if (exit) {
return;
}
const dialog = new Dialog({
content: genCardHTML({id, cardType, blocks: cardsData.cards, isTab: false}),
width: isMobile() ? "100vw" : "80vw",
height: isMobile() ? "100vh" : "70vh",
destroyCallback() {
if (editor) {
editor.destroy();
if (window.siyuan.mobile) {
window.siyuan.mobile.popEditor = null;
}
}
}
});
(dialog.element.querySelector(".b3-dialog__scrim") as HTMLElement).style.backgroundColor = "var(--b3-theme-background)";
(dialog.element.querySelector(".b3-dialog__container") as HTMLElement).style.maxWidth = "1024px";
const editor = bindCardEvent({
element: dialog.element,
blocks: cardsData.cards,
title,
id,
cardType,
dialog
});
}; };
const nextCard = (options: { const nextCard = (options: {

View file

@ -25,6 +25,7 @@ import {zoomOut} from "../menus/protyle";
import {countBlockWord, countSelectWord} from "../layout/status"; import {countBlockWord, countSelectWord} from "../layout/status";
import {showMessage} from "../dialog/message"; import {showMessage} from "../dialog/message";
import {getSearch} from "../util/functions"; import {getSearch} from "../util/functions";
import {resize} from "../protyle/util/resize";
export const openFileById = async (options: { export const openFileById = async (options: {
id: string, id: string,
@ -390,7 +391,7 @@ export const updatePanelByEditor = (protyle?: IProtyle, focus = true, pushBackSt
return; return;
} }
title = protyle.title.editElement.textContent; title = protyle.title.editElement.textContent;
setPadding(protyle); resize(protyle);
if (focus) { if (focus) {
if (protyle.toolbar.range) { if (protyle.toolbar.range) {
focusByRange(protyle.toolbar.range); focusByRange(protyle.toolbar.range);

View file

@ -33,6 +33,7 @@ import {escapeHtml} from "../util/escape";
import {isWindow} from "../util/functions"; import {isWindow} from "../util/functions";
import {hideAllElements} from "../protyle/ui/hideElements"; import {hideAllElements} from "../protyle/ui/hideElements";
import {focusByOffset, getSelectionOffset} from "../protyle/util/selection"; import {focusByOffset, getSelectionOffset} from "../protyle/util/selection";
import {Custom} from "./dock/Custom";
export class Wnd { export class Wnd {
public id: string; public id: string;
@ -646,6 +647,9 @@ export class Wnd {
model.pdfObject.pdfLoadingTask.destroy(); model.pdfObject.pdfLoadingTask.destroy();
} }
} }
if (model instanceof Custom) {
model.destroy();
}
model.send("closews", {}); model.send("closews", {});
} }

View file

@ -8,6 +8,8 @@ export class Custom extends Model {
constructor(options: { constructor(options: {
tab: Tab, tab: Tab,
data: any, data: any,
destroy?: () => void,
resize?: () => void,
type: string, // 同一类型的唯一标识 type: string, // 同一类型的唯一标识
init: (element: Element) => void init: (element: Element) => void
}) { }) {
@ -20,10 +22,24 @@ export class Custom extends Model {
this.element.addEventListener("click", () => { this.element.addEventListener("click", () => {
setPanelFocus(this.element.parentElement.parentElement); setPanelFocus(this.element.parentElement.parentElement);
}); });
this.update(); this.data = options.data;
this.destroy = options.destroy;
this.resize = options.resize;
}
public destroy() {
if (this.destroy) {
this.destroy();
}
}
public resize() {
if (this.resize) {
this.resize();
}
} }
private update() { private update() {
this.element.innerHTML = `eee` // TODO
} }
} }

View file

@ -9,6 +9,7 @@ import {Search} from "../search";
import {Files} from "./dock/Files"; import {Files} from "./dock/Files";
import {Bookmark} from "./dock/Bookmark"; import {Bookmark} from "./dock/Bookmark";
import {Tag} from "./dock/Tag"; import {Tag} from "./dock/Tag";
import {Custom} from "./dock/Custom";
export const getAllModels = () => { export const getAllModels = () => {
const models: IModels = { const models: IModels = {
@ -21,7 +22,8 @@ export const getAllModels = () => {
inbox: [], inbox: [],
files: [], files: [],
bookmark: [], bookmark: [],
tag: [] tag: [],
custom: [],
}; };
const getTabs = (layout: Layout) => { const getTabs = (layout: Layout) => {
for (let i = 0; i < layout.children.length; i++) { for (let i = 0; i < layout.children.length; i++) {
@ -46,6 +48,8 @@ export const getAllModels = () => {
models.bookmark.push(model); models.bookmark.push(model);
} else if (model instanceof Tag) { } else if (model instanceof Tag) {
models.tag.push(model); models.tag.push(model);
} else if (model instanceof Custom) {
models.custom.push(model);
} }
} else { } else {
getTabs(item as Layout); getTabs(item as Layout);

View file

@ -532,34 +532,9 @@ export const resizeTabs = () => {
resizeTimeout = window.setTimeout(() => { resizeTimeout = window.setTimeout(() => {
const models = getAllModels(); const models = getAllModels();
models.editor.forEach((item) => { models.editor.forEach((item) => {
if (item.editor && item.editor.protyle && item.element.parentElement) { if (item.editor && item.editor.protyle &&
hideElements(["gutter"], item.editor.protyle); item.element.parentElement && !item.element.classList.contains("fn__none")) {
setPadding(item.editor.protyle); item.editor.resize();
if (typeof echarts !== "undefined") {
item.editor.protyle.wysiwyg.element.querySelectorAll('[data-subtype="echarts"], [data-subtype="mindmap"]').forEach((chartItem: HTMLElement) => {
const chartInstance = echarts.getInstanceById(chartItem.firstElementChild.nextElementSibling.getAttribute("_echarts_instance_"));
if (chartInstance) {
chartInstance.resize();
}
});
}
// 保持光标位置不变 https://ld246.com/article/1673704873983/comment/1673765814595#comments
if (!item.element.classList.contains("fn__none") && item.editor.protyle.toolbar.range) {
let rangeRect = item.editor.protyle.toolbar.range.getBoundingClientRect();
if (rangeRect.height === 0) {
const blockElement = hasClosestBlock(item.editor.protyle.toolbar.range.startContainer);
if (blockElement) {
rangeRect = blockElement.getBoundingClientRect();
}
}
if (rangeRect.height === 0) {
return;
}
const protyleRect = item.editor.protyle.element.getBoundingClientRect();
if (protyleRect.top + 30 > rangeRect.top || protyleRect.bottom < rangeRect.bottom) {
item.editor.protyle.toolbar.range.startContainer.parentElement.scrollIntoView(protyleRect.top > rangeRect.top);
}
}
} }
}); });
// https://github.com/siyuan-note/siyuan/issues/6250 // https://github.com/siyuan-note/siyuan/issues/6250
@ -572,6 +547,9 @@ export const resizeTabs = () => {
hideElements(["gutter"], editorItem.protyle); hideElements(["gutter"], editorItem.protyle);
}); });
}); });
models.custom.forEach(item => {
item.resize();
})
pdfResize(); pdfResize();
hideAllElements(["gutter"]); hideAllElements(["gutter"]);
}, 200); }, 200);

View file

@ -26,6 +26,7 @@ import {disabledProtyle, enableProtyle, onGet} from "./util/onGet";
import {reloadProtyle} from "./util/reload"; import {reloadProtyle} from "./util/reload";
import {renderBacklink} from "./wysiwyg/renderBacklink"; import {renderBacklink} from "./wysiwyg/renderBacklink";
import {setEmpty} from "../mobile/util/setEmpty"; import {setEmpty} from "../mobile/util/setEmpty";
import {resize} from "./util/resize";
export class Protyle { export class Protyle {
@ -271,4 +272,8 @@ export class Protyle {
public destroy() { public destroy() {
destroy(this.protyle); destroy(this.protyle);
} }
public resize() {
resize(this.protyle);
}
} }

View file

@ -0,0 +1,33 @@
import {hideElements} from "../ui/hideElements";
import {setPadding} from "../ui/initUI";
import {hasClosestBlock} from "./hasClosest";
export const resize = (protyle: IProtyle) => {
hideElements(["gutter"], protyle);
setPadding(protyle);
if (typeof echarts !== "undefined") {
protyle.wysiwyg.element.querySelectorAll('[data-subtype="echarts"], [data-subtype="mindmap"]').forEach((chartItem: HTMLElement) => {
const chartInstance = echarts.getInstanceById(chartItem.firstElementChild.nextElementSibling.getAttribute("_echarts_instance_"));
if (chartInstance) {
chartInstance.resize();
}
});
}
// 保持光标位置不变 https://ld246.com/article/1673704873983/comment/1673765814595#comments
if (protyle.toolbar.range) {
let rangeRect = protyle.toolbar.range.getBoundingClientRect();
if (rangeRect.height === 0) {
const blockElement = hasClosestBlock(protyle.toolbar.range.startContainer);
if (blockElement) {
rangeRect = blockElement.getBoundingClientRect();
}
}
if (rangeRect.height === 0) {
return;
}
const protyleRect = protyle.element.getBoundingClientRect();
if (protyleRect.top + 30 > rangeRect.top || protyleRect.bottom < rangeRect.bottom) {
protyle.toolbar.range.startContainer.parentElement.scrollIntoView(protyleRect.top > rangeRect.top);
}
}
};

View file

@ -658,6 +658,7 @@ declare interface IModels {
tag: import("../layout/dock/Tag").Tag[] tag: import("../layout/dock/Tag").Tag[]
asset: import("../asset").Asset[] asset: import("../asset").Asset[]
search: import("../search").Search[] search: import("../search").Search[]
custom: import("../layout/dock/Custom").Custom[]
} }
declare interface IMenu { declare interface IMenu {