Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/9958

Vanessa4eba1176be51
diff --git a/app/src/protyle/render/av/col.ts b/app/src/protyle/render/av/col.ts
index 7506b86333..0d068ee332 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: {
<div class="b3-menu__item fn__flex-column fn__none" data-type="nobg">
<button style="margin: 4px 0 8px;" class="b3-button fn__block" data-type="updateRelation">${window.siyuan.languages.confirm}</button>
</div>`;
+ } else if (colData.type === "rollup") {
+ html += `<button class="b3-menu__item" data-type="goSearchRollupCol" data-av-id="${colData.relation?.avID || ""}" data-old-value='${JSON.stringify(colData.relation || {})}'>
+ <span class="b3-menu__label">${window.siyuan.languages.relation}</span>
+ <span class="b3-menu__accelerator">TODO</span>
+ <svg class="b3-menu__icon b3-menu__icon--small"><use xlink:href="#iconRight"></use></svg>
+</button>
+<button class="b3-menu__item b3-menu__item--disabled" data-type="goSearchRollupTarget" data-av-id="${colData.relation?.avID || ""}" data-old-value='${JSON.stringify(colData.relation || {})}'>
+ <span class="b3-menu__label">${window.siyuan.languages.attr}</span>
+ <span class="b3-menu__accelerator">TODO</span>
+ <svg class="b3-menu__icon b3-menu__icon--small"><use xlink:href="#iconRight"></use></svg>
+</button>
+<button class="b3-menu__item b3-menu__item--disabled" data-type="goSearchRollupCalc" data-av-id="${colData.relation?.avID || ""}" data-old-value='${JSON.stringify(colData.relation || {})}'>
+ <span class="b3-menu__label">${window.siyuan.languages.calc}</span>
+ <span class="b3-menu__accelerator">TODO</span>
+ <svg class="b3-menu__icon b3-menu__icon--small"><use xlink:href="#iconRight"></use></svg>
+</button>`;
}
return `<div class="b3-menu__items">
${html}
diff --git a/app/src/protyle/render/av/openMenuPanel.ts b/app/src/protyle/render/av/openMenuPanel.ts
index d453819739..71411c90bd 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 0000000000..d30377903f
--- /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 += `<div class="b3-list-item b3-list-item--narrow${index === 0 ? " b3-list-item--focus" : ""}" data-av-id="${item.avID}" data-block-id="${item.blockID}">
+ <div class="b3-list-item--two fn__flex-1">
+ <div class="b3-list-item__first">
+ <span class="b3-list-item__text">${escapeHtml(item.avName || window.siyuan.languages.title)}</span>
+ </div>
+ <div class="b3-list-item__meta b3-list-item__showall">${escapeHtml(item.hPath)}</div>
+ </div>
+ <svg aria-label="${window.siyuan.languages.thisDatabase}" style="margin: 0 0 0 4px" class="b3-list-item__hinticon ariaLabel${item.avID === avId ? "" : " fn__none"}"><use xlink:href="#iconInfo"></use></svg>
+</div>`;
+ });
+ 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: `<div class="fn__flex-column" style = "min-width: 260px;max-width:420px;max-height: 50vh">
+ <input class="b3-text-field fn__flex-shrink"/>
+ <div class="fn__hr"></div>
+ <div class="b3-list fn__flex-1 b3-list--background">
+ <img style="margin: 0 auto;display: block;width: 64px;height: 64px" src="/stage/loading-pure.svg">
+ </div>
+</div>`,
+ 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) => {
+
+}