@donotdev/crud 0.0.12 → 0.0.14
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/DateFilter.d.ts +30 -0
- package/dist/components/DateFilter.d.ts.map +1 -0
- package/dist/components/DateFilter.js +1 -0
- package/dist/components/DisplayFieldRenderer.js +1 -1
- package/dist/components/EntityDisplayRenderer.js +1 -1
- package/dist/components/EntityFilters.d.ts +28 -15
- 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.d.ts.map +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/PhoneNumberComponent.d.ts.map +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/hooks/useEntityForm.d.ts.map +1 -1
- package/dist/forms/index.js +1 -1
- package/dist/forms/utils/getFieldsForOperation.d.ts.map +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/translateFieldLabel.d.ts.map +1 -1
- package/dist/forms/utils/validateEntity.js +1 -1
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/useCrudFilters.d.ts +32 -0
- package/dist/hooks/useCrudFilters.d.ts.map +1 -0
- package/dist/hooks/useCrudFilters.js +1 -0
- 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.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/registerBuiltinFieldTypes.d.ts.map +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/types.d.ts +4 -1
- package/dist/types.d.ts.map +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 +3 -3
package/dist/CrudService.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{toast as u}from"@donotdev/components";import{createSingleton as p,handleError as n,getQueryClient as y,getI18nInstance as c}from"@donotdev/core";import{FirestoreAdapter as m}from"./adapters/FirestoreAdapter";import{FunctionsAdapter as f}from"./adapters/FunctionsAdapter";const l=1/0,F=1e3*60*30;class S{adapter=null;backend=null;store=null;_shouldShowSuccessToast(t){return t?.showSuccessToast===!0?!0:t?.showSuccessToast===!1?!1:!this.store?.getState().hideSuccessToasts}setStore(t){this.store=t}async initialize(t){if(!(this.backend===t&&this.adapter)){if(this.backend=t,t==="functions")this.adapter=new f;else if(t==="firestore")this.adapter=new m;else throw new Error(`Unknown backend: ${t}`);this.store&&(this.store.getState().setBackend(t),this.store.getState().setCrudService(this))}}getQueryClient(){return y()}getListQueryOptions(t,e,r,a,s="list"){const i=this.adapter,o=()=>this.initialize("firestore");return{queryKey:["crud",t,"query",s,JSON.stringify(e)],queryFn:async()=>{if(i||await o(),!this.adapter)throw new Error("Adapter not initialized");return this.adapter.query(t,e,r,s)},staleTime:a?.staleTime??l}}getDocQueryOptions(t,e,r,a){const s=this.adapter,i=()=>this.initialize("firestore");return{queryKey:["crud",t,"get",e],queryFn:async()=>{if(s||await i(),!this.adapter)throw new Error("Adapter not initialized");return this.adapter.get(t,e,r)},staleTime:a?.staleTime??l}}_updateGetCache(t,e,r,a){const s=this.getQueryClient(),i=["crud",t,"get",e];a==="delete"?s.removeQueries({queryKey:i}):(a==="update"||a==="add")&&r&&s.setQueryData(i,o=>o?{...o,...r}:r)}_updateListCaches(t,e,r,a){const s=this.getQueryClient();this._updateGetCache(t,e,r,a),s.setQueriesData({queryKey:["crud",t]},i=>{if(i&&typeof i=="object"&&"items"in i){const o=i;let h=o.items;return a==="delete"?(h=o.items.filter(d=>d.id!==e),{...o,items:h,total:(o.total??h.length)-1}):a==="add"&&r?(h=[...o.items,{...r,id:e}],{...o,items:h,total:(o.total??o.items.length)+1}):a==="update"&&r&&o.items.some(d=>d.id===e)?(h=o.items.map(d=>d.id===e?{...d,...r}:d),{...o,items:h}):i}if(Array.isArray(i)){if(a==="delete")return i.filter(o=>o.id!==e);if(a==="add"&&r)return[...i,{...r,id:e}];if(a==="update"&&r)return i.some(o=>o.id===e)?i.map(o=>o.id===e?{...o,...r}:o):i}return i})}_getItemFromListCache(t,e){const r=this.getQueryClient().getQueriesData({queryKey:["crud",t]});for(const[,a]of r)if(a?.items){const s=a.items.find(i=>i.id===e);if(s)return s}return null}async invalidateCollection(t){await this.getQueryClient().invalidateQueries({queryKey:["crud",t]})}async get(t,e,r,a){if(this.adapter||await this.initialize("firestore"),a?.noCache)return this._getFromAdapter(t,e,r);this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{return await this.getQueryClient().fetchQuery({queryKey:["crud",t,"get",e],queryFn:()=>this._getFromAdapter(t,e,r,!1),staleTime:a?.staleTime??l})}catch(s){const i=n(s,{userMessage:`Failed to fetch ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,i),i}finally{this.store&&this.store.getState().setLoading(t,!1)}}async _getFromAdapter(t,e,r,a=!0){this.store&&a&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{if(!this.adapter)throw new Error("Adapter not initialized");return await this.adapter.get(t,e,r)}catch(s){const i=n(s,{userMessage:`Failed to fetch ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,i),i}finally{this.store&&a&&this.store.getState().setLoading(t,!1)}}async query(t,e,r,a,s="list"){if(this.adapter||await this.initialize("firestore"),a?.noCache)return this._queryFromAdapter(t,e,r,!0,s);this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{return await this.getQueryClient().fetchQuery({queryKey:["crud",t,"query",s,JSON.stringify(e)],queryFn:()=>this._queryFromAdapter(t,e,r,!1,s),staleTime:a?.staleTime??l})}catch(i){const o=n(i,{userMessage:`Failed to query ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,o),o}finally{this.store&&this.store.getState().setLoading(t,!1)}}async _queryFromAdapter(t,e,r,a=!0,s="list"){this.store&&a&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{if(!this.adapter)throw new Error("Adapter not initialized");return await this.adapter.query(t,e,r,s)}catch(i){const o=n(i,{userMessage:`Failed to query ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,o),o}finally{this.store&&a&&this.store.getState().setLoading(t,!1)}}_getEntityName(t){const e=c();let r=`entity-${t}`,a=e.t("name",{ns:r,defaultValue:null});return a&&a!=="name"&&a!==`${r}:name`||t.endsWith("s")&&t.length>1&&(r=`entity-${t.slice(0,-1)}`,a=e.t("name",{ns:r,defaultValue:null}),a&&a!=="name"&&a!==`${r}:name`)?a:t}async set(t,e,r,a,s){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const i=this.getQueryClient().getQueryData(["crud",t,"get",e])??null;this.store&&this.store.getState().updateOptimistic(t,e,r,i);try{if(!this.adapter)throw new Error("Adapter not initialized");if(await this.adapter.set(t,e,r,a),this._updateListCaches(t,e,r,"update"),this.store&&this.store.getState().confirmUpdate(t,e),this._shouldShowSuccessToast(s)){const o=c(),h=this._getEntityName(t);u("success",o.t("messages.updateSuccess",{ns:"crud",entity:h}))}}catch(o){i&&this._updateListCaches(t,e,i,"update"),this.store&&this.store.getState().rejectUpdate(t,e);const h=n(o,{userMessage:`Failed to save ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,h),h}finally{this.store&&this.store.getState().setLoading(t,!1)}}async update(t,e,r,a){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const s=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e),i=s?{...s,...r}:{...r,id:e};this.store&&s&&this.store.getState().updateOptimistic(t,e,i,s);try{if(!this.adapter)throw new Error("Adapter not initialized");if(await this.adapter.update(t,e,r),this._updateListCaches(t,e,i,"update"),this.store&&this.store.getState().confirmUpdate(t,e),this._shouldShowSuccessToast(a)){const o=c(),h=this._getEntityName(t);u("success",o.t("messages.updateSuccess",{ns:"crud",entity:h}))}}catch(o){s&&this._updateListCaches(t,e,s,"update"),this.store&&this.store.getState().rejectUpdate(t,e);const h=n(o,{userMessage:`Failed to update ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,h),h}finally{this.store&&this.store.getState().setLoading(t,!1)}}async delete(t,e,r){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const a=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e);this.store&&a&&this.store.getState().deleteOptimistic(t,e,a);try{if(!this.adapter)throw new Error("Adapter not initialized");if(await this.adapter.delete(t,e),this._updateListCaches(t,e,null,"delete"),this.store&&this.store.getState().confirmDelete(t,e),this._shouldShowSuccessToast(r)){const s=c(),i=this._getEntityName(t);u("success",s.t("messages.deleteSuccess",{ns:"crud",entity:i}))}}catch(s){a&&this._updateListCaches(t,e,a,"add"),this.store&&this.store.getState().rejectDelete(t,e);const i=n(s,{userMessage:`Failed to delete ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,i),i}finally{this.store&&this.store.getState().setLoading(t,!1)}}async add(t,e,r,a){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const s=`temp_${crypto.randomUUID()}`;this.store&&this.store.getState().addOptimistic(t,s,{...e,id:s});try{if(!this.adapter)throw new Error("Adapter not initialized");const i=await this.adapter.add(t,e,r);if(this._updateListCaches(t,s,null,"delete"),this._updateListCaches(t,i,{...e,id:i},"add"),this.store&&this.store.getState().confirmOptimistic(t,s,i,{...e,id:i}),this._shouldShowSuccessToast(a)){const o=c(),h=this._getEntityName(t);u("success",o.t("messages.createSuccess",{ns:"crud",entity:h}))}return i}catch(i){this._updateListCaches(t,s,null,"delete"),this.store&&this.store.getState().rejectOptimistic(t,s);const o=n(i,{userMessage:`Failed to create ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,o),o}finally{this.store&&this.store.getState().setLoading(t,!1)}}subscribe(t,e,r,a){this.adapter||this.initialize("firestore").catch(()=>{});try{return this.adapter?this.adapter.subscribe(t,e,(s,i)=>{s&&this.getQueryClient().setQueryData(["crud",t,"get",e],s),r(s,i)},a):(r(null,new Error("Adapter not initialized")),()=>{})}catch(s){return r(null,n(s)),()=>{}}}subscribeToCollection(t,e,r,a){this.adapter||this.initialize("firestore").catch(()=>{});try{return this.adapter?this.adapter.subscribeToCollection(t,e,(s,i)=>{s&&this.getQueryClient().setQueryData(["crud",t,"query",JSON.stringify(e)],{items:s}),r(s,i)},a):(r([],new Error("Adapter not initialized")),()=>{})}catch(s){return r([],n(s)),()=>{}}}async addOptimistic(t,e,r,a){this.adapter||await this.initialize("firestore");const s=`temp_${crypto.randomUUID()}`,i={...e,id:s,_optimistic:!0};this.store&&this.store.getState().addOptimistic(t,s,i);try{if(!this.adapter)throw new Error("Adapter not initialized");const o=await this.adapter.add(t,e,r),h={...e,id:o};if(this._updateListCaches(t,s,null,"delete"),this._updateListCaches(t,o,h,"add"),this.store&&this.store.getState().confirmOptimistic(t,s,o,h),this._shouldShowSuccessToast(a)){const d=c(),g=this._getEntityName(t);u("success",d.t("messages.createSuccess",{ns:"crud",entity:g}))}return h}catch(o){throw this._updateListCaches(t,s,null,"delete"),this.store&&this.store.getState().rejectOptimistic(t,s),n(o,{userMessage:`Failed to create ${t}`,showNotification:!0})}}async updateOptimistic(t,e,r,a,s){this.adapter||await this.initialize("firestore");const i=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e),o=i?{...i,...r,_optimistic:!0}:{...r,id:e,_optimistic:!0};this.store&&i&&this.store.getState().updateOptimistic(t,e,o,i);try{if(!this.adapter)throw new Error("Adapter not initialized");await this.adapter.update(t,e,r);const h={...o,_optimistic:void 0};if(this._updateListCaches(t,e,h,"update"),this.store&&this.store.getState().confirmUpdate(t,e),this._shouldShowSuccessToast(s)){const d=c(),g=this._getEntityName(t);u("success",d.t("messages.updateSuccess",{ns:"crud",entity:g}))}return h}catch(h){throw i&&this._updateListCaches(t,e,i,"update"),this.store&&this.store.getState().rejectUpdate(t,e),n(h,{userMessage:`Failed to update ${t}`,showNotification:!0})}}async deleteOptimistic(t,e,r){this.adapter||await this.initialize("firestore");const a=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e);this.store&&a&&this.store.getState().deleteOptimistic(t,e,a);try{if(!this.adapter)throw new Error("Adapter not initialized");if(await this.adapter.delete(t,e),this._updateListCaches(t,e,null,"delete"),this.store&&this.store.getState().confirmDelete(t,e),this._shouldShowSuccessToast(r)){const s=c(),i=this._getEntityName(t);u("success",s.t("messages.deleteSuccess",{ns:"crud",entity:i}))}}catch(s){throw a&&this._updateListCaches(t,e,a,"add"),this.store&&this.store.getState().rejectDelete(t,e),n(s,{userMessage:`Failed to delete ${t}`,showNotification:!0})}}}const w=p(()=>new S);export{w as getCrudService};
|
|
1
|
+
import{toast as p}from"@donotdev/components";import{createSingleton as m,handleError as d,getQueryClient as w,getI18nInstance as f}from"@donotdev/core";import{FirestoreAdapter as S}from"./adapters/FirestoreAdapter";import{FunctionsAdapter as C}from"./adapters/FunctionsAdapter";const g=1/0,Q=1e3*60*30;class c{adapter=null;backend=null;store=null;_shouldShowSuccessToast(t){return t?.showSuccessToast===!0?!0:t?.showSuccessToast===!1?!1:!this.store?.getState().hideSuccessToasts}setStore(t){this.store=t}async initialize(t){if(!(this.backend===t&&this.adapter)){if(this.backend=t,t==="functions")this.adapter=new C;else if(t==="firestore")this.adapter=new S;else throw new Error(`Unknown backend: ${t}`);this.store&&(this.store.getState().setBackend(t),this.store.getState().setCrudService(this))}}getQueryClient(){return w()}getListQueryOptions(t,e,i,h,s="list"){const r=this.adapter,a=()=>this.initialize("firestore");return{queryKey:["crud",t,"query",s,JSON.stringify(e)],queryFn:async()=>{if(r||await a(),!this.adapter)throw new Error("Adapter not initialized");return this.adapter.query(t,e,i,s)},staleTime:h?.staleTime??g}}getDocQueryOptions(t,e,i,h){const s=this.adapter,r=()=>this.initialize("firestore");return{queryKey:["crud",t,"get",e],queryFn:async()=>{if(s||await r(),!this.adapter)throw new Error("Adapter not initialized");return this.adapter.get(t,e,i)},staleTime:h?.staleTime??g}}_updateGetCache(t,e,i,h){const s=this.getQueryClient(),r=["crud",t,"get",e];h==="delete"?s.removeQueries({queryKey:r}):(h==="update"||h==="add")&&i&&s.setQueryData(r,a=>a?{...a,...i}:i)}_updateListCaches(t,e,i,h){const s=this.getQueryClient();this._updateGetCache(t,e,i,h),s.setQueriesData({queryKey:["crud",t]},r=>{if(r&&typeof r=="object"&&"items"in r){const a=r;let u=a.items;return h==="delete"?(u=a.items.filter(n=>n.id!==e),{...a,items:u,total:(a.total??u.length)-1}):h==="add"&&i?(u=[...a.items,{...i,id:e}],{...a,items:u,total:(a.total??a.items.length)+1}):h==="update"&&i&&a.items.some(o=>o.id===e)?(u=a.items.map(o=>o.id===e?{...o,...i}:o),{...a,items:u}):r}if(Array.isArray(r)){if(h==="delete")return r.filter(a=>a.id!==e);if(h==="add"&&i)return[...r,{...i,id:e}];if(h==="update"&&i)return r.some(u=>u.id===e)?r.map(u=>u.id===e?{...u,...i}:u):r}return r})}_getItemFromListCache(t,e){const h=this.getQueryClient().getQueriesData({queryKey:["crud",t]});for(const[,s]of h)if(s?.items){const r=s.items.find(a=>a.id===e);if(r)return r}return null}async invalidateCollection(t){await this.getQueryClient().invalidateQueries({queryKey:["crud",t]})}async get(t,e,i,h){if(this.adapter||await this.initialize("firestore"),h?.noCache)return this._getFromAdapter(t,e,i);this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{return await this.getQueryClient().fetchQuery({queryKey:["crud",t,"get",e],queryFn:()=>this._getFromAdapter(t,e,i,!1),staleTime:h?.staleTime??g})}catch(s){const r=d(s,{userMessage:`Failed to fetch ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,r),r}finally{this.store&&this.store.getState().setLoading(t,!1)}}async _getFromAdapter(t,e,i,h=!0){this.store&&h&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{if(!this.adapter)throw new Error("Adapter not initialized");return await this.adapter.get(t,e,i)}catch(s){const r=d(s,{userMessage:`Failed to fetch ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,r),r}finally{this.store&&h&&this.store.getState().setLoading(t,!1)}}async query(t,e,i,h,s="list"){if(this.adapter||await this.initialize("firestore"),h?.noCache)return this._queryFromAdapter(t,e,i,!0,s);this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{return await this.getQueryClient().fetchQuery({queryKey:["crud",t,"query",s,JSON.stringify(e)],queryFn:()=>this._queryFromAdapter(t,e,i,!1,s),staleTime:h?.staleTime??g})}catch(r){const a=d(r,{userMessage:`Failed to query ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,a),a}finally{this.store&&this.store.getState().setLoading(t,!1)}}async _queryFromAdapter(t,e,i,h=!0,s="list"){this.store&&h&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{if(!this.adapter)throw new Error("Adapter not initialized");return await this.adapter.query(t,e,i,s)}catch(r){const a=d(r,{userMessage:`Failed to query ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,a),a}finally{this.store&&h&&this.store.getState().setLoading(t,!1)}}_getEntityName(t){const e=f();let i=`entity-${t}`,h=e.t("name",{ns:i,defaultValue:null});return h&&h!=="name"&&h!==`${i}:name`||t.endsWith("s")&&t.length>1&&(i=`entity-${t.slice(0,-1)}`,h=e.t("name",{ns:i,defaultValue:null}),h&&h!=="name"&&h!==`${i}:name`)?h:t}async set(t,e,i,h,s){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const a=this.getQueryClient().getQueryData(["crud",t,"get",e])??null;this.store&&this.store.getState().updateOptimistic(t,e,i,a);try{if(!this.adapter)throw new Error("Adapter not initialized");if(await this.adapter.set(t,e,i,h),this._updateListCaches(t,e,i,"update"),this.store&&this.store.getState().confirmUpdate(t,e),this._shouldShowSuccessToast(s)){const u=f(),n=this._getEntityName(t);p("success",u.t("messages.updateSuccess",{ns:"crud",entity:n}))}}catch(u){a&&this._updateListCaches(t,e,a,"update"),this.store&&this.store.getState().rejectUpdate(t,e);const n=d(u,{userMessage:`Failed to save ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,n),n}finally{this.store&&this.store.getState().setLoading(t,!1)}}async update(t,e,i,h){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const r=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e),a=r?{...r,...i}:{...i,id:e};this.store&&r&&this.store.getState().updateOptimistic(t,e,a,r);try{if(!this.adapter)throw new Error("Adapter not initialized");if(await this.adapter.update(t,e,i),this._updateListCaches(t,e,a,"update"),this.store&&this.store.getState().confirmUpdate(t,e),this._shouldShowSuccessToast(h)){const u=f(),n=this._getEntityName(t);p("success",u.t("messages.updateSuccess",{ns:"crud",entity:n}))}}catch(u){r&&this._updateListCaches(t,e,r,"update"),this.store&&this.store.getState().rejectUpdate(t,e);const n=d(u,{userMessage:`Failed to update ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,n),n}finally{this.store&&this.store.getState().setLoading(t,!1)}}async delete(t,e,i){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const s=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e);this.store&&s&&this.store.getState().deleteOptimistic(t,e,s);try{if(!this.adapter)throw new Error("Adapter not initialized");if(await this.adapter.delete(t,e),this._updateListCaches(t,e,null,"delete"),this.store&&this.store.getState().confirmDelete(t,e),this._shouldShowSuccessToast(i)){const r=f(),a=this._getEntityName(t);p("success",r.t("messages.deleteSuccess",{ns:"crud",entity:a}))}}catch(r){s&&this._updateListCaches(t,e,s,"add"),this.store&&this.store.getState().rejectDelete(t,e);const a=d(r,{userMessage:`Failed to delete ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,a),a}finally{this.store&&this.store.getState().setLoading(t,!1)}}async add(t,e,i,h){this.adapter||await this.initialize("firestore"),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const s=`temp_${crypto.randomUUID()}`;this.store&&this.store.getState().addOptimistic(t,s,{...e,id:s});try{if(!this.adapter)throw new Error("Adapter not initialized");const r=await this.adapter.add(t,e,i);if(this._updateListCaches(t,s,null,"delete"),this._updateListCaches(t,r,{...e,id:r},"add"),this.store&&this.store.getState().confirmOptimistic(t,s,r,{...e,id:r}),this._shouldShowSuccessToast(h)){const a=f(),u=this._getEntityName(t);p("success",a.t("messages.createSuccess",{ns:"crud",entity:u}))}return r}catch(r){this._updateListCaches(t,s,null,"delete"),this.store&&this.store.getState().rejectOptimistic(t,s);const a=d(r,{userMessage:`Failed to create ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,a),a}finally{this.store&&this.store.getState().setLoading(t,!1)}}subscribe(t,e,i,h){this.adapter||this.initialize("firestore").catch(()=>{});try{return this.adapter?this.adapter.subscribe(t,e,(s,r)=>{s&&this.getQueryClient().setQueryData(["crud",t,"get",e],s),i(s,r)},h):(i(null,new Error("Adapter not initialized")),()=>{})}catch(s){return i(null,d(s)),()=>{}}}subscribeToCollection(t,e,i,h){this.adapter||this.initialize("firestore").catch(()=>{});try{return this.adapter?this.adapter.subscribeToCollection(t,e,(s,r)=>{s&&this.getQueryClient().setQueryData(["crud",t,"query",JSON.stringify(e)],{items:s}),i(s,r)},h):(i([],new Error("Adapter not initialized")),()=>{})}catch(s){return i([],d(s)),()=>{}}}async addOptimistic(t,e,i,h){this.adapter||await this.initialize("firestore");const s=`temp_${crypto.randomUUID()}`,r={...e,id:s,_optimistic:!0};this.store&&this.store.getState().addOptimistic(t,s,r);try{if(!this.adapter)throw new Error("Adapter not initialized");const a=await this.adapter.add(t,e,i),u={...e,id:a};if(this._updateListCaches(t,s,null,"delete"),this._updateListCaches(t,a,u,"add"),this.store&&this.store.getState().confirmOptimistic(t,s,a,u),this._shouldShowSuccessToast(h)){const n=f(),o=this._getEntityName(t);p("success",n.t("messages.createSuccess",{ns:"crud",entity:o}))}return u}catch(a){throw this._updateListCaches(t,s,null,"delete"),this.store&&this.store.getState().rejectOptimistic(t,s),d(a,{userMessage:`Failed to create ${t}`,showNotification:!0})}}async updateOptimistic(t,e,i,h,s){this.adapter||await this.initialize("firestore");const a=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e),u=a?{...a,...i,_optimistic:!0}:{...i,id:e,_optimistic:!0};this.store&&a&&this.store.getState().updateOptimistic(t,e,u,a);try{if(!this.adapter)throw new Error("Adapter not initialized");await this.adapter.update(t,e,i);const n={...u,_optimistic:void 0};if(this._updateListCaches(t,e,n,"update"),this.store&&this.store.getState().confirmUpdate(t,e),this._shouldShowSuccessToast(s)){const o=f(),y=this._getEntityName(t);p("success",o.t("messages.updateSuccess",{ns:"crud",entity:y}))}return n}catch(n){throw a&&this._updateListCaches(t,e,a,"update"),this.store&&this.store.getState().rejectUpdate(t,e),d(n,{userMessage:`Failed to update ${t}`,showNotification:!0})}}async deleteOptimistic(t,e,i){this.adapter||await this.initialize("firestore");const s=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e);this.store&&s&&this.store.getState().deleteOptimistic(t,e,s);try{if(!this.adapter)throw new Error("Adapter not initialized");if(await this.adapter.delete(t,e),this._updateListCaches(t,e,null,"delete"),this.store&&this.store.getState().confirmDelete(t,e),this._shouldShowSuccessToast(i)){const r=f(),a=this._getEntityName(t);p("success",r.t("messages.deleteSuccess",{ns:"crud",entity:a}))}}catch(r){throw s&&this._updateListCaches(t,e,s,"add"),this.store&&this.store.getState().rejectDelete(t,e),d(r,{userMessage:`Failed to delete ${t}`,showNotification:!0})}}}const N=m(()=>new c);export{N as getCrudService};
|
package/dist/CrudStore.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createDoNotDevStore as
|
|
1
|
+
import{createDoNotDevStore as m}from"@donotdev/core";const u={filters:{},showFavoritesOnly:!1};function r(){return{loading:!1,error:null,lastUpdated:0,optimistic:{},ui:{...u}}}const d={backend:null,crudService:null,hideSuccessToasts:!1,collections:{}},f=m({name:"crud-store",createStore:(n,s)=>({...d,setCrudService:t=>{n({crudService:t})},setBackend:t=>{n({backend:t})},setHideSuccessToasts:t=>{n({hideSuccessToasts:t})},setLoading:(t,c)=>{n(i=>{const o=i.collections[t]||r();return{collections:{...i.collections,[t]:{...o,loading:c}}}})},setError:(t,c)=>{n(i=>{const o=i.collections[t]||r();return{collections:{...i.collections,[t]:{...o,error:c,loading:!1}}}})},setFilters:(t,c)=>{n(i=>{const o=i.collections[t]||r();return{collections:{...i.collections,[t]:{...o,ui:{...o.ui,filters:c}}}}})},setShowFavoritesOnly:(t,c)=>{n(i=>{const o=i.collections[t]||r();return{collections:{...i.collections,[t]:{...o,ui:{...o.ui,showFavoritesOnly:c}}}}})},getFilters:t=>s().collections[t]?.ui?.filters||{},getShowFavoritesOnly:t=>s().collections[t]?.ui?.showFavoritesOnly||!1,clearCollection:t=>{n(c=>{const{[t]:i,...o}=c.collections;return{collections:o}})},clearError:t=>{n(c=>{const i=c.collections[t];return i?{collections:{...c.collections,[t]:{...i,error:null}}}:c})},addOptimistic:(t,c,i)=>{n(o=>{const e=o.collections[t]||r();return{collections:{...o.collections,[t]:{...e,optimistic:{...e.optimistic,[c]:{tempId:c,originalData:null,optimisticData:i,status:"pending",operation:"add"}},lastUpdated:Date.now()}}}})},confirmOptimistic:(t,c,i,o)=>{n(e=>{const l=e.collections[t];if(!l)return e;const{[c]:a,...p}=l.optimistic;return{collections:{...e.collections,[t]:{...l,optimistic:p,lastUpdated:Date.now()}}}})},rejectOptimistic:(t,c)=>{n(i=>{const o=i.collections[t];if(!o)return i;const{[c]:e,...l}=o.optimistic;return{collections:{...i.collections,[t]:{...o,optimistic:l,lastUpdated:Date.now()}}}})},updateOptimistic:(t,c,i,o)=>{n(e=>{const l=e.collections[t]||r();return{collections:{...e.collections,[t]:{...l,optimistic:{...l.optimistic,[c]:{tempId:c,originalData:o,optimisticData:i,status:"pending",operation:"update"}},lastUpdated:Date.now()}}}})},confirmUpdate:(t,c)=>{n(i=>{const o=i.collections[t];if(!o)return i;const{[c]:e,...l}=o.optimistic;return{collections:{...i.collections,[t]:{...o,optimistic:l}}}})},rejectUpdate:(t,c)=>{n(i=>{const o=i.collections[t];if(!o)return i;const e=o.optimistic[c];if(!e||e.operation!=="update")return i;const{[c]:l,...a}=o.optimistic;return{collections:{...i.collections,[t]:{...o,optimistic:a,lastUpdated:Date.now()}}}})},deleteOptimistic:(t,c,i)=>{n(o=>{const e=o.collections[t];return e?{collections:{...o.collections,[t]:{...e,optimistic:{...e.optimistic,[c]:{tempId:c,originalData:i,optimisticData:null,status:"pending",operation:"delete"}},lastUpdated:Date.now()}}}:o})},confirmDelete:(t,c)=>{n(i=>{const o=i.collections[t];if(!o)return i;const{[c]:e,...l}=o.optimistic;return{collections:{...i.collections,[t]:{...o,optimistic:l}}}})},rejectDelete:(t,c)=>{n(i=>{const o=i.collections[t];if(!o)return i;const e=o.optimistic[c];if(!e||e.operation!=="delete")return i;const{[c]:l,...a}=o.optimistic;return{collections:{...i.collections,[t]:{...o,optimistic:a,lastUpdated:Date.now()}}}})},getLoading:t=>s().collections[t]?.loading||!1,getError:t=>s().collections[t]?.error||null,isOptimistic:(t,c)=>s().collections[t]?.optimistic[c]?.status==="pending",getOptimisticStatus:(t,c)=>s().collections[t]?.optimistic[c]?.status??null,getOptimisticData:(t,c)=>s().collections[t]?.optimistic[c]?.optimisticData??null})});export{f as useCrudStore};
|
package/dist/FieldRegistry.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";class
|
|
1
|
+
"use client";class i{components=new Map;registerComponent(e,n,o){this.components.set(e,{controlled:n,uncontrolled:o})}register(e){const{type:n,controlledComponent:o,uncontrolledComponent:l}=e;this.components.set(n,{controlled:o,uncontrolled:l})}getControlledComponent(e){return this.components.get(e)?.controlled}getUncontrolledComponent(e){return this.components.get(e)?.uncontrolled}has(e){return this.components.has(e)}getRegisteredTypes(){return Array.from(this.components.keys())}clear(){this.components.clear()}}let r=null;function s(){return r||(r=new i),r}function c(t){s().register(t)}function p(t){return s().has(t)}export{s as getFieldRegistry,p as isFieldTypeRegistered,c as registerFieldType};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as
|
|
1
|
+
import*as h from"valibot";import{handleError as m}from"@donotdev/core";import{getFirestore as B,getFirebaseSDK as C,doc as p,getDoc as w,getDocs as E,setDoc as v,updateDoc as V,deleteDoc as z,addDoc as M,collection as L,query as A,where as D,orderBy as R,limit as I,startAfter as S,onSnapshot as q}from"@donotdev/firebase";import{transformFirestoreData as F,prepareForFirestore as g}from"@donotdev/firebase";class W{firestore;ensureFirestore(){if(this.firestore)return!0;try{return this.firestore=B(),!0}catch{return!1}}getCollectionRef(s){return!this.ensureFirestore()||!this.firestore?null:L(this.firestore,s)}async get(s,e,t){if(!this.ensureFirestore()||!this.firestore)return null;try{const o=p(this.firestore,s,e),i=await w(o);if(!i.exists())return null;let r=i.data();return r=F(r),{...h.parse(t,r),id:e}}catch(o){return m(o,{context:{operation:"FirestoreAdapter.get",collection:s,docId:e},severity:"warning"}),null}}async set(s,e,t,o){if(!(!this.ensureFirestore()||!this.firestore))try{h.parse(o,t);const i=p(this.firestore,s,e),r=g(t);await v(i,r)}catch(i){throw i}}async update(s,e,t){if(!(!this.ensureFirestore()||!this.firestore))try{const o=p(this.firestore,s,e),i=g(t);await V(o,i)}catch(o){throw o}}async delete(s,e){if(!(!this.ensureFirestore()||!this.firestore))try{const t=p(this.firestore,s,e);await z(t)}catch(t){throw t}}async add(s,e,t){if(!this.ensureFirestore())return"";try{h.parse(t,e);const o=this.getCollectionRef(s);if(!o)return"";const i=new Date().toISOString(),r=C().getCurrentUser()?.uid||"anonymous",n={...e,createdAt:i,updatedAt:i,createdById:r,updatedById:r},a=g(n);return(await M(o,a)).id}catch(o){throw o}}async query(s,e,t,o="list"){if(!this.ensureFirestore())return{items:[]};const i=this.getCollectionRef(s);if(!i)return{items:[]};try{const r=[];if(e.where)for(const c of e.where)r.push(D(c.field,c.operator,c.value));if(e.orderBy)for(const c of e.orderBy)r.push(R(c.field,c.direction||"asc"));if(e.startAfterId){const c=await w(p(i,e.startAfterId));c.exists()&&r.push(S(c))}const n=e.limit?e.limit+1:void 0;n&&r.push(I(n));const a=A(i,...r),d=await E(a),f=[];let l=null;d.forEach(c=>{try{let u=c.data();if(!u)return;u=F(u);const x=h.parse(t,u);f.push({...x,id:c.id}),l=c.id}catch(u){m(u,{context:{operation:"FirestoreAdapter.query.parse",docId:c.id,collection:s},showNotification:!1})}});const y=n?f.length>(e.limit||0):!1;return{items:y?f.slice(0,e.limit):f,hasMore:y,lastVisible:l,total:void 0}}catch(r){throw m(r,{context:{operation:"FirestoreAdapter.query",collection:s,options:e}}),r}}subscribe(s,e,t,o){if(!this.ensureFirestore()||!this.firestore)return()=>{};const i=p(this.firestore,s,e);return q(i,r=>{try{if(!r.exists()){t(null);return}let n=r.data();n=F(n);const a=h.parse(o,n);t({...a,id:e})}catch(n){t(null,n)}},r=>{t(null,r)})}subscribeToCollection(s,e,t,o){if(!this.ensureFirestore())return()=>{};const i=this.getCollectionRef(s);if(!i)return()=>{};try{const r=[];if(e.where)for(const a of e.where)r.push(D(a.field,a.operator,a.value));if(e.orderBy)for(const a of e.orderBy)r.push(R(a.field,a.direction||"asc"));e.limit&&r.push(I(e.limit));const n=A(i,...r);return q(n,a=>{try{const d=[];a.forEach(f=>{let l=f.data();l=F(l);const y=h.parse(o,l);d.push({...y,id:f.id})}),t(d)}catch(d){t([],d)}},a=>{t([],a)})}catch(r){return t([],r),()=>{}}}}export{W as FirestoreAdapter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{httpsCallable as
|
|
1
|
+
import{httpsCallable as c}from"firebase/functions";import*as u from"valibot";import{getPlatformEnvVar as d}from"@donotdev/core";import{getFirebaseFunctions as f}from"@donotdev/firebase";class y{functions;region;constructor(){this.region=d("FIREBASE_FUNCTIONS_REGION")||"europe-west1"}async ensureFunctions(){if(this.functions)return!0;try{return this.functions=await f(this.region),!0}catch{return!1}}async get(e,t,s){if(!await this.ensureFunctions())return null;try{const r=`get_${e}`;return(await c(this.functions,r)({id:t})).data}catch(r){throw r}}async set(e,t,s,r){if(await this.ensureFunctions())try{u.parse(r,s);const a=`update_${e}`;await c(this.functions,a)({id:t,payload:s})}catch(a){throw a}}async update(e,t,s){if(await this.ensureFunctions())try{const r=`update_${e}`;await c(this.functions,r)({id:t,payload:s})}catch(r){throw r}}async delete(e,t){if(await this.ensureFunctions())try{const s=`delete_${e}`;await c(this.functions,s)({id:t})}catch(s){throw s}}async add(e,t,s){if(!await this.ensureFunctions())return"";try{u.parse(s,t);const r=`create_${e}`;return(await c(this.functions,r)({payload:t})).data.id}catch(r){throw r}}async query(e,t,s,r="list"){if(!await this.ensureFunctions())return{items:[]};try{const a=r==="listCard"?`listCard_${e}`:`list_${e}`,i={};t.where&&(i.where=t.where.map(o=>[o.field,o.operator,o.value])),t.orderBy&&(i.orderBy=t.orderBy.map(o=>[o.field,o.direction||"asc"])),t.limit&&(i.limit=t.limit),t.startAfterId&&(i.startAfterId=t.startAfterId);const n=await c(this.functions,a)(i);return{items:n.data.items,total:n.data.count,hasMore:n.data.hasMore,lastVisible:n.data.lastVisible}}catch(a){throw a}}async listCard(e,t,s){if(!await this.ensureFunctions())return[];try{const r=`listCard_${e}`,a={};return t.where&&(a.where=t.where.map(n=>[n.field,n.operator,n.value])),t.orderBy&&(a.orderBy=t.orderBy.map(n=>[n.field,n.direction||"asc"])),t.limit&&(a.limit=t.limit),(await c(this.functions,r)(a)).data.items}catch(r){throw r}}subscribe(){throw new Error("Subscriptions are not supported with Functions backend. Use Firestore backend for real-time features.")}subscribeToCollection(){throw new Error("Subscriptions are not supported with Functions backend. Use Firestore backend for real-time features.")}}export{y as FunctionsAdapter};
|
package/dist/adapters/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./FirestoreAdapter";import{FunctionsAdapter as
|
|
1
|
+
export*from"./FirestoreAdapter";import{FunctionsAdapter as e}from"./FunctionsAdapter";export{e as FunctionsAdapter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as n}from"react/jsx-runtime";import{ActionButton as d}from"@donotdev/components";import{useCrudStore as l}from"../CrudStore";function a({requiresAuth:t=!0,user:e,disabled:r=!1,children:i,...o}){const s=l(u=>!!u.crudService);return n(d,{...o,disabled:r||!s||t&&!e,children:i})}var p=a;export{p as default};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type DateFilterValue = {
|
|
2
|
+
min?: string;
|
|
3
|
+
max?: string;
|
|
4
|
+
};
|
|
5
|
+
export interface DateFilterProps {
|
|
6
|
+
/** Field label */
|
|
7
|
+
label: string;
|
|
8
|
+
/** Field type */
|
|
9
|
+
fieldType: 'date' | 'week' | 'month' | 'year';
|
|
10
|
+
/** Current filter value (range format: { min?: string; max?: string }) */
|
|
11
|
+
value?: DateFilterValue;
|
|
12
|
+
/** Callback when filter value changes */
|
|
13
|
+
onChange: (value: DateFilterValue | undefined) => void;
|
|
14
|
+
/** Translation function for CRUD namespace */
|
|
15
|
+
tCrud: (key: string, opts?: {
|
|
16
|
+
defaultValue?: string;
|
|
17
|
+
}) => string;
|
|
18
|
+
/** Current locale for date formatting */
|
|
19
|
+
locale?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* DateFilter - Simple date filter component
|
|
23
|
+
* Uses open-ended From/To range which covers all use cases:
|
|
24
|
+
* - From only: set min, leave max empty
|
|
25
|
+
* - To only: set max, leave min empty
|
|
26
|
+
* - Between: set both min and max
|
|
27
|
+
* - Exact: set min = max (same date)
|
|
28
|
+
*/
|
|
29
|
+
export declare function DateFilter({ label, fieldType, value, onChange, tCrud, locale, }: DateFilterProps): import("react/jsx-runtime").JSX.Element;
|
|
30
|
+
//# sourceMappingURL=DateFilter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DateFilter.d.ts","sourceRoot":"","sources":["../../src/components/DateFilter.tsx"],"names":[],"mappings":"AA2BA,MAAM,MAAM,eAAe,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7D,MAAM,WAAW,eAAe;IAC9B,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB;IACjB,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;IAC9C,0EAA0E;IAC1E,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,yCAAyC;IACzC,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,GAAG,SAAS,KAAK,IAAI,CAAC;IACvD,8CAA8C;IAC9C,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC;IACjE,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,SAAS,EACT,KAAK,EACL,QAAQ,EACR,KAAK,EACL,MAAa,GACd,EAAE,eAAe,2CAkQjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import{jsx as a,jsxs as k,Fragment as Dt}from"react/jsx-runtime";import{useState as T,useMemo as yt}from"react";import{X as ht}from"lucide-react";import{Button as S,Calendar as St,FloatingLabel as ut,Sheet as E,Text as pt}from"@donotdev/components";import{formatDate as ft}from"@donotdev/core";function vt({label:u,fieldType:xt,value:s,onChange:p,tCrud:o,locale:_="en"}){const[w,l]=T(!1),[F,f]=T(null),b=yt(()=>s?typeof s=="object"&&s!==null&&"min"in s?{min:s.min||"",max:s.max||""}:{min:"",max:""}:{min:"",max:""},[s]),v=t=>{if(!t)return"";try{const n=new Date(t+"T00:00:00");return ft(n,_)}catch{return t}},C=()=>{const t=new Date;t.setHours(0,0,0,0);const n=t.getFullYear(),c=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0"),g=`${n}-${c}-${r}`,i=new Date(t);i.setDate(i.getDate()-1);const M=i.getFullYear(),x=String(i.getMonth()+1).padStart(2,"0"),z=String(i.getDate()).padStart(2,"0"),A=`${M}-${x}-${z}`,d=new Date(t);d.setDate(d.getDate()+1);const B=d.getFullYear(),H=String(d.getMonth()+1).padStart(2,"0"),I=String(d.getDate()).padStart(2,"0"),L=`${B}-${H}-${I}`,m=new Date(t);m.setDate(m.getDate()-7);const O=m.getFullYear(),P=String(m.getMonth()+1).padStart(2,"0"),W=String(m.getDate()).padStart(2,"0"),X=`${O}-${P}-${W}`,D=new Date(t);D.setDate(D.getDate()-30);const q=D.getFullYear(),G=String(D.getMonth()+1).padStart(2,"0"),J=String(D.getDate()).padStart(2,"0"),K=`${q}-${G}-${J}`,y=new Date(t);y.setDate(y.getDate()+7);const Q=y.getFullYear(),U=String(y.getMonth()+1).padStart(2,"0"),Z=String(y.getDate()).padStart(2,"0"),tt=`${Q}-${U}-${Z}`,h=new Date(t);h.setDate(h.getDate()+30);const et=h.getFullYear(),at=String(h.getMonth()+1).padStart(2,"0"),nt=String(h.getDate()).padStart(2,"0"),rt=`${et}-${at}-${nt}`,$=new Date(t.getFullYear(),t.getMonth(),1),st=$.getFullYear(),ot=String($.getMonth()+1).padStart(2,"0"),lt=String($.getDate()).padStart(2,"0"),it=`${st}-${ot}-${lt}`,Y=new Date(t.getFullYear(),t.getMonth()+1,0),ct=Y.getFullYear(),gt=String(Y.getMonth()+1).padStart(2,"0"),dt=String(Y.getDate()).padStart(2,"0"),mt=`${ct}-${gt}-${dt}`;return{today:g,yesterday:A,tomorrow:L,last7Days:X,last30Days:K,next7Days:tt,next30Days:rt,thisMonthStart:it,thisMonthEnd:mt}},e=b,N=C(),R=!!(e?.min||e?.max),V=t=>{const n=t==="start",c=n?e?.min:e?.max;return a("div",{style:{padding:"var(--gap-md)"},children:k("div",{style:{display:"flex",flexDirection:"column",gap:"var(--gap-md)"},children:[a("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 g=N[r];return a(S,{variant:"outline",onClick:()=>{p({min:n?g:e?.min||"",max:n?e?.max||"":g}),l(!1)},children:o(`filter.${r}`,{defaultValue:r})},r)})}),a(St,{selected:c?new Date(c+"T00:00:00"):void 0,mode:"single",onSelect:r=>{if(!r)return;const g=r.getFullYear(),i=String(r.getMonth()+1).padStart(2,"0"),M=String(r.getDate()).padStart(2,"0"),x=`${g}-${i}-${M}`;p({min:n?x:e?.min||"",max:n?e?.max||"":x}),l(!1)},defaultMonth:c?new Date(c+"T00:00:00"):new Date}),a(S,{variant:"ghost",display:"compact",onClick:()=>{p({min:n?"":e?.min||"",max:n&&e?.max||""}),l(!1)},children:o("filter.clear",{defaultValue:"Clear"})})]})})},j=k(Dt,{children:[a(E,{trigger:a(S,{variant:"outline",onClick:()=>{f("start"),l(!0)},style:{flex:1},children:e?.min?v(e.min):o("filter.min",{defaultValue:"Min"})}),title:`${u} - ${o("filter.min",{defaultValue:"Min"})}`,open:w&&F==="start",onOpenChange:t=>{l(t),t||f(null)},children:V("start")}),a(pt,{level:"small",variant:"muted",style:{display:"flex",alignItems:"center"},children:"\u2013"}),a(E,{trigger:a(S,{variant:"outline",onClick:()=>{f("end"),l(!0)},style:{flex:1},children:e?.max?v(e.max):o("filter.max",{defaultValue:"Max"})}),title:`${u} - ${o("filter.max",{defaultValue:"Max"})}`,open:w&&F==="end",onOpenChange:t=>{l(t),t||f(null)},children:V("end")}),a(S,{variant:"ghost",display:"compact",icon:a(ht,{size:16}),onClick:()=>{p(void 0)},disabled:!R,"aria-label":o("filter.clear",{defaultValue:"Clear"})})]});return u?a(ut,{label:u,className:"dndev-range-input",children:j}):a("div",{className:"dndev-range-input",children:j})}export{vt as DateFilter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as t,jsxs as s}from"react/jsx-runtime";import{Text as a,Stack as p}from"@donotdev/components";import{handleError as d}from"@donotdev/core";import{translateFieldLabel as f}from"../forms/utils";import{getDisplayFormatter as y}from"../fieldTypeRegistry";function c(r,e,o,n){const i=n?.compact??!1;if(r==null||r==="")return i?t("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):t(a,{variant:"muted",children:"\u2014"});const l=y(e.type);if(l)try{return l(r,e,o,n)}catch(m){return d(m,{userMessage:`Error formatting field "${e.label||e.name}"`,context:{fieldType:e.type,fieldName:e.label||"unknown",operation:"display_format"},severity:"warning"}),i?t("span",{style:{color:"var(--muted-foreground)"},children:String(r)}):t(a,{variant:"muted",children:String(r)})}return d(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"}),i?t("span",{style:{color:"var(--muted-foreground)"},children:String(r)}):t(a,{variant:"muted",children:String(r)})}function u({name:r,config:e,value:o,t:n}){const i=c(o,e,n,{compact:!1}),l=f(r,e,n);return s(p,{direction:"row",align:"baseline",style:{marginBottom:"var(--gap-sm)",padding:"var(--gap-sm)",minHeight:"38px",alignItems:"center"},children:[s(a,{variant:"muted",style:{fontSize:"var(--font-size-sm)",fontWeight:500,minWidth:"fit-content",flexShrink:0},children:[l,":"]}),t("div",{style:{flex:1,display:"flex",alignItems:"center"},children:typeof i=="string"?t(a,{children:i}):i})]})}var b=u;export{u as DisplayFieldRenderer,b as default,c as formatValue};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as n,jsxs as O}from"react/jsx-runtime";import{useEffect as _,useState as m,useMemo as I}from"react";import{Stack as p,Spinner as M}from"@donotdev/components";import{useTranslation as v,isFieldVisible as R}from"@donotdev/core";import{DisplayFieldRenderer as T}from"./DisplayFieldRenderer";import{useCrud as $}from"../useCrud";function q({entity:s,id:a,t:E,className:f="",backend:b="functions",loadingMessage:j,notFoundMessage:x,viewerRole:g="guest"}){const{get:d,loading:F,data:A,error:S,isAvailable:y}=$(s,{backend:b}),[D,u]=m(!1),[V,i]=m(null),[k,c]=m(null),{t:w}=v([s.namespace,"crud"]),{t:h}=v("crud"),z=E||w;_(()=>{if(!a){c(null),i(null),u(!1);return}if(!y||!d)return;let t=!1;return u(!0),i(null),d(a).then(r=>{t||(u(!1),r?(c(r),i(null)):(c(null),i(new Error("Entity not found"))))}).catch(r=>{t||(u(!1),i(r instanceof Error?r:new Error(String(r))),c(null))}),()=>{t=!0}},[a,d,y]);const l=A||k,o=S||V,C=F||D||!a,L=I(()=>l?Object.entries(s.fields).filter(([t,r])=>{if(!R(r.visibility,g)||r.visibility==="hidden")return!1;const e=l[t];return!(e==null||typeof e=="string"&&e.trim()===""||Array.isArray(e)&&e.length===0||typeof e=="object"&&!Array.isArray(e)&&e!==null&&Object.keys(e).length===0)}):[],[s.fields,g,l]);return C?n("div",{style:{position:"relative",width:"100%",gridColumn:"1 / -1",display:"contents"},className:f,children:n(M,{overlay:!0,"aria-label":j||h("form.loading",{defaultValue:"Loading..."})})}):o||!l?n(p,{align:"center",justify:"center",style:{padding:"var(--gap-3xl)",textAlign:"center"},className:f,children:O(p,{direction:"column",gap:"tight",children:[n("h3",{style:{color:"var(--muted-foreground)"},children:x||h("errors.notFound",{defaultValue:`${s.name} not found`})}),o&&n("p",{style:{color:"var(--destructive)",fontSize:"var(--font-size-sm)"},children:o instanceof Error?o.message:String(o)})]})}):n(p,{direction:"column",className:f,children:L.map(([t,r])=>n(T,{name:t,config:r,value:l[t],t:z},t))})}var Q=q;export{q as EntityDisplayRenderer,Q as default};
|
|
@@ -17,26 +17,35 @@ import type { Entity } from '@donotdev/core';
|
|
|
17
17
|
export declare function matchesFilter(itemValue: any, filterValue: string | {
|
|
18
18
|
min?: string;
|
|
19
19
|
max?: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
20
|
+
} | string[] | {
|
|
21
|
+
date: string;
|
|
22
|
+
time?: string;
|
|
23
|
+
} | {
|
|
24
|
+
min?: {
|
|
25
|
+
date: string;
|
|
26
|
+
time?: string;
|
|
27
|
+
};
|
|
28
|
+
max?: {
|
|
29
|
+
date: string;
|
|
30
|
+
time?: string;
|
|
31
|
+
};
|
|
32
|
+
} | {
|
|
33
|
+
date: string;
|
|
34
|
+
time?: string;
|
|
35
|
+
}[], fieldType: string): boolean;
|
|
36
|
+
export interface EntityFiltersProps<T extends Record<string, any> & {
|
|
37
|
+
id: string;
|
|
38
|
+
} = Record<string, any> & {
|
|
39
|
+
id: string;
|
|
40
|
+
}> {
|
|
22
41
|
/** The entity definition */
|
|
23
42
|
entity: Entity;
|
|
24
|
-
/** Data array to extract unique values and min/max from */
|
|
25
|
-
data: T[];
|
|
26
|
-
/** Current filter values */
|
|
27
|
-
filters: Record<string, string | {
|
|
28
|
-
min?: string;
|
|
29
|
-
max?: string;
|
|
30
|
-
}>;
|
|
31
|
-
/** Callback when filters change */
|
|
32
|
-
onFiltersChange: (filters: Record<string, string | {
|
|
33
|
-
min?: string;
|
|
34
|
-
max?: string;
|
|
35
|
-
}>) => void;
|
|
36
43
|
/** Optional: Specific fields to show filters for (defaults to all entity fields) */
|
|
37
44
|
fieldsToFilter?: string[];
|
|
38
45
|
/** Layout variant: 'inline' (multi-column grid) or 'sidebar' (single column stack) */
|
|
39
46
|
variant?: 'inline' | 'sidebar';
|
|
47
|
+
/** Optional: Data array to extract unique values and min/max from (if not provided, fetches automatically) */
|
|
48
|
+
data?: T[];
|
|
40
49
|
}
|
|
41
50
|
/**
|
|
42
51
|
|
|
@@ -57,5 +66,9 @@ export interface EntityFiltersProps<T = any> {
|
|
|
57
66
|
* - Clear individual filters or all filters
|
|
58
67
|
|
|
59
68
|
*/
|
|
60
|
-
export declare function EntityFilters<T extends Record<string, any>
|
|
69
|
+
export declare function EntityFilters<T extends Record<string, any> & {
|
|
70
|
+
id: string;
|
|
71
|
+
} = Record<string, any> & {
|
|
72
|
+
id: string;
|
|
73
|
+
}>({ entity, data: dataProp, fieldsToFilter, variant, }: EntityFiltersProps<T>): import("react/jsx-runtime").JSX.Element | null;
|
|
61
74
|
//# sourceMappingURL=EntityFilters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityFilters.d.ts","sourceRoot":"","sources":["../../src/components/EntityFilters.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EntityFilters.d.ts","sourceRoot":"","sources":["../../src/components/EntityFilters.tsx"],"names":[],"mappings":"AAyDA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAS7C;;;;;;;;;;;;;;GAcG;AAEH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,GAAG,EAEd,WAAW,EAAE,MAAM,GAAG;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,EAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,GAAG,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,GAAG,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,EAExN,SAAS,EAAE,MAAM,GAChB,OAAO,CAgUT;AAGD,MAAM,WAAW,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE;IACvH,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAC;IAEf,oFAAoF;IACpF,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAE1B,sFAAsF;IACtF,OAAO,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAE/B,8GAA8G;IAC9G,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;CACZ;AAED;;;;;;;;;;;;;;;;;;GAkBG;AAEH,wBAAgB,aAAa,CAC3B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EACrF,EACA,MAAM,EACN,IAAI,EAAE,QAAQ,EACd,cAAc,EACd,OAAkB,GACnB,EAAE,kBAAkB,CAAC,CAAC,CAAC,kDAknBvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as A,jsxs as K}from"react/jsx-runtime";import{useMemo as G}from"react";import{FilterX as Z}from"lucide-react";import{Button as v,Combobox as V,Grid as tt,RangeInput as nt,Slider as et,Stack as rt}from"@donotdev/components";import{DateFilter as it}from"./DateFilter";import{useTranslation as Q,handleError as X}from"@donotdev/core";import{translateFieldLabel as st,translateLabel as U}from"../forms/utils";import{getFilterType as I,isFilterable as ot}from"../fieldTypeRegistry";import{useCrudFilters as at}from"../hooks/useCrudFilters";import{useCrudCardList as ct}from"../useCrudCardList";function lt(t,s,a){if(!s)return!0;if(Array.isArray(s)){if(s.length===0)return!0;if(!(I(a)==="range"&&(a==="date"||a==="datetime-local"||a==="timestamp")))return s.some(l=>{if(typeof l=="object"&&"date"in l){const h=l.date;return(t instanceof Date?t.toISOString().split("T")[0]:new Date(t).toISOString().split("T")[0])===h}return String(t)===String(l)});const F=t instanceof Date?t.toISOString().split("T")[0]:new Date(t).toISOString().split("T")[0];return s.some(l=>typeof l=="string"?F===l:typeof l=="object"&&"date"in l?F===l.date:!1)}if(typeof s=="object"&&"date"in s&&!("min"in s)&&!Array.isArray(s)){if(!(I(a)==="range"&&(a==="date"||a==="datetime-local"||a==="timestamp")))return!1;const F=s.date;if(!F)return!0;if(t==null)return!1;const l=t instanceof Date?t.toISOString().split("T")[0]:new Date(t).toISOString().split("T")[0];if((a==="datetime-local"||a==="timestamp")&&s.time){const h=t instanceof Date?t.toISOString().slice(11,16):new Date(t).toISOString().slice(11,16);return l===F&&h===s.time}return l===F}if(typeof s=="object"&&"min"in s){const T=I(a);if(!T)throw X(new Error(`Field type "${a}" not registered in field type registry`),{userMessage:`Field type "${a}" is missing from registry`,context:{fieldType:a,operation:"filter_matching",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"}});const b=T==="range"&&(a==="date"||a==="datetime-local"||a==="timestamp"),F=T==="range"&&!b,l=a==="price",h=l&&t!=null&&typeof t=="object"?Number(t.amount):F&&t!=null?typeof t=="number"?t:Number(t):NaN;if(F||l){if(typeof s.min=="object"&&s.min!==null&&"date"in s.min)return!1;const d=s,m=typeof d.min=="string"&&d.min!=="",x=typeof d.max=="string"&&d.max!=="";return m&&!x?t==null||isNaN(h)?!1:h>=Number(d.min):!m&&x?t==null?!0:isNaN(h)?!1:h<=Number(d.max):m&&x?t==null||isNaN(h)?!1:h>=Number(d.min)&&h<=Number(d.max):!0}if(b){if(typeof s.min=="object"&&s.min!==null&&"date"in s.min&&!("min"in s.min)){const p=s,g=p.min,y=p.max,L=g?.date&&g.date!=="",C=y?.date&&y.date!=="";if(L&&!C){if(t==null)return!1;const w=t instanceof Date?t:new Date(t);if(isNaN(w.getTime()))return!1;const M=new Date(g.date+(g.time?`T${g.time}:00`:"T00:00:00"));return w>=M}if(!L&&C&&y){if(t==null)return!0;const w=t instanceof Date?t:new Date(t);if(isNaN(w.getTime()))return!1;const M=new Date(y.date+(y.time?`T${y.time}:00`:"T23:59:59"));return w<=M}if(L&&C&&y){if(t==null)return!1;const w=t instanceof Date?t:new Date(t);if(isNaN(w.getTime()))return!1;const M=new Date(g.date+(g.time?`T${g.time}:00`:"T00:00:00")),q=new Date(y.date+(y.time?`T${y.time}:00`:"T23:59:59"));return w>=M&&w<=q}return!0}const d=s,m=typeof d.min=="string"&&d.min!=="",x=typeof d.max=="string"&&d.max!=="";if(m&&!x){if(t==null)return!1;const p=t instanceof Date?t:new Date(t);return isNaN(p.getTime())?!1:p>=new Date(d.min)}if(!m&&x){if(t==null)return!0;const p=t instanceof Date?t:new Date(t);return isNaN(p.getTime())?!1:p<=new Date(d.max)}if(m&&x){if(t==null)return!1;const p=t instanceof Date?t:new Date(t);return isNaN(p.getTime())?!1:p>=new Date(d.min)&&p<=new Date(d.max)}return!0}}const $=I(a);if(!$)throw X(new Error(`Field type "${a}" not registered in field type registry`),{userMessage:`Field type "${a}" is missing from registry`,context:{fieldType:a,operation:"filter_matching",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"}});if($==="address")return t==null?!1:typeof t=="object"&&"formatted_address"in t?String(t.formatted_address).toLowerCase().includes(String(s).toLowerCase()):!1;if($==="multiselect"){if(!Array.isArray(t)||t.length===0)return!1;const T=String(s).toLowerCase();return t.some(b=>String(b).toLowerCase().includes(T))}return t==null?!1:String(t).toLowerCase().includes(String(s).toLowerCase())}function Mt({entity:t,data:s,fieldsToFilter:a,variant:$="inline"}){const T=$==="sidebar",{t:b,i18n:F}=Q("crud"),{t:l}=Q([t.namespace,"crud"]),h=F?.language||"en",{data:d}=ct(t,{enabled:!s}),m=s??(d?.items||[]),{filters:x,setFilters:p}=at({collection:t.collection}),g=G(()=>(a&&a.length>0?a:t.listFields||Object.keys(t.fields)).filter(n=>{const e=t.fields[n]?.type||"text";return ot(e)}),[a,t.listFields,t.fields]),y=G(()=>{const i={};return g.forEach(n=>{const f=Object.fromEntries(Object.entries(x).filter(([e])=>e!==n));if(Object.keys(f).length===0){i[n]=m;return}i[n]=m.filter(e=>Object.entries(f).every(([D,E])=>{const N=e[D],c=t.fields[D]?.type||"text";return lt(N,E,c)}))}),i},[m,x,t.fields,g]),L=G(()=>{const i={};return g.forEach(n=>{const f=t.fields[n];if(!f)return;const e=f.type||"text",D=I(e);if(!D){X(new Error(`Field type "${e}" not registered in field type registry`),{userMessage:`Field type "${e}" is missing from registry`,context:{fieldType:e,fieldName:n,operation:"minmax_computation",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"});return}const E=D==="range"&&(e==="date"||e==="datetime-local"||e==="timestamp"||e==="time"||e==="week"||e==="month"||e==="year"),N=D==="range"&&!E,R=e==="price";if(N||R){const c=m.map(o=>o[n]).filter(o=>o!=null&&o!=="").map(o=>R&&typeof o=="object"&&o!==null?Number(o.amount):typeof o=="number"?o:Number(o)).filter(o=>!isNaN(o));c.length>0&&(i[n]={min:Math.min(...c),max:Math.max(...c)})}else if(E){const c=m.map(o=>o[n]).filter(o=>o!=null&&o!=="").map(o=>o instanceof Date?o:new Date(o)).filter(o=>!isNaN(o.getTime()));if(c.length>0){const o=new Date(Math.min(...c.map(_=>_.getTime()))),O=new Date(Math.max(...c.map(_=>_.getTime()))),J=o.toISOString().split("T")[0],B=O.toISOString().split("T")[0];i[n]={min:J||"",max:B||""}}}}),i},[m,t.fields,g]),C=(i,n)=>{const f={...x};if(!n||n==="")delete f[i];else if(Array.isArray(n))f[i]=n;else if(typeof n=="object"&&"min"in n){const e=n.min&&n.min!=="",D=n.max&&n.max!=="";!e&&!D?delete f[i]:f[i]=n}else f[i]=n;p(f)},w=()=>{p({})},M=G(()=>g.length===0?null:g.map(i=>{const n=t.fields[i];if(!n)return null;const f=st(i,n,l),e=n.type||"text",D=I(e);if(!D)return X(new Error(`Field type "${e}" not registered in field type registry`),{userMessage:`Field type "${e}" is missing from registry`,context:{fieldType:e,fieldName:i,operation:"filter_ui_render",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"}),null;const E=D==="range"&&(e==="date"||e==="datetime-local"||e==="timestamp"||e==="time"||e==="week"||e==="month"||e==="year"),N=D==="range"&&!E,R=D==="select",c=x[i],O=typeof c=="object"&&c!==null&&"min"in c?c:{min:"",max:""};if(N){const u=L[i],S=u?.min??0,r=u?.max??100,j=O.min?Number(O.min):S,z=O.max?Number(O.max):r;return K(rt,{gap:"tight",style:{gridColumn:"span 2"},children:[A(nt,{type:"number",label:f,minPlaceholder:b("filter.min",{defaultValue:"Min"}),maxPlaceholder:b("filter.max",{defaultValue:"Max"}),minValue:O.min||"",maxValue:O.max||"",actualMin:S,actualMax:r,onChange:(k,Y)=>{C(i,{min:k,max:Y})},onClear:()=>C(i,void 0)}),A(et,{value:[j,z],min:S,max:r,step:1,onValueChange:k=>{C(i,{min:String(k[0]),max:String(k[1])})}})]},i)}if(E){const u=e==="week"||e==="month"||e==="year"?e:"date",S=(()=>{if(c){if(typeof c=="object"&&"min"in c){const r=c;return{min:r.min&&r.min.split("T")[0]||"",max:r.max&&r.max.split("T")[0]||""}}if(typeof c=="string"){const r=c.split("T")[0]||"";return{min:r,max:r}}}})();return A("div",{style:{gridColumn:"span 2",gridRow:T?void 0:"span 1"},children:A(it,{label:f,fieldType:u,value:S,locale:h,onChange:r=>{if(!r){C(i,void 0);return}typeof r=="object"&&"min"in r&&C(i,{min:r.min||"",max:r.max||""})},tCrud:b})},i)}const B=R&&n.validation&&"options"in n.validation&&n.validation?Array.isArray(n.validation.options)?n.validation.options:typeof n.validation.options=="function"?n.validation.options():[]:[],_=y[i]||m,H=new Set;_.forEach(u=>{const S=u[i];S!=null&&H.add(String(S))});const P=[{value:"all",label:b("filter.selectPlaceholder",{defaultValue:"All"})}];if(B.length>0){const u=[],S=[];B.forEach(r=>{const j=typeof r=="string"?r:r.value,z=typeof r=="string"?r:r.label;H.has(j)?u.push({value:j,label:z}):S.push({value:j,label:z})}),u.sort((r,j)=>r.label.localeCompare(j.label)),S.sort((r,j)=>r.label.localeCompare(j.label)),u.forEach(r=>{P.push({value:r.value,label:U(r.label,l),disabled:!1})}),S.forEach(r=>{P.push({value:r.value,label:U(r.label,l),disabled:!0})})}else Array.from(H).sort().slice(0,100).forEach(u=>{P.push({value:u,label:u})});return A("div",{style:{gridColumn:"span 2",gridRow:"span 1"},children:A(V,{label:f,value:typeof c=="string"?c:void 0,onValueChange:u=>{C(i,u==="all"||!u?"":String(u))},options:P,placeholder:b("filter.placeholder",{defaultValue:"Filter..."}),clearable:!0})},i)}),[g,t.fields,m,x,l,b,y]);if(!M||M.length===0)return null;const q=M.filter(Boolean),W=Object.keys(x).length>0;return K(tt,{cols:$==="sidebar"?2:[2,4,6,8],children:[q,A(v,{variant:"outline",icon:A(Z,{size:18}),onClick:w,disabled:!W,style:{gridColumn:"1 / -1",gridRow:"span 1"},children:b("filter.clear",{defaultValue:"Clear Filters"})})]})}export{Mt as EntityFilters,lt as matchesFilter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as l}from"react/jsx-runtime";import{handleError as h}from"@donotdev/core";import{getFieldRegistry as T}from"../FieldRegistry";import{ControlledTextField as S}from"./controlled";import{TextFieldComponent as g}from"./form/fields";import"../builtinFieldTypes";const x=T();function w({name:r,config:e,t,...o}){const s=n=>d=>{try{n(d)}catch(C){h(C,{userMessage:`Error updating field ${e.label||r}`,context:{fieldName:r,fieldType:e.type},severity:"warning"})}},i="control"in o&&o.control,p=e.type==="submit"||e.type==="reset";if(i&&!p){const{control:n,errors:d}=o,F=e.options?.fieldSpecific?.placeholder,f={control:n,errors:d,fieldConfig:{...e,label:e.label||r},t,placeholder:F,onChange:s(()=>{})},m=x.getControlledComponent(e.type);return m?l(m,{...f}):(h(new Error(`Unregistered field type: ${e.type}`),{userMessage:t("errors.unsupportedFieldType",{type:e.type}),context:{fieldName:r,fieldType:e.type},severity:"warning"}),l(S,{...f,fieldConfig:{...e,type:"text"}}))}const b=i&&p?{name:r,config:e,t,value:void 0,onChange:()=>{},error:void 0}:o,{value:a,onChange:v,error:u}=b,y=s(v),c=x.getUncontrolledComponent(e.type);return c?l(c,{name:r,label:e.label||r,value:a,onChange:y,error:u,t,config:e,...e.options}):l(g,{label:e.label||r,value:a,onChange:y,error:u||void 0,...e.options})}var R=w;export{w as FormFieldRenderer,R as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as e,jsxs as r,Fragment as N}from"react/jsx-runtime";import{useState as j}from"react";import{FormProvider as w}from"react-hook-form";import{Button as s,BUTTON_VARIANT as C,Spinner as F,cn as _,Stack as i,Grid as I}from"@donotdev/components";import{useTranslation as L}from"@donotdev/core";const k=({title:m,onSubmit:c,children:f,formMethods:u,loading:n=!1,submitText:g,cancelText:v,showCancel:p=!1,onCancel:b,variant:l="default",columns:h=1,description:o})=>{const{t:d}=L("dndev"),[t,a]=j(!1),y=g||d("form.submit","Submit"),S=v||d("form.cancel","Cancel"),x=async T=>{a(!0);try{await c(T)}finally{a(!1)}},z={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 e(w,{...u,children:e("form",{onSubmit:x,className:_("dndev-mx-auto",{default:"dndev-surface",card:"dndev-surface",minimal:""}[l]),style:l!=="minimal"?{padding:"var(--gap-lg)"}:void 0,role:"form","aria-labelledby":"form-title",noValidate:!0,children:r(i,{gap:"large",children:[r(i,{gap:"tight",children:[e("h2",{id:"form-title",style:{fontSize:"var(--font-size-2xl)",fontWeight:600,color:"var(--foreground)"},children:m}),o&&e("p",{style:{color:"var(--muted-foreground)"},children:o})]}),e(I,{cols:h,className:"dndev-w-full dndev-min-w-0",children:f}),r(i,{direction:"row",align:"center",justify:"end",style:{paddingTop:"var(--gap-md)",borderTop:"1px solid var(--border)"},children:[p&&e(s,{type:"button",variant:C.OUTLINE,onClick:b,disabled:n||t,children:S}),e(s,{type:"submit",disabled:n||t,style:{minWidth:"120px"},children:n||t?r(N,{children:[e(F,{className:"me-component-gap"}),t?d("form.submitting","Submitting..."):d("form.loading","Loading...")]}):y})]})]})})})};var E=k;export{E as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as l}from"react/jsx-runtime";import{Controller as f}from"react-hook-form";import{AddressFieldComponent as m}from"../../form/fields";import{convertValidationRules as u}from"../types";function h(s){const{control:a,errors:r,fieldConfig:n,t:d}=s,{name:e,label:c,validation:o}=n,t=(n.options||{}).fieldSpecific;return l(f,{name:e,control:a,rules:o?u(o):void 0,render:({field:i})=>l(m,{label:d(c),value:i.value??void 0,onChange:p=>i.onChange(p),error:!!r[e],helperText:r[e]?.message,required:o?.required,enableGoogleMaps:t?.enableGoogleMaps,extractDistrictCode:t?.extractDistrictCode})})}export{h as ControlledAddressField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as n}from"react/jsx-runtime";import{Controller as p}from"react-hook-form";import{DateFieldComponent as f}from"../../form/fields";import{convertValidationRules as C}from"../types";function j(a){const{control:l,errors:r,fieldConfig:m,t:i}=a,{name:e,label:d,validation:o,type:s}=m,c={date:"date","datetime-local":"datetime-local",month:"month",time:"time",week:"week"}[s]||"date";return n(p,{name:e,control:l,rules:o?C(o):void 0,render:({field:t})=>n(f,{...t,label:i(d),value:t.value??null,onChange:u=>t.onChange(u),error:!!r[e],helperText:r[e]?.message,required:o?.required,mode:c})})}export{j as ControlledDateField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as a}from"react/jsx-runtime";import{Controller as u}from"react-hook-form";import{GeoPointFieldComponent as p}from"../../form/fields";import{convertValidationRules as C}from"../types";function b(l){const{control:i,errors:t,fieldConfig:s,t:g}=l,{name:n,label:m,validation:o}=s;return a(u,{name:n,control:i,rules:o?C(o):void 0,render:({field:e})=>{const c=r=>{if("target"in r)try{const d=JSON.parse(r.target.value);e.onChange(d)}catch{e.onChange({lat:0,lng:0})}else e.onChange(r||{lat:0,lng:0})};return a(p,{label:g(m),value:e.value||{lat:0,lng:0},onChange:c,error:!!t[n],helperText:t[n]?.message,required:o?.required})}})}export{b as ControlledGeoPointField};
|
|
@@ -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 u}from"react-hook-form";import{MapFieldComponent as g}from"../../form/fields";import{convertValidationRules as C}from"../types";function b(l){const{control:i,errors:t,fieldConfig:s,t:m}=l,{name:r,label:c,validation:n}=s;return a(u,{name:r,control:i,rules:n?C(n):void 0,render:({field:e})=>{const p=o=>{if("target"in o)try{const d=JSON.parse(o.target.value);e.onChange(d)}catch{e.onChange({})}else e.onChange(o||{})};return a(g,{label:m(c),value:e.value||{},onChange:p,error:!!t[r],helperText:t[r]?.message,required:n?.required})}})}export{b as ControlledMapField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as t}from"react/jsx-runtime";import{Controller as
|
|
1
|
+
"use client";import{jsx as t}from"react/jsx-runtime";import{Controller as d}from"react-hook-form";import{MultiInputTextFieldComponent as C}from"../../form/fields";import{convertValidationRules as g}from"../types";function x(a){const{control:l,errors:h,fieldConfig:s,t:i}=a,{name:u,label:c,validation:e,options:m={}}=s;return t(d,{name:u,control:l,rules:e?g(e):void 0,render:({field:r})=>{const p=n=>{if(Array.isArray(n))r.onChange(n);else try{const o=JSON.parse(n.target.value);r.onChange(Array.isArray(o)?o:[])}catch{r.onChange([])}};return t(C,{label:i(c),value:Array.isArray(r.value)?r.value:[],onChange:p,required:e?.required,className:m.className})}})}export{x as ControlledMultiInputField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as t}from"react/jsx-runtime";import{Controller as u}from"react-hook-form";import{RichTextComponent as
|
|
1
|
+
"use client";import{jsx as t}from"react/jsx-runtime";import{Controller as u}from"react-hook-form";import{RichTextComponent as h}from"../../form/fields";import{convertValidationRules as f}from"../types";function R(a){const{control:i,errors:r,fieldConfig:s,t:m,placeholder:c}=a,{name:e,label:d,validation:o,options:l={}}=s;return t(u,{name:e,control:i,rules:o?f(o):void 0,render:({field:n})=>t(h,{label:m(d),value:n.value??"",onChange:p=>n.onChange(p),error:r[e]?.message,helperText:r[e]?.message,required:o?.required,placeholder:c||l.placeholder,className:l.className})})}export{R as ControlledRichTextField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as t}from"react/jsx-runtime";import{Controller as d}from"react-hook-form";import{TimestampFieldComponent as p}from"../../form/fields";import{convertValidationRules as c}from"../types";function x(l){const{control:i,errors:n,fieldConfig:a,t:m}=l,{name:e,label:s,validation:r}=a;return t(d,{name:e,control:i,rules:r?c(r):void 0,render:({field:o})=>t(p,{...o,label:m(s),value:o.value??null,onChange:u=>o.onChange(u),error:!!n[e],helperText:n[e]?.message,required:r?.required})})}export{x as ControlledTimestampField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ControlledAddressField as
|
|
1
|
+
import{ControlledAddressField as l}from"./ControlledAddressField";import{ControlledDateField as t}from"./ControlledDateField";import{ControlledGeoPointField as i}from"./ControlledGeoPointField";import{ControlledMapField as m}from"./ControlledMapField";import{ControlledMultiInputField as x}from"./ControlledMultiInputField";import{ControlledRichTextField as C}from"./ControlledRichTextField";import{ControlledTimestampField as a}from"./ControlledTimestampField";export{l as ControlledAddressField,t as ControlledDateField,i as ControlledGeoPointField,m as ControlledMapField,x as ControlledMultiInputField,C as ControlledRichTextField,a as ControlledTimestampField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as a}from"react/jsx-runtime";import{Controller as d}from"react-hook-form";import{DocumentFieldComponent as p}from"../../form/fields";import{convertValidationRules as f}from"../types";function v(i){const{control:m,errors:r,fieldConfig:n,t:s}=i,{name:e,label:u,validation:o}=n,t=n.options||{};return a(d,{name:e,control:m,rules:o?f(o):void 0,render:({field:l})=>a(p,{name:e,label:s(u),value:l.value??null,onChange:c=>l.onChange(c),error:!!r[e],helperText:r[e]?.message,required:o?.required,multiple:!1,maxFiles:1,maxSize:t.maxSize,storagePath:t.storagePath})})}export{v as ControlledDocumentField};
|
|
@@ -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{FileFieldComponent as c}from"../../form/fields";import{convertValidationRules as f}from"../types";function F(a){const{control:s,errors:r,fieldConfig:n,t:m}=a,{name:e,label:u,validation:o}=n,l=n.options||{};return i(p,{name:e,control:s,rules:o?f(o):void 0,render:({field:t})=>i(c,{name:e,label:m(u),value:t.value??null,onChange:d=>t.onChange(d),error:!!r[e],helperText:r[e]?.message,required:o?.required,multiple:!1,maxFiles:1,maxSize:l.maxSize,storagePath:l.storagePath})})}export{F as ControlledFileField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as a}from"react/jsx-runtime";import{Controller as p}from"react-hook-form";import{ImageFieldComponent as c}from"../../form/fields";import{convertValidationRules as f}from"../types";function v(i){const{control:m,errors:r,fieldConfig:n,t:s}=i,{name:e,label:u,validation:o}=n,t=n.options||{};return a(p,{name:e,control:m,rules:o?f(o):void 0,render:({field:l})=>a(c,{name:e,label:s(u),value:l.value??null,onChange:d=>l.onChange(d),error:!!r[e],helperText:r[e]?.message,required:o?.required,multiple:!1,maxFiles:1,maxSize:t.maxSize,storagePath:t.storagePath})})}export{v as ControlledImageField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as l}from"react/jsx-runtime";import{Controller as x}from"react-hook-form";import{DocumentFieldComponent as d}from"../../form/fields";import{convertValidationRules as v}from"../types";function F(i){const{control:u,errors:t,fieldConfig:a,t:m}=i,{name:r,label:s,validation:o}=a,n=a.options||{};return l(x,{name:r,control:u,rules:o?v(o):void 0,render:({field:e})=>{const c=Array.isArray(e.value)?e.value:e.value?[e.value]:null;return l(d,{name:r,label:m(s),value:c,onChange:p=>e.onChange(p),error:!!t[r],helperText:t[r]?.message,required:o?.required,multiple:!0,maxFiles:n.maxFiles??10,maxSize:n.maxSize,storagePath:n.storagePath})}})}export{F as ControlledMultiDocumentField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as l}from"react/jsx-runtime";import{Controller as x}from"react-hook-form";import{FileFieldComponent as d}from"../../form/fields";import{convertValidationRules as v}from"../types";function f(i){const{control:s,errors:t,fieldConfig:a,t:u}=i,{name:r,label:m,validation:o}=a,n=a.options||{};return l(x,{name:r,control:s,rules:o?v(o):void 0,render:({field:e})=>{const p=Array.isArray(e.value)?e.value:e.value?[e.value]:null;return l(d,{name:r,label:u(m),value:p,onChange:c=>e.onChange(c),error:!!t[r],helperText:t[r]?.message,required:o?.required,multiple:!0,maxFiles:n.maxFiles??10,maxSize:n.maxSize,storagePath:n.storagePath})}})}export{f as ControlledMultiFileField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as l}from"react/jsx-runtime";import{Controller as g}from"react-hook-form";import{ImageFieldComponent as x}from"../../form/fields";import{convertValidationRules as d}from"../types";function F(i){const{control:m,errors:n,fieldConfig:t,t:s}=i,{name:r,label:u,validation:o}=t,a=t.options||{};return l(g,{name:r,control:m,rules:o?d(o):void 0,render:({field:e})=>{const p=Array.isArray(e.value)?e.value:e.value?[e.value]:null;return l(x,{name:r,label:s(u),value:p,onChange:c=>e.onChange(c),error:!!n[r],helperText:n[r]?.message,required:o?.required,multiple:!0,maxFiles:a.maxFiles??10,maxSize:a.maxSize,storagePath:a.storagePath})}})}export{F as ControlledMultiImageField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ControlledDocumentField as l}from"./ControlledDocumentField";import{ControlledFileField as
|
|
1
|
+
import{ControlledDocumentField as l}from"./ControlledDocumentField";import{ControlledFileField as t}from"./ControlledFileField";import{ControlledImageField as i}from"./ControlledImageField";import{ControlledMultiDocumentField as n}from"./ControlledMultiDocumentField";import{ControlledMultiFileField as f}from"./ControlledMultiFileField";import{ControlledMultiImageField as x}from"./ControlledMultiImageField";export{l as ControlledDocumentField,t as ControlledFileField,i as ControlledImageField,n as ControlledMultiDocumentField,f as ControlledMultiFileField,x as ControlledMultiImageField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{convertValidationRules as
|
|
1
|
+
import{convertValidationRules as e,convertPatternToRegex as t}from"./types";export*from"./input";export*from"./select";export*from"./file";export*from"./complex";export{t as convertPatternToRegex,e as convertValidationRules};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as r}from"react/jsx-runtime";import{Controller as s}from"react-hook-form";import{CheckboxFieldComponent as u}from"../../form/fields";import{convertValidationRules as C}from"../types";function x(t){const{control:l,errors:f,fieldConfig:i,t:a}=t,{name:c,label:e,validation:o}=i,d=typeof e=="string"?a(e):e;return r(s,{name:c,control:l,rules:o?C(o):void 0,render:({field:n})=>r(u,{label:d,checked:!!n.value,onChange:m=>n.onChange(m.target.checked),required:o?.required})})}export{x as ControlledCheckboxField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as c}from"react/jsx-runtime";import{Controller as g}from"react-hook-form";import{CurrencyFieldComponent as v}from"../../form/fields";import{convertValidationRules as y}from"../types";function V(i){const{control:s,errors:l,fieldConfig:t,t:d,placeholder:p}=i,{name:o,label:m,validation:r}=t,a=(t.options||{}).fieldSpecific;return c(g,{name:o,control:s,rules:r?y(r):void 0,render:({field:e})=>{const f=h=>{const n=h.target.value;if(n==null||n===""){e.onChange(null);return}const u=typeof n=="number"?n/100:parseFloat(String(n))/100;isNaN(u)?e.onChange(null):e.onChange(u)},C=e.value!=null&&!isNaN(e.value)?Math.round(e.value*100):void 0;return c(v,{label:d(m),value:C,onChange:f,currency:a?.currency||"EUR",locale:a?.locale,error:!!l[o],helperText:l[o]?.message,required:r?.required,placeholder:p})}})}export{V as ControlledCurrencyField};
|