Vanessa 2024-04-12 16:04:05 +08:00
parent 6cb4ec8777
commit f822e4d69e
3 changed files with 61 additions and 16 deletions

View file

@ -12,6 +12,7 @@ import {getColIconByType} from "./col";
import {genAVValueHTML} from "./blockAttr";
import {Constants} from "../../../constants";
import {hintRef} from "../../hint/extend";
import {pathPosix} from "../../../util/pathName";
const renderCellURL = (urlContent: string) => {
let host = urlContent;
@ -133,7 +134,7 @@ export const genCellValue = (colType: TAVCol, value: string | any) => {
type: colType,
[colType === "select" ? "mSelect" : colType]: value as IAVCellDateValue
};
if (typeof value === "string" && value && colType !== "mAsset") {
if (typeof value === "string" && value) {
if (colType === "number") {
cellValue = {
type: colType,
@ -181,6 +182,16 @@ export const genCellValue = (colType: TAVCol, value: string | any) => {
type: colType,
relation: {blockIDs: [value], contents: []}
};
} else if (colType === "mAsset") {
const type = pathPosix().extname(value).toLowerCase();
cellValue = {
type: colType,
mAsset: [{
type: Constants.SIYUAN_ASSETS_IMAGE.includes(type) ? "image" : "file",
content: value,
name: "",
}]
};
}
} else if (typeof value === "undefined" || !value) {
if (colType === "number") {

View file

@ -23,19 +23,22 @@ export const avKeydown = (event: KeyboardEvent, nodeElement: HTMLElement, protyl
if (!rowElement) {
return false;
}
if (event.key === "Backspace" || event.key === "Delete") {
updateCellsValue(protyle, nodeElement, undefined, Array.from(nodeElement.querySelectorAll(".av__cell--active, .av__cell--select")));
event.preventDefault();
return true;
}
const avPanelElement = document.querySelector(".av__panel");
if (avPanelElement &&
(event.key === "Escape" || event.key.startsWith("ArrowLeft") || event.key === "Enter" || matchHotKey("⇥", event) || matchHotKey("⇧⇥", event))) {
(event.key === "Backspace" || event.key === "Delete" || event.key === "Escape" ||
event.key.startsWith("ArrowLeft") || event.key === "Enter" || matchHotKey("⇥", event) ||
matchHotKey("⇧⇥", event))) {
avPanelElement.remove();
event.preventDefault();
event.stopPropagation();
return true;
}
// 需在 avPanelElement 之后,否则点击资源单元格后删除,资源面板不会更新
if (event.key === "Backspace" || event.key === "Delete") {
updateCellsValue(protyle, nodeElement, undefined, Array.from(nodeElement.querySelectorAll(".av__cell--active, .av__cell--select")));
event.preventDefault();
return true;
}
if (event.key === "Escape") {
selectCellElement.classList.remove("av__cell--select", "av__cell--active");
selectCellElement.querySelector(".av__drag-fill")?.remove();

View file

@ -8,7 +8,7 @@ import {pathPosix} from "../../util/pathName";
import {genAssetHTML} from "../../asset/renderAssets";
import {hasClosestBlock} from "../util/hasClosest";
import {getContenteditableElement} from "../wysiwyg/getBlock";
import {updateCellsValue} from "../render/av/cell";
import {getTypeByCellElement, updateCellsValue} from "../render/av/cell";
export class Upload {
public element: HTMLElement;
@ -143,17 +143,48 @@ const genUploadedLabel = (responseText: string, protyle: IProtyle) => {
}
}
});
if ((nodeElement && nodeElement.classList.contains("av"))) {
updateCellsValue(protyle, nodeElement, avAssets);
document.querySelector(".av__panel")?.remove();
return;
}
if (document.querySelector(".av__panel")) {
const blockElement = hasClosestBlock(protyle.wysiwyg.element.querySelector(".av__cell--select"));
if (blockElement) {
updateCellsValue(protyle, blockElement, avAssets);
const cellElements: HTMLElement[] = []
nodeElement.querySelectorAll(".av__row--select:not(.av__row--header)").forEach(item => {
item.querySelectorAll(".av__cell").forEach((cellItem: HTMLElement) => {
if (getTypeByCellElement(cellItem) === "mAsset") {
cellElements.push(cellItem);
}
})
})
if (cellElements.length === 0) {
protyle.wysiwyg.element.querySelectorAll(".av__cell--active").forEach((item: HTMLElement) => {
if (getTypeByCellElement(item) === "mAsset") {
cellElements.push(item);
}
})
}
if (cellElements.length > 0) {
updateCellsValue(protyle, nodeElement, avAssets, cellElements);
document.querySelector(".av__panel")?.remove();
return;
} else {
return;
}
}
if (document.querySelector(".av__panel")) {
const cellElements: HTMLElement[] = []
protyle.wysiwyg.element.querySelectorAll(".av__cell--active").forEach((item: HTMLElement) => {
if (getTypeByCellElement(item) === "mAsset") {
cellElements.push(item);
}
})
if (cellElements.length > 0) {
const blockElement = hasClosestBlock(cellElements[0]);
if (blockElement) {
updateCellsValue(protyle, blockElement, avAssets, cellElements);
document.querySelector(".av__panel")?.remove();
return;
}
} else {
return;
}
}
// 避免插入代码块中,其次因为都要独立成块 https://github.com/siyuan-note/siyuan/issues/7607