@donotdev/crud 0.0.7 → 0.0.9

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 (184) hide show
  1. package/dist/CrudService.d.ts +6 -54
  2. package/dist/CrudService.d.ts.map +1 -1
  3. package/dist/CrudService.js +1 -1
  4. package/dist/CrudStore.d.ts +1 -94
  5. package/dist/CrudStore.d.ts.map +1 -1
  6. package/dist/adapters/FirestoreAdapter.d.ts +3 -1
  7. package/dist/adapters/FirestoreAdapter.d.ts.map +1 -1
  8. package/dist/adapters/FirestoreAdapter.js +1 -1
  9. package/dist/adapters/FunctionsAdapter.d.ts +8 -1
  10. package/dist/adapters/FunctionsAdapter.d.ts.map +1 -1
  11. package/dist/adapters/FunctionsAdapter.js +1 -1
  12. package/dist/builtinFieldTypes.d.ts.map +1 -1
  13. package/dist/builtinFieldTypes.js +1 -1
  14. package/dist/components/EntityCardList.d.ts +5 -3
  15. package/dist/components/EntityCardList.d.ts.map +1 -1
  16. package/dist/components/EntityCardList.js +1 -1
  17. package/dist/components/EntityDisplayRenderer.d.ts +3 -3
  18. package/dist/components/EntityDisplayRenderer.d.ts.map +1 -1
  19. package/dist/components/EntityDisplayRenderer.js +1 -1
  20. package/dist/components/EntityFilters.d.ts +43 -0
  21. package/dist/components/EntityFilters.d.ts.map +1 -0
  22. package/dist/components/EntityFilters.js +1 -0
  23. package/dist/components/EntityFormRenderer.d.ts +22 -1
  24. package/dist/components/EntityFormRenderer.d.ts.map +1 -1
  25. package/dist/components/EntityFormRenderer.js +1 -1
  26. package/dist/components/EntityList.d.ts +12 -6
  27. package/dist/components/EntityList.d.ts.map +1 -1
  28. package/dist/components/EntityList.js +1 -1
  29. package/dist/components/FormFieldRenderer.d.ts.map +1 -1
  30. package/dist/components/controlled/complex/ControlledAddressField.d.ts +3 -0
  31. package/dist/components/controlled/complex/ControlledAddressField.d.ts.map +1 -1
  32. package/dist/components/controlled/complex/ControlledDateField.d.ts +3 -0
  33. package/dist/components/controlled/complex/ControlledDateField.d.ts.map +1 -1
  34. package/dist/components/controlled/complex/ControlledGeoPointField.d.ts +3 -0
  35. package/dist/components/controlled/complex/ControlledGeoPointField.d.ts.map +1 -1
  36. package/dist/components/controlled/complex/ControlledMapField.d.ts +3 -0
  37. package/dist/components/controlled/complex/ControlledMapField.d.ts.map +1 -1
  38. package/dist/components/controlled/complex/ControlledMultiInputField.d.ts +3 -0
  39. package/dist/components/controlled/complex/ControlledMultiInputField.d.ts.map +1 -1
  40. package/dist/components/controlled/complex/ControlledRichTextField.d.ts +3 -0
  41. package/dist/components/controlled/complex/ControlledRichTextField.d.ts.map +1 -1
  42. package/dist/components/controlled/complex/ControlledTimestampField.d.ts +3 -0
  43. package/dist/components/controlled/complex/ControlledTimestampField.d.ts.map +1 -1
  44. package/dist/components/controlled/complex/index.d.ts.map +1 -1
  45. package/dist/components/controlled/file/ControlledDocumentField.d.ts +3 -0
  46. package/dist/components/controlled/file/ControlledDocumentField.d.ts.map +1 -1
  47. package/dist/components/controlled/file/ControlledFileField.d.ts +3 -0
  48. package/dist/components/controlled/file/ControlledFileField.d.ts.map +1 -1
  49. package/dist/components/controlled/file/ControlledImageField.d.ts +3 -0
  50. package/dist/components/controlled/file/ControlledImageField.d.ts.map +1 -1
  51. package/dist/components/controlled/file/ControlledMultiDocumentField.d.ts +3 -0
  52. package/dist/components/controlled/file/ControlledMultiDocumentField.d.ts.map +1 -1
  53. package/dist/components/controlled/file/ControlledMultiFileField.d.ts +3 -0
  54. package/dist/components/controlled/file/ControlledMultiFileField.d.ts.map +1 -1
  55. package/dist/components/controlled/file/ControlledMultiImageField.d.ts +3 -0
  56. package/dist/components/controlled/file/ControlledMultiImageField.d.ts.map +1 -1
  57. package/dist/components/controlled/file/index.d.ts.map +1 -1
  58. package/dist/components/controlled/index.d.ts +4 -0
  59. package/dist/components/controlled/index.d.ts.map +1 -1
  60. package/dist/components/controlled/input/ControlledCheckboxField.d.ts +3 -0
  61. package/dist/components/controlled/input/ControlledCheckboxField.d.ts.map +1 -1
  62. package/dist/components/controlled/input/ControlledCheckboxField.js +1 -1
  63. package/dist/components/controlled/input/ControlledGdprConsentField.d.ts +8 -0
  64. package/dist/components/controlled/input/ControlledGdprConsentField.d.ts.map +1 -0
  65. package/dist/components/controlled/input/ControlledGdprConsentField.js +1 -0
  66. package/dist/components/controlled/input/ControlledNumberField.d.ts +3 -0
  67. package/dist/components/controlled/input/ControlledNumberField.d.ts.map +1 -1
  68. package/dist/components/controlled/input/ControlledPasswordField.d.ts +3 -0
  69. package/dist/components/controlled/input/ControlledPasswordField.d.ts.map +1 -1
  70. package/dist/components/controlled/input/ControlledPhoneField.d.ts +3 -0
  71. package/dist/components/controlled/input/ControlledPhoneField.d.ts.map +1 -1
  72. package/dist/components/controlled/input/ControlledRangeField.d.ts +3 -0
  73. package/dist/components/controlled/input/ControlledRangeField.d.ts.map +1 -1
  74. package/dist/components/controlled/input/ControlledSwitchField.d.ts +3 -0
  75. package/dist/components/controlled/input/ControlledSwitchField.d.ts.map +1 -1
  76. package/dist/components/controlled/input/ControlledTextField.d.ts +3 -0
  77. package/dist/components/controlled/input/ControlledTextField.d.ts.map +1 -1
  78. package/dist/components/controlled/input/ControlledTextareaField.d.ts +3 -0
  79. package/dist/components/controlled/input/ControlledTextareaField.d.ts.map +1 -1
  80. package/dist/components/controlled/input/index.d.ts +1 -0
  81. package/dist/components/controlled/input/index.d.ts.map +1 -1
  82. package/dist/components/controlled/input/index.js +1 -1
  83. package/dist/components/controlled/select/ControlledComboboxField.d.ts +4 -0
  84. package/dist/components/controlled/select/ControlledComboboxField.d.ts.map +1 -1
  85. package/dist/components/controlled/select/ControlledDropdownField.d.ts +4 -0
  86. package/dist/components/controlled/select/ControlledDropdownField.d.ts.map +1 -1
  87. package/dist/components/controlled/select/ControlledMultiDropdownField.d.ts +4 -0
  88. package/dist/components/controlled/select/ControlledMultiDropdownField.d.ts.map +1 -1
  89. package/dist/components/controlled/select/ControlledRadioField.d.ts +4 -0
  90. package/dist/components/controlled/select/ControlledRadioField.d.ts.map +1 -1
  91. package/dist/components/controlled/select/ControlledYearField.d.ts +9 -0
  92. package/dist/components/controlled/select/ControlledYearField.d.ts.map +1 -0
  93. package/dist/components/controlled/select/ControlledYearField.js +1 -0
  94. package/dist/components/controlled/select/index.d.ts +1 -0
  95. package/dist/components/controlled/select/index.d.ts.map +1 -1
  96. package/dist/components/controlled/select/index.js +1 -1
  97. package/dist/components/controlled/types.d.ts +6 -0
  98. package/dist/components/controlled/types.d.ts.map +1 -1
  99. package/dist/components/form/fields/CheckboxFieldComponent.d.ts +3 -3
  100. package/dist/components/form/fields/CheckboxFieldComponent.d.ts.map +1 -1
  101. package/dist/components/form/fields/DocumentFieldComponent.d.ts.map +1 -1
  102. package/dist/components/form/fields/FileFieldComponent.d.ts.map +1 -1
  103. package/dist/components/form/fields/GdprConsentFieldComponent.d.ts +26 -0
  104. package/dist/components/form/fields/GdprConsentFieldComponent.d.ts.map +1 -0
  105. package/dist/components/form/fields/GdprConsentFieldComponent.js +1 -0
  106. package/dist/components/form/fields/ImageFieldComponent.d.ts +4 -3
  107. package/dist/components/form/fields/ImageFieldComponent.d.ts.map +1 -1
  108. package/dist/components/form/fields/ImageFieldComponent.js +1 -1
  109. package/dist/components/form/fields/PhoneNumberComponent.d.ts.map +1 -1
  110. package/dist/components/form/fields/PhoneNumberComponent.js +1 -1
  111. package/dist/components/form/fields/RichTextComponent.d.ts +2 -21
  112. package/dist/components/form/fields/RichTextComponent.d.ts.map +1 -1
  113. package/dist/components/form/fields/TextAreaComponent.d.ts.map +1 -1
  114. package/dist/components/form/fields/TextAreaComponent.js +1 -1
  115. package/dist/components/form/fields/index.d.ts +3 -1
  116. package/dist/components/form/fields/index.d.ts.map +1 -1
  117. package/dist/components/form/fields/index.js +1 -1
  118. package/dist/components/form/fields/internal/TiptapEditor.d.ts +1 -1
  119. package/dist/components/form/fields/internal/TiptapEditor.d.ts.map +1 -1
  120. package/dist/components/form/fields/types.d.ts +33 -0
  121. package/dist/components/form/fields/types.d.ts.map +1 -0
  122. package/dist/components/form/fields/types.js +0 -0
  123. package/dist/components/form/internal/ImageViewerDialog.d.ts +2 -1
  124. package/dist/components/form/internal/ImageViewerDialog.d.ts.map +1 -1
  125. package/dist/components/form/internal/ImageViewerDialog.js +1 -1
  126. package/dist/components/index.d.ts +2 -0
  127. package/dist/components/index.d.ts.map +1 -1
  128. package/dist/components/index.js +1 -1
  129. package/dist/contexts/UploadContext.d.ts.map +1 -1
  130. package/dist/forms/hooks/useEntityForm.d.ts.map +1 -1
  131. package/dist/forms/hooks/useEntityForm.js +1 -1
  132. package/dist/forms/index.d.ts +2 -2
  133. package/dist/forms/index.d.ts.map +1 -1
  134. package/dist/forms/index.js +1 -1
  135. package/dist/forms/types.d.ts +15 -0
  136. package/dist/forms/types.d.ts.map +1 -1
  137. package/dist/forms/utils/index.d.ts +0 -2
  138. package/dist/forms/utils/index.d.ts.map +1 -1
  139. package/dist/forms/utils/index.js +1 -1
  140. package/dist/forms/utils/validateEntity.js +1 -1
  141. package/dist/hooks/useFileUpload.d.ts +1 -1
  142. package/dist/hooks/useFileUpload.d.ts.map +1 -1
  143. package/dist/hooks/useFileUpload.js +1 -1
  144. package/dist/hooks/useFormNavigationGuard.d.ts +34 -0
  145. package/dist/hooks/useFormNavigationGuard.d.ts.map +1 -0
  146. package/dist/hooks/useFormNavigationGuard.js +1 -0
  147. package/dist/hooks/useUnsavedChangesWarning.d.ts +51 -0
  148. package/dist/hooks/useUnsavedChangesWarning.d.ts.map +1 -0
  149. package/dist/hooks/useUnsavedChangesWarning.js +1 -0
  150. package/dist/index.d.ts +6 -4
  151. package/dist/index.d.ts.map +1 -1
  152. package/dist/index.js +1 -1
  153. package/dist/stores/FormStore.d.ts +17 -0
  154. package/dist/stores/FormStore.d.ts.map +1 -1
  155. package/dist/stores/FormStore.js +1 -1
  156. package/dist/stores/index.d.ts +1 -1
  157. package/dist/stores/index.d.ts.map +1 -1
  158. package/dist/stores/index.js +1 -1
  159. package/dist/tsconfig.tsbuildinfo +1 -1
  160. package/dist/types.d.ts +167 -0
  161. package/dist/types.d.ts.map +1 -0
  162. package/dist/types.js +0 -0
  163. package/dist/useCrud.d.ts +1 -2
  164. package/dist/useCrud.d.ts.map +1 -1
  165. package/dist/useCrud.js +1 -1
  166. package/dist/useCrudCardList.d.ts.map +1 -1
  167. package/dist/useCrudCardList.js +1 -1
  168. package/dist/useCrudList.d.ts +7 -0
  169. package/dist/useCrudList.d.ts.map +1 -1
  170. package/dist/useCrudList.js +1 -1
  171. package/dist/utils/fileStorage.d.ts +1 -1
  172. package/dist/utils/fileStorage.d.ts.map +1 -1
  173. package/dist/utils/imageStorage.d.ts +1 -1
  174. package/dist/utils/imageStorage.d.ts.map +1 -1
  175. package/dist/utils/imageUtils.d.ts +1 -1
  176. package/dist/utils/imageUtils.d.ts.map +1 -1
  177. package/dist/utils/mergeWithOptimistic.d.ts +1 -1
  178. package/dist/utils/mergeWithOptimistic.d.ts.map +1 -1
  179. package/dist/utils/uploadValidation.d.ts +1 -1
  180. package/dist/utils/uploadValidation.d.ts.map +1 -1
  181. package/package.json +17 -11
  182. package/dist/forms/utils/optionHelpers.d.ts +0 -54
  183. package/dist/forms/utils/optionHelpers.d.ts.map +0 -1
  184. package/dist/forms/utils/optionHelpers.js +0 -1
