@donotdev/crud 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CrudService.js +1 -1
- package/dist/CrudStore.js +1 -1
- package/dist/FieldRegistry.js +1 -1
- package/dist/adapters/FirestoreAdapter.js +1 -1
- package/dist/adapters/FunctionsAdapter.js +1 -1
- package/dist/adapters/index.js +1 -1
- package/dist/components/CrudButton.js +1 -1
- package/dist/components/DisplayFieldRenderer.js +1 -1
- package/dist/components/EntityDisplayRenderer.js +1 -1
- package/dist/components/EntityFilters.d.ts.map +1 -1
- package/dist/components/EntityFilters.js +1 -1
- package/dist/components/EntityFormRenderer.d.ts.map +1 -1
- package/dist/components/EntityFormRenderer.js +1 -1
- package/dist/components/FormFieldRenderer.js +1 -1
- package/dist/components/FormLayout.js +1 -1
- package/dist/components/controlled/complex/ControlledAddressField.js +1 -1
- package/dist/components/controlled/complex/ControlledDateField.js +1 -1
- package/dist/components/controlled/complex/ControlledGeoPointField.js +1 -1
- package/dist/components/controlled/complex/ControlledMapField.js +1 -1
- package/dist/components/controlled/complex/ControlledMultiInputField.js +1 -1
- package/dist/components/controlled/complex/ControlledRichTextField.js +1 -1
- package/dist/components/controlled/complex/ControlledTimestampField.js +1 -1
- package/dist/components/controlled/complex/index.js +1 -1
- package/dist/components/controlled/file/ControlledDocumentField.js +1 -1
- package/dist/components/controlled/file/ControlledFileField.js +1 -1
- package/dist/components/controlled/file/ControlledImageField.js +1 -1
- package/dist/components/controlled/file/ControlledMultiDocumentField.js +1 -1
- package/dist/components/controlled/file/ControlledMultiFileField.js +1 -1
- package/dist/components/controlled/file/ControlledMultiImageField.js +1 -1
- package/dist/components/controlled/file/index.js +1 -1
- package/dist/components/controlled/index.js +1 -1
- package/dist/components/controlled/input/ControlledCheckboxField.js +1 -1
- package/dist/components/controlled/input/ControlledCurrencyField.js +1 -1
- package/dist/components/controlled/input/ControlledDurationField.js +1 -1
- package/dist/components/controlled/input/ControlledGdprConsentField.js +1 -1
- package/dist/components/controlled/input/ControlledNumberField.js +1 -1
- package/dist/components/controlled/input/ControlledPasswordField.js +1 -1
- package/dist/components/controlled/input/ControlledPhoneField.js +1 -1
- package/dist/components/controlled/input/ControlledPriceField.js +1 -1
- package/dist/components/controlled/input/ControlledRangeField.js +1 -1
- package/dist/components/controlled/input/ControlledRatingField.js +1 -1
- package/dist/components/controlled/input/ControlledSwitchField.js +1 -1
- package/dist/components/controlled/input/ControlledTextField.js +1 -1
- package/dist/components/controlled/input/ControlledTextareaField.js +1 -1
- package/dist/components/controlled/input/index.js +1 -1
- package/dist/components/controlled/select/ControlledComboboxField.js +1 -1
- package/dist/components/controlled/select/ControlledDropdownField.js +1 -1
- package/dist/components/controlled/select/ControlledMultiDropdownField.js +1 -1
- package/dist/components/controlled/select/ControlledRadioField.js +1 -1
- package/dist/components/controlled/select/ControlledYearField.js +1 -1
- package/dist/components/controlled/select/index.js +1 -1
- package/dist/components/controlled/types.js +1 -1
- package/dist/components/fields/display/AvatarFieldDisplay.js +1 -1
- package/dist/components/fields/display/BadgeFieldDisplay.js +1 -1
- package/dist/components/fields/display/ButtonFieldDisplay.js +1 -1
- package/dist/components/fields/display/CheckboxFieldDisplay.js +1 -1
- package/dist/components/fields/display/DateFieldDisplay.js +1 -1
- package/dist/components/fields/display/DropdownDisplay.js +1 -1
- package/dist/components/fields/display/FileFieldDisplay.js +1 -1
- package/dist/components/fields/display/GeoPointFieldDisplay.js +1 -1
- package/dist/components/fields/display/HiddenFieldDisplay.js +1 -1
- package/dist/components/fields/display/ImageFieldDisplay.js +1 -1
- package/dist/components/fields/display/LinkFieldDisplay.js +1 -1
- package/dist/components/fields/display/MapFieldDisplay.js +1 -1
- package/dist/components/fields/display/MultiDropdownDisplay.js +1 -1
- package/dist/components/fields/display/MultiInputTextFieldDisplay.js +1 -1
- package/dist/components/fields/display/NumberFieldDisplay.js +1 -1
- package/dist/components/fields/display/PasswordFieldDisplay.js +1 -1
- package/dist/components/fields/display/PhoneNumberDisplay.js +1 -1
- package/dist/components/fields/display/RadioFieldDisplay.js +1 -1
- package/dist/components/fields/display/RangeFieldDisplay.js +1 -1
- package/dist/components/fields/display/ReferenceFieldDisplay.js +1 -1
- package/dist/components/fields/display/RichTextDisplay.js +2 -2
- package/dist/components/fields/display/TextAreaDisplay.js +1 -1
- package/dist/components/fields/display/TextFieldDisplay.js +1 -1
- package/dist/components/fields/display/TimestampFieldDisplay.js +1 -1
- package/dist/components/fields/display/index.js +1 -1
- package/dist/components/form/fields/AddressFieldComponent.js +1 -1
- package/dist/components/form/fields/AvatarFieldComponent.js +1 -1
- package/dist/components/form/fields/BadgeFieldComponent.js +1 -1
- package/dist/components/form/fields/ButtonFieldComponent.js +1 -1
- package/dist/components/form/fields/CheckboxFieldComponent.js +1 -1
- package/dist/components/form/fields/ComboboxComponent.js +1 -1
- package/dist/components/form/fields/CurrencyFieldComponent.js +1 -1
- package/dist/components/form/fields/DateFieldComponent.js +1 -1
- package/dist/components/form/fields/DocumentFieldComponent.js +1 -1
- package/dist/components/form/fields/DropdownComponent.js +1 -1
- package/dist/components/form/fields/DurationFieldComponent.js +1 -1
- package/dist/components/form/fields/FileFieldComponent.js +1 -1
- package/dist/components/form/fields/GdprConsentFieldComponent.js +1 -1
- package/dist/components/form/fields/GeoPointFieldComponent.js +1 -1
- package/dist/components/form/fields/HiddenFieldComponent.js +1 -1
- package/dist/components/form/fields/ImageFieldComponent.js +1 -1
- package/dist/components/form/fields/MapFieldComponent.js +1 -1
- package/dist/components/form/fields/MultiDropdownComponent.js +1 -1
- package/dist/components/form/fields/MultiInputTextFieldComponent.js +1 -1
- package/dist/components/form/fields/NumberFieldComponent.js +1 -1
- package/dist/components/form/fields/PasswordFieldComponent.js +1 -1
- package/dist/components/form/fields/PhoneNumberComponent.d.ts.map +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/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/hooks/useEntityForm.js +1 -1
- package/dist/forms/index.js +1 -1
- package/dist/forms/types.d.ts +8 -1
- package/dist/forms/types.d.ts.map +1 -1
- package/dist/forms/utils/buildInitialValues.d.ts +30 -0
- package/dist/forms/utils/buildInitialValues.d.ts.map +1 -0
- package/dist/forms/utils/buildInitialValues.js +1 -0
- 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 +11 -5
- package/dist/forms/utils/translateFieldLabel.d.ts.map +1 -1
- package/dist/forms/utils/translateFieldLabel.js +1 -1
- package/dist/forms/utils/validateEntity.js +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/useEntityFavorites.js +1 -1
- package/dist/hooks/useFileUpload.js +1 -1
- package/dist/hooks/useFormNavigationGuard.js +1 -1
- package/dist/hooks/useRelatedItems.js +1 -1
- package/dist/hooks/useUnsavedChangesWarning.js +1 -1
- package/dist/index.js +1 -1
- package/dist/registerBuiltinFieldTypes.d.ts.map +1 -1
- package/dist/registerBuiltinFieldTypes.js +1 -1
- package/dist/stores/FormStore.js +1 -1
- package/dist/stores/UploadStore.js +1 -1
- package/dist/stores/index.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/useBaseCrudList.js +1 -1
- package/dist/useCrud.js +1 -1
- package/dist/useCrudCardList.js +1 -1
- package/dist/useCrudList.js +1 -1
- package/dist/utils/collections.js +1 -1
- package/dist/utils/fileStorage.js +1 -1
- package/dist/utils/imageProcessing.js +1 -1
- package/dist/utils/imageStorage.js +1 -1
- package/dist/utils/imageUtils.js +1 -1
- package/dist/utils/mergeWithOptimistic.js +1 -1
- package/dist/utils/scopeUtils.js +1 -1
- package/dist/utils/uploadValidation.js +1 -1
- package/package.json +4 -4
package/dist/CrudService.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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};
|
|
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};
|
package/dist/CrudStore.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createDoNotDevStore as
|
|
1
|
+
import{createDoNotDevStore as u}from"@donotdev/core";const d={filters:{},showFavoritesOnly:!1};function r(){return{loading:!1,error:null,lastUpdated:0,optimistic:{},ui:{...d}}}const m={backend:null,crudService:null,hideSuccessToasts:!1,collections:{}},g=u({name:"crud-store",createStore:(l,n)=>({...m,setCrudService:t=>{l({crudService:t})},setBackend:t=>{l({backend:t})},setHideSuccessToasts:t=>{l({hideSuccessToasts:t})},setLoading:(t,e)=>{l(o=>{const i=o.collections[t]||r();return{collections:{...o.collections,[t]:{...i,loading:e}}}})},setError:(t,e)=>{l(o=>{const i=o.collections[t]||r();return{collections:{...o.collections,[t]:{...i,error:e,loading:!1}}}})},setFilters:(t,e)=>{l(o=>{const i=o.collections[t]||r();return{collections:{...o.collections,[t]:{...i,ui:{...i.ui,filters:e}}}}})},setShowFavoritesOnly:(t,e)=>{l(o=>{const i=o.collections[t]||r();return{collections:{...o.collections,[t]:{...i,ui:{...i.ui,showFavoritesOnly:e}}}}})},getFilters:t=>n().collections[t]?.ui?.filters||{},getShowFavoritesOnly:t=>n().collections[t]?.ui?.showFavoritesOnly||!1,clearCollection:t=>{l(e=>{const{[t]:o,...i}=e.collections;return{collections:i}})},clearError:t=>{l(e=>{const o=e.collections[t];return o?{collections:{...e.collections,[t]:{...o,error:null}}}:e})},addOptimistic:(t,e,o)=>{l(i=>{const c=i.collections[t]||r();return{collections:{...i.collections,[t]:{...c,optimistic:{...c.optimistic,[e]:{tempId:e,originalData:null,optimisticData:o,status:"pending",operation:"add"}},lastUpdated:Date.now()}}}})},confirmOptimistic:(t,e,o,i)=>{l(c=>{const s=c.collections[t];if(!s)return c;const{[e]:a,...p}=s.optimistic;return{collections:{...c.collections,[t]:{...s,optimistic:p,lastUpdated:Date.now()}}}})},rejectOptimistic:(t,e)=>{l(o=>{const i=o.collections[t];if(!i)return o;const{[e]:c,...s}=i.optimistic;return{collections:{...o.collections,[t]:{...i,optimistic:s,lastUpdated:Date.now()}}}})},updateOptimistic:(t,e,o,i)=>{l(c=>{const s=c.collections[t]||r();return{collections:{...c.collections,[t]:{...s,optimistic:{...s.optimistic,[e]:{tempId:e,originalData:i,optimisticData:o,status:"pending",operation:"update"}},lastUpdated:Date.now()}}}})},confirmUpdate:(t,e)=>{l(o=>{const i=o.collections[t];if(!i)return o;const{[e]:c,...s}=i.optimistic;return{collections:{...o.collections,[t]:{...i,optimistic:s}}}})},rejectUpdate:(t,e)=>{l(o=>{const i=o.collections[t];if(!i)return o;const c=i.optimistic[e];if(!c||c.operation!=="update")return o;const{[e]:s,...a}=i.optimistic;return{collections:{...o.collections,[t]:{...i,optimistic:a,lastUpdated:Date.now()}}}})},deleteOptimistic:(t,e,o)=>{l(i=>{const c=i.collections[t];return c?{collections:{...i.collections,[t]:{...c,optimistic:{...c.optimistic,[e]:{tempId:e,originalData:o,optimisticData:null,status:"pending",operation:"delete"}},lastUpdated:Date.now()}}}:i})},confirmDelete:(t,e)=>{l(o=>{const i=o.collections[t];if(!i)return o;const{[e]:c,...s}=i.optimistic;return{collections:{...o.collections,[t]:{...i,optimistic:s}}}})},rejectDelete:(t,e)=>{l(o=>{const i=o.collections[t];if(!i)return o;const c=i.optimistic[e];if(!c||c.operation!=="delete")return o;const{[e]:s,...a}=i.optimistic;return{collections:{...o.collections,[t]:{...i,optimistic:a,lastUpdated:Date.now()}}}})},getLoading:t=>n().collections[t]?.loading||!1,getError:t=>n().collections[t]?.error||null,isOptimistic:(t,e)=>n().collections[t]?.optimistic[e]?.status==="pending",getOptimisticStatus:(t,e)=>n().collections[t]?.optimistic[e]?.status??null,getOptimisticData:(t,e)=>n().collections[t]?.optimistic[e]?.optimisticData??null})});export{g as useCrudStore};
|
package/dist/FieldRegistry.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";class
|
|
1
|
+
"use client";class c{components=new Map;registerComponent(e,t,o){this.components.set(e,{controlled:t,uncontrolled:o})}register(e){const{type:t,controlledComponent:o,uncontrolledComponent:l}=e;this.components.set(t,{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 c),r}function i(n){s().register(n)}function p(n){return s().has(n)}export{s as getFieldRegistry,p as isFieldTypeRegistered,i as registerFieldType};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as
|
|
1
|
+
import*as d from"valibot";import{handleError as w}from"@donotdev/core";import{getFirestore as b,getFirebaseSDK as v,doc as p,getDoc as g,getDocs as q,setDoc as R,updateDoc as S,deleteDoc as E,addDoc as M,collection as V,query as A,where as D,orderBy as x,limit as B,startAfter as z,onSnapshot as I}from"@donotdev/firebase";import{transformFirestoreData as m,prepareForFirestore as F}from"@donotdev/firebase";class K{firestore;ensureFirestore(){if(this.firestore)return!0;try{return this.firestore=b(),!0}catch{return!1}}getCollectionRef(s){return!this.ensureFirestore()||!this.firestore?null:V(this.firestore,s)}async get(s,t,e){if(!this.ensureFirestore()||!this.firestore)return null;try{const o=p(this.firestore,s,t),i=await g(o);if(!i.exists())return null;let r=i.data();return r=m(r),{...d.parse(e,r),id:t}}catch(o){return w(o,{context:{operation:"FirestoreAdapter.get",collection:s,docId:t},severity:"warning"}),null}}async set(s,t,e,o){if(!(!this.ensureFirestore()||!this.firestore))try{d.parse(o,e);const i=p(this.firestore,s,t),r=F(e);await R(i,r)}catch(i){throw i}}async update(s,t,e){if(!(!this.ensureFirestore()||!this.firestore))try{const o=p(this.firestore,s,t),i=F(e);await S(o,i)}catch(o){throw o}}async delete(s,t){if(!(!this.ensureFirestore()||!this.firestore))try{const e=p(this.firestore,s,t);await E(e)}catch(e){throw e}}async add(s,t,e){if(!this.ensureFirestore())return"";try{d.parse(e,t);const o=this.getCollectionRef(s);if(!o)return"";const i=new Date().toISOString(),r=v().getCurrentUser()?.uid||"anonymous",c={...t,createdAt:i,updatedAt:i,createdById:r,updatedById:r},a=F(c);return(await M(o,a)).id}catch(o){throw o}}async query(s,t,e,o="list"){if(!this.ensureFirestore())return{items:[]};const i=this.getCollectionRef(s);if(!i)return{items:[]};try{const r=[];if(t.where)for(const n of t.where)r.push(D(n.field,n.operator,n.value));if(t.orderBy)for(const n of t.orderBy)r.push(x(n.field,n.direction||"asc"));if(t.startAfterId){const n=await g(p(i,t.startAfterId));n.exists()&&r.push(z(n))}const c=t.limit?t.limit+1:void 0;c&&r.push(B(c));const a=A(i,...r),h=await q(a),u=[];let l=null;h.forEach(n=>{try{let f=n.data();if(!f)return;f=m(f);const C=d.parse(e,f);u.push({...C,id:n.id}),l=n.id}catch(f){w(f,{context:{operation:"FirestoreAdapter.query.parse",docId:n.id,collection:s},showNotification:!1})}});const y=c?u.length>(t.limit||0):!1;return{items:y?u.slice(0,t.limit):u,hasMore:y,lastVisible:l,total:void 0}}catch(r){throw w(r,{context:{operation:"FirestoreAdapter.query",collection:s,options:t}}),r}}subscribe(s,t,e,o){if(!this.ensureFirestore()||!this.firestore)return()=>{};const i=p(this.firestore,s,t);return I(i,r=>{try{if(!r.exists()){e(null);return}let c=r.data();c=m(c);const a=d.parse(o,c);e({...a,id:t})}catch(c){e(null,c)}},r=>{e(null,r)})}subscribeToCollection(s,t,e,o){if(!this.ensureFirestore())return()=>{};const i=this.getCollectionRef(s);if(!i)return()=>{};try{const r=[];if(t.where)for(const a of t.where)r.push(D(a.field,a.operator,a.value));if(t.orderBy)for(const a of t.orderBy)r.push(x(a.field,a.direction||"asc"));t.limit&&r.push(B(t.limit));const c=A(i,...r);return I(c,a=>{try{const h=[];a.forEach(u=>{let l=u.data();l=m(l);const y=d.parse(o,l);h.push({...y,id:u.id})}),e(h)}catch(h){e([],h)}},a=>{e([],a)})}catch(r){return e([],r),()=>{}}}}export{K as FirestoreAdapter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{httpsCallable as
|
|
1
|
+
import{httpsCallable as n}from"firebase/functions";import*as u from"valibot";import{getPlatformEnvVar as d}from"@donotdev/core";import{getFirebaseFunctions as h}from"@donotdev/firebase";class l{functions;region;constructor(){this.region=d("FIREBASE_FUNCTIONS_REGION")||"europe-west1"}async ensureFunctions(){if(this.functions)return!0;try{return this.functions=await h(this.region),!0}catch{return!1}}async get(i,t,a){if(!await this.ensureFunctions())return null;try{const r=`get_${i}`;return(await n(this.functions,r)({id:t})).data}catch(r){throw r}}async set(i,t,a,r){if(await this.ensureFunctions())try{u.parse(r,a);const e=`update_${i}`;await n(this.functions,e)({id:t,payload:a})}catch(e){throw e}}async update(i,t,a){if(await this.ensureFunctions())try{const r=`update_${i}`;await n(this.functions,r)({id:t,payload:a})}catch(r){throw r}}async delete(i,t){if(await this.ensureFunctions())try{const a=`delete_${i}`;await n(this.functions,a)({id:t})}catch(a){throw a}}async add(i,t,a){if(!await this.ensureFunctions())return"";try{u.parse(a,t);const r=`create_${i}`;return(await n(this.functions,r)({payload:t})).data.id}catch(r){throw r}}async query(i,t,a,r="list"){if(!await this.ensureFunctions())return{items:[]};try{const e=r==="listCard"?`listCard_${i}`:`list_${i}`,s={};t.where&&(s.where=t.where.map(o=>[o.field,o.operator,o.value])),t.orderBy&&(s.orderBy=t.orderBy.map(o=>[o.field,o.direction||"asc"])),t.limit&&(s.limit=t.limit),t.startAfterId&&(s.startAfterId=t.startAfterId);const c=await n(this.functions,e)(s);return{items:c.data.items,total:c.data.count,hasMore:c.data.hasMore,lastVisible:c.data.lastVisible}}catch(e){throw e}}async listCard(i,t,a){if(!await this.ensureFunctions())return[];try{const r=`listCard_${i}`,e={};return t.where&&(e.where=t.where.map(s=>[s.field,s.operator,s.value])),t.orderBy&&(e.orderBy=t.orderBy.map(s=>[s.field,s.direction||"asc"])),t.limit&&(e.limit=t.limit),(await n(this.functions,r)(e)).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{l as FunctionsAdapter};
|
package/dist/adapters/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./FirestoreAdapter";import{FunctionsAdapter as
|
|
1
|
+
export*from"./FirestoreAdapter";import{FunctionsAdapter as o}from"./FunctionsAdapter";export{o as FunctionsAdapter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
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:s,...i}){const o=a(u=>!!u.crudService);return d(n,{...i,disabled:t||!o||r&&!e,children:s})}var l=c;export{l as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as r,jsxs as s}from"react/jsx-runtime";import{Text as a,Stack as c}from"@donotdev/components";import{handleError as d}from"@donotdev/core";import{translateFieldLabel as u}from"../forms/utils";import{getDisplayFormatter as y}from"../fieldTypeRegistry";function m(t,e,o,n){const i=n?.compact??!1;if(t==null||t==="")return i?r("span",{style:{color:"var(--muted-foreground)"},children:"\u2014"}):r(a,{variant:"muted",children:"\u2014"});const l=y(e.type);if(l)try{return l(t,e,o,n)}catch(f){return d(f,{userMessage:`Error formatting field "${e.label||e.name}"`,context:{fieldType:e.type,fieldName:e.label||"unknown",operation:"display_format"},severity:"warning"}),i?r("span",{style:{color:"var(--muted-foreground)"},children:String(t)}):r(a,{variant:"muted",children:String(t)})}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?r("span",{style:{color:"var(--muted-foreground)"},children:String(t)}):r(a,{variant:"muted",children:String(t)})}function p({name:t,config:e,value:o,t:n}){const i=m(o,e,n,{compact:!1}),l=u(t,e,n);return s(c,{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,":"]}),r("div",{style:{flex:1,display:"flex",alignItems:"center"},children:typeof i=="string"?r(a,{children:i}):i})]})}var g=p;export{p as DisplayFieldRenderer,g as default,m as formatValue};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as t,jsxs as D}from"react/jsx-runtime";import{useEffect as O,useState as f,useMemo as L}from"react";import{Stack as g,Spinner as T}from"@donotdev/components";import{useTranslation as v,isFieldVisible as $}from"@donotdev/core";import{DisplayFieldRenderer as q}from"./DisplayFieldRenderer";import{useCrud as I}from"../useCrud";function b({entity:i,id:o,t:A,className:c="",backend:E="functions",loadingMessage:S,notFoundMessage:j,viewerRole:p="guest"}){const{get:m,loading:k,data:w,error:x,isAvailable:y}=I(i,{backend:E}),[F,u]=f(!1),[M,a]=f(null),[N,d]=f(null),{t:R}=v([i.namespace,"crud"]),{t:h}=v("crud"),V=A||R;O(()=>{if(!o){d(null),a(null),u(!1);return}if(!y||!m)return;let n=!1;return u(!0),a(null),m(o).then(e=>{n||(u(!1),e?(d(e),a(null)):(d(null),a(new Error("Entity not found"))))}).catch(e=>{n||(u(!1),a(e instanceof Error?e:new Error(String(e))),d(null))}),()=>{n=!0}},[o,m,y]);const l=w||N,s=x||M,z=k||F||!o,C=L(()=>l?Object.entries(i.fields).filter(([n,e])=>{if(!$(e.visibility,p)||e.visibility==="hidden")return!1;const r=l[n];return!(r==null||typeof r=="string"&&r.trim()===""||Array.isArray(r)&&r.length===0||typeof r=="object"&&!Array.isArray(r)&&r!==null&&Object.keys(r).length===0)}):[],[i.fields,p,l]);return z?t("div",{style:{position:"relative",width:"100%",gridColumn:"1 / -1",display:"contents"},className:c,children:t(T,{overlay:!0,"aria-label":S||h("form.loading",{defaultValue:"Loading..."})})}):s||!l?t(g,{align:"center",justify:"center",gap:"medium",style:{padding:"var(--gap-3xl)",textAlign:"center"},className:c,children:D(g,{direction:"column",gap:"tight",children:[t("h3",{style:{color:"var(--muted-foreground)"},children:j||h("errors.notFound",{defaultValue:`${i.name} not found`})}),s&&t("p",{style:{color:"var(--destructive)",fontSize:"var(--font-size-sm)"},children:s instanceof Error?s.message:String(s)})]})}):t(g,{direction:"column",gap:"medium",className:c,children:C.map(([n,e])=>t(q,{name:n,config:e,value:l[n],t:V},n))})}var Q=b;export{b as EntityDisplayRenderer,Q as default};
|
|
@@ -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":"AAsDA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAM7C;;;;;;;;;;;;;;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,EAEpD,SAAS,EAAE,MAAM,GAChB,OAAO,CA8MT;AAqND,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,GAAG;IACzC,4BAA4B;IAE5B,MAAM,EAAE,MAAM,CAAC;IAEf,2DAA2D;IAE3D,IAAI,EAAE,CAAC,EAAE,CAAC;IAEV,4BAA4B;IAE5B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAEjE,mCAAmC;IAEnC,eAAe,EAAE,CACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,KAC7D,IAAI,CAAC;IAEV,oFAAoF;IAEpF,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAE1B,sFAAsF;IAEtF,OAAO,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AAEH,wBAAgB,aAAa,CAC3B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnD,EACA,MAAM,EAEN,IAAI,EAEJ,OAAO,EAEP,eAAe,EAEf,cAAc,EAEd,OAAkB,GACnB,EAAE,kBAAkB,CAAC,CAAC,CAAC,kDAyjBvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as g,jsxs as R}from"react/jsx-runtime";import{useMemo as B,useState as
|
|
1
|
+
"use client";import{jsx as g,jsxs as R}from"react/jsx-runtime";import{useMemo as B,useState as U}from"react";import{FilterX as Z}from"lucide-react";import{Button as j,Calendar as V,Combobox as ee,Grid as te,Popover as ne,RangeInput as re,Slider as ie,Stack as z,Text as X}from"@donotdev/components";import{useTranslation as q,handleError as N,formatDate as H}from"@donotdev/core";import{translateFieldLabel as se,translateLabel as J}from"../forms/utils";import{getFilterType as W,isFilterable as oe}from"../fieldTypeRegistry";function ae(e,t,s){if(!t)return!0;if(typeof t=="object"&&"min"in t){const l=W(s);if(!l)throw N(new Error(`Field type "${s}" not registered in field type registry`),{userMessage:`Field type "${s}" is missing from registry`,context:{fieldType:s,operation:"filter_matching",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"}});const C=l==="range"&&(s==="date"||s==="datetime-local"||s==="timestamp"),F=l==="range"&&!C,D=s==="price",u=D&&e!=null&&typeof e=="object"?Number(e.amount):F&&e!=null?typeof e=="number"?e:Number(e):NaN;if(F||D){const d=t.min&&t.min!=="",y=t.max&&t.max!=="";return d&&!y?e==null||isNaN(u)?!1:u>=Number(t.min):!d&&y?e==null?!0:isNaN(u)?!1:u<=Number(t.max):d&&y?e==null||isNaN(u)?!1:u>=Number(t.min)&&u<=Number(t.max):!0}if(C){const d=t.min&&t.min!=="",y=t.max&&t.max!=="";if(d&&!y){if(e==null)return!1;const b=e instanceof Date?e:new Date(e);return isNaN(b.getTime())?!1:b>=new Date(t.min)}if(!d&&y){if(e==null)return!0;const b=e instanceof Date?e:new Date(e);return isNaN(b.getTime())?!1:b<=new Date(t.max)}if(d&&y){if(e==null)return!1;const b=e instanceof Date?e:new Date(e);return isNaN(b.getTime())?!1:b>=new Date(t.min)&&b<=new Date(t.max)}return!0}}const h=W(s);if(!h)throw N(new Error(`Field type "${s}" not registered in field type registry`),{userMessage:`Field type "${s}" is missing from registry`,context:{fieldType:s,operation:"filter_matching",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"}});if(h==="address")return e==null?!1:typeof e=="object"&&"formatted_address"in e?String(e.formatted_address).toLowerCase().includes(String(t).toLowerCase()):!1;if(h==="multiselect"){if(!Array.isArray(e)||e.length===0)return!1;const l=String(t).toLowerCase();return e.some(C=>String(C).toLowerCase().includes(l))}return e==null?!1:String(e).toLowerCase().includes(String(t).toLowerCase())}function le(e,t,s){if(!e&&!t)return s??"From \u2013 To";const h=e?H(e,void 0,{month:"short",day:"numeric",year:"numeric"}):"",l=t?H(t,void 0,{month:"short",day:"numeric",year:"numeric"}):"";return h&&l?`${h} \u2013 ${l}`:h?`${h} \u2013 \u2026`:l?`\u2026 \u2013 ${l}`:s??"From \u2013 To"}function ce({label:e,rangeFilter:t,onRangeChange:s,onClear:h,tCrud:l}){const[C,F]=U(!1),D=!!(t.min||t.max),u=t.min||t.max?{from:t.min?new Date(t.min+"T00:00:00"):void 0,to:t.max?new Date(t.max+"T00:00:00"):void 0}:void 0,d=a=>{if(!a){h();return}const x=a.from?a.from.toISOString().split("T")[0]:"",O=a.to?a.to.toISOString().split("T")[0]:"";s(x,O),a.from&&a.to&&F(!1)},y=(a,x)=>{s(a,x),F(!1)},b=()=>{h(),F(!1)},E=le(t.min,t.max,l("filter.fromTo",{defaultValue:"From \u2013 To"}));return g(ne,{open:C,onOpenChange:F,trigger:g(j,{variant:"outline","aria-haspopup":"dialog","aria-expanded":C,"aria-label":e,children:R(X,{as:"span",level:"small",variant:D?void 0:"muted",children:[e,": ",E]})}),children:R(z,{gap:"medium",style:{padding:"var(--gap-md)"},children:[g(X,{as:"span",level:"small",variant:"muted",children:e}),R(z,{direction:"row",gap:"tight",children:[g(j,{variant:"outline",display:"compact",onClick:()=>{const a=new Date().toISOString().split("T")[0];y(a,a)},children:l("filter.today",{defaultValue:"Today"})}),g(j,{variant:"outline",display:"compact",onClick:()=>{const a=new Date,x=new Date(a);x.setDate(a.getDate()-a.getDay());const O=new Date(x);O.setDate(x.getDate()+6),y(x.toISOString().split("T")[0],O.toISOString().split("T")[0])},children:l("filter.thisWeek",{defaultValue:"This Week"})}),g(j,{variant:"outline",display:"compact",onClick:()=>{const a=new Date,x=new Date(a.getFullYear(),a.getMonth(),1),O=new Date(a.getFullYear(),a.getMonth()+1,0);y(x.toISOString().split("T")[0],O.toISOString().split("T")[0])},children:l("filter.thisMonth",{defaultValue:"This Month"})})]}),g(V,{mode:"range",selected:u,onSelect:d,defaultMonth:u?.from??u?.to??new Date}),g(j,{variant:"ghost",display:"compact",onClick:b,children:l("filter.clearDate",{defaultValue:"Clear"})})]})})}function ye({entity:e,data:t,filters:s,onFiltersChange:h,fieldsToFilter:l,variant:C="inline"}){const F=C==="sidebar",{t:D}=q("crud"),{t:u}=q([e.namespace,"crud"]),d=B(()=>(l&&l.length>0?l:e.listFields||Object.keys(e.fields)).filter(n=>{const o=e.fields[n]?.type||"text";return oe(o)}),[l,e.listFields,e.fields]),y=B(()=>{const r={};return d.forEach(n=>{const m=Object.fromEntries(Object.entries(s).filter(([o])=>o!==n));if(Object.keys(m).length===0){r[n]=t;return}r[n]=t.filter(o=>Object.entries(m).every(([w,v])=>{const A=o[w],p=e.fields[w]?.type||"text";return ae(A,v,p)}))}),r},[t,s,e.fields,d]),b=B(()=>{const r={};return d.forEach(n=>{const m=e.fields[n];if(!m)return;const o=m.type||"text",w=W(o);if(!w){N(new Error(`Field type "${o}" not registered in field type registry`),{userMessage:`Field type "${o}" is missing from registry`,context:{fieldType:o,fieldName:n,operation:"minmax_computation",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"});return}const v=w==="range"&&(o==="date"||o==="datetime-local"||o==="timestamp"),A=w==="range"&&!v,k=o==="price";if(A||k){const p=t.map(i=>i[n]).filter(i=>i!=null&&i!=="").map(i=>k&&typeof i=="object"&&i!==null?Number(i.amount):typeof i=="number"?i:Number(i)).filter(i=>!isNaN(i));p.length>0&&(r[n]={min:Math.min(...p),max:Math.max(...p)})}else if(v){const p=t.map(i=>i[n]).filter(i=>i!=null&&i!=="").map(i=>i instanceof Date?i:new Date(i)).filter(i=>!isNaN(i.getTime()));if(p.length>0){const i=new Date(Math.min(...p.map($=>$.getTime()))),M=new Date(Math.max(...p.map($=>$.getTime()))),G=i.toISOString().split("T")[0],I=M.toISOString().split("T")[0];r[n]={min:G||"",max:I||""}}}}),r},[t,e.fields,d]),E=(r,n)=>{const m={...s};if(!n||n==="")delete m[r];else if(typeof n=="object"&&"min"in n){const o=n.min&&n.min!=="",w=n.max&&n.max!=="";!o&&!w?delete m[r]:m[r]=n}else m[r]=n;h(m)},a=()=>{h({})},x=B(()=>d.length===0?null:d.map(r=>{const n=e.fields[r];if(!n)return null;const m=se(r,n,u),o=n.type||"text",w=W(o);if(!w)return N(new Error(`Field type "${o}" not registered in field type registry`),{userMessage:`Field type "${o}" is missing from registry`,context:{fieldType:o,fieldName:r,operation:"filter_ui_render",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"}),null;const v=w==="range"&&(o==="date"||o==="datetime-local"||o==="timestamp"),A=w==="range"&&!v,k=w==="select",p=s[r],M=typeof p=="object"&&p!==null&&"min"in p?p:{min:"",max:""};if(A){const f=b[r],S=f?.min??0,c=f?.max??100,T=M.min?Number(M.min):S,_=M.max?Number(M.max):c;return R(z,{gap:"tight",style:{gridColumn:"span 2",gridRow:F?void 0:"span 2"},children:[g(re,{type:"number",label:m,minPlaceholder:D("filter.min",{defaultValue:"Min"}),maxPlaceholder:D("filter.max",{defaultValue:"Max"}),minValue:M.min||"",maxValue:M.max||"",actualMin:S,actualMax:c,onChange:(L,Q)=>{E(r,{min:L,max:Q})},onClear:()=>E(r,void 0)}),g(ie,{value:[T,_],min:S,max:c,step:1,onValueChange:L=>{E(r,{min:String(L[0]),max:String(L[1])})}})]},r)}if(v)return g("div",{style:{gridColumn:"span 2",gridRow:F?void 0:"span 1"},children:g(ce,{label:m,rangeFilter:M,onRangeChange:(f,S)=>E(r,{min:f,max:S}),onClear:()=>E(r,void 0),tCrud:D})},r);const I=k&&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[r]||t,Y=new Set;$.forEach(f=>{const S=f[r];S!=null&&Y.add(String(S))});const P=[{value:"all",label:D("filter.selectPlaceholder",{defaultValue:"All"})}];if(I.length>0){const f=[],S=[];I.forEach(c=>{const T=typeof c=="string"?c:c.value,_=typeof c=="string"?c:c.label;Y.has(T)?f.push({value:T,label:_}):S.push({value:T,label:_})}),f.sort((c,T)=>c.label.localeCompare(T.label)),S.sort((c,T)=>c.label.localeCompare(T.label)),f.forEach(c=>{P.push({value:c.value,label:J(c.label,u),disabled:!1})}),S.forEach(c=>{P.push({value:c.value,label:J(c.label,u),disabled:!0})})}else Array.from(Y).sort().slice(0,100).forEach(f=>{P.push({value:f,label:f})});return g("div",{style:{gridColumn:"span 2",gridRow:"span 1"},children:g(ee,{label:m,value:typeof p=="string"?p:void 0,onValueChange:f=>{E(r,f==="all"||!f?"":String(f))},options:P,placeholder:D("filter.placeholder",{defaultValue:"Filter..."}),clearable:!0})},r)}),[d,e.fields,t,s,u,D,y]);if(!x||x.length===0)return null;const O=x.filter(Boolean),K=Object.keys(s).length>0;return R(te,{cols:C==="sidebar"?2:[2,4,6,8],gap:"medium",style:{gridAutoRows:"min-content"},children:[O,g(j,{variant:"outline",icon:g(Z,{size:18}),onClick:a,disabled:!K,style:{gridColumn:"1 / -1",gridRow:"span 1"},children:D("filter.clear",{defaultValue:"Clear Filters"})})]})}export{ye as EntityFilters,ae as matchesFilter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityFormRenderer.d.ts","sourceRoot":"","sources":["../../src/components/EntityFormRenderer.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAY7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,UAAU,uBAAuB,CAC/B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAE3D,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,2BAA2B;IAC3B,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC;IAC/D,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yBAAyB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0BAA0B;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3B,4BAA4B;IAC5B,aAAa,CAAC,EAAE,SAAS,GAAG,aAAa,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;IACzE,4BAA4B;IAC5B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,+BAA+B;IAC/B,sBAAsB,CAAC,EACnB,SAAS,GACT,aAAa,GACb,SAAS,GACT,OAAO,GACP,MAAM,CAAC;IACX,0CAA0C;IAC1C,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD;;;OAGG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB;;;OAGG;IACH,SAAS,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,EACtE,MAAM,EACN,QAAQ,EACR,CAAC,EACD,SAAc,EACd,UAAU,EACV,OAAe,EACf,aAAa,EACb,aAAyB,EACzB,mBAAmB,EACnB,sBAAkC,EAClC,iBAAiB,EACjB,UAAU,EACV,SAA6C,EAC7C,QAAiC,EACjC,MAAM,EAAE,cAAc,EACtB,UAAU,EACV,QAAQ,EACR,oBAA2B,EAC3B,qBAAqB,GACtB,EAAE,uBAAuB,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"EntityFormRenderer.d.ts","sourceRoot":"","sources":["../../src/components/EntityFormRenderer.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAY7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,UAAU,uBAAuB,CAC/B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAE3D,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,2BAA2B;IAC3B,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC;IAC/D,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yBAAyB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0BAA0B;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3B,4BAA4B;IAC5B,aAAa,CAAC,EAAE,SAAS,GAAG,aAAa,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC;IACzE,4BAA4B;IAC5B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,+BAA+B;IAC/B,sBAAsB,CAAC,EACnB,SAAS,GACT,aAAa,GACb,SAAS,GACT,OAAO,GACP,MAAM,CAAC;IACX,0CAA0C;IAC1C,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD;;;OAGG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB;;;OAGG;IACH,SAAS,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,EACtE,MAAM,EACN,QAAQ,EACR,CAAC,EACD,SAAc,EACd,UAAU,EACV,OAAe,EACf,aAAa,EACb,aAAyB,EACzB,mBAAmB,EACnB,sBAAkC,EAClC,iBAAiB,EACjB,UAAU,EACV,SAA6C,EAC7C,QAAiC,EACjC,MAAM,EAAE,cAAc,EACtB,UAAU,EACV,QAAQ,EACR,oBAA2B,EAC3B,qBAAqB,GACtB,EAAE,uBAAuB,CAAC,CAAC,CAAC,2CAkP5B;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as r,jsxs as f}from"react/jsx-runtime";import{useEffect as T,useId as
|
|
1
|
+
"use client";import{jsx as r,jsxs as f}from"react/jsx-runtime";import{useEffect as T,useId as Z,useMemo as p}from"react";import{FormProvider as ee}from"react-hook-form";import{Button as v,Stack as re,Spinner as oe}from"@donotdev/components";import{useTranslation as D}from"@donotdev/core";import{DisplayFieldRenderer as te}from"./DisplayFieldRenderer";import{FormFieldRenderer as ne}from"./FormFieldRenderer";import{UploadProvider as ae}from"../contexts/UploadContext";import{useEntityForm as ie}from"../forms/hooks/useEntityForm";import{useUnsavedChangesWarning as se,useConfirmNavigation as de}from"../hooks/useUnsavedChangesWarning";import{useFormStore as le}from"../stores";function ue({entity:u,onSubmit:I,t:k,className:V="",submitText:N,loading:j=!1,defaultValues:s,submitVariant:P="primary",secondaryButtonText:m,secondaryButtonVariant:U="outline",onSecondarySubmit:h,viewerRole:B,operation:c=s?"edit":"create",autoSave:E=c==="create",formId:L,cancelText:y,onCancel:R,warnOnUnsavedChanges:$=!0,unsavedChangesMessage:d}){const M=Z(),n=L??`entity-form-${u.name}-${M}`,{t:Y}=D([u.namespace,"crud"]),{t:e}=D("crud"),g=k||Y,b=ie(u,{formId:n,operation:c,defaultValues:s,viewerRole:B,t:g,autoSave:E}),{control:_,handleSubmit:x,formState:{errors:z},fields:A,formStatus:l,uploadProgress:a,cleanup:C,isDirty:W,hasUserInteracted:q,resetForm:G}=b,i=W&&q;T(()=>{n&&le.getState().setIsDirty(n,i)},[n,i]),T(()=>C,[C]);const H=p(()=>d||e("messages.unsavedChangesLeave",{defaultValue:"You have unsaved changes. Are you sure you want to leave?"}),[d,e]),J=p(()=>d||e("messages.unsavedChangesDiscard",{defaultValue:"You have unsaved changes. Discard them?"}),[d,e]);se({isDirty:i,enabled:$,message:H});const K=de(i,J),O=async()=>{i&&!await K()||(G(),R?.())},F=y!==null,S=y??e("form.cancel",{defaultValue:"Cancel"}),Q=j||c==="edit"&&!s,o=p(()=>l==="uploading"?{loading:!0,loadingText:a<100?e("form.uploading",{progress:Math.round(a),defaultValue:`Uploading ${Math.round(a)}%...`}):e("form.processing",{defaultValue:"Processing..."}),progress:a}:l==="validating"?{loading:!0,loadingText:e("form.validating",{defaultValue:"Validating..."})}:l==="submitting"?{loading:!0,loadingText:e("form.saving",{defaultValue:"Saving..."})}:{loading:!1},[l,a,e]);return r(ee,{...b,children:r(ae,{formId:n,children:f("div",{style:{position:"relative",width:"100%",gridColumn:"1 / -1",display:"contents"},children:[Q&&r(oe,{overlay:!0}),f("form",{onSubmit:x(I),noValidate:!0,className:V,style:{width:"100%",gridColumn:"1 / -1",display:"contents"},children:[A.map(({name:t,config:w,editable:X})=>X?r(ne,{name:t,config:w,control:_,errors:z,t:g},t):r(te,{name:t,config:w,value:s?.[t],t:g},t)),f(re,{direction:m||F?"row":"column",gap:"tight",style:{gridColumn:"1 / -1",position:"sticky",bottom:0,backgroundColor:"var(--background)",borderTop:"1px solid var(--border)",paddingTop:"var(--gap-md)",paddingBottom:"var(--gap-md)",zIndex:10,marginTop:"var(--gap-lg)"},children:[F&&S&&r(v,{type:"button",onClick:O,disabled:o.loading,variant:"outline",className:"dndev-w-full",children:S}),m&&r(v,{type:"button",onClick:()=>h&&x(h)(),loading:o.loading,loadingText:o.loadingText,progress:o.progress,variant:U,className:"dndev-w-full",children:m}),r(v,{type:"submit",loading:o.loading,loadingText:o.loadingText,progress:o.progress,variant:P,className:"dndev-w-full",children:N||e("form.submit",{defaultValue:"Submit"})})]})]})]})})})}var Se=ue;export{ue as EntityFormRenderer,Se as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as t}from"react/jsx-runtime";import{handleError as C}from"@donotdev/core";import{getFieldRegistry as F}from"../FieldRegistry";import{ControlledTextField as T}from"./controlled";import{TextFieldComponent as w}from"./form/fields";import"../builtinFieldTypes";const v=F();function h({name:o,config:e,t:r,...n}){const p=l=>i=>{try{l(i)}catch(a){C(a,{userMessage:`Error updating field ${e.label||o}`,context:{fieldName:o,fieldType:e.type},severity:"warning"})}},s="control"in n&&n.control,d=e.type==="submit"||e.type==="reset";if(s&&!d){const{control:l,errors:i}=n,a=e.options?.fieldSpecific?.placeholder,y={control:l,errors:i,fieldConfig:{...e,label:e.label||o},t:r,placeholder:a,onChange:p(()=>{})},u=v.getControlledComponent(e.type);return u?t(u,{...y}):(C(new Error(`Unregistered field type: ${e.type}`),{userMessage:r("errors.unsupportedFieldType",{type:e.type}),context:{fieldName:o,fieldType:e.type},severity:"warning"}),t(T,{...y,fieldConfig:{...e,type:"text"}}))}const b=s&&d?{name:o,config:e,t:r,value:void 0,onChange:()=>{},error:void 0}:n,{value:f,onChange:x,error:c}=b,m=p(x),g=v.getUncontrolledComponent(e.type);return g?t(g,{name:o,label:e.label||o,value:f,onChange:m,error:c,t:r,config:e,...e.options}):t(w,{label:e.label||o,value:f,onChange:m,error:c||void 0,...e.options})}var E=h;export{h as FormFieldRenderer,E as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as d,jsxs as r,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 n,Grid as F}from"@donotdev/components";import{useTranslation as I}from"@donotdev/core";const L=({title:m,onSubmit:c,children:g,formMethods:u,loading:a=!1,submitText:f,cancelText:v,showCancel:p=!1,onCancel:h,variant:o="default",columns:b=1,description:t})=>{const{t:e}=I("dndev"),[i,l]=w(!1),y=f||e("form.submit","Submit"),x=v||e("form.cancel","Cancel"),S=async T=>{l(!0);try{await c(T)}finally{l(!1)}},B={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,{...u,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:r(n,{gap:"large",children:[r(n,{gap:"tight",children:[d("h2",{id:"form-title",style:{fontSize:"var(--font-size-2xl)",fontWeight:600,color:"var(--foreground)"},children:m}),t&&d("p",{style:{color:"var(--muted-foreground)"},children:t})]}),d(F,{cols:b,gap:"medium",className:"dndev-w-full dndev-min-w-0",children:g}),r(n,{direction:"row",align:"center",justify:"end",gap:"medium",style:{paddingTop:"var(--gap-md)",borderTop:"1px solid var(--border)"},children:[p&&d(s,{type:"button",variant:j.OUTLINE,onClick:h,disabled:a||i,children:x}),d(s,{type:"submit",disabled:a||i,style:{minWidth:"120px"},children:a||i?r(N,{children:[d(k,{className:"me-component-gap"}),i?e("form.submitting","Submitting..."):e("form.loading","Loading...")]}):y})]})]})})})};var A=L;export{A as default};
|
|
@@ -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{AddressFieldComponent as p}from"../../form/fields";import{convertValidationRules as u}from"../types";function C(a){const{control:s,errors:r,fieldConfig:t,t:d}=a,{name:e,label:c,validation:o}=t,l=(t.options||{}).fieldSpecific;return n(f,{name:e,control:s,rules:o?u(o):void 0,render:({field:i})=>n(p,{label:d(c),value:i.value??void 0,onChange:m=>i.onChange(m),error:!!r[e],helperText:r[e]?.message,required:o?.required,enableGoogleMaps:l?.enableGoogleMaps,extractDistrictCode:l?.extractDistrictCode})})}export{C as ControlledAddressField};
|
|
@@ -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{DateFieldComponent as p}from"../../form/fields";import{convertValidationRules as C}from"../types";function h(a){const{control:n,errors:t,fieldConfig:i,t:m}=a,{name:e,label:d,validation:o,type:s}=i,u={date:"date","datetime-local":"datetime-local",month:"month",time:"time",week:"week"}[s]||"date";return l(f,{name:e,control:n,rules:o?C(o):void 0,render:({field:r})=>l(p,{...r,label:m(d),value:r.value??null,onChange:c=>r.onChange(c),error:!!t[e],helperText:t[e]?.message,required:o?.required,mode:u})})}export{h as ControlledDateField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as l}from"react/jsx-runtime";import{Controller as c}from"react-hook-form";import{GeoPointFieldComponent as f}from"../../form/fields";import{convertValidationRules as p}from"../types";function C(a){const{control:i,errors:t,fieldConfig:s,t:m}=a,{name:o,label:d,validation:n}=s;return l(c,{name:o,control:i,rules:n?p(n):void 0,render:({field:e})=>{const g=r=>{if("target"in r)try{const u=JSON.parse(r.target.value);e.onChange(u)}catch{e.onChange({lat:0,lng:0})}else e.onChange(r||{lat:0,lng:0})};return l(f,{label:m(d),value:e.value||{lat:0,lng:0},onChange:g,error:!!t[o],helperText:t[o]?.message,required:n?.required})}})}export{C 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 p}from"react-hook-form";import{MapFieldComponent as f}from"../../form/fields";import{convertValidationRules as g}from"../types";function C(l){const{control:i,errors:t,fieldConfig:s,t:m}=l,{name:r,label:d,validation:o}=s;return a(p,{name:r,control:i,rules:o?g(o):void 0,render:({field:e})=>{const u=n=>{if("target"in n)try{const c=JSON.parse(n.target.value);e.onChange(c)}catch{e.onChange({})}else e.onChange(n||{})};return a(f,{label:m(d),value:e.value||{},onChange:u,error:!!t[r],helperText:t[r]?.message,required:o?.required})}})}export{C 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 p}from"react-hook-form";import{MultiInputTextFieldComponent as f}from"../../form/fields";import{convertValidationRules as C}from"../types";function g(n){const{control:l,errors:v,fieldConfig:i,t:s}=n,{name:u,label:m,validation:r,options:c={}}=i;return t(p,{name:u,control:l,rules:r?C(r):void 0,render:({field:e})=>{const d=o=>{if(Array.isArray(o))e.onChange(o);else try{const a=JSON.parse(o.target.value);e.onChange(Array.isArray(a)?a:[])}catch{e.onChange([])}};return t(f,{label:s(m),value:Array.isArray(e.value)?e.value:[],onChange:d,required:r?.required,className:c.className})}})}export{g 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 f}from"../../form/fields";import{convertValidationRules as h}from"../types";function C(n){const{control:i,errors:r,fieldConfig:s,t:m,placeholder:c}=n,{name:e,label:d,validation:o,options:l={}}=s;return t(u,{name:e,control:i,rules:o?h(o):void 0,render:({field:a})=>t(f,{label:m(d),value:a.value??"",onChange:p=>a.onChange(p),error:r[e]?.message,helperText:r[e]?.message,required:o?.required,placeholder:c||l.placeholder,className:l.className})})}export{C as ControlledRichTextField};
|
|
@@ -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{TimestampFieldComponent as u}from"../../form/fields";import{convertValidationRules as f}from"../types";function c(t){const{control:a,errors:l,fieldConfig:i,t:m}=t,{name:e,label:s,validation:r}=i;return n(p,{name:e,control:a,rules:r?f(r):void 0,render:({field:o})=>n(u,{...o,label:m(s),value:o.value??null,onChange:d=>o.onChange(d),error:!!l[e],helperText:l[e]?.message,required:r?.required})})}export{c as ControlledTimestampField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ControlledAddressField as
|
|
1
|
+
import{ControlledAddressField as o}from"./ControlledAddressField";import{ControlledDateField as l}from"./ControlledDateField";import{ControlledGeoPointField as e}from"./ControlledGeoPointField";import{ControlledMapField as t}from"./ControlledMapField";import{ControlledMultiInputField as d}from"./ControlledMultiInputField";import{ControlledRichTextField as r}from"./ControlledRichTextField";import{ControlledTimestampField as i}from"./ControlledTimestampField";export{o as ControlledAddressField,l as ControlledDateField,e as ControlledGeoPointField,t as ControlledMapField,d as ControlledMultiInputField,r as ControlledRichTextField,i as ControlledTimestampField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as l}from"react/jsx-runtime";import{Controller as p}from"react-hook-form";import{DocumentFieldComponent as f}from"../../form/fields";import{convertValidationRules as c}from"../types";function g(i){const{control:m,errors:r,fieldConfig:n,t:s}=i,{name:e,label:u,validation:o}=n,t=n.options||{};return l(p,{name:e,control:m,rules:o?c(o):void 0,render:({field:a})=>l(f,{name:e,label:s(u),value:a.value??null,onChange:d=>a.onChange(d),error:!!r[e],helperText:r[e]?.message,required:o?.required,multiple:!1,maxFiles:1,maxSize:t.maxSize,storagePath:t.storagePath})})}export{g as ControlledDocumentField};
|
|
@@ -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{FileFieldComponent as f}from"../../form/fields";import{convertValidationRules as c}from"../types";function g(t){const{control:m,errors:r,fieldConfig:l,t:s}=t,{name:e,label:u,validation:o}=l,a=l.options||{};return n(p,{name:e,control:m,rules:o?c(o):void 0,render:({field:i})=>n(f,{name:e,label:s(u),value:i.value??null,onChange:d=>i.onChange(d),error:!!r[e],helperText:r[e]?.message,required:o?.required,multiple:!1,maxFiles:1,maxSize:a.maxSize,storagePath:a.storagePath})})}export{g as ControlledFileField};
|
|
@@ -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{ImageFieldComponent as f}from"../../form/fields";import{convertValidationRules as g}from"../types";function c(i){const{control:m,errors:r,fieldConfig:a,t:s}=i,{name:e,label:u,validation:o}=a,l=a.options||{};return t(p,{name:e,control:m,rules:o?g(o):void 0,render:({field:n})=>t(f,{name:e,label:s(u),value:n.value??null,onChange:d=>n.onChange(d),error:!!r[e],helperText:r[e]?.message,required:o?.required,multiple:!1,maxFiles:1,maxSize:l.maxSize,storagePath:l.storagePath})})}export{c as ControlledImageField};
|
|
@@ -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{DocumentFieldComponent as v}from"../../form/fields";import{convertValidationRules as f}from"../types";function x(i){const{control:m,errors:l,fieldConfig:t,t:s}=i,{name:r,label:u,validation:o}=t,a=t.options||{};return n(p,{name:r,control:m,rules:o?f(o):void 0,render:({field:e})=>{const d=Array.isArray(e.value)?e.value:e.value?[e.value]:null;return n(v,{name:r,label:s(u),value:d,onChange:c=>e.onChange(c),error:!!l[r],helperText:l[r]?.message,required:o?.required,multiple:!0,maxFiles:a.maxFiles??10,maxSize:a.maxSize,storagePath:a.storagePath})}})}export{x as ControlledMultiDocumentField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as i}from"react/jsx-runtime";import{Controller as f}from"react-hook-form";import{FileFieldComponent as v}from"../../form/fields";import{convertValidationRules as x}from"../types";function c(n){const{control:s,errors:a,fieldConfig:t,t:m}=n,{name:r,label:u,validation:o}=t,l=t.options||{};return i(f,{name:r,control:s,rules:o?x(o):void 0,render:({field:e})=>{const d=Array.isArray(e.value)?e.value:e.value?[e.value]:null;return i(v,{name:r,label:m(u),value:d,onChange:p=>e.onChange(p),error:!!a[r],helperText:a[r]?.message,required:o?.required,multiple:!0,maxFiles:l.maxFiles??10,maxSize:l.maxSize,storagePath:l.storagePath})}})}export{c as ControlledMultiFileField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as n}from"react/jsx-runtime";import{Controller as g}from"react-hook-form";import{ImageFieldComponent as f}from"../../form/fields";import{convertValidationRules as v}from"../types";function x(i){const{control:m,errors:l,fieldConfig:t,t:s}=i,{name:r,label:u,validation:o}=t,a=t.options||{};return n(g,{name:r,control:m,rules:o?v(o):void 0,render:({field:e})=>{const d=Array.isArray(e.value)?e.value:e.value?[e.value]:null;return n(f,{name:r,label:s(u),value:d,onChange:p=>e.onChange(p),error:!!l[r],helperText:l[r]?.message,required:o?.required,multiple:!0,maxFiles:a.maxFiles??10,maxSize:a.maxSize,storagePath:a.storagePath})}})}export{x as ControlledMultiImageField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ControlledDocumentField as l}from"./ControlledDocumentField";import{ControlledFileField as
|
|
1
|
+
import{ControlledDocumentField as l}from"./ControlledDocumentField";import{ControlledFileField as o}from"./ControlledFileField";import{ControlledImageField as e}from"./ControlledImageField";import{ControlledMultiDocumentField as t}from"./ControlledMultiDocumentField";import{ControlledMultiFileField as i}from"./ControlledMultiFileField";import{ControlledMultiImageField as r}from"./ControlledMultiImageField";export{l as ControlledDocumentField,o as ControlledFileField,e as ControlledImageField,t as ControlledMultiDocumentField,i as ControlledMultiFileField,r as ControlledMultiImageField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{convertValidationRules as
|
|
1
|
+
import{convertValidationRules as o,convertPatternToRegex as e}from"./types";export*from"./input";export*from"./select";export*from"./file";export*from"./complex";export{e as convertPatternToRegex,o as convertValidationRules};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as n}from"react/jsx-runtime";import{Controller as m}from"react-hook-form";import{CheckboxFieldComponent as f}from"../../form/fields";import{convertValidationRules as u}from"../types";function C(t){const{control:l,errors:p,fieldConfig:i,t:a}=t,{name:d,label:e,validation:o}=i,c=typeof e=="string"?a(e):e;return n(m,{name:d,control:l,rules:o?u(o):void 0,render:({field:r})=>n(f,{label:c,checked:!!r.value,onChange:s=>r.onChange(s.target.checked),required:o?.required})})}export{C as ControlledCheckboxField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as u}from"react/jsx-runtime";import{Controller as g}from"react-hook-form";import{CurrencyFieldComponent as h}from"../../form/fields";import{convertValidationRules as y}from"../types";function N(c){const{control:s,errors:n,fieldConfig:a,t:d,placeholder:m}=c,{name:o,label:p,validation:l}=a,t=(a.options||{}).fieldSpecific;return u(g,{name:o,control:s,rules:l?y(l):void 0,render:({field:e})=>{const f=v=>{const r=v.target.value;if(r==null||r===""){e.onChange(null);return}const i=typeof r=="number"?r/100:parseFloat(String(r))/100;isNaN(i)?e.onChange(null):e.onChange(i)},C=e.value!=null&&!isNaN(e.value)?Math.round(e.value*100):void 0;return u(h,{label:d(p),value:C,onChange:f,currency:t?.currency||"EUR",locale:t?.locale,error:!!n[o],helperText:n[o]?.message,required:l?.required,placeholder:m})}})}export{N as ControlledCurrencyField};
|
|
@@ -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{DurationFieldComponent as p}from"../../form/fields";import{convertValidationRules as c}from"../types";function C(s){const{control:d,errors:n,fieldConfig:l,t}=s,{name:e,label:m,validation:o}=l,r=(l.options||{}).fieldSpecific;return a(f,{name:e,control:d,rules:o?c(o):void 0,render:({field:i})=>a(p,{label:t(m),value:i.value??0,onChange:u=>i.onChange(u),error:!!n[e],helperText:n[e]?.message,required:o?.required,disabled:i.disabled,min:r?.min??0,max:r?.max??480,step:r?.step??5,t})})}export{C as ControlledDurationField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as o}from"react/jsx-runtime";import{Controller as C}from"react-hook-form";import{GdprConsentFieldComponent as u}from"../../form/fields";import{convertValidationRules as h}from"../types";function v(i){const{control:a,errors:y,fieldConfig:l}=i,{name:s,validation:n,options:d={}}=l,r=d.fieldSpecific,c=r?.privacyPolicyPath||"/legal/privacy",p=r?.termsPath||"/legal/terms";return o(C,{name:s,control:a,rules:n?h(n):void 0,render:({field:t})=>{const e=t.value,m=typeof e=="object"&&e!==null?!!e.gdprConsent:!!e;return o(u,{checked:m,onChange:g=>{if(g.target.checked){const f=new Date().toISOString().split("T")[0];t.onChange({gdprConsent:!0,gdprConsentDate:new Date().toISOString(),gdprConsentVersion:f})}else t.onChange(!1)},required:n?.required,privacyPolicyPath:c,termsPath:p})}})}export{v as ControlledGdprConsentField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as m}from"react/jsx-runtime";import{Controller as g}from"react-hook-form";import{NumberFieldComponent as
|
|
1
|
+
"use client";import{jsx as m}from"react/jsx-runtime";import{Controller as g}from"react-hook-form";import{NumberFieldComponent as v}from"../../form/fields";import{convertValidationRules as C}from"../types";function h(u){const{control:c,errors:t,fieldConfig:n,t:d,placeholder:N}=u,{name:o,label:p,validation:e}=n,i=n.options||{},a=i.fieldSpecific;return m(g,{name:o,control:c,rules:e?C(e):void 0,render:({field:r})=>{const f=l=>{if(l.target.value===""||l.target.value===null){r.onChange(null);return}try{const s=parseFloat(l.target.value);isNaN(s)||r.onChange(s)}catch{r.onChange(0)}};return m(v,{...r,label:d(p),value:r.value??void 0,onChange:f,error:!!t[o],helperText:t[o]?.message,required:e?.required,min:e?.min,max:e?.max,step:a?.mask==="currency"?.01:a?.mask==="mileage"?1:void 0,mask:a?.mask||"number",className:i.className})}})}export{h as ControlledNumberField};
|
|
@@ -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{PasswordFieldComponent as u}from"../../form/fields";import{convertValidationRules as f}from"../types";function h(s){const{control:i,errors:l,fieldConfig:t,t:d,placeholder:m}=s,{name:e,label:c,validation:o,options:a={}}=t;return n(p,{name:e,control:i,rules:o?f(o):void 0,render:({field:r})=>n(u,{...r,label:d(c),value:r.value??"",onChange:r.onChange,error:!!l[e],helperText:l[e]?.message,required:o?.required,placeholder:m||a.placeholder,className:a.className})})}export{h as ControlledPasswordField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as t}from"react/jsx-runtime";import{Controller as d}from"react-hook-form";import{PhoneNumberComponent as
|
|
1
|
+
"use client";import{jsx as t}from"react/jsx-runtime";import{Controller as d}from"react-hook-form";import{PhoneNumberComponent as f}from"../../form/fields";import{convertValidationRules as p}from"../types";function c(a){const{control:l,errors:n,fieldConfig:i,t:s}=a,{name:e,label:m,validation:r}=i;return t(d,{name:e,control:l,rules:r?p(r):void 0,render:({field:o})=>t(f,{label:s(m),value:typeof o.value=="string"?o.value:"",onChange:u=>o.onChange(u.target.value||""),error:n[e]?.message,helperText:n[e]?.message,required:r?.required})})}export{c as ControlledPhoneField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as t}from"react/jsx-runtime";import{Controller as C}from"react-hook-form";import{PriceFieldComponent as h}from"../../form/fields";import{convertValidationRules as v}from"../types";function g(a){const{control:s,errors:i,fieldConfig:l,t:c,placeholder:d}=a,{name:e,label:u,validation:r}=l,o=(l.options||{}).fieldSpecific;return t(C,{name:e,control:s,rules:r?v(r):void 0,render:({field:n})=>{const p=n.value,f=m=>{n.onChange(m)};return t(h,{label:c(u),value:p??void 0,onChange:f,error:!!i[e],helperText:i[e]?.message,required:r?.required,placeholder:d,defaultCurrency:o?.defaultCurrency??"EUR",optionsTitle:o?.optionsTitle,currencies:o?.currencies})}})}export{g as ControlledPriceField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as t}from"react/jsx-runtime";import{Controller as f}from"react-hook-form";import{RangeFieldComponent as c}from"../../form/fields";import{convertValidationRules as g}from"../types";function v(m){const{control:s,errors:n,fieldConfig:l,t:u}=m,{name:o,label:d,validation:e}=l,i=l.options||{},p=i.fieldSpecific;return t(f,{name:o,control:s,rules:e?g(e):void 0,render:({field:r})=>t(c,{label:u(d),value:r.value??void 0,onChange:a=>{typeof a=="number"?r.onChange(a):r.onChange(Number(a.target.value)||0)},error:!!n[o],helperText:n[o]?.message,required:e?.required,min:e?.min,max:e?.max,step:i.step,showValue:p?.showValue})})}export{v as ControlledRangeField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as i}from"react/jsx-runtime";import{Controller as f}from"react-hook-form";import{RatingFieldComponent as p}from"../../form/fields";import{convertValidationRules as c}from"../types";function g(t){const{control:s,errors:r,fieldConfig:l,t:m}=t,{name:o,label:d,validation:e}=l,n=(l.options||{}).fieldSpecific;return i(f,{name:o,control:s,rules:e?c(e):void 0,render:({field:a})=>i(p,{label:m(d),value:a.value??0,onChange:u=>{a.onChange(u)},error:!!r[o],helperText:r[o]?.message,required:e?.required,max:n?.max??e?.max??5,showValue:n?.showValue})})}export{g as ControlledRatingField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as d}from"react/jsx-runtime";import{Controller as x}from"react-hook-form";import{SwitchFieldComponent as v}from"../../form/fields";import"../types";function S(h){const{control:s,errors:m,fieldConfig:u,t:o,onChange:n}=h,{name:l,label:f,options:p={}}=u,e=p.fieldSpecific,k=e?.uncheckedValue??!1,r=e?.checkedValue??!0,t=e?.uncheckedLabel,a=e?.checkedLabel;return d(x,{name:l,control:s,render:({field:{value:g,onChange:C}})=>{const b=g===r,L=c=>{const i=c?r:k;C(i),n&&n(i)};return d(v,{label:o(f),checked:b,onChange:c=>L(c.target.checked),uncheckedLabel:t?o(t):void 0,checkedLabel:a?o(a):void 0,helperText:m[l]?.message})}})}export{S as ControlledSwitchField};
|