@donotdev/crud 0.0.12 → 0.0.13
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.
- package/dist/CrudService.js +1 -1
- package/dist/CrudStore.js +1 -1
- package/dist/FieldRegistry.js +1 -1
- package/dist/adapters/FirestoreAdapter.js +1 -1
- package/dist/adapters/FunctionsAdapter.js +1 -1
- package/dist/adapters/index.js +1 -1
- package/dist/components/CrudButton.js +1 -1
- package/dist/components/DisplayFieldRenderer.js +1 -1
- package/dist/components/EntityDisplayRenderer.js +1 -1
- package/dist/components/EntityFilters.d.ts.map +1 -1
- package/dist/components/EntityFilters.js +1 -1
- package/dist/components/FormFieldRenderer.js +1 -1
- package/dist/components/FormLayout.js +1 -1
- package/dist/components/controlled/complex/ControlledAddressField.js +1 -1
- package/dist/components/controlled/complex/ControlledDateField.js +1 -1
- package/dist/components/controlled/complex/ControlledGeoPointField.js +1 -1
- package/dist/components/controlled/complex/ControlledMapField.js +1 -1
- package/dist/components/controlled/complex/ControlledMultiInputField.js +1 -1
- package/dist/components/controlled/complex/ControlledRichTextField.js +1 -1
- package/dist/components/controlled/complex/ControlledTimestampField.js +1 -1
- package/dist/components/controlled/complex/index.js +1 -1
- package/dist/components/controlled/file/ControlledDocumentField.js +1 -1
- package/dist/components/controlled/file/ControlledFileField.js +1 -1
- package/dist/components/controlled/file/ControlledImageField.js +1 -1
- package/dist/components/controlled/file/ControlledMultiDocumentField.js +1 -1
- package/dist/components/controlled/file/ControlledMultiFileField.js +1 -1
- package/dist/components/controlled/file/ControlledMultiImageField.js +1 -1
- package/dist/components/controlled/file/index.js +1 -1
- package/dist/components/controlled/index.js +1 -1
- package/dist/components/controlled/input/ControlledCheckboxField.js +1 -1
- package/dist/components/controlled/input/ControlledCurrencyField.js +1 -1
- package/dist/components/controlled/input/ControlledDurationField.js +1 -1
- package/dist/components/controlled/input/ControlledGdprConsentField.js +1 -1
- package/dist/components/controlled/input/ControlledNumberField.js +1 -1
- package/dist/components/controlled/input/ControlledPasswordField.js +1 -1
- package/dist/components/controlled/input/ControlledPhoneField.js +1 -1
- package/dist/components/controlled/input/ControlledPriceField.js +1 -1
- package/dist/components/controlled/input/ControlledRangeField.js +1 -1
- package/dist/components/controlled/input/ControlledRatingField.js +1 -1
- package/dist/components/controlled/input/ControlledSwitchField.js +1 -1
- package/dist/components/controlled/input/ControlledTextField.js +1 -1
- package/dist/components/controlled/input/ControlledTextareaField.js +1 -1
- package/dist/components/controlled/input/index.js +1 -1
- package/dist/components/controlled/select/ControlledComboboxField.js +1 -1
- package/dist/components/controlled/select/ControlledDropdownField.js +1 -1
- package/dist/components/controlled/select/ControlledMultiDropdownField.js +1 -1
- package/dist/components/controlled/select/ControlledRadioField.js +1 -1
- package/dist/components/controlled/select/ControlledYearField.js +1 -1
- package/dist/components/controlled/select/index.js +1 -1
- package/dist/components/controlled/types.js +1 -1
- package/dist/components/fields/display/AvatarFieldDisplay.js +1 -1
- package/dist/components/fields/display/BadgeFieldDisplay.js +1 -1
- package/dist/components/fields/display/ButtonFieldDisplay.js +1 -1
- package/dist/components/fields/display/CheckboxFieldDisplay.js +1 -1
- package/dist/components/fields/display/DateFieldDisplay.js +1 -1
- package/dist/components/fields/display/DropdownDisplay.js +1 -1
- package/dist/components/fields/display/FileFieldDisplay.js +1 -1
- package/dist/components/fields/display/GeoPointFieldDisplay.js +1 -1
- package/dist/components/fields/display/HiddenFieldDisplay.js +1 -1
- package/dist/components/fields/display/ImageFieldDisplay.js +1 -1
- package/dist/components/fields/display/LinkFieldDisplay.js +1 -1
- package/dist/components/fields/display/MapFieldDisplay.js +1 -1
- package/dist/components/fields/display/MultiDropdownDisplay.js +1 -1
- package/dist/components/fields/display/MultiInputTextFieldDisplay.js +1 -1
- package/dist/components/fields/display/NumberFieldDisplay.js +1 -1
- package/dist/components/fields/display/PasswordFieldDisplay.js +1 -1
- package/dist/components/fields/display/PhoneNumberDisplay.js +1 -1
- package/dist/components/fields/display/RadioFieldDisplay.js +1 -1
- package/dist/components/fields/display/RangeFieldDisplay.js +1 -1
- package/dist/components/fields/display/ReferenceFieldDisplay.js +1 -1
- package/dist/components/fields/display/RichTextDisplay.js +2 -2
- package/dist/components/fields/display/TextAreaDisplay.js +1 -1
- package/dist/components/fields/display/TextFieldDisplay.js +1 -1
- package/dist/components/fields/display/TimestampFieldDisplay.js +1 -1
- package/dist/components/fields/display/index.js +1 -1
- package/dist/components/form/fields/AddressFieldComponent.js +1 -1
- package/dist/components/form/fields/AvatarFieldComponent.js +1 -1
- package/dist/components/form/fields/BadgeFieldComponent.js +1 -1
- package/dist/components/form/fields/ButtonFieldComponent.js +1 -1
- package/dist/components/form/fields/CheckboxFieldComponent.js +1 -1
- package/dist/components/form/fields/ComboboxComponent.js +1 -1
- package/dist/components/form/fields/CurrencyFieldComponent.js +1 -1
- package/dist/components/form/fields/DateFieldComponent.js +1 -1
- package/dist/components/form/fields/DocumentFieldComponent.js +1 -1
- package/dist/components/form/fields/DropdownComponent.js +1 -1
- package/dist/components/form/fields/DurationFieldComponent.js +1 -1
- package/dist/components/form/fields/FileFieldComponent.js +1 -1
- package/dist/components/form/fields/GdprConsentFieldComponent.js +1 -1
- package/dist/components/form/fields/GeoPointFieldComponent.js +1 -1
- package/dist/components/form/fields/HiddenFieldComponent.js +1 -1
- package/dist/components/form/fields/ImageFieldComponent.js +1 -1
- package/dist/components/form/fields/MapFieldComponent.js +1 -1
- package/dist/components/form/fields/MultiDropdownComponent.js +1 -1
- package/dist/components/form/fields/MultiInputTextFieldComponent.js +1 -1
- package/dist/components/form/fields/NumberFieldComponent.js +1 -1
- package/dist/components/form/fields/PasswordFieldComponent.js +1 -1
- package/dist/components/form/fields/PriceFieldComponent.js +1 -1
- package/dist/components/form/fields/RadioFieldComponent.js +1 -1
- package/dist/components/form/fields/RangeFieldComponent.js +1 -1
- package/dist/components/form/fields/RatingFieldComponent.js +1 -1
- package/dist/components/form/fields/ReferenceFieldComponent.js +1 -1
- package/dist/components/form/fields/RichTextComponent.js +1 -1
- package/dist/components/form/fields/SwitchFieldComponent.js +1 -1
- package/dist/components/form/fields/TextAreaComponent.js +1 -1
- package/dist/components/form/fields/TextFieldComponent.js +1 -1
- package/dist/components/form/fields/TimestampFieldComponent.js +1 -1
- package/dist/components/form/fields/index.js +1 -1
- package/dist/components/form/fields/internal/TiptapEditor.js +2 -2
- package/dist/components/form/internal/ImageViewerDialog.js +1 -1
- package/dist/components/index.js +1 -1
- package/dist/contexts/UploadContext.js +1 -1
- package/dist/contexts/index.js +1 -1
- package/dist/fieldTypeRegistry.js +1 -1
- package/dist/forms/hooks/index.js +1 -1
- package/dist/forms/hooks/useController.js +1 -1
- package/dist/forms/hooks/useEntityField.js +1 -1
- package/dist/forms/index.js +1 -1
- package/dist/forms/utils/getFieldsForOperation.js +1 -1
- package/dist/forms/utils/index.js +1 -1
- package/dist/forms/utils/isFieldEditable.js +1 -1
- package/dist/forms/utils/validateEntity.js +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/useEntityFavorites.js +1 -1
- package/dist/hooks/useFileUpload.js +1 -1
- package/dist/hooks/useFormNavigationGuard.js +1 -1
- package/dist/hooks/useRelatedItems.js +1 -1
- package/dist/hooks/useUnsavedChangesWarning.js +1 -1
- package/dist/index.js +1 -1
- package/dist/stores/FormStore.js +1 -1
- package/dist/stores/UploadStore.js +1 -1
- package/dist/stores/index.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/useBaseCrudList.js +1 -1
- package/dist/useCrud.js +1 -1
- package/dist/useCrudCardList.js +1 -1
- package/dist/useCrudList.js +1 -1
- package/dist/utils/collections.js +1 -1
- package/dist/utils/fileStorage.js +1 -1
- package/dist/utils/imageProcessing.js +1 -1
- package/dist/utils/imageStorage.js +1 -1
- package/dist/utils/imageUtils.js +1 -1
- package/dist/utils/mergeWithOptimistic.js +1 -1
- package/dist/utils/scopeUtils.js +1 -1
- package/dist/utils/uploadValidation.js +1 -1
- package/package.json +2 -2
package/dist/useBaseCrudList.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useMemo as
|
|
1
|
+
import{useMemo as _,useCallback as J,useRef as z}from"react";import{useQuery as N}from"@donotdev/core";import{useCrudStore as U}from"./CrudStore";import{useCrud as D,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";function le(V,m,t,p={}){const j=p.enabled??!0,I=D("status"),c=I==="ready",E=D(V,p),{error:P,invalidate:M,_collection:a,_schemas:g,_cacheOptions:y,_scope:S}=E,q=U(e=>e.collections[a]?.optimistic||Z),v=z(new Map([[1,null]])),b=z(0),R=te(S),O=_(()=>{if(!c||!g)return null;const e=X();if(!e)return null;const f=m==="listCard"?g.listCard:g.list,u=ee(p.queryOptions,S);if(!t||t.mode==="client")return e.getListQueryOptions(a,u,f,y,m);const i=v.current,n=b.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,startAfterId:s},f,y,m)},[c,a,y,g?"hasSchema":"noSchema",m,t?.mode,t?.page,t?.pageSize,p.queryOptions,S?.provider,R]),{data:l,isLoading:K,isFetching:k,error:B,refetch:L}=N({queryKey:O?.queryKey??["crud",a,"disabled"],queryFn:O?.queryFn??(()=>Promise.resolve({items:[]})),staleTime:O?.staleTime,enabled:j&&!!O}),T=_(()=>{if(!l||!c)return{items:[],total:void 0};let e=l.items;if(t?.mode==="server"&&e.length>0){const s=v.current,r=b.current,{page:o,pageSize:C}=t,Y=e.length;if(Math.ceil(Y/C)>1||o>r){const A=s.has(o)?o:r+1;for(let F=A;F<=o;F++){const Q=(F-A+1)*C-1;if(Q<e.length){const H=e[Q];s.set(F+1,H.id)}}}l.lastVisible&&s.set(o+1,l.lastVisible),b.current=Math.max(r,o);const x=s.has(o)?0:(o-r-1)*C,G=x+C;e=e.slice(x,G)}const f=$(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==="add"&&!u.has(s)?i++:r.operation==="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]),w=J(async()=>{c&&(t?.mode==="server"&&(v.current=new Map([[1,null]]),b.current=0),await M(),await L())},[M,L,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 W=T?.items??[];return{status:I,data:T,items:W,loading:K,fetching:k,error:B??P,mutate:w,refresh:w,isAvailable:!0}}export{le as useBaseCrudList};
|
package/dist/useCrud.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useEffect as
|
|
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 h,handleError as Z,isClient as $,createSchemas as H,DEGRADED_CRUD_API as J}from"@donotdev/core";import{getCrudService as X}from"./CrudService";import{useCrudStore as l}from"./CrudStore";import{injectScope as F,injectScopeFilter as O}from"./utils/scopeUtils";const re={},ne={};let P=null,E=null,g=!1;function o(){return P}function ae(d,u={}){const S=V(W.CRUD),k=l(e=>e.crudService),T=S&&!k,p=S?T?h.INITIALIZING:h.READY:h.DEGRADED;if(d==="status")return p;const v=typeof d=="object"?d:u.entity,t=typeof d=="string"?d:d.collection,i=v?.scope,m=u.backend||"functions",b=u.noCache??!1,A=u.staleTime,f=w(()=>({noCache:b,staleTime:A}),[b,A]),s=w(()=>{if(u.schema){const e=u.schema;return{create:e,draft:e,update:e,get:e,list:e,listCard:e,delete:e}}if(v)return H(v)},[u.schema?"custom":v?.name,t]),x=l(e=>e.collections[t]?.loading||!1),C=l(e=>e.collections[t]?.error||null),M=null;Q(()=>{if(!$()||!S||!s)return;const{crudService:e,backend:r}=l.getState();e&&r===m||E||(E=(async()=>{try{const c=X();P=c,c.setStore(l),await c.initialize(m),g=!1,l.getState().setBackend(m),l.getState().setCrudService(c)}catch(c){g||(Z(c,{userMessage:"Failed to initialize CRUD service.",context:{backend:m,collection:t},severity:"error"}),g=!0)}finally{E=null}})())},[S,m,t,s?"hasSchema":"noSchema"]);const _=T||x,N=p===h.READY,z=a(async e=>{const r=o();return!r||!s?null:r.get(t,e,s.get,f)},[t,s?"hasSchema":"noSchema",f]),Y=a(async(e,r,c)=>{const n=o();if(!n||!s)return;const D=F(r,i),L=D?.status==="draft"?s.draft:s.create;await n.set(t,e,D,L,c)},[t,s?"hasSchema":"noSchema",i?.provider]),j=a(async(e,r,c)=>{const n=o();n&&await n.update(t,e,r,c)},[t]),q=a(async(e,r)=>{const c=o();c&&await c.delete(t,e,r)},[t]),G=a(async(e,r)=>{const c=o();if(!c||!s)return"";const n=F(e,i),U=n?.status==="draft"?s.draft:s.create;return c.add(t,n,U,r)},[t,s?"hasSchema":"noSchema",i?.provider]),B=a(async e=>{const r=o();if(!r||!s)return[];const c=O(e,i);return(await r.query(t,c,s.list,f)).items},[t,s?"hasSchema":"noSchema",f,i?.provider]),I=a((e,r)=>{const c=o();return!c||!s?()=>{}:c.subscribe(t,e,r,s.get)},[t,s?"hasSchema":"noSchema"]),R=a((e,r)=>{const c=o();return!c||!s?()=>{}:c.subscribeToCollection(t,e,r,s.list)},[t,s?"hasSchema":"noSchema"]),y=a(async()=>{const e=o();e&&await e.invalidateCollection(t)},[t]);return N?{status:h.READY,data:M,loading:_,error:C,get:z,set:Y,update:j,delete:q,add:G,query:B,subscribe:I,subscribeToCollection:R,invalidate:y,isAvailable:!0,_collection:t,_schemas:s,_cacheOptions:f,_scope:i}:{...J,status:p,loading:_,error:C,subscribe:I,subscribeToCollection:R,invalidate:y,_collection:t,_schemas:s,_cacheOptions:f,_scope:i}}export{re as EMPTY_DATA,ne as EMPTY_OPTIMISTIC,o as getCrudServiceInstance,ae as useCrud};
|
package/dist/useCrudCardList.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useBaseCrudList as
|
|
1
|
+
import{useBaseCrudList as r}from"./useBaseCrudList";function l(t,a={}){const s={enabled:a.enabled,queryOptions:a.queryOptions,backend:a.backend,schema:a.schema,entity:a.entity,staleTime:a.staleTime,noCache:a.noCache},e=r(t,"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};
|
package/dist/useCrudList.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useBaseCrudList as
|
|
1
|
+
import{useBaseCrudList as r}from"./useBaseCrudList";function u(a,e={}){const n=e.pagination??"client",t=e.page??1,c=e.pageSize??10,i={mode:n,page:t,pageSize:c},s={enabled:e.enabled,queryOptions:e.queryOptions,backend:e.backend,schema:e.schema,entity:e.entity,staleTime:e.staleTime,noCache:e.noCache};return r(a,"list",i,s)}export{u as useCrudList};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getCrudService as
|
|
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 p}from"@donotdev/core";import{uploadFileResumable as
|
|
1
|
+
"use client";import{handleError as p}from"@donotdev/core";import{uploadFileResumable as u,deleteFileByUrl as d}from"@donotdev/firebase";function f(e){return e.replace(/[^a-zA-Z0-9.-]/g,"_").replace(/_{2,}/g,"_").toLowerCase()}async function x(e,t={}){const{storagePath:r="uploads/files",filename:n,onProgress:a}=t,o=Date.now(),i=f(e.name),c=n||`${o}_${i}`,l=`${r}/${c}`;try{const{promise:s}=u(e,{basePath:r,filename:c,onProgress:a,metadata:{contentType:e.type}});return{url:(await s).url,filename:e.name,size:e.size,mimeType:e.type,uploadedAt:new Date().toISOString()}}catch(s){throw p(s,{userMessage:"Failed to upload file",severity:"error",context:{filename:e.name,fileSize:e.size}})}}async function v(e,t={}){const r=[],n=e.reduce((o,i)=>o+i.size,0);let a=0;for(const o of e){const i=t.onProgress?l=>{const s=l.bytesTransferred/l.totalBytes*o.size;t.onProgress({bytesTransferred:a+s,totalBytes:n,progress:(a+s)/n*100})}:void 0,c=await x(o,{...t,onProgress:i});r.push(c),a+=o.size}return r}async function M(e){try{await d(e.url)}catch(t){throw p(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 m(e){const t=e.split(".");return t.length>1?t.pop().toLowerCase():""}function P(e,t){const r=t?m(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 B(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 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"],g=[".pdf",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".txt",".md",".html",".csv"];function E(){return[...h,...g].join(",")}export{g as DOCUMENT_EXTENSIONS,h as DOCUMENT_MIME_TYPES,M as deleteFile,B as formatFileSize,S as generateFileId,E as getDocumentAcceptString,m as getFileExtension,P as getFileIcon,x as uploadFile,v as uploadFiles};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
async function
|
|
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 +1 @@
|
|
|
1
|
-
import{handleError as
|
|
1
|
+
import{handleError as _}from"@donotdev/core";import{uploadFileResumable as c,deleteFileByUrl as i,getFileUrl as m}from"@donotdev/firebase";function F(e){return e.replace(/[^a-zA-Z0-9.-]/g,"_").replace(/_{2,}/g,"_").toLowerCase()}async function N(e,l,b,h={}){const{storagePath:r="uploads/images",filename:f,onProgress:s}=h,p=Date.now(),t=(f||`${p}_${F(b)}`).replace(/\.[^/.]+$/,""),w=`${r}/${t}_full.webp`,g=`${r}/${t}_thumb.webp`;try{const u=s?a=>{s({bytesTransferred:a.bytesTransferred,totalBytes:a.totalBytes*2,progress:a.progress*.5})}:void 0,o=new File([e],`${t}_full.webp`,{type:"image/webp"}),{promise:n}=c(o,{basePath:r,filename:`${t}_full.webp`,onProgress:u,metadata:{contentType:"image/webp"}}),d=(await n).url,y=s?a=>{s({bytesTransferred:a.bytesTransferred+e.size,totalBytes:e.size+l.size,progress:50+a.progress*.5})}:void 0,P=new File([l],`${t}_thumb.webp`,{type:"image/webp"}),{promise:U}=c(P,{basePath:r,filename:`${t}_thumb.webp`,onProgress:y,metadata:{contentType:"image/webp"}}),$=(await U).url;return{fullUrl:d,thumbUrl:$}}catch(u){try{const o=await m(w).catch(()=>null),n=await m(g).catch(()=>null);o&&await i(o).catch(()=>{}),n&&await i(n).catch(()=>{})}catch{}throw u}}async function k(e){try{await Promise.all([i(e.fullUrl),i(e.thumbUrl)])}catch(l){throw _(l,{userMessage:"Failed to delete image",severity:"error",context:{fullUrl:e.fullUrl,thumbUrl:e.thumbUrl}}),l}}export{k as deleteImage,N as uploadImage};
|
package/dist/utils/imageUtils.js
CHANGED
|
@@ -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(
|
|
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
|
-
function n(
|
|
1
|
+
function n(a,o){const e=[],s=new Set;for(const i of a){const t=o[i.id];t?.operation!=="delete"&&(t?.operation==="update"&&t.optimisticData?e.push(t.optimisticData):e.push(i),s.add(i.id))}for(const[i,t]of Object.entries(o))t.operation==="add"&&!s.has(i)&&t.optimisticData&&e.push(t.optimisticData);return e}export{n as mergeWithOptimistic};
|
package/dist/utils/scopeUtils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getScopeValue as n}from"@donotdev/core";function
|
|
1
|
+
import{getScopeValue as n}from"@donotdev/core";function c(e,o){if(!o)return e;const r=n(o.provider);return r?{...e,[o.field]:r}:e}function l(e,o){const r=e??{};if(!o)return r;const t=n(o.provider);if(!t)return r;const i={field:o.field,operator:"==",value:t};return{...r,where:r.where?[...r.where,i]:[i]}}function u(e){return e?n(e.provider):null}export{u as getCurrentScopeValue,c as injectScope,l as injectScopeFilter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";function
|
|
1
|
+
"use client";function l(r){return!r||typeof r!="string"?!1:r.startsWith("https://")&&!r.startsWith("blob:")}function i(r){return!r||typeof r!="object"?!1:l(r.fullUrl)&&l(r.thumbUrl)}function f(r,n=""){const e=[];if(r==null)return e;if(typeof r=="string")return r.startsWith("blob:")&&e.push(n||"root"),e;if(typeof r!="object")return e;if(Array.isArray(r))r.forEach((t,o)=>{const s=n?`${n}[${o}]`:`[${o}]`;e.push(...f(t,s))});else if(r.fullUrl!==void 0&&r.thumbUrl!==void 0){if(!l(r.fullUrl)||!l(r.thumbUrl)){const t=n||"root";e.push(`${t}.fullUrl or ${t}.thumbUrl contains blob URL`)}}else Object.entries(r).forEach(([t,o])=>{const s=n?`${n}.${t}`:t;e.push(...f(o,s))});return e}function u(r){return f(r).length>0}export{f as checkForBlobUrls,u as hasBlobUrls,l as isStorageUrl,i as validatePicture};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@donotdev/crud",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@dnd-kit/sortable": "^10.0.0",
|
|
55
55
|
"@dnd-kit/utilities": "^3.2.2",
|
|
56
56
|
"@donotdev/components": "^0.0.16",
|
|
57
|
-
"@donotdev/core": "^0.0.
|
|
57
|
+
"@donotdev/core": "^0.0.22",
|
|
58
58
|
"@hookform/resolvers": "^5.2.2",
|
|
59
59
|
"react-easy-crop": "^5.5.6"
|
|
60
60
|
},
|