@donotdev/crud 0.0.11 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/dist/CrudService.js +1 -1
  2. package/dist/CrudStore.js +1 -1
  3. package/dist/FieldRegistry.js +1 -1
  4. package/dist/adapters/FirestoreAdapter.js +1 -1
  5. package/dist/adapters/FunctionsAdapter.js +1 -1
  6. package/dist/adapters/index.js +1 -1
  7. package/dist/components/CrudButton.js +1 -1
  8. package/dist/components/DisplayFieldRenderer.js +1 -1
  9. package/dist/components/EntityDisplayRenderer.js +1 -1
  10. package/dist/components/EntityFilters.d.ts.map +1 -1
  11. package/dist/components/EntityFilters.js +1 -1
  12. package/dist/components/EntityFormRenderer.d.ts.map +1 -1
  13. package/dist/components/EntityFormRenderer.js +1 -1
  14. package/dist/components/FormFieldRenderer.js +1 -1
  15. package/dist/components/FormLayout.js +1 -1
  16. package/dist/components/controlled/complex/ControlledAddressField.js +1 -1
  17. package/dist/components/controlled/complex/ControlledDateField.js +1 -1
  18. package/dist/components/controlled/complex/ControlledGeoPointField.js +1 -1
  19. package/dist/components/controlled/complex/ControlledMapField.js +1 -1
  20. package/dist/components/controlled/complex/ControlledMultiInputField.js +1 -1
  21. package/dist/components/controlled/complex/ControlledRichTextField.js +1 -1
  22. package/dist/components/controlled/complex/ControlledTimestampField.js +1 -1
  23. package/dist/components/controlled/complex/index.js +1 -1
  24. package/dist/components/controlled/file/ControlledDocumentField.js +1 -1
  25. package/dist/components/controlled/file/ControlledFileField.js +1 -1
  26. package/dist/components/controlled/file/ControlledImageField.js +1 -1
  27. package/dist/components/controlled/file/ControlledMultiDocumentField.js +1 -1
  28. package/dist/components/controlled/file/ControlledMultiFileField.js +1 -1
  29. package/dist/components/controlled/file/ControlledMultiImageField.js +1 -1
  30. package/dist/components/controlled/file/index.js +1 -1
  31. package/dist/components/controlled/index.js +1 -1
  32. package/dist/components/controlled/input/ControlledCheckboxField.js +1 -1
  33. package/dist/components/controlled/input/ControlledCurrencyField.js +1 -1
  34. package/dist/components/controlled/input/ControlledDurationField.js +1 -1
  35. package/dist/components/controlled/input/ControlledGdprConsentField.js +1 -1
  36. package/dist/components/controlled/input/ControlledNumberField.js +1 -1
  37. package/dist/components/controlled/input/ControlledPasswordField.js +1 -1
  38. package/dist/components/controlled/input/ControlledPhoneField.js +1 -1
  39. package/dist/components/controlled/input/ControlledPriceField.js +1 -1
  40. package/dist/components/controlled/input/ControlledRangeField.js +1 -1
  41. package/dist/components/controlled/input/ControlledRatingField.js +1 -1
  42. package/dist/components/controlled/input/ControlledSwitchField.js +1 -1
  43. package/dist/components/controlled/input/ControlledTextField.js +1 -1
  44. package/dist/components/controlled/input/ControlledTextareaField.js +1 -1
  45. package/dist/components/controlled/input/index.js +1 -1
  46. package/dist/components/controlled/select/ControlledComboboxField.js +1 -1
  47. package/dist/components/controlled/select/ControlledDropdownField.js +1 -1
  48. package/dist/components/controlled/select/ControlledMultiDropdownField.js +1 -1
  49. package/dist/components/controlled/select/ControlledRadioField.js +1 -1
  50. package/dist/components/controlled/select/ControlledYearField.js +1 -1
  51. package/dist/components/controlled/select/index.js +1 -1
  52. package/dist/components/controlled/types.js +1 -1
  53. package/dist/components/fields/display/AvatarFieldDisplay.js +1 -1
  54. package/dist/components/fields/display/BadgeFieldDisplay.js +1 -1
  55. package/dist/components/fields/display/ButtonFieldDisplay.js +1 -1
  56. package/dist/components/fields/display/CheckboxFieldDisplay.js +1 -1
  57. package/dist/components/fields/display/DateFieldDisplay.js +1 -1
  58. package/dist/components/fields/display/DropdownDisplay.js +1 -1
  59. package/dist/components/fields/display/FileFieldDisplay.js +1 -1
  60. package/dist/components/fields/display/GeoPointFieldDisplay.js +1 -1
  61. package/dist/components/fields/display/HiddenFieldDisplay.js +1 -1
  62. package/dist/components/fields/display/ImageFieldDisplay.js +1 -1
  63. package/dist/components/fields/display/LinkFieldDisplay.js +1 -1
  64. package/dist/components/fields/display/MapFieldDisplay.js +1 -1
  65. package/dist/components/fields/display/MultiDropdownDisplay.js +1 -1
  66. package/dist/components/fields/display/MultiInputTextFieldDisplay.js +1 -1
  67. package/dist/components/fields/display/NumberFieldDisplay.js +1 -1
  68. package/dist/components/fields/display/PasswordFieldDisplay.js +1 -1
  69. package/dist/components/fields/display/PhoneNumberDisplay.js +1 -1
  70. package/dist/components/fields/display/RadioFieldDisplay.js +1 -1
  71. package/dist/components/fields/display/RangeFieldDisplay.js +1 -1
  72. package/dist/components/fields/display/ReferenceFieldDisplay.js +1 -1
  73. package/dist/components/fields/display/RichTextDisplay.js +2 -2
  74. package/dist/components/fields/display/TextAreaDisplay.js +1 -1
  75. package/dist/components/fields/display/TextFieldDisplay.js +1 -1
  76. package/dist/components/fields/display/TimestampFieldDisplay.js +1 -1
  77. package/dist/components/fields/display/index.js +1 -1
  78. package/dist/components/form/fields/AddressFieldComponent.js +1 -1
  79. package/dist/components/form/fields/AvatarFieldComponent.js +1 -1
  80. package/dist/components/form/fields/BadgeFieldComponent.js +1 -1
  81. package/dist/components/form/fields/ButtonFieldComponent.js +1 -1
  82. package/dist/components/form/fields/CheckboxFieldComponent.js +1 -1
  83. package/dist/components/form/fields/ComboboxComponent.js +1 -1
  84. package/dist/components/form/fields/CurrencyFieldComponent.js +1 -1
  85. package/dist/components/form/fields/DateFieldComponent.js +1 -1
  86. package/dist/components/form/fields/DocumentFieldComponent.js +1 -1
  87. package/dist/components/form/fields/DropdownComponent.js +1 -1
  88. package/dist/components/form/fields/DurationFieldComponent.js +1 -1
  89. package/dist/components/form/fields/FileFieldComponent.js +1 -1
  90. package/dist/components/form/fields/GdprConsentFieldComponent.js +1 -1
  91. package/dist/components/form/fields/GeoPointFieldComponent.js +1 -1
  92. package/dist/components/form/fields/HiddenFieldComponent.js +1 -1
  93. package/dist/components/form/fields/ImageFieldComponent.js +1 -1
  94. package/dist/components/form/fields/MapFieldComponent.js +1 -1
  95. package/dist/components/form/fields/MultiDropdownComponent.js +1 -1
  96. package/dist/components/form/fields/MultiInputTextFieldComponent.js +1 -1
  97. package/dist/components/form/fields/NumberFieldComponent.js +1 -1
  98. package/dist/components/form/fields/PasswordFieldComponent.js +1 -1
  99. package/dist/components/form/fields/PhoneNumberComponent.d.ts.map +1 -1
  100. package/dist/components/form/fields/PhoneNumberComponent.js +1 -1
  101. package/dist/components/form/fields/PriceFieldComponent.js +1 -1
  102. package/dist/components/form/fields/RadioFieldComponent.js +1 -1
  103. package/dist/components/form/fields/RangeFieldComponent.js +1 -1
  104. package/dist/components/form/fields/RatingFieldComponent.js +1 -1
  105. package/dist/components/form/fields/ReferenceFieldComponent.js +1 -1
  106. package/dist/components/form/fields/RichTextComponent.js +1 -1
  107. package/dist/components/form/fields/SwitchFieldComponent.js +1 -1
  108. package/dist/components/form/fields/TextAreaComponent.js +1 -1
  109. package/dist/components/form/fields/TextFieldComponent.js +1 -1
  110. package/dist/components/form/fields/TimestampFieldComponent.js +1 -1
  111. package/dist/components/form/fields/index.js +1 -1
  112. package/dist/components/form/fields/internal/TiptapEditor.js +2 -2
  113. package/dist/components/form/internal/ImageViewerDialog.js +1 -1
  114. package/dist/components/index.js +1 -1
  115. package/dist/contexts/UploadContext.js +1 -1
  116. package/dist/contexts/index.js +1 -1
  117. package/dist/fieldTypeRegistry.js +1 -1
  118. package/dist/forms/hooks/index.js +1 -1
  119. package/dist/forms/hooks/useController.js +1 -1
  120. package/dist/forms/hooks/useEntityField.js +1 -1
  121. package/dist/forms/hooks/useEntityForm.d.ts.map +1 -1
  122. package/dist/forms/hooks/useEntityForm.js +1 -1
  123. package/dist/forms/index.js +1 -1
  124. package/dist/forms/types.d.ts +8 -1
  125. package/dist/forms/types.d.ts.map +1 -1
  126. package/dist/forms/utils/buildInitialValues.d.ts +30 -0
  127. package/dist/forms/utils/buildInitialValues.d.ts.map +1 -0
  128. package/dist/forms/utils/buildInitialValues.js +1 -0
  129. package/dist/forms/utils/getFieldsForOperation.js +1 -1
  130. package/dist/forms/utils/index.js +1 -1
  131. package/dist/forms/utils/isFieldEditable.js +1 -1
  132. package/dist/forms/utils/translateFieldLabel.d.ts +11 -5
  133. package/dist/forms/utils/translateFieldLabel.d.ts.map +1 -1
  134. package/dist/forms/utils/translateFieldLabel.js +1 -1
  135. package/dist/forms/utils/validateEntity.js +1 -1
  136. package/dist/hooks/index.js +1 -1
  137. package/dist/hooks/useEntityFavorites.js +1 -1
  138. package/dist/hooks/useFileUpload.js +1 -1
  139. package/dist/hooks/useFormNavigationGuard.js +1 -1
  140. package/dist/hooks/useRelatedItems.js +1 -1
  141. package/dist/hooks/useUnsavedChangesWarning.js +1 -1
  142. package/dist/index.js +1 -1
  143. package/dist/registerBuiltinFieldTypes.d.ts.map +1 -1
  144. package/dist/registerBuiltinFieldTypes.js +1 -1
  145. package/dist/stores/FormStore.js +1 -1
  146. package/dist/stores/UploadStore.js +1 -1
  147. package/dist/stores/index.js +1 -1
  148. package/dist/tsconfig.tsbuildinfo +1 -1
  149. package/dist/useBaseCrudList.js +1 -1
  150. package/dist/useCrud.js +1 -1
  151. package/dist/useCrudCardList.js +1 -1
  152. package/dist/useCrudList.js +1 -1
  153. package/dist/utils/collections.js +1 -1
  154. package/dist/utils/fileStorage.js +1 -1
  155. package/dist/utils/imageProcessing.js +1 -1
  156. package/dist/utils/imageStorage.js +1 -1
  157. package/dist/utils/imageUtils.js +1 -1
  158. package/dist/utils/mergeWithOptimistic.js +1 -1
  159. package/dist/utils/scopeUtils.js +1 -1
  160. package/dist/utils/uploadValidation.js +1 -1
  161. package/package.json +4 -4
@@ -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 l,jsxs as p}from"react/jsx-runtime";import{Upload as Y,X as Z,File as $,Loader2 as ee,FileText as D,FileSpreadsheet as re,FileImage as ae,FileVideo as le,FileAudio as se,FileArchive as te,FileCode as ie}from"lucide-react";import{useCallback as h,useState as j,useRef as F,useEffect as B,useImperativeHandle as oe,forwardRef as ne}from"react";import{Button as de,BUTTON_VARIANT as ce,Text as y,Stack as N,Progress as ue}from"@donotdev/components";import{handleError as I,useTranslation as pe}from"@donotdev/core";import{useUploadContext as me}from"../../../contexts/UploadContext";import{useUploadStore as fe}from"../../../stores/UploadStore";import{uploadFile as ge,deleteFile as ve,generateFileId as R,getFileIcon as he,formatFileSize as ye}from"../../../utils/fileStorage";function xe({type:m,className:o}){switch(m){case"pdf":return l(D,{className:o,style:{color:"var(--destructive)"}});case"doc":return l(D,{className:o,style:{color:"var(--primary)"}});case"xls":return l(re,{className:o,style:{color:"var(--success)"}});case"ppt":return l(D,{className:o,style:{color:"var(--warning)"}});case"image":return l(ae,{className:o});case"video":return l(le,{className:o});case"audio":return l(se,{className:o});case"archive":return l(te,{className:o});case"html":case"text":return l(ie,{className:o});default:return l($,{className:o})}}const H=ne(({name:m,label:o,value:f,onChange:M,error:b,helperText:U,accept:q,multiple:n=!1,maxFiles:P=10,maxSize:z=50*1024*1024,storagePath:A="uploads/files",required:K},V)=>{const{t:W}=pe("dndev"),c=W,g=me(),T=fe(),L=!!g,[t,u]=j([]),[E,S]=j(!1),v=F(null),C=F(!1),x=F(void 0),w=h(e=>{const r=e.filter(a=>a.uploaded&&!a.error).map(a=>a.uploaded);M(n?r:r[0]||null)},[n,M]);B(()=>{if(C.current){C.current=!1;return}if(f){const e=[];(Array.isArray(f)?f:[f]).forEach(r=>{r.url&&e.push({id:R(),file:new File([],r.filename),uploadProgress:null,uploaded:r,error:null})}),u(e)}else u([])},[f]);const X=h(async()=>{const e=t.filter(r=>!r.uploaded&&!r.error&&r.uploadProgress===null);if(e.length!==0){u(r=>r.map(a=>e.some(s=>s.id===a.id)?{...a,uploadProgress:0}:a));for(const r of e)try{const a=await ge(r.file,{storagePath:A,onProgress:s=>{u(d=>d.map(i=>i.id===r.id?{...i,uploadProgress:s.progress}:i))}});u(s=>{const d=s.map(i=>i.id===r.id?{...i,uploaded:a,uploadProgress:100,error:null}:i);return queueMicrotask(()=>w(d)),d})}catch{u(a=>a.map(s=>s.id===r.id?{...s,error:"Upload failed",uploadProgress:null}:s))}}},[t,A,w]);x.current=X,B(()=>{if(!(!g||!m))return T.registerUpload(g,m,async e=>{await x.current?.()}),()=>{T.unregisterUpload(g,m)}},[g,m,T]),oe(V,()=>({upload:async()=>{await x.current?.()},getFiles:()=>O.current||[]}),[]);const O=F(t);O.current=t;const k=h(e=>{const r=(n?P:1)-t.length;if(r<=0){I(new Error("Maximum files reached"),{userMessage:c("file.errors.maxFiles",{max:P}),severity:"warning",showNotification:!0});return}const a=e.slice(0,r),s=[],d=(z/(1024*1024)).toFixed(0);for(const i of a){if(i.size>z){I(new Error("File too large"),{userMessage:c("file.errors.exceedsSize",{fileName:i.name,size:d}),severity:"warning",showNotification:!0});continue}s.push({id:R(),file:i,uploadProgress:null,uploaded:null,error:null})}s.length!==0&&(u(i=>n?[...i,...s]:s),L||setTimeout(()=>x.current?.(),0))},[t,n,P,z,c,L]),_=e=>{const r=Array.from(e.target.files||[]);r.length>0&&k(r),v.current&&(v.current.value="")},G=h(e=>{e.preventDefault(),S(!1);const r=Array.from(e.dataTransfer.files);k(r)},[k]),J=h(async e=>{const r=t[e];if(r)try{r.uploaded&&await ve(r.uploaded);const a=t.filter((s,d)=>d!==e);C.current=!0,u(a),setTimeout(()=>w(a),0)}catch(a){I(a,{userMessage:c("file.delete.failed"),severity:"error",showNotification:!0})}},[t,w,c]),Q=n||t.length===0,Fe=t.some(e=>!e.uploaded&&!e.error&&e.uploadProgress===null);return p(N,{gap:"tight",children:[p(y,{level:"body",align:"start",children:[o,K?"*":""]}),Q&&p("div",{role:"button",tabIndex:0,"aria-label":c(n?"file.upload.ariaLabelMultiple":"file.upload.ariaLabelSingle"),className:"dndev-surface","data-variant":b?"destructive":"default",style:{border:"var(--border-width) dashed",borderColor:E?"var(--primary)":b?"var(--destructive)":"var(--border)",borderRadius:"var(--radius-lg)",padding:"var(--gap-lg)",backgroundColor:E?"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:G,onClick:()=>v.current?.click(),onKeyDown:e=>{(e.key==="Enter"||e.key===" ")&&(e.preventDefault(),v.current?.click())},children:[l("input",{ref:v,type:"file",accept:q,multiple:n,style:{display:"none"},onChange:_}),p(N,{align:"center",justify:"center",gap:"medium",children:[l(Y,{className:"dndev-size-lg",style:{color:"var(--muted-foreground)"}}),l(y,{as:"p",variant:"muted",level:"small",align:"center",children:c(n?"file.upload.dragDropMultiple":"file.upload.dragDropSingle")})]})]}),t.length>0&&l(N,{gap:"tight",children:t.map((e,r)=>{const a=he(e.uploaded?.mimeType||e.file.type,e.file.name),s=e.uploadProgress!==null&&e.uploadProgress<100,d=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:[l(xe,{type:a,className:"dndev-size-md"}),p(N,{gap:"none",style:{flex:1,minWidth:0},children:[l(y,{level:"small",style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.file.name}),p(y,{level:"caption",variant:"muted",children:[ye(e.uploaded?.size||e.file.size),e.error&&p("span",{style:{color:"var(--destructive)"},children:[" ","\xB7 ",e.error]})]}),s&&l(ue,{value:e.uploadProgress||0,max:100,style:{marginTop:"var(--gap-xs)"}})]}),s?l(ee,{className:"dndev-size-sm",style:{animation:"spin 1s linear infinite"}}):l(de,{variant:ce.GHOST,onClick:()=>J(r),"aria-label":c("file.delete.ariaLabel"),children:l(Z,{className:"dndev-size-sm"})})]},e.id)})}),U&&l(y,{level:"caption",variant:b?"destructive":"muted",style:{marginTop:"var(--gap-xs)"},children:U})]})});H.displayName="FileFieldComponent";var we=H;export{we as default};
@@ -1 +1 @@
1
- import{jsx as t,jsxs as o,Fragment as w}from"react/jsx-runtime";import{useState as m}from"react";import{Checkbox as T,Label as O,Sheet as g,Stack as D,Text as j}from"@donotdev/components";import{useTranslation as H}from"@donotdev/core";const V=({checked:l=!1,onChange:s,required:u,privacyPolicyPath:a="/legal/privacy",termsPath:c="/legal/terms"})=>{const{t:n}=H("crud"),[x,d]=m(!1),[y,h]=m(!1),p=e=>{s&&s({target:{checked:e}})},C=e=>{e.target.tagName!=="A"&&(e.target.closest('[data-type="checkbox"]')||p(!l))},f=(e,b)=>{e.preventDefault(),b==="privacy"?d(!0):h(!0)},v=n("gdprConsent.consent",{defaultValue:"I agree to the"}),r=n("gdprConsent.privacyPolicy",{defaultValue:"privacy policy"}),i=n("gdprConsent.terms",{defaultValue:"terms of use"}),k=n("gdprConsent.and",{defaultValue:"and consent to the processing of my personal data."});return o(w,{children:[o(D,{direction:"row",align:"center",gap:"tight",children:[t(T,{checked:l,onCheckedChange:p}),t(O,{required:u,plain:!0,onClick:C,style:{cursor:"pointer"},children:o(j,{level:"small",children:[v," ",t("a",{href:a,onClick:e=>f(e,"privacy"),style:{textDecoration:"underline",cursor:"pointer"},children:r})," / ",t("a",{href:c,onClick:e=>f(e,"terms"),style:{textDecoration:"underline",cursor:"pointer"},children:i})," ",k]})})]}),t(g,{open:x,onOpenChange:d,side:"bottom",title:r,style:{width:"100%",height:"90%",maxHeight:"90dvh",display:"flex",flexDirection:"column",overflow:"hidden"},children:t("iframe",{src:a,style:{width:"100%",height:"100%",border:"none",flex:1,minHeight:0},title:r})}),t(g,{open:y,onOpenChange:h,side:"bottom",title:i,style:{width:"100%",height:"90%",maxHeight:"90dvh",display:"flex",flexDirection:"column",overflow:"hidden"},children:t("iframe",{src:c,style:{width:"100%",height:"100%",border:"none",flex:1,minHeight:0},title:i})})]})};var q=V;export{q as default};
1
+ import{jsx as t,jsxs as a,Fragment as b}from"react/jsx-runtime";import{useState as m}from"react";import{Checkbox as D,Label as H,Sheet as f,Stack as V,Text as P}from"@donotdev/components";import{useTranslation as j}from"@donotdev/core";const q=({checked:o=!1,onChange:l,required:u,privacyPolicyPath:s="/legal/privacy",termsPath:c="/legal/terms"})=>{const{t:r}=j("crud"),[y,d]=m(!1),[x,h]=m(!1),p=e=>{l&&l({target:{checked:e}})},v=e=>{e.target.tagName!=="A"&&(e.target.closest('[data-type="checkbox"]')||p(!o))},g=(e,w)=>{e.preventDefault(),w==="privacy"?d(!0):h(!0)},C=r("gdprConsent.consent",{defaultValue:"I agree to the"}),n=r("gdprConsent.privacyPolicy",{defaultValue:"privacy policy"}),i=r("gdprConsent.terms",{defaultValue:"terms of use"}),k=r("gdprConsent.and",{defaultValue:"and consent to the processing of my personal data."});return a(b,{children:[a(V,{direction:"row",align:"center",gap:"tight",children:[t(D,{checked:o,onCheckedChange:p}),t(H,{required:u,plain:!0,onClick:v,style:{cursor:"pointer"},children:a(P,{level:"small",children:[C," ",t("a",{href:s,onClick:e=>g(e,"privacy"),style:{textDecoration:"underline",cursor:"pointer"},children:n})," / ",t("a",{href:c,onClick:e=>g(e,"terms"),style:{textDecoration:"underline",cursor:"pointer"},children:i})," ",k]})})]}),t(f,{open:y,onOpenChange:d,side:"bottom",title:n,style:{width:"100%",height:"90%",maxHeight:"90dvh",display:"flex",flexDirection:"column",overflow:"hidden"},children:t("iframe",{src:s,style:{width:"100%",height:"100%",border:"none",flex:1,minHeight:0},title:n})}),t(f,{open:x,onOpenChange:h,side:"bottom",title:i,style:{width:"100%",height:"90%",maxHeight:"90dvh",display:"flex",flexDirection:"column",overflow:"hidden"},children:t("iframe",{src:c,style:{width:"100%",height:"100%",border:"none",flex:1,minHeight:0},title:i})})]})};var O=q;export{O 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 t,jsxs as u}from"react/jsx-runtime";import{Label as h,Input as v,Stack as g}from"@donotdev/components";const b=({label:c,value:a={lat:0,lng:0},onChange:i,error:r,helperText:o,disabled:d,required:m})=>{const p=n=>{const e=parseFloat(n.target.value)||0;if(e>=-90&&e<=90){const l={...a,lat:e},s={target:{value:JSON.stringify(l)}};i(s)}},f=n=>{const e=parseFloat(n.target.value)||0;if(e>=-180&&e<=180){const l={...a,lng:e},s={target:{value:JSON.stringify(l)}};i(s)}};return u(g,{gap:"tight",children:[t(h,{required:m,style:{display:"block",fontSize:"var(--font-size-sm)",fontWeight:500},children:c}),u(g,{direction:"row",gap:"medium",children:[t(v,{label:"Latitude",type:"number",value:a.lat,onChange:p,min:"-90",max:"90",step:"0.000001",disabled:d,"data-variant":r?"destructive":void 0,className:"dndev-w-full"}),t(v,{label:"Longitude",type:"number",value:a.lng,onChange:f,min:"-180",max:"180",step:"0.000001",disabled:d,"data-variant":r?"destructive":void 0,className:"dndev-w-full"})]}),o&&t("p",{style:{fontSize:"var(--font-size-xs)",color:r?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:o})]})};var y=b;export{y as default};
@@ -1 +1 @@
1
- import{jsx as t}from"react/jsx-runtime";const d=({name:e,value:n})=>t("input",{type:"hidden",name:e,value:n});var i=d;export{i as default};
1
+ import{jsx as t}from"react/jsx-runtime";const n=({name:a,value:e})=>t("input",{type:"hidden",name:a,value:e});var d=n;export{d as default};
@@ -1 +1 @@
1
- "use client";import{jsx as r,jsxs as l,Fragment as q}from"react/jsx-runtime";import{DndContext as J,closestCenter as Q,PointerSensor as Z,TouchSensor as ee,useSensor as j,useSensors as re}from"@dnd-kit/core";import{SortableContext as te,useSortable as oe,rectSortingStrategy as ne,arrayMove as ie}from"@dnd-kit/sortable";import{CSS as ae}from"@dnd-kit/utilities";import{Upload as se,X as A,Loader2 as le,GripVertical as de}from"lucide-react";import{forwardRef as ce,useCallback as V,useImperativeHandle as pe,useRef as ue,useState as L}from"react";import{Text as h,Stack as C,Progress as ge}from"@donotdev/components";import{useTranslation as me}from"@donotdev/core";import{useFileUpload as he}from"../../../hooks/useFileUpload";import{processImage as ve}from"../../../utils/imageProcessing";import{uploadImage as fe}from"../../../utils/imageStorage";import{ImageViewerDialog as be}from"../internal/ImageViewerDialog";const ye=["image/*"];function we(t){return{id:t.id,file:t.file,previewURL:t.previewURL,hash:"",rotation:0,uploadProgress:t.progress,uploaded:t.uploaded,error:t.error}}function xe({file:t,index:v,multiple:f,onImageClick:d,onRemove:b,t:u}){const{attributes:n,listeners:D,setNodeRef:S,transform:g,transition:R,isDragging:y}=oe({id:t.id}),w=t.progress!==null&&t.progress<100,s=f&&!w,a={transform:ae.Transform.toString(g),transition:R,position:"relative",width:100,height:100,borderRadius:"var(--radius-md)",border:"var(--border-width) solid var(--border)",overflow:"hidden",backgroundColor:"var(--surface)",opacity:y?.5:1,cursor:s?"grab":"pointer",userSelect:"none",touchAction:s?"none":"auto"};return r("div",{ref:S,style:a,...n,...s?D:{},onClick:()=>{y||d(v)},children:w?l(C,{align:"center",justify:"center",style:{width:"100%",height:"100%"},children:[r(le,{style:{animation:"spin 1s linear infinite"}}),r(ge,{value:t.progress||0,style:{width:"80%"}})]}):t.error?l(C,{align:"center",justify:"center",style:{width:"100%",height:"100%"},children:[r(A,{style:{color:"var(--destructive)"}}),r(h,{variant:"destructive",level:"small",children:t.error})]}):l(q,{children:[f&&r("div",{style:{position:"absolute",top:4,left:4,padding:2,background:"rgba(0,0,0,0.5)",borderRadius:"var(--radius-sm)",display:"flex",zIndex:2,pointerEvents:"none"},children:r(de,{style:{color:"white",width:14,height:14}})}),r("img",{src:t.previewURL,alt:u("image.alt.upload",{index:v+1}),draggable:!1,style:{width:"100%",height:"100%",objectFit:"cover",pointerEvents:"none",userSelect:"none"}}),r("button",{type:"button",onClick:c=>{c.stopPropagation(),b(t.id)},onPointerDown:c=>c.stopPropagation(),style:{position:"absolute",top:4,right:4,padding:4,background:"rgba(0,0,0,0.5)",border:"none",borderRadius:"var(--radius-sm)",cursor:"pointer",display:"flex",zIndex:2},children:r(A,{style:{color:"white",width:16,height:16}})}),!t.uploaded&&r("div",{style:{position:"absolute",bottom:0,left:0,right:0,padding:4,background:"rgba(0,0,0,0.7)",textAlign:"center",pointerEvents:"none"},children:r(h,{variant:"muted",level:"small",style:{color:"white"},children:u("image.upload.pending",{defaultValue:"Pending"})})})]})})}const z=ce(({name:t="image",label:v,value:f,onChange:d,error:b,helperText:u,multiple:n=!1,maxFiles:D=10,maxSize:S=10*1024*1024,storagePath:g="uploads/images",required:R,capture:y},w)=>{const{t:s}=me("crud"),a=ue(null),[E,c]=L(!1),[_,P]=L(0),M=re(j(Z,{activationConstraint:{distance:8}}),j(ee,{activationConstraint:{delay:200,tolerance:5}})),N=V(async(e,o)=>{const{fullBlob:m,thumbBlob:x}=await ve(e);return fe(m,x,e.name,{storagePath:g,onProgress:I=>o(I.progress)})},[g]),{files:i,addFiles:F,removeFile:T}=he({name:t,value:f,onChange:d,multiple:n,maxFiles:D,maxSize:S,accept:ye,storagePath:g,uploadFn:N}),O=e=>{const o=Array.from(e.target.files||[]);o.length>0&&F(o),a.current&&(a.current.value="")},B=V(e=>{e.preventDefault(),e.stopPropagation(),e.dataTransfer.files.length>0&&F(Array.from(e.dataTransfer.files))},[F]),G=V(e=>{const{active:o,over:m}=e;if(m&&o.id!==m.id){const x=i.findIndex(k=>k.id===o.id),I=i.findIndex(k=>k.id===m.id);if(x!==-1&&I!==-1){const U=ie(i,x,I).filter(p=>p.uploaded||p.previewURL).map(p=>p.uploaded||{fullUrl:p.previewURL,thumbUrl:p.previewURL});d(n?U.length>0?U:null:U[0]||null)}}},[i,n,d]),H=e=>{P(e),c(!0)},K=(e,o)=>{},W=e=>{const o=i[e];o&&T(o.id)},X=e=>{P(e)},Y=n||i.length===0;pe(w,()=>({upload:async()=>{},focus:()=>a.current?.focus()}),[]);const $=i.map(we);return l(C,{gap:"tight",children:[l(h,{level:"body",align:"start",children:[v,R&&"*"]}),Y&&l("div",{role:"button",tabIndex:0,onClick:()=>a.current?.click(),onKeyDown:e=>{(e.key==="Enter"||e.key===" ")&&a.current?.click()},onDragOver:e=>e.preventDefault(),onDrop:B,style:{border:`var(--border-width) dashed ${b?"var(--destructive)":"var(--border)"}`,borderRadius:"var(--radius-lg)",padding:"var(--gap-lg)",backgroundColor:"var(--surface)",cursor:"pointer",textAlign:"center"},children:[r("input",{ref:a,type:"file",accept:"image/*",capture:y,multiple:n,style:{display:"none"},onChange:O}),l(C,{align:"center",gap:"medium",children:[r(se,{style:{color:"var(--muted-foreground)"}}),r(h,{variant:"muted",level:"small",children:n?s("image.upload.dropzoneMultiple",{defaultValue:"Drop images here or click to upload"}):s("image.upload.dropzoneSingle",{defaultValue:"Drop image here or click to upload"})})]})]}),i.length>0&&r(J,{sensors:M,collisionDetection:Q,onDragEnd:G,children:r(te,{items:i.map(e=>e.id),strategy:ne,children:r("div",{style:{display:"flex",flexWrap:"wrap",gap:"var(--gap-md)"},children:i.map((e,o)=>r(xe,{file:e,index:o,multiple:n,onImageClick:H,onRemove:T,t:s},e.id))})})}),u&&r(h,{variant:b?"destructive":"muted",level:"small",children:u}),r(be,{images:$,selectedIndex:_,open:E,onClose:()=>c(!1),onUpdate:K,onDelete:W,onNavigate:X,multiple:n})]})});z.displayName="ImageFieldComponent";var je=z;export{je as default};
1
+ "use client";import{jsx as r,jsxs as d,Fragment as J}from"react/jsx-runtime";import{DndContext as Q,closestCenter as Y,PointerSensor as Z,TouchSensor as _,useSensor as j,useSensors as ee}from"@dnd-kit/core";import{SortableContext as re,useSortable as ae,rectSortingStrategy as oe,arrayMove as te}from"@dnd-kit/sortable";import{CSS as ie}from"@dnd-kit/utilities";import{Upload as ne,X as z,Loader2 as le,GripVertical as se}from"lucide-react";import{forwardRef as de,useCallback as U,useImperativeHandle as ue,useRef as ce,useState as A}from"react";import{Text as f,Stack as k,Progress as pe}from"@donotdev/components";import{useTranslation as ge}from"@donotdev/core";import{useFileUpload as me}from"../../../hooks/useFileUpload";import{processImage as he}from"../../../utils/imageProcessing";import{uploadImage as fe}from"../../../utils/imageStorage";import{ImageViewerDialog as ve}from"../internal/ImageViewerDialog";const ye=["image/*"];function be(a){return{id:a.id,file:a.file,previewURL:a.previewURL,hash:"",rotation:0,uploadProgress:a.progress,uploaded:a.uploaded,error:a.error}}function xe({file:a,index:v,multiple:y,onImageClick:c,onRemove:b,t:p}){const{attributes:t,listeners:R,setNodeRef:D,transform:g,transition:I,isDragging:x}=ae({id:a.id}),w=a.progress!==null&&a.progress<100,l=y&&!w,n={transform:ie.Transform.toString(g),transition:I,position:"relative",width:100,height:100,borderRadius:"var(--radius-md)",border:"var(--border-width) solid var(--border)",overflow:"hidden",backgroundColor:"var(--surface)",opacity:x?.5:1,cursor:l?"grab":"pointer",userSelect:"none",touchAction:l?"none":"auto"};return r("div",{ref:D,style:n,...t,...l?R:{},onClick:()=>{x||c(v)},children:w?d(k,{align:"center",justify:"center",style:{width:"100%",height:"100%"},children:[r(le,{style:{animation:"spin 1s linear infinite"}}),r(pe,{value:a.progress||0,style:{width:"80%"}})]}):a.error?d(k,{align:"center",justify:"center",style:{width:"100%",height:"100%"},children:[r(z,{style:{color:"var(--destructive)"}}),r(f,{variant:"destructive",level:"small",children:a.error})]}):d(J,{children:[y&&r("div",{style:{position:"absolute",top:4,left:4,padding:2,background:"rgba(0,0,0,0.5)",borderRadius:"var(--radius-sm)",display:"flex",zIndex:2,pointerEvents:"none"},children:r(se,{style:{color:"white",width:14,height:14}})}),r("img",{src:a.previewURL,alt:p("image.alt.upload",{index:v+1}),draggable:!1,style:{width:"100%",height:"100%",objectFit:"cover",pointerEvents:"none",userSelect:"none"}}),r("button",{type:"button",onClick:m=>{m.stopPropagation(),b(a.id)},onPointerDown:m=>m.stopPropagation(),style:{position:"absolute",top:4,right:4,padding:4,background:"rgba(0,0,0,0.5)",border:"none",borderRadius:"var(--radius-sm)",cursor:"pointer",display:"flex",zIndex:2},children:r(z,{style:{color:"white",width:16,height:16}})}),!a.uploaded&&r("div",{style:{position:"absolute",bottom:0,left:0,right:0,padding:4,background:"rgba(0,0,0,0.7)",textAlign:"center",pointerEvents:"none"},children:r(f,{variant:"muted",level:"small",style:{color:"white"},children:p("image.upload.pending",{defaultValue:"Pending"})})})]})})}const E=de(({name:a="image",label:v,value:y,onChange:c,error:b,helperText:p,multiple:t=!1,maxFiles:R=10,maxSize:D=10*1024*1024,storagePath:g="uploads/images",required:I,capture:x},w)=>{const{t:l}=ge("crud"),n=ce(null),[m,F]=A(!1),[V,L]=A(0),N=ee(j(Z,{activationConstraint:{distance:8}}),j(_,{activationConstraint:{delay:200,tolerance:5}})),B=U(async(e,o)=>{const{fullBlob:h,thumbBlob:C}=await he(e);return fe(h,C,e.name,{storagePath:g,onProgress:S=>o(S.progress)})},[g]),{files:i,addFiles:P,removeFile:T}=me({name:a,value:y,onChange:c,multiple:t,maxFiles:R,maxSize:D,accept:ye,storagePath:g,uploadFn:B}),M=e=>{const o=Array.from(e.target.files||[]);o.length>0&&P(o),n.current&&(n.current.value="")},q=U(e=>{e.preventDefault(),e.stopPropagation(),e.dataTransfer.files.length>0&&P(Array.from(e.dataTransfer.files))},[P]),G=U(e=>{const{active:o,over:h}=e;if(h&&o.id!==h.id){const C=i.findIndex(s=>s.id===o.id),S=i.findIndex(s=>s.id===h.id);if(C!==-1&&S!==-1){const s=te(i,C,S).filter(u=>u.uploaded||u.previewURL).map(u=>u.uploaded||{fullUrl:u.previewURL,thumbUrl:u.previewURL});c(t?s.length>0?s:null:s[0]||null)}}},[i,t,c]),H=e=>{L(e),F(!0)},K=(e,o)=>{},O=e=>{const o=i[e];o&&T(o.id)},W=e=>{L(e)},X=t||i.length===0;ue(w,()=>({upload:async()=>{},focus:()=>n.current?.focus()}),[]);const $=i.map(be);return d(k,{gap:"tight",children:[d(f,{level:"body",align:"start",children:[v,I&&"*"]}),X&&d("div",{role:"button",tabIndex:0,onClick:()=>n.current?.click(),onKeyDown:e=>{(e.key==="Enter"||e.key===" ")&&n.current?.click()},onDragOver:e=>e.preventDefault(),onDrop:q,style:{border:`var(--border-width) dashed ${b?"var(--destructive)":"var(--border)"}`,borderRadius:"var(--radius-lg)",padding:"var(--gap-lg)",backgroundColor:"var(--surface)",cursor:"pointer",textAlign:"center"},children:[r("input",{ref:n,type:"file",accept:"image/*",capture:x,multiple:t,style:{display:"none"},onChange:M}),d(k,{align:"center",gap:"medium",children:[r(ne,{style:{color:"var(--muted-foreground)"}}),r(f,{variant:"muted",level:"small",children:t?l("image.upload.dropzoneMultiple",{defaultValue:"Drop images here or click to upload"}):l("image.upload.dropzoneSingle",{defaultValue:"Drop image here or click to upload"})})]})]}),i.length>0&&r(Q,{sensors:N,collisionDetection:Y,onDragEnd:G,children:r(re,{items:i.map(e=>e.id),strategy:oe,children:r("div",{style:{display:"flex",flexWrap:"wrap",gap:"var(--gap-md)"},children:i.map((e,o)=>r(xe,{file:e,index:o,multiple:t,onImageClick:H,onRemove:T,t:l},e.id))})})}),p&&r(f,{variant:b?"destructive":"muted",level:"small",children:p}),r(ve,{images:$,selectedIndex:V,open:m,onClose:()=>F(!1),onUpdate:K,onDelete:O,onNavigate:W,multiple:t})]})});E.displayName="ImageFieldComponent";var we=E;export{we as default};
@@ -1 +1 @@
1
- import{jsx as e,jsxs as n}from"react/jsx-runtime";import{Input as p,Stack as u}from"@donotdev/components";import{useTranslation as m}from"@donotdev/core";const f=({label:s,value:d={},onChange:a,error:t,helperText:r,required:i})=>{const{t:l}=m("dndev");return n(u,{gap:"tight",children:[n("div",{className:"dndev-surface","data-variant":t?"destructive":"default",style:{border:"1px solid",borderColor:t?"var(--destructive)":"var(--input)",borderRadius:"var(--radius-lg)",padding:"var(--gap-md)"},children:[e("p",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)",marginBottom:"var(--gap-md)"},children:"Map component placeholder"}),e(p,{label:s,type:"text",required:i,className:"dndev-w-full",placeholder:l("form.enterLocationData","Enter location data (JSON)"),value:JSON.stringify(d),onChange:c=>{try{const o=JSON.parse(c.target.value),v={target:{value:JSON.stringify(o)}};a(v)}catch{a({target:{value:"{}"}})}}})]}),r&&e("p",{style:{fontSize:"var(--font-size-xs)",color:t?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:r})]})};var x=f;export{x as default};
1
+ import{jsx as r,jsxs as o}from"react/jsx-runtime";import{Input as c,Stack as p}from"@donotdev/components";import{useTranslation as m}from"@donotdev/core";const g=({label:n,value:d={},onChange:a,error:e,helperText:t,required:s})=>{const{t:l}=m("dndev");return o(p,{gap:"tight",children:[o("div",{className:"dndev-surface","data-variant":e?"destructive":"default",style:{border:"1px solid",borderColor:e?"var(--destructive)":"var(--input)",borderRadius:"var(--radius-lg)",padding:"var(--gap-md)"},children:[r("p",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)",marginBottom:"var(--gap-md)"},children:"Map component placeholder"}),r(c,{label:n,type:"text",required:s,className:"dndev-w-full",placeholder:l("form.enterLocationData","Enter location data (JSON)"),value:JSON.stringify(d),onChange:i=>{try{const u=JSON.parse(i.target.value),v={target:{value:JSON.stringify(u)}};a(v)}catch{a({target:{value:"{}"}})}}})]}),t&&r("p",{style:{fontSize:"var(--font-size-xs)",color:e?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:t})]})};var f=g;export{f as default};
@@ -1 +1 @@
1
- import{jsx as t,jsxs as c}from"react/jsx-runtime";import{X as C}from"lucide-react";import{useMemo as z,useId as E}from"react";import{Combobox as I,Badge as V,BADGE_VARIANT as j,Button as w,BUTTON_VARIANT as B,Stack as d}from"@donotdev/components";import{useTranslation as R}from"@donotdev/core";const T=({label:g,value:o=[],options:s,error:h,helperText:a,onChange:u,onBlur:f,required:v,className:y})=>{const{t:m}=R("dndev"),p=E(),b=z(()=>s.map(e=>({value:String(e.value),label:e.label})),[s]),N=e=>{const n=Array.isArray(e)?e:[e],r={target:{value:JSON.stringify(n)}};u(r)},S=e=>{e||f?.()},A=e=>{const n=o.filter(l=>l!==e),r={target:{value:JSON.stringify(n)}};u(r)},i=!!h,O=`${p}-error`,x=`${p}-helper`;return c(d,{gap:"tight",className:y,children:[o.length>0&&t(d,{direction:"row",wrap:"wrap",gap:"medium",children:o.map((e,n)=>{const r=s.find(l=>String(l.value)===e)?.label||e;return c(V,{variant:j.SECONDARY,className:"dndev-gap-sm",children:[r,t(w,{type:"button",variant:B.GHOST,style:{padding:0,height:"auto"},onClick:()=>A(e),children:t(C,{className:"dndev-size-md"})})]},n)})}),t(I,{label:g,value:o,onValueChange:N,onOpenChange:S,placeholder:m("actions.selectOptions","Select options..."),emptyMessage:m("messages.noResults","No results found"),options:b,multiple:!0,required:v,variant:i?"destructive":void 0}),i&&c(d,{id:O,direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)",color:"var(--destructive-foreground)"},role:"alert",children:[t("span",{children:"\u26A0"}),a]}),a&&!i&&t("p",{id:x,style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:a})]})};var $=T;export{$ as default};
1
+ import{jsx as r,jsxs as d}from"react/jsx-runtime";import{X as T}from"lucide-react";import{useMemo as C,useId as z}from"react";import{Combobox as B,Badge as w,BADGE_VARIANT as R,Button as I,BUTTON_VARIANT as V,Stack as c}from"@donotdev/components";import{useTranslation as j}from"@donotdev/core";const E=({label:g,value:s=[],options:n,error:v,helperText:o,onChange:u,onBlur:h,required:f,className:N})=>{const{t:p}=j("dndev"),m=z(),S=C(()=>n.map(e=>({value:String(e.value),label:e.label})),[n]),A=e=>{const a=Array.isArray(e)?e:[e],t={target:{value:JSON.stringify(a)}};u(t)},b=e=>{e||h?.()},y=e=>{const a=s.filter(l=>l!==e),t={target:{value:JSON.stringify(a)}};u(t)},i=!!v,x=`${m}-error`,O=`${m}-helper`;return d(c,{gap:"tight",className:N,children:[s.length>0&&r(c,{direction:"row",wrap:"wrap",gap:"medium",children:s.map((e,a)=>{const t=n.find(l=>String(l.value)===e)?.label||e;return d(w,{variant:R.SECONDARY,className:"dndev-gap-sm",children:[t,r(I,{type:"button",variant:V.GHOST,style:{padding:0,height:"auto"},onClick:()=>y(e),children:r(T,{className:"dndev-size-md"})})]},a)})}),r(B,{label:g,value:s,onValueChange:A,onOpenChange:b,placeholder:p("actions.selectOptions","Select options..."),emptyMessage:p("messages.noResults","No results found"),options:S,multiple:!0,required:f,variant:i?"destructive":void 0}),i&&d(c,{id:x,direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)",color:"var(--destructive-foreground)"},role:"alert",children:[r("span",{children:"\u26A0"}),o]}),o&&!i&&r("p",{id:O,style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:o})]})};var $=E;export{$ as default};
@@ -1 +1 @@
1
- "use client";import{jsx as a,jsxs as d}from"react/jsx-runtime";import{useState as y}from"react";import{Input as h,Button as x,Stack as i}from"@donotdev/components";import{useTranslation as b}from"@donotdev/core";const w=({label:m,value:o=[],onChange:l,className:c,required:p})=>{const{t:s}=b("dndev"),[n,u]=y(""),g=()=>{if(n.trim()){const e=[...o,n.trim()],t={target:{value:JSON.stringify(e)}};l(t),u("")}},f=e=>{const t=o.filter((S,v)=>v!==e),r={target:{value:JSON.stringify(t)}};l(r)};return d(i,{gap:"medium",className:c,children:[d(i,{direction:"row",align:"end",gap:"medium",children:[a(h,{label:m,type:"text",value:n,onChange:e=>u(e.target.value),required:p,className:"dndev-flex-1",placeholder:s("form.typeAndPressAdd","Type and press Add...")}),a(x,{type:"button",onClick:g,disabled:!n.trim(),children:s("form.add","Add")})]}),a(i,{direction:"row",wrap:"wrap",gap:"medium",children:o.map((e,t)=>d("span",{className:"dndev-surface","data-variant":"muted",style:{display:"inline-flex",alignItems:"center",gap:"var(--gap-sm)",padding:"var(--gap-sm) var(--gap-md)",fontSize:"var(--font-size-sm)",fontWeight:500,borderRadius:"var(--radius-lg)"},children:[e,a("button",{type:"button",onClick:()=>f(t),style:{color:"var(--muted-foreground)",marginInlineStart:"var(--gap-sm)"},onMouseEnter:r=>{r.currentTarget.style.color="var(--foreground)"},onMouseLeave:r=>{r.currentTarget.style.color="var(--muted-foreground)"},"aria-label":`${s("form.remove","Remove")} ${e}`,children:"\xD7"})]},t))})]})};var j=w;export{j as default};
1
+ "use client";import{jsx as n,jsxs as d}from"react/jsx-runtime";import{useState as y}from"react";import{Input as h,Button as b,Stack as i}from"@donotdev/components";import{useTranslation as x}from"@donotdev/core";const S=({label:u,value:s=[],onChange:l,className:c,required:g})=>{const{t:o}=x("dndev"),[t,m]=y(""),p=()=>{if(t.trim()){const e=[...s,t.trim()],r={target:{value:JSON.stringify(e)}};l(r),m("")}},f=e=>{const r=s.filter((w,v)=>v!==e),a={target:{value:JSON.stringify(r)}};l(a)};return d(i,{gap:"medium",className:c,children:[d(i,{direction:"row",align:"end",gap:"medium",children:[n(h,{label:u,type:"text",value:t,onChange:e=>m(e.target.value),required:g,className:"dndev-flex-1",placeholder:o("form.typeAndPressAdd","Type and press Add...")}),n(b,{type:"button",onClick:p,disabled:!t.trim(),children:o("form.add","Add")})]}),n(i,{direction:"row",wrap:"wrap",gap:"medium",children:s.map((e,r)=>d("span",{className:"dndev-surface","data-variant":"muted",style:{display:"inline-flex",alignItems:"center",gap:"var(--gap-sm)",padding:"var(--gap-sm) var(--gap-md)",fontSize:"var(--font-size-sm)",fontWeight:500,borderRadius:"var(--radius-lg)"},children:[e,n("button",{type:"button",onClick:()=>f(r),style:{color:"var(--muted-foreground)",marginInlineStart:"var(--gap-sm)"},onMouseEnter:a=>{a.currentTarget.style.color="var(--foreground)"},onMouseLeave:a=>{a.currentTarget.style.color="var(--muted-foreground)"},"aria-label":`${o("form.remove","Remove")} ${e}`,children:"\xD7"})]},r))})]})};var N=S;export{N as default};
@@ -1 +1 @@
1
- import{jsx as g,jsxs as z}from"react/jsx-runtime";import{useState as C,useEffect as E,useCallback as y}from"react";import{Input as I,cn as M,Stack as T}from"@donotdev/components";import{useTranslation as _}from"@donotdev/core";const q=({label:S,value:u,onChange:i,error:d,helperText:m,min:b,max:x,step:N,disabled:l,required:F,className:V,mask:r="number",...h})=>{const{i18n:j}=_(),a=j?.language||(typeof navigator<"u"?navigator.language:"en-US"),s=y(e=>e==null||isNaN(e)?"":r==="currency"?e.toLocaleString(a,{minimumFractionDigits:2,maximumFractionDigits:2}):r==="mileage"?Math.round(e).toLocaleString(a):e.toString(),[r,a]),v=y(e=>{if(!e||e.trim()==="")return null;const t=new Intl.NumberFormat(a).formatToParts(1234.56),D=t.find(c=>c.type==="group")?.value||",",L=t.find(c=>c.type==="decimal")?.value||".";let o=e.replace(new RegExp(`\\${D}`,"g"),"");o=o.replace(L,"."),o=o.replace(/[^\d.\-]/g,"");const p=parseFloat(o);return isNaN(p)?null:p},[a]),[w,f]=C(()=>s(u));return E(()=>{f(s(u))},[u,s]),z(T,{gap:"tight",children:[g(I,{type:r==="number"?"number":"text",inputMode:r==="number"?void 0:"decimal",label:S,value:w,onChange:e=>{const n=e.target.value;if(f(n),r==="number"){const t=parseFloat(n);isNaN(t)?i(e):i({...e,target:{...e.target,value:t.toString()}})}else{const t=v(n);t!==null?i({...e,target:{...e.target,value:t.toString()}}):n===""&&i({...e,target:{...e.target,value:""}})}},min:b,max:x,step:N,disabled:l,required:F,className:M("dndev-w-full",V),"data-variant":d?"destructive":void 0,style:{opacity:l?"var(--opacity-muted)":void 0,cursor:l?"not-allowed":void 0},...h}),m&&g("p",{style:{fontSize:"var(--font-size-xs)",color:d?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:m})]})};var G=q;export{G as default};
1
+ import{jsx as v,jsxs as k}from"react/jsx-runtime";import{useState as q,useEffect as z,useCallback as f}from"react";import{Input as D,cn as E,Stack as I}from"@donotdev/components";import{useTranslation as L}from"@donotdev/core";const M=({label:b,value:s,onChange:i,error:g,helperText:c,min:x,max:y,step:N,disabled:l,required:S,className:h,mask:r="number",...w})=>{const{i18n:F}=L(),n=F?.language||(typeof navigator<"u"?navigator.language:"en-US"),u=f(a=>a==null||isNaN(a)?"":r==="currency"?a.toLocaleString(n,{minimumFractionDigits:2,maximumFractionDigits:2}):r==="mileage"?Math.round(a).toLocaleString(n):a.toString(),[r,n]),T=f(a=>{if(!a||a.trim()==="")return null;const t=new Intl.NumberFormat(n).formatToParts(1234.56),e=t.find(m=>m.type==="group")?.value||",",j=t.find(m=>m.type==="decimal")?.value||".";let o=a.replace(new RegExp(`\\${e}`,"g"),"");o=o.replace(j,"."),o=o.replace(/[^\d.\-]/g,"");const p=parseFloat(o);return isNaN(p)?null:p},[n]),[C,d]=q(()=>u(s));return z(()=>{d(u(s))},[s,u]),k(I,{gap:"tight",children:[v(D,{type:r==="number"?"number":"text",inputMode:r==="number"?void 0:"decimal",label:b,value:C,onChange:a=>{const t=a.target.value;if(d(t),r==="number"){const e=parseFloat(t);isNaN(e)?i(a):i({...a,target:{...a.target,value:e.toString()}})}else{const e=T(t);e!==null?i({...a,target:{...a.target,value:e.toString()}}):t===""&&i({...a,target:{...a.target,value:""}})}},min:x,max:y,step:N,disabled:l,required:S,className:E("dndev-w-full",h),"data-variant":g?"destructive":void 0,style:{opacity:l?"var(--opacity-muted)":void 0,cursor:l?"not-allowed":void 0},...w}),c&&v("p",{style:{fontSize:"var(--font-size-xs)",color:g?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:c})]})};var G=M;export{G as default};
@@ -1 +1 @@
1
- "use client";import{jsx as o,jsxs as i}from"react/jsx-runtime";import{useId as l}from"react";import{PasswordInput as u,Stack as m}from"@donotdev/components";const c=({label:s,value:a,onChange:t,error:n,helperText:r,...e})=>{const d=l();return i(m,{gap:"tight",children:[o(u,{id:d,value:a??"",onChange:t,label:s,className:"dndev-w-full",required:e.required,...e}),r&&o("p",{style:{fontSize:"var(--font-size-xs)",color:n?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:r})]})};var j=c;export{j as default};
1
+ "use client";import{jsx as a,jsxs as d}from"react/jsx-runtime";import{useId as i}from"react";import{PasswordInput as u,Stack as m}from"@donotdev/components";const c=({label:o,value:s,onChange:t,error:l,helperText:e,...r})=>{const n=i();return d(m,{gap:"tight",children:[a(u,{id:n,value:s??"",onChange:t,label:o,className:"dndev-w-full",required:r.required,...r}),e&&a("p",{style:{fontSize:"var(--font-size-xs)",color:l?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:e})]})};var p=c;export{p as default};
@@ -1 +1 @@
1
- {"version":3,"file":"PhoneNumberComponent.d.ts","sourceRoot":"","sources":["../../../../src/components/form/fields/PhoneNumberComponent.tsx"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAExD,MAAM,WAAW,yBAAyB;IACxC,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,iEAAiE;IACjE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qBAAqB;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IACzD,oBAAoB;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kBAAkB;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gDAAgD;IAChD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oCAAoC;IACpC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,4EAA4E;IAC5E,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;;;;GAMG;AACH,QAAA,MAAM,oBAAoB,EAAE,aAAa,CAAC,yBAAyB,CAiOlE,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"PhoneNumberComponent.d.ts","sourceRoot":"","sources":["../../../../src/components/form/fields/PhoneNumberComponent.tsx"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAExD,MAAM,WAAW,yBAAyB;IACxC,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,iEAAiE;IACjE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qBAAqB;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IACzD,oBAAoB;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kBAAkB;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gDAAgD;IAChD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oCAAoC;IACpC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,4EAA4E;IAC5E,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,yFAAyF;IACzF,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;;;;GAMG;AACH,QAAA,MAAM,oBAAoB,EAAE,aAAa,CAAC,yBAAyB,CAiQlE,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
@@ -1 +1 @@
1
- "use client";import{jsx as t,jsxs as s}from"react/jsx-runtime";import{useState as B,useMemo as f,useEffect as L,useId as M}from"react";import{Input as W,FloatingLabel as k,Button as F,BUTTON_VARIANT as O,DropdownMenu as U,Stack as p,cn as _}from"@donotdev/components";import{Flag as I,COUNTRIES as N}from"@donotdev/core";const D=({label:V,value:o="",onChange:R,error:x,helperText:g,required:w=!1,disabled:b=!1,defaultCountry:S="FR",showFlags:z=!0,preferredCountries:c,countries:h})=>{const i=M(),m=f(()=>h&&h.length>0?h.map(e=>N.find(r=>r.code===e)).filter(e=>e!==void 0):Array.from(N),[h]),a=f(()=>{if(!c||c.length===0)return m;const e=c.map(d=>m.find(y=>y.code===d)).filter(d=>d!==void 0),r=m.filter(d=>!c.includes(d.code));return[...e,...r]},[m,c]),u=f(()=>a.find(e=>e.code===S)||a[0]||N[0],[S,a]),{country:v,phoneNumber:T}=f(()=>{if(!o)return{country:u,phoneNumber:""};const e=a.find(r=>o.startsWith(r.dialCode));return e?{country:e,phoneNumber:o.slice(e.dialCode.length).trim()}:o.startsWith("+")?{country:u,phoneNumber:o}:{country:u,phoneNumber:o}},[o,u,a]),[n,E]=B(u);L(()=>{v.code!==n.code&&E(v)},[v,n.code]);const C=T,$=e=>{E(e);const d={target:{value:e.dialCode+(C?" "+C:"")}};R(d)},j=e=>{const r=e.target.value,y={target:{value:n.dialCode+(r?" "+r:"")}};R(y)},A=a.map(e=>({label:e.dialCode,onClick:()=>$(e),checked:e.code===n.code,children:z?s(p,{direction:"row",align:"center",gap:"tight",children:[t(I,{code:e.flagCode,title:e.name}),t("span",{children:e.dialCode}),t("span",{style:{color:"var(--muted-foreground)",fontSize:"var(--font-size-xs)"},children:e.name})]}):s("span",{children:[e.dialCode," ",e.name]})})),l=!!x;return s(p,{gap:"tight",children:[t(k,{htmlFor:i,label:V,disabled:b,required:w,children:s("div",{className:"dndev-relative",style:{display:"flex",gap:0},children:[t(U,{trigger:t(F,{type:"button",variant:O.OUTLINE,disabled:b,style:{minWidth:"fit-content",padding:"0 var(--gap-md)",borderRight:"none",borderTopRightRadius:0,borderBottomRightRadius:0,borderRadius:"var(--radius-md) 0 0 var(--radius-md)"},"aria-label":`Country code: ${n.dialCode}`,children:s(p,{direction:"row",align:"center",gap:"tight",children:[z&&t(I,{code:n.flagCode,title:n.name}),t("span",{children:n.dialCode})]})}),items:A,contentWidth:"16rem"}),t(W,{id:i,type:"tel",inputMode:"tel",value:C,onChange:j,disabled:b,placeholder:"6 12 34 56 78",bare:!0,"data-variant":l?"destructive":void 0,className:"dndev-flex-1",style:{borderTopLeftRadius:0,borderBottomLeftRadius:0,borderRadius:"0 var(--radius-md) var(--radius-md) 0"},"aria-describedby":_(l&&`${i}-error`,g&&!l&&`${i}-helper`),"aria-invalid":l})]})}),l&&s(p,{id:`${i}-error`,direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)",color:"var(--destructive-foreground)"},role:"alert",children:[t("span",{children:"\u26A0"}),x]}),g&&!l&&t("p",{id:`${i}-helper`,style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:g})]})};var J=D;export{J as default};
1
+ "use client";import{jsx as i,jsxs as s}from"react/jsx-runtime";import{useState as A,useMemo as p,useEffect as B,useId as L}from"react";import{Input as M,FloatingLabel as k,Button as F,BUTTON_VARIANT as O,DropdownMenu as U,Stack as g,cn as _}from"@donotdev/components";import{Flag as z,COUNTRIES as y}from"@donotdev/core";const D=({label:E,value:d="",onChange:N,error:R,helperText:b,required:I=!1,disabled:v=!1,defaultCountry:x="FR",showFlags:W=!0,preferredCountries:c,countries:h})=>{const a=L(),f=p(()=>h&&h.length>0?h.map(e=>y.find(t=>t.code===e)).filter(e=>e!==void 0):Array.from(y),[h]),o=p(()=>{if(!c||c.length===0)return f;const e=c.map(r=>f.find(m=>m.code===r)).filter(r=>r!==void 0),t=f.filter(r=>!c.includes(r.code));return[...e,...t]},[f,c]),u=p(()=>o.find(e=>e.code===x)||o[0]||y[0],[x,o]),{country:C,phoneNumber:w}=p(()=>{if(!d)return{country:u,phoneNumber:""};const e=o.find(r=>d.startsWith(r.dialCode));if(e){let r=d.slice(e.dialCode.length).trim();return r.startsWith("0")&&(r=r.slice(1).trim()),r=r.replace(/\s+/g," ").trim(),{country:e,phoneNumber:r}}if(d.startsWith("+"))return{country:u,phoneNumber:d};let t=d.trim();return t.startsWith("0")&&(t=t.slice(1).trim()),t=t.replace(/\s+/g," ").trim(),{country:u,phoneNumber:t}},[d,u,o]),[n,S]=A(u);B(()=>{C.code!==n.code&&S(C)},[C,n.code]);const V=w,T=e=>{S(e);let t=V;t.startsWith("0")&&(t=t.slice(1).trim()),t=t.replace(/\s+/g," ").trim();const m={target:{value:e.dialCode+(t?" "+t:"")}};N(m)},$=e=>{let t=e.target.value;t.startsWith("0")&&(t=t.slice(1).trim()),t=t.replace(/\s+/g," ").trim();const m={target:{value:n.dialCode+(t?" "+t:"")}};N(m)},j=o.map(e=>({label:e.dialCode,onClick:()=>T(e),checked:e.code===n.code,children:W?s(g,{direction:"row",align:"center",gap:"tight",children:[i(z,{code:e.flagCode,title:e.name}),i("span",{children:e.dialCode}),i("span",{style:{color:"var(--muted-foreground)",fontSize:"var(--font-size-xs)"},children:e.name})]}):s("span",{children:[e.dialCode," ",e.name]})})),l=!!R;return s(g,{gap:"tight",children:[i(k,{htmlFor:a,label:E,disabled:v,required:I,children:s("div",{className:"dndev-relative",style:{display:"flex",gap:0},children:[i(U,{trigger:i(F,{type:"button",variant:O.OUTLINE,disabled:v,style:{minWidth:"fit-content",padding:"0 var(--gap-md)",borderRight:"none",borderTopRightRadius:0,borderBottomRightRadius:0,borderRadius:"var(--radius-md) 0 0 var(--radius-md)"},"aria-label":`Country code: ${n.dialCode}`,children:s(g,{direction:"row",align:"center",gap:"tight",children:[W&&i(z,{code:n.flagCode,title:n.name}),i("span",{children:n.dialCode})]})}),items:j,contentWidth:"16rem"}),i(M,{id:a,type:"tel",inputMode:"tel",value:V,onChange:$,disabled:v,placeholder:"6 12 34 56 78",bare:!0,"data-variant":l?"destructive":void 0,className:"dndev-flex-1",style:{borderTopLeftRadius:0,borderBottomLeftRadius:0,borderRadius:"0 var(--radius-md) var(--radius-md) 0"},"aria-describedby":_(l&&`${a}-error`,b&&!l&&`${a}-helper`),"aria-invalid":l})]})}),l&&s(g,{id:`${a}-error`,direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)",color:"var(--destructive-foreground)"},role:"alert",children:[i("span",{children:"\u26A0"}),R]}),b&&!l&&i("p",{id:`${a}-helper`,style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:b})]})};var J=D;export{J as default};
@@ -1 +1 @@
1
- "use client";import{jsx as t,jsxs as l}from"react/jsx-runtime";import{useId as U,useState as D}from"react";import{Input as C,Checkbox as E,Stack as _,Select as $,CollapsiblePrimitive as A,CollapsibleTrigger as L,CollapsibleContent as M}from"@donotdev/components";import{useTranslation as w,getCurrencySymbol as z}from"@donotdev/core";import{CirclePlus as Y,CircleMinus as q}from"lucide-react";const B=["EUR","USD","GBP","CHF","JPY","KRW"],G=({label:y,value:n,onChange:I,error:s,helperText:h,required:P=!1,disabled:i=!1,placeholder:N="0",defaultCurrency:r="EUR",optionsTitle:x="Price options",currencies:f})=>{const u=U(),{t:m}=w("crud"),o=f?.length?f:[...B],b=n?.currency??r,p=o.includes(b)?b:o[0]??r,O=n?.vatIncluded??!0,v=n?.discountPercent??0,S=`${y} (${z(p)})`,d=e=>{const c=e.amount!==void 0?e.amount:n?.amount??0;let a=e.currency!==void 0?e.currency:n?.currency??r;o.includes(a)||(a=p);const F=e.vatIncluded!==void 0?e.vatIncluded:n?.vatIncluded??!0,R=e.discountPercent!==void 0?e.discountPercent:n?.discountPercent??0;I({amount:Number(c),currency:a,vatIncluded:F,discountPercent:Number(R)})},T=e=>{const c=e.target.value;if(c===""||c===null){d({amount:0});return}const a=parseFloat(c);d({amount:isNaN(a)?0:a})},V=e=>{d({currency:e||r})},j=e=>{const c=e.target.value;if(c===""||c===null){d({discountPercent:0});return}const a=parseFloat(c);d({discountPercent:isNaN(a)?0:a})},[g,k]=D(!1);return l(A,{open:g,onOpenChange:k,children:[l(_,{gap:"medium",children:[l("div",{style:{display:"grid",gridTemplateColumns:"1fr auto",gap:"var(--gap-sm)",alignItems:"end"},children:[t(C,{id:u,type:"number",inputMode:"decimal",label:S,value:n?.amount!==void 0&&n?.amount!==null?n.amount:"",onChange:T,disabled:i,placeholder:N,required:P,min:0,step:.01,"data-variant":s?"destructive":void 0,"aria-invalid":s}),t(L,{asChild:!0,children:t("button",{type:"button","aria-label":x,"aria-expanded":g,className:"dndev-collapsible-trigger",style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"var(--gap-sm)",background:"none",border:"none",cursor:"pointer"},children:g?t(q,{className:"dndev-collapsible-icon","aria-hidden":"true"}):t(Y,{className:"dndev-collapsible-icon","aria-hidden":"true"})})})]}),t(M,{className:"dndev-collapsible-content",children:l("div",{style:{display:"grid",gridTemplateColumns:o.length>1?"1fr auto 1fr":"auto 1fr",gap:"var(--gap-sm)",alignItems:"end",paddingTop:"var(--gap-md)"},children:[o.length>1&&t($,{value:p,onValueChange:V,placeholder:r,options:o.map(e=>({value:e,label:e})),disabled:i,label:m("price.currency",{defaultValue:"Currency"})}),t(E,{id:`${u}-vat`,label:m("price.vatIncluded",{defaultValue:"VAT Incl."}),checked:O,onCheckedChange:e=>d({vatIncluded:e===!0}),disabled:i}),t(C,{id:`${u}-discount`,type:"number",inputMode:"decimal",min:0,max:100,step:1,value:v===0?"":v,onChange:j,disabled:i,placeholder:"0",label:m("price.discountLabel",{defaultValue:"Discount (%)"})})]})})]}),h&&t("p",{style:{fontSize:"var(--font-size-xs)",color:s?"var(--destructive-foreground)":"var(--muted-foreground)"},children:h})]})};var X=G;export{X as default};
1
+ "use client";import{jsx as n,jsxs as c}from"react/jsx-runtime";import{useId as R,useState as U}from"react";import{Input as y,Checkbox as q,Stack as z,Select as D,CollapsiblePrimitive as E,CollapsibleTrigger as A,CollapsibleContent as B}from"@donotdev/components";import{useTranslation as G,getCurrencySymbol as L}from"@donotdev/core";import{CirclePlus as O,CircleMinus as Y}from"lucide-react";const w=["EUR","USD","GBP","CHF","JPY","KRW"],H=({label:f,value:a,onChange:I,error:s,helperText:g,required:P=!1,disabled:o=!1,placeholder:N="0",defaultCurrency:i="EUR",optionsTitle:x="Price options",currencies:b})=>{const u=R(),{t:p}=G("crud"),r=b?.length?b:[...w],h=a?.currency??i,m=r.includes(h)?h:r[0]??i,T=a?.vatIncluded??!0,C=a?.discountPercent??0,S=`${f} (${L(m)})`,d=e=>{const l=e.amount!==void 0?e.amount:a?.amount??0;let t=e.currency!==void 0?e.currency:a?.currency??i;r.includes(t)||(t=m);const F=e.vatIncluded!==void 0?e.vatIncluded:a?.vatIncluded??!0,M=e.discountPercent!==void 0?e.discountPercent:a?.discountPercent??0;I({amount:Number(l),currency:t,vatIncluded:F,discountPercent:Number(M)})},k=e=>{const l=e.target.value;if(l===""||l===null){d({amount:0});return}const t=parseFloat(l);d({amount:isNaN(t)?0:t})},V=e=>{d({currency:e||i})},$=e=>{const l=e.target.value;if(l===""||l===null){d({discountPercent:0});return}const t=parseFloat(l);d({discountPercent:isNaN(t)?0:t})},[v,j]=U(!1);return c(E,{open:v,onOpenChange:j,children:[c(z,{gap:"medium",children:[c("div",{style:{display:"grid",gridTemplateColumns:"1fr auto",gap:"var(--gap-sm)",alignItems:"end"},children:[n(y,{id:u,type:"number",inputMode:"decimal",label:S,value:a?.amount!==void 0&&a?.amount!==null?a.amount:"",onChange:k,disabled:o,placeholder:N,required:P,min:0,step:.01,"data-variant":s?"destructive":void 0,"aria-invalid":s}),n(A,{asChild:!0,children:n("button",{type:"button","aria-label":x,"aria-expanded":v,className:"dndev-collapsible-trigger",style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"var(--gap-sm)",background:"none",border:"none",cursor:"pointer"},children:v?n(Y,{className:"dndev-collapsible-icon","aria-hidden":"true"}):n(O,{className:"dndev-collapsible-icon","aria-hidden":"true"})})})]}),n(B,{className:"dndev-collapsible-content",children:c("div",{style:{display:"grid",gridTemplateColumns:r.length>1?"1fr auto 1fr":"auto 1fr",gap:"var(--gap-sm)",alignItems:"end",paddingTop:"var(--gap-md)"},children:[r.length>1&&n(D,{value:m,onValueChange:V,placeholder:i,options:r.map(e=>({value:e,label:e})),disabled:o,label:p("price.currency",{defaultValue:"Currency"})}),n(q,{id:`${u}-vat`,label:p("price.vatIncluded",{defaultValue:"VAT Incl."}),checked:T,onCheckedChange:e=>d({vatIncluded:e===!0}),disabled:o}),n(y,{id:`${u}-discount`,type:"number",inputMode:"decimal",min:0,max:100,step:1,value:C===0?"":C,onChange:$,disabled:o,placeholder:"0",label:p("price.discountLabel",{defaultValue:"Discount (%)"})})]})})]}),g&&n("p",{style:{fontSize:"var(--font-size-xs)",color:s?"var(--destructive-foreground)":"var(--muted-foreground)"},children:g})]})};var J=H;export{J as default};
@@ -1 +1 @@
1
- import{jsx as e,jsxs as c}from"react/jsx-runtime";import{RadioGroup as u,Label as f,Stack as h}from"@donotdev/components";const v=({label:o,value:n,onChange:r,options:s,error:a,helperText:t,required:i})=>{const d=l=>{r({target:{value:l}})};return c(h,{gap:"tight",children:[e(f,{required:i,style:{display:"block",fontSize:"var(--font-size-sm)",fontWeight:500},children:o}),e(u,{value:n,onValueChange:d,items:s}),t&&e("p",{style:{fontSize:"var(--font-size-xs)",color:a?"var(--destructive-foreground)":"var(--muted-foreground)"},children:t})]})};var x=v;export{x as default};
1
+ import{jsx as e,jsxs as d}from"react/jsx-runtime";import{RadioGroup as f,Label as c,Stack as v}from"@donotdev/components";const h=({label:o,value:a,onChange:t,options:s,error:i,helperText:r,required:n})=>{const l=u=>{t({target:{value:u}})};return d(v,{gap:"tight",children:[e(c,{required:n,style:{display:"block",fontSize:"var(--font-size-sm)",fontWeight:500},children:o}),e(f,{value:a,onValueChange:l,items:s}),r&&e("p",{style:{fontSize:"var(--font-size-xs)",color:i?"var(--destructive-foreground)":"var(--muted-foreground)"},children:r})]})};var p=h;export{p as default};
@@ -1 +1 @@
1
- import{jsx as e,jsxs as d}from"react/jsx-runtime";import{Label as h,Slider as y,Stack as c}from"@donotdev/components";const x=({label:o,value:a=0,onChange:l,error:i,helperText:s,min:t=0,max:u=100,step:f=1,disabled:r,required:g,showValue:v=!0})=>{const m=n=>{const p={target:{value:n.toString()}};l(p)};return d(c,{gap:"tight",children:[d(c,{direction:"row",justify:"between",align:"center",children:[e(h,{required:g,style:{fontSize:"var(--font-size-sm)",fontWeight:500},children:o}),v&&e("span",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},children:a})]}),e(y,{value:[a??t],onValueChange:([n])=>m(n??t),min:t,max:u,step:f,disabled:r,style:{borderColor:i?"var(--destructive)":void 0,opacity:r?"var(--opacity-muted)":void 0,cursor:r?"not-allowed":void 0},"aria-label":o}),s&&e("p",{style:{fontSize:"var(--font-size-xs)",color:i?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:s})]})};var C=x;export{C as default};
1
+ import{jsx as e,jsxs as l}from"react/jsx-runtime";import{Label as h,Slider as x,Stack as d}from"@donotdev/components";const y=({label:t,value:i=0,onChange:c,error:n,helperText:s,min:r=0,max:u=100,step:v=1,disabled:o,required:m,showValue:f=!0})=>{const p=a=>{const g={target:{value:a.toString()}};c(g)};return l(d,{gap:"tight",children:[l(d,{direction:"row",justify:"between",align:"center",children:[e(h,{required:m,style:{fontSize:"var(--font-size-sm)",fontWeight:500},children:t}),f&&e("span",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},children:i})]}),e(x,{value:[i??r],onValueChange:([a])=>p(a??r),min:r,max:u,step:v,disabled:o,style:{borderColor:n?"var(--destructive)":void 0,opacity:o?"var(--opacity-muted)":void 0,cursor:o?"not-allowed":void 0},"aria-label":t}),s&&e("p",{style:{fontSize:"var(--font-size-xs)",color:n?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:s})]})};var b=y;export{b as default};
@@ -1 +1 @@
1
- import{jsx as e,jsxs as g}from"react/jsx-runtime";import{Label as m,Rating as u,Stack as c}from"@donotdev/components";const p=({label:r,value:o=0,onChange:t,error:n,helperText:a,max:s=5,disabled:i,required:d,readonly:l,showValue:f=!1})=>g(c,{gap:"tight",children:[e(m,{required:d,style:{fontSize:"var(--font-size-sm)",fontWeight:500},children:r}),e(u,{value:o,onChange:t,max:s,disabled:i,readonly:l,showValue:f,"aria-label":r}),a&&e("p",{style:{fontSize:"var(--font-size-xs)",color:n?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:a})]});var x=p;export{x as default};
1
+ import{jsx as e,jsxs as g}from"react/jsx-runtime";import{Label as m,Rating as f,Stack as h}from"@donotdev/components";const p=({label:a,value:o=0,onChange:s,error:l,helperText:r,max:t=5,disabled:i,required:n,readonly:d,showValue:u=!1})=>g(h,{gap:"tight",children:[e(m,{required:n,style:{fontSize:"var(--font-size-sm)",fontWeight:500},children:a}),e(f,{value:o,onChange:s,max:t,disabled:i,readonly:d,showValue:u,"aria-label":a}),r&&e("p",{style:{fontSize:"var(--font-size-xs)",color:l?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:r})]});var v=p;export{v as default};
@@ -1 +1 @@
1
- import{jsx as t,jsxs as l}from"react/jsx-runtime";import"lucide-react";import{useMemo as z,useId as S}from"react";import{Combobox as A,Stack as d}from"@donotdev/components";import{useTranslation as I}from"@donotdev/core";const O=({label:r,value:s,onChange:u,options:a,isLoading:f=!1,error:p,helperText:o,required:m,onBlur:h,onCreate:$,placeholder:g})=>{const{t:i}=I("crud"),c=S(),v=z(()=>a.map(e=>({value:e.id,label:e.label,description:e.description})),[a]),x=e=>{const j=Array.isArray(e)?e[0]||"":e;u(j)},C=e=>{e||h?.()},n=!!p,b=`${c}-error`,y=`${c}-helper`;return l(d,{gap:"tight",children:[t(A,{label:r,value:s||"",onValueChange:x,onOpenChange:C,placeholder:g||i("reference.placeholder",{label:r})||`Select ${r}`,emptyMessage:i("reference.noResults")||"No results found",options:v,required:m,variant:n?"destructive":void 0,isLoading:f,clearable:!!s}),n&&l(d,{id:b,direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)",color:"var(--destructive-foreground)"},role:"alert",children:[t("span",{children:"\u26A0"}),o]}),o&&!n&&t("p",{id:y,style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:o})]})};var F=O;export{F as default};
1
+ import{jsx as t,jsxs as d}from"react/jsx-runtime";import"lucide-react";import{useMemo as S,useId as A}from"react";import{Combobox as $,Stack as c}from"@donotdev/components";import{useTranslation as j}from"@donotdev/core";const q=({label:r,value:l,onChange:p,options:n,isLoading:u=!1,error:f,helperText:o,required:h,onBlur:m,onCreate:L,placeholder:g})=>{const{t:i}=j("crud"),s=A(),v=S(()=>n.map(e=>({value:e.id,label:e.label,description:e.description})),[n]),b=e=>{const z=Array.isArray(e)?e[0]||"":e;p(z)},x=e=>{e||m?.()},a=!!f,y=`${s}-error`,C=`${s}-helper`;return d(c,{gap:"tight",children:[t($,{label:r,value:l||"",onValueChange:b,onOpenChange:x,placeholder:g||i("reference.placeholder",{label:r})||`Select ${r}`,emptyMessage:i("reference.noResults")||"No results found",options:v,required:h,variant:a?"destructive":void 0,isLoading:u,clearable:!!l}),a&&d(c,{id:y,direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)",color:"var(--destructive-foreground)"},role:"alert",children:[t("span",{children:"\u26A0"}),o]}),o&&!a&&t("p",{id:C,style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:o})]})};var I=q;export{I as default};
@@ -1 +1 @@
1
- "use client";import{jsx as e}from"react/jsx-runtime";import{lazy as m,Suspense as h,useState as x,useEffect as C}from"react";import{Stack as T}from"@donotdev/components";import p from"./TextAreaComponent";const c=m(()=>typeof window<"u"?import("./internal/TiptapEditor").catch(()=>({default:()=>null})):Promise.resolve({default:()=>null})),b=({label:t,value:r="",onChange:l,error:o,helperText:n,required:a,disabled:i,placeholder:s,className:u})=>{const[f,d]=x(!1);return C(()=>{d(!0)},[]),f?e(T,{gap:"tight",children:e(h,{fallback:e(p,{label:t,value:r,onChange:l,error:o,helperText:n,required:a,disabled:i,placeholder:s,className:u}),children:c?e(c,{label:t,value:r,onChange:l,error:o,helperText:n,required:a,disabled:i,placeholder:s,className:u}):e(p,{label:t,value:r,onChange:l,error:o,helperText:n,required:a,disabled:i,placeholder:s,className:u})})}):e(p,{label:t,value:r,onChange:l,error:o,helperText:n,required:a,disabled:i,placeholder:s,className:u})};var v=b;export{v as default};
1
+ "use client";import{jsx as e}from"react/jsx-runtime";import{lazy as m,Suspense as b,useState as f,useEffect as v}from"react";import{Stack as x}from"@donotdev/components";import p from"./TextAreaComponent";const i=m(()=>typeof window<"u"?import("./internal/TiptapEditor").catch(()=>({default:()=>null})):Promise.resolve({default:()=>null})),g=({label:l,value:a="",onChange:r,error:s,helperText:o,required:d,disabled:t,placeholder:c,className:h})=>{const[u,n]=f(!1);return v(()=>{n(!0)},[]),u?e(x,{gap:"tight",children:e(b,{fallback:e(p,{label:l,value:a,onChange:r,error:s,helperText:o,required:d,disabled:t,placeholder:c,className:h}),children:i?e(i,{label:l,value:a,onChange:r,error:s,helperText:o,required:d,disabled:t,placeholder:c,className:h}):e(p,{label:l,value:a,onChange:r,error:s,helperText:o,required:d,disabled:t,placeholder:c,className:h})})}):e(p,{label:l,value:a,onChange:r,error:s,helperText:o,required:d,disabled:t,placeholder:c,className:h})};var C=g;export{C as default};
@@ -1 +1 @@
1
- import{jsxs as e,jsx as n}from"react/jsx-runtime";import{Switch as m,Text as i,Stack as l}from"@donotdev/components";import{useTranslation as p}from"@donotdev/core";const f=({label:t,checked:c=!1,onChange:a,uncheckedLabel:d,checkedLabel:s,helperText:r})=>{const{t:g}=p("dndev"),o=h=>{a&&a({target:{checked:h}})};return e(l,{gap:"tight",children:[e(l,{direction:"row",align:"center",gap:"medium",style:{flexWrap:"wrap"},children:[e(i,{level:"body",align:"start",children:[t,":"]}),n(m,{checked:c,onCheckedChange:o,"aria-label":t,variant:"muted",uncheckedLabel:d,checkedLabel:s})]}),r&&n(i,{as:"p",variant:"muted",level:"small",children:r})]})};var v=f;export{v as default};
1
+ import{jsxs as e,jsx as c}from"react/jsx-runtime";import{Switch as m,Text as r,Stack as n}from"@donotdev/components";import{useTranslation as p}from"@donotdev/core";const g=({label:a,checked:d=!1,onChange:l,uncheckedLabel:i,checkedLabel:s,helperText:t})=>{const{t:u}=p("dndev"),h=o=>{l&&l({target:{checked:o}})};return e(n,{gap:"tight",children:[e(n,{direction:"row",align:"center",gap:"medium",style:{flexWrap:"wrap"},children:[e(r,{level:"body",align:"start",children:[a,":"]}),c(m,{checked:d,onCheckedChange:h,"aria-label":a,variant:"muted",uncheckedLabel:i,checkedLabel:s})]}),t&&c(r,{as:"p",variant:"muted",level:"small",children:t})]})};var k=g;export{k as default};
@@ -1 +1 @@
1
- "use client";import{jsx as s,jsxs as a}from"react/jsx-runtime";import{useState as N,useId as z,useRef as A,useEffect as B}from"react";import{Textarea as E,FloatingLabel as I,Spinner as _,cn as p,Stack as m}from"@donotdev/components";const k=({label:b,value:i="",onChange:y,error:f,helperText:o,rows:x=3,loading:l=!1,maxLength:r,showCharCount:v=!1,autoResize:n=!1,required:F=!1,disabled:h=!1,className:$,...S})=>{const e=z(),[q,g]=N(!1),d=A(null),t=!!f,c=i.length,j=r&&c>r*.8,w=r&&c>r;return B(()=>{if(n&&d.current){const u=d.current;u.style.height="auto",u.style.height=`${u.scrollHeight}px`}},[i,n]),a(m,{gap:"tight",children:[s(I,{htmlFor:e,label:b,disabled:h||l,required:F,children:a("div",{className:"dndev-relative",children:[s(E,{ref:d,id:e,value:i,onChange:y,onFocus:()=>g(!0),onBlur:()=>g(!1),disabled:h||l,maxLength:r,rows:n?1:x,bare:!0,"aria-describedby":p(t&&`${e}-error`,o&&!t&&`${e}-helper`,v&&`${e}-count`),"aria-invalid":t,className:p("dndev-w-full",n&&"dndev-overflow-hidden",$),"data-variant":t?"destructive":void 0,style:{resize:n?"none":void 0},...S}),l&&s("div",{className:"dndev-absolute",style:{right:"var(--gap-md)",top:"var(--gap-md)"},children:s(_,{"aria-label":"Loading"})})]})}),v&&r&&a("div",{id:`${e}-count`,style:{fontSize:"var(--font-size-xs)",textAlign:"right",color:w?"var(--destructive-foreground)":j?"var(--warning)":"var(--muted-foreground)"},children:[c,"/",r]}),t&&a(m,{as:"p",id:`${e}-error`,direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)",color:"var(--destructive-foreground)"},role:"alert",children:[s("span",{children:"\u26A0"}),f]}),o&&!t&&s("p",{id:`${e}-helper`,style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:o})]})};var J=k;export{J as default};
1
+ "use client";import{jsx as t,jsxs as i}from"react/jsx-runtime";import{useState as C,useId as L,useRef as j,useEffect as q}from"react";import{Textarea as A,FloatingLabel as F,Spinner as k,cn as m,Stack as p}from"@donotdev/components";const B=({label:x,value:o="",onChange:b,error:h,helperText:d,rows:z=3,loading:l=!1,maxLength:r,showCharCount:v=!1,autoResize:s=!1,required:w=!1,disabled:g=!1,className:y,...$})=>{const e=L(),[I,f]=C(!1),n=j(null),a=!!h,c=o.length,S=r&&c>r*.8,N=r&&c>r;return q(()=>{if(s&&n.current){const u=n.current;u.style.height="auto",u.style.height=`${u.scrollHeight}px`}},[o,s]),i(p,{gap:"tight",children:[t(F,{htmlFor:e,label:x,disabled:g||l,required:w,children:i("div",{className:"dndev-relative",children:[t(A,{ref:n,id:e,value:o,onChange:b,onFocus:()=>f(!0),onBlur:()=>f(!1),disabled:g||l,maxLength:r,rows:s?1:z,bare:!0,"aria-describedby":m(a&&`${e}-error`,d&&!a&&`${e}-helper`,v&&`${e}-count`),"aria-invalid":a,className:m("dndev-w-full",s&&"dndev-overflow-hidden",y),"data-variant":a?"destructive":void 0,style:{resize:s?"none":void 0},...$}),l&&t("div",{className:"dndev-absolute",style:{right:"var(--gap-md)",top:"var(--gap-md)"},children:t(k,{"aria-label":"Loading"})})]})}),v&&r&&i("div",{id:`${e}-count`,style:{fontSize:"var(--font-size-xs)",textAlign:"right",color:N?"var(--destructive-foreground)":S?"var(--warning)":"var(--muted-foreground)"},children:[c,"/",r]}),a&&i(p,{as:"p",id:`${e}-error`,direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)",color:"var(--destructive-foreground)"},role:"alert",children:[t("span",{children:"\u26A0"}),h]}),d&&!a&&t("p",{id:`${e}-helper`,style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:d})]})};var E=B;export{E as default};
@@ -1 +1 @@
1
- "use client";import{jsx as o,jsxs as s}from"react/jsx-runtime";import{useId as j}from"react";import{Input as x,cn as c,Stack as u}from"@donotdev/components";const _=({label:f,value:d="",onChange:v,error:a,helperText:t,type:p="text",loading:g=!1,maxLength:r,showCharCount:l=!1,required:h=!1,disabled:m=!1,className:z,...$})=>{const e=j(),i=!!a,n=d.length,b=r&&n>r*.8,y=r&&n>r,{children:w,...S}=$;return s(u,{gap:"tight",children:[o(x,{id:e,type:p,value:d,onChange:v,label:f,disabled:m||g,maxLength:r,required:h,"aria-describedby":c(i&&`${e}-error`,t&&!i&&`${e}-helper`,l&&`${e}-count`),"aria-invalid":i,className:c("dndev-w-full",z),"data-variant":i?"destructive":void 0,...S}),l&&r&&s("div",{id:`${e}-count`,style:{fontSize:"var(--font-size-xs)",textAlign:"right",color:y?"var(--destructive-foreground)":b?"var(--warning)":"var(--muted-foreground)"},children:[n,"/",r]}),i&&s(u,{id:`${e}-error`,direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)",color:"var(--destructive-foreground)"},role:"alert",children:[o("span",{children:"\u26A0"}),a]}),t&&!i&&o("p",{id:`${e}-helper`,style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:t})]})};var C=_;export{C as default};
1
+ "use client";import{jsx as n,jsxs as o}from"react/jsx-runtime";import{useId as w}from"react";import{Input as C,cn as c,Stack as u}from"@donotdev/components";const S=({label:h,value:d="",onChange:v,error:s,helperText:a,type:g="text",loading:f=!1,maxLength:e,showCharCount:l=!1,required:p=!1,disabled:m=!1,className:x,...b})=>{const r=w(),t=!!s,i=d.length,y=e&&i>e*.8,z=e&&i>e,{children:q,...$}=b;return o(u,{gap:"tight",children:[n(C,{id:r,type:g,value:d,onChange:v,label:h,disabled:m||f,maxLength:e,required:p,"aria-describedby":c(t&&`${r}-error`,a&&!t&&`${r}-helper`,l&&`${r}-count`),"aria-invalid":t,className:c("dndev-w-full",x),"data-variant":t?"destructive":void 0,...$}),l&&e&&o("div",{id:`${r}-count`,style:{fontSize:"var(--font-size-xs)",textAlign:"right",color:z?"var(--destructive-foreground)":y?"var(--warning)":"var(--muted-foreground)"},children:[i,"/",e]}),t&&o(u,{id:`${r}-error`,direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)",color:"var(--destructive-foreground)"},role:"alert",children:[n("span",{children:"\u26A0"}),s]}),a&&!t&&n("p",{id:`${r}-helper`,style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:a})]})};var j=S;export{j as default};
@@ -1 +1 @@
1
- import{jsx as m}from"react/jsx-runtime";import h from"./DateFieldComponent";const p=({label:o,value:e,onChange:t,error:a,helperText:r,mode:s="datetime-local",required:l})=>{const i=e?new Date(e).toISOString():"";return m(h,{label:o,value:i,onChange:n=>{if(n){const d={target:{value:new Date(n).toISOString()}};t(d)}else t({target:{value:""}})},error:a,helperText:r,mode:s,required:l})};var f=p;export{f as default};
1
+ import{jsx as d}from"react/jsx-runtime";import s from"./DateFieldComponent";const g=({label:a,value:e,onChange:r,error:o,helperText:l,mode:n="datetime-local",required:i})=>{const m=e?new Date(e).toISOString():"";return d(s,{label:a,value:m,onChange:t=>{if(t){const u={target:{value:new Date(t).toISOString()}};r(u)}else r({target:{value:""}})},error:o,helperText:l,mode:n,required:i})};var p=g;export{p as default};
@@ -1 +1 @@
1
- import{default as t}from"./AvatarFieldComponent";import{default as n}from"./BadgeFieldComponent";import{default as m}from"./TextFieldComponent";import{default as d}from"./NumberFieldComponent";import{default as l}from"./DateFieldComponent";import{default as x}from"./CheckboxFieldComponent";import{default as s}from"./ComboboxComponent";import{default as F}from"./DropdownComponent";import{default as c}from"./MultiDropdownComponent";import{default as R}from"./FileFieldComponent";import{default as P}from"./ImageFieldComponent";import{default as h}from"./DocumentFieldComponent";import{default as A}from"./TextAreaComponent";import{default as M}from"./SwitchFieldComponent";import{default as S}from"./RadioFieldComponent";import{default as E}from"./RangeFieldComponent";import{default as k}from"./RatingFieldComponent";import{default as y}from"./DurationFieldComponent";import{DURATION_PRESETS as O}from"./DurationFieldComponent";import{default as _}from"./PhoneNumberComponent";import{default as q}from"./GeoPointFieldComponent";import{default as J}from"./MapFieldComponent";import{default as L}from"./TimestampFieldComponent";import{default as V}from"./MultiInputTextFieldComponent";import{default as X}from"./ButtonFieldComponent";import{default as Z}from"./HiddenFieldComponent";import{default as oo}from"./PasswordFieldComponent";import{default as to}from"./AddressFieldComponent";import{default as no}from"./CurrencyFieldComponent";import{default as mo}from"./PriceFieldComponent";import{default as fo}from"./RichTextComponent";import{default as uo}from"./GdprConsentFieldComponent";export{to as AddressFieldComponent,t as AvatarFieldComponent,n as BadgeFieldComponent,X as ButtonFieldComponent,x as CheckboxFieldComponent,s as ComboboxComponent,no as CurrencyFieldComponent,O as DURATION_PRESETS,l as DateFieldComponent,h as DocumentFieldComponent,F as DropdownComponent,y as DurationFieldComponent,R as FileFieldComponent,uo as GdprConsentFieldComponent,q as GeoPointFieldComponent,Z as HiddenFieldComponent,P as ImageFieldComponent,J as MapFieldComponent,c as MultiDropdownComponent,V as MultiInputTextFieldComponent,d as NumberFieldComponent,oo as PasswordFieldComponent,_ as PhoneNumberComponent,mo as PriceFieldComponent,S as RadioFieldComponent,E as RangeFieldComponent,k as RatingFieldComponent,fo as RichTextComponent,M as SwitchFieldComponent,A as TextAreaComponent,m as TextFieldComponent,L as TimestampFieldComponent};
1
+ import{default as o}from"./AvatarFieldComponent";import{default as t}from"./BadgeFieldComponent";import{default as e}from"./TextFieldComponent";import{default as a}from"./NumberFieldComponent";import{default as m}from"./DateFieldComponent";import{default as n}from"./CheckboxFieldComponent";import{default as r}from"./ComboboxComponent";import{default as s}from"./DropdownComponent";import{default as p}from"./MultiDropdownComponent";import{default as i}from"./FileFieldComponent";import{default as d}from"./ImageFieldComponent";import{default as f}from"./DocumentFieldComponent";import{default as l}from"./TextAreaComponent";import{default as u}from"./SwitchFieldComponent";import{default as C}from"./RadioFieldComponent";import{default as F}from"./RangeFieldComponent";import{default as R}from"./RatingFieldComponent";import{default as T}from"./DurationFieldComponent";import{DURATION_PRESETS as x}from"./DurationFieldComponent";import{default as c}from"./PhoneNumberComponent";import{default as D}from"./GeoPointFieldComponent";import{default as P}from"./MapFieldComponent";import{default as A}from"./TimestampFieldComponent";import{default as S}from"./MultiInputTextFieldComponent";import{default as b}from"./ButtonFieldComponent";import{default as h}from"./HiddenFieldComponent";import{default as E}from"./PasswordFieldComponent";import{default as g}from"./AddressFieldComponent";import{default as w}from"./CurrencyFieldComponent";import{default as I}from"./PriceFieldComponent";import{default as M}from"./RichTextComponent";import{default as N}from"./GdprConsentFieldComponent";export{g as AddressFieldComponent,o as AvatarFieldComponent,t as BadgeFieldComponent,b as ButtonFieldComponent,n as CheckboxFieldComponent,r as ComboboxComponent,w as CurrencyFieldComponent,x as DURATION_PRESETS,m as DateFieldComponent,f as DocumentFieldComponent,s as DropdownComponent,T as DurationFieldComponent,i as FileFieldComponent,N as GdprConsentFieldComponent,D as GeoPointFieldComponent,h as HiddenFieldComponent,d as ImageFieldComponent,P as MapFieldComponent,p as MultiDropdownComponent,S as MultiInputTextFieldComponent,a as NumberFieldComponent,E as PasswordFieldComponent,c as PhoneNumberComponent,I as PriceFieldComponent,C as RadioFieldComponent,F as RangeFieldComponent,R as RatingFieldComponent,M as RichTextComponent,u as SwitchFieldComponent,l as TextAreaComponent,e as TextFieldComponent,A as TimestampFieldComponent};
@@ -1,4 +1,4 @@
1
- "use client";import{jsx as n,jsxs as M}from"react/jsx-runtime";import{useEffect as y,useState as r,useMemo as j}from"react";import{Stack as L}from"@donotdev/components";const H=({label:P,value:o="",onChange:f,error:a,helperText:m,required:E,disabled:s,placeholder:g,className:b})=>{const[i,x]=r(!1),[d,T]=r(!1),[l,z]=r(null),[h,C]=r(null),[c,S]=r(null),[p,w]=r(null);y(()=>{if(i||d)return;(async()=>{try{const[{useEditor:e,EditorContent:u},k,F]=await Promise.all([import("@tiptap/react"),import("@tiptap/starter-kit"),import("@tiptap/extension-placeholder")]);z(e),C(u),S(k.default),w(F.default),x(!0)}catch(e){e instanceof Error&&(e.message.includes("Cannot find module '@tiptap")||e.message.includes("Failed to fetch dynamically imported module")),T(!0)}})()},[i,d]);const t=j(()=>!i||!l||!c||!p?null:l({extensions:[c.configure({heading:{levels:[1,2,3]}}),p.configure({placeholder:g||"Start typing..."})],content:o,editable:!s,onUpdate:({editor:v})=>{const u={target:{value:v.getHTML()}};f(u)}}),[i,l,c,p,o,s,g,f]);return y(()=>{t&&o!==t.getHTML()&&t.commands.setContent(o||"")},[o,t]),d||!i||!t||!h?null:M(L,{gap:"tight",children:[M("label",{style:{fontSize:"var(--font-size-sm)",fontWeight:500,color:a?"var(--destructive-foreground)":"var(--foreground)"},children:[P,E&&n("span",{style:{color:"var(--destructive)"},children:" *"})]}),n("div",{className:b,"data-variant":a?"destructive":void 0,style:{border:"var(--border-hairline) solid",borderColor:a?"var(--destructive)":"var(--line-2)",borderRadius:"var(--radius-interactive)",padding:"var(--gap-md)",minHeight:"200px",backgroundColor:s?"var(--muted)":"transparent",opacity:s?"var(--opacity-muted)":void 0},children:n(h,{editor:t})}),m&&n("p",{style:{fontSize:"var(--font-size-xs)",color:a?"var(--destructive-foreground)":"var(--muted-foreground)"},children:m}),n("style",{children:`
1
+ "use client";import{jsx as n,jsxs as h}from"react/jsx-runtime";import{useEffect as y,useState as o,useMemo as T}from"react";import{Stack as j}from"@donotdev/components";const L=({label:M,value:t="",onChange:f,error:a,helperText:g,required:b,disabled:l,placeholder:v,className:P})=>{const[i,x]=o(!1),[s,z]=o(!1),[d,C]=o(null),[p,w]=o(null),[c,S]=o(null),[u,k]=o(null);y(()=>{i||s||(async()=>{try{const[{useEditor:r,EditorContent:m},E,H]=await Promise.all([import("@tiptap/react"),import("@tiptap/starter-kit"),import("@tiptap/extension-placeholder")]);C(r),w(m),S(E.default),k(H.default),x(!0)}catch(r){r instanceof Error&&(r.message.includes("Cannot find module '@tiptap")||r.message.includes("Failed to fetch dynamically imported module")),z(!0)}})()},[i,s]);const e=T(()=>!i||!d||!c||!u?null:d({extensions:[c.configure({heading:{levels:[1,2,3]}}),u.configure({placeholder:v||"Start typing..."})],content:t,editable:!l,onUpdate:({editor:r})=>{const m={target:{value:r.getHTML()}};f(m)}}),[i,d,c,u,t,l,v,f]);return y(()=>{e&&t!==e.getHTML()&&e.commands.setContent(t||"")},[t,e]),s||!i||!e||!p?null:h(j,{gap:"tight",children:[h("label",{style:{fontSize:"var(--font-size-sm)",fontWeight:500,color:a?"var(--destructive-foreground)":"var(--foreground)"},children:[M,b&&n("span",{style:{color:"var(--destructive)"},children:" *"})]}),n("div",{className:P,"data-variant":a?"destructive":void 0,style:{border:"var(--border-hairline) solid",borderColor:a?"var(--destructive)":"var(--line-2)",borderRadius:"var(--radius-interactive)",padding:"var(--gap-md)",minHeight:"200px",backgroundColor:l?"var(--muted)":"transparent",opacity:l?"var(--opacity-muted)":void 0},children:n(p,{editor:e})}),g&&n("p",{style:{fontSize:"var(--font-size-xs)",color:a?"var(--destructive-foreground)":"var(--muted-foreground)"},children:g}),n("style",{children:`
2
2
  .ProseMirror {
3
3
  outline: none;
4
4
  min-height: 150px;
@@ -49,4 +49,4 @@
49
49
  margin: 0.5em 0;
50
50
  color: var(--muted-foreground);
51
51
  }
52
- `})]})};var _=H;export{_ as default};
52
+ `})]})};var q=L;export{q as default};
@@ -1 +1 @@
1
- "use client";import{jsx as e,Fragment as re,jsxs as o}from"react/jsx-runtime";import{ChevronLeft as ae,ChevronRight as ne,RotateCcw as W,RotateCw as M,Trash2 as le,Check as ce,Undo2 as se,ZoomIn as de,ZoomOut as me,Maximize2 as pe,Grid3X3 as ge}from"lucide-react";import{useCallback as m,useEffect as Z,useState as s,useRef as he}from"react";import ue from"react-easy-crop";import{Button as r,BUTTON_VARIANT as a,Sheet as fe,Stack as l,Text as u,Slider as _,ToggleGroup as ve}from"@donotdev/components";import{useTranslation as we}from"@donotdev/core";import{processImage as ye}from"../../../utils/imageProcessing";import{createPreviewURL as Ce,revokePreviewURL as be}from"../../../utils/imageUtils";const Re={free:void 0,"1:1":1,"4:3":4/3,"16:9":16/9,"3:2":3/2};function ke({images:h,selectedIndex:n,open:L,onClose:U,onUpdate:B,onDelete:S,onNavigate:p,multiple:E=!1}){const{t:i}=we("crud"),[D,C]=s({x:0,y:0}),[f,g]=s(1),[b,v]=s(0),[I,H]=s(null),[P,A]=s("free"),[R,Y]=s(!0),[w,y]=s(!1),[G,z]=s(!1),[$,k]=s(!1),T=he({crop:{x:0,y:0},zoom:1,rotation:0}),c=h[n],O=E&&n>0,x=E&&n<h.length-1;Z(()=>{if(c){const t={x:0,y:0};C(t),g(1),v(c.rotation*90),A("free"),y(!1),k(!1),T.current={crop:t,zoom:1,rotation:c.rotation*90}}},[c]);const q=m((t,d)=>{H(d)},[]),K=m(()=>{C(T.current.crop),g(T.current.zoom),v(T.current.rotation)},[]),j=m(()=>{v(t=>(t-90+360)%360)},[]),F=m(()=>{v(t=>(t+90)%360)},[]),X=m(()=>{g(t=>Math.min(t+.25,3))},[]),J=m(()=>{g(t=>Math.max(t-.25,1))},[]),Q=m(()=>{g(1),C({x:0,y:0})},[]),ee=async()=>{if(!(!c||!I)){z(!0);try{const t=await ye(c.file,{crop:I,maxWidth:2048,maxHeight:2048,quality:.95}),d=new File([t.fullBlob],c.file.name,{type:"image/webp"}),oe=Ce(d);c.previewURL.startsWith("blob:")&&be(c.previewURL),B(n,{file:d,previewURL:oe,uploaded:null,uploadProgress:null,error:null,rotation:0}),y(!1)}catch{}finally{z(!1)}}},te=m(()=>{S(n),k(!1),h.length===1?U():n>=h.length-1&&p(n-1)},[n,h.length,S,U,p]);if(Z(()=>{if(!L)return;const t=d=>{d.key==="ArrowLeft"&&O?p(n-1):d.key==="ArrowRight"&&x?p(n+1):d.key==="Escape"&&w&&y(!1)};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[L,O,x,n,p,w]),!c)return null;const N=c.uploadProgress!==null&&c.uploadProgress<100,V=c.uploaded?.fullUrl||c.previewURL,ie=E?i("image.editor.titleWithIndex",{current:n+1,total:h.length}):i("image.editor.title");return e(fe,{open:L,onOpenChange:t=>!t&&U(),side:"right",title:ie,description:i("image.editor.description"),noSwipe:w,children:o(l,{gap:"large",style:{height:"100%"},children:[e("div",{style:{position:"relative",flex:1,minHeight:300,backgroundColor:"var(--surface-muted)",borderRadius:"var(--radius-lg)",overflow:"hidden"},children:w?e(ue,{image:V,crop:D,zoom:f,rotation:b,aspect:Re[P],onCropChange:C,onCropComplete:q,onZoomChange:g,showGrid:R,style:{containerStyle:{position:"absolute",top:0,left:0,right:0,bottom:0},cropAreaStyle:{border:"2px solid var(--primary)",boxShadow:"0 0 0 9999px rgba(0,0,0,0.5)"}}}):o(re,{children:[O&&e(r,{variant:a.GHOST,icon:ae,onClick:()=>p(n-1),"aria-label":i("image.editor.previousImage"),style:{position:"absolute",left:"var(--gap-sm)",top:"50%",transform:"translateY(-50%)",zIndex:10,backgroundColor:"rgba(0,0,0,0.3)",color:"white"}}),e("img",{src:V,alt:`Image ${n+1}`,style:{width:"100%",height:"100%",objectFit:"contain",transform:`rotate(${b}deg)`,transition:"transform var(--dur-normal) var(--ease-out)"}}),x&&e(r,{variant:a.GHOST,icon:ne,onClick:()=>p(n+1),"aria-label":i("image.editor.nextImage"),style:{position:"absolute",right:"var(--gap-sm)",top:"50%",transform:"translateY(-50%)",zIndex:10,backgroundColor:"rgba(0,0,0,0.3)",color:"white"}})]})}),w?o(l,{gap:"medium",children:[o(l,{gap:"tight",children:[e(u,{level:"small",variant:"muted",children:i("image.editor.aspectRatio")}),e(ve,{type:"single",value:P,onValueChange:t=>t&&A(t),items:[{value:"free",label:i("image.editor.aspectFree")},{value:"1:1",label:"1:1"},{value:"4:3",label:"4:3"},{value:"16:9",label:"16:9"}]})]}),o(l,{gap:"tight",children:[o(l,{direction:"row",justify:"between",align:"center",children:[e(u,{level:"small",variant:"muted",children:i("image.editor.zoom")}),o(u,{level:"small",variant:"muted",children:[Math.round(f*100),"%"]})]}),o(l,{direction:"row",gap:"tight",align:"center",children:[e(r,{variant:a.OUTLINE,icon:me,display:"compact",onClick:J,disabled:f<=1}),e(_,{value:[f],min:1,max:3,step:.05,onValueChange:t=>g(t[0]??1),style:{flex:1}}),e(r,{variant:a.OUTLINE,icon:de,display:"compact",onClick:X,disabled:f>=3})]})]}),o(l,{gap:"tight",children:[o(l,{direction:"row",justify:"between",align:"center",children:[e(u,{level:"small",variant:"muted",children:i("image.editor.rotation")}),o(u,{level:"small",variant:"muted",children:[b,"\xB0"]})]}),o(l,{direction:"row",gap:"tight",align:"center",children:[e(r,{variant:a.OUTLINE,icon:W,display:"compact",onClick:j,tooltip:i("image.editor.rotateLeft")}),e(_,{value:[b],min:0,max:360,step:1,onValueChange:t=>v(t[0]??0),style:{flex:1}}),e(r,{variant:a.OUTLINE,icon:M,display:"compact",onClick:F,tooltip:i("image.editor.rotateRight")})]})]}),o(l,{direction:"row",gap:"tight",children:[e(r,{variant:a.OUTLINE,icon:pe,display:"compact",onClick:Q,tooltip:i("image.editor.fitToView")}),e(r,{variant:a.OUTLINE,icon:ge,display:"compact",onClick:()=>Y(!R),tooltip:i(R?"image.editor.hideGrid":"image.editor.showGrid"),"data-active":R||void 0}),e(r,{variant:a.OUTLINE,icon:se,display:"compact",onClick:K,tooltip:i("image.editor.reset")})]}),o(l,{direction:"row",gap:"medium",style:{marginTop:"var(--gap-md)"},children:[e(r,{variant:a.OUTLINE,onClick:()=>y(!1),fullWidth:!0,children:i("image.editor.cancel")}),e(r,{variant:a.PRIMARY,icon:ce,onClick:ee,disabled:G,fullWidth:!0,children:i(G?"image.editor.processing":"image.editor.apply")})]})]}):o(l,{gap:"medium",children:[o(l,{direction:"row",gap:"tight",justify:"center",children:[e(r,{variant:a.OUTLINE,icon:W,display:"compact",onClick:j,tooltip:i("image.editor.rotateLeft")}),e(r,{variant:a.PRIMARY,onClick:()=>y(!0),disabled:N,children:i("image.editor.editButton")}),e(r,{variant:a.OUTLINE,icon:M,display:"compact",onClick:F,tooltip:i("image.editor.rotateRight")})]}),$?o(l,{gap:"medium",style:{border:"1px solid var(--destructive)",padding:"var(--gap-md)",borderRadius:"var(--radius-md)"},children:[e(u,{variant:"destructive",level:"small",align:"center",children:i("image.editor.deleteConfirm")}),o(l,{direction:"row",gap:"tight",children:[e(r,{variant:a.OUTLINE,onClick:()=>k(!1),fullWidth:!0,children:i("image.editor.cancel")}),e(r,{variant:a.DESTRUCTIVE,onClick:te,fullWidth:!0,children:i("actions.delete")})]})]}):e(r,{variant:a.GHOST,icon:le,onClick:()=>k(!0),disabled:N,style:{color:"var(--destructive)"},children:i("image.editor.deleteImage")})]})]})})}var Pe=ke;export{ke as ImageViewerDialog,Pe as default};
1
+ "use client";import{jsx as e,Fragment as re,jsxs as a}from"react/jsx-runtime";import{ChevronLeft as le,ChevronRight as ne,RotateCcw as M,RotateCw as H,Trash2 as de,Check as ce,Undo2 as se,ZoomIn as me,ZoomOut as ge,Maximize2 as pe,Grid3X3 as ue}from"lucide-react";import{useCallback as m,useEffect as B,useState as c,useRef as he}from"react";import ve from"react-easy-crop";import{Button as o,BUTTON_VARIANT as r,Sheet as fe,Stack as n,Text as h,Slider as F,ToggleGroup as ye}from"@donotdev/components";import{useTranslation as we}from"@donotdev/core";import{processImage as Ce}from"../../../utils/imageProcessing";import{createPreviewURL as be,revokePreviewURL as ke}from"../../../utils/imageUtils";const xe={free:void 0,"1:1":1,"4:3":4/3,"16:9":16/9,"3:2":3/2};function Y({images:u,selectedIndex:l,open:T,onClose:R,onUpdate:D,onDelete:E,onNavigate:g,multiple:L=!1}){const{t}=we("crud"),[Z,C]=c({x:0,y:0}),[v,p]=c(1),[b,f]=c(0),[N,$]=c(null),[S,z]=c("free"),[k,q]=c(!0),[y,w]=c(!1),[G,P]=c(!1),[X,x]=c(!1),I=he({crop:{x:0,y:0},zoom:1,rotation:0}),d=u[l],U=L&&l>0,O=L&&l<u.length-1;B(()=>{if(d){const i={x:0,y:0};C(i),p(1),f(d.rotation*90),z("free"),w(!1),x(!1),I.current={crop:i,zoom:1,rotation:d.rotation*90}}},[d]);const _=m((i,s)=>{$(s)},[]),J=m(()=>{C(I.current.crop),p(I.current.zoom),f(I.current.rotation)},[]),A=m(()=>{f(i=>(i-90+360)%360)},[]),V=m(()=>{f(i=>(i+90)%360)},[]),K=m(()=>{p(i=>Math.min(i+.25,3))},[]),Q=m(()=>{p(i=>Math.max(i-.25,1))},[]),ee=m(()=>{p(1),C({x:0,y:0})},[]),ie=async()=>{if(!(!d||!N)){P(!0);try{const i=await Ce(d.file,{crop:N,maxWidth:2048,maxHeight:2048,quality:.95}),s=new File([i.fullBlob],d.file.name,{type:"image/webp"}),oe=be(s);d.previewURL.startsWith("blob:")&&ke(d.previewURL),D(l,{file:s,previewURL:oe,uploaded:null,uploadProgress:null,error:null,rotation:0}),w(!1)}catch{}finally{P(!1)}}},te=m(()=>{E(l),x(!1),u.length===1?R():l>=u.length-1&&g(l-1)},[l,u.length,E,R,g]);if(B(()=>{if(!T)return;const i=s=>{s.key==="ArrowLeft"&&U?g(l-1):s.key==="ArrowRight"&&O?g(l+1):s.key==="Escape"&&y&&w(!1)};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[T,U,O,l,g,y]),!d)return null;const W=d.uploadProgress!==null&&d.uploadProgress<100,j=d.uploaded?.fullUrl||d.previewURL,ae=L?t("image.editor.titleWithIndex",{current:l+1,total:u.length}):t("image.editor.title");return e(fe,{open:T,onOpenChange:i=>!i&&R(),side:"right",title:ae,description:t("image.editor.description"),noSwipe:y,children:a(n,{gap:"large",style:{height:"100%"},children:[e("div",{style:{position:"relative",flex:1,minHeight:300,backgroundColor:"var(--surface-muted)",borderRadius:"var(--radius-lg)",overflow:"hidden"},children:y?e(ve,{image:j,crop:Z,zoom:v,rotation:b,aspect:xe[S],onCropChange:C,onCropComplete:_,onZoomChange:p,showGrid:k,style:{containerStyle:{position:"absolute",top:0,left:0,right:0,bottom:0},cropAreaStyle:{border:"2px solid var(--primary)",boxShadow:"0 0 0 9999px rgba(0,0,0,0.5)"}}}):a(re,{children:[U&&e(o,{variant:r.GHOST,icon:le,onClick:()=>g(l-1),"aria-label":t("image.editor.previousImage"),style:{position:"absolute",left:"var(--gap-sm)",top:"50%",transform:"translateY(-50%)",zIndex:10,backgroundColor:"rgba(0,0,0,0.3)",color:"white"}}),e("img",{src:j,alt:`Image ${l+1}`,style:{width:"100%",height:"100%",objectFit:"contain",transform:`rotate(${b}deg)`,transition:"transform var(--dur-normal) var(--ease-out)"}}),O&&e(o,{variant:r.GHOST,icon:ne,onClick:()=>g(l+1),"aria-label":t("image.editor.nextImage"),style:{position:"absolute",right:"var(--gap-sm)",top:"50%",transform:"translateY(-50%)",zIndex:10,backgroundColor:"rgba(0,0,0,0.3)",color:"white"}})]})}),y?a(n,{gap:"medium",children:[a(n,{gap:"tight",children:[e(h,{level:"small",variant:"muted",children:t("image.editor.aspectRatio")}),e(ye,{type:"single",value:S,onValueChange:i=>i&&z(i),items:[{value:"free",label:t("image.editor.aspectFree")},{value:"1:1",label:"1:1"},{value:"4:3",label:"4:3"},{value:"16:9",label:"16:9"}]})]}),a(n,{gap:"tight",children:[a(n,{direction:"row",justify:"between",align:"center",children:[e(h,{level:"small",variant:"muted",children:t("image.editor.zoom")}),a(h,{level:"small",variant:"muted",children:[Math.round(v*100),"%"]})]}),a(n,{direction:"row",gap:"tight",align:"center",children:[e(o,{variant:r.OUTLINE,icon:ge,display:"compact",onClick:Q,disabled:v<=1}),e(F,{value:[v],min:1,max:3,step:.05,onValueChange:i=>p(i[0]??1),style:{flex:1}}),e(o,{variant:r.OUTLINE,icon:me,display:"compact",onClick:K,disabled:v>=3})]})]}),a(n,{gap:"tight",children:[a(n,{direction:"row",justify:"between",align:"center",children:[e(h,{level:"small",variant:"muted",children:t("image.editor.rotation")}),a(h,{level:"small",variant:"muted",children:[b,"\xB0"]})]}),a(n,{direction:"row",gap:"tight",align:"center",children:[e(o,{variant:r.OUTLINE,icon:M,display:"compact",onClick:A,tooltip:t("image.editor.rotateLeft")}),e(F,{value:[b],min:0,max:360,step:1,onValueChange:i=>f(i[0]??0),style:{flex:1}}),e(o,{variant:r.OUTLINE,icon:H,display:"compact",onClick:V,tooltip:t("image.editor.rotateRight")})]})]}),a(n,{direction:"row",gap:"tight",children:[e(o,{variant:r.OUTLINE,icon:pe,display:"compact",onClick:ee,tooltip:t("image.editor.fitToView")}),e(o,{variant:r.OUTLINE,icon:ue,display:"compact",onClick:()=>q(!k),tooltip:t(k?"image.editor.hideGrid":"image.editor.showGrid"),"data-active":k||void 0}),e(o,{variant:r.OUTLINE,icon:se,display:"compact",onClick:J,tooltip:t("image.editor.reset")})]}),a(n,{direction:"row",gap:"medium",style:{marginTop:"var(--gap-md)"},children:[e(o,{variant:r.OUTLINE,onClick:()=>w(!1),fullWidth:!0,children:t("image.editor.cancel")}),e(o,{variant:r.PRIMARY,icon:ce,onClick:ie,disabled:G,fullWidth:!0,children:t(G?"image.editor.processing":"image.editor.apply")})]})]}):a(n,{gap:"medium",children:[a(n,{direction:"row",gap:"tight",justify:"center",children:[e(o,{variant:r.OUTLINE,icon:M,display:"compact",onClick:A,tooltip:t("image.editor.rotateLeft")}),e(o,{variant:r.PRIMARY,onClick:()=>w(!0),disabled:W,children:t("image.editor.editButton")}),e(o,{variant:r.OUTLINE,icon:H,display:"compact",onClick:V,tooltip:t("image.editor.rotateRight")})]}),X?a(n,{gap:"medium",style:{border:"1px solid var(--destructive)",padding:"var(--gap-md)",borderRadius:"var(--radius-md)"},children:[e(h,{variant:"destructive",level:"small",align:"center",children:t("image.editor.deleteConfirm")}),a(n,{direction:"row",gap:"tight",children:[e(o,{variant:r.OUTLINE,onClick:()=>x(!1),fullWidth:!0,children:t("image.editor.cancel")}),e(o,{variant:r.DESTRUCTIVE,onClick:te,fullWidth:!0,children:t("actions.delete")})]})]}):e(o,{variant:r.GHOST,icon:de,onClick:()=>x(!0),disabled:W,style:{color:"var(--destructive)"},children:t("image.editor.deleteImage")})]})]})})}var Ie=Y;export{Y as ImageViewerDialog,Ie as default};
@@ -1 +1 @@
1
- import{default as o}from"./CrudButton";import{FormFieldRenderer as m}from"./FormFieldRenderer";import{DisplayFieldRenderer as a,formatValue as p}from"./DisplayFieldRenderer";import{default as x}from"./FormLayout";export*from"./controlled";export*from"./form";import{EntityFilters as F,matchesFilter as s}from"./EntityFilters";export*from"./fields/display";export{o as CrudButton,a as DisplayFieldRenderer,F as EntityFilters,m as FormFieldRenderer,x as FormLayout,p as formatValue,s as matchesFilter};
1
+ import{default as r}from"./CrudButton";import{FormFieldRenderer as e}from"./FormFieldRenderer";import{DisplayFieldRenderer as a,formatValue as t}from"./DisplayFieldRenderer";import{default as o}from"./FormLayout";export*from"./controlled";export*from"./form";import{EntityFilters as m,matchesFilter as s}from"./EntityFilters";export*from"./fields/display";export{r as CrudButton,a as DisplayFieldRenderer,m as EntityFilters,e as FormFieldRenderer,o as FormLayout,t as formatValue,s as matchesFilter};
@@ -1 +1 @@
1
- "use client";import{jsx as r}from"react/jsx-runtime";import{createContext as n,useContext as i}from"react";const e=n(void 0);function x({formId:t,children:o}){return r(e.Provider,{value:t,children:o})}function p(){return i(e)}export{x as UploadProvider,p as useUploadContext};
1
+ "use client";import{jsx as t}from"react/jsx-runtime";import{createContext as n,useContext as i}from"react";const e=n(void 0);function s({formId:r,children:o}){return t(e.Provider,{value:r,children:o})}function a(){return i(e)}export{s as UploadProvider,a as useUploadContext};
@@ -1 +1 @@
1
- import{UploadProvider as r,useUploadContext as d}from"./UploadContext";export{r as UploadProvider,d as useUploadContext};
1
+ import{UploadProvider as o,useUploadContext as a}from"./UploadContext";export{o as UploadProvider,a as useUploadContext};
@@ -1 +1 @@
1
- "use client";import{getFieldRegistry as i}from"./FieldRegistry";const t=new Map;function p(e){const{type:n,components:r}=e;r&&i().registerComponent(n,r.controlled,r.uncontrolled),t.set(n,e)}function g(e){return t.get(e)}function s(e){return t.get(e)?.filterType}function u(e){return t.get(e)?.displayFormatter}function c(e){return t.get(e)?.filterable??!1}function a(e){return t.get(e)?.valueType}function y(){t.clear()}export{y as clearFieldTypeRegistry,u as getDisplayFormatter,g as getFieldTypeMetadata,s as getFilterType,a as getValueType,c as isFilterable,p as registerBuiltinFieldType};
1
+ "use client";import{getFieldRegistry as i}from"./FieldRegistry";const t=new Map;function a(e){const{type:r,components:n}=e;n&&i().registerComponent(r,n.controlled,n.uncontrolled),t.set(r,e)}function l(e){return t.get(e)}function o(e){return t.get(e)?.filterType}function s(e){return t.get(e)?.displayFormatter}function u(e){return t.get(e)?.filterable??!1}function c(e){return t.get(e)?.valueType}function p(){t.clear()}export{p as clearFieldTypeRegistry,s as getDisplayFormatter,l as getFieldTypeMetadata,o as getFilterType,c as getValueType,u as isFilterable,a as registerBuiltinFieldType};
@@ -1 +1 @@
1
- import{useEntityForm as e}from"./useEntityForm";import{useEntityField as m}from"./useEntityField";import{useController as i}from"./useController";export{i as useController,m as useEntityField,e as useEntityForm};
1
+ import{useEntityForm as t}from"./useEntityForm";import{useEntityField as o}from"./useEntityField";import{useController as r}from"./useController";export{r as useController,o as useEntityField,t as useEntityForm};
@@ -1 +1 @@
1
- "use client";import{useController as e}from"react-hook-form";function t(r){return e(r)}export{t as useController};
1
+ "use client";import{useController as r}from"react-hook-form";function o(e){return r(e)}export{o as useController};
@@ -1 +1 @@
1
- "use client";import{useMemo as s}from"react";import{useController as m}from"./useController";import{isFieldEditable as p}from"../utils";function g(l,e){const{entity:a,operation:o,viewerRole:c,fields:u}=l,r=a.fields[e],t=s(()=>r?{...r,name:r.name||e,label:r.label||e}:{name:e,type:"text",label:e,visibility:"user"},[e,r]),n=s(()=>u.some(f=>f.name===e),[u,e]),b=s(()=>!n||o==="edit"&&t.visibility==="technical"&&t.editable===void 0?!1:p(t.editable,c,o),[n,o,t.visibility,t.editable,c]),{field:d,fieldState:i}=m({name:e,control:l.control}),y=s(()=>({error:i.error?.message,touched:i.isTouched,isDirty:i.isDirty}),[i.error?.message,i.isTouched,i.isDirty]);return{field:d,meta:y,config:t,isEditable:b,isVisible:n}}export{g as useEntityField};
1
+ "use client";import{useMemo as o}from"react";import{useController as y}from"./useController";import{isFieldEditable as p}from"../utils";function v(a,i){const{entity:m,operation:r,viewerRole:n,fields:d}=a,s=m.fields[i],e=o(()=>s?{...s,name:s.name||i,label:s.label||i}:{name:i,type:"text",label:i,visibility:"user"},[i,s]),l=o(()=>d.some(f=>f.name===i),[d,i]),b=o(()=>!l||r==="edit"&&e.visibility==="technical"&&e.editable===void 0?!1:p(e.editable,n,r),[l,r,e.visibility,e.editable,n]),{field:c,fieldState:t}=y({name:i,control:a.control}),u=o(()=>({error:t.error?.message,touched:t.isTouched,isDirty:t.isDirty}),[t.error?.message,t.isTouched,t.isDirty]);return{field:c,meta:u,config:e,isEditable:b,isVisible:l}}export{v as useEntityField};
@@ -1 +1 @@
1
- {"version":3,"file":"useEntityForm.d.ts","sourceRoot":"","sources":["../../../src/forms/hooks/useEntityForm.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAO7C,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EAEjB,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAC5C,MAAM,EAAE,CAAC,EACT,OAAO,GAAE,oBAAoB,CAAC,CAAC,CAAM,GACpC,gBAAgB,CAAC,CAAC,CAAC,CAyerB"}
1
+ {"version":3,"file":"useEntityForm.d.ts","sourceRoot":"","sources":["../../../src/forms/hooks/useEntityForm.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAW7C,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EAEjB,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAC5C,MAAM,EAAE,CAAC,EACT,OAAO,GAAE,oBAAoB,CAAC,CAAC,CAAM,GACpC,gBAAgB,CAAC,CAAC,CAAC,CAmdrB"}
@@ -1 +1 @@
1
- "use client";import{valibotResolver as z}from"@hookform/resolvers/valibot";import{useMemo as p,useEffect as U,useRef as S,useCallback as y}from"react";import{useForm as re,useWatch as se}from"react-hook-form";import{useLocalStorage as ne,BACKEND_GENERATED_FIELD_NAMES as oe,createSchemas as ae}from"@donotdev/core";import{useFormStore as F,useFormStatus as ue,useUploadProgress as ce}from"../../stores";import{useUploadStore as B}from"../../stores/UploadStore";import{checkForBlobUrls as L}from"../../utils/uploadValidation";import{getFieldsForOperation as ie}from"../utils";function ve(i,J={}){const{formId:r,operation:_,defaultValues:c,viewerRole:K,mode:W="onBlur",t:q,autoSave:d=!1}=J,R=K??"guest",o=_??(c?"edit":"create"),G=ue(r??""),H=ce(r??""),g=p(()=>ae(i),[i.name]),I=p(()=>z(g.create),[g.create]),k=p(()=>z(g.draft),[g.draft]),Q=p(()=>async(t,n,e)=>((t?.status??c?.status)==="draft"?k:I)(t,n,e),[I,k,c?.status]),u=p(()=>{if(!c)return c;const t={...c};return Object.entries(i.fields).forEach(([n,e])=>{const s=t[n],l=!(n in c)||s===null||s===void 0;if(e.type==="switch"){if(s==null){const f=e.options?.fieldSpecific;t[n]=f?.uncheckedValue??!1}}else l&&(e.type==="price"?t[n]={amount:0,currency:"EUR",vatIncluded:!0,discountPercent:0}:e.type==="checkbox"||e.type==="boolean"?t[n]=!1:e.type==="text"||e.type==="textarea"||e.type==="email"||e.type==="url"||e.type==="tel"||e.type==="password"||e.type==="color"?t[n]="":(e.type==="number"||e.type==="range"||e.type==="rating")&&(t[n]=void 0))}),t},[c,i.fields]),a=re({defaultValues:u,mode:W,resolver:Q,shouldUnregister:!1,shouldFocusError:!0}),v=S(null);U(()=>{if(o==="edit"&&u){const t=u.id??null;t&&t!==v.current?(a.reset(u),v.current=t):!t&&v.current===null&&(a.reset(u),v.current="initialized")}},[o,u,a]);const X=p(()=>`${i.name.toLowerCase()}-form-draft`,[i.name]),{value:P,setValue:M,removeValue:w}=ne(X,{defaultValue:null,syncAcrossTabs:!0}),E=S(!1);U(()=>{!d||o!=="create"||c||E.current||(P&&a.reset(P),E.current=!0)},[d,o,c,P,a]);const m=se({control:a.control}),V=S(!1),h=S(null),D=S(void 0),T=S(!0);U(()=>{if(T.current){T.current=!1,D.current=m?JSON.stringify(m):void 0;return}if(!d||o!=="create"||V.current||!E.current)return;const t=m?JSON.stringify(m):void 0;if(D.current!==t)return D.current=t,h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{if(!m)return;Object.values(m).some(e=>e!=null&&e!=="")&&M(m)},3e3),()=>{h.current&&clearTimeout(h.current)}},[m,d,o,M]);const j=y(async()=>{if(!r)return!0;const t=B.getState(),n=F.getState();if(!t.hasPendingUploads(r))return!0;try{n.setUploading(r,0),await t.uploadAll(r),await new Promise(f=>setTimeout(f,50));let e=a.getValues(),s=L(e),b=0;const l=5;for(;s.length>0&&b<l;)b++,await new Promise(f=>setTimeout(f,100)),e=a.getValues(),s=L(e);if(s.length>0){const f=`Upload incomplete: files still pending at ${s.join(", ")}`;return n.setError(r,f),!1}return!0}catch(e){const s=e instanceof Error?e.message:"File upload failed";return F.getState().setError(r,s),!1}},[r,a]),x=y(t=>o!=="create"?t:Object.fromEntries(Object.entries(t).filter(([n])=>!oe.includes(n))),[o]),A=y(t=>{if(typeof window>"u")return;const n=Object.keys(t).find(s=>s!=="root"&&t[s]);if(!n)return;const e=document.querySelector(`input[name="${n}"][aria-invalid="true"], textarea[name="${n}"][aria-invalid="true"], select[name="${n}"][aria-invalid="true"]`);e&&(e.scrollIntoView({behavior:"smooth",block:"center"}),e.focus())},[]),$=a.handleSubmit,Y=p(()=>((t,n)=>async e=>{e?.preventDefault?.();const s=r?F.getState():null;r&&s&&s.startSubmit(r),V.current=!0;try{if(!await j()){V.current=!1;return}r&&s&&s.setValidating(r),await $(async(l,f)=>{r&&s&&s.setSubmitting(r);const ee=x(l);try{await t(ee,f),d&&o==="create"&&w(),r&&s&&s.setSuccess(r)}catch(O){const te=O instanceof Error?O.message:"Submission failed";throw r&&s&&s.setError(r,te),O}},l=>{r&&s&&s.setError(r,"Validation failed"),A(l),n?.(l)})(e)}finally{V.current=!1}}),[$,r,j,x,A,d,o,w]),Z=y(()=>{d&&o==="create"&&w(),a.reset(u),D.current=u?JSON.stringify(u):void 0,T.current=!0,E.current=!1},[d,o,w,a,u]),N=y(()=>{r&&(F.getState().cleanup(r),B.getState().cleanup(r))},[r]),C=p(()=>ie(i,{operation:o,viewerRole:R,availableFields:void 0}),[i,o,R]);return{...a,handleSubmit:Y,fields:C,operation:o,entity:i,t:q??(t=>t),viewerRole:R,formId:r,formStatus:r?G:"idle",uploadProgress:r?H:0,cleanup:N,isDirty:a.formState.isDirty,resetForm:Z,originalValues:u}}export{ve as useEntityForm};
1
+ "use client";import{valibotResolver as C}from"@hookform/resolvers/valibot";import{useMemo as c,useEffect as R,useRef as p,useCallback as h}from"react";import{useForm as ue,useWatch as ie}from"react-hook-form";import{useLocalStorage as ce,BACKEND_GENERATED_FIELD_NAMES as le,createSchemas as fe}from"@donotdev/core";import{useFormStore as y,useFormStatus as de,useUploadProgress as me}from"../../stores";import{useUploadStore as J}from"../../stores/UploadStore";import{checkForBlobUrls as _}from"../../utils/uploadValidation";import{getFieldsForOperation as pe}from"../utils";import{buildInitialFromRecord as Se,buildSchemaDefaults as ge}from"../utils/buildInitialValues";function Pe(u,z={}){const{formId:e,operation:K,defaultValues:S,viewerRole:W,mode:q="onBlur",t:G,autoSave:l=!1}=z,P=W??"guest",o=K??(S?"edit":"create"),H=de(e??""),Q=me(e??""),b=c(()=>fe(u),[u.name]),j=c(()=>C(b.create),[b.create]),k=c(()=>C(b.draft),[b.draft]),X=c(()=>async(t,a,s)=>((t?.status??S?.status)==="draft"?k:j)(t,a,s),[j,k,S?.status]),A=c(()=>ge(u),[u]),T=S,i=c(()=>{if(o==="create")return A;if(T)return Se(u,T)},[o,A,u,T]),n=ue({defaultValues:o==="create"?i:void 0,mode:q,resolver:X,shouldUnregister:!1,shouldFocusError:!0}),O=p(n);R(()=>{O.current=n},[n]);const v=p(null);R(()=>{if(o==="edit"&&i){const t=i.id??null;t&&t!==v.current?(O.current.reset(i),v.current=t):!t&&v.current===null&&(O.current.reset(i),v.current="initialized")}},[o,i]);const Y=c(()=>`${u.name.toLowerCase()}-form-draft`,[u.name]),{value:I,setValue:N,removeValue:F}=ce(Y,{defaultValue:null,syncAcrossTabs:!0}),w=p(!1);R(()=>{!l||o!=="create"||S||w.current||(I&&n.reset(I),w.current=!0)},[l,o,S,I,n]);const f=ie({control:n.control}),D=p(!1),g=p(null),V=p(void 0),U=p(!0);R(()=>{if(U.current){U.current=!1,V.current=f?JSON.stringify(f):void 0;return}if(!l||o!=="create"||D.current||!w.current)return;const t=f?JSON.stringify(f):void 0;if(V.current!==t)return V.current=t,g.current&&clearTimeout(g.current),g.current=setTimeout(()=>{if(!f)return;Object.values(f).some(s=>s!=null&&s!=="")&&N(f)},3e3),()=>{g.current&&clearTimeout(g.current)}},[f,l,o,N]);const $=h(async()=>{if(!e)return!0;const t=J.getState(),a=y.getState();if(!t.hasPendingUploads(e))return!0;try{a.setUploading(e,0),await t.uploadAll(e),await new Promise(m=>setTimeout(m,50));let s=n.getValues(),r=_(s),E=0;const d=5;for(;r.length>0&&E<d;)E++,await new Promise(m=>setTimeout(m,100)),s=n.getValues(),r=_(s);if(r.length>0){const m=`Upload incomplete: files still pending at ${r.join(", ")}`;return a.setError(e,m),!1}return!0}catch(s){const r=s instanceof Error?s.message:"File upload failed";return y.getState().setError(e,r),!1}},[e,n]),B=h(t=>o!=="create"?t:Object.fromEntries(Object.entries(t).filter(([a])=>!le.includes(a))),[o]),L=h(t=>{if(typeof window>"u")return;const a=Object.keys(t).find(r=>r!=="root"&&t[r]);if(!a)return;const s=document.querySelector(`input[name="${a}"][aria-invalid="true"], textarea[name="${a}"][aria-invalid="true"], select[name="${a}"][aria-invalid="true"]`);s&&(s.scrollIntoView({behavior:"smooth",block:"center"}),s.focus())},[]),x=n.handleSubmit,Z=c(()=>((t,a)=>async s=>{s?.preventDefault?.();const r=e?y.getState():null;e&&r&&r.startSubmit(e),D.current=!0;try{if(!await $()){D.current=!1;return}e&&r&&r.setValidating(e),await x(async(d,m)=>{e&&r&&r.setSubmitting(e);const ne=B(d);try{await t(ne,m),l&&o==="create"&&F(),e&&r&&r.setSuccess(e)}catch(M){const ae=M instanceof Error?M.message:"Submission failed";throw e&&r&&r.setError(e,ae),M}},d=>{e&&r&&r.setError(e,"Validation failed"),L(d),a?.(d)})(s)}finally{D.current=!1}}),[x,e,$,B,L,l,o,F]),ee=h(()=>{l&&o==="create"&&F(),n.reset(i),V.current=i?JSON.stringify(i):void 0,U.current=!0,w.current=!1},[l,o,F,n,i]),te=h(()=>{e&&(y.getState().cleanup(e),J.getState().cleanup(e))},[e]),re=c(()=>pe(u,{operation:o,viewerRole:P,availableFields:void 0}),[u,o,P]),se=G??(t=>t),oe=n.formState.isSubmitted||Object.keys(n.formState.touchedFields||{}).length>0;return{...n,handleSubmit:Z,fields:re,operation:o,entity:u,t:se,viewerRole:P,formId:e,formStatus:e?H:"idle",uploadProgress:e?Q:0,cleanup:te,isDirty:n.formState.isDirty,hasUserInteracted:oe,resetForm:ee,originalValues:i}}export{Pe as useEntityForm};