slice-machine-ui 2.20.3 → 2.20.4-alpha.jp-figma-to-slice-login-issue.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/out/404.html +1 -1
- package/out/_next/static/chunks/633-dcaa16aa381f8980.js +1 -0
- package/out/_next/static/chunks/pages/{_app-e05b813938e03558.js → _app-06554710922d81e3.js} +1 -1
- package/out/_next/static/{UHKch3IjklJSCLLn7XwOF → ljmoBvM8WSwJza0pcMtek}/_buildManifest.js +1 -1
- package/out/changelog.html +1 -1
- package/out/changes.html +1 -1
- package/out/custom-types/[customTypeId].html +1 -1
- package/out/custom-types.html +1 -1
- package/out/index.html +1 -1
- package/out/labs.html +1 -1
- package/out/page-types/[pageTypeId].html +1 -1
- package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
- package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
- package/out/slices.html +1 -1
- package/package.json +5 -4
- package/src/features/customTypes/customTypesBuilder/CreateSliceFromImageModal/CreateSliceFromImageModal.tsx +9 -3
- package/out/_next/static/chunks/633-f3f030e76fa70a4d.js +0 -1
- /package/out/_next/static/{UHKch3IjklJSCLLn7XwOF → ljmoBvM8WSwJza0pcMtek}/_ssgManifest.js +0 -0
package/out/404.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<!DOCTYPE html><html><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="/_next/static/css/bc89f2cd4e4781f5.css" as="style"/><link rel="stylesheet" href="/_next/static/css/bc89f2cd4e4781f5.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="/_next/static/chunks/polyfills-42372ed130431b0a.js"></script><script src="/_next/static/chunks/webpack-24ddb02bea621501.js" defer=""></script><script src="/_next/static/chunks/framework-ab7ddb551c23d05a.js" defer=""></script><script src="/_next/static/chunks/main-de87250a4e0c9fcf.js" defer=""></script><script src="/_next/static/chunks/pages/_app-
|
|
1
|
+
<!DOCTYPE html><html><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width"/><meta name="next-head-count" content="2"/><link rel="preload" href="/_next/static/css/bc89f2cd4e4781f5.css" as="style"/><link rel="stylesheet" href="/_next/static/css/bc89f2cd4e4781f5.css" data-n-g=""/><noscript data-n-css=""></noscript><script defer="" nomodule="" src="/_next/static/chunks/polyfills-42372ed130431b0a.js"></script><script src="/_next/static/chunks/webpack-24ddb02bea621501.js" defer=""></script><script src="/_next/static/chunks/framework-ab7ddb551c23d05a.js" defer=""></script><script src="/_next/static/chunks/main-de87250a4e0c9fcf.js" defer=""></script><script src="/_next/static/chunks/pages/_app-06554710922d81e3.js" defer=""></script><script src="/_next/static/chunks/pages/_error-fedd2c6ebd3d27b9.js" defer=""></script><script src="/_next/static/ljmoBvM8WSwJza0pcMtek/_buildManifest.js" defer=""></script><script src="/_next/static/ljmoBvM8WSwJza0pcMtek/_ssgManifest.js" defer=""></script></head><body><div id="__next"></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"statusCode":404}},"page":"/_error","query":{},"buildId":"ljmoBvM8WSwJza0pcMtek","runtimeConfig":{"sentryEnvironment":"alpha"},"nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[633],{21446:function(e,a,t){t.d(a,{S:function(){return S}});var r=t(52322),i=t(74217),n=t(11699),l=t(37792),s=t(5632),o=t(2784),c=t(76473),d=t(88932),u=t(30195),m=t(94160),g=t(34166),p=t(98250),h=t(68968),f=t(96317);let x=(0,o.forwardRef)((e,a)=>{let{width:t,height:i}=e;return void 0===t&&void 0===i&&(t=10,i=16),(0,r.jsxs)("svg",{ref:a,viewBox:"0 0 10 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",height:i,width:t,children:[(0,r.jsx)("path",{d:"M5 7.83323C5 6.45253 6.11928 5.33325 7.49997 5.33325C8.8807 5.33325 10 6.45255 10 7.83328V8.16656C10 9.54728 8.8807 10.6666 7.49997 10.6666C6.11928 10.6666 5 9.54731 5 8.16661V7.83323Z",fill:"#1ABCFE"}),(0,r.jsx)("path",{d:"M0 13.3334C0 11.8607 1.19391 10.6667 2.66667 10.6667H5V13.5001C5 14.8808 3.88071 16.0001 2.5 16.0001C1.11929 16.0001 0 14.8808 0 13.5001L0 13.3334Z",fill:"#0ACF83"}),(0,r.jsx)("path",{d:"M5 0V5.33333H7.33333C8.80609 5.33333 10 4.13943 10 2.66667C10 1.19391 8.80609 0 7.33333 0L5 0Z",fill:"#FF7262"}),(0,r.jsx)("path",{d:"M0 2.66659C0 4.13934 1.19391 5.33325 2.66667 5.33325L5 5.33325L5 -8.15392e-05L2.66667 -8.15392e-05C1.19391 -8.15392e-05 0 1.19383 0 2.66659Z",fill:"#F24E1E"}),(0,r.jsx)("path",{d:"M0 8.00008C0 9.47284 1.19391 10.6667 2.66667 10.6667H5L5 5.33341L2.66667 5.33341C1.19391 5.33341 0 6.52732 0 8.00008Z",fill:"#A259FF"})]})});var y=t(80148),j=t(54597),b=t(62434),w=t(56141);function v(e){let a;let{slice:t}=e,i="uploading"===t.status||"generating"===t.status,l="uploadError"===t.status||"generateError"===t.status||"cancelled"===t.status,s="pending"===t.status||"generateError"===t.status||"generating"===t.status||"success"===t.status||"cancelled"===t.status;return l?a=(0,r.jsx)(n.E,{startIcon:"refresh",color:"grey",onClick:t.onRetry,children:"Retry"}):"figma"===t.source&&(a=(0,r.jsx)(n.c3,{content:"Pasted from Figma",children:(0,r.jsx)(w.S,{})})),(0,r.jsxs)(b.Zb,{disabled:i,children:[s?(0,r.jsx)(b.ZB,{src:t.thumbnailUrl}):(0,r.jsx)(b.ZB,{component:"div"}),(0,r.jsx)(b.eW,{loading:i,startIcon:function(e){switch(e){case"uploadError":case"generateError":case"cancelled":return"close";case"pending":return"image";case"success":return"check";default:return}}(t.status),title:"success"===t.status?t.model.name:"figma"===t.source?t.image.name.split(".")[0]:t.image.name,subtitle:function(e){switch(e.status){case"uploading":return"Uploading...";case"pending":var a;return(a=e.image.size)<1024?"".concat(a," B"):a<1048576?"".concat((a/1024).toFixed(1)," kB"):"".concat((a/1048576).toFixed(1)," MB");case"uploadError":return"Unable to upload image";case"generating":return"Generating...";case"generateError":return"Something went wrong";case"cancelled":return"Cancelled";case"success":return"Generated"}}(t),error:l,action:a})]})}let C=u.z.object({__type:u.z.literal("figma-to-prismic/clipboard-data"),name:u.z.string(),image:u.z.string().startsWith("data:image/")});function S(e){let{open:a,location:t,onSuccess:u,onClose:f}=e,b=(0,s.useRouter)(),[w,S]=(0,o.useState)([]),[L,E]=(0,o.useState)(!1),[D,U]=(0,o.useState)(!1),{syncChanges:z}=(0,h.g)(),{createSliceSuccess:N,openLoginModal:B}=(0,j.Z)(),{completeStep:P}=(0,p.k)(),R=function(e){let{open:a}=e,t=(0,o.useRef)([]);return(0,o.useEffect)(()=>{a&&(t.current=[],y.managerClient.slices.readAllSlices().then(e=>{t.current=e.models.map(e=>{let{model:a}=e;return a})}).catch(()=>null))},[a]),t}({open:a}),M=A(),{libraryID:Z,isLoading:G}=function(){let[e,a]=(0,o.useState)();return(0,o.useEffect)(()=>{y.managerClient.project.getSliceMachineConfig().then(e=>{var t;let r=null==e?void 0:null===(t=e.libraries)||void 0===t?void 0:t[0];if(void 0===r)throw Error("No library found in the config.");a(r)}).catch(()=>{throw Error("Could not get library ID from the config.")})},[]),{libraryID:e,isLoading:void 0===e}}(),T=(0,i.R9)(Q),_=(0,o.useRef)(crypto.randomUUID());(0,c.y1)(["meta+v","ctrl+v"],e=>{e.preventDefault(),K({isShortcut:!0})},{enabled:a&&M}),(0,o.useEffect)(()=>{if(!w.some(e=>"generating"===e.status))return;let e=e=>{T();let a="Your current generating slices will be cancelled.";return e.returnValue=a,a};return b.events.on("routeChangeStart",T),window.addEventListener("beforeunload",e),()=>{b.events.off("routeChangeStart",T),window.removeEventListener("beforeunload",e)}},[w,b.events,T]);let V=e=>{let{index:a,slice:t}=e;S(e=>e.map((e,r)=>r===a?t(e):e))},O=e=>{if(Y)return;if(e.length>10){d.Am.error("You can only upload ".concat(10," images at a time."));return}let a=w.length;S(a=>[...a,...e.map(e=>({source:"upload",status:"uploading",image:e}))]),e.forEach((e,t)=>{X({index:a+t,image:e,source:"upload"})})},X=async e=>{let{index:a,image:t,source:r}=e,i=_.current;V({index:a,slice:e=>({...e,status:"uploading",image:t,source:r})});try{let e=await I({image:t});if(i!==_.current)return;V({index:a,slice:a=>({...a,status:"pending",thumbnailUrl:e})})}catch(e){if(i!==_.current)return;V({index:a,slice:e=>({...e,status:"uploadError",onRetry:()=>void X({index:a,image:t,source:r})})})}},H=async e=>{if(void 0===Z)return;let{index:a,imageUrl:r,source:i}=e,n=_.current,s=crypto.randomUUID();V({index:a,slice:e=>({...e,status:"generating",thumbnailUrl:r,requestId:s})});try{let e=await y.managerClient.customTypes.inferSlice({source:i,libraryID:Z,imageUrl:r,requestId:s});if(n!==_.current)return;let l=function(e){let{existingSlices:a,newSlices:t,slice:r}=e,i=new Set,n=new Set;for(let{id:e,name:t}of a)i.add(e),n.add(t.toLowerCase());for(let e of t)"success"===e.status&&(i.add(e.model.id),n.add(e.model.name.toLowerCase()));let l=r.id,s=2;for(;i.has(l);)l="".concat(r.id,"_").concat(s),s++;let o=r.name;for(s=2;n.has(o.toLowerCase());)o="".concat(r.name).concat(s),s++;return{...r,id:l,name:o}}({existingSlices:R.current,newSlices:w,slice:e.slice});if(S(t=>t.map((t,i)=>i!==a?t:{...t,status:"success",thumbnailUrl:r,model:l,langSmithUrl:e.langSmithUrl})),"upload"===i){n=_.current;let e=w[a],{errors:t}=await y.managerClient.slices.createSlice({libraryID:Z,model:l});if(t.length)throw Error("Failed to create slice ".concat(l.id,"."));if(await y.managerClient.slices.updateSliceScreenshot({libraryID:Z,sliceID:l.id,variationID:l.variations[0].id,data:e.image}),n!==_.current)return}P("createSlice"),m.Xe.track({event:"slice:created",id:l.id,name:l.name,library:Z,location:t,..."figma"===i?{mode:"figma-to-slice"}:{mode:"ai",langSmithUrl:e.langSmithUrl}}),m.Xe.track({event:"slice-generation:ended",error:!1}),(0,g.nZ)({type:"model",library:Z,sliceId:l.id,variationId:l.variations[0].id,langSmithUrl:e.langSmithUrl})}catch(e){if(n!==_.current)return;if(V({index:a,slice:t=>({...t,status:e instanceof Error&&"AbortError"===e.name?"cancelled":"generateError",thumbnailUrl:r,onRetry:()=>{H({index:a,imageUrl:r,source:i})}})}),(0,l.ff)(e)){d.Am.error("Please log in and try again."),J(),B();return}m.Xe.track({event:"slice-generation:ended",error:!0})}},W=w.reduce((e,a)=>("generating"===a.status?e.generating++:"uploading"===a.status?e.uploading++:"pending"===a.status?e.pending++:"success"===a.status&&e.completed++,e.loading=e.generating+e.uploading,e.generate=e.loading+e.pending,e),{generating:0,uploading:0,pending:0,completed:0,loading:0,generate:0}),Y=W.generating>0||W.completed>0,J=()=>{W.loading>0||(f(),_.current=crypto.randomUUID(),setTimeout(()=>S([]),250))},q=async()=>{if(void 0!==Z)try{E(!0);let e=await (0,m.y0)();N(e.libraries),z(),u({slices:w.flatMap(e=>"success"===e.status?e.model:[]),library:Z}),J()}finally{E(!1)}},K=async e=>{var t;let{isShortcut:r=!1}=null!=e?e:{};if(!(!a||!M||w.some(e=>"figma"===e.source)||w.some(e=>"uploading"===e.status||"generating"===e.status))){if("function"!=typeof(null===(t=navigator.clipboard)||void 0===t?void 0:t.read)){d.Am.error("Clipboard paste is not supported in this browser.");return}try{let e=await navigator.clipboard.read();if(0===e.length){d.Am.error("No data found in clipboard.");return}let a="pasted-image.png",t=null,i=!1;for(let a of e){let e=a.types.find(e=>e.startsWith("image/"));if(void 0!==e){t=await a.getType(e);break}}for(let r of e)if(r.types.includes("text/plain"))try{let e=await r.getType("text/plain"),n=await e.text(),l=C.safeParse(JSON.parse(n));if(l.success){i=!0;let e=l.data;if(a="".concat(e.name,".png"),!t){let a=await fetch(e.image);t=await a.blob()}}else console.warn("Clipboard data validation failed:",l.error)}catch(e){console.warn("Failed to parse JSON from clipboard:",e)}if(!t){i?d.Am.error("Could not extract Figma data from clipboard. Please try copying again using the Prismic Figma plugin."):d.Am.error("No Figma data found in clipboard. Make sure you've copied a design using the Prismic Figma plugin.");return}let n=w.length;if(n>=10){d.Am.error("You can only upload ".concat(10," images at a time."));return}let l=new File([t],a,{type:t.type});S(e=>[...e,{source:"figma",status:"uploading",image:l}]),X({index:n,image:l,source:"figma"}),m.Xe.track({event:"slice-generation:pasted-from-figma",source:r?"shortcut":"button"}),d.Am.success("Pasted ".concat(a).concat(i?" from Figma":""))}catch(e){console.error("Failed to paste from clipboard:",e),d.Am.error("Failed to paste from clipboard. Please check browser permissions and try again.")}}};function Q(){let e=w.flatMap(e=>"generating"===e.status?[e.requestId]:[]);0!==e.length&&e.forEach(e=>{y.managerClient.customTypes.cancelInferSlice({requestId:e})})}return(0,r.jsxs)(n.ae,{open:a,onOpenChange:e=>!e&&J(),children:[(0,r.jsx)(n.al,{title:"Generate slices with AI"}),(0,r.jsxs)(n.aj,{gap:0,children:[(0,r.jsx)(n.ak,{hidden:!0,children:"Upload images to generate slices with AI"}),G?(0,r.jsx)(n.D,{display:"flex",justifyContent:"center",alignItems:"center",height:"100%",children:(0,r.jsx)(n.bg,{color:"purple9"})}):(0,r.jsxs)(r.Fragment,{children:[0===w.length?(0,r.jsxs)(n.D,{padding:16,height:"100%",gap:16,display:"flex",flexDirection:"column",children:[M&&(0,r.jsxs)(n.D,{display:"flex",gap:16,alignItems:"center",backgroundColor:"grey2",padding:16,borderRadius:12,children:[(0,r.jsxs)(n.D,{display:"flex",gap:8,alignItems:"center",flexGrow:1,children:[(0,r.jsx)(n.D,{width:48,height:48,backgroundColor:"grey12",borderRadius:"100%",display:"flex",alignItems:"center",justifyContent:"center",children:(0,r.jsx)(x,{height:25})}),(0,r.jsxs)(n.D,{display:"flex",flexDirection:"column",flexGrow:1,children:[(0,r.jsx)(n.bL,{variant:"bold",children:"Want to work faster?"}),(0,r.jsx)(n.bL,{variant:"small",color:"grey11",children:"Copy frames from Figma with the Slice Machine plugin and paste them here."})]})]}),(0,r.jsx)(n.E,{endIcon:"arrowForward",color:"indigo",onClick:()=>{window.open("https://www.figma.com/community/plugin/1567955296461153730/figma-to-slice","_blank"),m.Xe.track({event:"slice-generation:plugin-installation-clicked"})},sx:{marginRight:8},invisible:!0,children:"Install plugin"})]}),(0,r.jsx)(n.aF,{onFilesSelected:O,assetType:"image",maxFiles:10,overlay:(0,r.jsx)(F,{onFilesSelected:O,onPaste:K,droppingFiles:!0}),children:(0,r.jsx)(F,{onFilesSelected:O,onPaste:K})})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(n.D,{display:"flex",alignItems:"center",justifyContent:"space-between",padding:16,children:[(0,r.jsx)(n.bL,{variant:"h3",children:"Design"}),(0,r.jsx)(n.aG,{size:"medium",color:"grey",onFilesSelected:O,startIcon:"attachFile",disabled:Y,children:"Add images"})]}),(0,r.jsx)(n.bn,{stableScrollbar:!1,children:(0,r.jsx)(n.D,{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16,padding:16,children:w.map((e,a)=>(0,r.jsx)(v,{slice:e},"slice-".concat(a)))})})]}),(0,r.jsxs)(n.ah,{children:[W.generating>0?(0,r.jsx)(n.ai,{onClick:()=>U(!0),size:"medium",sx:{marginRight:8},invisible:!0,children:"Cancel"}):(0,r.jsx)(n.ai,{onClick:()=>J(),size:"medium",sx:{marginRight:8},invisible:!0,children:"Close"}),0===W.completed||W.loading>0?(0,r.jsxs)(n.af,{color:"purple",startIcon:"autoFixHigh",onClick:()=>{void 0!==Z&&w.forEach((e,a)=>{"pending"===e.status&&H({index:a,imageUrl:e.thumbnailUrl,source:e.source})})},disabled:Y||W.loading>0||0===W.pending,loading:W.loading>0,size:"medium",children:["Generate ",W.generate>0?"(".concat(W.generate,") "):"",1===W.generate?"Slice":"Slices"]}):(0,r.jsx)(n.af,{color:"purple",onClick:()=>void q(),loading:L,size:"medium",children:k(t,W.completed)})]})]})]}),(0,r.jsxs)(n.ae,{size:"small",open:D,onOpenChange:U,children:[(0,r.jsx)(n.al,{title:"Cancel generation"}),(0,r.jsxs)(n.aj,{children:[(0,r.jsx)(n.ak,{children:(0,r.jsx)(n.D,{display:"flex",flexDirection:"column",padding:{inline:16},children:(0,r.jsx)(n.bL,{variant:"bold",children:"Are you sure you want to cancel the generation for all slices?"})})}),(0,r.jsxs)(n.ah,{children:[(0,r.jsx)(n.ai,{onClick:()=>U(!1),size:"small",children:"Keep generating"}),(0,r.jsx)(n.af,{color:"tomato",onClick:()=>{U(!1),Q()},size:"small",children:"Confirm"})]})]})]})]})}function F(e){let{droppingFiles:a=!1,onFilesSelected:t,onPaste:i}=e,l=A();return(0,r.jsx)(n.D,{justifyContent:"center",flexDirection:"column",height:"100%",backgroundColor:a?"purple2":"grey2",border:!0,borderStyle:"dashed",borderColor:a?"purple9":"grey6",borderRadius:12,flexGrow:1,children:(0,r.jsx)(n.s,{children:(0,r.jsxs)(n.D,{display:"flex",flexDirection:"column",gap:16,alignItems:"center",children:[(0,r.jsx)(n.x,{lineColor:"purple11",backgroundColor:"purple5",name:"cloudUpload",size:"large"}),(0,r.jsx)(n.D,{display:"flex",flexDirection:"column",gap:4,alignItems:"center",children:l?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.bL,{children:"Generate slices from your designs"}),(0,r.jsx)(n.bL,{variant:"small",color:"grey11",children:"Upload your design images or paste them directly from Figma."})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.bL,{children:"Upload your design images."}),(0,r.jsx)(n.bL,{variant:"small",color:"grey11",children:"Once uploaded, you can generate slices automatically using AI."})]})}),(0,r.jsx)(n.D,{display:"flex",alignItems:"center",gap:16,children:l?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.E,{size:"small",renderStartIcon:()=>(0,r.jsx)(x,{height:16}),color:"grey",onClick:()=>void i(),children:"Paste from Figma"}),(0,r.jsx)(n.aG,{size:"small",onFilesSelected:t,color:"purple",invisible:!0,children:"Add images"})]}):(0,r.jsx)(n.aG,{startIcon:"attachFile",onFilesSelected:t,color:"grey",children:"Add images"})})]})})})}async function I(e){let{image:a}=e,t=[await y.managerClient.project.getResolvedRepositoryName(),"shared-slices","prismic-inferred-slices",crypto.randomUUID()].join("/");await y.managerClient.screenshots.initS3ACL();let{url:r}=await y.managerClient.screenshots.uploadScreenshot({keyPrefix:t,data:a});return r}let k=(e,a)=>{switch(e){case"custom_type":return"Add to type (".concat(a,")");case"page_type":return"Add to page (".concat(a,")");case"slices":return"Done"}};function A(){let e=(0,f.L)("llm-proxy-access");return(null==e?void 0:e.value)==="on"}},27213:function(e,a,t){t.d(a,{F:function(){return n}});var r=t(52322),i=t(11699);let n=e=>{let{menuType:a}=e;return{fromImage:{BackgroundIcon:(0,r.jsx)(i.B,{name:"autoFixHigh",size:"ActionList"===a?"small":"extraSmall",iconSize:"ActionList"===a?"medium":"small",color:"purple",variant:"solid",radius:6}),title:"Generate from image",description:"Build a slice based on your design image."},fromScratch:{BackgroundIcon:(0,r.jsx)(i.B,{name:"add",size:"ActionList"===a?"small":"extraSmall",iconSize:"ActionList"===a?"medium":"small",color:"white",variant:"solid",radius:6}),title:"Start from scratch",description:"Build a custom slice your way."},fromTemplate:{BackgroundIcon:(0,r.jsx)(i.B,{name:"contentCopy",size:"ActionList"===a?"small":"extraSmall",iconSize:"ActionList"===a?"medium":"small",color:"white",variant:"solid",radius:6}),title:"Use a template",description:"Choose from ready-made examples."},fromExisting:{BackgroundIcon:(0,r.jsx)(i.B,{name:"folder",size:"ActionList"===a?"small":"extraSmall",iconSize:"ActionList"===a?"medium":"small",color:"white",variant:"solid",radius:6}),title:"Reuse an existing slice",description:"Select from your created slices."}}}},6256:function(e,a,t){t.d(a,{c:function(){return j}});var r=t(52322),i=t(2784),n=t(36131),l=t(75289),s=t(94160),o=t(98250),c=t(88932),d=t(63908),u=t(358),m=t(80148);async function g(e){let{sliceName:a,libraryName:t,location:r,onSuccess:i}=e;try{let e=(0,d.fo)(a),{errors:n}=await m.managerClient.slices.createSlice({libraryID:t,model:e});if(n.length>0)throw n;s.Xe.track({event:"slice:created",id:(0,u.MP)(a),name:a,library:t,location:r,mode:"manual"}),await i(e)}catch(t){let e="An unexpected error happened while creating slice ".concat(a,".");console.error(e,t),c.Am.error(e)}}var p=t(68968),h=t(59532),f=t(54597),x=t(46999),y=t(63019);let j=e=>{let{onClose:a,onSuccess:t,localLibraries:c,location:d,remoteSlices:u}=e,{createSliceSuccess:m}=(0,f.Z)(),[j,b]=(0,i.useState)(!1),{syncChanges:w}=(0,p.g)(),{completeStep:v}=(0,o.k)(),C=async e=>{let a=e.sliceName,r=e.from;b(!0),await g({sliceName:a,libraryName:r,location:d,onSuccess:async e=>{m((await (0,s.y0)()).libraries),t(e,r),w(),v("createSlice")}})};return(0,r.jsx)(h.Z,{testId:"create-slice-modal",isOpen:!0,widthInPx:"530px",isLoading:j,formId:"create-new-slice",close:a,buttonLabel:"Create",onSubmit:e=>{C(e)},initialValues:{sliceName:"",from:c[0].name},validate:e=>(0,y.h)(e,c,u),content:{title:"Create a new slice"},children:e=>{let{touched:a,values:t,setFieldValue:i,errors:s}=e;return(0,r.jsxs)(l.xu,{children:[(0,r.jsx)(x.W,{name:"sliceName",label:"Slice name",placeholder:"Pascalised slice API ID (e.g. TextBlock)",error:a.sliceName?s.sliceName:void 0,testId:"slice-name-input"}),(0,r.jsx)(l.__,{htmlFor:"from",sx:{mb:2},children:"Target Library"}),(0,r.jsx)(n.ZP,{name:"from",options:c.map(e=>({value:e.name,label:e.name})),onChange:e=>e?void i("from",e.value):null,defaultValue:{value:t.from,label:t.from},styles:{option:e=>({...e,color:"#161618"})},theme:e=>({...e,colors:{...e.colors,primary:"#E9E8EA"}}),menuPortalTarget:document.body})]})}})}},63019:function(e,a,t){t.d(a,{h:function(){return o}});var r=t(96009),i=t.n(r),n=t(74600),l=t.n(n),s=t(7974);function o(e,a,t){let{sliceName:r}=e;return r?s.lS.includes(r.toLowerCase())?{sliceName:'Name "'.concat(r,'" is reserved for Slice Machine use.')}:s.xo.exec(r)?l()(i()(r)).replace(/\s/gm,"")!==r.trim()?{sliceName:"Value has to be PascalCased."}:r.match(/^\d/)?{sliceName:"Value cannot start with a number."}:[...a.flatMap(e=>e.components.map(e=>e.model.name)),...t.map(e=>e.name)].includes(r)?{sliceName:"Slice name is already taken."}:void 0:{sliceName:"No special characters allowed."}:{sliceName:"Cannot be empty"}}},21151:function(e,a,t){var r=t(52322),i=t(75289);a.Z=function(e){let{elems:a,renderElem:t,defineElementKey:n,gridTemplateMinPx:l="320px",gridGap:s="16px",sx:o}=e;return(0,r.jsx)(i.xu,{as:"section",sx:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(".concat(l,", 1fr))"),gridGap:s,pt:2,...o},children:a.map((e,a)=>e?(0,r.jsx)("span",{children:t(e,a)},"".concat(n(e),"-").concat(a+1)):null)})}}}]);
|