@monkvision/common 4.0.11 → 4.0.13
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.
|
@@ -24,6 +24,36 @@ specify to it which language you want it to use. The following languages are sup
|
|
|
24
24
|
- Dutch
|
|
25
25
|
|
|
26
26
|
# i18n Utilities
|
|
27
|
+
## i18nWrap wrapper
|
|
28
|
+
### Description
|
|
29
|
+
This wrapped is used by internal monk SDK to wrap the component with I18nextProvider.
|
|
30
|
+
|
|
31
|
+
### Example of usage
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import i18n from '@monkvision/common';
|
|
35
|
+
import { i18nMyComponent } from './i18n';
|
|
36
|
+
|
|
37
|
+
const MyComponent = i18nWrap(function MyComponent(){
|
|
38
|
+
return <></>
|
|
39
|
+
}, i18nMyComponent)
|
|
40
|
+
/// in i18n.ts
|
|
41
|
+
import { i18nCreateSDKInstance } from '@monkvision/common';
|
|
42
|
+
import en from './translations/en.json';
|
|
43
|
+
import fr from './translations/fr.json';
|
|
44
|
+
import de from './translations/de.json';
|
|
45
|
+
import nl from './translations/nl.json';
|
|
46
|
+
|
|
47
|
+
const i18nMyComponent = i18nCreateSDKInstance({
|
|
48
|
+
resources: {
|
|
49
|
+
en: { translation: en },
|
|
50
|
+
fr: { translation: fr },
|
|
51
|
+
de: { translation: de },
|
|
52
|
+
nl: { translation: nl },
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
```
|
|
56
|
+
|
|
27
57
|
## useI18nSync hook
|
|
28
58
|
### Description
|
|
29
59
|
This hook is used mostly by MonkJs packages internally to synchronize their own i18n instance with the language param
|
|
@@ -31,7 +61,7 @@ or prop that they are provided.
|
|
|
31
61
|
|
|
32
62
|
### Example of usage
|
|
33
63
|
|
|
34
|
-
```
|
|
64
|
+
```ts
|
|
35
65
|
import i18n from 'i18next';
|
|
36
66
|
import { useI18nSync } from '@monkvision/common';
|
|
37
67
|
|
|
@@ -44,6 +44,11 @@ function getSights(config, vehicleType, steeringWheel) {
|
|
|
44
44
|
return sights_1.sights[id];
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
|
+
function getAvailableVehicleTypes(config) {
|
|
48
|
+
return (config.enableSteeringWheelPosition
|
|
49
|
+
? Object.keys(config.sights.left)
|
|
50
|
+
: Object.keys(config.sights));
|
|
51
|
+
}
|
|
47
52
|
/**
|
|
48
53
|
* A React context provider that declares the state for the common parameters used by Monk applications. The parameters
|
|
49
54
|
* are described in the `MonkAppState` interface. Using options available in the App config (`config` prop), this
|
|
@@ -60,7 +65,8 @@ function MonkAppStateProvider(_a) {
|
|
|
60
65
|
var _c = (0, react_1.useState)(null), inspectionId = _c[0], setInspectionId = _c[1];
|
|
61
66
|
var _d = (0, react_1.useState)(null), vehicleType = _d[0], setVehicleType = _d[1];
|
|
62
67
|
var _e = (0, react_1.useState)(null), steeringWheel = _e[0], setSteeringWheel = _e[1];
|
|
63
|
-
var
|
|
68
|
+
var availableVehicleTypes = (0, react_1.useMemo)(function () { return getAvailableVehicleTypes(config); }, [config]);
|
|
69
|
+
var monkSearchParams = (0, searchParams_1.useMonkSearchParams)({ availableVehicleTypes: availableVehicleTypes });
|
|
64
70
|
(0, monitoring_1.useAppStateMonitoring)({ authToken: authToken, inspectionId: inspectionId, vehicleType: vehicleType, steeringWheel: steeringWheel });
|
|
65
71
|
(0, analytics_1.useAppStateAnalytics)({ inspectionId: inspectionId });
|
|
66
72
|
(0, react_1.useEffect)(function () {
|
|
@@ -50,11 +50,22 @@ export type MonkSearchParamsGetter = {
|
|
|
50
50
|
(param: MonkSearchParam.STEERING_WHEEL): SteeringWheelPosition | null;
|
|
51
51
|
(param: MonkSearchParam.LANGUAGE): MonkLanguage | null;
|
|
52
52
|
};
|
|
53
|
+
/**
|
|
54
|
+
* Options accepted by the useMonkSearchParams hook.
|
|
55
|
+
*/
|
|
56
|
+
export interface UseMonkSearchParamsOptions {
|
|
57
|
+
/**
|
|
58
|
+
* The list of available vehicle types to allow.
|
|
59
|
+
*
|
|
60
|
+
* @default Object.values(VehicleType)
|
|
61
|
+
*/
|
|
62
|
+
availableVehicleTypes?: VehicleType[];
|
|
63
|
+
}
|
|
53
64
|
/**
|
|
54
65
|
* Custom hook used to return a getter function used to fetch the value of different MonkSearchParams.
|
|
55
66
|
*
|
|
56
67
|
* @see MonkSearchParam
|
|
57
68
|
*/
|
|
58
|
-
export declare function useMonkSearchParams(): {
|
|
69
|
+
export declare function useMonkSearchParams({ availableVehicleTypes }?: UseMonkSearchParamsOptions): {
|
|
59
70
|
get: MonkSearchParamsGetter;
|
|
60
71
|
};
|
package/lib/apps/searchParams.js
CHANGED
|
@@ -56,7 +56,8 @@ function validateParamValue(value, validValues) {
|
|
|
56
56
|
*
|
|
57
57
|
* @see MonkSearchParam
|
|
58
58
|
*/
|
|
59
|
-
function useMonkSearchParams() {
|
|
59
|
+
function useMonkSearchParams(_a) {
|
|
60
|
+
var _b = _a === void 0 ? {} : _a, availableVehicleTypes = _b.availableVehicleTypes;
|
|
60
61
|
var searchParams = (0, hooks_1.useSearchParams)();
|
|
61
62
|
var get = (0, react_1.useCallback)(function (param) {
|
|
62
63
|
var value = searchParams.get(param);
|
|
@@ -66,7 +67,7 @@ function useMonkSearchParams() {
|
|
|
66
67
|
case MonkSearchParam.INSPECTION_ID:
|
|
67
68
|
return value;
|
|
68
69
|
case MonkSearchParam.VEHICLE_TYPE:
|
|
69
|
-
return validateParamValue(value, types_1.VehicleType);
|
|
70
|
+
return validateParamValue(value, availableVehicleTypes !== null && availableVehicleTypes !== void 0 ? availableVehicleTypes : types_1.VehicleType);
|
|
70
71
|
case MonkSearchParam.STEERING_WHEEL:
|
|
71
72
|
return validateParamValue(value, types_1.SteeringWheelPosition);
|
|
72
73
|
case MonkSearchParam.LANGUAGE:
|
package/lib/i18n/utils.d.ts
CHANGED
|
@@ -25,10 +25,10 @@ export interface I18NSDKOptions {
|
|
|
25
25
|
*/
|
|
26
26
|
export declare function i18nCreateSDKInstance({ resources }: I18NSDKOptions): i18n;
|
|
27
27
|
/**
|
|
28
|
-
* This function is used internally by the Monk SDK to wrap its exported components in an
|
|
29
|
-
* to the resulting component is forwarded to the wrapped component.
|
|
28
|
+
* This function is used internally by the Monk SDK to wrap its exported components in an I18nextProvider. The ref
|
|
29
|
+
* passed to the resulting component is forwarded to the wrapped component.
|
|
30
30
|
*
|
|
31
|
-
* @param Component The component to wrap in the provider.
|
|
31
|
+
* @param Component The component to wrap in the provider. It should be an functional component
|
|
32
32
|
* @param instance The i18n instance created using the `i18nCreateSDKInstance` function.
|
|
33
33
|
* @typeParam T - The type of the ref of the wrapped component.
|
|
34
34
|
* @typeParam P - The type of the props of the wrapped component.
|
package/lib/i18n/utils.js
CHANGED
|
@@ -58,17 +58,19 @@ function i18nCreateSDKInstance(_a) {
|
|
|
58
58
|
}
|
|
59
59
|
exports.i18nCreateSDKInstance = i18nCreateSDKInstance;
|
|
60
60
|
/**
|
|
61
|
-
* This function is used internally by the Monk SDK to wrap its exported components in an
|
|
62
|
-
* to the resulting component is forwarded to the wrapped component.
|
|
61
|
+
* This function is used internally by the Monk SDK to wrap its exported components in an I18nextProvider. The ref
|
|
62
|
+
* passed to the resulting component is forwarded to the wrapped component.
|
|
63
63
|
*
|
|
64
|
-
* @param Component The component to wrap in the provider.
|
|
64
|
+
* @param Component The component to wrap in the provider. It should be an functional component
|
|
65
65
|
* @param instance The i18n instance created using the `i18nCreateSDKInstance` function.
|
|
66
66
|
* @typeParam T - The type of the ref of the wrapped component.
|
|
67
67
|
* @typeParam P - The type of the props of the wrapped component.
|
|
68
68
|
* @return The Component passed in the arguments. wrapped in an I18nextProvider.
|
|
69
69
|
*/
|
|
70
70
|
function i18nWrap(Component, instance) {
|
|
71
|
-
return (0, react_1.forwardRef)(function (props, ref) {
|
|
71
|
+
return (0, react_1.forwardRef)(function I18nWrappedComponent(props, ref) {
|
|
72
|
+
return ((0, jsx_runtime_1.jsx)(react_i18next_1.I18nextProvider, __assign({ i18n: instance }, { children: (0, jsx_runtime_1.jsx)(Component, __assign({ ref: ref }, props)) })));
|
|
73
|
+
});
|
|
72
74
|
}
|
|
73
75
|
exports.i18nWrap = i18nWrap;
|
|
74
76
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monkvision/common",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.13",
|
|
4
4
|
"license": "BSD-3-Clause-Clear",
|
|
5
5
|
"packageManager": "yarn@3.2.4",
|
|
6
6
|
"description": "MonkJs common logic package",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"lint:fix": "yarn run prettier:fix && yarn run eslint:fix"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@monkvision/analytics": "4.0.
|
|
32
|
-
"@monkvision/monitoring": "4.0.
|
|
33
|
-
"@monkvision/sights": "4.0.
|
|
34
|
-
"@monkvision/types": "4.0.
|
|
31
|
+
"@monkvision/analytics": "4.0.13",
|
|
32
|
+
"@monkvision/monitoring": "4.0.13",
|
|
33
|
+
"@monkvision/sights": "4.0.13",
|
|
34
|
+
"@monkvision/types": "4.0.13",
|
|
35
35
|
"i18next": "^23.4.5",
|
|
36
36
|
"jsonwebtoken": "^9.0.2",
|
|
37
37
|
"jwt-decode": "^4.0.0",
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
"react-router-dom": "^6.22.3"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@monkvision/eslint-config-base": "4.0.
|
|
51
|
-
"@monkvision/eslint-config-typescript": "4.0.
|
|
52
|
-
"@monkvision/eslint-config-typescript-react": "4.0.
|
|
53
|
-
"@monkvision/jest-config": "4.0.
|
|
54
|
-
"@monkvision/prettier-config": "4.0.
|
|
55
|
-
"@monkvision/test-utils": "4.0.
|
|
56
|
-
"@monkvision/typescript-config": "4.0.
|
|
50
|
+
"@monkvision/eslint-config-base": "4.0.13",
|
|
51
|
+
"@monkvision/eslint-config-typescript": "4.0.13",
|
|
52
|
+
"@monkvision/eslint-config-typescript-react": "4.0.13",
|
|
53
|
+
"@monkvision/jest-config": "4.0.13",
|
|
54
|
+
"@monkvision/prettier-config": "4.0.13",
|
|
55
|
+
"@monkvision/test-utils": "4.0.13",
|
|
56
|
+
"@monkvision/typescript-config": "4.0.13",
|
|
57
57
|
"@testing-library/react": "^12.1.5",
|
|
58
58
|
"@testing-library/react-hooks": "^8.0.1",
|
|
59
59
|
"@types/jest": "^29.2.2",
|
|
@@ -96,5 +96,5 @@
|
|
|
96
96
|
"url": "https://github.com/monkvision/monkjs/issues"
|
|
97
97
|
},
|
|
98
98
|
"homepage": "https://github.com/monkvision/monkjs",
|
|
99
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "aaed1ea6df50b958aa5b3bba3765235847ad895e"
|
|
100
100
|
}
|