sanity-plugin-shopify-assets 1.2.3 → 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.js CHANGED
@@ -1,248 +1,248 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true
5
- });
6
- var sanity = require('sanity');
7
- var jsxRuntime = require('react/jsx-runtime');
8
- var icons = require('@sanity/icons');
9
- var ui = require('@sanity/ui');
10
- var React = require('react');
11
- var prettyBytes = require('pretty-bytes');
12
- var prettyMilliseconds = require('pretty-ms');
13
- var styledComponents = require('styled-components');
14
- var videojs = require('video.js');
15
- var rxjs = require('rxjs');
16
- var PhotoAlbum = require('react-photo-album');
17
- var InfiniteScroll = require('react-infinite-scroll-component');
18
- var operators = require('rxjs/operators');
19
- var axios = require('axios');
20
- function _interopDefaultCompat(e) {
21
- return e && typeof e === 'object' && 'default' in e ? e : {
22
- default: e
23
- };
24
- }
25
- var React__default = /*#__PURE__*/_interopDefaultCompat(React);
26
- var prettyBytes__default = /*#__PURE__*/_interopDefaultCompat(prettyBytes);
27
- var prettyMilliseconds__default = /*#__PURE__*/_interopDefaultCompat(prettyMilliseconds);
28
- var videojs__default = /*#__PURE__*/_interopDefaultCompat(videojs);
29
- var PhotoAlbum__default = /*#__PURE__*/_interopDefaultCompat(PhotoAlbum);
30
- var InfiniteScroll__default = /*#__PURE__*/_interopDefaultCompat(InfiniteScroll);
31
- var axios__default = /*#__PURE__*/_interopDefaultCompat(axios);
32
- const Root = styledComponents.styled.div`
33
- overflow: hidden;
34
- background-origin: content-box;
35
- background-repeat: no-repeat;
36
- background-clip: border-box;
37
- background-size: cover;
38
- background-color: ${_ref => {
39
- let {
40
- theme
41
- } = _ref;
42
- return theme.sanity.color.card.enabled.bg2;
43
- }};
44
- position: relative;
45
- outline: none !important;
46
- border: ${_ref2 => {
47
- let {
48
- theme
49
- } = _ref2;
50
- return `1px solid ${theme.sanity.color.card.enabled.border}`;
51
- }};
52
- box-sizing: content-box;
53
- user-drag: none;
54
-
55
- &:hover {
56
- opacity: 0.85;
57
- }
58
-
59
- &:focus,
60
- &:active {
61
- border: 1px solid var(--input-border-color-focus);
62
- box-shadow: inset 0 0 0 3px var(--input-border-color-focus);
1
+ import { defineType, defineField, DiffFromTo, useProjectId, useDataset, useClient, PatchEvent, set, unset, definePlugin } from "sanity";
2
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
+ import { c } from "react/compiler-runtime";
4
+ import { Flex, Stack, Text, Card, Box, Button, Inline, TextInput, Spinner, Dialog, Grid } from "@sanity/ui";
5
+ import { getTheme_v2 } from "@sanity/ui/theme";
6
+ import prettyBytes from "pretty-bytes";
7
+ import prettyMilliseconds from "pretty-ms";
8
+ import { styled } from "styled-components";
9
+ import { useRef, useEffect, useState } from "react";
10
+ import videojs from "video.js";
11
+ import { LaunchIcon, ErrorOutlineIcon } from "@sanity/icons";
12
+ import InfiniteScroll from "react-infinite-scroll-component";
13
+ import { PhotoAlbum } from "react-photo-album";
14
+ import { concat, defer, BehaviorSubject } from "rxjs";
15
+ import axios from "axios";
16
+ import { withLatestFrom, debounceTime, distinctUntilChanged, switchMap, map } from "rxjs/operators";
17
+ const shopifyAssetMetadataSchema = defineType({
18
+ type: "object",
19
+ name: "shopify.assetMetadata",
20
+ title: "Asset metadata",
21
+ fields: [defineField({
22
+ type: "string",
23
+ name: "alt",
24
+ title: "Alternative text"
25
+ }), defineField({
26
+ type: "number",
27
+ name: "duration",
28
+ title: "Duration"
29
+ }), defineField({
30
+ type: "number",
31
+ name: "fileSize",
32
+ title: "File size"
33
+ }), defineField({
34
+ type: "number",
35
+ name: "height",
36
+ title: "Height"
37
+ }), defineField({
38
+ type: "number",
39
+ name: "width",
40
+ title: "Width"
41
+ })]
42
+ }), shopifyAssetPreviewSchema = defineType({
43
+ type: "object",
44
+ name: "shopify.assetPreview",
45
+ title: "Asset preview",
46
+ fields: [defineField({
47
+ type: "number",
48
+ name: "height",
49
+ title: "Height"
50
+ }), defineField({
51
+ type: "number",
52
+ name: "width",
53
+ title: "Width"
54
+ }), defineField({
55
+ type: "url",
56
+ name: "url",
57
+ title: "URL"
58
+ })]
59
+ }), ShopifyAssetDiffPreview = (t0) => {
60
+ const $ = c(11), {
61
+ value
62
+ } = t0;
63
+ if (!value)
64
+ return null;
65
+ if (value?.preview?.url) {
66
+ const t12 = value?.preview?.url;
67
+ let t2;
68
+ $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = {
69
+ objectFit: "contain",
70
+ margin: "auto",
71
+ maxWidth: "100%",
72
+ maxHeight: "100%"
73
+ }, $[0] = t2) : t2 = $[0];
74
+ let t3;
75
+ $[1] !== t12 ? (t3 = /* @__PURE__ */ jsx("img", { alt: "preview", src: t12, style: t2 }), $[1] = t12, $[2] = t3) : t3 = $[2];
76
+ let t4;
77
+ $[3] !== value.type ? (t4 = value.type.charAt(0).toUpperCase(), $[3] = value.type, $[4] = t4) : t4 = $[4];
78
+ const t5 = t4 + value.type.slice(1);
79
+ let t6;
80
+ $[5] !== t5 ? (t6 = /* @__PURE__ */ jsx(Text, { size: 1, children: t5 }), $[5] = t5, $[6] = t6) : t6 = $[6];
81
+ let t7;
82
+ return $[7] !== t3 || $[8] !== t6 ? (t7 = /* @__PURE__ */ jsx(Flex, { justify: "center", align: "center", height: "fill", width: "fill", children: /* @__PURE__ */ jsxs(Stack, { gap: 2, children: [
83
+ t3,
84
+ t6
85
+ ] }) }), $[7] = t3, $[8] = t6, $[9] = t7) : t7 = $[9], t7;
63
86
  }
64
- `;
65
- const InfoLine = styledComponents.styled(ui.Card)`
66
- ${_ref3 => {
67
- let {
68
- theme
69
- } = _ref3;
87
+ let t1;
88
+ return $[10] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = /* @__PURE__ */ jsx(Flex, { justify: "center", align: "center", height: "fill", width: "fill", children: /* @__PURE__ */ jsx("div", { children: "(no image)" }) }), $[10] = t1) : t1 = $[10], t1;
89
+ }, AssetDiff = (t0) => {
90
+ const $ = c(3), {
91
+ diff,
92
+ schemaType
93
+ } = t0;
94
+ let t1;
95
+ return $[0] !== diff || $[1] !== schemaType ? (t1 = /* @__PURE__ */ jsx(DiffFromTo, { diff, schemaType, previewComponent: ShopifyAssetDiffPreview, layout: "grid" }), $[0] = diff, $[1] = schemaType, $[2] = t1) : t1 = $[2], t1;
96
+ }, Root = styled.div.withConfig({
97
+ displayName: "Root",
98
+ componentId: "sc-1wrh02w-0"
99
+ })`${({
100
+ theme
101
+ }) => {
102
+ const v2 = getTheme_v2({
103
+ sanity: theme.sanity
104
+ });
70
105
  return `
71
- --infoline-fg: ${theme.sanity.color.card.enabled.fg};
72
- --infoline-bg: ${theme.sanity.color.card.enabled.bg};
73
- `;
74
- }};
75
- user-drag: none;
76
- position: absolute;
77
- background-color: var(--infoline-bg);
78
- top: 0;
79
- left: 0;
80
- max-width: 65%;
81
- overflow-wrap: break-word;
82
-
83
- [data-ui='Text'] {
84
- color: var(--infoline-fg);
85
- }
86
- `;
87
- const DurationLine = styledComponents.styled(ui.Card)`
88
- ${_ref4 => {
89
- let {
90
- theme
91
- } = _ref4;
106
+ background-color: ${v2.color.muted.bg};
107
+ border: 1px solid ${v2.color.border};
108
+ `;
109
+ }};overflow:hidden;background-origin:content-box;background-repeat:no-repeat;background-clip:border-box;background-size:cover;position:relative;outline:none !important;box-sizing:content-box;user-drag:none;&:hover{opacity:0.85;}&:focus,&:active{border:1px solid var(--input-border-color-focus);box-shadow:inset 0 0 0 3px var(--input-border-color-focus);}`, InfoLine = styled(Card).withConfig({
110
+ displayName: "InfoLine",
111
+ componentId: "sc-1wrh02w-1"
112
+ })`${({
113
+ theme
114
+ }) => {
115
+ const v2 = getTheme_v2({
116
+ sanity: theme.sanity
117
+ });
92
118
  return `
93
- --durationline-fg: ${theme.sanity.color.card.enabled.bg};
94
- --durationline-bg: ${theme.sanity.color.card.enabled.fg};
95
- `;
96
- }};
97
- user-drag: none;
98
- position: absolute;
99
- background-color: var(--durationline-bg);
100
- top: 0;
101
- right: 0;
102
-
103
- [data-ui='Text'] {
104
- color: var(--durationline-fg);
105
- }
106
- `;
107
- const VideoPlayer = _ref5 => {
108
- let {
119
+ --infoline-fg: ${v2.color.fg};
120
+ --infoline-bg: ${v2.color.bg};
121
+ `;
122
+ }};user-drag:none;position:absolute;background-color:var(--infoline-bg);top:0;left:0;max-width:65%;overflow-wrap:break-word;[data-ui='Text']{color:var(--infoline-fg);}`, DurationLine = styled(Card).withConfig({
123
+ displayName: "DurationLine",
124
+ componentId: "sc-1wrh02w-2"
125
+ })`${({
126
+ theme
127
+ }) => {
128
+ const v2 = getTheme_v2({
129
+ sanity: theme.sanity
130
+ });
131
+ return `
132
+ --durationline-fg: ${v2.color.bg};
133
+ --durationline-bg: ${v2.color.fg};
134
+ `;
135
+ }};user-drag:none;position:absolute;background-color:var(--durationline-bg);top:0;right:0;[data-ui='Text']{color:var(--durationline-fg);}`, VideoPlayer = (t0) => {
136
+ const $ = c(11), {
109
137
  src,
110
138
  kind
111
- } = _ref5;
112
- const videoNode = React__default.default.useRef(null);
113
- const player = React__default.default.useRef();
114
- React.useEffect(() => {
115
- player.current = videojs__default.default(videoNode.current ?? "", {
139
+ } = t0, videoNode = useRef(null), player = useRef(void 0);
140
+ let t1, t2;
141
+ $[0] !== src ? (t1 = () => {
142
+ player.current = videojs(videoNode.current ?? "", {
116
143
  sources: [{
117
144
  src
118
145
  }],
119
- controls: true
120
- });
121
- player.current.src({
146
+ controls: !0
147
+ }), player.current.src({
122
148
  src
123
149
  });
124
- }, [src]);
125
- const stopPropagation = React.useCallback(event => {
126
- event.stopPropagation();
127
- }, []);
128
- const className = {
150
+ }, t2 = [src], $[0] = src, $[1] = t1, $[2] = t2) : (t1 = $[1], t2 = $[2]), useEffect(t1, t2);
151
+ const stopPropagation = _temp$1;
152
+ let t3;
153
+ $[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = {
129
154
  player: "video-js vjs-16-9 vjs-big-play-centered",
130
155
  diff: "video-js vjs-layout-tiny vjs-fluid"
131
- };
132
- const style = {
156
+ }, $[3] = t3) : t3 = $[3];
157
+ const className = t3;
158
+ let t4;
159
+ $[4] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t4 = {
133
160
  position: "relative"
134
- };
135
- return /* @__PURE__ */jsxRuntime.jsxs("div", {
136
- children: [/* @__PURE__ */jsxRuntime.jsx("link", {
137
- href: "https://vjs.zencdn.net/7.8.4/video-js.css",
138
- rel: "stylesheet"
139
- }), /* @__PURE__ */jsxRuntime.jsx("div", {
140
- "data-vjs-player": true,
141
- children: /* @__PURE__ */jsxRuntime.jsx("video", {
142
- onClick: stopPropagation,
143
- style: kind === "diff" ? style : {},
144
- className: className[kind],
145
- ref: videoNode
146
- })
147
- })]
148
- });
161
+ }, $[4] = t4) : t4 = $[4];
162
+ const style = t4;
163
+ let t5;
164
+ $[5] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t5 = /* @__PURE__ */ jsx("link", { href: "https://vjs.zencdn.net/7.8.4/video-js.css", rel: "stylesheet" }), $[5] = t5) : t5 = $[5];
165
+ let t6;
166
+ $[6] !== kind ? (t6 = kind === "diff" ? style : {}, $[6] = kind, $[7] = t6) : t6 = $[7];
167
+ const t7 = className[kind];
168
+ let t8;
169
+ return $[8] !== t6 || $[9] !== t7 ? (t8 = /* @__PURE__ */ jsxs("div", { children: [
170
+ t5,
171
+ /* @__PURE__ */ jsx("div", { "data-vjs-player": !0, children: /* @__PURE__ */ jsx("video", { "aria-label": "Video preview", onClick: stopPropagation, style: t6, className: t7, ref: videoNode }) })
172
+ ] }), $[8] = t6, $[9] = t7, $[10] = t8) : t8 = $[10], t8;
149
173
  };
150
- const StyledBox = styledComponents.styled(ui.Box)`
151
- background-color: ${_ref6 => {
152
- let {
153
- theme
154
- } = _ref6;
155
- return theme.sanity.color?.card?.enabled?.bg2;
156
- }};
157
- border: ${_ref7 => {
158
- let {
159
- theme
160
- } = _ref7;
161
- return `1px solid ${theme.sanity?.color?.card?.enabled?.border}`;
162
- }};
163
- display: flex;
164
- justify-content: center;
165
- margin-bottom: ${_ref8 => {
166
- let {
167
- theme
168
- } = _ref8;
169
- return theme.sanity.space[4];
170
- }};
171
- position: relative;
172
- `;
173
- const RenderAsset = _ref9 => {
174
- let {
174
+ function _temp$1(event) {
175
+ event.stopPropagation();
176
+ }
177
+ const StyledBox = styled(Box).withConfig({
178
+ displayName: "StyledBox",
179
+ componentId: "sc-s00el7-0"
180
+ })`${({
181
+ theme
182
+ }) => {
183
+ const v2 = getTheme_v2({
184
+ sanity: theme.sanity
185
+ });
186
+ return `
187
+ background-color: ${v2.color.muted.bg};
188
+ border: 1px solid ${v2.color.border};
189
+ `;
190
+ }};display:flex;justify-content:center;position:relative;`, RenderAsset = (t0) => {
191
+ const $ = c(5), {
175
192
  value,
176
193
  url
177
- } = _ref9;
178
- switch (value.type) {
179
- case "video":
180
- return /* @__PURE__ */jsxRuntime.jsx(VideoPlayer, {
181
- src: url,
182
- kind: "player"
183
- });
184
- default:
185
- return /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
186
- justify: "center",
187
- children: /* @__PURE__ */jsxRuntime.jsx("img", {
188
- alt: "preview",
189
- src: value?.preview?.url,
190
- style: {
191
- maxWidth: "100%",
192
- height: "auto",
193
- display: "block",
194
- maxHeight: "30vh"
195
- }
196
- })
197
- });
194
+ } = t0;
195
+ if (value.type === "video") {
196
+ let t1;
197
+ return $[0] !== url ? (t1 = /* @__PURE__ */ jsx(VideoPlayer, { src: url, kind: "player" }), $[0] = url, $[1] = t1) : t1 = $[1], t1;
198
+ } else {
199
+ const t1 = value?.preview?.url;
200
+ let t2;
201
+ $[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = {
202
+ maxWidth: "100%",
203
+ height: "auto",
204
+ display: "block",
205
+ maxHeight: "30vh"
206
+ }, $[2] = t2) : t2 = $[2];
207
+ let t3;
208
+ return $[3] !== t1 ? (t3 = /* @__PURE__ */ jsx(Flex, { justify: "center", children: /* @__PURE__ */ jsx("img", { alt: "preview", src: t1, style: t2 }) }), $[3] = t1, $[4] = t3) : t3 = $[4], t3;
198
209
  }
199
- };
200
- const AssetPreview = _ref0 => {
201
- let {
210
+ }, AssetPreview = (t0) => {
211
+ const $ = c(16), {
202
212
  value
203
- } = _ref0;
204
- const url = value && value.url;
205
- if (!value || !url) {
213
+ } = t0, url = value && value.url;
214
+ if (!value || !url)
206
215
  return null;
207
- }
208
216
  const {
209
217
  filename,
210
218
  meta
211
- } = value;
212
- const {
219
+ } = value, {
213
220
  fileSize,
214
221
  duration
215
222
  } = meta;
216
- return /* @__PURE__ */jsxRuntime.jsxs(StyledBox, {
217
- marginBottom: 2,
218
- children: [/* @__PURE__ */jsxRuntime.jsx(RenderAsset, {
219
- value,
220
- url
221
- }), /* @__PURE__ */jsxRuntime.jsx(InfoLine, {
222
- padding: 2,
223
- radius: 2,
224
- margin: 2,
225
- children: /* @__PURE__ */jsxRuntime.jsxs(ui.Text, {
226
- size: 1,
227
- title: `Select ${filename}`,
228
- children: [filename, " ", fileSize && `(${prettyBytes__default.default(fileSize)})`]
229
- })
230
- }), duration && /* @__PURE__ */jsxRuntime.jsx(DurationLine, {
231
- padding: 2,
232
- radius: 2,
233
- margin: 2,
234
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
235
- size: 1,
236
- title: `Video duration: ${filename}`,
237
- children: prettyMilliseconds__default.default(duration, {
238
- colonNotation: true,
239
- secondsDecimalDigits: 0
240
- })
241
- })
242
- })]
243
- });
244
- };
245
- const fetchSearch = props => {
223
+ let t1;
224
+ $[0] !== url || $[1] !== value ? (t1 = /* @__PURE__ */ jsx(RenderAsset, { value, url }), $[0] = url, $[1] = value, $[2] = t1) : t1 = $[2];
225
+ const t2 = `Select ${filename}`;
226
+ let t3;
227
+ $[3] !== fileSize ? (t3 = fileSize && `(${prettyBytes(fileSize)})`, $[3] = fileSize, $[4] = t3) : t3 = $[4];
228
+ let t4;
229
+ $[5] !== filename || $[6] !== t2 || $[7] !== t3 ? (t4 = /* @__PURE__ */ jsx(InfoLine, { padding: 2, radius: 2, margin: 2, children: /* @__PURE__ */ jsxs(Text, { size: 1, title: t2, children: [
230
+ filename,
231
+ " ",
232
+ t3
233
+ ] }) }), $[5] = filename, $[6] = t2, $[7] = t3, $[8] = t4) : t4 = $[8];
234
+ let t5;
235
+ $[9] !== duration || $[10] !== filename ? (t5 = duration && /* @__PURE__ */ jsx(DurationLine, { padding: 2, radius: 2, margin: 2, children: /* @__PURE__ */ jsx(Text, { size: 1, title: `Video duration: ${filename}`, children: prettyMilliseconds(duration, {
236
+ colonNotation: !0,
237
+ secondsDecimalDigits: 0
238
+ }) }) }), $[9] = duration, $[10] = filename, $[11] = t5) : t5 = $[11];
239
+ let t6;
240
+ return $[12] !== t1 || $[13] !== t4 || $[14] !== t5 ? (t6 = /* @__PURE__ */ jsxs(StyledBox, { marginBottom: 2, children: [
241
+ t1,
242
+ t4,
243
+ t5
244
+ ] }), $[12] = t1, $[13] = t4, $[14] = t5, $[15] = t6) : t6 = $[15], t6;
245
+ }, fetchSearch = (props) => {
246
246
  const {
247
247
  projectId,
248
248
  dataset,
@@ -252,17 +252,14 @@ const fetchSearch = props => {
252
252
  resultsPerPage,
253
253
  token
254
254
  } = props;
255
- return rxjs.defer(() => {
256
- return axios__default.default.get(`https://${projectId}.api.sanity.io/v1/shopify/assets/${dataset}?shop=${shop}&query=${encodeURIComponent(query)}${cursor && `&cursor=${cursor}`}&limit=${resultsPerPage}`, {
257
- withCredentials: true,
258
- method: "GET",
259
- headers: token ? {
260
- Authorization: `Bearer ${token}`
261
- } : {}
262
- });
263
- }).pipe(operators.map(result => result.data));
264
- };
265
- const fetchList = props => {
255
+ return defer(() => axios.get(`https://${projectId}.api.sanity.io/v1/shopify/assets/${dataset}?shop=${shop}&query=${encodeURIComponent(query)}${cursor && `&cursor=${cursor}`}&limit=${resultsPerPage}`, {
256
+ withCredentials: !0,
257
+ method: "GET",
258
+ headers: token ? {
259
+ Authorization: `Bearer ${token}`
260
+ } : {}
261
+ })).pipe(map((result) => result.data));
262
+ }, fetchList = (props) => {
266
263
  const {
267
264
  projectId,
268
265
  dataset,
@@ -271,15 +268,14 @@ const fetchList = props => {
271
268
  resultsPerPage,
272
269
  token
273
270
  } = props;
274
- return rxjs.defer(() => axios__default.default.get(`https://${projectId}.api.sanity.io/v1/shopify/assets/${dataset}?shop=${shop}${cursor && `&cursor=${cursor}`}&limit=${resultsPerPage}`, {
275
- withCredentials: true,
271
+ return defer(() => axios.get(`https://${projectId}.api.sanity.io/v1/shopify/assets/${dataset}?shop=${shop}${cursor && `&cursor=${cursor}`}&limit=${resultsPerPage}`, {
272
+ withCredentials: !0,
276
273
  method: "GET",
277
274
  headers: token ? {
278
275
  Authorization: `Bearer ${token}`
279
276
  } : {}
280
- })).pipe(operators.map(result => result.data));
281
- };
282
- const search = props => {
277
+ })).pipe(map((result) => result.data));
278
+ }, search = (props) => {
283
279
  const {
284
280
  projectId,
285
281
  dataset,
@@ -289,155 +285,129 @@ const search = props => {
289
285
  resultsPerPage,
290
286
  token
291
287
  } = props;
292
- return rxjs.concat(query.pipe(operators.withLatestFrom(cursor), operators.debounceTime(500), operators.distinctUntilChanged(), operators.switchMap(_ref1 => {
293
- let [q, c] = _ref1;
294
- if (q) {
295
- return fetchSearch({
296
- projectId,
297
- dataset,
298
- shop,
299
- query: q,
300
- cursor: c,
301
- resultsPerPage,
302
- token
303
- }).pipe(operators.distinctUntilChanged());
304
- }
305
- return fetchList({
306
- projectId,
307
- dataset,
308
- shop,
309
- cursor: c,
310
- resultsPerPage,
311
- token
312
- });
313
- })));
314
- };
315
- const DialogHeader = props => {
316
- const {
288
+ return concat(query.pipe(withLatestFrom(cursor), debounceTime(500), distinctUntilChanged(), switchMap(([q, c2]) => q ? fetchSearch({
289
+ projectId,
290
+ dataset,
291
+ shop,
292
+ query: q,
293
+ cursor: c2,
294
+ resultsPerPage,
295
+ token
296
+ }).pipe(distinctUntilChanged()) : fetchList({
297
+ projectId,
298
+ dataset,
299
+ shop,
300
+ cursor: c2,
301
+ resultsPerPage,
302
+ token
303
+ }))));
304
+ }, DialogHeader = (props) => {
305
+ const $ = c(9), {
317
306
  title,
318
307
  shopifyDomain
319
308
  } = props;
320
- const handleOpenInNewTab = React.useCallback(() => {
309
+ let t0;
310
+ $[0] !== shopifyDomain ? (t0 = () => {
321
311
  window.open(`https://${shopifyDomain}/admin/content/files`, "_blank");
322
- }, [shopifyDomain]);
323
- return /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
324
- align: "center",
325
- children: [title, /* @__PURE__ */jsxRuntime.jsx("input", {
326
- style: {
327
- opacity: 0
328
- },
329
- tabIndex: -1,
330
- type: "button"
331
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
332
- style: {
333
- position: "absolute",
334
- right: "-1.5em"
335
- },
336
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
337
- className: "button-large",
338
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
339
- fontSize: 1,
340
- icon: icons.LaunchIcon,
341
- mode: "bleed",
342
- onClick: handleOpenInNewTab,
343
- text: "Add New"
344
- })
345
- })
346
- })]
347
- });
348
- };
349
- const extractName = name => name?.split("/")?.pop()?.split("?")[0] ?? "";
312
+ }, $[0] = shopifyDomain, $[1] = t0) : t0 = $[1];
313
+ const handleOpenInNewTab = t0;
314
+ let t1;
315
+ $[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = /* @__PURE__ */ jsx("input", { "aria-hidden": "true", "aria-label": "Focus trap", style: {
316
+ opacity: 0
317
+ }, tabIndex: -1, type: "button" }), $[2] = t1) : t1 = $[2];
318
+ let t2;
319
+ $[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = {
320
+ position: "absolute",
321
+ right: "-1.5em"
322
+ }, $[3] = t2) : t2 = $[3];
323
+ let t3;
324
+ $[4] !== handleOpenInNewTab ? (t3 = /* @__PURE__ */ jsx(Box, { style: t2, children: /* @__PURE__ */ jsx(Box, { className: "button-large", children: /* @__PURE__ */ jsx(Button, { fontSize: 1, icon: LaunchIcon, mode: "bleed", onClick: handleOpenInNewTab, text: "Add New" }) }) }), $[4] = handleOpenInNewTab, $[5] = t3) : t3 = $[5];
325
+ let t4;
326
+ return $[6] !== t3 || $[7] !== title ? (t4 = /* @__PURE__ */ jsxs(Flex, { align: "center", children: [
327
+ title,
328
+ t1,
329
+ t3
330
+ ] }), $[6] = t3, $[7] = title, $[8] = t4) : t4 = $[8], t4;
331
+ }, extractName = (name) => name?.split("/")?.pop()?.split("?")[0] ?? "";
350
332
  function File(props) {
351
- const {
333
+ const $ = c(25), {
352
334
  onClick,
353
335
  data,
354
336
  width,
355
337
  height
356
- } = props;
357
- const rootElm = React.useRef(null);
358
- const {
338
+ } = props, rootElm = useRef(null), {
359
339
  preview,
360
340
  meta
361
341
  } = data;
362
- const filename = extractName(data.url);
363
- const handleClick = React.useCallback(() => {
342
+ let t0;
343
+ $[0] !== data.url ? (t0 = extractName(data.url), $[0] = data.url, $[1] = t0) : t0 = $[1];
344
+ const filename = t0;
345
+ let t1;
346
+ $[2] !== data || $[3] !== filename || $[4] !== onClick ? (t1 = () => {
364
347
  onClick({
365
348
  ...data,
366
349
  filename
367
350
  });
368
- }, [onClick, data, filename]);
369
- return /* @__PURE__ */jsxRuntime.jsxs(Root, {
370
- ref: rootElm,
371
- title: `${filename}`,
372
- tabIndex: 0,
373
- style: {
374
- width: `${width}px`,
375
- height: `${height}px`,
376
- backgroundImage: `url("${preview?.url}")`
377
- },
378
- onClick: handleClick,
379
- children: [/* @__PURE__ */jsxRuntime.jsx(InfoLine, {
380
- padding: 2,
381
- radius: 2,
382
- margin: 2,
383
- children: /* @__PURE__ */jsxRuntime.jsxs(ui.Text, {
384
- size: 1,
385
- title: `Select ${filename}`,
386
- children: [filename, " ", meta.fileSize && `(${prettyBytes__default.default(meta.fileSize)})`]
387
- })
388
- }), meta.duration && /* @__PURE__ */jsxRuntime.jsx(DurationLine, {
389
- padding: 2,
390
- radius: 2,
391
- margin: 2,
392
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
393
- size: 1,
394
- title: `Video duration: ${filename}`,
395
- children: prettyMilliseconds__default.default(meta.duration, {
396
- colonNotation: true,
397
- secondsDecimalDigits: 0
398
- })
399
- })
400
- })]
401
- });
351
+ }, $[2] = data, $[3] = filename, $[4] = onClick, $[5] = t1) : t1 = $[5];
352
+ const handleClick = t1, t2 = `${width}px`, t3 = `${height}px`, t4 = `url("${preview?.url}")`;
353
+ let t5;
354
+ $[6] !== t2 || $[7] !== t3 || $[8] !== t4 ? (t5 = {
355
+ width: t2,
356
+ height: t3,
357
+ backgroundImage: t4
358
+ }, $[6] = t2, $[7] = t3, $[8] = t4, $[9] = t5) : t5 = $[9];
359
+ const t6 = `Select ${filename}`;
360
+ let t7;
361
+ $[10] !== meta.fileSize ? (t7 = meta.fileSize && `(${prettyBytes(meta.fileSize)})`, $[10] = meta.fileSize, $[11] = t7) : t7 = $[11];
362
+ let t8;
363
+ $[12] !== filename || $[13] !== t6 || $[14] !== t7 ? (t8 = /* @__PURE__ */ jsx(InfoLine, { padding: 2, radius: 2, margin: 2, children: /* @__PURE__ */ jsxs(Text, { size: 1, title: t6, children: [
364
+ filename,
365
+ " ",
366
+ t7
367
+ ] }) }), $[12] = filename, $[13] = t6, $[14] = t7, $[15] = t8) : t8 = $[15];
368
+ let t9;
369
+ $[16] !== filename || $[17] !== meta.duration ? (t9 = meta.duration && /* @__PURE__ */ jsx(DurationLine, { padding: 2, radius: 2, margin: 2, children: /* @__PURE__ */ jsx(Text, { size: 1, title: `Video duration: ${filename}`, children: prettyMilliseconds(meta.duration, {
370
+ colonNotation: !0,
371
+ secondsDecimalDigits: 0
372
+ }) }) }), $[16] = filename, $[17] = meta.duration, $[18] = t9) : t9 = $[18];
373
+ let t10;
374
+ return $[19] !== filename || $[20] !== handleClick || $[21] !== t5 || $[22] !== t8 || $[23] !== t9 ? (t10 = /* @__PURE__ */ jsxs(Root, { ref: rootElm, title: filename, tabIndex: 0, style: t5, onClick: handleClick, children: [
375
+ t8,
376
+ t9
377
+ ] }), $[19] = filename, $[20] = handleClick, $[21] = t5, $[22] = t8, $[23] = t9, $[24] = t10) : t10 = $[24], t10;
402
378
  }
