@instructure/ui-react-utils 11.6.0 → 11.6.1-snapshot-129
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/CHANGELOG.md +38 -296
- package/es/DeterministicIdContext/index.js +2 -1
- package/es/DeterministicIdContext/useDeterministicId.js +60 -0
- package/es/index.js +1 -1
- package/lib/DeterministicIdContext/index.js +8 -1
- package/lib/DeterministicIdContext/useDeterministicId.js +66 -0
- package/lib/index.js +6 -0
- package/package.json +8 -7
- package/src/DeterministicIdContext/index.ts +1 -0
- package/src/DeterministicIdContext/useDeterministicId.tsx +65 -0
- package/src/index.ts +2 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/DeterministicIdContext/index.d.ts +1 -0
- package/types/DeterministicIdContext/index.d.ts.map +1 -1
- package/types/DeterministicIdContext/useDeterministicId.d.ts +29 -0
- package/types/DeterministicIdContext/useDeterministicId.d.ts.map +1 -0
- package/types/index.d.ts +1 -1
- package/types/index.d.ts.map +1 -1
package/es/index.js
CHANGED
|
@@ -33,4 +33,4 @@ export { passthroughProps } from "./passthroughProps.js";
|
|
|
33
33
|
export { pickProps } from "./pickProps.js";
|
|
34
34
|
export { safeCloneElement } from "./safeCloneElement.js";
|
|
35
35
|
export { windowMessageListener } from "./windowMessageListener.js";
|
|
36
|
-
export { DeterministicIdContext, DeterministicIdContextProvider, withDeterministicId } from "./DeterministicIdContext/index.js";
|
|
36
|
+
export { DeterministicIdContext, DeterministicIdContextProvider, withDeterministicId, useDeterministicId } from "./DeterministicIdContext/index.js";
|
|
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "DeterministicIdContextProvider", {
|
|
|
15
15
|
return _DeterministicIdContextProvider.DeterministicIdContextProvider;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "useDeterministicId", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _useDeterministicId.useDeterministicId;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
Object.defineProperty(exports, "withDeterministicId", {
|
|
19
25
|
enumerable: true,
|
|
20
26
|
get: function () {
|
|
@@ -23,4 +29,5 @@ Object.defineProperty(exports, "withDeterministicId", {
|
|
|
23
29
|
});
|
|
24
30
|
var _DeterministicIdContextProvider = require("./DeterministicIdContextProvider");
|
|
25
31
|
var _DeterministicIdContext = require("./DeterministicIdContext");
|
|
26
|
-
var _withDeterministicId = require("./withDeterministicId");
|
|
32
|
+
var _withDeterministicId = require("./withDeterministicId");
|
|
33
|
+
var _useDeterministicId = require("./useDeterministicId");
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
exports.useDeterministicId = useDeterministicId;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _generateId = require("@instructure/ui-utils/lib/generateId.js");
|
|
10
|
+
var _DeterministicIdContext = require("./DeterministicIdContext");
|
|
11
|
+
/*
|
|
12
|
+
* The MIT License (MIT)
|
|
13
|
+
*
|
|
14
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
15
|
+
*
|
|
16
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
17
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
18
|
+
* in the Software without restriction, including without limitation the rights
|
|
19
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
20
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
21
|
+
* furnished to do so, subject to the following conditions:
|
|
22
|
+
*
|
|
23
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
24
|
+
* copies or substantial portions of the Software.
|
|
25
|
+
*
|
|
26
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
27
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
28
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
29
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
30
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
31
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
32
|
+
* SOFTWARE.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A React hook that provides deterministic ID generation for functional components.
|
|
37
|
+
*
|
|
38
|
+
* This hook is the functional component equivalent of the `withDeterministicId` decorator.
|
|
39
|
+
* It uses the `DeterministicIdContext` which is needed for deterministic id generation.
|
|
40
|
+
*
|
|
41
|
+
* The context is there for the users to pass an `instanceCounterMap` Map which is then used
|
|
42
|
+
* in the child components to deterministically create ids for them based on the `instanceCounterMap`.
|
|
43
|
+
* Read more about it here: [SSR guide](https://instructure.design/#server-side-rendering)
|
|
44
|
+
*
|
|
45
|
+
* @param componentName - Optional component name to use as the ID prefix.
|
|
46
|
+
* @returns A function that generates deterministic IDs. The function accepts an optional instanceName parameter.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* const MyComponent = () => {
|
|
51
|
+
* const [deterministicId, setDeterministicId] = useState()
|
|
52
|
+
* const getId = useDeterministicId('MyComponent')
|
|
53
|
+
* useEffect(() => {
|
|
54
|
+
* setDeterministicId(getId())
|
|
55
|
+
* }, [])
|
|
56
|
+
* return <div id={deterministicId}>Content</div>
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
function useDeterministicId(componentName) {
|
|
61
|
+
const instanceCounterMap = (0, _react.useContext)(_DeterministicIdContext.DeterministicIdContext);
|
|
62
|
+
return (instanceName = componentName) => {
|
|
63
|
+
return (0, _generateId.generateId)(instanceName, instanceCounterMap);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
var _default = exports.default = useDeterministicId;
|
package/lib/index.js
CHANGED
|
@@ -75,6 +75,12 @@ Object.defineProperty(exports, "safeCloneElement", {
|
|
|
75
75
|
return _safeCloneElement.safeCloneElement;
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
|
+
Object.defineProperty(exports, "useDeterministicId", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return _DeterministicIdContext.useDeterministicId;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
78
84
|
Object.defineProperty(exports, "windowMessageListener", {
|
|
79
85
|
enumerable: true,
|
|
80
86
|
get: function () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-react-utils",
|
|
3
|
-
"version": "11.6.
|
|
3
|
+
"version": "11.6.1-snapshot-129",
|
|
4
4
|
"description": "A React utility library made by Instructure Inc.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -17,17 +17,17 @@
|
|
|
17
17
|
"@babel/runtime": "^7.27.6",
|
|
18
18
|
"@emotion/is-prop-valid": "^1.3.1",
|
|
19
19
|
"hoist-non-react-statics": "^3.3.2",
|
|
20
|
-
"@instructure/
|
|
21
|
-
"@instructure/
|
|
22
|
-
"@instructure/
|
|
23
|
-
"@instructure/ui-
|
|
24
|
-
"@instructure/ui-utils": "11.6.
|
|
20
|
+
"@instructure/console": "11.6.1-snapshot-129",
|
|
21
|
+
"@instructure/shared-types": "11.6.1-snapshot-129",
|
|
22
|
+
"@instructure/ui-decorator": "11.6.1-snapshot-129",
|
|
23
|
+
"@instructure/ui-utils": "11.6.1-snapshot-129",
|
|
24
|
+
"@instructure/ui-dom-utils": "11.6.1-snapshot-129"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@testing-library/jest-dom": "^6.6.3",
|
|
28
28
|
"@testing-library/react": "15.0.7",
|
|
29
29
|
"vitest": "^3.2.2",
|
|
30
|
-
"@instructure/ui-babel-preset": "11.6.
|
|
30
|
+
"@instructure/ui-babel-preset": "11.6.1-snapshot-129"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"react": ">=18 <=19",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"sideEffects": false,
|
|
40
40
|
"exports": {
|
|
41
41
|
".": {
|
|
42
|
+
"src": "./src/index.ts",
|
|
42
43
|
"types": "./types/index.d.ts",
|
|
43
44
|
"import": "./es/index.js",
|
|
44
45
|
"require": "./lib/index.js",
|
|
@@ -25,5 +25,6 @@
|
|
|
25
25
|
export { DeterministicIdContextProvider } from './DeterministicIdContextProvider'
|
|
26
26
|
export { DeterministicIdContext } from './DeterministicIdContext'
|
|
27
27
|
export { withDeterministicId } from './withDeterministicId'
|
|
28
|
+
export { useDeterministicId } from './useDeterministicId'
|
|
28
29
|
export type { DeterministicIdProviderValue } from './DeterministicIdContextProvider'
|
|
29
30
|
export type { WithDeterministicIdProps } from './withDeterministicId'
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { useContext } from 'react'
|
|
26
|
+
import { generateId } from '@instructure/ui-utils'
|
|
27
|
+
import { DeterministicIdContext } from './DeterministicIdContext'
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A React hook that provides deterministic ID generation for functional components.
|
|
31
|
+
*
|
|
32
|
+
* This hook is the functional component equivalent of the `withDeterministicId` decorator.
|
|
33
|
+
* It uses the `DeterministicIdContext` which is needed for deterministic id generation.
|
|
34
|
+
*
|
|
35
|
+
* The context is there for the users to pass an `instanceCounterMap` Map which is then used
|
|
36
|
+
* in the child components to deterministically create ids for them based on the `instanceCounterMap`.
|
|
37
|
+
* Read more about it here: [SSR guide](https://instructure.design/#server-side-rendering)
|
|
38
|
+
*
|
|
39
|
+
* @param componentName - Optional component name to use as the ID prefix.
|
|
40
|
+
* @returns A function that generates deterministic IDs. The function accepts an optional instanceName parameter.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```tsx
|
|
44
|
+
* const MyComponent = () => {
|
|
45
|
+
* const [deterministicId, setDeterministicId] = useState()
|
|
46
|
+
* const getId = useDeterministicId('MyComponent')
|
|
47
|
+
* useEffect(() => {
|
|
48
|
+
* setDeterministicId(getId())
|
|
49
|
+
* }, [])
|
|
50
|
+
* return <div id={deterministicId}>Content</div>
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
function useDeterministicId(
|
|
55
|
+
componentName: string
|
|
56
|
+
): (instanceName?: string) => string {
|
|
57
|
+
const instanceCounterMap = useContext(DeterministicIdContext)
|
|
58
|
+
|
|
59
|
+
return (instanceName = componentName) => {
|
|
60
|
+
return generateId(instanceName, instanceCounterMap)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default useDeterministicId
|
|
65
|
+
export { useDeterministicId }
|
package/src/index.ts
CHANGED
|
@@ -37,7 +37,8 @@ export { windowMessageListener } from './windowMessageListener'
|
|
|
37
37
|
export {
|
|
38
38
|
DeterministicIdContext,
|
|
39
39
|
DeterministicIdContextProvider,
|
|
40
|
-
withDeterministicId
|
|
40
|
+
withDeterministicId,
|
|
41
|
+
useDeterministicId
|
|
41
42
|
} from './DeterministicIdContext'
|
|
42
43
|
|
|
43
44
|
export type { GetInteractionOptions } from './getInteraction'
|