@akinon/app-client 0.8.2 → 0.9.0
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/cjs/app-client-provider.d.ts +2 -0
- package/dist/cjs/app-client-provider.d.ts.map +1 -1
- package/dist/cjs/app-client-provider.js +20 -2
- package/dist/esm/app-client-provider.d.ts +2 -0
- package/dist/esm/app-client-provider.d.ts.map +1 -1
- package/dist/esm/app-client-provider.js +21 -3
- package/package.json +24 -20
|
@@ -23,6 +23,8 @@ interface AppClientContextState {
|
|
|
23
23
|
showToast?: (content: string, type: 'success' | 'warning' | 'error' | 'loading' | 'destroy') => void;
|
|
24
24
|
showErrorMessage?: (title: string, content: string) => void;
|
|
25
25
|
showRichModal?: (path: string, context?: any) => void;
|
|
26
|
+
locale: string;
|
|
27
|
+
onLocaleChange: (callback: (newLocale: string) => void) => void;
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
30
|
* Props for the AppClientProvider component.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-client-provider.d.ts","sourceRoot":"","sources":["../../src/app-client-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EAGjB,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,
|
|
1
|
+
{"version":3,"file":"app-client-provider.d.ts","sourceRoot":"","sources":["../../src/app-client-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EAGjB,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAON,MAAM,OAAO,CAAC;AAEf;;;;;;;;;;;GAWG;AACH,UAAU,qBAAqB;IAC7B,IAAI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AAY,EAAE,CAAC;AAC3C,YAAY,EACV,qBAAqB,EACrB,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,eAAe,EAChB,CAAC"}
|
|
@@ -18,7 +18,9 @@ const defaultContextState = {
|
|
|
18
18
|
invokeAction: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
19
|
return Promise.reject('Action functionality not initialized.');
|
|
20
20
|
}),
|
|
21
|
-
navigate: () => { }
|
|
21
|
+
navigate: () => { },
|
|
22
|
+
locale: 'en',
|
|
23
|
+
onLocaleChange: () => { }
|
|
22
24
|
};
|
|
23
25
|
const AppClientContext = (0, react_1.createContext)(defaultContextState);
|
|
24
26
|
/**
|
|
@@ -120,6 +122,8 @@ const AppClientProvider = ({ children, config }) => {
|
|
|
120
122
|
const [data, setData] = (0, react_1.useState)(undefined);
|
|
121
123
|
const [params, setParams] = (0, react_1.useState)(undefined);
|
|
122
124
|
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
125
|
+
const [locale, setLocale] = (0, react_1.useState)('en');
|
|
126
|
+
const localeChangeCallbacks = (0, react_1.useRef)([]);
|
|
123
127
|
// Function to invoke an action in the AppShell
|
|
124
128
|
const invokeAction = (actionKey, ...args) => {
|
|
125
129
|
return new Promise((resolve, reject) => {
|
|
@@ -183,10 +187,22 @@ const AppClientProvider = ({ children, config }) => {
|
|
|
183
187
|
}
|
|
184
188
|
});
|
|
185
189
|
}
|
|
190
|
+
// Listen for locale changes
|
|
191
|
+
bus.on(app_shared_1.EVENTS.LOCALE_CHANGED, message => {
|
|
192
|
+
const { locale: newLocale } = message;
|
|
193
|
+
setLocale(newLocale);
|
|
194
|
+
localeChangeCallbacks.current.forEach(callback => callback(newLocale));
|
|
195
|
+
});
|
|
186
196
|
return () => {
|
|
187
197
|
bus.teardown();
|
|
188
198
|
};
|
|
189
199
|
}, [config]);
|
|
200
|
+
const onLocaleChange = (0, react_1.useCallback)((callback) => {
|
|
201
|
+
localeChangeCallbacks.current.push(callback);
|
|
202
|
+
return () => {
|
|
203
|
+
localeChangeCallbacks.current = localeChangeCallbacks.current.filter(cb => cb !== callback);
|
|
204
|
+
};
|
|
205
|
+
}, []);
|
|
190
206
|
const contextValue = {
|
|
191
207
|
data,
|
|
192
208
|
params,
|
|
@@ -197,7 +213,9 @@ const AppClientProvider = ({ children, config }) => {
|
|
|
197
213
|
showConfirmationDialog,
|
|
198
214
|
showToast,
|
|
199
215
|
showErrorMessage,
|
|
200
|
-
showRichModal
|
|
216
|
+
showRichModal,
|
|
217
|
+
locale,
|
|
218
|
+
onLocaleChange
|
|
201
219
|
};
|
|
202
220
|
return (react_1.default.createElement(AppClientContext.Provider, { value: contextValue }, children));
|
|
203
221
|
};
|
|
@@ -23,6 +23,8 @@ interface AppClientContextState {
|
|
|
23
23
|
showToast?: (content: string, type: 'success' | 'warning' | 'error' | 'loading' | 'destroy') => void;
|
|
24
24
|
showErrorMessage?: (title: string, content: string) => void;
|
|
25
25
|
showRichModal?: (path: string, context?: any) => void;
|
|
26
|
+
locale: string;
|
|
27
|
+
onLocaleChange: (callback: (newLocale: string) => void) => void;
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
30
|
* Props for the AppClientProvider component.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-client-provider.d.ts","sourceRoot":"","sources":["../../src/app-client-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EAGjB,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,
|
|
1
|
+
{"version":3,"file":"app-client-provider.d.ts","sourceRoot":"","sources":["../../src/app-client-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EAGjB,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACj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AA,MAAM,YAAY,6BAAqC,CAAC;AA4FxD;;;;;GAKG;AACH,QAAA,MAAM,iBAAiB,yBAA0B,sBAAsB,sBAoItE,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAC;AAC3C,YAAY,EACV,qBAAqB,EACrB,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,eAAe,EAChB,CAAC"}
|
|
@@ -9,13 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { DEFAULT_ACTION_KEYS, EVENTS } from '@akinon/app-shared';
|
|
11
11
|
import Framebus from 'framebus';
|
|
12
|
-
import React, { createContext, useContext, useEffect, useState } from 'react';
|
|
12
|
+
import React, { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
13
13
|
const defaultContextState = {
|
|
14
14
|
isLoading: true,
|
|
15
15
|
invokeAction: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
16
|
return Promise.reject('Action functionality not initialized.');
|
|
17
17
|
}),
|
|
18
|
-
navigate: () => { }
|
|
18
|
+
navigate: () => { },
|
|
19
|
+
locale: 'en',
|
|
20
|
+
onLocaleChange: () => { }
|
|
19
21
|
};
|
|
20
22
|
const AppClientContext = createContext(defaultContextState);
|
|
21
23
|
/**
|
|
@@ -116,6 +118,8 @@ const AppClientProvider = ({ children, config }) => {
|
|
|
116
118
|
const [data, setData] = useState(undefined);
|
|
117
119
|
const [params, setParams] = useState(undefined);
|
|
118
120
|
const [isLoading, setIsLoading] = useState(true);
|
|
121
|
+
const [locale, setLocale] = useState('en');
|
|
122
|
+
const localeChangeCallbacks = useRef([]);
|
|
119
123
|
// Function to invoke an action in the AppShell
|
|
120
124
|
const invokeAction = (actionKey, ...args) => {
|
|
121
125
|
return new Promise((resolve, reject) => {
|
|
@@ -179,10 +183,22 @@ const AppClientProvider = ({ children, config }) => {
|
|
|
179
183
|
}
|
|
180
184
|
});
|
|
181
185
|
}
|
|
186
|
+
// Listen for locale changes
|
|
187
|
+
bus.on(EVENTS.LOCALE_CHANGED, message => {
|
|
188
|
+
const { locale: newLocale } = message;
|
|
189
|
+
setLocale(newLocale);
|
|
190
|
+
localeChangeCallbacks.current.forEach(callback => callback(newLocale));
|
|
191
|
+
});
|
|
182
192
|
return () => {
|
|
183
193
|
bus.teardown();
|
|
184
194
|
};
|
|
185
195
|
}, [config]);
|
|
196
|
+
const onLocaleChange = useCallback((callback) => {
|
|
197
|
+
localeChangeCallbacks.current.push(callback);
|
|
198
|
+
return () => {
|
|
199
|
+
localeChangeCallbacks.current = localeChangeCallbacks.current.filter(cb => cb !== callback);
|
|
200
|
+
};
|
|
201
|
+
}, []);
|
|
186
202
|
const contextValue = {
|
|
187
203
|
data,
|
|
188
204
|
params,
|
|
@@ -193,7 +209,9 @@ const AppClientProvider = ({ children, config }) => {
|
|
|
193
209
|
showConfirmationDialog,
|
|
194
210
|
showToast,
|
|
195
211
|
showErrorMessage,
|
|
196
|
-
showRichModal
|
|
212
|
+
showRichModal,
|
|
213
|
+
locale,
|
|
214
|
+
onLocaleChange
|
|
197
215
|
};
|
|
198
216
|
return (React.createElement(AppClientContext.Provider, { value: contextValue }, children));
|
|
199
217
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akinon/app-client",
|
|
3
3
|
"description": "Akinon AppClient library. This library is used to create a new plugin or an application which will reside in Akinon's applications.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.9.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/esm/index.js",
|
|
@@ -9,18 +9,34 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "pnpm run build:esm && pnpm run build:commonjs && pnpm run copy:files",
|
|
14
|
+
"build:esm": "tsc --outDir dist/esm",
|
|
15
|
+
"build:commonjs": "tsc --module commonjs --outDir dist/cjs",
|
|
16
|
+
"copy:files": "copyfiles -u 1 src/**/*.css dist/esm && copyfiles -u 1 src/**/*.css dist/cjs",
|
|
17
|
+
"clean": "rimraf dist/",
|
|
18
|
+
"lint": "eslint *.ts*",
|
|
19
|
+
"test": "vitest run",
|
|
20
|
+
"test:coverage": "vitest run --coverage",
|
|
21
|
+
"test:ui": "vitest --ui",
|
|
22
|
+
"test:watch": "vitest watch",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"prepublishOnly": "pnpm run build",
|
|
25
|
+
"prepack": "clean-package",
|
|
26
|
+
"postpack": "clean-package restore"
|
|
27
|
+
},
|
|
12
28
|
"dependencies": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
29
|
+
"@akinon/app-shared": "workspace:*",
|
|
30
|
+
"framebus": "^6.0.0"
|
|
15
31
|
},
|
|
16
32
|
"devDependencies": {
|
|
33
|
+
"@akinon/vite-config": "workspace:*",
|
|
34
|
+
"@akinon/eslint-config": "workspace:*",
|
|
35
|
+
"@akinon/typescript-config": "workspace:*",
|
|
17
36
|
"clean-package": "2.2.0",
|
|
18
37
|
"copyfiles": "^2.4.1",
|
|
19
38
|
"rimraf": "^5.0.5",
|
|
20
|
-
"typescript": "^5.2.2"
|
|
21
|
-
"@akinon/vite-config": "0.4.0",
|
|
22
|
-
"@akinon/eslint-config": "0.1.0",
|
|
23
|
-
"@akinon/typescript-config": "0.2.0"
|
|
39
|
+
"typescript": "^5.2.2"
|
|
24
40
|
},
|
|
25
41
|
"peerDependencies": {
|
|
26
42
|
"react": ">=18",
|
|
@@ -35,17 +51,5 @@
|
|
|
35
51
|
"require": "./dist/cjs/index.js"
|
|
36
52
|
},
|
|
37
53
|
"./package.json": "./package.json"
|
|
38
|
-
},
|
|
39
|
-
"scripts": {
|
|
40
|
-
"build": "pnpm run build:esm && pnpm run build:commonjs && pnpm run copy:files",
|
|
41
|
-
"build:esm": "tsc --outDir dist/esm",
|
|
42
|
-
"build:commonjs": "tsc --module commonjs --outDir dist/cjs",
|
|
43
|
-
"copy:files": "copyfiles -u 1 src/**/*.css dist/esm && copyfiles -u 1 src/**/*.css dist/cjs",
|
|
44
|
-
"clean": "rimraf dist/",
|
|
45
|
-
"lint": "eslint *.ts*",
|
|
46
|
-
"test": "vitest run",
|
|
47
|
-
"test:ui": "vitest --ui",
|
|
48
|
-
"test:watch": "vitest watch",
|
|
49
|
-
"typecheck": "tsc --noEmit"
|
|
50
54
|
}
|
|
51
|
-
}
|
|
55
|
+
}
|