mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-03 23:38:49 +01:00
This commit is contained in:
parent
b5d9968237
commit
d9d3db1920
4 changed files with 62 additions and 43 deletions
45
app/src/protyle/render/av/action.ts
Normal file
45
app/src/protyle/render/av/action.ts
Normal file
|
|
@ -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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue