@baseplate-dev/project-builder-web 0.2.4 → 0.2.6
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/dist/assets/{-constants-BC9esibq.js → -constants-CqYT9Sad.js} +2 -2
- package/dist/assets/{-constants-BC9esibq.js.map → -constants-CqYT9Sad.js.map} +1 -1
- package/dist/assets/__federation_shared_@baseplate-dev/project-builder-lib/{web-BaAZd6c4.js → web-CEscUEnR.js} +2 -2
- package/dist/assets/__federation_shared_@baseplate-dev/project-builder-lib/{web-BaAZd6c4.js.map → web-CEscUEnR.js.map} +1 -1
- package/dist/assets/__federation_shared_@baseplate-dev/project-builder-lib-CzpSl25Z.js +5 -0
- package/dist/assets/__federation_shared_@baseplate-dev/project-builder-lib-CzpSl25Z.js.map +1 -0
- package/dist/assets/__federation_shared_@baseplate-dev/{ui-components-CbLT5eCP.js → ui-components-Bpztr-cx.js} +4 -4
- package/dist/assets/__federation_shared_@baseplate-dev/ui-components-Bpztr-cx.js.map +1 -0
- package/dist/assets/{_virtual___federation_fn_import-CzwHXTRo.js → _virtual___federation_fn_import-BLYgPlMt.js} +2 -2
- package/dist/assets/{_virtual___federation_fn_import-CzwHXTRo.js.map → _virtual___federation_fn_import-BLYgPlMt.js.map} +1 -1
- package/dist/assets/{backend-B3MDDop9.js → backend-hJNcdERv.js} +2 -2
- package/dist/assets/{backend-B3MDDop9.js.map → backend-hJNcdERv.js.map} +1 -1
- package/dist/assets/{badge-with-type-label-CNVJUqNt.js → badge-with-type-label-CezAtjFy.js} +2 -2
- package/dist/assets/{badge-with-type-label-CNVJUqNt.js.map → badge-with-type-label-CezAtjFy.js.map} +1 -1
- package/dist/assets/{edit._id-Ce2Ymc-o.js → edit._id-bMpe6S3O.js} +2 -2
- package/dist/assets/{edit._id-Ce2Ymc-o.js.map → edit._id-bMpe6S3O.js.map} +1 -1
- package/dist/assets/{enum-info-form-CVHvQqYN.js → enum-info-form-xlZ2HO8I.js} +2 -2
- package/dist/assets/{enum-info-form-CVHvQqYN.js.map → enum-info-form-xlZ2HO8I.js.map} +1 -1
- package/dist/assets/{graphql-BlURtGp8.js → graphql-D3J4ZWXL.js} +2 -2
- package/dist/assets/{graphql-BlURtGp8.js.map → graphql-D3J4ZWXL.js.map} +1 -1
- package/dist/assets/{hierarchy-B1V1qwhL.js → hierarchy-DF9lzUjz.js} +2 -2
- package/dist/assets/{hierarchy-B1V1qwhL.js.map → hierarchy-DF9lzUjz.js.map} +1 -1
- package/dist/assets/{immer-xieDw-3D.js → immer-BOh2djD_.js} +2 -2
- package/dist/assets/{immer-xieDw-3D.js.map → immer-BOh2djD_.js.map} +1 -1
- package/dist/assets/{index-BEMXZzJT.js → index-1ErFJbDw.js} +2 -2
- package/dist/assets/{index-BEMXZzJT.js.map → index-1ErFJbDw.js.map} +1 -1
- package/dist/assets/index-37eYMUXo.js +2 -0
- package/dist/assets/index-37eYMUXo.js.map +1 -0
- package/dist/assets/{index-1rH5AIf1.js → index-B5-Qczd9.js} +2 -2
- package/dist/assets/{index-1rH5AIf1.js.map → index-B5-Qczd9.js.map} +1 -1
- package/dist/assets/{index-Bw18F51O.js → index-BLuLGksP.js} +2 -2
- package/dist/assets/{index-Bw18F51O.js.map → index-BLuLGksP.js.map} +1 -1
- package/dist/assets/index-BPK2SbiO.js +2 -0
- package/dist/assets/index-BPK2SbiO.js.map +1 -0
- package/dist/assets/{index-1DYdEncJ.js → index-BdmJimiZ.js} +2 -2
- package/dist/assets/{index-1DYdEncJ.js.map → index-BdmJimiZ.js.map} +1 -1
- package/dist/assets/{index-BRdI-lNh.js → index-Bv8hyN9u.js} +2 -2
- package/dist/assets/{index-BRdI-lNh.js.map → index-Bv8hyN9u.js.map} +1 -1
- package/dist/assets/{index-BxN9iLEr.js → index-C15I7WFi.js} +2 -2
- package/dist/assets/{index-BxN9iLEr.js.map → index-C15I7WFi.js.map} +1 -1
- package/dist/assets/{index-BMCloLL3.js → index-C_wN4CIq.js} +19 -19
- package/dist/assets/index-C_wN4CIq.js.map +1 -0
- package/dist/assets/index-DBOJRz5n.css +1 -0
- package/dist/assets/{index-DlrvL7L-.js → index-DJsZccoO.js} +2 -2
- package/dist/assets/{index-DlrvL7L-.js.map → index-DJsZccoO.js.map} +1 -1
- package/dist/assets/{index-DJrwWHdu.js → index-DwyYddxl.js} +2 -2
- package/dist/assets/{index-DJrwWHdu.js.map → index-DwyYddxl.js.map} +1 -1
- package/dist/assets/index-P-wtG1LL.js +2 -0
- package/dist/assets/index-P-wtG1LL.js.map +1 -0
- package/dist/assets/{index.esm-C6ngV5UE.js → index.esm-DcyGeCKA.js} +2 -2
- package/dist/assets/{index.esm-C6ngV5UE.js.map → index.esm-DcyGeCKA.js.map} +1 -1
- package/dist/assets/{model-info-form-B3UWaCuz.js → model-info-form-VtbYsjrH.js} +2 -2
- package/dist/assets/{model-info-form-B3UWaCuz.js.map → model-info-form-VtbYsjrH.js.map} +1 -1
- package/dist/assets/model-merger-qJqD9I2_.js +2 -0
- package/dist/assets/{model-merger-BoPVsTMR.js.map → model-merger-qJqD9I2_.js.map} +1 -1
- package/dist/assets/{new-app-dialog-DmiiaAcy.js → new-app-dialog-CTtQ52jO.js} +2 -2
- package/dist/assets/{new-app-dialog-DmiiaAcy.js.map → new-app-dialog-CTtQ52jO.js.map} +1 -1
- package/dist/assets/{new-enum-dialog-eE-ABw-k.js → new-enum-dialog-B0QcIWdY.js} +2 -2
- package/dist/assets/{new-enum-dialog-eE-ABw-k.js.map → new-enum-dialog-B0QcIWdY.js.map} +1 -1
- package/dist/assets/{new-model-dialog-DsUABBKe.js → new-model-dialog-CM2dJ8Iv.js} +2 -2
- package/dist/assets/{new-model-dialog-DsUABBKe.js.map → new-model-dialog-CM2dJ8Iv.js.map} +1 -1
- package/dist/assets/{route-CBp4D5qe.js → route-B34jnFQF.js} +2 -2
- package/dist/assets/{route-CBp4D5qe.js.map → route-B34jnFQF.js.map} +1 -1
- package/dist/assets/{route-MODh5ysn.js → route-BRBmSLMi.js} +2 -2
- package/dist/assets/{route-MODh5ysn.js.map → route-BRBmSLMi.js.map} +1 -1
- package/dist/assets/{route-Cey_4lZX.js → route-BsIUCKz1.js} +2 -2
- package/dist/assets/{route-Cey_4lZX.js.map → route-BsIUCKz1.js.map} +1 -1
- package/dist/assets/route-CAp89B2q.js +2 -0
- package/dist/assets/{route-CqtFDOsk.js.map → route-CAp89B2q.js.map} +1 -1
- package/dist/assets/{route-rX4E9J5V.js → route-DcsVxxui.js} +2 -2
- package/dist/assets/{route-rX4E9J5V.js.map → route-DcsVxxui.js.map} +1 -1
- package/dist/assets/{route-BcszKLdV.js → route-DmdFbZkw.js} +2 -2
- package/dist/assets/{route-BcszKLdV.js.map → route-DmdFbZkw.js.map} +1 -1
- package/dist/assets/{route-DioBcaFQ.js → route-Dpmx4lrA.js} +2 -2
- package/dist/assets/{route-DioBcaFQ.js.map → route-Dpmx4lrA.js.map} +1 -1
- package/dist/assets/route-T4J_Uk-9.js +2 -0
- package/dist/assets/route-T4J_Uk-9.js.map +1 -0
- package/dist/assets/{route-sqtj7nCf.js → route-w8_2x1VY.js} +2 -2
- package/dist/assets/{route-sqtj7nCf.js.map → route-w8_2x1VY.js.map} +1 -1
- package/dist/assets/{service-CuzPG1Yl.js → service-Bgm1ICPI.js} +2 -2
- package/dist/assets/{service-CuzPG1Yl.js.map → service-Bgm1ICPI.js.map} +1 -1
- package/dist/assets/{template-extractor-B9fEhgo_.js → template-extractor-DEU0CX0Y.js} +2 -2
- package/dist/assets/{template-extractor-B9fEhgo_.js.map → template-extractor-DEU0CX0Y.js.map} +1 -1
- package/dist/assets/{theme-builder-Bw8c01EE.js → theme-builder-La1nKR0K.js} +2 -2
- package/dist/assets/{theme-builder-Bw8c01EE.js.map → theme-builder-La1nKR0K.js.map} +1 -1
- package/dist/assets/{use-definition-schema-DANa9pch.js → use-definition-schema-CuFFJIzk.js} +2 -2
- package/dist/assets/{use-definition-schema-DANa9pch.js.map → use-definition-schema-CuFFJIzk.js.map} +1 -1
- package/dist/assets/{use-enum-form-Dz-Wnbxj.js → use-enum-form-DKD2EDHZ.js} +2 -2
- package/dist/assets/{use-enum-form-Dz-Wnbxj.js.map → use-enum-form-DKD2EDHZ.js.map} +1 -1
- package/dist/assets/{use-model-form-DMG7DdSK.js → use-model-form-BQa-PiE_.js} +2 -2
- package/dist/assets/{use-model-form-DMG7DdSK.js.map → use-model-form-BQa-PiE_.js.map} +1 -1
- package/dist/assets/{utils-95Eli4qP.js → utils-BYjOwi1b.js} +2 -2
- package/dist/assets/{utils-95Eli4qP.js.map → utils-BYjOwi1b.js.map} +1 -1
- package/dist/index.html +6 -6
- package/package.json +6 -6
- package/dist/assets/__federation_shared_@baseplate-dev/project-builder-lib-C7fVVw7M.js +0 -5
- package/dist/assets/__federation_shared_@baseplate-dev/project-builder-lib-C7fVVw7M.js.map +0 -1
- package/dist/assets/__federation_shared_@baseplate-dev/ui-components-CbLT5eCP.js.map +0 -1
- package/dist/assets/index-B9Di1LKs.css +0 -1
- package/dist/assets/index-BMCloLL3.js.map +0 -1
- package/dist/assets/index-BazMYfmA.js +0 -2
- package/dist/assets/index-BazMYfmA.js.map +0 -1
- package/dist/assets/index-D9m5kBYP.js +0 -2
- package/dist/assets/index-D9m5kBYP.js.map +0 -1
- package/dist/assets/model-merger-BoPVsTMR.js +0 -2
- package/dist/assets/route-CqtFDOsk.js +0 -2
- package/dist/assets/route-VW3n5-PC.js +0 -2
- package/dist/assets/route-VW3n5-PC.js.map +0 -1
- package/dist/assets/sections-D48VzvlO.js +0 -2
- package/dist/assets/sections-D48VzvlO.js.map +0 -1
- package/dist/assets/sections._sectionKey-Cojmxr6C.js +0 -2
- package/dist/assets/sections._sectionKey-Cojmxr6C.js.map +0 -1
- package/dist/assets/web-B6BjTv_c.js +0 -2
- package/dist/assets/web-B6BjTv_c.js.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{i as f}from"./_virtual___federation_fn_import-CzwHXTRo.js";import{j as e,u as I,b as ie,e as le,f as Se}from"./index.esm-C6ngV5UE.js";import{s as te,m as U,e as ne,S as $e,n as Ne,a as Fe,r as se}from"./index-BMCloLL3.js";import{u as g,S as Me,E as Ie}from"./-constants-BC9esibq.js";import{u as Le}from"./use-model-form-DMG7DdSK.js";import{q as Te,c as w,L as Ee,N as Oe,O as Ue,P as qe,I as ve,K as be,B as Ce}from"./index-BxN9iLEr.js";import{i as Pe}from"./inflection-C1nKqrJS.js";import{c as Ae}from"./capitalize-gOJXDbsR.js";const Be=/\p{Lu}?\p{Ll}+|[0-9]+|\p{Lu}+(?!\p{Ll})|\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{L}+/gu;function Ke(d){return Array.from(d.match(Be)??[])}function M(d){const t=Ke(d);if(t.length===0)return"";const[s,...l]=t;return`${s.toLowerCase()}${l.map(r=>Ae(r)).join("")}`}const{modelScalarFieldEntityType:ae}=await f("@baseplate-dev/project-builder-lib"),{Button:re,ButtonGroup:ze,DropdownMenu:Ve,DropdownMenuContent:ke,DropdownMenuItem:He,DropdownMenuTrigger:_e}=await f("@baseplate-dev/ui-components"),{useMemo:We}=await f("react");function Ge({className:d,appendField:t,setValue:s}){const l=g(i=>i.model.fields.map(a=>a.name)),r=g(i=>i.model.primaryKeyFieldRefs.length),n=We(()=>{const i=[];r||i.push({name:"ID (uuid)",fields:[{name:"id",type:"uuid",options:{genUuid:!0},isPrimaryKey:!0}]});const a=l.includes("createdAt"),m=l.includes("updatedAt");return(!a||!m)&&i.push({name:"Timestamps",fields:[{name:"createdAt",type:"dateTime",options:{defaultToNow:!0}},{name:"updatedAt",type:"dateTime",options:{updatedAt:!0,defaultToNow:!0}}]}),i},[l,r]),o=i=>{for(const{isPrimaryKey:a,...m}of i.fields){const c=ae.generateNewId();l.includes(m.name)||t({id:c,...m}),a&&s("model.primaryKeyFieldRefs",[c],{shouldDirty:!0})}};return e.jsxs(ze,{className:d,children:[e.jsx(re,{variant:"secondary",onClick:()=>{t({id:ae.generateNewId(),name:"",type:"string",isOptional:!0,options:{default:""}})},size:"sm",children:"Add Field"}),e.jsxs(Ve,{children:[e.jsx(_e,{disabled:n.length===0,asChild:!0,children:e.jsx(re,{variant:"secondary",size:"sm",children:e.jsx(Te,{})})}),e.jsx(ke,{children:n.map(i=>e.jsx(He,{onClick:()=>{o(i)},children:i.name},i.name))})]})]})}const{Button:de,DialogClose:Ye,DialogFooter:Xe,MultiComboboxFieldController:Je}=await f("@baseplate-dev/ui-components"),{useId:Qe}=await f("react"),{z:W}=await f("zod"),Ze=W.object({fields:W.array(W.string()).min(1,"At least one primary key is required")});function en({className:d,control:t,onSubmitSuccess:s}){const l=g(c=>c.model.fields),{field:{value:r=[],onChange:n}}=I({name:"model.primaryKeyFieldRefs",control:t}),{control:o,handleSubmit:i}=ie({resolver:te(Ze),values:{fields:r}}),a=i(c=>{n(c.fields),s?.()}),m=Qe();return e.jsxs("form",{className:w("space-y-4",d),onSubmit:c=>(c.stopPropagation(),a(c)),id:m,children:[e.jsx(Je,{control:o,name:"fields",options:l.map(c=>({value:c.id,label:c.name})),placeholder:"Select fields to use as primary keys"}),e.jsxs(Xe,{children:[e.jsx(Ye,{asChild:!0,children:e.jsx(de,{variant:"secondary",children:"Cancel"})}),e.jsx(de,{type:"submit",form:m,children:"Save"})]})]})}const{Dialog:nn,DialogContent:tn,DialogDescription:sn,DialogHeader:on,DialogTitle:ln,DialogTrigger:an,useControlledState:rn}=await f("@baseplate-dev/ui-components");function we({control:d,children:t,asChild:s,open:l,onOpenChange:r}){const[n,o]=rn(l,r,!1);return e.jsxs(nn,{open:n,onOpenChange:o,children:[t&&e.jsx(an,{asChild:s,children:t}),e.jsxs(tn,{children:[e.jsxs(on,{children:[e.jsx(ln,{children:"Primary Keys"}),e.jsx(sn,{children:"Select the fields that will be used as the primary key for this model"})]}),e.jsx(en,{control:d,onSubmitSuccess:()=>{o(!1)}})]})]})}const{BadgeWithIcon:dn}=await f("@baseplate-dev/ui-components"),{useState:cn}=await f("react");function mn({className:d,control:t,autoCollapse:s}){const[l,r]=cn(!1),n=!s||l;return e.jsx(we,{control:t,children:e.jsx(dn,{icon:Ee,variant:"secondary",className:d,onMouseEnter:()=>{r(!0)},onMouseLeave:()=>{r(!1)},"aria-label":"Primary Key",title:"Primary Key",children:n&&"Primary"})})}const{createModelRelationFieldSchema:un,ModelFieldUtils:fn,modelForeignRelationEntityType:pn,modelLocalRelationEntityType:hn,ModelUtils:ce}=await f("@baseplate-dev/project-builder-lib"),{useDefinitionSchema:xn,useProjectDefinition:jn}=await f("@baseplate-dev/project-builder-lib/web"),{Button:G,ComboboxField:gn,ComboboxFieldController:Y,DialogClose:yn,DialogFooter:vn,InputFieldController:me,SelectFieldController:bn,toast:ue}=await f("@baseplate-dev/ui-components"),De=await f("react"),{useId:Cn,useMemo:wn}=De;function Dn(d,t,s){if(!s)return;const l=s.replace(/Id$/,""),r=a=>d.models.find(m=>m.id!==t.id&&a(m))?.id,n=r(a=>a.name.toLowerCase()===l.toLowerCase());if(n)return n;const o=r(a=>a.featureRef===a.featureRef&&a.name.toLowerCase().includes(l.toLowerCase()));return o||r(a=>a.name.toLowerCase().includes(l.toLowerCase()))}function fe(d,t,s,l){const r=(()=>{if(s.name)return s.name;if(s.modelRef){const i=ce.byIdOrThrow(d,s.modelRef);return M(i.name)}})(),n=(()=>{if(!s.modelRef)return;const{model:{fields:i,primaryKeyFieldRefs:a},name:m}=ce.byIdOrThrow(d,s.modelRef),c=i.filter(x=>a.includes(x.id)),p=s.references??[];return c.map((x,h)=>{const D=h===0&&l?l:c.length===1?`${M(m)}Id`:x.name;return{localRef:p[h]?.localRef??t.model.fields.find(y=>y.name===D)?.id,foreignRef:x.id}})})(),o=(()=>{if(!n)return;if(s.foreignRelationName)return s.foreignRelationName;const i=n.every(a=>a.localRef)&&fn.areScalarsUnique(t,n.map(a=>a.localRef));return M(i?t.name:Pe.pluralize(t.name))})();return{name:r??"",foreignRelationName:o??"",references:n??[]}}function Rn({className:d,control:t,onSubmitSuccess:s,relationId:l,defaultFieldName:r}){const{definition:n}=jn(),o=g(u=>u),i=o.name,{fields:a}=o.model,{field:{value:m=[],onChange:c}}=I({name:"model.relations",control:t}),p=n.models.map(u=>({label:u.name,value:u.id})),x=l===void 0?void 0:m.find(u=>u.id===l),h=wn(()=>{if(x)return x;const u=Dn(n,o,r);return{id:hn.generateNewId(),foreignId:pn.generateNewId(),modelRef:u??"",onDelete:"Restrict",onUpdate:"Restrict",...fe(n,o,{modelRef:u},r)}},[x,r,n,o]),D=xn(un),{control:b,handleSubmit:y,setError:H,watch:P,setValue:L}=ie({resolver:te(D),defaultValues:h}),S=P(),$=S.modelRef?n.models.find(u=>u.id===S.modelRef):void 0,T=$?.model.fields,_=a.map(u=>({label:u.name,value:u.id})),A=T?.map(u=>({label:u.name,value:u.id}))??[],j=S.references.some(u=>a.find(C=>C.id===u.localRef)?.isOptional),R=()=>{c(m.filter(u=>u.id!==l)),s?.()},Re=y(u=>{const{id:C}=u;if(a.some(v=>v.name===u.name)||m.some(v=>v.name===u.name&&v.id!==u.id)){H("name",{message:"The relation name cannot be the same as a field/relation name"});return}const O=u.references.map(v=>v.localRef);if(new Set(O).size!==O.length){ue.error("Local fields must be unique");return}const B=u.references.map(v=>v.foreignRef);if(new Set(B).size!==B.length){ue.error("Foreign fields must be unique");return}m.some(v=>v.id===C)?c(m.map(v=>v.id===C?u:v)):c([...m,u]),s?.()}),oe=Cn(),E=!!$;return e.jsxs("form",{className:w("space-y-4",d),onSubmit:u=>(u.stopPropagation(),Re(u)),id:oe,children:[e.jsxs("div",{className:"grid grid-cols-2 gap-x-8 gap-y-2",children:[e.jsx(gn,{options:[{label:i,value:i}],value:i,disabled:!0,label:"Local Model"}),e.jsx(Y,{control:b,name:"modelRef",options:p,label:"Foreign Model",onChange:u=>{if(!u)return;const{foreignRelationName:C,name:O,references:B}=fe(n,o,{...S,modelRef:u},r);C&&L("foreignRelationName",C),O&&L("name",O),L("references",B)}})]}),e.jsxs("div",{className:w("grid grid-cols-2 gap-x-8 gap-y-2",!E&&"pointer-events-none opacity-50"),children:[e.jsx(me,{control:b,disabled:!E,name:"name",label:"Local Relation Name",description:e.jsxs("span",{children:["Name of the relation, e.g. ",M(i),".",e.jsx("strong",{children:$?.name?M($.name):"user"})]})}),e.jsx(me,{control:b,disabled:!E,name:"foreignRelationName",label:"Foreign Relation Name",description:e.jsxs("span",{children:["Name of the relation on the foreign model, e.g."," ",M($?.name??"post"),".",e.jsx("strong",{children:h.foreignRelationName||"user"})]})}),e.jsx("div",{className:"text-sm font-medium",children:"Local Field"}),e.jsx("div",{className:"text-sm font-medium",children:"Foreign Field"}),S.references.map((u,C)=>e.jsxs(De.Fragment,{children:[e.jsx(Y,{disabled:!E,control:b,name:`references.${C}.localRef`,options:_}),e.jsx(Y,{control:b,name:`references.${C}.foreignRef`,options:A,disabled:!0})]},C))]}),e.jsx("div",{className:"grid grid-cols-2 gap-x-8 gap-y-2 border-t pt-4",children:e.jsx(bn,{label:"On Delete",control:b,options:[{label:"Cascade (delete entire local row)",value:"Cascade"},{label:"Restrict (throw error)",value:"Restrict"},...j?[{label:"Set Null (set local field to null)",value:"SetNull"}]:[]],name:"onDelete",description:"What to do when the foreign row is deleted"})}),e.jsx(vn,{children:e.jsxs("div",{className:"flex w-full justify-between",children:[l&&e.jsx(G,{variant:"secondary",onClick:u=>{u.preventDefault(),R()},children:"Delete"}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(yn,{asChild:!0,children:e.jsx(G,{variant:"secondary",children:"Cancel"})}),e.jsx(G,{type:"submit",form:oe,disabled:!E,children:"Save"})]})]})})]})}const{Dialog:Sn,DialogContent:$n,DialogDescription:Nn,DialogHeader:Fn,DialogTitle:Mn,DialogTrigger:In,useControlledState:Ln}=await f("@baseplate-dev/ui-components");function V({control:d,children:t,asChild:s,open:l,onOpenChange:r,relationId:n,defaultFieldName:o}){const[i,a]=Ln(l,r,!1);return e.jsxs(Sn,{open:i,onOpenChange:a,children:[t&&e.jsx(In,{asChild:s,children:t}),e.jsxs($n,{width:"lg",children:[e.jsxs(Fn,{children:[e.jsx(Mn,{children:n?"Edit Relation":"Create Relation"}),e.jsx(Nn,{children:"Set up the relation between this model and another model"})]}),e.jsx(Rn,{control:d,onSubmitSuccess:()=>{a(!1)},relationId:n,defaultFieldName:o})]})]})}const{useProjectDefinition:Tn}=await f("@baseplate-dev/project-builder-lib/web"),{BadgeWithIcon:En}=await f("@baseplate-dev/ui-components"),{useState:On}=await f("react");function Un({className:d,control:t,relation:s,autoCollapse:l}){const{definitionContainer:r}=Tn(),[n,o]=On(!1),i=!l||n;return e.jsx(V,{control:t,relationId:s.id,children:e.jsx(En,{icon:Oe,variant:"secondary",className:w("max-w-[100px]",d),onMouseEnter:()=>{o(!0)},onMouseLeave:()=>{o(!1)},"aria-label":"Relation",title:"Relation",children:i&&`${r.nameFromId(s.modelRef)} ${s.references.length>1?`(${s.references.length})`:""}`})})}const{modelUniqueConstraintEntityType:qn}=await f("@baseplate-dev/project-builder-lib"),{Button:X,DialogClose:Pn,DialogFooter:An,MultiComboboxFieldController:Bn}=await f("@baseplate-dev/ui-components"),{useId:Kn}=await f("react"),{z:K}=await f("zod"),zn=K.object({id:K.string().optional(),fields:K.array(K.string()).min(1,"At least one field is required")});function Vn({className:d,control:t,onSubmitSuccess:s,constraintId:l}){const r=g(h=>h.model.fields),{field:{value:n=[],onChange:o}}=I({name:"model.uniqueConstraints",control:t}),i=l===void 0?void 0:n.find(h=>h.id===l),{control:a,handleSubmit:m}=ie({resolver:te(zn),values:i?{id:i.id,fields:i.fields.map(h=>h.fieldRef)}:{fields:[]}}),c=()=>{o(n.filter(h=>h.id!==l)),s?.()},p=m(h=>{const D={id:h.id??qn.generateNewId(),fields:h.fields.map(y=>({fieldRef:y}))},{id:b}=D;n.some(y=>y.id===b)?o(n.map(y=>y.id===b?D:y)):o([...n,D]),s?.()}),x=Kn();return e.jsxs("form",{className:w("space-y-4",d),onSubmit:h=>(h.stopPropagation(),p(h)),id:x,children:[e.jsx(Bn,{control:a,name:"fields",options:r.map(h=>({value:h.id,label:h.name})),placeholder:"Select fields to use as primary keys"}),e.jsx(An,{children:e.jsxs("div",{className:"flex w-full justify-between",children:[l&&e.jsx(X,{variant:"secondary",onClick:h=>{h.preventDefault(),c()},children:"Delete"}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(Pn,{asChild:!0,children:e.jsx(X,{variant:"secondary",children:"Cancel"})}),e.jsx(X,{type:"submit",form:x,children:"Save"})]})]})})]})}const{Dialog:kn,DialogContent:Hn,DialogDescription:_n,DialogHeader:Wn,DialogTitle:Gn,DialogTrigger:Yn,useControlledState:Xn}=await f("@baseplate-dev/ui-components");function k({control:d,children:t,asChild:s,open:l,onOpenChange:r,constraintId:n}){const[o,i]=Xn(l,r,!1);return e.jsxs(kn,{open:o,onOpenChange:i,children:[t&&e.jsx(Yn,{asChild:s,children:t}),e.jsxs(Hn,{children:[e.jsxs(Wn,{children:[e.jsx(Gn,{children:"Unique Constraint"}),e.jsx(_n,{children:"Select the fields that will be part of this unique constraint."})]}),e.jsx(Vn,{control:d,onSubmitSuccess:()=>{i(!1)},constraintId:n})]})]})}const{BadgeWithIcon:Jn}=await f("@baseplate-dev/ui-components"),{useState:Qn}=await f("react");function Zn({className:d,control:t,constraintId:s,autoCollapse:l}){const[r,n]=Qn(!1),o=!l||r,i=g(a=>a.model.uniqueConstraints?.find(m=>m.id===s)?.fields.length??0);return e.jsx(k,{control:t,constraintId:s,children:e.jsx(Jn,{variant:"secondary",icon:Ue,className:w("",d),onMouseEnter:()=>{n(!0)},onMouseLeave:()=>{n(!1)},"aria-label":"Unique Constraint",title:"Unique Constraint",children:o&&`Unique ${i>1?`(${i})`:""}`})})}function ei({className:d,control:t,idx:s}){const l=g(c=>c.model.fields[s]),r=g(c=>c.model.primaryKeyFieldRefs.includes(l.id)),n=g(c=>c.model.uniqueConstraints?.filter(p=>p.fields.some(x=>x.fieldRef===l.id)).map(p=>p.id)??[]),o=g(({model:c})=>{const p=c.fields[s];return c.relations?.filter(x=>x.references.some(h=>h.localRef===p.id))??[]}),a=(r?1:0)+n.length+o.length>2,m=[r&&e.jsx(mn,{control:t,autoCollapse:a},"primary"),...n.map(c=>e.jsx(Zn,{control:t,constraintId:c,autoCollapse:a},c)),...o.map(c=>e.jsx(Un,{control:t,relation:c,autoCollapse:a},c.id))];return e.jsx("div",{className:w("flex gap-4",d),children:m})}const{EnumUtils:ni}=await f("@baseplate-dev/project-builder-lib"),{useProjectDefinition:ii}=await f("@baseplate-dev/project-builder-lib/web"),{Button:N,ComboboxField:ti,DropdownMenu:pe,DropdownMenuContent:he,DropdownMenuGroup:xe,DropdownMenuItem:J,DropdownMenuTrigger:je,InputField:ge,InputFieldController:Q,SelectFieldController:si}=await f("@baseplate-dev/ui-components");function oi({control:d,idx:t,setValue:s}){const{definition:l}=ii(),r=le({control:d,name:`model.fields.${t}.type`}),{field:{value:n,onChange:o}}=I({name:`model.fields.${t}.options`,control:d}),i=le({control:d,name:`model.fields.${t}.options.default`});if(r==="boolean")return e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(si,{control:d,className:"flex-1",name:`model.fields.${t}.options.default`,options:[{label:"True",value:"true"},{label:"False",value:"false"}],placeholder:"NULL"}),i&&e.jsx(N,{title:"Reset",onClick:()=>{s(`model.fields.${t}.options.default`,"",{shouldDirty:!0})},variant:"ghost",size:"icon",children:e.jsx(U,{})})]});if(["string","int","float"].includes(r))return e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Q,{control:d,placeholder:"NULL",name:`model.fields.${t}.options.default`,className:"flex-1"}),i&&e.jsx(N,{title:"Reset",onClick:()=>{s(`model.fields.${t}.options.default`,void 0,{shouldDirty:!0})},variant:"ghost",size:"icon",children:e.jsx(U,{})})]});if(r==="uuid")return n?.genUuid?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ge,{disabled:!0,value:"Random UUID v4",className:"flex-1"}),e.jsx(N,{title:"Reset",onClick:()=>{o({...n,genUuid:!1})},variant:"ghost",size:"icon",children:e.jsx(U,{})})]}):e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Q,{control:d,placeholder:"NULL",name:`model.fields.${t}.options.default`,className:"flex-1"}),e.jsxs(pe,{children:[e.jsx(je,{asChild:!0,children:e.jsx(N,{title:"Options",variant:"ghost",size:"icon",children:e.jsx(ne,{})})}),e.jsx(he,{children:e.jsx(xe,{children:e.jsx(J,{onSelect:()=>{o({...n,genUuid:!0})},children:"Random UUID v4"})})})]})]});if(r==="dateTime"||r==="date"){const{defaultToNow:a,updatedAt:m}=n??{};return a??m?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ge,{disabled:!0,value:m?"Last Updated":"Now",className:"flex-1"}),e.jsx(N,{title:"Reset",onClick:()=>{o({...n,defaultToNow:!1,updatedAt:!1})},variant:"ghost",size:"icon",children:e.jsx(U,{})})]}):e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(Q,{placeholder:"NULL",control:d,name:`model.fields.${t}.options.default`,className:"flex-1"}),e.jsxs(pe,{children:[e.jsx(je,{asChild:!0,children:e.jsx(N,{title:"Options",variant:"ghost",size:"icon",children:e.jsx(ne,{})})}),e.jsx(he,{children:e.jsxs(xe,{children:[e.jsx(J,{onSelect:()=>{o({...n,defaultToNow:!0,updatedAt:!1})},children:"Now"}),e.jsx(J,{onSelect:()=>{o({...n,defaultToNow:!0,updatedAt:!0})},children:"Last Updated At"})]})})]})]})}if(r==="enum"&&n?.enumRef){const m=ni.byIdOrThrow(l,n.enumRef).values.map(c=>({label:c.friendlyName,value:c.id}));return e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(ti,{placeholder:"NULL",value:n.defaultEnumValueRef??null,onChange:c=>{o({...n,defaultEnumValueRef:c||void 0})},options:m,className:"flex-1"}),n.defaultEnumValueRef&&e.jsx(N,{title:"Reset",onClick:()=>{o({...n,defaultEnumValueRef:""})},variant:"ghost",size:"icon",children:e.jsx(U,{})})]})}return e.jsx("div",{})}const{SCALAR_FIELD_TYPES:li}=await f("@baseplate-dev/project-builder-lib"),{useProjectDefinition:ai}=await f("@baseplate-dev/project-builder-lib/web"),{ComboboxField:ri}=await f("@baseplate-dev/ui-components");function di({control:d,idx:t}){const{definition:s}=ai(),l=(s.enums??[]).map(p=>({label:p.name,value:`enum-${p.id}`,description:"Enum type"})),r=[...li.filter(p=>p!=="enum").map(p=>Me[p]),...l],{field:{value:n,onChange:o}}=I({name:`model.fields.${t}.type`,control:d}),{field:{value:i,onChange:a}}=I({name:`model.fields.${t}.options`,control:d}),m=p=>{if(p?.startsWith("enum-")){const x=p.replace("enum-","");a({enumRef:x}),o("enum")}else o(p)},c=i?.enumRef;return e.jsx("div",{className:"space-y-2",children:e.jsx(ri,{value:n==="enum"&&c?`enum-${c}`:n,onChange:m,options:r,renderItemLabel:p=>e.jsxs("div",{className:"flex flex-col",children:[e.jsx("div",{children:p.label}),e.jsx("div",{className:"text-xs text-muted-foreground",children:p.description})]})})})}const{modelUniqueConstraintEntityType:ci}=await f("@baseplate-dev/project-builder-lib"),{Button:ye,DropdownMenu:mi,DropdownMenuContent:ui,DropdownMenuGroup:fi,DropdownMenuItem:F,DropdownMenuTrigger:pi,InputFieldController:hi,SwitchFieldController:xi,toast:ji}=await f("@baseplate-dev/ui-components"),{useState:q}=await f("react");function gi({className:d,control:t,idx:s,setValue:l,onRemove:r}){const n=g(j=>j.model.fields[s]),o=g(j=>j.model.relations),i=g(j=>j.model.primaryKeyFieldRefs),a=g(j=>j.model.uniqueConstraints)??[],m=i.includes(n.id),c=i.length>1,p=a.filter(j=>j.fields.some(R=>R.fieldRef===n.id)),x=o?.filter(j=>j.references.some(R=>R.localRef===n.id))??[],h=(()=>{if(x.length>0)return`Unable to remove field as it is being used in relations ${x.map(j=>j.name).join(", ")}`;if(m&&c)return"Unable to remove field as it is being used in in the primary key";if(a.some(j=>j.fields.some(R=>R.fieldRef===n.id)))return"Unable to remove field as it is being used in in a unique constraint"})();function D(){if(h){ji.error(h);return}r(s),m&&!c&&l("model.primaryKeyFieldRefs",[],{shouldDirty:!0})}const[b,y]=q(!1),[H,P]=q(!1),[L,S]=q(),[$,T]=q(!1),[_,A]=q();return e.jsxs("div",{className:w("items-center",d),children:[e.jsx("div",{children:e.jsx(hi,{control:t,name:`model.fields.${s}.name`})}),e.jsx("div",{children:e.jsx(di,{control:t,idx:s})}),e.jsx("div",{children:e.jsx(xi,{control:t,name:`model.fields.${s}.isOptional`})}),e.jsx("div",{className:"mr-4",children:e.jsx(oi,{control:t,idx:s,setValue:l})}),e.jsx("div",{children:e.jsx(ei,{control:t,idx:s})}),e.jsx("div",{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(mi,{children:[e.jsx(pi,{asChild:!0,children:e.jsx(ye,{variant:"ghost",size:"icon",children:e.jsx(ne,{})})}),e.jsx(ui,{children:e.jsxs(fi,{children:[x.length===0&&e.jsx(F,{onSelect:()=>{T(!0),A(void 0)},children:"Add Relation"}),x.length>0&&x.map(j=>e.jsxs(F,{onSelect:()=>{T(!0),A(j.id)},children:["Edit Relation ",x.length>1&&j.name]},j.id)),!c&&!m&&e.jsx(F,{onSelect:()=>{l("model.primaryKeyFieldRefs",[n.id],{shouldDirty:!0})},children:"Set as Primary Key"}),m&&e.jsx(F,{onSelect:()=>{y(!0)},children:"Edit Primary Key"}),p.length===0&&(c||!m)&&e.jsx(F,{onSelect:()=>{l("model.uniqueConstraints",[...a,{id:ci.generateNewId(),fields:[{fieldRef:n.id}]}],{shouldDirty:!0})},children:"Make Unique"}),p.length>0&&p.map((j,R)=>e.jsxs(F,{onSelect:()=>{S(j.id),P(!0)},children:["Edit Unique Constraint"," ",p.length>1&&R+1]},j.id))]})})]}),e.jsx(we,{control:t,open:b,onOpenChange:y}),e.jsx(k,{control:t,open:H,onOpenChange:P,constraintId:L}),e.jsx(V,{control:t,open:$,onOpenChange:T,relationId:_,defaultFieldName:n.name}),e.jsx(ye,{variant:"ghost",onClick:()=>{D()},size:"icon",children:e.jsx(qe,{})})]})})]})}function yi({className:d,control:t,setValue:s}){const{fields:l,remove:r,append:n,move:o}=Se({control:t,name:"model.fields"}),i="grid grid-cols-[repeat(2,minmax(130px,1fr))_60px_minmax(130px,1fr)_minmax(100px,1fr)_80px] gap-3",a=l.map((m,c)=>({id:m.id,element:e.jsx(gi,{className:i,control:t,setValue:s,idx:c,onRemove:r},m.id)}));return e.jsxs("div",{className:w("space-y-4",d),children:[l.length===0?e.jsx("p",{className:"pt-4 text-style-muted",children:"Add some fields to get started"}):e.jsxs("div",{className:"flex w-full flex-col gap-2 bg-white",children:[e.jsxs("div",{className:w(i,"sticky -top-0 z-10 bg-white py-2 text-sm font-semibold","pl-12"),children:[e.jsx("div",{children:"Name"}),e.jsx("div",{children:"Type"}),e.jsx("div",{children:"Optional"}),e.jsx("div",{children:"Default Value"}),e.jsx("div",{className:"sr-only",children:"Badges"}),e.jsx("div",{className:"sr-only",children:"Actions"})]}),e.jsx($e,{listItems:a,sortItems:o})]}),e.jsx(Ge,{appendField:n,setValue:s})]})}const{useProjectDefinition:vi}=await f("@baseplate-dev/project-builder-lib/web"),{Button:Z,RecordView:bi,RecordViewActions:Ci,RecordViewItem:z,RecordViewItemList:wi,SectionListSection:Di,SectionListSectionContent:Ri,SectionListSectionDescription:Si,SectionListSectionHeader:$i,SectionListSectionTitle:Ni,useConfirmDialog:Fi}=await f("@baseplate-dev/ui-components");function Mi({control:d,setValue:t}){const{requestConfirm:s}=Fi(),{definitionContainer:l}=vi(),r=g(({model:i})=>i.relations??[]),n=g(({model:i})=>Object.fromEntries(i.fields.map(a=>[a.id,a.name])));function o(i){const a=r.find(m=>m.id===i);s({title:"Delete Relation",content:`Are you sure you want to delete the relation "${a?.name??"<invalid>"}"?`,onConfirm:()=>{t("model.relations",r.filter(m=>m.id!==i))}})}return e.jsxs(Di,{children:[e.jsxs($i,{children:[e.jsx(Ni,{children:"Relations"}),e.jsx(Si,{children:"Define relations to enforce uniqueness on one or more fields."})]}),e.jsxs(Ri,{className:"space-y-4",children:[r.map(i=>e.jsxs(bi,{children:[e.jsxs(wi,{children:[e.jsx(z,{title:"Name",children:i.name}),e.jsx(z,{title:"Local Field",children:i.references.map(a=>n[a.localRef]).join(", ")}),e.jsx(z,{title:"Foreign Model",children:l.nameFromId(i.modelRef)}),e.jsx(z,{title:"On Delete",children:i.onDelete})]}),e.jsxs(Ci,{children:[e.jsx(V,{relationId:i.id,control:d,asChild:!0,children:e.jsx(Z,{variant:"ghost",size:"icon",title:"Edit",children:e.jsx(ve,{})})}),e.jsx(Z,{variant:"ghostDestructive",size:"icon",title:"Delete",onClick:()=>{o(i.id)},children:e.jsx(be,{})})]})]},i.id)),e.jsx(V,{control:d,asChild:!0,children:e.jsxs(Z,{variant:"secondary",size:"sm",children:[e.jsx(Ce,{}),"Add Relation"]})})]})]})}const{Button:ee,RecordView:Ii,RecordViewActions:Li,RecordViewItem:Ti,RecordViewItemList:Ei,SectionListSection:Oi,SectionListSectionContent:Ui,SectionListSectionDescription:qi,SectionListSectionHeader:Pi,SectionListSectionTitle:Ai,useConfirmDialog:Bi}=await f("@baseplate-dev/ui-components");function Ki({control:d,setValue:t}){const{requestConfirm:s}=Bi(),l=g(({model:o})=>o.uniqueConstraints??[]),r=g(({model:o})=>Object.fromEntries(o.fields.map(i=>[i.id,i.name])));function n(o){s({title:"Delete Unique Constraint",content:"Are you sure you want to delete this unique constraint?",onConfirm:()=>{t("model.uniqueConstraints",l.filter(i=>i.id!==o))}})}return e.jsxs(Oi,{children:[e.jsxs(Pi,{children:[e.jsx(Ai,{children:"Unique Constraints"}),e.jsx(qi,{children:"Define unique constraints to enforce uniqueness on one or more fields."})]}),e.jsxs(Ui,{className:"space-y-4",children:[l.map(o=>e.jsxs(Ii,{children:[e.jsx(Ei,{children:e.jsx(Ti,{title:"Fields",children:o.fields.map(i=>r[i.fieldRef]??"<invalid>").join(", ")})}),e.jsxs(Li,{children:[e.jsx(k,{constraintId:o.id,control:d,asChild:!0,children:e.jsx(ee,{variant:"ghost",size:"icon",title:"Edit",children:e.jsx(ve,{})})}),e.jsx(ee,{variant:"ghostDestructive",size:"icon",title:"Delete",onClick:()=>{n(o.id)},children:e.jsx(be,{})})]})]},o.id)),e.jsx(k,{control:d,asChild:!0,children:e.jsxs(ee,{variant:"secondary",size:"sm",children:[e.jsx(Ce,{}),"Add Unique Constraint"]})})]})]})}const{modelEntityType:zi,modelLocalRelationEntityType:Vi,modelScalarFieldEntityType:ki}=await f("@baseplate-dev/project-builder-lib"),{useBlockUnsavedChangesNavigate:Hi}=await f("@baseplate-dev/project-builder-lib/web"),{FormActionBar:_i,SectionList:Wi}=await f("@baseplate-dev/ui-components");se(zi,"/data/models/edit/{key}");se(ki,"/data/models/edit/{parentKey}");se(Vi,"/data/models/edit/{parentKey}");const it=function(){const{key:t}=Ne.useParams(),{form:s,onSubmit:l,originalModel:r}=Le({omit:["name","featureRef"],modelKey:t}),{control:n,watch:o,getValues:i,setValue:a,reset:m}=s;return Hi({control:n,reset:m,onSubmit:l}),e.jsx(Fe,{children:e.jsx(Ie,{originalModel:r,getValues:i,watch:o,children:e.jsxs("form",{onSubmit:l,className:"max-w-7xl min-w-[700px] flex-1 space-y-4 px-4 pb-4",children:[e.jsx(yi,{control:n,setValue:a}),e.jsxs(Wi,{children:[e.jsx(Mi,{control:n,setValue:a}),e.jsx(Ki,{control:n,setValue:a})]}),e.jsx(_i,{form:s})]})})})};export{it as component};
|
|
2
|
-
//# sourceMappingURL=index-
|
|
1
|
+
import{i as f}from"./_virtual___federation_fn_import-BLYgPlMt.js";import{j as e,u as I,b as ie,e as le,f as Se}from"./index.esm-DcyGeCKA.js";import{s as te,k as U,e as ne,S as $e,m as Ne,a as Fe,r as se}from"./index-C_wN4CIq.js";import{u as g,S as Me,E as Ie}from"./-constants-CqYT9Sad.js";import{u as Le}from"./use-model-form-BQa-PiE_.js";import{q as Te,c as w,L as Ee,N as Oe,O as Ue,P as qe,I as ve,K as be,B as Ce}from"./index-C15I7WFi.js";import{i as Pe}from"./inflection-C1nKqrJS.js";import{c as Ae}from"./capitalize-gOJXDbsR.js";const Be=/\p{Lu}?\p{Ll}+|[0-9]+|\p{Lu}+(?!\p{Ll})|\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{L}+/gu;function Ke(d){return Array.from(d.match(Be)??[])}function M(d){const t=Ke(d);if(t.length===0)return"";const[s,...l]=t;return`${s.toLowerCase()}${l.map(r=>Ae(r)).join("")}`}const{modelScalarFieldEntityType:ae}=await f("@baseplate-dev/project-builder-lib"),{Button:re,ButtonGroup:ze,DropdownMenu:ke,DropdownMenuContent:Ve,DropdownMenuItem:He,DropdownMenuTrigger:_e}=await f("@baseplate-dev/ui-components"),{useMemo:We}=await f("react");function Ge({className:d,appendField:t,setValue:s}){const l=g(i=>i.model.fields.map(a=>a.name)),r=g(i=>i.model.primaryKeyFieldRefs.length),n=We(()=>{const i=[];r||i.push({name:"ID (uuid)",fields:[{name:"id",type:"uuid",options:{genUuid:!0},isPrimaryKey:!0}]});const a=l.includes("createdAt"),m=l.includes("updatedAt");return(!a||!m)&&i.push({name:"Timestamps",fields:[{name:"createdAt",type:"dateTime",options:{defaultToNow:!0}},{name:"updatedAt",type:"dateTime",options:{updatedAt:!0,defaultToNow:!0}}]}),i},[l,r]),o=i=>{for(const{isPrimaryKey:a,...m}of i.fields){const c=ae.generateNewId();l.includes(m.name)||t({id:c,...m}),a&&s("model.primaryKeyFieldRefs",[c],{shouldDirty:!0})}};return e.jsxs(ze,{className:d,children:[e.jsx(re,{variant:"secondary",onClick:()=>{t({id:ae.generateNewId(),name:"",type:"string",isOptional:!0,options:{default:""}})},size:"sm",children:"Add Field"}),e.jsxs(ke,{children:[e.jsx(_e,{disabled:n.length===0,asChild:!0,children:e.jsx(re,{variant:"secondary",size:"sm",children:e.jsx(Te,{})})}),e.jsx(Ve,{children:n.map(i=>e.jsx(He,{onClick:()=>{o(i)},children:i.name},i.name))})]})]})}const{Button:de,DialogClose:Ye,DialogFooter:Xe,MultiComboboxFieldController:Je}=await f("@baseplate-dev/ui-components"),{useId:Qe}=await f("react"),{z:W}=await f("zod"),Ze=W.object({fields:W.array(W.string()).min(1,"At least one primary key is required")});function en({className:d,control:t,onSubmitSuccess:s}){const l=g(c=>c.model.fields),{field:{value:r=[],onChange:n}}=I({name:"model.primaryKeyFieldRefs",control:t}),{control:o,handleSubmit:i}=ie({resolver:te(Ze),values:{fields:r}}),a=i(c=>{n(c.fields),s?.()}),m=Qe();return e.jsxs("form",{className:w("space-y-4",d),onSubmit:c=>(c.stopPropagation(),a(c)),id:m,children:[e.jsx(Je,{control:o,name:"fields",options:l.map(c=>({value:c.id,label:c.name})),placeholder:"Select fields to use as primary keys"}),e.jsxs(Xe,{children:[e.jsx(Ye,{asChild:!0,children:e.jsx(de,{variant:"secondary",children:"Cancel"})}),e.jsx(de,{type:"submit",form:m,children:"Save"})]})]})}const{Dialog:nn,DialogContent:tn,DialogDescription:sn,DialogHeader:on,DialogTitle:ln,DialogTrigger:an,useControlledState:rn}=await f("@baseplate-dev/ui-components");function we({control:d,children:t,asChild:s,open:l,onOpenChange:r}){const[n,o]=rn(l,r,!1);return e.jsxs(nn,{open:n,onOpenChange:o,children:[t&&e.jsx(an,{asChild:s,children:t}),e.jsxs(tn,{children:[e.jsxs(on,{children:[e.jsx(ln,{children:"Primary Keys"}),e.jsx(sn,{children:"Select the fields that will be used as the primary key for this model"})]}),e.jsx(en,{control:d,onSubmitSuccess:()=>{o(!1)}})]})]})}const{BadgeWithIcon:dn}=await f("@baseplate-dev/ui-components"),{useState:cn}=await f("react");function mn({className:d,control:t,autoCollapse:s}){const[l,r]=cn(!1),n=!s||l;return e.jsx(we,{control:t,children:e.jsx(dn,{icon:Ee,variant:"secondary",className:d,onMouseEnter:()=>{r(!0)},onMouseLeave:()=>{r(!1)},"aria-label":"Primary Key",title:"Primary Key",children:n&&"Primary"})})}const{createModelRelationFieldSchema:un,ModelFieldUtils:fn,modelForeignRelationEntityType:pn,modelLocalRelationEntityType:hn,ModelUtils:ce}=await f("@baseplate-dev/project-builder-lib"),{useDefinitionSchema:xn,useProjectDefinition:jn}=await f("@baseplate-dev/project-builder-lib/web"),{Button:G,ComboboxField:gn,ComboboxFieldController:Y,DialogClose:yn,DialogFooter:vn,InputFieldController:me,SelectFieldController:bn,toast:ue}=await f("@baseplate-dev/ui-components"),De=await f("react"),{useId:Cn,useMemo:wn}=De;function Dn(d,t,s){if(!s)return;const l=s.replace(/Id$/,""),r=a=>d.models.find(m=>m.id!==t.id&&a(m))?.id,n=r(a=>a.name.toLowerCase()===l.toLowerCase());if(n)return n;const o=r(a=>a.featureRef===a.featureRef&&a.name.toLowerCase().includes(l.toLowerCase()));return o||r(a=>a.name.toLowerCase().includes(l.toLowerCase()))}function fe(d,t,s,l){const r=(()=>{if(s.name)return s.name;if(s.modelRef){const i=ce.byIdOrThrow(d,s.modelRef);return M(i.name)}})(),n=(()=>{if(!s.modelRef)return;const{model:{fields:i,primaryKeyFieldRefs:a},name:m}=ce.byIdOrThrow(d,s.modelRef),c=i.filter(x=>a.includes(x.id)),p=s.references??[];return c.map((x,h)=>{const D=h===0&&l?l:c.length===1?`${M(m)}Id`:x.name;return{localRef:p[h]?.localRef??t.model.fields.find(y=>y.name===D)?.id,foreignRef:x.id}})})(),o=(()=>{if(!n)return;if(s.foreignRelationName)return s.foreignRelationName;const i=n.every(a=>a.localRef)&&fn.areScalarsUnique(t,n.map(a=>a.localRef));return M(i?t.name:Pe.pluralize(t.name))})();return{name:r??"",foreignRelationName:o??"",references:n??[]}}function Rn({className:d,control:t,onSubmitSuccess:s,relationId:l,defaultFieldName:r}){const{definition:n}=jn(),o=g(u=>u),i=o.name,{fields:a}=o.model,{field:{value:m=[],onChange:c}}=I({name:"model.relations",control:t}),p=n.models.map(u=>({label:u.name,value:u.id})),x=l===void 0?void 0:m.find(u=>u.id===l),h=wn(()=>{if(x)return x;const u=Dn(n,o,r);return{id:hn.generateNewId(),foreignId:pn.generateNewId(),modelRef:u??"",onDelete:"Restrict",onUpdate:"Restrict",...fe(n,o,{modelRef:u},r)}},[x,r,n,o]),D=xn(un),{control:b,handleSubmit:y,setError:H,watch:P,setValue:L}=ie({resolver:te(D),defaultValues:h}),S=P(),$=S.modelRef?n.models.find(u=>u.id===S.modelRef):void 0,T=$?.model.fields,_=a.map(u=>({label:u.name,value:u.id})),A=T?.map(u=>({label:u.name,value:u.id}))??[],j=S.references.some(u=>a.find(C=>C.id===u.localRef)?.isOptional),R=()=>{c(m.filter(u=>u.id!==l)),s?.()},Re=y(u=>{const{id:C}=u;if(a.some(v=>v.name===u.name)||m.some(v=>v.name===u.name&&v.id!==u.id)){H("name",{message:"The relation name cannot be the same as a field/relation name"});return}const O=u.references.map(v=>v.localRef);if(new Set(O).size!==O.length){ue.error("Local fields must be unique");return}const B=u.references.map(v=>v.foreignRef);if(new Set(B).size!==B.length){ue.error("Foreign fields must be unique");return}m.some(v=>v.id===C)?c(m.map(v=>v.id===C?u:v)):c([...m,u]),s?.()}),oe=Cn(),E=!!$;return e.jsxs("form",{className:w("space-y-4",d),onSubmit:u=>(u.stopPropagation(),Re(u)),id:oe,children:[e.jsxs("div",{className:"grid grid-cols-2 gap-x-8 gap-y-2",children:[e.jsx(gn,{options:[{label:i,value:i}],value:i,disabled:!0,label:"Local Model"}),e.jsx(Y,{control:b,name:"modelRef",options:p,label:"Foreign Model",onChange:u=>{if(!u)return;const{foreignRelationName:C,name:O,references:B}=fe(n,o,{...S,modelRef:u},r);C&&L("foreignRelationName",C),O&&L("name",O),L("references",B)}})]}),e.jsxs("div",{className:w("grid grid-cols-2 gap-x-8 gap-y-2",!E&&"pointer-events-none opacity-50"),children:[e.jsx(me,{control:b,disabled:!E,name:"name",label:"Local Relation Name",description:e.jsxs("span",{children:["Name of the relation, e.g. ",M(i),".",e.jsx("strong",{children:$?.name?M($.name):"user"})]})}),e.jsx(me,{control:b,disabled:!E,name:"foreignRelationName",label:"Foreign Relation Name",description:e.jsxs("span",{children:["Name of the relation on the foreign model, e.g."," ",M($?.name??"post"),".",e.jsx("strong",{children:h.foreignRelationName||"user"})]})}),e.jsx("div",{className:"text-sm font-medium",children:"Local Field"}),e.jsx("div",{className:"text-sm font-medium",children:"Foreign Field"}),S.references.map((u,C)=>e.jsxs(De.Fragment,{children:[e.jsx(Y,{disabled:!E,control:b,name:`references.${C}.localRef`,options:_}),e.jsx(Y,{control:b,name:`references.${C}.foreignRef`,options:A,disabled:!0})]},C))]}),e.jsx("div",{className:"grid grid-cols-2 gap-x-8 gap-y-2 border-t pt-4",children:e.jsx(bn,{label:"On Delete",control:b,options:[{label:"Cascade (delete entire local row)",value:"Cascade"},{label:"Restrict (throw error)",value:"Restrict"},...j?[{label:"Set Null (set local field to null)",value:"SetNull"}]:[]],name:"onDelete",description:"What to do when the foreign row is deleted"})}),e.jsx(vn,{children:e.jsxs("div",{className:"flex w-full justify-between",children:[l&&e.jsx(G,{variant:"secondary",onClick:u=>{u.preventDefault(),R()},children:"Delete"}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(yn,{asChild:!0,children:e.jsx(G,{variant:"secondary",children:"Cancel"})}),e.jsx(G,{type:"submit",form:oe,disabled:!E,children:"Save"})]})]})})]})}const{Dialog:Sn,DialogContent:$n,DialogDescription:Nn,DialogHeader:Fn,DialogTitle:Mn,DialogTrigger:In,useControlledState:Ln}=await f("@baseplate-dev/ui-components");function k({control:d,children:t,asChild:s,open:l,onOpenChange:r,relationId:n,defaultFieldName:o}){const[i,a]=Ln(l,r,!1);return e.jsxs(Sn,{open:i,onOpenChange:a,children:[t&&e.jsx(In,{asChild:s,children:t}),e.jsxs($n,{width:"lg",children:[e.jsxs(Fn,{children:[e.jsx(Mn,{children:n?"Edit Relation":"Create Relation"}),e.jsx(Nn,{children:"Set up the relation between this model and another model"})]}),e.jsx(Rn,{control:d,onSubmitSuccess:()=>{a(!1)},relationId:n,defaultFieldName:o})]})]})}const{useProjectDefinition:Tn}=await f("@baseplate-dev/project-builder-lib/web"),{BadgeWithIcon:En}=await f("@baseplate-dev/ui-components"),{useState:On}=await f("react");function Un({className:d,control:t,relation:s,autoCollapse:l}){const{definitionContainer:r}=Tn(),[n,o]=On(!1),i=!l||n;return e.jsx(k,{control:t,relationId:s.id,children:e.jsx(En,{icon:Oe,variant:"secondary",className:w("max-w-[100px]",d),onMouseEnter:()=>{o(!0)},onMouseLeave:()=>{o(!1)},"aria-label":"Relation",title:"Relation",children:i&&`${r.nameFromId(s.modelRef)} ${s.references.length>1?`(${s.references.length})`:""}`})})}const{modelUniqueConstraintEntityType:qn}=await f("@baseplate-dev/project-builder-lib"),{Button:X,DialogClose:Pn,DialogFooter:An,MultiComboboxFieldController:Bn}=await f("@baseplate-dev/ui-components"),{useId:Kn}=await f("react"),{z:K}=await f("zod"),zn=K.object({id:K.string().optional(),fields:K.array(K.string()).min(1,"At least one field is required")});function kn({className:d,control:t,onSubmitSuccess:s,constraintId:l}){const r=g(h=>h.model.fields),{field:{value:n=[],onChange:o}}=I({name:"model.uniqueConstraints",control:t}),i=l===void 0?void 0:n.find(h=>h.id===l),{control:a,handleSubmit:m}=ie({resolver:te(zn),values:i?{id:i.id,fields:i.fields.map(h=>h.fieldRef)}:{fields:[]}}),c=()=>{o(n.filter(h=>h.id!==l)),s?.()},p=m(h=>{const D={id:h.id??qn.generateNewId(),fields:h.fields.map(y=>({fieldRef:y}))},{id:b}=D;n.some(y=>y.id===b)?o(n.map(y=>y.id===b?D:y)):o([...n,D]),s?.()}),x=Kn();return e.jsxs("form",{className:w("space-y-4",d),onSubmit:h=>(h.stopPropagation(),p(h)),id:x,children:[e.jsx(Bn,{control:a,name:"fields",options:r.map(h=>({value:h.id,label:h.name})),placeholder:"Select fields to use as primary keys"}),e.jsx(An,{children:e.jsxs("div",{className:"flex w-full justify-between",children:[l&&e.jsx(X,{variant:"secondary",onClick:h=>{h.preventDefault(),c()},children:"Delete"}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(Pn,{asChild:!0,children:e.jsx(X,{variant:"secondary",children:"Cancel"})}),e.jsx(X,{type:"submit",form:x,children:"Save"})]})]})})]})}const{Dialog:Vn,DialogContent:Hn,DialogDescription:_n,DialogHeader:Wn,DialogTitle:Gn,DialogTrigger:Yn,useControlledState:Xn}=await f("@baseplate-dev/ui-components");function V({control:d,children:t,asChild:s,open:l,onOpenChange:r,constraintId:n}){const[o,i]=Xn(l,r,!1);return e.jsxs(Vn,{open:o,onOpenChange:i,children:[t&&e.jsx(Yn,{asChild:s,children:t}),e.jsxs(Hn,{children:[e.jsxs(Wn,{children:[e.jsx(Gn,{children:"Unique Constraint"}),e.jsx(_n,{children:"Select the fields that will be part of this unique constraint."})]}),e.jsx(kn,{control:d,onSubmitSuccess:()=>{i(!1)},constraintId:n})]})]})}const{BadgeWithIcon:Jn}=await f("@baseplate-dev/ui-components"),{useState:Qn}=await f("react");function Zn({className:d,control:t,constraintId:s,autoCollapse:l}){const[r,n]=Qn(!1),o=!l||r,i=g(a=>a.model.uniqueConstraints?.find(m=>m.id===s)?.fields.length??0);return e.jsx(V,{control:t,constraintId:s,children:e.jsx(Jn,{variant:"secondary",icon:Ue,className:w("",d),onMouseEnter:()=>{n(!0)},onMouseLeave:()=>{n(!1)},"aria-label":"Unique Constraint",title:"Unique Constraint",children:o&&`Unique ${i>1?`(${i})`:""}`})})}function ei({className:d,control:t,idx:s}){const l=g(c=>c.model.fields[s]),r=g(c=>c.model.primaryKeyFieldRefs.includes(l.id)),n=g(c=>c.model.uniqueConstraints?.filter(p=>p.fields.some(x=>x.fieldRef===l.id)).map(p=>p.id)??[]),o=g(({model:c})=>{const p=c.fields[s];return c.relations?.filter(x=>x.references.some(h=>h.localRef===p.id))??[]}),a=(r?1:0)+n.length+o.length>2,m=[r&&e.jsx(mn,{control:t,autoCollapse:a},"primary"),...n.map(c=>e.jsx(Zn,{control:t,constraintId:c,autoCollapse:a},c)),...o.map(c=>e.jsx(Un,{control:t,relation:c,autoCollapse:a},c.id))];return e.jsx("div",{className:w("flex gap-4",d),children:m})}const{EnumUtils:ni}=await f("@baseplate-dev/project-builder-lib"),{useProjectDefinition:ii}=await f("@baseplate-dev/project-builder-lib/web"),{Button:N,ComboboxField:ti,DropdownMenu:pe,DropdownMenuContent:he,DropdownMenuGroup:xe,DropdownMenuItem:J,DropdownMenuTrigger:je,InputField:ge,InputFieldController:Q,SelectFieldController:si}=await f("@baseplate-dev/ui-components");function oi({control:d,idx:t,setValue:s}){const{definition:l}=ii(),r=le({control:d,name:`model.fields.${t}.type`}),{field:{value:n,onChange:o}}=I({name:`model.fields.${t}.options`,control:d}),i=le({control:d,name:`model.fields.${t}.options.default`});if(r==="boolean")return e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(si,{control:d,className:"flex-1",name:`model.fields.${t}.options.default`,options:[{label:"True",value:"true"},{label:"False",value:"false"}],placeholder:"NULL"}),i&&e.jsx(N,{title:"Reset",onClick:()=>{s(`model.fields.${t}.options.default`,"",{shouldDirty:!0})},variant:"ghost",size:"icon",children:e.jsx(U,{})})]});if(["string","int","float"].includes(r))return e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Q,{control:d,placeholder:"NULL",name:`model.fields.${t}.options.default`,className:"flex-1"}),i&&e.jsx(N,{title:"Reset",onClick:()=>{s(`model.fields.${t}.options.default`,void 0,{shouldDirty:!0})},variant:"ghost",size:"icon",children:e.jsx(U,{})})]});if(r==="uuid")return n?.genUuid?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ge,{disabled:!0,value:"Random UUID v4",className:"flex-1"}),e.jsx(N,{title:"Reset",onClick:()=>{o({...n,genUuid:!1})},variant:"ghost",size:"icon",children:e.jsx(U,{})})]}):e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Q,{control:d,placeholder:"NULL",name:`model.fields.${t}.options.default`,className:"flex-1"}),e.jsxs(pe,{children:[e.jsx(je,{asChild:!0,children:e.jsx(N,{title:"Options",variant:"ghost",size:"icon",children:e.jsx(ne,{})})}),e.jsx(he,{children:e.jsx(xe,{children:e.jsx(J,{onSelect:()=>{o({...n,genUuid:!0})},children:"Random UUID v4"})})})]})]});if(r==="dateTime"||r==="date"){const{defaultToNow:a,updatedAt:m}=n??{};return a??m?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ge,{disabled:!0,value:m?"Last Updated":"Now",className:"flex-1"}),e.jsx(N,{title:"Reset",onClick:()=>{o({...n,defaultToNow:!1,updatedAt:!1})},variant:"ghost",size:"icon",children:e.jsx(U,{})})]}):e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(Q,{placeholder:"NULL",control:d,name:`model.fields.${t}.options.default`,className:"flex-1"}),e.jsxs(pe,{children:[e.jsx(je,{asChild:!0,children:e.jsx(N,{title:"Options",variant:"ghost",size:"icon",children:e.jsx(ne,{})})}),e.jsx(he,{children:e.jsxs(xe,{children:[e.jsx(J,{onSelect:()=>{o({...n,defaultToNow:!0,updatedAt:!1})},children:"Now"}),e.jsx(J,{onSelect:()=>{o({...n,defaultToNow:!0,updatedAt:!0})},children:"Last Updated At"})]})})]})]})}if(r==="enum"&&n?.enumRef){const m=ni.byIdOrThrow(l,n.enumRef).values.map(c=>({label:c.friendlyName,value:c.id}));return e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(ti,{placeholder:"NULL",value:n.defaultEnumValueRef??null,onChange:c=>{o({...n,defaultEnumValueRef:c||void 0})},options:m,className:"flex-1"}),n.defaultEnumValueRef&&e.jsx(N,{title:"Reset",onClick:()=>{o({...n,defaultEnumValueRef:""})},variant:"ghost",size:"icon",children:e.jsx(U,{})})]})}return e.jsx("div",{})}const{SCALAR_FIELD_TYPES:li}=await f("@baseplate-dev/project-builder-lib"),{useProjectDefinition:ai}=await f("@baseplate-dev/project-builder-lib/web"),{ComboboxField:ri}=await f("@baseplate-dev/ui-components");function di({control:d,idx:t}){const{definition:s}=ai(),l=(s.enums??[]).map(p=>({label:p.name,value:`enum-${p.id}`,description:"Enum type"})),r=[...li.filter(p=>p!=="enum").map(p=>Me[p]),...l],{field:{value:n,onChange:o}}=I({name:`model.fields.${t}.type`,control:d}),{field:{value:i,onChange:a}}=I({name:`model.fields.${t}.options`,control:d}),m=p=>{if(p?.startsWith("enum-")){const x=p.replace("enum-","");a({enumRef:x}),o("enum")}else o(p)},c=i?.enumRef;return e.jsx("div",{className:"space-y-2",children:e.jsx(ri,{value:n==="enum"&&c?`enum-${c}`:n,onChange:m,options:r,renderItemLabel:p=>e.jsxs("div",{className:"flex flex-col",children:[e.jsx("div",{children:p.label}),e.jsx("div",{className:"text-xs text-muted-foreground",children:p.description})]})})})}const{modelUniqueConstraintEntityType:ci}=await f("@baseplate-dev/project-builder-lib"),{Button:ye,DropdownMenu:mi,DropdownMenuContent:ui,DropdownMenuGroup:fi,DropdownMenuItem:F,DropdownMenuTrigger:pi,InputFieldController:hi,SwitchFieldController:xi,toast:ji}=await f("@baseplate-dev/ui-components"),{useState:q}=await f("react");function gi({className:d,control:t,idx:s,setValue:l,onRemove:r}){const n=g(j=>j.model.fields[s]),o=g(j=>j.model.relations),i=g(j=>j.model.primaryKeyFieldRefs),a=g(j=>j.model.uniqueConstraints)??[],m=i.includes(n.id),c=i.length>1,p=a.filter(j=>j.fields.some(R=>R.fieldRef===n.id)),x=o?.filter(j=>j.references.some(R=>R.localRef===n.id))??[],h=(()=>{if(x.length>0)return`Unable to remove field as it is being used in relations ${x.map(j=>j.name).join(", ")}`;if(m&&c)return"Unable to remove field as it is being used in in the primary key";if(a.some(j=>j.fields.some(R=>R.fieldRef===n.id)))return"Unable to remove field as it is being used in in a unique constraint"})();function D(){if(h){ji.error(h);return}r(s),m&&!c&&l("model.primaryKeyFieldRefs",[],{shouldDirty:!0})}const[b,y]=q(!1),[H,P]=q(!1),[L,S]=q(),[$,T]=q(!1),[_,A]=q();return e.jsxs("div",{className:w("items-center",d),children:[e.jsx("div",{children:e.jsx(hi,{control:t,name:`model.fields.${s}.name`})}),e.jsx("div",{children:e.jsx(di,{control:t,idx:s})}),e.jsx("div",{children:e.jsx(xi,{control:t,name:`model.fields.${s}.isOptional`})}),e.jsx("div",{className:"mr-4",children:e.jsx(oi,{control:t,idx:s,setValue:l})}),e.jsx("div",{children:e.jsx(ei,{control:t,idx:s})}),e.jsx("div",{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(mi,{children:[e.jsx(pi,{asChild:!0,children:e.jsx(ye,{variant:"ghost",size:"icon",children:e.jsx(ne,{})})}),e.jsx(ui,{children:e.jsxs(fi,{children:[x.length===0&&e.jsx(F,{onSelect:()=>{T(!0),A(void 0)},children:"Add Relation"}),x.length>0&&x.map(j=>e.jsxs(F,{onSelect:()=>{T(!0),A(j.id)},children:["Edit Relation ",x.length>1&&j.name]},j.id)),!c&&!m&&e.jsx(F,{onSelect:()=>{l("model.primaryKeyFieldRefs",[n.id],{shouldDirty:!0})},children:"Set as Primary Key"}),m&&e.jsx(F,{onSelect:()=>{y(!0)},children:"Edit Primary Key"}),p.length===0&&(c||!m)&&e.jsx(F,{onSelect:()=>{l("model.uniqueConstraints",[...a,{id:ci.generateNewId(),fields:[{fieldRef:n.id}]}],{shouldDirty:!0})},children:"Make Unique"}),p.length>0&&p.map((j,R)=>e.jsxs(F,{onSelect:()=>{S(j.id),P(!0)},children:["Edit Unique Constraint"," ",p.length>1&&R+1]},j.id))]})})]}),e.jsx(we,{control:t,open:b,onOpenChange:y}),e.jsx(V,{control:t,open:H,onOpenChange:P,constraintId:L}),e.jsx(k,{control:t,open:$,onOpenChange:T,relationId:_,defaultFieldName:n.name}),e.jsx(ye,{variant:"ghost",onClick:()=>{D()},size:"icon",children:e.jsx(qe,{})})]})})]})}function yi({className:d,control:t,setValue:s}){const{fields:l,remove:r,append:n,move:o}=Se({control:t,name:"model.fields"}),i="grid grid-cols-[repeat(2,minmax(130px,1fr))_60px_minmax(130px,1fr)_minmax(100px,1fr)_80px] gap-3",a=l.map((m,c)=>({id:m.id,element:e.jsx(gi,{className:i,control:t,setValue:s,idx:c,onRemove:r},m.id)}));return e.jsxs("div",{className:w("space-y-4",d),children:[l.length===0?e.jsx("p",{className:"pt-4 text-style-muted",children:"Add some fields to get started"}):e.jsxs("div",{className:"flex w-full flex-col gap-2 bg-white",children:[e.jsxs("div",{className:w(i,"sticky -top-0 z-10 bg-white py-2 text-sm font-semibold","pl-12"),children:[e.jsx("div",{children:"Name"}),e.jsx("div",{children:"Type"}),e.jsx("div",{children:"Optional"}),e.jsx("div",{children:"Default Value"}),e.jsx("div",{className:"sr-only",children:"Badges"}),e.jsx("div",{className:"sr-only",children:"Actions"})]}),e.jsx($e,{listItems:a,sortItems:o})]}),e.jsx(Ge,{appendField:n,setValue:s})]})}const{useProjectDefinition:vi}=await f("@baseplate-dev/project-builder-lib/web"),{Button:Z,RecordView:bi,RecordViewActions:Ci,RecordViewItem:z,RecordViewItemList:wi,SectionListSection:Di,SectionListSectionContent:Ri,SectionListSectionDescription:Si,SectionListSectionHeader:$i,SectionListSectionTitle:Ni,useConfirmDialog:Fi}=await f("@baseplate-dev/ui-components");function Mi({control:d,setValue:t}){const{requestConfirm:s}=Fi(),{definitionContainer:l}=vi(),r=g(({model:i})=>i.relations??[]),n=g(({model:i})=>Object.fromEntries(i.fields.map(a=>[a.id,a.name])));function o(i){const a=r.find(m=>m.id===i);s({title:"Delete Relation",content:`Are you sure you want to delete the relation "${a?.name??"<invalid>"}"?`,onConfirm:()=>{t("model.relations",r.filter(m=>m.id!==i))}})}return e.jsxs(Di,{children:[e.jsxs($i,{children:[e.jsx(Ni,{children:"Relations"}),e.jsx(Si,{children:"Define relations to enforce uniqueness on one or more fields."})]}),e.jsxs(Ri,{className:"space-y-4",children:[r.map(i=>e.jsxs(bi,{children:[e.jsxs(wi,{children:[e.jsx(z,{title:"Name",children:i.name}),e.jsx(z,{title:"Local Field",children:i.references.map(a=>n[a.localRef]).join(", ")}),e.jsx(z,{title:"Foreign Model",children:l.nameFromId(i.modelRef)}),e.jsx(z,{title:"On Delete",children:i.onDelete})]}),e.jsxs(Ci,{children:[e.jsx(k,{relationId:i.id,control:d,asChild:!0,children:e.jsx(Z,{variant:"ghost",size:"icon",title:"Edit",children:e.jsx(ve,{})})}),e.jsx(Z,{variant:"ghostDestructive",size:"icon",title:"Delete",onClick:()=>{o(i.id)},children:e.jsx(be,{})})]})]},i.id)),e.jsx(k,{control:d,asChild:!0,children:e.jsxs(Z,{variant:"secondary",size:"sm",children:[e.jsx(Ce,{}),"Add Relation"]})})]})]})}const{Button:ee,RecordView:Ii,RecordViewActions:Li,RecordViewItem:Ti,RecordViewItemList:Ei,SectionListSection:Oi,SectionListSectionContent:Ui,SectionListSectionDescription:qi,SectionListSectionHeader:Pi,SectionListSectionTitle:Ai,useConfirmDialog:Bi}=await f("@baseplate-dev/ui-components");function Ki({control:d,setValue:t}){const{requestConfirm:s}=Bi(),l=g(({model:o})=>o.uniqueConstraints??[]),r=g(({model:o})=>Object.fromEntries(o.fields.map(i=>[i.id,i.name])));function n(o){s({title:"Delete Unique Constraint",content:"Are you sure you want to delete this unique constraint?",onConfirm:()=>{t("model.uniqueConstraints",l.filter(i=>i.id!==o))}})}return e.jsxs(Oi,{children:[e.jsxs(Pi,{children:[e.jsx(Ai,{children:"Unique Constraints"}),e.jsx(qi,{children:"Define unique constraints to enforce uniqueness on one or more fields."})]}),e.jsxs(Ui,{className:"space-y-4",children:[l.map(o=>e.jsxs(Ii,{children:[e.jsx(Ei,{children:e.jsx(Ti,{title:"Fields",children:o.fields.map(i=>r[i.fieldRef]??"<invalid>").join(", ")})}),e.jsxs(Li,{children:[e.jsx(V,{constraintId:o.id,control:d,asChild:!0,children:e.jsx(ee,{variant:"ghost",size:"icon",title:"Edit",children:e.jsx(ve,{})})}),e.jsx(ee,{variant:"ghostDestructive",size:"icon",title:"Delete",onClick:()=>{n(o.id)},children:e.jsx(be,{})})]})]},o.id)),e.jsx(V,{control:d,asChild:!0,children:e.jsxs(ee,{variant:"secondary",size:"sm",children:[e.jsx(Ce,{}),"Add Unique Constraint"]})})]})]})}const{modelEntityType:zi,modelLocalRelationEntityType:ki,modelScalarFieldEntityType:Vi}=await f("@baseplate-dev/project-builder-lib"),{useBlockUnsavedChangesNavigate:Hi}=await f("@baseplate-dev/project-builder-lib/web"),{FormActionBar:_i,SectionList:Wi}=await f("@baseplate-dev/ui-components");se(zi,"/data/models/edit/{key}");se(Vi,"/data/models/edit/{parentKey}");se(ki,"/data/models/edit/{parentKey}");const it=function(){const{key:t}=Ne.useParams(),{form:s,onSubmit:l,originalModel:r}=Le({omit:["name","featureRef"],modelKey:t}),{control:n,watch:o,getValues:i,setValue:a,reset:m}=s;return Hi({control:n,reset:m,onSubmit:l}),e.jsx(Fe,{children:e.jsx(Ie,{originalModel:r,getValues:i,watch:o,children:e.jsxs("form",{onSubmit:l,className:"max-w-7xl min-w-[700px] flex-1 space-y-4 px-4 pb-4",children:[e.jsx(yi,{control:n,setValue:a}),e.jsxs(Wi,{children:[e.jsx(Mi,{control:n,setValue:a}),e.jsx(Ki,{control:n,setValue:a})]}),e.jsx(_i,{form:s})]})})})};export{it as component};
|
|
2
|
+
//# sourceMappingURL=index-BLuLGksP.js.map
|