@helpwave/hightide 0.1.37 → 0.1.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/date/DatePicker.js.map +1 -1
- package/dist/components/date/DatePicker.mjs.map +1 -1
- package/dist/components/date/DayPicker.js.map +1 -1
- package/dist/components/date/DayPicker.mjs.map +1 -1
- package/dist/components/date/TimeDisplay.js.map +1 -1
- package/dist/components/date/TimeDisplay.mjs.map +1 -1
- package/dist/components/date/YearMonthPicker.js.map +1 -1
- package/dist/components/date/YearMonthPicker.mjs.map +1 -1
- package/dist/components/date/index.js.map +1 -1
- package/dist/components/date/index.mjs.map +1 -1
- package/dist/components/dialog/ConfirmDialog.js +15 -9
- package/dist/components/dialog/ConfirmDialog.js.map +1 -1
- package/dist/components/dialog/ConfirmDialog.mjs +16 -10
- package/dist/components/dialog/ConfirmDialog.mjs.map +1 -1
- package/dist/components/dialog/Dialog.d.mts +4 -5
- package/dist/components/dialog/Dialog.d.ts +4 -5
- package/dist/components/dialog/Dialog.js +15 -9
- package/dist/components/dialog/Dialog.js.map +1 -1
- package/dist/components/dialog/Dialog.mjs +16 -10
- package/dist/components/dialog/Dialog.mjs.map +1 -1
- package/dist/components/dialog/DiscardChangesDialog.js +15 -9
- package/dist/components/dialog/DiscardChangesDialog.js.map +1 -1
- package/dist/components/dialog/DiscardChangesDialog.mjs +16 -10
- package/dist/components/dialog/DiscardChangesDialog.mjs.map +1 -1
- package/dist/components/dialog/InputDialog.js +15 -9
- package/dist/components/dialog/InputDialog.js.map +1 -1
- package/dist/components/dialog/InputDialog.mjs +16 -10
- package/dist/components/dialog/InputDialog.mjs.map +1 -1
- package/dist/components/dialog/LanguageDialog.js +188 -154
- package/dist/components/dialog/LanguageDialog.js.map +1 -1
- package/dist/components/dialog/LanguageDialog.mjs +151 -116
- package/dist/components/dialog/LanguageDialog.mjs.map +1 -1
- package/dist/components/dialog/ThemeDialog.js +191 -157
- package/dist/components/dialog/ThemeDialog.js.map +1 -1
- package/dist/components/dialog/ThemeDialog.mjs +151 -116
- package/dist/components/dialog/ThemeDialog.mjs.map +1 -1
- package/dist/components/dialog/index.js +205 -171
- package/dist/components/dialog/index.js.map +1 -1
- package/dist/components/dialog/index.mjs +152 -117
- package/dist/components/dialog/index.mjs.map +1 -1
- package/dist/components/index.js +337 -299
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +198 -159
- package/dist/components/index.mjs.map +1 -1
- package/dist/components/layout/Carousel.d.mts +2 -1
- package/dist/components/layout/Carousel.d.ts +2 -1
- package/dist/components/layout/Carousel.js +4 -0
- package/dist/components/layout/Carousel.js.map +1 -1
- package/dist/components/layout/Carousel.mjs +4 -0
- package/dist/components/layout/Carousel.mjs.map +1 -1
- package/dist/components/layout/TextImage.js.map +1 -1
- package/dist/components/layout/TextImage.mjs.map +1 -1
- package/dist/components/layout/index.js +4 -0
- package/dist/components/layout/index.js.map +1 -1
- package/dist/components/layout/index.mjs +4 -0
- package/dist/components/layout/index.mjs.map +1 -1
- package/dist/components/loading-states/ErrorComponent.js.map +1 -1
- package/dist/components/loading-states/ErrorComponent.mjs.map +1 -1
- package/dist/components/loading-states/LoadingAnimation.js.map +1 -1
- package/dist/components/loading-states/LoadingAnimation.mjs.map +1 -1
- package/dist/components/loading-states/index.js.map +1 -1
- package/dist/components/loading-states/index.mjs.map +1 -1
- package/dist/components/navigation/Pagination.js.map +1 -1
- package/dist/components/navigation/Pagination.mjs.map +1 -1
- package/dist/components/navigation/StepperBar.js.map +1 -1
- package/dist/components/navigation/StepperBar.mjs.map +1 -1
- package/dist/components/navigation/index.js.map +1 -1
- package/dist/components/navigation/index.mjs.map +1 -1
- package/dist/components/properties/CheckboxProperty.js.map +1 -1
- package/dist/components/properties/CheckboxProperty.mjs.map +1 -1
- package/dist/components/properties/DateProperty.js.map +1 -1
- package/dist/components/properties/DateProperty.mjs.map +1 -1
- package/dist/components/properties/MultiSelectProperty.js +129 -101
- package/dist/components/properties/MultiSelectProperty.js.map +1 -1
- package/dist/components/properties/MultiSelectProperty.mjs +131 -102
- package/dist/components/properties/MultiSelectProperty.mjs.map +1 -1
- package/dist/components/properties/NumberProperty.js.map +1 -1
- package/dist/components/properties/NumberProperty.mjs.map +1 -1
- package/dist/components/properties/PropertyBase.js.map +1 -1
- package/dist/components/properties/PropertyBase.mjs.map +1 -1
- package/dist/components/properties/SelectProperty.js +129 -101
- package/dist/components/properties/SelectProperty.js.map +1 -1
- package/dist/components/properties/SelectProperty.mjs +131 -102
- package/dist/components/properties/SelectProperty.mjs.map +1 -1
- package/dist/components/properties/TextProperty.js.map +1 -1
- package/dist/components/properties/TextProperty.mjs.map +1 -1
- package/dist/components/properties/index.js +129 -101
- package/dist/components/properties/index.js.map +1 -1
- package/dist/components/properties/index.mjs +131 -102
- package/dist/components/properties/index.mjs.map +1 -1
- package/dist/components/table/Table.js.map +1 -1
- package/dist/components/table/Table.mjs.map +1 -1
- package/dist/components/table/TableFilterButton.js.map +1 -1
- package/dist/components/table/TableFilterButton.mjs.map +1 -1
- package/dist/components/table/index.js.map +1 -1
- package/dist/components/table/index.mjs.map +1 -1
- package/dist/components/user-action/CopyToClipboardWrapper.js.map +1 -1
- package/dist/components/user-action/CopyToClipboardWrapper.mjs.map +1 -1
- package/dist/components/user-action/DateAndTimePicker.js.map +1 -1
- package/dist/components/user-action/DateAndTimePicker.mjs.map +1 -1
- package/dist/components/user-action/SearchBar.js.map +1 -1
- package/dist/components/user-action/SearchBar.mjs.map +1 -1
- package/dist/components/user-action/index.js +129 -101
- package/dist/components/user-action/index.js.map +1 -1
- package/dist/components/user-action/index.mjs +131 -102
- package/dist/components/user-action/index.mjs.map +1 -1
- package/dist/components/user-action/select/Select.d.mts +2 -0
- package/dist/components/user-action/select/Select.d.ts +2 -0
- package/dist/components/user-action/select/Select.js +129 -101
- package/dist/components/user-action/select/Select.js.map +1 -1
- package/dist/components/user-action/select/Select.mjs +131 -102
- package/dist/components/user-action/select/Select.mjs.map +1 -1
- package/dist/components/user-action/select/index.js +129 -101
- package/dist/components/user-action/select/index.js.map +1 -1
- package/dist/components/user-action/select/index.mjs +131 -102
- package/dist/components/user-action/select/index.mjs.map +1 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/hooks/useValidators.js.map +1 -1
- package/dist/hooks/useValidators.mjs.map +1 -1
- package/dist/index.js +362 -324
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +206 -167
- package/dist/index.mjs.map +1 -1
- package/dist/localization/LanguageProvider.js +1 -1
- package/dist/localization/LanguageProvider.js.map +1 -1
- package/dist/localization/LanguageProvider.mjs +1 -1
- package/dist/localization/LanguageProvider.mjs.map +1 -1
- package/dist/localization/index.js +1 -1
- package/dist/localization/index.js.map +1 -1
- package/dist/localization/index.mjs +1 -1
- package/dist/localization/index.mjs.map +1 -1
- package/dist/localization/useTranslation.js.map +1 -1
- package/dist/localization/useTranslation.mjs.map +1 -1
- package/dist/style/globals.css +0 -3
- package/dist/theming/index.js +1 -1
- package/dist/theming/index.js.map +1 -1
- package/dist/theming/index.mjs +1 -1
- package/dist/theming/index.mjs.map +1 -1
- package/dist/theming/useTheme.js +1 -1
- package/dist/theming/useTheme.js.map +1 -1
- package/dist/theming/useTheme.mjs +1 -1
- package/dist/theming/useTheme.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -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) 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,KA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W,8BAA8B,EAAE;AACtE,UAAM,eAAe,OAAO,WAAW,+BAA+B,EAAE;AACxE,uBAAmB,cAAc,SAAU,eAAe,UAAU,QAAS;AAAA,EAC/E,GAAG,CAAC,CAAC;AAEL,+BAAU,MAAM;AACd,kBAAc;AAAA,EAChB,GAAG,CAAC,aAAa,CAAC;AAElB,+BAAU,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,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 && theme !== 'system') {\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;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Provider = ({ children, theme }) => {
|
|
|
156
156
|
theme: storedTheme,
|
|
157
157
|
resolvedTheme,
|
|
158
158
|
setTheme: (newTheme) => {
|
|
159
|
-
if (theme) {
|
|
159
|
+
if (theme && theme !== "system") {
|
|
160
160
|
console.warn("ThemeProvider: Attempting to change the theme while setting a fixed theme won't have any effect. Change the theme provided to the ThemeProvider instead.");
|
|
161
161
|
}
|
|
162
162
|
setStoredTheme(newTheme);
|
|
@@ -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) 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,QAAM,MAAM,YAAY,MAAS;AAC/B,QAAI,OAAO,WAAW,aAAa;AACjC,aAAO;AAAA,IACT;AACA,UAAM,iBAAiB,IAAI,oBAAoB;AAC/C,QAAI;AACF,YAAM,QAAQ,eAAe,IAAO,GAAG;AACvC,aAAO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a;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 && theme !== 'system') {\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,QAAM,MAAM,YAAY,MAAS;AAC/B,QAAI,OAAO,WAAW,aAAa;AACjC,aA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;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,SAAS,UAAU,UAAU;AAC/B,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/dist/theming/useTheme.js
CHANGED
|
@@ -182,7 +182,7 @@ var ThemeProvider = ({ children, theme }) => {
|
|
|
182
182
|
theme: storedTheme,
|
|
183
183
|
resolvedTheme,
|
|
184
184
|
setTheme: (newTheme) => {
|
|
185
|
-
if (theme) {
|
|
185
|
+
if (theme && theme !== "system") {
|
|
186
186
|
console.warn("ThemeProvider: Attempting to change the theme while setting a fixed theme won't have any effect. Change the theme provided to the ThemeProvider instead.");
|
|
187
187
|
}
|
|
188
188
|
setStoredTheme(newTheme);
|
|
@@ -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) 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;AACA,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,QA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Ae,OAAO,WAAW,+BAA+B,EAAE;AACxE,uBAAmB,cAAc,SAAU,eAAe,UAAU,QAAS;AAAA,EAC/E,GAAG,CAAC,CAAC;AAEL,+BAAU,MAAM;AACd,kBAAc;AAAA,EAChB,GAAG,CAAC,aAAa,CAAC;AAElB,+BAAU,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,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/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 && theme !== 'system') {\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;AACA,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,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ACnE,GAAG,CAAC,aAAa,CAAC;AAElB,QAAM,oBAAgB,2BAAY,MAAM;AACtC,UAAM,cAAc,OAAO,WAAW,8BAA8B,EAAE;AACtE,UAAM,eAAe,OAAO,WAAW,+BAA+B,EAAE;AACxE,uBAAmB,cAAc,SAAU,eAAe,UAAU,QAAS;AAAA,EAC/E,GAAG,CAAC,CAAC;AAEL,+BAAU,MAAM;AACd,kBAAc;AAAA,EAChB,GAAG,CAAC,aAAa,CAAC;AAElB,+BAAU,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,SAAS,UAAU,UAAU;AAC/B,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"]}
|
|
@@ -156,7 +156,7 @@ var ThemeProvider = ({ children, theme }) => {
|
|
|
156
156
|
theme: storedTheme,
|
|
157
157
|
resolvedTheme,
|
|
158
158
|
setTheme: (newTheme) => {
|
|
159
|
-
if (theme) {
|
|
159
|
+
if (theme && theme !== "system") {
|
|
160
160
|
console.warn("ThemeProvider: Attempting to change the theme while setting a fixed theme won't have any effect. Change the theme provided to the ThemeProvider instead.");
|
|
161
161
|
}
|
|
162
162
|
setStoredTheme(newTheme);
|
|
@@ -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) 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,QAAM,MAAM,YAAY,MAAS;AAC/B,QAAI,OAAO,WAAW,aAAa;AACjC,aAAO;AAAA,IACT;AACA,UAAM,iBAAiB,IAAI,oBAAoB;AAC/C,QAAI;AACF,YAAM,QAAQ,eAAe,IAAO,GAAG;AACvC,aAAO,SAAS;AAAA,IAElB,SAAS,GAAG;AACV,cAAQ,KAAK,0FAA0F;AACvG,qBAAe,OAAO,GAAG;AACzB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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 && theme !== 'system') {\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,QAAM,MAAM,YAAY,MAAS;AAC/B,QAAI,OAAO,WAAW,aAAa;AACjC,aAAO;AAAA,IACT;AACA,UAAM,iBAAiB,IAAI,oBAAoB;AAC/C,QAAI;AACF,YAAM,QAAQ,eAAe,IA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