@seshuk/payload-media-preview 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +507 -0
  3. package/dist/components/Cell/Cell.client.d.ts +18 -0
  4. package/dist/components/Cell/Cell.client.js +131 -0
  5. package/dist/components/Cell/Cell.scss +43 -0
  6. package/dist/components/Cell/Cell.server.d.ts +11 -0
  7. package/dist/components/Cell/Cell.server.js +33 -0
  8. package/dist/components/ExternalLinkIcon/ExternalLinkIcon.d.ts +5 -0
  9. package/dist/components/ExternalLinkIcon/ExternalLinkIcon.js +17 -0
  10. package/dist/components/ExternalLinkIcon/ExternalLinkIcon.scss +19 -0
  11. package/dist/components/Field/Field.d.ts +18 -0
  12. package/dist/components/Field/Field.js +107 -0
  13. package/dist/components/Field/Field.scss +14 -0
  14. package/dist/components/MediaPreview.constants.d.ts +4 -0
  15. package/dist/components/MediaPreview.constants.js +28 -0
  16. package/dist/components/MediaPreview.d.ts +10 -0
  17. package/dist/components/MediaPreview.js +57 -0
  18. package/dist/components/MediaPreview.types.d.ts +2 -0
  19. package/dist/components/MediaPreview.types.js +1 -0
  20. package/dist/components/MediaPreview.utils.d.ts +6 -0
  21. package/dist/components/MediaPreview.utils.js +38 -0
  22. package/dist/components/Modal/Modal.constants.d.ts +16 -0
  23. package/dist/components/Modal/Modal.constants.js +16 -0
  24. package/dist/components/Modal/Modal.d.ts +19 -0
  25. package/dist/components/Modal/Modal.js +277 -0
  26. package/dist/components/Modal/Modal.scss +173 -0
  27. package/dist/components/Viewer/AudioViewer.d.ts +3 -0
  28. package/dist/components/Viewer/AudioViewer.js +24 -0
  29. package/dist/components/Viewer/IframeViewer.d.ts +3 -0
  30. package/dist/components/Viewer/IframeViewer.js +14 -0
  31. package/dist/components/Viewer/ImageViewer.d.ts +3 -0
  32. package/dist/components/Viewer/ImageViewer.js +10 -0
  33. package/dist/components/Viewer/VideoViewer.d.ts +3 -0
  34. package/dist/components/Viewer/VideoViewer.js +25 -0
  35. package/dist/components/Viewer/Viewer.d.ts +12 -0
  36. package/dist/components/Viewer/Viewer.js +50 -0
  37. package/dist/components/adapterResolver.d.ts +13 -0
  38. package/dist/components/adapterResolver.js +43 -0
  39. package/dist/exports/client.d.ts +5 -0
  40. package/dist/exports/client.js +5 -0
  41. package/dist/exports/rsc.d.ts +2 -0
  42. package/dist/exports/rsc.js +2 -0
  43. package/dist/field.d.ts +18 -0
  44. package/dist/field.js +36 -0
  45. package/dist/index.d.ts +6 -0
  46. package/dist/index.js +90 -0
  47. package/dist/translations/index.d.ts +8 -0
  48. package/dist/translations/index.js +90 -0
  49. package/dist/translations/locales/ar.d.ts +2 -0
  50. package/dist/translations/locales/ar.js +11 -0
  51. package/dist/translations/locales/az.d.ts +2 -0
  52. package/dist/translations/locales/az.js +11 -0
  53. package/dist/translations/locales/bg.d.ts +2 -0
  54. package/dist/translations/locales/bg.js +11 -0
  55. package/dist/translations/locales/bnBd.d.ts +2 -0
  56. package/dist/translations/locales/bnBd.js +11 -0
  57. package/dist/translations/locales/bnIn.d.ts +2 -0
  58. package/dist/translations/locales/bnIn.js +11 -0
  59. package/dist/translations/locales/ca.d.ts +2 -0
  60. package/dist/translations/locales/ca.js +11 -0
  61. package/dist/translations/locales/cs.d.ts +2 -0
  62. package/dist/translations/locales/cs.js +11 -0
  63. package/dist/translations/locales/da.d.ts +2 -0
  64. package/dist/translations/locales/da.js +11 -0
  65. package/dist/translations/locales/de.d.ts +2 -0
  66. package/dist/translations/locales/de.js +11 -0
  67. package/dist/translations/locales/en.d.ts +2 -0
  68. package/dist/translations/locales/en.js +11 -0
  69. package/dist/translations/locales/es.d.ts +2 -0
  70. package/dist/translations/locales/es.js +11 -0
  71. package/dist/translations/locales/et.d.ts +2 -0
  72. package/dist/translations/locales/et.js +11 -0
  73. package/dist/translations/locales/fa.d.ts +2 -0
  74. package/dist/translations/locales/fa.js +11 -0
  75. package/dist/translations/locales/fr.d.ts +2 -0
  76. package/dist/translations/locales/fr.js +11 -0
  77. package/dist/translations/locales/he.d.ts +2 -0
  78. package/dist/translations/locales/he.js +11 -0
  79. package/dist/translations/locales/hr.d.ts +2 -0
  80. package/dist/translations/locales/hr.js +11 -0
  81. package/dist/translations/locales/hu.d.ts +2 -0
  82. package/dist/translations/locales/hu.js +11 -0
  83. package/dist/translations/locales/hy.d.ts +2 -0
  84. package/dist/translations/locales/hy.js +11 -0
  85. package/dist/translations/locales/id.d.ts +2 -0
  86. package/dist/translations/locales/id.js +11 -0
  87. package/dist/translations/locales/is.d.ts +2 -0
  88. package/dist/translations/locales/is.js +11 -0
  89. package/dist/translations/locales/it.d.ts +2 -0
  90. package/dist/translations/locales/it.js +11 -0
  91. package/dist/translations/locales/ja.d.ts +2 -0
  92. package/dist/translations/locales/ja.js +11 -0
  93. package/dist/translations/locales/ko.d.ts +2 -0
  94. package/dist/translations/locales/ko.js +11 -0
  95. package/dist/translations/locales/lt.d.ts +2 -0
  96. package/dist/translations/locales/lt.js +11 -0
  97. package/dist/translations/locales/lv.d.ts +2 -0
  98. package/dist/translations/locales/lv.js +11 -0
  99. package/dist/translations/locales/my.d.ts +2 -0
  100. package/dist/translations/locales/my.js +11 -0
  101. package/dist/translations/locales/nb.d.ts +2 -0
  102. package/dist/translations/locales/nb.js +11 -0
  103. package/dist/translations/locales/nl.d.ts +2 -0
  104. package/dist/translations/locales/nl.js +11 -0
  105. package/dist/translations/locales/pl.d.ts +2 -0
  106. package/dist/translations/locales/pl.js +11 -0
  107. package/dist/translations/locales/pt.d.ts +2 -0
  108. package/dist/translations/locales/pt.js +11 -0
  109. package/dist/translations/locales/ro.d.ts +2 -0
  110. package/dist/translations/locales/ro.js +11 -0
  111. package/dist/translations/locales/rs.d.ts +2 -0
  112. package/dist/translations/locales/rs.js +11 -0
  113. package/dist/translations/locales/rsLatin.d.ts +2 -0
  114. package/dist/translations/locales/rsLatin.js +11 -0
  115. package/dist/translations/locales/ru.d.ts +2 -0
  116. package/dist/translations/locales/ru.js +11 -0
  117. package/dist/translations/locales/sk.d.ts +2 -0
  118. package/dist/translations/locales/sk.js +11 -0
  119. package/dist/translations/locales/sl.d.ts +2 -0
  120. package/dist/translations/locales/sl.js +11 -0
  121. package/dist/translations/locales/sv.d.ts +2 -0
  122. package/dist/translations/locales/sv.js +11 -0
  123. package/dist/translations/locales/ta.d.ts +2 -0
  124. package/dist/translations/locales/ta.js +11 -0
  125. package/dist/translations/locales/th.d.ts +2 -0
  126. package/dist/translations/locales/th.js +11 -0
  127. package/dist/translations/locales/tr.d.ts +2 -0
  128. package/dist/translations/locales/tr.js +11 -0
  129. package/dist/translations/locales/uk.d.ts +2 -0
  130. package/dist/translations/locales/uk.js +11 -0
  131. package/dist/translations/locales/vi.d.ts +2 -0
  132. package/dist/translations/locales/vi.js +11 -0
  133. package/dist/translations/locales/zh.d.ts +2 -0
  134. package/dist/translations/locales/zh.js +11 -0
  135. package/dist/translations/locales/zhTw.d.ts +2 -0
  136. package/dist/translations/locales/zhTw.js +11 -0
  137. package/dist/translations/types.d.ts +11 -0
  138. package/dist/translations/types.js +1 -0
  139. package/dist/types.d.ts +130 -0
  140. package/dist/types.js +2 -0
  141. package/dist/utils/insertField.d.ts +3 -0
  142. package/dist/utils/insertField.js +97 -0
  143. package/package.json +121 -0
