🎨 数据库改进

This commit is contained in:
Vanessa 2024-01-10 11:33:49 +08:00
parent a97a8d70bd
commit 3cde9f5219
6 changed files with 28 additions and 19 deletions

View file

@ -23,7 +23,7 @@ export const initBlockPopover = (app: App) => {
if (aElement) {
let tip = aElement.getAttribute("aria-label") || aElement.getAttribute("data-inline-memo-content");
if (aElement.classList.contains("av__celltext")) {
if (aElement.offsetWidth > aElement.parentElement.clientWidth - 5) { // 只能减左边 padding换行时字体会穿透到右侧 padding
if (aElement.offsetWidth > aElement.parentElement.clientWidth - (aElement.classList.contains("fn__flex-shrink") ? 19 : 5)) { // 只能减左边 padding换行时字体会穿透到右侧 padding
if (aElement.querySelector(".av__cellicon")) {
tip = `${aElement.firstChild.textContent}${aElement.lastChild.textContent}`;
} else {

View file

@ -217,6 +217,9 @@ export class Gutter {
return;
}
if (buttonElement.dataset.type === "NodeAttributeViewRow") {
blockElement.querySelectorAll(".av__cell--select").forEach((cellElement: HTMLElement) => {
cellElement.classList.remove("av__cell--select");
});
const avID = blockElement.getAttribute("data-av-id");
const srcIDs = [Lute.NewNodeID()];
const previousID = event.altKey ? (rowElement.previousElementSibling.getAttribute("data-id") || "") : buttonElement.dataset.rowId;

View file

@ -399,7 +399,10 @@ ${genHintItemHTML(item)}
return;
}
if (this.source === "av") {
const cellElement = hasClosestByClassName(protyle.toolbar.range.startContainer, "av__cell");
let cellElement = hasClosestByClassName(protyle.toolbar.range.startContainer, "av__cell");
if (!cellElement) {
cellElement = nodeElement.querySelector(".av__cell--select") as HTMLElement;
}
if (!cellElement) {
return;
}

View file

@ -315,8 +315,15 @@ export const popTextCell = (protyle: IProtyle, cellElements: HTMLElement[], type
inputElement.addEventListener("input", (event: InputEvent) => {
if (Constants.BLOCK_HINT_KEYS.includes(inputElement.value.substring(0, 2))) {
protyle.toolbar.range = document.createRange();
if (!blockElement.contains(cellElements[0])) {
const rowElement = hasClosestByClassName(cellElements[0], "av__row") as HTMLElement;
if (cellElements[0]) {
cellElements[0] = blockElement.querySelector(`.av__row[data-id="${rowElement.dataset.id}"] .av__cell[data-col-id="${cellElements[0].dataset.colId}"]`) as HTMLElement;
}
}
protyle.toolbar.range.selectNodeContents(cellElements[0].lastChild);
focusByRange(protyle.toolbar.range);
cellElements[0].classList.add("av__cell--select");
hintRef(inputElement.value.substring(2), protyle, "av");
avMaskElement?.remove();
event.preventDefault();

View file

@ -98,7 +98,7 @@ data-icon="${column.icon}" data-dtype="${column.type}" data-wrap="${column.wrap}
style="width: ${column.width || "200px"};">
<div draggable="true" class="av__cellheader">
${column.icon ? unicode2Emoji(column.icon, "av__cellheadericon", true) : `<svg class="av__cellheadericon"><use xlink:href="#${getColIconByType(column.type)}"></use></svg>`}
<span class="av__celltext">${column.name}</span>
<span class="av__celltext fn__flex-shrink">${column.name}</span>
${column.pin ? '<div class="fn__flex-1"></div><svg class="av__cellheadericon"><use xlink:href="#iconPin"></use></svg>' : ""}
</div>
<div class="av__widthdrag"></div>
@ -292,11 +292,7 @@ export const refreshAV = (protyle: IProtyle, operation: IOperation) => {
Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-av-id="${operation.avID}"]`)).forEach((item: HTMLElement) => {
item.removeAttribute("data-render");
avRender(item, protyle, () => {
if (operation.action === "insertAttrViewBlock") {
item.querySelectorAll(".av__cell--select").forEach((cellElement: HTMLElement) => {
cellElement.classList.remove("av__cell--select");
});
} else if (operation.action === "addAttrViewCol" && item.querySelector(".av__pulse")) {
if (operation.action === "addAttrViewCol" && item.querySelector(".av__pulse")) {
openMenuPanel({protyle, blockElement: item, type: "edit", colId: operation.id});
}
}, ["addAttrViewView", "duplicateAttrViewView"].includes(operation.action) ? operation.id :

View file

@ -1326,6 +1326,17 @@ export class WYSIWYG {
/// #endif
return false;
}
// 在 span 前面,防止单元格哪 block-ref 被修改
const avRowElement = hasClosestByClassName(target, "av__row");
if (avRowElement && avContextmenu(protyle, avRowElement, {
x: event.clientX,
y: avRowElement.getBoundingClientRect().bottom,
h: avRowElement.clientHeight
})) {
event.stopPropagation();
event.preventDefault();
return;
}
protyle.toolbar.range = getEditorRange(protyle.element);
if (target.tagName === "SPAN") { // https://ld246.com/article/1665141518103
let types = protyle.toolbar.getCurrentType(protyle.toolbar.range);
@ -1373,17 +1384,6 @@ export class WYSIWYG {
});
return false;
}
const avRowElement = hasClosestByClassName(target, "av__row");
if (avRowElement && avContextmenu(protyle, avRowElement, {
x: event.clientX,
y: avRowElement.getBoundingClientRect().bottom,
h: avRowElement.clientHeight
})) {
event.stopPropagation();
event.preventDefault();
return;
}
const nodeElement = hasClosestBlock(target);
if (!nodeElement) {
return false;