This commit is contained in:
Vanessa 2024-10-30 23:00:52 +08:00
parent 56e64c9b7e
commit ca6955dc31
3 changed files with 46 additions and 46 deletions

View file

@ -2,7 +2,7 @@ import {Menu} from "../../../plugin/Menu";
import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "../../util/hasClosest"; import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "../../util/hasClosest";
import {transaction} from "../../wysiwyg/transaction"; import {transaction} from "../../wysiwyg/transaction";
import {openEditorTab} from "../../../menus/util"; import {openEditorTab} from "../../../menus/util";
import {copySubMenu, openFileAttr} from "../../../menus/commonMenuItem"; import {openFileAttr} from "../../../menus/commonMenuItem";
import { import {
addDragFill, addDragFill,
genCellValueByElement, genCellValueByElement,
@ -93,7 +93,7 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
searchElement.style.paddingRight = ""; searchElement.style.paddingRight = "";
const viewsElement = hasClosestByClassName(searchElement, "av__views"); const viewsElement = hasClosestByClassName(searchElement, "av__views");
if (viewsElement) { if (viewsElement) {
viewsElement.classList.add("av__views--show") viewsElement.classList.add("av__views--show");
} }
setTimeout(() => { setTimeout(() => {
searchElement.focus(); searchElement.focus();
@ -288,38 +288,38 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
}); });
/// #endif /// #endif
} }
let copyMenu: IMenu[] = [] let copyMenu: IMenu[] = [];
if (rowElements.length === 1 && keyCellElement.getAttribute("data-detached") === "true") { if (rowElements.length === 1 && keyCellElement.getAttribute("data-detached") === "true") {
copyMenu.push({ copyMenu.push({
iconHTML: "", iconHTML: "",
label: window.siyuan.languages['_attrView'].key, label: window.siyuan.languages["_attrView"].key,
click() { click() {
writeText(rowElements[0].querySelector('.av__cell[data-dtype="block"] .av__celltext').textContent); writeText(rowElements[0].querySelector('.av__cell[data-dtype="block"] .av__celltext').textContent);
} }
}) });
} else { } else {
copyMenu = [{ copyMenu = [{
id: "copyBlockRef", id: "copyBlockRef",
iconHTML: "", iconHTML: "",
label: window.siyuan.languages.copyBlockRef, label: window.siyuan.languages.copyBlockRef,
click: async () => { click: async () => {
let text = "" let text = "";
for (let i = 0; i < ids.length; i++) { for (let i = 0; i < ids.length; i++) {
const id = ids[i]; const id = ids[i];
let content = "" let content = "";
const cellElement = rowElements[i].querySelector(".av__cell[data-dtype='block']") const cellElement = rowElements[i].querySelector(".av__cell[data-dtype='block']");
if (cellElement.getAttribute("data-detached") === "true") { if (cellElement.getAttribute("data-detached") === "true") {
content = cellElement.querySelector(".av__celltext").textContent; content = cellElement.querySelector(".av__celltext").textContent;
} else { } else {
const response = await fetchSyncPost("/api/block/getRefText", {id}); const response = await fetchSyncPost("/api/block/getRefText", {id});
content = `((${id} '${response.data}'))` content = `((${id} '${response.data}'))`;
} }
if (ids.length > 1) { if (ids.length > 1) {
text += "* " text += "* ";
} }
text += content; text += content;
if (ids.length > 1 && i !== ids.length - 1) { if (ids.length > 1 && i !== ids.length - 1) {
text += "\n" text += "\n";
} }
} }
writeText(text); writeText(text);
@ -329,21 +329,21 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
iconHTML: "", iconHTML: "",
label: window.siyuan.languages.copyBlockEmbed, label: window.siyuan.languages.copyBlockEmbed,
click: () => { click: () => {
let text = "" let text = "";
ids.forEach((id, index) => { ids.forEach((id, index) => {
if (ids.length > 1) { if (ids.length > 1) {
text += "* " text += "* ";
} }
const cellElement = rowElements[index].querySelector(".av__cell[data-dtype='block']") const cellElement = rowElements[index].querySelector(".av__cell[data-dtype='block']");
if (cellElement.getAttribute("data-detached") === "true") { if (cellElement.getAttribute("data-detached") === "true") {
text += cellElement.querySelector(".av__celltext").textContent; text += cellElement.querySelector(".av__celltext").textContent;
} else { } else {
text += `{{select * from blocks where id='${id}'}}` text += `{{select * from blocks where id='${id}'}}`;
} }
if (ids.length > 1 && index !== ids.length - 1) { if (ids.length > 1 && index !== ids.length - 1) {
text += "\n" text += "\n";
} }
}) });
writeText(text); writeText(text);
} }
}, { }, {
@ -351,12 +351,12 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
iconHTML: "", iconHTML: "",
label: window.siyuan.languages.copyProtocol, label: window.siyuan.languages.copyProtocol,
click: () => { click: () => {
let text = "" let text = "";
ids.forEach((id, index) => { ids.forEach((id, index) => {
if (ids.length > 1) { if (ids.length > 1) {
text += "* "; text += "* ";
} }
const cellElement = rowElements[index].querySelector(".av__cell[data-dtype='block']") const cellElement = rowElements[index].querySelector(".av__cell[data-dtype='block']");
if (cellElement.getAttribute("data-detached") === "true") { if (cellElement.getAttribute("data-detached") === "true") {
text += cellElement.querySelector(".av__celltext").textContent; text += cellElement.querySelector(".av__celltext").textContent;
} else { } else {
@ -365,7 +365,7 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
if (ids.length > 1 && index !== ids.length - 1) { if (ids.length > 1 && index !== ids.length - 1) {
text += "\n"; text += "\n";
} }
}) });
writeText(text); writeText(text);
} }
}, { }, {
@ -373,23 +373,23 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
iconHTML: "", iconHTML: "",
label: window.siyuan.languages.copyProtocolInMd, label: window.siyuan.languages.copyProtocolInMd,
click: async () => { click: async () => {
let text = "" let text = "";
for (let i = 0; i < ids.length; i++) { for (let i = 0; i < ids.length; i++) {
const id = ids[i]; const id = ids[i];
let content = "" let content = "";
const cellElement = rowElements[i].querySelector(".av__cell[data-dtype='block']") const cellElement = rowElements[i].querySelector(".av__cell[data-dtype='block']");
if (cellElement.getAttribute("data-detached") === "true") { if (cellElement.getAttribute("data-detached") === "true") {
content = cellElement.querySelector(".av__celltext").textContent; content = cellElement.querySelector(".av__celltext").textContent;
} else { } else {
const response = await fetchSyncPost("/api/block/getRefText", {id}); const response = await fetchSyncPost("/api/block/getRefText", {id});
content = `[${response.data}](siyuan://blocks/${id})` content = `[${response.data}](siyuan://blocks/${id})`;
} }
if (ids.length > 1) { if (ids.length > 1) {
text += "* " text += "* ";
} }
text += content text += content;
if (ids.length > 1 && i !== ids.length - 1) { if (ids.length > 1 && i !== ids.length - 1) {
text += "\n" text += "\n";
} }
} }
writeText(text); writeText(text);
@ -399,24 +399,24 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
iconHTML: "", iconHTML: "",
label: window.siyuan.languages.copyHPath, label: window.siyuan.languages.copyHPath,
click: async () => { click: async () => {
let text = "" let text = "";
for (let i = 0; i < ids.length; i++) { for (let i = 0; i < ids.length; i++) {
const id = ids[i]; const id = ids[i];
let content = "" let content = "";
const cellElement = rowElements[i].querySelector(".av__cell[data-dtype='block']") const cellElement = rowElements[i].querySelector(".av__cell[data-dtype='block']");
if (cellElement.getAttribute("data-detached") === "true") { if (cellElement.getAttribute("data-detached") === "true") {
content = cellElement.querySelector(".av__celltext").textContent; content = cellElement.querySelector(".av__celltext").textContent;
} else { } else {
const response = await fetchSyncPost("/api/filetree/getHPathByID", {id}); const response = await fetchSyncPost("/api/filetree/getHPathByID", {id});
content = response.data content = response.data;
} }
if (ids.length > 1) { if (ids.length > 1) {
text += "* " text += "* ";
} }
text += content text += content;
if (ids.length > 1 && i !== ids.length - 1) { if (ids.length > 1 && i !== ids.length - 1) {
text += "\n" text += "\n";
} }
} }
writeText(text); writeText(text);
@ -426,24 +426,24 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
iconHTML: "", iconHTML: "",
label: window.siyuan.languages.copyID, label: window.siyuan.languages.copyID,
click: () => { click: () => {
let text = "" let text = "";
ids.forEach((id, index) => { ids.forEach((id, index) => {
if (ids.length > 1) { if (ids.length > 1) {
text += "* "; text += "* ";
} }
const cellElement = rowElements[index].querySelector(".av__cell[data-dtype='block']") const cellElement = rowElements[index].querySelector(".av__cell[data-dtype='block']");
if (cellElement.getAttribute("data-detached") === "true") { if (cellElement.getAttribute("data-detached") === "true") {
text += cellElement.querySelector(".av__celltext").textContent; text += cellElement.querySelector(".av__celltext").textContent;
} else { } else {
text += id text += id;
} }
if (ids.length > 1 && index !== ids.length - 1) { if (ids.length > 1 && index !== ids.length - 1) {
text += "\n"; text += "\n";
} }
}) });
writeText(text); writeText(text);
} }
}] }];
} }
menu.addItem({ menu.addItem({

View file

@ -209,7 +209,7 @@ const processTable = (range: Range, html: string, protyle: IProtyle, blockElemen
const scrollLeft = blockElement.firstElementChild.scrollLeft; const scrollLeft = blockElement.firstElementChild.scrollLeft;
const tableSelectElement = blockElement.querySelector(".table__select") as HTMLElement; const tableSelectElement = blockElement.querySelector(".table__select") as HTMLElement;
let index = 0; let index = 0;
const matchCellsElement: HTMLTableCellElement[] = [] const matchCellsElement: HTMLTableCellElement[] = [];
blockElement.querySelectorAll("th, td").forEach((item: HTMLTableCellElement) => { blockElement.querySelectorAll("th, td").forEach((item: HTMLTableCellElement) => {
if (!item.classList.contains("fn__none") && if (!item.classList.contains("fn__none") &&
item.offsetLeft + 6 > tableSelectElement.offsetLeft + scrollLeft && item.offsetLeft + item.clientWidth - 6 < tableSelectElement.offsetLeft + scrollLeft + tableSelectElement.clientWidth && item.offsetLeft + 6 > tableSelectElement.offsetLeft + scrollLeft && item.offsetLeft + item.clientWidth - 6 < tableSelectElement.offsetLeft + scrollLeft + tableSelectElement.clientWidth &&
@ -227,7 +227,7 @@ const processTable = (range: Range, html: string, protyle: IProtyle, blockElemen
if (matchIndex === matchCellsElement.length - 1) { if (matchIndex === matchCellsElement.length - 1) {
setLastNodeRange(item, range, false); setLastNodeRange(item, range, false);
} }
}) });
range.collapse(false); range.collapse(false);
updateTransaction(protyle, blockElement.getAttribute("data-node-id"), blockElement.outerHTML, oldHTML); updateTransaction(protyle, blockElement.getAttribute("data-node-id"), blockElement.outerHTML, oldHTML);
return true; return true;

View file

@ -565,7 +565,7 @@ export class WYSIWYG {
documentSelf.onselect = null; documentSelf.onselect = null;
if (lastCellElement) { if (lastCellElement) {
dragFillCellsValue(protyle, nodeElement, originData, originCellIds); dragFillCellsValue(protyle, nodeElement, originData, originCellIds);
const allActiveCellsElement = nodeElement.querySelectorAll(".av__cell--active") const allActiveCellsElement = nodeElement.querySelectorAll(".av__cell--active");
addDragFill(allActiveCellsElement[allActiveCellsElement.length - 1]); addDragFill(allActiveCellsElement[allActiveCellsElement.length - 1]);
} }
return false; return false;
@ -701,7 +701,7 @@ export class WYSIWYG {
} }
// table cell select // table cell select
let tableBlockElement: HTMLElement | false; let tableBlockElement: HTMLElement | false;
const targetCellElemet = hasClosestByMatchTag(target, "TH") || hasClosestByMatchTag(target, "TD") const targetCellElemet = hasClosestByMatchTag(target, "TH") || hasClosestByMatchTag(target, "TD");
if (targetCellElemet) { if (targetCellElemet) {
target = targetCellElemet; target = targetCellElemet;
} }
@ -790,9 +790,9 @@ export class WYSIWYG {
// table cell select // table cell select
if (!protyle.disabled && tableBlockElement && tableBlockElement.contains(moveTarget) && !hasClosestByClassName(tableBlockElement, "protyle-wysiwyg__embed")) { if (!protyle.disabled && tableBlockElement && tableBlockElement.contains(moveTarget) && !hasClosestByClassName(tableBlockElement, "protyle-wysiwyg__embed")) {
if (moveTarget.classList.contains("table__select")) { if (moveTarget.classList.contains("table__select")) {
moveTarget.classList.add("fn__none") moveTarget.classList.add("fn__none");
const pointElement = document.elementFromPoint(moveEvent.clientX, moveEvent.clientY) const pointElement = document.elementFromPoint(moveEvent.clientX, moveEvent.clientY);
moveTarget.classList.remove("fn__none") moveTarget.classList.remove("fn__none");
moveTarget = hasClosestByMatchTag(pointElement, "TH") || hasClosestByMatchTag(pointElement, "TD"); moveTarget = hasClosestByMatchTag(pointElement, "TH") || hasClosestByMatchTag(pointElement, "TD");
} }
if (moveTarget && (moveTarget.tagName === "TH" || moveTarget.tagName === "TD") && (!moveCellElement || !moveCellElement.isSameNode(moveTarget))) { if (moveTarget && (moveTarget.tagName === "TH" || moveTarget.tagName === "TD") && (!moveCellElement || !moveCellElement.isSameNode(moveTarget))) {