mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-19 16:10:12 +01:00
This commit is contained in:
parent
73bcce1485
commit
e62e36fbc0
4 changed files with 64 additions and 115 deletions
|
|
@ -17,7 +17,7 @@ export const setFilter = (options: {
|
||||||
const oldFilters = JSON.parse(JSON.stringify(options.data.filters));
|
const oldFilters = JSON.parse(JSON.stringify(options.data.filters));
|
||||||
let hasMatch = false;
|
let hasMatch = false;
|
||||||
|
|
||||||
let cellValue;
|
let cellValue: IAVCellValue;
|
||||||
if (colType === "number") {
|
if (colType === "number") {
|
||||||
if (textElement.value) {
|
if (textElement.value) {
|
||||||
cellValue = {
|
cellValue = {
|
||||||
|
|
@ -46,7 +46,7 @@ export const setFilter = (options: {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const newFilter = {
|
const newFilter: IAVFilter = {
|
||||||
column: options.filter.column,
|
column: options.filter.column,
|
||||||
value: cellValue,
|
value: cellValue,
|
||||||
operator: (window.siyuan.menus.menu.element.querySelector(".b3-select") as HTMLSelectElement).value as TAVFilterOperator
|
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");
|
textElement.parentElement.parentElement.classList.remove("fn__none");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const textElement = (window.siyuan.menus.menu.element.querySelector(".b3-text-field") as HTMLInputElement);
|
const textElement = window.siyuan.menus.menu.element.querySelector(".b3-text-field") as HTMLInputElement;
|
||||||
textElement.addEventListener("keydown", (event) => {
|
if (textElement) {
|
||||||
if (event.isComposing) {
|
textElement.addEventListener("keydown", (event) => {
|
||||||
event.preventDefault();
|
if (event.isComposing) {
|
||||||
return;
|
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});
|
menu.open({x: rectTarget.left, y: rectTarget.bottom});
|
||||||
textElement.select();
|
textElement.select();
|
||||||
|
|
|
||||||
|
|
@ -54,23 +54,20 @@ ${column.wrap ? "" : "white-space: nowrap;"}">
|
||||||
if (data.columns[index].hidden) {
|
if (data.columns[index].hidden) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let text = "";
|
let text = '';
|
||||||
if (cell.valueType === "text") {
|
if (cell.valueType === "text") {
|
||||||
text = `<span class="av__celltext">${cell.value?.text.content || ""}</span>`;
|
text = `<span class="av__celltext">${cell.value?.text.content || ""}</span>`;
|
||||||
} else if (cell.valueType === "block") {
|
} else if (cell.valueType === "block") {
|
||||||
text = `<span class="av__celltext">${cell.value?.block.content || ""}</span>`;
|
text = `<span class="av__celltext">${cell.value?.block.content || ""}</span>`;
|
||||||
} else if (cell.valueType === "number") {
|
} else if (cell.valueType === "number") {
|
||||||
text = `<span class="av__celltext">${cell.value?.number.content || ""}</span>`;
|
text = `<span class="av__celltext">${cell.value?.number.content || ""}</span>`;
|
||||||
} else if (cell.valueType === "select") {
|
} else if (cell.valueType === "mSelect" || cell.valueType === "select") {
|
||||||
if (cell.value?.select.content) {
|
|
||||||
text = `<span class="av__celltext"><span class="b3-chip b3-chip--middle" style="background-color:var(--b3-font-background${cell.value.select.color});color:var(--b3-font-color${cell.value.select.color})">${cell.value.select.content}</span></span>`;
|
|
||||||
} else {
|
|
||||||
text = "<span class=\"av__celltext\"></span>";
|
|
||||||
}
|
|
||||||
} else if (cell.valueType === "mSelect") {
|
|
||||||
cell.value?.mSelect.forEach((item: { content: string, color: string }) => {
|
cell.value?.mSelect.forEach((item: { content: string, color: string }) => {
|
||||||
text += `<span class="av__celltext"><span class="b3-chip b3-chip--middle" style="background-color:var(--b3-font-background${item.color});color:var(--b3-font-color${item.color})">${item.content}</span></span>`;
|
text += `<span class="av__celltext"><span class="b3-chip b3-chip--middle" style="background-color:var(--b3-font-background${item.color});color:var(--b3-font-color${item.color})">${item.content}</span></span>`;
|
||||||
});
|
});
|
||||||
|
if (!text) {
|
||||||
|
text = '<span class="av__celltext"></span>'
|
||||||
|
}
|
||||||
} else if (cell.valueType === "date") {
|
} else if (cell.valueType === "date") {
|
||||||
text = `<span class="av__celltext">${cell.value?.date.content || ""}</span>`;
|
text = `<span class="av__celltext">${cell.value?.date.content || ""}</span>`;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,22 +74,13 @@ export const removeSelectCell = (protyle: IProtyle, data: IAV, options: {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let oldValue;
|
const oldValue = Object.assign([], cellData.value.mSelect);
|
||||||
if (colData.type !== "select") {
|
cellData.value.mSelect?.find((item: { content: string }, index: number) => {
|
||||||
oldValue = Object.assign([], cellData.value.mSelect);
|
if (item.content === target.dataset.content) {
|
||||||
cellData.value.mSelect?.find((item: { content: string }, index: number) => {
|
cellData.value.mSelect.splice(index, 1);
|
||||||
if (item.content === target.dataset.content) {
|
return true;
|
||||||
cellData.value.mSelect.splice(index, 1);
|
}
|
||||||
return true;
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
oldValue = Object.assign({}, cellData.value.select);
|
|
||||||
cellData.value.select = {
|
|
||||||
color: "",
|
|
||||||
content: ""
|
|
||||||
};
|
|
||||||
}
|
|
||||||
target.remove();
|
target.remove();
|
||||||
|
|
||||||
transaction(protyle, [{
|
transaction(protyle, [{
|
||||||
|
|
@ -156,16 +147,12 @@ export const setSelectCol = (protyle: IProtyle, data: IAV, options: {
|
||||||
if (row.id === options.cellElement.parentElement.dataset.id) {
|
if (row.id === options.cellElement.parentElement.dataset.id) {
|
||||||
row.cells.find(cell => {
|
row.cells.find(cell => {
|
||||||
if (cell.id === options.cellElement.dataset.id) {
|
if (cell.id === options.cellElement.dataset.id) {
|
||||||
if (cell.valueType === "select") {
|
cell.value.mSelect.find((item) => {
|
||||||
cell.value.select.content = inputElement.value;
|
if (item.content === name) {
|
||||||
} else {
|
item.content = inputElement.value;
|
||||||
cell.value.mSelect.find((item) => {
|
return true;
|
||||||
if (item.content === name) {
|
}
|
||||||
item.content = inputElement.value;
|
});
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -217,19 +204,12 @@ export const setSelectCol = (protyle: IProtyle, data: IAV, options: {
|
||||||
if (row.id === options.cellElement.parentElement.dataset.id) {
|
if (row.id === options.cellElement.parentElement.dataset.id) {
|
||||||
row.cells.find(cell => {
|
row.cells.find(cell => {
|
||||||
if (cell.id === options.cellElement.dataset.id) {
|
if (cell.id === options.cellElement.dataset.id) {
|
||||||
if (cell.valueType === "select") {
|
cell.value.mSelect.find((item, index) => {
|
||||||
cell.value.select = {
|
if (item.content === newName) {
|
||||||
color: "",
|
cell.value.mSelect.splice(index, 1);
|
||||||
content: ""
|
return true;
|
||||||
};
|
}
|
||||||
} else {
|
});
|
||||||
cell.value.mSelect.find((item, index) => {
|
|
||||||
if (item.content === newName) {
|
|
||||||
cell.value.mSelect.splice(index, 1);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -291,20 +271,13 @@ export const setSelectCol = (protyle: IProtyle, data: IAV, options: {
|
||||||
if (row.id === options.cellElement.parentElement.dataset.id) {
|
if (row.id === options.cellElement.parentElement.dataset.id) {
|
||||||
row.cells.find(cell => {
|
row.cells.find(cell => {
|
||||||
if (cell.id === options.cellElement.dataset.id) {
|
if (cell.id === options.cellElement.dataset.id) {
|
||||||
if (cell.valueType === "select") {
|
cell.value.mSelect.find((item) => {
|
||||||
cell.value.select = {
|
if (item.content === name) {
|
||||||
content: inputElement.value,
|
item.content = inputElement.value;
|
||||||
color: (index + 1).toString()
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -402,23 +375,12 @@ export const addSelectColAndCell = (protyle: IProtyle, data: IAV, options: {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let oldValue;
|
const oldValue = Object.assign([], cellData.value.mSelect);
|
||||||
if (colData.type !== "select") {
|
cellData.value.mSelect?.push({
|
||||||
oldValue = Object.assign([], cellData.value.mSelect);
|
color: currentElement.dataset.color,
|
||||||
cellData.value.mSelect?.push({
|
content: currentElement.dataset.name
|
||||||
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
|
|
||||||
};
|
|
||||||
}
|
|
||||||
if (currentElement.querySelector(".b3-menu__accelerator")) {
|
if (currentElement.querySelector(".b3-menu__accelerator")) {
|
||||||
colData.options.push({
|
colData.options.push({
|
||||||
color: currentElement.dataset.color,
|
color: currentElement.dataset.color,
|
||||||
|
|
@ -476,13 +438,9 @@ export const getSelectHTML = (data: IAV, options: { cellElement: HTMLElement })
|
||||||
if (options.cellElement.parentElement.dataset.id === row.id) {
|
if (options.cellElement.parentElement.dataset.id === row.id) {
|
||||||
row.cells.find(cell => {
|
row.cells.find(cell => {
|
||||||
if (cell.id === cellId && cell.value) {
|
if (cell.id === cellId && cell.value) {
|
||||||
if (colData.type === "mSelect") {
|
cell.value.mSelect?.forEach((item: { content: string, color: string }) => {
|
||||||
cell.value.mSelect?.forEach((item: { content: string, color: string }) => {
|
selectedHTML += `<div class="b3-chip b3-chip--middle" data-content="${item.content}" style="background-color:var(--b3-font-background${item.color});color:var(--b3-font-color${item.color})">${item.content}<svg class="b3-chip__close" data-type="removeSelectCell"><use xlink:href="#iconCloseRound"></use></svg></div>`;
|
||||||
selectedHTML += `<div class="b3-chip b3-chip--middle" data-content="${item.content}" style="background-color:var(--b3-font-background${item.color});color:var(--b3-font-color${item.color})">${item.content}<svg class="b3-chip__close" data-type="removeSelectCell"><use xlink:href="#iconCloseRound"></use></svg></div>`;
|
});
|
||||||
});
|
|
||||||
} else if (cell.value.select.content) {
|
|
||||||
selectedHTML += `<div class="b3-chip b3-chip--middle" data-content="${cell.value.select.content}" style="background-color:var(--b3-font-background${cell.value.select.color});color:var(--b3-font-color${cell.value.select.color})">${cell.value.select.content}<svg class="b3-chip__close" data-type="removeSelectCell"><use xlink:href="#iconCloseRound"></use></svg></div>`;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
22
app/src/types/index.d.ts
vendored
22
app/src/types/index.d.ts
vendored
|
|
@ -855,11 +855,7 @@ interface IAV {
|
||||||
interface IAVFilter {
|
interface IAVFilter {
|
||||||
column: string,
|
column: string,
|
||||||
operator: TAVFilterOperator,
|
operator: TAVFilterOperator,
|
||||||
value: {
|
value: IAVCellValue
|
||||||
[key in TAVCol]?: IAVCellValue
|
|
||||||
} & {
|
|
||||||
mSelect?: { content: string, color: string }[]
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IAVSort {
|
interface IAVSort {
|
||||||
|
|
@ -891,18 +887,14 @@ interface IAVCell {
|
||||||
id: string,
|
id: string,
|
||||||
color: string,
|
color: string,
|
||||||
bgColor: string,
|
bgColor: string,
|
||||||
value: {
|
value: IAVCellValue,
|
||||||
[key in TAVCol]?: IAVCellValue
|
|
||||||
} & {
|
|
||||||
mSelect?: { content: string, color: string }[]
|
|
||||||
},
|
|
||||||
valueType: TAVCol,
|
valueType: TAVCol,
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IAVCellValue {
|
interface IAVCellValue {
|
||||||
content?: any
|
text?: { content: string },
|
||||||
content2?: string // 用于日期
|
number?: { content?: number, isNotEmpty: boolean },
|
||||||
color?: string
|
mSelect?: { content: string, color: string }[]
|
||||||
id?: string
|
block?: { content: string, id: string }
|
||||||
isNotEmpty?: boolean
|
date?: { content: string, content2?: string }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue