@olenbetong/appframe-core 2.11.8 → 2.11.10

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.
@@ -367,10 +367,24 @@ async function downloadRequest(request, { fileName, signal, onProgress }) {
367
367
 
368
368
  // src/parseFunc.ts
369
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)*)\}$/;
370
+ var arrowBlockRegex = /^(?:\(([^)]*)\)|([a-zA-Z$_][a-zA-Z0-9$_]*))\s*=>\s*\{([\s\S]*)\}$/;
371
+ var arrowExpressionRegex = /^(?:\(([^)]*)\)|([a-zA-Z$_][a-zA-Z0-9$_]*))\s*=>\s*([\s\S]+)$/;
372
+ var parseArguments = (args) => args.split(",").map((a) => a.trim()).filter(Boolean);
370
373
  function parseFunc(func) {
371
- const match = func.toString().match(funcRegex);
374
+ const funcString = func.toString();
375
+ const arrowBlockMatch = funcString.match(arrowBlockRegex);
376
+ if (arrowBlockMatch) {
377
+ const args = parseArguments(arrowBlockMatch[1] ?? arrowBlockMatch[2] ?? "");
378
+ return { name: func.name, args, body: arrowBlockMatch[3] };
379
+ }
380
+ const arrowExpressionMatch = funcString.match(arrowExpressionRegex);
381
+ if (arrowExpressionMatch) {
382
+ const args = parseArguments(arrowExpressionMatch[1] ?? arrowExpressionMatch[2] ?? "");
383
+ return { name: func.name, args, body: arrowExpressionMatch[3] };
384
+ }
385
+ const match = funcString.match(funcRegex);
372
386
  invariant(match, "Unable to parse function!");
373
- return { name: func.name ?? match[1], args: match[2].split(",").map((a) => a.trim()), body: match[3] };
387
+ return { name: func.name ?? match[1], args: parseArguments(match[2]), body: match[3] };
374
388
  }
375
389
 
376
390
  // src/Namespace.ts
@@ -646,7 +660,7 @@ function saveSettings(setting, value, article2) {
646
660
  }
647
661
 
648
662
  // src/index.ts
