@donotdev/crud 0.0.13 → 0.0.15
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/README.md +27 -19
- package/dist/CrudService.d.ts +84 -11
- package/dist/CrudService.d.ts.map +1 -1
- package/dist/CrudService.js +9 -1
- package/dist/CrudStore.d.ts.map +1 -1
- package/dist/CrudStore.js +1 -1
- package/dist/FieldRegistry.d.ts +40 -13
- package/dist/FieldRegistry.d.ts.map +1 -1
- package/dist/FieldRegistry.js +1 -1
- package/dist/adapters/FunctionsAdapter.d.ts +20 -26
- package/dist/adapters/FunctionsAdapter.d.ts.map +1 -1
- package/dist/adapters/FunctionsAdapter.js +1 -1
- package/dist/adapters/index.d.ts +0 -1
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +1 -1
- package/dist/components/CrudCard.d.ts +8 -0
- package/dist/components/CrudCard.d.ts.map +1 -0
- package/dist/components/CrudCard.js +1 -0
- package/dist/components/DateFilter.d.ts +30 -0
- package/dist/components/DateFilter.d.ts.map +1 -0
- package/dist/components/DateFilter.js +1 -0
- package/dist/components/DisplayThumbnail.d.ts +29 -0
- package/dist/components/DisplayThumbnail.d.ts.map +1 -0
- package/dist/components/DisplayThumbnail.js +1 -0
- package/dist/components/EntityFilters.d.ts +28 -15
- package/dist/components/EntityFilters.d.ts.map +1 -1
- package/dist/components/EntityFilters.js +1 -1
- package/dist/components/FormLayout.d.ts.map +1 -1
- package/dist/components/FormLayout.js +1 -1
- package/dist/components/__tests__/EntityFilters.test.d.ts +2 -0
- package/dist/components/__tests__/EntityFilters.test.d.ts.map +1 -0
- package/dist/components/__tests__/EntityFilters.test.js +1 -0
- package/dist/components/__tests__/FormFieldRenderer.test.d.ts +2 -0
- package/dist/components/__tests__/FormFieldRenderer.test.d.ts.map +1 -0
- package/dist/components/__tests__/FormFieldRenderer.test.js +1 -0
- package/dist/components/controlled/file/ControlledMultiImageField.js +1 -1
- package/dist/components/fields/display/FileFieldDisplay.js +1 -1
- package/dist/components/fields/display/MultiDropdownDisplay.js +1 -1
- package/dist/components/fields/display/MultiInputTextFieldDisplay.js +1 -1
- package/dist/components/fields/display/PasswordFieldDisplay.js +1 -1
- package/dist/components/fields/display/RichTextDisplay.d.ts.map +1 -1
- package/dist/components/fields/display/RichTextDisplay.js +2 -2
- package/dist/components/form/fields/AddressFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/AddressFieldComponent.js +1 -1
- package/dist/components/form/fields/AvatarFieldComponent.js +1 -1
- package/dist/components/form/fields/BadgeFieldComponent.js +1 -1
- package/dist/components/form/fields/DocumentFieldComponent.js +1 -1
- package/dist/components/form/fields/DurationFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/DurationFieldComponent.js +1 -1
- package/dist/components/form/fields/FileFieldComponent.js +1 -1
- package/dist/components/form/fields/GeoPointFieldComponent.js +1 -1
- package/dist/components/form/fields/ImageFieldComponent.js +1 -1
- package/dist/components/form/fields/MultiDropdownComponent.js +1 -1
- package/dist/components/form/fields/MultiInputTextFieldComponent.js +1 -1
- package/dist/components/form/fields/PhoneNumberComponent.d.ts.map +1 -1
- package/dist/components/form/fields/PriceFieldComponent.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/components/form/fields/internal/TiptapEditor.d.ts +4 -2
- package/dist/components/form/fields/internal/TiptapEditor.d.ts.map +1 -1
- package/dist/components/form/fields/internal/TiptapEditor.js +2 -2
- package/dist/components/form/internal/ImageViewerDialog.d.ts.map +1 -1
- package/dist/components/form/internal/ImageViewerDialog.js +1 -1
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/fieldTypeRegistry.d.ts +3 -0
- package/dist/fieldTypeRegistry.d.ts.map +1 -1
- package/dist/fieldTypeRegistry.js +1 -1
- package/dist/forms/hooks/useEntityForm.d.ts.map +1 -1
- package/dist/forms/hooks/useEntityForm.js +1 -1
- package/dist/forms/utils/getFieldsForOperation.d.ts.map +1 -1
- package/dist/forms/utils/translateFieldLabel.d.ts.map +1 -1
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/useCrudFilters.d.ts +17 -0
- package/dist/hooks/useCrudFilters.d.ts.map +1 -0
- package/dist/hooks/useCrudFilters.js +1 -0
- package/dist/hooks/useFileUpload.d.ts.map +1 -1
- package/dist/hooks/useFileUpload.js +1 -1
- package/dist/hooks/useFormNavigationGuard.d.ts.map +1 -1
- package/dist/hooks/useFormNavigationGuard.js +1 -1
- package/dist/hooks/useRelatedItems.d.ts +1 -2
- package/dist/hooks/useRelatedItems.d.ts.map +1 -1
- package/dist/hooks/useRelatedItems.js +1 -1
- package/dist/index.d.ts +6 -4
- 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/stores/FormStore.d.ts.map +1 -1
- package/dist/stores/FormStore.js +1 -1
- package/dist/stores/UploadStore.d.ts.map +1 -1
- package/dist/stores/UploadStore.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +26 -20
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/dist/useBaseCrudList.d.ts +1 -4
- package/dist/useBaseCrudList.d.ts.map +1 -1
- package/dist/useBaseCrudList.js +1 -1
- package/dist/useCrud.d.ts +1 -2
- package/dist/useCrud.d.ts.map +1 -1
- package/dist/useCrud.js +1 -1
- package/dist/useCrudCardList.d.ts +1 -2
- package/dist/useCrudCardList.d.ts.map +1 -1
- package/dist/useCrudCardList.js +1 -1
- package/dist/useCrudList.d.ts +1 -1
- package/dist/useCrudList.d.ts.map +1 -1
- package/dist/useCrudList.js +1 -1
- package/dist/utils/fileStorage.d.ts +10 -5
- package/dist/utils/fileStorage.d.ts.map +1 -1
- package/dist/utils/fileStorage.js +1 -1
- package/dist/utils/imageStorage.d.ts +9 -4
- package/dist/utils/imageStorage.d.ts.map +1 -1
- package/dist/utils/imageStorage.js +1 -1
- package/dist/utils/mergeWithOptimistic.d.ts.map +1 -1
- package/dist/utils/mergeWithOptimistic.js +1 -1
- package/dist/utils/sanitizeHtml.d.ts +6 -0
- package/dist/utils/sanitizeHtml.d.ts.map +1 -0
- package/dist/utils/sanitizeHtml.js +1 -0
- package/dist/utils/scopeUtils.d.ts +1 -2
- package/dist/utils/scopeUtils.d.ts.map +1 -1
- package/dist/utils/scopeUtils.js +1 -1
- package/dist/utils/uploadValidation.d.ts +5 -4
- package/dist/utils/uploadValidation.d.ts.map +1 -1
- package/dist/utils/uploadValidation.js +1 -1
- package/package.json +12 -6
- package/dist/adapters/FirestoreAdapter.d.ts +0 -65
- package/dist/adapters/FirestoreAdapter.d.ts.map +0 -1
- package/dist/adapters/FirestoreAdapter.js +0 -1
- package/dist/components/EntityDisplayRenderer.d.ts +0 -43
- package/dist/components/EntityDisplayRenderer.d.ts.map +0 -1
- package/dist/components/EntityDisplayRenderer.js +0 -1
- package/dist/components/EntityFormRenderer.d.ts +0 -86
- package/dist/components/EntityFormRenderer.d.ts.map +0 -1
- package/dist/components/EntityFormRenderer.js +0 -1
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { dndevSchema } from '@donotdev/core';
|
|
2
|
-
import { type Unsubscribe, type FirestoreError } from '@donotdev/firebase';
|
|
3
|
-
import type { PaginatedQueryResult } from './FunctionsAdapter';
|
|
4
|
-
/**
|
|
5
|
-
* Firestore query operators
|
|
6
|
-
*/
|
|
7
|
-
export type FirestoreOperator = '==' | '!=' | '<' | '<=' | '>' | '>=' | 'array-contains' | 'in' | 'not-in';
|
|
8
|
-
/**
|
|
9
|
-
* Query options for Firestore queries
|
|
10
|
-
*
|
|
11
|
-
* @version 0.0.1
|
|
12
|
-
* @since 0.0.1
|
|
13
|
-
* @author AMBROISE PARK Consulting
|
|
14
|
-
*/
|
|
15
|
-
export interface QueryOptions {
|
|
16
|
-
where?: Array<{
|
|
17
|
-
field: string;
|
|
18
|
-
operator: FirestoreOperator;
|
|
19
|
-
value: unknown;
|
|
20
|
-
}>;
|
|
21
|
-
orderBy?: Array<{
|
|
22
|
-
field: string;
|
|
23
|
-
direction?: 'asc' | 'desc';
|
|
24
|
-
}>;
|
|
25
|
-
limit?: number;
|
|
26
|
-
startAfterId?: string;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Subscription callback for document subscriptions
|
|
30
|
-
*
|
|
31
|
-
* @version 0.0.1
|
|
32
|
-
* @since 0.0.1
|
|
33
|
-
* @author AMBROISE PARK Consulting
|
|
34
|
-
*/
|
|
35
|
-
export type SubscriptionCallback<T> = (data: T | null, error?: FirestoreError) => void;
|
|
36
|
-
/**
|
|
37
|
-
* Subscription callback for collection subscriptions
|
|
38
|
-
*
|
|
39
|
-
* @version 0.0.1
|
|
40
|
-
* @since 0.0.1
|
|
41
|
-
* @author AMBROISE PARK Consulting
|
|
42
|
-
*/
|
|
43
|
-
export type CollectionSubscriptionCallback<T> = (data: T[], error?: FirestoreError) => void;
|
|
44
|
-
/**
|
|
45
|
-
* Firestore backend adapter
|
|
46
|
-
* Works with any collection dynamically (collection name passed per operation)
|
|
47
|
-
*
|
|
48
|
-
* @version 0.0.1
|
|
49
|
-
* @since 0.0.1
|
|
50
|
-
* @author AMBROISE PARK Consulting
|
|
51
|
-
*/
|
|
52
|
-
export declare class FirestoreAdapter {
|
|
53
|
-
private firestore;
|
|
54
|
-
private ensureFirestore;
|
|
55
|
-
private getCollectionRef;
|
|
56
|
-
get<T>(collectionName: string, id: string, schema: dndevSchema<unknown>): Promise<T | null>;
|
|
57
|
-
set<T>(collectionName: string, id: string, data: T, schema: dndevSchema<T>): Promise<void>;
|
|
58
|
-
update<T>(collectionName: string, id: string, data: Partial<T>): Promise<void>;
|
|
59
|
-
delete(collectionName: string, id: string): Promise<void>;
|
|
60
|
-
add<T>(collectionName: string, data: T, schema: dndevSchema<T>): Promise<string>;
|
|
61
|
-
query<T>(collectionName: string, options: QueryOptions, schema: dndevSchema<unknown>, _schemaType?: 'list' | 'listCard'): Promise<PaginatedQueryResult<T>>;
|
|
62
|
-
subscribe<T>(collectionName: string, id: string, callback: SubscriptionCallback<T>, schema: dndevSchema<unknown>): Unsubscribe;
|
|
63
|
-
subscribeToCollection<T>(collectionName: string, options: QueryOptions, callback: CollectionSubscriptionCallback<T>, schema: dndevSchema<unknown>): Unsubscribe;
|
|
64
|
-
}
|
|
65
|
-
//# sourceMappingURL=FirestoreAdapter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FirestoreAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/FirestoreAdapter.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAsBL,KAAK,WAAW,EAChB,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAO5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,IAAI,GACJ,IAAI,GACJ,GAAG,GACH,IAAI,GACJ,GAAG,GACH,IAAI,GACJ,gBAAgB,GAChB,IAAI,GACJ,QAAQ,CAAC;AAEb;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,iBAAiB,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAC9E,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/D,KAA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AO,EAAE,YAAY,EACrB,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,EAC5B,WAAW,GAAE,MAAM,GAAG,UAAmB,GACxC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IA6FnC,SAAS,CAAC,CAAC,EACT,cAAc,EAAE,MAAM,EACtB,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,oBAAoB,CAAC,CAAC,CAAC,EACjC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAC3B,WAAW;IA8Bd,qBAAqB,CAAC,CAAC,EACrB,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,YAAY,EACrB,QAAQ,EAAE,8BAA8B,CAAC,CAAC,CAAC,EAC3C,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAC3B,WAAW;CAgDf"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import*as h from"valibot";import{handleError as m}from"@donotdev/core";import{getFirestore as B,getFirebaseSDK as C,doc as p,getDoc as w,getDocs as E,setDoc as v,updateDoc as V,deleteDoc as z,addDoc as M,collection as L,query as A,where as D,orderBy as R,limit as I,startAfter as S,onSnapshot as q}from"@donotdev/firebase";import{transformFirestoreData as F,prepareForFirestore as g}from"@donotdev/firebase";class W{firestore;ensureFirestore(){if(this.firestore)return!0;try{return this.firestore=B(),!0}catch{return!1}}getCollectionRef(s){return!this.ensureFirestore()||!this.firestore?null:L(this.firestore,s)}async get(s,e,t){if(!this.ensureFirestore()||!this.firestore)return null;try{const o=p(this.firestore,s,e),i=await w(o);if(!i.exists())return null;let r=i.data();return r=F(r),{...h.parse(t,r),id:e}}catch(o){return m(o,{context:{operation:"FirestoreAdapter.get",collection:s,docId:e},severity:"warning"}),null}}async set(s,e,t,o){if(!(!this.ensureFirestore()||!this.firestore))try{h.parse(o,t);const i=p(this.firestore,s,e),r=g(t);await v(i,r)}catch(i){throw i}}async update(s,e,t){if(!(!this.ensureFirestore()||!this.firestore))try{const o=p(this.firestore,s,e),i=g(t);await V(o,i)}catch(o){throw o}}async delete(s,e){if(!(!this.ensureFirestore()||!this.firestore))try{const t=p(this.firestore,s,e);await z(t)}catch(t){throw t}}async add(s,e,t){if(!this.ensureFirestore())return"";try{h.parse(t,e);const o=this.getCollectionRef(s);if(!o)return"";const i=new Date().toISOString(),r=C().getCurrentUser()?.uid||"anonymous",n={...e,createdAt:i,updatedAt:i,createdById:r,updatedById:r},a=g(n);return(await M(o,a)).id}catch(o){throw o}}async query(s,e,t,o="list"){if(!this.ensureFirestore())return{items:[]};const i=this.getCollectionRef(s);if(!i)return{items:[]};try{const r=[];if(e.where)for(const c of e.where)r.push(D(c.field,c.operator,c.value));if(e.orderBy)for(const c of e.orderBy)r.push(R(c.field,c.direction||"asc"));if(e.startAfterId){const c=await w(p(i,e.startAfterId));c.exists()&&r.push(S(c))}const n=e.limit?e.limit+1:void 0;n&&r.push(I(n));const a=A(i,...r),d=await E(a),f=[];let l=null;d.forEach(c=>{try{let u=c.data();if(!u)return;u=F(u);const x=h.parse(t,u);f.push({...x,id:c.id}),l=c.id}catch(u){m(u,{context:{operation:"FirestoreAdapter.query.parse",docId:c.id,collection:s},showNotification:!1})}});const y=n?f.length>(e.limit||0):!1;return{items:y?f.slice(0,e.limit):f,hasMore:y,lastVisible:l,total:void 0}}catch(r){throw m(r,{context:{operation:"FirestoreAdapter.query",collection:s,options:e}}),r}}subscribe(s,e,t,o){if(!this.ensureFirestore()||!this.firestore)return()=>{};const i=p(this.firestore,s,e);return q(i,r=>{try{if(!r.exists()){t(null);return}let n=r.data();n=F(n);const a=h.parse(o,n);t({...a,id:e})}catch(n){t(null,n)}},r=>{t(null,r)})}subscribeToCollection(s,e,t,o){if(!this.ensureFirestore())return()=>{};const i=this.getCollectionRef(s);if(!i)return()=>{};try{const r=[];if(e.where)for(const a of e.where)r.push(D(a.field,a.operator,a.value));if(e.orderBy)for(const a of e.orderBy)r.push(R(a.field,a.direction||"asc"));e.limit&&r.push(I(e.limit));const n=A(i,...r);return q(n,a=>{try{const d=[];a.forEach(f=>{let l=f.data();l=F(l);const y=h.parse(o,l);d.push({...y,id:f.id})}),t(d)}catch(d){t([],d)}},a=>{t([],a)})}catch(r){return t([],r),()=>{}}}}export{W as FirestoreAdapter};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { Entity } from '@donotdev/core';
|
|
2
|
-
export interface EntityDisplayRendererProps<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
3
|
-
/** Entity definition - pass the full entity from defineEntity() */
|
|
4
|
-
entity: Entity;
|
|
5
|
-
/** Entity ID to fetch */
|
|
6
|
-
id: string;
|
|
7
|
-
/** Translation function (optional - auto-generated if not provided) */
|
|
8
|
-
t?: (key: string, options?: Record<string, unknown>) => string;
|
|
9
|
-
/** Additional CSS classes */
|
|
10
|
-
className?: string;
|
|
11
|
-
/** Backend to use */
|
|
12
|
-
backend?: 'firestore' | 'functions';
|
|
13
|
-
/** Custom loading message */
|
|
14
|
-
loadingMessage?: string;
|
|
15
|
-
/** Custom not found message */
|
|
16
|
-
notFoundMessage?: string;
|
|
17
|
-
/**
|
|
18
|
-
* Current viewer's role for visibility checks
|
|
19
|
-
* Used to determine which fields should be visible based on their visibility setting
|
|
20
|
-
* If not provided, defaults to 'guest' (most restrictive - shows only public fields)
|
|
21
|
-
* @default 'guest'
|
|
22
|
-
*/
|
|
23
|
-
viewerRole?: string;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* EntityDisplayRenderer - Automatically fetches and displays entity data
|
|
27
|
-
*
|
|
28
|
-
* Features:
|
|
29
|
-
* - Automatic data fetching using useCrud
|
|
30
|
-
* - Loading state handling
|
|
31
|
-
* - Error handling
|
|
32
|
-
* - Automatic field rendering (respects visibility rules)
|
|
33
|
-
* - Full i18n support
|
|
34
|
-
* - No form/submit buttons - pure read-only display
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```tsx
|
|
38
|
-
* <EntityDisplayRenderer entity={carEntity} id={carId} />
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export declare function EntityDisplayRenderer<T extends Record<string, unknown> = Record<string, unknown>>({ entity, id, t, className, backend, loadingMessage, notFoundMessage, viewerRole, }: EntityDisplayRendererProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
42
|
-
export default EntityDisplayRenderer;
|
|
43
|
-
//# sourceMappingURL=EntityDisplayRenderer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EntityDisplayRenderer.d.ts","sourceRoot":"","sources":["../../src/components/EntityDisplayRenderer.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAK7C,MAAM,WAAW,0BAA0B,CACzC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAE3D,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,yBAAyB;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,uEAAuE;IACvE,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC;IAC/D,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qBAAqB;IACrB,OAAO,CAAC,EAAE,WAAW,GAAG,WAAW,CAAC;IACpC,6BAA6B;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,+BAA+B;IAC/B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACnC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,EACA,MAAM,EACN,EAAE,EACF,CAAC,EACD,SAAc,EACd,OAAqB,EACrB,cAAc,EACd,eAAe,EACf,UAAoB,GACrB,EAAE,0BAA0B,CAAC,CAAC,CAAC,2CAgM/B;AAED,eAAe,qBAAqB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use client";import{jsx as n,jsxs as O}from"react/jsx-runtime";import{useEffect as _,useState as m,useMemo as I}from"react";import{Stack as p,Spinner as M}from"@donotdev/components";import{useTranslation as v,isFieldVisible as R}from"@donotdev/core";import{DisplayFieldRenderer as T}from"./DisplayFieldRenderer";import{useCrud as $}from"../useCrud";function q({entity:i,id:o,t:E,className:f="",backend:b="functions",loadingMessage:j,notFoundMessage:x,viewerRole:g="guest"}){const{get:d,loading:F,data:A,error:S,isAvailable:y}=$(i,{backend:b}),[D,u]=m(!1),[V,s]=m(null),[k,c]=m(null),{t:w}=v([i.namespace,"crud"]),{t:h}=v("crud"),z=E||w;_(()=>{if(!o){c(null),s(null),u(!1);return}if(!y||!d)return;let t=!1;return u(!0),s(null),d(o).then(r=>{t||(u(!1),r?(c(r),s(null)):(c(null),s(new Error("Entity not found"))))}).catch(r=>{t||(u(!1),s(r instanceof Error?r:new Error(String(r))),c(null))}),()=>{t=!0}},[o,d,y]);const l=A||k,a=S||V,C=F||D||!o,L=I(()=>l?Object.entries(i.fields).filter(([t,r])=>{if(!R(r.visibility,g)||r.visibility==="hidden")return!1;const e=l[t];return!(e==null||typeof e=="string"&&e.trim()===""||Array.isArray(e)&&e.length===0||typeof e=="object"&&!Array.isArray(e)&&e!==null&&Object.keys(e).length===0)}):[],[i.fields,g,l]);return C?n("div",{style:{position:"relative",width:"100%",gridColumn:"1 / -1",display:"contents"},className:f,children:n(M,{overlay:!0,"aria-label":j||h("form.loading",{defaultValue:"Loading..."})})}):a||!l?n(p,{align:"center",justify:"center",gap:"medium",style:{padding:"var(--gap-3xl)",textAlign:"center"},className:f,children:O(p,{direction:"column",gap:"tight",children:[n("h3",{style:{color:"var(--muted-foreground)"},children:x||h("errors.notFound",{defaultValue:`${i.name} not found`})}),a&&n("p",{style:{color:"var(--destructive)",fontSize:"var(--font-size-sm)"},children:a instanceof Error?a.message:String(a)})]})}):n(p,{direction:"column",gap:"medium",className:f,children:L.map(([t,r])=>n(T,{name:t,config:r,value:l[t],t:z},t))})}var Q=q;export{q as EntityDisplayRenderer,Q as default};
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import type { Entity } from '@donotdev/core';
|
|
2
|
-
import type { ViewerRole } from '../forms/utils';
|
|
3
|
-
interface EntityFormRendererProps<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
4
|
-
/** Entity definition - pass the full entity from defineEntity() */
|
|
5
|
-
entity: Entity;
|
|
6
|
-
/** Form submission handler */
|
|
7
|
-
onSubmit: (data: T) => void | Promise<void>;
|
|
8
|
-
/** Translation function */
|
|
9
|
-
t?: (key: string, options?: Record<string, unknown>) => string;
|
|
10
|
-
/** Additional CSS classes */
|
|
11
|
-
className?: string;
|
|
12
|
-
/** Submit button text */
|
|
13
|
-
submitText?: string;
|
|
14
|
-
/**
|
|
15
|
-
* Whether form data is loading (shows loading overlay)
|
|
16
|
-
* Use this when fetching existing entity data for edit mode
|
|
17
|
-
*/
|
|
18
|
-
loading?: boolean;
|
|
19
|
-
/** Initial form values */
|
|
20
|
-
defaultValues?: Partial<T>;
|
|
21
|
-
/** Submit button variant */
|
|
22
|
-
submitVariant?: 'primary' | 'destructive' | 'outline' | 'ghost' | 'link';
|
|
23
|
-
/** Secondary button text */
|
|
24
|
-
secondaryButtonText?: string;
|
|
25
|
-
/** Secondary button variant */
|
|
26
|
-
secondaryButtonVariant?: 'primary' | 'destructive' | 'outline' | 'ghost' | 'link';
|
|
27
|
-
/** Secondary button submission handler */
|
|
28
|
-
onSecondarySubmit?: (data: T) => void | Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* Current viewer's role for editability checks
|
|
31
|
-
* @default 'admin'
|
|
32
|
-
*/
|
|
33
|
-
viewerRole?: ViewerRole;
|
|
34
|
-
/**
|
|
35
|
-
* Form operation type
|
|
36
|
-
* @default 'create' (or 'edit' if defaultValues provided)
|
|
37
|
-
*/
|
|
38
|
-
operation?: 'create' | 'edit';
|
|
39
|
-
/**
|
|
40
|
-
* Enable auto-save to localStorage for crash recovery.
|
|
41
|
-
* @default true for create mode
|
|
42
|
-
*/
|
|
43
|
-
autoSave?: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Optional form ID for tracking loading state.
|
|
46
|
-
* If not provided, one will be generated automatically.
|
|
47
|
-
*/
|
|
48
|
-
formId?: string;
|
|
49
|
-
/**
|
|
50
|
-
* Cancel button text. If provided, shows a cancel button.
|
|
51
|
-
* If not provided but onCancel is provided, shows default "Cancel" text.
|
|
52
|
-
* Set to null to explicitly hide cancel button.
|
|
53
|
-
*/
|
|
54
|
-
cancelText?: string | null;
|
|
55
|
-
/**
|
|
56
|
-
* Callback when cancel is clicked (after confirmation if dirty).
|
|
57
|
-
* If not provided, cancel just resets the form.
|
|
58
|
-
* If provided, cancel button will show (with cancelText or default "Cancel").
|
|
59
|
-
*/
|
|
60
|
-
onCancel?: () => void;
|
|
61
|
-
/**
|
|
62
|
-
* Whether to show unsaved changes warning when navigating away.
|
|
63
|
-
* @default true
|
|
64
|
-
*/
|
|
65
|
-
warnOnUnsavedChanges?: boolean;
|
|
66
|
-
/**
|
|
67
|
-
* Custom message for unsaved changes confirmation.
|
|
68
|
-
*/
|
|
69
|
-
unsavedChangesMessage?: string;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* EntityFormRenderer - Dumb component that renders a form from entity definition.
|
|
73
|
-
*
|
|
74
|
-
* All orchestration (uploads, validation, status tracking) is handled by useEntityForm.
|
|
75
|
-
* This component just:
|
|
76
|
-
* - Generates formId
|
|
77
|
-
* - Renders fields
|
|
78
|
-
* - Renders submit button with status from useEntityForm
|
|
79
|
-
*
|
|
80
|
-
* @version 0.0.6
|
|
81
|
-
* @since 0.0.1
|
|
82
|
-
* @author AMBROISE PARK Consulting
|
|
83
|
-
*/
|
|
84
|
-
export declare function EntityFormRenderer<T extends Record<string, any> = any>({ entity, onSubmit, t, className, submitText, loading, defaultValues, submitVariant, secondaryButtonText, secondaryButtonVariant, onSecondarySubmit, viewerRole, operation, autoSave, formId: externalFormId, cancelText, onCancel, warnOnUnsavedChanges, unsavedChangesMessage, }: EntityFormRendererProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
85
|
-
export default EntityFormRenderer;
|
|
86
|
-
//# sourceMappingURL=EntityFormRenderer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EntityFormRenderer.d.ts","sourceRoot":"","sources":["../../src/components/EntityFormRenderer.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAY7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,UAAU,uBAAuB,CAC/B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAE3D,mEAAmE;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,2BAA2B;IAC3B,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC;IAC/D,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yBAAyB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0BAA0B;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3B,4BA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B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use client";import{jsx as r,jsxs as f}from"react/jsx-runtime";import{useEffect as T,useId as Z,useMemo as p}from"react";import{FormProvider as ee}from"react-hook-form";import{Button as v,Stack as re,Spinner as oe}from"@donotdev/components";import{useTranslation as D}from"@donotdev/core";import{DisplayFieldRenderer as te}from"./DisplayFieldRenderer";import{FormFieldRenderer as ne}from"./FormFieldRenderer";import{UploadProvider as ae}from"../contexts/UploadContext";import{useEntityForm as ie}from"../forms/hooks/useEntityForm";import{useUnsavedChangesWarning as se,useConfirmNavigation as de}from"../hooks/useUnsavedChangesWarning";import{useFormStore as le}from"../stores";function ue({entity:u,onSubmit:I,t:k,className:V="",submitText:N,loading:j=!1,defaultValues:s,submitVariant:P="primary",secondaryButtonText:m,secondaryButtonVariant:U="outline",onSecondarySubmit:h,viewerRole:B,operation:c=s?"edit":"create",autoSave:E=c==="create",formId:L,cancelText:y,onCancel:R,warnOnUnsavedChanges:$=!0,unsavedChangesMessage:d}){const M=Z(),n=L??`entity-form-${u.name}-${M}`,{t:Y}=D([u.namespace,"crud"]),{t:e}=D("crud"),g=k||Y,b=ie(u,{formId:n,operation:c,defaultValues:s,viewerRole:B,t:g,autoSave:E}),{control:_,handleSubmit:x,formState:{errors:z},fields:A,formStatus:l,uploadProgress:a,cleanup:C,isDirty:W,hasUserInteracted:q,resetForm:G}=b,i=W&&q;T(()=>{n&&le.getState().setIsDirty(n,i)},[n,i]),T(()=>C,[C]);const H=p(()=>d||e("messages.unsavedChangesLeave",{defaultValue:"You have unsaved changes. Are you sure you want to leave?"}),[d,e]),J=p(()=>d||e("messages.unsavedChangesDiscard",{defaultValue:"You have unsaved changes. Discard them?"}),[d,e]);se({isDirty:i,enabled:$,message:H});const K=de(i,J),O=async()=>{i&&!await K()||(G(),R?.())},F=y!==null,S=y??e("form.cancel",{defaultValue:"Cancel"}),Q=j||c==="edit"&&!s,o=p(()=>l==="uploading"?{loading:!0,loadingText:a<100?e("form.uploading",{progress:Math.round(a),defaultValue:`Uploading ${Math.round(a)}%...`}):e("form.processing",{defaultValue:"Processing..."}),progress:a}:l==="validating"?{loading:!0,loadingText:e("form.validating",{defaultValue:"Validating..."})}:l==="submitting"?{loading:!0,loadingText:e("form.saving",{defaultValue:"Saving..."})}:{loading:!1},[l,a,e]);return r(ee,{...b,children:r(ae,{formId:n,children:f("div",{style:{position:"relative",width:"100%",gridColumn:"1 / -1",display:"contents"},children:[Q&&r(oe,{overlay:!0}),f("form",{onSubmit:x(I),noValidate:!0,className:V,style:{width:"100%",gridColumn:"1 / -1",display:"contents"},children:[A.map(({name:t,config:w,editable:X})=>X?r(ne,{name:t,config:w,control:_,errors:z,t:g},t):r(te,{name:t,config:w,value:s?.[t],t:g},t)),f(re,{direction:m||F?"row":"column",gap:"tight",style:{gridColumn:"1 / -1",position:"sticky",bottom:0,backgroundColor:"var(--background)",borderTop:"1px solid var(--border)",paddingTop:"var(--gap-md)",paddingBottom:"var(--gap-md)",zIndex:10,marginTop:"var(--gap-lg)"},children:[F&&S&&r(v,{type:"button",onClick:O,disabled:o.loading,variant:"outline",className:"dndev-w-full",children:S}),m&&r(v,{type:"button",onClick:()=>h&&x(h)(),loading:o.loading,loadingText:o.loadingText,progress:o.progress,variant:U,className:"dndev-w-full",children:m}),r(v,{type:"submit",loading:o.loading,loadingText:o.loadingText,progress:o.progress,variant:P,className:"dndev-w-full",children:N||e("form.submit",{defaultValue:"Submit"})})]})]})]})})})}var Se=ue;export{ue as EntityFormRenderer,Se as default};
|