From a231b9e12821578547e07842ef2fc710596edaaa Mon Sep 17 00:00:00 2001 From: Vanessa Date: Fri, 28 Jul 2023 15:20:34 +0800 Subject: [PATCH] :sparkles: https://github.com/siyuan-note/siyuan/issues/8665 --- app/src/protyle/hint/extend.ts | 81 +++++++++++------------------ app/src/protyle/hint/index.ts | 36 +++---------- app/src/protyle/render/av/cell.ts | 2 +- app/src/protyle/render/av/render.ts | 2 +- 4 files changed, 40 insertions(+), 81 deletions(-) diff --git a/app/src/protyle/hint/extend.ts b/app/src/protyle/hint/extend.ts index f74bb5c22..7cb329fd8 100644 --- a/app/src/protyle/hint/extend.ts +++ b/app/src/protyle/hint/extend.ts @@ -317,6 +317,35 @@ export const hintTag = (key: string, protyle: IProtyle): IHintData[] => { return []; }; +export const genHintItemHTML = (item: IBlock) => { + let iconHTML; + if (item.type === "NodeDocument" && item.ial.icon) { + iconHTML = unicode2Emoji(item.ial.icon, "b3-list-item__graphic popover__block", true); + iconHTML = iconHTML.replace('popover__block"', `popover__block" data-id="${item.id}"`); + } else { + iconHTML = ``; + } + let attrHTML = ""; + if (item.name) { + attrHTML += `${item.name}`; + } + if (item.alias) { + attrHTML += `${item.alias}`; + } + if (item.memo) { + attrHTML += `${item.memo}`; + } + if (attrHTML) { + attrHTML = `
${attrHTML}
`; + } + + return `${attrHTML}
+ ${iconHTML} + ${item.content} +
+
${item.hPath}
`; +} + export const hintRef = (key: string, protyle: IProtyle, isQuick = false): IHintData[] => { const nodeElement = hasClosestBlock(getEditorRange(protyle.wysiwyg.element).startContainer); protyle.hint.genLoading(protyle); @@ -337,37 +366,13 @@ export const hintRef = (key: string, protyle: IProtyle, isQuick = false): IHintD }); } response.data.blocks.forEach((item: IBlock) => { - let iconHTML; - if (item.type === "NodeDocument" && item.ial.icon) { - iconHTML = unicode2Emoji(item.ial.icon, "b3-list-item__graphic popover__block", true); - iconHTML = iconHTML.replace('popover__block"', `popover__block" data-id="${item.id}"`); - } else { - iconHTML = ``; - } - let attrHTML = ""; - if (item.name) { - attrHTML += `${item.name}`; - } - if (item.alias) { - attrHTML += `${item.alias}`; - } - if (item.memo) { - attrHTML += `${item.memo}`; - } - if (attrHTML) { - attrHTML = `
${attrHTML}
`; - } let value = `${item.name || item.refText}`; if (isQuick) { value = `${key}`; } dataList.push({ value, - html: `${attrHTML}
- ${iconHTML} - ${item.content} -
-
${item.hPath}
`, + html: genHintItemHTML(item), }); }); if (isQuick) { @@ -401,33 +406,9 @@ export const hintEmbed = (key: string, protyle: IProtyle): IHintData[] => { }, (response) => { const dataList: IHintData[] = []; response.data.blocks.forEach((item: IBlock) => { - let iconHTML; - if (item.type === "NodeDocument" && item.ial.icon) { - iconHTML = unicode2Emoji(item.ial.icon, "b3-list-item__graphic popover__block", true); - iconHTML = iconHTML.replace('popover__block"', `popover__block" data-id="${item.id}"`); - } else { - iconHTML = ``; - } - let attrHTML = ""; - if (item.name) { - attrHTML += `${item.name}`; - } - if (item.alias) { - attrHTML += `${item.alias}`; - } - if (item.memo) { - attrHTML += `${item.memo}`; - } - if (attrHTML) { - attrHTML = `
${attrHTML}
`; - } dataList.push({ value: `{{select * from blocks where id='${item.id}'}}`, - html: `${attrHTML}
- ${iconHTML} - ${item.content} -
-
${item.hPath}
`, + html: genHintItemHTML(item), }); }); if (dataList.length === 0) { diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.ts index 94b59adc9..73d4de31d 100644 --- a/app/src/protyle/hint/index.ts +++ b/app/src/protyle/hint/index.ts @@ -8,7 +8,7 @@ import { getSelectionOffset, getSelectionPosition } from "../util/selection"; -import {hintEmbed, hintRef, hintSlash} from "./extend"; +import {genHintItemHTML, hintEmbed, hintRef, hintSlash} from "./extend"; import {getSavePath} from "../../util/newFile"; import {upDownHint} from "../../util/upDownHint"; import {setPosition} from "../../util/setPosition"; @@ -238,7 +238,7 @@ ${unicode2Emoji(emoji.unicode)}`; } } - public getHTMLByData(data: IHintData[], hasSearch = false) { + private getHTMLByData(data: IHintData[], hasSearch = false) { let hintsHTML = ""; if (hasSearch) { hintsHTML = '
'; @@ -338,39 +338,17 @@ ${unicode2Emoji(emoji.unicode)}`; let searchHTML = ""; if (response.data.newDoc) { const blockRefText = `((newFile "${oldValue}"${Constants.ZWSP}'${response.data.k}${Lute.Caret}'))`; - searchHTML += ``; } response.data.blocks.forEach((item: IBlock, index: number) => { - let iconHTML; - if (item.type === "NodeDocument" && item.ial.icon) { - iconHTML = unicode2Emoji(item.ial.icon, "b3-list-item__graphic popover__block", true); - iconHTML = iconHTML.replace('popover__block"', `popover__block" data-id="${item.id}"`); - } else { - iconHTML = ``; - } - let attrHTML = ""; - if (item.name) { - attrHTML += `${item.name}`; - } - if (item.alias) { - attrHTML += `${item.alias}`; - } - if (item.memo) { - attrHTML += `${item.memo}`; - } - if (attrHTML) { - attrHTML = `
${attrHTML}
`; - } const blockRefHTML = `${oldValue}`; - searchHTML += ``; + searchHTML += ``; }); if (searchHTML === "") { - searchHTML = ``; + searchHTML = ``; } this.element.lastElementChild.innerHTML = searchHTML; }); diff --git a/app/src/protyle/render/av/cell.ts b/app/src/protyle/render/av/cell.ts index c31ac4659..5a3f13e02 100644 --- a/app/src/protyle/render/av/cell.ts +++ b/app/src/protyle/render/av/cell.ts @@ -344,7 +344,7 @@ export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[]) => { const style = `style="position:absolute;left: ${cellRect.left}px;top: ${cellRect.top}px;width:${Math.max(cellRect.width, 200)}px;height: ${cellRect.height}px"`; const blockElement = hasClosestBlock(cellElements[0]); if (type === "block" || type === "text") { - html = ``; + html = ``; } else if (type === "number") { html = ``; } else if (["select", "mSelect"].includes(type) && blockElement) { diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.ts index 1d8e1004b..b1ac01b82 100644 --- a/app/src/protyle/render/av/render.ts +++ b/app/src/protyle/render/av/render.ts @@ -64,7 +64,7 @@ style="width: ${column.width || "200px"}">${getCalcValue(column) || '${cell.value?.block.content || ""}`; if (cell.value?.block.id) { - text += `${window.siyuan.languages.openBy}`; + text += `${window.siyuan.languages.openBy}`; } } else if (cell.valueType === "number") { text = `${cell.value?.number.content || ""}`;