@donotdev/crud 0.1.43 → 0.1.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CrudService.bulk.js +1 -1
- package/dist/CrudService.cache.js +1 -1
- package/dist/CrudStore.js +1 -1
- package/dist/components/CrudCard.js +1 -1
- package/dist/components/EntityFilters.js +1 -1
- package/dist/components/controlled/input/ControlledDurationField.js +1 -1
- package/dist/components/controlled/input/ControlledPriceField.js +1 -1
- package/dist/components/controlled/input/ControlledRangeField.js +1 -1
- package/dist/components/controlled/input/ControlledRatingField.js +1 -1
- package/dist/components/fields/display/BadgeFieldDisplay.js +1 -1
- package/dist/components/fields/display/CheckboxFieldDisplay.js +1 -1
- package/dist/components/fields/display/MapFieldDisplay.js +1 -1
- package/dist/components/fields/display/NumberFieldDisplay.js +1 -1
- package/dist/components/fields/display/PasswordFieldDisplay.js +1 -1
- package/dist/components/fields/display/TextFieldDisplay.js +1 -1
- package/dist/components/form/fields/AddressFieldComponent.d.ts +12 -10
- package/dist/components/form/fields/AddressFieldComponent.d.ts.map +1 -1
- package/dist/components/form/fields/AddressFieldComponent.js +1 -1
- package/dist/components/form/fields/DropdownComponent.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/PhoneNumberComponent.js +1 -1
- package/dist/components/form/fields/PriceFieldComponent.js +1 -1
- package/dist/components/form/fields/RangeFieldComponent.js +1 -1
- package/dist/components/form/fields/RichTextComponent.js +1 -1
- package/dist/components/form/fields/SwitchFieldComponent.js +1 -1
- package/dist/components/form/fields/TextAreaComponent.js +1 -1
- package/dist/forms/hooks/useEntityForm.js +1 -1
- package/dist/forms/utils/buildInitialValues.js +1 -1
- package/dist/forms/utils/isFieldEditable.js +1 -1
- package/dist/stores/FormStore.js +1 -1
- package/dist/stores/UploadStore.js +1 -1
- package/dist/symbol-index.json +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/clientListProcessing.js +1 -1
- package/dist/utils/collections.js +1 -1
- package/dist/utils/imageProcessing.js +1 -1
- package/dist/utils/uploadValidation.js +1 -1
- package/package.json +3 -3
package/dist/CrudService.bulk.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{toast as v}from"@donotdev/components";import{BulkCollisionError as L,detectBulkCollisions as j,DEFAULT_STATUS_VALUE as R,generateUUID as _,getI18nInstance as T,handleError as F,validateWithSchema as N}from"@donotdev/core";import{updateListCaches as h}from"./CrudService.cache";import{assertCanAccess as b,ensureAdapter as Q,getEntityName as C,getPiiFields as O,rateLimitKey as $,shouldShowSuccessToast as B,withResilience as K}from"./CrudService.internal";import{CRUD_OPERATION as m}from"./types";function M(t,e,p){const
|
|
1
|
+
import{toast as v}from"@donotdev/components";import{BulkCollisionError as L,detectBulkCollisions as j,DEFAULT_STATUS_VALUE as R,generateUUID as _,getI18nInstance as T,handleError as F,validateWithSchema as N}from"@donotdev/core";import{updateListCaches as h}from"./CrudService.cache";import{assertCanAccess as b,ensureAdapter as Q,getEntityName as C,getPiiFields as O,rateLimitKey as $,shouldShowSuccessToast as B,withResilience as K}from"./CrudService.internal";import{CRUD_OPERATION as m}from"./types";function M(t,e,p){const o=t.getQueryClient(),y=new Map;if(p.length===0)return y;const S=o.getQueriesData({queryKey:["crud",e]});for(const c of p){const g=o.getQueryData(["crud",e,"get",c]);if(g!=null){y.set(c,g);continue}let f=null;for(const[,E]of S){const D=E&&typeof E=="object"&&"items"in E?E.items:null;if(!D)continue;const w=D.find(A=>A?.id===c);if(w){f=w;break}}y.set(c,f)}return y}async function q(t,e,p,o,y){const S=j({inserts:p.inserts,updates:p.updates,deletes:p.deletes});if(S.where!==null)throw new L(S.collisions,S.where);const c=p.inserts??[],g=p.updates??[],f=p.deletes??[];if(c.length===0&&g.length===0&&f.length===0)return{insertedIds:[],updatedIds:[],deletedIds:[]};await Q(t),t.store&&(t.store.getState().setLoading(e,!0),t.store.getState().setError(e,null)),o.create?b(t,e,o.create):o.update&&b(t,e,o.update),t.security&&await t.security.checkRateLimit($(t,e),"write");const E=O(o.create??o.draft),D=O(o.update??o.create),w=c.map(n=>{const d=n,i=d.status===void 0||d.status===null?{...d,status:R}:d,u=i.status==="draft"&&o.draft?o.draft:o.create??o.draft,s=u?N(u,i,"CrudService.bulk.insert"):i;return E.length>0&&t.security?t.security.encryptPii(s,E):s}),A=g.map(({id:n,patch:d})=>{const i=d,u=D.length>0&&t.security?t.security.encryptPii(i,D):d;return{id:n,patch:u}}),I={inserts:[],updates:[],deletes:[]},P=[...g.map(n=>n.id),...f],U=M(t,e,P),k=c.map(()=>`temp_${_()}`);try{if(c.forEach((s,r)=>{const a=k[r],l={...s,id:a};t.store&&t.store.getState().addOptimistic(e,a,l),h(t,e,a,l,m.ADD),I.inserts.push({tempId:a,data:l})}),g.forEach(({id:s,patch:r})=>{const a=U.get(s)??null,l=a?{...a,...r}:{...r,id:s};t.store&&t.store.getState().updateOptimistic(e,s,l,a??null),h(t,e,s,l,m.UPDATE),I.updates.push({id:s,prev:a,merged:l})}),f.forEach(s=>{const r=U.get(s)??null;t.store&&r&&t.store.getState().deleteOptimistic(e,s,r),h(t,e,s,null,m.DELETE),I.deletes.push({id:s,prev:r})}),!t.adapter)throw new Error(`[dndev] Adapter not initialized for "${e}" bulk().`);const n=t.adapter,d={inserts:w,updates:A,deletes:f},i=await K(()=>n.bulk(e,d)),u=i.insertedIds??[];if(k.forEach((s,r)=>{const a=u[r];if(!a)return;const l=c[r];h(t,e,s,null,m.DELETE),h(t,e,a,l,m.ADD),t.store&&t.store.getState().confirmOptimistic(e,s,a,l)}),(i.updatedIds??[]).forEach(s=>{t.store&&t.store.getState().confirmUpdate(e,s)}),(i.deletedIds??[]).forEach(s=>{t.store&&t.store.getState().confirmDelete(e,s)}),t.security&&(t.security.audit({type:"crud.bulk",collection:e,userId:t.currentUserId??void 0,metadata:{inserts:c.length,updates:g.length,deletes:f.length}}),f.length>0&&t.security.recordAnomaly?.("bulk.deletes",t.currentUserId??void 0)),u.length+(i.updatedIds?.length??0)+(i.deletedIds?.length??0)>0&&B(t,y)){const s=T(),r=C(e);v("success",s.t("messages.updateSuccess",{ns:"crud",entity:r}))}return{insertedIds:u,updatedIds:i.updatedIds??[],deletedIds:i.deletedIds??[]}}catch(n){for(const{id:s,prev:r}of I.deletes)r&&h(t,e,s,r,m.ADD),t.store&&t.store.getState().rejectDelete(e,s);for(const{id:s,prev:r}of I.updates)r?h(t,e,s,r,m.UPDATE):t.invalidateCollection(e),t.store&&t.store.getState().rejectUpdate(e,s);for(const{tempId:s}of I.inserts)h(t,e,s,null,m.DELETE),t.store&&t.store.getState().rejectOptimistic(e,s);if(n instanceof L)throw t.store&&t.store.getState().setError(e,n),n;const d=F(n,{userMessage:`Failed to bulk-write ${e}`,showNotification:!0}),i=T(),u=C(e);throw v("error",i.t("messages.updateError",{ns:"crud",entity:u})),t.store&&t.store.getState().setError(e,d),d}finally{t.store&&t.store.getState().setLoading(e,!1)}}export{q as bulkImpl};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{handleError as E}from"@donotdev/core";import{CRUD_OPERATION as u}from"./types";function m(a,c,
|
|
1
|
+
import{handleError as E}from"@donotdev/core";import{CRUD_OPERATION as u}from"./types";function m(a,c,s,r,t){const l=a.getQueryClient(),i=["crud",c,"get",s];t===u.DELETE?l.removeQueries({queryKey:i}):t===u.SET&&r?l.setQueryData(i,r):(t===u.UPDATE||t===u.ADD)&&r&&l.setQueryData(i,e=>e?{...e,...r}:r)}function D(a,c,s,r,t){const l=a.getQueryClient();m(a,c,s,r,t),l.setQueriesData({queryKey:["crud",c]},i=>{if(i&&typeof i=="object"&&"items"in i){const e=i;let n=e.items;return t===u.DELETE?(n=e.items.filter(o=>o!=null&&typeof o=="object"&&o.id!==s),{...e,items:n,total:Math.max(0,(e.total??n.length)-1)}):t===u.ADD&&r?(n=[...e.items,{...r,id:s}],{...e,items:n,total:(e.total??e.items.length)+1}):(t===u.UPDATE||t===u.SET)&&r&&e.items.some(o=>o!=null&&typeof o=="object"&&o.id===s)?(n=e.items.map(o=>o==null||typeof o!="object"||o.id!==s?o:t===u.SET?{...r,id:s}:{...o,...r}),{...e,items:n}):i}if(Array.isArray(i)){if(t===u.DELETE)return i.filter(e=>e.id!==s);if(t===u.ADD&&r)return[...i,{...r,id:s}];if((t===u.UPDATE||t===u.SET)&&r)return i.some(e=>e!=null&&typeof e=="object"&&e.id===s)?i.map(e=>e==null||typeof e!="object"||e.id!==s?e:t===u.SET?{...r,id:s}:{...e,...r}):i}return i})}function g(a,c,s,r){const t=r.metadata?.uniqueKeys;if(!t||t.length===0)return null;const l=a.getQueryClient().getQueriesData({queryKey:["crud",c]}),i=[];for(const[,n]of l)n&&typeof n=="object"&&"items"in n?i.push(...n.items):Array.isArray(n)&&i.push(...n);if(i.length===0)return null;const e=s;for(const n of t){if(!n.fields.every(f=>e[f]!=null&&e[f]!==""))continue;const o=i.find(f=>n.fields.every(d=>{const y=typeof e[d]=="string"?e[d].toLowerCase():e[d],p=typeof f[d]=="string"?f[d].toLowerCase():f[d];return y===p}));if(o){if(n.findOrCreate)return o.id;const f=n.fields.join(" + ");throw E(new Error(n.errorMessage||`Duplicate ${f}`),{userMessage:n.errorMessage||`A record with this ${f} already exists`,showNotification:!0})}}return null}function h(a,c,s){const r=a.getQueryClient().getQueriesData({queryKey:["crud",c]});for(const[,t]of r)if(t?.items){const l=t.items.find(i=>i.id===s);if(l)return l}return null}async function C(a,c){await a.getQueryClient().invalidateQueries({queryKey:["crud",c]})}export{g as checkUniquenessFromCache,h as getItemFromListCache,C as invalidateCollectionImpl,m as updateGetCache,D as updateListCaches};
|
package/dist/CrudStore.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createDoNotDevStore as g,isClient as f}from"@donotdev/core";import{OPTIMISTIC_STATUSES as d,CRUD_OPERATION as u}from"./types";let m=null;const a="f_";function S(n){if(!f())return;const s=new URLSearchParams(location.search);[...s.keys()].filter(i=>i.startsWith(a)).forEach(i=>s.delete(i));for(const[i,
|
|
1
|
+
import{createDoNotDevStore as g,isClient as f}from"@donotdev/core";import{OPTIMISTIC_STATUSES as d,CRUD_OPERATION as u}from"./types";let m=null;const a="f_";function S(n){if(!f())return;const s=new URLSearchParams(location.search);[...s.keys()].filter(i=>i.startsWith(a)).forEach(i=>s.delete(i));for(const[i,o]of Object.entries(n))typeof o=="string"?s.set(`${a}${i}`,o):Array.isArray(o)?s.set(`${a}${i}`,o.join(",")):(o.min&&s.set(`${a}${i}_min`,o.min),o.max&&s.set(`${a}${i}_max`,o.max));const t=s.toString();history.replaceState(null,"",`${location.pathname}${t?`?${t}`:""}`)}function h(){if(!f())return{};const n=new URLSearchParams(location.search),s={},t=new Map;return n.forEach((i,o)=>{if(!o.startsWith(a))return;const e=o.slice(a.length);if(e.endsWith("_min")){const c=e.slice(0,-4),l=t.get(c)??{};l.min=i,t.set(c,l)}else if(e.endsWith("_max")){const c=e.slice(0,-4),l=t.get(c)??{};l.max=i,t.set(c,l)}else i.includes(",")?s[e]=i.split(","):s[e]=i}),t.forEach((i,o)=>{s[o]=i}),s}const E={filters:{},showFavoritesOnly:!1};function r(){return{loading:!1,error:null,lastUpdated:0,optimistic:{},ui:{...E}}}const O={crudService:null,hideSuccessToasts:!1,collections:{}},U=g({name:"crud-store",createStore:(n,s)=>({...O,setCrudService:t=>{n({crudService:t})},setHideSuccessToasts:t=>{n({hideSuccessToasts:t})},setLoading:(t,i)=>{n(o=>{const e=o.collections[t]||r();return{collections:{...o.collections,[t]:{...e,loading:i}}}})},setError:(t,i)=>{n(o=>{const e=o.collections[t]||r();return{collections:{...o.collections,[t]:{...e,error:i,loading:!1}}}})},setFilters:(t,i)=>{n(o=>{const e=o.collections[t]||r();return{collections:{...o.collections,[t]:{...e,ui:{...e.ui,filters:i}}}}}),m&&clearTimeout(m),m=setTimeout(()=>{m=null,S(i)},500)},setShowFavoritesOnly:(t,i)=>{n(o=>{const e=o.collections[t]||r();return{collections:{...o.collections,[t]:{...e,ui:{...e.ui,showFavoritesOnly:i}}}}})},getFilters:t=>{const i=s().collections[t]?.ui?.filters;if(i)return i;const o=h();return Object.keys(o).length>0?(n(e=>{const c=e.collections[t]||r();return{collections:{...e.collections,[t]:{...c,ui:{...c.ui,filters:o}}}}}),o):{}},getShowFavoritesOnly:t=>s().collections[t]?.ui?.showFavoritesOnly||!1,setPageSize:(t,i)=>{n(o=>{const e=o.collections[t]||r();return{collections:{...o.collections,[t]:{...e,ui:{...e.ui,pageSize:i}}}}})},getPageSize:t=>s().collections[t]?.ui?.pageSize,clearCollection:t=>{n(i=>{const{[t]:o,...e}=i.collections;return{collections:e}})},clearError:t=>{n(i=>{const o=i.collections[t];return o?{collections:{...i.collections,[t]:{...o,error:null}}}:i})},addOptimistic:(t,i,o)=>{n(e=>{const c=e.collections[t]||r();return{collections:{...e.collections,[t]:{...c,optimistic:{...c.optimistic,[i]:{tempId:i,originalData:null,optimisticData:o,status:d.PENDING,operation:u.ADD}},lastUpdated:Date.now()}}}})},confirmOptimistic:(t,i,o,e)=>{n(c=>{const l=c.collections[t];if(!l)return c;const{[i]:p,...D}=l.optimistic;return{collections:{...c.collections,[t]:{...l,optimistic:D,lastUpdated:Date.now()}}}})},rejectOptimistic:(t,i)=>{n(o=>{const e=o.collections[t];if(!e)return o;const{[i]:c,...l}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:l,lastUpdated:Date.now()}}}})},updateOptimistic:(t,i,o,e)=>{n(c=>{const l=c.collections[t]||r();return{collections:{...c.collections,[t]:{...l,optimistic:{...l.optimistic,[i]:{tempId:i,originalData:e,optimisticData:o,status:d.PENDING,operation:u.UPDATE}},lastUpdated:Date.now()}}}})},confirmUpdate:(t,i)=>{n(o=>{const e=o.collections[t];if(!e)return o;const{[i]:c,...l}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:l}}}})},rejectUpdate:(t,i)=>{n(o=>{const e=o.collections[t];if(!e)return o;const c=e.optimistic[i];if(!c||c.operation!==u.UPDATE)return o;const{[i]:l,...p}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:p,lastUpdated:Date.now()}}}})},deleteOptimistic:(t,i,o)=>{n(e=>{const c=e.collections[t];return c?{collections:{...e.collections,[t]:{...c,optimistic:{...c.optimistic,[i]:{tempId:i,originalData:o,optimisticData:null,status:d.PENDING,operation:u.DELETE}},lastUpdated:Date.now()}}}:e})},confirmDelete:(t,i)=>{n(o=>{const e=o.collections[t];if(!e)return o;const{[i]:c,...l}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:l}}}})},rejectDelete:(t,i)=>{n(o=>{const e=o.collections[t];if(!e)return o;const c=e.optimistic[i];if(!c||c.operation!==u.DELETE)return o;const{[i]:l,...p}=e.optimistic;return{collections:{...o.collections,[t]:{...e,optimistic:p,lastUpdated:Date.now()}}}})},getLoading:t=>s().collections[t]?.loading||!1,getError:t=>s().collections[t]?.error||null,isOptimistic:(t,i)=>s().collections[t]?.optimistic[i]?.status==="pending",getOptimisticStatus:(t,i)=>s().collections[t]?.optimistic[i]?.status??null,getOptimisticData:(t,i)=>s().collections[t]?.optimistic[i]?.optimisticData??null})});export{U as useCrudStore};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as a,jsxs as k}from"react/jsx-runtime";import{Trash2 as z}from"lucide-react";import{useMemo as y}from"react";import{Card as G,Stack as w,Text as V,ActionButton as H}from"@donotdev/components";import{useTranslation as j,getListCardFieldNames as J}from"@donotdev/core";import{formatValue as F}from"./DisplayFieldRenderer";import{DisplayThumbnail as P}from"./DisplayThumbnail";import{translateFieldLabel as K}from"../forms/utils/translateFieldLabel";import{useCrud as Q}from"../useCrud";function d(t){return t==="image"||t==="images"}function U(t){return y(()=>{const l=t.listCardFields;if(l&&!Array.isArray(l)){const s=l;return{titleFields:s.title??[],subtitleFields:s.subtitle??[],contentFields:s.content??[],footerFields:s.footer??[]}}const f=J(t),m=f.filter(s=>!d(t.fields[s]?.type)),C=f.filter(s=>d(t.fields[s]?.type)),b=m.length>0?[m[0]]:[],x=[...m.slice(1,4),...C];return{titleFields:b,subtitleFields:[],contentFields:x,footerFields:[]}},[t])}function I({item:t,entity:l,onClick:f,titleFields:m,subtitleFields:C,contentFields:b,footerFields:x,showDelete:s=!1,renderActions:B,renderOverlay:L,className:N}){const{t:o}=j([l.namespace,"crud"]),{t:p}=j("crud"),h=U(l),S=m??h.titleFields,A=C??h.subtitleFields,D=b??h.contentFields,g=x??h.footerFields,c=t,T=y(()=>{if(!S?.length)return t.id??"";const r=S.filter(e=>typeof e=="string").filter(e=>!d(l.fields[e]?.type)).map(e=>{const n=l.fields[e],v=t[e],u=n?F(v,n,o,{compact:!0,asString:!0,item:c}):v;return typeof u=="string"?u:String(u??"")}).filter(Boolean),i=!Array.isArray(l.listCardFields)&&l.listCardFields?.titleSeparator!=null?l.listCardFields.titleSeparator:" ";return r.join(i)||String(t.id??"")},[t,l.fields,S,l.listCardFields,o]),O=y(()=>A?.length&&A.filter(r=>typeof r=="string").filter(r=>!d(l.fields[r]?.type)).map(r=>{const i=l.fields[r],e=t[r],n=i?F(e,i,o,{compact:!0,asString:!0,item:c}):e;return typeof n=="string"?n:String(n??"")}).filter(Boolean).join(" ")||void 0,[t,l.fields,A,o]),R=y(()=>{if(!D?.length)return null;const r=D.map(i=>{const e=l.fields[i];if(!e||e.options?.displayValue?.(t[i],c,o)===null)return null;if(d(e.type)){const n=t[i];return n==null?null:a(P,{pictures:n,alt:String(T),aspectRatio:"16/9"},i)}return k("div",{children:[a(V,{level:"small",variant:"muted",children:K(i,e,o)}),a(V,{children:F(t[i],e,o,{compact:!0,item:c})})]},i)}).filter(Boolean);return r.length>0?a(w,{direction:"column",gap:"tight",children:r}):null},[t,l.fields,D,T,o]),E=y(()=>{if(!g?.length)return;if(g.some(i=>d(l.fields[i]?.type))){const i=g.map(e=>{const n=l.fields[e];if(!n)return null;if(d(n.type)){const u=t[e];return u==null?null:a(P,{pictures:u,alt:"",aspectRatio:"1"},e)}const v=F(t[e],n,o,{compact:!0,item:c});return a("span",{children:v},e)});return a(w,{direction:"row",gap:"tight",align:"center",children:i.filter(Boolean)})}const r=g.map(i=>{const e=l.fields[i];return e?F(t[i],e,o,{compact:!0,item:c}):t[i]});return a(V,{level:"small",children:r.join(" \xB7 ")})},[t,l.fields,g,o]),M=Q(l).delete,q=B||s?k("div",{style:{display:"flex",alignItems:"flex-start",gap:"var(--gap-xs)",pointerEvents:"auto"},onClick:r=>r.stopPropagation(),onMouseDown:r=>r.stopPropagation(),children:[B,s&&a(H,{action:async()=>{await M(t.id)},confirmText:p("delete.confirm",{defaultValue:"Are you sure you want to delete this item?"}),confirmTitle:p("delete.title",{defaultValue:"Delete Item"}),loadingText:p("delete.loading",{defaultValue:"Deleting..."}),variant:"destructive",icon:z,"aria-label":p("delete",{defaultValue:"Delete"}),children:p("delete",{defaultValue:"Delete"})})]}):null;return a(G,{title:String(T??""),subtitle:O,content:R??void 0,footer:E,clickable:!0,elevated:!0,onClick:f?()=>f(t.id):void 0,className:N,overlay:q??void 0,overlayPosition:"top-right",fullOverlay:L??void 0})}var W=I;export{I as CrudCard,W as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as u,jsxs as E}from"react/jsx-runtime";import{FilterX as ye}from"lucide-react";import{useMemo as M,useState as te,useRef as he,useEffect as ve}from"react";import{Button as be,Combobox as ie,Grid as xe,Rating as Fe,RangeInput as Ce,ScrollArea as Te,Slider as je,Stack as Y,Tag as G}from"@donotdev/components";import{useTranslation as
|
|
1
|
+
"use client";import{jsx as u,jsxs as E}from"react/jsx-runtime";import{FilterX as ye}from"lucide-react";import{useMemo as M,useState as te,useRef as he,useEffect as ve}from"react";import{Button as be,Combobox as ie,Grid as xe,Rating as Fe,RangeInput as Ce,ScrollArea as Te,Slider as je,Stack as Y,Tag as G}from"@donotdev/components";import{useTranslation as ne,handleError as re,isFieldVisible as we}from"@donotdev/core";import{DateFilter as Ee}from"./DateFilter";import{YearFilter as Se}from"./YearFilter";import{getFilterType as ae,isFilterable as Ae}from"../fieldTypeRegistry";import{translateFieldLabel as le,translateLabel as D}from"../forms/utils";import{useCrudFilters as Ve}from"../hooks/useCrudFilters";import{useCrudCardList as Me}from"../useCrudCardList";import{matchesFilter as Ne}from"../utils/matchesFilter";import{matchesFilter as Oe}from"../utils/matchesFilter";function $e({entity:d,data:W,fieldsToFilter:N,variant:se="inline",cols:oe,viewerRole:X="guest"}){const z=se==="sidebar",{t:x,i18n:me}=ne("crud"),{t:F}=ne(d.namespace),de=me?.language||"en",{data:ue}=Me(d,{enabled:!W}),C=W??(ue?.items||[]),{filters:T,setFilters:J}=Ve({collection:d.collection}),[K,B]=te({}),[fe,Q]=te({}),O=he({});ve(()=>()=>{Object.values(O.current).forEach(clearTimeout)},[]);const ce=(e,t,a)=>{B(r=>({...r,[e]:{min:t,max:a}})),O.current[e]&&clearTimeout(O.current[e]),O.current[e]=setTimeout(()=>{c(e,{min:t,max:a})},250)},j=M(()=>(N&&N.length>0?N:d.listFields||Object.keys(d.fields)).filter(e=>{const t=d.fields[e],a=t?.type||"text";return!(!Ae(a)||!we(t?.visibility??"guest",X))}),[N,d.listFields,d.fields,X]),U=M(()=>{const e={};return j.forEach(t=>{const a=Object.fromEntries(Object.entries(T).filter(([r])=>r!==t));if(Object.keys(a).length===0){e[t]=C;return}e[t]=C.filter(r=>Object.entries(a).every(([o,m])=>{const f=r[o],h=d.fields[o]?.type||"text";return Ne(f,m,h)}))}),e},[C,T,d.fields,j]),Z=M(()=>{const e={};return j.forEach(t=>{const a=d.fields[t];if(!a)return;const r=a.type||"text",o=ae(r);if(!o){re(new Error(`Field type "${r}" not registered in field type registry`),{userMessage:`Field type "${r}" is missing from registry`,context:{fieldType:r,fieldName:t,operation:"minmax_computation",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"});return}const m=o==="range"&&r==="year",f=o==="range"&&!m&&(r==="date"||r==="datetime-local"||r==="timestamp"||r==="time"||r==="week"||r==="month"),h=o==="range"&&!f&&!m,S=r==="price";if(h||m||S){const p=C.map(n=>n[t]).filter(n=>n!=null&&n!=="").map(n=>S&&typeof n=="object"&&n!==null?Number(n.amount):typeof n=="number"?n:Number(n)).filter(n=>!isNaN(n));p.length>0&&(e[t]={min:Math.min(...p),max:Math.max(...p)})}else if(f){const p=C.map(n=>n[t]).filter(n=>n!=null&&n!=="").map(n=>n instanceof Date?n:new Date(n)).filter(n=>!isNaN(n.getTime()));if(p.length>0){const n=new Date(Math.min(...p.map(w=>w.getTime()))),$=new Date(Math.max(...p.map(w=>w.getTime()))),v=n.toISOString().split("T")[0],A=$.toISOString().split("T")[0];e[t]={min:v||"",max:A||""}}}}),e},[C,d.fields,j]),c=(e,t)=>{const a={...T};if(!t||t==="")delete a[e];else if(Array.isArray(t))a[e]=t;else if(typeof t=="object"&&"min"in t){const r=t.min&&t.min!=="",o=t.max&&t.max!=="";!r&&!o?delete a[e]:a[e]=t}else a[e]=t;J(a)},pe=()=>{J({})},I=M(()=>j.length===0?null:j.map(e=>{const t=d.fields[e];if(!t)return null;const a=le(e,t,F),r=t.type||"text",o=ae(r);if(!o)return re(new Error(`Field type "${r}" not registered in field type registry`),{userMessage:`Field type "${r}" is missing from registry`,context:{fieldType:r,fieldName:e,operation:"filter_ui_render",fix:"Add to registerBuiltinFieldTypes.ts or registerFieldType()"},severity:"warning"}),null;const m=o==="range"&&r==="year",f=o==="range"&&!m&&(r==="date"||r==="datetime-local"||r==="timestamp"||r==="time"||r==="week"||r==="month"),h=o==="range"&&!f&&!m,S=o==="select",p=o==="multiselect",n=T[e],$=typeof n=="object"&&n!==null&&"min"in n,v=$?n:{min:"",max:""},A={gridColumn:z?"span 1":"span 2"};if(o==="rating"){const s=t.validation?.max??5,l=typeof n=="string"&&n!==""?Number(n):0;return u("div",{style:{gridColumn:"span 1",gridRow:"span 1"},children:u(Fe,{value:l,max:s,"aria-label":a,onChange:i=>{c(e,i===l?void 0:String(i))}})},e)}if(h){const s=Z[e],l=s?.min??0,i=s?.max??100,g=v.min?Number(v.min):l,_=v.max?Number(v.max):i;return E(Y,{gap:"tight",style:A,children:[u(Ce,{type:"number",label:a,minPlaceholder:x("filter.min",{defaultValue:"Min"}),maxPlaceholder:x("filter.max",{defaultValue:"Max"}),minValue:K[e]?.min??v.min??"",maxValue:K[e]?.max??v.max??"",actualMin:l,actualMax:i,onChange:(y,b)=>ce(e,y,b),onClear:()=>{B(y=>{const b={...y};return delete b[e],b}),Q(y=>{const b={...y};return delete b[e],b}),c(e,void 0)}}),u(je,{value:fe[e]??[g,_],min:l,max:i,step:1,onValueChange:y=>Q(b=>({...b,[e]:y})),onValueCommit:y=>{B(b=>({...b,[e]:{min:String(y[0]),max:String(y[1])}})),c(e,{min:String(y[0]),max:String(y[1])})}},`${e}-${v.min??""}-${v.max??""}`)]},e)}if(m){const s=Z[e];return u("div",{style:A,children:u(Se,{label:a,value:$?v:void 0,onChange:l=>c(e,l),tCrud:x,minYear:s?.min??t.validation?.min,maxYear:s?.max??t.validation?.max})},e)}if(f){const s=r==="week"||r==="month"?r:"date",l=(()=>{if(n){if(typeof n=="object"&&"min"in n){const i=n;return{min:i.min&&i.min.split("T")[0]||"",max:i.max&&i.max.split("T")[0]||""}}if(typeof n=="string"){const i=n.split("T")[0]||"";return{min:i,max:i}}}})();return u("div",{style:A,children:u(Ee,{label:a,fieldType:s,value:l,locale:de,onChange:i=>{if(!i){c(e,void 0);return}typeof i=="object"&&"min"in i&&c(e,{min:i.min||"",max:i.max||""})},tCrud:x})},e)}const w=(S||p)&&t.validation&&"options"in t.validation&&t.validation?Array.isArray(t.validation.options)?t.validation.options:typeof t.validation.options=="function"?t.validation.options():[]:[],P=U[e]||C,k=new Set,ee=o==="address";P.forEach(s=>{const l=s[e];if(l!=null)if(ee&&typeof l=="object"&&"formatted_address"in l){const i=l;i.formatted_address&&k.add(String(i.formatted_address))}else k.add(String(l))});const R=new Map;P.forEach(s=>{const l=s[e];if(l!=null){const i=ee&&typeof l=="object"&&"formatted_address"in l?String(l.formatted_address):String(l);R.set(i,(R.get(i)||0)+1)}});const V=[{value:"all",label:x("filter.selectPlaceholder",{defaultValue:"All"}),count:P.length}];if(w.length>0){const s=[],l=[];w.forEach(i=>{const g=typeof i=="string"?i:i.value,_=typeof i=="string"?i:i.label;k.has(g)?s.push({value:g,label:_}):l.push({value:g,label:_})}),s.sort((i,g)=>i.label.localeCompare(g.label)),l.sort((i,g)=>i.label.localeCompare(g.label)),s.forEach(i=>{V.push({value:i.value,label:D(i.label,F),disabled:!1,count:R.get(i.value)??0})}),l.forEach(i=>{V.push({value:i.value,label:D(i.label,F),disabled:!0,count:0})})}else Array.from(k).sort().slice(0,100).forEach(s=>{V.push({value:s,label:s,count:R.get(s)??0})});if(p){const s=V.filter(i=>i.value!=="all"),l=Array.isArray(n)?n:[];return u("div",{style:{gridColumn:"span 1",gridRow:"span 1"},children:u(ie,{label:a,value:l,onValueChange:i=>{const g=Array.isArray(i)?i:[i];c(e,g.length>0?g:void 0)},options:s,placeholder:x("filter.placeholder",{defaultValue:"Filter..."}),multiple:!0,clearable:!0})},e)}return u("div",{style:{gridColumn:"span 1",gridRow:"span 1"},children:u(ie,{label:a,value:typeof n=="string"?n:void 0,onValueChange:s=>{c(e,s==="all"||!s?"":String(s))},options:V,placeholder:x("filter.placeholder",{defaultValue:"Filter..."}),clearable:!0})},e)}),[j,d.fields,C,T,F,x,U]);if(!I||I.length===0)return null;const ge=I.filter(Boolean),L=Object.keys(T).length>0,H=M(()=>{if(!L)return null;const e=[];return Object.entries(T).forEach(([t,a])=>{const r=d.fields[t];if(!r)return;const o=le(t,r,F);if(typeof a=="string"){const m=r.validation&&"options"in r.validation?D(a,F):a;e.push(E(G,{size:"sm",variant:"outline",onRemove:()=>c(t,void 0),children:[o,": ",m]},t))}else if(Array.isArray(a))a.forEach((m,f)=>{e.push(E(G,{size:"sm",variant:"outline",onRemove:()=>{const h=a.filter((S,p)=>p!==f);c(t,h.length>0?h:void 0)},children:[o,": ",D(m,F)]},`${t}-${f}`))});else if(typeof a=="object"&&"min"in a){const m=a,f=[];m.min&&f.push(m.min),m.max&&f.push(m.max);const h=f.join(" - ");h&&e.push(E(G,{size:"sm",variant:"outline",onRemove:()=>c(t,void 0),children:[o,": ",h]},t))}}),e.length>0?e:null},[T,d.fields,F,x,L]),q=E(Y,{direction:"column",gap:"tight",children:[H&&u(Y,{direction:"row",gap:"tight",style:{flexWrap:"wrap"},children:H}),E(xe,{cols:oe??(z?1:[2,4,6,8]),children:[ge,u(be,{variant:"outline",icon:u(ye,{size:18}),onClick:pe,disabled:!L,style:{gridColumn:"1 / -1",gridRow:"span 1"},children:x("filter.clear",{defaultValue:"Clear Filters"})})]})]});return z?u(Te,{style:{maxHeight:"100%"},children:q}):q}export{$e as EntityFilters,Oe as matchesFilter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as t}from"react/jsx-runtime";import{Controller as p}from"react-hook-form";import{DurationFieldComponent as c}from"../../form/fields";import{convertValidationRules as C}from"../types";function v(a){const{control:s,errors:x,fieldConfig:r,t:i,required:d}=a,{name:m,label:f,validation:n}=r,e=(r.options||{}).fieldSpecific;return t(p,{name:m,control:s,rules:n?C(n):void 0,render:({field:o,fieldState:l})=>t(c,{label:i(f),value:o.value??0,onChange:u=>o.onChange(u),error:!!l.error,helperText:l.error?.message,required:d,disabled:o.disabled,min:e?.min??0,max:e?.max??480,step:e?.step??5,t:i})})}export{v as ControlledDurationField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as n}from"react/jsx-runtime";import{Controller as v}from"react-hook-form";import{PriceFieldComponent as h}from"../../form/fields";import{convertValidationRules as g}from"../types";function x(t){const{control:a,errors:F,fieldConfig:r,t:c,placeholder:s,required:d}=t,{name:u,label:f,validation:o}=r,e=(r.options||{}).fieldSpecific;return n(v,{name:u,control:a,rules:o?g(o):void 0,render:({field:
|
|
1
|
+
"use client";import{jsx as n}from"react/jsx-runtime";import{Controller as v}from"react-hook-form";import{PriceFieldComponent as h}from"../../form/fields";import{convertValidationRules as g}from"../types";function x(t){const{control:a,errors:F,fieldConfig:r,t:c,placeholder:s,required:d}=t,{name:u,label:f,validation:o}=r,e=(r.options||{}).fieldSpecific;return n(v,{name:u,control:a,rules:o?g(o):void 0,render:({field:l,fieldState:i})=>{const p=l.value,m=C=>{l.onChange(C)};return n(h,{label:c(f),value:p??void 0,onChange:m,error:!!i.error,helperText:i.error?.message,required:d,placeholder:s,defaultCurrency:e?.defaultCurrency??"EUR",optionsTitle:e?.optionsTitle,currencies:e?.currencies})}})}export{x as ControlledPriceField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as t}from"react/jsx-runtime";import{Controller as c}from"react-hook-form";import{RangeFieldComponent as g}from"../../form/fields";import{convertValidationRules as v}from"../types";function C(i){const{control:m,errors:h,fieldConfig:n,t:s,required:d}=i,{name:u,label:f,validation:e}=n,a=n.options||{},p=a.fieldSpecific;return t(c,{name:u,control:m,rules:e?v(e):void 0,render:({field:r,fieldState:l})=>t(g,{label:s(f),value:r.value??void 0,onChange:o=>{typeof o=="number"?r.onChange(o):r.onChange(Number(o.target.value)||0)},error:!!l.error,helperText:l.error?.message,required:d,min:e?.min,max:e?.max,step:a.step,showValue:p?.showValue})})}export{C as ControlledRangeField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as l}from"react/jsx-runtime";import{Controller as p}from"react-hook-form";import{RatingFieldComponent as c}from"../../form/fields";import{convertValidationRules as g}from"../types";function x(i){const{control:t,errors:C,fieldConfig:r,t:s,required:m}=i,{name:d,label:f,validation:e}=r,o=(r.options||{}).fieldSpecific;return l(p,{name:d,control:t,rules:e?g(e):void 0,render:({field:a,fieldState:n})=>l(c,{label:s(f),value:a.value??0,onChange:u=>{a.onChange(u)},error:!!n.error,helperText:n.error?.message,required:m,max:o?.max??e?.max??5,showValue:o?.showValue})})}export{x as ControlledRatingField};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as o}from"react/jsx-runtime";import{Badge as
|
|
1
|
+
import{jsx as o}from"react/jsx-runtime";import{Badge as r,Text as l}from"@donotdev/components";const n=({config:m,value:a,t:s,className:e})=>{if(a==null)return o(l,{as:"span",variant:"muted",className:e,children:"-"});const t=typeof a=="boolean"?s(a?"common.yes":"common.no"):String(a);return o(r,{variant:typeof a=="boolean"?a?"default":"secondary":"outline",className:e,children:t})};var i=n;export{n as BadgeFieldDisplay,i as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as s}from"react/jsx-runtime";import{Badge as
|
|
1
|
+
import{jsx as s}from"react/jsx-runtime";import{Badge as t,Text as c}from"@donotdev/components";const n=({config:m,value:a,t:o,className:e})=>{if(a==null)return s(c,{as:"span",variant:"muted",className:e,children:"-"});const r=o(a?"common.yes":"common.no");return s(t,{variant:a?"default":"secondary",className:e,children:r})};var l=n;export{n as CheckboxFieldDisplay,l as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as o,jsxs as
|
|
1
|
+
import{jsx as o,jsxs as t}from"react/jsx-runtime";import{Text as l}from"@donotdev/components";const e=({config:d,value:a,t:m,className:s})=>!a||a.lat===void 0&&a.lng===void 0?o(l,{as:"span",variant:"muted",className:s,children:"-"}):t(l,{as:"div",level:"small",className:`font-mono ${s||""}`,children:[a.lat?.toFixed(6),", ",a.lng?.toFixed(6)]});var i=e;export{e as MapFieldDisplay,i as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as s}from"react/jsx-runtime";import{Text as e,Spinner as
|
|
1
|
+
import{jsx as s}from"react/jsx-runtime";import{Text as e,Spinner as o}from"@donotdev/components";import{getI18nInstance as r}from"@donotdev/core";const l=({config:i,value:n,t:c,className:a,loading:t=!1})=>t?s(o,{className:a}):n==null?s(e,{as:"span",variant:"muted",className:a,children:"-"}):s(e,{as:"span",className:`font-mono ${a||""}`,children:n.toLocaleString(r()?.language)});var m=l;export{l as NumberFieldDisplay,m as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as o,jsxs as
|
|
1
|
+
import{jsx as o,jsxs as i}from"react/jsx-runtime";import{Eye as c,EyeOff as n}from"lucide-react";import{useState as u}from"react";import{Skeleton as m,Button as y,CopyToClipboard as f,Stack as t}from"@donotdev/components";const l=({config:g,value:e,t:r,className:s,loading:d=!1})=>{const[a,p]=u(!1);return d?o(m,{className:s}):e?i(t,{direction:"row",align:"center",className:s,children:[o("span",{style:{fontFamily:"monospace"},children:a?e:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"}),i(t,{direction:"row",align:"center",gap:"tight",children:[o(y,{type:"button",onClick:()=>p(!a),"aria-label":a?"Hide password":"Show password",children:a?o(n,{}):o(c,{})}),o(f,{text:e,tooltipText:r("copyToClipboard")||"Copy to clipboard",copiedTooltipText:r("copied")||"Copied!",ariaLabel:r("copyPassword")||"Copy password"})]})]}):o("div",{style:{color:"var(--muted-foreground)"},children:"-"})};var w=l;export{l as PasswordFieldDisplay,w as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as n}from"react/jsx-runtime";import{Mail as L,Calendar as k,Clock as I}from"lucide-react";import{useState as A}from"react";import{Skeleton as T,Badge as B,BADGE_VARIANT as E,Text as l,cn as f,CopyToClipboard as x,Stack as i}from"@donotdev/components";import{getWeekFromISOString as M,getI18nInstance as b}from"@donotdev/core";const C=({config:o,value:a,t:r,className:s,loading:v=!1,showCopy:
|
|
1
|
+
import{jsx as e,jsxs as n}from"react/jsx-runtime";import{Mail as L,Calendar as k,Clock as I}from"lucide-react";import{useState as A}from"react";import{Skeleton as T,Badge as B,BADGE_VARIANT as E,Text as l,cn as f,CopyToClipboard as x,Stack as i}from"@donotdev/components";import{getWeekFromISOString as M,getI18nInstance as b}from"@donotdev/core";const C=({config:o,value:a,t:r,className:s,loading:v=!1,showCopy:u=!1,asBadge:w=!1,truncate:c=!1,maxLength:d=50,showLabel:p=!1})=>{const[j,m]=A(!1),F=async()=>{try{await navigator.clipboard.writeText(a),m(!0),setTimeout(()=>m(!1),2e3)}catch{}},h=()=>{switch(o.type){case"email":return e(L,{});case"month":case"week":return e(k,{});case"time":return e(I,{});default:return null}},S=t=>{if(!t)return null;switch(o.type){case"email":return n("a",{href:`mailto:${t}`,style:{display:"flex",alignItems:"center",gap:"var(--gap-sm)"},onMouseEnter:g=>g.currentTarget.style.textDecoration="underline",onMouseLeave:g=>g.currentTarget.style.textDecoration="none",children:[h(),t]});case"month":return new Date(t).toLocaleDateString(b()?.language,{year:"numeric",month:"long"});case"week":return M(t);case"time":return new Date(`2000-01-01T${t}`).toLocaleTimeString(b()?.language);default:return t}},D=t=>!c||t.length<=d?t:`${t.substring(0,d)}...`;if(v)return n(i,{gap:"tight",children:[p&&e(T,{style:{height:"1rem",width:"6rem"}}),e(T,{className:"dndev-w-full",style:{height:"1.5rem"}})]});if(!a)return n(i,{gap:"tight",children:[p&&e(l,{as:"span",variant:"muted",children:o.label||o.name}),e(l,{as:"span",variant:"muted",className:f(s),style:{fontStyle:"italic"},children:r("common.noValue",{defaultValue:"No value"})})]});const N=S(a),y=D(String(N));return w?n(i,{direction:"row",align:"center",gap:"tight",children:[h(),e(B,{variant:E.SECONDARY,className:s,children:y}),u&&e(x,{text:a,tooltipText:r("copyToClipboard")||"Copy to clipboard",copiedTooltipText:r("copied")||"Copied!",ariaLabel:r("copyToClipboard")||"Copy to clipboard"})]}):n(i,{gap:"tight",children:[p&&e(l,{as:"span",variant:"muted",children:o.label||o.name}),n(i,{direction:"row",align:"center",gap:"tight",children:[e("div",{className:f("dndev-flex-1",c&&"truncate",s),title:c&&a.length>d?a:void 0,children:e(l,{as:"span",children:y})}),u&&e(x,{text:a,tooltipText:r("copyToClipboard")||"Copy to clipboard",copiedTooltipText:r("copied")||"Copied!",ariaLabel:r("copyToClipboard")||"Copy to clipboard"})]})]})};var V=C;export{C as TextFieldDisplay,V as default};
|
|
@@ -14,11 +14,14 @@ export interface AddressFieldComponentProps {
|
|
|
14
14
|
/** Change handler */
|
|
15
15
|
onChange: (value: any) => void;
|
|
16
16
|
/**
|
|
17
|
-
* Whether to enable Google Maps autocomplete (default: false)
|
|
18
|
-
* Requires env var: VITE_GOOGLE_MAPS_API_KEY (Vite) or NEXT_PUBLIC_GOOGLE_MAPS_API_KEY (Next.js)
|
|
17
|
+
* Whether to enable Google Maps autocomplete (default: false).
|
|
18
|
+
* Requires env var: VITE_GOOGLE_MAPS_API_KEY (Vite) or NEXT_PUBLIC_GOOGLE_MAPS_API_KEY (Next.js).
|
|
19
19
|
*/
|
|
20
20
|
enableGoogleMaps?: boolean;
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Whether to extract district_code (last 2 digits of postal code, "92" prefix → 92)
|
|
23
|
+
* onto the address value.
|
|
24
|
+
*/
|
|
22
25
|
extractDistrictCode?: boolean;
|
|
23
26
|
/** Error state */
|
|
24
27
|
error?: boolean;
|
|
@@ -28,16 +31,15 @@ export interface AddressFieldComponentProps {
|
|
|
28
31
|
required?: boolean;
|
|
29
32
|
}
|
|
30
33
|
/**
|
|
31
|
-
* Address field component with Google
|
|
32
|
-
* Integrates with Google Places API for address selection
|
|
34
|
+
* Address field component with Google Places autocomplete (new API).
|
|
33
35
|
*
|
|
34
|
-
*
|
|
36
|
+
* Modes:
|
|
37
|
+
* - Manual (no API key or `enableGoogleMaps=false`): free-text via Combobox `creatable`.
|
|
38
|
+
* - Google: AutocompleteSuggestion + Place.fetchFields() with Geocoder fallback for coords.
|
|
39
|
+
*
|
|
40
|
+
* Env vars:
|
|
35
41
|
* - Vite: VITE_GOOGLE_MAPS_API_KEY
|
|
36
42
|
* - Next.js: NEXT_PUBLIC_GOOGLE_MAPS_API_KEY
|
|
37
|
-
*
|
|
38
|
-
* @component
|
|
39
|
-
* @param {AddressFieldComponentProps} props - Component props
|
|
40
|
-
* @returns {JSX.Element} Address input field with autocomplete
|
|
41
43
|
*/
|
|
42
44
|
declare const AddressFieldComponent: ({ label, value, onChange, enableGoogleMaps, extractDistrictCode, error, helperText, required, }: AddressFieldComponentProps) => import("react/jsx-runtime").JSX.Element;
|
|
43
45
|
export default AddressFieldComponent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AddressFieldComponent.d.ts","sourceRoot":"","sources":["../../../../src/components/form/fields/AddressFieldComponent.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AddressFieldComponent.d.ts","sourceRoot":"","sources":["../../../../src/components/form/fields/AddressFieldComponent.tsx"],"names":[],"mappings":"AAgBA;;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;;;OAGG;IACH,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;AAwFD;;;;;;;;;;GAUG;AACH,QAAA,MAAM,qBAAqB,GAAI,iGAS5B,0BAA0B,4CAsS5B,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as L,jsxs as V}from"react/jsx-runtime";import{useState as C,useEffect as q,useRef as B,useCallback as Z}from"react";import{Combobox as D,Stack as F}from"@donotdev/components";import{useTranslation as H,getPlatformEnvVar as Q}from"@donotdev/core";const K="dndev-address-autocomplete-cache",X=100;function $(){try{const o=typeof localStorage<"u"?localStorage.getItem(K):null;if(o)return new Map(JSON.parse(o))}catch{}return new Map}function ee(o){try{typeof localStorage<"u"&&localStorage.setItem(K,JSON.stringify([...o]))}catch{}}function W(o){if(o.size>X){const d=o.keys().next().value;d!==void 0&&o.delete(d)}}const z=$(),M=new Map;function te(o){const d={key:o,v:"weekly"},s="google",x="importLibrary",A="__ib__",m=document,u=window;u[s]=u[s]||{};const c=u[s].maps||(u[s].maps={}),l=new Set,a=new URLSearchParams,f=()=>c._p||(c._p=new Promise(async(S,p)=>{const h=m.createElement("script");a.set("libraries",[...l].join(","));for(const y of Object.keys(d))a.set(y.replace(/[A-Z]/g,E=>"_"+E[0].toLowerCase()),d[y]);a.set("callback",s+".maps."+A),h.src="https://maps.googleapis.com/maps/api/js?"+a,c[A]=S,h.onerror=()=>{c._p=null,p(new Error("Google Maps JS API could not load."))};const g=m.querySelector("script[nonce]");g?.nonce&&(h.nonce=g.nonce),m.head.append(h)}));c[x]||(c[x]=(S,...p)=>(l.add(S),f().then(()=>c[x](S,...p))))}const oe=({label:o,value:d,onChange:s,enableGoogleMaps:x=!1,extractDistrictCode:A,error:m,helperText:u,required:c})=>{const{t:l}=H("crud"),[a,f]=C(d?.formatted_address||""),[S,p]=C([]),[h,g]=C(!1),[y,E]=C(!1),[P,U]=C(!1),T=B(null),k=B(null),G=Q("GOOGLE_MAPS_API_KEY")||"",w=x&&!!G;q(()=>{const t=d?.formatted_address??"";f(e=>e===t?e:t)},[d]),q(()=>{if(!w||P)return;const t=window.google;if(t?.maps?.places?.AutocompleteSuggestion){T.current=new t.maps.places.AutocompleteSessionToken,U(!0);return}let e=!1;return(async()=>{try{if(window.google?.maps?.importLibrary||te(G),await window.google.maps.importLibrary("places"),e)return;T.current=new window.google.maps.places.AutocompleteSessionToken,U(!0)}catch{e||E(!0)}})(),()=>{e=!0}},[w,G,P]),q(()=>{if(!w||!P||y)return;if(a.length<3){p([]);return}const t=z.get(a);if(t){p(t);return}return k.current&&clearTimeout(k.current),k.current=setTimeout(async()=>{g(!0);try{const e=window.google.maps.places,{suggestions:v}=await e.AutocompleteSuggestion.fetchAutocompleteSuggestions({input:a,sessionToken:T.current}),b=v.filter(r=>r.placePrediction).map(r=>{const n=r.placePrediction,i=[n.mainText?.text,n.secondaryText?.text].filter(Boolean).join(", ");return M.set(i,n),W(M),{value:i,label:i}});p(b),z.set(a,b),W(z),ee(z)}catch{E(!0),p([])}finally{g(!1)}},300),()=>{k.current&&clearTimeout(k.current)}},[w,P,y,a]);const J=Z(async t=>{const e=Array.isArray(t)?t[0]||"":t;if(!e)return;if(!w){f(e),s({formatted_address:e});return}let v=M.get(e);const b=window.google?.maps?.places;if(b){if(!v){g(!0);try{const{suggestions:r}=await b.AutocompleteSuggestion.fetchAutocompleteSuggestions({input:e,sessionToken:T.current}),n=r.find(i=>[i.placePrediction?.mainText?.text,i.placePrediction?.secondaryText?.text].filter(Boolean).join(", ")===e);n?.placePrediction&&(v=n.placePrediction,M.set(e,v))}catch{}if(!v){g(!1),f(e),s({formatted_address:e});return}}g(!0);try{const r=v.toPlace();await r.fetchFields({fields:["formattedAddress","location","addressComponents"]});const n=r.formattedAddress||e;let i=r.location?.lat()??0,I=r.location?.lng()??0;if(i===0&&I===0&&n)try{const j=await window.google.maps.importLibrary("geocoding"),_=(await new j.Geocoder().geocode({address:n})).results?.[0]?.geometry?.location;_&&(i=_.lat(),I=_.lng())}catch{}const R={formatted_address:n,latitude:i,longitude:I};if(A){const j=r.addressComponents||[],_=j.find(O=>(O.types||[]).includes("postal_code"))?.longText||j.find(O=>(O.types||[]).includes("postal_code"))?.long_name||"",Y=_.startsWith("92")?92:parseInt(_.slice(-2),10)||null;R.district_code=Y}f(n),p([]),s(R),T.current=new b.AutocompleteSessionToken}catch{f(e),s({formatted_address:e})}finally{g(!1)}}},[w,A,s]),N=t=>{f(t)};return w?V(F,{gap:"tight",children:[L(D,{label:o,value:a,onValueChange:J,onSearchChange:N,placeholder:l("address.placeholder","Enter address..."),emptyMessage:h?l("messages.loading","Loading..."):l("address.noResults","No addresses found"),options:S.map(t=>({value:t.value,label:t.label})),required:c,variant:m?"destructive":void 0,isLoading:h,creatable:!0,createLabel:l("actions.use","Use this address"),disabled:!P&&!y}),y&&L("p",{style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:l("address.apiUnavailable","Google Places unavailable \u2014 type address manually")}),u&&L("p",{style:{fontSize:"var(--font-size-xs)",color:m?"var(--destructive-foreground)":"var(--muted-foreground)"},children:u})]}):V(F,{gap:"tight",children:[L(D,{label:o,value:a,onValueChange:J,onSearchChange:N,placeholder:l("address.placeholder","Enter address..."),options:[],required:c,variant:m?"destructive":void 0,creatable:!0,createLabel:l("actions.use","Use this address")}),u&&L("p",{style:{fontSize:"var(--font-size-xs)",color:m?"var(--destructive-foreground)":"var(--muted-foreground)"},children:u})]})};var ae=oe;export{ae as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as l,jsxs as g}from"react/jsx-runtime";import{Select as d,Stack as v}from"@donotdev/components";import{useTranslation as m}from"@donotdev/core";const f=({label:t,value:r,options:n,error:s,helperText:a,onChange:o,onBlur:i,required:u})=>{const{t:p}=m("crud"),c=r!=null?String(r):"";return g(v,{gap:"tight",children:[l(d,{label:t,value:c,onValueChange:e=>{o&&o({target:{value:e}})},onOpenChange:e=>!e&&i?.(),placeholder:p("actions.select","Select"),required:u,options:n.map(e=>({value:String(e.value),label:e.label}))}),a&&l("p",{style:{fontSize:"var(--font-size-xs)",color:s?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:a})]})};var h=f;export{h as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as t,jsxs as u}from"react/jsx-runtime";import{Label as b,Input as v,Stack as g}from"@donotdev/components";const h=({label:c,value:a={lat:0,lng:0},onChange:i,error:r,helperText:o,disabled:d,required:f})=>{const
|
|
1
|
+
import{jsx as t,jsxs as u}from"react/jsx-runtime";import{Label as b,Input as v,Stack as g}from"@donotdev/components";const h=({label:c,value:a={lat:0,lng:0},onChange:i,error:r,helperText:o,disabled:d,required:f})=>{const p=l=>{const e=parseFloat(l.target.value)||0;if(e>=-90&&e<=90){const n={...a,lat:e},s={target:{value:JSON.stringify(n)}};i(s)}},m=l=>{const e=parseFloat(l.target.value)||0;if(e>=-180&&e<=180){const n={...a,lng:e},s={target:{value:JSON.stringify(n)}};i(s)}};return u(g,{gap:"tight",children:[t(b,{required:f,style:{display:"block",fontSize:"var(--font-size-sm)",fontWeight:500},children:c}),u(g,{direction:"row",children:[t(v,{label:"Latitude",type:"number",value:a.lat,onChange:p,min:"-90",max:"90",step:"0.000001",disabled:d,"data-variant":r?"destructive":void 0,className:"dndev-w-full"}),t(v,{label:"Longitude",type:"number",value:a.lng,onChange:m,min:"-180",max:"180",step:"0.000001",disabled:d,"data-variant":r?"destructive":void 0,className:"dndev-w-full"})]}),o&&t("p",{style:{fontSize:"var(--font-size-xs)",color:r?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:o})]})};var y=h;export{y as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as r,jsxs as s,Fragment as Y}from"react/jsx-runtime";import{DndContext as Z,closestCenter as _,PointerSensor as Q,TouchSensor as ee,useSensor as A,useSensors as re}from"@dnd-kit/core";import{SortableContext as te,useSortable as
|
|
1
|
+
"use client";import{jsx as r,jsxs as s,Fragment as Y}from"react/jsx-runtime";import{DndContext as Z,closestCenter as _,PointerSensor as Q,TouchSensor as ee,useSensor as A,useSensors as re}from"@dnd-kit/core";import{SortableContext as te,useSortable as oe,rectSortingStrategy as ae,arrayMove as ie}from"@dnd-kit/sortable";import{CSS as ne}from"@dnd-kit/utilities";import{Upload as le,X as U,Loader2 as se,GripVertical as de}from"lucide-react";import{forwardRef as ce,useCallback as R,useImperativeHandle as ue,useRef as pe,useState as j}from"react";import{Text as m,Stack as k,Progress as ge,handleImageError as me}from"@donotdev/components";import{useTranslation as he}from"@donotdev/core";import{useFileUpload as fe}from"../../../hooks/useFileUpload";import{processImage as ve}from"../../../utils/imageProcessing";import{uploadImage as be}from"../../../utils/imageStorage";import{ImageViewerDialog as ye}from"../internal/ImageViewerDialog";const xe=["image/*"];function we(t){return{id:t.id,file:t.file,previewURL:t.previewURL,hash:"",rotation:0,uploadProgress:t.progress,uploaded:t.uploaded,error:t.error}}function ke({file:t,index:h,multiple:f,onImageClick:C,onRemove:v,t:d}){const{attributes:i,listeners:S,setNodeRef:D,transform:c,transition:I,isDragging:b}=oe({id:t.id}),y=t.progress!==null&&t.progress<100,l=f&&!y,n={transform:ne.Transform.toString(c),transition:I,position:"relative",width:100,height:100,borderRadius:"var(--radius-md)",border:"var(--border-width) solid var(--border)",overflow:"hidden",backgroundColor:"var(--surface)",opacity:b?.5:1,cursor:l?"grab":"pointer",userSelect:"none",touchAction:l?"none":"auto"};return r("div",{ref:D,style:n,...i,...l?S:{},onClick:()=>{b||C(h)},children:y?s(k,{align:"center",justify:"center",style:{width:"100%",height:"100%"},children:[r(se,{style:{animation:"spin 1s linear infinite"}}),r(ge,{value:t.progress||0,style:{width:"80%"}})]}):t.error?s(k,{align:"center",justify:"center",style:{width:"100%",height:"100%"},children:[r(U,{style:{color:"var(--destructive)"}}),r(m,{variant:"destructive",level:"small",children:t.error})]}):s(Y,{children:[f&&r("div",{style:{position:"absolute",top:4,left:4,padding:2,background:"rgba(0,0,0,0.5)",borderRadius:"var(--radius-sm)",display:"flex",zIndex:2,pointerEvents:"none"},children:r(de,{style:{color:"white",width:14,height:14}})}),r("img",{src:t.previewURL,alt:d("image.alt.upload",{index:h+1}),draggable:!1,onError:me,style:{width:"100%",height:"100%",objectFit:"cover",pointerEvents:"none",userSelect:"none"}}),r("button",{type:"button",onClick:u=>{u.stopPropagation(),v(t.id)},onPointerDown:u=>u.stopPropagation(),style:{position:"absolute",top:4,right:4,padding:4,background:"rgba(0,0,0,0.5)",border:"none",borderRadius:"var(--radius-sm)",cursor:"pointer",display:"flex",zIndex:2},children:r(U,{style:{color:"white",width:16,height:16}})}),!t.uploaded&&r("div",{style:{position:"absolute",bottom:0,left:0,right:0,padding:4,background:"rgba(0,0,0,0.7)",textAlign:"center",pointerEvents:"none"},children:r(m,{variant:"muted",level:"small",style:{color:"white"},children:d("image.upload.pending",{defaultValue:"Pending"})})})]})})}const V=ce(({name:t="image",label:h,value:f,onChange:C,error:v,helperText:d,multiple:i=!1,maxFiles:S=10,maxSize:D=10*1024*1024,storagePath:c,required:I,capture:b},y)=>{const{t:l}=he("crud"),n=pe(null),[u,F]=j(!1),[L,E]=j(0),N=re(A(Q,{activationConstraint:{distance:8}}),A(ee,{activationConstraint:{delay:200,tolerance:5}})),B=R(async(e,o)=>{const{fullBlob:p,thumbBlob:x}=await ve(e);return be(p,x,e.name,{storagePath:c,onProgress:w=>o(w.progress)})},[c]),{files:a,addFiles:P,removeFile:T,reorderFiles:z}=fe({name:t,value:f,onChange:C,multiple:i,maxFiles:S,maxSize:D,accept:xe,storagePath:c,uploadFn:B}),M=e=>{const o=Array.from(e.target.files||[]);o.length>0&&P(o),n.current&&(n.current.value="")},q=R(e=>{e.preventDefault(),e.stopPropagation(),e.dataTransfer.files.length>0&&P(Array.from(e.dataTransfer.files))},[P]),G=R(e=>{const{active:o,over:p}=e;if(p&&o.id!==p.id){const x=a.findIndex(g=>g.id===o.id),w=a.findIndex(g=>g.id===p.id);if(x!==-1&&w!==-1){const g=ie(a.map(J=>J.id),x,w);z(g)}}},[a,z]),H=e=>{E(e),F(!0)},K=(e,o)=>{},O=e=>{const o=a[e];o&&T(o.id)},W=e=>{E(e)},X=i||a.length===0;ue(y,()=>({upload:async()=>{},focus:()=>n.current?.focus()}),[]);const $=a.map(we);return s(k,{gap:"tight",children:[s(m,{level:"body",textAlign:"start",children:[h,I&&"*"]}),X&&s("div",{role:"button",tabIndex:0,onClick:()=>n.current?.click(),onKeyDown:e=>{(e.key==="Enter"||e.key===" ")&&n.current?.click()},onDragOver:e=>e.preventDefault(),onDrop:q,style:{border:`var(--border-width) dashed ${v?"var(--destructive)":"var(--border)"}`,borderRadius:"var(--radius-lg)",padding:"var(--gap-lg)",backgroundColor:"var(--surface)",cursor:"pointer",textAlign:"center"},children:[r("input",{ref:n,type:"file",accept:"image/*",capture:b,multiple:i,style:{display:"none"},onChange:M}),s(k,{align:"center",children:[r(le,{style:{color:"var(--muted-foreground)"}}),r(m,{variant:"muted",level:"small",children:i?l("image.upload.dropzoneMultiple",{defaultValue:"Drop images here or click to upload"}):l("image.upload.dropzoneSingle",{defaultValue:"Drop image here or click to upload"})})]})]}),a.length>0&&r(Z,{sensors:N,collisionDetection:_,onDragEnd:G,children:r(te,{items:a.map(e=>e.id),strategy:ae,children:r("div",{style:{display:"flex",flexWrap:"wrap",gap:"var(--gap-md)"},children:a.map((e,o)=>r(ke,{file:e,index:o,multiple:i,onImageClick:H,onRemove:T,t:l},e.id))})})}),d&&r(m,{variant:v?"destructive":"muted",level:"small",children:d}),r(ye,{images:$,selectedIndex:L,open:u,onClose:()=>F(!1),onUpdate:K,onDelete:O,onNavigate:W,multiple:i})]})});V.displayName="ImageFieldComponent";var Ce=V;export{Ce as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as a,jsxs as o,Fragment as q}from"react/jsx-runtime";import{useMemo as J,useId as M}from"react";import{Combobox as R,Tag as p,Stack as h}from"@donotdev/components";import{useTranslation as k}from"@donotdev/core";const d=4,v=3,B=({label:f,value:t=[],options:l,error:b,helperText:i,onChange:u,onBlur:S,required:x,className:y})=>{const{t:g}=k("crud"),m=M(),z=J(()=>l.map(e=>({value:String(e.value),label:e.label})),[l]),N=e=>{const r=Array.isArray(e)?e:[e],s={target:{value:JSON.stringify(r)}};u(s)},C=e=>{e||S?.()},O=e=>{const r=t.filter(c=>c!==e),s={target:{value:JSON.stringify(r)}};u(s)},n=!!b,A=`${m}-error`,T=`${m}-helper`,j=t.length>0?o(q,{children:[t.slice(0,t.length>d?v:d).map((e,r)=>{const s=l.find(c=>String(c.value)===e)?.label||e;return a(p,{size:"sm",onRemove:()=>O(e),children:s},r)}),t.length>d&&o(p,{size:"sm",variant:"outline",disabled:!0,children:["+",t.length-v," more"]})]}):void 0;return o(h,{gap:"tight",className:y,children:[a(R,{label:f,value:t,onValueChange:N,onOpenChange:C,placeholder:g("actions.selectOptions","Select options..."),emptyMessage:g("messages.noResults","No results found"),options:z,multiple:!0,required:x,variant:n?"destructive":void 0,chips:j}),n&&o(h,{id:A,direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)",color:"var(--destructive-foreground)"},role:"alert",children:[a("span",{children:"\u26A0"}),i]}),i&&!n&&a("p",{id:T,style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:i})]})};var I=B;export{I as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as i,jsxs as s}from"react/jsx-runtime";import{useState as L,useMemo as m,useEffect as M,useId as O}from"react";import{Input as j,FloatingLabel as k,Button as q,BUTTON_VARIANT as E,DropdownMenu as U,Stack as f,cn as D}from"@donotdev/components";import{Flag as
|
|
1
|
+
"use client";import{jsx as i,jsxs as s}from"react/jsx-runtime";import{useState as L,useMemo as m,useEffect as M,useId as O}from"react";import{Input as j,FloatingLabel as k,Button as q,BUTTON_VARIANT as E,DropdownMenu as U,Stack as f,cn as D}from"@donotdev/components";import{Flag as R,COUNTRIES as y}from"@donotdev/core";const V=({label:w,value:o="",onChange:C,error:N,helperText:g,required:S=!1,disabled:v=!1,defaultCountry:x="FR",showFlags:T=!0,preferredCountries:c,countries:h})=>{const d=O(),p=m(()=>h&&h.length>0?h.map(e=>y.find(r=>r.code===e)).filter(e=>e!==void 0):Array.from(y),[h]),n=m(()=>{if(!c||c.length===0)return p;const e=c.map(t=>p.find(B=>B.code===t)).filter(t=>t!==void 0),r=p.filter(t=>!c.includes(t.code));return[...e,...r]},[p,c]),u=m(()=>n.find(e=>e.code===x)||n[0]||y[0],[x,n]),{country:b,phoneNumber:$}=m(()=>{if(!o)return{country:u,phoneNumber:""};const e=n.find(t=>o.startsWith(t.dialCode));if(e){let t=o.slice(e.dialCode.length).trim();return t.startsWith("0")&&(t=t.slice(1).trim()),t=t.replace(/\s+/g," ").trim(),{country:e,phoneNumber:t}}if(o.startsWith("+"))return{country:u,phoneNumber:o};let r=o.trim();return r.startsWith("0")&&(r=r.slice(1).trim()),r=r.replace(/\s+/g," ").trim(),{country:u,phoneNumber:r}},[o,u,n]),[a,W]=L(u);M(()=>{b.code!==a.code&&W(b)},[b,a.code]);const z=$,A=e=>{W(e);let r=z;r.startsWith("0")&&(r=r.slice(1).trim()),r=r.replace(/\s+/g," ").trim();const t={target:{value:e.dialCode+(r?" "+r:"")}};C(t)},F=e=>{let r=e.target.value;r.startsWith("0")&&(r=r.slice(1).trim()),r=r.replace(/\s+/g," ").trim();const t={target:{value:a.dialCode+(r?" "+r:"")}};C(t)},I=n.map(e=>({label:e.dialCode,onClick:()=>A(e),checked:e.code===a.code,children:T?s(f,{direction:"row",align:"center",gap:"tight",children:[i(R,{code:e.flagCode,title:e.name}),i("span",{children:e.dialCode}),i("span",{style:{color:"var(--muted-foreground)",fontSize:"var(--font-size-xs)"},children:e.name})]}):s("span",{children:[e.dialCode," ",e.name]})})),l=!!N;return s(f,{gap:"tight",children:[i(k,{htmlFor:d,label:w,disabled:v,required:S,children:s("div",{className:"dndev-relative",style:{display:"flex",gap:0},children:[i(U,{trigger:i(q,{type:"button",variant:E.GHOST,disabled:v,style:{minWidth:"fit-content",padding:"0 var(--gap-md)"},"aria-label":`Country code: ${a.dialCode}`,children:s(f,{direction:"row",align:"center",gap:"tight",children:[T&&i(R,{code:a.flagCode,title:a.name}),i("span",{children:a.dialCode})]})}),items:I,contentWidth:"16rem"}),i(j,{id:d,type:"tel",inputMode:"tel",value:z,onChange:F,disabled:v,placeholder:"6 12 34 56 78",bare:!0,"data-variant":l?"destructive":void 0,className:"dndev-flex-1",style:{borderTopLeftRadius:0,borderBottomLeftRadius:0,borderRadius:"0 var(--radius-md) var(--radius-md) 0"},"aria-describedby":D(l&&`${d}-error`,g&&!l&&`${d}-helper`),"aria-invalid":l})]})}),l&&s(f,{id:`${d}-error`,direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)",color:"var(--destructive-foreground)"},role:"alert",children:[i("span",{children:"\u26A0"}),N]}),g&&!l&&i("p",{id:`${d}-helper`,style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:g})]})};var _=V;export{_ as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as a,jsxs as
|
|
1
|
+
"use client";import{jsx as a,jsxs as u}from"react/jsx-runtime";import{CirclePlus as R,CircleMinus as U}from"lucide-react";import{useId as q,useState as z}from"react";import{Input as C,Checkbox as D,Stack as E,Select as A,CollapsiblePrimitive as B,CollapsibleTrigger as G,CollapsibleContent as H}from"@donotdev/components";import{useTranslation as J,getCurrencySymbol as L}from"@donotdev/core";const O=["EUR","USD","GBP","CHF","JPY","KRW"],Y=({label:f,value:n,onChange:I,error:s,helperText:g,required:P=!1,disabled:o=!1,placeholder:N="0",defaultCurrency:d="EUR",optionsTitle:x="Price options",currencies:b})=>{const c=q(),{t:p}=J("crud"),r=b?.length?b:[...O],h=n?.currency??d,m=r.includes(h)?h:r[0]??d,T=n?.vatIncluded??!0,y=n?.discountPercent??0,S=`${f} (${L(m)})`,i=e=>{const l=e.amount!==void 0?e.amount:n?.amount??null;let t=e.currency!==void 0?e.currency:n?.currency??d;r.includes(t)||(t=m);const F=e.vatIncluded!==void 0?e.vatIncluded:n?.vatIncluded??!0,M=e.discountPercent!==void 0?e.discountPercent:n?.discountPercent??0;I({amount:l===null?null:Number(l),currency:t,vatIncluded:F,discountPercent:Number(M)})},k=e=>{const l=e.target.value;if(l===""||l===null){i({amount:null});return}const t=parseFloat(l);i({amount:isNaN(t)?null:t})},V=e=>{i({currency:e||d})},$=e=>{const l=e.target.value;if(l===""||l===null){i({discountPercent:0});return}const t=parseFloat(l);i({discountPercent:isNaN(t)?0:t})},[v,j]=z(!1);return u(B,{open:v,onOpenChange:j,children:[u(E,{children:[u("div",{style:{display:"grid",gridTemplateColumns:"1fr auto",gap:"var(--gap-sm)",alignItems:"end"},children:[a(C,{id:c,type:"number",inputMode:"decimal",label:S,value:n?.amount!==void 0&&n?.amount!==null?n.amount:"",onChange:k,disabled:o,placeholder:N,required:P,min:0,step:.01,"data-variant":s?"destructive":void 0,"aria-invalid":s}),a(G,{asChild:!0,children:a("button",{type:"button","aria-label":x,"aria-expanded":v,className:"dndev-collapsible-trigger",style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"var(--gap-sm)",background:"none",border:"none",cursor:"pointer"},children:v?a(U,{className:"dndev-collapsible-icon","aria-hidden":"true"}):a(R,{className:"dndev-collapsible-icon","aria-hidden":"true"})})})]}),a(H,{className:"dndev-collapsible-content",children:u("div",{style:{display:"grid",gridTemplateColumns:r.length>1?"1fr auto 1fr":"auto 1fr",gap:"var(--gap-sm)",alignItems:"end",paddingTop:"var(--gap-md)"},children:[r.length>1&&a(A,{value:m,onValueChange:V,placeholder:d,options:r.map(e=>({value:e,label:e})),disabled:o,label:p("price.currency",{defaultValue:"Currency"})}),a(D,{id:`${c}-vat`,label:p("price.vatIncluded",{defaultValue:"VAT Incl."}),checked:T,onCheckedChange:e=>i({vatIncluded:e===!0}),disabled:o}),a(C,{id:`${c}-discount`,type:"number",inputMode:"decimal",min:0,max:100,step:1,value:y===0?"":y,onChange:$,disabled:o,placeholder:"0",label:p("price.discountLabel",{defaultValue:"Discount (%)"})})]})})]}),g&&a("p",{style:{fontSize:"var(--font-size-xs)",color:s?"var(--destructive-foreground)":"var(--muted-foreground)"},children:g})]})};var w=Y;export{w as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as l}from"react/jsx-runtime";import{Label as h,Slider as b,Stack as d}from"@donotdev/components";const x=({label:
|
|
1
|
+
import{jsx as e,jsxs as l}from"react/jsx-runtime";import{Label as h,Slider as b,Stack as d}from"@donotdev/components";const x=({label:t,value:i=0,onChange:u,error:n,helperText:s,min:r=0,max:c=100,step:v=1,disabled:o,required:m,showValue:f=!0})=>{const g=a=>{const p={target:{value:a.toString()}};u(p)};return l(d,{gap:"tight",children:[l(d,{direction:"row",justify:"between",align:"center",children:[e(h,{required:m,style:{fontSize:"var(--font-size-sm)",fontWeight:500},children:t}),f&&e("span",{style:{fontSize:"var(--font-size-sm)",color:"var(--muted-foreground)"},children:i})]}),e(b,{value:[i??r],onValueChange:([a])=>g(a??r),min:r,max:c,step:v,disabled:o,style:{borderColor:n?"var(--destructive)":void 0,opacity:o?"var(--opacity-muted)":void 0,cursor:o?"not-allowed":void 0},"aria-label":t}),s&&e("p",{style:{fontSize:"var(--font-size-xs)",color:n?"var(--destructive-foreground)":"var(--muted-foreground)",marginTop:"var(--gap-sm)"},children:s})]})};var y=x;export{y as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as e}from"react/jsx-runtime";import{lazy as m,Suspense as b,useState as f,useEffect as g}from"react";import{Stack as v}from"@donotdev/components";import
|
|
1
|
+
"use client";import{jsx as e}from"react/jsx-runtime";import{lazy as m,Suspense as b,useState as f,useEffect as g}from"react";import{Stack as v}from"@donotdev/components";import h from"./TextAreaComponent";const p=m(()=>typeof window<"u"?import("./internal/TiptapEditor").catch(()=>({default:()=>null})):Promise.resolve({default:()=>null})),x=({label:l,value:a="",onChange:r,error:s,helperText:o,required:d,disabled:t,placeholder:i,className:u})=>{const[c,n]=f(!1);return g(()=>{n(!0)},[]),c?e(v,{gap:"tight",children:e(b,{fallback:e(h,{label:l,value:a,onChange:r,error:s,helperText:o,required:d,disabled:t,placeholder:i,className:u}),children:p?e(p,{label:l,value:a,onChange:r,error:s,helperText:o,required:d,disabled:t,placeholder:i,className:u}):e(h,{label:l,value:a,onChange:r,error:s,helperText:o,required:d,disabled:t,placeholder:i,className:u})})}):e(h,{label:l,value:a,onChange:r,error:s,helperText:o,required:d,disabled:t,placeholder:i,className:u})};var C=x;export{C as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as e,jsx as r}from"react/jsx-runtime";import{Switch as k,Text as l,Stack as n}from"@donotdev/components";const p=({label:a,checked:d=!1,onChange:
|
|
1
|
+
import{jsxs as e,jsx as r}from"react/jsx-runtime";import{Switch as k,Text as l,Stack as n}from"@donotdev/components";const p=({label:a,checked:d=!1,onChange:c,uncheckedLabel:h,checkedLabel:s,helperText:t})=>{const i=o=>{c&&c({target:{checked:o}})};return e(n,{gap:"tight",children:[e(n,{direction:"row",align:"center",style:{flexWrap:"wrap"},children:[e(l,{level:"body",textAlign:"start",children:[a,":"]}),r(k,{checked:d,onCheckedChange:i,"aria-label":a,variant:"muted",uncheckedLabel:h,checkedLabel:s})]}),t&&r(l,{as:"p",variant:"muted",level:"small",children:t})]})};var g=p;export{g as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as t,jsxs as
|
|
1
|
+
"use client";import{jsx as t,jsxs as l}from"react/jsx-runtime";import{useState as L,useId as N,useRef as F,useEffect as j}from"react";import{Textarea as q,FloatingLabel as A,Spinner as k,cn as m,Stack as p}from"@donotdev/components";const B=({label:x,value:o="",onChange:b,error:h,helperText:s,rows:y=3,loading:n=!1,maxLength:r,showCharCount:v=!1,autoResize:i=!1,required:z=!1,disabled:g=!1,className:w,...S})=>{const e=N(),[I,f]=L(!1),d=F(null),a=!!h,c=o.length,$=r&&c>r*.8,C=r&&c>r;return j(()=>{if(i&&d.current){const u=d.current;u.style.height="auto",u.style.height=`${u.scrollHeight}px`}},[o,i]),l(p,{gap:"tight",children:[t(A,{htmlFor:e,label:x,disabled:g||n,required:z,children:l("div",{className:"dndev-relative",children:[t(q,{ref:d,id:e,value:o,onChange:b,onFocus:()=>f(!0),onBlur:()=>f(!1),disabled:g||n,maxLength:r,rows:i?1:y,bare:!0,"aria-describedby":m(a&&`${e}-error`,s&&!a&&`${e}-helper`,v&&`${e}-count`),"aria-invalid":a,className:m("dndev-w-full",i&&"dndev-overflow-hidden",w),"data-variant":a?"destructive":void 0,style:{resize:i?"none":void 0},...S}),n&&t("div",{className:"dndev-absolute",style:{right:"var(--gap-md)",top:"var(--gap-md)"},children:t(k,{"aria-label":"Loading"})})]})}),v&&r&&l("div",{id:`${e}-count`,style:{fontSize:"var(--font-size-xs)",textAlign:"right",color:C?"var(--destructive-foreground)":$?"var(--warning)":"var(--muted-foreground)"},children:[c,"/",r]}),a&&l(p,{as:"p",id:`${e}-error`,direction:"row",align:"center",gap:"tight",style:{fontSize:"var(--font-size-xs)",color:"var(--destructive-foreground)"},role:"alert",children:[t("span",{children:"\u26A0"}),h]}),s&&!a&&t("p",{id:`${e}-helper`,style:{fontSize:"var(--font-size-xs)",color:"var(--muted-foreground)"},children:s})]})};var E=B;export{E as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{valibotResolver as B}from"@hookform/resolvers/valibot";import{useMemo as C,useEffect as
|
|
1
|
+
"use client";import{valibotResolver as B}from"@hookform/resolvers/valibot";import{useMemo as C,useEffect as T,useRef as y,createElement as ce}from"react";import{useForm as fe}from"react-hook-form";import{toast as G,ToastAction as de}from"@donotdev/components";import{BACKEND_GENERATED_FIELD_NAMES as me,createSchemas as ge}from"@donotdev/core";import{useFormStore as d,useFormStatus as pe,useUploadProgress as be}from"../../stores";import{useUploadStore as w}from"../../stores/UploadStore";import{checkForBlobUrls as Se,isStorageUrl as ye}from"../../utils/uploadValidation";import{getFieldsForOperation as he}from"../utils";import{buildInitialFromRecord as ve,buildSchemaDefaults as Ee}from"../utils/buildInitialValues";const je=t=>t;function K(t,f){const e={...t};for(const b of Object.keys(f)){const l=t[b],h=f[b];h!==null&&typeof h=="object"&&!Array.isArray(h)&&l!==null&&typeof l=="object"&&!Array.isArray(l)?e[b]=K(l,h):e[b]=h}return e}function L(t){if(t==null)return t;if(typeof t=="string")return t.startsWith("blob:")?null:t;if(Array.isArray(t)){const f=t.map(L).filter(e=>e!==null);return f.length>0?f:null}if(typeof t=="object"){const f=t;if("fullUrl"in f&&typeof f.fullUrl=="string")return ye(f.fullUrl)?f:null;const e={};for(const[b,l]of Object.entries(f))e[b]=L(l);return e}return t}function De(t,f={}){const{formId:e,operation:b,defaultValues:l,viewerRole:h,mode:W="onBlur",t:Y,loading:F=!1}=f,S=Y??je,N=h??"guest",c=b??(l?"edit":"create"),H=pe(e??""),J=be(e??""),$=C(()=>ge(t),[t.name]),Q=C(()=>{const r=B($.create),o=B($.draft),n=B($.update);return async(a,s,i)=>c==="edit"?n(a,s,i):(a?.status??l?.status??"draft")==="draft"?o(a,s,i):r(a,s,i)},[$,c,l?.status]),A=C(()=>Ee(t),[t]),U=l,m=C(()=>{if(!F)return c==="edit"?U?ve(t,U):void 0:U?{...A,...U}:A},[F,c,A,t,U]),u=fe({defaultValues:c==="create"?m:void 0,mode:W,resolver:Q,shouldUnregister:!1,shouldFocusError:!0}),E=y(u);T(()=>{E.current=u},[u]);const I=y(null);T(()=>{if(c==="edit"&&m){const r=m.id??null;r&&r!==I.current?(E.current.reset(m),I.current=r):!r&&I.current===null&&(E.current.reset(m),I.current="initialized")}},[c,m]);const k=l?.id,x=`${t.name.toLowerCase()}-form-draft`,v=c==="create"?x:k?`${x}-${k}`:`${x}-edit`,j=y(!1),_=y(F);_.current&&!F&&(j.current=!1),_.current=F,T(()=>{if(j.current)return;const r=d.getState().loadDraft(v),o=n=>{const a=()=>{d.getState().clearDraft(v),n&&E.current.reset(n)};G({toastType:"info",title:S("draft.restored",{defaultValue:"Draft restored"}),description:S("draft.restoredDescription",{defaultValue:"Your unsaved changes were recovered"}),action:ce(de,{altText:S("draft.discard",{defaultValue:"Discard"}),onClick:a},S("draft.discard",{defaultValue:"Discard"})),duration:8e3})};if(c==="create"&&!l){r&&(u.reset(r.data),o(A)),j.current=!0;return}if(c==="edit"&&m){if(r){const n=K(m,r.data);u.reset(n),o(m)}j.current=!0}},[c,l,v,u,m,S,A]);const P=y(!1),V=y(null);T(()=>{const r=u.watch(o=>{P.current||!j.current||(V.current&&clearTimeout(V.current),V.current=setTimeout(()=>{if(o&&Object.values(o).some(n=>n!=null&&n!=="")){const n=L(o);d.getState().saveDraft(v,n,t.name,k)}},3e3))});return()=>{r.unsubscribe(),V.current&&clearTimeout(V.current)}},[u,v,t.name,k]);const D=y(null),O=y(!1),X=async r=>{if(!e)return{};const o=w.getState(),n=d.getState();if(!o.hasPendingUploads(e))return{};const a=setInterval(()=>{const s=w.getState().getTotalProgress(e);d.getState().setUploading(e,s)},200);try{return n.setUploading(e,0),await o.uploadAll(e,r),r?.aborted?null:w.getState().getResults(e)}catch(s){const i=w.getState().uploads[e];i&&Object.entries(i).forEach(([g,R])=>{R.status==="error"&&R.error&&u.setError(g,{type:"upload",message:R.error})});const p=s instanceof Error?s.message:"File upload failed";return d.getState().setError(e,p),null}finally{clearInterval(a)}},Z=r=>c!=="create"?r:Object.fromEntries(Object.entries(r).filter(([o])=>!me.includes(o))),ee=(r,o)=>{const n={...o};for(const[a,s]of Object.entries(r.fields))if(s.type==="price"&&a in n){const i=n[a];(i==null||i.amount==null)&&(n[a]=null)}return n},te=r=>{if(typeof window>"u")return;const o=Object.keys(r).find(a=>a!=="root"&&r[a]);if(!o)return;const n=document.querySelector(`input[name="${o}"][aria-invalid="true"], textarea[name="${o}"][aria-invalid="true"], select[name="${o}"][aria-invalid="true"]`)??document.querySelector(`[name="${o}"]`);n&&(n.scrollIntoView({behavior:"smooth",block:"center"}),n.focus())},re=u.handleSubmit,ae=((r,o)=>async n=>{if(n?.preventDefault?.(),O.current)return;const a=e?d.getState():null;await re(async(s,i)=>{if(O.current)return;O.current=!0,D.current?.abort();const p=new AbortController;D.current=p,P.current=!0;try{e&&a&&a.startSubmit(e);const g=await X(p.signal);if(g===null||p.signal.aborted)return;e&&a&&a.setSubmitting(e);const R={...s,...g},ue=Z(R),M=ee(t,ue),z=Se(M);if(z.length>0){const le=`Cannot save: blob URLs detected at ${z.join(", ")}. Re-upload the files.`;e&&a&&a.setError(e,le);return}if(p.signal.aborted)return;await r(M,i),d.getState().clearDraft(v),E.current.reset(E.current.getValues()),e&&a&&a.setSuccess(e)}catch(g){throw e&&a&&a.setError(e,g instanceof Error?g.message:"Submission failed"),g}finally{if(P.current=!1,O.current=!1,D.current===p&&(D.current=null),e){const g=d.getState().forms[e]?.status;(g==="uploading"||g==="validating"||g==="submitting")&&d.getState().reset(e)}}},s=>{const i=Object.keys(s).filter(p=>p!=="root"&&s[p]);G({toastType:"error",title:S("validation.failed",{defaultValue:"Validation failed"}),description:S("validation.fixErrorsCount",{count:i.length,fields:i.join(", "),defaultValue:`${i.length} field(s) need attention: ${i.join(", ")}`}),duration:8e3}),te(s),o?.(s)})(n)}),ne=()=>{d.getState().clearDraft(v),u.reset(m),j.current=!1},q=()=>{D.current?.abort(),e&&(d.getState().cleanup(e),w.getState().cleanup(e))};T(()=>q,[]);const oe=()=>{D.current?.abort(),e&&(w.getState().abortAll(e),d.getState().reset(e)),O.current=!1},se=he(t,{operation:c,viewerRole:N,availableFields:void 0}),ie=u.formState.isSubmitted||Object.keys(u.formState.touchedFields||{}).length>0;return{...u,handleSubmit:ae,fields:se,operation:c,entity:t,t:S,viewerRole:N,formId:e,formStatus:e?H:"idle",uploadProgress:e?J:0,cleanup:q,cancel:oe,isDirty:u.formState.isDirty,hasUserInteracted:ie,resetForm:ne,originalValues:m}}export{De as useEntityForm};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function s(i,
|
|
1
|
+
function s(i,p){if(p in i)return i[p];const c=p.replace(/_([a-z])/g,(t,n)=>n.toUpperCase());if(c!==p&&c in i)return i[c]}function u(i,p){if(p in i)return!0;const c=p.replace(/_([a-z])/g,(t,n)=>n.toUpperCase());return c!==p&&c in i}function l(i,p){const c=p??{},t={...c};return Object.entries(i.fields).forEach(([n,e])=>{const r=s(t,n);r!==void 0&&!(n in t)&&(t[n]=r);const a=!u(c,n)||r===null||r===void 0;if(n==="status"&&a)t[n]="draft";else if(e.type==="switch"){if(r==null){const o=e.options?.fieldSpecific;t[n]=o?.uncheckedValue??!1}}else a&&(e.type==="price"?t[n]=null:e.type==="checkbox"||e.type==="boolean"?t[n]=!1:e.type==="text"||e.type==="textarea"||e.type==="email"||e.type==="url"||e.type==="tel"||e.type==="iban"||e.type==="password"||e.type==="color"?t[n]="":(e.type==="number"||e.type==="range"||e.type==="rating")&&(t[n]=void 0))}),t}function f(i){return l(i,{})}export{l as buildInitialFromRecord,f as buildSchemaDefaults};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EDITABLE as
|
|
1
|
+
import{EDITABLE as i,hasRoleAccess as t}from"@donotdev/core";function r(e,o,s){return e===void 0||e===!0?!0:e===!1||e===i.GENERATED||e===i.COMPUTED?!1:e===i.CREATE_ONLY?s==="create":typeof e=="string"?t(o,e):!0}export{r as isFieldEditable};
|