@tamagui/core 1.0.1-rc.8 → 1.0.1
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/Pressability.js +32 -0
- package/dist/cjs/Pressability.js.map +7 -0
- package/dist/cjs/Pressability.native.js +32 -0
- package/dist/cjs/Pressability.native.js.map +7 -0
- package/dist/cjs/ThemeContext.js +30 -0
- package/dist/cjs/ThemeContext.js.map +7 -0
- package/dist/cjs/ThemeManager.js +211 -0
- package/dist/cjs/ThemeManager.js.map +7 -0
- package/dist/cjs/conf.js +70 -0
- package/dist/cjs/conf.js.map +7 -0
- package/dist/cjs/constants/platform.js +4 -10
- package/dist/cjs/constants/platform.js.map +2 -2
- package/dist/cjs/constants/rnw.native.js +28 -0
- package/dist/cjs/constants/rnw.native.js.map +7 -0
- package/dist/cjs/contexts/ButtonInsideButtonContext.js.map +1 -1
- package/dist/cjs/createComponent.js +25 -27
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/createTamagui.js +4 -1
- package/dist/cjs/createTamagui.js.map +2 -2
- package/dist/cjs/defaultComponentState.js +2 -0
- package/dist/cjs/defaultComponentState.js.map +7 -0
- package/dist/cjs/helpers/ThemeManager.js +4 -2
- package/dist/cjs/helpers/ThemeManager.js.map +2 -2
- package/dist/cjs/helpers/Unwrap.js +29 -0
- package/dist/cjs/helpers/Unwrap.js.map +7 -0
- package/dist/cjs/helpers/assignNativePropsToWeb.js.map +1 -1
- package/dist/cjs/helpers/assignNativePropsToWeb.native.js.map +1 -1
- package/dist/cjs/helpers/cache.js +7 -11
- package/dist/cjs/helpers/cache.js.map +2 -2
- package/dist/cjs/helpers/calc.js.map +2 -2
- package/dist/cjs/helpers/createShallowUpdate.js +9 -12
- package/dist/cjs/helpers/createShallowUpdate.js.map +1 -1
- package/dist/cjs/helpers/createTamaguiProvider.js +65 -0
- package/dist/cjs/helpers/createTamaguiProvider.js.map +7 -0
- package/dist/cjs/helpers/cssHash.js +51 -0
- package/dist/cjs/helpers/cssHash.js.map +7 -0
- package/dist/cjs/helpers/expandStyle.js +29 -41
- package/dist/cjs/helpers/expandStyle.js.map +2 -2
- package/dist/cjs/helpers/expandStyle.test.js +10 -0
- package/dist/cjs/helpers/expandStyle.test.js.map +7 -0
- package/dist/cjs/helpers/getFont.js +2 -6
- package/dist/cjs/helpers/getFont.js.map +2 -2
- package/dist/cjs/helpers/getSplitStyles.js +22 -23
- package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
- package/dist/cjs/helpers/getStackSize.js.map +1 -1
- package/dist/cjs/helpers/getStylesAtomic.js +10 -11
- package/dist/cjs/helpers/getStylesAtomic.js.map +2 -2
- package/dist/cjs/helpers/insertStyleRule.js +58 -27
- package/dist/cjs/helpers/insertStyleRule.js.map +3 -3
- package/dist/cjs/helpers/nativeGestureHandler.native.js +19 -0
- package/dist/cjs/helpers/nativeGestureHandler.native.js.map +7 -0
- package/dist/cjs/helpers/normalizeValueWithProperty.js +3 -3
- package/dist/cjs/helpers/normalizeValueWithProperty.js.map +2 -2
- package/dist/cjs/helpers/startTransition.js +1 -4
- package/dist/cjs/helpers/startTransition.js.map +2 -2
- package/dist/cjs/helpers/themeable.js +2 -2
- package/dist/cjs/helpers/themeable.js.map +2 -2
- package/dist/cjs/helpers/wrapThemeManagerContext.js +37 -0
- package/dist/cjs/helpers/wrapThemeManagerContext.js.map +7 -0
- package/dist/cjs/hooks/useConstant.js +0 -3
- package/dist/cjs/hooks/useConstant.js.map +2 -2
- package/dist/cjs/hooks/useElementLayout.js +1 -1
- package/dist/cjs/hooks/useElementLayout.js.map +2 -2
- package/dist/cjs/hooks/useFeatures.js +201 -0
- package/dist/cjs/hooks/useFeatures.js.map +7 -0
- package/dist/cjs/hooks/useIsMounted.js.map +1 -1
- package/dist/cjs/hooks/useIsSSR.js +6 -10
- package/dist/cjs/hooks/useIsSSR.js.map +2 -2
- package/dist/cjs/hooks/useMedia.js +5 -0
- package/dist/cjs/hooks/useMedia.js.map +2 -2
- package/dist/cjs/hooks/usePressable.js.map +1 -1
- package/dist/cjs/hooks/usePrevious.js +1 -0
- package/dist/cjs/hooks/usePrevious.js.map +7 -0
- package/dist/cjs/hooks/useTheme.js +45 -50
- package/dist/cjs/hooks/useTheme.js.map +3 -3
- package/dist/cjs/hooks/useUnmountEffect.js.map +1 -1
- package/dist/cjs/styled.js +12 -0
- package/dist/cjs/styled.js.map +2 -2
- package/dist/cjs/views/TamaguiProvider.js +3 -0
- package/dist/cjs/views/TamaguiProvider.js.map +2 -2
- package/dist/cjs/views/TextAncestorContext.js +44 -0
- package/dist/cjs/views/TextAncestorContext.js.map +7 -0
- package/dist/cjs/views/Theme.js +15 -21
- package/dist/cjs/views/Theme.js.map +3 -3
- package/dist/cjs/views/ThemeInverse.js +20 -21
- package/dist/cjs/views/ThemeInverse.js.map +2 -2
- package/dist/cjs/views/ThemeReset.js +5 -10
- package/dist/cjs/views/ThemeReset.js.map +3 -3
- package/dist/esm/Pressability.js +7 -0
- package/dist/esm/Pressability.js.map +7 -0
- package/dist/esm/Pressability.native.js +7 -0
- package/dist/esm/Pressability.native.js.map +7 -0
- package/dist/esm/ThemeContext.js +6 -0
- package/dist/esm/ThemeContext.js.map +7 -0
- package/dist/esm/ThemeManager.js +185 -0
- package/dist/esm/ThemeManager.js.map +7 -0
- package/dist/esm/conf.js +39 -0
- package/dist/esm/conf.js.map +7 -0
- package/dist/esm/constants/platform.js +3 -7
- package/dist/esm/constants/platform.js.map +2 -2
- package/dist/esm/constants/rnw.native.js +5 -0
- package/dist/esm/constants/rnw.native.js.map +7 -0
- package/dist/esm/contexts/ButtonInsideButtonContext.js.map +1 -1
- package/dist/esm/createComponent.js +26 -28
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/createTamagui.js +9 -2
- package/dist/esm/createTamagui.js.map +2 -2
- package/dist/esm/defaultComponentState.js +1 -0
- package/dist/esm/defaultComponentState.js.map +7 -0
- package/dist/esm/helpers/ThemeManager.js +4 -2
- package/dist/esm/helpers/ThemeManager.js.map +2 -2
- package/dist/esm/helpers/Unwrap.js +5 -0
- package/dist/esm/helpers/Unwrap.js.map +7 -0
- package/dist/esm/helpers/assignNativePropsToWeb.js.map +1 -1
- package/dist/esm/helpers/assignNativePropsToWeb.native.js.map +1 -1
- package/dist/esm/helpers/cache.js +7 -10
- package/dist/esm/helpers/cache.js.map +2 -2
- package/dist/esm/helpers/calc.js.map +2 -2
- package/dist/esm/helpers/createShallowUpdate.js +9 -12
- package/dist/esm/helpers/createShallowUpdate.js.map +1 -1
- package/dist/esm/helpers/createTamaguiProvider.js +38 -0
- package/dist/esm/helpers/createTamaguiProvider.js.map +7 -0
- package/dist/esm/helpers/cssHash.js +27 -0
- package/dist/esm/helpers/cssHash.js.map +7 -0
- package/dist/esm/helpers/expandStyle.js +26 -38
- package/dist/esm/helpers/expandStyle.js.map +2 -2
- package/dist/esm/helpers/expandStyle.test.js +9 -0
- package/dist/esm/helpers/expandStyle.test.js.map +7 -0
- package/dist/esm/helpers/getFont.js +2 -6
- package/dist/esm/helpers/getFont.js.map +2 -2
- package/dist/esm/helpers/getSplitStyles.js +24 -24
- package/dist/esm/helpers/getSplitStyles.js.map +2 -2
- package/dist/esm/helpers/getStackSize.js.map +1 -1
- package/dist/esm/helpers/getStylesAtomic.js +10 -11
- package/dist/esm/helpers/getStylesAtomic.js.map +2 -2
- package/dist/esm/helpers/insertStyleRule.js +56 -26
- package/dist/esm/helpers/insertStyleRule.js.map +3 -3
- package/dist/esm/helpers/nativeGestureHandler.native.js +2 -0
- package/dist/esm/helpers/nativeGestureHandler.native.js.map +7 -0
- package/dist/esm/helpers/normalizeValueWithProperty.js +3 -3
- package/dist/esm/helpers/normalizeValueWithProperty.js.map +2 -2
- package/dist/esm/helpers/startTransition.js.map +1 -1
- package/dist/esm/helpers/themeable.js +2 -2
- package/dist/esm/helpers/themeable.js.map +2 -2
- package/dist/esm/helpers/wrapThemeManagerContext.js +11 -0
- package/dist/esm/helpers/wrapThemeManagerContext.js.map +7 -0
- package/dist/esm/hooks/useConstant.js +1 -4
- package/dist/esm/hooks/useConstant.js.map +2 -2
- package/dist/esm/hooks/useElementLayout.js +1 -1
- package/dist/esm/hooks/useElementLayout.js.map +2 -2
- package/dist/esm/hooks/useFeatures.js +174 -0
- package/dist/esm/hooks/useFeatures.js.map +7 -0
- package/dist/esm/hooks/useIsMounted.js.map +1 -1
- package/dist/esm/hooks/useIsSSR.js +8 -12
- package/dist/esm/hooks/useIsSSR.js.map +2 -2
- package/dist/esm/hooks/useMedia.js +4 -0
- package/dist/esm/hooks/useMedia.js.map +2 -2
- package/dist/esm/hooks/usePressable.js.map +1 -1
- package/dist/esm/hooks/usePrevious.js +1 -0
- package/dist/esm/hooks/usePrevious.js.map +7 -0
- package/dist/esm/hooks/useTheme.js +45 -50
- package/dist/esm/hooks/useTheme.js.map +3 -3
- package/dist/esm/hooks/useUnmountEffect.js.map +1 -1
- package/dist/esm/styled.js +12 -0
- package/dist/esm/styled.js.map +2 -2
- package/dist/esm/views/TamaguiProvider.js +3 -0
- package/dist/esm/views/TamaguiProvider.js.map +2 -2
- package/dist/esm/views/TextAncestorContext.js +15 -0
- package/dist/esm/views/TextAncestorContext.js.map +7 -0
- package/dist/esm/views/Theme.js +14 -14
- package/dist/esm/views/Theme.js.map +2 -2
- package/dist/esm/views/ThemeInverse.js +15 -20
- package/dist/esm/views/ThemeInverse.js.map +2 -2
- package/dist/esm/views/ThemeReset.js +4 -6
- package/dist/esm/views/ThemeReset.js.map +2 -2
- package/package.json +13 -14
- package/src/createComponent.tsx +47 -43
- package/src/createTamagui.ts +10 -2
- package/src/helpers/ThemeManager.tsx +7 -2
- package/src/helpers/cache.ts +7 -9
- package/src/helpers/expandStyle.ts +27 -41
- package/src/helpers/getSplitStyles.tsx +40 -23
- package/src/helpers/getStylesAtomic.ts +15 -15
- package/src/helpers/insertStyleRule.tsx +68 -38
- package/src/helpers/normalizeValueWithProperty.ts +3 -3
- package/src/helpers/themeable.tsx +3 -3
- package/src/hooks/useElementLayout.tsx +1 -1
- package/src/hooks/useMedia.tsx +3 -0
- package/src/hooks/useTheme.tsx +67 -48
- package/src/styled.tsx +15 -0
- package/src/views/TamaguiProvider.tsx +6 -0
- package/src/views/Theme.tsx +15 -22
- package/types/createComponent.d.ts +1 -1
- package/types/helpers/ThemeManager.d.ts +1 -1
- package/types/helpers/cache.d.ts +2 -4
- package/types/helpers/insertStyleRule.d.ts +2 -1
- package/types/helpers/themeable.d.ts +1 -1
- package/types/hooks/useMedia.d.ts +1 -0
- package/types/hooks/useTheme.d.ts +1 -1
- package/types/views/Theme.d.ts +1 -1
|
@@ -17,20 +17,16 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
24
21
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
22
|
var ThemeReset_exports = {};
|
|
26
23
|
__export(ThemeReset_exports, {
|
|
27
24
|
ThemeReset: () => ThemeReset
|
|
28
25
|
});
|
|
29
26
|
module.exports = __toCommonJS(ThemeReset_exports);
|
|
30
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
31
27
|
var import_react = __toESM(require("react"));
|
|
32
28
|
var import_platform = require("../constants/platform");
|
|
33
|
-
var import_ThemeManager = require("../
|
|
29
|
+
var import_ThemeManager = require("../ThemeManager");
|
|
34
30
|
var import_Theme = require("./Theme");
|
|
35
31
|
import_react.default["createElement"];
|
|
36
32
|
const ThemeReset = (props) => {
|
|
@@ -55,12 +51,11 @@ const ThemeReset = (props) => {
|
|
|
55
51
|
if (!themeManager || !props.children) {
|
|
56
52
|
return props.children || null;
|
|
57
53
|
}
|
|
58
|
-
return /* @__PURE__ */
|
|
54
|
+
return /* @__PURE__ */ import_react.default.createElement(import_Theme.Theme, {
|
|
59
55
|
className: "tui-theme-reset",
|
|
60
56
|
reset: true,
|
|
61
|
-
name
|
|
62
|
-
|
|
63
|
-
});
|
|
57
|
+
name
|
|
58
|
+
}, props.children);
|
|
64
59
|
};
|
|
65
60
|
// Annotate the CommonJS export names for ESM import in node:
|
|
66
61
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/views/ThemeReset.tsx"],
|
|
4
|
-
"sourcesContent": ["import React, { useContext, useLayoutEffect, useState } from 'react'\n\nimport { isWeb } from '../constants/platform'\nimport { ThemeManagerContext } from '../
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
4
|
+
"sourcesContent": ["import React, { useContext, useLayoutEffect, useState } from 'react'\n\nimport { isWeb } from '../constants/platform'\nimport { ThemeManagerContext } from '../ThemeManager'\nimport { Theme } from './Theme'\n\n// bugfix esbuild strips react jsx: 'preserve'\nReact['createElement']\n\n// resets the theme to the parent theme\nexport const ThemeReset = (props: { children?: any }) => {\n const themeManager = useContext(ThemeManagerContext)\n const [name, setName] = useState<string | null>(null)\n\n // this component doesn't work with SSR, so must run only client side\n // we could at least prevent more flickering by having the ssr head script\n // that changes to dark initially also go through and change all of these\n if (!isWeb || typeof document !== 'undefined') {\n useLayoutEffect(() => {\n if (!themeManager) return\n if (name !== themeManager.parentName) {\n setName(themeManager.parentName)\n }\n }, [themeManager?.parentName])\n\n useLayoutEffect(() => {\n if (!themeManager) return\n return themeManager.onChangeTheme(() => {\n setName(themeManager.parentName)\n })\n }, [])\n }\n\n if (!themeManager || !props.children) {\n return props.children || null\n }\n\n return (\n <Theme className=\"tui-theme-reset\" reset name={name}>\n {props.children}\n </Theme>\n )\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA6D;AAE7D,sBAAsB;AACtB,0BAAoC;AACpC,mBAAsB;AAGtB,qBAAM;AAGC,MAAM,aAAa,CAAC,UAA8B;AACvD,QAAM,eAAe,6BAAW,uCAAmB;AACnD,QAAM,CAAC,MAAM,WAAW,2BAAwB,IAAI;AAKpD,MAAI,CAAC,yBAAS,OAAO,aAAa,aAAa;AAC7C,sCAAgB,MAAM;AACpB,UAAI,CAAC;AAAc;AACnB,UAAI,SAAS,aAAa,YAAY;AACpC,gBAAQ,aAAa,UAAU;AAAA,MACjC;AAAA,IACF,GAAG,CAAC,6CAAc,UAAU,CAAC;AAE7B,sCAAgB,MAAM;AACpB,UAAI,CAAC;AAAc;AACnB,aAAO,aAAa,cAAc,MAAM;AACtC,gBAAQ,aAAa,UAAU;AAAA,MACjC,CAAC;AAAA,IACH,GAAG,CAAC,CAAC;AAAA,EACP;AAEA,MAAI,CAAC,gBAAgB,CAAC,MAAM,UAAU;AACpC,WAAO,MAAM,YAAY;AAAA,EAC3B;AAEA,SACE,mDAAC;AAAA,IAAM,WAAU;AAAA,IAAkB,OAAK;AAAA,IAAC;AAAA,KACtC,MAAM,QACT;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const Pressability = require("react-native/Libraries/Pressability/Pressability").default;
|
|
2
|
+
const usePressability = require("react-native/Libraries/Pressability/usePressability").default;
|
|
3
|
+
export {
|
|
4
|
+
Pressability,
|
|
5
|
+
usePressability
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=Pressability.native.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Pressability.native.tsx"],
|
|
4
|
+
"sourcesContent": ["export const Pressability = require('react-native/Libraries/Pressability/Pressability').default\nexport const usePressability =\n require('react-native/Libraries/Pressability/usePressability').default\n"],
|
|
5
|
+
"mappings": "AAAO,MAAM,eAAe,QAAQ,kDAAkD,EAAE;AACjF,MAAM,kBACX,QAAQ,qDAAqD,EAAE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/ThemeContext.tsx"],
|
|
4
|
+
"sourcesContent": ["import { createContext } from 'react'\n\nimport { ThemeName, Themes } from './types'\n\nexport const ThemeContext = createContext<{ themes: Themes; defaultTheme: ThemeName } | null>(null)\n"],
|
|
5
|
+
"mappings": "AAAA;AAIO,MAAM,eAAe,cAAkE,IAAI;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
import { getThemes } from "./conf";
|
|
3
|
+
import { THEME_CLASSNAME_PREFIX, THEME_NAME_SEPARATOR } from "./constants/constants";
|
|
4
|
+
import { getThemeUnwrapped } from "./hooks/getThemeUnwrapped";
|
|
5
|
+
class ThemeManager {
|
|
6
|
+
constructor(name = "", theme = null, parentManager = null, reset = false) {
|
|
7
|
+
this.name = name;
|
|
8
|
+
this.theme = theme;
|
|
9
|
+
this.parentManager = parentManager;
|
|
10
|
+
this.reset = reset;
|
|
11
|
+
this.keys = /* @__PURE__ */ new Map();
|
|
12
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
13
|
+
this.themeListeners = /* @__PURE__ */ new Set();
|
|
14
|
+
this.className = null;
|
|
15
|
+
let parent = parentManager;
|
|
16
|
+
let tries = 0;
|
|
17
|
+
while (true) {
|
|
18
|
+
tries++;
|
|
19
|
+
if (tries > 10) {
|
|
20
|
+
throw new Error(`Nested 10 of the same theme in a row, likely error`);
|
|
21
|
+
}
|
|
22
|
+
if (!parent)
|
|
23
|
+
break;
|
|
24
|
+
if (parent.name === name) {
|
|
25
|
+
parent = parent.parentManager;
|
|
26
|
+
} else {
|
|
27
|
+
this.parentManager = parent;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
get didChangeTheme() {
|
|
33
|
+
return this.parentManager && this.name !== this.parentManager.fullName;
|
|
34
|
+
}
|
|
35
|
+
get parentName() {
|
|
36
|
+
var _a;
|
|
37
|
+
return ((_a = this.parentManager) == null ? void 0 : _a.name) || null;
|
|
38
|
+
}
|
|
39
|
+
get fullName() {
|
|
40
|
+
return this.getNextTheme().name || this.name || "";
|
|
41
|
+
}
|
|
42
|
+
getValue(key) {
|
|
43
|
+
let theme = this.theme;
|
|
44
|
+
let manager = this;
|
|
45
|
+
while (true) {
|
|
46
|
+
if (!theme)
|
|
47
|
+
return;
|
|
48
|
+
if (key in theme) {
|
|
49
|
+
return theme[key];
|
|
50
|
+
}
|
|
51
|
+
manager = this.parentManager;
|
|
52
|
+
if (!manager) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (manager.theme === theme) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
theme = manager.theme;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
update({ name, theme, className } = {}) {
|
|
62
|
+
const nameChanged = name !== this.name;
|
|
63
|
+
if (!nameChanged) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
this.className = className || null;
|
|
67
|
+
this.name = name || "";
|
|
68
|
+
this.theme = theme;
|
|
69
|
+
this.notifyListeners();
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
getNextTheme(props = {}, debug) {
|
|
73
|
+
var _a;
|
|
74
|
+
const { themes = getThemes(), name, componentName } = props;
|
|
75
|
+
if (props.reset && name) {
|
|
76
|
+
return {
|
|
77
|
+
name,
|
|
78
|
+
theme: themes[name],
|
|
79
|
+
className: this.getClassName(name)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
const parentIsReset = (_a = this.parentManager) == null ? void 0 : _a.reset;
|
|
83
|
+
if (!name) {
|
|
84
|
+
if (componentName) {
|
|
85
|
+
const names = [
|
|
86
|
+
`${this.name}_${componentName}`,
|
|
87
|
+
`${withoutComponentName(this.name)}_${componentName}`
|
|
88
|
+
];
|
|
89
|
+
for (const name2 of names) {
|
|
90
|
+
if (name2 in themes) {
|
|
91
|
+
const className = this.getClassName(name2);
|
|
92
|
+
return { name: name2, theme: themes[name2], className };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
name: this.name,
|
|
98
|
+
theme: this.theme
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
let nextName = name || this.name || "";
|
|
102
|
+
let parentName = parentIsReset ? this.parentName || this.fullName : this.fullName;
|
|
103
|
+
while (true) {
|
|
104
|
+
if (nextName in themes) {
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
nextName = `${parentName}_${name}`;
|
|
108
|
+
if (nextName in themes) {
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
if (!parentName.includes(THEME_NAME_SEPARATOR)) {
|
|
112
|
+
console.warn("theme not found", name);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
parentName = parentName.slice(0, parentName.lastIndexOf(THEME_NAME_SEPARATOR));
|
|
116
|
+
}
|
|
117
|
+
if (componentName) {
|
|
118
|
+
const names = [
|
|
119
|
+
`${nextName}_${componentName}`,
|
|
120
|
+
`${withoutComponentName(nextName)}_${componentName}`
|
|
121
|
+
];
|
|
122
|
+
for (const name2 of names) {
|
|
123
|
+
if (name2 in themes) {
|
|
124
|
+
nextName = name2;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
let theme = themes[nextName];
|
|
129
|
+
if (!theme) {
|
|
130
|
+
theme = themes[`light_${nextName}`];
|
|
131
|
+
}
|
|
132
|
+
if (process.env.NODE_ENV === "development") {
|
|
133
|
+
if (debug) {
|
|
134
|
+
console.log("getNextTheme", this.getClassName(nextName), { props, nextName, parentName });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
name: nextName,
|
|
139
|
+
theme: getThemeUnwrapped(theme),
|
|
140
|
+
className: this.getClassName(nextName)
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
getClassName(name) {
|
|
144
|
+
return `${THEME_CLASSNAME_PREFIX}${name} t_Theme`.replace("light_", "").replace("dark_", "");
|
|
145
|
+
}
|
|
146
|
+
track(uuid, keys) {
|
|
147
|
+
if (!this.name)
|
|
148
|
+
return;
|
|
149
|
+
this.keys.set(uuid, keys);
|
|
150
|
+
}
|
|
151
|
+
notifyListeners() {
|
|
152
|
+
var _a;
|
|
153
|
+
if (!this.name) {
|
|
154
|
+
this.keys.clear();
|
|
155
|
+
}
|
|
156
|
+
for (const [uuid, keys] of this.keys.entries()) {
|
|
157
|
+
if (keys.size) {
|
|
158
|
+
(_a = this.listeners.get(uuid)) == null ? void 0 : _a();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
this.themeListeners.forEach((cb) => cb(this.name, this));
|
|
162
|
+
}
|
|
163
|
+
onChangeTheme(cb) {
|
|
164
|
+
this.themeListeners.add(cb);
|
|
165
|
+
return () => {
|
|
166
|
+
this.themeListeners.delete(cb);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
onUpdate(uuid, cb) {
|
|
170
|
+
this.listeners.set(uuid, cb);
|
|
171
|
+
return () => {
|
|
172
|
+
this.listeners.delete(uuid);
|
|
173
|
+
this.keys.delete(uuid);
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const ThemeManagerContext = createContext(null);
|
|
178
|
+
const emptyManager = new ThemeManager();
|
|
179
|
+
const withoutComponentName = (name) => name.replace(/(\_[A-Z][a-zA-Z]+)+$/g, "");
|
|
180
|
+
export {
|
|
181
|
+
ThemeManager,
|
|
182
|
+
ThemeManagerContext,
|
|
183
|
+
emptyManager
|
|
184
|
+
};
|
|
185
|
+
//# sourceMappingURL=ThemeManager.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/ThemeManager.tsx"],
|
|
4
|
+
"sourcesContent": ["import { createContext } from 'react'\n\nimport { getThemes } from './conf'\nimport { THEME_CLASSNAME_PREFIX, THEME_NAME_SEPARATOR } from './constants/constants'\nimport { getThemeUnwrapped } from './hooks/getThemeUnwrapped'\nimport { ThemeObject, Themes } from './types'\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}\n\nexport type GetNextThemeProps = {\n themes?: Themes\n name?: string | null\n componentName?: string | null\n reset?: boolean\n}\n\nexport class ThemeManager {\n keys = new Map<any, Set<string>>()\n listeners = new Map<any, Function>()\n themeListeners = new Set<ThemeListener>()\n className: string | null = null\n\n constructor(\n public name: string = '',\n public theme: ThemeObject | null = null,\n public parentManager: ThemeManager | null = null,\n public reset: boolean = false\n ) {\n // find the nearest different parentManager\n let parent = parentManager\n let tries = 0\n while (true) {\n tries++\n if (tries > 10) {\n throw new Error(`Nested 10 of the same theme in a row, likely error`)\n }\n if (!parent) break\n if (parent.name === name) {\n // go up if same\n parent = parent.parentManager\n } else {\n this.parentManager = parent\n break\n }\n }\n }\n\n get didChangeTheme() {\n return this.parentManager && this.name !== this.parentManager.fullName\n }\n\n get parentName() {\n return this.parentManager?.name || null\n }\n\n get fullName(): string {\n return this.getNextTheme().name || this.name || ''\n // const parentName = this.parentManager?.fullName || ''\n // const name = this.name || ''\n // const parts = [...new Set([...`${parentName}_${name}`.split('_')])].filter(Boolean)\n // return parts.join('_')\n }\n\n // gets value going up to parents\n getValue(key: string) {\n let theme = this.theme\n let manager = this as ThemeManager | null\n while (true) {\n if (!theme) return\n if (key in theme) {\n return theme[key]\n }\n manager = this.parentManager\n if (!manager) {\n return\n }\n if (manager.theme === theme) {\n return\n }\n theme = manager.theme\n }\n }\n\n update({ name, theme, className }: SetActiveThemeProps = {}) {\n // className compare on web, avoids light/dark re-renders\n const nameChanged = name !== this.name\n if (!nameChanged) {\n return false\n }\n this.className = className || null\n this.name = name || ''\n this.theme = theme\n this.notifyListeners()\n return true\n }\n\n getNextTheme(props: GetNextThemeProps = {}, debug?: any) {\n const { themes = getThemes(), name, componentName } = props\n\n if (props.reset && name) {\n return {\n name: name,\n theme: themes[name],\n className: this.getClassName(name),\n }\n }\n\n const parentIsReset = this.parentManager?.reset\n\n if (!name) {\n if (componentName) {\n // allow for _Card_Button or just _Button\n const names = [\n `${this.name}_${componentName}`,\n `${withoutComponentName(this.name)}_${componentName}`,\n ]\n for (const name of names) {\n if (name in themes) {\n const className = this.getClassName(name)\n return { name, theme: themes[name], className }\n }\n }\n }\n return {\n name: this.name,\n theme: this.theme,\n }\n }\n\n let nextName = name || this.name || ''\n let parentName = parentIsReset ? this.parentName || this.fullName : this.fullName\n\n while (true) {\n if (nextName in themes) {\n break\n }\n nextName = `${parentName}_${name}`\n if (nextName in themes) {\n break\n }\n if (!parentName.includes(THEME_NAME_SEPARATOR)) {\n // not found!\n console.warn('theme not found', name)\n // this happens in next during _document.getInitialProps and has a terrible/non-existent stack trace\n // throw new Error(`Theme not found: ${name}`)\n break\n }\n // go up one\n parentName = parentName.slice(0, parentName.lastIndexOf(THEME_NAME_SEPARATOR))\n }\n\n if (componentName) {\n // allow for _Card_Button or just _Button\n const names = [\n `${nextName}_${componentName}`,\n `${withoutComponentName(nextName)}_${componentName}`,\n ]\n for (const name of names) {\n if (name in themes) {\n nextName = name\n }\n }\n }\n\n let theme = themes[nextName]\n if (!theme) {\n theme = themes[`light_${nextName}`]\n }\n\n if (process.env.NODE_ENV === 'development') {\n if (debug) {\n console.log('getNextTheme', this.getClassName(nextName), { props, nextName, parentName })\n }\n }\n\n return {\n name: nextName,\n theme: getThemeUnwrapped(theme),\n className: this.getClassName(nextName),\n }\n }\n\n getClassName(name: string) {\n return `${THEME_CLASSNAME_PREFIX}${name} t_Theme`.replace('light_', '').replace('dark_', '')\n }\n\n track(uuid: any, keys: Set<string>) {\n if (!this.name) return\n this.keys.set(uuid, keys)\n }\n\n notifyListeners() {\n if (!this.name) {\n this.keys.clear()\n }\n for (const [uuid, keys] of this.keys.entries()) {\n if (keys.size) {\n this.listeners.get(uuid)?.()\n }\n }\n this.themeListeners.forEach((cb) => cb(this.name, this))\n }\n\n onChangeTheme(cb: ThemeListener) {\n this.themeListeners.add(cb)\n return () => {\n this.themeListeners.delete(cb)\n }\n }\n\n onUpdate(uuid: any, cb: Function) {\n this.listeners.set(uuid, cb)\n return () => {\n this.listeners.delete(uuid)\n this.keys.delete(uuid)\n }\n }\n}\n\nexport const ThemeManagerContext = createContext<ThemeManager | null>(null)\nexport const emptyManager = new ThemeManager()\n\nconst withoutComponentName = (name: string) => name.replace(/(\\_[A-Z][a-zA-Z]+)+$/g, '')\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/esm/conf.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
let conf;
|
|
2
|
+
const setConfig = (next) => {
|
|
3
|
+
conf = next;
|
|
4
|
+
if (configListeners.size) {
|
|
5
|
+
configListeners.forEach((cb) => cb(conf));
|
|
6
|
+
configListeners.clear();
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
const setConfigFont = (name, font, fontParsed) => {
|
|
10
|
+
if (process.env.NODE_ENV === "development") {
|
|
11
|
+
if (!conf)
|
|
12
|
+
throw new Error(`Haven't called createTamagui yet`);
|
|
13
|
+
}
|
|
14
|
+
Object.assign(conf.fonts, { [name]: font });
|
|
15
|
+
Object.assign(conf.fontsParsed, { [`$${name}`]: fontParsed });
|
|
16
|
+
};
|
|
17
|
+
const getHasConfigured = () => !!conf;
|
|
18
|
+
const getConfig = () => conf;
|
|
19
|
+
const getTokens = () => conf.tokensParsed;
|
|
20
|
+
const getThemes = () => conf.themes;
|
|
21
|
+
const configListeners = /* @__PURE__ */ new Set();
|
|
22
|
+
const onConfiguredOnce = (cb) => {
|
|
23
|
+
if (conf) {
|
|
24
|
+
cb(conf);
|
|
25
|
+
} else {
|
|
26
|
+
configListeners.add(cb);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
configListeners,
|
|
31
|
+
getConfig,
|
|
32
|
+
getHasConfigured,
|
|
33
|
+
getThemes,
|
|
34
|
+
getTokens,
|
|
35
|
+
onConfiguredOnce,
|
|
36
|
+
setConfig,
|
|
37
|
+
setConfigFont
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=conf.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/conf.ts"],
|
|
4
|
+
"sourcesContent": ["import { ConfigListener, TamaguiInternalConfig } from './types'\n\nlet conf: TamaguiInternalConfig | null\n\nexport const setConfig = (next: TamaguiInternalConfig) => {\n conf = next\n if (configListeners.size) {\n configListeners.forEach((cb) => cb(conf!))\n configListeners.clear()\n }\n}\n\nexport const setConfigFont = (name: string, font: any, fontParsed: any) => {\n if (process.env.NODE_ENV === 'development') {\n if (!conf) throw new Error(`Haven't called createTamagui yet`)\n }\n Object.assign(conf!.fonts, { [name]: font })\n Object.assign(conf!.fontsParsed, { [`$${name}`]: fontParsed })\n}\n\nexport const getHasConfigured = () => !!conf\nexport const getConfig = () => conf!\nexport const getTokens = () => conf!.tokensParsed\nexport const getThemes = () => conf!.themes\n\nexport const configListeners = new Set<ConfigListener>()\n\nexport const onConfiguredOnce = (cb: ConfigListener) => {\n if (conf) {\n cb(conf!)\n } else {\n configListeners.add(cb)\n }\n}\n"],
|
|
5
|
+
"mappings": "AAEA,IAAI;AAEG,MAAM,YAAY,CAAC,SAAgC;AACxD,SAAO;AACP,MAAI,gBAAgB,MAAM;AACxB,oBAAgB,QAAQ,CAAC,OAAO,GAAG,IAAK,CAAC;AACzC,oBAAgB,MAAM;AAAA,EACxB;AACF;AAEO,MAAM,gBAAgB,CAAC,MAAc,MAAW,eAAoB;AACzE,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,CAAC;AAAM,YAAM,IAAI,MAAM,kCAAkC;AAAA,EAC/D;AACA,SAAO,OAAO,KAAM,OAAO,EAAE,CAAC,OAAO,KAAK,CAAC;AAC3C,SAAO,OAAO,KAAM,aAAa,EAAE,CAAC,IAAI,SAAS,WAAW,CAAC;AAC/D;AAEO,MAAM,mBAAmB,MAAM,CAAC,CAAC;AACjC,MAAM,YAAY,MAAM;AACxB,MAAM,YAAY,MAAM,KAAM;AAC9B,MAAM,YAAY,MAAM,KAAM;AAE9B,MAAM,kBAAkB,oBAAI,IAAoB;AAEhD,MAAM,mBAAmB,CAAC,OAAuB;AACtD,MAAI,MAAM;AACR,OAAG,IAAK;AAAA,EACV,OAAO;AACL,oBAAgB,IAAI,EAAE;AAAA,EACxB;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -5,12 +5,9 @@ const isAndroid = ((_a = Platform) == null ? void 0 : _a.OS) === "android";
|
|
|
5
5
|
const isIOS = ((_b = Platform) == null ? void 0 : _b.OS) === "ios";
|
|
6
6
|
const isWeb = process.env.TAMAGUI_TARGET === "web";
|
|
7
7
|
const isWindowDefined = typeof window !== "undefined";
|
|
8
|
-
const
|
|
8
|
+
const isSSR = isWeb && !isWindowDefined;
|
|
9
9
|
const isClient = isWeb && isWindowDefined;
|
|
10
|
-
const
|
|
11
|
-
const idFn = () => {
|
|
12
|
-
};
|
|
13
|
-
const useIsomorphicLayoutEffect = isRSC ? idFn : isServer ? useEffect : useLayoutEffect;
|
|
10
|
+
const useIsomorphicLayoutEffect = isSSR ? useEffect : useLayoutEffect;
|
|
14
11
|
const isChrome = typeof navigator !== "undefined" && /Chrome/.test(navigator.userAgent || "");
|
|
15
12
|
const isWebTouchable = isClient && "ontouchstart" in window;
|
|
16
13
|
const isTouchable = !isWeb || isWebTouchable;
|
|
@@ -19,8 +16,7 @@ export {
|
|
|
19
16
|
isChrome,
|
|
20
17
|
isClient,
|
|
21
18
|
isIOS,
|
|
22
|
-
|
|
23
|
-
isServer,
|
|
19
|
+
isSSR,
|
|
24
20
|
isTouchable,
|
|
25
21
|
isWeb,
|
|
26
22
|
isWebTouchable,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/constants/platform.ts"],
|
|
4
|
-
"sourcesContent": ["import { useEffect, useLayoutEffect } from 'react'\nimport { Platform } from 'react-native'\n\nexport const isAndroid = Platform?.OS === 'android'\nexport const isIOS = Platform?.OS === 'ios'\nexport const isWeb = process.env.TAMAGUI_TARGET === 'web'\nexport const isWindowDefined = typeof window !== 'undefined'\nexport const
|
|
5
|
-
"mappings": "AAAA;AAAA
|
|
4
|
+
"sourcesContent": ["import { useEffect, useLayoutEffect } from 'react'\nimport { Platform } from 'react-native'\n\nexport const isAndroid = Platform?.OS === 'android'\nexport const isIOS = Platform?.OS === 'ios'\nexport const isWeb = process.env.TAMAGUI_TARGET === 'web'\nexport const isWindowDefined = typeof window !== 'undefined'\nexport const isSSR = isWeb && !isWindowDefined\nexport const isClient = isWeb && isWindowDefined\nexport const useIsomorphicLayoutEffect = isSSR ? useEffect : useLayoutEffect\nexport const isChrome = typeof navigator !== 'undefined' && /Chrome/.test(navigator.userAgent || '')\nexport const isWebTouchable = isClient && 'ontouchstart' in window\nexport const isTouchable = !isWeb || isWebTouchable\n"],
|
|
5
|
+
"mappings": "AAAA;AAAA;AACA;AAEO,MAAM,YAAY,uCAAU,QAAO;AACnC,MAAM,QAAQ,uCAAU,QAAO;AAC/B,MAAM,QAAQ,QAAQ,IAAI,mBAAmB;AAC7C,MAAM,kBAAkB,OAAO,WAAW;AAC1C,MAAM,QAAQ,SAAS,CAAC;AACxB,MAAM,WAAW,SAAS;AAC1B,MAAM,4BAA4B,QAAQ,YAAY;AACtD,MAAM,WAAW,OAAO,cAAc,eAAe,SAAS,KAAK,UAAU,aAAa,EAAE;AAC5F,MAAM,iBAAiB,YAAY,kBAAkB;AACrD,MAAM,cAAc,CAAC,SAAS;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/contexts/ButtonInsideButtonContext.tsx"],
|
|
4
4
|
"sourcesContent": ["import { createContext } from 'react'\n\nexport const ButtonInsideButtonContext = createContext(false)\n"],
|
|
5
|
-
"mappings": "AAAA
|
|
5
|
+
"mappings": "AAAA;AAEO,MAAM,4BAA4B,cAAc,KAAK;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -43,7 +43,7 @@ import { useServerRef, useServerState } from "./hooks/useServerHooks";
|
|
|
43
43
|
import { getThemeIsNewTheme, getThemeManager, useTheme } from "./hooks/useTheme";
|
|
44
44
|
import { usePressability } from "./vendor/Pressability";
|
|
45
45
|
import { Slot, mergeEvent } from "./views/Slot";
|
|
46
|
-
import {
|
|
46
|
+
import { useThemeManagerContext } from "./views/Theme";
|
|
47
47
|
process.env.TAMAGUI_TARGET;
|
|
48
48
|
let defaultComponentState = null;
|
|
49
49
|
let defaultComponentStateMounted = null;
|
|
@@ -368,7 +368,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
368
368
|
viewProps.ref = useComposedRefs(hostRef, forwardedRef);
|
|
369
369
|
if (process.env.NODE_ENV === "development" && !isText && isWeb) {
|
|
370
370
|
Children.toArray(props.children).forEach((item) => {
|
|
371
|
-
if (typeof item === "string") {
|
|
371
|
+
if (typeof item === "string" && item !== "\n") {
|
|
372
372
|
console.error(
|
|
373
373
|
`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`
|
|
374
374
|
);
|
|
@@ -392,10 +392,16 @@ function createComponent(configIn, ParentComponent) {
|
|
|
392
392
|
useEffect(() => {
|
|
393
393
|
if (!shouldSetMounted)
|
|
394
394
|
return;
|
|
395
|
+
if (state.unmounted === true && needsMount) {
|
|
396
|
+
setStateShallow({
|
|
397
|
+
unmounted: false
|
|
398
|
+
});
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
395
401
|
setStateShallow({
|
|
396
402
|
unmounted: false
|
|
397
403
|
});
|
|
398
|
-
}, [shouldSetMounted]);
|
|
404
|
+
}, [shouldSetMounted, state.unmounted]);
|
|
399
405
|
let styles;
|
|
400
406
|
if (isStringElement && shouldAvoidClasses && !shouldForcePseudo) {
|
|
401
407
|
styles = {
|
|
@@ -416,6 +422,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
416
422
|
}
|
|
417
423
|
const fontFamilyClassName = fontFamily ? `font_${fontFamily}` : "";
|
|
418
424
|
const classList = [
|
|
425
|
+
hasEnterStyle && (state.unmounted && needsMount || !isClient) ? "t_will-mount" : "",
|
|
419
426
|
componentName ? componentClassName : "",
|
|
420
427
|
fontFamilyClassName,
|
|
421
428
|
themeIsNew ? theme.className : "",
|
|
@@ -556,7 +563,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
556
563
|
if (themeShouldReset) {
|
|
557
564
|
stateRef.current.themeShouldReset = true;
|
|
558
565
|
}
|
|
559
|
-
const
|
|
566
|
+
const innerContent = useThemeManagerContext(
|
|
560
567
|
spacedChildren({
|
|
561
568
|
separator,
|
|
562
569
|
children,
|
|
@@ -567,7 +574,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
567
574
|
stateRef.current.hasProvidedThemeManager ? themeManager : void 0,
|
|
568
575
|
stateRef.current.themeShouldReset
|
|
569
576
|
);
|
|
570
|
-
let content;
|
|
577
|
+
let content = !children || asChild ? children : innerContent;
|
|
571
578
|
if (asChild) {
|
|
572
579
|
elementType = Slot;
|
|
573
580
|
viewProps = {
|
|
@@ -596,7 +603,7 @@ function createComponent(configIn, ParentComponent) {
|
|
|
596
603
|
}
|
|
597
604
|
}
|
|
598
605
|
}
|
|
599
|
-
content = createElement(elementType, viewProps,
|
|
606
|
+
content = createElement(elementType, viewProps, content);
|
|
600
607
|
if (process.env.TAMAGUI_TARGET === "web") {
|
|
601
608
|
if (events || isAnimatedReactNativeWeb) {
|
|
602
609
|
content = /* @__PURE__ */ jsx("span", {
|
|
@@ -642,7 +649,6 @@ function createComponent(configIn, ParentComponent) {
|
|
|
642
649
|
styles,
|
|
643
650
|
pseudos,
|
|
644
651
|
content,
|
|
645
|
-
childEls,
|
|
646
652
|
shouldAvoidClasses,
|
|
647
653
|
avoidClasses: avoidClassesWhileAnimating,
|
|
648
654
|
animation: props.animation,
|
|
@@ -822,15 +828,9 @@ const Spacer = createComponent({
|
|
|
822
828
|
}
|
|
823
829
|
}
|
|
824
830
|
});
|
|
825
|
-
function spacedChildren({
|
|
826
|
-
|
|
827
|
-
children,
|
|
828
|
-
space,
|
|
829
|
-
direction,
|
|
830
|
-
spaceFlex,
|
|
831
|
-
separator
|
|
832
|
-
}) {
|
|
833
|
-
var _a;
|
|
831
|
+
function spacedChildren(props) {
|
|
832
|
+
var _a, _b, _c;
|
|
833
|
+
const { isZStack, children, space, direction, spaceFlex, separator } = props;
|
|
834
834
|
const hasSpace = !!(space || spaceFlex);
|
|
835
835
|
const hasSeparator = !(separator === void 0 || separator === null);
|
|
836
836
|
if (!(hasSpace || hasSeparator || isZStack)) {
|
|
@@ -838,22 +838,20 @@ function spacedChildren({
|
|
|
838
838
|
}
|
|
839
839
|
const childrenList = Children.toArray(children);
|
|
840
840
|
const len = childrenList.length;
|
|
841
|
-
if (len <= 1 && !isZStack) {
|
|
842
|
-
if (len === 1) {
|
|
843
|
-
const [onlyChild] = childrenList;
|
|
844
|
-
if (React.isValidElement(onlyChild) && ((_a = onlyChild.type) == null ? void 0 : _a["shouldForwardSpace"])) {
|
|
845
|
-
return React.cloneElement(onlyChild, {
|
|
846
|
-
space,
|
|
847
|
-
spaceFlex,
|
|
848
|
-
separator
|
|
849
|
-
});
|
|
850
|
-
}
|
|
851
|
-
}
|
|
841
|
+
if (len <= 1 && !isZStack && !((_b = (_a = childrenList[0]) == null ? void 0 : _a["type"]) == null ? void 0 : _b["shouldForwardSpace"])) {
|
|
852
842
|
return childrenList;
|
|
853
843
|
}
|
|
854
844
|
const final = [];
|
|
855
|
-
for (
|
|
845
|
+
for (let [index, child] of childrenList.entries()) {
|
|
856
846
|
const isEmpty = child === null || child === void 0 || Array.isArray(child) && child.length === 0;
|
|
847
|
+
if (!isEmpty && React.isValidElement(child) && ((_c = child.type) == null ? void 0 : _c["shouldForwardSpace"])) {
|
|
848
|
+
child = React.cloneElement(child, {
|
|
849
|
+
space,
|
|
850
|
+
spaceFlex,
|
|
851
|
+
separator,
|
|
852
|
+
key: child.key
|
|
853
|
+
});
|
|
854
|
+
}
|
|
857
855
|
if (isEmpty || !child || child["key"] && !isZStack) {
|
|
858
856
|
final.push(child);
|
|
859
857
|
} else {
|