2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2024-02-11 08:10:29 +00:00
|
|
|
<span :class="containerClass" :style="style" v-bind="ptmi('root')">
|
2023-10-31 17:21:47 +00:00
|
|
|
<slot name="image" :onError="onError" :errorCallback="onError">
|
2023-06-07 10:46:13 +00:00
|
|
|
<img :style="imageStyle" :class="[cx('image'), imageClass]" @error="onError" v-bind="{ ...$attrs, ...ptm('image') }" />
|
2023-05-03 17:54:50 +00:00
|
|
|
</slot>
|
2023-11-30 13:57:55 +00:00
|
|
|
<button v-if="preview" ref="previewButton" :aria-label="zoomImageAriaLabel" type="button" :class="cx('button')" @click="onImageClick" v-bind="{ ...previewButtonProps, ...ptm('button') }">
|
2023-04-18 09:31:46 +00:00
|
|
|
<slot name="indicatoricon">
|
2023-05-31 08:00:55 +00:00
|
|
|
<component :is="indicatorIcon ? 'i' : 'EyeIcon'" :class="cx('icon')" v-bind="ptm('icon')" />
|
2022-09-06 12:03:37 +00:00
|
|
|
</slot>
|
2022-12-08 11:04:25 +00:00
|
|
|
</button>
|
2022-09-06 12:03:37 +00:00
|
|
|
<Portal>
|
2023-05-31 08:00:55 +00:00
|
|
|
<div v-if="maskVisible" :ref="maskRef" v-focustrap role="dialog" :class="cx('mask')" :aria-modal="maskVisible" @click="onMaskClick" @keydown="onMaskKeydown" v-bind="ptm('mask')">
|
2023-10-05 07:08:28 +00:00
|
|
|
<div :class="cx('toolbar')" v-bind="ptm('toolbar')">
|
2023-08-14 11:21:46 +00:00
|
|
|
<button :class="cx('rotateRightButton')" @click="rotateRight" type="button" :aria-label="rightAriaLabel" v-bind="ptm('rotateRightButton')" data-pc-group-section="action">
|
2023-03-22 13:40:31 +00:00
|
|
|
<slot name="refresh">
|
2023-05-04 07:45:01 +00:00
|
|
|
<RefreshIcon v-bind="ptm('rotateRightIcon')" />
|
2023-03-22 13:40:31 +00:00
|
|
|
</slot>
|
2022-09-06 12:03:37 +00:00
|
|
|
</button>
|
2023-03-22 13:40:31 +00:00
|
|
|
|
2023-08-14 11:21:46 +00:00
|
|
|
<button :class="cx('rotateLeftButton')" @click="rotateLeft" type="button" :aria-label="leftAriaLabel" v-bind="ptm('rotateLeftButton')" data-pc-group-section="action">
|
2023-03-22 13:40:31 +00:00
|
|
|
<slot name="undo">
|
2023-05-04 07:45:01 +00:00
|
|
|
<UndoIcon v-bind="ptm('rotateLeftIcon')" />
|
2023-03-22 13:40:31 +00:00
|
|
|
</slot>
|
2022-09-06 12:03:37 +00:00
|
|
|
</button>
|
2023-03-22 13:40:31 +00:00
|
|
|
|
2023-08-14 11:21:46 +00:00
|
|
|
<button :class="cx('zoomOutButton')" @click="zoomOut" type="button" :disabled="isZoomOutDisabled" :aria-label="zoomOutAriaLabel" v-bind="ptm('zoomOutButton')" data-pc-group-section="action">
|
2023-03-22 13:40:31 +00:00
|
|
|
<slot name="zoomout">
|
2023-05-04 07:45:01 +00:00
|
|
|
<SearchMinusIcon v-bind="ptm('zoomOutIcon')" />
|
2023-03-22 13:40:31 +00:00
|
|
|
</slot>
|
2022-09-06 12:03:37 +00:00
|
|
|
</button>
|
2023-03-22 13:40:31 +00:00
|
|
|
|
2023-08-14 11:21:46 +00:00
|
|
|
<button :class="cx('zoomInButton')" @click="zoomIn" type="button" :disabled="isZoomInDisabled" :aria-label="zoomInAriaLabel" v-bind="ptm('zoomInButton')" data-pc-group-section="action">
|
2023-03-22 13:40:31 +00:00
|
|
|
<slot name="zoomin">
|
2023-05-04 07:45:01 +00:00
|
|
|
<SearchPlusIcon v-bind="ptm('zoomInIcon')" />
|
2023-03-22 13:40:31 +00:00
|
|
|
</slot>
|
2022-09-06 12:03:37 +00:00
|
|
|
</button>
|
2023-03-22 13:40:31 +00:00
|
|
|
|
2023-08-14 11:21:46 +00:00
|
|
|
<button :class="cx('closeButton')" type="button" @click="hidePreview" :aria-label="closeAriaLabel" autofocus v-bind="ptm('closeButton')" data-pc-group-section="action">
|
2023-03-22 13:40:31 +00:00
|
|
|
<slot name="close">
|
2023-05-04 07:45:01 +00:00
|
|
|
<TimesIcon v-bind="ptm('closeIcon')" />
|
2023-03-22 13:40:31 +00:00
|
|
|
</slot>
|
2022-09-06 12:03:37 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
2024-04-10 06:16:00 +00:00
|
|
|
<transition name="p-image-original" @before-enter="onBeforeEnter" @enter="onEnter" @leave="onLeave" @before-leave="onBeforeLeave" @after-leave="onAfterLeave" v-bind="ptm('transition')">
|
2023-05-04 07:45:01 +00:00
|
|
|
<div v-if="previewVisible" v-bind="ptm('previewContainer')">
|
2023-10-31 17:21:47 +00:00
|
|
|
<slot name="preview" :class="cx('preview')" :style="imagePreviewStyle" :onClick="onPreviewImageClick" :previewCallback="onPreviewImageClick">
|
2023-05-31 08:00:55 +00:00
|
|
|
<img :src="$attrs.src" :class="cx('preview')" :style="imagePreviewStyle" @click="onPreviewImageClick" v-bind="ptm('preview')" />
|
2023-04-29 18:43:56 +00:00
|
|
|
</slot>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</div>
|
|
|
|
</Portal>
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-12-08 11:04:25 +00:00
|
|
|
import FocusTrap from 'primevue/focustrap';
|
2023-04-18 12:53:43 +00:00
|
|
|
import EyeIcon from 'primevue/icons/eye';
|
|
|
|
import RefreshIcon from 'primevue/icons/refresh';
|
|
|
|
import SearchMinusIcon from 'primevue/icons/searchminus';
|
|
|
|
import SearchPlusIcon from 'primevue/icons/searchplus';
|
|
|
|
import TimesIcon from 'primevue/icons/times';
|
|
|
|
import UndoIcon from 'primevue/icons/undo';
|
2022-09-06 12:03:37 +00:00
|
|
|
import Portal from 'primevue/portal';
|
2022-12-08 11:04:25 +00:00
|
|
|
import { DomHandler, ZIndexUtils } from 'primevue/utils';
|
2023-06-09 10:28:10 +00:00
|
|
|
import BaseImage from './BaseImage.vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Image',
|
2023-05-31 08:00:55 +00:00
|
|
|
extends: BaseImage,
|
2022-09-06 12:03:37 +00:00
|
|
|
inheritAttrs: false,
|
|
|
|
emits: ['show', 'hide', 'error'],
|
|
|
|
mask: null,
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
maskVisible: false,
|
|
|
|
previewVisible: false,
|
|
|
|
rotate: 0,
|
|
|
|
scale: 1
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
beforeUnmount() {
|
|
|
|
if (this.mask) {
|
|
|
|
ZIndexUtils.clear(this.container);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
maskRef(el) {
|
|
|
|
this.mask = el;
|
|
|
|
},
|
|
|
|
toolbarRef(el) {
|
|
|
|
this.toolbarRef = el;
|
|
|
|
},
|
|
|
|
onImageClick() {
|
|
|
|
if (this.preview) {
|
2023-10-10 22:36:20 +00:00
|
|
|
DomHandler.blockBodyScroll();
|
2022-09-06 12:03:37 +00:00
|
|
|
this.maskVisible = true;
|
|
|
|
setTimeout(() => {
|
|
|
|
this.previewVisible = true;
|
|
|
|
}, 25);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onPreviewImageClick() {
|
|
|
|
this.previewClick = true;
|
|
|
|
},
|
2023-04-10 10:35:15 +00:00
|
|
|
onMaskClick(event) {
|
2023-12-20 11:44:46 +00:00
|
|
|
const isBarActionsClicked = DomHandler.isAttributeEquals(event.target, 'data-pc-section-group', 'action') || event.target.closest('[data-pc-section-group="action"]');
|
2023-04-10 10:35:15 +00:00
|
|
|
|
2023-12-20 11:44:46 +00:00
|
|
|
if (!this.previewClick && !isBarActionsClicked) {
|
2022-09-06 12:03:37 +00:00
|
|
|
this.previewVisible = false;
|
|
|
|
this.rotate = 0;
|
|
|
|
this.scale = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.previewClick = false;
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
onMaskKeydown(event) {
|
|
|
|
switch (event.code) {
|
|
|
|
case 'Escape':
|
2023-07-01 17:40:49 +00:00
|
|
|
this.hidePreview();
|
2022-12-08 11:04:25 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
DomHandler.focus(this.$refs.previewButton);
|
2023-07-21 13:46:16 +00:00
|
|
|
}, 200);
|
2022-12-08 11:04:25 +00:00
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
onError() {
|
|
|
|
this.$emit('error');
|
|
|
|
},
|
|
|
|
rotateRight() {
|
|
|
|
this.rotate += 90;
|
|
|
|
this.previewClick = true;
|
|
|
|
},
|
|
|
|
rotateLeft() {
|
|
|
|
this.rotate -= 90;
|
|
|
|
this.previewClick = true;
|
|
|
|
},
|
|
|
|
zoomIn() {
|
|
|
|
this.scale = this.scale + 0.1;
|
|
|
|
this.previewClick = true;
|
|
|
|
},
|
|
|
|
zoomOut() {
|
|
|
|
this.scale = this.scale - 0.1;
|
|
|
|
this.previewClick = true;
|
|
|
|
},
|
|
|
|
onBeforeEnter() {
|
|
|
|
ZIndexUtils.set('modal', this.mask, this.$primevue.config.zIndex.modal);
|
|
|
|
},
|
|
|
|
onEnter() {
|
2022-12-08 11:04:25 +00:00
|
|
|
this.focus();
|
2022-09-06 12:03:37 +00:00
|
|
|
this.$emit('show');
|
|
|
|
},
|
|
|
|
onBeforeLeave() {
|
2023-05-31 08:00:55 +00:00
|
|
|
!this.isUnstyled && DomHandler.addClass(this.mask, 'p-component-overlay-leave');
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
onLeave() {
|
2023-10-10 22:36:20 +00:00
|
|
|
DomHandler.unblockBodyScroll();
|
2022-09-06 12:03:37 +00:00
|
|
|
this.$emit('hide');
|
|
|
|
},
|
|
|
|
onAfterLeave(el) {
|
|
|
|
ZIndexUtils.clear(el);
|
|
|
|
this.maskVisible = false;
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
focus() {
|
|
|
|
let focusTarget = this.mask.querySelector('[autofocus]');
|
|
|
|
|
|
|
|
if (focusTarget) {
|
|
|
|
focusTarget.focus();
|
|
|
|
}
|
2023-04-10 10:35:15 +00:00
|
|
|
},
|
|
|
|
hidePreview() {
|
|
|
|
this.previewVisible = false;
|
|
|
|
this.rotate = 0;
|
|
|
|
this.scale = 1;
|
2023-10-10 22:36:20 +00:00
|
|
|
DomHandler.unblockBodyScroll();
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
containerClass() {
|
2023-06-09 10:28:10 +00:00
|
|
|
return [this.cx('root'), this.class];
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
rotateClass() {
|
|
|
|
return 'p-image-preview-rotate-' + this.rotate;
|
|
|
|
},
|
|
|
|
imagePreviewStyle() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return { transform: 'rotate(' + this.rotate + 'deg) scale(' + this.scale + ')' };
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2023-04-10 10:35:15 +00:00
|
|
|
isZoomInDisabled() {
|
|
|
|
return this.zoomInDisabled || this.scale >= 1.5;
|
|
|
|
},
|
|
|
|
isZoomOutDisabled() {
|
|
|
|
return this.zoomOutDisabled || this.scale <= 0.5;
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
rightAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.rotateRight : undefined;
|
|
|
|
},
|
|
|
|
leftAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.rotateLeft : undefined;
|
|
|
|
},
|
|
|
|
zoomInAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.zoomIn : undefined;
|
|
|
|
},
|
|
|
|
zoomOutAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.zoomOut : undefined;
|
|
|
|
},
|
2023-11-30 13:57:55 +00:00
|
|
|
zoomImageAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.zoomImage : undefined;
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
closeAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.close : undefined;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
2023-04-06 08:21:43 +00:00
|
|
|
Portal: Portal,
|
|
|
|
EyeIcon: EyeIcon,
|
|
|
|
RefreshIcon: RefreshIcon,
|
|
|
|
UndoIcon: UndoIcon,
|
|
|
|
SearchMinusIcon: SearchMinusIcon,
|
|
|
|
SearchPlusIcon: SearchPlusIcon,
|
|
|
|
TimesIcon: TimesIcon
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
focustrap: FocusTrap
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|