@gaddario98/react-core 2.0.0 → 2.0.2

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 (45) hide show
  1. package/dist/form/index.js +4566 -1
  2. package/dist/form/index.js.map +1 -1
  3. package/dist/form/index.mjs +4566 -1
  4. package/dist/form/index.mjs.map +1 -1
  5. package/dist/index.d.ts +2152 -7
  6. package/dist/index.js +20713 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.mjs +20713 -1
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/localization/index.js +318 -1
  11. package/dist/localization/index.js.map +1 -1
  12. package/dist/localization/index.mjs +318 -1
  13. package/dist/localization/index.mjs.map +1 -1
  14. package/dist/notifications/index.js +84 -0
  15. package/dist/notifications/index.js.map +1 -0
  16. package/dist/notifications/index.mjs +84 -0
  17. package/dist/notifications/index.mjs.map +1 -0
  18. package/dist/pages/index.js +4652 -1
  19. package/dist/pages/index.js.map +1 -1
  20. package/dist/pages/index.mjs +4652 -1
  21. package/dist/pages/index.mjs.map +1 -1
  22. package/dist/providers/index.d.ts +12 -1
  23. package/dist/providers/index.js +17 -1
  24. package/dist/providers/index.js.map +1 -1
  25. package/dist/providers/index.mjs +17 -1
  26. package/dist/providers/index.mjs.map +1 -1
  27. package/dist/queries/index.js +8903 -1
  28. package/dist/queries/index.js.map +1 -1
  29. package/dist/queries/index.mjs +8903 -1
  30. package/dist/queries/index.mjs.map +1 -1
  31. package/dist/state/index.js +1927 -1
  32. package/dist/state/index.js.map +1 -1
  33. package/dist/state/index.mjs +1927 -1
  34. package/dist/state/index.mjs.map +1 -1
  35. package/dist/utiles/index.d.ts +15 -1
  36. package/dist/utiles/index.js +2973 -1
  37. package/dist/utiles/index.js.map +1 -1
  38. package/dist/utiles/index.mjs +2973 -1
  39. package/dist/utiles/index.mjs.map +1 -1
  40. package/package.json +12 -6
  41. package/dist/form/index.d.ts +0 -1
  42. package/dist/localization/index.d.ts +0 -1
  43. package/dist/pages/index.d.ts +0 -1
  44. package/dist/queries/index.d.ts +0 -1
  45. package/dist/state/index.d.ts +0 -1
@@ -1 +1,318 @@
1
- 'use strict';var reactLocalization=require('@gaddario98/react-localization');Object.keys(reactLocalization).forEach(function(k){if(k!=='default'&&!Object.prototype.hasOwnProperty.call(exports,k))Object.defineProperty(exports,k,{enumerable:true,get:function(){return reactLocalization[k]}})});//# sourceMappingURL=index.js.map
1
+ 'use strict';var compilerRuntime=require('react/compiler-runtime'),reactState=require('@gaddario98/react-state');// Lazy initialization to avoid side effects at module load time
2
+ const _localizationConfig = {
3
+ currentLocale: 'it',
4
+ locales: {
5
+ it: {}
6
+ }
7
+ };
8
+ const {
9
+ atom: localizationConfigAtom,
10
+ useValue: useLocalizationConfigValue,
11
+ useState: useLocalizationConfigState,
12
+ useReset: useLocalizationConfigReset
13
+ } = reactState.atomStateGenerator({
14
+ key: 'localizationConfig',
15
+ defaultValue: _localizationConfig,
16
+ persist: true
17
+ });
18
+ /**
19
+ * Hook per gestire le operazioni di localization
20
+ */
21
+ const useLocalizationActions = () => {
22
+ const $ = compilerRuntime.c(10);
23
+ const [config, setConfig] = useLocalizationConfigState();
24
+ let t0;
25
+ let t1;
26
+ if ($[0] !== config || $[1] !== setConfig) {
27
+ t0 = (locale, resources) => {
28
+ setConfig(Object.assign(Object.assign({}, config), {
29
+ locales: Object.assign(Object.assign({}, config.locales), {
30
+ [locale]: resources
31
+ })
32
+ }));
33
+ };
34
+ t1 = locale_0 => {
35
+ setConfig(Object.assign(Object.assign({}, config), {
36
+ currentLocale: locale_0
37
+ }));
38
+ };
39
+ $[0] = config;
40
+ $[1] = setConfig;
41
+ $[2] = t0;
42
+ $[3] = t1;
43
+ } else {
44
+ t0 = $[2];
45
+ t1 = $[3];
46
+ }
47
+ let t2;
48
+ if ($[4] !== setConfig) {
49
+ t2 = (locale_1, resources_0) => {
50
+ setConfig({
51
+ currentLocale: locale_1,
52
+ locales: {
53
+ [locale_1]: resources_0
54
+ }
55
+ });
56
+ };
57
+ $[4] = setConfig;
58
+ $[5] = t2;
59
+ } else {
60
+ t2 = $[5];
61
+ }
62
+ let t3;
63
+ if ($[6] !== t0 || $[7] !== t1 || $[8] !== t2) {
64
+ t3 = {
65
+ addLocale: t0,
66
+ switchLocale: t1,
67
+ initializeLocale: t2
68
+ };
69
+ $[6] = t0;
70
+ $[7] = t1;
71
+ $[8] = t2;
72
+ $[9] = t3;
73
+ } else {
74
+ t3 = $[9];
75
+ }
76
+ return t3;
77
+ };/**
78
+ * Risolve una chiave di traduzione dalle risorse fornite.
79
+ * Supporta la notazione punto per oggetti annidati (es. 'common.buttons.save').
80
+ */
81
+ const getNestedValue = (obj, key) => {
82
+ return key.split('.').reduce((acc, part) => {
83
+ return acc && acc[part] !== undefined ? acc[part] : undefined;
84
+ }, obj);
85
+ };
86
+ /**
87
+ * Formatta un numero secondo le opzioni specificate
88
+ */
89
+ const formatNumber = (value, locale = 'en-US', formatOptions) => {
90
+ try {
91
+ return new Intl.NumberFormat(locale, formatOptions).format(value);
92
+ } catch (_a) {
93
+ return String(value);
94
+ }
95
+ };
96
+ /**
97
+ * Formatta una data secondo le opzioni specificate
98
+ */
99
+ const formatDate = (value, locale = 'en-US', formatOptions) => {
100
+ try {
101
+ const date = value instanceof Date ? value : new Date(value);
102
+ return new Intl.DateTimeFormat(locale, formatOptions).format(date);
103
+ } catch (_a) {
104
+ return String(value);
105
+ }
106
+ };
107
+ /**
108
+ * Formatta una valuta secondo le opzioni specificate
109
+ */
110
+ const formatCurrency = (value, locale = 'en-US', currency = 'USD', formatOptions) => {
111
+ try {
112
+ return new Intl.NumberFormat(locale, Object.assign({
113
+ style: 'currency',
114
+ currency
115
+ }, formatOptions)).format(value);
116
+ } catch (_a) {
117
+ return String(value);
118
+ }
119
+ };
120
+ /**
121
+ * Gestisce la pluralizzazione secondo ICU MessageFormat
122
+ * Formato: {{count, plural, =0{nessuno} one{un elemento} other{# elementi}}}
123
+ */
124
+ const handlePlural = (count, pattern) => {
125
+ // Estrae le varie forme: =0{...} one{...} few{...} many{...} other{...}
126
+ const forms = {};
127
+ const regex = /(=\d+|zero|one|two|few|many|other)\{([^}]*)\}/g;
128
+ let match;
129
+ while ((match = regex.exec(pattern)) !== null) {
130
+ forms[match[1]] = match[2];
131
+ }
132
+ // Controlla forme esatte prima (=0, =1, etc.)
133
+ const exactForm = forms[`=${count}`];
134
+ if (exactForm !== undefined) {
135
+ return exactForm.replace(/#/g, String(count));
136
+ }
137
+ // Regole di pluralizzazione semplificate (inglese-based)
138
+ let pluralForm;
139
+ if (count === 0 && forms.zero) {
140
+ pluralForm = forms.zero;
141
+ } else if (count === 1 && forms.one) {
142
+ pluralForm = forms.one;
143
+ } else if (count === 2 && forms.two) {
144
+ pluralForm = forms.two;
145
+ } else if (forms.other) {
146
+ pluralForm = forms.other;
147
+ } else {
148
+ pluralForm = pattern;
149
+ }
150
+ // Sostituisce # con il conteggio
151
+ return pluralForm.replace(/#/g, String(count));
152
+ };
153
+ /**
154
+ * Gestisce la selezione secondo ICU MessageFormat
155
+ * Formato: {{gender, select, male{lui} female{lei} other{loro}}}
156
+ */
157
+ const handleSelect = (value, pattern) => {
158
+ const forms = {};
159
+ const regex = /(\w+)\{([^}]*)\}/g;
160
+ let match;
161
+ while ((match = regex.exec(pattern)) !== null) {
162
+ forms[match[1]] = match[2];
163
+ }
164
+ return forms[value] || forms.other || pattern;
165
+ };
166
+ /**
167
+ * Effettua l'interpolazione avanzata dei parametri nella stringa di traduzione.
168
+ * Supporta:
169
+ * - Interpolazione semplice: {{name}}
170
+ * - Formattazione numeri: {{count, number}}
171
+ * - Formattazione date: {{date, date}}
172
+ * - Formattazione valuta: {{price, currency}}
173
+ * - Pluralizzazione: {{count, plural, =0{nessuno} one{un elemento} other{# elementi}}}
174
+ * - Selezione: {{gender, select, male{lui} female{lei} other{loro}}}
175
+ */
176
+ const interpolate = (text, options, locale = 'en-US') => {
177
+ if (!options) return text;
178
+ // Pattern per catturare interpolazioni complesse: {{key}} o {{key, format, pattern}}
179
+ return text.replace(/\{\{([^}]+)\}\}/g, (match, content) => {
180
+ var _a, _b;
181
+ const parts = content.split(',').map(p => p.trim());
182
+ const key = parts[0];
183
+ const value = options[key];
184
+ if (value === undefined) {
185
+ return match; // Mantiene il placeholder se il valore non esiste
186
+ }
187
+ // Nessun formato specificato - interpolazione semplice
188
+ if (parts.length === 1) {
189
+ return String(value);
190
+ }
191
+ const format = parts[1];
192
+ const formatOpts = (_a = options.formatOptions) === null || _a === void 0 ? void 0 : _a[key];
193
+ switch (format) {
194
+ case 'number':
195
+ {
196
+ if (typeof value !== 'number') return String(value);
197
+ return formatNumber(value, locale, formatOpts === null || formatOpts === void 0 ? void 0 : formatOpts.number);
198
+ }
199
+ case 'date':
200
+ {
201
+ return formatDate(value, locale, formatOpts === null || formatOpts === void 0 ? void 0 : formatOpts.date);
202
+ }
203
+ case 'currency':
204
+ {
205
+ if (typeof value !== 'number') return String(value);
206
+ const currency = ((_b = formatOpts === null || formatOpts === void 0 ? void 0 : formatOpts.currency) === null || _b === void 0 ? void 0 : _b.currency) || 'USD';
207
+ return formatCurrency(value, locale, currency, formatOpts === null || formatOpts === void 0 ? void 0 : formatOpts.currency);
208
+ }
209
+ case 'plural':
210
+ {
211
+ if (typeof value !== 'number') return String(value);
212
+ const pattern = parts.slice(2).join(',').trim();
213
+ return handlePlural(value, pattern);
214
+ }
215
+ case 'select':
216
+ {
217
+ const pattern = parts.slice(2).join(',').trim();
218
+ return handleSelect(String(value), pattern);
219
+ }
220
+ default:
221
+ return String(value);
222
+ }
223
+ });
224
+ };
225
+ /**
226
+ * Funzione core per risolvere una traduzione.
227
+ */
228
+ const resolveTranslation = (key, resources, options, locale = 'en-US') => {
229
+ const rawValue = getNestedValue(resources, key);
230
+ // Se non trovato, usa defaultValue se presente, altrimenti la chiave stessa
231
+ if (rawValue === undefined) {
232
+ if (options && options.defaultValue) {
233
+ return interpolate(options.defaultValue, options, locale);
234
+ }
235
+ return key;
236
+ }
237
+ return interpolate(String(rawValue), options, locale);
238
+ };const useTranslation = _ns => {
239
+ const $ = compilerRuntime.c(7);
240
+ const {
241
+ currentLocale,
242
+ locales
243
+ } = useLocalizationConfigValue();
244
+ const resources = locales[currentLocale];
245
+ let t0;
246
+ if ($[0] !== _ns || $[1] !== currentLocale || $[2] !== resources) {
247
+ t0 = (key, options) => resolveTranslation(_ns ? `${_ns}.${key}` : key, resources, options, currentLocale);
248
+ $[0] = _ns;
249
+ $[1] = currentLocale;
250
+ $[2] = resources;
251
+ $[3] = t0;
252
+ } else {
253
+ t0 = $[3];
254
+ }
255
+ const t = t0;
256
+ let t1;
257
+ if ($[4] !== currentLocale || $[5] !== t) {
258
+ t1 = {
259
+ t,
260
+ locale: currentLocale
261
+ };
262
+ $[4] = currentLocale;
263
+ $[5] = t;
264
+ $[6] = t1;
265
+ } else {
266
+ t1 = $[6];
267
+ }
268
+ return t1;
269
+ };/**
270
+ * Crea un'istanza di traduzione per l'uso lato server (o fuori dai componenti React).
271
+ */
272
+ const createServerTranslator = (resources, locale = 'it') => {
273
+ const t = (key, options) => {
274
+ return resolveTranslation(key, resources, options);
275
+ };
276
+ return {
277
+ t,
278
+ locale
279
+ };
280
+ };/**
281
+ * Hook per tradurre testi che si adatta al sistema di traduzione interno.
282
+ * Wrapper di retro-compatibilità per useTranslation.
283
+ *
284
+ * @param ns - Namespace opzionale (ignorato nella nuova implementazione)
285
+ * @returns Un oggetto con la funzione traslateText (e alias t)
286
+ */
287
+ const useTranslatedText = ns => {
288
+ const $ = compilerRuntime.c(4);
289
+ const {
290
+ t
291
+ } = useTranslation(ns);
292
+ let t0;
293
+ if ($[0] !== t) {
294
+ t0 = (text, options) => {
295
+ if (!text) {
296
+ return "";
297
+ }
298
+ return t(text, options);
299
+ };
300
+ $[0] = t;
301
+ $[1] = t0;
302
+ } else {
303
+ t0 = $[1];
304
+ }
305
+ const traslateText = t0;
306
+ let t1;
307
+ if ($[2] !== traslateText) {
308
+ t1 = {
309
+ traslateText,
310
+ t: traslateText
311
+ };
312
+ $[2] = traslateText;
313
+ $[3] = t1;
314
+ } else {
315
+ t1 = $[3];
316
+ }
317
+ return t1;
318
+ };exports.createServerTranslator=createServerTranslator;exports.localizationConfigAtom=localizationConfigAtom;exports.resolveTranslation=resolveTranslation;exports.useLocalizationActions=useLocalizationActions;exports.useLocalizationConfigReset=useLocalizationConfigReset;exports.useLocalizationConfigState=useLocalizationConfigState;exports.useLocalizationConfigValue=useLocalizationConfigValue;exports.useTranslatedText=useTranslatedText;exports.useTranslation=useTranslation;//# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.js","sources":["../../localization/config.ts","../../localization/core.ts","../../localization/hooks.ts","../../localization/server.ts","../../localization/useTranslatedText.ts"],"sourcesContent":["import { atomStateGenerator } from '@gaddario98/react-state'\nimport type { Locale, TranslationResources } from './types'\n\nexport interface LocalizationConfigProps {\n currentLocale: Locale\n locales: Record<Locale, TranslationResources>\n}\n\n// Lazy initialization to avoid side effects at module load time\nconst _localizationConfig: LocalizationConfigProps = {\n currentLocale: 'it',\n locales: {\n it: {},\n },\n}\n\nexport const {\n atom: localizationConfigAtom,\n useValue: useLocalizationConfigValue,\n useState: useLocalizationConfigState,\n useReset: useLocalizationConfigReset,\n} = atomStateGenerator<LocalizationConfigProps>({\n key: 'localizationConfig',\n defaultValue: _localizationConfig,\n persist: true,\n})\n\n/**\n * Hook per gestire le operazioni di localization\n */\nexport const useLocalizationActions = () => {\n const [config, setConfig] = useLocalizationConfigState()\n return {\n /**\n * Aggiunge o aggiorna una locale con le sue risorse\n */\n addLocale: (locale: Locale, resources: TranslationResources) => {\n setConfig({\n ...config,\n locales: {\n ...config.locales,\n [locale]: resources,\n },\n })\n },\n\n /**\n * Switch alla locale specificata\n */\n switchLocale: (locale: Locale) => {\n setConfig({\n ...config,\n currentLocale: locale,\n })\n },\n\n /**\n * Inizializza con una locale di default\n */\n initializeLocale: (locale: Locale, resources: TranslationResources) => {\n setConfig({\n currentLocale: locale,\n locales: {\n [locale]: resources,\n },\n })\n },\n }\n}\n","import type { TranslationOptions, TranslationResources } from './types'\n\n/**\n * Risolve una chiave di traduzione dalle risorse fornite.\n * Supporta la notazione punto per oggetti annidati (es. 'common.buttons.save').\n */\nconst getNestedValue = (obj: any, key: string): string | undefined => {\n return key.split('.').reduce((acc, part) => {\n return acc && acc[part] !== undefined ? acc[part] : undefined\n }, obj)\n}\n\n/**\n * Formatta un numero secondo le opzioni specificate\n */\nconst formatNumber = (\n value: number,\n locale: string = 'en-US',\n formatOptions?: Intl.NumberFormatOptions\n): string => {\n try {\n return new Intl.NumberFormat(locale, formatOptions).format(value)\n } catch {\n return String(value)\n }\n}\n\n/**\n * Formatta una data secondo le opzioni specificate\n */\nconst formatDate = (\n value: Date | number | string,\n locale: string = 'en-US',\n formatOptions?: Intl.DateTimeFormatOptions\n): string => {\n try {\n const date = value instanceof Date ? value : new Date(value)\n return new Intl.DateTimeFormat(locale, formatOptions).format(date)\n } catch {\n return String(value)\n }\n}\n\n/**\n * Formatta una valuta secondo le opzioni specificate\n */\nconst formatCurrency = (\n value: number,\n locale: string = 'en-US',\n currency: string = 'USD',\n formatOptions?: Intl.NumberFormatOptions\n): string => {\n try {\n return new Intl.NumberFormat(locale, {\n style: 'currency',\n currency,\n ...formatOptions,\n }).format(value)\n } catch {\n return String(value)\n }\n}\n\n/**\n * Gestisce la pluralizzazione secondo ICU MessageFormat\n * Formato: {{count, plural, =0{nessuno} one{un elemento} other{# elementi}}}\n */\nconst handlePlural = (count: number, pattern: string): string => {\n // Estrae le varie forme: =0{...} one{...} few{...} many{...} other{...}\n const forms: Record<string, string> = {}\n const regex = /(=\\d+|zero|one|two|few|many|other)\\{([^}]*)\\}/g\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(pattern)) !== null) {\n forms[match[1]] = match[2]\n }\n\n // Controlla forme esatte prima (=0, =1, etc.)\n const exactForm = forms[`=${count}`]\n if (exactForm !== undefined) {\n return exactForm.replace(/#/g, String(count))\n }\n\n // Regole di pluralizzazione semplificate (inglese-based)\n let pluralForm: string\n if (count === 0 && forms.zero) {\n pluralForm = forms.zero\n } else if (count === 1 && forms.one) {\n pluralForm = forms.one\n } else if (count === 2 && forms.two) {\n pluralForm = forms.two\n } else if (forms.other) {\n pluralForm = forms.other\n } else {\n pluralForm = pattern\n }\n\n // Sostituisce # con il conteggio\n return pluralForm.replace(/#/g, String(count))\n}\n\n/**\n * Gestisce la selezione secondo ICU MessageFormat\n * Formato: {{gender, select, male{lui} female{lei} other{loro}}}\n */\nconst handleSelect = (value: string, pattern: string): string => {\n const forms: Record<string, string> = {}\n const regex = /(\\w+)\\{([^}]*)\\}/g\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(pattern)) !== null) {\n forms[match[1]] = match[2]\n }\n\n return forms[value] || forms.other || pattern\n}\n\n/**\n * Effettua l'interpolazione avanzata dei parametri nella stringa di traduzione.\n * Supporta:\n * - Interpolazione semplice: {{name}}\n * - Formattazione numeri: {{count, number}}\n * - Formattazione date: {{date, date}}\n * - Formattazione valuta: {{price, currency}}\n * - Pluralizzazione: {{count, plural, =0{nessuno} one{un elemento} other{# elementi}}}\n * - Selezione: {{gender, select, male{lui} female{lei} other{loro}}}\n */\nconst interpolate = (\n text: string,\n options?: TranslationOptions,\n locale: string = 'en-US'\n): string => {\n if (!options) return text\n\n // Pattern per catturare interpolazioni complesse: {{key}} o {{key, format, pattern}}\n return text.replace(/\\{\\{([^}]+)\\}\\}/g, (match, content) => {\n const parts = content.split(',').map((p: string) => p.trim())\n const key = parts[0]\n const value = options[key]\n\n if (value === undefined) {\n return match // Mantiene il placeholder se il valore non esiste\n }\n\n // Nessun formato specificato - interpolazione semplice\n if (parts.length === 1) {\n return String(value)\n }\n\n const format = parts[1]\n const formatOpts = options.formatOptions?.[key]\n\n switch (format) {\n case 'number': {\n if (typeof value !== 'number') return String(value)\n return formatNumber(value, locale, formatOpts?.number)\n }\n\n case 'date': {\n return formatDate(value, locale, formatOpts?.date)\n }\n\n case 'currency': {\n if (typeof value !== 'number') return String(value)\n const currency = formatOpts?.currency?.currency || 'USD'\n return formatCurrency(value, locale, currency, formatOpts?.currency)\n }\n\n case 'plural': {\n if (typeof value !== 'number') return String(value)\n const pattern = parts.slice(2).join(',').trim()\n return handlePlural(value, pattern)\n }\n\n case 'select': {\n const pattern = parts.slice(2).join(',').trim()\n return handleSelect(String(value), pattern)\n }\n\n default:\n return String(value)\n }\n })\n}\n\n/**\n * Funzione core per risolvere una traduzione.\n */\nexport const resolveTranslation = (\n key: string,\n resources: TranslationResources,\n options?: TranslationOptions,\n locale: string = 'en-US'\n): string => {\n const rawValue = getNestedValue(resources, key)\n\n // Se non trovato, usa defaultValue se presente, altrimenti la chiave stessa\n if (rawValue === undefined) {\n if (options && options.defaultValue) {\n return interpolate(options.defaultValue, options, locale)\n }\n return key\n }\n\n return interpolate(String(rawValue), options, locale)\n}\n","import { useMemo } from 'react'\nimport { useLocalizationConfigValue } from './config'\nimport { resolveTranslation } from './core';\nimport type { Locale, TranslateFunction } from './types'\n\nexport const useTranslation = (\n _ns?: string,\n): { t: TranslateFunction; locale: Locale } => {\n const { currentLocale, locales } = useLocalizationConfigValue()\n const resources = useMemo(\n () => locales[currentLocale],\n [locales, currentLocale],\n )\n\n const t = useMemo<TranslateFunction>(() => {\n return (key, options) =>\n resolveTranslation(\n _ns ? `${_ns}.${key}` : key,\n resources,\n options,\n currentLocale,\n )\n }, [resources, currentLocale, _ns])\n\n return { t, locale: currentLocale }\n}\n","import { resolveTranslation } from './core'\nimport type { Locale, TranslateFunction, TranslationResources } from './types'\n\n/**\n * Crea un'istanza di traduzione per l'uso lato server (o fuori dai componenti React).\n */\nexport const createServerTranslator = (\n resources: TranslationResources,\n locale: Locale = 'it', // Default locale hardcoded per ora, o passato come argomento\n): { t: TranslateFunction; locale: Locale } => {\n const t: TranslateFunction = (key, options) => {\n return resolveTranslation(key, resources, options)\n }\n\n return { t, locale }\n}\n","import { useCallback } from 'react'\nimport { useTranslation } from './hooks'\nimport type { TranslationOptions } from './types'\n\n// Mantengo l'interfaccia TranslationFunction per compatibilità\nexport type TranslationFunction = (\n key: string,\n options?: TranslationOptions,\n) => string\n\n/**\n * Hook per tradurre testi che si adatta al sistema di traduzione interno.\n * Wrapper di retro-compatibilità per useTranslation.\n *\n * @param ns - Namespace opzionale (ignorato nella nuova implementazione)\n * @returns Un oggetto con la funzione traslateText (e alias t)\n */\nexport const useTranslatedText = (ns?: string) => {\n const { t } = useTranslation(ns)\n\n const traslateText = useCallback(\n (text: string, options?: TranslationOptions) => {\n if (!text) return ''\n return t(text, options)\n },\n [t],\n )\n\n return { traslateText, t: traslateText }\n}\n"],"names":["_localizationConfig","currentLocale","locales","it","atom","localizationConfigAtom","useValue","useLocalizationConfigValue","useState","useLocalizationConfigState","useReset","useLocalizationConfigReset","atomStateGenerator","key","defaultValue","persist","useLocalizationActions","$","_c","config","setConfig","t0","t1","locale","resources","Object","assign","locale_0","t2","locale_1","resources_0","t3","addLocale","switchLocale","initializeLocale","getNestedValue","obj","split","reduce","acc","part","undefined","formatNumber","value","formatOptions","Intl","NumberFormat","format","_a","String","formatDate","date","Date","DateTimeFormat","formatCurrency","currency","style","handlePlural","count","pattern","forms","regex","match","exec","exactForm","replace","pluralForm","zero","one","two","other","handleSelect","interpolate","text","options","content","parts","map","p","trim","length","formatOpts","number","_b","slice","join","resolveTranslation","rawValue","useTranslation","_ns","t","createServerTranslator","useTranslatedText","ns","traslateText"],"mappings":"iHAQA;AACA,MAAMA,mBAAmB,GAA4B;AACnDC,EAAAA,aAAa,EAAE,IAAI;AACnBC,EAAAA,OAAO,EAAE;AACPC,IAAAA,EAAE,EAAE;AACL;CACF;AAEM,MAAM;AACXC,EAAAA,IAAI,EAAEC,sBAAsB;AAC5BC,EAAAA,QAAQ,EAAEC,0BAA0B;AACpCC,EAAAA,QAAQ,EAAEC,0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AEkD,OAAO,CAAC;EACpD,CAAC;EAED,OAAO;IAAEgB,CAAC;AAAEnE,IAAAA;GAAQ;AACtB,ECLA;;;;;;AAMG;AACI,MAAMqE,iBAAiB,GAAGC,EAAA,IAAA;EAAA,MAAA5E,CAAA,GAAAC,iBAAA,CAAA,CAAA,CAAA;AAC/B,EAAA,MAAA;AAAAwE,IAAAA;GAAA,GAAcF,cAAc,CAACK,EAAE,CAAC;AAAA,EAAA,IAAAxE,EAAA;EAAA,IAAAJ,CAAA,QAAAyE,CAAA,EAAA;AAG9BrE,IAAAA,EAAA,GAAAA,CAAAoD,IAAA,EAAAC,OAAA,KAAA;AACE,MAAA,IAAI,CAACD,IAAI,EAAA;AAAA,QAAA,OAAS,EAAE;AAAA,MAAA;AAAA,MAAA,OACbiB,CAAC,CAACjB,IAAI,EAAEC,OAAO,CAAC;IAAA,CACxB;AAAAzD,IAAAA,CAAA,MAAAyE,CAAA;AAAAzE,IAAAA,CAAA,MAAAI,EAAA;AAAA,EAAA,CAAA,MAAA;AAAAA,IAAAA,EAAA,GAAAJ,CAAA,CAAA,CAAA,CAAA;AAAA,EAAA;EAJH,MAAA6E,YAAA,GAAqBzE,EAMpB;AAAA,EAAA,IAAAC,EAAA;EAAA,IAAAL,CAAA,QAAA6E,YAAA,EAAA;IAEMxE,EAAA,GAAA;MAAAwE,YAAA;AAAAJ,MAAAA,CAAA,EAAmBI;KAAc;AAAA7E,IAAAA,CAAA,MAAA6E,YAAA;AAAA7E,IAAAA,CAAA,MAAAK,EAAA;AAAA,EAAA,CAAA,MAAA;AAAAA,IAAAA,EAAA,GAAAL,CAAA,CAAA,CAAA,CAAA;AAAA,EAAA;AAAA,EAAA,OAAjCK,EAAiC;AAAA"}
@@ -1 +1,318 @@
1
- export*from'@gaddario98/react-localization';//# sourceMappingURL=index.mjs.map
1
+ import {c}from'react/compiler-runtime';import {atomStateGenerator}from'@gaddario98/react-state';// Lazy initialization to avoid side effects at module load time
2
+ const _localizationConfig = {
3
+ currentLocale: 'it',
4
+ locales: {
5
+ it: {}
6
+ }
7
+ };
8
+ const {
9
+ atom: localizationConfigAtom,
10
+ useValue: useLocalizationConfigValue,
11
+ useState: useLocalizationConfigState,
12
+ useReset: useLocalizationConfigReset
13
+ } = atomStateGenerator({
14
+ key: 'localizationConfig',
15
+ defaultValue: _localizationConfig,
16
+ persist: true
17
+ });
18
+ /**
19
+ * Hook per gestire le operazioni di localization
20
+ */
21
+ const useLocalizationActions = () => {
22
+ const $ = c(10);
23
+ const [config, setConfig] = useLocalizationConfigState();
24
+ let t0;
25
+ let t1;
26
+ if ($[0] !== config || $[1] !== setConfig) {
27
+ t0 = (locale, resources) => {
28
+ setConfig(Object.assign(Object.assign({}, config), {
29
+ locales: Object.assign(Object.assign({}, config.locales), {
30
+ [locale]: resources
31
+ })
32
+ }));
33
+ };
34
+ t1 = locale_0 => {
35
+ setConfig(Object.assign(Object.assign({}, config), {
36
+ currentLocale: locale_0
37
+ }));
38
+ };
39
+ $[0] = config;
40
+ $[1] = setConfig;
41
+ $[2] = t0;
42
+ $[3] = t1;
43
+ } else {
44
+ t0 = $[2];
45
+ t1 = $[3];
46
+ }
47
+ let t2;
48
+ if ($[4] !== setConfig) {
49
+ t2 = (locale_1, resources_0) => {
50
+ setConfig({
51
+ currentLocale: locale_1,
52
+ locales: {
53
+ [locale_1]: resources_0
54
+ }
55
+ });
56
+ };
57
+ $[4] = setConfig;
58
+ $[5] = t2;
59
+ } else {
60
+ t2 = $[5];
61
+ }
62
+ let t3;
63
+ if ($[6] !== t0 || $[7] !== t1 || $[8] !== t2) {
64
+ t3 = {
65
+ addLocale: t0,
66
+ switchLocale: t1,
67
+ initializeLocale: t2
68
+ };
69
+ $[6] = t0;
70
+ $[7] = t1;
71
+ $[8] = t2;
72
+ $[9] = t3;
73
+ } else {
74
+ t3 = $[9];
75
+ }
76
+ return t3;
77
+ };/**
78
+ * Risolve una chiave di traduzione dalle risorse fornite.
79
+ * Supporta la notazione punto per oggetti annidati (es. 'common.buttons.save').
80
+ */
81
+ const getNestedValue = (obj, key) => {
82
+ return key.split('.').reduce((acc, part) => {
83
+ return acc && acc[part] !== undefined ? acc[part] : undefined;
84
+ }, obj);
85
+ };
86
+ /**
87
+ * Formatta un numero secondo le opzioni specificate
88
+ */
89
+ const formatNumber = (value, locale = 'en-US', formatOptions) => {
90
+ try {
91
+ return new Intl.NumberFormat(locale, formatOptions).format(value);
92
+ } catch (_a) {
93
+ return String(value);
94
+ }
95
+ };
96
+ /**
97
+ * Formatta una data secondo le opzioni specificate
98
+ */
99
+ const formatDate = (value, locale = 'en-US', formatOptions) => {
100
+ try {
101
+ const date = value instanceof Date ? value : new Date(value);
102
+ return new Intl.DateTimeFormat(locale, formatOptions).format(date);
103
+ } catch (_a) {
104
+ return String(value);
105
+ }
106
+ };
107
+ /**
108
+ * Formatta una valuta secondo le opzioni specificate
109
+ */
110
+ const formatCurrency = (value, locale = 'en-US', currency = 'USD', formatOptions) => {
111
+ try {
112
+ return new Intl.NumberFormat(locale, Object.assign({
113
+ style: 'currency',
114
+ currency
115
+ }, formatOptions)).format(value);
116
+ } catch (_a) {
117
+ return String(value);
118
+ }
119
+ };
120
+ /**
121
+ * Gestisce la pluralizzazione secondo ICU MessageFormat
122
+ * Formato: {{count, plural, =0{nessuno} one{un elemento} other{# elementi}}}
123
+ */
124
+ const handlePlural = (count, pattern) => {
125
+ // Estrae le varie forme: =0{...} one{...} few{...} many{...} other{...}
126
+ const forms = {};
127
+ const regex = /(=\d+|zero|one|two|few|many|other)\{([^}]*)\}/g;
128
+ let match;
129
+ while ((match = regex.exec(pattern)) !== null) {
130
+ forms[match[1]] = match[2];
131
+ }
132
+ // Controlla forme esatte prima (=0, =1, etc.)
133
+ const exactForm = forms[`=${count}`];
134
+ if (exactForm !== undefined) {
135
+ return exactForm.replace(/#/g, String(count));
136
+ }
137
+ // Regole di pluralizzazione semplificate (inglese-based)
138
+ let pluralForm;
139
+ if (count === 0 && forms.zero) {
140
+ pluralForm = forms.zero;
141
+ } else if (count === 1 && forms.one) {
142
+ pluralForm = forms.one;
143
+ } else if (count === 2 && forms.two) {
144
+ pluralForm = forms.two;
145
+ } else if (forms.other) {
146
+ pluralForm = forms.other;
147
+ } else {
148
+ pluralForm = pattern;
149
+ }
150
+ // Sostituisce # con il conteggio
151
+ return pluralForm.replace(/#/g, String(count));
152
+ };
153
+ /**
154
+ * Gestisce la selezione secondo ICU MessageFormat
155
+ * Formato: {{gender, select, male{lui} female{lei} other{loro}}}
156
+ */
157
+ const handleSelect = (value, pattern) => {
158
+ const forms = {};
159
+ const regex = /(\w+)\{([^}]*)\}/g;
160
+ let match;
161
+ while ((match = regex.exec(pattern)) !== null) {
162
+ forms[match[1]] = match[2];
163
+ }
164
+ return forms[value] || forms.other || pattern;
165
+ };
166
+ /**
167
+ * Effettua l'interpolazione avanzata dei parametri nella stringa di traduzione.
168
+ * Supporta:
169
+ * - Interpolazione semplice: {{name}}
170
+ * - Formattazione numeri: {{count, number}}
171
+ * - Formattazione date: {{date, date}}
172
+ * - Formattazione valuta: {{price, currency}}
173
+ * - Pluralizzazione: {{count, plural, =0{nessuno} one{un elemento} other{# elementi}}}
174
+ * - Selezione: {{gender, select, male{lui} female{lei} other{loro}}}
175
+ */
176
+ const interpolate = (text, options, locale = 'en-US') => {
177
+ if (!options) return text;
178
+ // Pattern per catturare interpolazioni complesse: {{key}} o {{key, format, pattern}}
179
+ return text.replace(/\{\{([^}]+)\}\}/g, (match, content) => {
180
+ var _a, _b;
181
+ const parts = content.split(',').map(p => p.trim());
182
+ const key = parts[0];
183
+ const value = options[key];
184
+ if (value === undefined) {
185
+ return match; // Mantiene il placeholder se il valore non esiste
186
+ }
187
+ // Nessun formato specificato - interpolazione semplice
188
+ if (parts.length === 1) {
189
+ return String(value);
190
+ }
191
+ const format = parts[1];
192
+ const formatOpts = (_a = options.formatOptions) === null || _a === void 0 ? void 0 : _a[key];
193
+ switch (format) {
194
+ case 'number':
195
+ {
196
+ if (typeof value !== 'number') return String(value);
197
+ return formatNumber(value, locale, formatOpts === null || formatOpts === void 0 ? void 0 : formatOpts.number);
198
+ }
199
+ case 'date':
200
+ {
201
+ return formatDate(value, locale, formatOpts === null || formatOpts === void 0 ? void 0 : formatOpts.date);
202
+ }
203
+ case 'currency':
204
+ {
205
+ if (typeof value !== 'number') return String(value);
206
+ const currency = ((_b = formatOpts === null || formatOpts === void 0 ? void 0 : formatOpts.currency) === null || _b === void 0 ? void 0 : _b.currency) || 'USD';
207
+ return formatCurrency(value, locale, currency, formatOpts === null || formatOpts === void 0 ? void 0 : formatOpts.currency);
208
+ }
209
+ case 'plural':
210
+ {
211
+ if (typeof value !== 'number') return String(value);
212
+ const pattern = parts.slice(2).join(',').trim();
213
+ return handlePlural(value, pattern);
214
+ }
215
+ case 'select':
216
+ {
217
+ const pattern = parts.slice(2).join(',').trim();
218
+ return handleSelect(String(value), pattern);
219
+ }
220
+ default:
221
+ return String(value);
222
+ }
223
+ });
224
+ };
225
+ /**
226
+ * Funzione core per risolvere una traduzione.
227
+ */
228
+ const resolveTranslation = (key, resources, options, locale = 'en-US') => {
229
+ const rawValue = getNestedValue(resources, key);
230
+ // Se non trovato, usa defaultValue se presente, altrimenti la chiave stessa
231
+ if (rawValue === undefined) {
232
+ if (options && options.defaultValue) {
233
+ return interpolate(options.defaultValue, options, locale);
234
+ }
235
+ return key;
236
+ }
237
+ return interpolate(String(rawValue), options, locale);
238
+ };const useTranslation = _ns => {
239
+ const $ = c(7);
240
+ const {
241
+ currentLocale,
242
+ locales
243
+ } = useLocalizationConfigValue();
244
+ const resources = locales[currentLocale];
245
+ let t0;
246
+ if ($[0] !== _ns || $[1] !== currentLocale || $[2] !== resources) {
247
+ t0 = (key, options) => resolveTranslation(_ns ? `${_ns}.${key}` : key, resources, options, currentLocale);
248
+ $[0] = _ns;
249
+ $[1] = currentLocale;
250
+ $[2] = resources;
251
+ $[3] = t0;
252
+ } else {
253
+ t0 = $[3];
254
+ }
255
+ const t = t0;
256
+ let t1;
257
+ if ($[4] !== currentLocale || $[5] !== t) {
258
+ t1 = {
259
+ t,
260
+ locale: currentLocale
261
+ };
262
+ $[4] = currentLocale;
263
+ $[5] = t;
264
+ $[6] = t1;
265
+ } else {
266
+ t1 = $[6];
267
+ }
268
+ return t1;
269
+ };/**
270
+ * Crea un'istanza di traduzione per l'uso lato server (o fuori dai componenti React).
271
+ */
272
+ const createServerTranslator = (resources, locale = 'it') => {
273
+ const t = (key, options) => {
274
+ return resolveTranslation(key, resources, options);
275
+ };
276
+ return {
277
+ t,
278
+ locale
279
+ };
280
+ };/**
281
+ * Hook per tradurre testi che si adatta al sistema di traduzione interno.
282
+ * Wrapper di retro-compatibilità per useTranslation.
283
+ *
284
+ * @param ns - Namespace opzionale (ignorato nella nuova implementazione)
285
+ * @returns Un oggetto con la funzione traslateText (e alias t)
286
+ */
287
+ const useTranslatedText = ns => {
288
+ const $ = c(4);
289
+ const {
290
+ t
291
+ } = useTranslation(ns);
292
+ let t0;
293
+ if ($[0] !== t) {
294
+ t0 = (text, options) => {
295
+ if (!text) {
296
+ return "";
297
+ }
298
+ return t(text, options);
299
+ };
300
+ $[0] = t;
301
+ $[1] = t0;
302
+ } else {
303
+ t0 = $[1];
304
+ }
305
+ const traslateText = t0;
306
+ let t1;
307
+ if ($[2] !== traslateText) {
308
+ t1 = {
309
+ traslateText,
310
+ t: traslateText
311
+ };
312
+ $[2] = traslateText;
313
+ $[3] = t1;
314
+ } else {
315
+ t1 = $[3];
316
+ }
317
+ return t1;
318
+ };export{createServerTranslator,localizationConfigAtom,resolveTranslation,useLocalizationActions,useLocalizationConfigReset,useLocalizationConfigState,useLocalizationConfigValue,useTranslatedText,useTranslation};//# sourceMappingURL=index.mjs.map