diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.ts new file mode 100644 index 000000000..8ea97fbb6 --- /dev/null +++ b/app/src/protyle/render/av/action.ts @@ -0,0 +1,45 @@ +import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "../../util/hasClosest"; +import {transaction} from "../../wysiwyg/transaction"; +import {Menu} from "../../../plugin/API"; + +export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLElement }) => { + const blockElement = hasClosestBlock(event.target) + const addElement = hasClosestByAttribute(event.target, "data-type", "av-header-add") + if (addElement && blockElement) { + const menu = new Menu("av-header-add") + menu.addItem({ + icon: "iconAlignLeft", + label: window.siyuan.languages.text, + click() { + const id = Lute.NewNodeID() + transaction(protyle, [{ + action: "addAttrViewCol", + name: "Text", + parentID: blockElement.getAttribute("data-av-id"), + type: "text", + id + }], [{ + action: "removeAttrViewCol", + id, + parentID: blockElement.getAttribute("data-av-type"), + }]); + + } + }) + const addRect = addElement.getBoundingClientRect() + menu.open({ + x: addRect.left, + y: addRect.bottom + }) + event.preventDefault(); + event.stopPropagation(); + return true + } + const cellElement = hasClosestByClassName(event.target, "av__cell") + if (cellElement && blockElement) { + event.preventDefault(); + event.stopPropagation(); + return true + } + return false +} diff --git a/app/src/protyle/render/av/index.ts b/app/src/protyle/render/av/index.ts index fecd329f1..22bb6822d 100644 --- a/app/src/protyle/render/av/index.ts +++ b/app/src/protyle/render/av/index.ts @@ -16,62 +16,27 @@ export const avRender = (element: Element) => { if (e.getAttribute("data-render") === "true") { return; } - // const data = { - // title: "table", - // filter: {}, - // sorts: {}, - // columns: [{ - // width: 500, - // icon: "", - // id: "", - // name: "columnA", - // wrap: false, - // type: "", - // }, { - // width: 500, - // icon: "", - // id: "", - // name: "columnB", - // wrap: false, - // type: "", - // }], - // rows: [{ - // id: "", - // cells: [{ - // value: "a", - // }, { - // color: "var(--b3-card-error-color)", - // bgColor: "var(--b3-card-error-background)", - // value: "a1", - // }] - // }, { - // id: "", - // cells: [{ - // color: "var(--b3-card-success-color)", - // bgColor: "var(--b3-card-success-background)", - // value: "b", - // }, { - // value: "b1", - // }] - // }] - // }; fetchPost("/api/av/renderAttributeView", {id: e.getAttribute("data-av-id")}, (response) => { const data = response.data.av; + + // header let tableHTML = '