app-studio 0.2.4 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/appstudio.cjs.development.js +82 -42
- package/dist/appstudio.cjs.development.js.map +1 -1
- package/dist/appstudio.cjs.production.min.js +1 -1
- package/dist/appstudio.cjs.production.min.js.map +1 -1
- package/dist/appstudio.esm.js +82 -42
- package/dist/appstudio.esm.js.map +1 -1
- package/dist/appstudio.umd.development.js +82 -42
- package/dist/appstudio.umd.development.js.map +1 -1
- package/dist/appstudio.umd.production.min.js +1 -1
- package/dist/appstudio.umd.production.min.js.map +1 -1
- package/dist/providers/Theme.d.ts +19 -50
- package/package.json +1 -1
|
@@ -310,6 +310,7 @@
|
|
|
310
310
|
}
|
|
311
311
|
};
|
|
312
312
|
|
|
313
|
+
// Configuration de thème par défaut
|
|
313
314
|
const defaultThemeMain = {
|
|
314
315
|
primary: 'color.black',
|
|
315
316
|
secondary: 'color.blue',
|
|
@@ -319,6 +320,7 @@
|
|
|
319
320
|
disabled: 'color.gray.500',
|
|
320
321
|
loading: 'color.dark.500'
|
|
321
322
|
};
|
|
323
|
+
// Configuration des couleurs par défaut
|
|
322
324
|
const defaultColors = {
|
|
323
325
|
white: '#FFFFFF',
|
|
324
326
|
black: '#000000',
|
|
@@ -351,10 +353,9 @@
|
|
|
351
353
|
darkGreen: '#006400',
|
|
352
354
|
salmon: '#FA8072'
|
|
353
355
|
};
|
|
356
|
+
// Création du contexte de thème avec des valeurs par défaut
|
|
354
357
|
const ThemeContext = /*#__PURE__*/React.createContext({
|
|
355
|
-
getColor: name =>
|
|
356
|
-
return name;
|
|
357
|
-
},
|
|
358
|
+
getColor: name => name,
|
|
358
359
|
colors: {
|
|
359
360
|
main: defaultColors,
|
|
360
361
|
palette: palette
|
|
@@ -364,7 +365,35 @@
|
|
|
364
365
|
components: {}
|
|
365
366
|
}
|
|
366
367
|
});
|
|
368
|
+
// Hook personnalisé pour utiliser le contexte de thème
|
|
367
369
|
const useTheme = () => React.useContext(ThemeContext);
|
|
370
|
+
// Fonction de fusion profonde simple
|
|
371
|
+
const deepMerge = (target, source) => {
|
|
372
|
+
if (typeof source !== 'object' || source === null) {
|
|
373
|
+
return target;
|
|
374
|
+
}
|
|
375
|
+
const merged = {
|
|
376
|
+
...target
|
|
377
|
+
};
|
|
378
|
+
for (const key in source) {
|
|
379
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
380
|
+
const sourceValue = source[key];
|
|
381
|
+
const targetValue = target[key];
|
|
382
|
+
if (Array.isArray(sourceValue)) {
|
|
383
|
+
// Remplacer les tableaux
|
|
384
|
+
merged[key] = sourceValue;
|
|
385
|
+
} else if (typeof sourceValue === 'object' && sourceValue !== null && !Array.isArray(sourceValue)) {
|
|
386
|
+
// Fusion récursive des objets
|
|
387
|
+
merged[key] = deepMerge(targetValue || {}, sourceValue);
|
|
388
|
+
} else {
|
|
389
|
+
// Remplacer les autres types de valeurs
|
|
390
|
+
merged[key] = sourceValue;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return merged;
|
|
395
|
+
};
|
|
396
|
+
// Composant ThemeProvider
|
|
368
397
|
const ThemeProvider = _ref => {
|
|
369
398
|
let {
|
|
370
399
|
theme = {
|
|
@@ -377,58 +406,69 @@
|
|
|
377
406
|
},
|
|
378
407
|
children
|
|
379
408
|
} = _ref;
|
|
409
|
+
// Fusion profonde des thèmes par défaut avec ceux fournis
|
|
410
|
+
const mergedTheme = deepMerge({
|
|
411
|
+
main: defaultThemeMain,
|
|
412
|
+
components: {}
|
|
413
|
+
}, theme);
|
|
414
|
+
// Fusion profonde des couleurs par défaut avec celles fournies
|
|
415
|
+
const mergedColors = deepMerge({
|
|
416
|
+
main: defaultColors,
|
|
417
|
+
palette: palette
|
|
418
|
+
}, colors);
|
|
419
|
+
/**
|
|
420
|
+
* Fonction pour récupérer une couleur basée sur un chemin en chaîne.
|
|
421
|
+
* Supporte les références imbriquées comme 'theme.button.primary.background'.
|
|
422
|
+
* @param name - Le nom de la couleur à récupérer.
|
|
423
|
+
* @returns La valeur de couleur résolue ou le nom original si non trouvé.
|
|
424
|
+
*/
|
|
380
425
|
const getColor = name => {
|
|
381
426
|
if (name === 'transparent') return name;
|
|
382
427
|
try {
|
|
383
|
-
// Si le nom commence par "theme.", nous recherchons dans les couleurs du thème
|
|
384
428
|
if (name.startsWith('theme.')) {
|
|
385
429
|
const keys = name.split('.');
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
430
|
+
let value = mergedTheme;
|
|
431
|
+
for (let i = 1; i < keys.length; i++) {
|
|
432
|
+
value = value[keys[i]];
|
|
433
|
+
if (value === undefined) {
|
|
434
|
+
console.warn(`Couleur "${name}" non trouvée dans le thème.`);
|
|
435
|
+
return name;
|
|
436
|
+
}
|
|
392
437
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
else if (name.startsWith('color.')) {
|
|
396
|
-
const keys = name.split('.'); // Retirer le préfixe "color."
|
|
397
|
-
if (colors.palette && colors.palette[keys[1]][keys[2]] !== undefined) {
|
|
398
|
-
return colors.palette[keys[1]][keys[2]];
|
|
399
|
-
} else if (colors.palette && colors.palette[keys[1]][parseInt(keys[2])] !== undefined) {
|
|
400
|
-
return colors.palette[keys[1]][parseInt(keys[2])];
|
|
401
|
-
} else if (colors.main && colors.main[keys[1]] !== undefined) {
|
|
402
|
-
return colors.main[keys[1]];
|
|
438
|
+
if (typeof value === 'string') {
|
|
439
|
+
return getColor(value); // Résoudre les références imbriquées
|
|
403
440
|
} else {
|
|
404
|
-
console.
|
|
441
|
+
console.warn(`La couleur "${name}" a résolu à une valeur non-string.`);
|
|
442
|
+
return name;
|
|
443
|
+
}
|
|
444
|
+
} else if (name.startsWith('color.')) {
|
|
445
|
+
const keys = name.split('.');
|
|
446
|
+
if (keys.length === 2) {
|
|
447
|
+
// Exemple : "color.white"
|
|
448
|
+
const colorName = keys[1];
|
|
449
|
+
return mergedColors.main[colorName] || name;
|
|
450
|
+
} else if (keys.length === 3) {
|
|
451
|
+
// Exemple : "color.palette.primary.500"
|
|
452
|
+
const [_, paletteName, variant] = keys;
|
|
453
|
+
if (mergedColors.palette[paletteName] && mergedColors.palette[paletteName][variant]) {
|
|
454
|
+
return mergedColors.palette[paletteName][variant];
|
|
455
|
+
} else {
|
|
456
|
+
console.warn(`Color ${_} non trouvée`);
|
|
457
|
+
}
|
|
405
458
|
}
|
|
459
|
+
console.warn(`Color "${name}" non trouvée dans la palette ou les couleurs principales.`);
|
|
406
460
|
}
|
|
407
|
-
} catch (e) {
|
|
408
|
-
|
|
461
|
+
} catch (e) {
|
|
462
|
+
console.error('Erreur lors de la récupération de la couleur:', e);
|
|
463
|
+
}
|
|
464
|
+
return name; // Retourner le nom original si non trouvé
|
|
409
465
|
};
|
|
466
|
+
|
|
410
467
|
return /*#__PURE__*/React__default.createElement(ThemeContext.Provider, {
|
|
411
468
|
value: {
|
|
412
469
|
getColor,
|
|
413
|
-
theme:
|
|
414
|
-
|
|
415
|
-
...defaultThemeMain,
|
|
416
|
-
...theme.main
|
|
417
|
-
},
|
|
418
|
-
components: {
|
|
419
|
-
...theme.components
|
|
420
|
-
}
|
|
421
|
-
},
|
|
422
|
-
colors: {
|
|
423
|
-
main: {
|
|
424
|
-
...defaultColors,
|
|
425
|
-
...colors.main
|
|
426
|
-
},
|
|
427
|
-
palette: {
|
|
428
|
-
...palette,
|
|
429
|
-
...colors.palette
|
|
430
|
-
}
|
|
431
|
-
}
|
|
470
|
+
theme: mergedTheme,
|
|
471
|
+
colors: mergedColors
|
|
432
472
|
}
|
|
433
473
|
}, children);
|
|
434
474
|
};
|