Skip to content

Commit

Permalink
🚨
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Oct 30, 2024
1 parent 56e64c9 commit ca6955d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
78 changes: 39 additions & 39 deletions app/src/protyle/render/av/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Menu} from "../../../plugin/Menu";
import {hasClosestBlock, hasClosestByAttribute, hasClosestByClassName} from "../../util/hasClosest";
import {transaction} from "../../wysiwyg/transaction";
import {openEditorTab} from "../../../menus/util";
import {copySubMenu, openFileAttr} from "../../../menus/commonMenuItem";
import {openFileAttr} from "../../../menus/commonMenuItem";
import {
addDragFill,
genCellValueByElement,
Expand Down Expand Up @@ -93,7 +93,7 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle
searchElement.style.paddingRight = "";
const viewsElement = hasClosestByClassName(searchElement, "av__views");
if (viewsElement) {
viewsElement.classList.add("av__views--show")
viewsElement.classList.add("av__views--show");
}
setTimeout(() => {
searchElement.focus();
Expand Down Expand Up @@ -288,38 +288,38 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
});
/// #endif
}
let copyMenu: IMenu[] = []
let copyMenu: IMenu[] = [];
if (rowElements.length === 1 && keyCellElement.getAttribute("data-detached") === "true") {
copyMenu.push({
iconHTML: "",
label: window.siyuan.languages['_attrView'].key,
label: window.siyuan.languages["_attrView"].key,
click() {
writeText(rowElements[0].querySelector('.av__cell[data-dtype="block"] .av__celltext').textContent);
}
})
});
} else {
copyMenu = [{
id: "copyBlockRef",
iconHTML: "",
label: window.siyuan.languages.copyBlockRef,
click: async () => {
let text = ""
let text = "";
for (let i = 0; i < ids.length; i++) {
const id = ids[i];
let content = ""
const cellElement = rowElements[i].querySelector(".av__cell[data-dtype='block']")
let content = "";
const cellElement = rowElements[i].querySelector(".av__cell[data-dtype='block']");
if (cellElement.getAttribute("data-detached") === "true") {
content = cellElement.querySelector(".av__celltext").textContent;
} else {
const response = await fetchSyncPost("/api/block/getRefText", {id});
content = `((${id} '${response.data}'))`
content = `((${id} '${response.data}'))`;
}
if (ids.length > 1) {
text += "* "
text += "* ";
}
text += content;
if (ids.length > 1 && i !== ids.length - 1) {
text += "\n"
text += "\n";
}
}
writeText(text);
Expand All @@ -329,34 +329,34 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
iconHTML: "",
label: window.siyuan.languages.copyBlockEmbed,
click: () => {
let text = ""
let text = "";
ids.forEach((id, index) => {
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") {
text += cellElement.querySelector(".av__celltext").textContent;
} else {
text += `{{select * from blocks where id='${id}'}}`
text += `{{select * from blocks where id='${id}'}}`;
}
if (ids.length > 1 && index !== ids.length - 1) {
text += "\n"
text += "\n";
}
})
});
writeText(text);
}
}, {
id: "copyProtocol",
iconHTML: "",
label: window.siyuan.languages.copyProtocol,
click: () => {
let text = ""
let text = "";
ids.forEach((id, index) => {
if (ids.length > 1) {
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") {
text += cellElement.querySelector(".av__celltext").textContent;
} else {
Expand All @@ -365,31 +365,31 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
if (ids.length > 1 && index !== ids.length - 1) {
text += "\n";
}
})
});
writeText(text);
}
}, {
id: "copyProtocolInMd",
iconHTML: "",
label: window.siyuan.languages.copyProtocolInMd,
click: async () => {
let text = ""
let text = "";
for (let i = 0; i < ids.length; i++) {
const id = ids[i];
let content = ""
const cellElement = rowElements[i].querySelector(".av__cell[data-dtype='block']")
let content = "";
const cellElement = rowElements[i].querySelector(".av__cell[data-dtype='block']");
if (cellElement.getAttribute("data-detached") === "true") {
content = cellElement.querySelector(".av__celltext").textContent;
} else {
const response = await fetchSyncPost("/api/block/getRefText", {id});
content = `[${response.data}](siyuan://blocks/${id})`
content = `[${response.data}](siyuan://blocks/${id})`;
}
if (ids.length > 1) {
text += "* "
text += "* ";
}
text += content
text += content;
if (ids.length > 1 && i !== ids.length - 1) {
text += "\n"
text += "\n";
}
}
writeText(text);
Expand All @@ -399,24 +399,24 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
iconHTML: "",
label: window.siyuan.languages.copyHPath,
click: async () => {
let text = ""
let text = "";
for (let i = 0; i < ids.length; i++) {
const id = ids[i];
let content = ""
const cellElement = rowElements[i].querySelector(".av__cell[data-dtype='block']")
let content = "";
const cellElement = rowElements[i].querySelector(".av__cell[data-dtype='block']");
if (cellElement.getAttribute("data-detached") === "true") {
content = cellElement.querySelector(".av__celltext").textContent;
} else {
const response = await fetchSyncPost("/api/filetree/getHPathByID", {id});
content = response.data
content = response.data;
}

if (ids.length > 1) {
text += "* "
text += "* ";
}
text += content
text += content;
if (ids.length > 1 && i !== ids.length - 1) {
text += "\n"
text += "\n";
}
}
writeText(text);
Expand All @@ -426,24 +426,24 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
iconHTML: "",
label: window.siyuan.languages.copyID,
click: () => {
let text = ""
let text = "";
ids.forEach((id, index) => {
if (ids.length > 1) {
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") {
text += cellElement.querySelector(".av__celltext").textContent;
} else {
text += id
text += id;
}
if (ids.length > 1 && index !== ids.length - 1) {
text += "\n";
}
})
});
writeText(text);
}
}]
}];
}

