@olenbetong/appframe-core 1.3.7 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/af.common.js +231 -315
- package/dist/esm/af.common.legacy.js +230 -316
- package/dist/esm/af.common.legacy.min.js +6 -6
- 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 +229 -316
- package/dist/iife/af.common.legacy.js +230 -317
- package/dist/iife/af.common.legacy.min.js +6 -6
- package/dist/iife/af.common.legacy.min.js.map +4 -4
- package/dist/iife/af.common.min.js +8 -8
- package/dist/iife/af.common.min.js.map +4 -4
- package/es/UserSession.d.ts +17 -3
- package/es/UserSession.js +13 -2
- package/es/index.d.ts +31 -3
- package/es/index.js +3 -4
- package/package.json +2 -2
- package/src/UserSession.ts +17 -3
- 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
package/dist/iife/af.common.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var af;
|
|
3
2
|
(af ||= {}).common = (() => {
|
|
4
3
|
var __defProp = Object.defineProperty;
|
|
5
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: true, configurable: true, writable: true, value }) : obj[key2] = value;
|
|
8
8
|
var __export = (target, all) => {
|
|
9
9
|
for (var name in all)
|
|
10
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -18,6 +18,10 @@ var af;
|
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
20
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var __publicField = (obj, key2, value) => {
|
|
22
|
+
__defNormalProp(obj, typeof key2 !== "symbol" ? key2 + "" : key2, value);
|
|
23
|
+
return value;
|
|
24
|
+
};
|
|
21
25
|
|
|
22
26
|
// src/index.ts
|
|
23
27
|
var src_exports = {};
|
|
@@ -26,18 +30,12 @@ var af;
|
|
|
26
30
|
UserSession: () => UserSession,
|
|
27
31
|
downloadBlob: () => downloadBlob,
|
|
28
32
|
downloadRequest: () => downloadRequest,
|
|
29
|
-
exportOptionsFromDataObject: () => exportOptionsFromDataObject,
|
|
30
33
|
expose: () => expose,
|
|
31
|
-
formDataToDataObjectRecord: () => formDataToDataObjectRecord,
|
|
32
|
-
formDataToObject: () => formDataToObject,
|
|
33
|
-
formDataToProcedureParameters: () => formDataToProcedureParameters,
|
|
34
|
-
getDataObjectReportRequest: () => getDataObjectReportRequest,
|
|
35
34
|
getLocalizedString: () => getLocalizedString,
|
|
36
35
|
getSettings: () => getSettings,
|
|
37
36
|
has: () => has,
|
|
38
37
|
localStorage: () => localStorage_default,
|
|
39
38
|
mitt: () => mitt_default,
|
|
40
|
-
openDataObjectReport: () => openDataObjectReport,
|
|
41
39
|
saveSettings: () => saveSettings,
|
|
42
40
|
version: () => version
|
|
43
41
|
});
|
|
@@ -83,223 +81,6 @@ var af;
|
|
|
83
81
|
} };
|
|
84
82
|
}
|
|
85
83
|
|
|
86
|
-
// src/downloadBlob.ts
|
|
87
|
-
function downloadBlob(blob, fileName) {
|
|
88
|
-
return new Promise(function(resolve, reject) {
|
|
89
|
-
try {
|
|
90
|
-
const url = URL.createObjectURL(blob);
|
|
91
|
-
const parent = document.body;
|
|
92
|
-
const anchor = document.createElement("a");
|
|
93
|
-
anchor.setAttribute("download", fileName);
|
|
94
|
-
anchor.href = url;
|
|
95
|
-
parent.append(anchor);
|
|
96
|
-
anchor.click();
|
|
97
|
-
parent.removeChild(anchor);
|
|
98
|
-
setTimeout(function() {
|
|
99
|
-
URL.revokeObjectURL(url);
|
|
100
|
-
resolve();
|
|
101
|
-
}, 250);
|
|
102
|
-
} catch (ex) {
|
|
103
|
-
reject(ex);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// src/downloadRequest.ts
|
|
109
|
-
async function downloadRequest(request, { fileName, signal, onProgress }) {
|
|
110
|
-
function reportProgress(progress) {
|
|
111
|
-
if (typeof onProgress === "function") {
|
|
112
|
-
onProgress({ ...progress });
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
let bytesReceived = 0;
|
|
116
|
-
reportProgress({ status: "requested" });
|
|
117
|
-
try {
|
|
118
|
-
let response = await fetch(request);
|
|
119
|
-
if (!response.ok || !response.body) {
|
|
120
|
-
if (response.headers.get("content-type")?.includes("application/json")) {
|
|
121
|
-
let data = await response.json();
|
|
122
|
-
if (data.error) {
|
|
123
|
-
throw new Error(data.error);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
throw new Error(`${response.status} ${response.statusText}`);
|
|
127
|
-
}
|
|
128
|
-
try {
|
|
129
|
-
const reader = response.body.getReader();
|
|
130
|
-
const stream = new ReadableStream({
|
|
131
|
-
start: function(controller) {
|
|
132
|
-
function pump() {
|
|
133
|
-
return reader.read().then(function(read) {
|
|
134
|
-
if (read.done) {
|
|
135
|
-
controller.close();
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
bytesReceived += read.value.length;
|
|
139
|
-
reportProgress({ bytesReceived, status: "downloading" });
|
|
140
|
-
controller.enqueue(read.value);
|
|
141
|
-
return pump();
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
return pump();
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
response = new Response(stream);
|
|
148
|
-
} catch (error) {
|
|
149
|
-
console.warn("Failed to replace response stream to log download progress.");
|
|
150
|
-
}
|
|
151
|
-
const blob = await response.blob();
|
|
152
|
-
reportProgress({ bytesReceived, status: "downloaded" });
|
|
153
|
-
await downloadBlob(blob, fileName);
|
|
154
|
-
reportProgress({ bytesReceived, status: "completed" });
|
|
155
|
-
} catch (err) {
|
|
156
|
-
if (signal?.aborted) {
|
|
157
|
-
reportProgress({ status: "cancelled" });
|
|
158
|
-
} else {
|
|
159
|
-
reportProgress({ error: err.message, status: "error" });
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// src/exportDataObject.ts
|
|
165
|
-
function exportOptionsFromDataObject(dataObject, specifiedOptions) {
|
|
166
|
-
return {
|
|
167
|
-
columns: dataObject.getFields().map((field) => ({ name: field.name })),
|
|
168
|
-
distinctRows: dataObject.getParameter("distinctRows"),
|
|
169
|
-
filterObject: dataObject.getParameter("filterObject"),
|
|
170
|
-
filterString: dataObject.getParameter("filterString"),
|
|
171
|
-
maxRecords: dataObject.getParameter("maxRecords"),
|
|
172
|
-
sortOrder: dataObject.getParameter("sortOrder"),
|
|
173
|
-
whereClause: dataObject.getParameter("whereClause"),
|
|
174
|
-
whereObject: dataObject.getParameter("whereObject"),
|
|
175
|
-
...specifiedOptions
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
var defaultOptions = {
|
|
179
|
-
columns: [],
|
|
180
|
-
distinctRows: false,
|
|
181
|
-
filterObject: null,
|
|
182
|
-
filterString: "",
|
|
183
|
-
maxRecords: -1,
|
|
184
|
-
sortOrder: [],
|
|
185
|
-
whereClause: "",
|
|
186
|
-
whereObject: null
|
|
187
|
-
};
|
|
188
|
-
function getDataObjectReportRequest(params) {
|
|
189
|
-
const { articleId, dataObject, format, options } = params;
|
|
190
|
-
const reportOptions = options ? Object.assign({}, defaultOptions, options) : defaultOptions;
|
|
191
|
-
const body = "data=" + encodeURIComponent(JSON.stringify(reportOptions));
|
|
192
|
-
const requestUrl = `/api/data-object/export/${articleId}/${dataObject}/${format}`;
|
|
193
|
-
const controller = params.controller ?? new AbortController();
|
|
194
|
-
return {
|
|
195
|
-
controller,
|
|
196
|
-
request: new Request(requestUrl, {
|
|
197
|
-
body,
|
|
198
|
-
credentials: "same-origin",
|
|
199
|
-
headers: {
|
|
200
|
-
"Content-Type": "application/x-www-form-urlencoded"
|
|
201
|
-
},
|
|
202
|
-
method: "POST",
|
|
203
|
-
signal: controller.signal
|
|
204
|
-
})
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
function openDataObjectReport(params) {
|
|
208
|
-
const { dataObject, fileName, format } = params;
|
|
209
|
-
const { request } = getDataObjectReportRequest(params);
|
|
210
|
-
return downloadRequest(request, {
|
|
211
|
-
fileName: `${fileName || dataObject}.${format}`
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// src/has.ts
|
|
216
|
-
function has(obj, key2) {
|
|
217
|
-
return Object.prototype.hasOwnProperty.call(obj, key2);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// src/parseFunc.ts
|
|
221
|
-
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)*)\}$/;
|
|
222
|
-
function parseFunc(func) {
|
|
223
|
-
var match = func.toString().match(funcRegex);
|
|
224
|
-
if (match === null) {
|
|
225
|
-
throw new TypeError("Unable to parse function!");
|
|
226
|
-
}
|
|
227
|
-
return { name: match[1], args: match[2].split(","), body: match[3] };
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// src/Namespace.ts
|
|
231
|
-
function Namespace() {
|
|
232
|
-
}
|
|
233
|
-
Namespace.prototype = /* @__PURE__ */ Object.create(null);
|
|
234
|
-
var Namespace_default = Namespace;
|
|
235
|
-
|
|
236
|
-
// src/requireNamespace.ts
|
|
237
|
-
function requireNamespace(root, namespace) {
|
|
238
|
-
if (typeof root === "object") {
|
|
239
|
-
if (typeof namespace === "string") {
|
|
240
|
-
let path = namespace.split(".");
|
|
241
|
-
return requireNamespace(root, path);
|
|
242
|
-
} else if (Array.isArray(namespace)) {
|
|
243
|
-
let current = root;
|
|
244
|
-
for (let i = 0; i < namespace.length; i++) {
|
|
245
|
-
current = current[namespace[i]] = current[namespace[i]] || new Namespace_default();
|
|
246
|
-
}
|
|
247
|
-
return current;
|
|
248
|
-
} else {
|
|
249
|
-
throw new TypeError("Invalid type of parameter 'namespace'");
|
|
250
|
-
}
|
|
251
|
-
} else {
|
|
252
|
-
throw new TypeError("Invalid type of parameter 'root'");
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// src/warn.ts
|
|
257
|
-
function warn(message, fallbackToAlert) {
|
|
258
|
-
console.warn(message);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// src/expose.ts
|
|
262
|
-
function expose(name, value) {
|
|
263
|
-
if (arguments.length !== 2) {
|
|
264
|
-
throw new Error("Incorrect number of arguments passed to the expose function!");
|
|
265
|
-
}
|
|
266
|
-
if (Array.isArray(value)) {
|
|
267
|
-
for (let func of value) {
|
|
268
|
-
const { name: funcName } = parseFunc(func);
|
|
269
|
-
if (funcName) {
|
|
270
|
-
expose(name, func);
|
|
271
|
-
} else {
|
|
272
|
-
throw new Error(
|
|
273
|
-
"Unable to detect name of function! Name it, or only supply one function and include name in first parameter."
|
|
274
|
-
);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
} else {
|
|
278
|
-
let keyName;
|
|
279
|
-
let namespace;
|
|
280
|
-
if (typeof value === "function") {
|
|
281
|
-
keyName = parseFunc(value).name;
|
|
282
|
-
}
|
|
283
|
-
if (typeof name === "string") {
|
|
284
|
-
let pathParts = name.split(".");
|
|
285
|
-
if (!keyName) {
|
|
286
|
-
keyName = pathParts[pathParts.length - 1];
|
|
287
|
-
pathParts = pathParts.slice(0, pathParts.length - 1);
|
|
288
|
-
}
|
|
289
|
-
namespace = requireNamespace(window, pathParts);
|
|
290
|
-
} else if (keyName && (typeof name === "object" || typeof name === "function")) {
|
|
291
|
-
namespace = name;
|
|
292
|
-
} else {
|
|
293
|
-
throw new TypeError("Invalid typeof parameter 'name', or unable to parse pValue!");
|
|
294
|
-
}
|
|
295
|
-
if (has(namespace, keyName)) {
|
|
296
|
-
warn([name, keyName].join(".") + " is already defined!");
|
|
297
|
-
} else {
|
|
298
|
-
namespace[keyName] = value;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
84
|
// src/getLocalizedString.ts
|
|
304
85
|
async function getLocalizedStringAsync(string) {
|
|
305
86
|
try {
|
|
@@ -421,55 +202,11 @@ return s;
|
|
|
421
202
|
return localized;
|
|
422
203
|
}
|
|
423
204
|
|
|
424
|
-
// src/localStorage.ts
|
|
425
|
-
function getLocalKey(key2) {
|
|
426
|
-
return [af?.article?.id || "", "common", key2].join(".");
|
|
427
|
-
}
|
|
428
|
-
var LocalStorage = class {
|
|
429
|
-
isPersisted() {
|
|
430
|
-
return true;
|
|
431
|
-
}
|
|
432
|
-
getLocalStorageKey(key2, global) {
|
|
433
|
-
return global ? ["common", key2].join(".") : getLocalKey(key2);
|
|
434
|
-
}
|
|
435
|
-
get(key2, defaultValue, global) {
|
|
436
|
-
const lsKey = this.getLocalStorageKey(key2, global);
|
|
437
|
-
const value = localStorage.getItem(lsKey);
|
|
438
|
-
return value !== null ? JSON.parse(value) : defaultValue;
|
|
439
|
-
}
|
|
440
|
-
set(key2, value, global) {
|
|
441
|
-
localStorage.setItem(
|
|
442
|
-
this.getLocalStorageKey(key2, global),
|
|
443
|
-
JSON.stringify(value)
|
|
444
|
-
);
|
|
445
|
-
}
|
|
446
|
-
remove(key2, global) {
|
|
447
|
-
const lsKey = this.getLocalStorageKey(key2, global);
|
|
448
|
-
if (localStorage.getItem(lsKey) !== null) {
|
|
449
|
-
localStorage.removeItem(lsKey);
|
|
450
|
-
return true;
|
|
451
|
-
} else {
|
|
452
|
-
return false;
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
clear() {
|
|
456
|
-
const baseKey = getLocalKey("");
|
|
457
|
-
for (let key2 in localStorage) {
|
|
458
|
-
if (key2.slice(0, baseKey.length) === baseKey) {
|
|
459
|
-
localStorage.removeItem(key2);
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
};
|
|
464
|
-
var localStorage_default = new LocalStorage();
|
|
465
|
-
|
|
466
205
|
// src/SessionHandler.ts
|
|
467
206
|
var _SessionHandler = class {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
this.dialog = null;
|
|
472
|
-
}
|
|
207
|
+
eventHandler = mitt_default();
|
|
208
|
+
showingDialog = false;
|
|
209
|
+
dialog = null;
|
|
473
210
|
expired(callback) {
|
|
474
211
|
af.userSession = af.userSession || {
|
|
475
212
|
login: null
|
|
@@ -602,71 +339,247 @@ return s;
|
|
|
602
339
|
}
|
|
603
340
|
};
|
|
604
341
|
var SessionHandler = _SessionHandler;
|
|
605
|
-
SessionHandler
|
|
342
|
+
__publicField(SessionHandler, "messages", {
|
|
606
343
|
login: "Log in",
|
|
607
344
|
relog: "Session expired - log in"
|
|
608
|
-
};
|
|
345
|
+
});
|
|
609
346
|
|
|
610
347
|
// src/UserSession.ts
|
|
611
348
|
var UserSession = class extends SessionHandler {
|
|
349
|
+
amDesignator = "a.m.";
|
|
350
|
+
dayNames = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
|
351
|
+
dayNamesShort = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
|
|
352
|
+
decimalSeparator = ".";
|
|
353
|
+
domain = "OB";
|
|
354
|
+
email;
|
|
355
|
+
formats;
|
|
356
|
+
groupSeparator = null;
|
|
357
|
+
integratedSecurity = false;
|
|
358
|
+
isDeveloper = false;
|
|
359
|
+
login = "";
|
|
360
|
+
loginType;
|
|
361
|
+
monthNames = ["january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december", ""];
|
|
362
|
+
monthNamesShort = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "augt", "sep", "oct", "nov", "dec", ""];
|
|
363
|
+
name;
|
|
364
|
+
pmDesignator = "p.m.";
|
|
365
|
+
shortDateFormat = "dd.MM.yyyy";
|
|
366
|
+
culture = "en-GB";
|
|
367
|
+
uiculture = "en-GB";
|
|
368
|
+
expired = () => null;
|
|
612
369
|
constructor(userData) {
|
|
613
370
|
super();
|
|
614
|
-
this.decimalSeparator = ".";
|
|
615
|
-
this.groupSeparator = null;
|
|
616
|
-
this.shortDateFormat = "dd.MM.yyyy";
|
|
617
|
-
this.login = null;
|
|
618
|
-
this.isDeveloper = false;
|
|
619
371
|
this.formats = {};
|
|
620
372
|
Object.assign(this, userData);
|
|
621
373
|
}
|
|
622
374
|
};
|
|
623
375
|
|
|
624
|
-
// src/
|
|
625
|
-
function
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
376
|
+
// src/downloadBlob.ts
|
|
377
|
+
function downloadBlob(blob, fileName) {
|
|
378
|
+
return new Promise(function(resolve, reject) {
|
|
379
|
+
try {
|
|
380
|
+
const url = URL.createObjectURL(blob);
|
|
381
|
+
const parent = document.body;
|
|
382
|
+
const anchor = document.createElement("a");
|
|
383
|
+
anchor.setAttribute("download", fileName);
|
|
384
|
+
anchor.href = url;
|
|
385
|
+
parent.append(anchor);
|
|
386
|
+
anchor.click();
|
|
387
|
+
parent.removeChild(anchor);
|
|
388
|
+
setTimeout(function() {
|
|
389
|
+
URL.revokeObjectURL(url);
|
|
390
|
+
resolve();
|
|
391
|
+
}, 250);
|
|
392
|
+
} catch (ex) {
|
|
393
|
+
reject(ex);
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// src/downloadRequest.ts
|
|
399
|
+
async function downloadRequest(request, { fileName, signal, onProgress }) {
|
|
400
|
+
function reportProgress(progress) {
|
|
401
|
+
if (typeof onProgress === "function") {
|
|
402
|
+
onProgress({ ...progress });
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
let bytesReceived = 0;
|
|
406
|
+
reportProgress({ status: "requested" });
|
|
407
|
+
try {
|
|
408
|
+
let response = await fetch(request);
|
|
409
|
+
if (!response.ok || !response.body) {
|
|
410
|
+
if (response.headers.get("content-type")?.includes("application/json")) {
|
|
411
|
+
let data = await response.json();
|
|
412
|
+
if (data.error) {
|
|
413
|
+
throw new Error(data.error);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
throw new Error(`${response.status} ${response.statusText}`);
|
|
417
|
+
}
|
|
418
|
+
try {
|
|
419
|
+
const reader = response.body.getReader();
|
|
420
|
+
const stream = new ReadableStream({
|
|
421
|
+
start: function(controller) {
|
|
422
|
+
function pump() {
|
|
423
|
+
return reader.read().then(function(read) {
|
|
424
|
+
if (read.done) {
|
|
425
|
+
controller.close();
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
bytesReceived += read.value.length;
|
|
429
|
+
reportProgress({ bytesReceived, status: "downloading" });
|
|
430
|
+
controller.enqueue(read.value);
|
|
431
|
+
return pump();
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
return pump();
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
response = new Response(stream);
|
|
438
|
+
} catch (error) {
|
|
439
|
+
console.warn("Failed to replace response stream to log download progress.");
|
|
440
|
+
}
|
|
441
|
+
const blob = await response.blob();
|
|
442
|
+
reportProgress({ bytesReceived, status: "downloaded" });
|
|
443
|
+
await downloadBlob(blob, fileName);
|
|
444
|
+
reportProgress({ bytesReceived, status: "completed" });
|
|
445
|
+
} catch (err) {
|
|
446
|
+
if (signal?.aborted) {
|
|
447
|
+
reportProgress({ status: "cancelled" });
|
|
448
|
+
} else {
|
|
449
|
+
reportProgress({ error: err.message, status: "error" });
|
|
450
|
+
}
|
|
638
451
|
}
|
|
639
|
-
return value;
|
|
640
452
|
}
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
453
|
+
|
|
454
|
+
// src/has.ts
|
|
455
|
+
function has(obj, key2) {
|
|
456
|
+
return Object.prototype.hasOwnProperty.call(obj, key2);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// src/parseFunc.ts
|
|
460
|
+
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)*)\}$/;
|
|
461
|
+
function parseFunc(func) {
|
|
462
|
+
var match = func.toString().match(funcRegex);
|
|
463
|
+
if (match === null) {
|
|
464
|
+
throw new TypeError("Unable to parse function!");
|
|
465
|
+
}
|
|
466
|
+
return { name: match[1], args: match[2].split(","), body: match[3] };
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// src/Namespace.ts
|
|
470
|
+
function Namespace() {
|
|
471
|
+
}
|
|
472
|
+
Namespace.prototype = /* @__PURE__ */ Object.create(null);
|
|
473
|
+
var Namespace_default = Namespace;
|
|
474
|
+
|
|
475
|
+
// src/requireNamespace.ts
|
|
476
|
+
function requireNamespace(root, namespace) {
|
|
477
|
+
if (typeof root === "object") {
|
|
478
|
+
if (typeof namespace === "string") {
|
|
479
|
+
let path = namespace.split(".");
|
|
480
|
+
return requireNamespace(root, path);
|
|
481
|
+
} else if (Array.isArray(namespace)) {
|
|
482
|
+
let current = root;
|
|
483
|
+
for (let i = 0; i < namespace.length; i++) {
|
|
484
|
+
current = current[namespace[i]] = current[namespace[i]] || new Namespace_default();
|
|
653
485
|
}
|
|
486
|
+
return current;
|
|
654
487
|
} else {
|
|
655
|
-
|
|
488
|
+
throw new TypeError("Invalid type of parameter 'namespace'");
|
|
656
489
|
}
|
|
490
|
+
} else {
|
|
491
|
+
throw new TypeError("Invalid type of parameter 'root'");
|
|
657
492
|
}
|
|
658
|
-
return result;
|
|
659
493
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
494
|
+
|
|
495
|
+
// src/warn.ts
|
|
496
|
+
function warn(message, fallbackToAlert) {
|
|
497
|
+
console.warn(message);
|
|
664
498
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
499
|
+
|
|
500
|
+
// src/expose.ts
|
|
501
|
+
function expose(name, value) {
|
|
502
|
+
if (arguments.length !== 2) {
|
|
503
|
+
throw new Error("Incorrect number of arguments passed to the expose function!");
|
|
504
|
+
}
|
|
505
|
+
if (Array.isArray(value)) {
|
|
506
|
+
for (let func of value) {
|
|
507
|
+
const { name: funcName } = parseFunc(func);
|
|
508
|
+
if (funcName) {
|
|
509
|
+
expose(name, func);
|
|
510
|
+
} else {
|
|
511
|
+
throw new Error(
|
|
512
|
+
"Unable to detect name of function! Name it, or only supply one function and include name in first parameter."
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
} else {
|
|
517
|
+
let keyName;
|
|
518
|
+
let namespace;
|
|
519
|
+
if (typeof value === "function") {
|
|
520
|
+
keyName = parseFunc(value).name;
|
|
521
|
+
}
|
|
522
|
+
if (typeof name === "string") {
|
|
523
|
+
let pathParts = name.split(".");
|
|
524
|
+
if (!keyName) {
|
|
525
|
+
keyName = pathParts[pathParts.length - 1];
|
|
526
|
+
pathParts = pathParts.slice(0, pathParts.length - 1);
|
|
527
|
+
}
|
|
528
|
+
namespace = requireNamespace(window, pathParts);
|
|
529
|
+
} else if (keyName && (typeof name === "object" || typeof name === "function")) {
|
|
530
|
+
namespace = name;
|
|
531
|
+
} else {
|
|
532
|
+
throw new TypeError("Invalid typeof parameter 'name', or unable to parse pValue!");
|
|
533
|
+
}
|
|
534
|
+
if (has(namespace, keyName)) {
|
|
535
|
+
warn([name, keyName].join(".") + " is already defined!");
|
|
536
|
+
} else {
|
|
537
|
+
namespace[keyName] = value;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// src/localStorage.ts
|
|
543
|
+
function getLocalKey(key2) {
|
|
544
|
+
return [af?.article?.id || "", "common", key2].join(".");
|
|
669
545
|
}
|
|
546
|
+
var LocalStorage = class {
|
|
547
|
+
isPersisted() {
|
|
548
|
+
return true;
|
|
549
|
+
}
|
|
550
|
+
getLocalStorageKey(key2, global) {
|
|
551
|
+
return global ? ["common", key2].join(".") : getLocalKey(key2);
|
|
552
|
+
}
|
|
553
|
+
get(key2, defaultValue, global) {
|
|
554
|
+
const lsKey = this.getLocalStorageKey(key2, global);
|
|
555
|
+
const value = localStorage.getItem(lsKey);
|
|
556
|
+
return value !== null ? JSON.parse(value) : defaultValue;
|
|
557
|
+
}
|
|
558
|
+
set(key2, value, global) {
|
|
559
|
+
localStorage.setItem(
|
|
560
|
+
this.getLocalStorageKey(key2, global),
|
|
561
|
+
JSON.stringify(value)
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
remove(key2, global) {
|
|
565
|
+
const lsKey = this.getLocalStorageKey(key2, global);
|
|
566
|
+
if (localStorage.getItem(lsKey) !== null) {
|
|
567
|
+
localStorage.removeItem(lsKey);
|
|
568
|
+
return true;
|
|
569
|
+
} else {
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
clear() {
|
|
574
|
+
const baseKey = getLocalKey("");
|
|
575
|
+
for (let key2 in localStorage) {
|
|
576
|
+
if (key2.slice(0, baseKey.length) === baseKey) {
|
|
577
|
+
localStorage.removeItem(key2);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
var localStorage_default = new LocalStorage();
|
|
670
583
|
|
|
671
584
|
// src/settings.ts
|
|
672
585
|
function getKey(article) {
|
|
@@ -697,6 +610,6 @@ return s;
|
|
|
697
610
|
}
|
|
698
611
|
|
|
699
612
|
// src/index.ts
|
|
700
|
-
var version = "
|
|
613
|
+
var version = "2.0.1";
|
|
701
614
|
return __toCommonJS(src_exports);
|
|
702
615
|
})();
|