@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/iife/af.common.js
CHANGED
|
@@ -4,22 +4,22 @@ var af;
|
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __defNormalProp = (obj,
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
8
|
var __export = (target, all) => {
|
|
9
9
|
for (var name in all)
|
|
10
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
11
|
};
|
|
12
12
|
var __copyProps = (to, from, except, desc) => {
|
|
13
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let
|
|
15
|
-
if (!__hasOwnProp.call(to,
|
|
16
|
-
__defProp(to,
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
20
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
-
var __publicField = (obj,
|
|
22
|
-
__defNormalProp(obj, typeof
|
|
21
|
+
var __publicField = (obj, key, value) => {
|
|
22
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
23
23
|
return value;
|
|
24
24
|
};
|
|
25
25
|
|
|
@@ -82,12 +82,12 @@ var af;
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
// src/has.ts
|
|
85
|
-
function has(obj,
|
|
86
|
-
return Object.prototype.hasOwnProperty.call(obj,
|
|
85
|
+
function has(obj, key) {
|
|
86
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
// src/getLocalizedString.ts
|
|
90
|
-
async function
|
|
90
|
+
async function fetchLocalizedString(text) {
|
|
91
91
|
try {
|
|
92
92
|
let response = await fetch(`/api/user/localize/new/${af.article.id}`, {
|
|
93
93
|
body: JSON.stringify({ text }),
|
|
@@ -105,7 +105,7 @@ var af;
|
|
|
105
105
|
}
|
|
106
106
|
return text;
|
|
107
107
|
}
|
|
108
|
-
function
|
|
108
|
+
function getLocalizedString(string, wait) {
|
|
109
109
|
if (typeof string === "string" && string.trim().length === 0) {
|
|
110
110
|
return string;
|
|
111
111
|
}
|
|
@@ -115,7 +115,7 @@ var af;
|
|
|
115
115
|
if (af?.article?.i18n !== void 0) {
|
|
116
116
|
if (!has(af.article.i18n, string)) {
|
|
117
117
|
af.article.i18n[string] = string;
|
|
118
|
-
let promise =
|
|
118
|
+
let promise = fetchLocalizedString(string).then((text) => {
|
|
119
119
|
af.article.i18n[string] = text;
|
|
120
120
|
return text;
|
|
121
121
|
});
|
|
@@ -128,84 +128,6 @@ var af;
|
|
|
128
128
|
return string;
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
-
var key = "__UNLOCALIZED_STRINGS__";
|
|
132
|
-
var localizeSet = window[key] || /* @__PURE__ */ new Set();
|
|
133
|
-
if (!window[key]) {
|
|
134
|
-
window[key] = localizeSet;
|
|
135
|
-
}
|
|
136
|
-
function handleReadyStateChange() {
|
|
137
|
-
if (document.readyState !== "loading") {
|
|
138
|
-
addDeveloperUtils();
|
|
139
|
-
document.removeEventListener("readystatechange", handleReadyStateChange);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if (document.readyState !== "loading") {
|
|
143
|
-
addDeveloperUtils();
|
|
144
|
-
} else {
|
|
145
|
-
document.addEventListener("readystatechange", handleReadyStateChange);
|
|
146
|
-
}
|
|
147
|
-
function isDeveloper() {
|
|
148
|
-
const { af: af2 } = window;
|
|
149
|
-
return af2 && af2.userSession && af2.userSession.isDeveloper;
|
|
150
|
-
}
|
|
151
|
-
function addDeveloperUtils() {
|
|
152
|
-
if (isDeveloper()) {
|
|
153
|
-
if (typeof window.__doNothingWithStrings === "function") {
|
|
154
|
-
const addedStrings = window.__doNothingWithStrings();
|
|
155
|
-
for (let string of Object.keys(addedStrings)) {
|
|
156
|
-
localizeSet.add(string);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (!window[key]) {
|
|
160
|
-
window[key] = localizeSet;
|
|
161
|
-
}
|
|
162
|
-
if (!window.__getUnlocalizedStrings) {
|
|
163
|
-
window.__getUnlocalizedStrings = function(forCustomRoute) {
|
|
164
|
-
const strings = [];
|
|
165
|
-
for (let string of localizeSet) {
|
|
166
|
-
if (string) {
|
|
167
|
-
const escaped = string.replace(/'/g, "\\'");
|
|
168
|
-
if (forCustomRoute) {
|
|
169
|
-
const localized = afGetLocalizedString(string).replaceAll(/'/g, "\\'");
|
|
170
|
-
strings.push(`'${escaped}': '${localized}',`);
|
|
171
|
-
} else {
|
|
172
|
-
strings.push(
|
|
173
|
-
`s['${escaped}'] = @Html(@context.AddLocalizableString("${string.replaceAll('"', '\\"')}"));`
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
if (forCustomRoute) {
|
|
179
|
-
return `// Localization hack, since it AddLocalizableString doesn't work properly when custom routes is used
|
|
180
|
-
if (af.userSession.uiculture === 'nb-NO') {
|
|
181
|
-
const strings = {
|
|
182
|
-
${strings.join("\n ")}
|
|
183
|
-
};
|
|
184
|
-
af.article.i18n = af.article.i18n || {};
|
|
185
|
-
Object.assign(af.article.i18n, strings);
|
|
186
|
-
}`;
|
|
187
|
-
}
|
|
188
|
-
return `<script type="text/javascript">
|
|
189
|
-
function __doNothingWithStrings() {
|
|
190
|
-
@{
|
|
191
|
-
var context = @Appframe.Web.Context.RequestContext.Current;
|
|
192
|
-
}
|
|
193
|
-
let s = {};
|
|
194
|
-
${strings.join("\n")}
|
|
195
|
-
return s;
|
|
196
|
-
}
|
|
197
|
-
<\/script>`;
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
function getLocalizedString(string) {
|
|
203
|
-
const localized = afGetLocalizedString(string);
|
|
204
|
-
if (localized === string && !localizeSet.has(string)) {
|
|
205
|
-
localizeSet.add(string);
|
|
206
|
-
}
|
|
207
|
-
return localized;
|
|
208
|
-
}
|
|
209
131
|
|
|
210
132
|
// src/SessionHandler.ts
|
|
211
133
|
var _SessionHandler = class {
|
|
@@ -540,29 +462,29 @@ return s;
|
|
|
540
462
|
}
|
|
541
463
|
|
|
542
464
|
// src/localStorage.ts
|
|
543
|
-
function getLocalKey(
|
|
544
|
-
return [af?.article?.id || "", "common",
|
|
465
|
+
function getLocalKey(key) {
|
|
466
|
+
return [af?.article?.id || "", "common", key].join(".");
|
|
545
467
|
}
|
|
546
468
|
var LocalStorage = class {
|
|
547
469
|
isPersisted() {
|
|
548
470
|
return true;
|
|
549
471
|
}
|
|
550
|
-
getLocalStorageKey(
|
|
551
|
-
return global ? ["common",
|
|
472
|
+
getLocalStorageKey(key, global) {
|
|
473
|
+
return global ? ["common", key].join(".") : getLocalKey(key);
|
|
552
474
|
}
|
|
553
|
-
get(
|
|
554
|
-
const lsKey = this.getLocalStorageKey(
|
|
475
|
+
get(key, defaultValue, global) {
|
|
476
|
+
const lsKey = this.getLocalStorageKey(key, global);
|
|
555
477
|
const value = localStorage.getItem(lsKey);
|
|
556
478
|
return value !== null ? JSON.parse(value) : defaultValue;
|
|
557
479
|
}
|
|
558
|
-
set(
|
|
480
|
+
set(key, value, global) {
|
|
559
481
|
localStorage.setItem(
|
|
560
|
-
this.getLocalStorageKey(
|
|
482
|
+
this.getLocalStorageKey(key, global),
|
|
561
483
|
JSON.stringify(value)
|
|
562
484
|
);
|
|
563
485
|
}
|
|
564
|
-
remove(
|
|
565
|
-
const lsKey = this.getLocalStorageKey(
|
|
486
|
+
remove(key, global) {
|
|
487
|
+
const lsKey = this.getLocalStorageKey(key, global);
|
|
566
488
|
if (localStorage.getItem(lsKey) !== null) {
|
|
567
489
|
localStorage.removeItem(lsKey);
|
|
568
490
|
return true;
|
|
@@ -572,9 +494,9 @@ return s;
|
|
|
572
494
|
}
|
|
573
495
|
clear() {
|
|
574
496
|
const baseKey = getLocalKey("");
|
|
575
|
-
for (let
|
|
576
|
-
if (
|
|
577
|
-
localStorage.removeItem(
|
|
497
|
+
for (let key in localStorage) {
|
|
498
|
+
if (key.slice(0, baseKey.length) === baseKey) {
|
|
499
|
+
localStorage.removeItem(key);
|
|
578
500
|
}
|
|
579
501
|
}
|
|
580
502
|
}
|
|
@@ -589,8 +511,8 @@ return s;
|
|
|
589
511
|
function getSettings(setting, article) {
|
|
590
512
|
if (!af?.userSession)
|
|
591
513
|
return null;
|
|
592
|
-
const
|
|
593
|
-
const settings = JSON.parse(localStorage.getItem(
|
|
514
|
+
const key = getKey(article);
|
|
515
|
+
const settings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
594
516
|
if (setting) {
|
|
595
517
|
return settings[setting] || null;
|
|
596
518
|
}
|
|
@@ -599,17 +521,17 @@ return s;
|
|
|
599
521
|
function saveSettings(setting, value, article) {
|
|
600
522
|
if (!af?.userSession)
|
|
601
523
|
return;
|
|
602
|
-
const
|
|
603
|
-
let userSettings = JSON.parse(localStorage.getItem(
|
|
524
|
+
const key = getKey(article);
|
|
525
|
+
let userSettings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
604
526
|
if (typeof value !== "undefined") {
|
|
605
527
|
userSettings[setting] = value;
|
|
606
528
|
} else {
|
|
607
529
|
userSettings = setting;
|
|
608
530
|
}
|
|
609
|
-
localStorage.setItem(
|
|
531
|
+
localStorage.setItem(key, JSON.stringify(userSettings));
|
|
610
532
|
}
|
|
611
533
|
|
|
612
534
|
// src/index.ts
|
|
613
|
-
var version = "2.0.
|
|
535
|
+
var version = "2.0.4";
|
|
614
536
|
return __toCommonJS(src_exports);
|
|
615
537
|
})();
|
|
@@ -6,7 +6,7 @@ af.common = (() => {
|
|
|
6
6
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
-
var __defNormalProp = (obj,
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
10
|
var __spreadValues = (a, b) => {
|
|
11
11
|
for (var prop in b || (b = {}))
|
|
12
12
|
if (__hasOwnProp.call(b, prop))
|
|
@@ -24,15 +24,15 @@ af.common = (() => {
|
|
|
24
24
|
};
|
|
25
25
|
var __copyProps = (to, from, except, desc) => {
|
|
26
26
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
27
|
-
for (let
|
|
28
|
-
if (!__hasOwnProp.call(to,
|
|
29
|
-
__defProp(to,
|
|
27
|
+
for (let key of __getOwnPropNames(from))
|
|
28
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
29
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
30
30
|
}
|
|
31
31
|
return to;
|
|
32
32
|
};
|
|
33
33
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
|
-
var __publicField = (obj,
|
|
35
|
-
__defNormalProp(obj, typeof
|
|
34
|
+
var __publicField = (obj, key, value) => {
|
|
35
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
36
36
|
return value;
|
|
37
37
|
};
|
|
38
38
|
|
|
@@ -96,12 +96,12 @@ af.common = (() => {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
// src/has.ts
|
|
99
|
-
function has(obj,
|
|
100
|
-
return Object.prototype.hasOwnProperty.call(obj,
|
|
99
|
+
function has(obj, key) {
|
|
100
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
// src/getLocalizedString.ts
|
|
104
|
-
async function
|
|
104
|
+
async function fetchLocalizedString(text) {
|
|
105
105
|
try {
|
|
106
106
|
let response = await fetch(`/api/user/localize/new/${af.article.id}`, {
|
|
107
107
|
body: JSON.stringify({ text }),
|
|
@@ -119,7 +119,7 @@ af.common = (() => {
|
|
|
119
119
|
}
|
|
120
120
|
return text;
|
|
121
121
|
}
|
|
122
|
-
function
|
|
122
|
+
function getLocalizedString(string, wait) {
|
|
123
123
|
var _a;
|
|
124
124
|
if (typeof string === "string" && string.trim().length === 0) {
|
|
125
125
|
return string;
|
|
@@ -130,7 +130,7 @@ af.common = (() => {
|
|
|
130
130
|
if (((_a = af == null ? void 0 : af.article) == null ? void 0 : _a.i18n) !== void 0) {
|
|
131
131
|
if (!has(af.article.i18n, string)) {
|
|
132
132
|
af.article.i18n[string] = string;
|
|
133
|
-
let promise =
|
|
133
|
+
let promise = fetchLocalizedString(string).then((text) => {
|
|
134
134
|
af.article.i18n[string] = text;
|
|
135
135
|
return text;
|
|
136
136
|
});
|
|
@@ -143,84 +143,6 @@ af.common = (() => {
|
|
|
143
143
|
return string;
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
|
-
var key = "__UNLOCALIZED_STRINGS__";
|
|
147
|
-
var localizeSet = window[key] || /* @__PURE__ */ new Set();
|
|
148
|
-
if (!window[key]) {
|
|
149
|
-
window[key] = localizeSet;
|
|
150
|
-
}
|
|
151
|
-
function handleReadyStateChange() {
|
|
152
|
-
if (document.readyState !== "loading") {
|
|
153
|
-
addDeveloperUtils();
|
|
154
|
-
document.removeEventListener("readystatechange", handleReadyStateChange);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
if (document.readyState !== "loading") {
|
|
158
|
-
addDeveloperUtils();
|
|
159
|
-
} else {
|
|
160
|
-
document.addEventListener("readystatechange", handleReadyStateChange);
|
|
161
|
-
}
|
|
162
|
-
function isDeveloper() {
|
|
163
|
-
const { af: af2 } = window;
|
|
164
|
-
return af2 && af2.userSession && af2.userSession.isDeveloper;
|
|
165
|
-
}
|
|
166
|
-
function addDeveloperUtils() {
|
|
167
|
-
if (isDeveloper()) {
|
|
168
|
-
if (typeof window.__doNothingWithStrings === "function") {
|
|
169
|
-
const addedStrings = window.__doNothingWithStrings();
|
|
170
|
-
for (let string of Object.keys(addedStrings)) {
|
|
171
|
-
localizeSet.add(string);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
if (!window[key]) {
|
|
175
|
-
window[key] = localizeSet;
|
|
176
|
-
}
|
|
177
|
-
if (!window.__getUnlocalizedStrings) {
|
|
178
|
-
window.__getUnlocalizedStrings = function(forCustomRoute) {
|
|
179
|
-
const strings = [];
|
|
180
|
-
for (let string of localizeSet) {
|
|
181
|
-
if (string) {
|
|
182
|
-
const escaped = string.replace(/'/g, "\\'");
|
|
183
|
-
if (forCustomRoute) {
|
|
184
|
-
const localized = afGetLocalizedString(string).replaceAll(/'/g, "\\'");
|
|
185
|
-
strings.push(`'${escaped}': '${localized}',`);
|
|
186
|
-
} else {
|
|
187
|
-
strings.push(
|
|
188
|
-
`s['${escaped}'] = @Html(@context.AddLocalizableString("${string.replaceAll('"', '\\"')}"));`
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
if (forCustomRoute) {
|
|
194
|
-
return `// Localization hack, since it AddLocalizableString doesn't work properly when custom routes is used
|
|
195
|
-
if (af.userSession.uiculture === 'nb-NO') {
|
|
196
|
-
const strings = {
|
|
197
|
-
${strings.join("\n ")}
|
|
198
|
-
};
|
|
199
|
-
af.article.i18n = af.article.i18n || {};
|
|
200
|
-
Object.assign(af.article.i18n, strings);
|
|
201
|
-
}`;
|
|
202
|
-
}
|
|
203
|
-
return `<script type="text/javascript">
|
|
204
|
-
function __doNothingWithStrings() {
|
|
205
|
-
@{
|
|
206
|
-
var context = @Appframe.Web.Context.RequestContext.Current;
|
|
207
|
-
}
|
|
208
|
-
let s = {};
|
|
209
|
-
${strings.join("\n")}
|
|
210
|
-
return s;
|
|
211
|
-
}
|
|
212
|
-
<\/script>`;
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
function getLocalizedString(string) {
|
|
218
|
-
const localized = afGetLocalizedString(string);
|
|
219
|
-
if (localized === string && !localizeSet.has(string)) {
|
|
220
|
-
localizeSet.add(string);
|
|
221
|
-
}
|
|
222
|
-
return localized;
|
|
223
|
-
}
|
|
224
146
|
|
|
225
147
|
// src/SessionHandler.ts
|
|
226
148
|
var _SessionHandler = class {
|
|
@@ -558,30 +480,30 @@ return s;
|
|
|
558
480
|
}
|
|
559
481
|
|
|
560
482
|
// src/localStorage.ts
|
|
561
|
-
function getLocalKey(
|
|
483
|
+
function getLocalKey(key) {
|
|
562
484
|
var _a;
|
|
563
|
-
return [((_a = af == null ? void 0 : af.article) == null ? void 0 : _a.id) || "", "common",
|
|
485
|
+
return [((_a = af == null ? void 0 : af.article) == null ? void 0 : _a.id) || "", "common", key].join(".");
|
|
564
486
|
}
|
|
565
487
|
var LocalStorage = class {
|
|
566
488
|
isPersisted() {
|
|
567
489
|
return true;
|
|
568
490
|
}
|
|
569
|
-
getLocalStorageKey(
|
|
570
|
-
return global ? ["common",
|
|
491
|
+
getLocalStorageKey(key, global) {
|
|
492
|
+
return global ? ["common", key].join(".") : getLocalKey(key);
|
|
571
493
|
}
|
|
572
|
-
get(
|
|
573
|
-
const lsKey = this.getLocalStorageKey(
|
|
494
|
+
get(key, defaultValue, global) {
|
|
495
|
+
const lsKey = this.getLocalStorageKey(key, global);
|
|
574
496
|
const value = localStorage.getItem(lsKey);
|
|
575
497
|
return value !== null ? JSON.parse(value) : defaultValue;
|
|
576
498
|
}
|
|
577
|
-
set(
|
|
499
|
+
set(key, value, global) {
|
|
578
500
|
localStorage.setItem(
|
|
579
|
-
this.getLocalStorageKey(
|
|
501
|
+
this.getLocalStorageKey(key, global),
|
|
580
502
|
JSON.stringify(value)
|
|
581
503
|
);
|
|
582
504
|
}
|
|
583
|
-
remove(
|
|
584
|
-
const lsKey = this.getLocalStorageKey(
|
|
505
|
+
remove(key, global) {
|
|
506
|
+
const lsKey = this.getLocalStorageKey(key, global);
|
|
585
507
|
if (localStorage.getItem(lsKey) !== null) {
|
|
586
508
|
localStorage.removeItem(lsKey);
|
|
587
509
|
return true;
|
|
@@ -591,9 +513,9 @@ return s;
|
|
|
591
513
|
}
|
|
592
514
|
clear() {
|
|
593
515
|
const baseKey = getLocalKey("");
|
|
594
|
-
for (let
|
|
595
|
-
if (
|
|
596
|
-
localStorage.removeItem(
|
|
516
|
+
for (let key in localStorage) {
|
|
517
|
+
if (key.slice(0, baseKey.length) === baseKey) {
|
|
518
|
+
localStorage.removeItem(key);
|
|
597
519
|
}
|
|
598
520
|
}
|
|
599
521
|
}
|
|
@@ -608,8 +530,8 @@ return s;
|
|
|
608
530
|
function getSettings(setting, article) {
|
|
609
531
|
if (!(af == null ? void 0 : af.userSession))
|
|
610
532
|
return null;
|
|
611
|
-
const
|
|
612
|
-
const settings = JSON.parse(localStorage.getItem(
|
|
533
|
+
const key = getKey(article);
|
|
534
|
+
const settings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
613
535
|
if (setting) {
|
|
614
536
|
return settings[setting] || null;
|
|
615
537
|
}
|
|
@@ -618,17 +540,17 @@ return s;
|
|
|
618
540
|
function saveSettings(setting, value, article) {
|
|
619
541
|
if (!(af == null ? void 0 : af.userSession))
|
|
620
542
|
return;
|
|
621
|
-
const
|
|
622
|
-
let userSettings = JSON.parse(localStorage.getItem(
|
|
543
|
+
const key = getKey(article);
|
|
544
|
+
let userSettings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
623
545
|
if (typeof value !== "undefined") {
|
|
624
546
|
userSettings[setting] = value;
|
|
625
547
|
} else {
|
|
626
548
|
userSettings = setting;
|
|
627
549
|
}
|
|
628
|
-
localStorage.setItem(
|
|
550
|
+
localStorage.setItem(key, JSON.stringify(userSettings));
|
|
629
551
|
}
|
|
630
552
|
|
|
631
553
|
// src/index.ts
|
|
632
|
-
var version = "2.0.
|
|
554
|
+
var version = "2.0.4";
|
|
633
555
|
return __toCommonJS(src_exports);
|
|
634
556
|
})();
|
|
@@ -1,22 +1,4 @@
|
|
|
1
|
-
var af=af||{};af.common=(()=>{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 y(t){let e=I(t);return e===t&&!h.has(t)&&h.add(t),e}var E=class{constructor(){i(this,"eventHandler",x());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 af=af||{};af.common=(()=>{var b=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames,k=Object.getOwnPropertySymbols;var R=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable;var j=(t,e,n)=>e in t?b(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,H=(t,e)=>{for(var n in e||(e={}))R.call(e,n)&&j(t,n,e[n]);if(k)for(var n of k(e))M.call(e,n)&&j(t,n,e[n]);return t};var $=(t,e)=>{for(var n in e)b(t,n,{get:e[n],enumerable:!0})},K=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of D(e))!R.call(t,o)&&o!==n&&b(t,o,{get:()=>e[o],enumerable:!(r=_(e,o))||r.enumerable});return t};var C=t=>K(b({},"__esModule",{value:!0}),t);var i=(t,e,n)=>(j(t,typeof e!="symbol"?e+"":e,n),n);var V={};$(V,{SessionHandler:()=>f,UserSession:()=>w,downloadBlob:()=>x,downloadRequest:()=>B,expose:()=>A,getLocalizedString:()=>y,getSettings:()=>U,has:()=>h,localStorage:()=>I,mitt:()=>v,saveSettings:()=>X,version:()=>Z});window.addEventListener("error",t=>{var e,n,r,o,l,a,s;try{let p={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(p),headers:{Accept:"application/json","Content-Type":"application/json; charset=utf-8","X-Requested-With":"XMLHttpRequest"},method:"POST"})}catch(p){}});function v(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 F(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=F(t).then(o=>(af.article.i18n[t]=o,o));if(e)return r}return af.article.i18n[t]}else return t}var S=class{constructor(){i(this,"eventHandler",v());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">
|
|
@@ -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?S.messages.relog:S.messages.login,l=r.querySelector(".message"),a=r.querySelector(".alert-warning"),s=r.querySelector("input[type=text]"),p=r.querySelector(".sign-in"),c=r.querySelector("input[type=password]");if(l!==null&&s!==null&&a!==null&&s!==null&&p!==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 g=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(m){if(m&&typeof m=="object"){let d=m;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")}}};p.addEventListener("click",g),c.addEventListener("keyup",u=>{u.key==="Enter"&&g()}),c.addEventListener("change",u=>{u.key==="Enter"&&g()}),s.addEventListener("keyup",u=>{u.key==="Enter"&&g()}),s.addEventListener("change",u=>{u.key==="Enter"&&g()}),c.focus()}}}attachEvent(e,n){return this.eventHandler.on(e,n)}detachEvent(e,n){return this.eventHandler.off(e,n)}},f=S;i(f,"messages",{login:"Log in",relog:"Session expired - log in"});var w=class extends f{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 x(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 B(t,{fileName:e,signal:n,onProgress:r}){var a;function o(s){typeof r=="function"&&r(H({},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(),g=new ReadableStream({start:function(u){function m(){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),m()})}return m()}});s=new Response(g)}catch(c){console.warn("Failed to replace response stream to log download progress.")}let p=await s.blob();o({bytesReceived:l,status:"downloaded"}),await x(p,e),o({bytesReceived:l,status:"completed"})}catch(s){n!=null&&n.aborted?o({status:"cancelled"}):o({error:s.message,status:"error"})}}var J=/^function(?:\s+([a-zA-Z$_][a-zA-Z0-9$_]*))?\s*\(((?:(?:\s*[a-zA-Z$_][a-zA-Z0-9$_]*)(?:\s*,\s*[a-zA-Z$_][a-zA-Z0-9$_]*)*)?)\s*\)\s*\{((?:.|\n|\r)*)\}$/;function E(t){var e=t.toString().match(J);if(e===null)throw new TypeError("Unable to parse function!");return{name:e[1],args:e[2].split(","),body:e[3]}}function O(){}O.prototype=Object.create(null);var q=O;function L(t,e){if(typeof t=="object")if(typeof e=="string"){let n=e.split(".");return L(t,n)}else if(Array.isArray(e)){let n=t;for(let r=0;r<e.length;r++)n=n[e[r]]=n[e[r]]||new q;return n}else throw new TypeError("Invalid type of parameter 'namespace'");else throw new TypeError("Invalid type of parameter 'root'")}function T(t,e){console.warn(t)}function A(t,e){if(arguments.length!==2)throw new Error("Incorrect number of arguments passed to the expose function!");if(Array.isArray(e))for(let n of e){let{name:r}=E(n);if(r)A(t,n);else throw new Error("Unable to detect name of function! Name it, or only supply one function and include name in first parameter.")}else{let n,r;if(typeof e=="function"&&(n=E(e).name),typeof t=="string"){let o=t.split(".");n||(n=o[o.length-1],o=o.slice(0,o.length-1)),r=L(window,o)}else if(n&&(typeof t=="object"||typeof t=="function"))r=t;else throw new TypeError("Invalid typeof parameter 'name', or unable to parse pValue!");h(r,n)?T([t,n].join(".")+" is already defined!"):r[n]=e}}function z(t){var e;return[((e=af==null?void 0:af.article)==null?void 0:e.id)||"","common",t].join(".")}var N=class{isPersisted(){return!0}getLocalStorageKey(e,n){return n?["common",e].join("."):z(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=z("");for(let n in localStorage)n.slice(0,e.length)===e&&localStorage.removeItem(n)}},I=new N;function P(t){return`${t||af.article.id}.${af.userSession.login}`}function U(t,e){if(!(af!=null&&af.userSession))return null;let n=P(e),r=JSON.parse(localStorage.getItem(n)||"{}");return t?r[t]||null:r}function X(t,e,n){if(!(af!=null&&af.userSession))return;let r=P(n),o=JSON.parse(localStorage.getItem(r)||"{}");typeof e<"u"?o[t]=e:o=t,localStorage.setItem(r,JSON.stringify(o))}var Z="2.0.4";return C(V);})();
|
|
48
30
|
//# sourceMappingURL=af.common.legacy.min.js.map
|