403
- const Search = styledComponents.styled(ui.Stack)`
404
- position: sticky;
405
- top: 0;
406
- z-index: 1;
407
- `;
408
- styledComponents.styled.div`
409
- overflow-y: auto;
410
- max-height: 80vh;
411
- `;
412
- const RESULTS_PER_PAGE = 42;
413
- const PHOTO_SPACING = 2;
414
- const PHOTO_PADDING = 1;
379
+ const Search = styled(Stack).withConfig({
380
+ displayName: "Search",
381
+ componentId: "sc-1qdoq6k-0"
382
+ })`position:sticky;top:0;z-index:1;`, RESULTS_PER_PAGE = 42, PHOTO_SPACING = 2, PHOTO_PADDING = 1;
415
383
  function ShopifyAssetPicker(props) {
416
- const {
384
+ const $ = c(38), {
417
385
  isOpen,
418
386
  onClose,
419
387
  shopifyDomain,
420
388
  onChange,
421
389
  schemaType,
422
390
  value
423
- } = props;
424
- const projectId = sanity.useProjectId();
425
- const dataset = sanity.useDataset();
426
- const client = sanity.useClient({
391
+ } = props, projectId = useProjectId(), dataset = useDataset();
392
+ let t0;
393
+ $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = {
427
394
  apiVersion: "2021-06-07"
428
- });
429
- const token = client.config().token;
430
- const [error, setError] = React.useState("");
431
- const [query, setQuery] = React.useState("");
432
- const [searchResults, setSearchResults] = React.useState([]);
433
- const [pageInfo, setPageInfo] = React.useState();
434
- const [isLoading, setIsLoading] = React.useState(true);
435
- const searchSubject$ = React.useMemo(() => new rxjs.BehaviorSubject(""), []);
436
- const cursorSubject$ = React.useMemo(() => new rxjs.BehaviorSubject(""), []);
437
- React.useEffect(() => {
438
- if (!shopifyDomain) setError("Please configure your Shopify domain in the plugin config");
439
- }, [shopifyDomain]);
440
- React.useEffect(() => {
395
+ }, $[0] = t0) : t0 = $[0];
396
+ const client = useClient(t0);
397
+ let t1;
398
+ $[1] !== client ? (t1 = client.config(), $[1] = client, $[2] = t1) : t1 = $[2];
399
+ const token = t1.token, [apiError, setApiError] = useState(""), [query, setQuery] = useState("");
400
+ let t2;
401
+ $[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = [], $[3] = t2) : t2 = $[3];
402
+ const [searchResults, setSearchResults] = useState(t2), [pageInfo, setPageInfo] = useState(), [isLoading, setIsLoading] = useState(!0), error = shopifyDomain ? apiError : "Please configure your Shopify domain in the plugin config";
403
+ let t3;
404
+ $[4] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t3 = new BehaviorSubject(""), $[4] = t3) : t3 = $[4];
405
+ const searchSubject$ = t3;
406
+ let t4;
407
+ $[5] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t4 = new BehaviorSubject(""), $[5] = t4) : t4 = $[5];
408
+ const cursorSubject$ = t4;
409
+ let t5, t6;
410
+ $[6] !== dataset || $[7] !== projectId || $[8] !== shopifyDomain || $[9] !== token ? (t5 = () => {
441
411
  const searchSubscription = search({
442
412
  projectId,
443
413
  dataset,
@@ -447,348 +417,188 @@ function ShopifyAssetPicker(props) {
447
417
  resultsPerPage: RESULTS_PER_PAGE,
448
418
  token
449
419
  }).subscribe({
450
- next: results => {
451
- setSearchResults(prevResults => [...prevResults, ...results.assets]);
452
- setPageInfo(results.pageInfo);
453
- setIsLoading(false);
420
+ next: (results) => {
421
+ setSearchResults((prevResults) => [...prevResults, ...results.assets]), setPageInfo(results.pageInfo), setIsLoading(!1);
454
422
  },
455
- error: err => {
456
- setError(`${err.response?.data?.message || err.message || "An error occurred"} - check plugin configuration`);
423
+ error: (err) => {
424
+ setApiError(`${err.response?.data?.message || err.message || "An error occurred"} - check plugin configuration`);
457
425
  }
458
426
  });
459
427
  return () => searchSubscription.unsubscribe();
460
- }, [searchSubject$, cursorSubject$, shopifyDomain, projectId, dataset, token]);
461
- const handleSearchTermChanged = React.useCallback(event => {
428
+ }, t6 = [searchSubject$, cursorSubject$, shopifyDomain, projectId, dataset, token], $[6] = dataset, $[7] = projectId, $[8] = shopifyDomain, $[9] = token, $[10] = t5, $[11] = t6) : (t5 = $[10], t6 = $[11]), useEffect(t5, t6);
429
+ let t7;
430
+ $[12] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t7 = (event) => {
462
431
  const newQuery = event.currentTarget.value;
463
- setQuery(newQuery);
464
- setSearchResults([]);
465
- setPageInfo(void 0);
466
- setIsLoading(true);
467
- cursorSubject$.next("");
468
- searchSubject$.next(newQuery);
469
- }, [cursorSubject$, searchSubject$]);
470
- const handleScollerLoadMore = React.useCallback(() => {
471
- setIsLoading(true);
472
- if (pageInfo) cursorSubject$.next(pageInfo.cursor);
473
- searchSubject$.next(query);
474
- }, [cursorSubject$, pageInfo, searchSubject$, query]);
475
- const handleSelect = React.useCallback(file => {
476
- file._key = value?._key;
477
- file._type = schemaType.name;
478
- onChange(sanity.PatchEvent.from([sanity.set(file)]));
479
- onClose();
480
- }, [onChange, onClose, schemaType.name, value?._key]);
481
- const renderFile = React.useCallback(fileProps => {
432
+ setQuery(newQuery), setSearchResults([]), setPageInfo(void 0), setIsLoading(!0), cursorSubject$.next(""), searchSubject$.next(newQuery);
433
+ }, $[12] = t7) : t7 = $[12];
434
+ const handleSearchTermChanged = t7;
435
+ let t8;
436
+ $[13] !== pageInfo || $[14] !== query ? (t8 = () => {
437
+ setIsLoading(!0), pageInfo && cursorSubject$.next(pageInfo.cursor), searchSubject$.next(query);
438
+ }, $[13] = pageInfo, $[14] = query, $[15] = t8) : t8 = $[15];
439
+ const handleScollerLoadMore = t8;
440
+ let t9;
441
+ $[16] !== onChange || $[17] !== onClose || $[18] !== schemaType.name || $[19] !== value?._key ? (t9 = (file) => {
442
+ file._key = value?._key, file._type = schemaType.name, onChange(PatchEvent.from([set(file)])), onClose();
443
+ }, $[16] = onChange, $[17] = onClose, $[18] = schemaType.name, $[19] = value?._key, $[20] = t9) : t9 = $[20];
444
+ const handleSelect = t9;
445
+ let t10;
446
+ $[21] !== handleSelect ? (t10 = (fileProps) => {
482
447
  const {
483
448
  photo,
484
449
  layout
485
450
  } = fileProps;
486
- return /* @__PURE__ */jsxRuntime.jsx(File, {
487
- onClick: handleSelect,
488
- data: photo.data,
489
- width: layout.width,
490
- height: layout.height
491
- });
492
- }, [handleSelect]);
493
- const handleWidth = React.useCallback(width => {
494
- if (width < 300) return 150;else if (width < 600) return 200;
495
- return 300;
496
- }, []);
497
- return /* @__PURE__ */jsxRuntime.jsx(ui.Dialog, {
498
- id: "shopify-asset-source",
499
- header: /* @__PURE__ */jsxRuntime.jsx(DialogHeader, {
500
- title: "Shopify Assets",
501
- shopifyDomain
502
- }),
503
- onClose,
504
- open: isOpen,
505
- width: 4,
506
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Stack, {
507
- space: 3,
508
- padding: 4,
509
- children: error ? /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
510
- overflow: "hidden",
511
- padding: 4,
512
- radius: 2,
513
- shadow: 1,
514
- tone: "critical",
515
- children: /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
516
- align: "center",
517
- gap: 3,
518
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Text, {
519
- size: 2,
520
- children: /* @__PURE__ */jsxRuntime.jsx(icons.ErrorOutlineIcon, {})
521
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Inline, {
522
- space: 2,
523
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
524
- size: 1,
525
- children: error
526
- })
527
- })]
528
- })
529
- }) : /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
530
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Card, {
531
- children: /* @__PURE__ */jsxRuntime.jsxs(Search, {
532
- space: 3,
533
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Text, {
534
- size: 1,
535
- weight: "semibold",
536
- children: "Search Shopify for assets"
537
- }), /* @__PURE__ */jsxRuntime.jsx(ui.TextInput, {
538
- label: "Search Images",
539
- placeholder: "filename.jpg",
540
- value: query,
541
- onChange: handleSearchTermChanged
542
- })]
543
- })
544
- }), !isLoading && searchResults.length === 0 && /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
545
- size: 1,
546
- muted: true,
547
- children: "No results found"
548
- }), /* @__PURE__ */jsxRuntime.jsx(InfiniteScroll__default.default, {
549
- dataLength: searchResults.length,
550
- next: handleScollerLoadMore,
551
- hasMore: pageInfo ? pageInfo?.hasNextPage : true,
552
- scrollThreshold: 0.99,
553
- height: "60vh",
554
- loader: /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
555
- align: "center",
556
- justify: "center",
557
- padding: 3,
558
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Spinner, {
559
- muted: true
560
- })
561
- }),
562
- endMessage: /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
563
- align: "center",
564
- justify: "center",
565
- padding: 3,
566
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
567
- size: 1,
568
- muted: true,
569
- children: "No more results"
570
- })
571
- }),
572
- children: searchResults && /* @__PURE__ */jsxRuntime.jsx(PhotoAlbum__default.default, {
573
- layout: "rows",
574
- spacing: PHOTO_SPACING,
575
- padding: PHOTO_PADDING,
576
- targetRowHeight: handleWidth,
577
- photos: searchResults.map(file => ({
578
- src: file?.preview?.url,
579
- width: file?.preview?.width || 2048,
580
- height: file?.preview?.height || 2048,
581
- key: file.id,
582
- data: file
583
- })),
584
- renderPhoto: renderFile,
585
- componentsProps: {
586
- containerProps: {
587
- style: {
588
- marginBottom: `${PHOTO_SPACING}px`
589
- }
590
- }
591
- }
592
- })
593
- })]
594
- })
595
- })
596
- });
451
+ return /* @__PURE__ */ jsx(File, { onClick: handleSelect, data: photo.data, width: layout.width, height: layout.height });
452
+ }, $[21] = handleSelect, $[22] = t10) : t10 = $[22];
453
+ const renderFile = t10, handleWidth = _temp;
454
+ let t11;
455
+ $[23] !== shopifyDomain ? (t11 = /* @__PURE__ */ jsx(DialogHeader, { title: "Shopify Assets", shopifyDomain }), $[23] = shopifyDomain, $[24] = t11) : t11 = $[24];
456
+ let t12;
457
+ $[25] !== error || $[26] !== handleScollerLoadMore || $[27] !== isLoading || $[28] !== pageInfo || $[29] !== query || $[30] !== renderFile || $[31] !== searchResults ? (t12 = /* @__PURE__ */ jsx(Stack, { gap: 3, padding: 4, children: error ? /* @__PURE__ */ jsx(Card, { overflow: "hidden", padding: 4, radius: 2, shadow: 1, tone: "critical", children: /* @__PURE__ */ jsxs(Flex, { align: "center", gap: 3, children: [
458
+ /* @__PURE__ */ jsx(Text, { size: 2, children: /* @__PURE__ */ jsx(ErrorOutlineIcon, {}) }),
459
+ /* @__PURE__ */ jsx(Inline, { gap: 2, children: /* @__PURE__ */ jsx(Text, { size: 1, children: error }) })
460
+ ] }) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
461
+ /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsxs(Search, { gap: 3, children: [
462
+ /* @__PURE__ */ jsx(Text, { size: 1, weight: "semibold", children: "Search Shopify for assets" }),
463
+ /* @__PURE__ */ jsx(TextInput, { label: "Search Images", placeholder: "filename.jpg", value: query, onChange: handleSearchTermChanged })
464
+ ] }) }),
465
+ !isLoading && searchResults.length === 0 && /* @__PURE__ */ jsx(Text, { size: 1, muted: !0, children: "No results found" }),
466
+ /* @__PURE__ */ jsx(InfiniteScroll, { dataLength: searchResults.length, next: handleScollerLoadMore, hasMore: pageInfo ? pageInfo?.hasNextPage : !0, scrollThreshold: 0.99, height: "60vh", loader: /* @__PURE__ */ jsx(Flex, { align: "center", justify: "center", padding: 3, children: /* @__PURE__ */ jsx(Spinner, { muted: !0 }) }), endMessage: /* @__PURE__ */ jsx(Flex, { align: "center", justify: "center", padding: 3, children: /* @__PURE__ */ jsx(Text, { size: 1, muted: !0, children: "No more results" }) }), children: searchResults && /* @__PURE__ */ jsx(PhotoAlbum, { layout: "rows", spacing: PHOTO_SPACING, padding: PHOTO_PADDING, targetRowHeight: handleWidth, photos: searchResults.map(_temp2), renderPhoto: renderFile, componentsProps: {
467
+ containerProps: {
468
+ style: {
469
+ marginBottom: `${PHOTO_SPACING}px`
470
+ }
471
+ }
472
+ } }) })
473
+ ] }) }), $[25] = error, $[26] = handleScollerLoadMore, $[27] = isLoading, $[28] = pageInfo, $[29] = query, $[30] = renderFile, $[31] = searchResults, $[32] = t12) : t12 = $[32];
474
+ let t13;
475
+ return $[33] !== isOpen || $[34] !== onClose || $[35] !== t11 || $[36] !== t12 ? (t13 = /* @__PURE__ */ jsx(Dialog, { id: "shopify-asset-source", header: t11, onClose, open: isOpen, width: 4, children: t12 }), $[33] = isOpen, $[34] = onClose, $[35] = t11, $[36] = t12, $[37] = t13) : t13 = $[37], t13;
476
+ }
477
+ function _temp2(file_0) {
478
+ return {
479
+ src: file_0?.preview?.url,
480
+ width: file_0?.preview?.width || 2048,
481
+ height: file_0?.preview?.height || 2048,
482
+ key: file_0.id,
483
+ data: file_0
484
+ };
485
+ }
486
+ function _temp(width) {
487
+ return width < 300 ? 150 : width < 600 ? 200 : 300;
597
488
  }
