Vanessa 2022-09-29 23:08:37 +08:00
parent 268f83cf9e
commit 902ad918c1
4 changed files with 35 additions and 8 deletions

View File

@ -81,7 +81,7 @@ class Protyle {
}
this.init();
if (!options.action.includes(Constants.CB_GET_HISTORY)) {
if (!mergedOptions.action.includes(Constants.CB_GET_HISTORY)) {
this.protyle.ws = new Model({
id: this.protyle.id,
type: "protyle",
@ -164,13 +164,13 @@ class Protyle {
fetchPost("/api/filetree/getDoc", {
id: options.blockId,
k: options.key || "",
mode: (options.action && options.action.includes(Constants.CB_GET_CONTEXT)) ? 3 : 0, // 0: 仅当前 ID默认值1向上 2向下3上下都加载4加载最后
size: options.action?.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
mode: (mergedOptions.action && mergedOptions.action.includes(Constants.CB_GET_CONTEXT)) ? 3 : 0, // 0: 仅当前 ID默认值1向上 2向下3上下都加载4加载最后
size: mergedOptions.action?.includes(Constants.CB_GET_ALL) ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
}, getResponse => {
onGet(getResponse, this.protyle, options.action, options.scrollAttr);
onGet(getResponse, this.protyle, mergedOptions.action, options.scrollAttr);
if (this.protyle.model) {
/// #if !MOBILE
if (options.action?.includes(Constants.CB_GET_FOCUS)) {
if (mergedOptions.action?.includes(Constants.CB_GET_FOCUS)) {
setPanelFocus(this.protyle.model.element.parentElement.parentElement);
}
updatePanelByEditor(this.protyle, false);

View File

@ -17,6 +17,7 @@ export class Options {
breadcrumbDocName: false,
breadcrumbContext: false
},
action: [],
after: undefined,
classes: {
preview: "",

View File

@ -136,7 +136,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
window.siyuan.menus.menu.remove();
}
if (!["Alt", "Meta", "Shift", "Control", "CapsLock", "Escape"].includes(event.key)) {
if (!["Alt", "Meta", "Shift", "Control", "CapsLock", "Escape"].includes(event.key) && protyle.options.render.breadcrumb) {
protyle.breadcrumb.hide();
}

View File

@ -1,6 +1,32 @@
export const renderBacklink = (protype: IProtyle, backlinkData: {
import {getIconByType} from "../../editor/getIcon";
import {removeLoading} from "../ui/initUI";
export const renderBacklink = (protyle: IProtyle, backlinkData: {
blockPaths: IBreadcrumb[],
dom: string
}[]) => {
protyle.block.showAll = true
let html = ""
backlinkData.forEach(item => {
html += genBreadcrumb(item.blockPaths) + item.dom
});
protyle.wysiwyg.element.innerHTML = html
removeLoading(protyle);
}
const genBreadcrumb = (blockPaths: IBreadcrumb[]) => {
let html = ''
blockPaths.forEach((item, index) => {
if (index === 0) {
return;
}
html += `<span class="protyle-breadcrumb__item" data-node-id="${item.id}">
<svg class="popover__block" data-id="${item.id}"><use xlink:href="#${getIconByType(item.type, item.subType)}"></use></svg>
<span class="protyle-breadcrumb__text" title="${item.name}">${item.name}</span>
</span>`;
if (index !== blockPaths.length - 1) {
html += '<svg class="protyle-breadcrumb__arrow"><use xlink:href="#iconRight"></use></svg>';
}
})
return `<div contenteditable="false" class="protyle-breadcrumb__bar protyle-breadcrumb__bar--nowrap">${html}</div>`;
}