@rc-component/util 1.8.0 → 1.8.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/es/hooks/useId.d.ts +2 -1
- package/es/hooks/useId.js +4 -1
- package/lib/hooks/useId.d.ts +2 -1
- package/lib/hooks/useId.js +4 -1
- package/package.json +1 -1
package/es/hooks/useId.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
/** @private Note only worked in develop env. Not work in production. */
|
|
2
3
|
export declare function resetUuid(): void;
|
|
3
4
|
/**
|
|
@@ -7,6 +8,6 @@ export declare function resetUuid(): void;
|
|
|
7
8
|
* @param key - The key from React element, may contain spaces or invalid characters
|
|
8
9
|
* @returns A valid HTML id string
|
|
9
10
|
*/
|
|
10
|
-
export declare function getId(prefix: string, key:
|
|
11
|
+
export declare function getId(prefix: string, key: React.Key): string;
|
|
11
12
|
declare const _default: (id?: string) => string;
|
|
12
13
|
export default _default;
|
package/es/hooks/useId.js
CHANGED
|
@@ -23,9 +23,12 @@ export function resetUuid() {
|
|
|
23
23
|
* @returns A valid HTML id string
|
|
24
24
|
*/
|
|
25
25
|
export function getId(prefix, key) {
|
|
26
|
+
// React.Key can be string | number, convert to string first
|
|
27
|
+
const keyStr = String(key);
|
|
28
|
+
|
|
26
29
|
// Valid id characters: letters, digits, hyphen, underscore, colon, period
|
|
27
30
|
// Replace all invalid characters (including spaces) with hyphens to preserve length
|
|
28
|
-
const sanitizedKey =
|
|
31
|
+
const sanitizedKey = keyStr.replace(/[^a-zA-Z0-9_.:-]/g, '-');
|
|
29
32
|
return `${prefix}-${sanitizedKey}`;
|
|
30
33
|
}
|
|
31
34
|
const useOriginId = getUseId();
|
package/lib/hooks/useId.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
/** @private Note only worked in develop env. Not work in production. */
|
|
2
3
|
export declare function resetUuid(): void;
|
|
3
4
|
/**
|
|
@@ -7,6 +8,6 @@ export declare function resetUuid(): void;
|
|
|
7
8
|
* @param key - The key from React element, may contain spaces or invalid characters
|
|
8
9
|
* @returns A valid HTML id string
|
|
9
10
|
*/
|
|
10
|
-
export declare function getId(prefix: string, key:
|
|
11
|
+
export declare function getId(prefix: string, key: React.Key): string;
|
|
11
12
|
declare const _default: (id?: string) => string;
|
|
12
13
|
export default _default;
|
package/lib/hooks/useId.js
CHANGED
|
@@ -33,9 +33,12 @@ function resetUuid() {
|
|
|
33
33
|
* @returns A valid HTML id string
|
|
34
34
|
*/
|
|
35
35
|
function getId(prefix, key) {
|
|
36
|
+
// React.Key can be string | number, convert to string first
|
|
37
|
+
const keyStr = String(key);
|
|
38
|
+
|
|
36
39
|
// Valid id characters: letters, digits, hyphen, underscore, colon, period
|
|
37
40
|
// Replace all invalid characters (including spaces) with hyphens to preserve length
|
|
38
|
-
const sanitizedKey =
|
|
41
|
+
const sanitizedKey = keyStr.replace(/[^a-zA-Z0-9_.:-]/g, '-');
|
|
39
42
|
return `${prefix}-${sanitizedKey}`;
|
|
40
43
|
}
|
|
41
44
|
const useOriginId = getUseId();
|