mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-16 00:50:56 +08:00
This commit is contained in:
parent
5939add4a1
commit
bee5ff9d4f
@ -10,6 +10,7 @@ export const getCellValue = (colType: TAVCol, value: string) => {
|
|||||||
if (colType === "number") {
|
if (colType === "number") {
|
||||||
if (value) {
|
if (value) {
|
||||||
cellValue = {
|
cellValue = {
|
||||||
|
type: colType,
|
||||||
number: {
|
number: {
|
||||||
content: parseFloat(value),
|
content: parseFloat(value),
|
||||||
isNotEmpty: true
|
isNotEmpty: true
|
||||||
@ -17,6 +18,7 @@ export const getCellValue = (colType: TAVCol, value: string) => {
|
|||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
cellValue = {
|
cellValue = {
|
||||||
|
type: colType,
|
||||||
number: {
|
number: {
|
||||||
isNotEmpty: false
|
isNotEmpty: false
|
||||||
}
|
}
|
||||||
@ -24,12 +26,14 @@ export const getCellValue = (colType: TAVCol, value: string) => {
|
|||||||
}
|
}
|
||||||
} else if (colType === "text") {
|
} else if (colType === "text") {
|
||||||
cellValue = {
|
cellValue = {
|
||||||
|
type: colType,
|
||||||
text: {
|
text: {
|
||||||
content: value
|
content: value
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else if (colType === "mSelect" || colType === "select") {
|
} else if (colType === "mSelect" || colType === "select") {
|
||||||
cellValue = {
|
cellValue = {
|
||||||
|
type: colType,
|
||||||
mSelect: [{
|
mSelect: [{
|
||||||
content: value,
|
content: value,
|
||||||
color: ""
|
color: ""
|
||||||
@ -45,12 +49,11 @@ export const setFilter = (options: {
|
|||||||
data: IAV,
|
data: IAV,
|
||||||
target: HTMLElement,
|
target: HTMLElement,
|
||||||
}) => {
|
}) => {
|
||||||
const colType = Object.keys(options.filter.value)[0] as TAVCol;
|
|
||||||
const rectTarget = options.target.getBoundingClientRect();
|
const rectTarget = options.target.getBoundingClientRect();
|
||||||
const menu = new Menu("set-filter-" + options.filter.column, () => {
|
const menu = new Menu("set-filter-" + options.filter.column, () => {
|
||||||
const oldFilters = JSON.parse(JSON.stringify(options.data.view.filters));
|
const oldFilters = JSON.parse(JSON.stringify(options.data.view.filters));
|
||||||
let hasMatch = false;
|
let hasMatch = false;
|
||||||
const cellValue = getCellValue(colType, textElement?.value || "");
|
const cellValue = getCellValue(options.filter.value.type, textElement?.value || "");
|
||||||
const newFilter: IAVFilter = {
|
const newFilter: IAVFilter = {
|
||||||
column: options.filter.column,
|
column: options.filter.column,
|
||||||
value: cellValue,
|
value: cellValue,
|
||||||
@ -91,7 +94,7 @@ export const setFilter = (options: {
|
|||||||
}
|
}
|
||||||
let selectHTML = "";
|
let selectHTML = "";
|
||||||
let colData: IAVColumn;
|
let colData: IAVColumn;
|
||||||
switch (colType) {
|
switch (options.filter.value.type) {
|
||||||
case "text":
|
case "text":
|
||||||
selectHTML = `<option ${"=" === options.filter.operator ? "selected" : ""} value="=">${window.siyuan.languages.filterOperatorIs}</option>
|
selectHTML = `<option ${"=" === options.filter.operator ? "selected" : ""} value="=">${window.siyuan.languages.filterOperatorIs}</option>
|
||||||
<option ${"!=" === options.filter.operator ? "selected" : ""} value="!=">${window.siyuan.languages.filterOperatorIsNot}</option>
|
<option ${"!=" === options.filter.operator ? "selected" : ""} value="!=">${window.siyuan.languages.filterOperatorIsNot}</option>
|
||||||
@ -140,7 +143,7 @@ export const setFilter = (options: {
|
|||||||
iconHTML: "",
|
iconHTML: "",
|
||||||
label: `<select style="margin: 4px 0" class="b3-select fn__size200">${selectHTML}</select>`
|
label: `<select style="margin: 4px 0" class="b3-select fn__size200">${selectHTML}</select>`
|
||||||
});
|
});
|
||||||
if (colType === "mSelect") {
|
if (options.filter.value.type === "mSelect") {
|
||||||
// TODO
|
// TODO
|
||||||
colData.options.forEach((option) => {
|
colData.options.forEach((option) => {
|
||||||
menu.addItem({
|
menu.addItem({
|
||||||
@ -150,12 +153,12 @@ export const setFilter = (options: {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else if (colType === "text") {
|
} else if (options.filter.value.type === "text") {
|
||||||
menu.addItem({
|
menu.addItem({
|
||||||
iconHTML: "",
|
iconHTML: "",
|
||||||
label: `<input style="margin: 4px 0" value="${options.filter.value.text.content}" class="b3-text-field fn__size200">`
|
label: `<input style="margin: 4px 0" value="${options.filter.value.text.content}" class="b3-text-field fn__size200">`
|
||||||
});
|
});
|
||||||
} else if (colType === "number") {
|
} else if (options.filter.value.type === "number") {
|
||||||
menu.addItem({
|
menu.addItem({
|
||||||
iconHTML: "",
|
iconHTML: "",
|
||||||
label: `<input style="margin: 4px 0" value="${options.filter.value.number.isNotEmpty ? options.filter.value.number.content : ""}" class="b3-text-field fn__size200">`
|
label: `<input style="margin: 4px 0" value="${options.filter.value.number.isNotEmpty ? options.filter.value.number.content : ""}" class="b3-text-field fn__size200">`
|
||||||
|
@ -484,7 +484,7 @@ export const openMenuPanel = (protyle: IProtyle,
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
} else if (type === "removeSelectCell") {
|
} else if (type === "removeSelectCell") {
|
||||||
removeSelectCell(protyle, data.view, options, target.parentElement);
|
removeSelectCell(protyle, data, options, target.parentElement);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ const filterSelectHTML = (key: string, options: { name: string, color: string }[
|
|||||||
return html;
|
return html;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const removeSelectCell = (protyle: IProtyle, data: IAVTable, options: {
|
export const removeSelectCell = (protyle: IProtyle, data: IAV, options: {
|
||||||
cellElement: HTMLElement
|
cellElement: HTMLElement
|
||||||
}, target: HTMLElement) => {
|
}, target: HTMLElement) => {
|
||||||
if (!target) {
|
if (!target) {
|
||||||
@ -52,7 +52,7 @@ export const removeSelectCell = (protyle: IProtyle, data: IAVTable, options: {
|
|||||||
const colId = options.cellElement.dataset.colId;
|
const colId = options.cellElement.dataset.colId;
|
||||||
const cellId = options.cellElement.dataset.id;
|
const cellId = options.cellElement.dataset.id;
|
||||||
let colData: IAVColumn;
|
let colData: IAVColumn;
|
||||||
data.columns.find((item: IAVColumn) => {
|
data.view.columns.find((item: IAVColumn) => {
|
||||||
if (item.id === colId) {
|
if (item.id === colId) {
|
||||||
colData = item;
|
colData = item;
|
||||||
return;
|
return;
|
||||||
@ -62,7 +62,7 @@ export const removeSelectCell = (protyle: IProtyle, data: IAVTable, options: {
|
|||||||
colData.options = [];
|
colData.options = [];
|
||||||
}
|
}
|
||||||
let cellData: IAVCell;
|
let cellData: IAVCell;
|
||||||
data.rows.find(row => {
|
data.view.rows.find(row => {
|
||||||
if (row.id === rowID) {
|
if (row.id === rowID) {
|
||||||
row.cells.find(cell => {
|
row.cells.find(cell => {
|
||||||
if (cell.id === cellId) {
|
if (cell.id === cellId) {
|
||||||
@ -342,7 +342,9 @@ export const bindSelectEvent = (protyle: IProtyle, data: IAV, menuElement: HTMLE
|
|||||||
}
|
}
|
||||||
addSelectColAndCell(protyle, data, options, currentElement, menuElement);
|
addSelectColAndCell(protyle, data, options, currentElement, menuElement);
|
||||||
} else if (event.key === "Backspace" && inputElement.value === "") {
|
} else if (event.key === "Backspace" && inputElement.value === "") {
|
||||||
removeSelectCell(protyle, data.view, options, inputElement.previousElementSibling as HTMLElement);
|
removeSelectCell(protyle, data, options, inputElement.previousElementSibling as HTMLElement);
|
||||||
|
} else if (event.key === "Escape") {
|
||||||
|
menuElement.parentElement.remove();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -381,7 +383,7 @@ export const addSelectColAndCell = (protyle: IProtyle, data: IAV, options: {
|
|||||||
if (!cellData) {
|
if (!cellData) {
|
||||||
cellData = {
|
cellData = {
|
||||||
color: "",
|
color: "",
|
||||||
bgColor:"",
|
bgColor: "",
|
||||||
id: Lute.NewNodeID(),
|
id: Lute.NewNodeID(),
|
||||||
value: {
|
value: {
|
||||||
mSelect: []
|
mSelect: []
|
||||||
|
1
app/src/types/index.d.ts
vendored
1
app/src/types/index.d.ts
vendored
@ -912,6 +912,7 @@ interface IAVCell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface IAVCellValue {
|
interface IAVCellValue {
|
||||||
|
type?: TAVCol,
|
||||||
text?: { content: string },
|
text?: { content: string },
|
||||||
number?: { content?: number, isNotEmpty: boolean },
|
number?: { content?: number, isNotEmpty: boolean },
|
||||||
mSelect?: { content: string, color: string }[]
|
mSelect?: { content: string, color: string }[]
|
||||||
|
Loading…
Reference in New Issue
Block a user