@olenbetong/appframe-core 2.11.6 → 2.11.8
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 +63 -67
- package/dist/esm/af.common.legacy.js +67 -74
- 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 +2 -2
- package/dist/esm/af.common.min.js.map +4 -4
- package/dist/iife/af.common.js +67 -72
- package/dist/iife/af.common.legacy.js +71 -79
- 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 +2 -2
- package/dist/iife/af.common.min.js.map +4 -4
- package/es/SessionHandler.d.ts +1 -1
- package/es/alert.js +3 -1
- package/es/date.test.js +1 -1
- package/es/downloadBlob.js +2 -2
- package/es/downloadRequest.js +3 -3
- package/es/expose.d.ts +1 -1
- package/es/expose.js +1 -1
- package/es/expose.test.d.ts +1 -1
- package/es/expose.test.js +13 -13
- package/es/getLocalizedString.js +1 -1
- package/es/getUserImage.test.js +2 -2
- package/es/index.d.ts +11 -11
- package/es/index.js +5 -4
- package/es/invariant.test.js +2 -2
- package/es/localize.js +2 -2
- package/es/log.js +1 -1
- package/es/parseFunc.d.ts +1 -1
- package/es/parseFunc.js +1 -1
- package/es/parseFunc.test.js +2 -2
- package/es/test/setup.d.ts +0 -0
- package/es/test/setup.js +3 -0
- package/package.json +53 -53
- package/src/SessionHandler.ts +2 -2
- package/src/UserSession.ts +10 -10
- package/src/alert.ts +8 -6
- package/src/date.test.ts +1 -1
- package/src/date.ts +1 -1
- package/src/downloadBlob.ts +2 -2
- package/src/downloadRequest.ts +3 -3
- package/src/expose.test.ts +14 -15
- package/src/expose.ts +4 -4
- package/src/getLocalizedString.ts +1 -1
- package/src/getUserImage.test.ts +2 -2
- package/src/index.ts +12 -11
- package/src/invariant.test.ts +2 -2
- package/src/invariant.ts +3 -3
- package/src/localize.ts +2 -2
- package/src/log.ts +2 -2
- package/src/parseFunc.test.ts +2 -2
- package/src/parseFunc.ts +2 -2
- package/src/test/setup.ts +2 -0
- package/LICENSE +0 -21
package/dist/esm/af.common.js
CHANGED
|
@@ -135,7 +135,7 @@ async function logActivity(activity, parameters = {}, timeElapsed = 0) {
|
|
|
135
135
|
console.error(`${response.status} ${response.statusText}`);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
-
} catch
|
|
138
|
+
} catch {
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
function startActivity(activity, startParameters = {}) {
|
|
@@ -149,8 +149,7 @@ async function time(callback) {
|
|
|
149
149
|
}
|
|
150
150
|
async function logError(error) {
|
|
151
151
|
try {
|
|
152
|
-
if (!error)
|
|
153
|
-
return;
|
|
152
|
+
if (!error) return;
|
|
154
153
|
let data = typeof error === "string" ? { error } : typeof error === "object" ? "message" in error ? {
|
|
155
154
|
error: error.message,
|
|
156
155
|
stack: error.stack ?? null
|
|
@@ -289,7 +288,7 @@ function toLocalDateTime(date) {
|
|
|
289
288
|
|
|
290
289
|
// src/downloadBlob.ts
|
|
291
290
|
function downloadBlob(blob, fileName) {
|
|
292
|
-
return new Promise(
|
|
291
|
+
return new Promise((resolve, reject) => {
|
|
293
292
|
try {
|
|
294
293
|
const url = URL.createObjectURL(blob);
|
|
295
294
|
const parent = document.body;
|
|
@@ -299,7 +298,7 @@ function downloadBlob(blob, fileName) {
|
|
|
299
298
|
parent.append(anchor);
|
|
300
299
|
anchor.click();
|
|
301
300
|
parent.removeChild(anchor);
|
|
302
|
-
setTimeout(
|
|
301
|
+
setTimeout(() => {
|
|
303
302
|
URL.revokeObjectURL(url);
|
|
304
303
|
resolve();
|
|
305
304
|
}, 250);
|
|
@@ -334,9 +333,9 @@ async function downloadRequest(request, { fileName, signal, onProgress }) {
|
|
|
334
333
|
try {
|
|
335
334
|
const reader = response.body.getReader();
|
|
336
335
|
const stream = new ReadableStream({
|
|
337
|
-
start:
|
|
336
|
+
start: (controller) => {
|
|
338
337
|
function pump() {
|
|
339
|
-
return reader.read().then(
|
|
338
|
+
return reader.read().then((read) => {
|
|
340
339
|
if (read.done) {
|
|
341
340
|
controller.close();
|
|
342
341
|
return;
|
|
@@ -351,7 +350,7 @@ async function downloadRequest(request, { fileName, signal, onProgress }) {
|
|
|
351
350
|
}
|
|
352
351
|
});
|
|
353
352
|
response = new Response(stream);
|
|
354
|
-
} catch
|
|
353
|
+
} catch {
|
|
355
354
|
}
|
|
356
355
|
const blob = await response.blob();
|
|
357
356
|
onProgress?.({ bytesReceived, status: "downloaded" });
|
|
@@ -369,7 +368,7 @@ async function downloadRequest(request, { fileName, signal, onProgress }) {
|
|
|
369
368
|
// src/parseFunc.ts
|
|
370
369
|
var funcRegex = /^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)*)\}$/;
|
|
371
370
|
function parseFunc(func) {
|
|
372
|
-
|
|
371
|
+
const match = func.toString().match(funcRegex);
|
|
373
372
|
invariant(match, "Unable to parse function!");
|
|
374
373
|
return { name: func.name ?? match[1], args: match[2].split(",").map((a) => a.trim()), body: match[3] };
|
|
375
374
|
}
|
|
@@ -426,32 +425,13 @@ function expose(name, value, options = {}) {
|
|
|
426
425
|
invariant(false, "Invalid typeof parameter 'name', or unable to parse pValue!");
|
|
427
426
|
}
|
|
428
427
|
if (Object.hasOwn(namespace, keyName) && options?.overwrite !== true) {
|
|
429
|
-
console.warn([name, keyName].join(".")
|
|
428
|
+
console.warn(`${[name, keyName].join(".")} is already defined!`);
|
|
430
429
|
} else {
|
|
431
430
|
namespace[keyName] = value;
|
|
432
431
|
}
|
|
433
432
|
}
|
|
434
433
|
}
|
|
435
434
|
|
|
436
|
-
// src/getUserImage.ts
|
|
437
|
-
var sizeMap = {
|
|
438
|
-
xs: 64,
|
|
439
|
-
sm: 128,
|
|
440
|
-
md: 256,
|
|
441
|
-
lg: 512,
|
|
442
|
-
xl: void 0
|
|
443
|
-
};
|
|
444
|
-
function getUserImage(primKeyOrOptions, login, hash, size = "xs") {
|
|
445
|
-
if (primKeyOrOptions && typeof primKeyOrOptions === "object") {
|
|
446
|
-
return getUserImage(primKeyOrOptions.primKey, primKeyOrOptions.login, primKeyOrOptions.hash, primKeyOrOptions.size);
|
|
447
|
-
}
|
|
448
|
-
if (!primKeyOrOptions || !hash) {
|
|
449
|
-
return "";
|
|
450
|
-
}
|
|
451
|
-
let sizePx = sizeMap[size];
|
|
452
|
-
return `/api/data/blob/EmployeesLookup/${primKeyOrOptions}/Image/${encodeURIComponent(login ?? "")}${login ? "." : ""}${encodeURIComponent(hash)}.jpg${sizePx ? `?width=${sizePx}` : ""}`;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
435
|
// src/getLocalizedString.ts
|
|
456
436
|
async function fetchLocalizedString(text) {
|
|
457
437
|
try {
|
|
@@ -467,7 +447,7 @@ async function fetchLocalizedString(text) {
|
|
|
467
447
|
if (response.ok) {
|
|
468
448
|
return await response.json();
|
|
469
449
|
}
|
|
470
|
-
} catch
|
|
450
|
+
} catch {
|
|
471
451
|
}
|
|
472
452
|
return text;
|
|
473
453
|
}
|
|
@@ -495,6 +475,25 @@ function getLocalizedString(string, wait) {
|
|
|
495
475
|
}
|
|
496
476
|
}
|
|
497
477
|
|
|
478
|
+
// src/getUserImage.ts
|
|
479
|
+
var sizeMap = {
|
|
480
|
+
xs: 64,
|
|
481
|
+
sm: 128,
|
|
482
|
+
md: 256,
|
|
483
|
+
lg: 512,
|
|
484
|
+
xl: void 0
|
|
485
|
+
};
|
|
486
|
+
function getUserImage(primKeyOrOptions, login, hash, size = "xs") {
|
|
487
|
+
if (primKeyOrOptions && typeof primKeyOrOptions === "object") {
|
|
488
|
+
return getUserImage(primKeyOrOptions.primKey, primKeyOrOptions.login, primKeyOrOptions.hash, primKeyOrOptions.size);
|
|
489
|
+
}
|
|
490
|
+
if (!primKeyOrOptions || !hash) {
|
|
491
|
+
return "";
|
|
492
|
+
}
|
|
493
|
+
let sizePx = sizeMap[size];
|
|
494
|
+
return `/api/data/blob/EmployeesLookup/${primKeyOrOptions}/Image/${encodeURIComponent(login ?? "")}${login ? "." : ""}${encodeURIComponent(hash)}.jpg${sizePx ? `?width=${sizePx}` : ""}`;
|
|
495
|
+
}
|
|
496
|
+
|
|
498
497
|
// src/localize.ts
|
|
499
498
|
function localize(stringParts, ...args) {
|
|
500
499
|
invariant(
|
|
@@ -504,39 +503,11 @@ function localize(stringParts, ...args) {
|
|
|
504
503
|
let stringToLocalize = stringParts.map((s, i) => i === stringParts.length - 1 ? s : `${s}$${i}`).join("");
|
|
505
504
|
let localized = getLocalizedString(stringToLocalize);
|
|
506
505
|
args.forEach((arg, index) => {
|
|
507
|
-
localized = localized.replace(
|
|
506
|
+
localized = localized.replace(`$${index}`, arg);
|
|
508
507
|
});
|
|
509
508
|
return localized;
|
|
510
509
|
}
|
|
511
510
|
|
|
512
|
-
// src/settings.ts
|
|
513
|
-
function getKey(article2) {
|
|
514
|
-
const articleKey = article2 ?? window.af?.article?.id ?? window.window?.location.pathname.substring(1).split("/")[0];
|
|
515
|
-
return `${articleKey}.${window.af?.userSession.login ?? "anonymous"}`;
|
|
516
|
-
}
|
|
517
|
-
function getSettings(setting, article2) {
|
|
518
|
-
if (!window.af?.userSession)
|
|
519
|
-
return null;
|
|
520
|
-
const key = getKey(article2);
|
|
521
|
-
const settings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
522
|
-
if (setting) {
|
|
523
|
-
return settings[setting] || null;
|
|
524
|
-
}
|
|
525
|
-
return settings;
|
|
526
|
-
}
|
|
527
|
-
function saveSettings(setting, value, article2) {
|
|
528
|
-
if (!window.af?.userSession)
|
|
529
|
-
return;
|
|
530
|
-
const key = getKey(article2);
|
|
531
|
-
let userSettings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
532
|
-
if (typeof value !== "undefined") {
|
|
533
|
-
userSettings[setting] = value;
|
|
534
|
-
} else {
|
|
535
|
-
userSettings = setting;
|
|
536
|
-
}
|
|
537
|
-
localStorage.setItem(key, JSON.stringify(userSettings));
|
|
538
|
-
}
|
|
539
|
-
|
|
540
511
|
// src/alert.ts
|
|
541
512
|
var template = `
|
|
542
513
|
<dialog class="alert-dialog">
|
|
@@ -581,15 +552,15 @@ async function openAlertDialog({ buttons, content, className, id, title }) {
|
|
|
581
552
|
return await alertDialogPromiseMap.get(id);
|
|
582
553
|
}
|
|
583
554
|
let $template = document.querySelector("#AlertDialogTemplate");
|
|
584
|
-
if (!$template)
|
|
585
|
-
throw Error("No alert dialog template found");
|
|
555
|
+
if (!$template) throw Error("No alert dialog template found");
|
|
586
556
|
let $dialog = $template.content.firstElementChild?.cloneNode(true);
|
|
587
557
|
let $content = $dialog?.querySelector("article");
|
|
588
558
|
let $menu = $dialog?.querySelector("footer menu");
|
|
589
|
-
if (!$dialog || !$content || !$menu)
|
|
590
|
-
throw Error("Invalid alert dialog template");
|
|
559
|
+
if (!$dialog || !$content || !$menu) throw Error("Invalid alert dialog template");
|
|
591
560
|
if (className) {
|
|
592
|
-
className.split(/\s+/)
|
|
561
|
+
for (const className_ of className.split(/\s+/)) {
|
|
562
|
+
$dialog?.classList.add(className_);
|
|
563
|
+
}
|
|
593
564
|
}
|
|
594
565
|
if (title) {
|
|
595
566
|
let $header = document.createElement("header");
|
|
@@ -614,8 +585,7 @@ async function openAlertDialog({ buttons, content, className, id, title }) {
|
|
|
614
585
|
if (id && alertDialogPromiseMap.has(id)) {
|
|
615
586
|
alertDialogPromiseMap.delete(id);
|
|
616
587
|
}
|
|
617
|
-
if ($dialog)
|
|
618
|
-
document.body.removeChild($dialog);
|
|
588
|
+
if ($dialog) document.body.removeChild($dialog);
|
|
619
589
|
return returnValue;
|
|
620
590
|
});
|
|
621
591
|
if (id) {
|
|
@@ -649,8 +619,34 @@ async function alert(prompt, options = {}) {
|
|
|
649
619
|
});
|
|
650
620
|
}
|
|
651
621
|
|
|
622
|
+
// src/settings.ts
|
|
623
|
+
function getKey(article2) {
|
|
624
|
+
const articleKey = article2 ?? window.af?.article?.id ?? window.window?.location.pathname.substring(1).split("/")[0];
|
|
625
|
+
return `${articleKey}.${window.af?.userSession.login ?? "anonymous"}`;
|
|
626
|
+
}
|
|
627
|
+
function getSettings(setting, article2) {
|
|
628
|
+
if (!window.af?.userSession) return null;
|
|
629
|
+
const key = getKey(article2);
|
|
630
|
+
const settings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
631
|
+
if (setting) {
|
|
632
|
+
return settings[setting] || null;
|
|
633
|
+
}
|
|
634
|
+
return settings;
|
|
635
|
+
}
|
|
636
|
+
function saveSettings(setting, value, article2) {
|
|
637
|
+
if (!window.af?.userSession) return;
|
|
638
|
+
const key = getKey(article2);
|
|
639
|
+
let userSettings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
640
|
+
if (typeof value !== "undefined") {
|
|
641
|
+
userSettings[setting] = value;
|
|
642
|
+
} else {
|
|
643
|
+
userSettings = setting;
|
|
644
|
+
}
|
|
645
|
+
localStorage.setItem(key, JSON.stringify(userSettings));
|
|
646
|
+
}
|
|
647
|
+
|
|
652
648
|
// src/index.ts
|
|
653
|
-
var version = "2.11.
|
|
649
|
+
var version = "2.11.8";
|
|
654
650
|
export {
|
|
655
651
|
ConfirmButtons,
|
|
656
652
|
SessionHandler,
|
|
@@ -17,10 +17,7 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __publicField = (obj, key, value) =>
|
|
21
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
-
return value;
|
|
23
|
-
};
|
|
20
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
24
21
|
|
|
25
22
|
// ../../node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/dist/mitt.mjs
|
|
26
23
|
function mitt_default(n) {
|
|
@@ -162,7 +159,7 @@ async function logActivity(activity, parameters = {}, timeElapsed = 0) {
|
|
|
162
159
|
console.error("".concat(response.status, " ").concat(response.statusText));
|
|
163
160
|
}
|
|
164
161
|
}
|
|
165
|
-
} catch (
|
|
162
|
+
} catch (e) {
|
|
166
163
|
}
|
|
167
164
|
}
|
|
168
165
|
function startActivity(activity, startParameters = {}) {
|
|
@@ -177,8 +174,7 @@ async function time(callback) {
|
|
|
177
174
|
async function logError(error) {
|
|
178
175
|
var _a3;
|
|
179
176
|
try {
|
|
180
|
-
if (!error)
|
|
181
|
-
return;
|
|
177
|
+
if (!error) return;
|
|
182
178
|
let data = typeof error === "string" ? { error } : typeof error === "object" ? "message" in error ? {
|
|
183
179
|
error: error.message,
|
|
184
180
|
stack: (_a3 = error.stack) != null ? _a3 : null
|
|
@@ -325,7 +321,7 @@ function toLocalDateTime(date) {
|
|
|
325
321
|
|
|
326
322
|
// src/downloadBlob.ts
|
|
327
323
|
function downloadBlob(blob, fileName) {
|
|
328
|
-
return new Promise(
|
|
324
|
+
return new Promise((resolve, reject) => {
|
|
329
325
|
try {
|
|
330
326
|
const url = URL.createObjectURL(blob);
|
|
331
327
|
const parent = document.body;
|
|
@@ -335,7 +331,7 @@ function downloadBlob(blob, fileName) {
|
|
|
335
331
|
parent.append(anchor);
|
|
336
332
|
anchor.click();
|
|
337
333
|
parent.removeChild(anchor);
|
|
338
|
-
setTimeout(
|
|
334
|
+
setTimeout(() => {
|
|
339
335
|
URL.revokeObjectURL(url);
|
|
340
336
|
resolve();
|
|
341
337
|
}, 250);
|
|
@@ -371,9 +367,9 @@ async function downloadRequest(request, { fileName, signal, onProgress }) {
|
|
|
371
367
|
try {
|
|
372
368
|
const reader = response.body.getReader();
|
|
373
369
|
const stream = new ReadableStream({
|
|
374
|
-
start:
|
|
370
|
+
start: (controller) => {
|
|
375
371
|
function pump() {
|
|
376
|
-
return reader.read().then(
|
|
372
|
+
return reader.read().then((read) => {
|
|
377
373
|
if (read.done) {
|
|
378
374
|
controller.close();
|
|
379
375
|
return;
|
|
@@ -388,7 +384,7 @@ async function downloadRequest(request, { fileName, signal, onProgress }) {
|
|
|
388
384
|
}
|
|
389
385
|
});
|
|
390
386
|
response = new Response(stream);
|
|
391
|
-
} catch (
|
|
387
|
+
} catch (e) {
|
|
392
388
|
}
|
|
393
389
|
const blob = await response.blob();
|
|
394
390
|
onProgress == null ? void 0 : onProgress({ bytesReceived, status: "downloaded" });
|
|
@@ -407,7 +403,7 @@ async function downloadRequest(request, { fileName, signal, onProgress }) {
|
|
|
407
403
|
var funcRegex = /^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)*)\}$/;
|
|
408
404
|
function parseFunc(func) {
|
|
409
405
|
var _a3;
|
|
410
|
-
|
|
406
|
+
const match = func.toString().match(funcRegex);
|
|
411
407
|
invariant(match, "Unable to parse function!");
|
|
412
408
|
return { name: (_a3 = func.name) != null ? _a3 : match[1], args: match[2].split(",").map((a) => a.trim()), body: match[3] };
|
|
413
409
|
}
|
|
@@ -464,32 +460,13 @@ function expose(name, value, options = {}) {
|
|
|
464
460
|
invariant(false, "Invalid typeof parameter 'name', or unable to parse pValue!");
|
|
465
461
|
}
|
|
466
462
|
if (Object.hasOwn(namespace, keyName) && (options == null ? void 0 : options.overwrite) !== true) {
|
|
467
|
-
console.warn([name, keyName].join(".")
|
|
463
|
+
console.warn("".concat([name, keyName].join("."), " is already defined!"));
|
|
468
464
|
} else {
|
|
469
465
|
namespace[keyName] = value;
|
|
470
466
|
}
|
|
471
467
|
}
|
|
472
468
|
}
|
|
473
469
|
|
|
474
|
-
// src/getUserImage.ts
|
|
475
|
-
var sizeMap = {
|
|
476
|
-
xs: 64,
|
|
477
|
-
sm: 128,
|
|
478
|
-
md: 256,
|
|
479
|
-
lg: 512,
|
|
480
|
-
xl: void 0
|
|
481
|
-
};
|
|
482
|
-
function getUserImage(primKeyOrOptions, login, hash, size = "xs") {
|
|
483
|
-
if (primKeyOrOptions && typeof primKeyOrOptions === "object") {
|
|
484
|
-
return getUserImage(primKeyOrOptions.primKey, primKeyOrOptions.login, primKeyOrOptions.hash, primKeyOrOptions.size);
|
|
485
|
-
}
|
|
486
|
-
if (!primKeyOrOptions || !hash) {
|
|
487
|
-
return "";
|
|
488
|
-
}
|
|
489
|
-
let sizePx = sizeMap[size];
|
|
490
|
-
return "/api/data/blob/EmployeesLookup/".concat(primKeyOrOptions, "/Image/").concat(encodeURIComponent(login != null ? login : "")).concat(login ? "." : "").concat(encodeURIComponent(hash), ".jpg").concat(sizePx ? "?width=".concat(sizePx) : "");
|
|
491
|
-
}
|
|
492
|
-
|
|
493
470
|
// src/getLocalizedString.ts
|
|
494
471
|
async function fetchLocalizedString(text) {
|
|
495
472
|
try {
|
|
@@ -505,7 +482,7 @@ async function fetchLocalizedString(text) {
|
|
|
505
482
|
if (response.ok) {
|
|
506
483
|
return await response.json();
|
|
507
484
|
}
|
|
508
|
-
} catch (
|
|
485
|
+
} catch (e) {
|
|
509
486
|
}
|
|
510
487
|
return text;
|
|
511
488
|
}
|
|
@@ -534,6 +511,25 @@ function getLocalizedString(string, wait) {
|
|
|
534
511
|
}
|
|
535
512
|
}
|
|
536
513
|
|
|
514
|
+
// src/getUserImage.ts
|
|
515
|
+
var sizeMap = {
|
|
516
|
+
xs: 64,
|
|
517
|
+
sm: 128,
|
|
518
|
+
md: 256,
|
|
519
|
+
lg: 512,
|
|
520
|
+
xl: void 0
|
|
521
|
+
};
|
|
522
|
+
function getUserImage(primKeyOrOptions, login, hash, size = "xs") {
|
|
523
|
+
if (primKeyOrOptions && typeof primKeyOrOptions === "object") {
|
|
524
|
+
return getUserImage(primKeyOrOptions.primKey, primKeyOrOptions.login, primKeyOrOptions.hash, primKeyOrOptions.size);
|
|
525
|
+
}
|
|
526
|
+
if (!primKeyOrOptions || !hash) {
|
|
527
|
+
return "";
|
|
528
|
+
}
|
|
529
|
+
let sizePx = sizeMap[size];
|
|
530
|
+
return "/api/data/blob/EmployeesLookup/".concat(primKeyOrOptions, "/Image/").concat(encodeURIComponent(login != null ? login : "")).concat(login ? "." : "").concat(encodeURIComponent(hash), ".jpg").concat(sizePx ? "?width=".concat(sizePx) : "");
|
|
531
|
+
}
|
|
532
|
+
|
|
537
533
|
// src/localize.ts
|
|
538
534
|
function localize(stringParts, ...args) {
|
|
539
535
|
invariant(
|
|
@@ -543,42 +539,11 @@ function localize(stringParts, ...args) {
|
|
|
543
539
|
let stringToLocalize = stringParts.map((s, i) => i === stringParts.length - 1 ? s : "".concat(s, "$").concat(i)).join("");
|
|
544
540
|
let localized = getLocalizedString(stringToLocalize);
|
|
545
541
|
args.forEach((arg, index) => {
|
|
546
|
-
localized = localized.replace("$"
|
|
542
|
+
localized = localized.replace("$".concat(index), arg);
|
|
547
543
|
});
|
|
548
544
|
return localized;
|
|
549
545
|
}
|
|
550
546
|
|
|
551
|
-
// src/settings.ts
|
|
552
|
-
function getKey(article2) {
|
|
553
|
-
var _a3, _b2, _c2, _d2, _e, _f;
|
|
554
|
-
const articleKey = (_d2 = article2 != null ? article2 : (_b2 = (_a3 = window.af) == null ? void 0 : _a3.article) == null ? void 0 : _b2.id) != null ? _d2 : (_c2 = window.window) == null ? void 0 : _c2.location.pathname.substring(1).split("/")[0];
|
|
555
|
-
return "".concat(articleKey, ".").concat((_f = (_e = window.af) == null ? void 0 : _e.userSession.login) != null ? _f : "anonymous");
|
|
556
|
-
}
|
|
557
|
-
function getSettings(setting, article2) {
|
|
558
|
-
var _a3;
|
|
559
|
-
if (!((_a3 = window.af) == null ? void 0 : _a3.userSession))
|
|
560
|
-
return null;
|
|
561
|
-
const key = getKey(article2);
|
|
562
|
-
const settings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
563
|
-
if (setting) {
|
|
564
|
-
return settings[setting] || null;
|
|
565
|
-
}
|
|
566
|
-
return settings;
|
|
567
|
-
}
|
|
568
|
-
function saveSettings(setting, value, article2) {
|
|
569
|
-
var _a3;
|
|
570
|
-
if (!((_a3 = window.af) == null ? void 0 : _a3.userSession))
|
|
571
|
-
return;
|
|
572
|
-
const key = getKey(article2);
|
|
573
|
-
let userSettings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
574
|
-
if (typeof value !== "undefined") {
|
|
575
|
-
userSettings[setting] = value;
|
|
576
|
-
} else {
|
|
577
|
-
userSettings = setting;
|
|
578
|
-
}
|
|
579
|
-
localStorage.setItem(key, JSON.stringify(userSettings));
|
|
580
|
-
}
|
|
581
|
-
|
|
582
547
|
// src/alert.ts
|
|
583
548
|
var template = '\n <dialog class="alert-dialog">\n <form method="dialog">\n <article></article>\n <footer>\n <menu></menu>\n </footer>\n </form>\n </dialog>\n';
|
|
584
549
|
if (window.document && !document.querySelector("#AlertDialogTemplate")) {
|
|
@@ -615,15 +580,15 @@ async function openAlertDialog({ buttons, content, className, id, title }) {
|
|
|
615
580
|
return await alertDialogPromiseMap.get(id);
|
|
616
581
|
}
|
|
617
582
|
let $template = document.querySelector("#AlertDialogTemplate");
|
|
618
|
-
if (!$template)
|
|
619
|
-
throw Error("No alert dialog template found");
|
|
583
|
+
if (!$template) throw Error("No alert dialog template found");
|
|
620
584
|
let $dialog = (_a3 = $template.content.firstElementChild) == null ? void 0 : _a3.cloneNode(true);
|
|
621
585
|
let $content = $dialog == null ? void 0 : $dialog.querySelector("article");
|
|
622
586
|
let $menu = $dialog == null ? void 0 : $dialog.querySelector("footer menu");
|
|
623
|
-
if (!$dialog || !$content || !$menu)
|
|
624
|
-
throw Error("Invalid alert dialog template");
|
|
587
|
+
if (!$dialog || !$content || !$menu) throw Error("Invalid alert dialog template");
|
|
625
588
|
if (className) {
|
|
626
|
-
className.split(/\s+/)
|
|
589
|
+
for (const className_ of className.split(/\s+/)) {
|
|
590
|
+
$dialog == null ? void 0 : $dialog.classList.add(className_);
|
|
591
|
+
}
|
|
627
592
|
}
|
|
628
593
|
if (title) {
|
|
629
594
|
let $header = document.createElement("header");
|
|
@@ -648,8 +613,7 @@ async function openAlertDialog({ buttons, content, className, id, title }) {
|
|
|
648
613
|
if (id && alertDialogPromiseMap.has(id)) {
|
|
649
614
|
alertDialogPromiseMap.delete(id);
|
|
650
615
|
}
|
|
651
|
-
if ($dialog)
|
|
652
|
-
document.body.removeChild($dialog);
|
|
616
|
+
if ($dialog) document.body.removeChild($dialog);
|
|
653
617
|
return returnValue;
|
|
654
618
|
});
|
|
655
619
|
if (id) {
|
|
@@ -682,8 +646,37 @@ async function alert(prompt, options = {}) {
|
|
|
682
646
|
}, options));
|
|
683
647
|
}
|
|
684
648
|
|
|
649
|
+
// src/settings.ts
|
|
650
|
+
function getKey(article2) {
|
|
651
|
+
var _a3, _b2, _c2, _d2, _e, _f;
|
|
652
|
+
const articleKey = (_d2 = article2 != null ? article2 : (_b2 = (_a3 = window.af) == null ? void 0 : _a3.article) == null ? void 0 : _b2.id) != null ? _d2 : (_c2 = window.window) == null ? void 0 : _c2.location.pathname.substring(1).split("/")[0];
|
|
653
|
+
return "".concat(articleKey, ".").concat((_f = (_e = window.af) == null ? void 0 : _e.userSession.login) != null ? _f : "anonymous");
|
|
654
|
+
}
|
|
655
|
+
function getSettings(setting, article2) {
|
|
656
|
+
var _a3;
|
|
657
|
+
if (!((_a3 = window.af) == null ? void 0 : _a3.userSession)) return null;
|
|
658
|
+
const key = getKey(article2);
|
|
659
|
+
const settings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
660
|
+
if (setting) {
|
|
661
|
+
return settings[setting] || null;
|
|
662
|
+
}
|
|
663
|
+
return settings;
|
|
664
|
+
}
|
|
665
|
+
function saveSettings(setting, value, article2) {
|
|
666
|
+
var _a3;
|
|
667
|
+
if (!((_a3 = window.af) == null ? void 0 : _a3.userSession)) return;
|
|
668
|
+
const key = getKey(article2);
|
|
669
|
+
let userSettings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
670
|
+
if (typeof value !== "undefined") {
|
|
671
|
+
userSettings[setting] = value;
|
|
672
|
+
} else {
|
|
673
|
+
userSettings = setting;
|
|
674
|
+
}
|
|
675
|
+
localStorage.setItem(key, JSON.stringify(userSettings));
|
|
676
|
+
}
|
|
677
|
+
|
|
685
678
|
// src/index.ts
|
|
686
|
-
var version = "2.11.
|
|
679
|
+
var version = "2.11.8";
|
|
687
680
|
export {
|
|
688
681
|
ConfirmButtons,
|
|
689
682
|
SessionHandler,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var oe=Object.defineProperty,re=Object.defineProperties;var ie=Object.getOwnPropertyDescriptors;var $=Object.getOwnPropertySymbols;var ae=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var A=(e,t,o)=>t in e?oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,g=(e,t)=>{for(var o in t||(t={}))ae.call(t,o)&&A(e,o,t[o]);if($)for(var o of $(t))le.call(t,o)&&A(e,o,t[o]);return e},C=(e,t)=>re(e,ie(t));var l=(e,t,o)=>(A(e,typeof t!="symbol"?t+"":t,o),o);function I(e){return{all:e=e||new Map,on:function(t,o){var n=e.get(t);n?n.push(o):e.set(t,[o])},off:function(t,o){var n=e.get(t);n&&(o?n.splice(n.indexOf(o)>>>0,1):e.set(t,[]))},emit:function(t,o){var n=e.get(t);n&&n.slice().map(function(r){r(o)}),(n=e.get("*"))&&n.slice().map(function(r){r(t,o)})}}}var m=class{constructor(){l(this,"eventHandler",I())}authenticated(){this.eventHandler.emit("onAuthenticated")}async expired(t,o){try{let n=new Promise(i=>{let a=()=>{this.eventHandler.off("onAuthenticated",a),t==null||t(),i()};this.eventHandler.on("onAuthenticated",a)}),r=document.querySelector("dialog.session-expired-dialog");if(r)await n;else{r=document.createElement("dialog"),r.className="session-expired-dialog",r.style.display="flex",r.style.padding="0",r.style.left="50%",r.style.transform="translateX(-50%)";let i="/login?ReturnUrl=%2fapi/sessionexpired/remove";o!=="RequireTwoFactor"?await fetch("/logout",{method:"POST"}):i="/login?RequireTwoFactor=1&ReturnUrl=%2fapi/sessionexpired/remove",r.innerHTML='<iframe sandbox="allow-same-origin allow-scripts allow-modals allow-top-navigation-by-user-activation allow-forms" src="'.concat(i,'" style="border:0;width:min(500px,100vw);height:min(700px, 100vh);"></iframe>'),document.body.append(r),r.showModal(),await n,r.remove()}}catch(n){window.location.href="/login?ReturnUrl=".concat(encodeURIComponent(window.location.pathname)).concat(encodeURIComponent(window.location.search))}}attachEvent(t,o){return this.eventHandler.on(t,o)}detachEvent(t,o){return this.eventHandler.off(t,o)}};var L=class extends m{constructor(o){super();l(this,"amDesignator","a.m.");l(this,"dayNames",["sunday","monday","tuesday","wednesday","thursday","friday","saturday"]);l(this,"dayNamesShort",["sun","mon","tue","wed","thu","fri","sat"]);l(this,"decimalSeparator",".");l(this,"domain","OB");l(this,"email");l(this,"formats");l(this,"groupSeparator",null);l(this,"integratedSecurity",!1);l(this,"isDeveloper",!1);l(this,"login","");l(this,"loginType");l(this,"monthNames",["january","february","march","april","may","june","july","august","september","october","november","december",""]);l(this,"monthNamesShort",["jan","feb","mar","apr","may","jun","jul","augt","sep","oct","nov","dec",""]);l(this,"name");l(this,"pmDesignator","p.m.");l(this,"shortDateFormat","dd.MM.yyyy");l(this,"culture","en-GB");l(this,"uiculture","en-GB");this.formats={},Object.assign(this,o)}};var _,H,M,q,k=(q=(H=(_=window.af)==null?void 0:_.article)==null?void 0:H.id)!=null?q:(M=window.window)==null?void 0:M.location.pathname.substring(1).split("/")[0];async function T(e,t={},o=0){var n;try{let r=await fetch("/api/logging/log-activity",{method:"POST",body:JSON.stringify({article:k,timeElapsed:o,action:e,parameters:C(g({},t),{_session:E()})}),headers:{"Content-Type":"application/json",Accept:"application/json"}});if(!r.ok)if((n=r.headers.get("Content-Type"))!=null&&n.includes("application/json")){let i=await r.json();console.error(i.error)}else console.error("".concat(r.status," ").concat(r.statusText))}catch(r){}}function se(e,t={}){let o=performance.now();return(n={})=>T(e,g(g({},t),n),performance.now()-o)}async function ce(e){let t=performance.now();return[await e(),performance.now()-t]}async function D(e){var t;try{if(!e)return;let o=typeof e=="string"?{error:e}:typeof e=="object"?"message"in e?{error:e.message,stack:(t=e.stack)!=null?t:null}:{error:e.toString()}:{error:"Unspecified error"};console.error(e);let n=await fetch("/data/Logger/LogError",{method:"POST",body:JSON.stringify(o),headers:{"Content-Type":"application/json; charset=utf-8"}});if(n.ok)return await n.json();console.error(Error("Failed to log error"))}catch(o){}}function B(){var e;return(e=crypto.randomUUID)==null?void 0:e.call(crypto)}var U=Date.now(),F=B(),S="",x="";if("document"in window){let e=()=>{var t,o,n,r,i,a;return T("AfSessionInit",{"appframe-core":(o=(t=window.af)==null?void 0:t.common)==null?void 0:o.version,"appframe-data":(r=(n=window.af)==null?void 0:n.data)==null?void 0:r.version,"app-version":(a=(i=window.af)==null?void 0:i.article)==null?void 0:a.version})};document.addEventListener("DOMContentLoaded",()=>{S=localStorage.getItem("_afDeviceId"),x=sessionStorage.getItem("_afSessionId"),S||(S=B(),localStorage.setItem("_afDeviceId",S)),x||(x=F,sessionStorage.setItem("_afSessionId",x)),e()}),document.addEventListener("visibilitychange",function(){document.visibilityState==="hidden"?navigator.sendBeacon("/api/logging/log-activity",JSON.stringify({article:k,action:"AfSessionEnd",parameters:{_session:E()}})):e()})}function E(){return{browserSessionId:x,sessionStart:U,sessionLength:Date.now()-U,sessionId:F,deviceId:S}}var J;(J=window.window)==null||J.addEventListener("error",e=>{typeof e=="object"&&"error"in e?D(e.error):typeof e=="object"&&"message"in e&&D(e)});function K(e){var t;return[((t=af==null?void 0:af.article)==null?void 0:t.id)||"","common",e].join(".")}var z=class{constructor(){l(this,"isPersisted",()=>!0)}getLocalStorageKey(t,o){return o?["common",t].join("."):K(t)}get(t,o,n){let r=this.getLocalStorageKey(t,n),i=localStorage.getItem(r);return i!==null?JSON.parse(i):o}set(t,o,n){localStorage.setItem(this.getLocalStorageKey(t,n),JSON.stringify(o))}remove(t,o){let n=this.getLocalStorageKey(t,o);return localStorage.getItem(n)!==null?(localStorage.removeItem(n),!0):!1}clear(){let t=K("");for(let o in localStorage)o.slice(0,t.length)===t&&localStorage.removeItem(o)}},ue=new z;function de(e){return e?V(e).substring(0,10):null}function p(e,t=2){return String(e).padStart(t,"0")}function V(e){return e?"".concat(e.getFullYear(),"-").concat(p(e.getMonth()+1),"-").concat(p(e.getDate()),"T").concat(p(e.getHours()),":").concat(p(e.getMinutes()),":").concat(p(e.getSeconds()),".").concat(p(e.getMilliseconds(),3)):null}function fe(e){return e?e.toISOString().substring(0,16):""}function O(e,t){return new Promise(function(o,n){try{let r=URL.createObjectURL(e),i=document.body,a=document.createElement("a");a.setAttribute("download",t),a.href=r,i.append(a),a.click(),i.removeChild(a),setTimeout(function(){URL.revokeObjectURL(r),o()},250)}catch(r){n(r)}})}function c(e,t){if(e)return;let o=typeof t=="function"?t():t;throw new Error(o!=null?o:"Invariant failed")}async function ge(e,{fileName:t,signal:o,onProgress:n}){var i;let r=0;n==null||n({status:"requested"});try{let a=await fetch(e);if(!a.ok||!a.body){if((i=a.headers.get("content-type"))!=null&&i.includes("application/json")){let f=await a.json();c(!f.error,f.error)}throw new Error("".concat(a.status," ").concat(a.statusText))}try{let f=a.body.getReader(),v=new ReadableStream({start:function(y){function h(){return f.read().then(function(s){if(s.done){y.close();return}return r+=s.value.length,n==null||n({bytesReceived:r,status:"downloading"}),y.enqueue(s.value),h()})}return h()}});a=new Response(v)}catch(f){}let u=await a.blob();n==null||n({bytesReceived:r,status:"downloaded"}),await O(u,t),n==null||n({bytesReceived:r,status:"completed"})}catch(a){o!=null&&o.aborted?n==null||n({status:"cancelled"}):n==null||n({error:a.message,status:"error"})}}var me=/^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)*)\}$/;function j(e){var o;var t=e.toString().match(me);return c(t,"Unable to parse function!"),{name:(o=e.name)!=null?o:t[1],args:t[2].split(",").map(n=>n.trim()),body:t[3]}}function Z(){}Z.prototype=Object.create(null);var Y=Z;function N(e,t){if(typeof e=="object"){if(typeof t=="string"){let o=t.split(".");return N(e,o)}else if(Array.isArray(t)){let o=e;for(let n=0;n<t.length;n++)o=o[t[n]]=o[t[n]]||new Y;return o}}}function X(e,t,o={}){if(Array.isArray(t))for(let n of t){let{name:r}=j(n);c(r,"Unable to detect name of function! Name it, or only supply one function and include name in first parameter."),X(e,n)}else{let n,r;if(typeof t=="function"&&(n=j(t).name),typeof e=="string"){let i=e.split(".");n||(n=i[i.length-1],i=i.slice(0,i.length-1)),r=N(window,i)}else n&&(typeof e=="object"||typeof e=="function")?r=e:c(!1,"Invalid typeof parameter 'name', or unable to parse pValue!");Object.hasOwn(r,n)&&(o==null?void 0:o.overwrite)!==!0?console.warn([e,n].join(".")+" is already defined!"):r[n]=t}}var pe={xs:64,sm:128,md:256,lg:512,xl:void 0};function G(e,t,o,n="xs"){if(e&&typeof e=="object")return G(e.primKey,e.login,e.hash,e.size);if(!e||!o)return"";let r=pe[n];return"/api/data/blob/EmployeesLookup/".concat(e,"/Image/").concat(encodeURIComponent(t!=null?t:"")).concat(t?".":"").concat(encodeURIComponent(o),".jpg").concat(r?"?width=".concat(r):"")}async function ye(e){try{let t=await fetch("/api/user/localize/new/".concat(af.article.id),{body:JSON.stringify({text:e}),headers:{Accept:"application/json; */*","Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},method:"POST"});if(t.ok)return await t.json()}catch(t){}return e}function d(e,t){var o,n;if(typeof e=="string"&&e.trim().length===0)return e;if(!(e===void 0||e===""||e===null))if(((n=(o=window.af)==null?void 0:o.article)==null?void 0:n.i18n)!==void 0){if(!Object.hasOwn(af.article.i18n,e)){af.article.i18n[e]=e;let r=ye(e).then(i=>(af.article.i18n[e]=i,i));if(t)return r}return af.article.i18n[e]}else return e}function he(e,...t){c(Array.isArray(e)&&e.length===t.length+1,"Method 'localize' must be used as a tag function");let o=e.map((r,i)=>i===e.length-1?r:"".concat(r,"$").concat(i)).join(""),n=d(o);return t.forEach((r,i)=>{n=n.replace("$"+i,r)}),n}function W(e){var o,n,r,i,a,u;let t=(i=e!=null?e:(n=(o=window.af)==null?void 0:o.article)==null?void 0:n.id)!=null?i:(r=window.window)==null?void 0:r.location.pathname.substring(1).split("/")[0];return"".concat(t,".").concat((u=(a=window.af)==null?void 0:a.userSession.login)!=null?u:"anonymous")}function be(e,t){var r;if(!((r=window.af)!=null&&r.userSession))return null;let o=W(t),n=JSON.parse(localStorage.getItem(o)||"{}");return e?n[e]||null:n}function Se(e,t,o){var i;if(!((i=window.af)!=null&&i.userSession))return;let n=W(o),r=JSON.parse(localStorage.getItem(n)||"{}");typeof t<"u"?r[e]=t:r=e,localStorage.setItem(n,JSON.stringify(r))}var xe='\n <dialog class="alert-dialog">\n <form method="dialog">\n <article></article>\n <footer>\n <menu></menu>\n </footer>\n </form>\n </dialog>\n';if(window.document&&!document.querySelector("#AlertDialogTemplate")){let e=document.createElement("template");e.id="AlertDialogTemplate",e.innerHTML=xe,document.body.append(e)}function Q(e,t="No"){return new Promise(o=>{let n=new AbortController;e.addEventListener("close",()=>{o(e.returnValue),n.abort()},{signal:n.signal}),e.addEventListener("cancel",()=>{o(t),n.abort()},{signal:n.signal})})}var w=new Map;async function R({buttons:e,content:t,className:o,id:n,title:r}){var y,h;if(n&&w.has(n))return await w.get(n);let i=document.querySelector("#AlertDialogTemplate");if(!i)throw Error("No alert dialog template found");let a=(y=i.content.firstElementChild)==null?void 0:y.cloneNode(!0),u=a==null?void 0:a.querySelector("article"),f=a==null?void 0:a.querySelector("footer menu");if(!a||!u||!f)throw Error("Invalid alert dialog template");if(o&&o.split(/\s+/).forEach(s=>a==null?void 0:a.classList.add(s)),r){let s=document.createElement("header");s.append(r),(h=u.parentNode)==null||h.insertBefore(s,u)}u.appendChild(typeof t=="string"?document.createTextNode(t):t);for(let{label:s,value:ee,primary:te}of e){let ne=document.createElement("li"),b=document.createElement("button");b.value=ee,te&&b.classList.add("primary"),b.textContent=s,ne.appendChild(b),f.appendChild(b)}document.body.appendChild(a),a.showModal();let v=Q(a).then(s=>(n&&w.has(n)&&w.delete(n),a&&document.body.removeChild(a),s));return n&&w.set(n,v),await v}var P=(o=>(o[o.YesNo=0]="YesNo",o[o.OkCancel=1]="OkCancel",o))(P||{});async function we(e,t={}){let{buttons:o=0,title:n}=t,r=o===1?[{label:d("OK"),value:"yes",primary:!0},{label:d("Cancel"),value:"no"}]:[{label:d("Yes"),value:"yes",primary:!0},{label:d("No"),value:"no"}];return await R({content:e,buttons:r,className:"alert-dialog-confirm",title:n})==="yes"}async function ve(e,t={}){await R(g({content:e,className:"alert-dialog-alert",buttons:[{label:d("OK"),value:"ok",primary:!0}]},t))}var dt="2.11.6";export{P as ConfirmButtons,m as SessionHandler,L as UserSession,ve as alert,we as confirm,O as downloadBlob,ge as downloadRequest,X as expose,d as getLocalizedString,E as getSessionData,be as getSettings,G as getUserImage,c as invariant,ue as localStorage,he as localize,T as logActivity,D as logError,I as mitt,R as openAlertDialog,Se as saveSettings,se as startActivity,ce as time,fe as toLocalDateTime,de as toLocalISODate,V as toLocalISODateTime,dt as version,Q as waitForDialog};
|
|
1
|
+
var oe=Object.defineProperty,re=Object.defineProperties;var ie=Object.getOwnPropertyDescriptors;var R=Object.getOwnPropertySymbols;var ae=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var A=(e,t,o)=>t in e?oe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,p=(e,t)=>{for(var o in t||(t={}))ae.call(t,o)&&A(e,o,t[o]);if(R)for(var o of R(t))le.call(t,o)&&A(e,o,t[o]);return e},C=(e,t)=>re(e,ie(t));var l=(e,t,o)=>A(e,typeof t!="symbol"?t+"":t,o);function I(e){return{all:e=e||new Map,on:function(t,o){var n=e.get(t);n?n.push(o):e.set(t,[o])},off:function(t,o){var n=e.get(t);n&&(o?n.splice(n.indexOf(o)>>>0,1):e.set(t,[]))},emit:function(t,o){var n=e.get(t);n&&n.slice().map(function(r){r(o)}),(n=e.get("*"))&&n.slice().map(function(r){r(t,o)})}}}var g=class{constructor(){l(this,"eventHandler",I())}authenticated(){this.eventHandler.emit("onAuthenticated")}async expired(t,o){try{let n=new Promise(i=>{let a=()=>{this.eventHandler.off("onAuthenticated",a),t==null||t(),i()};this.eventHandler.on("onAuthenticated",a)}),r=document.querySelector("dialog.session-expired-dialog");if(r)await n;else{r=document.createElement("dialog"),r.className="session-expired-dialog",r.style.display="flex",r.style.padding="0",r.style.left="50%",r.style.transform="translateX(-50%)";let i="/login?ReturnUrl=%2fapi/sessionexpired/remove";o!=="RequireTwoFactor"?await fetch("/logout",{method:"POST"}):i="/login?RequireTwoFactor=1&ReturnUrl=%2fapi/sessionexpired/remove",r.innerHTML='<iframe sandbox="allow-same-origin allow-scripts allow-modals allow-top-navigation-by-user-activation allow-forms" src="'.concat(i,'" style="border:0;width:min(500px,100vw);height:min(700px, 100vh);"></iframe>'),document.body.append(r),r.showModal(),await n,r.remove()}}catch(n){window.location.href="/login?ReturnUrl=".concat(encodeURIComponent(window.location.pathname)).concat(encodeURIComponent(window.location.search))}}attachEvent(t,o){return this.eventHandler.on(t,o)}detachEvent(t,o){return this.eventHandler.off(t,o)}};var L=class extends g{constructor(o){super();l(this,"amDesignator","a.m.");l(this,"dayNames",["sunday","monday","tuesday","wednesday","thursday","friday","saturday"]);l(this,"dayNamesShort",["sun","mon","tue","wed","thu","fri","sat"]);l(this,"decimalSeparator",".");l(this,"domain","OB");l(this,"email");l(this,"formats");l(this,"groupSeparator",null);l(this,"integratedSecurity",!1);l(this,"isDeveloper",!1);l(this,"login","");l(this,"loginType");l(this,"monthNames",["january","february","march","april","may","june","july","august","september","october","november","december",""]);l(this,"monthNamesShort",["jan","feb","mar","apr","may","jun","jul","augt","sep","oct","nov","dec",""]);l(this,"name");l(this,"pmDesignator","p.m.");l(this,"shortDateFormat","dd.MM.yyyy");l(this,"culture","en-GB");l(this,"uiculture","en-GB");this.formats={},Object.assign(this,o)}};var U,H,M,q,k=(q=(H=(U=window.af)==null?void 0:U.article)==null?void 0:H.id)!=null?q:(M=window.window)==null?void 0:M.location.pathname.substring(1).split("/")[0];async function T(e,t={},o=0){var n;try{let r=await fetch("/api/logging/log-activity",{method:"POST",body:JSON.stringify({article:k,timeElapsed:o,action:e,parameters:C(p({},t),{_session:E()})}),headers:{"Content-Type":"application/json",Accept:"application/json"}});if(!r.ok)if((n=r.headers.get("Content-Type"))!=null&&n.includes("application/json")){let i=await r.json();console.error(i.error)}else console.error("".concat(r.status," ").concat(r.statusText))}catch(r){}}function se(e,t={}){let o=performance.now();return(n={})=>T(e,p(p({},t),n),performance.now()-o)}async function ce(e){let t=performance.now();return[await e(),performance.now()-t]}async function D(e){var t;try{if(!e)return;let o=typeof e=="string"?{error:e}:typeof e=="object"?"message"in e?{error:e.message,stack:(t=e.stack)!=null?t:null}:{error:e.toString()}:{error:"Unspecified error"};console.error(e);let n=await fetch("/data/Logger/LogError",{method:"POST",body:JSON.stringify(o),headers:{"Content-Type":"application/json; charset=utf-8"}});if(n.ok)return await n.json();console.error(Error("Failed to log error"))}catch(o){}}function B(){var e;return(e=crypto.randomUUID)==null?void 0:e.call(crypto)}var _=Date.now(),F=B(),b="",x="";if("document"in window){let e=()=>{var t,o,n,r,i,a;return T("AfSessionInit",{"appframe-core":(o=(t=window.af)==null?void 0:t.common)==null?void 0:o.version,"appframe-data":(r=(n=window.af)==null?void 0:n.data)==null?void 0:r.version,"app-version":(a=(i=window.af)==null?void 0:i.article)==null?void 0:a.version})};document.addEventListener("DOMContentLoaded",()=>{b=localStorage.getItem("_afDeviceId"),x=sessionStorage.getItem("_afSessionId"),b||(b=B(),localStorage.setItem("_afDeviceId",b)),x||(x=F,sessionStorage.setItem("_afSessionId",x)),e()}),document.addEventListener("visibilitychange",function(){document.visibilityState==="hidden"?navigator.sendBeacon("/api/logging/log-activity",JSON.stringify({article:k,action:"AfSessionEnd",parameters:{_session:E()}})):e()})}function E(){return{browserSessionId:x,sessionStart:_,sessionLength:Date.now()-_,sessionId:F,deviceId:b}}var J;(J=window.window)==null||J.addEventListener("error",e=>{typeof e=="object"&&"error"in e?D(e.error):typeof e=="object"&&"message"in e&&D(e)});function K(e){var t;return[((t=af==null?void 0:af.article)==null?void 0:t.id)||"","common",e].join(".")}var j=class{constructor(){l(this,"isPersisted",()=>!0)}getLocalStorageKey(t,o){return o?["common",t].join("."):K(t)}get(t,o,n){let r=this.getLocalStorageKey(t,n),i=localStorage.getItem(r);return i!==null?JSON.parse(i):o}set(t,o,n){localStorage.setItem(this.getLocalStorageKey(t,n),JSON.stringify(o))}remove(t,o){let n=this.getLocalStorageKey(t,o);return localStorage.getItem(n)!==null?(localStorage.removeItem(n),!0):!1}clear(){let t=K("");for(let o in localStorage)o.slice(0,t.length)===t&&localStorage.removeItem(o)}},ue=new j;function de(e){return e?V(e).substring(0,10):null}function m(e,t=2){return String(e).padStart(t,"0")}function V(e){return e?"".concat(e.getFullYear(),"-").concat(m(e.getMonth()+1),"-").concat(m(e.getDate()),"T").concat(m(e.getHours()),":").concat(m(e.getMinutes()),":").concat(m(e.getSeconds()),".").concat(m(e.getMilliseconds(),3)):null}function fe(e){return e?e.toISOString().substring(0,16):""}function z(e,t){return new Promise((o,n)=>{try{let r=URL.createObjectURL(e),i=document.body,a=document.createElement("a");a.setAttribute("download",t),a.href=r,i.append(a),a.click(),i.removeChild(a),setTimeout(()=>{URL.revokeObjectURL(r),o()},250)}catch(r){n(r)}})}function c(e,t){if(e)return;let o=typeof t=="function"?t():t;throw new Error(o!=null?o:"Invariant failed")}async function pe(e,{fileName:t,signal:o,onProgress:n}){var i;let r=0;n==null||n({status:"requested"});try{let a=await fetch(e);if(!a.ok||!a.body){if((i=a.headers.get("content-type"))!=null&&i.includes("application/json")){let f=await a.json();c(!f.error,f.error)}throw new Error("".concat(a.status," ").concat(a.statusText))}try{let f=a.body.getReader(),v=new ReadableStream({start:y=>{function h(){return f.read().then(s=>{if(s.done){y.close();return}return r+=s.value.length,n==null||n({bytesReceived:r,status:"downloading"}),y.enqueue(s.value),h()})}return h()}});a=new Response(v)}catch(f){}let u=await a.blob();n==null||n({bytesReceived:r,status:"downloaded"}),await z(u,t),n==null||n({bytesReceived:r,status:"completed"})}catch(a){o!=null&&o.aborted?n==null||n({status:"cancelled"}):n==null||n({error:a.message,status:"error"})}}var ge=/^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)*)\}$/;function O(e){var o;let t=e.toString().match(ge);return c(t,"Unable to parse function!"),{name:(o=e.name)!=null?o:t[1],args:t[2].split(",").map(n=>n.trim()),body:t[3]}}function Z(){}Z.prototype=Object.create(null);var Y=Z;function N(e,t){if(typeof e=="object"){if(typeof t=="string"){let o=t.split(".");return N(e,o)}else if(Array.isArray(t)){let o=e;for(let n=0;n<t.length;n++)o=o[t[n]]=o[t[n]]||new Y;return o}}}function X(e,t,o={}){if(Array.isArray(t))for(let n of t){let{name:r}=O(n);c(r,"Unable to detect name of function! Name it, or only supply one function and include name in first parameter."),X(e,n)}else{let n,r;if(typeof t=="function"&&(n=O(t).name),typeof e=="string"){let i=e.split(".");n||(n=i[i.length-1],i=i.slice(0,i.length-1)),r=N(window,i)}else n&&(typeof e=="object"||typeof e=="function")?r=e:c(!1,"Invalid typeof parameter 'name', or unable to parse pValue!");Object.hasOwn(r,n)&&(o==null?void 0:o.overwrite)!==!0?console.warn("".concat([e,n].join(".")," is already defined!")):r[n]=t}}async function me(e){try{let t=await fetch("/api/user/localize/new/".concat(af.article.id),{body:JSON.stringify({text:e}),headers:{Accept:"application/json; */*","Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},method:"POST"});if(t.ok)return await t.json()}catch(t){}return e}function d(e,t){var o,n;if(typeof e=="string"&&e.trim().length===0)return e;if(!(e===void 0||e===""||e===null))if(((n=(o=window.af)==null?void 0:o.article)==null?void 0:n.i18n)!==void 0){if(!Object.hasOwn(af.article.i18n,e)){af.article.i18n[e]=e;let r=me(e).then(i=>(af.article.i18n[e]=i,i));if(t)return r}return af.article.i18n[e]}else return e}var ye={xs:64,sm:128,md:256,lg:512,xl:void 0};function G(e,t,o,n="xs"){if(e&&typeof e=="object")return G(e.primKey,e.login,e.hash,e.size);if(!e||!o)return"";let r=ye[n];return"/api/data/blob/EmployeesLookup/".concat(e,"/Image/").concat(encodeURIComponent(t!=null?t:"")).concat(t?".":"").concat(encodeURIComponent(o),".jpg").concat(r?"?width=".concat(r):"")}function he(e,...t){c(Array.isArray(e)&&e.length===t.length+1,"Method 'localize' must be used as a tag function");let o=e.map((r,i)=>i===e.length-1?r:"".concat(r,"$").concat(i)).join(""),n=d(o);return t.forEach((r,i)=>{n=n.replace("$".concat(i),r)}),n}var Se='\n <dialog class="alert-dialog">\n <form method="dialog">\n <article></article>\n <footer>\n <menu></menu>\n </footer>\n </form>\n </dialog>\n';if(window.document&&!document.querySelector("#AlertDialogTemplate")){let e=document.createElement("template");e.id="AlertDialogTemplate",e.innerHTML=Se,document.body.append(e)}function W(e,t="No"){return new Promise(o=>{let n=new AbortController;e.addEventListener("close",()=>{o(e.returnValue),n.abort()},{signal:n.signal}),e.addEventListener("cancel",()=>{o(t),n.abort()},{signal:n.signal})})}var w=new Map;async function $({buttons:e,content:t,className:o,id:n,title:r}){var y,h;if(n&&w.has(n))return await w.get(n);let i=document.querySelector("#AlertDialogTemplate");if(!i)throw Error("No alert dialog template found");let a=(y=i.content.firstElementChild)==null?void 0:y.cloneNode(!0),u=a==null?void 0:a.querySelector("article"),f=a==null?void 0:a.querySelector("footer menu");if(!a||!u||!f)throw Error("Invalid alert dialog template");if(o)for(let s of o.split(/\s+/))a==null||a.classList.add(s);if(r){let s=document.createElement("header");s.append(r),(h=u.parentNode)==null||h.insertBefore(s,u)}u.appendChild(typeof t=="string"?document.createTextNode(t):t);for(let{label:s,value:ee,primary:te}of e){let ne=document.createElement("li"),S=document.createElement("button");S.value=ee,te&&S.classList.add("primary"),S.textContent=s,ne.appendChild(S),f.appendChild(S)}document.body.appendChild(a),a.showModal();let v=W(a).then(s=>(n&&w.has(n)&&w.delete(n),a&&document.body.removeChild(a),s));return n&&w.set(n,v),await v}var Q=(o=>(o[o.YesNo=0]="YesNo",o[o.OkCancel=1]="OkCancel",o))(Q||{});async function be(e,t={}){let{buttons:o=0,title:n}=t,r=o===1?[{label:d("OK"),value:"yes",primary:!0},{label:d("Cancel"),value:"no"}]:[{label:d("Yes"),value:"yes",primary:!0},{label:d("No"),value:"no"}];return await $({content:e,buttons:r,className:"alert-dialog-confirm",title:n})==="yes"}async function xe(e,t={}){await $(p({content:e,className:"alert-dialog-alert",buttons:[{label:d("OK"),value:"ok",primary:!0}]},t))}function P(e){var o,n,r,i,a,u;let t=(i=e!=null?e:(n=(o=window.af)==null?void 0:o.article)==null?void 0:n.id)!=null?i:(r=window.window)==null?void 0:r.location.pathname.substring(1).split("/")[0];return"".concat(t,".").concat((u=(a=window.af)==null?void 0:a.userSession.login)!=null?u:"anonymous")}function we(e,t){var r;if(!((r=window.af)!=null&&r.userSession))return null;let o=P(t),n=JSON.parse(localStorage.getItem(o)||"{}");return e?n[e]||null:n}function ve(e,t,o){var i;if(!((i=window.af)!=null&&i.userSession))return;let n=P(o),r=JSON.parse(localStorage.getItem(n)||"{}");typeof t<"u"?r[e]=t:r=e,localStorage.setItem(n,JSON.stringify(r))}var ct="2.11.8";export{Q as ConfirmButtons,g as SessionHandler,L as UserSession,xe as alert,be as confirm,z as downloadBlob,pe as downloadRequest,X as expose,d as getLocalizedString,E as getSessionData,we as getSettings,G as getUserImage,c as invariant,ue as localStorage,he as localize,T as logActivity,D as logError,I as mitt,$ as openAlertDialog,ve as saveSettings,se as startActivity,ce as time,fe as toLocalDateTime,de as toLocalISODate,V as toLocalISODateTime,ct as version,W as waitForDialog};
|
|
2
2
|
//# sourceMappingURL=af.common.legacy.min.js.map
|