2023-07-02 20:52:16 +08:00
|
|
|
import {transaction} from "../../wysiwyg/transaction";
|
|
|
|
|
import {fetchPost} from "../../../util/fetch";
|
2025-01-12 18:58:59 +08:00
|
|
|
import {addCol, bindEditEvent, duplicateCol, getColIconByType, getColNameByType, getEditHTML, removeCol} from "./col";
|
2023-07-03 12:39:39 +08:00
|
|
|
import {setPosition} from "../../../util/setPosition";
|
2023-10-27 21:38:44 +08:00
|
|
|
import {hasClosestByAttribute, hasClosestByClassName} from "../../util/hasClosest";
|
2024-09-22 19:43:10 +08:00
|
|
|
import {addColOptionOrCell, bindSelectEvent, getSelectHTML, removeCellOption, setColOption} from "./select";
|
2023-07-09 23:55:29 +08:00
|
|
|
import {addFilter, getFiltersHTML, setFilter} from "./filter";
|
2023-07-09 23:54:32 +08:00
|
|
|
import {addSort, bindSortsEvent, getSortsHTML} from "./sort";
|
2023-12-29 14:56:00 +08:00
|
|
|
import {bindDateEvent, getDateHTML} from "./date";
|
2023-08-03 23:46:53 +08:00
|
|
|
import {formatNumber} from "./number";
|
2024-10-17 18:01:11 +08:00
|
|
|
import {updateAttrViewCellAnimation} from "./action";
|
2023-09-23 10:37:22 +08:00
|
|
|
import {addAssetLink, bindAssetEvent, editAssetItem, getAssetHTML, updateAssetCell} from "./asset";
|
2023-09-22 20:24:00 +08:00
|
|
|
import {Constants} from "../../../constants";
|
2023-10-01 10:26:31 +08:00
|
|
|
import {hideElements} from "../../ui/hideElements";
|
2023-10-11 17:28:40 +08:00
|
|
|
import {isLocalPath, pathPosix} from "../../../util/pathName";
|
2023-10-05 12:03:38 +08:00
|
|
|
import {openEmojiPanel, unicode2Emoji} from "../../../emoji";
|
2023-10-15 18:28:09 +08:00
|
|
|
import {getSearch} from "../../../util/functions";
|
|
|
|
|
/// #if !MOBILE
|
2023-10-11 17:28:40 +08:00
|
|
|
import {openAsset} from "../../../editor/util";
|
2023-10-15 18:28:09 +08:00
|
|
|
/// #endif
|
2023-10-11 17:28:40 +08:00
|
|
|
import {previewImage} from "../../preview/image";
|
2023-11-02 11:20:02 +08:00
|
|
|
import {assetMenu} from "../../../menus/protyle";
|
2024-10-12 12:34:41 +08:00
|
|
|
import {addView, bindSwitcherEvent, bindViewEvent, getSwitcherHTML, getViewHTML, openViewMenu} from "./view";
|
|
|
|
|
import {focusBlock} from "../../util/selection";
|
2023-12-01 16:59:04 +08:00
|
|
|
import {avRender} from "./render";
|
2023-12-08 12:37:26 +08:00
|
|
|
import {setPageSize} from "./row";
|
2023-12-24 16:54:15 +08:00
|
|
|
import {bindRelationEvent, getRelationHTML, openSearchAV, setRelationCell, updateRelation} from "./relation";
|
2024-02-26 23:39:10 +08:00
|
|
|
import {bindRollupData, getRollupHTML, goSearchRollupCol} from "./rollup";
|
2023-12-29 14:56:00 +08:00
|
|
|
import {updateCellsValue} from "./cell";
|
2023-12-30 17:41:31 +08:00
|
|
|
import {openCalcMenu} from "./calc";
|
2024-11-18 23:43:13 +08:00
|
|
|
import {escapeAttr, escapeHtml} from "../../../util/escape";
|
2024-10-17 18:01:11 +08:00
|
|
|
import {Dialog} from "../../../dialog";
|
2023-07-02 20:52:16 +08:00
|
|
|
|
2023-07-18 01:03:35 +08:00
|
|
|
export const openMenuPanel = (options: {
|
|
|
|
|
protyle: IProtyle,
|
2023-09-21 10:54:17 +08:00
|
|
|
blockElement: Element,
|
2024-01-01 17:20:22 +08:00
|
|
|
type: "select" | "properties" | "config" | "sorts" | "filters" | "edit" | "date" | "asset" | "switcher" | "relation" | "rollup",
|
|
|
|
|
colId?: string, // for edit, rollup
|
2024-02-26 23:39:10 +08:00
|
|
|
// 使用前端构造的数据
|
|
|
|
|
editData?: {
|
|
|
|
|
previousID: string,
|
|
|
|
|
colData: IAVColumn,
|
|
|
|
|
},
|
2023-12-24 16:54:15 +08:00
|
|
|
cellElements?: HTMLElement[], // for select & date & relation & asset
|
2023-12-01 11:05:27 +08:00
|
|
|
cb?: (avPanelElement: Element) => void
|
2023-07-18 01:03:35 +08:00
|
|
|
}) => {
|
2023-07-03 12:49:35 +08:00
|
|
|
let avPanelElement = document.querySelector(".av__panel");
|
|
|
|
|
if (avPanelElement) {
|
|
|
|
|
avPanelElement.remove();
|
2023-07-02 20:52:16 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2023-07-18 01:38:59 +08:00
|
|
|
const avID = options.blockElement.getAttribute("data-av-id");
|
2023-07-31 11:31:50 +08:00
|
|
|
fetchPost("/api/av/renderAttributeView", {
|
|
|
|
|
id: avID,
|
2024-08-07 22:34:56 +08:00
|
|
|
query: (options.blockElement.querySelector('[data-type="av-search"]') as HTMLInputElement)?.value.trim() || "",
|
2023-12-19 16:56:16 +08:00
|
|
|
pageSize: parseInt(options.blockElement.getAttribute("data-page-size")) || undefined,
|
2024-03-04 21:51:43 +08:00
|
|
|
viewID: options.blockElement.getAttribute(Constants.CUSTOM_SY_AV_VIEW)
|
2023-07-31 11:31:50 +08:00
|
|
|
}, (response) => {
|
2024-05-02 14:46:52 +08:00
|
|
|
avPanelElement = document.querySelector(".av__panel");
|
|
|
|
|
if (avPanelElement) {
|
|
|
|
|
avPanelElement.remove();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
const blockID = options.blockElement.getAttribute("data-node-id");
|
|
|
|
|
|
2024-01-21 12:21:31 +08:00
|
|
|
const isCustomAttr = !options.blockElement.classList.contains("av");
|
2023-07-11 22:48:48 +08:00
|
|
|
const data = response.data as IAV;
|
2023-07-02 23:59:01 +08:00
|
|
|
let html;
|
2023-07-18 01:03:35 +08:00
|
|
|
if (options.type === "config") {
|
2024-10-09 11:55:48 +08:00
|
|
|
html = getViewHTML(data);
|
2023-07-18 01:03:35 +08:00
|
|
|
} else if (options.type === "properties") {
|
2023-07-11 22:48:48 +08:00
|
|
|
html = getPropertiesHTML(data.view);
|
2023-07-18 01:03:35 +08:00
|
|
|
} else if (options.type === "sorts") {
|
2023-07-11 22:48:48 +08:00
|
|
|
html = getSortsHTML(data.view.columns, data.view.sorts);
|
2023-12-01 16:59:04 +08:00
|
|
|
} else if (options.type === "switcher") {
|
|
|
|
|
html = getSwitcherHTML(data.views, data.viewID);
|
2023-07-18 01:03:35 +08:00
|
|
|
} else if (options.type === "filters") {
|
2023-07-11 22:48:48 +08:00
|
|
|
html = getFiltersHTML(data.view);
|
2023-07-18 01:03:35 +08:00
|
|
|
} else if (options.type === "select") {
|
2024-05-17 00:42:20 +08:00
|
|
|
html = getSelectHTML(data.view, options.cellElements, true);
|
2023-09-22 12:11:56 +08:00
|
|
|
} else if (options.type === "asset") {
|
2024-01-02 23:04:25 +08:00
|
|
|
html = getAssetHTML(options.cellElements);
|
2023-07-18 01:03:35 +08:00
|
|
|
} else if (options.type === "edit") {
|
2024-02-26 23:39:10 +08:00
|
|
|
if (options.editData) {
|
|
|
|
|
if (options.editData.previousID) {
|
|
|
|
|
data.view.columns.find((item, index) => {
|
|
|
|
|
if (item.id === options.editData.previousID) {
|
|
|
|
|
data.view.columns.splice(index + 1, 0, options.editData.colData);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
data.view.columns.splice(0, 0, options.editData.colData);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-21 12:21:31 +08:00
|
|
|
html = getEditHTML({protyle: options.protyle, data, colId: options.colId, isCustomAttr});
|
2023-07-22 10:18:11 +08:00
|
|
|
} else if (options.type === "date") {
|
2025-02-28 11:08:13 +08:00
|
|
|
html = getDateHTML(options.cellElements);
|
2024-01-01 17:20:22 +08:00
|
|
|
} else if (options.type === "rollup") {
|
|
|
|
|
html = `<div class="b3-menu__items">${getRollupHTML({data, cellElements: options.cellElements})}</div>`;
|
2023-12-24 16:54:15 +08:00
|
|
|
} else if (options.type === "relation") {
|
|
|
|
|
html = getRelationHTML(data, options.cellElements);
|
|
|
|
|
if (!html) {
|
2024-01-21 12:21:31 +08:00
|
|
|
openMenuPanel({
|
|
|
|
|
protyle: options.protyle,
|
|
|
|
|
blockElement: options.blockElement,
|
|
|
|
|
type: "edit",
|
|
|
|
|
colId: options.cellElements[0].dataset.colId
|
|
|
|
|
});
|
2023-12-24 16:54:15 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2023-07-02 20:52:16 +08:00
|
|
|
}
|
2023-07-09 23:54:32 +08:00
|
|
|
|
2023-09-02 11:13:47 +08:00
|
|
|
document.body.insertAdjacentHTML("beforeend", `<div class="av__panel" style="z-index: ${++window.siyuan.zIndex}">
|
2023-07-03 12:49:35 +08:00
|
|
|
<div class="b3-dialog__scrim" data-type="close"></div>
|
|
|
|
|
<div class="b3-menu">${html}</div>
|
|
|
|
|
</div>`);
|
|
|
|
|
avPanelElement = document.querySelector(".av__panel");
|
2024-03-11 23:36:39 +08:00
|
|
|
let closeCB: () => void;
|
2023-07-03 12:49:35 +08:00
|
|
|
const menuElement = avPanelElement.lastElementChild as HTMLElement;
|
2024-04-07 18:49:56 +08:00
|
|
|
let tabRect = options.blockElement.querySelector(`.av__views, .av__row[data-col-id="${options.colId}"] > .block__logo`)?.getBoundingClientRect();
|
2024-01-01 17:20:22 +08:00
|
|
|
if (["select", "date", "asset", "relation", "rollup"].includes(options.type)) {
|
2023-07-17 19:55:46 +08:00
|
|
|
const cellRect = options.cellElements[options.cellElements.length - 1].getBoundingClientRect();
|
2023-09-22 12:11:56 +08:00
|
|
|
if (options.type === "select") {
|
2023-12-29 12:55:26 +08:00
|
|
|
bindSelectEvent(options.protyle, data, menuElement, options.cellElements, options.blockElement);
|
2023-09-22 12:11:56 +08:00
|
|
|
} else if (options.type === "date") {
|
2024-03-11 23:36:39 +08:00
|
|
|
closeCB = bindDateEvent({
|
2023-12-29 14:08:35 +08:00
|
|
|
protyle: options.protyle,
|
|
|
|
|
data,
|
|
|
|
|
menuElement,
|
|
|
|
|
cellElements: options.cellElements,
|
|
|
|
|
blockElement: options.blockElement
|
|
|
|
|
});
|
2023-09-22 12:11:56 +08:00
|
|
|
} else if (options.type === "asset") {
|
2023-12-29 14:30:46 +08:00
|
|
|
bindAssetEvent({
|
|
|
|
|
protyle: options.protyle,
|
|
|
|
|
menuElement,
|
|
|
|
|
cellElements: options.cellElements,
|
|
|
|
|
blockElement: options.blockElement
|
|
|
|
|
});
|
2023-09-22 20:24:00 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
|
setPosition(menuElement, cellRect.left, cellRect.bottom, cellRect.height);
|
2023-12-24 16:54:15 +08:00
|
|
|
}, Constants.TIMEOUT_LOAD); // 等待加载
|
|
|
|
|
} else if (options.type === "relation") {
|
2024-01-24 15:32:29 +08:00
|
|
|
bindRelationEvent({
|
|
|
|
|
menuElement,
|
|
|
|
|
cellElements: options.cellElements,
|
|
|
|
|
protyle: options.protyle,
|
|
|
|
|
blockElement: options.blockElement
|
|
|
|
|
});
|
2024-01-01 17:20:22 +08:00
|
|
|
} else if (options.type === "rollup") {
|
2024-02-26 23:39:10 +08:00
|
|
|
bindRollupData({protyle: options.protyle, data, menuElement});
|
2023-09-22 12:11:56 +08:00
|
|
|
}
|
2024-01-01 17:20:22 +08:00
|
|
|
if (["select", "date", "relation", "rollup"].includes(options.type)) {
|
2023-09-22 12:11:56 +08:00
|
|
|
const inputElement = menuElement.querySelector("input");
|
2023-12-24 16:54:15 +08:00
|
|
|
if (inputElement) {
|
|
|
|
|
inputElement.select();
|
|
|
|
|
inputElement.focus();
|
|
|
|
|
}
|
2023-09-22 20:24:00 +08:00
|
|
|
setPosition(menuElement, cellRect.left, cellRect.bottom, cellRect.height);
|
2023-09-22 12:11:56 +08:00
|
|
|
}
|
2023-07-09 23:54:32 +08:00
|
|
|
} else {
|
|
|
|
|
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
2023-07-18 01:03:35 +08:00
|
|
|
if (options.type === "sorts") {
|
2024-03-04 17:42:54 +08:00
|
|
|
bindSortsEvent(options.protyle, menuElement, data, blockID);
|
2023-07-18 01:38:59 +08:00
|
|
|
} else if (options.type === "edit") {
|
2024-04-07 11:25:52 +08:00
|
|
|
bindEditEvent({protyle: options.protyle, data, menuElement, isCustomAttr, blockID});
|
2023-12-01 09:56:29 +08:00
|
|
|
} else if (options.type === "config") {
|
2024-04-06 22:25:38 +08:00
|
|
|
bindViewEvent({protyle: options.protyle, data, menuElement, blockElement: options.blockElement});
|
2024-10-12 12:34:41 +08:00
|
|
|
} else if (options.type === "switcher") {
|
|
|
|
|
bindSwitcherEvent({protyle: options.protyle, menuElement, blockElement: options.blockElement});
|
2023-07-17 12:54:24 +08:00
|
|
|
}
|
2023-07-09 23:54:32 +08:00
|
|
|
}
|
2023-12-01 11:05:27 +08:00
|
|
|
if (options.cb) {
|
|
|
|
|
options.cb(avPanelElement);
|
|
|
|
|
}
|
2023-11-10 12:08:21 +08:00
|
|
|
avPanelElement.addEventListener("dragstart", (event: DragEvent) => {
|
2023-07-07 23:04:16 +08:00
|
|
|
window.siyuan.dragElement = event.target as HTMLElement;
|
|
|
|
|
window.siyuan.dragElement.style.opacity = ".1";
|
|
|
|
|
return;
|
|
|
|
|
});
|
|
|
|
|
avPanelElement.addEventListener("drop", (event) => {
|
2024-09-22 22:42:32 +08:00
|
|
|
counter = 0;
|
2024-05-15 11:17:34 +08:00
|
|
|
if (!window.siyuan.dragElement) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-07-07 23:04:16 +08:00
|
|
|
window.siyuan.dragElement.style.opacity = "";
|
|
|
|
|
const sourceElement = window.siyuan.dragElement;
|
|
|
|
|
window.siyuan.dragElement = undefined;
|
2023-09-24 17:53:28 +08:00
|
|
|
if (options.protyle && options.protyle.disabled) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!options.protyle && window.siyuan.config.readonly) {
|
2023-07-07 23:04:16 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-10-26 17:35:48 +08:00
|
|
|
const targetElement = avPanelElement.querySelector(".dragover__bottom, .dragover__top") as HTMLElement;
|
|
|
|
|
if (!targetElement) {
|
2023-07-07 23:04:16 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2023-07-10 19:15:22 +08:00
|
|
|
const isTop = targetElement.classList.contains("dragover__top");
|
2023-07-07 23:04:16 +08:00
|
|
|
const sourceId = sourceElement.dataset.id;
|
|
|
|
|
const targetId = targetElement.dataset.id;
|
2023-12-24 23:24:35 +08:00
|
|
|
if (targetElement.querySelector('[data-type="removeSort"]')) {
|
2023-07-11 22:48:48 +08:00
|
|
|
const changeData = data.view.sorts;
|
|
|
|
|
const oldData = Object.assign([], changeData);
|
|
|
|
|
let sortFilter: IAVSort;
|
|
|
|
|
changeData.find((sort, index: number) => {
|
|
|
|
|
if (sort.column === sourceId) {
|
|
|
|
|
sortFilter = changeData.splice(index, 1)[0];
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
changeData.find((sort, index: number) => {
|
|
|
|
|
if (sort.column === targetId) {
|
|
|
|
|
if (isTop) {
|
|
|
|
|
changeData.splice(index, 0, sortFilter);
|
|
|
|
|
} else {
|
|
|
|
|
changeData.splice(index + 1, 0, sortFilter);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-07-18 01:03:35 +08:00
|
|
|
transaction(options.protyle, [{
|
2023-07-11 22:48:48 +08:00
|
|
|
action: "setAttrViewSorts",
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: changeData,
|
|
|
|
|
blockID
|
2023-07-11 22:48:48 +08:00
|
|
|
}], [{
|
|
|
|
|
action: "setAttrViewSorts",
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: oldData,
|
|
|
|
|
blockID
|
2023-07-11 22:48:48 +08:00
|
|
|
}]);
|
|
|
|
|
menuElement.innerHTML = getSortsHTML(data.view.columns, data.view.sorts);
|
2024-03-04 17:42:54 +08:00
|
|
|
bindSortsEvent(options.protyle, menuElement, data, blockID);
|
2023-07-11 22:48:48 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2023-12-24 23:24:35 +08:00
|
|
|
if (targetElement.querySelector('[data-type="removeFilter"]')) {
|
2023-07-11 22:48:48 +08:00
|
|
|
const changeData = data.view.filters;
|
2023-07-07 23:04:16 +08:00
|
|
|
const oldData = Object.assign([], changeData);
|
2023-07-09 23:55:29 +08:00
|
|
|
let targetFilter: IAVFilter;
|
2023-07-07 23:04:16 +08:00
|
|
|
changeData.find((filter, index: number) => {
|
|
|
|
|
if (filter.column === sourceId) {
|
|
|
|
|
targetFilter = changeData.splice(index, 1)[0];
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-07-09 23:55:29 +08:00
|
|
|
});
|
2023-07-07 23:04:16 +08:00
|
|
|
changeData.find((filter, index: number) => {
|
|
|
|
|
if (filter.column === targetId) {
|
|
|
|
|
if (isTop) {
|
|
|
|
|
changeData.splice(index, 0, targetFilter);
|
|
|
|
|
} else {
|
|
|
|
|
changeData.splice(index + 1, 0, targetFilter);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-07-09 23:55:29 +08:00
|
|
|
});
|
2023-07-07 23:04:16 +08:00
|
|
|
|
2023-07-18 01:03:35 +08:00
|
|
|
transaction(options.protyle, [{
|
2023-07-11 22:48:48 +08:00
|
|
|
action: "setAttrViewFilters",
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: changeData,
|
|
|
|
|
blockID
|
2023-07-07 23:04:16 +08:00
|
|
|
}], [{
|
2023-07-11 22:48:48 +08:00
|
|
|
action: "setAttrViewFilters",
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: oldData,
|
|
|
|
|
blockID
|
2023-07-07 23:04:16 +08:00
|
|
|
}]);
|
2023-07-11 22:48:48 +08:00
|
|
|
menuElement.innerHTML = getFiltersHTML(data.view);
|
2023-07-07 23:04:16 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2023-12-24 23:24:35 +08:00
|
|
|
if (targetElement.querySelector('[data-type="av-view-edit"]')) {
|
|
|
|
|
transaction(options.protyle, [{
|
|
|
|
|
action: "sortAttrViewView",
|
|
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
blockID,
|
2023-12-24 23:24:35 +08:00
|
|
|
id: sourceId,
|
|
|
|
|
previousID: isTop ? targetElement.previousElementSibling?.getAttribute("data-id") : targetElement.getAttribute("data-id")
|
|
|
|
|
}], [{
|
|
|
|
|
action: "sortAttrViewView",
|
|
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
blockID,
|
2023-12-24 23:24:35 +08:00
|
|
|
id: sourceId,
|
|
|
|
|
previousID: sourceElement.previousElementSibling?.getAttribute("data-id")
|
|
|
|
|
}]);
|
|
|
|
|
if (isTop) {
|
|
|
|
|
targetElement.before(sourceElement);
|
|
|
|
|
targetElement.classList.remove("dragover__top");
|
|
|
|
|
} else {
|
|
|
|
|
targetElement.after(sourceElement);
|
|
|
|
|
targetElement.classList.remove("dragover__bottom");
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (targetElement.querySelector('[data-type="editAssetItem"]')) {
|
2023-09-23 12:12:16 +08:00
|
|
|
if (isTop) {
|
2023-09-26 10:33:33 +08:00
|
|
|
targetElement.before(sourceElement);
|
2023-09-23 12:12:16 +08:00
|
|
|
} else {
|
|
|
|
|
targetElement.after(sourceElement);
|
|
|
|
|
}
|
2023-09-26 09:38:16 +08:00
|
|
|
const replaceValue: IAVCellAssetValue[] = [];
|
2023-09-23 12:12:16 +08:00
|
|
|
Array.from(targetElement.parentElement.children).forEach((item: HTMLElement) => {
|
|
|
|
|
if (item.dataset.content) {
|
|
|
|
|
replaceValue.push({
|
|
|
|
|
content: item.dataset.content,
|
|
|
|
|
name: item.dataset.name,
|
|
|
|
|
type: item.dataset.type as "image" | "file",
|
2023-09-26 10:33:33 +08:00
|
|
|
});
|
2023-09-23 10:37:22 +08:00
|
|
|
}
|
2023-09-26 10:33:33 +08:00
|
|
|
});
|
2023-09-23 10:37:22 +08:00
|
|
|
updateAssetCell({
|
2023-09-23 12:12:16 +08:00
|
|
|
protyle: options.protyle,
|
|
|
|
|
cellElements: options.cellElements,
|
2023-12-29 14:30:46 +08:00
|
|
|
replaceValue,
|
|
|
|
|
blockElement: options.blockElement
|
2023-09-23 10:37:22 +08:00
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-12-24 23:24:35 +08:00
|
|
|
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 oldData = Object.assign([], changeData);
|
|
|
|
|
let targetOption: { name: string, color: string };
|
|
|
|
|
changeData.find((option, index: number) => {
|
|
|
|
|
if (option.name === sourceElement.dataset.name) {
|
|
|
|
|
targetOption = changeData.splice(index, 1)[0];
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
changeData.find((option, index: number) => {
|
|
|
|
|
if (option.name === targetElement.dataset.name) {
|
|
|
|
|
if (isTop) {
|
|
|
|
|
changeData.splice(index, 0, targetOption);
|
|
|
|
|
} else {
|
|
|
|
|
changeData.splice(index + 1, 0, targetOption);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
transaction(options.protyle, [{
|
|
|
|
|
action: "updateAttrViewColOptions",
|
|
|
|
|
id: colId,
|
2024-02-26 23:39:10 +08:00
|
|
|
avID,
|
2023-12-24 23:24:35 +08:00
|
|
|
data: changeData,
|
|
|
|
|
}], [{
|
|
|
|
|
action: "updateAttrViewColOptions",
|
|
|
|
|
id: colId,
|
2024-02-26 23:39:10 +08:00
|
|
|
avID,
|
2023-12-24 23:24:35 +08:00
|
|
|
data: oldData,
|
|
|
|
|
}]);
|
2024-06-15 10:53:06 +08:00
|
|
|
const oldScroll = menuElement.querySelector(".b3-menu__items").scrollTop;
|
2023-12-24 23:24:35 +08:00
|
|
|
if (options.cellElements) {
|
|
|
|
|
menuElement.innerHTML = getSelectHTML(data.view, options.cellElements);
|
2023-12-29 12:55:26 +08:00
|
|
|
bindSelectEvent(options.protyle, data, menuElement, options.cellElements, options.blockElement);
|
2023-12-24 23:24:35 +08:00
|
|
|
} else {
|
|
|
|
|
menuElement.innerHTML = getEditHTML({
|
|
|
|
|
protyle: options.protyle,
|
|
|
|
|
data,
|
2024-01-21 12:21:31 +08:00
|
|
|
colId,
|
|
|
|
|
isCustomAttr
|
2023-12-24 23:24:35 +08:00
|
|
|
});
|
2024-04-07 11:25:52 +08:00
|
|
|
bindEditEvent({protyle: options.protyle, data, menuElement, isCustomAttr, blockID});
|
2023-12-24 23:24:35 +08:00
|
|
|
}
|
2024-06-15 10:53:06 +08:00
|
|
|
menuElement.querySelector(".b3-menu__items").scrollTop = oldScroll;
|
2023-12-24 23:24:35 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (targetElement.getAttribute("data-type") === "setRelationCell") {
|
2023-12-24 23:35:19 +08:00
|
|
|
if (isTop) {
|
|
|
|
|
targetElement.before(sourceElement);
|
|
|
|
|
} else {
|
|
|
|
|
targetElement.after(sourceElement);
|
|
|
|
|
}
|
|
|
|
|
targetElement.classList.remove("dragover__bottom", "dragover__top");
|
2024-03-07 23:40:57 +08:00
|
|
|
const blockIDs: string[] = [];
|
2024-03-08 12:37:54 +08:00
|
|
|
const contents: IAVCellValue[] = [];
|
2024-03-07 23:40:57 +08:00
|
|
|
targetElement.parentElement.querySelectorAll(".fn__grab").forEach(item => {
|
2024-03-08 12:37:54 +08:00
|
|
|
const dateElement = item.nextElementSibling as HTMLElement;
|
|
|
|
|
blockIDs.push(dateElement.dataset.id);
|
2024-03-07 23:40:57 +08:00
|
|
|
contents.push({
|
|
|
|
|
isDetached: !dateElement.style.color,
|
|
|
|
|
type: "block",
|
|
|
|
|
block: {
|
|
|
|
|
content: dateElement.textContent,
|
|
|
|
|
id: dateElement.dataset.id
|
|
|
|
|
}
|
2024-03-08 12:37:54 +08:00
|
|
|
});
|
|
|
|
|
});
|
2024-03-07 23:40:57 +08:00
|
|
|
updateCellsValue(options.protyle, options.blockElement as HTMLElement, {
|
|
|
|
|
blockIDs,
|
|
|
|
|
contents,
|
|
|
|
|
}, options.cellElements);
|
2023-12-24 23:24:35 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-18 19:48:09 +08:00
|
|
|
if (targetElement.getAttribute("data-type") === "editCol") {
|
2024-04-19 11:20:11 +08:00
|
|
|
const previousID = (targetElement.classList.contains("dragover__top") ? targetElement.previousElementSibling?.getAttribute("data-id") : targetElement.getAttribute("data-id")) || "";
|
2024-04-18 19:48:09 +08:00
|
|
|
const undoPreviousID = sourceElement.previousElementSibling?.getAttribute("data-id") || "";
|
|
|
|
|
if (previousID !== undoPreviousID && previousID !== sourceId) {
|
|
|
|
|
transaction(options.protyle, [{
|
|
|
|
|
action: "sortAttrViewCol",
|
|
|
|
|
avID,
|
|
|
|
|
previousID,
|
|
|
|
|
id: sourceId,
|
|
|
|
|
blockID,
|
|
|
|
|
}], [{
|
|
|
|
|
action: "sortAttrViewCol",
|
|
|
|
|
avID,
|
|
|
|
|
previousID: undoPreviousID,
|
|
|
|
|
id: sourceId,
|
|
|
|
|
blockID
|
|
|
|
|
}]);
|
|
|
|
|
let column: IAVColumn;
|
|
|
|
|
data.view.columns.find((item, index: number) => {
|
|
|
|
|
if (item.id === sourceId) {
|
|
|
|
|
column = data.view.columns.splice(index, 1)[0];
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
data.view.columns.find((item, index: number) => {
|
|
|
|
|
if (item.id === targetId) {
|
|
|
|
|
if (isTop) {
|
|
|
|
|
data.view.columns.splice(index, 0, column);
|
|
|
|
|
} else {
|
|
|
|
|
data.view.columns.splice(index + 1, 0, column);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-07-07 23:04:16 +08:00
|
|
|
}
|
2024-04-18 19:48:09 +08:00
|
|
|
menuElement.innerHTML = getPropertiesHTML(data.view);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-07-07 23:04:16 +08:00
|
|
|
});
|
2023-07-09 23:55:29 +08:00
|
|
|
let dragoverElement: HTMLElement;
|
2023-07-07 23:04:16 +08:00
|
|
|
avPanelElement.addEventListener("dragover", (event: DragEvent) => {
|
2024-05-15 11:17:34 +08:00
|
|
|
if (event.dataTransfer.types.includes("Files")) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-07-07 23:04:16 +08:00
|
|
|
const target = event.target as HTMLElement;
|
2023-10-26 17:28:22 +08:00
|
|
|
let targetElement = hasClosestByAttribute(target, "draggable", "true");
|
|
|
|
|
if (!targetElement) {
|
2023-10-26 17:35:48 +08:00
|
|
|
targetElement = hasClosestByAttribute(document.elementFromPoint(event.clientX, event.clientY - 1), "draggable", "true");
|
2023-10-26 17:28:22 +08:00
|
|
|
}
|
2023-07-07 23:04:16 +08:00
|
|
|
if (!targetElement || targetElement.isSameNode(window.siyuan.dragElement)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
if (dragoverElement && targetElement.isSameNode(dragoverElement)) {
|
|
|
|
|
const nodeRect = targetElement.getBoundingClientRect();
|
2024-09-22 19:43:10 +08:00
|
|
|
avPanelElement.querySelectorAll(".dragover__bottom, .dragover__top").forEach((item: HTMLElement) => {
|
|
|
|
|
item.classList.remove("dragover__bottom", "dragover__top");
|
|
|
|
|
});
|
2023-07-07 23:04:16 +08:00
|
|
|
if (event.clientY > nodeRect.top + nodeRect.height / 2) {
|
|
|
|
|
targetElement.classList.add("dragover__bottom");
|
|
|
|
|
} else {
|
|
|
|
|
targetElement.classList.add("dragover__top");
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
dragoverElement = targetElement;
|
|
|
|
|
});
|
2024-09-24 09:02:25 +08:00
|
|
|
let counter = 0;
|
2023-10-26 17:28:22 +08:00
|
|
|
avPanelElement.addEventListener("dragleave", () => {
|
2024-09-22 19:43:10 +08:00
|
|
|
counter--;
|
|
|
|
|
if (counter === 0) {
|
|
|
|
|
avPanelElement.querySelectorAll(".dragover__bottom, .dragover__top").forEach((item: HTMLElement) => {
|
|
|
|
|
item.classList.remove("dragover__bottom", "dragover__top");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
avPanelElement.addEventListener("dragenter", (event) => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
counter++;
|
2023-07-07 23:04:16 +08:00
|
|
|
});
|
2023-07-09 23:55:29 +08:00
|
|
|
avPanelElement.addEventListener("dragend", () => {
|
2023-07-07 23:04:16 +08:00
|
|
|
if (window.siyuan.dragElement) {
|
2023-07-09 23:55:29 +08:00
|
|
|
window.siyuan.dragElement.style.opacity = "";
|
2023-07-07 23:04:16 +08:00
|
|
|
window.siyuan.dragElement = undefined;
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-09-27 22:53:19 +08:00
|
|
|
avPanelElement.addEventListener("mousedown", (event: MouseEvent & { target: HTMLElement }) => {
|
|
|
|
|
if (event.button === 1 && !hasClosestByClassName(event.target, "b3-menu")) {
|
|
|
|
|
document.querySelector(".av__panel").dispatchEvent(new CustomEvent("click", {detail: "close"}));
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-04-10 22:38:48 +08:00
|
|
|
avPanelElement.addEventListener("click", (event: MouseEvent) => {
|
|
|
|
|
let type: string;
|
|
|
|
|
if (typeof event.detail === "string") {
|
|
|
|
|
type = event.detail;
|
|
|
|
|
}
|
2023-07-02 20:52:16 +08:00
|
|
|
let target = event.target as HTMLElement;
|
2024-04-10 22:38:48 +08:00
|
|
|
while (target && !target.isSameNode(avPanelElement) || type) {
|
2024-04-15 01:28:48 +08:00
|
|
|
type = target?.dataset.type || type;
|
2023-07-02 20:52:16 +08:00
|
|
|
if (type === "close") {
|
2023-11-23 17:37:44 +08:00
|
|
|
if (!options.protyle.toolbar.subElement.classList.contains("fn__none")) {
|
2023-10-01 10:26:31 +08:00
|
|
|
// 优先关闭资源文件搜索
|
2023-10-01 10:27:07 +08:00
|
|
|
hideElements(["util"], options.protyle);
|
2023-11-23 17:37:44 +08:00
|
|
|
} else if (!window.siyuan.menus.menu.element.classList.contains("fn__none")) {
|
|
|
|
|
// 过滤面板先关闭过滤条件
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
} else {
|
2024-03-11 23:36:39 +08:00
|
|
|
closeCB?.();
|
2023-11-23 17:37:44 +08:00
|
|
|
avPanelElement.remove();
|
2023-12-27 00:18:49 +08:00
|
|
|
focusBlock(options.blockElement);
|
2023-10-01 10:26:31 +08:00
|
|
|
}
|
2023-07-03 20:54:57 +08:00
|
|
|
window.siyuan.menus.menu.remove();
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-02 21:53:02 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-12-08 12:37:26 +08:00
|
|
|
} else if (type === "go-config") {
|
2024-10-09 11:55:48 +08:00
|
|
|
menuElement.innerHTML = getViewHTML(data);
|
2023-07-03 12:49:35 +08:00
|
|
|
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
2024-04-06 22:25:38 +08:00
|
|
|
bindViewEvent({protyle: options.protyle, data, menuElement, blockElement: options.blockElement});
|
2024-04-10 22:38:48 +08:00
|
|
|
window.siyuan.menus.menu.remove();
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-02 21:53:02 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-12-08 12:37:26 +08:00
|
|
|
} else if (type === "go-properties") {
|
2024-04-07 18:49:56 +08:00
|
|
|
// 复制列后点击返回到属性面板,宽度不一致,需重新计算
|
|
|
|
|
tabRect = options.blockElement.querySelector(".av__views").getBoundingClientRect();
|
2023-07-11 22:48:48 +08:00
|
|
|
menuElement.innerHTML = getPropertiesHTML(data.view);
|
2023-07-03 12:49:35 +08:00
|
|
|
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
2024-04-10 22:38:48 +08:00
|
|
|
window.siyuan.menus.menu.remove();
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-02 21:53:02 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-07-03 12:25:02 +08:00
|
|
|
} else if (type === "goSorts") {
|
2023-07-11 22:48:48 +08:00
|
|
|
menuElement.innerHTML = getSortsHTML(data.view.columns, data.view.sorts);
|
2024-03-04 17:42:54 +08:00
|
|
|
bindSortsEvent(options.protyle, menuElement, data, blockID);
|
2023-07-03 12:49:35 +08:00
|
|
|
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
2024-04-10 22:38:48 +08:00
|
|
|
window.siyuan.menus.menu.remove();
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-03 12:25:02 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
|
|
|
|
} else if (type === "removeSorts") {
|
2023-07-18 01:03:35 +08:00
|
|
|
transaction(options.protyle, [{
|
2023-07-11 22:48:48 +08:00
|
|
|
action: "setAttrViewSorts",
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: [],
|
|
|
|
|
blockID
|
2023-07-03 16:03:52 +08:00
|
|
|
}], [{
|
2023-07-11 22:48:48 +08:00
|
|
|
action: "setAttrViewSorts",
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: data.view.sorts,
|
|
|
|
|
blockID
|
2023-07-03 16:03:52 +08:00
|
|
|
}]);
|
2023-07-11 22:48:48 +08:00
|
|
|
data.view.sorts = [];
|
|
|
|
|
menuElement.innerHTML = getSortsHTML(data.view.columns, data.view.sorts);
|
2024-03-04 17:42:54 +08:00
|
|
|
bindSortsEvent(options.protyle, menuElement, data, blockID);
|
2023-07-03 16:03:52 +08:00
|
|
|
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-03 12:25:02 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
|
|
|
|
} else if (type === "addSort") {
|
2023-07-18 01:03:35 +08:00
|
|
|
addSort({
|
|
|
|
|
data,
|
|
|
|
|
rect: target.getBoundingClientRect(),
|
|
|
|
|
menuElement,
|
|
|
|
|
tabRect,
|
2023-07-18 01:38:59 +08:00
|
|
|
avId: avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
protyle: options.protyle,
|
|
|
|
|
blockID,
|
2023-07-18 01:03:35 +08:00
|
|
|
});
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-03 12:25:02 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
|
|
|
|
} else if (type === "removeSort") {
|
2023-07-11 22:48:48 +08:00
|
|
|
const oldSorts = Object.assign([], data.view.sorts);
|
|
|
|
|
data.view.sorts.find((item: IAVSort, index: number) => {
|
2023-07-03 20:54:57 +08:00
|
|
|
if (item.column === target.parentElement.dataset.id) {
|
2023-07-11 22:48:48 +08:00
|
|
|
data.view.sorts.splice(index, 1);
|
2023-07-03 20:54:57 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-07-18 01:03:35 +08:00
|
|
|
transaction(options.protyle, [{
|
2023-07-11 22:48:48 +08:00
|
|
|
action: "setAttrViewSorts",
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: data.view.sorts,
|
|
|
|
|
blockID
|
2023-07-03 20:54:57 +08:00
|
|
|
}], [{
|
2023-07-11 22:48:48 +08:00
|
|
|
action: "setAttrViewSorts",
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: oldSorts,
|
|
|
|
|
blockID
|
2023-07-03 20:54:57 +08:00
|
|
|
}]);
|
2023-07-11 22:48:48 +08:00
|
|
|
menuElement.innerHTML = getSortsHTML(data.view.columns, data.view.sorts);
|
2024-03-04 17:42:54 +08:00
|
|
|
bindSortsEvent(options.protyle, menuElement, data, blockID);
|
2023-07-03 20:54:57 +08:00
|
|
|
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-03 12:25:02 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-07-06 18:56:16 +08:00
|
|
|
} else if (type === "goFilters") {
|
2023-07-11 22:48:48 +08:00
|
|
|
menuElement.innerHTML = getFiltersHTML(data.view);
|
2023-07-06 18:56:16 +08:00
|
|
|
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
2024-04-10 22:38:48 +08:00
|
|
|
window.siyuan.menus.menu.remove();
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-06 18:56:16 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
|
|
|
|
} else if (type === "removeFilters") {
|
2023-07-18 01:03:35 +08:00
|
|
|
transaction(options.protyle, [{
|
2023-07-11 22:48:48 +08:00
|
|
|
action: "setAttrViewFilters",
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: [],
|
|
|
|
|
blockID
|
2023-07-06 18:56:16 +08:00
|
|
|
}], [{
|
2023-07-11 22:48:48 +08:00
|
|
|
action: "setAttrViewFilters",
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: data.view.filters,
|
|
|
|
|
blockID
|
2023-07-06 18:56:16 +08:00
|
|
|
}]);
|
2023-07-11 22:48:48 +08:00
|
|
|
data.view.filters = [];
|
|
|
|
|
menuElement.innerHTML = getFiltersHTML(data.view);
|
2023-07-06 18:56:16 +08:00
|
|
|
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
2024-04-14 12:13:15 +08:00
|
|
|
window.siyuan.menus.menu.remove();
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-06 18:56:16 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
|
|
|
|
} else if (type === "addFilter") {
|
2023-07-18 01:03:35 +08:00
|
|
|
addFilter({
|
|
|
|
|
data,
|
|
|
|
|
rect: target.getBoundingClientRect(),
|
|
|
|
|
menuElement,
|
|
|
|
|
tabRect,
|
2023-07-18 01:38:59 +08:00
|
|
|
avId: avID,
|
2023-12-31 00:09:47 +08:00
|
|
|
protyle: options.protyle,
|
|
|
|
|
blockElement: options.blockElement
|
2023-07-18 01:03:35 +08:00
|
|
|
});
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-06 18:56:16 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
|
|
|
|
} else if (type === "removeFilter") {
|
2023-07-07 11:12:49 +08:00
|
|
|
window.siyuan.menus.menu.remove();
|
2023-07-11 22:48:48 +08:00
|
|
|
const oldFilters = Object.assign([], data.view.filters);
|
|
|
|
|
data.view.filters.find((item: IAVFilter, index: number) => {
|
2024-03-06 22:20:46 +08:00
|
|
|
if (item.column === target.parentElement.dataset.id && item.value.type === target.parentElement.dataset.filterType) {
|
2023-07-11 22:48:48 +08:00
|
|
|
data.view.filters.splice(index, 1);
|
2023-07-06 18:56:16 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-07-18 01:03:35 +08:00
|
|
|
transaction(options.protyle, [{
|
2023-07-11 22:48:48 +08:00
|
|
|
action: "setAttrViewFilters",
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: data.view.filters,
|
|
|
|
|
blockID
|
2023-07-06 18:56:16 +08:00
|
|
|
}], [{
|
2023-07-11 22:48:48 +08:00
|
|
|
action: "setAttrViewFilters",
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: oldFilters,
|
|
|
|
|
blockID
|
2023-07-06 18:56:16 +08:00
|
|
|
}]);
|
2023-07-11 22:48:48 +08:00
|
|
|
menuElement.innerHTML = getFiltersHTML(data.view);
|
2023-07-06 18:56:16 +08:00
|
|
|
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-06 18:56:16 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-07-06 21:52:34 +08:00
|
|
|
} else if (type === "setFilter") {
|
2023-07-11 22:48:48 +08:00
|
|
|
data.view.filters.find((item: IAVFilter) => {
|
2024-03-06 22:20:46 +08:00
|
|
|
if (item.column === target.parentElement.parentElement.dataset.id && item.value.type === target.parentElement.parentElement.dataset.filterType) {
|
2023-07-10 22:15:14 +08:00
|
|
|
setFilter({
|
|
|
|
|
filter: item,
|
2023-07-18 01:03:35 +08:00
|
|
|
protyle: options.protyle,
|
2023-07-10 22:15:14 +08:00
|
|
|
data,
|
2023-12-31 00:09:47 +08:00
|
|
|
target,
|
|
|
|
|
blockElement: options.blockElement
|
2023-07-10 22:15:14 +08:00
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-07-12 00:08:00 +08:00
|
|
|
});
|
2023-08-03 23:23:28 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
|
|
|
|
} else if (type === "numberFormat") {
|
2023-08-03 23:46:53 +08:00
|
|
|
formatNumber({
|
|
|
|
|
avPanelElement,
|
|
|
|
|
element: target,
|
|
|
|
|
protyle: options.protyle,
|
|
|
|
|
oldFormat: target.dataset.format,
|
|
|
|
|
colId: menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id"),
|
|
|
|
|
avID
|
|
|
|
|
});
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-06 21:52:34 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-07-02 21:53:02 +08:00
|
|
|
} else if (type === "newCol") {
|
2023-07-03 12:49:35 +08:00
|
|
|
avPanelElement.remove();
|
2023-07-18 01:03:35 +08:00
|
|
|
const addMenu = addCol(options.protyle, options.blockElement);
|
2023-07-02 21:53:02 +08:00
|
|
|
addMenu.open({
|
|
|
|
|
x: tabRect.right,
|
|
|
|
|
y: tabRect.bottom,
|
|
|
|
|
h: tabRect.height,
|
|
|
|
|
isLeft: true
|
|
|
|
|
});
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-02 21:53:02 +08:00
|
|
|
event.stopPropagation();
|
2023-10-04 21:54:39 +08:00
|
|
|
break;
|
2023-12-01 09:56:29 +08:00
|
|
|
} else if (type === "update-view-icon") {
|
2023-12-01 10:22:52 +08:00
|
|
|
const rect = target.getBoundingClientRect();
|
|
|
|
|
openEmojiPanel("", "av", {
|
|
|
|
|
x: rect.left,
|
2024-10-27 16:49:05 +08:00
|
|
|
y: rect.bottom + 4,
|
2023-12-01 10:22:52 +08:00
|
|
|
h: rect.height,
|
|
|
|
|
w: rect.width
|
|
|
|
|
}, (unicode) => {
|
|
|
|
|
transaction(options.protyle, [{
|
|
|
|
|
action: "setAttrViewViewIcon",
|
|
|
|
|
avID,
|
|
|
|
|
id: data.viewID,
|
|
|
|
|
data: unicode,
|
|
|
|
|
}], [{
|
|
|
|
|
action: "setAttrViewViewIcon",
|
|
|
|
|
id: data.viewID,
|
|
|
|
|
avID,
|
|
|
|
|
data: target.dataset.icon,
|
|
|
|
|
}]);
|
2024-10-26 10:35:42 +08:00
|
|
|
target.innerHTML = unicode ? unicode2Emoji(unicode) : '<svg style="width: 14px;height: 14px;"><use xlink:href="#iconTable"></use></svg>';
|
2023-12-01 11:50:34 +08:00
|
|
|
target.dataset.icon = unicode;
|
2024-11-13 00:51:30 +08:00
|
|
|
}, target.querySelector("img"));
|
2023-12-01 10:22:52 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-12-08 12:37:26 +08:00
|
|
|
} else if (type === "set-page-size") {
|
2023-12-08 22:54:18 +08:00
|
|
|
setPageSize({
|
|
|
|
|
target,
|
|
|
|
|
protyle: options.protyle,
|
|
|
|
|
avID,
|
|
|
|
|
nodeElement: options.blockElement
|
|
|
|
|
});
|
2023-12-08 12:37:26 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-12-01 10:22:52 +08:00
|
|
|
} else if (type === "duplicate-view") {
|
|
|
|
|
const id = Lute.NewNodeID();
|
|
|
|
|
transaction(options.protyle, [{
|
|
|
|
|
action: "duplicateAttrViewView",
|
|
|
|
|
avID,
|
|
|
|
|
previousID: data.viewID,
|
2024-03-04 17:42:54 +08:00
|
|
|
id,
|
|
|
|
|
blockID
|
2023-12-01 10:22:52 +08:00
|
|
|
}], [{
|
|
|
|
|
action: "removeAttrViewView",
|
|
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
id,
|
|
|
|
|
blockID
|
2023-12-01 10:22:52 +08:00
|
|
|
}]);
|
2024-03-04 21:52:29 +08:00
|
|
|
options.blockElement.setAttribute(Constants.CUSTOM_SY_AV_VIEW, id);
|
2023-12-01 10:39:07 +08:00
|
|
|
avPanelElement.remove();
|
2023-12-01 10:22:52 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
|
|
|
|
} else if (type === "delete-view") {
|
2024-10-09 11:55:48 +08:00
|
|
|
transaction(options.protyle, [{
|
|
|
|
|
action: "removeAttrViewView",
|
|
|
|
|
avID,
|
|
|
|
|
id: data.viewID,
|
|
|
|
|
blockID
|
|
|
|
|
}]);
|
2023-12-01 10:39:07 +08:00
|
|
|
avPanelElement.remove();
|
2023-12-01 09:56:29 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-10-04 21:54:39 +08:00
|
|
|
} else if (type === "update-icon") {
|
|
|
|
|
const rect = target.getBoundingClientRect();
|
|
|
|
|
openEmojiPanel("", "av", {
|
|
|
|
|
x: rect.left,
|
2024-10-27 16:49:05 +08:00
|
|
|
y: rect.bottom + 4,
|
2023-10-04 21:54:39 +08:00
|
|
|
h: rect.height,
|
|
|
|
|
w: rect.width
|
2023-10-05 12:03:38 +08:00
|
|
|
}, (unicode) => {
|
|
|
|
|
const colId = menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id");
|
|
|
|
|
transaction(options.protyle, [{
|
|
|
|
|
action: "setAttrViewColIcon",
|
|
|
|
|
id: colId,
|
|
|
|
|
avID,
|
|
|
|
|
data: unicode,
|
|
|
|
|
}], [{
|
|
|
|
|
action: "setAttrViewColIcon",
|
|
|
|
|
id: colId,
|
|
|
|
|
avID,
|
|
|
|
|
data: target.dataset.icon,
|
|
|
|
|
}]);
|
2024-10-26 10:35:42 +08:00
|
|
|
target.innerHTML = unicode ? unicode2Emoji(unicode) : `<svg style="height: 14px;width: 14px"><use xlink:href="#${getColIconByType(target.dataset.colType as TAVCol)}"></use></svg>`;
|
2024-01-21 12:21:31 +08:00
|
|
|
if (isCustomAttr) {
|
2024-01-23 16:07:58 +08:00
|
|
|
const iconElement = options.blockElement.querySelector(`.av__row[data-col-id="${colId}"] .block__logoicon`);
|
2024-01-21 12:21:31 +08:00
|
|
|
iconElement.outerHTML = unicode ? unicode2Emoji(unicode, "block__logoicon", true) : `<svg class="block__logoicon"><use xlink:href="#${getColIconByType(iconElement.nextElementSibling.getAttribute("data-type") as TAVCol)}"></use></svg>`;
|
|
|
|
|
} else {
|
|
|
|
|
updateAttrViewCellAnimation(options.blockElement.querySelector(`.av__row--header .av__cell[data-col-id="${colId}"]`), undefined, {icon: unicode});
|
|
|
|
|
}
|
2023-12-01 11:50:34 +08:00
|
|
|
target.dataset.icon = unicode;
|
2024-11-13 00:51:30 +08:00
|
|
|
}, target.querySelector("img"));
|
2023-10-04 21:54:39 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
2023-07-02 21:53:02 +08:00
|
|
|
break;
|
|
|
|
|
} else if (type === "showAllCol") {
|
2023-07-02 23:59:01 +08:00
|
|
|
const doOperations: IOperation[] = [];
|
|
|
|
|
const undoOperations: IOperation[] = [];
|
2023-07-11 22:48:48 +08:00
|
|
|
data.view.columns.forEach((item: IAVColumn) => {
|
2023-07-02 22:18:21 +08:00
|
|
|
if (item.hidden) {
|
|
|
|
|
doOperations.push({
|
|
|
|
|
action: "setAttrViewColHidden",
|
|
|
|
|
id: item.id,
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: false,
|
|
|
|
|
blockID,
|
2023-07-02 23:59:01 +08:00
|
|
|
});
|
2023-07-02 22:18:21 +08:00
|
|
|
undoOperations.push({
|
|
|
|
|
action: "setAttrViewColHidden",
|
|
|
|
|
id: item.id,
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: true,
|
|
|
|
|
blockID
|
2023-07-02 23:59:01 +08:00
|
|
|
});
|
|
|
|
|
item.hidden = false;
|
2023-07-02 22:18:21 +08:00
|
|
|
}
|
2023-07-02 23:59:01 +08:00
|
|
|
});
|
2023-07-02 22:18:21 +08:00
|
|
|
if (doOperations.length > 0) {
|
2023-07-18 01:03:35 +08:00
|
|
|
transaction(options.protyle, doOperations, undoOperations);
|
2023-07-11 22:48:48 +08:00
|
|
|
menuElement.innerHTML = getPropertiesHTML(data.view);
|
2023-07-03 12:49:35 +08:00
|
|
|
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
2023-07-02 22:18:21 +08:00
|
|
|
}
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-02 21:53:02 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
|
|
|
|
} else if (type === "hideAllCol") {
|
2023-07-02 23:59:01 +08:00
|
|
|
const doOperations: IOperation[] = [];
|
|
|
|
|
const undoOperations: IOperation[] = [];
|
2023-07-11 22:48:48 +08:00
|
|
|
data.view.columns.forEach((item: IAVColumn) => {
|
2023-07-02 22:18:21 +08:00
|
|
|
if (!item.hidden && item.type !== "block") {
|
|
|
|
|
doOperations.push({
|
|
|
|
|
action: "setAttrViewColHidden",
|
|
|
|
|
id: item.id,
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: true,
|
|
|
|
|
blockID
|
2023-07-02 23:59:01 +08:00
|
|
|
});
|
2023-07-02 22:18:21 +08:00
|
|
|
undoOperations.push({
|
|
|
|
|
action: "setAttrViewColHidden",
|
|
|
|
|
id: item.id,
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: false,
|
|
|
|
|
blockID
|
2023-07-02 23:59:01 +08:00
|
|
|
});
|
|
|
|
|
item.hidden = true;
|
2023-07-02 22:18:21 +08:00
|
|
|
}
|
2023-07-02 23:59:01 +08:00
|
|
|
});
|
2023-07-02 22:18:21 +08:00
|
|
|
if (doOperations.length > 0) {
|
2023-07-18 01:03:35 +08:00
|
|
|
transaction(options.protyle, doOperations, undoOperations);
|
2023-07-11 22:48:48 +08:00
|
|
|
menuElement.innerHTML = getPropertiesHTML(data.view);
|
2023-07-03 12:49:35 +08:00
|
|
|
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
2023-07-02 22:18:21 +08:00
|
|
|
}
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-02 21:53:02 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-07-18 01:03:35 +08:00
|
|
|
} else if (type === "editCol") {
|
|
|
|
|
menuElement.innerHTML = getEditHTML({
|
|
|
|
|
protyle: options.protyle,
|
|
|
|
|
data,
|
2024-04-07 10:16:11 +08:00
|
|
|
colId: target.dataset.id,
|
2024-01-21 12:21:31 +08:00
|
|
|
isCustomAttr
|
2023-07-18 01:03:35 +08:00
|
|
|
});
|
2024-04-07 11:25:52 +08:00
|
|
|
bindEditEvent({protyle: options.protyle, data, menuElement, isCustomAttr, blockID});
|
2023-12-24 11:11:07 +08:00
|
|
|
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-18 01:03:35 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-10-27 21:38:44 +08:00
|
|
|
} else if (type === "updateColType") {
|
|
|
|
|
if (target.dataset.newType !== target.dataset.oldType) {
|
2025-01-16 10:00:30 +08:00
|
|
|
const nameElement = avPanelElement.querySelector('.b3-text-field[data-type="name"]') as HTMLInputElement;
|
2025-01-12 18:58:59 +08:00
|
|
|
const name = nameElement.value;
|
|
|
|
|
let newName = name;
|
|
|
|
|
data.view.columns.find((item: IAVColumn) => {
|
|
|
|
|
if (item.id === options.colId) {
|
|
|
|
|
item.type = target.dataset.newType as TAVCol;
|
|
|
|
|
if (getColNameByType(target.dataset.oldType as TAVCol) === name) {
|
|
|
|
|
newName = getColNameByType(target.dataset.newType as TAVCol);
|
|
|
|
|
item.name = newName;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2023-10-27 21:38:44 +08:00
|
|
|
transaction(options.protyle, [{
|
|
|
|
|
action: "updateAttrViewCol",
|
|
|
|
|
id: options.colId,
|
|
|
|
|
avID,
|
2025-01-12 18:58:59 +08:00
|
|
|
name: newName,
|
2023-10-27 21:38:44 +08:00
|
|
|
type: target.dataset.newType as TAVCol,
|
|
|
|
|
}], [{
|
|
|
|
|
action: "updateAttrViewCol",
|
|
|
|
|
id: options.colId,
|
|
|
|
|
avID,
|
|
|
|
|
name,
|
2023-11-02 11:20:02 +08:00
|
|
|
type: target.dataset.oldType as TAVCol,
|
2023-10-27 21:38:44 +08:00
|
|
|
}]);
|
2024-04-15 00:49:48 +08:00
|
|
|
|
|
|
|
|
// 需要取消 lineNumber 列的排序和过滤
|
|
|
|
|
if (target.dataset.newType === "lineNumber") {
|
|
|
|
|
const sortExist = data.view.sorts.find((sort) => sort.column === options.colId);
|
|
|
|
|
if (sortExist) {
|
|
|
|
|
const oldSorts = Object.assign([], data.view.sorts);
|
|
|
|
|
const newSorts = data.view.sorts.filter((sort) => sort.column !== options.colId);
|
|
|
|
|
|
|
|
|
|
transaction(options.protyle, [{
|
|
|
|
|
action: "setAttrViewSorts",
|
|
|
|
|
avID: data.id,
|
|
|
|
|
data: newSorts,
|
|
|
|
|
blockID,
|
|
|
|
|
}], [{
|
|
|
|
|
action: "setAttrViewSorts",
|
|
|
|
|
avID: data.id,
|
|
|
|
|
data: oldSorts,
|
|
|
|
|
blockID,
|
|
|
|
|
}]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const filterExist = data.view.filters.find((filter) => filter.column === options.colId);
|
|
|
|
|
if (filterExist) {
|
|
|
|
|
const oldFilters = JSON.parse(JSON.stringify(data.view.filters));
|
|
|
|
|
const newFilters = data.view.filters.filter((filter) => filter.column !== options.colId);
|
|
|
|
|
|
|
|
|
|
transaction(options.protyle, [{
|
|
|
|
|
action: "setAttrViewFilters",
|
|
|
|
|
avID: data.id,
|
|
|
|
|
data: newFilters,
|
|
|
|
|
blockID
|
|
|
|
|
}], [{
|
|
|
|
|
action: "setAttrViewFilters",
|
|
|
|
|
avID: data.id,
|
|
|
|
|
data: oldFilters,
|
|
|
|
|
blockID
|
|
|
|
|
}]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-27 21:38:44 +08:00
|
|
|
}
|
2024-04-18 23:27:27 +08:00
|
|
|
menuElement.innerHTML = getEditHTML({
|
|
|
|
|
protyle: options.protyle,
|
|
|
|
|
data,
|
|
|
|
|
colId: options.colId,
|
|
|
|
|
isCustomAttr
|
|
|
|
|
});
|
|
|
|
|
bindEditEvent({protyle: options.protyle, data, menuElement, isCustomAttr, blockID});
|
|
|
|
|
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
2023-10-27 21:38:44 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
|
|
|
|
} else if (type === "goUpdateColType") {
|
2023-10-28 11:44:59 +08:00
|
|
|
const editMenuElement = hasClosestByClassName(target, "b3-menu");
|
2023-10-27 21:38:44 +08:00
|
|
|
if (editMenuElement) {
|
|
|
|
|
editMenuElement.firstElementChild.classList.add("fn__none");
|
|
|
|
|
editMenuElement.lastElementChild.classList.remove("fn__none");
|
|
|
|
|
}
|
|
|
|
|
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
2023-12-23 20:25:58 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
|
|
|
|
} else if (type === "goSearchAV") {
|
2024-05-06 10:55:02 +08:00
|
|
|
openSearchAV(avID, target, undefined, false);
|
2023-12-23 23:50:04 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-12-29 10:30:21 +08:00
|
|
|
} else if (type === "goSearchRollupCol") {
|
2023-12-29 11:09:45 +08:00
|
|
|
goSearchRollupCol({
|
|
|
|
|
target,
|
|
|
|
|
data,
|
2023-12-30 17:41:31 +08:00
|
|
|
isRelation: true,
|
2023-12-29 11:09:45 +08:00
|
|
|
protyle: options.protyle,
|
2024-01-01 17:20:22 +08:00
|
|
|
colId: options.colId || menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id")
|
2023-12-29 11:09:45 +08:00
|
|
|
});
|
2023-12-29 10:30:21 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
|
|
|
|
} else if (type === "goSearchRollupTarget") {
|
2023-12-30 17:41:31 +08:00
|
|
|
goSearchRollupCol({
|
|
|
|
|
target,
|
|
|
|
|
data,
|
|
|
|
|
isRelation: false,
|
|
|
|
|
protyle: options.protyle,
|
2024-01-01 17:20:22 +08:00
|
|
|
colId: options.colId || menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id")
|
2023-12-30 17:41:31 +08:00
|
|
|
});
|
2023-12-29 10:30:21 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
|
|
|
|
} else if (type === "goSearchRollupCalc") {
|
2024-04-07 10:43:56 +08:00
|
|
|
openCalcMenu(options.protyle, target, {
|
|
|
|
|
data,
|
|
|
|
|
colId: options.colId || menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id"),
|
|
|
|
|
blockID
|
|
|
|
|
});
|
2023-12-29 10:30:21 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-12-23 23:50:04 +08:00
|
|
|
} else if (type === "updateRelation") {
|
|
|
|
|
updateRelation({
|
|
|
|
|
protyle: options.protyle,
|
|
|
|
|
avElement: avPanelElement,
|
2023-12-25 12:41:29 +08:00
|
|
|
avID,
|
|
|
|
|
colsData: data.view.columns,
|
|
|
|
|
blockElement: options.blockElement,
|
2023-12-23 23:50:04 +08:00
|
|
|
});
|
2023-10-27 21:38:44 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
|
|
|
|
} else if (type === "goEditCol") {
|
2023-10-28 11:44:59 +08:00
|
|
|
const editMenuElement = hasClosestByClassName(target, "b3-menu");
|
2023-10-27 21:38:44 +08:00
|
|
|
if (editMenuElement) {
|
|
|
|
|
editMenuElement.firstElementChild.classList.remove("fn__none");
|
|
|
|
|
editMenuElement.lastElementChild.classList.add("fn__none");
|
|
|
|
|
}
|
|
|
|
|
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-07-02 21:53:02 +08:00
|
|
|
} else if (type === "hideCol") {
|
2023-12-08 12:37:26 +08:00
|
|
|
const isEdit = menuElement.querySelector('[data-type="go-properties"]');
|
2023-08-02 15:19:56 +08:00
|
|
|
const colId = isEdit ? menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id") : target.parentElement.getAttribute("data-id");
|
2023-07-18 01:03:35 +08:00
|
|
|
transaction(options.protyle, [{
|
2023-07-02 21:53:02 +08:00
|
|
|
action: "setAttrViewColHidden",
|
|
|
|
|
id: colId,
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: true,
|
|
|
|
|
blockID
|
2023-07-02 21:53:02 +08:00
|
|
|
}], [{
|
|
|
|
|
action: "setAttrViewColHidden",
|
|
|
|
|
id: colId,
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: false,
|
|
|
|
|
blockID
|
2023-07-02 21:53:02 +08:00
|
|
|
}]);
|
2023-07-11 22:48:48 +08:00
|
|
|
data.view.columns.find((item: IAVColumn) => item.id === colId).hidden = true;
|
2023-07-18 01:38:59 +08:00
|
|
|
if (isEdit) {
|
|
|
|
|
menuElement.innerHTML = getEditHTML({
|
|
|
|
|
protyle: options.protyle,
|
|
|
|
|
data,
|
2024-01-21 12:21:31 +08:00
|
|
|
colId,
|
|
|
|
|
isCustomAttr
|
2023-07-18 01:38:59 +08:00
|
|
|
});
|
2024-04-07 11:25:52 +08:00
|
|
|
bindEditEvent({protyle: options.protyle, data, menuElement, isCustomAttr, blockID});
|
2023-07-18 01:38:59 +08:00
|
|
|
} else {
|
|
|
|
|
menuElement.innerHTML = getPropertiesHTML(data.view);
|
|
|
|
|
}
|
2023-07-03 12:49:35 +08:00
|
|
|
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-02 21:53:02 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
|
|
|
|
} else if (type === "showCol") {
|
2023-12-08 12:37:26 +08:00
|
|
|
const isEdit = menuElement.querySelector('[data-type="go-properties"]');
|
2023-08-02 15:19:56 +08:00
|
|
|
const colId = isEdit ? menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id") : target.parentElement.getAttribute("data-id");
|
2023-07-18 01:03:35 +08:00
|
|
|
transaction(options.protyle, [{
|
2023-07-02 21:53:02 +08:00
|
|
|
action: "setAttrViewColHidden",
|
|
|
|
|
id: colId,
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: false,
|
|
|
|
|
blockID
|
2023-07-02 21:53:02 +08:00
|
|
|
}], [{
|
|
|
|
|
action: "setAttrViewColHidden",
|
|
|
|
|
id: colId,
|
2023-07-18 01:38:59 +08:00
|
|
|
avID,
|
2024-03-04 17:42:54 +08:00
|
|
|
data: true,
|
|
|
|
|
blockID
|
2023-07-02 21:53:02 +08:00
|
|
|
}]);
|
2023-07-11 22:48:48 +08:00
|
|
|
data.view.columns.find((item: IAVColumn) => item.id === colId).hidden = false;
|
2023-07-18 01:38:59 +08:00
|
|
|
if (isEdit) {
|
|
|
|
|
menuElement.innerHTML = getEditHTML({
|
|
|
|
|
protyle: options.protyle,
|
|
|
|
|
data,
|
2024-01-21 12:21:31 +08:00
|
|
|
colId,
|
|
|
|
|
isCustomAttr
|
2023-07-18 01:38:59 +08:00
|
|
|
});
|
2024-04-07 11:25:52 +08:00
|
|
|
bindEditEvent({protyle: options.protyle, data, menuElement, isCustomAttr, blockID});
|
2023-07-18 01:38:59 +08:00
|
|
|
} else {
|
|
|
|
|
menuElement.innerHTML = getPropertiesHTML(data.view);
|
|
|
|
|
}
|
2023-07-03 12:49:35 +08:00
|
|
|
setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-02 21:53:02 +08:00
|
|
|
event.stopPropagation();
|
2023-07-02 20:52:16 +08:00
|
|
|
break;
|
2023-07-18 01:38:59 +08:00
|
|
|
} else if (type === "duplicateCol") {
|
2023-07-31 11:31:50 +08:00
|
|
|
duplicateCol({
|
2024-03-08 21:37:42 +08:00
|
|
|
blockElement: options.blockElement,
|
2023-07-31 11:31:50 +08:00
|
|
|
protyle: options.protyle,
|
2024-04-07 18:49:56 +08:00
|
|
|
colId: menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id"),
|
|
|
|
|
data,
|
2024-03-04 21:51:43 +08:00
|
|
|
viewID: data.viewID,
|
2023-07-31 11:31:50 +08:00
|
|
|
});
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-18 01:38:59 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
|
|
|
|
} else if (type === "removeCol") {
|
2024-10-17 18:42:17 +08:00
|
|
|
if (!isCustomAttr) {
|
|
|
|
|
tabRect = options.blockElement.querySelector(".av__views").getBoundingClientRect();
|
|
|
|
|
}
|
2024-10-17 18:01:11 +08:00
|
|
|
const colId = menuElement.querySelector(".b3-menu__item").getAttribute("data-col-id");
|
2024-10-17 18:42:17 +08:00
|
|
|
const colData = data.view.columns.find((item: IAVColumn) => {
|
2024-10-17 18:01:11 +08:00
|
|
|
if (item.id === colId) {
|
|
|
|
|
return true;
|
2024-04-07 18:49:56 +08:00
|
|
|
}
|
2024-03-25 17:38:13 +08:00
|
|
|
});
|
2024-10-17 22:14:12 +08:00
|
|
|
const isTwoWay = colData.type === "relation" && colData.relation?.isTwoWay;
|
2024-10-17 18:42:17 +08:00
|
|
|
if (isCustomAttr || isTwoWay) {
|
2024-10-17 18:01:11 +08:00
|
|
|
const dialog = new Dialog({
|
2024-10-17 18:42:17 +08:00
|
|
|
title: isTwoWay ? window.siyuan.languages.removeCol.replace("${x}", menuElement.querySelector("input").value) : window.siyuan.languages.deleteOpConfirm,
|
2024-10-17 18:01:11 +08:00
|
|
|
content: `<div class="b3-dialog__content">
|
2024-10-17 18:42:17 +08:00
|
|
|
${isTwoWay ? window.siyuan.languages.confirmRemoveRelationField.replace("${x}", menuElement.querySelector('.b3-menu__item[data-type="goSearchAV"] .b3-menu__accelerator').textContent) : window.siyuan.languages.removeCol.replace("${x}", menuElement.querySelector("input").value)}
|
|
|
|
|
<div class="fn__hr--b"></div>
|
2024-10-28 18:56:20 +08:00
|
|
|
<button class="fn__block b3-button b3-button--remove" data-action="delete">${window.siyuan.languages.delete}</button>
|
2024-10-17 18:42:17 +08:00
|
|
|
<div class="fn__hr"></div>
|
2024-10-28 18:56:20 +08:00
|
|
|
<button class="fn__block b3-button b3-button--remove${isTwoWay ? "" : " fn__none"}" data-action="keep-relation">${window.siyuan.languages.removeButKeepRelationField}</button>
|
2024-10-17 18:42:17 +08:00
|
|
|
<div class="fn__hr"></div>
|
2024-10-28 18:56:20 +08:00
|
|
|
<button class="fn__block b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button>
|
2024-10-17 18:01:11 +08:00
|
|
|
</div>`,
|
|
|
|
|
});
|
2024-12-20 18:57:49 +08:00
|
|
|
dialog.element.addEventListener("click", (dialogEvent) => {
|
|
|
|
|
let target = dialogEvent.target as HTMLElement;
|
|
|
|
|
const isDispatch = typeof dialogEvent.detail === "string";
|
|
|
|
|
while (target && !target.isSameNode(dialog.element) || isDispatch) {
|
2024-10-28 18:56:20 +08:00
|
|
|
const action = target.getAttribute("data-action");
|
2024-12-20 18:57:49 +08:00
|
|
|
if (action === "delete" || (isDispatch && dialogEvent.detail === "Enter")) {
|
2024-10-17 18:42:17 +08:00
|
|
|
removeCol({
|
|
|
|
|
protyle: options.protyle,
|
|
|
|
|
data,
|
|
|
|
|
avID,
|
|
|
|
|
blockID,
|
|
|
|
|
menuElement,
|
|
|
|
|
isCustomAttr,
|
|
|
|
|
blockElement: options.blockElement,
|
|
|
|
|
avPanelElement,
|
|
|
|
|
tabRect,
|
|
|
|
|
isTwoWay: true
|
|
|
|
|
});
|
|
|
|
|
dialog.destroy();
|
|
|
|
|
break;
|
2024-10-28 18:56:20 +08:00
|
|
|
} else if (action === "keep-relation") {
|
2024-10-17 18:42:17 +08:00
|
|
|
removeCol({
|
|
|
|
|
protyle: options.protyle,
|
|
|
|
|
data,
|
|
|
|
|
avID,
|
|
|
|
|
blockID,
|
|
|
|
|
menuElement,
|
|
|
|
|
isCustomAttr,
|
|
|
|
|
blockElement: options.blockElement,
|
|
|
|
|
avPanelElement,
|
|
|
|
|
tabRect,
|
|
|
|
|
isTwoWay: false
|
|
|
|
|
});
|
|
|
|
|
dialog.destroy();
|
|
|
|
|
break;
|
2024-12-20 18:57:49 +08:00
|
|
|
} else if (target.classList.contains("b3-button--cancel") || (isDispatch && dialogEvent.detail === "Escape")) {
|
2024-10-17 18:42:17 +08:00
|
|
|
dialog.destroy();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
target = target.parentElement;
|
|
|
|
|
}
|
2024-10-17 22:14:12 +08:00
|
|
|
});
|
2024-12-20 18:57:49 +08:00
|
|
|
dialog.element.setAttribute("data-key", Constants.DIALOG_CONFIRM);
|
2024-10-17 18:01:11 +08:00
|
|
|
} else {
|
|
|
|
|
removeCol({
|
|
|
|
|
protyle: options.protyle,
|
|
|
|
|
data,
|
|
|
|
|
avID,
|
|
|
|
|
blockID,
|
|
|
|
|
menuElement,
|
|
|
|
|
isCustomAttr,
|
|
|
|
|
blockElement: options.blockElement,
|
|
|
|
|
avPanelElement,
|
2024-10-17 18:42:17 +08:00
|
|
|
tabRect,
|
|
|
|
|
isTwoWay: false
|
2024-10-17 18:01:11 +08:00
|
|
|
});
|
|
|
|
|
}
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-18 01:38:59 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-07-18 01:03:35 +08:00
|
|
|
} else if (type === "setColOption") {
|
2024-01-21 12:21:31 +08:00
|
|
|
setColOption(options.protyle, data, target, options.blockElement, isCustomAttr, options.cellElements);
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-09 23:54:32 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-12-24 16:54:15 +08:00
|
|
|
} else if (type === "setRelationCell") {
|
2025-03-14 20:19:26 +08:00
|
|
|
menuElement.querySelector(".b3-menu__item--current")?.classList.remove("b3-menu__item--current");
|
|
|
|
|
target.classList.add("b3-menu__item--current");
|
2023-12-25 00:20:51 +08:00
|
|
|
setRelationCell(options.protyle, options.blockElement as HTMLElement, target, options.cellElements);
|
2023-12-24 16:54:15 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-07-18 01:03:35 +08:00
|
|
|
} else if (type === "addColOptionOrCell") {
|
2025-03-14 19:16:26 +08:00
|
|
|
menuElement.querySelector(".b3-menu__item--current")?.classList.remove("b3-menu__item--current");
|
|
|
|
|
target.classList.add("b3-menu__item--current");
|
2024-03-31 20:18:34 +08:00
|
|
|
if (target.querySelector(".b3-menu__checked")) {
|
2024-05-17 00:42:20 +08:00
|
|
|
removeCellOption(options.protyle, options.cellElements, menuElement.querySelector(`.b3-chips .b3-chip[data-content="${escapeAttr(target.dataset.name)}"]`), options.blockElement);
|
2024-03-31 20:18:34 +08:00
|
|
|
} else {
|
|
|
|
|
addColOptionOrCell(options.protyle, data, options.cellElements, target, menuElement, options.blockElement);
|
|
|
|
|
}
|
2023-07-10 19:02:59 +08:00
|
|
|
window.siyuan.menus.menu.remove();
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-10 10:29:26 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-07-18 01:03:35 +08:00
|
|
|
} else if (type === "removeCellOption") {
|
2024-05-17 00:42:20 +08:00
|
|
|
removeCellOption(options.protyle, options.cellElements, target.parentElement, options.blockElement);
|
2023-07-22 10:18:11 +08:00
|
|
|
event.preventDefault();
|
2023-07-10 00:17:54 +08:00
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-09-22 12:11:56 +08:00
|
|
|
} else if (type === "addAssetLink") {
|
2024-05-15 11:17:34 +08:00
|
|
|
addAssetLink(options.protyle, options.cellElements, target, options.blockElement);
|
2023-09-22 12:11:56 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-10-01 10:26:31 +08:00
|
|
|
} else if (type === "addAssetExist") {
|
2023-10-01 10:27:07 +08:00
|
|
|
const rect = target.getBoundingClientRect();
|
2023-11-02 11:20:02 +08:00
|
|
|
assetMenu(options.protyle, {
|
2023-10-05 12:03:38 +08:00
|
|
|
x: rect.right,
|
|
|
|
|
y: rect.bottom,
|
|
|
|
|
w: target.parentElement.clientWidth + 8,
|
|
|
|
|
h: rect.height
|
2024-01-23 10:06:51 +08:00
|
|
|
}, (url, name) => {
|
2023-10-01 10:26:31 +08:00
|
|
|
let value: IAVCellAssetValue;
|
|
|
|
|
if (Constants.SIYUAN_ASSETS_IMAGE.includes(pathPosix().extname(url).toLowerCase())) {
|
|
|
|
|
value = {
|
|
|
|
|
type: "image",
|
|
|
|
|
content: url,
|
|
|
|
|
name: ""
|
2023-10-01 10:27:07 +08:00
|
|
|
};
|
2023-10-01 10:26:31 +08:00
|
|
|
} else {
|
|
|
|
|
value = {
|
|
|
|
|
type: "file",
|
|
|
|
|
content: url,
|
2024-01-23 10:06:51 +08:00
|
|
|
name
|
2023-10-01 10:27:07 +08:00
|
|
|
};
|
2023-10-01 10:26:31 +08:00
|
|
|
}
|
|
|
|
|
updateAssetCell({
|
|
|
|
|
protyle: options.protyle,
|
|
|
|
|
cellElements: options.cellElements,
|
2024-04-12 10:18:45 +08:00
|
|
|
addValue: [value],
|
2023-12-29 14:30:46 +08:00
|
|
|
blockElement: options.blockElement
|
2023-10-01 10:26:31 +08:00
|
|
|
});
|
2023-11-02 11:20:02 +08:00
|
|
|
window.siyuan.menus.menu.remove();
|
2023-10-01 10:26:31 +08:00
|
|
|
});
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-10-11 17:28:40 +08:00
|
|
|
} else if (type === "openAssetItem") {
|
|
|
|
|
const assetLink = target.parentElement.dataset.content;
|
2023-10-12 20:23:18 +08:00
|
|
|
const suffix = pathPosix().extname(assetLink);
|
2023-10-15 18:28:09 +08:00
|
|
|
/// #if !MOBILE
|
|
|
|
|
if (isLocalPath(assetLink) && (
|
2023-10-11 17:28:40 +08:00
|
|
|
[".pdf"].concat(Constants.SIYUAN_ASSETS_AUDIO).concat(Constants.SIYUAN_ASSETS_VIDEO).includes(suffix) && (
|
2023-10-26 17:28:22 +08:00
|
|
|
suffix !== ".pdf" || (suffix === ".pdf" && !assetLink.startsWith("file://"))
|
2023-10-11 17:28:40 +08:00
|
|
|
)
|
|
|
|
|
)) {
|
|
|
|
|
openAsset(options.protyle.app, assetLink.trim(), parseInt(getSearch("page", assetLink)), "right");
|
|
|
|
|
} else if (Constants.SIYUAN_ASSETS_IMAGE.includes(suffix)) {
|
|
|
|
|
previewImage(assetLink);
|
|
|
|
|
} else {
|
|
|
|
|
window.open(assetLink);
|
|
|
|
|
}
|
2023-10-15 18:28:09 +08:00
|
|
|
/// #else
|
|
|
|
|
if (Constants.SIYUAN_ASSETS_IMAGE.includes(suffix)) {
|
|
|
|
|
previewImage(assetLink);
|
|
|
|
|
} else {
|
|
|
|
|
window.open(assetLink);
|
|
|
|
|
}
|
|
|
|
|
/// #endif
|
2023-10-11 17:28:40 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-09-22 20:24:00 +08:00
|
|
|
} else if (type === "editAssetItem") {
|
2024-05-15 12:14:26 +08:00
|
|
|
editAssetItem({
|
|
|
|
|
protyle: options.protyle,
|
|
|
|
|
cellElements: options.cellElements,
|
|
|
|
|
blockElement: options.blockElement,
|
|
|
|
|
content: target.parentElement.dataset.content,
|
|
|
|
|
type: target.parentElement.dataset.type as "image" | "file",
|
|
|
|
|
name: target.parentElement.dataset.name,
|
|
|
|
|
index: parseInt(target.parentElement.dataset.index),
|
|
|
|
|
rect: target.parentElement.getBoundingClientRect()
|
|
|
|
|
});
|
2023-09-22 20:24:00 +08:00
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-07-22 15:49:18 +08:00
|
|
|
} else if (type === "clearDate") {
|
2023-12-29 14:56:00 +08:00
|
|
|
updateCellsValue(options.protyle, options.blockElement as HTMLElement, {
|
|
|
|
|
isNotEmpty2: false,
|
|
|
|
|
isNotEmpty: false,
|
|
|
|
|
content: null,
|
|
|
|
|
content2: null,
|
|
|
|
|
hasEndDate: false,
|
|
|
|
|
isNotTime: true,
|
|
|
|
|
}, options.cellElements);
|
2023-07-22 15:49:18 +08:00
|
|
|
avPanelElement.remove();
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-12-01 16:59:04 +08:00
|
|
|
} else if (type === "av-add") {
|
2023-12-01 21:11:54 +08:00
|
|
|
window.siyuan.menus.menu.remove();
|
2023-12-01 16:59:04 +08:00
|
|
|
addView(options.protyle, options.blockElement);
|
|
|
|
|
avPanelElement.remove();
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2024-02-27 16:14:02 +08:00
|
|
|
} else if (type === "av-view-switch") {
|
2024-12-25 19:15:33 +08:00
|
|
|
if (!target.parentElement.classList.contains("b3-menu__item--current")) {
|
2024-12-26 09:18:14 +08:00
|
|
|
avPanelElement.querySelector(".b3-menu__item--current")?.classList.remove("b3-menu__item--current");
|
2024-12-30 10:17:32 +08:00
|
|
|
target.parentElement.classList.add("b3-menu__item--current");
|
2024-02-27 16:14:02 +08:00
|
|
|
options.blockElement.removeAttribute("data-render");
|
|
|
|
|
avRender(options.blockElement, options.protyle, undefined, target.parentElement.dataset.id);
|
|
|
|
|
}
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-12-01 16:59:04 +08:00
|
|
|
} else if (type === "av-view-edit") {
|
2024-12-25 19:15:33 +08:00
|
|
|
if (target.parentElement.classList.contains("b3-menu__item--current")) {
|
2023-12-01 16:59:04 +08:00
|
|
|
openViewMenu({
|
|
|
|
|
protyle: options.protyle,
|
|
|
|
|
blockElement: options.blockElement as HTMLElement,
|
|
|
|
|
element: target.parentElement
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2024-12-26 09:18:14 +08:00
|
|
|
avPanelElement.querySelector(".b3-menu__item--current")?.classList.remove("b3-menu__item--current");
|
2024-12-30 10:17:32 +08:00
|
|
|
target.parentElement.classList.add("b3-menu__item--current");
|
2023-12-01 16:59:04 +08:00
|
|
|
options.blockElement.removeAttribute("data-render");
|
|
|
|
|
avRender(options.blockElement, options.protyle, () => {
|
|
|
|
|
openViewMenu({
|
|
|
|
|
protyle: options.protyle,
|
|
|
|
|
blockElement: options.blockElement as HTMLElement,
|
|
|
|
|
element: target.parentElement
|
|
|
|
|
});
|
2023-12-02 20:42:18 +08:00
|
|
|
avPanelElement.querySelector(".b3-chip--primary").classList.remove("b3-chip--primary");
|
|
|
|
|
target.parentElement.querySelector(".b3-chip").classList.add("b3-chip--primary");
|
2023-12-01 16:59:04 +08:00
|
|
|
}, target.parentElement.dataset.id);
|
|
|
|
|
}
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
break;
|
2023-07-02 20:52:16 +08:00
|
|
|
}
|
2024-05-06 11:26:28 +08:00
|
|
|
// 有错误日志,没找到重现步骤,需先判断一下
|
|
|
|
|
if (!target || !target.parentElement) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-07-02 20:52:16 +08:00
|
|
|
target = target.parentElement;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2023-07-02 23:59:01 +08:00
|
|
|
};
|
2023-07-02 21:53:02 +08:00
|
|
|
|
2024-04-07 18:49:56 +08:00
|
|
|
export const getPropertiesHTML = (data: IAVTable) => {
|
2023-07-02 21:53:02 +08:00
|
|
|
let showHTML = "";
|
|
|
|
|
let hideHTML = "";
|
|
|
|
|
data.columns.forEach((item: IAVColumn) => {
|
|
|
|
|
if (item.hidden) {
|
2024-04-07 10:16:11 +08:00
|
|
|
hideHTML += `<button class="b3-menu__item" data-type="editCol" draggable="true" data-id="${item.id}">
|
2024-01-20 00:13:38 +08:00
|
|
|
<svg class="b3-menu__icon fn__grab"><use xlink:href="#iconDrag"></use></svg>
|
2024-02-27 16:59:25 +08:00
|
|
|
<div class="b3-menu__label fn__flex">
|
|
|
|
|
${item.icon ? unicode2Emoji(item.icon, "b3-menu__icon", true) : `<svg class="b3-menu__icon"><use xlink:href="#${getColIconByType(item.type)}"></use></svg>`}
|
2024-11-18 23:43:13 +08:00
|
|
|
${escapeHtml(item.name) || " "}
|
2023-07-07 16:05:05 +08:00
|
|
|
</div>
|
2024-03-01 22:22:37 +08:00
|
|
|
<svg class="b3-menu__action" data-type="showCol"><use xlink:href="#iconEye"></use></svg>
|
2024-04-07 10:16:11 +08:00
|
|
|
<svg class="b3-menu__icon b3-menu__icon--small"><use xlink:href="#iconRight"></use></svg>
|
2023-07-02 23:59:01 +08:00
|
|
|
</button>`;
|
2023-07-02 21:53:02 +08:00
|
|
|
} else {
|
2024-04-07 10:16:11 +08:00
|
|
|
showHTML += `<button class="b3-menu__item" data-type="editCol" draggable="true" data-id="${item.id}">
|
2024-01-20 00:13:38 +08:00
|
|
|
<svg class="b3-menu__icon fn__grab"><use xlink:href="#iconDrag"></use></svg>
|
2024-02-27 16:59:25 +08:00
|
|
|
<div class="b3-menu__label fn__flex">
|
|
|
|
|
${item.icon ? unicode2Emoji(item.icon, "b3-menu__icon", true) : `<svg class="b3-menu__icon"><use xlink:href="#${getColIconByType(item.type)}"></use></svg>`}
|
2024-11-18 23:43:13 +08:00
|
|
|
${escapeHtml(item.name) || " "}
|
2023-07-07 16:05:05 +08:00
|
|
|
</div>
|
2024-03-01 22:22:37 +08:00
|
|
|
<svg class="b3-menu__action${item.type === "block" ? " fn__none" : ""}" data-type="hideCol"><use xlink:href="#iconEyeoff"></use></svg>
|
2024-04-07 10:16:11 +08:00
|
|
|
<svg class="b3-menu__icon b3-menu__icon--small"><use xlink:href="#iconRight"></use></svg>
|
2023-07-02 23:59:01 +08:00
|
|
|
</button>`;
|
2023-07-02 21:53:02 +08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (hideHTML) {
|
|
|
|
|
hideHTML = `<button class="b3-menu__separator"></button>
|
2023-07-02 22:18:21 +08:00
|
|
|
<button class="b3-menu__item" data-type="nobg">
|
|
|
|
|
<span class="b3-menu__label">
|
|
|
|
|
${window.siyuan.languages.hideCol}
|
|
|
|
|
</span>
|
|
|
|
|
<span class="block__icon" data-type="showAllCol">
|
|
|
|
|
${window.siyuan.languages.showAll}
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
<svg><use xlink:href="#iconEye"></use></svg>
|
|
|
|
|
</span>
|
2023-07-02 21:53:02 +08:00
|
|
|
</button>
|
|
|
|
|
${hideHTML}`;
|
|
|
|
|
}
|
2023-07-27 13:38:14 +08:00
|
|
|
return `<div class="b3-menu__items">
|
|
|
|
|
<button class="b3-menu__item" data-type="nobg">
|
2023-12-08 12:37:26 +08:00
|
|
|
<span class="block__icon" style="padding: 8px;margin-left: -4px;" data-type="go-config">
|
2023-07-03 12:49:35 +08:00
|
|
|
<svg><use xlink:href="#iconLeft"></use></svg>
|
|
|
|
|
</span>
|
2024-11-15 00:00:37 +08:00
|
|
|
<span class="b3-menu__label ft__center">${window.siyuan.languages.fields}</span>
|
2023-07-03 12:49:35 +08:00
|
|
|
</button>
|
|
|
|
|
<button class="b3-menu__separator"></button>
|
|
|
|
|
<button class="b3-menu__item" data-type="nobg">
|
|
|
|
|
<span class="b3-menu__label">
|
|
|
|
|
${window.siyuan.languages.showCol}
|
|
|
|
|
</span>
|
|
|
|
|
<span class="block__icon" data-type="hideAllCol">
|
|
|
|
|
${window.siyuan.languages.hideAll}
|
|
|
|
|
<span class="fn__space"></span>
|
|
|
|
|
<svg><use xlink:href="#iconEyeoff"></use></svg>
|
|
|
|
|
</span>
|
|
|
|
|
</button>
|
|
|
|
|
${showHTML}
|
|
|
|
|
${hideHTML}
|
|
|
|
|
<button class="b3-menu__separator"></button>
|
|
|
|
|
<button class="b3-menu__item" data-type="newCol">
|
|
|
|
|
<svg class="b3-menu__icon"><use xlink:href="#iconAdd"></use></svg>
|
|
|
|
|
<span class="b3-menu__label">${window.siyuan.languages.new}</span>
|
2023-07-27 13:38:14 +08:00
|
|
|
</button>
|
|
|
|
|
</div>`;
|
2023-07-02 23:59:01 +08:00
|
|
|
};
|
2023-07-03 16:03:52 +08:00
|
|
|
|