diff --git a/app/src/protyle/render/av/filter.ts b/app/src/protyle/render/av/filter.ts index 0d4ee61f8..cef1664a1 100644 --- a/app/src/protyle/render/av/filter.ts +++ b/app/src/protyle/render/av/filter.ts @@ -17,7 +17,7 @@ export const setFilter = (options: { const oldFilters = JSON.parse(JSON.stringify(options.data.filters)); let hasMatch = false; - let cellValue; + let cellValue: IAVCellValue; if (colType === "number") { if (textElement.value) { cellValue = { @@ -46,7 +46,7 @@ export const setFilter = (options: { } }; } - const newFilter = { + const newFilter: IAVFilter = { column: options.filter.column, value: cellValue, operator: (window.siyuan.menus.menu.element.querySelector(".b3-select") as HTMLSelectElement).value as TAVFilterOperator @@ -156,21 +156,23 @@ export const setFilter = (options: { textElement.parentElement.parentElement.classList.remove("fn__none"); } }); - const textElement = (window.siyuan.menus.menu.element.querySelector(".b3-text-field") as HTMLInputElement); - textElement.addEventListener("keydown", (event) => { - if (event.isComposing) { - event.preventDefault(); - return; + const textElement = window.siyuan.menus.menu.element.querySelector(".b3-text-field") as HTMLInputElement; + if (textElement) { + textElement.addEventListener("keydown", (event) => { + if (event.isComposing) { + event.preventDefault(); + return; + } + if (event.key === "Enter") { + menu.close(); + event.preventDefault(); + } + }); + if (selectElement.value === "Is empty" || selectElement.value === "Is not empty") { + textElement.parentElement.parentElement.classList.add("fn__none"); + } else { + textElement.parentElement.parentElement.classList.remove("fn__none"); } - if (event.key === "Enter") { - menu.close(); - event.preventDefault(); - } - }); - if (selectElement.value === "Is empty" || selectElement.value === "Is not empty") { - textElement.parentElement.parentElement.classList.add("fn__none"); - } else { - textElement.parentElement.parentElement.classList.remove("fn__none"); } menu.open({x: rectTarget.left, y: rectTarget.bottom}); textElement.select(); diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.ts index 786cf05ed..ce63688cb 100644 --- a/app/src/protyle/render/av/render.ts +++ b/app/src/protyle/render/av/render.ts @@ -54,23 +54,20 @@ ${column.wrap ? "" : "white-space: nowrap;"}"> if (data.columns[index].hidden) { return; } - let text = ""; + let text = ''; if (cell.valueType === "text") { text = `${cell.value?.text.content || ""}`; } else if (cell.valueType === "block") { text = `${cell.value?.block.content || ""}`; } else if (cell.valueType === "number") { text = `${cell.value?.number.content || ""}`; - } else if (cell.valueType === "select") { - if (cell.value?.select.content) { - text = `${cell.value.select.content}`; - } else { - text = ""; - } - } else if (cell.valueType === "mSelect") { + } else if (cell.valueType === "mSelect" || cell.valueType === "select") { cell.value?.mSelect.forEach((item: { content: string, color: string }) => { text += `${item.content}`; }); + if (!text) { + text = '' + } } else if (cell.valueType === "date") { text = `${cell.value?.date.content || ""}`; } diff --git a/app/src/protyle/render/av/select.ts b/app/src/protyle/render/av/select.ts index 82314f9ef..27352d149 100644 --- a/app/src/protyle/render/av/select.ts +++ b/app/src/protyle/render/av/select.ts @@ -74,22 +74,13 @@ export const removeSelectCell = (protyle: IProtyle, data: IAV, options: { return true; } }); - let oldValue; - if (colData.type !== "select") { - oldValue = Object.assign([], cellData.value.mSelect); - cellData.value.mSelect?.find((item: { content: string }, index: number) => { - if (item.content === target.dataset.content) { - cellData.value.mSelect.splice(index, 1); - return true; - } - }); - } else { - oldValue = Object.assign({}, cellData.value.select); - cellData.value.select = { - color: "", - content: "" - }; - } + const oldValue = Object.assign([], cellData.value.mSelect); + cellData.value.mSelect?.find((item: { content: string }, index: number) => { + if (item.content === target.dataset.content) { + cellData.value.mSelect.splice(index, 1); + return true; + } + }); target.remove(); transaction(protyle, [{ @@ -156,16 +147,12 @@ export const setSelectCol = (protyle: IProtyle, data: IAV, options: { if (row.id === options.cellElement.parentElement.dataset.id) { row.cells.find(cell => { if (cell.id === options.cellElement.dataset.id) { - if (cell.valueType === "select") { - cell.value.select.content = inputElement.value; - } else { - cell.value.mSelect.find((item) => { - if (item.content === name) { - item.content = inputElement.value; - return true; - } - }); - } + cell.value.mSelect.find((item) => { + if (item.content === name) { + item.content = inputElement.value; + return true; + } + }); return true; } }); @@ -217,19 +204,12 @@ export const setSelectCol = (protyle: IProtyle, data: IAV, options: { if (row.id === options.cellElement.parentElement.dataset.id) { row.cells.find(cell => { if (cell.id === options.cellElement.dataset.id) { - if (cell.valueType === "select") { - cell.value.select = { - color: "", - content: "" - }; - } else { - cell.value.mSelect.find((item, index) => { - if (item.content === newName) { - cell.value.mSelect.splice(index, 1); - return true; - } - }); - } + cell.value.mSelect.find((item, index) => { + if (item.content === newName) { + cell.value.mSelect.splice(index, 1); + return true; + } + }); return true; } }); @@ -291,20 +271,13 @@ export const setSelectCol = (protyle: IProtyle, data: IAV, options: { if (row.id === options.cellElement.parentElement.dataset.id) { row.cells.find(cell => { if (cell.id === options.cellElement.dataset.id) { - if (cell.valueType === "select") { - cell.value.select = { - content: inputElement.value, - color: (index + 1).toString() + cell.value.mSelect.find((item) => { + if (item.content === name) { + item.content = inputElement.value; + item.color = (index + 1).toString(); + return true; } - } else { - cell.value.mSelect.find((item) => { - if (item.content === name) { - item.content = inputElement.value; - item.color = (index + 1).toString(); - return true; - } - }); - } + }); return true; } }); @@ -402,23 +375,12 @@ export const addSelectColAndCell = (protyle: IProtyle, data: IAV, options: { } }); - let oldValue; - if (colData.type !== "select") { - oldValue = Object.assign([], cellData.value.mSelect); - cellData.value.mSelect?.push({ - color: currentElement.dataset.color, - content: currentElement.dataset.name - }); - } else { - if (!cellData.value) { - cellData.value = {select: {}}; - } - oldValue = Object.assign({}, cellData.value.select); - cellData.value.select = { - color: currentElement.dataset.color, - content: currentElement.dataset.name - }; - } + const oldValue = Object.assign([], cellData.value.mSelect); + cellData.value.mSelect?.push({ + color: currentElement.dataset.color, + content: currentElement.dataset.name + }); + if (currentElement.querySelector(".b3-menu__accelerator")) { colData.options.push({ color: currentElement.dataset.color, @@ -476,13 +438,9 @@ export const getSelectHTML = (data: IAV, options: { cellElement: HTMLElement }) if (options.cellElement.parentElement.dataset.id === row.id) { row.cells.find(cell => { if (cell.id === cellId && cell.value) { - if (colData.type === "mSelect") { - cell.value.mSelect?.forEach((item: { content: string, color: string }) => { - selectedHTML += `
${item.content}
`; - }); - } else if (cell.value.select.content) { - selectedHTML += `
${cell.value.select.content}
`; - } + cell.value.mSelect?.forEach((item: { content: string, color: string }) => { + selectedHTML += `
${item.content}
`; + }); return true; } }); diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index 12a75fb1f..f8b4e4bde 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -855,11 +855,7 @@ interface IAV { interface IAVFilter { column: string, operator: TAVFilterOperator, - value: { - [key in TAVCol]?: IAVCellValue - } & { - mSelect?: { content: string, color: string }[] - }, + value: IAVCellValue } interface IAVSort { @@ -891,18 +887,14 @@ interface IAVCell { id: string, color: string, bgColor: string, - value: { - [key in TAVCol]?: IAVCellValue - } & { - mSelect?: { content: string, color: string }[] - }, + value: IAVCellValue, valueType: TAVCol, } interface IAVCellValue { - content?: any - content2?: string // 用于日期 - color?: string - id?: string - isNotEmpty?: boolean + text?: { content: string }, + number?: { content?: number, isNotEmpty: boolean }, + mSelect?: { content: string, color: string }[] + block?: { content: string, id: string } + date?: { content: string, content2?: string } }