sanity-plugin-shopify-assets 1.2.2 → 2.0.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/dist/index.esm.js DELETED
@@ -1,859 +0,0 @@
1
- import { useProjectId, useDataset, useClient, PatchEvent, set, unset, DiffFromTo, defineType, defineField, definePlugin } from 'sanity';
2
- import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
3
- import { LaunchIcon, ErrorOutlineIcon } from '@sanity/icons';
4
- import { Card, Box, Text, Flex, Button, Stack, Dialog, Inline, TextInput, Spinner, Grid } from '@sanity/ui';
5
- import React, { useEffect, useCallback, useRef, useState, useMemo } from 'react';
6
- import prettyBytes from 'pretty-bytes';
7
- import prettyMilliseconds from 'pretty-ms';
8
- import { styled } from 'styled-components';
9
- import videojs from 'video.js';
10
- import { concat, defer, BehaviorSubject } from 'rxjs';
11
- import PhotoAlbum from 'react-photo-album';
12
- import InfiniteScroll from 'react-infinite-scroll-component';
13
- import { withLatestFrom, debounceTime, distinctUntilChanged, switchMap, map } from 'rxjs/operators';
14
- import axios from 'axios';
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 => {
22
- let {
23
- theme
24
- } = _ref;
25
- return theme.sanity.color.card.enabled.bg2;
26
- }};
27
- position: relative;
28
- outline: none !important;
29
- border: ${_ref2 => {
30
- let {
31
- theme
32
- } = _ref2;
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 => {
50
- let {
51
- theme
52
- } = _ref3;
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 => {
72
- let {
73
- theme
74
- } = _ref4;
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
- `;
90
- const VideoPlayer = _ref5 => {
91
- let {
92
- src,
93
- kind
94
- } = _ref5;
95
- const videoNode = React.useRef(null);
96
- const player = React.useRef();
97
- useEffect(() => {
98
- player.current = videojs(videoNode.current ?? "", {
99
- sources: [{
100
- src
101
- }],
102
- controls: true
103
- });
104
- player.current.src({
105
- src
106
- });
107
- }, [src]);
108
- const stopPropagation = useCallback(event => {
109
- event.stopPropagation();
110
- }, []);
111
- const className = {
112
- player: "video-js vjs-16-9 vjs-big-play-centered",
113
- diff: "video-js vjs-layout-tiny vjs-fluid"
114
- };
115
- const style = {
116
- position: "relative"
117
- };
118
- return /* @__PURE__ */jsxs("div", {
119
- children: [/* @__PURE__ */jsx("link", {
120
- href: "https://vjs.zencdn.net/7.8.4/video-js.css",
121
- rel: "stylesheet"
122
- }), /* @__PURE__ */jsx("div", {
123
- "data-vjs-player": true,
124
- children: /* @__PURE__ */jsx("video", {
125
- onClick: stopPropagation,
126
- style: kind === "diff" ? style : {},
127
- className: className[kind],
128
- ref: videoNode
129
- })
130
- })]
131
- });
132
- };
133
- const StyledBox = styled(Box)`
134
- background-color: ${_ref6 => {
135
- let {
136
- theme
137
- } = _ref6;
138
- return theme.sanity.color?.card?.enabled?.bg2;
139
- }};
140
- border: ${_ref7 => {
141
- let {
142
- theme
143
- } = _ref7;
144
- return `1px solid ${theme.sanity?.color?.card?.enabled?.border}`;
145
- }};
146
- display: flex;
147
- justify-content: center;
148
- margin-bottom: ${_ref8 => {
149
- let {
150
- theme
151
- } = _ref8;
152
- return theme.sanity.space[4];
153
- }};
154
- position: relative;
155
- `;
156
- const RenderAsset = _ref9 => {
157
- let {
158
- value,
159
- url
160
- } = _ref9;
161
- switch (value.type) {
162
- case "video":
163
- return /* @__PURE__ */jsx(VideoPlayer, {
164
- src: url,
165
- kind: "player"
166
- });
167
- default:
168
- return /* @__PURE__ */jsx(Flex, {
169
- justify: "center",
170
- children: /* @__PURE__ */jsx("img", {
171
- alt: "preview",
172
- src: value?.preview?.url,
173
- style: {
174
- maxWidth: "100%",
175
- height: "auto",
176
- display: "block",
177
- maxHeight: "30vh"
178
- }
179
- })
180
- });
181
- }
182
- };
183
- const AssetPreview = _ref0 => {
184
- let {
185
- value
186
- } = _ref0;
187
- const url = value && value.url;
188
- if (!value || !url) {
189
- return null;
190
- }
191
- const {
192
- filename,
193
- meta
194
- } = value;
195
- const {
196
- fileSize,
197
- duration
198
- } = meta;
199
- return /* @__PURE__ */jsxs(StyledBox, {
200
- marginBottom: 2,
201
- children: [/* @__PURE__ */jsx(RenderAsset, {
202
- value,
203
- url
204
- }), /* @__PURE__ */jsx(InfoLine, {
205
- padding: 2,
206
- radius: 2,
207
- margin: 2,
208
- children: /* @__PURE__ */jsxs(Text, {
209
- size: 1,
210
- title: `Select ${filename}`,
211
- children: [filename, " ", fileSize && `(${prettyBytes(fileSize)})`]
212
- })
213
- }), duration && /* @__PURE__ */jsx(DurationLine, {
214
- padding: 2,
215
- radius: 2,
216
- margin: 2,
217
- children: /* @__PURE__ */jsx(Text, {
218
- size: 1,
219
- title: `Video duration: ${filename}`,
220
- children: prettyMilliseconds(duration, {
221
- colonNotation: true,
222
- secondsDecimalDigits: 0
223
- })
224
- })
225
- })]
226
- });
227
- };
228
- const fetchSearch = props => {
229
- const {
230
- projectId,
231
- dataset,
232
- shop,
233
- query,
234
- cursor,
235
- resultsPerPage,
236
- token
237
- } = props;
238
- return defer(() => {
239
- return axios.get(`https://${projectId}.api.sanity.io/v1/shopify/assets/${dataset}?shop=${shop}&query=${encodeURIComponent(query)}${cursor && `&cursor=${cursor}`}&limit=${resultsPerPage}`, {
240
- withCredentials: true,
241
- method: "GET",
242
- headers: token ? {
243
- Authorization: `Bearer ${token}`
244
- } : {}
245
- });
246
- }).pipe(map(result => result.data));
247
- };
248
- const fetchList = props => {
249
- const {
250
- projectId,
251
- dataset,
252
- shop,
253
- cursor,
254
- resultsPerPage,
255
- token
256
- } = props;
257
- return defer(() => axios.get(`https://${projectId}.api.sanity.io/v1/shopify/assets/${dataset}?shop=${shop}${cursor && `&cursor=${cursor}`}&limit=${resultsPerPage}`, {
258
- withCredentials: true,
259
- method: "GET",
260
- headers: token ? {
261
- Authorization: `Bearer ${token}`
262
- } : {}
263
- })).pipe(map(result => result.data));
264
- };
265
- const search = props => {
266
- const {
267
- projectId,
268
- dataset,
269
- shop,
270
- query,
271
- cursor,
272
- resultsPerPage,
273
- token
274
- } = props;
275
- return concat(query.pipe(withLatestFrom(cursor), debounceTime(500), distinctUntilChanged(), switchMap(_ref1 => {
276
- let [q, c] = _ref1;
277
- if (q) {
278
- return fetchSearch({
279
- projectId,
280
- dataset,
281
- shop,
282
- query: q,
283
- cursor: c,
284
- resultsPerPage,
285
- token
286
- }).pipe(distinctUntilChanged());
287
- }
288
- return fetchList({
289
- projectId,
290
- dataset,
291
- shop,
292
- cursor: c,
293
- resultsPerPage,
294
- token
295
- });
296
- })));
297
- };
298
- const DialogHeader = props => {
299
- const {
300
- title,
301
- shopifyDomain
302
- } = props;
303
- const handleOpenInNewTab = useCallback(() => {
304
- window.open(`https://${shopifyDomain}/admin/settings/files`, "_blank");
305
- }, [shopifyDomain]);
306
- return /* @__PURE__ */jsxs(Flex, {
307
- align: "center",
308
- children: [title, /* @__PURE__ */jsx("input", {
309
- style: {
310
- opacity: 0
311
- },
312
- tabIndex: -1,
313
- type: "button"
314
- }), /* @__PURE__ */jsx(Box, {
315
- style: {
316
- position: "absolute",
317
- right: "-1.5em"
318
- },
319
- children: /* @__PURE__ */jsx(Box, {
320
- className: "button-large",
321
- children: /* @__PURE__ */jsx(Button, {
322
- fontSize: 1,
323
- icon: LaunchIcon,
324
- mode: "bleed",
325
- onClick: handleOpenInNewTab,
326
- text: "Add New"
327
- })
328
- })
329
- })]
330
- });
331
- };
332
- const extractName = name => name?.split("/")?.pop()?.split("?")[0] ?? "";
333
- function File(props) {
334
- const {
335
- onClick,
336
- data,
337
- width,
338
- height
339
- } = props;
340
- const rootElm = useRef(null);
341
- const {
342
- preview,
343
- meta
344
- } = data;
345
- const filename = extractName(data.url);
346
- const handleClick = useCallback(() => {
347
- onClick({
348
- ...data,
349
- filename
350
- });
351
- }, [onClick, data, filename]);
352
- return /* @__PURE__ */jsxs(Root, {
353
- ref: rootElm,
354
- title: `${filename}`,
355
- tabIndex: 0,
356
- style: {
357
- width: `${width}px`,
358
- height: `${height}px`,
359
- backgroundImage: `url("${preview?.url}")`
360
- },
361
- onClick: handleClick,
362
- children: [/* @__PURE__ */jsx(InfoLine, {
363
- padding: 2,
364
- radius: 2,
365
- margin: 2,
366
- children: /* @__PURE__ */jsxs(Text, {
367
- size: 1,
368
- title: `Select ${filename}`,
369
- children: [filename, " ", meta.fileSize && `(${prettyBytes(meta.fileSize)})`]
370
- })
371
- }), meta.duration && /* @__PURE__ */jsx(DurationLine, {
372
- padding: 2,
373
- radius: 2,
374
- margin: 2,
375
- children: /* @__PURE__ */jsx(Text, {
376
- size: 1,
377
- title: `Video duration: ${filename}`,
378
- children: prettyMilliseconds(meta.duration, {
379
- colonNotation: true,
380
- secondsDecimalDigits: 0
381
- })
382
- })
383
- })]
384
- });
385
- }
386
- const Search = styled(Stack)`
387
- position: sticky;
388
- top: 0;
389
- z-index: 1;
390
- `;
391
- styled.div`
392
- overflow-y: auto;
393
- max-height: 80vh;
394
- `;
395
- const RESULTS_PER_PAGE = 42;
396
- const PHOTO_SPACING = 2;
397
- const PHOTO_PADDING = 1;
398
- function ShopifyAssetPicker(props) {
399
- const {
400
- isOpen,
401
- onClose,
402
- shopifyDomain,
403
- onChange,
404
- schemaType,
405
- value
406
- } = props;
407
- const projectId = useProjectId();
408
- const dataset = useDataset();
409
- const client = useClient({
410
- apiVersion: "2021-06-07"
411
- });
412
- const token = client.config().token;
413
- const [error, setError] = useState("");
414
- const [query, setQuery] = useState("");
415
- const [searchResults, setSearchResults] = useState([]);
416
- const [pageInfo, setPageInfo] = useState();
417
- const [isLoading, setIsLoading] = useState(true);
418
- const searchSubject$ = useMemo(() => new BehaviorSubject(""), []);
419
- const cursorSubject$ = useMemo(() => new BehaviorSubject(""), []);
420
- useEffect(() => {
421
- if (!shopifyDomain) setError("Please configure your Shopify domain in the plugin config");
422
- }, [shopifyDomain]);
423
- useEffect(() => {
424
- const searchSubscription = search({
425
- projectId,
426
- dataset,
427
- shop: shopifyDomain,
428
- query: searchSubject$,
429
- cursor: cursorSubject$,
430
- resultsPerPage: RESULTS_PER_PAGE,
431
- token
432
- }).subscribe({
433
- next: results => {
434
- setSearchResults(prevResults => [...prevResults, ...results.assets]);
435
- setPageInfo(results.pageInfo);
436
- setIsLoading(false);
437
- },
438
- error: err => {
439
- setError(`${err.response?.data?.message || err.message || "An error occurred"} - check plugin configuration`);
440
- }
441
- });
442
- return () => searchSubscription.unsubscribe();
443
- }, [searchSubject$, cursorSubject$, shopifyDomain, projectId, dataset, token]);
444
- const handleSearchTermChanged = useCallback(event => {
445
- const newQuery = event.currentTarget.value;
446
- setQuery(newQuery);
447
- setSearchResults([]);
448
- setPageInfo(void 0);
449
- setIsLoading(true);
450
- cursorSubject$.next("");
451
- searchSubject$.next(newQuery);
452
- }, [cursorSubject$, searchSubject$]);
453
- const handleScollerLoadMore = useCallback(() => {
454
- setIsLoading(true);
455
- if (pageInfo) cursorSubject$.next(pageInfo.cursor);
456
- searchSubject$.next(query);
457
- }, [cursorSubject$, pageInfo, searchSubject$, query]);
458
- const handleSelect = useCallback(file => {
459
- file._key = value?._key;
460
- file._type = schemaType.name;
461
- onChange(PatchEvent.from([set(file)]));
462
- onClose();
463
- }, [onChange, onClose, schemaType.name, value?._key]);
464
- const renderFile = useCallback(fileProps => {
465
- const {
466
- photo,
467
- layout
468
- } = fileProps;
469
- return /* @__PURE__ */jsx(File, {
470
- onClick: handleSelect,
471
- data: photo.data,
472
- width: layout.width,
473
- height: layout.height
474
- });
475
- }, [handleSelect]);
476
- const handleWidth = useCallback(width => {
477
- if (width < 300) return 150;else if (width < 600) return 200;
478
- return 300;
479
- }, []);
480
- return /* @__PURE__ */jsx(Dialog, {
481
- id: "shopify-asset-source",
482
- header: /* @__PURE__ */jsx(DialogHeader, {
483
- title: "Shopify Assets",
484
- shopifyDomain
485
- }),
486
- onClose,
487
- open: isOpen,
488
- width: 4,
489
- children: /* @__PURE__ */jsx(Stack, {
490
- space: 3,
491
- padding: 4,
492
- children: error ? /* @__PURE__ */jsx(Card, {
493
- overflow: "hidden",
494
- padding: 4,
495
- radius: 2,
496
- shadow: 1,
497
- tone: "critical",
498
- children: /* @__PURE__ */jsxs(Flex, {
499
- align: "center",
500
- gap: 3,
501
- children: [/* @__PURE__ */jsx(Text, {
502
- size: 2,
503
- children: /* @__PURE__ */jsx(ErrorOutlineIcon, {})
504
- }), /* @__PURE__ */jsx(Inline, {
505
- space: 2,
506
- children: /* @__PURE__ */jsx(Text, {
507
- size: 1,
508
- children: error
509
- })
510
- })]
511
- })
512
- }) : /* @__PURE__ */jsxs(Fragment, {
513
- children: [/* @__PURE__ */jsx(Card, {
514
- children: /* @__PURE__ */jsxs(Search, {
515
- space: 3,
516
- children: [/* @__PURE__ */jsx(Text, {
517
- size: 1,
518
- weight: "semibold",
519
- children: "Search Shopify for assets"
520
- }), /* @__PURE__ */jsx(TextInput, {
521
- label: "Search Images",
522
- placeholder: "filename.jpg",
523
- value: query,
524
- onChange: handleSearchTermChanged
525
- })]
526
- })
527
- }), !isLoading && searchResults.length === 0 && /* @__PURE__ */jsx(Text, {
528
- size: 1,
529
- muted: true,
530
- children: "No results found"
531
- }), /* @__PURE__ */jsx(InfiniteScroll, {
532
- dataLength: searchResults.length,
533
- next: handleScollerLoadMore,
534
- hasMore: pageInfo ? pageInfo?.hasNextPage : true,
535
- scrollThreshold: 0.99,
536
- height: "60vh",
537
- loader: /* @__PURE__ */jsx(Flex, {
538
- align: "center",
539
- justify: "center",
540
- padding: 3,
541
- children: /* @__PURE__ */jsx(Spinner, {
542
- muted: true
543
- })
544
- }),
545
- endMessage: /* @__PURE__ */jsx(Flex, {
546
- align: "center",
547
- justify: "center",
548
- padding: 3,
549
- children: /* @__PURE__ */jsx(Text, {
550
- size: 1,
551
- muted: true,
552
- children: "No more results"
553
- })
554
- }),
555
- children: searchResults && /* @__PURE__ */jsx(PhotoAlbum, {
556
- layout: "rows",
557
- spacing: PHOTO_SPACING,
558
- padding: PHOTO_PADDING,
559
- targetRowHeight: handleWidth,
560
- photos: searchResults.map(file => ({
561
- src: file?.preview?.url,
562
- width: file?.preview?.width || 2048,
563
- height: file?.preview?.height || 2048,
564
- key: file.id,
565
- data: file
566
- })),
567
- renderPhoto: renderFile,
568
- componentsProps: {
569
- containerProps: {
570
- style: {
571
- marginBottom: `${PHOTO_SPACING}px`
572
- }
573
- }
574
- }
575
- })
576
- })]
577
- })
578
- })
579
- });
580
- }
581
- const ShopifyIcon = () => {
582
- return /* @__PURE__ */jsxs("svg", {
583
- width: "18",
584
- height: "20",
585
- viewBox: "0 0 18 20",
586
- fill: "none",
587
- xmlns: "http://www.w3.org/2000/svg",
588
- children: [/* @__PURE__ */jsx("path", {
589
- d: "M15.3269 3.85113C15.3132 3.75015 15.2258 3.69411 15.1531 3.688C15.081 3.6819 13.6693 3.66026 13.6693 3.66026C13.6693 3.66026 12.4887 2.50392 12.3722 2.38628C12.2555 2.26865 12.0277 2.30417 11.9392 2.3308C11.9381 2.33135 11.7175 2.40016 11.3461 2.51612C11.2839 2.31304 11.1927 2.06335 11.0622 1.81255C10.6419 1.00356 10.0263 0.575752 9.2825 0.574642C9.28142 0.574642 9.28092 0.574642 9.27975 0.574642C9.22808 0.574642 9.17692 0.579636 9.12517 0.584074C9.10317 0.557441 9.08117 0.531362 9.05808 0.505838C8.73408 0.156272 8.31869 -0.0140727 7.82082 0.000908712C6.86027 0.0286521 5.90357 0.72834 5.12787 1.97124C4.58212 2.84572 4.16677 3.94435 4.04904 4.79497C2.94601 5.13953 2.17471 5.38035 2.15766 5.3859C1.60091 5.56235 1.58331 5.57955 1.51069 6.10889C1.45677 6.50895 0 17.8704 0 17.8704L12.2082 20L17.4994 18.6733C17.4994 18.6733 15.3407 3.95212 15.3269 3.85113ZM10.7349 2.707C10.4537 2.79467 10.1342 2.89454 9.78758 3.00274C9.78042 2.51224 9.72267 1.82975 9.496 1.23992C10.2249 1.3792 10.5836 2.21095 10.7349 2.707ZM9.14883 3.20249C8.509 3.40225 7.81091 3.62031 7.11058 3.83892C7.30753 3.0782 7.68107 2.32081 8.13989 1.8242C8.31044 1.63943 8.54917 1.43358 8.832 1.31594C9.09767 1.87525 9.15542 2.66705 9.14883 3.20249ZM7.84007 0.645665C8.06562 0.640671 8.25542 0.690609 8.41775 0.798253C8.15805 0.9342 7.90718 1.12951 7.67172 1.38419C7.06162 2.04448 6.594 3.06932 6.4075 4.0581C5.826 4.23954 5.25715 4.41766 4.73342 4.58078C5.06405 3.02438 6.35743 0.688944 7.84007 0.645665Z",
590
- fill: "#95BF47"
591
- }), /* @__PURE__ */jsx("path", {
592
- d: "M9.276 6.43238L8.66142 8.75117C8.66142 8.75117 7.97598 8.43658 7.16342 8.48817C5.97181 8.56417 5.95916 9.32217 5.97126 9.51242C6.03618 10.5495 8.74125 10.7759 8.89308 13.2051C9.01242 15.1161 7.88796 16.4233 6.26779 16.5265C4.32303 16.6502 3.25246 15.4933 3.25246 15.4933L3.66452 13.7256C3.66452 13.7256 4.74224 14.5457 5.60487 14.4907C6.16821 14.4547 6.36957 13.9924 6.34921 13.6657C6.26448 12.3128 4.06172 12.3927 3.92253 10.17C3.80536 8.29951 5.02337 6.40408 7.71081 6.23318C8.74617 6.16604 9.276 6.43238 9.276 6.43238Z",
593
- fill: "white"
594
- }), /* @__PURE__ */jsx("path", {
595
- d: "M15.1536 3.68853C15.0815 3.68243 13.6698 3.66078 13.6698 3.66078C13.6698 3.66078 12.4893 2.50444 12.3726 2.38681C12.3292 2.34298 12.2703 2.32023 12.2087 2.31079L12.2093 19.9994L17.4999 18.6733C17.4999 18.6733 15.3412 3.95264 15.3274 3.85166C15.3137 3.75068 15.2257 3.69463 15.1536 3.68853Z",
596
- fill: "#5E8E3E"
597
- })]
598
- });
599
- };
600
- function ShopifyAssetInput(props) {
601
- const {
602
- onChange,
603
- readOnly,
604
- value,
605
- schemaType
606
- } = props;
607
- const {
608
- options
609
- } = schemaType;
610
- const {
611
- shopifyDomain
612
- } = options;
613
- const [dialogOpen, setDialogOpen] = useState(false);
614
- const removeValue = useCallback(() => {
615
- onChange(PatchEvent.from([unset()]));
616
- }, [onChange]);
617
- const onOpen = useCallback(() => {
618
- setDialogOpen(true);
619
- }, [setDialogOpen]);
620
- const onClose = useCallback(() => {
621
- setDialogOpen(false);
622
- }, [setDialogOpen]);
623
- if (!shopifyDomain) {
624
- return /* @__PURE__ */jsx(Card, {
625
- overflow: "hidden",
626
- padding: 4,
627
- radius: 2,
628
- shadow: 1,
629
- tone: "critical",
630
- children: /* @__PURE__ */jsxs(Flex, {
631
- align: "center",
632
- gap: 3,
633
- children: [/* @__PURE__ */jsx(Text, {
634
- size: 2,
635
- children: /* @__PURE__ */jsx(ErrorOutlineIcon, {})
636
- }), /* @__PURE__ */jsx(Inline, {
637
- space: 2,
638
- children: /* @__PURE__ */jsx(Text, {
639
- size: 1,
640
- children: "You need to configure your *.myshopify.com domain in the plugin / field options to enable Shopify Assets."
641
- })
642
- })]
643
- })
644
- });
645
- }
646
- return /* @__PURE__ */jsxs(Fragment, {
647
- children: [dialogOpen && /* @__PURE__ */jsx(ShopifyAssetPicker, {
648
- ...props,
649
- shopifyDomain,
650
- isOpen: dialogOpen,
651
- onClose,
652
- value
653
- }), /* @__PURE__ */jsxs(Stack, {
654
- children: [/* @__PURE__ */jsx(AssetPreview, {
655
- value
656
- }), /* @__PURE__ */jsxs(Grid, {
657
- gap: 1,
658
- style: {
659
- gridTemplateColumns: "repeat(auto-fit, minmax(100px, 1fr))"
660
- },
661
- children: [/* @__PURE__ */jsx(Button, {
662
- disabled: readOnly,
663
- mode: "ghost",
664
- icon: ShopifyIcon,
665
- title: "Select an asset",
666
- onClick: onOpen,
667
- text: "Select\u2026"
668
- }), /* @__PURE__ */jsx(Button, {
669
- disabled: readOnly || !value,
670
- tone: "critical",
671
- mode: "ghost",
672
- title: "Remove asset",
673
- text: "Remove",
674
- onClick: removeValue
675
- })]
676
- })]
677
- })]
678
- });
679
- }
680
- const CloudinaryDiffPreview = _ref10 => {
681
- let {
682
- value
683
- } = _ref10;
684
- if (!value) {
685
- return null;
686
- }
687
- if (value?.preview?.url) {
688
- return /* @__PURE__ */jsx(Flex, {
689
- justify: "center",
690
- align: "center",
691
- height: "fill",
692
- width: "fill",
693
- children: /* @__PURE__ */jsxs(Stack, {
694
- space: 2,
695
- children: [/* @__PURE__ */jsx("img", {
696
- alt: "preview",
697
- src: value?.preview?.url,
698
- style: {
699
- objectFit: "contain",
700
- margin: "auto",
701
- maxWidth: "100%",
702
- maxHeight: "100%"
703
- }
704
- }), /* @__PURE__ */jsx(Text, {
705
- size: 1,
706
- children: value.type.charAt(0).toUpperCase() + value.type.slice(1)
707
- })]
708
- })
709
- });
710
- }
711
- return /* @__PURE__ */jsx(Flex, {
712
- justify: "center",
713
- align: "center",
714
- height: "fill",
715
- width: "fill",
716
- children: /* @__PURE__ */jsx("div", {
717
- children: "(no image)"
718
- })
719
- });
720
- };
721
- const AssetDiff = _ref11 => {
722
- let {
723
- diff,
724
- schemaType
725
- } = _ref11;
726
- return /* @__PURE__ */jsx(DiffFromTo, {
727
- diff,
728
- schemaType,
729
- previewComponent: CloudinaryDiffPreview,
730
- layout: "grid"
731
- });
732
- };
733
- const shopifyAssetSchema = config => {
734
- const {
735
- shopifyDomain
736
- } = config;
737
- return defineType({
738
- type: "object",
739
- name: "shopify.asset",
740
- title: "Shopify Asset",
741
- options: {
742
- shopifyDomain
743
- },
744
- fields: [defineField({
745
- type: "string",
746
- name: "filename",
747
- title: "Filename"
748
- }), defineField({
749
- type: "string",
750
- name: "id",
751
- title: "ID"
752
- }), defineField({
753
- type: "shopify.assetMetadata",
754
- name: "meta",
755
- title: "Metadata"
756
- }), defineField({
757
- type: "shopify.assetPreview",
758
- name: "preview",
759
- title: "Preview"
760
- }), defineField({
761
- type: "string",
762
- name: "type",
763
- title: "Type"
764
- }), defineField({
765
- type: "url",
766
- name: "url",
767
- title: "URL"
768
- })],
769
- ...{
770
- components: {
771
- input: ShopifyAssetInput,
772
- diff: AssetDiff,
773
- preview: AssetPreview
774
- }
775
- },
776
- preview: {
777
- select: {
778
- meta: "meta",
779
- preview: "preview",
780
- url: "url",
781
- filename: "filename",
782
- type: "type"
783
- },
784
- prepare(_ref12) {
785
- let {
786
- url,
787
- meta,
788
- preview,
789
- filename,
790
- type
791
- } = _ref12;
792
- return {
793
- title: filename,
794
- subtitle: type,
795
- value: {
796
- url,
797
- meta,
798
- preview,
799
- filename
800
- }
801
- };
802
- }
803
- }
804
- });
805
- };
806
- const shopifyAssetPreviewSchema = defineType({
807
- type: "object",
808
- name: "shopify.assetPreview",
809
- title: "Asset preview",
810
- fields: [defineField({
811
- type: "number",
812
- name: "height",
813
- title: "Height"
814
- }), defineField({
815
- type: "number",
816
- name: "width",
817
- title: "Width"
818
- }), defineField({
819
- type: "url",
820
- name: "url",
821
- title: "URL"
822
- })]
823
- });
824
- const shopifyAssetMetadataSchema = defineType({
825
- type: "object",
826
- name: "shopify.assetMetadata",
827
- title: "Asset metadata",
828
- fields: [defineField({
829
- type: "string",
830
- name: "alt",
831
- title: "Alternative text"
832
- }), defineField({
833
- type: "number",
834
- name: "duration",
835
- title: "Duration"
836
- }), defineField({
837
- type: "number",
838
- name: "fileSize",
839
- title: "File size"
840
- }), defineField({
841
- type: "number",
842
- name: "height",
843
- title: "Height"
844
- }), defineField({
845
- type: "number",
846
- name: "width",
847
- title: "Width"
848
- })]
849
- });
850
- const shopifyAssets = definePlugin(config => {
851
- return {
852
- name: "shopify-asset-schema",
853
- schema: {
854
- types: [shopifyAssetPreviewSchema, shopifyAssetMetadataSchema, shopifyAssetSchema(config)]
855
- }
856
- };
857
- });
858
- export { shopifyAssets };
859
- //# sourceMappingURL=index.esm.js.map