@soppiya/app-bridge 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/README.md +23 -0
- package/dist/assets/images/docs.js +2 -0
- package/dist/assets/images/document.js +2 -0
- package/dist/assets/images/pdf.js +2 -0
- package/dist/assets/images/play.js +2 -0
- package/dist/assets/images/ppt.js +2 -0
- package/dist/assets/images/rar.js +2 -0
- package/dist/assets/images/sound.js +2 -0
- package/dist/assets/images/txt.js +2 -0
- package/dist/assets/images/xls.js +2 -0
- package/dist/assets/images/zip.js +2 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +3 -0
- package/dist/components/infinity-scroll/InfinityScroll.d.ts +5 -0
- package/dist/components/infinity-scroll/InfinityScroll.js +29 -0
- package/dist/components/infinity-scroll/index.d.ts +1 -0
- package/dist/components/infinity-scroll/index.js +2 -0
- package/dist/components/media/Media.d.ts +11 -0
- package/dist/components/media/Media.js +349 -0
- package/dist/components/media/Media.stories.d.ts +18 -0
- package/dist/components/media/Media.stories.js +13 -0
- package/dist/components/media/MediaItem.d.ts +12 -0
- package/dist/components/media/MediaItem.js +104 -0
- package/dist/components/media/MediaPreview.d.ts +7 -0
- package/dist/components/media/MediaPreview.js +127 -0
- package/dist/components/media/MediaSorting.d.ts +8 -0
- package/dist/components/media/MediaSorting.js +85 -0
- package/dist/components/media/format.d.ts +1 -0
- package/dist/components/media/format.js +28 -0
- package/dist/components/media/graph.d.ts +22 -0
- package/dist/components/media/graph.js +75 -0
- package/dist/components/media/index.d.ts +1 -0
- package/dist/components/media/index.js +2 -0
- package/dist/components/media/types.d.ts +13 -0
- package/dist/components/media/types.js +6 -0
- package/dist/components/media/uploadMedias.d.ts +7 -0
- package/dist/components/media/uploadMedias.js +31 -0
- package/dist/components/media/useDeleteMedias.d.ts +7 -0
- package/dist/components/media/useDeleteMedias.js +14 -0
- package/dist/components/media/useDrop.d.ts +11 -0
- package/dist/components/media/useDrop.js +41 -0
- package/dist/components/media/useMediaFilter.d.ts +5 -0
- package/dist/components/media/useMediaFilter.js +15 -0
- package/dist/components/media/useMediaSorting.d.ts +6 -0
- package/dist/components/media/useMediaSorting.js +19 -0
- package/dist/components/media/useMedias.d.ts +31 -0
- package/dist/components/media/useMedias.js +58 -0
- package/dist/components/media/useStorage.d.ts +8 -0
- package/dist/components/media/useStorage.js +17 -0
- package/dist/components/media/useThumbnail.d.ts +5 -0
- package/dist/components/media/useThumbnail.js +64 -0
- package/dist/components/savebar/SaveBar.d.ts +9 -0
- package/dist/components/savebar/SaveBar.js +21 -0
- package/dist/components/savebar/index.d.ts +1 -0
- package/dist/components/savebar/index.js +2 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/useSoppiyaBridge.d.ts +3 -0
- package/dist/hooks/useSoppiyaBridge.js +9 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/shared/graphql/fragment-masking.d.ts +19 -0
- package/dist/shared/graphql/fragment-masking.js +15 -0
- package/dist/shared/graphql/gql.d.ts +56 -0
- package/dist/shared/graphql/gql.js +12 -0
- package/dist/shared/graphql/graphql.d.ts +3881 -0
- package/dist/shared/graphql/graphql.js +1226 -0
- package/dist/shared/graphql/index.d.ts +2 -0
- package/dist/shared/graphql/index.js +2 -0
- package/dist/static/image/docs.png +0 -0
- package/dist/static/image/document.png +0 -0
- package/dist/static/image/pdf.png +0 -0
- package/dist/static/image/play.png +0 -0
- package/dist/static/image/ppt.png +0 -0
- package/dist/static/image/rar.png +0 -0
- package/dist/static/image/sound.png +0 -0
- package/dist/static/image/txt.png +0 -0
- package/dist/static/image/xls.png +0 -0
- package/dist/static/image/zip.png +0 -0
- package/dist/styles.css +869 -0
- package/package.json +66 -0
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Rslib project
|
|
2
|
+
|
|
3
|
+
## Setup
|
|
4
|
+
|
|
5
|
+
Install the dependencies:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm install
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Get started
|
|
12
|
+
|
|
13
|
+
Build the library:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm build
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Build the library in watch mode:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm dev
|
|
23
|
+
```
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { BlockStack, Spinner } from "@soppiya/elementus";
|
|
3
|
+
import { useIntersectionObserver } from "@uidotdev/usehooks";
|
|
4
|
+
import { useEffect } from "react";
|
|
5
|
+
const InfinityScroll = ({ onFetch })=>{
|
|
6
|
+
const [ref, entry] = useIntersectionObserver({
|
|
7
|
+
threshold: 0,
|
|
8
|
+
root: null,
|
|
9
|
+
rootMargin: "0px"
|
|
10
|
+
});
|
|
11
|
+
const isIntersecting = entry?.isIntersecting;
|
|
12
|
+
useEffect(()=>{
|
|
13
|
+
if (isIntersecting) onFetch();
|
|
14
|
+
}, [
|
|
15
|
+
isIntersecting,
|
|
16
|
+
onFetch
|
|
17
|
+
]);
|
|
18
|
+
return /*#__PURE__*/ jsx(BlockStack, {
|
|
19
|
+
ref: ref,
|
|
20
|
+
justifyContent: "center",
|
|
21
|
+
alignItems: "center",
|
|
22
|
+
className: "p-5",
|
|
23
|
+
children: /*#__PURE__*/ jsx(Spinner, {
|
|
24
|
+
size: "md"
|
|
25
|
+
})
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const infinity_scroll_InfinityScroll = InfinityScroll;
|
|
29
|
+
export { infinity_scroll_InfinityScroll as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as InfinityScroll } from "./InfinityScroll";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MediaType } from "../../shared/graphql/graphql";
|
|
2
|
+
type MediaProps = {
|
|
3
|
+
title?: string;
|
|
4
|
+
types?: MediaType[];
|
|
5
|
+
limit?: number;
|
|
6
|
+
isFilterByTypes?: boolean;
|
|
7
|
+
onClose?: () => void;
|
|
8
|
+
onOk?: (medias: string[]) => void;
|
|
9
|
+
};
|
|
10
|
+
declare const Media: ({ title, types, isFilterByTypes, limit, onClose, onOk, }: MediaProps) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export default Media;
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { MediaType } from "../../shared/graphql/graphql.js";
|
|
3
|
+
import { CombinedGraphQLErrors } from "@apollo/client";
|
|
4
|
+
import { BlockStack, Box, Button, InlineStack, Input, Modal, ProgressBar, SoppiyaIcon, Spinner, Text } from "@soppiya/elementus";
|
|
5
|
+
import classnames from "classnames";
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { Bounce, ToastContainer, toast } from "react-toastify";
|
|
8
|
+
import { InfinityScroll } from "../infinity-scroll/index.js";
|
|
9
|
+
import { formatToBytes } from "./format.js";
|
|
10
|
+
import MediaItem from "./MediaItem.js";
|
|
11
|
+
import MediaPreview from "./MediaPreview.js";
|
|
12
|
+
import MediaSorting from "./MediaSorting.js";
|
|
13
|
+
import { View } from "./types.js";
|
|
14
|
+
import { useUploadMedias } from "./uploadMedias.js";
|
|
15
|
+
import { useDeleteMedias } from "./useDeleteMedias.js";
|
|
16
|
+
import { useDrop } from "./useDrop.js";
|
|
17
|
+
import { useMediaFilter } from "./useMediaFilter.js";
|
|
18
|
+
import { useMedias } from "./useMedias.js";
|
|
19
|
+
import { useMediaSorting } from "./useMediaSorting.js";
|
|
20
|
+
import { useStorage } from "./useStorage.js";
|
|
21
|
+
const Media_Media = ({ title = "Media", types = [
|
|
22
|
+
MediaType.audio,
|
|
23
|
+
MediaType.file,
|
|
24
|
+
MediaType.image,
|
|
25
|
+
MediaType.video
|
|
26
|
+
], isFilterByTypes = false, limit = 1 / 0, onClose, onOk })=>{
|
|
27
|
+
const { query, debounceQuery, onChangeQuery } = useMediaFilter();
|
|
28
|
+
const { sorting, onChangeSorting } = useMediaSorting();
|
|
29
|
+
const [selectedMedias, setSelectedMedias] = useState([]);
|
|
30
|
+
const [preview, setPreview] = useState(null);
|
|
31
|
+
const [view, setView] = useState(View.Grid);
|
|
32
|
+
const { medias, isLoadingMedias, isFetchingMore, pageInfo, fetchMoreMedias } = useMedias({
|
|
33
|
+
count: 20,
|
|
34
|
+
query: debounceQuery,
|
|
35
|
+
reverse: sorting.reverse,
|
|
36
|
+
sortKey: sorting.sortKey,
|
|
37
|
+
...isFilterByTypes && {
|
|
38
|
+
filterKeys: {
|
|
39
|
+
types
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
const { usageStorage, mediaUsage, totalStorage, refetchMediaUsage } = useStorage();
|
|
44
|
+
const { isUploadingMedias, uploadMedias } = useUploadMedias();
|
|
45
|
+
const { deleteMedias, isDeletingMedias } = useDeleteMedias();
|
|
46
|
+
const { ref, onChangeFile, onDrop, onDragOver } = useDrop({
|
|
47
|
+
async onComplete (files) {
|
|
48
|
+
try {
|
|
49
|
+
await uploadMedias({
|
|
50
|
+
variables: {
|
|
51
|
+
input: files.map((file)=>file.file)
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
refetchMediaUsage();
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (CombinedGraphQLErrors.is(error)) toast(error.message);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const isMediaSelected = selectedMedias.length > 0;
|
|
61
|
+
const activePreviewMedia = medias.find((media)=>media?._id === preview);
|
|
62
|
+
const handlePreview = (value)=>{
|
|
63
|
+
setPreview((prev)=>value && prev !== value ? value : null);
|
|
64
|
+
};
|
|
65
|
+
const toggleView = ()=>{
|
|
66
|
+
setView((prev)=>prev === View.Grid ? View.List : View.Grid);
|
|
67
|
+
};
|
|
68
|
+
const handleSelectMedia = (media)=>{
|
|
69
|
+
if (selectedMedias.some((mediaId)=>mediaId === media)) return void setSelectedMedias((prev)=>prev.filter((mediaId)=>mediaId !== media));
|
|
70
|
+
setSelectedMedias((prev)=>prev.concat(media));
|
|
71
|
+
};
|
|
72
|
+
const handleDeleteMedias = async ()=>{
|
|
73
|
+
try {
|
|
74
|
+
await deleteMedias({
|
|
75
|
+
variables: {
|
|
76
|
+
cursors: selectedMedias
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
refetchMediaUsage();
|
|
80
|
+
setSelectedMedias([]);
|
|
81
|
+
if (selectedMedias.includes(String(preview))) setPreview(null);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
if (CombinedGraphQLErrors.is(error)) toast(error.message);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const handleOk = ()=>{
|
|
87
|
+
if ("function" == typeof onOk) onOk(selectedMedias);
|
|
88
|
+
};
|
|
89
|
+
const isValidMedia = ()=>{
|
|
90
|
+
if (!isMediaSelected) return false;
|
|
91
|
+
const isTypeMatch = medias?.every((media)=>selectedMedias.includes(String(media?._id)) ? types.includes(media?.type) : true);
|
|
92
|
+
if (!isTypeMatch) return false;
|
|
93
|
+
if (limit === 1 / 0) return true;
|
|
94
|
+
return selectedMedias.length <= limit;
|
|
95
|
+
};
|
|
96
|
+
const modalFooterJSX = /*#__PURE__*/ jsxs(InlineStack, {
|
|
97
|
+
justifyContent: "space-between",
|
|
98
|
+
alignItems: "center",
|
|
99
|
+
children: [
|
|
100
|
+
/*#__PURE__*/ jsxs(BlockStack, {
|
|
101
|
+
className: "!max-w-[150px] w-full",
|
|
102
|
+
gapY: 30,
|
|
103
|
+
children: [
|
|
104
|
+
/*#__PURE__*/ jsxs(InlineStack, {
|
|
105
|
+
alignItems: "center",
|
|
106
|
+
gapX: 40,
|
|
107
|
+
children: [
|
|
108
|
+
/*#__PURE__*/ jsx(SoppiyaIcon, {
|
|
109
|
+
icon: "upload-02.svg",
|
|
110
|
+
size: "md"
|
|
111
|
+
}),
|
|
112
|
+
/*#__PURE__*/ jsxs(Text, {
|
|
113
|
+
size: "sm",
|
|
114
|
+
weight: "semibold",
|
|
115
|
+
color: "secondary",
|
|
116
|
+
children: [
|
|
117
|
+
formatToBytes(mediaUsage, 2),
|
|
118
|
+
" / ",
|
|
119
|
+
formatToBytes(totalStorage, 2)
|
|
120
|
+
]
|
|
121
|
+
})
|
|
122
|
+
]
|
|
123
|
+
}),
|
|
124
|
+
/*#__PURE__*/ jsx(ProgressBar, {
|
|
125
|
+
accept: `${usageStorage}%`
|
|
126
|
+
})
|
|
127
|
+
]
|
|
128
|
+
}),
|
|
129
|
+
/*#__PURE__*/ jsx(InlineStack, {
|
|
130
|
+
gapX: 60,
|
|
131
|
+
stack: "full",
|
|
132
|
+
justifyContent: "end",
|
|
133
|
+
children: /*#__PURE__*/ jsx(Button, {
|
|
134
|
+
size: "xs",
|
|
135
|
+
disabled: !isValidMedia(),
|
|
136
|
+
onClick: handleOk,
|
|
137
|
+
children: "Done"
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
]
|
|
141
|
+
});
|
|
142
|
+
return /*#__PURE__*/ jsxs(Modal, {
|
|
143
|
+
title: title,
|
|
144
|
+
open: true,
|
|
145
|
+
size: "lg",
|
|
146
|
+
scroll: false,
|
|
147
|
+
bodyPadding: 0,
|
|
148
|
+
buttons: modalFooterJSX,
|
|
149
|
+
onClose: onClose,
|
|
150
|
+
children: [
|
|
151
|
+
/*#__PURE__*/ jsx(ToastContainer, {
|
|
152
|
+
position: "bottom-center",
|
|
153
|
+
autoClose: 5000,
|
|
154
|
+
hideProgressBar: false,
|
|
155
|
+
newestOnTop: false,
|
|
156
|
+
closeOnClick: false,
|
|
157
|
+
rtl: false,
|
|
158
|
+
pauseOnFocusLoss: true,
|
|
159
|
+
draggable: true,
|
|
160
|
+
pauseOnHover: true,
|
|
161
|
+
theme: "dark",
|
|
162
|
+
transition: Bounce
|
|
163
|
+
}),
|
|
164
|
+
/*#__PURE__*/ jsxs(BlockStack, {
|
|
165
|
+
className: "relative z",
|
|
166
|
+
onDrop: onDrop,
|
|
167
|
+
onDragOver: onDragOver,
|
|
168
|
+
children: [
|
|
169
|
+
/*#__PURE__*/ jsx(BlockStack, {
|
|
170
|
+
padding: 80,
|
|
171
|
+
gapY: 30,
|
|
172
|
+
children: /*#__PURE__*/ jsxs(InlineStack, {
|
|
173
|
+
justifyContent: "space-between",
|
|
174
|
+
stack: "full",
|
|
175
|
+
children: [
|
|
176
|
+
/*#__PURE__*/ jsx(Box, {
|
|
177
|
+
className: "w-[207px] lg:w-[300px]",
|
|
178
|
+
children: /*#__PURE__*/ jsx(Input, {
|
|
179
|
+
size: "sm",
|
|
180
|
+
type: "search",
|
|
181
|
+
placeholder: "Search files",
|
|
182
|
+
value: query,
|
|
183
|
+
onChange: (event)=>onChangeQuery(event.target.value)
|
|
184
|
+
})
|
|
185
|
+
}),
|
|
186
|
+
/*#__PURE__*/ jsxs(InlineStack, {
|
|
187
|
+
gap: 50,
|
|
188
|
+
flexWrap: "wrap",
|
|
189
|
+
justifyContent: "end",
|
|
190
|
+
children: [
|
|
191
|
+
/*#__PURE__*/ jsxs(Box, {
|
|
192
|
+
children: [
|
|
193
|
+
/*#__PURE__*/ jsx(Button, {
|
|
194
|
+
color: "primary",
|
|
195
|
+
className: "!px-[8px]",
|
|
196
|
+
onClick: ()=>ref.current?.click(),
|
|
197
|
+
children: /*#__PURE__*/ jsx(SoppiyaIcon, {
|
|
198
|
+
size: "sm",
|
|
199
|
+
icon: "plus.svg",
|
|
200
|
+
color: "white"
|
|
201
|
+
})
|
|
202
|
+
}),
|
|
203
|
+
/*#__PURE__*/ jsx("input", {
|
|
204
|
+
className: "hidden",
|
|
205
|
+
type: "file",
|
|
206
|
+
onChange: onChangeFile,
|
|
207
|
+
multiple: true,
|
|
208
|
+
ref: ref,
|
|
209
|
+
accept: [
|
|
210
|
+
"jpg",
|
|
211
|
+
"png",
|
|
212
|
+
"svg",
|
|
213
|
+
"gif",
|
|
214
|
+
"avif",
|
|
215
|
+
"webp",
|
|
216
|
+
"heic",
|
|
217
|
+
"mp4",
|
|
218
|
+
"avi",
|
|
219
|
+
"mkv",
|
|
220
|
+
"mov",
|
|
221
|
+
"webm",
|
|
222
|
+
"mpeg",
|
|
223
|
+
"ogv",
|
|
224
|
+
"flv",
|
|
225
|
+
"pdf",
|
|
226
|
+
"zip",
|
|
227
|
+
"rar",
|
|
228
|
+
"doc",
|
|
229
|
+
"docx",
|
|
230
|
+
"ppt",
|
|
231
|
+
"pptx",
|
|
232
|
+
"xls",
|
|
233
|
+
"xlsx",
|
|
234
|
+
"rtf",
|
|
235
|
+
"txt",
|
|
236
|
+
"mp3",
|
|
237
|
+
"wav",
|
|
238
|
+
"aac",
|
|
239
|
+
"ogg",
|
|
240
|
+
"m4a"
|
|
241
|
+
].map((type)=>"." + type).join(",")
|
|
242
|
+
})
|
|
243
|
+
]
|
|
244
|
+
}),
|
|
245
|
+
/*#__PURE__*/ jsx(MediaSorting, {
|
|
246
|
+
sort: sorting,
|
|
247
|
+
onChange: onChangeSorting
|
|
248
|
+
}),
|
|
249
|
+
/*#__PURE__*/ jsx(Box, {
|
|
250
|
+
children: /*#__PURE__*/ jsx(Button, {
|
|
251
|
+
variant: "outline",
|
|
252
|
+
color: "secondary",
|
|
253
|
+
className: "!px-[8px]",
|
|
254
|
+
onClick: toggleView,
|
|
255
|
+
children: /*#__PURE__*/ jsx(SoppiyaIcon, {
|
|
256
|
+
size: "sm",
|
|
257
|
+
icon: view === View.Grid ? "list-01.svg" : "grid.svg"
|
|
258
|
+
})
|
|
259
|
+
})
|
|
260
|
+
}),
|
|
261
|
+
/*#__PURE__*/ jsx(Box, {
|
|
262
|
+
children: /*#__PURE__*/ jsx(Button, {
|
|
263
|
+
variant: "outline",
|
|
264
|
+
color: "secondary",
|
|
265
|
+
className: "!px-[8px]",
|
|
266
|
+
disabled: !isMediaSelected,
|
|
267
|
+
loading: isDeletingMedias,
|
|
268
|
+
onClick: handleDeleteMedias,
|
|
269
|
+
children: /*#__PURE__*/ jsx(SoppiyaIcon, {
|
|
270
|
+
size: "sm",
|
|
271
|
+
icon: "delete-02.svg",
|
|
272
|
+
color: isMediaSelected ? "danger" : "secondary"
|
|
273
|
+
})
|
|
274
|
+
})
|
|
275
|
+
})
|
|
276
|
+
]
|
|
277
|
+
})
|
|
278
|
+
]
|
|
279
|
+
})
|
|
280
|
+
}),
|
|
281
|
+
(isUploadingMedias || isDeletingMedias) && /*#__PURE__*/ jsx(BlockStack, {
|
|
282
|
+
justifyContent: "center",
|
|
283
|
+
alignItems: "center",
|
|
284
|
+
className: "absolute h-full w-full z-1 bg-gray-400 opacity-50",
|
|
285
|
+
children: /*#__PURE__*/ jsx(Spinner, {
|
|
286
|
+
size: "lg"
|
|
287
|
+
})
|
|
288
|
+
}),
|
|
289
|
+
isLoadingMedias && !isFetchingMore ? /*#__PURE__*/ jsx(BlockStack, {
|
|
290
|
+
justifyContent: "center",
|
|
291
|
+
alignItems: "center",
|
|
292
|
+
className: "absolute h-full w-full z-1 bg-gray-400 opacity-50",
|
|
293
|
+
children: /*#__PURE__*/ jsx(Spinner, {
|
|
294
|
+
size: "lg"
|
|
295
|
+
})
|
|
296
|
+
}) : /*#__PURE__*/ jsxs(InlineStack, {
|
|
297
|
+
gapX: {
|
|
298
|
+
xs: 0,
|
|
299
|
+
md: 70,
|
|
300
|
+
lg: 80
|
|
301
|
+
},
|
|
302
|
+
padding: {
|
|
303
|
+
px: 80
|
|
304
|
+
},
|
|
305
|
+
stack: "full",
|
|
306
|
+
alignItems: "initial",
|
|
307
|
+
children: [
|
|
308
|
+
/*#__PURE__*/ jsxs(BlockStack, {
|
|
309
|
+
gapY: 90,
|
|
310
|
+
className: classnames("max-h-[calc(100dvh-300px)] overflow-x-hidden overflow-y-auto [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden", {
|
|
311
|
+
"md:!w-[calc(100%-300px)] lg:!w-[calc(100%-336px)]": Boolean(preview)
|
|
312
|
+
}),
|
|
313
|
+
children: [
|
|
314
|
+
/*#__PURE__*/ jsx(Box, {
|
|
315
|
+
className: `mx-auto ${preview ? "md:w-[395px] lg:w-[444px]" : "w-[320px] md:w-[708px] lg:w-[780px] "}`,
|
|
316
|
+
children: /*#__PURE__*/ jsx(Box, {
|
|
317
|
+
className: classnames("grid", {
|
|
318
|
+
"grid-cols-[repeat(1,1fr)]": view === View.List,
|
|
319
|
+
"grid-cols-[repeat(auto-fill,minmax(150px,1fr))] md:grid-cols-[repeat(auto-fill,minmax(117px,1fr))] !rounded-[6px] gap-[20px] lg:gap-[35px]": view === View.Grid,
|
|
320
|
+
"gap-[20px]": view === View.Grid && Boolean(preview)
|
|
321
|
+
}),
|
|
322
|
+
children: medias.map((media)=>/*#__PURE__*/ jsx(MediaItem, {
|
|
323
|
+
view: view,
|
|
324
|
+
media: media,
|
|
325
|
+
isSelected: selectedMedias.includes(String(media?._id)),
|
|
326
|
+
isPreview: Boolean(preview),
|
|
327
|
+
onPreview: handlePreview,
|
|
328
|
+
onSelect: handleSelectMedia
|
|
329
|
+
}, media?._id))
|
|
330
|
+
})
|
|
331
|
+
}),
|
|
332
|
+
pageInfo?.hasNextPage && /*#__PURE__*/ jsx(InfinityScroll, {
|
|
333
|
+
onFetch: fetchMoreMedias
|
|
334
|
+
})
|
|
335
|
+
]
|
|
336
|
+
}),
|
|
337
|
+
!!preview && /*#__PURE__*/ jsx(MediaPreview, {
|
|
338
|
+
media: activePreviewMedia,
|
|
339
|
+
onClose: handlePreview
|
|
340
|
+
})
|
|
341
|
+
]
|
|
342
|
+
})
|
|
343
|
+
]
|
|
344
|
+
})
|
|
345
|
+
]
|
|
346
|
+
});
|
|
347
|
+
};
|
|
348
|
+
const Media = Media_Media;
|
|
349
|
+
export { Media as default };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare const meta: {
|
|
2
|
+
title: string;
|
|
3
|
+
component: ({ title, types, isFilterByTypes, limit, onClose, onOk, }: {
|
|
4
|
+
title?: string;
|
|
5
|
+
types?: import("../../shared/graphql/graphql").MediaType[];
|
|
6
|
+
limit?: number;
|
|
7
|
+
isFilterByTypes?: boolean;
|
|
8
|
+
onClose?: () => void;
|
|
9
|
+
onOk?: (medias: string[]) => void;
|
|
10
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
};
|
|
12
|
+
export default meta;
|
|
13
|
+
export declare const Default: {
|
|
14
|
+
args: {
|
|
15
|
+
primary: boolean;
|
|
16
|
+
label: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Maybe, Media } from "../../shared/graphql/graphql";
|
|
2
|
+
import { View } from "./types";
|
|
3
|
+
type MediaItemProps = {
|
|
4
|
+
view: View;
|
|
5
|
+
media?: Maybe<Media>;
|
|
6
|
+
isPreview: boolean;
|
|
7
|
+
isSelected: boolean;
|
|
8
|
+
onPreview: (value?: string | null) => void;
|
|
9
|
+
onSelect: (value: string) => void;
|
|
10
|
+
};
|
|
11
|
+
declare const MediaItem: ({ view, media, isPreview, isSelected, onPreview, onSelect }: MediaItemProps) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export default MediaItem;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import play from "../../assets/images/play.js";
|
|
3
|
+
import { BlockStack, Box, Button, InlineStack, SoppiyaIcon, Spinner, Text } from "@soppiya/elementus";
|
|
4
|
+
import classnames from "classnames";
|
|
5
|
+
import { View } from "./types.js";
|
|
6
|
+
import { useThumbnail } from "./useThumbnail.js";
|
|
7
|
+
const MediaItem = ({ view, media, isPreview = false, isSelected = false, onPreview, onSelect })=>{
|
|
8
|
+
const { url, loading } = useThumbnail(media);
|
|
9
|
+
return /*#__PURE__*/ jsxs(InlineStack, {
|
|
10
|
+
flexDirection: view === View.Grid ? "col" : "row",
|
|
11
|
+
className: classnames("group p-[10px]", {
|
|
12
|
+
"w-full gap-x-[12px] border-b border-b-[#ebebeb] last:border-b-0 lg:cursor-pointer relative hover:!bg-[#f7f7f7]": view === View.List,
|
|
13
|
+
"w-[150px] h-[180px] md:h-[150px] lg:h-[154px] md:w-[117px] lg:w-[128px]": view === View.Grid,
|
|
14
|
+
"bg-[#ebebeb]": isSelected
|
|
15
|
+
}),
|
|
16
|
+
onClick: ()=>onSelect(String(media?._id)),
|
|
17
|
+
children: [
|
|
18
|
+
/*#__PURE__*/ jsxs(Box, {
|
|
19
|
+
className: classnames("relative", {
|
|
20
|
+
"w-[50px] h-[50px]": view === View.List,
|
|
21
|
+
"w-[130px] md:w-[100px] lg:w-[108px] h-[130px] md:h-[100px] lg:h-[108px]": view === View.Grid
|
|
22
|
+
}),
|
|
23
|
+
children: [
|
|
24
|
+
media?.type === "image" || media?.type === "video" ? /*#__PURE__*/ jsxs(Box, {
|
|
25
|
+
className: "relative w-full h-full",
|
|
26
|
+
children: [
|
|
27
|
+
loading && /*#__PURE__*/ jsx(BlockStack, {
|
|
28
|
+
justifyContent: "center",
|
|
29
|
+
alignItems: "center",
|
|
30
|
+
className: "absolute left-0 top-o z-1 backdrop-blur-xs h-full",
|
|
31
|
+
children: /*#__PURE__*/ jsx(Spinner, {
|
|
32
|
+
size: "lg"
|
|
33
|
+
})
|
|
34
|
+
}),
|
|
35
|
+
media?.type === "video" && /*#__PURE__*/ jsx(BlockStack, {
|
|
36
|
+
justifyContent: "center",
|
|
37
|
+
alignItems: "center",
|
|
38
|
+
className: "absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2",
|
|
39
|
+
children: /*#__PURE__*/ jsx("img", {
|
|
40
|
+
src: play,
|
|
41
|
+
className: "object-cover w-[50px] invert brightness-0",
|
|
42
|
+
alt: "video"
|
|
43
|
+
})
|
|
44
|
+
}),
|
|
45
|
+
/*#__PURE__*/ jsx("img", {
|
|
46
|
+
className: "w-full h-full object-cover rounded-[5px]",
|
|
47
|
+
src: String(url)
|
|
48
|
+
})
|
|
49
|
+
]
|
|
50
|
+
}) : /*#__PURE__*/ jsx(Box, {
|
|
51
|
+
className: "w-full h-full flex justify-center items-center border border-dashed-[#ebebeb]",
|
|
52
|
+
children: /*#__PURE__*/ jsx("img", {
|
|
53
|
+
className: "w-[50px] h-[50px] object-cover rounded-[5px]",
|
|
54
|
+
src: String(url)
|
|
55
|
+
})
|
|
56
|
+
}),
|
|
57
|
+
view === View.Grid && /*#__PURE__*/ jsx(Box, {
|
|
58
|
+
className: "hidden group-hover:block absolute top-1 right-1",
|
|
59
|
+
children: /*#__PURE__*/ jsx(Button, {
|
|
60
|
+
color: "white",
|
|
61
|
+
size: "xs",
|
|
62
|
+
className: "!px-[5px] !border-0 !rounded-[3px]",
|
|
63
|
+
onClick: (event)=>{
|
|
64
|
+
event.stopPropagation();
|
|
65
|
+
onPreview(media?._id);
|
|
66
|
+
},
|
|
67
|
+
children: /*#__PURE__*/ jsx(SoppiyaIcon, {
|
|
68
|
+
icon: isPreview ? "eye-close.svg" : "eye-open.svg",
|
|
69
|
+
size: "sm"
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
]
|
|
74
|
+
}),
|
|
75
|
+
view === View.List && /*#__PURE__*/ jsx(Box, {
|
|
76
|
+
className: "hidden group-hover:block absolute right-4 top-1/2 -translate-y-1/2",
|
|
77
|
+
children: /*#__PURE__*/ jsx(Button, {
|
|
78
|
+
color: "white",
|
|
79
|
+
size: "xs",
|
|
80
|
+
className: "!px-[5px] !border-0 !rounded-[3px]",
|
|
81
|
+
onClick: (event)=>{
|
|
82
|
+
event.stopPropagation();
|
|
83
|
+
onPreview(media?.url);
|
|
84
|
+
},
|
|
85
|
+
children: /*#__PURE__*/ jsx(SoppiyaIcon, {
|
|
86
|
+
icon: isPreview ? "eye-open.svg" : "eye-close.svg",
|
|
87
|
+
size: "sm"
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
}),
|
|
91
|
+
/*#__PURE__*/ jsx(InlineStack, {
|
|
92
|
+
justifyContent: "center",
|
|
93
|
+
className: "mt-[10px]",
|
|
94
|
+
children: /*#__PURE__*/ jsx(Text, {
|
|
95
|
+
truncate: "truncate-1",
|
|
96
|
+
size: "xs",
|
|
97
|
+
children: media?.file_name
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
]
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
const media_MediaItem = MediaItem;
|
|
104
|
+
export { media_MediaItem as default };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Maybe, Media } from "../../shared/graphql/graphql";
|
|
2
|
+
type MediaPreviewProps = {
|
|
3
|
+
media: Maybe<Media | undefined>;
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
};
|
|
6
|
+
declare const MediaPreview: ({ media, onClose }: MediaPreviewProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export default MediaPreview;
|