@donotdev/crud 0.0.13 → 0.0.15

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.
Files changed (138) hide show
  1. package/README.md +27 -19
  2. package/dist/CrudService.d.ts +84 -11
  3. package/dist/CrudService.d.ts.map +1 -1
  4. package/dist/CrudService.js +9 -1
  5. package/dist/CrudStore.d.ts.map +1 -1
  6. package/dist/CrudStore.js +1 -1
  7. package/dist/FieldRegistry.d.ts +40 -13
  8. package/dist/FieldRegistry.d.ts.map +1 -1
  9. package/dist/FieldRegistry.js +1 -1
  10. package/dist/adapters/FunctionsAdapter.d.ts +20 -26
  11. package/dist/adapters/FunctionsAdapter.d.ts.map +1 -1
  12. package/dist/adapters/FunctionsAdapter.js +1 -1
  13. package/dist/adapters/index.d.ts +0 -1
  14. package/dist/adapters/index.d.ts.map +1 -1
  15. package/dist/adapters/index.js +1 -1
  16. package/dist/components/CrudCard.d.ts +8 -0
  17. package/dist/components/CrudCard.d.ts.map +1 -0
  18. package/dist/components/CrudCard.js +1 -0
  19. package/dist/components/DateFilter.d.ts +30 -0
  20. package/dist/components/DateFilter.d.ts.map +1 -0
  21. package/dist/components/DateFilter.js +1 -0
  22. package/dist/components/DisplayThumbnail.d.ts +29 -0
  23. package/dist/components/DisplayThumbnail.d.ts.map +1 -0
  24. package/dist/components/DisplayThumbnail.js +1 -0
  25. package/dist/components/EntityFilters.d.ts +28 -15
  26. package/dist/components/EntityFilters.d.ts.map +1 -1
  27. package/dist/components/EntityFilters.js +1 -1
  28. package/dist/components/FormLayout.d.ts.map +1 -1
  29. package/dist/components/FormLayout.js +1 -1
  30. package/dist/components/__tests__/EntityFilters.test.d.ts +2 -0
  31. package/dist/components/__tests__/EntityFilters.test.d.ts.map +1 -0
  32. package/dist/components/__tests__/EntityFilters.test.js +1 -0
  33. package/dist/components/__tests__/FormFieldRenderer.test.d.ts +2 -0
  34. package/dist/components/__tests__/FormFieldRenderer.test.d.ts.map +1 -0
  35. package/dist/components/__tests__/FormFieldRenderer.test.js +1 -0
  36. package/dist/components/controlled/file/ControlledMultiImageField.js +1 -1
  37. package/dist/components/fields/display/FileFieldDisplay.js +1 -1
  38. package/dist/components/fields/display/MultiDropdownDisplay.js +1 -1
  39. package/dist/components/fields/display/MultiInputTextFieldDisplay.js +1 -1
  40. package/dist/components/fields/display/PasswordFieldDisplay.js +1 -1
  41. package/dist/components/fields/display/RichTextDisplay.d.ts.map +1 -1
  42. package/dist/components/fields/display/RichTextDisplay.js +2 -2
  43. package/dist/components/form/fields/AddressFieldComponent.d.ts.map +1 -1
  44. package/dist/components/form/fields/AddressFieldComponent.js +1 -1
  45. package/dist/components/form/fields/AvatarFieldComponent.js +1 -1
  46. package/dist/components/form/fields/BadgeFieldComponent.js +1 -1
  47. package/dist/components/form/fields/DocumentFieldComponent.js +1 -1
  48. package/dist/components/form/fields/DurationFieldComponent.d.ts.map +1 -1
  49. package/dist/components/form/fields/DurationFieldComponent.js +1 -1
  50. package/dist/components/form/fields/FileFieldComponent.js +1 -1
  51. package/dist/components/form/fields/GeoPointFieldComponent.js +1 -1
  52. package/dist/components/form/fields/ImageFieldComponent.js +1 -1
  53. package/dist/components/form/fields/MultiDropdownComponent.js +1 -1
  54. package/dist/components/form/fields/MultiInputTextFieldComponent.js +1 -1
  55. package/dist/components/form/fields/PhoneNumberComponent.d.ts.map +1 -1
  56. package/dist/components/form/fields/PriceFieldComponent.js +1 -1
  57. package/dist/components/form/fields/SwitchFieldComponent.d.ts.map +1 -1
  58. package/dist/components/form/fields/SwitchFieldComponent.js +1 -1
  59. package/dist/components/form/fields/internal/TiptapEditor.d.ts +4 -2
  60. package/dist/components/form/fields/internal/TiptapEditor.d.ts.map +1 -1
  61. package/dist/components/form/fields/internal/TiptapEditor.js +2 -2
  62. package/dist/components/form/internal/ImageViewerDialog.d.ts.map +1 -1
  63. package/dist/components/form/internal/ImageViewerDialog.js +1 -1
  64. package/dist/components/index.d.ts +2 -0
  65. package/dist/components/index.d.ts.map +1 -1
  66. package/dist/components/index.js +1 -1
  67. package/dist/fieldTypeRegistry.d.ts +3 -0
  68. package/dist/fieldTypeRegistry.d.ts.map +1 -1
  69. package/dist/fieldTypeRegistry.js +1 -1
  70. package/dist/forms/hooks/useEntityForm.d.ts.map +1 -1
  71. package/dist/forms/hooks/useEntityForm.js +1 -1
  72. package/dist/forms/utils/getFieldsForOperation.d.ts.map +1 -1
  73. package/dist/forms/utils/translateFieldLabel.d.ts.map +1 -1
  74. package/dist/hooks/index.d.ts +2 -0
  75. package/dist/hooks/index.d.ts.map +1 -1
  76. package/dist/hooks/index.js +1 -1
  77. package/dist/hooks/useCrudFilters.d.ts +17 -0
  78. package/dist/hooks/useCrudFilters.d.ts.map +1 -0
  79. package/dist/hooks/useCrudFilters.js +1 -0
  80. package/dist/hooks/useFileUpload.d.ts.map +1 -1
  81. package/dist/hooks/useFileUpload.js +1 -1
  82. package/dist/hooks/useFormNavigationGuard.d.ts.map +1 -1
  83. package/dist/hooks/useFormNavigationGuard.js +1 -1
  84. package/dist/hooks/useRelatedItems.d.ts +1 -2
  85. package/dist/hooks/useRelatedItems.d.ts.map +1 -1
  86. package/dist/hooks/useRelatedItems.js +1 -1
  87. package/dist/index.d.ts +6 -4
  88. package/dist/index.d.ts.map +1 -1
  89. package/dist/index.js +1 -1
  90. package/dist/registerBuiltinFieldTypes.d.ts.map +1 -1
  91. package/dist/registerBuiltinFieldTypes.js +1 -1
  92. package/dist/stores/FormStore.d.ts.map +1 -1
  93. package/dist/stores/FormStore.js +1 -1
  94. package/dist/stores/UploadStore.d.ts.map +1 -1
  95. package/dist/stores/UploadStore.js +1 -1
  96. package/dist/tsconfig.tsbuildinfo +1 -1
  97. package/dist/types.d.ts +26 -20
  98. package/dist/types.d.ts.map +1 -1
  99. package/dist/types.js +1 -0
  100. package/dist/useBaseCrudList.d.ts +1 -4
  101. package/dist/useBaseCrudList.d.ts.map +1 -1
  102. package/dist/useBaseCrudList.js +1 -1
  103. package/dist/useCrud.d.ts +1 -2
  104. package/dist/useCrud.d.ts.map +1 -1
  105. package/dist/useCrud.js +1 -1
  106. package/dist/useCrudCardList.d.ts +1 -2
  107. package/dist/useCrudCardList.d.ts.map +1 -1
  108. package/dist/useCrudCardList.js +1 -1
  109. package/dist/useCrudList.d.ts +1 -1
  110. package/dist/useCrudList.d.ts.map +1 -1
  111. package/dist/useCrudList.js +1 -1
  112. package/dist/utils/fileStorage.d.ts +10 -5
  113. package/dist/utils/fileStorage.d.ts.map +1 -1
  114. package/dist/utils/fileStorage.js +1 -1
  115. package/dist/utils/imageStorage.d.ts +9 -4
  116. package/dist/utils/imageStorage.d.ts.map +1 -1
  117. package/dist/utils/imageStorage.js +1 -1
  118. package/dist/utils/mergeWithOptimistic.d.ts.map +1 -1
  119. package/dist/utils/mergeWithOptimistic.js +1 -1
  120. package/dist/utils/sanitizeHtml.d.ts +6 -0
  121. package/dist/utils/sanitizeHtml.d.ts.map +1 -0
  122. package/dist/utils/sanitizeHtml.js +1 -0
  123. package/dist/utils/scopeUtils.d.ts +1 -2
  124. package/dist/utils/scopeUtils.d.ts.map +1 -1
  125. package/dist/utils/scopeUtils.js +1 -1
  126. package/dist/utils/uploadValidation.d.ts +5 -4
  127. package/dist/utils/uploadValidation.d.ts.map +1 -1
  128. package/dist/utils/uploadValidation.js +1 -1
  129. package/package.json +12 -6
  130. package/dist/adapters/FirestoreAdapter.d.ts +0 -65
  131. package/dist/adapters/FirestoreAdapter.d.ts.map +0 -1
  132. package/dist/adapters/FirestoreAdapter.js +0 -1
  133. package/dist/components/EntityDisplayRenderer.d.ts +0 -43
  134. package/dist/components/EntityDisplayRenderer.d.ts.map +0 -1
  135. package/dist/components/EntityDisplayRenderer.js +0 -1
  136. package/dist/components/EntityFormRenderer.d.ts +0 -86
  137. package/dist/components/EntityFormRenderer.d.ts.map +0 -1
  138. package/dist/components/EntityFormRenderer.js +0 -1
