sanity-plugin-shopify-assets 1.0.1 → 1.1.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 +21 -21
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +120 -96
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +122 -98
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/AssetDiff.tsx +2 -1
- package/src/components/AssetPreview.tsx +5 -5
- package/src/components/DialogHeader.tsx +1 -2
- package/src/components/File.tsx +4 -4
- package/src/components/ShopifyAssetInput.tsx +2 -2
- package/src/components/ShopifyAssetPicker.tsx +5 -5
- package/src/components/VideoPlayer.tsx +2 -2
- package/src/datastores/shopify.ts +2 -2
- package/src/index.ts +5 -3
- package/src/schema/shopifyAssetMetadataSchema.ts +34 -0
- package/src/schema/shopifyAssetPreviewSchema.ts +24 -0
- package/src/schema/shopifyAssetSchema.ts +8 -38
- package/src/types.ts +1 -1
package/README.md
CHANGED
|
@@ -14,45 +14,45 @@ npm install sanity-plugin-shopify-assets
|
|
|
14
14
|
|
|
15
15
|
Add it as a plugin in sanity.config.ts (or .js):
|
|
16
16
|
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
```ts
|
|
18
|
+
import {defineConfig} from 'sanity'
|
|
19
|
+
import {shopifyAssets} from 'sanity-plugin-shopify-assets'
|
|
20
|
+
|
|
21
|
+
export const defineConfig({
|
|
22
|
+
//...
|
|
23
|
+
plugins: [
|
|
24
|
+
shopifyAssets({
|
|
25
|
+
shopifyDomain: '*.myshopify.com'
|
|
26
|
+
})
|
|
27
|
+
]
|
|
28
|
+
})
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
Simply update the `shopifyDomain` to your store URL. You'll need to install the [Sanity Connect](https://www.sanity.io/docs/sanity-connect-for-shopify) app on your store to handle authorisation. You'll need to ensure the Liquid sync option is enabled within the Sanity Connect app.
|
|
32
32
|
|
|
33
33
|
Then you can enable the asset selector on a field:
|
|
34
34
|
|
|
35
|
-
```
|
|
35
|
+
```ts
|
|
36
36
|
import {defineType, defineField} from 'sanity'
|
|
37
37
|
|
|
38
38
|
export const myDocumentSchema = defineType({
|
|
39
|
-
type:
|
|
40
|
-
name:
|
|
39
|
+
type: 'document',
|
|
40
|
+
name: 'article',
|
|
41
41
|
fields: [
|
|
42
42
|
defineField({
|
|
43
|
-
type:
|
|
44
|
-
name:
|
|
43
|
+
type: 'shopify.asset',
|
|
44
|
+
name: 'shopifyAsset',
|
|
45
45
|
}),
|
|
46
|
-
]
|
|
46
|
+
],
|
|
47
47
|
})
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
It's also possible to define the Shopify domain on the field level, which allows you to retrieve assets from different stores. Each store must be connected to your Sanity project via the Sanity Connect app. In order to do this, simply declare the `shopifyDomain` on the field:
|
|
51
51
|
|
|
52
|
-
```
|
|
52
|
+
```ts
|
|
53
53
|
defineField({
|
|
54
|
-
type:
|
|
55
|
-
name:
|
|
54
|
+
type: 'shopify.asset',
|
|
55
|
+
name: 'shopifyAsset',
|
|
56
56
|
options: {
|
|
57
57
|
shopifyDomain: '*.myshopify.com'
|
|
58
58
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.esm.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
|
|
2
2
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
3
|
+
import { useProjectId, useDataset, PatchEvent, set, unset, DiffFromTo, defineType, defineField, definePlugin } from 'sanity';
|
|
3
4
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
5
|
+
import { LaunchIcon, ErrorOutlineIcon } from '@sanity/icons';
|
|
4
6
|
import { Card, Box, useTheme, Text, Flex, Button, Stack, Dialog, Inline, TextInput, Spinner, Grid } from '@sanity/ui';
|
|
5
|
-
import { useProjectId, useDataset, PatchEvent, set, unset, DiffFromTo, defineType, defineField, definePlugin } from 'sanity';
|
|
6
7
|
import r, { useRef, useDebugValue, useContext, createElement, useEffect, useCallback, useState, useMemo } from 'react';
|
|
7
|
-
import videojs from 'video.js';
|
|
8
8
|
import prettyBytes from 'pretty-bytes';
|
|
9
9
|
import prettyMilliseconds from 'pretty-ms';
|
|
10
|
-
import
|
|
10
|
+
import videojs from 'video.js';
|
|
11
11
|
import { concat, defer, BehaviorSubject } from 'rxjs';
|
|
12
|
-
import InfiniteScroll from 'react-infinite-scroll-component';
|
|
13
12
|
import PhotoAlbum from 'react-photo-album';
|
|
13
|
+
import InfiniteScroll from 'react-infinite-scroll-component';
|
|
14
14
|
import { withLatestFrom, debounceTime, distinctUntilChanged, switchMap, map } from 'rxjs/operators';
|
|
15
15
|
import axios from 'axios';
|
|
16
16
|
var reactIsExports$1 = {};
|
|
@@ -2106,6 +2106,65 @@ const AssetPreview = _ref10 => {
|
|
|
2106
2106
|
})]
|
|
2107
2107
|
});
|
|
2108
2108
|
};
|
|
2109
|
+
const fetchSearch = props => {
|
|
2110
|
+
const {
|
|
2111
|
+
projectId,
|
|
2112
|
+
dataset,
|
|
2113
|
+
shop,
|
|
2114
|
+
query,
|
|
2115
|
+
cursor,
|
|
2116
|
+
resultsPerPage
|
|
2117
|
+
} = props;
|
|
2118
|
+
return defer(() => {
|
|
2119
|
+
return axios.get("https://".concat(projectId, ".api.sanity.io/v1/shopify/assets/").concat(dataset, "?shop=").concat(shop, "&query=").concat(encodeURIComponent(query)).concat(cursor && "&cursor=".concat(cursor), "&limit=").concat(resultsPerPage), {
|
|
2120
|
+
withCredentials: true,
|
|
2121
|
+
method: "GET"
|
|
2122
|
+
});
|
|
2123
|
+
}).pipe(map(result => result.data));
|
|
2124
|
+
};
|
|
2125
|
+
const fetchList = props => {
|
|
2126
|
+
const {
|
|
2127
|
+
projectId,
|
|
2128
|
+
dataset,
|
|
2129
|
+
shop,
|
|
2130
|
+
cursor,
|
|
2131
|
+
resultsPerPage
|
|
2132
|
+
} = props;
|
|
2133
|
+
return defer(() => axios.get("https://".concat(projectId, ".api.sanity.io/v1/shopify/assets/").concat(dataset, "?shop=").concat(shop).concat(cursor && "&cursor=".concat(cursor), "&limit=").concat(resultsPerPage), {
|
|
2134
|
+
withCredentials: true,
|
|
2135
|
+
method: "GET"
|
|
2136
|
+
})).pipe(map(result => result.data));
|
|
2137
|
+
};
|
|
2138
|
+
const search = props => {
|
|
2139
|
+
const {
|
|
2140
|
+
projectId,
|
|
2141
|
+
dataset,
|
|
2142
|
+
shop,
|
|
2143
|
+
query,
|
|
2144
|
+
cursor,
|
|
2145
|
+
resultsPerPage
|
|
2146
|
+
} = props;
|
|
2147
|
+
return concat(query.pipe(withLatestFrom(cursor), debounceTime(500), distinctUntilChanged(), switchMap(_ref11 => {
|
|
2148
|
+
let [q, c] = _ref11;
|
|
2149
|
+
if (q) {
|
|
2150
|
+
return fetchSearch({
|
|
2151
|
+
projectId,
|
|
2152
|
+
dataset,
|
|
2153
|
+
shop,
|
|
2154
|
+
query: q,
|
|
2155
|
+
cursor: c,
|
|
2156
|
+
resultsPerPage
|
|
2157
|
+
}).pipe(distinctUntilChanged());
|
|
2158
|
+
}
|
|
2159
|
+
return fetchList({
|
|
2160
|
+
projectId,
|
|
2161
|
+
dataset,
|
|
2162
|
+
shop,
|
|
2163
|
+
cursor: c,
|
|
2164
|
+
resultsPerPage
|
|
2165
|
+
});
|
|
2166
|
+
})));
|
|
2167
|
+
};
|
|
2109
2168
|
const DialogHeader = props => {
|
|
2110
2169
|
const {
|
|
2111
2170
|
title,
|
|
@@ -2203,65 +2262,6 @@ function File(props) {
|
|
|
2203
2262
|
}
|
|
2204
2263
|
const Search = styled(Stack)(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n position: sticky;\n top: 0;\n z-index: 1;\n"])));
|
|
2205
2264
|
styled.div(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n overflow-y: auto;\n max-height: 80vh;\n"])));
|
|
2206
|
-
const fetchSearch = props => {
|
|
2207
|
-
const {
|
|
2208
|
-
projectId,
|
|
2209
|
-
dataset,
|
|
2210
|
-
shop,
|
|
2211
|
-
query,
|
|
2212
|
-
cursor,
|
|
2213
|
-
resultsPerPage
|
|
2214
|
-
} = props;
|
|
2215
|
-
return defer(() => {
|
|
2216
|
-
return axios.get("https://".concat(projectId, ".api.sanity.work/v1/shopify/assets/").concat(dataset, "?shop=").concat(shop, "&query=").concat(encodeURIComponent(query)).concat(cursor && "&cursor=".concat(cursor), "&limit=").concat(resultsPerPage), {
|
|
2217
|
-
withCredentials: true,
|
|
2218
|
-
method: "GET"
|
|
2219
|
-
});
|
|
2220
|
-
}).pipe(map(result => result.data));
|
|
2221
|
-
};
|
|
2222
|
-
const fetchList = props => {
|
|
2223
|
-
const {
|
|
2224
|
-
projectId,
|
|
2225
|
-
dataset,
|
|
2226
|
-
shop,
|
|
2227
|
-
cursor,
|
|
2228
|
-
resultsPerPage
|
|
2229
|
-
} = props;
|
|
2230
|
-
return defer(() => axios.get("https://".concat(projectId, ".api.sanity.work/v1/shopify/assets/").concat(dataset, "?shop=").concat(shop).concat(cursor && "&cursor=".concat(cursor), "&limit=").concat(resultsPerPage), {
|
|
2231
|
-
withCredentials: true,
|
|
2232
|
-
method: "GET"
|
|
2233
|
-
})).pipe(map(result => result.data));
|
|
2234
|
-
};
|
|
2235
|
-
const search = props => {
|
|
2236
|
-
const {
|
|
2237
|
-
projectId,
|
|
2238
|
-
dataset,
|
|
2239
|
-
shop,
|
|
2240
|
-
query,
|
|
2241
|
-
cursor,
|
|
2242
|
-
resultsPerPage
|
|
2243
|
-
} = props;
|
|
2244
|
-
return concat(query.pipe(withLatestFrom(cursor), debounceTime(500), distinctUntilChanged(), switchMap(_ref11 => {
|
|
2245
|
-
let [q, c] = _ref11;
|
|
2246
|
-
if (q) {
|
|
2247
|
-
return fetchSearch({
|
|
2248
|
-
projectId,
|
|
2249
|
-
dataset,
|
|
2250
|
-
shop,
|
|
2251
|
-
query: q,
|
|
2252
|
-
cursor: c,
|
|
2253
|
-
resultsPerPage
|
|
2254
|
-
}).pipe(distinctUntilChanged());
|
|
2255
|
-
}
|
|
2256
|
-
return fetchList({
|
|
2257
|
-
projectId,
|
|
2258
|
-
dataset,
|
|
2259
|
-
shop,
|
|
2260
|
-
cursor: c,
|
|
2261
|
-
resultsPerPage
|
|
2262
|
-
});
|
|
2263
|
-
})));
|
|
2264
|
-
};
|
|
2265
2265
|
const RESULTS_PER_PAGE = 42;
|
|
2266
2266
|
const PHOTO_SPACING = 2;
|
|
2267
2267
|
const PHOTO_PADDING = 1;
|
|
@@ -2612,48 +2612,28 @@ const shopifyAssetSchema = config => {
|
|
|
2612
2612
|
},
|
|
2613
2613
|
fields: [defineField({
|
|
2614
2614
|
type: "string",
|
|
2615
|
-
name: "filename"
|
|
2615
|
+
name: "filename",
|
|
2616
|
+
title: "Filename"
|
|
2616
2617
|
}), defineField({
|
|
2617
2618
|
type: "string",
|
|
2618
|
-
name: "id"
|
|
2619
|
+
name: "id",
|
|
2620
|
+
title: "ID"
|
|
2619
2621
|
}), defineField({
|
|
2620
|
-
type: "
|
|
2622
|
+
type: "shopify.assetMetadata",
|
|
2621
2623
|
name: "meta",
|
|
2622
|
-
|
|
2623
|
-
type: "string",
|
|
2624
|
-
name: "alt"
|
|
2625
|
-
}), defineField({
|
|
2626
|
-
type: "number",
|
|
2627
|
-
name: "duration"
|
|
2628
|
-
}), defineField({
|
|
2629
|
-
type: "number",
|
|
2630
|
-
name: "fileSize"
|
|
2631
|
-
}), defineField({
|
|
2632
|
-
type: "number",
|
|
2633
|
-
name: "height"
|
|
2634
|
-
}), defineField({
|
|
2635
|
-
type: "number",
|
|
2636
|
-
name: "width"
|
|
2637
|
-
})]
|
|
2624
|
+
title: "Metadata"
|
|
2638
2625
|
}), defineField({
|
|
2639
|
-
type: "
|
|
2626
|
+
type: "shopify.assetPreview",
|
|
2640
2627
|
name: "preview",
|
|
2641
|
-
|
|
2642
|
-
type: "number",
|
|
2643
|
-
name: "height"
|
|
2644
|
-
}), defineField({
|
|
2645
|
-
type: "number",
|
|
2646
|
-
name: "width"
|
|
2647
|
-
}), defineField({
|
|
2648
|
-
type: "url",
|
|
2649
|
-
name: "url"
|
|
2650
|
-
})]
|
|
2628
|
+
title: "Preview"
|
|
2651
2629
|
}), defineField({
|
|
2652
2630
|
type: "string",
|
|
2653
|
-
name: "type"
|
|
2631
|
+
name: "type",
|
|
2632
|
+
title: "Type"
|
|
2654
2633
|
}), defineField({
|
|
2655
2634
|
type: "url",
|
|
2656
|
-
name: "url"
|
|
2635
|
+
name: "url",
|
|
2636
|
+
title: "URL"
|
|
2657
2637
|
})],
|
|
2658
2638
|
...{
|
|
2659
2639
|
components: {
|
|
@@ -2692,11 +2672,55 @@ const shopifyAssetSchema = config => {
|
|
|
2692
2672
|
}
|
|
2693
2673
|
});
|
|
2694
2674
|
};
|
|
2675
|
+
const shopifyAssetPreviewSchema = defineType({
|
|
2676
|
+
type: "object",
|
|
2677
|
+
name: "shopify.assetPreview",
|
|
2678
|
+
title: "Asset preview",
|
|
2679
|
+
fields: [defineField({
|
|
2680
|
+
type: "number",
|
|
2681
|
+
name: "height",
|
|
2682
|
+
title: "Height"
|
|
2683
|
+
}), defineField({
|
|
2684
|
+
type: "number",
|
|
2685
|
+
name: "width",
|
|
2686
|
+
title: "Width"
|
|
2687
|
+
}), defineField({
|
|
2688
|
+
type: "url",
|
|
2689
|
+
name: "url",
|
|
2690
|
+
title: "URL"
|
|
2691
|
+
})]
|
|
2692
|
+
});
|
|
2693
|
+
const shopifyAssetMetadataSchema = defineType({
|
|
2694
|
+
type: "object",
|
|
2695
|
+
name: "shopify.assetMetadata",
|
|
2696
|
+
title: "Asset metadata",
|
|
2697
|
+
fields: [defineField({
|
|
2698
|
+
type: "string",
|
|
2699
|
+
name: "alt",
|
|
2700
|
+
title: "Alternative text"
|
|
2701
|
+
}), defineField({
|
|
2702
|
+
type: "number",
|
|
2703
|
+
name: "duration",
|
|
2704
|
+
title: "Duration"
|
|
2705
|
+
}), defineField({
|
|
2706
|
+
type: "number",
|
|
2707
|
+
name: "fileSize",
|
|
2708
|
+
title: "File size"
|
|
2709
|
+
}), defineField({
|
|
2710
|
+
type: "number",
|
|
2711
|
+
name: "height",
|
|
2712
|
+
title: "Height"
|
|
2713
|
+
}), defineField({
|
|
2714
|
+
type: "number",
|
|
2715
|
+
name: "width",
|
|
2716
|
+
title: "Width"
|
|
2717
|
+
})]
|
|
2718
|
+
});
|
|
2695
2719
|
const shopifyAssets = definePlugin(config => {
|
|
2696
2720
|
return {
|
|
2697
2721
|
name: "shopify-asset-schema",
|
|
2698
2722
|
schema: {
|
|
2699
|
-
types: [shopifyAssetSchema(config)]
|
|
2723
|
+
types: [shopifyAssetPreviewSchema, shopifyAssetMetadataSchema, shopifyAssetSchema(config)]
|
|
2700
2724
|
}
|
|
2701
2725
|
};
|
|
2702
2726
|
});
|