@donotdev/crud 0.0.28 → 0.0.29
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/FieldRegistry.d.ts +6 -5
- package/dist/FieldRegistry.d.ts.map +1 -1
- package/dist/FieldRegistry.js +1 -1
- package/dist/components/DisplayFieldRenderer.d.ts.map +1 -1
- package/dist/components/DisplayFieldRenderer.js +1 -1
- package/dist/components/EntityFilters.js +1 -1
- package/dist/components/controlled/file/ControlledFileField.js +1 -1
- package/dist/components/controlled/input/ControlledDurationField.js +1 -1
- package/dist/components/form/fields/DropdownComponent.js +1 -1
- package/dist/components/form/fields/MultiDropdownComponent.js +1 -1
- package/dist/components/form/fields/PhoneNumberComponent.js +1 -1
- package/dist/components/form/fields/RangeFieldComponent.js +1 -1
- package/dist/components/form/fields/TextAreaComponent.js +1 -1
- package/dist/hooks/useFileUpload.js +1 -1
- package/dist/registerBuiltinFieldTypes.d.ts.map +1 -1
- package/dist/registerBuiltinFieldTypes.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/collections.js +1 -1
- package/dist/utils/uploadValidation.js +1 -1
- package/package.json +3 -3
package/dist/FieldRegistry.d.ts
CHANGED
|
@@ -39,10 +39,11 @@ export type CustomFilterType = 'text' | 'range' | 'select' | 'none' | 'address'
|
|
|
39
39
|
* Optional displayFormatter so list/card/display views can render the value.
|
|
40
40
|
* Optional filterable + filterType so EntityFilters can show the right filter UI.
|
|
41
41
|
*/
|
|
42
|
-
export interface FieldTypeRegistration<FT extends
|
|
42
|
+
export interface FieldTypeRegistration<FT extends FieldType = FieldType> {
|
|
43
43
|
type: FT;
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
/** Controlled form component. Optional for display-only registrations. */
|
|
45
|
+
controlledComponent?: ComponentType<ControlledFieldProps<FieldValues, FT>>;
|
|
46
|
+
uncontrolledComponent?: ComponentType<UncontrolledFieldProps<FT>>;
|
|
46
47
|
/** Formatter for list/card/display; receives (value, fieldConfig, t, options?) */
|
|
47
48
|
displayFormatter?: CustomDisplayFormatter;
|
|
48
49
|
/** Whether this field is filterable in list/card filters */
|
|
@@ -67,7 +68,7 @@ declare class FieldRegistry {
|
|
|
67
68
|
* Register a custom field type (UI components only)
|
|
68
69
|
* Schemas must be defined in entity.validation.schema
|
|
69
70
|
*/
|
|
70
|
-
register<FT extends
|
|
71
|
+
register<FT extends FieldType>(registration: FieldTypeRegistration<FT>): void;
|
|
71
72
|
/**
|
|
72
73
|
* Get controlled component
|
|
73
74
|
*/
|
|
@@ -154,7 +155,7 @@ export declare function getFieldRegistry(): FieldRegistry;
|
|
|
154
155
|
* });
|
|
155
156
|
* ```
|
|
156
157
|
*/
|
|
157
|
-
export declare function registerFieldType<FT extends
|
|
158
|
+
export declare function registerFieldType<FT extends FieldType>(registration: FieldTypeRegistration<FT>): void;
|
|
158
159
|
/**
|
|
159
160
|
* Check if a field type is registered
|
|
160
161
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldRegistry.d.ts","sourceRoot":"","sources":["../src/FieldRegistry.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEhF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,YAAY,EAAE,oBAAoB,EAAE,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,sBAAsB,CAAC,EAAE,SAAS,SAAS,GAAG,SAAS;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,iBAAiB,CAAC,EAAE,CAAC,CAAC;IAC7B,Q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A6CG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,SAAS,SAAS,EACpD,YAAY,EAAE,qBAAqB,CAAC,EAAE,CAAC,GACtC,IAAI,CAEN;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE3D"}
|
package/dist/FieldRegistry.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";class c{components=new Map;displayFormatters=new Map;filterMetadata=new Map;registerComponent(e,t,n){this.components.set(e,{controlled:t,uncontrolled:n})}register(e){const{type:t,controlledComponent:n,uncontrolledComponent:
|
|
1
|
+
"use client";class c{components=new Map;displayFormatters=new Map;filterMetadata=new Map;registerComponent(e,t,n){this.components.set(e,{controlled:t,uncontrolled:n})}register(e){const{type:t,controlledComponent:n,uncontrolledComponent:l,displayFormatter:i,filterable:a,filterType:p}=e;(n||l)&&this.components.set(t,{controlled:n,uncontrolled:l}),i&&this.displayFormatters.set(t,i),(a!==void 0||p!==void 0)&&this.filterMetadata.set(t,{filterable:a??!1,filterType:p})}getControlledComponent(e){return this.components.get(e)?.controlled}getUncontrolledComponent(e){return this.components.get(e)?.uncontrolled}getDisplayFormatter(e){return this.displayFormatters.get(e)}getFilterType(e){return this.filterMetadata.get(e)?.filterType}isFilterable(e){return this.filterMetadata.get(e)?.filterable??!1}has(e){return this.components.has(e)}getRegisteredTypes(){return Array.from(this.components.keys())}clear(){this.components.clear(),this.displayFormatters.clear(),this.filterMetadata.clear()}}let o=null;function s(){return o||(o=new c),o}function d(r){s().register(r)}function m(r){return s().has(r)}export{s as getFieldRegistry,m as isFieldTypeRegistered,d as registerFieldType};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DisplayFieldRenderer.d.ts","sourceRoot":"","sources":["../../src/components/DisplayFieldRenderer.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAK7D,OAAO,KAAK,E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,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC;CAC3D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,GAAG,EACV,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,EACzD,OAAO,CAAC,EAAE,uBAAuB,GAChC,MAAM,GAAG,YAAY,CA4EvB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EAAE,EACpE,IAAI,EACJ,MAAM,EACN,KAAK,EACL,CAAC,GACF,EAAE,yBAAyB,CAAC,CAAC,CAAC,GAAG,YAAY,CAyC7C;AAED,eAAe,oBAAoB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as r,jsxs as
|
|
1
|
+
"use client";import{jsx as r,jsxs as f}from"react/jsx-runtime";import{Text as s,Stack as h}from"@donotdev/components";import{handleError as c}from"@donotdev/core";import{getDisplayFormatter as v}from"../fieldTypeRegistry";import{translateFieldLabel as x}from"../forms/utils";function y(e,t,a,n){const i=n?.compact??!1,l=n?.asString??!1;if(e==null||e==="")return l?"\u2014":i?r("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):r(s,{variant:"muted",children:"\u2014"});const d=v(t.type),m=t.options?.displayKey;if(m){let o=String(e);if(d)try{const p=d(e,t,a,n);o=typeof p=="string"?p:String(e)}catch{}const u=(Array.isArray(m)?m:[m]).map(p=>p.replace("{{value}}",o));return a(u,{value:o})}if(d)try{return d(e,t,a,n)}catch(o){return c(o,{userMessage:`Error formatting field "${t.label||t.name}"`,context:{fieldType:t.type,fieldName:t.label||"unknown",operation:"display_format"},severity:"warning"}),l?String(e):i?r("span",{style:{color:"var(--muted-foreground)"},children:String(e)}):r(s,{variant:"muted",children:String(e)})}return c(new Error(`Display formatter not registered for field type: ${t.type}`),{userMessage:`Field type "${t.type}" is missing display formatter`,context:{fieldType:t.type,fieldName:t.label||"unknown",operation:"display_format",fix:"Add displayFormatter to registerBuiltinFieldType() in registerBuiltinFieldTypes.tsx"},severity:"warning"}),l?String(e):i?r("span",{style:{color:"var(--muted-foreground)"},children:String(e)}):r(s,{variant:"muted",children:String(e)})}function g({name:e,config:t,value:a,t:n}){const i=y(a,t,n,{compact:!1}),l=x(e,t,n);return f(h,{direction:"row",align:"baseline",style:{marginBottom:"var(--gap-sm)",padding:"var(--gap-sm)",minHeight:"38px",alignItems:"center"},children:[f(s,{variant:"muted",style:{fontSize:"var(--font-size-sm)",fontWeight:500,minWidth:"fit-content",flexShrink:0},children:[l,":"]}),r("div",{style:{flex:1,display:"flex",alignItems:"center"},children:typeof i=="string"?r(s,{children:i}):i})]})}var S=g;export{g as DisplayFieldRenderer,S as default,y as formatValue};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as d,jsxs as _}from"react/jsx-runtime";import{FilterX as Y}from"lucide-react";import{useMemo as V}from"react";import{Button as Z,Combobox as W,Grid as ee,Rating as te,RangeInput as ae,Slider as ie,Stack as le}from"@donotdev/components";import{useTranslation as D,handleError as B}from"@donotdev/core";import{DateFilter as ne}from"./DateFilter";import{getFilterType as $,isFilterable as re}from"../fieldTypeRegistry";import{translateFieldLabel as se,translateLabel as I}from"../forms/utils";import{useCrudFilters as oe}from"../hooks/useCrudFilters";import{useCrudCardList as me}from"../useCrudCardList";import{matchesFilter as fe}from"../utils/matchesFilter";import{matchesFilter as de}from"../utils/matchesFilter";function ue({entity:f,data:O,fieldsToFilter:T,variant:L="inline",cols:P}){const z=L==="sidebar",{t:p,i18n:G}=D("crud"),{t:j}=D([f.namespace,"crud"]),X=G?.language||"en",{data:q}=me(f,{enabled:!O}),c=O??(q?.items||[]),{filters:b,setFilters:A}=oe({collection:f.collection}),g=V(()=>(T&&T.length>0?T:f.listFields||Object.keys(f.fields)).filter(a=>{const t=f.fields[a]?.type||"text";return re(t)}),[T,f.listFields,f.fields]),R=V(()=>{const a={};return g.forEach(t=>{const o=Object.fromEntries(Object.entries(b).filter(([i])=>i!==t));if(Object.keys(o).length===0){a[t]=c;return}a[t]=c.filter(i=>Object.entries(o).every(([m,h])=>{const F=i[m],x=f.fields[m]?.type||"text";return fe(F,h,x)}))}),a},[c,b,f.fields,g]),H=V(()=>{const a={};return g.forEach(t=>{const o=f.fields[t];if(!o)return;const i=o.type||"text",m=$(i);if(!m){B(new Error(`Field type "${i}" not registered in field type registry`),{userMessage:`Field type "${i}" is missing from registry`,context:{fieldType:i,fieldName:t,operation:"minmax_computation",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"});return}const h=m==="range"&&(i==="date"||i==="datetime-local"||i==="timestamp"||i==="time"||i==="week"||i==="month"||i==="year"),F=m==="range"&&!h,x=i==="price";if(F||x){const n=c.map(l=>l[t]).filter(l=>l!=null&&l!=="").map(l=>x&&typeof l=="object"&&l!==null?Number(l.amount):typeof l=="number"?l:Number(l)).filter(l=>!isNaN(l));n.length>0&&(a[t]={min:Math.min(...n),max:Math.max(...n)})}else if(h){const n=c.map(l=>l[t]).filter(l=>l!=null&&l!=="").map(l=>l instanceof Date?l:new Date(l)).filter(l=>!isNaN(l.getTime()));if(n.length>0){const l=new Date(Math.min(...n.map(C=>C.getTime()))),E=new Date(Math.max(...n.map(C=>C.getTime()))),k=l.toISOString().split("T")[0],v=E.toISOString().split("T")[0];a[t]={min:k||"",max:v||""}}}}),a},[c,f.fields,g]),y=(a,t)=>{const o={...b};if(!t||t==="")delete o[a];else if(Array.isArray(t))o[a]=t;else if(typeof t=="object"&&"min"in t){const i=t.min&&t.min!=="",m=t.max&&t.max!=="";!i&&!m?delete o[a]:o[a]=t}else o[a]=t;A(o)},J=()=>{A({})},N=V(()=>g.length===0?null:g.map(a=>{const t=f.fields[a];if(!t)return null;const o=se(a,t,j),i=t.type||"text",m=$(i);if(!m)return B(new Error(`Field type "${i}" not registered in field type registry`),{userMessage:`Field type "${i}" is missing from registry`,context:{fieldType:i,fieldName:a,operation:"filter_ui_render",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"}),null;const h=m==="range"&&(i==="date"||i==="datetime-local"||i==="timestamp"||i==="time"||i==="week"||i==="month"||i==="year"),F=m==="range"&&!h,x=m==="select",n=b[a],l=typeof n=="object"&&n!==null&&"min"in n?n:{min:"",max:""};if(m==="rating"){const r=t.validation?.max??5,s=typeof n=="string"&&n!==""?Number(n):0;return d("div",{style:{gridColumn:"span 2",gridRow:"span 1"},children:d(te,{value:s,max:r,"aria-label":o,onChange:e=>{y(a,e===s?void 0:String(e))}})},a)}if(F){const r=H[a],s=r?.min??0,e=r?.max??100,u=l.min?Number(l.min):s,w=l.max?Number(l.max):e;return _(le,{gap:"tight",style:{gridColumn:"span 2"},children:[d(ae,{type:"number",label:o,minPlaceholder:p("filter.min",{defaultValue:"Min"}),maxPlaceholder:p("filter.max",{defaultValue:"Max"}),minValue:l.min||"",maxValue:l.max||"",actualMin:s,actualMax:e,onChange:(M,U)=>{y(a,{min:M,max:U})},onClear:()=>y(a,void 0)}),d(ie,{value:[u,w],min:s,max:e,step:1,onValueChange:M=>{y(a,{min:String(M[0]),max:String(M[1])})}})]},a)}if(h){const r=i==="week"||i==="month"||i==="year"?i:"date",s=(()=>{if(n){if(typeof n=="object"&&"min"in n){const e=n;return{min:e.min&&e.min.split("T")[0]||"",max:e.max&&e.max.split("T")[0]||""}}if(typeof n=="string"){const e=n.split("T")[0]||"";return{min:e,max:e}}}})();return d("div",{style:{gridColumn:"span 2",gridRow:"span 1"},children:d(ne,{label:o,fieldType:r,value:s,locale:X,onChange:e=>{if(!e){y(a,void 0);return}typeof e=="object"&&"min"in e&&y(a,{min:e.min||"",max:e.max||""})},tCrud:p})},a)}const E=x&&t.validation&&"options"in t.validation&&t.validation?Array.isArray(t.validation.options)?t.validation.options:typeof t.validation.options=="function"?t.validation.options():[]:[],k=R[a]||c,v=new Set,C=m==="address";k.forEach(r=>{const s=r[a];if(s!=null)if(C&&typeof s=="object"&&"formatted_address"in s){const e=s;e.formatted_address&&v.add(String(e.formatted_address))}else v.add(String(s))});const S=[{value:"all",label:p("filter.selectPlaceholder",{defaultValue:"All"})}];if(E.length>0){const r=[],s=[];E.forEach(e=>{const u=typeof e=="string"?e:e.value,w=typeof e=="string"?e:e.label;v.has(u)?r.push({value:u,label:w}):s.push({value:u,label:w})}),r.sort((e,u)=>e.label.localeCompare(u.label)),s.sort((e,u)=>e.label.localeCompare(u.label)),r.forEach(e=>{S.push({value:e.value,label:I(e.label,j),disabled:!1})}),s.forEach(e=>{S.push({value:e.value,label:I(e.label,j),disabled:!0})})}else Array.from(v).sort().slice(0,100).forEach(r=>{S.push({value:r,label:r})});return d("div",{style:{gridColumn:"span 1",gridRow:"span 1"},children:d(W,{label:o,value:typeof n=="string"?n:void 0,onValueChange:r=>{y(a,r==="all"||!r?"":String(r))},options:S,placeholder:p("filter.placeholder",{defaultValue:"Filter..."}),clearable:!0})},a)}),[g,f.fields,c,b,j,p,R]);if(!N||N.length===0)return null;const K=N.filter(Boolean),Q=Object.keys(b).length>0;return _(ee,{cols:P??(z?2:[2,4,4,6]),children:[K,d(Z,{variant:"outline",icon:d(Y,{size:18}),onClick:J,disabled:!Q,style:{gridColumn:"1 / -1",gridRow:"span 1"},children:p("filter.clear",{defaultValue:"Clear Filters"})})]})}export{ue as EntityFilters,de as matchesFilter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as t}from"react/jsx-runtime";import{Controller as p}from"react-hook-form";import{FileFieldComponent as f}from"../../form/fields";import{convertValidationRules as c}from"../types";function g(i){const{control:m,errors:r,fieldConfig:l,t:s}=i,{name:e,label:u,validation:o}=l,a=l.options||{};return t(p,{name:e,control:m,rules:o?c(o):void 0,render:({field:n})=>t(f,{name:e,label:s(u),value:n.value??null,onChange:d=>n.onChange(d),error:!!r[e],helperText:r[e]?.message,required:o?.required,multiple:!1,maxFiles:1,maxSize:a.maxSize,storagePath:a.storagePath})})}export{g as ControlledFileField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as t}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:l,fieldConfig:a,t:n}=s,{name:e,label:m,validation:o}=a,r=(a.options||{}).fieldSpecific;return t(f,{name:e,control:d,rules:o?c(o):void 0,render:({field:i})=>t(p,{label:n(m),value:i.value??0,onChange:u=>i.onChange(u),error:!!l[e],helperText:l[e]?.message,required:o?.required,disabled:i.disabled,min:r?.min??0,max:r?.max??480,step:r?.step??5,t:n})})}export{C as ControlledDurationField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as t,jsxs as g}from"react/jsx-runtime";import{Select as d,Stack as v}from"@donotdev/components";import{useTranslation as m}from"@donotdev/core";const f=({label:o,value:r,options:n,error:s,helperText:a,onChange:l,onBlur:i,required:u})=>{const{t:p}=m("crud"),c=r!=null?String(r):"";return g(v,{gap:"tight",children:[t(d,{label:o,value:c,onValueChange:e=>{l&&l({target:{value:e}})},onOpenChange:e=>!e&&i?.(),placeholder:p("actions.select","Select"),required:u,options:n.map(e=>({value:String(e.value),label:e.label}))}),a&&t("p",{style:{fontSize:"var(--font-size-xs)",color:s?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:a})]})};var h=f;export{h as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as o,jsxs as
|
|
1
|
+
import{jsx as o,jsxs as t,Fragment as q}from"react/jsx-runtime";import{useMemo as J,useId as M}from"react";import{Combobox as R,Tag as p,Stack as h}from"@donotdev/components";import{useTranslation as k}from"@donotdev/core";const d=4,v=3,B=({label:f,value:r=[],options:n,error:b,helperText:l,onChange:u,onBlur:S,required:x,className:y})=>{const{t:g}=k("crud"),m=M(),z=J(()=>n.map(e=>({value:String(e.value),label:e.label})),[n]),N=e=>{const s=Array.isArray(e)?e:[e],a={target:{value:JSON.stringify(s)}};u(a)},C=e=>{e||S?.()},O=e=>{const s=r.filter(c=>c!==e),a={target:{value:JSON.stringify(s)}};u(a)},i=!!b,A=`${m}-error`,T=`${m}-helper`,j=r.length>0?t(q,{children:[r.slice(0,r.length>d?v:d).map((e,s)=>{const a=n.find(c=>String(c.value)===e)?.label||e;return o(p,{size:"sm",onRemove:()=>O(e),children:a},s)}),r.length>d&&t(p,{size:"sm",variant:"outline",disabled:!0,children:["+",r.length-v," more"]})]}):void 0;return t(h,{gap:"tight",className:y,children:[o(R,{label:f,value:r,onValueChange:N,onOpenChange:C,placeholder:g("actions.selectOptions","Select options..."),emptyMessage:g("messages.noResults","No results found"),options:z,multiple:!0,required:x,variant:i?"destructive":void 0,chips:j}),i&&t(h,{id:A,direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)",color:"var(--destructive-foreground)"},role:"alert",children:[o("span",{children:"\u26A0"}),l]}),l&&!i&&o("p",{id:T,style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:l})]})};var I=B;export{I as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as i,jsxs as s}from"react/jsx-runtime";import{useState as L,useMemo as h,useEffect as k,useId as E}from"react";import{Input as M,FloatingLabel as O,Button as U,BUTTON_VARIANT as j,DropdownMenu as q,Stack as g,cn as D}from"@donotdev/components";import{Flag as z,COUNTRIES as y}from"@donotdev/core";const V=({label:
|
|
1
|
+
"use client";import{jsx as i,jsxs as s}from"react/jsx-runtime";import{useState as L,useMemo as h,useEffect as k,useId as E}from"react";import{Input as M,FloatingLabel as O,Button as U,BUTTON_VARIANT as j,DropdownMenu as q,Stack as g,cn as D}from"@donotdev/components";import{Flag as z,COUNTRIES as y}from"@donotdev/core";const V=({label:w,value:d="",onChange:C,error:R,helperText:f,required:S=!1,disabled:v=!1,defaultCountry:N="FR",showFlags:T=!0,preferredCountries:c,countries:m})=>{const o=E(),p=h(()=>m&&m.length>0?m.map(e=>y.find(r=>r.code===e)).filter(e=>e!==void 0):Array.from(y),[m]),n=h(()=>{if(!c||c.length===0)return p;const e=c.map(t=>p.find(I=>I.code===t)).filter(t=>t!==void 0),r=p.filter(t=>!c.includes(t.code));return[...e,...r]},[p,c]),u=h(()=>n.find(e=>e.code===N)||n[0]||y[0],[N,n]),{country:b,phoneNumber:$}=h(()=>{if(!d)return{country:u,phoneNumber:""};const e=n.find(t=>d.startsWith(t.dialCode));if(e){let t=d.slice(e.dialCode.length).trim();return t.startsWith("0")&&(t=t.slice(1).trim()),t=t.replace(/\s+/g," ").trim(),{country:e,phoneNumber:t}}if(d.startsWith("+"))return{country:u,phoneNumber:d};let r=d.trim();return r.startsWith("0")&&(r=r.slice(1).trim()),r=r.replace(/\s+/g," ").trim(),{country:u,phoneNumber:r}},[d,u,n]),[a,W]=L(u);k(()=>{b.code!==a.code&&W(b)},[b,a.code]);const x=$,A=e=>{W(e);let r=x;r.startsWith("0")&&(r=r.slice(1).trim()),r=r.replace(/\s+/g," ").trim();const t={target:{value:e.dialCode+(r?" "+r:"")}};C(t)},B=e=>{let r=e.target.value;r.startsWith("0")&&(r=r.slice(1).trim()),r=r.replace(/\s+/g," ").trim();const t={target:{value:a.dialCode+(r?" "+r:"")}};C(t)},F=n.map(e=>({label:e.dialCode,onClick:()=>A(e),checked:e.code===a.code,children:T?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(O,{htmlFor:o,label:w,disabled:v,required:S,children:s("div",{className:"dndev-relative",style:{display:"flex",gap:0},children:[i(q,{trigger:i(U,{type:"button",variant:j.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: ${a.dialCode}`,children:s(g,{direction:"row",align:"center",gap:"tight",children:[T&&i(z,{code:a.flagCode,title:a.name}),i("span",{children:a.dialCode})]})}),items:F,contentWidth:"16rem"}),i(M,{id:o,type:"tel",inputMode:"tel",value:x,onChange:B,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":D(l&&`${o}-error`,f&&!l&&`${o}-helper`),"aria-invalid":l})]})}),l&&s(g,{id:`${o}-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]}),f&&!l&&i("p",{id:`${o}-helper`,style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:f})]})};var _=V;export{_ as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as l}from"react/jsx-runtime";import{Label as h,Slider as b,Stack as d}from"@donotdev/components";const x=({label:
|
|
1
|
+
import{jsx as e,jsxs as l}from"react/jsx-runtime";import{Label as h,Slider as b,Stack as d}from"@donotdev/components";const x=({label:o,value:i=0,onChange:u,error:n,helperText:s,min:r=0,max:c=100,step:v=1,disabled:a,required:m,showValue:f=!0})=>{const g=t=>{const p={target:{value:t.toString()}};u(p)};return l(d,{gap:"tight",children:[l(d,{direction:"row",justify:"between",align:"center",children:[e(h,{required:m,style:{fontSize:"var(--font-size-sm)",fontWeight:500},children:o}),f&&e("span",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},children:i})]}),e(b,{value:[i??r],onValueChange:([t])=>g(t??r),min:r,max:c,step:v,disabled:a,style:{borderColor:n?"var(--destructive)":void 0,opacity:a?"var(--opacity-muted)":void 0,cursor:a?"not-allowed":void 0},"aria-label":o}),s&&e("p",{style:{fontSize:"var(--font-size-xs)",color:n?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:s})]})};var y=x;export{y as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as t,jsxs as
|
|
1
|
+
"use client";import{jsx as t,jsxs as l}from"react/jsx-runtime";import{useState as L,useId as N,useRef as F,useEffect as j}from"react";import{Textarea as q,FloatingLabel as A,Spinner as k,cn as m,Stack as p}from"@donotdev/components";const B=({label:x,value:o="",onChange:b,error:h,helperText:s,rows:y=3,loading:n=!1,maxLength:r,showCharCount:v=!1,autoResize:i=!1,required:z=!1,disabled:g=!1,className:$,...w})=>{const e=N(),[I,f]=L(!1),d=F(null),a=!!h,c=o.length,S=r&&c>r*.8,C=r&&c>r;return j(()=>{if(i&&d.current){const u=d.current;u.style.height="auto",u.style.height=`${u.scrollHeight}px`}},[o,i]),l(p,{gap:"tight",children:[t(A,{htmlFor:e,label:x,disabled:g||n,required:z,children:l("div",{className:"dndev-relative",children:[t(q,{ref:d,id:e,value:o,onChange:b,onFocus:()=>f(!0),onBlur:()=>f(!1),disabled:g||n,maxLength:r,rows:i?1:y,bare:!0,"aria-describedby":m(a&&`${e}-error`,s&&!a&&`${e}-helper`,v&&`${e}-count`),"aria-invalid":a,className:m("dndev-w-full",i&&"dndev-overflow-hidden",$),"data-variant":a?"destructive":void 0,style:{resize:i?"none":void 0},...w}),n&&t("div",{className:"dndev-absolute",style:{right:"var(--gap-md)",top:"var(--gap-md)"},children:t(k,{"aria-label":"Loading"})})]})}),v&&r&&l("div",{id:`${e}-count`,style:{fontSize:"var(--font-size-xs)",textAlign:"right",color:C?"var(--destructive-foreground)":S?"var(--warning)":"var(--muted-foreground)"},children:[c,"/",r]}),a&&l(p,{as:"p",id:`${e}-error`,direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)",color:"var(--destructive-foreground)"},role:"alert",children:[t("span",{children:"\u26A0"}),h]}),s&&!a&&t("p",{id:`${e}-helper`,style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:s})]})};var E=B;export{E as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useState as T,useCallback as v,useEffect as A,useRef as g,startTransition as q}from"react";import{handleError as C}from"@donotdev/core";import{useUploadContext as G}from"../contexts/UploadContext";import{useUploadStore as N}from"../stores/UploadStore";let P=0;function W(s){if(s){const u=s.split("/").pop()?.split("?")[0];if(u)return`file-${u}`}P+=1;const a=typeof performance<"u"?performance.now():Date.now(),p=Math.random().toString(36).slice(2,11);return`file-${P}-${a}-${p}`}function H(s){return URL.createObjectURL(s)}function k(s){s.startsWith("blob:")&&URL.revokeObjectURL(s)}function K(s,a,p){return a.length>0&&!a.some(u=>{if(u.endsWith("/*")){const
|
|
1
|
+
"use client";import{useState as T,useCallback as v,useEffect as A,useRef as g,startTransition as q}from"react";import{handleError as C}from"@donotdev/core";import{useUploadContext as G}from"../contexts/UploadContext";import{useUploadStore as N}from"../stores/UploadStore";let P=0;function W(s){if(s){const u=s.split("/").pop()?.split("?")[0];if(u)return`file-${u}`}P+=1;const a=typeof performance<"u"?performance.now():Date.now(),p=Math.random().toString(36).slice(2,11);return`file-${P}-${a}-${p}`}function H(s){return URL.createObjectURL(s)}function k(s){s.startsWith("blob:")&&URL.revokeObjectURL(s)}function K(s,a,p){return a.length>0&&!a.some(u=>{if(u.endsWith("/*")){const U=u.slice(0,-2);return s.type.startsWith(U)}return s.type===u})?{valid:!1,error:`File type ${s.type} not accepted`}:s.size>p?{valid:!1,error:`File exceeds ${(p/1048576).toFixed(0)}MB limit`}:{valid:!0}}function Q({name:s,value:a,onChange:p,multiple:u=!1,maxFiles:U=10,maxSize:$=10*1024*1024,accept:S=[],storagePath:V="uploads",uploadFn:y}){const h=G(),w=!!h,[d,c]=T([]),R=g(!1),E=g(null),x=g(a),L=g([]),F=g(!1),M=g(null);A(()=>{if(R.current){R.current=!1;return}const n=a?JSON.stringify((Array.isArray(a)?a:[a]).map(l=>l.fullUrl).filter(Boolean)):null;n!==E.current&&(E.current=n,x.current=a,q(()=>{if(a){const l=(Array.isArray(a)?a:[a]).filter(t=>t.fullUrl).map((t,r)=>({id:`${W(t.fullUrl)}-existing-${r}`,file:new File([],"existing"),previewURL:t.thumbUrl||t.fullUrl,progress:100,uploaded:t,error:null}));c(l)}else c([])}))},[a]),A(()=>{L.current=d},[d]),A(()=>{F.current&&(F.current=!1,M.current?.(d,!0))},[d]),A(()=>()=>{L.current.forEach(n=>k(n.previewURL))},[]);const f=v((n,l=!1)=>{const t=(l?n.filter(i=>!i.error):n.filter(i=>i.uploaded&&!i.error)).map(i=>i.uploaded?i.uploaded:l&&w?{fullUrl:i.previewURL,thumbUrl:i.previewURL}:null).filter(i=>i!==null);let r;u?r=t.length>0?t:null:r=t[0]||null;const e=x.current;(()=>{if(!r&&!e)return!1;if(!r||!e)return!0;if(u&&Array.isArray(r)&&Array.isArray(e)){if(r.length!==e.length)return!0;const i=r.map(m=>m.fullUrl).join(","),o=e.map(m=>m.fullUrl).join(",");return i!==o}return!u&&!Array.isArray(r)&&!Array.isArray(e)?r.fullUrl!==e.fullUrl:!0})()&&(R.current=!0,x.current=r,p(r))},[u,p,w]);M.current=f;const b=v(async()=>{if(!y)return;let n=[];if(c(t=>(n=t.filter(r=>!r.uploaded&&!r.error),n.length===0?t:t.map(r=>n.some(e=>e.id===r.id)?{...r,progress:0}:r))),n.length===0)return;const l=await Promise.allSettled(n.map(async t=>{try{const r=await y(t.file,e=>{c(i=>i.map(o=>o.id===t.id?{...o,progress:e}:o))});return{id:t.id,picture:r,error:null}}catch(r){const e=r instanceof Error?r.message:"Upload failed";return{id:t.id,picture:null,error:e}}}));c(t=>{const r=t.map(e=>{const i=l.find(o=>o.status==="fulfilled"&&o.value.id===e.id);if(i&&i.status==="fulfilled"){const o=i.value;return{...e,uploaded:o.picture,progress:o.picture?100:null,error:o.error}}return e});return f(r,!1),r})},[y,f]),j=g(b);j.current=b,A(()=>{if(!(!h||!s))return N.getState().registerUpload(h,s,async()=>{await j.current()},()=>L.current.some(n=>!n.uploaded&&!n.error)),()=>{N.getState().unregisterUpload(h,s)}},[h,s]);const O=v(async n=>{if(y){c(l=>l.map(t=>t.id===n.id?{...t,progress:0}:t));try{const l=await y(n.file,t=>{c(r=>r.map(e=>e.id===n.id?{...e,progress:t}:e))});c(t=>{const r=t.map(e=>e.id===n.id?{...e,uploaded:l,progress:100,error:null}:e);return f(r,!1),r})}catch(l){const t=l instanceof Error?l.message:"Upload failed";c(r=>r.map(e=>e.id===n.id?{...e,error:t,progress:null}:e))}}},[y,f]),z=v(n=>{c(l=>{const t=(u?U:1)-l.length;if(t<=0)return C(new Error("Maximum files reached"),{userMessage:u?`Maximum ${U} files allowed`:"Only one file allowed",severity:"warning",showNotification:!0}),l;const r=n.slice(0,t),e=[];for(const o of r){const m=K(o,S,$);if(!m.valid){C(new Error(m.error),{userMessage:m.error,severity:"warning",showNotification:!0});continue}e.push({id:W(),file:o,previewURL:H(o),progress:null,uploaded:null,error:null})}if(e.length===0)return l;const i=u?[...l,...e]:e;return w?F.current=!0:e.forEach(o=>O(o)),i})},[u,U,S,$,w,O,f]),B=v(n=>{c(l=>{const t=l.find(e=>e.id===n);t&&k(t.previewURL);const r=l.filter(e=>e.id!==n);return f(r,!1),r})},[f]),D=d.some(n=>!n.uploaded&&!n.error),I=d.some(n=>n.progress!==null&&n.progress<100),J=d.length>0?d.reduce((n,l)=>n+(l.progress??0),0)/d.length:0;return{files:d,addFiles:z,removeFile:B,hasPending:D,isUploading:I,progress:J,formId:h,isDeferred:w}}export{Q as useFileUpload};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerBuiltinFieldTypes.d.ts","sourceRoot":"","sources":["../src/registerBuiltinFieldTypes.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"registerBuiltinFieldTypes.d.ts","sourceRoot":"","sources":["../src/registerBuiltinFieldTypes.tsx"],"names":[],"mappings":"AAgFA,OAAO,KAAK,EACV,iBAAiB,EAElB,MAAM,2BAA2B,CAAC;AA0zBnC;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,EAChD,aAAa,EAAE;IACb,iBAAiB,EAAE,CACjB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,GAAG,EACf,YAAY,CAAC,EAAE,GAAG,KACf,IAAI,CAAC;CACX,GACA,IAAI,CAuuBN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as p,jsxs as f}from"react/jsx-runtime";import{Text as m,Stack as b,ImageGallery as V,Rating as L,CopyToClipboard as w}from"@donotdev/components";import{formatCurrency as F,maybeTranslate as $}from"@donotdev/core";import{ControlledCheckboxField as k,ControlledComboboxField as I,ControlledDateField as h,ControlledDropdownField as N,ControlledFileField as M,ControlledMultiFileField as P,ControlledDocumentField as R,ControlledMultiDocumentField as B,ControlledGeoPointField as _,ControlledImageField as E,ControlledMapField as U,ControlledMultiDropdownField as H,ControlledMultiInputField as K,ControlledNumberField as Y,ControlledPasswordField as G,ControlledPhoneField as O,ControlledRangeField as J,ControlledRatingField as W,ControlledDurationField as q,ControlledRadioField as Q,ControlledReferenceField as X,ControlledYearField as Z,ControlledTextField as g,ControlledTextareaField as ee,ControlledRichTextField as te,ControlledTimestampField as re,ControlledAddressField as ne,ControlledFieldArrayField as oe,ControlledSwitchField as le,ControlledMultiImageField as ae,ControlledGdprConsentField as ie,ControlledCurrencyField as ce,ControlledPriceField as se}from"./components/controlled";import{AvatarFieldComponent as pe,BadgeFieldComponent as de,ButtonFieldComponent as A,HiddenFieldComponent as ue,TextAreaComponent as ye,RichTextComponent as fe,TextFieldComponent as T}from"./components/form/fields";import{translateLabel as v}from"./forms/utils";import{sanitizeHtml as me}from"./utils/sanitizeHtml";function d(e){return e?p("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):p(m,{variant:"muted",children:"\u2014"})}const i={timestamp:(e,a,r,n)=>{const t=n?.compact??!1;if(e==null||e==="")return d(t);try{return(e instanceof Date?e:new Date(e)).toLocaleString()}catch{return String(e)}},date:(e,a,r,n)=>{const t=n?.compact??!1;if(e==null||e==="")return d(t);try{return(e instanceof Date?e:new Date(e)).toLocaleDateString()}catch{return String(e)}},"datetime-local":(e,a,r,n)=>{const t=n?.compact??!1;if(e==null||e==="")return d(t);try{return(e instanceof Date?e:new Date(e)).toLocaleString()}catch{return String(e)}},time:(e,a,r,n)=>{const t=n?.compact??!1;if(e==null||e==="")return d(t);try{return(e instanceof Date?e:new Date(e)).toLocaleTimeString()}catch{return String(e)}},week:(e,a,r,n)=>{const t=n?.compact??!1;return e==null||e===""?d(t):String(e)},month:(e,a,r,n)=>{const t=n?.compact??!1;return e==null||e===""?d(t):String(e)},boolean:(e,a,r)=>e?"Yes":"No",checkbox:(e,a,r)=>e?"Yes":"No",switch:(e,a,r)=>{const n=a.options?.fieldSpecific;if(n){const t=n.uncheckedValue??!1,o=n.checkedValue??!0;if(e===o&&n.checkedLabel)return v(n.checkedLabel,r);if(e===t&&n.uncheckedLabel)return v(n.uncheckedLabel,r)}return e?"Yes":"No"},year:(e,a,r)=>String(e),number:(e,a,r)=>{if(e==null||e==="")return"\u2014";const n=a.options?.unit??"",t=$(r,a.options?.suffix);return[(typeof e=="number"?e.toLocaleString():String(e))+n,t].filter(Boolean).join(" ")},currency:(e,a,r)=>{if(e==null||isNaN(e))return"";const n=(a.options||{}).fieldSpecific?.currency||"EUR";return F(e,n)},price:(e,a,r,n)=>{const t=n?.compact??!1,o=n?.asString??!1,l=e!=null&&typeof e=="number"?{amount:e,currency:"EUR",vatIncluded:!0,discountPercent:0}:e;if(l==null||typeof l!="object")return d(t);const c=l.amount;if(c==null||isNaN(c))return d(t);const s=l.currency||"EUR",y=l.vatIncluded??!0,u=l.discountPercent??0,x=u>0?c*(1-u/100):c,C=y?` ${r("crud:price.vatIncluded",{defaultValue:"VAT Incl."})}`:"";if(u>0){const z=F(c,s),S=F(x,s),j=` ${r("crud:price.discountPercent",{percent:Math.round(u),defaultValue:"-{{percent}}%"})}`;return o?`${S}${C}${j}`:t?f(m,{variant:"success",weight:"bold",children:[S,C,j]}):f(b,{direction:"column",gap:"tight",align:"end",children:[p(m,{variant:"muted",style:{textDecoration:"line-through",fontSize:"var(--font-size-sm)"},children:z}),f(m,{variant:"success",weight:"bold",children:[S,C]})]})}return`${F(c,s)}${C}`},range:(e,a,r)=>typeof e=="number"?e.toLocaleString():String(e),rating:(e,a,r,n)=>{const t=n?.compact??!1;if(e==null)return d(t);const o=typeof e=="number"?e:parseFloat(e);if(isNaN(o))return d(t);const l=a.validation?.max??5;return p(L,{value:o,max:l,readonly:!0,"aria-label":`${o} out of ${l} stars`})},duration:(e,a,r,n)=>{const t=n?.compact??!1;if(e==null)return d(t);const o=typeof e=="number"?e:parseInt(String(e),10);if(Number.isNaN(o))return d(t);if(o===0)return r("crud:duration.zero",{defaultValue:"\u2014"});if(o<60)return r("crud:duration.minutes",{count:o,defaultValue:`${o} min`});const l=Math.floor(o/60),c=o%60;return r("crud:duration.hoursMinutes",{hours:l,minutes:c,defaultValue:c===0?`${l}h`:`${l}h ${c}min`})},gdprConsent:(e,a,r,n)=>{const t=n?.compact??!1;if(!e||typeof e!="object")return d(t);const o=e.gdprConsent===!0,l=e.gdprConsentDate,c=e.gdprConsentVersion,s=r("crud:gdprConsent.display.yes",{defaultValue:"Consented"}),y=r("crud:gdprConsent.display.no",{defaultValue:"Not consented"});if(!o)return y;const u=[s];if(l)try{const x=new Date(l);u.push(x.toLocaleDateString())}catch{u.push(l)}return c&&u.push(`v${c}`),u.join(" \xB7 ")},select:(e,a,r)=>{const n=a.validation?.options;if(Array.isArray(n)){const t=n.find(o=>o.value===e)?.label;return t?v(t,r):String(e)}return String(e)},radio:(e,a,r)=>{const n=a.validation?.options;if(Array.isArray(n)){const t=n.find(o=>o.value===e)?.label;return t?v(t,r):String(e)}return String(e)},combobox:(e,a,r)=>{const n=a.validation?.options;if(Array.isArray(n)){const t=n.find(o=>o.value===e)?.label;return t?v(t,r):String(e)}return String(e)},multiselect:(e,a,r)=>{if(Array.isArray(e)){const n=a.validation?.options;if(Array.isArray(n))return e.map(t=>{const o=n.find(l=>l.value===t)?.label;return o?v(o,r):t}).join(", ")}return String(e)},image:(e,a,r,n)=>{const t=n?.compact??!1;return e==null||e===""?d(t):typeof e=="string"?p("img",{src:e,alt:a.label||"",style:{width:t?"40px":void 0,height:t?"40px":void 0,maxWidth:t?void 0:"200px",maxHeight:t?void 0:"150px",objectFit:"cover",borderRadius:"var(--radius-sm)"}}):d(t)},images:(e,a,r,n)=>{const t=n?.compact??!1;if(!Array.isArray(e)||e.length===0)return d(t);const o=e[0],l=typeof o=="object"&&o.thumbUrl?o.thumbUrl:o;return t?f("div",{style:{display:"flex",alignItems:"center",gap:"var(--gap-xs)"},children:[p("img",{src:l,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(V,{images:e,altPrefix:a.label||"Image"})},files:(e,a,r,n)=>{const t=n?.compact??!1;return!Array.isArray(e)||e.length===0?d(t):p(b,{gap:"tight",children:e.map((o,l)=>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 ${l+1}`,o.size&&f(m,{level:"caption",variant:"muted",style:{marginLeft:"var(--gap-sm)"},children:["(",Math.round(o.size/1024)," KB)"]})]},l))})},documents:(e,a,r,n)=>{const t=n?.compact??!1;return!Array.isArray(e)||e.length===0?d(t):p(b,{gap:"tight",children:e.map((o,l)=>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 ${l+1}`,o.size&&f(m,{level:"caption",variant:"muted",style:{marginLeft:"var(--gap-sm)"},children:["(",Math.round(o.size/1024)," KB)"]})]},l))})},file:(e,a,r,n)=>{const t=n?.compact??!1;if(!e)return d(t);const o=typeof e=="string"?e:e.url,l=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:[l,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,a,r,n)=>{const t=n?.compact??!1;if(!e)return d(t);const o=typeof e=="string"?e:e.url,l=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:[l,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,a,r,n)=>{const t=n?.compact??!1;if(!e)return d(t);const o=a.validation?.reference;if(n?.referenceData&&typeof o=="string"){const l=n.referenceData[o]?.[String(e)];if(l)return l}if(typeof e=="object"&&e!==null){const l=e.displayName||e.name||e.id||String(e);return String(l)}return String(e)},geopoint:(e,a,r,n)=>{const t=n?.compact??!1;return e&&typeof e=="object"&&"lat"in e&&"lng"in e?`${e.lat.toFixed(6)}, ${e.lng.toFixed(6)}`:d(t)},address:(e,a,r)=>e&&typeof e=="object"&&"formatted_address"in e?e.formatted_address:String(e),map:(e,a,r,n)=>{const t=n?.compact??!1;if(e&&typeof e=="object"){const o=Object.entries(e);return o.length===0?d(t):f(b,{direction:"column",gap:"tight",children:[o.slice(0,5).map(([l,c])=>f(m,{style:{fontSize:"var(--font-size-sm)"},children:[f("strong",{children:[l,":"]})," ",String(c)]},l)),o.length>5&&f(m,{variant:"muted",children:["+",o.length-5," more"]})]})}return d(t)},array:(e,a,r,n)=>{const t=n?.compact??!1;return Array.isArray(e)?e.length===0?d(t):e.join(", "):d(t)},"field-array":(e,a,r,n)=>{const t=n?.compact??!1;if(!Array.isArray(e)||e.length===0)return d(t);const o=a.options?.fieldSpecific?.fields;return e.map(l=>{if(typeof l!="object"||l==null)return"";const c=l;return(o?o.map(s=>s.name):Object.keys(c)).map(s=>c[s]).filter(s=>s!=null&&s!=="").map(s=>typeof s=="object"?JSON.stringify(s):String(s)).join(" \xB7 ")}).filter(Boolean).join(", ")},password:()=>"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",email:(e,a,r)=>f(b,{direction:"row",gap:"tight",align:"center",children:[p("a",{href:`mailto:${e}`,style:{color:"var(--primary)",flex:1},onClick:n=>n.stopPropagation(),children:e}),p(w,{text:e,tooltipText:r("crud:copyToClipboard",{defaultValue:"Copy to clipboard"}),ariaLabel:r("crud:actions.copyEmail",{defaultValue:"Copy email"}),onClick:n=>n.stopPropagation()})]}),tel:(e,a,r)=>f(b,{direction:"row",gap:"tight",align:"center",children:[p("a",{href:`tel:${e}`,style:{color:"var(--primary)",flex:1},onClick:n=>n.stopPropagation(),children:e}),p(w,{text:e,tooltipText:r("crud:copyToClipboard",{defaultValue:"Copy to clipboard"}),ariaLabel:r("crud:actions.copyPhone",{defaultValue:"Copy phone"}),onClick:n=>n.stopPropagation()})]}),iban:(e,a,r,n)=>{const t=n?.compact??!1;return e?f(b,{direction:"row",gap:"tight",align:"center",children:[p(m,{style:{flex:1},children:e}),p(w,{text:e,tooltipText:r("crud:copyToClipboard",{defaultValue:"Copy to clipboard"}),ariaLabel:r("crud:actions.copyIban",{defaultValue:"Copy IBAN"}),onClick:o=>o.stopPropagation()})]}):d(t)},url:(e,a,r)=>p("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--primary)"},children:e}),color:(e,a,r)=>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(m,{children:e})]}),textarea:(e,a,r)=>String(e),text:(e,a,r)=>String(e),richtext:(e,a,r,n)=>{const t=n?.compact??!1;return e&&typeof e=="string"?t?e.replace(/<[^>]*>/g,"").trim()||p("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):p("div",{dangerouslySetInnerHTML:{__html:me(e)},style:{padding:"var(--gap-sm)",fontSize:"var(--font-size-sm)",lineHeight:"1.6"}}):d(t)}};function ge(e){return e.type==="avatar"}function be(e){return e.type==="badge"}let D=!1;function ve(e,a){if(D)return;D=!0;const r=n=>{const{type:t,components:o}=n;o&&a.registerComponent(t,o.controlled,o.uncontrolled),e.set(t,n)};r({type:"text",filterable:!0,filterType:"text",valueType:"string",displayFormatter:i.text,components:{controlled:g,uncontrolled:n=>{const{value:t,onChange:o,label:l,error:c,config:s}=n;return p(T,{label:l||"",value:typeof t=="string"?t:"",onChange:y=>{const u=y.target.value;o(u)},error:c,...s.options})}}}),r({type:"email",filterable:!0,filterType:"text",valueType:"string",displayFormatter:i.email,components:{controlled:g,uncontrolled:n=>{const{value:t,onChange:o,label:l,error:c,config:s}=n;return p(T,{label:l||"",value:typeof t=="string"?t:"",onChange:y=>{const u=y.target.value;o(u)},error:c,type:"email",...s.options})}}}),r({type:"url",filterable:!0,filterType:"text",valueType:"string",displayFormatter:i.url,components:{controlled:g,uncontrolled:n=>{const{value:t,onChange:o,label:l,error:c,config:s}=n;return p(T,{label:l||"",value:typeof t=="string"?t:"",onChange:y=>{const u=y.target.value;o(u)},error:c,type:"url",...s.options})}}}),r({type:"color",filterable:!0,filterType:"text",valueType:"string",displayFormatter:i.color,components:{controlled:g,uncontrolled:n=>{const{value:t,onChange:o,label:l,error:c,config:s}=n;return p(T,{label:l||"",value:typeof t=="string"?t:"",onChange:y=>{const u=y.target.value;o(u)},error:c,type:"color",...s.options})}}}),r({type:"textarea",filterable:!0,filterType:"text",valueType:"string",displayFormatter:i.textarea,components:{controlled:ee,uncontrolled:n=>{const{value:t,onChange:o,label:l,error:c,config:s}=n;return p(ye,{label:l||"",value:typeof t=="string"?t:"",onChange:y=>{const u=y.target.value;o(u)},error:c,...s.options})}}}),r({type:"richtext",filterable:!0,filterType:"text",valueType:"string",displayFormatter:i.richtext,components:{controlled:te,uncontrolled:n=>{const{value:t,onChange:o,label:l,error:c,config:s}=n;return p(fe,{label:l||"",value:typeof t=="string"?t:"",onChange:y=>{const u=y.target.value;o(u)},error:c,...s.options})}}}),r({type:"password",filterable:!1,filterType:"none",valueType:"string",displayFormatter:i.password,components:{controlled:G}}),r({type:"tel",filterable:!0,filterType:"text",valueType:"string",displayFormatter:i.tel,components:{controlled:O}}),r({type:"iban",filterable:!0,filterType:"text",valueType:"string",displayFormatter:i.iban,components:{controlled:g,uncontrolled:n=>{const{value:t,onChange:o,label:l,error:c,config:s}=n;return p(T,{label:l||"",value:typeof t=="string"?t:"",onChange:y=>{const u=y.target.value.replace(/\s/g,"").toUpperCase();o(u)},error:c,...s.options})}}}),r({type:"number",filterable:!0,filterType:"range",valueType:"number",displayFormatter:i.number,components:{controlled:Y}}),r({type:"currency",filterable:!0,filterType:"range",valueType:"number",displayFormatter:i.currency,components:{controlled:ce}}),r({type:"price",filterable:!0,filterType:"range",valueType:"object",displayFormatter:i.price,components:{controlled:se}}),r({type:"range",filterable:!0,filterType:"range",valueType:"number",displayFormatter:i.range,components:{controlled:J}}),r({type:"year",filterable:!0,filterType:"range",valueType:"number",displayFormatter:i.year,components:{controlled:Z}}),r({type:"rating",filterable:!0,filterType:"rating",valueType:"number",displayFormatter:i.rating,components:{controlled:W}}),r({type:"duration",filterable:!0,filterType:"range",valueType:"number",displayFormatter:i.duration,components:{controlled:q}}),r({type:"boolean",filterable:!0,filterType:"select",valueType:"boolean",displayFormatter:i.boolean,components:{controlled:k}}),r({type:"checkbox",filterable:!0,filterType:"select",valueType:"boolean",displayFormatter:i.checkbox,components:{controlled:k}}),r({type:"gdprConsent",filterable:!0,filterType:"select",valueType:"object",displayFormatter:i.gdprConsent,components:{controlled:ie}}),r({type:"switch",filterable:!0,filterType:"select",valueType:"boolean",displayFormatter:i.switch,components:{controlled:le}}),r({type:"date",filterable:!0,filterType:"range",valueType:"date",displayFormatter:i.date,components:{controlled:h}}),r({type:"datetime-local",filterable:!0,filterType:"range",valueType:"date",displayFormatter:i["datetime-local"],components:{controlled:h}}),r({type:"time",filterable:!0,filterType:"range",valueType:"date",displayFormatter:i.time,components:{controlled:h}}),r({type:"week",filterable:!0,filterType:"range",valueType:"date",displayFormatter:i.week,components:{controlled:h}}),r({type:"month",filterable:!0,filterType:"range",valueType:"date",displayFormatter:i.month,components:{controlled:h}}),r({type:"timestamp",filterable:!0,filterType:"range",valueType:"date",displayFormatter:i.timestamp,components:{controlled:re}}),r({type:"file",filterable:!1,filterType:"none",valueType:"object",displayFormatter:i.file,components:{controlled:M}}),r({type:"files",filterable:!1,filterType:"none",valueType:"array",displayFormatter:i.files,components:{controlled:P}}),r({type:"document",filterable:!1,filterType:"none",valueType:"object",displayFormatter:i.document,components:{controlled:R}}),r({type:"documents",filterable:!1,filterType:"none",valueType:"array",displayFormatter:i.documents,components:{controlled:B}}),r({type:"image",filterable:!1,filterType:"none",valueType:"object",displayFormatter:i.image,components:{controlled:E}}),r({type:"images",filterable:!1,filterType:"none",valueType:"array",displayFormatter:i.images,components:{controlled:ae}}),r({type:"geopoint",filterable:!1,filterType:"none",valueType:"object",displayFormatter:i.geopoint,components:{controlled:_}}),r({type:"address",filterable:!0,filterType:"address",valueType:"object",displayFormatter:i.address,components:{controlled:ne}}),r({type:"map",filterable:!1,filterType:"none",valueType:"object",displayFormatter:i.map,components:{controlled:U}}),r({type:"array",filterable:!1,filterType:"none",valueType:"array",displayFormatter:i.array,components:{controlled:K}}),r({type:"field-array",filterable:!1,filterType:"none",valueType:"array",displayFormatter:i["field-array"],components:{controlled:oe}}),r({type:"select",filterable:!0,filterType:"select",valueType:"string",displayFormatter:i.select,components:{controlled:N}}),r({type:"combobox",filterable:!0,filterType:"select",valueType:"string",displayFormatter:i.combobox,components:{controlled:I}}),r({type:"multiselect",filterable:!0,filterType:"multiselect",valueType:"array",displayFormatter:i.multiselect,components:{controlled:H}}),r({type:"radio",filterable:!0,filterType:"select",valueType:"string",displayFormatter:i.radio,components:{controlled:Q}}),r({type:"reference",filterable:!0,filterType:"text",valueType:"string",displayFormatter:i.reference,components:{controlled:X}}),r({type:"hidden",filterable:!1,filterType:"none",valueType:"string",components:{controlled:g,uncontrolled:n=>{const{name:t,value:o}=n;return p(ue,{name:t,value:typeof o=="string"?o:""})}}}),r({type:"avatar",filterable:!1,filterType:"none",valueType:"string",components:{controlled:g,uncontrolled:n=>{const{value:t,onChange:o,error:l,config:c,t:s}=n;if(!ge(c))throw new Error("Invalid config type for avatar field");return p(pe,{config:c,value:typeof t=="string"?t:"",onChange:y=>{o(y)},error:!!l,helperText:l||void 0,t:s,...c.options})}}}),r({type:"badge",filterable:!1,filterType:"none",valueType:"string",components:{controlled:g,uncontrolled:n=>{const{value:t,onChange:o,error:l,config:c,t:s}=n;if(!be(c))throw new Error("Invalid config type for badge field");return p(de,{config:c,value:typeof t=="string"?t:"",onChange:y=>{o(y)},error:!!l,helperText:l||void 0,t:s,...c.options})}}}),r({type:"submit",filterable:!1,filterType:"none",valueType:"string",components:{controlled:g,uncontrolled:n=>{const{name:t,label:o,config:l}=n;return p(A,{label:o||t,type:"submit",onClick:()=>{},...l.options})}}}),r({type:"reset",filterable:!1,filterType:"none",valueType:"string",components:{controlled:g,uncontrolled:n=>{const{name:t,label:o,config:l}=n;return p(A,{label:o||t,type:"reset",onClick:()=>{},...l.options})}}})}export{ve as registerAllBuiltinFieldTypes};
|
|
1
|
+
"use client";import{jsx as p,jsxs as f}from"react/jsx-runtime";import{Text as m,Stack as b,ImageGallery as V,Rating as L,CopyToClipboard as w}from"@donotdev/components";import{formatCurrency as F}from"@donotdev/core";import{ControlledCheckboxField as k,ControlledComboboxField as $,ControlledDateField as h,ControlledDropdownField as I,ControlledFileField as N,ControlledMultiFileField as M,ControlledDocumentField as P,ControlledMultiDocumentField as R,ControlledGeoPointField as B,ControlledImageField as _,ControlledMapField as E,ControlledMultiDropdownField as U,ControlledMultiInputField as H,ControlledNumberField as K,ControlledPasswordField as Y,ControlledPhoneField as G,ControlledRangeField as O,ControlledRatingField as J,ControlledDurationField as W,ControlledRadioField as q,ControlledReferenceField as Q,ControlledYearField as X,ControlledTextField as g,ControlledTextareaField as Z,ControlledRichTextField as ee,ControlledTimestampField as te,ControlledAddressField as re,ControlledFieldArrayField as oe,ControlledSwitchField as ne,ControlledMultiImageField as le,ControlledGdprConsentField as ae,ControlledCurrencyField as ie,ControlledPriceField as ce}from"./components/controlled";import{AvatarFieldComponent as se,BadgeFieldComponent as pe,ButtonFieldComponent as A,HiddenFieldComponent as de,TextAreaComponent as ue,RichTextComponent as ye,TextFieldComponent as T}from"./components/form/fields";import{translateLabel as v}from"./forms/utils";import{sanitizeHtml as fe}from"./utils/sanitizeHtml";function d(e){return e?p("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):p(m,{variant:"muted",children:"\u2014"})}const i={timestamp:(e,a,r,o)=>{const t=o?.compact??!1;if(e==null||e==="")return d(t);try{return(e instanceof Date?e:new Date(e)).toLocaleString()}catch{return String(e)}},date:(e,a,r,o)=>{const t=o?.compact??!1;if(e==null||e==="")return d(t);try{return(e instanceof Date?e:new Date(e)).toLocaleDateString()}catch{return String(e)}},"datetime-local":(e,a,r,o)=>{const t=o?.compact??!1;if(e==null||e==="")return d(t);try{return(e instanceof Date?e:new Date(e)).toLocaleString()}catch{return String(e)}},time:(e,a,r,o)=>{const t=o?.compact??!1;if(e==null||e==="")return d(t);try{return(e instanceof Date?e:new Date(e)).toLocaleTimeString()}catch{return String(e)}},week:(e,a,r,o)=>{const t=o?.compact??!1;return e==null||e===""?d(t):String(e)},month:(e,a,r,o)=>{const t=o?.compact??!1;return e==null||e===""?d(t):String(e)},boolean:(e,a,r)=>e?"Yes":"No",checkbox:(e,a,r)=>e?"Yes":"No",switch:(e,a,r)=>{const o=a.options?.fieldSpecific;if(o){const t=o.uncheckedValue??!1,n=o.checkedValue??!0;if(e===n&&o.checkedLabel)return v(o.checkedLabel,r);if(e===t&&o.uncheckedLabel)return v(o.uncheckedLabel,r)}return e?"Yes":"No"},year:(e,a,r)=>String(e),number:e=>e==null||e===""?"\u2014":typeof e=="number"?e.toLocaleString():String(e),currency:(e,a,r)=>{if(e==null||isNaN(e))return"";const o=(a.options||{}).fieldSpecific?.currency||"EUR";return F(e,o)},price:(e,a,r,o)=>{const t=o?.compact??!1,n=o?.asString??!1,l=e!=null&&typeof e=="number"?{amount:e,currency:"EUR",vatIncluded:!0,discountPercent:0}:e;if(l==null||typeof l!="object")return d(t);const c=l.amount;if(c==null||isNaN(c))return d(t);const s=l.currency||"EUR",y=l.vatIncluded??!0,u=l.discountPercent??0,x=u>0?c*(1-u/100):c,C=y?` ${r("crud:price.vatIncluded",{defaultValue:"VAT Incl."})}`:"";if(u>0){const z=F(c,s),S=F(x,s),j=` ${r("crud:price.discountPercent",{percent:Math.round(u),defaultValue:"-{{percent}}%"})}`;return n?`${S}${C}${j}`:t?f(m,{variant:"success",weight:"bold",children:[S,C,j]}):f(b,{direction:"column",gap:"tight",align:"end",children:[p(m,{variant:"muted",style:{textDecoration:"line-through",fontSize:"var(--font-size-sm)"},children:z}),f(m,{variant:"success",weight:"bold",children:[S,C]})]})}return`${F(c,s)}${C}`},range:(e,a,r)=>typeof e=="number"?e.toLocaleString():String(e),rating:(e,a,r,o)=>{const t=o?.compact??!1;if(e==null)return d(t);const n=typeof e=="number"?e:parseFloat(e);if(isNaN(n))return d(t);const l=a.validation?.max??5;return p(L,{value:n,max:l,readonly:!0,"aria-label":`${n} out of ${l} stars`})},duration:(e,a,r,o)=>{const t=o?.compact??!1;if(e==null)return d(t);const n=typeof e=="number"?e:parseInt(String(e),10);if(Number.isNaN(n))return d(t);if(n===0)return r("crud:duration.zero",{defaultValue:"\u2014"});if(n<60)return r("crud:duration.minutes",{count:n,defaultValue:`${n} min`});const l=Math.floor(n/60),c=n%60;return r("crud:duration.hoursMinutes",{hours:l,minutes:c,defaultValue:c===0?`${l}h`:`${l}h ${c}min`})},gdprConsent:(e,a,r,o)=>{const t=o?.compact??!1;if(!e||typeof e!="object")return d(t);const n=e.gdprConsent===!0,l=e.gdprConsentDate,c=e.gdprConsentVersion,s=r("crud:gdprConsent.display.yes",{defaultValue:"Consented"}),y=r("crud:gdprConsent.display.no",{defaultValue:"Not consented"});if(!n)return y;const u=[s];if(l)try{const x=new Date(l);u.push(x.toLocaleDateString())}catch{u.push(l)}return c&&u.push(`v${c}`),u.join(" \xB7 ")},select:(e,a,r)=>{const o=a.validation?.options;if(Array.isArray(o)){const t=o.find(n=>n.value===e)?.label;return t?v(t,r):String(e)}return String(e)},radio:(e,a,r)=>{const o=a.validation?.options;if(Array.isArray(o)){const t=o.find(n=>n.value===e)?.label;return t?v(t,r):String(e)}return String(e)},combobox:(e,a,r)=>{const o=a.validation?.options;if(Array.isArray(o)){const t=o.find(n=>n.value===e)?.label;return t?v(t,r):String(e)}return String(e)},multiselect:(e,a,r)=>{if(Array.isArray(e)){const o=a.validation?.options;if(Array.isArray(o))return e.map(t=>{const n=o.find(l=>l.value===t)?.label;return n?v(n,r):t}).join(", ")}return String(e)},image:(e,a,r,o)=>{const t=o?.compact??!1;return e==null||e===""?d(t):typeof e=="string"?p("img",{src:e,alt:a.label||"",style:{width:t?"40px":void 0,height:t?"40px":void 0,maxWidth:t?void 0:"200px",maxHeight:t?void 0:"150px",objectFit:"cover",borderRadius:"var(--radius-sm)"}}):d(t)},images:(e,a,r,o)=>{const t=o?.compact??!1;if(!Array.isArray(e)||e.length===0)return d(t);const n=e[0],l=typeof n=="object"&&n.thumbUrl?n.thumbUrl:n;return t?f("div",{style:{display:"flex",alignItems:"center",gap:"var(--gap-xs)"},children:[p("img",{src:l,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(V,{images:e,altPrefix:a.label||"Image"})},files:(e,a,r,o)=>{const t=o?.compact??!1;return!Array.isArray(e)||e.length===0?d(t):p(b,{gap:"tight",children:e.map((n,l)=>f("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 ${l+1}`,n.size&&f(m,{level:"caption",variant:"muted",style:{marginLeft:"var(--gap-sm)"},children:["(",Math.round(n.size/1024)," KB)"]})]},l))})},documents:(e,a,r,o)=>{const t=o?.compact??!1;return!Array.isArray(e)||e.length===0?d(t):p(b,{gap:"tight",children:e.map((n,l)=>f("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 ${l+1}`,n.size&&f(m,{level:"caption",variant:"muted",style:{marginLeft:"var(--gap-sm)"},children:["(",Math.round(n.size/1024)," KB)"]})]},l))})},file:(e,a,r,o)=>{const t=o?.compact??!1;if(!e)return d(t);const n=typeof e=="string"?e:e.url,l=typeof e=="string"?"View file":e.filename||"View file";return f("a",{href:n,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--primary)",textDecoration:"none"},children:[l,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,a,r,o)=>{const t=o?.compact??!1;if(!e)return d(t);const n=typeof e=="string"?e:e.url,l=typeof e=="string"?"View file":e.filename||"View file";return f("a",{href:n,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--primary)",textDecoration:"none"},children:[l,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,a,r,o)=>{const t=o?.compact??!1;if(!e)return d(t);const n=a.validation?.reference;if(o?.referenceData&&typeof n=="string"){const l=o.referenceData[n]?.[String(e)];if(l)return l}if(typeof e=="object"&&e!==null){const l=e.displayName||e.name||e.id||String(e);return String(l)}return String(e)},geopoint:(e,a,r,o)=>{const t=o?.compact??!1;return e&&typeof e=="object"&&"lat"in e&&"lng"in e?`${e.lat.toFixed(6)}, ${e.lng.toFixed(6)}`:d(t)},address:(e,a,r)=>e&&typeof e=="object"&&"formatted_address"in e?e.formatted_address:String(e),map:(e,a,r,o)=>{const t=o?.compact??!1;if(e&&typeof e=="object"){const n=Object.entries(e);return n.length===0?d(t):f(b,{direction:"column",gap:"tight",children:[n.slice(0,5).map(([l,c])=>f(m,{style:{fontSize:"var(--font-size-sm)"},children:[f("strong",{children:[l,":"]})," ",String(c)]},l)),n.length>5&&f(m,{variant:"muted",children:["+",n.length-5," more"]})]})}return d(t)},array:(e,a,r,o)=>{const t=o?.compact??!1;return Array.isArray(e)?e.length===0?d(t):e.join(", "):d(t)},"field-array":(e,a,r,o)=>{const t=o?.compact??!1;if(!Array.isArray(e)||e.length===0)return d(t);const n=a.options?.fieldSpecific?.fields;return e.map(l=>{if(typeof l!="object"||l==null)return"";const c=l;return(n?n.map(s=>s.name):Object.keys(c)).map(s=>c[s]).filter(s=>s!=null&&s!=="").map(s=>typeof s=="object"?JSON.stringify(s):String(s)).join(" \xB7 ")}).filter(Boolean).join(", ")},password:()=>"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",email:(e,a,r)=>f(b,{direction:"row",gap:"tight",align:"center",children:[p("a",{href:`mailto:${e}`,style:{color:"var(--primary)",flex:1},onClick:o=>o.stopPropagation(),children:e}),p(w,{text:e,tooltipText:r("crud:copyToClipboard",{defaultValue:"Copy to clipboard"}),ariaLabel:r("crud:actions.copyEmail",{defaultValue:"Copy email"}),onClick:o=>o.stopPropagation()})]}),tel:(e,a,r)=>f(b,{direction:"row",gap:"tight",align:"center",children:[p("a",{href:`tel:${e}`,style:{color:"var(--primary)",flex:1},onClick:o=>o.stopPropagation(),children:e}),p(w,{text:e,tooltipText:r("crud:copyToClipboard",{defaultValue:"Copy to clipboard"}),ariaLabel:r("crud:actions.copyPhone",{defaultValue:"Copy phone"}),onClick:o=>o.stopPropagation()})]}),iban:(e,a,r,o)=>{const t=o?.compact??!1;return e?f(b,{direction:"row",gap:"tight",align:"center",children:[p(m,{style:{flex:1},children:e}),p(w,{text:e,tooltipText:r("crud:copyToClipboard",{defaultValue:"Copy to clipboard"}),ariaLabel:r("crud:actions.copyIban",{defaultValue:"Copy IBAN"}),onClick:n=>n.stopPropagation()})]}):d(t)},url:(e,a,r)=>p("a",{href:e,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--primary)"},children:e}),color:(e,a,r)=>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(m,{children:e})]}),textarea:(e,a,r)=>String(e),text:(e,a,r)=>String(e),richtext:(e,a,r,o)=>{const t=o?.compact??!1;return e&&typeof e=="string"?t?e.replace(/<[^>]*>/g,"").trim()||p("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):p("div",{dangerouslySetInnerHTML:{__html:fe(e)},style:{padding:"var(--gap-sm)",fontSize:"var(--font-size-sm)",lineHeight:"1.6"}}):d(t)}};function me(e){return e.type==="avatar"}function ge(e){return e.type==="badge"}let D=!1;function be(e,a){if(D)return;D=!0;const r=o=>{const{type:t,components:n}=o;n&&a.registerComponent(t,n.controlled,n.uncontrolled),e.set(t,o)};r({type:"text",filterable:!0,filterType:"text",valueType:"string",displayFormatter:i.text,components:{controlled:g,uncontrolled:o=>{const{value:t,onChange:n,label:l,error:c,config:s}=o;return p(T,{label:l||"",value:typeof t=="string"?t:"",onChange:y=>{const u=y.target.value;n(u)},error:c,...s.options})}}}),r({type:"email",filterable:!0,filterType:"text",valueType:"string",displayFormatter:i.email,components:{controlled:g,uncontrolled:o=>{const{value:t,onChange:n,label:l,error:c,config:s}=o;return p(T,{label:l||"",value:typeof t=="string"?t:"",onChange:y=>{const u=y.target.value;n(u)},error:c,type:"email",...s.options})}}}),r({type:"url",filterable:!0,filterType:"text",valueType:"string",displayFormatter:i.url,components:{controlled:g,uncontrolled:o=>{const{value:t,onChange:n,label:l,error:c,config:s}=o;return p(T,{label:l||"",value:typeof t=="string"?t:"",onChange:y=>{const u=y.target.value;n(u)},error:c,type:"url",...s.options})}}}),r({type:"color",filterable:!0,filterType:"text",valueType:"string",displayFormatter:i.color,components:{controlled:g,uncontrolled:o=>{const{value:t,onChange:n,label:l,error:c,config:s}=o;return p(T,{label:l||"",value:typeof t=="string"?t:"",onChange:y=>{const u=y.target.value;n(u)},error:c,type:"color",...s.options})}}}),r({type:"textarea",filterable:!0,filterType:"text",valueType:"string",displayFormatter:i.textarea,components:{controlled:Z,uncontrolled:o=>{const{value:t,onChange:n,label:l,error:c,config:s}=o;return p(ue,{label:l||"",value:typeof t=="string"?t:"",onChange:y=>{const u=y.target.value;n(u)},error:c,...s.options})}}}),r({type:"richtext",filterable:!0,filterType:"text",valueType:"string",displayFormatter:i.richtext,components:{controlled:ee,uncontrolled:o=>{const{value:t,onChange:n,label:l,error:c,config:s}=o;return p(ye,{label:l||"",value:typeof t=="string"?t:"",onChange:y=>{const u=y.target.value;n(u)},error:c,...s.options})}}}),r({type:"password",filterable:!1,filterType:"none",valueType:"string",displayFormatter:i.password,components:{controlled:Y}}),r({type:"tel",filterable:!0,filterType:"text",valueType:"string",displayFormatter:i.tel,components:{controlled:G}}),r({type:"iban",filterable:!0,filterType:"text",valueType:"string",displayFormatter:i.iban,components:{controlled:g,uncontrolled:o=>{const{value:t,onChange:n,label:l,error:c,config:s}=o;return p(T,{label:l||"",value:typeof t=="string"?t:"",onChange:y=>{const u=y.target.value.replace(/\s/g,"").toUpperCase();n(u)},error:c,...s.options})}}}),r({type:"number",filterable:!0,filterType:"range",valueType:"number",displayFormatter:i.number,components:{controlled:K}}),r({type:"currency",filterable:!0,filterType:"range",valueType:"number",displayFormatter:i.currency,components:{controlled:ie}}),r({type:"price",filterable:!0,filterType:"range",valueType:"object",displayFormatter:i.price,components:{controlled:ce}}),r({type:"range",filterable:!0,filterType:"range",valueType:"number",displayFormatter:i.range,components:{controlled:O}}),r({type:"year",filterable:!0,filterType:"range",valueType:"number",displayFormatter:i.year,components:{controlled:X}}),r({type:"rating",filterable:!0,filterType:"rating",valueType:"number",displayFormatter:i.rating,components:{controlled:J}}),r({type:"duration",filterable:!0,filterType:"range",valueType:"number",displayFormatter:i.duration,components:{controlled:W}}),r({type:"boolean",filterable:!0,filterType:"select",valueType:"boolean",displayFormatter:i.boolean,components:{controlled:k}}),r({type:"checkbox",filterable:!0,filterType:"select",valueType:"boolean",displayFormatter:i.checkbox,components:{controlled:k}}),r({type:"gdprConsent",filterable:!0,filterType:"select",valueType:"object",displayFormatter:i.gdprConsent,components:{controlled:ae}}),r({type:"switch",filterable:!0,filterType:"select",valueType:"boolean",displayFormatter:i.switch,components:{controlled:ne}}),r({type:"date",filterable:!0,filterType:"range",valueType:"date",displayFormatter:i.date,components:{controlled:h}}),r({type:"datetime-local",filterable:!0,filterType:"range",valueType:"date",displayFormatter:i["datetime-local"],components:{controlled:h}}),r({type:"time",filterable:!0,filterType:"range",valueType:"date",displayFormatter:i.time,components:{controlled:h}}),r({type:"week",filterable:!0,filterType:"range",valueType:"date",displayFormatter:i.week,components:{controlled:h}}),r({type:"month",filterable:!0,filterType:"range",valueType:"date",displayFormatter:i.month,components:{controlled:h}}),r({type:"timestamp",filterable:!0,filterType:"range",valueType:"date",displayFormatter:i.timestamp,components:{controlled:te}}),r({type:"file",filterable:!1,filterType:"none",valueType:"object",displayFormatter:i.file,components:{controlled:N}}),r({type:"files",filterable:!1,filterType:"none",valueType:"array",displayFormatter:i.files,components:{controlled:M}}),r({type:"document",filterable:!1,filterType:"none",valueType:"object",displayFormatter:i.document,components:{controlled:P}}),r({type:"documents",filterable:!1,filterType:"none",valueType:"array",displayFormatter:i.documents,components:{controlled:R}}),r({type:"image",filterable:!1,filterType:"none",valueType:"object",displayFormatter:i.image,components:{controlled:_}}),r({type:"images",filterable:!1,filterType:"none",valueType:"array",displayFormatter:i.images,components:{controlled:le}}),r({type:"geopoint",filterable:!1,filterType:"none",valueType:"object",displayFormatter:i.geopoint,components:{controlled:B}}),r({type:"address",filterable:!0,filterType:"address",valueType:"object",displayFormatter:i.address,components:{controlled:re}}),r({type:"map",filterable:!1,filterType:"none",valueType:"object",displayFormatter:i.map,components:{controlled:E}}),r({type:"array",filterable:!1,filterType:"none",valueType:"array",displayFormatter:i.array,components:{controlled:H}}),r({type:"field-array",filterable:!1,filterType:"none",valueType:"array",displayFormatter:i["field-array"],components:{controlled:oe}}),r({type:"select",filterable:!0,filterType:"select",valueType:"string",displayFormatter:i.select,components:{controlled:I}}),r({type:"combobox",filterable:!0,filterType:"select",valueType:"string",displayFormatter:i.combobox,components:{controlled:$}}),r({type:"multiselect",filterable:!0,filterType:"multiselect",valueType:"array",displayFormatter:i.multiselect,components:{controlled:U}}),r({type:"radio",filterable:!0,filterType:"select",valueType:"string",displayFormatter:i.radio,components:{controlled:q}}),r({type:"reference",filterable:!0,filterType:"text",valueType:"string",displayFormatter:i.reference,components:{controlled:Q}}),r({type:"hidden",filterable:!1,filterType:"none",valueType:"string",components:{controlled:g,uncontrolled:o=>{const{name:t,value:n}=o;return p(de,{name:t,value:typeof n=="string"?n:""})}}}),r({type:"avatar",filterable:!1,filterType:"none",valueType:"string",components:{controlled:g,uncontrolled:o=>{const{value:t,onChange:n,error:l,config:c,t:s}=o;if(!me(c))throw new Error("Invalid config type for avatar field");return p(se,{config:c,value:typeof t=="string"?t:"",onChange:y=>{n(y)},error:!!l,helperText:l||void 0,t:s,...c.options})}}}),r({type:"badge",filterable:!1,filterType:"none",valueType:"string",components:{controlled:g,uncontrolled:o=>{const{value:t,onChange:n,error:l,config:c,t:s}=o;if(!ge(c))throw new Error("Invalid config type for badge field");return p(pe,{config:c,value:typeof t=="string"?t:"",onChange:y=>{n(y)},error:!!l,helperText:l||void 0,t:s,...c.options})}}}),r({type:"submit",filterable:!1,filterType:"none",valueType:"string",components:{controlled:g,uncontrolled:o=>{const{name:t,label:n,config:l}=o;return p(A,{label:n||t,type:"submit",onClick:()=>{},...l.options})}}}),r({type:"reset",filterable:!1,filterType:"none",valueType:"string",components:{controlled:g,uncontrolled:o=>{const{name:t,label:n,config:l}=o;return p(A,{label:n||t,type:"reset",onClick:()=>{},...l.options})}}})}export{be as registerAllBuiltinFieldTypes};
|