@donotdev/crud 0.0.18 → 0.0.20
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.d.ts.map +1 -1
- package/dist/CrudService.js +1 -1
- package/dist/components/CrudButton.d.ts.map +1 -1
- package/dist/components/DateFilter.js +1 -1
- package/dist/components/DisplayFieldRenderer.d.ts +2 -4
- package/dist/components/DisplayFieldRenderer.d.ts.map +1 -1
- package/dist/components/EntityFilters.d.ts.map +1 -1
- package/dist/components/EntityFilters.js +1 -1
- package/dist/components/FormLayout.js +1 -1
- package/dist/components/controlled/select/ControlledReferenceField.d.ts +20 -0
- package/dist/components/controlled/select/ControlledReferenceField.d.ts.map +1 -0
- package/dist/components/controlled/select/ControlledReferenceField.js +1 -0
- package/dist/components/controlled/select/index.d.ts +1 -0
- package/dist/components/controlled/select/index.d.ts.map +1 -1
- package/dist/components/controlled/select/index.js +1 -1
- package/dist/components/form/fields/AddressFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/AddressFieldComponent.js +1 -1
- package/dist/components/form/fields/DocumentFieldComponent.js +1 -1
- package/dist/components/form/fields/DropdownComponent.js +1 -1
- package/dist/components/form/fields/FileFieldComponent.js +1 -1
- package/dist/components/form/fields/MapFieldComponent.js +1 -1
- package/dist/components/form/fields/MultiDropdownComponent.d.ts.map +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/SwitchFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/SwitchFieldComponent.js +1 -1
- package/dist/fieldTypeRegistry.d.ts +3 -1
- package/dist/fieldTypeRegistry.d.ts.map +1 -1
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/useFieldConditions.d.ts +27 -0
- package/dist/hooks/useFieldConditions.d.ts.map +1 -0
- package/dist/hooks/useFieldConditions.js +1 -0
- package/dist/hooks/useReferenceResolver.d.ts +15 -0
- package/dist/hooks/useReferenceResolver.d.ts.map +1 -0
- package/dist/hooks/useReferenceResolver.js +1 -0
- package/dist/index.d.ts +5 -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/registerBuiltinFieldTypes.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/useCrudCardList.d.ts.map +1 -1
- package/dist/utils/imageProcessing.d.ts +1 -3
- package/dist/utils/imageProcessing.d.ts.map +1 -1
- package/dist/utils/imageProcessing.js +1 -1
- package/dist/utils/matchesFilter.d.ts.map +1 -1
- package/dist/utils/matchesFilter.js +1 -1
- package/dist/workflows/WorkflowPersistence.d.ts +31 -0
- package/dist/workflows/WorkflowPersistence.d.ts.map +1 -0
- package/dist/workflows/WorkflowPersistence.js +1 -0
- package/dist/workflows/defineWorkflow.d.ts +92 -0
- package/dist/workflows/defineWorkflow.d.ts.map +1 -0
- package/dist/workflows/defineWorkflow.js +1 -0
- package/dist/workflows/index.d.ts +15 -0
- package/dist/workflows/index.d.ts.map +1 -0
- package/dist/workflows/index.js +1 -0
- package/dist/workflows/useEntityWorkflow.d.ts +54 -0
- package/dist/workflows/useEntityWorkflow.d.ts.map +1 -0
- package/dist/workflows/useEntityWorkflow.js +1 -0
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CrudService.d.ts","sourceRoot":"","sources":["../src/CrudService.ts"],"names":[],"mappings":"AAwDA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EAEX,YAAY,EACZ,oBAAoB,EACpB,cAAc,EACd,eAAe,EAChB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,KAAK,EAGV,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,eAAe,EAEhB,MAAM,SAAS,CAAC;AAUjB,YAAY,EAAE,YAAY,EAAE,CAAC;AAQ7B;;;;;;GAMG;AACH,cAAM,WAAY,YAAW,oBAAoB;IAC/C,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,KAAK,CAA6B;IAC1C,oFAAoF;IACpF,OAAO,CAAC,QAAQ,CAAgC;IAChD;;;;OAIG;IACH,OAAO,CAAC,aAAa,CAAuB;IAM5C;;;;;OAKG;IACH,OAAO,CAAC,uBAAuB;IAW/B,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAInC;;;;;;;;;OASG;IACH,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;IAI5C;;;;;;;;;;OAUG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAI3C;;;OAGG;IACH,OAAO,CAAC,aAAa;IAMrB;;;OAGG;IACH,OAAO,CAAC,UAAU;IAelB;;;;;;;;;OASG;IACH,OAAO,CAAC,aAAa;IAMrB,4DAA4D;YAC9C,cAAc;IAK5B;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAsBxB;;;;;OAKG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IA4BjC;;;OAGG;IACH,cAAc,IAAI,WAAW;IAI7B;;;;OAIG;IACH,mBAAmB,CAAC,CAAC,EACnB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,EAC5B,YAAY,CAAC,EAAE,YAAY,EAC3B,UAAU,GAAE,cAAsC;;uBAa7B,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;;;IAcvD;;;;OAIG;IACH,kBAAkB,CAAC,CAAC,EAClB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,EAC5B,YAAY,CAAC,EAAE,YAAY;;uBAON,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;;;IASxC;;;OAGG;IACH,OAAO,CAAC,eAAe;IA4BvB;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAkHzB;;;;;OAKG;IACH,OAAO,CAAC,yBAAyB;IAgFjC;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IAgB7B;;OAEG;IACG,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWvD,GAAG,CAAC,CAAC,EACT,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IA0CpB,sDAAsD;YACxC,eAAe;
|
|
1
|
+
{"version":3,"file":"CrudService.d.ts","sourceRoot":"","sources":["../src/CrudService.ts"],"names":[],"mappings":"AAwDA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EAEX,YAAY,EACZ,oBAAoB,EACpB,cAAc,EACd,eAAe,EAChB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,KAAK,EAGV,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,eAAe,EAEhB,MAAM,SAAS,CAAC;AAUjB,YAAY,EAAE,YAAY,EAAE,CAAC;AAQ7B;;;;;;GAMG;AACH,cAAM,WAAY,YAAW,oBAAoB;IAC/C,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,KAAK,CAA6B;IAC1C,oFAAoF;IACpF,OAAO,CAAC,QAAQ,CAAgC;IAChD;;;;OAIG;IACH,OAAO,CAAC,aAAa,CAAuB;IAM5C;;;;;OAKG;IACH,OAAO,CAAC,uBAAuB;IAW/B,QAAQ,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAInC;;;;;;;;;OASG;IACH,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;IAI5C;;;;;;;;;;OAUG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAI3C;;;OAGG;IACH,OAAO,CAAC,aAAa;IAMrB;;;OAGG;IACH,OAAO,CAAC,UAAU;IAelB;;;;;;;;;OASG;IACH,OAAO,CAAC,aAAa;IAMrB,4DAA4D;YAC9C,cAAc;IAK5B;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAsBxB;;;;;OAKG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IA4BjC;;;OAGG;IACH,cAAc,IAAI,WAAW;IAI7B;;;;OAIG;IACH,mBAAmB,CAAC,CAAC,EACnB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,EAC5B,YAAY,CAAC,EAAE,YAAY,EAC3B,UAAU,GAAE,cAAsC;;uBAa7B,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;;;IAcvD;;;;OAIG;IACH,kBAAkB,CAAC,CAAC,EAClB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,EAC5B,YAAY,CAAC,EAAE,YAAY;;uBAON,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;;;IASxC;;;OAGG;IACH,OAAO,CAAC,eAAe;IA4BvB;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAkHzB;;;;;OAKG;IACH,OAAO,CAAC,yBAAyB;IAgFjC;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IAgB7B;;OAEG;IACG,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWvD,GAAG,CAAC,CAAC,EACT,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,OAAO,CAAC,EAAE,YAAY,GACrB,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IA0CpB,sDAAsD;YACxC,eAAe;IAgDvB,KAAK,CAAC,CAAC,EACX,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,YAAY,CAAC,EAAE,YAAY,EAC3B,UAAU,GAAE,cAAsC,GACjD,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IAyDnC,sDAAsD;YACxC,iBAAiB;IA6D/B;;;;OAIG;IACH,OAAO,CAAC,cAAc;IAqChB,GAAG,CAAC,CAAC,EACT,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,CAAC,EACP,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,IAAI,CAAC;IAiGV,MAAM,CAAC,CAAC,EACZ,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,EACvB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,IAAI,CAAC;IAmHV,MAAM,CACV,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,IAAI,CAAC;IA0FV,GAAG,CAAC,CAAC,EACT,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,CAAC,EACP,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,MAAM,CAAC;IAgHlB,SAAS,CAAC,CAAC,EACT,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,EACjD,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GACrB,MAAM,IAAI;IA+Bb,2EAA2E;IAC3E,OAAO,CAAC,cAAc;IAqCtB,qBAAqB,CAAC,CAAC,EACrB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,EAC5C,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GACrB,MAAM,IAAI;IAkCb,uFAAuF;IACvF,OAAO,CAAC,0BAA0B;IA2C5B,aAAa,CAAC,CAAC,SAAS;QAAE,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,EAC3C,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,CAAC,EACP,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,CAAC,GAAG;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAsFxB,gBAAgB,CAAC,CAAC,EACtB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAChB,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EACtB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,CAAC,CAAC;IA4FP,gBAAgB,CACpB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,IAAI,CAAC;CA6EjB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,mBAE1B,CAAC"}
|
package/dist/CrudService.js
CHANGED
|
@@ -6,4 +6,4 @@ Examples:
|
|
|
6
6
|
|
|
7
7
|
configureProviders({ crud: new FirestoreAdapter() }) // Firebase direct
|
|
8
8
|
configureProviders({ crud: new FunctionsAdapter() }) // via callable functions
|
|
9
|
-
configureProviders({ crud: new SupabaseCrudAdapter(sb) }) // Supabase direct (RLS)`);this.adapter=T("crud"),this.store&&this.store.getState().setCrudService(this)}}getQueryClient(){return L()}getListQueryOptions(t,e,s,i,a=_.LIST){const r=this.adapter,u=()=>this._ensureAdapter();return{queryKey:["crud",t,"query",JSON.stringify(e)],queryFn:async()=>{if(r||await u(),!this.adapter)throw new Error("Adapter not initialized");return this.adapter.query(t,e,s,a)},staleTime:i?.staleTime??S}}getDocQueryOptions(t,e,s,i){const a=this.adapter,r=()=>this._ensureAdapter();return{queryKey:["crud",t,"get",e],queryFn:async()=>{if(a||await r(),!this.adapter)throw new Error("Adapter not initialized");return this.adapter.get(t,e,s)},staleTime:i?.staleTime??S}}_updateGetCache(t,e,s,i){const a=this.getQueryClient(),r=["crud",t,"get",e];i===y.DELETE?a.removeQueries({queryKey:r}):i===y.SET&&s?a.setQueryData(r,s):(i===y.UPDATE||i===y.ADD)&&s&&a.setQueryData(r,u=>u?{...u,...s}:s)}_updateListCaches(t,e,s,i){const a=this.getQueryClient();this._updateGetCache(t,e,s,i),a.setQueriesData({queryKey:["crud",t]},r=>{if(r&&typeof r=="object"&&"items"in r){const u=r;let h=u.items;return i===y.DELETE?(h=u.items.filter(d=>d!=null&&typeof d=="object"&&d.id!==e),{...u,items:h,total:Math.max(0,(u.total??h.length)-1)}):i===y.ADD&&s?(h=[...u.items,{...s,id:e}],{...u,items:h,total:(u.total??u.items.length)+1}):(i===y.UPDATE||i===y.SET)&&s&&u.items.some(n=>n!=null&&typeof n=="object"&&n.id===e)?(h=u.items.map(n=>n==null||typeof n!="object"||n.id!==e?n:i===y.SET?{...s,id:e}:{...n,...s}),{...u,items:h}):r}if(Array.isArray(r)){if(i===y.DELETE)return r.filter(u=>u.id!==e);if(i===y.ADD&&s)return[...r,{...s,id:e}];if((i===y.UPDATE||i===y.SET)&&s)return r.some(h=>h!=null&&typeof h=="object"&&h.id===e)?r.map(h=>h==null||typeof h!="object"||h.id!==e?h:i===y.SET?{...s,id:e}:{...h,...s}):r}return r})}_checkUniquenessFromCache(t,e,s){const a=s.metadata?.uniqueKeys;if(!a||a.length===0)return null;const u=this.getQueryClient().getQueriesData({queryKey:["crud",t]}),h=[];for(const[,n]of u)n&&typeof n=="object"&&"items"in n?h.push(...n.items):Array.isArray(n)&&h.push(...n);if(h.length===0)return null;const d=e;for(const n of a){if(!n.fields.every(p=>d[p]!=null&&d[p]!==""))continue;const g=h.find(p=>n.fields.every(w=>{const C=typeof d[w]=="string"?d[w].toLowerCase():d[w],E=typeof p[w]=="string"?p[w].toLowerCase():p[w];return C===E}));if(g){if(n.findOrCreate)return g.id;const p=n.fields.join(" + ");throw f(new Error(n.errorMessage||`Duplicate ${p}`),{userMessage:n.errorMessage||`A record with this ${p} already exists`,showNotification:!0})}}return null}_getItemFromListCache(t,e){const i=this.getQueryClient().getQueriesData({queryKey:["crud",t]});for(const[,a]of i)if(a?.items){const r=a.items.find(u=>u.id===e);if(r)return r}return null}async invalidateCollection(t){await this.getQueryClient().invalidateQueries({queryKey:["crud",t]})}async get(t,e,s,i){if(await this._ensureAdapter(),i?.noCache)return this._getFromAdapter(t,e,s);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,s,!1),staleTime:i?.staleTime??S})}catch(a){const r=f(a,{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,s,i=!0){this.store&&i&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{if(!this.adapter)throw new Error("Adapter not initialized");return this._assertCanAccess(t,s),await this.adapter.get(t,e,s)}catch(a){const r=f(a,{userMessage:`Failed to fetch ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,r),r}finally{this.store&&i&&this.store.getState().setLoading(t,!1)}}async query(t,e,s,i,a=_.LIST){if(await this._ensureAdapter(),i?.noCache)return this._queryFromAdapter(t,e,s,!0,a);this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{return await this.getQueryClient().fetchQuery({queryKey:["crud",t,"query",JSON.stringify(e)],queryFn:()=>this._queryFromAdapter(t,e,s,!1,a),staleTime:i?.staleTime??S})}catch(r){const u=f(r,{userMessage:`Failed to query ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,u),u}finally{this.store&&this.store.getState().setLoading(t,!1)}}async _queryFromAdapter(t,e,s,i=!0,a=_.LIST){this.store&&i&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{if(!this.adapter)throw new Error("Adapter not initialized");return this._assertCanAccess(t,s),await this.adapter.query(t,e,s,a)}catch(r){const u=f(r,{userMessage:`Failed to query ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,u),u}finally{this.store&&i&&this.store.getState().setLoading(t,!1)}}_getEntityName(t){const e=c();let s=`entity-${t}`,i=e.t("name",{ns:s,defaultValue:null});return i&&i!=="name"&&i!==`${s}:name`||t.endsWith("s")&&t.length>1&&(s=`entity-${t.slice(0,-1)}`,i=e.t("name",{ns:s,defaultValue:null}),i&&i!=="name"&&i!==`${s}:name`)?i:t}async set(t,e,s,i,a){await this._ensureAdapter(),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const u=this.getQueryClient().getQueryData(["crud",t,"get",e])??null;this.store&&this.store.getState().updateOptimistic(t,e,s,u);try{if(!this.adapter)throw new Error("Adapter not initialized");this._assertCanAccess(t,i),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const h=this._getPiiFields(i),d=h.length>0&&this.security?this.security.encryptPii(s,h):s;if(await this.adapter.set(t,e,d,i),this._updateListCaches(t,e,s,y.SET),this.store&&this.store.getState().confirmUpdate(t,e),this._auditCrud("crud.update",t,e),this._shouldShowSuccessToast(a)){const n=c(),o=this._getEntityName(t);m("success",n.t("messages.updateSuccess",{ns:"crud",entity:o}))}}catch(h){u&&this._updateListCaches(t,e,u,y.SET),this.store&&this.store.getState().rejectUpdate(t,e);const d=f(h,{userMessage:`Failed to save ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,d),d}finally{this.store&&this.store.getState().setLoading(t,!1)}}async update(t,e,s,i,a){await this._ensureAdapter(),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const u=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e),h=u?{...u,...s}:{...s,id:e};this.store&&this.store.getState().updateOptimistic(t,e,h,u??null);try{if(!this.adapter)throw new Error("Adapter not initialized");i&&this._assertCanAccess(t,i),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const d=i?this._getPiiFields(i):[],n=d.length>0&&this.security?this.security.encryptPii(s,d):s;if(await this.adapter.update(t,e,n),this._updateListCaches(t,e,h,y.UPDATE),this.store&&this.store.getState().confirmUpdate(t,e),this._auditCrud("crud.update",t,e),this._shouldShowSuccessToast(a)){const o=c(),g=this._getEntityName(t);m("success",o.t("messages.updateSuccess",{ns:"crud",entity:g}))}}catch(d){u?this._updateListCaches(t,e,u,y.UPDATE):this.invalidateCollection(t),this.store&&this.store.getState().rejectUpdate(t,e);const n=f(d,{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,s){await this._ensureAdapter(),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(this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write"),await this.adapter.delete(t,e),this._updateListCaches(t,e,null,y.DELETE),this.store&&this.store.getState().confirmDelete(t,e),this._auditCrud("crud.delete",t,e),this.security?.recordAnomaly?.("bulk.deletes",this.currentUserId??void 0),this._shouldShowSuccessToast(s)){const r=c(),u=this._getEntityName(t);m("success",r.t("messages.deleteSuccess",{ns:"crud",entity:u}))}}catch(r){a&&this._updateListCaches(t,e,a,y.ADD),this.store&&this.store.getState().rejectDelete(t,e);const u=f(r,{userMessage:`Failed to delete ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,u),u}finally{this.store&&this.store.getState().setLoading(t,!1)}}async add(t,e,s,i){await this._ensureAdapter();const a=this._checkUniquenessFromCache(t,e,s);if(a)return a;this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const r=`temp_${crypto.randomUUID()}`;this.store&&this.store.getState().addOptimistic(t,r,{...e,id:r});try{if(!this.adapter)throw new Error("Adapter not initialized");this._assertCanAccess(t,s),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const u=this._getPiiFields(s),h=u.length>0&&this.security?this.security.encryptPii(e,u):e,d=await this.adapter.add(t,h,s),n=d.id,o=d.data;if(this._updateListCaches(t,r,null,y.DELETE),this._updateListCaches(t,n,o,y.ADD),this.store&&this.store.getState().confirmOptimistic(t,r,n,o),this._auditCrud("crud.create",t,n),this._shouldShowSuccessToast(i)){const g=c(),p=this._getEntityName(t);m("success",g.t("messages.createSuccess",{ns:"crud",entity:p}))}return n}catch(u){this._updateListCaches(t,r,null,y.DELETE),this.store&&this.store.getState().rejectOptimistic(t,r);const h=f(u,{userMessage:`Failed to create ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,h),h}finally{this.store&&this.store.getState().setLoading(t,!1)}}subscribe(t,e,s,i){if(!this.adapter){let a=!1,r=null;return this._ensureAdapter().then(()=>{a||(r=this._subscribeSync(t,e,s,i))}).catch(u=>{a||s(null,f(u))}),()=>{a=!0,r?.()}}return this._subscribeSync(t,e,s,i)}_subscribeSync(t,e,s,i){try{const a=this.adapter;return a?a.subscribe?(this._assertCanAccess(t,i),a.subscribe(t,e,(r,u)=>{r&&this.getQueryClient().setQueryData(["crud",t,"get",e],r),s(r,u)},i)):()=>{}:(s(null,new Error("Adapter not initialized")),()=>{})}catch(a){return s(null,f(a)),()=>{}}}subscribeToCollection(t,e,s,i){if(!this.adapter){let a=!1,r=null;return this._ensureAdapter().then(()=>{a||(r=this._subscribeToCollectionSync(t,e,s,i))}).catch(u=>{a||s([],f(u))}),()=>{a=!0,r?.()}}return this._subscribeToCollectionSync(t,e,s,i)}_subscribeToCollectionSync(t,e,s,i){try{const a=this.adapter;return a?a.subscribeToCollection?(this._assertCanAccess(t,i),a.subscribeToCollection(t,e,(r,u)=>{r&&this.getQueryClient().setQueryData(["crud",t,"query",JSON.stringify(e)],h=>h?{...h,items:r}:{items:r}),s(r,u)},i)):()=>{}:(s([],new Error("Adapter not initialized")),()=>{})}catch(a){return s([],f(a)),()=>{}}}async addOptimistic(t,e,s,i){await this._ensureAdapter();const a=this._checkUniquenessFromCache(t,e,s);if(a)return{...e,id:a};this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const r=`temp_${crypto.randomUUID()}`,u={...e,id:r,_optimistic:!0};this.store&&this.store.getState().addOptimistic(t,r,u);try{if(!this.adapter)throw new Error("Adapter not initialized");const h=await this.adapter.add(t,e,s),d=h.id,n=h.data;if(this._updateListCaches(t,r,null,y.DELETE),this._updateListCaches(t,d,n,y.ADD),this.store&&this.store.getState().confirmOptimistic(t,r,d,n),this._auditCrud("crud.create",t,d),this._shouldShowSuccessToast(i)){const o=c(),g=this._getEntityName(t);m("success",o.t("messages.createSuccess",{ns:"crud",entity:g}))}return n}catch(h){throw this._updateListCaches(t,r,null,y.DELETE),this.store&&this.store.getState().rejectOptimistic(t,r),f(h,{userMessage:`Failed to create ${t}`,showNotification:!0})}}async updateOptimistic(t,e,s,i,a){await this._ensureAdapter(),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const u=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e),h=u?{...u,...s,_optimistic:!0}:{...s,id:e,_optimistic:!0};this.store&&u&&this.store.getState().updateOptimistic(t,e,h,u);try{if(!this.adapter)throw new Error("Adapter not initialized");await this.adapter.update(t,e,s);const{_optimistic:d,...n}=h;if(this._updateListCaches(t,e,n,y.UPDATE),this.store&&this.store.getState().confirmUpdate(t,e),this._auditCrud("crud.update",t,e),this._shouldShowSuccessToast(a)){const o=c(),g=this._getEntityName(t);m("success",o.t("messages.updateSuccess",{ns:"crud",entity:g}))}return n}catch(d){throw u&&this._updateListCaches(t,e,u,y.UPDATE),this.store&&this.store.getState().rejectUpdate(t,e),f(d,{userMessage:`Failed to update ${t}`,showNotification:!0})}}async deleteOptimistic(t,e,s){await this._ensureAdapter(),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");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,y.DELETE),this.store&&this.store.getState().confirmDelete(t,e),this._auditCrud("crud.delete",t,e),this.security?.recordAnomaly?.("bulk.deletes",this.currentUserId??void 0),this._shouldShowSuccessToast(s)){const r=c(),u=this._getEntityName(t);m("success",r.t("messages.deleteSuccess",{ns:"crud",entity:u}))}}catch(r){throw a&&this._updateListCaches(t,e,a,y.ADD),this.store&&this.store.getState().rejectDelete(t,e),f(r,{userMessage:`Failed to delete ${t}`,showNotification:!0})}}}const O=A(()=>new F);export{O as getCrudService};
|
|
9
|
+
configureProviders({ crud: new SupabaseCrudAdapter(sb) }) // Supabase direct (RLS)`);this.adapter=T("crud"),this.store&&this.store.getState().setCrudService(this)}}getQueryClient(){return L()}getListQueryOptions(t,e,s,i,a=_.LIST){const r=this.adapter,u=()=>this._ensureAdapter();return{queryKey:["crud",t,"query",JSON.stringify(e)],queryFn:async()=>{if(r||await u(),!this.adapter)throw new Error("Adapter not initialized");return this.adapter.query(t,e,s,a)},staleTime:i?.staleTime??S}}getDocQueryOptions(t,e,s,i){const a=this.adapter,r=()=>this._ensureAdapter();return{queryKey:["crud",t,"get",e],queryFn:async()=>{if(a||await r(),!this.adapter)throw new Error("Adapter not initialized");return this.adapter.get(t,e,s)},staleTime:i?.staleTime??S}}_updateGetCache(t,e,s,i){const a=this.getQueryClient(),r=["crud",t,"get",e];i===y.DELETE?a.removeQueries({queryKey:r}):i===y.SET&&s?a.setQueryData(r,s):(i===y.UPDATE||i===y.ADD)&&s&&a.setQueryData(r,u=>u?{...u,...s}:s)}_updateListCaches(t,e,s,i){const a=this.getQueryClient();this._updateGetCache(t,e,s,i),a.setQueriesData({queryKey:["crud",t]},r=>{if(r&&typeof r=="object"&&"items"in r){const u=r;let h=u.items;return i===y.DELETE?(h=u.items.filter(d=>d!=null&&typeof d=="object"&&d.id!==e),{...u,items:h,total:Math.max(0,(u.total??h.length)-1)}):i===y.ADD&&s?(h=[...u.items,{...s,id:e}],{...u,items:h,total:(u.total??u.items.length)+1}):(i===y.UPDATE||i===y.SET)&&s&&u.items.some(n=>n!=null&&typeof n=="object"&&n.id===e)?(h=u.items.map(n=>n==null||typeof n!="object"||n.id!==e?n:i===y.SET?{...s,id:e}:{...n,...s}),{...u,items:h}):r}if(Array.isArray(r)){if(i===y.DELETE)return r.filter(u=>u.id!==e);if(i===y.ADD&&s)return[...r,{...s,id:e}];if((i===y.UPDATE||i===y.SET)&&s)return r.some(h=>h!=null&&typeof h=="object"&&h.id===e)?r.map(h=>h==null||typeof h!="object"||h.id!==e?h:i===y.SET?{...s,id:e}:{...h,...s}):r}return r})}_checkUniquenessFromCache(t,e,s){const a=s.metadata?.uniqueKeys;if(!a||a.length===0)return null;const u=this.getQueryClient().getQueriesData({queryKey:["crud",t]}),h=[];for(const[,n]of u)n&&typeof n=="object"&&"items"in n?h.push(...n.items):Array.isArray(n)&&h.push(...n);if(h.length===0)return null;const d=e;for(const n of a){if(!n.fields.every(p=>d[p]!=null&&d[p]!==""))continue;const g=h.find(p=>n.fields.every(w=>{const C=typeof d[w]=="string"?d[w].toLowerCase():d[w],E=typeof p[w]=="string"?p[w].toLowerCase():p[w];return C===E}));if(g){if(n.findOrCreate)return g.id;const p=n.fields.join(" + ");throw f(new Error(n.errorMessage||`Duplicate ${p}`),{userMessage:n.errorMessage||`A record with this ${p} already exists`,showNotification:!0})}}return null}_getItemFromListCache(t,e){const i=this.getQueryClient().getQueriesData({queryKey:["crud",t]});for(const[,a]of i)if(a?.items){const r=a.items.find(u=>u.id===e);if(r)return r}return null}async invalidateCollection(t){await this.getQueryClient().invalidateQueries({queryKey:["crud",t]})}async get(t,e,s,i){if(await this._ensureAdapter(),i?.noCache)return this._getFromAdapter(t,e,s);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,s,!1),staleTime:i?.staleTime??S})}catch(a){const r=f(a,{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,s,i=!0){this.store&&i&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{if(!this.adapter)throw new Error("Adapter not initialized");this._assertCanAccess(t,s);const a=await this.adapter.get(t,e,s);if(a&&this.security){const r=this._getPiiFields(s);if(r.length>0)return this.security.decryptPii(a,r)}return a}catch(a){const r=f(a,{userMessage:`Failed to fetch ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,r),r}finally{this.store&&i&&this.store.getState().setLoading(t,!1)}}async query(t,e,s,i,a=_.LIST){if(await this._ensureAdapter(),i?.noCache)return this._queryFromAdapter(t,e,s,!0,a);this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{return await this.getQueryClient().fetchQuery({queryKey:["crud",t,"query",JSON.stringify(e)],queryFn:()=>this._queryFromAdapter(t,e,s,!1,a),staleTime:i?.staleTime??S})}catch(r){const u=f(r,{userMessage:`Failed to query ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,u),u}finally{this.store&&this.store.getState().setLoading(t,!1)}}async _queryFromAdapter(t,e,s,i=!0,a=_.LIST){this.store&&i&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));try{if(!this.adapter)throw new Error("Adapter not initialized");this._assertCanAccess(t,s);const r=await this.adapter.query(t,e,s,a);if(this.security&&r.items.length>0){const u=this._getPiiFields(s);u.length>0&&(r.items=r.items.map(h=>this.security.decryptPii(h,u)))}return r}catch(r){const u=f(r,{userMessage:`Failed to query ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,u),u}finally{this.store&&i&&this.store.getState().setLoading(t,!1)}}_getEntityName(t){const e=c();let s=`entity-${t}`,i=e.t("name",{ns:s,defaultValue:null});return i&&i!=="name"&&i!==`${s}:name`||t.endsWith("s")&&t.length>1&&(s=`entity-${t.slice(0,-1)}`,i=e.t("name",{ns:s,defaultValue:null}),i&&i!=="name"&&i!==`${s}:name`)?i:t}async set(t,e,s,i,a){await this._ensureAdapter(),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const u=this.getQueryClient().getQueryData(["crud",t,"get",e])??null;this.store&&this.store.getState().updateOptimistic(t,e,s,u);try{if(!this.adapter)throw new Error("Adapter not initialized");this._assertCanAccess(t,i),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const h=this._getPiiFields(i),d=h.length>0&&this.security?this.security.encryptPii(s,h):s;if(await this.adapter.set(t,e,d,i),this._updateListCaches(t,e,s,y.SET),this.store&&this.store.getState().confirmUpdate(t,e),this._auditCrud("crud.update",t,e),this._shouldShowSuccessToast(a)){const n=c(),o=this._getEntityName(t);m("success",n.t("messages.updateSuccess",{ns:"crud",entity:o}))}}catch(h){u&&this._updateListCaches(t,e,u,y.SET),this.store&&this.store.getState().rejectUpdate(t,e);const d=f(h,{userMessage:`Failed to save ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,d),d}finally{this.store&&this.store.getState().setLoading(t,!1)}}async update(t,e,s,i,a){await this._ensureAdapter(),this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const u=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e),h=u?{...u,...s}:{...s,id:e};this.store&&this.store.getState().updateOptimistic(t,e,h,u??null);try{if(!this.adapter)throw new Error("Adapter not initialized");i&&this._assertCanAccess(t,i),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const d=i?this._getPiiFields(i):[],n=d.length>0&&this.security?this.security.encryptPii(s,d):s;if(await this.adapter.update(t,e,n),this._updateListCaches(t,e,h,y.UPDATE),this.store&&this.store.getState().confirmUpdate(t,e),this._auditCrud("crud.update",t,e),this._shouldShowSuccessToast(a)){const o=c(),g=this._getEntityName(t);m("success",o.t("messages.updateSuccess",{ns:"crud",entity:g}))}}catch(d){u?this._updateListCaches(t,e,u,y.UPDATE):this.invalidateCollection(t),this.store&&this.store.getState().rejectUpdate(t,e);const n=f(d,{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,s){await this._ensureAdapter(),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(this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write"),await this.adapter.delete(t,e),this._updateListCaches(t,e,null,y.DELETE),this.store&&this.store.getState().confirmDelete(t,e),this._auditCrud("crud.delete",t,e),this.security?.recordAnomaly?.("bulk.deletes",this.currentUserId??void 0),this._shouldShowSuccessToast(s)){const r=c(),u=this._getEntityName(t);m("success",r.t("messages.deleteSuccess",{ns:"crud",entity:u}))}}catch(r){a&&this._updateListCaches(t,e,a,y.ADD),this.store&&this.store.getState().rejectDelete(t,e);const u=f(r,{userMessage:`Failed to delete ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,u),u}finally{this.store&&this.store.getState().setLoading(t,!1)}}async add(t,e,s,i){await this._ensureAdapter();const a=this._checkUniquenessFromCache(t,e,s);if(a)return a;this.store&&(this.store.getState().setLoading(t,!0),this.store.getState().setError(t,null));const r=`temp_${crypto.randomUUID()}`;this.store&&this.store.getState().addOptimistic(t,r,{...e,id:r});try{if(!this.adapter)throw new Error("Adapter not initialized");this._assertCanAccess(t,s),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const u=this._getPiiFields(s),h=u.length>0&&this.security?this.security.encryptPii(e,u):e,d=await this.adapter.add(t,h,s),n=d.id,o=d.data;if(this._updateListCaches(t,r,null,y.DELETE),this._updateListCaches(t,n,o,y.ADD),this.store&&this.store.getState().confirmOptimistic(t,r,n,o),this._auditCrud("crud.create",t,n),this._shouldShowSuccessToast(i)){const g=c(),p=this._getEntityName(t);m("success",g.t("messages.createSuccess",{ns:"crud",entity:p}))}return n}catch(u){this._updateListCaches(t,r,null,y.DELETE),this.store&&this.store.getState().rejectOptimistic(t,r);const h=f(u,{userMessage:`Failed to create ${t}`,showNotification:!0});throw this.store&&this.store.getState().setError(t,h),h}finally{this.store&&this.store.getState().setLoading(t,!1)}}subscribe(t,e,s,i){if(!this.adapter){let a=!1,r=null;return this._ensureAdapter().then(()=>{a||(r=this._subscribeSync(t,e,s,i))}).catch(u=>{a||s(null,f(u))}),()=>{a=!0,r?.()}}return this._subscribeSync(t,e,s,i)}_subscribeSync(t,e,s,i){try{const a=this.adapter;return a?a.subscribe?(this._assertCanAccess(t,i),a.subscribe(t,e,(r,u)=>{r&&this.getQueryClient().setQueryData(["crud",t,"get",e],r),s(r,u)},i)):()=>{}:(s(null,new Error("Adapter not initialized")),()=>{})}catch(a){return s(null,f(a)),()=>{}}}subscribeToCollection(t,e,s,i){if(!this.adapter){let a=!1,r=null;return this._ensureAdapter().then(()=>{a||(r=this._subscribeToCollectionSync(t,e,s,i))}).catch(u=>{a||s([],f(u))}),()=>{a=!0,r?.()}}return this._subscribeToCollectionSync(t,e,s,i)}_subscribeToCollectionSync(t,e,s,i){try{const a=this.adapter;return a?a.subscribeToCollection?(this._assertCanAccess(t,i),a.subscribeToCollection(t,e,(r,u)=>{r&&this.getQueryClient().setQueryData(["crud",t,"query",JSON.stringify(e)],h=>h?{...h,items:r}:{items:r}),s(r,u)},i)):()=>{}:(s([],new Error("Adapter not initialized")),()=>{})}catch(a){return s([],f(a)),()=>{}}}async addOptimistic(t,e,s,i){await this._ensureAdapter();const a=this._checkUniquenessFromCache(t,e,s);if(a)return{...e,id:a};this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const r=`temp_${crypto.randomUUID()}`,u={...e,id:r,_optimistic:!0};this.store&&this.store.getState().addOptimistic(t,r,u);try{if(!this.adapter)throw new Error("Adapter not initialized");const h=await this.adapter.add(t,e,s),d=h.id,n=h.data;if(this._updateListCaches(t,r,null,y.DELETE),this._updateListCaches(t,d,n,y.ADD),this.store&&this.store.getState().confirmOptimistic(t,r,d,n),this._auditCrud("crud.create",t,d),this._shouldShowSuccessToast(i)){const o=c(),g=this._getEntityName(t);m("success",o.t("messages.createSuccess",{ns:"crud",entity:g}))}return n}catch(h){throw this._updateListCaches(t,r,null,y.DELETE),this.store&&this.store.getState().rejectOptimistic(t,r),f(h,{userMessage:`Failed to create ${t}`,showNotification:!0})}}async updateOptimistic(t,e,s,i,a){await this._ensureAdapter(),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");const u=this.getQueryClient().getQueryData(["crud",t,"get",e])??this._getItemFromListCache(t,e),h=u?{...u,...s,_optimistic:!0}:{...s,id:e,_optimistic:!0};this.store&&u&&this.store.getState().updateOptimistic(t,e,h,u);try{if(!this.adapter)throw new Error("Adapter not initialized");await this.adapter.update(t,e,s);const{_optimistic:d,...n}=h;if(this._updateListCaches(t,e,n,y.UPDATE),this.store&&this.store.getState().confirmUpdate(t,e),this._auditCrud("crud.update",t,e),this._shouldShowSuccessToast(a)){const o=c(),g=this._getEntityName(t);m("success",o.t("messages.updateSuccess",{ns:"crud",entity:g}))}return n}catch(d){throw u&&this._updateListCaches(t,e,u,y.UPDATE),this.store&&this.store.getState().rejectUpdate(t,e),f(d,{userMessage:`Failed to update ${t}`,showNotification:!0})}}async deleteOptimistic(t,e,s){await this._ensureAdapter(),this.security&&await this.security.checkRateLimit(this._rateLimitKey(t),"write");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,y.DELETE),this.store&&this.store.getState().confirmDelete(t,e),this._auditCrud("crud.delete",t,e),this.security?.recordAnomaly?.("bulk.deletes",this.currentUserId??void 0),this._shouldShowSuccessToast(s)){const r=c(),u=this._getEntityName(t);m("success",r.t("messages.deleteSuccess",{ns:"crud",entity:u}))}}catch(r){throw a&&this._updateListCaches(t,e,a,y.ADD),this.store&&this.store.getState().rejectDelete(t,e),f(r,{userMessage:`Failed to delete ${t}`,showNotification:!0})}}}const P=A(()=>new F);export{P as getCrudService};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CrudButton.d.ts","sourceRoot":"","sources":["../../src/components/CrudButton.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CrudButton.d.ts","sourceRoot":"","sources":["../../src/components/CrudButton.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAI9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,IAAI,CACxD,iBAAiB,CAAC,CAAC,CAAC,EACpB,UAAU,CACX;IACC;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qBAAqB;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,iBAAS,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,EAC/B,YAAmB,EACnB,IAAI,EACJ,QAAgB,EAChB,QAAQ,EACR,GAAG,iBAAiB,EACrB,EAAE,eAAe,CAAC,CAAC,CAAC,2CAYpB;AAED,eAAe,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as a,jsxs as k,Fragment as Dt}from"react/jsx-runtime";import{useState as T,useMemo as
|
|
1
|
+
"use client";import{jsx as a,jsxs as k,Fragment as Dt}from"react/jsx-runtime";import{useState as T,useMemo as ht}from"react";import{X as yt}from"lucide-react";import{Button as S,Calendar as St,FloatingLabel as pt,Sheet as E,Text as ut}from"@donotdev/components";import{formatDate as ft}from"@donotdev/core";function vt({label:p,fieldType:xt,value:s,onChange:u,tCrud:o,locale:_="en"}){const[w,l]=T(!1),[F,f]=T(null),b=ht(()=>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}`,h=new Date(t);h.setDate(h.getDate()+7);const Q=h.getFullYear(),U=String(h.getMonth()+1).padStart(2,"0"),Z=String(h.getDate()).padStart(2,"0"),tt=`${Q}-${U}-${Z}`,y=new Date(t);y.setDate(y.getDate()+30);const et=y.getFullYear(),at=String(y.getMonth()+1).padStart(2,"0"),nt=String(y.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:()=>{u({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}`;u({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:()=>{u({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:"ghost",onClick:()=>{f("start"),l(!0)},style:{flex:1},children:e?.min?v(e.min):o("filter.min",{defaultValue:"Min"})}),title:`${p} - ${o("filter.min",{defaultValue:"Min"})}`,open:w&&F==="start",onOpenChange:t=>{l(t),t||f(null)},children:V("start")}),a(ut,{level:"small",variant:"muted",style:{display:"flex",alignItems:"center"},children:"\u2013"}),a(E,{trigger:a(S,{variant:"ghost",onClick:()=>{f("end"),l(!0)},style:{flex:1},children:e?.max?v(e.max):o("filter.max",{defaultValue:"Max"})}),title:`${p} - ${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(yt,{size:16}),onClick:()=>{u(void 0)},disabled:!R,"aria-label":o("filter.clear",{defaultValue:"Clear"})})]});return p?a(pt,{label:p,className:"dndev-range-input",children:j}):a("div",{className:"dndev-range-input",children:j})}export{vt as DateFilter};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { FieldType, EntityField } from '@donotdev/core';
|
|
2
|
+
import type { DisplayFormatterOptions } from '../fieldTypeRegistry';
|
|
2
3
|
import type { ReactElement } from 'react';
|
|
3
4
|
export interface DisplayFieldRendererProps<T extends FieldType = FieldType> {
|
|
4
5
|
/** Field identifier */
|
|
@@ -21,10 +22,7 @@ export interface DisplayFieldRendererProps<T extends FieldType = FieldType> {
|
|
|
21
22
|
* @param options.asString - Prefer string output when possible (e.g. for price in text placeholders)
|
|
22
23
|
* @returns Formatted value as string or ReactElement
|
|
23
24
|
*/
|
|
24
|
-
export declare function formatValue(value: any, config: EntityField, t: (key: string, options?: Record<string, any>) => string, options?:
|
|
25
|
-
compact?: boolean;
|
|
26
|
-
asString?: boolean;
|
|
27
|
-
}): string | ReactElement;
|
|
25
|
+
export declare function formatValue(value: any, config: EntityField, t: (key: string, options?: Record<string, any>) => string, options?: DisplayFormatterOptions): string | ReactElement;
|
|
28
26
|
/**
|
|
29
27
|
* DisplayFieldRenderer - Renders a field value as read-only display
|
|
30
28
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DisplayFieldRenderer.d.ts","sourceRoot":"","sources":["../../src/components/DisplayFieldRenderer.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"DisplayFieldRenderer.d.ts","sourceRoot":"","sources":["../../src/components/DisplayFieldRenderer.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAEpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE1C,MAAM,WAAW,yBAAyB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IACxE,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IACvB,0BAA0B;IAC1B,KAAK,EAAE,GAAG,CAAC;IACX,2BAA2B;IAC3B,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC;CAC3D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,GAAG,EACV,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,EACzD,OAAO,CAAC,EAAE,uBAAuB,GAChC,MAAM,GAAG,YAAY,CA0DvB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EAAE,EACpE,IAAI,EACJ,MAAM,EACN,KAAK,EACL,CAAC,GACF,EAAE,yBAAyB,CAAC,CAAC,CAAC,GAAG,YAAY,CAyC7C;AAED,eAAe,oBAAoB,CAAC"}
|
|
@@ -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":"AA0DA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAW7C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,MAAM,WAAW,kBAAkB,CACjC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IACrE,EAAE,EAAE,MAAM,CAAC;CACZ;IAED,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;IACrE,EAAE,EAAE,MAAM,CAAC;CACZ,EACD,EACA,MAAM,EACN,IAAI,EAAE,QAAQ,EACd,cAAc,EACd,OAAkB,GACnB,EAAE,kBAAkB,CAAC,CAAC,CAAC,kDAwpBvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as m,jsxs as B}from"react/jsx-runtime";import{useMemo as w}from"react";import{FilterX as Z}from"lucide-react";import{Button as N,Combobox as ee,Grid as te,Rating as ne,RangeInput as ie,Slider as re,Stack as se}from"@donotdev/components";import{DateFilter as le}from"./DateFilter";import{useTranslation as L,handleError as $}from"@donotdev/core";import{translateFieldLabel as ae,translateLabel as I}from"../forms/utils";import{getFilterType as z,isFilterable as oe}from"../fieldTypeRegistry";import{useCrudFilters as ce}from"../hooks/useCrudFilters";import{useCrudCardList as de}from"../useCrudCardList";import{matchesFilter as me}from"../utils/matchesFilter";import{matchesFilter as ke}from"../utils/matchesFilter";function Oe({entity:d,data:k,fieldsToFilter:S,variant:R="inline"}){const G=R==="sidebar",{t:g,i18n:X}=L("crud"),{t:j}=L([d.namespace,"crud"]),q=X?.language||"en",{data:H}=de(d,{enabled:!k}),f=k??(H?.items||[]),{filters:y,setFilters:_}=ce({collection:d.collection}),h=w(()=>(S&&S.length>0?S:d.listFields||Object.keys(d.fields)).filter(t=>{const n=d.fields[t]?.type||"text";return oe(n)}),[S,d.listFields,d.fields]),v=w(()=>{const i={};return h.forEach(t=>{const o=Object.fromEntries(Object.entries(y).filter(([n])=>n!==t));if(Object.keys(o).length===0){i[t]=f;return}i[t]=f.filter(n=>Object.entries(o).every(([c,x])=>{const F=n[c],s=d.fields[c]?.type||"text";return me(F,x,s)}))}),i},[f,y,d.fields,h]),J=w(()=>{const i={};return h.forEach(t=>{const o=d.fields[t];if(!o)return;const n=o.type||"text",c=z(n);if(!c){$(new Error(`Field type "${n}" not registered in field type registry`),{userMessage:`Field type "${n}" is missing from registry`,context:{fieldType:n,fieldName:t,operation:"minmax_computation",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"});return}const x=c==="range"&&(n==="date"||n==="datetime-local"||n==="timestamp"||n==="time"||n==="week"||n==="month"||n==="year"),F=c==="range"&&!x,C=n==="price";if(F||C){const s=f.map(r=>r[t]).filter(r=>r!=null&&r!=="").map(r=>C&&typeof r=="object"&&r!==null?Number(r.amount):typeof r=="number"?r:Number(r)).filter(r=>!isNaN(r));s.length>0&&(i[t]={min:Math.min(...s),max:Math.max(...s)})}else if(x){const s=f.map(r=>r[t]).filter(r=>r!=null&&r!=="").map(r=>r instanceof Date?r:new Date(r)).filter(r=>!isNaN(r.getTime()));if(s.length>0){const r=new Date(Math.min(...s.map(T=>T.getTime()))),p=new Date(Math.max(...s.map(T=>T.getTime()))),P=r.toISOString().split("T")[0],E=p.toISOString().split("T")[0];i[t]={min:P||"",max:E||""}}}}),i},[f,d.fields,h]),b=(i,t)=>{const o={...y};if(!t||t==="")delete o[i];else if(Array.isArray(t))o[i]=t;else if(typeof t=="object"&&"min"in t){const n=t.min&&t.min!=="",c=t.max&&t.max!=="";!n&&!c?delete o[i]:o[i]=t}else o[i]=t;_(o)},K=()=>{_({})},V=w(()=>h.length===0?null:h.map(i=>{const t=d.fields[i];if(!t)return null;const o=ae(i,t,j),n=t.type||"text",c=z(n);if(!c)return $(new Error(`Field type "${n}" not registered in field type registry`),{userMessage:`Field type "${n}" is missing from registry`,context:{fieldType:n,fieldName:i,operation:"filter_ui_render",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"}),null;const x=c==="range"&&(n==="date"||n==="datetime-local"||n==="timestamp"||n==="time"||n==="week"||n==="month"||n==="year"),F=c==="range"&&!x,C=c==="select",s=y[i],p=typeof s=="object"&&s!==null&&"min"in s?s:{min:"",max:""};if(c==="rating"){const l=t.validation?.max??5,a=typeof s=="string"&&s!==""?Number(s):0;return m("div",{style:{gridColumn:"span 2"},children:m(ne,{value:a,max:l,"aria-label":o,onChange:e=>{b(i,e===a?void 0:String(e))}})},i)}if(F){const l=J[i],a=l?.min??0,e=l?.max??100,u=p.min?Number(p.min):a,O=p.max?Number(p.max):e;return B(se,{gap:"tight",style:{gridColumn:"span 2"},children:[m(ie,{type:"number",label:o,minPlaceholder:g("filter.min",{defaultValue:"Min"}),maxPlaceholder:g("filter.max",{defaultValue:"Max"}),minValue:p.min||"",maxValue:p.max||"",actualMin:a,actualMax:e,onChange:(M,Y)=>{b(i,{min:M,max:Y})},onClear:()=>b(i,void 0)}),m(re,{value:[u,O],min:a,max:e,step:1,onValueChange:M=>{b(i,{min:String(M[0]),max:String(M[1])})}})]},i)}if(x){const l=n==="week"||n==="month"||n==="year"?n:"date",a=(()=>{if(s){if(typeof s=="object"&&"min"in s){const e=s;return{min:e.min&&e.min.split("T")[0]||"",max:e.max&&e.max.split("T")[0]||""}}if(typeof s=="string"){const e=s.split("T")[0]||"";return{min:e,max:e}}}})();return m("div",{style:{gridColumn:"span 2",gridRow:G?void 0:"span 1"},children:m(le,{label:o,fieldType:l,value:a,locale:q,onChange:e=>{if(!e){b(i,void 0);return}typeof e=="object"&&"min"in e&&b(i,{min:e.min||"",max:e.max||""})},tCrud:g})},i)}const E=C&&t.validation&&"options"in t.validation&&t.validation?Array.isArray(t.validation.options)?t.validation.options:typeof t.validation.options=="function"?t.validation.options():[]:[],T=v[i]||f,D=new Set,W=c==="address";T.forEach(l=>{const a=l[i];if(a!=null)if(W&&typeof a=="object"&&"formatted_address"in a){const e=a;e.formatted_address&&D.add(String(e.formatted_address))}else D.add(String(a))});const A=[{value:"all",label:g("filter.selectPlaceholder",{defaultValue:"All"})}];if(E.length>0){const l=[],a=[];E.forEach(e=>{const u=typeof e=="string"?e:e.value,O=typeof e=="string"?e:e.label;D.has(u)?l.push({value:u,label:O}):a.push({value:u,label:O})}),l.sort((e,u)=>e.label.localeCompare(u.label)),a.sort((e,u)=>e.label.localeCompare(u.label)),l.forEach(e=>{A.push({value:e.value,label:I(e.label,j),disabled:!1})}),a.forEach(e=>{A.push({value:e.value,label:I(e.label,j),disabled:!0})})}else Array.from(D).sort().slice(0,100).forEach(l=>{A.push({value:l,label:l})});return m("div",{style:{gridColumn:"span 2",gridRow:"span 1"},children:m(ee,{label:o,value:typeof s=="string"?s:void 0,onValueChange:l=>{b(i,l==="all"||!l?"":String(l))},options:A,placeholder:g("filter.placeholder",{defaultValue:"Filter..."}),clearable:!0})},i)}),[h,d.fields,f,y,j,g,v]);if(!V||V.length===0)return null;const Q=V.filter(Boolean),U=Object.keys(y).length>0;return B(te,{cols:R==="sidebar"?2:[2,4,6,8],children:[Q,m(N,{variant:"outline",icon:m(Z,{size:18}),onClick:K,disabled:!U,style:{gridColumn:"1 / -1",gridRow:"span 1"},children:g("filter.clear",{defaultValue:"Clear Filters"})})]})}export{Oe as EntityFilters,ke as matchesFilter};
|
|
@@ -1 +1 @@
|
|
|
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:
|
|
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:u,formMethods:f,loading:n=!1,submitText:g,cancelText:v,showCancel:p=!1,onCancel:b,variant:l="default",columns:h=1,description:o})=>{const{t:d}=L("crud"),[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,{...f,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:u}),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};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ControlledFieldProps } from '../types';
|
|
2
|
+
import type { ReactElement } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Build a display label for a referenced item.
|
|
5
|
+
*
|
|
6
|
+
* Resolution order:
|
|
7
|
+
* 1. `labelFields` — join multiple fields (e.g. `['first_name', 'last_name']` → "John Doe")
|
|
8
|
+
* 2. `displayField` — single field
|
|
9
|
+
* 3. Auto-detect: first match from name/title/label/displayName
|
|
10
|
+
* 4. Fallback: document `id`
|
|
11
|
+
*/
|
|
12
|
+
export declare function buildReferenceLabel(item: Record<string, any>, labelFields?: string[], displayField?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* ControlledReferenceField — Controlled component for `type: 'reference'` fields.
|
|
15
|
+
*
|
|
16
|
+
* Reads `validation.reference` to determine the collection, auto-fetches items
|
|
17
|
+
* via `useCrudList`, and renders the existing `ReferenceFieldComponent` (Combobox).
|
|
18
|
+
*/
|
|
19
|
+
export declare function ControlledReferenceField(props: ControlledFieldProps): ReactElement;
|
|
20
|
+
//# sourceMappingURL=ControlledReferenceField.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ControlledReferenceField.d.ts","sourceRoot":"","sources":["../../../../src/components/controlled/select/ControlledReferenceField.tsx"],"names":[],"mappings":"AASA,OAAO,EAA0B,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAI7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAK1C;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACzB,WAAW,CAAC,EAAE,MAAM,EAAE,EACtB,YAAY,CAAC,EAAE,MAAM,GACpB,MAAM,CAqBR;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,oBAAoB,GAC1B,YAAY,CAyDd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import{jsx as u}from"react/jsx-runtime";import{useMemo as C}from"react";import{Controller as _}from"react-hook-form";import{useCrudList as x}from"../../../useCrudList";import S from"../../form/fields/ReferenceFieldComponent";import{convertValidationRules as L}from"../types";const R=["name","title","label","displayName"];function T(e,t,n){if(t?.length){const r=t.map(o=>e[o]).filter(o=>o!=null&&o!=="");if(r.length)return r.join(" ")}if(n&&e[n]!=null&&e[n]!=="")return String(e[n]);for(const r of R)if(e[r]!=null&&e[r]!=="")return String(e[r]);return e.id??"?"}function B(e){const{control:t,errors:n,fieldConfig:r,t:o,placeholder:p}=e,{name:s,label:m,validation:i,options:c={}}=r,f=i?.reference,a=c.fieldSpecific,{items:d,loading:g}=x(f??"__disabled__",{enabled:!!f}),b=C(()=>d.map(l=>({id:l.id,label:T(l,a?.labelFields,a?.displayField)})),[d,a?.labelFields,a?.displayField]);return u(_,{name:s,control:t,rules:i?L(i):void 0,render:({field:l})=>u(S,{label:o(m),value:l.value??"",onChange:h=>l.onChange(h),onBlur:l.onBlur,options:b,isLoading:g,error:!!n[s],helperText:n[s]?.message,required:i?.required,placeholder:p||c.placeholder})})}export{B as ControlledReferenceField,T as buildReferenceLabel};
|
|
@@ -2,5 +2,6 @@ export { ControlledComboboxField } from './ControlledComboboxField';
|
|
|
2
2
|
export { ControlledDropdownField } from './ControlledDropdownField';
|
|
3
3
|
export { ControlledMultiDropdownField } from './ControlledMultiDropdownField';
|
|
4
4
|
export { ControlledRadioField } from './ControlledRadioField';
|
|
5
|
+
export { ControlledReferenceField } from './ControlledReferenceField';
|
|
5
6
|
export { ControlledYearField } from './ControlledYearField';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/controlled/select/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/controlled/select/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,4BAA4B,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ControlledComboboxField as
|
|
1
|
+
import{ControlledComboboxField as r}from"./ControlledComboboxField";import{ControlledDropdownField as d}from"./ControlledDropdownField";import{ControlledMultiDropdownField as n}from"./ControlledMultiDropdownField";import{ControlledRadioField as p}from"./ControlledRadioField";import{ControlledReferenceField as m}from"./ControlledReferenceField";import{ControlledYearField as C}from"./ControlledYearField";export{r as ControlledComboboxField,d as ControlledDropdownField,n as ControlledMultiDropdownField,p as ControlledRadioField,m as ControlledReferenceField,C as ControlledYearField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AddressFieldComponent.d.ts","sourceRoot":"","sources":["../../../../src/components/form/fields/AddressFieldComponent.tsx"],"names":[],"mappings":"AAiBA;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,2DAA2D;IAC3D,KAAK,CAAC,EAAE;QACN,iBAAiB,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IACF,qBAAqB;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IAC/B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,2DAA2D;IAC3D,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,kBAAkB;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kBAAkB;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,qBAAqB,GAAI,iGAS5B,0BAA0B,
|
|
1
|
+
{"version":3,"file":"AddressFieldComponent.d.ts","sourceRoot":"","sources":["../../../../src/components/form/fields/AddressFieldComponent.tsx"],"names":[],"mappings":"AAiBA;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,2DAA2D;IAC3D,KAAK,CAAC,EAAE;QACN,iBAAiB,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;IACF,qBAAqB;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IAC/B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,2DAA2D;IAC3D,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,kBAAkB;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kBAAkB;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,qBAAqB,GAAI,iGAS5B,0BAA0B,4CAiT5B,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as r,jsxs as p}from"react/jsx-runtime";import{MapPin as D}from"lucide-react";import{useState as S,useEffect as w,useRef as b,useMemo as F}from"react";import{Combobox as
|
|
1
|
+
import{jsx as r,jsxs as p}from"react/jsx-runtime";import{MapPin as D}from"lucide-react";import{useState as S,useEffect as w,useRef as b,useMemo as F}from"react";import{Combobox as L,Stack as M}from"@donotdev/components";import{useTranslation as N,getPlatformEnvVar as W}from"@donotdev/core";const Y=({label:C,value:i,onChange:P,enableGoogleMaps:j=!1,extractDistrictCode:O,error:c,helperText:l,required:x})=>{const{t:n}=N("crud"),[a,u]=S(i?.formatted_address||""),[f,g]=S([]),[I,m]=S(!1),v=b(null),h=b(null),d=b(null),_=W("GOOGLE_MAPS_API_KEY")||"",o=j&&!!_,R=F(()=>f.map(e=>({value:e.place_id,label:e.description,description:e.structured_formatting?.secondary_text,content:p("div",{style:{display:"flex",alignItems:"center",gap:"var(--gap-sm)"},children:[r(D,{style:{width:"var(--size-icon-sm)",height:"var(--size-icon-sm)"}}),p("div",{children:[r("div",{children:e.description}),e.structured_formatting?.secondary_text&&r("div",{style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:e.structured_formatting.secondary_text})]})]})})),[f]),V=e=>{h.current&&(m(!0),h.current.getDetails({placeId:e,fields:["formatted_address","geometry","address_components"]},(t,y)=>{if(m(!1),y===window.google?.maps?.places?.PlacesServiceStatus.OK&&t){const s=t.formatted_address||"",k=t.geometry?.location?.lat(),q=t.geometry?.location?.lng(),z={formatted_address:s,latitude:k,longitude:q};if(O&&t.address_components){const A=t.address_components.find(U=>U.types.includes("postal_code"))?.long_name||"",T=A.startsWith("92")?92:parseInt(A.slice(-2),10)||null;z.district_code=T}u(s),P(z)}}))};w(()=>{i?.formatted_address&&u(i.formatted_address)},[i]),w(()=>{if(!o)return;let e=null;const t=()=>{window.google?.maps?.places&&(v.current=new window.google.maps.places.AutocompleteService,h.current=new window.google.maps.places.PlacesService(document.createElement("div")))};return(()=>{if(window.google?.maps?.places){t();return}if(document.querySelector("#google-maps-script")){e=setInterval(()=>{window.google?.maps?.places&&(clearInterval(e),e=null,t())},100);return}const s=document.createElement("script");s.id="google-maps-script",s.src=`https://maps.googleapis.com/maps/api/js?key=${_}&libraries=places`,s.async=!0,s.defer=!0,s.onload=()=>t(),document.head.appendChild(s)})(),()=>{e!==null&&(clearInterval(e),e=null)}},[o,_]),w(()=>{if(!o||!a||!v.current){g([]);return}return d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{m(!0),v.current.getPlacePredictions({input:a,types:["geocode","establishment"]},(e,t)=>{m(!1),t===window.google?.maps?.places?.PlacesServiceStatus.OK&&e?g(e):g([])})},300),()=>{d.current&&clearTimeout(d.current)}},[o,a]);const K=e=>{u(e),P({formatted_address:e})},E=e=>{const t=Array.isArray(e)?e[0]||"":e;if(!o){K(t);return}f.some(s=>s.place_id===t)&&V(t)},G=e=>{o&&u(e)};return o?p(M,{gap:"tight",children:[r(L,{label:C,value:a,onValueChange:E,onSearchChange:G,placeholder:n("address.placeholder","Enter address..."),emptyMessage:I?n("messages.loading","Loading..."):n("address.noResults","No addresses found"),options:R,required:x,variant:c?"destructive":void 0,isLoading:I,creatable:!0,createLabel:n("actions.use","Use this address")}),l&&r("p",{style:{fontSize:"var(--font-size-xs)",color:c?"var(--destructive-foreground)":"var(--muted-foreground)"},children:l})]}):p(M,{gap:"tight",children:[r(L,{label:C,value:a,onValueChange:E,placeholder:n("address.placeholder","Enter address..."),options:[],required:x,variant:c?"destructive":void 0,creatable:!0,createLabel:n("actions.use","Use this address")}),l&&r("p",{style:{fontSize:"var(--font-size-xs)",color:c?"var(--destructive-foreground)":"var(--muted-foreground)"},children:l})]})};var Z=Y;export{Z as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as n,jsxs as l,Fragment as ie}from"react/jsx-runtime";import{Upload as ae,X as se,FileText as P,FileSpreadsheet as le,File as de,Loader2 as ce,Eye as ue}from"lucide-react";import{useCallback as w,useState as E,useRef as F,useEffect as W,useImperativeHandle as pe,forwardRef as me}from"react";import{Button as _,BUTTON_VARIANT as G,Text as g,Stack as x,Progress as fe,Dialog as ge,DialogContent as ve,DialogHeader as he,DialogTitle as ye}from"@donotdev/components";import{handleError as N,useTranslation as we}from"@donotdev/core";import{useUploadContext as xe}from"../../../contexts/UploadContext";import{useUploadStore as V}from"../../../stores/UploadStore";import{uploadFile as Te,deleteFile as be,generateFileId as X,getFileIcon as Pe,formatFileSize as Fe,getDocumentAcceptString as Ne}from"../../../utils/fileStorage";function De({type:f,className:c}){switch(f){case"pdf":return n(P,{className:c,style:{color:"var(--destructive)"}});case"doc":return n(P,{className:c,style:{color:"var(--primary)"}});case"xls":return n(le,{className:c,style:{color:"var(--success)"}});case"ppt":return n(P,{className:c,style:{color:"var(--warning)"}});case"text":case"html":return n(P,{className:c});default:return n(de,{className:c})}}const q=me(({name:f,label:c,value:v,onChange:D,error:k,helperText:M,multiple:p=!1,maxFiles:A=10,maxSize:C=25*1024*1024,storagePath:R="uploads/documents",required:K,enablePreview:L=!0},J)=>{const{t:Q}=we("
|
|
1
|
+
"use client";import{jsx as n,jsxs as l,Fragment as ie}from"react/jsx-runtime";import{Upload as ae,X as se,FileText as P,FileSpreadsheet as le,File as de,Loader2 as ce,Eye as ue}from"lucide-react";import{useCallback as w,useState as E,useRef as F,useEffect as W,useImperativeHandle as pe,forwardRef as me}from"react";import{Button as _,BUTTON_VARIANT as G,Text as g,Stack as x,Progress as fe,Dialog as ge,DialogContent as ve,DialogHeader as he,DialogTitle as ye}from"@donotdev/components";import{handleError as N,useTranslation as we}from"@donotdev/core";import{useUploadContext as xe}from"../../../contexts/UploadContext";import{useUploadStore as V}from"../../../stores/UploadStore";import{uploadFile as Te,deleteFile as be,generateFileId as X,getFileIcon as Pe,formatFileSize as Fe,getDocumentAcceptString as Ne}from"../../../utils/fileStorage";function De({type:f,className:c}){switch(f){case"pdf":return n(P,{className:c,style:{color:"var(--destructive)"}});case"doc":return n(P,{className:c,style:{color:"var(--primary)"}});case"xls":return n(le,{className:c,style:{color:"var(--success)"}});case"ppt":return n(P,{className:c,style:{color:"var(--warning)"}});case"text":case"html":return n(P,{className:c});default:return n(de,{className:c})}}const q=me(({name:f,label:c,value:v,onChange:D,error:k,helperText:M,multiple:p=!1,maxFiles:A=10,maxSize:C=25*1024*1024,storagePath:R="uploads/documents",required:K,enablePreview:L=!0},J)=>{const{t:Q}=we("crud"),s=Q,h=xe(),H=!!h,[a,u]=E([]),[O,I]=E(!1),[S,j]=E(null),y=F(null),U=F(!1),T=F(void 0),Y=Ne(),b=w(e=>{const t=e.filter(r=>r.uploaded&&!r.error).map(r=>r.uploaded);D(p?t:t[0]||null)},[p,D]);W(()=>{if(U.current){U.current=!1;return}if(v){const e=[];(Array.isArray(v)?v:[v]).forEach(r=>{r.url&&e.push({id:X(),file:new File([],r.filename),uploadProgress:null,uploaded:r,error:null})}),u(e)}else u([])},[v]);const Z=w(async()=>{const e=a.filter(t=>!t.uploaded&&!t.error&&t.uploadProgress===null);if(e.length!==0){u(t=>t.map(r=>e.some(i=>i.id===r.id)?{...r,uploadProgress:0}:r));for(const t of e)try{const r=await Te(t.file,{storagePath:R,onProgress:i=>{u(o=>o.map(d=>d.id===t.id?{...d,uploadProgress:i.progress}:d))}});u(i=>{const o=i.map(d=>d.id===t.id?{...d,uploaded:r,uploadProgress:100,error:null}:d);return queueMicrotask(()=>b(o)),o})}catch{u(i=>i.map(o=>o.id===t.id?{...o,error:"Upload failed",uploadProgress:null}:o))}}},[a,R,b]);T.current=Z,W(()=>{if(!(!h||!f))return V.getState().registerUpload(h,f,async()=>{await T.current?.()}),()=>{V.getState().unregisterUpload(h,f)}},[h,f]),pe(J,()=>({upload:async()=>{await T.current?.()},getDocuments:()=>B.current||[]}),[]);const B=F(a);B.current=a;const $=e=>{const t=[".pdf",".doc",".docx",".xls",".xlsx",".ppt",".pptx",".txt",".md",".html",".csv"],r="."+e.name.split(".").pop()?.toLowerCase();return t.includes(r)},z=w(e=>{const r=(p?A:1)-a.length;if(r<=0){N(new Error("Maximum documents reached"),{userMessage:s("document.errors.maxFiles",{max:A}),severity:"warning",showNotification:!0});return}const i=e.slice(0,r),o=[],d=(C/(1024*1024)).toFixed(0);for(const m of i){if(!$(m)){N(new Error("Invalid document type"),{userMessage:s("document.errors.invalidType",{fileName:m.name}),severity:"warning",showNotification:!0});continue}if(m.size>C){N(new Error("Document too large"),{userMessage:s("document.errors.exceedsSize",{fileName:m.name,size:d}),severity:"warning",showNotification:!0});continue}o.push({id:X(),file:m,uploadProgress:null,uploaded:null,error:null})}o.length!==0&&(u(m=>p?[...m,...o]:o),H||setTimeout(()=>T.current?.(),0))},[a,p,A,C,s,H]),ee=e=>{const t=Array.from(e.target.files||[]);t.length>0&&z(t),y.current&&(y.current.value="")},re=w(e=>{e.preventDefault(),I(!1);const t=Array.from(e.dataTransfer.files);z(t)},[z]),te=w(async e=>{const t=a.find(r=>r.id===e);if(t)try{t.uploaded&&await be(t.uploaded);const r=a.filter(i=>i.id!==e);U.current=!0,u(r),setTimeout(()=>b(r),0)}catch(r){N(r,{userMessage:s("document.delete.failed"),severity:"error",showNotification:!0})}},[a,b,s]),ne=e=>{e.uploaded?.url&&e.uploaded.mimeType==="application/pdf"&&j(e.uploaded.url)},oe=p||a.length===0;return l(ie,{children:[l(x,{gap:"tight",children:[l(g,{level:"body",align:"start",children:[c,K?"*":""]}),oe&&l("div",{role:"button",tabIndex:0,"aria-label":s("document.upload.ariaLabel"),className:"dndev-surface","data-variant":k?"destructive":"default",style:{border:"var(--border-width) dashed",borderColor:O?"var(--primary)":k?"var(--destructive)":"var(--border)",borderRadius:"var(--radius-lg)",padding:"var(--gap-lg)",backgroundColor:O?"color-mix(in oklab, var(--primary) 5%, transparent)":"var(--surface)",transition:"border-color var(--dur-fast), background-color var(--dur-fast)",cursor:"pointer",outline:"none"},onDragOver:e=>{e.preventDefault(),I(!0)},onDragLeave:()=>I(!1),onDrop:re,onClick:()=>y.current?.click(),onKeyDown:e=>{(e.key==="Enter"||e.key===" ")&&(e.preventDefault(),y.current?.click())},children:[n("input",{ref:y,type:"file",accept:Y,multiple:p,style:{display:"none"},onChange:ee}),l(x,{align:"center",justify:"center",children:[n(ae,{className:"dndev-size-lg",style:{color:"var(--muted-foreground)"}}),n(g,{as:"p",variant:"muted",level:"small",align:"center",children:s("document.upload.hint")}),n(g,{as:"p",variant:"muted",level:"caption",align:"center",children:"PDF, Word, Excel, PowerPoint, TXT, Markdown, HTML"})]})]}),a.length>0&&n(x,{gap:"tight",children:a.map((e,t)=>{const r=Pe(e.uploaded?.mimeType||e.file.type,e.file.name),i=e.uploadProgress!==null&&e.uploadProgress<100,o=e.uploaded?.mimeType==="application/pdf"||e.file.name.toLowerCase().endsWith(".pdf");return l("div",{className:"dndev-surface","data-variant":"muted",style:{padding:"var(--gap-md)",borderRadius:"var(--radius-md)",display:"flex",alignItems:"center",gap:"var(--gap-md)"},children:[n(De,{type:r,className:"dndev-size-md"}),l(x,{gap:"none",style:{flex:1,minWidth:0},children:[n(g,{level:"small",style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.file.name}),l(g,{level:"caption",variant:"muted",children:[Fe(e.uploaded?.size||e.file.size),e.error&&l("span",{style:{color:"var(--destructive)"},children:[" ","\xB7 ",e.error]})]}),i&&n(fe,{value:e.uploadProgress||0,max:100,style:{marginTop:"var(--gap-xs)"}})]}),l(x,{direction:"row",gap:"tight",children:[L&&o&&e.uploaded&&n(_,{variant:G.GHOST,onClick:()=>ne(e),"aria-label":s("document.preview.ariaLabel"),children:n(ue,{className:"dndev-size-sm"})}),i?n(ce,{className:"dndev-size-sm",style:{animation:"spin 1s linear infinite"}}):n(_,{variant:G.GHOST,onClick:()=>te(e.id),"aria-label":s("document.delete.ariaLabel"),children:n(se,{className:"dndev-size-sm"})})]})]},e.id)})}),M&&n(g,{level:"caption",variant:k?"destructive":"muted",style:{marginTop:"var(--gap-xs)"},children:M})]}),L&&S&&n(ge,{open:!!S,onOpenChange:()=>j(null),children:l(ve,{style:{maxWidth:"90vw",maxHeight:"90vh",width:"900px",height:"80vh"},children:[n(he,{children:n(ye,{children:s("document.preview.title")})}),n("iframe",{src:S,sandbox:"allow-same-origin",style:{width:"100%",height:"100%",border:"none",borderRadius:"var(--radius-md)"},title:"PDF Preview"})]})})]})});q.displayName="DocumentFieldComponent";var Me=q;export{Me as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as r,jsxs as p}from"react/jsx-runtime";import{Select as g,Stack as m}from"@donotdev/components";import{useTranslation as f}from"@donotdev/core";const h=({label:o,value:t,options:s,error:l,helperText:n,onChange:a,onBlur:i,required:c})=>{const{t:d}=f("crud"),u=t!=null?String(t):"";return p(m,{gap:"tight",children:[r(g,{label:o,value:u,onValueChange:e=>{a&&a({target:{value:e}})},onOpenChange:e=>!e&&i?.(),placeholder:d("actions.select","Select"),required:c,options:s.map(e=>({value:String(e.value),label:e.label}))}),n&&r("p",{style:{fontSize:"var(--font-size-xs)",color:l?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:n})]})};var C=h;export{C as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as t,jsxs as p}from"react/jsx-runtime";import{Upload as Z,X as $,File as ee,Loader2 as re,FileText as z,FileSpreadsheet as se,FileImage as te,FileVideo as oe,FileAudio as ae,FileArchive as ne,FileCode as le}from"lucide-react";import{useCallback as y,useState as B,useRef as b,useEffect as O,useImperativeHandle as ie,forwardRef as de}from"react";import{Button as ue,BUTTON_VARIANT as ce,Text as F,Stack as P,Progress as pe}from"@donotdev/components";import{handleError as C,useTranslation as fe}from"@donotdev/core";import{useUploadContext as ge}from"../../../contexts/UploadContext";import{useUploadStore as H}from"../../../stores/UploadStore";import{uploadFile as me,deleteFile as ve,generateFileId as _,getFileIcon as he,formatFileSize as ye}from"../../../utils/fileStorage";function Fe({type:f,className:l}){switch(f){case"pdf":return t(z,{className:l,style:{color:"var(--destructive)"}});case"doc":return t(z,{className:l,style:{color:"var(--primary)"}});case"xls":return t(se,{className:l,style:{color:"var(--success)"}});case"ppt":return t(z,{className:l,style:{color:"var(--warning)"}});case"image":return t(te,{className:l});case"video":return t(oe,{className:l});case"audio":return t(ae,{className:l});case"archive":return t(ne,{className:l});case"html":case"text":return t(le,{className:l});default:return t(ee,{className:l})}}const V=de(({name:f,label:l,value:g,onChange:T,error:A,helperText:M,accept:q,multiple:d=!1,maxFiles:N=10,maxSize:k=50*1024*1024,storagePath:R="uploads/files",required:D},G)=>{const{t:K}=fe("
|
|
1
|
+
"use client";import{jsx as t,jsxs as p}from"react/jsx-runtime";import{Upload as Z,X as $,File as ee,Loader2 as re,FileText as z,FileSpreadsheet as se,FileImage as te,FileVideo as oe,FileAudio as ae,FileArchive as ne,FileCode as le}from"lucide-react";import{useCallback as y,useState as B,useRef as b,useEffect as O,useImperativeHandle as ie,forwardRef as de}from"react";import{Button as ue,BUTTON_VARIANT as ce,Text as F,Stack as P,Progress as pe}from"@donotdev/components";import{handleError as C,useTranslation as fe}from"@donotdev/core";import{useUploadContext as ge}from"../../../contexts/UploadContext";import{useUploadStore as H}from"../../../stores/UploadStore";import{uploadFile as me,deleteFile as ve,generateFileId as _,getFileIcon as he,formatFileSize as ye}from"../../../utils/fileStorage";function Fe({type:f,className:l}){switch(f){case"pdf":return t(z,{className:l,style:{color:"var(--destructive)"}});case"doc":return t(z,{className:l,style:{color:"var(--primary)"}});case"xls":return t(se,{className:l,style:{color:"var(--success)"}});case"ppt":return t(z,{className:l,style:{color:"var(--warning)"}});case"image":return t(te,{className:l});case"video":return t(oe,{className:l});case"audio":return t(ae,{className:l});case"archive":return t(ne,{className:l});case"html":case"text":return t(le,{className:l});default:return t(ee,{className:l})}}const V=de(({name:f,label:l,value:g,onChange:T,error:A,helperText:M,accept:q,multiple:d=!1,maxFiles:N=10,maxSize:k=50*1024*1024,storagePath:R="uploads/files",required:D},G)=>{const{t:K}=fe("crud"),i=K,m=ge(),E=!!m,[n,c]=B([]),[j,I]=B(!1),v=b(null),S=b(!1),w=b(void 0),x=y(e=>{const s=e.filter(r=>r.uploaded&&!r.error).map(r=>r.uploaded);T(d?s:s[0]||null)},[d,T]);O(()=>{if(S.current){S.current=!1;return}if(g){const e=[];(Array.isArray(g)?g:[g]).forEach(r=>{r.url&&e.push({id:_(),file:new File([],r.filename),uploadProgress:null,uploaded:r,error:null})}),c(e)}else c([])},[g]);const W=y(async()=>{const e=n.filter(s=>!s.uploaded&&!s.error&&s.uploadProgress===null);if(e.length!==0){c(s=>s.map(r=>e.some(o=>o.id===r.id)?{...r,uploadProgress:0}:r));for(const s of e)try{const r=await me(s.file,{storagePath:R,onProgress:o=>{c(a=>a.map(u=>u.id===s.id?{...u,uploadProgress:o.progress}:u))}});c(o=>{const a=o.map(u=>u.id===s.id?{...u,uploaded:r,uploadProgress:100,error:null}:u);return queueMicrotask(()=>x(a)),a})}catch{c(o=>o.map(a=>a.id===s.id?{...a,error:"Upload failed",uploadProgress:null}:a))}}},[n,R,x]);w.current=W,O(()=>{if(!(!m||!f))return H.getState().registerUpload(m,f,async e=>{await w.current?.()}),()=>{H.getState().unregisterUpload(m,f)}},[m,f]),ie(G,()=>({upload:async()=>{await w.current?.()},getFiles:()=>L.current||[]}),[]);const L=b(n);L.current=n;const U=y(e=>{const r=(d?N:1)-n.length;if(r<=0){C(new Error("Maximum files reached"),{userMessage:i("file.errors.maxFiles",{max:N}),severity:"warning",showNotification:!0});return}const o=e.slice(0,r),a=[],u=(k/(1024*1024)).toFixed(0);for(const h of o){if(h.size>k){C(new Error("File too large"),{userMessage:i("file.errors.exceedsSize",{fileName:h.name,size:u}),severity:"warning",showNotification:!0});continue}a.push({id:_(),file:h,uploadProgress:null,uploaded:null,error:null})}a.length!==0&&(c(h=>d?[...h,...a]:a),E||setTimeout(()=>w.current?.(),0))},[n,d,N,k,i,E]),X=e=>{const s=Array.from(e.target.files||[]);s.length>0&&U(s),v.current&&(v.current.value="")},J=y(e=>{e.preventDefault(),I(!1);const s=Array.from(e.dataTransfer.files);U(s)},[U]),Q=y(async e=>{const s=n.find(r=>r.id===e);if(s)try{s.uploaded&&await ve(s.uploaded);const r=n.filter(o=>o.id!==e);S.current=!0,c(r),setTimeout(()=>x(r),0)}catch(r){C(r,{userMessage:i("file.delete.failed"),severity:"error",showNotification:!0})}},[n,x,i]),Y=d||n.length===0,we=n.some(e=>!e.uploaded&&!e.error&&e.uploadProgress===null);return p(P,{gap:"tight",children:[p(F,{level:"body",align:"start",children:[l,D?"*":""]}),Y&&p("div",{role:"button",tabIndex:0,"aria-label":i(d?"file.upload.ariaLabelMultiple":"file.upload.ariaLabelSingle"),className:"dndev-surface","data-variant":A?"destructive":"default",style:{border:"var(--border-width) dashed",borderColor:j?"var(--primary)":A?"var(--destructive)":"var(--border)",borderRadius:"var(--radius-lg)",padding:"var(--gap-lg)",backgroundColor:j?"color-mix(in oklab, var(--primary) 5%, transparent)":"var(--surface)",transition:"border-color var(--dur-fast), background-color var(--dur-fast)",cursor:"pointer",outline:"none"},onDragOver:e=>{e.preventDefault(),I(!0)},onDragLeave:()=>I(!1),onDrop:J,onClick:()=>v.current?.click(),onKeyDown:e=>{(e.key==="Enter"||e.key===" ")&&(e.preventDefault(),v.current?.click())},children:[t("input",{ref:v,type:"file",accept:q,multiple:d,style:{display:"none"},onChange:X}),p(P,{align:"center",justify:"center",children:[t(Z,{className:"dndev-size-lg",style:{color:"var(--muted-foreground)"}}),t(F,{as:"p",variant:"muted",level:"small",align:"center",children:i(d?"file.upload.dragDropMultiple":"file.upload.dragDropSingle")})]})]}),n.length>0&&t(P,{gap:"tight",children:n.map((e,s)=>{const r=he(e.uploaded?.mimeType||e.file.type,e.file.name),o=e.uploadProgress!==null&&e.uploadProgress<100,a=e.uploaded&&!e.error;return p("div",{className:"dndev-surface","data-variant":"muted",style:{padding:"var(--gap-md)",borderRadius:"var(--radius-md)",display:"flex",alignItems:"center",gap:"var(--gap-md)"},children:[t(Fe,{type:r,className:"dndev-size-md"}),p(P,{gap:"none",style:{flex:1,minWidth:0},children:[t(F,{level:"small",style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.file.name}),p(F,{level:"caption",variant:"muted",children:[ye(e.uploaded?.size||e.file.size),e.error&&p("span",{style:{color:"var(--destructive)"},children:[" ","\xB7 ",e.error]})]}),o&&t(pe,{value:e.uploadProgress||0,max:100,style:{marginTop:"var(--gap-xs)"}})]}),o?t(re,{className:"dndev-size-sm",style:{animation:"spin 1s linear infinite"}}):t(ue,{variant:ce.GHOST,onClick:()=>Q(e.id),"aria-label":i("file.delete.ariaLabel"),children:t($,{className:"dndev-size-sm"})})]},e.id)})}),M&&t(F,{level:"caption",variant:A?"destructive":"muted",style:{marginTop:"var(--gap-xs)"},children:M})]})});V.displayName="FileFieldComponent";var Ue=V;export{Ue as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as n}from"react/jsx-runtime";import{Input as
|
|
1
|
+
import{jsx as e,jsxs as n}from"react/jsx-runtime";import{Input as u,Stack as p}from"@donotdev/components";import{useTranslation as m}from"@donotdev/core";const f=({label:s,value:d={},onChange:a,error:t,helperText:r,required:i})=>{const{t:l}=m("crud");return n(p,{gap:"tight",children:[n("div",{className:"dndev-surface","data-variant":t?"destructive":"default",style:{border:"1px solid",borderColor:t?"var(--destructive)":"var(--input)",borderRadius:"var(--radius-lg)",padding:"var(--gap-md)"},children:[e("p",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)",marginBottom:"var(--gap-md)"},children:"Map component placeholder"}),e(u,{label:s,type:"text",required:i,className:"dndev-w-full",placeholder:l("form.enterLocationData","Enter location data (JSON)"),value:JSON.stringify(d),onChange:c=>{try{const o=JSON.parse(c.target.value),v={target:{value:JSON.stringify(o)}};a(v)}catch{a({target:{value:"{}"}})}}})]}),r&&e("p",{style:{fontSize:"var(--font-size-xs)",color:t?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:r})]})};var x=f;export{x as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiDropdownComponent.d.ts","sourceRoot":"","sources":["../../../../src/components/form/fields/MultiDropdownComponent.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MultiDropdownComponent.d.ts","sourceRoot":"","sources":["../../../../src/components/form/fields/MultiDropdownComponent.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAOxD,MAAM,WAAW,2BAA2B;IAC1C,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,4BAA4B;IAC5B,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC/D,8BAA8B;IAC9B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,gCAAgC;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,WAAW,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;IACrE,mBAAmB;IACnB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,QAAA,MAAM,sBAAsB,EAAE,aAAa,CAAC,2BAA2B,CAsHtE,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as o,jsxs as s,Fragment as V}from"react/jsx-runtime";import{useMemo as _,useId as j}from"react";import{Combobox as M,Tag as h,Stack as p}from"@donotdev/components";import{useTranslation as N}from"@donotdev/core";const d=4,f=3,B=({label:S,value:t=[],options:i,error:b,helperText:a,onChange:u,onBlur:v,required:y,className:x})=>{const{t:m}=N("crud"),g=j(),I=_(()=>i.map(e=>({value:String(e.value),label:e.label})),[i]),O=e=>{const n=Array.isArray(e)?e:[e],r={target:{value:JSON.stringify(n)}};u(r)},z=e=>{e||v?.()},C=e=>{const n=t.filter(c=>c!==e),r={target:{value:JSON.stringify(n)}};u(r)},l=!!b,E=`${g}-error`,A=`${g}-helper`,L=t.length>0?s(V,{children:[t.slice(0,t.length>d?f:d).map((e,n)=>{const r=i.find(c=>String(c.value)===e)?.label||e;return o(h,{size:"sm",onRemove:()=>C(e),children:r},n)}),t.length>d&&s(h,{size:"sm",variant:"outline",disabled:!0,children:["+",t.length-f," more"]})]}):void 0;return s(p,{gap:"tight",className:x,children:[o(M,{label:S,value:t,onValueChange:O,onOpenChange:z,placeholder:m("actions.selectOptions","Select options..."),emptyMessage:m("messages.noResults","No results found"),options:I,multiple:!0,required:y,variant:l?"destructive":void 0,chips:L}),l&&s(p,{id:E,direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)",color:"var(--destructive-foreground)"},role:"alert",children:[o("span",{children:"\u26A0"}),a]}),a&&!l&&o("p",{id:A,style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:a})]})};var k=B;export{k as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as a,jsxs as d}from"react/jsx-runtime";import{useState as y}from"react";import{Input as h,Button as x,Stack as i}from"@donotdev/components";import{useTranslation as b}from"@donotdev/core";const w=({label:c,value:o=[],onChange:l,className:m,required:p})=>{const{t:s}=b("
|
|
1
|
+
"use client";import{jsx as a,jsxs as d}from"react/jsx-runtime";import{useState as y}from"react";import{Input as h,Button as x,Stack as i}from"@donotdev/components";import{useTranslation as b}from"@donotdev/core";const w=({label:c,value:o=[],onChange:l,className:m,required:p})=>{const{t:s}=b("crud"),[n,u]=y(""),f=()=>{if(n.trim()){const e=[...o,n.trim()],t={target:{value:JSON.stringify(e)}};l(t),u("")}},g=e=>{const t=o.filter((S,v)=>v!==e),r={target:{value:JSON.stringify(t)}};l(r)};return d(i,{className:m,children:[d(i,{direction:"row",align:"end",children:[a(h,{label:c,type:"text",value:n,onChange:e=>u(e.target.value),required:p,className:"dndev-flex-1",placeholder:s("form.typeAndPressAdd","Type and press Add...")}),a(x,{type:"button",onClick:f,disabled:!n.trim(),children:s("form.add","Add")})]}),a(i,{direction:"row",wrap:"wrap",children:o.map((e,t)=>d("span",{className:"dndev-surface","data-variant":"muted",style:{display:"inline-flex",alignItems:"center",gap:"var(--gap-sm)",padding:"var(--gap-sm) var(--gap-md)",fontSize:"var(--font-size-sm)",fontWeight:500,borderRadius:"var(--radius-lg)"},children:[e,a("button",{type:"button",onClick:()=>g(t),style:{color:"var(--muted-foreground)",marginInlineStart:"var(--gap-sm)"},onMouseEnter:r=>{r.currentTarget.style.color="var(--foreground)"},onMouseLeave:r=>{r.currentTarget.style.color="var(--muted-foreground)"},"aria-label":`${s("form.remove","Remove")} ${e}`,children:"\xD7"})]},t))})]})};var j=w;export{j as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwitchFieldComponent.d.ts","sourceRoot":"","sources":["../../../../src/components/form/fields/SwitchFieldComponent.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SwitchFieldComponent.d.ts","sourceRoot":"","sources":["../../../../src/components/form/fields/SwitchFieldComponent.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAExD,MAAM,WAAW,yBAAyB;IACxC,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IAC1D,iDAAiD;IACjD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kDAAkD;IAClD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kBAAkB;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;GASG;AACH,QAAA,MAAM,oBAAoB,EAAE,aAAa,CAAC,yBAAyB,CAuClE,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as e,jsx as
|
|
1
|
+
import{jsxs as e,jsx as l}from"react/jsx-runtime";import{Switch as m,Text as c,Stack as i}from"@donotdev/components";const p=({label:a,checked:n=!1,onChange:t,uncheckedLabel:d,checkedLabel:s,helperText:r})=>{const h=o=>{t&&t({target:{checked:o}})};return e(i,{gap:"tight",children:[e(i,{direction:"row",align:"center",style:{flexWrap:"wrap"},children:[e(c,{level:"body",align:"start",children:[a,":"]}),l(m,{checked:n,onCheckedChange:h,"aria-label":a,variant:"muted",uncheckedLabel:d,checkedLabel:s})]}),r&&l(c,{as:"p",variant:"muted",level:"small",children:r})]})};var x=p;export{x as default};
|
|
@@ -13,7 +13,7 @@ import type { ControlledFieldProps, UncontrolledFieldProps } from './FieldRegist
|
|
|
13
13
|
/**
|
|
14
14
|
* Filter type metadata for EntityFilters component
|
|
15
15
|
*/
|
|
16
|
-
export type FilterType = 'text' | 'range' | 'select' | 'none' | 'address' | 'multiselect';
|
|
16
|
+
export type FilterType = 'text' | 'range' | 'select' | 'none' | 'address' | 'multiselect' | 'rating';
|
|
17
17
|
/**
|
|
18
18
|
* Value type for type checking
|
|
19
19
|
*/
|
|
@@ -24,6 +24,8 @@ export type ValueType = 'string' | 'number' | 'boolean' | 'date' | 'object' | 'a
|
|
|
24
24
|
export type DisplayFormatterOptions = {
|
|
25
25
|
compact?: boolean;
|
|
26
26
|
asString?: boolean;
|
|
27
|
+
/** Pre-resolved reference data: { collectionName: { id: displayLabel } } */
|
|
28
|
+
referenceData?: Record<string, Record<string, string>>;
|
|
27
29
|
};
|
|
28
30
|
export type DisplayFormatter = (value: any, config: EntityField, t: (key: string, options?: Record<string, any>) => string, options?: DisplayFormatterOptions) => string | ReactElement;
|
|
29
31
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fieldTypeRegistry.d.ts","sourceRoot":"","sources":["../src/fieldTypeRegistry.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAI7D,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,iBAAiB,CAAC;AAEzB;;GAEG;AACH,MAAM,MAAM,UAAU,GAClB,MAAM,GACN,OAAO,GACP,QAAQ,GACR,MAAM,GACN,SAAS,GACT,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"fieldTypeRegistry.d.ts","sourceRoot":"","sources":["../src/fieldTypeRegistry.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAI7D,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,iBAAiB,CAAC;AAEzB;;GAEG;AACH,MAAM,MAAM,UAAU,GAClB,MAAM,GACN,OAAO,GACP,QAAQ,GACR,MAAM,GACN,SAAS,GACT,aAAa,GACb,QAAQ,CAAC;AAEb;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,MAAM,GACN,QAAQ,GACR,OAAO,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,4EAA4E;IAC5E,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACxD,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,CAC7B,KAAK,EAAE,GAAG,EACV,MAAM,EAAE,WAAW,EACnB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,EACzD,OAAO,CAAC,EAAE,uBAAuB,KAC9B,MAAM,GAAG,YAAY,CAAC;AAE3B;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,aAAa,CAAC,oBAAoB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAC1D,YAAY,CAAC,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;CACtD;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,4BAA4B;IAC5B,IAAI,EAAE,SAAS,CAAC;IAChB,4CAA4C;IAC5C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,uCAAuC;IACvC,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,iCAAiC;IACjC,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,yBAAyB;IACzB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,oBAAoB;IACpB,UAAU,CAAC,EAAE,qBAAqB,CAAC;CACpC;AAOD;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAmB1E;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,GACX,iBAAiB,GAAG,SAAS,CAE/B;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CAIlE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,GACX,gBAAgB,GAAG,SAAS,CAI9B;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGlD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAEhE;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C"}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -7,4 +7,7 @@ export { useCrudFilters } from './useCrudFilters';
|
|
|
7
7
|
export type { UseCrudFiltersOptions, UseCrudFiltersReturn, } from './useCrudFilters';
|
|
8
8
|
export { useRelatedItems } from './useRelatedItems';
|
|
9
9
|
export type { UseRelatedItemsOptions, UseRelatedItemsReturn, } from './useRelatedItems';
|
|
10
|
+
export { useFieldConditions } from './useFieldConditions';
|
|
11
|
+
export { useReferenceResolver } from './useReferenceResolver';
|
|
12
|
+
export type { ReferenceData } from './useReferenceResolver';
|
|
10
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,YAAY,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAE1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,YAAY,EACV,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EACV,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EACV,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,YAAY,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAE1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,YAAY,EACV,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,YAAY,EACV,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EACV,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/hooks/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useFileUpload as o}from"./useFileUpload";import{useUnsavedChangesWarning as
|
|
1
|
+
import{useFileUpload as o}from"./useFileUpload";import{useUnsavedChangesWarning as t}from"./useUnsavedChangesWarning";import{useEntityFavorites as i}from"./useEntityFavorites";import{useCrudFilters as n}from"./useCrudFilters";import{useRelatedItems as u}from"./useRelatedItems";import{useFieldConditions as a}from"./useFieldConditions";import{useReferenceResolver as l}from"./useReferenceResolver";export{n as useCrudFilters,i as useEntityFavorites,a as useFieldConditions,o as useFileUpload,l as useReferenceResolver,u as useRelatedItems,t as useUnsavedChangesWarning};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Control, FieldValues } from 'react-hook-form';
|
|
2
|
+
import type { ConditionResult } from '@donotdev/core';
|
|
3
|
+
import type { RenderableField } from '../forms/utils/getFieldsForOperation';
|
|
4
|
+
/**
|
|
5
|
+
* Evaluate field conditions against live form values.
|
|
6
|
+
*
|
|
7
|
+
* @param fields - Array of renderable fields (from useEntityForm or getFieldsForOperation)
|
|
8
|
+
* @param control - React Hook Form control object
|
|
9
|
+
* @returns Record mapping field names to their computed condition states.
|
|
10
|
+
* Fields without conditions are not included — treat missing entries as defaults.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* function MyForm({ entity }) {
|
|
15
|
+
* const { fields, control } = useEntityForm(entity, { operation: 'create' });
|
|
16
|
+
* const conditions = useFieldConditions(fields, control);
|
|
17
|
+
*
|
|
18
|
+
* return fields.map(({ name, config }) => {
|
|
19
|
+
* const cond = conditions[name];
|
|
20
|
+
* if (cond && !cond.visible) return null;
|
|
21
|
+
* return <FormField key={name} disabled={cond?.disabled} required={cond?.required} />;
|
|
22
|
+
* });
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function useFieldConditions<TFieldValues extends FieldValues = FieldValues>(fields: readonly RenderableField[], control: Control<TFieldValues>): Record<string, ConditionResult>;
|
|
27
|
+
//# sourceMappingURL=useFieldConditions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFieldConditions.d.ts","sourceRoot":"","sources":["../../src/hooks/useFieldConditions.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,kBAAkB,CAChC,YAAY,SAAS,WAAW,GAAG,WAAW,EAE9C,MAAM,EAAE,SAAS,eAAe,EAAE,EAClC,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,GAC7B,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAwBjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import{useMemo as r}from"react";import{useWatch as c}from"react-hook-form";import{evaluateFieldConditions as u}from"@donotdev/core";function d(o,s){const t=c({control:s}),e=r(()=>o.some(n=>n.config.conditions),[o]);return r(()=>{if(!e)return{};const n={};for(const i of o)i.config.conditions&&(n[i.name]=u(i.config.conditions,t));return n},[o,t,e])}export{d as useFieldConditions};
|