Vanessa 2025-06-17 19:14:00 +08:00
parent 3a991f8075
commit 06abf29c27
6 changed files with 81 additions and 13 deletions

View file

@ -61,16 +61,17 @@ export const renderGallery = (options: {
view.cards.forEach((item: IAVGalleryItem, rowIndex: number) => { view.cards.forEach((item: IAVGalleryItem, rowIndex: number) => {
galleryHTML += `<div data-id="${item.id}" class="av__gallery-item${selectItemIds.includes(item.id) ? " av__gallery-item--select" : ""}">`; galleryHTML += `<div data-id="${item.id}" class="av__gallery-item${selectItemIds.includes(item.id) ? " av__gallery-item--select" : ""}">`;
if (view.coverFrom !== 0) { if (view.coverFrom !== 0) {
const coverClass= "av__gallery-cover av__gallery-cover--" + view.cardAspectRatio
if (item.coverURL) { if (item.coverURL) {
if (item.coverURL.startsWith("background")) { if (item.coverURL.startsWith("background")) {
galleryHTML += `<div class="av__gallery-cover"><div class="av__gallery-img${view.fitImage ? " av__gallery-img--fit" : ""}" style="${item.coverURL}"></div></div>`; galleryHTML += `<div class="${coverClass}"><div class="av__gallery-img${view.fitImage ? " av__gallery-img--fit" : ""}" style="${item.coverURL}"></div></div>`;
} else { } else {
galleryHTML += `<div class="av__gallery-cover"><div class="av__gallery-img${view.fitImage ? " av__gallery-img--fit" : ""}" style="background-image:url('${item.coverURL}')"></div></div>`; galleryHTML += `<div class="${coverClass}"><div class="av__gallery-img${view.fitImage ? " av__gallery-img--fit" : ""}" style="background-image:url('${item.coverURL}')"></div></div>`;
} }
} else if (item.coverContent) { } else if (item.coverContent) {
galleryHTML += `<div class="av__gallery-cover"><div class="av__gallery-content">${item.coverContent}</div><div></div></div>`; galleryHTML += `<div class="${coverClass}"><div class="av__gallery-content">${item.coverContent}</div><div></div></div>`;
} else { } else {
galleryHTML += '<div class="av__gallery-cover"></div>'; galleryHTML += '<div class="${coverClass}"></div>';
} }
} }
galleryHTML += `<div class="av__gallery-fields${editIds.includes(item.id) ? " av__gallery-fields--edit" : ""}${view.wrapField ? " av__gallery-fields--wrap" : ""}">`; galleryHTML += `<div class="av__gallery-fields${editIds.includes(item.id) ? " av__gallery-fields--edit" : ""}${view.wrapField ? " av__gallery-fields--wrap" : ""}">`;

View file

@ -102,7 +102,6 @@ export const setGallerySize = (options: {
const menu = new Menu(); const menu = new Menu();
const avID = options.nodeElement.getAttribute("data-av-id"); const avID = options.nodeElement.getAttribute("data-av-id");
const blockID = options.nodeElement.getAttribute("data-node-id"); const blockID = options.nodeElement.getAttribute("data-node-id");
const galleryElement = options.nodeElement.querySelector(".av__gallery");
const targetNameElement = options.target.querySelector(".b3-menu__accelerator"); const targetNameElement = options.target.querySelector(".b3-menu__accelerator");
menu.addItem({ menu.addItem({
iconHTML: "", iconHTML: "",
@ -121,8 +120,6 @@ export const setGallerySize = (options: {
data: options.view.cardSize data: options.view.cardSize
}]); }]);
options.view.cardSize = 0; options.view.cardSize = 0;
galleryElement.classList.add("av__gallery--small");
galleryElement.classList.remove("av__gallery--big");
targetNameElement.textContent = window.siyuan.languages.small; targetNameElement.textContent = window.siyuan.languages.small;
} }
}); });
@ -143,7 +140,6 @@ export const setGallerySize = (options: {
data: options.view.cardSize data: options.view.cardSize
}]); }]);
options.view.cardSize = 1; options.view.cardSize = 1;
galleryElement.classList.remove("av__gallery--big", "av__gallery--small");
targetNameElement.textContent = window.siyuan.languages.medium; targetNameElement.textContent = window.siyuan.languages.medium;
} }
}); });
@ -164,8 +160,6 @@ export const setGallerySize = (options: {
data: options.view.cardSize data: options.view.cardSize
}]); }]);
options.view.cardSize = 2; options.view.cardSize = 2;
galleryElement.classList.remove("av__gallery--small");
galleryElement.classList.add("av__gallery--big");
targetNameElement.textContent = window.siyuan.languages.large; targetNameElement.textContent = window.siyuan.languages.large;
} }
}); });
@ -173,6 +167,60 @@ export const setGallerySize = (options: {
menu.open({x: rect.left, y: rect.bottom}); menu.open({x: rect.left, y: rect.bottom});
}; };
export const getCardAspectRatio = (ratio: number) => {
switch (ratio) {
case 0:
return "16:9";
case 1:
return "9:16";
case 2:
return "4:3";
case 3:
return "3:4";
case 4:
return "3:2";
case 5:
return "3:2";
case 6:
return "1:1";
}
return "16:9";
};
export const setGalleryRatio = (options: {
view: IAVGallery
nodeElement: Element,
protyle: IProtyle,
target: HTMLElement
}) => {
const menu = new Menu();
const avID = options.nodeElement.getAttribute("data-av-id");
const blockID = options.nodeElement.getAttribute("data-node-id");
const targetNameElement = options.target.querySelector(".b3-menu__accelerator");
menu.addItem({
iconHTML: "",
checked: options.view.cardAspectRatio === 0,
label: "16:9",
click() {
transaction(options.protyle, [{
action: "setAttrViewCardAspectRatio",
avID,
blockID,
data: 0
}], [{
action: "setAttrViewCardAspectRatio",
avID,
blockID,
data: options.view.cardSize
}]);
options.view.cardAspectRatio = 0;
targetNameElement.textContent = getCardAspectRatio(0);
}
});
const rect = options.target.getBoundingClientRect();
menu.open({x: rect.left, y: rect.bottom});
};
export const openGalleryItemMenu = (options: { export const openGalleryItemMenu = (options: {
target: HTMLElement, target: HTMLElement,
blockElement: HTMLElement, blockElement: HTMLElement,

View file

@ -1,6 +1,7 @@
import {transaction} from "../../wysiwyg/transaction"; import {transaction} from "../../wysiwyg/transaction";
import {Constants} from "../../../constants"; import {Constants} from "../../../constants";
import {fetchPost} from "../../../util/fetch"; import {fetchPost} from "../../../util/fetch";
import {getCardAspectRatio} from "./gallery/util";
export const getLayoutHTML = (data: IAV) => { export const getLayoutHTML = (data: IAV) => {
let html = ""; let html = "";
@ -31,6 +32,12 @@ export const getLayoutHTML = (data: IAV) => {
<span class="b3-menu__accelerator">${view.cardSize === 0 ? window.siyuan.languages.small : (view.cardSize === 1 ? window.siyuan.languages.medium : window.siyuan.languages.large)}</span> <span class="b3-menu__accelerator">${view.cardSize === 0 ? window.siyuan.languages.small : (view.cardSize === 1 ? window.siyuan.languages.medium : window.siyuan.languages.large)}</span>
<svg class="b3-menu__icon b3-menu__icon--small"><use xlink:href="#iconRight"></use></svg> <svg class="b3-menu__icon b3-menu__icon--small"><use xlink:href="#iconRight"></use></svg>
</button> </button>
<button class="b3-menu__item" data-type="set-gallery-ratio">
<span class="fn__flex-center">${window.siyuan.languages.cardAspectRatio}</span>
<span class="fn__flex-1"></span>
<span class="b3-menu__accelerator">${getCardAspectRatio(view.cardAspectRatio)}</span>
<svg class="b3-menu__icon b3-menu__icon--small"><use xlink:href="#iconRight"></use></svg>
</button>
<label class="b3-menu__item"> <label class="b3-menu__item">
<span class="fn__flex-center">${window.siyuan.languages.fitImage}</span> <span class="fn__flex-center">${window.siyuan.languages.fitImage}</span>
<span class="fn__space fn__flex-1"></span> <span class="fn__space fn__flex-1"></span>

View file

@ -46,7 +46,7 @@ import {openCalcMenu} from "./calc";
import {escapeAttr, escapeHtml} from "../../../util/escape"; import {escapeAttr, escapeHtml} from "../../../util/escape";
import {Dialog} from "../../../dialog"; import {Dialog} from "../../../dialog";
import {bindLayoutEvent, getLayoutHTML, updateLayout} from "./layout"; import {bindLayoutEvent, getLayoutHTML, updateLayout} from "./layout";
import {setGalleryCover, setGallerySize} from "./gallery/util"; import {setGalleryCover, setGalleryRatio, setGallerySize} from "./gallery/util";
export const openMenuPanel = (options: { export const openMenuPanel = (options: {
protyle: IProtyle, protyle: IProtyle,
@ -1394,6 +1394,16 @@ export const openMenuPanel = (options: {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
break; break;
} else if (type === "set-gallery-ratio") {
setGalleryRatio({
target,
protyle: options.protyle,
nodeElement: options.blockElement,
view: data.view as IAVGallery
});
event.preventDefault();
event.stopPropagation();
break;
} else if (type === "set-layout") { } else if (type === "set-layout") {
updateLayout({ updateLayout({
target, target,

View file

@ -854,7 +854,7 @@ export const onTransaction = (protyle: IProtyle, operation: IOperation, isUndo:
"removeAttrViewView", "setAttrViewViewName", "setAttrViewViewIcon", "duplicateAttrViewView", "sortAttrViewView", "removeAttrViewView", "setAttrViewViewName", "setAttrViewViewIcon", "duplicateAttrViewView", "sortAttrViewView",
"updateAttrViewColRelation", "setAttrViewPageSize", "updateAttrViewColRollup", "sortAttrViewKey", "setAttrViewColDesc", "updateAttrViewColRelation", "setAttrViewPageSize", "updateAttrViewColRollup", "sortAttrViewKey", "setAttrViewColDesc",
"duplicateAttrViewKey", "setAttrViewViewDesc", "setAttrViewCoverFrom", "setAttrViewCoverFromAssetKeyID", "duplicateAttrViewKey", "setAttrViewViewDesc", "setAttrViewCoverFrom", "setAttrViewCoverFromAssetKeyID",
"setAttrViewBlockView"].includes(operation.action)) { "setAttrViewBlockView", "setAttrViewCardSize"].includes(operation.action)) {
if (!isUndo) { if (!isUndo) {
// 撤销 transaction 会进行推送,需使用推送来进行刷新最新数据 https://github.com/siyuan-note/siyuan/issues/13607 // 撤销 transaction 会进行推送,需使用推送来进行刷新最新数据 https://github.com/siyuan-note/siyuan/issues/13607
refreshAV(protyle, operation); refreshAV(protyle, operation);

View file

@ -52,6 +52,7 @@ type TOperation =
| "updateAttrViewColRollup" | "updateAttrViewColRollup"
| "hideAttrViewName" | "hideAttrViewName"
| "setAttrViewCardSize" | "setAttrViewCardSize"
| "setAttrViewCardAspectRatio"
| "setAttrViewCoverFrom" | "setAttrViewCoverFrom"
| "setAttrViewCoverFromAssetKeyID" | "setAttrViewCoverFromAssetKeyID"
| "setAttrViewFitImage" | "setAttrViewFitImage"
@ -850,6 +851,7 @@ interface IAVGallery extends IAVView {
coverFrom: number; // 01内容图2资源字段 coverFrom: number; // 01内容图2资源字段
coverFromAssetKeyID?: string; coverFromAssetKeyID?: string;
cardSize: number; // 0小卡片1中卡片2大卡片 cardSize: number; // 0小卡片1中卡片2大卡片
cardAspectRatio: number;
fitImage: boolean; fitImage: boolean;
showIcon: boolean; showIcon: boolean;
wrapField: boolean; wrapField: boolean;