@tamagui/web 1.14.6 → 1.14.8
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/cjs/helpers/ThemeManager.js +4 -1
- package/dist/cjs/helpers/ThemeManager.js.map +2 -2
- package/dist/cjs/hooks/useTheme.js +50 -24
- package/dist/cjs/hooks/useTheme.js.map +2 -2
- package/dist/cjs/views/ThemeDebug.js +57 -38
- package/dist/cjs/views/ThemeDebug.js.map +2 -2
- package/dist/esm/helpers/ThemeManager.js +4 -1
- package/dist/esm/helpers/ThemeManager.js.map +2 -2
- package/dist/esm/helpers/ThemeManager.mjs +4 -1
- package/dist/esm/helpers/ThemeManager.mjs.map +2 -2
- package/dist/esm/hooks/useTheme.js +50 -24
- package/dist/esm/hooks/useTheme.js.map +2 -2
- package/dist/esm/hooks/useTheme.mjs +50 -24
- package/dist/esm/hooks/useTheme.mjs.map +2 -2
- package/dist/esm/views/ThemeDebug.js +59 -40
- package/dist/esm/views/ThemeDebug.js.map +2 -2
- package/dist/esm/views/ThemeDebug.mjs +59 -40
- package/dist/esm/views/ThemeDebug.mjs.map +2 -2
- package/package.json +9 -9
- package/src/helpers/ThemeManager.tsx +5 -1
- package/src/hooks/useTheme.tsx +54 -26
- package/src/views/ThemeDebug.tsx +55 -34
- package/types/helpers/ThemeManager.d.ts.map +1 -1
- package/types/hooks/useTheme.d.ts.map +1 -1
- package/types/views/ThemeDebug.d.ts.map +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/helpers/ThemeManager.tsx"],
|
|
4
|
-
"sourcesContent": ["import { getThemes, getTokens } from '../config.js'\nimport { THEME_CLASSNAME_PREFIX, THEME_NAME_SEPARATOR } from '../constants/constants.js'\nimport { getThemeUnwrapped } from '../hooks/getThemeUnwrapped.js'\nimport { ThemeParsed, ThemeProps } from '../types.js'\n\ntype ThemeListener = (name: string | null, themeManager: ThemeManager) => void\n\nexport type SetActiveThemeProps = {\n className?: string\n parentManager?: ThemeManager | null\n name?: string | null\n theme?: any\n reset?: boolean\n}\n\nexport type ThemeManagerState = {\n name: string\n theme?: ThemeParsed | null\n className?: string\n parentName?: string\n}\n\nconst emptyState: ThemeManagerState = { name: '' }\n\nexport function hasNoThemeUpdatingProps(props: ThemeProps) {\n return !(props.name || props.componentName || props.inverse || props.reset)\n}\n\nlet uid = 0\n\nexport class ThemeManager {\n id = uid++\n isComponent = false\n themeListeners = new Set<ThemeListener>()\n parentManager: ThemeManager | null = null\n state: ThemeManagerState = emptyState\n\n constructor(\n public props: ThemeProps = {},\n parentManagerIn?: ThemeManager | 'root' | null | undefined\n ) {\n if (parentManagerIn === 'root') {\n this.updateState(props, false)\n return\n }\n\n const parentManager = getNonComponentParentManager(parentManagerIn)\n\n if (!parentManager) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `No parent manager given, this is likely due to duplicated Tamagui dependencies. Check your lockfile for mis-matched versions.`\n )\n }\n throw `\u274C`\n }\n\n // no change no props\n if (hasNoThemeUpdatingProps(props)) {\n return parentManager\n }\n\n if (parentManager) {\n this.parentManager = parentManager\n }\n\n if (this.updateState(props, false)) {\n return\n }\n\n return parentManager || this\n }\n\n updateState(\n props: ThemeProps & { forceTheme?: ThemeParsed } = this.props || {},\n shouldNotify = true\n ) {\n const isChanging = (() => {\n if (props.forceTheme) {\n this.state.theme = props.forceTheme\n this.state.name = props.name || ''\n return true\n }\n const nextState = this.getStateIfChanged(props)\n if (nextState) {\n this.props = props\n this.state = nextState\n return true\n }\n })()\n\n if (isChanging) {\n const names = this.state.name.split('_')\n const lastName = names[names.length - 1][0]\n this.isComponent = lastName[0] === lastName[0].toUpperCase()\n this._allKeys = null\n\n if (process.env.NODE_ENV === 'development') {\n this['_numChangeEventsSent'] ??= 0\n this['_numChangeEventsSent']++\n }\n\n if (shouldNotify) {\n this.notify()\n }\n\n return this.state\n }\n }\n\n getStateIfChanged(\n props = this.props,\n state: ThemeManagerState | null = this.state,\n parentManager = this.parentManager\n ) {\n const _ = this.getState(props, parentManager)\n // is removing\n if (state && state !== emptyState && !_) {\n return parentManager?.state\n }\n if (this.getStateShouldChange(_, state)) {\n return _\n }\n }\n\n getStateShouldChange(\n nextState: ThemeManagerState | null,\n state: ThemeManagerState | null = this.state\n ) {\n if (!nextState?.theme || nextState.theme === state?.theme) {\n return false\n }\n return true\n }\n\n getState(props = this.props, parentManager = this.parentManager) {\n return (\n getState(props, parentManager) ||\n (process.env.TAMAGUI_TARGET === 'native' ? parentManager?.state || null : null)\n )\n }\n\n _allKeys: Set<string> | null = null\n get allKeys() {\n this._allKeys ||= new Set([\n ...(this.parentManager?.allKeys || []),\n ...Object.keys(this.state.theme || {}),\n ])\n return this._allKeys\n }\n\n // gets value going up to parents\n getValue(key: string, state?: ThemeManagerState) {\n if (!key) return\n let theme = (state || this.state).theme\n let manager = this as ThemeManager | null\n while (theme && manager) {\n if (key in theme) {\n return theme[key]\n }\n manager = manager.parentManager\n theme = manager?.state.theme\n }\n const tokens = getTokens()\n if (key in tokens.color) {\n return tokens.color[key]\n }\n }\n\n notify() {\n this.themeListeners.forEach((cb) => cb(this.state.name, this))\n }\n\n onChangeTheme(cb: ThemeListener, debugId?: number) {\n if (process.env.NODE_ENV === 'development' && debugId) {\n // @ts-ignore\n this._listeningIds ??= new Set()\n // @ts-ignore\n this._listeningIds.add(debugId)\n }\n\n this.themeListeners.add(cb)\n return () => {\n this.themeListeners.delete(cb)\n }\n }\n}\n\nfunction getNextThemeClassName(name: string, props: ThemeProps) {\n const next = `t_sub_theme ${THEME_CLASSNAME_PREFIX}${name}`\n if (props.inverse || props.forceClassName) {\n return (\n next +\n // ensure you invert to base dark as well as specific dark\n // ... logic should likely be elsewhere\n (next.includes('dark_') ? ` t_dark` : next.includes('light_') ? ` t_light` : '')\n )\n }\n return next.replace('light_', '').replace('dark_', '')\n}\n\nfunction getState(\n props: ThemeProps,\n parentManager?: ThemeManager | null\n): ThemeManagerState | null {\n const themes = getThemes()\n\n if (props.name && props.reset) {\n throw new Error('Cannot reset + set new name')\n }\n\n if (props.reset && !parentManager?.parentManager) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('Cannot reset no grandparent exists')\n }\n return null\n }\n\n let result: ThemeManagerState | null = null\n\n const nextName = props.reset\n ? parentManager?.parentManager?.state?.name || ''\n : props.name || ''\n const { componentName } = props\n const parentName = parentManager?.state?.name || ''\n\n // components look for most specific, fallback upwards\n const base = parentName.split(THEME_NAME_SEPARATOR)\n const lastSegment = base[base.length - 1]\n const isParentComponentTheme =\n parentName && lastSegment[0].toUpperCase() === lastSegment[0]\n if (isParentComponentTheme) {\n base.pop() // always remove componentName they can't nest\n }\n const parentBaseTheme = isParentComponentTheme\n ? base.slice(0, base.length).join(THEME_NAME_SEPARATOR)\n : parentName\n const max = base.length\n const min =\n componentName && !nextName\n ? max // component name only don't search upwards\n : 0\n\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {\n console.groupCollapsed('ThemeManager.getState()')\n console.log({\n props,\n parentName,\n parentBaseTheme,\n base,\n min,\n max,\n isParentComponentTheme,\n })\n }\n\n for (let i = max; i >= min; i--) {\n let prefix = base.slice(0, i).join(THEME_NAME_SEPARATOR)\n if (props.inverse) {\n prefix = inverseThemeName(prefix)\n }\n const potentials: string[] = []\n if (prefix && prefix !== parentBaseTheme) {\n potentials.push(prefix)\n }\n if (nextName) {\n potentials.unshift(prefix ? `${prefix}_${nextName}` : nextName)\n }\n if (i === 1) {\n const lastSegment = potentials.findIndex((x) => !x.includes('_'))\n if (lastSegment > 0) {\n potentials.splice(lastSegment, 0, nextName) // last try prefer our new name to parent\n }\n }\n if (componentName) {\n // components only look for component themes\n if (nextName) {\n const beforeSeparator = prefix.slice(0, prefix.indexOf(THEME_NAME_SEPARATOR))\n potentials.push(`${beforeSeparator}_${nextName}_${componentName}`)\n }\n potentials.push(`${prefix}_${componentName}`)\n if (nextName) {\n potentials.unshift(`${prefix}_${nextName}_${componentName}`)\n }\n }\n\n const found = potentials.find((t) => t in themes)\n\n if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {\n console.log(' - ', { found, potentials })\n }\n\n if (found) {\n result = {\n name: found,\n theme: getThemeUnwrapped(themes[found]),\n className: getNextThemeClassName(found, props),\n parentName,\n }\n break\n }\n }\n\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {\n console.warn('ThemeManager.getState():', {\n result,\n })\n console.trace()\n console.groupEnd()\n }\n\n return result\n}\n\nconst inverseThemeName = (themeName: string) => {\n return themeName.startsWith('light')\n ? themeName.replace(/^light/, 'dark')\n : themeName.replace(/^dark/, 'light')\n}\n\nexport function getNonComponentParentManager(themeManager?: ThemeManager | null) {\n // components never inherit from components\n // example <Switch><Switch.Thumb /></Switch>\n // the Switch theme shouldn't be considered parent of Thumb\n let res = themeManager\n while (res) {\n if (res?.isComponent) {\n res = res.parentManager\n } else {\n break\n }\n }\n return res\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,WAAW,iBAAiB;AACrC,SAAS,wBAAwB,4BAA4B;AAC7D,SAAS,yBAAyB;AAoBlC,MAAM,aAAgC,EAAE,MAAM,GAAG;AAE1C,SAAS,wBAAwB,OAAmB;AACzD,SAAO,EAAE,MAAM,QAAQ,MAAM,iBAAiB,MAAM,WAAW,MAAM;AACvE;AAEA,IAAI,MAAM;AAEH,MAAM,aAAa;AAAA,EAOxB,YACS,QAAoB,CAAC,GAC5B,iBACA;AAFO;AAPT,cAAK;AACL,uBAAc;AACd,0BAAiB,oBAAI,IAAmB;AACxC,yBAAqC;AACrC,iBAA2B;AA2G3B,oBAA+B;AArG7B,QAAI,oBAAoB,QAAQ;AAC9B,WAAK,YAAY,OAAO,KAAK;AAC7B;AAAA,IACF;AAEA,UAAM,gBAAgB,6BAA6B,eAAe;AAElE,QAAI,CAAC,eAAe;AAClB,UAAI,QAAQ,IAAI,aAAa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AAQ,eAAe,yBAAyB;AAChD,YAAQ,IAAI;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAEA,WAAS,IAAI,KAAK,KAAK,KAAK,KAAK;AAC/B,QAAI,SAAS,KAAK,MAAM,GAAG,CAAC,EAAE,KAAK,oBAAoB;AACvD,QAAI,MAAM,SAAS;AACjB,eAAS,iBAAiB,MAAM;AAAA,IAClC;AACA,UAAM,aAAuB,CAAC;AAC9B,QAAI,UAAU,WAAW,iBAAiB;AACxC,iBAAW,KAAK,MAAM;AAAA,IACxB;AACA,QAAI,UAAU;AACZ,iBAAW,QAAQ,SAAS,GAAG,UAAU,aAAa,QAAQ;AAAA,IAChE;AACA,QAAI,MAAM,GAAG;AACX,YAAMA,eAAc,WAAW,UAAU,CAAC,MAAM,CAAC,EAAE,SAAS,GAAG,CAAC;AAChE,UAAIA,eAAc,GAAG;AACnB,mBAAW,OAAOA,cAAa,GAAG,QAAQ;AAAA,MAC5C;AAAA,IACF;AACA,QAAI,eAAe;AAEjB,UAAI,UAAU;AACZ,cAAM,kBAAkB,OAAO,MAAM,GAAG,OAAO,QAAQ,oBAAoB,CAAC;AAC5E,mBAAW,KAAK,GAAG,mBAAmB,YAAY,eAAe;AAAA,MACnE;AACA,iBAAW,KAAK,GAAG,UAAU,eAAe;AAC5C,UAAI,UAAU;AACZ,mBAAW,QAAQ,GAAG,UAAU,YAAY,eAAe;AAAA,MAC7D;AAAA,IACF;AAEA,UAAM,QAAQ,WAAW,KAAK,CAAC,MAAM,KAAK,MAAM;AAEhD,QAAI,QAAQ,IAAI,aAAa,iBAAiB,OAAO,MAAM,UAAU,UAAU;AAC7E,cAAQ,IAAI,OAAO,EAAE,OAAO,
|
|
4
|
+
"sourcesContent": ["import { getThemes, getTokens } from '../config.js'\nimport { THEME_CLASSNAME_PREFIX, THEME_NAME_SEPARATOR } from '../constants/constants.js'\nimport { getThemeUnwrapped } from '../hooks/getThemeUnwrapped.js'\nimport { ThemeParsed, ThemeProps } from '../types.js'\n\ntype ThemeListener = (name: string | null, themeManager: ThemeManager) => void\n\nexport type SetActiveThemeProps = {\n className?: string\n parentManager?: ThemeManager | null\n name?: string | null\n theme?: any\n reset?: boolean\n}\n\nexport type ThemeManagerState = {\n name: string\n theme?: ThemeParsed | null\n className?: string\n parentName?: string\n}\n\nconst emptyState: ThemeManagerState = { name: '' }\n\nexport function hasNoThemeUpdatingProps(props: ThemeProps) {\n return !(props.name || props.componentName || props.inverse || props.reset)\n}\n\nlet uid = 0\n\nexport class ThemeManager {\n id = uid++\n isComponent = false\n themeListeners = new Set<ThemeListener>()\n parentManager: ThemeManager | null = null\n state: ThemeManagerState = emptyState\n\n constructor(\n public props: ThemeProps = {},\n parentManagerIn?: ThemeManager | 'root' | null | undefined\n ) {\n if (parentManagerIn === 'root') {\n this.updateState(props, false)\n return\n }\n\n const parentManager = getNonComponentParentManager(parentManagerIn)\n\n if (!parentManager) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `No parent manager given, this is likely due to duplicated Tamagui dependencies. Check your lockfile for mis-matched versions.`\n )\n }\n throw `\u274C`\n }\n\n // no change no props\n if (hasNoThemeUpdatingProps(props)) {\n return parentManager\n }\n\n if (parentManager) {\n this.parentManager = parentManager\n }\n\n if (this.updateState(props, false)) {\n return\n }\n\n return parentManager || this\n }\n\n updateState(\n props: ThemeProps & { forceTheme?: ThemeParsed } = this.props || {},\n shouldNotify = true\n ) {\n const isChanging = (() => {\n if (props.forceTheme) {\n this.state.theme = props.forceTheme\n this.state.name = props.name || ''\n return true\n }\n const nextState = this.getStateIfChanged(props)\n if (nextState) {\n this.props = props\n this.state = nextState\n return true\n }\n })()\n\n if (isChanging) {\n const names = this.state.name.split('_')\n const lastName = names[names.length - 1][0]\n this.isComponent = lastName[0] === lastName[0].toUpperCase()\n this._allKeys = null\n\n if (process.env.NODE_ENV === 'development') {\n this['_numChangeEventsSent'] ??= 0\n this['_numChangeEventsSent']++\n }\n\n if (shouldNotify) {\n this.notify()\n }\n\n return this.state\n }\n }\n\n getStateIfChanged(\n props = this.props,\n state: ThemeManagerState | null = this.state,\n parentManager = this.parentManager\n ) {\n const _ = this.getState(props, parentManager)\n // is removing\n if (state && state !== emptyState && !_) {\n return parentManager?.state\n }\n if (this.getStateShouldChange(_, state)) {\n return _\n }\n }\n\n getStateShouldChange(\n nextState: ThemeManagerState | null,\n state: ThemeManagerState | null = this.state\n ) {\n if (!nextState?.theme || nextState.theme === state?.theme) {\n return false\n }\n return true\n }\n\n getState(props = this.props, parentManager = this.parentManager) {\n return (\n getState(props, parentManager) ||\n (process.env.TAMAGUI_TARGET === 'native' ? parentManager?.state || null : null)\n )\n }\n\n _allKeys: Set<string> | null = null\n get allKeys() {\n this._allKeys ||= new Set([\n ...(this.parentManager?.allKeys || []),\n ...Object.keys(this.state.theme || {}),\n ])\n return this._allKeys\n }\n\n // gets value going up to parents\n getValue(key: string, state?: ThemeManagerState) {\n if (!key) return\n let theme = (state || this.state).theme\n let manager = this as ThemeManager | null\n while (theme && manager) {\n if (key in theme) {\n return theme[key]\n }\n manager = manager.parentManager\n theme = manager?.state.theme\n }\n const tokens = getTokens()\n if (key in tokens.color) {\n return tokens.color[key]\n }\n }\n\n notify() {\n this.themeListeners.forEach((cb) => cb(this.state.name, this))\n }\n\n onChangeTheme(cb: ThemeListener, debugId?: number) {\n if (process.env.NODE_ENV === 'development' && debugId) {\n // @ts-ignore\n this._listeningIds ??= new Set()\n // @ts-ignore\n this._listeningIds.add(debugId)\n }\n\n this.themeListeners.add(cb)\n return () => {\n this.themeListeners.delete(cb)\n }\n }\n}\n\nfunction getNextThemeClassName(name: string, props: ThemeProps) {\n const next = `t_sub_theme ${THEME_CLASSNAME_PREFIX}${name}`\n if (props.inverse || props.forceClassName) {\n return (\n next +\n // ensure you invert to base dark as well as specific dark\n // ... logic should likely be elsewhere\n (next.includes('dark_') ? ` t_dark` : next.includes('light_') ? ` t_light` : '')\n )\n }\n return next.replace('light_', '').replace('dark_', '')\n}\n\nfunction getState(\n props: ThemeProps,\n parentManager?: ThemeManager | null\n): ThemeManagerState | null {\n const themes = getThemes()\n\n if (props.name && props.reset) {\n throw new Error('Cannot reset + set new name')\n }\n\n if (!props.name && !props.inverse && !props.reset && !props.componentName) {\n return null\n }\n\n if (props.reset && !parentManager?.parentManager) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('Cannot reset no grandparent exists')\n }\n return null\n }\n\n let result: ThemeManagerState | null = null\n\n const nextName = props.reset\n ? parentManager?.parentManager?.state?.name || ''\n : props.name || ''\n const { componentName } = props\n const parentName = parentManager?.state?.name || ''\n\n // components look for most specific, fallback upwards\n const base = parentName.split(THEME_NAME_SEPARATOR)\n const lastSegment = base[base.length - 1]\n const isParentComponentTheme =\n parentName && lastSegment[0].toUpperCase() === lastSegment[0]\n if (isParentComponentTheme) {\n base.pop() // always remove componentName they can't nest\n }\n const parentBaseTheme = isParentComponentTheme\n ? base.slice(0, base.length).join(THEME_NAME_SEPARATOR)\n : parentName\n const max = base.length\n const min =\n componentName && !nextName\n ? max // component name only don't search upwards\n : 0\n\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {\n console.groupCollapsed('ThemeManager.getState()')\n console.log({\n props,\n parentName,\n parentBaseTheme,\n base,\n min,\n max,\n isParentComponentTheme,\n })\n }\n\n for (let i = max; i >= min; i--) {\n let prefix = base.slice(0, i).join(THEME_NAME_SEPARATOR)\n if (props.inverse) {\n prefix = inverseThemeName(prefix)\n }\n const potentials: string[] = []\n if (prefix && prefix !== parentBaseTheme) {\n potentials.push(prefix)\n }\n if (nextName) {\n potentials.unshift(prefix ? `${prefix}_${nextName}` : nextName)\n }\n if (i === 1) {\n const lastSegment = potentials.findIndex((x) => !x.includes('_'))\n if (lastSegment > 0) {\n potentials.splice(lastSegment, 0, nextName) // last try prefer our new name to parent\n }\n }\n if (componentName) {\n // components only look for component themes\n if (nextName) {\n const beforeSeparator = prefix.slice(0, prefix.indexOf(THEME_NAME_SEPARATOR))\n potentials.push(`${beforeSeparator}_${nextName}_${componentName}`)\n }\n potentials.push(`${prefix}_${componentName}`)\n if (nextName) {\n potentials.unshift(`${prefix}_${nextName}_${componentName}`)\n }\n }\n\n const found = potentials.find((t) => t in themes)\n\n if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {\n console.log(' - ', { found, potentials, parentManager })\n }\n\n if (found) {\n result = {\n name: found,\n theme: getThemeUnwrapped(themes[found]),\n className: getNextThemeClassName(found, props),\n parentName,\n }\n break\n }\n }\n\n // eslint-disable-next-line no-console\n if (process.env.NODE_ENV === 'development' && typeof props.debug === 'string') {\n console.warn('ThemeManager.getState():', {\n result,\n })\n console.trace()\n console.groupEnd()\n }\n\n return result\n}\n\nconst inverseThemeName = (themeName: string) => {\n return themeName.startsWith('light')\n ? themeName.replace(/^light/, 'dark')\n : themeName.replace(/^dark/, 'light')\n}\n\nexport function getNonComponentParentManager(themeManager?: ThemeManager | null) {\n // components never inherit from components\n // example <Switch><Switch.Thumb /></Switch>\n // the Switch theme shouldn't be considered parent of Thumb\n let res = themeManager\n while (res) {\n if (res?.isComponent) {\n res = res.parentManager\n } else {\n break\n }\n }\n return res\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,WAAW,iBAAiB;AACrC,SAAS,wBAAwB,4BAA4B;AAC7D,SAAS,yBAAyB;AAoBlC,MAAM,aAAgC,EAAE,MAAM,GAAG;AAE1C,SAAS,wBAAwB,OAAmB;AACzD,SAAO,EAAE,MAAM,QAAQ,MAAM,iBAAiB,MAAM,WAAW,MAAM;AACvE;AAEA,IAAI,MAAM;AAEH,MAAM,aAAa;AAAA,EAOxB,YACS,QAAoB,CAAC,GAC5B,iBACA;AAFO;AAPT,cAAK;AACL,uBAAc;AACd,0BAAiB,oBAAI,IAAmB;AACxC,yBAAqC;AACrC,iBAA2B;AA2G3B,oBAA+B;AArG7B,QAAI,oBA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,WAAW,KAAK,CAAC,MAAM,KAAK,MAAM;AAEhD,QAAI,QAAQ,IAAI,aAAa,iBAAiB,OAAO,MAAM,UAAU,UAAU;AAC7E,cAAQ,IAAI,OAAO,EAAE,OAAO,YAAY,cAAc,CAAC;AAAA,IACzD;AAEA,QAAI,OAAO;AACT,eAAS;AAAA,QACP,MAAM;AAAA,QACN,OAAO,kBAAkB,OAAO,KAAK,CAAC;AAAA,QACtC,WAAW,sBAAsB,OAAO,KAAK;AAAA,QAC7C;AAAA,MACF;AACA;AAAA,IACF;AAAA,EACF;AAGA,MAAI,QAAQ,IAAI,aAAa,iBAAiB,OAAO,MAAM,UAAU,UAAU;AAC7E,YAAQ,KAAK,4BAA4B;AAAA,MACvC;AAAA,IACF,CAAC;AACD,YAAQ,MAAM;AACd,YAAQ,SAAS;AAAA,EACnB;AAEA,SAAO;AACT;AAEA,MAAM,mBAAmB,CAAC,cAAsB;AAC9C,SAAO,UAAU,WAAW,OAAO,IAC/B,UAAU,QAAQ,UAAU,MAAM,IAClC,UAAU,QAAQ,SAAS,OAAO;AACxC;AAEO,SAAS,6BAA6B,cAAoC;AAI/E,MAAI,MAAM;AACV,SAAO,KAAK;AACV,QAAI,2BAAK,aAAa;AACpB,YAAM,IAAI;AAAA,IACZ,OAAO;AACL;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": ["lastSegment"]
|
|
7
7
|
}
|
|
@@ -123,15 +123,8 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
|
|
|
123
123
|
const { state, themeManager, mounted, isNewTheme } = themeState;
|
|
124
124
|
const isInversingOnMount = Boolean(!themeState.mounted && props.inverse);
|
|
125
125
|
const shouldReturnParentState = isInversingOnMount;
|
|
126
|
-
function
|
|
127
|
-
const next = manager.getState(
|
|
128
|
-
props,
|
|
129
|
-
parentManager === themeManager ? parentManager.parentManager : parentManager
|
|
130
|
-
);
|
|
131
|
-
return next;
|
|
132
|
-
}
|
|
133
|
-
function getThemeManagerNextStateIfChanged(manager = themeManager, forceShouldChange = false) {
|
|
134
|
-
const next = getNextThemeManagerState(manager);
|
|
126
|
+
function getShouldUpdateTheme(manager = themeManager, nextState, forceShouldChange = false) {
|
|
127
|
+
const next = nextState || manager.getState(props, parentManager);
|
|
135
128
|
if (!next)
|
|
136
129
|
return;
|
|
137
130
|
if ((disableUpdate == null ? void 0 : disableUpdate()) === true)
|
|
@@ -156,22 +149,30 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
|
|
|
156
149
|
};
|
|
157
150
|
}, [isNewTheme, themeManager, state, debug]);
|
|
158
151
|
useLayoutEffect(() => {
|
|
159
|
-
|
|
152
|
+
var _a;
|
|
153
|
+
const nextState = getShouldUpdateTheme(themeManager);
|
|
160
154
|
if (nextState) {
|
|
161
155
|
if (isNewTheme) {
|
|
162
156
|
themeManager.updateState(nextState, true);
|
|
163
157
|
}
|
|
164
158
|
setThemeState(createState);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const shouldUpdate = Boolean((keys == null ? void 0 : keys.length) || isNewTheme);
|
|
168
|
-
if (shouldUpdate) {
|
|
169
|
-
if (process.env.NODE_ENV === "development" && props["debug"]) {
|
|
170
|
-
console.log(`onChangeTheme`, shouldUpdate, { props, name, manager, keys });
|
|
171
|
-
}
|
|
159
|
+
} else {
|
|
160
|
+
if (isNewTheme) {
|
|
172
161
|
setThemeState(createState);
|
|
173
162
|
}
|
|
174
|
-
}
|
|
163
|
+
}
|
|
164
|
+
const disposeChangeListener = (_a = themeManager.parentManager) == null ? void 0 : _a.onChangeTheme(
|
|
165
|
+
(name, manager) => {
|
|
166
|
+
const shouldUpdate = Boolean((keys == null ? void 0 : keys.length) || isNewTheme);
|
|
167
|
+
if (shouldUpdate) {
|
|
168
|
+
if (process.env.NODE_ENV === "development" && props["debug"]) {
|
|
169
|
+
console.log(`onChangeTheme`, shouldUpdate, { props, name, manager, keys });
|
|
170
|
+
}
|
|
171
|
+
setThemeState(createState);
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
themeManager.id
|
|
175
|
+
);
|
|
175
176
|
return () => {
|
|
176
177
|
disposeChangeListener == null ? void 0 : disposeChangeListener();
|
|
177
178
|
};
|
|
@@ -183,6 +184,15 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
|
|
|
183
184
|
props.name,
|
|
184
185
|
props.reset
|
|
185
186
|
]);
|
|
187
|
+
if (process.env.NODE_ENV === "development") {
|
|
188
|
+
useEffect(() => {
|
|
189
|
+
globalThis["TamaguiThemeManagers"] ??= /* @__PURE__ */ new Set();
|
|
190
|
+
globalThis["TamaguiThemeManagers"].add(themeManager);
|
|
191
|
+
return () => {
|
|
192
|
+
globalThis["TamaguiThemeManagers"].delete(themeManager);
|
|
193
|
+
};
|
|
194
|
+
}, [themeManager]);
|
|
195
|
+
}
|
|
186
196
|
}
|
|
187
197
|
if (shouldReturnParentState) {
|
|
188
198
|
if (!parentManager)
|
|
@@ -211,7 +221,8 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
|
|
|
211
221
|
if (prev == null ? void 0 : prev.themeManager) {
|
|
212
222
|
themeManager2 = prev.themeManager;
|
|
213
223
|
const forceChange = Boolean(keys == null ? void 0 : keys.length);
|
|
214
|
-
const
|
|
224
|
+
const next = themeManager2.getState(props, parentManager);
|
|
225
|
+
const nextState = getShouldUpdateTheme(themeManager2, next, forceChange);
|
|
215
226
|
if (nextState) {
|
|
216
227
|
state2 = nextState;
|
|
217
228
|
if (!prev.isNewTheme || !isWeb) {
|
|
@@ -219,13 +230,17 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
|
|
|
219
230
|
} else {
|
|
220
231
|
themeManager2.updateState(nextState, true);
|
|
221
232
|
}
|
|
233
|
+
} else {
|
|
234
|
+
if (prev.isNewTheme) {
|
|
235
|
+
if (parentManager && !next) {
|
|
236
|
+
themeManager2 = parentManager;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
222
239
|
}
|
|
223
240
|
} else {
|
|
224
241
|
themeManager2 = getNewThemeManager();
|
|
225
242
|
}
|
|
226
|
-
const isNewTheme2 = Boolean(
|
|
227
|
-
themeManager2 !== parentManager || prev && themeManager2.state.name !== prev.state.name
|
|
228
|
-
);
|
|
243
|
+
const isNewTheme2 = Boolean(themeManager2 !== parentManager);
|
|
229
244
|
const mounted2 = !props.inverse ? true : root || (prev == null ? void 0 : prev.mounted);
|
|
230
245
|
if (!state2) {
|
|
231
246
|
state2 = isNewTheme2 ? { ...themeManager2.state } : { ...parentManager.state };
|
|
@@ -237,8 +252,19 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
|
|
|
237
252
|
mounted: mounted2
|
|
238
253
|
};
|
|
239
254
|
if (process.env.NODE_ENV === "development" && props["debug"]) {
|
|
240
|
-
console.groupCollapsed(` \u{1F537} useChangeThemeEffect createState`);
|
|
241
|
-
|
|
255
|
+
console.groupCollapsed(` \u{1F537} ${themeManager2.id} useChangeThemeEffect createState`);
|
|
256
|
+
const parentState = { ...parentManager == null ? void 0 : parentManager.state };
|
|
257
|
+
const parentId = parentManager == null ? void 0 : parentManager.id;
|
|
258
|
+
const themeManagerState = { ...themeManager2.state };
|
|
259
|
+
console.log({
|
|
260
|
+
props,
|
|
261
|
+
parentState,
|
|
262
|
+
parentId,
|
|
263
|
+
themeManager: themeManager2,
|
|
264
|
+
prev,
|
|
265
|
+
response,
|
|
266
|
+
themeManagerState
|
|
267
|
+
});
|
|
242
268
|
console.groupEnd();
|
|
243
269
|
}
|
|
244
270
|
return response;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useTheme.tsx"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable no-console */\nimport { isClient, isRSC, isServer, isWeb } from '@tamagui/constants'\nimport { useContext, useEffect, useLayoutEffect, useMemo, useState } from 'react'\n\nimport { getConfig } from '../config.js'\nimport { isDevTools } from '../constants/isDevTools.js'\nimport { isVariable } from '../createVariable.js'\nimport { createProxy } from '../helpers/createProxy.js'\nimport {\n ThemeManager,\n ThemeManagerState,\n getNonComponentParentManager,\n hasNoThemeUpdatingProps,\n} from '../helpers/ThemeManager.js'\nimport { ThemeManagerContext } from '../helpers/ThemeManagerContext.js'\nimport type { ThemeParsed, ThemeProps } from '../types.js'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped.js'\nimport { useServerRef } from './useServerHooks.js'\n\nexport type ChangedThemeResponse = {\n isNewTheme: boolean\n themeManager: ThemeManager | null\n name: string\n theme?: ThemeParsed | null\n className?: string\n}\n\ntype State = {\n state: ThemeManagerState\n themeManager: ThemeManager\n isNewTheme: boolean\n mounted?: boolean\n}\n\nconst emptyProps = { name: null }\n\nfunction getDefaultThemeProxied() {\n const config = getConfig()\n const name = Object.keys(config.themes)[0]\n return getThemeProxied({\n theme: config.themes[name],\n name,\n })\n}\n\nexport const useTheme = (props: ThemeProps = emptyProps): ThemeParsed => {\n return (isRSC ? null : useThemeWithState(props)?.theme) || getDefaultThemeProxied()\n}\n\nexport const useThemeWithState = (props: ThemeProps) => {\n const keys = useServerRef<string[]>([])\n\n const changedTheme = useChangeThemeEffect(\n props,\n false,\n keys.current,\n isClient\n ? () => {\n return props.shouldUpdate?.() ?? keys.current.length === 0\n }\n : undefined\n )\n\n const { themeManager, theme, name, className } = changedTheme\n\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose') {\n console.groupCollapsed(' \uD83D\uDD39 useTheme =>', name)\n const logs = { ...props, name, className, ...(isDevTools && { theme }) }\n for (const key in logs) {\n console.log(' ', key, logs[key])\n }\n console.groupEnd()\n }\n\n if (!changedTheme.theme) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('No theme found', name, props, themeManager)\n }\n return null\n }\n\n const proxiedTheme = useMemo(() => {\n return getThemeProxied(changedTheme as any, keys.current)\n }, [theme, name, className, themeManager])\n\n return {\n ...changedTheme,\n theme: proxiedTheme,\n }\n}\n\nexport function getThemeProxied(\n {\n theme,\n themeManager,\n }: Partial<ChangedThemeResponse> & {\n theme: ThemeParsed\n },\n keys?: string[]\n) {\n return createProxy(theme, {\n has(_, key) {\n if (typeof key === 'string') {\n if (key[0] === '$') key = key.slice(1)\n return themeManager?.allKeys.has(key)\n }\n return Reflect.has(theme, key)\n },\n get(_, key) {\n if (key === GetThemeUnwrapped) {\n return theme\n }\n if (\n key === '__proto__' ||\n key === '$typeof' ||\n typeof key !== 'string' ||\n !themeManager\n ) {\n return Reflect.get(_, key)\n }\n\n // auto convert variables to plain\n const keyString = key[0] === '$' ? key.slice(1) : key\n const val = themeManager.getValue(keyString)\n\n if (val && keys) {\n return new Proxy(val as any, {\n // when they touch the actual value we only track it\n // if its a variable (web), its ignored!\n get(_, subkey) {\n if (subkey === 'val' && !keys.includes(keyString)) {\n keys.push(keyString)\n }\n return Reflect.get(val as any, subkey)\n },\n })\n }\n\n return val\n },\n })\n}\n\nexport const activeThemeManagers = new Set<ThemeManager>()\n\nexport const useChangeThemeEffect = (\n props: ThemeProps,\n root = false,\n keys?: string[],\n disableUpdate?: () => boolean\n): ChangedThemeResponse => {\n if (isRSC) {\n // we need context working for this to work well\n return {\n isNewTheme: false,\n ...createState().state,\n themeManager: null,\n }\n }\n\n const parentManager = getNonComponentParentManager(useContext(ThemeManagerContext))\n\n const {\n debug,\n // @ts-expect-error internal use only\n disable,\n } = props\n\n if (disable) {\n if (!parentManager) throw `\u274C`\n return {\n isNewTheme: false,\n ...parentManager.state,\n themeManager: parentManager,\n }\n }\n\n const [themeState, setThemeState] = useState<State>(createState)\n const { state, themeManager, mounted, isNewTheme } = themeState\n const isInversingOnMount = Boolean(!themeState.mounted && props.inverse)\n const shouldReturnParentState = isInversingOnMount\n\n function getNextThemeManagerState(manager = themeManager) {\n const next = manager.getState(\n props,\n parentManager === themeManager ? parentManager.parentManager : parentManager\n )\n return next\n }\n\n function getThemeManagerNextStateIfChanged(\n manager = themeManager,\n forceShouldChange = false\n ) {\n const next = getNextThemeManagerState(manager)\n if (!next) return\n if (disableUpdate?.() === true) return\n if (!forceShouldChange && !manager.getStateShouldChange(next, state)) return\n return next\n }\n\n if (!isServer) {\n useEffect(() => {\n // SSR safe inverse (because server can't know prefers scheme)\n // could be done through fancy selectors like how we do prefers-media\n // but may be a bit of explosion of selectors\n if (props.inverse && !mounted) {\n setThemeState({ ...themeState, mounted: true })\n return\n }\n\n if (!isNewTheme) return\n if (!themeManager) return\n\n activeThemeManagers.add(themeManager)\n\n return () => {\n activeThemeManagers.delete(themeManager)\n }\n }, [isNewTheme, themeManager, state, debug])\n\n // listen for parent change + notify children change\n useLayoutEffect(() => {\n const nextState = getThemeManagerNextStateIfChanged(themeManager)\n\n if (nextState) {\n if (isNewTheme) {\n // if it's a new theme we can just update + publish to children\n themeManager.updateState(nextState, true)\n }\n // if not we will be creating a whole new themeManager\n setThemeState(createState)\n }\n\n const disposeChangeListener = parentManager?.onChangeTheme((name, manager) => {\n const shouldUpdate = Boolean(keys?.length || isNewTheme)\n if (shouldUpdate) {\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n console.log(`onChangeTheme`, shouldUpdate, { props, name, manager, keys })\n }\n setThemeState(createState)\n }\n }, themeManager.id)\n\n return () => {\n disposeChangeListener?.()\n }\n }, [\n parentManager,\n isNewTheme,\n props.componentName,\n props.inverse,\n props.name,\n props.reset,\n ])\n }\n\n if (shouldReturnParentState) {\n if (!parentManager) throw 'impossible'\n return {\n isNewTheme: false,\n ...parentManager.state,\n className: isInversingOnMount ? '' : parentManager.state.className,\n themeManager: parentManager,\n }\n }\n\n return {\n ...state,\n isNewTheme,\n themeManager,\n }\n\n function createState(prev?: State): State {\n if (prev && disableUpdate?.()) {\n return prev\n }\n\n // returns previous theme manager if no change\n let themeManager: ThemeManager\n let state: ThemeManagerState | undefined\n\n const getNewThemeManager = () => {\n return new ThemeManager(props, root ? 'root' : parentManager)\n }\n\n if (prev?.themeManager) {\n themeManager = prev.themeManager\n\n // this could be a bit better, problem is on toggling light/dark the state is actually\n // showing light even when the last was dark. but technically allso onChangeTheme should\n // basically always call on a change, so i'm wondering if we even need the shouldUpdate\n // at all anymore. this forces updates onChangeTheme for all dynamic style accessed components\n // which is correct, potentially in the future we can avoid forceChange and just know to\n // update if keys.length is set + onChangeTheme called\n const forceChange = Boolean(keys?.length)\n\n const nextState = getThemeManagerNextStateIfChanged(themeManager, forceChange)\n\n if (nextState) {\n state = nextState\n\n if (!prev.isNewTheme || !isWeb) {\n themeManager = getNewThemeManager()\n } else {\n themeManager.updateState(nextState, true)\n }\n }\n } else {\n themeManager = getNewThemeManager()\n }\n\n const isNewTheme = Boolean(\n themeManager !== parentManager ||\n (prev && themeManager.state.name !== prev.state.name)\n )\n\n // only inverse relies on this for ssr\n const mounted = !props.inverse ? true : root || prev?.mounted\n\n if (!state) {\n state = isNewTheme ? { ...themeManager.state } : { ...parentManager!.state }\n }\n\n const response = {\n state,\n themeManager,\n isNewTheme,\n mounted,\n }\n\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n console.groupCollapsed(` \uD83D\uDD37 useChangeThemeEffect createState`)\n console.log({ props, parentManager, themeManager, prev, response })\n console.groupEnd()\n }\n\n return response\n }\n}\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,UAAU,OAAO,UAAU,aAAa;AACjD,SAAS,YAAY,WAAW,iBAAiB,SAAS,gBAAgB;AAE1E,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAE3B,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EAEA;AAAA,OAEK;AACP,SAAS,2BAA2B;AAEpC,SAAS,yBAAyB;AAClC,SAAS,oBAAoB;AAiB7B,MAAM,aAAa,EAAE,MAAM,KAAK;AAEhC,SAAS,yBAAyB;AAChC,QAAM,SAAS,UAAU;AACzB,QAAM,OAAO,OAAO,KAAK,OAAO,MAAM,EAAE,CAAC;AACzC,SAAO,gBAAgB;AAAA,IACrB,OAAO,OAAO,OAAO,IAAI;AAAA,IACzB;AAAA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;AAC/D,QAAM,EAAE,OAAO,cAAc,SAAS,WAAW,IAAI;AACrD,QAAM,qBAAqB,QAAQ,CAAC,WAAW,WAAW,MAAM,OAAO;AACvE,QAAM,0BAA0B;AAEhC,WAAS,
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-console */\nimport { isClient, isRSC, isServer, isWeb } from '@tamagui/constants'\nimport { useContext, useEffect, useLayoutEffect, useMemo, useState } from 'react'\n\nimport { getConfig } from '../config.js'\nimport { isDevTools } from '../constants/isDevTools.js'\nimport { isVariable } from '../createVariable.js'\nimport { createProxy } from '../helpers/createProxy.js'\nimport {\n ThemeManager,\n ThemeManagerState,\n getNonComponentParentManager,\n hasNoThemeUpdatingProps,\n} from '../helpers/ThemeManager.js'\nimport { ThemeManagerContext } from '../helpers/ThemeManagerContext.js'\nimport type { ThemeParsed, ThemeProps } from '../types.js'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped.js'\nimport { useServerRef } from './useServerHooks.js'\n\nexport type ChangedThemeResponse = {\n isNewTheme: boolean\n themeManager: ThemeManager | null\n name: string\n theme?: ThemeParsed | null\n className?: string\n}\n\ntype State = {\n state: ThemeManagerState\n themeManager: ThemeManager\n isNewTheme: boolean\n mounted?: boolean\n}\n\nconst emptyProps = { name: null }\n\nfunction getDefaultThemeProxied() {\n const config = getConfig()\n const name = Object.keys(config.themes)[0]\n return getThemeProxied({\n theme: config.themes[name],\n name,\n })\n}\n\nexport const useTheme = (props: ThemeProps = emptyProps): ThemeParsed => {\n return (isRSC ? null : useThemeWithState(props)?.theme) || getDefaultThemeProxied()\n}\n\nexport const useThemeWithState = (props: ThemeProps) => {\n const keys = useServerRef<string[]>([])\n\n const changedTheme = useChangeThemeEffect(\n props,\n false,\n keys.current,\n isClient\n ? () => {\n return props.shouldUpdate?.() ?? keys.current.length === 0\n }\n : undefined\n )\n\n const { themeManager, theme, name, className } = changedTheme\n\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose') {\n console.groupCollapsed(' \uD83D\uDD39 useTheme =>', name)\n const logs = { ...props, name, className, ...(isDevTools && { theme }) }\n for (const key in logs) {\n console.log(' ', key, logs[key])\n }\n console.groupEnd()\n }\n\n if (!changedTheme.theme) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('No theme found', name, props, themeManager)\n }\n return null\n }\n\n const proxiedTheme = useMemo(() => {\n return getThemeProxied(changedTheme as any, keys.current)\n }, [theme, name, className, themeManager])\n\n return {\n ...changedTheme,\n theme: proxiedTheme,\n }\n}\n\nexport function getThemeProxied(\n {\n theme,\n themeManager,\n }: Partial<ChangedThemeResponse> & {\n theme: ThemeParsed\n },\n keys?: string[]\n) {\n return createProxy(theme, {\n has(_, key) {\n if (typeof key === 'string') {\n if (key[0] === '$') key = key.slice(1)\n return themeManager?.allKeys.has(key)\n }\n return Reflect.has(theme, key)\n },\n get(_, key) {\n if (key === GetThemeUnwrapped) {\n return theme\n }\n if (\n key === '__proto__' ||\n key === '$typeof' ||\n typeof key !== 'string' ||\n !themeManager\n ) {\n return Reflect.get(_, key)\n }\n\n // auto convert variables to plain\n const keyString = key[0] === '$' ? key.slice(1) : key\n const val = themeManager.getValue(keyString)\n\n if (val && keys) {\n return new Proxy(val as any, {\n // when they touch the actual value we only track it\n // if its a variable (web), its ignored!\n get(_, subkey) {\n if (subkey === 'val' && !keys.includes(keyString)) {\n keys.push(keyString)\n }\n return Reflect.get(val as any, subkey)\n },\n })\n }\n\n return val\n },\n })\n}\n\nexport const activeThemeManagers = new Set<ThemeManager>()\n\nexport const useChangeThemeEffect = (\n props: ThemeProps,\n root = false,\n keys?: string[],\n disableUpdate?: () => boolean\n): ChangedThemeResponse => {\n if (isRSC) {\n // we need context working for this to work well\n return {\n isNewTheme: false,\n ...createState().state,\n themeManager: null,\n }\n }\n\n const parentManager = getNonComponentParentManager(useContext(ThemeManagerContext))\n\n const {\n debug,\n // @ts-expect-error internal use only\n disable,\n } = props\n\n if (disable) {\n if (!parentManager) throw `\u274C`\n return {\n isNewTheme: false,\n ...parentManager.state,\n themeManager: parentManager,\n }\n }\n\n const [themeState, setThemeState] = useState<State>(createState)\n const { state, themeManager, mounted, isNewTheme } = themeState\n const isInversingOnMount = Boolean(!themeState.mounted && props.inverse)\n const shouldReturnParentState = isInversingOnMount\n\n function getShouldUpdateTheme(\n manager = themeManager,\n nextState?: ThemeManagerState | null,\n forceShouldChange = false\n ) {\n const next = nextState || manager.getState(props, parentManager)\n if (!next) return\n if (disableUpdate?.() === true) return\n if (!forceShouldChange && !manager.getStateShouldChange(next, state)) return\n return next\n }\n\n if (!isServer) {\n useEffect(() => {\n // SSR safe inverse (because server can't know prefers scheme)\n // could be done through fancy selectors like how we do prefers-media\n // but may be a bit of explosion of selectors\n if (props.inverse && !mounted) {\n setThemeState({ ...themeState, mounted: true })\n return\n }\n\n if (!isNewTheme) return\n if (!themeManager) return\n\n activeThemeManagers.add(themeManager)\n\n return () => {\n activeThemeManagers.delete(themeManager)\n }\n }, [isNewTheme, themeManager, state, debug])\n\n // listen for parent change + notify children change\n useLayoutEffect(() => {\n const nextState = getShouldUpdateTheme(themeManager)\n\n if (nextState) {\n if (isNewTheme) {\n // if it's a new theme we can just update + publish to children\n themeManager.updateState(nextState, true)\n }\n\n // if not we will be creating a whole new themeManager\n setThemeState(createState)\n } else {\n if (isNewTheme) {\n // need to revert to parent\n setThemeState(createState)\n }\n }\n\n const disposeChangeListener = themeManager.parentManager?.onChangeTheme(\n (name, manager) => {\n const shouldUpdate = Boolean(keys?.length || isNewTheme)\n if (shouldUpdate) {\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n console.log(`onChangeTheme`, shouldUpdate, { props, name, manager, keys })\n }\n setThemeState(createState)\n }\n },\n themeManager.id\n )\n\n return () => {\n disposeChangeListener?.()\n }\n }, [\n parentManager,\n isNewTheme,\n props.componentName,\n props.inverse,\n props.name,\n props.reset,\n ])\n\n if (process.env.NODE_ENV === 'development') {\n useEffect(() => {\n globalThis['TamaguiThemeManagers'] ??= new Set()\n globalThis['TamaguiThemeManagers'].add(themeManager)\n return () => {\n globalThis['TamaguiThemeManagers'].delete(themeManager)\n }\n }, [themeManager])\n }\n }\n\n if (shouldReturnParentState) {\n if (!parentManager) throw 'impossible'\n return {\n isNewTheme: false,\n ...parentManager.state,\n className: isInversingOnMount ? '' : parentManager.state.className,\n themeManager: parentManager,\n }\n }\n\n return {\n ...state,\n isNewTheme,\n themeManager,\n }\n\n function createState(prev?: State): State {\n if (prev && disableUpdate?.()) {\n return prev\n }\n\n // returns previous theme manager if no change\n let themeManager: ThemeManager\n let state: ThemeManagerState | undefined\n\n const getNewThemeManager = () => {\n return new ThemeManager(props, root ? 'root' : parentManager)\n }\n\n if (prev?.themeManager) {\n themeManager = prev.themeManager\n\n // this could be a bit better, problem is on toggling light/dark the state is actually\n // showing light even when the last was dark. but technically allso onChangeTheme should\n // basically always call on a change, so i'm wondering if we even need the shouldUpdate\n // at all anymore. this forces updates onChangeTheme for all dynamic style accessed components\n // which is correct, potentially in the future we can avoid forceChange and just know to\n // update if keys.length is set + onChangeTheme called\n const forceChange = Boolean(keys?.length)\n\n const next = themeManager.getState(props, parentManager)\n const nextState = getShouldUpdateTheme(themeManager, next, forceChange)\n\n if (nextState) {\n state = nextState\n\n if (!prev.isNewTheme || !isWeb) {\n themeManager = getNewThemeManager()\n } else {\n themeManager.updateState(nextState, true)\n }\n } else {\n if (prev.isNewTheme) {\n // reset to parent\n if (parentManager && !next) {\n themeManager = parentManager\n }\n }\n }\n } else {\n themeManager = getNewThemeManager()\n }\n\n const isNewTheme = Boolean(themeManager !== parentManager)\n\n // only inverse relies on this for ssr\n const mounted = !props.inverse ? true : root || prev?.mounted\n\n if (!state) {\n state = isNewTheme ? { ...themeManager.state } : { ...parentManager!.state }\n }\n\n const response = {\n state,\n themeManager,\n isNewTheme,\n mounted,\n }\n\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n console.groupCollapsed(` \uD83D\uDD37 ${themeManager.id} useChangeThemeEffect createState`)\n const parentState = { ...parentManager?.state }\n const parentId = parentManager?.id\n const themeManagerState = { ...themeManager.state }\n console.log({\n props,\n parentState,\n parentId,\n themeManager,\n prev,\n response,\n themeManagerState,\n })\n console.groupEnd()\n }\n\n return response\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,UAAU,OAAO,UAAU,aAAa;AACjD,SAAS,YAAY,WAAW,iBAAiB,SAAS,gBAAgB;AAE1E,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAE3B,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EAEA;AAAA,OAEK;AACP,SAAS,2BAA2B;AAEpC,SAAS,yBAAyB;AAClC,SAAS,oBAAoB;AAiB7B,MAAM,aAAa,EAAE,MAAM,KAAK;AAEhC,SAAS,yBAAyB;AAChC,QAAM,SAAS,UAAU;AACzB,QAAM,OAAO,OAAO,KAAK,OAAO,MAAM,EAAE,CAAC;AACzC,SAAO,gBAAgB;AAAA,IACrB,OAAO,OAAO,OAAO,IAAI;AAAA,IACzB;AAAA,EACF,CAAC;AACH;AAEO,MAAM,WAAW,CAAC,QAAoB,eAA4B;AA7CzE;AA8CE,UAAQ,QAAQ,QAAO,uBAAkB,KAAK,MAAvB,mBAA0B,UAAU,uBAAuB;AACpF;AAEO,MAAM,oBAAoB,CAAC,UAAsB;AACtD,QAAM,OAAO,aAAuB,CAAC,CAAC;AAEtC,QAAM,eAAe;AAAA,IACnB;AAAA,IACA;AAAA,IACA,KAAK;AAAA,IACL,WACI,MAAM;AAzDd;AA0DU,eAAO,WAAM,iBAAN,mCAA0B,KAAK,QAAQ,WAAW;AAAA,IAC3D,IACA;AAAA,EACN;AAEA,QAAM,EAAE,cAAc,OAAO,MAAM,UAAU,IAAI;AAEjD,MAAI,QAAQ,IAAI,aAAa,iBAAiB,MAAM,UAAU,WAAW;AACvE,YAAQ,eAAe,2BAAoB,IAAI;AAC/C,UAAM,OAAO,EAAE,GAAG,OAAO,MAAM,WAAW,GAAI,cAAc,EAAE,MAAM,EAAG;AACvE,eAAW,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AQ,eAAe,cAAOH,cAAa,qCAAqC;AAChF,YAAM,cAAc,EAAE,GAAG,+CAAe,MAAM;AAC9C,YAAM,WAAW,+CAAe;AAChC,YAAM,oBAAoB,EAAE,GAAGA,cAAa,MAAM;AAClD,cAAQ,IAAI;AAAA,QACV;AAAA,QACA;AAAA,QACA;AAAA,QACA,cAAAA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AACD,cAAQ,SAAS;AAAA,IACnB;AAEA,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": ["_", "themeManager", "state", "isNewTheme", "mounted"]
|
|
7
7
|
}
|
|
@@ -123,15 +123,8 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
|
|
|
123
123
|
const { state, themeManager, mounted, isNewTheme } = themeState;
|
|
124
124
|
const isInversingOnMount = Boolean(!themeState.mounted && props.inverse);
|
|
125
125
|
const shouldReturnParentState = isInversingOnMount;
|
|
126
|
-
function
|
|
127
|
-
const next = manager.getState(
|
|
128
|
-
props,
|
|
129
|
-
parentManager === themeManager ? parentManager.parentManager : parentManager
|
|
130
|
-
);
|
|
131
|
-
return next;
|
|
132
|
-
}
|
|
133
|
-
function getThemeManagerNextStateIfChanged(manager = themeManager, forceShouldChange = false) {
|
|
134
|
-
const next = getNextThemeManagerState(manager);
|
|
126
|
+
function getShouldUpdateTheme(manager = themeManager, nextState, forceShouldChange = false) {
|
|
127
|
+
const next = nextState || manager.getState(props, parentManager);
|
|
135
128
|
if (!next)
|
|
136
129
|
return;
|
|
137
130
|
if ((disableUpdate == null ? void 0 : disableUpdate()) === true)
|
|
@@ -156,22 +149,30 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
|
|
|
156
149
|
};
|
|
157
150
|
}, [isNewTheme, themeManager, state, debug]);
|
|
158
151
|
useLayoutEffect(() => {
|
|
159
|
-
|
|
152
|
+
var _a;
|
|
153
|
+
const nextState = getShouldUpdateTheme(themeManager);
|
|
160
154
|
if (nextState) {
|
|
161
155
|
if (isNewTheme) {
|
|
162
156
|
themeManager.updateState(nextState, true);
|
|
163
157
|
}
|
|
164
158
|
setThemeState(createState);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const shouldUpdate = Boolean((keys == null ? void 0 : keys.length) || isNewTheme);
|
|
168
|
-
if (shouldUpdate) {
|
|
169
|
-
if (process.env.NODE_ENV === "development" && props["debug"]) {
|
|
170
|
-
console.log(`onChangeTheme`, shouldUpdate, { props, name, manager, keys });
|
|
171
|
-
}
|
|
159
|
+
} else {
|
|
160
|
+
if (isNewTheme) {
|
|
172
161
|
setThemeState(createState);
|
|
173
162
|
}
|
|
174
|
-
}
|
|
163
|
+
}
|
|
164
|
+
const disposeChangeListener = (_a = themeManager.parentManager) == null ? void 0 : _a.onChangeTheme(
|
|
165
|
+
(name, manager) => {
|
|
166
|
+
const shouldUpdate = Boolean((keys == null ? void 0 : keys.length) || isNewTheme);
|
|
167
|
+
if (shouldUpdate) {
|
|
168
|
+
if (process.env.NODE_ENV === "development" && props["debug"]) {
|
|
169
|
+
console.log(`onChangeTheme`, shouldUpdate, { props, name, manager, keys });
|
|
170
|
+
}
|
|
171
|
+
setThemeState(createState);
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
themeManager.id
|
|
175
|
+
);
|
|
175
176
|
return () => {
|
|
176
177
|
disposeChangeListener == null ? void 0 : disposeChangeListener();
|
|
177
178
|
};
|
|
@@ -183,6 +184,15 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
|
|
|
183
184
|
props.name,
|
|
184
185
|
props.reset
|
|
185
186
|
]);
|
|
187
|
+
if (process.env.NODE_ENV === "development") {
|
|
188
|
+
useEffect(() => {
|
|
189
|
+
globalThis["TamaguiThemeManagers"] ??= /* @__PURE__ */ new Set();
|
|
190
|
+
globalThis["TamaguiThemeManagers"].add(themeManager);
|
|
191
|
+
return () => {
|
|
192
|
+
globalThis["TamaguiThemeManagers"].delete(themeManager);
|
|
193
|
+
};
|
|
194
|
+
}, [themeManager]);
|
|
195
|
+
}
|
|
186
196
|
}
|
|
187
197
|
if (shouldReturnParentState) {
|
|
188
198
|
if (!parentManager)
|
|
@@ -211,7 +221,8 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
|
|
|
211
221
|
if (prev == null ? void 0 : prev.themeManager) {
|
|
212
222
|
themeManager2 = prev.themeManager;
|
|
213
223
|
const forceChange = Boolean(keys == null ? void 0 : keys.length);
|
|
214
|
-
const
|
|
224
|
+
const next = themeManager2.getState(props, parentManager);
|
|
225
|
+
const nextState = getShouldUpdateTheme(themeManager2, next, forceChange);
|
|
215
226
|
if (nextState) {
|
|
216
227
|
state2 = nextState;
|
|
217
228
|
if (!prev.isNewTheme || !isWeb) {
|
|
@@ -219,13 +230,17 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
|
|
|
219
230
|
} else {
|
|
220
231
|
themeManager2.updateState(nextState, true);
|
|
221
232
|
}
|
|
233
|
+
} else {
|
|
234
|
+
if (prev.isNewTheme) {
|
|
235
|
+
if (parentManager && !next) {
|
|
236
|
+
themeManager2 = parentManager;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
222
239
|
}
|
|
223
240
|
} else {
|
|
224
241
|
themeManager2 = getNewThemeManager();
|
|
225
242
|
}
|
|
226
|
-
const isNewTheme2 = Boolean(
|
|
227
|
-
themeManager2 !== parentManager || prev && themeManager2.state.name !== prev.state.name
|
|
228
|
-
);
|
|
243
|
+
const isNewTheme2 = Boolean(themeManager2 !== parentManager);
|
|
229
244
|
const mounted2 = !props.inverse ? true : root || (prev == null ? void 0 : prev.mounted);
|
|
230
245
|
if (!state2) {
|
|
231
246
|
state2 = isNewTheme2 ? { ...themeManager2.state } : { ...parentManager.state };
|
|
@@ -237,8 +252,19 @@ const useChangeThemeEffect = (props, root = false, keys, disableUpdate) => {
|
|
|
237
252
|
mounted: mounted2
|
|
238
253
|
};
|
|
239
254
|
if (process.env.NODE_ENV === "development" && props["debug"]) {
|
|
240
|
-
console.groupCollapsed(` \u{1F537} useChangeThemeEffect createState`);
|
|
241
|
-
|
|
255
|
+
console.groupCollapsed(` \u{1F537} ${themeManager2.id} useChangeThemeEffect createState`);
|
|
256
|
+
const parentState = { ...parentManager == null ? void 0 : parentManager.state };
|
|
257
|
+
const parentId = parentManager == null ? void 0 : parentManager.id;
|
|
258
|
+
const themeManagerState = { ...themeManager2.state };
|
|
259
|
+
console.log({
|
|
260
|
+
props,
|
|
261
|
+
parentState,
|
|
262
|
+
parentId,
|
|
263
|
+
themeManager: themeManager2,
|
|
264
|
+
prev,
|
|
265
|
+
response,
|
|
266
|
+
themeManagerState
|
|
267
|
+
});
|
|
242
268
|
console.groupEnd();
|
|
243
269
|
}
|
|
244
270
|
return response;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useTheme.tsx"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable no-console */\nimport { isClient, isRSC, isServer, isWeb } from '@tamagui/constants'\nimport { useContext, useEffect, useLayoutEffect, useMemo, useState } from 'react'\n\nimport { getConfig } from '../config.js'\nimport { isDevTools } from '../constants/isDevTools.js'\nimport { isVariable } from '../createVariable.js'\nimport { createProxy } from '../helpers/createProxy.js'\nimport {\n ThemeManager,\n ThemeManagerState,\n getNonComponentParentManager,\n hasNoThemeUpdatingProps,\n} from '../helpers/ThemeManager.js'\nimport { ThemeManagerContext } from '../helpers/ThemeManagerContext.js'\nimport type { ThemeParsed, ThemeProps } from '../types.js'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped.js'\nimport { useServerRef } from './useServerHooks.js'\n\nexport type ChangedThemeResponse = {\n isNewTheme: boolean\n themeManager: ThemeManager | null\n name: string\n theme?: ThemeParsed | null\n className?: string\n}\n\ntype State = {\n state: ThemeManagerState\n themeManager: ThemeManager\n isNewTheme: boolean\n mounted?: boolean\n}\n\nconst emptyProps = { name: null }\n\nfunction getDefaultThemeProxied() {\n const config = getConfig()\n const name = Object.keys(config.themes)[0]\n return getThemeProxied({\n theme: config.themes[name],\n name,\n })\n}\n\nexport const useTheme = (props: ThemeProps = emptyProps): ThemeParsed => {\n return (isRSC ? null : useThemeWithState(props)?.theme) || getDefaultThemeProxied()\n}\n\nexport const useThemeWithState = (props: ThemeProps) => {\n const keys = useServerRef<string[]>([])\n\n const changedTheme = useChangeThemeEffect(\n props,\n false,\n keys.current,\n isClient\n ? () => {\n return props.shouldUpdate?.() ?? keys.current.length === 0\n }\n : undefined\n )\n\n const { themeManager, theme, name, className } = changedTheme\n\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose') {\n console.groupCollapsed(' \uD83D\uDD39 useTheme =>', name)\n const logs = { ...props, name, className, ...(isDevTools && { theme }) }\n for (const key in logs) {\n console.log(' ', key, logs[key])\n }\n console.groupEnd()\n }\n\n if (!changedTheme.theme) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('No theme found', name, props, themeManager)\n }\n return null\n }\n\n const proxiedTheme = useMemo(() => {\n return getThemeProxied(changedTheme as any, keys.current)\n }, [theme, name, className, themeManager])\n\n return {\n ...changedTheme,\n theme: proxiedTheme,\n }\n}\n\nexport function getThemeProxied(\n {\n theme,\n themeManager,\n }: Partial<ChangedThemeResponse> & {\n theme: ThemeParsed\n },\n keys?: string[]\n) {\n return createProxy(theme, {\n has(_, key) {\n if (typeof key === 'string') {\n if (key[0] === '$') key = key.slice(1)\n return themeManager?.allKeys.has(key)\n }\n return Reflect.has(theme, key)\n },\n get(_, key) {\n if (key === GetThemeUnwrapped) {\n return theme\n }\n if (\n key === '__proto__' ||\n key === '$typeof' ||\n typeof key !== 'string' ||\n !themeManager\n ) {\n return Reflect.get(_, key)\n }\n\n // auto convert variables to plain\n const keyString = key[0] === '$' ? key.slice(1) : key\n const val = themeManager.getValue(keyString)\n\n if (val && keys) {\n return new Proxy(val as any, {\n // when they touch the actual value we only track it\n // if its a variable (web), its ignored!\n get(_, subkey) {\n if (subkey === 'val' && !keys.includes(keyString)) {\n keys.push(keyString)\n }\n return Reflect.get(val as any, subkey)\n },\n })\n }\n\n return val\n },\n })\n}\n\nexport const activeThemeManagers = new Set<ThemeManager>()\n\nexport const useChangeThemeEffect = (\n props: ThemeProps,\n root = false,\n keys?: string[],\n disableUpdate?: () => boolean\n): ChangedThemeResponse => {\n if (isRSC) {\n // we need context working for this to work well\n return {\n isNewTheme: false,\n ...createState().state,\n themeManager: null,\n }\n }\n\n const parentManager = getNonComponentParentManager(useContext(ThemeManagerContext))\n\n const {\n debug,\n // @ts-expect-error internal use only\n disable,\n } = props\n\n if (disable) {\n if (!parentManager) throw `\u274C`\n return {\n isNewTheme: false,\n ...parentManager.state,\n themeManager: parentManager,\n }\n }\n\n const [themeState, setThemeState] = useState<State>(createState)\n const { state, themeManager, mounted, isNewTheme } = themeState\n const isInversingOnMount = Boolean(!themeState.mounted && props.inverse)\n const shouldReturnParentState = isInversingOnMount\n\n function getNextThemeManagerState(manager = themeManager) {\n const next = manager.getState(\n props,\n parentManager === themeManager ? parentManager.parentManager : parentManager\n )\n return next\n }\n\n function getThemeManagerNextStateIfChanged(\n manager = themeManager,\n forceShouldChange = false\n ) {\n const next = getNextThemeManagerState(manager)\n if (!next) return\n if (disableUpdate?.() === true) return\n if (!forceShouldChange && !manager.getStateShouldChange(next, state)) return\n return next\n }\n\n if (!isServer) {\n useEffect(() => {\n // SSR safe inverse (because server can't know prefers scheme)\n // could be done through fancy selectors like how we do prefers-media\n // but may be a bit of explosion of selectors\n if (props.inverse && !mounted) {\n setThemeState({ ...themeState, mounted: true })\n return\n }\n\n if (!isNewTheme) return\n if (!themeManager) return\n\n activeThemeManagers.add(themeManager)\n\n return () => {\n activeThemeManagers.delete(themeManager)\n }\n }, [isNewTheme, themeManager, state, debug])\n\n // listen for parent change + notify children change\n useLayoutEffect(() => {\n const nextState = getThemeManagerNextStateIfChanged(themeManager)\n\n if (nextState) {\n if (isNewTheme) {\n // if it's a new theme we can just update + publish to children\n themeManager.updateState(nextState, true)\n }\n // if not we will be creating a whole new themeManager\n setThemeState(createState)\n }\n\n const disposeChangeListener = parentManager?.onChangeTheme((name, manager) => {\n const shouldUpdate = Boolean(keys?.length || isNewTheme)\n if (shouldUpdate) {\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n console.log(`onChangeTheme`, shouldUpdate, { props, name, manager, keys })\n }\n setThemeState(createState)\n }\n }, themeManager.id)\n\n return () => {\n disposeChangeListener?.()\n }\n }, [\n parentManager,\n isNewTheme,\n props.componentName,\n props.inverse,\n props.name,\n props.reset,\n ])\n }\n\n if (shouldReturnParentState) {\n if (!parentManager) throw 'impossible'\n return {\n isNewTheme: false,\n ...parentManager.state,\n className: isInversingOnMount ? '' : parentManager.state.className,\n themeManager: parentManager,\n }\n }\n\n return {\n ...state,\n isNewTheme,\n themeManager,\n }\n\n function createState(prev?: State): State {\n if (prev && disableUpdate?.()) {\n return prev\n }\n\n // returns previous theme manager if no change\n let themeManager: ThemeManager\n let state: ThemeManagerState | undefined\n\n const getNewThemeManager = () => {\n return new ThemeManager(props, root ? 'root' : parentManager)\n }\n\n if (prev?.themeManager) {\n themeManager = prev.themeManager\n\n // this could be a bit better, problem is on toggling light/dark the state is actually\n // showing light even when the last was dark. but technically allso onChangeTheme should\n // basically always call on a change, so i'm wondering if we even need the shouldUpdate\n // at all anymore. this forces updates onChangeTheme for all dynamic style accessed components\n // which is correct, potentially in the future we can avoid forceChange and just know to\n // update if keys.length is set + onChangeTheme called\n const forceChange = Boolean(keys?.length)\n\n const nextState = getThemeManagerNextStateIfChanged(themeManager, forceChange)\n\n if (nextState) {\n state = nextState\n\n if (!prev.isNewTheme || !isWeb) {\n themeManager = getNewThemeManager()\n } else {\n themeManager.updateState(nextState, true)\n }\n }\n } else {\n themeManager = getNewThemeManager()\n }\n\n const isNewTheme = Boolean(\n themeManager !== parentManager ||\n (prev && themeManager.state.name !== prev.state.name)\n )\n\n // only inverse relies on this for ssr\n const mounted = !props.inverse ? true : root || prev?.mounted\n\n if (!state) {\n state = isNewTheme ? { ...themeManager.state } : { ...parentManager!.state }\n }\n\n const response = {\n state,\n themeManager,\n isNewTheme,\n mounted,\n }\n\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n console.groupCollapsed(` \uD83D\uDD37 useChangeThemeEffect createState`)\n console.log({ props, parentManager, themeManager, prev, response })\n console.groupEnd()\n }\n\n return response\n }\n}\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,UAAU,OAAO,UAAU,aAAa;AACjD,SAAS,YAAY,WAAW,iBAAiB,SAAS,gBAAgB;AAE1E,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAE3B,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EAEA;AAAA,OAEK;AACP,SAAS,2BAA2B;AAEpC,SAAS,yBAAyB;AAClC,SAAS,oBAAoB;AAiB7B,MAAM,aAAa,EAAE,MAAM,KAAK;AAEhC,SAAS,yBAAyB;AAChC,QAAM,SAAS,UAAU;AACzB,QAAM,OAAO,OAAO,KAAK,OAAO,MAAM,EAAE,CAAC;AACzC,SAAO,gBAAgB;AAAA,IACrB,OAAO,OAAO,OAAO,IAAI;AAAA,IACzB;AAAA,EACF,CAAC;AACH;AAEO,MAAM,WAAW,CAAC,QAAoB,eAA4B;AA7CzE;AA8CE,UAAQ,QAAQ,QAAO,uBAAkB,KAAK,MAAvB,mBAA0B,UAAU,uBAAuB;AACpF;AAEO,MAAM,oBAAoB,CAAC,UAAsB;AACtD,QAAM,OAAO,aAAuB,CAAC,CAAC;AAEtC,QAAM,eAAe;AAAA,IACnB;AAAA,IACA;AAAA,IACA,KAAK;AAAA,IACL,WACI,MAAM;AAzDd;AA0DU,eAAO,WAAM,iBAAN,mCAA0B,KAAK,QAAQ,WAAW;AAAA,IAC3D,IACA;AAAA,EACN;AAEA,QAAM,EAAE,cAAc,OAAO,MAAM,UAAU,IAAI;AAEjD,MAAI,QAAQ,IAAI,aAAa,iBAAiB,MAAM,UAAU,WAAW;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B,IAAIA,IAAG,QAAQ;AACb,gBAAI,WAAW,SAAS,CAAC,KAAK,SAAS,SAAS,GAAG;AACjD,mBAAK,KAAK,SAAS;AAAA,YACrB;AACA,mBAAO,QAAQ,IAAI,KAAY,MAAM;AAAA,UACvC;AAAA,QACF,CAAC;AAAA,MACH;AAEA,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;AAEO,MAAM,sBAAsB,oBAAI,IAAkB;AAElD,MAAM,uBAAuB,CAClC,OACA,OAAO,OACP,MACA,kBACyB;AACzB,MAAI,OAAO;AAET,WAAO;AAAA,MACL,YAAY;AAAA,MACZ,GAAG,YAAY,EAAE;AAAA,MACjB,cAAc;AAAA,IAChB;AAAA,EACF;AAEA,QAAM,gBAAgB,6BAA6B,WAAW,mBAAmB,CAAC;AAElF,QAAM;AAAA,IACJ;AAAA;AAAA,IAEA;AAAA,EACF,IAAI;AAEJ,MAAI,SAAS;AACX,QAAI,CAAC;AAAe,YAAM;AAC1B,WAAO;AAAA,MACL,YAAY;AAAA,MACZ,GAAG,cAAc;AAAA,MACjB,cAAc;AAAA,IAChB;AAAA,EACF;AAEA,QAAM,CAAC,YAAY,aAAa,IAAI,SAAgB,WAAW;AAC/D,QAAM,EAAE,OAAO,cAAc,SAAS,WAAW,IAAI;AACrD,QAAM,qBAAqB,QAAQ,CAAC,WAAW,WAAW,MAAM,OAAO;AACvE,QAAM,0BAA0B;AAEhC,WAAS,
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-console */\nimport { isClient, isRSC, isServer, isWeb } from '@tamagui/constants'\nimport { useContext, useEffect, useLayoutEffect, useMemo, useState } from 'react'\n\nimport { getConfig } from '../config.js'\nimport { isDevTools } from '../constants/isDevTools.js'\nimport { isVariable } from '../createVariable.js'\nimport { createProxy } from '../helpers/createProxy.js'\nimport {\n ThemeManager,\n ThemeManagerState,\n getNonComponentParentManager,\n hasNoThemeUpdatingProps,\n} from '../helpers/ThemeManager.js'\nimport { ThemeManagerContext } from '../helpers/ThemeManagerContext.js'\nimport type { ThemeParsed, ThemeProps } from '../types.js'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped.js'\nimport { useServerRef } from './useServerHooks.js'\n\nexport type ChangedThemeResponse = {\n isNewTheme: boolean\n themeManager: ThemeManager | null\n name: string\n theme?: ThemeParsed | null\n className?: string\n}\n\ntype State = {\n state: ThemeManagerState\n themeManager: ThemeManager\n isNewTheme: boolean\n mounted?: boolean\n}\n\nconst emptyProps = { name: null }\n\nfunction getDefaultThemeProxied() {\n const config = getConfig()\n const name = Object.keys(config.themes)[0]\n return getThemeProxied({\n theme: config.themes[name],\n name,\n })\n}\n\nexport const useTheme = (props: ThemeProps = emptyProps): ThemeParsed => {\n return (isRSC ? null : useThemeWithState(props)?.theme) || getDefaultThemeProxied()\n}\n\nexport const useThemeWithState = (props: ThemeProps) => {\n const keys = useServerRef<string[]>([])\n\n const changedTheme = useChangeThemeEffect(\n props,\n false,\n keys.current,\n isClient\n ? () => {\n return props.shouldUpdate?.() ?? keys.current.length === 0\n }\n : undefined\n )\n\n const { themeManager, theme, name, className } = changedTheme\n\n if (process.env.NODE_ENV === 'development' && props.debug === 'verbose') {\n console.groupCollapsed(' \uD83D\uDD39 useTheme =>', name)\n const logs = { ...props, name, className, ...(isDevTools && { theme }) }\n for (const key in logs) {\n console.log(' ', key, logs[key])\n }\n console.groupEnd()\n }\n\n if (!changedTheme.theme) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('No theme found', name, props, themeManager)\n }\n return null\n }\n\n const proxiedTheme = useMemo(() => {\n return getThemeProxied(changedTheme as any, keys.current)\n }, [theme, name, className, themeManager])\n\n return {\n ...changedTheme,\n theme: proxiedTheme,\n }\n}\n\nexport function getThemeProxied(\n {\n theme,\n themeManager,\n }: Partial<ChangedThemeResponse> & {\n theme: ThemeParsed\n },\n keys?: string[]\n) {\n return createProxy(theme, {\n has(_, key) {\n if (typeof key === 'string') {\n if (key[0] === '$') key = key.slice(1)\n return themeManager?.allKeys.has(key)\n }\n return Reflect.has(theme, key)\n },\n get(_, key) {\n if (key === GetThemeUnwrapped) {\n return theme\n }\n if (\n key === '__proto__' ||\n key === '$typeof' ||\n typeof key !== 'string' ||\n !themeManager\n ) {\n return Reflect.get(_, key)\n }\n\n // auto convert variables to plain\n const keyString = key[0] === '$' ? key.slice(1) : key\n const val = themeManager.getValue(keyString)\n\n if (val && keys) {\n return new Proxy(val as any, {\n // when they touch the actual value we only track it\n // if its a variable (web), its ignored!\n get(_, subkey) {\n if (subkey === 'val' && !keys.includes(keyString)) {\n keys.push(keyString)\n }\n return Reflect.get(val as any, subkey)\n },\n })\n }\n\n return val\n },\n })\n}\n\nexport const activeThemeManagers = new Set<ThemeManager>()\n\nexport const useChangeThemeEffect = (\n props: ThemeProps,\n root = false,\n keys?: string[],\n disableUpdate?: () => boolean\n): ChangedThemeResponse => {\n if (isRSC) {\n // we need context working for this to work well\n return {\n isNewTheme: false,\n ...createState().state,\n themeManager: null,\n }\n }\n\n const parentManager = getNonComponentParentManager(useContext(ThemeManagerContext))\n\n const {\n debug,\n // @ts-expect-error internal use only\n disable,\n } = props\n\n if (disable) {\n if (!parentManager) throw `\u274C`\n return {\n isNewTheme: false,\n ...parentManager.state,\n themeManager: parentManager,\n }\n }\n\n const [themeState, setThemeState] = useState<State>(createState)\n const { state, themeManager, mounted, isNewTheme } = themeState\n const isInversingOnMount = Boolean(!themeState.mounted && props.inverse)\n const shouldReturnParentState = isInversingOnMount\n\n function getShouldUpdateTheme(\n manager = themeManager,\n nextState?: ThemeManagerState | null,\n forceShouldChange = false\n ) {\n const next = nextState || manager.getState(props, parentManager)\n if (!next) return\n if (disableUpdate?.() === true) return\n if (!forceShouldChange && !manager.getStateShouldChange(next, state)) return\n return next\n }\n\n if (!isServer) {\n useEffect(() => {\n // SSR safe inverse (because server can't know prefers scheme)\n // could be done through fancy selectors like how we do prefers-media\n // but may be a bit of explosion of selectors\n if (props.inverse && !mounted) {\n setThemeState({ ...themeState, mounted: true })\n return\n }\n\n if (!isNewTheme) return\n if (!themeManager) return\n\n activeThemeManagers.add(themeManager)\n\n return () => {\n activeThemeManagers.delete(themeManager)\n }\n }, [isNewTheme, themeManager, state, debug])\n\n // listen for parent change + notify children change\n useLayoutEffect(() => {\n const nextState = getShouldUpdateTheme(themeManager)\n\n if (nextState) {\n if (isNewTheme) {\n // if it's a new theme we can just update + publish to children\n themeManager.updateState(nextState, true)\n }\n\n // if not we will be creating a whole new themeManager\n setThemeState(createState)\n } else {\n if (isNewTheme) {\n // need to revert to parent\n setThemeState(createState)\n }\n }\n\n const disposeChangeListener = themeManager.parentManager?.onChangeTheme(\n (name, manager) => {\n const shouldUpdate = Boolean(keys?.length || isNewTheme)\n if (shouldUpdate) {\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n console.log(`onChangeTheme`, shouldUpdate, { props, name, manager, keys })\n }\n setThemeState(createState)\n }\n },\n themeManager.id\n )\n\n return () => {\n disposeChangeListener?.()\n }\n }, [\n parentManager,\n isNewTheme,\n props.componentName,\n props.inverse,\n props.name,\n props.reset,\n ])\n\n if (process.env.NODE_ENV === 'development') {\n useEffect(() => {\n globalThis['TamaguiThemeManagers'] ??= new Set()\n globalThis['TamaguiThemeManagers'].add(themeManager)\n return () => {\n globalThis['TamaguiThemeManagers'].delete(themeManager)\n }\n }, [themeManager])\n }\n }\n\n if (shouldReturnParentState) {\n if (!parentManager) throw 'impossible'\n return {\n isNewTheme: false,\n ...parentManager.state,\n className: isInversingOnMount ? '' : parentManager.state.className,\n themeManager: parentManager,\n }\n }\n\n return {\n ...state,\n isNewTheme,\n themeManager,\n }\n\n function createState(prev?: State): State {\n if (prev && disableUpdate?.()) {\n return prev\n }\n\n // returns previous theme manager if no change\n let themeManager: ThemeManager\n let state: ThemeManagerState | undefined\n\n const getNewThemeManager = () => {\n return new ThemeManager(props, root ? 'root' : parentManager)\n }\n\n if (prev?.themeManager) {\n themeManager = prev.themeManager\n\n // this could be a bit better, problem is on toggling light/dark the state is actually\n // showing light even when the last was dark. but technically allso onChangeTheme should\n // basically always call on a change, so i'm wondering if we even need the shouldUpdate\n // at all anymore. this forces updates onChangeTheme for all dynamic style accessed components\n // which is correct, potentially in the future we can avoid forceChange and just know to\n // update if keys.length is set + onChangeTheme called\n const forceChange = Boolean(keys?.length)\n\n const next = themeManager.getState(props, parentManager)\n const nextState = getShouldUpdateTheme(themeManager, next, forceChange)\n\n if (nextState) {\n state = nextState\n\n if (!prev.isNewTheme || !isWeb) {\n themeManager = getNewThemeManager()\n } else {\n themeManager.updateState(nextState, true)\n }\n } else {\n if (prev.isNewTheme) {\n // reset to parent\n if (parentManager && !next) {\n themeManager = parentManager\n }\n }\n }\n } else {\n themeManager = getNewThemeManager()\n }\n\n const isNewTheme = Boolean(themeManager !== parentManager)\n\n // only inverse relies on this for ssr\n const mounted = !props.inverse ? true : root || prev?.mounted\n\n if (!state) {\n state = isNewTheme ? { ...themeManager.state } : { ...parentManager!.state }\n }\n\n const response = {\n state,\n themeManager,\n isNewTheme,\n mounted,\n }\n\n if (process.env.NODE_ENV === 'development' && props['debug']) {\n console.groupCollapsed(` \uD83D\uDD37 ${themeManager.id} useChangeThemeEffect createState`)\n const parentState = { ...parentManager?.state }\n const parentId = parentManager?.id\n const themeManagerState = { ...themeManager.state }\n console.log({\n props,\n parentState,\n parentId,\n themeManager,\n prev,\n response,\n themeManagerState,\n })\n console.groupEnd()\n }\n\n return response\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,UAAU,OAAO,UAAU,aAAa;AACjD,SAAS,YAAY,WAAW,iBAAiB,SAAS,gBAAgB;AAE1E,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAE3B,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EAEA;AAAA,OAEK;AACP,SAAS,2BAA2B;AAEpC,SAAS,yBAAyB;AAClC,SAAS,oBAAoB;AAiB7B,MAAM,aAAa,EAAE,MAAM,KAAK;AAEhC,SAAS,yBAAyB;AAChC,QAAM,SAAS,UAAU;AAC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UAAI,WAAW;AACb,QAAAC,SAAQ;AAER,YAAI,CAAC,KAAK,cAAc,CAAC,OAAO;AAC9B,UAAAD,gBAAe,mBAAmB;AAAA,QACpC,OAAO;AACL,UAAAA,cAAa,YAAY,WAAW,IAAI;AAAA,QAC1C;AAAA,MACF,OAAO;AACL,YAAI,KAAK,YAAY;AAEnB,cAAI,iBAAiB,CAAC,MAAM;AAC1B,YAAAA,gBAAe;AAAA,UACjB;AAAA,QACF;AAAA,MACF;AAAA,IACF,OAAO;AACL,MAAAA,gBAAe,mBAAmB;AAAA,IACpC;AAEA,UAAME,cAAa,QAAQF,kBAAiB,aAAa;AAGzD,UAAMG,WAAU,CAAC,MAAM,UAAU,OAAO,SAAQ,6BAAM;AAEtD,QAAI,CAACF,QAAO;AACV,MAAAA,SAAQC,cAAa,EAAE,GAAGF,cAAa,MAAM,IAAI,EAAE,GAAG,cAAe,MAAM;AAAA,IAC7E;AAEA,UAAM,WAAW;AAAA,MACf,OAAAC;AAAA,MACA,cAAAD;AAAA,MACA,YAAAE;AAAA,MACA,SAAAC;AAAA,IACF;AAEA,QAAI,QAAQ,IAAI,aAAa,iBAAiB,MAAM,OAAO,GAAG;AAC5D,cAAQ,eAAe,cAAOH,cAAa,qCAAqC;AAChF,YAAM,cAAc,EAAE,GAAG,+CAAe,MAAM;AAC9C,YAAM,WAAW,+CAAe;AAChC,YAAM,oBAAoB,EAAE,GAAGA,cAAa,MAAM;AAClD,cAAQ,IAAI;AAAA,QACV;AAAA,QACA;AAAA,QACA;AAAA,QACA,cAAAA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AACD,cAAQ,SAAS;AAAA,IACnB;AAEA,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": ["_", "themeManager", "state", "isNewTheme", "mounted"]
|
|
7
7
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useForceUpdate } from "@tamagui/use-force-update";
|
|
3
|
-
import { useEffect, useState } from "react";
|
|
3
|
+
import { useEffect, useId, useState } from "react";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
let node;
|
|
4
6
|
function ThemeDebug({
|
|
5
7
|
themeState,
|
|
6
8
|
themeProps,
|
|
@@ -10,6 +12,22 @@ function ThemeDebug({
|
|
|
10
12
|
if (process.env.NODE_ENV === "development") {
|
|
11
13
|
const [onChangeCount, setOnChangeCount] = useState(0);
|
|
12
14
|
const rerender = useForceUpdate();
|
|
15
|
+
const id = useId();
|
|
16
|
+
if (process.env.NODE_ENV === "development" && typeof document !== "undefined") {
|
|
17
|
+
if (!node) {
|
|
18
|
+
node = document.createElement("div");
|
|
19
|
+
node.style.width = "100%";
|
|
20
|
+
node.style.height = "200px";
|
|
21
|
+
node.style.overflowY = "scroll";
|
|
22
|
+
node.style.position = "fixed";
|
|
23
|
+
node.style.top = "0px";
|
|
24
|
+
node.style.left = "0px";
|
|
25
|
+
node.style.display = "flex";
|
|
26
|
+
node.style.flexDirection = "row";
|
|
27
|
+
node.style.background = "var(--background)";
|
|
28
|
+
document.body.appendChild(node);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
13
31
|
useEffect(() => {
|
|
14
32
|
var _a2, _b2;
|
|
15
33
|
(_b2 = (_a2 = themeState.themeManager) == null ? void 0 : _a2.parentManager) == null ? void 0 : _b2.onChangeTheme((name, manager) => {
|
|
@@ -21,44 +39,45 @@ function ThemeDebug({
|
|
|
21
39
|
const tm = setInterval(rerender, 100);
|
|
22
40
|
return () => clearTimeout(tm);
|
|
23
41
|
}, []);
|
|
24
|
-
return /* @__PURE__ */ jsxs(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
42
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
43
|
+
createPortal(
|
|
44
|
+
/* @__PURE__ */ jsxs(
|
|
45
|
+
"code",
|
|
46
|
+
{
|
|
47
|
+
style: {
|
|
48
|
+
whiteSpace: "pre"
|
|
49
|
+
},
|
|
50
|
+
children: [
|
|
51
|
+
"<Theme ",
|
|
52
|
+
id,
|
|
53
|
+
" />\xA0",
|
|
54
|
+
JSON.stringify(
|
|
55
|
+
{
|
|
56
|
+
name: themeState.name,
|
|
57
|
+
className: themeState.className,
|
|
58
|
+
inverse: themeProps.inverse,
|
|
59
|
+
forceClassName: themeProps.forceClassName,
|
|
60
|
+
parent: (_a = themeState.themeManager) == null ? void 0 : _a.state.parentName,
|
|
61
|
+
id: (_b = themeState.themeManager) == null ? void 0 : _b.id,
|
|
62
|
+
parentId: (_d = (_c = themeState.themeManager) == null ? void 0 : _c.parentManager) == null ? void 0 : _d.id,
|
|
63
|
+
isNew: themeState.isNewTheme,
|
|
64
|
+
onChangeCount,
|
|
65
|
+
listening: [...((_e = themeState.themeManager) == null ? void 0 : _e["_listeningIds"]) || []].join(
|
|
66
|
+
","
|
|
67
|
+
),
|
|
68
|
+
_numChangeEventsSent: (_f = themeState.themeManager) == null ? void 0 : _f["_numChangeEventsSent"]
|
|
69
|
+
},
|
|
70
|
+
null,
|
|
71
|
+
2
|
|
72
|
+
)
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
),
|
|
76
|
+
node
|
|
77
|
+
),
|
|
78
|
+
/* @__PURE__ */ jsx("div", { children: id }),
|
|
79
|
+
children
|
|
80
|
+
] });
|
|
62
81
|
}
|
|
63
82
|
return children;
|
|
64
83
|
}
|