react-native-twc 1.0.3 → 1.1.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/index.js +23 -7
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { clsx } from "clsx";
|
|
3
3
|
import React from "react";
|
|
4
4
|
import { twMerge } from "tailwind-merge";
|
|
5
|
-
import {
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
function filterProps(props, shouldForwardProp) {
|
|
7
7
|
const filteredProps = {};
|
|
8
8
|
const keys = Object.keys(props);
|
|
@@ -19,23 +19,39 @@ var createTwc = (config = {}) => {
|
|
|
19
19
|
const defaultShouldForwardProp = config.shouldForwardProp || ((prop) => prop[0] !== "$");
|
|
20
20
|
const wrap = (Component) => {
|
|
21
21
|
const createTemplate = (attrs, shouldForwardProp = defaultShouldForwardProp) => {
|
|
22
|
+
const componentCache = new Map;
|
|
22
23
|
const template = (stringsOrFn, ...values) => {
|
|
23
24
|
const isClassFn = typeof stringsOrFn === "function";
|
|
24
|
-
const
|
|
25
|
+
const cacheKey = isClassFn ? stringsOrFn.toString() : String.raw({ raw: stringsOrFn }, ...values);
|
|
26
|
+
if (componentCache.has(cacheKey)) {
|
|
27
|
+
return componentCache.get(cacheKey);
|
|
28
|
+
}
|
|
29
|
+
const tplClassName = !isClassFn ? cacheKey : undefined;
|
|
30
|
+
const hasAttrs = attrs !== undefined;
|
|
31
|
+
const isAttrsFunction = typeof attrs === "function";
|
|
32
|
+
const staticAttrs = !isAttrsFunction && hasAttrs ? attrs : undefined;
|
|
25
33
|
const ForwardedComponent = React.forwardRef((p, ref) => {
|
|
26
34
|
const { className: classNameProp, ...rest } = p;
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
let finalProps;
|
|
36
|
+
if (!hasAttrs) {
|
|
37
|
+
finalProps = filterProps(rest, shouldForwardProp);
|
|
38
|
+
} else if (isAttrsFunction) {
|
|
39
|
+
const resolvedAttrs = attrs(p);
|
|
40
|
+
finalProps = filterProps({ ...resolvedAttrs, ...rest }, shouldForwardProp);
|
|
41
|
+
} else {
|
|
42
|
+
finalProps = filterProps({ ...staticAttrs, ...rest }, shouldForwardProp);
|
|
43
|
+
}
|
|
29
44
|
const baseClassName = isClassFn ? stringsOrFn(p) : tplClassName;
|
|
30
45
|
const finalClassName = typeof baseClassName === "function" ? (renderProps) => compose(baseClassName(renderProps), typeof classNameProp === "function" ? classNameProp(renderProps) : classNameProp) : compose(baseClassName, classNameProp);
|
|
31
46
|
const Comp = Component;
|
|
32
|
-
return /* @__PURE__ */
|
|
47
|
+
return /* @__PURE__ */ jsx(Comp, {
|
|
33
48
|
ref,
|
|
34
49
|
className: finalClassName,
|
|
35
|
-
...
|
|
36
|
-
}
|
|
50
|
+
...finalProps
|
|
51
|
+
});
|
|
37
52
|
});
|
|
38
53
|
ForwardedComponent.displayName = `twc(${Component.displayName || Component.name || "Component"})`;
|
|
54
|
+
componentCache.set(cacheKey, ForwardedComponent);
|
|
39
55
|
return ForwardedComponent;
|
|
40
56
|
};
|
|
41
57
|
template.transientProps = (fnOrArray) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-twc",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Create reusable React Native + NativeWind components with Tailwind CSS syntax.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"test": "bun test",
|
|
19
19
|
"build": "rm -rf dist && bun run build:js && bun run build:dts",
|
|
20
|
-
"build:js": "bun build src/index.tsx --outdir dist --format esm --external react --external react-native --external clsx --external tailwind-merge",
|
|
20
|
+
"build:js": "NODE_ENV=production bun build src/index.tsx --outdir dist --format esm --external react --external react-native --external clsx --external tailwind-merge",
|
|
21
21
|
"build:dts": "tsc -p tsconfig.build.json",
|
|
22
22
|
"check-types": "tsc --noEmit",
|
|
23
|
-
"prepublishOnly": "bun run build"
|
|
23
|
+
"prepublishOnly": "bun run build && bun test"
|
|
24
24
|
},
|
|
25
25
|
"keywords": [
|
|
26
26
|
"react-native",
|