@dashadmin/dash-components 1.3.24 → 1.3.26

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.
Files changed (111) hide show
  1. package/dist/components/AuditLog/AuditLog.js +345 -1
  2. package/dist/components/AuditLog/index.js +4 -1
  3. package/dist/components/AutoCompleteArrayInput/AutoCompleteCheckBoxInput.js +630 -3
  4. package/dist/components/AutoCompleteArrayInput/AutocompleteCheckBoxArrayInput.js +53 -1
  5. package/dist/components/AutoCompleteArrayInputAutoSearch/AutoCompleteCheckBoxInput.js +647 -3
  6. package/dist/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayInput.js +53 -1
  7. package/dist/components/Json/Json.js +235 -1
  8. package/dist/components/JsonColorSelector/JsonColorSelector.js +1172 -1
  9. package/dist/components/JsonColorSelector/JsonColorSelectorEnhanced.js +863 -2
  10. package/dist/components/JsonColorSelector/JsonCssVarValues.js +738 -1
  11. package/dist/components/JsonColorSelector/components/ColorEditDialog.js +426 -1
  12. package/dist/components/JsonColorSelector/components/ColorPaletteItem.js +75 -1
  13. package/dist/components/JsonColorSelector/components/ImageColorExtractor.js +283 -1
  14. package/dist/components/JsonColorSelector/helpers/functions.js +101 -1
  15. package/dist/components/JsonColorSelector/useAsyncColorThief.js +105 -1
  16. package/dist/components/ListActive/ListActive.js +126 -1
  17. package/dist/components/ListActive/ListBoolean.js +124 -1
  18. package/dist/components/NotificationPreferences/NotificationPreferences.js +317 -1
  19. package/dist/components/NotificationPreferences/index.js +7 -1
  20. package/dist/components/SearchableSelects/RASearchableSelect.js +236 -1
  21. package/dist/components/SearchableSelects/RASearchableSelectCheckboxes.js +479 -1
  22. package/dist/components/SearchableSelects/RASearchableSelectChips.js +465 -1
  23. package/dist/components/SearchableSelects/RASearchableSelectChipsRecordContext.js +295 -1
  24. package/dist/components/SearchableSelects/SearchableSelect.js +202 -1
  25. package/dist/components/SearchableSelects/SearchableSelectCheckboxes.js +290 -1
  26. package/dist/components/SortableDataGrid/SortableDataGrid.js +72 -1
  27. package/dist/components/SortableDataGrid/SortableDataGridBody.js +167 -1
  28. package/dist/components/SortableDataGrid/SortableDataGridHeader.js +109 -1
  29. package/dist/components/SortableDataGrid/SortableDataGridRow.js +283 -1
  30. package/dist/components/Upload/SingleImageUploader.js +40 -1
  31. package/dist/components/custom/PackageCopyMethod.js +78 -1
  32. package/dist/components/custom/PackageRadioButtonGroup.js +45 -1
  33. package/dist/components/dialog/Basic.js +8 -1
  34. package/dist/components/dialog/Correct.js +14 -1
  35. package/dist/components/dialog/Error.js +14 -1
  36. package/dist/components/dialog/Info.js +14 -1
  37. package/dist/components/dialog/InfoV2.js +21 -1
  38. package/dist/components/dialog/NotFound.js +14 -1
  39. package/dist/components/dialog/QuickSearch.js +117 -1
  40. package/dist/components/notifications/NotificationsCenter.js +597 -1
  41. package/dist/components/notifications/index.js +24 -1
  42. package/dist/components/tables/PaginationComponent.js +36 -1
  43. package/dist/components/theme/AppLoadingFallback.js +38 -2
  44. package/dist/components/theme/ErrorBoundary.js +52 -1
  45. package/dist/components/theme/InitialLoader.js +13 -1
  46. package/dist/components/theme/NotFound.js +136 -1
  47. package/dist/components/theme/NotResults.js +38 -1
  48. package/dist/hooks/useDraggable.js +6 -1
  49. package/dist/hooks/useNotifications.js +8 -1
  50. package/dist/hooks/useQuickSearch.js +26 -1
  51. package/dist/index.js +66 -5567
  52. package/dist/utils/setNativeValue.js +17 -1
  53. package/package.json +149 -132
  54. package/src/components/AuditLog/AuditLog.tsx +476 -0
  55. package/src/components/AuditLog/index.ts +2 -0
  56. package/src/components/AutoCompleteArrayInput/AutoCompleteCheckBoxInput.tsx +917 -0
  57. package/src/components/AutoCompleteArrayInput/AutocompleteCheckBoxArrayInput.tsx +39 -0
  58. package/src/components/AutoCompleteArrayInputAutoSearch/AutoCompleteCheckBoxInput.tsx +916 -0
  59. package/src/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayInput.tsx +44 -0
  60. package/src/components/Json/Json.tsx +312 -0
  61. package/src/components/JsonColorSelector/JsonColorSelector.tsx +1435 -0
  62. package/src/components/JsonColorSelector/JsonColorSelectorEnhanced.tsx +1029 -0
  63. package/src/components/JsonColorSelector/JsonCssVarValues.tsx +863 -0
  64. package/src/components/JsonColorSelector/components/ColorEditDialog.tsx +491 -0
  65. package/src/components/JsonColorSelector/components/ColorPaletteItem.tsx +80 -0
  66. package/src/components/JsonColorSelector/components/ImageColorExtractor.tsx +328 -0
  67. package/src/components/JsonColorSelector/helpers/functions.tsx +123 -0
  68. package/src/components/JsonColorSelector/interfaces/interfaces.tsx +22 -0
  69. package/src/components/JsonColorSelector/useAsyncColorThief.tsx +97 -0
  70. package/src/components/ListActive/ListActive.tsx +106 -0
  71. package/src/components/ListActive/ListBoolean.tsx +96 -0
  72. package/src/components/NotificationPreferences/NotificationPreferences.tsx +463 -0
  73. package/src/components/NotificationPreferences/index.tsx +2 -0
  74. package/src/components/SearchableSelects/RASearchableSelect.tsx +300 -0
  75. package/src/components/SearchableSelects/RASearchableSelectCheckboxes.tsx +604 -0
  76. package/src/components/SearchableSelects/RASearchableSelectChips.tsx +558 -0
  77. package/src/components/SearchableSelects/RASearchableSelectChipsRecordContext.tsx +362 -0
  78. package/src/components/SearchableSelects/SearchableSelect.tsx +321 -0
  79. package/src/components/SearchableSelects/SearchableSelectCheckboxes.tsx +355 -0
  80. package/src/components/SortableDataGrid/SortableDataGrid.tsx +56 -0
  81. package/src/components/SortableDataGrid/SortableDataGridBody.tsx +175 -0
  82. package/src/components/SortableDataGrid/SortableDataGridHeader.tsx +171 -0
  83. package/src/components/SortableDataGrid/SortableDataGridRow.tsx +247 -0
  84. package/src/components/Upload/SingleImageUploader.tsx +55 -0
  85. package/src/components/custom/PackageCopyMethod.tsx +109 -0
  86. package/src/components/custom/PackageRadioButtonGroup.tsx +47 -0
  87. package/src/components/dialog/Basic.tsx +11 -0
  88. package/src/components/dialog/Correct.tsx +16 -0
  89. package/src/components/dialog/Error.tsx +15 -0
  90. package/src/components/dialog/Info.tsx +15 -0
  91. package/src/components/dialog/InfoV2.tsx +35 -0
  92. package/src/components/dialog/NotFound.tsx +18 -0
  93. package/src/components/dialog/QuickSearch.tsx +115 -0
  94. package/src/components/notifications/NotificationsCenter.tsx +792 -0
  95. package/src/components/notifications/index.ts +42 -0
  96. package/src/components/tables/PaginationComponent.tsx +17 -0
  97. package/src/components/theme/AppLoadingFallback.tsx +42 -0
  98. package/src/components/theme/ErrorBoundary.tsx +57 -0
  99. package/src/components/theme/InitialLoader.tsx +16 -0
  100. package/src/components/theme/NotFound.tsx +124 -0
  101. package/src/components/theme/NotResults.tsx +54 -0
  102. package/src/hooks/useDraggable.ts +11 -0
  103. package/src/hooks/useNotifications.ts +14 -0
  104. package/src/hooks/useQuickSearch.tsx +29 -0
  105. package/src/index.tsx +77 -0
  106. package/src/utils/setNativeValue.tsx +23 -0
  107. package/dist/color-thief-CTwGFhOB.js +0 -272
  108. /package/{dist → src}/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayAutoSearch.tsx.wip +0 -0
  109. /package/{dist → src}/components/JsonColorSelector/JsonColorSelector.tsx.bkup +0 -0
  110. /package/{dist → src}/components/SortableDataGrid/README.md +0 -0
  111. /package/{dist → src}/styles/index.less +0 -0
