@baseplate-dev/project-builder-web
Version:
Web interface for constructing project builder JSON
3 lines (2 loc) • 4.03 kB
JavaScript
import{i}from"./_virtual___federation_fn_import-DOo8C-zl.js";import{j as e}from"./jsx-runtime-D_zvdyIk.js";import{b as C,l as k}from"./index-DiAhmW9l.js";import{f as v}from"./index.esm-DImnoN58.js";import{w as U}from"./words-Cs2RBKRm.js";import{s as S}from"./sortBy-C9bvycg5.js";function q(h){const l=U(h.trim());let s="";for(let n=0;n<l.length;n++){const c=l[n];s&&(s+=" "),s+=c[0].toUpperCase()+c.slice(1).toLowerCase()}return s}const{appEntityType:T,baseAppSchema:z,baseLibrarySchema:G,libraryEntityType:D,libraryTypeSpec:J}=await i("@baseplate-dev/project-builder-lib"),{useProjectDefinition:K}=await i("@baseplate-dev/project-builder-lib/web"),{Button:u,Dialog:Q,DialogContent:X,DialogDescription:Y,DialogFooter:N,DialogHeader:Z,DialogTitle:_,DialogTrigger:ee,InputFieldController:A,SelectFieldController:F,Tabs:ae,TabsContent:I,TabsList:te,TabsTrigger:$,useControlledState:se}=await i("@baseplate-dev/ui-components"),{useNavigate:ne,useRouter:oe}=await i("@tanstack/react-router"),{useState:re}=await i("react");function me({children:h,open:l,onOpenChange:s,defaultTab:n="app"}){const[c,P]=se(l,s,!1),[E,g]=re(n),{saveDefinitionWithFeedback:f,isSavingDefinition:p,pluginContainer:L}=K(),w=L.use(J),O=[...w.webConfigs.entries()],j=ne(),x=oe(),d=v({resolver:C(z),defaultValues:{id:"",name:"",type:"backend"}}),b=v({resolver:C(G),defaultValues:{id:"",name:"",type:"node-library"}}),B=[{label:"Backend App",value:"backend"},{label:"Web App",value:"web"}],V=O.map(([a,t])=>({label:t.displayName,value:a})),W=d.handleSubmit(a=>{const t=T.generateNewId();return f(r=>{const y=[...r.apps,{...a,id:t,...a.type==="web"&&{title:q(a.name),description:`A ${a.type} application`}}];r.apps=S(y,[m=>m.name])},{successMessage:`Successfully created ${a.name}!`,onSuccess:()=>{o(!1),x.invalidate().then(()=>{j({to:`/packages/apps/${T.keyFromId(t)}`})}).catch(k)}})}),M=b.handleSubmit(a=>{const t=D.generateNewId(),r=w.webConfigs.get(a.type);if(!r)throw new Error(`No web config found for library type: ${a.type}`);const y=r.createDefinition({id:t,name:a.name});return f(m=>{const R=[...m.libraries,y];m.libraries=S(R,[H=>H.name])},{successMessage:`Successfully created ${a.name}!`,onSuccess:()=>{o(!1),x.invalidate().then(()=>{j({to:"/packages/libs/$key",params:{key:D.keyFromId(t)}})}).catch(k)}})}),o=a=>{P(a),a||(d.reset(),b.reset(),g(n))};return e.jsxs(Q,{open:c,onOpenChange:o,children:[e.jsx(ee,{asChild:!0,children:h}),e.jsxs(X,{className:"sm:max-w-md",children:[e.jsxs(Z,{children:[e.jsx(_,{children:"Create New"}),e.jsx(Y,{children:"Add a new app or package to your project."})]}),e.jsxs(ae,{value:E,onValueChange:a=>{g(a)},children:[e.jsxs(te,{className:"w-full",children:[e.jsx($,{value:"app",children:"App"}),e.jsx($,{value:"library",children:"Library"})]}),e.jsx(I,{value:"app",children:e.jsxs("form",{onSubmit:a=>(a.stopPropagation(),W(a)),className:"space-y-4",children:[e.jsx(A,{label:"Name",control:d.control,name:"name",placeholder:"e.g. backend, web, admin",description:"The name of the app, such as 'backend' or 'web'",autoComplete:"off"}),e.jsx(F,{label:"Type",control:d.control,name:"type",options:B,description:"Backend apps provide APIs, web apps are client applications"}),e.jsxs(N,{children:[e.jsx(u,{type:"button",variant:"outline",onClick:()=>{o(!1)},children:"Cancel"}),e.jsx(u,{type:"submit",disabled:p,children:p?"Creating...":"Create App"})]})]})}),e.jsx(I,{value:"library",children:e.jsxs("form",{onSubmit:a=>(a.stopPropagation(),M(a)),className:"space-y-4",children:[e.jsx(A,{label:"Name",control:b.control,name:"name",placeholder:"e.g. shared-utils, common",description:"The name of the package in kebab-case",autoComplete:"off"}),e.jsx(F,{label:"Type",control:b.control,name:"type",options:V,description:"The type of library package to create"}),e.jsxs(N,{children:[e.jsx(u,{type:"button",variant:"outline",onClick:()=>{o(!1)},children:"Cancel"}),e.jsx(u,{type:"submit",disabled:p,children:p?"Creating...":"Create Package"})]})]})})]})]})]})}export{me as N};
//# sourceMappingURL=new-dialog-Dom1lleR.js.map