menu.addItem({
Expand Down
4 changes: 2 additions & 2 deletions app/src/protyle/util/insertHTML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ const processTable = (range: Range, html: string, protyle: IProtyle, blockElemen
const scrollLeft = blockElement.firstElementChild.scrollLeft;
const tableSelectElement = blockElement.querySelector(".table__select") as HTMLElement;
let index = 0;
const matchCellsElement: HTMLTableCellElement[] = []
const matchCellsElement: HTMLTableCellElement[] = [];
blockElement.querySelectorAll("th, td").forEach((item: HTMLTableCellElement) => {
if (!item.classList.contains("fn__none") &&
item.offsetLeft + 6 > tableSelectElement.offsetLeft + scrollLeft && item.offsetLeft + item.clientWidth - 6 < tableSelectElement.offsetLeft + scrollLeft + tableSelectElement.clientWidth &&
Expand All @@ -227,7 +227,7 @@ const processTable = (range: Range, html: string, protyle: IProtyle, blockElemen
if (matchIndex === matchCellsElement.length - 1) {
setLastNodeRange(item, range, false);
}
})
});
range.collapse(false);
updateTransaction(protyle, blockElement.getAttribute("data-node-id"), blockElement.outerHTML, oldHTML);
return true;
Expand Down
10 changes: 5 additions & 5 deletions app/src/protyle/wysiwyg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ export class WYSIWYG {
documentSelf.onselect = null;
if (lastCellElement) {
dragFillCellsValue(protyle, nodeElement, originData, originCellIds);
const allActiveCellsElement = nodeElement.querySelectorAll(".av__cell--active")
const allActiveCellsElement = nodeElement.querySelectorAll(".av__cell--active");
addDragFill(allActiveCellsElement[allActiveCellsElement.length - 1]);
}
return false;
Expand Down Expand Up @@ -701,7 +701,7 @@ export class WYSIWYG {
}
// table cell select
let tableBlockElement: HTMLElement | false;
const targetCellElemet = hasClosestByMatchTag(target, "TH") || hasClosestByMatchTag(target, "TD")
const targetCellElemet = hasClosestByMatchTag(target, "TH") || hasClosestByMatchTag(target, "TD");
if (targetCellElemet) {
target = targetCellElemet;
}
Expand Down Expand Up @@ -790,9 +790,9 @@ export class WYSIWYG {
// table cell select
if (!protyle.disabled && tableBlockElement && tableBlockElement.contains(moveTarget) && !hasClosestByClassName(tableBlockElement, "protyle-wysiwyg__embed")) {
if (moveTarget.classList.contains("table__select")) {
moveTarget.classList.add("fn__none")
const pointElement = document.elementFromPoint(moveEvent.clientX, moveEvent.clientY)
moveTarget.classList.remove("fn__none")
moveTarget.classList.add("fn__none");
const pointElement = document.elementFromPoint(moveEvent.clientX, moveEvent.clientY);
moveTarget.classList.remove("fn__none");
moveTarget = hasClosestByMatchTag(pointElement, "TH") || hasClosestByMatchTag(pointElement, "TD");
}
if (moveTarget && (moveTarget.tagName === "TH" || moveTarget.tagName === "TD") && (!moveCellElement || !moveCellElement.isSameNode(moveTarget))) {
Expand Down

0 comments on commit ca6955d

Please sign in to comment.