@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.
- package/LICENSE +21 -0
- package/README.md +507 -0
- package/dist/components/Cell/Cell.client.d.ts +18 -0
- package/dist/components/Cell/Cell.client.js +131 -0
- package/dist/components/Cell/Cell.scss +43 -0
- package/dist/components/Cell/Cell.server.d.ts +11 -0
- package/dist/components/Cell/Cell.server.js +33 -0
- package/dist/components/ExternalLinkIcon/ExternalLinkIcon.d.ts +5 -0
- package/dist/components/ExternalLinkIcon/ExternalLinkIcon.js +17 -0
- package/dist/components/ExternalLinkIcon/ExternalLinkIcon.scss +19 -0
- package/dist/components/Field/Field.d.ts +18 -0
- package/dist/components/Field/Field.js +107 -0
- package/dist/components/Field/Field.scss +14 -0
- package/dist/components/MediaPreview.constants.d.ts +4 -0
- package/dist/components/MediaPreview.constants.js +28 -0
- package/dist/components/MediaPreview.d.ts +10 -0
- package/dist/components/MediaPreview.js +57 -0
- package/dist/components/MediaPreview.types.d.ts +2 -0
- package/dist/components/MediaPreview.types.js +1 -0
- package/dist/components/MediaPreview.utils.d.ts +6 -0
- package/dist/components/MediaPreview.utils.js +38 -0
- package/dist/components/Modal/Modal.constants.d.ts +16 -0
- package/dist/components/Modal/Modal.constants.js +16 -0
- package/dist/components/Modal/Modal.d.ts +19 -0
- package/dist/components/Modal/Modal.js +277 -0
- package/dist/components/Modal/Modal.scss +173 -0
- package/dist/components/Viewer/AudioViewer.d.ts +3 -0
- package/dist/components/Viewer/AudioViewer.js +24 -0
- package/dist/components/Viewer/IframeViewer.d.ts +3 -0
- package/dist/components/Viewer/IframeViewer.js +14 -0
- package/dist/components/Viewer/ImageViewer.d.ts +3 -0
- package/dist/components/Viewer/ImageViewer.js +10 -0
- package/dist/components/Viewer/VideoViewer.d.ts +3 -0
- package/dist/components/Viewer/VideoViewer.js +25 -0
- package/dist/components/Viewer/Viewer.d.ts +12 -0
- package/dist/components/Viewer/Viewer.js +50 -0
- package/dist/components/adapterResolver.d.ts +13 -0
- package/dist/components/adapterResolver.js +43 -0
- package/dist/exports/client.d.ts +5 -0
- package/dist/exports/client.js +5 -0
- package/dist/exports/rsc.d.ts +2 -0
- package/dist/exports/rsc.js +2 -0
- package/dist/field.d.ts +18 -0
- package/dist/field.js +36 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +90 -0
- package/dist/translations/index.d.ts +8 -0
- package/dist/translations/index.js +90 -0
- package/dist/translations/locales/ar.d.ts +2 -0
- package/dist/translations/locales/ar.js +11 -0
- package/dist/translations/locales/az.d.ts +2 -0
- package/dist/translations/locales/az.js +11 -0
- package/dist/translations/locales/bg.d.ts +2 -0
- package/dist/translations/locales/bg.js +11 -0
- package/dist/translations/locales/bnBd.d.ts +2 -0
- package/dist/translations/locales/bnBd.js +11 -0
- package/dist/translations/locales/bnIn.d.ts +2 -0
- package/dist/translations/locales/bnIn.js +11 -0
- package/dist/translations/locales/ca.d.ts +2 -0
- package/dist/translations/locales/ca.js +11 -0
- package/dist/translations/locales/cs.d.ts +2 -0
- package/dist/translations/locales/cs.js +11 -0
- package/dist/translations/locales/da.d.ts +2 -0
- package/dist/translations/locales/da.js +11 -0
- package/dist/translations/locales/de.d.ts +2 -0
- package/dist/translations/locales/de.js +11 -0
- package/dist/translations/locales/en.d.ts +2 -0
- package/dist/translations/locales/en.js +11 -0
- package/dist/translations/locales/es.d.ts +2 -0
- package/dist/translations/locales/es.js +11 -0
- package/dist/translations/locales/et.d.ts +2 -0
- package/dist/translations/locales/et.js +11 -0
- package/dist/translations/locales/fa.d.ts +2 -0
- package/dist/translations/locales/fa.js +11 -0
- package/dist/translations/locales/fr.d.ts +2 -0
- package/dist/translations/locales/fr.js +11 -0
- package/dist/translations/locales/he.d.ts +2 -0
- package/dist/translations/locales/he.js +11 -0
- package/dist/translations/locales/hr.d.ts +2 -0
- package/dist/translations/locales/hr.js +11 -0
- package/dist/translations/locales/hu.d.ts +2 -0
- package/dist/translations/locales/hu.js +11 -0
- package/dist/translations/locales/hy.d.ts +2 -0
- package/dist/translations/locales/hy.js +11 -0
- package/dist/translations/locales/id.d.ts +2 -0
- package/dist/translations/locales/id.js +11 -0
- package/dist/translations/locales/is.d.ts +2 -0
- package/dist/translations/locales/is.js +11 -0
- package/dist/translations/locales/it.d.ts +2 -0
- package/dist/translations/locales/it.js +11 -0
- package/dist/translations/locales/ja.d.ts +2 -0
- package/dist/translations/locales/ja.js +11 -0
- package/dist/translations/locales/ko.d.ts +2 -0
- package/dist/translations/locales/ko.js +11 -0
- package/dist/translations/locales/lt.d.ts +2 -0
- package/dist/translations/locales/lt.js +11 -0
- package/dist/translations/locales/lv.d.ts +2 -0
- package/dist/translations/locales/lv.js +11 -0
- package/dist/translations/locales/my.d.ts +2 -0
- package/dist/translations/locales/my.js +11 -0
- package/dist/translations/locales/nb.d.ts +2 -0
- package/dist/translations/locales/nb.js +11 -0
- package/dist/translations/locales/nl.d.ts +2 -0
- package/dist/translations/locales/nl.js +11 -0
- package/dist/translations/locales/pl.d.ts +2 -0
- package/dist/translations/locales/pl.js +11 -0
- package/dist/translations/locales/pt.d.ts +2 -0
- package/dist/translations/locales/pt.js +11 -0
- package/dist/translations/locales/ro.d.ts +2 -0
- package/dist/translations/locales/ro.js +11 -0
- package/dist/translations/locales/rs.d.ts +2 -0
- package/dist/translations/locales/rs.js +11 -0
- package/dist/translations/locales/rsLatin.d.ts +2 -0
- package/dist/translations/locales/rsLatin.js +11 -0
- package/dist/translations/locales/ru.d.ts +2 -0
- package/dist/translations/locales/ru.js +11 -0
- package/dist/translations/locales/sk.d.ts +2 -0
- package/dist/translations/locales/sk.js +11 -0
- package/dist/translations/locales/sl.d.ts +2 -0
- package/dist/translations/locales/sl.js +11 -0
- package/dist/translations/locales/sv.d.ts +2 -0
- package/dist/translations/locales/sv.js +11 -0
- package/dist/translations/locales/ta.d.ts +2 -0
- package/dist/translations/locales/ta.js +11 -0
- package/dist/translations/locales/th.d.ts +2 -0
- package/dist/translations/locales/th.js +11 -0
- package/dist/translations/locales/tr.d.ts +2 -0
- package/dist/translations/locales/tr.js +11 -0
- package/dist/translations/locales/uk.d.ts +2 -0
- package/dist/translations/locales/uk.js +11 -0
- package/dist/translations/locales/vi.d.ts +2 -0
- package/dist/translations/locales/vi.js +11 -0
- package/dist/translations/locales/zh.d.ts +2 -0
- package/dist/translations/locales/zh.js +11 -0
- package/dist/translations/locales/zhTw.d.ts +2 -0
- package/dist/translations/locales/zhTw.js +11 -0
- package/dist/translations/types.d.ts +11 -0
- package/dist/translations/types.js +1 -0
- package/dist/types.d.ts +130 -0
- package/dist/types.js +2 -0
- package/dist/utils/insertField.d.ts +3 -0
- package/dist/utils/insertField.js +97 -0
- package/package.json +121 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const lt = {
|
|
2
|
+
'@seshuk/payload-media-preview': {
|
|
3
|
+
close: 'Uždaryti',
|
|
4
|
+
label: 'Peržiūra',
|
|
5
|
+
open: 'Atidaryti',
|
|
6
|
+
titleAudio: 'Garso peržiūra',
|
|
7
|
+
titleDocument: 'Dokumento peržiūra',
|
|
8
|
+
titleImage: 'Vaizdo peržiūra',
|
|
9
|
+
titleVideo: 'Video peržiūra'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const lv = {
|
|
2
|
+
'@seshuk/payload-media-preview': {
|
|
3
|
+
close: 'Aizvērt',
|
|
4
|
+
label: 'Priekšskatījums',
|
|
5
|
+
open: 'Atvērt',
|
|
6
|
+
titleAudio: 'Audio priekšskatījums',
|
|
7
|
+
titleDocument: 'Dokumenta priekšskatījums',
|
|
8
|
+
titleImage: 'Attēla priekšskatījums',
|
|
9
|
+
titleVideo: 'Video priekšskatījums'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const my = {
|
|
2
|
+
'@seshuk/payload-media-preview': {
|
|
3
|
+
close: 'ပိတ်မည်',
|
|
4
|
+
label: 'အစမ်းကြည့်ရှုခြင်း',
|
|
5
|
+
open: 'ဖွင့်မည်',
|
|
6
|
+
titleAudio: 'အသံ အကြိုကြည့်ရှုခြင်း',
|
|
7
|
+
titleDocument: 'စာရွက်စာတမ်း အကြိုကြည့်ရှုခြင်း',
|
|
8
|
+
titleImage: 'ပုံ အကြိုကြည့်ရှုခြင်း',
|
|
9
|
+
titleVideo: 'ဗီဒီယို အကြိုကြည့်ရှုခြင်း'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const nb = {
|
|
2
|
+
'@seshuk/payload-media-preview': {
|
|
3
|
+
close: 'Lukk',
|
|
4
|
+
label: 'Forhåndsvisning',
|
|
5
|
+
open: 'Åpne',
|
|
6
|
+
titleAudio: 'Lydforhåndsvisning',
|
|
7
|
+
titleDocument: 'Dokumentforhåndsvisning',
|
|
8
|
+
titleImage: 'Bildeforhåndsvisning',
|
|
9
|
+
titleVideo: 'Videoforhåndsvisning'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const nl = {
|
|
2
|
+
'@seshuk/payload-media-preview': {
|
|
3
|
+
close: 'Sluiten',
|
|
4
|
+
label: 'Voorbeeld',
|
|
5
|
+
open: 'Openen',
|
|
6
|
+
titleAudio: 'Audio preview',
|
|
7
|
+
titleDocument: 'Document preview',
|
|
8
|
+
titleImage: 'Afbeelding preview',
|
|
9
|
+
titleVideo: 'Video preview'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const pt = {
|
|
2
|
+
'@seshuk/payload-media-preview': {
|
|
3
|
+
close: 'Fechar',
|
|
4
|
+
label: 'Visualização',
|
|
5
|
+
open: 'Abrir',
|
|
6
|
+
titleAudio: 'Pré-visualização de áudio',
|
|
7
|
+
titleDocument: 'Pré-visualização de documento',
|
|
8
|
+
titleImage: 'Pré-visualização de imagem',
|
|
9
|
+
titleVideo: 'Pré-visualização de vídeo'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const ro = {
|
|
2
|
+
'@seshuk/payload-media-preview': {
|
|
3
|
+
close: 'Închide',
|
|
4
|
+
label: 'Previzualizare',
|
|
5
|
+
open: 'Deschide',
|
|
6
|
+
titleAudio: 'Previzualizare audio',
|
|
7
|
+
titleDocument: 'Previzualizare document',
|
|
8
|
+
titleImage: 'Previzualizare imagine',
|
|
9
|
+
titleVideo: 'Previzualizare video'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const rsLatin = {
|
|
2
|
+
'@seshuk/payload-media-preview': {
|
|
3
|
+
close: 'Zatvori',
|
|
4
|
+
label: 'Pregled',
|
|
5
|
+
open: 'Otvori',
|
|
6
|
+
titleAudio: 'Pregled audia',
|
|
7
|
+
titleDocument: 'Pregled dokumenta',
|
|
8
|
+
titleImage: 'Pregled slike',
|
|
9
|
+
titleVideo: 'Pregled videa'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const ru = {
|
|
2
|
+
'@seshuk/payload-media-preview': {
|
|
3
|
+
close: 'Закрыть',
|
|
4
|
+
label: 'Предпросмотр',
|
|
5
|
+
open: 'Открыть',
|
|
6
|
+
titleAudio: 'Предпросмотр аудио',
|
|
7
|
+
titleDocument: 'Предпросмотр документа',
|
|
8
|
+
titleImage: 'Предпросмотр изображения',
|
|
9
|
+
titleVideo: 'Предпросмотр видео'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const sl = {
|
|
2
|
+
'@seshuk/payload-media-preview': {
|
|
3
|
+
close: 'Zapri',
|
|
4
|
+
label: 'Predogled',
|
|
5
|
+
open: 'Odpri',
|
|
6
|
+
titleAudio: 'Predogled zvoka',
|
|
7
|
+
titleDocument: 'Predogled dokumenta',
|
|
8
|
+
titleImage: 'Predogled slike',
|
|
9
|
+
titleVideo: 'Predogled videa'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const sv = {
|
|
2
|
+
'@seshuk/payload-media-preview': {
|
|
3
|
+
close: 'Stäng',
|
|
4
|
+
label: 'Förhandsgranskning',
|
|
5
|
+
open: 'Öppna',
|
|
6
|
+
titleAudio: 'Ljudförhandsgranskning',
|
|
7
|
+
titleDocument: 'Dokumentförhandsgranskning',
|
|
8
|
+
titleImage: 'Bildförhandsgranskning',
|
|
9
|
+
titleVideo: 'Videoförhandsgranskning'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const ta = {
|
|
2
|
+
'@seshuk/payload-media-preview': {
|
|
3
|
+
close: 'மூடு',
|
|
4
|
+
label: 'முன்னோட்டம்',
|
|
5
|
+
open: 'திற',
|
|
6
|
+
titleAudio: 'ஆடியோ முன்னோட்டம்',
|
|
7
|
+
titleDocument: 'ஆவண முன்னோட்டம்',
|
|
8
|
+
titleImage: 'படம் முன்னோட்டம்',
|
|
9
|
+
titleVideo: 'வீடியோ முன்னோட்டம்'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const uk = {
|
|
2
|
+
'@seshuk/payload-media-preview': {
|
|
3
|
+
close: 'Закрити',
|
|
4
|
+
label: 'Попередній перегляд',
|
|
5
|
+
open: 'Відкрити',
|
|
6
|
+
titleAudio: 'Попередній перегляд аудіо',
|
|
7
|
+
titleDocument: 'Попередній перегляд документа',
|
|
8
|
+
titleImage: 'Попередній перегляд зображення',
|
|
9
|
+
titleVideo: 'Попередній перегляд відео'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const vi = {
|
|
2
|
+
'@seshuk/payload-media-preview': {
|
|
3
|
+
close: 'Đóng',
|
|
4
|
+
label: 'Xem trước',
|
|
5
|
+
open: 'Mở',
|
|
6
|
+
titleAudio: 'Xem trước âm thanh',
|
|
7
|
+
titleDocument: 'Xem trước tài liệu',
|
|
8
|
+
titleImage: 'Xem trước hình ảnh',
|
|
9
|
+
titleVideo: 'Xem trước video'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { Plugin, UIField, UploadCollectionSlug } from 'payload';
|
|
2
|
+
export type VideoViewerProps = {
|
|
3
|
+
autoPlay?: boolean;
|
|
4
|
+
className?: string;
|
|
5
|
+
controls?: boolean;
|
|
6
|
+
loop?: boolean;
|
|
7
|
+
mimeType?: string;
|
|
8
|
+
muted?: boolean;
|
|
9
|
+
preload?: 'auto' | 'metadata' | 'none';
|
|
10
|
+
src: string;
|
|
11
|
+
title?: string;
|
|
12
|
+
};
|
|
13
|
+
export type AudioViewerProps = {
|
|
14
|
+
autoPlay?: boolean;
|
|
15
|
+
className?: string;
|
|
16
|
+
controls?: boolean;
|
|
17
|
+
loop?: boolean;
|
|
18
|
+
mimeType?: string;
|
|
19
|
+
muted?: boolean;
|
|
20
|
+
preload?: 'auto' | 'metadata' | 'none';
|
|
21
|
+
src: string;
|
|
22
|
+
title?: string;
|
|
23
|
+
};
|
|
24
|
+
export type ImageViewerProps = {
|
|
25
|
+
alt?: string;
|
|
26
|
+
className?: string;
|
|
27
|
+
src: string;
|
|
28
|
+
};
|
|
29
|
+
export type IframeViewerProps = {
|
|
30
|
+
allow?: string;
|
|
31
|
+
allowFullScreen?: boolean;
|
|
32
|
+
className?: string;
|
|
33
|
+
loading?: 'eager' | 'lazy';
|
|
34
|
+
src: string;
|
|
35
|
+
title?: string;
|
|
36
|
+
};
|
|
37
|
+
export type MediaPreviewAdapterResolveArgs = {
|
|
38
|
+
doc: Record<string, unknown>;
|
|
39
|
+
mimeType?: string;
|
|
40
|
+
url?: string;
|
|
41
|
+
};
|
|
42
|
+
/** Returned by `resolve()` to render the adapter's component inside a modal. */
|
|
43
|
+
export type MediaPreviewAdapterInlineResult = {
|
|
44
|
+
mode: 'inline';
|
|
45
|
+
props: Record<string, unknown>;
|
|
46
|
+
};
|
|
47
|
+
/** Returned by `resolve()` to open a URL in a new browser tab. */
|
|
48
|
+
export type MediaPreviewAdapterNewTabResult = {
|
|
49
|
+
mode: 'newTab';
|
|
50
|
+
url: string;
|
|
51
|
+
};
|
|
52
|
+
export type MediaPreviewAdapterResolveResult = MediaPreviewAdapterInlineResult | MediaPreviewAdapterNewTabResult;
|
|
53
|
+
/** Adapters are tried in order — first non-null `resolve()` result wins. */
|
|
54
|
+
export type MediaPreviewAdapter = {
|
|
55
|
+
/**
|
|
56
|
+
* Import path for the viewer component (e.g. `'my-pkg/client#Player'`).
|
|
57
|
+
* Only needed when `resolve()` can return `mode: 'inline'`.
|
|
58
|
+
*/
|
|
59
|
+
Component?: string;
|
|
60
|
+
name: string;
|
|
61
|
+
/**
|
|
62
|
+
* Decide how to preview a document.
|
|
63
|
+
*
|
|
64
|
+
* - Return `{ mode: 'inline', props }` to render `Component` in a modal.
|
|
65
|
+
* - Return `{ mode: 'newTab', url }` to open a link in a new tab.
|
|
66
|
+
* - Return `null` to skip this adapter.
|
|
67
|
+
*/
|
|
68
|
+
resolve: (args: MediaPreviewAdapterResolveArgs) => MediaPreviewAdapterResolveResult | null;
|
|
69
|
+
};
|
|
70
|
+
export type InsertPosition = 'first' | 'last' | {
|
|
71
|
+
after: string;
|
|
72
|
+
before?: never;
|
|
73
|
+
} | {
|
|
74
|
+
after?: never;
|
|
75
|
+
before: string;
|
|
76
|
+
};
|
|
77
|
+
export type MediaPreviewContentType = 'audio' | 'document' | 'image' | 'video';
|
|
78
|
+
export type MediaPreviewContentModeType = 'inline' | 'newTab';
|
|
79
|
+
/** `'auto'` adapts to context and device, `'fullscreen'` always uses a modal. */
|
|
80
|
+
export type MediaPreviewMode = 'auto' | 'fullscreen';
|
|
81
|
+
/**
|
|
82
|
+
* Controls how each content type is opened.
|
|
83
|
+
*
|
|
84
|
+
* - `'inline'` — show content in a modal preview.
|
|
85
|
+
* - `'newTab'` — open content in a new browser tab.
|
|
86
|
+
*
|
|
87
|
+
* @default 'inline' for all content types
|
|
88
|
+
*/
|
|
89
|
+
export type MediaPreviewContentMode = Record<MediaPreviewContentType, MediaPreviewContentModeType>;
|
|
90
|
+
export type MediaPreviewFieldConfig = {
|
|
91
|
+
/** Payload UI field overrides (`name` and `type` cannot be changed). */
|
|
92
|
+
overrides?: Partial<Omit<UIField, 'name' | 'type'>>;
|
|
93
|
+
/** @default 'last' */
|
|
94
|
+
position?: InsertPosition;
|
|
95
|
+
};
|
|
96
|
+
export type MediaPreviewCollectionConfig = {
|
|
97
|
+
/** Overrides global adapters when set. */
|
|
98
|
+
adapters?: MediaPreviewAdapter[];
|
|
99
|
+
contentMode?: Partial<MediaPreviewContentMode>;
|
|
100
|
+
/**
|
|
101
|
+
* Controls field injection into the collection.
|
|
102
|
+
*
|
|
103
|
+
* - Omit or pass `{}` to inject with defaults.
|
|
104
|
+
* - Pass `{ position, overrides }` to customize the injected field.
|
|
105
|
+
* - Set to `false` to skip injection (for manual placement via `mediaPreviewField()`).
|
|
106
|
+
*/
|
|
107
|
+
field?: false | MediaPreviewFieldConfig;
|
|
108
|
+
/**
|
|
109
|
+
* Preview display mode.
|
|
110
|
+
*
|
|
111
|
+
* - `'auto'` — popup in cell (desktop), fullscreen in field and on mobile.
|
|
112
|
+
* - `'fullscreen'` — always fullscreen modal.
|
|
113
|
+
* @default 'auto'
|
|
114
|
+
*/
|
|
115
|
+
mode?: MediaPreviewMode;
|
|
116
|
+
};
|
|
117
|
+
export type MediaPreviewPluginConfig = {
|
|
118
|
+
/** Adapters available to all collections. */
|
|
119
|
+
adapters?: MediaPreviewAdapter[];
|
|
120
|
+
/** Use `true` for defaults or an object for fine-tuning. */
|
|
121
|
+
collections: Partial<Record<UploadCollectionSlug, MediaPreviewCollectionConfig | true>>;
|
|
122
|
+
/** @default true */
|
|
123
|
+
enabled?: boolean;
|
|
124
|
+
};
|
|
125
|
+
export type MediaPreviewPlugin = (pluginConfig: MediaPreviewPluginConfig) => Plugin;
|
|
126
|
+
export type MediaPreviewFieldProps = {
|
|
127
|
+
adapterNames?: string[];
|
|
128
|
+
contentMode?: Partial<MediaPreviewContentMode>;
|
|
129
|
+
mode?: MediaPreviewMode;
|
|
130
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export const insertField = (fields, position, fieldToInsert)=>{
|
|
2
|
+
if (position === 'first') {
|
|
3
|
+
return [
|
|
4
|
+
fieldToInsert,
|
|
5
|
+
...fields
|
|
6
|
+
];
|
|
7
|
+
}
|
|
8
|
+
if (position === 'last') {
|
|
9
|
+
return [
|
|
10
|
+
...fields,
|
|
11
|
+
fieldToInsert
|
|
12
|
+
];
|
|
13
|
+
}
|
|
14
|
+
if ('after' in position && position.after) {
|
|
15
|
+
return insertFieldByPath(fields, position.after, fieldToInsert, 'after');
|
|
16
|
+
}
|
|
17
|
+
if ('before' in position && position.before) {
|
|
18
|
+
return insertFieldByPath(fields, position.before, fieldToInsert, 'before');
|
|
19
|
+
}
|
|
20
|
+
return fields;
|
|
21
|
+
};
|
|
22
|
+
const insertFieldByPath = (fields, targetPath, fieldToInsert, placement)=>{
|
|
23
|
+
const pathParts = targetPath.split('.');
|
|
24
|
+
const [currentPart, ...remainingParts] = pathParts;
|
|
25
|
+
if (remainingParts.length === 0) {
|
|
26
|
+
const targetIndex = fields.findIndex((f)=>'name' in f && f.name === currentPart);
|
|
27
|
+
if (targetIndex !== -1) {
|
|
28
|
+
const insertIndex = placement === 'before' ? targetIndex : targetIndex + 1;
|
|
29
|
+
return [
|
|
30
|
+
...fields.slice(0, insertIndex),
|
|
31
|
+
fieldToInsert,
|
|
32
|
+
...fields.slice(insertIndex)
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
return fields;
|
|
36
|
+
}
|
|
37
|
+
return fields.map((field)=>{
|
|
38
|
+
if ('name' in field && field.name === currentPart) {
|
|
39
|
+
const remainingPath = remainingParts.join('.');
|
|
40
|
+
if ('fields' in field && Array.isArray(field.fields)) {
|
|
41
|
+
return {
|
|
42
|
+
...field,
|
|
43
|
+
fields: insertFieldByPath(field.fields, remainingPath, fieldToInsert, placement)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if ('tabs' in field && Array.isArray(field.tabs)) {
|
|
47
|
+
const tabIndex = parseInt(remainingParts[0]);
|
|
48
|
+
if (!isNaN(tabIndex) && field.tabs[tabIndex]) {
|
|
49
|
+
const tabRemainingPath = remainingParts.slice(1).join('.');
|
|
50
|
+
const updatedTabs = [
|
|
51
|
+
...field.tabs
|
|
52
|
+
];
|
|
53
|
+
if ('fields' in updatedTabs[tabIndex] && Array.isArray(updatedTabs[tabIndex].fields)) {
|
|
54
|
+
updatedTabs[tabIndex] = {
|
|
55
|
+
...updatedTabs[tabIndex],
|
|
56
|
+
fields: insertFieldByPath(updatedTabs[tabIndex].fields, tabRemainingPath, fieldToInsert, placement)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
...field,
|
|
61
|
+
tabs: updatedTabs
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if ('fields' in field && Array.isArray(field.fields)) {
|
|
67
|
+
const updatedFields = insertFieldByPath(field.fields, targetPath, fieldToInsert, placement);
|
|
68
|
+
if (updatedFields !== field.fields) {
|
|
69
|
+
return {
|
|
70
|
+
...field,
|
|
71
|
+
fields: updatedFields
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if ('tabs' in field && Array.isArray(field.tabs)) {
|
|
76
|
+
const updatedTabs = field.tabs.map((tab)=>{
|
|
77
|
+
if ('fields' in tab && Array.isArray(tab.fields)) {
|
|
78
|
+
const updatedFields = insertFieldByPath(tab.fields, targetPath, fieldToInsert, placement);
|
|
79
|
+
if (updatedFields !== tab.fields) {
|
|
80
|
+
return {
|
|
81
|
+
...tab,
|
|
82
|
+
fields: updatedFields
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return tab;
|
|
87
|
+
});
|
|
88
|
+
if (JSON.stringify(updatedTabs) !== JSON.stringify(field.tabs)) {
|
|
89
|
+
return {
|
|
90
|
+
...field,
|
|
91
|
+
tabs: updatedTabs
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return field;
|
|
96
|
+
});
|
|
97
|
+
};
|