rn-css 1.3.0 → 1.4.2

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.
@@ -7,7 +7,7 @@ declare type Functs<T> = (arg: T & {
7
7
  shared: unknown;
8
8
  }) => Primitive;
9
9
  declare type OptionalProps = {
10
- rnCSS?: string;
10
+ rnCSS?: `${string};`;
11
11
  onMouseEnter?: (event: MouseEvent) => void;
12
12
  onMouseLeave?: (event: MouseEvent) => void;
13
13
  onLayout?: (event: LayoutChangeEvent) => void;
@@ -15,25 +15,23 @@ declare type OptionalProps = {
15
15
  style?: StyleProp<any>;
16
16
  };
17
17
  declare const styled: <Props>(Component: React.ComponentType<Props>) => {
18
- <S>(chunks: TemplateStringsArray, ...functs: (string | number | boolean | Functs<S & Props> | null | undefined)[]): React.ForwardRefExoticComponent<Props & S & OptionalProps & {
19
- ref?: ((instance: any) => void) | React.RefObject<any> | null | undefined;
18
+ <S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S & Props>)[]): React.ForwardRefExoticComponent<Props & S & OptionalProps & {
19
+ ref?: React.Ref<any> | undefined;
20
+ }>;
21
+ attrs<S_1>(opts: Partial<S_1 & Props> | ((props: S_1 & Props) => Partial<S_1 & Props>)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1 & Props>)[]) => React.ForwardRefExoticComponent<(Props | S_1) & OptionalProps & {
22
+ ref?: React.Ref<any> | undefined;
20
23
  }>;
21
- attrs<S_1>(opts: Partial<S_1 & Props> | ((props: S_1 & Props) => Partial<S_1 & Props>)): (chunks: TemplateStringsArray, ...functs: (string | number | boolean | Functs<S_1 & Props> | null | undefined)[]) => React.ForwardRefExoticComponent<(Props & OptionalProps & {
22
- ref?: ((instance: any) => void) | React.RefObject<any> | null | undefined;
23
- }) | (S_1 & OptionalProps & {
24
- ref?: ((instance: any) => void) | React.RefObject<any> | null | undefined;
25
- })>;
26
24
  };
27
25
  export default styled;
28
26
  export declare const styledFlatList: {
29
- <S>(chunks: TemplateStringsArray, ...functs: (string | number | boolean | Functs<S> | null | undefined)[]): <Type>(props: S & FlatListProps<Type> & OptionalProps) => JSX.Element;
30
- attrs<S_1>(opts: Partial<S_1 & FlatListProps<any>> | ((props: S_1 & FlatListProps<any>) => Partial<S_1 & FlatListProps<any>>)): (chunks: TemplateStringsArray, ...functs: (string | number | boolean | Functs<S_1 & FlatListProps<any>> | null | undefined)[]) => <Props>(componentProps: S_1 & FlatListProps<Props> & OptionalProps) => JSX.Element;
27
+ <S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]): <Type>(props: S & FlatListProps<Type> & OptionalProps) => JSX.Element;
28
+ attrs<S_1>(opts: Partial<S_1 & FlatListProps<any>> | ((props: S_1 & FlatListProps<any>) => Partial<S_1 & FlatListProps<any>>)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1 & FlatListProps<any>>)[]) => <Props>(componentProps: S_1 & FlatListProps<Props> & OptionalProps) => JSX.Element;
31
29
  };
32
30
  export declare const styledSectionList: {
33
- <S>(chunks: TemplateStringsArray, ...functs: (string | number | boolean | Functs<S> | null | undefined)[]): <Type>(props: S & SectionListProps<Type, import("react-native").DefaultSectionT> & OptionalProps) => JSX.Element;
34
- attrs<S_1>(opts: Partial<S_1 & SectionListProps<any, import("react-native").DefaultSectionT>> | ((props: S_1 & SectionListProps<any, import("react-native").DefaultSectionT>) => Partial<S_1 & SectionListProps<any, import("react-native").DefaultSectionT>>)): (chunks: TemplateStringsArray, ...functs: (string | number | boolean | Functs<S_1 & SectionListProps<any, import("react-native").DefaultSectionT>> | null | undefined)[]) => <Props>(componentProps: S_1 & SectionListProps<Props, import("react-native").DefaultSectionT> & OptionalProps) => JSX.Element;
31
+ <S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]): <Type>(props: S & SectionListProps<Type, import("react-native").DefaultSectionT> & OptionalProps) => JSX.Element;
32
+ attrs<S_1>(opts: Partial<S_1 & SectionListProps<any, import("react-native").DefaultSectionT>> | ((props: S_1 & SectionListProps<any, import("react-native").DefaultSectionT>) => Partial<S_1 & SectionListProps<any, import("react-native").DefaultSectionT>>)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1 & SectionListProps<any, import("react-native").DefaultSectionT>>)[]) => <Props>(componentProps: S_1 & SectionListProps<Props, import("react-native").DefaultSectionT> & OptionalProps) => JSX.Element;
35
33
  };
