@openmrs/esm-react-utils 5.0.3-pre.878 → 5.0.3-pre.882
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-react-utils",
|
|
3
|
-
"version": "5.0.3-pre.
|
|
3
|
+
"version": "5.0.3-pre.882",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "React utilities for OpenMRS.",
|
|
6
6
|
"browser": "dist/openmrs-esm-react-utils.js",
|
|
@@ -56,11 +56,11 @@
|
|
|
56
56
|
"react-i18next": "11.x"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@openmrs/esm-api": "^5.0.3-pre.
|
|
60
|
-
"@openmrs/esm-config": "^5.0.3-pre.
|
|
61
|
-
"@openmrs/esm-error-handling": "^5.0.3-pre.
|
|
62
|
-
"@openmrs/esm-extensions": "^5.0.3-pre.
|
|
63
|
-
"@openmrs/esm-globals": "^5.0.3-pre.
|
|
59
|
+
"@openmrs/esm-api": "^5.0.3-pre.882",
|
|
60
|
+
"@openmrs/esm-config": "^5.0.3-pre.882",
|
|
61
|
+
"@openmrs/esm-error-handling": "^5.0.3-pre.882",
|
|
62
|
+
"@openmrs/esm-extensions": "^5.0.3-pre.882",
|
|
63
|
+
"@openmrs/esm-globals": "^5.0.3-pre.882",
|
|
64
64
|
"dayjs": "^1.10.8",
|
|
65
65
|
"i18next": "^19.6.0",
|
|
66
66
|
"react": "^18.1.0",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"rxjs": "^6.5.3",
|
|
70
70
|
"webpack": "^5.88.0"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "ae49ca10f8b7954d5b4c6fec4b4c07880a83d649"
|
|
73
73
|
}
|
|
@@ -7,52 +7,12 @@ import {
|
|
|
7
7
|
ExtensionData,
|
|
8
8
|
} from "./ComponentContext";
|
|
9
9
|
|
|
10
|
-
let i18n: typeof window.i18next = window.i18next;
|
|
11
|
-
|
|
12
10
|
const defaultOpts = {
|
|
13
11
|
strictMode: true,
|
|
14
12
|
throwErrorsToConsole: true,
|
|
15
13
|
disableTranslations: false,
|
|
16
14
|
};
|
|
17
15
|
|
|
18
|
-
interface I18nextLoadNamespaceProps {
|
|
19
|
-
forceUpdate(): void;
|
|
20
|
-
ns: string;
|
|
21
|
-
children?: React.ReactNode;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const I18nextLoadNamespace: React.FC<I18nextLoadNamespaceProps> = (props) => {
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
i18n.on("languageChanged", props.forceUpdate);
|
|
27
|
-
return () => i18n.off("languageChanged", props.forceUpdate);
|
|
28
|
-
}, [props.forceUpdate]);
|
|
29
|
-
|
|
30
|
-
const loadNamespaceErrRef = useRef(null);
|
|
31
|
-
|
|
32
|
-
if (loadNamespaceErrRef.current) {
|
|
33
|
-
throw loadNamespaceErrRef.current;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// FIXME hasLoadedNamespace() is part of the API but not the current types
|
|
37
|
-
if (!(i18n as any).hasLoadedNamespace(props.ns)) {
|
|
38
|
-
const timeoutId = setTimeout(() => {
|
|
39
|
-
console.warn(
|
|
40
|
-
`openmrsComponentDecorator: the React suspense promise for i18next.loadNamespaces(['${props.ns}']) did not resolve nor reject after three seconds. This could mean you have multiple versions of i18next and haven't made i18next a webpack external in all projects.`
|
|
41
|
-
);
|
|
42
|
-
}, 3000);
|
|
43
|
-
|
|
44
|
-
throw i18n
|
|
45
|
-
.loadNamespaces([props.ns])
|
|
46
|
-
.then(() => clearTimeout(timeoutId))
|
|
47
|
-
.catch((err) => {
|
|
48
|
-
clearTimeout(timeoutId);
|
|
49
|
-
loadNamespaceErrRef.current = err;
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return <>{props.children}</>;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
16
|
export interface ComponentDecoratorOptions {
|
|
57
17
|
moduleName: string;
|
|
58
18
|
featureName: string;
|
|
@@ -71,10 +31,6 @@ export interface OpenmrsReactComponentState {
|
|
|
71
31
|
}
|
|
72
32
|
|
|
73
33
|
export function openmrsComponentDecorator(userOpts: ComponentDecoratorOptions) {
|
|
74
|
-
if (typeof i18n === "undefined" && typeof window.i18next !== "undefined") {
|
|
75
|
-
i18n = window.i18next;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
34
|
if (
|
|
79
35
|
typeof userOpts !== "object" ||
|
|
80
36
|
typeof userOpts.featureName !== "string" ||
|
|
@@ -134,20 +90,16 @@ export function openmrsComponentDecorator(userOpts: ComponentDecoratorOptions) {
|
|
|
134
90
|
} else {
|
|
135
91
|
const content = (
|
|
136
92
|
<ComponentContext.Provider value={this.state.config}>
|
|
137
|
-
|
|
138
|
-
{
|
|
93
|
+
{opts.disableTranslations ? (
|
|
94
|
+
<Comp {...this.props} />
|
|
95
|
+
) : (
|
|
96
|
+
<I18nextProvider
|
|
97
|
+
i18n={window.i18next}
|
|
98
|
+
defaultNS={opts.moduleName}
|
|
99
|
+
>
|
|
139
100
|
<Comp {...this.props} />
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
ns={opts.moduleName}
|
|
143
|
-
forceUpdate={() => this.forceUpdate()}
|
|
144
|
-
>
|
|
145
|
-
<I18nextProvider i18n={i18n} defaultNS={opts.moduleName}>
|
|
146
|
-
<Comp {...this.props} />
|
|
147
|
-
</I18nextProvider>
|
|
148
|
-
</I18nextLoadNamespace>
|
|
149
|
-
)}
|
|
150
|
-
</React.Suspense>
|
|
101
|
+
</I18nextProvider>
|
|
102
|
+
)}
|
|
151
103
|
</ComponentContext.Provider>
|
|
152
104
|
);
|
|
153
105
|
|