@@ -1 +1 @@
1
- "use client";import{jsx as e,Fragment as Y,jsxs as a}from"react/jsx-runtime";import{ChevronLeft as Z,ChevronRight as q,RotateCw as J,Trash2 as K,Crop as Q,Eye as X,Save as ee,Undo2 as te}from"lucide-react";import{useCallback as O,useEffect as ae,useState as c}from"react";import ie from"react-easy-crop";import{Button as l,BUTTON_VARIANT as s,Dialog as oe,Stack as r,Text as T,Input as V,Label as f,Slider as F,Tabs as re}from"@donotdev/components";import{processImage as ne}from"../../../utils/imageProcessing";import{createPreviewURL as le,revokePreviewURL as se}from"../../../utils/imageUtils";function ce({images:n,selectedIndex:i,open:N,onClose:C,onUpdate:A,onDelete:U,onNavigate:p,multiple:d=!1}){const[R,m]=c("view"),[j,x]=c({x:0,y:0}),[P,b]=c(1),[u,h]=c(0),[k,z]=c(null),[L,$]=c(!1),[w,S]=c({alt:"",caption:""}),[B,v]=c(!1),o=n[i],H=d&&i>0,W=d&&i<n.length-1;ae(()=>{o&&(x({x:0,y:0}),b(1),h(o.rotation*90),S({alt:"",caption:""}),m("view"),v(!1))},[o]);const D=(t,g)=>{S(y=>({...y,[t]:g}))},G=O((t,g)=>{z(g)},[]),M=async()=>{if(!(!o||!k)){$(!0);try{const t=await ne(o.file,{crop:k,maxWidth:2048,maxHeight:2048,quality:.95}),g=new File([t.fullBlob],o.file.name,{type:"image/webp"}),y=le(g);A(i,{file:g,previewURL:y,uploaded:null,uploadProgress:null,error:null,rotation:0}),o.previewURL.startsWith("blob:")&&se(o.previewURL),m("view")}catch{}finally{$(!1)}}},_=O(()=>{U(i),v(!1),n.length===1?C():i>=n.length-1&&p(i-1)},[i,n.length,U,C,p]);if(!o)return null;const E=o.uploadProgress!==null&&o.uploadProgress<100,I=o.previewURL||o.uploaded?.fullUrl;return e(oe,{open:N,onOpenChange:t=>!t&&C(),title:d?`Image ${i+1} of ${n.length}`:"Image Details",description:d?`View, edit, and manage image ${i+1} of ${n.length}. Use the tabs to view metadata or edit the image with crop and rotation tools.`:"View, edit, and manage this image. Use the tabs to view metadata or edit the image with crop and rotation tools.",showClose:!0,children:a("div",{style:{display:"grid",gridTemplateColumns:"1fr 300px",gap:"var(--gap-lg)",height:"60vh",minHeight:"500px"},children:[e("div",{style:{position:"relative",backgroundColor:"var(--surface-muted)",borderRadius:"var(--radius-lg)",overflow:"hidden",display:"flex",alignItems:"center",justifyContent:"center"},children:R==="edit"?e("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0},children:e(ie,{image:I,crop:j,zoom:P,rotation:u,onCropChange:x,onCropComplete:G,onZoomChange:b,onRotationChange:h})}):a(Y,{children:[H&&e(l,{variant:s.GHOST,icon:Z,onClick:()=>p(i-1),"aria-label":"Previous image",style:{position:"absolute",left:"var(--gap-sm)",zIndex:10,backgroundColor:"rgba(0,0,0,0.3)",color:"white",border:"none"}}),e("img",{src:I,alt:w.alt||o.file.name||`Image ${i+1}${d?` of ${n.length}`:""}`,loading:"eager",decoding:"async",fetchPriority:"high",style:{maxWidth:"100%",maxHeight:"100%",objectFit:"contain",transform:`rotate(${u}deg)`},"aria-label":`Image ${i+1}${d?` of ${n.length}`:""}`}),W&&e(l,{variant:s.GHOST,icon:q,onClick:()=>p(i+1),"aria-label":"Next image",style:{position:"absolute",right:"var(--gap-sm)",zIndex:10,backgroundColor:"rgba(0,0,0,0.3)",color:"white",border:"none"}})]})}),e(r,{gap:"large",style:{overflowY:"auto",height:"100%"},children:e(re,{value:R,onValueChange:t=>m(t),items:[{value:"view",label:a(r,{direction:"row",align:"center",gap:"tight",children:[e(X,{className:"dndev-size-sm"}),e(T,{children:"View"})]}),content:a(r,{gap:"medium",style:{paddingTop:"var(--gap-md)"},children:[a(r,{gap:"tight",children:[e(f,{htmlFor:"img-alt",children:"Alt Text (Accessibility)"}),e(V,{id:"img-alt",value:w.alt,onChange:t=>D("alt",t.target.value),placeholder:"Describe the image..."})]}),a(r,{gap:"tight",children:[e(f,{htmlFor:"img-caption",children:"Caption"}),e(V,{id:"img-caption",value:w.caption,onChange:t=>D("caption",t.target.value),placeholder:"Image caption or credits"})]}),e("div",{style:{marginTop:"auto",paddingTop:"var(--gap-lg)"},children:B?a(r,{gap:"medium",style:{border:"1px solid var(--destructive)",padding:"var(--gap-md)",borderRadius:"var(--radius-md)"},children:[e(T,{variant:"destructive",level:"small",children:"Permanently delete this image?"}),a(r,{direction:"row",gap:"tight",children:[e(l,{variant:s.DESTRUCTIVE,onClick:_,fullWidth:!0,children:"Yes, Delete"}),e(l,{variant:s.OUTLINE,onClick:()=>v(!1),fullWidth:!0,children:"Cancel"})]})]}):e(l,{variant:s.OUTLINE,className:"text-destructive hover:bg-destructive/10",icon:K,onClick:()=>v(!0),fullWidth:!0,disabled:E,children:"Delete Image"})})]})},{value:"edit",label:a(r,{direction:"row",align:"center",gap:"tight",children:[e(Q,{className:"dndev-size-sm"}),e(T,{children:"Edit"})]}),disabled:E,content:a(r,{gap:"medium",style:{paddingTop:"var(--gap-md)"},children:[a(r,{gap:"tight",children:[e(f,{children:"Zoom"}),e(F,{value:[P],min:1,max:3,step:.1,onValueChange:t=>b(t[0]??1)})]}),a(r,{gap:"tight",children:[a(f,{children:["Rotation (",u,"\xB0)"]}),a(r,{direction:"row",gap:"tight",children:[e(l,{variant:s.OUTLINE,onClick:()=>h(t=>t-90),icon:te,title:"-90\xB0"}),e(F,{value:[u],min:0,max:360,step:90,onValueChange:t=>h(t[0]??0),style:{flex:1}}),e(l,{variant:s.OUTLINE,onClick:()=>h(t=>t+90),icon:J,title:"+90\xB0"})]})]}),a(r,{gap:"medium",style:{marginTop:"var(--gap-xl)"},children:[e(l,{variant:s.PRIMARY,onClick:M,disabled:L,icon:ee,children:L?"Processing...":"Save Changes"}),e(l,{variant:s.GHOST,onClick:()=>m("view"),children:"Cancel"})]})]})}]})})]})})}var fe=ce;export{ce as ImageViewerDialog,fe as default};
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};
@@ -21,4 +21,6 @@ export { EntityList } from './EntityList';
21
21
  export type { EntityListProps } from './EntityList';
22
22
  export { EntityCardList } from './EntityCardList';
23
23
  export type { EntityCardListProps } from './EntityCardList';
24
+ export { EntityFilters } from './EntityFilters';
25
+ export type { EntityFiltersProps } from './EntityFilters';
24
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,YAAY,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,YAAY,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1 +1 @@
1
- import{default as o}from"./CrudButton";import{EntityFormRenderer as m}from"./EntityFormRenderer";import{FormFieldRenderer as p}from"./FormFieldRenderer";import{DisplayFieldRenderer as i}from"./DisplayFieldRenderer";import{EntityDisplayRenderer as n}from"./EntityDisplayRenderer";import{default as y}from"./FormLayout";export*from"./controlled";export*from"./form";import{EntityList as F}from"./EntityList";import{EntityCardList as R}from"./EntityCardList";export{o as CrudButton,i as DisplayFieldRenderer,R as EntityCardList,n as EntityDisplayRenderer,m as EntityFormRenderer,F as EntityList,p as FormFieldRenderer,y as FormLayout};
1
+ import{default as e}from"./CrudButton";import{EntityFormRenderer as m}from"./EntityFormRenderer";import{FormFieldRenderer as p}from"./FormFieldRenderer";import{DisplayFieldRenderer as x}from"./DisplayFieldRenderer";import{EntityDisplayRenderer as n}from"./EntityDisplayRenderer";import{default as y}from"./FormLayout";export*from"./controlled";export*from"./form";import{EntityList as u}from"./EntityList";import{EntityCardList as R}from"./EntityCardList";import{EntityFilters as C}from"./EntityFilters";export{e as CrudButton,x as DisplayFieldRenderer,R as EntityCardList,n as EntityDisplayRenderer,C as EntityFilters,m as EntityFormRenderer,u as EntityList,p as FormFieldRenderer,y as FormLayout};
@@ -1 +1 @@
1
- {"version":3,"file":"UploadContext.d.ts","sourceRoot":"","sources":["../../src/contexts/UploadContext.tsx"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKvC,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,mBAAmB,2CAMvE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,SAAS,CAErD"}
1
+ {"version":3,"file":"UploadContext.d.ts","sourceRoot":"","sources":["../../src/contexts/UploadContext.tsx"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKvC,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,mBAAmB,2CAIvE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,SAAS,CAErD"}
@@ -1 +1 @@
1
- {"version":3,"file":"useEntityForm.d.ts","sourceRoot":"","sources":["../../../src/forms/hooks/useEntityForm.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAQ7C,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,CAiarB"}
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,CAwcrB"}
@@ -1 +1 @@
1
- "use client";import{valibotResolver as B}from"@hookform/resolvers/valibot";import{useMemo as l,useEffect as O,useRef as g,useCallback as w}from"react";import{useForm as ee,useWatch as te}from"react-hook-form";import{useLocalStorage as re,BACKEND_GENERATED_FIELD_NAMES as se}from"@donotdev/core";import{createSchemas as oe}from"@donotdev/schemas";import{useFormStore as V,useFormStatus as ne,useUploadProgress as ae}from"../../stores";import{useUploadStore as L}from"../../stores/UploadStore";import{checkForBlobUrls as x}from"../../utils/uploadValidation";import{getFieldsForOperation as ue}from"../utils";function ve(i,N={}){const{formId:e,operation:_,defaultValues:a,viewerRole:F="admin",mode:C="onBlur",t:J,autoSave:m=!1}=N,n=_??(a?"edit":"create"),K=ne(e??""),W=ae(e??""),b=l(()=>oe(i),[i.name]),P=l(()=>B(b.create),[b.create]),U=l(()=>B(b.draft),[b.draft]),q=l(()=>async(t,o,s)=>((t?.status??a?.status)==="draft"?U:P)(t,o,s),[P,U,a?.status]),p=l(()=>{if(!a)return a;const t={...a};return Object.entries(i.fields).forEach(([o,s])=>{if(s.type==="switch"){const r=t[o];if(r==null){const S=s.options?.fieldSpecific;t[o]=S?.uncheckedValue??!1}}}),t},[a,i.fields]),u=ee({defaultValues:p,mode:C,resolver:q,shouldUnregister:!1,shouldFocusError:!0}),v=g(null);O(()=>{if(n==="edit"&&p){const t=p.id??null;t&&t!==v.current?(u.reset(p),v.current=t):!t&&v.current===null&&(u.reset(p),v.current="initialized")}},[n,p,u]);const G=l(()=>`${i.name.toLowerCase()}-form-draft`,[i.name]),{value:D,setValue:j,removeValue:k}=re(G,{defaultValue:null,syncAcrossTabs:!0}),R=g(!1);O(()=>{!m||n!=="create"||a||R.current||(D&&u.reset(D),R.current=!0)},[m,n,a,D,u]);const c=te({control:u.control}),E=g(!1),h=g(null),y=g(void 0),I=g(!0);O(()=>{if(I.current){I.current=!1,y.current=c?JSON.stringify(c):void 0;return}if(!m||n!=="create"||E.current||!R.current)return;const t=c?JSON.stringify(c):void 0;if(y.current!==t)return y.current=t,h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{if(!c)return;Object.values(c).some(s=>s!=null&&s!=="")&&j(c)},3e3),()=>{h.current&&clearTimeout(h.current)}},[c,m,n,j]);const M=w(async()=>{if(!e)return!0;const t=L.getState(),o=V.getState();if(!t.hasPendingUploads(e))return!0;try{o.setUploading(e,0),await t.uploadAll(e),await new Promise(d=>setTimeout(d,50));let s=u.getValues(),r=x(s),S=0;const f=5;for(;r.length>0&&S<f;)S++,await new Promise(d=>setTimeout(d,100)),s=u.getValues(),r=x(s);if(r.length>0){const d=`Upload incomplete: files still pending at ${r.join(", ")}`;return o.setError(e,d),!1}return!0}catch(s){const r=s instanceof Error?s.message:"File upload failed";return V.getState().setError(e,r),!1}},[e,u]),A=w(t=>n!=="create"?t:Object.fromEntries(Object.entries(t).filter(([o])=>!se.includes(o))),[n]),$=w(t=>{if(typeof window>"u")return;const o=Object.keys(t).find(r=>r!=="root"&&t[r]);if(!o)return;const s=document.querySelector(`input[name="${o}"][aria-invalid="true"], textarea[name="${o}"][aria-invalid="true"], select[name="${o}"][aria-invalid="true"]`);s&&(s.scrollIntoView({behavior:"smooth",block:"center"}),s.focus())},[]),z=u.handleSubmit,H=l(()=>((t,o)=>async s=>{s?.preventDefault?.();const r=e?V.getState():null;e&&r&&r.startSubmit(e),E.current=!0;try{if(!await M()){E.current=!1;return}e&&r&&r.setValidating(e),await z(async(f,d)=>{e&&r&&r.setSubmitting(e);const Y=A(f);try{await t(Y,d),m&&n==="create"&&k(),e&&r&&r.setSuccess(e)}catch(T){const Z=T instanceof Error?T.message:"Submission failed";throw e&&r&&r.setError(e,Z),T}},f=>{e&&r&&r.setError(e,"Validation failed"),$(f),o?.(f)})(s)}finally{E.current=!1}}),[z,e,M,A,$,m,n,k]),Q=w(()=>{e&&(V.getState().cleanup(e),L.getState().cleanup(e))},[e]),X=l(()=>ue(i,{operation:n,viewerRole:F,availableFields:n==="edit"&&a?Object.keys(a):void 0}),[i,n,F,a]);return{...u,handleSubmit:H,fields:X,operation:n,entity:i,t:J??(t=>t),viewerRole:F,formId:e,formStatus:e?K:"idle",uploadProgress:e?W:0,cleanup:Q}}export{ve as useEntityForm};
1
+ "use client";import{valibotResolver as B}from"@hookform/resolvers/valibot";import{useMemo as d,useEffect as U,useRef as g,useCallback as b}from"react";import{useForm as te,useWatch as re}from"react-hook-form";import{useLocalStorage as se,BACKEND_GENERATED_FIELD_NAMES as ne,createSchemas as oe}from"@donotdev/core";import{useFormStore as y,useFormStatus as ae,useUploadProgress as ie}from"../../stores";import{useUploadStore as L}from"../../stores/UploadStore";import{checkForBlobUrls as N}from"../../utils/uploadValidation";import{getFieldsForOperation as ue}from"../utils";function ve(c,x={}){const{formId:e,operation:J,defaultValues:i,viewerRole:R="admin",mode:_="onBlur",t:C,autoSave:l=!1}=x,o=J??(i?"edit":"create"),K=ae(e??""),W=ie(e??""),v=d(()=>oe(c),[c.name]),j=d(()=>B(v.create),[v.create]),k=d(()=>B(v.draft),[v.draft]),q=d(()=>async(t,n,s)=>((t?.status??i?.status)==="draft"?k:j)(t,n,s),[j,k,i?.status]),u=d(()=>{if(!i)return i;const t={...i};return Object.entries(c.fields).forEach(([n,s])=>{if(s.type==="switch"){const r=t[n];if(r==null){const S=s.options?.fieldSpecific;t[n]=S?.uncheckedValue??!1}}}),t},[i,c.fields]),a=te({defaultValues:u,mode:_,resolver:q,shouldUnregister:!1,shouldFocusError:!0}),E=g(null);U(()=>{if(o==="edit"&&u){const t=u.id??null;t&&t!==E.current?(a.reset(u),E.current=t):!t&&E.current===null&&(a.reset(u),E.current="initialized")}},[o,u,a]);const G=d(()=>`${c.name.toLowerCase()}-form-draft`,[c.name]),{value:O,setValue:I,removeValue:V}=se(G,{defaultValue:null,syncAcrossTabs:!0}),w=g(!1);U(()=>{!l||o!=="create"||i||w.current||(O&&a.reset(O),w.current=!0)},[l,o,i,O,a]);const f=re({control:a.control}),F=g(!1),h=g(null),D=g(void 0),T=g(!0);U(()=>{if(T.current){T.current=!1,D.current=f?JSON.stringify(f):void 0;return}if(!l||o!=="create"||F.current||!w.current)return;const t=f?JSON.stringify(f):void 0;if(D.current!==t)return D.current=t,h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{if(!f)return;Object.values(f).some(s=>s!=null&&s!=="")&&I(f)},3e3),()=>{h.current&&clearTimeout(h.current)}},[f,l,o,I]);const M=b(async()=>{if(!e)return!0;const t=L.getState(),n=y.getState();if(!t.hasPendingUploads(e))return!0;try{n.setUploading(e,0),await t.uploadAll(e),await new Promise(p=>setTimeout(p,50));let s=a.getValues(),r=N(s),S=0;const m=5;for(;r.length>0&&S<m;)S++,await new Promise(p=>setTimeout(p,100)),s=a.getValues(),r=N(s);if(r.length>0){const p=`Upload incomplete: files still pending at ${r.join(", ")}`;return n.setError(e,p),!1}return!0}catch(s){const r=s instanceof Error?s.message:"File upload failed";return y.getState().setError(e,r),!1}},[e,a]),A=b(t=>o!=="create"?t:Object.fromEntries(Object.entries(t).filter(([n])=>!ne.includes(n))),[o]),$=b(t=>{if(typeof window>"u")return;const n=Object.keys(t).find(r=>r!=="root"&&t[r]);if(!n)return;const s=document.querySelector(`input[name="${n}"][aria-invalid="true"], textarea[name="${n}"][aria-invalid="true"], select[name="${n}"][aria-invalid="true"]`);s&&(s.scrollIntoView({behavior:"smooth",block:"center"}),s.focus())},[]),z=a.handleSubmit,H=d(()=>((t,n)=>async s=>{s?.preventDefault?.();const r=e?y.getState():null;e&&r&&r.startSubmit(e),F.current=!0;try{if(!await M()){F.current=!1;return}e&&r&&r.setValidating(e),await z(async(m,p)=>{e&&r&&r.setSubmitting(e);const Z=A(m);try{await t(Z,p),l&&o==="create"&&V(),e&&r&&r.setSuccess(e)}catch(P){const ee=P instanceof Error?P.message:"Submission failed";throw e&&r&&r.setError(e,ee),P}},m=>{e&&r&&r.setError(e,"Validation failed"),$(m),n?.(m)})(s)}finally{F.current=!1}}),[z,e,M,A,$,l,o,V]),Q=b(()=>{l&&o==="create"&&V(),a.reset(u),D.current=u?JSON.stringify(u):void 0,T.current=!0,w.current=!1},[l,o,V,a,u]),X=b(()=>{e&&(y.getState().cleanup(e),L.getState().cleanup(e))},[e]),Y=d(()=>ue(c,{operation:o,viewerRole:R,availableFields:o==="edit"&&i?Object.keys(i):void 0}),[c,o,R,i]);return{...a,handleSubmit:H,fields:Y,operation:o,entity:c,t:C??(t=>t),viewerRole:R,formId:e,formStatus:e?K:"idle",uploadProgress:e?W:0,cleanup:X,isDirty:a.formState.isDirty,resetForm:Q,originalValues:u}}export{ve as useEntityForm};
@@ -33,7 +33,7 @@ export { useEntityForm } from './hooks/useEntityForm';
33
33
  export { useEntityField } from './hooks/useEntityField';
34
34
  export { useController } from './hooks/useController';
35
35
  export type { UseControllerProps, UseControllerReturn, ControllerRenderProps, ControllerFieldState, } from './hooks/useController';
36
- export { isFieldEditable, getFieldsForOperation, validateEntity, translateFieldLabel, translateLabel, yearOptions, rangeOptions, } from './utils';
37
- export type { ViewerRole, RenderableField, GetFieldsForOperationOptions, EntityFieldsInput, SchemaOperation, ValidationIssue, ValidationResult, SelectOption, } from './utils';
36
+ export { isFieldEditable, getFieldsForOperation, validateEntity, translateFieldLabel, translateLabel, } from './utils';
37
+ export type { ViewerRole, RenderableField, GetFieldsForOperationOptions, EntityFieldsInput, SchemaOperation, ValidationIssue, ValidationResult, } from './utils';
38
38
  export type { InferEntityData, InferEntityInput, InferEntityOutput, UseEntityFormOptions, EntityFormReturn, EntityFieldReturn, Entity, EntityField, FieldType, Visibility, Editable, ValidationRules, dndevSchema, } from './types';
39
39
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/forms/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,YAAY,EACV,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,cAAc,EAEd,WAAW,EACX,YAAY,GACb,MAAM,SAAS,CAAC;AAGjB,YAAY,EAEV,UAAU,EACV,eAAe,EACf,4BAA4B,EAC5B,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,YAAY,GACb,MAAM,SAAS,CAAC;AAEjB,YAAY,EAEV,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EAEjB,MAAM,EACN,WAAW,EACX,SAAS,EACT,UAAU,EACV,QAAQ,EACR,eAAe,EACf,WAAW,GACZ,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/forms/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,YAAY,EACV,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,cAAc,GACf,MAAM,SAAS,CAAC;AAGjB,YAAY,EAEV,UAAU,EACV,eAAe,EACf,4BAA4B,EAC5B,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAEjB,YAAY,EAEV,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EAEjB,MAAM,EACN,WAAW,EACX,SAAS,EACT,UAAU,EACV,QAAQ,EACR,eAAe,EACf,WAAW,GACZ,MAAM,SAAS,CAAC"}
@@ -1 +1 @@
1
- import{useEntityForm as r}from"./hooks/useEntityForm";import{useEntityField as i}from"./hooks/useEntityField";import{useController as l}from"./hooks/useController";import{isFieldEditable as s,getFieldsForOperation as p,validateEntity as d,translateFieldLabel as F,translateLabel as m,yearOptions as f,rangeOptions as x}from"./utils";export{p as getFieldsForOperation,s as isFieldEditable,x as rangeOptions,F as translateFieldLabel,m as translateLabel,l as useController,i as useEntityField,r as useEntityForm,d as validateEntity,f as yearOptions};
1
+ import{useEntityForm as r}from"./hooks/useEntityForm";import{useEntityField as l}from"./hooks/useEntityField";import{useController as a}from"./hooks/useController";import{isFieldEditable as s,getFieldsForOperation as d,validateEntity as F,translateFieldLabel as m,translateLabel as p}from"./utils";export{d as getFieldsForOperation,s as isFieldEditable,m as translateFieldLabel,p as translateLabel,a as useController,l as useEntityField,r as useEntityForm,F as validateEntity};
@@ -171,6 +171,21 @@ export interface EntityFormReturn<E extends Entity> extends UseFormReturn<InferE
171
171
  * Cleans up FormStore and UploadStore state for this form.
172
172
  */
173
173
  cleanup: () => void;
174
+ /**
175
+ * Whether the form has unsaved changes.
176
+ * True if any field value differs from original/default values.
177
+ */
178
+ isDirty: boolean;
179
+ /**
180
+ * Reset form to original values and clear any saved draft.
181
+ * Use this for "Cancel" button functionality.
182
+ */
183
+ resetForm: () => void;
184
+ /**
185
+ * Original values the form was initialized with.
186
+ * Undefined for create mode, the defaultValues for edit mode.
187
+ */
188
+ originalValues: Partial<InferEntityData<E>> | undefined;
174
189
  }
175
190
  /**
176
191
  * Return type for useEntityField hook.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/forms/types.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,MAAM,EACN,WAAW,EACX,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,QAAQ,EACR,eAAe,EACf,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,K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;OAGG;IACH,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAE3B;;;OAGG;IACH,UAAU,EAAE,UAAU,CAAC;IAEvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,OAAO,EAAE,MAAM,IAAI,CAAC;IAEpB;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;;OAGG;IACH,SAAS,EAAE,MAAM,IAAI,CAAC;IAEtB;;;OAGG;IACH,cAAc,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;CACzD;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,iBAAiB,CAChC,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,MAAM,eAAe,CAAC,CAAC,CAAC;IAElC;;OAEG;IACH,KAAK,EAAE,qBAAqB,CAC1B,eAAe,CAAC,CAAC,CAAC,EAClB,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAC9B,CAAC;IAEF;;OAEG;IACH,IAAI,EAAE;QACJ,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;QAC1B,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IAEF;;OAEG;IACH,MAAM,EAAE,WAAW,CAAC;IAEpB;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,SAAS,EAAE,OAAO,CAAC;CACpB"}
@@ -13,6 +13,4 @@ export type { RenderableField, GetFieldsForOperationOptions, EntityFieldsInput,
13
13
  export { validateEntity } from './validateEntity';
14
14
  export type { ValidationIssue, ValidationResult, SchemaOperation, } from './validateEntity';
15
15
  export { translateFieldLabel, translateLabel } from './translateFieldLabel';
16
- export { yearOptions, rangeOptions } from './optionHelpers';
17
- export type { SelectOption } from './optionHelpers';
18
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/forms/utils/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,YAAY,EACV,eAAe,EACf,4BAA4B,EAC5B,iBAAiB,GAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC5D,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/forms/utils/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,YAAY,EACV,eAAe,EACf,4BAA4B,EAC5B,iBAAiB,GAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
@@ -1 +1 @@
1
- import{isFieldEditable as r}from"./isFieldEditable";import{getFieldsForOperation as a}from"./getFieldsForOperation";import{validateEntity as l}from"./validateEntity";import{translateFieldLabel as n,translateLabel as s}from"./translateFieldLabel";import{yearOptions as f,rangeOptions as m}from"./optionHelpers";export{a as getFieldsForOperation,r as isFieldEditable,m as rangeOptions,n as translateFieldLabel,s as translateLabel,l as validateEntity,f as yearOptions};
1
+ import{isFieldEditable as r}from"./isFieldEditable";import{getFieldsForOperation as o}from"./getFieldsForOperation";import{validateEntity as i}from"./validateEntity";import{translateFieldLabel as p,translateLabel as f}from"./translateFieldLabel";export{o as getFieldsForOperation,r as isFieldEditable,p as translateFieldLabel,f as translateLabel,i as validateEntity};
@@ -1 +1 @@
1
- import*as o from"valibot";import{createSchemas as p}from"@donotdev/schemas";function h(a,c,r="create"){const s=p(a),u={create:s.create,draft:s.draft,update:s.update,full:s.get}[r],e=o.safeParse(u,c);return e.success?{success:!0,data:e.output}:{success:!1,issues:e.issues.map(t=>({path:t.path?.map(m=>m.key).join(".")||"",message:t.message}))}}export{h as validateEntity};
1
+ import*as o from"valibot";import{createSchemas as p}from"@donotdev/core";function h(a,c,r="create"){const s=p(a),u={create:s.create,draft:s.draft,update:s.update,full:s.get}[r],e=o.safeParse(u,c);return e.success?{success:!0,data:e.output}:{success:!1,issues:e.issues.map(t=>({path:t.path?.map(m=>m.key).join(".")||"",message:t.message}))}}export{h as validateEntity};
@@ -1,4 +1,4 @@
1
- import type { Picture } from '@donotdev/types';
1
+ import type { Picture } from '@donotdev/core';
2
2
  /** Metadata for a file in the upload queue */
3
3
  export interface FileMetadata {
4
4
  /** Unique ID for React keys */
@@ -1 +1 @@
1
- {"version":3,"file":"useFileUpload.d.ts","sourceRoot":"","sources":["../../src/hooks/useFileUpload.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAK/C,8CAA8C;AAC9C,MAAM,WAAW,YAAY;IAC3B,+BAA+B;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,6CAA6C;IAC7C,IAAI,EAAE,IAAI,CAAC;IACX,6DAA6D;IAC7D,UAAU,EAAE,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B,aAAa,CAAC,EAC5B,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,QAAgB,EAChB,QAAa,EACb,OAA0B,EAC1B,MAAW,EACX,WAAuB,EACvB,QAAQ,GACT,EAAE,oBAAoB;IAwZnB,yCAAyC;;IAEzC,4CAA4C;yBAvGjC,IAAI,EAAE;IAyGjB,0BAA0B;qBAhCrB,MAAM;IAkCX,2CAA2C;;IAE3C,oCAAoC;;IAEpC,6BAA6B;;IAE7B,qDAAqD;;IAErD,sFAAsF;;EAGzF"}
@@ -1 +1 @@
1
- "use client";import{useState as G,useCallback as R,useEffect as v,useRef as A,startTransition as H}from"react";import{handleError as j}from"@donotdev/core";import{useUploadContext as K}from"../contexts/UploadContext";import{useUploadStore as k}from"../stores/UploadStore";let B=0;function M(l){if(l){const d=l.split("/").pop()?.split("?")[0];if(d)return`file-${d}`}B+=1;const u=typeof performance<"u"?performance.now():Date.now(),g=Math.random().toString(36).slice(2,11);return`file-${B}-${u}-${g}`}function Q(l){return URL.createObjectURL(l)}function V(l){l.startsWith("blob:")&&URL.revokeObjectURL(l)}function X(l,u,g){return u.length>0&&!u.some(m=>{if(m.endsWith("/*")){const L=m.slice(0,-2);return l.type.startsWith(L)}return l.type===m})?{valid:!1,error:`File type ${l.type} not accepted`}:l.size>g?{valid:!1,error:`File exceeds ${(g/1048576).toFixed(0)}MB limit`}:{valid:!0}}function er({name:l,value:u,onChange:g,multiple:d=!1,maxFiles:m=10,maxSize:L=10*1024*1024,accept:x=[],storagePath:Y="uploads",uploadFn:U}){const h=K(),w=!!h,[f,c]=G([]),E=A(!1),P=A(null),F=A(u),$=A([]);v(()=>{if(E.current){E.current=!1;return}const e=u?JSON.stringify((Array.isArray(u)?u:[u]).map(s=>s.fullUrl).filter(Boolean).sort()):null;e!==P.current&&(P.current=e,F.current=u,H(()=>{if(u){const n=(Array.isArray(u)?u:[u]).filter(t=>t.fullUrl).map((t,r)=>({id:`${M(t.fullUrl)}-existing-${r}`,file:new File([],"existing"),previewURL:t.thumbUrl||t.fullUrl,progress:100,uploaded:t,error:null}));c(n)}else c([])}))},[u]),v(()=>{$.current=f},[f]),v(()=>()=>{$.current.forEach(e=>V(e.previewURL))},[]);const p=R((e,s=!1)=>{const t=(s?e.filter(i=>!i.error):e.filter(i=>i.uploaded&&!i.error)).map(i=>i.uploaded?i.uploaded:s&&w?{fullUrl:i.previewURL,thumbUrl:i.previewURL}:null).filter(i=>i!==null);let r;d?r=t.length>0?t:null:r=t[0]||null;const o=F.current;(()=>{if(!r&&!o)return!1;if(!r||!o)return!0;if(d&&Array.isArray(r)&&Array.isArray(o)){if(r.length!==o.length)return!0;const i=r.map(b=>b.fullUrl).sort().join(","),y=o.map(b=>b.fullUrl).sort().join(",");return i!==y}return!d&&!Array.isArray(r)&&!Array.isArray(o)?r.fullUrl!==o.fullUrl:!0})()&&(E.current=!0,F.current=r,g(r))},[d,g,w]),S=R(async()=>{if(!U)return;let e=[];if(c(n=>(e=n.filter(t=>!t.uploaded&&!t.error),e.length===0?n:n.map(t=>e.some(r=>r.id===t.id)?{...t,progress:0}:t))),e.length===0)return;const s=await Promise.allSettled(e.map(async n=>{try{const t=await U(n.file,r=>{c(o=>o.map(a=>a.id===n.id?{...a,progress:r}:a))});return{id:n.id,picture:t,error:null}}catch(t){const r=t instanceof Error?t.message:"Upload failed";return{id:n.id,picture:null,error:r}}}));c(n=>{const t=n.map(r=>{const o=s.find(a=>a.status==="fulfilled"&&a.value.id===r.id);if(o&&o.status==="fulfilled"){const a=o.value;return{...r,uploaded:a.picture,progress:a.picture?100:null,error:a.error}}return r});return p(t,!1),t})},[U,p]),C=A(S);C.current=S;const I=k(e=>e.registerUpload),N=k(e=>e.unregisterUpload);v(()=>{if(!(!h||!l))return I(h,l,async()=>{await C.current()},()=>$.current.some(e=>!e.uploaded&&!e.error)),()=>{N(h,l)}},[h,l,I,N]);const T=R(async e=>{if(U){c(s=>s.map(n=>n.id===e.id?{...n,progress:0}:n));try{const s=await U(e.file,n=>{c(t=>t.map(r=>r.id===e.id?{...r,progress:n}:r))});c(n=>{const t=n.map(r=>r.id===e.id?{...r,uploaded:s,progress:100,error:null}:r);return p(t,!1),t})}catch(s){const n=s instanceof Error?s.message:"Upload failed";c(t=>t.map(r=>r.id===e.id?{...r,error:n,progress:null}:r))}}},[U,p]),D=R(e=>{c(s=>{const t=(d?m:1)-s.length;if(t<=0)return j(new Error("Maximum files reached"),{userMessage:d?`Maximum ${m} files allowed`:"Only one file allowed",severity:"warning",showNotification:!0}),s;const r=e.slice(0,t),o=[];for(const i of r){const y=X(i,x,L);if(!y.valid){j(new Error(y.error),{userMessage:y.error,severity:"warning",showNotification:!0});continue}o.push({id:M(),file:i,previewURL:Q(i),progress:null,uploaded:null,error:null})}if(o.length===0)return s;const a=d?[...s,...o]:o;return w?setTimeout(()=>{p(a,!0)},0):o.forEach(i=>T(i)),a})},[d,m,x,L,w,T,p]),O=R(e=>{c(s=>{const n=s.find(r=>r.id===e);n&&V(n.previewURL);const t=s.filter(r=>r.id!==e);return p(t,!1),t})},[p]),W=f.some(e=>!e.uploaded&&!e.error),J=f.some(e=>e.progress!==null&&e.progress<100),q=f.length>0?f.reduce((e,s)=>e+(s.progress??0),0)/f.length:0;return{files:f,addFiles:D,removeFile:O,hasPending:W,isUploading:J,progress:q,formId:h,isDeferred:w}}export{er as useFileUpload};
1
+ "use client";import{useState as G,useCallback as R,useEffect as v,useRef as A,startTransition as H}from"react";import{handleError as j}from"@donotdev/core";import{useUploadContext as K}from"../contexts/UploadContext";import{useUploadStore as k}from"../stores/UploadStore";let B=0;function M(l){if(l){const d=l.split("/").pop()?.split("?")[0];if(d)return`file-${d}`}B+=1;const u=typeof performance<"u"?performance.now():Date.now(),g=Math.random().toString(36).slice(2,11);return`file-${B}-${u}-${g}`}function Q(l){return URL.createObjectURL(l)}function V(l){l.startsWith("blob:")&&URL.revokeObjectURL(l)}function X(l,u,g){return u.length>0&&!u.some(m=>{if(m.endsWith("/*")){const L=m.slice(0,-2);return l.type.startsWith(L)}return l.type===m})?{valid:!1,error:`File type ${l.type} not accepted`}:l.size>g?{valid:!1,error:`File exceeds ${(g/1048576).toFixed(0)}MB limit`}:{valid:!0}}function er({name:l,value:u,onChange:g,multiple:d=!1,maxFiles:m=10,maxSize:L=10*1024*1024,accept:x=[],storagePath:Y="uploads",uploadFn:U}){const h=K(),w=!!h,[f,c]=G([]),E=A(!1),P=A(null),F=A(u),$=A([]);v(()=>{if(E.current){E.current=!1;return}const e=u?JSON.stringify((Array.isArray(u)?u:[u]).map(s=>s.fullUrl).filter(Boolean)):null;e!==P.current&&(P.current=e,F.current=u,H(()=>{if(u){const n=(Array.isArray(u)?u:[u]).filter(t=>t.fullUrl).map((t,r)=>({id:`${M(t.fullUrl)}-existing-${r}`,file:new File([],"existing"),previewURL:t.thumbUrl||t.fullUrl,progress:100,uploaded:t,error:null}));c(n)}else c([])}))},[u]),v(()=>{$.current=f},[f]),v(()=>()=>{$.current.forEach(e=>V(e.previewURL))},[]);const p=R((e,s=!1)=>{const t=(s?e.filter(i=>!i.error):e.filter(i=>i.uploaded&&!i.error)).map(i=>i.uploaded?i.uploaded:s&&w?{fullUrl:i.previewURL,thumbUrl:i.previewURL}:null).filter(i=>i!==null);let r;d?r=t.length>0?t:null:r=t[0]||null;const o=F.current;(()=>{if(!r&&!o)return!1;if(!r||!o)return!0;if(d&&Array.isArray(r)&&Array.isArray(o)){if(r.length!==o.length)return!0;const i=r.map(b=>b.fullUrl).join(","),y=o.map(b=>b.fullUrl).join(",");return i!==y}return!d&&!Array.isArray(r)&&!Array.isArray(o)?r.fullUrl!==o.fullUrl:!0})()&&(E.current=!0,F.current=r,g(r))},[d,g,w]),S=R(async()=>{if(!U)return;let e=[];if(c(n=>(e=n.filter(t=>!t.uploaded&&!t.error),e.length===0?n:n.map(t=>e.some(r=>r.id===t.id)?{...t,progress:0}:t))),e.length===0)return;const s=await Promise.allSettled(e.map(async n=>{try{const t=await U(n.file,r=>{c(o=>o.map(a=>a.id===n.id?{...a,progress:r}:a))});return{id:n.id,picture:t,error:null}}catch(t){const r=t instanceof Error?t.message:"Upload failed";return{id:n.id,picture:null,error:r}}}));c(n=>{const t=n.map(r=>{const o=s.find(a=>a.status==="fulfilled"&&a.value.id===r.id);if(o&&o.status==="fulfilled"){const a=o.value;return{...r,uploaded:a.picture,progress:a.picture?100:null,error:a.error}}return r});return p(t,!1),t})},[U,p]),C=A(S);C.current=S;const I=k(e=>e.registerUpload),N=k(e=>e.unregisterUpload);v(()=>{if(!(!h||!l))return I(h,l,async()=>{await C.current()},()=>$.current.some(e=>!e.uploaded&&!e.error)),()=>{N(h,l)}},[h,l,I,N]);const T=R(async e=>{if(U){c(s=>s.map(n=>n.id===e.id?{...n,progress:0}:n));try{const s=await U(e.file,n=>{c(t=>t.map(r=>r.id===e.id?{...r,progress:n}:r))});c(n=>{const t=n.map(r=>r.id===e.id?{...r,uploaded:s,progress:100,error:null}:r);return p(t,!1),t})}catch(s){const n=s instanceof Error?s.message:"Upload failed";c(t=>t.map(r=>r.id===e.id?{...r,error:n,progress:null}:r))}}},[U,p]),D=R(e=>{c(s=>{const t=(d?m:1)-s.length;if(t<=0)return j(new Error("Maximum files reached"),{userMessage:d?`Maximum ${m} files allowed`:"Only one file allowed",severity:"warning",showNotification:!0}),s;const r=e.slice(0,t),o=[];for(const i of r){const y=X(i,x,L);if(!y.valid){j(new Error(y.error),{userMessage:y.error,severity:"warning",showNotification:!0});continue}o.push({id:M(),file:i,previewURL:Q(i),progress:null,uploaded:null,error:null})}if(o.length===0)return s;const a=d?[...s,...o]:o;return w?setTimeout(()=>{p(a,!0)},0):o.forEach(i=>T(i)),a})},[d,m,x,L,w,T,p]),O=R(e=>{c(s=>{const n=s.find(r=>r.id===e);n&&V(n.previewURL);const t=s.filter(r=>r.id!==e);return p(t,!1),t})},[p]),W=f.some(e=>!e.uploaded&&!e.error),J=f.some(e=>e.progress!==null&&e.progress<100),q=f.length>0?f.reduce((e,s)=>e+(s.progress??0),0)/f.length:0;return{files:f,addFiles:D,removeFile:O,hasPending:W,isUploading:J,progress:q,formId:h,isDeferred:w}}export{er as useFileUpload};
@@ -0,0 +1,34 @@
1
+ export interface UseFormNavigationGuardOptions {
2
+ /** Whether the guard is enabled (default: true) */
3
+ enabled?: boolean;
4
+ /** Custom message for navigation confirmation */
5
+ message?: string;
6
+ }
7
+ /**
8
+ * Hook to block SPA navigation when forms are dirty.
9
+ * Uses FormStore as single source of truth.
10
+ *
11
+ * For React Router: Uses useBlocker
12
+ * For Next.js: Intercepts router.push calls
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * // In your app root/layout
17
+ * useFormNavigationGuard({
18
+ * message: 'You have unsaved changes. Are you sure you want to leave?',
19
+ * });
20
+ * ```
21
+ */
22
+ export declare function useFormNavigationGuard({ enabled, message, }?: UseFormNavigationGuardOptions): void;
23
+ /**
24
+ * Check if navigation should be blocked and get confirmation.
25
+ * Used by router navigation hooks.
26
+ *
27
+ * NOTE: For safe access from @donotdev/ui, use checkFormNavigationSafe from useFormStoreSafe.
28
+ * This function is for direct use within CRUD package.
29
+ *
30
+ * @returns Promise<boolean> - true if navigation should proceed, false if blocked
31
+ */
32
+ export declare function checkFormNavigation(message?: string): Promise<boolean>;
33
+ export default useFormNavigationGuard;
34
+ //# sourceMappingURL=useFormNavigationGuard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFormNavigationGuard.d.ts","sourceRoot":"","sources":["../../src/hooks/useFormNavigationGuard.ts"],"names":[],"mappings":"AAmBA,MAAM,WAAW,6BAA6B;IAC5C,mDAAmD;IACnD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,sBAAsB,CAAC,EACrC,OAAc,EACd,OAAqE,GACtE,GAAE,6BAAkC,GAAG,IAAI,CAsB3C;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,SAA4C,GAClD,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED,eAAe,sBAAsB,CAAC"}
@@ -0,0 +1 @@
1
+ "use client";import{useEffect as a}from"react";import{isClient as u}from"@donotdev/core";import{useFormStore as i}from"../stores";function s({enabled:r=!0,message:e="You have unsaved changes. Are you sure you want to leave?"}={}){const o=i(t=>t.hasDirtyForms());a(()=>{if(!r||!o||!u())return;const t=n=>(n.preventDefault(),n.returnValue=e,e);return window.addEventListener("beforeunload",t),()=>{window.removeEventListener("beforeunload",t)}},[r,o,e])}async function d(r="You have unsaved changes. Discard them?"){return!u()||!i.getState().hasDirtyForms()?!0:window.confirm(r)}var h=s;export{d as checkFormNavigation,h as default,s as useFormNavigationGuard};
@@ -0,0 +1,51 @@
1
+ export interface UseUnsavedChangesWarningOptions {
2
+ /** Whether the form has unsaved changes */
3
+ isDirty: boolean;
4
+ /** Whether the warning is enabled (default: true) */
5
+ enabled?: boolean;
6
+ /** Custom message for beforeunload (browsers often ignore this) */
7
+ message?: string;
8
+ /** Callback when user tries to navigate away - return false to block, true to allow */
9
+ onBeforeNavigate?: () => boolean | Promise<boolean>;
10
+ }
11
+ /**
12
+ * Hook to warn users about unsaved changes before leaving the page.
13
+ *
14
+ * Handles:
15
+ * - Browser refresh/close (beforeunload event)
16
+ * - Browser back/forward (beforeunload event)
17
+ *
18
+ * For SPA navigation (Next.js router), use the onBeforeNavigate callback
19
+ * with your router's navigation blocking mechanism.
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * const { isDirty } = useFormState();
24
+ *
25
+ * useUnsavedChangesWarning({
26
+ * isDirty,
27
+ * message: 'You have unsaved changes. Are you sure you want to leave?',
28
+ * });
29
+ * ```
30
+ */
31
+ export declare function useUnsavedChangesWarning({ isDirty, enabled, message, onBeforeNavigate, }: UseUnsavedChangesWarningOptions): void;
32
+ /**
33
+ * Helper to confirm navigation with unsaved changes.
34
+ * Use this in your router's navigation guard.
35
+ *
36
+ * @example Next.js App Router:
37
+ * ```tsx
38
+ * // In your page/layout
39
+ * const confirmNavigation = useConfirmNavigation(isDirty);
40
+ *
41
+ * // In link click handler
42
+ * const handleNavigation = async (href: string) => {
43
+ * if (await confirmNavigation()) {
44
+ * router.push(href);
45
+ * }
46
+ * };
47
+ * ```
48
+ */
49
+ export declare function useConfirmNavigation(isDirty: boolean, message?: string): () => Promise<boolean>;
50
+ export default useUnsavedChangesWarning;
51
+ //# sourceMappingURL=useUnsavedChangesWarning.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUnsavedChangesWarning.d.ts","sourceRoot":"","sources":["../../src/hooks/useUnsavedChangesWarning.ts"],"names":[],"mappings":"AAiBA,MAAM,WAAW,+BAA+B;IAC9C,2CAA2C;IAC3C,OAAO,EAAE,OAAO,CAAC;IACjB,qDAAqD;IACrD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uFAAuF;IACvF,gBAAgB,CAAC,EAAE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACrD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,wBAAwB,CAAC,EACvC,OAAO,EACP,OAAc,EACd,OAAqE,EACrE,gBAAgB,GACjB,EAAE,+BAA+B,GAAG,IAAI,CAuBxC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,OAAO,EAChB,OAAO,SAA4C,GAClD,MAAM,OAAO,CAAC,OAAO,CAAC,CAWxB;AAED,eAAe,wBAAwB,CAAC"}
@@ -0,0 +1 @@
1
+ "use client";import{useEffect as a,useCallback as f}from"react";import{isClient as u}from"@donotdev/core";function i({isDirty:e,enabled:n=!0,message:r="You have unsaved changes. Are you sure you want to leave?",onBeforeNavigate:d}){a(()=>{if(!n||!e||!u())return;const o=t=>(t.preventDefault(),t.returnValue=r,r);return window.addEventListener("beforeunload",o),()=>{window.removeEventListener("beforeunload",o)}},[e,n,r])}function s(e,n="You have unsaved changes. Discard them?"){return f(async()=>e?u()?window.confirm(n):!1:!0,[e,n])}var v=i;export{v as default,s as useConfirmNavigation,i as useUnsavedChangesWarning};
package/dist/index.d.ts CHANGED
@@ -11,13 +11,15 @@ export * from './useCrudList';
11
11
  export * from './useCrudCardList';
12
12
  export * from './components';
13
13
  export * from './stores';
14
- export { getCrudService, type CrudServiceInterface, type CacheOptions, type QueryOptions, } from './CrudService';
15
- export { useCrudStore, type CrudState, type CrudActions, type BackendType, type OptimisticStatus, type OptimisticMeta, } from './CrudStore';
14
+ export { getCrudService } from './CrudService';
15
+ export type { QueryOptions } from './CrudService';
16
+ export { useCrudStore } from './CrudStore';
17
+ export type { CrudServiceInterface, CrudState, CrudActions, BackendType, OptimisticStatus, OptimisticMeta, CrudStoreApi, CacheOptions, } from './types';
16
18
  export { loadDeterministicRange, upsertDeterministic, appendToCollection, } from './utils/collections';
17
19
  export { getFieldRegistry, registerFieldType, isFieldTypeRegistered, type FieldTypeRegistration, type ControlledFieldProps, type UncontrolledFieldProps, } from './FieldRegistry';
18
20
  export { registerBuiltinFieldTypes } from './builtinFieldTypes';
19
- export { useEntityForm, useEntityField, useController, isFieldEditable, getFieldsForOperation, validateEntity, translateFieldLabel, translateLabel, yearOptions, rangeOptions, } from './forms';
20
- export type { ViewerRole, RenderableField, GetFieldsForOperationOptions, EntityFieldsInput, SchemaOperation, ValidationIssue, ValidationResult, SelectOption, InferEntityData, InferEntityInput, InferEntityOutput, UseEntityFormOptions, EntityFormReturn, EntityFieldReturn, UseControllerProps, UseControllerReturn, ControllerRenderProps, ControllerFieldState, } from './forms';
21
+ export { useEntityForm, useEntityField, useController, isFieldEditable, getFieldsForOperation, validateEntity, translateFieldLabel, translateLabel, } from './forms';
22
+ export type { ViewerRole, RenderableField, GetFieldsForOperationOptions, EntityFieldsInput, SchemaOperation, ValidationIssue, ValidationResult, InferEntityData, InferEntityInput, InferEntityOutput, UseEntityFormOptions, EntityFormReturn, EntityFieldReturn, UseControllerProps, UseControllerReturn, ControllerRenderProps, ControllerFieldState, } from './forms';
21
23
  export { UploadProvider, useUploadContext } from './contexts';
22
24
  export type { UploadProviderProps } from './contexts';
23
25
  export { useFileUpload } from './hooks';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAGH,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAGlC,cAAc,cAAc,CAAC;AAG7B,cAAc,UAAU,CAAC;AAGzB,OAAO,EACL,cAAc,EACd,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,YAAY,GAClB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,YAAY,EACZ,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,cAAc,GACpB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,qBAAqB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,GAC5B,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAGhE,OAAO,EAEL,aAAa,EACb,cAAc,EACd,aAAa,EAEb,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,cAAc,EAEd,WAAW,EACX,YAAY,GACb,MAAM,SAAS,CAAC;AAGjB,YAAY,EACV,UAAU,EACV,eAAe,EACf,4BAA4B,EAC5B,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,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Ac,EACd,aAAa,EAEb,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,cAAc,GACf,MAAM,SAAS,CAAC;AAGjB,YAAY,EACV,UAAU,EACV,eAAe,EACf,4BAA4B,EAC5B,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9D,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,YAAY,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAGlE,OAAO,EACL,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,WAAW,GACZ,MAAM,0BAA0B,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export*from"./useCrud";export*from"./useCrudList";export*from"./useCrudCardList";export*from"./components";export*from"./stores";import{getCrudService as s}from"./CrudService";import{useCrudStore as d}from"./CrudStore";import{loadDeterministicRange as n,upsertDeterministic as x,appendToCollection as f}from"./utils/collections";import{getFieldRegistry as u,registerFieldType as g,isFieldTypeRegistered as y}from"./FieldRegistry";import{registerBuiltinFieldTypes as U}from"./builtinFieldTypes";import{useEntityForm as C,useEntityField as v,useController as E,isFieldEditable as T,getFieldsForOperation as B,validateEntity as O,translateFieldLabel as R,translateLabel as S,yearOptions as h,rangeOptions as D}from"./forms";import{UploadProvider as P,useUploadContext as k}from"./contexts";import{useFileUpload as q}from"./hooks";import{isStorageUrl as z,validatePicture as A,checkForBlobUrls as G,hasBlobUrls as H}from"./utils/uploadValidation";export{P as UploadProvider,f as appendToCollection,G as checkForBlobUrls,s as getCrudService,u as getFieldRegistry,B as getFieldsForOperation,H as hasBlobUrls,T as isFieldEditable,y as isFieldTypeRegistered,z as isStorageUrl,n as loadDeterministicRange,D as rangeOptions,U as registerBuiltinFieldTypes,g as registerFieldType,R as translateFieldLabel,S as translateLabel,x as upsertDeterministic,E as useController,d as useCrudStore,v as useEntityField,C as useEntityForm,q as useFileUpload,k as useUploadContext,O as validateEntity,A as validatePicture,h as yearOptions};
1
+ export*from"./useCrud";export*from"./useCrudList";export*from"./useCrudCardList";export*from"./components";export*from"./stores";import{getCrudService as s}from"./CrudService";import{useCrudStore as d}from"./CrudStore";import{loadDeterministicRange as x,upsertDeterministic as f,appendToCollection as n}from"./utils/collections";import{getFieldRegistry as u,registerFieldType as g,isFieldTypeRegistered as c}from"./FieldRegistry";import{registerBuiltinFieldTypes as U}from"./builtinFieldTypes";import{useEntityForm as C,useEntityField as v,useController as E,isFieldEditable as T,getFieldsForOperation as B,validateEntity as R,translateFieldLabel as S,translateLabel as h}from"./forms";import{UploadProvider as L,useUploadContext as P}from"./contexts";import{useFileUpload as O}from"./hooks";import{isStorageUrl as q,validatePicture as w,checkForBlobUrls as z,hasBlobUrls as A}from"./utils/uploadValidation";export{L as UploadProvider,n as appendToCollection,z as checkForBlobUrls,s as getCrudService,u as getFieldRegistry,B as getFieldsForOperation,A as hasBlobUrls,T as isFieldEditable,c as isFieldTypeRegistered,q as isStorageUrl,x as loadDeterministicRange,U as registerBuiltinFieldTypes,g as registerFieldType,S as translateFieldLabel,h as translateLabel,f as upsertDeterministic,E as useController,d as useCrudStore,v as useEntityField,C as useEntityForm,O as useFileUpload,P as useUploadContext,R as validateEntity,w as validatePicture};
@@ -10,6 +10,7 @@ interface FormState {
10
10
  status: FormStatus;
11
11
  error: string | null;
12
12
  uploadProgress: number;
13
+ isDirty: boolean;
13
14
  }
14
15
  /**
15
16
  * Form store state interface
@@ -38,6 +39,12 @@ export interface FormStoreActions {
38
39
  reset: (formId: string) => void;
39
40
  /** Clean up form state (on unmount) */
40
41
  cleanup: (formId: string) => void;
42
+ /** Set form dirty state */
43
+ setIsDirty: (formId: string, isDirty: boolean) => void;
44
+ /** Check if any form is dirty */
45
+ hasDirtyForms: () => boolean;
46
+ /** Get all dirty form IDs */
47
+ getDirtyFormIds: () => string[];
41
48
  /** Get form status */
42
49
  getStatus: (formId: string) => FormStatus;
43
50
  /** Check if form is in any loading state */
@@ -46,6 +53,8 @@ export interface FormStoreActions {
46
53
  getUploadProgress: (formId: string) => number;
47
54
  /** Get error message */
48
55
  getError: (formId: string) => string | null;
56
+ /** Check if form is dirty */
57
+ getIsDirty: (formId: string) => boolean;
49
58
  }
50
59
  /**
51
60
  * Form store for managing form submission states
@@ -74,5 +83,13 @@ export declare const useUploadProgress: (formId: string) => number;
74
83
  * Hook to get form error
75
84
  */
76
85
  export declare const useFormError: (formId: string) => string | null;
86
+ /**
87
+ * Hook to check if form is dirty
88
+ */
89
+ export declare const useFormIsDirty: (formId: string) => boolean;
90
+ /**
91
+ * Hook to check if any form is dirty
92
+ */
93
+ export declare const useHasDirtyForms: () => boolean;
77
94
  export {};
78
95
  //# sourceMappingURL=FormStore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormStore.d.ts","sourceRoot":"","sources":["../../src/stores/FormStore.ts"],"names":[],"mappings":"AAkBA;;;GAGG;AACH,MAAM,MAAM,UAAU,GAClB,MAAM,GACN,WAAW,GACX,YAAY,GACZ,YAAY,GACZ,SAAS,GACT,OAAO,CAAC;AAEZ;;GAEG;AACH,UAAU,SAAS;IACjB,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,kCAAkC;IAClC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAE/B,8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adProgress:0},m=a({name:"form-store",createStore:(o,t)=>({forms:{},startSubmit:r=>{o(s=>({forms:{...s.forms,[r]:{status:"uploading",error:null,uploadProgress:0}}}))},setUploading:(r,s)=>{o(u=>{const n=u.forms[r]||e;return{forms:{...u.forms,[r]:{...n,status:"uploading",uploadProgress:Math.min(100,Math.max(0,s))}}}})},setValidating:r=>{o(s=>{const u=s.forms[r]||e;return{forms:{...s.forms,[r]:{...u,status:"validating",uploadProgress:100}}}})},setSubmitting:r=>{o(s=>{const u=s.forms[r]||e;return{forms:{...s.forms,[r]:{...u,status:"submitting"}}}})},setSuccess:r=>{o(s=>{const u=s.forms[r]||e;return{forms:{...s.forms,[r]:{...u,status:"success",error:null}}}}),setTimeout(()=>{t().reset(r)},1500)},setError:(r,s)=>{o(u=>{const n=u.forms[r]||e;return{forms:{...u.forms,[r]:{...n,status:"error",error:s}}}})},reset:r=>{o(s=>({forms:{...s.forms,[r]:{...e}}}))},cleanup:r=>{o(s=>{const{[r]:u,...n}=s.forms;return{forms:n}})},getStatus:r=>t().forms[r]?.status??"idle",isLoading:r=>{const s=t().forms[r]?.status??"idle";return s==="uploading"||s==="validating"||s==="submitting"},getUploadProgress:r=>t().forms[r]?.uploadProgress??0,getError:r=>t().forms[r]?.error??null})}),l=o=>m(t=>t.forms[o]?.status??"idle"),f=o=>m(t=>{const r=t.forms[o]?.status??"idle";return r==="uploading"||r==="validating"||r==="submitting"}),g=o=>m(t=>t.forms[o]?.uploadProgress??0),c=o=>m(t=>t.forms[o]?.error??null);export{c as useFormError,f as useFormLoading,l as useFormStatus,m as useFormStore,g as useUploadProgress};
1
+ "use client";import{createDoNotDevStore as i}from"@donotdev/core";const m={status:"idle",error:null,uploadProgress:0,isDirty:!1},u=i({name:"form-store",createStore:(o,e)=>({forms:{},startSubmit:r=>{o(s=>{const t=s.forms[r]||m;return{forms:{...s.forms,[r]:{...t,status:"uploading",error:null,uploadProgress:0}}}})},setUploading:(r,s)=>{o(t=>{const n=t.forms[r]||m;return{forms:{...t.forms,[r]:{...n,status:"uploading",uploadProgress:Math.min(100,Math.max(0,s))}}}})},setValidating:r=>{o(s=>{const t=s.forms[r]||m;return{forms:{...s.forms,[r]:{...t,status:"validating",uploadProgress:100}}}})},setSubmitting:r=>{o(s=>{const t=s.forms[r]||m;return{forms:{...s.forms,[r]:{...t,status:"submitting"}}}})},setSuccess:r=>{o(s=>{const t=s.forms[r]||m;return{forms:{...s.forms,[r]:{...t,status:"success",error:null}}}}),setTimeout(()=>{e().reset(r)},1500)},setError:(r,s)=>{o(t=>{const n=t.forms[r]||m;return{forms:{...t.forms,[r]:{...n,status:"error",error:s}}}})},reset:r=>{o(s=>({forms:{...s.forms,[r]:{...m}}}))},setIsDirty:(r,s)=>{o(t=>{const n=t.forms[r]||m;return{forms:{...t.forms,[r]:{...n,isDirty:s}}}})},hasDirtyForms:()=>{const r=e().forms;return Object.values(r).some(s=>s.isDirty)},getDirtyFormIds:()=>{const r=e().forms;return Object.entries(r).filter(([s,t])=>t.isDirty).map(([s])=>s)},cleanup:r=>{o(s=>{const{[r]:t,...n}=s.forms;return{forms:n}})},getStatus:r=>e().forms[r]?.status??"idle",isLoading:r=>{const s=e().forms[r]?.status??"idle";return s==="uploading"||s==="validating"||s==="submitting"},getUploadProgress:r=>e().forms[r]?.uploadProgress??0,getError:r=>e().forms[r]?.error??null,getIsDirty:r=>e().forms[r]?.isDirty??!1})}),f=o=>u(e=>e.forms[o]?.status??"idle"),l=o=>u(e=>{const r=e.forms[o]?.status??"idle";return r==="uploading"||r==="validating"||r==="submitting"}),c=o=>u(e=>e.forms[o]?.uploadProgress??0),p=o=>u(e=>e.forms[o]?.error??null),g=o=>u(e=>e.forms[o]?.isDirty??!1),d=()=>u(o=>o.hasDirtyForms());export{p as useFormError,g as useFormIsDirty,l as useFormLoading,f as useFormStatus,u as useFormStore,d as useHasDirtyForms,c as useUploadProgress};
@@ -6,6 +6,6 @@
6
6
  * @since 0.0.1
7
7
  * @author AMBROISE PARK Consulting
8
8
  */
9
- export { useFormStore, useFormStatus, useFormLoading, useUploadProgress, useFormError, type FormStatus, type FormStoreState, type FormStoreActions, } from './FormStore';
9
+ export { useFormStore, useFormStatus, useFormLoading, useUploadProgress, useFormError, useFormIsDirty, useHasDirtyForms, type FormStatus, type FormStoreState, type FormStoreActions, } from './FormStore';
10
10
  export { useUploadStore, useTotalProgress, useIsUploading, useFieldProgress, useFieldUploadStatus, type UploadStatus, type UploadFunction, type UploadStoreState, type UploadStoreActions, } from './UploadStore';
11
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stores/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAGH,OAAO,EACL,YAAY,EACZ,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,gBAAgB,GACtB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,GACxB,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stores/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAGH,OAAO,EACL,YAAY,EACZ,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,gBAAgB,GACtB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,GACxB,MAAM,eAAe,CAAC"}
@@ -1 +1 @@
1
- import{useFormStore as r,useFormStatus as s,useFormLoading as u,useUploadProgress as t,useFormError as a}from"./FormStore";import{useUploadStore as l,useTotalProgress as m,useIsUploading as p,useFieldProgress as F,useFieldUploadStatus as g}from"./UploadStore";export{F as useFieldProgress,g as useFieldUploadStatus,a as useFormError,u as useFormLoading,s as useFormStatus,r as useFormStore,p as useIsUploading,m as useTotalProgress,t as useUploadProgress,l as useUploadStore};
1
+ import{useFormStore as o,useFormStatus as e,useFormLoading as u,useUploadProgress as t,useFormError as a,useFormIsDirty as m,useHasDirtyForms as F}from"./FormStore";import{useUploadStore as l,useTotalProgress as i,useIsUploading as p,useFieldProgress as g,useFieldUploadStatus as S}from"./UploadStore";export{g as useFieldProgress,S as useFieldUploadStatus,a as useFormError,m as useFormIsDirty,u as useFormLoading,e as useFormStatus,o as useFormStore,F as useHasDirtyForms,p as useIsUploading,i as useTotalProgress,t as useUploadProgress,l as useUploadStore};