sanity-plugin-asset-source-unsplash 3.0.0-v3-studio.13 → 3.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 +1 -1
- package/README.md +16 -23
- package/lib/index.cjs +313 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.ts +79 -0
- package/lib/index.js +317 -1
- package/lib/index.js.map +1 -1
- package/package.json +55 -76
- package/src/components/Icon.tsx +3 -10
- package/src/components/Photo.styled.tsx +3 -9
- package/src/components/Photo.tsx +12 -17
- package/src/components/UnsplashAssetSource.styled.tsx +3 -3
- package/src/components/UnsplashAssetSource.tsx +37 -26
- package/src/datastores/unsplash.ts +20 -14
- package/src/index.ts +4 -3
- package/v2-incompatible.js +2 -2
- package/lib/index.esm.js +0 -2
- package/lib/index.esm.js.map +0 -1
- /package/lib/{src/index.d.ts → index.d.cts} +0 -0
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,36 +1,32 @@
|
|
|
1
1
|
# Sanity Asset Source Plugin: Unsplash
|
|
2
2
|
|
|
3
|
-
> **
|
|
4
|
-
>
|
|
5
|
-
> This is the **Sanity Studio v3 version** of sanity-plugin-asset-source-unsplash.
|
|
6
|
-
>
|
|
7
|
-
> For the v2 version, please refer to the [v2-branch](https://github.com/sanity-io/sanity-plugin-asset-source-unsplash).
|
|
3
|
+
> This is a **Sanity Studio v3** plugin.
|
|
4
|
+
> For the v2 version, please refer to the [v2-branch](https://github.com/sanity-io/sanity-plugin-asset-source-unsplash/tree/studio-v2).
|
|
8
5
|
|
|
9
6
|
## What is it?
|
|
7
|
+
|
|
10
8
|
Search for photos on Unsplash and add them to your project right inside Sanity Studio.
|
|
11
9
|
|
|
12
|
-

|
|
13
11
|
|
|
14
12
|
## Installation
|
|
15
13
|
|
|
16
|
-
`npm install --save sanity-plugin-asset-source-unsplash
|
|
14
|
+
`npm install --save sanity-plugin-asset-source-unsplash`
|
|
17
15
|
|
|
18
16
|
or
|
|
19
17
|
|
|
20
|
-
`yarn add sanity-plugin-asset-source-unsplash
|
|
18
|
+
`yarn add sanity-plugin-asset-source-unsplash`
|
|
21
19
|
|
|
22
20
|
## Usage
|
|
23
21
|
|
|
24
22
|
Add it as a plugin in sanity.config.ts (or .js):
|
|
25
23
|
|
|
26
24
|
```js
|
|
27
|
-
import { unsplashImageAsset } from
|
|
25
|
+
import { unsplashImageAsset } from 'sanity-plugin-asset-source-unsplash'
|
|
28
26
|
|
|
29
27
|
export default defineConfig({
|
|
30
28
|
// ...
|
|
31
|
-
plugins: [
|
|
32
|
-
unsplashImageAsset(),
|
|
33
|
-
]
|
|
29
|
+
plugins: [unsplashImageAsset()],
|
|
34
30
|
})
|
|
35
31
|
```
|
|
36
32
|
|
|
@@ -39,22 +35,20 @@ This will add [unsplashAssetSource](src/index.ts) to all image-fields in Sanity
|
|
|
39
35
|
### Manually configure asset sources
|
|
40
36
|
|
|
41
37
|
If you need to configure when Unsplash should be available as an asset source, filter it out as needed in
|
|
42
|
-
`
|
|
38
|
+
`form.image.assetSources`:
|
|
43
39
|
|
|
44
40
|
```js
|
|
45
|
-
import { unsplashImageAsset, unsplashAssetSource } from
|
|
41
|
+
import { unsplashImageAsset, unsplashAssetSource } from 'sanity-plugin-asset-source-unsplash'
|
|
46
42
|
|
|
47
43
|
export default defineConfig({
|
|
48
44
|
// ...
|
|
49
|
-
plugins: [
|
|
50
|
-
|
|
51
|
-
],
|
|
52
|
-
formBuilder: {
|
|
45
|
+
plugins: [unsplashImageAsset()],
|
|
46
|
+
form: {
|
|
53
47
|
image: {
|
|
54
|
-
assetSources: (previousAssetSources, {schema}) => {
|
|
48
|
+
assetSources: (previousAssetSources, { schema }) => {
|
|
55
49
|
if (schema.name === 'movie-image') {
|
|
56
50
|
// remove unsplash from movie-image types
|
|
57
|
-
return previousAssetSources.filter(assetSource => assetSource !== unsplashAssetSource)
|
|
51
|
+
return previousAssetSources.filter((assetSource) => assetSource !== unsplashAssetSource)
|
|
58
52
|
}
|
|
59
53
|
return previousAssetSources
|
|
60
54
|
},
|
|
@@ -125,7 +119,6 @@ export default defineConfig({
|
|
|
125
119
|
"accepted_tos": true
|
|
126
120
|
}
|
|
127
121
|
}
|
|
128
|
-
|
|
129
122
|
```
|
|
130
123
|
|
|
131
124
|
## Example resulting asset document
|
|
@@ -226,8 +219,8 @@ export default defineConfig({
|
|
|
226
219
|
|
|
227
220
|
## Futher reading
|
|
228
221
|
|
|
229
|
-
|
|
230
|
-
|
|
222
|
+
- https://unsplash.com/documentation
|
|
223
|
+
- https://www.sanity.io/docs/custom-asset-sources
|
|
231
224
|
|
|
232
225
|
## License
|
|
233
226
|
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
+
var sanity = require("sanity"), jsxRuntime = require("react/jsx-runtime"), icons = require("@sanity/icons"), ui = require("@sanity/ui"), React = require("react"), InfiniteScroll = require("react-infinite-scroll-component"), PhotoAlbum = require("react-photo-album"), rxjs = require("rxjs"), operators = require("rxjs/operators"), styledComponents = require("styled-components");
|
|
4
|
+
function _interopDefaultCompat(e) {
|
|
5
|
+
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
|
+
}
|
|
7
|
+
var React__default = /* @__PURE__ */ _interopDefaultCompat(React), InfiniteScroll__default = /* @__PURE__ */ _interopDefaultCompat(InfiniteScroll), PhotoAlbum__default = /* @__PURE__ */ _interopDefaultCompat(PhotoAlbum);
|
|
8
|
+
function UnsplashIcon() {
|
|
9
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("svg", { role: "img", viewBox: "0 0 25 25", width: "1em", height: "1em", fill: "currentColor", children: [
|
|
10
|
+
/* @__PURE__ */ jsxRuntime.jsx("title", {}),
|
|
11
|
+
/* @__PURE__ */ jsxRuntime.jsx("path", { d: "M9 9V4h7v5H9Zm7 3h5v9H4v-9h5v5h7v-5Z" })
|
|
12
|
+
] });
|
|
13
|
+
}
|
|
14
|
+
const fetchSearch = (client, query, page, perPage) => rxjs.defer(
|
|
15
|
+
() => client.observable.request({
|
|
16
|
+
url: `/addons/unsplash/search/photos?query=${encodeURIComponent(
|
|
17
|
+
query
|
|
18
|
+
)}&page=${page}&per_page=${perPage}`,
|
|
19
|
+
withCredentials: !0,
|
|
20
|
+
method: "GET"
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
})
|
|
23
|
+
), fetchList = (client, type, page, perPage) => rxjs.defer(
|
|
24
|
+
() => client.observable.request({
|
|
25
|
+
url: `/addons/unsplash/photos?order_by=${type}&page=${page}&per_page=${perPage}`,
|
|
26
|
+
withCredentials: !0,
|
|
27
|
+
method: "GET"
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
+
})
|
|
30
|
+
);
|
|
31
|
+
function fetchDownloadUrl(client, photo) {
|
|
32
|
+
const downloadUrl = photo.links.download_location.replace(
|
|
33
|
+
"https://api.unsplash.com",
|
|
34
|
+
"/addons/unsplash"
|
|
35
|
+
);
|
|
36
|
+
return client.request({
|
|
37
|
+
url: downloadUrl,
|
|
38
|
+
withCredentials: !0,
|
|
39
|
+
method: "GET"
|
|
40
|
+
}).then((result) => result.url);
|
|
41
|
+
}
|
|
42
|
+
const search = (client, query, page, resultsPerPage) => rxjs.concat(
|
|
43
|
+
query.pipe(
|
|
44
|
+
operators.withLatestFrom(page),
|
|
45
|
+
operators.debounceTime(500),
|
|
46
|
+
operators.distinctUntilChanged(),
|
|
47
|
+
operators.switchMap(([q, p]) => q ? fetchSearch(client, q, p, resultsPerPage).pipe(
|
|
48
|
+
operators.distinctUntilChanged(),
|
|
49
|
+
operators.map((result) => result.results)
|
|
50
|
+
) : fetchList(client, "popular", p, resultsPerPage))
|
|
51
|
+
)
|
|
52
|
+
), Root = styledComponents.styled.div`
|
|
53
|
+
overflow: hidden;
|
|
54
|
+
background-origin: content-box;
|
|
55
|
+
background-repeat: no-repeat;
|
|
56
|
+
background-clip: border-box;
|
|
57
|
+
background-size: cover;
|
|
58
|
+
position: relative;
|
|
59
|
+
outline: none !important;
|
|
60
|
+
border: ${({ theme }) => `1px solid ${theme.sanity.color.card.enabled.border}`};
|
|
61
|
+
box-sizing: content-box;
|
|
62
|
+
user-drag: none;
|
|
63
|
+
|
|
64
|
+
&:hover {
|
|
65
|
+
opacity: 0.85;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
&:focus,
|
|
69
|
+
&:active {
|
|
70
|
+
border: 1px solid var(--input-border-color-focus);
|
|
71
|
+
box-shadow: inset 0 0 0 3px var(--input-border-color-focus);
|
|
72
|
+
}
|
|
73
|
+
`, CreditLineLink = styledComponents.styled.a`
|
|
74
|
+
text-decoration: none;
|
|
75
|
+
cursor: pointer;
|
|
76
|
+
`, CreditLine = styledComponents.styled(ui.Card)`
|
|
77
|
+
${({ theme }) => `
|
|
78
|
+
--creditline-fg: ${theme.sanity.color.card.enabled.fg};
|
|
79
|
+
--creditline-bg: ${theme.sanity.color.card.enabled.bg};
|
|
80
|
+
`};
|
|
81
|
+
user-drag: none;
|
|
82
|
+
position: absolute;
|
|
83
|
+
background-color: var(--creditline-bg);
|
|
84
|
+
bottom: 0;
|
|
85
|
+
|
|
86
|
+
[data-ui='Text'] {
|
|
87
|
+
color: var(--creditline-fg);
|
|
88
|
+
}
|
|
89
|
+
`, UTM_SOURCE = "sanity-plugin-asset-source-unsplash";
|
|
90
|
+
function Photo(props) {
|
|
91
|
+
const { onClick, data, onKeyDown, onFocus, active, width, height } = props, handleClick = React.useCallback(() => {
|
|
92
|
+
onClick(data);
|
|
93
|
+
}, [onClick, data]), handleCreditLineClicked = React.useCallback(
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
95
|
+
(event) => {
|
|
96
|
+
event.stopPropagation();
|
|
97
|
+
const url = `${data.links.html}?utm_source=${encodeURIComponent(
|
|
98
|
+
UTM_SOURCE
|
|
99
|
+
)}&utm_medium=referral`;
|
|
100
|
+
window.open(url, data.id, "noreferrer,noopener");
|
|
101
|
+
},
|
|
102
|
+
[data]
|
|
103
|
+
), handleKeyDown = React.useCallback(
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
105
|
+
(event) => {
|
|
106
|
+
onKeyDown(event), event.keyCode === 13 && onClick(data);
|
|
107
|
+
},
|
|
108
|
+
[onKeyDown, data, onClick]
|
|
109
|
+
), handleMouseDown = React.useCallback(() => {
|
|
110
|
+
onFocus(data);
|
|
111
|
+
}, [onFocus, data]);
|
|
112
|
+
React.useEffect(() => {
|
|
113
|
+
active && onFocus(data);
|
|
114
|
+
}, [active, data, onFocus]);
|
|
115
|
+
const src = data.urls.small, userName = data.user.name;
|
|
116
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
117
|
+
Root,
|
|
118
|
+
{
|
|
119
|
+
title: `Select image by ${userName} from Unsplash`,
|
|
120
|
+
tabIndex: 0,
|
|
121
|
+
onKeyDown: handleKeyDown,
|
|
122
|
+
onMouseDown: handleMouseDown,
|
|
123
|
+
style: {
|
|
124
|
+
width: `${width}px`,
|
|
125
|
+
height: `${height}px`,
|
|
126
|
+
backgroundImage: `url("${src}")`
|
|
127
|
+
},
|
|
128
|
+
onClick: handleClick,
|
|
129
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(CreditLineLink, { onClick: handleCreditLineClicked, children: /* @__PURE__ */ jsxRuntime.jsx(CreditLine, { padding: 2, radius: 2, margin: 2, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, title: `Open image by ${userName} on Unsplash in new window`, children: [
|
|
130
|
+
"By @",
|
|
131
|
+
data.user.username
|
|
132
|
+
] }) }) })
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
const SearchInput = styledComponents.styled(ui.TextInput)`
|
|
137
|
+
position: sticky;
|
|
138
|
+
top: 0;
|
|
139
|
+
z-index: 1;
|
|
140
|
+
`;
|
|
141
|
+
styledComponents.styled.div`
|
|
142
|
+
overflow-y: auto;
|
|
143
|
+
max-height: 80vh;
|
|
144
|
+
`;
|
|
145
|
+
var __defProp = Object.defineProperty, __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField = (obj, key, value) => (__defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value), value);
|
|
146
|
+
const RESULTS_PER_PAGE = 42, PHOTO_SPACING = 2, PHOTO_PADDING = 1;
|
|
147
|
+
function UnsplashAssetSource(props) {
|
|
148
|
+
const client = sanity.useClient({ apiVersion: "2022-09-01" });
|
|
149
|
+
return /* @__PURE__ */ jsxRuntime.jsx(UnsplashAssetSourceInternal, { ...props, client });
|
|
150
|
+
}
|
|
151
|
+
class UnsplashAssetSourceInternal extends React__default.default.Component {
|
|
152
|
+
constructor() {
|
|
153
|
+
super(...arguments), __publicField(this, "state", {
|
|
154
|
+
cursor: 0,
|
|
155
|
+
query: "",
|
|
156
|
+
page: 1,
|
|
157
|
+
searchResults: [[]],
|
|
158
|
+
isLoading: !0
|
|
159
|
+
}), __publicField(this, "searchSubscription", null), __publicField(this, "searchSubject$", new rxjs.BehaviorSubject("")), __publicField(this, "pageSubject$", new rxjs.BehaviorSubject(1)), __publicField(this, "handleSelect", (photo) => (this.setState({ isLoading: !0 }), fetchDownloadUrl(this.props.client, photo).then((downloadUrl) => {
|
|
160
|
+
const description = photo.description || void 0, asset = {
|
|
161
|
+
kind: "url",
|
|
162
|
+
value: downloadUrl,
|
|
163
|
+
assetDocumentProps: {
|
|
164
|
+
_type: "sanity.imageAsset",
|
|
165
|
+
source: {
|
|
166
|
+
name: "unsplash",
|
|
167
|
+
id: photo.id,
|
|
168
|
+
url: photo.links.html
|
|
169
|
+
},
|
|
170
|
+
description,
|
|
171
|
+
creditLine: `${photo.user.name} by Unsplash`
|
|
172
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
this.props.onSelect([asset]);
|
|
176
|
+
}))), __publicField(this, "handleClose", () => {
|
|
177
|
+
this.props.onClose();
|
|
178
|
+
}), __publicField(this, "handleSearchTermChanged", (event) => {
|
|
179
|
+
const query = event.currentTarget.value;
|
|
180
|
+
this.setState({ query, page: 1, searchResults: [[]], isLoading: !0, cursor: 0 }), this.pageSubject$.next(1), this.searchSubject$.next(query);
|
|
181
|
+
}), __publicField(this, "handleSearchTermCleared", () => {
|
|
182
|
+
this.setState({ query: "", page: 1, searchResults: [[]], isLoading: !0, cursor: 0 }), this.pageSubject$.next(1), this.searchSubject$.next("");
|
|
183
|
+
}), __publicField(this, "handleScollerLoadMore", () => {
|
|
184
|
+
const nextPage = this.state.page + 1;
|
|
185
|
+
this.setState({ page: nextPage, isLoading: !0 }), this.pageSubject$.next(nextPage), this.searchSubject$.next(this.state.query);
|
|
186
|
+
}), __publicField(this, "handleKeyDown", (event) => {
|
|
187
|
+
const { cursor } = this.state;
|
|
188
|
+
(event.keyCode === 38 || event.keyCode === 37) && cursor > 0 ? this.setState((prevState) => ({
|
|
189
|
+
cursor: prevState.cursor - 1
|
|
190
|
+
})) : (event.keyCode === 40 || event.keyCode === 39) && cursor < this.getPhotos().length - 1 && this.setState((prevState) => ({
|
|
191
|
+
cursor: prevState.cursor + 1
|
|
192
|
+
}));
|
|
193
|
+
}), __publicField(this, "updateCursor", (photo) => {
|
|
194
|
+
const index = this.getPhotos().findIndex((result) => result.id === photo.id);
|
|
195
|
+
this.setState({ cursor: index });
|
|
196
|
+
}), __publicField(this, "renderImage", (props) => {
|
|
197
|
+
const { photo, layout } = props, active = this.getPhotos().findIndex((result) => result.id === photo.data.id) === this.state.cursor || !1;
|
|
198
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
199
|
+
Photo,
|
|
200
|
+
{
|
|
201
|
+
onClick: this.handleSelect.bind(photo.data),
|
|
202
|
+
onKeyDown: this.handleKeyDown,
|
|
203
|
+
data: photo.data,
|
|
204
|
+
width: layout.width,
|
|
205
|
+
height: layout.height,
|
|
206
|
+
active,
|
|
207
|
+
onFocus: this.updateCursor
|
|
208
|
+
}
|
|
209
|
+
);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
componentDidMount() {
|
|
213
|
+
this.searchSubscription = search(
|
|
214
|
+
this.props.client,
|
|
215
|
+
this.searchSubject$,
|
|
216
|
+
this.pageSubject$,
|
|
217
|
+
RESULTS_PER_PAGE
|
|
218
|
+
).subscribe({
|
|
219
|
+
next: (results) => {
|
|
220
|
+
this.setState((prev) => ({
|
|
221
|
+
searchResults: [...prev.searchResults, results],
|
|
222
|
+
isLoading: !1
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
componentWillUnmount() {
|
|
228
|
+
this.searchSubscription && this.searchSubscription.unsubscribe();
|
|
229
|
+
}
|
|
230
|
+
getPhotos() {
|
|
231
|
+
return this.state.searchResults.flat();
|
|
232
|
+
}
|
|
233
|
+
render() {
|
|
234
|
+
const { query, searchResults, isLoading } = this.state;
|
|
235
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
236
|
+
ui.Dialog,
|
|
237
|
+
{
|
|
238
|
+
animate: !0,
|
|
239
|
+
id: "unsplash-asset-source",
|
|
240
|
+
header: "Select image from Unsplash",
|
|
241
|
+
onClose: this.handleClose,
|
|
242
|
+
open: !0,
|
|
243
|
+
width: 4,
|
|
244
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 3, paddingX: 4, paddingBottom: 4, children: [
|
|
245
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
246
|
+
SearchInput,
|
|
247
|
+
{
|
|
248
|
+
clearButton: query.length > 0,
|
|
249
|
+
icon: icons.SearchIcon,
|
|
250
|
+
onChange: this.handleSearchTermChanged,
|
|
251
|
+
onClear: this.handleSearchTermCleared,
|
|
252
|
+
placeholder: "Search by topics or colors",
|
|
253
|
+
value: query
|
|
254
|
+
}
|
|
255
|
+
),
|
|
256
|
+
!isLoading && this.getPhotos().length === 0 && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, muted: !0, children: "No results found" }),
|
|
257
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
258
|
+
InfiniteScroll__default.default,
|
|
259
|
+
{
|
|
260
|
+
dataLength: this.getPhotos().length,
|
|
261
|
+
next: this.handleScollerLoadMore,
|
|
262
|
+
hasMore: !0,
|
|
263
|
+
scrollThreshold: 0.99,
|
|
264
|
+
height: "60vh",
|
|
265
|
+
loader: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { align: "center", justify: "center", padding: 3, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, { muted: !0 }) }),
|
|
266
|
+
endMessage: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, muted: !0, children: "No more results" }),
|
|
267
|
+
children: searchResults.filter((photos) => photos.length > 0).map((photos, index) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
268
|
+
PhotoAlbum__default.default,
|
|
269
|
+
{
|
|
270
|
+
layout: "rows",
|
|
271
|
+
spacing: PHOTO_SPACING,
|
|
272
|
+
padding: PHOTO_PADDING,
|
|
273
|
+
targetRowHeight: (width) => width < 300 ? 150 : width < 600 ? 200 : 300,
|
|
274
|
+
photos: photos.map((photo) => ({
|
|
275
|
+
src: photo.urls.small,
|
|
276
|
+
width: photo.width,
|
|
277
|
+
height: photo.height,
|
|
278
|
+
key: photo.id,
|
|
279
|
+
data: photo
|
|
280
|
+
})),
|
|
281
|
+
renderPhoto: this.renderImage,
|
|
282
|
+
componentsProps: {
|
|
283
|
+
containerProps: { style: { marginBottom: `${PHOTO_SPACING}px` } }
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
`gallery-${query || "popular"}-${index}`
|
|
287
|
+
))
|
|
288
|
+
}
|
|
289
|
+
)
|
|
290
|
+
] })
|
|
291
|
+
}
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
__publicField(UnsplashAssetSourceInternal, "defaultProps", {
|
|
296
|
+
selectedAssets: void 0
|
|
297
|
+
});
|
|
298
|
+
const unsplashAssetSource = {
|
|
299
|
+
name: "unsplash",
|
|
300
|
+
title: "Unsplash",
|
|
301
|
+
component: UnsplashAssetSource,
|
|
302
|
+
icon: UnsplashIcon
|
|
303
|
+
}, unsplashImageAsset = sanity.definePlugin({
|
|
304
|
+
name: "asset-source-unsplash-plugin",
|
|
305
|
+
form: {
|
|
306
|
+
image: {
|
|
307
|
+
assetSources: (prev) => [...prev, unsplashAssetSource]
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
exports.unsplashAssetSource = unsplashAssetSource;
|
|
312
|
+
exports.unsplashImageAsset = unsplashImageAsset;
|
|
313
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/components/Icon.tsx","../src/datastores/unsplash.ts","../src/components/Photo.styled.tsx","../src/components/Photo.tsx","../src/components/UnsplashAssetSource.styled.tsx","../src/components/UnsplashAssetSource.tsx","../src/index.ts"],"sourcesContent":["export default function UnsplashIcon() {\n return (\n <svg role=\"img\" viewBox=\"0 0 25 25\" width=\"1em\" height=\"1em\" fill=\"currentColor\">\n <title />\n <path d=\"M9 9V4h7v5H9Zm7 3h5v9H4v-9h5v5h7v-5Z\" />\n </svg>\n )\n}\n","import { type BehaviorSubject, concat, defer, type Observable } from 'rxjs'\nimport { debounceTime, distinctUntilChanged, map, switchMap, withLatestFrom } from 'rxjs/operators'\nimport type { SanityClient } from 'sanity'\n\nimport type { UnsplashPhoto } from '../types'\n\ntype SearchSubject = BehaviorSubject<string>\ntype PageSubject = BehaviorSubject<number>\n\nconst fetchSearch = (\n client: SanityClient,\n query: string,\n page: number,\n perPage: number,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): Observable<any> =>\n defer(\n () =>\n client.observable.request({\n url: `/addons/unsplash/search/photos?query=${encodeURIComponent(\n query,\n )}&page=${page}&per_page=${perPage}`,\n withCredentials: true,\n method: 'GET',\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n }) as any,\n )\n\nconst fetchList = (\n client: SanityClient,\n type: string,\n page: number,\n perPage: number,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): Observable<any> =>\n defer(\n () =>\n client.observable.request({\n url: `/addons/unsplash/photos?order_by=${type}&page=${page}&per_page=${perPage}`,\n withCredentials: true,\n method: 'GET',\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n }) as any,\n )\n\nexport function fetchDownloadUrl(client: SanityClient, photo: UnsplashPhoto): Promise<string> {\n const downloadUrl = photo.links.download_location.replace(\n 'https://api.unsplash.com',\n '/addons/unsplash',\n )\n return client\n .request({\n url: downloadUrl,\n withCredentials: true,\n method: 'GET',\n })\n .then((result: { url: string }) => {\n return result.url\n })\n}\n\nexport const search = (\n client: SanityClient,\n query: SearchSubject,\n page: PageSubject,\n resultsPerPage: number,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): Observable<any> => {\n return concat(\n query.pipe(\n withLatestFrom(page),\n debounceTime(500),\n distinctUntilChanged(),\n switchMap(([q, p]) => {\n if (q) {\n return fetchSearch(client, q, p, resultsPerPage).pipe(\n distinctUntilChanged(),\n map((result) => result.results),\n )\n }\n return fetchList(client, 'popular', p, resultsPerPage)\n }),\n ),\n )\n}\n","import { Card } from '@sanity/ui'\nimport { styled } from 'styled-components'\n\nexport const Root = styled.div`\n overflow: hidden;\n background-origin: content-box;\n background-repeat: no-repeat;\n background-clip: border-box;\n background-size: cover;\n position: relative;\n outline: none !important;\n border: ${({ theme }) => `1px solid ${theme.sanity.color.card.enabled.border}`};\n box-sizing: content-box;\n user-drag: none;\n\n &:hover {\n opacity: 0.85;\n }\n\n &:focus,\n &:active {\n border: 1px solid var(--input-border-color-focus);\n box-shadow: inset 0 0 0 3px var(--input-border-color-focus);\n }\n`\n\nexport const CreditLineLink = styled.a`\n text-decoration: none;\n cursor: pointer;\n`\n\nexport const CreditLine = styled(Card)`\n ${({ theme }) => `\n --creditline-fg: ${theme.sanity.color.card.enabled.fg};\n --creditline-bg: ${theme.sanity.color.card.enabled.bg};\n `};\n user-drag: none;\n position: absolute;\n background-color: var(--creditline-bg);\n bottom: 0;\n\n [data-ui='Text'] {\n color: var(--creditline-fg);\n }\n`\n","import { Text } from '@sanity/ui'\nimport { useCallback, useEffect } from 'react'\n\nimport type { UnsplashPhoto } from '../types'\nimport { CreditLine, CreditLineLink, Root } from './Photo.styled'\n\ntype Props = {\n data: UnsplashPhoto\n width: number\n height: number\n onClick: (photo: UnsplashPhoto) => void\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onKeyDown: (event: any) => void\n active: boolean\n onFocus: (photo: UnsplashPhoto) => void\n}\n\nconst UTM_SOURCE = 'sanity-plugin-asset-source-unsplash'\n\nexport default function Photo(props: Props) {\n const { onClick, data, onKeyDown, onFocus, active, width, height } = props\n\n const handleClick = useCallback(() => {\n onClick(data)\n }, [onClick, data])\n\n const handleCreditLineClicked = useCallback(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (event: any) => {\n event.stopPropagation()\n const url = `${data.links.html}?utm_source=${encodeURIComponent(\n UTM_SOURCE,\n )}&utm_medium=referral`\n window.open(url, data.id, 'noreferrer,noopener')\n },\n [data],\n )\n\n const handleKeyDown = useCallback(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (event: any) => {\n onKeyDown(event)\n if (event.keyCode === 13) {\n onClick(data)\n }\n },\n [onKeyDown, data, onClick],\n )\n\n const handleMouseDown = useCallback(() => {\n onFocus(data)\n }, [onFocus, data])\n\n useEffect(() => {\n if (active) {\n onFocus(data)\n }\n }, [active, data, onFocus])\n\n const src = data.urls.small\n const userName = data.user.name\n\n return (\n <Root\n title={`Select image by ${userName} from Unsplash`}\n tabIndex={0}\n onKeyDown={handleKeyDown}\n onMouseDown={handleMouseDown}\n style={{\n width: `${width}px`,\n height: `${height}px`,\n backgroundImage: `url(\"${src}\")`,\n }}\n onClick={handleClick}\n >\n <CreditLineLink onClick={handleCreditLineClicked}>\n <CreditLine padding={2} radius={2} margin={2}>\n <Text size={1} title={`Open image by ${userName} on Unsplash in new window`}>\n By @{data.user.username}\n </Text>\n </CreditLine>\n </CreditLineLink>\n </Root>\n )\n}\n","import { TextInput } from '@sanity/ui'\nimport { styled } from 'styled-components'\n\nexport const SearchInput = styled(TextInput)`\n position: sticky;\n top: 0;\n z-index: 1;\n`\n\nexport const Scroller = styled.div`\n overflow-y: auto;\n max-height: 80vh;\n`\n","import { SearchIcon } from '@sanity/icons'\nimport { Dialog, Flex, Spinner, Stack, Text } from '@sanity/ui'\nimport React from 'react'\nimport InfiniteScroll from 'react-infinite-scroll-component'\nimport PhotoAlbum from 'react-photo-album'\nimport { BehaviorSubject, type Subscription } from 'rxjs'\nimport {\n type AssetFromSource,\n type AssetSourceComponentProps,\n type SanityClient,\n useClient,\n} from 'sanity'\n\nimport { fetchDownloadUrl, search } from '../datastores/unsplash'\nimport type { UnsplashPhoto } from '../types'\nimport Photo from './Photo'\nimport { SearchInput } from './UnsplashAssetSource.styled'\n\ntype State = {\n query: string\n searchResults: UnsplashPhoto[][]\n page: number\n isLoading: boolean\n cursor: number\n}\n\nconst RESULTS_PER_PAGE = 42\nconst PHOTO_SPACING = 2\nconst PHOTO_PADDING = 1 // offset the 1px border width\n\nexport default function UnsplashAssetSource(props: AssetSourceComponentProps) {\n const client = useClient({ apiVersion: '2022-09-01' })\n return <UnsplashAssetSourceInternal {...props} client={client} />\n}\n\nclass UnsplashAssetSourceInternal extends React.Component<\n AssetSourceComponentProps & { client: SanityClient },\n State\n> {\n static defaultProps = {\n selectedAssets: undefined,\n }\n\n state = {\n cursor: 0,\n query: '',\n page: 1,\n searchResults: [[]],\n isLoading: true,\n }\n\n searchSubscription: Subscription | null = null\n\n searchSubject$ = new BehaviorSubject('')\n pageSubject$ = new BehaviorSubject(1)\n\n componentDidMount() {\n this.searchSubscription = search(\n this.props.client,\n this.searchSubject$,\n this.pageSubject$,\n RESULTS_PER_PAGE,\n ).subscribe({\n next: (results: UnsplashPhoto[]) => {\n this.setState((prev) => ({\n searchResults: [...prev.searchResults, results],\n isLoading: false,\n }))\n },\n })\n }\n\n componentWillUnmount() {\n if (this.searchSubscription) {\n this.searchSubscription.unsubscribe()\n }\n }\n\n handleSelect = (photo: UnsplashPhoto) => {\n this.setState({ isLoading: true })\n return fetchDownloadUrl(this.props.client, photo).then((downloadUrl) => {\n const description = photo.description || undefined\n const asset: AssetFromSource = {\n kind: 'url',\n value: downloadUrl,\n assetDocumentProps: {\n _type: 'sanity.imageAsset',\n source: {\n name: 'unsplash',\n id: photo.id,\n url: photo.links.html,\n },\n description,\n creditLine: `${photo.user.name} by Unsplash`,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } as any,\n }\n this.props.onSelect([asset])\n })\n }\n\n handleClose = () => {\n this.props.onClose()\n }\n\n handleSearchTermChanged = (event: React.ChangeEvent<HTMLInputElement>) => {\n const query = event.currentTarget.value\n this.setState({ query, page: 1, searchResults: [[]], isLoading: true, cursor: 0 })\n this.pageSubject$.next(1)\n this.searchSubject$.next(query)\n }\n\n handleSearchTermCleared = () => {\n this.setState({ query: '', page: 1, searchResults: [[]], isLoading: true, cursor: 0 })\n this.pageSubject$.next(1)\n this.searchSubject$.next('')\n }\n\n handleScollerLoadMore = () => {\n // eslint-disable-next-line react/no-access-state-in-setstate\n const nextPage = this.state.page + 1\n this.setState({ page: nextPage, isLoading: true })\n this.pageSubject$.next(nextPage)\n this.searchSubject$.next(this.state.query)\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n handleKeyDown = (event: any) => {\n const { cursor } = this.state\n if ((event.keyCode === 38 || event.keyCode === 37) && cursor > 0) {\n this.setState((prevState) => ({\n cursor: prevState.cursor - 1,\n }))\n } else if (\n (event.keyCode === 40 || event.keyCode === 39) &&\n cursor < this.getPhotos().length - 1\n ) {\n this.setState((prevState) => ({\n cursor: prevState.cursor + 1,\n }))\n }\n }\n\n getPhotos() {\n return this.state.searchResults.flat()\n }\n\n updateCursor = (photo: UnsplashPhoto) => {\n const index = this.getPhotos().findIndex((result: UnsplashPhoto) => result.id === photo.id)\n this.setState({ cursor: index })\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n renderImage = (props: any) => {\n const { photo, layout } = props\n const active =\n this.getPhotos().findIndex((result: UnsplashPhoto) => result.id === photo.data.id) ===\n this.state.cursor || false\n return (\n <Photo\n onClick={this.handleSelect.bind(photo.data)}\n onKeyDown={this.handleKeyDown}\n data={photo.data}\n width={layout.width}\n height={layout.height}\n active={active}\n onFocus={this.updateCursor}\n />\n )\n }\n\n render() {\n const { query, searchResults, isLoading } = this.state\n\n return (\n <Dialog\n animate\n id=\"unsplash-asset-source\"\n header=\"Select image from Unsplash\"\n onClose={this.handleClose}\n open\n width={4}\n >\n <Stack space={3} paddingX={4} paddingBottom={4}>\n <SearchInput\n clearButton={query.length > 0}\n icon={SearchIcon}\n onChange={this.handleSearchTermChanged}\n onClear={this.handleSearchTermCleared}\n placeholder=\"Search by topics or colors\"\n value={query}\n />\n {!isLoading && this.getPhotos().length === 0 && (\n <Text size={1} muted>\n No results found\n </Text>\n )}\n <InfiniteScroll\n dataLength={this.getPhotos().length} // This is important field to render the next data\n next={this.handleScollerLoadMore}\n // scrollableTarget=\"unsplash-scroller\"\n hasMore\n scrollThreshold={0.99}\n height=\"60vh\"\n loader={\n <Flex align=\"center\" justify=\"center\" padding={3}>\n <Spinner muted />\n </Flex>\n }\n endMessage={\n <Text size={1} muted>\n No more results\n </Text>\n }\n >\n {searchResults\n .filter((photos) => photos.length > 0)\n .map((photos: UnsplashPhoto[], index) => (\n <PhotoAlbum\n // eslint-disable-next-line react/no-array-index-key\n key={`gallery-${query || 'popular'}-${index}`}\n layout=\"rows\"\n spacing={PHOTO_SPACING}\n padding={PHOTO_PADDING}\n targetRowHeight={(width) => {\n if (width < 300) return 150\n if (width < 600) return 200\n return 300\n }}\n photos={photos.map((photo: UnsplashPhoto) => ({\n src: photo.urls.small,\n width: photo.width,\n height: photo.height,\n key: photo.id,\n data: photo,\n }))}\n renderPhoto={this.renderImage}\n componentsProps={{\n containerProps: { style: { marginBottom: `${PHOTO_SPACING}px` } },\n }}\n />\n ))}\n </InfiniteScroll>\n </Stack>\n </Dialog>\n )\n }\n}\n","import { AssetSource, definePlugin } from 'sanity'\n\nimport Icon from './components/Icon'\nimport Unsplash from './components/UnsplashAssetSource'\n\nexport type { Asset, AssetDocument, UnsplashPhoto } from './types'\n\n/**\n * @public\n */\nexport const unsplashAssetSource: AssetSource = {\n name: 'unsplash',\n title: 'Unsplash',\n component: Unsplash,\n icon: Icon,\n}\n\n/**\n * @public\n */\nexport const unsplashImageAsset = definePlugin({\n name: 'asset-source-unsplash-plugin',\n\n form: {\n image: {\n assetSources: (prev) => {\n return [...prev, unsplashAssetSource]\n },\n },\n },\n})\n"],"names":["jsxs","jsx","defer","concat","withLatestFrom","debounceTime","distinctUntilChanged","switchMap","map","styled","Card","useCallback","useEffect","Text","TextInput","useClient","React","BehaviorSubject","Dialog","Stack","SearchIcon","InfiniteScroll","Flex","Spinner","PhotoAlbum","Unsplash","Icon","definePlugin"],"mappings":";;;;;;;AAAA,SAAwB,eAAe;AAEnC,SAAAA,2BAAA,KAAC,OAAI,EAAA,MAAK,OAAM,SAAQ,aAAY,OAAM,OAAM,QAAO,OAAM,MAAK,gBAChE,UAAA;AAAA,IAAAC,2BAAA,IAAC,SAAM,EAAA;AAAA,IACPA,2BAAAA,IAAC,QAAK,EAAA,GAAE,uCAAuC,CAAA;AAAA,EACjD,EAAA,CAAA;AAEJ;ACEA,MAAM,cAAc,CAClB,QACA,OACA,MACA,YAGAC,KAAA;AAAA,EACE,MACE,OAAO,WAAW,QAAQ;AAAA,IACxB,KAAK,wCAAwC;AAAA,MAC3C;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QAAyB,UAC7BZ,2BAAA;AAAA,gBAACuB,oBAAA;AAAA,gBAAA;AAAA,kBAGC,QAAO;AAAA,kBACP,SAAS;AAAA,kBACT,SAAS;AAAA,kBACT,iBAAiB,CAAC,UACZ,QAAQ,MAAY,MACpB,QAAQ,MAAY,MACjB;AAAA,kBAET,QAAQ,OAAO,IAAI,CAAC,WAA0B;AAAA,oBAC5C,KAAK,MAAM,KAAK;AAAA,oBAChB,OAAO,MAAM;AAAA,oBACb,QAAQ,MAAM;AAAA,oBACd,KAAK,MAAM;AAAA,oBACX,MAAM;AAAA,kBAAA,EACN;AAAA,kBACF,aAAa,KAAK;AAAA,kBAClB,iBAAiB;AAAA,oBACf,gBAAgB,EAAE,OAAO,EAAE,cAAc,GAAG,aAAa,OAAO;AAAA,kBAClE;AAAA,gBAAA;AAAA,gBAnBK,WAAW,SAAS,SAAS,IAAI,KAAK;AAAA,cAAA,CAqB9C;AAAA,YAAA;AAAA,UACL;AAAA,QAAA,GACF;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AAhNE,cAJI,6BAIG,gBAAe;AAAA,EACpB,gBAAgB;AAClB,CAAA;AC/BK,MAAM,sBAAmC;AAAA,EAC9C,MAAM;AAAA,EACN,OAAO;AAAA,EACP,WAAWC;AAAAA,EACX,MAAMC;AACR,GAKa,qBAAqBC,oBAAa;AAAA,EAC7C,MAAM;AAAA,EAEN,MAAM;AAAA,IACJ,OAAO;AAAA,MACL,cAAc,CAAC,SACN,CAAC,GAAG,MAAM,mBAAmB;AAAA,IAExC;AAAA,EACF;AACF,CAAC;;;"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { AssetSource } from 'sanity'
|
|
2
|
+
import { Plugin as Plugin_2 } from 'sanity'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export declare interface Asset {
|
|
8
|
+
kind: 'url' | 'base64' | 'file' | 'assetDocumentId'
|
|
9
|
+
value: string | File
|
|
10
|
+
assetDocumentProps?: {
|
|
11
|
+
originalFileName?: string
|
|
12
|
+
label?: string
|
|
13
|
+
title?: string
|
|
14
|
+
description?: string
|
|
15
|
+
source?: {
|
|
16
|
+
id: string
|
|
17
|
+
name: string
|
|
18
|
+
url?: string
|
|
19
|
+
}
|
|
20
|
+
creditLine?: string
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
export declare interface AssetDocument {
|
|
28
|
+
_id: string
|
|
29
|
+
label?: string
|
|
30
|
+
title?: string
|
|
31
|
+
description?: string
|
|
32
|
+
source?: {
|
|
33
|
+
id: string
|
|
34
|
+
name: string
|
|
35
|
+
url?: string
|
|
36
|
+
}
|
|
37
|
+
creditLine?: string
|
|
38
|
+
originalFilename?: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export declare const unsplashAssetSource: AssetSource
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
export declare const unsplashImageAsset: Plugin_2<void>
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export declare interface UnsplashPhoto {
|
|
55
|
+
id: string
|
|
56
|
+
width: number
|
|
57
|
+
height: number
|
|
58
|
+
description?: string
|
|
59
|
+
alt_description?: string
|
|
60
|
+
urls: {
|
|
61
|
+
full: string
|
|
62
|
+
small: string
|
|
63
|
+
}
|
|
64
|
+
user: {
|
|
65
|
+
name: string
|
|
66
|
+
username: string
|
|
67
|
+
links: {
|
|
68
|
+
html: string
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
links: {
|
|
72
|
+
html: string
|
|
73
|
+
self: string
|
|
74
|
+
download: string
|
|
75
|
+
download_location: string
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export {}
|