Vanessa 2026-02-01 17:37:57 +08:00
parent e385f9cc53
commit 872191d078
7 changed files with 47 additions and 19 deletions

View file

@ -12,8 +12,11 @@ import {openBy} from "../editor/util";
import {renderAssetsPreview} from "../asset/renderAssets";
import {writeText} from "../protyle/util/compatibility";
import {Constants} from "../constants";
import {avRender} from "../protyle/render/av/render";
import {showMessage} from "../dialog/message";
import {Protyle} from "../protyle";
import {App} from "../index";
import {disabledProtyle, onGet} from "../protyle/util/onGet";
import {removeLoading} from "../protyle/ui/initUI";
export const image = {
element: undefined as Element,
@ -78,9 +81,22 @@ export const image = {
</div>
</div>`;
},
bindEvent: () => {
bindEvent: (app: App) => {
const assetsListElement = image.element.querySelector('.config-assets[data-type="remove"] .config-assets__list');
const avListElement = image.element.querySelector('.config-assets[data-type="removeAV"] .config-assets__list');
const editor = new Protyle(app, avListElement.nextElementSibling as HTMLElement, {
blockId: "",
action: [Constants.CB_GET_HISTORY],
render: {
background: false,
gutter: false,
breadcrumb: false,
breadcrumbDocName: false,
},
typewriterMode: false,
});
disabledProtyle(editor.protyle);
removeLoading(editor.protyle);
image.element.addEventListener("click", (event) => {
let target = event.target as HTMLElement;
while (target && !target.isEqualNode(image.element)) {
@ -138,14 +154,25 @@ export const image = {
event.stopPropagation();
break;
} else if (target.getAttribute("data-tab-type") === "unRefAV") {
avListElement.nextElementSibling.innerHTML = `<div data-node-id="${Lute.NewNodeID()}" data-av-id="${target.dataset.item}" data-type="NodeAttributeView" data-av-type="table"><div spellcheck="true"></div><div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div></div>`;
avRender(avListElement.nextElementSibling.firstElementChild, null);
onGet({
data: {
data: {
content: `<div class="av" data-node-id="${Lute.NewNodeID()}" data-av-id="${target.dataset.item}" data-type="NodeAttributeView" data-av-type="table"><div spellcheck="true"></div><div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div></div>`,
id: Lute.NewNodeID(),
rootID: Lute.NewNodeID(),
},
msg: "",
code: 0
},
protyle: editor.protyle,
action: [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML],
});
event.preventDefault();
event.stopPropagation();
break;
} else if (type === "copy") {
if (target.parentElement.getAttribute("data-tab-type") === "unRefAV") {
writeText(`<div data-node-id="${Lute.NewNodeID()}" data-av-id="${target.parentElement.dataset.item}" data-type="NodeAttributeView" data-av-type="table"></div>`);
writeText(`<div class="av" data-node-id="${Lute.NewNodeID()}" data-av-id="${target.parentElement.dataset.item}" data-type="NodeAttributeView" data-av-type="table"></div>`);
} else {
writeText(target.parentElement.querySelector(".b3-list-item__text").textContent.trim());
}

View file

@ -43,7 +43,7 @@ export const genItemPanel = (type: string, containerElement: Element, app: App)
case "image":
containerElement.innerHTML = image.genHTML();
image.element = containerElement;
image.bindEvent();
image.bindEvent(app);
break;
case "export":
containerElement.innerHTML = exportConfig.genHTML();

View file

@ -753,7 +753,7 @@ const bindEvent = (app: App, element: Element, dialog?: Dialog) => {
onGet({
data: {
data: {
content: `<div data-node-id="${Lute.NewNodeID()}" data-av-id="${target.querySelector(".b3-list-item__text").textContent}" data-type="NodeAttributeView" data-av-type="table"><div spellcheck="true"></div><div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div></div>`,
content: `<div class="av" data-node-id="${Lute.NewNodeID()}" data-av-id="${target.querySelector(".b3-list-item__text").textContent}" data-type="NodeAttributeView" data-av-type="table"><div spellcheck="true"></div><div class="protyle-attr" contenteditable="false">${Constants.ZWSP}</div></div>`,
id: Lute.NewNodeID(),
rootID: Lute.NewNodeID(),
},

View file

@ -1,6 +1,6 @@
import {popSearch} from "./search";
import {initAppearance} from "../settings/appearance";
import {initAssets} from "../settings/assets";
import {initConfigAssets} from "../settings/assets";
import {closePanel} from "../util/closePanel";
import {mountHelp, newDailyNote, newNotebook} from "../../util/mount";
import {repos} from "../../config/repos";
@ -178,7 +178,7 @@ export const initRightMenu = (app: App) => {
event.stopPropagation();
break;
} else if (target.id === "menuAssets") {
initAssets();
initConfigAssets(app);
event.preventDefault();
event.stopPropagation();
break;

View file

@ -1,14 +1,15 @@
import {openModel} from "../menu/model";
import {image} from "../../config/image";
import {App} from "../../index";
export const initAssets = () => {
export const initConfigAssets = (app: App) => {
openModel({
title: window.siyuan.languages.assets,
icon: "iconImage",
html: image.genHTML(),
bindEvent(modelMainElement: HTMLElement) {
image.element = modelMainElement.firstElementChild;
image.bindEvent();
image.bindEvent(app);
}
});
};

View file

@ -864,7 +864,7 @@ export const duplicateCompletely = (protyle: IProtyle, nodeElement: HTMLElement)
fetchPost("/api/av/duplicateAttributeViewBlock", {avID: nodeElement.getAttribute("data-av-id")}, (response) => {
nodeElement.classList.remove("protyle-wysiwyg--select");
const tempElement = document.createElement("template");
tempElement.innerHTML = protyle.lute.SpinBlockDOM(`<div data-node-id="${response.data.blockID}" data-av-id="${response.data.avID}" data-type="NodeAttributeView" data-av-type="table"></div>`);
tempElement.innerHTML = protyle.lute.SpinBlockDOM(`<div class="av" data-node-id="${response.data.blockID}" data-av-id="${response.data.avID}" data-type="NodeAttributeView" data-av-type="table"></div>`);
const cloneElement = tempElement.content.firstElementChild;
nodeElement.after(cloneElement);
avRender(cloneElement, protyle, () => {

View file

@ -270,7 +270,7 @@ const renderGroupTable = (options: ITableOptions) => {
});
if (options.renderAll) {
options.blockElement.firstElementChild.outerHTML = `<div class="av__container">
${genTabHeaderHTML(options.data, isSearching || !!query, options.protyle ? (!options.protyle.disabled && !hasClosestByAttribute(options.blockElement, "data-type", "NodeBlockQueryEmbed")) : false)}
${genTabHeaderHTML(options.data, isSearching || !!query, !options.protyle.disabled && !hasClosestByAttribute(options.blockElement, "data-type", "NodeBlockQueryEmbed"))}
<div class="av__scroll">
${avBodyHTML}
</div>
@ -290,13 +290,13 @@ const afterRenderTable = (options: ITableOptions) => {
options.blockElement.setAttribute("data-render", "true");
options.blockElement.querySelector(".av__scroll").scrollLeft = options.resetData.left;
options.blockElement.style.alignSelf = options.resetData.alignSelf;
const editRect = options.protyle ? options.protyle.contentElement.getBoundingClientRect() : null;
const editRect = options.protyle.contentElement.getBoundingClientRect();
if (options.resetData.headerTransform) {
const headerTransformElement = options.blockElement.querySelector(`.av__body[data-group-id="${options.resetData.headerTransform.groupId}"] .av__row--header`) as HTMLElement;
if (headerTransformElement) {
headerTransformElement.style.transform = options.resetData.headerTransform.transform;
}
} else if (editRect && options.protyle && !options.protyle.options.action.includes(Constants.CB_GET_HISTORY)) {
} else if (editRect && !options.protyle.options.action.includes(Constants.CB_GET_HISTORY)) {
// 需等待渲染完,否则 getBoundingClientRect 错误 https://github.com/siyuan-note/siyuan/issues/13787
setTimeout(() => {
stickyRow(options.blockElement, editRect, "top");
@ -307,7 +307,7 @@ const afterRenderTable = (options: ITableOptions) => {
if (footerTransformElement) {
footerTransformElement.style.transform = options.resetData.footerTransform.transform;
}
} else if (editRect && options.protyle && !options.protyle.options.action.includes(Constants.CB_GET_HISTORY)) {
} else if (editRect && !options.protyle.options.action.includes(Constants.CB_GET_HISTORY)) {
// 需等待渲染完,否则 getBoundingClientRect 错误 https://github.com/siyuan-note/siyuan/issues/13787
setTimeout(() => {
stickyRow(options.blockElement, editRect, "bottom");
@ -552,8 +552,8 @@ export const avRender = async (element: Element, protyle: IProtyle, cb?: (data:
const avPageSize = getPageSize(e);
let data: IAV;
if (!avData) {
const created = protyle ? protyle.options.history?.created : false;
const snapshot = protyle ? protyle.options.history?.snapshot : false;
const created = protyle.options.history?.created;
const snapshot = protyle.options.history?.snapshot;
const response = await fetchSyncPost(created ? "/api/av/renderHistoryAttributeView" : (snapshot ? "/api/av/renderSnapshotAttributeView" : "/api/av/renderAttributeView"), {
id: e.getAttribute("data-av-id"),
created,
@ -588,7 +588,7 @@ export const avRender = async (element: Element, protyle: IProtyle, cb?: (data:
</div>`;
if (renderAll) {
e.firstElementChild.outerHTML = `<div class="av__container">
${genTabHeaderHTML(data, resetData.isSearching || !!resetData.query, protyle ? (!protyle.disabled && !hasClosestByAttribute(e, "data-type", "NodeBlockQueryEmbed")) : false)}
${genTabHeaderHTML(data, resetData.isSearching || !!resetData.query, !protyle.disabled && !hasClosestByAttribute(e, "data-type", "NodeBlockQueryEmbed"))}
<div class="av__scroll">
${avBodyHTML}
</div>