@baseplate-dev/project-builder-web 0.2.5 → 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-CyTNHADu.js → -constants-CqYT9Sad.js} +2 -2
- package/dist/assets/{-constants-CyTNHADu.js.map → -constants-CqYT9Sad.js.map} +1 -1
- package/dist/assets/__federation_shared_@baseplate-dev/project-builder-lib/{web-dPVRSC8L.js → web-CEscUEnR.js} +2 -2
- package/dist/assets/__federation_shared_@baseplate-dev/project-builder-lib/{web-dPVRSC8L.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-z-HwX7Wv.js → ui-components-Bpztr-cx.js} +4 -4
- package/dist/assets/__federation_shared_@baseplate-dev/{ui-components-z-HwX7Wv.js.map → ui-components-Bpztr-cx.js.map} +1 -1
- package/dist/assets/{_virtual___federation_fn_import-DK_YYIlv.js → _virtual___federation_fn_import-BLYgPlMt.js} +2 -2
- package/dist/assets/{_virtual___federation_fn_import-DK_YYIlv.js.map → _virtual___federation_fn_import-BLYgPlMt.js.map} +1 -1
- package/dist/assets/{backend-B_UhUC1z.js → backend-hJNcdERv.js} +2 -2
- package/dist/assets/{backend-B_UhUC1z.js.map → backend-hJNcdERv.js.map} +1 -1
- package/dist/assets/{badge-with-type-label-Cvf-Kq7s.js → badge-with-type-label-CezAtjFy.js} +2 -2
- package/dist/assets/{badge-with-type-label-Cvf-Kq7s.js.map → badge-with-type-label-CezAtjFy.js.map} +1 -1
- package/dist/assets/{edit._id-TYAWf8Zb.js → edit._id-bMpe6S3O.js} +2 -2
- package/dist/assets/{edit._id-TYAWf8Zb.js.map → edit._id-bMpe6S3O.js.map} +1 -1
- package/dist/assets/{enum-info-form-CfQbLUQ3.js → enum-info-form-xlZ2HO8I.js} +2 -2
- package/dist/assets/{enum-info-form-CfQbLUQ3.js.map → enum-info-form-xlZ2HO8I.js.map} +1 -1
- package/dist/assets/{graphql-DTRjqtIq.js → graphql-D3J4ZWXL.js} +2 -2
- package/dist/assets/{graphql-DTRjqtIq.js.map → graphql-D3J4ZWXL.js.map} +1 -1
- package/dist/assets/{hierarchy-BDu76BxG.js → hierarchy-DF9lzUjz.js} +2 -2
- package/dist/assets/{hierarchy-BDu76BxG.js.map → hierarchy-DF9lzUjz.js.map} +1 -1
- package/dist/assets/{index-DITwAD5X.js → index-1ErFJbDw.js} +2 -2
- package/dist/assets/{index-DITwAD5X.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-DhWOhNFS.js → index-B5-Qczd9.js} +2 -2
- package/dist/assets/{index-DhWOhNFS.js.map → index-B5-Qczd9.js.map} +1 -1
- package/dist/assets/{index-PWrncK3R.js → index-BLuLGksP.js} +2 -2
- package/dist/assets/{index-PWrncK3R.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-01LAxHjt.js → index-BdmJimiZ.js} +2 -2
- package/dist/assets/{index-01LAxHjt.js.map → index-BdmJimiZ.js.map} +1 -1
- package/dist/assets/{index-D8LleqeK.js → index-Bv8hyN9u.js} +2 -2
- package/dist/assets/{index-D8LleqeK.js.map → index-Bv8hyN9u.js.map} +1 -1
- package/dist/assets/{index-BgFEd-vA.js → index-C15I7WFi.js} +2 -2
- package/dist/assets/{index-BgFEd-vA.js.map → index-C15I7WFi.js.map} +1 -1
- package/dist/assets/{index-B7G2CMwL.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-CKCJuR7p.js → index-DJsZccoO.js} +2 -2
- package/dist/assets/{index-CKCJuR7p.js.map → index-DJsZccoO.js.map} +1 -1
- package/dist/assets/{index-tLZ1b0Gc.js → index-DwyYddxl.js} +2 -2
- package/dist/assets/{index-tLZ1b0Gc.js.map → index-DwyYddxl.js.map} +1 -1
- package/dist/assets/{index-BkkIaDrq.js → index-P-wtG1LL.js} +2 -2
- package/dist/assets/{index-BkkIaDrq.js.map → index-P-wtG1LL.js.map} +1 -1
- package/dist/assets/{index.esm-Bvv3vNQh.js → index.esm-DcyGeCKA.js} +2 -2
- package/dist/assets/{index.esm-Bvv3vNQh.js.map → index.esm-DcyGeCKA.js.map} +1 -1
- package/dist/assets/{model-info-form-tJoD-VwE.js → model-info-form-VtbYsjrH.js} +2 -2
- package/dist/assets/{model-info-form-tJoD-VwE.js.map → model-info-form-VtbYsjrH.js.map} +1 -1
- package/dist/assets/model-merger-qJqD9I2_.js +2 -0
- package/dist/assets/{model-merger-DuBMgrZ3.js.map → model-merger-qJqD9I2_.js.map} +1 -1
- package/dist/assets/{new-app-dialog-CFhp6QLe.js → new-app-dialog-CTtQ52jO.js} +2 -2
- package/dist/assets/{new-app-dialog-CFhp6QLe.js.map → new-app-dialog-CTtQ52jO.js.map} +1 -1
- package/dist/assets/{new-enum-dialog-BxDxXwX_.js → new-enum-dialog-B0QcIWdY.js} +2 -2
- package/dist/assets/{new-enum-dialog-BxDxXwX_.js.map → new-enum-dialog-B0QcIWdY.js.map} +1 -1
- package/dist/assets/{new-model-dialog-D4pnLGR_.js → new-model-dialog-CM2dJ8Iv.js} +2 -2
- package/dist/assets/{new-model-dialog-D4pnLGR_.js.map → new-model-dialog-CM2dJ8Iv.js.map} +1 -1
- package/dist/assets/{route-rzAviP-P.js → route-B34jnFQF.js} +2 -2
- package/dist/assets/{route-rzAviP-P.js.map → route-B34jnFQF.js.map} +1 -1
- package/dist/assets/{route-BLMjDHl_.js → route-BRBmSLMi.js} +2 -2
- package/dist/assets/{route-BLMjDHl_.js.map → route-BRBmSLMi.js.map} +1 -1
- package/dist/assets/{route-CO2y2T3j.js → route-BsIUCKz1.js} +2 -2
- package/dist/assets/{route-CO2y2T3j.js.map → route-BsIUCKz1.js.map} +1 -1
- package/dist/assets/route-CAp89B2q.js +2 -0
- package/dist/assets/{route-DSICQIL3.js.map → route-CAp89B2q.js.map} +1 -1
- package/dist/assets/{route-BGYla1q4.js → route-DcsVxxui.js} +2 -2
- package/dist/assets/{route-BGYla1q4.js.map → route-DcsVxxui.js.map} +1 -1
- package/dist/assets/{route-DYHQ0t6P.js → route-DmdFbZkw.js} +2 -2
- package/dist/assets/{route-DYHQ0t6P.js.map → route-DmdFbZkw.js.map} +1 -1
- package/dist/assets/{route-MA2rDgPd.js → route-Dpmx4lrA.js} +2 -2
- package/dist/assets/{route-MA2rDgPd.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-BILZA_nq.js → route-w8_2x1VY.js} +2 -2
- package/dist/assets/{route-BILZA_nq.js.map → route-w8_2x1VY.js.map} +1 -1
- package/dist/assets/{service-C0mRE7Wd.js → service-Bgm1ICPI.js} +2 -2
- package/dist/assets/{service-C0mRE7Wd.js.map → service-Bgm1ICPI.js.map} +1 -1
- package/dist/assets/{template-extractor-1dzSeRMo.js → template-extractor-DEU0CX0Y.js} +2 -2
- package/dist/assets/{template-extractor-1dzSeRMo.js.map → template-extractor-DEU0CX0Y.js.map} +1 -1
- package/dist/assets/{theme-builder-NSOA1xIw.js → theme-builder-La1nKR0K.js} +2 -2
- package/dist/assets/{theme-builder-NSOA1xIw.js.map → theme-builder-La1nKR0K.js.map} +1 -1
- package/dist/assets/{use-definition-schema-DOTr2MSB.js → use-definition-schema-CuFFJIzk.js} +2 -2
- package/dist/assets/{use-definition-schema-DOTr2MSB.js.map → use-definition-schema-CuFFJIzk.js.map} +1 -1
- package/dist/assets/{use-enum-form-Bon-b8Oc.js → use-enum-form-DKD2EDHZ.js} +2 -2
- package/dist/assets/{use-enum-form-Bon-b8Oc.js.map → use-enum-form-DKD2EDHZ.js.map} +1 -1
- package/dist/assets/{use-model-form-Bjm8n0m8.js → use-model-form-BQa-PiE_.js} +2 -2
- package/dist/assets/{use-model-form-Bjm8n0m8.js.map → use-model-form-BQa-PiE_.js.map} +1 -1
- package/dist/assets/{utils-BGrwv_U7.js → utils-BYjOwi1b.js} +2 -2
- package/dist/assets/{utils-BGrwv_U7.js.map → utils-BYjOwi1b.js.map} +1 -1
- package/dist/index.html +5 -5
- package/package.json +6 -6
- package/dist/assets/__federation_shared_@baseplate-dev/project-builder-lib-DnM8acZf.js +0 -5
- package/dist/assets/__federation_shared_@baseplate-dev/project-builder-lib-DnM8acZf.js.map +0 -1
- package/dist/assets/index-B7G2CMwL.js.map +0 -1
- package/dist/assets/index-B9Di1LKs.css +0 -1
- package/dist/assets/index-Cg4QKyV6.js +0 -2
- package/dist/assets/index-Cg4QKyV6.js.map +0 -1
- package/dist/assets/model-merger-DuBMgrZ3.js +0 -2
- package/dist/assets/route-DSICQIL3.js +0 -2
- package/dist/assets/route-DvbGaH6v.js +0 -2
- package/dist/assets/route-DvbGaH6v.js.map +0 -1
- package/dist/assets/sections-BSA71xrl.js +0 -2
- package/dist/assets/sections-BSA71xrl.js.map +0 -1
- package/dist/assets/sections._sectionKey-DSatzih8.js +0 -2
- package/dist/assets/sections._sectionKey-DSatzih8.js.map +0 -1
- package/dist/assets/web-B598C4Bq.js +0 -2
- package/dist/assets/web-B598C4Bq.js.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{i as c}from"./_virtual___federation_fn_import-
|
|
2
|
-
//# sourceMappingURL=index-
|
|
1
|
+
import{i as c}from"./_virtual___federation_fn_import-BLYgPlMt.js";import{j as e,f as S,e as j}from"./index.esm-DcyGeCKA.js";import{S as v,n as f,a as L}from"./index-C_wN4CIq.js";import{u as y}from"./use-enum-form-DKD2EDHZ.js";import{K as C,c as N}from"./index-C15I7WFi.js";const{SectionListSection:b,SectionListSectionContent:g,SectionListSectionHeader:w,SectionListSectionTitle:E,SwitchFieldController:V}=await c("@baseplate-dev/ui-components");function F({control:s}){return e.jsxs(b,{children:[e.jsx(w,{children:e.jsx(E,{children:"GraphQL"})}),e.jsx(g,{className:"space-y-4",children:e.jsx(V,{label:"Expose in GraphQL schema",control:s,name:"isExposed",description:"Whether to expose this enum in the GraphQL schema"})})]})}function A(s){return s.split("_").map(n=>n.charAt(0).toUpperCase()+n.slice(1).toLowerCase()).join(" ")}const{modelEnumValueEntityType:T}=await c("@baseplate-dev/project-builder-lib"),{Button:d,InputFieldController:u,Label:p,SectionListSection:$,SectionListSectionContent:I,SectionListSectionDescription:k,SectionListSectionHeader:B,SectionListSectionTitle:D}=await c("@baseplate-dev/ui-components");function G({control:s,setValue:l}){const{fields:t,remove:n,append:r,move:a}=S({control:s,name:"values"}),o=j({control:s,name:"values"}),m="grid grid-cols-[repeat(2,minmax(130px,1fr))_80px] gap-3",x=t.map((h,i)=>({id:h.id,element:e.jsxs("div",{className:m,children:[e.jsx(u,{control:s,name:`values.${i}.name`}),e.jsx(u,{control:s,name:`values.${i}.friendlyName`,onFocus:()=>{!o[i].friendlyName&&o[i].name&&l(`values.${i}.friendlyName`,A(o[i].name))}}),e.jsxs(d,{variant:"ghost",size:"icon",onClick:()=>{n(i)},children:[e.jsx(C,{}),e.jsx("div",{className:"sr-only",children:"Delete Enum"})]})]})}));return e.jsxs($,{children:[e.jsxs(B,{children:[e.jsx(D,{children:"Values"}),e.jsx(k,{children:"Configure the allowed values for this enum."})]}),e.jsxs(I,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:N(m,"pl-12"),children:[e.jsx(p,{children:"Value Name, e.g. ACTIVE"}),e.jsx(p,{children:"Value Friendly Name, e.g. Active"}),e.jsx("div",{})]}),t.length===0?e.jsx("p",{className:"pt-4 text-style-muted",children:"Add some values to get started"}):e.jsx(v,{listItems:x,sortItems:a})]}),e.jsx(d,{size:"sm",variant:"secondary",onClick:()=>{r({id:T.generateNewId(),name:"",friendlyName:""})},children:"Add Value"})]})]})}const{useBlockUnsavedChangesNavigate:Q}=await c("@baseplate-dev/project-builder-lib/web"),{FormActionBar:H,SectionList:R}=await c("@baseplate-dev/ui-components"),_=function(){const{key:l}=f.useParams(),{form:t,onSubmit:n,isSavingDefinition:r}=y({omit:["name","featureRef"],enumKey:l}),{control:a,setValue:o}=t;return Q({control:a,reset:t.reset,onSubmit:n}),e.jsx(L,{children:e.jsxs("form",{onSubmit:n,className:"mx-4 max-w-7xl min-w-[700px] flex-1 space-y-4 pb-4",children:[e.jsxs(R,{children:[e.jsx(F,{control:a}),e.jsx(G,{control:a,setValue:o})]}),e.jsx(H,{form:t,disabled:r})]})})};export{_ as component};
|
|
2
|
+
//# sourceMappingURL=index-1ErFJbDw.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-DITwAD5X.js","sources":["../../src/routes/data/enums/edit.$key/-components/enum-graph-ql-section.tsx","../../src/utils/casing.ts","../../src/routes/data/enums/edit.$key/-components/enum-values-section.tsx","../../src/routes/data/enums/edit.$key/index.tsx?tsr-split=component"],"sourcesContent":["import type { EnumConfig } from '@baseplate-dev/project-builder-lib';\nimport type React from 'react';\nimport type { Control } from 'react-hook-form';\n\nimport {\n SectionListSection,\n SectionListSectionContent,\n SectionListSectionHeader,\n SectionListSectionTitle,\n SwitchFieldController,\n} from '@baseplate-dev/ui-components';\n\nexport function EnumGraphQLSection({\n control,\n}: {\n control: Control<EnumConfig>;\n}): React.JSX.Element {\n return (\n <SectionListSection>\n <SectionListSectionHeader>\n <SectionListSectionTitle>GraphQL</SectionListSectionTitle>\n </SectionListSectionHeader>\n <SectionListSectionContent className=\"space-y-4\">\n <SwitchFieldController\n label=\"Expose in GraphQL schema\"\n control={control}\n name=\"isExposed\"\n description=\"Whether to expose this enum in the GraphQL schema\"\n />\n </SectionListSectionContent>\n </SectionListSection>\n );\n}\n","export function underscoreToTitleCase(str: string): string {\n // Split the string into an array of words\n const words = str.split('_');\n\n // Capitalize the first letter of each word and join them back together\n const titleCase = words\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())\n .join(' ');\n\n return titleCase;\n}\n","import type { EnumConfig } from '@baseplate-dev/project-builder-lib';\nimport type React from 'react';\nimport type { Control, UseFormSetValue } from 'react-hook-form';\n\nimport { modelEnumValueEntityType } from '@baseplate-dev/project-builder-lib';\nimport {\n Button,\n InputFieldController,\n Label,\n SectionListSection,\n SectionListSectionContent,\n SectionListSectionDescription,\n SectionListSectionHeader,\n SectionListSectionTitle,\n} from '@baseplate-dev/ui-components';\nimport clsx from 'clsx';\nimport { useFieldArray, useWatch } from 'react-hook-form';\nimport { MdDeleteOutline } from 'react-icons/md';\n\nimport { SortableList } from '#src/components/index.js';\nimport { underscoreToTitleCase } from '#src/utils/casing.js';\n\nexport function EnumValuesSection({\n control,\n setValue,\n}: {\n control: Control<EnumConfig>;\n setValue: UseFormSetValue<EnumConfig>;\n}): React.JSX.Element {\n const {\n fields: valueFields,\n remove: removeValue,\n append: appendValue,\n move: sortValues,\n } = useFieldArray({\n control,\n name: 'values',\n });\n\n const values = useWatch({ control, name: 'values' });\n\n const gridClassNames =\n 'grid grid-cols-[repeat(2,minmax(130px,1fr))_80px] gap-3';\n\n const valueListItems = valueFields.map((field, i) => ({\n id: field.id,\n element: (\n <div className={gridClassNames}>\n <InputFieldController control={control} name={`values.${i}.name`} />\n <InputFieldController\n control={control}\n name={`values.${i}.friendlyName`}\n onFocus={() => {\n if (!values[i].friendlyName && values[i].name) {\n setValue(\n `values.${i}.friendlyName`,\n underscoreToTitleCase(values[i].name),\n );\n }\n }}\n />\n <Button\n variant=\"ghost\"\n size=\"icon\"\n onClick={() => {\n removeValue(i);\n }}\n >\n <MdDeleteOutline />\n <div className=\"sr-only\">Delete Enum</div>\n </Button>\n </div>\n ),\n }));\n\n return (\n <SectionListSection>\n <SectionListSectionHeader>\n <SectionListSectionTitle>Values</SectionListSectionTitle>\n <SectionListSectionDescription>\n Configure the allowed values for this enum.\n </SectionListSectionDescription>\n </SectionListSectionHeader>\n <SectionListSectionContent className=\"space-y-4\">\n <div className=\"space-y-2\">\n <div\n className={clsx(\n gridClassNames,\n // account for handle in sortable list\n 'pl-12',\n )}\n >\n <Label>Value Name, e.g. ACTIVE</Label>\n <Label>Value Friendly Name, e.g. Active</Label>\n <div />\n </div>\n {valueFields.length === 0 ? (\n <p className=\"pt-4 text-style-muted\">\n Add some values to get started\n </p>\n ) : (\n <SortableList listItems={valueListItems} sortItems={sortValues} />\n )}\n </div>\n <Button\n size=\"sm\"\n variant=\"secondary\"\n onClick={() => {\n appendValue({\n id: modelEnumValueEntityType.generateNewId(),\n name: '',\n friendlyName: '',\n });\n }}\n >\n Add Value\n </Button>\n </SectionListSectionContent>\n </SectionListSection>\n );\n}\n","import type React from 'react';\n\nimport { useBlockUnsavedChangesNavigate } from '@baseplate-dev/project-builder-lib/web';\nimport { FormActionBar, SectionList } from '@baseplate-dev/ui-components';\nimport { createFileRoute } from '@tanstack/react-router';\n\nimport { ErrorBoundary } from '#src/components/index.js';\n\nimport { useEnumForm } from '../-hooks/use-enum-form.js';\nimport { EnumGraphQLSection } from './-components/enum-graph-ql-section.js';\nimport { EnumValuesSection } from './-components/enum-values-section.js';\n\nexport const Route = createFileRoute('/data/enums/edit/$key/')({\n component: EnumEditPage,\n});\n\nfunction EnumEditPage(): React.JSX.Element {\n const { key } = Route.useParams();\n const { form, onSubmit, isSavingDefinition } = useEnumForm({\n omit: ['name', 'featureRef'],\n enumKey: key,\n });\n const { control, setValue } = form;\n\n useBlockUnsavedChangesNavigate({ control, reset: form.reset, onSubmit });\n\n return (\n <ErrorBoundary>\n <form\n onSubmit={onSubmit}\n className=\"mx-4 max-w-7xl min-w-[700px] flex-1 space-y-4 pb-4\"\n >\n <SectionList>\n <EnumGraphQLSection control={control} />\n <EnumValuesSection control={control} setValue={setValue} />\n </SectionList>\n <FormActionBar form={form} disabled={isSavingDefinition} />\n </form>\n </ErrorBoundary>\n );\n}\n"],"names":["SectionListSection","SectionListSectionContent","SectionListSectionHeader","SectionListSectionTitle","SwitchFieldController","importShared","EnumGraphQLSection","control","jsx","underscoreToTitleCase","str","word","modelEnumValueEntityType","Button","InputFieldController","Label","SectionListSectionDescription","EnumValuesSection","setValue","valueFields","removeValue","appendValue","sortValues","useFieldArray","values","useWatch","gridClassNames","valueListItems","field","jsxs","MdDeleteOutline","clsx","SortableList","useBlockUnsavedChangesNavigate","FormActionBar","SectionList","SplitComponent","key","Route","useParams","form","onSubmit","isSavingDefinition","useEnumForm","omit","enumKey","reset","ErrorBoundary"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"index-1ErFJbDw.js","sources":["../../src/routes/data/enums/edit.$key/-components/enum-graph-ql-section.tsx","../../src/utils/casing.ts","../../src/routes/data/enums/edit.$key/-components/enum-values-section.tsx","../../src/routes/data/enums/edit.$key/index.tsx?tsr-split=component"],"sourcesContent":["import type { EnumConfig } from '@baseplate-dev/project-builder-lib';\nimport type React from 'react';\nimport type { Control } from 'react-hook-form';\n\nimport {\n SectionListSection,\n SectionListSectionContent,\n SectionListSectionHeader,\n SectionListSectionTitle,\n SwitchFieldController,\n} from '@baseplate-dev/ui-components';\n\nexport function EnumGraphQLSection({\n control,\n}: {\n control: Control<EnumConfig>;\n}): React.JSX.Element {\n return (\n <SectionListSection>\n <SectionListSectionHeader>\n <SectionListSectionTitle>GraphQL</SectionListSectionTitle>\n </SectionListSectionHeader>\n <SectionListSectionContent className=\"space-y-4\">\n <SwitchFieldController\n label=\"Expose in GraphQL schema\"\n control={control}\n name=\"isExposed\"\n description=\"Whether to expose this enum in the GraphQL schema\"\n />\n </SectionListSectionContent>\n </SectionListSection>\n );\n}\n","export function underscoreToTitleCase(str: string): string {\n // Split the string into an array of words\n const words = str.split('_');\n\n // Capitalize the first letter of each word and join them back together\n const titleCase = words\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())\n .join(' ');\n\n return titleCase;\n}\n","import type { EnumConfig } from '@baseplate-dev/project-builder-lib';\nimport type React from 'react';\nimport type { Control, UseFormSetValue } from 'react-hook-form';\n\nimport { modelEnumValueEntityType } from '@baseplate-dev/project-builder-lib';\nimport {\n Button,\n InputFieldController,\n Label,\n SectionListSection,\n SectionListSectionContent,\n SectionListSectionDescription,\n SectionListSectionHeader,\n SectionListSectionTitle,\n} from '@baseplate-dev/ui-components';\nimport clsx from 'clsx';\nimport { useFieldArray, useWatch } from 'react-hook-form';\nimport { MdDeleteOutline } from 'react-icons/md';\n\nimport { SortableList } from '#src/components/index.js';\nimport { underscoreToTitleCase } from '#src/utils/casing.js';\n\nexport function EnumValuesSection({\n control,\n setValue,\n}: {\n control: Control<EnumConfig>;\n setValue: UseFormSetValue<EnumConfig>;\n}): React.JSX.Element {\n const {\n fields: valueFields,\n remove: removeValue,\n append: appendValue,\n move: sortValues,\n } = useFieldArray({\n control,\n name: 'values',\n });\n\n const values = useWatch({ control, name: 'values' });\n\n const gridClassNames =\n 'grid grid-cols-[repeat(2,minmax(130px,1fr))_80px] gap-3';\n\n const valueListItems = valueFields.map((field, i) => ({\n id: field.id,\n element: (\n <div className={gridClassNames}>\n <InputFieldController control={control} name={`values.${i}.name`} />\n <InputFieldController\n control={control}\n name={`values.${i}.friendlyName`}\n onFocus={() => {\n if (!values[i].friendlyName && values[i].name) {\n setValue(\n `values.${i}.friendlyName`,\n underscoreToTitleCase(values[i].name),\n );\n }\n }}\n />\n <Button\n variant=\"ghost\"\n size=\"icon\"\n onClick={() => {\n removeValue(i);\n }}\n >\n <MdDeleteOutline />\n <div className=\"sr-only\">Delete Enum</div>\n </Button>\n </div>\n ),\n }));\n\n return (\n <SectionListSection>\n <SectionListSectionHeader>\n <SectionListSectionTitle>Values</SectionListSectionTitle>\n <SectionListSectionDescription>\n Configure the allowed values for this enum.\n </SectionListSectionDescription>\n </SectionListSectionHeader>\n <SectionListSectionContent className=\"space-y-4\">\n <div className=\"space-y-2\">\n <div\n className={clsx(\n gridClassNames,\n // account for handle in sortable list\n 'pl-12',\n )}\n >\n <Label>Value Name, e.g. ACTIVE</Label>\n <Label>Value Friendly Name, e.g. Active</Label>\n <div />\n </div>\n {valueFields.length === 0 ? (\n <p className=\"pt-4 text-style-muted\">\n Add some values to get started\n </p>\n ) : (\n <SortableList listItems={valueListItems} sortItems={sortValues} />\n )}\n </div>\n <Button\n size=\"sm\"\n variant=\"secondary\"\n onClick={() => {\n appendValue({\n id: modelEnumValueEntityType.generateNewId(),\n name: '',\n friendlyName: '',\n });\n }}\n >\n Add Value\n </Button>\n </SectionListSectionContent>\n </SectionListSection>\n );\n}\n","import type React from 'react';\n\nimport { useBlockUnsavedChangesNavigate } from '@baseplate-dev/project-builder-lib/web';\nimport { FormActionBar, SectionList } from '@baseplate-dev/ui-components';\nimport { createFileRoute } from '@tanstack/react-router';\n\nimport { ErrorBoundary } from '#src/components/index.js';\n\nimport { useEnumForm } from '../-hooks/use-enum-form.js';\nimport { EnumGraphQLSection } from './-components/enum-graph-ql-section.js';\nimport { EnumValuesSection } from './-components/enum-values-section.js';\n\nexport const Route = createFileRoute('/data/enums/edit/$key/')({\n component: EnumEditPage,\n});\n\nfunction EnumEditPage(): React.JSX.Element {\n const { key } = Route.useParams();\n const { form, onSubmit, isSavingDefinition } = useEnumForm({\n omit: ['name', 'featureRef'],\n enumKey: key,\n });\n const { control, setValue } = form;\n\n useBlockUnsavedChangesNavigate({ control, reset: form.reset, onSubmit });\n\n return (\n <ErrorBoundary>\n <form\n onSubmit={onSubmit}\n className=\"mx-4 max-w-7xl min-w-[700px] flex-1 space-y-4 pb-4\"\n >\n <SectionList>\n <EnumGraphQLSection control={control} />\n <EnumValuesSection control={control} setValue={setValue} />\n </SectionList>\n <FormActionBar form={form} disabled={isSavingDefinition} />\n </form>\n </ErrorBoundary>\n );\n}\n"],"names":["SectionListSection","SectionListSectionContent","SectionListSectionHeader","SectionListSectionTitle","SwitchFieldController","importShared","EnumGraphQLSection","control","jsx","underscoreToTitleCase","str","word","modelEnumValueEntityType","Button","InputFieldController","Label","SectionListSectionDescription","EnumValuesSection","setValue","valueFields","removeValue","appendValue","sortValues","useFieldArray","values","useWatch","gridClassNames","valueListItems","field","jsxs","MdDeleteOutline","clsx","SortableList","useBlockUnsavedChangesNavigate","FormActionBar","SectionList","SplitComponent","key","Route","useParams","form","onSubmit","isSavingDefinition","useEnumForm","omit","enumKey","reset","ErrorBoundary"],"mappings":"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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{i as s}from"./_virtual___federation_fn_import-BLYgPlMt.js";import{j as e}from"./index.esm-DcyGeCKA.js";import{p as A,s as F}from"./index-C_wN4CIq.js";const{authConfigSpec:L,createWebAppSchema:R}=await s("@baseplate-dev/project-builder-lib"),{useBlockUnsavedChangesNavigate:D,useDefinitionSchema:k,useProjectDefinition:d,useResettableForm:y}=await s("@baseplate-dev/project-builder-lib/web"),{FormActionBar:N,InputFieldController:i,MultiComboboxFieldController:P,SectionList:W,SectionListSection:u,SectionListSectionContent:b,SectionListSectionDescription:h,SectionListSectionHeader:x,SectionListSectionTitle:j,SwitchFieldController:t}=await s("@baseplate-dev/ui-components"),E=function(){const{saveDefinitionWithFeedback:S}=d(),{webDefinition:a}=A.useRouteContext(),f=k(R),l=y({resolver:F(f),values:a}),{control:o,handleSubmit:w,reset:g}=l,{definition:C,pluginContainer:v}=d(),c=w(n=>S(p=>{p.apps=p.apps.map(m=>m.id===a.id?n:m)}));D({control:o,reset:g,onSubmit:c});const r=v.getPluginSpecOptional(L)?.getAuthRoles(C).map(n=>({label:n.name,value:n.id}));return e.jsxs("form",{onSubmit:c,className:"w-full max-w-7xl space-y-4 p-4",children:[e.jsxs(W,{children:[e.jsxs(u,{children:[e.jsxs(x,{children:[e.jsx(j,{children:"General"}),e.jsx(h,{children:"Basic configuration for your web application."})]}),e.jsxs(b,{className:"space-y-6",children:[e.jsx(i,{label:"Name",control:o,name:"name"}),e.jsx(i,{label:"Package Location (optional)",placeholder:"e.g. packages/web",control:o,name:"packageLocation"}),e.jsx(i,{label:"Page Title",control:o,name:"title"}),e.jsx(i,{label:"Description Meta Tag",control:o,name:"description"})]})]}),e.jsxs(u,{children:[e.jsxs(x,{children:[e.jsx(j,{children:"Features"}),e.jsx(h,{children:"Configure optional features for your web application."})]}),e.jsxs(b,{className:"space-y-6",children:[e.jsx(t,{label:"Include Auth?",control:o,name:"includeAuth"}),e.jsx(t,{label:"Include Upload Components?",control:o,name:"includeUploadComponents"}),e.jsx(t,{label:"Enable Subscriptions?",control:o,name:"enableSubscriptions"}),r&&e.jsx(P,{label:"Allowed Roles",description:"Which roles can access the web application",control:o,options:r,name:"allowedRoles"})]})]})]}),e.jsx(N,{form:l})]})};export{E as component};
|
|
2
|
+
//# sourceMappingURL=index-37eYMUXo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-37eYMUXo.js","sources":["../../src/routes/apps/edit.$key/web/index.tsx?tsr-split=component"],"sourcesContent":["import type React from 'react';\n\nimport {\n authConfigSpec,\n createWebAppSchema,\n} from '@baseplate-dev/project-builder-lib';\nimport {\n useBlockUnsavedChangesNavigate,\n useDefinitionSchema,\n useProjectDefinition,\n useResettableForm,\n} from '@baseplate-dev/project-builder-lib/web';\nimport {\n FormActionBar,\n InputFieldController,\n MultiComboboxFieldController,\n SectionList,\n SectionListSection,\n SectionListSectionContent,\n SectionListSectionDescription,\n SectionListSectionHeader,\n SectionListSectionTitle,\n SwitchFieldController,\n} from '@baseplate-dev/ui-components';\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport { createFileRoute } from '@tanstack/react-router';\n\nexport const Route = createFileRoute('/apps/edit/$key/web/')({\n component: WebAppGeneralForm,\n});\n\nfunction WebAppGeneralForm(): React.JSX.Element {\n const { saveDefinitionWithFeedback } = useProjectDefinition();\n const { webDefinition } = Route.useRouteContext();\n\n const webAppSchema = useDefinitionSchema(createWebAppSchema);\n const formProps = useResettableForm({\n resolver: zodResolver(webAppSchema),\n values: webDefinition,\n });\n const { control, handleSubmit, reset } = formProps;\n\n const { definition, pluginContainer } = useProjectDefinition();\n\n const onSubmit = handleSubmit((data) =>\n saveDefinitionWithFeedback((draftConfig) => {\n draftConfig.apps = draftConfig.apps.map((app) =>\n app.id === webDefinition.id ? data : app,\n );\n }),\n );\n\n useBlockUnsavedChangesNavigate({ control, reset, onSubmit });\n\n const roleOptions = pluginContainer\n .getPluginSpecOptional(authConfigSpec)\n ?.getAuthRoles(definition)\n .map((role) => ({\n label: role.name,\n value: role.id,\n }));\n\n return (\n <form onSubmit={onSubmit} className=\"w-full max-w-7xl space-y-4 p-4\">\n <SectionList>\n <SectionListSection>\n <SectionListSectionHeader>\n <SectionListSectionTitle>General</SectionListSectionTitle>\n <SectionListSectionDescription>\n Basic configuration for your web application.\n </SectionListSectionDescription>\n </SectionListSectionHeader>\n <SectionListSectionContent className=\"space-y-6\">\n <InputFieldController label=\"Name\" control={control} name=\"name\" />\n <InputFieldController\n label=\"Package Location (optional)\"\n placeholder=\"e.g. packages/web\"\n control={control}\n name=\"packageLocation\"\n />\n <InputFieldController\n label=\"Page Title\"\n control={control}\n name=\"title\"\n />\n <InputFieldController\n label=\"Description Meta Tag\"\n control={control}\n name=\"description\"\n />\n </SectionListSectionContent>\n </SectionListSection>\n\n <SectionListSection>\n <SectionListSectionHeader>\n <SectionListSectionTitle>Features</SectionListSectionTitle>\n <SectionListSectionDescription>\n Configure optional features for your web application.\n </SectionListSectionDescription>\n </SectionListSectionHeader>\n <SectionListSectionContent className=\"space-y-6\">\n <SwitchFieldController\n label=\"Include Auth?\"\n control={control}\n name=\"includeAuth\"\n />\n <SwitchFieldController\n label=\"Include Upload Components?\"\n control={control}\n name=\"includeUploadComponents\"\n />\n <SwitchFieldController\n label=\"Enable Subscriptions?\"\n control={control}\n name=\"enableSubscriptions\"\n />\n {roleOptions && (\n <MultiComboboxFieldController\n label=\"Allowed Roles\"\n description=\"Which roles can access the web application\"\n control={control}\n options={roleOptions}\n name=\"allowedRoles\"\n />\n )}\n </SectionListSectionContent>\n </SectionListSection>\n </SectionList>\n <FormActionBar form={formProps} />\n </form>\n );\n}\n"],"names":["authConfigSpec","createWebAppSchema","importShared","useBlockUnsavedChangesNavigate","useDefinitionSchema","useProjectDefinition","useResettableForm","FormActionBar","InputFieldController","MultiComboboxFieldController","SectionList","SectionListSection","SectionListSectionContent","SectionListSectionDescription","SectionListSectionHeader","SectionListSectionTitle","SwitchFieldController","SplitComponent","saveDefinitionWithFeedback","webDefinition","Route","useRouteContext","webAppSchema","formProps","resolver","zodResolver","values","control","handleSubmit","reset","definition","pluginContainer","onSubmit","draftConfig","apps","map","app","id","data","roleOptions","getPluginSpecOptional","getAuthRoles","role","label","name","value","jsxs","jsx"],"mappings":"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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{i as o}from"./_virtual___federation_fn_import-
|
|
2
|
-
//# sourceMappingURL=index-
|
|
1
|
+
import{i as o}from"./_virtual___federation_fn_import-BLYgPlMt.js";import{j as e}from"./index.esm-DcyGeCKA.js";import{s as d}from"./index-C_wN4CIq.js";const{generalSettingsSchema:h}=await o("@baseplate-dev/project-builder-lib"),{useBlockUnsavedChangesNavigate:f,useProjectDefinition:j,useResettableForm:u}=await o("@baseplate-dev/project-builder-lib/web"),{FormActionBar:g,InputFieldController:s,SectionList:x,SectionListSection:b,SectionListSectionContent:S,SectionListSectionHeader:v,SectionListSectionTitle:w}=await o("@baseplate-dev/ui-components"),L=function(){const{definition:n,saveDefinitionWithFeedback:r}=j(),i=u({resolver:d(h),defaultValues:n.settings.general}),{handleSubmit:l,control:t,reset:c}=i,a=l(p=>r(m=>{m.settings.general=p}));return f({control:t,reset:c,onSubmit:a}),e.jsxs("form",{className:"relative h-full max-h-full pb-(--action-bar-height)",onSubmit:a,children:[e.jsxs("div",{className:"flex h-full max-h-full flex-1 flex-col overflow-y-auto px-6",children:[e.jsx("div",{className:"sticky top-0 border-b bg-background py-6",children:e.jsx("h1",{children:"Project settings"})}),e.jsx(x,{children:e.jsxs(b,{children:[e.jsx(v,{children:e.jsx(w,{children:"Settings"})}),e.jsxs(S,{className:"flex max-w-80 flex-col gap-4",children:[e.jsx(s,{name:"name",label:"Project Name",description:"Lowercase letters and dashes, e.g. my-project",control:t,placeholder:"e.g. my-project"}),e.jsx(s,{name:"portOffset",label:"Port Offset",description:"Multiple of 1000, e.g. 4000. This will offset the ports used by the project, e.g. API at 4001, database at 4432, to avoid conflicts with other projects.",control:t,registerOptions:{valueAsNumber:!0}}),e.jsx(s,{label:"Package Scope",name:"packageScope",description:"The scope for packages in this project, e.g. my-project will result in @my-project/app-name",control:t})]})]})})]}),e.jsx(g,{form:i})]})};export{L as component};
|
|
2
|
+
//# sourceMappingURL=index-B5-Qczd9.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-B5-Qczd9.js","sources":["../../src/routes/settings/index.tsx?tsr-split=component"],"sourcesContent":["import type React from 'react';\n\nimport { generalSettingsSchema } from '@baseplate-dev/project-builder-lib';\nimport {\n useBlockUnsavedChangesNavigate,\n useProjectDefinition,\n useResettableForm,\n} from '@baseplate-dev/project-builder-lib/web';\nimport {\n FormActionBar,\n InputFieldController,\n SectionList,\n SectionListSection,\n SectionListSectionContent,\n SectionListSectionHeader,\n SectionListSectionTitle,\n} from '@baseplate-dev/ui-components';\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport { createFileRoute } from '@tanstack/react-router';\n\nexport const Route = createFileRoute('/settings/')({\n component: ProjectSettingsPage,\n beforeLoad: () => ({\n getTitle: () => 'Project Settings',\n }),\n});\n\nfunction ProjectSettingsPage(): React.JSX.Element {\n const { definition, saveDefinitionWithFeedback } = useProjectDefinition();\n\n const form = useResettableForm({\n resolver: zodResolver(generalSettingsSchema),\n defaultValues: definition.settings.general,\n });\n\n const { handleSubmit, control, reset } = form;\n\n const onSubmit = handleSubmit((data) =>\n saveDefinitionWithFeedback((draftConfig) => {\n draftConfig.settings.general = data;\n }),\n );\n\n useBlockUnsavedChangesNavigate({ control, reset, onSubmit });\n\n return (\n <form\n className=\"relative h-full max-h-full pb-(--action-bar-height)\"\n onSubmit={onSubmit}\n >\n <div className=\"flex h-full max-h-full flex-1 flex-col overflow-y-auto px-6\">\n <div className=\"sticky top-0 border-b bg-background py-6\">\n <h1>Project settings</h1>\n </div>\n <SectionList>\n <SectionListSection>\n <SectionListSectionHeader>\n <SectionListSectionTitle>Settings</SectionListSectionTitle>\n </SectionListSectionHeader>\n <SectionListSectionContent className=\"flex max-w-80 flex-col gap-4\">\n <InputFieldController\n name=\"name\"\n label=\"Project Name\"\n description=\"Lowercase letters and dashes, e.g. my-project\"\n control={control}\n placeholder=\"e.g. my-project\"\n />\n <InputFieldController\n name=\"portOffset\"\n label=\"Port Offset\"\n description=\"Multiple of 1000, e.g. 4000. This will offset the ports used by the project, e.g. API at 4001, database at 4432, to avoid conflicts with other projects.\"\n control={control}\n registerOptions={{ valueAsNumber: true }}\n />\n <InputFieldController\n label=\"Package Scope\"\n name=\"packageScope\"\n description=\"The scope for packages in this project, e.g. my-project will result in @my-project/app-name\"\n control={control}\n />\n </SectionListSectionContent>\n </SectionListSection>\n </SectionList>\n </div>\n <FormActionBar form={form} />\n </form>\n );\n}\n"],"names":["generalSettingsSchema","importShared","useBlockUnsavedChangesNavigate","useProjectDefinition","useResettableForm","FormActionBar","InputFieldController","SectionList","SectionListSection","SectionListSectionContent","SectionListSectionHeader","SectionListSectionTitle","SplitComponent","definition","saveDefinitionWithFeedback","form","resolver","zodResolver","defaultValues","settings","general","handleSubmit","control","reset","onSubmit","draftConfig","data","jsxs","jsx","valueAsNumber"],"mappings":"sJAEA,KAAA,CAAA,sBAAAA,CAAA,EAAA,MAAAC,EAAA,oCAAA,EACA,CAAA,+BAAAC,EAAA,qBAAAC,EAAA,kBAAAC,CAAA,EAAA,MAAAH,EAAA,wCAAA,EAKA,CAAA,cAAAI,EAAA,qBAAAC,EAAA,YAAAC,EAAA,mBAAAC,EAAA,0BAAAC,EAAA,yBAAAC,EAAA,wBAAAC,CAAA,EAAA,MAAAV,EAAA,8BAAA,EASsDW,EAAA,UAUJ,CAC1C,KAAA,CAAEC,WAAAA,EAAYC,2BAAAA,GAA+BX,EAAqB,EAElEY,EAAOX,EAAkB,CAC7BY,SAAUC,EAAYjB,CAAqB,EAC3CkB,cAAeL,EAAWM,SAASC,OAAAA,CACpC,EAEK,CAAEC,aAAAA,EAAcC,QAAAA,EAASC,MAAAA,CAAAA,EAAUR,EAEnCS,EAAWH,EACfP,GAAAA,EAA4CW,GAAA,CAC1CA,EAAYN,SAASC,QAAUM,CAAAA,CAChC,CACH,EAE+B,OAAAxB,EAAA,CAAEoB,QAAAA,EAASC,MAAAA,EAAOC,SAAAA,CAAAA,CAAU,EAGxDG,EAAAA,KAAA,OAAA,CACC,UAAU,sDACV,SAAAH,EAEA,SAAA,CAACG,EAAAA,KAAA,MAAA,CAAI,UAAU,8DACb,SAAA,CAAAC,EAAAA,IAAC,OAAI,UAAU,2CACb,SAACA,MAAA,KAAA,CAAG,4BAAgB,CACtB,CAAA,EACAA,EAAA,IAACrB,EACC,CAAA,SAAAoB,EAAAA,KAACnB,EACC,CAAA,SAAA,CAAAoB,MAAClB,EACC,CAAA,SAAAkB,EAAA,IAACjB,EAAwB,CAAA,SAAA,UAAQ,CAAA,EACnC,EACAgB,EAAAA,KAAClB,EAA0B,CAAA,UAAU,+BACnC,SAAA,CAACmB,EAAAA,IAAAtB,EAAA,CACC,KAAK,OACL,MAAM,eACN,YAAY,gDACZ,QAAAgB,EACA,YAAY,iBAAiB,CAAA,EAE/BM,EAAAA,IAACtB,GACC,KAAK,aACL,MAAM,cACN,YAAY,2JACZ,QAAAgB,EACA,gBAAiB,CAAEO,cAAe,EAAA,EAAO,EAE3CD,MAACtB,GACC,MAAM,gBACN,KAAK,eACL,YAAY,8FACZ,QAAAgB,CAAiB,CAAA,CAAA,CAErB,CAAA,CAAA,CAAA,CACF,CACF,CAAA,CAAA,EACF,EACAM,MAACvB,GAAc,KAAAU,CAAW,CAAA,CAAA,EAC5B,CAEJ"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{i as f}from"./_virtual___federation_fn_import-DK_YYIlv.js";import{j as e,u as I,b as ie,e as le,f as Se}from"./index.esm-Bvv3vNQh.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-B7G2CMwL.js";import{u as g,S as Me,E as Ie}from"./-constants-CyTNHADu.js";import{u as Le}from"./use-model-form-Bjm8n0m8.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-BgFEd-vA.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
|