36
34
  export declare const styledVirtualizedList: {
37
- <S>(chunks: TemplateStringsArray, ...functs: (string | number | boolean | Functs<S> | null | undefined)[]): <Type>(props: S & VirtualizedListProps<Type> & OptionalProps) => JSX.Element;
38
- attrs<S_1>(opts: Partial<S_1 & VirtualizedListProps<any>> | ((props: S_1 & VirtualizedListProps<any>) => Partial<S_1 & VirtualizedListProps<any>>)): (chunks: TemplateStringsArray, ...functs: (string | number | boolean | Functs<S_1 & VirtualizedListProps<any>> | null | undefined)[]) => <Props>(componentProps: S_1 & VirtualizedListProps<Props> & OptionalProps) => JSX.Element;
35
+ <S>(chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S>)[]): <Type>(props: S & VirtualizedListProps<Type> & OptionalProps) => JSX.Element;
36
+ attrs<S_1>(opts: Partial<S_1 & VirtualizedListProps<any>> | ((props: S_1 & VirtualizedListProps<any>) => Partial<S_1 & VirtualizedListProps<any>>)): (chunks: TemplateStringsArray, ...functs: (Primitive | Functs<S_1 & VirtualizedListProps<any>>)[]) => <Props>(componentProps: S_1 & VirtualizedListProps<Props> & OptionalProps) => JSX.Element;
39
37
  };
@@ -122,10 +122,10 @@ const styled = (Component) => {
122
122
  // if (em !== currentFontSize) {
123
123
  if (finalStyle.fontSize) {
124
124
  return react_1.default.createElement(features_1.FontSizeContext.Provider, { value: em },
125
- react_1.default.createElement(Component, Object.assign({ ref: ref }, props, newProps)));
125
+ react_1.default.createElement(Component, { ref: ref, ...props, ...newProps }));
126
126
  }
127
127
  else {
128
- return react_1.default.createElement(Component, Object.assign({ ref: ref }, props, newProps));
128
+ return react_1.default.createElement(Component, { ref: ref, ...props, ...newProps });
129
129
  }
130
130
  });
131
131
  return ForwardRefComponent;
