Vanessa 2022-10-05 21:29:56 +08:00
parent a2fb0071e7
commit d5931778cf
6 changed files with 34 additions and 30 deletions

View file

@ -306,7 +306,7 @@ export class Backlink extends Model {
const clickEvent = (currentSort: string) => { const clickEvent = (currentSort: string) => {
(type === "sort" ? this.tree : this.mTree).element.previousElementSibling.querySelector(`[data-type="${type}"]`).setAttribute("data-sort", currentSort); (type === "sort" ? this.tree : this.mTree).element.previousElementSibling.querySelector(`[data-type="${type}"]`).setAttribute("data-sort", currentSort);
this.searchBacklinks(); this.searchBacklinks();
} };
window.siyuan.menus.menu.remove(); window.siyuan.menus.menu.remove();
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
icon: sort === "0" ? "iconSelect" : undefined, icon: sort === "0" ? "iconSelect" : undefined,
@ -314,57 +314,57 @@ export class Backlink extends Model {
click: () => { click: () => {
clickEvent("0"); clickEvent("0");
} }
}).element) }).element);
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
icon: sort === "1" ? "iconSelect" : undefined, icon: sort === "1" ? "iconSelect" : undefined,
label: window.siyuan.languages.fileNameDESC, label: window.siyuan.languages.fileNameDESC,
click: () => { click: () => {
clickEvent("1"); clickEvent("1");
} }
}).element) }).element);
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
icon: sort === "4" ? "iconSelect" : undefined, icon: sort === "4" ? "iconSelect" : undefined,
label: window.siyuan.languages.fileNameNatASC, label: window.siyuan.languages.fileNameNatASC,
click: () => { click: () => {
clickEvent("4"); clickEvent("4");
} }
}).element) }).element);
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
icon: sort === "5" ? "iconSelect" : undefined, icon: sort === "5" ? "iconSelect" : undefined,
label: window.siyuan.languages.fileNameNatDESC, label: window.siyuan.languages.fileNameNatDESC,
click: () => { click: () => {
clickEvent("5"); clickEvent("5");
} }
}).element) }).element);
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element) window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
icon: sort === "9" ? "iconSelect" : undefined, icon: sort === "9" ? "iconSelect" : undefined,
label: window.siyuan.languages.createdASC, label: window.siyuan.languages.createdASC,
click: () => { click: () => {
clickEvent("9"); clickEvent("9");
} }
}).element) }).element);
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
icon: sort === "10" ? "iconSelect" : undefined, icon: sort === "10" ? "iconSelect" : undefined,
label: window.siyuan.languages.createdDESC, label: window.siyuan.languages.createdDESC,
click: () => { click: () => {
clickEvent("10"); clickEvent("10");
} }
}).element) }).element);
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
icon: sort === "2" ? "iconSelect" : undefined, icon: sort === "2" ? "iconSelect" : undefined,
label: window.siyuan.languages.modifiedASC, label: window.siyuan.languages.modifiedASC,
click: () => { click: () => {
clickEvent("2"); clickEvent("2");
} }
}).element) }).element);
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
icon: sort === "3" ? "iconSelect" : undefined, icon: sort === "3" ? "iconSelect" : undefined,
label: window.siyuan.languages.modifiedDESC, label: window.siyuan.languages.modifiedDESC,
click: () => { click: () => {
clickEvent("3"); clickEvent("3");
} }
}).element) }).element);
} }
private toggleItem(liElement: HTMLElement, isMention: boolean) { private toggleItem(liElement: HTMLElement, isMention: boolean) {
@ -443,13 +443,13 @@ export class Backlink extends Model {
backlinkOpenIds: [], backlinkOpenIds: [],
backlinkMOpenIds: [], backlinkMOpenIds: [],
backlinkMStatus: 3 // 0 全展开1 展开一半箭头向下2 展开一半箭头向上3 全收起 backlinkMStatus: 3 // 0 全展开1 展开一半箭头向下2 展开一半箭头向上3 全收起
} };
this.tree.element.querySelectorAll(".b3-list-item__arrow--open").forEach(item => { this.tree.element.querySelectorAll(".b3-list-item__arrow--open").forEach(item => {
this.status[this.blockId].backlinkOpenIds.push(item.parentElement.parentElement.getAttribute("data-node-id")) this.status[this.blockId].backlinkOpenIds.push(item.parentElement.parentElement.getAttribute("data-node-id"));
}) });
this.mTree.element.querySelectorAll(".b3-list-item__arrow--open").forEach(item => { this.mTree.element.querySelectorAll(".b3-list-item__arrow--open").forEach(item => {
this.status[this.blockId].backlinkMOpenIds.push(item.parentElement.parentElement.getAttribute("data-node-id")) this.status[this.blockId].backlinkMOpenIds.push(item.parentElement.parentElement.getAttribute("data-node-id"));
}) });
if (this.mTree.element.style.flex) { if (this.mTree.element.style.flex) {
if (this.mTree.element.style.height === "0px") { if (this.mTree.element.style.height === "0px") {
this.status[this.blockId].backlinkMStatus = 3; this.status[this.blockId].backlinkMStatus = 3;
@ -513,15 +513,15 @@ export class Backlink extends Model {
backlinkOpenIds: [], backlinkOpenIds: [],
backlinkMOpenIds: [], backlinkMOpenIds: [],
backlinkMStatus: 3 backlinkMStatus: 3
} };
if (data.mentionsCount === 0) { if (data.mentionsCount === 0) {
this.status[this.blockId].backlinkMStatus = 3; this.status[this.blockId].backlinkMStatus = 3;
} else { } else {
this.status[this.blockId].backlinkMOpenIds = [data.backmentions[0].id] this.status[this.blockId].backlinkMOpenIds = [data.backmentions[0].id];
if (data.linkRefsCount === 0) { if (data.linkRefsCount === 0) {
this.status[this.blockId].backlinkMStatus = 0; this.status[this.blockId].backlinkMStatus = 0;
} else { } else {
this.status[this.blockId].backlinkOpenIds = [data.backlinks[0].id] this.status[this.blockId].backlinkOpenIds = [data.backlinks[0].id];
this.status[this.blockId].backlinkMStatus = 1; this.status[this.blockId].backlinkMStatus = 1;
} }
} }
@ -529,17 +529,17 @@ export class Backlink extends Model {
// restore status // restore status
this.status[this.blockId].backlinkOpenIds.forEach(item => { this.status[this.blockId].backlinkOpenIds.forEach(item => {
const liElement = this.tree.element.querySelector(`.b3-list-item[data-node-id="${item}"]`) as HTMLElement const liElement = this.tree.element.querySelector(`.b3-list-item[data-node-id="${item}"]`) as HTMLElement;
if (liElement) { if (liElement) {
this.toggleItem(liElement, false); this.toggleItem(liElement, false);
} }
}) });
this.status[this.blockId].backlinkMOpenIds.forEach(item => { this.status[this.blockId].backlinkMOpenIds.forEach(item => {
const liElement = this.mTree.element.querySelector(`.b3-list-item[data-node-id="${item}"]`) as HTMLElement const liElement = this.mTree.element.querySelector(`.b3-list-item[data-node-id="${item}"]`) as HTMLElement;
if (liElement) { if (liElement) {
this.toggleItem(liElement, true); this.toggleItem(liElement, true);
} }
}) });
// 0 全展开1 展开一半箭头向下2 展开一半箭头向上3 全收起 // 0 全展开1 展开一半箭头向下2 展开一半箭头向上3 全收起
const layoutElement = this.mTree.element.previousElementSibling.querySelector('[data-type="layout"]'); const layoutElement = this.mTree.element.previousElementSibling.querySelector('[data-type="layout"]');
if (this.status[this.blockId].backlinkMStatus === 2 || this.status[this.blockId].backlinkMStatus === 1) { if (this.status[this.blockId].backlinkMStatus === 2 || this.status[this.blockId].backlinkMStatus === 1) {
@ -563,8 +563,8 @@ export class Backlink extends Model {
layoutElement.setAttribute("aria-label", window.siyuan.languages.down); layoutElement.setAttribute("aria-label", window.siyuan.languages.down);
layoutElement.querySelector("use").setAttribute("xlink:href", "#iconDown"); layoutElement.querySelector("use").setAttribute("xlink:href", "#iconDown");
} }
this.tree.element.previousElementSibling.querySelector('[data-type="sort"]').setAttribute("data-sort", this.status[this.blockId].sort) this.tree.element.previousElementSibling.querySelector('[data-type="sort"]').setAttribute("data-sort", this.status[this.blockId].sort);
this.mTree.element.previousElementSibling.querySelector('[data-type="mSort"]').setAttribute("data-sort", this.status[this.blockId].mSort) this.mTree.element.previousElementSibling.querySelector('[data-type="mSort"]').setAttribute("data-sort", this.status[this.blockId].mSort);
setTimeout(() => { setTimeout(() => {
this.tree.element.scrollTop = this.status[this.blockId].scrollTop; this.tree.element.scrollTop = this.status[this.blockId].scrollTop;

View file

@ -166,7 +166,7 @@ export const countBlockWord = (ids: string[], rootID?: string) => {
export const clearCounter = () => { export const clearCounter = () => {
document.querySelector("#status .status__counter").innerHTML = ""; document.querySelector("#status .status__counter").innerHTML = "";
} };
export const renderStatusbarCounter = (stat: { runeCount: number, wordCount: number, linkCount: number, imageCount: number, refCount: number }) => { export const renderStatusbarCounter = (stat: { runeCount: number, wordCount: number, linkCount: number, imageCount: number, refCount: number }) => {
let html = `<span class="ft__on-surface">${window.siyuan.languages.runeCount}</span>&nbsp;${stat.runeCount}<span class="fn__space"></span> let html = `<span class="ft__on-surface">${window.siyuan.languages.runeCount}</span>&nbsp;${stat.runeCount}<span class="fn__space"></span>

View file

@ -14,7 +14,7 @@ export const openByMobile = (uri: string) => {
}; };
export const writeText = async (text: string) => { export const writeText = async (text: string) => {
let range: Range let range: Range;
if (getSelection().rangeCount > 0) { if (getSelection().rangeCount > 0) {
range = getSelection().getRangeAt(0).cloneRange(); range = getSelection().getRangeAt(0).cloneRange();
} }

View file

@ -1101,8 +1101,8 @@ export class WYSIWYG {
this.element.addEventListener("contextmenu", (event: MouseEvent & { detail: any }) => { this.element.addEventListener("contextmenu", (event: MouseEvent & { detail: any }) => {
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
const x = event.clientX || event.detail.x const x = event.clientX || event.detail.x;
const y = event.clientY || event.detail.y const y = event.clientY || event.detail.y;
const selectElements = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"); const selectElements = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");
if (selectElements.length > 1) { if (selectElements.length > 1) {
// 多选块 // 多选块
@ -1111,7 +1111,7 @@ export class WYSIWYG {
window.siyuan.menus.menu.popup({x, y}); window.siyuan.menus.menu.popup({x, y});
return; return;
} }
const target = event.detail.target || event.target as HTMLElement const target = event.detail.target || event.target as HTMLElement;
const embedElement = hasClosestByAttribute(target, "data-type", "NodeBlockQueryEmbed"); const embedElement = hasClosestByAttribute(target, "data-type", "NodeBlockQueryEmbed");
if (embedElement) { if (embedElement) {
if (getSelection().rangeCount === 0) { if (getSelection().rangeCount === 0) {

View file

@ -446,6 +446,7 @@ declare interface IFile {
declare interface IBlockTree { declare interface IBlockTree {
nodeType: string, nodeType: string,
hPath: string,
subType: string, subType: string,
name: string, name: string,
type: string, type: string,

View file

@ -57,14 +57,17 @@ export class Tree {
private genHTML(data: IBlockTree[]) { private genHTML(data: IBlockTree[]) {
let html = `<ul${data[0].depth === 0 ? " class='b3-list b3-list--background'" : ""}>`; let html = `<ul${data[0].depth === 0 ? " class='b3-list b3-list--background'" : ""}>`;
data.forEach((item) => { data.forEach((item) => {
let titleTip = "";
let iconHTML = '<svg class="b3-list-item__graphic"><use xlink:href="#iconFolder"></use></svg>'; let iconHTML = '<svg class="b3-list-item__graphic"><use xlink:href="#iconFolder"></use></svg>';
if (item.type === "bookmark") { if (item.type === "bookmark") {
iconHTML = '<svg class="b3-list-item__graphic"><use xlink:href="#iconBookmark"></use></svg>'; iconHTML = '<svg class="b3-list-item__graphic"><use xlink:href="#iconBookmark"></use></svg>';
} else if (item.type === "tag") { } else if (item.type === "tag") {
iconHTML = '<svg class="b3-list-item__graphic"><use xlink:href="#iconTags"></use></svg>'; iconHTML = '<svg class="b3-list-item__graphic"><use xlink:href="#iconTags"></use></svg>';
} else if (item.type === "backlink") { } else if (item.type === "backlink") {
titleTip= ` title="${item.hPath}"`;
iconHTML = `<svg class="b3-list-item__graphic popover__block" data-id="${item.id}"><use xlink:href="#${getIconByType(item.nodeType, item.subType)}"></use></svg>`; iconHTML = `<svg class="b3-list-item__graphic popover__block" data-id="${item.id}"><use xlink:href="#${getIconByType(item.nodeType, item.subType)}"></use></svg>`;
} else if (item.type === "outline") { } else if (item.type === "outline") {
titleTip= ` title="${Lute.EscapeHTMLStr(Lute.BlockDOM2Content(item.name))}"`;
iconHTML = `<svg class="b3-list-item__graphic popover__block" data-id="${item.id}"><use xlink:href="#${getIconByType(item.nodeType, item.subType)}"></use></svg>`; iconHTML = `<svg class="b3-list-item__graphic popover__block" data-id="${item.id}"><use xlink:href="#${getIconByType(item.nodeType, item.subType)}"></use></svg>`;
} }
let countHTML = ""; let countHTML = "";
@ -82,7 +85,7 @@ ${item.label ? "data-label='" + item.label + "'" : ""}>
<svg data-id="${encodeURIComponent(item.name + item.depth)}" class="b3-list-item__arrow ${((item.children && item.children.length > 0) || (item.blocks && item.blocks.length > 0)) ? "b3-list-item__arrow--open" : (item.type === "backlink" ? "" : "fn__hidden")}"><use xlink:href="#iconRight"></use></svg> <svg data-id="${encodeURIComponent(item.name + item.depth)}" class="b3-list-item__arrow ${((item.children && item.children.length > 0) || (item.blocks && item.blocks.length > 0)) ? "b3-list-item__arrow--open" : (item.type === "backlink" ? "" : "fn__hidden")}"><use xlink:href="#iconRight"></use></svg>
</span> </span>
${iconHTML} ${iconHTML}
<span class="b3-list-item__text"${item.type === "outline" ? ' title="' + Lute.EscapeHTMLStr(Lute.BlockDOM2Content(item.name)) + '"' : ""}>${item.name}</span> <span class="b3-list-item__text"${titleTip}>${item.name}</span>
${countHTML} ${countHTML}
${this.topExtHTML || ""} ${this.topExtHTML || ""}
</li>`; </li>`;