diff --git a/app/src/protyle/render/av/col.ts b/app/src/protyle/render/av/col.ts index 7506b8633..0d068ee33 100644 --- a/app/src/protyle/render/av/col.ts +++ b/app/src/protyle/render/av/col.ts @@ -158,6 +158,22 @@ export const getEditHTML = (options: {
`; + } else if (colData.type === "rollup") { + html += ` + +`; } return `
${html} diff --git a/app/src/protyle/render/av/openMenuPanel.ts b/app/src/protyle/render/av/openMenuPanel.ts index d45381973..71411c90b 100644 --- a/app/src/protyle/render/av/openMenuPanel.ts +++ b/app/src/protyle/render/av/openMenuPanel.ts @@ -27,6 +27,7 @@ import {focusBlock, getEditorRange} from "../../util/selection"; import {avRender} from "./render"; import {setPageSize} from "./row"; import {bindRelationEvent, getRelationHTML, openSearchAV, setRelationCell, updateRelation} from "./relation"; +import {goSearchRollupCalc, goSearchRollupCol, goSearchRollupTarget} from "./rollup"; export const openMenuPanel = (options: { protyle: IProtyle, @@ -763,6 +764,21 @@ export const openMenuPanel = (options: { event.preventDefault(); event.stopPropagation(); break; + } else if (type === "goSearchRollupCol") { + goSearchRollupCol(avID, target); + event.preventDefault(); + event.stopPropagation(); + break; + } else if (type === "goSearchRollupTarget") { + goSearchRollupTarget(avID, target); + event.preventDefault(); + event.stopPropagation(); + break; + } else if (type === "goSearchRollupCalc") { + goSearchRollupCalc(avID, target); + event.preventDefault(); + event.stopPropagation(); + break; } else if (type === "updateRelation") { updateRelation({ protyle: options.protyle, diff --git a/app/src/protyle/render/av/rollup.ts b/app/src/protyle/render/av/rollup.ts new file mode 100644 index 000000000..d30377903 --- /dev/null +++ b/app/src/protyle/render/av/rollup.ts @@ -0,0 +1,100 @@ +import {Menu} from "../../../plugin/Menu"; +import {hasClosestByClassName} from "../../util/hasClosest"; +import {upDownHint} from "../../../util/upDownHint"; +import {fetchPost} from "../../../util/fetch"; +import {escapeHtml} from "../../../util/escape"; +import {transaction} from "../../wysiwyg/transaction"; +import {updateCellsValue} from "./cell"; +import {updateAttrViewCellAnimation} from "./action"; +import {focusBlock} from "../../util/selection"; + +const genSearchList = (element: Element, keyword: string, avId: string, cb?: () => void) => { + fetchPost("/api/av/searchAttributeViewNonRelationKey", {keyword}, (response) => { + let html = ""; + response.data.results.forEach((item: { + avID: string + avName: string + blockID: string + hPath: string + }, index: number) => { + html += `
+
+
+ ${escapeHtml(item.avName || window.siyuan.languages.title)} +
+
${escapeHtml(item.hPath)}
+
+ +
`; + }); + element.innerHTML = html; + if (cb) { + cb(); + } + }); +}; + +export const goSearchRollupCol = (avId: string, target: HTMLElement) => { + window.siyuan.menus.menu.remove(); + const menu = new Menu(); + menu.addItem({ + iconHTML: "", + type: "empty", + label: `
+ +
+
+ +
+
`, + bind(element) { + const listElement = element.querySelector(".b3-list"); + const inputElement = element.querySelector("input"); + inputElement.addEventListener("keydown", (event: KeyboardEvent) => { + if (event.isComposing) { + return; + } + const currentElement = upDownHint(listElement, event); + if (currentElement) { + event.stopPropagation(); + } + if (event.key === "Enter") { + event.preventDefault(); + event.stopPropagation(); + // setDatabase(avId, target, listElement.querySelector(".b3-list-item--focus")); + window.siyuan.menus.menu.remove(); + } + }); + inputElement.addEventListener("input", (event) => { + event.stopPropagation(); + genSearchList(listElement, inputElement.value, avId); + }); + element.lastElementChild.addEventListener("click", (event) => { + const listItemElement = hasClosestByClassName(event.target as HTMLElement, "b3-list-item"); + if (listItemElement) { + event.stopPropagation(); + // setDatabase(avId, target, listItemElement); + window.siyuan.menus.menu.remove(); + } + }); + genSearchList(listElement, "", avId, () => { + const rect = target.getBoundingClientRect(); + menu.open({ + x: rect.left, + y: rect.bottom, + h: rect.height, + }); + element.querySelector("input").focus(); + }); + } + }); + menu.element.querySelector(".b3-menu__items").setAttribute("style", "overflow: initial"); +}; + +export const goSearchRollupTarget = (avId: string, target: HTMLElement) => { + +} + +export const goSearchRollupCalc = (avId: string, target: HTMLElement) => { + +}