sanity-plugin-asset-source-unsplash
7.0.157.0.16
dist/UnsplashPhotoGallery.js−
dist/UnsplashPhotoGallery.jsDeleted−171
Index: package/dist/UnsplashPhotoGallery.js
===================================================================
--- package/dist/UnsplashPhotoGallery.js
+++ package/dist/UnsplashPhotoGallery.js
@@ -1,171 +0,0 @@
-import { t as Loader } from "./Loader.js";
-import "sanity";
-import { c } from "react/compiler-runtime";
-import { Fragment, jsx, jsxs } from "react/jsx-runtime";
-import { Box, Card, Text } from "@sanity/ui";
-import { Activity, use } from "react";
-import { styled } from "styled-components";
-import "react-photo-album/rows.css";
-import { RowsPhotoAlbum } from "react-photo-album";
-import InfiniteScroll from "react-photo-album/scroll";
-import { getTheme_v2 } from "@sanity/ui/theme";
-async function fetchDownloadUrl(client, photo) {
- let downloadUrl = photo.links.download_location.replace("https://api.unsplash.com", "/addons/unsplash"), { url } = await client.request({
- url: downloadUrl,
- withCredentials: !0,
- method: "GET"
- });
- return url;
-}
-const CreditLineLink = styled.a.withConfig({
- displayName: "CreditLineLink",
- componentId: "sc-7wgffj-0"
-})`text-decoration:none;cursor:pointer;&:hover,&:focus{[data-ui='Text']{text-decoration:underline;}}`, CreditLine = styled(Card).withConfig({
- displayName: "CreditLine",
- componentId: "sc-7wgffj-1"
-})`${({ theme }) => {
- let v2 = getTheme_v2({ sanity: theme.sanity });
- return `
- --creditline-fg: ${v2.color.fg};
- --creditline-bg: ${v2.color.bg};
- `;
-}};-webkit-user-drag:none;position:absolute;background-color:var(--creditline-bg);bottom:0;[data-ui='Text']{color:var(--creditline-fg);}`;
-function UnsplashCreditLine(t0) {
- let $ = c(11), { link, id, userName } = t0, T0, t1;
- if ($[0] !== link) {
- let url = new URL(link);
- url.searchParams.set("utm_source", "sanity-plugin-asset-source-unsplash"), url.searchParams.set("utm_medium", "referral"), T0 = CreditLineLink, t1 = url.toString(), $[0] = link, $[1] = T0, $[2] = t1;
- } else T0 = $[1], t1 = $[2];
- let t2 = `Open image by ${userName} on Unsplash in new window`, t3;
- $[3] !== t2 || $[4] !== userName ? (t3 = /* @__PURE__ */ jsx(CreditLine, {
- padding: 1,
- radius: 1,
- margin: 1,
- children: /* @__PURE__ */ jsxs(Text, {
- size: 0,
- title: t2,
- children: ["By @", userName]
- })
- }), $[3] = t2, $[4] = userName, $[5] = t3) : t3 = $[5];
- let t4;
- return $[6] !== T0 || $[7] !== id || $[8] !== t1 || $[9] !== t3 ? (t4 = /* @__PURE__ */ jsx(T0, {
- href: t1,
- target: id,
- rel: "noreferrer noopener",
- onClick: _temp$1,
- children: t3
- }), $[6] = T0, $[7] = id, $[8] = t1, $[9] = t3, $[10] = t4) : t4 = $[10], t4;
-}
-function _temp$1(event) {
- return event.stopPropagation();
-}
-function mapUnsplashToPhotoAlbumPhoto(photo) {
- return {
- src: photo.urls.small,
- width: photo.width,
- height: photo.height,
- key: photo.id,
- data: photo
- };
-}
-function UnsplashAssetSourceGallery(t0) {
- let $ = c(33), { client, query, fetcher, scrollContainerRef, onSelect, initialDataPromise } = t0, data = use(initialDataPromise), t1 = data.total === 0 ? "visible" : "hidden", t2;
- $[0] === query ? t2 = $[1] : (t2 = /* @__PURE__ */ jsx(Box, {
- paddingX: 2,
- paddingY: 3,
- children: /* @__PURE__ */ jsxs(Text, {
- size: 1,
- muted: !0,
- children: [
- "No results found for \"",
- query,
- "\""
- ]
- })
- }), $[0] = query, $[1] = t2);
- let t3;
- $[2] !== t1 || $[3] !== t2 ? (t3 = /* @__PURE__ */ jsx(Activity, {
- mode: t1,
- children: t2
- }), $[2] = t1, $[3] = t2, $[4] = t3) : t3 = $[4];
- let t4 = data.total === 0 ? "hidden" : "visible", t5;
- $[5] === scrollContainerRef ? t5 = $[6] : (t5 = () => scrollContainerRef.current, $[5] = scrollContainerRef, $[6] = t5);
- let t6;
- $[7] === data.results ? t6 = $[8] : (t6 = data.results.map(mapUnsplashToPhotoAlbumPhoto), $[7] = data.results, $[8] = t6);
- let t7;
- $[9] !== fetcher || $[10] !== query ? (t7 = async (index) => {
- let { results, total_pages } = await fetcher(query, index + 1);
- return index < total_pages ? results.map(mapUnsplashToPhotoAlbumPhoto) : null;
- }, $[9] = fetcher, $[10] = query, $[11] = t7) : t7 = $[11];
- let t8;
- $[12] === Symbol.for("react.memo_cache_sentinel") ? (t8 = /* @__PURE__ */ jsx(Loader, {}), $[12] = t8) : t8 = $[12];
- let t9;
- $[13] === query ? t9 = $[14] : (t9 = query && /* @__PURE__ */ jsx(Box, {
- paddingX: 2,
- paddingY: 3,
- children: /* @__PURE__ */ jsx(Text, {
- size: 1,
- muted: !0,
- children: "No more results"
- })
- }), $[13] = query, $[14] = t9);
- let t10;
- $[15] !== client || $[16] !== onSelect ? (t10 = async (t11) => {
- let { photo: t12 } = t11, { data: photo } = t12, downloadUrl = await fetchDownloadUrl(client, photo), description = photo.description || void 0;
- return onSelect([{
- kind: "url",
- value: downloadUrl,
- assetDocumentProps: {
- _type: "sanity.imageAsset",
- source: {
- name: "unsplash",
- id: photo.id,
- url: photo.links.html
- },
- description,
- creditLine: `${photo.user.name} by Unsplash`
- }
- }]);
- }, $[15] = client, $[16] = onSelect, $[17] = t10) : t10 = $[17];
- let t11;
- $[18] === Symbol.for("react.memo_cache_sentinel") ? (t11 = [], $[18] = t11) : t11 = $[18];
- let t12;
- $[19] === Symbol.for("react.memo_cache_sentinel") ? (t12 = /* @__PURE__ */ jsx(RowsPhotoAlbum, {
- photos: t11,
- spacing: 2,
- padding: 1,
- targetRowHeight: _temp,
- render: { extras: _temp2 },
- componentsProps: { container: { style: { marginBottom: 2 } } }
- }), $[19] = t12) : t12 = $[19];
- let t13;
- $[20] !== query || $[21] !== t10 || $[22] !== t5 || $[23] !== t6 || $[24] !== t7 || $[25] !== t9 ? (t13 = /* @__PURE__ */ jsx(InfiniteScroll, {
- scrollContainer: t5,
- photos: t6,
- fetch: t7,
- loading: t8,
- finished: t9,
- onClick: t10,
- children: t12
- }, query), $[20] = query, $[21] = t10, $[22] = t5, $[23] = t6, $[24] = t7, $[25] = t9, $[26] = t13) : t13 = $[26];
- let t14;
- $[27] !== t13 || $[28] !== t4 ? (t14 = /* @__PURE__ */ jsx(Activity, {
- mode: t4,
- children: t13
- }), $[27] = t13, $[28] = t4, $[29] = t14) : t14 = $[29];
- let t15;
- return $[30] !== t14 || $[31] !== t3 ? (t15 = /* @__PURE__ */ jsxs(Fragment, { children: [t3, t14] }), $[30] = t14, $[31] = t3, $[32] = t15) : t15 = $[32], t15;
-}
-function _temp2(_, context) {
- return /* @__PURE__ */ jsx(UnsplashCreditLine, {
- id: context.photo.data.id,
- link: context.photo.data.links.html,
- userName: context.photo.data.user.username
- });
-}
-function _temp(width) {
- return width < 300 ? 150 : width < 600 ? 200 : 300;
-}
-export { UnsplashAssetSourceGallery as default };
-
-//# sourceMappingURL=UnsplashPhotoGallery.js.map
\ No newline at end of file