@rubixstudios/payload-images 1.0.0 → 1.0.1
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 +22 -22
- package/dist/components/ImageSearch/index.d.ts +4 -0
- package/dist/components/ImageSearch/index.d.ts.map +1 -0
- package/dist/components/ImageSearch/index.js +31 -0
- package/dist/components/SearchImages/heart.d.ts +4 -0
- package/dist/components/SearchImages/heart.d.ts.map +1 -0
- package/dist/components/SearchImages/heart.js +12 -0
- package/dist/components/SearchImages/index.d.ts +11 -0
- package/dist/components/SearchImages/index.d.ts.map +1 -0
- package/dist/components/SearchImages/index.js +378 -0
- package/dist/components/SearchImages/style.css +1 -0
- package/dist/defaults.d.ts +3 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/defaults.js +8 -0
- package/dist/endpoints/handler/Pexels.d.ts +12 -0
- package/dist/endpoints/handler/Pexels.d.ts.map +1 -0
- package/dist/endpoints/handler/Pexels.js +60 -0
- package/dist/endpoints/handler/Pixabay.d.ts +12 -0
- package/dist/endpoints/handler/Pixabay.d.ts.map +1 -0
- package/dist/endpoints/handler/Pixabay.js +63 -0
- package/dist/endpoints/handler/Provider.d.ts +20 -0
- package/dist/endpoints/handler/Provider.d.ts.map +1 -0
- package/dist/endpoints/handler/Provider.js +53 -0
- package/dist/endpoints/handler/Unsplash.d.ts +13 -0
- package/dist/endpoints/handler/Unsplash.d.ts.map +1 -0
- package/dist/endpoints/handler/Unsplash.js +82 -0
- package/dist/endpoints/providers.d.ts +3 -0
- package/dist/endpoints/providers.d.ts.map +1 -0
- package/dist/endpoints/providers.js +125 -0
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/lib/cache.d.ts +7 -0
- package/dist/lib/cache.d.ts.map +1 -0
- package/dist/lib/cache.js +34 -0
- package/dist/types.d.ts +167 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +316 -0
- package/dist/utils/fetchCache.d.ts +2 -0
- package/dist/utils/fetchCache.d.ts.map +1 -0
- package/dist/utils/fetchCache.js +15 -0
- package/dist/utils/getProvider.d.ts +6 -0
- package/dist/utils/getProvider.d.ts.map +1 -0
- package/dist/utils/getProvider.js +16 -0
- package/dist/utils/getProviders.d.ts +6 -0
- package/dist/utils/getProviders.d.ts.map +1 -0
- package/dist/utils/getProviders.js +10 -0
- package/dist/utils/requireAccess.d.ts +3 -0
- package/dist/utils/requireAccess.d.ts.map +1 -0
- package/dist/utils/requireAccess.js +13 -0
- package/dist/utils/resolveProvider.d.ts +6 -0
- package/dist/utils/resolveProvider.d.ts.map +1 -0
- package/dist/utils/resolveProvider.js +5 -0
- package/package.json +27 -12
package/LICENSE
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 rilrom / Riley Langbein
|
|
4
|
-
Copyright (c) 2025-2026 Rubix Studios Pty. Ltd. <https://rubixstudios.com.au>
|
|
5
|
-
|
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
in the Software without restriction, including without limitation the rights
|
|
9
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
furnished to do so, subject to the following conditions:
|
|
12
|
-
|
|
13
|
-
The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
copies or substantial portions of the Software.
|
|
15
|
-
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 rilrom / Riley Langbein
|
|
4
|
+
Copyright (c) 2025-2026 Rubix Studios Pty. Ltd. <https://rubixstudios.com.au>
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ImageSearch/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAsB,MAAM,OAAO,CAAA;AAI1C,eAAO,MAAM,UAAU,yBAAyB,CAAA;AAEhD,eAAO,MAAM,WAAW,yBA8BvB,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Button, Drawer, useConfig, useModal, useUploadControls } from '@payloadcms/ui';
|
|
3
|
+
import React, { useCallback } from 'react';
|
|
4
|
+
import { SearchImages } from '../SearchImages/index.js';
|
|
5
|
+
export const drawerSlug = 'payload-image-search';
|
|
6
|
+
export const ImageSearch = ()=>{
|
|
7
|
+
const { config } = useConfig();
|
|
8
|
+
const { setUploadControlFileUrl } = useUploadControls();
|
|
9
|
+
const { openModal, closeModal } = useModal();
|
|
10
|
+
const handleSearchSubmit = useCallback((url)=>{
|
|
11
|
+
if (!url) return;
|
|
12
|
+
setUploadControlFileUrl(url);
|
|
13
|
+
closeModal(drawerSlug);
|
|
14
|
+
}, [
|
|
15
|
+
setUploadControlFileUrl,
|
|
16
|
+
closeModal
|
|
17
|
+
]);
|
|
18
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement("span", {
|
|
19
|
+
className: "file-field__orText"
|
|
20
|
+
}, "Or"), /*#__PURE__*/ React.createElement(Button, {
|
|
21
|
+
buttonStyle: "pill",
|
|
22
|
+
size: "small",
|
|
23
|
+
onClick: ()=>openModal(drawerSlug)
|
|
24
|
+
}, "Search images"), /*#__PURE__*/ React.createElement(Drawer, {
|
|
25
|
+
slug: drawerSlug
|
|
26
|
+
}, /*#__PURE__*/ React.createElement(SearchImages, {
|
|
27
|
+
serverURL: config.serverURL,
|
|
28
|
+
api: config.routes.api,
|
|
29
|
+
onSelect: handleSearchSubmit
|
|
30
|
+
})));
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heart.d.ts","sourceRoot":"","sources":["../../../src/components/SearchImages/heart.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,wBAAgB,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,aAAa,CAAC,qBASvD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export function HeartIcon(props) {
|
|
3
|
+
return /*#__PURE__*/ React.createElement("svg", {
|
|
4
|
+
viewBox: "0 0 15 15",
|
|
5
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
6
|
+
"aria-hidden": "true",
|
|
7
|
+
...props
|
|
8
|
+
}, /*#__PURE__*/ React.createElement("path", {
|
|
9
|
+
d: "M13.91 6.75c-1.17 2.25-4.3 5.31-6.07 6.94a.52.52 0 0 1-.67 0C5.39 12.06 2.26 9 1.09 6.75-1.48 1.8 5-1.5 7.5 3.45 10-1.5 16.48 1.8 13.91 6.75z",
|
|
10
|
+
fill: "currentColor"
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './style.css';
|
|
3
|
+
export declare const previewImageDrawerSlug = "preview-image";
|
|
4
|
+
type SearchImagesProps = {
|
|
5
|
+
serverURL: string;
|
|
6
|
+
api: string;
|
|
7
|
+
onSelect: (value: string) => void;
|
|
8
|
+
};
|
|
9
|
+
export declare const SearchImages: (props: SearchImagesProps) => React.JSX.Element;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SearchImages/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAA2C,MAAM,OAAO,CAAA;AAmB/D,OAAO,aAAa,CAAA;AAIpB,eAAO,MAAM,sBAAsB,kBAAkB,CAAA;AAOrD,KAAK,iBAAiB,GAAG;IACvB,SAAS,EAAE,MAAM,CAAA;IACjB,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CAClC,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,OAAO,iBAAiB,sBAgcpD,CAAA"}
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { LinkIcon, Pagination, SearchFilter, Select, Tooltip, toast } from '@payloadcms/ui';
|
|
3
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
4
|
+
import { PexelsColours, PexelsOrientation, PexelsSize, PixabayCategories, PixabayColours, PixabayImageType, PixabayOrder, PixabayOrientation, UnsplashColours, UnsplashOrientation } from '../../types.js';
|
|
5
|
+
import { fetchCache } from '../../utils/fetchCache.js';
|
|
6
|
+
import { HeartIcon } from '../SearchImages/heart.js';
|
|
7
|
+
import './style.css';
|
|
8
|
+
const baseClass = 'search-images';
|
|
9
|
+
export const previewImageDrawerSlug = 'preview-image';
|
|
10
|
+
export const SearchImages = (props)=>{
|
|
11
|
+
const { serverURL, api, onSelect } = props;
|
|
12
|
+
const [providerOptions, setProviderOptions] = useState([]);
|
|
13
|
+
const [selectedProvider, setSelectedProvider] = useState(null);
|
|
14
|
+
const [unsplashFilters, setUnsplashFilters] = useState({});
|
|
15
|
+
const [pexelsFilters, setPexelsFilters] = useState({});
|
|
16
|
+
const [pixabayFilters, setPixabayFilters] = useState({});
|
|
17
|
+
const [images, setImages] = useState(null);
|
|
18
|
+
const [totalPages, setTotalPages] = useState(null);
|
|
19
|
+
const [currentPage, setCurrentPage] = useState(null);
|
|
20
|
+
const [loading, setLoading] = useState(true);
|
|
21
|
+
const [show, setShow] = useState(false);
|
|
22
|
+
const [value, setValue] = useState('');
|
|
23
|
+
const addDefaultError = useCallback(()=>{
|
|
24
|
+
toast.error('Something went wrong.');
|
|
25
|
+
}, []);
|
|
26
|
+
const resetImages = useCallback(()=>{
|
|
27
|
+
setImages(null);
|
|
28
|
+
setTotalPages(null);
|
|
29
|
+
setCurrentPage(1);
|
|
30
|
+
}, []);
|
|
31
|
+
const getProviderOptions = useCallback(async ()=>{
|
|
32
|
+
try {
|
|
33
|
+
const response = await fetch(`${serverURL}${api}/providers`);
|
|
34
|
+
const json = await response.json();
|
|
35
|
+
if (json.error) {
|
|
36
|
+
setLoading(false);
|
|
37
|
+
return toast.error(json.error);
|
|
38
|
+
}
|
|
39
|
+
const providers = json.data.map((provider)=>({
|
|
40
|
+
label: provider.name,
|
|
41
|
+
value: provider.key.toLowerCase()
|
|
42
|
+
}));
|
|
43
|
+
setProviderOptions(providers);
|
|
44
|
+
setSelectedProvider(providers[0]);
|
|
45
|
+
} catch {
|
|
46
|
+
setLoading(false);
|
|
47
|
+
addDefaultError();
|
|
48
|
+
}
|
|
49
|
+
}, [
|
|
50
|
+
serverURL,
|
|
51
|
+
api,
|
|
52
|
+
addDefaultError
|
|
53
|
+
]);
|
|
54
|
+
const buildFeaturedParams = useCallback(()=>{
|
|
55
|
+
const params = new URLSearchParams();
|
|
56
|
+
if (selectedProvider?.value === 'unsplash') {
|
|
57
|
+
if (unsplashFilters.color) params.set('color', unsplashFilters.color);
|
|
58
|
+
if (unsplashFilters.orientation) params.set('orientation', unsplashFilters.orientation);
|
|
59
|
+
}
|
|
60
|
+
if (selectedProvider?.value === 'pexels') {
|
|
61
|
+
if (pexelsFilters.color) params.set('color', pexelsFilters.color);
|
|
62
|
+
if (pexelsFilters.orientation) params.set('orientation', pexelsFilters.orientation);
|
|
63
|
+
if (pexelsFilters.size) params.set('size', pexelsFilters.size);
|
|
64
|
+
}
|
|
65
|
+
if (selectedProvider?.value === 'pixabay') {
|
|
66
|
+
if (pixabayFilters.category) params.set('category', pixabayFilters.category);
|
|
67
|
+
if (pixabayFilters.image_type) params.set('image_type', pixabayFilters.image_type);
|
|
68
|
+
if (pixabayFilters.order) params.set('order', pixabayFilters.order);
|
|
69
|
+
if (pixabayFilters.orientation) params.set('orientation', pixabayFilters.orientation);
|
|
70
|
+
if (pixabayFilters.colors) params.set('colors', pixabayFilters.colors);
|
|
71
|
+
}
|
|
72
|
+
const query = params.toString();
|
|
73
|
+
return query ? `?${query}` : '';
|
|
74
|
+
}, [
|
|
75
|
+
selectedProvider?.value,
|
|
76
|
+
unsplashFilters,
|
|
77
|
+
pexelsFilters,
|
|
78
|
+
pixabayFilters
|
|
79
|
+
]);
|
|
80
|
+
const getFeaturedPhotos = useCallback(async ()=>{
|
|
81
|
+
try {
|
|
82
|
+
setLoading(true);
|
|
83
|
+
resetImages();
|
|
84
|
+
const json = await fetchCache(`${serverURL}${api}/providers/${selectedProvider?.value}/featured${buildFeaturedParams()}`);
|
|
85
|
+
if (json.error) return toast.error(json.error);
|
|
86
|
+
setImages(json.data.images);
|
|
87
|
+
} catch {
|
|
88
|
+
addDefaultError();
|
|
89
|
+
resetImages();
|
|
90
|
+
} finally{
|
|
91
|
+
setLoading(false);
|
|
92
|
+
}
|
|
93
|
+
}, [
|
|
94
|
+
resetImages,
|
|
95
|
+
serverURL,
|
|
96
|
+
api,
|
|
97
|
+
selectedProvider?.value,
|
|
98
|
+
addDefaultError,
|
|
99
|
+
buildFeaturedParams
|
|
100
|
+
]);
|
|
101
|
+
const buildQueryParams = useCallback((page = 1)=>{
|
|
102
|
+
const params = new URLSearchParams();
|
|
103
|
+
params.set('query', value);
|
|
104
|
+
params.set('page', String(page));
|
|
105
|
+
if (selectedProvider?.value === 'unsplash') {
|
|
106
|
+
if (unsplashFilters.color) params.set('color', unsplashFilters.color);
|
|
107
|
+
if (unsplashFilters.orientation) params.set('orientation', unsplashFilters.orientation);
|
|
108
|
+
}
|
|
109
|
+
if (selectedProvider?.value === 'pexels') {
|
|
110
|
+
if (pexelsFilters.color) params.set('color', pexelsFilters.color);
|
|
111
|
+
if (pexelsFilters.orientation) params.set('orientation', pexelsFilters.orientation);
|
|
112
|
+
if (pexelsFilters.size) params.set('size', pexelsFilters.size);
|
|
113
|
+
}
|
|
114
|
+
if (selectedProvider?.value === 'pixabay') {
|
|
115
|
+
if (pixabayFilters.category) params.set('category', pixabayFilters.category);
|
|
116
|
+
if (pixabayFilters.image_type) params.set('image_type', pixabayFilters.image_type);
|
|
117
|
+
if (pixabayFilters.order) params.set('order', pixabayFilters.order);
|
|
118
|
+
if (pixabayFilters.orientation) params.set('orientation', pixabayFilters.orientation);
|
|
119
|
+
if (pixabayFilters.colors) params.set('colors', pixabayFilters.colors);
|
|
120
|
+
}
|
|
121
|
+
return params.toString();
|
|
122
|
+
}, [
|
|
123
|
+
value,
|
|
124
|
+
selectedProvider?.value,
|
|
125
|
+
unsplashFilters,
|
|
126
|
+
pexelsFilters,
|
|
127
|
+
pixabayFilters
|
|
128
|
+
]);
|
|
129
|
+
const getPhotos = useCallback(async (page = 1)=>{
|
|
130
|
+
try {
|
|
131
|
+
setLoading(true);
|
|
132
|
+
resetImages();
|
|
133
|
+
const json = await fetchCache(`${serverURL}${api}/providers/${selectedProvider?.value}/search?${buildQueryParams(page)}`);
|
|
134
|
+
if (json.error) return toast.error(json.error);
|
|
135
|
+
setImages(json.data.images);
|
|
136
|
+
setTotalPages(json.data.totalPages);
|
|
137
|
+
setCurrentPage(page);
|
|
138
|
+
} catch {
|
|
139
|
+
addDefaultError();
|
|
140
|
+
resetImages();
|
|
141
|
+
} finally{
|
|
142
|
+
setLoading(false);
|
|
143
|
+
}
|
|
144
|
+
}, [
|
|
145
|
+
resetImages,
|
|
146
|
+
serverURL,
|
|
147
|
+
api,
|
|
148
|
+
selectedProvider?.value,
|
|
149
|
+
addDefaultError,
|
|
150
|
+
buildQueryParams
|
|
151
|
+
]);
|
|
152
|
+
const handleSearchFilterChange = useCallback((search)=>{
|
|
153
|
+
setValue(search);
|
|
154
|
+
}, []);
|
|
155
|
+
const handleSelectChange = useCallback((select)=>{
|
|
156
|
+
setSelectedProvider(select);
|
|
157
|
+
}, []);
|
|
158
|
+
const handleSearch = useCallback(()=>{
|
|
159
|
+
if (value.length > 0) {
|
|
160
|
+
getPhotos(1);
|
|
161
|
+
} else {
|
|
162
|
+
getFeaturedPhotos();
|
|
163
|
+
}
|
|
164
|
+
}, [
|
|
165
|
+
getFeaturedPhotos,
|
|
166
|
+
getPhotos,
|
|
167
|
+
value
|
|
168
|
+
]);
|
|
169
|
+
const handleSelect = async (url, download)=>{
|
|
170
|
+
onSelect(url);
|
|
171
|
+
if (!download) return;
|
|
172
|
+
try {
|
|
173
|
+
await fetch(`${serverURL}${api}/providers/${selectedProvider?.value}/track-download?url=${download}`);
|
|
174
|
+
} catch {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
useEffect(()=>{
|
|
179
|
+
if (!selectedProvider) {
|
|
180
|
+
getProviderOptions();
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
handleSearch();
|
|
184
|
+
}, [
|
|
185
|
+
getProviderOptions,
|
|
186
|
+
handleSearch,
|
|
187
|
+
selectedProvider
|
|
188
|
+
]);
|
|
189
|
+
return /*#__PURE__*/ React.createElement("div", {
|
|
190
|
+
className: baseClass
|
|
191
|
+
}, /*#__PURE__*/ React.createElement("div", {
|
|
192
|
+
className: `${baseClass}__fields`
|
|
193
|
+
}, /*#__PURE__*/ React.createElement(SearchFilter, {
|
|
194
|
+
label: "",
|
|
195
|
+
handleChange: handleSearchFilterChange
|
|
196
|
+
}), /*#__PURE__*/ React.createElement(Select, {
|
|
197
|
+
options: providerOptions,
|
|
198
|
+
value: selectedProvider,
|
|
199
|
+
onChange: (value)=>handleSelectChange(value),
|
|
200
|
+
isClearable: false,
|
|
201
|
+
isSearchable: false,
|
|
202
|
+
isCreatable: false
|
|
203
|
+
})), selectedProvider?.value === 'pexels' && /*#__PURE__*/ React.createElement("div", {
|
|
204
|
+
className: `${baseClass}__filters`
|
|
205
|
+
}, /*#__PURE__*/ React.createElement(Select, {
|
|
206
|
+
options: PexelsColours,
|
|
207
|
+
value: PexelsColours.find((o)=>o.value === pexelsFilters.color),
|
|
208
|
+
onChange: (opt)=>setPexelsFilters((prev)=>({
|
|
209
|
+
...prev,
|
|
210
|
+
color: opt?.value
|
|
211
|
+
})),
|
|
212
|
+
isClearable: true,
|
|
213
|
+
isSearchable: false,
|
|
214
|
+
placeholder: "Select color..."
|
|
215
|
+
}), /*#__PURE__*/ React.createElement(Select, {
|
|
216
|
+
options: PexelsSize,
|
|
217
|
+
value: PexelsSize.find((o)=>o.value === pexelsFilters.size),
|
|
218
|
+
onChange: (opt)=>setPexelsFilters((prev)=>({
|
|
219
|
+
...prev,
|
|
220
|
+
size: opt?.value
|
|
221
|
+
})),
|
|
222
|
+
isClearable: true,
|
|
223
|
+
isSearchable: false,
|
|
224
|
+
placeholder: "Select size..."
|
|
225
|
+
}), /*#__PURE__*/ React.createElement(Select, {
|
|
226
|
+
options: PexelsOrientation,
|
|
227
|
+
value: PexelsOrientation.find((o)=>o.value === pexelsFilters.orientation),
|
|
228
|
+
onChange: (opt)=>setPexelsFilters((prev)=>({
|
|
229
|
+
...prev,
|
|
230
|
+
orientation: opt?.value
|
|
231
|
+
})),
|
|
232
|
+
isClearable: true,
|
|
233
|
+
isSearchable: false,
|
|
234
|
+
placeholder: "Select orientation..."
|
|
235
|
+
})), selectedProvider?.value === 'pixabay' && /*#__PURE__*/ React.createElement("div", {
|
|
236
|
+
className: `${baseClass}__filters`
|
|
237
|
+
}, /*#__PURE__*/ React.createElement(Select, {
|
|
238
|
+
options: PixabayCategories,
|
|
239
|
+
value: PixabayCategories.find((o)=>o.value === pixabayFilters.category),
|
|
240
|
+
onChange: (opt)=>setPixabayFilters((prev)=>({
|
|
241
|
+
...prev,
|
|
242
|
+
category: opt?.value
|
|
243
|
+
})),
|
|
244
|
+
isClearable: true,
|
|
245
|
+
isSearchable: false,
|
|
246
|
+
placeholder: "Select category..."
|
|
247
|
+
}), /*#__PURE__*/ React.createElement(Select, {
|
|
248
|
+
options: PixabayImageType,
|
|
249
|
+
value: PixabayImageType.find((o)=>o.value === pixabayFilters.image_type),
|
|
250
|
+
onChange: (opt)=>setPixabayFilters((prev)=>({
|
|
251
|
+
...prev,
|
|
252
|
+
image_type: opt?.value
|
|
253
|
+
})),
|
|
254
|
+
isClearable: true,
|
|
255
|
+
isSearchable: false,
|
|
256
|
+
placeholder: "Select type..."
|
|
257
|
+
}), /*#__PURE__*/ React.createElement(Select, {
|
|
258
|
+
options: PixabayColours,
|
|
259
|
+
value: PixabayColours.find((o)=>o.value === pixabayFilters.colors),
|
|
260
|
+
onChange: (opt)=>setPixabayFilters((prev)=>({
|
|
261
|
+
...prev,
|
|
262
|
+
colors: opt?.value
|
|
263
|
+
})),
|
|
264
|
+
isClearable: true,
|
|
265
|
+
isSearchable: false,
|
|
266
|
+
placeholder: "Select color..."
|
|
267
|
+
}), /*#__PURE__*/ React.createElement(Select, {
|
|
268
|
+
options: PixabayOrientation,
|
|
269
|
+
value: PixabayOrientation.find((o)=>o.value === pixabayFilters.orientation),
|
|
270
|
+
onChange: (opt)=>setPixabayFilters((prev)=>({
|
|
271
|
+
...prev,
|
|
272
|
+
orientation: opt?.value
|
|
273
|
+
})),
|
|
274
|
+
isClearable: true,
|
|
275
|
+
isSearchable: false,
|
|
276
|
+
placeholder: "Select orientation..."
|
|
277
|
+
}), /*#__PURE__*/ React.createElement(Select, {
|
|
278
|
+
options: PixabayOrder,
|
|
279
|
+
value: PixabayOrder.find((o)=>o.value === pixabayFilters.order),
|
|
280
|
+
onChange: (opt)=>setPixabayFilters((prev)=>({
|
|
281
|
+
...prev,
|
|
282
|
+
order: opt?.value
|
|
283
|
+
})),
|
|
284
|
+
isClearable: true,
|
|
285
|
+
isSearchable: false,
|
|
286
|
+
placeholder: "Select order..."
|
|
287
|
+
})), selectedProvider?.value === 'unsplash' && /*#__PURE__*/ React.createElement("div", {
|
|
288
|
+
className: `${baseClass}__filters`
|
|
289
|
+
}, /*#__PURE__*/ React.createElement(Select, {
|
|
290
|
+
options: UnsplashColours,
|
|
291
|
+
value: UnsplashColours.find((o)=>o.value === unsplashFilters.color),
|
|
292
|
+
onChange: (opt)=>setUnsplashFilters((prev)=>({
|
|
293
|
+
...prev,
|
|
294
|
+
color: opt?.value
|
|
295
|
+
})),
|
|
296
|
+
isClearable: true,
|
|
297
|
+
isSearchable: false,
|
|
298
|
+
placeholder: "Select color..."
|
|
299
|
+
}), /*#__PURE__*/ React.createElement(Select, {
|
|
300
|
+
options: UnsplashOrientation,
|
|
301
|
+
value: UnsplashOrientation.find((o)=>o.value === unsplashFilters.orientation),
|
|
302
|
+
onChange: (opt)=>setUnsplashFilters((prev)=>({
|
|
303
|
+
...prev,
|
|
304
|
+
orientation: opt?.value
|
|
305
|
+
})),
|
|
306
|
+
isClearable: true,
|
|
307
|
+
isSearchable: false,
|
|
308
|
+
placeholder: "Select orientation..."
|
|
309
|
+
})), loading && /*#__PURE__*/ React.createElement("div", {
|
|
310
|
+
className: `${baseClass}__loading`
|
|
311
|
+
}, "Loading images..."), !loading && images?.length === 0 && /*#__PURE__*/ React.createElement("div", {
|
|
312
|
+
className: `${baseClass}__noResults`
|
|
313
|
+
}, "No images found"), !loading && images && images?.length > 0 && /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement("div", {
|
|
314
|
+
className: `${baseClass}__results`
|
|
315
|
+
}, images.map((data)=>/*#__PURE__*/ React.createElement("div", {
|
|
316
|
+
key: data.id,
|
|
317
|
+
className: `${baseClass}__card`
|
|
318
|
+
}, /*#__PURE__*/ React.createElement("button", {
|
|
319
|
+
type: "button",
|
|
320
|
+
className: `${baseClass}__button`,
|
|
321
|
+
onClick: ()=>handleSelect(data.urls.original, data.urls?.downloadLocation),
|
|
322
|
+
style: {
|
|
323
|
+
backgroundColor: data.color
|
|
324
|
+
}
|
|
325
|
+
}, /*#__PURE__*/ React.createElement("img", {
|
|
326
|
+
src: data.urls.view,
|
|
327
|
+
alt: data.alt,
|
|
328
|
+
width: data.width,
|
|
329
|
+
height: data.height
|
|
330
|
+
})), /*#__PURE__*/ React.createElement("div", {
|
|
331
|
+
className: `${baseClass}__topOverlay`
|
|
332
|
+
}, data.likes !== undefined && /*#__PURE__*/ React.createElement("button", {
|
|
333
|
+
type: "button",
|
|
334
|
+
className: `${baseClass}__likes`,
|
|
335
|
+
onMouseEnter: ()=>setShow(true),
|
|
336
|
+
onMouseLeave: ()=>setShow(false),
|
|
337
|
+
onFocus: ()=>setShow(true),
|
|
338
|
+
onBlur: ()=>setShow(false)
|
|
339
|
+
}, /*#__PURE__*/ React.createElement(HeartIcon, null), /*#__PURE__*/ React.createElement(Tooltip, {
|
|
340
|
+
position: "bottom",
|
|
341
|
+
alignCaret: "center",
|
|
342
|
+
show: show
|
|
343
|
+
}, data.likes, " likes")), /*#__PURE__*/ React.createElement("a", {
|
|
344
|
+
className: `${baseClass}__download`,
|
|
345
|
+
href: data.urls.download,
|
|
346
|
+
target: "_blank",
|
|
347
|
+
rel: "noopener noreferrer"
|
|
348
|
+
}, /*#__PURE__*/ React.createElement(LinkIcon, null))), /*#__PURE__*/ React.createElement("div", {
|
|
349
|
+
className: `${baseClass}__bottomOverlay`
|
|
350
|
+
}, /*#__PURE__*/ React.createElement("a", {
|
|
351
|
+
className: `${baseClass}__attribution`,
|
|
352
|
+
href: data.attribution.link,
|
|
353
|
+
target: "_blank",
|
|
354
|
+
rel: "noopener noreferrer"
|
|
355
|
+
}, data.avatar ? /*#__PURE__*/ React.createElement("img", {
|
|
356
|
+
className: `${baseClass}__avatar`,
|
|
357
|
+
src: data.avatar,
|
|
358
|
+
alt: data.attribution.name,
|
|
359
|
+
width: 24,
|
|
360
|
+
height: 24,
|
|
361
|
+
loading: "lazy",
|
|
362
|
+
referrerPolicy: "no-referrer"
|
|
363
|
+
}) : /*#__PURE__*/ React.createElement("div", {
|
|
364
|
+
className: `${baseClass}__avatarFallback`,
|
|
365
|
+
"aria-hidden": true
|
|
366
|
+
}), data.attribution.name))))), currentPage && totalPages && totalPages > 1 && /*#__PURE__*/ React.createElement("div", {
|
|
367
|
+
className: `${baseClass}__pagination`
|
|
368
|
+
}, /*#__PURE__*/ React.createElement(Pagination, {
|
|
369
|
+
hasNextPage: currentPage < totalPages,
|
|
370
|
+
hasPrevPage: currentPage > 1,
|
|
371
|
+
nextPage: currentPage < totalPages ? currentPage + 1 : undefined,
|
|
372
|
+
numberOfNeighbors: 3,
|
|
373
|
+
page: currentPage,
|
|
374
|
+
prevPage: currentPage > 1 ? currentPage - 1 : undefined,
|
|
375
|
+
totalPages: totalPages,
|
|
376
|
+
onChange: (page)=>getPhotos(page)
|
|
377
|
+
}))));
|
|
378
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.drawer__content-children{display:flex;flex-flow:column nowrap}.search-images{width:100%;display:flex;flex-flow:column nowrap;flex:1;padding:2rem 0}.search-images__fields{display:flex;gap:1.5rem}.search-images__fields .search-filter{flex:1}.search-images__fields .search-filter__input{height:100%;padding:0 1rem}.search-images__fields .rs__indicators{margin-left:.5rem}.search-images__filters{display:flex;margin-top:15px;gap:16px}.search-images__filters .react-select{min-width:130px}.search-images__results{margin-top:3rem;column-gap:16px;column-count:5}.search-images__card{break-inside:avoid;margin-bottom:16px}.search-images__results>div{width:100%}.search-images__results img{max-width:100%;width:100%}.search-images__pagination{margin-top:auto;padding-top:2rem;display:flex;justify-content:center}.search-images__loading,.search-images__noResults{display:flex;justify-content:center;align-items:center;flex:1}.search-images__card{position:relative;display:block;overflow:hidden}.search-images__card::after{content:"";position:absolute;inset:0;background:rgba(0,0,0,.45);opacity:0;transition:opacity .2s ease;pointer-events:none}.search-images__card:hover::after{opacity:1}.search-images__button{appearance:none;border:none;background-color:transparent;display:block;margin:0;padding:0;cursor:pointer;width:100%}.search-images__button img{display:block;width:100%;height:auto}.search-images__button svg{color:#fff}.search-images__bottomOverlay,.search-images__topOverlay{position:absolute;z-index:1;display:flex;opacity:0;transition:opacity .4s ease;max-width:calc(100% - 20px - 1rem)}.search-images__topOverlay{right:1rem;top:.8rem}.search-images__bottomOverlay{left:1rem;bottom:.8rem}.search-images__card:hover .search-images__bottomOverlay,.search-images__card:hover .search-images__topOverlay{opacity:1;pointer-events:auto}.search-images__likes{cursor:pointer;background:#fff;border-radius:6px;border:0;margin-right:10px;padding:7px;font-size:1em;line-height:1}.search-images__likes svg{width:14px}.search-images__likes:hover{background:rgb(255 255 255 / 80%);transition:background-color .4s ease}.search-images__likes .tooltip{left:14px}.search-images__download{background:#fff;border-radius:6px;padding:4px;font-size:0;line-height:1;width:28px;text-align:center}.search-images__download svg{pointer-events:none}a.search-images__download:hover{background:rgb(255 255 255 / 80%);transition:background-color .4s ease}img.search-images__avatar{max-width:24px;max-height:24px;margin-right:10px;border-radius:100%}.search-images__avatarFallback{width:24px;height:24px;margin-right:10px;border-radius:100%;background:rgba(255 255 255 / 25%)}.search-images__attribution{display:flex;align-items:center;white-space:nowrap;text-overflow:ellipsis;color:#fff;font-size:1rem;font-weight:600;line-height:1;text-decoration:none;overflow:hidden}.search-images__attribution:hover{text-decoration:underline}.search-images__image{border-radius:4px;object-fit:cover;width:100%}.search-images__provider{display:flex;justify-content:center;padding-top:3rem;margin-top:auto;margin-bottom:30px}@media (max-width:1600px){.search-images__results{column-count:5}}@media (max-width:1400px){.search-images__results{column-count:4}}@media (max-width:1200px){.search-images__results{column-count:3}}@media (max-width:900px){.search-images__results{column-count:2}.search-images__filters{display:grid}}@media (max-width:600px){.search-images__results{column-count:1}.search-images__filters{display:grid}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,CAOtD,CAAA"}
|
package/dist/defaults.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PexelsFilters, PexelsResult, ProviderResult } from '../../types.js';
|
|
2
|
+
import type { Resolver } from './Provider.js';
|
|
3
|
+
import { Provider } from './Provider.js';
|
|
4
|
+
export declare class Pexels extends Provider {
|
|
5
|
+
constructor(apiKey: Resolver);
|
|
6
|
+
getFetchBaseUrl(): string;
|
|
7
|
+
getFetchHeaders(): Record<string, string>;
|
|
8
|
+
getFeatured(filters?: PexelsFilters): Promise<unknown>;
|
|
9
|
+
getSearch(query: string, page: number, filters?: PexelsFilters): Promise<unknown>;
|
|
10
|
+
formatResults(data: PexelsResult[]): ProviderResult[];
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=Pexels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Pexels.d.ts","sourceRoot":"","sources":["../../../src/endpoints/handler/Pexels.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACjF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,qBAAa,MAAO,SAAQ,QAAQ;gBACtB,MAAM,EAAE,QAAQ;IAInB,eAAe,IAAI,MAAM;IAIzB,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAInC,WAAW,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC;IActD,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC;IAsBvF,aAAa,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,cAAc,EAAE;CAkB/D"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Provider } from './Provider.js';
|
|
2
|
+
export class Pexels extends Provider {
|
|
3
|
+
constructor(apiKey){
|
|
4
|
+
super('pexels', 'Pexels', 'https://www.pexels.com/', apiKey);
|
|
5
|
+
}
|
|
6
|
+
getFetchBaseUrl() {
|
|
7
|
+
return 'https://api.pexels.com';
|
|
8
|
+
}
|
|
9
|
+
getFetchHeaders() {
|
|
10
|
+
return {
|
|
11
|
+
Authorization: `${this.getApiKey()}`
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
async getFeatured(filters) {
|
|
15
|
+
if (filters?.color || filters?.orientation || filters?.size) {
|
|
16
|
+
return this.getSearch('featured', 1, filters);
|
|
17
|
+
}
|
|
18
|
+
const data = await this.fetch('GET', `/v1/curated?per_page=${this.getFetchLimit()}`);
|
|
19
|
+
return {
|
|
20
|
+
images: this.formatResults(data.photos),
|
|
21
|
+
totalImages: null,
|
|
22
|
+
totalPages: null
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
async getSearch(query, page, filters) {
|
|
26
|
+
const params = new URLSearchParams({
|
|
27
|
+
query: query || 'featured',
|
|
28
|
+
page: String(page),
|
|
29
|
+
per_page: String(this.getFetchLimit())
|
|
30
|
+
});
|
|
31
|
+
if (filters?.color) params.set('color', filters.color);
|
|
32
|
+
if (filters?.size) params.set('size', filters.size);
|
|
33
|
+
if (filters?.orientation) params.set('orientation', filters.orientation);
|
|
34
|
+
const data = await this.fetch('GET', `/v1/search?${params.toString()}`);
|
|
35
|
+
const totalResults = data.total_results;
|
|
36
|
+
return {
|
|
37
|
+
images: this.formatResults(data.photos),
|
|
38
|
+
totalImages: totalResults,
|
|
39
|
+
totalPages: Math.min(Math.ceil(totalResults / this.getFetchLimit()), 100)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
formatResults(data) {
|
|
43
|
+
return data.map((image)=>({
|
|
44
|
+
id: image.id,
|
|
45
|
+
alt: image.alt || '',
|
|
46
|
+
width: image.width,
|
|
47
|
+
height: image.height,
|
|
48
|
+
color: image.avg_color,
|
|
49
|
+
urls: {
|
|
50
|
+
view: image.src.medium,
|
|
51
|
+
original: image.src.original,
|
|
52
|
+
download: image.url
|
|
53
|
+
},
|
|
54
|
+
attribution: {
|
|
55
|
+
name: image.photographer,
|
|
56
|
+
link: image.photographer_url
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PixabayFilters, PixabayResult, ProviderResult } from '../../types.js';
|
|
2
|
+
import type { Resolver } from './Provider.js';
|
|
3
|
+
import { Provider } from './Provider.js';
|
|
4
|
+
export declare class Pixabay extends Provider {
|
|
5
|
+
constructor(apiKey: Resolver);
|
|
6
|
+
getFetchBaseUrl(): string;
|
|
7
|
+
getFetchHeaders(): Record<string, string>;
|
|
8
|
+
getFeatured(filters?: PixabayFilters): Promise<unknown>;
|
|
9
|
+
getSearch(query: string, page: number, filters?: PixabayFilters): Promise<unknown>;
|
|
10
|
+
formatResults(data: PixabayResult[]): ProviderResult[];
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=Pixabay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Pixabay.d.ts","sourceRoot":"","sources":["../../../src/endpoints/handler/Pixabay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACnF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,qBAAa,OAAQ,SAAQ,QAAQ;gBACvB,MAAM,EAAE,QAAQ;IAInB,eAAe,IAAI,MAAM;IAIzB,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAInC,WAAW,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC;IAuBvD,SAAS,CACtB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,OAAO,CAAC;IAyBV,aAAa,CAAC,IAAI,EAAE,aAAa,EAAE,GAAG,cAAc,EAAE;CAoBhE"}
|