@olenbetong/appframe-core 1.3.7 → 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
package/dist/iife/af.common.js
CHANGED
|
@@ -26,18 +26,12 @@ var af;
|
|
|
26
26
|
UserSession: () => UserSession,
|
|
27
27
|
downloadBlob: () => downloadBlob,
|
|
28
28
|
downloadRequest: () => downloadRequest,
|
|
29
|
-
exportOptionsFromDataObject: () => exportOptionsFromDataObject,
|
|
30
29
|
expose: () => expose,
|
|
31
|
-
formDataToDataObjectRecord: () => formDataToDataObjectRecord,
|
|
32
|
-
formDataToObject: () => formDataToObject,
|
|
33
|
-
formDataToProcedureParameters: () => formDataToProcedureParameters,
|
|
34
|
-
getDataObjectReportRequest: () => getDataObjectReportRequest,
|
|
35
30
|
getLocalizedString: () => getLocalizedString,
|
|
36
31
|
getSettings: () => getSettings,
|
|
37
32
|
has: () => has,
|
|
38
33
|
localStorage: () => localStorage_default,
|
|
39
34
|
mitt: () => mitt_default,
|
|
40
|
-
openDataObjectReport: () => openDataObjectReport,
|
|
41
35
|
saveSettings: () => saveSettings,
|
|
42
36
|
version: () => version
|
|
43
37
|
});
|
|
@@ -83,223 +77,6 @@ var af;
|
|
|
83
77
|
} };
|
|
84
78
|
}
|
|
85
79
|
|
|
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
80
|
// src/getLocalizedString.ts
|
|
304
81
|
async function getLocalizedStringAsync(string) {
|
|
305
82
|
try {
|
|
@@ -421,48 +198,6 @@ return s;
|
|
|
421
198
|
return localized;
|
|
422
199
|
}
|
|
423
200
|
|
|
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
201
|
// src/SessionHandler.ts
|
|
467
202
|
var _SessionHandler = class {
|
|
468
203
|
constructor() {
|
|
@@ -612,61 +347,226 @@ return s;
|
|
|
612
347
|
constructor(userData) {
|
|
613
348
|
super();
|
|
614
349
|
this.decimalSeparator = ".";
|
|
350
|
+
this.domain = "OB";
|
|
615
351
|
this.groupSeparator = null;
|
|
616
352
|
this.shortDateFormat = "dd.MM.yyyy";
|
|
617
|
-
this.login =
|
|
353
|
+
this.login = "";
|
|
618
354
|
this.isDeveloper = false;
|
|
355
|
+
this.culture = "en-GB";
|
|
356
|
+
this.uiculture = "en-GB";
|
|
357
|
+
this.expired = () => null;
|
|
619
358
|
this.formats = {};
|
|
620
359
|
Object.assign(this, userData);
|
|
621
360
|
}
|
|
622
361
|
};
|
|
623
362
|
|
|
624
|
-
// src/
|
|
625
|
-
function
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
363
|
+
// src/downloadBlob.ts
|
|
364
|
+
function downloadBlob(blob, fileName) {
|
|
365
|
+
return new Promise(function(resolve, reject) {
|
|
366
|
+
try {
|
|
367
|
+
const url = URL.createObjectURL(blob);
|
|
368
|
+
const parent = document.body;
|
|
369
|
+
const anchor = document.createElement("a");
|
|
370
|
+
anchor.setAttribute("download", fileName);
|
|
371
|
+
anchor.href = url;
|
|
372
|
+
parent.append(anchor);
|
|
373
|
+
anchor.click();
|
|
374
|
+
parent.removeChild(anchor);
|
|
375
|
+
setTimeout(function() {
|
|
376
|
+
URL.revokeObjectURL(url);
|
|
377
|
+
resolve();
|
|
378
|
+
}, 250);
|
|
379
|
+
} catch (ex) {
|
|
380
|
+
reject(ex);
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// src/downloadRequest.ts
|
|
386
|
+
async function downloadRequest(request, { fileName, signal, onProgress }) {
|
|
387
|
+
function reportProgress(progress) {
|
|
388
|
+
if (typeof onProgress === "function") {
|
|
389
|
+
onProgress({ ...progress });
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
let bytesReceived = 0;
|
|
393
|
+
reportProgress({ status: "requested" });
|
|
394
|
+
try {
|
|
395
|
+
let response = await fetch(request);
|
|
396
|
+
if (!response.ok || !response.body) {
|
|
397
|
+
if (response.headers.get("content-type")?.includes("application/json")) {
|
|
398
|
+
let data = await response.json();
|
|
399
|
+
if (data.error) {
|
|
400
|
+
throw new Error(data.error);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
throw new Error(`${response.status} ${response.statusText}`);
|
|
404
|
+
}
|
|
405
|
+
try {
|
|
406
|
+
const reader = response.body.getReader();
|
|
407
|
+
const stream = new ReadableStream({
|
|
408
|
+
start: function(controller) {
|
|
409
|
+
function pump() {
|
|
410
|
+
return reader.read().then(function(read) {
|
|
411
|
+
if (read.done) {
|
|
412
|
+
controller.close();
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
bytesReceived += read.value.length;
|
|
416
|
+
reportProgress({ bytesReceived, status: "downloading" });
|
|
417
|
+
controller.enqueue(read.value);
|
|
418
|
+
return pump();
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
return pump();
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
response = new Response(stream);
|
|
425
|
+
} catch (error) {
|
|
426
|
+
console.warn("Failed to replace response stream to log download progress.");
|
|
427
|
+
}
|
|
428
|
+
const blob = await response.blob();
|
|
429
|
+
reportProgress({ bytesReceived, status: "downloaded" });
|
|
430
|
+
await downloadBlob(blob, fileName);
|
|
431
|
+
reportProgress({ bytesReceived, status: "completed" });
|
|
432
|
+
} catch (err) {
|
|
433
|
+
if (signal?.aborted) {
|
|
434
|
+
reportProgress({ status: "cancelled" });
|
|
435
|
+
} else {
|
|
436
|
+
reportProgress({ error: err.message, status: "error" });
|
|
437
|
+
}
|
|
638
438
|
}
|
|
639
|
-
return value;
|
|
640
439
|
}
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
440
|
+
|
|
441
|
+
// src/has.ts
|
|
442
|
+
function has(obj, key2) {
|
|
443
|
+
return Object.prototype.hasOwnProperty.call(obj, key2);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// src/parseFunc.ts
|
|
447
|
+
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)*)\}$/;
|
|
448
|
+
function parseFunc(func) {
|
|
449
|
+
var match = func.toString().match(funcRegex);
|
|
450
|
+
if (match === null) {
|
|
451
|
+
throw new TypeError("Unable to parse function!");
|
|
452
|
+
}
|
|
453
|
+
return { name: match[1], args: match[2].split(","), body: match[3] };
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// src/Namespace.ts
|
|
457
|
+
function Namespace() {
|
|
458
|
+
}
|
|
459
|
+
Namespace.prototype = /* @__PURE__ */ Object.create(null);
|
|
460
|
+
var Namespace_default = Namespace;
|
|
461
|
+
|
|
462
|
+
// src/requireNamespace.ts
|
|
463
|
+
function requireNamespace(root, namespace) {
|
|
464
|
+
if (typeof root === "object") {
|
|
465
|
+
if (typeof namespace === "string") {
|
|
466
|
+
let path = namespace.split(".");
|
|
467
|
+
return requireNamespace(root, path);
|
|
468
|
+
} else if (Array.isArray(namespace)) {
|
|
469
|
+
let current = root;
|
|
470
|
+
for (let i = 0; i < namespace.length; i++) {
|
|
471
|
+
current = current[namespace[i]] = current[namespace[i]] || new Namespace_default();
|
|
653
472
|
}
|
|
473
|
+
return current;
|
|
654
474
|
} else {
|
|
655
|
-
|
|
475
|
+
throw new TypeError("Invalid type of parameter 'namespace'");
|
|
656
476
|
}
|
|
477
|
+
} else {
|
|
478
|
+
throw new TypeError("Invalid type of parameter 'root'");
|
|
657
479
|
}
|
|
658
|
-
return result;
|
|
659
480
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
481
|
+
|
|
482
|
+
// src/warn.ts
|
|
483
|
+
function warn(message, fallbackToAlert) {
|
|
484
|
+
console.warn(message);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// src/expose.ts
|
|
488
|
+
function expose(name, value) {
|
|
489
|
+
if (arguments.length !== 2) {
|
|
490
|
+
throw new Error("Incorrect number of arguments passed to the expose function!");
|
|
491
|
+
}
|
|
492
|
+
if (Array.isArray(value)) {
|
|
493
|
+
for (let func of value) {
|
|
494
|
+
const { name: funcName } = parseFunc(func);
|
|
495
|
+
if (funcName) {
|
|
496
|
+
expose(name, func);
|
|
497
|
+
} else {
|
|
498
|
+
throw new Error(
|
|
499
|
+
"Unable to detect name of function! Name it, or only supply one function and include name in first parameter."
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
} else {
|
|
504
|
+
let keyName;
|
|
505
|
+
let namespace;
|
|
506
|
+
if (typeof value === "function") {
|
|
507
|
+
keyName = parseFunc(value).name;
|
|
508
|
+
}
|
|
509
|
+
if (typeof name === "string") {
|
|
510
|
+
let pathParts = name.split(".");
|
|
511
|
+
if (!keyName) {
|
|
512
|
+
keyName = pathParts[pathParts.length - 1];
|
|
513
|
+
pathParts = pathParts.slice(0, pathParts.length - 1);
|
|
514
|
+
}
|
|
515
|
+
namespace = requireNamespace(window, pathParts);
|
|
516
|
+
} else if (keyName && (typeof name === "object" || typeof name === "function")) {
|
|
517
|
+
namespace = name;
|
|
518
|
+
} else {
|
|
519
|
+
throw new TypeError("Invalid typeof parameter 'name', or unable to parse pValue!");
|
|
520
|
+
}
|
|
521
|
+
if (has(namespace, keyName)) {
|
|
522
|
+
warn([name, keyName].join(".") + " is already defined!");
|
|
523
|
+
} else {
|
|
524
|
+
namespace[keyName] = value;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
664
527
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
return
|
|
528
|
+
|
|
529
|
+
// src/localStorage.ts
|
|
530
|
+
function getLocalKey(key2) {
|
|
531
|
+
return [af?.article?.id || "", "common", key2].join(".");
|
|
669
532
|
}
|
|
533
|
+
var LocalStorage = class {
|
|
534
|
+
isPersisted() {
|
|
535
|
+
return true;
|
|
536
|
+
}
|
|
537
|
+
getLocalStorageKey(key2, global) {
|
|
538
|
+
return global ? ["common", key2].join(".") : getLocalKey(key2);
|
|
539
|
+
}
|
|
540
|
+
get(key2, defaultValue, global) {
|
|
541
|
+
const lsKey = this.getLocalStorageKey(key2, global);
|
|
542
|
+
const value = localStorage.getItem(lsKey);
|
|
543
|
+
return value !== null ? JSON.parse(value) : defaultValue;
|
|
544
|
+
}
|
|
545
|
+
set(key2, value, global) {
|
|
546
|
+
localStorage.setItem(
|
|
547
|
+
this.getLocalStorageKey(key2, global),
|
|
548
|
+
JSON.stringify(value)
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
remove(key2, global) {
|
|
552
|
+
const lsKey = this.getLocalStorageKey(key2, global);
|
|
553
|
+
if (localStorage.getItem(lsKey) !== null) {
|
|
554
|
+
localStorage.removeItem(lsKey);
|
|
555
|
+
return true;
|
|
556
|
+
} else {
|
|
557
|
+
return false;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
clear() {
|
|
561
|
+
const baseKey = getLocalKey("");
|
|
562
|
+
for (let key2 in localStorage) {
|
|
563
|
+
if (key2.slice(0, baseKey.length) === baseKey) {
|
|
564
|
+
localStorage.removeItem(key2);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
var localStorage_default = new LocalStorage();
|
|
670
570
|
|
|
671
571
|
// src/settings.ts
|
|
672
572
|
function getKey(article) {
|
|
@@ -697,6 +597,6 @@ return s;
|
|
|
697
597
|
}
|
|
698
598
|
|
|
699
599
|
// src/index.ts
|
|
700
|
-
var version = "
|
|
600
|
+
var version = "2.0.0";
|
|
701
601
|
return __toCommonJS(src_exports);
|
|
702
602
|
})();
|