649
- var version = "2.11.8";
663
+ var version = "2.11.10";
650
664
  export {
651
665
  ConfirmButtons,
652
666
  SessionHandler,
@@ -1,24 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
-
22
1
  // ../../node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/dist/mitt.mjs
23
2
  function mitt_default(n) {
24
3
  return { all: n = n || /* @__PURE__ */ new Map(), on: function(t, e) {
@@ -39,9 +18,7 @@ function mitt_default(n) {
39
18
 
40
19
  // src/SessionHandler.ts
41
20
  var SessionHandler = class {
42
- constructor() {
43
- __publicField(this, "eventHandler", mitt_default());
44
- }
21
+ eventHandler = mitt_default();
45
22
  authenticated() {
46
23
  this.eventHandler.emit("onAuthenticated");
47
24
  }
@@ -50,7 +27,7 @@ var SessionHandler = class {
50
27
  let authPromise = new Promise((resolve) => {
51
28
  let eventHandler = () => {
52
29
  this.eventHandler.off("onAuthenticated", eventHandler);
53
- callback == null ? void 0 : callback();
30
+ callback?.();
54
31
  resolve();
55
32
  };
56
33
  this.eventHandler.on("onAuthenticated", eventHandler);
@@ -69,7 +46,7 @@ var SessionHandler = class {
69
46
  } else {
70
47
  link = "/login?RequireTwoFactor=1&ReturnUrl=%2fapi/sessionexpired/remove";
71
48
  }
72
- dialog.innerHTML = '<iframe sandbox="allow-same-origin allow-scripts allow-modals allow-top-navigation-by-user-activation allow-forms" src="'.concat(link, '" style="border:0;width:min(500px,100vw);height:min(700px, 100vh);"></iframe>');
49
+ dialog.innerHTML = `<iframe sandbox="allow-same-origin allow-scripts allow-modals allow-top-navigation-by-user-activation allow-forms" src="${link}" style="border:0;width:min(500px,100vw);height:min(700px, 100vh);"></iframe>`;
73
50
  document.body.append(dialog);
74
51
  dialog.showModal();
75
52
  await authPromise;
@@ -78,9 +55,9 @@ var SessionHandler = class {
78
55
  await authPromise;
79
56
  }
80
57
  } catch (_) {
81
- window.location.href = "/login?ReturnUrl=".concat(encodeURIComponent(window.location.pathname)).concat(encodeURIComponent(
58
+ window.location.href = `/login?ReturnUrl=${encodeURIComponent(window.location.pathname)}${encodeURIComponent(
82
59
  window.location.search
83
- ));
60
+ )}`;
84
61
  }
85
62
  }
86
63
  attachEvent(eventName, handler) {
@@ -93,51 +70,49 @@ var SessionHandler = class {
93
70
 
94
71
  // src/UserSession.ts
95
72
  var UserSession = class extends SessionHandler {
73
+ amDesignator = "a.m.";
74
+ dayNames = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
75
+ dayNamesShort = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
76
+ decimalSeparator = ".";
77
+ domain = "OB";
78
+ email;
79
+ formats;
80
+ groupSeparator = null;
81
+ integratedSecurity = false;
82
+ isDeveloper = false;
83
+ login = "";
84
+ loginType;
85
+ monthNames = [
86
+ "january",
87
+ "february",
88
+ "march",
89
+ "april",
90
+ "may",
91
+ "june",
92
+ "july",
93
+ "august",
94
+ "september",
95
+ "october",
96
+ "november",
97
+ "december",
98
+ ""
99
+ ];
100
+ monthNamesShort = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "augt", "sep", "oct", "nov", "dec", ""];
101
+ name;
102
+ pmDesignator = "p.m.";
103
+ shortDateFormat = "dd.MM.yyyy";
104
+ culture = "en-GB";
105
+ uiculture = "en-GB";
96
106
  constructor(userData) {
97
107
  super();
98
- __publicField(this, "amDesignator", "a.m.");
99
- __publicField(this, "dayNames", ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]);
100
- __publicField(this, "dayNamesShort", ["sun", "mon", "tue", "wed", "thu", "fri", "sat"]);
101
- __publicField(this, "decimalSeparator", ".");
102
- __publicField(this, "domain", "OB");
103
- __publicField(this, "email");
104
- __publicField(this, "formats");
105
- __publicField(this, "groupSeparator", null);
106
- __publicField(this, "integratedSecurity", false);
107
- __publicField(this, "isDeveloper", false);
108
- __publicField(this, "login", "");
109
- __publicField(this, "loginType");
110
- __publicField(this, "monthNames", [
111
- "january",
112
- "february",
113
- "march",
114
- "april",
115
- "may",
116
- "june",
117
- "july",
118
- "august",
119
- "september",
120
- "october",
121
- "november",
122
- "december",
123
- ""
124
- ]);
125
- __publicField(this, "monthNamesShort", ["jan", "feb", "mar", "apr", "may", "jun", "jul", "augt", "sep", "oct", "nov", "dec", ""]);
126
- __publicField(this, "name");
127
- __publicField(this, "pmDesignator", "p.m.");
128
- __publicField(this, "shortDateFormat", "dd.MM.yyyy");
129
- __publicField(this, "culture", "en-GB");
130
- __publicField(this, "uiculture", "en-GB");
131
108
  this.formats = {};
132
109
  Object.assign(this, userData);
133
110
  }
134
111
  };
135
112
 
136
113
  // src/log.ts
137
- var _a, _b, _c, _d;
138
- var article = (_d = (_b = (_a = window.af) == null ? void 0 : _a.article) == null ? void 0 : _b.id) != null ? _d : (_c = window.window) == null ? void 0 : _c.location.pathname.substring(1).split("/")[0];
114
+ var article = window.af?.article?.id ?? window.window?.location.pathname.substring(1).split("/")[0];
139
115
  async function logActivity(activity, parameters = {}, timeElapsed = 0) {
140
- var _a3;
141
116
  try {
142
117
  let response = await fetch("/api/logging/log-activity", {
143
118
  method: "POST",
@@ -145,26 +120,27 @@ async function logActivity(activity, parameters = {}, timeElapsed = 0) {
145
120
  article,
146
121
  timeElapsed,
147
122
  action: activity,
148
- parameters: __spreadProps(__spreadValues({}, parameters), {
123
+ parameters: {
124
+ ...parameters,
149
125
  _session: getSessionData()
150
- })
126
+ }
151
127
  }),
152
128
  headers: { "Content-Type": "application/json", Accept: "application/json" }
153
129
  });
154
130
  if (!response.ok) {
155
- if ((_a3 = response.headers.get("Content-Type")) == null ? void 0 : _a3.includes("application/json")) {
131
+ if (response.headers.get("Content-Type")?.includes("application/json")) {
156
132
  let data = await response.json();
157
133
  console.error(data.error);
158
134
  } else {
159
- console.error("".concat(response.status, " ").concat(response.statusText));
135
+ console.error(`${response.status} ${response.statusText}`);
160
136
  }
161
137
  }
162
- } catch (e) {
138
+ } catch {
163
139
  }
164
140
  }
165
141
  function startActivity(activity, startParameters = {}) {
166
142
  let start = performance.now();
167
- return (endParameters = {}) => logActivity(activity, __spreadValues(__spreadValues({}, startParameters), endParameters), performance.now() - start);
143
+ return (endParameters = {}) => logActivity(activity, { ...startParameters, ...endParameters }, performance.now() - start);
168
144
  }
169
145
  async function time(callback) {
170
146
  let start = performance.now();
@@ -172,12 +148,11 @@ async function time(callback) {
172
148
  return [returnValue, performance.now() - start];
173
149
  }
174
150
  async function logError(error) {
175
- var _a3;
176
151
  try {
177
152
  if (!error) return;
178
153
  let data = typeof error === "string" ? { error } : typeof error === "object" ? "message" in error ? {
179
154
  error: error.message,
180
- stack: (_a3 = error.stack) != null ? _a3 : null
155
+ stack: error.stack ?? null
181
156
  } : { error: error.toString() } : { error: "Unspecified error" };
182
157
  console.error(error);
183
158
  let result = await fetch("/data/Logger/LogError", {
@@ -191,26 +166,22 @@ async function logError(error) {
191
166
  return await result.json();
192
167
  }
193
168
  console.error(Error("Failed to log error"));
194
- } catch (e) {
169
+ } catch {
195
170
  }
196
171
  }
197
172
  function getSessionId() {
198
- var _a3;
199
- return (_a3 = crypto.randomUUID) == null ? void 0 : _a3.call(crypto);
173
+ return crypto.randomUUID?.();
200
174
  }
201
175
  var sessionStart = Date.now();
202
176
  var sessionId = getSessionId();
203
177
  var deviceId = "";
204
178
  var browserSessionId = "";
205
179
  if ("document" in window) {
206
- let startSession = () => {
207
- var _a3, _b2, _c2, _d2, _e, _f;
208
- return logActivity("AfSessionInit", {
209
- "appframe-core": (_b2 = (_a3 = window.af) == null ? void 0 : _a3.common) == null ? void 0 : _b2.version,
210
- "appframe-data": (_d2 = (_c2 = window.af) == null ? void 0 : _c2.data) == null ? void 0 : _d2.version,
211
- "app-version": (_f = (_e = window.af) == null ? void 0 : _e.article) == null ? void 0 : _f.version
212
- });
213
- };
180
+ let startSession = () => logActivity("AfSessionInit", {
181
+ "appframe-core": window.af?.common?.version,
182
+ "appframe-data": window.af?.data?.version,
183
+ "app-version": window.af?.article?.version
184
+ });
214
185
  document.addEventListener("DOMContentLoaded", () => {
215
186
  deviceId = localStorage.getItem("_afDeviceId");
216
187
  browserSessionId = sessionStorage.getItem("_afSessionId");
@@ -252,9 +223,8 @@ function getSessionData() {
252
223
  }
253
224
 
254
225
  // src/errorHandler.ts
255
- var _a2;
256
226
  if (true) {
257
- (_a2 = window.window) == null ? void 0 : _a2.addEventListener("error", (event) => {
227
+ window.window?.addEventListener("error", (event) => {
258
228
  if (typeof event === "object" && "error" in event) {
259
229
  logError(event.error);
260
230
  } else if (typeof event === "object" && "message" in event) {
@@ -265,13 +235,10 @@ if (true) {
265
235
 
266
236
  // src/localStorage.ts
267
237
  function getLocalKey(key) {
268
- var _a3;
269
- return [((_a3 = af == null ? void 0 : af.article) == null ? void 0 : _a3.id) || "", "common", key].join(".");
238
+ return [af?.article?.id || "", "common", key].join(".");
270
239
  }
271
240
  var LocalStorage = class {
272
- constructor() {
273
- __publicField(this, "isPersisted", () => true);
274
- }
241
+ isPersisted = () => true;
275
242
  getLocalStorageKey(key, global) {
276
243
  return global ? ["common", key].join(".") : getLocalKey(key);
277
244
  }
@@ -311,9 +278,9 @@ function pad(num, digits = 2) {
311
278
  return String(num).padStart(digits, "0");
312
279
  }
313
280
  function toLocalISODateTime(date) {
314
- return date ? "".concat(date.getFullYear(), "-").concat(pad(date.getMonth() + 1), "-").concat(pad(date.getDate()), "T").concat(pad(date.getHours()), ":").concat(pad(
281
+ return date ? `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(
315
282
  date.getMinutes()
316
- ), ":").concat(pad(date.getSeconds()), ".").concat(pad(date.getMilliseconds(), 3)) : null;
283
+ )}:${pad(date.getSeconds())}.${pad(date.getMilliseconds(), 3)}` : null;
317
284
  }
318
285
  function toLocalDateTime(date) {
319
286
  return date ? date.toISOString().substring(0, 16) : "";
@@ -347,22 +314,21 @@ function invariant(condition, message) {
347
314
  return;
348
315
  }
349
316
  const provided = typeof message === "function" ? message() : message;
350
- throw new Error(provided != null ? provided : "Invariant failed");
317
+ throw new Error(provided ?? "Invariant failed");
351
318
  }
352
319
 
353
320
  // src/downloadRequest.ts
354
321
  async function downloadRequest(request, { fileName, signal, onProgress }) {
355
- var _a3;
356
322
  let bytesReceived = 0;
357
- onProgress == null ? void 0 : onProgress({ status: "requested" });
323
+ onProgress?.({ status: "requested" });
358
324
  try {
359
325
  let response = await fetch(request);
360
326
  if (!response.ok || !response.body) {
361
- if ((_a3 = response.headers.get("content-type")) == null ? void 0 : _a3.includes("application/json")) {
327
+ if (response.headers.get("content-type")?.includes("application/json")) {
362
328
  let data = await response.json();
363
329
  invariant(!data.error, data.error);
364
330
  }
365
- throw new Error("".concat(response.status, " ").concat(response.statusText));
331
+ throw new Error(`${response.status} ${response.statusText}`);
366
332
  }
367
333
  try {
368
334
  const reader = response.body.getReader();
@@ -375,7 +341,7 @@ async function downloadRequest(request, { fileName, signal, onProgress }) {
375
341
  return;
376
342
  }
377
343
  bytesReceived += read.value.length;
378
- onProgress == null ? void 0 : onProgress({ bytesReceived, status: "downloading" });
344
+ onProgress?.({ bytesReceived, status: "downloading" });
379
345
  controller.enqueue(read.value);
380
346
  return pump();
381
347
  });
@@ -384,28 +350,41 @@ async function downloadRequest(request, { fileName, signal, onProgress }) {
384
350
  }
385
351
  });
386
352
  response = new Response(stream);
387
- } catch (e) {
353
+ } catch {
388
354
  }
389
355
  const blob = await response.blob();
390
- onProgress == null ? void 0 : onProgress({ bytesReceived, status: "downloaded" });
356
+ onProgress?.({ bytesReceived, status: "downloaded" });
391
357
  await downloadBlob(blob, fileName);
392
- onProgress == null ? void 0 : onProgress({ bytesReceived, status: "completed" });
358
+ onProgress?.({ bytesReceived, status: "completed" });
393
359
  } catch (err) {
394
- if (signal == null ? void 0 : signal.aborted) {
395
- onProgress == null ? void 0 : onProgress({ status: "cancelled" });
360
+ if (signal?.aborted) {
361
+ onProgress?.({ status: "cancelled" });
396
362
  } else {
397
- onProgress == null ? void 0 : onProgress({ error: err.message, status: "error" });
363
+ onProgress?.({ error: err.message, status: "error" });
398
364
  }
399
365
  }
400
366
  }
401
367
 
402
368
  // src/parseFunc.ts
403
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)*)\}$/;
370
+ var arrowBlockRegex = /^(?:\(([^)]*)\)|([a-zA-Z$_][a-zA-Z0-9$_]*))\s*=>\s*\{([\s\S]*)\}$/;
371
+ var arrowExpressionRegex = /^(?:\(([^)]*)\)|([a-zA-Z$_][a-zA-Z0-9$_]*))\s*=>\s*([\s\S]+)$/;
372
+ var parseArguments = (args) => args.split(",").map((a) => a.trim()).filter(Boolean);
404
373
  function parseFunc(func) {
405
- var _a3;
406
- const match = func.toString().match(funcRegex);
374
+ const funcString = func.toString();
375
+ const arrowBlockMatch = funcString.match(arrowBlockRegex);
376
+ if (arrowBlockMatch) {
377
+ const args = parseArguments(arrowBlockMatch[1] ?? arrowBlockMatch[2] ?? "");
378
+ return { name: func.name, args, body: arrowBlockMatch[3] };
379
+ }
380
+ const arrowExpressionMatch = funcString.match(arrowExpressionRegex);
381
+ if (arrowExpressionMatch) {
382
+ const args = parseArguments(arrowExpressionMatch[1] ?? arrowExpressionMatch[2] ?? "");
383
+ return { name: func.name, args, body: arrowExpressionMatch[3] };
384
+ }
385
+ const match = funcString.match(funcRegex);
407
386
  invariant(match, "Unable to parse function!");
408
- return { name: (_a3 = func.name) != null ? _a3 : match[1], args: match[2].split(",").map((a) => a.trim()), body: match[3] };
387
+ return { name: func.name ?? match[1], args: parseArguments(match[2]), body: match[3] };
409
388
  }
410
389
 
411
390
  // src/Namespace.ts
@@ -459,8 +438,8 @@ function expose(name, value, options = {}) {
459
438
  } else {
460
439
  invariant(false, "Invalid typeof parameter 'name', or unable to parse pValue!");
461
440
  }
462
- if (Object.hasOwn(namespace, keyName) && (options == null ? void 0 : options.overwrite) !== true) {
463
- console.warn("".concat([name, keyName].join("."), " is already defined!"));
441
+ if (Object.hasOwn(namespace, keyName) && options?.overwrite !== true) {
442
+ console.warn(`${[name, keyName].join(".")} is already defined!`);
464
443
  } else {
465
444
  namespace[keyName] = value;
466
445
  }
@@ -470,7 +449,7 @@ function expose(name, value, options = {}) {
470
449
  // src/getLocalizedString.ts
471
450
  async function fetchLocalizedString(text) {
472
451
  try {
473
- let response = await fetch("/api/user/localize/new/".concat(af.article.id), {
452
+ let response = await fetch(`/api/user/localize/new/${af.article.id}`, {
474
453
  body: JSON.stringify({ text }),
475
454
  headers: {
476
455
  Accept: "application/json; */*",
@@ -482,19 +461,18 @@ async function fetchLocalizedString(text) {
482
461
  if (response.ok) {
483
462
  return await response.json();
484
463
  }
485
- } catch (e) {
464
+ } catch {
486
465
  }
487
466
  return text;
488
467
  }
489
468
  function getLocalizedString(string, wait) {
490
- var _a3, _b2;
491
469
  if (typeof string === "string" && string.trim().length === 0) {
492
470
  return string;
493
471
  }
494
472
  if (string === void 0 || string === "" || string === null) {
495
473
  return;
496
474
  }
497
- if (((_b2 = (_a3 = window.af) == null ? void 0 : _a3.article) == null ? void 0 : _b2.i18n) !== void 0) {
475
+ if (window.af?.article?.i18n !== void 0) {
498
476
  if (!Object.hasOwn(af.article.i18n, string)) {
499
477
  af.article.i18n[string] = string;
500
478
  let promise = fetchLocalizedString(string).then((text) => {
@@ -527,7 +505,7 @@ function getUserImage(primKeyOrOptions, login, hash, size = "xs") {
527
505
  return "";
528
506
  }
529
507
  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) : "");
508
+ return `/api/data/blob/EmployeesLookup/${primKeyOrOptions}/Image/${encodeURIComponent(login ?? "")}${login ? "." : ""}${encodeURIComponent(hash)}.jpg${sizePx ? `?width=${sizePx}` : ""}`;
531
509
  }
532
510
 
533
511
  // src/localize.ts
@@ -536,16 +514,25 @@ function localize(stringParts, ...args) {
536
514
  Array.isArray(stringParts) && stringParts.length === args.length + 1,
537
515
  "Method 'localize' must be used as a tag function"
538
516
  );
539
- let stringToLocalize = stringParts.map((s, i) => i === stringParts.length - 1 ? s : "".concat(s, "$").concat(i)).join("");
517
+ let stringToLocalize = stringParts.map((s, i) => i === stringParts.length - 1 ? s : `${s}$${i}`).join("");
540
518
  let localized = getLocalizedString(stringToLocalize);
541
519
  args.forEach((arg, index) => {
542
- localized = localized.replace("$".concat(index), arg);
520
+ localized = localized.replace(`$${index}`, arg);
543
521
  });
544
522
  return localized;
545
523
  }
546
524
 
547
525
  // src/alert.ts
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';
526
+ var template = `
527
+ <dialog class="alert-dialog">
528
+ <form method="dialog">
529
+ <article></article>
530
+ <footer>
531
+ <menu></menu>
532
+ </footer>
533
+ </form>
534
+ </dialog>
535
+ `;
549
536
  if (window.document && !document.querySelector("#AlertDialogTemplate")) {
550
537
  let $template = document.createElement("template");
551
538
  $template.id = "AlertDialogTemplate";
@@ -575,25 +562,24 @@ function waitForDialog(dialog, cancelValue = "No") {
575
562
  }
576
563
  var alertDialogPromiseMap = /* @__PURE__ */ new Map();
577
564
  async function openAlertDialog({ buttons, content, className, id, title }) {
578
- var _a3, _b2;
579
565
  if (id && alertDialogPromiseMap.has(id)) {
580
566
  return await alertDialogPromiseMap.get(id);
581
567
  }
582
568
  let $template = document.querySelector("#AlertDialogTemplate");
583
569
  if (!$template) throw Error("No alert dialog template found");
584
- let $dialog = (_a3 = $template.content.firstElementChild) == null ? void 0 : _a3.cloneNode(true);
585
- let $content = $dialog == null ? void 0 : $dialog.querySelector("article");
586
- let $menu = $dialog == null ? void 0 : $dialog.querySelector("footer menu");
570
+ let $dialog = $template.content.firstElementChild?.cloneNode(true);
571
+ let $content = $dialog?.querySelector("article");
572
+ let $menu = $dialog?.querySelector("footer menu");
587
573
  if (!$dialog || !$content || !$menu) throw Error("Invalid alert dialog template");
588
574
  if (className) {
589
575
  for (const className_ of className.split(/\s+/)) {
590
- $dialog == null ? void 0 : $dialog.classList.add(className_);
576
+ $dialog?.classList.add(className_);
591
577
  }
592
578
  }
593
579
  if (title) {
594
580
  let $header = document.createElement("header");
595
581
  $header.append(title);
596
- (_b2 = $content.parentNode) == null ? void 0 : _b2.insertBefore($header, $content);
582
+ $content.parentNode?.insertBefore($header, $content);
597
583
  }
598
584
  $content.appendChild(typeof content === "string" ? document.createTextNode(content) : content);
599
585
  for (let { label, value, primary } of buttons) {
@@ -639,22 +625,21 @@ async function confirm(prompt, options = {}) {
639
625
  return result === "yes";
640
626
  }
641
627
  async function alert(prompt, options = {}) {
642
- await openAlertDialog(__spreadValues({
628
+ await openAlertDialog({
643
629
  content: prompt,
644
630
  className: "alert-dialog-alert",
645
- buttons: [{ label: getLocalizedString("OK"), value: "ok", primary: true }]
646
- }, options));
631
+ buttons: [{ label: getLocalizedString("OK"), value: "ok", primary: true }],
632
+ ...options
633
+ });
647
634
  }
648
635
 
649
636
  // src/settings.ts
650
637
  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");
638
+ const articleKey = article2 ?? window.af?.article?.id ?? window.window?.location.pathname.substring(1).split("/")[0];
639
+ return `${articleKey}.${window.af?.userSession.login ?? "anonymous"}`;
654
640
  }
655
641
  function getSettings(setting, article2) {
656
- var _a3;
657
- if (!((_a3 = window.af) == null ? void 0 : _a3.userSession)) return null;
642
+ if (!window.af?.userSession) return null;
658
643
  const key = getKey(article2);
659
644
  const settings = JSON.parse(localStorage.getItem(key) || "{}");
660
645
  if (setting) {
@@ -663,8 +648,7 @@ function getSettings(setting, article2) {
663
648
  return settings;
664
649
  }
665
650
  function saveSettings(setting, value, article2) {
666
- var _a3;
667
- if (!((_a3 = window.af) == null ? void 0 : _a3.userSession)) return;
651
+ if (!window.af?.userSession) return;
668
652
  const key = getKey(article2);
669
653
  let userSettings = JSON.parse(localStorage.getItem(key) || "{}");
670
654
  if (typeof value !== "undefined") {
@@ -676,7 +660,7 @@ function saveSettings(setting, value, article2) {
676
660
  }
677
661
 
678
662
  // src/index.ts
679
- var version = "2.11.8";
663
+ var version = "2.11.10";
680
664
  export {
681
665
  ConfirmButtons,
682
666
  SessionHandler,
@@ -1,2 +1,11 @@
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};
1
+ function w(e){return{all:e=e||new Map,on:function(t,n){var o=e.get(t);o?o.push(n):e.set(t,[n])},off:function(t,n){var o=e.get(t);o&&(n?o.splice(o.indexOf(n)>>>0,1):e.set(t,[]))},emit:function(t,n){var o=e.get(t);o&&o.slice().map(function(r){r(n)}),(o=e.get("*"))&&o.slice().map(function(r){r(t,n)})}}}var g=class{eventHandler=w();authenticated(){this.eventHandler.emit("onAuthenticated")}async expired(t,n){try{let o=new Promise(i=>{let a=()=>{this.eventHandler.off("onAuthenticated",a),t?.(),i()};this.eventHandler.on("onAuthenticated",a)}),r=document.querySelector("dialog.session-expired-dialog");if(r)await o;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";n!=="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="${i}" style="border:0;width:min(500px,100vw);height:min(700px, 100vh);"></iframe>`,document.body.append(r),r.showModal(),await o,r.remove()}}catch{window.location.href=`/login?ReturnUrl=${encodeURIComponent(window.location.pathname)}${encodeURIComponent(window.location.search)}`}}attachEvent(t,n){return this.eventHandler.on(t,n)}detachEvent(t,n){return this.eventHandler.off(t,n)}};var v=class extends g{amDesignator="a.m.";dayNames=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"];dayNamesShort=["sun","mon","tue","wed","thu","fri","sat"];decimalSeparator=".";domain="OB";email;formats;groupSeparator=null;integratedSecurity=!1;isDeveloper=!1;login="";loginType;monthNames=["january","february","march","april","may","june","july","august","september","october","november","december",""];monthNamesShort=["jan","feb","mar","apr","may","jun","jul","augt","sep","oct","nov","dec",""];name;pmDesignator="p.m.";shortDateFormat="dd.MM.yyyy";culture="en-GB";uiculture="en-GB";constructor(t){super(),this.formats={},Object.assign(this,t)}};var O=window.af?.article?.id??window.window?.location.pathname.substring(1).split("/")[0];async function A(e,t={},n=0){try{let o=await fetch("/api/logging/log-activity",{method:"POST",body:JSON.stringify({article:O,timeElapsed:n,action:e,parameters:{...t,_session:D()}}),headers:{"Content-Type":"application/json",Accept:"application/json"}});if(!o.ok)if(o.headers.get("Content-Type")?.includes("application/json")){let r=await o.json();console.error(r.error)}else console.error(`${o.status} ${o.statusText}`)}catch{}}function J(e,t={}){let n=performance.now();return(o={})=>A(e,{...t,...o},performance.now()-n)}async function K(e){let t=performance.now();return[await e(),performance.now()-t]}async function x(e){try{if(!e)return;let t=typeof e=="string"?{error:e}:typeof e=="object"?"message"in e?{error:e.message,stack:e.stack??null}:{error:e.toString()}:{error:"Unspecified error"};console.error(e);let n=await fetch("/data/Logger/LogError",{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json; charset=utf-8"}});if(n.ok)return await n.json();console.error(Error("Failed to log error"))}catch{}}function N(){return crypto.randomUUID?.()}var j=Date.now(),R=N(),y="",h="";if("document"in window){let e=()=>A("AfSessionInit",{"appframe-core":window.af?.common?.version,"appframe-data":window.af?.data?.version,"app-version":window.af?.article?.version});document.addEventListener("DOMContentLoaded",()=>{y=localStorage.getItem("_afDeviceId"),h=sessionStorage.getItem("_afSessionId"),y||(y=N(),localStorage.setItem("_afDeviceId",y)),h||(h=R,sessionStorage.setItem("_afSessionId",h)),e()}),document.addEventListener("visibilitychange",function(){document.visibilityState==="hidden"?navigator.sendBeacon("/api/logging/log-activity",JSON.stringify({article:O,action:"AfSessionEnd",parameters:{_session:D()}})):e()})}function D(){return{browserSessionId:h,sessionStart:j,sessionLength:Date.now()-j,sessionId:R,deviceId:y}}window.window?.addEventListener("error",e=>{typeof e=="object"&&"error"in e?x(e.error):typeof e=="object"&&"message"in e&&x(e)});function _(e){return[af?.article?.id||"","common",e].join(".")}var I=class{isPersisted=()=>!0;getLocalStorageKey(t,n){return n?["common",t].join("."):_(t)}get(t,n,o){let r=this.getLocalStorageKey(t,o),i=localStorage.getItem(r);return i!==null?JSON.parse(i):n}set(t,n,o){localStorage.setItem(this.getLocalStorageKey(t,o),JSON.stringify(n))}remove(t,n){let o=this.getLocalStorageKey(t,n);return localStorage.getItem(o)!==null?(localStorage.removeItem(o),!0):!1}clear(){let t=_("");for(let n in localStorage)n.slice(0,t.length)===t&&localStorage.removeItem(n)}},V=new I;function Y(e){return e?C(e).substring(0,10):null}function d(e,t=2){return String(e).padStart(t,"0")}function C(e){return e?`${e.getFullYear()}-${d(e.getMonth()+1)}-${d(e.getDate())}T${d(e.getHours())}:${d(e.getMinutes())}:${d(e.getSeconds())}.${d(e.getMilliseconds(),3)}`:null}function X(e){return e?e.toISOString().substring(0,16):""}function L(e,t){return new Promise((n,o)=>{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),n()},250)}catch(r){o(r)}})}function l(e,t){if(e)return;let n=typeof t=="function"?t():t;throw new Error(n??"Invariant failed")}async function G(e,{fileName:t,signal:n,onProgress:o}){let r=0;o?.({status:"requested"});try{let i=await fetch(e);if(!i.ok||!i.body){if(i.headers.get("content-type")?.includes("application/json")){let c=await i.json();l(!c.error,c.error)}throw new Error(`${i.status} ${i.statusText}`)}try{let c=i.body.getReader(),S=new ReadableStream({start:p=>{function s(){return c.read().then(f=>{if(f.done){p.close();return}return r+=f.value.length,o?.({bytesReceived:r,status:"downloading"}),p.enqueue(f.value),s()})}return s()}});i=new Response(S)}catch{}let a=await i.blob();o?.({bytesReceived:r,status:"downloaded"}),await L(a,t),o?.({bytesReceived:r,status:"completed"})}catch(i){n?.aborted?o?.({status:"cancelled"}):o?.({error:i.message,status:"error"})}}var W=/^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)*)\}$/,Q=/^(?:\(([^)]*)\)|([a-zA-Z$_][a-zA-Z0-9$_]*))\s*=>\s*\{([\s\S]*)\}$/,ee=/^(?:\(([^)]*)\)|([a-zA-Z$_][a-zA-Z0-9$_]*))\s*=>\s*([\s\S]+)$/,T=e=>e.split(",").map(t=>t.trim()).filter(Boolean);function E(e){let t=e.toString(),n=t.match(Q);if(n){let i=T(n[1]??n[2]??"");return{name:e.name,args:i,body:n[3]}}let o=t.match(ee);if(o){let i=T(o[1]??o[2]??"");return{name:e.name,args:i,body:o[3]}}let r=t.match(W);return l(r,"Unable to parse function!"),{name:e.name??r[1],args:T(r[2]),body:r[3]}}function U(){}U.prototype=Object.create(null);var M=U;function $(e,t){if(typeof e=="object"){if(typeof t=="string"){let n=t.split(".");return $(e,n)}else if(Array.isArray(t)){let n=e;for(let o=0;o<t.length;o++)n=n[t[o]]=n[t[o]]||new M;return n}}}function H(e,t,n={}){if(Array.isArray(t))for(let o of t){let{name:r}=E(o);l(r,"Unable to detect name of function! Name it, or only supply one function and include name in first parameter."),H(e,o)}else{let o,r;if(typeof t=="function"&&(o=E(t).name),typeof e=="string"){let i=e.split(".");o||(o=i[i.length-1],i=i.slice(0,i.length-1)),r=$(window,i)}else o&&(typeof e=="object"||typeof e=="function")?r=e:l(!1,"Invalid typeof parameter 'name', or unable to parse pValue!");Object.hasOwn(r,o)&&n?.overwrite!==!0?console.warn(`${[e,o].join(".")} is already defined!`):r[o]=t}}async function te(e){try{let t=await fetch(`/api/user/localize/new/${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{}return e}function u(e,t){if(typeof e=="string"&&e.trim().length===0)return e;if(!(e===void 0||e===""||e===null))if(window.af?.article?.i18n!==void 0){if(!Object.hasOwn(af.article.i18n,e)){af.article.i18n[e]=e;let n=te(e).then(o=>(af.article.i18n[e]=o,o));if(t)return n}return af.article.i18n[e]}else return e}var oe={xs:64,sm:128,md:256,lg:512,xl:void 0};function k(e,t,n,o="xs"){if(e&&typeof e=="object")return k(e.primKey,e.login,e.hash,e.size);if(!e||!n)return"";let r=oe[o];return`/api/data/blob/EmployeesLookup/${e}/Image/${encodeURIComponent(t??"")}${t?".":""}${encodeURIComponent(n)}.jpg${r?`?width=${r}`:""}`}function ne(e,...t){l(Array.isArray(e)&&e.length===t.length+1,"Method 'localize' must be used as a tag function");let n=e.map((r,i)=>i===e.length-1?r:`${r}$${i}`).join(""),o=u(n);return t.forEach((r,i)=>{o=o.replace(`$${i}`,r)}),o}var re=`
2
+ <dialog class="alert-dialog">
3
+ <form method="dialog">
4
+ <article></article>
5
+ <footer>
6
+ <menu></menu>
7
+ </footer>
8
+ </form>
9
+ </dialog>
10
+ `;if(window.document&&!document.querySelector("#AlertDialogTemplate")){let e=document.createElement("template");e.id="AlertDialogTemplate",e.innerHTML=re,document.body.append(e)}function P(e,t="No"){return new Promise(n=>{let o=new AbortController;e.addEventListener("close",()=>{n(e.returnValue),o.abort()},{signal:o.signal}),e.addEventListener("cancel",()=>{n(t),o.abort()},{signal:o.signal})})}var b=new Map;async function z({buttons:e,content:t,className:n,id:o,title:r}){if(o&&b.has(o))return await b.get(o);let i=document.querySelector("#AlertDialogTemplate");if(!i)throw Error("No alert dialog template found");let a=i.content.firstElementChild?.cloneNode(!0),c=a?.querySelector("article"),S=a?.querySelector("footer menu");if(!a||!c||!S)throw Error("Invalid alert dialog template");if(n)for(let s of n.split(/\s+/))a?.classList.add(s);if(r){let s=document.createElement("header");s.append(r),c.parentNode?.insertBefore(s,c)}c.appendChild(typeof t=="string"?document.createTextNode(t):t);for(let{label:s,value:f,primary:F}of e){let Z=document.createElement("li"),m=document.createElement("button");m.value=f,F&&m.classList.add("primary"),m.textContent=s,Z.appendChild(m),S.appendChild(m)}document.body.appendChild(a),a.showModal();let p=P(a).then(s=>(o&&b.has(o)&&b.delete(o),a&&document.body.removeChild(a),s));return o&&b.set(o,p),await p}var q=(n=>(n[n.YesNo=0]="YesNo",n[n.OkCancel=1]="OkCancel",n))(q||{});async function ie(e,t={}){let{buttons:n=0,title:o}=t,r=n===1?[{label:u("OK"),value:"yes",primary:!0},{label:u("Cancel"),value:"no"}]:[{label:u("Yes"),value:"yes",primary:!0},{label:u("No"),value:"no"}];return await z({content:e,buttons:r,className:"alert-dialog-confirm",title:o})==="yes"}async function ae(e,t={}){await z({content:e,className:"alert-dialog-alert",buttons:[{label:u("OK"),value:"ok",primary:!0}],...t})}function B(e){return`${e??window.af?.article?.id??window.window?.location.pathname.substring(1).split("/")[0]}.${window.af?.userSession.login??"anonymous"}`}function se(e,t){if(!window.af?.userSession)return null;let n=B(t),o=JSON.parse(localStorage.getItem(n)||"{}");return e?o[e]||null:o}function le(e,t,n){if(!window.af?.userSession)return;let o=B(n),r=JSON.parse(localStorage.getItem(o)||"{}");typeof t<"u"?r[e]=t:r=e,localStorage.setItem(o,JSON.stringify(r))}var Be="2.11.10";export{q as ConfirmButtons,g as SessionHandler,v as UserSession,ae as alert,ie as confirm,L as downloadBlob,G as downloadRequest,H as expose,u as getLocalizedString,D as getSessionData,se as getSettings,k as getUserImage,l as invariant,V as localStorage,ne as localize,A as logActivity,x as logError,w as mitt,z as openAlertDialog,le as saveSettings,J as startActivity,K as time,X as toLocalDateTime,Y as toLocalISODate,C as toLocalISODateTime,Be as version,P as waitForDialog};
2
11
  //# sourceMappingURL=af.common.legacy.min.js.map