598
489
  const ShopifyIcon = () => {
599
- return /* @__PURE__ */jsxRuntime.jsxs("svg", {
600
- width: "18",
601
- height: "20",
602
- viewBox: "0 0 18 20",
603
- fill: "none",
604
- xmlns: "http://www.w3.org/2000/svg",
605
- children: [/* @__PURE__ */jsxRuntime.jsx("path", {
606
- 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",
607
- fill: "#95BF47"
608
- }), /* @__PURE__ */jsxRuntime.jsx("path", {
609
- 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",
610
- fill: "white"
611
- }), /* @__PURE__ */jsxRuntime.jsx("path", {
612
- 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",
613
- fill: "#5E8E3E"
614
- })]
615
- });
490
+ const $ = c(1);
491
+ let t0;
492
+ return $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = /* @__PURE__ */ jsxs("svg", { width: "18", height: "20", viewBox: "0 0 18 20", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
493
+ /* @__PURE__ */ jsx("path", { 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", fill: "#95BF47" }),
494
+ /* @__PURE__ */ jsx("path", { 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", fill: "white" }),
495
+ /* @__PURE__ */ jsx("path", { 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", fill: "#5E8E3E" })
496
+ ] }), $[0] = t0) : t0 = $[0], t0;
616
497
  };
617
498
  function ShopifyAssetInput(props) {
618
- const {
499
+ const $ = c(28), {
619
500
  onChange,
620
501
  readOnly,
621
502
  value,
622
503
  schemaType
623
- } = props;
624
- const {
504
+ } = props, {
625
505
  options
626
- } = schemaType;
627
- const {
506
+ } = schemaType, {
628
507
  shopifyDomain
629
- } = options;
630
- const [dialogOpen, setDialogOpen] = React.useState(false);
631
- const removeValue = React.useCallback(() => {
632
- onChange(sanity.PatchEvent.from([sanity.unset()]));
633
- }, [onChange]);
634
- const onOpen = React.useCallback(() => {
635
- setDialogOpen(true);
636
- }, [setDialogOpen]);
637
- const onClose = React.useCallback(() => {
638
- setDialogOpen(false);
639
- }, [setDialogOpen]);
508
+ } = options, [dialogOpen, setDialogOpen] = useState(!1);
509
+ let t0;
510
+ $[0] !== onChange ? (t0 = () => {
511
+ onChange(PatchEvent.from([unset()]));
512
+ }, $[0] = onChange, $[1] = t0) : t0 = $[1];
513
+ const removeValue = t0;
514
+ let t1;
515
+ $[2] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t1 = () => {
516
+ setDialogOpen(!0);
517
+ }, $[2] = t1) : t1 = $[2];
518
+ const onOpen = t1;
519
+ let t2;
520
+ $[3] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t2 = () => {
521
+ setDialogOpen(!1);
522
+ }, $[3] = t2) : t2 = $[3];
523
+ const onClose = t2;
640
524
  if (!shopifyDomain) {
641
- return /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
642
- overflow: "hidden",
643
- padding: 4,
644
- radius: 2,
645
- shadow: 1,
646
- tone: "critical",
647
- children: /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
648
- align: "center",
649
- gap: 3,
650
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Text, {
651
- size: 2,
652
- children: /* @__PURE__ */jsxRuntime.jsx(icons.ErrorOutlineIcon, {})
653
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Inline, {
654
- space: 2,
655
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
656
- size: 1,
657
- children: "You need to configure your *.myshopify.com domain in the plugin / field options to enable Shopify Assets."
658
- })
659
- })]
660
- })
661
- });
525
+ let t32;
526
+ $[4] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t32 = /* @__PURE__ */ jsx(Text, { size: 2, children: /* @__PURE__ */ jsx(ErrorOutlineIcon, {}) }), $[4] = t32) : t32 = $[4];
527
+ let t42;
528
+ return $[5] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t42 = /* @__PURE__ */ jsx(Card, { overflow: "hidden", padding: 4, radius: 2, shadow: 1, tone: "critical", children: /* @__PURE__ */ jsxs(Flex, { align: "center", gap: 3, children: [
529
+ t32,
530
+ /* @__PURE__ */ jsx(Inline, { gap: 2, children: /* @__PURE__ */ jsx(Text, { size: 1, children: "You need to configure your *.myshopify.com domain in the plugin / field options to enable Shopify Assets." }) })
531
+ ] }) }), $[5] = t42) : t42 = $[5], t42;
662
532
  }
663
- return /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
664
- children: [dialogOpen && /* @__PURE__ */jsxRuntime.jsx(ShopifyAssetPicker, {
665
- ...props,
666
- shopifyDomain,
667
- isOpen: dialogOpen,
668
- onClose,
669
- value
670
- }), /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
671
- children: [/* @__PURE__ */jsxRuntime.jsx(AssetPreview, {
672
- value
673
- }), /* @__PURE__ */jsxRuntime.jsxs(ui.Grid, {
674
- gap: 1,
675
- style: {
676
- gridTemplateColumns: "repeat(auto-fit, minmax(100px, 1fr))"
677
- },
678
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Button, {
679
- disabled: readOnly,
680
- mode: "ghost",
681
- icon: ShopifyIcon,
682
- title: "Select an asset",
683
- onClick: onOpen,
684
- text: "Select\u2026"
685
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
686
- disabled: readOnly || !value,
687
- tone: "critical",
688
- mode: "ghost",
689
- title: "Remove asset",
690
- text: "Remove",
691
- onClick: removeValue
692
- })]
693
- })]
694
- })]
695
- });
533
+ let t3;
534
+ $[6] !== dialogOpen || $[7] !== props || $[8] !== shopifyDomain || $[9] !== value ? (t3 = dialogOpen && /* @__PURE__ */ jsx(ShopifyAssetPicker, { ...props, shopifyDomain, isOpen: dialogOpen, onClose, value }), $[6] = dialogOpen, $[7] = props, $[8] = shopifyDomain, $[9] = value, $[10] = t3) : t3 = $[10];
535
+ let t4;
536
+ $[11] !== value ? (t4 = /* @__PURE__ */ jsx(AssetPreview, { value }), $[11] = value, $[12] = t4) : t4 = $[12];
537
+ let t5;
538
+ $[13] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t5 = {
539
+ gridTemplateColumns: "repeat(auto-fit, minmax(100px, 1fr))"
540
+ }, $[13] = t5) : t5 = $[13];
541
+ let t6;
542
+ $[14] !== readOnly ? (t6 = /* @__PURE__ */ jsx(Button, { disabled: readOnly, mode: "ghost", icon: ShopifyIcon, title: "Select an asset", onClick: onOpen, text: "Select\u2026" }), $[14] = readOnly, $[15] = t6) : t6 = $[15];
543
+ const t7 = readOnly || !value;
544
+ let t8;
545
+ $[16] !== removeValue || $[17] !== t7 ? (t8 = /* @__PURE__ */ jsx(Button, { disabled: t7, tone: "critical", mode: "ghost", title: "Remove asset", text: "Remove", onClick: removeValue }), $[16] = removeValue, $[17] = t7, $[18] = t8) : t8 = $[18];
546
+ let t9;
547
+ $[19] !== t6 || $[20] !== t8 ? (t9 = /* @__PURE__ */ jsxs(Grid, { gap: 1, style: t5, children: [
548
+ t6,
549
+ t8
550
+ ] }), $[19] = t6, $[20] = t8, $[21] = t9) : t9 = $[21];
551
+ let t10;
552
+ $[22] !== t4 || $[23] !== t9 ? (t10 = /* @__PURE__ */ jsxs(Stack, { children: [
553
+ t4,
554
+ t9
555
+ ] }), $[22] = t4, $[23] = t9, $[24] = t10) : t10 = $[24];
556
+ let t11;
557
+ return $[25] !== t10 || $[26] !== t3 ? (t11 = /* @__PURE__ */ jsxs(Fragment, { children: [
558
+ t3,
559
+ t10
560
+ ] }), $[25] = t10, $[26] = t3, $[27] = t11) : t11 = $[27], t11;
696
561
  }
697
- const CloudinaryDiffPreview = _ref10 => {
698
- let {
699
- value
700
- } = _ref10;
701
- if (!value) {
702
- return null;
703
- }
704
- if (value?.preview?.url) {
705
- return /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
706
- justify: "center",
707
- align: "center",
708
- height: "fill",
709
- width: "fill",
710
- children: /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
711
- space: 2,
712
- children: [/* @__PURE__ */jsxRuntime.jsx("img", {
713
- alt: "preview",
714
- src: value?.preview?.url,
715
- style: {
716
- objectFit: "contain",
717
- margin: "auto",
718
- maxWidth: "100%",
719
- maxHeight: "100%"
720
- }
721
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
722
- size: 1,
723
- children: value.type.charAt(0).toUpperCase() + value.type.slice(1)
724
- })]
725
- })
726
- });
727
- }
728
- return /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
729
- justify: "center",
730
- align: "center",
731
- height: "fill",
732
- width: "fill",
733
- children: /* @__PURE__ */jsxRuntime.jsx("div", {
734
- children: "(no image)"
735
- })
736
- });
737
- };
738
- const AssetDiff = _ref11 => {
739
- let {
740
- diff,
741
- schemaType
742
- } = _ref11;
743
- return /* @__PURE__ */jsxRuntime.jsx(sanity.DiffFromTo, {
744
- diff,
745
- schemaType,
746
- previewComponent: CloudinaryDiffPreview,
747
- layout: "grid"
748
- });
749
- };
750
- const shopifyAssetSchema = config => {
562
+ const shopifyAssetSchema = (config) => {
751
563
  const {
752
564
  shopifyDomain
753
565
  } = config;
754
- return sanity.defineType({
566
+ return defineType({
755
567
  type: "object",
756
568
  name: "shopify.asset",
757
569
  title: "Shopify Asset",
758
570
  options: {
759
571
  shopifyDomain
760
572
  },
761
- fields: [sanity.defineField({
573
+ fields: [defineField({
762
574
  type: "string",
763
575
  name: "filename",
764
576
  title: "Filename"
765
- }), sanity.defineField({
577
+ }), defineField({
766
578
  type: "string",
767
579
  name: "id",
768
580
  title: "ID"
769
- }), sanity.defineField({
581
+ }), defineField({
770
582
  type: "shopify.assetMetadata",
771
583
  name: "meta",
772
584
  title: "Metadata"
773
- }), sanity.defineField({
585
+ }), defineField({
774
586
  type: "shopify.assetPreview",
775
587
  name: "preview",
776
588
  title: "Preview"
777
- }), sanity.defineField({
589
+ }), defineField({
778
590
  type: "string",
779
591
  name: "type",
780
592
  title: "Type"
781
- }), sanity.defineField({
593
+ }), defineField({
782
594
  type: "url",
783
595
  name: "url",
784
596
  title: "URL"
785
597
  })],
786
- ...{
787
- components: {
788
- input: ShopifyAssetInput,
789
- diff: AssetDiff,
790
- preview: AssetPreview
791
- }
598
+ components: {
599
+ input: ShopifyAssetInput,
600
+ diff: AssetDiff,
601
+ preview: AssetPreview
792
602
  },
793
603
  preview: {
794
604
  select: {
@@ -798,14 +608,13 @@ const shopifyAssetSchema = config => {
798
608
  filename: "filename",
799
609
  type: "type"
800
610
  },
801
- prepare(_ref12) {
802
- let {
803
- url,
804
- meta,
805
- preview,
806
- filename,
807
- type
808
- } = _ref12;
611
+ prepare({
612
+ url,
613
+ meta,
614
+ preview,
615
+ filename,
616
+ type
617
+ }) {
809
618
  return {
810
619
  title: filename,
811
620
  subtitle: type,
@@ -819,58 +628,13 @@ const shopifyAssetSchema = config => {
819
628
  }
820
629
  }
821
630
  });
631
+ }, shopifyAssets = definePlugin((config) => ({
632
+ name: "shopify-asset-schema",
633
+ schema: {
634
+ types: [shopifyAssetPreviewSchema, shopifyAssetMetadataSchema, shopifyAssetSchema(config)]
635
+ }
636
+ }));
637
+ export {
638
+ shopifyAssets
822
639
  };
823
- const shopifyAssetPreviewSchema = sanity.defineType({
824
- type: "object",
825
- name: "shopify.assetPreview",
826
- title: "Asset preview",
827
- fields: [sanity.defineField({
828
- type: "number",
829
- name: "height",
830
- title: "Height"
831
- }), sanity.defineField({
832
- type: "number",
833
- name: "width",
834
- title: "Width"
835
- }), sanity.defineField({
836
- type: "url",
837
- name: "url",
838
- title: "URL"
839
- })]
840
- });
841
- const shopifyAssetMetadataSchema = sanity.defineType({
842
- type: "object",
843
- name: "shopify.assetMetadata",
844
- title: "Asset metadata",
845
- fields: [sanity.defineField({
846
- type: "string",
847
- name: "alt",
848
- title: "Alternative text"
849
- }), sanity.defineField({
850
- type: "number",
851
- name: "duration",
852
- title: "Duration"
853
- }), sanity.defineField({
854
- type: "number",
855
- name: "fileSize",
856
- title: "File size"
857
- }), sanity.defineField({
858
- type: "number",
859
- name: "height",
860
- title: "Height"
861
- }), sanity.defineField({
862
- type: "number",
863
- name: "width",
864
- title: "Width"
865
- })]
866
- });
867
- const shopifyAssets = sanity.definePlugin(config => {
868
- return {
869
- name: "shopify-asset-schema",
870
- schema: {
871
- types: [shopifyAssetPreviewSchema, shopifyAssetMetadataSchema, shopifyAssetSchema(config)]
872
- }
873
- };
874
- });
875
- exports.shopifyAssets = shopifyAssets;
876
640
  //# sourceMappingURL=index.js.map