@donotdev/crud 0.0.10 → 0.0.12
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/components/EntityDisplayRenderer.d.ts +2 -2
- package/dist/components/EntityDisplayRenderer.d.ts.map +1 -1
- package/dist/components/EntityFilters.d.ts.map +1 -1
- package/dist/components/EntityFilters.js +1 -1
- package/dist/components/EntityFormRenderer.d.ts.map +1 -1
- package/dist/components/EntityFormRenderer.js +1 -1
- package/dist/components/controlled/input/ControlledDurationField.d.ts +7 -0
- package/dist/components/controlled/input/ControlledDurationField.d.ts.map +1 -0
- package/dist/components/controlled/input/ControlledDurationField.js +1 -0
- package/dist/components/controlled/input/index.d.ts +1 -0
- package/dist/components/controlled/input/index.d.ts.map +1 -1
- package/dist/components/controlled/input/index.js +1 -1
- package/dist/components/form/fields/DurationFieldComponent.d.ts +42 -0
- package/dist/components/form/fields/DurationFieldComponent.d.ts.map +1 -0
- package/dist/components/form/fields/DurationFieldComponent.js +1 -0
- package/dist/components/form/fields/PhoneNumberComponent.d.ts.map +1 -1
- package/dist/components/form/fields/PhoneNumberComponent.js +1 -1
- package/dist/components/form/fields/index.d.ts +3 -0
- package/dist/components/form/fields/index.d.ts.map +1 -1
- package/dist/components/form/fields/index.js +1 -1
- package/dist/forms/hooks/useEntityForm.d.ts.map +1 -1
- package/dist/forms/hooks/useEntityForm.js +1 -1
- package/dist/forms/types.d.ts +13 -4
- package/dist/forms/types.d.ts.map +1 -1
- package/dist/forms/utils/buildInitialValues.d.ts +30 -0
- package/dist/forms/utils/buildInitialValues.d.ts.map +1 -0
- package/dist/forms/utils/buildInitialValues.js +1 -0
- package/dist/forms/utils/getFieldsForOperation.d.ts +2 -3
- package/dist/forms/utils/getFieldsForOperation.d.ts.map +1 -1
- package/dist/forms/utils/getFieldsForOperation.js +1 -1
- package/dist/forms/utils/isFieldEditable.d.ts +1 -1
- package/dist/forms/utils/isFieldEditable.d.ts.map +1 -1
- package/dist/forms/utils/translateFieldLabel.d.ts +11 -5
- package/dist/forms/utils/translateFieldLabel.d.ts.map +1 -1
- package/dist/forms/utils/translateFieldLabel.js +1 -1
- package/dist/registerBuiltinFieldTypes.d.ts.map +1 -1
- package/dist/registerBuiltinFieldTypes.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Entity
|
|
1
|
+
import type { Entity } from '@donotdev/core';
|
|
2
2
|
export interface EntityDisplayRendererProps<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
3
3
|
/** Entity definition - pass the full entity from defineEntity() */
|
|
4
4
|
entity: Entity;
|
|
@@ -20,7 +20,7 @@ export interface EntityDisplayRendererProps<T extends Record<string, unknown> =
|
|
|
20
20
|
* If not provided, defaults to 'guest' (most restrictive - shows only public fields)
|
|
21
21
|
* @default 'guest'
|
|
22
22
|
*/
|
|
23
|
-
viewerRole?:
|
|
23
|
+
viewerRole?: string;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* EntityDisplayRenderer - Automatically fetches and displays entity data
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityDisplayRenderer.d.ts","sourceRoot":"","sources":["../../src/components/EntityDisplayRenderer.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"EntityDisplayRenderer.d.ts","sourceRoot":"","sources":["../../src/components/EntityDisplayRenderer.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAK7C,MAAM,WAAW,0BAA0B,CACzC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAE3D,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,yBAAyB;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,uEAAuE;IACvE,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC;IAC/D,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qBAAqB;IACrB,OAAO,CAAC,EAAE,WAAW,GAAG,WAAW,CAAC;IACpC,6BAA6B;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,+BAA+B;IAC/B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACnC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,EACA,MAAM,EACN,EAAE,EACF,CAAC,EACD,SAAc,EACd,OAAqB,EACrB,cAAc,EACd,eAAe,EACf,UAAoB,GACrB,EAAE,0BAA0B,CAAC,CAAC,CAAC,2CAgM/B;AAED,eAAe,qBAAqB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityFilters.d.ts","sourceRoot":"","sources":["../../src/components/EntityFilters.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EntityFilters.d.ts","sourceRoot":"","sources":["../../src/components/EntityFilters.tsx"],"names":[],"mappings":"AAsDA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAM7C;;;;;;;;;;;;;;GAcG;AAEH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,GAAG,EAEd,WAAW,EAAE,MAAM,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,EAEpD,SAAS,EAAE,MAAM,GAChB,OAAO,CA8MT;AAqND,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,GAAG;IACzC,4BAA4B;IAE5B,MAAM,EAAE,MAAM,CAAC;IAEf,2DAA2D;IAE3D,IAAI,EAAE,CAAC,EAAE,CAAC;IAEV,4BAA4B;IAE5B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAEjE,mCAAmC;IAEnC,eAAe,EAAE,CACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,KAC7D,IAAI,CAAC;IAEV,oFAAoF;IAEpF,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAE1B,sFAAsF;IAEtF,OAAO,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AAEH,wBAAgB,aAAa,CAC3B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnD,EACA,MAAM,EAEN,IAAI,EAEJ,OAAO,EAEP,eAAe,EAEf,cAAc,EAEd,OAAkB,GACnB,EAAE,kBAAkB,CAAC,CAAC,CAAC,kDAyjBvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as g,jsxs as R}from"react/jsx-runtime";import{useMemo as B,useState as U}from"react";import{FilterX as Z}from"lucide-react";import{Button as j,Calendar as V,Combobox as ee,Grid as te,Popover as ne,RangeInput as re,Slider as ie,Stack as z,Text as X}from"@donotdev/components";import{useTranslation as q,handleError as N,formatDate as H}from"@donotdev/core";import{translateFieldLabel as se,translateLabel as J}from"../forms/utils";import{getFilterType as W,isFilterable as oe}from"../fieldTypeRegistry";function ae(e,t,s){if(!t)return!0;if(typeof t=="object"&&"min"in t){const l=W(s);if(!l)throw N(new Error(`Field type "${s}" not registered in field type registry`),{userMessage:`Field type "${s}" is missing from registry`,context:{fieldType:s,operation:"filter_matching",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"}});const C=l==="range"&&(s==="date"||s==="datetime-local"||s==="timestamp"),F=l==="range"&&!C,D=s==="price",u=D&&e!=null&&typeof e=="object"?Number(e.amount):F&&e!=null?typeof e=="number"?e:Number(e):NaN;if(F||D){const d=t.min&&t.min!=="",y=t.max&&t.max!=="";return d&&!y?e==null||isNaN(u)?!1:u>=Number(t.min):!d&&y?e==null?!0:isNaN(u)?!1:u<=Number(t.max):d&&y?e==null||isNaN(u)?!1:u>=Number(t.min)&&u<=Number(t.max):!0}if(C){const d=t.min&&t.min!=="",y=t.max&&t.max!=="";if(d&&!y){if(e==null)return!1;const b=e instanceof Date?e:new Date(e);return isNaN(b.getTime())?!1:b>=new Date(t.min)}if(!d&&y){if(e==null)return!0;const b=e instanceof Date?e:new Date(e);return isNaN(b.getTime())?!1:b<=new Date(t.max)}if(d&&y){if(e==null)return!1;const b=e instanceof Date?e:new Date(e);return isNaN(b.getTime())?!1:b>=new Date(t.min)&&b<=new Date(t.max)}return!0}}const h=W(s);if(!h)throw N(new Error(`Field type "${s}" not registered in field type registry`),{userMessage:`Field type "${s}" is missing from registry`,context:{fieldType:s,operation:"filter_matching",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"}});if(h==="address")return e==null?!1:typeof e=="object"&&"formatted_address"in e?String(e.formatted_address).toLowerCase().includes(String(t).toLowerCase()):!1;if(h==="multiselect"){if(!Array.isArray(e)||e.length===0)return!1;const l=String(t).toLowerCase();return e.some(C=>String(C).toLowerCase().includes(l))}return e==null?!1:String(e).toLowerCase().includes(String(t).toLowerCase())}function le(e,t,s){if(!e&&!t)return s??"From \u2013 To";const h=e?H(e,void 0,{month:"short",day:"numeric",year:"numeric"}):"",l=t?H(t,void 0,{month:"short",day:"numeric",year:"numeric"}):"";return h&&l?`${h} \u2013 ${l}`:h?`${h} \u2013 \u2026`:l?`\u2026 \u2013 ${l}`:s??"From \u2013 To"}function ce({label:e,rangeFilter:t,onRangeChange:s,onClear:h,tCrud:l}){const[C,F]=U(!1),D=!!(t.min||t.max),u=t.min||t.max?{from:t.min?new Date(t.min+"T00:00:00"):void 0,to:t.max?new Date(t.max+"T00:00:00"):void 0}:void 0,d=a=>{if(!a){h();return}const x=a.from?a.from.toISOString().split("T")[0]:"",O=a.to?a.to.toISOString().split("T")[0]:"";s(x,O),a.from&&a.to&&F(!1)},y=(a,x)=>{s(a,x),F(!1)},b=()=>{h(),F(!1)},E=le(t.min,t.max,l("filter.fromTo",{defaultValue:"From \u2013 To"}));return g(ne,{open:C,onOpenChange:F,trigger:g(j,{variant:"outline","aria-haspopup":"dialog","aria-expanded":C,"aria-label":e,children:R(X,{as:"span",level:"small",variant:D?void 0:"muted",children:[e,": ",E]})}),children:R(z,{gap:"medium",style:{padding:"var(--gap-md)"},children:[g(X,{as:"span",level:"small",variant:"muted",children:e}),R(z,{direction:"row",gap:"tight",children:[g(j,{variant:"outline",display:"compact",onClick:()=>{const a=new Date().toISOString().split("T")[0];y(a,a)},children:l("filter.today",{defaultValue:"Today"})}),g(j,{variant:"outline",display:"compact",onClick:()=>{const a=new Date,x=new Date(a);x.setDate(a.getDate()-a.getDay());const O=new Date(x);O.setDate(x.getDate()+6),y(x.toISOString().split("T")[0],O.toISOString().split("T")[0])},children:l("filter.thisWeek",{defaultValue:"This Week"})}),g(j,{variant:"outline",display:"compact",onClick:()=>{const a=new Date,x=new Date(a.getFullYear(),a.getMonth(),1),O=new Date(a.getFullYear(),a.getMonth()+1,0);y(x.toISOString().split("T")[0],O.toISOString().split("T")[0])},children:l("filter.thisMonth",{defaultValue:"This Month"})})]}),g(V,{mode:"range",selected:u,onSelect:d,defaultMonth:u?.from??u?.to??new Date}),g(j,{variant:"ghost",display:"compact",onClick:b,children:l("filter.clearDate",{defaultValue:"Clear"})})]})})}function ye({entity:e,data:t,filters:s,onFiltersChange:h,fieldsToFilter:l,variant:C="inline"}){const F=C==="sidebar",{t:D}=q("crud"),{t:u}=q([e.namespace,"crud"]),d=B(()=>(l&&l.length>0?l:e.listFields||Object.keys(e.fields)).filter(n=>{const o=e.fields[n]?.type||"text";return oe(o)}),[l,e.listFields,e.fields]),y=B(()=>{const r={};return d.forEach(n=>{const m=Object.fromEntries(Object.entries(s).filter(([o])=>o!==n));if(Object.keys(m).length===0){r[n]=t;return}r[n]=t.filter(o=>Object.entries(m).every(([w,v])=>{const A=o[w],p=e.fields[w]?.type||"text";return ae(A,v,p)}))}),r},[t,s,e.fields,d]),b=B(()=>{const r={};return d.forEach(n=>{const m=e.fields[n];if(!m)return;const o=m.type||"text",w=W(o);if(!w){N(new Error(`Field type "${o}" not registered in field type registry`),{userMessage:`Field type "${o}" is missing from registry`,context:{fieldType:o,fieldName:n,operation:"minmax_computation",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"});return}const v=w==="range"&&(o==="date"||o==="datetime-local"||o==="timestamp"),A=w==="range"&&!v,k=o==="price";if(A||k){const p=t.map(i=>i[n]).filter(i=>i!=null&&i!=="").map(i=>k&&typeof i=="object"&&i!==null?Number(i.amount):typeof i=="number"?i:Number(i)).filter(i=>!isNaN(i));p.length>0&&(r[n]={min:Math.min(...p),max:Math.max(...p)})}else if(v){const p=t.map(i=>i[n]).filter(i=>i!=null&&i!=="").map(i=>i instanceof Date?i:new Date(i)).filter(i=>!isNaN(i.getTime()));if(p.length>0){const i=new Date(Math.min(...p.map($=>$.getTime()))),M=new Date(Math.max(...p.map($=>$.getTime()))),G=i.toISOString().split("T")[0],I=M.toISOString().split("T")[0];r[n]={min:G||"",max:I||""}}}}),r},[t,e.fields,d]),E=(r,n)=>{const m={...s};if(!n||n==="")delete m[r];else if(typeof n=="object"&&"min"in n){const o=n.min&&n.min!=="",w=n.max&&n.max!=="";!o&&!w?delete m[r]:m[r]=n}else m[r]=n;h(m)},a=()=>{h({})},x=B(()=>d.length===0?null:d.map(r=>{const n=e.fields[r];if(!n)return null;const m=se(r,n,u),o=n.type||"text",w=W(o);if(!w)return N(new Error(`Field type "${o}" not registered in field type registry`),{userMessage:`Field type "${o}" is missing from registry`,context:{fieldType:o,fieldName:r,operation:"filter_ui_render",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"}),null;const v=w==="range"&&(o==="date"||o==="datetime-local"||o==="timestamp"),A=w==="range"&&!v,k=w==="select",p=s[r],M=typeof p=="object"&&p!==null&&"min"in p?p:{min:"",max:""};if(A){const f=b[r],S=f?.min??0,c=f?.max??100,T=M.min?Number(M.min):S,_=M.max?Number(M.max):c;return R(z,{gap:"tight",style:{gridColumn:"span 2",gridRow:F?void 0:"span 2"},children:[g(re,{type:"number",label:m,minPlaceholder:D("filter.min",{defaultValue:"Min"}),maxPlaceholder:D("filter.max",{defaultValue:"Max"}),minValue:M.min||"",maxValue:M.max||"",actualMin:S,actualMax:c,onChange:(L,Q)=>{E(r,{min:L,max:Q})},onClear:()=>E(r,void 0)}),g(ie,{value:[T,_],min:S,max:c,step:1,onValueChange:L=>{E(r,{min:String(L[0]),max:String(L[1])})}})]},r)}if(v)return g("div",{style:{gridColumn:"span 2",gridRow:F?void 0:"span 1"},children:g(ce,{label:m,rangeFilter:M,onRangeChange:(f,S)=>E(r,{min:f,max:S}),onClear:()=>E(r,void 0),tCrud:D})},r);const I=k&&n.validation&&"options"in n.validation&&n.validation?Array.isArray(n.validation.options)?n.validation.options:typeof n.validation.options=="function"?n.validation.options():[]:[],$=y[r]||t,Y=new Set;$.forEach(f=>{const S=f[r];S!=null&&Y.add(String(S))});const P=[{value:"all",label:D("filter.selectPlaceholder",{defaultValue:"All"})}];if(I.length>0){const f=[],S=[];I.forEach(c=>{const T=typeof c=="string"?c:c.value,_=typeof c=="string"?c:c.label;Y.has(T)?f.push({value:T,label:_}):S.push({value:T,label:_})}),f.sort((c,T)=>c.label.localeCompare(T.label)),S.sort((c,T)=>c.label.localeCompare(T.label)),f.forEach(c=>{P.push({value:c.value,label:J(c.label,u),disabled:!1})}),S.forEach(c=>{P.push({value:c.value,label:J(c.label,u),disabled:!0})})}else Array.from(Y).sort().slice(0,100).forEach(f=>{P.push({value:f,label:f})});return g("div",{style:{gridColumn:"span 2",gridRow:"span 1"},children:g(ee,{label:m,value:typeof p=="string"?p:void 0,onValueChange:f=>{E(r,f==="all"||!f?"":String(f))},options:P,placeholder:D("filter.placeholder",{defaultValue:"Filter..."}),clearable:!0})},r)}),[d,e.fields,t,s,u,D,y]);if(!x||x.length===0)return null;const O=x.filter(Boolean),K=Object.keys(s).length>0;return R(te,{cols:C==="sidebar"?2:[2,4,6,8],gap:"medium",style:{gridAutoRows:"min-content"},children:[O,g(j,{variant:"outline",icon:g(Z,{size:18}),onClick:a,disabled:!K,style:{gridColumn:"1 / -1",gridRow:"span 1"},children:D("filter.clear",{defaultValue:"Clear Filters"})})]})}export{ye as EntityFilters,ae as matchesFilter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityFormRenderer.d.ts","sourceRoot":"","sources":["../../src/components/EntityFormRenderer.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAY7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,UAAU,uBAAuB,CAC/B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAE3D,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,2BAA2B;IAC3B,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAA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f}from"react/jsx-runtime";import{useEffect as T,useId as Z,useMemo as p}from"react";import{FormProvider as ee}from"react-hook-form";import{Button as v,Stack as re,Spinner as oe}from"@donotdev/components";import{useTranslation as D}from"@donotdev/core";import{DisplayFieldRenderer as te}from"./DisplayFieldRenderer";import{FormFieldRenderer as ne}from"./FormFieldRenderer";import{UploadProvider as ae}from"../contexts/UploadContext";import{useEntityForm as ie}from"../forms/hooks/useEntityForm";import{useUnsavedChangesWarning as se,useConfirmNavigation as de}from"../hooks/useUnsavedChangesWarning";import{useFormStore as le}from"../stores";function ue({entity:u,onSubmit:I,t:k,className:V="",submitText:N,loading:j=!1,defaultValues:s,submitVariant:P="primary",secondaryButtonText:m,secondaryButtonVariant:U="outline",onSecondarySubmit:h,viewerRole:B,operation:c=s?"edit":"create",autoSave:E=c==="create",formId:L,cancelText:y,onCancel:R,warnOnUnsavedChanges:$=!0,unsavedChangesMessage:d}){const M=Z(),n=L??`entity-form-${u.name}-${M}`,{t:Y}=D([u.namespace,"crud"]),{t:e}=D("crud"),g=k||Y,b=ie(u,{formId:n,operation:c,defaultValues:s,viewerRole:B,t:g,autoSave:E}),{control:_,handleSubmit:x,formState:{errors:z},fields:A,formStatus:l,uploadProgress:a,cleanup:C,isDirty:W,hasUserInteracted:q,resetForm:G}=b,i=W&&q;T(()=>{n&&le.getState().setIsDirty(n,i)},[n,i]),T(()=>C,[C]);const H=p(()=>d||e("messages.unsavedChangesLeave",{defaultValue:"You have unsaved changes. Are you sure you want to leave?"}),[d,e]),J=p(()=>d||e("messages.unsavedChangesDiscard",{defaultValue:"You have unsaved changes. Discard them?"}),[d,e]);se({isDirty:i,enabled:$,message:H});const K=de(i,J),O=async()=>{i&&!await K()||(G(),R?.())},F=y!==null,S=y??e("form.cancel",{defaultValue:"Cancel"}),Q=j||c==="edit"&&!s,o=p(()=>l==="uploading"?{loading:!0,loadingText:a<100?e("form.uploading",{progress:Math.round(a),defaultValue:`Uploading ${Math.round(a)}%...`}):e("form.processing",{defaultValue:"Processing..."}),progress:a}:l==="validating"?{loading:!0,loadingText:e("form.validating",{defaultValue:"Validating..."})}:l==="submitting"?{loading:!0,loadingText:e("form.saving",{defaultValue:"Saving..."})}:{loading:!1},[l,a,e]);return r(ee,{...b,children:r(ae,{formId:n,children:f("div",{style:{position:"relative",width:"100%",gridColumn:"1 / -1",display:"contents"},children:[Q&&r(oe,{overlay:!0}),f("form",{onSubmit:x(I),noValidate:!0,className:V,style:{width:"100%",gridColumn:"1 / -1",display:"contents"},children:[A.map(({name:t,config:w,editable:X})=>X?r(ne,{name:t,config:w,control:_,errors:z,t:g},t):r(te,{name:t,config:w,value:s?.[t],t:g},t)),f(re,{direction:m||F?"row":"column",gap:"tight",style:{gridColumn:"1 / -1",position:"sticky",bottom:0,backgroundColor:"var(--background)",borderTop:"1px solid var(--border)",paddingTop:"var(--gap-md)",paddingBottom:"var(--gap-md)",zIndex:10,marginTop:"var(--gap-lg)"},children:[F&&S&&r(v,{type:"button",onClick:O,disabled:o.loading,variant:"outline",className:"dndev-w-full",children:S}),m&&r(v,{type:"button",onClick:()=>h&&x(h)(),loading:o.loading,loadingText:o.loadingText,progress:o.progress,variant:U,className:"dndev-w-full",children:m}),r(v,{type:"submit",loading:o.loading,loadingText:o.loadingText,progress:o.progress,variant:P,className:"dndev-w-full",children:N||e("form.submit",{defaultValue:"Submit"})})]})]})]})})})}var Se=ue;export{ue as EntityFormRenderer,Se as default};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ControlledFieldProps } from '../types';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* ControlledDurationField - Controlled component for duration (minutes) with preset chips + custom slider
|
|
5
|
+
*/
|
|
6
|
+
export declare function ControlledDurationField(props: ControlledFieldProps): ReactElement;
|
|
7
|
+
//# sourceMappingURL=ControlledDurationField.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ControlledDurationField.d.ts","sourceRoot":"","sources":["../../../../src/components/controlled/input/ControlledDurationField.tsx"],"names":[],"mappings":"AAgBA,OAAO,EAA0B,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAG7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE1C;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,oBAAoB,GAC1B,YAAY,CA8Bd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import{jsx as a}from"react/jsx-runtime";import{Controller as f}from"react-hook-form";import{DurationFieldComponent as p}from"../../form/fields";import{convertValidationRules as c}from"../types";function C(s){const{control:d,errors:n,fieldConfig:l,t}=s,{name:e,label:m,validation:o}=l,r=(l.options||{}).fieldSpecific;return a(f,{name:e,control:d,rules:o?c(o):void 0,render:({field:i})=>a(p,{label:t(m),value:i.value??0,onChange:u=>i.onChange(u),error:!!n[e],helperText:n[e]?.message,required:o?.required,disabled:i.disabled,min:r?.min??0,max:r?.max??480,step:r?.step??5,t})})}export{C as ControlledDurationField};
|
|
@@ -6,6 +6,7 @@ export { ControlledPriceField } from './ControlledPriceField';
|
|
|
6
6
|
export { ControlledPhoneField } from './ControlledPhoneField';
|
|
7
7
|
export { ControlledRangeField } from './ControlledRangeField';
|
|
8
8
|
export { ControlledRatingField } from './ControlledRatingField';
|
|
9
|
+
export { ControlledDurationField } from './ControlledDurationField';
|
|
9
10
|
export { ControlledSwitchField } from './ControlledSwitchField';
|
|
10
11
|
export { ControlledTextField } from './ControlledTextField';
|
|
11
12
|
export { ControlledTextareaField } from './ControlledTextareaField';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/controlled/input/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,OAAO,EAAE,qBAAqB,EAAE,MA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2B,CAAC;AAEpE,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ControlledCheckboxField as o}from"./ControlledCheckboxField";import{ControlledCurrencyField as l}from"./ControlledCurrencyField";import{ControlledNumberField as e}from"./ControlledNumberField";import{ControlledPasswordField as r}from"./ControlledPasswordField";import{ControlledPriceField as d}from"./ControlledPriceField";import{ControlledPhoneField as t}from"./ControlledPhoneField";import{ControlledRangeField as i}from"./ControlledRangeField";import{ControlledRatingField as n}from"./ControlledRatingField";import{
|
|
1
|
+
import{ControlledCheckboxField as o}from"./ControlledCheckboxField";import{ControlledCurrencyField as l}from"./ControlledCurrencyField";import{ControlledNumberField as e}from"./ControlledNumberField";import{ControlledPasswordField as r}from"./ControlledPasswordField";import{ControlledPriceField as d}from"./ControlledPriceField";import{ControlledPhoneField as t}from"./ControlledPhoneField";import{ControlledRangeField as i}from"./ControlledRangeField";import{ControlledRatingField as n}from"./ControlledRatingField";import{ControlledDurationField as a}from"./ControlledDurationField";import{ControlledSwitchField as s}from"./ControlledSwitchField";import{ControlledTextField as C}from"./ControlledTextField";import{ControlledTextareaField as m}from"./ControlledTextareaField";import{ControlledGdprConsentField as F}from"./ControlledGdprConsentField";export{o as ControlledCheckboxField,l as ControlledCurrencyField,a as ControlledDurationField,F as ControlledGdprConsentField,e as ControlledNumberField,r as ControlledPasswordField,t as ControlledPhoneField,d as ControlledPriceField,i as ControlledRangeField,n as ControlledRatingField,s as ControlledSwitchField,C as ControlledTextField,m as ControlledTextareaField};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
/** Preset durations in minutes */
|
|
3
|
+
export declare const DURATION_PRESETS: readonly [15, 30, 45, 60, 90, 120, 150, 180];
|
|
4
|
+
export interface DurationFieldComponentProps {
|
|
5
|
+
/** Label for the field */
|
|
6
|
+
label: string;
|
|
7
|
+
/** Current value in minutes */
|
|
8
|
+
value?: number;
|
|
9
|
+
/** Change handler (minutes) */
|
|
10
|
+
onChange: (value: number) => void;
|
|
11
|
+
/** Whether the field is in error state */
|
|
12
|
+
error?: boolean;
|
|
13
|
+
/** Helper text */
|
|
14
|
+
helperText?: string;
|
|
15
|
+
/** Whether the field is disabled */
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
/** Whether the field is required */
|
|
18
|
+
required?: boolean;
|
|
19
|
+
/** Read-only mode (display only) */
|
|
20
|
+
readonly?: boolean;
|
|
21
|
+
/** Min minutes for custom slider (default 0) */
|
|
22
|
+
min?: number;
|
|
23
|
+
/** Max minutes for custom slider (default 480 = 8h) */
|
|
24
|
+
max?: number;
|
|
25
|
+
/** Step for custom slider (default 5) */
|
|
26
|
+
step?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Translation function for preset labels (e.g. t('crud:duration.30m')).
|
|
29
|
+
* Receives i18n key; return value is the chip label.
|
|
30
|
+
*/
|
|
31
|
+
t?: (key: string, options?: Record<string, unknown>) => string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* DurationFieldComponent - Preset chips + Custom slider for duration (minutes)
|
|
35
|
+
*
|
|
36
|
+
* Used by the built-in entity field type `duration`.
|
|
37
|
+
*
|
|
38
|
+
* @see Entity field type: `duration` (registered in registerBuiltinFieldTypes)
|
|
39
|
+
*/
|
|
40
|
+
declare const DurationFieldComponent: ComponentType<DurationFieldComponentProps>;
|
|
41
|
+
export default DurationFieldComponent;
|
|
42
|
+
//# sourceMappingURL=DurationFieldComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DurationFieldComponent.d.ts","sourceRoot":"","sources":["../../../../src/components/form/fields/DurationFieldComponent.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,kCAAkC;AAClC,eAAO,MAAM,gBAAgB,8CAA+C,CAAC;AAE7E,MAAM,WAAW,2BAA2B;IAC1C,0BAA0B;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,+BAA+B;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,0CAA0C;IAC1C,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kBAAkB;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC;CAChE;AAoBD;;;;;;GAMG;AACH,QAAA,MAAM,sBAAsB,EAAE,aAAa,CAAC,2BAA2B,CA0HtE,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as i,jsxs as l}from"react/jsx-runtime";import{useState as T,useMemo as k}from"react";import{Clock as x}from"lucide-react";import{Label as z,Stack as s,Button as S,Slider as w}from"@donotdev/components";const f=[15,30,45,60,90,120,150,180],N={15:"duration.15m",30:"duration.30m",45:"duration.45m",60:"duration.1h",90:"duration.1h30",120:"duration.2h",150:"duration.2h30",180:"duration.3h"};function W(a,o){const n=a<60?`${a}m`:a%60===0?`${a/60}h`:`${Math.floor(a/60)}h${a%60}`,u=N[a];return!o||!u?n:o(`crud:${u}`,{defaultValue:n})??n}const j=({label:a,value:o,onChange:n,error:u,helperText:d,disabled:m,required:p,readonly:C,min:g=0,max:v=480,step:M=5,t})=>{const r=typeof o=="number"&&!Number.isNaN(o)?o:0,h=f.includes(r),[c,b]=T(!h&&r>0),V=k(()=>f.map(e=>({minutes:e,label:W(e,t)})),[t]),y=t?t("crud:duration.custom",{defaultValue:"Custom"}):"Custom";if(C){const e=r===0?t?t("crud:duration.zero",{defaultValue:"\u2014"}):"\u2014":r<60?t?t("crud:duration.minutes",{count:r,defaultValue:`${r} min`}):`${r} min`:t?t("crud:duration.hoursMinutes",{hours:Math.floor(r/60),minutes:r%60,defaultValue:`${Math.floor(r/60)}h${r%60?` ${r%60}min`:""}`}):`${Math.floor(r/60)}h${r%60?` ${r%60}m`:""}`;return l(s,{gap:"tight",children:[i(z,{required:p,style:{fontSize:"var(--font-size-sm)",fontWeight:500},children:a}),l(s,{direction:"row",gap:"tight",align:"center",children:[i(x,{size:18,style:{color:"var(--muted-foreground)"},"aria-hidden":!0}),i("span",{style:{color:"var(--muted-foreground)",fontSize:"var(--font-size-sm)"},children:e})]}),d&&i("p",{style:{fontSize:"var(--font-size-xs)",color:u?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:d})]})}return l(s,{gap:"medium",children:[i(z,{required:p,style:{fontSize:"var(--font-size-sm)",fontWeight:500},children:a}),l(s,{direction:"row",gap:"tight",align:"center",style:{flexWrap:"wrap"},children:[V.map(({minutes:e,label:$})=>l(S,{type:"button",variant:r===e?"primary":"outline",disabled:m,onClick:()=>{b(!1),n(e)},"aria-pressed":r===e,"aria-label":$,children:[i(x,{size:14,style:{marginRight:"var(--gap-xs)"},"aria-hidden":!0}),$]},e)),i(S,{type:"button",variant:c?"primary":"outline",disabled:m,onClick:()=>{b(!0),!h&&r>0?n(r):n(30)},"aria-pressed":c,"aria-label":y,children:y})]}),c&&i(s,{gap:"tight",style:{marginTop:"var(--gap-sm)"},children:i(w,{value:[h?30:r],onValueChange:([e])=>n(Math.max(g,Math.min(v,e??0))),min:g,max:v,step:M,showValue:!0,disabled:m,"aria-label":a})}),d&&i("p",{style:{fontSize:"var(--font-size-xs)",color:u?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:d})]})};var q=j;export{f as DURATION_PRESETS,q as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneNumberComponent.d.ts","sourceRoot":"","sources":["../../../../src/components/form/fields/PhoneNumberComponent.tsx"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAExD,MAAM,WAAW,yBAAyB;IACxC,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,iEAAiE;IACjE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qBAAqB;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IACzD,oBAAoB;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kBAAkB;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gDAAgD;IAChD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oCAAoC;IACpC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,4EAA4E;IAC5E,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;;;;GAMG;AACH,QAAA,MAAM,oBAAoB,EAAE,aAAa,CAAC,yBAAyB,
|
|
1
|
+
{"version":3,"file":"PhoneNumberComponent.d.ts","sourceRoot":"","sources":["../../../../src/components/form/fields/PhoneNumberComponent.tsx"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAExD,MAAM,WAAW,yBAAyB;IACxC,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,iEAAiE;IACjE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qBAAqB;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IACzD,oBAAoB;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kBAAkB;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gDAAgD;IAChD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oCAAoC;IACpC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,4EAA4E;IAC5E,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;;;;GAMG;AACH,QAAA,MAAM,oBAAoB,EAAE,aAAa,CAAC,yBAAyB,CAiQlE,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as i,jsxs as s}from"react/jsx-runtime";import{useState as A,useMemo as p,useEffect as B,useId as L}from"react";import{Input as M,FloatingLabel as k,Button as F,BUTTON_VARIANT as O,DropdownMenu as U,Stack as g,cn as _}from"@donotdev/components";import{Flag as z,COUNTRIES as y}from"@donotdev/core";const D=({label:E,value:d="",onChange:N,error:R,helperText:b,required:I=!1,disabled:v=!1,defaultCountry:x="FR",showFlags:W=!0,preferredCountries:c,countries:h})=>{const a=L(),f=p(()=>h&&h.length>0?h.map(e=>y.find(t=>t.code===e)).filter(e=>e!==void 0):Array.from(y),[h]),o=p(()=>{if(!c||c.length===0)return f;const e=c.map(r=>f.find(m=>m.code===r)).filter(r=>r!==void 0),t=f.filter(r=>!c.includes(r.code));return[...e,...t]},[f,c]),u=p(()=>o.find(e=>e.code===x)||o[0]||y[0],[x,o]),{country:C,phoneNumber:w}=p(()=>{if(!d)return{country:u,phoneNumber:""};const e=o.find(r=>d.startsWith(r.dialCode));if(e){let r=d.slice(e.dialCode.length).trim();return r.startsWith("0")&&(r=r.slice(1).trim()),r=r.replace(/\s+/g," ").trim(),{country:e,phoneNumber:r}}if(d.startsWith("+"))return{country:u,phoneNumber:d};let t=d.trim();return t.startsWith("0")&&(t=t.slice(1).trim()),t=t.replace(/\s+/g," ").trim(),{country:u,phoneNumber:t}},[d,u,o]),[n,S]=A(u);B(()=>{C.code!==n.code&&S(C)},[C,n.code]);const V=w,T=e=>{S(e);let t=V;t.startsWith("0")&&(t=t.slice(1).trim()),t=t.replace(/\s+/g," ").trim();const m={target:{value:e.dialCode+(t?" "+t:"")}};N(m)},$=e=>{let t=e.target.value;t.startsWith("0")&&(t=t.slice(1).trim()),t=t.replace(/\s+/g," ").trim();const m={target:{value:n.dialCode+(t?" "+t:"")}};N(m)},j=o.map(e=>({label:e.dialCode,onClick:()=>T(e),checked:e.code===n.code,children:W?s(g,{direction:"row",align:"center",gap:"tight",children:[i(z,{code:e.flagCode,title:e.name}),i("span",{children:e.dialCode}),i("span",{style:{color:"var(--muted-foreground)",fontSize:"var(--font-size-xs)"},children:e.name})]}):s("span",{children:[e.dialCode," ",e.name]})})),l=!!R;return s(g,{gap:"tight",children:[i(k,{htmlFor:a,label:E,disabled:v,required:I,children:s("div",{className:"dndev-relative",style:{display:"flex",gap:0},children:[i(U,{trigger:i(F,{type:"button",variant:O.OUTLINE,disabled:v,style:{minWidth:"fit-content",padding:"0 var(--gap-md)",borderRight:"none",borderTopRightRadius:0,borderBottomRightRadius:0,borderRadius:"var(--radius-md) 0 0 var(--radius-md)"},"aria-label":`Country code: ${n.dialCode}`,children:s(g,{direction:"row",align:"center",gap:"tight",children:[W&&i(z,{code:n.flagCode,title:n.name}),i("span",{children:n.dialCode})]})}),items:j,contentWidth:"16rem"}),i(M,{id:a,type:"tel",inputMode:"tel",value:V,onChange:$,disabled:v,placeholder:"6 12 34 56 78",bare:!0,"data-variant":l?"destructive":void 0,className:"dndev-flex-1",style:{borderTopLeftRadius:0,borderBottomLeftRadius:0,borderRadius:"0 var(--radius-md) var(--radius-md) 0"},"aria-describedby":_(l&&`${a}-error`,b&&!l&&`${a}-helper`),"aria-invalid":l})]})}),l&&s(g,{id:`${a}-error`,direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)",color:"var(--destructive-foreground)"},role:"alert",children:[i("span",{children:"\u26A0"}),R]}),b&&!l&&i("p",{id:`${a}-helper`,style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:b})]})};var J=D;export{J as default};
|
|
@@ -40,6 +40,9 @@ export { default as RangeFieldComponent } from './RangeFieldComponent';
|
|
|
40
40
|
export type { RangeFieldComponentProps } from './RangeFieldComponent';
|
|
41
41
|
export { default as RatingFieldComponent } from './RatingFieldComponent';
|
|
42
42
|
export type { RatingFieldComponentProps } from './RatingFieldComponent';
|
|
43
|
+
export { default as DurationFieldComponent } from './DurationFieldComponent';
|
|
44
|
+
export type { DurationFieldComponentProps } from './DurationFieldComponent';
|
|
45
|
+
export { DURATION_PRESETS } from './DurationFieldComponent';
|
|
43
46
|
export { default as PhoneNumberComponent } from './PhoneNumberComponent';
|
|
44
47
|
export type { PhoneNumberComponentProps } from './PhoneNumberComponent';
|
|
45
48
|
export { default as GeoPointFieldComponent } from './GeoPointFieldComponent';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/form/fields/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACzE,YAAY,EAAE,yBAAyB,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
-
import{default as o}from"./AvatarFieldComponent";import{default as
|
|
1
|
+
import{default as o}from"./AvatarFieldComponent";import{default as t}from"./BadgeFieldComponent";import{default as e}from"./TextFieldComponent";import{default as a}from"./NumberFieldComponent";import{default as m}from"./DateFieldComponent";import{default as n}from"./CheckboxFieldComponent";import{default as r}from"./ComboboxComponent";import{default as s}from"./DropdownComponent";import{default as p}from"./MultiDropdownComponent";import{default as i}from"./FileFieldComponent";import{default as d}from"./ImageFieldComponent";import{default as f}from"./DocumentFieldComponent";import{default as l}from"./TextAreaComponent";import{default as u}from"./SwitchFieldComponent";import{default as C}from"./RadioFieldComponent";import{default as F}from"./RangeFieldComponent";import{default as R}from"./RatingFieldComponent";import{default as T}from"./DurationFieldComponent";import{DURATION_PRESETS as x}from"./DurationFieldComponent";import{default as c}from"./PhoneNumberComponent";import{default as D}from"./GeoPointFieldComponent";import{default as P}from"./MapFieldComponent";import{default as A}from"./TimestampFieldComponent";import{default as S}from"./MultiInputTextFieldComponent";import{default as b}from"./ButtonFieldComponent";import{default as h}from"./HiddenFieldComponent";import{default as E}from"./PasswordFieldComponent";import{default as g}from"./AddressFieldComponent";import{default as w}from"./CurrencyFieldComponent";import{default as I}from"./PriceFieldComponent";import{default as M}from"./RichTextComponent";import{default as N}from"./GdprConsentFieldComponent";export{g as AddressFieldComponent,o as AvatarFieldComponent,t as BadgeFieldComponent,b as ButtonFieldComponent,n as CheckboxFieldComponent,r as ComboboxComponent,w as CurrencyFieldComponent,x as DURATION_PRESETS,m as DateFieldComponent,f as DocumentFieldComponent,s as DropdownComponent,T as DurationFieldComponent,i as FileFieldComponent,N as GdprConsentFieldComponent,D as GeoPointFieldComponent,h as HiddenFieldComponent,d as ImageFieldComponent,P as MapFieldComponent,p as MultiDropdownComponent,S as MultiInputTextFieldComponent,a as NumberFieldComponent,E as PasswordFieldComponent,c as PhoneNumberComponent,I as PriceFieldComponent,C as RadioFieldComponent,F as RangeFieldComponent,R as RatingFieldComponent,M as RichTextComponent,u as SwitchFieldComponent,l as TextAreaComponent,e as TextFieldComponent,A as TimestampFieldComponent};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEntityForm.d.ts","sourceRoot":"","sources":["../../../src/forms/hooks/useEntityForm.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"useEntityForm.d.ts","sourceRoot":"","sources":["../../../src/forms/hooks/useEntityForm.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAW7C,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EAEjB,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAC5C,MAAM,EAAE,CAAC,EACT,OAAO,GAAE,oBAAoB,CAAC,CAAC,CAAM,GACpC,gBAAgB,CAAC,CAAC,CAAC,CAmdrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{valibotResolver as
|
|
1
|
+
"use client";import{valibotResolver as C}from"@hookform/resolvers/valibot";import{useMemo as c,useEffect as R,useRef as p,useCallback as h}from"react";import{useForm as ue,useWatch as ie}from"react-hook-form";import{useLocalStorage as ce,BACKEND_GENERATED_FIELD_NAMES as le,createSchemas as fe}from"@donotdev/core";import{useFormStore as y,useFormStatus as de,useUploadProgress as me}from"../../stores";import{useUploadStore as J}from"../../stores/UploadStore";import{checkForBlobUrls as _}from"../../utils/uploadValidation";import{getFieldsForOperation as pe}from"../utils";import{buildInitialFromRecord as Se,buildSchemaDefaults as ge}from"../utils/buildInitialValues";function Pe(u,z={}){const{formId:e,operation:K,defaultValues:S,viewerRole:W,mode:q="onBlur",t:G,autoSave:l=!1}=z,P=W??"guest",o=K??(S?"edit":"create"),H=de(e??""),Q=me(e??""),b=c(()=>fe(u),[u.name]),j=c(()=>C(b.create),[b.create]),k=c(()=>C(b.draft),[b.draft]),X=c(()=>async(t,a,s)=>((t?.status??S?.status)==="draft"?k:j)(t,a,s),[j,k,S?.status]),A=c(()=>ge(u),[u]),T=S,i=c(()=>{if(o==="create")return A;if(T)return Se(u,T)},[o,A,u,T]),n=ue({defaultValues:o==="create"?i:void 0,mode:q,resolver:X,shouldUnregister:!1,shouldFocusError:!0}),O=p(n);R(()=>{O.current=n},[n]);const v=p(null);R(()=>{if(o==="edit"&&i){const t=i.id??null;t&&t!==v.current?(O.current.reset(i),v.current=t):!t&&v.current===null&&(O.current.reset(i),v.current="initialized")}},[o,i]);const Y=c(()=>`${u.name.toLowerCase()}-form-draft`,[u.name]),{value:I,setValue:N,removeValue:F}=ce(Y,{defaultValue:null,syncAcrossTabs:!0}),w=p(!1);R(()=>{!l||o!=="create"||S||w.current||(I&&n.reset(I),w.current=!0)},[l,o,S,I,n]);const f=ie({control:n.control}),D=p(!1),g=p(null),V=p(void 0),U=p(!0);R(()=>{if(U.current){U.current=!1,V.current=f?JSON.stringify(f):void 0;return}if(!l||o!=="create"||D.current||!w.current)return;const t=f?JSON.stringify(f):void 0;if(V.current!==t)return V.current=t,g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{if(!f)return;Object.values(f).some(s=>s!=null&&s!=="")&&N(f)},3e3),()=>{g.current&&clearTimeout(g.current)}},[f,l,o,N]);const $=h(async()=>{if(!e)return!0;const t=J.getState(),a=y.getState();if(!t.hasPendingUploads(e))return!0;try{a.setUploading(e,0),await t.uploadAll(e),await new Promise(m=>setTimeout(m,50));let s=n.getValues(),r=_(s),E=0;const d=5;for(;r.length>0&&E<d;)E++,await new Promise(m=>setTimeout(m,100)),s=n.getValues(),r=_(s);if(r.length>0){const m=`Upload incomplete: files still pending at ${r.join(", ")}`;return a.setError(e,m),!1}return!0}catch(s){const r=s instanceof Error?s.message:"File upload failed";return y.getState().setError(e,r),!1}},[e,n]),B=h(t=>o!=="create"?t:Object.fromEntries(Object.entries(t).filter(([a])=>!le.includes(a))),[o]),L=h(t=>{if(typeof window>"u")return;const a=Object.keys(t).find(r=>r!=="root"&&t[r]);if(!a)return;const s=document.querySelector(`input[name="${a}"][aria-invalid="true"], textarea[name="${a}"][aria-invalid="true"], select[name="${a}"][aria-invalid="true"]`);s&&(s.scrollIntoView({behavior:"smooth",block:"center"}),s.focus())},[]),x=n.handleSubmit,Z=c(()=>((t,a)=>async s=>{s?.preventDefault?.();const r=e?y.getState():null;e&&r&&r.startSubmit(e),D.current=!0;try{if(!await $()){D.current=!1;return}e&&r&&r.setValidating(e),await x(async(d,m)=>{e&&r&&r.setSubmitting(e);const ne=B(d);try{await t(ne,m),l&&o==="create"&&F(),e&&r&&r.setSuccess(e)}catch(M){const ae=M instanceof Error?M.message:"Submission failed";throw e&&r&&r.setError(e,ae),M}},d=>{e&&r&&r.setError(e,"Validation failed"),L(d),a?.(d)})(s)}finally{D.current=!1}}),[x,e,$,B,L,l,o,F]),ee=h(()=>{l&&o==="create"&&F(),n.reset(i),V.current=i?JSON.stringify(i):void 0,U.current=!0,w.current=!1},[l,o,F,n,i]),te=h(()=>{e&&(y.getState().cleanup(e),J.getState().cleanup(e))},[e]),re=c(()=>pe(u,{operation:o,viewerRole:P,availableFields:void 0}),[u,o,P]),se=G??(t=>t),oe=n.formState.isSubmitted||Object.keys(n.formState.touchedFields||{}).length>0;return{...n,handleSubmit:Z,fields:re,operation:o,entity:u,t:se,viewerRole:P,formId:e,formStatus:e?H:"idle",uploadProgress:e?Q:0,cleanup:te,isDirty:n.formState.isDirty,hasUserInteracted:oe,resetForm:ee,originalValues:i}}export{Pe as useEntityForm};
|
package/dist/forms/types.d.ts
CHANGED
|
@@ -97,9 +97,10 @@ export interface UseEntityFormOptions<E extends Entity> {
|
|
|
97
97
|
/**
|
|
98
98
|
* Viewer role for editability checks.
|
|
99
99
|
* Determines which fields render as inputs vs read-only.
|
|
100
|
-
*
|
|
100
|
+
* If not provided, defaults to 'guest' (most restrictive)
|
|
101
|
+
* @default 'guest'
|
|
101
102
|
*/
|
|
102
|
-
viewerRole?:
|
|
103
|
+
viewerRole?: string;
|
|
103
104
|
/**
|
|
104
105
|
* React Hook Form mode.
|
|
105
106
|
* @default 'onSubmit'
|
|
@@ -150,8 +151,9 @@ export interface EntityFormReturn<E extends Entity> extends UseFormReturn<InferE
|
|
|
150
151
|
t: (key: string, options?: Record<string, unknown>) => string;
|
|
151
152
|
/**
|
|
152
153
|
* Current viewer role.
|
|
154
|
+
* Always has a value (defaults to 'guest' if not provided).
|
|
153
155
|
*/
|
|
154
|
-
viewerRole:
|
|
156
|
+
viewerRole: string;
|
|
155
157
|
/**
|
|
156
158
|
* Form ID for state tracking.
|
|
157
159
|
* Undefined if not provided in options.
|
|
@@ -176,6 +178,12 @@ export interface EntityFormReturn<E extends Entity> extends UseFormReturn<InferE
|
|
|
176
178
|
* True if any field value differs from original/default values.
|
|
177
179
|
*/
|
|
178
180
|
isDirty: boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Whether the user has interacted with the form.
|
|
183
|
+
* True if any field has been touched or the form has been submitted.
|
|
184
|
+
* Used to gate navigation blocking so we don't warn on untouched forms.
|
|
185
|
+
*/
|
|
186
|
+
hasUserInteracted: boolean;
|
|
179
187
|
/**
|
|
180
188
|
* Reset form to original values and clear any saved draft.
|
|
181
189
|
* Use this for "Cancel" button functionality.
|
|
@@ -183,7 +191,8 @@ export interface EntityFormReturn<E extends Entity> extends UseFormReturn<InferE
|
|
|
183
191
|
resetForm: () => void;
|
|
184
192
|
/**
|
|
185
193
|
* Original values the form was initialized with.
|
|
186
|
-
*
|
|
194
|
+
* For create mode: schema-based defaults.
|
|
195
|
+
* For edit mode: schema defaults overlaid with the DB record.
|
|
187
196
|
*/
|
|
188
197
|
originalValues: Partial<InferEntityData<E>> | undefined;
|
|
189
198
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/forms/types.ts"],"names":[],"mappings":"AAEA;;;;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UAAU,EAAE,UAAU,CAAC;IAEvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,OAAO,EAAE,MAAM,IAAI,CAAC;IAEpB;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;;;OAIG;IACH,iBAAiB,EAAE,OAAO,CAAC;IAE3B;;;OAGG;IACH,SAAS,EAAE,MAAM,IAAI,CAAC;IAEtB;;;;OAIG;IACH,cAAc,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;CACzD;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,iBAAiB,CAChC,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,eAAe,CAAC,CAAC,CAAC;IAElC;;OAEG;IACH,KAAK,EAAE,qBAAqB,CAC1B,eAAe,CAAC,CAAC,CAAC,EAClB,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAC9B,CAAC;IAEF;;OAEG;IACH,IAAI,EAAE;QACJ,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;QAC1B,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IAEF;;OAEG;IACH,MAAM,EAAE,WAAW,CAAC;IAEpB;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,SAAS,EAAE,OAAO,CAAC;CACpB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Initial values builders for CRUD forms
|
|
3
|
+
* @description
|
|
4
|
+
* - buildSchemaDefaults: compute create-mode defaults from entity definition only.
|
|
5
|
+
* - buildInitialFromRecord: overlay schema defaults with an existing DB record
|
|
6
|
+
* and apply type-specific normalizations (switch, price, etc.).
|
|
7
|
+
*
|
|
8
|
+
* These helpers provide a single, canonical "initialValues" snapshot that
|
|
9
|
+
* React Hook Form can use as its dirty baseline.
|
|
10
|
+
*/
|
|
11
|
+
import type { Entity } from '@donotdev/core';
|
|
12
|
+
import type { InferEntityData } from '../types';
|
|
13
|
+
/**
|
|
14
|
+
* Build initial values for an existing DB record.
|
|
15
|
+
*
|
|
16
|
+
* - Starts from the raw record (already filtered/masked by the backend).
|
|
17
|
+
* - For each field in the entity:
|
|
18
|
+
* - If the record has a non-null, non-undefined value, keep it.
|
|
19
|
+
* - Otherwise, apply the same type-specific defaults we use in forms.
|
|
20
|
+
*/
|
|
21
|
+
export declare function buildInitialFromRecord<E extends Entity>(entity: E, record: Partial<InferEntityData<E>>): Partial<InferEntityData<E>>;
|
|
22
|
+
/**
|
|
23
|
+
* Build schema defaults for create-mode forms.
|
|
24
|
+
*
|
|
25
|
+
* - Starts from an empty record and applies the same type-specific defaults as
|
|
26
|
+
* buildInitialFromRecord.
|
|
27
|
+
* - This represents "what a brand-new object would look like" before any user edits.
|
|
28
|
+
*/
|
|
29
|
+
export declare function buildSchemaDefaults<E extends Entity>(entity: E): Partial<InferEntityData<E>>;
|
|
30
|
+
//# sourceMappingURL=buildInitialValues.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildInitialValues.d.ts","sourceRoot":"","sources":["../../../src/forms/utils/buildInitialValues.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,EACrD,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,GAClC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAwD7B;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,EAClD,MAAM,EAAE,CAAC,GACR,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAG7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function y(s,r){const n=r??{},e={...n};return Object.entries(s.fields).forEach(([c,t])=>{const u=e[c],p=!(c in n)||u===null||u===void 0;if(t.type==="switch"){if(u==null){const a=t.options?.fieldSpecific;e[c]=a?.uncheckedValue??!1}}else p&&(t.type==="price"?e[c]={amount:0,currency:"EUR",vatIncluded:!0,discountPercent:0}:t.type==="checkbox"||t.type==="boolean"?e[c]=!1:t.type==="text"||t.type==="textarea"||t.type==="email"||t.type==="url"||t.type==="tel"||t.type==="iban"||t.type==="password"||t.type==="color"?e[c]="":(t.type==="number"||t.type==="range"||t.type==="rating")&&(e[c]=void 0))}),e}function o(s){return y(s,{})}export{y as buildInitialFromRecord,o as buildSchemaDefaults};
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
import type { Entity, EntityField, FieldType } from '@donotdev/core';
|
|
10
10
|
/** Entity fields input - supports Entity, Entity['fields'], or plain Record */
|
|
11
11
|
export type EntityFieldsInput = Entity | Entity['fields'] | Record<string, EntityField<FieldType>>;
|
|
12
|
-
import type { ViewerRole } from './isFieldEditable';
|
|
13
12
|
/** Field with computed editability for rendering */
|
|
14
13
|
export interface RenderableField<T extends FieldType = FieldType> {
|
|
15
14
|
/** Field name/key */
|
|
@@ -23,8 +22,8 @@ export interface RenderableField<T extends FieldType = FieldType> {
|
|
|
23
22
|
export interface GetFieldsForOperationOptions {
|
|
24
23
|
/** Form operation type */
|
|
25
24
|
operation: 'create' | 'edit';
|
|
26
|
-
/** Viewer role for editability checks */
|
|
27
|
-
viewerRole?:
|
|
25
|
+
/** Viewer role for editability checks (defaults to 'guest' if undefined) */
|
|
26
|
+
viewerRole?: string;
|
|
28
27
|
/**
|
|
29
28
|
* Available field names (for edit mode).
|
|
30
29
|
* When provided, only fields in this list are returned.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFieldsForOperation.d.ts","sourceRoot":"","sources":["../../../src/forms/utils/getFieldsForOperation.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"getFieldsForOperation.d.ts","sourceRoot":"","sources":["../../../src/forms/utils/getFieldsForOperation.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGrE,+EAA+E;AAC/E,MAAM,MAAM,iBAAiB,GACzB,MAAM,GACN,MAAM,CAAC,QAAQ,CAAC,GAChB,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC;AAI3C,oDAAoD;AACpD,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IAC9D,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IACvB,qDAAqD;IACrD,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,kCAAkC;AAClC,MAAM,WAAW,4BAA4B;IAC3C,0BAA0B;IAC1B,SAAS,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC7B,4EAA4E;IAC5E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,iBAAiB,EACzB,OAAO,EAAE,4BAA4B,GACpC,eAAe,EAAE,CAmDnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{isFieldVisible as u}from"@donotdev/core";import{isFieldEditable as m}from"./isFieldEditable";function g(i,d){const{operation:e,viewerRole:r,availableFields:l}=d,n=r??"guest",f=i&&typeof i=="object"&&"fields"in i&&"name"in i?i.fields:i,b=Object.entries(f),s=[];for(const[a,p]of b){const t=p,o=t.visibility||"guest";if(!u(o,n)||e==="create"&&o==="technical"||e==="edit"&&l&&!l.includes(a))continue;let c=m(t.editable,n,e);e==="edit"&&o==="technical"&&t.editable===void 0&&(c=!1),s.push({name:a,config:t,editable:c})}return s}export{g as getFieldsForOperation};
|
|
@@ -31,5 +31,5 @@ export type ViewerRole = 'public' | 'guest' | 'user' | 'admin' | 'super';
|
|
|
31
31
|
* @since 0.0.1
|
|
32
32
|
* @author AMBROISE PARK Consulting
|
|
33
33
|
*/
|
|
34
|
-
export declare function isFieldEditable(editable: Editable | undefined, viewerRole:
|
|
34
|
+
export declare function isFieldEditable(editable: Editable | undefined, viewerRole: string, operation: 'create' | 'edit'): boolean;
|
|
35
35
|
//# sourceMappingURL=isFieldEditable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isFieldEditable.d.ts","sourceRoot":"","sources":["../../../src/forms/utils/isFieldEditable.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,qDAAqD;AACrD,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,QAAQ,GAAG,SAAS,EAC9B,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"isFieldEditable.d.ts","sourceRoot":"","sources":["../../../src/forms/utils/isFieldEditable.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,qDAAqD;AACrD,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,QAAQ,GAAG,SAAS,EAC9B,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,QAAQ,GAAG,MAAM,GAC3B,OAAO,CAcT"}
|
|
@@ -12,19 +12,25 @@ import type { EntityField, FieldType } from '@donotdev/core';
|
|
|
12
12
|
* Translates a label string with namespace support.
|
|
13
13
|
* Used for translating option labels, field labels, or any label string.
|
|
14
14
|
*
|
|
15
|
-
* Supports namespace:key syntax (e.g., "
|
|
15
|
+
* Supports namespace:key syntax (e.g., "crud:status.draft")
|
|
16
|
+
*
|
|
17
|
+
* **Translation Fallback Order (for status labels):**
|
|
18
|
+
* 1. Entity namespace (`entity-{name}`) - User overrides take priority
|
|
19
|
+
* 2. CRUD namespace (`crud`) - Framework defaults
|
|
20
|
+
*
|
|
21
|
+
* No dndev fallback - CRUD is optional and shouldn't pollute core framework namespace.
|
|
16
22
|
*
|
|
17
23
|
* @param label - Label string to translate (may include namespace:key syntax)
|
|
18
|
-
* @param t - Translation function from useTranslation hook
|
|
24
|
+
* @param t - Translation function from useTranslation hook (should be from multi-namespace hook like [entity.namespace, 'crud'])
|
|
19
25
|
* @returns Translated label string
|
|
20
26
|
*
|
|
21
27
|
* @example
|
|
22
28
|
* ```typescript
|
|
23
|
-
* translateLabel('
|
|
24
|
-
* translateLabel('make', t); // Translates "make" in current namespace
|
|
29
|
+
* translateLabel('crud:status.draft', t); // Tries entity namespace first, then crud
|
|
30
|
+
* translateLabel('make', t); // Translates "make" in current namespace (entity or crud)
|
|
25
31
|
* ```
|
|
26
32
|
*
|
|
27
|
-
* @version 0.0.
|
|
33
|
+
* @version 0.0.4
|
|
28
34
|
* @since 0.0.1
|
|
29
35
|
* @author AMBROISE PARK Consulting
|
|
30
36
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translateFieldLabel.d.ts","sourceRoot":"","sources":["../../../src/forms/utils/translateFieldLabel.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE7D
|
|
1
|
+
{"version":3,"file":"translateFieldLabel.d.ts","sourceRoot":"","sources":["../../../src/forms/utils/translateFieldLabel.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,GACxD,MAAM,CA6BR;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EACjE,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS,EAClC,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,GACxD,MAAM,CAGR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function a(n,s){if(typeof n=="string"&&n.includes(":")){const r=n.split(":"),t=r[1]??n,e=r[0];if(t.startsWith("status.")){const i=s(t);return i!==t&&i!==`${e}:${t}`?i:s(t,{ns:e})}return s(t,{ns:e})}return s(n)}function o(n,s,r){const t=s?.label||n;return a(t,r)}export{o as translateFieldLabel,a as translateLabel};
|