@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
package/src/createComponent.tsx
CHANGED
|
@@ -20,7 +20,6 @@ import React, {
|
|
|
20
20
|
createElement,
|
|
21
21
|
forwardRef,
|
|
22
22
|
memo,
|
|
23
|
-
startTransition,
|
|
24
23
|
useCallback,
|
|
25
24
|
useContext,
|
|
26
25
|
useEffect,
|
|
@@ -61,7 +60,7 @@ import {
|
|
|
61
60
|
} from './types'
|
|
62
61
|
import { usePressability } from './vendor/Pressability'
|
|
63
62
|
import { Slot, mergeEvent } from './views/Slot'
|
|
64
|
-
import {
|
|
63
|
+
import { useThemeManagerContext } from './views/Theme'
|
|
65
64
|
|
|
66
65
|
// let t
|
|
67
66
|
// import { timer } from '@tamagui/timer'
|
|
@@ -558,7 +557,8 @@ export function createComponent<
|
|
|
558
557
|
|
|
559
558
|
if (process.env.NODE_ENV === 'development' && !isText && isWeb) {
|
|
560
559
|
Children.toArray(props.children).forEach((item) => {
|
|
561
|
-
|
|
560
|
+
// allow newlines because why not its annoying with mdx
|
|
561
|
+
if (typeof item === 'string' && item !== '\n') {
|
|
562
562
|
// eslint-disable-next-line no-console
|
|
563
563
|
console.error(
|
|
564
564
|
`Unexpected text node: ${item}. A text node cannot be a child of a <View>.`
|
|
@@ -585,10 +585,17 @@ export function createComponent<
|
|
|
585
585
|
const shouldSetMounted = needsMount && state.unmounted
|
|
586
586
|
useEffect(() => {
|
|
587
587
|
if (!shouldSetMounted) return
|
|
588
|
+
if (state.unmounted === true && needsMount) {
|
|
589
|
+
setStateShallow({
|
|
590
|
+
unmounted: false,
|
|
591
|
+
})
|
|
592
|
+
return
|
|
593
|
+
}
|
|
594
|
+
|
|
588
595
|
setStateShallow({
|
|
589
596
|
unmounted: false,
|
|
590
597
|
})
|
|
591
|
-
}, [shouldSetMounted])
|
|
598
|
+
}, [shouldSetMounted, state.unmounted])
|
|
592
599
|
|
|
593
600
|
let styles: Record<string, any>[]
|
|
594
601
|
|
|
@@ -618,11 +625,15 @@ export function createComponent<
|
|
|
618
625
|
const fontFamilyClassName = fontFamily ? `font_${fontFamily}` : ''
|
|
619
626
|
|
|
620
627
|
const classList = [
|
|
628
|
+
hasEnterStyle && ((state.unmounted && needsMount) || !isClient)
|
|
629
|
+
? 't_will-mount'
|
|
630
|
+
: '',
|
|
621
631
|
componentName ? componentClassName : '',
|
|
622
632
|
fontFamilyClassName,
|
|
623
633
|
themeIsNew ? theme.className : '',
|
|
624
634
|
classNames ? Object.values(classNames).join(' ') : '',
|
|
625
635
|
]
|
|
636
|
+
|
|
626
637
|
const className = classList.join(' ')
|
|
627
638
|
|
|
628
639
|
if (process.env.TAMAGUI_TARGET === 'web') {
|
|
@@ -811,23 +822,20 @@ export function createComponent<
|
|
|
811
822
|
stateRef.current.themeShouldReset = true
|
|
812
823
|
}
|
|
813
824
|
|
|
814
|
-
const
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
stateRef.current.hasProvidedThemeManager ? themeManager : undefined,
|
|
827
|
-
stateRef.current.themeShouldReset
|
|
828
|
-
)
|
|
825
|
+
const innerContent = useThemeManagerContext(
|
|
826
|
+
spacedChildren({
|
|
827
|
+
separator,
|
|
828
|
+
children,
|
|
829
|
+
space,
|
|
830
|
+
direction: props.spaceDirection || 'both',
|
|
831
|
+
isZStack,
|
|
832
|
+
}),
|
|
833
|
+
// only set context if changed theme
|
|
834
|
+
stateRef.current.hasProvidedThemeManager ? themeManager : undefined,
|
|
835
|
+
stateRef.current.themeShouldReset
|
|
836
|
+
)
|
|
829
837
|
|
|
830
|
-
let content:
|
|
838
|
+
let content = !children || asChild ? children : innerContent
|
|
831
839
|
|
|
832
840
|
if (asChild) {
|
|
833
841
|
elementType = Slot
|
|
@@ -865,7 +873,7 @@ export function createComponent<
|
|
|
865
873
|
}
|
|
866
874
|
}
|
|
867
875
|
|
|
868
|
-
content = createElement(elementType, viewProps,
|
|
876
|
+
content = createElement(elementType, viewProps, content)
|
|
869
877
|
|
|
870
878
|
if (process.env.TAMAGUI_TARGET === 'web') {
|
|
871
879
|
if (events || isAnimatedReactNativeWeb) {
|
|
@@ -921,7 +929,6 @@ export function createComponent<
|
|
|
921
929
|
styles,
|
|
922
930
|
pseudos,
|
|
923
931
|
content,
|
|
924
|
-
childEls,
|
|
925
932
|
shouldAvoidClasses,
|
|
926
933
|
avoidClasses: avoidClassesWhileAnimating,
|
|
927
934
|
animation: props.animation,
|
|
@@ -1162,41 +1169,38 @@ export type SpacedChildrenProps = {
|
|
|
1162
1169
|
separator?: React.ReactNode
|
|
1163
1170
|
}
|
|
1164
1171
|
|
|
1165
|
-
export function spacedChildren({
|
|
1166
|
-
isZStack,
|
|
1167
|
-
children,
|
|
1168
|
-
space,
|
|
1169
|
-
direction,
|
|
1170
|
-
spaceFlex,
|
|
1171
|
-
separator,
|
|
1172
|
-
}: SpacedChildrenProps) {
|
|
1172
|
+
export function spacedChildren(props: SpacedChildrenProps) {
|
|
1173
|
+
const { isZStack, children, space, direction, spaceFlex, separator } = props
|
|
1173
1174
|
const hasSpace = !!(space || spaceFlex)
|
|
1174
1175
|
const hasSeparator = !(separator === undefined || separator === null)
|
|
1175
1176
|
if (!(hasSpace || hasSeparator || isZStack)) {
|
|
1176
1177
|
return children
|
|
1177
1178
|
}
|
|
1179
|
+
|
|
1178
1180
|
const childrenList = Children.toArray(children)
|
|
1181
|
+
|
|
1179
1182
|
const len = childrenList.length
|
|
1180
|
-
if (len <= 1 && !isZStack) {
|
|
1181
|
-
if (len === 1) {
|
|
1182
|
-
// forward space! only when one component doesn't make sense to forward space to all children
|
|
1183
|
-
const [onlyChild] = childrenList
|
|
1184
|
-
if (React.isValidElement(onlyChild) && onlyChild.type?.['shouldForwardSpace']) {
|
|
1185
|
-
return React.cloneElement(onlyChild, {
|
|
1186
|
-
space,
|
|
1187
|
-
spaceFlex,
|
|
1188
|
-
separator,
|
|
1189
|
-
} as any)
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1183
|
+
if (len <= 1 && !isZStack && !childrenList[0]?.['type']?.['shouldForwardSpace']) {
|
|
1192
1184
|
return childrenList
|
|
1193
1185
|
}
|
|
1186
|
+
|
|
1194
1187
|
const final: React.ReactNode[] = []
|
|
1195
|
-
for (
|
|
1188
|
+
for (let [index, child] of childrenList.entries()) {
|
|
1196
1189
|
const isEmpty =
|
|
1197
1190
|
child === null ||
|
|
1198
1191
|
child === undefined ||
|
|
1199
1192
|
(Array.isArray(child) && child.length === 0)
|
|
1193
|
+
|
|
1194
|
+
// forward space
|
|
1195
|
+
if (!isEmpty && React.isValidElement(child) && child.type?.['shouldForwardSpace']) {
|
|
1196
|
+
child = React.cloneElement(child, {
|
|
1197
|
+
space,
|
|
1198
|
+
spaceFlex,
|
|
1199
|
+
separator,
|
|
1200
|
+
key: child.key,
|
|
1201
|
+
} as any)
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1200
1204
|
// push them all, but wrap some in Fragment
|
|
1201
1205
|
if (isEmpty || !child || (child['key'] && !isZStack)) {
|
|
1202
1206
|
final.push(child)
|
package/src/createTamagui.ts
CHANGED
|
@@ -3,7 +3,11 @@ import { isRSC, isWeb } from '@tamagui/constants'
|
|
|
3
3
|
import { configListeners, setConfig } from './config'
|
|
4
4
|
import { createVariables } from './createVariables'
|
|
5
5
|
import { getThemeCSSRules } from './helpers/getThemeCSSRules'
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
getAllRules,
|
|
8
|
+
listenForSheetChanges,
|
|
9
|
+
scanAllSheets,
|
|
10
|
+
} from './helpers/insertStyleRule'
|
|
7
11
|
import {
|
|
8
12
|
registerCSSVariable,
|
|
9
13
|
tokensValueToVariable,
|
|
@@ -42,6 +46,9 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
|
|
|
42
46
|
}
|
|
43
47
|
}
|
|
44
48
|
|
|
49
|
+
scanAllSheets()
|
|
50
|
+
listenForSheetChanges()
|
|
51
|
+
|
|
45
52
|
const fontTokens = Object.fromEntries(
|
|
46
53
|
Object.entries(configIn.fonts!).map(([k, v]) => {
|
|
47
54
|
return [k, createVariables(v, 'f', true)]
|
|
@@ -205,7 +212,8 @@ export function createTamagui<Conf extends CreateTamaguiProps>(
|
|
|
205
212
|
tokensParsed,
|
|
206
213
|
parsed: true,
|
|
207
214
|
getCSS: (separator = '\n') => {
|
|
208
|
-
return `.
|
|
215
|
+
return `.t_unmounted .t_will-mount {opacity:0;visibility:hidden;}
|
|
216
|
+
.is_Text .is_Text {display:inline-flex;}
|
|
209
217
|
._dsp_contents {display:contents;}
|
|
210
218
|
${themeConfig.cssRuleSets.join(separator)}
|
|
211
219
|
${themeConfig.themeRuleSets.join(separator)}
|
|
@@ -42,6 +42,10 @@ export class ThemeManager {
|
|
|
42
42
|
if (!parentManager) {
|
|
43
43
|
throw new Error('Must set up root first')
|
|
44
44
|
}
|
|
45
|
+
|
|
46
|
+
// copy over listeners
|
|
47
|
+
this.themeListeners = parentManager.themeListeners
|
|
48
|
+
|
|
45
49
|
// no change no props
|
|
46
50
|
if (hasNoThemeUpdatingProps(props)) {
|
|
47
51
|
return parentManager
|
|
@@ -101,9 +105,9 @@ export class ThemeManager {
|
|
|
101
105
|
state: ThemeManagerState | null = this.state
|
|
102
106
|
) {
|
|
103
107
|
if (!nextState?.theme || nextState.theme === state?.theme) {
|
|
104
|
-
return
|
|
108
|
+
return false
|
|
105
109
|
}
|
|
106
|
-
return
|
|
110
|
+
return true
|
|
107
111
|
}
|
|
108
112
|
|
|
109
113
|
getState(props = this.props, parentManager = this.parentManager) {
|
|
@@ -136,6 +140,7 @@ export class ThemeManager {
|
|
|
136
140
|
}
|
|
137
141
|
|
|
138
142
|
notify() {
|
|
143
|
+
console.log('notify', this.themeListeners.size, this.themeListeners)
|
|
139
144
|
this.themeListeners.forEach((cb) => cb(this.state.name, this))
|
|
140
145
|
}
|
|
141
146
|
|
package/src/helpers/cache.ts
CHANGED
|
@@ -2,17 +2,15 @@ type Value = Object | Array<any> | string | number
|
|
|
2
2
|
|
|
3
3
|
export type Style = { [key: string]: Value }
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
v: Record<string, any> = {}
|
|
5
|
+
const v: Record<string, any> = {}
|
|
7
6
|
|
|
7
|
+
export const cache = {
|
|
8
8
|
get(key: string, valStr: string) {
|
|
9
|
-
return
|
|
10
|
-
}
|
|
9
|
+
return v[key]?.[valStr]
|
|
10
|
+
},
|
|
11
11
|
|
|
12
12
|
set(key: string, valStr: string, object: any) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
13
|
+
v[key] ??= {}
|
|
14
|
+
v[key][valStr] = object
|
|
15
|
+
},
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
export const cache = new Cache()
|
|
@@ -30,25 +30,16 @@ export function expandStyle(key: string, value: any) {
|
|
|
30
30
|
|
|
31
31
|
// web only
|
|
32
32
|
switch (key) {
|
|
33
|
-
case 'aspectRatio': {
|
|
34
|
-
return [[key, value.toString()]]
|
|
35
|
-
}
|
|
36
|
-
|
|
37
33
|
case 'textAlignVertical': {
|
|
38
34
|
return [['verticalAlign', value === 'center' ? 'middle' : value]]
|
|
39
35
|
}
|
|
40
|
-
|
|
41
|
-
case 'textDecorationLine': {
|
|
42
|
-
return [['textDecorationLine', value]]
|
|
43
|
-
}
|
|
44
|
-
|
|
45
36
|
case 'writingDirection': {
|
|
46
37
|
return [['direction', value]]
|
|
47
38
|
}
|
|
48
39
|
}
|
|
49
40
|
}
|
|
50
41
|
|
|
51
|
-
const longKey =
|
|
42
|
+
const longKey = EXPANSIONS[key]
|
|
52
43
|
if (longKey) {
|
|
53
44
|
return longKey.map((key) => {
|
|
54
45
|
return [key, value]
|
|
@@ -56,41 +47,36 @@ export function expandStyle(key: string, value: any) {
|
|
|
56
47
|
}
|
|
57
48
|
}
|
|
58
49
|
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
],
|
|
50
|
+
const all = ['Top', 'Right', 'Bottom', 'Left']
|
|
51
|
+
const horiz = ['Right', 'Left']
|
|
52
|
+
const vert = ['Top', 'Bottom']
|
|
53
|
+
const xy = ['X', 'Y']
|
|
54
|
+
|
|
55
|
+
const EXPANSIONS: Record<string, string[]> = {
|
|
56
|
+
borderColor: ['TopColor', 'RightColor', 'BottomColor', 'LeftColor'],
|
|
66
57
|
borderRadius: [
|
|
67
|
-
'
|
|
68
|
-
'
|
|
69
|
-
'
|
|
70
|
-
'
|
|
71
|
-
],
|
|
72
|
-
borderWidth: [
|
|
73
|
-
'borderTopWidth',
|
|
74
|
-
'borderRightWidth',
|
|
75
|
-
'borderBottomWidth',
|
|
76
|
-
'borderLeftWidth',
|
|
58
|
+
'TopLeftRadius',
|
|
59
|
+
'TopRightRadius',
|
|
60
|
+
'BottomRightRadius',
|
|
61
|
+
'BottomLeftRadius',
|
|
77
62
|
],
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
63
|
+
borderWidth: ['TopWidth', 'RightWidth', 'BottomWidth', 'LeftWidth'],
|
|
64
|
+
margin: all,
|
|
65
|
+
marginHorizontal: horiz,
|
|
66
|
+
marginVertical: vert,
|
|
67
|
+
overscrollBehavior: xy,
|
|
68
|
+
padding: all,
|
|
69
|
+
paddingHorizontal: horiz,
|
|
70
|
+
paddingVertical: vert,
|
|
85
71
|
...(isWeb && {
|
|
86
72
|
// react-native only supports borderStyle
|
|
87
|
-
borderStyle: [
|
|
88
|
-
'borderTopStyle',
|
|
89
|
-
'borderRightStyle',
|
|
90
|
-
'borderBottomStyle',
|
|
91
|
-
'borderLeftStyle',
|
|
92
|
-
],
|
|
73
|
+
borderStyle: ['TopStyle', 'RightStyle', 'BottomStyle', 'LeftStyle'],
|
|
93
74
|
// react-native doesn't support X / Y
|
|
94
|
-
overflow:
|
|
75
|
+
overflow: xy,
|
|
95
76
|
}),
|
|
96
77
|
}
|
|
78
|
+
|
|
79
|
+
for (const parent in EXPANSIONS) {
|
|
80
|
+
const prefix = parent.slice(0, /[A-Z]/.exec(parent)?.index ?? parent.length)
|
|
81
|
+
EXPANSIONS[parent] = EXPANSIONS[parent].map((k) => `${prefix}${k}`)
|
|
82
|
+
}
|
|
@@ -20,6 +20,7 @@ import { isDevTools } from '../constants/isDevTools'
|
|
|
20
20
|
import {
|
|
21
21
|
getMediaImportanceIfMoreImportant,
|
|
22
22
|
mediaState as globalMediaState,
|
|
23
|
+
mediaKeysWithAndWithout$,
|
|
23
24
|
mediaQueryConfig,
|
|
24
25
|
mergeMediaByImportance,
|
|
25
26
|
} from '../hooks/useMedia'
|
|
@@ -45,8 +46,8 @@ import {
|
|
|
45
46
|
RulesToInsert,
|
|
46
47
|
insertStyleRules,
|
|
47
48
|
insertedTransforms,
|
|
49
|
+
scanAllSheets,
|
|
48
50
|
shouldInsertStyleRules,
|
|
49
|
-
updateInserted,
|
|
50
51
|
updateRules,
|
|
51
52
|
} from './insertStyleRule'
|
|
52
53
|
import { FlatTransforms, mergeTransform, mergeTransforms } from './mergeTransform'
|
|
@@ -205,7 +206,7 @@ const accessibilityRoleToWebRole = {
|
|
|
205
206
|
// const classNames = {}
|
|
206
207
|
|
|
207
208
|
const isMediaKey = (key: string) =>
|
|
208
|
-
Boolean(key[0] === '$' &&
|
|
209
|
+
Boolean(key[0] === '$' && mediaKeysWithAndWithout$.has(key))
|
|
209
210
|
|
|
210
211
|
export const getSplitStyles: StyleSplitter = (
|
|
211
212
|
props,
|
|
@@ -217,6 +218,10 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
217
218
|
elementType,
|
|
218
219
|
debug
|
|
219
220
|
) => {
|
|
221
|
+
if (cache.has(props)) {
|
|
222
|
+
return cache.get(props)
|
|
223
|
+
}
|
|
224
|
+
|
|
220
225
|
conf = conf || getConfig()
|
|
221
226
|
const { shorthands } = conf
|
|
222
227
|
const {
|
|
@@ -320,8 +325,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
320
325
|
const valInit = props[keyInit]
|
|
321
326
|
|
|
322
327
|
// normalize shorthands up front
|
|
323
|
-
|
|
324
|
-
if (expandedKey) {
|
|
328
|
+
if (keyInit in shorthands) {
|
|
325
329
|
keyInit = shorthands[keyInit]
|
|
326
330
|
}
|
|
327
331
|
|
|
@@ -329,8 +333,8 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
329
333
|
if (keyInit in skipProps) continue
|
|
330
334
|
if (!isWeb && keyInit.startsWith('data-')) continue
|
|
331
335
|
|
|
332
|
-
if (
|
|
333
|
-
if (
|
|
336
|
+
if (typeof valInit === 'string' && valInit[0] === '_') {
|
|
337
|
+
if (keyInit in validStyleProps || keyInit.includes('-')) {
|
|
334
338
|
if (shouldDoClasses) {
|
|
335
339
|
classNames[keyInit] = valInit
|
|
336
340
|
} else {
|
|
@@ -425,20 +429,12 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
425
429
|
}
|
|
426
430
|
break
|
|
427
431
|
}
|
|
428
|
-
case '
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
+
case 'accessibilityLabelledBy':
|
|
433
|
+
case 'accessibilityFlowTo':
|
|
434
|
+
case 'accessibilityControls':
|
|
432
435
|
case 'accessibilityDescribedBy': {
|
|
433
|
-
viewProps[
|
|
434
|
-
|
|
435
|
-
}
|
|
436
|
-
case 'accessibilityFlowTo': {
|
|
437
|
-
viewProps['aria-flowto'] = processIDRefList(valInit)
|
|
438
|
-
break
|
|
439
|
-
}
|
|
440
|
-
case 'accessibilityLabelledBy': {
|
|
441
|
-
viewProps['aria-labelledby'] = processIDRefList(valInit)
|
|
436
|
+
viewProps[`aria-${keyInit.replace('accessibility', '').toLowerCase()}`] =
|
|
437
|
+
processIDRefList(valInit)
|
|
442
438
|
break
|
|
443
439
|
}
|
|
444
440
|
case 'accessibilityKeyShortcuts': {
|
|
@@ -538,7 +534,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
538
534
|
)
|
|
539
535
|
) {
|
|
540
536
|
// web-only, exclude all other accessibility props not handled above
|
|
541
|
-
if (isWeb && keyInit.
|
|
537
|
+
if (isWeb && keyInit.indexOf('ccessibility') > 0) {
|
|
542
538
|
continue
|
|
543
539
|
}
|
|
544
540
|
usedKeys[keyInit] = 1
|
|
@@ -642,7 +638,24 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
642
638
|
}
|
|
643
639
|
}
|
|
644
640
|
} else {
|
|
645
|
-
|
|
641
|
+
let isDisabled = !state[descriptor.stateKey || descriptor.name]
|
|
642
|
+
|
|
643
|
+
// we never animate in on server side just show the full thing
|
|
644
|
+
// on client side we use CSS to hide the fully in SSR items, then
|
|
645
|
+
// un-hide and replay with original animation.
|
|
646
|
+
if (!isClient && isEnter) {
|
|
647
|
+
isDisabled = false
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// console.log(
|
|
651
|
+
// 'isDisabled',
|
|
652
|
+
// state,
|
|
653
|
+
// descriptor.stateKey,
|
|
654
|
+
// state[descriptor.stateKey || descriptor.name],
|
|
655
|
+
// isDisabled,
|
|
656
|
+
// descriptor
|
|
657
|
+
// )
|
|
658
|
+
|
|
646
659
|
if (!isDisabled) {
|
|
647
660
|
usedKeys[key] ||= 1
|
|
648
661
|
}
|
|
@@ -766,7 +779,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
766
779
|
fontFamily = valInit[0] === '$' ? valInit : val
|
|
767
780
|
}
|
|
768
781
|
|
|
769
|
-
if (validStyleProps
|
|
782
|
+
if (key in validStyleProps) {
|
|
770
783
|
mergeStyle(styleState, key, val)
|
|
771
784
|
continue
|
|
772
785
|
}
|
|
@@ -887,6 +900,7 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
887
900
|
rulesToInsert,
|
|
888
901
|
parentSplitStyles,
|
|
889
902
|
flatTransforms,
|
|
903
|
+
result,
|
|
890
904
|
}
|
|
891
905
|
for (const key in { ...result, ...logs }) {
|
|
892
906
|
// eslint-disable-next-line no-console
|
|
@@ -897,6 +911,8 @@ export const getSplitStyles: StyleSplitter = (
|
|
|
897
911
|
}
|
|
898
912
|
}
|
|
899
913
|
|
|
914
|
+
cache.set(props, result)
|
|
915
|
+
|
|
900
916
|
return result
|
|
901
917
|
}
|
|
902
918
|
|
|
@@ -916,7 +932,8 @@ function mergeClassName(
|
|
|
916
932
|
if (isClient) {
|
|
917
933
|
if (!transform) {
|
|
918
934
|
// HMR or loaded a new chunk
|
|
919
|
-
|
|
935
|
+
console.warn(`got a new ting`)
|
|
936
|
+
scanAllSheets()
|
|
920
937
|
transform = insertedTransforms[val]
|
|
921
938
|
if (process.env.NODE_ENV === 'development') {
|
|
922
939
|
if (!transform) {
|
|
@@ -82,7 +82,21 @@ const generateAtomicStyles = (
|
|
|
82
82
|
|
|
83
83
|
// transform
|
|
84
84
|
if (style.transform && Array.isArray(style.transform)) {
|
|
85
|
-
style.transform = style.transform
|
|
85
|
+
style.transform = style.transform
|
|
86
|
+
.map(
|
|
87
|
+
// { scale: 2 } => 'scale(2)'
|
|
88
|
+
// { translateX: 20 } => 'translateX(20px)'
|
|
89
|
+
// { matrix: [1,2,3,4,5,6] } => 'matrix(1,2,3,4,5,6)'
|
|
90
|
+
(transform) => {
|
|
91
|
+
const type = Object.keys(transform)[0]
|
|
92
|
+
const value = transform[type]
|
|
93
|
+
if (type === 'matrix' || type === 'matrix3d') {
|
|
94
|
+
return `${type}(${value.join(',')})`
|
|
95
|
+
}
|
|
96
|
+
return `${type}(${normalizeValueWithProperty(value, type)})`
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
.join(' ')
|
|
86
100
|
}
|
|
87
101
|
|
|
88
102
|
styleToCSS(style)
|
|
@@ -160,20 +174,6 @@ export function styleToCSS(style: Record<string, any>) {
|
|
|
160
174
|
}
|
|
161
175
|
}
|
|
162
176
|
|
|
163
|
-
// { scale: 2 } => 'scale(2)'
|
|
164
|
-
// { translateX: 20 } => 'translateX(20px)'
|
|
165
|
-
// { matrix: [1,2,3,4,5,6] } => 'matrix(1,2,3,4,5,6)'
|
|
166
|
-
const mapTransform = (transform) => {
|
|
167
|
-
const type = Object.keys(transform)[0]
|
|
168
|
-
const value = transform[type]
|
|
169
|
-
if (type === 'matrix' || type === 'matrix3d') {
|
|
170
|
-
return `${type}(${value.join(',')})`
|
|
171
|
-
} else {
|
|
172
|
-
const normalizedValue = normalizeValueWithProperty(value, type)
|
|
173
|
-
return `${type}(${normalizedValue})`
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
177
|
function createDeclarationBlock(style: Style, important = false) {
|
|
178
178
|
let next = ''
|
|
179
179
|
for (const key in style) {
|