@rc-component/util 1.2.0 → 1.2.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.
@@ -83,8 +83,11 @@ export function injectCSS(css, option = {}) {
83
83
  return styleNode;
84
84
  }
85
85
  function findExistNode(key, option = {}) {
86
- const container = getContainer(option);
87
- return (option.styles || findStyles(container)).find(node => node.getAttribute(getMark(option)) === key);
86
+ let {
87
+ styles
88
+ } = option;
89
+ styles ||= findStyles(getContainer(option));
90
+ return styles.find(node => node.getAttribute(getMark(option)) === key);
88
91
  }
89
92
  export function removeCSS(key, option = {}) {
90
93
  const existNode = findExistNode(key, option);
package/es/ref.js CHANGED
@@ -1,7 +1,8 @@
1
- import { isValidElement } from 'react';
1
+ import { isValidElement, version } from 'react';
2
2
  import { ForwardRef, isMemo } from 'react-is';
3
3
  import useMemo from "./hooks/useMemo";
4
4
  import isFragment from "./React/isFragment";
5
+ const ReactMajorVersion = Number(version.split('.')[0]);
5
6
  export const fillRef = (ref, node) => {
6
7
  if (typeof ref === 'function') {
7
8
  ref(node);
@@ -35,7 +36,7 @@ export const supportRef = nodeOrComponent => {
35
36
  }
36
37
 
37
38
  // React 19 no need `forwardRef` anymore. So just pass if is a React element.
38
- if (isReactElement(nodeOrComponent) && nodeOrComponent.props.propertyIsEnumerable('ref')) {
39
+ if (isReactElement(nodeOrComponent) && ReactMajorVersion >= 19) {
39
40
  return true;
40
41
  }
41
42
  const type = isMemo(nodeOrComponent) ? nodeOrComponent.type.type : nodeOrComponent.type;
@@ -93,8 +93,11 @@ function injectCSS(css, option = {}) {
93
93
  return styleNode;
94
94
  }
95
95
  function findExistNode(key, option = {}) {
96
- const container = getContainer(option);
97
- return (option.styles || findStyles(container)).find(node => node.getAttribute(getMark(option)) === key);
96
+ let {
97
+ styles
98
+ } = option;
99
+ styles ||= findStyles(getContainer(option));
100
+ return styles.find(node => node.getAttribute(getMark(option)) === key);
98
101
  }
99
102
  function removeCSS(key, option = {}) {
100
103
  const existNode = findExistNode(key, option);
package/lib/ref.js CHANGED
@@ -9,6 +9,7 @@ var _reactIs = require("react-is");
9
9
  var _useMemo = _interopRequireDefault(require("./hooks/useMemo"));
10
10
  var _isFragment = _interopRequireDefault(require("./React/isFragment"));
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ const ReactMajorVersion = Number(_react.version.split('.')[0]);
12
13
  const fillRef = (ref, node) => {
13
14
  if (typeof ref === 'function') {
14
15
  ref(node);
@@ -45,7 +46,7 @@ const supportRef = nodeOrComponent => {
45
46
  }
46
47
 
47
48
  // React 19 no need `forwardRef` anymore. So just pass if is a React element.
48
- if (isReactElement(nodeOrComponent) && nodeOrComponent.props.propertyIsEnumerable('ref')) {
49
+ if (isReactElement(nodeOrComponent) && ReactMajorVersion >= 19) {
49
50
  return true;
50
51
  }
51
52
  const type = (0, _reactIs.isMemo)(nodeOrComponent) ? nodeOrComponent.type.type : nodeOrComponent.type;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/util",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Common Utils For React Component",
5
5
  "keywords": [
6
6
  "react",
@@ -27,7 +27,7 @@
27
27
  "coverage": "npm test -- --coverage",
28
28
  "lint": "eslint src/ --ext .tsx,.ts & eslint tests/ --ext .tsx,.ts",
29
29
  "prepare": "husky install",
30
- "prepublishOnly": "npm run compile && np --yolo --no-publish",
30
+ "prepublishOnly": "npm run compile && rc-np",
31
31
  "start": "dumi dev",
32
32
  "test": "rc-test"
33
33
  },
@@ -42,6 +42,7 @@
42
42
  },
43
43
  "devDependencies": {
44
44
  "@rc-component/father-plugin": "^2.0.1",
45
+ "@rc-component/np": "^1.0.3",
45
46
  "@testing-library/react": "^16.0.0",
46
47
  "@types/jest": "^29.4.0",
47
48
  "@types/node": "^22.5.5",
@@ -60,7 +61,6 @@
60
61
  "glob": "^9.2.1",
61
62
  "husky": "^9.1.6",
62
63
  "lint-staged": "^15.1.0",
63
- "np": "^10.0.2",
64
64
  "prettier": "^3.3.2",
65
65
  "rc-test": "^7.0.14",
66
66
  "react": "^18.0.0",