sanity-plugin-cloudinary 1.0.0 → 1.0.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.
- package/LICENSE +1 -1
- package/lib/{src/index.d.ts → index.d.ts} +0 -0
- package/lib/index.esm.js +605 -1
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +620 -1
- package/lib/index.js.map +1 -1
- package/package.json +38 -32
- package/src/components/AssetDiff.tsx +1 -1
- package/src/components/AssetPreview.tsx +11 -6
- package/src/components/VideoPlayer.tsx +16 -54
- package/src/components/WidgetInput.tsx +1 -1
- package/src/schema/cloudinaryAsset.ts +5 -2
- package/src/utils.ts +1 -1
package/lib/index.js
CHANGED
|
@@ -1,2 +1,621 @@
|
|
|
1
|
-
"use strict";var e,n;function t(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var c=Object.getOwnPropertySymbols(e);n&&(c=c.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,c)}return t}function c(e){for(var n=1;n<arguments.length;n++){var c=null!=arguments[n]?arguments[n]:{};n%2?t(Object(c),!0).forEach((function(n){r(e,n,c[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(c)):t(Object(c)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(c,n))}))}return e}function r(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function i(e,n){return n||(n=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(n)}}))}Object.defineProperty(exports,"__esModule",{value:!0});var l=require("react/jsx-runtime"),s=require("react"),o=require("sanity"),a=require("@sanity/ui"),u=require("@sanity/icons"),d=require("styled-components"),p=require("video.js"),y=require("nanoid"),h=require("@sanity/studio-secrets");function m(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var f=m(s),v=m(d),j=m(p);class x extends f.default.Component{componentDidMount(){const{src:e}=this.props;this.player=j.default(this.videoNode,{sources:[{src:e}],controls:!0})}componentWillUnmount(){this.player&&this.player.dispose()}render(){const{kind:e}=this.props;return l.jsxs("div",{children:[l.jsx("link",{href:"https://vjs.zencdn.net/7.8.4/video-js.css",rel:"stylesheet"}),l.jsx("div",{"data-vjs-player":!0,children:l.jsx("video",{onClick:e=>e.stopPropagation(),style:"diff"===e?{position:"relative"}:{},className:{player:"video-js vjs-16-9 vjs-big-play-centered",diff:"video-js vjs-layout-tiny vjs-fluid"}[e],ref:e=>{e&&(this.videoNode=e)}})})]})}}const g="https://media-library.cloudinary.com/global/all.js";function b(e){if(e.derived&&e.derived.length>0){const[n]=e.derived;return n.secure_url?n.secure_url:n.url}return e.secure_url?e.secure_url:e.url}function _(e,n){const t=document.getElementById("damWidget");if(!t){const t=document.createElement("script");t.src=e,t.id="damWidget",document.body.appendChild(t),t.onload=()=>!n||n()}return!t||!n||n()}function C(e){const{resource_type:n,public_id:t,type:c}=e;return btoa(JSON.stringify({public_id:t,resource_type:n,type:c}))}function w(e){return"".concat(e.public_id.split("/").slice(-1)[0],".").concat(e.format)}const S=e=>{let{value:n,layout:t}=e;const c=n&&b(n);return n&&c?"video"===n.resource_type?l.jsx(a.Box,{children:l.jsx(x,{src:c,kind:"player"})}):l.jsx(a.Box,{children:l.jsx("img",{alt:"preview",src:c,style:{maxWidth:"default"===t?"80px":"100%",height:"auto"}})}):null},k=v.default.div(e||(e=i(["\n position: relative;\n display: block;\n font-size: 0.8em;\n transform: translate(0%, -10%);\n"]))),O=e=>{const{onChange:n,readOnly:t,value:c,openMediaSelector:r}=e,i=s.useCallback((()=>{n(o.PatchEvent.from([o.unset()]))}),[n]);return l.jsxs(a.Stack,{children:[l.jsx(k,{children:l.jsx(a.Flex,{flex:1,justify:"flex-end",children:l.jsx(a.Button,{color:"primary",icon:u.PlugIcon,mode:"bleed",title:"Configure",onClick:e.onSetup,tabIndex:1})})}),l.jsx(a.Flex,{style:{textAlign:"center"},marginBottom:2,children:l.jsx(S,{value:c})}),l.jsxs(a.Grid,{gap:1,style:{gridTemplateColumns:"repeat(auto-fit, minmax(100px, 1fr))"},children:[l.jsx(a.Button,{disabled:t,mode:"ghost",title:"Select an asset",tone:"default",onClick:r,text:"Select…"}),l.jsx(a.Button,{disabled:t||!c,tone:"critical",mode:"ghost",title:"Remove asset",text:"Remove",onClick:i})]})]})},P=[{key:"cloudName",title:"Cloud name",description:""},{key:"apiKey",title:"API key",description:""}],D=e=>l.jsx(h.SettingsView,{title:"Cloudinary config",namespace:"cloudinary",keys:P,onClose:e.onClose}),B=e=>{let{value:n}=e;if(!n)return null;const t=b(n);return"video"===n.resource_type?l.jsx("section",{style:{display:"flex",flexWrap:"wrap",justifyContent:"space-between"},children:l.jsx(x,{src:t,kind:"diff"})}):l.jsx("img",{alt:"preview",src:t,style:{maxWidth:"100%",height:"auto"}})},M=o.defineType(c(c({type:"object",name:"cloudinary.asset",fields:[{type:"string",name:"public_id"},{type:"string",name:"resource_type"},{type:"string",name:"type"},{type:"string",name:"format"},{type:"number",name:"version"},{type:"url",name:"url"},{type:"url",name:"secure_url"},{type:"number",name:"width"},{type:"number",name:"height"},{type:"number",name:"bytes"},{type:"number",name:"duration"},{type:"array",name:"tags",of:[{type:"string"}]},{type:"datetime",name:"created_at"},{type:"array",name:"derived",of:[{type:"cloudinary.assetDerived"}]},{type:"string",name:"access_mode"}]},{components:{input:e=>{const[n,t]=s.useState(!1),{secrets:r}=h.useSecrets("cloudinary"),{onChange:i,schemaType:a}=e,u=e.value||void 0,d=s.useCallback((e=>{const[n]=e.assets;n&&i(o.PatchEvent.from([o.set(Object.assign(c({_type:a.name,_version:1},(null==u?void 0:u._key)?{_key:u._key}:{_key:y.nanoid()}),n))]))}),[i,a,null==u?void 0:u._key]),p=r?()=>{return e=r.cloudName,n=r.apiKey,t=!1,c=d,i=u,void _(g,(()=>{const r={cloud_name:e,api_key:n,insert_caption:"Select",multiple:t};i&&(r.asset={public_id:i.public_id,type:i.type,resource_type:i.resource_type}),window.cloudinary.openMediaLibrary(r,{insertHandler:c})}));var e,n,t,c,i}:()=>t(!0);return l.jsxs(l.Fragment,{children:[n&&l.jsx(D,{onClose:()=>t(!1)}),l.jsx(O,c({onSetup:()=>t(!0),openMediaSelector:p},e))]})},diff:e=>{let{diff:n,schemaType:t}=e;return l.jsx(o.DiffFromTo,{diff:n,schemaType:t,previewComponent:B})},preview:S}}),{},{preview:{select:{url:"url",resource_type:"resource_type",derived:"derived.0.url"},prepare(e){let{url:n,derived:t,resource_type:c}=e;return{title:n,resource_type:c,url:t||n}}}})),E=o.defineType({type:"object",name:"cloudinary.assetDerived",fields:[{type:"string",name:"raw_transformation"},{type:"url",name:"url"},{type:"url",name:"secure_url"}]});const T=v.default.div(n||(n=i(["\n height: 70vh;\n"])));const F=o.definePlugin({name:"cloudinary-schema",schema:{types:[M,E]}}),N={name:"cloudinary-image",title:"Cloudinary",icon:function(){return l.jsx("svg",{version:"1.1",id:"Layer_1",x:"0px",y:"0px",width:"1em",height:"1em",viewBox:"0 0 141.732 141.747",enableBackground:"new 0 0 141.732 141.747",children:l.jsxs("g",{children:[l.jsx("path",{fill:"#0071CE",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\n 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\n 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\n 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\n 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\n 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\n c0,10.693-6.934,20.146-17.253,23.523C116.382,109.18,115.98,109.242,115.585,109.242z"}),l.jsx("path",{fill:"#DC8327",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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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"}),l.jsx("path",{fill:"#F4B21B",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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n C84.267,111.345,84.112,111.121,83.889,111.02z"}),l.jsx("path",{fill:"#F2D864",d:"M110.667,111.02l-0.002-0.001c-0.001,0-0.002-0.001-0.003-0.001h-0.001\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n C111.045,111.345,110.889,111.121,110.667,111.02z"})]})})},component:function(e){const{onClose:n}=e,[t,c]=s.useState("Loading Cloudinary Media Libary"),r=s.useRef(),i=s.useRef(null),{secrets:o}=h.useSecrets("cloudinary"),d=null==o?void 0:o.cloudName,p=null==o?void 0:o.apiKey,[y]=s.useState((()=>"cloundinaryWidget-".concat(Date.now()))),[m,f]=s.useState(!1),v=s.useRef(e);s.useEffect((()=>{v.current=e}),[e]);const j=s.useCallback((()=>{r.current&&r.current.hide(),n()}),[n,r]);s.useEffect((()=>{d&&p&&(e=>{let{cloudName:n,apiKey:t,inlineContainer:c,libraryCreated:r,insertHandler:i}=e;_(g,(()=>{const e={cloud_name:n,api_key:t,insert_caption:"Select",inline_container:c,remove_header:!0};r(window.cloudinary.createMediaLibrary(e,{insertHandler:i}))}))})({cloudName:d,apiKey:p,inlineContainer:"#".concat(y),libraryCreated:e=>{r.current=e;const n=v.current.selectedAssets,t=n?n[0]:null,l=i.current&&i.current.firstChild;if(l&&l instanceof HTMLIFrameElement){let n;c(void 0),"single"===v.current.selectionType&&t&&t.source&&t.source.id&&(n=function(e){let n;try{n=JSON.parse(atob(e))}catch(e){}return n}(t.source.id));const r=n?{path:n.public_id.split("/").slice(0,-1).join("/"),resource_type:"image"}:{path:"",resource_type:"image"};e&&i.current&&(e.show({folder:r,asset:n}),i.current.style.visibility="visible")}},insertHandler:e=>{let{assets:n}=e;if(!r.current)return;const t=n.filter((e=>"image"===e.resource_type));if(0===t.length)throw new Error("The selection did not contain any images.");r.current.hide(),v.current.onSelect(t.map((e=>({kind:"url",value:e.derived&&e.derived[0]?e.derived[0].secure_url:e.secure_url,assetDocumentProps:{_type:"sanity.imageAsset",originalFilename:w(e),source:{id:C(e),name:"cloudinary:".concat(d)}}}))))}})}),[d,p,y]);const x=p&&d;return l.jsx(a.Dialog,{id:"cloudinary-asset-source",header:"Select image from Cloudinary",onClose:j,open:!0,width:4,children:l.jsxs(a.Box,{padding:4,children:[m&&l.jsx(D,{onClose:()=>f(!1)}),l.jsx(a.Flex,{flex:1,justify:"flex-end",children:l.jsx(a.Button,{color:"primary",icon:u.PlugIcon,mode:"bleed",title:"Configure",onClick:()=>f(!0),tabIndex:1,text:x?void 0:"Configure Cloudinary plugin"})}),x&&t&&l.jsxs(a.Stack,{space:3,children:[l.jsx(a.Flex,{align:"center",justify:"center",children:l.jsx(a.Spinner,{muted:!0})}),l.jsx(a.Text,{size:1,muted:!0,align:"center",children:t})]}),l.jsx(T,{style:{visibility:"hidden"},ref:i,id:y})]})})}},q=o.definePlugin({name:"cloudinart-asset-source",form:{image:{assetSources:[N]}}});exports.cloudinaryAssetDerivedSchema=E,exports.cloudinaryAssetSchema=M,exports.cloudinaryAssetSourcePlugin=q,exports.cloudinaryImageSource=N,exports.cloudinarySchemaPlugin=F;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _templateObject, _templateObject2;
|
|
4
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
5
|
+
Object.defineProperty(exports, '__esModule', {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
9
|
+
var react = require('react');
|
|
10
|
+
var sanity = require('sanity');
|
|
11
|
+
var ui = require('@sanity/ui');
|
|
12
|
+
var icons = require('@sanity/icons');
|
|
13
|
+
var styled = require('styled-components');
|
|
14
|
+
var nanoid = require('nanoid');
|
|
15
|
+
var studioSecrets = require('@sanity/studio-secrets');
|
|
16
|
+
function _interopDefaultCompat(e) {
|
|
17
|
+
return e && typeof e === 'object' && 'default' in e ? e : {
|
|
18
|
+
default: e
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
var styled__default = /*#__PURE__*/_interopDefaultCompat(styled);
|
|
22
|
+
function VideoPlayer(props) {
|
|
23
|
+
const {
|
|
24
|
+
src
|
|
25
|
+
} = props;
|
|
26
|
+
const style = {
|
|
27
|
+
width: "100%",
|
|
28
|
+
height: "auto"
|
|
29
|
+
};
|
|
30
|
+
return /* @__PURE__ */jsxRuntime.jsx("video", {
|
|
31
|
+
controls: true,
|
|
32
|
+
style,
|
|
33
|
+
children: /* @__PURE__ */jsxRuntime.jsx("source", {
|
|
34
|
+
src,
|
|
35
|
+
type: "video/mp4"
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const widgetSrc = "https://media-library.cloudinary.com/global/all.js";
|
|
40
|
+
function assetUrl(asset) {
|
|
41
|
+
if (asset.derived && asset.derived.length > 0) {
|
|
42
|
+
const [derived] = asset.derived;
|
|
43
|
+
if (derived.secure_url) {
|
|
44
|
+
return derived.secure_url;
|
|
45
|
+
}
|
|
46
|
+
return derived.url;
|
|
47
|
+
}
|
|
48
|
+
if (asset.secure_url) {
|
|
49
|
+
return asset.secure_url;
|
|
50
|
+
}
|
|
51
|
+
return asset.url;
|
|
52
|
+
}
|
|
53
|
+
const openMediaSelector = (cloudName, apiKey, multiple, insertHandler, selectedAsset) => {
|
|
54
|
+
loadJS(widgetSrc, () => {
|
|
55
|
+
const options = {
|
|
56
|
+
cloud_name: cloudName,
|
|
57
|
+
api_key: apiKey,
|
|
58
|
+
insert_caption: "Select",
|
|
59
|
+
multiple
|
|
60
|
+
};
|
|
61
|
+
if (selectedAsset) {
|
|
62
|
+
options.asset = {
|
|
63
|
+
public_id: selectedAsset.public_id,
|
|
64
|
+
type: selectedAsset.type,
|
|
65
|
+
resource_type: selectedAsset.resource_type
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
window.cloudinary.openMediaLibrary(options, {
|
|
69
|
+
insertHandler
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
const createMediaLibrary = _ref => {
|
|
74
|
+
let {
|
|
75
|
+
cloudName,
|
|
76
|
+
apiKey,
|
|
77
|
+
inlineContainer,
|
|
78
|
+
libraryCreated,
|
|
79
|
+
insertHandler
|
|
80
|
+
} = _ref;
|
|
81
|
+
loadJS(widgetSrc, () => {
|
|
82
|
+
const options = {
|
|
83
|
+
cloud_name: cloudName,
|
|
84
|
+
api_key: apiKey,
|
|
85
|
+
insert_caption: "Select",
|
|
86
|
+
inline_container: inlineContainer,
|
|
87
|
+
remove_header: true
|
|
88
|
+
};
|
|
89
|
+
libraryCreated(window.cloudinary.createMediaLibrary(options, {
|
|
90
|
+
insertHandler
|
|
91
|
+
}));
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
function loadJS(url, callback) {
|
|
95
|
+
const existingScript = document.getElementById("damWidget");
|
|
96
|
+
if (!existingScript) {
|
|
97
|
+
const script = document.createElement("script");
|
|
98
|
+
script.src = url;
|
|
99
|
+
script.id = "damWidget";
|
|
100
|
+
document.body.appendChild(script);
|
|
101
|
+
script.onload = () => {
|
|
102
|
+
if (callback) {
|
|
103
|
+
return callback();
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
if (existingScript && callback) {
|
|
109
|
+
return callback();
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
function encodeSourceId(asset) {
|
|
114
|
+
const {
|
|
115
|
+
resource_type,
|
|
116
|
+
public_id,
|
|
117
|
+
type
|
|
118
|
+
} = asset;
|
|
119
|
+
return btoa(JSON.stringify({
|
|
120
|
+
public_id,
|
|
121
|
+
resource_type,
|
|
122
|
+
type
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
function encodeFilename(asset) {
|
|
126
|
+
return "".concat(asset.public_id.split("/").slice(-1)[0], ".").concat(asset.format);
|
|
127
|
+
}
|
|
128
|
+
function decodeSourceId(sourceId) {
|
|
129
|
+
let sourceIdDecoded;
|
|
130
|
+
try {
|
|
131
|
+
sourceIdDecoded = JSON.parse(atob(sourceId));
|
|
132
|
+
} catch (err) {}
|
|
133
|
+
return sourceIdDecoded;
|
|
134
|
+
}
|
|
135
|
+
const AssetPreview = _ref2 => {
|
|
136
|
+
let {
|
|
137
|
+
value,
|
|
138
|
+
layout
|
|
139
|
+
} = _ref2;
|
|
140
|
+
const url = value && assetUrl(value);
|
|
141
|
+
if (!value || !url) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
switch (value.resource_type) {
|
|
145
|
+
case "video":
|
|
146
|
+
return /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
|
|
147
|
+
align: "center",
|
|
148
|
+
style: {
|
|
149
|
+
maxWidth: layout === "default" ? "80px" : "100%"
|
|
150
|
+
},
|
|
151
|
+
children: /* @__PURE__ */jsxRuntime.jsx(VideoPlayer, {
|
|
152
|
+
src: url,
|
|
153
|
+
kind: "player"
|
|
154
|
+
})
|
|
155
|
+
});
|
|
156
|
+
default:
|
|
157
|
+
return /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
|
|
158
|
+
align: "center",
|
|
159
|
+
children: /* @__PURE__ */jsxRuntime.jsx("img", {
|
|
160
|
+
alt: "preview",
|
|
161
|
+
src: url,
|
|
162
|
+
style: {
|
|
163
|
+
maxWidth: layout === "default" ? "80px" : "100%",
|
|
164
|
+
height: "auto"
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
const SetupButtonContainer = styled__default.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n display: block;\n font-size: 0.8em;\n transform: translate(0%, -10%);\n"])));
|
|
171
|
+
const WidgetInput = props => {
|
|
172
|
+
const {
|
|
173
|
+
onChange,
|
|
174
|
+
readOnly,
|
|
175
|
+
value,
|
|
176
|
+
openMediaSelector
|
|
177
|
+
} = props;
|
|
178
|
+
const removeValue = react.useCallback(() => {
|
|
179
|
+
onChange(sanity.PatchEvent.from([sanity.unset()]));
|
|
180
|
+
}, [onChange]);
|
|
181
|
+
return /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
|
|
182
|
+
children: [/* @__PURE__ */jsxRuntime.jsx(SetupButtonContainer, {
|
|
183
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
|
|
184
|
+
flex: 1,
|
|
185
|
+
justify: "flex-end",
|
|
186
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
187
|
+
color: "primary",
|
|
188
|
+
icon: icons.PlugIcon,
|
|
189
|
+
mode: "bleed",
|
|
190
|
+
title: "Configure",
|
|
191
|
+
onClick: props.onSetup,
|
|
192
|
+
tabIndex: 1
|
|
193
|
+
})
|
|
194
|
+
})
|
|
195
|
+
}), /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
|
|
196
|
+
style: {
|
|
197
|
+
textAlign: "center",
|
|
198
|
+
width: "100%"
|
|
199
|
+
},
|
|
200
|
+
marginBottom: 2,
|
|
201
|
+
children: /* @__PURE__ */jsxRuntime.jsx(AssetPreview, {
|
|
202
|
+
value
|
|
203
|
+
})
|
|
204
|
+
}), /* @__PURE__ */jsxRuntime.jsxs(ui.Grid, {
|
|
205
|
+
gap: 1,
|
|
206
|
+
style: {
|
|
207
|
+
gridTemplateColumns: "repeat(auto-fit, minmax(100px, 1fr))"
|
|
208
|
+
},
|
|
209
|
+
children: [/* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
210
|
+
disabled: readOnly,
|
|
211
|
+
mode: "ghost",
|
|
212
|
+
title: "Select an asset",
|
|
213
|
+
tone: "default",
|
|
214
|
+
onClick: openMediaSelector,
|
|
215
|
+
text: "Select\u2026"
|
|
216
|
+
}), /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
217
|
+
disabled: readOnly || !value,
|
|
218
|
+
tone: "critical",
|
|
219
|
+
mode: "ghost",
|
|
220
|
+
title: "Remove asset",
|
|
221
|
+
text: "Remove",
|
|
222
|
+
onClick: removeValue
|
|
223
|
+
})]
|
|
224
|
+
})]
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
const pluginConfigKeys = [{
|
|
228
|
+
key: "cloudName",
|
|
229
|
+
title: "Cloud name",
|
|
230
|
+
description: ""
|
|
231
|
+
}, {
|
|
232
|
+
key: "apiKey",
|
|
233
|
+
title: "API key",
|
|
234
|
+
description: ""
|
|
235
|
+
}];
|
|
236
|
+
const namespace = "cloudinary";
|
|
237
|
+
const SecretsConfigView = props => {
|
|
238
|
+
return /* @__PURE__ */jsxRuntime.jsx(studioSecrets.SettingsView, {
|
|
239
|
+
title: "Cloudinary config",
|
|
240
|
+
namespace,
|
|
241
|
+
keys: pluginConfigKeys,
|
|
242
|
+
onClose: props.onClose
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
const CloudinaryInput = props => {
|
|
246
|
+
const [showSettings, setShowSettings] = react.useState(false);
|
|
247
|
+
const {
|
|
248
|
+
secrets
|
|
249
|
+
} = studioSecrets.useSecrets(namespace);
|
|
250
|
+
const {
|
|
251
|
+
onChange,
|
|
252
|
+
schemaType: type
|
|
253
|
+
} = props;
|
|
254
|
+
const value = props.value || void 0;
|
|
255
|
+
const handleSelect = react.useCallback(payload => {
|
|
256
|
+
const [asset] = payload.assets;
|
|
257
|
+
if (!asset) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
onChange(sanity.PatchEvent.from([sanity.set(Object.assign({
|
|
261
|
+
_type: type.name,
|
|
262
|
+
_version: 1,
|
|
263
|
+
...((value == null ? void 0 : value._key) ? {
|
|
264
|
+
_key: value._key
|
|
265
|
+
} : {
|
|
266
|
+
_key: nanoid.nanoid()
|
|
267
|
+
})
|
|
268
|
+
}, asset))]));
|
|
269
|
+
}, [onChange, type, value == null ? void 0 : value._key]);
|
|
270
|
+
const action = secrets ? () => openMediaSelector(secrets.cloudName, secrets.apiKey, false,
|
|
271
|
+
// single selection
|
|
272
|
+
handleSelect, value) : () => setShowSettings(true);
|
|
273
|
+
return /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
274
|
+
children: [showSettings && /* @__PURE__ */jsxRuntime.jsx(SecretsConfigView, {
|
|
275
|
+
onClose: () => setShowSettings(false)
|
|
276
|
+
}), /* @__PURE__ */jsxRuntime.jsx(WidgetInput, {
|
|
277
|
+
onSetup: () => setShowSettings(true),
|
|
278
|
+
openMediaSelector: action,
|
|
279
|
+
...props
|
|
280
|
+
})]
|
|
281
|
+
});
|
|
282
|
+
};
|
|
283
|
+
const CloudinaryDiffPreview = _ref3 => {
|
|
284
|
+
let {
|
|
285
|
+
value
|
|
286
|
+
} = _ref3;
|
|
287
|
+
if (!value) {
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
const url = assetUrl(value);
|
|
291
|
+
if (value.resource_type === "video" && url) {
|
|
292
|
+
return /* @__PURE__ */jsxRuntime.jsx("section", {
|
|
293
|
+
style: {
|
|
294
|
+
display: "flex",
|
|
295
|
+
flexWrap: "wrap",
|
|
296
|
+
justifyContent: "space-between"
|
|
297
|
+
},
|
|
298
|
+
children: /* @__PURE__ */jsxRuntime.jsx(VideoPlayer, {
|
|
299
|
+
src: url,
|
|
300
|
+
kind: "diff"
|
|
301
|
+
})
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
return /* @__PURE__ */jsxRuntime.jsx("img", {
|
|
305
|
+
alt: "preview",
|
|
306
|
+
src: url,
|
|
307
|
+
style: {
|
|
308
|
+
maxWidth: "100%",
|
|
309
|
+
height: "auto"
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
const AssetDiff = _ref4 => {
|
|
314
|
+
let {
|
|
315
|
+
diff,
|
|
316
|
+
schemaType
|
|
317
|
+
} = _ref4;
|
|
318
|
+
return /* @__PURE__ */jsxRuntime.jsx(sanity.DiffFromTo, {
|
|
319
|
+
diff,
|
|
320
|
+
schemaType,
|
|
321
|
+
previewComponent: CloudinaryDiffPreview
|
|
322
|
+
});
|
|
323
|
+
};
|
|
324
|
+
const cloudinaryAssetSchema = sanity.defineType({
|
|
325
|
+
type: "object",
|
|
326
|
+
name: "cloudinary.asset",
|
|
327
|
+
fields: [{
|
|
328
|
+
type: "string",
|
|
329
|
+
name: "public_id"
|
|
330
|
+
}, {
|
|
331
|
+
type: "string",
|
|
332
|
+
name: "resource_type"
|
|
333
|
+
// "image", "?"
|
|
334
|
+
}, {
|
|
335
|
+
type: "string",
|
|
336
|
+
name: "type"
|
|
337
|
+
// "upload", "?"
|
|
338
|
+
}, {
|
|
339
|
+
type: "string",
|
|
340
|
+
name: "format"
|
|
341
|
+
// "jpg"
|
|
342
|
+
}, {
|
|
343
|
+
type: "number",
|
|
344
|
+
name: "version"
|
|
345
|
+
}, {
|
|
346
|
+
type: "url",
|
|
347
|
+
name: "url"
|
|
348
|
+
}, {
|
|
349
|
+
type: "url",
|
|
350
|
+
name: "secure_url"
|
|
351
|
+
}, {
|
|
352
|
+
type: "number",
|
|
353
|
+
name: "width"
|
|
354
|
+
}, {
|
|
355
|
+
type: "number",
|
|
356
|
+
name: "height"
|
|
357
|
+
}, {
|
|
358
|
+
type: "number",
|
|
359
|
+
name: "bytes"
|
|
360
|
+
}, {
|
|
361
|
+
type: "number",
|
|
362
|
+
name: "duration"
|
|
363
|
+
// can be null
|
|
364
|
+
}, {
|
|
365
|
+
type: "array",
|
|
366
|
+
name: "tags",
|
|
367
|
+
of: [{
|
|
368
|
+
type: "string"
|
|
369
|
+
}]
|
|
370
|
+
}, {
|
|
371
|
+
type: "datetime",
|
|
372
|
+
name: "created_at"
|
|
373
|
+
}, {
|
|
374
|
+
type: "array",
|
|
375
|
+
name: "derived",
|
|
376
|
+
of: [{
|
|
377
|
+
type: "cloudinary.assetDerived"
|
|
378
|
+
}]
|
|
379
|
+
}, {
|
|
380
|
+
type: "string",
|
|
381
|
+
name: "access_mode"
|
|
382
|
+
}
|
|
383
|
+
// context array of unknown content
|
|
384
|
+
// metadata array of unknown content
|
|
385
|
+
],
|
|
386
|
+
|
|
387
|
+
...{
|
|
388
|
+
components: {
|
|
389
|
+
input: CloudinaryInput,
|
|
390
|
+
diff: AssetDiff,
|
|
391
|
+
preview: AssetPreview
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
//TODO revert this change when rc.1 is released
|
|
395
|
+
preview: {
|
|
396
|
+
select: {
|
|
397
|
+
url: "url",
|
|
398
|
+
resource_type: "resource_type",
|
|
399
|
+
derived: "derived.0.url"
|
|
400
|
+
},
|
|
401
|
+
prepare(_ref5) {
|
|
402
|
+
let {
|
|
403
|
+
url,
|
|
404
|
+
derived,
|
|
405
|
+
resource_type
|
|
406
|
+
} = _ref5;
|
|
407
|
+
return {
|
|
408
|
+
title: url,
|
|
409
|
+
value: {
|
|
410
|
+
title: url,
|
|
411
|
+
resource_type,
|
|
412
|
+
url: derived || url
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
const cloudinaryAssetDerivedSchema = sanity.defineType({
|
|
419
|
+
type: "object",
|
|
420
|
+
name: "cloudinary.assetDerived",
|
|
421
|
+
fields: [{
|
|
422
|
+
type: "string",
|
|
423
|
+
name: "raw_transformation"
|
|
424
|
+
}, {
|
|
425
|
+
type: "url",
|
|
426
|
+
name: "url"
|
|
427
|
+
}, {
|
|
428
|
+
type: "url",
|
|
429
|
+
name: "secure_url"
|
|
430
|
+
}]
|
|
431
|
+
});
|
|
432
|
+
function CloudinaryIcon() {
|
|
433
|
+
return /* @__PURE__ */jsxRuntime.jsx("svg", {
|
|
434
|
+
version: "1.1",
|
|
435
|
+
id: "Layer_1",
|
|
436
|
+
x: "0px",
|
|
437
|
+
y: "0px",
|
|
438
|
+
width: "1em",
|
|
439
|
+
height: "1em",
|
|
440
|
+
viewBox: "0 0 141.732 141.747",
|
|
441
|
+
enableBackground: "new 0 0 141.732 141.747",
|
|
442
|
+
children: /* @__PURE__ */jsxRuntime.jsxs("g", {
|
|
443
|
+
children: [/* @__PURE__ */jsxRuntime.jsx("path", {
|
|
444
|
+
fill: "#0071CE",
|
|
445
|
+
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\n 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\n 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\n 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\n 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\n 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\n c0,10.693-6.934,20.146-17.253,23.523C116.382,109.18,115.98,109.242,115.585,109.242z"
|
|
446
|
+
}), /* @__PURE__ */jsxRuntime.jsx("path", {
|
|
447
|
+
fill: "#DC8327",
|
|
448
|
+
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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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"
|
|
449
|
+
}), /* @__PURE__ */jsxRuntime.jsx("path", {
|
|
450
|
+
fill: "#F4B21B",
|
|
451
|
+
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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n C84.267,111.345,84.112,111.121,83.889,111.02z"
|
|
452
|
+
}), /* @__PURE__ */jsxRuntime.jsx("path", {
|
|
453
|
+
fill: "#F2D864",
|
|
454
|
+
d: "M110.667,111.02l-0.002-0.001c-0.001,0-0.002-0.001-0.003-0.001h-0.001\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n 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\n C111.045,111.345,110.889,111.121,110.667,111.02z"
|
|
455
|
+
})]
|
|
456
|
+
})
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
const Widget = styled__default.default.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n height: 70vh;\n"])));
|
|
460
|
+
function CloudinaryAssetSource(props) {
|
|
461
|
+
const {
|
|
462
|
+
onClose
|
|
463
|
+
} = props;
|
|
464
|
+
const [loadingMessage, setLoadingMessage] = react.useState("Loading Cloudinary Media Libary");
|
|
465
|
+
const library = react.useRef();
|
|
466
|
+
const contentRef = react.useRef(null);
|
|
467
|
+
const {
|
|
468
|
+
secrets
|
|
469
|
+
} = studioSecrets.useSecrets(namespace);
|
|
470
|
+
const cloudName = secrets == null ? void 0 : secrets.cloudName;
|
|
471
|
+
const apiKey = secrets == null ? void 0 : secrets.apiKey;
|
|
472
|
+
const [widgetId] = react.useState(() => "cloundinaryWidget-".concat(Date.now()));
|
|
473
|
+
const [showSettings, setShowSettings] = react.useState(false);
|
|
474
|
+
const propsRef = react.useRef(props);
|
|
475
|
+
react.useEffect(() => {
|
|
476
|
+
propsRef.current = props;
|
|
477
|
+
}, [props]);
|
|
478
|
+
const handleClose = react.useCallback(() => {
|
|
479
|
+
if (library.current) {
|
|
480
|
+
library.current.hide();
|
|
481
|
+
}
|
|
482
|
+
onClose();
|
|
483
|
+
}, [onClose, library]);
|
|
484
|
+
react.useEffect(() => {
|
|
485
|
+
if (!cloudName || !apiKey) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
createMediaLibrary({
|
|
489
|
+
cloudName,
|
|
490
|
+
apiKey,
|
|
491
|
+
inlineContainer: "#".concat(widgetId),
|
|
492
|
+
libraryCreated: lib => {
|
|
493
|
+
library.current = lib;
|
|
494
|
+
const selectedAssets = propsRef.current.selectedAssets;
|
|
495
|
+
const firstSelectedAsset = selectedAssets ? selectedAssets[0] : null;
|
|
496
|
+
const iframe = contentRef.current && contentRef.current.firstChild;
|
|
497
|
+
if (iframe && iframe instanceof HTMLIFrameElement) {
|
|
498
|
+
setLoadingMessage(void 0);
|
|
499
|
+
let asset;
|
|
500
|
+
if (propsRef.current.selectionType === "single" && firstSelectedAsset && firstSelectedAsset.source && firstSelectedAsset.source.id) {
|
|
501
|
+
asset = decodeSourceId(firstSelectedAsset.source.id);
|
|
502
|
+
}
|
|
503
|
+
const folder = asset ? {
|
|
504
|
+
path: asset.public_id.split("/").slice(0, -1).join("/"),
|
|
505
|
+
resource_type: "image"
|
|
506
|
+
} : {
|
|
507
|
+
path: "",
|
|
508
|
+
resource_type: "image"
|
|
509
|
+
};
|
|
510
|
+
if (lib && contentRef.current) {
|
|
511
|
+
lib.show({
|
|
512
|
+
folder,
|
|
513
|
+
asset
|
|
514
|
+
});
|
|
515
|
+
contentRef.current.style.visibility = "visible";
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
},
|
|
519
|
+
insertHandler: _ref6 => {
|
|
520
|
+
let {
|
|
521
|
+
assets
|
|
522
|
+
} = _ref6;
|
|
523
|
+
if (!library.current) {
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
const imageAssets = assets.filter(asset => asset.resource_type === "image");
|
|
527
|
+
if (imageAssets.length === 0) {
|
|
528
|
+
throw new Error("The selection did not contain any images.");
|
|
529
|
+
}
|
|
530
|
+
library.current.hide();
|
|
531
|
+
propsRef.current.onSelect(imageAssets.map(asset => {
|
|
532
|
+
const url = asset.derived && asset.derived[0] ? asset.derived[0].secure_url : asset.secure_url;
|
|
533
|
+
return {
|
|
534
|
+
kind: "url",
|
|
535
|
+
value: url,
|
|
536
|
+
assetDocumentProps: {
|
|
537
|
+
_type: "sanity.imageAsset",
|
|
538
|
+
originalFilename: encodeFilename(asset),
|
|
539
|
+
source: {
|
|
540
|
+
id: encodeSourceId(asset),
|
|
541
|
+
name: "cloudinary:".concat(cloudName)
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
}));
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
}, [cloudName, apiKey, widgetId]);
|
|
549
|
+
const hasConfig = apiKey && cloudName;
|
|
550
|
+
return /* @__PURE__ */jsxRuntime.jsx(ui.Dialog, {
|
|
551
|
+
id: "cloudinary-asset-source",
|
|
552
|
+
header: "Select image from Cloudinary",
|
|
553
|
+
onClose: handleClose,
|
|
554
|
+
open: true,
|
|
555
|
+
width: 4,
|
|
556
|
+
children: /* @__PURE__ */jsxRuntime.jsxs(ui.Box, {
|
|
557
|
+
padding: 4,
|
|
558
|
+
children: [showSettings && /* @__PURE__ */jsxRuntime.jsx(SecretsConfigView, {
|
|
559
|
+
onClose: () => setShowSettings(false)
|
|
560
|
+
}), /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
|
|
561
|
+
flex: 1,
|
|
562
|
+
justify: "flex-end",
|
|
563
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
564
|
+
color: "primary",
|
|
565
|
+
icon: icons.PlugIcon,
|
|
566
|
+
mode: "bleed",
|
|
567
|
+
title: "Configure",
|
|
568
|
+
onClick: () => setShowSettings(true),
|
|
569
|
+
tabIndex: 1,
|
|
570
|
+
text: hasConfig ? void 0 : "Configure Cloudinary plugin"
|
|
571
|
+
})
|
|
572
|
+
}), hasConfig && loadingMessage && /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
|
|
573
|
+
space: 3,
|
|
574
|
+
children: [/* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
|
|
575
|
+
align: "center",
|
|
576
|
+
justify: "center",
|
|
577
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Spinner, {
|
|
578
|
+
muted: true
|
|
579
|
+
})
|
|
580
|
+
}), /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
|
|
581
|
+
size: 1,
|
|
582
|
+
muted: true,
|
|
583
|
+
align: "center",
|
|
584
|
+
children: loadingMessage
|
|
585
|
+
})]
|
|
586
|
+
}), /* @__PURE__ */jsxRuntime.jsx(Widget, {
|
|
587
|
+
style: {
|
|
588
|
+
visibility: "hidden"
|
|
589
|
+
},
|
|
590
|
+
ref: contentRef,
|
|
591
|
+
id: widgetId
|
|
592
|
+
})]
|
|
593
|
+
})
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
const cloudinarySchemaPlugin = sanity.definePlugin({
|
|
597
|
+
name: "cloudinary-schema",
|
|
598
|
+
schema: {
|
|
599
|
+
types: [cloudinaryAssetSchema, cloudinaryAssetDerivedSchema]
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
const cloudinaryImageSource = {
|
|
603
|
+
name: "cloudinary-image",
|
|
604
|
+
title: "Cloudinary",
|
|
605
|
+
icon: CloudinaryIcon,
|
|
606
|
+
component: CloudinaryAssetSource
|
|
607
|
+
};
|
|
608
|
+
const cloudinaryAssetSourcePlugin = sanity.definePlugin({
|
|
609
|
+
name: "cloudinart-asset-source",
|
|
610
|
+
form: {
|
|
611
|
+
image: {
|
|
612
|
+
assetSources: [cloudinaryImageSource]
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
exports.cloudinaryAssetDerivedSchema = cloudinaryAssetDerivedSchema;
|
|
617
|
+
exports.cloudinaryAssetSchema = cloudinaryAssetSchema;
|
|
618
|
+
exports.cloudinaryAssetSourcePlugin = cloudinaryAssetSourcePlugin;
|
|
619
|
+
exports.cloudinaryImageSource = cloudinaryImageSource;
|
|
620
|
+
exports.cloudinarySchemaPlugin = cloudinarySchemaPlugin;
|
|
2
621
|
//# sourceMappingURL=index.js.map
|