mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 09:30:14 +01:00
This commit is contained in:
parent
b46100b29c
commit
c4c889f75f
4 changed files with 54 additions and 51 deletions
|
|
@ -23,7 +23,7 @@ import {assetMenu} from "../../../menus/protyle";
|
|||
import {
|
||||
addView,
|
||||
bindSwitcherEvent,
|
||||
bindViewEvent,
|
||||
bindViewEvent, getFieldsByData,
|
||||
getSwitcherHTML,
|
||||
getViewHTML,
|
||||
openViewMenu
|
||||
|
|
@ -76,12 +76,13 @@ export const openMenuPanel = (options: {
|
|||
const isCustomAttr = !options.blockElement.classList.contains("av");
|
||||
const data = response.data as IAV;
|
||||
let html;
|
||||
const fields = getFieldsByData(data);
|
||||
if (options.type === "config") {
|
||||
html = getViewHTML(data);
|
||||
} else if (options.type === "properties") {
|
||||
html = getPropertiesHTML(data.view);
|
||||
html = getPropertiesHTML(fields);
|
||||
} else if (options.type === "sorts") {
|
||||
html = getSortsHTML(data.view.columns, data.view.sorts);
|
||||
html = getSortsHTML(fields, data.view.sorts);
|
||||
} else if (options.type === "switcher") {
|
||||
html = getSwitcherHTML(data.views, data.viewID);
|
||||
} else if (options.type === "filters") {
|
||||
|
|
@ -93,14 +94,14 @@ export const openMenuPanel = (options: {
|
|||
} else if (options.type === "edit") {
|
||||
if (options.editData) {
|
||||
if (options.editData.previousID) {
|
||||
data.view.columns.find((item, index) => {
|
||||
fields.find((item, index) => {
|
||||
if (item.id === options.editData.previousID) {
|
||||
data.view.columns.splice(index + 1, 0, options.editData.colData);
|
||||
fields.splice(index + 1, 0, options.editData.colData);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
data.view.columns.splice(0, 0, options.editData.colData);
|
||||
fields.splice(0, 0, options.editData.colData);
|
||||
}
|
||||
}
|
||||
html = getEditHTML({protyle: options.protyle, data, colId: options.colId, isCustomAttr});
|
||||
|
|
@ -248,7 +249,7 @@ export const openMenuPanel = (options: {
|
|||
data: oldData,
|
||||
blockID
|
||||
}]);
|
||||
menuElement.innerHTML = getSortsHTML(data.view.columns, data.view.sorts);
|
||||
menuElement.innerHTML = getSortsHTML(fields, data.view.sorts);
|
||||
bindSortsEvent(options.protyle, menuElement, data, blockID);
|
||||
return;
|
||||
}
|
||||
|
|
@ -336,7 +337,7 @@ export const openMenuPanel = (options: {
|
|||
}
|
||||
if (targetElement.querySelector('[data-type="setColOption"]')) {
|
||||
const colId = options.cellElements ? options.cellElements[0].dataset.colId : menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id");
|
||||
const changeData = data.view.columns.find((column) => column.id === colId).options;
|
||||
const changeData = fields.find((column) => column.id === colId).options;
|
||||
const oldData = Object.assign([], changeData);
|
||||
let targetOption: { name: string, color: string };
|
||||
changeData.find((option, index: number) => {
|
||||
|
|
@ -428,24 +429,24 @@ export const openMenuPanel = (options: {
|
|||
blockID
|
||||
}]);
|
||||
let column: IAVColumn;
|
||||
data.view.columns.find((item, index: number) => {
|
||||
fields.find((item, index: number) => {
|
||||
if (item.id === sourceId) {
|
||||
column = data.view.columns.splice(index, 1)[0];
|
||||
column = fields.splice(index, 1)[0];
|
||||
return true;
|
||||
}
|
||||
});
|
||||
data.view.columns.find((item, index: number) => {
|
||||
fields.find((item, index: number) => {
|
||||
if (item.id === targetId) {
|
||||
if (isTop) {
|
||||
data.view.columns.splice(index, 0, column);
|
||||
fields.splice(index, 0, column);
|
||||
} else {
|
||||
data.view.columns.splice(index + 1, 0, column);
|
||||
fields.splice(index + 1, 0, column);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
menuElement.innerHTML = getPropertiesHTML(data.view);
|
||||
menuElement.innerHTML = getPropertiesHTML(fields);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
|
@ -540,7 +541,7 @@ export const openMenuPanel = (options: {
|
|||
} else if (type === "go-properties") {
|
||||
// 复制列后点击返回到属性面板,宽度不一致,需重新计算
|
||||
tabRect = options.blockElement.querySelector(".av__views").getBoundingClientRect();
|
||||
menuElement.innerHTML = getPropertiesHTML(data.view);
|
||||
menuElement.innerHTML = getPropertiesHTML(fields);
|
||||
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
||||
window.siyuan.menus.menu.remove();
|
||||
event.preventDefault();
|
||||
|
|
@ -555,7 +556,7 @@ export const openMenuPanel = (options: {
|
|||
event.stopPropagation();
|
||||
break;
|
||||
} else if (type === "goSorts") {
|
||||
menuElement.innerHTML = getSortsHTML(data.view.columns, data.view.sorts);
|
||||
menuElement.innerHTML = getSortsHTML(fields, data.view.sorts);
|
||||
bindSortsEvent(options.protyle, menuElement, data, blockID);
|
||||
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
||||
window.siyuan.menus.menu.remove();
|
||||
|
|
@ -575,7 +576,7 @@ export const openMenuPanel = (options: {
|
|||
blockID
|
||||
}]);
|
||||
data.view.sorts = [];
|
||||
menuElement.innerHTML = getSortsHTML(data.view.columns, data.view.sorts);
|
||||
menuElement.innerHTML = getSortsHTML(fields, data.view.sorts);
|
||||
bindSortsEvent(options.protyle, menuElement, data, blockID);
|
||||
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
||||
event.preventDefault();
|
||||
|
|
@ -613,7 +614,7 @@ export const openMenuPanel = (options: {
|
|||
data: oldSorts,
|
||||
blockID
|
||||
}]);
|
||||
menuElement.innerHTML = getSortsHTML(data.view.columns, data.view.sorts);
|
||||
menuElement.innerHTML = getSortsHTML(fields, data.view.sorts);
|
||||
bindSortsEvent(options.protyle, menuElement, data, blockID);
|
||||
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
||||
event.preventDefault();
|
||||
|
|
@ -823,7 +824,7 @@ export const openMenuPanel = (options: {
|
|||
} else if (type === "showAllCol") {
|
||||
const doOperations: IOperation[] = [];
|
||||
const undoOperations: IOperation[] = [];
|
||||
data.view.columns.forEach((item: IAVColumn) => {
|
||||
fields.forEach((item: IAVColumn) => {
|
||||
if (item.hidden) {
|
||||
doOperations.push({
|
||||
action: "setAttrViewColHidden",
|
||||
|
|
@ -844,7 +845,7 @@ export const openMenuPanel = (options: {
|
|||
});
|
||||
if (doOperations.length > 0) {
|
||||
transaction(options.protyle, doOperations, undoOperations);
|
||||
menuElement.innerHTML = getPropertiesHTML(data.view);
|
||||
menuElement.innerHTML = getPropertiesHTML(fields);
|
||||
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
||||
}
|
||||
event.preventDefault();
|
||||
|
|
@ -853,7 +854,7 @@ export const openMenuPanel = (options: {
|
|||
} else if (type === "hideAllCol") {
|
||||
const doOperations: IOperation[] = [];
|
||||
const undoOperations: IOperation[] = [];
|
||||
data.view.columns.forEach((item: IAVColumn) => {
|
||||
fields.forEach((item: IAVColumn) => {
|
||||
if (!item.hidden && item.type !== "block") {
|
||||
doOperations.push({
|
||||
action: "setAttrViewColHidden",
|
||||
|
|
@ -874,7 +875,7 @@ export const openMenuPanel = (options: {
|
|||
});
|
||||
if (doOperations.length > 0) {
|
||||
transaction(options.protyle, doOperations, undoOperations);
|
||||
menuElement.innerHTML = getPropertiesHTML(data.view);
|
||||
menuElement.innerHTML = getPropertiesHTML(fields);
|
||||
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
||||
}
|
||||
event.preventDefault();
|
||||
|
|
@ -897,7 +898,7 @@ export const openMenuPanel = (options: {
|
|||
const nameElement = avPanelElement.querySelector('.b3-text-field[data-type="name"]') as HTMLInputElement;
|
||||
const name = nameElement.value;
|
||||
let newName = name;
|
||||
data.view.columns.find((item: IAVColumn) => {
|
||||
fields.find((item: IAVColumn) => {
|
||||
if (item.id === options.colId) {
|
||||
item.type = target.dataset.newType as TAVCol;
|
||||
if (getColNameByType(target.dataset.oldType as TAVCol) === name) {
|
||||
|
|
@ -1023,7 +1024,7 @@ export const openMenuPanel = (options: {
|
|||
protyle: options.protyle,
|
||||
avElement: avPanelElement,
|
||||
avID,
|
||||
colsData: data.view.columns,
|
||||
colsData: fields,
|
||||
blockElement: options.blockElement,
|
||||
});
|
||||
event.preventDefault();
|
||||
|
|
@ -1055,7 +1056,7 @@ export const openMenuPanel = (options: {
|
|||
data: false,
|
||||
blockID
|
||||
}]);
|
||||
data.view.columns.find((item: IAVColumn) => item.id === colId).hidden = true;
|
||||
fields.find((item: IAVColumn) => item.id === colId).hidden = true;
|
||||
if (isEdit) {
|
||||
menuElement.innerHTML = getEditHTML({
|
||||
protyle: options.protyle,
|
||||
|
|
@ -1065,7 +1066,7 @@ export const openMenuPanel = (options: {
|
|||
});
|
||||
bindEditEvent({protyle: options.protyle, data, menuElement, isCustomAttr, blockID});
|
||||
} else {
|
||||
menuElement.innerHTML = getPropertiesHTML(data.view);
|
||||
menuElement.innerHTML = getPropertiesHTML(fields);
|
||||
}
|
||||
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
||||
event.preventDefault();
|
||||
|
|
@ -1087,7 +1088,7 @@ export const openMenuPanel = (options: {
|
|||
data: true,
|
||||
blockID
|
||||
}]);
|
||||
data.view.columns.find((item: IAVColumn) => item.id === colId).hidden = false;
|
||||
fields.find((item: IAVColumn) => item.id === colId).hidden = false;
|
||||
if (isEdit) {
|
||||
menuElement.innerHTML = getEditHTML({
|
||||
protyle: options.protyle,
|
||||
|
|
@ -1097,7 +1098,7 @@ export const openMenuPanel = (options: {
|
|||
});
|
||||
bindEditEvent({protyle: options.protyle, data, menuElement, isCustomAttr, blockID});
|
||||
} else {
|
||||
menuElement.innerHTML = getPropertiesHTML(data.view);
|
||||
menuElement.innerHTML = getPropertiesHTML(fields);
|
||||
}
|
||||
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
||||
event.preventDefault();
|
||||
|
|
@ -1119,7 +1120,7 @@ export const openMenuPanel = (options: {
|
|||
tabRect = options.blockElement.querySelector(".av__views").getBoundingClientRect();
|
||||
}
|
||||
const colId = menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id");
|
||||
const colData = data.view.columns.find((item: IAVColumn) => {
|
||||
const colData = fields.find((item: IAVColumn) => {
|
||||
if (item.id === colId) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1146,7 +1147,7 @@ export const openMenuPanel = (options: {
|
|||
if (action === "delete" || (isDispatch && dialogEvent.detail === "Enter")) {
|
||||
removeCol({
|
||||
protyle: options.protyle,
|
||||
data,
|
||||
fields,
|
||||
avID,
|
||||
blockID,
|
||||
menuElement,
|
||||
|
|
@ -1161,7 +1162,7 @@ export const openMenuPanel = (options: {
|
|||
} else if (action === "keep-relation") {
|
||||
removeCol({
|
||||
protyle: options.protyle,
|
||||
data,
|
||||
fields,
|
||||
avID,
|
||||
blockID,
|
||||
menuElement,
|
||||
|
|
@ -1184,7 +1185,7 @@ export const openMenuPanel = (options: {
|
|||
} else {
|
||||
removeCol({
|
||||
protyle: options.protyle,
|
||||
data,
|
||||
fields,
|
||||
avID,
|
||||
blockID,
|
||||
menuElement,
|
||||
|
|
@ -1402,10 +1403,10 @@ export const openMenuPanel = (options: {
|
|||
});
|
||||
};
|
||||
|
||||
export const getPropertiesHTML = (data: IAVTable) => {
|
||||
export const getPropertiesHTML = (fields: IAVColumn[]) => {
|
||||
let showHTML = "";
|
||||
let hideHTML = "";
|
||||
data.columns.forEach((item: IAVColumn) => {
|
||||
fields.forEach((item: IAVColumn) => {
|
||||
if (item.hidden) {
|
||||
hideHTML += `<button class="b3-menu__item" data-type="editCol" draggable="true" data-id="${item.id}">
|
||||
<svg class="b3-menu__icon fn__grab"><use xlink:href="#iconDrag"></use></svg>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue