@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 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.mjs","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":"gGAQA;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,0BAA0B;AACpCC,EAAAA,QAAQ,EAAEC;AAA0B,CACrC,GAAGC,kBAAkB,CAA0B;AAC9CC,EAAAA,GAAG,EAAE,oBAAoB;AACzBC,EAAAA,YAAY,EAAEd,mBAAmB;AACjCe,EAAAA,OAAO,EAAE;AACV,CAAA;AAED;;AAEG;AACI,MAAMC,sBAAsB,GAAGA,MAAA;EAAA,MAAAC,CAAA,GAAAC,CAAA,CAAA,EAAA,CAAA;AACpC,E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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"}
@@ -0,0 +1,84 @@
1
+ 'use strict';var compilerRuntime=require('react/compiler-runtime'),react=require('react'),reactState=require('@gaddario98/react-state');const {
2
+ atom: notificationAtom,
3
+ useValue: useNotificationValue,
4
+ useState: useNotificationState
5
+ } = reactState.atomStateGenerator({
6
+ defaultValue: null,
7
+ key: 'reactNotificationAtom',
8
+ persist: false
9
+ });const useNotificationSet = () => {
10
+ const [, setValue] = useNotificationState();
11
+ return setValue;
12
+ };
13
+ const useNotification = t0 => {
14
+ const $ = compilerRuntime.c(10);
15
+ const ns = t0 === undefined ? "notifications" : t0;
16
+ const setNotification = useNotificationSet();
17
+ let t1;
18
+ if ($[0] !== ns || $[1] !== setNotification) {
19
+ t1 = {
20
+ setNotification,
21
+ ns
22
+ };
23
+ $[0] = ns;
24
+ $[1] = setNotification;
25
+ $[2] = t1;
26
+ } else {
27
+ t1 = $[2];
28
+ }
29
+ const ref = react.useRef(t1);
30
+ let t2;
31
+ let t3;
32
+ if ($[3] !== ns || $[4] !== setNotification) {
33
+ t2 = () => {
34
+ ref.current = {
35
+ setNotification,
36
+ ns
37
+ };
38
+ };
39
+ t3 = [setNotification, ns];
40
+ $[3] = ns;
41
+ $[4] = setNotification;
42
+ $[5] = t2;
43
+ $[6] = t3;
44
+ } else {
45
+ t2 = $[5];
46
+ t3 = $[6];
47
+ }
48
+ react.useEffect(t2, t3);
49
+ let t4;
50
+ if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
51
+ t4 = notification => {
52
+ ref.current.setNotification(Object.assign(Object.assign({
53
+ ns: ref.current.ns
54
+ }, notification), {
55
+ id: Date.now().toString()
56
+ }));
57
+ };
58
+ $[7] = t4;
59
+ } else {
60
+ t4 = $[7];
61
+ }
62
+ const showNotification = t4;
63
+ let t5;
64
+ if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
65
+ t5 = () => {
66
+ ref.current.setNotification(null);
67
+ };
68
+ $[8] = t5;
69
+ } else {
70
+ t5 = $[8];
71
+ }
72
+ const clearNotification = t5;
73
+ let t6;
74
+ if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
75
+ t6 = {
76
+ showNotification,
77
+ clearNotification
78
+ };
79
+ $[9] = t6;
80
+ } else {
81
+ t6 = $[9];
82
+ }
83
+ return t6;
84
+ };exports.notificationAtom=notificationAtom;exports.useNotification=useNotification;exports.useNotificationState=useNotificationState;exports.useNotificationValue=useNotificationValue;//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../notifications/notificationAtom.ts","../../notifications/useNotification.ts"],"sourcesContent":["import { atomStateGenerator } from '@gaddario98/react-state';\nimport type { NotificationMessage } from './types';\n\nconst {\n atom: notificationAtom,\n useValue: useNotificationValue,\n useState: useNotificationState,\n} = atomStateGenerator<NotificationMessage | null>({\n defaultValue: null,\n key: 'reactNotificationAtom',\n persist: false,\n});\n\nexport { notificationAtom, useNotificationValue, useNotificationState };\n","import { useCallback, useEffect, useRef } from 'react';\nimport { useNotificationState } from './notificationAtom';\nimport type { NotificationMessage } from './types';\n\n const useNotificationSet = () => {\n const [, setValue] = useNotificationState();\n return setValue;\n };\n\nexport const useNotification = (ns = 'notifications') => {\n const setNotification = useNotificationSet();\n const ref =useRef({setNotification, ns})\n\n useEffect(() => {\n ref.current = { setNotification, ns };\n }, [setNotification, ns]);\n\n const showNotification = useCallback(\n (notification: Omit<NotificationMessage, 'id'>) => {\n ref.current.setNotification({\n ns: ref.current.ns,\n ...notification,\n id: Date.now().toString(),\n });\n },\n [],\n );\n\n const clearNotification = useCallback(() => {\n ref.current.setNotification(null);\n }, []);\n\n return {\n showNotification,\n clearNotification,\n };\n};\n"],"names":["atom","notificationAtom","useValue","useNotificationValue","useState","useNotificationState","atomStateGenerator","defaultValue","key","persist","useNotificationSet","setValue","useNotification","t0","$","_c","ns","undefined","setNotification","t1","ref","useRef","t2","t3","current","useEffect","t4","Symbol","for","notification","Object","assign","id","Date","now","toString","showNotification","t5","clearNotification","t6"],"mappings":"wIAGA,MAAM;AACJA,EAAAA,IAAI,EAAEC,gBAAgB;AACtBC,EAAAA,QAAQ,EAAEC,oBAAoB;AAC9BC,EAAAA,QAAQ,EAAEC;AAAoB,CAC/B,GAAGC,6BAAkB,CAA6B;AACjDC,EAAAA,YAAY,EAAE,IAAI;AAClBC,EAAAA,GAAG,EAAE,uBAAuB;AAC5BC,EAAAA,OAAO,EAAE;AACV,CAAA,ECPC,MAAMC,kBAAkB,GAAGA,MAAA;AACzB,EAAA,MAAA,GAAAC,QAAA,CAAA,GAAqBN,oBAAoB,EAAE;AAAC,EAAA,OACrCM,QAAQ;AAAA,CAChB;AAEI,MAAMC,eAAe,GAAGC,EAAA,IAAA;EAAA,MAAAC,CAAA,GAAAC,iBAAA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,CAAA,CAAA,CAAA,CAAA;AAAA,EAAA;AAAA,EAAA,OAHMyB,EAGN;AAAA"}
@@ -0,0 +1,84 @@
1
+ import {c}from'react/compiler-runtime';import {useRef,useEffect}from'react';import {atomStateGenerator}from'@gaddario98/react-state';const {
2
+ atom: notificationAtom,
3
+ useValue: useNotificationValue,
4
+ useState: useNotificationState
5
+ } = atomStateGenerator({
6
+ defaultValue: null,
7
+ key: 'reactNotificationAtom',
8
+ persist: false
9
+ });const useNotificationSet = () => {
10
+ const [, setValue] = useNotificationState();
11
+ return setValue;
12
+ };
13
+ const useNotification = t0 => {
14
+ const $ = c(10);
15
+ const ns = t0 === undefined ? "notifications" : t0;
16
+ const setNotification = useNotificationSet();
17
+ let t1;
18
+ if ($[0] !== ns || $[1] !== setNotification) {
19
+ t1 = {
20
+ setNotification,
21
+ ns
22
+ };
23
+ $[0] = ns;
24
+ $[1] = setNotification;
25
+ $[2] = t1;
26
+ } else {
27
+ t1 = $[2];
28
+ }
29
+ const ref = useRef(t1);
30
+ let t2;
31
+ let t3;
32
+ if ($[3] !== ns || $[4] !== setNotification) {
33
+ t2 = () => {
34
+ ref.current = {
35
+ setNotification,
36
+ ns
37
+ };
38
+ };
39
+ t3 = [setNotification, ns];
40
+ $[3] = ns;
41
+ $[4] = setNotification;
42
+ $[5] = t2;
43
+ $[6] = t3;
44
+ } else {
45
+ t2 = $[5];
46
+ t3 = $[6];
47
+ }
48
+ useEffect(t2, t3);
49
+ let t4;
50
+ if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
51
+ t4 = notification => {
52
+ ref.current.setNotification(Object.assign(Object.assign({
53
+ ns: ref.current.ns
54
+ }, notification), {
55
+ id: Date.now().toString()
56
+ }));
57
+ };
58
+ $[7] = t4;
59
+ } else {
60
+ t4 = $[7];
61
+ }
62
+ const showNotification = t4;
63
+ let t5;
64
+ if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
65
+ t5 = () => {
66
+ ref.current.setNotification(null);
67
+ };
68
+ $[8] = t5;
69
+ } else {
70
+ t5 = $[8];
71
+ }
72
+ const clearNotification = t5;
73
+ let t6;
74
+ if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
75
+ t6 = {
76
+ showNotification,
77
+ clearNotification
78
+ };
79
+ $[9] = t6;
80
+ } else {
81
+ t6 = $[9];
82
+ }
83
+ return t6;
84
+ };export{notificationAtom,useNotification,useNotificationState,useNotificationValue};//# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../../notifications/notificationAtom.ts","../../notifications/useNotification.ts"],"sourcesContent":["import { atomStateGenerator } from '@gaddario98/react-state';\nimport type { NotificationMessage } from './types';\n\nconst {\n atom: notificationAtom,\n useValue: useNotificationValue,\n useState: useNotificationState,\n} = atomStateGenerator<NotificationMessage | null>({\n defaultValue: null,\n key: 'reactNotificationAtom',\n persist: false,\n});\n\nexport { notificationAtom, useNotificationValue, useNotificationState };\n","import { useCallback, useEffect, useRef } from 'react';\nimport { useNotificationState } from './notificationAtom';\nimport type { NotificationMessage } from './types';\n\n const useNotificationSet = () => {\n const [, setValue] = useNotificationState();\n return setValue;\n };\n\nexport const useNotification = (ns = 'notifications') => {\n const setNotification = useNotificationSet();\n const ref =useRef({setNotification, ns})\n\n useEffect(() => {\n ref.current = { setNotification, ns };\n }, [setNotification, ns]);\n\n const showNotification = useCallback(\n (notification: Omit<NotificationMessage, 'id'>) => {\n ref.current.setNotification({\n ns: ref.current.ns,\n ...notification,\n id: Date.now().toString(),\n });\n },\n [],\n );\n\n const clearNotification = useCallback(() => {\n ref.current.setNotification(null);\n }, []);\n\n return {\n showNotification,\n clearNotification,\n };\n};\n"],"names":["atom","notificationAtom","useValue","useNotificationValue","useState","useNotificationState","atomStateGenerator","defaultValue","key","persist","useNotificationSet","setValue","useNotification","t0","$","_c","ns","undefined","setNotification","t1","ref","useRef","t2","t3","current","useEffect","t4","Symbol","for","notification","Object","assign","id","Date","now","toString","showNotification","t5","clearNotification","t6"],"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