@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,283 @@
1
- import{jsx as e,jsxs as a}from"react/jsx-runtime";import{Box as r,Button as A,IconButton as D,Typography as i,Card as j,CardMedia as L,CircularProgress as U,Input as O,Alert as F,TextField as H,Divider as K}from"@mui/material";import M from"@mui/icons-material/Delete";import V from"@mui/icons-material/CloudUpload";import $ from"@mui/icons-material/Palette";import q from"@mui/icons-material/AutoFixHigh";import{useState as m,useEffect as _,memo as J,useCallback as N}from"react";import{useAsyncColorThief as Q}from"../useAsyncColorThief";import{getContrastColor as X,rgbArrayToHex as Y}from"../helpers/functions";import{useAxios as Z}from"@dashadmin/dash-axios-hook";const ee=J(({onColorsExtracted:x,onColorsUpdate:h,existingPairs:I=[]})=>{const[c,C]=m(null),[te,v]=m(null),[f,R]=m(""),[y,T]=m(!1),[B,b]=m(null),[n,P]=m([]),w=Z(),{dominantColor:g,palette:p,loading:E,error:k}=Q(c,{colorCount:8,quality:10});_(()=>{p&&p.length>0&&(P(p),x(p))},[p,x]);const S=t=>{const o=t.target.files?.[0];if(o){if(!o.type.startsWith("image/")){alert("Please select a valid image file");return}if(o.size>5*1024*1024){alert("File size must be less than 5MB");return}v(o);const s=URL.createObjectURL(o);C(s)}},z=()=>{c&&c.startsWith("blob:")&&URL.revokeObjectURL(c),C(null),v(null),P([]),x([])},G=N(async()=>{if(!n||n.length===0){b("Please extract colors from an image first");return}T(!0),b(null);try{const t=await w.post("/tenant/tenant/settings/theme-generator",{colors:n,prompt:f,output_format:"json"});if(t.status!==200)throw new Error(`HTTP error! status: ${t.status}`);const o=t.data;if(o.success&&o.data){const s=Object.entries(o.data).map(([d,u])=>({key:d,value:String(u),id:Math.random().toString(36).substring(2,11)})),l=[...I];s.forEach(d=>{const u=l.findIndex(W=>W.key===d.key);u>=0?l[u]=d:l.push(d)}),h&&h(l)}else throw new Error(o.message||"Failed to generate theme")}catch(t){console.error("Theme generation error:",t),b(t instanceof Error?t.message:"Failed to generate theme")}finally{T(!1)}},[n,f,I,h,w]);return a(r,{sx:{mt:3,p:3,borderRadius:2},children:[a(i,{variant:"h6",gutterBottom:!0,sx:{display:"flex",alignItems:"center",gap:1},children:[e($,{}),"AI Theme Generator"]}),e(K,{sx:{mb:3}}),e(r,{sx:{mb:3},children:c?e(j,{sx:{maxWidth:400,mb:3},children:a(r,{sx:{position:"relative"},children:[e(L,{component:"img",height:"200",image:c,alt:"Uploaded image",sx:{objectFit:"contain"}}),e(D,{sx:{position:"absolute",top:8,right:8,backgroundColor:"rgba(255, 255, 255, 0.9)","&:hover":{backgroundColor:"rgba(255, 255, 255, 1)"}},onClick:z,size:"small",children:e(M,{})})]})}):a(r,{sx:{textAlign:"center",py:4,backgroundColor:"rgba(0,0,0,0.02)",borderRadius:1,border:"2px dashed #e0e0e0"},children:[e(O,{type:"file",inputProps:{accept:"image/*"},onChange:S,sx:{display:"none"},id:"color-extractor-upload"}),e(i,{variant:"body1",color:"textSecondary",gutterBottom:!0,children:"Upload an Image to Extract Colors"}),e(i,{variant:"body2",color:"textSecondary",sx:{mb:2},children:"Select an image file and we'll automatically extract a color palette"}),e("label",{htmlFor:"color-extractor-upload",children:e(A,{variant:"contained",component:"span",startIcon:e(V,{}),size:"large",children:"Choose Image"})})]})}),E&&a(r,{display:"flex",alignItems:"center",gap:2,sx:{mb:3,p:2,backgroundColor:"rgba(25, 118, 210, 0.04)",borderRadius:1},children:[e(U,{size:20}),e(i,{children:"Extracting colors from image..."})]}),k&&e(F,{severity:"error",sx:{mb:3},children:k}),B&&e(F,{severity:"error",sx:{mb:3},children:B}),n&&n.length>0&&!E&&a(r,{sx:{mb:3},children:[a(i,{variant:"subtitle1",gutterBottom:!0,children:["Extracted Colors (",n.length," colors found)"]}),e(r,{sx:{display:"flex",flexWrap:"wrap",gap:1,mt:2,mb:3},children:n.map((t,o)=>{const s=Y(t),l=g&&t[0]===g[0]&&t[1]===g[1]&&t[2]===g[2];return e(r,{sx:{width:50,height:50,backgroundColor:s,borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",border:l?"3px solid #4caf50":"2px solid #ccc",cursor:"pointer",transition:"transform 0.2s","&:hover":{transform:"scale(1.1)"}},title:`${s} ${l?"(Dominant)":""}`,children:e(i,{variant:"caption",sx:{color:X(s),fontWeight:"bold",fontSize:"0.8rem"},children:o+1})},o)})}),a(r,{sx:{mb:3},children:[e(H,{fullWidth:!0,multiline:!0,rows:2,placeholder:"Optional: Describe the theme style you want (e.g., 'modern and minimalist', 'warm and cozy', 'professional corporate')",value:f,onChange:t=>R(t.target.value),sx:{mb:2},label:"Theme Description (Optional)"}),e(r,{sx:{display:"flex",gap:2,flexWrap:"wrap"},children:e(A,{variant:"contained",startIcon:y?e(U,{size:16}):e(q,{}),onClick:G,disabled:y,color:"primary",children:y?"Generating...":"Generate AI Theme"})})]}),a(i,{variant:"body2",color:"textSecondary",sx:{fontStyle:"italic"},children:["\u2022 ",e("strong",{children:"Generate AI Theme:"})," Uses AI to create a complete color scheme based on extracted colors and your description"]})]})]})});var xe=ee;export{xe as default};
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import { jsx, jsxs } from "react/jsx-runtime";
22
+ import {
23
+ Box,
24
+ Button,
25
+ IconButton,
26
+ Typography,
27
+ Card,
28
+ CardMedia,
29
+ CircularProgress,
30
+ Input,
31
+ Alert,
32
+ TextField,
33
+ Divider
34
+ } from "@mui/material";
35
+ import DeleteIcon from "@mui/icons-material/Delete";
36
+ import CloudUploadIcon from "@mui/icons-material/CloudUpload";
37
+ import PaletteIcon from "@mui/icons-material/Palette";
38
+ import AutoFixHighIcon from "@mui/icons-material/AutoFixHigh";
39
+ import { useState, useEffect, memo, useCallback } from "react";
40
+ import { useAsyncColorThief } from "../useAsyncColorThief";
41
+ import { getContrastColor, rgbArrayToHex } from "../helpers/functions";
42
+ import { useAxios } from "dash-axios-hook";
43
+ const ImageColorExtractor = memo(({ onColorsExtracted, onColorsUpdate, existingPairs = [] }) => {
44
+ const [imageUrl, setImageUrl] = useState(null);
45
+ const [uploadedFile, setUploadedFile] = useState(null);
46
+ const [themePrompt, setThemePrompt] = useState("");
47
+ const [isGeneratingTheme, setIsGeneratingTheme] = useState(false);
48
+ const [themeError, setThemeError] = useState(null);
49
+ const [extractedPalette, setExtractedPalette] = useState([]);
50
+ const axios = useAxios();
51
+ const { dominantColor, palette, loading, error } = useAsyncColorThief(imageUrl, {
52
+ colorCount: 8,
53
+ quality: 10
54
+ });
55
+ useEffect(() => {
56
+ if (palette && palette.length > 0) {
57
+ setExtractedPalette(palette);
58
+ onColorsExtracted(palette);
59
+ }
60
+ }, [palette, onColorsExtracted]);
61
+ const handleFileSelect = (event) => {
62
+ var _a;
63
+ const file = (_a = event.target.files) == null ? void 0 : _a[0];
64
+ if (file) {
65
+ if (!file.type.startsWith("image/")) {
66
+ alert("Please select a valid image file");
67
+ return;
68
+ }
69
+ if (file.size > 5 * 1024 * 1024) {
70
+ alert("File size must be less than 5MB");
71
+ return;
72
+ }
73
+ setUploadedFile(file);
74
+ const previewUrl = URL.createObjectURL(file);
75
+ setImageUrl(previewUrl);
76
+ }
77
+ };
78
+ const handleImageRemove = () => {
79
+ if (imageUrl && imageUrl.startsWith("blob:")) {
80
+ URL.revokeObjectURL(imageUrl);
81
+ }
82
+ setImageUrl(null);
83
+ setUploadedFile(null);
84
+ setExtractedPalette([]);
85
+ onColorsExtracted([]);
86
+ };
87
+ const handleGenerateTheme = useCallback(() => __async(null, null, function* () {
88
+ if (!extractedPalette || extractedPalette.length === 0) {
89
+ setThemeError("Please extract colors from an image first");
90
+ return;
91
+ }
92
+ setIsGeneratingTheme(true);
93
+ setThemeError(null);
94
+ try {
95
+ const response = yield axios.post("/tenant/tenant/settings/theme-generator", {
96
+ colors: extractedPalette,
97
+ prompt: themePrompt,
98
+ output_format: "json"
99
+ });
100
+ if (response.status !== 200) {
101
+ throw new Error(`HTTP error! status: ${response.status}`);
102
+ }
103
+ const result = response.data;
104
+ if (result.success && result.data) {
105
+ const newPairs = Object.entries(result.data).map(([key, value]) => ({
106
+ key,
107
+ value: String(value),
108
+ id: Math.random().toString(36).substring(2, 11)
109
+ }));
110
+ const mergedPairs = [...existingPairs];
111
+ newPairs.forEach((newPair) => {
112
+ const existingIndex = mergedPairs.findIndex((existing) => existing.key === newPair.key);
113
+ if (existingIndex >= 0) {
114
+ mergedPairs[existingIndex] = newPair;
115
+ } else {
116
+ mergedPairs.push(newPair);
117
+ }
118
+ });
119
+ if (onColorsUpdate) {
120
+ onColorsUpdate(mergedPairs);
121
+ }
122
+ } else {
123
+ throw new Error(result.message || "Failed to generate theme");
124
+ }
125
+ } catch (error2) {
126
+ console.error("Theme generation error:", error2);
127
+ setThemeError(error2 instanceof Error ? error2.message : "Failed to generate theme");
128
+ } finally {
129
+ setIsGeneratingTheme(false);
130
+ }
131
+ }), [extractedPalette, themePrompt, existingPairs, onColorsUpdate, axios]);
132
+ return /* @__PURE__ */ jsxs(Box, { sx: { mt: 3, p: 3, borderRadius: 2 }, children: [
133
+ /* @__PURE__ */ jsxs(Typography, { variant: "h6", gutterBottom: true, sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
134
+ /* @__PURE__ */ jsx(PaletteIcon, {}),
135
+ "AI Theme Generator"
136
+ ] }),
137
+ /* @__PURE__ */ jsx(Divider, { sx: { mb: 3 } }),
138
+ /* @__PURE__ */ jsx(Box, { sx: { mb: 3 }, children: !imageUrl ? /* @__PURE__ */ jsxs(Box, { sx: {
139
+ textAlign: "center",
140
+ py: 4,
141
+ backgroundColor: "rgba(0,0,0,0.02)",
142
+ borderRadius: 1,
143
+ border: "2px dashed #e0e0e0"
144
+ }, children: [
145
+ /* @__PURE__ */ jsx(
146
+ Input,
147
+ {
148
+ type: "file",
149
+ inputProps: { accept: "image/*" },
150
+ onChange: handleFileSelect,
151
+ sx: { display: "none" },
152
+ id: "color-extractor-upload"
153
+ }
154
+ ),
155
+ /* @__PURE__ */ jsx(Typography, { variant: "body1", color: "textSecondary", gutterBottom: true, children: "Upload an Image to Extract Colors" }),
156
+ /* @__PURE__ */ jsx(Typography, { variant: "body2", color: "textSecondary", sx: { mb: 2 }, children: "Select an image file and we'll automatically extract a color palette" }),
157
+ /* @__PURE__ */ jsx("label", { htmlFor: "color-extractor-upload", children: /* @__PURE__ */ jsx(
158
+ Button,
159
+ {
160
+ variant: "contained",
161
+ component: "span",
162
+ startIcon: /* @__PURE__ */ jsx(CloudUploadIcon, {}),
163
+ size: "large",
164
+ children: "Choose Image"
165
+ }
166
+ ) })
167
+ ] }) : /* @__PURE__ */ jsx(Card, { sx: { maxWidth: 400, mb: 3 }, children: /* @__PURE__ */ jsxs(Box, { sx: { position: "relative" }, children: [
168
+ /* @__PURE__ */ jsx(
169
+ CardMedia,
170
+ {
171
+ component: "img",
172
+ height: "200",
173
+ image: imageUrl,
174
+ alt: "Uploaded image",
175
+ sx: { objectFit: "contain" }
176
+ }
177
+ ),
178
+ /* @__PURE__ */ jsx(
179
+ IconButton,
180
+ {
181
+ sx: {
182
+ position: "absolute",
183
+ top: 8,
184
+ right: 8,
185
+ backgroundColor: "rgba(255, 255, 255, 0.9)",
186
+ "&:hover": {
187
+ backgroundColor: "rgba(255, 255, 255, 1)"
188
+ }
189
+ },
190
+ onClick: handleImageRemove,
191
+ size: "small",
192
+ children: /* @__PURE__ */ jsx(DeleteIcon, {})
193
+ }
194
+ )
195
+ ] }) }) }),
196
+ loading && /* @__PURE__ */ jsxs(Box, { display: "flex", alignItems: "center", gap: 2, sx: { mb: 3, p: 2, backgroundColor: "rgba(25, 118, 210, 0.04)", borderRadius: 1 }, children: [
197
+ /* @__PURE__ */ jsx(CircularProgress, { size: 20 }),
198
+ /* @__PURE__ */ jsx(Typography, { children: "Extracting colors from image..." })
199
+ ] }),
200
+ error && /* @__PURE__ */ jsx(Alert, { severity: "error", sx: { mb: 3 }, children: error }),
201
+ themeError && /* @__PURE__ */ jsx(Alert, { severity: "error", sx: { mb: 3 }, children: themeError }),
202
+ extractedPalette && extractedPalette.length > 0 && !loading && /* @__PURE__ */ jsxs(Box, { sx: { mb: 3 }, children: [
203
+ /* @__PURE__ */ jsxs(Typography, { variant: "subtitle1", gutterBottom: true, children: [
204
+ "Extracted Colors (",
205
+ extractedPalette.length,
206
+ " colors found)"
207
+ ] }),
208
+ /* @__PURE__ */ jsx(Box, { sx: { display: "flex", flexWrap: "wrap", gap: 1, mt: 2, mb: 3 }, children: extractedPalette.map((color, index) => {
209
+ const hexColor = rgbArrayToHex(color);
210
+ const isDominant = dominantColor && color[0] === dominantColor[0] && color[1] === dominantColor[1] && color[2] === dominantColor[2];
211
+ return /* @__PURE__ */ jsx(
212
+ Box,
213
+ {
214
+ sx: {
215
+ width: 50,
216
+ height: 50,
217
+ backgroundColor: hexColor,
218
+ borderRadius: "50%",
219
+ display: "flex",
220
+ alignItems: "center",
221
+ justifyContent: "center",
222
+ border: isDominant ? "3px solid #4caf50" : "2px solid #ccc",
223
+ cursor: "pointer",
224
+ transition: "transform 0.2s",
225
+ "&:hover": {
226
+ transform: "scale(1.1)"
227
+ }
228
+ },
229
+ title: `${hexColor} ${isDominant ? "(Dominant)" : ""}`,
230
+ children: /* @__PURE__ */ jsx(
231
+ Typography,
232
+ {
233
+ variant: "caption",
234
+ sx: {
235
+ color: getContrastColor(hexColor),
236
+ fontWeight: "bold",
237
+ fontSize: "0.8rem"
238
+ },
239
+ children: index + 1
240
+ }
241
+ )
242
+ },
243
+ index
244
+ );
245
+ }) }),
246
+ /* @__PURE__ */ jsxs(Box, { sx: { mb: 3 }, children: [
247
+ /* @__PURE__ */ jsx(
248
+ TextField,
249
+ {
250
+ fullWidth: true,
251
+ multiline: true,
252
+ rows: 2,
253
+ placeholder: "Optional: Describe the theme style you want (e.g., 'modern and minimalist', 'warm and cozy', 'professional corporate')",
254
+ value: themePrompt,
255
+ onChange: (e) => setThemePrompt(e.target.value),
256
+ sx: { mb: 2 },
257
+ label: "Theme Description (Optional)"
258
+ }
259
+ ),
260
+ /* @__PURE__ */ jsx(Box, { sx: { display: "flex", gap: 2, flexWrap: "wrap" }, children: /* @__PURE__ */ jsx(
261
+ Button,
262
+ {
263
+ variant: "contained",
264
+ startIcon: isGeneratingTheme ? /* @__PURE__ */ jsx(CircularProgress, { size: 16 }) : /* @__PURE__ */ jsx(AutoFixHighIcon, {}),
265
+ onClick: handleGenerateTheme,
266
+ disabled: isGeneratingTheme,
267
+ color: "primary",
268
+ children: isGeneratingTheme ? "Generating..." : "Generate AI Theme"
269
+ }
270
+ ) })
271
+ ] }),
272
+ /* @__PURE__ */ jsxs(Typography, { variant: "body2", color: "textSecondary", sx: { fontStyle: "italic" }, children: [
273
+ "\u2022 ",
274
+ /* @__PURE__ */ jsx("strong", { children: "Generate AI Theme:" }),
275
+ " Uses AI to create a complete color scheme based on extracted colors and your description"
276
+ ] })
277
+ ] })
278
+ ] });
279
+ });
280
+ var ImageColorExtractor_default = ImageColorExtractor;
281
+ export {
282
+ ImageColorExtractor_default as default
283
+ };
@@ -1 +1,101 @@
1
- const l=t=>{let r,s,e,a=1;if(t.startsWith("#")){const n=t.replace("#","");n.length===8?(r=parseInt(n.substr(0,2),16),s=parseInt(n.substr(2,2),16),e=parseInt(n.substr(4,2),16),a=parseInt(n.substr(6,2),16)/255):(r=parseInt(n.substr(0,2),16),s=parseInt(n.substr(2,2),16),e=parseInt(n.substr(4,2),16))}else if(t.startsWith("rgb")){const n=t.match(/rgba?\(([^)]+)\)/);if(n){const h=n[1].split(",").map(i=>parseFloat(i.trim()));[r,s,e,a=1]=h}else return"#000000"}else return t.startsWith("hsl"),"#000000";return(.299*r+.587*s+.114*e)/255*a+(1-a)>.5?"#000000":"#ffffff"},m=(t,r)=>{switch(r){case"hex":if(t.rgb.a!==void 0&&t.rgb.a<1){const u=Math.round(t.rgb.a*255).toString(16).padStart(2,"0");return`${t.hex}${u}`}return t.hex;case"rgb":return`rgb(${Math.round(t.rgb.r)}, ${Math.round(t.rgb.g)}, ${Math.round(t.rgb.b)})`;case"rgba":const s=t.rgb.a!==void 0?Number(t.rgb.a.toFixed(2)):1;return`rgba(${Math.round(t.rgb.r)}, ${Math.round(t.rgb.g)}, ${Math.round(t.rgb.b)}, ${s})`;case"hsl":return`hsl(${Math.round(t.hsl.h)}, ${Math.round(t.hsl.s*100)}%, ${Math.round(t.hsl.l*100)}%)`;case"hsla":const e=t.hsl.a!==void 0?Number(t.hsl.a.toFixed(2)):1;return`hsla(${Math.round(t.hsl.h)}, ${Math.round(t.hsl.s*100)}%, ${Math.round(t.hsl.l*100)}%, ${e})`;default:return t.hex}},b=t=>{const r=t.split("--"),s=r[0],e=r[1];return{baseChips:s.split("-").filter(u=>u.length>0),mode:e}},c=t=>{const r=new Set;return t.forEach(s=>{const{mode:e}=b(s.key);e&&r.add(e)}),Array.from(r).sort()},$=t=>{if(!t)return"";switch(t.toLowerCase()){case"light":return"\u2600\uFE0F";case"dark":return"\u{1F319}";default:return t}},x=t=>{const[r,s,e]=t;return`#${((1<<24)+(r<<16)+(s<<8)+e).toString(16).slice(1)}`},M=t=>{const[r,s,e]=t;return`rgb(${r}, ${s}, ${e})`};export{m as convertColor,c as extractAvailableModes,l as getContrastColor,$ as getModeIcon,b as parseColorKey,x as rgbArrayToHex,M as rgbArrayToRgbString};
1
+ const getContrastColor = (color) => {
2
+ let r, g, b, a = 1;
3
+ if (color.startsWith("#")) {
4
+ const hex = color.replace("#", "");
5
+ if (hex.length === 8) {
6
+ r = parseInt(hex.substr(0, 2), 16);
7
+ g = parseInt(hex.substr(2, 2), 16);
8
+ b = parseInt(hex.substr(4, 2), 16);
9
+ a = parseInt(hex.substr(6, 2), 16) / 255;
10
+ } else {
11
+ r = parseInt(hex.substr(0, 2), 16);
12
+ g = parseInt(hex.substr(2, 2), 16);
13
+ b = parseInt(hex.substr(4, 2), 16);
14
+ }
15
+ } else if (color.startsWith("rgb")) {
16
+ const match = color.match(/rgba?\(([^)]+)\)/);
17
+ if (match) {
18
+ const values = match[1].split(",").map((v) => parseFloat(v.trim()));
19
+ [r, g, b, a = 1] = values;
20
+ } else {
21
+ return "#000000";
22
+ }
23
+ } else if (color.startsWith("hsl")) {
24
+ return "#000000";
25
+ } else {
26
+ return "#000000";
27
+ }
28
+ const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
29
+ const effectiveLuminance = luminance * a + (1 - a);
30
+ return effectiveLuminance > 0.5 ? "#000000" : "#ffffff";
31
+ };
32
+ const convertColor = (color, format) => {
33
+ switch (format) {
34
+ case "hex":
35
+ if (color.rgb.a !== void 0 && color.rgb.a < 1) {
36
+ const alpha2 = Math.round(color.rgb.a * 255);
37
+ const alphaHex = alpha2.toString(16).padStart(2, "0");
38
+ return `${color.hex}${alphaHex}`;
39
+ }
40
+ return color.hex;
41
+ case "rgb":
42
+ return `rgb(${Math.round(color.rgb.r)}, ${Math.round(color.rgb.g)}, ${Math.round(color.rgb.b)})`;
43
+ case "rgba":
44
+ const alpha = color.rgb.a !== void 0 ? Number(color.rgb.a.toFixed(2)) : 1;
45
+ return `rgba(${Math.round(color.rgb.r)}, ${Math.round(color.rgb.g)}, ${Math.round(color.rgb.b)}, ${alpha})`;
46
+ case "hsl":
47
+ return `hsl(${Math.round(color.hsl.h)}, ${Math.round(color.hsl.s * 100)}%, ${Math.round(color.hsl.l * 100)}%)`;
48
+ case "hsla":
49
+ const hslaAlpha = color.hsl.a !== void 0 ? Number(color.hsl.a.toFixed(2)) : 1;
50
+ return `hsla(${Math.round(color.hsl.h)}, ${Math.round(color.hsl.s * 100)}%, ${Math.round(color.hsl.l * 100)}%, ${hslaAlpha})`;
51
+ default:
52
+ return color.hex;
53
+ }
54
+ };
55
+ const parseColorKey = (key) => {
56
+ const parts = key.split("--");
57
+ const baseName = parts[0];
58
+ const mode = parts[1];
59
+ const baseChips = baseName.split("-").filter((part) => part.length > 0);
60
+ return { baseChips, mode };
61
+ };
62
+ const extractAvailableModes = (pairs) => {
63
+ const modes = /* @__PURE__ */ new Set();
64
+ pairs.forEach((pair) => {
65
+ const { mode } = parseColorKey(pair.key);
66
+ if (mode) {
67
+ modes.add(mode);
68
+ }
69
+ });
70
+ return Array.from(modes).sort();
71
+ };
72
+ const getModeIcon = (mode) => {
73
+ if (!mode) return "";
74
+ switch (mode.toLowerCase()) {
75
+ case "light":
76
+ return "\u2600\uFE0F";
77
+ // Sun icon
78
+ case "dark":
79
+ return "\u{1F319}";
80
+ // Moon icon
81
+ default:
82
+ return mode;
83
+ }
84
+ };
85
+ const rgbArrayToHex = (rgb) => {
86
+ const [r, g, b] = rgb;
87
+ return `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`;
88
+ };
89
+ const rgbArrayToRgbString = (rgb) => {
90
+ const [r, g, b] = rgb;
91
+ return `rgb(${r}, ${g}, ${b})`;
92
+ };
93
+ export {
94
+ convertColor,
95
+ extractAvailableModes,
96
+ getContrastColor,
97
+ getModeIcon,
98
+ parseColorKey,
99
+ rgbArrayToHex,
100
+ rgbArrayToRgbString
101
+ };
@@ -1 +1,105 @@
1
- import{useState as f,useEffect as d,useCallback as C}from"react";const m=(t,n={})=>{const[u,l]=f({dominantColor:null,palette:null,loading:!1,error:null}),s=C(async i=>{if(i){l(e=>({...e,loading:!0,error:null}));try{const e=(await import("colorthief")).default,r=new Image;r.crossOrigin="anonymous",r.onload=()=>{try{const o=new e,a=o.getColor(r),c=o.getPalette(r,n.colorCount||5,n.quality||10);l({dominantColor:a,palette:c,loading:!1,error:null})}catch(o){console.error("Color extraction error:",o),l(a=>({...a,loading:!1,error:`Failed to extract colors: ${o instanceof Error?o.message:"Unknown error"}`}))}},r.onerror=()=>{l(o=>({...o,loading:!1,error:"Failed to load image"}))},r.src=i}catch(e){console.error("ColorThief import error:",e),l(r=>({...r,loading:!1,error:`Failed to load Color Thief: ${e instanceof Error?e.message:"Unknown error"}`}))}}},[n.colorCount,n.quality]);return d(()=>{t?s(t):l({dominantColor:null,palette:null,loading:!1,error:null})},[t,s]),u};export{m as useAsyncColorThief};
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 { useState, useEffect, useCallback } from "react";
41
+ const useAsyncColorThief = (imageSource, options = {}) => {
42
+ const [result, setResult] = useState({
43
+ dominantColor: null,
44
+ palette: null,
45
+ loading: false,
46
+ error: null
47
+ });
48
+ const extractColors = useCallback((src) => __async(null, null, function* () {
49
+ if (!src) return;
50
+ setResult((prev) => __spreadProps(__spreadValues({}, prev), { loading: true, error: null }));
51
+ try {
52
+ const ColorThief = (yield import("colorthief")).default;
53
+ const img = new Image();
54
+ img.crossOrigin = "anonymous";
55
+ img.onload = () => {
56
+ try {
57
+ const colorThief = new ColorThief();
58
+ const dominantColor = colorThief.getColor(img);
59
+ const palette = colorThief.getPalette(img, options.colorCount || 5, options.quality || 10);
60
+ setResult({
61
+ dominantColor,
62
+ palette,
63
+ loading: false,
64
+ error: null
65
+ });
66
+ } catch (error) {
67
+ console.error("Color extraction error:", error);
68
+ setResult((prev) => __spreadProps(__spreadValues({}, prev), {
69
+ loading: false,
70
+ error: `Failed to extract colors: ${error instanceof Error ? error.message : "Unknown error"}`
71
+ }));
72
+ }
73
+ };
74
+ img.onerror = () => {
75
+ setResult((prev) => __spreadProps(__spreadValues({}, prev), {
76
+ loading: false,
77
+ error: "Failed to load image"
78
+ }));
79
+ };
80
+ img.src = src;
81
+ } catch (error) {
82
+ console.error("ColorThief import error:", error);
83
+ setResult((prev) => __spreadProps(__spreadValues({}, prev), {
84
+ loading: false,
85
+ error: `Failed to load Color Thief: ${error instanceof Error ? error.message : "Unknown error"}`
86
+ }));
87
+ }
88
+ }), [options.colorCount, options.quality]);
89
+ useEffect(() => {
90
+ if (imageSource) {
91
+ extractColors(imageSource);
92
+ } else {
93
+ setResult({
94
+ dominantColor: null,
95
+ palette: null,
96
+ loading: false,
97
+ error: null
98
+ });
99
+ }
100
+ }, [imageSource, extractColors]);
101
+ return result;
102
+ };
103
+ export {
104
+ useAsyncColorThief
105
+ };
@@ -1 +1,126 @@
1
- import{Fragment as b,jsx as r,jsxs as v}from"react/jsx-runtime";import{useCallback as h,useEffect as C,useState as u}from"react";import{useRecordContext as I,useUpdate as y}from"react-admin";import{Switch as x,Box as S}from"@mui/material";import{AttributeToField as w}from"@dashadmin/dash-auto-admin/src/mui/AttributeToField";import B from"@dashadmin/dash-auto-admin/src/mui/AttributeToInput";const D=({method:s,attribute:e,resourceConfig:i,activeLabel:c="Activo",inactiveLabel:l="Inactivo",enableLabel:F="Activar",disableLabel:T="Desactivar",showLabel:A=!1})=>{const[,L]=u(!0),[d,{isLoading:k}]=y(),t=I(),[n,m]=u(!1),p=o=>{console.error(o)},g=h(async o=>{try{await d(i.model+"/partial/"+t.id,{id:t.id,data:{[e.attribute]:o},previousData:t,meta:{method:"POST"}},{onSuccess:()=>{m(o)},onSettled:(a,f)=>{f&&p(f)}})}catch(a){p(a)}},[d,t]);switch(C(()=>{L(!1),t&&e&&e.attribute in t&&m(!!t[e.attribute])},[t,e]),s){case"create":case"edit":return B(s,i,{...e,custom:!1,type:Boolean});case"view":return w(s,i,{...e,custom:!1,type:Boolean});case"list":return r("div",{children:v(S,{children:[r(x,{size:"small",onChange:(o,a)=>g(a),checked:n}),A?n?c:l:r(b,{})]})});default:return v(b,{children:[e.label,": ",n?c:l]})}};var K=D;export{K 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 { useCallback, useEffect, useState } from "react";
42
+ import { useRecordContext, useUpdate } from "react-admin";
43
+ import { Switch, Box } from "@mui/material";
44
+ import { AttributeToField } from "dash-auto-admin/src/mui/AttributeToField";
45
+ import AttributeToInput from "dash-auto-admin/src/mui/AttributeToInput";
46
+ const ListActive = ({
47
+ method,
48
+ attribute,
49
+ resourceConfig,
50
+ activeLabel = "Activo",
51
+ inactiveLabel = "Inactivo",
52
+ enableLabel = "Activar",
53
+ disableLabel = "Desactivar",
54
+ showLabel = false
55
+ }) => {
56
+ const [, setLoading] = useState(true);
57
+ const [update, { isLoading: updateLoading }] = useUpdate();
58
+ const record = useRecordContext();
59
+ const [is_active, setIsActive] = useState(false);
60
+ const onError = (error) => {
61
+ console.error(error);
62
+ };
63
+ const onChange = useCallback(
64
+ (value) => __async(null, null, function* () {
65
+ try {
66
+ yield update(
67
+ resourceConfig.model + "/partial/" + record.id,
68
+ {
69
+ id: record.id,
70
+ data: { [attribute.attribute]: value },
71
+ previousData: record,
72
+ meta: {
73
+ method: "POST"
74
+ }
75
+ },
76
+ {
77
+ onSuccess: () => {
78
+ setIsActive(value);
79
+ },
80
+ onSettled: (data, error) => {
81
+ if (error) onError(error);
82
+ }
83
+ }
84
+ );
85
+ } catch (error) {
86
+ onError(error);
87
+ }
88
+ }),
89
+ [update, record]
90
+ );
91
+ useEffect(() => {
92
+ setLoading(false);
93
+ if (record && attribute && attribute.attribute in record) {
94
+ setIsActive(!!record[attribute.attribute]);
95
+ }
96
+ }, [record, attribute]);
97
+ switch (method) {
98
+ case "create":
99
+ case "edit":
100
+ return AttributeToInput(method, resourceConfig, __spreadProps(__spreadValues({}, attribute), { custom: false, type: Boolean }));
101
+ case "view":
102
+ return AttributeToField(method, resourceConfig, __spreadProps(__spreadValues({}, attribute), { custom: false, type: Boolean }));
103
+ case "list":
104
+ return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(Box, { children: [
105
+ /* @__PURE__ */ jsx(
106
+ Switch,
107
+ {
108
+ size: "small",
109
+ onChange: (e, value) => onChange(value),
110
+ checked: is_active
111
+ }
112
+ ),
113
+ showLabel ? is_active ? activeLabel : inactiveLabel : /* @__PURE__ */ jsx(Fragment, {})
114
+ ] }) });
115
+ default:
116
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
117
+ attribute.label,
118
+ ": ",
119
+ is_active ? activeLabel : inactiveLabel
120
+ ] });
121
+ }
122
+ };
123
+ var ListActive_default = ListActive;
124
+ export {
125
+ ListActive_default as default
126
+ };