@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/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
|
|
|
@@ -81,11 +81,16 @@ var af;
|
|
|
81
81
|
} };
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
// src/has.ts
|
|
85
|
+
function has(obj, key) {
|
|
86
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
87
|
+
}
|
|
88
|
+
|
|
84
89
|
// src/getLocalizedString.ts
|
|
85
|
-
async function
|
|
90
|
+
async function fetchLocalizedString(text) {
|
|
86
91
|
try {
|
|
87
|
-
let response = await fetch(`/api/user/localize`, {
|
|
88
|
-
body: JSON.stringify({
|
|
92
|
+
let response = await fetch(`/api/user/localize/new/${af.article.id}`, {
|
|
93
|
+
body: JSON.stringify({ text }),
|
|
89
94
|
headers: {
|
|
90
95
|
Accept: "application/json; */*",
|
|
91
96
|
"Content-Type": "application/json",
|
|
@@ -98,13 +103,19 @@ var af;
|
|
|
98
103
|
}
|
|
99
104
|
} catch (error) {
|
|
100
105
|
}
|
|
101
|
-
return
|
|
106
|
+
return text;
|
|
102
107
|
}
|
|
103
|
-
function
|
|
108
|
+
function getLocalizedString(string, wait) {
|
|
109
|
+
if (typeof string === "string" && string.trim().length === 0) {
|
|
110
|
+
return string;
|
|
111
|
+
}
|
|
112
|
+
if (string === void 0 || string === "" || string === null) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
104
115
|
if (af?.article?.i18n !== void 0) {
|
|
105
|
-
if (!
|
|
116
|
+
if (!has(af.article.i18n, string)) {
|
|
106
117
|
af.article.i18n[string] = string;
|
|
107
|
-
let promise =
|
|
118
|
+
let promise = fetchLocalizedString(string).then((text) => {
|
|
108
119
|
af.article.i18n[string] = text;
|
|
109
120
|
return text;
|
|
110
121
|
});
|
|
@@ -117,84 +128,6 @@ var af;
|
|
|
117
128
|
return string;
|
|
118
129
|
}
|
|
119
130
|
}
|
|
120
|
-
var key = "__UNLOCALIZED_STRINGS__";
|
|
121
|
-
var localizeSet = window[key] || /* @__PURE__ */ new Set();
|
|
122
|
-
if (!window[key]) {
|
|
123
|
-
window[key] = localizeSet;
|
|
124
|
-
}
|
|
125
|
-
function handleReadyStateChange() {
|
|
126
|
-
if (document.readyState !== "loading") {
|
|
127
|
-
addDeveloperUtils();
|
|
128
|
-
document.removeEventListener("readystatechange", handleReadyStateChange);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (document.readyState !== "loading") {
|
|
132
|
-
addDeveloperUtils();
|
|
133
|
-
} else {
|
|
134
|
-
document.addEventListener("readystatechange", handleReadyStateChange);
|
|
135
|
-
}
|
|
136
|
-
function isDeveloper() {
|
|
137
|
-
const { af: af2 } = window;
|
|
138
|
-
return af2 && af2.userSession && af2.userSession.isDeveloper;
|
|
139
|
-
}
|
|
140
|
-
function addDeveloperUtils() {
|
|
141
|
-
if (isDeveloper()) {
|
|
142
|
-
if (typeof window.__doNothingWithStrings === "function") {
|
|
143
|
-
const addedStrings = window.__doNothingWithStrings();
|
|
144
|
-
for (let string of Object.keys(addedStrings)) {
|
|
145
|
-
localizeSet.add(string);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (!window[key]) {
|
|
149
|
-
window[key] = localizeSet;
|
|
150
|
-
}
|
|
151
|
-
if (!window.__getUnlocalizedStrings) {
|
|
152
|
-
window.__getUnlocalizedStrings = function(forCustomRoute) {
|
|
153
|
-
const strings = [];
|
|
154
|
-
for (let string of localizeSet) {
|
|
155
|
-
if (string) {
|
|
156
|
-
const escaped = string.replace(/'/g, "\\'");
|
|
157
|
-
if (forCustomRoute) {
|
|
158
|
-
const localized = afGetLocalizedString(string).replaceAll(/'/g, "\\'");
|
|
159
|
-
strings.push(`'${escaped}': '${localized}',`);
|
|
160
|
-
} else {
|
|
161
|
-
strings.push(
|
|
162
|
-
`s['${escaped}'] = @Html(@context.AddLocalizableString("${string.replaceAll('"', '\\"')}"));`
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
if (forCustomRoute) {
|
|
168
|
-
return `// Localization hack, since it AddLocalizableString doesn't work properly when custom routes is used
|
|
169
|
-
if (af.userSession.uiculture === 'nb-NO') {
|
|
170
|
-
const strings = {
|
|
171
|
-
${strings.join("\n ")}
|
|
172
|
-
};
|
|
173
|
-
af.article.i18n = af.article.i18n || {};
|
|
174
|
-
Object.assign(af.article.i18n, strings);
|
|
175
|
-
}`;
|
|
176
|
-
}
|
|
177
|
-
return `<script type="text/javascript">
|
|
178
|
-
function __doNothingWithStrings() {
|
|
179
|
-
@{
|
|
180
|
-
var context = @Appframe.Web.Context.RequestContext.Current;
|
|
181
|
-
}
|
|
182
|
-
let s = {};
|
|
183
|
-
${strings.join("\n")}
|
|
184
|
-
return s;
|
|
185
|
-
}
|
|
186
|
-
<\/script>`;
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
function getLocalizedString(string) {
|
|
192
|
-
const localized = afGetLocalizedString(string);
|
|
193
|
-
if (localized === string && !localizeSet.has(string)) {
|
|
194
|
-
localizeSet.add(string);
|
|
195
|
-
}
|
|
196
|
-
return localized;
|
|
197
|
-
}
|
|
198
131
|
|
|
199
132
|
// src/SessionHandler.ts
|
|
200
133
|
var _SessionHandler = class {
|
|
@@ -445,11 +378,6 @@ return s;
|
|
|
445
378
|
}
|
|
446
379
|
}
|
|
447
380
|
|
|
448
|
-
// src/has.ts
|
|
449
|
-
function has(obj, key2) {
|
|
450
|
-
return Object.prototype.hasOwnProperty.call(obj, key2);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
381
|
// src/parseFunc.ts
|
|
454
382
|
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)*)\}$/;
|
|
455
383
|
function parseFunc(func) {
|
|
@@ -534,29 +462,29 @@ return s;
|
|
|
534
462
|
}
|
|
535
463
|
|
|
536
464
|
// src/localStorage.ts
|
|
537
|
-
function getLocalKey(
|
|
538
|
-
return [af?.article?.id || "", "common",
|
|
465
|
+
function getLocalKey(key) {
|
|
466
|
+
return [af?.article?.id || "", "common", key].join(".");
|
|
539
467
|
}
|
|
540
468
|
var LocalStorage = class {
|
|
541
469
|
isPersisted() {
|
|
542
470
|
return true;
|
|
543
471
|
}
|
|
544
|
-
getLocalStorageKey(
|
|
545
|
-
return global ? ["common",
|
|
472
|
+
getLocalStorageKey(key, global) {
|
|
473
|
+
return global ? ["common", key].join(".") : getLocalKey(key);
|
|
546
474
|
}
|
|
547
|
-
get(
|
|
548
|
-
const lsKey = this.getLocalStorageKey(
|
|
475
|
+
get(key, defaultValue, global) {
|
|
476
|
+
const lsKey = this.getLocalStorageKey(key, global);
|
|
549
477
|
const value = localStorage.getItem(lsKey);
|
|
550
478
|
return value !== null ? JSON.parse(value) : defaultValue;
|
|
551
479
|
}
|
|
552
|
-
set(
|
|
480
|
+
set(key, value, global) {
|
|
553
481
|
localStorage.setItem(
|
|
554
|
-
this.getLocalStorageKey(
|
|
482
|
+
this.getLocalStorageKey(key, global),
|
|
555
483
|
JSON.stringify(value)
|
|
556
484
|
);
|
|
557
485
|
}
|
|
558
|
-
remove(
|
|
559
|
-
const lsKey = this.getLocalStorageKey(
|
|
486
|
+
remove(key, global) {
|
|
487
|
+
const lsKey = this.getLocalStorageKey(key, global);
|
|
560
488
|
if (localStorage.getItem(lsKey) !== null) {
|
|
561
489
|
localStorage.removeItem(lsKey);
|
|
562
490
|
return true;
|
|
@@ -566,9 +494,9 @@ return s;
|
|
|
566
494
|
}
|
|
567
495
|
clear() {
|
|
568
496
|
const baseKey = getLocalKey("");
|
|
569
|
-
for (let
|
|
570
|
-
if (
|
|
571
|
-
localStorage.removeItem(
|
|
497
|
+
for (let key in localStorage) {
|
|
498
|
+
if (key.slice(0, baseKey.length) === baseKey) {
|
|
499
|
+
localStorage.removeItem(key);
|
|
572
500
|
}
|
|
573
501
|
}
|
|
574
502
|
}
|
|
@@ -583,8 +511,8 @@ return s;
|
|
|
583
511
|
function getSettings(setting, article) {
|
|
584
512
|
if (!af?.userSession)
|
|
585
513
|
return null;
|
|
586
|
-
const
|
|
587
|
-
const settings = JSON.parse(localStorage.getItem(
|
|
514
|
+
const key = getKey(article);
|
|
515
|
+
const settings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
588
516
|
if (setting) {
|
|
589
517
|
return settings[setting] || null;
|
|
590
518
|
}
|
|
@@ -593,17 +521,17 @@ return s;
|
|
|
593
521
|
function saveSettings(setting, value, article) {
|
|
594
522
|
if (!af?.userSession)
|
|
595
523
|
return;
|
|
596
|
-
const
|
|
597
|
-
let userSettings = JSON.parse(localStorage.getItem(
|
|
524
|
+
const key = getKey(article);
|
|
525
|
+
let userSettings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
598
526
|
if (typeof value !== "undefined") {
|
|
599
527
|
userSettings[setting] = value;
|
|
600
528
|
} else {
|
|
601
529
|
userSettings = setting;
|
|
602
530
|
}
|
|
603
|
-
localStorage.setItem(
|
|
531
|
+
localStorage.setItem(key, JSON.stringify(userSettings));
|
|
604
532
|
}
|
|
605
533
|
|
|
606
534
|
// src/index.ts
|
|
607
|
-
var version = "2.0.
|
|
535
|
+
var version = "2.0.4";
|
|
608
536
|
return __toCommonJS(src_exports);
|
|
609
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
|
|
|
@@ -95,11 +95,16 @@ af.common = (() => {
|
|
|
95
95
|
} };
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
// src/has.ts
|
|
99
|
+
function has(obj, key) {
|
|
100
|
+
return Object.prototype.hasOwnProperty.call(obj, key);
|
|
101
|
+
}
|
|
102
|
+
|
|
98
103
|
// src/getLocalizedString.ts
|
|
99
|
-
async function
|
|
104
|
+
async function fetchLocalizedString(text) {
|
|
100
105
|
try {
|
|
101
|
-
let response = await fetch(`/api/user/localize`, {
|
|
102
|
-
body: JSON.stringify({
|
|
106
|
+
let response = await fetch(`/api/user/localize/new/${af.article.id}`, {
|
|
107
|
+
body: JSON.stringify({ text }),
|
|
103
108
|
headers: {
|
|
104
109
|
Accept: "application/json; */*",
|
|
105
110
|
"Content-Type": "application/json",
|
|
@@ -112,14 +117,20 @@ af.common = (() => {
|
|
|
112
117
|
}
|
|
113
118
|
} catch (error) {
|
|
114
119
|
}
|
|
115
|
-
return
|
|
120
|
+
return text;
|
|
116
121
|
}
|
|
117
|
-
function
|
|
122
|
+
function getLocalizedString(string, wait) {
|
|
118
123
|
var _a;
|
|
124
|
+
if (typeof string === "string" && string.trim().length === 0) {
|
|
125
|
+
return string;
|
|
126
|
+
}
|
|
127
|
+
if (string === void 0 || string === "" || string === null) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
119
130
|
if (((_a = af == null ? void 0 : af.article) == null ? void 0 : _a.i18n) !== void 0) {
|
|
120
|
-
if (!
|
|
131
|
+
if (!has(af.article.i18n, string)) {
|
|
121
132
|
af.article.i18n[string] = string;
|
|
122
|
-
let promise =
|
|
133
|
+
let promise = fetchLocalizedString(string).then((text) => {
|
|
123
134
|
af.article.i18n[string] = text;
|
|
124
135
|
return text;
|
|
125
136
|
});
|
|
@@ -132,84 +143,6 @@ af.common = (() => {
|
|
|
132
143
|
return string;
|
|
133
144
|
}
|
|
134
145
|
}
|
|
135
|
-
var key = "__UNLOCALIZED_STRINGS__";
|
|
136
|
-
var localizeSet = window[key] || /* @__PURE__ */ new Set();
|
|
137
|
-
if (!window[key]) {
|
|
138
|
-
window[key] = localizeSet;
|
|
139
|
-
}
|
|
140
|
-
function handleReadyStateChange() {
|
|
141
|
-
if (document.readyState !== "loading") {
|
|
142
|
-
addDeveloperUtils();
|
|
143
|
-
document.removeEventListener("readystatechange", handleReadyStateChange);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (document.readyState !== "loading") {
|
|
147
|
-
addDeveloperUtils();
|
|
148
|
-
} else {
|
|
149
|
-
document.addEventListener("readystatechange", handleReadyStateChange);
|
|
150
|
-
}
|
|
151
|
-
function isDeveloper() {
|
|
152
|
-
const { af: af2 } = window;
|
|
153
|
-
return af2 && af2.userSession && af2.userSession.isDeveloper;
|
|
154
|
-
}
|
|
155
|
-
function addDeveloperUtils() {
|
|
156
|
-
if (isDeveloper()) {
|
|
157
|
-
if (typeof window.__doNothingWithStrings === "function") {
|
|
158
|
-
const addedStrings = window.__doNothingWithStrings();
|
|
159
|
-
for (let string of Object.keys(addedStrings)) {
|
|
160
|
-
localizeSet.add(string);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
if (!window[key]) {
|
|
164
|
-
window[key] = localizeSet;
|
|
165
|
-
}
|
|
166
|
-
if (!window.__getUnlocalizedStrings) {
|
|
167
|
-
window.__getUnlocalizedStrings = function(forCustomRoute) {
|
|
168
|
-
const strings = [];
|
|
169
|
-
for (let string of localizeSet) {
|
|
170
|
-
if (string) {
|
|
171
|
-
const escaped = string.replace(/'/g, "\\'");
|
|
172
|
-
if (forCustomRoute) {
|
|
173
|
-
const localized = afGetLocalizedString(string).replaceAll(/'/g, "\\'");
|
|
174
|
-
strings.push(`'${escaped}': '${localized}',`);
|
|
175
|
-
} else {
|
|
176
|
-
strings.push(
|
|
177
|
-
`s['${escaped}'] = @Html(@context.AddLocalizableString("${string.replaceAll('"', '\\"')}"));`
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
if (forCustomRoute) {
|
|
183
|
-
return `// Localization hack, since it AddLocalizableString doesn't work properly when custom routes is used
|
|
184
|
-
if (af.userSession.uiculture === 'nb-NO') {
|
|
185
|
-
const strings = {
|
|
186
|
-
${strings.join("\n ")}
|
|
187
|
-
};
|
|
188
|
-
af.article.i18n = af.article.i18n || {};
|
|
189
|
-
Object.assign(af.article.i18n, strings);
|
|
190
|
-
}`;
|
|
191
|
-
}
|
|
192
|
-
return `<script type="text/javascript">
|
|
193
|
-
function __doNothingWithStrings() {
|
|
194
|
-
@{
|
|
195
|
-
var context = @Appframe.Web.Context.RequestContext.Current;
|
|
196
|
-
}
|
|
197
|
-
let s = {};
|
|
198
|
-
${strings.join("\n")}
|
|
199
|
-
return s;
|
|
200
|
-
}
|
|
201
|
-
<\/script>`;
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
function getLocalizedString(string) {
|
|
207
|
-
const localized = afGetLocalizedString(string);
|
|
208
|
-
if (localized === string && !localizeSet.has(string)) {
|
|
209
|
-
localizeSet.add(string);
|
|
210
|
-
}
|
|
211
|
-
return localized;
|
|
212
|
-
}
|
|
213
146
|
|
|
214
147
|
// src/SessionHandler.ts
|
|
215
148
|
var _SessionHandler = class {
|
|
@@ -463,11 +396,6 @@ return s;
|
|
|
463
396
|
}
|
|
464
397
|
}
|
|
465
398
|
|
|
466
|
-
// src/has.ts
|
|
467
|
-
function has(obj, key2) {
|
|
468
|
-
return Object.prototype.hasOwnProperty.call(obj, key2);
|
|
469
|
-
}
|
|
470
|
-
|
|
471
399
|
// src/parseFunc.ts
|
|
472
400
|
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)*)\}$/;
|
|
473
401
|
function parseFunc(func) {
|
|
@@ -552,30 +480,30 @@ return s;
|
|
|
552
480
|
}
|
|
553
481
|
|
|
554
482
|
// src/localStorage.ts
|
|
555
|
-
function getLocalKey(
|
|
483
|
+
function getLocalKey(key) {
|
|
556
484
|
var _a;
|
|
557
|
-
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(".");
|
|
558
486
|
}
|
|
559
487
|
var LocalStorage = class {
|
|
560
488
|
isPersisted() {
|
|
561
489
|
return true;
|
|
562
490
|
}
|
|
563
|
-
getLocalStorageKey(
|
|
564
|
-
return global ? ["common",
|
|
491
|
+
getLocalStorageKey(key, global) {
|
|
492
|
+
return global ? ["common", key].join(".") : getLocalKey(key);
|
|
565
493
|
}
|
|
566
|
-
get(
|
|
567
|
-
const lsKey = this.getLocalStorageKey(
|
|
494
|
+
get(key, defaultValue, global) {
|
|
495
|
+
const lsKey = this.getLocalStorageKey(key, global);
|
|
568
496
|
const value = localStorage.getItem(lsKey);
|
|
569
497
|
return value !== null ? JSON.parse(value) : defaultValue;
|
|
570
498
|
}
|
|
571
|
-
set(
|
|
499
|
+
set(key, value, global) {
|
|
572
500
|
localStorage.setItem(
|
|
573
|
-
this.getLocalStorageKey(
|
|
501
|
+
this.getLocalStorageKey(key, global),
|
|
574
502
|
JSON.stringify(value)
|
|
575
503
|
);
|
|
576
504
|
}
|
|
577
|
-
remove(
|
|
578
|
-
const lsKey = this.getLocalStorageKey(
|
|
505
|
+
remove(key, global) {
|
|
506
|
+
const lsKey = this.getLocalStorageKey(key, global);
|
|
579
507
|
if (localStorage.getItem(lsKey) !== null) {
|
|
580
508
|
localStorage.removeItem(lsKey);
|
|
581
509
|
return true;
|
|
@@ -585,9 +513,9 @@ return s;
|
|
|
585
513
|
}
|
|
586
514
|
clear() {
|
|
587
515
|
const baseKey = getLocalKey("");
|
|
588
|
-
for (let
|
|
589
|
-
if (
|
|
590
|
-
localStorage.removeItem(
|
|
516
|
+
for (let key in localStorage) {
|
|
517
|
+
if (key.slice(0, baseKey.length) === baseKey) {
|
|
518
|
+
localStorage.removeItem(key);
|
|
591
519
|
}
|
|
592
520
|
}
|
|
593
521
|
}
|
|
@@ -602,8 +530,8 @@ return s;
|
|
|
602
530
|
function getSettings(setting, article) {
|
|
603
531
|
if (!(af == null ? void 0 : af.userSession))
|
|
604
532
|
return null;
|
|
605
|
-
const
|
|
606
|
-
const settings = JSON.parse(localStorage.getItem(
|
|
533
|
+
const key = getKey(article);
|
|
534
|
+
const settings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
607
535
|
if (setting) {
|
|
608
536
|
return settings[setting] || null;
|
|
609
537
|
}
|
|
@@ -612,17 +540,17 @@ return s;
|
|
|
612
540
|
function saveSettings(setting, value, article) {
|
|
613
541
|
if (!(af == null ? void 0 : af.userSession))
|
|
614
542
|
return;
|
|
615
|
-
const
|
|
616
|
-
let userSettings = JSON.parse(localStorage.getItem(
|
|
543
|
+
const key = getKey(article);
|
|
544
|
+
let userSettings = JSON.parse(localStorage.getItem(key) || "{}");
|
|
617
545
|
if (typeof value !== "undefined") {
|
|
618
546
|
userSettings[setting] = value;
|
|
619
547
|
} else {
|
|
620
548
|
userSettings = setting;
|
|
621
549
|
}
|
|
622
|
-
localStorage.setItem(
|
|
550
|
+
localStorage.setItem(key, JSON.stringify(userSettings));
|
|
623
551
|
}
|
|
624
552
|
|
|
625
553
|
// src/index.ts
|
|
626
|
-
var version = "2.0.
|
|
554
|
+
var version = "2.0.4";
|
|
627
555
|
return __toCommonJS(src_exports);
|
|
628
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 x=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=`
|
|
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
|