mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 17:40:13 +01:00
This commit is contained in:
parent
ca330e2557
commit
94f303da50
3 changed files with 88 additions and 45 deletions
|
|
@ -3,7 +3,7 @@ import {transaction} from "../../wysiwyg/transaction";
|
||||||
import {fetchPost} from "../../../util/fetch";
|
import {fetchPost} from "../../../util/fetch";
|
||||||
import {getDefaultOperatorByType, setFilter} from "./filter";
|
import {getDefaultOperatorByType, setFilter} from "./filter";
|
||||||
import {genCellValue} from "./cell";
|
import {genCellValue} from "./cell";
|
||||||
import {openMenuPanel} from "./openMenuPanel";
|
import {getPropertiesHTML, openMenuPanel} from "./openMenuPanel";
|
||||||
import {getLabelByNumberFormat} from "./number";
|
import {getLabelByNumberFormat} from "./number";
|
||||||
import {removeAttrViewColAnimation, updateAttrViewCellAnimation} from "./action";
|
import {removeAttrViewColAnimation, updateAttrViewCellAnimation} from "./action";
|
||||||
import {openEmojiPanel, unicode2Emoji} from "../../../emoji";
|
import {openEmojiPanel, unicode2Emoji} from "../../../emoji";
|
||||||
|
|
@ -908,6 +908,54 @@ export const showColMenu = (protyle: IProtyle, blockElement: Element, cellElemen
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const removeCol = (options: {
|
||||||
|
protyle: IProtyle,
|
||||||
|
data: IAV,
|
||||||
|
previousID: string,
|
||||||
|
colData: IAVColumn,
|
||||||
|
avID: string,
|
||||||
|
blockID: string,
|
||||||
|
isCustomAttr: boolean
|
||||||
|
menuElement: HTMLElement,
|
||||||
|
blockElement: Element
|
||||||
|
avPanelElement: Element
|
||||||
|
tabRect: DOMRect
|
||||||
|
}) => {
|
||||||
|
const colId = options.menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id");
|
||||||
|
const newUpdated = dayjs().format("YYYYMMDDHHmmss");
|
||||||
|
transaction(options.protyle, [{
|
||||||
|
action: "removeAttrViewCol",
|
||||||
|
id: colId,
|
||||||
|
avID: options.avID,
|
||||||
|
}, {
|
||||||
|
action: "doUpdateUpdated",
|
||||||
|
id: options.blockID,
|
||||||
|
data: newUpdated,
|
||||||
|
}], [{
|
||||||
|
action: "addAttrViewCol",
|
||||||
|
name: options.colData.name,
|
||||||
|
avID: options.avID,
|
||||||
|
type: options.colData.type,
|
||||||
|
id: colId,
|
||||||
|
previousID:options.previousID
|
||||||
|
}, {
|
||||||
|
action: "doUpdateUpdated",
|
||||||
|
id: options.blockID,
|
||||||
|
data: options.blockElement.getAttribute("updated")
|
||||||
|
}]);
|
||||||
|
removeAttrViewColAnimation(options.blockElement, colId);
|
||||||
|
options.blockElement.setAttribute("updated", newUpdated);
|
||||||
|
|
||||||
|
if (options.isCustomAttr) {
|
||||||
|
options.avPanelElement.remove();
|
||||||
|
} else {
|
||||||
|
options.menuElement.innerHTML = getPropertiesHTML(options.data.view);
|
||||||
|
setPosition(options.menuElement,
|
||||||
|
options.tabRect.right - options.menuElement.clientWidth, options.tabRect.bottom,
|
||||||
|
options.tabRect.height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const genUpdateColItem = (type: TAVCol, oldType: TAVCol) => {
|
const genUpdateColItem = (type: TAVCol, oldType: TAVCol) => {
|
||||||
return `<button class="b3-menu__item" data-type="updateColType" data-old-type="${oldType}" data-new-type="${type}">
|
return `<button class="b3-menu__item" data-type="updateColType" data-old-type="${oldType}" data-new-type="${type}">
|
||||||
<svg class="b3-menu__icon"><use xlink:href="#${getColIconByType(type)}"></use></svg>
|
<svg class="b3-menu__icon"><use xlink:href="#${getColIconByType(type)}"></use></svg>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import {transaction} from "../../wysiwyg/transaction";
|
import {transaction} from "../../wysiwyg/transaction";
|
||||||
import {fetchPost} from "../../../util/fetch";
|
import {fetchPost} from "../../../util/fetch";
|
||||||
import {addCol, bindEditEvent, duplicateCol, getColIconByType, getEditHTML} from "./col";
|
import {addCol, bindEditEvent, duplicateCol, getColIconByType, getEditHTML, removeCol} from "./col";
|
||||||
import {setPosition} from "../../../util/setPosition";
|
import {setPosition} from "../../../util/setPosition";
|
||||||
import {hasClosestByAttribute, hasClosestByClassName} from "../../util/hasClosest";
|
import {hasClosestByAttribute, hasClosestByClassName} from "../../util/hasClosest";
|
||||||
import {addColOptionOrCell, bindSelectEvent, getSelectHTML, removeCellOption, setColOption} from "./select";
|
import {addColOptionOrCell, bindSelectEvent, getSelectHTML, removeCellOption, setColOption} from "./select";
|
||||||
|
|
@ -8,7 +8,7 @@ import {addFilter, getFiltersHTML, setFilter} from "./filter";
|
||||||
import {addSort, bindSortsEvent, getSortsHTML} from "./sort";
|
import {addSort, bindSortsEvent, getSortsHTML} from "./sort";
|
||||||
import {bindDateEvent, getDateHTML} from "./date";
|
import {bindDateEvent, getDateHTML} from "./date";
|
||||||
import {formatNumber} from "./number";
|
import {formatNumber} from "./number";
|
||||||
import {removeAttrViewColAnimation, updateAttrViewCellAnimation} from "./action";
|
import {updateAttrViewCellAnimation} from "./action";
|
||||||
import {addAssetLink, bindAssetEvent, editAssetItem, getAssetHTML, updateAssetCell} from "./asset";
|
import {addAssetLink, bindAssetEvent, editAssetItem, getAssetHTML, updateAssetCell} from "./asset";
|
||||||
import {Constants} from "../../../constants";
|
import {Constants} from "../../../constants";
|
||||||
import {hideElements} from "../../ui/hideElements";
|
import {hideElements} from "../../ui/hideElements";
|
||||||
|
|
@ -28,9 +28,8 @@ import {bindRelationEvent, getRelationHTML, openSearchAV, setRelationCell, updat
|
||||||
import {bindRollupData, getRollupHTML, goSearchRollupCol} from "./rollup";
|
import {bindRollupData, getRollupHTML, goSearchRollupCol} from "./rollup";
|
||||||
import {updateCellsValue} from "./cell";
|
import {updateCellsValue} from "./cell";
|
||||||
import {openCalcMenu} from "./calc";
|
import {openCalcMenu} from "./calc";
|
||||||
import * as dayjs from "dayjs";
|
|
||||||
import {confirmDialog} from "../../../dialog/confirmDialog";
|
|
||||||
import {escapeAttr} from "../../../util/escape";
|
import {escapeAttr} from "../../../util/escape";
|
||||||
|
import {Dialog} from "../../../dialog";
|
||||||
|
|
||||||
export const openMenuPanel = (options: {
|
export const openMenuPanel = (options: {
|
||||||
protyle: IProtyle,
|
protyle: IProtyle,
|
||||||
|
|
@ -1084,48 +1083,43 @@ export const openMenuPanel = (options: {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
} else if (type === "removeCol") {
|
} else if (type === "removeCol") {
|
||||||
confirmDialog(isCustomAttr ? window.siyuan.languages.deleteOpConfirm : "", isCustomAttr ? window.siyuan.languages.removeCol.replace("${x}", menuElement.querySelector("input").value) : "", () => {
|
tabRect = options.blockElement.querySelector(".av__views").getBoundingClientRect();
|
||||||
const colId = menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id");
|
const colId = menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id");
|
||||||
let previousID: string;
|
let previousID = "";
|
||||||
const colData = data.view.columns.find((item: IAVColumn, index) => {
|
const colData = data.view.columns.find((item: IAVColumn, index) => {
|
||||||
if (item.id === colId) {
|
if (item.id === colId) {
|
||||||
previousID = data.view.columns[index - 1]?.id;
|
previousID = data.view.columns[index - 1]?.id;
|
||||||
data.view.columns.splice(index, 1);
|
data.view.columns.splice(index, 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
});
|
|
||||||
const newUpdated = dayjs().format("YYYYMMDDHHmmss");
|
|
||||||
transaction(options.protyle, [{
|
|
||||||
action: "removeAttrViewCol",
|
|
||||||
id: colId,
|
|
||||||
avID,
|
|
||||||
}, {
|
|
||||||
action: "doUpdateUpdated",
|
|
||||||
id: blockID,
|
|
||||||
data: newUpdated,
|
|
||||||
}], [{
|
|
||||||
action: "addAttrViewCol",
|
|
||||||
name: colData.name,
|
|
||||||
avID,
|
|
||||||
type: colData.type,
|
|
||||||
id: colId,
|
|
||||||
previousID
|
|
||||||
}, {
|
|
||||||
action: "doUpdateUpdated",
|
|
||||||
id: blockID,
|
|
||||||
data: options.blockElement.getAttribute("updated")
|
|
||||||
}]);
|
|
||||||
removeAttrViewColAnimation(options.blockElement, colId);
|
|
||||||
options.blockElement.setAttribute("updated", newUpdated);
|
|
||||||
|
|
||||||
if (isCustomAttr) {
|
|
||||||
avPanelElement.remove();
|
|
||||||
} else {
|
|
||||||
tabRect = options.blockElement.querySelector(".av__views").getBoundingClientRect();
|
|
||||||
menuElement.innerHTML = getPropertiesHTML(data.view);
|
|
||||||
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (isCustomAttr || (colData.type === "relation" && colData.relation.isTwoWay)) {
|
||||||
|
const dialog = new Dialog({
|
||||||
|
title: window.siyuan.languages.removeCol.replace("${x}", menuElement.querySelector("input").value),
|
||||||
|
content: `<div class="b3-dialog__content">
|
||||||
|
${window.siyuan.languages.confirmRemoveRelationField.replace("${x}", (menuElement.querySelector('.b3-text-field[data-type="colName"]') as HTMLInputElement).value)}
|
||||||
|
</div>
|
||||||
|
<div class="b3-dialog__action">
|
||||||
|
<button class="b3-button b3-button--error">${window.siyuan.languages.delete}</button>
|
||||||
|
<button class="b3-button b3-button--warning">${window.siyuan.languages.removeButKeepRelationField}</button>
|
||||||
|
<button class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button>
|
||||||
|
</div>`,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
removeCol({
|
||||||
|
protyle: options.protyle,
|
||||||
|
previousID,
|
||||||
|
colData,
|
||||||
|
data,
|
||||||
|
avID,
|
||||||
|
blockID,
|
||||||
|
menuElement,
|
||||||
|
isCustomAttr,
|
||||||
|
blockElement: options.blockElement,
|
||||||
|
avPanelElement,
|
||||||
|
tabRect
|
||||||
|
});
|
||||||
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
1
app/src/types/index.d.ts
vendored
1
app/src/types/index.d.ts
vendored
|
|
@ -462,6 +462,7 @@ interface IOperation {
|
||||||
type?: TAVCol // addAttrViewCol 专享
|
type?: TAVCol // addAttrViewCol 专享
|
||||||
deckID?: string // add/removeFlashcards 专享
|
deckID?: string // add/removeFlashcards 专享
|
||||||
blockIDs?: string[] // add/removeFlashcards 专享
|
blockIDs?: string[] // add/removeFlashcards 专享
|
||||||
|
removeDest?: boolean // removeAttrViewCol 专享
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IOperationSrcs {
|
interface IOperationSrcs {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue