slice-machine-ui 2.20.5-alpha.jp-import-slices-2.1 → 2.20.5-alpha.jp-import-slices-2.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 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/b30fbbc3ed00a725.css" as="style"/><link rel="stylesheet" href="/_next/static/css/b30fbbc3ed00a725.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-e986dd216b883a74.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-a60aecdbaa4efedd.js" defer=""></script><script src="/_next/static/chunks/pages/_error-fedd2c6ebd3d27b9.js" defer=""></script><script src="/_next/static/60BSwFmsh1-aNIyMe29hH/_buildManifest.js" defer=""></script><script src="/_next/static/60BSwFmsh1-aNIyMe29hH/_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":"60BSwFmsh1-aNIyMe29hH","runtimeConfig":{"sentryEnvironment":"alpha"},"nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>
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/b30fbbc3ed00a725.css" as="style"/><link rel="stylesheet" href="/_next/static/css/b30fbbc3ed00a725.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-e986dd216b883a74.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-89df34df01f52931.js" defer=""></script><script src="/_next/static/chunks/pages/_error-fedd2c6ebd3d27b9.js" defer=""></script><script src="/_next/static/-Yjs5UmgvuB8nY3BLb3TK/_buildManifest.js" defer=""></script><script src="/_next/static/-Yjs5UmgvuB8nY3BLb3TK/_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":"-Yjs5UmgvuB8nY3BLb3TK","runtimeConfig":{"sentryEnvironment":"alpha"},"nextExport":true,"isFallback":false,"gip":true,"scriptLoader":[]}</script></body></html>
@@ -1 +1 @@
1
- self.__BUILD_MANIFEST=function(s,c,a,e,t,i,b,d,n,u,h,f,k,j,l,p,g,o,r,m,_,y,I,N){return{__rewrites:{afterFiles:[],beforeFiles:[],fallback:[]},"/":[s,t,o,r,"static/chunks/pages/index-0d8cb369de720a35.js"],"/_error":["static/chunks/pages/_error-fedd2c6ebd3d27b9.js"],"/changelog":[c,i,"static/chunks/870-a72b74312773efea.js","static/chunks/pages/changelog-bc83e25e8d316ca9.js"],"/changes":[c,b,"static/chunks/8eec4907-b712959d9f984b68.js",a,"static/chunks/125-00b909bdbab2ca15.js",e,n,"static/css/d98ebc475f8423a3.css","static/chunks/pages/changes-6f371ebe52dbe76a.js"],"/custom-types":[s,t,o,r,"static/chunks/pages/custom-types-5acd56959b60346f.js"],"/custom-types/[customTypeId]":[c,u,h,f,k,s,a,i,d,j,l,m,e,t,p,g,_,y,"static/chunks/pages/custom-types/[customTypeId]-80defa14b6ea36f7.js"],"/labs":["static/chunks/pages/labs-16d118a80936d583.js"],"/page-types/[pageTypeId]":[c,u,h,f,k,s,a,i,d,j,l,m,e,t,p,g,_,y,"static/chunks/pages/page-types/[pageTypeId]-f4ff9ad74b44bf09.js"],"/slices":[c,b,I,s,a,d,N,e,g,n,"static/css/efa5152b7c0f35c0.css","static/chunks/pages/slices-93fc784c443a996c.js"],"/slices/[lib]/[sliceName]/[variation]":[c,b,u,h,f,k,I,s,a,i,d,j,N,"static/chunks/484-3e011e79c41f0342.js",e,p,n,"static/css/e8e03c0d4003d1eb.css","static/chunks/pages/slices/[lib]/[sliceName]/[variation]-0e9aa745ed9fe1ec.js"],"/slices/[lib]/[sliceName]/[variation]/simulator":[b,"static/chunks/72585f70-28b4d7d5384b3703.js",l,"static/chunks/429-e5d7e39160de9f5e.js","static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-873c0c89aaf50b3c.js"],sortedPages:["/","/_app","/_error","/changelog","/changes","/custom-types","/custom-types/[customTypeId]","/labs","/page-types/[pageTypeId]","/slices","/slices/[lib]/[sliceName]/[variation]","/slices/[lib]/[sliceName]/[variation]/simulator"]}}("static/chunks/397-e6c340070a3bcb41.js","static/chunks/59b4e022-ef680789f7cc9b11.js","static/chunks/66-d9d3bcb5d041cb6d.js","static/chunks/882-8ab59c0c72307c87.js","static/chunks/647-a29bee23cb9ac7a2.js","static/chunks/183-4ea255b867ff171b.js","static/chunks/c8eae200-966ce352f7b5d2b9.js","static/chunks/344-b64f09e670634ed1.js","static/chunks/593-7ffd1197c3405ef8.js","static/chunks/f36c6662-1f3a854183168b10.js","static/chunks/4c744e84-480e426e4b1cfef3.js","static/chunks/065a3ddb-9a38ca0d60f0bf2f.js","static/chunks/1cc2734a-09fb3b997ad1eb70.js","static/chunks/256-07f768a2b19b0a0e.js","static/chunks/130-e1a16d2f94fb2b64.js","static/chunks/630-4fe1e982234bd925.js","static/chunks/633-2d20c3e815c79c7f.js","static/chunks/248-2902bda47821f37b.js","static/css/4e475d945cf8a890.css","static/chunks/21-f3962d02eda0a46e.js","static/chunks/660-a3ec593dcfbb44c9.js","static/css/56f2a6684a524374.css","static/chunks/52d4c156-89c6ec6efca0a0bb.js","static/chunks/444-d39213143f782fec.js"),self.__BUILD_MANIFEST_CB&&self.__BUILD_MANIFEST_CB();
1
+ self.__BUILD_MANIFEST=function(s,c,a,e,t,i,b,d,n,u,h,f,k,j,l,p,g,o,r,m,_,y,I,N){return{__rewrites:{afterFiles:[],beforeFiles:[],fallback:[]},"/":[s,t,o,r,"static/chunks/pages/index-0d8cb369de720a35.js"],"/_error":["static/chunks/pages/_error-fedd2c6ebd3d27b9.js"],"/changelog":[c,i,"static/chunks/870-a72b74312773efea.js","static/chunks/pages/changelog-bc83e25e8d316ca9.js"],"/changes":[c,b,"static/chunks/8eec4907-b712959d9f984b68.js",a,"static/chunks/125-00b909bdbab2ca15.js",e,n,"static/css/d98ebc475f8423a3.css","static/chunks/pages/changes-6f371ebe52dbe76a.js"],"/custom-types":[s,t,o,r,"static/chunks/pages/custom-types-5acd56959b60346f.js"],"/custom-types/[customTypeId]":[c,u,h,f,k,s,a,i,d,j,l,m,e,t,p,g,_,y,"static/chunks/pages/custom-types/[customTypeId]-80defa14b6ea36f7.js"],"/labs":["static/chunks/pages/labs-16d118a80936d583.js"],"/page-types/[pageTypeId]":[c,u,h,f,k,s,a,i,d,j,l,m,e,t,p,g,_,y,"static/chunks/pages/page-types/[pageTypeId]-f4ff9ad74b44bf09.js"],"/slices":[c,b,I,s,a,d,N,e,g,n,"static/css/efa5152b7c0f35c0.css","static/chunks/pages/slices-93fc784c443a996c.js"],"/slices/[lib]/[sliceName]/[variation]":[c,b,u,h,f,k,I,s,a,i,d,j,N,"static/chunks/484-3e011e79c41f0342.js",e,p,n,"static/css/e8e03c0d4003d1eb.css","static/chunks/pages/slices/[lib]/[sliceName]/[variation]-0e9aa745ed9fe1ec.js"],"/slices/[lib]/[sliceName]/[variation]/simulator":[b,"static/chunks/72585f70-28b4d7d5384b3703.js",l,"static/chunks/429-e5d7e39160de9f5e.js","static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-873c0c89aaf50b3c.js"],sortedPages:["/","/_app","/_error","/changelog","/changes","/custom-types","/custom-types/[customTypeId]","/labs","/page-types/[pageTypeId]","/slices","/slices/[lib]/[sliceName]/[variation]","/slices/[lib]/[sliceName]/[variation]/simulator"]}}("static/chunks/397-e6c340070a3bcb41.js","static/chunks/59b4e022-ef680789f7cc9b11.js","static/chunks/66-d9d3bcb5d041cb6d.js","static/chunks/882-8ab59c0c72307c87.js","static/chunks/647-a29bee23cb9ac7a2.js","static/chunks/183-4ea255b867ff171b.js","static/chunks/c8eae200-966ce352f7b5d2b9.js","static/chunks/344-b64f09e670634ed1.js","static/chunks/593-7ffd1197c3405ef8.js","static/chunks/f36c6662-1f3a854183168b10.js","static/chunks/4c744e84-480e426e4b1cfef3.js","static/chunks/065a3ddb-9a38ca0d60f0bf2f.js","static/chunks/1cc2734a-09fb3b997ad1eb70.js","static/chunks/256-07f768a2b19b0a0e.js","static/chunks/130-e1a16d2f94fb2b64.js","static/chunks/630-4fe1e982234bd925.js","static/chunks/633-2d20c3e815c79c7f.js","static/chunks/248-2902bda47821f37b.js","static/css/4e475d945cf8a890.css","static/chunks/21-f3962d02eda0a46e.js","static/chunks/660-e3d7a5444ab7391e.js","static/css/56f2a6684a524374.css","static/chunks/52d4c156-89c6ec6efca0a0bb.js","static/chunks/444-d39213143f782fec.js"),self.__BUILD_MANIFEST_CB&&self.__BUILD_MANIFEST_CB();
@@ -1 +1 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[660],{10660:function(e,t,n){"use strict";n.d(t,{H:function(){return tu}});var i=n(52322),a=n(18337),o=n(97729),l=n.n(o),r=n(5632),s=n(2784),c=n(56580),d=n(43388),m=n(77630),h=n(23094),u=n(59294),p=n(58446),f=n(74217),g=n(94160),x=n(68968),b=n(23710),y=n(54597),v=n(98564);let j=(0,s.createContext)(void 0);function S(e){let{children:t,initialCustomType:n}=e,[a,o]=(0,s.useState)(n),l=(0,m.y6)(a),r=v.$[l],{actionQueueStatus:c,setNextAction:d}=(0,b.c)({errorMessage:r.autoSaveFailed}),{refreshState:h}=(0,y.Z)(),u=(0,f.R9)(h),{syncChanges:p}=(0,x.g)(),S=(0,s.useCallback)(e=>{let{customType:t,onSaveCallback:n,updateMeta:i}=e;o(t),d(async()=>{let{errors:e}=await (0,g.KA)({customType:t,updateMeta:i});if(e.length>0)throw e;u(await (0,g.y0)()),p(),null==n||n()})},[d,u,p]),w=(0,s.useMemo)(()=>({actionQueueStatus:c,customType:a,setCustomType:S}),[c,a,S]);return(0,i.jsx)(j.Provider,{value:w,children:"function"==typeof t?t(w):t})}function w(){let e=(0,s.useContext)(j);if(!e)throw Error("CustomTypeProvider not found");return e}var C=n(30195);function I(){var e;let[t,n]=(0,s.useState)(!1),{customType:o,setCustomType:l}=w(),[r,c]=null!==(e=(0,m.j5)(o))&&void 0!==e?e:[],d=c?(0,m.N3)(c):"",[h,u]=(0,s.useState)(null!=d?d:""),[p,g]=(0,s.useState)();(0,f.pQ)(t,()=>{t||(u(null!=d?d:""),g(void 0))});let x=(0,s.useCallback)(()=>(0,i.jsx)(a.aX,{name:c?"language":"add",size:"small",color:"grey11"}),[c]);return(0,i.jsxs)(a.ae,{open:t,onOpenChange:n,size:"small",trigger:(0,i.jsx)(a.E,{color:"grey",textColor:"placeholder",textWeight:"normal",renderStartIcon:x,sx:{marginInline:"auto"},children:c?d:"Add an UID"}),children:[(0,i.jsx)(a.al,{title:"Edit the UID label"}),(0,i.jsx)(a.aj,{children:(0,i.jsxs)(a.aJ,{onSubmit:function(){p||(l({customType:c?(0,m.eK)(h,o):(0,m.H8)(h,o)}),n(!1))},children:[(0,i.jsx)(a.D,{flexDirection:"column",padding:16,gap:4,children:(0,i.jsx)(a.aM,{type:"text",label:"Label *",placeholder:"UID",value:h,onValueChange:function(e){u(e),g(function(e){let t=D.safeParse(e,{errorMap:k});if(t.error)return t.error.errors[0].message}(e))},error:p,description:"A label for the UID"})}),(0,i.jsxs)(a.ah,{children:[(0,i.jsx)(a.ai,{size:"medium"}),(0,i.jsx)(a.af,{type:"submit",size:"medium",disabled:!!p,children:"Save"})]})]})})]})}let D=C.z.string().max(35).min(1),k=e=>{switch(e.code){case C.z.ZodIssueCode.too_big:return{message:"The label can't be longer than ".concat(e.maximum," characters")};case C.z.ZodIssueCode.too_small:return{message:"This field is required"};default:return{message:"Invalid value"}}};var T=n(94840),_=n(59532),A=n(63397),E=n(75289);let L=e=>{let{name:t,label:n,placeholder:a,error:o,...l}=e;return(0,i.jsxs)(E.xu,{mb:3,children:[(0,i.jsx)(E.__,{htmlFor:t,mb:2,children:n}),(0,i.jsx)(A.gN,{name:t,type:"text",placeholder:a,as:E.II,autoComplete:"off",...l}),o?(0,i.jsx)(E.xv,{sx:{color:"error",mt:1},children:o}):null]})};var z=e=>{let{isOpen:t,onSubmit:n,close:a,tabIds:o}=e;return(0,i.jsx)(_.Z,{isOpen:t,widthInPx:"530px",formId:"create-tab",close:a,onSubmit:e=>{n(e),a()},initialValues:{id:""},validate:e=>{let{id:t}=e;return t?o.includes(t.toLowerCase())?{id:"Tab exists already"}:void 0:{id:"Tab ID is required"}},content:{title:"Add Tab"},children:e=>{let{errors:t}=e;return(0,i.jsx)(L,{name:"id",label:"New Tab ID",placeholder:"A label for selecting the tab (i.e. not used in the API)",error:t.id})}})},N=e=>{let{isOpen:t,onSubmit:n,close:a}=e;return(0,i.jsx)(_.Z,{omitFooter:!0,isOpen:t,widthInPx:"530px",formId:"create-tab",close:a,cardProps:{bodySx:{p:0}},onSubmit:e=>{n(e),a()},initialValues:{},content:{title:"Remove Tab"},children:()=>(0,i.jsxs)(E.xu,{sx:{px:4,py:4},children:[(0,i.jsx)(E.X6,{as:"h4",children:"Remove this tab?"}),(0,i.jsx)(E.xv,{as:"p",color:"textClear",sx:{mt:2},children:"This action cannot be undone."}),(0,i.jsx)(E.zx,{type:"button",variant:"buttons.actionDelete",sx:{mt:3},onClick:()=>{n({}),a()},children:"Yes, remove tab"})]})})},P=e=>{let{isOpen:t,onSubmit:n,close:a,tabIds:o,initialTabKey:l}=e;return(0,i.jsx)(_.Z,{omitFooter:!0,isOpen:t,widthInPx:"530px",formId:"create-tab",close:a,cardProps:{bodySx:{p:0}},onSubmit:e=>{n(e),a()},initialValues:{id:l},validate:e=>{let{id:t}=e;return t?o.includes(t.toLowerCase())?{id:"Tab exists already"}:void 0:{id:"Tab ID is required"}},content:{title:"Rename Tab"},children:e=>{let{errors:t,values:o,setFieldValue:l,isValid:r}=e;return(0,i.jsxs)(E.xu,{sx:{px:4,py:4},children:[(0,i.jsx)(L,{name:"id",label:"Rename Tab ID",placeholder:"A label for selecting the tab (i.e. not used in the API)",error:t.id,onBlur:e=>{o.id!==e.target.value&&l("id",e.target.value.trim())},onChange:e=>{l("id",e.target.value)}}),(0,i.jsx)(E.zx,{type:"button",sx:{mt:3,width:"100%"},disabled:!r,onClick:()=>{o.id&&o.id.length&&n({id:o.id.trim()}),a()},children:"Save"})]})}})},M=n(28316),F=n(88932),O=n(35289),U=n(87446),Z=n(45440),G=n(16086),B=n(358),R=n(5495),H=n(39302),K=n(3285),X=n(40141),V=n(65077),q=n(21446);let W=(e,t)=>{switch(e){case"custom_type":case"page_type":return"Add to ".concat(t)}};var Y=n(80148),$=n(74686),J=n(88866);async function Q(e,t,n){let i=Array(e.length),a=0,o=Array(Math.min(t,e.length)).fill(null).map(async()=>{for(;;){let t=a++;if(t>=e.length)break;i[t]=await n(e[t],t)}});return await Promise.all(o),i}class ee{getHeaders(){let e={Accept:"application/vnd.github.v3+json"};return void 0!==this.token&&(e.Authorization="Bearer ".concat(this.token)),e}async request(e,t){let n="".concat(this.baseUrl).concat(e),i=await fetch(n,{...t,headers:{...this.getHeaders(),...null==t?void 0:t.headers}});if(!i.ok)throw Error("GitHub API request failed: ".concat(i.status," ").concat(i.statusText));return i.json()}async getDefaultBranch(){let e=await this.request("/repos/".concat(this.owner,"/").concat(this.repo));return C.z.object({default_branch:C.z.string()}).parse(e).default_branch}async getFileContents(e,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=await this.request("/repos/".concat(this.owner,"/").concat(this.repo,"/contents/").concat(e,"?ref=").concat(t)),a=C.z.object({content:C.z.string(),encoding:C.z.string()}).parse(i);if("base64"!==a.encoding)throw Error("Unexpected encoding for ".concat(e,": ").concat(a.encoding));let o=atob(a.content.replace(/\s/g,""));if(!n)return o;{let e=new Uint8Array(o.length);for(let t=0;t<o.length;t++)e[t]=o.charCodeAt(t);return e.buffer}}async getDirectoryContents(e){let t=await this.request("/repos/".concat(this.owner,"/").concat(this.repo,"/contents/").concat(e));return C.z.array(C.z.object({name:C.z.string(),type:C.z.string(),path:C.z.string()})).parse(t)}async searchCode(e){let{path:t,filename:n}=e,i=[];void 0!==t&&i.push("path:".concat(t)),void 0!==n&&i.push("filename:".concat(n)),i.push("repo:".concat(this.owner,"/").concat(this.repo));let a="/search/code?q=".concat(encodeURIComponent(i.join(" "))),o=await this.request(a);return C.z.object({items:C.z.array(C.z.object({path:C.z.string(),name:C.z.string()})).optional(),total_count:C.z.number().optional()}).parse(o)}async getSliceLibraries(e){let t=await this.request("/repos/".concat(this.owner,"/").concat(this.repo,"/contents/slicemachine.config.json?ref=").concat(e)),n=C.z.object({content:C.z.string().optional(),encoding:C.z.string().optional()}).parse(t);if("string"==typeof n.content){let e=atob(n.content.replace(/\s/g,""));return C.z.object({libraries:C.z.array(C.z.string())}).parse(JSON.parse(e)).libraries}throw Error("No content found in slicemachine.config.json")}constructor(e){this.baseUrl="https://api.github.com",this.owner=e.owner,this.repo=e.repo,this.token=e.token}}let et=e=>{let t=e.match(/github\.com\/([^\/]+)\/([^\/]+)(?:\/|$)/);if(!t)throw Error("Invalid GitHub URL format");let[,n,i]=t;return{owner:n,repo:i.replace(/\.git$/,"")}},en=async e=>{let{owner:t,repo:n}=e;return new ee({owner:t,repo:n}).getDefaultBranch()},ei=async e=>{let{owner:t,repo:n,branch:i}=e;return new ee({owner:t,repo:n}).getSliceLibraries(i)},ea=async e=>{let{owner:t,repo:n,branch:i,libraries:a}=e,o=new ee({owner:t,repo:n}),l=[];for(let e of(console.log("Fetching slices from ".concat(a.length," library/libraries:"),a),a)){let t=e.replace(/^\.\//,""),n=[],a=!1;try{n=(await o.getDirectoryContents(t)).filter(e=>"dir"===e.type).map(e=>({name:e.name,path:e.path}))}catch(n){a=!0;let t=n instanceof Error?n.message:String(n);t.includes("403")?console.warn("GitHub API returned 403 for ".concat(e,", trying direct discovery...")):console.warn("GitHub API error for ".concat(e,", trying direct discovery..."),t)}if(a&&0===n.length){console.log("Attempting to discover slices using GitHub Search API for ".concat(e,"..."));try{let i=await o.searchCode({path:t,filename:"model.json"});if(i.items&&i.items.length>0){let a=new Set;for(let e of i.items){let t=e.path.split("/");if(t.length>=2){let e=t[t.length-2];e&&!a.has(e)&&a.add(e)}}n=Array.from(a).map(e=>({name:e,path:"".concat(t,"/").concat(e)})),console.log("Discovered ".concat(n.length," slice(s) via GitHub Search API for library ").concat(e))}else console.warn("GitHub Search API found no model.json files in ".concat(e))}catch(n){let t=n instanceof Error?n.message:String(n);t.includes("403")?console.warn("GitHub Search API also returned 403. Cannot discover slices without API access."):console.warn("Error using GitHub Search API for ".concat(e,":"),t)}}if(0===n.length){console.warn("No slices found in library ".concat(e,". The repository may be private or require authentication."));continue}console.log("Processing ".concat(n.length," slice(s) in library ").concat(e));let r=async e=>{try{let t,n,a,r;let s=await o.getFileContents("".concat(e.path,"/model.json"),i,!1);if("string"!=typeof s){console.warn("Failed to fetch model.json for slice: ".concat(e.name," - unexpected content type"));return}let c=J.SharedSlice.decode(JSON.parse(s));if("Left"===c._tag){console.warn("Failed to decode model.json for slice: ".concat(e.name));return}let d=c.right,m=[];try{m=await eo({api:o,branch:i,directoryPath:e.path}),console.log("Fetched ".concat(m.length," file(s) for slice ").concat(e.name,":"),m.map(e=>"".concat(e.path).concat(e.isBinary?" (binary)":"")))}catch(t){console.warn("Failed to fetch files for slice ".concat(e.name,":"),t instanceof Error?t.message:String(t))}for(let i of m)if(void 0===t&&i.path.match(/^index\.(tsx?|jsx?|vue|svelte)$/)&&"string"==typeof i.contents&&(t=i.contents),"mocks.json"===i.path&&"string"==typeof i.contents)try{let t=$.SharedSliceContent.decode(JSON.parse(i.contents));if("Left"===t._tag)console.warn("Failed to decode mocks.json for slice: ".concat(e.name));else{let e=t.right;Array.isArray(e)&&e.length>0&&(n=e)}}catch(t){console.warn("Failed to decode mocks.json for slice: ".concat(e.name))}let h={};void 0!==d.variations&&d.variations.length>0&&(await Promise.allSettled(d.variations.map(async t=>{try{let n="".concat(e.path,"/screenshot-").concat(t.id,".png"),l=await o.getFileContents(n,i,!0);if(l instanceof ArrayBuffer){let e=new Blob([l],{type:"image/png"}),n=new File([e],"screenshot-".concat(t.id,".png"),{type:"image/png"});h[t.id]=n,void 0===a&&void 0!==d.variations[0]&&t.id===d.variations[0].id&&(a=URL.createObjectURL(e),r=n)}}catch(e){console.warn("Failed to fetch screenshot for variation ".concat(t.id,":"),e instanceof Error?e.message:String(e))}}))).forEach((e,t)=>{if("rejected"===e.status){var n;console.warn("Failed to fetch screenshot for variation ".concat(null===(n=d.variations[t])||void 0===n?void 0:n.id,":"),e.reason instanceof Error?e.reason.message:String(e.reason))}});let u=null!=r?r:new File([],"".concat(d.name,".json"),{type:"application/json"}),p={image:u,thumbnailUrl:null!=a?a:URL.createObjectURL(u),model:d,files:m,componentContents:t,mocks:n,screenshots:Object.keys(h).length>0?h:void 0};l.push(p)}catch(t){console.warn("Error fetching slice ".concat(e.name,":"),t instanceof Error?t.message:String(t))}};await Q(n,6,r)}return l},eo=async e=>{let{api:t,branch:n,directoryPath:i}=e,a=[],o=!1;try{let e=await t.getDirectoryContents(i);o=!0;let l=e.filter(e=>"file"===e.type),r=e.filter(e=>"dir"===e.type);for(let e of(await Q(l,8,async e=>{if("model.json"===e.name)return null;try{let i=[".png",".jpg",".jpeg",".gif",".svg",".ico",".webp"].some(t=>e.name.toLowerCase().endsWith(t)),a=await t.getFileContents(e.path,n,i);return{path:e.name,contents:a,isBinary:i}}catch(t){return console.warn("Failed to fetch file ".concat(e.path,":"),t instanceof Error?t.message:String(t)),null}})))e&&a.push(e);for(let e of r)for(let i of(await eo({api:t,branch:n,directoryPath:e.path})))a.push({...i,path:"".concat(e.name,"/").concat(i.path)})}catch(e){console.warn("GitHub API failed for directory ".concat(i,", trying Search API..."),e instanceof Error?e.message:String(e))}if(!o)try{console.log("Using GitHub Search API to find all files in ".concat(i,"..."));let e=await t.searchCode({path:i});if(e.items&&e.items.length>0){for(let o of(console.log("Found ".concat(e.items.length," file(s) via Search API for ").concat(i)),await Q(e.items,8,async e=>{try{if("model.json"===e.name)return null;let a=e.path.startsWith(i+"/")?e.path.slice(i.length+1):e.name,o=[".png",".jpg",".jpeg",".gif",".svg",".ico",".webp",".woff",".woff2",".ttf",".eot",".otf",".pdf",".zip",".gz"].some(t=>e.name.toLowerCase().endsWith(t)),l=await t.getFileContents(e.path,n,o);return{path:a,contents:l,isBinary:o}}catch(t){return console.warn("Error fetching file ".concat(e.path,":"),t instanceof Error?t.message:String(t)),null}})))o&&a.push(o);console.log("Fetched ".concat(a.length," file(s) from ").concat(i," via Search API"))}else console.warn("GitHub Search API found no files in ".concat(i))}catch(t){let e=t instanceof Error?t.message:String(t);e.includes("403")?console.warn("GitHub Search API returned 403 for ".concat(i,". Cannot fetch files without API access.")):console.warn("Error using GitHub Search API for ".concat(i,":"),e)}return a};function el(){let[e,t]=(0,s.useState)(!1),[n,i]=(0,s.useState)([]);return{isLoadingSlices:e,slices:n,resetSlices:()=>{i([]),t(!1)},handleImportFromGithub:async e=>{try{let n;t(!0);let{owner:a,repo:o}=et(e);if(!a||!o)throw F.Am.error("Invalid GitHub URL format"),t(!1),Error("Invalid GitHub URL format");let l=await en({owner:a,repo:o});try{n=await ei({owner:a,repo:o,branch:l})}catch(e){throw console.error("Failed to fetch slicemachine.config.json:",e),F.Am.error("Failed to fetch slicemachine.config.json: ".concat(e instanceof Error?e.message:"Unknown error")),t(!1),e}if(0===n.length)throw console.warn("No libraries were found in the SM config."),t(!1),F.Am.error("No libraries were found in the SM config."),Error("No libraries were found in the SM config.");let r=await ea({owner:a,repo:o,branch:l,libraries:n});if(0===r.length)throw F.Am.error("Error fetching slices from the repository"),t(!1),Error("No slices were found in the libraries.");return i(r),t(!1),F.Am.success("Found ".concat(r.length," slice(s) from ").concat(n.length," library/libraries")),r}catch(e){return console.error("Error importing from GitHub:",e),F.Am.error("Error importing from GitHub: ".concat(e instanceof Error?e.message:"Unknown error")),t(!1),[]}}}}var er=n(98250);async function es(e){let{libraries:t=[]}=await Y.managerClient.project.getSliceMachineConfig(),n=t[0];if(!n)throw Error("No library found in the config.");await Q(e,3,async e=>{let{errors:t}=await Y.managerClient.slices.createSlice({libraryID:n,model:e.model,componentContents:e.componentContents});if(t.length)throw Error("Failed to create slice ".concat(e.model.id,"."))});let i=await Q(e,3,async e=>{let{model:t,image:i,langSmithUrl:a,mocks:o,files:l,screenshots:r}=e;if(o&&Array.isArray(o)&&o.length>0){let{errors:e}=await Y.managerClient.slices.updateSliceMocks({libraryID:n,sliceID:t.id,mocks:o});e.length&&console.warn("Failed to update mocks for slice ".concat(t.id,":"),e)}return r&&Object.keys(r).length>0?await Promise.all(Object.entries(r).map(async e=>{let[i,a]=e;a.size>0&&await Y.managerClient.slices.updateSliceScreenshot({libraryID:n,sliceID:t.id,variationID:i,data:a})})):i.size>0&&void 0!==t.variations&&t.variations.length>0&&await Y.managerClient.slices.updateSliceScreenshot({libraryID:n,sliceID:t.id,variationID:t.variations[0].id,data:i}),console.log("About to write files for slice ".concat(t.id,":"),l?"".concat(l.length," file(s) - ").concat(l.map(e=>e.path).join(", ")):"no files"),l&&l.length>0?await ec({libraryID:n,sliceID:t.id,files:l}):console.warn("No files to write for slice ".concat(t.id,". Files:"),l),{model:t,langSmithUrl:a}});return{library:n,slices:i}}async function ec(e){let{libraryID:t,sliceID:n,files:i}=e;if(0===i.length)return;let a=i.filter(e=>"mocks.json"!==e.path&&!e.path.startsWith("screenshot-")&&!e.path.match(/^index\.(tsx?|jsx?|vue|svelte)$/));if(console.log("Writing ".concat(a.length," additional file(s) for slice ").concat(n,":"),a.map(e=>e.path)),0!==a.length)try{let e=a.map(e=>{if(e.isBinary)return{path:e.path,contents:e.contents,isBinary:!0};if("string"==typeof e.contents)return{path:e.path,contents:e.contents,isBinary:!1};throw Error("Unexpected file contents type for ".concat(e.path))}),i=await Y.managerClient.slices.writeSliceFiles({libraryID:t,sliceID:n,files:e});i.errors.length>0?console.error("Errors writing files for slice ".concat(n,":"),i.errors.map(e=>{var t;return null!==(t=e.message)&&void 0!==t?t:String(e)})):console.log("Successfully wrote ".concat(a.length," file(s) for slice ").concat(n))}catch(e){console.error("Error writing files for slice ".concat(n,":"),e instanceof Error?e.message:String(e))}}let ed=(0,s.createContext)(void 0);function em(e){let{children:t}=e,[n,a]=(0,s.useState)([]),[o,l]=(0,s.useState)([]),[r,c]=(0,s.useState)(!1),{syncChanges:d}=(0,x.g)(),{createSliceSuccess:m,updateSliceMockSuccess:h}=(0,y.Z)(),{completeStep:u}=(0,er.k)(),p=(0,s.useRef)(crypto.randomUUID()),f=(0,s.useCallback)(e=>{a(t=>t.some(t=>t.model.id===e.model.id)?t.filter(t=>t.model.id!==e.model.id):[...t,e])},[]),b=(0,s.useCallback)(e=>{l(t=>t.some(t=>t.model.id===e.model.id)?t.filter(t=>t.model.id!==e.model.id):[...t,e])},[]),v=(0,s.useCallback)(e=>{l(e)},[]),j=(0,s.useCallback)(()=>{a([]),l([]),p.current=crypto.randomUUID()},[]),S=(0,s.useCallback)(async e=>{let{existingSlices:t,location:i,resetSlices:a}=e;if(0===n.length+o.length)throw F.Am.error("Please select at least one slice"),Error("No slices selected");let l=n.map(e=>e.model),r=o.map(e=>({image:e.image,model:e.model,files:e.files,componentContents:e.componentContents,mocks:e.mocks,screenshots:e.screenshots}));if(!(r.length>0))return j(),{slices:l};{let e=[],n=[...t.current,...l];for(let t of r){let i=function(e){let{existingSlices:t,newSlices:n,slice:i}=e,a=new Set,o=new Set;for(let{id:e,name:n}of t)a.add(e),o.add(n.toLowerCase());for(let e of n)a.add(e.model.id),o.add(e.model.name.toLowerCase());let l=i.id,r=2;for(;a.has(l);)l="".concat(i.id,"_").concat(r),r++;let s=i.name;for(r=2;o.has(s.toLowerCase());)s="".concat(i.name).concat(r),r++;return{...i,id:l,name:s}}({existingSlices:n,newSlices:e,slice:t.model});e.push({...t,model:i})}let o=p.current;c(!0);try{let{slices:t,library:n}=await es(e);if(o!==p.current)throw Error("Modal instance changed");await new Promise(e=>setTimeout(e,100));let s=(await (0,g.y0)()).libraries.map(t=>t.name!==n?t:{...t,components:t.components.map(t=>{let n=e.find(e=>e.model.id===t.model.id),i=t.mocks&&t.mocks.length>0?t.mocks:null==n?void 0:n.mocks;return{...t,mocks:null!=i?i:t.mocks}})});for(let e of(m(s),r))e.mocks&&Array.isArray(e.mocks)&&e.mocks.length>0&&h({libraryID:n,sliceID:e.model.id,mocks:e.mocks});d();let f=[...l,...t.map(e=>e.model)];for(let{model:e}of(c(!1),j(),a(),u("createSlice"),t))g.Xe.track({event:"slice:created",id:e.id,name:e.name,library:n,location:i,mode:"import"});return{slices:f,library:n}}catch(e){if(o!==p.current)throw e;throw c(!1),F.Am.error("An unexpected error happened while adding slices."),e}}},[n,o,d,m,h,u,j]),w=n.length+o.length;return(0,i.jsx)(ed.Provider,{value:{selectedLocalSlices:n,selectedLibrarySlices:o,toggleLocalSlice:f,toggleLibrarySlice:b,setAllLibrarySlices:v,reset:j,submit:S,isSubmitting:r,totalSelected:w},children:t})}function eh(){let e=(0,s.useContext)(ed);if(void 0===e)throw Error("useReuseExistingSlicesContext must be used within ReuseExistingSlicesProvider");return e}var eu=n(62434);function ep(e){let{thumbnailUrl:t,model:n,selected:o=!0,onSelectedChange:l}=e,r=(0,i.jsxs)(i.Fragment,{children:[void 0!==t&&t?(0,i.jsx)(eu.ZB,{src:t}):(0,i.jsx)(eu.ZB,{component:"div"}),(0,i.jsx)(eu.eW,{title:n.name,action:(0,i.jsx)("div",{onClick:e=>e.stopPropagation(),children:(0,i.jsx)(a.U,{checked:o,onCheckedChange:l})})})]});return(0,i.jsx)(eu.Zb,{interactive:!0,onClick:()=>{l(!o)},checked:o,size:"small",children:r})}function ef(){let[e,t]=(0,s.useState)(""),{isLoadingSlices:n,handleImportFromGithub:o,slices:l}=el(),{selectedLibrarySlices:r,toggleLibrarySlice:c,setAllLibrarySlices:d}=eh(),{allSelected:m,someSelected:h}=(0,s.useMemo)(()=>0===l.length?{allSelected:!1,someSelected:!1}:{allSelected:l.every(e=>r.some(t=>t.model.id===e.model.id)),someSelected:l.some(e=>r.some(t=>t.model.id===e.model.id))},[l,r]),u=async()=>{d(await o(e))};if(0===l.length)return(0,i.jsx)(a.D,{padding:16,height:"100%",flexDirection:"column",gap:16,children:(0,i.jsx)(a.D,{flexDirection:"column",gap:8,children:(0,i.jsxs)(a.D,{display:"flex",flexDirection:"column",gap:8,padding:16,border:!0,borderRadius:8,children:[(0,i.jsx)(a.bL,{color:"grey11",children:"Import from GitHub"}),(0,i.jsx)(a.bN,{placeholder:"https://github.com/username/repository",value:e,onValueChange:t}),(0,i.jsx)(a.E,{onClick:()=>void u(),disabled:!e.trim()||n,loading:n,color:"purple",children:n?"Loading slices...":"Import from GitHub"})]})})});let p="Select all slices";return m?p="Selected all slices (".concat(r.length,")"):h&&(p="".concat(r.length," of ").concat(l.length," selected")),(0,i.jsxs)(a.D,{flexDirection:"column",flexGrow:1,minHeight:0,children:[(0,i.jsx)(a.D,{padding:{block:12,inline:16},alignItems:"center",gap:8,children:(0,i.jsx)(a.aR,{value:p,children:(0,i.jsx)(a.U,{checked:m,indeterminate:h&&!m,onCheckedChange:e=>{e?d(l):d([])}})})}),(0,i.jsx)(a.bn,{stableScrollbar:!1,children:(0,i.jsx)(a.D,{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:16,padding:{inline:16,bottom:16},children:l.map(e=>{let t=r.some(t=>t.model.id===e.model.id);return(0,i.jsx)(ep,{model:e.model,thumbnailUrl:e.thumbnailUrl,selected:t,onSelectedChange:()=>{c(e)}},e.model.id)})})})]})}var eg=n(51507);function ex(e){let{availableSlices:t}=e,{selectedLocalSlices:n,toggleLocalSlice:o}=eh();return 0===t.length?(0,i.jsx)(a.D,{padding:16,height:"100%",flexDirection:"column",gap:16,children:(0,i.jsx)(a.D,{flexDirection:"column",gap:8,children:(0,i.jsx)(a.D,{display:"flex",flexDirection:"column",gap:8,padding:16,alignItems:"center",justifyContent:"center",children:"No local slices available"})})}):(0,i.jsx)(a.bn,{stableScrollbar:!1,children:(0,i.jsx)(a.D,{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:16,flexGrow:1,padding:16,minHeight:0,children:t.map(e=>{let t=n.some(t=>t.model.id===e.model.id);return(0,i.jsx)(eg.b,{action:{type:"checkbox"},mode:"selection",onSelectedChange:()=>{o(e)},selected:t,slice:e,variant:"outlined"},"".concat(e.from,"-").concat(e.model.name))})})})}function eb(e){let{open:t,location:n,typeName:o,availableSlices:l=[],onSuccess:r,onClose:c}=e,[d,m]=(0,s.useState)("local"),h=function(e){let{open:t}=e,n=(0,s.useRef)([]);return(0,s.useEffect)(()=>{t&&(n.current=[],Y.managerClient.slices.readAllSlices().then(e=>{n.current=e.models.map(e=>{let{model:t}=e;return t})}).catch(()=>null))},[t]),n}({open:t}),{resetSlices:u}=el(),{submit:p,isSubmitting:f,totalSelected:g,reset:x}=eh(),b=async()=>{try{let e=await p({existingSlices:h,location:n,resetSlices:u});r(e)}catch(e){}};return(0,i.jsxs)(a.ae,{open:t,onOpenChange:e=>{e||f||(c(),x(),u(),m("local"))},children:[(0,i.jsx)(a.al,{title:"Reuse an existing slice"}),(0,i.jsxs)(a.aj,{gap:0,children:[(0,i.jsx)(a.ak,{hidden:!0,children:"Select existing slices or import slices from a GitHub repository"}),(0,i.jsxs)(a.D,{flexDirection:"column",flexGrow:1,minHeight:0,children:[(0,i.jsxs)(a.D,{justifyContent:"space-between",padding:16,border:{bottom:!0},children:[(0,i.jsxs)(a.D,{gap:8,children:[(0,i.jsx)(a.bD,{selected:"local"===d,onClick:()=>m("local"),children:"Local Slices"}),(0,i.jsx)(a.bD,{selected:"library"===d,onClick:()=>m("library"),children:"Library Slices"})]}),"library"===d&&"<repo-select>"]}),(0,i.jsx)(ey,{selected:"local"===d,children:(0,i.jsx)(ex,{availableSlices:l})}),(0,i.jsx)(ey,{selected:"library"===d,children:(0,i.jsx)(ef,{})})]}),(0,i.jsxs)(a.ah,{children:[(0,i.jsx)(a.ai,{disabled:f,size:"medium"}),(0,i.jsxs)(a.af,{disabled:0===g,loading:f,onClick:()=>void b(),size:"medium",children:[W(n,o)," (",g,")"]})]})]})]})}function ey(e){let{children:t,selected:n}=e;return n?(0,i.jsx)(a.D,{display:"flex",flexDirection:"column",flexGrow:1,minHeight:0,children:t}):(0,i.jsx)(a.D,{display:"none",minHeight:0,children:t})}function ev(e){return(0,i.jsx)(em,{children:(0,i.jsx)(eb,{...e})})}var ej=n(27213);let eS=e=>{let{openCreateSliceModal:t,openCreateSliceFromImageModal:n,openUpdateSliceZoneModal:o,openSlicesTemplatesModal:l,isSlicesTemplatesSupported:r}=e,s=(0,ej.F)({menuType:"ActionList"});return(0,i.jsxs)(a.s,{"data-testid":"slice-zone-blank-slate",sx:{width:648},children:[(0,i.jsx)(a.x,{lineColor:"purple9",backgroundColor:"purple5",name:"add",size:"large"}),(0,i.jsx)(a.z,{size:"big",children:"Add slices"}),(0,i.jsx)(a.w,{children:"Slices are reusable website sections. You can use them on different pages and write unique content for each. Each slice has its own component in your code."}),(0,i.jsx)(a.v,{children:(0,i.jsxs)(a.A,{children:[(0,i.jsx)(a.b,{renderStartIcon:()=>s.fromImage.BackgroundIcon,onClick:n,description:s.fromImage.description,children:s.fromImage.title}),(0,i.jsx)(a.b,{renderStartIcon:()=>s.fromScratch.BackgroundIcon,onClick:t,description:s.fromScratch.description,children:s.fromScratch.title}),r&&(0,i.jsx)(a.b,{renderStartIcon:()=>s.fromTemplate.BackgroundIcon,onClick:l,description:s.fromTemplate.description,children:s.fromTemplate.title}),(0,i.jsx)(a.b,{renderStartIcon:()=>s.fromExisting.BackgroundIcon,onClick:o,description:s.fromExisting.description,children:s.fromExisting.title})]})})]})};function ew(e){let{customType:t,tabId:n,slices:i}=e,a={...t};return i.forEach(e=>{a={...a,tabs:a.tabs.map(t=>t.key===n&&t.sliceZone?{...t,sliceZone:{key:t.sliceZone.key,value:[{key:e.id,value:e},...t.sliceZone.value]}}:t)}}),g.Xe.track({event:"custom-type:slice-zone-updated",customTypeId:t.id}),a}var eC=n(18566);async function eI(){try{let{templates:e,errors:t}=await Y.managerClient.sliceTemplateLibrary.readLibrary({});if(t.length>0)throw t;return e.map(e=>({model:e.model,screenshots:Object.fromEntries(Object.entries(e.screenshots).map(e=>{let[t,n]=e;return[t,URL.createObjectURL(n)]}))}))}catch(e){return[]}}var eD=n(6256),ek=n(39204),eT=n(7723),e_=n(33986),eA=n(30527),eE=n(55862);let eL=e=>{let{deleteSliceZone:t,closeDeleteSliceZoneModal:n}=e;return(0,i.jsx)(eE.Z,{isOpen:!0,shouldCloseOnOverlayClick:!0,style:{content:{maxWidth:612}},onRequestClose:n,children:(0,i.jsx)(eA.Z,{bodySx:{p:0,bg:"white",position:"relative",height:"100%",padding:16},footerSx:{position:"sticky",bottom:0,p:0},sx:{border:"none",overflow:"hidden"},borderFooter:!0,Header:(0,i.jsxs)(E.kC,{sx:{position:"sticky",top:0,zIndex:1,p:"16px",alignItems:"center",justifyContent:"space-between",borderBottom:e=>{var t;return"1px solid ".concat(String(null===(t=e.colors)||void 0===t?void 0:t.borders))}},children:[(0,i.jsx)(E.X6,{sx:{fontSize:"14px",fontWeight:"bold",ml:1},children:"Do you really want to delete Slice Zone?"}),(0,i.jsx)(E.x8,{type:"button",onClick:n})]}),Footer:()=>(0,i.jsxs)(E.kC,{sx:{justifyContent:"flex-end",height:64,alignItems:"center",paddingRight:16,borderTop:e=>{var t;return"1px solid ".concat(String(null===(t=e.colors)||void 0===t?void 0:t.darkBorders))},backgroundColor:"gray"},children:[(0,i.jsx)(e_.z,{label:"Cancel",variant:"secondary",onClick:n,sx:{mr:"10px",fontWeight:"bold",color:"grey12",borderRadius:6}}),(0,i.jsx)(e_.z,{label:"Delete",variant:"danger",onClick:t,sx:{minHeight:39,minWidth:78}})]}),children:(0,i.jsx)(E.nv,{children:"You're about to delete Slice Zone."})})})};var ez=n(84879),eN=n(63908),eP=n(63019),eM=n(65375),eF=n.n(eM);let eO=e=>{var t;let{isOpen:n,close:o,onSubmit:l,isLoading:r,slice:d,libraries:m}=e,{remoteSlices:h}=(0,c.v9)(e=>({remoteSlices:(0,eT.sT)(e)})),u={from:null===(t=m[0])||void 0===t?void 0:t.name,sliceName:(0,B.MP)(d.key)},[p,g]=(0,s.useState)(u),[x,b]=(0,s.useState)();function y(e){g(e),b((0,eP.h)(e,m,h))}return(0,f.pQ)(n,()=>{n||(g(u),b(void 0))}),(0,i.jsxs)(a.ae,{open:n,onOpenChange:e=>!e&&o(),size:{width:448,height:"auto"},children:[(0,i.jsx)(a.al,{title:"Upgrade slice"}),(0,i.jsx)(a.aj,{children:(0,i.jsx)(a.aJ,{onSubmit:function(){x&&Object.keys(x).length>0||l({libraryID:p.from,sliceID:p.sliceName})},children:(0,i.jsxs)(a.D,{flexDirection:"column",children:[(0,i.jsxs)(a.bn,{className:eF().scrollArea,children:[(0,i.jsx)(a.bL,{variant:"normal",color:"grey11",children:"This will create a new slice with the same fields. The new slice will replace the legacy slice in all of your types, and the existing slice content will be re-mapped to the new slice."}),(0,i.jsx)(a.bL,{variant:"normal",color:"grey11",children:"This will not migrate your component. You will need to do that manually."}),(0,i.jsxs)(a.D,{flexDirection:"column",gap:4,children:[(0,i.jsx)(a.aM,{label:"Slice name *",placeholder:"Pascalised Slice API ID (e.g. ".concat((0,B.MP)(d.key),")"),error:null==x?void 0:x.sliceName,value:p.sliceName,onValueChange:e=>y({...p,sliceName:e.slice(0,30)}),"data-testid":"slice-name-input"}),(0,i.jsx)(a.bL,{variant:"normal",color:"grey11",children:"A display name for the slice"})]}),(0,i.jsxs)(a.D,{flexDirection:"column",gap:4,children:[(0,i.jsx)("label",{className:eF().label,children:(0,i.jsx)(a.bL,{variant:"bold",children:"Slice library *"})}),(0,i.jsx)(a.bq,{size:"medium",color:"grey",startIcon:"folder",flexContent:!0,value:p.from,onValueChange:e=>{e&&y({...p,from:e})},children:m.map(e=>(0,i.jsx)(a.bt,{value:e.name,children:e.name},e.name))}),(0,i.jsx)(a.bL,{variant:"normal",color:"grey11",children:"The library where we'll store your slice"})]})]}),(0,i.jsxs)(a.ah,{children:[(0,i.jsx)(a.ai,{size:"medium"}),(0,i.jsx)(a.af,{type:"submit",size:"medium",loading:r,disabled:x&&Object.keys(x).length>0,children:"Upgrade"})]})]})})})]})};var eU=n(96009),eZ=n.n(eU);let eG=e=>{var t,n;let{isOpen:o,close:l,onSubmit:r,isLoading:c,slice:d,sliceName:m,libraries:h,localSharedSlices:u}=e,p={libraryID:null===(t=u[0])||void 0===t?void 0:t.from,sliceID:null===(n=u[0])||void 0===n?void 0:n.model.id,variationID:eZ()(d.key),variationName:m},[g,x]=(0,s.useState)(!0),[b,y]=(0,s.useState)(p),[v,j]=(0,s.useState)({});function S(e){y(e),j(eB(e,h))}return(0,f.pQ)(o,()=>{o||(y(p),j({}))}),(0,i.jsxs)(a.ae,{open:o,onOpenChange:e=>!e&&l(),size:{width:448,height:"auto"},children:[(0,i.jsx)(a.al,{title:"Convert to slice variation"}),(0,i.jsx)(a.aj,{children:(0,i.jsx)(a.aJ,{onSubmit:function(){Object.keys(v).length>0||r(b)},children:(0,i.jsxs)(a.D,{display:"flex",flexDirection:"column",children:[(0,i.jsxs)(a.bn,{className:eF().scrollArea,children:[(0,i.jsx)(a.bL,{variant:"normal",color:"grey11",children:"If you have multiple slices that are similar, you can combine them as variations of the same slice."}),(0,i.jsxs)(a.D,{display:"flex",flexDirection:"column",gap:4,children:[(0,i.jsxs)("label",{className:eF().label,children:[(0,i.jsx)(a.bL,{variant:"bold",children:"Target slice *"}),"string"==typeof v.libraryID?(0,i.jsx)(a.bL,{variant:"small",color:"tomato10",children:v.libraryID}):null,"string"==typeof v.sliceID?(0,i.jsx)(a.bL,{variant:"small",color:"tomato10",children:v.sliceID}):null]}),(0,i.jsx)(a.bq,{size:"medium",color:"grey",startIcon:"viewDay",flexContent:!0,value:"".concat(b.libraryID,"::").concat(b.sliceID),onValueChange:e=>{if(e){let[t,n]=e.split("::");S({...b,libraryID:t,sliceID:n})}},children:u.map(e=>(0,i.jsxs)(a.bt,{value:"".concat(e.from,"::").concat(e.model.id),children:[e.from," ",">"," ",e.model.name," (",e.model.id,")"]},"".concat(e.from,"::").concat(e.model.id)))}),(0,i.jsx)(a.bL,{variant:"normal",color:"grey11",children:"Choose the slice to which you would like to add this variation."})]}),(0,i.jsx)(a.D,{display:"flex",flexDirection:"column",gap:4,children:(0,i.jsx)(a.aM,{label:"Variation name *",placeholder:m,error:v.variationName,value:b.variationName,onValueChange:e=>{let t={...b,variationName:e.slice(0,30)};g&&(t.variationID=eZ()(t.variationName)),S(t)},"data-testid":"variation-name-input"})}),(0,i.jsx)(a.D,{display:"flex",flexDirection:"column",gap:4,children:(0,i.jsx)(a.aM,{label:"ID *",placeholder:eZ()(d.key),error:v.variationID,value:b.variationID,onValueChange:e=>{x(!1),S({...b,variationID:e.slice(0,30)})},"data-testid":"variation-id-input"})})]}),(0,i.jsxs)(a.ah,{children:[(0,i.jsx)(a.ai,{size:"medium"}),(0,i.jsx)(a.af,{type:"submit",size:"medium",loading:c,disabled:Object.keys(v).length>0,children:"Convert"})]})]})})})]})},eB=(e,t)=>{let n={};e.libraryID||(n.libraryID="Cannot be empty.");let i=t.find(t=>t.path===e.libraryID);n.libraryID||i||(n.libraryID="Does not exist."),e.sliceID||(n.sliceID="Cannot be empty.");let a=null==i?void 0:i.components.find(t=>t.model.id===e.sliceID);if(n.sliceID||a||(n.sliceID="Does not exist."),e.variationName||(n.variationName="Cannot be empty."),e.variationID){var o;(null!==(o=null==a?void 0:a.model.variations.map(e=>e.id))&&void 0!==o?o:[]).includes(e.variationID)&&(n.variationID="Slice variation ID is already taken.")}else n.variationID="Cannot be empty.";return n},eR=e=>{var t,n;let{isOpen:o,close:l,onSubmit:r,isLoading:c,identicalSlices:d}=e,m=null!==(n=null===(t=d[0])||void 0===t?void 0:t.path)&&void 0!==n?n:"",[h,u]=(0,s.useState)(m),[p,g]=(0,s.useState)();return(0,f.pQ)(o,()=>{o||(u(m),g(void 0))}),(0,i.jsxs)(a.ae,{open:o,onOpenChange:e=>!e&&l(),size:{width:448,height:"auto"},children:[(0,i.jsx)(a.al,{title:"Merge with an existing slice"}),(0,i.jsx)(a.aj,{children:(0,i.jsx)(a.aJ,{onSubmit:function(){if(p)return;let[e,t,n]=h.split("::");r({libraryID:e,sliceID:t,variationID:n})},children:(0,i.jsxs)(a.D,{display:"flex",flexDirection:"column",children:[(0,i.jsxs)(a.bn,{className:eF().scrollArea,children:[(0,i.jsx)(a.bL,{variant:"normal",color:"grey11",children:"If you have multiple identical slices, you can merge them. All of your content will be remapped to the target slice."}),(0,i.jsxs)(a.D,{display:"flex",flexDirection:"column",gap:4,children:[(0,i.jsxs)("label",{className:eF().label,children:[(0,i.jsx)(a.bL,{variant:"bold",children:"Target slice*"}),"string"==typeof p?(0,i.jsx)(a.bL,{variant:"small",color:"tomato10",children:p}):null]}),(0,i.jsx)(a.bq,{size:"medium",color:"grey",startIcon:"viewDay",flexContent:!0,value:h,onValueChange:function(e){u(e),e||g("Cannot be empty.")},children:d.map(e=>(0,i.jsx)(a.bt,{value:e.path,children:e.path.split("::").join(" > ")},e.path))}),(0,i.jsx)(a.bL,{variant:"normal",color:"grey11",children:"Choose a slice that you would like to merge this into."})]})]}),(0,i.jsxs)(a.ah,{children:[(0,i.jsx)(a.ai,{size:"medium"}),(0,i.jsx)(a.af,{type:"submit",size:"medium",loading:c,disabled:!!p,children:"Merge"})]})]})})})]})},eH=e=>{var t;let{slice:n,path:o}=e,{refreshState:l}=(0,y.Z)(),[r,d]=(0,s.useState)(!1),[m,h]=(0,s.useState)(),{setCustomType:u}=w(),{libraries:p}=(0,c.v9)(e=>({libraries:(0,eT.Sd)(e)})),f="Slice"===n.value.type&&null!==(t=n.value.fieldset)&&void 0!==t?t:n.key,x=p.filter(e=>e.isLocal),b=x.map(e=>e.components).flat(),v=eK(n,f,b),j=async e=>{var t,i,a;if(!m)return;d(!0),g.Xe.track({event:"legacy-slice:converted",id:e.sliceID,variation:null!==(t=e.variationID)&&void 0!==t?t:"default",library:e.libraryID,conversionType:m});let{errors:r}=await Y.managerClient.slices.convertLegacySliceToSharedSlice({model:n.value,src:{...o,sliceID:n.key},dest:{libraryID:e.libraryID,sliceID:e.sliceID,variationName:null!==(i=e.variationName)&&void 0!==i?i:"Default",variationID:null!==(a=e.variationID)&&void 0!==a?a:"default"}});if(r.length)throw console.error("Could not convert slice `".concat(f,"`"),r),F.Am.error("Could not convert slice `".concat(f,"`")),r;let{model:s,errors:c}=await Y.managerClient.customTypes.readCustomType({id:o.customTypeID});if(c.length||!s){console.error("Could not refresh custom type view `".concat(o.customTypeID,"`"),c),F.Am.error("Could not refresh custom type view `".concat(o.customTypeID,"`"));return}switch(l(await (0,g.y0)()),d(!1),h(void 0),m){case"as_new_slice":F.Am.success("".concat(f," has been upgraded to a new slice ").concat(e.libraryID," > ").concat(e.sliceID));break;case"as_new_variation":F.Am.success("".concat(f," has been converted as a variation of ").concat(e.libraryID," > ").concat(e.sliceID));break;default:F.Am.success("".concat(f," has been merged with ").concat(e.libraryID," > ").concat(e.sliceID))}u({customType:s})},S={path:o,slice:n,sliceName:f,libraries:x,localSharedSlices:b,identicalSlices:v,close:()=>h(void 0),onSubmit:j,isLoading:r};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(a.ar,{children:[(0,i.jsx)(a.av,{children:(0,i.jsx)(a.E,{"data-testid":"convert-legacy-slice",startIcon:"refresh",endIcon:"arrowDropDown",size:"medium",color:"grey",children:"Migrate legacy slice"})}),(0,i.jsxs)(a.as,{align:"start",children:[(0,i.jsx)(a.at,{startIcon:(0,i.jsx)(a.aX,{name:"folder",size:"large"}),description:"Use it with new types",onSelect:()=>h("as_new_slice"),children:"Upgrade slice"}),(0,i.jsx)(a.at,{startIcon:(0,i.jsx)(a.aX,{name:"viewDay",size:"large"}),description:"Add it to another slice",onSelect:()=>h("as_new_variation"),disabled:!b.length,children:"Convert to slice variation"}),(0,i.jsx)(a.at,{startIcon:(0,i.jsx)(a.aX,{name:"driveFileMove",size:"large"}),description:"Combine identical slices",onSelect:()=>h("merge_with_identical"),disabled:!v.length,children:"Merge with another slice"})]})]}),(0,i.jsx)(eO,{...S,isOpen:"as_new_slice"===m}),(0,i.jsx)(eG,{...S,isOpen:"as_new_variation"===m}),(0,i.jsx)(eR,{...S,isOpen:"merge_with_identical"===m})]})},eK=(e,t,n)=>(0,s.useMemo)(()=>{let i=[],a=(0,eN.ux)(e.value,t);for(let e of n)for(let t of e.model.variations){let n=(0,eN.ux)(t,e.model.name);a.primary===n.primary&&a.items===n.items&&i.push({libraryID:e.from,sliceID:e.model.id,variationID:t.id,path:"".concat(e.from,"::").concat(e.model.id,"::").concat(t.id)})}return i},[e,t,n]),eX=e=>{let{slice:t,path:n}=e,[o]=(0,ez.E)("legacySliceUpgrader"),l=o.enabled?"This Slice was created with the Legacy Builder. It needs to be converted first to be used within Slice Machine.":"This Slice was created with the Legacy Builder, and is incompatible with Slice Machine. You cannot edit, push, or delete it in Slice Machine. In order to proceed, manually remove the Slice from your type model. Then create a new Slice with the same fields using Slice Machine.";return(0,i.jsxs)(eu.Zb,{children:[(0,i.jsx)(eu.ZB,{component:"div",children:(0,i.jsx)(a.D,{alignItems:"center",justifyContent:"center",children:(0,i.jsx)(a.bL,{color:"grey11",component:"span",children:"No screenshot available"})})}),(0,i.jsxs)(eu.T$,{children:[(0,i.jsx)(a.c3,{content:l,side:"bottom",children:(0,i.jsx)(a.m,{color:"purple",title:"Legacy Slice"})}),o.enabled?(0,i.jsx)(eH,{slice:t,path:n}):null]}),(0,i.jsx)(eu.eW,{subtitle:"1 variation",title:(0,eN.Dj)(t.value)})]})};var eV=n(21151);let eq=e=>{let{slices:t,format:n,path:a,onRemoveSharedSlice:o}=e,l=t.some(e=>"SharedSlice"!==e.type),r=v.$[n],[c]=(0,ez.E)("legacySliceUpgrader");return(0,s.useEffect)(()=>{l&&(c.enabled?F.Am.info("This ".concat(r.name({start:!1,plural:!1})," contains legacy slices that can be upgraded.")):F.Am.warning("This ".concat(r.name({start:!1,plural:!1})," contains slices that are incompatible.")))},[l]),(0,i.jsx)(eV.Z,{elems:t,defineElementKey:e=>"SharedSlice"!==e.type?e.payload.key:e.payload.model.name,renderElem:e=>{if("SharedSlice"!==e.type){let t=e.payload;return(0,i.jsx)(eX,{slice:t,path:a})}{let t=e.payload;return(0,i.jsx)(eg.b,{action:{type:"remove",onRemove:()=>{o(t.model.id)}},mode:"navigation",slice:t,variant:"solid"})}},sx:{padding:"16px"}})};async function eW(e){try{let{templateIDs:t,localLibrariesNames:n,location:i,onSuccess:a}=e,{data:o,errors:l}=await Y.managerClient.sliceTemplateLibrary.createSlices({templateIDs:t});if(l.length>0||void 0===o)throw l;o.sliceIDs.forEach((e,a)=>{g.Xe.track({event:"slice:created",id:e,name:e,library:n[0],location:i,mode:"template",sliceTemplate:t[a]})}),await a(o.sliceIDs)}catch(t){let e="Internal Error: Slice(s) not created";console.error(e,t),F.Am.error(e)}}var eY=n(26109),e$=e=>{let{availableSlices:t,values:n}=e;return(0,i.jsx)(A.F2,{name:"sliceKeys",render:e=>(0,i.jsx)(eV.Z,{gridTemplateMinPx:"200px",elems:t,defineElementKey:e=>"".concat(e.from,"-").concat(e.model.name),renderElem:t=>{let a=n.sliceKeys.includes(t.model.id);return(0,i.jsx)(eg.b,{action:{type:"checkbox"},mode:"selection",onSelectedChange:i=>{i?e.push(t.model.id):e.remove(n.sliceKeys.indexOf(t.model.id))},selected:a,slice:t,variant:"outlined"})}})})};let eJ=e=>{let{formId:t,close:n,onSuccess:a,availableSlicesTemplates:o,localLibraries:l,location:r}=e,{createSliceSuccess:s}=(0,y.Z)();return(0,i.jsx)(_.Z,{isOpen:!0,buttonLabel:"Add",formId:t,close:n,onSubmit:e=>{let{sliceKeys:t}=e;eW({templateIDs:t,localLibrariesNames:l.map(e=>e.name),location:r,onSuccess:async e=>{s((await (0,g.y0)()).libraries),a(await Promise.all(e.map(async e=>(await Y.managerClient.slices.readSlice({libraryID:l[0].name,sliceID:e})).model).filter(e=>void 0!==e)))}})},initialValues:{sliceKeys:[]},content:{title:"Use template slices"},validate:e=>{if(0===e.sliceKeys.length)return{sliceKeys:"Select at least one template to add"}},actionMessage:e=>{let{errors:t}=e;return void 0!==t.sliceKeys?(0,i.jsx)(E.xv,{sx:{color:"error"},children:t.sliceKeys}):void 0},children:e=>{let{values:t}=e;return(0,i.jsx)(e$,{values:t,availableSlices:o.map(e=>({extension:"",fileName:"",from:"",href:"",pathToSlice:"",model:eY.id.toSM(e.model),screenshots:Object.entries(e.screenshots).reduce((e,t)=>({...e,[t[0]]:{url:t[1]}}),{})}))})}})},eQ=(e,t)=>{let n=(t||[]).reduce((e,t)=>[...e,...t.components],[]),{slicesInSliceZone:i,notFound:a}=e.value.reduce((e,t)=>{let{key:i,value:a}=t;if("SharedSlice"===a.type){let t=n.find(e=>e.model.id===i);return t?{...e,slicesInSliceZone:[...e.slicesInSliceZone,{type:"SharedSlice",payload:t}]}:{...e,notFound:[...e.notFound,{key:i}]}}return{...e,slicesInSliceZone:[...e.slicesInSliceZone,{type:"Slice",payload:{key:i,value:a}}]}},{slicesInSliceZone:[],notFound:[]});return{availableSlices:n,slicesInSliceZone:i,notFound:a}};var e0=e=>{var t,n;let{customType:o,onCreateSliceZone:l,onDeleteSliceZone:r,onRemoveSharedSlice:d,sliceZone:m,tabId:h}=e,u=(0,eC.QT)(eI,[]),[p,f]=(0,s.useState)(!1),[x,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(!1),[S,C]=(0,s.useState)(!1),{remoteSlices:I,libraries:D}=(0,c.v9)(e=>({remoteSlices:(0,eT.sT)(e),libraries:(0,eT.Sd)(e),slices:(0,eT.xC)(e)})),{setCustomType:k}=w(),{completeStep:_}=(0,er.k)(),{openLoginModal:A}=(0,y.Z)(),E=(0,ej.F)({menuType:"Dropdown"}),L=D.filter(e=>e.isLocal),{availableSlices:z,slicesInSliceZone:N,notFound:P}=(0,s.useMemo)(()=>m?eQ(m,D):{availableSlices:[],slicesInSliceZone:[],notFound:[]},[m,D]),[M,U]=(0,s.useState)(!1);(0,s.useEffect)(()=>{(null==P?void 0:P.length)&&P.forEach(e=>{let{key:t}=e;d(t)})},[P]);let Z=N.filter(e=>"SharedSlice"===e.type).map(e=>e.payload),G=z.filter(e=>!Z.some(t=>t.model.id===e.model.id)),B=()=>{b(!0)},R=()=>{j(!0)},H=async()=>{await Y.managerClient.user.checkIsLoggedIn()?C(!0):A()},K=()=>{f(!0),g.Xe.track({event:"custom-type:open-add-from-templates",customTypeId:o.id,customTypeFormat:o.format})},X=()=>{b(!1)},W=()=>{j(!1)},$=()=>{C(!1)},J=()=>{f(!1)};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(O.Bu,{actions:m?(0,i.jsxs)(a.ar,{children:[(0,i.jsx)(a.av,{children:(0,i.jsx)(a.E,{color:"purple",startIcon:"add","data-testid":"add-new-slice-dropdown",children:"Add"})}),(0,i.jsxs)(a.as,{align:"end",children:[(0,i.jsx)(a.at,{renderStartIcon:()=>E.fromImage.BackgroundIcon,onSelect:()=>void H(),description:E.fromImage.description,children:E.fromImage.title}),(0,i.jsx)(a.at,{renderStartIcon:()=>E.fromScratch.BackgroundIcon,onSelect:R,description:E.fromScratch.description,children:E.fromScratch.title}),u.length>0?(0,i.jsx)(a.at,{onSelect:K,renderStartIcon:()=>E.fromTemplate.BackgroundIcon,description:E.fromTemplate.description,children:E.fromTemplate.title}):void 0,(0,i.jsx)(a.at,{onSelect:B,renderStartIcon:()=>E.fromExisting.BackgroundIcon,description:E.fromExisting.description,children:E.fromExisting.title})]})]}):void 0,toggle:"page"!==o.format||"Main"!==h?(0,i.jsx)(a.bC,{checked:!!m,onCheckedChange:e=>{e?l():U(!0)},size:"small","data-testid":"slice-zone-switch"}):void 0,children:"Slices"}),m?N.length>0?(0,i.jsx)(V.xR,{children:(0,i.jsx)(eq,{slices:N,format:o.format,path:{customTypeID:o.id,tabID:h,sliceZoneID:null!==(t=null==m?void 0:m.key)&&void 0!==t?t:""},onRemoveSharedSlice:d})}):(0,i.jsx)(a.D,{flexDirection:"column",flexGrow:1,justifyContent:"center",alignItems:"center",padding:{block:32},children:(0,i.jsx)(eS,{openUpdateSliceZoneModal:B,openCreateSliceModal:R,openCreateSliceFromImageModal:()=>void H(),openSlicesTemplatesModal:K,projectHasAvailableSlices:G.length>0,isSlicesTemplatesSupported:u.length>0})}):void 0,(0,i.jsx)(ev,{open:x,location:"".concat(o.format,"_type"),typeName:null!==(n=o.label)&&void 0!==n?n:o.id,availableSlices:G,onSuccess:e=>{let{slices:t,library:n}=e,a=ew({customType:o,tabId:h,slices:t});k({customType:T.Dc.fromSM(a),onSaveCallback:()=>{F.Am.success((0,i.jsx)(ek.GX,{message:"Slice(s) added to slice zone and created at: ",path:null!=n?n:""}))}}),_("createSlice"),X()},onClose:X}),p&&(0,i.jsx)(eJ,{formId:"tab-slicezone-form-".concat(h),availableSlicesTemplates:u,localLibraries:L,location:"".concat(o.format,"_type"),onSuccess:e=>{let t=ew({customType:o,tabId:h,slices:e});k({customType:T.Dc.fromSM(t),onSaveCallback:()=>{F.Am.success((0,i.jsx)(ek.GX,{message:"Slice template(s) added to slice zone and created at: ",path:"".concat(L[0].name,"/")}))}}),_("createSlice"),J()},close:J}),M&&(0,i.jsx)(eL,{closeDeleteSliceZoneModal:()=>{U(!1)},deleteSliceZone:()=>{r(),U(!1)}}),(null==L?void 0:L.length)!==0&&v&&(0,i.jsx)(eD.c,{onSuccess:e=>{let t=ew({customType:o,tabId:h,slices:[e]});k({customType:T.Dc.fromSM(t),onSaveCallback:()=>{F.Am.success((0,i.jsx)(ek.GX,{message:"New slice added to slice zone and created at: ",path:"".concat(L[0].name,"/")}))}}),W()},localLibraries:L,location:"".concat(o.format,"_type"),remoteSlices:I,onClose:W}),(0,i.jsx)(q.S,{open:S,location:"".concat(o.format,"_type"),onSuccess:e=>{let{slices:t,library:n}=e,a=ew({customType:o,tabId:h,slices:t});k({customType:T.Dc.fromSM(a),onSaveCallback:()=>{F.Am.success((0,i.jsx)(ek.GX,{message:"Slice(s) added to slice zone and created at: ",path:n}))}}),$()},onClose:$})]})};let e1=[Z.C.UID,Z.C.Image,Z.C.Text,Z.C.StructuredText,Z.C.Link,Z.C.Select,Z.C.Boolean,Z.C.Number,Z.C.Color,Z.C.Date,Z.C.Table,Z.C.Embed,Z.C.Timestamp,Z.C.GeoPoint,Z.C.ContentRelationship,Z.C.LinkToMedia,Z.C.Group,Z.C.NestedGroup];var e6=e=>{var t,n,o,l;let{tabId:r}=e,{customType:c,setCustomType:d}=w(),h=T.Dc.toSM(c),u=null===(t=h.tabs.find(e=>e.key===r))||void 0===t?void 0:t.sliceZone,p=null!==(o=null===(n=h.tabs.find(e=>e.key===r))||void 0===n?void 0:n.value)&&void 0!==o?o:[],f="page"===h.format&&h.repeatable?p.filter(e=>"uid"!==e.key):p,g=h.tabs.reduce((e,t)=>[...e,...t.value],[]),x=e=>{var t;let{apiId:n,value:i}=e,a=null===(t=i.config)||void 0===t?void 0:t.label;if((0,G.Ss)(Z.C,i.type)||null==a)return;if("Range"===i.type||"IntegrationFields"===i.type||"Separator"===i.type)throw Error("Unsupported Field Type: ".concat(i.type));let o=Z.C[i.type];try{o.schema.validateSync(i,{stripUnknown:!1})}catch(e){throw Error('Add field: Model is invalid for field "'.concat(i.type,'".'))}let l=T.L$.fromSM(i);d({customType:(0,m.xS)({customType:c,newField:l,newFieldId:n,sectionId:r}),onSaveCallback:()=>{F.Am.success("".concat("Group"===i.type?"Group":"Field"," added"))}}),(0,R.V)({id:n,field:l})},b=e=>{let{apiId:t,newKey:n,value:i,inGroupFieldAction:a,updateMeta:o}=e;if((0,G.Ss)(Z.C,i.type))return;let l=T.L$.fromSM(i);d({customType:(0,m.L4)({customType:c,previousFieldId:t,newFieldId:n,newField:l,sectionId:r}),onSaveCallback:()=>{"add"===a&&F.Am.success("Field added")},updateMeta:o}),a||(0,H.Z)({previousId:t,id:n,field:l})};return(0,i.jsx)(U.h,{children:(0,i.jsx)(s.Suspense,{fallback:(0,i.jsx)(a.D,{padding:32,children:(0,i.jsx)(a.bg,{})}),children:(0,i.jsxs)(O.aV,{border:!1,style:{flexGrow:1},children:[(0,i.jsx)(X.Z,{zoneType:"customType",zoneTypeFormat:null!==(l=c.format)&&void 0!==l?l:"custom",tabId:r,title:"Static zone",dataTip:"",fields:f,poolOfFieldsToCheck:g,showHints:!0,EditModal:K.Z,widgetsArray:e1,onDeleteItem:e=>{d({customType:(0,m.AK)({customType:c,fieldId:e,sectionId:r})})},onSave:e=>""===e.apiId?x({...e,apiId:e.newKey}):b(e),onDragEnd:e=>{if((0,G.uS)(e))return;let{source:t,destination:n}=e;if(!n)return;let i=(0,m.gR)({customType:c,sourceIndex:t.index,destinationIndex:n.index,sectionId:r});(0,M.flushSync)(()=>d({customType:i}))},renderHintBase:e=>{let{item:t}=e;return"data".concat((0,B.Ti)(t.key))},renderFieldAccessor:e=>"data".concat((0,B.Ti)(e)),testId:"static-zone-content",isRepeatableCustomType:c.repeatable}),(0,i.jsx)(e0,{customType:h,tabId:r,sliceZone:u,onRemoveSharedSlice:e=>{d({customType:(0,m.EN)({customType:c,sectionId:r,sliceId:e})})},onCreateSliceZone:()=>{d({customType:(0,m.Tr)(c,r)})},onDeleteSliceZone:()=>{d({customType:(0,m.E3)(c,r)})}})]})})})};let e4=()=>{var e,t,n;let{customType:o,setCustomType:l}=w(),r=T.Dc.toSM(o),[c,d]=(0,s.useState)(null===(e=r.tabs[0])||void 0===e?void 0:e.key),[h,u]=(0,s.useState)(),p=(null===(n=r.tabs.find(e=>e.key===c))||void 0===n?void 0:null===(t=n.sliceZone)||void 0===t?void 0:t.value.length)===0;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(a.c9,{sx:p?{flexGrow:1}:void 0,children:["page"===o.format?(0,i.jsx)(a.ca,{title:o.repeatable?(0,i.jsx)(I,{}):void 0}):void 0,(0,i.jsxs)(a.cb,{onValueChange:d,value:c,children:[(0,i.jsx)(a.cd,{onAddNewTab:()=>{u({type:"CREATE_CUSTOM_TYPE_TAB"})},children:r.tabs.map(e=>(0,i.jsx)(a.ce,{menu:(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(a.at,{onSelect:()=>{u({type:"UPDATE_CUSTOM_TYPE_TAB",tabKey:e.key})},startIcon:(0,i.jsx)(a.aX,{name:"edit"}),children:"Rename"}),(0,i.jsx)(a.at,{color:"tomato",disabled:function(e){if(r.tabs.length<=1)return!0;let t=r.tabs.find(e=>e.value.find(e=>"uid"===e.key));return"page"===o.format&&o.repeatable&&(null==t?void 0:t.key)===e}(e.key),onSelect:()=>{u({type:"DELETE_CUSTOM_TYPE_TAB",tabKey:e.key})},startIcon:(0,i.jsx)(a.aX,{name:"delete"}),children:"Remove"})]}),value:e.key,children:e.key},e.key))}),r.tabs.map(e=>(0,i.jsx)(a.cc,{value:e.key,children:(0,i.jsx)(e6,{tabId:e.key})},e.key))]})]}),(null==h?void 0:h.type)==="CREATE_CUSTOM_TYPE_TAB"?(0,i.jsx)(z,{close:()=>{u(void 0)},isOpen:!0,onSubmit:e=>{let{id:t}=e;l({customType:(0,m.vB)(o,t)}),d(t)},tabIds:r.tabs.map(e=>e.key.toLowerCase())}):void 0,(null==h?void 0:h.type)==="UPDATE_CUSTOM_TYPE_TAB"?(0,i.jsx)(P,{close:()=>{u(void 0)},initialTabKey:h.tabKey,isOpen:!0,onSubmit:e=>{let{id:t}=e;l({customType:(0,m.HO)(o,h.tabKey,t)}),c===h.tabKey&&d(t)},tabIds:r.tabs.filter(e=>e.key!==h.tabKey).map(e=>e.key.toLowerCase())}):void 0,(null==h?void 0:h.type)==="DELETE_CUSTOM_TYPE_TAB"?(0,i.jsx)(N,{close:()=>{u(void 0)},isOpen:!0,onSubmit:()=>{if(l({customType:(0,m.F$)(o,h.tabKey)}),c===h.tabKey){var e;let t=null===(e=r.tabs.find(e=>e.key!==h.tabKey))||void 0===e?void 0:e.key;void 0!==t&&d(t)}}}):void 0]})};var e8=n(16442),e3=n(78254),e2=n(60867),e5=n(11166),e9=n(34919),e7=n.n(e9);let te=e=>{let{tabs:t,...n}=e;return(0,i.jsxs)(e5.fC,{...n,className:e7().root,defaultValue:t[0].label,orientation:"vertical",children:[(0,i.jsx)(e5.aV,{className:e7().list,"aria-label":"content tabs",children:t.map((e,t)=>{let{label:n}=e;return(0,i.jsx)(e5.xz,{className:e7().trigger,value:n,children:(0,i.jsx)(a.bL,{className:e7().triggerText,component:"span",color:"inherit",children:n})},"".concat(n,"-trig").concat(t+1))})}),t.map((e,t)=>{let{label:n,content:o}=e;return(0,i.jsx)(e5.VY,{className:e7().content,value:n,children:(0,i.jsx)(a.bn,{className:e7().scrollArea,children:o})},"".concat(n,"-content").concat(t+1))})]})};var tt=n(25661),tn=n(88241),ti=n(32554),ta=n(44621),to=n.n(ta);let tl=e=>{var t,n;let{inline:o,...l}=e,r=(0,ti.p)();if(!0===o)return(0,i.jsx)("code",{...l,className:to().inlineCode});let s=(()=>{var e,t,n,i,a;if((null===(t=l.node)||void 0===t?void 0:null===(e=t.data)||void 0===e?void 0:e.meta)!==void 0){let e=null===(i=l.node)||void 0===i?void 0:null===(n=i.data)||void 0===n?void 0:n.meta;return{fileName:e.substring(1,e.length-1),language:null===(a=l.className)||void 0===a?void 0:a.split("-")[1]}}return null})(),c=null===(t=/language-(\w+)/.exec(null!==(n=l.className)&&void 0!==n?n:""))||void 0===t?void 0:t[1];return(0,i.jsx)(a.W,{...l,onCopy:()=>{g.Xe.track({event:"page-type:copy-snippet",framework:r})},language:c,code:String(l.children).replace(/\n$/,""),title:null==s?void 0:s.fileName})},tr=e=>{let{markdown:t}=e;return(0,i.jsx)(tt.D,{children:t,linkTarget:"_blank",remarkPlugins:[tn.Z],components:{code:e=>(0,i.jsx)(tl,{...e}),h1:e=>(0,i.jsx)(a.bL,{children:e.children,component:"h1",variant:"h1"}),h2:e=>(0,i.jsx)(a.bL,{children:e.children,component:"h2",variant:"h2"}),h3:e=>(0,i.jsx)(a.bL,{children:e.children,component:"h3",variant:"h3"}),h4:e=>(0,i.jsx)(a.bL,{children:e.children,component:"h4",variant:"h4"}),h5:e=>(0,i.jsx)(a.bL,{children:e.children,component:"h4",variant:"h4"}),p:e=>(0,i.jsx)(a.bL,{className:to().section,children:e.children,component:"p",variant:"normal"}),pre:e=>(0,i.jsx)(a.bL,{className:to().section,children:e.children,component:"pre",variant:"normal"})}})};async function ts(e){let t=JSON.parse(e),{errors:n,documentation:i}=await Y.managerClient.documentation.read({kind:t.kind,data:t.data});if(n.length>0)throw n;return i}var tc=n(65480),td=n.n(tc);let tm=e=>{var t;let{model:n}=e,o=(0,ti.p)(),l=(t={kind:"PageSnippet",data:{model:n}},(0,eC.QT)(ts,[JSON.stringify(t)])),{completeStep:r}=(0,er.k)();return 0===l.length?null:(0,i.jsxs)(a.ae,{size:"small",trigger:(0,i.jsx)(a.E,{color:"grey",onClick:()=>{r("codePage"),g.Xe.track({event:"page-type:open-snippet",framework:o})},startIcon:"code",children:"Page snippet"}),children:[(0,i.jsx)(a.al,{icon:"code",title:"Page snippet"}),(0,i.jsx)("section",{className:td().content,children:l.length>1?(0,i.jsx)(te,{style:{flex:1},tabs:l.map((e,t)=>{let{label:n,content:a}=e;return{label:null!=n?n:"Tab ".concat(t+1),content:(0,i.jsx)(tr,{markdown:a})}})}):(0,i.jsx)(a.bn,{style:{flex:1,padding:16},children:(0,i.jsx)(tr,{markdown:l[0].content})})})]})},th=e=>{let{model:t}=e;return(0,i.jsx)("div",{children:(0,i.jsx)(U.h,{children:(0,i.jsx)(s.Suspense,{fallback:(0,i.jsx)(a.E,{color:"grey",startIcon:"code",children:"Page snippet"}),children:(0,i.jsx)(tm,{model:t})})})})},tu=()=>{let e=(0,r.useRouter)(),{selectedCustomType:t}=(0,c.v9)(t=>({selectedCustomType:(0,e3.Jk)(t,(0,u.Ag)(e.query))}));return((0,s.useEffect)(()=>{t&&(0,e8.TG)(t)||e.replace("/")},[t,e]),t&&(0,e8.TG)(t))?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(l(),{children:(0,i.jsxs)("title",{children:[t.local.label," - Slice Machine"]})}),(0,i.jsx)(tp,{customType:t.local})]}):(0,i.jsx)(p.LN,{})},tp=e=>{let{customType:t}=e;return null===t?(0,i.jsx)(p.LN,{}):(0,i.jsx)(p.LN,{children:(0,i.jsx)(S,{initialCustomType:T.Dc.fromSM(t),children:e=>{var n;let{actionQueueStatus:o,customType:l,setCustomType:r}=e,s=(0,m.y6)(l),c=u.cd[t.format],f=v.$[t.format];return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(p.wd,{children:[(0,i.jsx)(p.Xq,{url:c.tablePagePathname}),(0,i.jsxs)(p.Cx,{children:[(0,i.jsx)(d.g,{children:f.name({start:!0,plural:!0})}),(0,i.jsx)(d.g,{active:!0,children:null!==(n=l.label)&&void 0!==n?n:l.id})]}),(0,i.jsxs)(p.K2,{children:[(0,i.jsx)(h.X,{status:o}),"page"===l.format?(0,i.jsx)(th,{model:l}):void 0,(0,i.jsx)(e2._,{isChangesLocal:!0,format:s,customType:l,setLocalCustomType:r})]})]}),(0,i.jsx)(p.RN,{children:(0,i.jsx)(a.D,{flexDirection:"column",minWidth:0,children:(0,i.jsx)(e4,{})})})]})}})})}},84879:function(e,t,n){"use strict";n.d(t,{E:function(){return l}});var i=n(18566),a=n(80148);async function o(){return a.managerClient.project.getSliceMachineConfig()}function l(e){var t,n;let[l,r]=[(0,i.QT)(o,[]),async e=>{await a.managerClient.project.writeSliceMachineConfig({config:e}),(0,i.VA)(o,[],e)}],s=async t=>{let n={...l,labs:{...l.labs}};t?n.labs[e]=t:e in n.labs&&delete n.labs[e],0===Object.keys(n.labs).length&&delete n.labs,await r(n)};return[{enabled:null!==(n=null==l?void 0:null===(t=l.labs)||void 0===t?void 0:t[e])&&void 0!==n&&n},s]}},34919:function(e){e.exports={flex:"ContentTabs_flex__T21Oc",column:"ContentTabs_column__1f8b8 ContentTabs_flex__T21Oc",root:"ContentTabs_root__Gn3Zg ContentTabs_column__1f8b8 ContentTabs_flex__T21Oc",list:"ContentTabs_list__rAZtl ContentTabs_flex__T21Oc",trigger:"ContentTabs_trigger__cTyPN ContentTabs_column__1f8b8 ContentTabs_flex__T21Oc",triggerText:"ContentTabs_triggerText__p_ZBl",content:"ContentTabs_content__H1Stj ContentTabs_column__1f8b8 ContentTabs_flex__T21Oc",scrollArea:"ContentTabs_scrollArea__DuDcQ"}},65480:function(e){e.exports={content:"PageSnippetDialog_content__jIN6d"}},44621:function(e){e.exports={section:"MarkdownRenderer_section__uNS1M",inlineCode:"MarkdownRenderer_inlineCode__lmGTi"}},65375:function(e){e.exports={scrollArea:"ConvertLegacySliceButton_scrollArea__xf3vM",label:"ConvertLegacySliceButton_label__BK0Gd"}}}]);
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[660],{10660:function(e,t,n){"use strict";n.d(t,{H:function(){return tu}});var i=n(52322),a=n(18337),o=n(97729),l=n.n(o),r=n(5632),s=n(2784),c=n(56580),d=n(43388),m=n(77630),h=n(23094),u=n(59294),p=n(58446),f=n(74217),g=n(94160),x=n(68968),b=n(23710),y=n(54597),v=n(98564);let j=(0,s.createContext)(void 0);function S(e){let{children:t,initialCustomType:n}=e,[a,o]=(0,s.useState)(n),l=(0,m.y6)(a),r=v.$[l],{actionQueueStatus:c,setNextAction:d}=(0,b.c)({errorMessage:r.autoSaveFailed}),{refreshState:h}=(0,y.Z)(),u=(0,f.R9)(h),{syncChanges:p}=(0,x.g)(),S=(0,s.useCallback)(e=>{let{customType:t,onSaveCallback:n,updateMeta:i}=e;o(t),d(async()=>{let{errors:e}=await (0,g.KA)({customType:t,updateMeta:i});if(e.length>0)throw e;u(await (0,g.y0)()),p(),null==n||n()})},[d,u,p]),w=(0,s.useMemo)(()=>({actionQueueStatus:c,customType:a,setCustomType:S}),[c,a,S]);return(0,i.jsx)(j.Provider,{value:w,children:"function"==typeof t?t(w):t})}function w(){let e=(0,s.useContext)(j);if(!e)throw Error("CustomTypeProvider not found");return e}var C=n(30195);function I(){var e;let[t,n]=(0,s.useState)(!1),{customType:o,setCustomType:l}=w(),[r,c]=null!==(e=(0,m.j5)(o))&&void 0!==e?e:[],d=c?(0,m.N3)(c):"",[h,u]=(0,s.useState)(null!=d?d:""),[p,g]=(0,s.useState)();(0,f.pQ)(t,()=>{t||(u(null!=d?d:""),g(void 0))});let x=(0,s.useCallback)(()=>(0,i.jsx)(a.aX,{name:c?"language":"add",size:"small",color:"grey11"}),[c]);return(0,i.jsxs)(a.ae,{open:t,onOpenChange:n,size:"small",trigger:(0,i.jsx)(a.E,{color:"grey",textColor:"placeholder",textWeight:"normal",renderStartIcon:x,sx:{marginInline:"auto"},children:c?d:"Add an UID"}),children:[(0,i.jsx)(a.al,{title:"Edit the UID label"}),(0,i.jsx)(a.aj,{children:(0,i.jsxs)(a.aJ,{onSubmit:function(){p||(l({customType:c?(0,m.eK)(h,o):(0,m.H8)(h,o)}),n(!1))},children:[(0,i.jsx)(a.D,{flexDirection:"column",padding:16,gap:4,children:(0,i.jsx)(a.aM,{type:"text",label:"Label *",placeholder:"UID",value:h,onValueChange:function(e){u(e),g(function(e){let t=D.safeParse(e,{errorMap:k});if(t.error)return t.error.errors[0].message}(e))},error:p,description:"A label for the UID"})}),(0,i.jsxs)(a.ah,{children:[(0,i.jsx)(a.ai,{size:"medium"}),(0,i.jsx)(a.af,{type:"submit",size:"medium",disabled:!!p,children:"Save"})]})]})})]})}let D=C.z.string().max(35).min(1),k=e=>{switch(e.code){case C.z.ZodIssueCode.too_big:return{message:"The label can't be longer than ".concat(e.maximum," characters")};case C.z.ZodIssueCode.too_small:return{message:"This field is required"};default:return{message:"Invalid value"}}};var T=n(94840),_=n(59532),A=n(63397),E=n(75289);let L=e=>{let{name:t,label:n,placeholder:a,error:o,...l}=e;return(0,i.jsxs)(E.xu,{mb:3,children:[(0,i.jsx)(E.__,{htmlFor:t,mb:2,children:n}),(0,i.jsx)(A.gN,{name:t,type:"text",placeholder:a,as:E.II,autoComplete:"off",...l}),o?(0,i.jsx)(E.xv,{sx:{color:"error",mt:1},children:o}):null]})};var z=e=>{let{isOpen:t,onSubmit:n,close:a,tabIds:o}=e;return(0,i.jsx)(_.Z,{isOpen:t,widthInPx:"530px",formId:"create-tab",close:a,onSubmit:e=>{n(e),a()},initialValues:{id:""},validate:e=>{let{id:t}=e;return t?o.includes(t.toLowerCase())?{id:"Tab exists already"}:void 0:{id:"Tab ID is required"}},content:{title:"Add Tab"},children:e=>{let{errors:t}=e;return(0,i.jsx)(L,{name:"id",label:"New Tab ID",placeholder:"A label for selecting the tab (i.e. not used in the API)",error:t.id})}})},N=e=>{let{isOpen:t,onSubmit:n,close:a}=e;return(0,i.jsx)(_.Z,{omitFooter:!0,isOpen:t,widthInPx:"530px",formId:"create-tab",close:a,cardProps:{bodySx:{p:0}},onSubmit:e=>{n(e),a()},initialValues:{},content:{title:"Remove Tab"},children:()=>(0,i.jsxs)(E.xu,{sx:{px:4,py:4},children:[(0,i.jsx)(E.X6,{as:"h4",children:"Remove this tab?"}),(0,i.jsx)(E.xv,{as:"p",color:"textClear",sx:{mt:2},children:"This action cannot be undone."}),(0,i.jsx)(E.zx,{type:"button",variant:"buttons.actionDelete",sx:{mt:3},onClick:()=>{n({}),a()},children:"Yes, remove tab"})]})})},P=e=>{let{isOpen:t,onSubmit:n,close:a,tabIds:o,initialTabKey:l}=e;return(0,i.jsx)(_.Z,{omitFooter:!0,isOpen:t,widthInPx:"530px",formId:"create-tab",close:a,cardProps:{bodySx:{p:0}},onSubmit:e=>{n(e),a()},initialValues:{id:l},validate:e=>{let{id:t}=e;return t?o.includes(t.toLowerCase())?{id:"Tab exists already"}:void 0:{id:"Tab ID is required"}},content:{title:"Rename Tab"},children:e=>{let{errors:t,values:o,setFieldValue:l,isValid:r}=e;return(0,i.jsxs)(E.xu,{sx:{px:4,py:4},children:[(0,i.jsx)(L,{name:"id",label:"Rename Tab ID",placeholder:"A label for selecting the tab (i.e. not used in the API)",error:t.id,onBlur:e=>{o.id!==e.target.value&&l("id",e.target.value.trim())},onChange:e=>{l("id",e.target.value)}}),(0,i.jsx)(E.zx,{type:"button",sx:{mt:3,width:"100%"},disabled:!r,onClick:()=>{o.id&&o.id.length&&n({id:o.id.trim()}),a()},children:"Save"})]})}})},M=n(28316),F=n(88932),O=n(35289),U=n(87446),Z=n(45440),G=n(16086),B=n(358),R=n(5495),H=n(39302),K=n(3285),V=n(40141),X=n(65077),q=n(21446);let W=(e,t)=>{switch(e){case"custom_type":case"page_type":return"Add to ".concat(t)}};var Y=n(80148),$=n(74686),J=n(88866);async function Q(e,t,n){let i=Array(e.length),a=0,o=Array(Math.min(t,e.length)).fill(null).map(async()=>{for(;;){let t=a++;if(t>=e.length)break;i[t]=await n(e[t],t)}});return await Promise.all(o),i}class ee{getHeaders(){let e={Accept:"application/vnd.github.v3+json"};return void 0!==this.token&&(e.Authorization="Bearer ".concat(this.token)),e}async request(e,t){let n="".concat(this.baseUrl).concat(e),i=await fetch(n,{...t,headers:{...this.getHeaders(),...null==t?void 0:t.headers}});if(!i.ok)throw Error("GitHub API request failed: ".concat(i.status," ").concat(i.statusText));return i.json()}async getDefaultBranch(){let e=await this.request("/repos/".concat(this.owner,"/").concat(this.repo));return C.z.object({default_branch:C.z.string()}).parse(e).default_branch}async getFileContents(e,t){let n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=await this.request("/repos/".concat(this.owner,"/").concat(this.repo,"/contents/").concat(e,"?ref=").concat(t)),a=C.z.object({content:C.z.string(),encoding:C.z.string()}).parse(i);if("base64"!==a.encoding)throw Error("Unexpected encoding for ".concat(e,": ").concat(a.encoding));let o=atob(a.content.replace(/\s/g,""));if(!n)return o;{let e=new Uint8Array(o.length);for(let t=0;t<o.length;t++)e[t]=o.charCodeAt(t);return e.buffer}}async getDirectoryContents(e){let t=await this.request("/repos/".concat(this.owner,"/").concat(this.repo,"/contents/").concat(e));return C.z.array(C.z.object({name:C.z.string(),type:C.z.string(),path:C.z.string()})).parse(t)}async searchCode(e){let{path:t,filename:n}=e,i=[];void 0!==t&&i.push("path:".concat(t)),void 0!==n&&i.push("filename:".concat(n)),i.push("repo:".concat(this.owner,"/").concat(this.repo));let a="/search/code?q=".concat(encodeURIComponent(i.join(" "))),o=await this.request(a);return C.z.object({items:C.z.array(C.z.object({path:C.z.string(),name:C.z.string()})).optional(),total_count:C.z.number().optional()}).parse(o)}async getSliceLibraries(e){let t=await this.request("/repos/".concat(this.owner,"/").concat(this.repo,"/contents/slicemachine.config.json?ref=").concat(e)),n=C.z.object({content:C.z.string().optional(),encoding:C.z.string().optional()}).parse(t);if("string"==typeof n.content){let e=atob(n.content.replace(/\s/g,""));return C.z.object({libraries:C.z.array(C.z.string())}).parse(JSON.parse(e)).libraries}throw Error("No content found in slicemachine.config.json")}constructor(e){this.baseUrl="https://api.github.com",this.owner=e.owner,this.repo=e.repo,this.token=e.token}}let et=e=>{let t=e.match(/github\.com\/([^\/]+)\/([^\/]+)(?:\/|$)/);if(!t)throw Error("Invalid GitHub URL format");let[,n,i]=t;return{owner:n,repo:i.replace(/\.git$/,"")}},en=async e=>{let{owner:t,repo:n}=e;return new ee({owner:t,repo:n}).getDefaultBranch()},ei=async e=>{let{owner:t,repo:n,branch:i}=e;return new ee({owner:t,repo:n}).getSliceLibraries(i)},ea=async e=>{let{owner:t,repo:n,branch:i,libraries:a}=e,o=new ee({owner:t,repo:n}),l=[];for(let e of(console.log("Fetching slices from ".concat(a.length," library/libraries:"),a),a)){let t=e.replace(/^\.\//,""),n=[],a=!1;try{n=(await o.getDirectoryContents(t)).filter(e=>"dir"===e.type).map(e=>({name:e.name,path:e.path}))}catch(n){a=!0;let t=n instanceof Error?n.message:String(n);t.includes("403")?console.warn("GitHub API returned 403 for ".concat(e,", trying direct discovery...")):console.warn("GitHub API error for ".concat(e,", trying direct discovery..."),t)}if(a&&0===n.length){console.log("Attempting to discover slices using GitHub Search API for ".concat(e,"..."));try{let i=await o.searchCode({path:t,filename:"model.json"});if(i.items&&i.items.length>0){let a=new Set;for(let e of i.items){let t=e.path.split("/");if(t.length>=2){let e=t[t.length-2];e&&!a.has(e)&&a.add(e)}}n=Array.from(a).map(e=>({name:e,path:"".concat(t,"/").concat(e)})),console.log("Discovered ".concat(n.length," slice(s) via GitHub Search API for library ").concat(e))}else console.warn("GitHub Search API found no model.json files in ".concat(e))}catch(n){let t=n instanceof Error?n.message:String(n);t.includes("403")?console.warn("GitHub Search API also returned 403. Cannot discover slices without API access."):console.warn("Error using GitHub Search API for ".concat(e,":"),t)}}if(0===n.length){console.warn("No slices found in library ".concat(e,". The repository may be private or require authentication."));continue}console.log("Processing ".concat(n.length," slice(s) in library ").concat(e));let r=async e=>{try{let t,n,a,r;let s=await o.getFileContents("".concat(e.path,"/model.json"),i,!1);if("string"!=typeof s){console.warn("Failed to fetch model.json for slice: ".concat(e.name," - unexpected content type"));return}let c=J.SharedSlice.decode(JSON.parse(s));if("Left"===c._tag){console.warn("Failed to decode model.json for slice: ".concat(e.name));return}let d=c.right,m=[];try{m=await eo({api:o,branch:i,directoryPath:e.path}),console.log("Fetched ".concat(m.length," file(s) for slice ").concat(e.name,":"),m.map(e=>"".concat(e.path).concat(e.isBinary?" (binary)":"")))}catch(t){console.warn("Failed to fetch files for slice ".concat(e.name,":"),t instanceof Error?t.message:String(t))}for(let i of m)if(void 0===t&&i.path.match(/^index\.(tsx?|jsx?|vue|svelte)$/)&&"string"==typeof i.contents&&(t=i.contents),"mocks.json"===i.path&&"string"==typeof i.contents)try{let t=$.SharedSliceContent.decode(JSON.parse(i.contents));if("Left"===t._tag)console.warn("Failed to decode mocks.json for slice: ".concat(e.name));else{let e=t.right;Array.isArray(e)&&e.length>0&&(n=e)}}catch(t){console.warn("Failed to decode mocks.json for slice: ".concat(e.name))}let h={};void 0!==d.variations&&d.variations.length>0&&(await Promise.allSettled(d.variations.map(async t=>{try{let n="".concat(e.path,"/screenshot-").concat(t.id,".png"),l=await o.getFileContents(n,i,!0);if(l instanceof ArrayBuffer){let e=new Blob([l],{type:"image/png"}),n=new File([e],"screenshot-".concat(t.id,".png"),{type:"image/png"});h[t.id]=n,void 0===a&&void 0!==d.variations[0]&&t.id===d.variations[0].id&&(a=URL.createObjectURL(e),r=n)}}catch(e){console.warn("Failed to fetch screenshot for variation ".concat(t.id,":"),e instanceof Error?e.message:String(e))}}))).forEach((e,t)=>{if("rejected"===e.status){var n;console.warn("Failed to fetch screenshot for variation ".concat(null===(n=d.variations[t])||void 0===n?void 0:n.id,":"),e.reason instanceof Error?e.reason.message:String(e.reason))}});let u=null!=r?r:new File([],"".concat(d.name,".json"),{type:"application/json"}),p={image:u,thumbnailUrl:null!=a?a:URL.createObjectURL(u),model:d,files:m,componentContents:t,mocks:n,screenshots:Object.keys(h).length>0?h:void 0};l.push(p)}catch(t){console.warn("Error fetching slice ".concat(e.name,":"),t instanceof Error?t.message:String(t))}};await Q(n,6,r)}return l},eo=async e=>{let{api:t,branch:n,directoryPath:i}=e,a=[],o=!1;try{let e=await t.getDirectoryContents(i);o=!0;let l=e.filter(e=>"file"===e.type),r=e.filter(e=>"dir"===e.type);for(let e of(await Q(l,8,async e=>{if("model.json"===e.name)return null;try{let i=[".png",".jpg",".jpeg",".gif",".svg",".ico",".webp"].some(t=>e.name.toLowerCase().endsWith(t)),a=await t.getFileContents(e.path,n,i);return{path:e.name,contents:a,isBinary:i}}catch(t){return console.warn("Failed to fetch file ".concat(e.path,":"),t instanceof Error?t.message:String(t)),null}})))e&&a.push(e);for(let e of r)for(let i of(await eo({api:t,branch:n,directoryPath:e.path})))a.push({...i,path:"".concat(e.name,"/").concat(i.path)})}catch(e){console.warn("GitHub API failed for directory ".concat(i,", trying Search API..."),e instanceof Error?e.message:String(e))}if(!o)try{console.log("Using GitHub Search API to find all files in ".concat(i,"..."));let e=await t.searchCode({path:i});if(e.items&&e.items.length>0){for(let o of(console.log("Found ".concat(e.items.length," file(s) via Search API for ").concat(i)),await Q(e.items,8,async e=>{try{if("model.json"===e.name)return null;let a=e.path.startsWith(i+"/")?e.path.slice(i.length+1):e.name,o=[".png",".jpg",".jpeg",".gif",".svg",".ico",".webp",".woff",".woff2",".ttf",".eot",".otf",".pdf",".zip",".gz"].some(t=>e.name.toLowerCase().endsWith(t)),l=await t.getFileContents(e.path,n,o);return{path:a,contents:l,isBinary:o}}catch(t){return console.warn("Error fetching file ".concat(e.path,":"),t instanceof Error?t.message:String(t)),null}})))o&&a.push(o);console.log("Fetched ".concat(a.length," file(s) from ").concat(i," via Search API"))}else console.warn("GitHub Search API found no files in ".concat(i))}catch(t){let e=t instanceof Error?t.message:String(t);e.includes("403")?console.warn("GitHub Search API returned 403 for ".concat(i,". Cannot fetch files without API access.")):console.warn("Error using GitHub Search API for ".concat(i,":"),e)}return a};function el(){let[e,t]=(0,s.useState)(!1),[n,i]=(0,s.useState)([]);return{isLoadingSlices:e,slices:n,resetSlices:()=>{i([]),t(!1)},handleImportFromGithub:async e=>{try{let n;t(!0);let{owner:a,repo:o}=et(e);if(!a||!o)throw F.Am.error("Invalid GitHub URL format"),t(!1),Error("Invalid GitHub URL format");let l=await en({owner:a,repo:o});try{n=await ei({owner:a,repo:o,branch:l})}catch(e){throw console.error("Failed to fetch slicemachine.config.json:",e),F.Am.error("Failed to fetch slicemachine.config.json: ".concat(e instanceof Error?e.message:"Unknown error")),t(!1),e}if(0===n.length)throw console.warn("No libraries were found in the SM config."),t(!1),F.Am.error("No libraries were found in the SM config."),Error("No libraries were found in the SM config.");let r=await ea({owner:a,repo:o,branch:l,libraries:n});if(0===r.length)throw F.Am.error("Error fetching slices from the repository"),t(!1),Error("No slices were found in the libraries.");return i(r),t(!1),F.Am.success("Found ".concat(r.length," slice(s) from ").concat(n.length," library/libraries")),r}catch(e){return console.error("Error importing from GitHub:",e),F.Am.error("Error importing from GitHub: ".concat(e instanceof Error?e.message:"Unknown error")),t(!1),[]}}}}var er=n(98250);async function es(e){let{libraries:t=[]}=await Y.managerClient.project.getSliceMachineConfig(),n=t[0];if(!n)throw Error("No library found in the config.");await Q(e,3,async e=>{let{errors:t}=await Y.managerClient.slices.createSlice({libraryID:n,model:e.model,componentContents:e.componentContents});if(t.length)throw Error("Failed to create slice ".concat(e.model.id,"."))});let i=await Q(e,3,async e=>{let{model:t,image:i,langSmithUrl:a,mocks:o,files:l,screenshots:r}=e;if(o&&Array.isArray(o)&&o.length>0){let{errors:e}=await Y.managerClient.slices.updateSliceMocks({libraryID:n,sliceID:t.id,mocks:o});e.length&&console.warn("Failed to update mocks for slice ".concat(t.id,":"),e)}return r&&Object.keys(r).length>0?await Promise.all(Object.entries(r).map(async e=>{let[i,a]=e;a.size>0&&await Y.managerClient.slices.updateSliceScreenshot({libraryID:n,sliceID:t.id,variationID:i,data:a})})):i.size>0&&void 0!==t.variations&&t.variations.length>0&&await Y.managerClient.slices.updateSliceScreenshot({libraryID:n,sliceID:t.id,variationID:t.variations[0].id,data:i}),console.log("About to write files for slice ".concat(t.id,":"),l?"".concat(l.length," file(s) - ").concat(l.map(e=>e.path).join(", ")):"no files"),l&&l.length>0?await ec({libraryID:n,sliceID:t.id,files:l}):console.warn("No files to write for slice ".concat(t.id,". Files:"),l),{model:t,langSmithUrl:a}});return{library:n,slices:i}}async function ec(e){let{libraryID:t,sliceID:n,files:i}=e;if(0===i.length)return;let a=i.filter(e=>"mocks.json"!==e.path&&!e.path.startsWith("screenshot-")&&!e.path.match(/^index\.(tsx?|jsx?|vue|svelte)$/));if(console.log("Writing ".concat(a.length," additional file(s) for slice ").concat(n,":"),a.map(e=>e.path)),0!==a.length)try{let e=a.map(e=>{if(e.isBinary)return{path:e.path,contents:e.contents,isBinary:!0};if("string"==typeof e.contents)return{path:e.path,contents:e.contents,isBinary:!1};throw Error("Unexpected file contents type for ".concat(e.path))}),i=await Y.managerClient.slices.writeSliceFiles({libraryID:t,sliceID:n,files:e});i.errors.length>0?console.error("Errors writing files for slice ".concat(n,":"),i.errors.map(e=>{var t;return null!==(t=e.message)&&void 0!==t?t:String(e)})):console.log("Successfully wrote ".concat(a.length," file(s) for slice ").concat(n))}catch(e){console.error("Error writing files for slice ".concat(n,":"),e instanceof Error?e.message:String(e))}}let ed=(0,s.createContext)(void 0);function em(e){let{children:t}=e,[n,a]=(0,s.useState)([]),[o,l]=(0,s.useState)([]),[r,c]=(0,s.useState)(!1),{syncChanges:d}=(0,x.g)(),{createSliceSuccess:m,updateSliceMockSuccess:h}=(0,y.Z)(),{completeStep:u}=(0,er.k)(),p=(0,s.useRef)(crypto.randomUUID()),f=(0,s.useCallback)(e=>{a(t=>t.some(t=>t.model.id===e.model.id)?t.filter(t=>t.model.id!==e.model.id):[...t,e])},[]),b=(0,s.useCallback)(e=>{l(t=>t.some(t=>t.model.id===e.model.id)?t.filter(t=>t.model.id!==e.model.id):[...t,e])},[]),v=(0,s.useCallback)(e=>{l(e)},[]),j=(0,s.useCallback)(()=>{a([]),l([]),p.current=crypto.randomUUID()},[]),S=(0,s.useCallback)(async e=>{let{existingSlices:t,location:i,resetSlices:a}=e;if(0===n.length+o.length)throw F.Am.error("Please select at least one slice"),Error("No slices selected");let l=n.map(e=>e.model),r=o.map(e=>({image:e.image,model:e.model,files:e.files,componentContents:e.componentContents,mocks:e.mocks,screenshots:e.screenshots}));if(!(r.length>0))return j(),{slices:l};{let e=[],n=[...t.current,...l];for(let t of r){let i=function(e){let{existingSlices:t,newSlices:n,slice:i}=e,a=new Set,o=new Set;for(let{id:e,name:n}of t)a.add(e),o.add(n.toLowerCase());for(let e of n)a.add(e.model.id),o.add(e.model.name.toLowerCase());let l=i.id,r=2;for(;a.has(l);)l="".concat(i.id,"_").concat(r),r++;let s=i.name;for(r=2;o.has(s.toLowerCase());)s="".concat(i.name).concat(r),r++;return{...i,id:l,name:s}}({existingSlices:n,newSlices:e,slice:t.model});e.push({...t,model:i})}let o=p.current;c(!0);try{let{slices:t,library:n}=await es(e);if(o!==p.current)throw Error("Modal instance changed");await new Promise(e=>setTimeout(e,100));let s=(await (0,g.y0)()).libraries.map(t=>t.name!==n?t:{...t,components:t.components.map(t=>{let n=e.find(e=>e.model.id===t.model.id),i=t.mocks&&t.mocks.length>0?t.mocks:null==n?void 0:n.mocks;return{...t,mocks:null!=i?i:t.mocks}})});for(let e of(m(s),r))e.mocks&&Array.isArray(e.mocks)&&e.mocks.length>0&&h({libraryID:n,sliceID:e.model.id,mocks:e.mocks});d();let f=[...l,...t.map(e=>e.model)];for(let{model:e}of(c(!1),j(),a(),u("createSlice"),t))g.Xe.track({event:"slice:created",id:e.id,name:e.name,library:n,location:i,mode:"import"});return{slices:f,library:n}}catch(e){if(o!==p.current)throw e;throw c(!1),F.Am.error("An unexpected error happened while adding slices."),e}}},[n,o,d,m,h,u,j]),w=n.length+o.length;return(0,i.jsx)(ed.Provider,{value:{selectedLocalSlices:n,selectedLibrarySlices:o,toggleLocalSlice:f,toggleLibrarySlice:b,setAllLibrarySlices:v,reset:j,submit:S,isSubmitting:r,totalSelected:w},children:t})}function eh(){let e=(0,s.useContext)(ed);if(void 0===e)throw Error("useReuseExistingSlicesContext must be used within ReuseExistingSlicesProvider");return e}var eu=n(62434);function ep(e){let{thumbnailUrl:t,model:n,selected:o=!0,onSelectedChange:l}=e,r=(0,i.jsxs)(i.Fragment,{children:[void 0!==t&&t?(0,i.jsx)(eu.ZB,{src:t}):(0,i.jsx)(eu.ZB,{component:"div"}),(0,i.jsx)(eu.eW,{title:n.name,action:(0,i.jsx)("div",{onClick:e=>e.stopPropagation(),children:(0,i.jsx)(a.U,{checked:o,onCheckedChange:l})})})]});return(0,i.jsx)(eu.Zb,{interactive:!0,onClick:()=>{l(!o)},checked:o,size:"small",children:r})}function ef(){let[e,t]=(0,s.useState)(""),{isLoadingSlices:n,handleImportFromGithub:o,slices:l}=el(),{selectedLibrarySlices:r,toggleLibrarySlice:c,setAllLibrarySlices:d}=eh(),{allSelected:m,someSelected:h}=(0,s.useMemo)(()=>0===l.length?{allSelected:!1,someSelected:!1}:{allSelected:l.every(e=>r.some(t=>t.model.id===e.model.id)),someSelected:l.some(e=>r.some(t=>t.model.id===e.model.id))},[l,r]),u=async()=>{d(await o(e))};if(0===l.length)return(0,i.jsx)(a.D,{padding:16,height:"100%",flexDirection:"column",gap:16,children:(0,i.jsx)(a.D,{flexDirection:"column",gap:8,children:(0,i.jsxs)(a.D,{display:"flex",flexDirection:"column",gap:8,padding:16,border:!0,borderRadius:8,children:[(0,i.jsx)(a.bL,{color:"grey11",children:"Import from GitHub"}),(0,i.jsx)(a.bN,{placeholder:"https://github.com/username/repository",value:e,onValueChange:t}),(0,i.jsx)(a.E,{onClick:()=>void u(),disabled:!e.trim()||n,loading:n,color:"purple",children:n?"Loading slices...":"Import from GitHub"})]})})});let p="Select all slices";return m?p="Selected all slices (".concat(r.length,")"):h&&(p="".concat(r.length," of ").concat(l.length," selected")),(0,i.jsxs)(a.D,{flexDirection:"column",flexGrow:1,minHeight:0,children:[(0,i.jsx)(a.D,{padding:{block:12,inline:16},alignItems:"center",gap:8,children:(0,i.jsx)(a.aR,{value:p,children:(0,i.jsx)(a.U,{checked:m,indeterminate:h&&!m,onCheckedChange:e=>{e?d(l):d([])}})})}),(0,i.jsx)(a.bn,{stableScrollbar:!1,children:(0,i.jsx)(a.D,{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:16,padding:{inline:16,bottom:16},children:l.map(e=>{let t=r.some(t=>t.model.id===e.model.id);return(0,i.jsx)(ep,{model:e.model,thumbnailUrl:e.thumbnailUrl,selected:t,onSelectedChange:()=>{c(e)}},e.model.id)})})})]})}var eg=n(51507);function ex(e){let{availableSlices:t}=e,{selectedLocalSlices:n,toggleLocalSlice:o}=eh();return 0===t.length?(0,i.jsx)(a.D,{padding:16,height:"100%",flexDirection:"column",gap:16,children:(0,i.jsx)(a.D,{flexDirection:"column",gap:8,children:(0,i.jsx)(a.D,{display:"flex",flexDirection:"column",gap:8,padding:16,alignItems:"center",justifyContent:"center",children:"No local slices available"})})}):(0,i.jsx)(a.bn,{stableScrollbar:!1,children:(0,i.jsx)(a.D,{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:16,flexGrow:1,padding:16,minHeight:0,children:t.map(e=>{let t=n.some(t=>t.model.id===e.model.id);return(0,i.jsx)(eg.b,{action:{type:"checkbox"},mode:"selection",onSelectedChange:()=>{o(e)},selected:t,slice:e,variant:"outlined"},"".concat(e.from,"-").concat(e.model.name))})})})}function eb(e){let{open:t,location:n,typeName:o,availableSlices:l=[],onSuccess:r,onClose:c}=e,[d,m]=(0,s.useState)("local"),h=function(e){let{open:t}=e,n=(0,s.useRef)([]);return(0,s.useEffect)(()=>{t&&(n.current=[],Y.managerClient.slices.readAllSlices().then(e=>{n.current=e.models.map(e=>{let{model:t}=e;return t})}).catch(()=>null))},[t]),n}({open:t}),{resetSlices:u}=el(),{submit:p,isSubmitting:f,totalSelected:g,reset:x}=eh(),b=async()=>{try{let e=await p({existingSlices:h,location:n,resetSlices:u});r(e)}catch(e){}};return(0,i.jsxs)(a.ae,{open:t,onOpenChange:e=>{e||f||(c(),x(),u(),m("local"))},children:[(0,i.jsx)(a.al,{title:"Reuse an existing slice"}),(0,i.jsxs)(a.aj,{gap:0,children:[(0,i.jsx)(a.ak,{hidden:!0,children:"Select existing slices or import slices from a GitHub repository"}),(0,i.jsxs)(a.D,{flexDirection:"column",flexGrow:1,minHeight:0,children:[(0,i.jsxs)(a.D,{justifyContent:"space-between",padding:16,border:{bottom:!0},children:[(0,i.jsxs)(a.D,{gap:8,children:[(0,i.jsx)(a.bD,{selected:"local"===d,onClick:()=>m("local"),children:"Local Slices"}),(0,i.jsx)(a.bD,{selected:"library"===d,onClick:()=>m("library"),children:"Library Slices"})]}),"library"===d&&"<repo-select>"]}),(0,i.jsx)(ey,{selected:"local"===d,children:(0,i.jsx)(ex,{availableSlices:l})}),(0,i.jsx)(ey,{selected:"library"===d,children:(0,i.jsx)(ef,{})})]}),(0,i.jsxs)(a.ah,{children:[(0,i.jsx)(a.ai,{disabled:f,size:"medium"}),(0,i.jsxs)(a.af,{disabled:0===g,loading:f,onClick:()=>void b(),size:"medium",children:[W(n,o)," (",g,")"]})]})]})]})}function ey(e){let{children:t,selected:n}=e;return n?(0,i.jsx)(a.D,{display:"flex",flexDirection:"column",flexGrow:1,minHeight:0,children:t}):(0,i.jsx)(a.D,{display:"none",minHeight:0,children:t})}function ev(e){return(0,i.jsx)(em,{children:(0,i.jsx)(eb,{...e})})}var ej=n(27213);let eS=e=>{let{openCreateSliceModal:t,openCreateSliceFromImageModal:n,openUpdateSliceZoneModal:o,openSlicesTemplatesModal:l,isSlicesTemplatesSupported:r}=e,s=(0,ej.F)({menuType:"ActionList"});return(0,i.jsxs)(a.s,{"data-testid":"slice-zone-blank-slate",sx:{width:648},children:[(0,i.jsx)(a.x,{lineColor:"purple9",backgroundColor:"purple5",name:"add",size:"large"}),(0,i.jsx)(a.z,{size:"big",children:"Add slices"}),(0,i.jsx)(a.w,{children:"Slices are reusable website sections. You can use them on different pages and write unique content for each. Each slice has its own component in your code."}),(0,i.jsx)(a.v,{children:(0,i.jsxs)(a.A,{children:[(0,i.jsx)(a.b,{renderStartIcon:()=>s.fromImage.BackgroundIcon,onClick:n,description:s.fromImage.description,children:s.fromImage.title}),(0,i.jsx)(a.b,{renderStartIcon:()=>s.fromScratch.BackgroundIcon,onClick:t,description:s.fromScratch.description,children:s.fromScratch.title}),r&&(0,i.jsx)(a.b,{renderStartIcon:()=>s.fromTemplate.BackgroundIcon,onClick:l,description:s.fromTemplate.description,children:s.fromTemplate.title}),(0,i.jsx)(a.b,{renderStartIcon:()=>s.fromExisting.BackgroundIcon,onClick:o,description:s.fromExisting.description,children:s.fromExisting.title})]})})]})};function ew(e){let{customType:t,tabId:n,slices:i}=e,a={...t};return i.forEach(e=>{a={...a,tabs:a.tabs.map(t=>t.key===n&&t.sliceZone?{...t,sliceZone:{key:t.sliceZone.key,value:[{key:e.id,value:e},...t.sliceZone.value]}}:t)}}),g.Xe.track({event:"custom-type:slice-zone-updated",customTypeId:t.id}),a}var eC=n(18566);async function eI(){try{let{templates:e,errors:t}=await Y.managerClient.sliceTemplateLibrary.readLibrary({});if(t.length>0)throw t;return e.map(e=>({model:e.model,screenshots:Object.fromEntries(Object.entries(e.screenshots).map(e=>{let[t,n]=e;return[t,URL.createObjectURL(n)]}))}))}catch(e){return[]}}var eD=n(6256),ek=n(39204),eT=n(7723),e_=n(33986),eA=n(30527),eE=n(55862);let eL=e=>{let{deleteSliceZone:t,closeDeleteSliceZoneModal:n}=e;return(0,i.jsx)(eE.Z,{isOpen:!0,shouldCloseOnOverlayClick:!0,style:{content:{maxWidth:612}},onRequestClose:n,children:(0,i.jsx)(eA.Z,{bodySx:{p:0,bg:"white",position:"relative",height:"100%",padding:16},footerSx:{position:"sticky",bottom:0,p:0},sx:{border:"none",overflow:"hidden"},borderFooter:!0,Header:(0,i.jsxs)(E.kC,{sx:{position:"sticky",top:0,zIndex:1,p:"16px",alignItems:"center",justifyContent:"space-between",borderBottom:e=>{var t;return"1px solid ".concat(String(null===(t=e.colors)||void 0===t?void 0:t.borders))}},children:[(0,i.jsx)(E.X6,{sx:{fontSize:"14px",fontWeight:"bold",ml:1},children:"Do you really want to delete Slice Zone?"}),(0,i.jsx)(E.x8,{type:"button",onClick:n})]}),Footer:()=>(0,i.jsxs)(E.kC,{sx:{justifyContent:"flex-end",height:64,alignItems:"center",paddingRight:16,borderTop:e=>{var t;return"1px solid ".concat(String(null===(t=e.colors)||void 0===t?void 0:t.darkBorders))},backgroundColor:"gray"},children:[(0,i.jsx)(e_.z,{label:"Cancel",variant:"secondary",onClick:n,sx:{mr:"10px",fontWeight:"bold",color:"grey12",borderRadius:6}}),(0,i.jsx)(e_.z,{label:"Delete",variant:"danger",onClick:t,sx:{minHeight:39,minWidth:78}})]}),children:(0,i.jsx)(E.nv,{children:"You're about to delete Slice Zone."})})})};var ez=n(84879),eN=n(63908),eP=n(63019),eM=n(65375),eF=n.n(eM);let eO=e=>{var t;let{isOpen:n,close:o,onSubmit:l,isLoading:r,slice:d,libraries:m}=e,{remoteSlices:h}=(0,c.v9)(e=>({remoteSlices:(0,eT.sT)(e)})),u={from:null===(t=m[0])||void 0===t?void 0:t.name,sliceName:(0,B.MP)(d.key)},[p,g]=(0,s.useState)(u),[x,b]=(0,s.useState)();function y(e){g(e),b((0,eP.h)(e,m,h))}return(0,f.pQ)(n,()=>{n||(g(u),b(void 0))}),(0,i.jsxs)(a.ae,{open:n,onOpenChange:e=>!e&&o(),size:{width:448,height:"auto"},children:[(0,i.jsx)(a.al,{title:"Upgrade slice"}),(0,i.jsx)(a.aj,{children:(0,i.jsx)(a.aJ,{onSubmit:function(){x&&Object.keys(x).length>0||l({libraryID:p.from,sliceID:p.sliceName})},children:(0,i.jsxs)(a.D,{flexDirection:"column",children:[(0,i.jsxs)(a.bn,{className:eF().scrollArea,children:[(0,i.jsx)(a.bL,{variant:"normal",color:"grey11",children:"This will create a new slice with the same fields. The new slice will replace the legacy slice in all of your types, and the existing slice content will be re-mapped to the new slice."}),(0,i.jsx)(a.bL,{variant:"normal",color:"grey11",children:"This will not migrate your component. You will need to do that manually."}),(0,i.jsxs)(a.D,{flexDirection:"column",gap:4,children:[(0,i.jsx)(a.aM,{label:"Slice name *",placeholder:"Pascalised Slice API ID (e.g. ".concat((0,B.MP)(d.key),")"),error:null==x?void 0:x.sliceName,value:p.sliceName,onValueChange:e=>y({...p,sliceName:e.slice(0,30)}),"data-testid":"slice-name-input"}),(0,i.jsx)(a.bL,{variant:"normal",color:"grey11",children:"A display name for the slice"})]}),(0,i.jsxs)(a.D,{flexDirection:"column",gap:4,children:[(0,i.jsx)("label",{className:eF().label,children:(0,i.jsx)(a.bL,{variant:"bold",children:"Slice library *"})}),(0,i.jsx)(a.bq,{size:"medium",color:"grey",startIcon:"folder",flexContent:!0,value:p.from,onValueChange:e=>{e&&y({...p,from:e})},children:m.map(e=>(0,i.jsx)(a.bt,{value:e.name,children:e.name},e.name))}),(0,i.jsx)(a.bL,{variant:"normal",color:"grey11",children:"The library where we'll store your slice"})]})]}),(0,i.jsxs)(a.ah,{children:[(0,i.jsx)(a.ai,{size:"medium"}),(0,i.jsx)(a.af,{type:"submit",size:"medium",loading:r,disabled:x&&Object.keys(x).length>0,children:"Upgrade"})]})]})})})]})};var eU=n(96009),eZ=n.n(eU);let eG=e=>{var t,n;let{isOpen:o,close:l,onSubmit:r,isLoading:c,slice:d,sliceName:m,libraries:h,localSharedSlices:u}=e,p={libraryID:null===(t=u[0])||void 0===t?void 0:t.from,sliceID:null===(n=u[0])||void 0===n?void 0:n.model.id,variationID:eZ()(d.key),variationName:m},[g,x]=(0,s.useState)(!0),[b,y]=(0,s.useState)(p),[v,j]=(0,s.useState)({});function S(e){y(e),j(eB(e,h))}return(0,f.pQ)(o,()=>{o||(y(p),j({}))}),(0,i.jsxs)(a.ae,{open:o,onOpenChange:e=>!e&&l(),size:{width:448,height:"auto"},children:[(0,i.jsx)(a.al,{title:"Convert to slice variation"}),(0,i.jsx)(a.aj,{children:(0,i.jsx)(a.aJ,{onSubmit:function(){Object.keys(v).length>0||r(b)},children:(0,i.jsxs)(a.D,{display:"flex",flexDirection:"column",children:[(0,i.jsxs)(a.bn,{className:eF().scrollArea,children:[(0,i.jsx)(a.bL,{variant:"normal",color:"grey11",children:"If you have multiple slices that are similar, you can combine them as variations of the same slice."}),(0,i.jsxs)(a.D,{display:"flex",flexDirection:"column",gap:4,children:[(0,i.jsxs)("label",{className:eF().label,children:[(0,i.jsx)(a.bL,{variant:"bold",children:"Target slice *"}),"string"==typeof v.libraryID?(0,i.jsx)(a.bL,{variant:"small",color:"tomato10",children:v.libraryID}):null,"string"==typeof v.sliceID?(0,i.jsx)(a.bL,{variant:"small",color:"tomato10",children:v.sliceID}):null]}),(0,i.jsx)(a.bq,{size:"medium",color:"grey",startIcon:"viewDay",flexContent:!0,value:"".concat(b.libraryID,"::").concat(b.sliceID),onValueChange:e=>{if(e){let[t,n]=e.split("::");S({...b,libraryID:t,sliceID:n})}},children:u.map(e=>(0,i.jsxs)(a.bt,{value:"".concat(e.from,"::").concat(e.model.id),children:[e.from," ",">"," ",e.model.name," (",e.model.id,")"]},"".concat(e.from,"::").concat(e.model.id)))}),(0,i.jsx)(a.bL,{variant:"normal",color:"grey11",children:"Choose the slice to which you would like to add this variation."})]}),(0,i.jsx)(a.D,{display:"flex",flexDirection:"column",gap:4,children:(0,i.jsx)(a.aM,{label:"Variation name *",placeholder:m,error:v.variationName,value:b.variationName,onValueChange:e=>{let t={...b,variationName:e.slice(0,30)};g&&(t.variationID=eZ()(t.variationName)),S(t)},"data-testid":"variation-name-input"})}),(0,i.jsx)(a.D,{display:"flex",flexDirection:"column",gap:4,children:(0,i.jsx)(a.aM,{label:"ID *",placeholder:eZ()(d.key),error:v.variationID,value:b.variationID,onValueChange:e=>{x(!1),S({...b,variationID:e.slice(0,30)})},"data-testid":"variation-id-input"})})]}),(0,i.jsxs)(a.ah,{children:[(0,i.jsx)(a.ai,{size:"medium"}),(0,i.jsx)(a.af,{type:"submit",size:"medium",loading:c,disabled:Object.keys(v).length>0,children:"Convert"})]})]})})})]})},eB=(e,t)=>{let n={};e.libraryID||(n.libraryID="Cannot be empty.");let i=t.find(t=>t.path===e.libraryID);n.libraryID||i||(n.libraryID="Does not exist."),e.sliceID||(n.sliceID="Cannot be empty.");let a=null==i?void 0:i.components.find(t=>t.model.id===e.sliceID);if(n.sliceID||a||(n.sliceID="Does not exist."),e.variationName||(n.variationName="Cannot be empty."),e.variationID){var o;(null!==(o=null==a?void 0:a.model.variations.map(e=>e.id))&&void 0!==o?o:[]).includes(e.variationID)&&(n.variationID="Slice variation ID is already taken.")}else n.variationID="Cannot be empty.";return n},eR=e=>{var t,n;let{isOpen:o,close:l,onSubmit:r,isLoading:c,identicalSlices:d}=e,m=null!==(n=null===(t=d[0])||void 0===t?void 0:t.path)&&void 0!==n?n:"",[h,u]=(0,s.useState)(m),[p,g]=(0,s.useState)();return(0,f.pQ)(o,()=>{o||(u(m),g(void 0))}),(0,i.jsxs)(a.ae,{open:o,onOpenChange:e=>!e&&l(),size:{width:448,height:"auto"},children:[(0,i.jsx)(a.al,{title:"Merge with an existing slice"}),(0,i.jsx)(a.aj,{children:(0,i.jsx)(a.aJ,{onSubmit:function(){if(p)return;let[e,t,n]=h.split("::");r({libraryID:e,sliceID:t,variationID:n})},children:(0,i.jsxs)(a.D,{display:"flex",flexDirection:"column",children:[(0,i.jsxs)(a.bn,{className:eF().scrollArea,children:[(0,i.jsx)(a.bL,{variant:"normal",color:"grey11",children:"If you have multiple identical slices, you can merge them. All of your content will be remapped to the target slice."}),(0,i.jsxs)(a.D,{display:"flex",flexDirection:"column",gap:4,children:[(0,i.jsxs)("label",{className:eF().label,children:[(0,i.jsx)(a.bL,{variant:"bold",children:"Target slice*"}),"string"==typeof p?(0,i.jsx)(a.bL,{variant:"small",color:"tomato10",children:p}):null]}),(0,i.jsx)(a.bq,{size:"medium",color:"grey",startIcon:"viewDay",flexContent:!0,value:h,onValueChange:function(e){u(e),e||g("Cannot be empty.")},children:d.map(e=>(0,i.jsx)(a.bt,{value:e.path,children:e.path.split("::").join(" > ")},e.path))}),(0,i.jsx)(a.bL,{variant:"normal",color:"grey11",children:"Choose a slice that you would like to merge this into."})]})]}),(0,i.jsxs)(a.ah,{children:[(0,i.jsx)(a.ai,{size:"medium"}),(0,i.jsx)(a.af,{type:"submit",size:"medium",loading:c,disabled:!!p,children:"Merge"})]})]})})})]})},eH=e=>{var t;let{slice:n,path:o}=e,{refreshState:l}=(0,y.Z)(),[r,d]=(0,s.useState)(!1),[m,h]=(0,s.useState)(),{setCustomType:u}=w(),{libraries:p}=(0,c.v9)(e=>({libraries:(0,eT.Sd)(e)})),f="Slice"===n.value.type&&null!==(t=n.value.fieldset)&&void 0!==t?t:n.key,x=p.filter(e=>e.isLocal),b=x.map(e=>e.components).flat(),v=eK(n,f,b),j=async e=>{var t,i,a;if(!m)return;d(!0),g.Xe.track({event:"legacy-slice:converted",id:e.sliceID,variation:null!==(t=e.variationID)&&void 0!==t?t:"default",library:e.libraryID,conversionType:m});let{errors:r}=await Y.managerClient.slices.convertLegacySliceToSharedSlice({model:n.value,src:{...o,sliceID:n.key},dest:{libraryID:e.libraryID,sliceID:e.sliceID,variationName:null!==(i=e.variationName)&&void 0!==i?i:"Default",variationID:null!==(a=e.variationID)&&void 0!==a?a:"default"}});if(r.length)throw console.error("Could not convert slice `".concat(f,"`"),r),F.Am.error("Could not convert slice `".concat(f,"`")),r;let{model:s,errors:c}=await Y.managerClient.customTypes.readCustomType({id:o.customTypeID});if(c.length||!s){console.error("Could not refresh custom type view `".concat(o.customTypeID,"`"),c),F.Am.error("Could not refresh custom type view `".concat(o.customTypeID,"`"));return}switch(l(await (0,g.y0)()),d(!1),h(void 0),m){case"as_new_slice":F.Am.success("".concat(f," has been upgraded to a new slice ").concat(e.libraryID," > ").concat(e.sliceID));break;case"as_new_variation":F.Am.success("".concat(f," has been converted as a variation of ").concat(e.libraryID," > ").concat(e.sliceID));break;default:F.Am.success("".concat(f," has been merged with ").concat(e.libraryID," > ").concat(e.sliceID))}u({customType:s})},S={path:o,slice:n,sliceName:f,libraries:x,localSharedSlices:b,identicalSlices:v,close:()=>h(void 0),onSubmit:j,isLoading:r};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(a.ar,{children:[(0,i.jsx)(a.av,{children:(0,i.jsx)(a.E,{"data-testid":"convert-legacy-slice",startIcon:"refresh",endIcon:"arrowDropDown",size:"medium",color:"grey",children:"Migrate legacy slice"})}),(0,i.jsxs)(a.as,{align:"start",children:[(0,i.jsx)(a.at,{startIcon:(0,i.jsx)(a.aX,{name:"folder",size:"large"}),description:"Use it with new types",onSelect:()=>h("as_new_slice"),children:"Upgrade slice"}),(0,i.jsx)(a.at,{startIcon:(0,i.jsx)(a.aX,{name:"viewDay",size:"large"}),description:"Add it to another slice",onSelect:()=>h("as_new_variation"),disabled:!b.length,children:"Convert to slice variation"}),(0,i.jsx)(a.at,{startIcon:(0,i.jsx)(a.aX,{name:"driveFileMove",size:"large"}),description:"Combine identical slices",onSelect:()=>h("merge_with_identical"),disabled:!v.length,children:"Merge with another slice"})]})]}),(0,i.jsx)(eO,{...S,isOpen:"as_new_slice"===m}),(0,i.jsx)(eG,{...S,isOpen:"as_new_variation"===m}),(0,i.jsx)(eR,{...S,isOpen:"merge_with_identical"===m})]})},eK=(e,t,n)=>(0,s.useMemo)(()=>{let i=[],a=(0,eN.ux)(e.value,t);for(let e of n)for(let t of e.model.variations){let n=(0,eN.ux)(t,e.model.name);a.primary===n.primary&&a.items===n.items&&i.push({libraryID:e.from,sliceID:e.model.id,variationID:t.id,path:"".concat(e.from,"::").concat(e.model.id,"::").concat(t.id)})}return i},[e,t,n]),eV=e=>{let{slice:t,path:n}=e,[o]=(0,ez.E)("legacySliceUpgrader"),l=o.enabled?"This Slice was created with the Legacy Builder. It needs to be converted first to be used within Slice Machine.":"This Slice was created with the Legacy Builder, and is incompatible with Slice Machine. You cannot edit, push, or delete it in Slice Machine. In order to proceed, manually remove the Slice from your type model. Then create a new Slice with the same fields using Slice Machine.";return(0,i.jsxs)(eu.Zb,{children:[(0,i.jsx)(eu.ZB,{component:"div",children:(0,i.jsx)(a.D,{alignItems:"center",justifyContent:"center",children:(0,i.jsx)(a.bL,{color:"grey11",component:"span",children:"No screenshot available"})})}),(0,i.jsxs)(eu.T$,{children:[(0,i.jsx)(a.c3,{content:l,side:"bottom",children:(0,i.jsx)(a.m,{color:"purple",title:"Legacy Slice"})}),o.enabled?(0,i.jsx)(eH,{slice:t,path:n}):null]}),(0,i.jsx)(eu.eW,{subtitle:"1 variation",title:(0,eN.Dj)(t.value)})]})};var eX=n(21151);let eq=e=>{let{slices:t,format:n,path:a,onRemoveSharedSlice:o}=e,l=t.some(e=>"SharedSlice"!==e.type),r=v.$[n],[c]=(0,ez.E)("legacySliceUpgrader");return(0,s.useEffect)(()=>{l&&(c.enabled?F.Am.info("This ".concat(r.name({start:!1,plural:!1})," contains legacy slices that can be upgraded.")):F.Am.warning("This ".concat(r.name({start:!1,plural:!1})," contains slices that are incompatible.")))},[l]),(0,i.jsx)(eX.Z,{elems:t,defineElementKey:e=>"SharedSlice"!==e.type?e.payload.key:e.payload.model.name,renderElem:e=>{if("SharedSlice"!==e.type){let t=e.payload;return(0,i.jsx)(eV,{slice:t,path:a})}{let t=e.payload;return(0,i.jsx)(eg.b,{action:{type:"remove",onRemove:()=>{o(t.model.id)}},mode:"navigation",slice:t,variant:"solid"})}},sx:{padding:"16px"}})};async function eW(e){try{let{templateIDs:t,localLibrariesNames:n,location:i,onSuccess:a}=e,{data:o,errors:l}=await Y.managerClient.sliceTemplateLibrary.createSlices({templateIDs:t});if(l.length>0||void 0===o)throw l;o.sliceIDs.forEach((e,a)=>{g.Xe.track({event:"slice:created",id:e,name:e,library:n[0],location:i,mode:"template",sliceTemplate:t[a]})}),await a(o.sliceIDs)}catch(t){let e="Internal Error: Slice(s) not created";console.error(e,t),F.Am.error(e)}}var eY=n(26109),e$=e=>{let{availableSlices:t,values:n}=e;return(0,i.jsx)(A.F2,{name:"sliceKeys",render:e=>(0,i.jsx)(eX.Z,{gridTemplateMinPx:"200px",elems:t,defineElementKey:e=>"".concat(e.from,"-").concat(e.model.name),renderElem:t=>{let a=n.sliceKeys.includes(t.model.id);return(0,i.jsx)(eg.b,{action:{type:"checkbox"},mode:"selection",onSelectedChange:i=>{i?e.push(t.model.id):e.remove(n.sliceKeys.indexOf(t.model.id))},selected:a,slice:t,variant:"outlined"})}})})};let eJ=e=>{let{formId:t,close:n,onSuccess:a,availableSlicesTemplates:o,localLibraries:l,location:r}=e,{createSliceSuccess:s}=(0,y.Z)();return(0,i.jsx)(_.Z,{isOpen:!0,buttonLabel:"Add",formId:t,close:n,onSubmit:e=>{let{sliceKeys:t}=e;eW({templateIDs:t,localLibrariesNames:l.map(e=>e.name),location:r,onSuccess:async e=>{s((await (0,g.y0)()).libraries),a(await Promise.all(e.map(async e=>(await Y.managerClient.slices.readSlice({libraryID:l[0].name,sliceID:e})).model).filter(e=>void 0!==e)))}})},initialValues:{sliceKeys:[]},content:{title:"Use template slices"},validate:e=>{if(0===e.sliceKeys.length)return{sliceKeys:"Select at least one template to add"}},actionMessage:e=>{let{errors:t}=e;return void 0!==t.sliceKeys?(0,i.jsx)(E.xv,{sx:{color:"error"},children:t.sliceKeys}):void 0},children:e=>{let{values:t}=e;return(0,i.jsx)(e$,{values:t,availableSlices:o.map(e=>({extension:"",fileName:"",from:"",href:"",pathToSlice:"",model:eY.id.toSM(e.model),screenshots:Object.entries(e.screenshots).reduce((e,t)=>({...e,[t[0]]:{url:t[1]}}),{})}))})}})},eQ=(e,t)=>{let n=(t||[]).reduce((e,t)=>[...e,...t.components],[]),{slicesInSliceZone:i,notFound:a}=e.value.reduce((e,t)=>{let{key:i,value:a}=t;if("SharedSlice"===a.type){let t=n.find(e=>e.model.id===i);return t?{...e,slicesInSliceZone:[...e.slicesInSliceZone,{type:"SharedSlice",payload:t}]}:{...e,notFound:[...e.notFound,{key:i}]}}return{...e,slicesInSliceZone:[...e.slicesInSliceZone,{type:"Slice",payload:{key:i,value:a}}]}},{slicesInSliceZone:[],notFound:[]});return{availableSlices:n,slicesInSliceZone:i,notFound:a}};var e0=e=>{var t,n;let{customType:o,onCreateSliceZone:l,onDeleteSliceZone:r,onRemoveSharedSlice:d,sliceZone:m,tabId:h}=e,u=(0,eC.QT)(eI,[]),[p,f]=(0,s.useState)(!1),[x,b]=(0,s.useState)(!1),[v,j]=(0,s.useState)(!1),[S,C]=(0,s.useState)(!1),{remoteSlices:I,libraries:D}=(0,c.v9)(e=>({remoteSlices:(0,eT.sT)(e),libraries:(0,eT.Sd)(e),slices:(0,eT.xC)(e)})),{setCustomType:k}=w(),{completeStep:_}=(0,er.k)(),{openLoginModal:A}=(0,y.Z)(),E=(0,ej.F)({menuType:"Dropdown"}),L=D.filter(e=>e.isLocal),{availableSlices:z,slicesInSliceZone:N,notFound:P}=(0,s.useMemo)(()=>m?eQ(m,D):{availableSlices:[],slicesInSliceZone:[],notFound:[]},[m,D]),[M,U]=(0,s.useState)(!1);(0,s.useEffect)(()=>{(null==P?void 0:P.length)&&P.forEach(e=>{let{key:t}=e;d(t)})},[P]);let Z=N.filter(e=>"SharedSlice"===e.type).map(e=>e.payload),G=z.filter(e=>!Z.some(t=>t.model.id===e.model.id)),B=()=>{b(!0)},R=()=>{j(!0)},H=async()=>{await Y.managerClient.user.checkIsLoggedIn()?C(!0):A()},K=()=>{f(!0),g.Xe.track({event:"custom-type:open-add-from-templates",customTypeId:o.id,customTypeFormat:o.format})},V=()=>{b(!1)},W=()=>{j(!1)},$=()=>{C(!1)},J=()=>{f(!1)};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(O.Bu,{actions:m?(0,i.jsxs)(a.ar,{children:[(0,i.jsx)(a.av,{children:(0,i.jsx)(a.E,{color:"purple",startIcon:"add","data-testid":"add-new-slice-dropdown",children:"Add"})}),(0,i.jsxs)(a.as,{align:"end",children:[(0,i.jsx)(a.at,{renderStartIcon:()=>E.fromImage.BackgroundIcon,onSelect:()=>void H(),description:E.fromImage.description,children:E.fromImage.title}),(0,i.jsx)(a.at,{renderStartIcon:()=>E.fromScratch.BackgroundIcon,onSelect:R,description:E.fromScratch.description,children:E.fromScratch.title}),u.length>0?(0,i.jsx)(a.at,{onSelect:K,renderStartIcon:()=>E.fromTemplate.BackgroundIcon,description:E.fromTemplate.description,children:E.fromTemplate.title}):void 0,(0,i.jsx)(a.at,{onSelect:B,renderStartIcon:()=>E.fromExisting.BackgroundIcon,description:E.fromExisting.description,children:E.fromExisting.title})]})]}):void 0,toggle:"page"!==o.format||"Main"!==h?(0,i.jsx)(a.bC,{checked:!!m,onCheckedChange:e=>{e?l():U(!0)},size:"small","data-testid":"slice-zone-switch"}):void 0,children:"Slices"}),m?N.length>0?(0,i.jsx)(X.xR,{children:(0,i.jsx)(eq,{slices:N,format:o.format,path:{customTypeID:o.id,tabID:h,sliceZoneID:null!==(t=null==m?void 0:m.key)&&void 0!==t?t:""},onRemoveSharedSlice:d})}):(0,i.jsx)(a.D,{flexDirection:"column",flexGrow:1,justifyContent:"center",alignItems:"center",padding:{block:32},children:(0,i.jsx)(eS,{openUpdateSliceZoneModal:B,openCreateSliceModal:R,openCreateSliceFromImageModal:()=>void H(),openSlicesTemplatesModal:K,projectHasAvailableSlices:G.length>0,isSlicesTemplatesSupported:u.length>0})}):void 0,(0,i.jsx)(ev,{open:x,location:"".concat(o.format,"_type"),typeName:null!==(n=o.label)&&void 0!==n?n:o.id,availableSlices:G,onSuccess:e=>{let{slices:t}=e,n=ew({customType:o,tabId:h,slices:t});k({customType:T.Dc.fromSM(n),onSaveCallback:()=>{F.Am.success("Slices successfully added")}}),_("createSlice"),V()},onClose:V}),p&&(0,i.jsx)(eJ,{formId:"tab-slicezone-form-".concat(h),availableSlicesTemplates:u,localLibraries:L,location:"".concat(o.format,"_type"),onSuccess:e=>{let t=ew({customType:o,tabId:h,slices:e});k({customType:T.Dc.fromSM(t),onSaveCallback:()=>{F.Am.success((0,i.jsx)(ek.GX,{message:"Slice template(s) added to slice zone and created at: ",path:"".concat(L[0].name,"/")}))}}),_("createSlice"),J()},close:J}),M&&(0,i.jsx)(eL,{closeDeleteSliceZoneModal:()=>{U(!1)},deleteSliceZone:()=>{r(),U(!1)}}),(null==L?void 0:L.length)!==0&&v&&(0,i.jsx)(eD.c,{onSuccess:e=>{let t=ew({customType:o,tabId:h,slices:[e]});k({customType:T.Dc.fromSM(t),onSaveCallback:()=>{F.Am.success((0,i.jsx)(ek.GX,{message:"New slice added to slice zone and created at: ",path:"".concat(L[0].name,"/")}))}}),W()},localLibraries:L,location:"".concat(o.format,"_type"),remoteSlices:I,onClose:W}),(0,i.jsx)(q.S,{open:S,location:"".concat(o.format,"_type"),onSuccess:e=>{let{slices:t,library:n}=e,a=ew({customType:o,tabId:h,slices:t});k({customType:T.Dc.fromSM(a),onSaveCallback:()=>{F.Am.success((0,i.jsx)(ek.GX,{message:"Slice(s) added to slice zone and created at: ",path:n}))}}),$()},onClose:$})]})};let e1=[Z.C.UID,Z.C.Image,Z.C.Text,Z.C.StructuredText,Z.C.Link,Z.C.Select,Z.C.Boolean,Z.C.Number,Z.C.Color,Z.C.Date,Z.C.Table,Z.C.Embed,Z.C.Timestamp,Z.C.GeoPoint,Z.C.ContentRelationship,Z.C.LinkToMedia,Z.C.Group,Z.C.NestedGroup];var e6=e=>{var t,n,o,l;let{tabId:r}=e,{customType:c,setCustomType:d}=w(),h=T.Dc.toSM(c),u=null===(t=h.tabs.find(e=>e.key===r))||void 0===t?void 0:t.sliceZone,p=null!==(o=null===(n=h.tabs.find(e=>e.key===r))||void 0===n?void 0:n.value)&&void 0!==o?o:[],f="page"===h.format&&h.repeatable?p.filter(e=>"uid"!==e.key):p,g=h.tabs.reduce((e,t)=>[...e,...t.value],[]),x=e=>{var t;let{apiId:n,value:i}=e,a=null===(t=i.config)||void 0===t?void 0:t.label;if((0,G.Ss)(Z.C,i.type)||null==a)return;if("Range"===i.type||"IntegrationFields"===i.type||"Separator"===i.type)throw Error("Unsupported Field Type: ".concat(i.type));let o=Z.C[i.type];try{o.schema.validateSync(i,{stripUnknown:!1})}catch(e){throw Error('Add field: Model is invalid for field "'.concat(i.type,'".'))}let l=T.L$.fromSM(i);d({customType:(0,m.xS)({customType:c,newField:l,newFieldId:n,sectionId:r}),onSaveCallback:()=>{F.Am.success("".concat("Group"===i.type?"Group":"Field"," added"))}}),(0,R.V)({id:n,field:l})},b=e=>{let{apiId:t,newKey:n,value:i,inGroupFieldAction:a,updateMeta:o}=e;if((0,G.Ss)(Z.C,i.type))return;let l=T.L$.fromSM(i);d({customType:(0,m.L4)({customType:c,previousFieldId:t,newFieldId:n,newField:l,sectionId:r}),onSaveCallback:()=>{"add"===a&&F.Am.success("Field added")},updateMeta:o}),a||(0,H.Z)({previousId:t,id:n,field:l})};return(0,i.jsx)(U.h,{children:(0,i.jsx)(s.Suspense,{fallback:(0,i.jsx)(a.D,{padding:32,children:(0,i.jsx)(a.bg,{})}),children:(0,i.jsxs)(O.aV,{border:!1,style:{flexGrow:1},children:[(0,i.jsx)(V.Z,{zoneType:"customType",zoneTypeFormat:null!==(l=c.format)&&void 0!==l?l:"custom",tabId:r,title:"Static zone",dataTip:"",fields:f,poolOfFieldsToCheck:g,showHints:!0,EditModal:K.Z,widgetsArray:e1,onDeleteItem:e=>{d({customType:(0,m.AK)({customType:c,fieldId:e,sectionId:r})})},onSave:e=>""===e.apiId?x({...e,apiId:e.newKey}):b(e),onDragEnd:e=>{if((0,G.uS)(e))return;let{source:t,destination:n}=e;if(!n)return;let i=(0,m.gR)({customType:c,sourceIndex:t.index,destinationIndex:n.index,sectionId:r});(0,M.flushSync)(()=>d({customType:i}))},renderHintBase:e=>{let{item:t}=e;return"data".concat((0,B.Ti)(t.key))},renderFieldAccessor:e=>"data".concat((0,B.Ti)(e)),testId:"static-zone-content",isRepeatableCustomType:c.repeatable}),(0,i.jsx)(e0,{customType:h,tabId:r,sliceZone:u,onRemoveSharedSlice:e=>{d({customType:(0,m.EN)({customType:c,sectionId:r,sliceId:e})})},onCreateSliceZone:()=>{d({customType:(0,m.Tr)(c,r)})},onDeleteSliceZone:()=>{d({customType:(0,m.E3)(c,r)})}})]})})})};let e4=()=>{var e,t,n;let{customType:o,setCustomType:l}=w(),r=T.Dc.toSM(o),[c,d]=(0,s.useState)(null===(e=r.tabs[0])||void 0===e?void 0:e.key),[h,u]=(0,s.useState)(),p=(null===(n=r.tabs.find(e=>e.key===c))||void 0===n?void 0:null===(t=n.sliceZone)||void 0===t?void 0:t.value.length)===0;return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(a.c9,{sx:p?{flexGrow:1}:void 0,children:["page"===o.format?(0,i.jsx)(a.ca,{title:o.repeatable?(0,i.jsx)(I,{}):void 0}):void 0,(0,i.jsxs)(a.cb,{onValueChange:d,value:c,children:[(0,i.jsx)(a.cd,{onAddNewTab:()=>{u({type:"CREATE_CUSTOM_TYPE_TAB"})},children:r.tabs.map(e=>(0,i.jsx)(a.ce,{menu:(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(a.at,{onSelect:()=>{u({type:"UPDATE_CUSTOM_TYPE_TAB",tabKey:e.key})},startIcon:(0,i.jsx)(a.aX,{name:"edit"}),children:"Rename"}),(0,i.jsx)(a.at,{color:"tomato",disabled:function(e){if(r.tabs.length<=1)return!0;let t=r.tabs.find(e=>e.value.find(e=>"uid"===e.key));return"page"===o.format&&o.repeatable&&(null==t?void 0:t.key)===e}(e.key),onSelect:()=>{u({type:"DELETE_CUSTOM_TYPE_TAB",tabKey:e.key})},startIcon:(0,i.jsx)(a.aX,{name:"delete"}),children:"Remove"})]}),value:e.key,children:e.key},e.key))}),r.tabs.map(e=>(0,i.jsx)(a.cc,{value:e.key,children:(0,i.jsx)(e6,{tabId:e.key})},e.key))]})]}),(null==h?void 0:h.type)==="CREATE_CUSTOM_TYPE_TAB"?(0,i.jsx)(z,{close:()=>{u(void 0)},isOpen:!0,onSubmit:e=>{let{id:t}=e;l({customType:(0,m.vB)(o,t)}),d(t)},tabIds:r.tabs.map(e=>e.key.toLowerCase())}):void 0,(null==h?void 0:h.type)==="UPDATE_CUSTOM_TYPE_TAB"?(0,i.jsx)(P,{close:()=>{u(void 0)},initialTabKey:h.tabKey,isOpen:!0,onSubmit:e=>{let{id:t}=e;l({customType:(0,m.HO)(o,h.tabKey,t)}),c===h.tabKey&&d(t)},tabIds:r.tabs.filter(e=>e.key!==h.tabKey).map(e=>e.key.toLowerCase())}):void 0,(null==h?void 0:h.type)==="DELETE_CUSTOM_TYPE_TAB"?(0,i.jsx)(N,{close:()=>{u(void 0)},isOpen:!0,onSubmit:()=>{if(l({customType:(0,m.F$)(o,h.tabKey)}),c===h.tabKey){var e;let t=null===(e=r.tabs.find(e=>e.key!==h.tabKey))||void 0===e?void 0:e.key;void 0!==t&&d(t)}}}):void 0]})};var e8=n(16442),e3=n(78254),e2=n(60867),e5=n(11166),e9=n(34919),e7=n.n(e9);let te=e=>{let{tabs:t,...n}=e;return(0,i.jsxs)(e5.fC,{...n,className:e7().root,defaultValue:t[0].label,orientation:"vertical",children:[(0,i.jsx)(e5.aV,{className:e7().list,"aria-label":"content tabs",children:t.map((e,t)=>{let{label:n}=e;return(0,i.jsx)(e5.xz,{className:e7().trigger,value:n,children:(0,i.jsx)(a.bL,{className:e7().triggerText,component:"span",color:"inherit",children:n})},"".concat(n,"-trig").concat(t+1))})}),t.map((e,t)=>{let{label:n,content:o}=e;return(0,i.jsx)(e5.VY,{className:e7().content,value:n,children:(0,i.jsx)(a.bn,{className:e7().scrollArea,children:o})},"".concat(n,"-content").concat(t+1))})]})};var tt=n(25661),tn=n(88241),ti=n(32554),ta=n(44621),to=n.n(ta);let tl=e=>{var t,n;let{inline:o,...l}=e,r=(0,ti.p)();if(!0===o)return(0,i.jsx)("code",{...l,className:to().inlineCode});let s=(()=>{var e,t,n,i,a;if((null===(t=l.node)||void 0===t?void 0:null===(e=t.data)||void 0===e?void 0:e.meta)!==void 0){let e=null===(i=l.node)||void 0===i?void 0:null===(n=i.data)||void 0===n?void 0:n.meta;return{fileName:e.substring(1,e.length-1),language:null===(a=l.className)||void 0===a?void 0:a.split("-")[1]}}return null})(),c=null===(t=/language-(\w+)/.exec(null!==(n=l.className)&&void 0!==n?n:""))||void 0===t?void 0:t[1];return(0,i.jsx)(a.W,{...l,onCopy:()=>{g.Xe.track({event:"page-type:copy-snippet",framework:r})},language:c,code:String(l.children).replace(/\n$/,""),title:null==s?void 0:s.fileName})},tr=e=>{let{markdown:t}=e;return(0,i.jsx)(tt.D,{children:t,linkTarget:"_blank",remarkPlugins:[tn.Z],components:{code:e=>(0,i.jsx)(tl,{...e}),h1:e=>(0,i.jsx)(a.bL,{children:e.children,component:"h1",variant:"h1"}),h2:e=>(0,i.jsx)(a.bL,{children:e.children,component:"h2",variant:"h2"}),h3:e=>(0,i.jsx)(a.bL,{children:e.children,component:"h3",variant:"h3"}),h4:e=>(0,i.jsx)(a.bL,{children:e.children,component:"h4",variant:"h4"}),h5:e=>(0,i.jsx)(a.bL,{children:e.children,component:"h4",variant:"h4"}),p:e=>(0,i.jsx)(a.bL,{className:to().section,children:e.children,component:"p",variant:"normal"}),pre:e=>(0,i.jsx)(a.bL,{className:to().section,children:e.children,component:"pre",variant:"normal"})}})};async function ts(e){let t=JSON.parse(e),{errors:n,documentation:i}=await Y.managerClient.documentation.read({kind:t.kind,data:t.data});if(n.length>0)throw n;return i}var tc=n(65480),td=n.n(tc);let tm=e=>{var t;let{model:n}=e,o=(0,ti.p)(),l=(t={kind:"PageSnippet",data:{model:n}},(0,eC.QT)(ts,[JSON.stringify(t)])),{completeStep:r}=(0,er.k)();return 0===l.length?null:(0,i.jsxs)(a.ae,{size:"small",trigger:(0,i.jsx)(a.E,{color:"grey",onClick:()=>{r("codePage"),g.Xe.track({event:"page-type:open-snippet",framework:o})},startIcon:"code",children:"Page snippet"}),children:[(0,i.jsx)(a.al,{icon:"code",title:"Page snippet"}),(0,i.jsx)("section",{className:td().content,children:l.length>1?(0,i.jsx)(te,{style:{flex:1},tabs:l.map((e,t)=>{let{label:n,content:a}=e;return{label:null!=n?n:"Tab ".concat(t+1),content:(0,i.jsx)(tr,{markdown:a})}})}):(0,i.jsx)(a.bn,{style:{flex:1,padding:16},children:(0,i.jsx)(tr,{markdown:l[0].content})})})]})},th=e=>{let{model:t}=e;return(0,i.jsx)("div",{children:(0,i.jsx)(U.h,{children:(0,i.jsx)(s.Suspense,{fallback:(0,i.jsx)(a.E,{color:"grey",startIcon:"code",children:"Page snippet"}),children:(0,i.jsx)(tm,{model:t})})})})},tu=()=>{let e=(0,r.useRouter)(),{selectedCustomType:t}=(0,c.v9)(t=>({selectedCustomType:(0,e3.Jk)(t,(0,u.Ag)(e.query))}));return((0,s.useEffect)(()=>{t&&(0,e8.TG)(t)||e.replace("/")},[t,e]),t&&(0,e8.TG)(t))?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(l(),{children:(0,i.jsxs)("title",{children:[t.local.label," - Slice Machine"]})}),(0,i.jsx)(tp,{customType:t.local})]}):(0,i.jsx)(p.LN,{})},tp=e=>{let{customType:t}=e;return null===t?(0,i.jsx)(p.LN,{}):(0,i.jsx)(p.LN,{children:(0,i.jsx)(S,{initialCustomType:T.Dc.fromSM(t),children:e=>{var n;let{actionQueueStatus:o,customType:l,setCustomType:r}=e,s=(0,m.y6)(l),c=u.cd[t.format],f=v.$[t.format];return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsxs)(p.wd,{children:[(0,i.jsx)(p.Xq,{url:c.tablePagePathname}),(0,i.jsxs)(p.Cx,{children:[(0,i.jsx)(d.g,{children:f.name({start:!0,plural:!0})}),(0,i.jsx)(d.g,{active:!0,children:null!==(n=l.label)&&void 0!==n?n:l.id})]}),(0,i.jsxs)(p.K2,{children:[(0,i.jsx)(h.X,{status:o}),"page"===l.format?(0,i.jsx)(th,{model:l}):void 0,(0,i.jsx)(e2._,{isChangesLocal:!0,format:s,customType:l,setLocalCustomType:r})]})]}),(0,i.jsx)(p.RN,{children:(0,i.jsx)(a.D,{flexDirection:"column",minWidth:0,children:(0,i.jsx)(e4,{})})})]})}})})}},84879:function(e,t,n){"use strict";n.d(t,{E:function(){return l}});var i=n(18566),a=n(80148);async function o(){return a.managerClient.project.getSliceMachineConfig()}function l(e){var t,n;let[l,r]=[(0,i.QT)(o,[]),async e=>{await a.managerClient.project.writeSliceMachineConfig({config:e}),(0,i.VA)(o,[],e)}],s=async t=>{let n={...l,labs:{...l.labs}};t?n.labs[e]=t:e in n.labs&&delete n.labs[e],0===Object.keys(n.labs).length&&delete n.labs,await r(n)};return[{enabled:null!==(n=null==l?void 0:null===(t=l.labs)||void 0===t?void 0:t[e])&&void 0!==n&&n},s]}},34919:function(e){e.exports={flex:"ContentTabs_flex__T21Oc",column:"ContentTabs_column__1f8b8 ContentTabs_flex__T21Oc",root:"ContentTabs_root__Gn3Zg ContentTabs_column__1f8b8 ContentTabs_flex__T21Oc",list:"ContentTabs_list__rAZtl ContentTabs_flex__T21Oc",trigger:"ContentTabs_trigger__cTyPN ContentTabs_column__1f8b8 ContentTabs_flex__T21Oc",triggerText:"ContentTabs_triggerText__p_ZBl",content:"ContentTabs_content__H1Stj ContentTabs_column__1f8b8 ContentTabs_flex__T21Oc",scrollArea:"ContentTabs_scrollArea__DuDcQ"}},65480:function(e){e.exports={content:"PageSnippetDialog_content__jIN6d"}},44621:function(e){e.exports={section:"MarkdownRenderer_section__uNS1M",inlineCode:"MarkdownRenderer_inlineCode__lmGTi"}},65375:function(e){e.exports={scrollArea:"ConvertLegacySliceButton_scrollArea__xf3vM",label:"ConvertLegacySliceButton_label__BK0Gd"}}}]);