@@ -135,7 +135,7 @@ const styled = (Component) => {
135
135
  const ComponentWithAttrs = styledComponent(chunks, ...functs);
136
136
  const ForwardRefComponent = react_1.default.forwardRef((props, ref) => {
137
137
  const attrs = (opts instanceof Function) ? opts(props) : opts;
138
- return react_1.default.createElement(ComponentWithAttrs, Object.assign({ ref: ref }, props, attrs));
138
+ return react_1.default.createElement(ComponentWithAttrs, { ref: ref, ...props, ...attrs });
139
139
  });
140
140
  // TODO : Find a way to remove from the Props the properties affected by opts
141
141
  return ForwardRefComponent;
@@ -153,5 +153,5 @@ const styledVirtualizedList = (chunks, ...functs) => (props) => invoke(styled(re
153
153
  exports.styledVirtualizedList = styledVirtualizedList;
154
154
  exports.styledVirtualizedList.attrs = (opts) => (chunks, ...functs) => (componentProps) => invoke(styled(react_native_1.VirtualizedList).attrs(opts)(chunks, ...functs), componentProps);
155
155
  function invoke(Component, props) {
156
- return react_1.default.createElement(Component, Object.assign({}, props));
156
+ return react_1.default.createElement(Component, { ...props });
157
157
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-css",
3
- "version": "1.3.0",
3
+ "version": "1.4.2",
4
4
  "scripts": {
5
5
  "test": "jest",
6
6
  "prepare": "tsc",
@@ -23,9 +23,9 @@
23
23
  "@types/jest": "^26.0.20",
24
24
  "@types/react": "^17.0.1",
25
25
  "@types/react-native": "^0.63.48",
26
- "@typescript-eslint/eslint-plugin": "^4.15.0",
27
- "@typescript-eslint/parser": "^4.15.0",
28
- "babel-jest": "^26.6.3",
26
+ "@typescript-eslint/eslint-plugin": "^4.29.2",
27
+ "@typescript-eslint/parser": "^4.29.2",
28
+ "babel-jest": "^27.0.6",
29
29
  "babel-loader": "^8.2.2",
30
30
  "dotenv": "^8.2.0",
31
31
  "eslint": "^7.19.0",
@@ -49,9 +49,9 @@
49
49
  "react-native-web": "^0.17.1",
50
50
  "react-test-renderer": "17.0.2",
51
51
  "release-it": "^14.3.0",
52
- "ts-jest": "^26.5.1",
53
- "ts-loader": "^8.0.17",
54
- "typescript": "^4.1.4",
52
+ "ts-jest": "^27.0.5",
53
+ "ts-loader": "^9.2.5",
54
+ "typescript": "^4.3.5",
55
55
  "webpack": "^5.21.2",
56
56
  "webpack-cli": "^4.5.0",
57
57
  "webpack-dev-server": "^3.11.2"
@@ -42,8 +42,8 @@ export function cssToRNStyle (css: string, units: { em?: number, width?: number,
42
42
  vh: height / 100,
43
43
  vmin: Math.min(width, height) / 100,
44
44
  vmax: Math.max(width, height) / 100,
45
- width: 1,
46
- height: 1,
45
+ width: 100,
46
+ height: 100,
47
47
  rem: 16,
48
48
  px: 1,
49
49
  pt: 72 / 96,
@@ -59,8 +59,9 @@ export function cssToRNStyle (css: string, units: { em?: number, width?: number,
59
59
 
60
60
  function cssChunkToStyle (css: string) {
61
61
  const result: PartialStyle = {}
62
- css.split(/\s*;\s*/mg).forEach((entry: string) => {
63
- const [rawKey, rawValue] = entry.split(':')
62
+ css.split(/\s*;\s*(?!base64)/mg).forEach((entry: string) => {
63
+ const [rawKey, ...rest] = entry.split(':')
64
+ const rawValue = rest.join(':')
64
65
  if (!rawValue) return
65
66
  const key = kebab2camel(rawKey.trim())
66
67
  const value = stripSpaces(rawValue.trim())// We need this to correctly read calc() values
package/src/features.tsx CHANGED
@@ -41,11 +41,15 @@ export const useMediaQuery = (media: undefined | MediaQuery[], units: Units): St
41
41
  }
42
42
  }
43
43
 
44
- /** HOC that will apply the font size to the styles defined with em units */
44
+ /** HOC that will measure the layout to handle styles that use % units */
45
45
  export const useLayout = (onLayout?: (event: LayoutChangeEvent) => void) => {
46
46
  const [layout, setLayout] = React.useState({ width: 0, height: 0 })
47
+ // Prevent calling setState if the component is unmounted
48
+ const unmounted = React.useRef(false)
49
+ React.useEffect(() => () => { unmounted.current = true }, [])
47
50
  const updateLayout = React.useCallback((event: LayoutChangeEvent) => {
48
51
  if (onLayout) onLayout(event)
52
+ if (unmounted.current) return
49
53
  const { width, height } = event.nativeEvent.layout
50
54
  if (width !== layout.width || height !== layout.height) setLayout({ width, height })
51
55
  }, [onLayout, layout.width, layout.height])
@@ -17,7 +17,7 @@ export const SharedValue = React.createContext<unknown>(undefined)
17
17
  type Primitive = number | string | null | undefined | boolean
18
18
  type Functs<T> = (arg: T & { rnCSS?: string; shared: unknown }) => Primitive
19
19
  type OptionalProps = {
20
- rnCSS?: string;
20
+ rnCSS?: `${string};`;
21
21
  onMouseEnter?: (event: MouseEvent) => void;
22
22
  onMouseLeave?: (event: MouseEvent) => void;
23
23
  onLayout?: (event: LayoutChangeEvent) => void