@olenbetong/appframe-core 2.7.6 → 2.8.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/dist/esm/af.common.js +29 -9
- package/dist/esm/af.common.legacy.js +29 -9
- package/dist/esm/af.common.legacy.min.js +1 -1
- package/dist/esm/af.common.legacy.min.js.map +3 -3
- package/dist/esm/af.common.min.js +2 -2
- package/dist/esm/af.common.min.js.map +3 -3
- package/dist/iife/af.common.js +29 -9
- package/dist/iife/af.common.legacy.js +29 -9
- package/dist/iife/af.common.legacy.min.js +1 -1
- package/dist/iife/af.common.legacy.min.js.map +3 -3
- package/dist/iife/af.common.min.js +2 -2
- package/dist/iife/af.common.min.js.map +3 -3
- package/es/alert.d.ts +1 -1
- package/es/alert.js +12 -8
- package/es/index.d.ts +3 -2
- package/es/index.js +2 -2
- package/es/logActivity.d.ts +6 -1
- package/es/logActivity.js +11 -2
- package/package.json +2 -2
- package/src/alert.ts +27 -15
- package/src/index.ts +3 -2
- package/src/logActivity.ts +14 -2
package/es/alert.js
CHANGED
|
@@ -15,9 +15,17 @@ if (globalThis.document && !document.querySelector("#AlertDialogTemplate")) {
|
|
|
15
15
|
$template.innerHTML = template;
|
|
16
16
|
document.body.append($template);
|
|
17
17
|
}
|
|
18
|
-
export function waitForDialog(dialog) {
|
|
18
|
+
export function waitForDialog(dialog, cancelValue = "No") {
|
|
19
19
|
return new Promise((resolve) => {
|
|
20
|
-
|
|
20
|
+
let controller = new AbortController();
|
|
21
|
+
dialog.addEventListener("close", () => {
|
|
22
|
+
resolve(dialog.returnValue);
|
|
23
|
+
controller.abort();
|
|
24
|
+
}, { signal: controller.signal });
|
|
25
|
+
dialog.addEventListener("cancel", () => {
|
|
26
|
+
resolve(cancelValue);
|
|
27
|
+
controller.abort();
|
|
28
|
+
}, { signal: controller.signal });
|
|
21
29
|
});
|
|
22
30
|
}
|
|
23
31
|
const alertDialogPromiseMap = new Map();
|
|
@@ -55,17 +63,13 @@ export async function openAlertDialog({ buttons, content, className, id, title }
|
|
|
55
63
|
}
|
|
56
64
|
document.body.appendChild($dialog);
|
|
57
65
|
$dialog.showModal();
|
|
58
|
-
let dialogPromise = waitForDialog($dialog)
|
|
59
|
-
.then(() => {
|
|
66
|
+
let dialogPromise = waitForDialog($dialog).then((returnValue) => {
|
|
60
67
|
if (id && alertDialogPromiseMap.has(id)) {
|
|
61
68
|
alertDialogPromiseMap.delete(id);
|
|
62
69
|
}
|
|
63
|
-
})
|
|
64
|
-
.then(() => {
|
|
65
|
-
let result = $dialog?.returnValue || "cancel";
|
|
66
70
|
if ($dialog)
|
|
67
71
|
document.body.removeChild($dialog);
|
|
68
|
-
return
|
|
72
|
+
return returnValue;
|
|
69
73
|
});
|
|
70
74
|
if (id) {
|
|
71
75
|
alertDialogPromiseMap.set(id, dialogPromise);
|
package/es/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { expose } from "./expose.js";
|
|
|
5
5
|
import { getLocalizedString } from "./getLocalizedString.js";
|
|
6
6
|
import afLocalStorage from "./localStorage.js";
|
|
7
7
|
import { localize } from "./localize.js";
|
|
8
|
-
import { logActivity, startActivity } from "./logActivity.js";
|
|
8
|
+
import { logActivity, startActivity, time } from "./logActivity.js";
|
|
9
9
|
export { default as mitt } from "mitt";
|
|
10
10
|
export { toLocalISODate, toLocalISODateTime } from "./date.js";
|
|
11
11
|
export { downloadBlob } from "./downloadBlob.js";
|
|
@@ -19,7 +19,7 @@ export { has } from "./has.js";
|
|
|
19
19
|
export { invariant } from "./invariant.js";
|
|
20
20
|
export { localize } from "./localize.js";
|
|
21
21
|
export { afLocalStorage as localStorage };
|
|
22
|
-
export { logActivity, startActivity } from "./logActivity.js";
|
|
22
|
+
export { logActivity, startActivity, time } from "./logActivity.js";
|
|
23
23
|
export { default as SessionHandler } from "./SessionHandler.js";
|
|
24
24
|
export { UserSession };
|
|
25
25
|
export { getSettings, saveSettings } from "./settings.js";
|
|
@@ -51,6 +51,7 @@ export interface AfCore {
|
|
|
51
51
|
alert: typeof alert;
|
|
52
52
|
confirm: typeof confirm;
|
|
53
53
|
openAlertDialog: typeof openAlertDialog;
|
|
54
|
+
time: typeof time;
|
|
54
55
|
};
|
|
55
56
|
controls?: {
|
|
56
57
|
alert?: (message: string, callback?: () => void) => void;
|
package/es/index.js
CHANGED
|
@@ -12,9 +12,9 @@ export { has } from "./has.js";
|
|
|
12
12
|
export { invariant } from "./invariant.js";
|
|
13
13
|
export { localize } from "./localize.js";
|
|
14
14
|
export { afLocalStorage as localStorage };
|
|
15
|
-
export { logActivity, startActivity } from "./logActivity.js";
|
|
15
|
+
export { logActivity, startActivity, time } from "./logActivity.js";
|
|
16
16
|
export { default as SessionHandler } from "./SessionHandler.js";
|
|
17
17
|
export { UserSession };
|
|
18
18
|
export { getSettings, saveSettings } from "./settings.js";
|
|
19
19
|
export { alert, confirm, ConfirmButtons, openAlertDialog, waitForDialog } from "./alert.js";
|
|
20
|
-
export const version = "2.
|
|
20
|
+
export const version = "2.8.1";
|
package/es/logActivity.d.ts
CHANGED
|
@@ -14,4 +14,9 @@ export declare function logActivity(activity: string, parameters: Record<string,
|
|
|
14
14
|
* @param parameters A dictionary of parameters used when doing the activity
|
|
15
15
|
* @returns A function that should be called when the activity is completed to log it to the website log
|
|
16
16
|
*/
|
|
17
|
-
export declare function startActivity(activity: string,
|
|
17
|
+
export declare function startActivity(activity: string, startParameters?: Record<string, any>): (endParameters?: Record<string, any>) => Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Records the time used to execute an operation and returns the value of the operation and the time
|
|
20
|
+
* in milliseconds
|
|
21
|
+
*/
|
|
22
|
+
export declare function time<T>(callback: () => T | Promise<T>): Promise<[T, number]>;
|
package/es/logActivity.js
CHANGED
|
@@ -37,7 +37,16 @@ export async function logActivity(activity, parameters, timeElapsed = 0) {
|
|
|
37
37
|
* @param parameters A dictionary of parameters used when doing the activity
|
|
38
38
|
* @returns A function that should be called when the activity is completed to log it to the website log
|
|
39
39
|
*/
|
|
40
|
-
export function startActivity(activity,
|
|
40
|
+
export function startActivity(activity, startParameters = {}) {
|
|
41
41
|
let start = performance.now();
|
|
42
|
-
return () => logActivity(activity,
|
|
42
|
+
return (endParameters = {}) => logActivity(activity, { ...startParameters, ...endParameters }, performance.now() - start);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Records the time used to execute an operation and returns the value of the operation and the time
|
|
46
|
+
* in milliseconds
|
|
47
|
+
*/
|
|
48
|
+
export async function time(callback) {
|
|
49
|
+
let start = performance.now();
|
|
50
|
+
let returnValue = await callback();
|
|
51
|
+
return [returnValue, performance.now() - start];
|
|
43
52
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olenbetong/appframe-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.1",
|
|
4
4
|
"description": "Javascript libraries to utilize the Appframe framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"chalk": "^5.3.0"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "bd38247c3326720c7d80384e0ad52063de28006d"
|
|
52
52
|
}
|
package/src/alert.ts
CHANGED
|
@@ -18,12 +18,29 @@ if (globalThis.document && !document.querySelector("#AlertDialogTemplate")) {
|
|
|
18
18
|
document.body.append($template);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export function waitForDialog(dialog: HTMLDialogElement) {
|
|
21
|
+
export function waitForDialog(dialog: HTMLDialogElement, cancelValue: string = "No"): Promise<string> {
|
|
22
22
|
return new Promise((resolve) => {
|
|
23
|
-
|
|
23
|
+
let controller = new AbortController();
|
|
24
|
+
|
|
25
|
+
dialog.addEventListener(
|
|
26
|
+
"close",
|
|
27
|
+
() => {
|
|
28
|
+
resolve(dialog.returnValue);
|
|
29
|
+
controller.abort();
|
|
30
|
+
},
|
|
31
|
+
{ signal: controller.signal },
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
dialog.addEventListener(
|
|
35
|
+
"cancel",
|
|
36
|
+
() => {
|
|
37
|
+
resolve(cancelValue);
|
|
38
|
+
controller.abort();
|
|
39
|
+
},
|
|
40
|
+
{ signal: controller.signal },
|
|
41
|
+
);
|
|
24
42
|
});
|
|
25
43
|
}
|
|
26
|
-
|
|
27
44
|
export type AlertDialogButton = {
|
|
28
45
|
label: string;
|
|
29
46
|
value: string;
|
|
@@ -80,18 +97,13 @@ export async function openAlertDialog({ buttons, content, className, id, title }
|
|
|
80
97
|
document.body.appendChild($dialog);
|
|
81
98
|
$dialog.showModal();
|
|
82
99
|
|
|
83
|
-
let dialogPromise = waitForDialog($dialog)
|
|
84
|
-
.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
let result = $dialog?.returnValue || "cancel";
|
|
91
|
-
if ($dialog) document.body.removeChild($dialog);
|
|
92
|
-
|
|
93
|
-
return result;
|
|
94
|
-
});
|
|
100
|
+
let dialogPromise = waitForDialog($dialog).then((returnValue) => {
|
|
101
|
+
if (id && alertDialogPromiseMap.has(id)) {
|
|
102
|
+
alertDialogPromiseMap.delete(id);
|
|
103
|
+
}
|
|
104
|
+
if ($dialog) document.body.removeChild($dialog);
|
|
105
|
+
return returnValue;
|
|
106
|
+
});
|
|
95
107
|
|
|
96
108
|
if (id) {
|
|
97
109
|
alertDialogPromiseMap.set(id, dialogPromise);
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { expose } from "./expose.js";
|
|
|
5
5
|
import { getLocalizedString } from "./getLocalizedString.js";
|
|
6
6
|
import afLocalStorage from "./localStorage.js";
|
|
7
7
|
import { localize } from "./localize.js";
|
|
8
|
-
import { logActivity, startActivity } from "./logActivity.js";
|
|
8
|
+
import { logActivity, startActivity, time } from "./logActivity.js";
|
|
9
9
|
|
|
10
10
|
export { default as mitt } from "mitt";
|
|
11
11
|
export { toLocalISODate, toLocalISODateTime } from "./date.js";
|
|
@@ -20,7 +20,7 @@ export { has } from "./has.js";
|
|
|
20
20
|
export { invariant } from "./invariant.js";
|
|
21
21
|
export { localize } from "./localize.js";
|
|
22
22
|
export { afLocalStorage as localStorage };
|
|
23
|
-
export { logActivity, startActivity } from "./logActivity.js";
|
|
23
|
+
export { logActivity, startActivity, time } from "./logActivity.js";
|
|
24
24
|
export { default as SessionHandler } from "./SessionHandler.js";
|
|
25
25
|
export { UserSession };
|
|
26
26
|
export { getSettings, saveSettings } from "./settings.js";
|
|
@@ -57,6 +57,7 @@ export interface AfCore {
|
|
|
57
57
|
alert: typeof alert;
|
|
58
58
|
confirm: typeof confirm;
|
|
59
59
|
openAlertDialog: typeof openAlertDialog;
|
|
60
|
+
time: typeof time;
|
|
60
61
|
};
|
|
61
62
|
controls?: {
|
|
62
63
|
alert?: (message: string, callback?: () => void) => void;
|
package/src/logActivity.ts
CHANGED
|
@@ -37,7 +37,19 @@ export async function logActivity(activity: string, parameters: Record<string, a
|
|
|
37
37
|
* @param parameters A dictionary of parameters used when doing the activity
|
|
38
38
|
* @returns A function that should be called when the activity is completed to log it to the website log
|
|
39
39
|
*/
|
|
40
|
-
export function startActivity(activity: string,
|
|
40
|
+
export function startActivity(activity: string, startParameters: Record<string, any> = {}) {
|
|
41
41
|
let start = performance.now();
|
|
42
|
-
return (
|
|
42
|
+
return (endParameters: Record<string, any> = {}) =>
|
|
43
|
+
logActivity(activity, { ...startParameters, ...endParameters }, performance.now() - start);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Records the time used to execute an operation and returns the value of the operation and the time
|
|
48
|
+
* in milliseconds
|
|
49
|
+
*/
|
|
50
|
+
export async function time<T>(callback: () => T | Promise<T>): Promise<[T, number]> {
|
|
51
|
+
let start = performance.now();
|
|
52
|
+
let returnValue = await callback();
|
|
53
|
+
|
|
54
|
+
return [returnValue, performance.now() - start];
|
|
43
55
|
}
|