drag thumbs
This commit is contained in:
@@ -145,6 +145,25 @@ const DocumentThumbnailImage = ({
|
|||||||
innerClasses.push('document-thumbnail-inner--multipage');
|
innerClasses.push('document-thumbnail-inner--multipage');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const aspectRatio = useMemo(() => {
|
||||||
|
if (Number.isFinite(assetWidth) && Number.isFinite(assetHeight) && assetWidth > 0 && assetHeight > 0) {
|
||||||
|
return assetWidth / assetHeight;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}, [assetWidth, assetHeight]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const node = visibilityRef.current;
|
||||||
|
if (!node) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (aspectRatio) {
|
||||||
|
node.dataset.thumbnailAspect = String(aspectRatio);
|
||||||
|
} else {
|
||||||
|
delete node.dataset.thumbnailAspect;
|
||||||
|
}
|
||||||
|
}, [aspectRatio]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="document-thumbnail-wrapper" ref={visibilityRef}>
|
<div className="document-thumbnail-wrapper" ref={visibilityRef}>
|
||||||
<div className={innerClasses.join(' ')} style={innerStyle}>
|
<div className={innerClasses.join(' ')} style={innerStyle}>
|
||||||
|
|||||||
+23
-9
@@ -2765,18 +2765,32 @@ const AppLayout = () => {
|
|||||||
: null;
|
: null;
|
||||||
const thumbnailEl = rowEl?.querySelector('.document-thumbnail');
|
const thumbnailEl = rowEl?.querySelector('.document-thumbnail');
|
||||||
const placeholderEl = rowEl?.querySelector('.thumb-placeholder');
|
const placeholderEl = rowEl?.querySelector('.thumb-placeholder');
|
||||||
|
const wrapperEl = rowEl?.querySelector('.document-thumbnail-wrapper');
|
||||||
|
const aspectAttr = wrapperEl?.dataset?.thumbnailAspect;
|
||||||
|
const aspectRatio = aspectAttr ? parseFloat(aspectAttr) : null;
|
||||||
|
|
||||||
let content = null;
|
let thumbWidth = size;
|
||||||
if (thumbnailEl instanceof HTMLImageElement) {
|
let thumbHeight = size;
|
||||||
content = thumbnailEl.cloneNode(true);
|
if (Number.isFinite(aspectRatio) && aspectRatio > 0) {
|
||||||
content.draggable = false;
|
if (aspectRatio >= 1) {
|
||||||
content.style.pointerEvents = 'none';
|
thumbWidth = size;
|
||||||
} else if (placeholderEl instanceof HTMLElement) {
|
thumbHeight = Math.max(size / aspectRatio, size * 0.5);
|
||||||
content = placeholderEl.cloneNode(true);
|
} else {
|
||||||
content.style.pointerEvents = 'none';
|
thumbHeight = size;
|
||||||
|
thumbWidth = Math.max(size * aspectRatio, size * 0.5);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
layer.style.width = `${Math.round(thumbWidth)}px`;
|
||||||
|
layer.style.height = `${Math.round(thumbHeight)}px`;
|
||||||
|
|
||||||
if (content) {
|
const thumbSrc = thumbnailEl?.currentSrc || thumbnailEl?.src || null;
|
||||||
|
|
||||||
|
if (thumbSrc) {
|
||||||
|
layer.classList.add('document-drag-preview__thumb--image');
|
||||||
|
layer.style.backgroundImage = `url("${thumbSrc}")`;
|
||||||
|
} else if (placeholderEl instanceof HTMLElement) {
|
||||||
|
const content = placeholderEl.cloneNode(true);
|
||||||
|
content.style.pointerEvents = 'none';
|
||||||
layer.appendChild(content);
|
layer.appendChild(content);
|
||||||
} else {
|
} else {
|
||||||
layer.textContent = 'DOC';
|
layer.textContent = 'DOC';
|
||||||
|
|||||||
@@ -598,6 +598,13 @@ button.danger:hover:not([disabled]) {
|
|||||||
transform-origin: center;
|
transform-origin: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.document-drag-preview__thumb--image {
|
||||||
|
background-color: #000;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-size: contain;
|
||||||
|
background-position: center;
|
||||||
|
}
|
||||||
|
|
||||||
.document-drag-preview__thumb .document-thumbnail,
|
.document-drag-preview__thumb .document-thumbnail,
|
||||||
.document-drag-preview__thumb img {
|
.document-drag-preview__thumb img {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
Reference in New Issue
Block a user