@olenbetong/appframe-core 2.0.3 → 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 +27 -105
- package/dist/esm/af.common.legacy.js +27 -105
- package/dist/esm/af.common.legacy.min.js +5 -23
- package/dist/esm/af.common.legacy.min.js.map +3 -3
- package/dist/esm/af.common.min.js +5 -23
- package/dist/esm/af.common.min.js.map +3 -3
- package/dist/iife/af.common.js +30 -108
- package/dist/iife/af.common.legacy.js +30 -108
- package/dist/iife/af.common.legacy.min.js +2 -20
- package/dist/iife/af.common.legacy.min.js.map +3 -3
- package/dist/iife/af.common.min.js +5 -23
- package/dist/iife/af.common.min.js.map +3 -3
- package/es/getLocalizedString.d.ts +6 -7
- package/es/getLocalizedString.js +9 -82
- package/es/index.js +1 -1
- package/package.json +2 -2
- package/src/getLocalizedString.ts +22 -110
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
|
|
|
@@ -47,12 +47,12 @@ function mitt_default(n) {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
// src/has.ts
|
|
50
|
-
function has(obj,
|
|
51
|
-
return Object.prototype.hasOwnProperty.call(obj,
|
|
50
|
+
function has(obj, key) {
|
|
51
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
// src/getLocalizedString.ts
|
|
55
|
-
async function
|
|
55
|
+
async function fetchLocalizedString(text) {
|
|
56
56
|
try {
|
|
57
57
|
let response = await fetch(`/api/user/localize/new/${af.article.id}`, {
|
|
58
58
|
body: JSON.stringify({ text }),
|
|
@@ -70,7 +70,7 @@ async function getLocalizedStringAsync(text) {
|
|
|
70
70
|
}
|
|
71
71
|
return text;
|
|
72
72
|
}
|
|
73
|
-
function
|
|
73
|
+
function getLocalizedString(string, wait) {
|
|
74
74
|
if (typeof string === "string" && string.trim().length === 0) {
|
|
75
75
|
return string;
|
|
76
76
|
}
|
|
@@ -80,7 +80,7 @@ function afGetLocalizedString(string, wait) {
|
|
|
80
80
|
if (af?.article?.i18n !== void 0) {
|
|
81
81
|
if (!has(af.article.i18n, string)) {
|
|
82
82
|
af.article.i18n[string] = string;
|
|
83
|
-
let promise =
|
|
83
|
+
let promise = fetchLocalizedString(string).then((text) => {
|
|
84
84
|
af.article.i18n[string] = text;
|
|
85
85
|
return text;
|
|
86
86
|
});
|
|
@@ -93,84 +93,6 @@ function afGetLocalizedString(string, wait) {
|
|
|
93
93
|
return string;
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
-
var key = "__UNLOCALIZED_STRINGS__";
|
|
97
|
-
var localizeSet = window[key] || /* @__PURE__ */ new Set();
|
|
98
|
-
if (!window[key]) {
|
|
99
|
-
window[key] = localizeSet;
|
|
100
|
-
}
|
|
101
|
-
function handleReadyStateChange() {
|
|
102
|
-
if (document.readyState !== "loading") {
|
|
103
|
-
addDeveloperUtils();
|
|
104
|
-
document.removeEventListener("readystatechange", handleReadyStateChange);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (document.readyState !== "loading") {
|
|
108
|
-
addDeveloperUtils();
|
|
109
|
-
} else {
|
|
110
|
-
document.addEventListener("readystatechange", handleReadyStateChange);
|
|
111
|
-
}
|
|
112
|
-
function isDeveloper() {
|
|
113
|
-
const { af: af2 } = window;
|
|
114
|
-
return af2 && af2.userSession && af2.userSession.isDeveloper;
|
|
115
|
-
}
|
|
116
|
-
function addDeveloperUtils() {
|
|
117
|
-
if (isDeveloper()) {
|
|
118
|
-
if (typeof window.__doNothingWithStrings === "function") {
|
|
119
|
-
const addedStrings = window.__doNothingWithStrings();
|
|
120
|
-
for (let string of Object.keys(addedStrings)) {
|
|
121
|
-
localizeSet.add(string);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
if (!window[key]) {
|
|
125
|
-
window[key] = localizeSet;
|
|
126
|
-
}
|
|
127
|
-
if (!window.__getUnlocalizedStrings) {
|
|
128
|
-
window.__getUnlocalizedStrings = function(forCustomRoute) {
|
|
129
|
-
const strings = [];
|
|
130
|
-
for (let string of localizeSet) {
|
|
131
|
-
if (string) {
|
|
132
|
-
const escaped = string.replace(/'/g, "\\'");
|
|
133
|
-
if (forCustomRoute) {
|
|
134
|
-
const localized = afGetLocalizedString(string).replaceAll(/'/g, "\\'");
|
|
135
|
-
strings.push(`'${escaped}': '${localized}',`);
|
|
136
|
-
} else {
|
|
137
|
-
strings.push(
|
|
138
|
-
`s['${escaped}'] = @Html(@context.AddLocalizableString("${string.replaceAll('"', '\\"')}"));`
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (forCustomRoute) {
|
|
144
|
-
return `// Localization hack, since it AddLocalizableString doesn't work properly when custom routes is used
|
|
145
|
-
if (af.userSession.uiculture === 'nb-NO') {
|
|
146
|
-
const strings = {
|
|
147
|
-
${strings.join("\n ")}
|
|
148
|
-
};
|
|
149
|
-
af.article.i18n = af.article.i18n || {};
|
|
150
|
-
Object.assign(af.article.i18n, strings);
|
|
151
|
-
}`;
|
|
152
|
-
}
|
|
153
|
-
return `<script type="text/javascript">
|
|
154
|
-
function __doNothingWithStrings() {
|
|
155
|
-
@{
|
|
156
|
-
var context = @Appframe.Web.Context.RequestContext.Current;
|
|
157
|
-
}
|
|
158
|
-
let s = {};
|
|
159
|
-
${strings.join("\n")}
|
|
160
|
-
return s;
|
|
161
|
-
}
|
|
162
|
-
<\/script>`;
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
function getLocalizedString(string) {
|
|
168
|
-
const localized = afGetLocalizedString(string);
|
|
169
|
-
if (localized === string && !localizeSet.has(string)) {
|
|
170
|
-
localizeSet.add(string);
|
|
171
|
-
}
|
|
172
|
-
return localized;
|
|
173
|
-
}
|
|
174
96
|
|
|
175
97
|
// src/SessionHandler.ts
|
|
176
98
|
var _SessionHandler = class {
|
|
@@ -505,29 +427,29 @@ function expose(name, value) {
|
|
|
505
427
|
}
|
|
506
428
|
|
|
507
429
|
// src/localStorage.ts
|
|
508
|
-
function getLocalKey(
|
|
509
|
-
return [af?.article?.id || "", "common",
|
|
430
|
+
function getLocalKey(key) {
|
|
431
|
+
return [af?.article?.id || "", "common", key].join(".");
|
|
510
432
|
}
|
|
511
433
|
var LocalStorage = class {
|
|
512
434
|
isPersisted() {
|
|
513
435
|
return true;
|
|
514
436
|
}
|
|
515
|
-
getLocalStorageKey(
|
|
516
|
-
return global ? ["common",
|
|
437
|
+
getLocalStorageKey(key, global) {
|
|
438
|
+
return global ? ["common", key].join(".") : getLocalKey(key);
|
|
517
439
|
}
|
|
518
|
-
get(
|
|
519
|
-
const lsKey = this.getLocalStorageKey(
|
|
440
|
+
get(key, defaultValue, global) {
|
|
441
|
+
const lsKey = this.getLocalStorageKey(key, global);
|
|
520
442
|
const value = localStorage.getItem(lsKey);
|
|
521
443
|
return value !== null ? JSON.parse(value) : defaultValue;
|
|
522
444
|
}
|
|
523
|
-
set(
|
|
445
|
+
set(key, value, global) {
|
|
524
446
|
localStorage.setItem(
|
|
525
|
-
this.getLocalStorageKey(
|
|
447
|
+
this.getLocalStorageKey(key, global),
|
|
526
448
|
JSON.stringify(value)
|
|
527
449
|
);
|
|
528
450
|
}
|
|
529
|
-
remove(
|
|
530
|
-
const lsKey = this.getLocalStorageKey(
|
|
451
|
+
remove(key, global) {
|
|
452
|
+
const lsKey = this.getLocalStorageKey(key, global);
|
|
531
453
|
if (localStorage.getItem(lsKey) !== null) {
|
|
532
454
|
localStorage.removeItem(lsKey);
|
|
533
455
|
return true;
|
|
@@ -537,9 +459,9 @@ var LocalStorage = class {
|
|
|
537
459
|
}
|
|
538
460
|
clear() {
|
|
539
461
|
const baseKey = getLocalKey("");
|
|
540
|
-
for (let
|
|
541
|
-
if (
|
|
542
|
-
localStorage.removeItem(
|
|
462
|
+
for (let key in localStorage) {
|
|
463
|
+
if (key.slice(0, baseKey.length) === baseKey) {
|
|
464
|
+
localStorage.removeItem(key);
|
|
543
465
|
}
|
|
544
466
|
}
|
|
545
467
|
}
|
|
@@ -554,8 +476,8 @@ function getKey(article) {
|
|
|
554
476
|
function getSettings(setting, article) {
|
|
555
477
|
if (!af?.userSession)
|
|
556
478
|
return null;
|
|
557
|
-
const
|
|
558
|
-
const settings = JSON.parse(localStorage.getItem(
|
|
479
|
+
const key = getKey(article);
|
|
480
|
+
const settings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
559
481
|
if (setting) {
|
|
560
482
|
return settings[setting] || null;
|
|
561
483
|
}
|
|
@@ -564,18 +486,18 @@ function getSettings(setting, article) {
|
|
|
564
486
|
function saveSettings(setting, value, article) {
|
|
565
487
|
if (!af?.userSession)
|
|
566
488
|
return;
|
|
567
|
-
const
|
|
568
|
-
let userSettings = JSON.parse(localStorage.getItem(
|
|
489
|
+
const key = getKey(article);
|
|
490
|
+
let userSettings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
569
491
|
if (typeof value !== "undefined") {
|
|
570
492
|
userSettings[setting] = value;
|
|
571
493
|
} else {
|
|
572
494
|
userSettings = setting;
|
|
573
495
|
}
|
|
574
|
-
localStorage.setItem(
|
|
496
|
+
localStorage.setItem(key, JSON.stringify(userSettings));
|
|
575
497
|
}
|
|
576
498
|
|
|
577
499
|
// src/index.ts
|
|
578
|
-
var version = "2.0.
|
|
500
|
+
var version = "2.0.4";
|
|
579
501
|
export {
|
|
580
502
|
SessionHandler,
|
|
581
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
|
|
|
@@ -62,12 +62,12 @@ function mitt_default(n) {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
// src/has.ts
|
|
65
|
-
function has(obj,
|
|
66
|
-
return Object.prototype.hasOwnProperty.call(obj,
|
|
65
|
+
function has(obj, key) {
|
|
66
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
// src/getLocalizedString.ts
|
|
70
|
-
async function
|
|
70
|
+
async function fetchLocalizedString(text) {
|
|
71
71
|
try {
|
|
72
72
|
let response = await fetch(`/api/user/localize/new/${af.article.id}`, {
|
|
73
73
|
body: JSON.stringify({ text }),
|
|
@@ -85,7 +85,7 @@ async function getLocalizedStringAsync(text) {
|
|
|
85
85
|
}
|
|
86
86
|
return text;
|
|
87
87
|
}
|
|
88
|
-
function
|
|
88
|
+
function getLocalizedString(string, wait) {
|
|
89
89
|
var _a;
|
|
90
90
|
if (typeof string === "string" && string.trim().length === 0) {
|
|
91
91
|
return string;
|
|
@@ -96,7 +96,7 @@ function afGetLocalizedString(string, wait) {
|
|
|
96
96
|
if (((_a = af == null ? void 0 : af.article) == null ? void 0 : _a.i18n) !== void 0) {
|
|
97
97
|
if (!has(af.article.i18n, string)) {
|
|
98
98
|
af.article.i18n[string] = string;
|
|
99
|
-
let promise =
|
|
99
|
+
let promise = fetchLocalizedString(string).then((text) => {
|
|
100
100
|
af.article.i18n[string] = text;
|
|
101
101
|
return text;
|
|
102
102
|
});
|
|
@@ -109,84 +109,6 @@ function afGetLocalizedString(string, wait) {
|
|
|
109
109
|
return string;
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
var key = "__UNLOCALIZED_STRINGS__";
|
|
113
|
-
var localizeSet = window[key] || /* @__PURE__ */ new Set();
|
|
114
|
-
if (!window[key]) {
|
|
115
|
-
window[key] = localizeSet;
|
|
116
|
-
}
|
|
117
|
-
function handleReadyStateChange() {
|
|
118
|
-
if (document.readyState !== "loading") {
|
|
119
|
-
addDeveloperUtils();
|
|
120
|
-
document.removeEventListener("readystatechange", handleReadyStateChange);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if (document.readyState !== "loading") {
|
|
124
|
-
addDeveloperUtils();
|
|
125
|
-
} else {
|
|
126
|
-
document.addEventListener("readystatechange", handleReadyStateChange);
|
|
127
|
-
}
|
|
128
|
-
function isDeveloper() {
|
|
129
|
-
const { af: af2 } = window;
|
|
130
|
-
return af2 && af2.userSession && af2.userSession.isDeveloper;
|
|
131
|
-
}
|
|
132
|
-
function addDeveloperUtils() {
|
|
133
|
-
if (isDeveloper()) {
|
|
134
|
-
if (typeof window.__doNothingWithStrings === "function") {
|
|
135
|
-
const addedStrings = window.__doNothingWithStrings();
|
|
136
|
-
for (let string of Object.keys(addedStrings)) {
|
|
137
|
-
localizeSet.add(string);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
if (!window[key]) {
|
|
141
|
-
window[key] = localizeSet;
|
|
142
|
-
}
|
|
143
|
-
if (!window.__getUnlocalizedStrings) {
|
|
144
|
-
window.__getUnlocalizedStrings = function(forCustomRoute) {
|
|
145
|
-
const strings = [];
|
|
146
|
-
for (let string of localizeSet) {
|
|
147
|
-
if (string) {
|
|
148
|
-
const escaped = string.replace(/'/g, "\\'");
|
|
149
|
-
if (forCustomRoute) {
|
|
150
|
-
const localized = afGetLocalizedString(string).replaceAll(/'/g, "\\'");
|
|
151
|
-
strings.push(`'${escaped}': '${localized}',`);
|
|
152
|
-
} else {
|
|
153
|
-
strings.push(
|
|
154
|
-
`s['${escaped}'] = @Html(@context.AddLocalizableString("${string.replaceAll('"', '\\"')}"));`
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (forCustomRoute) {
|
|
160
|
-
return `// Localization hack, since it AddLocalizableString doesn't work properly when custom routes is used
|
|
161
|
-
if (af.userSession.uiculture === 'nb-NO') {
|
|
162
|
-
const strings = {
|
|
163
|
-
${strings.join("\n ")}
|
|
164
|
-
};
|
|
165
|
-
af.article.i18n = af.article.i18n || {};
|
|
166
|
-
Object.assign(af.article.i18n, strings);
|
|
167
|
-
}`;
|
|
168
|
-
}
|
|
169
|
-
return `<script type="text/javascript">
|
|
170
|
-
function __doNothingWithStrings() {
|
|
171
|
-
@{
|
|
172
|
-
var context = @Appframe.Web.Context.RequestContext.Current;
|
|
173
|
-
}
|
|
174
|
-
let s = {};
|
|
175
|
-
${strings.join("\n")}
|
|
176
|
-
return s;
|
|
177
|
-
}
|
|
178
|
-
<\/script>`;
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
function getLocalizedString(string) {
|
|
184
|
-
const localized = afGetLocalizedString(string);
|
|
185
|
-
if (localized === string && !localizeSet.has(string)) {
|
|
186
|
-
localizeSet.add(string);
|
|
187
|
-
}
|
|
188
|
-
return localized;
|
|
189
|
-
}
|
|
190
112
|
|
|
191
113
|
// src/SessionHandler.ts
|
|
192
114
|
var _SessionHandler = class {
|
|
@@ -524,30 +446,30 @@ function expose(name, value) {
|
|
|
524
446
|
}
|
|
525
447
|
|
|
526
448
|
// src/localStorage.ts
|
|
527
|
-
function getLocalKey(
|
|
449
|
+
function getLocalKey(key) {
|
|
528
450
|
var _a;
|
|
529
|
-
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(".");
|
|
530
452
|
}
|
|
531
453
|
var LocalStorage = class {
|
|
532
454
|
isPersisted() {
|
|
533
455
|
return true;
|
|
534
456
|
}
|
|
535
|
-
getLocalStorageKey(
|
|
536
|
-
return global ? ["common",
|
|
457
|
+
getLocalStorageKey(key, global) {
|
|
458
|
+
return global ? ["common", key].join(".") : getLocalKey(key);
|
|
537
459
|
}
|
|
538
|
-
get(
|
|
539
|
-
const lsKey = this.getLocalStorageKey(
|
|
460
|
+
get(key, defaultValue, global) {
|
|
461
|
+
const lsKey = this.getLocalStorageKey(key, global);
|
|
540
462
|
const value = localStorage.getItem(lsKey);
|
|
541
463
|
return value !== null ? JSON.parse(value) : defaultValue;
|
|
542
464
|
}
|
|
543
|
-
set(
|
|
465
|
+
set(key, value, global) {
|
|
544
466
|
localStorage.setItem(
|
|
545
|
-
this.getLocalStorageKey(
|
|
467
|
+
this.getLocalStorageKey(key, global),
|
|
546
468
|
JSON.stringify(value)
|
|
547
469
|
);
|
|
548
470
|
}
|
|
549
|
-
remove(
|
|
550
|
-
const lsKey = this.getLocalStorageKey(
|
|
471
|
+
remove(key, global) {
|
|
472
|
+
const lsKey = this.getLocalStorageKey(key, global);
|
|
551
473
|
if (localStorage.getItem(lsKey) !== null) {
|
|
552
474
|
localStorage.removeItem(lsKey);
|
|
553
475
|
return true;
|
|
@@ -557,9 +479,9 @@ var LocalStorage = class {
|
|
|
557
479
|
}
|
|
558
480
|
clear() {
|
|
559
481
|
const baseKey = getLocalKey("");
|
|
560
|
-
for (let
|
|
561
|
-
if (
|
|
562
|
-
localStorage.removeItem(
|
|
482
|
+
for (let key in localStorage) {
|
|
483
|
+
if (key.slice(0, baseKey.length) === baseKey) {
|
|
484
|
+
localStorage.removeItem(key);
|
|
563
485
|
}
|
|
564
486
|
}
|
|
565
487
|
}
|
|
@@ -574,8 +496,8 @@ function getKey(article) {
|
|
|
574
496
|
function getSettings(setting, article) {
|
|
575
497
|
if (!(af == null ? void 0 : af.userSession))
|
|
576
498
|
return null;
|
|
577
|
-
const
|
|
578
|
-
const settings = JSON.parse(localStorage.getItem(
|
|
499
|
+
const key = getKey(article);
|
|
500
|
+
const settings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
579
501
|
if (setting) {
|
|
580
502
|
return settings[setting] || null;
|
|
581
503
|
}
|
|
@@ -584,18 +506,18 @@ function getSettings(setting, article) {
|
|
|
584
506
|
function saveSettings(setting, value, article) {
|
|
585
507
|
if (!(af == null ? void 0 : af.userSession))
|
|
586
508
|
return;
|
|
587
|
-
const
|
|
588
|
-
let userSettings = JSON.parse(localStorage.getItem(
|
|
509
|
+
const key = getKey(article);
|
|
510
|
+
let userSettings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
589
511
|
if (typeof value !== "undefined") {
|
|
590
512
|
userSettings[setting] = value;
|
|
591
513
|
} else {
|
|
592
514
|
userSettings = setting;
|
|
593
515
|
}
|
|
594
|
-
localStorage.setItem(
|
|
516
|
+
localStorage.setItem(key, JSON.stringify(userSettings));
|
|
595
517
|
}
|
|
596
518
|
|
|
597
519
|
// src/index.ts
|
|
598
|
-
var version = "2.0.
|
|
520
|
+
var version = "2.0.4";
|
|
599
521
|
export {
|
|
600
522
|
SessionHandler,
|
|
601
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=O(t);return e===t&&!y.has(t)&&y.add(t),e}var b=class{constructor(){i(this,"eventHandler",_());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
|