@olenbetong/appframe-core 2.4.3 → 2.5.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/esm/af.common.js +44 -33
- package/dist/esm/af.common.legacy.js +46 -35
- package/dist/esm/af.common.legacy.min.js +1 -1
- package/dist/esm/af.common.legacy.min.js.map +4 -4
- package/dist/esm/af.common.min.js +1 -1
- package/dist/esm/af.common.min.js.map +4 -4
- package/dist/iife/af.common.js +44 -33
- package/dist/iife/af.common.legacy.js +46 -35
- package/dist/iife/af.common.legacy.min.js +1 -1
- package/dist/iife/af.common.legacy.min.js.map +4 -4
- package/dist/iife/af.common.min.js +1 -1
- package/dist/iife/af.common.min.js.map +4 -4
- package/es/UserSession.js +15 -1
- package/es/date.d.ts +2 -2
- package/es/expose.d.ts +7 -1
- package/es/expose.js +2 -2
- package/es/index.d.ts +1 -1
- package/es/index.js +2 -2
- package/es/requireNamespace.js +1 -2
- package/package.json +2 -2
- package/src/SessionHandler.ts +56 -56
- package/src/UserSession.ts +38 -24
- package/src/date.ts +2 -2
- package/src/downloadBlob.ts +18 -18
- package/src/downloadRequest.ts +67 -67
- package/src/errorHandler.ts +23 -23
- package/src/expose.ts +54 -43
- package/src/getLocalizedString.ts +40 -40
- package/src/getUserImage.ts +44 -44
- package/src/has.ts +2 -5
- package/src/index.ts +26 -27
- package/src/invariant.ts +5 -5
- package/src/localStorage.ts +39 -42
- package/src/localize.ts +10 -10
- package/src/parseFunc.ts +4 -4
- package/src/requireNamespace.ts +13 -17
- package/src/settings.ts +19 -23
package/src/getUserImage.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
export type ImageSize = "xs" | "sm" | "md" | "lg" | "xl";
|
|
2
2
|
|
|
3
3
|
export interface getUserImageOptions {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Prim key of the record in atbl_Personnel_Employees
|
|
6
|
+
*/
|
|
7
|
+
primKey: string | null;
|
|
8
|
+
/**
|
|
9
|
+
* Person ID of the employee
|
|
10
|
+
*/
|
|
11
|
+
login: string | null;
|
|
12
|
+
/**
|
|
13
|
+
* The value of the ImageHash column in atbl_Personnel_Employees
|
|
14
|
+
*/
|
|
15
|
+
hash: string | number | null;
|
|
16
|
+
/**
|
|
17
|
+
* The image will be resized according to this value. Default is 'xs':
|
|
18
|
+
* - xs: 64px
|
|
19
|
+
* - sm: 128px
|
|
20
|
+
* - md: 256px
|
|
21
|
+
* - lg: 512px
|
|
22
|
+
* - xl: image is not resized
|
|
23
|
+
*/
|
|
24
|
+
size?: ImageSize;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const sizeMap: Record<ImageSize, number | undefined> = {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
xs: 64,
|
|
29
|
+
sm: 128,
|
|
30
|
+
md: 256,
|
|
31
|
+
lg: 512,
|
|
32
|
+
xl: undefined,
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
/**
|
|
@@ -39,28 +39,28 @@ const sizeMap: Record<ImageSize, number | undefined> = {
|
|
|
39
39
|
* If one of primKey or hash are not provided, or are null, an empty string will be returned.
|
|
40
40
|
*/
|
|
41
41
|
export function getUserImage(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
primKey: string | null,
|
|
43
|
+
login: string | null,
|
|
44
|
+
hash: string | number | null,
|
|
45
|
+
size?: ImageSize
|
|
46
46
|
): string;
|
|
47
47
|
export function getUserImage(options: getUserImageOptions): string;
|
|
48
48
|
export function getUserImage(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
primKeyOrOptions: string | null | getUserImageOptions,
|
|
50
|
+
login?: string | null,
|
|
51
|
+
hash?: string | number | null,
|
|
52
|
+
size: ImageSize = "xs"
|
|
53
53
|
) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
if (primKeyOrOptions && typeof primKeyOrOptions === "object") {
|
|
55
|
+
return getUserImage(primKeyOrOptions.primKey, primKeyOrOptions.login, primKeyOrOptions.hash, primKeyOrOptions.size);
|
|
56
|
+
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
if (!primKeyOrOptions || !hash) {
|
|
59
|
+
return "";
|
|
60
|
+
}
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
let sizePx = sizeMap[size];
|
|
63
|
+
return `/api/data/blob/EmployeesLookup/${primKeyOrOptions}/Image/${login}${login ? "." : ""}${hash}.jpg${
|
|
64
|
+
sizePx ? `?width=${sizePx}` : ""
|
|
65
|
+
}`;
|
|
66
66
|
}
|
package/src/has.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
export function has(
|
|
2
|
-
|
|
3
|
-
key: string | number | symbol
|
|
4
|
-
): boolean {
|
|
5
|
-
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
1
|
+
export function has(obj: any, key: string | number | symbol): boolean {
|
|
2
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
6
3
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import { UserSession } from "./UserSession.js";
|
|
1
2
|
import "./errorHandler.js";
|
|
2
3
|
import { expose } from "./expose.js";
|
|
3
4
|
import { getLocalizedString } from "./getLocalizedString.js";
|
|
4
5
|
import { localize } from "./localize.js";
|
|
5
6
|
|
|
6
|
-
import { UserSession } from "./UserSession.js";
|
|
7
|
-
|
|
8
7
|
export { default as mitt } from "mitt";
|
|
9
8
|
export * from "./date.js";
|
|
10
9
|
export { downloadBlob } from "./downloadBlob.js";
|
|
@@ -23,36 +22,36 @@ export * from "./settings.js";
|
|
|
23
22
|
export const version = __VERSION__;
|
|
24
23
|
|
|
25
24
|
declare global {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
var __VERSION__: string;
|
|
26
|
+
var __DEV__: number;
|
|
27
|
+
var af: AfCore;
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
interface Window {
|
|
30
|
+
af: AfCore;
|
|
31
|
+
}
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
export interface AfArticle {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
hostName: string;
|
|
36
|
+
i18n: Record<string, string>;
|
|
37
|
+
id: string;
|
|
39
38
|
}
|
|
40
39
|
|
|
41
40
|
export interface AfCore {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
41
|
+
article: AfArticle;
|
|
42
|
+
common: {
|
|
43
|
+
getLocalizedString: typeof getLocalizedString;
|
|
44
|
+
expose: typeof expose;
|
|
45
|
+
localize: typeof localize;
|
|
46
|
+
};
|
|
47
|
+
controls?: {
|
|
48
|
+
alert?: (message: string, callback?: () => void) => void;
|
|
49
|
+
confirm?: (options: {
|
|
50
|
+
title: string;
|
|
51
|
+
message: string;
|
|
52
|
+
buttons: string[];
|
|
53
|
+
callback: (button: number) => void;
|
|
54
|
+
}) => void;
|
|
55
|
+
};
|
|
56
|
+
userSession: UserSession;
|
|
58
57
|
}
|
package/src/invariant.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export function invariant(condition: any, message?: string | (() => string)): asserts condition {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
if (condition) {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
const provided: string | undefined = typeof message === "function" ? message() : message;
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
throw new Error(provided ?? "Invariant failed");
|
|
8
8
|
}
|
package/src/localStorage.ts
CHANGED
|
@@ -1,49 +1,46 @@
|
|
|
1
1
|
function getLocalKey(key: string): string {
|
|
2
|
-
|
|
2
|
+
return [af?.article?.id || "", "common", key].join(".");
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
class LocalStorage {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
6
|
+
isPersisted() {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
getLocalStorageKey(key: string, global?: boolean) {
|
|
11
|
+
return global ? ["common", key].join(".") : getLocalKey(key);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get(key: string, defaultValue: unknown, global?: boolean) {
|
|
15
|
+
const lsKey = this.getLocalStorageKey(key, global);
|
|
16
|
+
const value = localStorage.getItem(lsKey);
|
|
17
|
+
|
|
18
|
+
return value !== null ? JSON.parse(value) : defaultValue;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
set(key: string, value: unknown, global?: boolean) {
|
|
22
|
+
localStorage.setItem(this.getLocalStorageKey(key, global), JSON.stringify(value));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
remove(key: string, global?: boolean) {
|
|
26
|
+
const lsKey = this.getLocalStorageKey(key, global);
|
|
27
|
+
if (localStorage.getItem(lsKey) !== null) {
|
|
28
|
+
localStorage.removeItem(lsKey);
|
|
29
|
+
return true;
|
|
30
|
+
} else {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
clear() {
|
|
36
|
+
const baseKey = getLocalKey("");
|
|
37
|
+
|
|
38
|
+
for (let key in localStorage) {
|
|
39
|
+
if (key.slice(0, baseKey.length) === baseKey) {
|
|
40
|
+
localStorage.removeItem(key);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
47
44
|
}
|
|
48
45
|
|
|
49
46
|
export default new LocalStorage();
|
package/src/localize.ts
CHANGED
|
@@ -15,17 +15,17 @@ import { invariant } from "./invariant.js";
|
|
|
15
15
|
* @returns Translated string
|
|
16
16
|
*/
|
|
17
17
|
export function localize(stringParts: TemplateStringsArray, ...args: any[]): string {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
invariant(
|
|
19
|
+
Array.isArray(stringParts) && stringParts.length === args.length + 1,
|
|
20
|
+
"Method 'localize' must be used as a tag function"
|
|
21
|
+
);
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
let stringToLocalize = stringParts.map((s, i) => (i === stringParts.length - 1 ? s : `${s}\$${i}`)).join("");
|
|
24
|
+
let localized = getLocalizedString(stringToLocalize);
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
args.forEach((arg, index) => {
|
|
27
|
+
localized = localized.replace("$" + index, arg);
|
|
28
|
+
});
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
return localized;
|
|
31
31
|
}
|
package/src/parseFunc.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { invariant } from "./invariant.js";
|
|
2
2
|
|
|
3
3
|
const funcRegex =
|
|
4
|
-
|
|
4
|
+
/^function(?:\s+([a-zA-Z$_][a-zA-Z0-9$_]*))?\s*\(((?:(?:\s*[a-zA-Z$_][a-zA-Z0-9$_]*)(?:\s*,\s*[a-zA-Z$_][a-zA-Z0-9$_]*)*)?)\s*\)\s*\{((?:.|\n|\r)*)\}$/;
|
|
5
5
|
|
|
6
6
|
export function parseFunc(func: Function) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
var match = func.toString().match(funcRegex);
|
|
8
|
+
invariant(match, "Unable to parse function!");
|
|
9
|
+
return { name: match[1], args: match[2].split(","), body: match[3] };
|
|
10
10
|
}
|
package/src/requireNamespace.ts
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
import Namespace from "./Namespace.js";
|
|
2
2
|
|
|
3
|
-
export function requireNamespace(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (typeof root === "object") {
|
|
8
|
-
if (typeof namespace === "string") {
|
|
9
|
-
let path = namespace.split(".");
|
|
3
|
+
export function requireNamespace(root: any, namespace: string | Array<string>): any {
|
|
4
|
+
if (typeof root === "object") {
|
|
5
|
+
if (typeof namespace === "string") {
|
|
6
|
+
let path = namespace.split(".");
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
8
|
+
return requireNamespace(root, path);
|
|
9
|
+
} else if (Array.isArray(namespace)) {
|
|
10
|
+
let current: any = root;
|
|
11
|
+
for (let i = 0; i < namespace.length; i++) {
|
|
12
|
+
current = current[namespace[i]] = current[namespace[i]] || new (Namespace as any)();
|
|
13
|
+
}
|
|
18
14
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
return current;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
22
18
|
}
|
package/src/settings.ts
CHANGED
|
@@ -1,36 +1,32 @@
|
|
|
1
1
|
function getKey(article?: string) {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const articleKey = article || af.article.id;
|
|
3
|
+
return `${articleKey}.${af.userSession.login}`;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
export function getSettings<T>(setting: string, article?: string): T | null {
|
|
7
|
-
|
|
7
|
+
if (!af?.userSession) return null;
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const key = getKey(article);
|
|
10
|
+
const settings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
if (setting) {
|
|
13
|
+
return settings[setting] || null;
|
|
14
|
+
}
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
return settings;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export function saveSettings<T>(
|
|
20
|
-
|
|
21
|
-
value: T | null,
|
|
22
|
-
article?: string
|
|
23
|
-
): void {
|
|
24
|
-
if (!af?.userSession) return;
|
|
19
|
+
export function saveSettings<T>(setting: string, value: T | null, article?: string): void {
|
|
20
|
+
if (!af?.userSession) return;
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
const key = getKey(article);
|
|
23
|
+
let userSettings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
if (typeof value !== "undefined") {
|
|
26
|
+
userSettings[setting] = value;
|
|
27
|
+
} else {
|
|
28
|
+
userSettings = setting;
|
|
29
|
+
}
|
|
34
30
|
|
|
35
|
-
|
|
31
|
+
localStorage.setItem(key, JSON.stringify(userSettings));
|
|
36
32
|
}
|