@firedesktop/react-base 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.
- package/.babelrc +1 -2
- package/dist/ConfigurationLoader.d.ts +7 -0
- package/dist/ConfigurationLoader.js +26 -2
- package/dist/ConfigurationManager.d.ts +4 -0
- package/dist/ConfigurationManager.js +62 -2
- package/dist/LanguageLoader.d.ts +8 -0
- package/dist/LanguageLoader.js +27 -2
- package/dist/LanguageManager.d.ts +5 -0
- package/dist/LanguageManager.js +80 -2
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -2
- package/package.json +6 -5
- package/src/App.tsx +4 -4
- package/src/types/ConfigurationLoader.d.ts +7 -0
- package/src/types/ConfigurationLoader.js +26 -0
- package/src/types/ConfigurationManager.d.ts +4 -0
- package/src/types/ConfigurationManager.js +62 -0
- package/src/types/LanguageLoader.d.ts +8 -0
- package/src/types/LanguageLoader.js +27 -0
- package/src/types/LanguageManager.d.ts +5 -0
- package/src/types/LanguageManager.js +80 -0
- package/src/types/index.d.ts +5 -0
- package/src/types/index.js +5 -0
- package/tsconfig.json +5 -3
- package/tsconfig.original.json +26 -0
package/.babelrc
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare type configurationLoaderParamsType = {
|
|
3
|
+
updateAppState: any;
|
|
4
|
+
path: string | null;
|
|
5
|
+
};
|
|
6
|
+
declare function ConfigurationLoader({ updateAppState, path }: configurationLoaderParamsType): JSX.Element;
|
|
7
|
+
export default ConfigurationLoader;
|
|
@@ -1,2 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import React, { useEffect } from "react";
|
|
2
|
+
import { useDispatch, useSelector } from "react-redux";
|
|
3
|
+
import ConfigurationManager from './ConfigurationManager';
|
|
4
|
+
function ConfigurationLoader(_a) {
|
|
5
|
+
var updateAppState = _a.updateAppState, path = _a.path;
|
|
6
|
+
var dispatch = useDispatch();
|
|
7
|
+
var configuration = useSelector(function (state) { return state; }).configuration;
|
|
8
|
+
var loadConfiguration = ConfigurationManager().loadConfiguration;
|
|
9
|
+
var fullPath = './configuration/config.json';
|
|
10
|
+
if (path)
|
|
11
|
+
fullPath = path;
|
|
12
|
+
useEffect(function () {
|
|
13
|
+
if (!configuration) {
|
|
14
|
+
console.log("Loading Configuration for this Site in this path: " + fullPath);
|
|
15
|
+
loadConfiguration(fullPath).then(function (response) {
|
|
16
|
+
console.log("Loaded Configuration for this Site in this path: " + fullPath, response);
|
|
17
|
+
dispatch(updateAppState("configuration", response));
|
|
18
|
+
})
|
|
19
|
+
.catch(function (err) {
|
|
20
|
+
console.log("Problem loading the Site Configuration in this path: " + fullPath);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}, [configuration, dispatch, loadConfiguration, fullPath, updateAppState]);
|
|
24
|
+
return (React.createElement(React.Fragment, null));
|
|
25
|
+
}
|
|
26
|
+
export default ConfigurationLoader;
|
|
@@ -1,2 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
function ConfigurationManager(formData) {
|
|
38
|
+
function loadConfiguration(fullPath) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
40
|
+
var res, err_1;
|
|
41
|
+
return __generator(this, function (_a) {
|
|
42
|
+
switch (_a.label) {
|
|
43
|
+
case 0:
|
|
44
|
+
_a.trys.push([0, 3, , 4]);
|
|
45
|
+
return [4 /*yield*/, fetch(fullPath, { headers: { "Content-Type": "application/json; charset=utf-8" } })];
|
|
46
|
+
case 1:
|
|
47
|
+
res = _a.sent();
|
|
48
|
+
return [4 /*yield*/, res.json()];
|
|
49
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
50
|
+
case 3:
|
|
51
|
+
err_1 = _a.sent();
|
|
52
|
+
console.log("Problem loading the Site Labels");
|
|
53
|
+
return [3 /*break*/, 4];
|
|
54
|
+
case 4: return [2 /*return*/];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
;
|
|
60
|
+
return { loadConfiguration: loadConfiguration };
|
|
61
|
+
}
|
|
62
|
+
export default ConfigurationManager;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare type languageLoaderParamsType = {
|
|
3
|
+
updateAppState: any;
|
|
4
|
+
locale: string;
|
|
5
|
+
path: string | null;
|
|
6
|
+
};
|
|
7
|
+
declare function LanguageLoader({ updateAppState, locale, path }: languageLoaderParamsType): JSX.Element;
|
|
8
|
+
export default LanguageLoader;
|
package/dist/LanguageLoader.js
CHANGED
|
@@ -1,2 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import React, { useEffect } from "react";
|
|
2
|
+
import { useDispatch, useSelector } from "react-redux";
|
|
3
|
+
import LanguageManager from './LanguageManager';
|
|
4
|
+
function LanguageLoader(_a) {
|
|
5
|
+
var updateAppState = _a.updateAppState, locale = _a.locale, path = _a.path;
|
|
6
|
+
var dispatch = useDispatch();
|
|
7
|
+
var labels = useSelector(function (state) { return state; }).labels;
|
|
8
|
+
var loadLabels = LanguageManager().loadLabels;
|
|
9
|
+
var fileName = locale + ".json";
|
|
10
|
+
var fullPath = "./labels/" + fileName;
|
|
11
|
+
if (path)
|
|
12
|
+
fullPath = "./" + path + "/" + fileName;
|
|
13
|
+
useEffect(function () {
|
|
14
|
+
if (!labels) {
|
|
15
|
+
console.log("Loading Language Labels for this Site in this path: " + fullPath);
|
|
16
|
+
loadLabels(fullPath).then(function (response) {
|
|
17
|
+
console.log("Loaded Language Labels for this Site in this path: " + fullPath, response);
|
|
18
|
+
dispatch(updateAppState("labels", response));
|
|
19
|
+
})
|
|
20
|
+
.catch(function (err) {
|
|
21
|
+
console.log("Problem loading the Site Language Labels in this path: " + fullPath);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}, [labels, dispatch, loadLabels, fullPath, updateAppState]);
|
|
25
|
+
return (React.createElement(React.Fragment, null));
|
|
26
|
+
}
|
|
27
|
+
export default LanguageLoader;
|
package/dist/LanguageManager.js
CHANGED
|
@@ -1,2 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
function LanguageManager(formData) {
|
|
38
|
+
function loadLabels(fullPath) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
40
|
+
var res, err_1;
|
|
41
|
+
return __generator(this, function (_a) {
|
|
42
|
+
switch (_a.label) {
|
|
43
|
+
case 0:
|
|
44
|
+
_a.trys.push([0, 3, , 4]);
|
|
45
|
+
return [4 /*yield*/, fetch(fullPath, { headers: { "Content-Type": "application/json; charset=utf-8" } })];
|
|
46
|
+
case 1:
|
|
47
|
+
res = _a.sent();
|
|
48
|
+
return [4 /*yield*/, res.json()];
|
|
49
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
50
|
+
case 3:
|
|
51
|
+
err_1 = _a.sent();
|
|
52
|
+
console.log("Problem loading the Site Labels");
|
|
53
|
+
return [3 /*break*/, 4];
|
|
54
|
+
case 4: return [2 /*return*/];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
;
|
|
60
|
+
function getLabel(labels, id, defaultValue) {
|
|
61
|
+
if (labels === null || labels === undefined)
|
|
62
|
+
return defaultValue || '';
|
|
63
|
+
try {
|
|
64
|
+
var splits = id.split('.');
|
|
65
|
+
var message = labels;
|
|
66
|
+
for (var index = 0; index < splits.length; index++) {
|
|
67
|
+
var element = splits[index];
|
|
68
|
+
message = message[element];
|
|
69
|
+
}
|
|
70
|
+
if (message !== null && message !== undefined)
|
|
71
|
+
return message;
|
|
72
|
+
return defaultValue ? defaultValue : id;
|
|
73
|
+
}
|
|
74
|
+
catch (ex) {
|
|
75
|
+
return defaultValue ? defaultValue : id;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return { getLabel: getLabel, loadLabels: loadLabels };
|
|
79
|
+
}
|
|
80
|
+
export default LanguageManager;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import ConfigurationLoader from './ConfigurationLoader';
|
|
2
|
+
import ConfigurationManager from './ConfigurationManager';
|
|
3
|
+
import LanguageLoader from './LanguageLoader';
|
|
4
|
+
import LanguageManager from './LanguageManager';
|
|
5
|
+
export { ConfigurationLoader, ConfigurationManager, LanguageLoader, LanguageManager };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import ConfigurationLoader from './ConfigurationLoader';
|
|
2
|
+
import ConfigurationManager from './ConfigurationManager';
|
|
3
|
+
import LanguageLoader from './LanguageLoader';
|
|
4
|
+
import LanguageManager from './LanguageManager';
|
|
5
|
+
export { ConfigurationLoader, ConfigurationManager, LanguageLoader, LanguageManager };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firedesktop/react-base",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"description": "This is the FireDesktop base package used to support every React Project in this Company.",
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"react": "^17.0.1",
|
|
11
11
|
"react-dom": "^17.0.1",
|
|
12
|
-
"react-scripts": "4.0.0",
|
|
13
12
|
"react-redux": "^7.2.1",
|
|
14
13
|
"redux": "^4.0.5"
|
|
15
14
|
},
|
|
@@ -31,12 +30,14 @@
|
|
|
31
30
|
"babel-plugin-minify-builtins": "^0.5.0",
|
|
32
31
|
"react-scripts": "^3.4.3",
|
|
33
32
|
"typescript": "^4.0.3",
|
|
34
|
-
"web-vitals": "^0.2.4"
|
|
33
|
+
"web-vitals": "^0.2.4",
|
|
34
|
+
"@firedesktop/react-base": "1.2.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {},
|
|
37
37
|
"scripts": {
|
|
38
|
-
"
|
|
39
|
-
"start": "react-scripts start"
|
|
38
|
+
"distribute_not_working": "rmdir /s /q dist & mkdir dist && npx babel src/lib --out-dir dist --extensions \".js,.ts,.tsx\" --source-maps inline",
|
|
39
|
+
"start": "react-scripts start",
|
|
40
|
+
"distribute": "rmdir /s /q dist & mkdir dist && tsc"
|
|
40
41
|
},
|
|
41
42
|
"eslintConfig": {
|
|
42
43
|
"extends": [
|
package/src/App.tsx
CHANGED
|
@@ -2,8 +2,8 @@ import React from 'react';
|
|
|
2
2
|
import { Provider } from "react-redux";
|
|
3
3
|
import { createStore } from 'redux';
|
|
4
4
|
|
|
5
|
-
import ConfigurationLoader from './
|
|
6
|
-
import LanguageLoader from './
|
|
5
|
+
import ConfigurationLoader from './types/ConfigurationLoader';
|
|
6
|
+
// import LanguageLoader from './types/LanguageLoader';
|
|
7
7
|
import TestLabelFunction from './TestLabelFunction';
|
|
8
8
|
|
|
9
9
|
export const UPDATE_APP_STATE = 'UPDATE_APP_STATE';
|
|
@@ -41,9 +41,9 @@ function App() {
|
|
|
41
41
|
<Provider store={store}>
|
|
42
42
|
|
|
43
43
|
<TestLabelFunction />
|
|
44
|
-
|
|
45
44
|
<ConfigurationLoader updateAppState={updateAppState} path={null} />
|
|
46
|
-
|
|
45
|
+
{/*
|
|
46
|
+
<LanguageLoader updateAppState={updateAppState} locale='it-IT' path={null} /> */}
|
|
47
47
|
</Provider >
|
|
48
48
|
);
|
|
49
49
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare type configurationLoaderParamsType = {
|
|
3
|
+
updateAppState: any;
|
|
4
|
+
path: string | null;
|
|
5
|
+
};
|
|
6
|
+
declare function ConfigurationLoader({ updateAppState, path }: configurationLoaderParamsType): JSX.Element;
|
|
7
|
+
export default ConfigurationLoader;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React, { useEffect } from "react";
|
|
2
|
+
import { useDispatch, useSelector } from "react-redux";
|
|
3
|
+
import ConfigurationManager from './ConfigurationManager';
|
|
4
|
+
function ConfigurationLoader(_a) {
|
|
5
|
+
var updateAppState = _a.updateAppState, path = _a.path;
|
|
6
|
+
var dispatch = useDispatch();
|
|
7
|
+
var configuration = useSelector(function (state) { return state; }).configuration;
|
|
8
|
+
var loadConfiguration = ConfigurationManager().loadConfiguration;
|
|
9
|
+
var fullPath = './configuration/config.json';
|
|
10
|
+
if (path)
|
|
11
|
+
fullPath = path;
|
|
12
|
+
useEffect(function () {
|
|
13
|
+
if (!configuration) {
|
|
14
|
+
console.log("Loading Configuration for this Site in this path: " + fullPath);
|
|
15
|
+
loadConfiguration(fullPath).then(function (response) {
|
|
16
|
+
console.log("Loaded Configuration for this Site in this path: " + fullPath, response);
|
|
17
|
+
dispatch(updateAppState("configuration", response));
|
|
18
|
+
})
|
|
19
|
+
.catch(function (err) {
|
|
20
|
+
console.log("Problem loading the Site Configuration in this path: " + fullPath);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}, [configuration, dispatch, loadConfiguration, fullPath, updateAppState]);
|
|
24
|
+
return (React.createElement(React.Fragment, null));
|
|
25
|
+
}
|
|
26
|
+
export default ConfigurationLoader;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
function ConfigurationManager(formData) {
|
|
38
|
+
function loadConfiguration(fullPath) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
40
|
+
var res, err_1;
|
|
41
|
+
return __generator(this, function (_a) {
|
|
42
|
+
switch (_a.label) {
|
|
43
|
+
case 0:
|
|
44
|
+
_a.trys.push([0, 3, , 4]);
|
|
45
|
+
return [4 /*yield*/, fetch(fullPath, { headers: { "Content-Type": "application/json; charset=utf-8" } })];
|
|
46
|
+
case 1:
|
|
47
|
+
res = _a.sent();
|
|
48
|
+
return [4 /*yield*/, res.json()];
|
|
49
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
50
|
+
case 3:
|
|
51
|
+
err_1 = _a.sent();
|
|
52
|
+
console.log("Problem loading the Site Labels");
|
|
53
|
+
return [3 /*break*/, 4];
|
|
54
|
+
case 4: return [2 /*return*/];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
;
|
|
60
|
+
return { loadConfiguration: loadConfiguration };
|
|
61
|
+
}
|
|
62
|
+
export default ConfigurationManager;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare type languageLoaderParamsType = {
|
|
3
|
+
updateAppState: any;
|
|
4
|
+
locale: string;
|
|
5
|
+
path: string | null;
|
|
6
|
+
};
|
|
7
|
+
declare function LanguageLoader({ updateAppState, locale, path }: languageLoaderParamsType): JSX.Element;
|
|
8
|
+
export default LanguageLoader;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { useEffect } from "react";
|
|
2
|
+
import { useDispatch, useSelector } from "react-redux";
|
|
3
|
+
import LanguageManager from './LanguageManager';
|
|
4
|
+
function LanguageLoader(_a) {
|
|
5
|
+
var updateAppState = _a.updateAppState, locale = _a.locale, path = _a.path;
|
|
6
|
+
var dispatch = useDispatch();
|
|
7
|
+
var labels = useSelector(function (state) { return state; }).labels;
|
|
8
|
+
var loadLabels = LanguageManager().loadLabels;
|
|
9
|
+
var fileName = locale + ".json";
|
|
10
|
+
var fullPath = "./labels/" + fileName;
|
|
11
|
+
if (path)
|
|
12
|
+
fullPath = "./" + path + "/" + fileName;
|
|
13
|
+
useEffect(function () {
|
|
14
|
+
if (!labels) {
|
|
15
|
+
console.log("Loading Language Labels for this Site in this path: " + fullPath);
|
|
16
|
+
loadLabels(fullPath).then(function (response) {
|
|
17
|
+
console.log("Loaded Language Labels for this Site in this path: " + fullPath, response);
|
|
18
|
+
dispatch(updateAppState("labels", response));
|
|
19
|
+
})
|
|
20
|
+
.catch(function (err) {
|
|
21
|
+
console.log("Problem loading the Site Language Labels in this path: " + fullPath);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}, [labels, dispatch, loadLabels, fullPath, updateAppState]);
|
|
25
|
+
return (React.createElement(React.Fragment, null));
|
|
26
|
+
}
|
|
27
|
+
export default LanguageLoader;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (_) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
function LanguageManager(formData) {
|
|
38
|
+
function loadLabels(fullPath) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
40
|
+
var res, err_1;
|
|
41
|
+
return __generator(this, function (_a) {
|
|
42
|
+
switch (_a.label) {
|
|
43
|
+
case 0:
|
|
44
|
+
_a.trys.push([0, 3, , 4]);
|
|
45
|
+
return [4 /*yield*/, fetch(fullPath, { headers: { "Content-Type": "application/json; charset=utf-8" } })];
|
|
46
|
+
case 1:
|
|
47
|
+
res = _a.sent();
|
|
48
|
+
return [4 /*yield*/, res.json()];
|
|
49
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
50
|
+
case 3:
|
|
51
|
+
err_1 = _a.sent();
|
|
52
|
+
console.log("Problem loading the Site Labels");
|
|
53
|
+
return [3 /*break*/, 4];
|
|
54
|
+
case 4: return [2 /*return*/];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
;
|
|
60
|
+
function getLabel(labels, id, defaultValue) {
|
|
61
|
+
if (labels === null || labels === undefined)
|
|
62
|
+
return defaultValue || '';
|
|
63
|
+
try {
|
|
64
|
+
var splits = id.split('.');
|
|
65
|
+
var message = labels;
|
|
66
|
+
for (var index = 0; index < splits.length; index++) {
|
|
67
|
+
var element = splits[index];
|
|
68
|
+
message = message[element];
|
|
69
|
+
}
|
|
70
|
+
if (message !== null && message !== undefined)
|
|
71
|
+
return message;
|
|
72
|
+
return defaultValue ? defaultValue : id;
|
|
73
|
+
}
|
|
74
|
+
catch (ex) {
|
|
75
|
+
return defaultValue ? defaultValue : id;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return { getLabel: getLabel, loadLabels: loadLabels };
|
|
79
|
+
}
|
|
80
|
+
export default LanguageManager;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import ConfigurationLoader from './ConfigurationLoader';
|
|
2
|
+
import ConfigurationManager from './ConfigurationManager';
|
|
3
|
+
import LanguageLoader from './LanguageLoader';
|
|
4
|
+
import LanguageManager from './LanguageManager';
|
|
5
|
+
export { ConfigurationLoader, ConfigurationManager, LanguageLoader, LanguageManager };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import ConfigurationLoader from './ConfigurationLoader';
|
|
2
|
+
import ConfigurationManager from './ConfigurationManager';
|
|
3
|
+
import LanguageLoader from './LanguageLoader';
|
|
4
|
+
import LanguageManager from './LanguageManager';
|
|
5
|
+
export { ConfigurationLoader, ConfigurationManager, LanguageLoader, LanguageManager };
|
package/tsconfig.json
CHANGED
|
@@ -17,10 +17,12 @@
|
|
|
17
17
|
"moduleResolution": "node",
|
|
18
18
|
"resolveJsonModule": true,
|
|
19
19
|
"isolatedModules": true,
|
|
20
|
-
"
|
|
21
|
-
"
|
|
20
|
+
"declaration": true,
|
|
21
|
+
"outDir": "dist",
|
|
22
|
+
"jsx": "react",
|
|
23
|
+
"noEmit": false
|
|
22
24
|
},
|
|
23
25
|
"include": [
|
|
24
|
-
"src"
|
|
26
|
+
"src/lib"
|
|
25
27
|
]
|
|
26
28
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es5",
|
|
4
|
+
"lib": [
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.iterable",
|
|
7
|
+
"esnext"
|
|
8
|
+
],
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"allowSyntheticDefaultImports": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"noFallthroughCasesInSwitch": true,
|
|
16
|
+
"module": "esnext",
|
|
17
|
+
"moduleResolution": "node",
|
|
18
|
+
"resolveJsonModule": true,
|
|
19
|
+
"isolatedModules": true,
|
|
20
|
+
"noEmit": true,
|
|
21
|
+
"jsx": "react"
|
|
22
|
+
},
|
|
23
|
+
"include": [
|
|
24
|
+
"src"
|
|
25
|
+
]
|
|
26
|
+
}
|