@@ -0,0 +1,8 @@
1
+ import type { CrudCardProps } from '@donotdev/core';
2
+ /**
3
+ * CrudCard — Presentational card from entity + item + field slots.
4
+ * No routing: use onClick for interaction. Parent wraps with Link if needed.
5
+ */
6
+ export declare function CrudCard({ item, entity, onClick, titleFields: titleFieldsProp, subtitleFields: subtitleFieldsProp, contentFields: contentFieldsProp, footerFields: footerFieldsProp, showDelete, renderActions, elevated, className, }: Omit<CrudCardProps, 'detailHref'>): import("react/jsx-runtime").JSX.Element;
7
+ export default CrudCard;
8
+ //# sourceMappingURL=CrudCard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CrudCard.d.ts","sourceRoot":"","sources":["../../src/components/CrudCard.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,aAAa,EAA2B,MAAM,gBAAgB,CAAC;AA4C7E;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,MAAM,EACN,OAAO,EACP,WAAW,EAAE,eAAe,EAC5B,cAAc,EAAE,kBAAkB,EAClC,aAAa,EAAE,iBAAiB,EAChC,YAAY,EAAE,gBAAgB,EAC9B,UAAkB,EAClB,aAAa,EACb,QAAe,EACf,SAAS,GACV,EAAE,IAAI,CAAC,aAAa,EAAE,YAAY,CAAC,2CA+LnC;AAED,eAAe,QAAQ,CAAC"}
@@ -0,0 +1 @@
1
+ import{jsx as i,jsxs as A}from"react/jsx-runtime";import{useMemo as F}from"react";import{Trash2 as G}from"lucide-react";import{Card as H,Stack as R,Text as B,ActionButton as J}from"@donotdev/components";import{useTranslation as k,getListCardFieldNames as K}from"@donotdev/core";import{formatValue as v}from"./DisplayFieldRenderer";import{translateFieldLabel as O}from"../forms/utils/translateFieldLabel";import{DisplayThumbnail as y}from"./DisplayThumbnail";import{useCrud as Q}from"../useCrud";function u(t){return t==="image"||t==="images"}function U(t){return F(()=>{const e=t.listCardFields;if(e&&!Array.isArray(e)){const o=e;return{titleFields:o.title??[],subtitleFields:o.subtitle??[],contentFields:o.content??[],footerFields:o.footer??[]}}const f=K(t),g=f.filter(o=>!u(t.fields[o]?.type)),x=f.filter(o=>u(t.fields[o]?.type)),S=g.length>0?[g[0]]:[],C=[...g.slice(1,4),...x];return{titleFields:S,subtitleFields:[],contentFields:C,footerFields:[]}},[t])}function W({item:t,entity:e,onClick:f,titleFields:g,subtitleFields:x,contentFields:S,footerFields:C,showDelete:o=!1,renderActions:D,elevated:M=!0,className:P}){const{t:n}=k([e.namespace,"crud"]),{t:m}=k("crud"),b=U(e),T=g??b.titleFields,I=x??b.subtitleFields,j=S??b.contentFields,h=C??b.footerFields,V=F(()=>{if(!T?.length)return t.id??"";const c=T.filter(l=>typeof l=="string").filter(l=>!u(e.fields[l]?.type)).map(l=>{const s=e.fields[l],a=t[l],p=s?v(a,s,n,{compact:!0,asString:!0}):a;return typeof p=="string"?p:String(p??"")}).filter(Boolean),r=!Array.isArray(e.listCardFields)&&e.listCardFields?.titleSeparator!=null?e.listCardFields.titleSeparator:" ";return c.join(r)||String(t.id??"")},[t,e.fields,T,e.listCardFields,n]),_=F(()=>I?.length&&I.filter(r=>typeof r=="string").filter(r=>!u(e.fields[r]?.type)).map(r=>{const l=e.fields[r],s=t[r],a=l?v(s,l,n,{compact:!0,asString:!0}):s;return typeof a=="string"?a:String(a??"")}).filter(Boolean).join(" ")||void 0,[t,e.fields,I,n]),z=F(()=>{if(!j?.length)return null;const c=j.map(r=>{const l=e.fields[r];if(!l)return null;if(u(l.type)){const s=t[r];return s==null?null:i(y,{pictures:s,alt:String(V),aspectRatio:"16/9"},r)}return A("div",{children:[i(B,{level:"small",variant:"muted",children:O(r,l,n)}),i(B,{children:v(t[r],l,n,{compact:!0})})]},r)}).filter(Boolean);return c.length>0?i(R,{direction:"column",gap:"tight",children:c}):null},[t,e.fields,j,V,n]),q=F(()=>{if(!h?.length)return;if(h.some(r=>u(e.fields[r]?.type))){const r=h.map(l=>{const s=e.fields[l];if(!s)return null;if(u(s.type)){const p=t[l];return p==null?null:i(y,{pictures:p,alt:"",aspectRatio:"1"},l)}const a=v(t[l],s,n,{compact:!0});return i("span",{children:a},l)});return i(R,{direction:"row",gap:"tight",align:"center",children:r.filter(Boolean)})}const c=h.map(r=>{const l=e.fields[r];return l?v(t[r],l,n,{compact:!0}):t[r]});return i(B,{level:"small",children:c.join(" \xB7 ")})},[t,e.fields,h,n]),E=Q(e).delete,w=i(H,{title:String(V??""),subtitle:_,content:z??void 0,footer:q,clickable:!!f,onClick:f?()=>f(t.id):void 0,elevated:M,className:P}),L=D||o?A("div",{style:{position:"absolute",top:"var(--gap-sm)",right:"var(--gap-sm)",zIndex:10,display:"flex",alignItems:"flex-start",gap:"var(--gap-xs)"},onClick:d=>d.stopPropagation(),onMouseDown:d=>d.stopPropagation(),children:[D,o&&i(J,{action:async()=>{await E(t.id)},confirmText:m("delete.confirm",{defaultValue:"Are you sure you want to delete this item?"}),confirmTitle:m("delete.title",{defaultValue:"Delete Item"}),loadingText:m("delete.loading",{defaultValue:"Deleting..."}),variant:"destructive",icon:G,"aria-label":m("delete",{defaultValue:"Delete"}),children:m("delete",{defaultValue:"Delete"})})]}):null;return L?A("div",{style:{position:"relative",height:"100%"},children:[w,L]}):w}var st=W;export{W as CrudCard,st as default};
@@ -0,0 +1,30 @@
1
+ export type DateFilterValue = {
2
+ min?: string;
3
+ max?: string;
4
+ };
5
+ export interface DateFilterProps {
6
+ /** Field label */
7
+ label: string;
8
+ /** Field type */
9
+ fieldType: 'date' | 'week' | 'month' | 'year';
10
+ /** Current filter value (range format: { min?: string; max?: string }) */
11
+ value?: DateFilterValue;
12
+ /** Callback when filter value changes */
13
+ onChange: (value: DateFilterValue | undefined) => void;
14
+ /** Translation function for CRUD namespace */
15
+ tCrud: (key: string, opts?: {
16
+ defaultValue?: string;
17
+ }) => string;
18
+ /** Current locale for date formatting */
19
+ locale?: string;
20
+ }
21
+ /**
22
+ * DateFilter - Simple date filter component
23
+ * Uses open-ended From/To range which covers all use cases:
24
+ * - From only: set min, leave max empty
25
+ * - To only: set max, leave min empty
26
+ * - Between: set both min and max
27
+ * - Exact: set min = max (same date)
28
+ */
29
+ export declare function DateFilter({ label, fieldType, value, onChange, tCrud, locale, }: DateFilterProps): import("react/jsx-runtime").JSX.Element;
30
+ //# sourceMappingURL=DateFilter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DateFilter.d.ts","sourceRoot":"","sources":["../../src/components/DateFilter.tsx"],"names":[],"mappings":"AA2BA,MAAM,MAAM,eAAe,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7D,MAAM,WAAW,eAAe;IAC9B,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB;IACjB,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IAC9C,0EAA0E;IAC1E,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,yCAAyC;IACzC,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,GAAG,SAAS,KAAK,IAAI,CAAC;IACvD,8CAA8C;IAC9C,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC;IACjE,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,SAAS,EACT,KAAK,EACL,QAAQ,EACR,KAAK,EACL,MAAa,GACd,EAAE,eAAe,2CA+RjB"}
@@ -0,0 +1 @@
1
+ "use client";import{jsx as a,jsxs as k,Fragment as Dt}from"react/jsx-runtime";import{useState as T,useMemo as yt}from"react";import{X as ht}from"lucide-react";import{Button as S,Calendar as St,FloatingLabel as ut,Sheet as E,Text as pt}from"@donotdev/components";import{formatDate as ft}from"@donotdev/core";function vt({label:u,fieldType:xt,value:s,onChange:p,tCrud:o,locale:_="en"}){const[w,l]=T(!1),[F,f]=T(null),b=yt(()=>s?typeof s=="object"&&s!==null&&"min"in s?{min:s.min||"",max:s.max||""}:{min:"",max:""}:{min:"",max:""},[s]),v=t=>{if(!t)return"";try{const n=new Date(t+"T00:00:00");return ft(n,_)}catch{return t}},C=()=>{const t=new Date;t.setHours(0,0,0,0);const n=t.getFullYear(),c=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0"),g=`${n}-${c}-${r}`,i=new Date(t);i.setDate(i.getDate()-1);const M=i.getFullYear(),x=String(i.getMonth()+1).padStart(2,"0"),z=String(i.getDate()).padStart(2,"0"),A=`${M}-${x}-${z}`,d=new Date(t);d.setDate(d.getDate()+1);const B=d.getFullYear(),H=String(d.getMonth()+1).padStart(2,"0"),I=String(d.getDate()).padStart(2,"0"),L=`${B}-${H}-${I}`,m=new Date(t);m.setDate(m.getDate()-7);const O=m.getFullYear(),P=String(m.getMonth()+1).padStart(2,"0"),W=String(m.getDate()).padStart(2,"0"),X=`${O}-${P}-${W}`,D=new Date(t);D.setDate(D.getDate()-30);const q=D.getFullYear(),G=String(D.getMonth()+1).padStart(2,"0"),J=String(D.getDate()).padStart(2,"0"),K=`${q}-${G}-${J}`,y=new Date(t);y.setDate(y.getDate()+7);const Q=y.getFullYear(),U=String(y.getMonth()+1).padStart(2,"0"),Z=String(y.getDate()).padStart(2,"0"),tt=`${Q}-${U}-${Z}`,h=new Date(t);h.setDate(h.getDate()+30);const et=h.getFullYear(),at=String(h.getMonth()+1).padStart(2,"0"),nt=String(h.getDate()).padStart(2,"0"),rt=`${et}-${at}-${nt}`,$=new Date(t.getFullYear(),t.getMonth(),1),st=$.getFullYear(),ot=String($.getMonth()+1).padStart(2,"0"),lt=String($.getDate()).padStart(2,"0"),it=`${st}-${ot}-${lt}`,Y=new Date(t.getFullYear(),t.getMonth()+1,0),ct=Y.getFullYear(),gt=String(Y.getMonth()+1).padStart(2,"0"),dt=String(Y.getDate()).padStart(2,"0"),mt=`${ct}-${gt}-${dt}`;return{today:g,yesterday:A,tomorrow:L,last7Days:X,last30Days:K,next7Days:tt,next30Days:rt,thisMonthStart:it,thisMonthEnd:mt}},e=b,N=C(),R=!!(e?.min||e?.max),V=t=>{const n=t==="start",c=n?e?.min:e?.max;return a("div",{style:{padding:"var(--gap-md)"},children:k("div",{style:{display:"flex",flexDirection:"column",gap:"var(--gap-md)"},children:[a("div",{style:{display:"flex",flexWrap:"wrap",gap:"var(--gap-tight)"},children:(n?["today","yesterday","last7Days","last30Days","thisMonthStart"]:["today","tomorrow","next7Days","next30Days","thisMonthEnd"]).map(r=>{const g=N[r];return a(S,{variant:"outline",onClick:()=>{p({min:n?g:e?.min||"",max:n?e?.max||"":g}),l(!1)},children:o(`filter.${r}`,{defaultValue:r})},r)})}),a(St,{selected:c?new Date(c+"T00:00:00"):void 0,mode:"single",onSelect:r=>{if(!r)return;const g=r.getFullYear(),i=String(r.getMonth()+1).padStart(2,"0"),M=String(r.getDate()).padStart(2,"0"),x=`${g}-${i}-${M}`;p({min:n?x:e?.min||"",max:n?e?.max||"":x}),l(!1)},defaultMonth:c?new Date(c+"T00:00:00"):new Date}),a(S,{variant:"ghost",display:"compact",onClick:()=>{p({min:n?"":e?.min||"",max:n&&e?.max||""}),l(!1)},children:o("filter.clear",{defaultValue:"Clear"})})]})})},j=k(Dt,{children:[a(E,{trigger:a(S,{variant:"outline",onClick:()=>{f("start"),l(!0)},style:{flex:1},children:e?.min?v(e.min):o("filter.min",{defaultValue:"Min"})}),title:`${u} - ${o("filter.min",{defaultValue:"Min"})}`,open:w&&F==="start",onOpenChange:t=>{l(t),t||f(null)},children:V("start")}),a(pt,{level:"small",variant:"muted",style:{display:"flex",alignItems:"center"},children:"\u2013"}),a(E,{trigger:a(S,{variant:"outline",onClick:()=>{f("end"),l(!0)},style:{flex:1},children:e?.max?v(e.max):o("filter.max",{defaultValue:"Max"})}),title:`${u} - ${o("filter.max",{defaultValue:"Max"})}`,open:w&&F==="end",onOpenChange:t=>{l(t),t||f(null)},children:V("end")}),a(S,{variant:"ghost",display:"compact",icon:a(ht,{size:16}),onClick:()=>{p(void 0)},disabled:!R,"aria-label":o("filter.clear",{defaultValue:"Clear"})})]});return u?a(ut,{label:u,className:"dndev-range-input",children:j}):a("div",{className:"dndev-range-input",children:j})}export{vt as DateFilter};
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @fileoverview DisplayThumbnail component
3
+ * @description Renders the thumbnail of the first picture (pictures[0]) for list cards and list views.
4
+ * Normalizes string (backend-optimized thumbUrl), single Picture, or Picture[].
5
+ *
6
+ * @version 0.0.1
7
+ * @since 0.0.1
8
+ * @author AMBROISE PARK Consulting
9
+ */
10
+ import type { Picture } from '@donotdev/core';
11
+ export interface DisplayThumbnailProps {
12
+ /** Picture(s) from item — string (optimized thumbUrl), single Picture, or Picture[] */
13
+ pictures: Picture[] | Picture | string | null;
14
+ /** Alt text for the image */
15
+ alt?: string;
16
+ /** CSS aspect-ratio (e.g. '16/9', '4/3') */
17
+ aspectRatio?: string;
18
+ /** Optional className for the wrapper */
19
+ className?: string;
20
+ /** Optional inline style for the wrapper */
21
+ style?: React.CSSProperties;
22
+ }
23
+ /**
24
+ * DisplayThumbnail - Renders thumbnail of first picture for list cards.
25
+ * Used by CrudCard and any list view that needs a single thumbnail.
26
+ */
27
+ export declare function DisplayThumbnail({ pictures, alt, aspectRatio, className, style, }: DisplayThumbnailProps): React.ReactElement | null;
28
+ export default DisplayThumbnail;
29
+ //# sourceMappingURL=DisplayThumbnail.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DisplayThumbnail.d.ts","sourceRoot":"","sources":["../../src/components/DisplayThumbnail.tsx"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C,MAAM,WAAW,qBAAqB;IACpC,uFAAuF;IACvF,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,CAAC;IAC9C,6BAA6B;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAC7B;AAmBD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,GAAQ,EACR,WAAoB,EACpB,SAAS,EACT,KAAK,GACN,EAAE,qBAAqB,GAAG,KAAK,CAAC,YAAY,GAAG,IAAI,CA6BnD;AAED,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1 @@
1
+ "use client";import{jsx as e}from"react/jsx-runtime";function u(r){if(r==null)return null;if(typeof r=="string")return r||null;const l=Array.isArray(r)&&r.length>0?r[0]:r;if(!l||typeof l!="object")return null;const t=l.thumbUrl??l.fullUrl;return typeof t=="string"?t:null}function a({pictures:r,alt:l="",aspectRatio:t="16/9",className:o,style:i}){const n=u(r);return n?e("div",{className:o,style:{width:"100%",aspectRatio:t,borderRadius:"var(--radius-md)",overflow:"hidden",backgroundColor:"var(--muted)",position:"relative",...i},children:e("img",{src:n,alt:l,loading:"lazy",style:{width:"100%",height:"100%",objectFit:"cover"}})}):null}var d=a;export{a as DisplayThumbnail,d as default};
@@ -17,26 +17,35 @@ import type { Entity } from '@donotdev/core';
17
17
  export declare function matchesFilter(itemValue: any, filterValue: string | {
18
18
  min?: string;
19
19
  max?: string;
20
- }, fieldType: string): boolean;
21
- export interface EntityFiltersProps<T = any> {
20
+ } | string[] | {
21
+ date: string;
22
+ time?: string;
23
+ } | {
24
+ min?: {
25
+ date: string;
26
+ time?: string;
27
+ };
28
+ max?: {
29
+ date: string;
30
+ time?: string;
31
+ };
32
+ } | {
33
+ date: string;
34
+ time?: string;
35
+ }[], fieldType: string): boolean;
36
+ export interface EntityFiltersProps<T extends Record<string, any> & {
37
+ id: string;
38
+ } = Record<string, any> & {
39
+ id: string;
40
+ }> {
22
41
  /** The entity definition */
23
42
  entity: Entity;
24
- /** Data array to extract unique values and min/max from */
25
- data: T[];
26
- /** Current filter values */
27
- filters: Record<string, string | {
28
- min?: string;
29
- max?: string;
30
- }>;
31
- /** Callback when filters change */
32
- onFiltersChange: (filters: Record<string, string | {
33
- min?: string;
34
- max?: string;
35
- }>) => void;
36
43
  /** Optional: Specific fields to show filters for (defaults to all entity fields) */
37
44
  fieldsToFilter?: string[];
38
45
  /** Layout variant: 'inline' (multi-column grid) or 'sidebar' (single column stack) */
39
46
  variant?: 'inline' | 'sidebar';
47
+ /** Optional: Data array to extract unique values and min/max from (if not provided, fetches automatically) */
48
+ data?: T[];
40
49
  }
41
50
  /**
42
51
 
@@ -57,5 +66,9 @@ export interface EntityFiltersProps<T = any> {
57
66
  * - Clear individual filters or all filters
58
67
 
59
68
  */
60
- export declare function EntityFilters<T extends Record<string, any> = Record<string, any>>({ entity, data, filters, onFiltersChange, fieldsToFilter, variant, }: EntityFiltersProps<T>): import("react/jsx-runtime").JSX.Element | null;
69
+ export declare function EntityFilters<T extends Record<string, any> & {
70
+ id: string;
71
+ } = Record<string, any> & {
72
+ id: string;
73
+ }>({ entity, data: dataProp, fieldsToFilter, variant, }: EntityFiltersProps<T>): import("react/jsx-runtime").JSX.Element | null;
61
74
  //# sourceMappingURL=EntityFilters.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EntityFilters.d.ts","sourceRoot":"","sources":["../../src/components/EntityFilters.tsx"],"names":[],"mappings":"AAsDA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAM7C;;;;;;;;;;;;;;GAcG;AAEH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,GAAG,EAEd,WAAW,EAAE,MAAM,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,EAEpD,SAAS,EAAE,MAAM,GAChB,OAAO,CA8MT;AAqND,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,GAAG;IACzC,4BAA4B;IAE5B,MAAM,EAAE,MAAM,CAAC;IAEf,2DAA2D;IAE3D,IAAI,EAAE,CAAC,EAAE,CAAC;IAEV,4BAA4B;IAE5B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAEjE,mCAAmC;IAEnC,eAAe,EAAE,CACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,KAC7D,IAAI,CAAC;IAEV,oFAAoF;IAEpF,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAE1B,sFAAsF;IAEtF,OAAO,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AAEH,wBAAgB,aAAa,CAC3B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnD,EACA,MAAM,EAEN,IAAI,EAEJ,OAAO,EAEP,eAAe,EAEf,cAAc,EAEd,OAAkB,GACnB,EAAE,kBAAkB,CAAC,CAAC,CAAC,kDAwjBvB"}
1
+ {"version":3,"file":"EntityFilters.d.ts","sourceRoot":"","sources":["../../src/components/EntityFilters.tsx"],"names":[],"mappings":"AAyDA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAS7C;;;;;;;;;;;;;;GAcG;AAEH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,GAAG,EAEd,WAAW,EACP,MAAM,GACN;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAC9B,MAAM,EAAE,GACR;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAC/B;IACE,GAAG,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACtC,GAAG,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACvC,GACD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,EAErC,SAAS,EAAE,MAAM,GAChB,OAAO,CAiVT;AAED,MAAM,WAAW,kBAAkB,CACjC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IACrE,EAAE,EAAE,MAAM,CAAC;CACZ;IAED,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAC;IAEf,oFAAoF;IACpF,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAE1B,sFAAsF;IACtF,OAAO,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAE/B,8GAA8G;IAC9G,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;CACZ;AAED;;;;;;;;;;;;;;;;;;GAkBG;AAEH,wBAAgB,aAAa,CAC3B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IACrE,EAAE,EAAE,MAAM,CAAC;CACZ,EACD,EACA,MAAM,EACN,IAAI,EAAE,QAAQ,EACd,cAAc,EACd,OAAkB,GACnB,EAAE,kBAAkB,CAAC,CAAC,CAAC,kDA2nBvB"}
@@ -1 +1 @@
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
+ "use client";import{jsx as E,jsxs as H}from"react/jsx-runtime";import{useMemo as G}from"react";import{FilterX as Z}from"lucide-react";import{Button as V,Combobox as tt,Grid as nt,RangeInput as et,Slider as rt,Stack as it}from"@donotdev/components";import{DateFilter as st}from"./DateFilter";import{useTranslation as J,handleError as K}from"@donotdev/core";import{translateFieldLabel as ot,translateLabel as Q}from"../forms/utils";import{getFilterType as _,isFilterable as at}from"../fieldTypeRegistry";import{useCrudFilters as ct}from"../hooks/useCrudFilters";import{useCrudCardList as lt}from"../useCrudCardList";function dt(t,s,c){if(!s)return!0;if(Array.isArray(s)){if(s.length===0)return!0;if(!(_(c)==="range"&&(c==="date"||c==="datetime-local"||c==="timestamp")))return s.some(l=>{if(typeof l=="object"&&"date"in l){const D=l.date;return(t instanceof Date?t.toISOString().split("T")[0]:new Date(t).toISOString().split("T")[0])===D}return String(t)===String(l)});const w=t instanceof Date?t.toISOString().split("T")[0]:new Date(t).toISOString().split("T")[0];return s.some(l=>typeof l=="string"?w===l:typeof l=="object"&&"date"in l?w===l.date:!1)}if(typeof s=="object"&&"date"in s&&!("min"in s)&&!Array.isArray(s)){if(!(_(c)==="range"&&(c==="date"||c==="datetime-local"||c==="timestamp")))return!1;const w=s.date;if(!w)return!0;if(t==null)return!1;const l=t instanceof Date?t.toISOString().split("T")[0]:new Date(t).toISOString().split("T")[0];if((c==="datetime-local"||c==="timestamp")&&s.time){const D=t instanceof Date?t.toISOString().slice(11,16):new Date(t).toISOString().slice(11,16);return l===w&&D===s.time}return l===w}if(typeof s=="object"&&"min"in s){const C=_(c);if(!C)return!0;const h=C==="range"&&(c==="date"||c==="datetime-local"||c==="timestamp"),w=C==="range"&&!h,l=c==="price",D=l&&t!=null&&typeof t=="object"?Number(t.amount):w&&t!=null?typeof t=="number"?t:Number(t):NaN;if(w||l){if(typeof s.min=="object"&&s.min!==null&&"date"in s.min)return!1;const d=s,u=typeof d.min=="string"&&d.min!=="",x=typeof d.max=="string"&&d.max!=="";return u&&!x?t==null||isNaN(D)?!1:D>=Number(d.min):!u&&x?t==null?!0:isNaN(D)?!1:D<=Number(d.max):u&&x?t==null||isNaN(D)?!1:D>=Number(d.min)&&D<=Number(d.max):!0}if(h){if(typeof s.min=="object"&&s.min!==null&&"date"in s.min&&!("min"in s.min)){const b=s,p=b.min,S=b.max,I=p?.date&&p.date!=="",T=S?.date&&S.date!=="";if(I&&!T){if(t==null)return!1;const F=t instanceof Date?t:new Date(t);if(isNaN(F.getTime()))return!1;const j=new Date(p.date+(p.time?`T${p.time}:00`:"T00:00:00"));return F>=j}if(!I&&T&&S){if(t==null)return!0;const F=t instanceof Date?t:new Date(t);if(isNaN(F.getTime()))return!1;const j=new Date(S.date+(S.time?`T${S.time}:00`:"T23:59:59"));return F<=j}if(I&&T&&S){if(t==null)return!1;const F=t instanceof Date?t:new Date(t);if(isNaN(F.getTime()))return!1;const j=new Date(p.date+(p.time?`T${p.time}:00`:"T00:00:00")),X=new Date(S.date+(S.time?`T${S.time}:00`:"T23:59:59"));return F>=j&&F<=X}return!0}const d=s,u=typeof d.min=="string"&&d.min!=="",x=typeof d.max=="string"&&d.max!=="";if(u&&!x){if(t==null)return!1;const b=t instanceof Date?t:new Date(t);return isNaN(b.getTime())?!1:b>=new Date(d.min)}if(!u&&x){if(t==null)return!0;const b=t instanceof Date?t:new Date(t);return isNaN(b.getTime())?!1:b<=new Date(d.max)}if(u&&x){if(t==null)return!1;const b=t instanceof Date?t:new Date(t);return isNaN(b.getTime())?!1:b>=new Date(d.min)&&b<=new Date(d.max)}return!0}}const N=_(c);if(!N)return!0;if(N==="address")return t==null?!1:typeof t=="object"&&"formatted_address"in t?String(t.formatted_address).toLowerCase().includes(String(s).toLowerCase()):!1;if(N==="multiselect"){if(!Array.isArray(t)||t.length===0)return!1;const C=String(s).toLowerCase();return t.some(h=>String(h).toLowerCase().includes(C))}return t==null?!1:String(t).toLowerCase().includes(String(s).toLowerCase())}function Mt({entity:t,data:s,fieldsToFilter:c,variant:N="inline"}){const C=N==="sidebar",{t:h,i18n:w}=J("crud"),{t:l}=J([t.namespace,"crud"]),D=w?.language||"en",{data:d}=lt(t,{enabled:!s}),u=s??(d?.items||[]),{filters:x,setFilters:b}=ct({collection:t.collection}),p=G(()=>(c&&c.length>0?c:t.listFields||Object.keys(t.fields)).filter(e=>{const r=t.fields[e]?.type||"text";return at(r)}),[c,t.listFields,t.fields]),S=G(()=>{const i={};return p.forEach(e=>{const f=Object.fromEntries(Object.entries(x).filter(([r])=>r!==e));if(Object.keys(f).length===0){i[e]=u;return}i[e]=u.filter(r=>Object.entries(f).every(([y,A])=>{const L=r[y],a=t.fields[y]?.type||"text";return dt(L,A,a)}))}),i},[u,x,t.fields,p]),I=G(()=>{const i={};return p.forEach(e=>{const f=t.fields[e];if(!f)return;const r=f.type||"text",y=_(r);if(!y){K(new Error(`Field type "${r}" not registered in field type registry`),{userMessage:`Field type "${r}" is missing from registry`,context:{fieldType:r,fieldName:e,operation:"minmax_computation",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"});return}const A=y==="range"&&(r==="date"||r==="datetime-local"||r==="timestamp"||r==="time"||r==="week"||r==="month"||r==="year"),L=y==="range"&&!A,k=r==="price";if(L||k){const a=u.map(o=>o[e]).filter(o=>o!=null&&o!=="").map(o=>k&&typeof o=="object"&&o!==null?Number(o.amount):typeof o=="number"?o:Number(o)).filter(o=>!isNaN(o));a.length>0&&(i[e]={min:Math.min(...a),max:Math.max(...a)})}else if(A){const a=u.map(o=>o[e]).filter(o=>o!=null&&o!=="").map(o=>o instanceof Date?o:new Date(o)).filter(o=>!isNaN(o.getTime()));if(a.length>0){const o=new Date(Math.min(...a.map(R=>R.getTime()))),O=new Date(Math.max(...a.map(R=>R.getTime()))),q=o.toISOString().split("T")[0],P=O.toISOString().split("T")[0];i[e]={min:q||"",max:P||""}}}}),i},[u,t.fields,p]),T=(i,e)=>{const f={...x};if(!e||e==="")delete f[i];else if(Array.isArray(e))f[i]=e;else if(typeof e=="object"&&"min"in e){const r=e.min&&e.min!=="",y=e.max&&e.max!=="";!r&&!y?delete f[i]:f[i]=e}else f[i]=e;b(f)},F=()=>{b({})},j=G(()=>p.length===0?null:p.map(i=>{const e=t.fields[i];if(!e)return null;const f=ot(i,e,l),r=e.type||"text",y=_(r);if(!y)return K(new Error(`Field type "${r}" not registered in field type registry`),{userMessage:`Field type "${r}" is missing from registry`,context:{fieldType:r,fieldName:i,operation:"filter_ui_render",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"}),null;const A=y==="range"&&(r==="date"||r==="datetime-local"||r==="timestamp"||r==="time"||r==="week"||r==="month"||r==="year"),L=y==="range"&&!A,k=y==="select",a=x[i],O=typeof a=="object"&&a!==null&&"min"in a?a:{min:"",max:""};if(L){const m=I[i],g=m?.min??0,n=m?.max??100,M=O.min?Number(O.min):g,z=O.max?Number(O.max):n;return H(it,{gap:"tight",style:{gridColumn:"span 2"},children:[E(et,{type:"number",label:f,minPlaceholder:h("filter.min",{defaultValue:"Min"}),maxPlaceholder:h("filter.max",{defaultValue:"Max"}),minValue:O.min||"",maxValue:O.max||"",actualMin:g,actualMax:n,onChange:($,Y)=>{T(i,{min:$,max:Y})},onClear:()=>T(i,void 0)}),E(rt,{value:[M,z],min:g,max:n,step:1,onValueChange:$=>{T(i,{min:String($[0]),max:String($[1])})}})]},i)}if(A){const m=r==="week"||r==="month"||r==="year"?r:"date",g=(()=>{if(a){if(typeof a=="object"&&"min"in a){const n=a;return{min:n.min&&n.min.split("T")[0]||"",max:n.max&&n.max.split("T")[0]||""}}if(typeof a=="string"){const n=a.split("T")[0]||"";return{min:n,max:n}}}})();return E("div",{style:{gridColumn:"span 2",gridRow:C?void 0:"span 1"},children:E(st,{label:f,fieldType:m,value:g,locale:D,onChange:n=>{if(!n){T(i,void 0);return}typeof n=="object"&&"min"in n&&T(i,{min:n.min||"",max:n.max||""})},tCrud:h})},i)}const P=k&&e.validation&&"options"in e.validation&&e.validation?Array.isArray(e.validation.options)?e.validation.options:typeof e.validation.options=="function"?e.validation.options():[]:[],R=S[i]||u,v=new Set,W=y==="address";R.forEach(m=>{const g=m[i];if(g!=null)if(W&&typeof g=="object"&&"formatted_address"in g){const n=g;n.formatted_address&&v.add(String(n.formatted_address))}else v.add(String(g))});const B=[{value:"all",label:h("filter.selectPlaceholder",{defaultValue:"All"})}];if(P.length>0){const m=[],g=[];P.forEach(n=>{const M=typeof n=="string"?n:n.value,z=typeof n=="string"?n:n.label;v.has(M)?m.push({value:M,label:z}):g.push({value:M,label:z})}),m.sort((n,M)=>n.label.localeCompare(M.label)),g.sort((n,M)=>n.label.localeCompare(M.label)),m.forEach(n=>{B.push({value:n.value,label:Q(n.label,l),disabled:!1})}),g.forEach(n=>{B.push({value:n.value,label:Q(n.label,l),disabled:!0})})}else Array.from(v).sort().slice(0,100).forEach(m=>{B.push({value:m,label:m})});return E("div",{style:{gridColumn:"span 2",gridRow:"span 1"},children:E(tt,{label:f,value:typeof a=="string"?a:void 0,onValueChange:m=>{T(i,m==="all"||!m?"":String(m))},options:B,placeholder:h("filter.placeholder",{defaultValue:"Filter..."}),clearable:!0})},i)}),[p,t.fields,u,x,l,h,S]);if(!j||j.length===0)return null;const X=j.filter(Boolean),U=Object.keys(x).length>0;return H(nt,{cols:N==="sidebar"?2:[2,4,6,8],children:[X,E(V,{variant:"outline",icon:E(Z,{size:18}),onClick:F,disabled:!U,style:{gridColumn:"1 / -1",gridRow:"span 1"},children:h("filter.clear",{defaultValue:"Clear Filters"})})]})}export{Mt as EntityFilters,dt as matchesFilter};
@@ -1 +1 @@
1
- {"version":3,"file":"FormLayout.d.ts","sourceRoot":"","sources":["../../src/components/FormLayout.tsx"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAElE,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,WAAW;IACzD,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,QAAQ,EAAE,gBAAgB,CAAC,eAAe,CAAC,CAAC;IAC5C,iCAAiC;IACjC,QAAQ,EAAE,SAAS,CAAC;IACpB,sCAAsC;IACtC,WAAW,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IAC9B,oBAAoB;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,yBAAyB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yBAAyB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yBAAyB;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,0BAA0B;IAC1B,OAAO,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;IACzC,yBAAyB;IACzB,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACxB,uBAAuB;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;GAcG;AACH,QAAA,MAAM,UAAU,GAAI,CAAC,SAAS,WAAW,EAAE,mIAaxC,oBAAoB,CAAC,CAAC,CAAC,4CA4GzB,CAAC;AAEF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"FormLayout.d.ts","sourceRoot":"","sources":["../../src/components/FormLayout.tsx"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAElE,MAAM,WAAW,oBAAoB,CAAC,CAAC,SAAS,WAAW;IACzD,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,QAAQ,EAAE,gBAAgB,CAAC,eAAe,CAAC,CAAC;IAC5C,iCAAiC;IACjC,QAAQ,EAAE,SAAS,CAAC;IACpB,sCAAsC;IACtC,WAAW,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IAC9B,oBAAoB;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,yBAAyB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yBAAyB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yBAAyB;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,0BAA0B;IAC1B,OAAO,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;IACzC,yBAAyB;IACzB,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACxB,uBAAuB;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;;;GAcG;AACH,QAAA,MAAM,UAAU,GAAI,CAAC,SAAS,WAAW,EAAE,mIAaxC,oBAAoB,CAAC,CAAC,CAAC,4CAuGzB,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -1 +1 @@
1
- "use client";import{jsx as e,jsxs as r,Fragment as N}from"react/jsx-runtime";import{useState as j}from"react";import{FormProvider as w}from"react-hook-form";import{Button as s,BUTTON_VARIANT as C,Spinner as F,cn as _,Stack as i,Grid as I}from"@donotdev/components";import{useTranslation as L}from"@donotdev/core";const k=({title:m,onSubmit:c,children:u,formMethods:f,loading:n=!1,submitText:g,cancelText:v,showCancel:p=!1,onCancel:b,variant:l="default",columns:h=1,description:o})=>{const{t:d}=L("dndev"),[t,a]=j(!1),y=g||d("form.submit","Submit"),S=v||d("form.cancel","Cancel"),x=async T=>{a(!0);try{await c(T)}finally{a(!1)}},z={1:"dndev-grid-cols-1",2:"dndev-grid-cols-1 dndev-md:grid-cols-2",3:"dndev-grid-cols-1 dndev-md:grid-cols-2 dndev-md:grid-cols-3",4:"dndev-grid-cols-1 dndev-md:grid-cols-2 dndev-md:grid-cols-4"};return e(w,{...f,children:e("form",{onSubmit:x,className:_("dndev-mx-auto",{default:"dndev-surface",card:"dndev-surface",minimal:""}[l]),style:l!=="minimal"?{padding:"var(--gap-lg)"}:void 0,role:"form","aria-labelledby":"form-title",noValidate:!0,children:r(i,{gap:"large",children:[r(i,{gap:"tight",children:[e("h2",{id:"form-title",style:{fontSize:"var(--font-size-2xl)",fontWeight:600,color:"var(--foreground)"},children:m}),o&&e("p",{style:{color:"var(--muted-foreground)"},children:o})]}),e(I,{cols:h,gap:"medium",className:"dndev-w-full dndev-min-w-0",children:u}),r(i,{direction:"row",align:"center",justify:"end",gap:"medium",style:{paddingTop:"var(--gap-md)",borderTop:"1px solid var(--border)"},children:[p&&e(s,{type:"button",variant:C.OUTLINE,onClick:b,disabled:n||t,children:S}),e(s,{type:"submit",disabled:n||t,style:{minWidth:"120px"},children:n||t?r(N,{children:[e(F,{className:"me-component-gap"}),t?d("form.submitting","Submitting..."):d("form.loading","Loading...")]}):y})]})]})})})};var E=k;export{E as default};
1
+ "use client";import{jsx as e,jsxs as r,Fragment as N}from"react/jsx-runtime";import{useState as j}from"react";import{FormProvider as w}from"react-hook-form";import{Button as s,BUTTON_VARIANT as C,Spinner as F,cn as _,Stack as i,Grid as I}from"@donotdev/components";import{useTranslation as L}from"@donotdev/core";const k=({title:m,onSubmit:c,children:f,formMethods:u,loading:n=!1,submitText:g,cancelText:v,showCancel:p=!1,onCancel:b,variant:l="default",columns:h=1,description:o})=>{const{t:d}=L("dndev"),[t,a]=j(!1),y=g||d("form.submit","Submit"),S=v||d("form.cancel","Cancel"),x=async T=>{a(!0);try{await c(T)}finally{a(!1)}},z={1:"dndev-grid-cols-1",2:"dndev-grid-cols-1 dndev-md:grid-cols-2",3:"dndev-grid-cols-1 dndev-md:grid-cols-2 dndev-md:grid-cols-3",4:"dndev-grid-cols-1 dndev-md:grid-cols-2 dndev-md:grid-cols-4"};return e(w,{...u,children:e("form",{onSubmit:x,className:_("dndev-mx-auto",{default:"dndev-surface",card:"dndev-surface",minimal:""}[l]),style:l!=="minimal"?{padding:"var(--gap-lg)"}:void 0,role:"form","aria-labelledby":"form-title",noValidate:!0,children:r(i,{gap:"large",children:[r(i,{gap:"tight",children:[e("h2",{id:"form-title",style:{fontSize:"var(--font-size-2xl)",fontWeight:600,color:"var(--foreground)"},children:m}),o&&e("p",{style:{color:"var(--muted-foreground)"},children:o})]}),e(I,{cols:h,className:"dndev-w-full dndev-min-w-0",children:f}),r(i,{direction:"row",align:"center",justify:"end",style:{paddingTop:"var(--gap-md)",borderTop:"1px solid var(--border)"},children:[p&&e(s,{type:"button",variant:C.OUTLINE,onClick:b,disabled:n||t,children:S}),e(s,{type:"submit",disabled:n||t,style:{minWidth:"120px"},children:n||t?r(N,{children:[e(F,{className:"me-component-gap"}),t?d("form.submitting","Submitting..."):d("form.loading","Loading...")]}):y})]})]})})})};var E=k;export{E as default};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=EntityFilters.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityFilters.test.d.ts","sourceRoot":"","sources":["../../../src/components/__tests__/EntityFilters.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ import{jsx as i}from"react/jsx-runtime";import{describe as c,it as r,expect as n,vi as e,beforeEach as d}from"vitest";import{render as a,screen as l}from"@testing-library/react";import{EntityFilters as s}from"../EntityFilters";import{defineEntity as u}from"@donotdev/core";e.mock("@donotdev/core",async()=>({...await e.importActual("@donotdev/core"),useTranslation:e.fn(()=>o=>o),handleError:e.fn()})),e.mock("@donotdev/components",()=>({Button:({children:t,...o})=>i("button",{...o,children:t}),Grid:({children:t})=>i("div",{children:t}),Combobox:({children:t})=>i("div",{children:t})})),e.mock("../hooks/useCrudFilters",()=>({useCrudFilters:e.fn(()=>({filters:{},setFilter:e.fn(),clearFilters:e.fn()}))})),c("EntityFilters",()=>{const t=u({name:"Product",collection:"products",fields:{title:{name:"title",label:"Title",type:"text",visibility:"user"},status:{name:"status",label:"Status",type:"select",visibility:"user",validation:{options:[{value:"active",label:"Active"},{value:"inactive",label:"Inactive"}]}}}});d(()=>{e.clearAllMocks()}),r("renders filters for entity fields",()=>{a(i(s,{entity:t})),n(l.getByRole("button",{name:/clear/i})).toBeDefined()}),r("renders with data prop",()=>{a(i(s,{entity:t,data:[{id:"1",title:"Product 1",status:"active"},{id:"2",title:"Product 2",status:"inactive"}]})),n(l.getByRole("button",{name:/clear/i})).toBeDefined()}),r("renders with sidebar variant",()=>{a(i(s,{entity:t,variant:"sidebar"})),n(l.getByRole("button",{name:/clear/i})).toBeDefined()})});
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=FormFieldRenderer.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormFieldRenderer.test.d.ts","sourceRoot":"","sources":["../../../src/components/__tests__/FormFieldRenderer.test.tsx"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ import{jsx as n}from"react/jsx-runtime";import{describe as s,it as i,expect as c,vi as e,beforeEach as f}from"vitest";import{render as l}from"@testing-library/react";import{FormFieldRenderer as a}from"../FormFieldRenderer";e.mock("react-hook-form",()=>({useFormContext:e.fn(()=>({register:e.fn(),control:{},formState:{errors:{}}})),Controller:({render:t})=>{const o={onChange:e.fn(),onBlur:e.fn(),value:"",name:"test-field"};return t({field:o})}})),e.mock("../FieldRegistry",()=>({getFieldRegistry:e.fn(()=>({getComponent:e.fn(()=>()=>n("div",{children:"Mock Field"}))}))})),s("FormFieldRenderer",()=>{const t={name:"title",label:"Title",type:"text",visibility:"user",validation:{required:!0}},o=e.fn(r=>r);f(()=>{e.clearAllMocks()}),i("renders field with correct props",()=>{const{container:r}=l(n(a,{name:"title",config:t,t:o,control:{},errors:{}}));c(r).toBeDefined()}),i("renders textarea field for textarea type",()=>{const r={...t,type:"textarea",name:"description",label:"Description"},{container:d}=l(n(a,{name:"description",config:r,t:o,control:{},errors:{}}));c(d).toBeDefined()}),i("handles uncontrolled mode",()=>{const{container:r}=l(n(a,{name:"title",config:t,t:o,value:"",onChange:e.fn()}));c(r).toBeDefined()})});
@@ -1 +1 @@
1
- "use client";import{jsx as l}from"react/jsx-runtime";import{Controller as g}from"react-hook-form";import{ImageFieldComponent as x}from"../../form/fields";import{convertValidationRules as d}from"../types";function F(i){const{control:m,errors:n,fieldConfig:t,t:s}=i,{name:r,label:u,validation:o}=t,a=t.options||{};return l(g,{name:r,control:m,rules:o?d(o):void 0,render:({field:e})=>{const p=Array.isArray(e.value)?e.value:e.value?[e.value]:null;return l(x,{name:r,label:s(u),value:p,onChange:c=>e.onChange(c),error:!!n[r],helperText:n[r]?.message,required:o?.required,multiple:!0,maxFiles:a.maxFiles??10,maxSize:a.maxSize,storagePath:a.storagePath})}})}export{F as ControlledMultiImageField};
1
+ "use client";import{jsx as l}from"react/jsx-runtime";import{Controller as d}from"react-hook-form";import{ImageFieldComponent as g}from"../../form/fields";import{convertValidationRules as x}from"../types";function F(i){const{control:m,errors:n,fieldConfig:t,t:s}=i,{name:r,label:u,validation:o}=t,a=t.options||{};return l(d,{name:r,control:m,rules:o?x(o):void 0,render:({field:e})=>{const c=Array.isArray(e.value)?e.value:e.value?[e.value]:null;return l(g,{name:r,label:s(u),value:c,onChange:p=>e.onChange(p),error:!!n[r],helperText:n[r]?.message,required:o?.required,multiple:!0,maxFiles:a.maxFiles??10,maxSize:a.maxSize,storagePath:a.fieldSpecific?.storagePath})}})}export{F as ControlledMultiImageField};
@@ -1 +1 @@
1
- import{jsx as r,jsxs as s}from"react/jsx-runtime";import{Badge as t,BADGE_VARIANT as n,Text as a,Stack as d}from"@donotdev/components";const l=({config:o,value:e,t:c,className:i})=>e?s(d,{direction:"row",align:"center",gap:"medium",className:i,children:[r(a,{as:"span",level:"small",children:e.name}),e.size&&s(t,{variant:n.SECONDARY,children:[(e.size/1024).toFixed(1)," KB"]})]}):r(a,{as:"span",variant:"muted",className:i,children:"-"});var x=l;export{l as FileFieldDisplay,x as default};
1
+ import{jsx as r,jsxs as s}from"react/jsx-runtime";import{Badge as a,BADGE_VARIANT as n,Text as t,Stack as l}from"@donotdev/components";const o=({config:c,value:e,t:d,className:i})=>e?s(l,{direction:"row",align:"center",className:i,children:[r(t,{as:"span",level:"small",children:e.name}),e.size&&s(a,{variant:n.SECONDARY,children:[(e.size/1024).toFixed(1)," KB"]})]}):r(t,{as:"span",variant:"muted",className:i,children:"-"});var p=o;export{o as FileFieldDisplay,p as default};
@@ -1 +1 @@
1
- import{jsx as t}from"react/jsx-runtime";import{Badge as e,BADGE_VARIANT as o,Text as p,Stack as s}from"@donotdev/components";const d=({config:m,value:r,t:c,className:a})=>!r||!Array.isArray(r)||r.length===0?t(p,{as:"span",variant:"muted",className:a,children:"-"}):t(s,{direction:"row",wrap:"wrap",gap:"medium",className:a,children:r.map((i,n)=>t(e,{variant:o.OUTLINE,children:String(i)},n))});var l=d;export{d as MultiDropdownDisplay,l as default};
1
+ import{jsx as t}from"react/jsx-runtime";import{Badge as o,BADGE_VARIANT as e,Text as p,Stack as s}from"@donotdev/components";const c=({config:d,value:r,t:m,className:a})=>!r||!Array.isArray(r)||r.length===0?t(p,{as:"span",variant:"muted",className:a,children:"-"}):t(s,{direction:"row",wrap:"wrap",className:a,children:r.map((i,n)=>t(o,{variant:e.OUTLINE,children:String(i)},n))});var x=c;export{c as MultiDropdownDisplay,x as default};
@@ -1 +1 @@
1
- import{jsx as t}from"react/jsx-runtime";import{Badge as n,BADGE_VARIANT as p,Text as o,Stack as s}from"@donotdev/components";const d=({config:m,value:r,t:c,className:i})=>!r||!Array.isArray(r)||r.length===0?t(o,{as:"span",variant:"muted",className:i,children:"-"}):t(s,{direction:"row",wrap:"wrap",gap:"medium",className:i,children:r.map((a,e)=>t(n,{variant:p.OUTLINE,children:String(a)},e))});var f=d;export{d as MultiInputTextFieldDisplay,f as default};
1
+ import{jsx as t}from"react/jsx-runtime";import{Badge as e,BADGE_VARIANT as o,Text as p,Stack as s}from"@donotdev/components";const c=({config:d,value:r,t:m,className:i})=>!r||!Array.isArray(r)||r.length===0?t(p,{as:"span",variant:"muted",className:i,children:"-"}):t(s,{direction:"row",wrap:"wrap",className:i,children:r.map((a,n)=>t(e,{variant:o.OUTLINE,children:String(a)},n))});var f=c;export{c as MultiInputTextFieldDisplay,f as default};
@@ -1 +1 @@
1
- import{jsx as o,jsxs as s}from"react/jsx-runtime";import{Eye as d,EyeOff as n}from"lucide-react";import{useState as c}from"react";import{Skeleton as f,Button as m,CopyToClipboard as y,Stack as a}from"@donotdev/components";const x=({config:b,value:i,t:r,className:t,loading:p=!1})=>{const[e,l]=c(!1);return p?o(f,{className:t}):i?s(a,{direction:"row",align:"center",gap:"medium",className:t,children:[o("span",{style:{fontFamily:"monospace"},children:e?i:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"}),s(a,{direction:"row",align:"center",gap:"tight",children:[o(m,{type:"button",onClick:()=>l(!e),"aria-label":e?"Hide password":"Show password",children:e?o(n,{}):o(d,{})}),o(y,{text:i,tooltipText:r("copyToClipboard")||"Copy to clipboard",copiedTooltipText:r("copied")||"Copied!",ariaLabel:r("copyPassword")||"Copy password"})]})]}):o("div",{style:{color:"var(--muted-foreground)"},children:"-"})};var C=x;export{x as PasswordFieldDisplay,C as default};
1
+ import{jsx as o,jsxs as s}from"react/jsx-runtime";import{Eye as n,EyeOff as d}from"lucide-react";import{useState as c}from"react";import{Skeleton as f,Button as m,CopyToClipboard as y,Stack as a}from"@donotdev/components";const x=({config:b,value:r,t:i,className:t,loading:l=!1})=>{const[e,p]=c(!1);return l?o(f,{className:t}):r?s(a,{direction:"row",align:"center",className:t,children:[o("span",{style:{fontFamily:"monospace"},children:e?r:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"}),s(a,{direction:"row",align:"center",gap:"tight",children:[o(m,{type:"button",onClick:()=>p(!e),"aria-label":e?"Hide password":"Show password",children:e?o(d,{}):o(n,{})}),o(y,{text:r,tooltipText:i("copyToClipboard")||"Copy to clipboard",copiedTooltipText:i("copied")||"Copied!",ariaLabel:i("copyPassword")||"Copy password"})]})]}):o("div",{style:{color:"var(--muted-foreground)"},children:"-"})};var g=x;export{x as PasswordFieldDisplay,g as default};
@@ -1 +1 @@
1
- {"version":3,"file":"RichTextDisplay.d.ts","sourceRoot":"","sources":["../../../../src/components/fields/display/RichTextDisplay.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,MAAM,WAAW,oBAAoB;IACnC,0BAA0B;IAC1B,MAAM,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IAChC,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,2BAA2B;IAC3B,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC;IAC1D,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC,oBAAoB,CAmG/D,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"RichTextDisplay.d.ts","sourceRoot":"","sources":["../../../../src/components/fields/display/RichTextDisplay.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIlD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,MAAM,WAAW,oBAAoB;IACnC,0BAA0B;IAC1B,MAAM,EAAE,WAAW,CAAC,UAAU,CAAC,CAAC;IAChC,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,2BAA2B;IAC3B,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC;IAC1D,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,EAAE,aAAa,CAAC,oBAAoB,CAkG/D,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -1,4 +1,4 @@
1
- import{jsx as e,jsxs as i}from"react/jsx-runtime";import{Text as t}from"@donotdev/components";const s=({config:a,value:r,t:n,className:o})=>!r||r.trim()===""?e(t,{as:"span",variant:"muted",className:o,children:"-"}):i("div",{className:o,style:{padding:"var(--gap-md)",backgroundColor:"var(--muted)",borderRadius:"var(--radius-md)",border:"1px solid var(--border)",minHeight:"38px"},children:[e("div",{dangerouslySetInnerHTML:{__html:r},style:{outline:"none",fontSize:"var(--font-size-base)",lineHeight:"1.6"},className:"prose prose-sm max-w-none"}),e("style",{children:`
1
+ import{jsx as e,jsxs as i}from"react/jsx-runtime";import{Text as t}from"@donotdev/components";import{sanitizeHtml as s}from"../../../utils/sanitizeHtml";const a=({config:n,value:r,t:m,className:o})=>!r||r.trim()===""?e(t,{as:"span",variant:"muted",className:o,children:"-"}):i("div",{className:o,style:{padding:"var(--gap-md)",backgroundColor:"var(--muted)",borderRadius:"var(--radius-md)",border:"1px solid var(--border)",minHeight:"38px"},children:[e("div",{dangerouslySetInnerHTML:{__html:s(r)},style:{outline:"none",fontSize:"var(--font-size-base)",lineHeight:"1.6"},className:"prose prose-sm max-w-none"}),e("style",{children:`
2
2
  /* Match Tiptap ProseMirror styling */
3
3
  .prose p {
4
4
  margin: 0.5em 0;
@@ -58,4 +58,4 @@ import{jsx as e,jsxs as i}from"react/jsx-runtime";import{Text as t}from"@donotde
58
58
  .prose a:hover {
59
59
  color: var(--primary-hover);
60
60
  }
61
- `})]});var p=s;export{s as RichTextDisplay,p as default};
61
+ `})]});var f=a;export{a as RichTextDisplay,f as default};
@@ -1 +1 @@
1
- {"version":3,"file":"AddressFieldComponent.d.ts","sourceRoot":"","sources":["../../../../src/components/form/fields/AddressFieldComponent.tsx"],"names":[],"mappings":"AAiBA;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,2DAA2D;IAC3D,KAAK,CAAC,EAAE;QACN,iBAAiB,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IACF,qBAAqB;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IAC/B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,2DAA2D;IAC3D,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,kBAAkB;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kBAAkB;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,qBAAqB,GAAI,iGAS5B,0BAA0B,4CAiS5B,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
1
+ {"version":3,"file":"AddressFieldComponent.d.ts","sourceRoot":"","sources":["../../../../src/components/form/fields/AddressFieldComponent.tsx"],"names":[],"mappings":"AAiBA;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,2DAA2D;IAC3D,KAAK,CAAC,EAAE;QACN,iBAAiB,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IACF,qBAAqB;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IAC/B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,2DAA2D;IAC3D,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,kBAAkB;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kBAAkB;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,qBAAqB,GAAI,iGAS5B,0BAA0B,4CA6S5B,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
@@ -1 +1 @@
1
- import{jsx as r,jsxs as f}from"react/jsx-runtime";import{MapPin as D}from"lucide-react";import{useState as S,useEffect as w,useRef as b,useMemo as F}from"react";import{Combobox as M,Stack as L}from"@donotdev/components";import{useTranslation as W,getPlatformEnvVar as Y}from"@donotdev/core";const $=({label:C,value:d,onChange:P,enableGoogleMaps:j=!1,extractDistrictCode:O,error:l,helperText:u,required:x})=>{const{t:n}=W("dndev"),[c,m]=S(d?.formatted_address||""),[g,v]=S([]),[I,p]=S(!1),h=b(null),_=b(null),i=b(null),y=Y("GOOGLE_MAPS_API_KEY")||"",s=j&&!!y,V=F(()=>g.map(e=>({value:e.place_id,label:e.description,description:e.structured_formatting?.secondary_text,content:f("div",{style:{display:"flex",alignItems:"center",gap:"var(--gap-sm)"},children:[r(D,{style:{width:"var(--size-icon-sm)",height:"var(--size-icon-sm)"}}),f("div",{children:[r("div",{children:e.description}),e.structured_formatting?.secondary_text&&r("div",{style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:e.structured_formatting.secondary_text})]})]})})),[g]),G=e=>{_.current&&(p(!0),_.current.getDetails({placeId:e,fields:["formatted_address","geometry","address_components"]},(t,o)=>{if(p(!1),o===window.google?.maps?.places?.PlacesServiceStatus.OK&&t){const a=t.formatted_address||"",k=t.geometry?.location?.lat(),q=t.geometry?.location?.lng(),A={formatted_address:a,latitude:k,longitude:q};if(O&&t.address_components){const E=t.address_components.find(U=>U.types.includes("postal_code"))?.long_name||"",T=E.startsWith("92")?92:parseInt(E.slice(-2),10)||null;A.district_code=T}m(a),P(A)}}))};w(()=>{d?.formatted_address&&m(d.formatted_address)},[d]),w(()=>{if(!s)return;const e=()=>{if(window.google?.maps?.places){t();return}if(document.querySelector("#google-maps-script")){const a=setInterval(()=>{window.google?.maps?.places&&(clearInterval(a),t())},100);return}const o=document.createElement("script");o.id="google-maps-script",o.src=`https://maps.googleapis.com/maps/api/js?key=${y}&libraries=places`,o.async=!0,o.defer=!0,o.onload=()=>t(),document.head.appendChild(o)},t=()=>{window.google?.maps?.places&&(h.current=new window.google.maps.places.AutocompleteService,_.current=new window.google.maps.places.PlacesService(document.createElement("div")))};e()},[s,y]),w(()=>{if(!s||!c||!h.current){v([]);return}return i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{p(!0),h.current.getPlacePredictions({input:c,types:["geocode","establishment"]},(e,t)=>{p(!1),t===window.google?.maps?.places?.PlacesServiceStatus.OK&&e?v(e):v([])})},300),()=>{i.current&&clearTimeout(i.current)}},[s,c]);const K=e=>{m(e),P({formatted_address:e})},z=e=>{const t=Array.isArray(e)?e[0]||"":e;if(!s){K(t);return}g.some(a=>a.place_id===t)&&G(t)},R=e=>{s&&m(e)};return s?f(L,{gap:"tight",children:[r(M,{label:C,value:c,onValueChange:z,onSearchChange:R,placeholder:n("common.address_placeholder"),emptyMessage:n(I?"common.loading":"common.no_results"),options:V,required:x,variant:l?"destructive":void 0,isLoading:I,creatable:!0,createLabel:n("actions.use","Use")}),u&&r("p",{style:{fontSize:"var(--font-size-xs)",color:l?"var(--destructive-foreground)":"var(--muted-foreground)"},children:u})]}):f(L,{gap:"tight",children:[r(M,{label:C,value:c,onValueChange:z,placeholder:n("common.address_placeholder"),options:[],required:x,variant:l?"destructive":void 0,creatable:!0,createLabel:n("actions.use","Use")}),u&&r("p",{style:{fontSize:"var(--font-size-xs)",color:l?"var(--destructive-foreground)":"var(--muted-foreground)"},children:u})]})};var Z=$;export{Z as default};
1
+ import{jsx as r,jsxs as p}from"react/jsx-runtime";import{MapPin as D}from"lucide-react";import{useState as S,useEffect as w,useRef as b,useMemo as F}from"react";import{Combobox as M,Stack as L}from"@donotdev/components";import{useTranslation as W,getPlatformEnvVar as Y}from"@donotdev/core";const $=({label:C,value:i,onChange:P,enableGoogleMaps:j=!1,extractDistrictCode:O,error:l,helperText:d,required:x})=>{const{t:n}=W("dndev"),[a,u]=S(i?.formatted_address||""),[f,g]=S([]),[I,m]=S(!1),v=b(null),_=b(null),c=b(null),h=Y("GOOGLE_MAPS_API_KEY")||"",s=j&&!!h,V=F(()=>f.map(e=>({value:e.place_id,label:e.description,description:e.structured_formatting?.secondary_text,content:p("div",{style:{display:"flex",alignItems:"center",gap:"var(--gap-sm)"},children:[r(D,{style:{width:"var(--size-icon-sm)",height:"var(--size-icon-sm)"}}),p("div",{children:[r("div",{children:e.description}),e.structured_formatting?.secondary_text&&r("div",{style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:e.structured_formatting.secondary_text})]})]})})),[f]),K=e=>{_.current&&(m(!0),_.current.getDetails({placeId:e,fields:["formatted_address","geometry","address_components"]},(t,y)=>{if(m(!1),y===window.google?.maps?.places?.PlacesServiceStatus.OK&&t){const o=t.formatted_address||"",k=t.geometry?.location?.lat(),q=t.geometry?.location?.lng(),A={formatted_address:o,latitude:k,longitude:q};if(O&&t.address_components){const E=t.address_components.find(U=>U.types.includes("postal_code"))?.long_name||"",T=E.startsWith("92")?92:parseInt(E.slice(-2),10)||null;A.district_code=T}u(o),P(A)}}))};w(()=>{i?.formatted_address&&u(i.formatted_address)},[i]),w(()=>{if(!s)return;let e=null;const t=()=>{window.google?.maps?.places&&(v.current=new window.google.maps.places.AutocompleteService,_.current=new window.google.maps.places.PlacesService(document.createElement("div")))};return(()=>{if(window.google?.maps?.places){t();return}if(document.querySelector("#google-maps-script")){e=setInterval(()=>{window.google?.maps?.places&&(clearInterval(e),e=null,t())},100);return}const o=document.createElement("script");o.id="google-maps-script",o.src=`https://maps.googleapis.com/maps/api/js?key=${h}&libraries=places`,o.async=!0,o.defer=!0,o.onload=()=>t(),document.head.appendChild(o)})(),()=>{e!==null&&(clearInterval(e),e=null)}},[s,h]),w(()=>{if(!s||!a||!v.current){g([]);return}return c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{m(!0),v.current.getPlacePredictions({input:a,types:["geocode","establishment"]},(e,t)=>{m(!1),t===window.google?.maps?.places?.PlacesServiceStatus.OK&&e?g(e):g([])})},300),()=>{c.current&&clearTimeout(c.current)}},[s,a]);const R=e=>{u(e),P({formatted_address:e})},z=e=>{const t=Array.isArray(e)?e[0]||"":e;if(!s){R(t);return}f.some(o=>o.place_id===t)&&K(t)},G=e=>{s&&u(e)};return s?p(L,{gap:"tight",children:[r(M,{label:C,value:a,onValueChange:z,onSearchChange:G,placeholder:n("common.address_placeholder"),emptyMessage:n(I?"common.loading":"common.no_results"),options:V,required:x,variant:l?"destructive":void 0,isLoading:I,creatable:!0,createLabel:n("actions.use","Use")}),d&&r("p",{style:{fontSize:"var(--font-size-xs)",color:l?"var(--destructive-foreground)":"var(--muted-foreground)"},children:d})]}):p(L,{gap:"tight",children:[r(M,{label:C,value:a,onValueChange:z,placeholder:n("common.address_placeholder"),options:[],required:x,variant:l?"destructive":void 0,creatable:!0,createLabel:n("actions.use","Use")}),d&&r("p",{style:{fontSize:"var(--font-size-xs)",color:l?"var(--destructive-foreground)":"var(--muted-foreground)"},children:d})]})};var Z=$;export{Z as default};
@@ -1 +1 @@
1
- import{jsx as e,jsxs as o}from"react/jsx-runtime";import{Avatar as u,Input as v,cn as h,Stack as n}from"@donotdev/components";const g=({config:t,value:a,onChange:s,error:f,helperText:l,t:i,className:c,...d})=>{const m=r=>r.split(" ").map(p=>p.charAt(0)).slice(0,2).join("").toUpperCase();return o(n,{gap:"medium",children:[o(n,{direction:"row",align:"center",gap:"medium",children:[e(u,{src:a,alt:t.label||"Avatar",fallback:m(t.label||"AV"),style:{height:"var(--touch-target)",width:"var(--touch-target)"}}),e("div",{className:"dndev-flex-1",children:e(v,{type:"url",className:h("dndev-w-full",c),placeholder:i("common.enterAvatarUrl"),value:a,onChange:r=>s(r.target.value),...d})})]}),l&&e("p",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},children:l})]})};var j=g;export{g as AvatarFieldComponent,j as default};
1
+ import{jsx as e,jsxs as o}from"react/jsx-runtime";import{Avatar as v,Input as h,cn as u,Stack as n}from"@donotdev/components";const f=({config:t,value:a,onChange:s,error:g,helperText:l,t:c,className:i,...d})=>{const m=r=>r.split(" ").map(p=>p.charAt(0)).slice(0,2).join("").toUpperCase();return o(n,{children:[o(n,{direction:"row",align:"center",children:[e(v,{src:a,alt:t.label||"Avatar",fallback:m(t.label||"AV"),style:{height:"var(--touch-target)",width:"var(--touch-target)"}}),e("div",{className:"dndev-flex-1",children:e(h,{type:"url",className:u("dndev-w-full",i),placeholder:c("common.enterAvatarUrl"),value:a,onChange:r=>s(r.target.value),...d})})]}),l&&e("p",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},children:l})]})};var j=f;export{f as AvatarFieldComponent,j as default};
@@ -1 +1 @@
1
- import{jsx as e,jsxs as t}from"react/jsx-runtime";import{Badge as s,Input as g,cn as f,Stack as a}from"@donotdev/components";const p=({config:u,value:r,onChange:d,error:v,helperText:n,t:o,variant:i="default",className:l,...m})=>t(a,{gap:"medium",children:[t(a,{direction:"row",align:"center",gap:"medium",children:[e(s,{variant:i,style:{minWidth:0},children:r||o("common.badgePreview")}),e("div",{className:"dndev-flex-1",children:e(g,{type:"text",className:f("dndev-w-full",l),placeholder:o("common.enterBadgeText"),value:r,onChange:c=>d(c.target.value),...m})})]}),n&&e("p",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},children:n})]});var j=p;export{p as BadgeFieldComponent,j as default};
1
+ import{jsx as e,jsxs as t}from"react/jsx-runtime";import{Badge as m,Input as f,cn as g,Stack as a}from"@donotdev/components";const p=({config:u,value:r,onChange:d,error:v,helperText:n,t:o,variant:i="default",className:l,...c})=>t(a,{children:[t(a,{direction:"row",align:"center",children:[e(m,{variant:i,style:{minWidth:0},children:r||o("common.badgePreview")}),e("div",{className:"dndev-flex-1",children:e(f,{type:"text",className:g("dndev-w-full",l),placeholder:o("common.enterBadgeText"),value:r,onChange:s=>d(s.target.value),...c})})]}),n&&e("p",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},children:n})]});var j=p;export{p as BadgeFieldComponent,j as default};
@@ -1 +1 @@
1
- "use client";import{jsx as n,jsxs as l,Fragment as ae}from"react/jsx-runtime";import{Upload as ie,X as se,FileText as P,FileSpreadsheet as le,File as de,Loader2 as ce,Eye as ue}from"lucide-react";import{useCallback as w,useState as M,useRef as F,useEffect as W,useImperativeHandle as pe,forwardRef as me}from"react";import{Button as G,BUTTON_VARIANT as V,Text as g,Stack as x,Progress as fe,Dialog as ge,DialogContent as ve,DialogHeader as he,DialogTitle as ye}from"@donotdev/components";import{handleError as D,useTranslation as we}from"@donotdev/core";import{useUploadContext as xe}from"../../../contexts/UploadContext";import{useUploadStore as Te}from"../../../stores/UploadStore";import{uploadFile as be,deleteFile as Pe,generateFileId as X,getFileIcon as Fe,formatFileSize as De,getDocumentAcceptString as Ne}from"../../../utils/fileStorage";function ke({type:f,className:c}){switch(f){case"pdf":return n(P,{className:c,style:{color:"var(--destructive)"}});case"doc":return n(P,{className:c,style:{color:"var(--primary)"}});case"xls":return n(le,{className:c,style:{color:"var(--success)"}});case"ppt":return n(P,{className:c,style:{color:"var(--warning)"}});case"text":case"html":return n(P,{className:c});default:return n(de,{className:c})}}const q=me(({name:f,label:c,value:v,onChange:N,error:k,helperText:R,multiple:p=!1,maxFiles:A=10,maxSize:C=25*1024*1024,storagePath:L="uploads/documents",required:K,enablePreview:H=!0},J)=>{const{t:Q}=we("dndev"),s=Q,h=xe(),I=Te(),O=!!h,[i,u]=M([]),[j,S]=M(!1),[U,_]=M(null),y=F(null),z=F(!1),T=F(void 0),Y=Ne(),b=w(e=>{const r=e.filter(t=>t.uploaded&&!t.error).map(t=>t.uploaded);N(p?r:r[0]||null)},[p,N]);W(()=>{if(z.current){z.current=!1;return}if(v){const e=[];(Array.isArray(v)?v:[v]).forEach(t=>{t.url&&e.push({id:X(),file:new File([],t.filename),uploadProgress:null,uploaded:t,error:null})}),u(e)}else u([])},[v]);const Z=w(async()=>{const e=i.filter(r=>!r.uploaded&&!r.error&&r.uploadProgress===null);if(e.length!==0){u(r=>r.map(t=>e.some(a=>a.id===t.id)?{...t,uploadProgress:0}:t));for(const r of e)try{const t=await be(r.file,{storagePath:L,onProgress:a=>{u(o=>o.map(d=>d.id===r.id?{...d,uploadProgress:a.progress}:d))}});u(a=>{const o=a.map(d=>d.id===r.id?{...d,uploaded:t,uploadProgress:100,error:null}:d);return queueMicrotask(()=>b(o)),o})}catch{u(a=>a.map(o=>o.id===r.id?{...o,error:"Upload failed",uploadProgress:null}:o))}}},[i,L,b]);T.current=Z,W(()=>{if(!(!h||!f))return I.registerUpload(h,f,async e=>{await T.current?.()}),()=>{I.unregisterUpload(h,f)}},[h,f,I]),pe(J,()=>({upload:async()=>{await T.current?.()},getDocuments:()=>B.current||[]}),[]);const B=F(i);B.current=i;const $=e=>{const r=[".pdf",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".txt",".md",".html",".csv"],t="."+e.name.split(".").pop()?.toLowerCase();return r.includes(t)},E=w(e=>{const t=(p?A:1)-i.length;if(t<=0){D(new Error("Maximum documents reached"),{userMessage:s("document.errors.maxFiles",{max:A}),severity:"warning",showNotification:!0});return}const a=e.slice(0,t),o=[],d=(C/(1024*1024)).toFixed(0);for(const m of a){if(!$(m)){D(new Error("Invalid document type"),{userMessage:s("document.errors.invalidType",{fileName:m.name}),severity:"warning",showNotification:!0});continue}if(m.size>C){D(new Error("Document too large"),{userMessage:s("document.errors.exceedsSize",{fileName:m.name,size:d}),severity:"warning",showNotification:!0});continue}o.push({id:X(),file:m,uploadProgress:null,uploaded:null,error:null})}o.length!==0&&(u(m=>p?[...m,...o]:o),O||setTimeout(()=>T.current?.(),0))},[i,p,A,C,s,O]),ee=e=>{const r=Array.from(e.target.files||[]);r.length>0&&E(r),y.current&&(y.current.value="")},re=w(e=>{e.preventDefault(),S(!1);const r=Array.from(e.dataTransfer.files);E(r)},[E]),te=w(async e=>{const r=i[e];if(r)try{r.uploaded&&await Pe(r.uploaded);const t=i.filter((a,o)=>o!==e);z.current=!0,u(t),setTimeout(()=>b(t),0)}catch(t){D(t,{userMessage:s("document.delete.failed"),severity:"error",showNotification:!0})}},[i,b,s]),ne=e=>{e.uploaded?.url&&e.uploaded.mimeType==="application/pdf"&&_(e.uploaded.url)},oe=p||i.length===0;return l(ae,{children:[l(x,{gap:"tight",children:[l(g,{level:"body",align:"start",children:[c,K?"*":""]}),oe&&l("div",{role:"button",tabIndex:0,"aria-label":s("document.upload.ariaLabel"),className:"dndev-surface","data-variant":k?"destructive":"default",style:{border:"var(--border-width) dashed",borderColor:j?"var(--primary)":k?"var(--destructive)":"var(--border)",borderRadius:"var(--radius-lg)",padding:"var(--gap-lg)",backgroundColor:j?"color-mix(in oklab, var(--primary) 5%, transparent)":"var(--surface)",transition:"border-color var(--dur-fast), background-color var(--dur-fast)",cursor:"pointer",outline:"none"},onDragOver:e=>{e.preventDefault(),S(!0)},onDragLeave:()=>S(!1),onDrop:re,onClick:()=>y.current?.click(),onKeyDown:e=>{(e.key==="Enter"||e.key===" ")&&(e.preventDefault(),y.current?.click())},children:[n("input",{ref:y,type:"file",accept:Y,multiple:p,style:{display:"none"},onChange:ee}),l(x,{align:"center",justify:"center",gap:"medium",children:[n(ie,{className:"dndev-size-lg",style:{color:"var(--muted-foreground)"}}),n(g,{as:"p",variant:"muted",level:"small",align:"center",children:s("document.upload.hint")}),n(g,{as:"p",variant:"muted",level:"caption",align:"center",children:"PDF, Word, Excel, PowerPoint, TXT, Markdown, HTML"})]})]}),i.length>0&&n(x,{gap:"tight",children:i.map((e,r)=>{const t=Fe(e.uploaded?.mimeType||e.file.type,e.file.name),a=e.uploadProgress!==null&&e.uploadProgress<100,o=e.uploaded?.mimeType==="application/pdf"||e.file.name.toLowerCase().endsWith(".pdf");return l("div",{className:"dndev-surface","data-variant":"muted",style:{padding:"var(--gap-md)",borderRadius:"var(--radius-md)",display:"flex",alignItems:"center",gap:"var(--gap-md)"},children:[n(ke,{type:t,className:"dndev-size-md"}),l(x,{gap:"none",style:{flex:1,minWidth:0},children:[n(g,{level:"small",style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.file.name}),l(g,{level:"caption",variant:"muted",children:[De(e.uploaded?.size||e.file.size),e.error&&l("span",{style:{color:"var(--destructive)"},children:[" ","\xB7 ",e.error]})]}),a&&n(fe,{value:e.uploadProgress||0,max:100,style:{marginTop:"var(--gap-xs)"}})]}),l(x,{direction:"row",gap:"tight",children:[H&&o&&e.uploaded&&n(G,{variant:V.GHOST,onClick:()=>ne(e),"aria-label":s("document.preview.ariaLabel"),children:n(ue,{className:"dndev-size-sm"})}),a?n(ce,{className:"dndev-size-sm",style:{animation:"spin 1s linear infinite"}}):n(G,{variant:V.GHOST,onClick:()=>te(r),"aria-label":s("document.delete.ariaLabel"),children:n(se,{className:"dndev-size-sm"})})]})]},e.id)})}),R&&n(g,{level:"caption",variant:k?"destructive":"muted",style:{marginTop:"var(--gap-xs)"},children:R})]}),H&&U&&n(ge,{open:!!U,onOpenChange:()=>_(null),children:l(ve,{style:{maxWidth:"90vw",maxHeight:"90vh",width:"900px",height:"80vh"},children:[n(he,{children:n(ye,{children:s("document.preview.title")})}),n("iframe",{src:U,style:{width:"100%",height:"100%",border:"none",borderRadius:"var(--radius-md)"},title:"PDF Preview"})]})})]})});q.displayName="DocumentFieldComponent";var Re=q;export{Re as default};
1
+ "use client";import{jsx as n,jsxs as l,Fragment as ae}from"react/jsx-runtime";import{Upload as ie,X as se,FileText as P,FileSpreadsheet as le,File as de,Loader2 as ce,Eye as ue}from"lucide-react";import{useCallback as w,useState as M,useRef as F,useEffect as W,useImperativeHandle as pe,forwardRef as me}from"react";import{Button as G,BUTTON_VARIANT as V,Text as g,Stack as x,Progress as fe,Dialog as ge,DialogContent as ve,DialogHeader as he,DialogTitle as ye}from"@donotdev/components";import{handleError as D,useTranslation as we}from"@donotdev/core";import{useUploadContext as xe}from"../../../contexts/UploadContext";import{useUploadStore as Te}from"../../../stores/UploadStore";import{uploadFile as be,deleteFile as Pe,generateFileId as X,getFileIcon as Fe,formatFileSize as De,getDocumentAcceptString as Ne}from"../../../utils/fileStorage";function ke({type:f,className:c}){switch(f){case"pdf":return n(P,{className:c,style:{color:"var(--destructive)"}});case"doc":return n(P,{className:c,style:{color:"var(--primary)"}});case"xls":return n(le,{className:c,style:{color:"var(--success)"}});case"ppt":return n(P,{className:c,style:{color:"var(--warning)"}});case"text":case"html":return n(P,{className:c});default:return n(de,{className:c})}}const q=me(({name:f,label:c,value:v,onChange:N,error:k,helperText:R,multiple:p=!1,maxFiles:A=10,maxSize:C=25*1024*1024,storagePath:L="uploads/documents",required:K,enablePreview:H=!0},J)=>{const{t:Q}=we("dndev"),s=Q,h=xe(),I=Te(),O=!!h,[i,u]=M([]),[j,S]=M(!1),[U,_]=M(null),y=F(null),z=F(!1),T=F(void 0),Y=Ne(),b=w(e=>{const r=e.filter(t=>t.uploaded&&!t.error).map(t=>t.uploaded);N(p?r:r[0]||null)},[p,N]);W(()=>{if(z.current){z.current=!1;return}if(v){const e=[];(Array.isArray(v)?v:[v]).forEach(t=>{t.url&&e.push({id:X(),file:new File([],t.filename),uploadProgress:null,uploaded:t,error:null})}),u(e)}else u([])},[v]);const Z=w(async()=>{const e=i.filter(r=>!r.uploaded&&!r.error&&r.uploadProgress===null);if(e.length!==0){u(r=>r.map(t=>e.some(a=>a.id===t.id)?{...t,uploadProgress:0}:t));for(const r of e)try{const t=await be(r.file,{storagePath:L,onProgress:a=>{u(o=>o.map(d=>d.id===r.id?{...d,uploadProgress:a.progress}:d))}});u(a=>{const o=a.map(d=>d.id===r.id?{...d,uploaded:t,uploadProgress:100,error:null}:d);return queueMicrotask(()=>b(o)),o})}catch{u(a=>a.map(o=>o.id===r.id?{...o,error:"Upload failed",uploadProgress:null}:o))}}},[i,L,b]);T.current=Z,W(()=>{if(!(!h||!f))return I.registerUpload(h,f,async e=>{await T.current?.()}),()=>{I.unregisterUpload(h,f)}},[h,f,I]),pe(J,()=>({upload:async()=>{await T.current?.()},getDocuments:()=>B.current||[]}),[]);const B=F(i);B.current=i;const $=e=>{const r=[".pdf",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".txt",".md",".html",".csv"],t="."+e.name.split(".").pop()?.toLowerCase();return r.includes(t)},E=w(e=>{const t=(p?A:1)-i.length;if(t<=0){D(new Error("Maximum documents reached"),{userMessage:s("document.errors.maxFiles",{max:A}),severity:"warning",showNotification:!0});return}const a=e.slice(0,t),o=[],d=(C/(1024*1024)).toFixed(0);for(const m of a){if(!$(m)){D(new Error("Invalid document type"),{userMessage:s("document.errors.invalidType",{fileName:m.name}),severity:"warning",showNotification:!0});continue}if(m.size>C){D(new Error("Document too large"),{userMessage:s("document.errors.exceedsSize",{fileName:m.name,size:d}),severity:"warning",showNotification:!0});continue}o.push({id:X(),file:m,uploadProgress:null,uploaded:null,error:null})}o.length!==0&&(u(m=>p?[...m,...o]:o),O||setTimeout(()=>T.current?.(),0))},[i,p,A,C,s,O]),ee=e=>{const r=Array.from(e.target.files||[]);r.length>0&&E(r),y.current&&(y.current.value="")},re=w(e=>{e.preventDefault(),S(!1);const r=Array.from(e.dataTransfer.files);E(r)},[E]),te=w(async e=>{const r=i[e];if(r)try{r.uploaded&&await Pe(r.uploaded);const t=i.filter((a,o)=>o!==e);z.current=!0,u(t),setTimeout(()=>b(t),0)}catch(t){D(t,{userMessage:s("document.delete.failed"),severity:"error",showNotification:!0})}},[i,b,s]),ne=e=>{e.uploaded?.url&&e.uploaded.mimeType==="application/pdf"&&_(e.uploaded.url)},oe=p||i.length===0;return l(ae,{children:[l(x,{gap:"tight",children:[l(g,{level:"body",align:"start",children:[c,K?"*":""]}),oe&&l("div",{role:"button",tabIndex:0,"aria-label":s("document.upload.ariaLabel"),className:"dndev-surface","data-variant":k?"destructive":"default",style:{border:"var(--border-width) dashed",borderColor:j?"var(--primary)":k?"var(--destructive)":"var(--border)",borderRadius:"var(--radius-lg)",padding:"var(--gap-lg)",backgroundColor:j?"color-mix(in oklab, var(--primary) 5%, transparent)":"var(--surface)",transition:"border-color var(--dur-fast), background-color var(--dur-fast)",cursor:"pointer",outline:"none"},onDragOver:e=>{e.preventDefault(),S(!0)},onDragLeave:()=>S(!1),onDrop:re,onClick:()=>y.current?.click(),onKeyDown:e=>{(e.key==="Enter"||e.key===" ")&&(e.preventDefault(),y.current?.click())},children:[n("input",{ref:y,type:"file",accept:Y,multiple:p,style:{display:"none"},onChange:ee}),l(x,{align:"center",justify:"center",children:[n(ie,{className:"dndev-size-lg",style:{color:"var(--muted-foreground)"}}),n(g,{as:"p",variant:"muted",level:"small",align:"center",children:s("document.upload.hint")}),n(g,{as:"p",variant:"muted",level:"caption",align:"center",children:"PDF, Word, Excel, PowerPoint, TXT, Markdown, HTML"})]})]}),i.length>0&&n(x,{gap:"tight",children:i.map((e,r)=>{const t=Fe(e.uploaded?.mimeType||e.file.type,e.file.name),a=e.uploadProgress!==null&&e.uploadProgress<100,o=e.uploaded?.mimeType==="application/pdf"||e.file.name.toLowerCase().endsWith(".pdf");return l("div",{className:"dndev-surface","data-variant":"muted",style:{padding:"var(--gap-md)",borderRadius:"var(--radius-md)",display:"flex",alignItems:"center",gap:"var(--gap-md)"},children:[n(ke,{type:t,className:"dndev-size-md"}),l(x,{gap:"none",style:{flex:1,minWidth:0},children:[n(g,{level:"small",style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.file.name}),l(g,{level:"caption",variant:"muted",children:[De(e.uploaded?.size||e.file.size),e.error&&l("span",{style:{color:"var(--destructive)"},children:[" ","\xB7 ",e.error]})]}),a&&n(fe,{value:e.uploadProgress||0,max:100,style:{marginTop:"var(--gap-xs)"}})]}),l(x,{direction:"row",gap:"tight",children:[H&&o&&e.uploaded&&n(G,{variant:V.GHOST,onClick:()=>ne(e),"aria-label":s("document.preview.ariaLabel"),children:n(ue,{className:"dndev-size-sm"})}),a?n(ce,{className:"dndev-size-sm",style:{animation:"spin 1s linear infinite"}}):n(G,{variant:V.GHOST,onClick:()=>te(r),"aria-label":s("document.delete.ariaLabel"),children:n(se,{className:"dndev-size-sm"})})]})]},e.id)})}),R&&n(g,{level:"caption",variant:k?"destructive":"muted",style:{marginTop:"var(--gap-xs)"},children:R})]}),H&&U&&n(ge,{open:!!U,onOpenChange:()=>_(null),children:l(ve,{style:{maxWidth:"90vw",maxHeight:"90vh",width:"900px",height:"80vh"},children:[n(he,{children:n(ye,{children:s("document.preview.title")})}),n("iframe",{src:U,style:{width:"100%",height:"100%",border:"none",borderRadius:"var(--radius-md)"},title:"PDF Preview"})]})})]})});q.displayName="DocumentFieldComponent";var Re=q;export{Re as default};
@@ -1 +1 @@
1
- {"version":3,"file":"DurationFieldComponent.d.ts","sourceRoot":"","sources":["../../../../src/components/form/fields/DurationFieldComponent.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,kCAAkC;AAClC,eAAO,MAAM,gBAAgB,8CAA+C,CAAC;AAE7E,MAAM,WAAW,2BAA2B;IAC1C,0BAA0B;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,+BAA+B;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,0CAA0C;IAC1C,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kBAAkB;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC;CAChE;AAoBD;;;;;;GAMG;AACH,QAAA,MAAM,sBAAsB,EAAE,aAAa,CAAC,2BAA2B,CA0HtE,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
1
+ {"version":3,"file":"DurationFieldComponent.d.ts","sourceRoot":"","sources":["../../../../src/components/form/fields/DurationFieldComponent.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C,kCAAkC;AAClC,eAAO,MAAM,gBAAgB,8CAA+C,CAAC;AAE7E,MAAM,WAAW,2BAA2B;IAC1C,0BAA0B;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,+BAA+B;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,0CAA0C;IAC1C,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kBAAkB;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,uDAAuD;IACvD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC;CAChE;AA4BD;;;;;;GAMG;AACH,QAAA,MAAM,sBAAsB,EAAE,aAAa,CAAC,2BAA2B,CAkLtE,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
@@ -1 +1 @@
1
- import{jsx as a,jsxs as u}from"react/jsx-runtime";import{useState as w,useMemo as C}from"react";import{Clock as S}from"lucide-react";import{Label as $,Stack as l,Button as b,Slider as E}from"@donotdev/components";const x=[15,30,45,60,90,120,150,180],N={15:"duration.15m",30:"duration.30m",45:"duration.45m",60:"duration.1h",90:"duration.1h30",120:"duration.2h",150:"duration.2h30",180:"duration.3h"};function _(e,n){const i=e<60?`${e}m`:e%60===0?`${e/60}h`:`${Math.floor(e/60)}h${e%60}`,s=N[e];return!n||!s?i:n(`crud:${s}`,{defaultValue:i})??i}const j=({label:e,value:n,onChange:i,error:s,helperText:d,disabled:c,required:h,readonly:M,min:p=0,max:g=480,step:V=5,t:o})=>{const r=typeof n=="number"&&!Number.isNaN(n)?n:0,m=x.includes(r),[f,v]=w(!m&&r>0),k=C(()=>x.map(t=>({minutes:t,label:_(t,o)})),[o]),y=o?o("crud:duration.custom",{defaultValue:"Custom"}):"Custom";if(M){const t=r===0?o?o("crud:duration.zero",{defaultValue:"\u2014"}):"\u2014":r<60?o?o("crud:duration.minutes",{count:r,defaultValue:`${r} min`}):`${r} min`:o?o("crud:duration.hoursMinutes",{hours:Math.floor(r/60),minutes:r%60,defaultValue:`${Math.floor(r/60)}h${r%60?` ${r%60}min`:""}`}):`${Math.floor(r/60)}h${r%60?` ${r%60}m`:""}`;return u(l,{gap:"tight",children:[a($,{required:h,style:{fontSize:"var(--font-size-sm)",fontWeight:500},children:e}),u(l,{direction:"row",gap:"tight",align:"center",children:[a(S,{size:18,style:{color:"var(--muted-foreground)"},"aria-hidden":!0}),a("span",{style:{color:"var(--muted-foreground)",fontSize:"var(--font-size-sm)"},children:t})]}),d&&a("p",{style:{fontSize:"var(--font-size-xs)",color:s?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:d})]})}return u(l,{gap:"medium",children:[a($,{required:h,style:{fontSize:"var(--font-size-sm)",fontWeight:500},children:e}),u(l,{direction:"row",gap:"tight",align:"center",style:{flexWrap:"wrap"},children:[k.map(({minutes:t,label:z})=>u(b,{type:"button",variant:r===t?"primary":"outline",disabled:c,onClick:()=>{v(!1),i(t)},"aria-pressed":r===t,"aria-label":z,children:[a(S,{size:14,style:{marginRight:"var(--gap-xs)"},"aria-hidden":!0}),z]},t)),a(b,{type:"button",variant:f?"primary":"outline",disabled:c,onClick:()=>{v(!0),!m&&r>0?i(r):i(30)},"aria-pressed":f,"aria-label":y,children:y})]}),f&&a(l,{gap:"tight",style:{marginTop:"var(--gap-sm)"},children:a(E,{value:[m?30:r],onValueChange:([t])=>i(Math.max(p,Math.min(g,t??0))),min:p,max:g,step:V,showValue:!0,disabled:c,"aria-label":e})}),d&&a("p",{style:{fontSize:"var(--font-size-xs)",color:s?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:d})]})};var W=j;export{x as DURATION_PRESETS,W as default};
1
+ import{jsx as a,jsxs as u}from"react/jsx-runtime";import{useState as w,useMemo as C}from"react";import{Clock as S}from"lucide-react";import{Label as $,Stack as l,Button as b,Slider as E}from"@donotdev/components";const x=[15,30,45,60,90,120,150,180],N={15:"duration.15m",30:"duration.30m",45:"duration.45m",60:"duration.1h",90:"duration.1h30",120:"duration.2h",150:"duration.2h30",180:"duration.3h"};function _(t,n){const i=t<60?`${t}m`:t%60===0?`${t/60}h`:`${Math.floor(t/60)}h${t%60}`,s=N[t];return!n||!s?i:n(`crud:${s}`,{defaultValue:i})??i}const j=({label:t,value:n,onChange:i,error:s,helperText:d,disabled:c,required:h,readonly:M,min:p=0,max:g=480,step:V=5,t:o})=>{const r=typeof n=="number"&&!Number.isNaN(n)?n:0,f=x.includes(r),[m,v]=w(!f&&r>0),k=C(()=>x.map(e=>({minutes:e,label:_(e,o)})),[o]),y=o?o("crud:duration.custom",{defaultValue:"Custom"}):"Custom";if(M){const e=r===0?o?o("crud:duration.zero",{defaultValue:"\u2014"}):"\u2014":r<60?o?o("crud:duration.minutes",{count:r,defaultValue:`${r} min`}):`${r} min`:o?o("crud:duration.hoursMinutes",{hours:Math.floor(r/60),minutes:r%60,defaultValue:`${Math.floor(r/60)}h${r%60?` ${r%60}min`:""}`}):`${Math.floor(r/60)}h${r%60?` ${r%60}m`:""}`;return u(l,{gap:"tight",children:[a($,{required:h,style:{fontSize:"var(--font-size-sm)",fontWeight:500},children:t}),u(l,{direction:"row",gap:"tight",align:"center",children:[a(S,{size:18,style:{color:"var(--muted-foreground)"},"aria-hidden":!0}),a("span",{style:{color:"var(--muted-foreground)",fontSize:"var(--font-size-sm)"},children:e})]}),d&&a("p",{style:{fontSize:"var(--font-size-xs)",color:s?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:d})]})}return u(l,{children:[a($,{required:h,style:{fontSize:"var(--font-size-sm)",fontWeight:500},children:t}),u(l,{direction:"row",gap:"tight",align:"center",style:{flexWrap:"wrap"},children:[k.map(({minutes:e,label:z})=>u(b,{type:"button",variant:r===e?"primary":"outline",disabled:c,onClick:()=>{v(!1),i(e)},"aria-pressed":r===e,"aria-label":z,children:[a(S,{size:14,style:{marginRight:"var(--gap-xs)"},"aria-hidden":!0}),z]},e)),a(b,{type:"button",variant:m?"primary":"outline",disabled:c,onClick:()=>{v(!0),!f&&r>0?i(r):i(30)},"aria-pressed":m,"aria-label":y,children:y})]}),m&&a(l,{gap:"tight",style:{marginTop:"var(--gap-sm)"},children:a(E,{value:[f?30:r],onValueChange:([e])=>i(Math.max(p,Math.min(g,e??0))),min:p,max:g,step:V,showValue:!0,disabled:c,"aria-label":t})}),d&&a("p",{style:{fontSize:"var(--font-size-xs)",color:s?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:d})]})};var W=j;export{x as DURATION_PRESETS,W as default};
@@ -1 +1 @@
1
- "use client";import{jsx as s,jsxs as p}from"react/jsx-runtime";import{Upload as Z,X as $,File as ee,Loader2 as re,FileText as C,FileSpreadsheet as oe,FileImage as se,FileVideo as ae,FileAudio as te,FileArchive as le,FileCode as ne}from"lucide-react";import{useCallback as y,useState as O,useRef as b,useEffect as _,useImperativeHandle as ie,forwardRef as de}from"react";import{Button as ue,BUTTON_VARIANT as ce,Text as F,Stack as P,Progress as pe}from"@donotdev/components";import{handleError as M,useTranslation as fe}from"@donotdev/core";import{useUploadContext as ge}from"../../../contexts/UploadContext";import{useUploadStore as me}from"../../../stores/UploadStore";import{uploadFile as ve,deleteFile as he,generateFileId as H,getFileIcon as ye,formatFileSize as Fe}from"../../../utils/fileStorage";function we({type:f,className:n}){switch(f){case"pdf":return s(C,{className:n,style:{color:"var(--destructive)"}});case"doc":return s(C,{className:n,style:{color:"var(--primary)"}});case"xls":return s(oe,{className:n,style:{color:"var(--success)"}});case"ppt":return s(C,{className:n,style:{color:"var(--warning)"}});case"image":return s(se,{className:n});case"video":return s(ae,{className:n});case"audio":return s(te,{className:n});case"archive":return s(le,{className:n});case"html":case"text":return s(ne,{className:n});default:return s(ee,{className:n})}}const D=de(({name:f,label:n,value:g,onChange:T,error:A,helperText:R,accept:V,multiple:d=!1,maxFiles:N=10,maxSize:k=50*1024*1024,storagePath:E="uploads/files",required:q},G)=>{const{t:K}=fe("dndev"),i=K,m=ge(),I=me(),j=!!m,[t,c]=O([]),[L,U]=O(!1),v=b(null),S=b(!1),w=b(void 0),x=y(e=>{const r=e.filter(o=>o.uploaded&&!o.error).map(o=>o.uploaded);T(d?r:r[0]||null)},[d,T]);_(()=>{if(S.current){S.current=!1;return}if(g){const e=[];(Array.isArray(g)?g:[g]).forEach(o=>{o.url&&e.push({id:H(),file:new File([],o.filename),uploadProgress:null,uploaded:o,error:null})}),c(e)}else c([])},[g]);const W=y(async()=>{const e=t.filter(r=>!r.uploaded&&!r.error&&r.uploadProgress===null);if(e.length!==0){c(r=>r.map(o=>e.some(l=>l.id===o.id)?{...o,uploadProgress:0}:o));for(const r of e)try{const o=await ve(r.file,{storagePath:E,onProgress:l=>{c(a=>a.map(u=>u.id===r.id?{...u,uploadProgress:l.progress}:u))}});c(l=>{const a=l.map(u=>u.id===r.id?{...u,uploaded:o,uploadProgress:100,error:null}:u);return queueMicrotask(()=>x(a)),a})}catch{c(l=>l.map(a=>a.id===r.id?{...a,error:"Upload failed",uploadProgress:null}:a))}}},[t,E,x]);w.current=W,_(()=>{if(!(!m||!f))return I.registerUpload(m,f,async e=>{await w.current?.()}),()=>{I.unregisterUpload(m,f)}},[m,f,I]),ie(G,()=>({upload:async()=>{await w.current?.()},getFiles:()=>B.current||[]}),[]);const B=b(t);B.current=t;const z=y(e=>{const o=(d?N:1)-t.length;if(o<=0){M(new Error("Maximum files reached"),{userMessage:i("file.errors.maxFiles",{max:N}),severity:"warning",showNotification:!0});return}const l=e.slice(0,o),a=[],u=(k/(1024*1024)).toFixed(0);for(const h of l){if(h.size>k){M(new Error("File too large"),{userMessage:i("file.errors.exceedsSize",{fileName:h.name,size:u}),severity:"warning",showNotification:!0});continue}a.push({id:H(),file:h,uploadProgress:null,uploaded:null,error:null})}a.length!==0&&(c(h=>d?[...h,...a]:a),j||setTimeout(()=>w.current?.(),0))},[t,d,N,k,i,j]),X=e=>{const r=Array.from(e.target.files||[]);r.length>0&&z(r),v.current&&(v.current.value="")},J=y(e=>{e.preventDefault(),U(!1);const r=Array.from(e.dataTransfer.files);z(r)},[z]),Q=y(async e=>{const r=t[e];if(r)try{r.uploaded&&await he(r.uploaded);const o=t.filter((l,a)=>a!==e);S.current=!0,c(o),setTimeout(()=>x(o),0)}catch(o){M(o,{userMessage:i("file.delete.failed"),severity:"error",showNotification:!0})}},[t,x,i]),Y=d||t.length===0,xe=t.some(e=>!e.uploaded&&!e.error&&e.uploadProgress===null);return p(P,{gap:"tight",children:[p(F,{level:"body",align:"start",children:[n,q?"*":""]}),Y&&p("div",{role:"button",tabIndex:0,"aria-label":i(d?"file.upload.ariaLabelMultiple":"file.upload.ariaLabelSingle"),className:"dndev-surface","data-variant":A?"destructive":"default",style:{border:"var(--border-width) dashed",borderColor:L?"var(--primary)":A?"var(--destructive)":"var(--border)",borderRadius:"var(--radius-lg)",padding:"var(--gap-lg)",backgroundColor:L?"color-mix(in oklab, var(--primary) 5%, transparent)":"var(--surface)",transition:"border-color var(--dur-fast), background-color var(--dur-fast)",cursor:"pointer",outline:"none"},onDragOver:e=>{e.preventDefault(),U(!0)},onDragLeave:()=>U(!1),onDrop:J,onClick:()=>v.current?.click(),onKeyDown:e=>{(e.key==="Enter"||e.key===" ")&&(e.preventDefault(),v.current?.click())},children:[s("input",{ref:v,type:"file",accept:V,multiple:d,style:{display:"none"},onChange:X}),p(P,{align:"center",justify:"center",gap:"medium",children:[s(Z,{className:"dndev-size-lg",style:{color:"var(--muted-foreground)"}}),s(F,{as:"p",variant:"muted",level:"small",align:"center",children:i(d?"file.upload.dragDropMultiple":"file.upload.dragDropSingle")})]})]}),t.length>0&&s(P,{gap:"tight",children:t.map((e,r)=>{const o=ye(e.uploaded?.mimeType||e.file.type,e.file.name),l=e.uploadProgress!==null&&e.uploadProgress<100,a=e.uploaded&&!e.error;return p("div",{className:"dndev-surface","data-variant":"muted",style:{padding:"var(--gap-md)",borderRadius:"var(--radius-md)",display:"flex",alignItems:"center",gap:"var(--gap-md)"},children:[s(we,{type:o,className:"dndev-size-md"}),p(P,{gap:"none",style:{flex:1,minWidth:0},children:[s(F,{level:"small",style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.file.name}),p(F,{level:"caption",variant:"muted",children:[Fe(e.uploaded?.size||e.file.size),e.error&&p("span",{style:{color:"var(--destructive)"},children:[" ","\xB7 ",e.error]})]}),l&&s(pe,{value:e.uploadProgress||0,max:100,style:{marginTop:"var(--gap-xs)"}})]}),l?s(re,{className:"dndev-size-sm",style:{animation:"spin 1s linear infinite"}}):s(ue,{variant:ce.GHOST,onClick:()=>Q(r),"aria-label":i("file.delete.ariaLabel"),children:s($,{className:"dndev-size-sm"})})]},e.id)})}),R&&s(F,{level:"caption",variant:A?"destructive":"muted",style:{marginTop:"var(--gap-xs)"},children:R})]})});D.displayName="FileFieldComponent";var ze=D;export{ze as default};
1
+ "use client";import{jsx as s,jsxs as p}from"react/jsx-runtime";import{Upload as Z,X as $,File as ee,Loader2 as re,FileText as C,FileSpreadsheet as oe,FileImage as se,FileVideo as te,FileAudio as ae,FileArchive as le,FileCode as ne}from"lucide-react";import{useCallback as y,useState as O,useRef as b,useEffect as _,useImperativeHandle as ie,forwardRef as de}from"react";import{Button as ue,BUTTON_VARIANT as ce,Text as F,Stack as P,Progress as pe}from"@donotdev/components";import{handleError as M,useTranslation as fe}from"@donotdev/core";import{useUploadContext as ge}from"../../../contexts/UploadContext";import{useUploadStore as me}from"../../../stores/UploadStore";import{uploadFile as ve,deleteFile as he,generateFileId as H,getFileIcon as ye,formatFileSize as Fe}from"../../../utils/fileStorage";function we({type:f,className:n}){switch(f){case"pdf":return s(C,{className:n,style:{color:"var(--destructive)"}});case"doc":return s(C,{className:n,style:{color:"var(--primary)"}});case"xls":return s(oe,{className:n,style:{color:"var(--success)"}});case"ppt":return s(C,{className:n,style:{color:"var(--warning)"}});case"image":return s(se,{className:n});case"video":return s(te,{className:n});case"audio":return s(ae,{className:n});case"archive":return s(le,{className:n});case"html":case"text":return s(ne,{className:n});default:return s(ee,{className:n})}}const D=de(({name:f,label:n,value:g,onChange:T,error:A,helperText:R,accept:V,multiple:d=!1,maxFiles:N=10,maxSize:k=50*1024*1024,storagePath:E="uploads/files",required:q},G)=>{const{t:K}=fe("dndev"),i=K,m=ge(),I=me(),j=!!m,[a,c]=O([]),[L,U]=O(!1),v=b(null),S=b(!1),w=b(void 0),x=y(e=>{const r=e.filter(o=>o.uploaded&&!o.error).map(o=>o.uploaded);T(d?r:r[0]||null)},[d,T]);_(()=>{if(S.current){S.current=!1;return}if(g){const e=[];(Array.isArray(g)?g:[g]).forEach(o=>{o.url&&e.push({id:H(),file:new File([],o.filename),uploadProgress:null,uploaded:o,error:null})}),c(e)}else c([])},[g]);const W=y(async()=>{const e=a.filter(r=>!r.uploaded&&!r.error&&r.uploadProgress===null);if(e.length!==0){c(r=>r.map(o=>e.some(l=>l.id===o.id)?{...o,uploadProgress:0}:o));for(const r of e)try{const o=await ve(r.file,{storagePath:E,onProgress:l=>{c(t=>t.map(u=>u.id===r.id?{...u,uploadProgress:l.progress}:u))}});c(l=>{const t=l.map(u=>u.id===r.id?{...u,uploaded:o,uploadProgress:100,error:null}:u);return queueMicrotask(()=>x(t)),t})}catch{c(l=>l.map(t=>t.id===r.id?{...t,error:"Upload failed",uploadProgress:null}:t))}}},[a,E,x]);w.current=W,_(()=>{if(!(!m||!f))return I.registerUpload(m,f,async e=>{await w.current?.()}),()=>{I.unregisterUpload(m,f)}},[m,f,I]),ie(G,()=>({upload:async()=>{await w.current?.()},getFiles:()=>B.current||[]}),[]);const B=b(a);B.current=a;const z=y(e=>{const o=(d?N:1)-a.length;if(o<=0){M(new Error("Maximum files reached"),{userMessage:i("file.errors.maxFiles",{max:N}),severity:"warning",showNotification:!0});return}const l=e.slice(0,o),t=[],u=(k/(1024*1024)).toFixed(0);for(const h of l){if(h.size>k){M(new Error("File too large"),{userMessage:i("file.errors.exceedsSize",{fileName:h.name,size:u}),severity:"warning",showNotification:!0});continue}t.push({id:H(),file:h,uploadProgress:null,uploaded:null,error:null})}t.length!==0&&(c(h=>d?[...h,...t]:t),j||setTimeout(()=>w.current?.(),0))},[a,d,N,k,i,j]),X=e=>{const r=Array.from(e.target.files||[]);r.length>0&&z(r),v.current&&(v.current.value="")},J=y(e=>{e.preventDefault(),U(!1);const r=Array.from(e.dataTransfer.files);z(r)},[z]),Q=y(async e=>{const r=a[e];if(r)try{r.uploaded&&await he(r.uploaded);const o=a.filter((l,t)=>t!==e);S.current=!0,c(o),setTimeout(()=>x(o),0)}catch(o){M(o,{userMessage:i("file.delete.failed"),severity:"error",showNotification:!0})}},[a,x,i]),Y=d||a.length===0,xe=a.some(e=>!e.uploaded&&!e.error&&e.uploadProgress===null);return p(P,{gap:"tight",children:[p(F,{level:"body",align:"start",children:[n,q?"*":""]}),Y&&p("div",{role:"button",tabIndex:0,"aria-label":i(d?"file.upload.ariaLabelMultiple":"file.upload.ariaLabelSingle"),className:"dndev-surface","data-variant":A?"destructive":"default",style:{border:"var(--border-width) dashed",borderColor:L?"var(--primary)":A?"var(--destructive)":"var(--border)",borderRadius:"var(--radius-lg)",padding:"var(--gap-lg)",backgroundColor:L?"color-mix(in oklab, var(--primary) 5%, transparent)":"var(--surface)",transition:"border-color var(--dur-fast), background-color var(--dur-fast)",cursor:"pointer",outline:"none"},onDragOver:e=>{e.preventDefault(),U(!0)},onDragLeave:()=>U(!1),onDrop:J,onClick:()=>v.current?.click(),onKeyDown:e=>{(e.key==="Enter"||e.key===" ")&&(e.preventDefault(),v.current?.click())},children:[s("input",{ref:v,type:"file",accept:V,multiple:d,style:{display:"none"},onChange:X}),p(P,{align:"center",justify:"center",children:[s(Z,{className:"dndev-size-lg",style:{color:"var(--muted-foreground)"}}),s(F,{as:"p",variant:"muted",level:"small",align:"center",children:i(d?"file.upload.dragDropMultiple":"file.upload.dragDropSingle")})]})]}),a.length>0&&s(P,{gap:"tight",children:a.map((e,r)=>{const o=ye(e.uploaded?.mimeType||e.file.type,e.file.name),l=e.uploadProgress!==null&&e.uploadProgress<100,t=e.uploaded&&!e.error;return p("div",{className:"dndev-surface","data-variant":"muted",style:{padding:"var(--gap-md)",borderRadius:"var(--radius-md)",display:"flex",alignItems:"center",gap:"var(--gap-md)"},children:[s(we,{type:o,className:"dndev-size-md"}),p(P,{gap:"none",style:{flex:1,minWidth:0},children:[s(F,{level:"small",style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.file.name}),p(F,{level:"caption",variant:"muted",children:[Fe(e.uploaded?.size||e.file.size),e.error&&p("span",{style:{color:"var(--destructive)"},children:[" ","\xB7 ",e.error]})]}),l&&s(pe,{value:e.uploadProgress||0,max:100,style:{marginTop:"var(--gap-xs)"}})]}),l?s(re,{className:"dndev-size-sm",style:{animation:"spin 1s linear infinite"}}):s(ue,{variant:ce.GHOST,onClick:()=>Q(r),"aria-label":i("file.delete.ariaLabel"),children:s($,{className:"dndev-size-sm"})})]},e.id)})}),R&&s(F,{level:"caption",variant:A?"destructive":"muted",style:{marginTop:"var(--gap-xs)"},children:R})]})});D.displayName="FileFieldComponent";var ze=D;export{ze as default};
@@ -1 +1 @@
1
- import{jsx as n,jsxs as c}from"react/jsx-runtime";import{Label as h,Input as g,Stack as u}from"@donotdev/components";const y=({label:m,value:e={lat:0,lng:0},onChange:l,error:a,helperText:r,disabled:d,required:f})=>{const v=i=>{const t=parseFloat(i.target.value)||0;if(t>=-90&&t<=90){const s={...e,lat:t},o={target:{value:JSON.stringify(s)}};l(o)}},p=i=>{const t=parseFloat(i.target.value)||0;if(t>=-180&&t<=180){const s={...e,lng:t},o={target:{value:JSON.stringify(s)}};l(o)}};return c(u,{gap:"tight",children:[n(h,{required:f,style:{display:"block",fontSize:"var(--font-size-sm)",fontWeight:500},children:m}),c(u,{direction:"row",gap:"medium",children:[n(g,{label:"Latitude",type:"number",value:e.lat,onChange:v,min:"-90",max:"90",step:"0.000001",disabled:d,"data-variant":a?"destructive":void 0,className:"dndev-w-full"}),n(g,{label:"Longitude",type:"number",value:e.lng,onChange:p,min:"-180",max:"180",step:"0.000001",disabled:d,"data-variant":a?"destructive":void 0,className:"dndev-w-full"})]}),r&&n("p",{style:{fontSize:"var(--font-size-xs)",color:a?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:r})]})};var L=y;export{L as default};
1
+ import{jsx as n,jsxs as c}from"react/jsx-runtime";import{Label as h,Input as g,Stack as u}from"@donotdev/components";const y=({label:f,value:e={lat:0,lng:0},onChange:l,error:a,helperText:r,disabled:d,required:m})=>{const v=i=>{const t=parseFloat(i.target.value)||0;if(t>=-90&&t<=90){const s={...e,lat:t},o={target:{value:JSON.stringify(s)}};l(o)}},p=i=>{const t=parseFloat(i.target.value)||0;if(t>=-180&&t<=180){const s={...e,lng:t},o={target:{value:JSON.stringify(s)}};l(o)}};return c(u,{gap:"tight",children:[n(h,{required:m,style:{display:"block",fontSize:"var(--font-size-sm)",fontWeight:500},children:f}),c(u,{direction:"row",children:[n(g,{label:"Latitude",type:"number",value:e.lat,onChange:v,min:"-90",max:"90",step:"0.000001",disabled:d,"data-variant":a?"destructive":void 0,className:"dndev-w-full"}),n(g,{label:"Longitude",type:"number",value:e.lng,onChange:p,min:"-180",max:"180",step:"0.000001",disabled:d,"data-variant":a?"destructive":void 0,className:"dndev-w-full"})]}),r&&n("p",{style:{fontSize:"var(--font-size-xs)",color:a?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:r})]})};var L=y;export{L as default};