@@ -1 +1,1172 @@
1
- import{Fragment as Ie,jsx as e,jsxs as s}from"react/jsx-runtime";import{useRecordContext as me}from"react-admin";import{useFormContext as De}from"react-hook-form";import{Box as a,Button as j,IconButton as Y,TextField as U,Typography as S,Dialog as Re,DialogTitle as ze,DialogContent as Ee,DialogActions as Fe,Card as Ve,Chip as z,InputAdornment as F,FormControl as ne,InputLabel as oe,Select as ae,MenuItem as V,Tabs as Le,Tab as pe,Pagination as je,Link as We}from"@mui/material";import $e from"@mui/icons-material/Delete";import he from"@mui/icons-material/Add";import Ke from"@mui/icons-material/Edit";import Oe from"@mui/icons-material/Preview";import fe from"@mui/icons-material/Search";import X from"@mui/icons-material/Clear";import ye from"@mui/icons-material/FilterList";import{ChromePicker as Ne}from"react-color";import{useState as C,useEffect as W,useRef as xe,useCallback as be,useMemo as q}from"react";import{updateDomCssVariables as He}from"@dashadmin/dash-utils";import{AuthPersistenceService as Ge}from"@dashadmin/dash-auth";const re=n=>{let r,d,h,f=1;if(n.startsWith("#")){const o=n.replace("#","");o.length===8?(r=parseInt(o.substr(0,2),16),d=parseInt(o.substr(2,2),16),h=parseInt(o.substr(4,2),16),f=parseInt(o.substr(6,2),16)/255):(r=parseInt(o.substr(0,2),16),d=parseInt(o.substr(2,2),16),h=parseInt(o.substr(4,2),16))}else if(n.startsWith("rgb")){const o=n.match(/rgba?\(([^)]+)\)/);if(o){const p=o[1].split(",").map(k=>parseFloat(k.trim()));[r,d,h,f=1]=p}else return"#000000"}else return n.startsWith("hsl"),"#000000";return(.299*r+.587*d+.114*h)/255*f+(1-f)>.5?"#000000":"#ffffff"},qe=(n,r)=>{switch(r){case"hex":return n.hex;case"rgb":return`rgb(${Math.round(n.rgb.r)}, ${Math.round(n.rgb.g)}, ${Math.round(n.rgb.b)})`;case"rgba":return`rgba(${Math.round(n.rgb.r)}, ${Math.round(n.rgb.g)}, ${Math.round(n.rgb.b)}, ${n.rgb.a||1})`;case"hsl":return`hsl(${Math.round(n.hsl.h)}, ${Math.round(n.hsl.s*100)}%, ${Math.round(n.hsl.l*100)}%)`;case"hsla":return`hsla(${Math.round(n.hsl.h)}, ${Math.round(n.hsl.s*100)}%, ${Math.round(n.hsl.l*100)}%, ${n.hsl.a||1})`;default:return n.hex}},_=n=>{const r=n.split("--"),d=r[0],h=r[1];return{baseChips:d.split("-").filter(v=>v.length>0),mode:h}},Ce=n=>{const r=new Set;return n.forEach(d=>{const{mode:h}=_(d.key);h&&r.add(h)}),Array.from(r).sort()},G=n=>{if(!n)return"";switch(n.toLowerCase()){case"light":return"\u2600\uFE0F";case"dark":return"\u{1F319}";default:return n}},_e=({pair:n,onEdit:r,onDelete:d})=>{const h=re(n.value),{baseChips:f,mode:v}=_(n.key),I=G(v);return s(Ve,{onClick:()=>r(n),elevation:1,sx:{width:"100%",display:"flex",alignItems:"stretch",cursor:"pointer",transition:"all 0.2s ease-in-out","&:hover":{transform:"translateY(-2px)",boxShadow:3},borderRadius:2,overflow:"hidden",position:"relative",height:80,backgroundColor:"background.paper"},children:[e(a,{sx:{width:80,backgroundColor:n.value,flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",position:"relative"},children:e(a,{sx:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0,0,0,0.3)",opacity:0,transition:"opacity 0.2s","&:hover":{opacity:1},display:"flex",alignItems:"center",justifyContent:"center"},children:e(Ke,{sx:{color:"#fff"}})})}),s(a,{sx:{flexGrow:1,p:1.5,display:"flex",flexDirection:"column",justifyContent:"space-between",overflow:"hidden"},children:[s(a,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",mb:.5},children:[e(S,{variant:"caption",sx:{fontFamily:"monospace",fontWeight:"bold",color:"text.secondary"},children:n.value}),v&&e(z,{label:v,size:"small",icon:e("span",{style:{marginLeft:6,fontSize:"0.8rem"},children:I}),sx:{height:18,fontSize:"0.65rem","& .MuiChip-label":{padding:"0 6px"}}})]}),e(a,{sx:{display:"flex",flexWrap:"wrap",gap:.5},children:f.map((o,p)=>e(z,{label:o,size:"small",variant:"outlined",sx:{height:20,fontSize:"0.7rem",maxWidth:"100%","& .MuiChip-label":{padding:"0 6px",overflow:"hidden",textOverflow:"ellipsis"}}},p))})]})]})},Je=({open:n,pair:r,onClose:d,onSave:h,onDelete:f,existingKeys:v,updateSingleDomColor:I})=>{const[o,p]=C(null),[k,g]=C("hex"),[T,B]=C(""),[D,y]=C(0);W(()=>{r&&(p({...r}),r.value.startsWith("rgba(")?g("rgba"):r.value.startsWith("rgb(")?g("rgb"):r.value.startsWith("hsla(")?g("hsla"):r.value.startsWith("hsl(")?g("hsl"):g("hex")),B("")},[r]);const $=x=>{if(!o)return;const R=v.some(E=>E===x&&x!==r?.key);B(R?"Key already exists":""),p({...o,key:x})},A=x=>{if(!o)return;const R=qe(x,k);p({...o,value:R}),I(o.key,R)},K=()=>{!o||T||!o.key.trim()||(h(o),d())},N=()=>{o&&(f(o.id),d())};return o?s(Re,{open:n,onClose:d,maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{minHeight:600}},children:[e(ze,{children:r?.key?`Edit Color: ${r.key}`:"Add New Color"}),e(Ee,{children:s(a,{sx:{display:"flex",flexDirection:"column",gap:3,pt:1},children:[e(U,{fullWidth:!0,label:"Color Name",value:o.key,onChange:x=>$(x.target.value),error:!!T,helperText:T,placeholder:"e.g., primary-color--light, background-dark--dark"}),s(ne,{fullWidth:!0,children:[e(oe,{children:"Color Format"}),s(ae,{value:k,label:"Color Format",onChange:x=>g(x.target.value),children:[e(V,{value:"hex",children:"HEX"}),e(V,{value:"rgb",children:"RGB"}),e(V,{value:"rgba",children:"RGBA (with alpha)"}),e(V,{value:"hsl",children:"HSL"}),e(V,{value:"hsla",children:"HSLA (with alpha)"})]})]}),s(a,{children:[s(Le,{value:D,onChange:(x,R)=>y(R),children:[e(pe,{label:"Color Picker"}),e(pe,{label:"Manual Input"})]}),D===0&&e(a,{sx:{mt:2,display:"flex",justifyContent:"center"},children:e(Ne,{color:o.value,onChange:A,disableAlpha:!["rgba","hsla"].includes(k)})}),D===1&&e(a,{sx:{mt:2},children:e(U,{fullWidth:!0,label:`Color Value (${k.toUpperCase()})`,value:o.value,onChange:x=>p({...o,value:x.target.value}),placeholder:k==="hex"?"#ff0000":k==="rgb"?"rgb(255, 0, 0)":k==="rgba"?"rgba(255, 0, 0, 1)":k==="hsl"?"hsl(0, 100%, 50%)":"hsla(0, 100%, 50%, 1)",InputProps:{startAdornment:e(F,{position:"start",children:e(a,{sx:{width:20,height:20,backgroundColor:o.value,border:"1px solid #ccc",borderRadius:1}})})}})})]}),s(a,{children:[e(S,{variant:"subtitle2",gutterBottom:!0,children:"Preview"}),e(a,{sx:{width:"100%",height:80,backgroundColor:o.value,border:"1px solid #ccc",borderRadius:1,display:"flex",alignItems:"center",justifyContent:"center",position:"relative"},children:e(S,{variant:"body2",sx:{color:re(o.value),fontWeight:"bold",backgroundColor:"rgba(0,0,0,0.1)",padding:"4px 8px",borderRadius:1},children:o.key||"Color Preview"})})]})]})}),s(Fe,{children:[r?.key&&e(j,{onClick:N,color:"error",startIcon:e($e,{}),children:"Delete"}),e(a,{sx:{flexGrow:1}}),e(j,{onClick:d,children:"Cancel"}),e(j,{onClick:K,variant:"contained",disabled:!!T||!o.key.trim(),children:"Save"})]})]}):null},ve=n=>{const{method:r,attribute:d,resourceConfig:h}=n,f=me(),{setValue:v,getValues:I}=De(),o=d.attribute,p=o.startsWith("settings."),k=p?o.split(".").slice(1).join("."):o,[g,T]=C([]),[B,D]=C(""),[y,$]=C(""),[A,K]=C(!0),[N,x]=C(!0),[R,E]=C(!1),[Q,O]=C(null),[i,m]=C(1),[b]=C(24),M=xe(null),J=xe(new Map),P=be(t=>{window.dispatchEvent(new MessageEvent("auto-admin-loading-state",{data:t}))},[]),H=q(()=>Ce(g),[g]),L=q(()=>{let t=g;return B.trim()&&(t=t.filter(l=>l.key.toLowerCase().includes(B.toLowerCase()))),y&&(t=t.filter(l=>{const{mode:u}=_(l.key);return u===y})),t},[g,B,y]),ke=t=>{D(t.target.value)},se=()=>{D("")},Se=t=>{$(t.target.value)},le=()=>{$("")};W(()=>{(async()=>{K(!0),P(!0);try{let l={},u={};try{u=d?.default_value||{}}catch{u={}}if(p&&f?.settings){const w=f.settings||{};l={...u,...we(w,k)}}else f?.[o]?l={...u,...f[o]}:l=u;const c=Object.entries(l).map(([w,Z])=>({key:w,value:String(Z),id:ie()}));T(c),c.length>50&&await new Promise(w=>setTimeout(w,100))}catch(l){console.error("Error loading initial data:",l)}finally{K(!1)}})()},[f,o]),W(()=>{!A&&g.length>=0&&(x(!0),requestAnimationFrame(()=>{requestAnimationFrame(()=>{x(!1),P(!1)})}))},[A,g.length,P]),W(()=>()=>{M.current&&clearTimeout(M.current),P(!1)},[P]);const we=(t,l)=>l?l.split(".").reduce((c,w)=>c&&c[w]!==void 0?c[w]:{},t):t,Be=(t,l,u)=>{if(!l)return u;const c=l.split("."),w=c.pop(),Z=c.reduce((ee,te)=>(ee[te]===void 0&&(ee[te]={}),ee[te]),t);return w&&(Z[w]=u),t},ie=()=>Math.random().toString(36).substring(2,11),de=()=>{const t={key:"",value:"#000000",id:ie()};O(t),E(!0)},Me=t=>{O(t),E(!0)},Ae=t=>{const l=g.findIndex(c=>c.id===t.id);let u;l>=0?u=g.map(c=>c.id===t.id?t:c):u=[...g,t],T(u),ge(u),ce(t.key,t.value)},ue=t=>{const l=g.filter(u=>u.id!==t);T(l),ge(l)},ce=(t,l)=>{if(!t.trim())return;const c=`--${document.documentElement.getAttribute("data-theme")}`;if(t.endsWith(c)){const w=t.slice(0,-c.length);document.documentElement.style.setProperty(`--${w}`,l)}},Te=()=>{const t=Ge.getTenantSettings();return t?t?.values||{}:{}},Pe=t=>{const l=g.reduce((u,c)=>(c.key.trim()&&(u[c.key]=c.value),u),{});He(t,l,Te())},ge=t=>{const l=t.reduce((u,c)=>(c.key.trim()&&(u[c.key]=c.value),u),{});if(p){const u=I("settings")||{},c=Be({...u},k,l);v("settings",c,{shouldDirty:!0})}else v(o,l,{shouldDirty:!0})};return A||N?e(a,{sx:{mt:1,mb:2,display:"flex",justifyContent:"center",alignItems:"center",minHeight:200},children:e(S,{variant:"body2",color:"textSecondary",children:A?"Loading color settings...":"Rendering colors..."})}):s(a,{sx:{mt:1,mb:2},children:[e(S,{variant:"subtitle1",gutterBottom:!0,children:d.label||"Color Palette"}),s(a,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:3},children:[e(j,{startIcon:e(Oe,{}),variant:"contained",size:"small",onClick:()=>Pe(document.documentElement.getAttribute("data-theme")),color:"primary",children:"Preview Colors TEST"}),e(j,{startIcon:e(he,{}),variant:"outlined",size:"small",onClick:de,children:"Add Color"})]}),s(a,{sx:{mb:3,display:"flex",gap:2,alignItems:"flex-end"},children:[e(U,{fullWidth:!0,size:"small",placeholder:"Search colors by name...",value:B,onChange:ke,InputProps:{startAdornment:e(F,{position:"start",children:e(fe,{})}),endAdornment:B&&e(F,{position:"end",children:e(Y,{size:"small",onClick:se,edge:"end",children:e(X,{})})})}}),s(ne,{size:"small",sx:{minWidth:150},children:[e(oe,{children:"Mode"}),s(ae,{value:y,label:"Mode",onChange:Se,startAdornment:e(F,{position:"start",children:e(ye,{fontSize:"small"})}),endAdornment:y&&e(F,{position:"end",children:e(Y,{size:"small",onClick:le,edge:"end",sx:{mr:1},children:e(X,{fontSize:"small"})})}),children:[e(V,{value:"",children:e("em",{children:"All Modes"})}),H.map(t=>e(V,{value:t,children:s(a,{sx:{display:"flex",alignItems:"center",gap:1},children:[e("span",{children:G(t)}),e("span",{children:t})]})},t))]})]})]}),(B||y)&&s(a,{sx:{mb:2,display:"flex",alignItems:"center",gap:1,flexWrap:"wrap"},children:[e(z,{label:`${L.length} of ${g.length} colors`,size:"small",variant:"outlined"}),y&&e(z,{label:`Mode: ${y}`,size:"small",variant:"filled",color:"primary",onDelete:le,avatar:e("span",{style:{paddingLeft:6},children:G(y)})}),B&&e(z,{label:`Search: "${B}"`,size:"small",variant:"filled",color:"secondary",onDelete:se})]}),N?e(a,{sx:{display:"flex",justifyContent:"center",p:4,alignItems:"center",flexDirection:"column",gap:2},children:e(S,{children:"Rendering Grid..."})}):L.length>0?s(Ie,{children:[e(a,{sx:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(300px, 1fr))",gap:2,width:"100%"},children:L.slice((i-1)*b,i*b).map(t=>e(a,{sx:{minWidth:0},children:e(_e,{pair:t,onEdit:Me,onDelete:ue})},t.id))}),L.length>b&&e(a,{sx:{mt:4,display:"flex",justifyContent:"center"},children:e(je,{count:Math.ceil(L.length/b),page:i,onChange:(t,l)=>m(l),color:"primary",size:"large",showFirstButton:!0,showLastButton:!0})}),s(S,{variant:"caption",sx:{display:"block",textAlign:"center",mt:2,color:"text.secondary"},children:["Showing ",Math.min((i-1)*b+1,L.length)," - ",Math.min(i*b,L.length)," of ",L.length," colors"]})]}):s(a,{sx:{p:4,textAlign:"center",bgcolor:"background.paper",borderRadius:1,border:"1px dashed #ccc"},children:[e(S,{color:"textSecondary",children:"No colors found using current filters."}),e(a,{sx:{mt:1},children:e(We,{component:"button",variant:"body2",onClick:()=>{D(""),$(""),m(1)},children:"Clear filters"})})]}),g.length===0&&s(a,{sx:{textAlign:"center",py:4},children:[e(S,{variant:"body2",color:"textSecondary",gutterBottom:!0,children:"No colors in your palette yet"}),e(j,{startIcon:e(he,{}),variant:"contained",onClick:de,children:"Add Your First Color"})]}),e(Je,{open:R,pair:Q,onClose:()=>{E(!1),O(null)},onSave:Ae,onDelete:ue,existingKeys:g.map(t=>t.key),updateSingleDomColor:ce})]})},Ye=n=>{const{attribute:r}=n,d=me(),h=r.attribute,f=h.startsWith("settings."),v=f?h.split(".").slice(1).join("."):h,[I,o]=C(""),[p,k]=C(""),[g,T]=C(!0),[B,D]=C(!0),[y,$]=C({}),A=be(i=>{window.dispatchEvent(new MessageEvent("auto-admin-loading-state",{data:i}))},[]),K=q(()=>Object.entries(y).map(([i,m])=>({key:i,value:String(m),id:i})),[y]),N=q(()=>Ce(K),[K]);W(()=>{(async()=>{T(!0),A(!0);try{let m={},b={};try{b=r?.default_value||{}}catch{b={}}if(f&&d?.settings){const M=d.settings||{};if(v){const J=v.split(".");m={...b,...J.reduce((P,H)=>P&&P[H]!==void 0?P[H]:{},M)}}else m={...b,...M}}else d?.[h]?m={...b,...d[h]}:m=b;$(m),Object.keys(m).length>50&&await new Promise(M=>setTimeout(M,100))}catch(m){console.error("Error loading view data:",m)}finally{T(!1)}})()},[d,h,r,f,v]),W(()=>{!g&&Object.keys(y).length>=0&&(D(!0),requestAnimationFrame(()=>{requestAnimationFrame(()=>{D(!1),A(!1)})}))},[g,y,A]),W(()=>()=>{A(!1)},[A]);const x=q(()=>{let i=Object.entries(y);return I.trim()&&(i=i.filter(([m])=>m.toLowerCase().includes(I.toLowerCase()))),p&&(i=i.filter(([m])=>{const{mode:b}=_(m);return b===p})),i.reduce((m,[b,M])=>(m[b]=M,m),{})},[y,I,p]),R=i=>{o(i.target.value)},E=()=>{o("")},Q=i=>{k(i.target.value)},O=()=>{k("")};return g||B?e(a,{sx:{mt:1,mb:2,display:"flex",justifyContent:"center",alignItems:"center",minHeight:200},children:e(S,{variant:"body2",color:"textSecondary",children:g?"Loading color settings...":"Rendering colors..."})}):s(a,{sx:{mt:1,mb:2},children:[e(S,{variant:"subtitle1",gutterBottom:!0,children:r.label||"Color Palette"}),Object.keys(y).length>0&&s(Ie,{children:[s(a,{sx:{mb:3,display:"flex",gap:2,alignItems:"flex-end"},children:[e(U,{fullWidth:!0,size:"small",placeholder:"Search colors by name...",value:I,onChange:R,InputProps:{startAdornment:e(F,{position:"start",children:e(fe,{})}),endAdornment:I&&e(F,{position:"end",children:e(Y,{size:"small",onClick:E,edge:"end",children:e(X,{})})})}}),s(ne,{size:"small",sx:{minWidth:150},children:[e(oe,{children:"Mode"}),s(ae,{value:p,label:"Mode",onChange:Q,startAdornment:e(F,{position:"start",children:e(ye,{fontSize:"small"})}),endAdornment:p&&e(F,{position:"end",children:e(Y,{size:"small",onClick:O,edge:"end",sx:{mr:1},children:e(X,{fontSize:"small"})})}),children:[e(V,{value:"",children:e("em",{children:"All Modes"})}),N.map(i=>e(V,{value:i,children:s(a,{sx:{display:"flex",alignItems:"center",gap:1},children:[e("span",{children:G(i)}),e("span",{children:i})]})},i))]})]})]}),(I||p)&&s(a,{sx:{mb:2,display:"flex",alignItems:"center",gap:1,flexWrap:"wrap"},children:[e(z,{label:`${Object.keys(x).length} of ${Object.keys(y).length} colors`,size:"small",variant:"outlined"}),p&&e(z,{label:`Mode: ${G(p)} ${p}`,size:"small",variant:"filled",color:"primary",onDelete:O}),I&&e(z,{label:`Search: "${I}"`,size:"small",variant:"filled",color:"secondary",onDelete:E})]}),Object.keys(x).length>0?e(a,{sx:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(240px, 1fr))",gap:0,border:"1px solid #e0e0e0"},children:Object.entries(x).map(([i,m])=>{const{baseChips:b,mode:M}=_(i),J=G(M);return s(a,{sx:{aspectRatio:"unset",height:"30px",transition:"all 0.2s ease-in-out","&:hover":{transform:"translateY(-2px)",boxShadow:3},position:"relative",overflow:"hidden",backgroundColor:m,display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"flex-start",border:"1px solid rgba(255,255,255,0.1)",padding:"0 8px",gap:.5},children:[e(a,{sx:{display:"flex",flexWrap:"wrap",gap:.25,justifyContent:"center"},children:b.map((P,H)=>e(z,{label:P,size:"small",sx:{height:16,fontSize:"0.6rem",backgroundColor:"rgba(255,255,255,0.1)",color:"#fff","& .MuiChip-label":{padding:"0 4px"}}},H))}),M&&e(z,{label:J,size:"small",sx:{height:16,fontSize:"0.6rem",backgroundColor:"rgba(0,0,0,0.7)",color:"#fff","& .MuiChip-label":{padding:"0 4px"}}}),e(S,{variant:"caption",sx:{color:re(m),backgroundColor:"rgba(0,0,0,0.1)",padding:"1px 4px",borderRadius:.5,fontSize:"0.5rem",fontFamily:"monospace",textAlign:"center",mt:"auto"},children:m})]},i)})}):s(a,{sx:{textAlign:"center",py:4},children:[e(S,{variant:"body2",color:"textSecondary",children:"No colors found matching your filters"}),s(a,{sx:{mt:1,display:"flex",justifyContent:"center",gap:1},children:[I&&e(j,{size:"small",onClick:E,children:"Clear search"}),p&&e(j,{size:"small",onClick:O,children:"Clear mode filter"})]})]})]}),Object.keys(y).length===0&&e(a,{sx:{textAlign:"center",py:4},children:e(S,{variant:"body2",color:"textSecondary",children:"No colors configured in this palette"})})]})},Ue=({method:n,attribute:r,resourceConfig:d})=>{const[h,f]=C(!0);if(W(()=>{window.dispatchEvent(new MessageEvent("auto-admin-loading-state",{data:!0}));const v=setTimeout(()=>{f(!1)},50);return()=>{clearTimeout(v),window.dispatchEvent(new MessageEvent("auto-admin-loading-state",{data:!1}))}},[]),h)return e(a,{sx:{display:"flex",justifyContent:"center",alignItems:"center",minHeight:100},children:e(S,{variant:"body2",color:"textSecondary",children:"Initializing color palette..."})});switch(n){case"edit":return e(ve,{attribute:r,method:n,resourceConfig:d});case"create":return e(ve,{attribute:r,method:n,resourceConfig:d});case"view":return e(Ye,{attribute:r,method:n,resourceConfig:d});default:return null}};var yt=Ue;export{ve as JsonEdit,Ye as JsonView,yt as default};
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __async = (__this, __arguments, generator) => {
21
+ return new Promise((resolve, reject) => {
22
+ var fulfilled = (value) => {
23
+ try {
24
+ step(generator.next(value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ };
29
+ var rejected = (value) => {
30
+ try {
31
+ step(generator.throw(value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ };
36
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
+ step((generator = generator.apply(__this, __arguments)).next());
38
+ });
39
+ };
40
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
41
+ import { useRecordContext } from "react-admin";
42
+ import { useFormContext } from "react-hook-form";
43
+ import {
44
+ Box,
45
+ Button,
46
+ IconButton,
47
+ TextField,
48
+ Typography,
49
+ Dialog,
50
+ DialogTitle,
51
+ DialogContent,
52
+ DialogActions,
53
+ Card,
54
+ Chip,
55
+ InputAdornment,
56
+ FormControl,
57
+ InputLabel,
58
+ Select,
59
+ MenuItem,
60
+ Tabs,
61
+ Tab,
62
+ Pagination,
63
+ Link
64
+ } from "@mui/material";
65
+ import DeleteIcon from "@mui/icons-material/Delete";
66
+ import AddIcon from "@mui/icons-material/Add";
67
+ import EditIcon from "@mui/icons-material/Edit";
68
+ import PreviewIcon from "@mui/icons-material/Preview";
69
+ import SearchIcon from "@mui/icons-material/Search";
70
+ import ClearIcon from "@mui/icons-material/Clear";
71
+ import FilterListIcon from "@mui/icons-material/FilterList";
72
+ import { ChromePicker } from "react-color";
73
+ import { useState, useEffect, useRef, useCallback, useMemo } from "react";
74
+ import { updateDomCssVariables } from "dash-utils";
75
+ import { AuthPersistenceService } from "dash-auth";
76
+ const getContrastColor = (color) => {
77
+ let r, g, b, a = 1;
78
+ if (color.startsWith("#")) {
79
+ const hex = color.replace("#", "");
80
+ if (hex.length === 8) {
81
+ r = parseInt(hex.substr(0, 2), 16);
82
+ g = parseInt(hex.substr(2, 2), 16);
83
+ b = parseInt(hex.substr(4, 2), 16);
84
+ a = parseInt(hex.substr(6, 2), 16) / 255;
85
+ } else {
86
+ r = parseInt(hex.substr(0, 2), 16);
87
+ g = parseInt(hex.substr(2, 2), 16);
88
+ b = parseInt(hex.substr(4, 2), 16);
89
+ }
90
+ } else if (color.startsWith("rgb")) {
91
+ const match = color.match(/rgba?\(([^)]+)\)/);
92
+ if (match) {
93
+ const values = match[1].split(",").map((v) => parseFloat(v.trim()));
94
+ [r, g, b, a = 1] = values;
95
+ } else {
96
+ return "#000000";
97
+ }
98
+ } else if (color.startsWith("hsl")) {
99
+ return "#000000";
100
+ } else {
101
+ return "#000000";
102
+ }
103
+ const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
104
+ const effectiveLuminance = luminance * a + (1 - a);
105
+ return effectiveLuminance > 0.5 ? "#000000" : "#ffffff";
106
+ };
107
+ const convertColor = (color, format) => {
108
+ switch (format) {
109
+ case "hex":
110
+ return color.hex;
111
+ case "rgb":
112
+ return `rgb(${Math.round(color.rgb.r)}, ${Math.round(color.rgb.g)}, ${Math.round(color.rgb.b)})`;
113
+ case "rgba":
114
+ return `rgba(${Math.round(color.rgb.r)}, ${Math.round(color.rgb.g)}, ${Math.round(color.rgb.b)}, ${color.rgb.a || 1})`;
115
+ case "hsl":
116
+ return `hsl(${Math.round(color.hsl.h)}, ${Math.round(color.hsl.s * 100)}%, ${Math.round(color.hsl.l * 100)}%)`;
117
+ case "hsla":
118
+ return `hsla(${Math.round(color.hsl.h)}, ${Math.round(color.hsl.s * 100)}%, ${Math.round(color.hsl.l * 100)}%, ${color.hsl.a || 1})`;
119
+ default:
120
+ return color.hex;
121
+ }
122
+ };
123
+ const parseColorKey = (key) => {
124
+ const parts = key.split("--");
125
+ const baseName = parts[0];
126
+ const mode = parts[1];
127
+ const baseChips = baseName.split("-").filter((part) => part.length > 0);
128
+ return { baseChips, mode };
129
+ };
130
+ const extractAvailableModes = (pairs) => {
131
+ const modes = /* @__PURE__ */ new Set();
132
+ pairs.forEach((pair) => {
133
+ const { mode } = parseColorKey(pair.key);
134
+ if (mode) {
135
+ modes.add(mode);
136
+ }
137
+ });
138
+ return Array.from(modes).sort();
139
+ };
140
+ const getModeIcon = (mode) => {
141
+ if (!mode) return "";
142
+ switch (mode.toLowerCase()) {
143
+ case "light":
144
+ return "\u2600\uFE0F";
145
+ // Sun icon
146
+ case "dark":
147
+ return "\u{1F319}";
148
+ // Moon icon
149
+ default:
150
+ return mode;
151
+ }
152
+ };
153
+ const ColorPaletteItem = ({ pair, onEdit, onDelete }) => {
154
+ const textColor = getContrastColor(pair.value);
155
+ const { baseChips, mode } = parseColorKey(pair.key);
156
+ const modeIcon = getModeIcon(mode);
157
+ return /* @__PURE__ */ jsxs(
158
+ Card,
159
+ {
160
+ onClick: () => onEdit(pair),
161
+ elevation: 1,
162
+ sx: {
163
+ width: "100%",
164
+ display: "flex",
165
+ alignItems: "stretch",
166
+ // Ensure stretch for full height
167
+ cursor: "pointer",
168
+ transition: "all 0.2s ease-in-out",
169
+ "&:hover": {
170
+ transform: "translateY(-2px)",
171
+ boxShadow: 3
172
+ },
173
+ borderRadius: 2,
174
+ overflow: "hidden",
175
+ position: "relative",
176
+ height: 80,
177
+ // Fixed height for consistency
178
+ backgroundColor: "background.paper"
179
+ },
180
+ children: [
181
+ /* @__PURE__ */ jsx(
182
+ Box,
183
+ {
184
+ sx: {
185
+ width: 80,
186
+ // Fixed square width
187
+ backgroundColor: pair.value,
188
+ flexShrink: 0,
189
+ display: "flex",
190
+ alignItems: "center",
191
+ justifyContent: "center",
192
+ position: "relative"
193
+ },
194
+ children: /* @__PURE__ */ jsx(
195
+ Box,
196
+ {
197
+ sx: {
198
+ position: "absolute",
199
+ top: 0,
200
+ left: 0,
201
+ right: 0,
202
+ bottom: 0,
203
+ backgroundColor: "rgba(0,0,0,0.3)",
204
+ opacity: 0,
205
+ transition: "opacity 0.2s",
206
+ "&:hover": { opacity: 1 },
207
+ display: "flex",
208
+ alignItems: "center",
209
+ justifyContent: "center"
210
+ },
211
+ children: /* @__PURE__ */ jsx(EditIcon, { sx: { color: "#fff" } })
212
+ }
213
+ )
214
+ }
215
+ ),
216
+ /* @__PURE__ */ jsxs(Box, { sx: {
217
+ flexGrow: 1,
218
+ p: 1.5,
219
+ display: "flex",
220
+ flexDirection: "column",
221
+ justifyContent: "space-between",
222
+ // Space key and chips
223
+ overflow: "hidden"
224
+ }, children: [
225
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "flex-start", justifyContent: "space-between", mb: 0.5 }, children: [
226
+ /* @__PURE__ */ jsx(Typography, { variant: "caption", sx: { fontFamily: "monospace", fontWeight: "bold", color: "text.secondary" }, children: pair.value }),
227
+ mode && /* @__PURE__ */ jsx(
228
+ Chip,
229
+ {
230
+ label: mode,
231
+ size: "small",
232
+ icon: /* @__PURE__ */ jsx("span", { style: { marginLeft: 6, fontSize: "0.8rem" }, children: modeIcon }),
233
+ sx: {
234
+ height: 18,
235
+ fontSize: "0.65rem",
236
+ "& .MuiChip-label": { padding: "0 6px" }
237
+ }
238
+ }
239
+ )
240
+ ] }),
241
+ /* @__PURE__ */ jsx(Box, { sx: { display: "flex", flexWrap: "wrap", gap: 0.5 }, children: baseChips.map((chip, index) => /* @__PURE__ */ jsx(
242
+ Chip,
243
+ {
244
+ label: chip,
245
+ size: "small",
246
+ variant: "outlined",
247
+ sx: {
248
+ height: 20,
249
+ fontSize: "0.7rem",
250
+ maxWidth: "100%",
251
+ "& .MuiChip-label": {
252
+ padding: "0 6px",
253
+ overflow: "hidden",
254
+ textOverflow: "ellipsis"
255
+ }
256
+ }
257
+ },
258
+ index
259
+ )) })
260
+ ] })
261
+ ]
262
+ }
263
+ );
264
+ };
265
+ const ColorEditDialog = ({ open, pair, onClose, onSave, onDelete, existingKeys, updateSingleDomColor }) => {
266
+ const [editedPair, setEditedPair] = useState(null);
267
+ const [colorFormat, setColorFormat] = useState("hex");
268
+ const [keyError, setKeyError] = useState("");
269
+ const [tabValue, setTabValue] = useState(0);
270
+ useEffect(() => {
271
+ if (pair) {
272
+ setEditedPair(__spreadValues({}, pair));
273
+ if (pair.value.startsWith("rgba(")) {
274
+ setColorFormat("rgba");
275
+ } else if (pair.value.startsWith("rgb(")) {
276
+ setColorFormat("rgb");
277
+ } else if (pair.value.startsWith("hsla(")) {
278
+ setColorFormat("hsla");
279
+ } else if (pair.value.startsWith("hsl(")) {
280
+ setColorFormat("hsl");
281
+ } else {
282
+ setColorFormat("hex");
283
+ }
284
+ }
285
+ setKeyError("");
286
+ }, [pair]);
287
+ const handleKeyChange = (newKey) => {
288
+ if (!editedPair) return;
289
+ const isDuplicate = existingKeys.some((key) => key === newKey && newKey !== (pair == null ? void 0 : pair.key));
290
+ setKeyError(isDuplicate ? "Key already exists" : "");
291
+ setEditedPair(__spreadProps(__spreadValues({}, editedPair), { key: newKey }));
292
+ };
293
+ const handleColorChange = (color) => {
294
+ if (!editedPair) return;
295
+ const newValue = convertColor(color, colorFormat);
296
+ setEditedPair(__spreadProps(__spreadValues({}, editedPair), { value: newValue }));
297
+ updateSingleDomColor(editedPair.key, newValue);
298
+ };
299
+ const handleSave = () => {
300
+ if (!editedPair || keyError || !editedPair.key.trim()) return;
301
+ onSave(editedPair);
302
+ onClose();
303
+ };
304
+ const handleDelete = () => {
305
+ if (!editedPair) return;
306
+ onDelete(editedPair.id);
307
+ onClose();
308
+ };
309
+ if (!editedPair) return null;
310
+ return /* @__PURE__ */ jsxs(
311
+ Dialog,
312
+ {
313
+ open,
314
+ onClose,
315
+ maxWidth: "sm",
316
+ fullWidth: true,
317
+ PaperProps: {
318
+ sx: { minHeight: 600 }
319
+ },
320
+ children: [
321
+ /* @__PURE__ */ jsx(DialogTitle, { children: (pair == null ? void 0 : pair.key) ? `Edit Color: ${pair.key}` : "Add New Color" }),
322
+ /* @__PURE__ */ jsx(DialogContent, { children: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "column", gap: 3, pt: 1 }, children: [
323
+ /* @__PURE__ */ jsx(
324
+ TextField,
325
+ {
326
+ fullWidth: true,
327
+ label: "Color Name",
328
+ value: editedPair.key,
329
+ onChange: (e) => handleKeyChange(e.target.value),
330
+ error: !!keyError,
331
+ helperText: keyError,
332
+ placeholder: "e.g., primary-color--light, background-dark--dark"
333
+ }
334
+ ),
335
+ /* @__PURE__ */ jsxs(FormControl, { fullWidth: true, children: [
336
+ /* @__PURE__ */ jsx(InputLabel, { children: "Color Format" }),
337
+ /* @__PURE__ */ jsxs(
338
+ Select,
339
+ {
340
+ value: colorFormat,
341
+ label: "Color Format",
342
+ onChange: (e) => setColorFormat(e.target.value),
343
+ children: [
344
+ /* @__PURE__ */ jsx(MenuItem, { value: "hex", children: "HEX" }),
345
+ /* @__PURE__ */ jsx(MenuItem, { value: "rgb", children: "RGB" }),
346
+ /* @__PURE__ */ jsx(MenuItem, { value: "rgba", children: "RGBA (with alpha)" }),
347
+ /* @__PURE__ */ jsx(MenuItem, { value: "hsl", children: "HSL" }),
348
+ /* @__PURE__ */ jsx(MenuItem, { value: "hsla", children: "HSLA (with alpha)" })
349
+ ]
350
+ }
351
+ )
352
+ ] }),
353
+ /* @__PURE__ */ jsxs(Box, { children: [
354
+ /* @__PURE__ */ jsxs(Tabs, { value: tabValue, onChange: (_, newValue) => setTabValue(newValue), children: [
355
+ /* @__PURE__ */ jsx(Tab, { label: "Color Picker" }),
356
+ /* @__PURE__ */ jsx(Tab, { label: "Manual Input" })
357
+ ] }),
358
+ tabValue === 0 && /* @__PURE__ */ jsx(Box, { sx: { mt: 2, display: "flex", justifyContent: "center" }, children: /* @__PURE__ */ jsx(
359
+ ChromePicker,
360
+ {
361
+ color: editedPair.value,
362
+ onChange: handleColorChange,
363
+ disableAlpha: !["rgba", "hsla"].includes(colorFormat)
364
+ }
365
+ ) }),
366
+ tabValue === 1 && /* @__PURE__ */ jsx(Box, { sx: { mt: 2 }, children: /* @__PURE__ */ jsx(
367
+ TextField,
368
+ {
369
+ fullWidth: true,
370
+ label: `Color Value (${colorFormat.toUpperCase()})`,
371
+ value: editedPair.value,
372
+ onChange: (e) => setEditedPair(__spreadProps(__spreadValues({}, editedPair), { value: e.target.value })),
373
+ placeholder: colorFormat === "hex" ? "#ff0000" : colorFormat === "rgb" ? "rgb(255, 0, 0)" : colorFormat === "rgba" ? "rgba(255, 0, 0, 1)" : colorFormat === "hsl" ? "hsl(0, 100%, 50%)" : "hsla(0, 100%, 50%, 1)",
374
+ InputProps: {
375
+ startAdornment: /* @__PURE__ */ jsx(InputAdornment, { position: "start", children: /* @__PURE__ */ jsx(
376
+ Box,
377
+ {
378
+ sx: {
379
+ width: 20,
380
+ height: 20,
381
+ backgroundColor: editedPair.value,
382
+ border: "1px solid #ccc",
383
+ borderRadius: 1
384
+ }
385
+ }
386
+ ) })
387
+ }
388
+ }
389
+ ) })
390
+ ] }),
391
+ /* @__PURE__ */ jsxs(Box, { children: [
392
+ /* @__PURE__ */ jsx(Typography, { variant: "subtitle2", gutterBottom: true, children: "Preview" }),
393
+ /* @__PURE__ */ jsx(
394
+ Box,
395
+ {
396
+ sx: {
397
+ width: "100%",
398
+ height: 80,
399
+ backgroundColor: editedPair.value,
400
+ border: "1px solid #ccc",
401
+ borderRadius: 1,
402
+ display: "flex",
403
+ alignItems: "center",
404
+ justifyContent: "center",
405
+ position: "relative"
406
+ },
407
+ children: /* @__PURE__ */ jsx(
408
+ Typography,
409
+ {
410
+ variant: "body2",
411
+ sx: {
412
+ color: getContrastColor(editedPair.value),
413
+ fontWeight: "bold",
414
+ backgroundColor: "rgba(0,0,0,0.1)",
415
+ padding: "4px 8px",
416
+ borderRadius: 1
417
+ },
418
+ children: editedPair.key || "Color Preview"
419
+ }
420
+ )
421
+ }
422
+ )
423
+ ] })
424
+ ] }) }),
425
+ /* @__PURE__ */ jsxs(DialogActions, { children: [
426
+ (pair == null ? void 0 : pair.key) && /* @__PURE__ */ jsx(
427
+ Button,
428
+ {
429
+ onClick: handleDelete,
430
+ color: "error",
431
+ startIcon: /* @__PURE__ */ jsx(DeleteIcon, {}),
432
+ children: "Delete"
433
+ }
434
+ ),
435
+ /* @__PURE__ */ jsx(Box, { sx: { flexGrow: 1 } }),
436
+ /* @__PURE__ */ jsx(Button, { onClick: onClose, children: "Cancel" }),
437
+ /* @__PURE__ */ jsx(
438
+ Button,
439
+ {
440
+ onClick: handleSave,
441
+ variant: "contained",
442
+ disabled: !!keyError || !editedPair.key.trim(),
443
+ children: "Save"
444
+ }
445
+ )
446
+ ] })
447
+ ]
448
+ }
449
+ );
450
+ };
451
+ const JsonEdit = (props) => {
452
+ const { method, attribute, resourceConfig } = props;
453
+ const record = useRecordContext();
454
+ const { setValue, getValues } = useFormContext();
455
+ const attributePath = attribute.attribute;
456
+ const isNestedSetting = attributePath.startsWith("settings.");
457
+ const settingsPath = isNestedSetting ? attributePath.split(".").slice(1).join(".") : attributePath;
458
+ const [pairs, setPairs] = useState([]);
459
+ const [searchTerm, setSearchTerm] = useState("");
460
+ const [selectedMode, setSelectedMode] = useState("");
461
+ const [isLoading, setIsLoading] = useState(true);
462
+ const [isRendering, setIsRendering] = useState(true);
463
+ const [editDialogOpen, setEditDialogOpen] = useState(false);
464
+ const [editingPair, setEditingPair] = useState(null);
465
+ const [page, setPage] = useState(1);
466
+ const [pageSize] = useState(24);
467
+ const throttleTimeoutRef = useRef(null);
468
+ const pendingUpdatesRef = useRef(/* @__PURE__ */ new Map());
469
+ const dispatchLoadingEvent = useCallback((loading) => {
470
+ window.dispatchEvent(new MessageEvent("auto-admin-loading-state", { data: loading }));
471
+ }, []);
472
+ const availableModes = useMemo(() => {
473
+ return extractAvailableModes(pairs);
474
+ }, [pairs]);
475
+ const filteredPairs = useMemo(() => {
476
+ let filtered = pairs;
477
+ if (searchTerm.trim()) {
478
+ filtered = filtered.filter(
479
+ (pair) => pair.key.toLowerCase().includes(searchTerm.toLowerCase())
480
+ );
481
+ }
482
+ if (selectedMode) {
483
+ filtered = filtered.filter((pair) => {
484
+ const { mode } = parseColorKey(pair.key);
485
+ return mode === selectedMode;
486
+ });
487
+ }
488
+ return filtered;
489
+ }, [pairs, searchTerm, selectedMode]);
490
+ const handleSearchChange = (event) => {
491
+ setSearchTerm(event.target.value);
492
+ };
493
+ const handleClearSearch = () => {
494
+ setSearchTerm("");
495
+ };
496
+ const handleModeChange = (event) => {
497
+ setSelectedMode(event.target.value);
498
+ };
499
+ const handleClearMode = () => {
500
+ setSelectedMode("");
501
+ };
502
+ useEffect(() => {
503
+ const loadInitialData = () => __async(null, null, function* () {
504
+ setIsLoading(true);
505
+ dispatchLoadingEvent(true);
506
+ try {
507
+ let initialValue = {};
508
+ let defaultValues = {};
509
+ try {
510
+ defaultValues = (attribute == null ? void 0 : attribute.default_value) || {};
511
+ } catch (e) {
512
+ defaultValues = {};
513
+ }
514
+ if (isNestedSetting && (record == null ? void 0 : record.settings)) {
515
+ const settings = record.settings || {};
516
+ initialValue = __spreadValues(__spreadValues({}, defaultValues), getNestedValue(settings, settingsPath));
517
+ } else if (record == null ? void 0 : record[attributePath]) {
518
+ initialValue = __spreadValues(__spreadValues({}, defaultValues), record[attributePath]);
519
+ } else {
520
+ initialValue = defaultValues;
521
+ }
522
+ const initialPairs = Object.entries(initialValue).map(([key, value]) => ({
523
+ key,
524
+ value: String(value),
525
+ id: generateId()
526
+ }));
527
+ setPairs(initialPairs);
528
+ if (initialPairs.length > 50) {
529
+ yield new Promise((resolve) => setTimeout(resolve, 100));
530
+ }
531
+ } catch (error) {
532
+ console.error("Error loading initial data:", error);
533
+ } finally {
534
+ setIsLoading(false);
535
+ }
536
+ });
537
+ loadInitialData();
538
+ }, [record, attributePath]);
539
+ useEffect(() => {
540
+ if (!isLoading && pairs.length >= 0) {
541
+ setIsRendering(true);
542
+ requestAnimationFrame(() => {
543
+ requestAnimationFrame(() => {
544
+ setIsRendering(false);
545
+ dispatchLoadingEvent(false);
546
+ });
547
+ });
548
+ }
549
+ }, [isLoading, pairs.length, dispatchLoadingEvent]);
550
+ useEffect(() => {
551
+ return () => {
552
+ if (throttleTimeoutRef.current) {
553
+ clearTimeout(throttleTimeoutRef.current);
554
+ }
555
+ dispatchLoadingEvent(false);
556
+ };
557
+ }, [dispatchLoadingEvent]);
558
+ const getNestedValue = (obj, path) => {
559
+ if (!path) return obj;
560
+ const keys = path.split(".");
561
+ return keys.reduce((o, key) => o && o[key] !== void 0 ? o[key] : {}, obj);
562
+ };
563
+ const setNestedValue = (obj, path, value) => {
564
+ if (!path) return value;
565
+ const keys = path.split(".");
566
+ const lastKey = keys.pop();
567
+ const lastObj = keys.reduce((o, key) => {
568
+ if (o[key] === void 0) o[key] = {};
569
+ return o[key];
570
+ }, obj);
571
+ if (lastKey) {
572
+ lastObj[lastKey] = value;
573
+ }
574
+ return obj;
575
+ };
576
+ const generateId = () => {
577
+ return Math.random().toString(36).substring(2, 11);
578
+ };
579
+ const addPair = () => {
580
+ const newPair = { key: "", value: "#000000", id: generateId() };
581
+ setEditingPair(newPair);
582
+ setEditDialogOpen(true);
583
+ };
584
+ const handleEditPair = (pair) => {
585
+ setEditingPair(pair);
586
+ setEditDialogOpen(true);
587
+ };
588
+ const handleSavePair = (editedPair) => {
589
+ const existingIndex = pairs.findIndex((p) => p.id === editedPair.id);
590
+ let updatedPairs;
591
+ if (existingIndex >= 0) {
592
+ updatedPairs = pairs.map((p) => p.id === editedPair.id ? editedPair : p);
593
+ } else {
594
+ updatedPairs = [...pairs, editedPair];
595
+ }
596
+ setPairs(updatedPairs);
597
+ updateFormValue(updatedPairs);
598
+ updateSingleDomColor(editedPair.key, editedPair.value);
599
+ };
600
+ const handleDeletePair = (id) => {
601
+ const updatedPairs = pairs.filter((pair) => pair.id !== id);
602
+ setPairs(updatedPairs);
603
+ updateFormValue(updatedPairs);
604
+ };
605
+ const updateSingleDomColor = (key, color) => {
606
+ if (!key.trim()) return;
607
+ const currentTheme = document.documentElement.getAttribute("data-theme");
608
+ const themeSuffix = `--${currentTheme}`;
609
+ if (key.endsWith(themeSuffix)) {
610
+ const baseKey = key.slice(0, -themeSuffix.length);
611
+ document.documentElement.style.setProperty(`--${baseKey}`, color);
612
+ }
613
+ };
614
+ const getTenantSettingsValues = () => {
615
+ const persistedTenantSettings = AuthPersistenceService.getTenantSettings();
616
+ if (persistedTenantSettings) {
617
+ return (persistedTenantSettings == null ? void 0 : persistedTenantSettings.values) || {};
618
+ }
619
+ return {};
620
+ };
621
+ const handlePreview = (m) => {
622
+ const colorsObj = pairs.reduce((acc, pair) => {
623
+ if (pair.key.trim()) {
624
+ acc[pair.key] = pair.value;
625
+ }
626
+ return acc;
627
+ }, {});
628
+ updateDomCssVariables(m, colorsObj, getTenantSettingsValues());
629
+ };
630
+ const updateFormValue = (currentPairs) => {
631
+ const obj = currentPairs.reduce((acc, pair) => {
632
+ if (pair.key.trim()) {
633
+ acc[pair.key] = pair.value;
634
+ }
635
+ return acc;
636
+ }, {});
637
+ if (isNestedSetting) {
638
+ const currentSettings = getValues("settings") || {};
639
+ const updatedSettings = setNestedValue(__spreadValues({}, currentSettings), settingsPath, obj);
640
+ setValue("settings", updatedSettings, { shouldDirty: true });
641
+ } else {
642
+ setValue(attributePath, obj, { shouldDirty: true });
643
+ }
644
+ };
645
+ if (isLoading || isRendering) {
646
+ return /* @__PURE__ */ jsx(Box, { sx: { mt: 1, mb: 2, display: "flex", justifyContent: "center", alignItems: "center", minHeight: 200 }, children: /* @__PURE__ */ jsx(Typography, { variant: "body2", color: "textSecondary", children: isLoading ? "Loading color settings..." : "Rendering colors..." }) });
647
+ }
648
+ return /* @__PURE__ */ jsxs(Box, { sx: { mt: 1, mb: 2 }, children: [
649
+ /* @__PURE__ */ jsx(Typography, { variant: "subtitle1", gutterBottom: true, children: attribute.label || "Color Palette" }),
650
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", justifyContent: "space-between", mb: 3 }, children: [
651
+ /* @__PURE__ */ jsx(
652
+ Button,
653
+ {
654
+ startIcon: /* @__PURE__ */ jsx(PreviewIcon, {}),
655
+ variant: "contained",
656
+ size: "small",
657
+ onClick: () => handlePreview(document.documentElement.getAttribute("data-theme")),
658
+ color: "primary",
659
+ children: "Preview Colors TEST"
660
+ }
661
+ ),
662
+ /* @__PURE__ */ jsx(
663
+ Button,
664
+ {
665
+ startIcon: /* @__PURE__ */ jsx(AddIcon, {}),
666
+ variant: "outlined",
667
+ size: "small",
668
+ onClick: addPair,
669
+ children: "Add Color"
670
+ }
671
+ )
672
+ ] }),
673
+ /* @__PURE__ */ jsxs(Box, { sx: { mb: 3, display: "flex", gap: 2, alignItems: "flex-end" }, children: [
674
+ /* @__PURE__ */ jsx(
675
+ TextField,
676
+ {
677
+ fullWidth: true,
678
+ size: "small",
679
+ placeholder: "Search colors by name...",
680
+ value: searchTerm,
681
+ onChange: handleSearchChange,
682
+ InputProps: {
683
+ startAdornment: /* @__PURE__ */ jsx(InputAdornment, { position: "start", children: /* @__PURE__ */ jsx(SearchIcon, {}) }),
684
+ endAdornment: searchTerm && /* @__PURE__ */ jsx(InputAdornment, { position: "end", children: /* @__PURE__ */ jsx(
685
+ IconButton,
686
+ {
687
+ size: "small",
688
+ onClick: handleClearSearch,
689
+ edge: "end",
690
+ children: /* @__PURE__ */ jsx(ClearIcon, {})
691
+ }
692
+ ) })
693
+ }
694
+ }
695
+ ),
696
+ /* @__PURE__ */ jsxs(FormControl, { size: "small", sx: { minWidth: 150 }, children: [
697
+ /* @__PURE__ */ jsx(InputLabel, { children: "Mode" }),
698
+ /* @__PURE__ */ jsxs(
699
+ Select,
700
+ {
701
+ value: selectedMode,
702
+ label: "Mode",
703
+ onChange: handleModeChange,
704
+ startAdornment: /* @__PURE__ */ jsx(InputAdornment, { position: "start", children: /* @__PURE__ */ jsx(FilterListIcon, { fontSize: "small" }) }),
705
+ endAdornment: selectedMode && /* @__PURE__ */ jsx(InputAdornment, { position: "end", children: /* @__PURE__ */ jsx(
706
+ IconButton,
707
+ {
708
+ size: "small",
709
+ onClick: handleClearMode,
710
+ edge: "end",
711
+ sx: { mr: 1 },
712
+ children: /* @__PURE__ */ jsx(ClearIcon, { fontSize: "small" })
713
+ }
714
+ ) }),
715
+ children: [
716
+ /* @__PURE__ */ jsx(MenuItem, { value: "", children: /* @__PURE__ */ jsx("em", { children: "All Modes" }) }),
717
+ availableModes.map((mode) => /* @__PURE__ */ jsx(MenuItem, { value: mode, children: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
718
+ /* @__PURE__ */ jsx("span", { children: getModeIcon(mode) }),
719
+ /* @__PURE__ */ jsx("span", { children: mode })
720
+ ] }) }, mode))
721
+ ]
722
+ }
723
+ )
724
+ ] })
725
+ ] }),
726
+ (searchTerm || selectedMode) && /* @__PURE__ */ jsxs(Box, { sx: { mb: 2, display: "flex", alignItems: "center", gap: 1, flexWrap: "wrap" }, children: [
727
+ /* @__PURE__ */ jsx(
728
+ Chip,
729
+ {
730
+ label: `${filteredPairs.length} of ${pairs.length} colors`,
731
+ size: "small",
732
+ variant: "outlined"
733
+ }
734
+ ),
735
+ selectedMode && /* @__PURE__ */ jsx(
736
+ Chip,
737
+ {
738
+ label: `Mode: ${selectedMode}`,
739
+ size: "small",
740
+ variant: "filled",
741
+ color: "primary",
742
+ onDelete: handleClearMode,
743
+ avatar: /* @__PURE__ */ jsx("span", { style: { paddingLeft: 6 }, children: getModeIcon(selectedMode) })
744
+ }
745
+ ),
746
+ searchTerm && /* @__PURE__ */ jsx(
747
+ Chip,
748
+ {
749
+ label: `Search: "${searchTerm}"`,
750
+ size: "small",
751
+ variant: "filled",
752
+ color: "secondary",
753
+ onDelete: handleClearSearch
754
+ }
755
+ )
756
+ ] }),
757
+ isRendering ? /* @__PURE__ */ jsx(Box, { sx: { display: "flex", justifyContent: "center", p: 4, alignItems: "center", flexDirection: "column", gap: 2 }, children: /* @__PURE__ */ jsx(Typography, { children: "Rendering Grid..." }) }) : filteredPairs.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
758
+ /* @__PURE__ */ jsx(Box, { sx: {
759
+ display: "grid",
760
+ gridTemplateColumns: "repeat(auto-fill, minmax(300px, 1fr))",
761
+ gap: 2,
762
+ width: "100%"
763
+ }, children: filteredPairs.slice((page - 1) * pageSize, page * pageSize).map((pair) => /* @__PURE__ */ jsx(Box, { sx: { minWidth: 0 }, children: /* @__PURE__ */ jsx(
764
+ ColorPaletteItem,
765
+ {
766
+ pair,
767
+ onEdit: handleEditPair,
768
+ onDelete: handleDeletePair
769
+ }
770
+ ) }, pair.id)) }),
771
+ filteredPairs.length > pageSize && /* @__PURE__ */ jsx(Box, { sx: { mt: 4, display: "flex", justifyContent: "center" }, children: /* @__PURE__ */ jsx(
772
+ Pagination,
773
+ {
774
+ count: Math.ceil(filteredPairs.length / pageSize),
775
+ page,
776
+ onChange: (_, value) => setPage(value),
777
+ color: "primary",
778
+ size: "large",
779
+ showFirstButton: true,
780
+ showLastButton: true
781
+ }
782
+ ) }),
783
+ /* @__PURE__ */ jsxs(Typography, { variant: "caption", sx: { display: "block", textAlign: "center", mt: 2, color: "text.secondary" }, children: [
784
+ "Showing ",
785
+ Math.min((page - 1) * pageSize + 1, filteredPairs.length),
786
+ " - ",
787
+ Math.min(page * pageSize, filteredPairs.length),
788
+ " of ",
789
+ filteredPairs.length,
790
+ " colors"
791
+ ] })
792
+ ] }) : /* @__PURE__ */ jsxs(Box, { sx: {
793
+ p: 4,
794
+ textAlign: "center",
795
+ bgcolor: "background.paper",
796
+ borderRadius: 1,
797
+ border: "1px dashed #ccc"
798
+ }, children: [
799
+ /* @__PURE__ */ jsx(Typography, { color: "textSecondary", children: "No colors found using current filters." }),
800
+ /* @__PURE__ */ jsx(Box, { sx: { mt: 1 }, children: /* @__PURE__ */ jsx(
801
+ Link,
802
+ {
803
+ component: "button",
804
+ variant: "body2",
805
+ onClick: () => {
806
+ setSearchTerm("");
807
+ setSelectedMode("");
808
+ setPage(1);
809
+ },
810
+ children: "Clear filters"
811
+ }
812
+ ) })
813
+ ] }),
814
+ pairs.length === 0 && /* @__PURE__ */ jsxs(Box, { sx: { textAlign: "center", py: 4 }, children: [
815
+ /* @__PURE__ */ jsx(Typography, { variant: "body2", color: "textSecondary", gutterBottom: true, children: "No colors in your palette yet" }),
816
+ /* @__PURE__ */ jsx(
817
+ Button,
818
+ {
819
+ startIcon: /* @__PURE__ */ jsx(AddIcon, {}),
820
+ variant: "contained",
821
+ onClick: addPair,
822
+ children: "Add Your First Color"
823
+ }
824
+ )
825
+ ] }),
826
+ /* @__PURE__ */ jsx(
827
+ ColorEditDialog,
828
+ {
829
+ open: editDialogOpen,
830
+ pair: editingPair,
831
+ onClose: () => {
832
+ setEditDialogOpen(false);
833
+ setEditingPair(null);
834
+ },
835
+ onSave: handleSavePair,
836
+ onDelete: handleDeletePair,
837
+ existingKeys: pairs.map((p) => p.key),
838
+ updateSingleDomColor
839
+ }
840
+ )
841
+ ] });
842
+ };
843
+ const JsonView = (props) => {
844
+ const { attribute } = props;
845
+ const record = useRecordContext();
846
+ const attributePath = attribute.attribute;
847
+ const isNestedSetting = attributePath.startsWith("settings.");
848
+ const settingsPath = isNestedSetting ? attributePath.split(".").slice(1).join(".") : attributePath;
849
+ const [searchTerm, setSearchTerm] = useState("");
850
+ const [selectedMode, setSelectedMode] = useState("");
851
+ const [isLoading, setIsLoading] = useState(true);
852
+ const [isRendering, setIsRendering] = useState(true);
853
+ const [displayValue, setDisplayValue] = useState({});
854
+ const dispatchLoadingEvent = useCallback((loading) => {
855
+ window.dispatchEvent(new MessageEvent("auto-admin-loading-state", { data: loading }));
856
+ }, []);
857
+ const displayPairs = useMemo(() => {
858
+ return Object.entries(displayValue).map(([key, value]) => ({
859
+ key,
860
+ value: String(value),
861
+ id: key
862
+ }));
863
+ }, [displayValue]);
864
+ const availableModes = useMemo(() => {
865
+ return extractAvailableModes(displayPairs);
866
+ }, [displayPairs]);
867
+ useEffect(() => {
868
+ const loadViewData = () => __async(null, null, function* () {
869
+ setIsLoading(true);
870
+ dispatchLoadingEvent(true);
871
+ try {
872
+ let viewValue = {};
873
+ let defaultValues = {};
874
+ try {
875
+ defaultValues = (attribute == null ? void 0 : attribute.default_value) || {};
876
+ } catch (e) {
877
+ defaultValues = {};
878
+ }
879
+ if (isNestedSetting && (record == null ? void 0 : record.settings)) {
880
+ const settings = record.settings || {};
881
+ if (settingsPath) {
882
+ const keys = settingsPath.split(".");
883
+ viewValue = __spreadValues(__spreadValues({}, defaultValues), keys.reduce((o, key) => o && o[key] !== void 0 ? o[key] : {}, settings));
884
+ } else {
885
+ viewValue = __spreadValues(__spreadValues({}, defaultValues), settings);
886
+ }
887
+ } else if (record == null ? void 0 : record[attributePath]) {
888
+ viewValue = __spreadValues(__spreadValues({}, defaultValues), record[attributePath]);
889
+ } else {
890
+ viewValue = defaultValues;
891
+ }
892
+ setDisplayValue(viewValue);
893
+ if (Object.keys(viewValue).length > 50) {
894
+ yield new Promise((resolve) => setTimeout(resolve, 100));
895
+ }
896
+ } catch (error) {
897
+ console.error("Error loading view data:", error);
898
+ } finally {
899
+ setIsLoading(false);
900
+ }
901
+ });
902
+ loadViewData();
903
+ }, [record, attributePath, attribute, isNestedSetting, settingsPath]);
904
+ useEffect(() => {
905
+ if (!isLoading && Object.keys(displayValue).length >= 0) {
906
+ setIsRendering(true);
907
+ requestAnimationFrame(() => {
908
+ requestAnimationFrame(() => {
909
+ setIsRendering(false);
910
+ dispatchLoadingEvent(false);
911
+ });
912
+ });
913
+ }
914
+ }, [isLoading, displayValue, dispatchLoadingEvent]);
915
+ useEffect(() => {
916
+ return () => {
917
+ dispatchLoadingEvent(false);
918
+ };
919
+ }, [dispatchLoadingEvent]);
920
+ const filteredDisplayValue = useMemo(() => {
921
+ let filtered = Object.entries(displayValue);
922
+ if (searchTerm.trim()) {
923
+ filtered = filtered.filter(
924
+ ([key]) => key.toLowerCase().includes(searchTerm.toLowerCase())
925
+ );
926
+ }
927
+ if (selectedMode) {
928
+ filtered = filtered.filter(([key]) => {
929
+ const { mode } = parseColorKey(key);
930
+ return mode === selectedMode;
931
+ });
932
+ }
933
+ return filtered.reduce((acc, [key, value]) => {
934
+ acc[key] = value;
935
+ return acc;
936
+ }, {});
937
+ }, [displayValue, searchTerm, selectedMode]);
938
+ const handleSearchChange = (event) => {
939
+ setSearchTerm(event.target.value);
940
+ };
941
+ const handleClearSearch = () => {
942
+ setSearchTerm("");
943
+ };
944
+ const handleModeChange = (event) => {
945
+ setSelectedMode(event.target.value);
946
+ };
947
+ const handleClearMode = () => {
948
+ setSelectedMode("");
949
+ };
950
+ if (isLoading || isRendering) {
951
+ return /* @__PURE__ */ jsx(Box, { sx: { mt: 1, mb: 2, display: "flex", justifyContent: "center", alignItems: "center", minHeight: 200 }, children: /* @__PURE__ */ jsx(Typography, { variant: "body2", color: "textSecondary", children: isLoading ? "Loading color settings..." : "Rendering colors..." }) });
952
+ }
953
+ return /* @__PURE__ */ jsxs(Box, { sx: { mt: 1, mb: 2 }, children: [
954
+ /* @__PURE__ */ jsx(Typography, { variant: "subtitle1", gutterBottom: true, children: attribute.label || "Color Palette" }),
955
+ Object.keys(displayValue).length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
956
+ /* @__PURE__ */ jsxs(Box, { sx: { mb: 3, display: "flex", gap: 2, alignItems: "flex-end" }, children: [
957
+ /* @__PURE__ */ jsx(
958
+ TextField,
959
+ {
960
+ fullWidth: true,
961
+ size: "small",
962
+ placeholder: "Search colors by name...",
963
+ value: searchTerm,
964
+ onChange: handleSearchChange,
965
+ InputProps: {
966
+ startAdornment: /* @__PURE__ */ jsx(InputAdornment, { position: "start", children: /* @__PURE__ */ jsx(SearchIcon, {}) }),
967
+ endAdornment: searchTerm && /* @__PURE__ */ jsx(InputAdornment, { position: "end", children: /* @__PURE__ */ jsx(
968
+ IconButton,
969
+ {
970
+ size: "small",
971
+ onClick: handleClearSearch,
972
+ edge: "end",
973
+ children: /* @__PURE__ */ jsx(ClearIcon, {})
974
+ }
975
+ ) })
976
+ }
977
+ }
978
+ ),
979
+ /* @__PURE__ */ jsxs(FormControl, { size: "small", sx: { minWidth: 150 }, children: [
980
+ /* @__PURE__ */ jsx(InputLabel, { children: "Mode" }),
981
+ /* @__PURE__ */ jsxs(
982
+ Select,
983
+ {
984
+ value: selectedMode,
985
+ label: "Mode",
986
+ onChange: handleModeChange,
987
+ startAdornment: /* @__PURE__ */ jsx(InputAdornment, { position: "start", children: /* @__PURE__ */ jsx(FilterListIcon, { fontSize: "small" }) }),
988
+ endAdornment: selectedMode && /* @__PURE__ */ jsx(InputAdornment, { position: "end", children: /* @__PURE__ */ jsx(
989
+ IconButton,
990
+ {
991
+ size: "small",
992
+ onClick: handleClearMode,
993
+ edge: "end",
994
+ sx: { mr: 1 },
995
+ children: /* @__PURE__ */ jsx(ClearIcon, { fontSize: "small" })
996
+ }
997
+ ) }),
998
+ children: [
999
+ /* @__PURE__ */ jsx(MenuItem, { value: "", children: /* @__PURE__ */ jsx("em", { children: "All Modes" }) }),
1000
+ availableModes.map((mode) => /* @__PURE__ */ jsx(MenuItem, { value: mode, children: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
1001
+ /* @__PURE__ */ jsx("span", { children: getModeIcon(mode) }),
1002
+ /* @__PURE__ */ jsx("span", { children: mode })
1003
+ ] }) }, mode))
1004
+ ]
1005
+ }
1006
+ )
1007
+ ] })
1008
+ ] }),
1009
+ (searchTerm || selectedMode) && /* @__PURE__ */ jsxs(Box, { sx: { mb: 2, display: "flex", alignItems: "center", gap: 1, flexWrap: "wrap" }, children: [
1010
+ /* @__PURE__ */ jsx(
1011
+ Chip,
1012
+ {
1013
+ label: `${Object.keys(filteredDisplayValue).length} of ${Object.keys(displayValue).length} colors`,
1014
+ size: "small",
1015
+ variant: "outlined"
1016
+ }
1017
+ ),
1018
+ selectedMode && /* @__PURE__ */ jsx(
1019
+ Chip,
1020
+ {
1021
+ label: `Mode: ${getModeIcon(selectedMode)} ${selectedMode}`,
1022
+ size: "small",
1023
+ variant: "filled",
1024
+ color: "primary",
1025
+ onDelete: handleClearMode
1026
+ }
1027
+ ),
1028
+ searchTerm && /* @__PURE__ */ jsx(
1029
+ Chip,
1030
+ {
1031
+ label: `Search: "${searchTerm}"`,
1032
+ size: "small",
1033
+ variant: "filled",
1034
+ color: "secondary",
1035
+ onDelete: handleClearSearch
1036
+ }
1037
+ )
1038
+ ] }),
1039
+ Object.keys(filteredDisplayValue).length > 0 ? /* @__PURE__ */ jsx(Box, { sx: {
1040
+ display: "grid",
1041
+ gridTemplateColumns: "repeat(auto-fill, minmax(240px, 1fr))",
1042
+ // Double the width
1043
+ gap: 0,
1044
+ border: "1px solid #e0e0e0"
1045
+ }, children: Object.entries(filteredDisplayValue).map(([key, value]) => {
1046
+ const { baseChips, mode } = parseColorKey(key);
1047
+ const modeIcon = getModeIcon(mode);
1048
+ return /* @__PURE__ */ jsxs(
1049
+ Box,
1050
+ {
1051
+ sx: {
1052
+ aspectRatio: "unset",
1053
+ // Remove aspect ratio
1054
+ height: "30px",
1055
+ // Set fixed height
1056
+ transition: "all 0.2s ease-in-out",
1057
+ "&:hover": {
1058
+ transform: "translateY(-2px)",
1059
+ boxShadow: 3
1060
+ },
1061
+ position: "relative",
1062
+ overflow: "hidden",
1063
+ backgroundColor: value,
1064
+ display: "flex",
1065
+ flexDirection: "row",
1066
+ // Change to row
1067
+ alignItems: "center",
1068
+ justifyContent: "flex-start",
1069
+ // Align to start
1070
+ border: "1px solid rgba(255,255,255,0.1)",
1071
+ padding: "0 8px",
1072
+ // Horizontal padding only
1073
+ gap: 0.5
1074
+ },
1075
+ children: [
1076
+ /* @__PURE__ */ jsx(Box, { sx: { display: "flex", flexWrap: "wrap", gap: 0.25, justifyContent: "center" }, children: baseChips.map((chip, index) => /* @__PURE__ */ jsx(
1077
+ Chip,
1078
+ {
1079
+ label: chip,
1080
+ size: "small",
1081
+ sx: {
1082
+ height: 16,
1083
+ fontSize: "0.6rem",
1084
+ backgroundColor: "rgba(255,255,255,0.1)",
1085
+ color: "#fff",
1086
+ "& .MuiChip-label": {
1087
+ padding: "0 4px"
1088
+ }
1089
+ }
1090
+ },
1091
+ index
1092
+ )) }),
1093
+ mode && /* @__PURE__ */ jsx(
1094
+ Chip,
1095
+ {
1096
+ label: modeIcon,
1097
+ size: "small",
1098
+ sx: {
1099
+ height: 16,
1100
+ fontSize: "0.6rem",
1101
+ backgroundColor: "rgba(0,0,0,0.7)",
1102
+ color: "#fff",
1103
+ "& .MuiChip-label": {
1104
+ padding: "0 4px"
1105
+ }
1106
+ }
1107
+ }
1108
+ ),
1109
+ /* @__PURE__ */ jsx(
1110
+ Typography,
1111
+ {
1112
+ variant: "caption",
1113
+ sx: {
1114
+ color: getContrastColor(value),
1115
+ backgroundColor: "rgba(0,0,0,0.1)",
1116
+ padding: "1px 4px",
1117
+ borderRadius: 0.5,
1118
+ fontSize: "0.5rem",
1119
+ fontFamily: "monospace",
1120
+ textAlign: "center",
1121
+ mt: "auto"
1122
+ },
1123
+ children: value
1124
+ }
1125
+ )
1126
+ ]
1127
+ },
1128
+ key
1129
+ );
1130
+ }) }) : /* @__PURE__ */ jsxs(Box, { sx: { textAlign: "center", py: 4 }, children: [
1131
+ /* @__PURE__ */ jsx(Typography, { variant: "body2", color: "textSecondary", children: "No colors found matching your filters" }),
1132
+ /* @__PURE__ */ jsxs(Box, { sx: { mt: 1, display: "flex", justifyContent: "center", gap: 1 }, children: [
1133
+ searchTerm && /* @__PURE__ */ jsx(Button, { size: "small", onClick: handleClearSearch, children: "Clear search" }),
1134
+ selectedMode && /* @__PURE__ */ jsx(Button, { size: "small", onClick: handleClearMode, children: "Clear mode filter" })
1135
+ ] })
1136
+ ] })
1137
+ ] }),
1138
+ Object.keys(displayValue).length === 0 && /* @__PURE__ */ jsx(Box, { sx: { textAlign: "center", py: 4 }, children: /* @__PURE__ */ jsx(Typography, { variant: "body2", color: "textSecondary", children: "No colors configured in this palette" }) })
1139
+ ] });
1140
+ };
1141
+ const JsonColorSelector = ({ method, attribute, resourceConfig }) => {
1142
+ const [componentLoading, setComponentLoading] = useState(true);
1143
+ useEffect(() => {
1144
+ window.dispatchEvent(new MessageEvent("auto-admin-loading-state", { data: true }));
1145
+ const timer = setTimeout(() => {
1146
+ setComponentLoading(false);
1147
+ }, 50);
1148
+ return () => {
1149
+ clearTimeout(timer);
1150
+ window.dispatchEvent(new MessageEvent("auto-admin-loading-state", { data: false }));
1151
+ };
1152
+ }, []);
1153
+ if (componentLoading) {
1154
+ return /* @__PURE__ */ jsx(Box, { sx: { display: "flex", justifyContent: "center", alignItems: "center", minHeight: 100 }, children: /* @__PURE__ */ jsx(Typography, { variant: "body2", color: "textSecondary", children: "Initializing color palette..." }) });
1155
+ }
1156
+ switch (method) {
1157
+ case "edit":
1158
+ return /* @__PURE__ */ jsx(JsonEdit, { attribute, method, resourceConfig });
1159
+ case "create":
1160
+ return /* @__PURE__ */ jsx(JsonEdit, { attribute, method, resourceConfig });
1161
+ case "view":
1162
+ return /* @__PURE__ */ jsx(JsonView, { attribute, method, resourceConfig });
1163
+ default:
1164
+ return null;
1165
+ }
1166
+ };
1167
+ var JsonColorSelector_default = JsonColorSelector;
1168
+ export {
1169
+ JsonEdit,
1170
+ JsonView,
1171
+ JsonColorSelector_default as default
1172
+ };