Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Ignore table interactions inside custom Protyle elements https://github.com/siyuan-note/siyuan/issues/18913

Danielb87bb9784804
diff --git a/app/src/boot/globalEvent/mousemove.ts b/app/src/boot/globalEvent/mousemove.ts
index 1a679d2b9b..9bbebd4d2d 100644
--- a/app/src/boot/globalEvent/mousemove.ts
+++ b/app/src/boot/globalEvent/mousemove.ts
@@ -263,7 +263,9 @@ export const windowMouseMove = (event: MouseEvent) => {
}
const blockElement = hasClosestByClassName(target, "table");
- if (blockElement && blockElement.style.cursor !== "col-resize" && !hasClosestByClassName(blockElement, "protyle-wysiwyg__embed")) {
+ if (blockElement && blockElement.style.cursor !== "col-resize" &&
+ !hasClosestByClassName(blockElement, "protyle-wysiwyg__embed") &&
+ !hasClosestByClassName(blockElement, "protyle-custom")) {
const cellElement = (hasClosestByTag(target, "TH") || hasClosestByTag(target, "TD")) as HTMLTableCellElement;
const tableElement = blockElement.querySelector("table");
const resizeElement = blockElement.querySelector(".table__resize");
diff --git a/app/src/protyle/util/tableControl.ts b/app/src/protyle/util/tableControl.ts
index 6e9e5f8036..7acc0a75c5 100644
--- a/app/src/protyle/util/tableControl.ts
+++ b/app/src/protyle/util/tableControl.ts
@@ -103,6 +103,9 @@ const getCell = (target: EventTarget | Node) => {
};
const getTableNode = (cell: HTMLTableCellElement) => {
+ if (cell?.closest(".protyle-custom")) {
+ return;
+ }
return cell?.closest<HTMLElement>('[data-type="NodeTable"]');
};
@@ -1009,6 +1012,9 @@ export class TableControl {
private getEdgeHover(clientX: number, clientY: number) {
const candidates: ITableEdgeHover[] = [];
this.wysiwygElement.querySelectorAll<HTMLTableElement>('[data-type="NodeTable"] table').forEach(table => {
+ if (table.closest(".protyle-custom")) {
+ return;
+ }
const gridRect = this.getTableGridRect(table);
const addColumnEdge = gridRect.right;
const viewportRect = this.getTableGridViewportRect(table, gridRect);
@@ -1169,6 +1175,9 @@ export class TableControl {
const actions = new Map<HTMLTableElement, HTMLElement>();
this.wysiwygElement.querySelectorAll<HTMLTableElement>(
'[data-type="NodeTable"][custom-pinthead="true"] table').forEach(table => {
+ if (table.closest(".protyle-custom")) {
+ return;
+ }
const action = table.nextElementSibling as HTMLElement;
if (!action?.classList.contains("protyle-action__table")) {
return;
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 7257053002..df898d314a 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -1076,11 +1076,15 @@ export class WYSIWYG {
const documentSelf = document;
documentSelf.onmouseup = null;
let target = event.target as HTMLElement;
+ const customElement = hasClosestByClassName(target, "protyle-custom");
let nodeElement = hasClosestBlock(target) as HTMLElement;
- let clickedTableNode = nodeElement && nodeElement.dataset.type === "NodeTable" ? nodeElement : undefined;
- if (!nodeElement) {
+ let clickedTableNode = !customElement && nodeElement?.dataset.type === "NodeTable" ? nodeElement : undefined;
+ if (!nodeElement && !customElement) {
clickedTableNode = Array.from(this.element.querySelectorAll<HTMLElement>(
'[data-type="NodeTable"]')).find(item => {
+ if (hasClosestByClassName(item, "protyle-custom")) {
+ return false;
+ }
const table = item.querySelector("table");
if (!table) {
return false;
@@ -1834,12 +1838,14 @@ export class WYSIWYG {
}
// table cell select
let tableBlockElement: HTMLElement | false;
- const targetCellElement = hasClosestByTag(target, "TH") || hasClosestByTag(target, "TD");
+ const targetCellElement = !customElement &&
+ (hasClosestByTag(target, "TH") || hasClosestByTag(target, "TD"));
if (targetCellElement) {
target = targetCellElement;
}
- if (target.tagName === "TH" || target.tagName === "TD" || target.firstElementChild?.tagName === "TABLE" ||
- target.classList.contains("table__resize") || target.classList.contains("table__select")) {
+ if (!customElement &&
+ (target.tagName === "TH" || target.tagName === "TD" || target.firstElementChild?.tagName === "TABLE" ||
+ target.classList.contains("table__resize") || target.classList.contains("table__select"))) {
tableBlockElement = nodeElement;
if (tableBlockElement) {
tableBlockElement.querySelector(".table__select").removeAttribute("style");
@@ -1858,7 +1864,7 @@ export class WYSIWYG {
// 后续拖拽操作写在多选节点中
}
// table col resize
- if (!protyle.disabled && target.classList.contains("table__resize")) {
+ if (!customElement && !protyle.disabled && target.classList.contains("table__resize")) {
if (!nodeElement) {
return;
}