@helpwave/hightide 0.1.35 → 0.1.36

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 (131) hide show
  1. package/dist/components/date/DatePicker.js.map +1 -1
  2. package/dist/components/date/DatePicker.mjs.map +1 -1
  3. package/dist/components/date/DayPicker.js.map +1 -1
  4. package/dist/components/date/DayPicker.mjs.map +1 -1
  5. package/dist/components/date/TimeDisplay.js.map +1 -1
  6. package/dist/components/date/TimeDisplay.mjs.map +1 -1
  7. package/dist/components/date/YearMonthPicker.js.map +1 -1
  8. package/dist/components/date/YearMonthPicker.mjs.map +1 -1
  9. package/dist/components/date/index.js.map +1 -1
  10. package/dist/components/date/index.mjs.map +1 -1
  11. package/dist/components/dialog/ConfirmDialog.js +30 -7
  12. package/dist/components/dialog/ConfirmDialog.js.map +1 -1
  13. package/dist/components/dialog/ConfirmDialog.mjs +29 -6
  14. package/dist/components/dialog/ConfirmDialog.mjs.map +1 -1
  15. package/dist/components/dialog/Dialog.d.mts +2 -1
  16. package/dist/components/dialog/Dialog.d.ts +2 -1
  17. package/dist/components/dialog/Dialog.js +30 -7
  18. package/dist/components/dialog/Dialog.js.map +1 -1
  19. package/dist/components/dialog/Dialog.mjs +29 -6
  20. package/dist/components/dialog/Dialog.mjs.map +1 -1
  21. package/dist/components/dialog/DiscardChangesDialog.js +30 -7
  22. package/dist/components/dialog/DiscardChangesDialog.js.map +1 -1
  23. package/dist/components/dialog/DiscardChangesDialog.mjs +29 -6
  24. package/dist/components/dialog/DiscardChangesDialog.mjs.map +1 -1
  25. package/dist/components/dialog/InputDialog.js +30 -7
  26. package/dist/components/dialog/InputDialog.js.map +1 -1
  27. package/dist/components/dialog/InputDialog.mjs +29 -6
  28. package/dist/components/dialog/InputDialog.mjs.map +1 -1
  29. package/dist/components/dialog/LanguageDialog.js +75 -52
  30. package/dist/components/dialog/LanguageDialog.js.map +1 -1
  31. package/dist/components/dialog/LanguageDialog.mjs +44 -21
  32. package/dist/components/dialog/LanguageDialog.mjs.map +1 -1
  33. package/dist/components/dialog/ThemeDialog.js +78 -55
  34. package/dist/components/dialog/ThemeDialog.js.map +1 -1
  35. package/dist/components/dialog/ThemeDialog.mjs +45 -22
  36. package/dist/components/dialog/ThemeDialog.mjs.map +1 -1
  37. package/dist/components/dialog/index.js +92 -69
  38. package/dist/components/dialog/index.js.map +1 -1
  39. package/dist/components/dialog/index.mjs +49 -26
  40. package/dist/components/dialog/index.mjs.map +1 -1
  41. package/dist/components/index.js +230 -207
  42. package/dist/components/index.js.map +1 -1
  43. package/dist/components/index.mjs +122 -99
  44. package/dist/components/index.mjs.map +1 -1
  45. package/dist/components/layout/Carousel.js.map +1 -1
  46. package/dist/components/layout/Carousel.mjs.map +1 -1
  47. package/dist/components/layout/TextImage.js.map +1 -1
  48. package/dist/components/layout/TextImage.mjs.map +1 -1
  49. package/dist/components/layout/index.js.map +1 -1
  50. package/dist/components/layout/index.mjs.map +1 -1
  51. package/dist/components/loading-states/ErrorComponent.js.map +1 -1
  52. package/dist/components/loading-states/ErrorComponent.mjs.map +1 -1
  53. package/dist/components/loading-states/LoadingAnimation.js.map +1 -1
  54. package/dist/components/loading-states/LoadingAnimation.mjs.map +1 -1
  55. package/dist/components/loading-states/index.js.map +1 -1
  56. package/dist/components/loading-states/index.mjs.map +1 -1
  57. package/dist/components/navigation/Pagination.js.map +1 -1
  58. package/dist/components/navigation/Pagination.mjs.map +1 -1
  59. package/dist/components/navigation/StepperBar.js.map +1 -1
  60. package/dist/components/navigation/StepperBar.mjs.map +1 -1
  61. package/dist/components/navigation/index.js.map +1 -1
  62. package/dist/components/navigation/index.mjs.map +1 -1
  63. package/dist/components/properties/CheckboxProperty.js.map +1 -1
  64. package/dist/components/properties/CheckboxProperty.mjs.map +1 -1
  65. package/dist/components/properties/DateProperty.js.map +1 -1
  66. package/dist/components/properties/DateProperty.mjs.map +1 -1
  67. package/dist/components/properties/MultiSelectProperty.js.map +1 -1
  68. package/dist/components/properties/MultiSelectProperty.mjs.map +1 -1
  69. package/dist/components/properties/NumberProperty.js.map +1 -1
  70. package/dist/components/properties/NumberProperty.mjs.map +1 -1
  71. package/dist/components/properties/PropertyBase.js.map +1 -1
  72. package/dist/components/properties/PropertyBase.mjs.map +1 -1
  73. package/dist/components/properties/SelectProperty.js.map +1 -1
  74. package/dist/components/properties/SelectProperty.mjs.map +1 -1
  75. package/dist/components/properties/TextProperty.js.map +1 -1
  76. package/dist/components/properties/TextProperty.mjs.map +1 -1
  77. package/dist/components/properties/index.js.map +1 -1
  78. package/dist/components/properties/index.mjs.map +1 -1
  79. package/dist/components/table/Table.js.map +1 -1
  80. package/dist/components/table/Table.mjs.map +1 -1
  81. package/dist/components/table/TableFilterButton.js.map +1 -1
  82. package/dist/components/table/TableFilterButton.mjs.map +1 -1
  83. package/dist/components/table/index.js.map +1 -1
  84. package/dist/components/table/index.mjs.map +1 -1
  85. package/dist/components/user-action/CopyToClipboardWrapper.js.map +1 -1
  86. package/dist/components/user-action/CopyToClipboardWrapper.mjs.map +1 -1
  87. package/dist/components/user-action/DateAndTimePicker.js.map +1 -1
  88. package/dist/components/user-action/DateAndTimePicker.mjs.map +1 -1
  89. package/dist/components/user-action/SearchBar.js.map +1 -1
  90. package/dist/components/user-action/SearchBar.mjs.map +1 -1
  91. package/dist/components/user-action/index.js.map +1 -1
  92. package/dist/components/user-action/index.mjs.map +1 -1
  93. package/dist/components/user-action/select/Select.js.map +1 -1
  94. package/dist/components/user-action/select/Select.mjs.map +1 -1
  95. package/dist/components/user-action/select/index.js.map +1 -1
  96. package/dist/components/user-action/select/index.mjs.map +1 -1
  97. package/dist/hooks/index.js +9 -2
  98. package/dist/hooks/index.js.map +1 -1
  99. package/dist/hooks/index.mjs +9 -2
  100. package/dist/hooks/index.mjs.map +1 -1
  101. package/dist/hooks/useLocalStorage.js +9 -2
  102. package/dist/hooks/useLocalStorage.js.map +1 -1
  103. package/dist/hooks/useLocalStorage.mjs +9 -2
  104. package/dist/hooks/useLocalStorage.mjs.map +1 -1
  105. package/dist/hooks/useValidators.js.map +1 -1
  106. package/dist/hooks/useValidators.mjs.map +1 -1
  107. package/dist/index.js +264 -232
  108. package/dist/index.js.map +1 -1
  109. package/dist/index.mjs +146 -114
  110. package/dist/index.mjs.map +1 -1
  111. package/dist/localization/LanguageProvider.js +10 -2
  112. package/dist/localization/LanguageProvider.js.map +1 -1
  113. package/dist/localization/LanguageProvider.mjs +10 -2
  114. package/dist/localization/LanguageProvider.mjs.map +1 -1
  115. package/dist/localization/index.js +10 -2
  116. package/dist/localization/index.js.map +1 -1
  117. package/dist/localization/index.mjs +10 -2
  118. package/dist/localization/index.mjs.map +1 -1
  119. package/dist/localization/useTranslation.js.map +1 -1
  120. package/dist/localization/useTranslation.mjs.map +1 -1
  121. package/dist/style/globals.css +1 -1
  122. package/dist/style/uncompiled/utitlity/animation.css +1 -1
  123. package/dist/theming/index.js +10 -2
  124. package/dist/theming/index.js.map +1 -1
  125. package/dist/theming/index.mjs +10 -2
  126. package/dist/theming/index.mjs.map +1 -1
  127. package/dist/theming/useTheme.js +10 -2
  128. package/dist/theming/useTheme.js.map +1 -1
  129. package/dist/theming/useTheme.mjs +10 -2
  130. package/dist/theming/useTheme.mjs.map +1 -1
  131. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/localization/LanguageProvider.tsx","../../src/hooks/useLocalStorage.ts","../../src/localization/util.ts","../../src/localization/useTranslation.ts"],"sourcesContent":["import type { Dispatch, PropsWithChildren, SetStateAction } from 'react'\nimport { createContext, useContext, useEffect, useMemo, useState } from 'react'\nimport { useLocalStorage } from '../hooks/useLocalStorage'\nimport type { Language } from './util'\nimport { LanguageUtil } from './util'\n\nexport type LanguageContextValue = {\n language: Language,\n setLanguage: Dispatch<SetStateAction<Language>>,\n}\n\nexport const LanguageContext = createContext<LanguageContextValue>({\n language: LanguageUtil.DEFAULT_LANGUAGE,\n setLanguage: (v) => v\n})\n\ntype LanguageWithSystem = Language | 'system'\n\ntype LanguageProviderProps = {\n language?: LanguageWithSystem,\n}\n\nexport const LanguageProvider = ({ children, language }: PropsWithChildren<LanguageProviderProps>) => {\n const {\n value: storedLanguage,\n setValue: setStoredLanguage,\n deleteValue: deleteStoredLanguage\n } = useLocalStorage<LanguageWithSystem>('language', 'system')\n const [languagePreference, setLanguagePreference] = useState<LanguageWithSystem>('system')\n\n const resolvedLanguage = useMemo(() => {\n if (language && language !== 'system') {\n return language\n }\n if (storedLanguage && storedLanguage !== 'system') {\n return storedLanguage\n }\n if (languagePreference !== 'system') {\n return languagePreference\n }\n return LanguageUtil.DEFAULT_LANGUAGE\n }, [language, languagePreference, storedLanguage])\n\n useEffect(() => {\n if (language === 'system') {\n deleteStoredLanguage()\n } else {\n setStoredLanguage(language)\n }\n }, [language]) // eslint-disable-line react-hooks/exhaustive-deps\n\n useEffect(() => {\n const LanguageToTestAgainst = Object.values(LanguageUtil.languages)\n\n const detectLanguage = () => {\n const matchingBrowserLanguage = window.navigator.languages\n .map(language =>\n LanguageToTestAgainst.find(\n (test) => language === test || language.split('-')[0] === test\n ))\n .filter((entry): entry is Language => entry !== undefined)\n\n if (matchingBrowserLanguage.length === 0) return\n\n const firstMatch = matchingBrowserLanguage[0]\n setLanguagePreference(firstMatch)\n }\n detectLanguage()\n\n window.addEventListener('languagechange', detectLanguage)\n return () => {\n window.removeEventListener('languagechange', detectLanguage)\n }\n }, [])\n\n return (\n <LanguageContext.Provider value={{\n language: resolvedLanguage,\n setLanguage: (newLanguage) => {\n if (language) {\n console.warn('LanguageProvider: Attempting to change the ' +\n \"language while setting a fixed language won't have any effect. \" +\n 'Change the language provided to the LanguageProvider instead.')\n }\n setStoredLanguage(newLanguage)\n }\n }}>\n {children}\n </LanguageContext.Provider>\n )\n}\n\nexport const useLanguage = () => {\n const context = useContext(LanguageContext)\n if (!context) {\n throw new Error('useLanguage must be used within LanguageContext. Try adding a LanguageProvider around your app.')\n }\n return context\n}\n\nexport const useLocale = (overWriteLanguage?: Language) => {\n const { language } = useLanguage()\n const mapping: Record<Language, string> = {\n en: 'en-US',\n de: 'de-DE'\n }\n return mapping[overWriteLanguage ?? language]\n}\n","'use client'\n\nimport type { Dispatch, SetStateAction } from 'react'\nimport { useCallback, useState } from 'react'\nimport { LocalStorageService } from '@/src/utils/storage'\nimport { resolveSetState } from '@/src/utils/resolveSetState'\n\ntype SetValue<T> = Dispatch<SetStateAction<T>>\n\ntype UseLocalStorageResult<T> = {\n value: T,\n setValue: SetValue<T>,\n deleteValue: () => void,\n}\n\n/**\n * @param key Key under which to save the data\n * @param backupValue Used if the storage is unavailable or no value is present\n *\n * The backup value will never be saved to the storage unless you explicitly\n */\nexport const useLocalStorage = <T>(key: string, backupValue: T): UseLocalStorageResult<T> => {\n const get = useCallback((): T => {\n if (typeof window === 'undefined') {\n return backupValue\n }\n const storageService = new LocalStorageService()\n const value = storageService.get<T>(key)\n return value || backupValue\n }, [backupValue, key])\n\n const [storedValue, setStoredValue] = useState<T>(get)\n\n const setValue: SetValue<T> = useCallback(action => {\n const newValue = resolveSetState(action, storedValue)\n const storageService = new LocalStorageService()\n storageService.set(key, newValue)\n\n setStoredValue(newValue)\n }, [storedValue, setStoredValue, key])\n\n const deleteValue = () => {\n const storageService = new LocalStorageService()\n storageService.delete(key)\n setStoredValue(backupValue)\n }\n\n return { value: storedValue, setValue, deleteValue }\n}","/**\n * The supported languages\n */\nconst languages = ['en', 'de'] as const\n\n/**\n * The supported languages\n */\nexport type Language = typeof languages[number]\n\n/**\n * The supported languages' names in their respective language\n */\nconst languagesLocalNames: Record<Language, string> = {\n en: 'English',\n de: 'Deutsch',\n}\n\n/**\n * The default language\n */\nconst DEFAULT_LANGUAGE: Language = 'en'\n\n/**\n * A constant definition for holding data regarding languages\n */\nexport const LanguageUtil = {\n languages,\n DEFAULT_LANGUAGE,\n languagesLocalNames,\n}","import { useLanguage } from './LanguageProvider'\nimport type { Language } from './util'\n\n/**\n * A type describing the pluralization of a word\n */\nexport type TranslationPlural = {\n zero?: string,\n one?: string,\n two?: string,\n few?: string,\n many?: string,\n other: string,\n}\n\n/**\n * The type describing all values of a translation\n */\nexport type TranslationType = Record<string, string | TranslationPlural>\n\n/**\n * The type of translations\n */\nexport type Translation<T extends TranslationType> = Record<Language, T>\n\ntype OverwriteTranslationType<T extends TranslationType> = {\n language?: Language,\n translation?: Translation<Partial<T>>,\n}\n\n/**\n * Adds the `language` prop to the component props.\n *\n * @param Translation the type of the translation object\n *\n * @param Props the type of the component props, defaults to `Record<string, never>`,\n * if you don't expect any other props other than `language` and get an\n * error when using your component (because it uses `forwardRef` etc.)\n * you can try out `Record<string, unknown>`, this might resolve your\n * problem as `SomeType & never` is still `never` but `SomeType & unknown`\n * is `SomeType` which means that adding back props (like `ref` etc.)\n * works properly\n */\nexport type PropsForTranslation<\n Translation extends TranslationType,\n Props = unknown\n> = Props & {\n overwriteTranslation?: OverwriteTranslationType<Translation>,\n}\n\ntype StringKeys<T> = Extract<keyof T, string>;\n\ntype TranslationFunctionOptions = {\n replacements?: Record<string, string>,\n count?: number,\n}\ntype TranslationFunction<T extends TranslationType> = (key: StringKeys<T>, options?: TranslationFunctionOptions) => string\n\nexport const TranslationPluralCount = {\n zero: 0,\n one: 1,\n two: 2,\n few: 3,\n many: 11,\n other: -1,\n}\n\n\nexport const useTranslation = <T extends TranslationType>(\n translations: Translation<Partial<TranslationType>>[],\n overwriteTranslation: OverwriteTranslationType<T> = {}\n): TranslationFunction<T> => {\n const { language: languageProp, translation: overwrite } = overwriteTranslation\n const { language: inferredLanguage } = useLanguage()\n const usedLanguage = languageProp ?? inferredLanguage\n const usedTranslations = [...translations]\n if (overwrite) {\n usedTranslations.push(overwrite)\n }\n\n return (key: StringKeys<T>, options?: TranslationFunctionOptions): string => {\n const { count, replacements } = { ...{ count: 0, replacements: {} }, ...options }\n\n try {\n for (let i = translations.length - 1; i >= 0; i--) {\n const translation = translations[i]\n const localizedTranslation = translation[usedLanguage]\n if (!localizedTranslation) {\n continue\n }\n const value = localizedTranslation[key]\n if(!value) {\n continue\n }\n\n let forProcessing: string\n if (typeof value !== 'string') {\n if (count === TranslationPluralCount.zero && value?.zero) {\n forProcessing = value.zero\n } else if (count === TranslationPluralCount.one && value?.one) {\n forProcessing = value.one\n } else if (count === TranslationPluralCount.two && value?.two) {\n forProcessing = value.two\n } else if (TranslationPluralCount.few <= count && count < TranslationPluralCount.many && value?.few) {\n forProcessing = value.few\n } else if (count > TranslationPluralCount.many && value?.many) {\n forProcessing = value.many\n } else {\n forProcessing = value.other\n }\n } else {\n forProcessing = value\n }\n forProcessing = forProcessing.replace(/\\{\\{(\\w+)}}/g, (_, placeholder) => {\n return replacements[placeholder] ?? `{{key:${placeholder}}}` // fallback if key is missing\n })\n return forProcessing\n }\n } catch (e) {\n console.error(e)\n }\n return `{{${usedLanguage}:${key}}}`\n }\n}"],"mappings":";AACA,SAAS,eAAe,YAAY,WAAW,SAAS,YAAAA,iBAAgB;;;ACExE,SAAS,aAAa,gBAAgB;;;ACAtC,IAAM,YAAY,CAAC,MAAM,IAAI;AAU7B,IAAM,sBAAgD;AAAA,EACpD,IAAI;AAAA,EACJ,IAAI;AACN;AAKA,IAAM,mBAA6B;AAK5B,IAAM,eAAe;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AACF;;;AF8CI;AAjEG,IAAM,kBAAkB,cAAoC;AAAA,EACjE,UAAU,aAAa;AAAA,EACvB,aAAa,CAAC,MAAM;AACtB,CAAC;AA8EM,IAAM,cAAc,MAAM;AAC/B,QAAM,UAAU,WAAW,eAAe;AAC1C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,iGAAiG;AAAA,EACnH;AACA,SAAO;AACT;;;AGxCO,IAAM,yBAAyB;AAAA,EACpC,MAAM;AAAA,EACN,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,MAAM;AAAA,EACN,OAAO;AACT;AAGO,IAAM,iBAAiB,CAC5B,cACA,uBAAoD,CAAC,MAC1B;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,eAAO;AAAA,MACT;AAAA,IACF,SAAS,GAAG;AACV,cAAQ,MAAM,CAAC;AAAA,IACjB;AACA,WAAO,KAAK,YAAY,IAAI,GAAG;AAAA,EACjC;AACF;","names":["useState"]}
1
+ {"version":3,"sources":["../../src/localization/LanguageProvider.tsx","../../src/hooks/useLocalStorage.ts","../../src/localization/util.ts","../../src/localization/useTranslation.ts"],"sourcesContent":["import type { Dispatch, PropsWithChildren, SetStateAction } from 'react'\nimport { createContext, useContext, useEffect, useMemo, useState } from 'react'\nimport { useLocalStorage } from '../hooks/useLocalStorage'\nimport type { Language } from './util'\nimport { LanguageUtil } from './util'\n\nexport type LanguageContextValue = {\n language: Language,\n setLanguage: Dispatch<SetStateAction<Language>>,\n}\n\nexport const LanguageContext = createContext<LanguageContextValue>({\n language: LanguageUtil.DEFAULT_LANGUAGE,\n setLanguage: (v) => v\n})\n\ntype LanguageWithSystem = Language | 'system'\n\ntype LanguageProviderProps = {\n language?: LanguageWithSystem,\n}\n\nexport const LanguageProvider = ({ children, language }: PropsWithChildren<LanguageProviderProps>) => {\n const {\n value: storedLanguage,\n setValue: setStoredLanguage,\n deleteValue: deleteStoredLanguage\n } = useLocalStorage<LanguageWithSystem>('language', 'system')\n const [languagePreference, setLanguagePreference] = useState<LanguageWithSystem>('system')\n\n const resolvedLanguage = useMemo(() => {\n if (language && language !== 'system') {\n return language\n }\n if (storedLanguage && storedLanguage !== 'system') {\n return storedLanguage\n }\n if (languagePreference !== 'system') {\n return languagePreference\n }\n return LanguageUtil.DEFAULT_LANGUAGE\n }, [language, languagePreference, storedLanguage])\n\n useEffect(() => {\n if(!language) return\n if (language === 'system') {\n deleteStoredLanguage()\n } else {\n setStoredLanguage(language)\n }\n }, [language]) // eslint-disable-line react-hooks/exhaustive-deps\n\n useEffect(() => {\n const LanguageToTestAgainst = Object.values(LanguageUtil.languages)\n\n const detectLanguage = () => {\n const matchingBrowserLanguage = window.navigator.languages\n .map(language =>\n LanguageToTestAgainst.find(\n (test) => language === test || language.split('-')[0] === test\n ))\n .filter((entry): entry is Language => entry !== undefined)\n\n if (matchingBrowserLanguage.length === 0) return\n\n const firstMatch = matchingBrowserLanguage[0]\n setLanguagePreference(firstMatch)\n }\n detectLanguage()\n\n window.addEventListener('languagechange', detectLanguage)\n return () => {\n window.removeEventListener('languagechange', detectLanguage)\n }\n }, [])\n\n return (\n <LanguageContext.Provider value={{\n language: resolvedLanguage,\n setLanguage: (newLanguage) => {\n if (language) {\n console.warn('LanguageProvider: Attempting to change the ' +\n \"language while setting a fixed language won't have any effect. \" +\n 'Change the language provided to the LanguageProvider instead.')\n }\n setStoredLanguage(newLanguage)\n }\n }}>\n {children}\n </LanguageContext.Provider>\n )\n}\n\nexport const useLanguage = () => {\n const context = useContext(LanguageContext)\n if (!context) {\n throw new Error('useLanguage must be used within LanguageContext. Try adding a LanguageProvider around your app.')\n }\n return context\n}\n\nexport const useLocale = (overWriteLanguage?: Language) => {\n const { language } = useLanguage()\n const mapping: Record<Language, string> = {\n en: 'en-US',\n de: 'de-DE'\n }\n return mapping[overWriteLanguage ?? language]\n}\n","'use client'\n\nimport type { Dispatch, SetStateAction } from 'react'\nimport { useCallback, useState } from 'react'\nimport { LocalStorageService } from '@/src/utils/storage'\nimport { resolveSetState } from '@/src/utils/resolveSetState'\n\ntype SetValue<T> = Dispatch<SetStateAction<T>>\n\ntype UseLocalStorageResult<T> = {\n value: T,\n setValue: SetValue<T>,\n deleteValue: () => void,\n}\n\n/**\n * @param key Key under which to save the data\n * @param backupValue Used if the storage is unavailable or no value is present\n *\n * The backup value will never be saved to the storage unless you explicitly\n */\nexport const useLocalStorage = <T>(key: string, backupValue: T): UseLocalStorageResult<T> => {\n const get = useCallback((): T => {\n if (typeof window === 'undefined') {\n return backupValue\n }\n const storageService = new LocalStorageService()\n try {\n const value = storageService.get<T>(key)\n return value || backupValue\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (_) {\n console.warn('useLocalStorage: Error while reading the stored value. Make sure your typing is correct.')\n storageService.delete(key)\n console.info(`useLocalStorage: deleted erroneous value for key: ${key}`)\n return backupValue\n }\n }, [backupValue, key])\n\n const [storedValue, setStoredValue] = useState<T>(get)\n\n const setValue: SetValue<T> = useCallback(action => {\n const newValue = resolveSetState(action, storedValue)\n const storageService = new LocalStorageService()\n storageService.set(key, newValue)\n\n setStoredValue(newValue)\n }, [storedValue, setStoredValue, key])\n\n const deleteValue = () => {\n const storageService = new LocalStorageService()\n storageService.delete(key)\n setStoredValue(backupValue)\n }\n\n return { value: storedValue, setValue, deleteValue }\n}","/**\n * The supported languages\n */\nconst languages = ['en', 'de'] as const\n\n/**\n * The supported languages\n */\nexport type Language = typeof languages[number]\n\n/**\n * The supported languages' names in their respective language\n */\nconst languagesLocalNames: Record<Language, string> = {\n en: 'English',\n de: 'Deutsch',\n}\n\n/**\n * The default language\n */\nconst DEFAULT_LANGUAGE: Language = 'en'\n\n/**\n * A constant definition for holding data regarding languages\n */\nexport const LanguageUtil = {\n languages,\n DEFAULT_LANGUAGE,\n languagesLocalNames,\n}","import { useLanguage } from './LanguageProvider'\nimport type { Language } from './util'\n\n/**\n * A type describing the pluralization of a word\n */\nexport type TranslationPlural = {\n zero?: string,\n one?: string,\n two?: string,\n few?: string,\n many?: string,\n other: string,\n}\n\n/**\n * The type describing all values of a translation\n */\nexport type TranslationType = Record<string, string | TranslationPlural>\n\n/**\n * The type of translations\n */\nexport type Translation<T extends TranslationType> = Record<Language, T>\n\ntype OverwriteTranslationType<T extends TranslationType> = {\n language?: Language,\n translation?: Translation<Partial<T>>,\n}\n\n/**\n * Adds the `language` prop to the component props.\n *\n * @param Translation the type of the translation object\n *\n * @param Props the type of the component props, defaults to `Record<string, never>`,\n * if you don't expect any other props other than `language` and get an\n * error when using your component (because it uses `forwardRef` etc.)\n * you can try out `Record<string, unknown>`, this might resolve your\n * problem as `SomeType & never` is still `never` but `SomeType & unknown`\n * is `SomeType` which means that adding back props (like `ref` etc.)\n * works properly\n */\nexport type PropsForTranslation<\n Translation extends TranslationType,\n Props = unknown\n> = Props & {\n overwriteTranslation?: OverwriteTranslationType<Translation>,\n}\n\ntype StringKeys<T> = Extract<keyof T, string>;\n\ntype TranslationFunctionOptions = {\n replacements?: Record<string, string>,\n count?: number,\n}\ntype TranslationFunction<T extends TranslationType> = (key: StringKeys<T>, options?: TranslationFunctionOptions) => string\n\nexport const TranslationPluralCount = {\n zero: 0,\n one: 1,\n two: 2,\n few: 3,\n many: 11,\n other: -1,\n}\n\n\nexport const useTranslation = <T extends TranslationType>(\n translations: Translation<Partial<TranslationType>>[],\n overwriteTranslation: OverwriteTranslationType<T> = {}\n): TranslationFunction<T> => {\n const { language: languageProp, translation: overwrite } = overwriteTranslation\n const { language: inferredLanguage } = useLanguage()\n const usedLanguage = languageProp ?? inferredLanguage\n const usedTranslations = [...translations]\n if (overwrite) {\n usedTranslations.push(overwrite)\n }\n\n return (key: StringKeys<T>, options?: TranslationFunctionOptions): string => {\n const { count, replacements } = { ...{ count: 0, replacements: {} }, ...options }\n\n try {\n for (let i = translations.length - 1; i >= 0; i--) {\n const translation = translations[i]\n const localizedTranslation = translation[usedLanguage]\n if (!localizedTranslation) {\n continue\n }\n const value = localizedTranslation[key]\n if(!value) {\n continue\n }\n\n let forProcessing: string\n if (typeof value !== 'string') {\n if (count === TranslationPluralCount.zero && value?.zero) {\n forProcessing = value.zero\n } else if (count === TranslationPluralCount.one && value?.one) {\n forProcessing = value.one\n } else if (count === TranslationPluralCount.two && value?.two) {\n forProcessing = value.two\n } else if (TranslationPluralCount.few <= count && count < TranslationPluralCount.many && value?.few) {\n forProcessing = value.few\n } else if (count > TranslationPluralCount.many && value?.many) {\n forProcessing = value.many\n } else {\n forProcessing = value.other\n }\n } else {\n forProcessing = value\n }\n forProcessing = forProcessing.replace(/\\{\\{(\\w+)}}/g, (_, placeholder) => {\n return replacements[placeholder] ?? `{{key:${placeholder}}}` // fallback if key is missing\n })\n return forProcessing\n }\n } catch (e) {\n console.error(e)\n }\n return `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AAsB;AACzB;AAAA,QACF;AACA,cAAM,QAAQ,qBAAqB,GAAG;AACtC,YAAG,CAAC,OAAO;AACT;AAAA,QACF;AAEA,YAAI;AACJ,YAAI,OAAO,UAAU,UAAU;AAC7B,cAAI,UAAU,uBAAuB,QAAQ,OAAO,MAAM;AACxD,4BAAgB,MAAM;AAAA,UACxB,WAAW,UAAU,uBAAuB,OAAO,OAAO,KAAK;AAC7D,4BAAgB,MAAM;AAAA,UACxB,WAAW,UAAU,uBAAuB,OAAO,OAAO,KAAK;AAC7D,4BAAgB,MAAM;AAAA,UACxB,WAAW,uBAAuB,OAAO,SAAS,QAAQ,uBAAuB,QAAQ,OAAO,KAAK;AACnG,4BAAgB,MAAM;AAAA,UACxB,WAAW,QAAQ,uBAAuB,QAAQ,OAAO,MAAM;AAC7D,4BAAgB,MAAM;AAAA,UACxB,OAAO;AACL,4BAAgB,MAAM;AAAA,UACxB;AAAA,QACF,OAAO;AACL,0BAAgB;AAAA,QAClB;AACA,wBAAgB,cAAc,QAAQ,gBAAgB,CAAC,GAAG,gBAAgB;AACxE,iBAAO,aAAa,WAAW,KAAK,SAAS,WAAW;AAAA,QAC1D,CAAC;AACD,eAAO;AAAA,MACT;AAAA,IACF,SAAS,GAAG;AACV,cAAQ,MAAM,CAAC;AAAA,IACjB;AACA,WAAO,KAAK,YAAY,IAAI,GAAG;AAAA,EACjC;AACF;","names":["useState"]}
@@ -2541,7 +2541,7 @@
2541
2541
  }
2542
2542
  .motion-safe\:animate-fade-out {
2543
2543
  @media (prefers-reduced-motion: no-preference) {
2544
- animation: fade-out 0.2s ease-in-out;
2544
+ animation: fade-out 0.2s ease-in-out forwards;
2545
2545
  }
2546
2546
  }
2547
2547
  .motion-safe\:animate-pop-in {
@@ -15,7 +15,7 @@
15
15
  }
16
16
 
17
17
  @utility animate-fade-out {
18
- animation: fade-out 0.2s ease-in-out;
18
+ animation: fade-out 0.2s ease-in-out forwards;
19
19
  }
20
20
 
21
21
  @utility animate-fade {
@@ -73,8 +73,15 @@ var useLocalStorage = (key, backupValue) => {
73
73
  return backupValue;
74
74
  }
75
75
  const storageService = new LocalStorageService();
76
- const value = storageService.get(key);
77
- return value || backupValue;
76
+ try {
77
+ const value = storageService.get(key);
78
+ return value || backupValue;
79
+ } catch (_) {
80
+ console.warn("useLocalStorage: Error while reading the stored value. Make sure your typing is correct.");
81
+ storageService.delete(key);
82
+ console.info(`useLocalStorage: deleted erroneous value for key: ${key}`);
83
+ return backupValue;
84
+ }
78
85
  }, [backupValue, key]);