@@ -0,0 +1,277 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Modal, useModal, useTranslation } from "@payloadcms/ui";
4
+ import { XIcon } from "@payloadcms/ui/icons/X";
5
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
6
+ import { createPortal } from "react-dom";
7
+ import { MediaPreviewViewer } from "../Viewer/Viewer.js";
8
+ import { AUDIO_DIMENSIONS, POPUP_DIMENSIONS, SPACING } from "./Modal.constants.js";
9
+ import "./Modal.scss";
10
+ export const MediaPreviewModal = ({ customViewer, media, mode, onClose, rowId, show, triggerRef })=>{
11
+ const { documentViewerUrl, height, mimeType, url, width } = media;
12
+ const [position, setPosition] = useState('bottom');
13
+ const [popupStyle, setPopupStyle] = useState({});
14
+ const popupRef = useRef(null);
15
+ const previousModalOpenRef = useRef(false);
16
+ const { closeModal, isModalOpen, openModal } = useModal();
17
+ const { t } = useTranslation();
18
+ const modalSlug = useMemo(()=>`media-preview-${rowId || 'field'}`, [
19
+ rowId
20
+ ]);
21
+ const isAudio = useMemo(()=>mimeType?.startsWith('audio/'), [
22
+ mimeType
23
+ ]);
24
+ const isVideo = useMemo(()=>mimeType?.startsWith('video/'), [
25
+ mimeType
26
+ ]);
27
+ const isImage = useMemo(()=>mimeType?.startsWith('image/'), [
28
+ mimeType
29
+ ]);
30
+ const getPopupDimensions = useCallback(()=>{
31
+ if (isImage && width && height) {
32
+ const aspectRatio = width / height;
33
+ let popupHeight = POPUP_DIMENSIONS.MAX_HEIGHT;
34
+ let popupWidth = popupHeight * aspectRatio;
35
+ if (popupWidth > POPUP_DIMENSIONS.MAX_WIDTH) {
36
+ popupWidth = POPUP_DIMENSIONS.MAX_WIDTH;
37
+ popupHeight = popupWidth / aspectRatio;
38
+ }
39
+ return {
40
+ height: Math.max(POPUP_DIMENSIONS.MIN_HEIGHT, popupHeight),
41
+ width: Math.max(POPUP_DIMENSIONS.MIN_WIDTH, popupWidth)
42
+ };
43
+ }
44
+ if (isAudio) {
45
+ return {
46
+ height: AUDIO_DIMENSIONS.HEIGHT,
47
+ width: AUDIO_DIMENSIONS.WIDTH
48
+ };
49
+ }
50
+ return {
51
+ height: POPUP_DIMENSIONS.MAX_HEIGHT,
52
+ width: POPUP_DIMENSIONS.MAX_WIDTH
53
+ };
54
+ }, [
55
+ isImage,
56
+ width,
57
+ height,
58
+ isAudio
59
+ ]);
60
+ const calculatePopupPosition = useCallback(()=>{
61
+ if (!triggerRef?.current || mode !== 'popup') {
62
+ return;
63
+ }
64
+ const rect = triggerRef.current.getBoundingClientRect();
65
+ const { height: popupHeight, width: popupWidth } = getPopupDimensions();
66
+ const spacingTop = SPACING.CARET_SIZE + SPACING.TOP;
67
+ const spacingBottom = SPACING.CARET_SIZE + SPACING.BOTTOM;
68
+ const viewportWidth = document.documentElement.clientWidth;
69
+ const viewportHeight = document.documentElement.clientHeight;
70
+ let top;
71
+ let selectedPosition;
72
+ let left = rect.left + rect.width / 2 - popupWidth / 2;
73
+ const buttonCenterX = rect.left + rect.width / 2;
74
+ if (left + popupWidth > viewportWidth - SPACING.VIEWPORT_MARGIN) {
75
+ left = viewportWidth - popupWidth - SPACING.VIEWPORT_MARGIN;
76
+ }
77
+ if (left < SPACING.VIEWPORT_MARGIN) {
78
+ left = SPACING.VIEWPORT_MARGIN;
79
+ }
80
+ const caretLeft = buttonCenterX - left;
81
+ const spaceBelow = viewportHeight - rect.bottom;
82
+ const spaceAbove = rect.top;
83
+ if (spaceBelow >= popupHeight + spacingBottom) {
84
+ selectedPosition = 'bottom';
85
+ top = rect.bottom + spacingBottom;
86
+ } else if (spaceAbove >= popupHeight + spacingTop) {
87
+ selectedPosition = 'top';
88
+ top = rect.top - popupHeight - spacingTop;
89
+ } else {
90
+ if (spaceAbove > spaceBelow) {
91
+ selectedPosition = 'top';
92
+ top = rect.top - popupHeight - spacingTop;
93
+ } else {
94
+ selectedPosition = 'bottom';
95
+ top = rect.bottom + spacingBottom;
96
+ }
97
+ }
98
+ setPosition(selectedPosition);
99
+ setPopupStyle({
100
+ '--caret-left': `${caretLeft}px`,
101
+ '--popup-height': `${popupHeight}px`,
102
+ '--popup-width': `${popupWidth}px`,
103
+ left: `${left}px`,
104
+ top: `${top}px`
105
+ });
106
+ }, [
107
+ triggerRef,
108
+ mode,
109
+ getPopupDimensions
110
+ ]);
111
+ useEffect(()=>{
112
+ if (mode === 'fullscreen') {
113
+ if (show && !isModalOpen(modalSlug)) {
114
+ openModal(modalSlug);
115
+ }
116
+ }
117
+ }, [
118
+ show,
119
+ mode,
120
+ modalSlug,
121
+ isModalOpen,
122
+ openModal
123
+ ]);
124
+ useEffect(()=>{
125
+ if (mode === 'fullscreen' && !show && isModalOpen(modalSlug)) {
126
+ closeModal(modalSlug);
127
+ }
128
+ }, [
129
+ show,
130
+ mode,
131
+ modalSlug,
132
+ isModalOpen,
133
+ closeModal
134
+ ]);
135
+ useEffect(()=>{
136
+ if (mode === 'fullscreen') {
137
+ const currentModalOpen = isModalOpen(modalSlug);
138
+ if (previousModalOpenRef.current && !currentModalOpen && show) {
139
+ onClose?.();
140
+ }
141
+ previousModalOpenRef.current = currentModalOpen;
142
+ }
143
+ }, [
144
+ isModalOpen,
145
+ modalSlug,
146
+ mode,
147
+ show,
148
+ onClose
149
+ ]);
150
+ useEffect(()=>{
151
+ if (show && mode === 'popup') {
152
+ calculatePopupPosition();
153
+ window.addEventListener('resize', calculatePopupPosition);
154
+ window.addEventListener('scroll', calculatePopupPosition, true);
155
+ return ()=>{
156
+ window.removeEventListener('resize', calculatePopupPosition);
157
+ window.removeEventListener('scroll', calculatePopupPosition, true);
158
+ };
159
+ }
160
+ }, [
161
+ show,
162
+ mode,
163
+ calculatePopupPosition
164
+ ]);
165
+ const handleClickOutside = useCallback((event)=>{
166
+ if (popupRef.current && !popupRef.current.contains(event.target) && triggerRef?.current && !triggerRef.current.contains(event.target)) {
167
+ onClose?.();
168
+ }
169
+ }, [
170
+ onClose,
171
+ triggerRef
172
+ ]);
173
+ useEffect(()=>{
174
+ if (!show || mode !== 'popup') {
175
+ return;
176
+ }
177
+ document.addEventListener('mousedown', handleClickOutside);
178
+ return ()=>{
179
+ document.removeEventListener('mousedown', handleClickOutside);
180
+ };
181
+ }, [
182
+ show,
183
+ mode,
184
+ handleClickOutside
185
+ ]);
186
+ const handleModalClose = useCallback(()=>{
187
+ closeModal(modalSlug);
188
+ onClose?.();
189
+ }, [
190
+ closeModal,
191
+ modalSlug,
192
+ onClose
193
+ ]);
194
+ const handleBackdropClick = useCallback((e)=>{
195
+ if ('key' in e && e.key !== 'Enter' && e.key !== ' ') {
196
+ return;
197
+ }
198
+ const target = e.target;
199
+ if (target.tagName === 'IMG' || target.tagName === 'VIDEO' || target.tagName === 'AUDIO' || target.tagName === 'IFRAME' || target.classList.contains('media-preview-modal__close') || target.closest('.media-preview-modal__close')) {
200
+ return;
201
+ }
202
+ handleModalClose();
203
+ }, [
204
+ handleModalClose
205
+ ]);
206
+ const viewerContent = useMemo(()=>{
207
+ if (customViewer) {
208
+ return customViewer;
209
+ }
210
+ return /*#__PURE__*/ _jsx(MediaPreviewViewer, {
211
+ className: documentViewerUrl ? 'media-preview-modal__iframe' : isVideo ? 'media-preview-modal__video' : isAudio ? 'media-preview-modal__audio' : 'media-preview-modal__image',
212
+ media: {
213
+ documentViewerUrl,
214
+ mimeType,
215
+ url
216
+ },
217
+ title: isVideo ? t('@seshuk/payload-media-preview:titleVideo') : isImage ? t('@seshuk/payload-media-preview:titleImage') : isAudio ? t('@seshuk/payload-media-preview:titleAudio') : t('@seshuk/payload-media-preview:titleDocument')
218
+ });
219
+ }, [
220
+ customViewer,
221
+ documentViewerUrl,
222
+ isVideo,
223
+ isAudio,
224
+ isImage,
225
+ mimeType,
226
+ url,
227
+ t
228
+ ]);
229
+ if (mode === 'popup') {
230
+ if (!show) {
231
+ return null;
232
+ }
233
+ return /*#__PURE__*/ createPortal(/*#__PURE__*/ _jsx("div", {
234
+ className: `media-preview-modal media-preview-modal--popup media-preview-modal--show media-preview-modal--position-${position}`,
235
+ ref: popupRef,
236
+ style: popupStyle,
237
+ children: /*#__PURE__*/ _jsx("div", {
238
+ className: "media-preview-modal__body",
239
+ children: viewerContent
240
+ })
241
+ }), document.body);
242
+ }
243
+ if (!isModalOpen(modalSlug)) {
244
+ return null;
245
+ }
246
+ return /*#__PURE__*/ _jsx(Modal, {
247
+ className: "media-preview-modal media-preview-modal--fullscreen",
248
+ onClick: handleBackdropClick,
249
+ slug: modalSlug,
250
+ children: /*#__PURE__*/ _jsxs("div", {
251
+ "aria-label": t('@seshuk/payload-media-preview:close'),
252
+ className: "media-preview-modal__wrapper",
253
+ onClick: handleBackdropClick,
254
+ onKeyDown: handleBackdropClick,
255
+ role: "button",
256
+ tabIndex: -1,
257
+ children: [
258
+ /*#__PURE__*/ _jsx("button", {
259
+ "aria-label": t('@seshuk/payload-media-preview:close'),
260
+ className: "drawer-close-button media-preview-modal__close",
261
+ onClick: handleModalClose,
262
+ type: "button",
263
+ children: /*#__PURE__*/ _jsx(XIcon, {})
264
+ }),
265
+ /*#__PURE__*/ _jsx("div", {
266
+ className: "media-preview-modal__content",
267
+ role: "dialog",
268
+ tabIndex: -1,
269
+ children: /*#__PURE__*/ _jsx("div", {
270
+ className: "media-preview-modal__body",
271
+ children: viewerContent
272
+ })
273
+ })
274
+ ]
275
+ })
276
+ });
277
+ };
@@ -0,0 +1,173 @@
1
+ @import '~@payloadcms/ui/scss';
2
+
3
+ .media-preview-modal {
4
+ &--popup {
5
+ --popup-caret-size: 10px;
6
+ --popup-padding: calc(var(--base) * 0.5);
7
+ --popup-width: 480px;
8
+ --popup-height: 290px;
9
+
10
+ position: fixed;
11
+ z-index: 9999;
12
+ opacity: 0;
13
+ visibility: hidden;
14
+ background: var(--theme-elevation-0);
15
+ border-radius: 4px;
16
+ padding: var(--popup-padding);
17
+ pointer-events: auto;
18
+ transition: opacity 0.2s ease-in-out;
19
+ will-change: opacity, transform;
20
+ max-height: 100vh;
21
+ overflow: visible;
22
+
23
+ html[data-theme='dark'] & {
24
+ background: var(--theme-elevation-100);
25
+ }
26
+
27
+ &.media-preview-modal--show {
28
+ visibility: visible;
29
+ opacity: 1;
30
+ }
31
+
32
+ &::after {
33
+ content: '';
34
+ position: absolute;
35
+ border: var(--popup-caret-size) solid transparent;
36
+ }
37
+
38
+ &.media-preview-modal--position-top {
39
+ @include shadow-lg;
40
+
41
+ &::after {
42
+ top: calc(100% - 1px);
43
+ left: var(--caret-left, 50%);
44
+ transform: translateX(-50%);
45
+ border-top-color: var(--theme-elevation-0);
46
+
47
+ html[data-theme='dark'] & {
48
+ border-top-color: var(--theme-elevation-100);
49
+ }
50
+ }
51
+ }
52
+
53
+ &.media-preview-modal--position-bottom {
54
+ @include shadow-lg-top;
55
+
56
+ &::after {
57
+ bottom: calc(100% - 1px);
58
+ left: var(--caret-left, 50%);
59
+ transform: translateX(-50%);
60
+ border-bottom-color: var(--theme-elevation-0);
61
+
62
+ html[data-theme='dark'] & {
63
+ border-bottom-color: var(--theme-elevation-100);
64
+ }
65
+ }
66
+ }
67
+ }
68
+
69
+ &--fullscreen {
70
+ @include blur-bg;
71
+ display: flex;
72
+ align-items: center;
73
+ justify-content: center;
74
+ height: 100%;
75
+ }
76
+
77
+ &__body {
78
+ position: relative;
79
+ }
80
+
81
+ &--popup &__body {
82
+ width: var(--popup-width);
83
+ height: var(--popup-height);
84
+ max-width: 90vw;
85
+ max-height: calc(100vh - 2rem);
86
+ overflow: auto;
87
+ }
88
+
89
+ &--fullscreen &__body {
90
+ width: 100%;
91
+ height: 100%;
92
+ border-radius: var(--border-radius-m);
93
+ overflow: hidden;
94
+ display: flex;
95
+ align-items: center;
96
+ justify-content: center;
97
+ flex: 1;
98
+ }
99
+
100
+ &__wrapper {
101
+ position: absolute;
102
+ inset: 0;
103
+ display: flex;
104
+ align-items: center;
105
+ justify-content: center;
106
+ pointer-events: auto;
107
+ cursor: pointer;
108
+ }
109
+
110
+ &__content {
111
+ position: relative;
112
+ z-index: 1;
113
+ max-width: min(90vw, calc(100vh * 1.6));
114
+ max-height: 90vh;
115
+ width: 100%;
116
+ height: 100%;
117
+ cursor: default;
118
+ pointer-events: auto;
119
+ display: flex;
120
+ flex-direction: column;
121
+ }
122
+
123
+ &__close {
124
+ position: absolute;
125
+ top: calc(var(--base) * 0.5);
126
+ right: calc(var(--base) * 0.5);
127
+ z-index: 10;
128
+ pointer-events: auto;
129
+ }
130
+
131
+ &--popup &__body &__iframe,
132
+ &--popup &__body &__video,
133
+ &--popup &__body &__image,
134
+ &--popup &__body &__audio {
135
+ position: absolute;
136
+ inset: 0;
137
+ width: 100%;
138
+ height: 100%;
139
+ border: none;
140
+ border-radius: var(--border-radius-s);
141
+ object-fit: contain;
142
+ }
143
+
144
+ &--fullscreen &__body &__iframe {
145
+ width: 100%;
146
+ height: 100%;
147
+ border: none;
148
+ border-radius: var(--border-radius-s);
149
+ object-fit: contain;
150
+ min-height: 60vh;
151
+ }
152
+
153
+ &--fullscreen &__body &__video {
154
+ width: 100%;
155
+ height: 100%;
156
+ border: none;
157
+ border-radius: var(--border-radius-s);
158
+ }
159
+
160
+ &--fullscreen &__body &__image {
161
+ width: auto;
162
+ height: auto;
163
+ max-width: 100%;
164
+ max-height: 100%;
165
+ border-radius: var(--border-radius-s);
166
+ }
167
+
168
+ @media (max-width: 768px) {
169
+ &--popup &__body {
170
+ width: min(400px, calc(100vw - 64px));
171
+ }
172
+ }
173
+ }
@@ -0,0 +1,3 @@
1
+ import type { AudioViewerProps } from '@/types.js';
2
+ import React from 'react';
3
+ export declare const AudioViewer: React.FC<AudioViewerProps>;
@@ -0,0 +1,24 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import React from "react";
4
+ export const AudioViewer = ({ autoPlay = true, className, controls = true, loop = false, mimeType, muted = false, preload = 'metadata', src, title })=>{
5
+ return(// eslint-disable-next-line jsx-a11y/control-has-associated-label
6
+ /*#__PURE__*/ _jsxs("audio", {
7
+ autoPlay: autoPlay,
8
+ className: className,
9
+ controls: controls,
10
+ loop: loop,
11
+ muted: muted,
12
+ preload: preload,
13
+ title: title,
14
+ children: [
15
+ /*#__PURE__*/ _jsx("source", {
16
+ src: src,
17
+ type: mimeType
18
+ }),
19
+ /*#__PURE__*/ _jsx("track", {
20
+ kind: "captions"
21
+ })
22
+ ]
23
+ }));
24
+ };
@@ -0,0 +1,3 @@
1
+ import type { IframeViewerProps } from '@/types.js';
2
+ import React from 'react';
3
+ export declare const IframeViewer: React.FC<IframeViewerProps>;
@@ -0,0 +1,14 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import React from "react";
4
+ export const IframeViewer = ({ allow = 'accelerometer; gyroscope; autoplay; encrypted-media; picture-in-picture;', allowFullScreen = true, className, loading = 'lazy', src, title })=>{
5
+ return(// eslint-disable-next-line @eslint-react/dom/no-missing-iframe-sandbox
6
+ /*#__PURE__*/ _jsx("iframe", {
7
+ allow: allow,
8
+ allowFullScreen: allowFullScreen,
9
+ className: className,
10
+ loading: loading,
11
+ src: src,
12
+ title: title
13
+ }));
14
+ };
@@ -0,0 +1,3 @@
1
+ import type { ImageViewerProps } from '@/types.js';
2
+ import React from 'react';
3
+ export declare const ImageViewer: React.FC<ImageViewerProps>;
@@ -0,0 +1,10 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import React from "react";
4
+ export const ImageViewer = ({ alt = 'Image preview', className, src })=>{
5
+ return /*#__PURE__*/ _jsx("img", {
6
+ alt: alt,
7
+ className: className,
8
+ src: src
9
+ });
10
+ };
@@ -0,0 +1,3 @@
1
+ import type { VideoViewerProps } from '@/types.js';
2
+ import React from 'react';
3
+ export declare const VideoViewer: React.FC<VideoViewerProps>;
@@ -0,0 +1,25 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import React from "react";
4
+ export const VideoViewer = ({ autoPlay = true, className, controls = true, loop = false, mimeType, muted = false, preload = 'metadata', src, title })=>{
5
+ return(// eslint-disable-next-line jsx-a11y/control-has-associated-label
6
+ /*#__PURE__*/ _jsxs("video", {
7
+ autoPlay: autoPlay,
8
+ className: className,
9
+ controls: controls,
10
+ loop: loop,
11
+ muted: muted,
12
+ playsInline: autoPlay,
13
+ preload: preload,
14
+ title: title,
15
+ children: [
16
+ /*#__PURE__*/ _jsx("source", {
17
+ src: src,
18
+ type: mimeType
19
+ }),
20
+ /*#__PURE__*/ _jsx("track", {
21
+ kind: "captions"
22
+ })
23
+ ]
24
+ }));
25
+ };
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ type ViewerProps = {
3
+ className?: string;
4
+ media: {
5
+ documentViewerUrl?: null | string;
6
+ mimeType?: string;
7
+ url?: string;
8
+ };
9
+ title?: string;
10
+ };
11
+ export declare const MediaPreviewViewer: React.FC<ViewerProps>;
12
+ export {};
@@ -0,0 +1,50 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import React, { useMemo } from "react";
4
+ import { AudioViewer } from "./AudioViewer.js";
5
+ import { IframeViewer } from "./IframeViewer.js";
6
+ import { ImageViewer } from "./ImageViewer.js";
7
+ import { VideoViewer } from "./VideoViewer.js";
8
+ export const MediaPreviewViewer = ({ className, media, title })=>{
9
+ const { documentViewerUrl, mimeType, url } = media;
10
+ const isAudio = useMemo(()=>mimeType?.startsWith('audio/'), [
11
+ mimeType
12
+ ]);
13
+ const isVideo = useMemo(()=>mimeType?.startsWith('video/'), [
14
+ mimeType
15
+ ]);
16
+ const isImage = useMemo(()=>mimeType?.startsWith('image/'), [
17
+ mimeType
18
+ ]);
19
+ if (isAudio && url) {
20
+ return /*#__PURE__*/ _jsx(AudioViewer, {
21
+ className: className,
22
+ mimeType: mimeType,
23
+ src: url,
24
+ title: title
25
+ });
26
+ }
27
+ if (isVideo && url) {
28
+ return /*#__PURE__*/ _jsx(VideoViewer, {
29
+ className: className,
30
+ mimeType: mimeType,
31
+ src: url,
32
+ title: title
33
+ });
34
+ }
35
+ if (isImage && url) {
36
+ return /*#__PURE__*/ _jsx(ImageViewer, {
37
+ alt: title || 'Image preview',
38
+ className: className,
39
+ src: url
40
+ });
41
+ }
42
+ if (documentViewerUrl) {
43
+ return /*#__PURE__*/ _jsx(IframeViewer, {
44
+ className: className,
45
+ src: documentViewerUrl,
46
+ title: title || 'Document preview'
47
+ });
48
+ }
49
+ return null;
50
+ };
@@ -0,0 +1,13 @@
1
+ import type { MediaPreviewAdapterInlineResult, MediaPreviewAdapterNewTabResult, MediaPreviewAdapterResolveArgs } from '@/types.js';
2
+ import type { ImportMap, SanitizedConfig } from 'payload';
3
+ type PayloadLike = {
4
+ config: SanitizedConfig;
5
+ importMap: ImportMap;
6
+ };
7
+ export type AdapterMatch = {
8
+ adapterName: string;
9
+ result: MediaPreviewAdapterInlineResult | MediaPreviewAdapterNewTabResult;
10
+ };
11
+ export declare const resolveAdapter: (payloadLike: PayloadLike, adapterNames: string[] | undefined, args: MediaPreviewAdapterResolveArgs) => AdapterMatch | null;
12
+ export declare const resolveAdapterViewer: (payloadLike: PayloadLike, match: AdapterMatch | null) => null | React.ReactNode;
13
+ export {};
@@ -0,0 +1,43 @@
1
+ import { RenderServerComponent } from "@payloadcms/ui/elements/RenderServerComponent";
2
+ const getAdapters = (config)=>{
3
+ const pluginData = config.custom?.['@seshuk/payload-media-preview'];
4
+ return pluginData?.adapters ?? [];
5
+ };
6
+ const filterAdapters = (allAdapters, adapterNames)=>{
7
+ if (!adapterNames) {
8
+ return allAdapters;
9
+ }
10
+ return allAdapters.filter((a)=>adapterNames.includes(a.name));
11
+ };
12
+ export const resolveAdapter = (payloadLike, adapterNames, args)=>{
13
+ const allAdapters = getAdapters(payloadLike.config);
14
+ if (allAdapters.length === 0) {
15
+ return null;
16
+ }
17
+ const adapters = filterAdapters(allAdapters, adapterNames);
18
+ for (const adapter of adapters){
19
+ const result = adapter.resolve(args);
20
+ if (result) {
21
+ return {
22
+ adapterName: adapter.name,
23
+ result
24
+ };
25
+ }
26
+ }
27
+ return null;
28
+ };
29
+ export const resolveAdapterViewer = (payloadLike, match)=>{
30
+ if (!match || match.result.mode !== 'inline') {
31
+ return null;
32
+ }
33
+ const depKey = `media-preview-viewer-${match.adapterName}`;
34
+ const dep = payloadLike.config.admin?.dependencies?.[depKey];
35
+ if (!dep) {
36
+ return null;
37
+ }
38
+ return RenderServerComponent({
39
+ clientProps: match.result.props,
40
+ Component: dep,
41
+ importMap: payloadLike.importMap
42
+ });
43
+ };
@@ -0,0 +1,5 @@
1
+ export { MediaPreviewFieldClient } from '@/components/Field/Field.js';
2
+ export { AudioViewer } from '@/components/Viewer/AudioViewer.js';
3
+ export { IframeViewer } from '@/components/Viewer/IframeViewer.js';
4
+ export { ImageViewer } from '@/components/Viewer/ImageViewer.js';
5
+ export { VideoViewer } from '@/components/Viewer/VideoViewer.js';
@@ -0,0 +1,5 @@
1
+ export { MediaPreviewFieldClient } from "../components/Field/Field.js";
2
+ export { AudioViewer } from "../components/Viewer/AudioViewer.js";
3
+ export { IframeViewer } from "../components/Viewer/IframeViewer.js";
4
+ export { ImageViewer } from "../components/Viewer/ImageViewer.js";
5
+ export { VideoViewer } from "../components/Viewer/VideoViewer.js";
@@ -0,0 +1,2 @@
1
+ export { MediaPreviewCell } from '@/components/Cell/Cell.server.js';
2
+ export { MediaPreview } from '@/components/MediaPreview.js';