@donotdev/crud 0.0.11 → 0.0.13

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.
@@ -1 +1 @@
1
- {"version":3,"file":"EntityFilters.d.ts","sourceRoot":"","sources":["../../src/components/EntityFilters.tsx"],"names":[],"mappings":"AAuDA,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;AAoOD,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,GA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,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,kDAwjBvB"}
@@ -1 +1 @@
1
- "use client";import{jsx as g,jsxs as R}from"react/jsx-runtime";import{useMemo as B,useState as Q}from"react";import{FilterX as U}from"lucide-react";import{Button as j,Calendar as Z,Combobox as V,Grid as ee,Popover as te,RangeInput as ne,Slider as re,Stack as z,Text as X}from"@donotdev/components";import{useTranslation as q,handleError as N}from"@donotdev/core";import{translateFieldLabel as ie,translateLabel as H}from"../forms/utils";import{getFilterType as W,isFilterable as se}from"../fieldTypeRegistry";function oe(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,S=s==="price",u=S&&e!=null&&typeof e=="object"?Number(e.amount):F&&e!=null?typeof e=="number"?e:Number(e):NaN;if(F||S){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 x=e instanceof Date?e:new Date(e);return isNaN(x.getTime())?!1:x>=new Date(t.min)}if(!d&&y){if(e==null)return!0;const x=e instanceof Date?e:new Date(e);return isNaN(x.getTime())?!1:x<=new Date(t.max)}if(d&&y){if(e==null)return!1;const x=e instanceof Date?e:new Date(e);return isNaN(x.getTime())?!1:x>=new Date(t.min)&&x<=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 ae(e,t,s){if(!e&&!t)return s??"From \u2013 To";const h=e?new Date(e+"T00:00:00").toLocaleDateString(void 0,{day:"numeric",month:"short",year:"numeric"}):"",l=t?new Date(t+"T00:00:00").toLocaleDateString(void 0,{day:"numeric",month:"short",year:"numeric"}):"";return h&&l?`${h} \u2013 ${l}`:h?`${h} \u2013 \u2026`:l?`\u2026 \u2013 ${l}`:s??"From \u2013 To"}function le({label:e,rangeFilter:t,onRangeChange:s,onClear:h,tCrud:l}){const[C,F]=Q(!1),S=!!(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 b=a.from?a.from.toISOString().split("T")[0]:"",O=a.to?a.to.toISOString().split("T")[0]:"";s(b,O),a.from&&a.to&&F(!1)},y=(a,b)=>{s(a,b),F(!1)},x=()=>{h(),F(!1)},E=ae(t.min,t.max,l("filter.fromTo",{defaultValue:"From \u2013 To"}));return g(te,{open:C,onOpenChange:F,trigger:g(j,{variant:"outline",display:"compact",className:"dndev-w-full dndev-justify-between","aria-haspopup":"dialog","aria-expanded":C,"aria-label":e,children:R(X,{as:"span",level:"small",variant:S?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,b=new Date(a);b.setDate(a.getDate()-a.getDay());const O=new Date(b);O.setDate(b.getDate()+6),y(b.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,b=new Date(a.getFullYear(),a.getMonth(),1),O=new Date(a.getFullYear(),a.getMonth()+1,0);y(b.toISOString().split("T")[0],O.toISOString().split("T")[0])},children:l("filter.thisMonth",{defaultValue:"This Month"})})]}),g(Z,{mode:"range",selected:u,onSelect:d,defaultMonth:u?.from??u?.to??new Date}),g(j,{variant:"ghost",display:"compact",onClick:x,children:l("filter.clearDate",{defaultValue:"Clear"})})]})})}function he({entity:e,data:t,filters:s,onFiltersChange:h,fieldsToFilter:l,variant:C="inline"}){const F=C==="sidebar",{t:S}=q("crud"),{t:u}=q(e.namespace),d=B(()=>(l&&l.length>0?l:e.listFields||Object.keys(e.fields)).filter(n=>{const o=e.fields[n]?.type||"text";return se(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 oe(A,v,p)}))}),r},[t,s,e.fields,d]),x=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(L=>L.getTime()))),T=new Date(Math.max(...p.map(L=>L.getTime()))),G=i.toISOString().split("T")[0],I=T.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({})},b=B(()=>d.length===0?null:d.map(r=>{const n=e.fields[r];if(!n)return null;const m=ie(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],T=typeof p=="object"&&p!==null&&"min"in p?p:{min:"",max:""};if(A){const f=x[r],D=f?.min??0,c=f?.max??100,M=T.min?Number(T.min):D,_=T.max?Number(T.max):c;return R(z,{gap:"tight",style:{gridColumn:"span 2",gridRow:F?void 0:"span 2"},children:[g(ne,{type:"number",label:m,minPlaceholder:S("filter.min",{defaultValue:"Min"}),maxPlaceholder:S("filter.max",{defaultValue:"Max"}),minValue:T.min||"",maxValue:T.max||"",actualMin:D,actualMax:c,onChange:($,K)=>{E(r,{min:$,max:K})},onClear:()=>E(r,void 0)}),g(re,{value:[M,_],min:D,max:c,step:1,onValueChange:$=>{E(r,{min:String($[0]),max:String($[1])})}})]},r)}if(v)return g("div",{style:{gridColumn:"span 2",gridRow:F?void 0:"span 1"},children:g(le,{label:m,rangeFilter:T,onRangeChange:(f,D)=>E(r,{min:f,max:D}),onClear:()=>E(r,void 0),tCrud:S})},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():[]:[],L=y[r]||t,Y=new Set;L.forEach(f=>{const D=f[r];D!=null&&Y.add(String(D))});const P=[{value:"all",label:S("filter.selectPlaceholder",{defaultValue:"All"})}];if(I.length>0){const f=[],D=[];I.forEach(c=>{const M=typeof c=="string"?c:c.value,_=typeof c=="string"?c:c.label;Y.has(M)?f.push({value:M,label:_}):D.push({value:M,label:_})}),f.sort((c,M)=>c.label.localeCompare(M.label)),D.sort((c,M)=>c.label.localeCompare(M.label)),f.forEach(c=>{P.push({value:c.value,label:H(c.label,u),disabled:!1})}),D.forEach(c=>{P.push({value:c.value,label:H(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(V,{label:m,value:typeof p=="string"?p:void 0,onValueChange:f=>{E(r,f==="all"||!f?"":String(f))},options:P,placeholder:S("filter.placeholder",{defaultValue:"Filter..."}),clearable:!0})},r)}),[d,e.fields,t,s,u,S,y]);if(!b||b.length===0)return null;const O=b.filter(Boolean),J=Object.keys(s).length>0;return R(ee,{cols:C==="sidebar"?2:[2,4,6,8],gap:"medium",style:{gridAutoRows:"min-content"},children:[O,g(j,{variant:"outline",icon:g(U,{size:18}),onClick:a,disabled:!J,style:{gridColumn:"1 / -1",gridRow:"span 1"},children:S("filter.clear",{defaultValue:"Clear Filters"})})]})}export{he as EntityFilters,oe as matchesFilter};
1
+ "use client";import{jsx as g,jsxs as I}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:I(X,{as:"span",level:"small",variant:D?void 0:"muted",children:[e,": ",E]})}),children:I(z,{gap:"medium",style:{padding:"var(--gap-md)"},children:[g(X,{as:"span",level:"small",variant:"muted",children:e}),I(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 k=o[w],p=e.fields[w]?.type||"text";return ae(k,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"),k=w==="range"&&!v,A=o==="price";if(k||A){const p=t.map(i=>i[n]).filter(i=>i!=null&&i!=="").map(i=>A&&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],R=M.toISOString().split("T")[0];r[n]={min:G||"",max:R||""}}}}),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"),k=w==="range"&&!v,A=w==="select",p=s[r],M=typeof p=="object"&&p!==null&&"min"in p?p:{min:"",max:""};if(k){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 I(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 R=A&&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(R.length>0){const f=[],S=[];R.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 I(te,{cols:C==="sidebar"?2:[2,4,6,8],gap:"medium",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,MAA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ACjB,UAAU,EACV,SAA6C,EAC7C,QAAiC,EACjC,MAAM,EAAE,cAAc,EACtB,UAAU,EACV,QAAQ,EACR,oBAA2B,EAC3B,qBAAqB,GACtB,EAAE,uBAAuB,CAAC,CAAC,CAAC,2CAkP5B;AAED,eAAe,kBAAkB,CAAC"}
@@ -1 +1 @@
1
- "use client";import{jsx as r,jsxs as f}from"react/jsx-runtime";import{useEffect as T,useId as Q,useMemo as p}from"react";import{FormProvider as X}from"react-hook-form";import{Button as v,Stack as Z,Spinner as ee}from"@donotdev/components";import{useTranslation as I}from"@donotdev/core";import{DisplayFieldRenderer as re}from"./DisplayFieldRenderer";import{FormFieldRenderer as oe}from"./FormFieldRenderer";import{UploadProvider as te}from"../contexts/UploadContext";import{useEntityForm as ne}from"../forms/hooks/useEntityForm";import{useUnsavedChangesWarning as ae,useConfirmNavigation as ie}from"../hooks/useUnsavedChangesWarning";import{useFormStore as se}from"../stores";function de({entity:u,onSubmit:V,t:k,className:D="",submitText:N,loading:j=!1,defaultValues:s,submitVariant:P="primary",secondaryButtonText:m,secondaryButtonVariant:E="outline",onSecondarySubmit:h,viewerRole:L,operation:c=s?"edit":"create",autoSave:R=c==="create",formId:U,cancelText:b,onCancel:$,warnOnUnsavedChanges:B=!0,unsavedChangesMessage:d}){const M=Q(),n=U??`entity-form-${u.name}-${M}`,{t:Y}=I(u.namespace),{t:e}=I("crud"),g=k||Y,y=ne(u,{formId:n,operation:c,defaultValues:s,viewerRole:L,t:g,autoSave:R}),{control:_,handleSubmit:x,formState:{errors:z},fields:A,formStatus:l,uploadProgress:a,cleanup:C,isDirty:i,resetForm:W}=y;T(()=>{n&&se.getState().setIsDirty(n,i)},[n,i]),T(()=>C,[C]);const q=p(()=>d||e("messages.unsavedChangesLeave",{defaultValue:"You have unsaved changes. Are you sure you want to leave?"}),[d,e]),G=p(()=>d||e("messages.unsavedChangesDiscard",{defaultValue:"You have unsaved changes. Discard them?"}),[d,e]);ae({isDirty:i,enabled:B,message:q});const H=ie(i,G),J=async()=>{i&&!await H()||(W(),$?.())},F=b!==null,S=b??e("form.cancel",{defaultValue:"Cancel"}),K=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(X,{...y,children:r(te,{formId:n,children:f("div",{style:{position:"relative",width:"100%",gridColumn:"1 / -1",display:"contents"},children:[K&&r(ee,{overlay:!0}),f("form",{onSubmit:x(V),noValidate:!0,className:D,style:{width:"100%",gridColumn:"1 / -1",display:"contents"},children:[A.map(({name:t,config:w,editable:O})=>O?r(oe,{name:t,config:w,control:_,errors:z,t:g},t):r(re,{name:t,config:w,value:s?.[t],t:g},t)),f(Z,{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:J,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:E,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 Ce=de;export{de as EntityFormRenderer,Ce as default};
1
+ "use client";import{jsx as r,jsxs as 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};
@@ -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,CAiOlE,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
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 t,jsxs as s}from"react/jsx-runtime";import{useState as B,useMemo as f,useEffect as L,useId as M}from"react";import{Input as W,FloatingLabel as k,Button as F,BUTTON_VARIANT as O,DropdownMenu as U,Stack as p,cn as _}from"@donotdev/components";import{Flag as I,COUNTRIES as N}from"@donotdev/core";const D=({label:V,value:o="",onChange:R,error:x,helperText:g,required:w=!1,disabled:b=!1,defaultCountry:S="FR",showFlags:z=!0,preferredCountries:c,countries:h})=>{const i=M(),m=f(()=>h&&h.length>0?h.map(e=>N.find(r=>r.code===e)).filter(e=>e!==void 0):Array.from(N),[h]),a=f(()=>{if(!c||c.length===0)return m;const e=c.map(d=>m.find(y=>y.code===d)).filter(d=>d!==void 0),r=m.filter(d=>!c.includes(d.code));return[...e,...r]},[m,c]),u=f(()=>a.find(e=>e.code===S)||a[0]||N[0],[S,a]),{country:v,phoneNumber:T}=f(()=>{if(!o)return{country:u,phoneNumber:""};const e=a.find(r=>o.startsWith(r.dialCode));return e?{country:e,phoneNumber:o.slice(e.dialCode.length).trim()}:o.startsWith("+")?{country:u,phoneNumber:o}:{country:u,phoneNumber:o}},[o,u,a]),[n,E]=B(u);L(()=>{v.code!==n.code&&E(v)},[v,n.code]);const C=T,$=e=>{E(e);const d={target:{value:e.dialCode+(C?" "+C:"")}};R(d)},j=e=>{const r=e.target.value,y={target:{value:n.dialCode+(r?" "+r:"")}};R(y)},A=a.map(e=>({label:e.dialCode,onClick:()=>$(e),checked:e.code===n.code,children:z?s(p,{direction:"row",align:"center",gap:"tight",children:[t(I,{code:e.flagCode,title:e.name}),t("span",{children:e.dialCode}),t("span",{style:{color:"var(--muted-foreground)",fontSize:"var(--font-size-xs)"},children:e.name})]}):s("span",{children:[e.dialCode," ",e.name]})})),l=!!x;return s(p,{gap:"tight",children:[t(k,{htmlFor:i,label:V,disabled:b,required:w,children:s("div",{className:"dndev-relative",style:{display:"flex",gap:0},children:[t(U,{trigger:t(F,{type:"button",variant:O.OUTLINE,disabled:b,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(p,{direction:"row",align:"center",gap:"tight",children:[z&&t(I,{code:n.flagCode,title:n.name}),t("span",{children:n.dialCode})]})}),items:A,contentWidth:"16rem"}),t(W,{id:i,type:"tel",inputMode:"tel",value:C,onChange:j,disabled:b,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&&`${i}-error`,g&&!l&&`${i}-helper`),"aria-invalid":l})]})}),l&&s(p,{id:`${i}-error`,direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)",color:"var(--destructive-foreground)"},role:"alert",children:[t("span",{children:"\u26A0"}),x]}),g&&!l&&t("p",{id:`${i}-helper`,style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:g})]})};var J=D;export{J as default};
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};
@@ -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;AAO7C,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,CAyerB"}
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 z}from"@hookform/resolvers/valibot";import{useMemo as p,useEffect as U,useRef as S,useCallback as y}from"react";import{useForm as re,useWatch as se}from"react-hook-form";import{useLocalStorage as ne,BACKEND_GENERATED_FIELD_NAMES as oe,createSchemas as ae}from"@donotdev/core";import{useFormStore as F,useFormStatus as ue,useUploadProgress as ce}from"../../stores";import{useUploadStore as B}from"../../stores/UploadStore";import{checkForBlobUrls as L}from"../../utils/uploadValidation";import{getFieldsForOperation as ie}from"../utils";function ve(i,J={}){const{formId:r,operation:_,defaultValues:c,viewerRole:K,mode:W="onBlur",t:q,autoSave:d=!1}=J,R=K??"guest",o=_??(c?"edit":"create"),G=ue(r??""),H=ce(r??""),g=p(()=>ae(i),[i.name]),I=p(()=>z(g.create),[g.create]),k=p(()=>z(g.draft),[g.draft]),Q=p(()=>async(t,n,e)=>((t?.status??c?.status)==="draft"?k:I)(t,n,e),[I,k,c?.status]),u=p(()=>{if(!c)return c;const t={...c};return Object.entries(i.fields).forEach(([n,e])=>{const s=t[n],l=!(n in c)||s===null||s===void 0;if(e.type==="switch"){if(s==null){const f=e.options?.fieldSpecific;t[n]=f?.uncheckedValue??!1}}else l&&(e.type==="price"?t[n]={amount:0,currency:"EUR",vatIncluded:!0,discountPercent:0}:e.type==="checkbox"||e.type==="boolean"?t[n]=!1:e.type==="text"||e.type==="textarea"||e.type==="email"||e.type==="url"||e.type==="tel"||e.type==="password"||e.type==="color"?t[n]="":(e.type==="number"||e.type==="range"||e.type==="rating")&&(t[n]=void 0))}),t},[c,i.fields]),a=re({defaultValues:u,mode:W,resolver:Q,shouldUnregister:!1,shouldFocusError:!0}),v=S(null);U(()=>{if(o==="edit"&&u){const t=u.id??null;t&&t!==v.current?(a.reset(u),v.current=t):!t&&v.current===null&&(a.reset(u),v.current="initialized")}},[o,u,a]);const X=p(()=>`${i.name.toLowerCase()}-form-draft`,[i.name]),{value:P,setValue:M,removeValue:w}=ne(X,{defaultValue:null,syncAcrossTabs:!0}),E=S(!1);U(()=>{!d||o!=="create"||c||E.current||(P&&a.reset(P),E.current=!0)},[d,o,c,P,a]);const m=se({control:a.control}),V=S(!1),h=S(null),D=S(void 0),T=S(!0);U(()=>{if(T.current){T.current=!1,D.current=m?JSON.stringify(m):void 0;return}if(!d||o!=="create"||V.current||!E.current)return;const t=m?JSON.stringify(m):void 0;if(D.current!==t)return D.current=t,h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{if(!m)return;Object.values(m).some(e=>e!=null&&e!=="")&&M(m)},3e3),()=>{h.current&&clearTimeout(h.current)}},[m,d,o,M]);const j=y(async()=>{if(!r)return!0;const t=B.getState(),n=F.getState();if(!t.hasPendingUploads(r))return!0;try{n.setUploading(r,0),await t.uploadAll(r),await new Promise(f=>setTimeout(f,50));let e=a.getValues(),s=L(e),b=0;const l=5;for(;s.length>0&&b<l;)b++,await new Promise(f=>setTimeout(f,100)),e=a.getValues(),s=L(e);if(s.length>0){const f=`Upload incomplete: files still pending at ${s.join(", ")}`;return n.setError(r,f),!1}return!0}catch(e){const s=e instanceof Error?e.message:"File upload failed";return F.getState().setError(r,s),!1}},[r,a]),x=y(t=>o!=="create"?t:Object.fromEntries(Object.entries(t).filter(([n])=>!oe.includes(n))),[o]),A=y(t=>{if(typeof window>"u")return;const n=Object.keys(t).find(s=>s!=="root"&&t[s]);if(!n)return;const e=document.querySelector(`input[name="${n}"][aria-invalid="true"], textarea[name="${n}"][aria-invalid="true"], select[name="${n}"][aria-invalid="true"]`);e&&(e.scrollIntoView({behavior:"smooth",block:"center"}),e.focus())},[]),$=a.handleSubmit,Y=p(()=>((t,n)=>async e=>{e?.preventDefault?.();const s=r?F.getState():null;r&&s&&s.startSubmit(r),V.current=!0;try{if(!await j()){V.current=!1;return}r&&s&&s.setValidating(r),await $(async(l,f)=>{r&&s&&s.setSubmitting(r);const ee=x(l);try{await t(ee,f),d&&o==="create"&&w(),r&&s&&s.setSuccess(r)}catch(O){const te=O instanceof Error?O.message:"Submission failed";throw r&&s&&s.setError(r,te),O}},l=>{r&&s&&s.setError(r,"Validation failed"),A(l),n?.(l)})(e)}finally{V.current=!1}}),[$,r,j,x,A,d,o,w]),Z=y(()=>{d&&o==="create"&&w(),a.reset(u),D.current=u?JSON.stringify(u):void 0,T.current=!0,E.current=!1},[d,o,w,a,u]),N=y(()=>{r&&(F.getState().cleanup(r),B.getState().cleanup(r))},[r]),C=p(()=>ie(i,{operation:o,viewerRole:R,availableFields:void 0}),[i,o,R]);return{...a,handleSubmit:Y,fields:C,operation:o,entity:i,t:q??(t=>t),viewerRole:R,formId:r,formStatus:r?G:"idle",uploadProgress:r?H:0,cleanup:N,isDirty:a.formState.isDirty,resetForm:Z,originalValues:u}}export{ve as useEntityForm};
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};
@@ -178,6 +178,12 @@ export interface EntityFormReturn<E extends Entity> extends UseFormReturn<InferE
178
178
  * True if any field value differs from original/default values.
179
179
  */
180
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;
181
187
  /**
182
188
  * Reset form to original values and clear any saved draft.
183
189
  * Use this for "Cancel" button functionality.
@@ -185,7 +191,8 @@ export interface EntityFormReturn<E extends Entity> extends UseFormReturn<InferE
185
191
  resetForm: () => void;
186
192
  /**
187
193
  * Original values the form was initialized with.
188
- * Undefined for create mode, the defaultValues for edit mode.
194
+ * For create mode: schema-based defaults.
195
+ * For edit mode: schema defaults overlaid with the DB record.
189
196
  */
190
197
  originalValues: Partial<InferEntityData<E>> | undefined;
191
198
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/forms/types.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,MAAM,EACN,WAAW,EACX,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,QAAQ,EACR,eAAe,EACf,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,KAAK,EACV,aAAa,EAUb,qBAAqB,EACrB,SAAS,EACV,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EACV,MAAM,EACN,WAAW,EACX,SAAS,EACT,UAAU,EACV,QAAQ,EACR,eAAe,EACf,WAAW,EACX,eAAe,EACf,UAAU,GACX,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,MAAM,IAAI;KAC7C,CAAC,IAAI,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS;QAAE,IAAI,EAAE,MAAM,CAAC,CAAA;KAAE,GAC9D,CAAC,SAAS,SAAS,GACjB,CAAC,SAAS,MAAM,gBAAgB,GAC9B,gBAAgB,CAAC,CAAC,CAAC,GACnB,OAAO,GACT,OAAO,GACT,OAAO;CACZ,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,gBAAgB,CAAC,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,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};
@@ -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., "common:actions.save")
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('common:status', t); // Translates "status" from "common" namespace
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.1
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;;;;;;;;;;;;;;;;;;;GAmBG;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,CAWR;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
+ {"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 o(t,n){if(typeof t=="string"&&t.includes(":")){const e=t.split(":"),r=e[1]??t,s=e[0];return n(r,{ns:s})}return n(t)}function c(t,n,e){const r=n?.label||t;return o(r,e)}export{c as translateFieldLabel,o as translateLabel};
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};
@@ -1 +1 @@
1
- {"version":3,"file":"registerBuiltinFieldTypes.d.ts","sourceRoot":"","sources":["../src/registerBuiltinFieldTypes.tsx"],"names":[],"mappings":"AA6vBA;;;GAGG;AACH,wBAAgB,4BAA4B,IAAI,IAAI,CA8qBnD"}
1
+ {"version":3,"file":"registerBuiltinFieldTypes.d.ts","sourceRoot":"","sources":["../src/registerBuiltinFieldTypes.tsx"],"names":[],"mappings":"AAk1BA;;;GAGG;AACH,wBAAgB,4BAA4B,IAAI,IAAI,CA6sBnD"}
@@ -1 +1 @@
1
- "use client";import{jsx as p,jsxs as f}from"react/jsx-runtime";import{Text as y,Stack as b,ImageGallery as D,Rating as $}from"@donotdev/components";import{formatCurrency as C}from"@donotdev/core";import{ControlledCheckboxField as V,ControlledComboboxField as I,ControlledDateField as h,ControlledDropdownField as L,ControlledFileField as M,ControlledMultiFileField as N,ControlledDocumentField as R,ControlledMultiDocumentField as _,ControlledGeoPointField as P,ControlledImageField as B,ControlledMapField as E,ControlledMultiDropdownField as U,ControlledMultiInputField as H,ControlledNumberField as K,ControlledPasswordField as O,ControlledPhoneField as Y,ControlledRangeField as G,ControlledRatingField as W,ControlledDurationField as q,ControlledRadioField as J,ControlledYearField as Q,ControlledTextField as m,ControlledTextareaField as X,ControlledRichTextField as Z,ControlledTimestampField as ee,ControlledAddressField as te,ControlledSwitchField as re,ControlledMultiImageField as ne,ControlledGdprConsentField as oe,ControlledCurrencyField as le,ControlledPriceField as ie}from"./components/controlled";import{AvatarFieldComponent as ae,BadgeFieldComponent as ce,ButtonFieldComponent as v,HiddenFieldComponent as se,TextAreaComponent as pe,RichTextComponent as de,TextFieldComponent as x}from"./components/form/fields";import{registerBuiltinFieldType as i}from"./fieldTypeRegistry";import{translateLabel as g}from"./forms/utils";function d(e){return e?p("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):p(y,{variant:"muted",children:"\u2014"})}const c={timestamp:(e,n,l,t)=>{const r=t?.compact??!1;if(e==null||e==="")return d(r);try{return(e instanceof Date?e:new Date(e)).toLocaleString()}catch{return String(e)}},date:(e,n,l,t)=>{const r=t?.compact??!1;if(e==null||e==="")return d(r);try{return(e instanceof Date?e:new Date(e)).toLocaleDateString()}catch{return String(e)}},"datetime-local":(e,n,l,t)=>{const r=t?.compact??!1;if(e==null||e==="")return d(r);try{return(e instanceof Date?e:new Date(e)).toLocaleString()}catch{return String(e)}},time:(e,n,l,t)=>{const r=t?.compact??!1;if(e==null||e==="")return d(r);try{return(e instanceof Date?e:new Date(e)).toLocaleTimeString()}catch{return String(e)}},week:(e,n,l,t)=>{const r=t?.compact??!1;return e==null||e===""?d(r):String(e)},month:(e,n,l,t)=>{const r=t?.compact??!1;return e==null||e===""?d(r):String(e)},boolean:(e,n,l)=>e?"Yes":"No",checkbox:(e,n,l)=>e?"Yes":"No",switch:(e,n,l)=>{const t=n.options?.fieldSpecific;if(t){const r=t.uncheckedValue??!1,o=t.checkedValue??!0;if(e===o&&t.checkedLabel)return g(t.checkedLabel,l);if(e===r&&t.uncheckedLabel)return g(t.uncheckedLabel,l)}return e?"Yes":"No"},year:(e,n,l)=>String(e),number:(e,n,l)=>typeof e=="number"?e.toLocaleString():String(e),currency:(e,n,l)=>{if(e==null||isNaN(e))return"";const o=(n.options||{}).fieldSpecific?.currency||"EUR";return C(e,o)},price:(e,n,l,t)=>{const r=t?.compact??!1,o=t?.asString??!1,a=e!=null&&typeof e=="number"?{amount:e,currency:"EUR",vatIncluded:!0,discountPercent:0}:e;if(a==null||typeof a!="object")return d(r);const s=a.amount;if(s==null||isNaN(s))return d(r);const u=a.currency||"EUR",j=a.vatIncluded??!0,T=a.discountPercent??0,A=T>0?s*(1-T/100):s,F=j?` ${l("crud:price.vatIncluded",{defaultValue:"VAT Incl."})}`:"";if(T>0){const z=C(s,u),S=C(A,u),w=` ${l("crud:price.discountPercent",{percent:Math.round(T),defaultValue:"-{{percent}}%"})}`;return o?`${S}${F}${w}`:r?f(y,{variant:"success",weight:"bold",children:[S,F,w]}):f(b,{direction:"column",gap:"tight",align:"end",children:[p(y,{variant:"muted",style:{textDecoration:"line-through",fontSize:"var(--font-size-sm)"},children:z}),f(y,{variant:"success",weight:"bold",children:[S,F]})]})}return`${C(s,u)}${F}`},range:(e,n,l)=>typeof e=="number"?e.toLocaleString():String(e),rating:(e,n,l,t)=>{const r=t?.compact??!1;if(e==null)return d(r);const o=typeof e=="number"?e:parseFloat(e);if(isNaN(o))return d(r);const a=n.validation?.max??5;return p($,{value:o,max:a,readonly:!0,"aria-label":`${o} out of ${a} stars`})},duration:(e,n,l,t)=>{const r=t?.compact??!1;if(e==null)return d(r);const o=typeof e=="number"?e:parseInt(String(e),10);if(Number.isNaN(o))return d(r);if(o===0)return l("crud:duration.zero",{defaultValue:"\u2014"});if(o<60)return l("crud:duration.minutes",{count:o,defaultValue:`${o} min`});const a=Math.floor(o/60),s=o%60;return l("crud:duration.hoursMinutes",{hours:a,minutes:s,defaultValue:s===0?`${a}h`:`${a}h ${s}min`})},select:(e,n,l)=>{const t=n.validation?.options;if(Array.isArray(t)){const o=t.find(a=>a.value===e)?.label;return o?g(o,l):String(e)}return String(e)},radio:(e,n,l)=>{const t=n.validation?.options;if(Array.isArray(t)){const o=t.find(a=>a.value===e)?.label;return o?g(o,l):String(e)}return String(e)},combobox:(e,n,l)=>{const t=n.validation?.options;if(Array.isArray(t)){const o=t.find(a=>a.value===e)?.label;return o?g(o,l):String(e)}return String(e)},multiselect:(e,n,l)=>{if(Array.isArray(e)){const t=n.validation?.options;if(Array.isArray(t))return e.map(o=>{const s=t.find(u=>u.value===o)?.label;return s?g(s,l):o}).join(", ")}return String(e)},image:(e,n,l,t)=>{const r=t?.compact??!1;return e==null||e===""?d(r):typeof e=="string"?p("img",{src:e,alt:n.label||"",style:{width:r?"40px":void 0,height:r?"40px":void 0,maxWidth:r?void 0:"200px",maxHeight:r?void 0:"150px",objectFit:"cover",borderRadius:"var(--radius-sm)"}}):d(r)},images:(e,n,l,t)=>{const r=t?.compact??!1;if(!Array.isArray(e)||e.length===0)return d(r);const o=e[0],a=typeof o=="object"&&o.thumbUrl?o.thumbUrl:o;return r?f("div",{style:{display:"flex",alignItems:"center",gap:"var(--gap-xs)"},children:[p("img",{src:a,alt:"",style:{width:"40px",height:"40px",objectFit:"cover",borderRadius:"var(--radius-sm)"}}),e.length>1&&f("span",{style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:["+",e.length-1]})]}):p(D,{images:e,altPrefix:n.label||"Image"})},files:(e,n,l,t)=>{const r=t?.compact??!1;return!Array.isArray(e)||e.length===0?d(r):p(b,{gap:"tight",children:e.map((o,a)=>f("a",{href:o.url||o,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--primary)",textDecoration:"none",display:"flex",alignItems:"center",fontSize:"var(--font-size-sm)"},children:[o.filename||`File ${a+1}`,o.size&&f(y,{level:"caption",variant:"muted",style:{marginLeft:"var(--gap-sm)"},children:["(",Math.round(o.size/1024)," KB)"]})]},a))})},documents:(e,n,l,t)=>{const r=t?.compact??!1;return!Array.isArray(e)||e.length===0?d(r):p(b,{gap:"tight",children:e.map((o,a)=>f("a",{href:o.url||o,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--primary)",textDecoration:"none",display:"flex",alignItems:"center",fontSize:"var(--font-size-sm)"},children:[o.filename||`File ${a+1}`,o.size&&f(y,{level:"caption",variant:"muted",style:{marginLeft:"var(--gap-sm)"},children:["(",Math.round(o.size/1024)," KB)"]})]},a))})},file:(e,n,l,t)=>{const r=t?.compact??!1;if(!e)return d(r);const o=typeof e=="string"?e:e.url,a=typeof e=="string"?"View file":e.filename||"View file";return f("a",{href:o,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--primary)",textDecoration:"none"},children:[a,typeof e=="object"&&e.size&&f("span",{style:{color:"var(--muted-foreground)",marginLeft:"var(--gap-sm)"},children:["(",Math.round(e.size/1024)," KB)"]})]})},document:(e,n,l,t)=>{const r=t?.compact??!1;if(!e)return d(r);const o=typeof e=="string"?e:e.url,a=typeof e=="string"?"View file":e.filename||"View file";return f("a",{href:o,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--primary)",textDecoration:"none"},children:[a,typeof e=="object"&&e.size&&f("span",{style:{color:"var(--muted-foreground)",marginLeft:"var(--gap-sm)"},children:["(",Math.round(e.size/1024)," KB)"]})]})},reference:(e,n,l)=>String(e),geopoint:(e,n,l,t)=>{const r=t?.compact??!1;return e&&typeof e=="object"&&"lat"in e&&"lng"in e?`${e.lat.toFixed(6)}, ${e.lng.toFixed(6)}`:d(r)},address:(e,n,l)=>e&&typeof e=="object"&&"formatted_address"in e?e.formatted_address:String(e),map:(e,n,l,t)=>{const r=t?.compact??!1;if(e&&typeof e=="object"){const o=Object.entries(e);return o.length===0?d(r):f(b,{direction:"column",gap:"tight",children:[o.slice(0,5).map(([a,s])=>f(y,{style:{fontSize:"var(--font-size-sm)"},children:[f("strong",{children:[a,":"]})," ",String(s)]},a)),o.length>5&&f(y,{variant:"muted",children:["+",o.length-5," more"]})]})}return d(r)},array:(e,n,l,t)=>{const r=t?.compact??!1;return Array.isArray(e)?e.length===0?d(r):e.join(", "):d(r)},password:()=>"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",email:(e,n,l)=>p("a",{href:`mailto:${e}`,style:{color:"var(--primary)"},onClick:t=>t.stopPropagation(),children:e}),tel:(e,n,l)=>p("a",{href:`tel:${e}`,style:{color:"var(--primary)"},onClick:t=>t.stopPropagation(),children:e}),url:(e,n,l)=>p("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--primary)"},children:e}),color:(e,n,l)=>f(b,{direction:"row",gap:"tight",align:"center",children:[p("div",{style:{width:"20px",height:"20px",backgroundColor:e,borderRadius:"var(--radius-sm)",border:"1px solid var(--border)"}}),p(y,{children:e})]}),textarea:(e,n,l)=>String(e),text:(e,n,l)=>String(e),richtext:(e,n,l,t)=>{const r=t?.compact??!1;return e&&typeof e=="string"?r?e.replace(/<[^>]*>/g,"").trim()||p("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):p("div",{dangerouslySetInnerHTML:{__html:e},style:{padding:"var(--gap-sm)",fontSize:"var(--font-size-sm)",lineHeight:"1.6"}}):d(r)}};function fe(e){return e.type==="avatar"}function ue(e){return e.type==="badge"}let k=!1;function me(){k||(k=!0,i({type:"text",filterable:!0,filterType:"text",valueType:"string",displayFormatter:c.text,components:{controlled:m,uncontrolled:e=>{const{value:n,onChange:l,label:t,error:r,config:o}=e;return p(x,{label:t||"",value:typeof n=="string"?n:"",onChange:s=>{const u=s.target.value;l(u)},error:r,...o.options})}}}),i({type:"email",filterable:!0,filterType:"text",valueType:"string",displayFormatter:c.email,components:{controlled:m,uncontrolled:e=>{const{value:n,onChange:l,label:t,error:r,config:o}=e;return p(x,{label:t||"",value:typeof n=="string"?n:"",onChange:s=>{const u=s.target.value;l(u)},error:r,type:"email",...o.options})}}}),i({type:"url",filterable:!0,filterType:"text",valueType:"string",displayFormatter:c.url,components:{controlled:m,uncontrolled:e=>{const{value:n,onChange:l,label:t,error:r,config:o}=e;return p(x,{label:t||"",value:typeof n=="string"?n:"",onChange:s=>{const u=s.target.value;l(u)},error:r,type:"url",...o.options})}}}),i({type:"color",filterable:!0,filterType:"text",valueType:"string",displayFormatter:c.color,components:{controlled:m,uncontrolled:e=>{const{value:n,onChange:l,label:t,error:r,config:o}=e;return p(x,{label:t||"",value:typeof n=="string"?n:"",onChange:s=>{const u=s.target.value;l(u)},error:r,type:"color",...o.options})}}}),i({type:"textarea",filterable:!0,filterType:"text",valueType:"string",displayFormatter:c.textarea,components:{controlled:X,uncontrolled:e=>{const{value:n,onChange:l,label:t,error:r,config:o}=e;return p(pe,{label:t||"",value:typeof n=="string"?n:"",onChange:s=>{const u=s.target.value;l(u)},error:r,...o.options})}}}),i({type:"richtext",filterable:!0,filterType:"text",valueType:"string",displayFormatter:c.richtext,components:{controlled:Z,uncontrolled:e=>{const{value:n,onChange:l,label:t,error:r,config:o}=e;return p(de,{label:t||"",value:typeof n=="string"?n:"",onChange:s=>{const u=s.target.value;l(u)},error:r,...o.options})}}}),i({type:"password",filterable:!1,filterType:"none",valueType:"string",displayFormatter:c.password,components:{controlled:O}}),i({type:"tel",filterable:!0,filterType:"text",valueType:"string",displayFormatter:c.tel,components:{controlled:Y}}),i({type:"number",filterable:!0,filterType:"range",valueType:"number",displayFormatter:c.number,components:{controlled:K}}),i({type:"currency",filterable:!0,filterType:"range",valueType:"number",displayFormatter:c.currency,components:{controlled:le}}),i({type:"price",filterable:!0,filterType:"range",valueType:"object",displayFormatter:c.price,components:{controlled:ie}}),i({type:"range",filterable:!0,filterType:"range",valueType:"number",displayFormatter:c.range,components:{controlled:G}}),i({type:"year",filterable:!0,filterType:"range",valueType:"number",displayFormatter:c.year,components:{controlled:Q}}),i({type:"rating",filterable:!0,filterType:"range",valueType:"number",displayFormatter:c.rating,components:{controlled:W}}),i({type:"duration",filterable:!0,filterType:"range",valueType:"number",displayFormatter:c.duration,components:{controlled:q}}),i({type:"boolean",filterable:!0,filterType:"select",valueType:"boolean",displayFormatter:c.boolean,components:{controlled:V}}),i({type:"checkbox",filterable:!0,filterType:"select",valueType:"boolean",displayFormatter:c.checkbox,components:{controlled:V}}),i({type:"gdprConsent",filterable:!0,filterType:"select",valueType:"object",components:{controlled:oe}}),i({type:"switch",filterable:!0,filterType:"select",valueType:"boolean",displayFormatter:c.switch,components:{controlled:re}}),i({type:"date",filterable:!0,filterType:"range",valueType:"date",displayFormatter:c.date,components:{controlled:h}}),i({type:"datetime-local",filterable:!0,filterType:"range",valueType:"date",displayFormatter:c["datetime-local"],components:{controlled:h}}),i({type:"time",filterable:!0,filterType:"range",valueType:"date",displayFormatter:c.time,components:{controlled:h}}),i({type:"week",filterable:!0,filterType:"range",valueType:"date",displayFormatter:c.week,components:{controlled:h}}),i({type:"month",filterable:!0,filterType:"range",valueType:"date",displayFormatter:c.month,components:{controlled:h}}),i({type:"timestamp",filterable:!0,filterType:"range",valueType:"date",displayFormatter:c.timestamp,components:{controlled:ee}}),i({type:"file",filterable:!1,filterType:"none",valueType:"object",displayFormatter:c.file,components:{controlled:M}}),i({type:"files",filterable:!1,filterType:"none",valueType:"array",displayFormatter:c.files,components:{controlled:N}}),i({type:"document",filterable:!1,filterType:"none",valueType:"object",displayFormatter:c.document,components:{controlled:R}}),i({type:"documents",filterable:!1,filterType:"none",valueType:"array",displayFormatter:c.documents,components:{controlled:_}}),i({type:"image",filterable:!1,filterType:"none",valueType:"object",displayFormatter:c.image,components:{controlled:B}}),i({type:"images",filterable:!1,filterType:"none",valueType:"array",displayFormatter:c.images,components:{controlled:ne}}),i({type:"geopoint",filterable:!1,filterType:"none",valueType:"object",displayFormatter:c.geopoint,components:{controlled:P}}),i({type:"address",filterable:!0,filterType:"address",valueType:"object",displayFormatter:c.address,components:{controlled:te}}),i({type:"map",filterable:!1,filterType:"none",valueType:"object",displayFormatter:c.map,components:{controlled:E}}),i({type:"array",filterable:!1,filterType:"none",valueType:"array",displayFormatter:c.array,components:{controlled:H}}),i({type:"select",filterable:!0,filterType:"select",valueType:"string",displayFormatter:c.select,components:{controlled:L}}),i({type:"combobox",filterable:!0,filterType:"select",valueType:"string",displayFormatter:c.combobox,components:{controlled:I}}),i({type:"multiselect",filterable:!0,filterType:"multiselect",valueType:"array",displayFormatter:c.multiselect,components:{controlled:U}}),i({type:"radio",filterable:!0,filterType:"select",valueType:"string",displayFormatter:c.radio,components:{controlled:J}}),i({type:"reference",filterable:!0,filterType:"text",valueType:"string",components:{controlled:m}}),i({type:"hidden",filterable:!1,filterType:"none",valueType:"string",components:{controlled:m,uncontrolled:e=>{const{name:n,value:l}=e;return p(se,{name:n,value:typeof l=="string"?l:""})}}}),i({type:"avatar",filterable:!1,filterType:"none",valueType:"string",components:{controlled:m,uncontrolled:e=>{const{value:n,onChange:l,error:t,config:r,t:o}=e;if(!fe(r))throw new Error("Invalid config type for avatar field");return p(ae,{config:r,value:typeof n=="string"?n:"",onChange:s=>{l(s)},error:!!t,helperText:t||void 0,t:o,...r.options})}}}),i({type:"badge",filterable:!1,filterType:"none",valueType:"string",components:{controlled:m,uncontrolled:e=>{const{value:n,onChange:l,error:t,config:r,t:o}=e;if(!ue(r))throw new Error("Invalid config type for badge field");return p(ce,{config:r,value:typeof n=="string"?n:"",onChange:s=>{l(s)},error:!!t,helperText:t||void 0,t:o,...r.options})}}}),i({type:"submit",filterable:!1,filterType:"none",valueType:"string",components:{controlled:m,uncontrolled:e=>{const{name:n,label:l,config:t}=e;return p(v,{label:l||n,type:"submit",onClick:()=>{},...t.options})}}}),i({type:"reset",filterable:!1,filterType:"none",valueType:"string",components:{controlled:m,uncontrolled:e=>{const{name:n,label:l,config:t}=e;return p(v,{label:l||n,type:"reset",onClick:()=>{},...t.options})}}}))}me();export{me as registerAllBuiltinFieldTypes};
1
+ "use client";import{jsx as p,jsxs as u}from"react/jsx-runtime";import{Text as m,Stack as b,ImageGallery as I,Rating as $,CopyToClipboard as k}from"@donotdev/components";import{formatCurrency as x}from"@donotdev/core";import{ControlledCheckboxField as A,ControlledComboboxField as v,ControlledDateField as T,ControlledDropdownField as N,ControlledFileField as P,ControlledMultiFileField as M,ControlledDocumentField as _,ControlledMultiDocumentField as R,ControlledGeoPointField as B,ControlledImageField as E,ControlledMapField as U,ControlledMultiDropdownField as H,ControlledMultiInputField as K,ControlledNumberField as O,ControlledPasswordField as Y,ControlledPhoneField as G,ControlledRangeField as W,ControlledRatingField as q,ControlledDurationField as J,ControlledRadioField as Q,ControlledYearField as X,ControlledTextField as y,ControlledTextareaField as Z,ControlledRichTextField as ee,ControlledTimestampField as te,ControlledAddressField as re,ControlledSwitchField as ne,ControlledMultiImageField as oe,ControlledGdprConsentField as le,ControlledCurrencyField as ie,ControlledPriceField as ae}from"./components/controlled";import{AvatarFieldComponent as ce,BadgeFieldComponent as se,ButtonFieldComponent as D,HiddenFieldComponent as pe,TextAreaComponent as de,RichTextComponent as fe,TextFieldComponent as C}from"./components/form/fields";import{registerBuiltinFieldType as a}from"./fieldTypeRegistry";import{translateLabel as h}from"./forms/utils";function d(e){return e?p("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):p(m,{variant:"muted",children:"\u2014"})}const c={timestamp:(e,l,o,t)=>{const r=t?.compact??!1;if(e==null||e==="")return d(r);try{return(e instanceof Date?e:new Date(e)).toLocaleString()}catch{return String(e)}},date:(e,l,o,t)=>{const r=t?.compact??!1;if(e==null||e==="")return d(r);try{return(e instanceof Date?e:new Date(e)).toLocaleDateString()}catch{return String(e)}},"datetime-local":(e,l,o,t)=>{const r=t?.compact??!1;if(e==null||e==="")return d(r);try{return(e instanceof Date?e:new Date(e)).toLocaleString()}catch{return String(e)}},time:(e,l,o,t)=>{const r=t?.compact??!1;if(e==null||e==="")return d(r);try{return(e instanceof Date?e:new Date(e)).toLocaleTimeString()}catch{return String(e)}},week:(e,l,o,t)=>{const r=t?.compact??!1;return e==null||e===""?d(r):String(e)},month:(e,l,o,t)=>{const r=t?.compact??!1;return e==null||e===""?d(r):String(e)},boolean:(e,l,o)=>e?"Yes":"No",checkbox:(e,l,o)=>e?"Yes":"No",switch:(e,l,o)=>{const t=l.options?.fieldSpecific;if(t){const r=t.uncheckedValue??!1,n=t.checkedValue??!0;if(e===n&&t.checkedLabel)return h(t.checkedLabel,o);if(e===r&&t.uncheckedLabel)return h(t.uncheckedLabel,o)}return e?"Yes":"No"},year:(e,l,o)=>String(e),number:(e,l,o)=>typeof e=="number"?e.toLocaleString():String(e),currency:(e,l,o)=>{if(e==null||isNaN(e))return"";const n=(l.options||{}).fieldSpecific?.currency||"EUR";return x(e,n)},price:(e,l,o,t)=>{const r=t?.compact??!1,n=t?.asString??!1,i=e!=null&&typeof e=="number"?{amount:e,currency:"EUR",vatIncluded:!0,discountPercent:0}:e;if(i==null||typeof i!="object")return d(r);const s=i.amount;if(s==null||isNaN(s))return d(r);const f=i.currency||"EUR",V=i.vatIncluded??!0,g=i.discountPercent??0,S=g>0?s*(1-g/100):s,F=V?` ${o("crud:price.vatIncluded",{defaultValue:"VAT Incl."})}`:"";if(g>0){const z=x(s,f),w=x(S,f),j=` ${o("crud:price.discountPercent",{percent:Math.round(g),defaultValue:"-{{percent}}%"})}`;return n?`${w}${F}${j}`:r?u(m,{variant:"success",weight:"bold",children:[w,F,j]}):u(b,{direction:"column",gap:"tight",align:"end",children:[p(m,{variant:"muted",style:{textDecoration:"line-through",fontSize:"var(--font-size-sm)"},children:z}),u(m,{variant:"success",weight:"bold",children:[w,F]})]})}return`${x(s,f)}${F}`},range:(e,l,o)=>typeof e=="number"?e.toLocaleString():String(e),rating:(e,l,o,t)=>{const r=t?.compact??!1;if(e==null)return d(r);const n=typeof e=="number"?e:parseFloat(e);if(isNaN(n))return d(r);const i=l.validation?.max??5;return p($,{value:n,max:i,readonly:!0,"aria-label":`${n} out of ${i} stars`})},duration:(e,l,o,t)=>{const r=t?.compact??!1;if(e==null)return d(r);const n=typeof e=="number"?e:parseInt(String(e),10);if(Number.isNaN(n))return d(r);if(n===0)return o("crud:duration.zero",{defaultValue:"\u2014"});if(n<60)return o("crud:duration.minutes",{count:n,defaultValue:`${n} min`});const i=Math.floor(n/60),s=n%60;return o("crud:duration.hoursMinutes",{hours:i,minutes:s,defaultValue:s===0?`${i}h`:`${i}h ${s}min`})},gdprConsent:(e,l,o,t)=>{const r=t?.compact??!1;if(!e||typeof e!="object")return d(r);const n=e.gdprConsent===!0,i=e.gdprConsentDate,s=e.gdprConsentVersion,f=o("crud:gdprConsent.display.yes",{defaultValue:"Consented"}),V=o("crud:gdprConsent.display.no",{defaultValue:"Not consented"});if(!n)return V;const g=[f];if(i)try{const S=new Date(i);g.push(S.toLocaleDateString())}catch{g.push(i)}return s&&g.push(`v${s}`),g.join(" \xB7 ")},select:(e,l,o)=>{const t=l.validation?.options;if(Array.isArray(t)){const n=t.find(i=>i.value===e)?.label;return n?h(n,o):String(e)}return String(e)},radio:(e,l,o)=>{const t=l.validation?.options;if(Array.isArray(t)){const n=t.find(i=>i.value===e)?.label;return n?h(n,o):String(e)}return String(e)},combobox:(e,l,o)=>{const t=l.validation?.options;if(Array.isArray(t)){const n=t.find(i=>i.value===e)?.label;return n?h(n,o):String(e)}return String(e)},multiselect:(e,l,o)=>{if(Array.isArray(e)){const t=l.validation?.options;if(Array.isArray(t))return e.map(n=>{const s=t.find(f=>f.value===n)?.label;return s?h(s,o):n}).join(", ")}return String(e)},image:(e,l,o,t)=>{const r=t?.compact??!1;return e==null||e===""?d(r):typeof e=="string"?p("img",{src:e,alt:l.label||"",style:{width:r?"40px":void 0,height:r?"40px":void 0,maxWidth:r?void 0:"200px",maxHeight:r?void 0:"150px",objectFit:"cover",borderRadius:"var(--radius-sm)"}}):d(r)},images:(e,l,o,t)=>{const r=t?.compact??!1;if(!Array.isArray(e)||e.length===0)return d(r);const n=e[0],i=typeof n=="object"&&n.thumbUrl?n.thumbUrl:n;return r?u("div",{style:{display:"flex",alignItems:"center",gap:"var(--gap-xs)"},children:[p("img",{src:i,alt:"",style:{width:"40px",height:"40px",objectFit:"cover",borderRadius:"var(--radius-sm)"}}),e.length>1&&u("span",{style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:["+",e.length-1]})]}):p(I,{images:e,altPrefix:l.label||"Image"})},files:(e,l,o,t)=>{const r=t?.compact??!1;return!Array.isArray(e)||e.length===0?d(r):p(b,{gap:"tight",children:e.map((n,i)=>u("a",{href:n.url||n,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--primary)",textDecoration:"none",display:"flex",alignItems:"center",fontSize:"var(--font-size-sm)"},children:[n.filename||`File ${i+1}`,n.size&&u(m,{level:"caption",variant:"muted",style:{marginLeft:"var(--gap-sm)"},children:["(",Math.round(n.size/1024)," KB)"]})]},i))})},documents:(e,l,o,t)=>{const r=t?.compact??!1;return!Array.isArray(e)||e.length===0?d(r):p(b,{gap:"tight",children:e.map((n,i)=>u("a",{href:n.url||n,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--primary)",textDecoration:"none",display:"flex",alignItems:"center",fontSize:"var(--font-size-sm)"},children:[n.filename||`File ${i+1}`,n.size&&u(m,{level:"caption",variant:"muted",style:{marginLeft:"var(--gap-sm)"},children:["(",Math.round(n.size/1024)," KB)"]})]},i))})},file:(e,l,o,t)=>{const r=t?.compact??!1;if(!e)return d(r);const n=typeof e=="string"?e:e.url,i=typeof e=="string"?"View file":e.filename||"View file";return u("a",{href:n,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--primary)",textDecoration:"none"},children:[i,typeof e=="object"&&e.size&&u("span",{style:{color:"var(--muted-foreground)",marginLeft:"var(--gap-sm)"},children:["(",Math.round(e.size/1024)," KB)"]})]})},document:(e,l,o,t)=>{const r=t?.compact??!1;if(!e)return d(r);const n=typeof e=="string"?e:e.url,i=typeof e=="string"?"View file":e.filename||"View file";return u("a",{href:n,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--primary)",textDecoration:"none"},children:[i,typeof e=="object"&&e.size&&u("span",{style:{color:"var(--muted-foreground)",marginLeft:"var(--gap-sm)"},children:["(",Math.round(e.size/1024)," KB)"]})]})},reference:(e,l,o,t)=>{const r=t?.compact??!1;if(!e)return d(r);if(typeof e=="object"&&e!==null){const n=e.displayName||e.name||e.id||String(e);return String(n)}return String(e)},geopoint:(e,l,o,t)=>{const r=t?.compact??!1;return e&&typeof e=="object"&&"lat"in e&&"lng"in e?`${e.lat.toFixed(6)}, ${e.lng.toFixed(6)}`:d(r)},address:(e,l,o)=>e&&typeof e=="object"&&"formatted_address"in e?e.formatted_address:String(e),map:(e,l,o,t)=>{const r=t?.compact??!1;if(e&&typeof e=="object"){const n=Object.entries(e);return n.length===0?d(r):u(b,{direction:"column",gap:"tight",children:[n.slice(0,5).map(([i,s])=>u(m,{style:{fontSize:"var(--font-size-sm)"},children:[u("strong",{children:[i,":"]})," ",String(s)]},i)),n.length>5&&u(m,{variant:"muted",children:["+",n.length-5," more"]})]})}return d(r)},array:(e,l,o,t)=>{const r=t?.compact??!1;return Array.isArray(e)?e.length===0?d(r):e.join(", "):d(r)},password:()=>"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",email:(e,l,o)=>u(b,{direction:"row",gap:"tight",align:"center",children:[p("a",{href:`mailto:${e}`,style:{color:"var(--primary)",flex:1},onClick:t=>t.stopPropagation(),children:e}),p(k,{text:e,tooltipText:o("crud:copyToClipboard",{defaultValue:"Copy to clipboard"}),ariaLabel:o("crud:actions.copyEmail",{defaultValue:"Copy email"}),onClick:t=>t.stopPropagation()})]}),tel:(e,l,o)=>u(b,{direction:"row",gap:"tight",align:"center",children:[p("a",{href:`tel:${e}`,style:{color:"var(--primary)",flex:1},onClick:t=>t.stopPropagation(),children:e}),p(k,{text:e,tooltipText:o("crud:copyToClipboard",{defaultValue:"Copy to clipboard"}),ariaLabel:o("crud:actions.copyPhone",{defaultValue:"Copy phone"}),onClick:t=>t.stopPropagation()})]}),iban:(e,l,o,t)=>{const r=t?.compact??!1;return e?u(b,{direction:"row",gap:"tight",align:"center",children:[p(m,{style:{flex:1},children:e}),p(k,{text:e,tooltipText:o("crud:copyToClipboard",{defaultValue:"Copy to clipboard"}),ariaLabel:o("crud:actions.copyIban",{defaultValue:"Copy IBAN"}),onClick:n=>n.stopPropagation()})]}):d(r)},url:(e,l,o)=>p("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--primary)"},children:e}),color:(e,l,o)=>u(b,{direction:"row",gap:"tight",align:"center",children:[p("div",{style:{width:"20px",height:"20px",backgroundColor:e,borderRadius:"var(--radius-sm)",border:"1px solid var(--border)"}}),p(m,{children:e})]}),textarea:(e,l,o)=>String(e),text:(e,l,o)=>String(e),richtext:(e,l,o,t)=>{const r=t?.compact??!1;return e&&typeof e=="string"?r?e.replace(/<[^>]*>/g,"").trim()||p("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):p("div",{dangerouslySetInnerHTML:{__html:e},style:{padding:"var(--gap-sm)",fontSize:"var(--font-size-sm)",lineHeight:"1.6"}}):d(r)}};function ue(e){return e.type==="avatar"}function ye(e){return e.type==="badge"}let L=!1;function me(){L||(L=!0,a({type:"text",filterable:!0,filterType:"text",valueType:"string",displayFormatter:c.text,components:{controlled:y,uncontrolled:e=>{const{value:l,onChange:o,label:t,error:r,config:n}=e;return p(C,{label:t||"",value:typeof l=="string"?l:"",onChange:s=>{const f=s.target.value;o(f)},error:r,...n.options})}}}),a({type:"email",filterable:!0,filterType:"text",valueType:"string",displayFormatter:c.email,components:{controlled:y,uncontrolled:e=>{const{value:l,onChange:o,label:t,error:r,config:n}=e;return p(C,{label:t||"",value:typeof l=="string"?l:"",onChange:s=>{const f=s.target.value;o(f)},error:r,type:"email",...n.options})}}}),a({type:"url",filterable:!0,filterType:"text",valueType:"string",displayFormatter:c.url,components:{controlled:y,uncontrolled:e=>{const{value:l,onChange:o,label:t,error:r,config:n}=e;return p(C,{label:t||"",value:typeof l=="string"?l:"",onChange:s=>{const f=s.target.value;o(f)},error:r,type:"url",...n.options})}}}),a({type:"color",filterable:!0,filterType:"text",valueType:"string",displayFormatter:c.color,components:{controlled:y,uncontrolled:e=>{const{value:l,onChange:o,label:t,error:r,config:n}=e;return p(C,{label:t||"",value:typeof l=="string"?l:"",onChange:s=>{const f=s.target.value;o(f)},error:r,type:"color",...n.options})}}}),a({type:"textarea",filterable:!0,filterType:"text",valueType:"string",displayFormatter:c.textarea,components:{controlled:Z,uncontrolled:e=>{const{value:l,onChange:o,label:t,error:r,config:n}=e;return p(de,{label:t||"",value:typeof l=="string"?l:"",onChange:s=>{const f=s.target.value;o(f)},error:r,...n.options})}}}),a({type:"richtext",filterable:!0,filterType:"text",valueType:"string",displayFormatter:c.richtext,components:{controlled:ee,uncontrolled:e=>{const{value:l,onChange:o,label:t,error:r,config:n}=e;return p(fe,{label:t||"",value:typeof l=="string"?l:"",onChange:s=>{const f=s.target.value;o(f)},error:r,...n.options})}}}),a({type:"password",filterable:!1,filterType:"none",valueType:"string",displayFormatter:c.password,components:{controlled:Y}}),a({type:"tel",filterable:!0,filterType:"text",valueType:"string",displayFormatter:c.tel,components:{controlled:G}}),a({type:"iban",filterable:!0,filterType:"text",valueType:"string",displayFormatter:c.iban,components:{controlled:y,uncontrolled:e=>{const{value:l,onChange:o,label:t,error:r,config:n}=e;return p(C,{label:t||"",value:typeof l=="string"?l:"",onChange:s=>{const f=s.target.value.replace(/\s/g,"").toUpperCase();o(f)},error:r,...n.options})}}}),a({type:"number",filterable:!0,filterType:"range",valueType:"number",displayFormatter:c.number,components:{controlled:O}}),a({type:"currency",filterable:!0,filterType:"range",valueType:"number",displayFormatter:c.currency,components:{controlled:ie}}),a({type:"price",filterable:!0,filterType:"range",valueType:"object",displayFormatter:c.price,components:{controlled:ae}}),a({type:"range",filterable:!0,filterType:"range",valueType:"number",displayFormatter:c.range,components:{controlled:W}}),a({type:"year",filterable:!0,filterType:"range",valueType:"number",displayFormatter:c.year,components:{controlled:X}}),a({type:"rating",filterable:!0,filterType:"range",valueType:"number",displayFormatter:c.rating,components:{controlled:q}}),a({type:"duration",filterable:!0,filterType:"range",valueType:"number",displayFormatter:c.duration,components:{controlled:J}}),a({type:"boolean",filterable:!0,filterType:"select",valueType:"boolean",displayFormatter:c.boolean,components:{controlled:A}}),a({type:"checkbox",filterable:!0,filterType:"select",valueType:"boolean",displayFormatter:c.checkbox,components:{controlled:A}}),a({type:"gdprConsent",filterable:!0,filterType:"select",valueType:"object",displayFormatter:c.gdprConsent,components:{controlled:le}}),a({type:"switch",filterable:!0,filterType:"select",valueType:"boolean",displayFormatter:c.switch,components:{controlled:ne}}),a({type:"date",filterable:!0,filterType:"range",valueType:"date",displayFormatter:c.date,components:{controlled:T}}),a({type:"datetime-local",filterable:!0,filterType:"range",valueType:"date",displayFormatter:c["datetime-local"],components:{controlled:T}}),a({type:"time",filterable:!0,filterType:"range",valueType:"date",displayFormatter:c.time,components:{controlled:T}}),a({type:"week",filterable:!0,filterType:"range",valueType:"date",displayFormatter:c.week,components:{controlled:T}}),a({type:"month",filterable:!0,filterType:"range",valueType:"date",displayFormatter:c.month,components:{controlled:T}}),a({type:"timestamp",filterable:!0,filterType:"range",valueType:"date",displayFormatter:c.timestamp,components:{controlled:te}}),a({type:"file",filterable:!1,filterType:"none",valueType:"object",displayFormatter:c.file,components:{controlled:P}}),a({type:"files",filterable:!1,filterType:"none",valueType:"array",displayFormatter:c.files,components:{controlled:M}}),a({type:"document",filterable:!1,filterType:"none",valueType:"object",displayFormatter:c.document,components:{controlled:_}}),a({type:"documents",filterable:!1,filterType:"none",valueType:"array",displayFormatter:c.documents,components:{controlled:R}}),a({type:"image",filterable:!1,filterType:"none",valueType:"object",displayFormatter:c.image,components:{controlled:E}}),a({type:"images",filterable:!1,filterType:"none",valueType:"array",displayFormatter:c.images,components:{controlled:oe}}),a({type:"geopoint",filterable:!1,filterType:"none",valueType:"object",displayFormatter:c.geopoint,components:{controlled:B}}),a({type:"address",filterable:!0,filterType:"address",valueType:"object",displayFormatter:c.address,components:{controlled:re}}),a({type:"map",filterable:!1,filterType:"none",valueType:"object",displayFormatter:c.map,components:{controlled:U}}),a({type:"array",filterable:!1,filterType:"none",valueType:"array",displayFormatter:c.array,components:{controlled:K}}),a({type:"select",filterable:!0,filterType:"select",valueType:"string",displayFormatter:c.select,components:{controlled:N}}),a({type:"combobox",filterable:!0,filterType:"select",valueType:"string",displayFormatter:c.combobox,components:{controlled:v}}),a({type:"multiselect",filterable:!0,filterType:"multiselect",valueType:"array",displayFormatter:c.multiselect,components:{controlled:H}}),a({type:"radio",filterable:!0,filterType:"select",valueType:"string",displayFormatter:c.radio,components:{controlled:Q}}),a({type:"reference",filterable:!0,filterType:"text",valueType:"string",displayFormatter:c.reference,components:{controlled:y}}),a({type:"hidden",filterable:!1,filterType:"none",valueType:"string",components:{controlled:y,uncontrolled:e=>{const{name:l,value:o}=e;return p(pe,{name:l,value:typeof o=="string"?o:""})}}}),a({type:"avatar",filterable:!1,filterType:"none",valueType:"string",components:{controlled:y,uncontrolled:e=>{const{value:l,onChange:o,error:t,config:r,t:n}=e;if(!ue(r))throw new Error("Invalid config type for avatar field");return p(ce,{config:r,value:typeof l=="string"?l:"",onChange:s=>{o(s)},error:!!t,helperText:t||void 0,t:n,...r.options})}}}),a({type:"badge",filterable:!1,filterType:"none",valueType:"string",components:{controlled:y,uncontrolled:e=>{const{value:l,onChange:o,error:t,config:r,t:n}=e;if(!ye(r))throw new Error("Invalid config type for badge field");return p(se,{config:r,value:typeof l=="string"?l:"",onChange:s=>{o(s)},error:!!t,helperText:t||void 0,t:n,...r.options})}}}),a({type:"submit",filterable:!1,filterType:"none",valueType:"string",components:{controlled:y,uncontrolled:e=>{const{name:l,label:o,config:t}=e;return p(D,{label:o||l,type:"submit",onClick:()=>{},...t.options})}}}),a({type:"reset",filterable:!1,filterType:"none",valueType:"string",components:{controlled:y,uncontrolled:e=>{const{name:l,label:o,config:t}=e;return p(D,{label:o||l,type:"reset",onClick:()=>{},...t.options})}}}))}me();export{me as registerAllBuiltinFieldTypes};