79
86
  const [storedValue, setStoredValue] = (0, import_react.useState)(get);
80
87
  const setValue = (0, import_react.useCallback)((action) => {
@@ -139,6 +146,7 @@ var ThemeProvider = ({ children, theme }) => {
139
146
  return "light";
140
147
  }, [storedTheme, theme, themePreference]);
141
148
  (0, import_react2.useEffect)(() => {
149
+ if (!theme) return;
142
150
  if (theme === "system") {
143
151
  deleteStoredTheme();
144
152
  } else {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/theming/index.ts","../../src/theming/useTheme.tsx","../../src/hooks/useLocalStorage.ts","../../src/utils/storage.ts","../../src/utils/resolveSetState.ts"],"sourcesContent":["export * from './useTheme'\n","import type { Dispatch, PropsWithChildren, SetStateAction } from 'react'\nimport { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'\nimport type { Translation, TranslationPlural } from '../localization/useTranslation'\nimport { useLocalStorage } from '../hooks/useLocalStorage'\n\nconst themes = ['light', 'dark', 'system'] as const\n\nexport type ThemeType = typeof themes[number]\nexport type ResolvedTheme = Exclude<ThemeType, 'system'>\n\nexport type ThemeTypeTranslation = Record<ThemeType, string> & {\n theme: TranslationPlural,\n}\n\nconst defaultThemeTypeTranslation: Translation<ThemeTypeTranslation> = {\n en: {\n dark: 'Dark',\n light: 'Light',\n system: 'System',\n theme: {\n one: 'Theme',\n other: 'Themes'\n }\n },\n de: {\n dark: 'Dunkel',\n light: 'Hell',\n system: 'System',\n theme: {\n one: 'Farbschema',\n other: 'Farbschemas'\n }\n }\n}\n\nexport const ThemeUtil = {\n themes,\n translation: defaultThemeTypeTranslation,\n}\n\ntype ThemeContextType = {\n theme: ThemeType,\n resolvedTheme: ResolvedTheme,\n setTheme: Dispatch<SetStateAction<ThemeType>>,\n}\n\nexport const ThemeContext = createContext<ThemeContextType | null>(null)\n\ntype ThemeProviderProps = {\n /**\n * Only set this if you want to control the theme yourself\n */\n theme?: ThemeType,\n}\n\nexport const ThemeProvider = ({ children, theme }: PropsWithChildren<ThemeProviderProps>) => {\n const {\n value: storedTheme,\n setValue: setStoredTheme,\n deleteValue: deleteStoredTheme\n } = useLocalStorage<ThemeType>('theme', 'system')\n const [themePreference, setThemePreference] = useState<ThemeType>('system')\n\n const resolvedTheme = useMemo((): ResolvedTheme => {\n if (theme && theme !== 'system') {\n return theme\n }\n if (storedTheme && storedTheme !== 'system') {\n return storedTheme\n }\n if (themePreference !== 'system') {\n return themePreference\n }\n return 'light'\n }, [storedTheme, theme, themePreference])\n\n useEffect(() => {\n if (theme === 'system') {\n deleteStoredTheme()\n } else {\n setStoredTheme(theme)\n }\n }, [theme]) // eslint-disable-line react-hooks/exhaustive-deps\n\n useEffect(() => {\n document.documentElement.setAttribute('data-theme', resolvedTheme)\n }, [resolvedTheme])\n\n const getPreference = useCallback(() => {\n const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches\n const prefersLight = window.matchMedia('(prefers-color-scheme: light)').matches\n setThemePreference(prefersDark ? 'dark' : (prefersLight ? 'light' : 'system'))\n }, [])\n\n useEffect(() => {\n getPreference()\n }, [getPreference])\n\n useEffect(() => {\n const darkQuery = window.matchMedia('(prefers-color-scheme: dark)')\n const lightQuery = window.matchMedia('(prefers-color-scheme: light)')\n const noPrefQuery = window.matchMedia('(prefers-color-scheme: no-preference)')\n darkQuery.addEventListener('change', getPreference)\n lightQuery.addEventListener('change', getPreference)\n noPrefQuery.addEventListener('change', getPreference)\n return () => {\n darkQuery.removeEventListener('change', getPreference)\n lightQuery.removeEventListener('change', getPreference)\n noPrefQuery.removeEventListener('change', getPreference)\n }\n }, [getPreference])\n\n return (\n <ThemeContext.Provider\n value={{\n theme: storedTheme,\n resolvedTheme,\n setTheme: (newTheme) => {\n if (theme) {\n console.warn('ThemeProvider: Attempting to change the ' +\n \"theme while setting a fixed theme won't have any effect. \" +\n 'Change the theme provided to the ThemeProvider instead.')\n }\n setStoredTheme(newTheme)\n }\n }}\n >\n {children}\n </ThemeContext.Provider>\n )\n}\n\nexport const useTheme = () => {\n const context = useContext(ThemeContext)\n if (!context) {\n throw new Error('useTheme must be used within ThemeContext. Try adding a ThemeProvider around your app.')\n }\n return context\n}\n","'use client'\n\nimport type { Dispatch, SetStateAction } from 'react'\nimport { useCallback, useState } from 'react'\nimport { LocalStorageService } from '@/src/utils/storage'\nimport { resolveSetState } from '@/src/utils/resolveSetState'\n\ntype SetValue<T> = Dispatch<SetStateAction<T>>\n\ntype UseLocalStorageResult<T> = {\n value: T,\n setValue: SetValue<T>,\n deleteValue: () => void,\n}\n\n/**\n * @param key Key under which to save the data\n * @param backupValue Used if the storage is unavailable or no value is present\n *\n * The backup value will never be saved to the storage unless you explicitly\n */\nexport const useLocalStorage = <T>(key: string, backupValue: T): UseLocalStorageResult<T> => {\n const get = useCallback((): T => {\n if (typeof window === 'undefined') {\n return backupValue\n }\n const storageService = new LocalStorageService()\n const value = storageService.get<T>(key)\n return value || backupValue\n }, [backupValue, key])\n\n const [storedValue, setStoredValue] = useState<T>(get)\n\n const setValue: SetValue<T> = useCallback(action => {\n const newValue = resolveSetState(action, storedValue)\n const storageService = new LocalStorageService()\n storageService.set(key, newValue)\n\n setStoredValue(newValue)\n }, [storedValue, setStoredValue, key])\n\n const deleteValue = () => {\n const storageService = new LocalStorageService()\n storageService.delete(key)\n setStoredValue(backupValue)\n }\n\n return { value: storedValue, setValue, deleteValue }\n}","class StorageService {\n // this seems to be a bug in eslint as 'paramter-properties' is a special syntax of typescript\n\n constructor(private storage: Storage) {\n }\n\n public get<T>(key: string): T | null {\n const value = this.storage.getItem(key)\n if (value === null) {\n return null\n }\n return JSON.parse(value)\n }\n\n public set<T>(key: string, value: T) {\n this.storage.setItem(key, JSON.stringify(value))\n }\n\n public delete(key: string) {\n this.storage.removeItem(key)\n }\n\n public deleteAll() {\n this.storage.clear()\n }\n}\n\nexport class LocalStorageService extends StorageService {\n constructor() {\n super(window.localStorage)\n }\n}\n\nexport class SessionStorageService extends StorageService {\n constructor() {\n super(window.sessionStorage)\n }\n}\n","import type { SetStateAction } from 'react'\n\nexport function resolveSetState<T>(action: SetStateAction<T>, prev: T): T {\n return typeof action === 'function' ? (action as (prev: T) => T)(prev) : action\n}"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,IAAAA,gBAAqF;;;ACErF,mBAAsC;;;ACHtC,IAAM,iBAAN,MAAqB;AAAA;AAAA,EAGnB,YAAoB,SAAkB;AAAlB;AAAA,EACpB;AAAA,EAEO,IAAO,KAAuB;AACnC,UAAM,QAAQ,KAAK,QAAQ,QAAQ,GAAG;AACtC,QAAI,UAAU,MAAM;AAClB,aAAO;AAAA,IACT;AACA,WAAO,KAAK,MAAM,KAAK;AAAA,EACzB;AAAA,EAEO,IAAO,KAAa,OAAU;AACnC,SAAK,QAAQ,QAAQ,KAAK,KAAK,UAAU,KAAK,CAAC;AAAA,EACjD;AAAA,EAEO,OAAO,KAAa;AACzB,SAAK,QAAQ,WAAW,GAAG;AAAA,EAC7B;AAAA,EAEO,YAAY;AACjB,SAAK,QAAQ,MAAM;AAAA,EACrB;AACF;AAEO,IAAM,sBAAN,cAAkC,eAAe;AAAA,EACtD,cAAc;AACZ,UAAM,OAAO,YAAY;AAAA,EAC3B;AACF;;;AC7BO,SAAS,gBAAmB,QAA2B,MAAY;AACxE,SAAO,OAAO,WAAW,aAAc,OAA0B,IAAI,IAAI;AAC3E;;;AFiBO,IAAM,kBAAkB,CAAI,KAAa,gBAA6C;AAC3F,QAAM,U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C,aAAa;AAAA,IAAb;AAAA,MACC,OAAO;AAAA,QACL,OAAO;AAAA,QACP;AAAA,QACA,UAAU,CAAC,aAAa;AACtB,cAAI,OAAO;AACT,oBAAQ,KAAK,0JAE8C;AAAA,UAC7D;AACA,yBAAe,QAAQ;AAAA,QACzB;AAAA,MACF;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;AAEO,IAAM,WAAW,MAAM;AAC5B,QAAM,cAAU,0BAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,wFAAwF;AAAA,EAC1G;AACA,SAAO;AACT;","names":["import_react"]}
1
+ {"version":3,"sources":["../../src/theming/index.ts","../../src/theming/useTheme.tsx","../../src/hooks/useLocalStorage.ts","../../src/utils/storage.ts","../../src/utils/resolveSetState.ts"],"sourcesContent":["export * from './useTheme'\n","import type { Dispatch, PropsWithChildren, SetStateAction } from 'react'\nimport { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'\nimport type { Translation, TranslationPlural } from '../localization/useTranslation'\nimport { useLocalStorage } from '../hooks/useLocalStorage'\n\nconst themes = ['light', 'dark', 'system'] as const\n\nexport type ThemeType = typeof themes[number]\nexport type ResolvedTheme = Exclude<ThemeType, 'system'>\n\nexport type ThemeTypeTranslation = Record<ThemeType, string> & {\n theme: TranslationPlural,\n}\n\nconst defaultThemeTypeTranslation: Translation<ThemeTypeTranslation> = {\n en: {\n dark: 'Dark',\n light: 'Light',\n system: 'System',\n theme: {\n one: 'Theme',\n other: 'Themes'\n }\n },\n de: {\n dark: 'Dunkel',\n light: 'Hell',\n system: 'System',\n theme: {\n one: 'Farbschema',\n other: 'Farbschemas'\n }\n }\n}\n\nexport const ThemeUtil = {\n themes,\n translation: defaultThemeTypeTranslation,\n}\n\ntype ThemeContextType = {\n theme: ThemeType,\n resolvedTheme: ResolvedTheme,\n setTheme: Dispatch<SetStateAction<ThemeType>>,\n}\n\nexport const ThemeContext = createContext<ThemeContextType | null>(null)\n\ntype ThemeProviderProps = {\n /**\n * Only set this if you want to control the theme yourself\n */\n theme?: ThemeType,\n}\n\nexport const ThemeProvider = ({ children, theme }: PropsWithChildren<ThemeProviderProps>) => {\n const {\n value: storedTheme,\n setValue: setStoredTheme,\n deleteValue: deleteStoredTheme\n } = useLocalStorage<ThemeType>('theme', 'system')\n const [themePreference, setThemePreference] = useState<ThemeType>('system')\n\n const resolvedTheme = useMemo((): ResolvedTheme => {\n if (theme && theme !== 'system') {\n return theme\n }\n if (storedTheme && storedTheme !== 'system') {\n return storedTheme\n }\n if (themePreference !== 'system') {\n return themePreference\n }\n return 'light'\n }, [storedTheme, theme, themePreference])\n\n useEffect(() => {\n if(!theme) return\n if (theme === 'system') {\n deleteStoredTheme()\n } else {\n setStoredTheme(theme)\n }\n }, [theme]) // eslint-disable-line react-hooks/exhaustive-deps\n\n useEffect(() => {\n document.documentElement.setAttribute('data-theme', resolvedTheme)\n }, [resolvedTheme])\n\n const getPreference = useCallback(() => {\n const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches\n const prefersLight = window.matchMedia('(prefers-color-scheme: light)').matches\n setThemePreference(prefersDark ? 'dark' : (prefersLight ? 'light' : 'system'))\n }, [])\n\n useEffect(() => {\n getPreference()\n }, [getPreference])\n\n useEffect(() => {\n const darkQuery = window.matchMedia('(prefers-color-scheme: dark)')\n const lightQuery = window.matchMedia('(prefers-color-scheme: light)')\n const noPrefQuery = window.matchMedia('(prefers-color-scheme: no-preference)')\n darkQuery.addEventListener('change', getPreference)\n lightQuery.addEventListener('change', getPreference)\n noPrefQuery.addEventListener('change', getPreference)\n return () => {\n darkQuery.removeEventListener('change', getPreference)\n lightQuery.removeEventListener('change', getPreference)\n noPrefQuery.removeEventListener('change', getPreference)\n }\n }, [getPreference])\n\n return (\n <ThemeContext.Provider\n value={{\n theme: storedTheme,\n resolvedTheme,\n setTheme: (newTheme) => {\n if (theme) {\n console.warn('ThemeProvider: Attempting to change the ' +\n \"theme while setting a fixed theme won't have any effect. \" +\n 'Change the theme provided to the ThemeProvider instead.')\n }\n setStoredTheme(newTheme)\n }\n }}\n >\n {children}\n </ThemeContext.Provider>\n )\n}\n\nexport const useTheme = () => {\n const context = useContext(ThemeContext)\n if (!context) {\n throw new Error('useTheme must be used within ThemeContext. Try adding a ThemeProvider around your app.')\n }\n return context\n}\n","'use client'\n\nimport type { Dispatch, SetStateAction } from 'react'\nimport { useCallback, useState } from 'react'\nimport { LocalStorageService } from '@/src/utils/storage'\nimport { resolveSetState } from '@/src/utils/resolveSetState'\n\ntype SetValue<T> = Dispatch<SetStateAction<T>>\n\ntype UseLocalStorageResult<T> = {\n value: T,\n setValue: SetValue<T>,\n deleteValue: () => void,\n}\n\n/**\n * @param key Key under which to save the data\n * @param backupValue Used if the storage is unavailable or no value is present\n *\n * The backup value will never be saved to the storage unless you explicitly\n */\nexport const useLocalStorage = <T>(key: string, backupValue: T): UseLocalStorageResult<T> => {\n const get = useCallback((): T => {\n if (typeof window === 'undefined') {\n return backupValue\n }\n const storageService = new LocalStorageService()\n try {\n const value = storageService.get<T>(key)\n return value || backupValue\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (_) {\n console.warn('useLocalStorage: Error while reading the stored value. Make sure your typing is correct.')\n storageService.delete(key)\n console.info(`useLocalStorage: deleted erroneous value for key: ${key}`)\n return backupValue\n }\n }, [backupValue, key])\n\n const [storedValue, setStoredValue] = useState<T>(get)\n\n const setValue: SetValue<T> = useCallback(action => {\n const newValue = resolveSetState(action, storedValue)\n const storageService = new LocalStorageService()\n storageService.set(key, newValue)\n\n setStoredValue(newValue)\n }, [storedValue, setStoredValue, key])\n\n const deleteValue = () => {\n const storageService = new LocalStorageService()\n storageService.delete(key)\n setStoredValue(backupValue)\n }\n\n return { value: storedValue, setValue, deleteValue }\n}","class StorageService {\n // this seems to be a bug in eslint as 'paramter-properties' is a special syntax of typescript\n\n constructor(private storage: Storage) {\n }\n\n public get<T>(key: string): T | null {\n const value = this.storage.getItem(key)\n if (value === null) {\n return null\n }\n return JSON.parse(value)\n }\n\n public set<T>(key: string, value: T) {\n this.storage.setItem(key, JSON.stringify(value))\n }\n\n public delete(key: string) {\n this.storage.removeItem(key)\n }\n\n public deleteAll() {\n this.storage.clear()\n }\n}\n\nexport class LocalStorageService extends StorageService {\n constructor() {\n super(window.localStorage)\n }\n}\n\nexport class SessionStorageService extends StorageService {\n constructor() {\n super(window.sessionStorage)\n }\n}\n","import type { SetStateAction } from 'react'\n\nexport function resolveSetState<T>(action: SetStateAction<T>, prev: T): T {\n return typeof action === 'function' ? (action as (prev: T) => T)(prev) : action\n}"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,IAAAA,gBAAqF;;;ACErF,mBAAsC;;;ACHtC,IAAM,iBAAN,MAAqB;AAAA;AAAA,EAGnB,YAAoB,SAAkB;AAAlB;AAAA,EACpB;AAAA,EAEO,IAAO,KAAuB;AACnC,UAAM,QAAQ,KAAK,QAAQ,QAAQ,GAAG;AACtC,QAAI,UAAU,MAAM;AAClB,aAAO;AAAA,IACT;AACA,WAAO,KAAK,MAAM,KAAK;AAAA,EACzB;AAAA,EAEO,IAAO,KAAa,OAAU;AACnC,SAAK,QAAQ,QAAQ,KAAK,KAAK,UAAU,KAAK,CAAC;AAAA,EACjD;AAAA,EAEO,OAAO,KAAa;AACzB,SAAK,QAAQ,WAAW,GAAG;AAAA,EAC7B;AAAA,EAEO,YAAY;AACjB,SAAK,QAAQ,MAAM;AAAA,EACrB;AACF;AAEO,IAAM,sBAAN,cAAkC,eAAe;AAAA,EACtD,cAAc;AACZ,UAAM,OAAO,YAAY;AAAA,EAC3B;AACF;;;AC7BO,SAAS,gBAAmB,QAA2B,MAAY;AACxE,SAAO,OAAO,WAAW,aAAc,OAA0B,IAAI,IAAI;AAC3E;;;AFiBO,IAAM,kBAAkB,CAAI,KAAa,gBAA6C;AAC3F,QAAM,UAAM,0BAAY,MAAS;AAC/B,QAAI,OA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a;AACrD,iBAAW,oBAAoB,UAAU,aAAa;AACtD,kBAAY,oBAAoB,UAAU,aAAa;AAAA,IACzD;AAAA,EACF,GAAG,CAAC,aAAa,CAAC;AAElB,SACE;AAAA,IAAC,aAAa;AAAA,IAAb;AAAA,MACC,OAAO;AAAA,QACL,OAAO;AAAA,QACP;AAAA,QACA,UAAU,CAAC,aAAa;AACtB,cAAI,OAAO;AACT,oBAAQ,KAAK,0JAE8C;AAAA,UAC7D;AACA,yBAAe,QAAQ;AAAA,QACzB;AAAA,MACF;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;AAEO,IAAM,WAAW,MAAM;AAC5B,QAAM,cAAU,0BAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,wFAAwF;AAAA,EAC1G;AACA,SAAO;AACT;","names":["import_react"]}
@@ -45,8 +45,15 @@ var useLocalStorage = (key, backupValue) => {
45
45
  return backupValue;
46
46
  }
47
47
  const storageService = new LocalStorageService();
48
- const value = storageService.get(key);
49
- return value || backupValue;
48
+ try {
49
+ const value = storageService.get(key);
50
+ return value || backupValue;
51
+ } catch (_) {
52
+ console.warn("useLocalStorage: Error while reading the stored value. Make sure your typing is correct.");
53
+ storageService.delete(key);
54
+ console.info(`useLocalStorage: deleted erroneous value for key: ${key}`);
55
+ return backupValue;
56
+ }
50
57
  }, [backupValue, key]);
51
58
  const [storedValue, setStoredValue] = useState(get);
52
59
  const setValue = useCallback((action) => {
@@ -111,6 +118,7 @@ var ThemeProvider = ({ children, theme }) => {
111
118
  return "light";
112
119
  }, [storedTheme, theme, themePreference]);
113
120
  useEffect(() => {
121
+ if (!theme) return;
114
122
  if (theme === "system") {
115
123
  deleteStoredTheme();
116
124
  } else {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/theming/useTheme.tsx","../../src/hooks/useLocalStorage.ts","../../src/utils/storage.ts","../../src/utils/resolveSetState.ts"],"sourcesContent":["import type { Dispatch, PropsWithChildren, SetStateAction } from 'react'\nimport { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'\nimport type { Translation, TranslationPlural } from '../localization/useTranslation'\nimport { useLocalStorage } from '../hooks/useLocalStorage'\n\nconst themes = ['light', 'dark', 'system'] as const\n\nexport type ThemeType = typeof themes[number]\nexport type ResolvedTheme = Exclude<ThemeType, 'system'>\n\nexport type ThemeTypeTranslation = Record<ThemeType, string> & {\n theme: TranslationPlural,\n}\n\nconst defaultThemeTypeTranslation: Translation<ThemeTypeTranslation> = {\n en: {\n dark: 'Dark',\n light: 'Light',\n system: 'System',\n theme: {\n one: 'Theme',\n other: 'Themes'\n }\n },\n de: {\n dark: 'Dunkel',\n light: 'Hell',\n system: 'System',\n theme: {\n one: 'Farbschema',\n other: 'Farbschemas'\n }\n }\n}\n\nexport const ThemeUtil = {\n themes,\n translation: defaultThemeTypeTranslation,\n}\n\ntype ThemeContextType = {\n theme: ThemeType,\n resolvedTheme: ResolvedTheme,\n setTheme: Dispatch<SetStateAction<ThemeType>>,\n}\n\nexport const ThemeContext = createContext<ThemeContextType | null>(null)\n\ntype ThemeProviderProps = {\n /**\n * Only set this if you want to control the theme yourself\n */\n theme?: ThemeType,\n}\n\nexport const ThemeProvider = ({ children, theme }: PropsWithChildren<ThemeProviderProps>) => {\n const {\n value: storedTheme,\n setValue: setStoredTheme,\n deleteValue: deleteStoredTheme\n } = useLocalStorage<ThemeType>('theme', 'system')\n const [themePreference, setThemePreference] = useState<ThemeType>('system')\n\n const resolvedTheme = useMemo((): ResolvedTheme => {\n if (theme && theme !== 'system') {\n return theme\n }\n if (storedTheme && storedTheme !== 'system') {\n return storedTheme\n }\n if (themePreference !== 'system') {\n return themePreference\n }\n return 'light'\n }, [storedTheme, theme, themePreference])\n\n useEffect(() => {\n if (theme === 'system') {\n deleteStoredTheme()\n } else {\n setStoredTheme(theme)\n }\n }, [theme]) // eslint-disable-line react-hooks/exhaustive-deps\n\n useEffect(() => {\n document.documentElement.setAttribute('data-theme', resolvedTheme)\n }, [resolvedTheme])\n\n const getPreference = useCallback(() => {\n const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches\n const prefersLight = window.matchMedia('(prefers-color-scheme: light)').matches\n setThemePreference(prefersDark ? 'dark' : (prefersLight ? 'light' : 'system'))\n }, [])\n\n useEffect(() => {\n getPreference()\n }, [getPreference])\n\n useEffect(() => {\n const darkQuery = window.matchMedia('(prefers-color-scheme: dark)')\n const lightQuery = window.matchMedia('(prefers-color-scheme: light)')\n const noPrefQuery = window.matchMedia('(prefers-color-scheme: no-preference)')\n darkQuery.addEventListener('change', getPreference)\n lightQuery.addEventListener('change', getPreference)\n noPrefQuery.addEventListener('change', getPreference)\n return () => {\n darkQuery.removeEventListener('change', getPreference)\n lightQuery.removeEventListener('change', getPreference)\n noPrefQuery.removeEventListener('change', getPreference)\n }\n }, [getPreference])\n\n return (\n <ThemeContext.Provider\n value={{\n theme: storedTheme,\n resolvedTheme,\n setTheme: (newTheme) => {\n if (theme) {\n console.warn('ThemeProvider: Attempting to change the ' +\n \"theme while setting a fixed theme won't have any effect. \" +\n 'Change the theme provided to the ThemeProvider instead.')\n }\n setStoredTheme(newTheme)\n }\n }}\n >\n {children}\n </ThemeContext.Provider>\n )\n}\n\nexport const useTheme = () => {\n const context = useContext(ThemeContext)\n if (!context) {\n throw new Error('useTheme must be used within ThemeContext. Try adding a ThemeProvider around your app.')\n }\n return context\n}\n","'use client'\n\nimport type { Dispatch, SetStateAction } from 'react'\nimport { useCallback, useState } from 'react'\nimport { LocalStorageService } from '@/src/utils/storage'\nimport { resolveSetState } from '@/src/utils/resolveSetState'\n\ntype SetValue<T> = Dispatch<SetStateAction<T>>\n\ntype UseLocalStorageResult<T> = {\n value: T,\n setValue: SetValue<T>,\n deleteValue: () => void,\n}\n\n/**\n * @param key Key under which to save the data\n * @param backupValue Used if the storage is unavailable or no value is present\n *\n * The backup value will never be saved to the storage unless you explicitly\n */\nexport const useLocalStorage = <T>(key: string, backupValue: T): UseLocalStorageResult<T> => {\n const get = useCallback((): T => {\n if (typeof window === 'undefined') {\n return backupValue\n }\n const storageService = new LocalStorageService()\n const value = storageService.get<T>(key)\n return value || backupValue\n }, [backupValue, key])\n\n const [storedValue, setStoredValue] = useState<T>(get)\n\n const setValue: SetValue<T> = useCallback(action => {\n const newValue = resolveSetState(action, storedValue)\n const storageService = new LocalStorageService()\n storageService.set(key, newValue)\n\n setStoredValue(newValue)\n }, [storedValue, setStoredValue, key])\n\n const deleteValue = () => {\n const storageService = new LocalStorageService()\n storageService.delete(key)\n setStoredValue(backupValue)\n }\n\n return { value: storedValue, setValue, deleteValue }\n}","class StorageService {\n // this seems to be a bug in eslint as 'paramter-properties' is a special syntax of typescript\n\n constructor(private storage: Storage) {\n }\n\n public get<T>(key: string): T | null {\n const value = this.storage.getItem(key)\n if (value === null) {\n return null\n }\n return JSON.parse(value)\n }\n\n public set<T>(key: string, value: T) {\n this.storage.setItem(key, JSON.stringify(value))\n }\n\n public delete(key: string) {\n this.storage.removeItem(key)\n }\n\n public deleteAll() {\n this.storage.clear()\n }\n}\n\nexport class LocalStorageService extends StorageService {\n constructor() {\n super(window.localStorage)\n }\n}\n\nexport class SessionStorageService extends StorageService {\n constructor() {\n super(window.sessionStorage)\n }\n}\n","import type { SetStateAction } from 'react'\n\nexport function resolveSetState<T>(action: SetStateAction<T>, prev: T): T {\n return typeof action === 'function' ? (action as (prev: T) => T)(prev) : action\n}"],"mappings":";AACA,SAAS,eAAe,eAAAA,cAAa,YAAY,WAAW,SAAS,YAAAC,iBAAgB;;;ACErF,SAAS,aAAa,gBAAgB;;;ACHtC,IAAM,iBAAN,MAAqB;AAAA;AAAA,EAGnB,YAAoB,SAAkB;AAAlB;AAAA,EACpB;AAAA,EAEO,IAAO,KAAuB;AACnC,UAAM,QAAQ,KAAK,QAAQ,QAAQ,GAAG;AACtC,QAAI,UAAU,MAAM;AAClB,aAAO;AAAA,IACT;AACA,WAAO,KAAK,MAAM,KAAK;AAAA,EACzB;AAAA,EAEO,IAAO,KAAa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G,CAAC,aAAa,CAAC;AAElB,YAAU,MAAM;AACd,UAAM,YAAY,OAAO,WAAW,8BAA8B;AAClE,UAAM,aAAa,OAAO,WAAW,+BAA+B;AACpE,UAAM,cAAc,OAAO,WAAW,uCAAuC;AAC7E,cAAU,iBAAiB,UAAU,aAAa;AAClD,eAAW,iBAAiB,UAAU,aAAa;AACnD,gBAAY,iBAAiB,UAAU,aAAa;AACpD,WAAO,MAAM;AACX,gBAAU,oBAAoB,UAAU,aAAa;AACrD,iBAAW,oBAAoB,UAAU,aAAa;AACtD,kBAAY,oBAAoB,UAAU,aAAa;AAAA,IACzD;AAAA,EACF,GAAG,CAAC,aAAa,CAAC;AAElB,SACE;AAAA,IAAC,aAAa;AAAA,IAAb;AAAA,MACC,OAAO;AAAA,QACL,OAAO;AAAA,QACP;AAAA,QACA,UAAU,CAAC,aAAa;AACtB,cAAI,OAAO;AACT,oBAAQ,KAAK,0JAE8C;AAAA,UAC7D;AACA,yBAAe,QAAQ;AAAA,QACzB;AAAA,MACF;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;AAEO,IAAM,WAAW,MAAM;AAC5B,QAAM,UAAU,WAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,wFAAwF;AAAA,EAC1G;AACA,SAAO;AACT;","names":["useCallback","useState","useState","useCallback"]}
1
+ {"version":3,"sources":["../../src/theming/useTheme.tsx","../../src/hooks/useLocalStorage.ts","../../src/utils/storage.ts","../../src/utils/resolveSetState.ts"],"sourcesContent":["import type { Dispatch, PropsWithChildren, SetStateAction } from 'react'\nimport { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'\nimport type { Translation, TranslationPlural } from '../localization/useTranslation'\nimport { useLocalStorage } from '../hooks/useLocalStorage'\n\nconst themes = ['light', 'dark', 'system'] as const\n\nexport type ThemeType = typeof themes[number]\nexport type ResolvedTheme = Exclude<ThemeType, 'system'>\n\nexport type ThemeTypeTranslation = Record<ThemeType, string> & {\n theme: TranslationPlural,\n}\n\nconst defaultThemeTypeTranslation: Translation<ThemeTypeTranslation> = {\n en: {\n dark: 'Dark',\n light: 'Light',\n system: 'System',\n theme: {\n one: 'Theme',\n other: 'Themes'\n }\n },\n de: {\n dark: 'Dunkel',\n light: 'Hell',\n system: 'System',\n theme: {\n one: 'Farbschema',\n other: 'Farbschemas'\n }\n }\n}\n\nexport const ThemeUtil = {\n themes,\n translation: defaultThemeTypeTranslation,\n}\n\ntype ThemeContextType = {\n theme: ThemeType,\n resolvedTheme: ResolvedTheme,\n setTheme: Dispatch<SetStateAction<ThemeType>>,\n}\n\nexport const ThemeContext = createContext<ThemeContextType | null>(null)\n\ntype ThemeProviderProps = {\n /**\n * Only set this if you want to control the theme yourself\n */\n theme?: ThemeType,\n}\n\nexport const ThemeProvider = ({ children, theme }: PropsWithChildren<ThemeProviderProps>) => {\n const {\n value: storedTheme,\n setValue: setStoredTheme,\n deleteValue: deleteStoredTheme\n } = useLocalStorage<ThemeType>('theme', 'system')\n const [themePreference, setThemePreference] = useState<ThemeType>('system')\n\n const resolvedTheme = useMemo((): ResolvedTheme => {\n if (theme && theme !== 'system') {\n return theme\n }\n if (storedTheme && storedTheme !== 'system') {\n return storedTheme\n }\n if (themePreference !== 'system') {\n return themePreference\n }\n return 'light'\n }, [storedTheme, theme, themePreference])\n\n useEffect(() => {\n if(!theme) return\n if (theme === 'system') {\n deleteStoredTheme()\n } else {\n setStoredTheme(theme)\n }\n }, [theme]) // eslint-disable-line react-hooks/exhaustive-deps\n\n useEffect(() => {\n document.documentElement.setAttribute('data-theme', resolvedTheme)\n }, [resolvedTheme])\n\n const getPreference = useCallback(() => {\n const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches\n const prefersLight = window.matchMedia('(prefers-color-scheme: light)').matches\n setThemePreference(prefersDark ? 'dark' : (prefersLight ? 'light' : 'system'))\n }, [])\n\n useEffect(() => {\n getPreference()\n }, [getPreference])\n\n useEffect(() => {\n const darkQuery = window.matchMedia('(prefers-color-scheme: dark)')\n const lightQuery = window.matchMedia('(prefers-color-scheme: light)')\n const noPrefQuery = window.matchMedia('(prefers-color-scheme: no-preference)')\n darkQuery.addEventListener('change', getPreference)\n lightQuery.addEventListener('change', getPreference)\n noPrefQuery.addEventListener('change', getPreference)\n return () => {\n darkQuery.removeEventListener('change', getPreference)\n lightQuery.removeEventListener('change', getPreference)\n noPrefQuery.removeEventListener('change', getPreference)\n }\n }, [getPreference])\n\n return (\n <ThemeContext.Provider\n value={{\n theme: storedTheme,\n resolvedTheme,\n setTheme: (newTheme) => {\n if (theme) {\n console.warn('ThemeProvider: Attempting to change the ' +\n \"theme while setting a fixed theme won't have any effect. \" +\n 'Change the theme provided to the ThemeProvider instead.')\n }\n setStoredTheme(newTheme)\n }\n }}\n >\n {children}\n </ThemeContext.Provider>\n )\n}\n\nexport const useTheme = () => {\n const context = useContext(ThemeContext)\n if (!context) {\n throw new Error('useTheme must be used within ThemeContext. Try adding a ThemeProvider around your app.')\n }\n return context\n}\n","'use client'\n\nimport type { Dispatch, SetStateAction } from 'react'\nimport { useCallback, useState } from 'react'\nimport { LocalStorageService } from '@/src/utils/storage'\nimport { resolveSetState } from '@/src/utils/resolveSetState'\n\ntype SetValue<T> = Dispatch<SetStateAction<T>>\n\ntype UseLocalStorageResult<T> = {\n value: T,\n setValue: SetValue<T>,\n deleteValue: () => void,\n}\n\n/**\n * @param key Key under which to save the data\n * @param backupValue Used if the storage is unavailable or no value is present\n *\n * The backup value will never be saved to the storage unless you explicitly\n */\nexport const useLocalStorage = <T>(key: string, backupValue: T): UseLocalStorageResult<T> => {\n const get = useCallback((): T => {\n if (typeof window === 'undefined') {\n return backupValue\n }\n const storageService = new LocalStorageService()\n try {\n const value = storageService.get<T>(key)\n return value || backupValue\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (_) {\n console.warn('useLocalStorage: Error while reading the stored value. Make sure your typing is correct.')\n storageService.delete(key)\n console.info(`useLocalStorage: deleted erroneous value for key: ${key}`)\n return backupValue\n }\n }, [backupValue, key])\n\n const [storedValue, setStoredValue] = useState<T>(get)\n\n const setValue: SetValue<T> = useCallback(action => {\n const newValue = resolveSetState(action, storedValue)\n const storageService = new LocalStorageService()\n storageService.set(key, newValue)\n\n setStoredValue(newValue)\n }, [storedValue, setStoredValue, key])\n\n const deleteValue = () => {\n const storageService = new LocalStorageService()\n storageService.delete(key)\n setStoredValue(backupValue)\n }\n\n return { value: storedValue, setValue, deleteValue }\n}","class StorageService {\n // this seems to be a bug in eslint as 'paramter-properties' is a special syntax of typescript\n\n constructor(private storage: Storage) {\n }\n\n public get<T>(key: string): T | null {\n const value = this.storage.getItem(key)\n if (value === null) {\n return null\n }\n return JSON.parse(value)\n }\n\n public set<T>(key: string, value: T) {\n this.storage.setItem(key, JSON.stringify(value))\n }\n\n public delete(key: string) {\n this.storage.removeItem(key)\n }\n\n public deleteAll() {\n this.storage.clear()\n }\n}\n\nexport class LocalStorageService extends StorageService {\n constructor() {\n super(window.localStorage)\n }\n}\n\nexport class SessionStorageService extends StorageService {\n constructor() {\n super(window.sessionStorage)\n }\n}\n","import type { SetStateAction } from 'react'\n\nexport function resolveSetState<T>(action: SetStateAction<T>, prev: T): T {\n return typeof action === 'function' ? (action as (prev: T) => T)(prev) : action\n}"],"mappings":";AACA,SAAS,eAAe,eAAAA,cAAa,YAAY,WAAW,SAAS,YAAAC,iBAAgB;;;ACErF,SAAS,aAAa,gBAAgB;;;ACHtC,IAAM,iBAAN,MAAqB;AAAA;AAAA,EAGnB,YAAoB,SAAkB;AAAlB;AAAA,EACpB;AAAA,EAEO,IAAO,KAAuB;AACnC,UAAM,QAAQ,KAAK,QAAQ,QAAQ,GAAG;AACtC,QAAI,UAAU,MAAM;AAClB,aAAO;AAAA,IACT;AACA,WAAO,KAAK,MAAM,KAAK;AAAA,EACzB;AAAA,EAEO,IAAO,KAAa,OAAU;AACnC,SAAK,QAAQ,QAAQ,KAAK,KAAK,UAAU,KAAK,CAAC;AAAA,EACjD;AAA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e,UAAU,QAAS;AAAA,EAC/E,GAAG,CAAC,CAAC;AAEL,YAAU,MAAM;AACd,kBAAc;AAAA,EAChB,GAAG,CAAC,aAAa,CAAC;AAElB,YAAU,MAAM;AACd,UAAM,YAAY,OAAO,WAAW,8BAA8B;AAClE,UAAM,aAAa,OAAO,WAAW,+BAA+B;AACpE,UAAM,cAAc,OAAO,WAAW,uCAAuC;AAC7E,cAAU,iBAAiB,UAAU,aAAa;AAClD,eAAW,iBAAiB,UAAU,aAAa;AACnD,gBAAY,iBAAiB,UAAU,aAAa;AACpD,WAAO,MAAM;AACX,gBAAU,oBAAoB,UAAU,aAAa;AACrD,iBAAW,oBAAoB,UAAU,aAAa;AACtD,kBAAY,oBAAoB,UAAU,aAAa;AAAA,IACzD;AAAA,EACF,GAAG,CAAC,aAAa,CAAC;AAElB,SACE;AAAA,IAAC,aAAa;AAAA,IAAb;AAAA,MACC,OAAO;AAAA,QACL,OAAO;AAAA,QACP;AAAA,QACA,UAAU,CAAC,aAAa;AACtB,cAAI,OAAO;AACT,oBAAQ,KAAK,0JAE8C;AAAA,UAC7D;AACA,yBAAe,QAAQ;AAAA,QACzB;AAAA,MACF;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;AAEO,IAAM,WAAW,MAAM;AAC5B,QAAM,UAAU,WAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,wFAAwF;AAAA,EAC1G;AACA,SAAO;AACT;","names":["useCallback","useState","useState","useCallback"]}
@@ -71,8 +71,15 @@ var useLocalStorage = (key, backupValue) => {
71
71
  return backupValue;
72
72
  }
73
73
  const storageService = new LocalStorageService();
74
- const value = storageService.get(key);
75
- return value || backupValue;
74
+ try {
75
+ const value = storageService.get(key);
76
+ return value || backupValue;
77
+ } catch (_) {
78
+ console.warn("useLocalStorage: Error while reading the stored value. Make sure your typing is correct.");
79
+ storageService.delete(key);
80
+ console.info(`useLocalStorage: deleted erroneous value for key: ${key}`);
81
+ return backupValue;
82
+ }
76
83
  }, [backupValue, key]);
77
84
  const [storedValue, setStoredValue] = (0, import_react.useState)(get);
78
85
  const setValue = (0, import_react.useCallback)((action) => {
@@ -137,6 +144,7 @@ var ThemeProvider = ({ children, theme }) => {
137
144
  return "light";
138
145
  }, [storedTheme, theme, themePreference]);
139
146
  (0, import_react2.useEffect)(() => {
147
+ if (!theme) return;
140
148
  if (theme === "system") {
141
149
  deleteStoredTheme();
142
150
  } else {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/theming/useTheme.tsx","../../src/hooks/useLocalStorage.ts","../../src/utils/storage.ts","../../src/utils/resolveSetState.ts"],"sourcesContent":["import type { Dispatch, PropsWithChildren, SetStateAction } from 'react'\nimport { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'\nimport type { Translation, TranslationPlural } from '../localization/useTranslation'\nimport { useLocalStorage } from '../hooks/useLocalStorage'\n\nconst themes = ['light', 'dark', 'system'] as const\n\nexport type ThemeType = typeof themes[number]\nexport type ResolvedTheme = Exclude<ThemeType, 'system'>\n\nexport type ThemeTypeTranslation = Record<ThemeType, string> & {\n theme: TranslationPlural,\n}\n\nconst defaultThemeTypeTranslation: Translation<ThemeTypeTranslation> = {\n en: {\n dark: 'Dark',\n light: 'Light',\n system: 'System',\n theme: {\n one: 'Theme',\n other: 'Themes'\n }\n },\n de: {\n dark: 'Dunkel',\n light: 'Hell',\n system: 'System',\n theme: {\n one: 'Farbschema',\n other: 'Farbschemas'\n }\n }\n}\n\nexport const ThemeUtil = {\n themes,\n translation: defaultThemeTypeTranslation,\n}\n\ntype ThemeContextType = {\n theme: ThemeType,\n resolvedTheme: ResolvedTheme,\n setTheme: Dispatch<SetStateAction<ThemeType>>,\n}\n\nexport const ThemeContext = createContext<ThemeContextType | null>(null)\n\ntype ThemeProviderProps = {\n /**\n * Only set this if you want to control the theme yourself\n */\n theme?: ThemeType,\n}\n\nexport const ThemeProvider = ({ children, theme }: PropsWithChildren<ThemeProviderProps>) => {\n const {\n value: storedTheme,\n setValue: setStoredTheme,\n deleteValue: deleteStoredTheme\n } = useLocalStorage<ThemeType>('theme', 'system')\n const [themePreference, setThemePreference] = useState<ThemeType>('system')\n\n const resolvedTheme = useMemo((): ResolvedTheme => {\n if (theme && theme !== 'system') {\n return theme\n }\n if (storedTheme && storedTheme !== 'system') {\n return storedTheme\n }\n if (themePreference !== 'system') {\n return themePreference\n }\n return 'light'\n }, [storedTheme, theme, themePreference])\n\n useEffect(() => {\n if (theme === 'system') {\n deleteStoredTheme()\n } else {\n setStoredTheme(theme)\n }\n }, [theme]) // eslint-disable-line react-hooks/exhaustive-deps\n\n useEffect(() => {\n document.documentElement.setAttribute('data-theme', resolvedTheme)\n }, [resolvedTheme])\n\n const getPreference = useCallback(() => {\n const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches\n const prefersLight = window.matchMedia('(prefers-color-scheme: light)').matches\n setThemePreference(prefersDark ? 'dark' : (prefersLight ? 'light' : 'system'))\n }, [])\n\n useEffect(() => {\n getPreference()\n }, [getPreference])\n\n useEffect(() => {\n const darkQuery = window.matchMedia('(prefers-color-scheme: dark)')\n const lightQuery = window.matchMedia('(prefers-color-scheme: light)')\n const noPrefQuery = window.matchMedia('(prefers-color-scheme: no-preference)')\n darkQuery.addEventListener('change', getPreference)\n lightQuery.addEventListener('change', getPreference)\n noPrefQuery.addEventListener('change', getPreference)\n return () => {\n darkQuery.removeEventListener('change', getPreference)\n lightQuery.removeEventListener('change', getPreference)\n noPrefQuery.removeEventListener('change', getPreference)\n }\n }, [getPreference])\n\n return (\n <ThemeContext.Provider\n value={{\n theme: storedTheme,\n resolvedTheme,\n setTheme: (newTheme) => {\n if (theme) {\n console.warn('ThemeProvider: Attempting to change the ' +\n \"theme while setting a fixed theme won't have any effect. \" +\n 'Change the theme provided to the ThemeProvider instead.')\n }\n setStoredTheme(newTheme)\n }\n }}\n >\n {children}\n </ThemeContext.Provider>\n )\n}\n\nexport const useTheme = () => {\n const context = useContext(ThemeContext)\n if (!context) {\n throw new Error('useTheme must be used within ThemeContext. Try adding a ThemeProvider around your app.')\n }\n return context\n}\n","'use client'\n\nimport type { Dispatch, SetStateAction } from 'react'\nimport { useCallback, useState } from 'react'\nimport { LocalStorageService } from '@/src/utils/storage'\nimport { resolveSetState } from '@/src/utils/resolveSetState'\n\ntype SetValue<T> = Dispatch<SetStateAction<T>>\n\ntype UseLocalStorageResult<T> = {\n value: T,\n setValue: SetValue<T>,\n deleteValue: () => void,\n}\n\n/**\n * @param key Key under which to save the data\n * @param backupValue Used if the storage is unavailable or no value is present\n *\n * The backup value will never be saved to the storage unless you explicitly\n */\nexport const useLocalStorage = <T>(key: string, backupValue: T): UseLocalStorageResult<T> => {\n const get = useCallback((): T => {\n if (typeof window === 'undefined') {\n return backupValue\n }\n const storageService = new LocalStorageService()\n const value = storageService.get<T>(key)\n return value || backupValue\n }, [backupValue, key])\n\n const [storedValue, setStoredValue] = useState<T>(get)\n\n const setValue: SetValue<T> = useCallback(action => {\n const newValue = resolveSetState(action, storedValue)\n const storageService = new LocalStorageService()\n storageService.set(key, newValue)\n\n setStoredValue(newValue)\n }, [storedValue, setStoredValue, key])\n\n const deleteValue = () => {\n const storageService = new LocalStorageService()\n storageService.delete(key)\n setStoredValue(backupValue)\n }\n\n return { value: storedValue, setValue, deleteValue }\n}","class StorageService {\n // this seems to be a bug in eslint as 'paramter-properties' is a special syntax of typescript\n\n constructor(private storage: Storage) {\n }\n\n public get<T>(key: string): T | null {\n const value = this.storage.getItem(key)\n if (value === null) {\n return null\n }\n return JSON.parse(value)\n }\n\n public set<T>(key: string, value: T) {\n this.storage.setItem(key, JSON.stringify(value))\n }\n\n public delete(key: string) {\n this.storage.removeItem(key)\n }\n\n public deleteAll() {\n this.storage.clear()\n }\n}\n\nexport class LocalStorageService extends StorageService {\n constructor() {\n super(window.localStorage)\n }\n}\n\nexport class SessionStorageService extends StorageService {\n constructor() {\n super(window.sessionStorage)\n }\n}\n","import type { SetStateAction } from 'react'\n\nexport function resolveSetState<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AM,wFAAwF;AAAA,EAC1G;AACA,SAAO;AACT;","names":["import_react"]}
1
+ {"version":3,"sources":["../../src/theming/useTheme.tsx","../../src/hooks/useLocalStorage.ts","../../src/utils/storage.ts","../../src/utils/resolveSetState.ts"],"sourcesContent":["import type { Dispatch, PropsWithChildren, SetStateAction } from 'react'\nimport { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'\nimport type { Translation, TranslationPlural } from '../localization/useTranslation'\nimport { useLocalStorage } from '../hooks/useLocalStorage'\n\nconst themes = ['light', 'dark', 'system'] as const\n\nexport type ThemeType = typeof themes[number]\nexport type ResolvedTheme = Exclude<ThemeType, 'system'>\n\nexport type ThemeTypeTranslation = Record<ThemeType, string> & {\n theme: TranslationPlural,\n}\n\nconst defaultThemeTypeTranslation: Translation<ThemeTypeTranslation> = {\n en: {\n dark: 'Dark',\n light: 'Light',\n system: 'System',\n theme: {\n one: 'Theme',\n other: 'Themes'\n }\n },\n de: {\n dark: 'Dunkel',\n light: 'Hell',\n system: 'System',\n theme: {\n one: 'Farbschema',\n other: 'Farbschemas'\n }\n }\n}\n\nexport const ThemeUtil = {\n themes,\n translation: defaultThemeTypeTranslation,\n}\n\ntype ThemeContextType = {\n theme: ThemeType,\n resolvedTheme: ResolvedTheme,\n setTheme: Dispatch<SetStateAction<ThemeType>>,\n}\n\nexport const ThemeContext = createContext<ThemeContextType | null>(null)\n\ntype ThemeProviderProps = {\n /**\n * Only set this if you want to control the theme yourself\n */\n theme?: ThemeType,\n}\n\nexport const ThemeProvider = ({ children, theme }: PropsWithChildren<ThemeProviderProps>) => {\n const {\n value: storedTheme,\n setValue: setStoredTheme,\n deleteValue: deleteStoredTheme\n } = useLocalStorage<ThemeType>('theme', 'system')\n const [themePreference, setThemePreference] = useState<ThemeType>('system')\n\n const resolvedTheme = useMemo((): ResolvedTheme => {\n if (theme && theme !== 'system') {\n return theme\n }\n if (storedTheme && storedTheme !== 'system') {\n return storedTheme\n }\n if (themePreference !== 'system') {\n return themePreference\n }\n return 'light'\n }, [storedTheme, theme, themePreference])\n\n useEffect(() => {\n if(!theme) return\n if (theme === 'system') {\n deleteStoredTheme()\n } else {\n setStoredTheme(theme)\n }\n }, [theme]) // eslint-disable-line react-hooks/exhaustive-deps\n\n useEffect(() => {\n document.documentElement.setAttribute('data-theme', resolvedTheme)\n }, [resolvedTheme])\n\n const getPreference = useCallback(() => {\n const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches\n const prefersLight = window.matchMedia('(prefers-color-scheme: light)').matches\n setThemePreference(prefersDark ? 'dark' : (prefersLight ? 'light' : 'system'))\n }, [])\n\n useEffect(() => {\n getPreference()\n }, [getPreference])\n\n useEffect(() => {\n const darkQuery = window.matchMedia('(prefers-color-scheme: dark)')\n const lightQuery = window.matchMedia('(prefers-color-scheme: light)')\n const noPrefQuery = window.matchMedia('(prefers-color-scheme: no-preference)')\n darkQuery.addEventListener('change', getPreference)\n lightQuery.addEventListener('change', getPreference)\n noPrefQuery.addEventListener('change', getPreference)\n return () => {\n darkQuery.removeEventListener('change', getPreference)\n lightQuery.removeEventListener('change', getPreference)\n noPrefQuery.removeEventListener('change', getPreference)\n }\n }, [getPreference])\n\n return (\n <ThemeContext.Provider\n value={{\n theme: storedTheme,\n resolvedTheme,\n setTheme: (newTheme) => {\n if (theme) {\n console.warn('ThemeProvider: Attempting to change the ' +\n \"theme while setting a fixed theme won't have any effect. \" +\n 'Change the theme provided to the ThemeProvider instead.')\n }\n setStoredTheme(newTheme)\n }\n }}\n >\n {children}\n </ThemeContext.Provider>\n )\n}\n\nexport const useTheme = () => {\n const context = useContext(ThemeContext)\n if (!context) {\n throw new Error('useTheme must be used within ThemeContext. Try adding a ThemeProvider around your app.')\n }\n return context\n}\n","'use client'\n\nimport type { Dispatch, SetStateAction } from 'react'\nimport { useCallback, useState } from 'react'\nimport { LocalStorageService } from '@/src/utils/storage'\nimport { resolveSetState } from '@/src/utils/resolveSetState'\n\ntype SetValue<T> = Dispatch<SetStateAction<T>>\n\ntype UseLocalStorageResult<T> = {\n value: T,\n setValue: SetValue<T>,\n deleteValue: () => void,\n}\n\n/**\n * @param key Key under which to save the data\n * @param backupValue Used if the storage is unavailable or no value is present\n *\n * The backup value will never be saved to the storage unless you explicitly\n */\nexport const useLocalStorage = <T>(key: string, backupValue: T): UseLocalStorageResult<T> => {\n const get = useCallback((): T => {\n if (typeof window === 'undefined') {\n return backupValue\n }\n const storageService = new LocalStorageService()\n try {\n const value = storageService.get<T>(key)\n return value || backupValue\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (_) {\n console.warn('useLocalStorage: Error while reading the stored value. Make sure your typing is correct.')\n storageService.delete(key)\n console.info(`useLocalStorage: deleted erroneous value for key: ${key}`)\n return backupValue\n }\n }, [backupValue, key])\n\n const [storedValue, setStoredValue] = useState<T>(get)\n\n const setValue: SetValue<T> = useCallback(action => {\n const newValue = resolveSetState(action, storedValue)\n const storageService = new LocalStorageService()\n storageService.set(key, newValue)\n\n setStoredValue(newValue)\n }, [storedValue, setStoredValue, key])\n\n const deleteValue = () => {\n const storageService = new LocalStorageService()\n storageService.delete(key)\n setStoredValue(backupValue)\n }\n\n return { value: storedValue, setValue, deleteValue }\n}","class StorageService {\n // this seems to be a bug in eslint as 'paramter-properties' is a special syntax of typescript\n\n constructor(private storage: Storage) {\n }\n\n public get<T>(key: string): T | null {\n const value = this.storage.getItem(key)\n if (value === null) {\n return null\n }\n return JSON.parse(value)\n }\n\n public set<T>(key: string, value: T) {\n this.storage.setItem(key, JSON.stringify(value))\n }\n\n public delete(key: string) {\n this.storage.removeItem(key)\n }\n\n public deleteAll() {\n this.storage.clear()\n }\n}\n\nexport class LocalStorageService extends StorageService {\n constructor() {\n super(window.localStorage)\n }\n}\n\nexport class SessionStorageService extends StorageService {\n constructor() {\n super(window.sessionStorage)\n }\n}\n","import type { SetStateAction } from 'react'\n\nexport function resolveSetState<T>(action: SetStateAction<T>, prev: T): T {\n return typeof action === 'function' ? (action as (prev: T) => T)(prev) : action\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J;AAEO,IAAM,WAAW,MAAM;AAC5B,QAAM,cAAU,0BAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,wFAAwF;AAAA,EAC1G;AACA,SAAO;AACT;","names":["import_react"]}
@@ -45,8 +45,15 @@ var useLocalStorage = (key, backupValue) => {
45
45
  return backupValue;
46
46
  }
47
47
  const storageService = new LocalStorageService();
48
- const value = storageService.get(key);
49
- return value || backupValue;
48
+ try {
49
+ const value = storageService.get(key);
50
+ return value || backupValue;
51
+ } catch (_) {
52
+ console.warn("useLocalStorage: Error while reading the stored value. Make sure your typing is correct.");
53
+ storageService.delete(key);
54
+ console.info(`useLocalStorage: deleted erroneous value for key: ${key}`);
55
+ return backupValue;
56
+ }
50
57
  }, [backupValue, key]);
51
58
  const [storedValue, setStoredValue] = useState(get);
52
59
  const setValue = useCallback((action) => {
@@ -111,6 +118,7 @@ var ThemeProvider = ({ children, theme }) => {
111
118
  return "light";
112
119
  }, [storedTheme, theme, themePreference]);
113
120
  useEffect(() => {
121
+ if (!theme) return;
114
122
  if (theme === "system") {
115
123
  deleteStoredTheme();
116
124
  } else {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/theming/useTheme.tsx","../../src/hooks/useLocalStorage.ts","../../src/utils/storage.ts","../../src/utils/resolveSetState.ts"],"sourcesContent":["import type { Dispatch, PropsWithChildren, SetStateAction } from 'react'\nimport { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'\nimport type { Translation, TranslationPlural } from '../localization/useTranslation'\nimport { useLocalStorage } from '../hooks/useLocalStorage'\n\nconst themes = ['light', 'dark', 'system'] as const\n\nexport type ThemeType = typeof themes[number]\nexport type ResolvedTheme = Exclude<ThemeType, 'system'>\n\nexport type ThemeTypeTranslation = Record<ThemeType, string> & {\n theme: TranslationPlural,\n}\n\nconst defaultThemeTypeTranslation: Translation<ThemeTypeTranslation> = {\n en: {\n dark: 'Dark',\n light: 'Light',\n system: 'System',\n theme: {\n one: 'Theme',\n other: 'Themes'\n }\n },\n de: {\n dark: 'Dunkel',\n light: 'Hell',\n system: 'System',\n theme: {\n one: 'Farbschema',\n other: 'Farbschemas'\n }\n }\n}\n\nexport const ThemeUtil = {\n themes,\n translation: defaultThemeTypeTranslation,\n}\n\ntype ThemeContextType = {\n theme: ThemeType,\n resolvedTheme: ResolvedTheme,\n setTheme: Dispatch<SetStateAction<ThemeType>>,\n}\n\nexport const ThemeContext = createContext<ThemeContextType | null>(null)\n\ntype ThemeProviderProps = {\n /**\n * Only set this if you want to control the theme yourself\n */\n theme?: ThemeType,\n}\n\nexport const ThemeProvider = ({ children, theme }: PropsWithChildren<ThemeProviderProps>) => {\n const {\n value: storedTheme,\n setValue: setStoredTheme,\n deleteValue: deleteStoredTheme\n } = useLocalStorage<ThemeType>('theme', 'system')\n const [themePreference, setThemePreference] = useState<ThemeType>('system')\n\n const resolvedTheme = useMemo((): ResolvedTheme => {\n if (theme && theme !== 'system') {\n return theme\n }\n if (storedTheme && storedTheme !== 'system') {\n return storedTheme\n }\n if (themePreference !== 'system') {\n return themePreference\n }\n return 'light'\n }, [storedTheme, theme, themePreference])\n\n useEffect(() => {\n if (theme === 'system') {\n deleteStoredTheme()\n } else {\n setStoredTheme(theme)\n }\n }, [theme]) // eslint-disable-line react-hooks/exhaustive-deps\n\n useEffect(() => {\n document.documentElement.setAttribute('data-theme', resolvedTheme)\n }, [resolvedTheme])\n\n const getPreference = useCallback(() => {\n const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches\n const prefersLight = window.matchMedia('(prefers-color-scheme: light)').matches\n setThemePreference(prefersDark ? 'dark' : (prefersLight ? 'light' : 'system'))\n }, [])\n\n useEffect(() => {\n getPreference()\n }, [getPreference])\n\n useEffect(() => {\n const darkQuery = window.matchMedia('(prefers-color-scheme: dark)')\n const lightQuery = window.matchMedia('(prefers-color-scheme: light)')\n const noPrefQuery = window.matchMedia('(prefers-color-scheme: no-preference)')\n darkQuery.addEventListener('change', getPreference)\n lightQuery.addEventListener('change', getPreference)\n noPrefQuery.addEventListener('change', getPreference)\n return () => {\n darkQuery.removeEventListener('change', getPreference)\n lightQuery.removeEventListener('change', getPreference)\n noPrefQuery.removeEventListener('change', getPreference)\n }\n }, [getPreference])\n\n return (\n <ThemeContext.Provider\n value={{\n theme: storedTheme,\n resolvedTheme,\n setTheme: (newTheme) => {\n if (theme) {\n console.warn('ThemeProvider: Attempting to change the ' +\n \"theme while setting a fixed theme won't have any effect. \" +\n 'Change the theme provided to the ThemeProvider instead.')\n }\n setStoredTheme(newTheme)\n }\n }}\n >\n {children}\n </ThemeContext.Provider>\n )\n}\n\nexport const useTheme = () => {\n const context = useContext(ThemeContext)\n if (!context) {\n throw new Error('useTheme must be used within ThemeContext. Try adding a ThemeProvider around your app.')\n }\n return context\n}\n","'use client'\n\nimport type { Dispatch, SetStateAction } from 'react'\nimport { useCallback, useState } from 'react'\nimport { LocalStorageService } from '@/src/utils/storage'\nimport { resolveSetState } from '@/src/utils/resolveSetState'\n\ntype SetValue<T> = Dispatch<SetStateAction<T>>\n\ntype UseLocalStorageResult<T> = {\n value: T,\n setValue: SetValue<T>,\n deleteValue: () => void,\n}\n\n/**\n * @param key Key under which to save the data\n * @param backupValue Used if the storage is unavailable or no value is present\n *\n * The backup value will never be saved to the storage unless you explicitly\n */\nexport const useLocalStorage = <T>(key: string, backupValue: T): UseLocalStorageResult<T> => {\n const get = useCallback((): T => {\n if (typeof window === 'undefined') {\n return backupValue\n }\n const storageService = new LocalStorageService()\n const value = storageService.get<T>(key)\n return value || backupValue\n }, [backupValue, key])\n\n const [storedValue, setStoredValue] = useState<T>(get)\n\n const setValue: SetValue<T> = useCallback(action => {\n const newValue = resolveSetState(action, storedValue)\n const storageService = new LocalStorageService()\n storageService.set(key, newValue)\n\n setStoredValue(newValue)\n }, [storedValue, setStoredValue, key])\n\n const deleteValue = () => {\n const storageService = new LocalStorageService()\n storageService.delete(key)\n setStoredValue(backupValue)\n }\n\n return { value: storedValue, setValue, deleteValue }\n}","class StorageService {\n // this seems to be a bug in eslint as 'paramter-properties' is a special syntax of typescript\n\n constructor(private storage: Storage) {\n }\n\n public get<T>(key: string): T | null {\n const value = this.storage.getItem(key)\n if (value === null) {\n return null\n }\n return JSON.parse(value)\n }\n\n public set<T>(key: string, value: T) {\n this.storage.setItem(key, JSON.stringify(value))\n }\n\n public delete(key: string) {\n this.storage.removeItem(key)\n }\n\n public deleteAll() {\n this.storage.clear()\n }\n}\n\nexport class LocalStorageService extends StorageService {\n constructor() {\n super(window.localStorage)\n }\n}\n\nexport class SessionStorageService extends StorageService {\n constructor() {\n super(window.sessionStorage)\n }\n}\n","import type { SetStateAction } from 'react'\n\nexport function resolveSetState<T>(action: SetStateAction<T>, prev: T): T {\n return typeof action === 'function' ? (action as (prev: T) => T)(prev) : action\n}"],"mappings":";AACA,SAAS,eAAe,eAAAA,cAAa,YAAY,WAAW,SAAS,YAAAC,iBAAgB;;;ACErF,SAAS,aAAa,gBAAgB;;;ACHtC,IAAM,iBAAN,MAAqB;AAAA;AAAA,EAGnB,YAAoB,SAAkB;AAAlB;AAAA,EACpB;AAAA,EAEO,IAAO,KAAuB;AACnC,UAAM,QAAQ,KAAK,QAAQ,QAAQ,GAAG;AACtC,QAAI,UAAU,MAAM;AAClB,aAAO;AAAA,IACT;AACA,WAAO,KAAK,MAAM,KAAK;AAAA,EACzB;AAAA,EAEO,IAAO,KAAa,OAAU;AACnC,SAAK,QAAQ,QAAQ,KAAK,KAAK,UAAU,KAAK,CAAC;AAAA,EACjD;AAAA,EAEO,OAAO,KAAa;AACzB,SAAK,QAAQ,WAAW,GAAG;AAAA,EAC7B;AAAA,EAEO,YAAY;AACjB,SAAK,QAAQ,MAAM;AAAA,EACrB;AACF;AAEO,IAAM,sBAAN,cAAkC,eAAe;AAAA,EACtD,cAAc;AACZ,UAAM,OAAO,YAAY;AAAA,EAC3B;AACF;;;AC7BO,SAAS,gBAAmB,QAA2B,MAAY;AACxE,SAAO,OAAO,WAAW,aAAc,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aAAa;AAAA,IACzD;AAAA,EACF,GAAG,CAAC,aAAa,CAAC;AAElB,SACE;AAAA,IAAC,aAAa;AAAA,IAAb;AAAA,MACC,OAAO;AAAA,QACL,OAAO;AAAA,QACP;AAAA,QACA,UAAU,CAAC,aAAa;AACtB,cAAI,OAAO;AACT,oBAAQ,KAAK,0JAE8C;AAAA,UAC7D;AACA,yBAAe,QAAQ;AAAA,QACzB;AAAA,MACF;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;AAEO,IAAM,WAAW,MAAM;AAC5B,QAAM,UAAU,WAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,wFAAwF;AAAA,EAC1G;AACA,SAAO;AACT;","names":["useCallback","useState","useState","useCallback"]}
1
+ {"version":3,"sources":["../../src/theming/useTheme.tsx","../../src/hooks/useLocalStorage.ts","../../src/utils/storage.ts","../../src/utils/resolveSetState.ts"],"sourcesContent":["import type { Dispatch, PropsWithChildren, SetStateAction } from 'react'\nimport { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'\nimport type { Translation, TranslationPlural } from '../localization/useTranslation'\nimport { useLocalStorage } from '../hooks/useLocalStorage'\n\nconst themes = ['light', 'dark', 'system'] as const\n\nexport type ThemeType = typeof themes[number]\nexport type ResolvedTheme = Exclude<ThemeType, 'system'>\n\nexport type ThemeTypeTranslation = Record<ThemeType, string> & {\n theme: TranslationPlural,\n}\n\nconst defaultThemeTypeTranslation: Translation<ThemeTypeTranslation> = {\n en: {\n dark: 'Dark',\n light: 'Light',\n system: 'System',\n theme: {\n one: 'Theme',\n other: 'Themes'\n }\n },\n de: {\n dark: 'Dunkel',\n light: 'Hell',\n system: 'System',\n theme: {\n one: 'Farbschema',\n other: 'Farbschemas'\n }\n }\n}\n\nexport const ThemeUtil = {\n themes,\n translation: defaultThemeTypeTranslation,\n}\n\ntype ThemeContextType = {\n theme: ThemeType,\n resolvedTheme: ResolvedTheme,\n setTheme: Dispatch<SetStateAction<ThemeType>>,\n}\n\nexport const ThemeContext = createContext<ThemeContextType | null>(null)\n\ntype ThemeProviderProps = {\n /**\n * Only set this if you want to control the theme yourself\n */\n theme?: ThemeType,\n}\n\nexport const ThemeProvider = ({ children, theme }: PropsWithChildren<ThemeProviderProps>) => {\n const {\n value: storedTheme,\n setValue: setStoredTheme,\n deleteValue: deleteStoredTheme\n } = useLocalStorage<ThemeType>('theme', 'system')\n const [themePreference, setThemePreference] = useState<ThemeType>('system')\n\n const resolvedTheme = useMemo((): ResolvedTheme => {\n if (theme && theme !== 'system') {\n return theme\n }\n if (storedTheme && storedTheme !== 'system') {\n return storedTheme\n }\n if (themePreference !== 'system') {\n return themePreference\n }\n return 'light'\n }, [storedTheme, theme, themePreference])\n\n useEffect(() => {\n if(!theme) return\n if (theme === 'system') {\n deleteStoredTheme()\n } else {\n setStoredTheme(theme)\n }\n }, [theme]) // eslint-disable-line react-hooks/exhaustive-deps\n\n useEffect(() => {\n document.documentElement.setAttribute('data-theme', resolvedTheme)\n }, [resolvedTheme])\n\n const getPreference = useCallback(() => {\n const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches\n const prefersLight = window.matchMedia('(prefers-color-scheme: light)').matches\n setThemePreference(prefersDark ? 'dark' : (prefersLight ? 'light' : 'system'))\n }, [])\n\n useEffect(() => {\n getPreference()\n }, [getPreference])\n\n useEffect(() => {\n const darkQuery = window.matchMedia('(prefers-color-scheme: dark)')\n const lightQuery = window.matchMedia('(prefers-color-scheme: light)')\n const noPrefQuery = window.matchMedia('(prefers-color-scheme: no-preference)')\n darkQuery.addEventListener('change', getPreference)\n lightQuery.addEventListener('change', getPreference)\n noPrefQuery.addEventListener('change', getPreference)\n return () => {\n darkQuery.removeEventListener('change', getPreference)\n lightQuery.removeEventListener('change', getPreference)\n noPrefQuery.removeEventListener('change', getPreference)\n }\n }, [getPreference])\n\n return (\n <ThemeContext.Provider\n value={{\n theme: storedTheme,\n resolvedTheme,\n setTheme: (newTheme) => {\n if (theme) {\n console.warn('ThemeProvider: Attempting to change the ' +\n \"theme while setting a fixed theme won't have any effect. \" +\n 'Change the theme provided to the ThemeProvider instead.')\n }\n setStoredTheme(newTheme)\n }\n }}\n >\n {children}\n </ThemeContext.Provider>\n )\n}\n\nexport const useTheme = () => {\n const context = useContext(ThemeContext)\n if (!context) {\n throw new Error('useTheme must be used within ThemeContext. Try adding a ThemeProvider around your app.')\n }\n return context\n}\n","'use client'\n\nimport type { Dispatch, SetStateAction } from 'react'\nimport { useCallback, useState } from 'react'\nimport { LocalStorageService } from '@/src/utils/storage'\nimport { resolveSetState } from '@/src/utils/resolveSetState'\n\ntype SetValue<T> = Dispatch<SetStateAction<T>>\n\ntype UseLocalStorageResult<T> = {\n value: T,\n setValue: SetValue<T>,\n deleteValue: () => void,\n}\n\n/**\n * @param key Key under which to save the data\n * @param backupValue Used if the storage is unavailable or no value is present\n *\n * The backup value will never be saved to the storage unless you explicitly\n */\nexport const useLocalStorage = <T>(key: string, backupValue: T): UseLocalStorageResult<T> => {\n const get = useCallback((): T => {\n if (typeof window === 'undefined') {\n return backupValue\n }\n const storageService = new LocalStorageService()\n try {\n const value = storageService.get<T>(key)\n return value || backupValue\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (_) {\n console.warn('useLocalStorage: Error while reading the stored value. Make sure your typing is correct.')\n storageService.delete(key)\n console.info(`useLocalStorage: deleted erroneous value for key: ${key}`)\n return backupValue\n }\n }, [backupValue, key])\n\n const [storedValue, setStoredValue] = useState<T>(get)\n\n const setValue: SetValue<T> = useCallback(action => {\n const newValue = resolveSetState(action, storedValue)\n const storageService = new LocalStorageService()\n storageService.set(key, newValue)\n\n setStoredValue(newValue)\n }, [storedValue, setStoredValue, key])\n\n const deleteValue = () => {\n const storageService = new LocalStorageService()\n storageService.delete(key)\n setStoredValue(backupValue)\n }\n\n return { value: storedValue, setValue, deleteValue }\n}","class StorageService {\n // this seems to be a bug in eslint as 'paramter-properties' is a special syntax of typescript\n\n constructor(private storage: Storage) {\n }\n\n public get<T>(key: string): T | null {\n const value = this.storage.getItem(key)\n if (value === null) {\n return null\n }\n return JSON.parse(value)\n }\n\n public set<T>(key: string, value: T) {\n this.storage.setItem(key, JSON.stringify(value))\n }\n\n public delete(key: string) {\n this.storage.removeItem(key)\n }\n\n public deleteAll() {\n this.storage.clear()\n }\n}\n\nexport class LocalStorageService extends StorageService {\n constructor() {\n super(window.localStorage)\n }\n}\n\nexport class SessionStorageService extends StorageService {\n constructor() {\n super(window.sessionStorage)\n }\n}\n","import type { SetStateAction } from 'react'\n\nexport function resolveSetState<T>(action: SetStateAction<T>, prev: T): T {\n return typeof action === 'function' ? (action as (prev: T) => T)(prev) : action\n}"],"mappings":";AACA,SAAS,eAAe,eAAAA,cAAa,YAAY,WAAW,SAAS,YAAAC,iBAAgB;;;ACErF,SAAS,aAAa,gBAAgB;;;ACHtC,IAAM,iBAAN,MAAqB;AAAA;AAAA,EAGnB,YAAoB,SAAkB;AAAlB;AAAA,EACpB;AAAA,EAEO,IAAO,KAAuB;AACnC,UAAM,QAAQ,KAAK,QAAQ,QAAQ,GAAG;AACtC,QAAI,UAAU,MAAM;AAClB,aAAO;AAAA,IACT;AACA,WAAO,KAAK,MAAM,KAAK;AAAA,EACzB;AAAA,EAEO,IAAO,KAAa,OAAU;AACnC,SAAK,QAAQ,QAAQ,KAAK,KAAK,UAAU,KAAK,CAAC;AAAA,EACjD;AAAA,EAEO,OAAO,KAAa;AACzB,SAAK,QAAQ,WAAW,GAAG;AAAA,EAC7B;AAAA,EAEO,YAAY;AACjB,SAAK,QAAQ,MAAM;AAAA,EACrB;AACF;AAEO,IAAM,sBAAN,cAAkC,eAAe;AAAA,EACtD,cAAc;AACZ,UAAM,OAAO,YAAY;AAAA,EAC3B;AACF;;;AC7BO,SAAS,gBAAmB,QAA2B,MAAY;AACxE,SAAO,OAAO,WAAW,aAAc,OAA0B,IAAI,IAAI;AAC3E;;;AFiBO,IAAM,kBAAkB,CAAI,KAAa,gBAA6C;AAC3F,Q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X,gBAAU,oBAAoB,UAAU,aAAa;AACrD,iBAAW,oBAAoB,UAAU,aAAa;AACtD,kBAAY,oBAAoB,UAAU,aAAa;AAAA,IACzD;AAAA,EACF,GAAG,CAAC,aAAa,CAAC;AAElB,SACE;AAAA,IAAC,aAAa;AAAA,IAAb;AAAA,MACC,OAAO;AAAA,QACL,OAAO;AAAA,QACP;AAAA,QACA,UAAU,CAAC,aAAa;AACtB,cAAI,OAAO;AACT,oBAAQ,KAAK,0JAE8C;AAAA,UAC7D;AACA,yBAAe,QAAQ;AAAA,QACzB;AAAA,MACF;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;AAEO,IAAM,WAAW,MAAM;AAC5B,QAAM,UAAU,WAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,wFAAwF;AAAA,EAC1G;AACA,SAAO;AACT;","names":["useCallback","useState","useState","useCallback"]}
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "url": "git+https://github.com/helpwave/hightide.git"
8
8
  },
9
9
  "license": "MPL-2.0",
10
- "version": "0.1.35",
10
+ "version": "0.1.36",
11
11
  "files": [
12
12
  "dist"
13
13
  ],