@donotdev/crud 0.0.19 → 0.0.20

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 (162) hide show
  1. package/dist/CrudService.d.ts.map +1 -1
  2. package/dist/CrudService.js +2 -2
  3. package/dist/CrudStore.js +1 -1
  4. package/dist/FieldRegistry.js +1 -1
  5. package/dist/adapters/FunctionsAdapter.js +1 -1
  6. package/dist/components/CrudButton.js +1 -1
  7. package/dist/components/CrudCard.js +1 -1
  8. package/dist/components/DateFilter.js +1 -1
  9. package/dist/components/DisplayFieldRenderer.js +1 -1
  10. package/dist/components/DisplayThumbnail.js +1 -1
  11. package/dist/components/EntityFilters.js +1 -1
  12. package/dist/components/FormFieldRenderer.js +1 -1
  13. package/dist/components/FormLayout.js +1 -1
  14. package/dist/components/controlled/complex/ControlledAddressField.js +1 -1
  15. package/dist/components/controlled/complex/ControlledDateField.js +1 -1
  16. package/dist/components/controlled/complex/ControlledFieldArrayField.js +1 -1
  17. package/dist/components/controlled/complex/ControlledGeoPointField.js +1 -1
  18. package/dist/components/controlled/complex/ControlledMapField.js +1 -1
  19. package/dist/components/controlled/complex/ControlledMultiInputField.js +1 -1
  20. package/dist/components/controlled/complex/ControlledRichTextField.js +1 -1
  21. package/dist/components/controlled/complex/ControlledTimestampField.js +1 -1
  22. package/dist/components/controlled/complex/index.js +1 -1
  23. package/dist/components/controlled/file/ControlledDocumentField.js +1 -1
  24. package/dist/components/controlled/file/ControlledFileField.js +1 -1
  25. package/dist/components/controlled/file/ControlledImageField.js +1 -1
  26. package/dist/components/controlled/file/ControlledMultiDocumentField.js +1 -1
  27. package/dist/components/controlled/file/ControlledMultiFileField.js +1 -1
  28. package/dist/components/controlled/file/ControlledMultiImageField.js +1 -1
  29. package/dist/components/controlled/file/index.js +1 -1
  30. package/dist/components/controlled/index.js +1 -1
  31. package/dist/components/controlled/input/ControlledCheckboxField.js +1 -1
  32. package/dist/components/controlled/input/ControlledCurrencyField.js +1 -1
  33. package/dist/components/controlled/input/ControlledDurationField.js +1 -1
  34. package/dist/components/controlled/input/ControlledGdprConsentField.js +1 -1
  35. package/dist/components/controlled/input/ControlledNumberField.js +1 -1
  36. package/dist/components/controlled/input/ControlledPasswordField.js +1 -1
  37. package/dist/components/controlled/input/ControlledPhoneField.js +1 -1
  38. package/dist/components/controlled/input/ControlledPriceField.js +1 -1
  39. package/dist/components/controlled/input/ControlledRangeField.js +1 -1
  40. package/dist/components/controlled/input/ControlledRatingField.js +1 -1
  41. package/dist/components/controlled/input/ControlledSwitchField.js +1 -1
  42. package/dist/components/controlled/input/ControlledTextField.js +1 -1
  43. package/dist/components/controlled/input/ControlledTextareaField.js +1 -1
  44. package/dist/components/controlled/input/index.js +1 -1
  45. package/dist/components/controlled/select/ControlledComboboxField.js +1 -1
  46. package/dist/components/controlled/select/ControlledDropdownField.js +1 -1
  47. package/dist/components/controlled/select/ControlledMultiDropdownField.js +1 -1
  48. package/dist/components/controlled/select/ControlledRadioField.js +1 -1
  49. package/dist/components/controlled/select/ControlledReferenceField.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.js +1 -1
  100. package/dist/components/form/fields/PriceFieldComponent.js +1 -1
  101. package/dist/components/form/fields/RadioFieldComponent.js +1 -1
  102. package/dist/components/form/fields/RangeFieldComponent.js +1 -1
  103. package/dist/components/form/fields/RatingFieldComponent.js +1 -1
  104. package/dist/components/form/fields/ReferenceFieldComponent.js +1 -1
  105. package/dist/components/form/fields/RichTextComponent.js +1 -1
  106. package/dist/components/form/fields/SwitchFieldComponent.js +1 -1
  107. package/dist/components/form/fields/TextAreaComponent.js +1 -1
  108. package/dist/components/form/fields/TextFieldComponent.js +1 -1
  109. package/dist/components/form/fields/TimestampFieldComponent.js +1 -1
  110. package/dist/components/form/fields/index.js +1 -1
  111. package/dist/components/form/fields/internal/TiptapEditor.js +2 -2
  112. package/dist/components/form/internal/ImageViewerDialog.js +1 -1
  113. package/dist/components/index.js +1 -1
  114. package/dist/contexts/UploadContext.js +1 -1
  115. package/dist/contexts/index.js +1 -1
  116. package/dist/fieldTypeRegistry.js +1 -1
  117. package/dist/forms/hooks/index.js +1 -1
  118. package/dist/forms/hooks/useController.js +1 -1
  119. package/dist/forms/hooks/useEntityField.js +1 -1
  120. package/dist/forms/hooks/useEntityForm.js +1 -1
  121. package/dist/forms/index.js +1 -1
  122. package/dist/forms/utils/buildInitialValues.js +1 -1
  123. package/dist/forms/utils/getFieldsForOperation.js +1 -1
  124. package/dist/forms/utils/index.js +1 -1
  125. package/dist/forms/utils/isFieldEditable.js +1 -1
  126. package/dist/forms/utils/translateFieldLabel.js +1 -1
  127. package/dist/forms/utils/validateEntity.js +1 -1
  128. package/dist/hooks/index.js +1 -1
  129. package/dist/hooks/useCrudFilters.js +1 -1
  130. package/dist/hooks/useEntityFavorites.js +1 -1
  131. package/dist/hooks/useFieldConditions.js +1 -1
  132. package/dist/hooks/useFileUpload.js +1 -1
  133. package/dist/hooks/useReferenceResolver.js +1 -1
  134. package/dist/hooks/useRelatedItems.js +1 -1
  135. package/dist/hooks/useUnsavedChangesWarning.js +1 -1
  136. package/dist/index.js +1 -1
  137. package/dist/registerBuiltinFieldTypes.js +1 -1
  138. package/dist/stores/FormStore.js +1 -1
  139. package/dist/stores/UploadStore.js +1 -1
  140. package/dist/stores/index.js +1 -1
  141. package/dist/tsconfig.tsbuildinfo +1 -1
  142. package/dist/types.js +1 -1
  143. package/dist/useBaseCrudList.js +1 -1
  144. package/dist/useCrud.js +1 -1
  145. package/dist/useCrudCardList.js +1 -1
  146. package/dist/useCrudList.js +1 -1
  147. package/dist/utils/clientListProcessing.js +1 -1
  148. package/dist/utils/collections.js +1 -1
  149. package/dist/utils/fileStorage.js +1 -1
  150. package/dist/utils/imageProcessing.js +1 -1
  151. package/dist/utils/imageStorage.js +1 -1
  152. package/dist/utils/imageUtils.js +1 -1
  153. package/dist/utils/matchesFilter.js +1 -1
  154. package/dist/utils/mergeWithOptimistic.js +1 -1
  155. package/dist/utils/sanitizeHtml.js +1 -1
  156. package/dist/utils/scopeUtils.js +1 -1
  157. package/dist/utils/uploadValidation.js +1 -1
  158. package/dist/workflows/WorkflowPersistence.js +1 -1
  159. package/dist/workflows/defineWorkflow.js +1 -1
  160. package/dist/workflows/index.js +1 -1
  161. package/dist/workflows/useEntityWorkflow.js +1 -1
  162. package/package.json +4 -4
package/dist/types.js CHANGED
@@ -1 +1 @@
1
- const E={PENDING:"pending",CONFIRMED:"confirmed",FAILED:"failed"},e={ADD:"add",UPDATE:"update",SET:"set",DELETE:"delete"};export{e as CRUD_OPERATION,E as OPTIMISTIC_STATUSES};
1
+ const e={PENDING:"pending",CONFIRMED:"confirmed",FAILED:"failed"},E={ADD:"add",UPDATE:"update",SET:"set",DELETE:"delete"};export{E as CRUD_OPERATION,e as OPTIMISTIC_STATUSES};
@@ -1 +1 @@
1
- import{useMemo as F,useCallback as G,useRef as P}from"react";import{useQuery as H}from"@donotdev/core";import{useCrudStore as J}from"./CrudStore";import{useCrud as z,getCrudServiceInstance as X,EMPTY_OPTIMISTIC as Z}from"./useCrud";import{mergeWithOptimistic as $}from"./utils/mergeWithOptimistic";import{injectScopeFilter as ee,getCurrentScopeValue as te}from"./utils/scopeUtils";import{CRUD_OPERATION as Q}from"./types";function se(R,f,t,p={}){const V=p.enabled??!0,C=z("status"),a=C==="ready",j=z(R,p),{error:q,invalidate:_,_collection:m,_schemas:g,_cacheOptions:O,_scope:b}=j,M=J(e=>e.collections[m]?.optimistic||Z),T=P(new Map([[1,null]])),h=P(0),x=te(b),v=F(()=>{if(!a||!g)return null;const e=X();if(!e)return null;const y=f==="listCard"?g.listCard:g.list,d=ee(p.queryOptions,b);if(!t||t.mode==="client")return e.getListQueryOptions(m,d,y,O,f);const o=T.current,n=h.current,{page:l,pageSize:s}=t;let i,r;if(o.has(l))i=o.get(l)??void 0,r=s;else if(l>n&&o.has(n)){const u=l-n;i=o.get(n)??void 0,r=u*s}else i=void 0,r=l*s;return e.getListQueryOptions(m,{...d,limit:r,startAfter:i},y,O,f)},[a,m,O,g?"hasSchema":"noSchema",f,t?.mode,t?.page,t?.pageSize,p.queryOptions,b?.provider,x]),{data:c,isLoading:K,isFetching:k,error:B,refetch:w}=H({queryKey:v?.queryKey??["crud",m,"disabled"],queryFn:v?.queryFn??(()=>Promise.resolve({items:[]})),staleTime:v?.staleTime,enabled:V&&!!v}),A=F(()=>{if(!c||!a)return{items:[],total:void 0};let e=c.items;if(t?.mode==="server"&&e.length>0){const s=T.current,i=h.current,{page:r,pageSize:u}=t,U=e.length;if(Math.ceil(U/u)>1||r>i){const L=s.has(r)?r:i+1;for(let S=L;S<=r;S++){const D=(S-L+1)*u-1;if(D<e.length){const Y=e[D];s.set(S+1,Y.id)}}}c.lastVisible&&s.set(r+1,c.lastVisible),h.current=Math.max(i,r);const I=s.has(r)?0:(r-i-1)*u,W=I+u;e=e.slice(I,W)}const y=$(e,M),d=new Set(e.map(s=>s.id));let o=0,n=0;for(const[s,i]of Object.entries(M))i.operation===Q.ADD&&!d.has(s)?o++:i.operation===Q.DELETE&&d.has(s)&&n++;const l=(c.total??e.length)+o-n;return{items:y,total:t?l:void 0}},[c,M,a,t?.mode,t?.page,t?.pageSize]),E=G(async()=>{a&&(t?.mode==="server"&&(T.current=new Map([[1,null]]),h.current=0),await _(),await w())},[_,w,a,t?.mode]);if(!a){const e=async()=>{};return{status:C,data:{items:[],total:void 0},items:[],loading:!1,fetching:!1,error:q,mutate:e,refresh:e,isAvailable:!1}}const N=A?.items??[];return{status:C,data:A,items:N,loading:K,fetching:k,error:B??q,mutate:E,refresh:E,isAvailable:!0}}export{se as useBaseCrudList};
1
+ import{useMemo as w,useCallback as H,useRef as x}from"react";import{useQuery as J}from"@donotdev/core";import{useCrudStore as X}from"./CrudStore";import{useCrud as Q,getCrudServiceInstance as Z,EMPTY_OPTIMISTIC as $}from"./useCrud";import{mergeWithOptimistic as ee}from"./utils/mergeWithOptimistic";import{injectScopeFilter as te,getCurrentScopeValue as se}from"./utils/scopeUtils";import{CRUD_OPERATION as R}from"./types";function de(z,m,t,p={}){const V=p.enabled??!0,I=Q("status"),c=I==="ready",j=Q(z,p),{error:P,invalidate:D,_collection:a,_schemas:g,_cacheOptions:y,_scope:S}=j,q=X(e=>e.collections[a]?.optimistic||$),v=x(new Map([[1,null]])),O=x(0),K=se(S),b=w(()=>{if(!c||!g)return null;const e=Z();if(!e)return null;const f=m==="listCard"?g.listCard:g.list,u=te(p.queryOptions,S);if(!t||t.mode==="client")return e.getListQueryOptions(a,u,f,y,m);const i=v.current,n=O.current,{page:d,pageSize:h}=t;let s,r;if(i.has(d))s=i.get(d)??void 0,r=h;else if(d>n&&i.has(n)){const o=d-n;s=i.get(n)??void 0,r=o*h}else s=void 0,r=d*h;return e.getListQueryOptions(a,{...u,limit:r,startAfter:s},f,y,m)},[c,a,y,g?"hasSchema":"noSchema",m,t?.mode,t?.page,t?.pageSize,p.queryOptions,S?.provider,K]),{data:l,isLoading:k,isFetching:B,error:N,refetch:T}=J({queryKey:b?.queryKey??["crud",a,"disabled"],queryFn:b?.queryFn??(()=>Promise.resolve({items:[]})),staleTime:b?.staleTime,enabled:V&&!!b}),A=w(()=>{if(!l||!c)return{items:[],total:void 0};let e=l.items;if(t?.mode==="server"&&e.length>0){const s=v.current,r=O.current,{page:o,pageSize:C}=t,W=e.length;if(Math.ceil(W/C)>1||o>r){const M=s.has(o)?o:r+1;for(let F=M;F<=o;F++){const _=(F-M+1)*C-1;if(_<e.length){const G=e[_];s.set(F+1,G.id)}}}l.lastVisible&&s.set(o+1,l.lastVisible),O.current=Math.max(r,o);const L=s.has(o)?0:(o-r-1)*C,Y=L+C;e=e.slice(L,Y)}const f=ee(e,q),u=new Set(e.map(s=>s.id));let i=0,n=0;for(const[s,r]of Object.entries(q))r.operation===R.ADD&&!u.has(s)?i++:r.operation===R.DELETE&&u.has(s)&&n++;const h=(l.total??e.length)+i-n;return{items:f,total:t?h:void 0}},[l,q,c,t?.mode,t?.page,t?.pageSize]),E=H(async()=>{c&&(t?.mode==="server"&&(v.current=new Map([[1,null]]),O.current=0),await D(),await T())},[D,T,c,t?.mode]);if(!c){const e=async()=>{};return{status:I,data:{items:[],total:void 0},items:[],loading:!1,fetching:!1,error:P,mutate:e,refresh:e,isAvailable:!1}}const U=A?.items??[];return{status:I,data:A,items:U,loading:k,fetching:B,error:N??P,mutate:E,refresh:E,isAvailable:!0}}export{de as useBaseCrudList};
package/dist/useCrud.js CHANGED
@@ -1 +1 @@
1
- "use client";import{useEffect as L,useMemo as F,useCallback as n}from"react";import{useFeatureConsent as W,FRAMEWORK_FEATURES as Z,FEATURE_STATUS as d,handleError as B,isClient as H,createSchemas as J,DEGRADED_CRUD_API as K}from"@donotdev/core";import{getCrudService as Q}from"./CrudService";import{useCrudStore as u}from"./CrudStore";import{injectScope as M,injectScopeFilter as V}from"./utils/scopeUtils";const X={},$={};let _=null,E=null,b=!1;function r(){return _}function ee(l,m={}){const f=W(Z.CRUD),U=u(e=>e.crudService),g=f&&!U,y=f?g?d.INITIALIZING:d.READY:d.DEGRADED,S=l==="status",p=!S&&typeof l=="object"?l:m.entity,a=S?"__status__":typeof l=="string"?l:l.collection,o=p?.scope,v=m.noCache??!1,T=m.staleTime,h=F(()=>({noCache:v,staleTime:T}),[v,T]),t=F(()=>{if(!S){if(m.schema){const e=m.schema;return{create:e,draft:e,update:e,get:e,list:e,listCard:e,delete:e}}if(p)return J(p)}},[S,m.schema,p?.name,a]),Y=u(e=>e.collections[a]?.loading||!1),A=u(e=>e.collections[a]?.error||null),O=null;L(()=>{if(!H()||!f||!t)return;const{crudService:e}=u.getState();e||_||E||(E=(async()=>{try{if(_||u.getState().crudService)return;const s=Q();_=s,s.setStore(u),await s.initialize(),b=!1,u.getState().setCrudService(s)}catch(s){b||(B(s,{userMessage:"Failed to initialize CRUD service.",context:{collection:a},severity:"error"}),b=!0)}finally{E=null}})())},[f,a,t?"hasSchema":"noSchema"]);const D=g||Y,P=y===d.READY,j=n(async e=>{const s=r();return!s||!t?null:s.get(a,e,t.get,h)},[a,t?"hasSchema":"noSchema",h]),G=n(async(e,s,c)=>{const i=r();if(!i||!t)return;const C=M(s,o),k=C?.status==="draft"?t.draft:t.create;await i.set(a,e,C,k,c)},[a,t?"hasSchema":"noSchema",o?.provider]),q=n(async(e,s,c)=>{const i=r();i&&await i.update(a,e,s,t?.update,c)},[a,t]),x=n(async(e,s)=>{const c=r();c&&await c.delete(a,e,s)},[a]),z=n(async(e,s)=>{const c=r();if(!c||!t)return"";const i=M(e,o),C=i?.status==="draft"?t.draft:t.create;return c.add(a,i,C,s)},[a,t?"hasSchema":"noSchema",o?.provider]),N=n(async e=>{const s=r();if(!s||!t)return[];const c=V(e,o);return(await s.query(a,c,t.list,h)).items},[a,t?"hasSchema":"noSchema",h,o?.provider]),R=n((e,s)=>{const c=r();return!c||!t?()=>{}:c.subscribe(a,e,s,t.get)},[a,t?"hasSchema":"noSchema"]),I=n((e,s)=>{const c=r();return!c||!t?()=>{}:c.subscribeToCollection(a,e,s,t.list)},[a,t?"hasSchema":"noSchema"]),w=n(async()=>{const e=r();e&&await e.invalidateCollection(a)},[a]);return S?y:P?{status:d.READY,data:O,loading:D,error:A,get:j,set:G,update:q,delete:x,add:z,query:N,subscribe:R,subscribeToCollection:I,invalidate:w,isAvailable:!0,_collection:a,_schemas:t,_cacheOptions:h,_scope:o}:{...K,status:y,loading:D,error:A,subscribe:R,subscribeToCollection:I,invalidate:w,_collection:a,_schemas:t,_cacheOptions:h,_scope:o}}export{X as EMPTY_DATA,$ as EMPTY_OPTIMISTIC,r as getCrudServiceInstance,ee as useCrud};
1
+ "use client";import{useEffect as V,useMemo as F,useCallback as a}from"react";import{useFeatureConsent as W,FRAMEWORK_FEATURES as Z,FEATURE_STATUS as h,handleError as $,isClient as B,createSchemas as H,DEGRADED_CRUD_API as J}from"@donotdev/core";import{getCrudService as X}from"./CrudService";import{useCrudStore as u}from"./CrudStore";import{injectScope as P,injectScopeFilter as O}from"./utils/scopeUtils";const re={},ne={};let v=null,_=null,g=!1;function i(){return v}function ae(l,d={}){const S=W(Z.CRUD),x=u(e=>e.crudService),C=S&&!x,D=S?C?h.INITIALIZING:h.READY:h.DEGRADED,m=l==="status",p=!m&&typeof l=="object"?l:d.entity,s=m?"__status__":typeof l=="string"?l:l.collection,o=p?.scope,T=d.noCache??!1,A=d.staleTime,f=F(()=>({noCache:T,staleTime:A}),[T,A]),t=F(()=>{if(!m){if(d.schema){const e=d.schema;return{create:e,draft:e,update:e,get:e,list:e,listCard:e,delete:e}}if(p)return H(p)}},[m,d.schema,p?.name,s]),M=u(e=>e.collections[s]?.loading||!1),b=u(e=>e.collections[s]?.error||null),N=null;V(()=>{if(!B()||!S||!t)return;const{crudService:e}=u.getState();e||v||_||(_=(async()=>{try{if(v||u.getState().crudService)return;const c=X();v=c,c.setStore(u),await c.initialize(),g=!1,u.getState().setCrudService(c)}catch(c){g||($(c,{userMessage:"Failed to initialize CRUD service.",context:{collection:s},severity:"error"}),g=!0)}finally{_=null}})())},[S,s,t?"hasSchema":"noSchema"]);const I=C||M,z=D===h.READY,Y=a(async e=>{const c=i();return!c||!t?null:c.get(s,e,t.get,f)},[s,t?"hasSchema":"noSchema",f]),j=a(async(e,c,r)=>{const n=i();if(!n||!t)return;const E=P(c,o),Q=E?.status==="draft"?t.draft:t.create;await n.set(s,e,E,Q,r)},[s,t?"hasSchema":"noSchema",o?.provider]),k=a(async(e,c,r)=>{const n=i();n&&await n.update(s,e,c,t?.update,r)},[s,t]),q=a(async(e,c)=>{const r=i();r&&await r.delete(s,e,c)},[s]),G=a(async(e,c)=>{const r=i();if(!r||!t)return"";const n=P(e,o),w=n?.status==="draft"?t.draft:t.create;return r.add(s,n,w,c)},[s,t?"hasSchema":"noSchema",o?.provider]),L=a(async e=>{const c=i();if(!c||!t)return[];const r=O(e,o);return(await c.query(s,r,t.list,f)).items},[s,t?"hasSchema":"noSchema",f,o?.provider]),R=a((e,c)=>{const r=i();return!r||!t?()=>{}:r.subscribe(s,e,c,t.get)},[s,t?"hasSchema":"noSchema"]),y=a((e,c)=>{const r=i();return!r||!t?()=>{}:r.subscribeToCollection(s,e,c,t.list)},[s,t?"hasSchema":"noSchema"]),U=a(async()=>{const e=i();e&&await e.invalidateCollection(s)},[s]);return m?D:z?{status:h.READY,data:N,loading:I,error:b,get:Y,set:j,update:k,delete:q,add:G,query:L,subscribe:R,subscribeToCollection:y,invalidate:U,isAvailable:!0,_collection:s,_schemas:t,_cacheOptions:f,_scope:o}:{...J,status:D,loading:I,error:b,subscribe:R,subscribeToCollection:y,invalidate:U,_collection:s,_schemas:t,_cacheOptions:f,_scope:o}}export{re as EMPTY_DATA,ne as EMPTY_OPTIMISTIC,i as getCrudServiceInstance,ae as useCrud};
@@ -1 +1 @@
1
- import{useMemo as d}from"react";import{useBaseCrudList as p}from"./useBaseCrudList";import{useCrudFilters as f}from"./hooks/useCrudFilters";import{applyFilters as h,applySearch as y,applySort as g}from"./utils/clientListProcessing";function C(a,t={}){const o={enabled:t.enabled,queryOptions:t.queryOptions,schema:t.schema,entity:t.entity,staleTime:t.staleTime,noCache:t.noCache},e=p(a,"listCard",null,o),s=typeof a=="string"?null:a,n=s?.collection??a,{filters:l}=f({collection:n}),i=t.clientSort===null?null:t.clientSort??s?.defaultSort??null,{processed:u,filteredTotal:c}=d(()=>{let r=e.items;s&&Object.keys(l).length>0&&(r=h(r,l,s)),s&&t.searchQuery&&(r=y(r,t.searchQuery,s));const m=r.length;return i&&(r=g(r,i)),{processed:r,filteredTotal:m}},[e.items,l,t.searchQuery,i,s]);return{status:e.status,data:e.data?{items:e.data.items}:null,items:e.items,processed:u,filteredTotal:c,loading:e.loading,fetching:e.fetching,error:e.error,mutate:e.mutate,refresh:e.refresh,isAvailable:e.isAvailable}}export{C as useCrudCardList};
1
+ import{useMemo as o}from"react";import{useBaseCrudList as f}from"./useBaseCrudList";import{useCrudFilters as h}from"./hooks/useCrudFilters";import{applyFilters as y,applySearch as g,applySort as p}from"./utils/clientListProcessing";function v(l,t={}){const u={enabled:t.enabled,queryOptions:t.queryOptions,schema:t.schema,entity:t.entity,staleTime:t.staleTime,noCache:t.noCache},e=f(l,"listCard",null,u),s=typeof l=="string"?null:l,c=s?.collection??l,{filters:a}=h({collection:c}),i=t.clientSort===null?null:t.clientSort??s?.defaultSort??null,{processed:n,filteredTotal:m}=o(()=>{let r=e.items;s&&Object.keys(a).length>0&&(r=y(r,a,s)),s&&t.searchQuery&&(r=g(r,t.searchQuery,s));const d=r.length;return i&&(r=p(r,i)),{processed:r,filteredTotal:d}},[e.items,a,t.searchQuery,i,s]);return{status:e.status,data:e.data?{items:e.data.items}:null,items:e.items,processed:n,filteredTotal:m,loading:e.loading,fetching:e.fetching,error:e.error,mutate:e.mutate,refresh:e.refresh,isAvailable:e.isAvailable}}export{v as useCrudCardList};
@@ -1 +1 @@
1
- import{useMemo as h}from"react";import{useBaseCrudList as g}from"./useBaseCrudList";import{useCrudFilters as S}from"./hooks/useCrudFilters";import{applyFilters as T,applySearch as C,applySort as b}from"./utils/clientListProcessing";function Q(l,e={}){const i=e.pagination??"client",n=e.page??1,c=e.pageSize??10,p={mode:i,page:n,pageSize:c},u={enabled:e.enabled,queryOptions:e.queryOptions,schema:e.schema,entity:e.entity,staleTime:e.staleTime,noCache:e.noCache},s=g(l,"list",p,u),r=typeof l=="string"?null:l,m=r?.collection??l,{filters:o}=S({collection:m}),a=e.clientSort===null?null:e.clientSort??r?.defaultSort??null,{processed:d,filteredTotal:y}=h(()=>{let t=s.items;r&&Object.keys(o).length>0&&(t=T(t,o,r)),r&&e.searchQuery&&(t=C(t,e.searchQuery,r));const f=t.length;return a&&(t=b(t,a)),{processed:t,filteredTotal:f}},[s.items,o,e.searchQuery,a,r]);return{...s,processed:d,filteredTotal:y}}export{Q as useCrudList};
1
+ import{useMemo as h}from"react";import{useBaseCrudList as y}from"./useBaseCrudList";import{useCrudFilters as S}from"./hooks/useCrudFilters";import{applyFilters as b,applySearch as T,applySort as Q}from"./utils/clientListProcessing";function L(s,e={}){const n=e.pagination??"client",u=e.page??1,i=e.pageSize??10,o={mode:n,page:u,pageSize:i},m={enabled:e.enabled,queryOptions:e.queryOptions,schema:e.schema,entity:e.entity,staleTime:e.staleTime,noCache:e.noCache},a=y(s,"list",o,m),r=typeof s=="string"?null:s,d=r?.collection??s,{filters:l}=S({collection:d}),c=e.clientSort===null?null:e.clientSort??r?.defaultSort??null,{processed:f,filteredTotal:p}=h(()=>{let t=a.items;r&&Object.keys(l).length>0&&(t=b(t,l,r)),r&&e.searchQuery&&(t=T(t,e.searchQuery,r));const g=t.length;return c&&(t=Q(t,c)),{processed:t,filteredTotal:g}},[a.items,l,e.searchQuery,c,r]);return{...a,processed:f,filteredTotal:p}}export{L as useCrudList};
@@ -1 +1 @@
1
- import{matchesFilter as u}from"./matchesFilter";import{getValueType as f}from"../fieldTypeRegistry";function d(t,i,a){const o=Object.entries(i);return o.length===0?t:t.filter(n=>o.every(([r,l])=>{const e=a.fields[r]?.type||"text";return u(n[r],l,e)}))}function c(t){if(t.search?.fields&&t.search.fields.length>0)return t.search.fields;const i=new Set(["string"]),a=[];for(const[o,n]of Object.entries(t.fields)){if(n.visibility==="hidden"||n.visibility==="technical")continue;const r=f(n.type);r&&i.has(r)&&a.push(o)}return a}function m(t,i,a){if(!i||i.trim()==="")return t;const o=i.toLowerCase(),n=c(a);return n.length===0?t.filter(r=>Object.values(r).some(l=>l==null?!1:String(l).toLowerCase().includes(o))):t.filter(r=>n.some(l=>{const e=r[l];return e==null?!1:typeof e=="object"&&"formatted_address"in e?String(e.formatted_address).toLowerCase().includes(o):String(e).toLowerCase().includes(o)}))}function p(t,i){const{field:a,direction:o="asc"}=i,n=o==="desc"?-1:1;return[...t].sort((r,l)=>{const e=r[a],s=l[a];return e==null&&s==null?0:e==null?1:s==null?-1:typeof e=="number"&&typeof s=="number"?(e-s)*n:typeof e=="object"&&"amount"in e&&typeof s=="object"&&"amount"in s?(e.amount-s.amount)*n:e instanceof Date&&s instanceof Date?(e.getTime()-s.getTime())*n:String(e).localeCompare(String(s))*n})}export{d as applyFilters,m as applySearch,p as applySort,c as getSearchableFields};
1
+ import{matchesFilter as u}from"./matchesFilter";import{getValueType as c}from"../fieldTypeRegistry";function g(t,l,s){const o=Object.entries(l);return o.length===0?t:t.filter(r=>o.every(([i,f])=>{const n=s.fields[i]?.type||"text";return u(r[i],f,n)}))}function a(t){if(t.search?.fields&&t.search.fields.length>0)return t.search.fields;const l=new Set(["string"]),s=[];for(const[o,r]of Object.entries(t.fields)){if(r.visibility==="hidden"||r.visibility==="technical")continue;const i=c(r.type);i&&l.has(i)&&s.push(o)}return s}function h(t,l,s){if(!l||l.trim()==="")return t;const o=l.toLowerCase(),r=a(s);return r.length===0?t.filter(i=>Object.values(i).some(f=>f==null?!1:String(f).toLowerCase().includes(o))):t.filter(i=>r.some(f=>{const e=i[f];return e==null?!1:typeof e=="object"&&"formatted_address"in e?String(e.formatted_address).toLowerCase().includes(o):String(e).toLowerCase().includes(o)}))}function b(t,l){const{field:s,direction:o="asc"}=l,r=o==="desc"?-1:1;return[...t].sort((i,f)=>{const e=i[s],n=f[s];return e==null&&n==null?0:e==null?1:n==null?-1:typeof e=="number"&&typeof n=="number"?(e-n)*r:typeof e=="object"&&"amount"in e&&typeof n=="object"&&"amount"in n?(e.amount-n.amount)*r:e instanceof Date&&n instanceof Date?(e.getTime()-n.getTime())*r:String(e).localeCompare(String(n))*r})}export{g as applyFilters,h as applySearch,b as applySort,a as getSearchableFields};
@@ -1 +1 @@
1
- import{getCrudService as c}from"../CrudService";async function d(r,n){const a=c(),e=[],t=n.range?.start??1,s=n.range?.end??28;for(let o=t;o<=s;o++){const m=String(o),i=await a.get(n.path(r),m,n.schema);i&&e.push(i)}return e}async function h(r,n,a){const e=c();for(const t of a){const s=n.idOf(t);await e.set(n.path(r),s,t,n.schema)}}async function p(r,n,a){const e=c();if(n.idFrom){const t=n.idFrom(a);return e.set(n.path(r),t,a,n.schema)}return e.add(n.path(r),a,n.schema)}export{p as appendToCollection,d as loadDeterministicRange,h as upsertDeterministic};
1
+ import{getCrudService as o}from"../CrudService";async function u(s,t){const e=o(),r=[],a=t.range?.start??1,n=t.range?.end??28;for(let c=a;c<=n;c++){const i=String(c),d=await e.get(t.path(s),i,t.schema);d&&r.push(d)}return r}async function m(s,t,e){const r=o();for(const a of e){const n=t.idOf(a);await r.set(t.path(s),n,a,t.schema)}}async function h(s,t,e){const r=o();if(t.idFrom){const a=t.idFrom(e);return r.set(t.path(s),a,e,t.schema)}return r.add(t.path(s),e,t.schema)}export{h as appendToCollection,u as loadDeterministicRange,m as upsertDeterministic};
@@ -1 +1 @@
1
- "use client";import{handleError as d,hasProvider as u,getProvider as f}from"@donotdev/core";function y(e){return e.replace(/[^a-zA-Z0-9.-]/g,"_").replace(/_{2,}/g,"_").toLowerCase()}async function m(e,t={}){const{storagePath:r="uploads/files",filename:s,onProgress:o}=t,n=Date.now(),i=y(e.name),l=s||`${n}_${i}`,c=`${r}/${l}`;try{let a;if(u("storage"))a=(await f("storage").upload(e,{storagePath:r,filename:l,onProgress:o?p=>o({bytesTransferred:0,totalBytes:0,progress:p}):void 0})).url;else{const{uploadFileResumable:p}=await import("@donotdev/firebase"),{promise:w}=p(e,{basePath:r,filename:l,onProgress:o,metadata:{contentType:e.type}});a=(await w).url}return{url:a,filename:e.name,size:e.size,mimeType:e.type,uploadedAt:new Date().toISOString()}}catch(a){throw d(a,{userMessage:"Failed to upload file",severity:"error",context:{filename:e.name,fileSize:e.size}})}}async function v(e,t={}){const r=[],s=e.reduce((n,i)=>n+i.size,0);let o=0;for(const n of e){const i=t.onProgress?c=>{const a=c.bytesTransferred/c.totalBytes*n.size;t.onProgress({bytesTransferred:o+a,totalBytes:s,progress:(o+a)/s*100})}:void 0,l=await m(n,{...t,onProgress:i});r.push(l),o+=n.size}return r}async function F(e){try{if(u("storage"))await f("storage").delete(e.url);else{const{deleteFileByUrl:t}=await import("@donotdev/firebase");await t(e.url)}}catch(t){throw d(t,{userMessage:"Failed to delete file",severity:"error",context:{url:e.url,filename:e.filename}}),t}}function M(){return`${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function g(e){const t=e.split(".");return t.length>1?t.pop().toLowerCase():""}function P(e,t){const r=t?g(t):"";if(e){if(e.startsWith("image/"))return"image";if(e.startsWith("video/"))return"video";if(e.startsWith("audio/"))return"audio";if(e==="application/pdf")return"pdf";if(e.includes("word")||e.includes("document"))return"doc";if(e.includes("excel")||e.includes("spreadsheet"))return"xls";if(e.includes("powerpoint")||e.includes("presentation"))return"ppt"}switch(r){case"pdf":return"pdf";case"doc":case"docx":return"doc";case"xls":case"xlsx":case"csv":return"xls";case"ppt":case"pptx":return"ppt";case"md":case"txt":return"text";case"html":case"htm":return"html";case"zip":case"rar":case"7z":return"archive";default:return"file"}}function z(e){if(e===0)return"0 B";const t=1024,r=["B","KB","MB","GB"],s=Math.floor(Math.log(e)/Math.log(t));return`${parseFloat((e/Math.pow(t,s)).toFixed(1))} ${r[s]}`}const h=["application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","text/plain","text/markdown","text/html","text/csv"],x=[".pdf",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".txt",".md",".html",".csv"];function B(){return[...h,...x].join(",")}export{x as DOCUMENT_EXTENSIONS,h as DOCUMENT_MIME_TYPES,F as deleteFile,z as formatFileSize,M as generateFileId,B as getDocumentAcceptString,g as getFileExtension,P as getFileIcon,m as uploadFile,v as uploadFiles};
1
+ "use client";import{handleError as d,hasProvider as f,getProvider as x}from"@donotdev/core";function m(e){return e.replace(/[^a-zA-Z0-9.-]/g,"_").replace(/_{2,}/g,"_").toLowerCase()}async function g(e,t={}){const{storagePath:r="uploads/files",filename:n,onProgress:s}=t,a=Date.now(),i=m(e.name),c=n||`${a}_${i}`,l=`${r}/${c}`;try{let o;if(f("storage"))o=(await x("storage").upload(e,{storagePath:r,filename:c,onProgress:s?u=>s({bytesTransferred:0,totalBytes:0,progress:u}):void 0})).url;else{const{uploadFileResumable:p}=await import("@donotdev/firebase"),{promise:u}=p(e,{basePath:r,filename:c,onProgress:s,metadata:{contentType:e.type}});o=(await u).url}return{url:o,filename:e.name,size:e.size,mimeType:e.type,uploadedAt:new Date().toISOString()}}catch(o){throw d(o,{userMessage:"Failed to upload file",severity:"error",context:{filename:e.name,fileSize:e.size}})}}async function P(e,t={}){const r=[],n=e.reduce((a,i)=>a+i.size,0);let s=0;for(const a of e){const i=t.onProgress?l=>{const o=l.bytesTransferred/l.totalBytes*a.size;t.onProgress({bytesTransferred:s+o,totalBytes:n,progress:(s+o)/n*100})}:void 0,c=await g(a,{...t,onProgress:i});r.push(c),s+=a.size}return r}async function M(e){try{if(f("storage"))await x("storage").delete(e.url);else{const{deleteFileByUrl:t}=await import("@donotdev/firebase");await t(e.url)}}catch(t){throw d(t,{userMessage:"Failed to delete file",severity:"error",context:{url:e.url,filename:e.filename}}),t}}function S(){return`${Date.now()}-${Math.random().toString(36).slice(2,9)}`}function h(e){const t=e.split(".");return t.length>1?t.pop().toLowerCase():""}function B(e,t){const r=t?h(t):"";if(e){if(e.startsWith("image/"))return"image";if(e.startsWith("video/"))return"video";if(e.startsWith("audio/"))return"audio";if(e==="application/pdf")return"pdf";if(e.includes("word")||e.includes("document"))return"doc";if(e.includes("excel")||e.includes("spreadsheet"))return"xls";if(e.includes("powerpoint")||e.includes("presentation"))return"ppt"}switch(r){case"pdf":return"pdf";case"doc":case"docx":return"doc";case"xls":case"xlsx":case"csv":return"xls";case"ppt":case"pptx":return"ppt";case"md":case"txt":return"text";case"html":case"htm":return"html";case"zip":case"rar":case"7z":return"archive";default:return"file"}}function E(e){if(e===0)return"0 B";const t=1024,r=["B","KB","MB","GB"],n=Math.floor(Math.log(e)/Math.log(t));return`${parseFloat((e/Math.pow(t,n)).toFixed(1))} ${r[n]}`}const w=["application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation","text/plain","text/markdown","text/html","text/csv"],z=[".pdf",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".txt",".md",".html",".csv"];function $(){return[...w,...z].join(",")}export{z as DOCUMENT_EXTENSIONS,w as DOCUMENT_MIME_TYPES,M as deleteFile,E as formatFileSize,S as generateFileId,$ as getDocumentAcceptString,h as getFileExtension,B as getFileIcon,g as uploadFile,P as uploadFiles};
@@ -1 +1 @@
1
- async function f(a,o={}){const{maxWidth:h=1920,maxHeight:n=1440,thumbWidth:l=300,thumbHeight:t=225,aspectRatio:e=4/3,quality:d=.85,crop:r}=o;return new Promise((w,c)=>{const i=new Image,s=new FileReader;s.onload=g=>{i.src=g.target?.result},s.onerror=()=>c(new Error("Failed to read file")),i.onload=async()=>{try{const{width:g,height:m}=v(r?r.width:i.width,r?r.height:i.height,h,n,e),F=await u(i,g,m,e,d,r),b=await u(i,l,t,e,.65,r);w({fullBlob:F,thumbBlob:b,width:g,height:m})}catch(g){c(g)}},i.onerror=()=>c(new Error("Failed to load image")),s.readAsDataURL(a)})}function v(a,o,h,n,l){let t=a,e=o;t>h&&(e=h/t*e,t=h),e>n&&(t=n/e*t,e=n);const d=t/e;return Math.abs(d-l)>.01&&(d>l?e=t/l:t=e*l),{width:Math.round(t),height:Math.round(e)}}async function u(a,o,h,n,l,t){const e=document.createElement("canvas"),d=e.getContext("2d");if(!d)throw new Error("Failed to get canvas context");e.width=o,e.height=h,d.fillStyle="#FFFFFF",d.fillRect(0,0,o,h);let r,w,c,i;if(t)r=t.x,w=t.y,c=t.width,i=t.height;else{const s=a.width/a.height;c=a.width,i=a.height,r=0,w=0,s>n?(c=a.height*n,r=(a.width-c)/2):s<n&&(i=a.width/n,w=(a.height-i)/2)}return d.drawImage(a,r,w,c,i,0,0,o,h),new Promise((s,g)=>{e.toBlob(m=>{m?s(m):g(new Error("Failed to convert canvas to blob"))},"image/webp",l)})}function x(a,o){return a.type.startsWith("image/")?o&&a.size>o?{valid:!1,error:`File size exceeds ${(o/1048576).toFixed(1)}MB limit`}:{valid:!0}:{valid:!1,error:"File must be an image"}}export{f as processImage,x as validateImageFile};
1
+ async function v(i,r={}){const{maxWidth:h=1920,maxHeight:l=1440,thumbWidth:d=300,thumbHeight:t=225,aspectRatio:e=4/3,quality:a=.85,crop:o}=r;return new Promise((w,s)=>{const n=new Image,c=new FileReader;c.onload=u=>{n.src=u.target?.result},c.onerror=()=>s(new Error("Failed to read file")),n.onload=async()=>{try{const{width:u,height:f}=m(o?o.width:n.width,o?o.height:n.height,h,l,e),b=await F(n,u,f,e,a,o),g=await F(n,d,t,e,.65,o);w({fullBlob:b,thumbBlob:g,width:u,height:f})}catch(u){s(u)}},n.onerror=()=>s(new Error("Failed to load image")),c.readAsDataURL(i)})}function m(i,r,h,l,d){let t=i,e=r;t>h&&(e=h/t*e,t=h),e>l&&(t=l/e*t,e=l);const a=t/e;return Math.abs(a-d)>.01&&(a>d?e=t/d:t=e*d),{width:Math.round(t),height:Math.round(e)}}async function F(i,r,h,l,d,t){const e=document.createElement("canvas"),a=e.getContext("2d");if(!a)throw new Error("Failed to get canvas context");e.width=r,e.height=h,a.fillStyle="#FFFFFF",a.fillRect(0,0,r,h);let o,w,s,n;if(t)o=t.x,w=t.y,s=t.width,n=t.height;else{const c=i.width/i.height;s=i.width,n=i.height,o=0,w=0,c>l?(s=i.height*l,o=(i.width-s)/2):c<l&&(n=i.width/l,w=(i.height-n)/2)}return a.drawImage(i,o,w,s,n,0,0,r,h),new Promise((c,u)=>{e.toBlob(f=>{f?c(f):u(new Error("Failed to convert canvas to blob"))},"image/webp",d)})}function x(i,r){return i.type.startsWith("image/")?r&&i.size>r?{valid:!1,error:`File size exceeds ${(r/1048576).toFixed(1)}MB limit`}:{valid:!0}:{valid:!1,error:"File must be an image"}}export{v as processImage,x as validateImageFile};
@@ -1 +1 @@
1
- import{handleError as _,hasProvider as w,getProvider as m}from"@donotdev/core";function v(e){return e.replace(/[^a-zA-Z0-9.-]/g,"_").replace(/_{2,}/g,"_").toLowerCase()}async function B(e,t,o,d={}){const{storagePath:i="uploads/images",filename:f,onProgress:a}=d,y=Date.now(),r=(f||`${y}_${v(o)}`).replace(/\.[^/.]+$/,""),b=`${i}/${r}_full.webp`,h=`${i}/${r}_thumb.webp`;try{const g=new File([e],`${r}_full.webp`,{type:"image/webp"}),s=new File([t],`${r}_thumb.webp`,{type:"image/webp"});let n,u;if(w("storage")){const l=m("storage");n=(await l.upload(g,{storagePath:i,filename:`${r}_full.webp`,onProgress:a?p=>a({bytesTransferred:0,totalBytes:0,progress:p*.5}):void 0})).url,u=(await l.upload(s,{storagePath:i,filename:`${r}_thumb.webp`,onProgress:a?p=>a({bytesTransferred:0,totalBytes:0,progress:50+p*.5}):void 0})).url}else{const{uploadFileResumable:l}=await import("@donotdev/firebase"),p=a?c=>{a({bytesTransferred:c.bytesTransferred,totalBytes:c.totalBytes*2,progress:c.progress*.5})}:void 0,{promise:U}=l(g,{basePath:i,filename:`${r}_full.webp`,onProgress:p,metadata:{contentType:"image/webp"}});n=(await U).url;const P=a?c=>{a({bytesTransferred:c.bytesTransferred+e.size,totalBytes:e.size+t.size,progress:50+c.progress*.5})}:void 0,{promise:$}=l(s,{basePath:i,filename:`${r}_thumb.webp`,onProgress:P,metadata:{contentType:"image/webp"}});u=(await $).url}return{fullUrl:n,thumbUrl:u}}catch(g){try{if(w("storage")){const s=m("storage");await s.delete(b).catch(()=>{}),await s.delete(h).catch(()=>{})}else{const{getFileUrl:s,deleteFileByUrl:n}=await import("@donotdev/firebase"),u=await s(b).catch(()=>null),l=await s(h).catch(()=>null);u&&await n(u).catch(()=>{}),l&&await n(l).catch(()=>{})}}catch{}throw g}}async function F(e){try{if(w("storage")){const t=m("storage"),o=[t.delete(e.fullUrl)];e.thumbUrl&&o.push(t.delete(e.thumbUrl)),await Promise.all(o)}else{const{deleteFileByUrl:t}=await import("@donotdev/firebase"),o=[t(e.fullUrl)];e.thumbUrl&&o.push(t(e.thumbUrl)),await Promise.all(o)}}catch(t){throw _(t,{userMessage:"Failed to delete image",severity:"error",context:{fullUrl:e.fullUrl,thumbUrl:e.thumbUrl}}),t}}export{F as deleteImage,B as uploadImage};
1
+ import{handleError as F,hasProvider as f,getProvider as h}from"@donotdev/core";function R(e){return e.replace(/[^a-zA-Z0-9.-]/g,"_").replace(/_{2,}/g,"_").toLowerCase()}async function B(e,t,o,y={}){const{storagePath:n="uploads/images",filename:P,onProgress:a}=y,U=Date.now(),l=(P||`${U}_${R(o)}`).replace(/\.[^/.]+$/,""),d=`${n}/${l}_full.webp`,g=`${n}/${l}_thumb.webp`;try{const c=new File([e],`${l}_full.webp`,{type:"image/webp"}),s=new File([t],`${l}_thumb.webp`,{type:"image/webp"});let i,u;if(f("storage")){const r=h("storage");i=(await r.upload(c,{storagePath:n,filename:`${l}_full.webp`,onProgress:a?b=>a({bytesTransferred:0,totalBytes:0,progress:b*.5}):void 0})).url,u=(await r.upload(s,{storagePath:n,filename:`${l}_thumb.webp`,onProgress:a?b=>a({bytesTransferred:0,totalBytes:0,progress:50+b*.5}):void 0})).url}else{const{uploadFileResumable:r}=await import("@donotdev/firebase"),w=a?m=>{a({bytesTransferred:m.bytesTransferred,totalBytes:m.totalBytes*2,progress:m.progress*.5})}:void 0,{promise:p}=r(c,{basePath:n,filename:`${l}_full.webp`,onProgress:w,metadata:{contentType:"image/webp"}});i=(await p).url;const $=a?m=>{a({bytesTransferred:m.bytesTransferred+e.size,totalBytes:e.size+t.size,progress:50+m.progress*.5})}:void 0,{promise:_}=r(s,{basePath:n,filename:`${l}_thumb.webp`,onProgress:$,metadata:{contentType:"image/webp"}});u=(await _).url}return{fullUrl:i,thumbUrl:u}}catch(c){try{if(f("storage")){const s=h("storage");await s.delete(d).catch(()=>{}),await s.delete(g).catch(()=>{})}else{const{getFileUrl:s,deleteFileByUrl:i}=await import("@donotdev/firebase"),u=await s(d).catch(()=>null),r=await s(g).catch(()=>null);u&&await i(u).catch(()=>{}),r&&await i(r).catch(()=>{})}}catch{}throw c}}async function v(e){try{if(f("storage")){const t=h("storage"),o=[t.delete(e.fullUrl)];e.thumbUrl&&o.push(t.delete(e.thumbUrl)),await Promise.all(o)}else{const{deleteFileByUrl:t}=await import("@donotdev/firebase"),o=[t(e.fullUrl)];e.thumbUrl&&o.push(t(e.thumbUrl)),await Promise.all(o)}}catch(t){throw F(t,{userMessage:"Failed to delete image",severity:"error",context:{fullUrl:e.fullUrl,thumbUrl:e.thumbUrl}}),t}}export{v as deleteImage,B as uploadImage};
@@ -1 +1 @@
1
- async function d(e){const t=await e.arrayBuffer(),r=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(r)).map(a=>a.toString(16).padStart(2,"0")).join("")}function h(e){return URL.createObjectURL(e)}function u(e){e.startsWith("blob:")&&URL.revokeObjectURL(e)}async function l(e){return new Promise((t,r)=>{const a=new Image,i=new FileReader;i.onload=n=>{if(!n.target?.result){r(new Error("Failed to read file"));return}a.src=n.target.result},i.onerror=()=>r(new Error("Failed to read file")),a.onload=()=>{const n=document.createElement("canvas"),o=n.getContext("2d");if(!o){r(new Error("Failed to get canvas context"));return}n.width=a.height,n.height=a.width,o.translate(n.width/2,n.height/2),o.rotate(Math.PI/2),o.drawImage(a,-a.width/2,-a.height/2),n.toBlob(s=>{if(s){const c=new File([s],e.name,{type:e.type,lastModified:Date.now()});t(c)}else r(new Error("Failed to create blob from canvas"))},e.type,.95)},a.onerror=()=>r(new Error("Failed to load image")),i.readAsDataURL(e)})}class g{undoStack=[];redoStack=[];maxStackSize=50;push(t){this.undoStack.push(t),this.undoStack.length>this.maxStackSize&&this.undoStack.shift(),this.redoStack=[]}undo(){const t=this.undoStack.pop();return t?(this.redoStack.push(t),t):null}redo(){const t=this.redoStack.pop();return t?(this.undoStack.push(t),t):null}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}clear(){this.undoStack=[],this.redoStack=[]}}function S(e,t){return e.filter(r=>r.hash===t)}function w(){return`img_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}export{g as UndoRedoManager,h as createPreviewURL,S as findDuplicatesByHash,d as generateFileHash,w as generateImageId,u as revokePreviewURL,l as rotateImage90};
1
+ async function d(e){const t=await e.arrayBuffer(),r=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(r)).map(o=>o.toString(16).padStart(2,"0")).join("")}function h(e){return URL.createObjectURL(e)}function u(e){e.startsWith("blob:")&&URL.revokeObjectURL(e)}async function l(e){return new Promise((t,r)=>{const a=new Image,o=new FileReader;o.onload=n=>{if(!n.target?.result){r(new Error("Failed to read file"));return}a.src=n.target.result},o.onerror=()=>r(new Error("Failed to read file")),a.onload=()=>{const n=document.createElement("canvas"),i=n.getContext("2d");if(!i){r(new Error("Failed to get canvas context"));return}n.width=a.height,n.height=a.width,i.translate(n.width/2,n.height/2),i.rotate(Math.PI/2),i.drawImage(a,-a.width/2,-a.height/2),n.toBlob(s=>{if(s){const c=new File([s],e.name,{type:e.type,lastModified:Date.now()});t(c)}else r(new Error("Failed to create blob from canvas"))},e.type,.95)},a.onerror=()=>r(new Error("Failed to load image")),o.readAsDataURL(e)})}class f{undoStack=[];redoStack=[];maxStackSize=50;push(t){this.undoStack.push(t),this.undoStack.length>this.maxStackSize&&this.undoStack.shift(),this.redoStack=[]}undo(){const t=this.undoStack.pop();return t?(this.redoStack.push(t),t):null}redo(){const t=this.redoStack.pop();return t?(this.undoStack.push(t),t):null}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}clear(){this.undoStack=[],this.redoStack=[]}}function g(e,t){return e.filter(r=>r.hash===t)}function p(){return`img_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}export{f as UndoRedoManager,h as createPreviewURL,g as findDuplicatesByHash,d as generateFileHash,p as generateImageId,u as revokePreviewURL,l as rotateImage90};
@@ -1 +1 @@
1
- import{getFilterType as N}from"../fieldTypeRegistry";function T(e,t,r){if(!t)return!0;if(Array.isArray(t)){if(t.length===0)return!0;if(!(N(r)==="range"&&(r==="date"||r==="datetime-local"||r==="timestamp")))return t.some(i=>{if(typeof i=="object"&&"date"in i){const g=i.date;return(e instanceof Date?e.toISOString().split("T")[0]:new Date(e).toISOString().split("T")[0])===g}return String(e)===String(i)});const a=e instanceof Date?e.toISOString().split("T")[0]:new Date(e).toISOString().split("T")[0];return t.some(i=>typeof i=="string"?a===i:typeof i=="object"&&"date"in i?a===i.date:!1)}if(typeof t=="object"&&"date"in t&&!("min"in t)&&!Array.isArray(t)){if(!(N(r)==="range"&&(r==="date"||r==="datetime-local"||r==="timestamp")))return!1;const a=t.date;if(!a)return!0;if(e==null)return!1;const i=e instanceof Date?e.toISOString().split("T")[0]:new Date(e).toISOString().split("T")[0];if((r==="datetime-local"||r==="timestamp")&&t.time){const g=e instanceof Date?e.toISOString().slice(11,16):new Date(e).toISOString().slice(11,16);return i===a&&g===t.time}return i===a}if(typeof t=="object"&&"min"in t){const a=N(r);if(!a)return!0;const i=a==="range"&&(r==="date"||r==="datetime-local"||r==="timestamp"),g=a==="range"&&!i,w=r==="price",f=w&&e!=null&&typeof e=="object"?Number(e.amount):g&&e!=null?typeof e=="number"?e:Number(e):NaN;if(g||w){if(typeof t.min=="object"&&t.min!==null&&"date"in t.min)return!1;const n=t,l=typeof n.min=="string"&&n.min!=="",c=typeof n.max=="string"&&n.max!=="";return l&&!c?e==null||isNaN(f)?!1:f>=Number(n.min):!l&&c?e==null?!0:isNaN(f)?!1:f<=Number(n.max):l&&c?e==null||isNaN(f)?!1:f>=Number(n.min)&&f<=Number(n.max):!0}if(i){if(typeof t.min=="object"&&t.min!==null&&"date"in t.min&&!("min"in t.min)){const o=t,u=o.min,s=o.max,D=u?.date&&u.date!=="",S=s?.date&&s.date!=="";if(D&&!S){if(e==null)return!1;const m=e instanceof Date?e:new Date(e);if(isNaN(m.getTime()))return!1;const d=new Date(u.date+(u.time?`T${u.time}:00`:"T00:00:00"));return m>=d}if(!D&&S&&s){if(e==null)return!0;const m=e instanceof Date?e:new Date(e);if(isNaN(m.getTime()))return!1;const d=new Date(s.date+(s.time?`T${s.time}:00`:"T23:59:59"));return m<=d}if(D&&S&&s){if(e==null)return!1;const m=e instanceof Date?e:new Date(e);if(isNaN(m.getTime()))return!1;const d=new Date(u.date+(u.time?`T${u.time}:00`:"T00:00:00")),y=new Date(s.date+(s.time?`T${s.time}:00`:"T23:59:59"));return m>=d&&m<=y}return!0}const n=t,l=typeof n.min=="string"&&n.min!=="",c=typeof n.max=="string"&&n.max!=="";if(l&&!c){if(e==null)return!1;const o=e instanceof Date?e:new Date(e);return isNaN(o.getTime())?!1:o>=new Date(n.min)}if(!l&&c){if(e==null)return!0;const o=e instanceof Date?e:new Date(e);return isNaN(o.getTime())?!1:o<=new Date(n.max)}if(l&&c){if(e==null)return!1;const o=e instanceof Date?e:new Date(e);return isNaN(o.getTime())?!1:o>=new Date(n.min)&&o<=new Date(n.max)}return!0}}if(typeof t=="string"&&N(r)==="rating"){if(e==null)return!1;const a=Number(t),i=typeof e=="number"?e:Number(e);return isNaN(a)||isNaN(i)?!0:i>=a}const p=N(r);if(!p)return!0;if(p==="address")return e==null?!1:typeof e=="object"&&"formatted_address"in e?String(e.formatted_address).toLowerCase().includes(String(t).toLowerCase()):!1;if(p==="multiselect"){if(!Array.isArray(e)||e.length===0)return!1;const a=String(t).toLowerCase();return e.some(i=>String(i).toLowerCase().includes(a))}return e==null?!1:String(e).toLowerCase().includes(String(t).toLowerCase())}export{T as matchesFilter};
1
+ import{getFilterType as w}from"../fieldTypeRegistry";function T(n,t,e){if(!t)return!0;if(Array.isArray(t)){if(t.length===0)return!0;if(!(w(e)==="range"&&(e==="date"||e==="datetime-local"||e==="timestamp")))return t.some(s=>{if(typeof s=="object"&&"date"in s){const i=s.date;return(n instanceof Date?n.toISOString().split("T")[0]:new Date(n).toISOString().split("T")[0])===i}return String(n)===String(s)});const d=n instanceof Date?n.toISOString().split("T")[0]:new Date(n).toISOString().split("T")[0];return t.some(s=>typeof s=="string"?d===s:typeof s=="object"&&"date"in s?d===s.date:!1)}if(typeof t=="object"&&"date"in t&&!("min"in t)&&!Array.isArray(t)){if(!(w(e)==="range"&&(e==="date"||e==="datetime-local"||e==="timestamp")))return!1;const d=t.date;if(!d)return!0;if(n==null)return!1;const s=n instanceof Date?n.toISOString().split("T")[0]:new Date(n).toISOString().split("T")[0];if((e==="datetime-local"||e==="timestamp")&&t.time){const i=n instanceof Date?n.toISOString().slice(11,16):new Date(n).toISOString().slice(11,16);return s===d&&i===t.time}return s===d}if(typeof t=="object"&&"min"in t){const a=w(e);if(!a)return!0;const c=a==="range"&&(e==="date"||e==="datetime-local"||e==="timestamp"),d=a==="range"&&!c,s=e==="price",i=s&&n!=null&&typeof n=="object"?Number(n.amount):d&&n!=null?typeof n=="number"?n:Number(n):NaN;if(d||s){if(typeof t.min=="object"&&t.min!==null&&"date"in t.min)return!1;const r=t,N=typeof r.min=="string"&&r.min!=="",p=typeof r.max=="string"&&r.max!=="";return N&&!p?n==null||isNaN(i)?!1:i>=Number(r.min):!N&&p?n==null?!0:isNaN(i)?!1:i<=Number(r.max):N&&p?n==null||isNaN(i)?!1:i>=Number(r.min)&&i<=Number(r.max):!0}if(c){if(typeof t.min=="object"&&t.min!==null&&"date"in t.min&&!("min"in t.min)){const o=t,D=o.min,f=o.max,u=D?.date&&D.date!=="",b=f?.date&&f.date!=="";if(u&&!b){if(n==null)return!1;const g=n instanceof Date?n:new Date(n);if(isNaN(g.getTime()))return!1;const S=new Date(D.date+(D.time?`T${D.time}:00`:"T00:00:00"));return g>=S}if(!u&&b&&f){if(n==null)return!0;const g=n instanceof Date?n:new Date(n);if(isNaN(g.getTime()))return!1;const S=new Date(f.date+(f.time?`T${f.time}:00`:"T23:59:59"));return g<=S}if(u&&b&&f){if(n==null)return!1;const g=n instanceof Date?n:new Date(n);if(isNaN(g.getTime()))return!1;const S=new Date(D.date+(D.time?`T${D.time}:00`:"T00:00:00")),y=new Date(f.date+(f.time?`T${f.time}:00`:"T23:59:59"));return g>=S&&g<=y}return!0}const r=t,N=typeof r.min=="string"&&r.min!=="",p=typeof r.max=="string"&&r.max!=="";if(N&&!p){if(n==null)return!1;const o=n instanceof Date?n:new Date(n);return isNaN(o.getTime())?!1:o>=new Date(r.min)}if(!N&&p){if(n==null)return!0;const o=n instanceof Date?n:new Date(n);return isNaN(o.getTime())?!1:o<=new Date(r.max)}if(N&&p){if(n==null)return!1;const o=n instanceof Date?n:new Date(n);return isNaN(o.getTime())?!1:o>=new Date(r.min)&&o<=new Date(r.max)}return!0}}if(typeof t=="string"&&w(e)==="rating"){if(n==null)return!1;const a=Number(t),c=typeof n=="number"?n:Number(n);return isNaN(a)||isNaN(c)?!0:c>=a}const m=w(e);if(!m)return!0;if(m==="address")return n==null?!1:typeof n=="object"&&"formatted_address"in n?String(n.formatted_address).toLowerCase().includes(String(t).toLowerCase()):!1;if(m==="multiselect"){if(!Array.isArray(n)||n.length===0)return!1;const a=String(t).toLowerCase();return n.some(c=>String(c).toLowerCase().includes(a))}return n==null?!1:String(n).toLowerCase().includes(String(t).toLowerCase())}export{T as matchesFilter};
@@ -1 +1 @@
1
- import{CRUD_OPERATION as a}from"../types";function p(n,s){const o=[],e=new Set;for(const i of n){const t=s[i.id];t?.operation!==a.DELETE&&(t?.operation===a.UPDATE&&t.optimisticData?o.push(t.optimisticData):o.push(i),e.add(i.id))}for(const[i,t]of Object.entries(s))t.operation===a.ADD&&!e.has(i)&&t.optimisticData&&o.push(t.optimisticData);return o}export{p as mergeWithOptimistic};
1
+ import{CRUD_OPERATION as e}from"../types";function r(a,s){const o=[],n=new Set;for(const i of a){const t=s[i.id];t?.operation!==e.DELETE&&(t?.operation===e.UPDATE&&t.optimisticData?o.push(t.optimisticData):o.push(i),n.add(i.id))}for(const[i,t]of Object.entries(s))t.operation===e.ADD&&!n.has(i)&&t.optimisticData&&o.push(t.optimisticData);return o}export{r as mergeWithOptimistic};
@@ -1 +1 @@
1
- const r=/<script[\s\S]*?<\/script>/gi,e=/\s+on\w+\s*=\s*["'][^"']*["']/gi,i=/\s+(?:xlink:)?href\s*=\s*["']\s*javascript:[^"']*["']/gi,c=/\s+src\s*=\s*["']\s*javascript:[^"']*["']/gi;function t(s){return s.replace(r,"").replace(e,"").replace(i,"").replace(c,"")}export{t as sanitizeHtml};
1
+ const c=/<script[\s\S]*?<\/script>/gi,r=/\s+on\w+\s*=\s*["'][^"']*["']/gi,t=/\s+(?:xlink:)?href\s*=\s*["']\s*javascript:[^"']*["']/gi,e=/\s+src\s*=\s*["']\s*javascript:[^"']*["']/gi;function i(s){return s.replace(c,"").replace(r,"").replace(t,"").replace(e,"")}export{i as sanitizeHtml};
@@ -1 +1 @@
1
- import{getScopeValue as n,CRUD_OPERATORS as u}from"@donotdev/core";function c(e,r){if(!r)return e;const t=n(r.provider);return t?{...e,[r.field]:t}:e}function f(e,r){const t=e??{};if(!r||typeof r.field!="string")return t;const i=n(r.provider);if(!i)return t;const o={field:r.field,operator:u.EQ,value:i};return{...t,where:t.where?[...t.where,o]:[o]}}function p(e){return e?n(e.provider):null}export{p as getCurrentScopeValue,c as injectScope,f as injectScopeFilter};
1
+ import{getScopeValue as n,CRUD_OPERATORS as p}from"@donotdev/core";function l(r,o){if(!o)return r;const e=n(o.provider);return e?{...r,[o.field]:e}:r}function u(r,o){const e=r??{};if(!o||typeof o.field!="string")return e;const t=n(o.provider);if(!t)return e;const i={field:o.field,operator:p.EQ,value:t};return{...e,where:e.where?[...e.where,i]:[i]}}function f(r){return r?n(r.provider):null}export{f as getCurrentScopeValue,l as injectScope,u as injectScopeFilter};
@@ -1 +1 @@
1
- "use client";function n(t){return!t||typeof t!="string"?!1:t.startsWith("https://")&&!t.startsWith("blob:")}function h(t){return!(!t||typeof t!="object"||!n(t.fullUrl)||t.thumbUrl&&!n(t.thumbUrl))}function u(t,o=""){const s=[];if(t==null)return s;if(typeof t=="string")return t.startsWith("blob:")&&s.push(o||"root"),s;if(typeof t!="object")return s;if(Array.isArray(t))t.forEach((r,l)=>{const e=o?`${o}[${l}]`:`[${l}]`;s.push(...u(r,e))});else{const r=t;if(r.fullUrl!==void 0&&r.thumbUrl!==void 0){const l=r.fullUrl,e=r.thumbUrl,i=typeof l=="string"&&!n(l),c=e&&typeof e=="string"&&!n(e);if(i||c){const f=o||"root";s.push(`${f}.fullUrl or ${f}.thumbUrl contains blob URL`)}}else Object.entries(r).forEach(([l,e])=>{const i=o?`${o}.${l}`:l;s.push(...u(e,i))})}return s}function b(t){return u(t).length>0}export{u as checkForBlobUrls,b as hasBlobUrls,n as isStorageUrl,h as validatePicture};
1
+ "use client";function s(r){return!r||typeof r!="string"?!1:r.startsWith("https://")&&!r.startsWith("blob:")}function c(r){return!(!r||typeof r!="object"||!s(r.fullUrl)||r.thumbUrl&&!s(r.thumbUrl))}function u(r,o=""){const t=[];if(r==null)return t;if(typeof r=="string")return r.startsWith("blob:")&&t.push(o||"root"),t;if(typeof r!="object")return t;if(Array.isArray(r))r.forEach((e,n)=>{const l=o?`${o}[${n}]`:`[${n}]`;t.push(...u(e,l))});else{const e=r;if(e.fullUrl!==void 0&&e.thumbUrl!==void 0){const n=e.fullUrl,l=e.thumbUrl,f=typeof n=="string"&&!s(n),b=l&&typeof l=="string"&&!s(l);if(f||b){const i=o||"root";t.push(`${i}.fullUrl or ${i}.thumbUrl contains blob URL`)}}else Object.entries(e).forEach(([n,l])=>{const f=o?`${o}.${n}`:n;t.push(...u(l,f))})}return t}function h(r){return u(r).length>0}export{u as checkForBlobUrls,h as hasBlobUrls,s as isStorageUrl,c as validatePicture};
@@ -1 +1 @@
1
- const a="dndev-workflow-";function r(t,o){try{const e=`${a}${t}`;localStorage.setItem(e,JSON.stringify(o))}catch{}}function c(t){try{const o=`${a}${t}`,e=localStorage.getItem(o);return e?JSON.parse(e):null}catch{return null}}function n(t){try{const o=`${a}${t}`;localStorage.removeItem(o)}catch{}}export{n as clearWorkflowState,c as loadWorkflowState,r as saveWorkflowState};
1
+ const r="dndev-workflow-";function c(t,o){try{const e=`${r}${t}`;localStorage.setItem(e,JSON.stringify(o))}catch{}}function n(t){try{const o=`${r}${t}`,e=localStorage.getItem(o);return e?JSON.parse(e):null}catch{return null}}function a(t){try{const o=`${r}${t}`;localStorage.removeItem(o)}catch{}}export{a as clearWorkflowState,n as loadWorkflowState,c as saveWorkflowState};
@@ -1 +1 @@
1
- function e(n){return n}export{e as defineWorkflow};
1
+ function n(e){return e}export{n as defineWorkflow};
@@ -1 +1 @@
1
- import{defineWorkflow as o}from"./defineWorkflow";import{useEntityWorkflow as a}from"./useEntityWorkflow";import{saveWorkflowState as t,loadWorkflowState as r,clearWorkflowState as e}from"./WorkflowPersistence";export{e as clearWorkflowState,o as defineWorkflow,r as loadWorkflowState,t as saveWorkflowState,a as useEntityWorkflow};
1
+ import{defineWorkflow as e}from"./defineWorkflow";import{useEntityWorkflow as f}from"./useEntityWorkflow";import{saveWorkflowState as a,loadWorkflowState as k,clearWorkflowState as w}from"./WorkflowPersistence";export{w as clearWorkflowState,e as defineWorkflow,k as loadWorkflowState,a as saveWorkflowState,f as useEntityWorkflow};
@@ -1 +1 @@
1
- "use client";import{useState as m,useCallback as p,useMemo as D,useEffect as L,useRef as M}from"react";import{evaluateCondition as R}from"@donotdev/core";import{saveWorkflowState as K,loadWorkflowState as j,clearWorkflowState as C}from"./WorkflowPersistence";function V(e,O={}){const{onComplete:w,onStepChange:f,defaultValues:y}=O,g=M(w);g.current=w;const[a,v]=m(()=>{if(e.persist){const t=j(e.persistKey??e.id);if(t)return t.stepData}if(y){const t={};for(const r of e.steps)if(r.entity&&r.fields){const o={};for(const i of r.fields)i in y&&(o[i]=y[i]);Object.keys(o).length>0&&(t[r.id]=o)}return t}return{}}),[s,S]=m(()=>{if(e.persist){const t=j(e.persistKey??e.id);if(t)return t.currentStepIndex}return 0}),[k,x]=m(!1),l=D(()=>{const t={};for(const[r,o]of Object.entries(a))for(const[i,c]of Object.entries(o))t[i]=c,t[`${r}.${i}`]=c;return t},[a]),n=D(()=>e.steps.filter(t=>t.conditions?.visible?R(t.conditions.visible,l):!0),[e.steps,l]),I=n[s]??n[0],b=s===0,d=s===n.length-1;L(()=>{e.persist&&K(e.persistKey??e.id,{currentStepIndex:s,stepData:a,savedAt:Date.now()})},[e.persist,e.persistKey,e.id,s,a]);const W=p(async t=>{const r=n[s];if(!r)return!1;if(t&&v(i=>({...i,[r.id]:{...i[r.id],...t}})),r.validation?.validate){const i={...l,...t??{}};if(r.validation.validate(i)!==!0)return!1}if(r.after){const i={};await r.after({data:t??a[r.id]??{},allData:{...l,...t??{}},next:{prefill:c=>{const u=n[s+1];u&&(i[u.id]=c)}}}),Object.keys(i).length>0&&v(c=>{const u={...c};for(const[h,G]of Object.entries(i))u[h]={...u[h],...G};return u})}if(d){x(!0);try{const i={...l,...t??{}},c=g.current??e.onComplete;return c&&await c(i),e.persist&&C(e.persistKey??e.id),!0}catch{return!1}finally{x(!1)}}const o=s+1;return S(o),f?.(s,o),!0},[n,s,l,a,d,e,f]),N=p(()=>{if(b)return;const t=s-1;S(t),f?.(s,t)},[s,b,f]),A=p(()=>{if(!n[s]?.allowSkip||d)return;const t=s+1;S(t),f?.(s,t)},[n,s,d,f]),E=p(t=>{t>=0&&t<n.length&&(f?.(s,t),S(t))},[n.length,s,f]),P=p(()=>{e.persist&&K(e.persistKey??e.id,{currentStepIndex:s,stepData:a,savedAt:Date.now()})},[e,s,a]),$=p(()=>{C(e.persistKey??e.id)},[e]),F=p((t,r)=>{v(o=>({...o,[t]:{...o[t],...r}}))},[]);return{currentStep:I,currentStepIndex:s,visibleSteps:n,stepData:a,allData:l,goNext:W,goPrevious:N,skipStep:A,goToStep:E,isFirst:b,isLast:d,isSubmitting:k,canGoNext:!k,persistNow:P,clearPersisted:$,prefillStep:F}}export{V as useEntityWorkflow};
1
+ "use client";import{useState as b,useCallback as p,useMemo as I,useEffect as G,useRef as L}from"react";import{evaluateCondition as M}from"@donotdev/core";import{saveWorkflowState as K,loadWorkflowState as j,clearWorkflowState as O}from"./WorkflowPersistence";function B(e,D={}){const{onComplete:k,onStepChange:u,defaultValues:y}=D,w=L(k);w.current=k;const[l,v]=b(()=>{if(e.persist){const t=j(e.persistKey??e.id);if(t)return t.stepData}if(y){const t={};for(const r of e.steps)if(r.entity&&r.fields){const o={};for(const i of r.fields)i in y&&(o[i]=y[i]);Object.keys(o).length>0&&(t[r.id]=o)}return t}return{}}),[s,m]=b(()=>{if(e.persist){const t=j(e.persistKey??e.id);if(t)return t.currentStepIndex}return 0}),[x,h]=b(!1),d=I(()=>{const t={};for(const[r,o]of Object.entries(l))for(const[i,a]of Object.entries(o))t[i]=a,t[`${r}.${i}`]=a;return t},[l]),n=I(()=>e.steps.filter(t=>t.conditions?.visible?M(t.conditions.visible,d):!0),[e.steps,d]),W=n[s]??n[0],S=s===0,c=s===n.length-1;G(()=>{e.persist&&K(e.persistKey??e.id,{currentStepIndex:s,stepData:l,savedAt:Date.now()})},[e.persist,e.persistKey,e.id,s,l]);const F=p(async t=>{const r=n[s];if(!r)return!1;if(t&&v(i=>({...i,[r.id]:{...i[r.id],...t}})),r.validation?.validate){const i={...d,...t??{}};if(r.validation.validate(i)!==!0)return!1}if(r.after){const i={};await r.after({data:t??l[r.id]??{},allData:{...d,...t??{}},next:{prefill:a=>{const f=n[s+1];f&&(i[f.id]=a)}}}),Object.keys(i).length>0&&v(a=>{const f={...a};for(const[C,$]of Object.entries(i))f[C]={...f[C],...$};return f})}if(c){h(!0);try{const i={...d,...t??{}},a=w.current??e.onComplete;return a&&await a(i),e.persist&&O(e.persistKey??e.id),!0}catch{return!1}finally{h(!1)}}const o=s+1;return m(o),u?.(s,o),!0},[n,s,d,l,c,e,u]),N=p(()=>{if(S)return;const t=s-1;m(t),u?.(s,t)},[s,S,u]),A=p(()=>{if(!n[s]?.allowSkip||c)return;const r=s+1;m(r),u?.(s,r)},[n,s,c,u]),E=p(t=>{t>=0&&t<n.length&&(u?.(s,t),m(t))},[n.length,s,u]),P=p(()=>{e.persist&&K(e.persistKey??e.id,{currentStepIndex:s,stepData:l,savedAt:Date.now()})},[e,s,l]),R=p(()=>{O(e.persistKey??e.id)},[e]),V=p((t,r)=>{v(o=>({...o,[t]:{...o[t],...r}}))},[]);return{currentStep:W,currentStepIndex:s,visibleSteps:n,stepData:l,allData:d,goNext:F,goPrevious:N,skipStep:A,goToStep:E,isFirst:S,isLast:c,isSubmitting:x,canGoNext:!x,persistNow:P,clearPersisted:R,prefillStep:V}}export{B as useEntityWorkflow};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@donotdev/crud",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
@@ -53,13 +53,13 @@
53
53
  "@dnd-kit/core": "^6.3.1",
54
54
  "@dnd-kit/sortable": "^10.0.0",
55
55
  "@dnd-kit/utilities": "^3.2.2",
56
- "@donotdev/components": "^0.0.22",
57
- "@donotdev/core": "^0.0.28",
56
+ "@donotdev/components": "^0.0.23",
57
+ "@donotdev/core": "^0.0.29",
58
58
  "@hookform/resolvers": "^5.2.2",
59
59
  "react-easy-crop": "^5.5.6"
60
60
  },
61
61
  "peerDependencies": {
62
- "@donotdev/firebase": "^0.0.14",
62
+ "@donotdev/firebase": "^0.0.15",
63
63
  "@tiptap/extension-placeholder": "^3.19.0",
64
64
  "@tiptap/pm": "^3.19.0",
65
65
  "@tiptap/react": "^3.19.0",