Vanessa 2025-03-16 11:35:19 +08:00
parent 244d360ef0
commit ecb186c969
4 changed files with 42 additions and 19 deletions

View File

@ -71,7 +71,7 @@ ${contentHTML}
}); });
return `<div class="b3-menu__items"> return `<div class="b3-menu__items">
${html} ${html}
<button data-type="addAssetExist" class="b3-menu__item"> <button data-type="addAssetExist" class="b3-menu__item b3-menu__item--current">
<svg class="b3-menu__icon"><use xlink:href="#iconImage"></use></svg> <svg class="b3-menu__icon"><use xlink:href="#iconImage"></use></svg>
<span class="b3-menu__label">${window.siyuan.languages.assets}</span> <span class="b3-menu__label">${window.siyuan.languages.assets}</span>
</button> </button>

View File

@ -202,21 +202,40 @@ export const avKeydown = (event: KeyboardEvent, nodeElement: HTMLElement, protyl
export const bindAVPanelKeydown = (event: KeyboardEvent) => { export const bindAVPanelKeydown = (event: KeyboardEvent) => {
const avPanelElement = document.querySelector(".av__panel"); const avPanelElement = document.querySelector(".av__panel");
if (avPanelElement && avPanelElement.querySelector('[data-type="goSearchRollupCol"]') && if (avPanelElement && window.siyuan.menus.menu.element.classList.contains("fn__none")) {
!avPanelElement.querySelector(".b3-text-field") && if ((avPanelElement.querySelector('[data-type="goSearchRollupCol"]') && !avPanelElement.querySelector(".b3-text-field")) ||
window.siyuan.menus.menu.element.classList.contains("fn__none")) { avPanelElement.querySelector('[data-type="addAssetExist"]')) {
const menuElement = avPanelElement.querySelector(".b3-menu__items") const menuElement = avPanelElement.querySelector(".b3-menu__items")
if (event.key === "Enter") { if (event.key === "Enter") {
const currentElement = menuElement.querySelector(".b3-menu__item--current"); const currentElement = menuElement.querySelector(".b3-menu__item--current");
if (currentElement) { if (currentElement) {
avPanelElement.dispatchEvent(new CustomEvent("click", {detail: currentElement.getAttribute("data-type")})); const editElement = currentElement.querySelector('[data-type="editAssetItem"]')
const uploadElement = currentElement.querySelector(".b3-form__upload")
if (editElement) {
avPanelElement.dispatchEvent(new CustomEvent("click", {
detail: {
type: editElement.getAttribute("data-type"),
target: editElement
}
}));
} else if (uploadElement) {
uploadElement.dispatchEvent(new MouseEvent('click', {bubbles: true}));
} else {
avPanelElement.dispatchEvent(new CustomEvent("click", {
detail: {
type: currentElement.getAttribute("data-type"),
target: currentElement
}
}));
}
}
} else if (event.key === "Escape") {
avPanelElement.dispatchEvent(new CustomEvent("click", {detail: "close"}));
} else {
upDownHint(menuElement, event, "b3-menu__item--current", menuElement.firstElementChild)
} }
} else if (event.key === "Escape") { return true;
avPanelElement.dispatchEvent(new CustomEvent("click", {detail: "close"}));
} else {
upDownHint(menuElement, event, "b3-menu__item--current", menuElement.firstElementChild)
} }
return true;
} }
return false; return false;
} }

View File

@ -139,6 +139,7 @@ export const openMenuPanel = (options: {
cellElements: options.cellElements, cellElements: options.cellElements,
blockElement: options.blockElement blockElement: options.blockElement
}); });
(avPanelElement.querySelector(".b3-menu__item") as HTMLButtonElement).focus();
setTimeout(() => { setTimeout(() => {
setPosition(menuElement, cellRect.left, cellRect.bottom, cellRect.height); setPosition(menuElement, cellRect.left, cellRect.bottom, cellRect.height);
}, Constants.TIMEOUT_LOAD); // 等待加载 }, Constants.TIMEOUT_LOAD); // 等待加载
@ -496,10 +497,13 @@ export const openMenuPanel = (options: {
}); });
avPanelElement.addEventListener("click", (event: MouseEvent) => { avPanelElement.addEventListener("click", (event: MouseEvent) => {
let type: string; let type: string;
let target = event.target as HTMLElement;
if (typeof event.detail === "string") { if (typeof event.detail === "string") {
type = event.detail; type = event.detail;
} else if (typeof event.detail === "object") {
type = (event.detail as { type: string }).type;
target = (event.detail as { target: HTMLElement }).target;
} }
let target = event.target as HTMLElement;
while (target && !target.isSameNode(avPanelElement) || type) { while (target && !target.isSameNode(avPanelElement) || type) {
type = target?.dataset.type || type; type = target?.dataset.type || type;
if (type === "close") { if (type === "close") {
@ -970,7 +974,7 @@ export const openMenuPanel = (options: {
break; break;
} else if (type === "goSearchRollupCol") { } else if (type === "goSearchRollupCol") {
goSearchRollupCol({ goSearchRollupCol({
target: avPanelElement.querySelector('[data-type="goSearchRollupCol"]'), target,
data, data,
isRelation: true, isRelation: true,
protyle: options.protyle, protyle: options.protyle,
@ -981,7 +985,7 @@ export const openMenuPanel = (options: {
break; break;
} else if (type === "goSearchRollupTarget") { } else if (type === "goSearchRollupTarget") {
goSearchRollupCol({ goSearchRollupCol({
target: avPanelElement.querySelector('[data-type="goSearchRollupTarget"]'), target,
data, data,
isRelation: false, isRelation: false,
protyle: options.protyle, protyle: options.protyle,
@ -991,7 +995,7 @@ export const openMenuPanel = (options: {
event.stopPropagation(); event.stopPropagation();
break; break;
} else if (type === "goSearchRollupCalc") { } else if (type === "goSearchRollupCalc") {
openCalcMenu(options.protyle, avPanelElement.querySelector('[data-type="goSearchRollupTarget"]'), { openCalcMenu(options.protyle, target, {
data, data,
colId: options.colId || menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id"), colId: options.colId || menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id"),
blockID blockID

View File

@ -173,7 +173,7 @@ export const getRollupHTML = (options: { data?: IAV, cellElements?: HTMLElement[
} }
}); });
} }
return `<button class="b3-menu__item" data-type="goSearchRollupCol" data-old-value='${JSON.stringify(colData.rollup || {})}'> return `<button class="b3-menu__item b3-menu__item--current" data-type="goSearchRollupCol" data-old-value='${JSON.stringify(colData.rollup || {})}'>
<span class="b3-menu__label">${window.siyuan.languages.relation}</span> <span class="b3-menu__label">${window.siyuan.languages.relation}</span>
<span class="b3-menu__accelerator"></span> <span class="b3-menu__accelerator"></span>
<svg class="b3-menu__icon b3-menu__icon--small"><use xlink:href="#iconRight"></use></svg> <svg class="b3-menu__icon b3-menu__icon--small"><use xlink:href="#iconRight"></use></svg>