sanity-plugin-shopify-assets 1.2.0 → 1.2.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/dist/index.esm.js +124 -71
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +124 -71
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
|
|
2
|
-
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
3
1
|
import { useProjectId, useDataset, PatchEvent, set, unset, DiffFromTo, defineType, defineField, definePlugin } from 'sanity';
|
|
4
2
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
5
3
|
import { LaunchIcon, ErrorOutlineIcon } from '@sanity/icons';
|
|
@@ -14,29 +12,81 @@ import PhotoAlbum from 'react-photo-album';
|
|
|
14
12
|
import InfiniteScroll from 'react-infinite-scroll-component';
|
|
15
13
|
import { withLatestFrom, debounceTime, distinctUntilChanged, switchMap, map } from 'rxjs/operators';
|
|
16
14
|
import axios from 'axios';
|
|
17
|
-
const Root = styled.div
|
|
15
|
+
const Root = styled.div`
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
background-origin: content-box;
|
|
18
|
+
background-repeat: no-repeat;
|
|
19
|
+
background-clip: border-box;
|
|
20
|
+
background-size: cover;
|
|
21
|
+
background-color: ${_ref => {
|
|
18
22
|
let {
|
|
19
23
|
theme
|
|
20
24
|
} = _ref;
|
|
21
25
|
return theme.sanity.color.card.enabled.bg2;
|
|
22
|
-
}
|
|
26
|
+
}};
|
|
27
|
+
position: relative;
|
|
28
|
+
outline: none !important;
|
|
29
|
+
border: ${_ref2 => {
|
|
23
30
|
let {
|
|
24
31
|
theme
|
|
25
32
|
} = _ref2;
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
|
|
33
|
+
return `1px solid ${theme.sanity.color.card.enabled.border}`;
|
|
34
|
+
}};
|
|
35
|
+
box-sizing: content-box;
|
|
36
|
+
user-drag: none;
|
|
37
|
+
|
|
38
|
+
&:hover {
|
|
39
|
+
opacity: 0.85;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
&:focus,
|
|
43
|
+
&:active {
|
|
44
|
+
border: 1px solid var(--input-border-color-focus);
|
|
45
|
+
box-shadow: inset 0 0 0 3px var(--input-border-color-focus);
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
const InfoLine = styled(Card)`
|
|
49
|
+
${_ref3 => {
|
|
29
50
|
let {
|
|
30
51
|
theme
|
|
31
52
|
} = _ref3;
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
|
|
53
|
+
return `
|
|
54
|
+
--infoline-fg: ${theme.sanity.color.card.enabled.fg};
|
|
55
|
+
--infoline-bg: ${theme.sanity.color.card.enabled.bg};
|
|
56
|
+
`;
|
|
57
|
+
}};
|
|
58
|
+
user-drag: none;
|
|
59
|
+
position: absolute;
|
|
60
|
+
background-color: var(--infoline-bg);
|
|
61
|
+
top: 0;
|
|
62
|
+
left: 0;
|
|
63
|
+
max-width: 65%;
|
|
64
|
+
overflow-wrap: break-word;
|
|
65
|
+
|
|
66
|
+
[data-ui='Text'] {
|
|
67
|
+
color: var(--infoline-fg);
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
70
|
+
const DurationLine = styled(Card)`
|
|
71
|
+
${_ref4 => {
|
|
35
72
|
let {
|
|
36
73
|
theme
|
|
37
74
|
} = _ref4;
|
|
38
|
-
return
|
|
39
|
-
}
|
|
75
|
+
return `
|
|
76
|
+
--durationline-fg: ${theme.sanity.color.card.enabled.bg};
|
|
77
|
+
--durationline-bg: ${theme.sanity.color.card.enabled.fg};
|
|
78
|
+
`;
|
|
79
|
+
}};
|
|
80
|
+
user-drag: none;
|
|
81
|
+
position: absolute;
|
|
82
|
+
background-color: var(--durationline-bg);
|
|
83
|
+
top: 0;
|
|
84
|
+
right: 0;
|
|
85
|
+
|
|
86
|
+
[data-ui='Text'] {
|
|
87
|
+
color: var(--durationline-fg);
|
|
88
|
+
}
|
|
89
|
+
`;
|
|
40
90
|
const VideoPlayer = _ref5 => {
|
|
41
91
|
let {
|
|
42
92
|
src,
|
|
@@ -45,8 +95,7 @@ const VideoPlayer = _ref5 => {
|
|
|
45
95
|
const videoNode = React.useRef(null);
|
|
46
96
|
const player = React.useRef();
|
|
47
97
|
useEffect(() => {
|
|
48
|
-
|
|
49
|
-
player.current = videojs((_a = videoNode.current) != null ? _a : "", {
|
|
98
|
+
player.current = videojs(videoNode.current ?? "", {
|
|
50
99
|
sources: [{
|
|
51
100
|
src
|
|
52
101
|
}],
|
|
@@ -81,30 +130,34 @@ const VideoPlayer = _ref5 => {
|
|
|
81
130
|
})]
|
|
82
131
|
});
|
|
83
132
|
};
|
|
84
|
-
const StyledBox = styled(Box)
|
|
133
|
+
const StyledBox = styled(Box)`
|
|
134
|
+
background-color: ${_ref6 => {
|
|
85
135
|
let {
|
|
86
136
|
theme
|
|
87
137
|
} = _ref6;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
138
|
+
return theme.sanity.color?.card?.enabled?.bg2;
|
|
139
|
+
}};
|
|
140
|
+
border: ${_ref7 => {
|
|
91
141
|
let {
|
|
92
142
|
theme
|
|
93
143
|
} = _ref7;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
144
|
+
return `1px solid ${theme.sanity?.color?.card?.enabled?.border}`;
|
|
145
|
+
}};
|
|
146
|
+
display: flex;
|
|
147
|
+
justify-content: center;
|
|
148
|
+
margin-bottom: ${_ref8 => {
|
|
97
149
|
let {
|
|
98
150
|
theme
|
|
99
151
|
} = _ref8;
|
|
100
152
|
return theme.sanity.space[4];
|
|
101
|
-
}
|
|
153
|
+
}};
|
|
154
|
+
position: relative;
|
|
155
|
+
`;
|
|
102
156
|
const RenderAsset = _ref9 => {
|
|
103
157
|
let {
|
|
104
158
|
value,
|
|
105
159
|
url
|
|
106
160
|
} = _ref9;
|
|
107
|
-
var _a;
|
|
108
161
|
switch (value.type) {
|
|
109
162
|
case "video":
|
|
110
163
|
return /* @__PURE__ */jsx(VideoPlayer, {
|
|
@@ -116,7 +169,7 @@ const RenderAsset = _ref9 => {
|
|
|
116
169
|
justify: "center",
|
|
117
170
|
children: /* @__PURE__ */jsx("img", {
|
|
118
171
|
alt: "preview",
|
|
119
|
-
src:
|
|
172
|
+
src: value?.preview?.url,
|
|
120
173
|
style: {
|
|
121
174
|
maxWidth: "100%",
|
|
122
175
|
height: "auto",
|
|
@@ -127,10 +180,10 @@ const RenderAsset = _ref9 => {
|
|
|
127
180
|
});
|
|
128
181
|
}
|
|
129
182
|
};
|
|
130
|
-
const AssetPreview =
|
|
183
|
+
const AssetPreview = _ref0 => {
|
|
131
184
|
let {
|
|
132
185
|
value
|
|
133
|
-
} =
|
|
186
|
+
} = _ref0;
|
|
134
187
|
const url = value && value.url;
|
|
135
188
|
if (!value || !url) {
|
|
136
189
|
return null;
|
|
@@ -154,8 +207,8 @@ const AssetPreview = _ref10 => {
|
|
|
154
207
|
margin: 2,
|
|
155
208
|
children: /* @__PURE__ */jsxs(Text, {
|
|
156
209
|
size: 1,
|
|
157
|
-
title:
|
|
158
|
-
children: [filename, " ", fileSize &&
|
|
210
|
+
title: `Select ${filename}`,
|
|
211
|
+
children: [filename, " ", fileSize && `(${prettyBytes(fileSize)})`]
|
|
159
212
|
})
|
|
160
213
|
}), duration && /* @__PURE__ */jsx(DurationLine, {
|
|
161
214
|
padding: 2,
|
|
@@ -163,7 +216,7 @@ const AssetPreview = _ref10 => {
|
|
|
163
216
|
margin: 2,
|
|
164
217
|
children: /* @__PURE__ */jsx(Text, {
|
|
165
218
|
size: 1,
|
|
166
|
-
title:
|
|
219
|
+
title: `Video duration: ${filename}`,
|
|
167
220
|
children: prettyMilliseconds(duration, {
|
|
168
221
|
colonNotation: true,
|
|
169
222
|
secondsDecimalDigits: 0
|
|
@@ -182,7 +235,7 @@ const fetchSearch = props => {
|
|
|
182
235
|
resultsPerPage
|
|
183
236
|
} = props;
|
|
184
237
|
return defer(() => {
|
|
185
|
-
return axios.get(
|
|
238
|
+
return axios.get(`https://${projectId}.api.sanity.io/v1/shopify/assets/${dataset}?shop=${shop}&query=${encodeURIComponent(query)}${cursor && `&cursor=${cursor}`}&limit=${resultsPerPage}`, {
|
|
186
239
|
withCredentials: true,
|
|
187
240
|
method: "GET"
|
|
188
241
|
});
|
|
@@ -196,7 +249,7 @@ const fetchList = props => {
|
|
|
196
249
|
cursor,
|
|
197
250
|
resultsPerPage
|
|
198
251
|
} = props;
|
|
199
|
-
return defer(() => axios.get(
|
|
252
|
+
return defer(() => axios.get(`https://${projectId}.api.sanity.io/v1/shopify/assets/${dataset}?shop=${shop}${cursor && `&cursor=${cursor}`}&limit=${resultsPerPage}`, {
|
|
200
253
|
withCredentials: true,
|
|
201
254
|
method: "GET"
|
|
202
255
|
})).pipe(map(result => result.data));
|
|
@@ -210,8 +263,8 @@ const search = props => {
|
|
|
210
263
|
cursor,
|
|
211
264
|
resultsPerPage
|
|
212
265
|
} = props;
|
|
213
|
-
return concat(query.pipe(withLatestFrom(cursor), debounceTime(500), distinctUntilChanged(), switchMap(
|
|
214
|
-
let [q, c] =
|
|
266
|
+
return concat(query.pipe(withLatestFrom(cursor), debounceTime(500), distinctUntilChanged(), switchMap(_ref1 => {
|
|
267
|
+
let [q, c] = _ref1;
|
|
215
268
|
if (q) {
|
|
216
269
|
return fetchSearch({
|
|
217
270
|
projectId,
|
|
@@ -237,7 +290,7 @@ const DialogHeader = props => {
|
|
|
237
290
|
shopifyDomain
|
|
238
291
|
} = props;
|
|
239
292
|
const handleOpenInNewTab = useCallback(() => {
|
|
240
|
-
window.open(
|
|
293
|
+
window.open(`https://${shopifyDomain}/admin/settings/files`, "_blank");
|
|
241
294
|
}, [shopifyDomain]);
|
|
242
295
|
return /* @__PURE__ */jsxs(Flex, {
|
|
243
296
|
align: "center",
|
|
@@ -265,10 +318,7 @@ const DialogHeader = props => {
|
|
|
265
318
|
})]
|
|
266
319
|
});
|
|
267
320
|
};
|
|
268
|
-
const extractName = name =>
|
|
269
|
-
var _a, _b, _c;
|
|
270
|
-
return (_c = (_b = (_a = name == null ? void 0 : name.split("/")) == null ? void 0 : _a.pop()) == null ? void 0 : _b.split("?")[0]) != null ? _c : "";
|
|
271
|
-
};
|
|
321
|
+
const extractName = name => name?.split("/")?.pop()?.split("?")[0] ?? "";
|
|
272
322
|
function File(props) {
|
|
273
323
|
const {
|
|
274
324
|
onClick,
|
|
@@ -290,12 +340,12 @@ function File(props) {
|
|
|
290
340
|
}, [onClick, data, filename]);
|
|
291
341
|
return /* @__PURE__ */jsxs(Root, {
|
|
292
342
|
ref: rootElm,
|
|
293
|
-
title:
|
|
343
|
+
title: `${filename}`,
|
|
294
344
|
tabIndex: 0,
|
|
295
345
|
style: {
|
|
296
|
-
width:
|
|
297
|
-
height:
|
|
298
|
-
backgroundImage:
|
|
346
|
+
width: `${width}px`,
|
|
347
|
+
height: `${height}px`,
|
|
348
|
+
backgroundImage: `url("${preview?.url}")`
|
|
299
349
|
},
|
|
300
350
|
onClick: handleClick,
|
|
301
351
|
children: [/* @__PURE__ */jsx(InfoLine, {
|
|
@@ -304,8 +354,8 @@ function File(props) {
|
|
|
304
354
|
margin: 2,
|
|
305
355
|
children: /* @__PURE__ */jsxs(Text, {
|
|
306
356
|
size: 1,
|
|
307
|
-
title:
|
|
308
|
-
children: [filename, " ", meta.fileSize &&
|
|
357
|
+
title: `Select ${filename}`,
|
|
358
|
+
children: [filename, " ", meta.fileSize && `(${prettyBytes(meta.fileSize)})`]
|
|
309
359
|
})
|
|
310
360
|
}), meta.duration && /* @__PURE__ */jsx(DurationLine, {
|
|
311
361
|
padding: 2,
|
|
@@ -313,7 +363,7 @@ function File(props) {
|
|
|
313
363
|
margin: 2,
|
|
314
364
|
children: /* @__PURE__ */jsx(Text, {
|
|
315
365
|
size: 1,
|
|
316
|
-
title:
|
|
366
|
+
title: `Video duration: ${filename}`,
|
|
317
367
|
children: prettyMilliseconds(meta.duration, {
|
|
318
368
|
colonNotation: true,
|
|
319
369
|
secondsDecimalDigits: 0
|
|
@@ -322,8 +372,15 @@ function File(props) {
|
|
|
322
372
|
})]
|
|
323
373
|
});
|
|
324
374
|
}
|
|
325
|
-
const Search = styled(Stack)
|
|
326
|
-
|
|
375
|
+
const Search = styled(Stack)`
|
|
376
|
+
position: sticky;
|
|
377
|
+
top: 0;
|
|
378
|
+
z-index: 1;
|
|
379
|
+
`;
|
|
380
|
+
styled.div`
|
|
381
|
+
overflow-y: auto;
|
|
382
|
+
max-height: 80vh;
|
|
383
|
+
`;
|
|
327
384
|
const RESULTS_PER_PAGE = 42;
|
|
328
385
|
const PHOTO_SPACING = 2;
|
|
329
386
|
const PHOTO_PADDING = 1;
|
|
@@ -363,7 +420,7 @@ function ShopifyAssetPicker(props) {
|
|
|
363
420
|
setIsLoading(false);
|
|
364
421
|
},
|
|
365
422
|
error: err => {
|
|
366
|
-
setError(
|
|
423
|
+
setError(`${err.response.data.message || err.message || "An error occurred"} - check plugin configuration`);
|
|
367
424
|
}
|
|
368
425
|
});
|
|
369
426
|
return () => searchSubscription.unsubscribe();
|
|
@@ -383,11 +440,11 @@ function ShopifyAssetPicker(props) {
|
|
|
383
440
|
searchSubject$.next(query);
|
|
384
441
|
}, [cursorSubject$, pageInfo, searchSubject$, query]);
|
|
385
442
|
const handleSelect = useCallback(file => {
|
|
386
|
-
file._key = value
|
|
443
|
+
file._key = value?._key;
|
|
387
444
|
file._type = schemaType.name;
|
|
388
445
|
onChange(PatchEvent.from([set(file)]));
|
|
389
446
|
onClose();
|
|
390
|
-
}, [onChange, onClose, schemaType.name, value
|
|
447
|
+
}, [onChange, onClose, schemaType.name, value?._key]);
|
|
391
448
|
const renderFile = useCallback(fileProps => {
|
|
392
449
|
const {
|
|
393
450
|
photo,
|
|
@@ -458,7 +515,7 @@ function ShopifyAssetPicker(props) {
|
|
|
458
515
|
}), /* @__PURE__ */jsx(InfiniteScroll, {
|
|
459
516
|
dataLength: searchResults.length,
|
|
460
517
|
next: handleScollerLoadMore,
|
|
461
|
-
hasMore: pageInfo ? pageInfo
|
|
518
|
+
hasMore: pageInfo ? pageInfo?.hasNextPage : true,
|
|
462
519
|
scrollThreshold: 0.99,
|
|
463
520
|
height: "60vh",
|
|
464
521
|
loader: /* @__PURE__ */jsx(Flex, {
|
|
@@ -484,21 +541,18 @@ function ShopifyAssetPicker(props) {
|
|
|
484
541
|
spacing: PHOTO_SPACING,
|
|
485
542
|
padding: PHOTO_PADDING,
|
|
486
543
|
targetRowHeight: handleWidth,
|
|
487
|
-
photos: searchResults.map(file => {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
data: file
|
|
495
|
-
};
|
|
496
|
-
}),
|
|
544
|
+
photos: searchResults.map(file => ({
|
|
545
|
+
src: file?.preview?.url,
|
|
546
|
+
width: file?.preview?.width || 2048,
|
|
547
|
+
height: file?.preview?.height || 2048,
|
|
548
|
+
key: file.id,
|
|
549
|
+
data: file
|
|
550
|
+
})),
|
|
497
551
|
renderPhoto: renderFile,
|
|
498
552
|
componentsProps: {
|
|
499
553
|
containerProps: {
|
|
500
554
|
style: {
|
|
501
|
-
marginBottom:
|
|
555
|
+
marginBottom: `${PHOTO_SPACING}px`
|
|
502
556
|
}
|
|
503
557
|
}
|
|
504
558
|
}
|
|
@@ -607,15 +661,14 @@ function ShopifyAssetInput(props) {
|
|
|
607
661
|
})]
|
|
608
662
|
});
|
|
609
663
|
}
|
|
610
|
-
const CloudinaryDiffPreview =
|
|
664
|
+
const CloudinaryDiffPreview = _ref10 => {
|
|
611
665
|
let {
|
|
612
666
|
value
|
|
613
|
-
} =
|
|
614
|
-
var _a, _b;
|
|
667
|
+
} = _ref10;
|
|
615
668
|
if (!value) {
|
|
616
669
|
return null;
|
|
617
670
|
}
|
|
618
|
-
if (
|
|
671
|
+
if (value?.preview?.url) {
|
|
619
672
|
return /* @__PURE__ */jsx(Flex, {
|
|
620
673
|
justify: "center",
|
|
621
674
|
align: "center",
|
|
@@ -625,7 +678,7 @@ const CloudinaryDiffPreview = _ref12 => {
|
|
|
625
678
|
space: 2,
|
|
626
679
|
children: [/* @__PURE__ */jsx("img", {
|
|
627
680
|
alt: "preview",
|
|
628
|
-
src:
|
|
681
|
+
src: value?.preview?.url,
|
|
629
682
|
style: {
|
|
630
683
|
objectFit: "contain",
|
|
631
684
|
margin: "auto",
|
|
@@ -649,11 +702,11 @@ const CloudinaryDiffPreview = _ref12 => {
|
|
|
649
702
|
})
|
|
650
703
|
});
|
|
651
704
|
};
|
|
652
|
-
const AssetDiff =
|
|
705
|
+
const AssetDiff = _ref11 => {
|
|
653
706
|
let {
|
|
654
707
|
diff,
|
|
655
708
|
schemaType
|
|
656
|
-
} =
|
|
709
|
+
} = _ref11;
|
|
657
710
|
return /* @__PURE__ */jsx(DiffFromTo, {
|
|
658
711
|
diff,
|
|
659
712
|
schemaType,
|
|
@@ -712,14 +765,14 @@ const shopifyAssetSchema = config => {
|
|
|
712
765
|
filename: "filename",
|
|
713
766
|
type: "type"
|
|
714
767
|
},
|
|
715
|
-
prepare(
|
|
768
|
+
prepare(_ref12) {
|
|
716
769
|
let {
|
|
717
770
|
url,
|
|
718
771
|
meta,
|
|
719
772
|
preview,
|
|
720
773
|
filename,
|
|
721
774
|
type
|
|
722
|
-
} =
|
|
775
|
+
} = _ref12;
|
|
723
776
|
return {
|
|
724
777
|
title: filename,
|
|
725
778
|
subtitle: type,
|