codenotch-react 1.0.35 → 1.0.37
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/dist/index.d.ts +24 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +126 -2
- package/package.json +3 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,12 @@ export interface ICodenotchEnv {
|
|
|
4
4
|
tenantName?: string;
|
|
5
5
|
accessToken?: string;
|
|
6
6
|
baseUrl?: string;
|
|
7
|
-
|
|
7
|
+
i18n?: {
|
|
8
|
+
[language: string]: {
|
|
9
|
+
[key: string]: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
currentLanguage?: string;
|
|
8
13
|
[key: string]: any;
|
|
9
14
|
}
|
|
10
15
|
export interface ICodenotchApi {
|
|
@@ -16,8 +21,26 @@ export interface ICodenotchApi {
|
|
|
16
21
|
onSignal: (signalId: string, callback: () => void) => {
|
|
17
22
|
dispose: () => void;
|
|
18
23
|
};
|
|
24
|
+
i18n: (key: string, ...args: any[]) => string;
|
|
25
|
+
showDialog: (node: React.DOMElement<React.DOMAttributes<Element>, Element>) => ICodenotchDialog;
|
|
26
|
+
}
|
|
27
|
+
export interface ICodenotchDialog {
|
|
28
|
+
id: string;
|
|
29
|
+
close: () => void;
|
|
19
30
|
}
|
|
20
31
|
declare const CODENOTCH_ENV: ICodenotchEnv;
|
|
32
|
+
/**
|
|
33
|
+
* Parse URL parameters and return them as an object
|
|
34
|
+
* @returns {Object} An object containing the URL parameters as key-value pairs
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseUrlParams(): {
|
|
37
|
+
[key: string]: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Setup Codenotch environment from the given object
|
|
41
|
+
* @param env An object containing the Codenotch environment variables as key-value pairs. This can be obtained from URL parameters or any other source.
|
|
42
|
+
* @returns {void}
|
|
43
|
+
*/
|
|
21
44
|
export declare function setupCodenotchEnv(env: any): void;
|
|
22
45
|
/**
|
|
23
46
|
* Return Codenotch API
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,aAAa;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IACzD,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC1B,GAAG,EAAE,aAAa,CAAC;IACnB,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IACjE,YAAY,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACrE,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,KAAK;QAAE,OAAO,EAAE,MAAM,IAAI,CAAA;KAAE,CAAC;IAC9E,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC;IAC9C,UAAU,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,KAAK,gBAAgB,CAAC;CACnG;AAED,MAAM,WAAW,gBAAgB;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,QAAA,MAAM,aAAa,EAAE,aAAkB,CAAC;AAExC;;;GAGG;AACH,wBAAgB,cAAc,IAAI;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAW1D;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CA4ChD;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,aAAa,CA2I5C;AAGD,OAAO,EAAE,aAAa,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,76 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.CODENOTCH_ENV = void 0;
|
|
7
|
+
exports.parseUrlParams = parseUrlParams;
|
|
4
8
|
exports.setupCodenotchEnv = setupCodenotchEnv;
|
|
5
9
|
exports.useCodenotch = useCodenotch;
|
|
10
|
+
const react_dom_1 = __importDefault(require("react-dom"));
|
|
6
11
|
const CODENOTCH_ENV = {};
|
|
7
12
|
exports.CODENOTCH_ENV = CODENOTCH_ENV;
|
|
13
|
+
/**
|
|
14
|
+
* Parse URL parameters and return them as an object
|
|
15
|
+
* @returns {Object} An object containing the URL parameters as key-value pairs
|
|
16
|
+
*/
|
|
17
|
+
function parseUrlParams() {
|
|
18
|
+
let result = {};
|
|
19
|
+
if (typeof window !== 'undefined') {
|
|
20
|
+
const params = new URL(window.location.href).searchParams;
|
|
21
|
+
params.forEach((value, key) => {
|
|
22
|
+
if (result[key] === undefined) {
|
|
23
|
+
result[key] = value;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Setup Codenotch environment from the given object
|
|
31
|
+
* @param env An object containing the Codenotch environment variables as key-value pairs. This can be obtained from URL parameters or any other source.
|
|
32
|
+
* @returns {void}
|
|
33
|
+
*/
|
|
8
34
|
function setupCodenotchEnv(env) {
|
|
9
35
|
if (env === undefined || env === null) {
|
|
10
36
|
console.warn("Codenotch environment is not defined. Please set it in the Codenotch configuration.");
|
|
11
37
|
return;
|
|
12
38
|
}
|
|
39
|
+
// i18n.fr.somekey=some value
|
|
40
|
+
let i18nLanguages = new Set();
|
|
13
41
|
Object.keys(env).forEach((key) => {
|
|
14
|
-
|
|
15
|
-
|
|
42
|
+
if (key.startsWith("i18n.")) {
|
|
43
|
+
// Special case
|
|
44
|
+
let parts = key.split(".");
|
|
45
|
+
let language = parts[1];
|
|
46
|
+
let keyName = parts.slice(2).join(".");
|
|
47
|
+
i18nLanguages.add(language);
|
|
48
|
+
let keyValue = `${env[key]}`.trim();
|
|
49
|
+
if (keyValue.startsWith('"') && keyValue.endsWith('"')) {
|
|
50
|
+
// Parse like json
|
|
51
|
+
try {
|
|
52
|
+
keyValue = JSON.parse(keyValue);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.warn(`Codenotch environment variable ${key} is not a valid JSON string. Using raw value.`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
CODENOTCH_ENV.i18n = CODENOTCH_ENV.i18n ?? {};
|
|
59
|
+
CODENOTCH_ENV.i18n[language] = CODENOTCH_ENV.i18n[language] ?? {};
|
|
60
|
+
CODENOTCH_ENV.i18n[language][keyName] = keyValue;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
CODENOTCH_ENV[key] = env[key];
|
|
64
|
+
console.log(`Codenotch environment variable ${key} set to ${env[key]}`);
|
|
65
|
+
}
|
|
16
66
|
});
|
|
67
|
+
if (CODENOTCH_ENV.currentLanguage === undefined) {
|
|
68
|
+
// If current language is not defined, we set it to the first language found in i18n
|
|
69
|
+
if (i18nLanguages.size > 0) {
|
|
70
|
+
CODENOTCH_ENV.currentLanguage = Array.from(i18nLanguages)[0];
|
|
71
|
+
console.log(`Codenotch current language set to ${CODENOTCH_ENV.currentLanguage}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
17
74
|
}
|
|
18
75
|
/**
|
|
19
76
|
* Return Codenotch API
|
|
@@ -22,6 +79,38 @@ function setupCodenotchEnv(env) {
|
|
|
22
79
|
function useCodenotch() {
|
|
23
80
|
return {
|
|
24
81
|
ENV: CODENOTCH_ENV,
|
|
82
|
+
i18n: (key, ...args) => {
|
|
83
|
+
try {
|
|
84
|
+
if (CODENOTCH_ENV.i18n === undefined || Object.keys(CODENOTCH_ENV.i18n).length === 0) {
|
|
85
|
+
console.warn("Codenotch i18n is not defined. Please set it in the Codenotch configuration.");
|
|
86
|
+
return key;
|
|
87
|
+
}
|
|
88
|
+
let language = CODENOTCH_ENV.currentLanguage ?? "en";
|
|
89
|
+
let isLanguageExists = CODENOTCH_ENV.i18n[language] !== undefined;
|
|
90
|
+
if (isLanguageExists === false) {
|
|
91
|
+
let fallbackLanguage = Object.keys(CODENOTCH_ENV.i18n)[0];
|
|
92
|
+
console.warn(`Codenotch i18n language ${language} is not defined. Falling back to ${fallbackLanguage}. Please set the correct language in the Codenotch configuration.`);
|
|
93
|
+
language = fallbackLanguage;
|
|
94
|
+
}
|
|
95
|
+
let dico = CODENOTCH_ENV.i18n[language];
|
|
96
|
+
let value = dico[key];
|
|
97
|
+
if (typeof value !== "string") {
|
|
98
|
+
console.warn(`Codenotch i18n key ${key} is not defined for language ${language}. Please set it in the Codenotch configuration.`);
|
|
99
|
+
return key;
|
|
100
|
+
}
|
|
101
|
+
args = args ?? [];
|
|
102
|
+
let result = value.replace(/{([\d ]*)}/g, (match, p1) => {
|
|
103
|
+
let argValue = args[p1.trim()];
|
|
104
|
+
// Instead of returning 'undefined', returns an empty string
|
|
105
|
+
return argValue !== undefined ? argValue : "";
|
|
106
|
+
});
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
console.error("Error in i18n function:", error);
|
|
111
|
+
return key;
|
|
112
|
+
}
|
|
113
|
+
},
|
|
25
114
|
requestSioql: async (sioql, verbose) => {
|
|
26
115
|
if (CODENOTCH_ENV.clusterUrl === undefined) {
|
|
27
116
|
throw new Error("Codenotch cluster URL is not defined. Please set it in the Codenotch configuration.");
|
|
@@ -68,6 +157,41 @@ function useCodenotch() {
|
|
|
68
157
|
console.log(`Stopped listening to signal ${signalId}`);
|
|
69
158
|
}
|
|
70
159
|
};
|
|
160
|
+
},
|
|
161
|
+
showDialog: (node) => {
|
|
162
|
+
let dialogId = "codenotch-dialog-" + Math.random().toString(36).substring(2, 9);
|
|
163
|
+
let result = {
|
|
164
|
+
id: dialogId,
|
|
165
|
+
close: () => {
|
|
166
|
+
let dialogElement = document.getElementById(dialogId);
|
|
167
|
+
if (dialogElement) {
|
|
168
|
+
dialogElement.remove();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
// Find "cn-dialog-container" element in the page
|
|
173
|
+
let container = document.getElementById("cn-dialog-container");
|
|
174
|
+
if (container === null) {
|
|
175
|
+
container = document.createElement("div");
|
|
176
|
+
container.id = "cn-dialog-container";
|
|
177
|
+
container.style.zIndex = "9999";
|
|
178
|
+
container.style.position = "fixed";
|
|
179
|
+
container.style.top = "0";
|
|
180
|
+
container.style.left = "0";
|
|
181
|
+
container.style.minWidth = "100vw";
|
|
182
|
+
container.style.minHeight = "100vh";
|
|
183
|
+
container.style.maxWidth = "100vw";
|
|
184
|
+
container.style.maxHeight = "100vh";
|
|
185
|
+
container.style.display = "flex";
|
|
186
|
+
container.style.alignItems = "center";
|
|
187
|
+
container.style.justifyContent = "center";
|
|
188
|
+
document.body.appendChild(container);
|
|
189
|
+
}
|
|
190
|
+
let dialogElement = document.createElement('dialog');
|
|
191
|
+
dialogElement.id = dialogId;
|
|
192
|
+
container.appendChild(dialogElement);
|
|
193
|
+
react_dom_1.default.render(node, dialogElement);
|
|
194
|
+
return result;
|
|
71
195
|
}
|
|
72
196
|
};
|
|
73
197
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codenotch-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.37",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": "Codenotch SA",
|
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/node": "^25.3.2",
|
|
21
21
|
"@types/react": "^16.14.69",
|
|
22
|
+
"@types/react-dom": "^16.9.25",
|
|
23
|
+
"react-dom": "^16.14.0",
|
|
22
24
|
"typescript": "^5.9.3"
|
|
23
25
|
},
|
|
24
26
|
"peerDependencies": {
|