@tamagui/core 1.0.1-beta.219 → 1.0.1-beta.221
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/addTheme.js +7 -10
- package/dist/cjs/addTheme.js.map +3 -3
- package/dist/cjs/config.js +8 -4
- package/dist/cjs/config.js.map +2 -2
- package/dist/cjs/{hooks/useUnmountEffect.js → contexts/ButtonNestingContext.js} +7 -9
- package/dist/cjs/contexts/ButtonNestingContext.js.map +7 -0
- package/dist/cjs/createComponent.js +63 -67
- package/dist/cjs/createComponent.js.map +3 -3
- package/dist/cjs/createFont.js +11 -4
- package/dist/cjs/createFont.js.map +2 -2
- package/dist/cjs/createFont.test.js +125 -0
- package/dist/cjs/createFont.test.js.map +7 -0
- package/dist/cjs/createTamagui.js +13 -12
- package/dist/cjs/createTamagui.js.map +2 -2
- package/dist/cjs/createTokens.js.map +2 -2
- package/dist/cjs/createTokens.test.js +27 -0
- package/dist/cjs/createTokens.test.js.map +7 -0
- package/dist/cjs/createVariable.js +4 -9
- package/dist/cjs/createVariable.js.map +2 -2
- package/dist/cjs/createVariable.test.js +7 -0
- package/dist/cjs/createVariable.test.js.map +7 -0
- package/dist/cjs/createVariables.js +6 -7
- package/dist/cjs/createVariables.js.map +2 -2
- package/dist/cjs/helpers/ThemeManager.js +161 -147
- package/dist/cjs/helpers/ThemeManager.js.map +3 -3
- package/dist/cjs/helpers/ThemeManager.test.js +449 -0
- package/dist/cjs/helpers/ThemeManager.test.js.map +7 -0
- package/dist/cjs/helpers/{getTokens.js → ThemeManagerContext.js} +8 -8
- package/dist/cjs/helpers/ThemeManagerContext.js.map +7 -0
- package/dist/cjs/helpers/createPropMapper.js +4 -4
- package/dist/cjs/helpers/createPropMapper.js.map +2 -2
- package/dist/cjs/helpers/extendStaticConfig.js +2 -4
- package/dist/cjs/helpers/extendStaticConfig.js.map +2 -2
- package/dist/cjs/helpers/{assignNativePropsToWeb.native.js → getBoundingClientRect.js} +15 -8
- package/dist/cjs/helpers/getBoundingClientRect.js.map +7 -0
- package/dist/cjs/{hooks/useConstant.js → helpers/getRect.js} +14 -17
- package/dist/cjs/helpers/getRect.js.map +7 -0
- package/dist/cjs/helpers/getSplitStyles.js +82 -87
- package/dist/cjs/helpers/getSplitStyles.js.map +3 -3
- package/dist/cjs/helpers/getStylesAtomic.native.js.map +2 -2
- package/dist/cjs/helpers/getThemeCSSRules.js +6 -2
- package/dist/cjs/helpers/getThemeCSSRules.js.map +2 -2
- package/dist/cjs/helpers/insertStyleRule.js +1 -1
- package/dist/cjs/helpers/insertStyleRule.js.map +2 -2
- package/dist/cjs/helpers/mergeTransform.js +11 -8
- package/dist/cjs/helpers/mergeTransform.js.map +2 -2
- package/dist/cjs/helpers/pseudoDescriptors.js +1 -0
- package/dist/cjs/helpers/pseudoDescriptors.js.map +2 -2
- package/dist/cjs/helpers/themeable.js +9 -9
- package/dist/cjs/helpers/themeable.js.map +2 -2
- package/dist/cjs/hooks/useElementLayout.js +4 -12
- package/dist/cjs/hooks/useElementLayout.js.map +2 -2
- package/dist/cjs/hooks/useMedia.js +2 -1
- package/dist/cjs/hooks/useMedia.js.map +2 -2
- package/dist/cjs/hooks/useTheme.js +114 -156
- package/dist/cjs/hooks/useTheme.js.map +3 -3
- package/dist/cjs/hooks/{useIsMounted.js → useThemeName.js} +23 -14
- package/dist/cjs/hooks/useThemeName.js.map +7 -0
- package/dist/cjs/index.js +2 -5
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/setupReactNative.js +20 -7
- package/dist/cjs/setupReactNative.js.map +2 -2
- package/dist/cjs/styled.js +2 -19
- package/dist/cjs/styled.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/updateTheme.js +9 -9
- package/dist/cjs/updateTheme.js.map +2 -2
- package/dist/cjs/views/TamaguiProvider.js +3 -3
- package/dist/cjs/views/TamaguiProvider.js.map +2 -2
- package/dist/cjs/views/Theme.js +39 -28
- package/dist/cjs/views/Theme.js.map +3 -3
- package/dist/cjs/views/ThemeInverse.js +4 -2
- package/dist/cjs/views/ThemeInverse.js.map +2 -2
- package/dist/cjs/views/ThemeProvider.js +8 -33
- package/dist/cjs/views/ThemeProvider.js.map +3 -3
- package/dist/esm/addTheme.js +7 -10
- package/dist/esm/addTheme.js.map +3 -3
- package/dist/esm/config.js +8 -3
- package/dist/esm/config.js.map +2 -2
- package/dist/esm/contexts/ButtonNestingContext.js +6 -0
- package/dist/esm/contexts/ButtonNestingContext.js.map +7 -0
- package/dist/esm/createComponent.js +65 -70
- package/dist/esm/createComponent.js.map +3 -3
- package/dist/esm/createFont.js +11 -4
- package/dist/esm/createFont.js.map +2 -2
- package/dist/esm/createFont.test.js +124 -0
- package/dist/esm/createFont.test.js.map +7 -0
- package/dist/esm/createTamagui.js +13 -12
- package/dist/esm/createTamagui.js.map +2 -2
- package/dist/esm/createTokens.js.map +2 -2
- package/dist/esm/createTokens.test.js +26 -0
- package/dist/esm/createTokens.test.js.map +7 -0
- package/dist/esm/createVariable.js +4 -9
- package/dist/esm/createVariable.js.map +2 -2
- package/dist/esm/createVariable.test.js +6 -0
- package/dist/esm/createVariable.test.js.map +7 -0
- package/dist/esm/createVariables.js +6 -7
- package/dist/esm/createVariables.js.map +2 -2
- package/dist/esm/helpers/ThemeManager.js +140 -144
- package/dist/esm/helpers/ThemeManager.js.map +3 -3
- package/dist/esm/helpers/ThemeManager.test.js +448 -0
- package/dist/esm/helpers/ThemeManager.test.js.map +7 -0
- package/dist/esm/helpers/ThemeManagerContext.js +6 -0
- package/dist/esm/helpers/ThemeManagerContext.js.map +7 -0
- package/dist/esm/helpers/createPropMapper.js +4 -4
- package/dist/esm/helpers/createPropMapper.js.map +2 -2
- package/dist/esm/helpers/extendStaticConfig.js +2 -4
- package/dist/esm/helpers/extendStaticConfig.js.map +2 -2
- package/dist/esm/helpers/getBoundingClientRect.js +13 -0
- package/dist/esm/helpers/getBoundingClientRect.js.map +7 -0
- package/dist/esm/helpers/getRect.js +12 -0
- package/dist/esm/helpers/getRect.js.map +7 -0
- package/dist/esm/helpers/getSplitStyles.js +90 -89
- package/dist/esm/helpers/getSplitStyles.js.map +3 -3
- package/dist/esm/helpers/getStylesAtomic.native.js.map +2 -2
- package/dist/esm/helpers/getThemeCSSRules.js +6 -2
- package/dist/esm/helpers/getThemeCSSRules.js.map +2 -2
- package/dist/esm/helpers/insertStyleRule.js +1 -1
- package/dist/esm/helpers/insertStyleRule.js.map +2 -2
- package/dist/esm/helpers/mergeTransform.js +8 -6
- package/dist/esm/helpers/mergeTransform.js.map +2 -2
- package/dist/esm/helpers/pseudoDescriptors.js +1 -0
- package/dist/esm/helpers/pseudoDescriptors.js.map +2 -2
- package/dist/esm/helpers/themeable.js +9 -9
- package/dist/esm/helpers/themeable.js.map +2 -2
- package/dist/esm/hooks/useElementLayout.js +2 -9
- package/dist/esm/hooks/useElementLayout.js.map +2 -2
- package/dist/esm/hooks/useMedia.js +3 -2
- package/dist/esm/hooks/useMedia.js.map +2 -2
- package/dist/esm/hooks/useTheme.js +114 -159
- package/dist/esm/hooks/useTheme.js.map +3 -3
- package/dist/esm/hooks/useThemeName.js +25 -0
- package/dist/esm/hooks/useThemeName.js.map +7 -0
- package/dist/esm/index.js +3 -5
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/setupReactNative.js +18 -6
- package/dist/esm/setupReactNative.js.map +2 -2
- package/dist/esm/styled.js +3 -20
- package/dist/esm/styled.js.map +2 -2
- package/dist/esm/updateTheme.js +9 -9
- package/dist/esm/updateTheme.js.map +2 -2
- package/dist/esm/views/TamaguiProvider.js +4 -4
- package/dist/esm/views/TamaguiProvider.js.map +2 -2
- package/dist/esm/views/Theme.js +40 -29
- package/dist/esm/views/Theme.js.map +3 -3
- package/dist/esm/views/ThemeInverse.js +4 -2
- package/dist/esm/views/ThemeInverse.js.map +2 -2
- package/dist/esm/views/ThemeProvider.js +8 -27
- package/dist/esm/views/ThemeProvider.js.map +2 -2
- package/package.json +13 -13
- package/src/__snapshots__/createTokens.test.ts.snap +877 -0
- package/src/addTheme.ts +9 -12
- package/src/config.ts +10 -2
- package/src/contexts/ButtonNestingContext.tsx +3 -0
- package/src/createComponent.tsx +117 -108
- package/src/createFont.test.ts +129 -0
- package/src/createFont.ts +12 -5
- package/src/createTamagui.ts +16 -14
- package/src/createTokens.test.ts +29 -0
- package/src/createTokens.ts +1 -1
- package/src/createVariable.test.ts +7 -0
- package/src/createVariable.ts +4 -10
- package/src/createVariables.ts +7 -7
- package/src/helpers/ThemeManager.test.tsx +480 -0
- package/src/helpers/ThemeManager.tsx +171 -166
- package/src/helpers/ThemeManagerContext.tsx +5 -0
- package/src/helpers/createPropMapper.ts +4 -4
- package/src/helpers/extendStaticConfig.ts +4 -4
- package/src/helpers/getBoundingClientRect.tsx +7 -0
- package/src/helpers/getRect.tsx +8 -0
- package/src/helpers/getSplitStyles.tsx +98 -94
- package/src/helpers/getStylesAtomic.native.ts +1 -0
- package/src/helpers/getThemeCSSRules.ts +9 -2
- package/src/helpers/insertStyleRule.tsx +2 -2
- package/src/helpers/mergeTransform.ts +13 -6
- package/src/helpers/pseudoDescriptors.ts +1 -0
- package/src/helpers/themeable.tsx +17 -9
- package/src/hooks/useElementLayout.tsx +3 -8
- package/src/hooks/useMedia.tsx +3 -3
- package/src/hooks/useTheme.tsx +138 -211
- package/src/hooks/useThemeName.tsx +25 -0
- package/src/index.ts +3 -4
- package/src/setupReactNative.ts +16 -5
- package/src/styled.tsx +4 -23
- package/src/types.tsx +42 -17
- package/src/updateTheme.ts +12 -9
- package/src/views/TamaguiProvider.tsx +5 -5
- package/src/views/Theme.tsx +48 -39
- package/src/views/ThemeProvider.tsx +11 -33
- package/types/Tamagui.d.ts +1 -1
- package/types/addTheme.d.ts +23 -2
- package/types/config.d.ts +0 -1
- package/types/contexts/ButtonNestingContext.d.ts +3 -0
- package/types/createFont.test.d.ts +2 -0
- package/types/createTokens.test.d.ts +2 -0
- package/types/createVariable.d.ts +2 -2
- package/types/createVariable.test.d.ts +2 -0
- package/types/helpers/ThemeManager.d.ts +20 -30
- package/types/helpers/ThemeManager.test.d.ts +2 -0
- package/types/helpers/ThemeManagerContext.d.ts +4 -0
- package/types/helpers/getBoundingClientRect.d.ts +2 -0
- package/types/helpers/getRect.d.ts +9 -0
- package/types/helpers/insertStyleRule.d.ts +1 -1
- package/types/helpers/mergeTransform.d.ts +5 -3
- package/types/helpers/themeable.d.ts +3 -0
- package/types/hooks/useElementLayout.d.ts +0 -8
- package/types/hooks/useTheme.d.ts +10 -20
- package/types/hooks/useThemeName.d.ts +5 -0
- package/types/index.d.ts +3 -4
- package/types/setupReactNative.d.ts +4 -2
- package/types/types.d.ts +35 -10
- package/types/updateTheme.d.ts +23 -2
- package/types/views/Theme.d.ts +3 -4
- package/dist/cjs/constants/platform.js +0 -74
- package/dist/cjs/constants/platform.js.map +0 -7
- package/dist/cjs/constants/platform.native.js +0 -62
- package/dist/cjs/constants/platform.native.js.map +0 -7
- package/dist/cjs/helpers/assignNativePropsToWeb.js +0 -188
- package/dist/cjs/helpers/assignNativePropsToWeb.js.map +0 -7
- package/dist/cjs/helpers/assignNativePropsToWeb.native.js.map +0 -7
- package/dist/cjs/helpers/calc.js +0 -71
- package/dist/cjs/helpers/calc.js.map +0 -7
- package/dist/cjs/helpers/getFont.js +0 -66
- package/dist/cjs/helpers/getFont.js.map +0 -7
- package/dist/cjs/helpers/getStackSize.js +0 -46
- package/dist/cjs/helpers/getStackSize.js.map +0 -7
- package/dist/cjs/helpers/getTokens.js.map +0 -7
- package/dist/cjs/helpers/startTransition.js +0 -36
- package/dist/cjs/helpers/startTransition.js.map +0 -7
- package/dist/cjs/helpers/validate.js +0 -2
- package/dist/cjs/helpers/validate.js.map +0 -7
- package/dist/cjs/hooks/useConstant.js.map +0 -7
- package/dist/cjs/hooks/useIsMounted.js.map +0 -7
- package/dist/cjs/hooks/usePressable.js +0 -36
- package/dist/cjs/hooks/usePressable.js.map +0 -7
- package/dist/cjs/hooks/useUnmountEffect.js.map +0 -7
- package/dist/cjs/injectStyles.js +0 -40
- package/dist/cjs/injectStyles.js.map +0 -7
- package/dist/cjs/react-native.js +0 -22
- package/dist/cjs/react-native.js.map +0 -7
- package/dist/esm/constants/platform.js +0 -39
- package/dist/esm/constants/platform.js.map +0 -7
- package/dist/esm/constants/platform.native.js +0 -28
- package/dist/esm/constants/platform.native.js.map +0 -7
- package/dist/esm/helpers/assignNativePropsToWeb.js +0 -164
- package/dist/esm/helpers/assignNativePropsToWeb.js.map +0 -7
- package/dist/esm/helpers/assignNativePropsToWeb.native.js +0 -6
- package/dist/esm/helpers/assignNativePropsToWeb.native.js.map +0 -7
- package/dist/esm/helpers/calc.js +0 -47
- package/dist/esm/helpers/calc.js.map +0 -7
- package/dist/esm/helpers/getFont.js +0 -42
- package/dist/esm/helpers/getFont.js.map +0 -7
- package/dist/esm/helpers/getStackSize.js +0 -22
- package/dist/esm/helpers/getStackSize.js.map +0 -7
- package/dist/esm/helpers/getTokens.js +0 -6
- package/dist/esm/helpers/getTokens.js.map +0 -7
- package/dist/esm/helpers/startTransition.js +0 -6
- package/dist/esm/helpers/startTransition.js.map +0 -7
- package/dist/esm/helpers/validate.js +0 -1
- package/dist/esm/helpers/validate.js.map +0 -7
- package/dist/esm/hooks/useConstant.js +0 -15
- package/dist/esm/hooks/useConstant.js.map +0 -7
- package/dist/esm/hooks/useIsMounted.js +0 -16
- package/dist/esm/hooks/useIsMounted.js.map +0 -7
- package/dist/esm/hooks/usePressable.js +0 -12
- package/dist/esm/hooks/usePressable.js.map +0 -7
- package/dist/esm/hooks/useUnmountEffect.js +0 -8
- package/dist/esm/hooks/useUnmountEffect.js.map +0 -7
- package/dist/esm/injectStyles.js +0 -16
- package/dist/esm/injectStyles.js.map +0 -7
- package/dist/esm/react-native.js +0 -3
- package/dist/esm/react-native.js.map +0 -7
- package/src/contexts/ButtonInsideButtonContext.tsx +0 -3
- package/src/contexts/ThemeContext.tsx +0 -5
- package/src/helpers/areEqualSets.tsx +0 -9
- package/src/views/ThemeInverse.tsx +0 -40
- package/src/views/ThemeReset.tsx +0 -43
- package/types/constants/platform.d.ts +0 -13
- package/types/constants/platform.native.d.ts +0 -13
- package/types/contexts/ButtonInsideButtonContext.d.ts +0 -3
- package/types/contexts/ThemeContext.d.ts +0 -7
- package/types/helpers/areEqualSets.d.ts +0 -2
- package/types/helpers/assignNativePropsToWeb.d.ts +0 -2
- package/types/helpers/assignNativePropsToWeb.native.d.ts +0 -2
- package/types/helpers/calc.d.ts +0 -1
- package/types/helpers/getFont.d.ts +0 -3
- package/types/helpers/getStackSize.d.ts +0 -8
- package/types/helpers/getTokens.d.ts +0 -2
- package/types/helpers/startTransition.d.ts +0 -3
- package/types/helpers/validate.d.ts +0 -1
- package/types/hooks/useConstant.d.ts +0 -2
- package/types/hooks/useIsMounted.d.ts +0 -3
- package/types/hooks/useMedia.test.d.ts +0 -1
- package/types/hooks/usePressable.d.ts +0 -3
- package/types/hooks/usePressablePressResponder.d.ts +0 -84
- package/types/hooks/useUnmountEffect.d.ts +0 -2
- package/types/injectStyles.d.ts +0 -7
- package/types/react-native.d.ts +0 -8
- package/types/views/AbsoluteFill.d.ts +0 -5
- package/types/views/AbsoluteFill.native.d.ts +0 -3
- package/types/views/ThemeInverse.d.ts +0 -9
- package/types/views/ThemeReset.d.ts +0 -4
|
@@ -1,244 +1,199 @@
|
|
|
1
|
-
import { isRSC, isServer,
|
|
2
|
-
import { useForceUpdate } from "@tamagui/use-force-update";
|
|
1
|
+
import { isClient, isRSC, isServer, isWeb } from "@tamagui/constants";
|
|
3
2
|
import { useContext, useLayoutEffect, useMemo, useState } from "react";
|
|
4
3
|
import { getConfig } from "../config";
|
|
5
4
|
import { isDevTools } from "../constants/isDevTools";
|
|
6
|
-
import { ThemeContext } from "../contexts/ThemeContext";
|
|
7
|
-
import { areEqualSets } from "../helpers/areEqualSets";
|
|
8
5
|
import { createProxy } from "../helpers/createProxy";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
ThemeManagerContext,
|
|
12
|
-
emptyManager
|
|
13
|
-
} from "../helpers/ThemeManager";
|
|
6
|
+
import { ThemeManager, hasNoThemeUpdatingProps } from "../helpers/ThemeManager";
|
|
7
|
+
import { ThemeManagerContext } from "../helpers/ThemeManagerContext";
|
|
14
8
|
import { GetThemeUnwrapped } from "./getThemeUnwrapped";
|
|
15
|
-
|
|
16
|
-
const useTheme = (
|
|
9
|
+
const emptyProps = { name: null };
|
|
10
|
+
const useTheme = (props = emptyProps) => {
|
|
11
|
+
var _a;
|
|
17
12
|
if (isRSC) {
|
|
18
13
|
const config = getConfig();
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
uuid: {},
|
|
25
|
-
keys: /* @__PURE__ */ new Set(),
|
|
26
|
-
isRendering: true
|
|
27
|
-
};
|
|
14
|
+
const name2 = Object.keys(config.themes)[0];
|
|
15
|
+
return getThemeProxied({
|
|
16
|
+
theme: config.themes[name2],
|
|
17
|
+
name: name2
|
|
18
|
+
});
|
|
28
19
|
}
|
|
29
|
-
const { name, theme, themes, themeManager, className } = useChangeThemeEffect(
|
|
30
|
-
themeName,
|
|
31
|
-
componentName,
|
|
32
|
-
props,
|
|
33
|
-
forceUpdate,
|
|
34
|
-
state.current.uuid
|
|
35
|
-
);
|
|
20
|
+
const { name, theme, themes, themeManager, className, isNewTheme } = useChangeThemeEffect(props);
|
|
36
21
|
if (process.env.NODE_ENV === "development") {
|
|
37
|
-
if ((
|
|
22
|
+
if (isWeb && isNewTheme && className === ((_a = themeManager == null ? void 0 : themeManager.parentManager) == null ? void 0 : _a.state.className)) {
|
|
23
|
+
console.error(`Should always change, duplicating ThemeMananger bug`, themeManager);
|
|
24
|
+
debugger;
|
|
25
|
+
}
|
|
26
|
+
if (props.debug === "verbose") {
|
|
38
27
|
console.groupCollapsed(" \u{1F539} useTheme =>", name);
|
|
39
|
-
const logs = {
|
|
28
|
+
const logs = { ...props, name, className, ...isDevTools && { theme } };
|
|
40
29
|
for (const key in logs) {
|
|
41
30
|
console.log(" ", key, logs[key]);
|
|
42
31
|
}
|
|
43
32
|
console.groupEnd();
|
|
44
33
|
}
|
|
45
34
|
}
|
|
46
|
-
state.current.isRendering = true;
|
|
47
|
-
useIsomorphicLayoutEffect(() => {
|
|
48
|
-
const st = state.current;
|
|
49
|
-
st.isRendering = false;
|
|
50
|
-
const cur = themeManager == null ? void 0 : themeManager.keys.get(st.uuid);
|
|
51
|
-
if (!cur || !areEqualSets(st.keys, cur)) {
|
|
52
|
-
themeManager == null ? void 0 : themeManager.track(st.uuid, st.keys);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
const debugProp = props && props["debug"];
|
|
56
35
|
if (!theme) {
|
|
57
36
|
if (process.env.NODE_ENV === "development") {
|
|
58
|
-
console.warn("No theme
|
|
37
|
+
console.warn("No theme found", name, props, themeManager);
|
|
59
38
|
}
|
|
60
39
|
return themes[Object.keys(themes)[0]];
|
|
61
40
|
}
|
|
62
41
|
return useMemo(() => {
|
|
63
42
|
return getThemeProxied({
|
|
43
|
+
isNewTheme,
|
|
64
44
|
theme,
|
|
65
45
|
name,
|
|
66
46
|
className,
|
|
67
|
-
themeManager
|
|
68
|
-
onStringKeyAccess(key) {
|
|
69
|
-
if (disableTracking)
|
|
70
|
-
return;
|
|
71
|
-
if (state) {
|
|
72
|
-
if (state.current.isRendering && !state.current.keys.has(key)) {
|
|
73
|
-
state.current.keys.add(key);
|
|
74
|
-
if (process.env.NODE_ENV === "development" && debugProp === "verbose") {
|
|
75
|
-
console.log(" \u{1F538} tracking theme", key);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
47
|
+
themeManager
|
|
80
48
|
});
|
|
81
|
-
}, [theme, name, className, themeManager
|
|
49
|
+
}, [theme, isNewTheme, name, className, themeManager]);
|
|
82
50
|
};
|
|
83
51
|
function getThemeProxied({
|
|
84
52
|
theme,
|
|
85
53
|
name,
|
|
86
54
|
className,
|
|
87
55
|
themeManager,
|
|
88
|
-
|
|
56
|
+
isNewTheme
|
|
89
57
|
}) {
|
|
90
58
|
return createProxy(theme, {
|
|
91
59
|
has(_, key) {
|
|
92
|
-
if (typeof key === "string"
|
|
93
|
-
key
|
|
60
|
+
if (typeof key === "string") {
|
|
61
|
+
if (key[0] === "$")
|
|
62
|
+
key = key.slice(1);
|
|
63
|
+
return themeManager == null ? void 0 : themeManager.allKeys.has(key);
|
|
94
64
|
}
|
|
95
65
|
return Reflect.has(theme, key);
|
|
96
66
|
},
|
|
97
67
|
get(_, key) {
|
|
98
68
|
if (key === GetThemeUnwrapped) {
|
|
99
69
|
return theme;
|
|
100
|
-
}
|
|
101
|
-
if (key === GetThemeManager) {
|
|
70
|
+
} else if (key === GetThemeManager) {
|
|
102
71
|
return themeManager;
|
|
103
|
-
}
|
|
104
|
-
|
|
72
|
+
} else if (key === GetIsNewTheme) {
|
|
73
|
+
return isNewTheme;
|
|
74
|
+
} else if (key === "name") {
|
|
105
75
|
return name;
|
|
106
|
-
}
|
|
107
|
-
if (key === "className") {
|
|
76
|
+
} else if (key === "className") {
|
|
108
77
|
return className;
|
|
109
|
-
}
|
|
110
|
-
if (!name || key === "__proto__" || typeof key === "symbol" || key === "$typeof") {
|
|
78
|
+
} else if (!name || key === "__proto__" || typeof key === "symbol" || key === "$typeof") {
|
|
111
79
|
return Reflect.get(_, key);
|
|
112
80
|
}
|
|
113
|
-
if (key[0] === "$")
|
|
81
|
+
if (key[0] === "$")
|
|
114
82
|
key = key.slice(1);
|
|
115
|
-
}
|
|
116
83
|
if (!themeManager) {
|
|
117
84
|
return theme[key];
|
|
118
85
|
}
|
|
119
|
-
onStringKeyAccess == null ? void 0 : onStringKeyAccess(key);
|
|
120
86
|
return themeManager.getValue(key);
|
|
121
87
|
}
|
|
122
88
|
});
|
|
123
89
|
}
|
|
124
90
|
const GetThemeManager = Symbol();
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return theme[GetThemeManager];
|
|
129
|
-
};
|
|
130
|
-
function useThemeName(opts) {
|
|
131
|
-
if (isRSC) {
|
|
132
|
-
const config = getConfig();
|
|
133
|
-
return config.themes[Object.keys(config.themes)[0]];
|
|
134
|
-
}
|
|
135
|
-
const parent = useContext(ThemeManagerContext);
|
|
136
|
-
const [name, setName] = useState((parent == null ? void 0 : parent.name) || "");
|
|
137
|
-
useIsomorphicLayoutEffect(() => {
|
|
138
|
-
if (!parent)
|
|
139
|
-
return;
|
|
140
|
-
return parent.onChangeTheme((next, manager) => {
|
|
141
|
-
const name2 = (opts == null ? void 0 : opts.parent) ? manager.parentName || next : next;
|
|
142
|
-
if (!name2)
|
|
143
|
-
return;
|
|
144
|
-
setName(name2);
|
|
145
|
-
});
|
|
146
|
-
}, [parent]);
|
|
147
|
-
return name;
|
|
148
|
-
}
|
|
149
|
-
const useDefaultThemeName = () => {
|
|
150
|
-
var _a;
|
|
151
|
-
return (_a = useContext(ThemeContext)) == null ? void 0 : _a.defaultTheme;
|
|
152
|
-
};
|
|
91
|
+
const GetIsNewTheme = Symbol();
|
|
92
|
+
const getThemeManager = (theme) => theme == null ? void 0 : theme[GetThemeManager];
|
|
93
|
+
const getThemeIsNewTheme = (theme) => theme == null ? void 0 : theme[GetIsNewTheme];
|
|
153
94
|
const activeThemeManagers = /* @__PURE__ */ new Set();
|
|
154
|
-
const useChangeThemeEffect = (
|
|
95
|
+
const useChangeThemeEffect = (props, root = false) => {
|
|
96
|
+
const parentManager = useContext(ThemeManagerContext);
|
|
155
97
|
const config = getConfig();
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
throw new Error(
|
|
159
|
-
`Missing tamagui config, you either have a duplicate config, or haven't set it up. Be sure createTamagui is called before rendering.`
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
98
|
+
const { debug } = props;
|
|
99
|
+
const disable = props.disable;
|
|
163
100
|
const { themes } = config;
|
|
164
101
|
if (isRSC) {
|
|
165
|
-
const parentManager2 = new ThemeManager("light", "light", themes.light);
|
|
166
|
-
const next2 = parentManager2.getNextTheme({
|
|
167
|
-
name,
|
|
168
|
-
componentName,
|
|
169
|
-
themes,
|
|
170
|
-
reset: props == null ? void 0 : props.reset
|
|
171
|
-
});
|
|
172
102
|
return {
|
|
173
|
-
...
|
|
103
|
+
...createState().state,
|
|
174
104
|
themes,
|
|
175
105
|
themeManager: null
|
|
176
106
|
};
|
|
177
107
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const next = parentManager.getNextTheme(getThemeProps, debug);
|
|
188
|
-
const forceUpdate = forceUpdateProp || useForceUpdate();
|
|
189
|
-
const themeManager = useMemo(() => {
|
|
190
|
-
return new ThemeManager(next.name, next.className, next.theme, parentManager, reset);
|
|
191
|
-
}, []);
|
|
192
|
-
let didChange = false;
|
|
193
|
-
if (process.env.TAMAGUI_TARGET === "native") {
|
|
194
|
-
didChange = Boolean(
|
|
195
|
-
(next == null ? void 0 : next.name) !== themeManager.name || (next == null ? void 0 : next.className) !== themeManager.className
|
|
196
|
-
);
|
|
197
|
-
if (didChange) {
|
|
198
|
-
themeManager.update(next, false, false);
|
|
199
|
-
}
|
|
108
|
+
if (disable) {
|
|
109
|
+
if (!parentManager)
|
|
110
|
+
throw new Error(`Disable topmost`);
|
|
111
|
+
return {
|
|
112
|
+
...parentManager.state,
|
|
113
|
+
isNewTheme: false,
|
|
114
|
+
themes,
|
|
115
|
+
themeManager: parentManager
|
|
116
|
+
};
|
|
200
117
|
}
|
|
118
|
+
const [themeState, setThemeState] = useState(createState);
|
|
119
|
+
const { isNewTheme, state, themeManager, mounted } = themeState;
|
|
201
120
|
if (!isServer) {
|
|
202
121
|
useLayoutEffect(() => {
|
|
203
|
-
|
|
122
|
+
if (disable)
|
|
123
|
+
return;
|
|
124
|
+
if (props.inverse && !mounted) {
|
|
125
|
+
setThemeState({ ...themeState, mounted: true });
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
204
128
|
activeThemeManagers.add(themeManager);
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
console.log("Changed theme", componentName, next2, { props });
|
|
215
|
-
}
|
|
216
|
-
forceUpdate();
|
|
129
|
+
const disposeChangeListener = parentManager == null ? void 0 : parentManager.onChangeTheme(() => {
|
|
130
|
+
if (!isNewTheme && !isWeb) {
|
|
131
|
+
setThemeState({
|
|
132
|
+
...themeState,
|
|
133
|
+
state: { ...themeManager.state },
|
|
134
|
+
isNewTheme: false
|
|
135
|
+
});
|
|
136
|
+
} else {
|
|
137
|
+
updateState();
|
|
217
138
|
}
|
|
218
139
|
});
|
|
219
140
|
return () => {
|
|
220
141
|
activeThemeManagers.delete(themeManager);
|
|
221
|
-
|
|
142
|
+
disposeChangeListener == null ? void 0 : disposeChangeListener();
|
|
222
143
|
};
|
|
223
|
-
}, [
|
|
144
|
+
}, [disable, state, isNewTheme, debug]);
|
|
145
|
+
}
|
|
146
|
+
if (process.env.NODE_ENV === "development" && debug)
|
|
147
|
+
console.log("useTheme.render isNewTheme", isNewTheme, props, themeManager.state.name, parentManager == null ? void 0 : parentManager.state.name);
|
|
148
|
+
if (hasNoThemeUpdatingProps(props)) {
|
|
149
|
+
if (!parentManager)
|
|
150
|
+
throw new Error(`Nada`);
|
|
151
|
+
return {
|
|
152
|
+
...parentManager.state,
|
|
153
|
+
themes,
|
|
154
|
+
themeManager: parentManager,
|
|
155
|
+
isNewTheme: false
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
updateState();
|
|
159
|
+
if (!mounted && !parentManager) {
|
|
160
|
+
throw new Error(`Impossible`);
|
|
224
161
|
}
|
|
225
162
|
return {
|
|
226
|
-
...
|
|
227
|
-
|
|
228
|
-
theme: parentManager.theme
|
|
229
|
-
},
|
|
230
|
-
...next,
|
|
231
|
-
className: next.className === parentManager.className ? void 0 : next.className,
|
|
163
|
+
...state,
|
|
164
|
+
isNewTheme,
|
|
232
165
|
themes,
|
|
233
|
-
themeManager
|
|
166
|
+
themeManager,
|
|
167
|
+
...!mounted && parentManager && {
|
|
168
|
+
...parentManager.state,
|
|
169
|
+
isNewTheme: false,
|
|
170
|
+
themeManager: parentManager
|
|
171
|
+
}
|
|
234
172
|
};
|
|
173
|
+
function createState(prev) {
|
|
174
|
+
const _ = new ThemeManager(props, root ? "root" : parentManager);
|
|
175
|
+
const isNewTheme2 = _ !== parentManager;
|
|
176
|
+
if (process.env.NODE_ENV === "development" && debug)
|
|
177
|
+
[console.groupCollapsed("useTheme create() isNewTheme", isNewTheme2), console.log("parent.state.name", parentManager == null ? void 0 : parentManager.state.name, "\n", "props", props, "\n", isClient ? parentManager : "", "getState", isNewTheme2 && isClient ? _.getState(props) : "", "\n", "state", isClient ? { ..._.state } : ""), console.groupEnd()];
|
|
178
|
+
const mounted2 = !props.inverse ? true : root || (prev == null ? void 0 : prev.mounted) || false;
|
|
179
|
+
return {
|
|
180
|
+
isNewTheme: isNewTheme2,
|
|
181
|
+
state: { ..._.state },
|
|
182
|
+
themeManager: _,
|
|
183
|
+
mounted: mounted2
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function updateState() {
|
|
187
|
+
if (themeManager.getStateIfChanged(props, state, parentManager)) {
|
|
188
|
+
setThemeState(createState);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
235
191
|
};
|
|
236
192
|
export {
|
|
237
193
|
activeThemeManagers,
|
|
194
|
+
getThemeIsNewTheme,
|
|
238
195
|
getThemeManager,
|
|
239
196
|
useChangeThemeEffect,
|
|
240
|
-
|
|
241
|
-
useTheme,
|
|
242
|
-
useThemeName
|
|
197
|
+
useTheme
|
|
243
198
|
};
|
|
244
199
|
//# sourceMappingURL=useTheme.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/useTheme.tsx"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["name", "
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-console */\nimport { isClient, isRSC, isServer, isWeb } from '@tamagui/constants'\nimport { useContext, useLayoutEffect, useMemo, useState } from 'react'\n\nimport { getConfig } from '../config'\nimport { isDevTools } from '../constants/isDevTools'\nimport { createProxy } from '../helpers/createProxy'\nimport { ThemeManager, ThemeManagerState, hasNoThemeUpdatingProps } from '../helpers/ThemeManager'\nimport { ThemeManagerContext } from '../helpers/ThemeManagerContext'\nimport { ThemeParsed, ThemeProps } from '../types'\nimport { GetThemeUnwrapped } from './getThemeUnwrapped'\n\nexport type ChangedThemeResponse = {\n themes: Record<string, ThemeParsed>\n themeManager: ThemeManager | null\n name: string\n isNewTheme?: boolean\n theme?: ThemeParsed | null\n className?: string\n}\n\nconst emptyProps = { name: null }\nexport const useTheme = (props: ThemeProps = emptyProps): ThemeParsed => {\n if (isRSC) {\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\n const { name, theme, themes, themeManager, className, isNewTheme } = useChangeThemeEffect(props)\n\n if (process.env.NODE_ENV === 'development') {\n // ensure we aren't creating too many ThemeManagers\n if (isWeb && isNewTheme && className === themeManager?.parentManager?.state.className) {\n console.error(`Should always change, duplicating ThemeMananger bug`, themeManager)\n // eslint-disable-next-line no-debugger\n debugger\n }\n if (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\n if (!theme) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('No theme found', name, props, themeManager)\n }\n return themes[Object.keys(themes)[0]]\n }\n\n return useMemo(() => {\n return getThemeProxied({\n isNewTheme,\n theme,\n name,\n className,\n themeManager,\n })\n }, [theme, isNewTheme, name, className, themeManager])\n}\n\nfunction getThemeProxied({\n theme,\n name,\n className,\n themeManager,\n isNewTheme,\n}: {\n theme: any\n name: string\n className?: string\n themeManager?: ThemeManager | null\n isNewTheme?: boolean\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 } else if (key === GetThemeManager) {\n return themeManager\n } else if (key === GetIsNewTheme) {\n return isNewTheme\n } else if (key === 'name') {\n return name\n } else if (key === 'className') {\n return className\n } else if (!name || key === '__proto__' || typeof key === 'symbol' || key === '$typeof') {\n return Reflect.get(_, key)\n }\n // auto convert variables to plain\n if (key[0] === '$') key = key.slice(1)\n if (!themeManager) {\n return theme[key]\n }\n return themeManager.getValue(key)\n },\n })\n}\n\nconst GetThemeManager = Symbol()\nconst GetIsNewTheme = Symbol()\n\nexport const getThemeManager = (theme: any): ThemeManager | undefined => theme?.[GetThemeManager]\nexport const getThemeIsNewTheme = (theme: any): ThemeManager | undefined => theme?.[GetIsNewTheme]\n\nexport const activeThemeManagers = new Set<ThemeManager>()\n\nexport const useChangeThemeEffect = (props: ThemeProps, root = false): ChangedThemeResponse => {\n const parentManager = useContext(ThemeManagerContext)\n const config = getConfig()\n const { debug } = props\n // @ts-expect-error internal use only\n const disable = props.disable\n const { themes } = config\n if (isRSC) {\n // we need context working for this to work well\n return {\n ...createState().state,\n themes,\n themeManager: null,\n }\n }\n if (disable) {\n if (!parentManager) throw new Error(`Disable topmost`)\n return {\n ...parentManager.state,\n isNewTheme: false,\n themes,\n themeManager: parentManager,\n }\n }\n\n type State = {\n isNewTheme: boolean\n state: ThemeManagerState\n themeManager: ThemeManager\n mounted?: boolean\n }\n\n const [themeState, setThemeState] = useState<State>(createState)\n const { isNewTheme, state, themeManager, mounted } = themeState\n\n if (!isServer) {\n useLayoutEffect(() => {\n if (disable) return\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 activeThemeManagers.add(themeManager)\n const disposeChangeListener = parentManager?.onChangeTheme(() => {\n if (!isNewTheme && !isWeb) {\n setThemeState({\n ...themeState,\n state: { ...themeManager.state },\n isNewTheme: false,\n })\n } else {\n updateState()\n }\n })\n return () => {\n activeThemeManagers.delete(themeManager)\n disposeChangeListener?.()\n }\n }, [disable, state, isNewTheme, debug])\n }\n\n // prettier-ignore\n if (process.env.NODE_ENV === 'development' && debug) console.log('useTheme.render isNewTheme', isNewTheme, props, themeManager.state.name, parentManager?.state.name)\n\n // this seems unnecessary\n if (hasNoThemeUpdatingProps(props)) {\n if (!parentManager) throw new Error(`Nada`)\n return {\n ...parentManager.state,\n themes,\n themeManager: parentManager,\n isNewTheme: false,\n }\n }\n\n // run inline in render\n updateState()\n\n if (!mounted && !parentManager) {\n throw new Error(`Impossible`)\n }\n\n return {\n ...state,\n isNewTheme,\n themes,\n themeManager,\n ...(!mounted &&\n parentManager && {\n ...parentManager.state,\n isNewTheme: false,\n themeManager: parentManager,\n }),\n }\n\n function createState(prev?: State) {\n const _ = new ThemeManager(props, root ? 'root' : parentManager)\n const isNewTheme = _ !== parentManager\n // prettier-ignore\n if (process.env.NODE_ENV === 'development' && debug) [console.groupCollapsed('useTheme create() isNewTheme', isNewTheme), console.log('parent.state.name', parentManager?.state.name, '\\n', 'props', props, '\\n', isClient ? parentManager : '', 'getState', isNewTheme && isClient ? _.getState(props) : '', '\\n', 'state', isClient ? { ..._.state } : ''), console.groupEnd()]\n // only inverse relies on this for ssr\n const mounted = !props.inverse ? true : root || prev?.mounted || false\n return {\n // ThemeManager returns parentManager if no change\n isNewTheme,\n state: { ..._.state },\n themeManager: _,\n mounted,\n }\n }\n\n function updateState() {\n if (themeManager.getStateIfChanged(props, state, parentManager)) {\n setThemeState(createState)\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,UAAU,OAAO,UAAU,aAAa;AACjD,SAAS,YAAY,iBAAiB,SAAS,gBAAgB;AAE/D,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,mBAAmB;AAC5B,SAAS,cAAiC,+BAA+B;AACzE,SAAS,2BAA2B;AAEpC,SAAS,yBAAyB;AAWlC,MAAM,aAAa,EAAE,MAAM,KAAK;AACzB,MAAM,WAAW,CAAC,QAAoB,eAA4B;AAtBzE;AAuBE,MAAI,OAAO;AACT,UAAM,SAAS,UAAU;AACzB,UAAMA,QAAO,OAAO,KAAK,OAAO,MAAM,EAAE;AACxC,WAAO,gBAAgB;AAAA,MACrB,OAAO,OAAO,OAAOA;AAAA,MACrB,MAAAA;AAAA,IACF,CAAC;AAAA,EACH;AAEA,QAAM,EAAE,MAAM,OAAO,QAAQ,cAAc,WAAW,WAAW,IAAI,qBAAqB,KAAK;AAE/F,MAAI,QAAQ,IAAI,aAAa,eAAe;AAE1C,QAAI,SAAS,cAAc,gBAAc,kDAAc,kBAAd,mBAA6B,MAAM,YAAW;AACrF,cAAQ,MAAM,uDAAuD,YAAY;AAEjF;AAAA,IACF;AACA,QAAI,MAAM,UAAU,WAAW;AAC7B,cAAQ,eAAe,2BAAoB,IAAI;AAC/C,YAAM,OAAO,EAAE,GAAG,OAAO,MAAM,WAAW,GAAI,cAAc,EAAE,MAAM,EAAG;AACvE,iBAAW,OAAO,MAAM;AACtB,gBAAQ,IAAI,MAAM,KAAK,KAAK,IAAI;AAAA,MAClC;AACA,cAAQ,SAAS;AAAA,IACnB;AAAA,EACF;AAEA,MAAI,CAAC,OAAO;AACV,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,cAAQ,KAAK,kBAAkB,MAAM,OAAO,YAAY;AAAA,IAC1D;AACA,WAAO,OAAO,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NewTheme", "mounted"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isRSC, useIsomorphicLayoutEffect } from "@tamagui/constants";
|
|
2
|
+
import { useContext, useState } from "react";
|
|
3
|
+
import { getConfig } from "../config";
|
|
4
|
+
import { ThemeManagerContext } from "../helpers/ThemeManagerContext";
|
|
5
|
+
function useThemeName(opts) {
|
|
6
|
+
if (isRSC) {
|
|
7
|
+
const config = getConfig();
|
|
8
|
+
return config.themes[Object.keys(config.themes)[0]];
|
|
9
|
+
}
|
|
10
|
+
const manager = useContext(ThemeManagerContext);
|
|
11
|
+
const [name, setName] = useState((manager == null ? void 0 : manager.state.name) || "");
|
|
12
|
+
useIsomorphicLayoutEffect(() => {
|
|
13
|
+
return manager == null ? void 0 : manager.onChangeTheme((next, manager2) => {
|
|
14
|
+
const name2 = (opts == null ? void 0 : opts.parent) ? manager2.state.parentName || next : next;
|
|
15
|
+
if (!name2)
|
|
16
|
+
return;
|
|
17
|
+
setName(name2);
|
|
18
|
+
});
|
|
19
|
+
}, [manager]);
|
|
20
|
+
return name;
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
useThemeName
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=useThemeName.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/useThemeName.tsx"],
|
|
4
|
+
"sourcesContent": ["import { isRSC, useIsomorphicLayoutEffect } from '@tamagui/constants'\nimport { useContext, useState } from 'react'\n\nimport { getConfig } from '../config'\nimport { ThemeManagerContext } from '../helpers/ThemeManagerContext'\nimport { ThemeName } from '../types'\n\nexport function useThemeName(opts?: { parent?: true }): ThemeName {\n if (isRSC) {\n const config = getConfig()\n return config.themes[Object.keys(config.themes)[0]] as any\n }\n const manager = useContext(ThemeManagerContext)\n const [name, setName] = useState(manager?.state.name || '')\n\n useIsomorphicLayoutEffect(() => {\n return manager?.onChangeTheme((next, manager) => {\n const name = opts?.parent ? manager.state.parentName || next : next\n if (!name) return\n setName(name)\n })\n }, [manager])\n\n return name\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,OAAO,iCAAiC;AACjD,SAAS,YAAY,gBAAgB;AAErC,SAAS,iBAAiB;AAC1B,SAAS,2BAA2B;AAG7B,SAAS,aAAa,MAAqC;AAChE,MAAI,OAAO;AACT,UAAM,SAAS,UAAU;AACzB,WAAO,OAAO,OAAO,OAAO,KAAK,OAAO,MAAM,EAAE;AAAA,EAClD;AACA,QAAM,UAAU,WAAW,mBAAmB;AAC9C,QAAM,CAAC,MAAM,OAAO,IAAI,UAAS,mCAAS,MAAM,SAAQ,EAAE;AAE1D,4BAA0B,MAAM;AAC9B,WAAO,mCAAS,cAAc,CAAC,MAAMA,aAAY;AAC/C,YAAMC,SAAO,6BAAM,UAASD,SAAQ,MAAM,cAAc,OAAO;AAC/D,UAAI,CAACC;AAAM;AACX,cAAQA,KAAI;AAAA,IACd;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO;AACT;",
|
|
6
|
+
"names": ["manager", "name"]
|
|
7
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -13,7 +13,7 @@ export * from "./updateTheme";
|
|
|
13
13
|
export * from "./styled";
|
|
14
14
|
export * from "./types";
|
|
15
15
|
export * from "./setupReactNative";
|
|
16
|
-
import {
|
|
16
|
+
import { getConfig, getThemes, getTokens, onConfiguredOnce } from "./config";
|
|
17
17
|
export * from "./constants/constants";
|
|
18
18
|
export * from "./helpers/useShallowSetState";
|
|
19
19
|
export * from "./helpers/getVariantExtras";
|
|
@@ -30,7 +30,7 @@ export * from "./helpers/isTamaguiComponent";
|
|
|
30
30
|
export * from "./helpers/matchMedia";
|
|
31
31
|
export * from "./helpers/themeable";
|
|
32
32
|
export * from "./helpers/withStaticProperties";
|
|
33
|
-
export * from "./contexts/
|
|
33
|
+
export * from "./contexts/ButtonNestingContext";
|
|
34
34
|
export * from "./hooks/useId";
|
|
35
35
|
export * from "./hooks/useIsTouchDevice";
|
|
36
36
|
import {
|
|
@@ -45,15 +45,14 @@ import {
|
|
|
45
45
|
mediaQueryConfig
|
|
46
46
|
} from "./hooks/useMedia";
|
|
47
47
|
export * from "./hooks/useTheme";
|
|
48
|
+
export * from "./hooks/useThemeName";
|
|
48
49
|
export * from "./hooks/useSafeRef";
|
|
49
50
|
export * from "./views/Slot";
|
|
50
51
|
export * from "./views/Stack";
|
|
51
52
|
export * from "./views/Text";
|
|
52
53
|
export * from "./contexts/TextAncestorContext";
|
|
53
54
|
export * from "./views/Theme";
|
|
54
|
-
export * from "./views/ThemeInverse";
|
|
55
55
|
export * from "./views/ThemeProvider";
|
|
56
|
-
export * from "./views/ThemeReset";
|
|
57
56
|
export * from "./views/FontLanguage";
|
|
58
57
|
export * from "./views/TamaguiProvider";
|
|
59
58
|
export * from "@tamagui/use-force-update";
|
|
@@ -66,7 +65,6 @@ export {
|
|
|
66
65
|
addMediaQueryListener,
|
|
67
66
|
configureMedia,
|
|
68
67
|
getConfig,
|
|
69
|
-
getHasConfigured,
|
|
70
68
|
getMedia,
|
|
71
69
|
getThemes,
|
|
72
70
|
getTokens,
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './Tamagui'\nexport * from './createComponent'\nexport * from './createShorthands'\nexport * from './createTheme'\nexport * from './createTamagui'\nexport * from './createFont'\nexport * from './createTokens'\nexport * from './createVariable'\nexport * from './createVariables'\nexport * from './insertFont'\nexport * from './addTheme'\nexport * from './updateTheme'\nexport * from './styled'\nexport * from './types'\nexport * from './setupReactNative'\n\n// for type portability\nexport type { RNWTextProps, RNWViewProps } from './types-rnw'\nexport {
|
|
5
|
-
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAId,SAAS,
|
|
4
|
+
"sourcesContent": ["export * from './Tamagui'\nexport * from './createComponent'\nexport * from './createShorthands'\nexport * from './createTheme'\nexport * from './createTamagui'\nexport * from './createFont'\nexport * from './createTokens'\nexport * from './createVariable'\nexport * from './createVariables'\nexport * from './insertFont'\nexport * from './addTheme'\nexport * from './updateTheme'\nexport * from './styled'\nexport * from './types'\nexport * from './setupReactNative'\n\n// for type portability\nexport type { RNWTextProps, RNWViewProps } from './types-rnw'\nexport { getConfig, getThemes, getTokens, onConfiguredOnce } from './config'\n\nexport * from './constants/constants'\n\nexport * from './helpers/useShallowSetState'\nexport * from './helpers/getVariantExtras'\nexport * from './helpers/getAnimationDriver'\nexport * from './helpers/getExpandedShorthands'\nexport * from './helpers/getSize'\nexport * from './helpers/getSplitStyles'\nexport * from './helpers/getStylesAtomic'\nexport * from './helpers/pseudoDescriptors'\nexport * from './helpers/mergeProps'\nexport * from './helpers/expandStyles'\nexport * from './helpers/isTamaguiElement'\nexport * from './helpers/isTamaguiComponent'\nexport * from './helpers/matchMedia'\nexport * from './helpers/themeable'\nexport * from './helpers/withStaticProperties'\n\nexport * from './contexts/ButtonNestingContext'\n\nexport * from './hooks/useId'\nexport * from './hooks/useIsTouchDevice'\n\nexport {\n configureMedia,\n getMedia,\n mediaState,\n useMedia,\n useMediaPropsActive,\n mediaObjectToString,\n addMediaQueryListener,\n removeMediaQueryListener,\n mediaQueryConfig,\n} from './hooks/useMedia'\nexport * from './hooks/useTheme'\nexport * from './hooks/useThemeName'\nexport * from './hooks/useSafeRef'\n\nexport * from './views/Slot'\nexport * from './views/Stack'\nexport * from './views/Text'\nexport * from './contexts/TextAncestorContext'\nexport * from './views/Theme'\nexport * from './views/ThemeProvider'\nexport * from './views/FontLanguage'\nexport * from './views/TamaguiProvider'\n\nexport * from '@tamagui/use-force-update'\nexport * from '@tamagui/use-did-finish-ssr'\nexport * from '@tamagui/use-event'\nexport * from '@tamagui/compose-refs'\nexport * from '@tamagui/helpers'\nexport * from '@tamagui/constants'\n"],
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAId,SAAS,WAAW,WAAW,WAAW,wBAAwB;AAElE,cAAc;AAEd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,cAAc;AAEd,cAAc;AACd,cAAc;AAEd;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,cAAc;AACd,cAAc;AACd,cAAc;AAEd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,12 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
function
|
|
3
|
-
return
|
|
1
|
+
const ReactNativeStaticConfigs = /* @__PURE__ */ new WeakMap();
|
|
2
|
+
function getReactNativeConfig(Component) {
|
|
3
|
+
return ReactNativeStaticConfigs.get(Component);
|
|
4
4
|
}
|
|
5
|
-
function setupReactNative(
|
|
6
|
-
|
|
5
|
+
function setupReactNative(rnExports) {
|
|
6
|
+
for (const key in rnExports) {
|
|
7
|
+
if (key[0].toLowerCase() === key[0])
|
|
8
|
+
continue;
|
|
9
|
+
if (!rnExports[key])
|
|
10
|
+
continue;
|
|
11
|
+
ReactNativeStaticConfigs.set(rnExports[key], {
|
|
12
|
+
isReactNative: true,
|
|
13
|
+
isText: key === "Text" || key === "TextInput",
|
|
14
|
+
isInput: key === "TextInput",
|
|
15
|
+
inlineProps: key === "Image" ? /* @__PURE__ */ new Set(["src", "width", "height"]) : void 0
|
|
16
|
+
});
|
|
17
|
+
}
|
|
7
18
|
}
|
|
8
19
|
export {
|
|
9
|
-
|
|
20
|
+
ReactNativeStaticConfigs,
|
|
21
|
+
getReactNativeConfig,
|
|
10
22
|
setupReactNative
|
|
11
23
|
};
|
|
12
24
|
//# sourceMappingURL=setupReactNative.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/setupReactNative.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { StaticConfig } from './types'\n\nexport const ReactNativeStaticConfigs = new WeakMap<any, Partial<StaticConfig> | null>()\n\nexport function getReactNativeConfig(Component: any) {\n return ReactNativeStaticConfigs.get(Component)\n}\n\nexport function setupReactNative(rnExports: Record<string, any>) {\n for (const key in rnExports) {\n if (key[0].toLowerCase() === key[0]) continue\n if (!rnExports[key]) continue\n ReactNativeStaticConfigs.set(rnExports[key], {\n isReactNative: true,\n isText: key === 'Text' || key === 'TextInput',\n isInput: key === 'TextInput',\n inlineProps: key === 'Image' ? new Set(['src', 'width', 'height']) : undefined,\n })\n }\n}\n"],
|
|
5
|
+
"mappings": "AAEO,MAAM,2BAA2B,oBAAI,QAA2C;AAEhF,SAAS,qBAAqB,WAAgB;AACnD,SAAO,yBAAyB,IAAI,SAAS;AAC/C;AAEO,SAAS,iBAAiB,WAAgC;AAC/D,aAAW,OAAO,WAAW;AAC3B,QAAI,IAAI,GAAG,YAAY,MAAM,IAAI;AAAI;AACrC,QAAI,CAAC,UAAU;AAAM;AACrB,6BAAyB,IAAI,UAAU,MAAM;AAAA,MAC3C,eAAe;AAAA,MACf,QAAQ,QAAQ,UAAU,QAAQ;AAAA,MAClC,SAAS,QAAQ;AAAA,MACjB,aAAa,QAAQ,UAAU,oBAAI,IAAI,CAAC,OAAO,SAAS,QAAQ,CAAC,IAAI;AAAA,IACvE,CAAC;AAAA,EACH;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|