@olenbetong/appframe-core 2.0.2 → 2.0.4
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 +40 -112
- package/dist/esm/af.common.legacy.js +40 -112
- package/dist/esm/af.common.legacy.min.js +5 -23
- package/dist/esm/af.common.legacy.min.js.map +4 -4
- package/dist/esm/af.common.min.js +5 -23
- package/dist/esm/af.common.min.js.map +4 -4
- package/dist/iife/af.common.js +43 -115
- package/dist/iife/af.common.legacy.js +43 -115
- package/dist/iife/af.common.legacy.min.js +2 -20
- package/dist/iife/af.common.legacy.min.js.map +4 -4
- package/dist/iife/af.common.min.js +5 -23
- package/dist/iife/af.common.min.js.map +4 -4
- package/es/getLocalizedString.d.ts +6 -7
- package/es/getLocalizedString.js +19 -85
- package/es/index.js +1 -1
- package/package.json +2 -2
- package/src/getLocalizedString.ts +32 -111
package/dist/esm/af.common.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj,
|
|
3
|
-
var __publicField = (obj,
|
|
4
|
-
__defNormalProp(obj, typeof
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
7
|
|
|
@@ -46,11 +46,16 @@ function mitt_default(n) {
|
|
|
46
46
|
} };
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
// src/has.ts
|
|
50
|
+
function has(obj, key) {
|
|
51
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
52
|
+
}
|
|
53
|
+
|
|
49
54
|
// src/getLocalizedString.ts
|
|
50
|
-
async function
|
|
55
|
+
async function fetchLocalizedString(text) {
|
|
51
56
|
try {
|
|
52
|
-
let response = await fetch(`/api/user/localize`, {
|
|
53
|
-
body: JSON.stringify({
|
|
57
|
+
let response = await fetch(`/api/user/localize/new/${af.article.id}`, {
|
|
58
|
+
body: JSON.stringify({ text }),
|
|
54
59
|
headers: {
|
|
55
60
|
Accept: "application/json; */*",
|
|
56
61
|
"Content-Type": "application/json",
|
|
@@ -63,13 +68,19 @@ async function getLocalizedStringAsync(string) {
|
|
|
63
68
|
}
|
|
64
69
|
} catch (error) {
|
|
65
70
|
}
|
|
66
|
-
return
|
|
71
|
+
return text;
|
|
67
72
|
}
|
|
68
|
-
function
|
|
73
|
+
function getLocalizedString(string, wait) {
|
|
74
|
+
if (typeof string === "string" && string.trim().length === 0) {
|
|
75
|
+
return string;
|
|
76
|
+
}
|
|
77
|
+
if (string === void 0 || string === "" || string === null) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
69
80
|
if (af?.article?.i18n !== void 0) {
|
|
70
|
-
if (!
|
|
81
|
+
if (!has(af.article.i18n, string)) {
|
|
71
82
|
af.article.i18n[string] = string;
|
|
72
|
-
let promise =
|
|
83
|
+
let promise = fetchLocalizedString(string).then((text) => {
|
|
73
84
|
af.article.i18n[string] = text;
|
|
74
85
|
return text;
|
|
75
86
|
});
|
|
@@ -82,84 +93,6 @@ function afGetLocalizedString(string, wait) {
|
|
|
82
93
|
return string;
|
|
83
94
|
}
|
|
84
95
|
}
|
|
85
|
-
var key = "__UNLOCALIZED_STRINGS__";
|
|
86
|
-
var localizeSet = window[key] || /* @__PURE__ */ new Set();
|
|
87
|
-
if (!window[key]) {
|
|
88
|
-
window[key] = localizeSet;
|
|
89
|
-
}
|
|
90
|
-
function handleReadyStateChange() {
|
|
91
|
-
if (document.readyState !== "loading") {
|
|
92
|
-
addDeveloperUtils();
|
|
93
|
-
document.removeEventListener("readystatechange", handleReadyStateChange);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
if (document.readyState !== "loading") {
|
|
97
|
-
addDeveloperUtils();
|
|
98
|
-
} else {
|
|
99
|
-
document.addEventListener("readystatechange", handleReadyStateChange);
|
|
100
|
-
}
|
|
101
|
-
function isDeveloper() {
|
|
102
|
-
const { af: af2 } = window;
|
|
103
|
-
return af2 && af2.userSession && af2.userSession.isDeveloper;
|
|
104
|
-
}
|
|
105
|
-
function addDeveloperUtils() {
|
|
106
|
-
if (isDeveloper()) {
|
|
107
|
-
if (typeof window.__doNothingWithStrings === "function") {
|
|
108
|
-
const addedStrings = window.__doNothingWithStrings();
|
|
109
|
-
for (let string of Object.keys(addedStrings)) {
|
|
110
|
-
localizeSet.add(string);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
if (!window[key]) {
|
|
114
|
-
window[key] = localizeSet;
|
|
115
|
-
}
|
|
116
|
-
if (!window.__getUnlocalizedStrings) {
|
|
117
|
-
window.__getUnlocalizedStrings = function(forCustomRoute) {
|
|
118
|
-
const strings = [];
|
|
119
|
-
for (let string of localizeSet) {
|
|
120
|
-
if (string) {
|
|
121
|
-
const escaped = string.replace(/'/g, "\\'");
|
|
122
|
-
if (forCustomRoute) {
|
|
123
|
-
const localized = afGetLocalizedString(string).replaceAll(/'/g, "\\'");
|
|
124
|
-
strings.push(`'${escaped}': '${localized}',`);
|
|
125
|
-
} else {
|
|
126
|
-
strings.push(
|
|
127
|
-
`s['${escaped}'] = @Html(@context.AddLocalizableString("${string.replaceAll('"', '\\"')}"));`
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (forCustomRoute) {
|
|
133
|
-
return `// Localization hack, since it AddLocalizableString doesn't work properly when custom routes is used
|
|
134
|
-
if (af.userSession.uiculture === 'nb-NO') {
|
|
135
|
-
const strings = {
|
|
136
|
-
${strings.join("\n ")}
|
|
137
|
-
};
|
|
138
|
-
af.article.i18n = af.article.i18n || {};
|
|
139
|
-
Object.assign(af.article.i18n, strings);
|
|
140
|
-
}`;
|
|
141
|
-
}
|
|
142
|
-
return `<script type="text/javascript">
|
|
143
|
-
function __doNothingWithStrings() {
|
|
144
|
-
@{
|
|
145
|
-
var context = @Appframe.Web.Context.RequestContext.Current;
|
|
146
|
-
}
|
|
147
|
-
let s = {};
|
|
148
|
-
${strings.join("\n")}
|
|
149
|
-
return s;
|
|
150
|
-
}
|
|
151
|
-
<\/script>`;
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
function getLocalizedString(string) {
|
|
157
|
-
const localized = afGetLocalizedString(string);
|
|
158
|
-
if (localized === string && !localizeSet.has(string)) {
|
|
159
|
-
localizeSet.add(string);
|
|
160
|
-
}
|
|
161
|
-
return localized;
|
|
162
|
-
}
|
|
163
96
|
|
|
164
97
|
// src/SessionHandler.ts
|
|
165
98
|
var _SessionHandler = class {
|
|
@@ -410,11 +343,6 @@ async function downloadRequest(request, { fileName, signal, onProgress }) {
|
|
|
410
343
|
}
|
|
411
344
|
}
|
|
412
345
|
|
|
413
|
-
// src/has.ts
|
|
414
|
-
function has(obj, key2) {
|
|
415
|
-
return Object.prototype.hasOwnProperty.call(obj, key2);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
346
|
// src/parseFunc.ts
|
|
419
347
|
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)*)\}$/;
|
|
420
348
|
function parseFunc(func) {
|
|
@@ -499,29 +427,29 @@ function expose(name, value) {
|
|
|
499
427
|
}
|
|
500
428
|
|
|
501
429
|
// src/localStorage.ts
|
|
502
|
-
function getLocalKey(
|
|
503
|
-
return [af?.article?.id || "", "common",
|
|
430
|
+
function getLocalKey(key) {
|
|
431
|
+
return [af?.article?.id || "", "common", key].join(".");
|
|
504
432
|
}
|
|
505
433
|
var LocalStorage = class {
|
|
506
434
|
isPersisted() {
|
|
507
435
|
return true;
|
|
508
436
|
}
|
|
509
|
-
getLocalStorageKey(
|
|
510
|
-
return global ? ["common",
|
|
437
|
+
getLocalStorageKey(key, global) {
|
|
438
|
+
return global ? ["common", key].join(".") : getLocalKey(key);
|
|
511
439
|
}
|
|
512
|
-
get(
|
|
513
|
-
const lsKey = this.getLocalStorageKey(
|
|
440
|
+
get(key, defaultValue, global) {
|
|
441
|
+
const lsKey = this.getLocalStorageKey(key, global);
|
|
514
442
|
const value = localStorage.getItem(lsKey);
|
|
515
443
|
return value !== null ? JSON.parse(value) : defaultValue;
|
|
516
444
|
}
|
|
517
|
-
set(
|
|
445
|
+
set(key, value, global) {
|
|
518
446
|
localStorage.setItem(
|
|
519
|
-
this.getLocalStorageKey(
|
|
447
|
+
this.getLocalStorageKey(key, global),
|
|
520
448
|
JSON.stringify(value)
|
|
521
449
|
);
|
|
522
450
|
}
|
|
523
|
-
remove(
|
|
524
|
-
const lsKey = this.getLocalStorageKey(
|
|
451
|
+
remove(key, global) {
|
|
452
|
+
const lsKey = this.getLocalStorageKey(key, global);
|
|
525
453
|
if (localStorage.getItem(lsKey) !== null) {
|
|
526
454
|
localStorage.removeItem(lsKey);
|
|
527
455
|
return true;
|
|
@@ -531,9 +459,9 @@ var LocalStorage = class {
|
|
|
531
459
|
}
|
|
532
460
|
clear() {
|
|
533
461
|
const baseKey = getLocalKey("");
|
|
534
|
-
for (let
|
|
535
|
-
if (
|
|
536
|
-
localStorage.removeItem(
|
|
462
|
+
for (let key in localStorage) {
|
|
463
|
+
if (key.slice(0, baseKey.length) === baseKey) {
|
|
464
|
+
localStorage.removeItem(key);
|
|
537
465
|
}
|
|
538
466
|
}
|
|
539
467
|
}
|
|
@@ -548,8 +476,8 @@ function getKey(article) {
|
|
|
548
476
|
function getSettings(setting, article) {
|
|
549
477
|
if (!af?.userSession)
|
|
550
478
|
return null;
|
|
551
|
-
const
|
|
552
|
-
const settings = JSON.parse(localStorage.getItem(
|
|
479
|
+
const key = getKey(article);
|
|
480
|
+
const settings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
553
481
|
if (setting) {
|
|
554
482
|
return settings[setting] || null;
|
|
555
483
|
}
|
|
@@ -558,18 +486,18 @@ function getSettings(setting, article) {
|
|
|
558
486
|
function saveSettings(setting, value, article) {
|
|
559
487
|
if (!af?.userSession)
|
|
560
488
|
return;
|
|
561
|
-
const
|
|
562
|
-
let userSettings = JSON.parse(localStorage.getItem(
|
|
489
|
+
const key = getKey(article);
|
|
490
|
+
let userSettings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
563
491
|
if (typeof value !== "undefined") {
|
|
564
492
|
userSettings[setting] = value;
|
|
565
493
|
} else {
|
|
566
494
|
userSettings = setting;
|
|
567
495
|
}
|
|
568
|
-
localStorage.setItem(
|
|
496
|
+
localStorage.setItem(key, JSON.stringify(userSettings));
|
|
569
497
|
}
|
|
570
498
|
|
|
571
499
|
// src/index.ts
|
|
572
|
-
var version = "2.0.
|
|
500
|
+
var version = "2.0.4";
|
|
573
501
|
export {
|
|
574
502
|
SessionHandler,
|
|
575
503
|
UserSession,
|
|
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
3
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
4
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj,
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
6
|
var __spreadValues = (a, b) => {
|
|
7
7
|
for (var prop in b || (b = {}))
|
|
8
8
|
if (__hasOwnProp.call(b, prop))
|
|
@@ -14,8 +14,8 @@ var __spreadValues = (a, b) => {
|
|
|
14
14
|
}
|
|
15
15
|
return a;
|
|
16
16
|
};
|
|
17
|
-
var __publicField = (obj,
|
|
18
|
-
__defNormalProp(obj, typeof
|
|
17
|
+
var __publicField = (obj, key, value) => {
|
|
18
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
19
19
|
return value;
|
|
20
20
|
};
|
|
21
21
|
|
|
@@ -61,11 +61,16 @@ function mitt_default(n) {
|
|
|
61
61
|
} };
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
// src/has.ts
|
|
65
|
+
function has(obj, key) {
|
|
66
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
67
|
+
}
|
|
68
|
+
|
|
64
69
|
// src/getLocalizedString.ts
|
|
65
|
-
async function
|
|
70
|
+
async function fetchLocalizedString(text) {
|
|
66
71
|
try {
|
|
67
|
-
let response = await fetch(`/api/user/localize`, {
|
|
68
|
-
body: JSON.stringify({
|
|
72
|
+
let response = await fetch(`/api/user/localize/new/${af.article.id}`, {
|
|
73
|
+
body: JSON.stringify({ text }),
|
|
69
74
|
headers: {
|
|
70
75
|
Accept: "application/json; */*",
|
|
71
76
|
"Content-Type": "application/json",
|
|
@@ -78,14 +83,20 @@ async function getLocalizedStringAsync(string) {
|
|
|
78
83
|
}
|
|
79
84
|
} catch (error) {
|
|
80
85
|
}
|
|
81
|
-
return
|
|
86
|
+
return text;
|
|
82
87
|
}
|
|
83
|
-
function
|
|
88
|
+
function getLocalizedString(string, wait) {
|
|
84
89
|
var _a;
|
|
90
|
+
if (typeof string === "string" && string.trim().length === 0) {
|
|
91
|
+
return string;
|
|
92
|
+
}
|
|
93
|
+
if (string === void 0 || string === "" || string === null) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
85
96
|
if (((_a = af == null ? void 0 : af.article) == null ? void 0 : _a.i18n) !== void 0) {
|
|
86
|
-
if (!
|
|
97
|
+
if (!has(af.article.i18n, string)) {
|
|
87
98
|
af.article.i18n[string] = string;
|
|
88
|
-
let promise =
|
|
99
|
+
let promise = fetchLocalizedString(string).then((text) => {
|
|
89
100
|
af.article.i18n[string] = text;
|
|
90
101
|
return text;
|
|
91
102
|
});
|
|
@@ -98,84 +109,6 @@ function afGetLocalizedString(string, wait) {
|
|
|
98
109
|
return string;
|
|
99
110
|
}
|
|
100
111
|
}
|
|
101
|
-
var key = "__UNLOCALIZED_STRINGS__";
|
|
102
|
-
var localizeSet = window[key] || /* @__PURE__ */ new Set();
|
|
103
|
-
if (!window[key]) {
|
|
104
|
-
window[key] = localizeSet;
|
|
105
|
-
}
|
|
106
|
-
function handleReadyStateChange() {
|
|
107
|
-
if (document.readyState !== "loading") {
|
|
108
|
-
addDeveloperUtils();
|
|
109
|
-
document.removeEventListener("readystatechange", handleReadyStateChange);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (document.readyState !== "loading") {
|
|
113
|
-
addDeveloperUtils();
|
|
114
|
-
} else {
|
|
115
|
-
document.addEventListener("readystatechange", handleReadyStateChange);
|
|
116
|
-
}
|
|
117
|
-
function isDeveloper() {
|
|
118
|
-
const { af: af2 } = window;
|
|
119
|
-
return af2 && af2.userSession && af2.userSession.isDeveloper;
|
|
120
|
-
}
|
|
121
|
-
function addDeveloperUtils() {
|
|
122
|
-
if (isDeveloper()) {
|
|
123
|
-
if (typeof window.__doNothingWithStrings === "function") {
|
|
124
|
-
const addedStrings = window.__doNothingWithStrings();
|
|
125
|
-
for (let string of Object.keys(addedStrings)) {
|
|
126
|
-
localizeSet.add(string);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
if (!window[key]) {
|
|
130
|
-
window[key] = localizeSet;
|
|
131
|
-
}
|
|
132
|
-
if (!window.__getUnlocalizedStrings) {
|
|
133
|
-
window.__getUnlocalizedStrings = function(forCustomRoute) {
|
|
134
|
-
const strings = [];
|
|
135
|
-
for (let string of localizeSet) {
|
|
136
|
-
if (string) {
|
|
137
|
-
const escaped = string.replace(/'/g, "\\'");
|
|
138
|
-
if (forCustomRoute) {
|
|
139
|
-
const localized = afGetLocalizedString(string).replaceAll(/'/g, "\\'");
|
|
140
|
-
strings.push(`'${escaped}': '${localized}',`);
|
|
141
|
-
} else {
|
|
142
|
-
strings.push(
|
|
143
|
-
`s['${escaped}'] = @Html(@context.AddLocalizableString("${string.replaceAll('"', '\\"')}"));`
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (forCustomRoute) {
|
|
149
|
-
return `// Localization hack, since it AddLocalizableString doesn't work properly when custom routes is used
|
|
150
|
-
if (af.userSession.uiculture === 'nb-NO') {
|
|
151
|
-
const strings = {
|
|
152
|
-
${strings.join("\n ")}
|
|
153
|
-
};
|
|
154
|
-
af.article.i18n = af.article.i18n || {};
|
|
155
|
-
Object.assign(af.article.i18n, strings);
|
|
156
|
-
}`;
|
|
157
|
-
}
|
|
158
|
-
return `<script type="text/javascript">
|
|
159
|
-
function __doNothingWithStrings() {
|
|
160
|
-
@{
|
|
161
|
-
var context = @Appframe.Web.Context.RequestContext.Current;
|
|
162
|
-
}
|
|
163
|
-
let s = {};
|
|
164
|
-
${strings.join("\n")}
|
|
165
|
-
return s;
|
|
166
|
-
}
|
|
167
|
-
<\/script>`;
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
function getLocalizedString(string) {
|
|
173
|
-
const localized = afGetLocalizedString(string);
|
|
174
|
-
if (localized === string && !localizeSet.has(string)) {
|
|
175
|
-
localizeSet.add(string);
|
|
176
|
-
}
|
|
177
|
-
return localized;
|
|
178
|
-
}
|
|
179
112
|
|
|
180
113
|
// src/SessionHandler.ts
|
|
181
114
|
var _SessionHandler = class {
|
|
@@ -429,11 +362,6 @@ async function downloadRequest(request, { fileName, signal, onProgress }) {
|
|
|
429
362
|
}
|
|
430
363
|
}
|
|
431
364
|
|
|
432
|
-
// src/has.ts
|
|
433
|
-
function has(obj, key2) {
|
|
434
|
-
return Object.prototype.hasOwnProperty.call(obj, key2);
|
|
435
|
-
}
|
|
436
|
-
|
|
437
365
|
// src/parseFunc.ts
|
|
438
366
|
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)*)\}$/;
|
|
439
367
|
function parseFunc(func) {
|
|
@@ -518,30 +446,30 @@ function expose(name, value) {
|
|
|
518
446
|
}
|
|
519
447
|
|
|
520
448
|
// src/localStorage.ts
|
|
521
|
-
function getLocalKey(
|
|
449
|
+
function getLocalKey(key) {
|
|
522
450
|
var _a;
|
|
523
|
-
return [((_a = af == null ? void 0 : af.article) == null ? void 0 : _a.id) || "", "common",
|
|
451
|
+
return [((_a = af == null ? void 0 : af.article) == null ? void 0 : _a.id) || "", "common", key].join(".");
|
|
524
452
|
}
|
|
525
453
|
var LocalStorage = class {
|
|
526
454
|
isPersisted() {
|
|
527
455
|
return true;
|
|
528
456
|
}
|
|
529
|
-
getLocalStorageKey(
|
|
530
|
-
return global ? ["common",
|
|
457
|
+
getLocalStorageKey(key, global) {
|
|
458
|
+
return global ? ["common", key].join(".") : getLocalKey(key);
|
|
531
459
|
}
|
|
532
|
-
get(
|
|
533
|
-
const lsKey = this.getLocalStorageKey(
|
|
460
|
+
get(key, defaultValue, global) {
|
|
461
|
+
const lsKey = this.getLocalStorageKey(key, global);
|
|
534
462
|
const value = localStorage.getItem(lsKey);
|
|
535
463
|
return value !== null ? JSON.parse(value) : defaultValue;
|
|
536
464
|
}
|
|
537
|
-
set(
|
|
465
|
+
set(key, value, global) {
|
|
538
466
|
localStorage.setItem(
|
|
539
|
-
this.getLocalStorageKey(
|
|
467
|
+
this.getLocalStorageKey(key, global),
|
|
540
468
|
JSON.stringify(value)
|
|
541
469
|
);
|
|
542
470
|
}
|
|
543
|
-
remove(
|
|
544
|
-
const lsKey = this.getLocalStorageKey(
|
|
471
|
+
remove(key, global) {
|
|
472
|
+
const lsKey = this.getLocalStorageKey(key, global);
|
|
545
473
|
if (localStorage.getItem(lsKey) !== null) {
|
|
546
474
|
localStorage.removeItem(lsKey);
|
|
547
475
|
return true;
|
|
@@ -551,9 +479,9 @@ var LocalStorage = class {
|
|
|
551
479
|
}
|
|
552
480
|
clear() {
|
|
553
481
|
const baseKey = getLocalKey("");
|
|
554
|
-
for (let
|
|
555
|
-
if (
|
|
556
|
-
localStorage.removeItem(
|
|
482
|
+
for (let key in localStorage) {
|
|
483
|
+
if (key.slice(0, baseKey.length) === baseKey) {
|
|
484
|
+
localStorage.removeItem(key);
|
|
557
485
|
}
|
|
558
486
|
}
|
|
559
487
|
}
|
|
@@ -568,8 +496,8 @@ function getKey(article) {
|
|
|
568
496
|
function getSettings(setting, article) {
|
|
569
497
|
if (!(af == null ? void 0 : af.userSession))
|
|
570
498
|
return null;
|
|
571
|
-
const
|
|
572
|
-
const settings = JSON.parse(localStorage.getItem(
|
|
499
|
+
const key = getKey(article);
|
|
500
|
+
const settings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
573
501
|
if (setting) {
|
|
574
502
|
return settings[setting] || null;
|
|
575
503
|
}
|
|
@@ -578,18 +506,18 @@ function getSettings(setting, article) {
|
|
|
578
506
|
function saveSettings(setting, value, article) {
|
|
579
507
|
if (!(af == null ? void 0 : af.userSession))
|
|
580
508
|
return;
|
|
581
|
-
const
|
|
582
|
-
let userSettings = JSON.parse(localStorage.getItem(
|
|
509
|
+
const key = getKey(article);
|
|
510
|
+
let userSettings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
583
511
|
if (typeof value !== "undefined") {
|
|
584
512
|
userSettings[setting] = value;
|
|
585
513
|
} else {
|
|
586
514
|
userSettings = setting;
|
|
587
515
|
}
|
|
588
|
-
localStorage.setItem(
|
|
516
|
+
localStorage.setItem(key, JSON.stringify(userSettings));
|
|
589
517
|
}
|
|
590
518
|
|
|
591
519
|
// src/index.ts
|
|
592
|
-
var version = "2.0.
|
|
520
|
+
var version = "2.0.4";
|
|
593
521
|
export {
|
|
594
522
|
SessionHandler,
|
|
595
523
|
UserSession,
|
|
@@ -1,38 +1,20 @@
|
|
|
1
|
-
var
|
|
2
|
-
if (af.userSession.uiculture === 'nb-NO') {
|
|
3
|
-
const strings = {
|
|
4
|
-
${e.join(`
|
|
5
|
-
`)}
|
|
6
|
-
};
|
|
7
|
-
af.article.i18n = af.article.i18n || {};
|
|
8
|
-
Object.assign(af.article.i18n, strings);
|
|
9
|
-
}`:`<script type="text/javascript">
|
|
10
|
-
function __doNothingWithStrings() {
|
|
11
|
-
@{
|
|
12
|
-
var context = @Appframe.Web.Context.RequestContext.Current;
|
|
13
|
-
}
|
|
14
|
-
let s = {};
|
|
15
|
-
${e.join(`
|
|
16
|
-
`)}
|
|
17
|
-
return s;
|
|
18
|
-
}
|
|
19
|
-
<\/script>`})}}function h(t){let e=R(t);return e===t&&!y.has(t)&&y.add(t),e}var b=class{constructor(){i(this,"eventHandler",L());i(this,"showingDialog",!1);i(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=`
|
|
1
|
+
var z=Object.defineProperty;var N=Object.getOwnPropertySymbols;var I=Object.prototype.hasOwnProperty,P=Object.prototype.propertyIsEnumerable;var x=(t,e,n)=>e in t?z(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,k=(t,e)=>{for(var n in e||(e={}))I.call(e,n)&&x(t,n,e[n]);if(N)for(var n of N(e))P.call(e,n)&&x(t,n,e[n]);return t};var i=(t,e,n)=>(x(t,typeof e!="symbol"?e+"":e,n),n);window.addEventListener("error",t=>{var e,n,r,o,l,a,s;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:(l=t.colno)!=null?l:0,stack:(s=(a=t.error)==null?void 0:a.stack)!=null?s: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 E(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)})}}}function h(t,e){return Object.prototype.hasOwnProperty.call(t,e)}async function _(t){try{let e=await fetch(`/api/user/localize/new/${af.article.id}`,{body:JSON.stringify({text: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 y(t,e){var n;if(typeof t=="string"&&t.trim().length===0)return t;if(!(t===void 0||t===""||t===null))if(((n=af==null?void 0:af.article)==null?void 0:n.i18n)!==void 0){if(!h(af.article.i18n,t)){af.article.i18n[t]=t;let r=_(t).then(o=>(af.article.i18n[t]=o,o));if(e)return r}return af.article.i18n[t]}else return t}var w=class{constructor(){i(this,"eventHandler",E());i(this,"showingDialog",!1);i(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
2
|
<div class="session-expired-log-in" style="margin-top: 20px;">
|
|
21
3
|
<div class="row">
|
|
22
4
|
<div class="sessionExpired">
|
|
23
5
|
<h4 class="message">Frakoblet - tidsavbrudd</h4>
|
|
24
6
|
<div class="form-group">
|
|
25
|
-
<label for="username">${
|
|
7
|
+
<label for="username">${y("Username")}</label>
|
|
26
8
|
<input type="text" class="form-control" id="username" autofocus>
|
|
27
9
|
</div>
|
|
28
10
|
<div class="form-group">
|
|
29
|
-
<label for="password">${
|
|
11
|
+
<label for="password">${y("Password")}</label>
|
|
30
12
|
<input type="password" autocomplete="password" class="form-control" id="password" >
|
|
31
13
|
</div>
|
|
32
14
|
<div class="form-group">
|
|
33
15
|
<div>
|
|
34
16
|
<button type="submit" class="btn btn-default sign-in">
|
|
35
|
-
${
|
|
17
|
+
${y("Log in")}
|
|
36
18
|
</button>
|
|
37
19
|
</div>
|
|
38
20
|
</div>
|
|
@@ -44,5 +26,5 @@ return s;
|
|
|
44
26
|
</div>
|
|
45
27
|
</div>
|
|
46
28
|
</div>
|
|
47
|
-
`;let o=af.userSession.login?
|
|
29
|
+
`;let o=af.userSession.login?w.messages.relog:w.messages.login,l=r.querySelector(".message"),a=r.querySelector(".alert-warning"),s=r.querySelector("input[type=text]"),f=r.querySelector(".sign-in"),c=r.querySelector("input[type=password]");if(l!==null&&s!==null&&a!==null&&s!==null&&f!==null&&c!==null){l.innerText=y(o),s.value=af.userSession.login||"",s.disabled=!!af.userSession.login,s.readOnly=!!af.userSession.login,document.body.appendChild(r);let p=async()=>{c.disabled=!0;let u=new Request("/login",{body:JSON.stringify({username:s.value,password:c.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(u)).json();if(d.success)document.body.removeChild(r),this.showingDialog=!1,this.eventHandler.emit("onAuthenticated"),a.parentNode&&(a.parentNode.style.display="none");else throw new Error(d.error)}catch(g){if(g&&typeof g=="object"){let d=g;c.disabled=!1,c.classList.toggle("invalid",!0),c.value="",c.focus(),a.innerText=d.message?d.message:String(d),a.parentNode&&(a.parentNode.style.display="initial")}}};f.addEventListener("click",p),c.addEventListener("keyup",u=>{u.key==="Enter"&&p()}),c.addEventListener("change",u=>{u.key==="Enter"&&p()}),s.addEventListener("keyup",u=>{u.key==="Enter"&&p()}),s.addEventListener("change",u=>{u.key==="Enter"&&p()}),c.focus()}}}attachEvent(e,n){return this.eventHandler.on(e,n)}detachEvent(e,n){return this.eventHandler.off(e,n)}},m=w;i(m,"messages",{login:"Log in",relog:"Session expired - log in"});var b=class extends m{constructor(n){super();i(this,"amDesignator","a.m.");i(this,"dayNames",["sunday","monday","tuesday","wednesday","thursday","friday","saturday"]);i(this,"dayNamesShort",["sun","mon","tue","wed","thu","fri","sat"]);i(this,"decimalSeparator",".");i(this,"domain","OB");i(this,"email");i(this,"formats");i(this,"groupSeparator",null);i(this,"integratedSecurity",!1);i(this,"isDeveloper",!1);i(this,"login","");i(this,"loginType");i(this,"monthNames",["january","february","march","april","may","june","july","august","september","october","november","december",""]);i(this,"monthNamesShort",["jan","feb","mar","apr","may","jun","jul","augt","sep","oct","nov","dec",""]);i(this,"name");i(this,"pmDesignator","p.m.");i(this,"shortDateFormat","dd.MM.yyyy");i(this,"culture","en-GB");i(this,"uiculture","en-GB");i(this,"expired",()=>null);this.formats={},Object.assign(this,n)}};function L(t,e){return new Promise(function(n,r){try{let o=URL.createObjectURL(t),l=document.body,a=document.createElement("a");a.setAttribute("download",e),a.href=o,l.append(a),a.click(),l.removeChild(a),setTimeout(function(){URL.revokeObjectURL(o),n()},250)}catch(o){r(o)}})}async function ne(t,{fileName:e,signal:n,onProgress:r}){var a;function o(s){typeof r=="function"&&r(k({},s))}let l=0;o({status:"requested"});try{let s=await fetch(t);if(!s.ok||!s.body){if((a=s.headers.get("content-type"))!=null&&a.includes("application/json")){let c=await s.json();if(c.error)throw new Error(c.error)}throw new Error(`${s.status} ${s.statusText}`)}try{let c=s.body.getReader(),p=new ReadableStream({start:function(u){function g(){return c.read().then(function(d){if(d.done){u.close();return}return l+=d.value.length,o({bytesReceived:l,status:"downloading"}),u.enqueue(d.value),g()})}return g()}});s=new Response(p)}catch(c){console.warn("Failed to replace response stream to log download progress.")}let f=await s.blob();o({bytesReceived:l,status:"downloaded"}),await L(f,e),o({bytesReceived:l,status:"completed"})}catch(s){n!=null&&n.aborted?o({status:"cancelled"}):o({error:s.message,status:"error"})}}var D=/^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 v(t){var e=t.toString().match(D);if(e===null)throw new TypeError("Unable to parse function!");return{name:e[1],args:e[2].split(","),body:e[3]}}function R(){}R.prototype=Object.create(null);var H=R;function S(t,e){if(typeof t=="object")if(typeof e=="string"){let n=e.split(".");return S(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 H;return n}else throw new TypeError("Invalid type of parameter 'namespace'");else throw new TypeError("Invalid type of parameter 'root'")}function A(t,e){console.warn(t)}function j(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}=v(n);if(r)j(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=v(e).name),typeof t=="string"){let o=t.split(".");n||(n=o[o.length-1],o=o.slice(0,o.length-1)),r=S(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!");h(r,n)?A([t,n].join(".")+" is already defined!"):r[n]=e}}function O(t){var e;return[((e=af==null?void 0:af.article)==null?void 0:e.id)||"","common",t].join(".")}var T=class{isPersisted(){return!0}getLocalStorageKey(e,n){return n?["common",e].join("."):O(e)}get(e,n,r){let o=this.getLocalStorageKey(e,r),l=localStorage.getItem(o);return l!==null?JSON.parse(l):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=O("");for(let n in localStorage)n.slice(0,e.length)===e&&localStorage.removeItem(n)}},M=new T;function q(t){return`${t||af.article.id}.${af.userSession.login}`}function ye(t,e){if(!(af!=null&&af.userSession))return null;let n=q(e),r=JSON.parse(localStorage.getItem(n)||"{}");return t?r[t]||null:r}function he(t,e,n){if(!(af!=null&&af.userSession))return;let r=q(n),o=JSON.parse(localStorage.getItem(r)||"{}");typeof e<"u"?o[t]=e:o=t,localStorage.setItem(r,JSON.stringify(o))}var Se="2.0.4";export{m as SessionHandler,b as UserSession,L as downloadBlob,ne as downloadRequest,j as expose,y as getLocalizedString,ye as getSettings,h as has,M as localStorage,E as mitt,he as saveSettings,Se as version};
|
|
48
30
|
//# sourceMappingURL=af.common.legacy.min.js.map
|