mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-27 01:14:07 +01:00
🎨 Improve #commonMenu menu (#16141)
* 改进菜单的 data-name 属性值和选项的 data-id 属性值 fix https://github.com/siyuan-note/siyuan/issues/12506 https://github.com/siyuan-note/siyuan/issues/16133 * 改进菜单的 data-name 属性值和选项的 data-id 属性值 fix https://github.com/siyuan-note/siyuan/issues/12506 https://github.com/siyuan-note/siyuan/issues/16133 * 更新数据库排序菜单文案 * 改进菜单的 data-name 属性值和选项的 data-id 属性值 fix https://github.com/siyuan-note/siyuan/issues/12506 https://github.com/siyuan-note/siyuan/issues/16133 使用正则 (?:get|set)Attribute\("data-name"|new Menu\((?:"|Constants) 来搜索 * 改进菜单的 data-name 属性值和选项的 data-subname 属性值 fix https://github.com/siyuan-note/siyuan/issues/12506 https://github.com/siyuan-note/siyuan/issues/15075 * 改进菜单的 data-name 属性值和选项的 data-subname 属性值 fix https://github.com/siyuan-note/siyuan/issues/12506 https://github.com/siyuan-note/siyuan/issues/15075
This commit is contained in:
parent
3e7177d22f
commit
8725e5daa8
52 changed files with 209 additions and 75 deletions
|
|
@ -606,7 +606,7 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
|
|||
menu.addSeparator({id: "separator_1"});
|
||||
}
|
||||
menu.addItem({
|
||||
id: "insertRowBefore",
|
||||
id: avType === "table" ? "insertRowBefore" : "insertItemBefore",
|
||||
icon: "iconBefore",
|
||||
label: `<div class="fn__flex" style="align-items: center;">
|
||||
${window.siyuan.languages[avType === "table" ? "insertRowBefore" : "insertItemBefore"].replace("${x}", `<span class="fn__space"></span><input style="width:64px" type="number" step="1" min="1" value="1" placeholder="${window.siyuan.languages.enterKey}" class="b3-text-field"><span class="fn__space"></span>`)}
|
||||
|
|
@ -641,7 +641,7 @@ ${window.siyuan.languages[avType === "table" ? "insertRowBefore" : "insertItemBe
|
|||
}
|
||||
});
|
||||
menu.addItem({
|
||||
id: "insertRowAfter",
|
||||
id: avType === "table" ? "insertRowAfter" : "insertItemAfter",
|
||||
icon: "iconAfter",
|
||||
label: `<div class="fn__flex" style="align-items: center;">
|
||||
${window.siyuan.languages[avType === "table" ? "insertRowAfter" : "insertItemAfter"].replace("${x}", `<span class="fn__space"></span><input style="width:64px" type="number" step="1" min="1" placeholder="${window.siyuan.languages.enterKey}" class="b3-text-field" value="1"><span class="fn__space"></span>`)}
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ export const editAssetItem = (options: {
|
|||
}) => {
|
||||
const linkAddress = removeCompressURL(options.content);
|
||||
const type = options.type as "image" | "file";
|
||||
const menu = new Menu("av-asset-edit", () => {
|
||||
const menu = new Menu(Constants.MENU_AV_ASSET_EDIT, () => {
|
||||
if ((!textElements[1] && textElements[0].value === linkAddress) ||
|
||||
(textElements[1] && textElements[0].value === linkAddress && textElements[1].value === options.name)) {
|
||||
return;
|
||||
|
|
@ -382,7 +382,7 @@ export const editAssetItem = (options: {
|
|||
};
|
||||
|
||||
export const addAssetLink = (protyle: IProtyle, cellElements: HTMLElement[], target: HTMLElement, blockElement: Element) => {
|
||||
const menu = new Menu("av-asset-link", () => {
|
||||
const menu = new Menu(Constants.MENU_AV_ASSET_EDIT, () => {
|
||||
const textElements = menu.element.querySelectorAll("textarea");
|
||||
if (!textElements[0].value && !textElements[1].value) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import {transaction} from "../../wysiwyg/transaction";
|
|||
import {hasClosestBlock, hasClosestByClassName} from "../../util/hasClosest";
|
||||
import {fetchSyncPost} from "../../../util/fetch";
|
||||
import {getFieldsByData} from "./view";
|
||||
import {Constants} from "../../../constants";
|
||||
|
||||
const calcItem = (options: {
|
||||
menu: Menu,
|
||||
|
|
@ -112,7 +113,7 @@ export const openCalcMenu = async (protyle: IProtyle, calcElement: HTMLElement,
|
|||
if (type === "lineNumber") {
|
||||
return;
|
||||
}
|
||||
const menu = new Menu("av-calc", () => {
|
||||
const menu = new Menu(Constants.MENU_AV_CALC, () => {
|
||||
if (rowElement) {
|
||||
rowElement.classList.remove("av__row--show");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -666,7 +666,7 @@ export const showColMenu = (protyle: IProtyle, blockElement: Element, cellElemen
|
|||
const blockID = blockElement.getAttribute("data-node-id");
|
||||
const oldValue = cellElement.querySelector(".av__celltext").textContent.trim();
|
||||
const oldDesc = cellElement.dataset.desc;
|
||||
const menu = new Menu("av-header-cell", () => {
|
||||
const menu = new Menu(Constants.MENU_AV_HEADER_CELL, () => {
|
||||
const newValue = (menu.element.querySelector(".b3-text-field") as HTMLInputElement).value;
|
||||
if (newValue !== oldValue) {
|
||||
transaction(protyle, [{
|
||||
|
|
@ -1235,7 +1235,7 @@ const genUpdateColItem = (type: TAVCol, oldType: TAVCol) => {
|
|||
};
|
||||
|
||||
export const addCol = (protyle: IProtyle, blockElement: Element, previousID?: string) => {
|
||||
const menu = new Menu("av-header-add");
|
||||
const menu = new Menu(Constants.MENU_AV_HEADER_ADD);
|
||||
const avID = blockElement.getAttribute("data-av-id");
|
||||
if (typeof previousID === "undefined" && blockElement.getAttribute("data-av-type") === "table") {
|
||||
previousID = Array.from(blockElement.querySelectorAll(".av__row--header .av__cell")).pop().getAttribute("data-col-id");
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import {fetchPost, fetchSyncPost} from "../../../util/fetch";
|
|||
import {showMessage} from "../../../dialog/message";
|
||||
import {upDownHint} from "../../../util/upDownHint";
|
||||
import {getFieldsByData} from "./view";
|
||||
import {Constants} from "../../../constants";
|
||||
|
||||
export const getDefaultOperatorByType = (type: TAVCol) => {
|
||||
if (["select", "number", "date", "created", "updated"].includes(type)) {
|
||||
|
|
@ -676,7 +677,7 @@ export const addFilter = (options: {
|
|||
protyle: IProtyle
|
||||
blockElement: Element
|
||||
}) => {
|
||||
const menu = new Menu("av-add-filter");
|
||||
const menu = new Menu(Constants.MENU_AV_ADD_FILTER);
|
||||
getFieldsByData(options.data).forEach((column) => {
|
||||
let filter: IAVFilter;
|
||||
options.data.view.filters.find((item) => {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import {getFieldsByData} from "./view";
|
|||
import {fetchSyncPost} from "../../../util/fetch";
|
||||
import {Menu} from "../../../plugin/Menu";
|
||||
import {objEquals} from "../../../util/functions";
|
||||
import {Constants} from "../../../constants";
|
||||
|
||||
export const getPageSize = (blockElement: Element) => {
|
||||
const groupPageSize: {
|
||||
|
|
@ -304,7 +305,7 @@ export const goGroupsDate = (options: {
|
|||
data: IAV;
|
||||
blockElement: Element;
|
||||
}) => {
|
||||
const menu = new Menu("avGroupDate");
|
||||
const menu = new Menu(Constants.MENU_AV_GROUP_DATE);
|
||||
if (menu.isOpen) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -351,7 +352,7 @@ export const goGroupsSort = (options: {
|
|||
menuElement: HTMLElement;
|
||||
blockElement: Element;
|
||||
}) => {
|
||||
const menu = new Menu("avGroupSort");
|
||||
const menu = new Menu(Constants.MENU_AV_GROUP_SORT);
|
||||
if (menu.isOpen) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {Menu} from "../../../plugin/Menu";
|
||||
import {transaction} from "../../wysiwyg/transaction";
|
||||
import {Constants} from "../../../constants";
|
||||
|
||||
const addFormatItem = (options: {
|
||||
menu: Menu,
|
||||
|
|
@ -40,7 +41,7 @@ export const formatNumber = (options: {
|
|||
avID: string,
|
||||
oldFormat: string
|
||||
}) => {
|
||||
const menu = new Menu("av-col-format-number");
|
||||
const menu = new Menu(Constants.MENU_AV_COL_FORMAT_NUMBER);
|
||||
addFormatItem({
|
||||
menu,
|
||||
protyle: options.protyle,
|
||||
|
|
|
|||
|
|
@ -263,7 +263,7 @@ export const setPageSize = (options: {
|
|||
avID: string,
|
||||
nodeElement: Element
|
||||
}) => {
|
||||
const menu = new Menu("av-page-size");
|
||||
const menu = new Menu(Constants.MENU_AV_PAGE_SIZE);
|
||||
if (menu.isOpen) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import {genCellValueByElement, getTypeByCellElement} from "./cell";
|
|||
import * as dayjs from "dayjs";
|
||||
import {getFieldsByData} from "./view";
|
||||
import {getFieldIdByCellElement} from "./row";
|
||||
import {Constants} from "../../../constants";
|
||||
|
||||
let cellValues: IAVCellValue[];
|
||||
|
||||
|
|
@ -152,7 +153,7 @@ export const setColOption = (protyle: IProtyle, data: IAV, target: HTMLElement,
|
|||
let desc = target.parentElement.dataset.desc;
|
||||
let color = target.parentElement.dataset.color;
|
||||
const fields = getFieldsByData(data);
|
||||
const menu = new Menu("av-col-option", () => {
|
||||
const menu = new Menu(Constants.MENU_AV_COL_OPTION, () => {
|
||||
if ((name === inputElement.value && desc === descElement.value) || !inputElement.value) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import {transaction} from "../../wysiwyg/transaction";
|
|||
import {setPosition} from "../../../util/setPosition";
|
||||
import {unicode2Emoji} from "../../../emoji";
|
||||
import {getFieldsByData} from "./view";
|
||||
import {Constants} from "../../../constants";
|
||||
|
||||
export const addSort = (options: {
|
||||
data: IAV,
|
||||
|
|
@ -14,7 +15,7 @@ export const addSort = (options: {
|
|||
protyle: IProtyle,
|
||||
blockID: string,
|
||||
}) => {
|
||||
const menu = new Menu("av-add-sort");
|
||||
const menu = new Menu(Constants.MENU_AV_ADD_SORT);
|
||||
const fields = getFieldsByData(options.data);
|
||||
fields.forEach((column) => {
|
||||
let hasSort = false;
|
||||
|
|
@ -131,11 +132,11 @@ export const getSortsHTML = (columns: IAVColumn[], sorts: IAVSort[]) => {
|
|||
${html}
|
||||
<button class="b3-menu__item${sorts.length === columns.length ? " fn__none" : ""}" data-type="addSort">
|
||||
<svg class="b3-menu__icon"><use xlink:href="#iconAdd"></use></svg>
|
||||
<span class="b3-menu__label">${window.siyuan.languages.new}</span>
|
||||
<span class="b3-menu__label">${window.siyuan.languages.addSort}</span>
|
||||
</button>
|
||||
<button class="b3-menu__item b3-menu__item--warning${html ? "" : " fn__none"}" data-type="removeSorts">
|
||||
<svg class="b3-menu__icon"><use xlink:href="#iconTrashcan"></use></svg>
|
||||
<span class="b3-menu__label">${window.siyuan.languages.delete}</span>
|
||||
<span class="b3-menu__label">${window.siyuan.languages.removeSorts}</span>
|
||||
</button>
|
||||
</div>`;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ export const openViewMenu = (options: { protyle: IProtyle, blockElement: HTMLEle
|
|||
if (options.protyle.disabled) {
|
||||
return;
|
||||
}
|
||||
const menu = new Menu("av-view");
|
||||
const menu = new Menu(Constants.MENU_AV_VIEW);
|
||||
if (menu.isOpen) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue