sanity-plugin-cloudinary 0.2.2 → 1.0.0-v3-studio.2

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.
Files changed (51) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +160 -66
  3. package/lib/cjs/index.js +708 -0
  4. package/lib/cjs/index.js.map +1 -0
  5. package/lib/esm/index.js +697 -0
  6. package/lib/esm/index.js.map +1 -0
  7. package/lib/types/index.d.ts +22 -0
  8. package/lib/types/index.d.ts.map +1 -0
  9. package/package.json +66 -41
  10. package/sanity.json +3 -15
  11. package/src/arrayFunctions.tsx +71 -0
  12. package/src/components/AssetDiff.tsx +44 -0
  13. package/src/components/AssetPreview.tsx +41 -0
  14. package/src/components/CloudinaryInput.tsx +61 -0
  15. package/src/components/SecretsConfigView.tsx +39 -0
  16. package/src/components/VideoPlayer.tsx +62 -0
  17. package/src/components/WidgetInput.tsx +66 -0
  18. package/src/components/asset-source/CloudinaryAssetSource.tsx +155 -0
  19. package/src/components/asset-source/Icon.tsx +93 -0
  20. package/src/index.ts +30 -0
  21. package/src/schema/cloudinaryAsset.ts +99 -0
  22. package/src/schema/cloudinaryAssetDerived.ts +26 -0
  23. package/src/typings.d.ts +74 -0
  24. package/src/utils.ts +115 -0
  25. package/v2-incompatible.js +11 -0
  26. package/dist/arrayFunctions.js +0 -82
  27. package/dist/arrayFunctions.js.map +0 -1
  28. package/dist/components/AssetDiff.js +0 -62
  29. package/dist/components/AssetDiff.js.map +0 -1
  30. package/dist/components/AssetPreview.js +0 -46
  31. package/dist/components/AssetPreview.js.map +0 -1
  32. package/dist/components/CloudinaryInput.js +0 -90
  33. package/dist/components/CloudinaryInput.js.map +0 -1
  34. package/dist/components/SecretsConfigView.js +0 -37
  35. package/dist/components/SecretsConfigView.js.map +0 -1
  36. package/dist/components/VideoPlayer.js +0 -70
  37. package/dist/components/VideoPlayer.js.map +0 -1
  38. package/dist/components/WidgetInput.js +0 -87
  39. package/dist/components/WidgetInput.js.map +0 -1
  40. package/dist/index.js +0 -24
  41. package/dist/index.js.map +0 -1
  42. package/dist/schema/cloudinary.js +0 -19
  43. package/dist/schema/cloudinary.js.map +0 -1
  44. package/dist/schema/cloudinaryAsset.js +0 -100
  45. package/dist/schema/cloudinaryAsset.js.map +0 -1
  46. package/dist/schema/cloudinaryAssetDerived.js +0 -22
  47. package/dist/schema/cloudinaryAssetDerived.js.map +0 -1
  48. package/dist/typings.d.js +0 -8
  49. package/dist/typings.d.js.map +0 -1
  50. package/dist/utils.js +0 -92
  51. package/dist/utils.js.map +0 -1
@@ -0,0 +1,697 @@
1
+ import {createPlugin as $gGrEF$createPlugin, defineType as $gGrEF$defineType, PatchEvent as $gGrEF$PatchEvent, set as $gGrEF$set, unset as $gGrEF$unset, DiffFromTo as $gGrEF$DiffFromTo} from "sanity";
2
+ import {jsxs as $gGrEF$jsxs, Fragment as $gGrEF$Fragment, jsx as $gGrEF$jsx} from "react/jsx-runtime";
3
+ import $gGrEF$react, {useState as $gGrEF$useState, useCallback as $gGrEF$useCallback, useRef as $gGrEF$useRef, useEffect as $gGrEF$useEffect} from "react";
4
+ import {nanoid as $gGrEF$nanoid} from "nanoid";
5
+ import {useSecrets as $gGrEF$useSecrets, SettingsView as $gGrEF$SettingsView} from "@sanity/studio-secrets";
6
+ import {Stack as $gGrEF$Stack, Flex as $gGrEF$Flex, Button as $gGrEF$Button, Grid as $gGrEF$Grid, Box as $gGrEF$Box, Dialog as $gGrEF$Dialog, Spinner as $gGrEF$Spinner, Text as $gGrEF$Text} from "@sanity/ui";
7
+ import {PlugIcon as $gGrEF$PlugIcon} from "@sanity/icons";
8
+ import $gGrEF$styledcomponents from "styled-components";
9
+ import $gGrEF$videojs from "video.js";
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+ class $d0ca2ce2bdc323f5$export$2e2bcd8739ae039 extends (0, $gGrEF$react).Component {
25
+ componentDidMount() {
26
+ const { src: src } = this.props;
27
+ this.player = (0, $gGrEF$videojs)(this.videoNode, {
28
+ sources: [
29
+ {
30
+ src: src
31
+ }
32
+ ],
33
+ controls: true
34
+ });
35
+ }
36
+ componentWillUnmount() {
37
+ if (this.player) this.player.dispose();
38
+ }
39
+ render() {
40
+ const { kind: kind } = this.props;
41
+ const className = {
42
+ player: "video-js vjs-16-9 vjs-big-play-centered",
43
+ diff: "video-js vjs-layout-tiny vjs-fluid"
44
+ };
45
+ const style = {
46
+ position: "relative"
47
+ };
48
+ return /*#__PURE__*/ (0, $gGrEF$jsxs)("div", {
49
+ children: [
50
+ /*#__PURE__*/ (0, $gGrEF$jsx)("link", {
51
+ href: "https://vjs.zencdn.net/7.8.4/video-js.css",
52
+ rel: "stylesheet"
53
+ }),
54
+ /*#__PURE__*/ (0, $gGrEF$jsx)("div", {
55
+ "data-vjs-player": true,
56
+ children: /*#__PURE__*/ (0, $gGrEF$jsx)("video", {
57
+ onClick: (event)=>event.stopPropagation(),
58
+ style: kind === "diff" ? style : {},
59
+ className: className[kind],
60
+ ref: (node)=>{
61
+ if (node) this.videoNode = node;
62
+ }
63
+ })
64
+ })
65
+ ]
66
+ });
67
+ }
68
+ }
69
+
70
+
71
+ const $9f26f9f7274adc0d$var$widgetSrc = "https://media-library.cloudinary.com/global/all.js";
72
+ function $9f26f9f7274adc0d$export$e762090a5452d842(asset) {
73
+ if (asset.derived && asset.derived.length > 0) {
74
+ const [derived] = asset.derived;
75
+ if (derived.secure_url) return derived.secure_url;
76
+ return derived.url;
77
+ }
78
+ if (asset.secure_url) return asset.secure_url;
79
+ return asset.url;
80
+ }
81
+ const $9f26f9f7274adc0d$export$7a7ae4f24e5cd9dc = (cloudName, apiKey, multiple, insertHandler, selectedAsset)=>{
82
+ $9f26f9f7274adc0d$export$93b33d367be6802b($9f26f9f7274adc0d$var$widgetSrc, ()=>{
83
+ const options = {
84
+ cloud_name: cloudName,
85
+ api_key: apiKey,
86
+ insert_caption: "Select",
87
+ multiple: multiple
88
+ };
89
+ if (selectedAsset) options.asset = {
90
+ public_id: selectedAsset.public_id,
91
+ type: selectedAsset.type,
92
+ resource_type: selectedAsset.resource_type
93
+ };
94
+ window.cloudinary.openMediaLibrary(options, {
95
+ insertHandler: insertHandler
96
+ });
97
+ });
98
+ };
99
+ const $9f26f9f7274adc0d$export$fa8126b76e785c83 = ({ cloudName: cloudName , apiKey: apiKey , inlineContainer: inlineContainer , libraryCreated: libraryCreated , insertHandler: insertHandler })=>{
100
+ $9f26f9f7274adc0d$export$93b33d367be6802b($9f26f9f7274adc0d$var$widgetSrc, ()=>{
101
+ const options = {
102
+ cloud_name: cloudName,
103
+ api_key: apiKey,
104
+ insert_caption: "Select",
105
+ inline_container: inlineContainer,
106
+ remove_header: true
107
+ };
108
+ libraryCreated(window.cloudinary.createMediaLibrary(options, {
109
+ insertHandler: insertHandler
110
+ }));
111
+ });
112
+ };
113
+ function $9f26f9f7274adc0d$export$93b33d367be6802b(url, callback) {
114
+ const existingScript = document.getElementById("damWidget");
115
+ if (!existingScript) {
116
+ const script = document.createElement("script");
117
+ script.src = url;
118
+ script.id = "damWidget";
119
+ document.body.appendChild(script);
120
+ script.onload = ()=>{
121
+ if (callback) return callback();
122
+ return true;
123
+ };
124
+ }
125
+ if (existingScript && callback) return callback();
126
+ return true;
127
+ }
128
+ function $9f26f9f7274adc0d$export$f58729bedbec21be(asset) {
129
+ const { resource_type: resource_type , public_id: public_id , type: type } = asset;
130
+ return btoa(JSON.stringify({
131
+ public_id: public_id,
132
+ resource_type: resource_type,
133
+ type: type
134
+ })) // Sort keys alphabetically!
135
+ ;
136
+ }
137
+ function $9f26f9f7274adc0d$export$e708ba11f5ba43ca(asset) {
138
+ return `${asset.public_id.split("/").slice(-1)[0]}.${asset.format}`;
139
+ }
140
+ function $9f26f9f7274adc0d$export$369dff7d11616ebd(sourceId) {
141
+ let sourceIdDecoded;
142
+ try {
143
+ sourceIdDecoded = JSON.parse(atob(sourceId));
144
+ } catch (err) {
145
+ // Do nothing
146
+ }
147
+ return sourceIdDecoded;
148
+ }
149
+
150
+
151
+
152
+ const $3c65b369e9d0aecb$var$AssetPreview = ({ value: value , layout: layout })=>{
153
+ const url = value && (0, $9f26f9f7274adc0d$export$e762090a5452d842)(value);
154
+ if (!value || !url) return null;
155
+ switch(value.resource_type){
156
+ case "video":
157
+ return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
158
+ children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $d0ca2ce2bdc323f5$export$2e2bcd8739ae039), {
159
+ src: url,
160
+ kind: "player"
161
+ })
162
+ });
163
+ default:
164
+ return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Box), {
165
+ children: /*#__PURE__*/ (0, $gGrEF$jsx)("img", {
166
+ alt: "preview",
167
+ src: url,
168
+ style: {
169
+ maxWidth: layout === "default" ? "80px" : "100%",
170
+ height: "auto"
171
+ }
172
+ })
173
+ });
174
+ }
175
+ };
176
+ var $3c65b369e9d0aecb$export$2e2bcd8739ae039 = $3c65b369e9d0aecb$var$AssetPreview;
177
+
178
+
179
+ const $dc014f96cd8956fa$var$SetupButtonContainer = (0, $gGrEF$styledcomponents).div`
180
+ position: relative;
181
+ display: block;
182
+ font-size: 0.8em;
183
+ transform: translate(0%, -10%);
184
+ `;
185
+ const $dc014f96cd8956fa$var$WidgetInput = (props)=>{
186
+ const { onChange: onChange , readOnly: readOnly , value: value , openMediaSelector: openMediaSelector } = props;
187
+ const removeValue = (0, $gGrEF$useCallback)(()=>{
188
+ onChange((0, $gGrEF$PatchEvent).from([
189
+ (0, $gGrEF$unset)()
190
+ ]));
191
+ }, [
192
+ onChange
193
+ ]);
194
+ return /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Stack), {
195
+ children: [
196
+ /*#__PURE__*/ (0, $gGrEF$jsx)($dc014f96cd8956fa$var$SetupButtonContainer, {
197
+ children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Flex), {
198
+ flex: 1,
199
+ justify: "flex-end",
200
+ children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Button), {
201
+ color: "primary",
202
+ icon: (0, $gGrEF$PlugIcon),
203
+ mode: "bleed",
204
+ title: "Configure",
205
+ onClick: props.onSetup,
206
+ tabIndex: 1
207
+ })
208
+ })
209
+ }),
210
+ /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Flex), {
211
+ style: {
212
+ textAlign: "center"
213
+ },
214
+ marginBottom: 2,
215
+ children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $3c65b369e9d0aecb$export$2e2bcd8739ae039), {
216
+ value: value
217
+ })
218
+ }),
219
+ /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Grid), {
220
+ gap: 1,
221
+ style: {
222
+ gridTemplateColumns: "repeat(auto-fit, minmax(100px, 1fr))"
223
+ },
224
+ children: [
225
+ /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Button), {
226
+ disabled: readOnly,
227
+ mode: "ghost",
228
+ title: "Select an asset",
229
+ tone: "default",
230
+ onClick: openMediaSelector,
231
+ text: "Select\u2026"
232
+ }),
233
+ /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Button), {
234
+ disabled: readOnly || !value,
235
+ tone: "critical",
236
+ mode: "ghost",
237
+ title: "Remove asset",
238
+ text: "Remove",
239
+ onClick: removeValue
240
+ })
241
+ ]
242
+ })
243
+ ]
244
+ });
245
+ };
246
+ var $dc014f96cd8956fa$export$2e2bcd8739ae039 = $dc014f96cd8956fa$var$WidgetInput;
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+ const $55bfa86538ac414c$var$pluginConfigKeys = [
257
+ {
258
+ key: "cloudName",
259
+ title: "Cloud name",
260
+ description: ""
261
+ },
262
+ {
263
+ key: "apiKey",
264
+ title: "API key",
265
+ description: ""
266
+ },
267
+ ];
268
+ const $55bfa86538ac414c$export$76a88f7de6507443 = "cloudinary";
269
+ const $55bfa86538ac414c$var$SecretsConfigView = (props)=>{
270
+ return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$SettingsView), {
271
+ title: "Cloudinary config",
272
+ namespace: $55bfa86538ac414c$export$76a88f7de6507443,
273
+ keys: $55bfa86538ac414c$var$pluginConfigKeys,
274
+ onClose: props.onClose
275
+ });
276
+ };
277
+ var $55bfa86538ac414c$export$2e2bcd8739ae039 = $55bfa86538ac414c$var$SecretsConfigView;
278
+
279
+
280
+ const $6e34dd052adcab4c$var$CloudinaryInput = (props)=>{
281
+ const [showSettings, setShowSettings] = (0, $gGrEF$useState)(false);
282
+ const { secrets: secrets } = (0, $gGrEF$useSecrets)((0, $55bfa86538ac414c$export$76a88f7de6507443));
283
+ const { onChange: onChange , schemaType: type } = props;
284
+ const value = props.value || undefined;
285
+ const handleSelect = (0, $gGrEF$useCallback)((payload)=>{
286
+ const [asset] = payload.assets;
287
+ if (!asset) return;
288
+ onChange((0, $gGrEF$PatchEvent).from([
289
+ (0, $gGrEF$set)(Object.assign({
290
+ _type: type.name,
291
+ _version: 1,
292
+ ...value?._key ? {
293
+ _key: value._key
294
+ } : {
295
+ _key: (0, $gGrEF$nanoid)()
296
+ }
297
+ }, asset)),
298
+ ]));
299
+ }, [
300
+ onChange,
301
+ type,
302
+ value?._key
303
+ ]);
304
+ const action = secrets ? ()=>(0, $9f26f9f7274adc0d$export$7a7ae4f24e5cd9dc)(secrets.cloudName, secrets.apiKey, false, handleSelect, value) : ()=>setShowSettings(true);
305
+ return /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Fragment), {
306
+ children: [
307
+ showSettings && /*#__PURE__*/ (0, $gGrEF$jsx)((0, $55bfa86538ac414c$export$2e2bcd8739ae039), {
308
+ onClose: ()=>setShowSettings(false)
309
+ }),
310
+ /*#__PURE__*/ (0, $gGrEF$jsx)((0, $dc014f96cd8956fa$export$2e2bcd8739ae039), {
311
+ onSetup: ()=>setShowSettings(true),
312
+ openMediaSelector: action,
313
+ ...props
314
+ })
315
+ ]
316
+ });
317
+ };
318
+ var $6e34dd052adcab4c$export$2e2bcd8739ae039 = $6e34dd052adcab4c$var$CloudinaryInput;
319
+
320
+
321
+
322
+
323
+
324
+
325
+
326
+ const $7d033a681fb9bd74$var$CloudinaryDiffPreview = ({ value: value })=>{
327
+ if (!value) return null;
328
+ const url = (0, $9f26f9f7274adc0d$export$e762090a5452d842)(value);
329
+ if (value.resource_type === "video") return /*#__PURE__*/ (0, $gGrEF$jsx)("section", {
330
+ style: {
331
+ display: "flex",
332
+ flexWrap: "wrap",
333
+ justifyContent: "space-between"
334
+ },
335
+ children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $d0ca2ce2bdc323f5$export$2e2bcd8739ae039), {
336
+ src: url,
337
+ kind: "diff"
338
+ })
339
+ });
340
+ return /*#__PURE__*/ (0, $gGrEF$jsx)("img", {
341
+ alt: "preview",
342
+ src: url,
343
+ style: {
344
+ maxWidth: "100%",
345
+ height: "auto"
346
+ }
347
+ });
348
+ };
349
+ const $7d033a681fb9bd74$var$AssetDiff = ({ diff: diff , schemaType: schemaType })=>{
350
+ return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$DiffFromTo), {
351
+ diff: diff,
352
+ schemaType: schemaType,
353
+ previewComponent: $7d033a681fb9bd74$var$CloudinaryDiffPreview
354
+ });
355
+ };
356
+ var $7d033a681fb9bd74$export$2e2bcd8739ae039 = $7d033a681fb9bd74$var$AssetDiff;
357
+
358
+
359
+
360
+
361
+ const $4a7defd9e77e9634$export$3ed2e98ebe80ce58 = (0, $gGrEF$defineType)({
362
+ type: "object",
363
+ name: "cloudinary.asset",
364
+ fields: [
365
+ {
366
+ type: "string",
367
+ name: "public_id"
368
+ },
369
+ {
370
+ type: "string",
371
+ name: "resource_type"
372
+ },
373
+ {
374
+ type: "string",
375
+ name: "type"
376
+ },
377
+ {
378
+ type: "string",
379
+ name: "format"
380
+ },
381
+ {
382
+ type: "number",
383
+ name: "version"
384
+ },
385
+ {
386
+ type: "url",
387
+ name: "url"
388
+ },
389
+ {
390
+ type: "url",
391
+ name: "secure_url"
392
+ },
393
+ {
394
+ type: "number",
395
+ name: "width"
396
+ },
397
+ {
398
+ type: "number",
399
+ name: "height"
400
+ },
401
+ {
402
+ type: "number",
403
+ name: "bytes"
404
+ },
405
+ {
406
+ type: "number",
407
+ name: "duration"
408
+ },
409
+ {
410
+ type: "array",
411
+ name: "tags",
412
+ of: [
413
+ {
414
+ type: "string"
415
+ }
416
+ ]
417
+ },
418
+ {
419
+ type: "datetime",
420
+ name: "created_at"
421
+ },
422
+ {
423
+ type: "array",
424
+ name: "derived",
425
+ of: [
426
+ {
427
+ type: "cloudinary.assetDerived"
428
+ }
429
+ ]
430
+ },
431
+ {
432
+ type: "string",
433
+ name: "access_mode"
434
+ }
435
+ ],
436
+ components: {
437
+ input: (0, $6e34dd052adcab4c$export$2e2bcd8739ae039),
438
+ diff: (0, $7d033a681fb9bd74$export$2e2bcd8739ae039),
439
+ preview: (0, $3c65b369e9d0aecb$export$2e2bcd8739ae039)
440
+ },
441
+ preview: {
442
+ select: {
443
+ url: "url",
444
+ resource_type: "resource_type",
445
+ derived: "derived.0.url"
446
+ },
447
+ prepare ({ url: url , derived: derived , resource_type: resource_type }) {
448
+ return {
449
+ title: url,
450
+ resource_type: resource_type,
451
+ url: derived || url
452
+ };
453
+ }
454
+ }
455
+ });
456
+
457
+
458
+
459
+ const $ebc9980d601ccc9b$export$26e4781cb23ffde8 = (0, $gGrEF$defineType)({
460
+ type: "object",
461
+ name: "cloudinary.assetDerived",
462
+ fields: [
463
+ {
464
+ type: "string",
465
+ name: "raw_transformation"
466
+ },
467
+ {
468
+ type: "url",
469
+ name: "url"
470
+ },
471
+ {
472
+ type: "url",
473
+ name: "secure_url"
474
+ },
475
+ ]
476
+ });
477
+
478
+
479
+
480
+
481
+
482
+ function $5737bc33d6712f10$export$41acf4847aa33418() {
483
+ return /*#__PURE__*/ (0, $gGrEF$jsx)("svg", {
484
+ version: "1.1",
485
+ id: "Layer_1",
486
+ x: "0px",
487
+ y: "0px",
488
+ width: "1em",
489
+ height: "1em",
490
+ viewBox: "0 0 141.732 141.747",
491
+ enableBackground: "new 0 0 141.732 141.747",
492
+ children: /*#__PURE__*/ (0, $gGrEF$jsxs)("g", {
493
+ children: [
494
+ /*#__PURE__*/ (0, $gGrEF$jsx)("path", {
495
+ fill: "#0071CE",
496
+ d: "M115.585,109.242c-1.609,0-3.107-1.024-3.635-2.637c-0.657-2.008,0.438-4.169,2.447-4.826 c7.278-2.382,11.98-8.761,11.98-16.252c0-9.487-7.718-17.206-17.205-17.206c-0.659,0-1.368,0.052-2.231,0.164l-3.741,0.485 l-0.537-3.735c-2.299-16.016-16.251-28.094-32.454-28.094c-13.395,0-25.32,8.019-30.377,20.43l-0.952,2.335l-2.52,0.046 c-11.581,0.213-21.003,9.804-21.003,21.379c0,8.45,4.906,16.156,12.498,19.631c1.921,0.88,2.766,3.15,1.886,5.071 c-0.88,1.921-3.149,2.764-5.07,1.887C14.363,103.202,7.703,92.766,7.703,81.331c0-14.88,11.465-27.345,26.028-28.876 c6.71-14.03,20.773-22.965,36.477-22.965c18.796,0,35.135,13.178,39.372,31.184c13.519,0.219,24.45,11.284,24.45,24.854 c0,10.693-6.934,20.146-17.253,23.523C116.382,109.18,115.98,109.242,115.585,109.242z"
497
+ }),
498
+ /*#__PURE__*/ (0, $gGrEF$jsx)("path", {
499
+ fill: "#DC8327",
500
+ d: "M57.12,111.02c-0.001-0.001-0.001-0.001-0.002-0.001c-0.001,0-0.002-0.001-0.003-0.001h-0.001 c0,0-0.001-0.001-0.001-0.001l-0.001-0.001c0,0-0.001,0-0.001-0.001h-0.001l-0.001-0.001c0.001-0.001-0.001-0.001-0.001-0.001 l-0.001-0.001c0,0-0.001,0-0.001,0l-0.001-0.001c0.001,0.001-0.001-0.001-0.001-0.001s-0.002-0.001-0.003-0.001l-0.001-0.001H57.1 c-0.001-0.001-0.001-0.001-0.001-0.001l-0.001-0.001c-0.003-0.001-0.002-0.001-0.003-0.001c-0.001,0.001-0.001-0.001-0.002-0.001 l-0.001-0.001c0,0-0.001-0.001-0.002-0.001l-0.001-0.001c-0.001-0.001-0.003-0.001-0.004-0.001s-0.003-0.001-0.004-0.001 c-0.001-0.001-0.001-0.001-0.002-0.001h-0.001c-0.001-0.001-0.002-0.001-0.003-0.001c-0.001-0.001-0.003-0.001-0.003-0.001 c-0.001,0-0.001,0-0.001,0l-0.002-0.001c-0.001,0-0.001-0.001-0.001-0.001h-0.001c-0.059-0.021-0.122-0.034-0.188-0.037h-0.002 h-0.002c-0.001,0-0.001,0-0.002,0c0,0,0,0-0.001,0c0,0-0.001,0-0.001,0h-0.001c-0.001-0.001-0.001-0.001-0.001-0.001 c-0.001,0-0.002,0-0.002,0c-0.001,0-0.002,0-0.002,0h-0.001h-0.001h-0.001c-0.001,0-0.002,0-0.002,0h-0.001H56.86h-0.001h-0.001 c-0.001,0-0.001,0-0.001,0h-0.001h-0.001h-0.001h-0.001c-0.001,0-0.001,0-0.001,0c-1.656,0-3.011-1.348-3.021-3V74.29h2.567 c0.004,0,0.009,0,0.013,0c0.393,0.017,0.661-0.285,0.661-0.648c0-0.271-0.166-0.503-0.402-0.6l-12.379-8.544 c-0.222-0.153-0.515-0.153-0.737,0l-12.476,8.611c-0.234,0.161-0.335,0.456-0.251,0.727c0.085,0.271,0.335,0.455,0.619,0.455h2.58 l0.002,33.674c0.013,2.328,1.883,4.228,4.262,4.288c0.027,0.003,0.053,0.005,0.08,0.005h18.481c0.004,0,0.007,0,0.011,0 c0.17-0.003,0.324-0.071,0.438-0.18c0,0,0,0,0.001-0.001c0.002-0.002,0.004-0.004,0.005-0.005c0.001-0.001,0.002-0.001,0.003-0.003 c0,0,0.001-0.001,0.001-0.001l0.001-0.001l0.001-0.001l0.001-0.001l0.001-0.001c0.001-0.001,0.001-0.001,0.001-0.001 c0.002-0.001,0.001-0.001,0.002-0.002c0,0,0,0,0.001-0.001l0.001-0.001c0,0,0,0,0.001-0.001c0.112-0.116,0.182-0.273,0.183-0.447 v-0.002v-0.001v-0.001v-0.001v-0.001v-0.001v-0.001v-0.002C57.498,111.345,57.343,111.121,57.12,111.02z"
501
+ }),
502
+ /*#__PURE__*/ (0, $gGrEF$jsx)("path", {
503
+ fill: "#F4B21B",
504
+ d: "M83.889,111.02c0,0-0.001-0.001-0.002-0.001c-0.001,0-0.002-0.001-0.003-0.001h-0.001 c-0.001-0.001-0.001-0.001-0.001-0.001l-0.001-0.001h-0.001c0,0-0.001-0.001-0.001-0.001c0,0-0.001-0.001-0.001-0.001 c0.001-0.001-0.001-0.001-0.002-0.001l-0.001-0.001h-0.001c-0.001,0-0.001-0.001-0.001-0.001c-0.002,0.001-0.002-0.001-0.002-0.001 l-0.002-0.001l-0.001-0.001h-0.001c0,0-0.001-0.001-0.001-0.001l-0.001-0.001c-0.001-0.001-0.002-0.001-0.002-0.001 c-0.001,0.001-0.001-0.001-0.003-0.001l-0.001-0.001l-0.001-0.001c0,0-0.001,0-0.002-0.001c-0.001-0.001-0.003-0.001-0.004-0.001 s-0.003-0.001-0.004-0.001c-0.001-0.001-0.001-0.001-0.002-0.001c-0.001,0-0.001,0-0.002-0.001c0,0-0.001,0-0.002-0.001 c-0.003-0.001-0.001-0.001-0.002-0.001c-0.003,0-0.001,0-0.002-0.001c0,0-0.001-0.001-0.002-0.001l-0.001-0.001h-0.001 c-0.059-0.021-0.122-0.034-0.188-0.037h-0.002c-0.001,0-0.001,0-0.001,0c-0.001,0-0.002,0-0.002,0s-0.001,0-0.001,0h-0.001h-0.001 l-0.001-0.001c-0.001,0-0.002,0-0.002,0c-0.001,0-0.002,0-0.002,0h-0.001c-0.001,0-0.001,0-0.001,0h-0.001 c-0.001,0-0.002,0-0.002,0s-0.001,0-0.002,0h-0.001c0,0-0.001,0-0.001,0h-0.001c-0.001,0-0.001,0-0.001,0h-0.001h-0.001h-0.001 h-0.001c-0.001,0-0.001,0-0.001,0c-1.655,0-3.01-1.348-3.02-3V81.829h2.579c0.009-0.001,0.016-0.001,0.026,0 c0.358,0,0.648-0.29,0.648-0.648c0-0.271-0.166-0.503-0.402-0.6l-12.38-8.544c-0.222-0.153-0.515-0.153-0.737,0L57.86,80.647 c-0.234,0.161-0.335,0.456-0.251,0.727c0.085,0.271,0.335,0.455,0.619,0.455h2.568l0.002,26.135 c0.011,2.329,1.884,4.23,4.264,4.289c0.026,0.003,0.052,0.004,0.078,0.004h18.481c0.004,0,0.007,0,0.011,0 c0.17-0.003,0.324-0.071,0.438-0.18c0,0,0,0,0.001-0.001c0.002-0.002,0.006-0.004,0.005-0.005c0.001-0.001,0.002-0.001,0.003-0.003 c0.001-0.001,0.001-0.001,0.001-0.001l0.001-0.001l0.001-0.001c0,0,0.001,0,0.001-0.001l0.001-0.001 c0.001,0,0.001-0.001,0.001-0.001c0.003-0.001,0.002-0.001,0.002-0.002c0,0,0,0,0.001-0.001c0,0,0,0,0.001-0.001 c0,0,0,0,0.001-0.001c0.112-0.116,0.182-0.273,0.183-0.447v-0.002v-0.001v-0.001v-0.001v-0.001v-0.001v-0.001v-0.002 C84.267,111.345,84.112,111.121,83.889,111.02z"
505
+ }),
506
+ /*#__PURE__*/ (0, $gGrEF$jsx)("path", {
507
+ fill: "#F2D864",
508
+ d: "M110.667,111.02l-0.002-0.001c-0.001,0-0.002-0.001-0.003-0.001h-0.001 c-0.001-0.001-0.001-0.001-0.001-0.001l-0.001-0.001c-0.001,0-0.001,0-0.001-0.001h-0.001l-0.001-0.001 c-0.001-0.001-0.001-0.001-0.001-0.001s-0.001,0-0.001-0.001h-0.001c0,0-0.001-0.001-0.001-0.001 c-0.001,0.001-0.001-0.001-0.002-0.001c0.001-0.001-0.001-0.001-0.002-0.001l-0.001-0.001c-0.001,0-0.001,0-0.001,0 c-0.001-0.001-0.001-0.001-0.001-0.001l-0.001-0.001c-0.003-0.001-0.002-0.001-0.002-0.001c-0.001,0.001-0.001-0.001-0.003-0.001 l-0.001-0.001c0.001-0.001-0.001-0.001-0.002-0.001c0,0-0.001,0-0.001-0.001c-0.001-0.001-0.003-0.001-0.004-0.001 s-0.003-0.001-0.004-0.001l-0.002-0.001c0,0-0.001,0-0.002-0.001l-0.002-0.001c-0.003-0.001-0.003-0.001-0.002-0.001 c-0.003,0-0.003,0-0.002-0.001c-0.001,0-0.001-0.001-0.001-0.001c-0.001,0-0.002-0.001-0.002-0.001h-0.001 c-0.059-0.021-0.122-0.034-0.188-0.037h-0.001c-0.001,0-0.002,0-0.002,0c-0.001,0-0.002,0-0.003,0h-0.001h-0.001h-0.001 c-0.001-0.001-0.001-0.001-0.002-0.001c0,0-0.001,0-0.002,0c0,0-0.001,0-0.002,0h-0.001c0,0-0.001,0-0.001,0h-0.001 c-0.001,0-0.002,0-0.002,0h-0.002c0,0,0,0-0.001,0c0,0-0.001,0-0.001,0h-0.001c0,0-0.001,0-0.001,0h-0.001h-0.001h-0.001H110.4 c0,0-0.001,0-0.001,0c-1.655,0-3.01-1.348-3.02-3V89.365h2.573c0.004,0,0.009,0,0.013,0c0.365-0.009,0.661-0.285,0.661-0.648 c0-0.271-0.166-0.503-0.402-0.6l-12.38-8.544c-0.221-0.153-0.515-0.153-0.737,0l-12.476,8.61c-0.234,0.161-0.335,0.456-0.251,0.727 c0.085,0.271,0.335,0.455,0.619,0.455h2.573l0.002,18.599c0.013,2.329,1.885,4.231,4.264,4.289 c0.026,0.003,0.052,0.004,0.078,0.004h18.481c0.004,0,0.007,0,0.011,0c0.17-0.003,0.324-0.071,0.438-0.18l0.001-0.001 c0.002-0.002,0.005-0.004,0.005-0.005c0.001-0.001,0.002-0.001,0.003-0.003c0,0,0.001-0.001,0.001-0.001l0.001-0.001l0.001-0.001 l0.001-0.001l0.001-0.001l0.001-0.001c0.003-0.001,0.001-0.001,0.002-0.002c0,0,0,0,0.001-0.001l0.001-0.001c0,0,0,0,0.001-0.001 c0.112-0.116,0.182-0.273,0.183-0.447v-0.002v-0.001v-0.001v-0.001v-0.001v-0.001v-0.001v-0.002 C111.045,111.345,110.889,111.121,110.667,111.02z"
509
+ })
510
+ ]
511
+ })
512
+ });
513
+ }
514
+
515
+
516
+
517
+
518
+
519
+
520
+
521
+
522
+
523
+
524
+ const $1d4b493cde06506a$export$a829527ff4e4114a = (0, $gGrEF$styledcomponents).div`
525
+ height: 70vh;
526
+ `;
527
+ function $1d4b493cde06506a$export$d86b01636c6a833b(props) {
528
+ const { onClose: onClose } = props;
529
+ const [loadingMessage, setLoadingMessage] = (0, $gGrEF$useState)("Loading Cloudinary Media Libary");
530
+ const library = (0, $gGrEF$useRef)();
531
+ const contentRef = (0, $gGrEF$useRef)(null);
532
+ const { secrets: secrets } = (0, $gGrEF$useSecrets)((0, $55bfa86538ac414c$export$76a88f7de6507443));
533
+ const cloudName = secrets?.cloudName;
534
+ const apiKey = secrets?.apiKey;
535
+ const [widgetId] = (0, $gGrEF$useState)(()=>`cloundinaryWidget-${Date.now()}`);
536
+ const [showSettings, setShowSettings] = (0, $gGrEF$useState)(false);
537
+ const propsRef = (0, $gGrEF$useRef)(props);
538
+ (0, $gGrEF$useEffect)(()=>{
539
+ // because we have to access props after loading js in a callback,
540
+ // we cannot pass props as dependecnies as that will cause infinite updates
541
+ // this takes a snapshot of props, so we can access them later
542
+ propsRef.current = props;
543
+ }, [
544
+ props
545
+ ]);
546
+ const handleClose = (0, $gGrEF$useCallback)(()=>{
547
+ if (library.current) library.current.hide();
548
+ onClose();
549
+ }, [
550
+ onClose,
551
+ library
552
+ ]);
553
+ (0, $gGrEF$useEffect)(()=>{
554
+ if (!cloudName || !apiKey) return;
555
+ (0, $9f26f9f7274adc0d$export$fa8126b76e785c83)({
556
+ cloudName: cloudName,
557
+ apiKey: apiKey,
558
+ inlineContainer: `#${widgetId}`,
559
+ libraryCreated: (lib)=>{
560
+ library.current = lib;
561
+ const selectedAssets = propsRef.current.selectedAssets;
562
+ const firstSelectedAsset = selectedAssets ? selectedAssets[0] : null;
563
+ // eslint-disable-next-line no-undef
564
+ const iframe = contentRef.current && contentRef.current.firstChild;
565
+ if (iframe && iframe instanceof HTMLIFrameElement) {
566
+ setLoadingMessage(undefined);
567
+ let asset;
568
+ if (propsRef.current.selectionType === "single" && firstSelectedAsset && firstSelectedAsset.source && firstSelectedAsset.source.id) asset = (0, $9f26f9f7274adc0d$export$369dff7d11616ebd)(firstSelectedAsset.source.id);
569
+ const folder = asset ? {
570
+ path: asset.public_id.split("/").slice(0, -1).join("/"),
571
+ resource_type: "image"
572
+ } : {
573
+ path: "",
574
+ resource_type: "image"
575
+ };
576
+ if (lib && contentRef.current) {
577
+ lib.show({
578
+ folder: folder,
579
+ asset: asset
580
+ });
581
+ contentRef.current.style.visibility = "visible";
582
+ }
583
+ }
584
+ },
585
+ insertHandler: ({ assets: assets })=>{
586
+ if (!library.current) return;
587
+ const imageAssets = assets.filter((asset)=>asset.resource_type === "image");
588
+ if (imageAssets.length === 0) throw new Error("The selection did not contain any images.");
589
+ library.current.hide();
590
+ propsRef.current.onSelect(imageAssets.map((asset)=>{
591
+ const url = asset.derived && asset.derived[0] ? asset.derived[0].secure_url : asset.secure_url;
592
+ return {
593
+ kind: "url",
594
+ value: url,
595
+ assetDocumentProps: {
596
+ _type: "sanity.imageAsset",
597
+ originalFilename: (0, $9f26f9f7274adc0d$export$e708ba11f5ba43ca)(asset),
598
+ source: {
599
+ id: (0, $9f26f9f7274adc0d$export$f58729bedbec21be)(asset),
600
+ name: `cloudinary:${cloudName}`
601
+ }
602
+ }
603
+ };
604
+ }));
605
+ }
606
+ });
607
+ }, [
608
+ cloudName,
609
+ apiKey,
610
+ widgetId
611
+ ]);
612
+ const hasConfig = apiKey && cloudName;
613
+ return /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Dialog), {
614
+ id: "cloudinary-asset-source",
615
+ header: "Select image from Cloudinary",
616
+ onClose: handleClose,
617
+ open: true,
618
+ width: 4,
619
+ children: /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Box), {
620
+ padding: 4,
621
+ children: [
622
+ showSettings && /*#__PURE__*/ (0, $gGrEF$jsx)((0, $55bfa86538ac414c$export$2e2bcd8739ae039), {
623
+ onClose: ()=>setShowSettings(false)
624
+ }),
625
+ /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Flex), {
626
+ flex: 1,
627
+ justify: "flex-end",
628
+ children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Button), {
629
+ color: "primary",
630
+ icon: (0, $gGrEF$PlugIcon),
631
+ mode: "bleed",
632
+ title: "Configure",
633
+ onClick: ()=>setShowSettings(true),
634
+ tabIndex: 1,
635
+ text: hasConfig ? undefined : "Configure Cloudinary plugin"
636
+ })
637
+ }),
638
+ hasConfig && loadingMessage && /*#__PURE__*/ (0, $gGrEF$jsxs)((0, $gGrEF$Stack), {
639
+ space: 3,
640
+ children: [
641
+ /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Flex), {
642
+ align: "center",
643
+ justify: "center",
644
+ children: /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Spinner), {
645
+ muted: true
646
+ })
647
+ }),
648
+ /*#__PURE__*/ (0, $gGrEF$jsx)((0, $gGrEF$Text), {
649
+ size: 1,
650
+ muted: true,
651
+ align: "center",
652
+ children: loadingMessage
653
+ })
654
+ ]
655
+ }),
656
+ /*#__PURE__*/ (0, $gGrEF$jsx)($1d4b493cde06506a$export$a829527ff4e4114a, {
657
+ style: {
658
+ visibility: "hidden"
659
+ },
660
+ ref: contentRef,
661
+ id: widgetId
662
+ })
663
+ ]
664
+ })
665
+ });
666
+ }
667
+
668
+
669
+ const $df9eabe9bda49ea8$export$d69fa36e91cd4a95 = (0, $gGrEF$createPlugin)({
670
+ name: "cloudinary-schema",
671
+ schema: {
672
+ types: [
673
+ (0, $4a7defd9e77e9634$export$3ed2e98ebe80ce58),
674
+ (0, $ebc9980d601ccc9b$export$26e4781cb23ffde8)
675
+ ]
676
+ }
677
+ });
678
+ const $df9eabe9bda49ea8$export$f3531f7607fb0a50 = {
679
+ name: "cloudinary-image",
680
+ title: "Cloudinary",
681
+ icon: (0, $5737bc33d6712f10$export$41acf4847aa33418),
682
+ component: (0, $1d4b493cde06506a$export$d86b01636c6a833b)
683
+ };
684
+ const $df9eabe9bda49ea8$export$4e2fc220d417fe6a = (0, $gGrEF$createPlugin)({
685
+ name: "cloudinart-asset-source",
686
+ form: {
687
+ image: {
688
+ assetSources: [
689
+ $df9eabe9bda49ea8$export$f3531f7607fb0a50
690
+ ]
691
+ }
692
+ }
693
+ });
694
+
695
+
696
+ export {$df9eabe9bda49ea8$export$d69fa36e91cd4a95 as cloudinarySchemaPlugin, $df9eabe9bda49ea8$export$f3531f7607fb0a50 as cloudinaryImageSource, $df9eabe9bda49ea8$export$4e2fc220d417fe6a as cloudinaryAssetSourcePlugin, $4a7defd9e77e9634$export$3ed2e98ebe80ce58 as cloudinaryAssetSchema, $ebc9980d601ccc9b$export$26e4781cb23ffde8 as cloudinaryAssetDerivedSchema};
697
+ //# sourceMappingURL=index.js.map