mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 17:10:12 +01:00
This commit is contained in:
parent
eb6af31572
commit
63e9e709e5
2 changed files with 179 additions and 207 deletions
|
|
@ -24,6 +24,7 @@ import {unicode2Emoji} from "../../../emoji";
|
|||
import {selectRow} from "./row";
|
||||
import * as dayjs from "dayjs";
|
||||
import {openCalcMenu} from "./calc";
|
||||
import {avRender} from "./render";
|
||||
|
||||
export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLElement }) => {
|
||||
const blockElement = hasClosestBlock(event.target);
|
||||
|
|
@ -51,14 +52,17 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
|
|||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (protyle.disabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const addElement = hasClosestByAttribute(event.target, "data-type", "av-header-add");
|
||||
if (addElement) {
|
||||
let target = event.target
|
||||
while (target && !target.isEqualNode(blockElement)) {
|
||||
const type = target.getAttribute("data-type")
|
||||
if (type === "av-header-add") {
|
||||
const addMenu = addCol(protyle, blockElement);
|
||||
const addRect = addElement.getBoundingClientRect();
|
||||
const addRect = target.getBoundingClientRect();
|
||||
addMenu.open({
|
||||
x: addRect.left,
|
||||
y: addRect.bottom,
|
||||
|
|
@ -67,15 +71,55 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
|
|||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
|
||||
const gutterElement = hasClosestByClassName(event.target, "av__gutter");
|
||||
if (gutterElement) {
|
||||
const rowElement = hasClosestByClassName(gutterElement, "av__row");
|
||||
} else if (type === "av-header-more") {
|
||||
openMenuPanel({protyle, blockElement, type: "properties"});
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
} else if (type === "av-more") {
|
||||
openMenuPanel({protyle, blockElement, type: "config"});
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
} else if (type === "av-sort") {
|
||||
openMenuPanel({protyle, blockElement, type: "sorts"});
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
} else if (type === "av-filter") {
|
||||
openMenuPanel({protyle, blockElement, type: "filters"});
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
} else if (type === "av-add") {
|
||||
const id = Lute.NewNodeID();
|
||||
const avID = blockElement.getAttribute("data-av-id");
|
||||
transaction(protyle, [{
|
||||
action: "addAttrViewView",
|
||||
avID,
|
||||
id
|
||||
}], [{
|
||||
action: "removeAttrViewView",
|
||||
avID,
|
||||
id
|
||||
}]);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
} else if (type === "block-more") {
|
||||
protyle.toolbar.range = document.createRange();
|
||||
protyle.toolbar.range.selectNodeContents(target);
|
||||
focusByRange(protyle.toolbar.range);
|
||||
hintRef(target.previousElementSibling.textContent.trim(), protyle, "av");
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
} else if (target.classList.contains("av__gutter")) {
|
||||
const rowElement = hasClosestByClassName(target, "av__row");
|
||||
if (!rowElement) {
|
||||
return;
|
||||
}
|
||||
if (gutterElement.dataset.action === "add") {
|
||||
if (target.dataset.action === "add") {
|
||||
const avID = blockElement.getAttribute("data-av-id");
|
||||
const srcIDs = [Lute.NewNodeID()];
|
||||
const previousID = event.altKey ? (rowElement.previousElementSibling.getAttribute("data-id") || "") : rowElement.getAttribute("data-id");
|
||||
|
|
@ -92,7 +136,7 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
|
|||
}]);
|
||||
insertAttrViewBlockAnimation(blockElement, 1, previousID, avID);
|
||||
} else {
|
||||
const gutterRect = gutterElement.getBoundingClientRect();
|
||||
const gutterRect = target.getBoundingClientRect();
|
||||
avContextmenu(protyle, rowElement, {
|
||||
x: gutterRect.left,
|
||||
y: gutterRect.bottom,
|
||||
|
|
@ -103,76 +147,20 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
|
|||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
|
||||
const checkElement = hasClosestByClassName(event.target, "av__firstcol");
|
||||
if (checkElement) {
|
||||
} else if (target.classList.contains("av__firstcol")) {
|
||||
window.siyuan.menus.menu.remove();
|
||||
selectRow(checkElement, "toggle");
|
||||
selectRow(target, "toggle");
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
|
||||
const headerMoreElement = hasClosestByAttribute(event.target, "data-type", "av-header-more");
|
||||
if (headerMoreElement) {
|
||||
openMenuPanel({protyle, blockElement, type: "properties"});
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
|
||||
const moreElement = hasClosestByAttribute(event.target, "data-type", "av-more");
|
||||
if (moreElement) {
|
||||
openMenuPanel({protyle, blockElement, type: "config"});
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
|
||||
const sortsElement = hasClosestByAttribute(event.target, "data-type", "av-sort");
|
||||
if (sortsElement) {
|
||||
openMenuPanel({protyle, blockElement, type: "sorts"});
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
|
||||
const filtersElement = hasClosestByAttribute(event.target, "data-type", "av-filter");
|
||||
if (filtersElement) {
|
||||
openMenuPanel({protyle, blockElement, type: "filters"});
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
|
||||
const addTabElement = hasClosestByAttribute(event.target, "data-type", "av-add");
|
||||
if (addTabElement) {
|
||||
const id = Lute.NewNodeID();
|
||||
const avID = blockElement.getAttribute("data-av-id");
|
||||
transaction(protyle, [{
|
||||
action: "addAttrViewView",
|
||||
avID,
|
||||
id
|
||||
}], [{
|
||||
action: "removeAttrViewView",
|
||||
avID,
|
||||
id
|
||||
}]);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
|
||||
const linkElement = hasClosestByClassName(event.target, "av__celltext--url");
|
||||
if (linkElement) {
|
||||
let linkAddress = linkElement.textContent.trim();
|
||||
if (linkElement.dataset.type === "phone") {
|
||||
} else if (target.classList.contains("av__celltext--url")) {
|
||||
let linkAddress = target.textContent.trim();
|
||||
if (target.dataset.type === "phone") {
|
||||
linkAddress = "tel:" + linkAddress;
|
||||
} else if (linkElement.dataset.type === "email") {
|
||||
} else if (target.dataset.type === "email") {
|
||||
linkAddress = "mailto:" + linkAddress;
|
||||
} else if (linkElement.classList.contains("b3-chip")) {
|
||||
linkAddress = linkElement.dataset.url;
|
||||
} else if (target.classList.contains("b3-chip")) {
|
||||
linkAddress = target.dataset.url;
|
||||
}
|
||||
/// #if !MOBILE
|
||||
const suffix = pathPosix().extname(linkAddress);
|
||||
|
|
@ -192,47 +180,28 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
|
|||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
|
||||
const imgElement = hasClosestByClassName(event.target, "av__cellassetimg") as HTMLImageElement;
|
||||
if (imgElement) {
|
||||
previewImage(imgElement.src);
|
||||
} else if (target.classList.contains("av__cellassetimg")) {
|
||||
previewImage((target as HTMLImageElement).src);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
|
||||
const cellHeaderElement = hasClosestByClassName(event.target, "av__cellheader");
|
||||
if (cellHeaderElement) {
|
||||
showColMenu(protyle, blockElement, cellHeaderElement.parentElement);
|
||||
} else if (target.classList.contains("av__cellheader")) {
|
||||
showColMenu(protyle, blockElement, target.parentElement);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
|
||||
const blockMoreElement = hasClosestByAttribute(event.target, "data-type", "block-more");
|
||||
if (blockMoreElement) {
|
||||
protyle.toolbar.range = document.createRange();
|
||||
protyle.toolbar.range.selectNodeContents(blockMoreElement);
|
||||
focusByRange(protyle.toolbar.range);
|
||||
hintRef(blockMoreElement.previousElementSibling.textContent.trim(), protyle, "av");
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
|
||||
const cellElement = hasClosestByClassName(event.target, "av__cell");
|
||||
if (cellElement && !hasClosestByClassName(cellElement, "av__row--header")) {
|
||||
const scrollElement = hasClosestByClassName(cellElement, "av__scroll");
|
||||
} else if (target.classList.contains("av__cell")) {
|
||||
if (!hasClosestByClassName(target, "av__row--header")) {
|
||||
const scrollElement = hasClosestByClassName(target, "av__scroll");
|
||||
if (!scrollElement) {
|
||||
return;
|
||||
}
|
||||
const rowElement = hasClosestByClassName(cellElement, "av__row");
|
||||
const rowElement = hasClosestByClassName(target, "av__row");
|
||||
if (!rowElement) {
|
||||
return;
|
||||
}
|
||||
const type = getTypeByCellElement(cellElement);
|
||||
if (type === "updated" || type === "created" || (type === "block" && !cellElement.getAttribute("data-detached"))) {
|
||||
const type = getTypeByCellElement(target);
|
||||
if (type === "updated" || type === "created" || (type === "block" && !target.getAttribute("data-detached"))) {
|
||||
selectRow(rowElement.querySelector(".av__firstcol"), "toggle");
|
||||
} else {
|
||||
scrollElement.querySelectorAll(".av__row--select").forEach(item => {
|
||||
|
|
@ -240,26 +209,21 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
|
|||
item.classList.remove("av__row--select");
|
||||
});
|
||||
updateHeader(rowElement);
|
||||
popTextCell(protyle, [cellElement]);
|
||||
popTextCell(protyle, [target]);
|
||||
}
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
|
||||
const calcElement = hasClosestByClassName(event.target, "av__calc");
|
||||
if (calcElement) {
|
||||
openCalcMenu(protyle, calcElement);
|
||||
} else if (target.classList.contains("av__calc")) {
|
||||
openCalcMenu(protyle, target);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
|
||||
const addRowElement = hasClosestByClassName(event.target, "av__row--add");
|
||||
if (addRowElement) {
|
||||
} else if (target.classList.contains("av__row--add")) {
|
||||
const avID = blockElement.getAttribute("data-av-id");
|
||||
const srcIDs = [Lute.NewNodeID()];
|
||||
const previousID = addRowElement.previousElementSibling.getAttribute("data-id") || "";
|
||||
const previousID = target.previousElementSibling.getAttribute("data-id") || "";
|
||||
transaction(protyle, [{
|
||||
action: "insertAttrViewBlock",
|
||||
avID,
|
||||
|
|
@ -275,8 +239,16 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
|
|||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
} else if (target.classList.contains("item") && target.parentElement.classList.contains("layout-tab-bar")) {
|
||||
if (!target.classList.contains("item--focus")) {
|
||||
avRender(blockElement, protyle, undefined, target.dataset.id);
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return true;
|
||||
}
|
||||
target = target.parentElement;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import {hasClosestByClassName} from "../../util/hasClosest";
|
|||
import {stickyRow} from "./row";
|
||||
import {getCalcValue} from "./calc";
|
||||
|
||||
export const avRender = (element: Element, protyle: IProtyle, cb?: () => void) => {
|
||||
export const avRender = (element: Element, protyle: IProtyle, cb?: () => void, viewID?: string) => {
|
||||
let avElements: Element[] = [];
|
||||
if (element.getAttribute("data-type") === "NodeAttributeView") {
|
||||
// 编辑器内代码块编辑渲染
|
||||
|
|
@ -56,7 +56,7 @@ export const avRender = (element: Element, protyle: IProtyle, cb?: () => void) =
|
|||
id: e.getAttribute("data-av-id"),
|
||||
created,
|
||||
snapshot,
|
||||
viewID: e.querySelector(".av__header .item--focus")?.getAttribute("data-id")
|
||||
viewID: viewID || e.querySelector(".av__header .item--focus")?.getAttribute("data-id")
|
||||
}, (response) => {
|
||||
const data = response.data.view as IAVTable;
|
||||
// header
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue