@donotdev/crud 0.0.15 → 0.0.16

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 (173) hide show
  1. package/dist/CrudService.js +2 -2
  2. package/dist/CrudStore.js +1 -1
  3. package/dist/FieldRegistry.d.ts +3 -30
  4. package/dist/FieldRegistry.d.ts.map +1 -1
  5. package/dist/FieldRegistry.js +1 -1
  6. package/dist/adapters/FunctionsAdapter.d.ts.map +1 -1
  7. package/dist/adapters/FunctionsAdapter.js +1 -1
  8. package/dist/components/CrudButton.js +1 -1
  9. package/dist/components/CrudCard.js +1 -1
  10. package/dist/components/DateFilter.js +1 -1
  11. package/dist/components/DisplayFieldRenderer.js +1 -1
  12. package/dist/components/DisplayThumbnail.js +1 -1
  13. package/dist/components/EntityFilters.js +1 -1
  14. package/dist/components/FormFieldRenderer.js +1 -1
  15. package/dist/components/FormLayout.js +1 -1
  16. package/dist/components/__tests__/EntityFilters.test.js +1 -1
  17. package/dist/components/__tests__/FormFieldRenderer.test.js +1 -1
  18. package/dist/components/controlled/complex/ControlledAddressField.js +1 -1
  19. package/dist/components/controlled/complex/ControlledDateField.js +1 -1
  20. package/dist/components/controlled/complex/ControlledGeoPointField.js +1 -1
  21. package/dist/components/controlled/complex/ControlledMapField.js +1 -1
  22. package/dist/components/controlled/complex/ControlledMultiInputField.js +1 -1
  23. package/dist/components/controlled/complex/ControlledRichTextField.js +1 -1
  24. package/dist/components/controlled/complex/ControlledTimestampField.js +1 -1
  25. package/dist/components/controlled/complex/index.js +1 -1
  26. package/dist/components/controlled/file/ControlledDocumentField.js +1 -1
  27. package/dist/components/controlled/file/ControlledFileField.js +1 -1
  28. package/dist/components/controlled/file/ControlledImageField.js +1 -1
  29. package/dist/components/controlled/file/ControlledMultiDocumentField.js +1 -1
  30. package/dist/components/controlled/file/ControlledMultiFileField.js +1 -1
  31. package/dist/components/controlled/file/ControlledMultiImageField.js +1 -1
  32. package/dist/components/controlled/file/index.js +1 -1
  33. package/dist/components/controlled/index.js +1 -1
  34. package/dist/components/controlled/input/ControlledCheckboxField.js +1 -1
  35. package/dist/components/controlled/input/ControlledCurrencyField.js +1 -1
  36. package/dist/components/controlled/input/ControlledDurationField.js +1 -1
  37. package/dist/components/controlled/input/ControlledGdprConsentField.js +1 -1
  38. package/dist/components/controlled/input/ControlledNumberField.js +1 -1
  39. package/dist/components/controlled/input/ControlledPasswordField.js +1 -1
  40. package/dist/components/controlled/input/ControlledPhoneField.js +1 -1
  41. package/dist/components/controlled/input/ControlledPriceField.js +1 -1
  42. package/dist/components/controlled/input/ControlledRangeField.js +1 -1
  43. package/dist/components/controlled/input/ControlledRatingField.js +1 -1
  44. package/dist/components/controlled/input/ControlledSwitchField.js +1 -1
  45. package/dist/components/controlled/input/ControlledTextField.js +1 -1
  46. package/dist/components/controlled/input/ControlledTextareaField.js +1 -1
  47. package/dist/components/controlled/input/index.js +1 -1
  48. package/dist/components/controlled/select/ControlledComboboxField.js +1 -1
  49. package/dist/components/controlled/select/ControlledDropdownField.js +1 -1
  50. package/dist/components/controlled/select/ControlledMultiDropdownField.js +1 -1
  51. package/dist/components/controlled/select/ControlledRadioField.js +1 -1
  52. package/dist/components/controlled/select/ControlledYearField.js +1 -1
  53. package/dist/components/controlled/select/index.js +1 -1
  54. package/dist/components/controlled/types.d.ts +19 -5
  55. package/dist/components/controlled/types.d.ts.map +1 -1
  56. package/dist/components/controlled/types.js +1 -1
  57. package/dist/components/fields/display/AvatarFieldDisplay.js +1 -1
  58. package/dist/components/fields/display/BadgeFieldDisplay.js +1 -1
  59. package/dist/components/fields/display/ButtonFieldDisplay.js +1 -1
  60. package/dist/components/fields/display/CheckboxFieldDisplay.js +1 -1
  61. package/dist/components/fields/display/DateFieldDisplay.js +1 -1
  62. package/dist/components/fields/display/DropdownDisplay.js +1 -1
  63. package/dist/components/fields/display/FileFieldDisplay.js +1 -1
  64. package/dist/components/fields/display/GeoPointFieldDisplay.js +1 -1
  65. package/dist/components/fields/display/HiddenFieldDisplay.js +1 -1
  66. package/dist/components/fields/display/ImageFieldDisplay.js +1 -1
  67. package/dist/components/fields/display/LinkFieldDisplay.js +1 -1
  68. package/dist/components/fields/display/MapFieldDisplay.js +1 -1
  69. package/dist/components/fields/display/MultiDropdownDisplay.js +1 -1
  70. package/dist/components/fields/display/MultiInputTextFieldDisplay.js +1 -1
  71. package/dist/components/fields/display/NumberFieldDisplay.js +1 -1
  72. package/dist/components/fields/display/PasswordFieldDisplay.js +1 -1
  73. package/dist/components/fields/display/PhoneNumberDisplay.js +1 -1
  74. package/dist/components/fields/display/RadioFieldDisplay.js +1 -1
  75. package/dist/components/fields/display/RangeFieldDisplay.js +1 -1
  76. package/dist/components/fields/display/ReferenceFieldDisplay.js +1 -1
  77. package/dist/components/fields/display/RichTextDisplay.js +2 -2
  78. package/dist/components/fields/display/TextAreaDisplay.js +1 -1
  79. package/dist/components/fields/display/TextFieldDisplay.js +1 -1
  80. package/dist/components/fields/display/TimestampFieldDisplay.js +1 -1
  81. package/dist/components/fields/display/index.js +1 -1
  82. package/dist/components/form/fields/AddressFieldComponent.js +1 -1
  83. package/dist/components/form/fields/AvatarFieldComponent.js +1 -1
  84. package/dist/components/form/fields/BadgeFieldComponent.js +1 -1
  85. package/dist/components/form/fields/ButtonFieldComponent.js +1 -1
  86. package/dist/components/form/fields/CheckboxFieldComponent.js +1 -1
  87. package/dist/components/form/fields/ComboboxComponent.js +1 -1
  88. package/dist/components/form/fields/CurrencyFieldComponent.js +1 -1
  89. package/dist/components/form/fields/DateFieldComponent.js +1 -1
  90. package/dist/components/form/fields/DocumentFieldComponent.d.ts.map +1 -1
  91. package/dist/components/form/fields/DocumentFieldComponent.js +1 -1
  92. package/dist/components/form/fields/DropdownComponent.js +1 -1
  93. package/dist/components/form/fields/DurationFieldComponent.js +1 -1
  94. package/dist/components/form/fields/FileFieldComponent.js +1 -1
  95. package/dist/components/form/fields/GdprConsentFieldComponent.js +1 -1
  96. package/dist/components/form/fields/GeoPointFieldComponent.js +1 -1
  97. package/dist/components/form/fields/HiddenFieldComponent.js +1 -1
  98. package/dist/components/form/fields/ImageFieldComponent.js +1 -1
  99. package/dist/components/form/fields/MapFieldComponent.js +1 -1
  100. package/dist/components/form/fields/MultiDropdownComponent.js +1 -1
  101. package/dist/components/form/fields/MultiInputTextFieldComponent.js +1 -1
  102. package/dist/components/form/fields/NumberFieldComponent.js +1 -1
  103. package/dist/components/form/fields/PasswordFieldComponent.js +1 -1
  104. package/dist/components/form/fields/PhoneNumberComponent.js +1 -1
  105. package/dist/components/form/fields/PriceFieldComponent.js +1 -1
  106. package/dist/components/form/fields/RadioFieldComponent.js +1 -1
  107. package/dist/components/form/fields/RangeFieldComponent.js +1 -1
  108. package/dist/components/form/fields/RatingFieldComponent.js +1 -1
  109. package/dist/components/form/fields/ReferenceFieldComponent.js +1 -1
  110. package/dist/components/form/fields/RichTextComponent.js +1 -1
  111. package/dist/components/form/fields/SwitchFieldComponent.js +1 -1
  112. package/dist/components/form/fields/TextAreaComponent.js +1 -1
  113. package/dist/components/form/fields/TextFieldComponent.js +1 -1
  114. package/dist/components/form/fields/TimestampFieldComponent.js +1 -1
  115. package/dist/components/form/fields/index.js +1 -1
  116. package/dist/components/form/fields/internal/TiptapEditor.js +2 -2
  117. package/dist/components/form/internal/ImageViewerDialog.js +1 -1
  118. package/dist/components/index.js +1 -1
  119. package/dist/contexts/UploadContext.js +1 -1
  120. package/dist/contexts/index.js +1 -1
  121. package/dist/fieldTypeRegistry.js +1 -1
  122. package/dist/forms/hooks/index.js +1 -1
  123. package/dist/forms/hooks/useController.js +1 -1
  124. package/dist/forms/hooks/useEntityField.js +1 -1
  125. package/dist/forms/hooks/useEntityForm.d.ts +3 -2
  126. package/dist/forms/hooks/useEntityForm.d.ts.map +1 -1
  127. package/dist/forms/hooks/useEntityForm.js +1 -1
  128. package/dist/forms/index.js +1 -1
  129. package/dist/forms/types.d.ts +0 -8
  130. package/dist/forms/types.d.ts.map +1 -1
  131. package/dist/forms/utils/buildInitialValues.js +1 -1
  132. package/dist/forms/utils/getFieldsForOperation.js +1 -1
  133. package/dist/forms/utils/index.js +1 -1
  134. package/dist/forms/utils/isFieldEditable.js +1 -1
  135. package/dist/forms/utils/translateFieldLabel.js +1 -1
  136. package/dist/forms/utils/validateEntity.js +1 -1
  137. package/dist/hooks/index.d.ts +1 -1
  138. package/dist/hooks/index.d.ts.map +1 -1
  139. package/dist/hooks/index.js +1 -1
  140. package/dist/hooks/useCrudFilters.js +1 -1
  141. package/dist/hooks/useEntityFavorites.js +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.js +1 -1
  145. package/dist/hooks/useRelatedItems.js +1 -1
  146. package/dist/hooks/useUnsavedChangesWarning.d.ts +3 -24
  147. package/dist/hooks/useUnsavedChangesWarning.d.ts.map +1 -1
  148. package/dist/hooks/useUnsavedChangesWarning.js +1 -1
  149. package/dist/index.d.ts +1 -1
  150. package/dist/index.d.ts.map +1 -1
  151. package/dist/index.js +1 -1
  152. package/dist/registerBuiltinFieldTypes.js +1 -1
  153. package/dist/stores/FormStore.js +1 -1
  154. package/dist/stores/UploadStore.js +1 -1
  155. package/dist/stores/index.js +1 -1
  156. package/dist/tsconfig.tsbuildinfo +1 -1
  157. package/dist/types.js +1 -1
  158. package/dist/useBaseCrudList.js +1 -1
  159. package/dist/useCrud.js +1 -1
  160. package/dist/useCrudCardList.js +1 -1
  161. package/dist/useCrudList.js +1 -1
  162. package/dist/utils/collections.js +1 -1
  163. package/dist/utils/fileStorage.js +1 -1
  164. package/dist/utils/imageProcessing.js +1 -1
  165. package/dist/utils/imageStorage.d.ts.map +1 -1
  166. package/dist/utils/imageStorage.js +1 -1
  167. package/dist/utils/imageUtils.js +1 -1
  168. package/dist/utils/mergeWithOptimistic.js +1 -1
  169. package/dist/utils/sanitizeHtml.js +1 -1
  170. package/dist/utils/scopeUtils.js +1 -1
  171. package/dist/utils/uploadValidation.d.ts.map +1 -1
  172. package/dist/utils/uploadValidation.js +1 -1
  173. package/package.json +5 -8
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 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};
1
+ import{useMemo as D,useCallback as G,useRef as F}from"react";import{useQuery as H}from"@donotdev/core";import{useCrudStore as J}from"./CrudStore";import{useCrud as P,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(V,p,t,g={}){const j=g.enabled??!0,C=P("status"),a=C==="ready",x=P(V,g),{error:q,invalidate:_,_collection:m,_schemas:f,_cacheOptions:O,_scope:b}=x,M=J(e=>e.collections[m]?.optimistic||Z),T=F(new Map([[1,null]])),h=F(0),K=te(b),y=D(()=>{if(!a||!f)return null;const e=X();if(!e)return null;const v=p==="listCard"?f.listCard:f.list,d=ee(g.queryOptions,b);if(!t||t.mode==="client")return e.getListQueryOptions(m,d,v,O,p);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},v,O,p)},[a,m,O,f?"hasSchema":"noSchema",p,t?.mode,t?.page,t?.pageSize,g.queryOptions,b?.provider,K]),{data:c,isLoading:R,isFetching:k,error:B,refetch:w}=H({queryKey:y?.queryKey??["crud",m,"disabled"],queryFn:y?.queryFn??(()=>Promise.resolve({items:[]})),staleTime:y?.staleTime,enabled:j&&!!y}),A=D(()=>{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 z=(S-L+1)*u-1;if(z<e.length){const Y=e[z];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 v=$(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:v,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:R,fetching:k,error:B??q,mutate:E,refresh:E,isAvailable:!0}}export{se as useBaseCrudList};
package/dist/useCrud.js CHANGED
@@ -1 +1 @@
1
- "use client";import{useEffect as Q,useMemo as w,useCallback as a}from"react";import{useFeatureConsent as V,FRAMEWORK_FEATURES as W,FEATURE_STATUS as m,handleError as Z,isClient as $,createSchemas as B,DEGRADED_CRUD_API as H}from"@donotdev/core";import{getCrudService as J}from"./CrudService";import{useCrudStore as u}from"./CrudStore";import{injectScope as F,injectScopeFilter as X}from"./utils/scopeUtils";const ce={},re={};let p=null,E=null,g=!1;function o(){return p}function ne(l,d={}){const h=V(W.CRUD),P=u(e=>e.crudService),T=h&&!P,v=h?T?m.INITIALIZING:m.READY:m.DEGRADED;if(l==="status")return v;const S=typeof l=="object"?l:d.entity,s=typeof l=="string"?l:l.collection,i=S?.scope,A=d.noCache??!1,C=d.staleTime,f=w(()=>({noCache:A,staleTime:C}),[A,C]),t=w(()=>{if(d.schema){const e=d.schema;return{create:e,draft:e,update:e,get:e,list:e,listCard:e,delete:e}}if(S)return B(S)},[d.schema,S?.name,s]),x=u(e=>e.collections[s]?.loading||!1),_=u(e=>e.collections[s]?.error||null),M=null;Q(()=>{if(!$()||!h||!t)return;const{crudService:e}=u.getState();e||p||E||(E=(async()=>{try{if(p||u.getState().crudService)return;const c=J();p=c,c.setStore(u),await c.initialize(),g=!1,u.getState().setCrudService(c)}catch(c){g||(Z(c,{userMessage:"Failed to initialize CRUD service.",context:{collection:s},severity:"error"}),g=!0)}finally{E=null}})())},[h,s,t?"hasSchema":"noSchema"]);const b=T||x,N=v===m.READY,z=a(async e=>{const c=o();return!c||!t?null:c.get(s,e,t.get,f)},[s,t?"hasSchema":"noSchema",f]),Y=a(async(e,c,r)=>{const n=o();if(!n||!t)return;const D=F(c,i),k=D?.status==="draft"?t.draft:t.create;await n.set(s,e,D,k,r)},[s,t?"hasSchema":"noSchema",i?.provider]),j=a(async(e,c,r)=>{const n=o();n&&await n.update(s,e,c,t?.update,r)},[s,t]),q=a(async(e,c)=>{const r=o();r&&await r.delete(s,e,c)},[s]),G=a(async(e,c)=>{const r=o();if(!r||!t)return"";const n=F(e,i),U=n?.status==="draft"?t.draft:t.create;return r.add(s,n,U,c)},[s,t?"hasSchema":"noSchema",i?.provider]),L=a(async e=>{const c=o();if(!c||!t)return[];const r=X(e,i);return(await c.query(s,r,t.list,f)).items},[s,t?"hasSchema":"noSchema",f,i?.provider]),I=a((e,c)=>{const r=o();return!r||!t?()=>{}:r.subscribe(s,e,c,t.get)},[s,t?"hasSchema":"noSchema"]),R=a((e,c)=>{const r=o();return!r||!t?()=>{}:r.subscribeToCollection(s,e,c,t.list)},[s,t?"hasSchema":"noSchema"]),y=a(async()=>{const e=o();e&&await e.invalidateCollection(s)},[s]);return N?{status:m.READY,data:M,loading:b,error:_,get:z,set:Y,update:j,delete:q,add:G,query:L,subscribe:I,subscribeToCollection:R,invalidate:y,isAvailable:!0,_collection:s,_schemas:t,_cacheOptions:f,_scope:i}:{...H,status:v,loading:b,error:_,subscribe:I,subscribeToCollection:R,invalidate:y,_collection:s,_schemas:t,_cacheOptions:f,_scope:i}}export{ce as EMPTY_DATA,re as EMPTY_OPTIMISTIC,o as getCrudServiceInstance,ne as useCrud};
1
+ "use client";import{useEffect as K,useMemo as F,useCallback as n}from"react";import{useFeatureConsent as L,FRAMEWORK_FEATURES as W,FEATURE_STATUS as m,handleError as Z,isClient as B,createSchemas as H,DEGRADED_CRUD_API as J}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,d={}){const f=L(W.CRUD),U=u(e=>e.crudService),g=f&&!U,y=f?g?m.INITIALIZING:m.READY:m.DEGRADED,S=l==="status",p=!S&&typeof l=="object"?l:d.entity,a=S?"__status__":typeof l=="string"?l:l.collection,o=p?.scope,v=d.noCache??!1,T=d.staleTime,h=F(()=>({noCache:v,staleTime:T}),[v,T]),t=F(()=>{if(!S){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)}},[S,d.schema,p?.name,a]),Y=u(e=>e.collections[a]?.loading||!1),A=u(e=>e.collections[a]?.error||null),O=null;K(()=>{if(!B()||!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||(Z(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===m.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:m.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}:{...J,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 +1 @@
1
- import{useBaseCrudList as r}from"./useBaseCrudList";function l(a,t={}){const s={enabled:t.enabled,queryOptions:t.queryOptions,schema:t.schema,entity:t.entity,staleTime:t.staleTime,noCache:t.noCache},e=r(a,"listCard",null,s);return{status:e.status,data:e.data?{items:e.data.items}:null,items:e.items,loading:e.loading,fetching:e.fetching,error:e.error,mutate:e.mutate,refresh:e.refresh,isAvailable:e.isAvailable}}export{l as useCrudCardList};
1
+ import{useBaseCrudList as i}from"./useBaseCrudList";function r(s,t={}){const a={enabled:t.enabled,queryOptions:t.queryOptions,schema:t.schema,entity:t.entity,staleTime:t.staleTime,noCache:t.noCache},e=i(s,"listCard",null,a);return{status:e.status,data:e.data?{items:e.data.items}:null,items:e.items,loading:e.loading,fetching:e.fetching,error:e.error,mutate:e.mutate,refresh:e.refresh,isAvailable:e.isAvailable}}export{r as useCrudCardList};
@@ -1 +1 @@
1
- import{useBaseCrudList as r}from"./useBaseCrudList";function g(a,e={}){const t=e.pagination??"client",n=e.page??1,i=e.pageSize??10,c={mode:t,page:n,pageSize:i},s={enabled:e.enabled,queryOptions:e.queryOptions,schema:e.schema,entity:e.entity,staleTime:e.staleTime,noCache:e.noCache};return r(a,"list",c,s)}export{g as useCrudList};
1
+ import{useBaseCrudList as p}from"./useBaseCrudList";function r(a,e={}){const t=e.pagination??"client",i=e.page??1,n=e.pageSize??10,s={mode:t,page:i,pageSize:n},o={enabled:e.enabled,queryOptions:e.queryOptions,schema:e.schema,entity:e.entity,staleTime:e.staleTime,noCache:e.noCache};return p(a,"list",s,o)}export{r as useCrudList};
@@ -1 +1 @@
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
+ import{getCrudService as i}from"../CrudService";async function p(a,t){const e=i(),s=[],o=t.range?.start??1,c=t.range?.end??28;for(let r=o;r<=c;r++){const m=String(r),n=await e.get(t.path(a),m,t.schema);n&&s.push(n)}return s}async function d(a,t,e){const s=i();for(const o of e){const c=t.idOf(o);await s.set(t.path(a),c,o,t.schema)}}async function h(a,t,e){const s=i();if(t.idFrom){const o=t.idFrom(e);return s.set(t.path(a),o,e,t.schema)}return s.add(t.path(a),e,t.schema)}export{h as appendToCollection,p as loadDeterministicRange,d as upsertDeterministic};
@@ -1 +1 @@
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
+ "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 +1 @@
1
- async function x(t,r={}){const{maxWidth:o=1920,maxHeight:a=1440,thumbWidth:d=300,thumbHeight:i=225,aspectRatio:e=4/3,quality:h=.85,transparentBackground:c=!0,crop:l}=r;return new Promise((f,s)=>{const n=new Image,u=new FileReader;u.onload=w=>{n.src=w.target?.result},u.onerror=()=>s(new Error("Failed to read file")),n.onload=async()=>{try{const{width:w,height:F}=g(l?l.width:n.width,l?l.height:n.height,o,a,e),m=await b(n,w,F,e,h,c,l),v=await b(n,d,i,e,.65,c,l);f({fullBlob:m,thumbBlob:v,width:w,height:F})}catch(w){s(w)}},n.onerror=()=>s(new Error("Failed to load image")),u.readAsDataURL(t)})}function g(t,r,o,a,d){let i=t,e=r;i>o&&(e=o/i*e,i=o),e>a&&(i=a/e*i,e=a);const h=i/e;return Math.abs(h-d)>.01&&(h>d?e=i/d:i=e*d),{width:Math.round(i),height:Math.round(e)}}async function b(t,r,o,a,d,i,e){const h=document.createElement("canvas"),c=h.getContext("2d");if(!c)throw new Error("Failed to get canvas context");h.width=r,h.height=o,i?c.clearRect(0,0,r,o):(c.fillStyle="#FFFFFF",c.fillRect(0,0,r,o));let l,f,s,n;if(e)l=e.x,f=e.y,s=e.width,n=e.height;else{const u=t.width/t.height;s=t.width,n=t.height,l=0,f=0,u>a?(s=t.height*a,l=(t.width-s)/2):u<a&&(n=t.width/a,f=(t.height-n)/2)}return c.drawImage(t,l,f,s,n,0,0,r,o),new Promise((u,w)=>{h.toBlob(F=>{F?u(F):w(new Error("Failed to convert canvas to blob"))},"image/webp",d)})}function y(t,r){return t.type.startsWith("image/")?r&&t.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{x as processImage,y as validateImageFile};
1
+ async function v(t,r={}){const{maxWidth:o=1920,maxHeight:n=1440,thumbWidth:s=300,thumbHeight:i=225,aspectRatio:e=4/3,quality:l=.85,transparentBackground:c=!0,crop:h}=r;return new Promise((u,d)=>{const a=new Image,g=new FileReader;g.onload=w=>{a.src=w.target?.result},g.onerror=()=>d(new Error("Failed to read file")),a.onload=async()=>{try{const{width:w,height:m}=x(h?h.width:a.width,h?h.height:a.height,o,n,e),b=await F(a,w,m,e,l,c,h),f=await F(a,s,i,e,.65,c,h);u({fullBlob:b,thumbBlob:f,width:w,height:m})}catch(w){d(w)}},a.onerror=()=>d(new Error("Failed to load image")),g.readAsDataURL(t)})}function x(t,r,o,n,s){let i=t,e=r;i>o&&(e=o/i*e,i=o),e>n&&(i=n/e*i,e=n);const l=i/e;return Math.abs(l-s)>.01&&(l>s?e=i/s:i=e*s),{width:Math.round(i),height:Math.round(e)}}async function F(t,r,o,n,s,i,e){const l=document.createElement("canvas"),c=l.getContext("2d");if(!c)throw new Error("Failed to get canvas context");l.width=r,l.height=o,i?c.clearRect(0,0,r,o):(c.fillStyle="#FFFFFF",c.fillRect(0,0,r,o));let h,u,d,a;if(e)h=e.x,u=e.y,d=e.width,a=e.height;else{const g=t.width/t.height;d=t.width,a=t.height,h=0,u=0,g>n?(d=t.height*n,h=(t.width-d)/2):g<n&&(a=t.width/n,u=(t.height-a)/2)}return c.drawImage(t,h,u,d,a,0,0,r,o),new Promise((g,w)=>{l.toBlob(m=>{m?g(m):w(new Error("Failed to convert canvas to blob"))},"image/webp",s)})}function y(t,r){return t.type.startsWith("image/")?r&&t.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,y as validateImageFile};
@@ -1 +1 @@
1
- {"version":3,"file":"imageStorage.d.ts","sourceRoot":"","sources":["../../src/utils/imageStorage.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C,iGAAiG;AACjG,KAAK,sBAAsB,GAAG,CAAC,QAAQ,EAAE;IACvC,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB,KAAK,IAAI,CAAC;AAEX,YAAY,EAAE,OAAO,EAAE,CAAC;AAExB,MAAM,WAAW,cAAc;IAC7B,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wBAAwB;IACxB,UAAU,CAAC,EAAE,sBAAsB,CAAC;CACrC;AAYD;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,IAAI,EACd,SAAS,EAAE,IAAI,EACf,gBAAgB,EAAE,MAAM,EACxB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,OAAO,CAAC,CA6GlB;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBjE"}
1
+ {"version":3,"file":"imageStorage.d.ts","sourceRoot":"","sources":["../../src/utils/imageStorage.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C,iGAAiG;AACjG,KAAK,sBAAsB,GAAG,CAAC,QAAQ,EAAE;IACvC,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB,KAAK,IAAI,CAAC;AAEX,YAAY,EAAE,OAAO,EAAE,CAAC;AAExB,MAAM,WAAW,cAAc;IAC7B,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wBAAwB;IACxB,UAAU,CAAC,EAAE,sBAAsB,CAAC;CACrC;AAYD;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,IAAI,EACd,SAAS,EAAE,IAAI,EACf,gBAAgB,EAAE,MAAM,EACxB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,OAAO,CAAC,CA6GlB;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBjE"}
@@ -1 +1 @@
1
- import{handleError as F,hasProvider as b,getProvider as f}from"@donotdev/core";function R(e){return e.replace(/[^a-zA-Z0-9.-]/g,"_").replace(/_{2,}/g,"_").toLowerCase()}async function B(e,t,p,y={}){const{storagePath:o="uploads/images",filename:P,onProgress:a}=y,U=Date.now(),l=(P||`${U}_${R(p)}`).replace(/\.[^/.]+$/,""),h=`${o}/${l}_full.webp`,d=`${o}/${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 n,i;if(b("storage")){const r=f("storage");n=(await r.upload(c,{storagePath:o,filename:`${l}_full.webp`,onProgress:a?m=>a({bytesTransferred:0,totalBytes:0,progress:m*.5}):void 0})).url,i=(await r.upload(s,{storagePath:o,filename:`${l}_thumb.webp`,onProgress:a?m=>a({bytesTransferred:0,totalBytes:0,progress:50+m*.5}):void 0})).url}else{const{uploadFileResumable:r}=await import("@donotdev/firebase"),g=a?u=>{a({bytesTransferred:u.bytesTransferred,totalBytes:u.totalBytes*2,progress:u.progress*.5})}:void 0,{promise:w}=r(c,{basePath:o,filename:`${l}_full.webp`,onProgress:g,metadata:{contentType:"image/webp"}});n=(await w).url;const $=a?u=>{a({bytesTransferred:u.bytesTransferred+e.size,totalBytes:e.size+t.size,progress:50+u.progress*.5})}:void 0,{promise:_}=r(s,{basePath:o,filename:`${l}_thumb.webp`,onProgress:$,metadata:{contentType:"image/webp"}});i=(await _).url}return{fullUrl:n,thumbUrl:i}}catch(c){try{if(b("storage")){const s=f("storage");await s.delete(h).catch(()=>{}),await s.delete(d).catch(()=>{})}else{const{getFileUrl:s,deleteFileByUrl:n}=await import("@donotdev/firebase"),i=await s(h).catch(()=>null),r=await s(d).catch(()=>null);i&&await n(i).catch(()=>{}),r&&await n(r).catch(()=>{})}}catch{}throw c}}async function v(e){try{if(b("storage")){const t=f("storage");await Promise.all([t.delete(e.fullUrl),t.delete(e.thumbUrl)])}else{const{deleteFileByUrl:t}=await import("@donotdev/firebase");await Promise.all([t(e.fullUrl),t(e.thumbUrl)])}}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
+ import{handleError as _,hasProvider as g,getProvider as w}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 c=new File([e],`${r}_full.webp`,{type:"image/webp"}),s=new File([t],`${r}_thumb.webp`,{type:"image/webp"});let n,u;if(g("storage")){const l=w("storage");n=(await l.upload(c,{storagePath:i,filename:`${r}_full.webp`,onProgress:a?m=>a({bytesTransferred:0,totalBytes:0,progress:m*.5}):void 0})).url,u=(await l.upload(s,{storagePath:i,filename:`${r}_thumb.webp`,onProgress:a?m=>a({bytesTransferred:0,totalBytes:0,progress:50+m*.5}):void 0})).url}else{const{uploadFileResumable:l}=await import("@donotdev/firebase"),m=a?p=>{a({bytesTransferred:p.bytesTransferred,totalBytes:p.totalBytes*2,progress:p.progress*.5})}:void 0,{promise:U}=l(c,{basePath:i,filename:`${r}_full.webp`,onProgress:m,metadata:{contentType:"image/webp"}});n=(await U).url;const P=a?p=>{a({bytesTransferred:p.bytesTransferred+e.size,totalBytes:e.size+t.size,progress:50+p.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(c){try{if(g("storage")){const s=w("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 c}}async function F(e){try{if(g("storage")){const t=w("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 +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(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
+ 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 +1 @@
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
+ import{CRUD_OPERATION as a}from"../types";function n(e,s){const o=[],p=new Set;for(const i of e){const t=s[i.id];t?.operation!==a.DELETE&&(t?.operation===a.UPDATE&&t.optimisticData?o.push(t.optimisticData):o.push(i),p.add(i.id))}for(const[i,t]of Object.entries(s))t.operation===a.ADD&&!p.has(i)&&t.optimisticData&&o.push(t.optimisticData);return o}export{n as mergeWithOptimistic};
@@ -1 +1 @@
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
+ 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 +1 @@
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
+ import{getScopeValue as n,CRUD_OPERATORS as u}from"@donotdev/core";function c(e,t){if(!t)return e;const r=n(t.provider);return r?{...e,[t.field]:r}:e}function f(e,t){const r=e??{};if(!t||typeof t.field!="string")return r;const o=n(t.provider);if(!o)return r;const i={field:t.field,operator:u.EQ,value:o};return{...r,where:r.where?[...r.where,i]:[i]}}function p(e){return e?n(e.provider):null}export{p as getCurrentScopeValue,c as injectScope,f as injectScopeFilter};
@@ -1 +1 @@
1
- {"version":3,"file":"uploadValidation.d.ts","sourceRoot":"","sources":["../../src/utils/uploadValidation.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAGjD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAMzD;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,SAAK,GAAG,MAAM,EAAE,CA+CnE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAElD"}
1
+ {"version":3,"file":"uploadValidation.d.ts","sourceRoot":"","sources":["../../src/utils/uploadValidation.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAGjD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAMzD;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,SAAK,GAAG,MAAM,EAAE,CAmDnE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAElD"}
@@ -1 +1 @@
1
- "use client";function l(r){return!r||typeof r!="string"?!1:r.startsWith("https://")&&!r.startsWith("blob:")}function u(r){return!(!r||typeof r!="object"||!l(r.fullUrl)||r.thumbUrl&&!l(r.thumbUrl))}function f(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((n,e)=>{const s=o?`${o}[${e}]`:`[${e}]`;t.push(...f(n,s))});else{const n=r;if(n.fullUrl!==void 0&&n.thumbUrl!==void 0){if(!l(String(n.fullUrl))||!l(String(n.thumbUrl))){const e=o||"root";t.push(`${e}.fullUrl or ${e}.thumbUrl contains blob URL`)}}else Object.entries(n).forEach(([e,s])=>{const i=o?`${o}.${e}`:e;t.push(...f(s,i))})}return t}function b(r){return f(r).length>0}export{f as checkForBlobUrls,b as hasBlobUrls,l as isStorageUrl,u as validatePicture};
1
+ "use client";function o(r){return!r||typeof r!="string"?!1:r.startsWith("https://")&&!r.startsWith("blob:")}function h(r){return!(!r||typeof r!="object"||!o(r.fullUrl)||r.thumbUrl&&!o(r.thumbUrl))}function i(r,l=""){const t=[];if(r==null)return t;if(typeof r=="string")return r.startsWith("blob:")&&t.push(l||"root"),t;if(typeof r!="object")return t;if(Array.isArray(r))r.forEach((e,s)=>{const n=l?`${l}[${s}]`:`[${s}]`;t.push(...i(e,n))});else{const e=r;if(e.fullUrl!==void 0&&e.thumbUrl!==void 0){const s=e.fullUrl,n=e.thumbUrl,u=typeof s=="string"&&!o(s),c=n&&typeof n=="string"&&!o(n);if(u||c){const f=l||"root";t.push(`${f}.fullUrl or ${f}.thumbUrl contains blob URL`)}}else Object.entries(e).forEach(([s,n])=>{const u=l?`${l}.${s}`:s;t.push(...i(n,u))})}return t}function b(r){return i(r).length>0}export{i as checkForBlobUrls,b as hasBlobUrls,o as isStorageUrl,h as validatePicture};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@donotdev/crud",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
@@ -47,19 +47,19 @@
47
47
  "dev": "tsc --noEmit --watch --listFiles false --listEmittedFiles false",
48
48
  "clean": "rimraf dist tsconfig.tsbuildinfo",
49
49
  "lint": "eslint src/",
50
- "type-check": "tsc --noEmit"
50
+ "type-check": "bunx tsc --noEmit"
51
51
  },
52
52
  "dependencies": {
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.18",
57
- "@donotdev/core": "^0.0.24",
56
+ "@donotdev/components": "^0.0.19",
57
+ "@donotdev/core": "^0.0.25",
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.10",
62
+ "@donotdev/firebase": "^0.0.12",
63
63
  "@tiptap/extension-placeholder": "^3.19.0",
64
64
  "@tiptap/pm": "^3.19.0",
65
65
  "@tiptap/react": "^3.19.0",
@@ -89,9 +89,6 @@
89
89
  },
90
90
  "firebase": {
91
91
  "optional": true
92
- },
93
- "tiptap": {
94
- "optional": true
95
92
  }
96
93
  }
97
94
  }