diff --git a/app/src/protyle/render/av/relation.ts b/app/src/protyle/render/av/relation.ts index f7ecf92a6..1f97870dd 100644 --- a/app/src/protyle/render/av/relation.ts +++ b/app/src/protyle/render/av/relation.ts @@ -174,7 +174,7 @@ export const toggleUpdateRelationBtn = (menuItemsElement: HTMLElement, avId: str const switchElement = switchItemElement.querySelector(".b3-switch") as HTMLInputElement; const inputItemElement = switchItemElement.nextElementSibling; const btnElement = inputItemElement.nextElementSibling; - const oldValue = JSON.parse(searchElement.dataset.oldValue) as IAVCellRelationValue; + const oldValue = JSON.parse(searchElement.dataset.oldValue) as IAVColumnRelation; if (oldValue.avID) { const inputElement = inputItemElement.querySelector("input") as HTMLInputElement; if (resetData) { @@ -323,7 +323,7 @@ ${html || genSelectItemHTML("empty")}`; }; export const getRelationHTML = (data: IAV, cellElements?: HTMLElement[]) => { - let colRelationData: IAVCellRelationValue; + let colRelationData: IAVColumnRelation; data.view.columns.find(item => { if (item.id === cellElements[0].dataset.colId) { colRelationData = item.relation; @@ -358,7 +358,19 @@ export const setRelationCell = (protyle: IProtyle, nodeElement: HTMLElement, tar if (!nodeElement.contains(cellElements[0])) { cellElements[0] = nodeElement.querySelector(`.av__row[data-id="${rowElement.dataset.id}"] .av__cell[data-col-id="${cellElements[0].dataset.colId}"]`) as HTMLElement; } - const newValue = genCellValueByElement("relation", cellElements[0]).relation; + const newValue:IAVCellRelationValue = {blockIDs: [], contents: []}; + menuElement.querySelectorAll('[data-type="setRelationCell"]').forEach(item => { + const id = item.getAttribute("data-id"); + newValue.blockIDs.push(id); + newValue.contents.push({ + type: "block", + block: { + id, + content: item.querySelector(".b3-menu__label").textContent + }, + isDetached: !item.querySelector(".popover__block") + }); + }); if (target.classList.contains("b3-menu__item")) { const targetId = target.getAttribute("data-id"); const separatorElement = menuElement.querySelector(".b3-menu__separator"); diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index ec9a89957..76a47f212 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -834,7 +834,7 @@ interface IAVColumn { name: string, color: string, }[], - relation?: IAVCellRelationValue, + relation?: IAVColumnRelation, rollup?: IAVCellRollupValue } @@ -886,10 +886,7 @@ interface IAVCellValue { checkbox?: { checked: boolean } - relation?: { - blockIDs: string[] - contents?: IAVCellValue[] - } + relation?: IAVCellRelationValue rollup?: { contents?: IAVCellValue[] } @@ -898,6 +895,11 @@ interface IAVCellValue { updated?: IAVCellDateValue } +interface IAVCellRelationValue { + blockIDs: string[] + contents?: IAVCellValue[] +} + interface IAVCellDateValue { content?: number, isNotEmpty?: boolean @@ -919,7 +921,7 @@ interface IAVCellAssetValue { type: "file" | "image" } -interface IAVCellRelationValue { +interface IAVColumnRelation { avID?: string backKeyID?: string isTwoWay?: boolean