@vitus-labs/attrs 2.6.1 → 2.7.0
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/lib/index.js +16 -15
- package/package.json +10 -5
package/lib/index.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { compose, hoistNonReactStatics, isEmpty, omit, pick, useStableValue } from "@vitus-labs/core";
|
|
2
|
-
import { useImperativeHandle, useMemo, useRef } from "react";
|
|
2
|
+
import { memo, useImperativeHandle, useMemo, useRef } from "react";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
|
|
5
5
|
//#region src/utils/attrs.ts
|
|
6
|
-
const removeUndefinedProps = (props) =>
|
|
7
|
-
const currentValue = props[key];
|
|
8
|
-
if (currentValue !== void 0) acc[key] = currentValue;
|
|
9
|
-
return acc;
|
|
10
|
-
}, {});
|
|
11
|
-
const calculateChainOptions = (options) => (args) => {
|
|
6
|
+
const removeUndefinedProps = (props) => {
|
|
12
7
|
const result = {};
|
|
13
|
-
|
|
8
|
+
for (const key in props) {
|
|
9
|
+
const value = props[key];
|
|
10
|
+
if (value !== void 0) result[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
};
|
|
14
|
+
const calculateChainOptions = (options) => (args) => {
|
|
15
|
+
if (!options || isEmpty(options)) return {};
|
|
14
16
|
return options.reduce((acc, item) => Object.assign(acc, item(...args)), {});
|
|
15
17
|
};
|
|
16
18
|
|
|
@@ -76,8 +78,8 @@ const createAttrsHOC = ({ attrs, priorityAttrs }) => {
|
|
|
76
78
|
*/
|
|
77
79
|
const useAttrsStyleRef = ({ $attrsRef, ref }) => {
|
|
78
80
|
const internalRef = useRef(null);
|
|
79
|
-
useImperativeHandle($attrsRef, () => internalRef.current);
|
|
80
|
-
useImperativeHandle(ref, () => internalRef.current);
|
|
81
|
+
useImperativeHandle($attrsRef, () => internalRef.current, []);
|
|
82
|
+
useImperativeHandle(ref, () => internalRef.current, []);
|
|
81
83
|
return internalRef;
|
|
82
84
|
};
|
|
83
85
|
|
|
@@ -133,25 +135,24 @@ const cloneAndEnhance = (defaultOpts, opts) => attrsComponent({
|
|
|
133
135
|
const attrsComponent = (options) => {
|
|
134
136
|
const componentName = options.name ?? options.component.displayName ?? options.component.name;
|
|
135
137
|
const RenderComponent = options.component;
|
|
138
|
+
const filterAttrsSet = !!options.filterAttrs && options.filterAttrs.length > 0 ? new Set(options.filterAttrs) : void 0;
|
|
136
139
|
const hocsFuncs = [createAttrsHOC(options), ...calculateHocsFuncs(options.compose)];
|
|
137
140
|
const EnhancedComponent = ({ $attrsRef, ref, ...props }) => {
|
|
138
141
|
const internalRef = useAttrsStyleRef({
|
|
139
142
|
$attrsRef,
|
|
140
143
|
ref
|
|
141
144
|
});
|
|
142
|
-
const
|
|
143
|
-
const needsFiltering = options.filterAttrs && options.filterAttrs.length > 0;
|
|
144
|
-
const baseProps = needsRef ? {
|
|
145
|
+
const baseProps = ref ?? $attrsRef ? {
|
|
145
146
|
...props,
|
|
146
147
|
ref: internalRef
|
|
147
148
|
} : props;
|
|
148
|
-
const filteredProps =
|
|
149
|
+
const filteredProps = filterAttrsSet ? omit(baseProps, filterAttrsSet) : baseProps;
|
|
149
150
|
return /* @__PURE__ */ jsx(RenderComponent, { ...process.env.NODE_ENV !== "production" ? {
|
|
150
151
|
...filteredProps,
|
|
151
152
|
"data-attrs": componentName
|
|
152
153
|
} : filteredProps });
|
|
153
154
|
};
|
|
154
|
-
const AttrsComponent = compose(...hocsFuncs)(EnhancedComponent);
|
|
155
|
+
const AttrsComponent = compose(...hocsFuncs)(memo(EnhancedComponent));
|
|
155
156
|
AttrsComponent.IS_ATTRS = true;
|
|
156
157
|
AttrsComponent.displayName = componentName;
|
|
157
158
|
AttrsComponent.meta = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitus-labs/attrs",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Vit Bokisch <vit@bokisch.cz>",
|
|
6
6
|
"maintainers": [
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"prepublish": "bun run build",
|
|
51
51
|
"build": "bun run vl_rolldown_build",
|
|
52
52
|
"build:watch": "bun run vl_rolldown_build-watch",
|
|
53
|
+
"bench": "bun benchmarks/render-bench.tsx",
|
|
53
54
|
"lint": "biome check src/",
|
|
54
55
|
"test": "vitest run",
|
|
55
56
|
"test:coverage": "vitest run --coverage",
|
|
@@ -58,14 +59,18 @@
|
|
|
58
59
|
"typecheck": "tsc --noEmit"
|
|
59
60
|
},
|
|
60
61
|
"peerDependencies": {
|
|
61
|
-
"@vitus-labs/core": "^2.
|
|
62
|
+
"@vitus-labs/core": "^2.7.0",
|
|
62
63
|
"react": ">= 19"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
66
|
+
"@vitus-labs/connector-styler": "workspace:*",
|
|
65
67
|
"@vitus-labs/core": "workspace:*",
|
|
66
68
|
"@vitus-labs/elements": "workspace:*",
|
|
67
|
-
"@vitus-labs/
|
|
68
|
-
"@vitus-labs/tools-
|
|
69
|
-
"@vitus-labs/tools-
|
|
69
|
+
"@vitus-labs/styler": "workspace:*",
|
|
70
|
+
"@vitus-labs/tools-rolldown": "2.5.0",
|
|
71
|
+
"@vitus-labs/tools-storybook": "2.5.0",
|
|
72
|
+
"@vitus-labs/tools-typescript": "2.5.0",
|
|
73
|
+
"jsdom": "^29.1.1",
|
|
74
|
+
"tinybench": "^6.0.1"
|
|
70
75
|
}
|
|
71
76
|
}
|