Vanessa 2023-12-24 23:35:19 +08:00
parent c70b8c382c
commit 769a8044dc
2 changed files with 36 additions and 27 deletions

View file

@ -307,7 +307,13 @@ export const openMenuPanel = (options: {
return; return;
} }
if (targetElement.getAttribute("data-type") === "setRelationCell") { if (targetElement.getAttribute("data-type") === "setRelationCell") {
if (isTop) {
targetElement.before(sourceElement);
} else {
targetElement.after(sourceElement);
}
targetElement.classList.remove("dragover__bottom", "dragover__top");
setRelationCell(options.protyle, options.blockElement as HTMLElement, sourceElement.parentElement);
return; return;
} }
@ -873,7 +879,7 @@ export const openMenuPanel = (options: {
event.stopPropagation(); event.stopPropagation();
break; break;
} else if (type === "setRelationCell") { } else if (type === "setRelationCell") {
setRelationCell(options.protyle, data, options.blockElement as HTMLElement, target); setRelationCell(options.protyle, options.blockElement as HTMLElement, target);
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
break; break;

View file

@ -255,7 +255,7 @@ export const getRelationHTML = (data: IAV, cellElements?: HTMLElement[]) => {
} }
} }
export const setRelationCell = (protyle: IProtyle, data: IAV, nodeElement: HTMLElement, target: HTMLElement) => { export const setRelationCell = (protyle: IProtyle, nodeElement: HTMLElement, target: HTMLElement) => {
const menuElement = hasClosestByClassName(target, "b3-menu__items"); const menuElement = hasClosestByClassName(target, "b3-menu__items");
if (!menuElement) { if (!menuElement) {
return return
@ -274,6 +274,7 @@ export const setRelationCell = (protyle: IProtyle, data: IAV, nodeElement: HTMLE
newValue.contents.push(item.textContent.trim()); newValue.contents.push(item.textContent.trim());
} }
}) })
if (target.classList.contains("b3-menu__item")) {
const targetId = target.getAttribute("data-id") const targetId = target.getAttribute("data-id")
const separatorElement = menuElement.querySelector(".b3-menu__separator"); const separatorElement = menuElement.querySelector(".b3-menu__separator");
if (target.getAttribute("draggable")) { if (target.getAttribute("draggable")) {
@ -300,5 +301,7 @@ export const setRelationCell = (protyle: IProtyle, data: IAV, nodeElement: HTMLE
separatorElement.insertAdjacentHTML("afterend", genSelectItemHTML("empty")); separatorElement.insertAdjacentHTML("afterend", genSelectItemHTML("empty"));
} }
} }
}
updateCellsValue(protyle, nodeElement, newValue); updateCellsValue(protyle, nodeElement, newValue);
}; };