@donotdev/crud 0.1.42 → 0.1.44
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.bulk.js +1 -1
- package/dist/CrudService.bulkAcross.js +1 -1
- package/dist/CrudService.cache.js +1 -1
- package/dist/CrudService.internal.js +2 -2
- package/dist/CrudService.mutations.js +1 -1
- package/dist/CrudService.optimistic.js +1 -1
- package/dist/CrudService.queries.js +1 -1
- package/dist/CrudService.subscriptions.js +1 -1
- package/dist/CrudStore.js +1 -1
- package/dist/adapters/FunctionsAdapter.js +1 -1
- package/dist/components/CrudButton.js +1 -1
- package/dist/components/CrudCard.d.ts.map +1 -1
- package/dist/components/CrudCard.js +1 -1
- package/dist/components/DateFilter.js +1 -1
- package/dist/components/DisplayFieldRenderer.js +1 -1
- package/dist/components/DisplayThumbnail.js +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/YearFilter.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/ControlledFieldArrayField.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/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/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/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/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/ControlledReferenceField.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/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/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.d.ts +12 -10
- package/dist/components/form/fields/AddressFieldComponent.d.ts.map +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/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/PhoneNumberComponent.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/contexts/UploadContext.js +1 -1
- package/dist/fieldTypeRegistry.store.js +1 -1
- package/dist/forms/hooks/useController.js +1 -1
- package/dist/forms/hooks/useEntityField.js +1 -1
- package/dist/forms/hooks/useEntityForm.js +1 -1
- package/dist/forms/utils/buildInitialValues.js +1 -1
- package/dist/forms/utils/isFieldEditable.js +1 -1
- package/dist/forms/utils/translateFieldLabel.js +1 -1
- package/dist/forms/utils/validateEntity.js +1 -1
- package/dist/hooks/useCrudFilters.js +1 -1
- package/dist/hooks/useCrudPageSize.js +1 -1
- package/dist/hooks/useEntityFavorites.js +1 -1
- package/dist/hooks/useFieldConditions.js +1 -1
- package/dist/hooks/useFileUpload.js +1 -1
- package/dist/hooks/useReferenceResolver.js +1 -1
- package/dist/hooks/useRelatedItems.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/symbol-index.json +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/clientListProcessing.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/matchesFilter.js +1 -1
- package/dist/utils/mergeWithOptimistic.js +1 -1
- package/dist/utils/sanitizeHtml.js +1 -1
- package/dist/utils/uploadValidation.js +1 -1
- package/dist/workflows/defineWorkflow.js +1 -1
- package/dist/workflows/useEntityWorkflow.js +1 -1
- package/package.json +3 -3
package/dist/CrudService.bulk.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{toast as v}from"@donotdev/components";import{BulkCollisionError as L,detectBulkCollisions as j,DEFAULT_STATUS_VALUE as R,generateUUID as _,getI18nInstance as T,handleError as F,validateWithSchema as N}from"@donotdev/core";import{updateListCaches as
|
|
1
|
+
import{toast as v}from"@donotdev/components";import{BulkCollisionError as L,detectBulkCollisions as j,DEFAULT_STATUS_VALUE as R,generateUUID as _,getI18nInstance as T,handleError as F,validateWithSchema as N}from"@donotdev/core";import{updateListCaches as h}from"./CrudService.cache";import{assertCanAccess as b,ensureAdapter as Q,getEntityName as C,getPiiFields as O,rateLimitKey as $,shouldShowSuccessToast as B,withResilience as K}from"./CrudService.internal";import{CRUD_OPERATION as m}from"./types";function M(t,e,p){const o=t.getQueryClient(),y=new Map;if(p.length===0)return y;const S=o.getQueriesData({queryKey:["crud",e]});for(const c of p){const g=o.getQueryData(["crud",e,"get",c]);if(g!=null){y.set(c,g);continue}let f=null;for(const[,E]of S){const D=E&&typeof E=="object"&&"items"in E?E.items:null;if(!D)continue;const w=D.find(A=>A?.id===c);if(w){f=w;break}}y.set(c,f)}return y}async function q(t,e,p,o,y){const S=j({inserts:p.inserts,updates:p.updates,deletes:p.deletes});if(S.where!==null)throw new L(S.collisions,S.where);const c=p.inserts??[],g=p.updates??[],f=p.deletes??[];if(c.length===0&&g.length===0&&f.length===0)return{insertedIds:[],updatedIds:[],deletedIds:[]};await Q(t),t.store&&(t.store.getState().setLoading(e,!0),t.store.getState().setError(e,null)),o.create?b(t,e,o.create):o.update&&b(t,e,o.update),t.security&&await t.security.checkRateLimit($(t,e),"write");const E=O(o.create??o.draft),D=O(o.update??o.create),w=c.map(n=>{const d=n,i=d.status===void 0||d.status===null?{...d,status:R}:d,u=i.status==="draft"&&o.draft?o.draft:o.create??o.draft,s=u?N(u,i,"CrudService.bulk.insert"):i;return E.length>0&&t.security?t.security.encryptPii(s,E):s}),A=g.map(({id:n,patch:d})=>{const i=d,u=D.length>0&&t.security?t.security.encryptPii(i,D):d;return{id:n,patch:u}}),I={inserts:[],updates:[],deletes:[]},P=[...g.map(n=>n.id),...f],U=M(t,e,P),k=c.map(()=>`temp_${_()}`);try{if(c.forEach((s,r)=>{const a=k[r],l={...s,id:a};t.store&&t.store.getState().addOptimistic(e,a,l),h(t,e,a,l,m.ADD),I.inserts.push({tempId:a,data:l})}),g.forEach(({id:s,patch:r})=>{const a=U.get(s)??null,l=a?{...a,...r}:{...r,id:s};t.store&&t.store.getState().updateOptimistic(e,s,l,a??null),h(t,e,s,l,m.UPDATE),I.updates.push({id:s,prev:a,merged:l})}),f.forEach(s=>{const r=U.get(s)??null;t.store&&r&&t.store.getState().deleteOptimistic(e,s,r),h(t,e,s,null,m.DELETE),I.deletes.push({id:s,prev:r})}),!t.adapter)throw new Error(`[dndev] Adapter not initialized for "${e}" bulk().`);const n=t.adapter,d={inserts:w,updates:A,deletes:f},i=await K(()=>n.bulk(e,d)),u=i.insertedIds??[];if(k.forEach((s,r)=>{const a=u[r];if(!a)return;const l=c[r];h(t,e,s,null,m.DELETE),h(t,e,a,l,m.ADD),t.store&&t.store.getState().confirmOptimistic(e,s,a,l)}),(i.updatedIds??[]).forEach(s=>{t.store&&t.store.getState().confirmUpdate(e,s)}),(i.deletedIds??[]).forEach(s=>{t.store&&t.store.getState().confirmDelete(e,s)}),t.security&&(t.security.audit({type:"crud.bulk",collection:e,userId:t.currentUserId??void 0,metadata:{inserts:c.length,updates:g.length,deletes:f.length}}),f.length>0&&t.security.recordAnomaly?.("bulk.deletes",t.currentUserId??void 0)),u.length+(i.updatedIds?.length??0)+(i.deletedIds?.length??0)>0&&B(t,y)){const s=T(),r=C(e);v("success",s.t("messages.updateSuccess",{ns:"crud",entity:r}))}return{insertedIds:u,updatedIds:i.updatedIds??[],deletedIds:i.deletedIds??[]}}catch(n){for(const{id:s,prev:r}of I.deletes)r&&h(t,e,s,r,m.ADD),t.store&&t.store.getState().rejectDelete(e,s);for(const{id:s,prev:r}of I.updates)r?h(t,e,s,r,m.UPDATE):t.invalidateCollection(e),t.store&&t.store.getState().rejectUpdate(e,s);for(const{tempId:s}of I.inserts)h(t,e,s,null,m.DELETE),t.store&&t.store.getState().rejectOptimistic(e,s);if(n instanceof L)throw t.store&&t.store.getState().setError(e,n),n;const d=F(n,{userMessage:`Failed to bulk-write ${e}`,showNotification:!0}),i=T(),u=C(e);throw v("error",i.t("messages.updateError",{ns:"crud",entity:u})),t.store&&t.store.getState().setError(e,d),d}finally{t.store&&t.store.getState().setLoading(e,!1)}}export{q as bulkImpl};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{toast as A}from"@donotdev/components";import{BulkAcrossCycleError as U,BulkCollisionError as
|
|
1
|
+
import{toast as A}from"@donotdev/components";import{BulkAcrossCycleError as U,BulkCollisionError as T,DEFAULT_STATUS_VALUE as L,detectBulkCollisions as O,generateUUID as C,getI18nInstance as v,handleError as P,validateWithSchema as _}from"@donotdev/core";import{updateListCaches as I}from"./CrudService.cache";import{assertCanAccess as j,ensureAdapter as M,getPiiFields as k,rateLimitKey as R,shouldShowSuccessToast as $,withResilience as B}from"./CrudService.internal";import{CRUD_OPERATION as b}from"./types";function F(t,y,h){const d=t.getQueryClient(),m=new Map;if(h.length===0)return m;const u=d.getQueriesData({queryKey:["crud",y]});for(const n of h){const e=d.getQueryData(["crud",y,"get",n]);if(e!=null){m.set(n,e);continue}let a=null;for(const[,r]of u){const o=r&&typeof r=="object"&&"items"in r?r.items:null;if(!o)continue;const i=o.find(s=>s?.id===n);if(i){a=i;break}}m.set(n,a)}return m}function Q(t){const y=new Map,h=new Map,d=new Map;for(const n of t){y.set(n.collection,n),h.set(n.collection,(n.dependsOn??[]).length);for(const e of n.dependsOn??[])d.has(e)||d.set(e,[]),d.get(e).push(n.collection)}const m=[];let u=[...h.entries()].filter(([,n])=>n===0).map(([n])=>n);for(;u.length>0;){m.push(u.map(e=>y.get(e)));const n=[];for(const e of u)for(const a of d.get(e)??[]){const r=(h.get(a)??0)-1;h.set(a,r),r===0&&n.push(a)}u=n}if(m.reduce((n,e)=>n+e.length,0)!==t.length){const n=[...h.entries()].filter(([,e])=>e>0).map(([e])=>e);throw new U(n)}return m}async function q(t,y,h){for(const e of y){const a=O({inserts:e.inserts,updates:e.updates,deletes:e.deletes});if(a.where!==null)throw new T(a.collisions,a.where)}const d=y.filter(e=>(e.inserts?.length??0)+(e.updates?.length??0)+(e.deletes?.length??0)>0);if(d.length===0)return{results:{}};const m=Q(d);await M(t);for(const e of d)t.store&&(t.store.getState().setLoading(e.collection,!0),t.store.getState().setError(e.collection,null));for(const e of d)j(t,e.collection,e.schemas.create??e.schemas.update);t.security&&await t.security.checkRateLimit(R(t,d[0].collection),"write");const u=d.map(e=>{const a=k(e.schemas.create??e.schemas.draft),r=k(e.schemas.update??e.schemas.create),o=(e.inserts??[]).map(s=>{const c=s,f=c.status==null?{...c,status:L}:c,p=f.status==="draft"&&e.schemas.draft?e.schemas.draft:e.schemas.create??e.schemas.draft,E=p?_(p,f,"CrudService.bulkAcross.insert"):f;return a.length>0&&t.security?t.security.encryptPii(E,a):E}),i=(e.updates??[]).map(({id:s,patch:c})=>{const f=c;return{id:s,patch:r.length>0&&t.security?t.security.encryptPii(f,r):f}});return{batch:e,encryptedInserts:o,encryptedUpdates:i}}),n=new Map;try{for(const{batch:r,encryptedInserts:o,encryptedUpdates:i}of u){const{collection:s,deletes:c=[]}=r,f=o.map(()=>`temp_${C()}`),p=[...(r.updates??[]).map(l=>l.id),...c],E=F(t,s,p),w={insertTempIds:f,inserts:[],updates:[],deletes:[]};o.forEach((l,S)=>{const g=f[S],D={...l,id:g};t.store&&t.store.getState().addOptimistic(s,g,D),I(t,s,g,D,b.ADD),w.inserts.push({tempId:g,originalRow:l})}),i.forEach(({id:l,patch:S})=>{const g=E.get(l)??null,D=g?{...g,...S}:{...S,id:l};t.store&&t.store.getState().updateOptimistic(s,l,D,g),I(t,s,l,D,b.UPDATE),w.updates.push({id:l,prev:g})}),c.forEach(l=>{const S=E.get(l)??null;t.store&&S&&t.store.getState().deleteOptimistic(s,l,S),I(t,s,l,null,b.DELETE),w.deletes.push({id:l,prev:S})}),n.set(s,w)}if(!t.adapter)throw new Error("[dndev] Adapter not initialized for bulkAcross().");const e=t.adapter,a={};for(const r of m){const o=r.map(s=>u.find(c=>c.batch.collection===s.collection)),i=await Promise.all(o.map(({batch:s,encryptedInserts:c,encryptedUpdates:f})=>B(()=>e.bulk(s.collection,{inserts:c,updates:f,deletes:s.deletes})).then(p=>({collection:s.collection,result:p}))));for(const{collection:s,result:c}of i)a[s]=c}for(const{batch:r,encryptedInserts:o}of u){const{collection:i}=r,s=a[i];if(!s)continue;const c=n.get(i),f=s.insertedIds??[];c.insertTempIds.forEach((p,E)=>{const w=f[E];if(!w)return;const l=o[E];I(t,i,p,null,b.DELETE),I(t,i,w,l,b.ADD),t.store&&t.store.getState().confirmOptimistic(i,p,w,l)}),(s.updatedIds??[]).forEach(p=>{t.store&&t.store.getState().confirmUpdate(i,p)}),(s.deletedIds??[]).forEach(p=>{t.store&&t.store.getState().confirmDelete(i,p)})}if(t.security){const r={};for(const{batch:o}of u)r[`${o.collection}_inserts`]=(o.inserts??[]).length,r[`${o.collection}_updates`]=(o.updates??[]).length,r[`${o.collection}_deletes`]=(o.deletes??[]).length;t.security.audit({type:"crud.bulk",collection:d.map(o=>o.collection).join(","),userId:t.currentUserId??void 0,metadata:r})}if(Object.values(a).some(r=>(r.insertedIds?.length??0)+(r.updatedIds?.length??0)+(r.deletedIds?.length??0)>0)&&$(t,h)){const r=v();A("success",r.t("messages.updateSuccess",{ns:"crud",entity:""}))}return{results:a}}catch(e){for(const[o,i]of n){for(const{id:s,prev:c}of i.deletes)c&&I(t,o,s,c,b.ADD),t.store&&t.store.getState().rejectDelete(o,s);for(const{id:s,prev:c}of i.updates)c?I(t,o,s,c,b.UPDATE):t.invalidateCollection(o),t.store&&t.store.getState().rejectUpdate(o,s);for(const{tempId:s}of i.inserts)I(t,o,s,null,b.DELETE),t.store&&t.store.getState().rejectOptimistic(o,s)}if(e instanceof T||e instanceof U){for(const{batch:o}of u)t.store&&t.store.getState().setError(o.collection,e);throw e}const a=P(e,{userMessage:"Failed to save across collections",showNotification:!0}),r=v();A("error",r.t("messages.updateError",{ns:"crud",entity:""}));for(const{batch:o}of u)t.store&&t.store.getState().setError(o.collection,a);throw a}finally{for(const{batch:e}of u)t.store&&t.store.getState().setLoading(e.collection,!1)}}export{q as bulkAcrossImpl};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{handleError as
|
|
1
|
+
import{handleError as E}from"@donotdev/core";import{CRUD_OPERATION as u}from"./types";function m(a,c,s,r,t){const l=a.getQueryClient(),i=["crud",c,"get",s];t===u.DELETE?l.removeQueries({queryKey:i}):t===u.SET&&r?l.setQueryData(i,r):(t===u.UPDATE||t===u.ADD)&&r&&l.setQueryData(i,e=>e?{...e,...r}:r)}function D(a,c,s,r,t){const l=a.getQueryClient();m(a,c,s,r,t),l.setQueriesData({queryKey:["crud",c]},i=>{if(i&&typeof i=="object"&&"items"in i){const e=i;let n=e.items;return t===u.DELETE?(n=e.items.filter(o=>o!=null&&typeof o=="object"&&o.id!==s),{...e,items:n,total:Math.max(0,(e.total??n.length)-1)}):t===u.ADD&&r?(n=[...e.items,{...r,id:s}],{...e,items:n,total:(e.total??e.items.length)+1}):(t===u.UPDATE||t===u.SET)&&r&&e.items.some(o=>o!=null&&typeof o=="object"&&o.id===s)?(n=e.items.map(o=>o==null||typeof o!="object"||o.id!==s?o:t===u.SET?{...r,id:s}:{...o,...r}),{...e,items:n}):i}if(Array.isArray(i)){if(t===u.DELETE)return i.filter(e=>e.id!==s);if(t===u.ADD&&r)return[...i,{...r,id:s}];if((t===u.UPDATE||t===u.SET)&&r)return i.some(e=>e!=null&&typeof e=="object"&&e.id===s)?i.map(e=>e==null||typeof e!="object"||e.id!==s?e:t===u.SET?{...r,id:s}:{...e,...r}):i}return i})}function g(a,c,s,r){const t=r.metadata?.uniqueKeys;if(!t||t.length===0)return null;const l=a.getQueryClient().getQueriesData({queryKey:["crud",c]}),i=[];for(const[,n]of l)n&&typeof n=="object"&&"items"in n?i.push(...n.items):Array.isArray(n)&&i.push(...n);if(i.length===0)return null;const e=s;for(const n of t){if(!n.fields.every(f=>e[f]!=null&&e[f]!==""))continue;const o=i.find(f=>n.fields.every(d=>{const y=typeof e[d]=="string"?e[d].toLowerCase():e[d],p=typeof f[d]=="string"?f[d].toLowerCase():f[d];return y===p}));if(o){if(n.findOrCreate)return o.id;const f=n.fields.join(" + ");throw E(new Error(n.errorMessage||`Duplicate ${f}`),{userMessage:n.errorMessage||`A record with this ${f} already exists`,showNotification:!0})}}return null}function h(a,c,s){const r=a.getQueryClient().getQueriesData({queryKey:["crud",c]});for(const[,t]of r)if(t?.items){const l=t.items.find(i=>i.id===s);if(l)return l}return null}async function C(a,c){await a.getQueryClient().invalidateQueries({queryKey:["crud",c]})}export{g as checkUniquenessFromCache,h as getItemFromListCache,C as invalidateCollectionImpl,m as updateGetCache,D as updateListCaches};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{getI18nInstance as c,hasProvider as l,getProvider as f,hasRestrictedVisibility as p,withTimeout as o,DEFAULT_CRUD_TIMEOUT as m}from"@donotdev/core";function
|
|
1
|
+
import{getI18nInstance as c,hasProvider as l,getProvider as f,hasRestrictedVisibility as p,withTimeout as o,DEFAULT_CRUD_TIMEOUT as m}from"@donotdev/core";function y(e,t){return t?.showSuccessToast===!0?!0:t?.showSuccessToast===!1?!1:!e.store?.getState().hideSuccessToasts}function h(e){return e?.security?.piiFields??[]}function w(e,t,r,a,i){e.security&&e.security.audit({type:t,collection:r,docId:a,userId:i??e.currentUserId??void 0})}function g(e,t){return e.currentUserId?`${e.currentUserId}:${t}`:t}function u(e,t){return`${e}:${t}`}async function v(e,t=m){try{return await o(e(),t)}catch(r){if(d(r))return await new Promise(a=>setTimeout(a,2e3)),await o(e(),t);throw r}}function d(e){if(e instanceof Error){if(e.name==="TimeoutError"||e.message.includes("Failed to fetch")||e.message.includes("NetworkError")||e.message.includes("network"))return!0;const t=e.message.match(/(?:status|code)\s*:?\s*(\d{3})/i);if(t?.[1]&&parseInt(t[1])>=500)return!0}return!1}async function S(e){e.adapter||await e.initialize()}function b(e,t,r){if(e.adapter&&r&&p(r)&&!e.adapter.serverSideOnly&&!e.adapter.dbLevelSecurity)throw new Error(`[dndev] Direct adapter cannot access "${t}": entity has restricted field visibility. Use a server-side adapter (FunctionsAdapter for Firebase, or SupabaseCrudAdapter with RLS enabled) to enforce field-level security (serverSideOnly = true | dbLevelSecurity = true).`)}async function A(e){if(!e.adapter){if(!l("crud"))throw new Error(`[dndev] No CRUD adapter configured. Call configureProviders({ crud: yourAdapter }) at app startup.
|
|
2
2
|
Examples:
|
|
3
3
|
import { FirestoreAdapter } from "@donotdev/firebase";
|
|
4
4
|
import { FunctionsAdapter } from "@donotdev/crud";
|
|
@@ -6,4 +6,4 @@ Examples:
|
|
|
6
6
|
|
|
7
7
|
configureProviders({ crud: new FirestoreAdapter() }) // Firebase direct
|
|
8
8
|
configureProviders({ crud: new FunctionsAdapter() }) // via callable functions
|
|
9
|
-
configureProviders({ crud: new SupabaseCrudAdapter(sb) }) // Supabase direct (RLS)`);e.adapter=f("crud"),e.store&&e.store.getState().setCrudService(e)}}function F(e){const t=c();let r=`entity-${e}`,a=t.t("name",{ns:r,defaultValue:null});return a&&a!=="name"&&a!==`${r}:name`||e.endsWith("s")&&e.length>1&&(r=`entity-${e.slice(0,-1)}`,a=t.t("name",{ns:r,defaultValue:null}),a&&a!=="name"&&a!==`${r}:name`)?a:e}async function T(e,t,r,a){const i=u(t,r),n=e._inflightMutations.get(i);n&&await n.catch(()=>{});const s=a();e._inflightMutations.set(i,s);try{return await s}finally{e._inflightMutations.get(i)===s&&e._inflightMutations.delete(i)}}export{b as assertCanAccess,w as auditCrud,S as ensureAdapter,F as getEntityName,
|
|
9
|
+
configureProviders({ crud: new SupabaseCrudAdapter(sb) }) // Supabase direct (RLS)`);e.adapter=f("crud"),e.store&&e.store.getState().setCrudService(e)}}function F(e){const t=c();let r=`entity-${e}`,a=t.t("name",{ns:r,defaultValue:null});return a&&a!=="name"&&a!==`${r}:name`||e.endsWith("s")&&e.length>1&&(r=`entity-${e.slice(0,-1)}`,a=t.t("name",{ns:r,defaultValue:null}),a&&a!=="name"&&a!==`${r}:name`)?a:e}async function T(e,t,r,a){const i=u(t,r),n=e._inflightMutations.get(i);n&&await n.catch(()=>{});const s=a();e._inflightMutations.set(i,s);try{return await s}finally{e._inflightMutations.get(i)===s&&e._inflightMutations.delete(i)}}export{b as assertCanAccess,w as auditCrud,S as ensureAdapter,F as getEntityName,h as getPiiFields,A as initializeImpl,d as isTransientError,u as mutationKey,g as rateLimitKey,T as runSerializedMutation,y as shouldShowSuccessToast,v as withResilience};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{toast as
|
|
1
|
+
import{toast as p}from"@donotdev/components";import{generateUUID as R,getI18nInstance as m,handleError as E}from"@donotdev/core";import{checkUniquenessFromCache as k,getItemFromListCache as O,updateListCaches as l}from"./CrudService.cache";import{assertCanAccess as U,auditCrud as f,ensureAdapter as h,getEntityName as S,getPiiFields as C,rateLimitKey as L,runSerializedMutation as I,shouldShowSuccessToast as D,withResilience as A}from"./CrudService.internal";import{CRUD_OPERATION as g}from"./types";async function N(t,e,r,i,c,u){await h(t),t.store&&(t.store.getState().setLoading(e,!0),t.store.getState().setError(e,null));const a=t.getQueryClient().getQueryData(["crud",e,"get",r])??null;t.store&&t.store.getState().updateOptimistic(e,r,i,a);try{if(!t.adapter)throw new Error("Adapter not initialized");U(t,e,c),t.security&&await t.security.checkRateLimit(L(t,e),"write");const o=C(c),s=o.length>0&&t.security?t.security.encryptPii(i,o):i,n=t.adapter;if(await I(t,e,r,async()=>{await A(()=>n.set(e,r,s,c))}),l(t,e,r,i,g.SET),t.store&&t.store.getState().confirmUpdate(e,r),f(t,"crud.update",e,r),D(t,u)){const d=m(),y=S(e);p("success",d.t("messages.updateSuccess",{ns:"crud",entity:y}))}}catch(o){a&&l(t,e,r,a,g.SET),t.store&&t.store.getState().rejectUpdate(e,r);const s=E(o,{userMessage:`Failed to save ${e}`,showNotification:!0}),n=m(),d=S(e);throw p("error",n.t("messages.updateError",{ns:"crud",entity:d})),t.store&&t.store.getState().setError(e,s),s}finally{t.store&&t.store.getState().setLoading(e,!1)}}async function Q(t,e,r,i,c,u){await h(t),t.store&&(t.store.getState().setLoading(e,!0),t.store.getState().setError(e,null));const a=t.getQueryClient().getQueryData(["crud",e,"get",r])??O(t,e,r),o=a?{...a,...i}:{...i,id:r};t.store&&t.store.getState().updateOptimistic(e,r,o,a??null);try{if(!t.adapter)throw new Error("Adapter not initialized");c&&U(t,e,c),t.security&&await t.security.checkRateLimit(L(t,e),"write");const s=c?C(c):[],n=s.length>0&&t.security?t.security.encryptPii(i,s):i,d=t.adapter;if(await I(t,e,r,async()=>{await A(()=>d.update(e,r,n))}),l(t,e,r,o,g.UPDATE),t.store&&t.store.getState().confirmUpdate(e,r),f(t,"crud.update",e,r),D(t,u)){const y=m(),w=S(e);p("success",y.t("messages.updateSuccess",{ns:"crud",entity:w}))}}catch(s){a?l(t,e,r,a,g.UPDATE):t.invalidateCollection(e),t.store&&t.store.getState().rejectUpdate(e,r);const n=E(s,{userMessage:`Failed to update ${e}`,showNotification:!0}),d=m(),y=S(e);throw p("error",d.t("messages.updateError",{ns:"crud",entity:y})),t.store&&t.store.getState().setError(e,n),n}finally{t.store&&t.store.getState().setLoading(e,!1)}}async function j(t,e,r,i){await h(t),t.store&&(t.store.getState().setLoading(e,!0),t.store.getState().setError(e,null));const c=t.getQueryClient().getQueryData(["crud",e,"get",r])??O(t,e,r);t.store&&c&&t.store.getState().deleteOptimistic(e,r,c);try{if(!t.adapter)throw new Error("Adapter not initialized");t.security&&await t.security.checkRateLimit(L(t,e),"write");const u=t.adapter;if(await I(t,e,r,async()=>{await A(()=>u.delete(e,r))}),l(t,e,r,null,g.DELETE),t.store&&t.store.getState().confirmDelete(e,r),f(t,"crud.delete",e,r),t.security?.recordAnomaly?.("bulk.deletes",t.currentUserId??void 0),D(t,i)){const a=m(),o=S(e);p("success",a.t("messages.deleteSuccess",{ns:"crud",entity:o}))}}catch(u){c&&l(t,e,r,c,g.ADD),t.store&&t.store.getState().rejectDelete(e,r);const a=E(u,{userMessage:`Failed to delete ${e}`,showNotification:!0}),o=m(),s=S(e);throw p("error",o.t("messages.deleteError",{ns:"crud",entity:s})),t.store&&t.store.getState().setError(e,a),a}finally{t.store&&t.store.getState().setLoading(e,!1)}}async function v(t,e,r,i,c){await h(t);const u=k(t,e,r,i);if(u)return u;t.store&&(t.store.getState().setLoading(e,!0),t.store.getState().setError(e,null));const a=`temp_${R()}`;t.store&&t.store.getState().addOptimistic(e,a,{...r,id:a});try{if(!t.adapter)throw new Error("Adapter not initialized");U(t,e,i),t.security&&await t.security.checkRateLimit(L(t,e),"write");const o=C(i),s=o.length>0&&t.security?t.security.encryptPii(r,o):r,n=s;(n.status===void 0||n.status===null)&&(n.status="draft");const d=t.adapter,y=await A(()=>d.add(e,s,i)),w=y.id,T=y.data;if(l(t,e,a,null,g.DELETE),l(t,e,w,T,g.ADD),t.store&&t.store.getState().confirmOptimistic(e,a,w,T),f(t,"crud.create",e,w),D(t,c)){const F=m(),P=S(e);p("success",F.t("messages.createSuccess",{ns:"crud",entity:P}))}return w}catch(o){l(t,e,a,null,g.DELETE),t.store&&t.store.getState().rejectOptimistic(e,a);const s=E(o,{userMessage:`Failed to create ${e}`,showNotification:!0}),n=m(),d=S(e);throw p("error",n.t("messages.createError",{ns:"crud",entity:d})),t.store&&t.store.getState().setError(e,s),s}finally{t.store&&t.store.getState().setLoading(e,!1)}}export{v as addImpl,j as deleteImpl,N as setImpl,Q as updateImpl};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{toast as g}from"@donotdev/components";import{generateUUID as C,getI18nInstance as w,handleError as f}from"@donotdev/core";import{checkUniquenessFromCache as T,getItemFromListCache as I,updateListCaches as m}from"./CrudService.cache";import{auditCrud as E,ensureAdapter as D,getEntityName as y,rateLimitKey as S,runSerializedMutation as L,shouldShowSuccessToast as A,withResilience as O}from"./CrudService.internal";import{CRUD_OPERATION as l}from"./types";async function R(e,
|
|
1
|
+
import{toast as g}from"@donotdev/components";import{generateUUID as C,getI18nInstance as w,handleError as f}from"@donotdev/core";import{checkUniquenessFromCache as T,getItemFromListCache as I,updateListCaches as m}from"./CrudService.cache";import{auditCrud as E,ensureAdapter as D,getEntityName as y,rateLimitKey as S,runSerializedMutation as L,shouldShowSuccessToast as A,withResilience as O}from"./CrudService.internal";import{CRUD_OPERATION as l}from"./types";async function R(t,e,r,o,u){await D(t);const n=T(t,e,r,o);if(n)return{...r,id:n};t.security&&await t.security.checkRateLimit(S(t,e),"write");const a=`temp_${C()}`,d={...r,id:a,_optimistic:!0};t.store&&t.store.getState().addOptimistic(e,a,d);try{if(!t.adapter)throw new Error("Adapter not initialized");const s=t.adapter,p=await O(()=>s.add(e,r,o)),i=p.id,c=p.data;if(m(t,e,a,null,l.DELETE),m(t,e,i,c,l.ADD),t.store&&t.store.getState().confirmOptimistic(e,a,i,c),E(t,"crud.create",e,i),A(t,u)){const h=w(),U=y(e);g("success",h.t("messages.createSuccess",{ns:"crud",entity:U}))}return c}catch(s){m(t,e,a,null,l.DELETE),t.store&&t.store.getState().rejectOptimistic(e,a);const p=f(s,{userMessage:`Failed to create ${e}`,showNotification:!0}),i=w(),c=y(e);throw g("error",i.t("messages.createError",{ns:"crud",entity:c})),p}}async function _(t,e,r,o,u,n){await D(t),t.security&&await t.security.checkRateLimit(S(t,e),"write");const a=t.getQueryClient().getQueryData(["crud",e,"get",r])??I(t,e,r),d=a?{...a,...o,_optimistic:!0}:{...o,id:r,_optimistic:!0};t.store&&a&&t.store.getState().updateOptimistic(e,r,d,a);try{if(!t.adapter)throw new Error("Adapter not initialized");const s=t.adapter;await L(t,e,r,async()=>{await O(()=>s.update(e,r,o))});const{_optimistic:p,...i}=d;if(m(t,e,r,i,l.UPDATE),t.store&&t.store.getState().confirmUpdate(e,r),E(t,"crud.update",e,r),A(t,n)){const c=w(),h=y(e);g("success",c.t("messages.updateSuccess",{ns:"crud",entity:h}))}return i}catch(s){a&&m(t,e,r,a,l.UPDATE),t.store&&t.store.getState().rejectUpdate(e,r);const p=f(s,{userMessage:`Failed to update ${e}`,showNotification:!0}),i=w(),c=y(e);throw g("error",i.t("messages.updateError",{ns:"crud",entity:c})),p}}async function N(t,e,r,o){await D(t),t.security&&await t.security.checkRateLimit(S(t,e),"write");const u=t.getQueryClient().getQueryData(["crud",e,"get",r])??I(t,e,r);t.store&&u&&t.store.getState().deleteOptimistic(e,r,u);try{if(!t.adapter)throw new Error("Adapter not initialized");const n=t.adapter;if(await L(t,e,r,async()=>{await O(()=>n.delete(e,r))}),m(t,e,r,null,l.DELETE),t.store&&t.store.getState().confirmDelete(e,r),E(t,"crud.delete",e,r),t.security?.recordAnomaly?.("bulk.deletes",t.currentUserId??void 0),A(t,o)){const a=w(),d=y(e);g("success",a.t("messages.deleteSuccess",{ns:"crud",entity:d}))}}catch(n){u&&m(t,e,r,u,l.ADD),t.store&&t.store.getState().rejectDelete(e,r);const a=f(n,{userMessage:`Failed to delete ${e}`,showNotification:!0}),d=w(),s=y(e);throw g("error",d.t("messages.deleteError",{ns:"crud",entity:s})),a}}export{R as addOptimisticImpl,N as deleteOptimisticImpl,_ as updateOptimisticImpl};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LIST_SCHEMA_TYPE as d,handleError as u}from"@donotdev/core";import{assertCanAccess as f,ensureAdapter as y,getPiiFields as h,withResilience as
|
|
1
|
+
import{LIST_SCHEMA_TYPE as d,handleError as u}from"@donotdev/core";import{assertCanAccess as f,ensureAdapter as y,getPiiFields as h,withResilience as l}from"./CrudService.internal";const g=1/0;function m(t,r,a,o,i,n=d.LIST){const e=t.adapter,s=()=>y(t);return{queryKey:["crud",r,"query",JSON.stringify(a)],queryFn:async()=>{if(e||await s(),!t.adapter)throw new Error("Adapter not initialized");const c=t.adapter;return l(()=>c.query(r,a,o,n))},staleTime:i?.staleTime??g}}function q(t,r,a,o,i){const n=t.adapter,e=()=>y(t);return{queryKey:["crud",r,"get",a],queryFn:async()=>{if(n||await e(),!t.adapter)throw new Error("Adapter not initialized");const s=t.adapter;return l(()=>s.get(r,a,o))},staleTime:i?.staleTime??g}}async function E(t,r,a,o,i){if(await y(t),i?.noCache)return p(t,r,a,o);t.store&&(t.store.getState().setLoading(r,!0),t.store.getState().setError(r,null));try{return await t.getQueryClient().fetchQuery({queryKey:["crud",r,"get",a],queryFn:()=>p(t,r,a,o,!1),staleTime:i?.staleTime??g})}catch(n){const e=u(n,{userMessage:`Failed to fetch ${r}`,showNotification:!0});throw t.store&&t.store.getState().setError(r,e),e}finally{t.store&&t.store.getState().setLoading(r,!1)}}async function p(t,r,a,o,i=!0){t.store&&i&&(t.store.getState().setLoading(r,!0),t.store.getState().setError(r,null));try{if(!t.adapter)throw new Error("Adapter not initialized");f(t,r,o);const n=t.adapter,e=await l(()=>n.get(r,a,o));if(e&&t.security){const s=h(o);if(s.length>0)return t.security.decryptPii(e,s)}return e}catch(n){const e=u(n,{userMessage:`Failed to fetch ${r}`,showNotification:!0});throw t.store&&t.store.getState().setError(r,e),e}finally{t.store&&i&&t.store.getState().setLoading(r,!1)}}async function L(t,r,a,o,i,n=d.LIST){if(await y(t),i?.noCache)return w(t,r,a,o,!0,n);t.store&&(t.store.getState().setLoading(r,!0),t.store.getState().setError(r,null));try{return await t.getQueryClient().fetchQuery({queryKey:["crud",r,"query",JSON.stringify(a)],queryFn:()=>w(t,r,a,o,!1,n),staleTime:i?.staleTime??g})}catch(e){const s=u(e,{userMessage:`Failed to query ${r}`,showNotification:!0});throw t.store&&t.store.getState().setError(r,s),s}finally{t.store&&t.store.getState().setLoading(r,!1)}}async function w(t,r,a,o,i=!0,n=d.LIST){t.store&&i&&(t.store.getState().setLoading(r,!0),t.store.getState().setError(r,null));try{if(!t.adapter)throw new Error("Adapter not initialized");f(t,r,o);const e=t.adapter,s=await l(()=>e.query(r,a,o,n));if(t.security&&s.items.length>0){const c=h(o);c.length>0&&(s.items=s.items.map(S=>t.security.decryptPii(S,c)))}return s}catch(e){const s=u(e,{userMessage:`Failed to query ${r}`,showNotification:!0});throw t.store&&t.store.getState().setError(r,s),s}finally{t.store&&i&&t.store.getState().setLoading(r,!1)}}export{q as getDocQueryOptionsImpl,E as getImpl,m as getListQueryOptionsImpl,L as queryImpl};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{handleError as
|
|
1
|
+
import{handleError as l}from"@donotdev/core";import{assertCanAccess as c,ensureAdapter as b}from"./CrudService.internal";function f(e,u,s,t,i){if(!e.adapter){let r=!1,n=null;return b(e).then(()=>{r||(n=d(e,u,s,t,i))}).catch(o=>{r||t(null,l(o))}),()=>{r=!0,n?.()}}return d(e,u,s,t,i)}function d(e,u,s,t,i){try{const r=e.adapter;return r?r.subscribe?(c(e,u,i),r.subscribe(u,s,(n,o)=>{n&&e.getQueryClient().setQueryData(["crud",u,"get",s],n),t(n,o)},i)):()=>{}:(t(null,new Error("Adapter not initialized")),()=>{})}catch(r){return t(null,l(r)),()=>{}}}function m(e,u,s,t,i){if(!e.adapter){let r=!1,n=null;return b(e).then(()=>{r||(n=p(e,u,s,t,i))}).catch(o=>{r||t([],l(o))}),()=>{r=!0,n?.()}}return p(e,u,s,t,i)}function p(e,u,s,t,i){try{const r=e.adapter;return r?r.subscribeToCollection?(c(e,u,i),r.subscribeToCollection(u,s,(n,o)=>{n&&e.getQueryClient().setQueryData(["crud",u,"query",JSON.stringify(s)],a=>a?{...a,items:n}:{items:n}),t(n,o)},i)):()=>{}:(t([],new Error("Adapter not initialized")),()=>{})}catch(r){return t([],l(r)),()=>{}}}export{f as subscribeImpl,m as subscribeToCollectionImpl};
|
package/dist/CrudStore.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createDoNotDevStore as g,isClient as f}from"@donotdev/core";import{OPTIMISTIC_STATUSES as d,CRUD_OPERATION as u}from"./types";let m=null;const a="f_";function S(
|
|
1
|
+
import{createDoNotDevStore as g,isClient as f}from"@donotdev/core";import{OPTIMISTIC_STATUSES as d,CRUD_OPERATION as u}from"./types";let m=null;const a="f_";function S(n){if(!f())return;const s=new URLSearchParams(location.search);[...s.keys()].filter(i=>i.startsWith(a)).forEach(i=>s.delete(i));for(const[i,o]of Object.entries(n))typeof o=="string"?s.set(`${a}${i}`,o):Array.isArray(o)?s.set(`${a}${i}`,o.join(",")):(o.min&&s.set(`${a}${i}_min`,o.min),o.max&&s.set(`${a}${i}_max`,o.max));const t=s.toString();history.replaceState(null,"",`${location.pathname}${t?`?${t}`:""}`)}function h(){if(!f())return{};const n=new URLSearchParams(location.search),s={},t=new Map;return n.forEach((i,o)=>{if(!o.startsWith(a))return;const e=o.slice(a.length);if(e.endsWith("_min")){const c=e.slice(0,-4),l=t.get(c)??{};l.min=i,t.set(c,l)}else if(e.endsWith("_max")){const c=e.slice(0,-4),l=t.get(c)??{};l.max=i,t.set(c,l)}else i.includes(",")?s[e]=i.split(","):s[e]=i}),t.forEach((i,o)=>{s[o]=i}),s}const E={filters:{},showFavoritesOnly:!1};function r(){return{loading:!1,error:null,lastUpdated:0,optimistic:{},ui:{...E}}}const O={crudService:null,hideSuccessToasts:!1,collections:{}},U=g({name:"crud-store",createStore:(n,s)=>({...O,setCrudService:t=>{n({crudService:t})},setHideSuccessToasts:t=>{n({hideSuccessToasts:t})},setLoading:(t,i)=>{n(o=>{const e=o.collections[t]||r();return{collections:{...o.collections,[t]:{...e,loading:i}}}})},setError:(t,i)=>{n(o=>{const e=o.collections[t]||r();return{collections:{...o.collections,[t]:{...e,error:i,loading:!1}}}})},setFilters:(t,i)=>{n(o=>{const e=o.collections[t]||r();return{collections:{...o.collections,[t]:{...e,ui:{...e.ui,filters:i}}}}}),m&&clearTimeout(m),m=setTimeout(()=>{m=null,S(i)},500)},setShowFavoritesOnly:(t,i)=>{n(o=>{const e=o.collections[t]||r();return{collections:{...o.collections,[t]:{...e,ui:{...e.ui,showFavoritesOnly:i}}}}})},getFilters:t=>{const i=s().collections[t]?.ui?.filters;if(i)return i;const o=h();return Object.keys(o).length>0?(n(e=>{const c=e.collections[t]||r();return{collections:{...e.collections,[t]:{...c,ui:{...c.ui,filters:o}}}}}),o):{}},getShowFavoritesOnly:t=>s().collections[t]?.ui?.showFavoritesOnly||!1,setPageSize:(t,i)=>{n(o=>{const e=o.collections[t]||r();return{collections:{...o.collections,[t]:{...e,ui:{...e.ui,pageSize:i}}}}})},getPageSize:t=>s().collections[t]?.ui?.pageSize,clearCollection:t=>{n(i=>{const{[t]:o,...e}=i.collections;return{collections:e}})},clearError:t=>{n(i=>{const o=i.collections[t];return o?{collections:{...i.collections,[t]:{...o,error:null}}}:i})},addOptimistic:(t,i,o)=>{n(e=>{const c=e.collections[t]||r();return{collections:{...e.collections,[t]:{...c,optimistic:{...c.optimistic,[i]:{tempId:i,originalData:null,optimisticData:o,status:d.PENDING,operation:u.ADD}},lastUpdated:Date.now()}}}})},confirmOptimistic:(t,i,o,e)=>{n(c=>{const l=c.collections[t];if(!l)return c;const{[i]:p,...D}=l.optimistic;return{collections:{...c.collections,[t]:{...l,optimistic:D,lastUpdated:Date.now()}}}})},rejectOptimistic:(t,i)=>{n(o=>{const e=o.collections[t];if(!e)return o;const{[i]:c,...l}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:l,lastUpdated:Date.now()}}}})},updateOptimistic:(t,i,o,e)=>{n(c=>{const l=c.collections[t]||r();return{collections:{...c.collections,[t]:{...l,optimistic:{...l.optimistic,[i]:{tempId:i,originalData:e,optimisticData:o,status:d.PENDING,operation:u.UPDATE}},lastUpdated:Date.now()}}}})},confirmUpdate:(t,i)=>{n(o=>{const e=o.collections[t];if(!e)return o;const{[i]:c,...l}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:l}}}})},rejectUpdate:(t,i)=>{n(o=>{const e=o.collections[t];if(!e)return o;const c=e.optimistic[i];if(!c||c.operation!==u.UPDATE)return o;const{[i]:l,...p}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:p,lastUpdated:Date.now()}}}})},deleteOptimistic:(t,i,o)=>{n(e=>{const c=e.collections[t];return c?{collections:{...e.collections,[t]:{...c,optimistic:{...c.optimistic,[i]:{tempId:i,originalData:o,optimisticData:null,status:d.PENDING,operation:u.DELETE}},lastUpdated:Date.now()}}}:e})},confirmDelete:(t,i)=>{n(o=>{const e=o.collections[t];if(!e)return o;const{[i]:c,...l}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:l}}}})},rejectDelete:(t,i)=>{n(o=>{const e=o.collections[t];if(!e)return o;const c=e.optimistic[i];if(!c||c.operation!==u.DELETE)return o;const{[i]:l,...p}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:p,lastUpdated:Date.now()}}}})},getLoading:t=>s().collections[t]?.loading||!1,getError:t=>s().collections[t]?.error||null,isOptimistic:(t,i)=>s().collections[t]?.optimistic[i]?.status==="pending",getOptimisticStatus:(t,i)=>s().collections[t]?.optimistic[i]?.status??null,getOptimisticData:(t,i)=>s().collections[t]?.optimistic[i]?.optimisticData??null})});export{U as useCrudStore};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as h from"valibot";import{BulkCollisionError as y,BulkRequestSchema as g,BulkResponseSchema as A,detectBulkCollisions as m,DoNotDevError as b,getProvider as C,validateWithSchema as p,wrapCrudError as l}from"@donotdev/core";import{LIST_SCHEMA_TYPE as f}from"@donotdev/core";class E{serverSideOnly=!0;getCallable(){return C("callable")}async getCallableFn(
|
|
1
|
+
import*as h from"valibot";import{BulkCollisionError as y,BulkRequestSchema as g,BulkResponseSchema as A,detectBulkCollisions as m,DoNotDevError as b,getProvider as C,validateWithSchema as p,wrapCrudError as l}from"@donotdev/core";import{LIST_SCHEMA_TYPE as f}from"@donotdev/core";class E{serverSideOnly=!0;getCallable(){return C("callable")}async getCallableFn(e){const t=this.getCallable();return async s=>({data:await t.call(e,s)})}async get(e,t,s){const i=`get_${e}`,n=await this.getCallableFn(i);try{const a=(await n({id:t})).data;return s?{...p(s,a,"FunctionsAdapter.get"),id:t}:{...a,id:t}}catch(a){throw l(a,"FunctionsAdapter","get",e,t)}}async set(e,t,s,i){const n=i?p(i,s,"FunctionsAdapter.set"):s,a=`update_${e}`,o=await this.getCallableFn(a);try{await o({id:t,payload:n})}catch(r){throw l(r,"FunctionsAdapter","set",e,t)}}async update(e,t,s){const i=`update_${e}`,n=await this.getCallableFn(i);try{await n({id:t,payload:s})}catch(a){throw l(a,"FunctionsAdapter","update",e,t)}}async delete(e,t){const s=`delete_${e}`,i=await this.getCallableFn(s);try{await i({id:t})}catch(n){throw l(n,"FunctionsAdapter","delete",e,t)}}async bulk(e,t,s,i){const n=m({inserts:t.inserts,updates:t.updates,deletes:t.deletes});if(n.where!==null)throw new y(n.collisions,n.where);const a=t.inserts??[],o=t.updates??[],r=t.deletes??[];if(a.length===0&&o.length===0&&r.length===0)return{insertedIds:[],updatedIds:[],deletedIds:[]};let w;try{w=h.parse(g,{inserts:a,updates:o,deletes:r})}catch(d){throw new b(`FunctionsAdapter.bulk(${e}): invalid bulk request payload`,"validation-failed",{details:{issues:d instanceof h.ValiError?d.issues:void 0},source:"validation",originalError:d instanceof Error?d:new Error(String(d))})}const F=await this.getCallableFn(`bulk_${e}`);try{const d=await F(w);if(!d.data)throw l(new Error("Bulk function returned no data"),"FunctionsAdapter","bulk",e);let u;try{u=h.parse(A,d.data)}catch(c){throw new b(`FunctionsAdapter.bulk(${e}): malformed server response`,"validation-failed",{details:{issues:c instanceof h.ValiError?c.issues:void 0,response:d.data},source:"validation",originalError:c instanceof Error?c:new Error(String(c))})}return{insertedIds:u.insertedIds,updatedIds:u.updatedIds,deletedIds:u.deletedIds}}catch(d){throw d instanceof y?d:l(d,"FunctionsAdapter","bulk",e)}}async add(e,t,s){const i=s?p(s,t,"FunctionsAdapter.add"):t,n=`create_${e}`,a=await this.getCallableFn(n);try{const o=await a({payload:i});if(!o.data)throw l(new Error("Create function returned no data"),"FunctionsAdapter","add",e);return{id:o.data.id,data:o.data}}catch(o){throw l(o,"FunctionsAdapter","add",e)}}async query(e,t,s,i=f.LIST){const n=i===f.LIST_CARD?`listCard_${e}`:`list_${e}`,a={};t.where&&(a.where=t.where.map(r=>[r.field,r.operator,r.value])),t.orderBy&&(a.orderBy=t.orderBy.map(r=>[r.field,r.direction||"asc"])),t.limit&&(a.limit=t.limit),t.startAfter&&(a.startAfterId=t.startAfter);const o=await this.getCallableFn(n);try{const r=await o(a);if(!r.data)throw l(new Error("Query function returned no data"),"FunctionsAdapter","query",e);return{items:r.data.items,total:r.data.count,hasMore:r.data.hasMore,lastVisible:r.data.lastVisible}}catch(r){throw l(r,"FunctionsAdapter","query",e)}}subscribe(){return()=>{}}subscribeToCollection(){return()=>{}}}export{E as FunctionsAdapter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as d}from"react/jsx-runtime";import{ActionButton as n}from"@donotdev/components";import{useCrudStore as a}from"../CrudStore";function c({requiresAuth:r=!0,user:e,disabled:t=!1,children:
|
|
1
|
+
"use client";import{jsx as d}from"react/jsx-runtime";import{ActionButton as n}from"@donotdev/components";import{useCrudStore as a}from"../CrudStore";function c({requiresAuth:r=!0,user:e,disabled:t=!1,children:o,...i}){const s=a(u=>!!u.crudService);return d(n,{...i,disabled:t||!s||r&&!e,children:o})}var l=c;export{l as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CrudCard.d.ts","sourceRoot":"","sources":["../../src/components/CrudCard.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,aAAa,EAA2B,MAAM,gBAAgB,CAAC;AA4C7E;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,MAAM,EACN,OAAO,EACP,WAAW,EAAE,eAAe,EAC5B,cAAc,EAAE,kBAAkB,EAClC,aAAa,EAAE,iBAAiB,EAChC,YAAY,EAAE,gBAAgB,EAC9B,UAAkB,EAClB,aAAa,EACb,aAAa,EACb,SAAS,GACV,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"CrudCard.d.ts","sourceRoot":"","sources":["../../src/components/CrudCard.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,aAAa,EAA2B,MAAM,gBAAgB,CAAC;AA4C7E;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,MAAM,EACN,OAAO,EACP,WAAW,EAAE,eAAe,EAC5B,cAAc,EAAE,kBAAkB,EAClC,aAAa,EAAE,iBAAiB,EAChC,YAAY,EAAE,gBAAgB,EAC9B,UAAkB,EAClB,aAAa,EACb,aAAa,EACb,SAAS,GACV,EAAE,aAAa,2CA6Mf;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as a,jsxs as
|
|
1
|
+
import{jsx as a,jsxs as k}from"react/jsx-runtime";import{Trash2 as z}from"lucide-react";import{useMemo as y}from"react";import{Card as G,Stack as w,Text as V,ActionButton as H}from"@donotdev/components";import{useTranslation as j,getListCardFieldNames as J}from"@donotdev/core";import{formatValue as F}from"./DisplayFieldRenderer";import{DisplayThumbnail as P}from"./DisplayThumbnail";import{translateFieldLabel as K}from"../forms/utils/translateFieldLabel";import{useCrud as Q}from"../useCrud";function d(t){return t==="image"||t==="images"}function U(t){return y(()=>{const l=t.listCardFields;if(l&&!Array.isArray(l)){const s=l;return{titleFields:s.title??[],subtitleFields:s.subtitle??[],contentFields:s.content??[],footerFields:s.footer??[]}}const f=J(t),m=f.filter(s=>!d(t.fields[s]?.type)),C=f.filter(s=>d(t.fields[s]?.type)),b=m.length>0?[m[0]]:[],x=[...m.slice(1,4),...C];return{titleFields:b,subtitleFields:[],contentFields:x,footerFields:[]}},[t])}function I({item:t,entity:l,onClick:f,titleFields:m,subtitleFields:C,contentFields:b,footerFields:x,showDelete:s=!1,renderActions:B,renderOverlay:L,className:N}){const{t:o}=j([l.namespace,"crud"]),{t:p}=j("crud"),h=U(l),S=m??h.titleFields,A=C??h.subtitleFields,D=b??h.contentFields,g=x??h.footerFields,c=t,T=y(()=>{if(!S?.length)return t.id??"";const r=S.filter(e=>typeof e=="string").filter(e=>!d(l.fields[e]?.type)).map(e=>{const n=l.fields[e],v=t[e],u=n?F(v,n,o,{compact:!0,asString:!0,item:c}):v;return typeof u=="string"?u:String(u??"")}).filter(Boolean),i=!Array.isArray(l.listCardFields)&&l.listCardFields?.titleSeparator!=null?l.listCardFields.titleSeparator:" ";return r.join(i)||String(t.id??"")},[t,l.fields,S,l.listCardFields,o]),O=y(()=>A?.length&&A.filter(r=>typeof r=="string").filter(r=>!d(l.fields[r]?.type)).map(r=>{const i=l.fields[r],e=t[r],n=i?F(e,i,o,{compact:!0,asString:!0,item:c}):e;return typeof n=="string"?n:String(n??"")}).filter(Boolean).join(" ")||void 0,[t,l.fields,A,o]),R=y(()=>{if(!D?.length)return null;const r=D.map(i=>{const e=l.fields[i];if(!e||e.options?.displayValue?.(t[i],c,o)===null)return null;if(d(e.type)){const n=t[i];return n==null?null:a(P,{pictures:n,alt:String(T),aspectRatio:"16/9"},i)}return k("div",{children:[a(V,{level:"small",variant:"muted",children:K(i,e,o)}),a(V,{children:F(t[i],e,o,{compact:!0,item:c})})]},i)}).filter(Boolean);return r.length>0?a(w,{direction:"column",gap:"tight",children:r}):null},[t,l.fields,D,T,o]),E=y(()=>{if(!g?.length)return;if(g.some(i=>d(l.fields[i]?.type))){const i=g.map(e=>{const n=l.fields[e];if(!n)return null;if(d(n.type)){const u=t[e];return u==null?null:a(P,{pictures:u,alt:"",aspectRatio:"1"},e)}const v=F(t[e],n,o,{compact:!0,item:c});return a("span",{children:v},e)});return a(w,{direction:"row",gap:"tight",align:"center",children:i.filter(Boolean)})}const r=g.map(i=>{const e=l.fields[i];return e?F(t[i],e,o,{compact:!0,item:c}):t[i]});return a(V,{level:"small",children:r.join(" \xB7 ")})},[t,l.fields,g,o]),M=Q(l).delete,q=B||s?k("div",{style:{display:"flex",alignItems:"flex-start",gap:"var(--gap-xs)",pointerEvents:"auto"},onClick:r=>r.stopPropagation(),onMouseDown:r=>r.stopPropagation(),children:[B,s&&a(H,{action:async()=>{await M(t.id)},confirmText:p("delete.confirm",{defaultValue:"Are you sure you want to delete this item?"}),confirmTitle:p("delete.title",{defaultValue:"Delete Item"}),loadingText:p("delete.loading",{defaultValue:"Deleting..."}),variant:"destructive",icon:z,"aria-label":p("delete",{defaultValue:"Delete"}),children:p("delete",{defaultValue:"Delete"})})]}):null;return a(G,{title:String(T??""),subtitle:O,content:R??void 0,footer:E,clickable:!0,elevated:!0,onClick:f?()=>f(t.id):void 0,className:N,overlay:q??void 0,overlayPosition:"top-right",fullOverlay:L??void 0})}var W=I;export{I as CrudCard,W as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as e,jsxs as j,Fragment as
|
|
1
|
+
"use client";import{jsx as e,jsxs as j,Fragment as ct}from"react/jsx-runtime";import{X as ht}from"lucide-react";import{useState as k}from"react";import{Button as x,Calendar as St,FloatingLabel as Dt,Sheet as T,Text as M}from"@donotdev/components";import{formatDate as ft}from"@donotdev/core";function $t({label:S,fieldType:xt,value:s,onChange:D,tCrud:l,locale:O="en"}){const[F,i]=k(!1),[C,f]=k(null),N=s?typeof s=="object"&&s!==null&&"min"in s?{min:s.min||"",max:s.max||""}:{min:"",max:""}:{min:"",max:""},Y=t=>{if(!t)return"";try{const n=new Date(t+"T00:00:00");return ft(n,O)}catch{return t}},W=()=>{const t=new Date;t.setHours(0,0,0,0);const n=t.getFullYear(),g=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0"),o=`${n}-${g}-${r}`,d=new Date(t);d.setDate(d.getDate()-1);const v=d.getFullYear(),$=String(d.getMonth()+1).padStart(2,"0"),B=String(d.getDate()).padStart(2,"0"),H=`${v}-${$}-${B}`,m=new Date(t);m.setDate(m.getDate()+1);const L=m.getFullYear(),X=String(m.getMonth()+1).padStart(2,"0"),q=String(m.getDate()).padStart(2,"0"),z=`${L}-${X}-${q}`,p=new Date(t);p.setDate(p.getDate()-7);const A=p.getFullYear(),G=String(p.getMonth()+1).padStart(2,"0"),J=String(p.getDate()).padStart(2,"0"),K=`${A}-${G}-${J}`,u=new Date(t);u.setDate(u.getDate()-30);const P=u.getFullYear(),Q=String(u.getMonth()+1).padStart(2,"0"),R=String(u.getDate()).padStart(2,"0"),U=`${P}-${Q}-${R}`,c=new Date(t);c.setDate(c.getDate()+7);const Z=c.getFullYear(),_=String(c.getMonth()+1).padStart(2,"0"),tt=String(c.getDate()).padStart(2,"0"),et=`${Z}-${_}-${tt}`,h=new Date(t);h.setDate(h.getDate()+30);const at=h.getFullYear(),nt=String(h.getMonth()+1).padStart(2,"0"),rt=String(h.getDate()).padStart(2,"0"),lt=`${at}-${nt}-${rt}`,y=new Date(t.getFullYear(),t.getMonth(),1),it=y.getFullYear(),dt=String(y.getMonth()+1).padStart(2,"0"),st=String(y.getDate()).padStart(2,"0"),gt=`${it}-${dt}-${st}`,w=new Date(t.getFullYear(),t.getMonth()+1,0),ot=w.getFullYear(),mt=String(w.getMonth()+1).padStart(2,"0"),pt=String(w.getDate()).padStart(2,"0"),ut=`${ot}-${mt}-${pt}`;return{today:o,yesterday:H,tomorrow:z,last7Days:K,last30Days:U,next7Days:et,next30Days:lt,thisMonthStart:gt,thisMonthEnd:ut}},a=N,E=W(),I=!!(a?.min||a?.max),b=t=>{const n=t==="start",g=n?a?.min:a?.max;return e("div",{style:{padding:"var(--gap-md)"},children:j("div",{style:{display:"flex",flexDirection:"column",gap:"var(--gap-md)"},children:[e("div",{style:{display:"flex",flexWrap:"wrap",gap:"var(--gap-tight)"},children:(n?["today","yesterday","last7Days","last30Days","thisMonthStart"]:["today","tomorrow","next7Days","next30Days","thisMonthEnd"]).map(r=>{const o=E[r];return e(x,{variant:"outline",onClick:()=>{D({min:n?o:a?.min||"",max:n?a?.max||"":o}),i(!1)},children:l(`filter.${r}`,{defaultValue:r})},r)})}),e(St,{selected:g?new Date(g+"T00:00:00"):void 0,mode:"single",onSelect:r=>{if(!r)return;const o=r.getFullYear(),d=String(r.getMonth()+1).padStart(2,"0"),v=String(r.getDate()).padStart(2,"0"),$=`${o}-${d}-${v}`;D({min:n?$:a?.min||"",max:n?a?.max||"":$}),i(!1)},defaultMonth:g?new Date(g+"T00:00:00"):new Date}),e(x,{variant:"ghost",display:"compact",onClick:()=>{D({min:n?"":a?.min||"",max:n&&a?.max||""}),i(!1)},children:l("filter.clear",{defaultValue:"Clear"})})]})})},V=j(ct,{children:[e(T,{trigger:e(x,{variant:"ghost",onClick:()=>{f("start"),i(!0)},style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",paddingInlineStart:"var(--gap-md)",justifyContent:"flex-start"},children:a?.min?Y(a.min):e(M,{as:"span",level:"small",variant:"muted",children:l("filter.min",{defaultValue:"Min"})})}),title:`${S} - ${l("filter.min",{defaultValue:"Min"})}`,open:F&&C==="start",onOpenChange:t=>{i(t),t||f(null)},children:b("start")}),e(M,{level:"small",variant:"muted",className:"dndev-range-input-separator",children:"\u2013"}),e(T,{trigger:e(x,{variant:"ghost",onClick:()=>{f("end"),i(!0)},style:{minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",paddingInlineStart:"var(--gap-md)",justifyContent:"flex-start"},children:a?.max?Y(a.max):e(M,{as:"span",level:"small",variant:"muted",children:l("filter.max",{defaultValue:"Max"})})}),title:`${S} - ${l("filter.max",{defaultValue:"Max"})}`,open:F&&C==="end",onOpenChange:t=>{i(t),t||f(null)},children:b("end")}),e("button",{type:"button",className:"dndev-inline-action-btn",onClick:()=>{D(void 0)},disabled:!I,"aria-label":l("filter.clear",{defaultValue:"Clear"}),children:e(ht,{})})]});return S?e(Dt,{label:S,children:e("div",{className:"dndev-range-input",children:V})}):e("div",{className:"dndev-range-input",children:V})}export{$t as DateFilter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{Fragment as x,jsx as
|
|
1
|
+
"use client";import{Fragment as x,jsx as n,jsxs as f}from"react/jsx-runtime";import{Text as s,Stack as S}from"@donotdev/components";import{handleError as g,getI18nInstance as u}from"@donotdev/core";import{getDisplayFormatter as F}from"../fieldTypeRegistry";import{translateFieldLabel as w}from"../forms/utils";function y(t,e,l,r){r&&!r.locale?r.locale=u()?.language:r||(r={locale:u()?.language});const a=r?.compact??!1,o=r?.asString??!1,c=e.options?.displayValue;if(c&&r?.item){const i=c(t,r.item,l);return i===null?o?"":n(x,{}):i}if(t==null||t==="")return o?"\u2014":a?n("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):n(s,{variant:"muted",children:"\u2014"});const d=F(e.type),m=e.options?.displayKey;if(m){let i=String(t);if(d)try{const p=d(t,e,l,r);i=typeof p=="string"?p:String(t)}catch{}const v=(Array.isArray(m)?m:[m]).map(p=>p.replace("{{value}}",i));return l(v,{value:i})}if(d)try{return d(t,e,l,r)}catch(i){return g(i,{userMessage:`Error formatting field "${e.label||e.name}"`,context:{fieldType:e.type,fieldName:e.label||"unknown",operation:"display_format"},severity:"warning"}),o?String(t):a?n("span",{style:{color:"var(--muted-foreground)"},children:String(t)}):n(s,{variant:"muted",children:String(t)})}return g(new Error(`Display formatter not registered for field type: ${e.type}`),{userMessage:`Field type "${e.type}" is missing display formatter`,context:{fieldType:e.type,fieldName:e.label||"unknown",operation:"display_format",fix:"Add displayFormatter to registerBuiltinFieldType() in registerBuiltinFieldTypes.tsx"},severity:"warning"}),o?String(t):a?n("span",{style:{color:"var(--muted-foreground)"},children:String(t)}):n(s,{variant:"muted",children:String(t)})}function h({name:t,config:e,value:l,t:r}){const a=y(l,e,r,{compact:!1}),o=w(t,e,r);return f(S,{direction:"row",align:"baseline",style:{marginBottom:"var(--gap-sm)",padding:"var(--gap-sm)",minHeight:"38px",alignItems:"center"},children:[f(s,{variant:"muted",style:{fontSize:"var(--font-size-sm)",fontWeight:500,minWidth:"fit-content",flexShrink:0},children:[o,":"]}),n("div",{style:{flex:1,display:"flex",alignItems:"center"},children:typeof a=="string"?n(s,{children:a}):a})]})}var b=h;export{h as DisplayFieldRenderer,b as default,y as formatValue};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as a}from"react/jsx-runtime";import{handleImageError as s}from"@donotdev/components";function u(
|
|
1
|
+
"use client";import{jsx as a}from"react/jsx-runtime";import{handleImageError as s}from"@donotdev/components";function u(r){if(r==null)return null;if(typeof r=="string")return r||null;const l=Array.isArray(r)&&r.length>0?r[0]:r;if(!l||typeof l!="object")return null;const e=l.thumbUrl??l.fullUrl;return typeof e=="string"?e:null}function n({pictures:r,alt:l="",aspectRatio:e="16/9",className:i,style:o}){const t=u(r);return t?a("div",{className:i,style:{width:"100%",aspectRatio:e,borderRadius:"var(--radius-md)",overflow:"hidden",backgroundColor:"var(--muted)",position:"relative",...o},children:a("img",{src:t,alt:l,loading:"lazy",onError:s,style:{width:"100%",height:"100%",objectFit:"cover"}})}):null}var c=n;export{n as DisplayThumbnail,c as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as u,jsxs as
|
|
1
|
+
"use client";import{jsx as u,jsxs as E}from"react/jsx-runtime";import{FilterX as ye}from"lucide-react";import{useMemo as M,useState as te,useRef as he,useEffect as ve}from"react";import{Button as be,Combobox as ie,Grid as xe,Rating as Fe,RangeInput as Ce,ScrollArea as Te,Slider as je,Stack as Y,Tag as G}from"@donotdev/components";import{useTranslation as ne,handleError as re,isFieldVisible as we}from"@donotdev/core";import{DateFilter as Ee}from"./DateFilter";import{YearFilter as Se}from"./YearFilter";import{getFilterType as ae,isFilterable as Ae}from"../fieldTypeRegistry";import{translateFieldLabel as le,translateLabel as D}from"../forms/utils";import{useCrudFilters as Ve}from"../hooks/useCrudFilters";import{useCrudCardList as Me}from"../useCrudCardList";import{matchesFilter as Ne}from"../utils/matchesFilter";import{matchesFilter as Oe}from"../utils/matchesFilter";function $e({entity:d,data:W,fieldsToFilter:N,variant:se="inline",cols:oe,viewerRole:X="guest"}){const z=se==="sidebar",{t:x,i18n:me}=ne("crud"),{t:F}=ne(d.namespace),de=me?.language||"en",{data:ue}=Me(d,{enabled:!W}),C=W??(ue?.items||[]),{filters:T,setFilters:J}=Ve({collection:d.collection}),[K,B]=te({}),[fe,Q]=te({}),O=he({});ve(()=>()=>{Object.values(O.current).forEach(clearTimeout)},[]);const ce=(e,t,a)=>{B(r=>({...r,[e]:{min:t,max:a}})),O.current[e]&&clearTimeout(O.current[e]),O.current[e]=setTimeout(()=>{c(e,{min:t,max:a})},250)},j=M(()=>(N&&N.length>0?N:d.listFields||Object.keys(d.fields)).filter(e=>{const t=d.fields[e],a=t?.type||"text";return!(!Ae(a)||!we(t?.visibility??"guest",X))}),[N,d.listFields,d.fields,X]),U=M(()=>{const e={};return j.forEach(t=>{const a=Object.fromEntries(Object.entries(T).filter(([r])=>r!==t));if(Object.keys(a).length===0){e[t]=C;return}e[t]=C.filter(r=>Object.entries(a).every(([o,m])=>{const f=r[o],h=d.fields[o]?.type||"text";return Ne(f,m,h)}))}),e},[C,T,d.fields,j]),Z=M(()=>{const e={};return j.forEach(t=>{const a=d.fields[t];if(!a)return;const r=a.type||"text",o=ae(r);if(!o){re(new Error(`Field type "${r}" not registered in field type registry`),{userMessage:`Field type "${r}" is missing from registry`,context:{fieldType:r,fieldName:t,operation:"minmax_computation",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"});return}const m=o==="range"&&r==="year",f=o==="range"&&!m&&(r==="date"||r==="datetime-local"||r==="timestamp"||r==="time"||r==="week"||r==="month"),h=o==="range"&&!f&&!m,S=r==="price";if(h||m||S){const p=C.map(n=>n[t]).filter(n=>n!=null&&n!=="").map(n=>S&&typeof n=="object"&&n!==null?Number(n.amount):typeof n=="number"?n:Number(n)).filter(n=>!isNaN(n));p.length>0&&(e[t]={min:Math.min(...p),max:Math.max(...p)})}else if(f){const p=C.map(n=>n[t]).filter(n=>n!=null&&n!=="").map(n=>n instanceof Date?n:new Date(n)).filter(n=>!isNaN(n.getTime()));if(p.length>0){const n=new Date(Math.min(...p.map(w=>w.getTime()))),$=new Date(Math.max(...p.map(w=>w.getTime()))),v=n.toISOString().split("T")[0],A=$.toISOString().split("T")[0];e[t]={min:v||"",max:A||""}}}}),e},[C,d.fields,j]),c=(e,t)=>{const a={...T};if(!t||t==="")delete a[e];else if(Array.isArray(t))a[e]=t;else if(typeof t=="object"&&"min"in t){const r=t.min&&t.min!=="",o=t.max&&t.max!=="";!r&&!o?delete a[e]:a[e]=t}else a[e]=t;J(a)},pe=()=>{J({})},I=M(()=>j.length===0?null:j.map(e=>{const t=d.fields[e];if(!t)return null;const a=le(e,t,F),r=t.type||"text",o=ae(r);if(!o)return re(new Error(`Field type "${r}" not registered in field type registry`),{userMessage:`Field type "${r}" is missing from registry`,context:{fieldType:r,fieldName:e,operation:"filter_ui_render",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"}),null;const m=o==="range"&&r==="year",f=o==="range"&&!m&&(r==="date"||r==="datetime-local"||r==="timestamp"||r==="time"||r==="week"||r==="month"),h=o==="range"&&!f&&!m,S=o==="select",p=o==="multiselect",n=T[e],$=typeof n=="object"&&n!==null&&"min"in n,v=$?n:{min:"",max:""},A={gridColumn:z?"span 1":"span 2"};if(o==="rating"){const s=t.validation?.max??5,l=typeof n=="string"&&n!==""?Number(n):0;return u("div",{style:{gridColumn:"span 1",gridRow:"span 1"},children:u(Fe,{value:l,max:s,"aria-label":a,onChange:i=>{c(e,i===l?void 0:String(i))}})},e)}if(h){const s=Z[e],l=s?.min??0,i=s?.max??100,g=v.min?Number(v.min):l,_=v.max?Number(v.max):i;return E(Y,{gap:"tight",style:A,children:[u(Ce,{type:"number",label:a,minPlaceholder:x("filter.min",{defaultValue:"Min"}),maxPlaceholder:x("filter.max",{defaultValue:"Max"}),minValue:K[e]?.min??v.min??"",maxValue:K[e]?.max??v.max??"",actualMin:l,actualMax:i,onChange:(y,b)=>ce(e,y,b),onClear:()=>{B(y=>{const b={...y};return delete b[e],b}),Q(y=>{const b={...y};return delete b[e],b}),c(e,void 0)}}),u(je,{value:fe[e]??[g,_],min:l,max:i,step:1,onValueChange:y=>Q(b=>({...b,[e]:y})),onValueCommit:y=>{B(b=>({...b,[e]:{min:String(y[0]),max:String(y[1])}})),c(e,{min:String(y[0]),max:String(y[1])})}},`${e}-${v.min??""}-${v.max??""}`)]},e)}if(m){const s=Z[e];return u("div",{style:A,children:u(Se,{label:a,value:$?v:void 0,onChange:l=>c(e,l),tCrud:x,minYear:s?.min??t.validation?.min,maxYear:s?.max??t.validation?.max})},e)}if(f){const s=r==="week"||r==="month"?r:"date",l=(()=>{if(n){if(typeof n=="object"&&"min"in n){const i=n;return{min:i.min&&i.min.split("T")[0]||"",max:i.max&&i.max.split("T")[0]||""}}if(typeof n=="string"){const i=n.split("T")[0]||"";return{min:i,max:i}}}})();return u("div",{style:A,children:u(Ee,{label:a,fieldType:s,value:l,locale:de,onChange:i=>{if(!i){c(e,void 0);return}typeof i=="object"&&"min"in i&&c(e,{min:i.min||"",max:i.max||""})},tCrud:x})},e)}const w=(S||p)&&t.validation&&"options"in t.validation&&t.validation?Array.isArray(t.validation.options)?t.validation.options:typeof t.validation.options=="function"?t.validation.options():[]:[],P=U[e]||C,k=new Set,ee=o==="address";P.forEach(s=>{const l=s[e];if(l!=null)if(ee&&typeof l=="object"&&"formatted_address"in l){const i=l;i.formatted_address&&k.add(String(i.formatted_address))}else k.add(String(l))});const R=new Map;P.forEach(s=>{const l=s[e];if(l!=null){const i=ee&&typeof l=="object"&&"formatted_address"in l?String(l.formatted_address):String(l);R.set(i,(R.get(i)||0)+1)}});const V=[{value:"all",label:x("filter.selectPlaceholder",{defaultValue:"All"}),count:P.length}];if(w.length>0){const s=[],l=[];w.forEach(i=>{const g=typeof i=="string"?i:i.value,_=typeof i=="string"?i:i.label;k.has(g)?s.push({value:g,label:_}):l.push({value:g,label:_})}),s.sort((i,g)=>i.label.localeCompare(g.label)),l.sort((i,g)=>i.label.localeCompare(g.label)),s.forEach(i=>{V.push({value:i.value,label:D(i.label,F),disabled:!1,count:R.get(i.value)??0})}),l.forEach(i=>{V.push({value:i.value,label:D(i.label,F),disabled:!0,count:0})})}else Array.from(k).sort().slice(0,100).forEach(s=>{V.push({value:s,label:s,count:R.get(s)??0})});if(p){const s=V.filter(i=>i.value!=="all"),l=Array.isArray(n)?n:[];return u("div",{style:{gridColumn:"span 1",gridRow:"span 1"},children:u(ie,{label:a,value:l,onValueChange:i=>{const g=Array.isArray(i)?i:[i];c(e,g.length>0?g:void 0)},options:s,placeholder:x("filter.placeholder",{defaultValue:"Filter..."}),multiple:!0,clearable:!0})},e)}return u("div",{style:{gridColumn:"span 1",gridRow:"span 1"},children:u(ie,{label:a,value:typeof n=="string"?n:void 0,onValueChange:s=>{c(e,s==="all"||!s?"":String(s))},options:V,placeholder:x("filter.placeholder",{defaultValue:"Filter..."}),clearable:!0})},e)}),[j,d.fields,C,T,F,x,U]);if(!I||I.length===0)return null;const ge=I.filter(Boolean),L=Object.keys(T).length>0,H=M(()=>{if(!L)return null;const e=[];return Object.entries(T).forEach(([t,a])=>{const r=d.fields[t];if(!r)return;const o=le(t,r,F);if(typeof a=="string"){const m=r.validation&&"options"in r.validation?D(a,F):a;e.push(E(G,{size:"sm",variant:"outline",onRemove:()=>c(t,void 0),children:[o,": ",m]},t))}else if(Array.isArray(a))a.forEach((m,f)=>{e.push(E(G,{size:"sm",variant:"outline",onRemove:()=>{const h=a.filter((S,p)=>p!==f);c(t,h.length>0?h:void 0)},children:[o,": ",D(m,F)]},`${t}-${f}`))});else if(typeof a=="object"&&"min"in a){const m=a,f=[];m.min&&f.push(m.min),m.max&&f.push(m.max);const h=f.join(" - ");h&&e.push(E(G,{size:"sm",variant:"outline",onRemove:()=>c(t,void 0),children:[o,": ",h]},t))}}),e.length>0?e:null},[T,d.fields,F,x,L]),q=E(Y,{direction:"column",gap:"tight",children:[H&&u(Y,{direction:"row",gap:"tight",style:{flexWrap:"wrap"},children:H}),E(xe,{cols:oe??(z?1:[2,4,6,8]),children:[ge,u(be,{variant:"outline",icon:u(ye,{size:18}),onClick:pe,disabled:!L,style:{gridColumn:"1 / -1",gridRow:"span 1"},children:x("filter.clear",{defaultValue:"Clear Filters"})})]})]});return z?u(Te,{style:{maxHeight:"100%"},children:q}):q}export{$e as EntityFilters,Oe as matchesFilter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as n}from"react/jsx-runtime";import{handleError as v}from"@donotdev/core";import{getFieldRegistry as F}from"../FieldRegistry";import{getMetadataRegistry as T}from"../fieldTypeRegistry.store";import{ControlledTextField as w}from"./controlled";import{TextFieldComponent as E}from"./form/fields";function h({name:
|
|
1
|
+
"use client";import{jsx as n}from"react/jsx-runtime";import{handleError as v}from"@donotdev/core";import{getFieldRegistry as F}from"../FieldRegistry";import{getMetadataRegistry as T}from"../fieldTypeRegistry.store";import{ControlledTextField as w}from"./controlled";import{TextFieldComponent as E}from"./form/fields";function h({name:r,config:e,t:o,...t}){const s=i=>l=>{try{i(l)}catch(a){v(a,{userMessage:`Error updating field ${e.label||r}`,context:{fieldName:r,fieldType:e.type},severity:"warning"})}};T();const p=F(),d="control"in t&&t.control,f=e.type==="submit"||e.type==="reset";if(d&&!f){const{control:i,errors:l}=t,a=e.options?.fieldSpecific?.placeholder,u={control:i,errors:l,fieldConfig:{...e,label:e.label||r},t:o,placeholder:a,required:e.validation?.required===!0,onChange:s(()=>{})},C=p.getControlledComponent(e.type);return C?n(C,{...u}):(v(new Error(`Unregistered field type: ${e.type}`),{userMessage:o("errors.unsupportedFieldType",{type:e.type}),context:{fieldName:r,fieldType:e.type},severity:"warning"}),n(w,{...u,fieldConfig:{...e,type:"text"}}))}const b=d&&f?{name:r,config:e,t:o,value:void 0,onChange:()=>{},error:void 0}:t,{value:c,onChange:x,error:g}=b,m=s(x),y=p.getUncontrolledComponent(e.type);return y?n(y,{name:r,label:e.label||r,value:c,onChange:m,error:g,t:o,config:e,...e.options}):n(E,{label:e.label||r,value:c,onChange:m,error:g||void 0,...e.options})}var M=h;export{h as FormFieldRenderer,M as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as d,jsxs as i,Fragment as N}from"react/jsx-runtime";import{useState as w}from"react";import{FormProvider as C}from"react-hook-form";import{Button as s,BUTTON_VARIANT as j,Spinner as k,cn as z,Stack as a,Grid as
|
|
1
|
+
"use client";import{jsx as d,jsxs as i,Fragment as N}from"react/jsx-runtime";import{useState as w}from"react";import{FormProvider as C}from"react-hook-form";import{Button as s,BUTTON_VARIANT as j,Spinner as k,cn as z,Stack as a,Grid as A}from"@donotdev/components";import{useTranslation as B}from"@donotdev/core";const F=({title:c,onSubmit:m,children:g,formMethods:f,loading:n=!1,submitText:u,cancelText:v,showCancel:p=!1,onCancel:h,variant:o="default",columns:b=1,description:l})=>{const{t:e}=B("crud"),[r,t]=w(!1),y=u||e("form.submit","Submit"),x=v||e("form.cancel","Cancel"),S=async T=>{t(!0);try{await m(T)}finally{t(!1)}},L={1:"dndev-grid-cols-1",2:"dndev-grid-cols-1 dndev-md:grid-cols-2",3:"dndev-grid-cols-1 dndev-md:grid-cols-2 dndev-md:grid-cols-3",4:"dndev-grid-cols-1 dndev-md:grid-cols-2 dndev-md:grid-cols-4"};return d(C,{...f,children:d("form",{onSubmit:S,className:z("dndev-mx-auto",{default:"dndev-surface",card:"dndev-surface",minimal:""}[o]),style:o!=="minimal"?{padding:"var(--gap-lg)"}:void 0,role:"form","aria-labelledby":"form-title",noValidate:!0,children:i(a,{gap:"large",children:[i(a,{gap:"tight",children:[d("h2",{id:"form-title",style:{fontSize:"var(--font-size-2xl)",fontWeight:600,color:"var(--foreground)"},children:c}),l&&d("p",{style:{color:"var(--muted-foreground)"},children:l})]}),d(A,{cols:b,className:"dndev-w-full dndev-min-w-0",children:g}),i(a,{direction:"row",align:"center",justify:"end",style:{paddingTop:"var(--gap-md)",borderTop:"1px solid var(--border)"},children:[p&&d(s,{type:"button",variant:j.OUTLINE,onClick:h,disabled:n||r,children:x}),d(s,{type:"submit",disabled:n||r,style:{minWidth:"120px"},children:n||r?i(N,{children:[d(k,{className:"me-component-gap"}),r?e("form.submitting","Submitting..."):e("form.loading","Loading...")]}):y})]})]})})})};var I=F;export{I as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as s}from"react/jsx-runtime";import{RangeInput as f}from"@donotdev/components";function v({label:o,value:t,onChange:i,tCrud:m,minYear:u=1900,maxYear:d=new Date().getFullYear()+10}){const l=t??{min:"",max:""};return s(f,{type:"number",label:o,min:u,max:d,minPlaceholder:m("filter.min",{defaultValue:"Min"}),maxPlaceholder:m("filter.max",{defaultValue:"Max"}),minValue:l.min||"",maxValue:l.max||"",onChange:(x,c)=>{const e=x.slice(0,4),a=c.slice(0,4),n=e?Number(e):void 0,r=a?Number(a):void 0;n!==void 0&&r!==void 0&&n>r||i(e||a?{min:e,max:a}:void 0)},onClear:()=>i(void 0)})}export{v as YearFilter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as i}from"react/jsx-runtime";import{Controller as p}from"react-hook-form";import{AddressFieldComponent as u}from"../../form/fields";import{convertValidationRules as C}from"../types";function g(n){const{control:a,errors:v,fieldConfig:e,required:s,t:d}=n,{name:c,label:f,validation:r}=e,o=(e.options||{}).fieldSpecific;return i(p,{name:c,control:a,rules:r?C(r):void 0,render:({field:l,fieldState:t})=>i(u,{label:d(f),value:l.value??void 0,onChange:m=>l.onChange(m),error:!!t.error,helperText:t.error?.message,required:s,enableGoogleMaps:o?.enableGoogleMaps,extractDistrictCode:o?.extractDistrictCode})})}export{g as ControlledAddressField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as t}from"react/jsx-runtime";import{Controller as p}from"react-hook-form";import{DateFieldComponent as C}from"../../form/fields";import{convertValidationRules as
|
|
1
|
+
"use client";import{jsx as t}from"react/jsx-runtime";import{Controller as p}from"react-hook-form";import{DateFieldComponent as C}from"../../form/fields";import{convertValidationRules as v}from"../types";function g(r){const{control:a,errors:h,fieldConfig:l,required:n,t:i}=r,{name:m,label:d,validation:o,type:s}=l,f={date:"date","datetime-local":"datetime-local",month:"month",time:"time",week:"week"}[s]||"date";return t(p,{name:m,control:a,rules:o?v(o):void 0,render:({field:e,fieldState:u})=>t(C,{...e,label:i(d),value:e.value??null,onChange:c=>e.onChange(c),error:u.error?.message,required:n,mode:f})})}export{g as ControlledDateField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsxs as
|
|
1
|
+
"use client";import{jsxs as t,jsx as i}from"react/jsx-runtime";import{Plus as $,Trash2 as q}from"lucide-react";import{useFieldArray as B,Controller as D}from"react-hook-form";import{Button as y}from"@donotdev/components";import{getFieldRegistry as I}from"../../../FieldRegistry";import{convertValidationRules as R}from"../types";function j(s){switch(s){case"number":return 0;case"boolean":return!1;default:return""}}function k(s){const{control:d,errors:h,fieldConfig:c,required:x,t:r}=s,{name:p,label:f,validation:A}=c,v=c.options?.fieldSpecific??{},o=v.fields??[],l=v.direction??"row",{fields:b,append:C,remove:w}=B({control:d,name:p}),S=I(),z=()=>{if(o.length===0)return;const a={};for(const n of o)a[n.name]=j(n.type);C(a)};return o.length===0?t("div",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},children:[r(f),": no sub-fields configured"]}):t("div",{style:{display:"flex",flexDirection:"column",gap:"var(--gap-sm)"},children:[t("div",{style:{display:"flex",alignItems:"center",gap:"var(--gap-sm)"},children:[t("span",{style:{fontSize:"var(--font-size-sm)",fontWeight:"var(--font-weight-medium)"},children:[r(f),x&&i("span",{style:{color:"var(--destructive)",marginInlineStart:"var(--gap-tight)"},children:"*"})]}),i(y,{type:"button",variant:"ghost",display:"compact",icon:$,onClick:z,"aria-label":r(f)+" \u2014 add"})]}),b.map((a,n)=>t("div",{style:{display:"flex",flexDirection:l,gap:"var(--gap-sm)",alignItems:l==="row"?"flex-start":void 0},children:[o.map(e=>{const u=`${p}.${n}.${e.name}`,F={name:u,type:e.type,label:e.label,visibility:c.visibility,validation:{...e.validation??{},...e.required?{required:!0}:{}},options:e.options??{}},g=S.getControlledComponent(e.type);return g?i("div",{style:{flex:l==="row"?1:void 0},children:i(g,{control:d,errors:h,fieldConfig:F,t:r})},e.name):i("div",{style:{flex:l==="row"?1:void 0},children:i(D,{name:u,control:d,rules:e.validation?R(e.validation):void 0,render:({field:m})=>t("label",{style:{display:"flex",flexDirection:"column",gap:"var(--gap-tight)"},children:[i("span",{style:{fontSize:"var(--font-size-xs)"},children:r(e.label)}),i("input",{className:"dndev-input",value:String(m.value??""),onChange:m.onChange,onBlur:m.onBlur})]})})},e.name)}),i(y,{type:"button",variant:"ghost",display:"compact",icon:q,onClick:()=>w(n),"aria-label":`Remove row ${n+1}`,style:{alignSelf:l==="row"?"center":"flex-end"}})]},a.id))]})}export{k as ControlledFieldArrayField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as n}from"react/jsx-runtime";import{Controller as f}from"react-hook-form";import{GeoPointFieldComponent as p}from"../../form/fields";import{convertValidationRules as C}from"../types";function h(l){const{control:a,errors:v,fieldConfig:i,required:s,t:d}=l,{name:m,label:g,validation:r}=i;return n(f,{name:m,control:a,rules:r?C(r):void 0,render:({field:e,fieldState:t})=>{const u=o=>{if("target"in o)try{const c=JSON.parse(o.target.value);e.onChange(c)}catch{e.onChange({lat:0,lng:0})}else e.onChange(o||{lat:0,lng:0})};return n(p,{label:d(g),value:e.value||{lat:0,lng:0},onChange:u,error:!!t.error,helperText:t.error?.message,required:s})}})}export{h as ControlledGeoPointField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as t}from"react/jsx-runtime";import{Controller as p}from"react-hook-form";import{MapFieldComponent as g}from"../../form/fields";import{convertValidationRules as C}from"../types";function h(a){const{control:l,errors:v,fieldConfig:i,required:s,t:d}=a,{name:m,label:u,validation:o}=i;return t(p,{name:m,control:l,rules:o?C(o):void 0,render:({field:e,fieldState:n})=>{const c=r=>{if("target"in r)try{const f=JSON.parse(r.target.value);e.onChange(f)}catch{e.onChange({})}else e.onChange(r||{})};return t(g,{label:d(u),value:e.value||{},onChange:c,error:!!n.error,helperText:n.error?.message,required:s})}})}export{h as ControlledMapField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as n}from"react/jsx-runtime";import{Controller as f}from"react-hook-form";import{MultiInputTextFieldComponent as C}from"../../form/fields";import{convertValidationRules as
|
|
1
|
+
"use client";import{jsx as n}from"react/jsx-runtime";import{Controller as f}from"react-hook-form";import{MultiInputTextFieldComponent as C}from"../../form/fields";import{convertValidationRules as v}from"../types";function y(t){const{control:l,errors:g,fieldConfig:i,required:s,t:u}=t,{name:m,label:c,validation:o,options:d={}}=i;return n(f,{name:m,control:l,rules:o?v(o):void 0,render:({field:r})=>{const p=e=>{if(Array.isArray(e))r.onChange(e);else try{const a=JSON.parse(e.target.value);r.onChange(Array.isArray(a)?a:[])}catch{r.onChange([])}};return n(C,{label:u(c),value:Array.isArray(r.value)?r.value:[],onChange:p,required:s,className:d.className})}})}export{y as ControlledMultiInputField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as a}from"react/jsx-runtime";import{Controller as
|
|
1
|
+
"use client";import{jsx as a}from"react/jsx-runtime";import{Controller as f}from"react-hook-form";import{RichTextComponent as h}from"../../form/fields";import{convertValidationRules as C}from"../types";function g(n){const{control:t,errors:x,fieldConfig:i,placeholder:s,required:m,t:d}=n,{name:c,label:p,validation:e,options:r={}}=i;return a(f,{name:c,control:t,rules:e?C(e):void 0,render:({field:o,fieldState:l})=>a(h,{label:d(p),value:o.value??"",onChange:u=>o.onChange(u),error:l.error?.message,helperText:l.error?.message,required:m,placeholder:s||r.placeholder,className:r.className})})}export{g as ControlledRichTextField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as o}from"react/jsx-runtime";import{Controller as
|
|
1
|
+
"use client";import{jsx as o}from"react/jsx-runtime";import{Controller as f}from"react-hook-form";import{TimestampFieldComponent as p}from"../../form/fields";import{convertValidationRules as c}from"../types";function C(l){const{control:n,errors:v,fieldConfig:t,required:a,t:i}=l,{name:m,label:s,validation:r}=t;return o(f,{name:m,control:n,rules:r?c(r):void 0,render:({field:e,fieldState:d})=>o(p,{...e,label:i(s),value:e.value??null,onChange:u=>e.onChange(u),error:d.error?.message,required:a})})}export{C as ControlledTimestampField};
|