@vitus-labs/attrs 2.6.2 → 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 +8 -10
- package/package.json +10 -5
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
|
|
@@ -12,8 +12,7 @@ const removeUndefinedProps = (props) => {
|
|
|
12
12
|
return result;
|
|
13
13
|
};
|
|
14
14
|
const calculateChainOptions = (options) => (args) => {
|
|
15
|
-
|
|
16
|
-
if (!options || isEmpty(options)) return result;
|
|
15
|
+
if (!options || isEmpty(options)) return {};
|
|
17
16
|
return options.reduce((acc, item) => Object.assign(acc, item(...args)), {});
|
|
18
17
|
};
|
|
19
18
|
|
|
@@ -79,8 +78,8 @@ const createAttrsHOC = ({ attrs, priorityAttrs }) => {
|
|
|
79
78
|
*/
|
|
80
79
|
const useAttrsStyleRef = ({ $attrsRef, ref }) => {
|
|
81
80
|
const internalRef = useRef(null);
|
|
82
|
-
useImperativeHandle($attrsRef, () => internalRef.current);
|
|
83
|
-
useImperativeHandle(ref, () => internalRef.current);
|
|
81
|
+
useImperativeHandle($attrsRef, () => internalRef.current, []);
|
|
82
|
+
useImperativeHandle(ref, () => internalRef.current, []);
|
|
84
83
|
return internalRef;
|
|
85
84
|
};
|
|
86
85
|
|
|
@@ -136,25 +135,24 @@ const cloneAndEnhance = (defaultOpts, opts) => attrsComponent({
|
|
|
136
135
|
const attrsComponent = (options) => {
|
|
137
136
|
const componentName = options.name ?? options.component.displayName ?? options.component.name;
|
|
138
137
|
const RenderComponent = options.component;
|
|
138
|
+
const filterAttrsSet = !!options.filterAttrs && options.filterAttrs.length > 0 ? new Set(options.filterAttrs) : void 0;
|
|
139
139
|
const hocsFuncs = [createAttrsHOC(options), ...calculateHocsFuncs(options.compose)];
|
|
140
140
|
const EnhancedComponent = ({ $attrsRef, ref, ...props }) => {
|
|
141
141
|
const internalRef = useAttrsStyleRef({
|
|
142
142
|
$attrsRef,
|
|
143
143
|
ref
|
|
144
144
|
});
|
|
145
|
-
const
|
|
146
|
-
const needsFiltering = options.filterAttrs && options.filterAttrs.length > 0;
|
|
147
|
-
const baseProps = needsRef ? {
|
|
145
|
+
const baseProps = ref ?? $attrsRef ? {
|
|
148
146
|
...props,
|
|
149
147
|
ref: internalRef
|
|
150
148
|
} : props;
|
|
151
|
-
const filteredProps =
|
|
149
|
+
const filteredProps = filterAttrsSet ? omit(baseProps, filterAttrsSet) : baseProps;
|
|
152
150
|
return /* @__PURE__ */ jsx(RenderComponent, { ...process.env.NODE_ENV !== "production" ? {
|
|
153
151
|
...filteredProps,
|
|
154
152
|
"data-attrs": componentName
|
|
155
153
|
} : filteredProps });
|
|
156
154
|
};
|
|
157
|
-
const AttrsComponent = compose(...hocsFuncs)(EnhancedComponent);
|
|
155
|
+
const AttrsComponent = compose(...hocsFuncs)(memo(EnhancedComponent));
|
|
158
156
|
AttrsComponent.IS_ATTRS = true;
|
|
159
157
|
AttrsComponent.displayName = componentName;
|
|
160
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
|
}
|