react-native-unistyles 3.0.0-beta.1 → 3.0.0-beta.3
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/README.md +4 -4
- package/Unistyles.podspec +7 -1
- package/android/build.gradle +6 -0
- package/android/src/main/cxx/NativeUnistylesModule.cpp +2 -2
- package/components/native/ActivityIndicator/package.json +4 -0
- package/components/native/FlatList/package.json +4 -0
- package/components/native/Image/package.json +4 -0
- package/components/native/ImageBackground/package.json +4 -0
- package/components/native/KeyboardAvoidingView/package.json +4 -0
- package/components/native/Pressable/package.json +5 -0
- package/components/native/RefreshControl/package.json +4 -0
- package/components/native/ScrollView/package.json +4 -0
- package/components/native/SectionList/package.json +4 -0
- package/components/native/Switch/package.json +4 -0
- package/components/native/Text/package.json +4 -0
- package/components/native/TextInput/package.json +4 -0
- package/components/native/TouchableHighlight/package.json +4 -0
- package/components/native/TouchableOpacity/package.json +4 -0
- package/components/native/View/package.json +4 -0
- package/components/native/VirtualizedList/package.json +4 -0
- package/cxx/common/Constants.h +2 -0
- package/cxx/core/HostStyle.cpp +17 -7
- package/cxx/core/HostStyle.h +5 -0
- package/cxx/core/UnistyleData.h +3 -3
- package/cxx/core/UnistyleWrapper.h +9 -9
- package/cxx/core/UnistylesRegistry.cpp +23 -30
- package/cxx/core/UnistylesRegistry.h +8 -2
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +117 -12
- package/cxx/hybridObjects/HybridShadowRegistry.h +27 -3
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +4 -0
- package/cxx/parser/Parser.cpp +184 -26
- package/cxx/parser/Parser.h +3 -1
- package/ios/UnistylesModuleOnLoad.mm +2 -2
- package/lib/commonjs/components/ScopedTheme.js +36 -0
- package/lib/commonjs/components/ScopedTheme.js.map +1 -0
- package/lib/commonjs/components/Variants.js +36 -0
- package/lib/commonjs/components/Variants.js.map +1 -0
- package/lib/commonjs/components/index.js +10 -3
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/components/native/ActivityIndicator.js +10 -0
- package/lib/commonjs/components/native/ActivityIndicator.js.map +1 -0
- package/lib/commonjs/components/native/FlatList.js +10 -0
- package/lib/commonjs/components/native/FlatList.js.map +1 -0
- package/lib/commonjs/components/native/Image.js +10 -0
- package/lib/commonjs/components/native/Image.js.map +1 -0
- package/lib/commonjs/components/native/ImageBackground.js +10 -0
- package/lib/commonjs/components/native/ImageBackground.js.map +1 -0
- package/lib/commonjs/components/native/KeyboardAvoidingView.js +10 -0
- package/lib/commonjs/components/native/KeyboardAvoidingView.js.map +1 -0
- package/lib/commonjs/components/{Pressable.web.js → native/Pressable.js} +26 -66
- package/lib/commonjs/components/native/Pressable.js.map +1 -0
- package/lib/commonjs/components/native/Pressable.native.js +51 -0
- package/lib/commonjs/components/native/Pressable.native.js.map +1 -0
- package/lib/commonjs/components/native/RefreshControl.js +10 -0
- package/lib/commonjs/components/native/RefreshControl.js.map +1 -0
- package/lib/commonjs/components/native/ScrollView.js +10 -0
- package/lib/commonjs/components/native/ScrollView.js.map +1 -0
- package/lib/commonjs/components/native/SectionList.js +10 -0
- package/lib/commonjs/components/native/SectionList.js.map +1 -0
- package/lib/commonjs/components/native/Switch.js +10 -0
- package/lib/commonjs/components/native/Switch.js.map +1 -0
- package/lib/commonjs/components/native/Text.js +10 -0
- package/lib/commonjs/components/native/Text.js.map +1 -0
- package/lib/commonjs/components/native/TextInput.js +10 -0
- package/lib/commonjs/components/native/TextInput.js.map +1 -0
- package/lib/commonjs/components/native/TouchableHighlight.js +10 -0
- package/lib/commonjs/components/native/TouchableHighlight.js.map +1 -0
- package/lib/commonjs/components/native/TouchableOpacity.js +10 -0
- package/lib/commonjs/components/native/TouchableOpacity.js.map +1 -0
- package/lib/commonjs/components/native/View.js +10 -0
- package/lib/commonjs/components/native/View.js.map +1 -0
- package/lib/commonjs/components/native/VirtualizedList.js +10 -0
- package/lib/commonjs/components/native/VirtualizedList.js.map +1 -0
- package/lib/commonjs/core/createUnistylesComponent.js +5 -68
- package/lib/commonjs/core/createUnistylesComponent.js.map +1 -1
- package/lib/commonjs/core/createUnistylesElement.js +16 -0
- package/lib/commonjs/core/createUnistylesElement.js.map +1 -0
- package/lib/commonjs/core/createUnistylesImageBackground.js +27 -0
- package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -0
- package/lib/commonjs/core/index.js +20 -6
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/core/passForwardRef.js +27 -0
- package/lib/commonjs/core/passForwardRef.js.map +1 -0
- package/lib/commonjs/core/withUnistyles/index.js +13 -0
- package/lib/commonjs/core/withUnistyles/index.js.map +1 -0
- package/lib/commonjs/core/withUnistyles/types.js +8 -0
- package/lib/commonjs/core/withUnistyles/types.js.map +1 -0
- package/lib/commonjs/core/withUnistyles/useDependencies.js +85 -0
- package/lib/commonjs/core/withUnistyles/useDependencies.js.map +1 -0
- package/lib/commonjs/core/withUnistyles/withUnistyles.js +88 -0
- package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -0
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +97 -0
- package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -0
- package/lib/commonjs/hooks/useMedia.js +17 -33
- package/lib/commonjs/hooks/useMedia.js.map +1 -1
- package/lib/commonjs/hooks/useMedia.native.js +60 -0
- package/lib/commonjs/hooks/useMedia.native.js.map +1 -0
- package/lib/commonjs/index.js +52 -31
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +3 -3
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/index.js +14 -40
- package/lib/commonjs/specs/index.js.map +1 -1
- package/lib/commonjs/specs/index.native.js +54 -0
- package/lib/commonjs/specs/index.native.js.map +1 -0
- package/lib/commonjs/web/create.js +9 -33
- package/lib/commonjs/web/create.js.map +1 -1
- package/lib/commonjs/web/index.js +15 -16
- package/lib/commonjs/web/index.js.map +1 -1
- package/lib/commonjs/web/registry.js +10 -3
- package/lib/commonjs/web/registry.js.map +1 -1
- package/lib/commonjs/web/runtime.js +3 -1
- package/lib/commonjs/web/runtime.js.map +1 -1
- package/lib/commonjs/web/shadowRegistry.js +66 -64
- package/lib/commonjs/web/shadowRegistry.js.map +1 -1
- package/lib/commonjs/web/utils/unistyle.js +4 -4
- package/lib/commonjs/web/utils/unistyle.js.map +1 -1
- package/lib/module/components/ScopedTheme.js +29 -0
- package/lib/module/components/ScopedTheme.js.map +1 -0
- package/lib/module/components/Variants.js +29 -0
- package/lib/module/components/Variants.js.map +1 -0
- package/lib/module/components/index.js +2 -1
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/components/native/ActivityIndicator.js +6 -0
- package/lib/module/components/native/ActivityIndicator.js.map +1 -0
- package/lib/module/components/native/FlatList.js +6 -0
- package/lib/module/components/native/FlatList.js.map +1 -0
- package/lib/module/components/native/Image.js +6 -0
- package/lib/module/components/native/Image.js.map +1 -0
- package/lib/module/components/native/ImageBackground.js +6 -0
- package/lib/module/components/native/ImageBackground.js.map +1 -0
- package/lib/module/components/native/KeyboardAvoidingView.js +6 -0
- package/lib/module/components/native/KeyboardAvoidingView.js.map +1 -0
- package/lib/module/components/native/Pressable.js +69 -0
- package/lib/module/components/native/Pressable.js.map +1 -0
- package/lib/module/components/native/Pressable.native.js +45 -0
- package/lib/module/components/native/Pressable.native.js.map +1 -0
- package/lib/module/components/native/RefreshControl.js +6 -0
- package/lib/module/components/native/RefreshControl.js.map +1 -0
- package/lib/module/components/native/ScrollView.js +6 -0
- package/lib/module/components/native/ScrollView.js.map +1 -0
- package/lib/module/components/native/SectionList.js +6 -0
- package/lib/module/components/native/SectionList.js.map +1 -0
- package/lib/module/components/native/Switch.js +6 -0
- package/lib/module/components/native/Switch.js.map +1 -0
- package/lib/module/components/native/Text.js +6 -0
- package/lib/module/components/native/Text.js.map +1 -0
- package/lib/module/components/native/TextInput.js +6 -0
- package/lib/module/components/native/TextInput.js.map +1 -0
- package/lib/module/components/native/TouchableHighlight.js +6 -0
- package/lib/module/components/native/TouchableHighlight.js.map +1 -0
- package/lib/module/components/native/TouchableOpacity.js +6 -0
- package/lib/module/components/native/TouchableOpacity.js.map +1 -0
- package/lib/module/components/native/View.js +6 -0
- package/lib/module/components/native/View.js.map +1 -0
- package/lib/module/components/native/VirtualizedList.js +6 -0
- package/lib/module/components/native/VirtualizedList.js.map +1 -0
- package/lib/module/core/createUnistylesComponent.js +5 -66
- package/lib/module/core/createUnistylesComponent.js.map +1 -1
- package/lib/module/core/createUnistylesElement.js +10 -0
- package/lib/module/core/createUnistylesElement.js.map +1 -0
- package/lib/module/core/createUnistylesImageBackground.js +21 -0
- package/lib/module/core/createUnistylesImageBackground.js.map +1 -0
- package/lib/module/core/index.js +4 -2
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/core/passForwardRef.js +22 -0
- package/lib/module/core/passForwardRef.js.map +1 -0
- package/lib/module/core/withUnistyles/index.js +4 -0
- package/lib/module/core/withUnistyles/index.js.map +1 -0
- package/lib/module/core/withUnistyles/types.js +4 -0
- package/lib/module/core/withUnistyles/types.js.map +1 -0
- package/lib/module/core/withUnistyles/useDependencies.js +79 -0
- package/lib/module/core/withUnistyles/useDependencies.js.map +1 -0
- package/lib/module/core/withUnistyles/withUnistyles.js +81 -0
- package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -0
- package/lib/module/core/withUnistyles/withUnistyles.native.js +90 -0
- package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -0
- package/lib/module/hooks/useMedia.js +19 -35
- package/lib/module/hooks/useMedia.js.map +1 -1
- package/lib/module/hooks/useMedia.native.js +55 -0
- package/lib/module/hooks/useMedia.native.js.map +1 -0
- package/lib/module/index.js +3 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +3 -3
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/index.js +2 -8
- package/lib/module/specs/index.js.map +1 -1
- package/lib/module/specs/index.native.js +11 -0
- package/lib/module/specs/index.native.js.map +1 -0
- package/lib/module/web/create.js +10 -34
- package/lib/module/web/create.js.map +1 -1
- package/lib/module/web/index.js +4 -3
- package/lib/module/web/index.js.map +1 -1
- package/lib/module/web/registry.js +11 -4
- package/lib/module/web/registry.js.map +1 -1
- package/lib/module/web/runtime.js +3 -1
- package/lib/module/web/runtime.js.map +1 -1
- package/lib/module/web/shadowRegistry.js +64 -62
- package/lib/module/web/shadowRegistry.js.map +1 -1
- package/lib/module/web/utils/unistyle.js +2 -2
- package/lib/module/web/utils/unistyle.js.map +1 -1
- package/lib/typescript/src/components/ScopedTheme.d.ts +8 -0
- package/lib/typescript/src/components/ScopedTheme.d.ts.map +1 -0
- package/lib/typescript/src/components/Variants.d.ts +7 -0
- package/lib/typescript/src/components/Variants.d.ts.map +1 -0
- package/lib/typescript/src/components/index.d.ts +2 -1
- package/lib/typescript/src/components/index.d.ts.map +1 -1
- package/lib/typescript/src/components/native/ActivityIndicator.d.ts +2 -0
- package/lib/typescript/src/components/native/ActivityIndicator.d.ts.map +1 -0
- package/lib/typescript/src/components/native/FlatList.d.ts +2 -0
- package/lib/typescript/src/components/native/FlatList.d.ts.map +1 -0
- package/lib/typescript/src/components/native/Image.d.ts +2 -0
- package/lib/typescript/src/components/native/Image.d.ts.map +1 -0
- package/lib/typescript/src/components/native/ImageBackground.d.ts +3 -0
- package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -0
- package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts +2 -0
- package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts.map +1 -0
- package/lib/typescript/src/components/{Pressable.web.d.ts → native/Pressable.d.ts} +3 -2
- package/lib/typescript/src/components/native/Pressable.d.ts.map +1 -0
- package/lib/typescript/src/components/{Pressable.d.ts → native/Pressable.native.d.ts} +1 -3
- package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -0
- package/lib/typescript/src/components/native/RefreshControl.d.ts +2 -0
- package/lib/typescript/src/components/native/RefreshControl.d.ts.map +1 -0
- package/lib/typescript/src/components/native/ScrollView.d.ts +2 -0
- package/lib/typescript/src/components/native/ScrollView.d.ts.map +1 -0
- package/lib/typescript/src/components/native/SectionList.d.ts +2 -0
- package/lib/typescript/src/components/native/SectionList.d.ts.map +1 -0
- package/lib/typescript/src/components/native/Switch.d.ts +2 -0
- package/lib/typescript/src/components/native/Switch.d.ts.map +1 -0
- package/lib/typescript/src/components/native/Text.d.ts +2 -0
- package/lib/typescript/src/components/native/Text.d.ts.map +1 -0
- package/lib/typescript/src/components/native/TextInput.d.ts +2 -0
- package/lib/typescript/src/components/native/TextInput.d.ts.map +1 -0
- package/lib/typescript/src/components/native/TouchableHighlight.d.ts +2 -0
- package/lib/typescript/src/components/native/TouchableHighlight.d.ts.map +1 -0
- package/lib/typescript/src/components/native/TouchableOpacity.d.ts +2 -0
- package/lib/typescript/src/components/native/TouchableOpacity.d.ts.map +1 -0
- package/lib/typescript/src/components/native/View.d.ts +2 -0
- package/lib/typescript/src/components/native/View.d.ts.map +1 -0
- package/lib/typescript/src/components/native/VirtualizedList.d.ts +2 -0
- package/lib/typescript/src/components/native/VirtualizedList.d.ts.map +1 -0
- package/lib/typescript/src/core/createUnistylesComponent.d.ts +9 -3
- package/lib/typescript/src/core/createUnistylesComponent.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesElement.d.ts +3 -0
- package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -0
- package/lib/typescript/src/core/createUnistylesImageBackground.d.ts +4 -0
- package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -0
- package/lib/typescript/src/core/index.d.ts +4 -2
- package/lib/typescript/src/core/index.d.ts.map +1 -1
- package/lib/typescript/src/core/passForwardRef.d.ts +3 -0
- package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -0
- package/lib/typescript/src/core/withUnistyles/index.d.ts +2 -0
- package/lib/typescript/src/core/withUnistyles/index.d.ts.map +1 -0
- package/lib/typescript/src/core/withUnistyles/types.d.ts +6 -0
- package/lib/typescript/src/core/withUnistyles/types.d.ts.map +1 -0
- package/lib/typescript/src/core/withUnistyles/useDependencies.d.ts +13 -0
- package/lib/typescript/src/core/withUnistyles/useDependencies.d.ts.map +1 -0
- package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts +11 -0
- package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -0
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts +8 -0
- package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useMedia.d.ts +1 -1
- package/lib/typescript/src/hooks/useMedia.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useMedia.native.d.ts +6 -0
- package/lib/typescript/src/hooks/useMedia.native.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +7 -2
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/types.d.ts +17 -0
- package/lib/typescript/src/specs/ShadowRegistry/types.d.ts.map +1 -1
- package/lib/typescript/src/specs/index.d.ts +3 -11
- package/lib/typescript/src/specs/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/index.native.d.ts +12 -0
- package/lib/typescript/src/specs/index.native.d.ts.map +1 -0
- package/lib/typescript/src/web/create.d.ts +1 -1441
- package/lib/typescript/src/web/create.d.ts.map +1 -1
- package/lib/typescript/src/web/index.d.ts +5 -1463
- package/lib/typescript/src/web/index.d.ts.map +1 -1
- package/lib/typescript/src/web/registry.d.ts +2 -3
- package/lib/typescript/src/web/registry.d.ts.map +1 -1
- package/lib/typescript/src/web/runtime.d.ts.map +1 -1
- package/lib/typescript/src/web/shadowRegistry.d.ts +11 -3
- package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
- package/lib/typescript/src/web/utils/unistyle.d.ts +1 -2
- package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
- package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +3 -0
- package/package.json +20 -4
- package/plugin/common.js +4 -6
- package/plugin/import.js +63 -26
- package/plugin/index.js +48 -28
- package/plugin/ref.js +0 -234
- package/plugin/style.js +4 -317
- package/plugin/stylesheet.js +25 -10
- package/plugin/variants.js +60 -1
- package/src/components/ScopedTheme.tsx +32 -0
- package/src/components/Variants.tsx +30 -0
- package/src/components/index.ts +2 -1
- package/src/components/native/ActivityIndicator.tsx +4 -0
- package/src/components/native/FlatList.tsx +4 -0
- package/src/components/native/Image.tsx +4 -0
- package/src/components/native/ImageBackground.tsx +4 -0
- package/src/components/native/KeyboardAvoidingView.tsx +4 -0
- package/src/components/native/Pressable.native.tsx +57 -0
- package/src/components/native/Pressable.tsx +98 -0
- package/src/components/native/RefreshControl.tsx +4 -0
- package/src/components/native/ScrollView.tsx +4 -0
- package/src/components/native/SectionList.tsx +4 -0
- package/src/components/native/Switch.tsx +4 -0
- package/src/components/native/Text.tsx +4 -0
- package/src/components/native/TextInput.tsx +4 -0
- package/src/components/native/TouchableHighlight.tsx +4 -0
- package/src/components/native/TouchableOpacity.tsx +4 -0
- package/src/components/native/View.tsx +4 -0
- package/src/components/native/VirtualizedList.tsx +4 -0
- package/src/core/createUnistylesComponent.tsx +6 -76
- package/src/core/createUnistylesElement.tsx +9 -0
- package/src/core/createUnistylesImageBackground.tsx +24 -0
- package/src/core/index.ts +4 -2
- package/src/core/passForwardRef.ts +29 -0
- package/src/core/withUnistyles/index.ts +1 -0
- package/src/core/withUnistyles/types.ts +7 -0
- package/src/core/withUnistyles/useDependencies.ts +98 -0
- package/src/core/withUnistyles/withUnistyles.native.tsx +97 -0
- package/src/core/withUnistyles/withUnistyles.tsx +90 -0
- package/src/hooks/useMedia.native.ts +65 -0
- package/src/hooks/useMedia.ts +19 -36
- package/src/index.ts +3 -3
- package/src/specs/ShadowRegistry/index.ts +14 -5
- package/src/specs/ShadowRegistry/types.ts +18 -1
- package/src/specs/index.native.ts +27 -0
- package/src/specs/index.ts +3 -27
- package/src/web/create.ts +11 -32
- package/src/web/index.ts +8 -4
- package/src/web/registry.ts +15 -6
- package/src/web/runtime.ts +3 -1
- package/src/web/shadowRegistry.ts +59 -51
- package/src/web/utils/unistyle.ts +2 -3
- package/lib/commonjs/components/Pressable.js +0 -74
- package/lib/commonjs/components/Pressable.js.map +0 -1
- package/lib/commonjs/components/Pressable.web.js.map +0 -1
- package/lib/commonjs/core/createUnistylesComponent.native.js +0 -82
- package/lib/commonjs/core/createUnistylesComponent.native.js.map +0 -1
- package/lib/commonjs/core/getBoundArgs.js +0 -18
- package/lib/commonjs/core/getBoundArgs.js.map +0 -1
- package/lib/commonjs/core/getId.js +0 -9
- package/lib/commonjs/core/getId.js.map +0 -1
- package/lib/commonjs/hooks/useMedia.web.js +0 -43
- package/lib/commonjs/hooks/useMedia.web.js.map +0 -1
- package/lib/commonjs/specs/index.web.js +0 -17
- package/lib/commonjs/specs/index.web.js.map +0 -1
- package/lib/module/components/Pressable.js +0 -68
- package/lib/module/components/Pressable.js.map +0 -1
- package/lib/module/components/Pressable.web.js +0 -109
- package/lib/module/components/Pressable.web.js.map +0 -1
- package/lib/module/core/createUnistylesComponent.native.js +0 -75
- package/lib/module/core/createUnistylesComponent.native.js.map +0 -1
- package/lib/module/core/getBoundArgs.js +0 -13
- package/lib/module/core/getBoundArgs.js.map +0 -1
- package/lib/module/core/getId.js +0 -4
- package/lib/module/core/getId.js.map +0 -1
- package/lib/module/hooks/useMedia.web.js +0 -38
- package/lib/module/hooks/useMedia.web.js.map +0 -1
- package/lib/module/specs/index.web.js +0 -4
- package/lib/module/specs/index.web.js.map +0 -1
- package/lib/typescript/src/components/Pressable.d.ts.map +0 -1
- package/lib/typescript/src/components/Pressable.web.d.ts.map +0 -1
- package/lib/typescript/src/core/createUnistylesComponent.native.d.ts +0 -8
- package/lib/typescript/src/core/createUnistylesComponent.native.d.ts.map +0 -1
- package/lib/typescript/src/core/getBoundArgs.d.ts +0 -2
- package/lib/typescript/src/core/getBoundArgs.d.ts.map +0 -1
- package/lib/typescript/src/core/getId.d.ts +0 -2
- package/lib/typescript/src/core/getId.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useMedia.web.d.ts +0 -6
- package/lib/typescript/src/hooks/useMedia.web.d.ts.map +0 -1
- package/lib/typescript/src/specs/index.web.d.ts +0 -2
- package/lib/typescript/src/specs/index.web.d.ts.map +0 -1
- package/src/components/Pressable.tsx +0 -89
- package/src/components/Pressable.web.tsx +0 -129
- package/src/core/createUnistylesComponent.native.tsx +0 -83
- package/src/core/getBoundArgs.ts +0 -15
- package/src/core/getId.ts +0 -1
- package/src/hooks/useMedia.web.ts +0 -47
- package/src/specs/index.web.ts +0 -1
package/plugin/ref.js
CHANGED
@@ -1,11 +1,3 @@
|
|
1
|
-
function getRefProp(t, path) {
|
2
|
-
return path.node.openingElement.attributes.find(attr =>
|
3
|
-
t.isJSXAttribute(attr) &&
|
4
|
-
t.isJSXIdentifier(attr.name, { name: 'ref' }) &&
|
5
|
-
t.isJSXExpressionContainer(attr.value)
|
6
|
-
)
|
7
|
-
}
|
8
|
-
|
9
1
|
function hasStringRef(t, path) {
|
10
2
|
return path.node.openingElement.attributes.find(attr =>
|
11
3
|
t.isJSXAttribute(attr) &&
|
@@ -14,232 +6,6 @@ function hasStringRef(t, path) {
|
|
14
6
|
)
|
15
7
|
}
|
16
8
|
|
17
|
-
function arrayExpressionFromMetadata(t, metadata) {
|
18
|
-
const memberExpressions = metadata
|
19
|
-
.map(meta => {
|
20
|
-
// possible for inline styles
|
21
|
-
if (meta.members.length === 0) {
|
22
|
-
return meta.inlineStyle || meta.conditionalExpression || meta.logicalExpression
|
23
|
-
}
|
24
|
-
|
25
|
-
const [base, ...members] = meta.members
|
26
|
-
|
27
|
-
return members.reduce((object, property) => t.memberExpression(object, t.identifier(property)), t.identifier(base))
|
28
|
-
})
|
29
|
-
|
30
|
-
return t.arrayExpression(memberExpressions)
|
31
|
-
}
|
32
|
-
|
33
|
-
function arrayFromDynamicFunctionArgs(t, metadata, path) {
|
34
|
-
const memberExpressions = metadata
|
35
|
-
.map(meta => meta.dynamicFunction
|
36
|
-
? t.arrayExpression(meta.dynamicFunction.arguments)
|
37
|
-
: t.arrayExpression([]))
|
38
|
-
.filter(Boolean)
|
39
|
-
|
40
|
-
return t.arrayExpression(memberExpressions)
|
41
|
-
}
|
42
|
-
|
43
|
-
function addRef(t, path, metadata, state) {
|
44
|
-
const hasVariants = state.file.hasVariants
|
45
|
-
|
46
|
-
const newRefFunction = t.arrowFunctionExpression(
|
47
|
-
[t.identifier('ref')],
|
48
|
-
t.blockStatement([
|
49
|
-
t.expressionStatement(
|
50
|
-
t.callExpression(
|
51
|
-
t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
|
52
|
-
[
|
53
|
-
t.identifier('ref'),
|
54
|
-
arrayExpressionFromMetadata(t, metadata),
|
55
|
-
t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
|
56
|
-
arrayFromDynamicFunctionArgs(t, metadata, path)
|
57
|
-
]
|
58
|
-
)
|
59
|
-
),
|
60
|
-
t.returnStatement(
|
61
|
-
t.arrowFunctionExpression([],
|
62
|
-
t.callExpression(
|
63
|
-
t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
|
64
|
-
[t.identifier('ref')]
|
65
|
-
)
|
66
|
-
)
|
67
|
-
)
|
68
|
-
])
|
69
|
-
)
|
70
|
-
|
71
|
-
const newRefProp = t.jsxAttribute(
|
72
|
-
t.jsxIdentifier('ref'),
|
73
|
-
t.jsxExpressionContainer(newRefFunction)
|
74
|
-
)
|
75
|
-
|
76
|
-
path.node.openingElement.attributes.push(newRefProp)
|
77
|
-
}
|
78
|
-
|
79
|
-
function overrideRef(t, path, refProp, metadata, state) {
|
80
|
-
const hasVariants = state.file.hasVariants
|
81
|
-
const uniqueRefName = path.scope.generateUidIdentifier('ref').name
|
82
|
-
const isIdentifier = t.isIdentifier(refProp.value.expression)
|
83
|
-
const binding = path.scope.getBinding(refProp.value.expression.name)
|
84
|
-
|
85
|
-
// ref={ref}
|
86
|
-
if (isIdentifier && binding && t.isCallExpression(binding.path.node.init)) {
|
87
|
-
const userVariableName = refProp.value.expression.name
|
88
|
-
const newRefFunction = t.arrowFunctionExpression(
|
89
|
-
[t.identifier(uniqueRefName)],
|
90
|
-
t.blockStatement([
|
91
|
-
t.expressionStatement(
|
92
|
-
t.assignmentExpression(
|
93
|
-
'=',
|
94
|
-
t.memberExpression(t.identifier(userVariableName), t.identifier('current')),
|
95
|
-
t.identifier(uniqueRefName)
|
96
|
-
)
|
97
|
-
),
|
98
|
-
t.expressionStatement(
|
99
|
-
t.callExpression(
|
100
|
-
t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
|
101
|
-
[
|
102
|
-
t.identifier(uniqueRefName),
|
103
|
-
arrayExpressionFromMetadata(t, metadata),
|
104
|
-
t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
|
105
|
-
arrayFromDynamicFunctionArgs(t, metadata, path)
|
106
|
-
]
|
107
|
-
)
|
108
|
-
),
|
109
|
-
t.returnStatement(
|
110
|
-
t.arrowFunctionExpression([],
|
111
|
-
t.callExpression(
|
112
|
-
t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
|
113
|
-
[
|
114
|
-
t.identifier(uniqueRefName)
|
115
|
-
]
|
116
|
-
)
|
117
|
-
)
|
118
|
-
)
|
119
|
-
])
|
120
|
-
)
|
121
|
-
|
122
|
-
refProp.value = t.jsxExpressionContainer(newRefFunction)
|
123
|
-
|
124
|
-
return
|
125
|
-
}
|
126
|
-
|
127
|
-
// ref={ref => { }}
|
128
|
-
if (t.isArrowFunctionExpression(refProp.value.expression)) {
|
129
|
-
const userArrowFunction = refProp.value.expression
|
130
|
-
const userStatements = userArrowFunction.body.body
|
131
|
-
const userReturnStatement = userStatements.find(statement => t.isReturnStatement(statement))
|
132
|
-
const userCleanupFunction = userReturnStatement
|
133
|
-
? userReturnStatement.argument
|
134
|
-
: null
|
135
|
-
const userRefName = refProp.value.expression.params.length >= 1
|
136
|
-
? refProp.value.expression.params.at(0).name
|
137
|
-
: 'ref'
|
138
|
-
|
139
|
-
const newRefFunction = t.arrowFunctionExpression(
|
140
|
-
[t.identifier(userRefName)],
|
141
|
-
t.blockStatement([
|
142
|
-
...userStatements.filter(statement => !t.isReturnStatement(statement)),
|
143
|
-
t.expressionStatement(
|
144
|
-
t.callExpression(
|
145
|
-
t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
|
146
|
-
[
|
147
|
-
t.identifier(userRefName),
|
148
|
-
arrayExpressionFromMetadata(t, metadata),
|
149
|
-
t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
|
150
|
-
arrayFromDynamicFunctionArgs(t, metadata, path)
|
151
|
-
]
|
152
|
-
)
|
153
|
-
),
|
154
|
-
// Merged cleanup function
|
155
|
-
t.returnStatement(
|
156
|
-
t.arrowFunctionExpression([], t.blockStatement([
|
157
|
-
...(userCleanupFunction ? [
|
158
|
-
t.expressionStatement(
|
159
|
-
t.callExpression(userCleanupFunction, [])
|
160
|
-
)
|
161
|
-
] : []),
|
162
|
-
t.expressionStatement(
|
163
|
-
t.callExpression(
|
164
|
-
t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
|
165
|
-
[
|
166
|
-
t.identifier(userRefName)
|
167
|
-
]
|
168
|
-
)
|
169
|
-
)
|
170
|
-
]))
|
171
|
-
)
|
172
|
-
])
|
173
|
-
)
|
174
|
-
|
175
|
-
refProp.value = t.jsxExpressionContainer(newRefFunction)
|
176
|
-
|
177
|
-
return
|
178
|
-
}
|
179
|
-
|
180
|
-
if (!binding) {
|
181
|
-
return
|
182
|
-
}
|
183
|
-
|
184
|
-
// ref={scopedFunction}
|
185
|
-
const isArrowFunction = t.isArrowFunctionExpression(binding.path.node.init)
|
186
|
-
const isFunction = t.isFunctionDeclaration(binding.path.node)
|
187
|
-
|
188
|
-
if (!isArrowFunction && !isFunction) {
|
189
|
-
return
|
190
|
-
}
|
191
|
-
|
192
|
-
const userFunctionName = refProp.value.expression
|
193
|
-
const userFunction = isArrowFunction
|
194
|
-
? binding.path.node.init
|
195
|
-
: binding.path.node
|
196
|
-
const returnStatement = userFunction.body.body.find(statement => t.isReturnStatement(statement));
|
197
|
-
const userCleanupFunction = returnStatement ? returnStatement.argument : null;
|
198
|
-
|
199
|
-
const newRefFunction = t.arrowFunctionExpression(
|
200
|
-
[t.identifier(uniqueRefName)],
|
201
|
-
t.blockStatement([
|
202
|
-
t.expressionStatement(
|
203
|
-
t.callExpression(userFunctionName, [t.identifier(uniqueRefName)])
|
204
|
-
),
|
205
|
-
t.expressionStatement(
|
206
|
-
t.callExpression(
|
207
|
-
t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
|
208
|
-
[
|
209
|
-
t.identifier(uniqueRefName),
|
210
|
-
arrayExpressionFromMetadata(t, metadata),
|
211
|
-
t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
|
212
|
-
arrayFromDynamicFunctionArgs(t, metadata, path)
|
213
|
-
]
|
214
|
-
)
|
215
|
-
),
|
216
|
-
t.returnStatement(
|
217
|
-
t.arrowFunctionExpression([], t.blockStatement([
|
218
|
-
...(userCleanupFunction ? [
|
219
|
-
t.expressionStatement(
|
220
|
-
t.callExpression(userCleanupFunction, [])
|
221
|
-
)
|
222
|
-
] : []),
|
223
|
-
t.expressionStatement(
|
224
|
-
t.callExpression(
|
225
|
-
t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
|
226
|
-
[
|
227
|
-
t.identifier(uniqueRefName)
|
228
|
-
]
|
229
|
-
)
|
230
|
-
)
|
231
|
-
].filter(Boolean)))
|
232
|
-
)
|
233
|
-
])
|
234
|
-
)
|
235
|
-
|
236
|
-
refProp.value = t.jsxExpressionContainer(newRefFunction)
|
237
|
-
userFunction.body.body = userFunction.body.body.filter(statement => !t.isReturnStatement(statement))
|
238
|
-
}
|
239
|
-
|
240
9
|
module.exports = {
|
241
|
-
getRefProp,
|
242
|
-
addRef,
|
243
|
-
overrideRef,
|
244
10
|
hasStringRef
|
245
11
|
}
|
package/plugin/style.js
CHANGED
@@ -141,224 +141,6 @@ function styleAttributeToArray(t, path) {
|
|
141
141
|
styleAttribute.value.expression = t.arrayExpression([styleAttribute.value.expression])
|
142
142
|
}
|
143
143
|
|
144
|
-
function metadataToRawStyle(t, metadata, styleExpression) {
|
145
|
-
const expressions = []
|
146
|
-
|
147
|
-
metadata.forEach(meta => {
|
148
|
-
if (meta.inlineStyle) {
|
149
|
-
return meta.inlineStyle.properties.forEach(prop => {
|
150
|
-
if (t.isObjectProperty(prop)) {
|
151
|
-
expressions.push(t.objectExpression([prop]))
|
152
|
-
}
|
153
|
-
})
|
154
|
-
}
|
155
|
-
|
156
|
-
if (meta.members.length > 0) {
|
157
|
-
return expressions.push(t.memberExpression(...meta.members.map(member => t.identifier(member))))
|
158
|
-
}
|
159
|
-
|
160
|
-
if (meta.logicalExpression) {
|
161
|
-
const expression = t.cloneNode(meta.logicalExpression)
|
162
|
-
|
163
|
-
if (t.isIdentifier(expression.left)) {
|
164
|
-
if (t.isCallExpression(expression.right)) {
|
165
|
-
expression.right = expression.right.callee
|
166
|
-
}
|
167
|
-
|
168
|
-
expressions.push(expression)
|
169
|
-
}
|
170
|
-
}
|
171
|
-
|
172
|
-
if (meta.conditionalExpression) {
|
173
|
-
const expression = t.cloneNode(meta.conditionalExpression)
|
174
|
-
|
175
|
-
if (t.isCallExpression(expression.alternate)) {
|
176
|
-
expression.alternate = expression.alternate.callee
|
177
|
-
}
|
178
|
-
|
179
|
-
if (t.isCallExpression(expression.consequent)) {
|
180
|
-
expression.consequent = expression.consequent.callee
|
181
|
-
}
|
182
|
-
|
183
|
-
expressions.push(expression)
|
184
|
-
}
|
185
|
-
})
|
186
|
-
|
187
|
-
if (t.isArrowFunctionExpression(styleExpression) && styleExpression.params.length === 1) {
|
188
|
-
return t.jsxAttribute(
|
189
|
-
t.jsxIdentifier('rawStyle'),
|
190
|
-
t.jsxExpressionContainer(
|
191
|
-
t.arrowFunctionExpression(styleExpression.params, t.arrayExpression([
|
192
|
-
...expressions
|
193
|
-
])
|
194
|
-
))
|
195
|
-
)
|
196
|
-
}
|
197
|
-
|
198
|
-
return t.jsxAttribute(
|
199
|
-
t.jsxIdentifier('rawStyle'),
|
200
|
-
t.jsxExpressionContainer(t.arrayExpression([
|
201
|
-
...expressions
|
202
|
-
]))
|
203
|
-
)
|
204
|
-
}
|
205
|
-
|
206
|
-
function wrapInGetBoundArgs(t, toWrap, extraArgs) {
|
207
|
-
const expression = t.callExpression(
|
208
|
-
t.identifier('getBoundArgs'),
|
209
|
-
[toWrap]
|
210
|
-
)
|
211
|
-
|
212
|
-
return t.callExpression(
|
213
|
-
t.memberExpression(expression, t.identifier('bind')),
|
214
|
-
[t.identifier('undefined'), ...extraArgs].filter(Boolean)
|
215
|
-
)
|
216
|
-
}
|
217
|
-
|
218
|
-
function handlePressableFromMemberExpression(t, path, metadata, wrapInArrowFunction) {
|
219
|
-
let expression = undefined
|
220
|
-
let args = []
|
221
|
-
|
222
|
-
const members = metadata.at(0).members
|
223
|
-
|
224
|
-
if (members) {
|
225
|
-
expression = members.slice(1).reduce(
|
226
|
-
(acc, property) => t.memberExpression(acc, t.identifier(property)),
|
227
|
-
t.identifier(members[0]))
|
228
|
-
}
|
229
|
-
|
230
|
-
if (t.isMemberExpression(metadata.at(0))) {
|
231
|
-
expression = metadata.at(0)
|
232
|
-
}
|
233
|
-
|
234
|
-
if (t.isCallExpression(metadata.at(0))) {
|
235
|
-
expression = metadata.at(0).callee
|
236
|
-
args = metadata.at(0).arguments
|
237
|
-
}
|
238
|
-
|
239
|
-
if (!expression) {
|
240
|
-
return
|
241
|
-
}
|
242
|
-
|
243
|
-
const bindCall = wrapInGetBoundArgs(t , expression, wrapInArrowFunction ? [t.identifier("state")] : args)
|
244
|
-
|
245
|
-
if (t.isCallExpression(metadata.at(0))) {
|
246
|
-
return bindCall
|
247
|
-
}
|
248
|
-
|
249
|
-
if (!wrapInArrowFunction) {
|
250
|
-
return t.conditionalExpression(
|
251
|
-
t.binaryExpression(
|
252
|
-
"===",
|
253
|
-
t.unaryExpression(
|
254
|
-
"typeof",
|
255
|
-
expression
|
256
|
-
),
|
257
|
-
t.stringLiteral("function")
|
258
|
-
),
|
259
|
-
bindCall,
|
260
|
-
expression
|
261
|
-
)
|
262
|
-
}
|
263
|
-
|
264
|
-
// state => typeof style.pressable === 'function'
|
265
|
-
// ? getBoundArgs(style.pressable).bind(undefined, state)
|
266
|
-
// : style.pressable
|
267
|
-
return t.arrowFunctionExpression(
|
268
|
-
[t.identifier("state")],
|
269
|
-
t.conditionalExpression(
|
270
|
-
t.binaryExpression(
|
271
|
-
"===",
|
272
|
-
t.unaryExpression(
|
273
|
-
"typeof",
|
274
|
-
expression
|
275
|
-
),
|
276
|
-
t.stringLiteral("function")
|
277
|
-
),
|
278
|
-
bindCall,
|
279
|
-
expression
|
280
|
-
)
|
281
|
-
)
|
282
|
-
}
|
283
|
-
|
284
|
-
function handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, wrapper, index) {
|
285
|
-
if (t.isObjectExpression(wrapper)) {
|
286
|
-
return
|
287
|
-
}
|
288
|
-
|
289
|
-
if (t.isMemberExpression(wrapper) && t.isArrayExpression(parentWrapper)) {
|
290
|
-
parentWrapper.elements[index] = handlePressableFromMemberExpression(t, path, [metadata[index]])
|
291
|
-
|
292
|
-
return
|
293
|
-
}
|
294
|
-
|
295
|
-
if (t.isMemberExpression(wrapper) && !t.isArrayExpression(parentWrapper)) {
|
296
|
-
parentWrapper = handlePressableFromMemberExpression(t, path, metadata)
|
297
|
-
|
298
|
-
return
|
299
|
-
}
|
300
|
-
|
301
|
-
if (t.isLogicalExpression(wrapper)) {
|
302
|
-
if (t.isIdentifier(wrapper.left) && t.isMemberExpression(wrapper.right)) {
|
303
|
-
parentWrapper.elements[index].right = handlePressableFromMemberExpression(t, path, [parentWrapper.elements[index].right])
|
304
|
-
|
305
|
-
return
|
306
|
-
}
|
307
|
-
|
308
|
-
return
|
309
|
-
}
|
310
|
-
|
311
|
-
if (t.isConditionalExpression(wrapper) && t.isArrayExpression(parentWrapper)) {
|
312
|
-
if (t.isMemberExpression(wrapper.alternate) || t.isCallExpression(wrapper.alternate)) {
|
313
|
-
parentWrapper.elements[index].alternate = handlePressableFromMemberExpression(t, path, [parentWrapper.elements[index].alternate])
|
314
|
-
}
|
315
|
-
|
316
|
-
if (t.isMemberExpression(wrapper.consequent) || t.isCallExpression(wrapper.consequent)) {
|
317
|
-
parentWrapper.elements[index].consequent = handlePressableFromMemberExpression(t, path, [parentWrapper.elements[index].consequent])
|
318
|
-
}
|
319
|
-
|
320
|
-
return
|
321
|
-
}
|
322
|
-
|
323
|
-
if (t.isConditionalExpression(wrapper) && !t.isArrayExpression(parentWrapper)) {
|
324
|
-
if (t.isMemberExpression(wrapper.alternate) || t.isCallExpression(wrapper.alternate)) {
|
325
|
-
parentWrapper.alternate = handlePressableFromMemberExpression(t, path, [parentWrapper.alternate])
|
326
|
-
}
|
327
|
-
|
328
|
-
if (t.isMemberExpression(wrapper.consequent) || t.isCallExpression(wrapper.consequent)) {
|
329
|
-
parentWrapper.consequent = handlePressableFromMemberExpression(t, path, [parentWrapper.consequent])
|
330
|
-
}
|
331
|
-
|
332
|
-
return
|
333
|
-
}
|
334
|
-
|
335
|
-
const pressableArgs = t.isCallExpression(wrapper)
|
336
|
-
? wrapper.arguments
|
337
|
-
: wrapper.argument.arguments
|
338
|
-
const callee = t.isCallExpression(wrapper)
|
339
|
-
? wrapper.callee
|
340
|
-
: wrapper.argument.callee
|
341
|
-
|
342
|
-
const getBoundArgsCall = t.callExpression(
|
343
|
-
t.identifier('getBoundArgs'),
|
344
|
-
[callee]
|
345
|
-
)
|
346
|
-
const bindCall = t.callExpression(
|
347
|
-
t.memberExpression(getBoundArgsCall, t.identifier('bind')),
|
348
|
-
[t.identifier('undefined'), ...pressableArgs]
|
349
|
-
)
|
350
|
-
|
351
|
-
if (t.isCallExpression(wrapper) && t.isArrayExpression(parentWrapper)) {
|
352
|
-
parentWrapper.elements[index] = bindCall
|
353
|
-
|
354
|
-
return
|
355
|
-
}
|
356
|
-
|
357
|
-
if (t.isCallExpression(wrapper)) {
|
358
|
-
styleExpression.body = bindCall
|
359
|
-
}
|
360
|
-
}
|
361
|
-
|
362
144
|
function handlePressable(t, path, styleAttr, metadata, state) {
|
363
145
|
// add variants
|
364
146
|
if (state.file.hasVariants) {
|
@@ -370,106 +152,11 @@ function handlePressable(t, path, styleAttr, metadata, state) {
|
|
370
152
|
path.node.openingElement.attributes.push(variants)
|
371
153
|
}
|
372
154
|
|
373
|
-
//
|
374
|
-
|
375
|
-
|
376
|
-
const styleExpression = styleAttr.value.expression
|
377
|
-
|
378
|
-
// {style.pressable}
|
379
|
-
if (t.isMemberExpression(styleExpression)) {
|
380
|
-
styleAttr.value.expression = handlePressableFromMemberExpression(t, path, metadata, true)
|
381
|
-
|
382
|
-
return
|
383
|
-
}
|
384
|
-
|
385
|
-
// {style.pressable(1, 2)}
|
386
|
-
if (t.isCallExpression(styleExpression)) {
|
387
|
-
// user already called dynamic function
|
388
|
-
const expression = t.callExpression(
|
389
|
-
t.identifier('getBoundArgs'),
|
390
|
-
[styleExpression.callee]
|
391
|
-
)
|
392
|
-
const bindCall = t.callExpression(
|
393
|
-
t.memberExpression(expression, t.identifier('bind')),
|
394
|
-
[t.identifier('undefined'), ...styleExpression.arguments]
|
395
|
-
)
|
396
|
-
|
397
|
-
path.node.openingElement.attributes = path.node.openingElement.attributes.map(attribute => {
|
398
|
-
if (attribute.name.name === "style") {
|
399
|
-
attribute.value.expression = t.arrowFunctionExpression([], bindCall)
|
400
|
-
}
|
401
|
-
|
402
|
-
return attribute
|
403
|
-
})
|
404
|
-
|
405
|
-
return
|
406
|
-
}
|
407
|
-
|
408
|
-
// {() => style.pressable(1, 2)}
|
409
|
-
if (t.isArrowFunctionExpression(styleExpression) && styleExpression.params.length === 0) {
|
410
|
-
let parentWrapper = t.isBlockStatement(styleExpression.body)
|
411
|
-
? styleExpression.body.body.find(node => t.isReturnStatement(node))
|
412
|
-
: styleExpression.body
|
413
|
-
|
414
|
-
if (t.isMemberExpression(parentWrapper)) {
|
415
|
-
return
|
416
|
-
}
|
417
|
-
|
418
|
-
if (t.isArrayExpression(parentWrapper)) {
|
419
|
-
return parentWrapper.elements.forEach((wrapper, index) => handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, wrapper, index))
|
420
|
-
}
|
421
|
-
|
422
|
-
if (t.isReturnStatement(parentWrapper)) {
|
423
|
-
parentWrapper = parentWrapper.argument
|
424
|
-
|
425
|
-
return handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, parentWrapper)
|
426
|
-
}
|
427
|
-
|
428
|
-
const pressableArgs = t.isCallExpression(parentWrapper)
|
429
|
-
? parentWrapper.arguments
|
430
|
-
: parentWrapper.argument.arguments
|
431
|
-
const callee = t.isCallExpression(parentWrapper)
|
432
|
-
? parentWrapper.callee
|
433
|
-
: parentWrapper.argument.callee
|
434
|
-
const getBoundArgsCall = t.callExpression(
|
435
|
-
t.identifier('getBoundArgs'),
|
436
|
-
[callee]
|
437
|
-
)
|
438
|
-
const bindCall = t.callExpression(
|
439
|
-
t.memberExpression(getBoundArgsCall, t.identifier('bind')),
|
440
|
-
[t.identifier('undefined'), ...pressableArgs]
|
441
|
-
)
|
442
|
-
|
443
|
-
if (t.isCallExpression(parentWrapper)) {
|
444
|
-
styleExpression.body = bindCall
|
445
|
-
|
446
|
-
return
|
447
|
-
}
|
448
|
-
|
449
|
-
if (parentWrapper) {
|
450
|
-
parentWrapper.argument = bindCall
|
451
|
-
}
|
452
|
-
|
453
|
-
return
|
454
|
-
}
|
455
|
-
|
456
|
-
// {state => style.pressable(state, 1, 2)}
|
457
|
-
if (t.isArrowFunctionExpression(styleExpression) && styleExpression.params.length > 0) {
|
458
|
-
// user used state with custom args we need to getBoundArgs
|
459
|
-
// detect between arrow function with body and arrow function
|
460
|
-
let parentWrapper = t.isBlockStatement(styleExpression.body)
|
461
|
-
? styleExpression.body.body.find(node => t.isReturnStatement(node))
|
462
|
-
: styleExpression.body
|
463
|
-
|
464
|
-
if (t.isArrayExpression(parentWrapper)) {
|
465
|
-
return parentWrapper.elements.forEach((wrapper, index) => handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, wrapper, index))
|
466
|
-
}
|
467
|
-
|
468
|
-
if (t.isReturnStatement(parentWrapper)) {
|
469
|
-
parentWrapper = parentWrapper.argument
|
470
|
-
}
|
155
|
+
// to add import
|
156
|
+
state.file.hasAnyUnistyle = true
|
471
157
|
|
472
|
-
|
158
|
+
if (t.isMemberExpression(styleAttr.value.expression)) {
|
159
|
+
// styleAttr.value.expression = handlePressableFromMemberExpression(t, path, metadata, true)
|
473
160
|
}
|
474
161
|
}
|
475
162
|
|
package/plugin/stylesheet.js
CHANGED
@@ -168,30 +168,45 @@ function analyzeDependencies(t, state, name, unistyleObj, themeName, rtName) {
|
|
168
168
|
}
|
169
169
|
}
|
170
170
|
|
171
|
-
function
|
171
|
+
function getUnistyles(t, property) {
|
172
172
|
const propertyValue = t.isArrowFunctionExpression(property.value)
|
173
173
|
? property.value.body
|
174
174
|
: property.value
|
175
175
|
|
176
176
|
if (t.isObjectExpression(propertyValue)) {
|
177
|
-
return propertyValue
|
177
|
+
return [propertyValue]
|
178
178
|
}
|
179
179
|
|
180
180
|
if (t.isBlockStatement(propertyValue)) {
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
181
|
+
// here we might have single return statement
|
182
|
+
// or if-else statements with return statements
|
183
|
+
return propertyValue.body
|
184
|
+
.flatMap(value => {
|
185
|
+
if (t.isReturnStatement(value)) {
|
186
|
+
return [value]
|
187
|
+
}
|
188
|
+
|
189
|
+
if (!t.isIfStatement(value)) {
|
190
|
+
return []
|
191
|
+
}
|
192
|
+
|
193
|
+
return [value.consequent, value.alternate]
|
194
|
+
.filter(Boolean)
|
195
|
+
.flatMap(value => {
|
196
|
+
if (t.isBlockStatement(value)) {
|
197
|
+
return value.body.filter(t.isReturnStatement)
|
198
|
+
}
|
199
|
+
})
|
200
|
+
})
|
201
|
+
.map(value => value.argument)
|
187
202
|
}
|
188
203
|
|
189
|
-
return
|
204
|
+
return []
|
190
205
|
}
|
191
206
|
|
192
207
|
module.exports = {
|
193
208
|
isUnistylesStyleSheet,
|
194
209
|
analyzeDependencies,
|
195
210
|
addStyleSheetTag,
|
196
|
-
|
211
|
+
getUnistyles
|
197
212
|
}
|
package/plugin/variants.js
CHANGED
@@ -27,7 +27,66 @@ function extractVariants(t, path, state) {
|
|
27
27
|
state.file.hasVariants = true
|
28
28
|
}
|
29
29
|
|
30
|
+
function wrapVariants(t, path) {
|
31
|
+
const wrapperElement = t.jsxElement(
|
32
|
+
t.jsxOpeningElement(
|
33
|
+
t.jsxIdentifier('Variants'),
|
34
|
+
[
|
35
|
+
t.jsxAttribute(
|
36
|
+
t.jsxIdentifier('variants'),
|
37
|
+
t.jsxExpressionContainer(t.identifier('__uni__variants'))
|
38
|
+
),
|
39
|
+
],
|
40
|
+
false
|
41
|
+
),
|
42
|
+
t.jsxClosingElement(t.jsxIdentifier('Variants')),
|
43
|
+
[]
|
44
|
+
)
|
45
|
+
|
46
|
+
const element = path.openingElement && path.openingElement.name
|
47
|
+
const isWrappedInRegularFragment = t.isJSXFragment(path)
|
48
|
+
const isWrappedInFragment = (t.isJSXMemberExpression(element) && element.object.name === 'React' && element.property.name === 'Fragment') || (t.isJSXIdentifier(element) && element.name === 'Fragment')
|
49
|
+
|
50
|
+
wrapperElement.children = (isWrappedInRegularFragment || isWrappedInFragment)
|
51
|
+
? path.children
|
52
|
+
: [path]
|
53
|
+
|
54
|
+
// copy Fragment props like key
|
55
|
+
if (isWrappedInFragment) {
|
56
|
+
wrapperElement.openingElement.attributes.push(...path.openingElement.attributes)
|
57
|
+
}
|
58
|
+
|
59
|
+
return wrapperElement
|
60
|
+
}
|
61
|
+
|
62
|
+
function addJSXVariants(t, path) {
|
63
|
+
if (!t.isReturnStatement(path.node)) {
|
64
|
+
return
|
65
|
+
}
|
66
|
+
|
67
|
+
const jsxElement = path.node.argument
|
68
|
+
|
69
|
+
if (t.isConditionalExpression(jsxElement)) {
|
70
|
+
const ifStatement = t.ifStatement(
|
71
|
+
jsxElement.test,
|
72
|
+
t.blockStatement([t.returnStatement(jsxElement.consequent)]),
|
73
|
+
t.blockStatement([t.returnStatement(jsxElement.alternate)])
|
74
|
+
)
|
75
|
+
|
76
|
+
path.replaceWith(ifStatement)
|
77
|
+
|
78
|
+
return
|
79
|
+
}
|
80
|
+
|
81
|
+
if (!t.isJSXElement(jsxElement) && !t.isJSXFragment(jsxElement)) {
|
82
|
+
return
|
83
|
+
}
|
84
|
+
|
85
|
+
path.get('argument').replaceWith(wrapVariants(t, jsxElement));
|
86
|
+
}
|
87
|
+
|
30
88
|
module.exports = {
|
31
89
|
isUsingVariants,
|
32
|
-
extractVariants
|
90
|
+
extractVariants,
|
91
|
+
addJSXVariants
|
33
92
|
}
|