@olenbetong/appframe-core 1.3.6 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/af.common.js +204 -304
- package/dist/esm/af.common.legacy.js +206 -307
- package/dist/esm/af.common.legacy.min.js +3 -3
- package/dist/esm/af.common.legacy.min.js.map +4 -4
- package/dist/esm/af.common.min.js +5 -5
- package/dist/esm/af.common.min.js.map +4 -4
- package/dist/iife/af.common.js +204 -304
- package/dist/iife/af.common.legacy.js +206 -307
- package/dist/iife/af.common.legacy.min.js +3 -3
- package/dist/iife/af.common.legacy.min.js.map +4 -4
- package/dist/iife/af.common.min.js +5 -5
- package/dist/iife/af.common.min.js.map +4 -4
- package/es/UserSession.d.ts +5 -1
- package/es/UserSession.js +5 -1
- package/es/index.d.ts +31 -3
- package/es/index.js +3 -4
- package/package.json +2 -2
- package/src/UserSession.ts +5 -1
- package/src/index.ts +36 -3
- package/es/exportDataObject.d.ts +0 -73
- package/es/exportDataObject.js +0 -61
- package/es/formDataToObject.d.ts +0 -26
- package/es/formDataToObject.js +0 -73
- package/src/exportDataObject.ts +0 -110
- package/src/formDataToObject.ts +0 -80
- package/src/global.d.ts +0 -56
|
@@ -40,18 +40,12 @@ af.common = (() => {
|
|
|
40
40
|
UserSession: () => UserSession,
|
|
41
41
|
downloadBlob: () => downloadBlob,
|
|
42
42
|
downloadRequest: () => downloadRequest,
|
|
43
|
-
exportOptionsFromDataObject: () => exportOptionsFromDataObject,
|
|
44
43
|
expose: () => expose,
|
|
45
|
-
formDataToDataObjectRecord: () => formDataToDataObjectRecord,
|
|
46
|
-
formDataToObject: () => formDataToObject,
|
|
47
|
-
formDataToProcedureParameters: () => formDataToProcedureParameters,
|
|
48
|
-
getDataObjectReportRequest: () => getDataObjectReportRequest,
|
|
49
44
|
getLocalizedString: () => getLocalizedString,
|
|
50
45
|
getSettings: () => getSettings,
|
|
51
46
|
has: () => has,
|
|
52
47
|
localStorage: () => localStorage_default,
|
|
53
48
|
mitt: () => mitt_default,
|
|
54
|
-
openDataObjectReport: () => openDataObjectReport,
|
|
55
49
|
saveSettings: () => saveSettings,
|
|
56
50
|
version: () => version
|
|
57
51
|
});
|
|
@@ -98,224 +92,6 @@ af.common = (() => {
|
|
|
98
92
|
} };
|
|
99
93
|
}
|
|
100
94
|
|
|
101
|
-
// src/downloadBlob.ts
|
|
102
|
-
function downloadBlob(blob, fileName) {
|
|
103
|
-
return new Promise(function(resolve, reject) {
|
|
104
|
-
try {
|
|
105
|
-
const url = URL.createObjectURL(blob);
|
|
106
|
-
const parent = document.body;
|
|
107
|
-
const anchor = document.createElement("a");
|
|
108
|
-
anchor.setAttribute("download", fileName);
|
|
109
|
-
anchor.href = url;
|
|
110
|
-
parent.append(anchor);
|
|
111
|
-
anchor.click();
|
|
112
|
-
parent.removeChild(anchor);
|
|
113
|
-
setTimeout(function() {
|
|
114
|
-
URL.revokeObjectURL(url);
|
|
115
|
-
resolve();
|
|
116
|
-
}, 250);
|
|
117
|
-
} catch (ex) {
|
|
118
|
-
reject(ex);
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// src/downloadRequest.ts
|
|
124
|
-
async function downloadRequest(request, { fileName, signal, onProgress }) {
|
|
125
|
-
var _a;
|
|
126
|
-
function reportProgress(progress) {
|
|
127
|
-
if (typeof onProgress === "function") {
|
|
128
|
-
onProgress(__spreadValues({}, progress));
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
let bytesReceived = 0;
|
|
132
|
-
reportProgress({ status: "requested" });
|
|
133
|
-
try {
|
|
134
|
-
let response = await fetch(request);
|
|
135
|
-
if (!response.ok || !response.body) {
|
|
136
|
-
if ((_a = response.headers.get("content-type")) == null ? void 0 : _a.includes("application/json")) {
|
|
137
|
-
let data = await response.json();
|
|
138
|
-
if (data.error) {
|
|
139
|
-
throw new Error(data.error);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
throw new Error(`${response.status} ${response.statusText}`);
|
|
143
|
-
}
|
|
144
|
-
try {
|
|
145
|
-
const reader = response.body.getReader();
|
|
146
|
-
const stream = new ReadableStream({
|
|
147
|
-
start: function(controller) {
|
|
148
|
-
function pump() {
|
|
149
|
-
return reader.read().then(function(read) {
|
|
150
|
-
if (read.done) {
|
|
151
|
-
controller.close();
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
bytesReceived += read.value.length;
|
|
155
|
-
reportProgress({ bytesReceived, status: "downloading" });
|
|
156
|
-
controller.enqueue(read.value);
|
|
157
|
-
return pump();
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
return pump();
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
response = new Response(stream);
|
|
164
|
-
} catch (error) {
|
|
165
|
-
console.warn("Failed to replace response stream to log download progress.");
|
|
166
|
-
}
|
|
167
|
-
const blob = await response.blob();
|
|
168
|
-
reportProgress({ bytesReceived, status: "downloaded" });
|
|
169
|
-
await downloadBlob(blob, fileName);
|
|
170
|
-
reportProgress({ bytesReceived, status: "completed" });
|
|
171
|
-
} catch (err) {
|
|
172
|
-
if (signal == null ? void 0 : signal.aborted) {
|
|
173
|
-
reportProgress({ status: "cancelled" });
|
|
174
|
-
} else {
|
|
175
|
-
reportProgress({ error: err.message, status: "error" });
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// src/exportDataObject.ts
|
|
181
|
-
function exportOptionsFromDataObject(dataObject, specifiedOptions) {
|
|
182
|
-
return __spreadValues({
|
|
183
|
-
columns: dataObject.getFields().map((field) => ({ name: field.name })),
|
|
184
|
-
distinctRows: dataObject.getParameter("distinctRows"),
|
|
185
|
-
filterObject: dataObject.getParameter("filterObject"),
|
|
186
|
-
filterString: dataObject.getParameter("filterString"),
|
|
187
|
-
maxRecords: dataObject.getParameter("maxRecords"),
|
|
188
|
-
sortOrder: dataObject.getParameter("sortOrder"),
|
|
189
|
-
whereClause: dataObject.getParameter("whereClause"),
|
|
190
|
-
whereObject: dataObject.getParameter("whereObject")
|
|
191
|
-
}, specifiedOptions);
|
|
192
|
-
}
|
|
193
|
-
var defaultOptions = {
|
|
194
|
-
columns: [],
|
|
195
|
-
distinctRows: false,
|
|
196
|
-
filterObject: null,
|
|
197
|
-
filterString: "",
|
|
198
|
-
maxRecords: -1,
|
|
199
|
-
sortOrder: [],
|
|
200
|
-
whereClause: "",
|
|
201
|
-
whereObject: null
|
|
202
|
-
};
|
|
203
|
-
function getDataObjectReportRequest(params) {
|
|
204
|
-
var _a;
|
|
205
|
-
const { articleId, dataObject, format, options } = params;
|
|
206
|
-
const reportOptions = options ? Object.assign({}, defaultOptions, options) : defaultOptions;
|
|
207
|
-
const body = "data=" + encodeURIComponent(JSON.stringify(reportOptions));
|
|
208
|
-
const requestUrl = `/api/data-object/export/${articleId}/${dataObject}/${format}`;
|
|
209
|
-
const controller = (_a = params.controller) != null ? _a : new AbortController();
|
|
210
|
-
return {
|
|
211
|
-
controller,
|
|
212
|
-
request: new Request(requestUrl, {
|
|
213
|
-
body,
|
|
214
|
-
credentials: "same-origin",
|
|
215
|
-
headers: {
|
|
216
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
217
|
-
},
|
|
218
|
-
method: "POST",
|
|
219
|
-
signal: controller.signal
|
|
220
|
-
})
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
function openDataObjectReport(params) {
|
|
224
|
-
const { dataObject, fileName, format } = params;
|
|
225
|
-
const { request } = getDataObjectReportRequest(params);
|
|
226
|
-
return downloadRequest(request, {
|
|
227
|
-
fileName: `${fileName || dataObject}.${format}`
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// src/has.ts
|
|
232
|
-
function has(obj, key2) {
|
|
233
|
-
return Object.prototype.hasOwnProperty.call(obj, key2);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// src/parseFunc.ts
|
|
237
|
-
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)*)\}$/;
|
|
238
|
-
function parseFunc(func) {
|
|
239
|
-
var match = func.toString().match(funcRegex);
|
|
240
|
-
if (match === null) {
|
|
241
|
-
throw new TypeError("Unable to parse function!");
|
|
242
|
-
}
|
|
243
|
-
return { name: match[1], args: match[2].split(","), body: match[3] };
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// src/Namespace.ts
|
|
247
|
-
function Namespace() {
|
|
248
|
-
}
|
|
249
|
-
Namespace.prototype = /* @__PURE__ */ Object.create(null);
|
|
250
|
-
var Namespace_default = Namespace;
|
|
251
|
-
|
|
252
|
-
// src/requireNamespace.ts
|
|
253
|
-
function requireNamespace(root, namespace) {
|
|
254
|
-
if (typeof root === "object") {
|
|
255
|
-
if (typeof namespace === "string") {
|
|
256
|
-
let path = namespace.split(".");
|
|
257
|
-
return requireNamespace(root, path);
|
|
258
|
-
} else if (Array.isArray(namespace)) {
|
|
259
|
-
let current = root;
|
|
260
|
-
for (let i = 0; i < namespace.length; i++) {
|
|
261
|
-
current = current[namespace[i]] = current[namespace[i]] || new Namespace_default();
|
|
262
|
-
}
|
|
263
|
-
return current;
|
|
264
|
-
} else {
|
|
265
|
-
throw new TypeError("Invalid type of parameter 'namespace'");
|
|
266
|
-
}
|
|
267
|
-
} else {
|
|
268
|
-
throw new TypeError("Invalid type of parameter 'root'");
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// src/warn.ts
|
|
273
|
-
function warn(message, fallbackToAlert) {
|
|
274
|
-
console.warn(message);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// src/expose.ts
|
|
278
|
-
function expose(name, value) {
|
|
279
|
-
if (arguments.length !== 2) {
|
|
280
|
-
throw new Error("Incorrect number of arguments passed to the expose function!");
|
|
281
|
-
}
|
|
282
|
-
if (Array.isArray(value)) {
|
|
283
|
-
for (let func of value) {
|
|
284
|
-
const { name: funcName } = parseFunc(func);
|
|
285
|
-
if (funcName) {
|
|
286
|
-
expose(name, func);
|
|
287
|
-
} else {
|
|
288
|
-
throw new Error(
|
|
289
|
-
"Unable to detect name of function! Name it, or only supply one function and include name in first parameter."
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
} else {
|
|
294
|
-
let keyName;
|
|
295
|
-
let namespace;
|
|
296
|
-
if (typeof value === "function") {
|
|
297
|
-
keyName = parseFunc(value).name;
|
|
298
|
-
}
|
|
299
|
-
if (typeof name === "string") {
|
|
300
|
-
let pathParts = name.split(".");
|
|
301
|
-
if (!keyName) {
|
|
302
|
-
keyName = pathParts[pathParts.length - 1];
|
|
303
|
-
pathParts = pathParts.slice(0, pathParts.length - 1);
|
|
304
|
-
}
|
|
305
|
-
namespace = requireNamespace(window, pathParts);
|
|
306
|
-
} else if (keyName && (typeof name === "object" || typeof name === "function")) {
|
|
307
|
-
namespace = name;
|
|
308
|
-
} else {
|
|
309
|
-
throw new TypeError("Invalid typeof parameter 'name', or unable to parse pValue!");
|
|
310
|
-
}
|
|
311
|
-
if (has(namespace, keyName)) {
|
|
312
|
-
warn([name, keyName].join(".") + " is already defined!");
|
|
313
|
-
} else {
|
|
314
|
-
namespace[keyName] = value;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
95
|
// src/getLocalizedString.ts
|
|
320
96
|
async function getLocalizedStringAsync(string) {
|
|
321
97
|
try {
|
|
@@ -438,49 +214,6 @@ return s;
|
|
|
438
214
|
return localized;
|
|
439
215
|
}
|
|
440
216
|
|
|
441
|
-
// src/localStorage.ts
|
|
442
|
-
function getLocalKey(key2) {
|
|
443
|
-
var _a;
|
|
444
|
-
return [((_a = af == null ? void 0 : af.article) == null ? void 0 : _a.id) || "", "common", key2].join(".");
|
|
445
|
-
}
|
|
446
|
-
var LocalStorage = class {
|
|
447
|
-
isPersisted() {
|
|
448
|
-
return true;
|
|
449
|
-
}
|
|
450
|
-
getLocalStorageKey(key2, global) {
|
|
451
|
-
return global ? ["common", key2].join(".") : getLocalKey(key2);
|
|
452
|
-
}
|
|
453
|
-
get(key2, defaultValue, global) {
|
|
454
|
-
const lsKey = this.getLocalStorageKey(key2, global);
|
|
455
|
-
const value = localStorage.getItem(lsKey);
|
|
456
|
-
return value !== null ? JSON.parse(value) : defaultValue;
|
|
457
|
-
}
|
|
458
|
-
set(key2, value, global) {
|
|
459
|
-
localStorage.setItem(
|
|
460
|
-
this.getLocalStorageKey(key2, global),
|
|
461
|
-
JSON.stringify(value)
|
|
462
|
-
);
|
|
463
|
-
}
|
|
464
|
-
remove(key2, global) {
|
|
465
|
-
const lsKey = this.getLocalStorageKey(key2, global);
|
|
466
|
-
if (localStorage.getItem(lsKey) !== null) {
|
|
467
|
-
localStorage.removeItem(lsKey);
|
|
468
|
-
return true;
|
|
469
|
-
} else {
|
|
470
|
-
return false;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
clear() {
|
|
474
|
-
const baseKey = getLocalKey("");
|
|
475
|
-
for (let key2 in localStorage) {
|
|
476
|
-
if (key2.slice(0, baseKey.length) === baseKey) {
|
|
477
|
-
localStorage.removeItem(key2);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
};
|
|
482
|
-
var localStorage_default = new LocalStorage();
|
|
483
|
-
|
|
484
217
|
// src/SessionHandler.ts
|
|
485
218
|
var _SessionHandler = class {
|
|
486
219
|
constructor() {
|
|
@@ -630,62 +363,228 @@ return s;
|
|
|
630
363
|
constructor(userData) {
|
|
631
364
|
super();
|
|
632
365
|
this.decimalSeparator = ".";
|
|
366
|
+
this.domain = "OB";
|
|
633
367
|
this.groupSeparator = null;
|
|
634
368
|
this.shortDateFormat = "dd.MM.yyyy";
|
|
635
|
-
this.login =
|
|
369
|
+
this.login = "";
|
|
636
370
|
this.isDeveloper = false;
|
|
371
|
+
this.culture = "en-GB";
|
|
372
|
+
this.uiculture = "en-GB";
|
|
373
|
+
this.expired = () => null;
|
|
637
374
|
this.formats = {};
|
|
638
375
|
Object.assign(this, userData);
|
|
639
376
|
}
|
|
640
377
|
};
|
|
641
378
|
|
|
642
|
-
// src/
|
|
643
|
-
function
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
379
|
+
// src/downloadBlob.ts
|
|
380
|
+
function downloadBlob(blob, fileName) {
|
|
381
|
+
return new Promise(function(resolve, reject) {
|
|
382
|
+
try {
|
|
383
|
+
const url = URL.createObjectURL(blob);
|
|
384
|
+
const parent = document.body;
|
|
385
|
+
const anchor = document.createElement("a");
|
|
386
|
+
anchor.setAttribute("download", fileName);
|
|
387
|
+
anchor.href = url;
|
|
388
|
+
parent.append(anchor);
|
|
389
|
+
anchor.click();
|
|
390
|
+
parent.removeChild(anchor);
|
|
391
|
+
setTimeout(function() {
|
|
392
|
+
URL.revokeObjectURL(url);
|
|
393
|
+
resolve();
|
|
394
|
+
}, 250);
|
|
395
|
+
} catch (ex) {
|
|
396
|
+
reject(ex);
|
|
397
|
+
}
|
|
398
|
+
});
|
|
658
399
|
}
|
|
659
|
-
|
|
400
|
+
|
|
401
|
+
// src/downloadRequest.ts
|
|
402
|
+
async function downloadRequest(request, { fileName, signal, onProgress }) {
|
|
660
403
|
var _a;
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
404
|
+
function reportProgress(progress) {
|
|
405
|
+
if (typeof onProgress === "function") {
|
|
406
|
+
onProgress(__spreadValues({}, progress));
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
let bytesReceived = 0;
|
|
410
|
+
reportProgress({ status: "requested" });
|
|
411
|
+
try {
|
|
412
|
+
let response = await fetch(request);
|
|
413
|
+
if (!response.ok || !response.body) {
|
|
414
|
+
if ((_a = response.headers.get("content-type")) == null ? void 0 : _a.includes("application/json")) {
|
|
415
|
+
let data = await response.json();
|
|
416
|
+
if (data.error) {
|
|
417
|
+
throw new Error(data.error);
|
|
418
|
+
}
|
|
672
419
|
}
|
|
420
|
+
throw new Error(`${response.status} ${response.statusText}`);
|
|
421
|
+
}
|
|
422
|
+
try {
|
|
423
|
+
const reader = response.body.getReader();
|
|
424
|
+
const stream = new ReadableStream({
|
|
425
|
+
start: function(controller) {
|
|
426
|
+
function pump() {
|
|
427
|
+
return reader.read().then(function(read) {
|
|
428
|
+
if (read.done) {
|
|
429
|
+
controller.close();
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
bytesReceived += read.value.length;
|
|
433
|
+
reportProgress({ bytesReceived, status: "downloading" });
|
|
434
|
+
controller.enqueue(read.value);
|
|
435
|
+
return pump();
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
return pump();
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
response = new Response(stream);
|
|
442
|
+
} catch (error) {
|
|
443
|
+
console.warn("Failed to replace response stream to log download progress.");
|
|
444
|
+
}
|
|
445
|
+
const blob = await response.blob();
|
|
446
|
+
reportProgress({ bytesReceived, status: "downloaded" });
|
|
447
|
+
await downloadBlob(blob, fileName);
|
|
448
|
+
reportProgress({ bytesReceived, status: "completed" });
|
|
449
|
+
} catch (err) {
|
|
450
|
+
if (signal == null ? void 0 : signal.aborted) {
|
|
451
|
+
reportProgress({ status: "cancelled" });
|
|
673
452
|
} else {
|
|
674
|
-
|
|
453
|
+
reportProgress({ error: err.message, status: "error" });
|
|
675
454
|
}
|
|
676
455
|
}
|
|
677
|
-
return result;
|
|
678
456
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
return
|
|
457
|
+
|
|
458
|
+
// src/has.ts
|
|
459
|
+
function has(obj, key2) {
|
|
460
|
+
return Object.prototype.hasOwnProperty.call(obj, key2);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// src/parseFunc.ts
|
|
464
|
+
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)*)\}$/;
|
|
465
|
+
function parseFunc(func) {
|
|
466
|
+
var match = func.toString().match(funcRegex);
|
|
467
|
+
if (match === null) {
|
|
468
|
+
throw new TypeError("Unable to parse function!");
|
|
469
|
+
}
|
|
470
|
+
return { name: match[1], args: match[2].split(","), body: match[3] };
|
|
683
471
|
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
return formDataToObject(form, types);
|
|
472
|
+
|
|
473
|
+
// src/Namespace.ts
|
|
474
|
+
function Namespace() {
|
|
688
475
|
}
|
|
476
|
+
Namespace.prototype = /* @__PURE__ */ Object.create(null);
|
|
477
|
+
var Namespace_default = Namespace;
|
|
478
|
+
|
|
479
|
+
// src/requireNamespace.ts
|
|
480
|
+
function requireNamespace(root, namespace) {
|
|
481
|
+
if (typeof root === "object") {
|
|
482
|
+
if (typeof namespace === "string") {
|
|
483
|
+
let path = namespace.split(".");
|
|
484
|
+
return requireNamespace(root, path);
|
|
485
|
+
} else if (Array.isArray(namespace)) {
|
|
486
|
+
let current = root;
|
|
487
|
+
for (let i = 0; i < namespace.length; i++) {
|
|
488
|
+
current = current[namespace[i]] = current[namespace[i]] || new Namespace_default();
|
|
489
|
+
}
|
|
490
|
+
return current;
|
|
491
|
+
} else {
|
|
492
|
+
throw new TypeError("Invalid type of parameter 'namespace'");
|
|
493
|
+
}
|
|
494
|
+
} else {
|
|
495
|
+
throw new TypeError("Invalid type of parameter 'root'");
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// src/warn.ts
|
|
500
|
+
function warn(message, fallbackToAlert) {
|
|
501
|
+
console.warn(message);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// src/expose.ts
|
|
505
|
+
function expose(name, value) {
|
|
506
|
+
if (arguments.length !== 2) {
|
|
507
|
+
throw new Error("Incorrect number of arguments passed to the expose function!");
|
|
508
|
+
}
|
|
509
|
+
if (Array.isArray(value)) {
|
|
510
|
+
for (let func of value) {
|
|
511
|
+
const { name: funcName } = parseFunc(func);
|
|
512
|
+
if (funcName) {
|
|
513
|
+
expose(name, func);
|
|
514
|
+
} else {
|
|
515
|
+
throw new Error(
|
|
516
|
+
"Unable to detect name of function! Name it, or only supply one function and include name in first parameter."
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
} else {
|
|
521
|
+
let keyName;
|
|
522
|
+
let namespace;
|
|
523
|
+
if (typeof value === "function") {
|
|
524
|
+
keyName = parseFunc(value).name;
|
|
525
|
+
}
|
|
526
|
+
if (typeof name === "string") {
|
|
527
|
+
let pathParts = name.split(".");
|
|
528
|
+
if (!keyName) {
|
|
529
|
+
keyName = pathParts[pathParts.length - 1];
|
|
530
|
+
pathParts = pathParts.slice(0, pathParts.length - 1);
|
|
531
|
+
}
|
|
532
|
+
namespace = requireNamespace(window, pathParts);
|
|
533
|
+
} else if (keyName && (typeof name === "object" || typeof name === "function")) {
|
|
534
|
+
namespace = name;
|
|
535
|
+
} else {
|
|
536
|
+
throw new TypeError("Invalid typeof parameter 'name', or unable to parse pValue!");
|
|
537
|
+
}
|
|
538
|
+
if (has(namespace, keyName)) {
|
|
539
|
+
warn([name, keyName].join(".") + " is already defined!");
|
|
540
|
+
} else {
|
|
541
|
+
namespace[keyName] = value;
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// src/localStorage.ts
|
|
547
|
+
function getLocalKey(key2) {
|
|
548
|
+
var _a;
|
|
549
|
+
return [((_a = af == null ? void 0 : af.article) == null ? void 0 : _a.id) || "", "common", key2].join(".");
|
|
550
|
+
}
|
|
551
|
+
var LocalStorage = class {
|
|
552
|
+
isPersisted() {
|
|
553
|
+
return true;
|
|
554
|
+
}
|
|
555
|
+
getLocalStorageKey(key2, global) {
|
|
556
|
+
return global ? ["common", key2].join(".") : getLocalKey(key2);
|
|
557
|
+
}
|
|
558
|
+
get(key2, defaultValue, global) {
|
|
559
|
+
const lsKey = this.getLocalStorageKey(key2, global);
|
|
560
|
+
const value = localStorage.getItem(lsKey);
|
|
561
|
+
return value !== null ? JSON.parse(value) : defaultValue;
|
|
562
|
+
}
|
|
563
|
+
set(key2, value, global) {
|
|
564
|
+
localStorage.setItem(
|
|
565
|
+
this.getLocalStorageKey(key2, global),
|
|
566
|
+
JSON.stringify(value)
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
remove(key2, global) {
|
|
570
|
+
const lsKey = this.getLocalStorageKey(key2, global);
|
|
571
|
+
if (localStorage.getItem(lsKey) !== null) {
|
|
572
|
+
localStorage.removeItem(lsKey);
|
|
573
|
+
return true;
|
|
574
|
+
} else {
|
|
575
|
+
return false;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
clear() {
|
|
579
|
+
const baseKey = getLocalKey("");
|
|
580
|
+
for (let key2 in localStorage) {
|
|
581
|
+
if (key2.slice(0, baseKey.length) === baseKey) {
|
|
582
|
+
localStorage.removeItem(key2);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
var localStorage_default = new LocalStorage();
|
|
689
588
|
|
|
690
589
|
// src/settings.ts
|
|
691
590
|
function getKey(article) {
|
|
@@ -716,6 +615,6 @@ return s;
|
|
|
716
615
|
}
|
|
717
616
|
|
|
718
617
|
// src/index.ts
|
|
719
|
-
var version = "
|
|
618
|
+
var version = "2.0.0";
|
|
720
619
|
return __toCommonJS(src_exports);
|
|
721
620
|
})();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var af=af||{};af.common=(()=>{var
|
|
1
|
+
"use strict";var af=af||{};af.common=(()=>{var S=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames,T=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable;var O=(t,e,n)=>e in t?S(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,R=(t,e)=>{for(var n in e||(e={}))k.call(e,n)&&O(t,n,e[n]);if(T)for(var n of T(e))K.call(e,n)&&O(t,n,e[n]);return t};var W=(t,e)=>{for(var n in e)S(t,n,{get:e[n],enumerable:!0})},F=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of U(e))!k.call(t,o)&&o!==n&&S(t,o,{get:()=>e[o],enumerable:!(r=M(e,o))||r.enumerable});return t};var B=t=>F(S({},"__esModule",{value:!0}),t);var ee={};W(ee,{SessionHandler:()=>u,UserSession:()=>w,downloadBlob:()=>x,downloadRequest:()=>Z,expose:()=>_,getLocalizedString:()=>m,getSettings:()=>V,has:()=>A,localStorage:()=>C,mitt:()=>b,saveSettings:()=>Q,version:()=>Y});window.addEventListener("error",t=>{var e,n,r,o,a,s,i;try{let f={error:(r=(n=(e=t.error)==null?void 0:e.message)!=null?n:t.message)!=null?r:null,file:t.filename,line:(o=t.lineno)!=null?o:0,column:(a=t.colno)!=null?a:0,stack:(i=(s=t.error)==null?void 0:s.stack)!=null?i:null};fetch("/data/Logger/LogError",{body:JSON.stringify(f),headers:{Accept:"application/json","Content-Type":"application/json; charset=utf-8","X-Requested-With":"XMLHttpRequest"},method:"POST"})}catch(f){}});function b(t){return{all:t=t||new Map,on:function(e,n){var r=t.get(e);r?r.push(n):t.set(e,[n])},off:function(e,n){var r=t.get(e);r&&(n?r.splice(r.indexOf(n)>>>0,1):t.set(e,[]))},emit:function(e,n){var r=t.get(e);r&&r.slice().map(function(o){o(n)}),(r=t.get("*"))&&r.slice().map(function(o){o(e,n)})}}}async function G(t){try{let e=await fetch("/api/user/localize",{body:JSON.stringify({string:t}),headers:{Accept:"application/json; */*","Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},method:"POST"});if(e.ok)return await e.json()}catch(e){}return t}function z(t,e){var n;if(((n=af==null?void 0:af.article)==null?void 0:n.i18n)!==void 0){if(!Object.prototype.hasOwnProperty.call(af.article.i18n,t)){af.article.i18n[t]=t;let r=G(t).then(o=>(af.article.i18n[t]=o,o));if(e)return r}return af.article.i18n[t]}else return t}var h="__UNLOCALIZED_STRINGS__",y=window[h]||new Set;window[h]||(window[h]=y);function I(){document.readyState!=="loading"&&(H(),document.removeEventListener("readystatechange",I))}document.readyState!=="loading"?H():document.addEventListener("readystatechange",I);function J(){let{af:t}=window;return t&&t.userSession&&t.userSession.isDeveloper}function H(){if(J()){if(typeof window.__doNothingWithStrings=="function"){let t=window.__doNothingWithStrings();for(let e of Object.keys(t))y.add(e)}window[h]||(window[h]=y),window.__getUnlocalizedStrings||(window.__getUnlocalizedStrings=function(t){let e=[];for(let n of y)if(n){let r=n.replace(/'/g,"\\'");if(t){let o=z(n).replaceAll(/'/g,"\\'");e.push(`'${r}': '${o}',`)}else e.push(`s['${r}'] = @Html(@context.AddLocalizableString("${n.replaceAll('"','\\"')}"));`)}return t?`// Localization hack, since it AddLocalizableString doesn't work properly when custom routes is used
|
|
2
2
|
if (af.userSession.uiculture === 'nb-NO') {
|
|
3
3
|
const strings = {
|
|
4
4
|
${e.join(`
|
|
@@ -16,7 +16,7 @@ ${e.join(`
|
|
|
16
16
|
`)}
|
|
17
17
|
return s;
|
|
18
18
|
}
|
|
19
|
-
<\/script>`})}}function m(t){let e=
|
|
19
|
+
<\/script>`})}}function m(t){let e=z(t);return e===t&&!y.has(t)&&y.add(t),e}var v=class{constructor(){this.eventHandler=b();this.showingDialog=!1;this.dialog=null}expired(e){if(af.userSession=af.userSession||{login:null},typeof e!="function")throw new TypeError("Parameter pCallback passed to the expired function must be a function!");let n=()=>{this.detachEvent("onAuthenticated",n),e()};if(this.attachEvent("onAuthenticated",n),this.showingDialog!==!0){this.showingDialog=!0;let r=document.createElement("div");r.className="session-expired-container",r.innerHTML=`
|
|
20
20
|
<div class="session-expired-log-in" style="margin-top: 20px;">
|
|
21
21
|
<div class="row">
|
|
22
22
|
<div class="sessionExpired">
|
|
@@ -44,5 +44,5 @@ return s;
|
|
|
44
44
|
</div>
|
|
45
45
|
</div>
|
|
46
46
|
</div>
|
|
47
|
-
`;let o=af.userSession.login?
|
|
47
|
+
`;let o=af.userSession.login?v.messages.relog:v.messages.login,a=r.querySelector(".message"),s=r.querySelector(".alert-warning"),i=r.querySelector("input[type=text]"),f=r.querySelector(".sign-in"),l=r.querySelector("input[type=password]");if(a!==null&&i!==null&&s!==null&&i!==null&&f!==null&&l!==null){a.innerText=m(o),i.value=af.userSession.login||"",i.disabled=!!af.userSession.login,i.readOnly=!!af.userSession.login,document.body.appendChild(r);let p=async()=>{l.disabled=!0;let c=new Request("/login",{body:JSON.stringify({username:i.value,password:l.value,remember:!1}),headers:{Accept:"application/json","Content-Type":"application/json; charset=utf-8","X-Requested-With":"XMLHttpRequest"},method:"POST"});try{let d=await(await fetch(c)).json();if(d.success)document.body.removeChild(r),this.showingDialog=!1,this.eventHandler.emit("onAuthenticated"),s.parentNode&&(s.parentNode.style.display="none");else throw new Error(d.error)}catch(g){if(g&&typeof g=="object"){let d=g;l.disabled=!1,l.classList.toggle("invalid",!0),l.value="",l.focus(),s.innerText=d.message?d.message:String(d),s.parentNode&&(s.parentNode.style.display="initial")}}};f.addEventListener("click",p),l.addEventListener("keyup",c=>{c.key==="Enter"&&p()}),l.addEventListener("change",c=>{c.key==="Enter"&&p()}),i.addEventListener("keyup",c=>{c.key==="Enter"&&p()}),i.addEventListener("change",c=>{c.key==="Enter"&&p()}),l.focus()}}}attachEvent(e,n){return this.eventHandler.on(e,n)}detachEvent(e,n){return this.eventHandler.off(e,n)}},u=v;u.messages={login:"Log in",relog:"Session expired - log in"};var w=class extends u{constructor(n){super();this.decimalSeparator=".";this.domain="OB";this.groupSeparator=null;this.shortDateFormat="dd.MM.yyyy";this.login="";this.isDeveloper=!1;this.culture="en-GB";this.uiculture="en-GB";this.expired=()=>null;this.formats={},Object.assign(this,n)}};function x(t,e){return new Promise(function(n,r){try{let o=URL.createObjectURL(t),a=document.body,s=document.createElement("a");s.setAttribute("download",e),s.href=o,a.append(s),s.click(),a.removeChild(s),setTimeout(function(){URL.revokeObjectURL(o),n()},250)}catch(o){r(o)}})}async function Z(t,{fileName:e,signal:n,onProgress:r}){var s;function o(i){typeof r=="function"&&r(R({},i))}let a=0;o({status:"requested"});try{let i=await fetch(t);if(!i.ok||!i.body){if((s=i.headers.get("content-type"))!=null&&s.includes("application/json")){let l=await i.json();if(l.error)throw new Error(l.error)}throw new Error(`${i.status} ${i.statusText}`)}try{let l=i.body.getReader(),p=new ReadableStream({start:function(c){function g(){return l.read().then(function(d){if(d.done){c.close();return}return a+=d.value.length,o({bytesReceived:a,status:"downloading"}),c.enqueue(d.value),g()})}return g()}});i=new Response(p)}catch(l){console.warn("Failed to replace response stream to log download progress.")}let f=await i.blob();o({bytesReceived:a,status:"downloaded"}),await x(f,e),o({bytesReceived:a,status:"completed"})}catch(i){n!=null&&n.aborted?o({status:"cancelled"}):o({error:i.message,status:"error"})}}function A(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var X=/^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 E(t){var e=t.toString().match(X);if(e===null)throw new TypeError("Unable to parse function!");return{name:e[1],args:e[2].split(","),body:e[3]}}function q(){}q.prototype=Object.create(null);var $=q;function L(t,e){if(typeof t=="object")if(typeof e=="string"){let n=e.split(".");return L(t,n)}else if(Array.isArray(e)){let n=t;for(let r=0;r<e.length;r++)n=n[e[r]]=n[e[r]]||new $;return n}else throw new TypeError("Invalid type of parameter 'namespace'");else throw new TypeError("Invalid type of parameter 'root'")}function N(t,e){console.warn(t)}function _(t,e){if(arguments.length!==2)throw new Error("Incorrect number of arguments passed to the expose function!");if(Array.isArray(e))for(let n of e){let{name:r}=E(n);if(r)_(t,n);else throw new Error("Unable to detect name of function! Name it, or only supply one function and include name in first parameter.")}else{let n,r;if(typeof e=="function"&&(n=E(e).name),typeof t=="string"){let o=t.split(".");n||(n=o[o.length-1],o=o.slice(0,o.length-1)),r=L(window,o)}else if(n&&(typeof t=="object"||typeof t=="function"))r=t;else throw new TypeError("Invalid typeof parameter 'name', or unable to parse pValue!");A(r,n)?N([t,n].join(".")+" is already defined!"):r[n]=e}}function D(t){var e;return[((e=af==null?void 0:af.article)==null?void 0:e.id)||"","common",t].join(".")}var j=class{isPersisted(){return!0}getLocalStorageKey(e,n){return n?["common",e].join("."):D(e)}get(e,n,r){let o=this.getLocalStorageKey(e,r),a=localStorage.getItem(o);return a!==null?JSON.parse(a):n}set(e,n,r){localStorage.setItem(this.getLocalStorageKey(e,r),JSON.stringify(n))}remove(e,n){let r=this.getLocalStorageKey(e,n);return localStorage.getItem(r)!==null?(localStorage.removeItem(r),!0):!1}clear(){let e=D("");for(let n in localStorage)n.slice(0,e.length)===e&&localStorage.removeItem(n)}},C=new j;function P(t){return`${t||af.article.id}.${af.userSession.login}`}function V(t,e){if(!(af!=null&&af.userSession))return null;let n=P(e),r=JSON.parse(localStorage.getItem(n)||"{}");return t?r[t]||null:r}function Q(t,e,n){if(!(af!=null&&af.userSession))return;let r=P(n),o=JSON.parse(localStorage.getItem(r)||"{}");typeof e<"u"?o[t]=e:o=t,localStorage.setItem(r,JSON.stringify(o))}var Y="2.0.0";return B(ee);})();
|
|
48
48
|
//# sourceMappingURL=af.common.legacy.min.js.map
|