@configura/web-api 2.0.0-alpha.21 → 2.0.0-alpha.22
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/.eslintrc.json +5 -5
- package/LICENSE +201 -201
- package/README.md +1 -1
- package/dist/CatalogueAPI.d.ts +622 -597
- package/dist/CatalogueAPI.js +329 -328
- package/dist/CfgMeasure.d.ts +32 -32
- package/dist/CfgMeasure.js +30 -30
- package/dist/CfgProduct.d.ts +344 -328
- package/dist/CfgProduct.js +996 -934
- package/dist/CfgReferencePathHelper.d.ts +26 -26
- package/dist/CfgReferencePathHelper.js +26 -26
- package/dist/ConfigurationConverter.d.ts +17 -17
- package/dist/ConfigurationConverter.js +175 -175
- package/dist/index.d.ts +23 -23
- package/dist/index.js +23 -23
- package/dist/io/CfgHistoryManager.d.ts +83 -83
- package/dist/io/CfgHistoryManager.js +144 -144
- package/dist/io/CfgHistoryToProdConfConnector.d.ts +21 -21
- package/dist/io/CfgHistoryToProdConfConnector.js +50 -50
- package/dist/io/CfgIOManager.d.ts +53 -53
- package/dist/io/CfgIOManager.js +134 -134
- package/dist/io/CfgIOProdConfConnector.d.ts +64 -64
- package/dist/io/CfgIOProdConfConnector.js +149 -149
- package/dist/io/CfgIOWarningSupplier.d.ts +3 -3
- package/dist/io/CfgIOWarningSupplier.js +1 -1
- package/dist/io/CfgObservableStateManager.d.ts +25 -25
- package/dist/io/CfgObservableStateManager.js +69 -69
- package/dist/io/CfgObservableStateToProdConfConnector.d.ts +14 -14
- package/dist/io/CfgObservableStateToProdConfConnector.js +16 -16
- package/dist/io/CfgWindowEventManager.d.ts +21 -21
- package/dist/io/CfgWindowEventManager.js +38 -38
- package/dist/io/CfgWindowMessageManager.d.ts +40 -40
- package/dist/io/CfgWindowMessageManager.js +91 -91
- package/dist/io/CfgWindowMessageToProdConfConnector.d.ts +16 -16
- package/dist/io/CfgWindowMessageToProdConfConnector.js +18 -18
- package/dist/io/index.d.ts +8 -8
- package/dist/io/index.js +8 -8
- package/dist/material/CfgMaterialMapping.d.ts +7 -7
- package/dist/material/CfgMaterialMapping.js +181 -181
- package/dist/material/CfgMtrlApplication.d.ts +18 -18
- package/dist/material/CfgMtrlApplication.js +43 -43
- package/dist/material/CfgMtrlApplicationSource.d.ts +7 -7
- package/dist/material/CfgMtrlApplicationSource.js +8 -8
- package/dist/material/CfgMtrlSource.d.ts +19 -19
- package/dist/material/CfgMtrlSource.js +40 -40
- package/dist/material/CfgMtrlSourceWithMetaData.d.ts +7 -7
- package/dist/material/CfgMtrlSourceWithMetaData.js +1 -1
- package/dist/productConfiguration/CfgFeature.d.ts +193 -189
- package/dist/productConfiguration/CfgFeature.js +671 -658
- package/dist/productConfiguration/CfgOption.d.ts +156 -151
- package/dist/productConfiguration/CfgOption.js +439 -422
- package/dist/productConfiguration/CfgProductConfiguration.d.ts +129 -129
- package/dist/productConfiguration/CfgProductConfiguration.js +340 -340
- package/dist/productConfiguration/filters.d.ts +15 -15
- package/dist/productConfiguration/filters.js +70 -70
- package/dist/productConfiguration/productParamsGenerator.d.ts +15 -15
- package/dist/productConfiguration/productParamsGenerator.js +51 -51
- package/dist/productConfiguration/utilitiesProductConfiguration.d.ts +17 -17
- package/dist/productConfiguration/utilitiesProductConfiguration.js +87 -87
- package/dist/productLoader.d.ts +33 -33
- package/dist/productLoader.js +49 -49
- package/dist/syncGroups/SyncGroupsApplyMode.d.ts +20 -20
- package/dist/syncGroups/SyncGroupsApplyMode.js +21 -21
- package/dist/syncGroups/SyncGroupsHandler.d.ts +47 -47
- package/dist/syncGroups/SyncGroupsHandler.js +370 -370
- package/dist/syncGroups/SyncGroupsPathHelper.d.ts +26 -26
- package/dist/syncGroups/SyncGroupsPathHelper.js +90 -90
- package/dist/syncGroups/SyncGroupsState.d.ts +39 -39
- package/dist/syncGroups/SyncGroupsState.js +167 -167
- package/dist/syncGroups/SyncGroupsTransaction.d.ts +154 -154
- package/dist/syncGroups/SyncGroupsTransaction.js +589 -589
- package/dist/tasks/TaskHandler.d.ts +77 -77
- package/dist/tasks/TaskHandler.js +276 -276
- package/dist/tasks/formats.d.ts +4 -4
- package/dist/tasks/formats.js +7 -7
- package/dist/tests/testData/collectorForTest.d.ts +73 -73
- package/dist/tests/testData/collectorForTest.js +194 -194
- package/dist/tests/testData/dummyProductForTest.d.ts +4 -4
- package/dist/tests/testData/dummyProductForTest.js +32 -32
- package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.d.ts +11 -11
- package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +282 -282
- package/dist/tests/testData/testDataCachedGetProduct.d.ts +5 -5
- package/dist/tests/testData/testDataCachedGetProduct.js +187 -187
- package/dist/tests/testData/testDataCachedPostValidate.d.ts +7 -7
- package/dist/tests/testData/testDataCachedPostValidate.js +185 -185
- package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.d.ts +3 -3
- package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.js +1099 -1099
- package/dist/tests/testData/testDataOptions.d.ts +12 -12
- package/dist/tests/testData/testDataOptions.js +60 -60
- package/dist/tests/testData/testDataProductAggregatedPrice.d.ts +6 -6
- package/dist/tests/testData/testDataProductAggregatedPrice.js +189 -189
- package/dist/tests/testData/testDataUpcharge.d.ts +8 -8
- package/dist/tests/testData/testDataUpcharge.js +121 -121
- package/dist/utilitiesCatalogueData.d.ts +47 -47
- package/dist/utilitiesCatalogueData.js +180 -180
- package/dist/utilitiesCataloguePermission.d.ts +38 -38
- package/dist/utilitiesCataloguePermission.js +79 -79
- package/dist/utilitiesNumericValues.d.ts +24 -24
- package/dist/utilitiesNumericValues.js +114 -114
- package/package.json +3 -3
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
import { CfgWindowEventManager } from "./CfgWindowEventManager.js";
|
|
2
|
-
declare type CfgHistoryManagerMessageData = {
|
|
3
|
-
initial: boolean;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* How the history is updated.
|
|
7
|
-
* @param DoNotWrite Only listens to initial URL-values.
|
|
8
|
-
* @param Replace Replaces the current history frame at updates.
|
|
9
|
-
* @param Push Adds history frames at updates.
|
|
10
|
-
* @param ReplaceAndUpdateUrl Replaces the current history frame at updates and updates the browser URL
|
|
11
|
-
* @param PushAndUpdateUrl Adds history frames at updates and updates the browser URL
|
|
12
|
-
*/
|
|
13
|
-
export declare enum HistoryMode {
|
|
14
|
-
DoNotWrite = 0,
|
|
15
|
-
Replace = 1,
|
|
16
|
-
Push = 2,
|
|
17
|
-
ReplaceAndUpdateUrl = 3,
|
|
18
|
-
PushAndUpdateUrl = 4
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* The collected data used when sending. For history this both contains the message, which is
|
|
22
|
-
* used as the "state" in the history-frame, and the qsKeyValues, which are query string
|
|
23
|
-
* key-values used in the URL.
|
|
24
|
-
* When navigating back and forth the stage (message) is used to restore the old state. When
|
|
25
|
-
* opening a window with no prior history the Query String will be used.
|
|
26
|
-
*/
|
|
27
|
-
export declare type CfgHistoryManagerSendData<D> = {
|
|
28
|
-
message: D;
|
|
29
|
-
mode: HistoryMode;
|
|
30
|
-
qsKeyValues: Map<string, string | undefined>;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* This class is used to coordinate writing and reading to the browser history.
|
|
34
|
-
* It handles messages sent from the connectors.
|
|
35
|
-
*/
|
|
36
|
-
export declare class CfgHistoryManager extends CfgWindowEventManager<"popstate", CfgHistoryManagerSendData<CfgHistoryManagerMessageData>> {
|
|
37
|
-
private static _instance;
|
|
38
|
-
static get instance(): CfgHistoryManager;
|
|
39
|
-
private constructor();
|
|
40
|
-
private _aggregatedQsKeyValues;
|
|
41
|
-
private _urlUpdateObservable;
|
|
42
|
-
/**
|
|
43
|
-
* @returns The current browser URL updated with the latest updates from
|
|
44
|
-
* the Connectors.
|
|
45
|
-
*/
|
|
46
|
-
getUrl(): string;
|
|
47
|
-
/**
|
|
48
|
-
* Listen for updated URL:s. This doesn't have to mean the URL in the
|
|
49
|
-
* browser has been updated.
|
|
50
|
-
*/
|
|
51
|
-
listenForUrl(listener: (url: string) => void): void;
|
|
52
|
-
/**
|
|
53
|
-
* Stop listen.
|
|
54
|
-
*/
|
|
55
|
-
stopListenForUrl(listener: (url: string) => void): void;
|
|
56
|
-
/**
|
|
57
|
-
* Write to the history
|
|
58
|
-
*/
|
|
59
|
-
send(messageKey: string, data: CfgHistoryManagerSendData<CfgHistoryManagerMessageData>): void;
|
|
60
|
-
/**
|
|
61
|
-
* Takes the current in browser URL and updates it with the provided Query String values.
|
|
62
|
-
* Old Query String is replaced.
|
|
63
|
-
*/
|
|
64
|
-
private static _makeUpdatedUrl;
|
|
65
|
-
/**
|
|
66
|
-
* Returns the current in browser Query String updated with the key values provided.
|
|
67
|
-
* If a value is undefined in the passed map it will be deleted from the Query String.
|
|
68
|
-
*/
|
|
69
|
-
private static _makeUpdatedQueryString;
|
|
70
|
-
/**
|
|
71
|
-
* @returns The current in browser Query String as a Map
|
|
72
|
-
*/
|
|
73
|
-
static currentQsKeyValues(): Map<string, string>;
|
|
74
|
-
/**
|
|
75
|
-
* If the passed currentState is a CfgIOContainer it will update it with the
|
|
76
|
-
* passed message. If not it will create a new CfgIOContainer with the message.
|
|
77
|
-
*/
|
|
78
|
-
private static _makeUpdatedState;
|
|
79
|
-
protected readonly eventType = "popstate";
|
|
80
|
-
protected getDataFromEvent(event: PopStateEvent): unknown;
|
|
81
|
-
static getMessageFromCurrentHistoryState(messageKey: string): unknown | undefined;
|
|
82
|
-
}
|
|
83
|
-
export {};
|
|
1
|
+
import { CfgWindowEventManager } from "./CfgWindowEventManager.js";
|
|
2
|
+
declare type CfgHistoryManagerMessageData = {
|
|
3
|
+
initial: boolean;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* How the history is updated.
|
|
7
|
+
* @param DoNotWrite Only listens to initial URL-values.
|
|
8
|
+
* @param Replace Replaces the current history frame at updates.
|
|
9
|
+
* @param Push Adds history frames at updates.
|
|
10
|
+
* @param ReplaceAndUpdateUrl Replaces the current history frame at updates and updates the browser URL
|
|
11
|
+
* @param PushAndUpdateUrl Adds history frames at updates and updates the browser URL
|
|
12
|
+
*/
|
|
13
|
+
export declare enum HistoryMode {
|
|
14
|
+
DoNotWrite = 0,
|
|
15
|
+
Replace = 1,
|
|
16
|
+
Push = 2,
|
|
17
|
+
ReplaceAndUpdateUrl = 3,
|
|
18
|
+
PushAndUpdateUrl = 4
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The collected data used when sending. For history this both contains the message, which is
|
|
22
|
+
* used as the "state" in the history-frame, and the qsKeyValues, which are query string
|
|
23
|
+
* key-values used in the URL.
|
|
24
|
+
* When navigating back and forth the stage (message) is used to restore the old state. When
|
|
25
|
+
* opening a window with no prior history the Query String will be used.
|
|
26
|
+
*/
|
|
27
|
+
export declare type CfgHistoryManagerSendData<D> = {
|
|
28
|
+
message: D;
|
|
29
|
+
mode: HistoryMode;
|
|
30
|
+
qsKeyValues: Map<string, string | undefined>;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* This class is used to coordinate writing and reading to the browser history.
|
|
34
|
+
* It handles messages sent from the connectors.
|
|
35
|
+
*/
|
|
36
|
+
export declare class CfgHistoryManager extends CfgWindowEventManager<"popstate", CfgHistoryManagerSendData<CfgHistoryManagerMessageData>> {
|
|
37
|
+
private static _instance;
|
|
38
|
+
static get instance(): CfgHistoryManager;
|
|
39
|
+
private constructor();
|
|
40
|
+
private _aggregatedQsKeyValues;
|
|
41
|
+
private _urlUpdateObservable;
|
|
42
|
+
/**
|
|
43
|
+
* @returns The current browser URL updated with the latest updates from
|
|
44
|
+
* the Connectors.
|
|
45
|
+
*/
|
|
46
|
+
getUrl(): string;
|
|
47
|
+
/**
|
|
48
|
+
* Listen for updated URL:s. This doesn't have to mean the URL in the
|
|
49
|
+
* browser has been updated.
|
|
50
|
+
*/
|
|
51
|
+
listenForUrl(listener: (url: string) => void): void;
|
|
52
|
+
/**
|
|
53
|
+
* Stop listen.
|
|
54
|
+
*/
|
|
55
|
+
stopListenForUrl(listener: (url: string) => void): void;
|
|
56
|
+
/**
|
|
57
|
+
* Write to the history
|
|
58
|
+
*/
|
|
59
|
+
send(messageKey: string, data: CfgHistoryManagerSendData<CfgHistoryManagerMessageData>): void;
|
|
60
|
+
/**
|
|
61
|
+
* Takes the current in browser URL and updates it with the provided Query String values.
|
|
62
|
+
* Old Query String is replaced.
|
|
63
|
+
*/
|
|
64
|
+
private static _makeUpdatedUrl;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the current in browser Query String updated with the key values provided.
|
|
67
|
+
* If a value is undefined in the passed map it will be deleted from the Query String.
|
|
68
|
+
*/
|
|
69
|
+
private static _makeUpdatedQueryString;
|
|
70
|
+
/**
|
|
71
|
+
* @returns The current in browser Query String as a Map
|
|
72
|
+
*/
|
|
73
|
+
static currentQsKeyValues(): Map<string, string>;
|
|
74
|
+
/**
|
|
75
|
+
* If the passed currentState is a CfgIOContainer it will update it with the
|
|
76
|
+
* passed message. If not it will create a new CfgIOContainer with the message.
|
|
77
|
+
*/
|
|
78
|
+
private static _makeUpdatedState;
|
|
79
|
+
protected readonly eventType = "popstate";
|
|
80
|
+
protected getDataFromEvent(event: PopStateEvent): unknown;
|
|
81
|
+
static getMessageFromCurrentHistoryState(messageKey: string): unknown | undefined;
|
|
82
|
+
}
|
|
83
|
+
export {};
|
|
84
84
|
//# sourceMappingURL=CfgHistoryManager.d.ts.map
|
|
@@ -1,144 +1,144 @@
|
|
|
1
|
-
import { mapQueryString, Observable, unmapQueryString } from "@configura/web-utilities";
|
|
2
|
-
import { CfgIOManager } from "./CfgIOManager.js";
|
|
3
|
-
import { CfgWindowEventManager } from "./CfgWindowEventManager.js";
|
|
4
|
-
/**
|
|
5
|
-
* How the history is updated.
|
|
6
|
-
* @param DoNotWrite Only listens to initial URL-values.
|
|
7
|
-
* @param Replace Replaces the current history frame at updates.
|
|
8
|
-
* @param Push Adds history frames at updates.
|
|
9
|
-
* @param ReplaceAndUpdateUrl Replaces the current history frame at updates and updates the browser URL
|
|
10
|
-
* @param PushAndUpdateUrl Adds history frames at updates and updates the browser URL
|
|
11
|
-
*/
|
|
12
|
-
export var HistoryMode;
|
|
13
|
-
(function (HistoryMode) {
|
|
14
|
-
HistoryMode[HistoryMode["DoNotWrite"] = 0] = "DoNotWrite";
|
|
15
|
-
HistoryMode[HistoryMode["Replace"] = 1] = "Replace";
|
|
16
|
-
HistoryMode[HistoryMode["Push"] = 2] = "Push";
|
|
17
|
-
HistoryMode[HistoryMode["ReplaceAndUpdateUrl"] = 3] = "ReplaceAndUpdateUrl";
|
|
18
|
-
HistoryMode[HistoryMode["PushAndUpdateUrl"] = 4] = "PushAndUpdateUrl";
|
|
19
|
-
})(HistoryMode || (HistoryMode = {}));
|
|
20
|
-
/**
|
|
21
|
-
* This class is used to coordinate writing and reading to the browser history.
|
|
22
|
-
* It handles messages sent from the connectors.
|
|
23
|
-
*/
|
|
24
|
-
export class CfgHistoryManager extends CfgWindowEventManager {
|
|
25
|
-
constructor() {
|
|
26
|
-
super();
|
|
27
|
-
this._aggregatedQsKeyValues = new Map();
|
|
28
|
-
this._urlUpdateObservable = new Observable();
|
|
29
|
-
this.eventType = "popstate";
|
|
30
|
-
}
|
|
31
|
-
static get instance() {
|
|
32
|
-
if (this._instance === undefined) {
|
|
33
|
-
this._instance = new CfgHistoryManager();
|
|
34
|
-
}
|
|
35
|
-
return this._instance;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* @returns The current browser URL updated with the latest updates from
|
|
39
|
-
* the Connectors.
|
|
40
|
-
*/
|
|
41
|
-
getUrl() {
|
|
42
|
-
return CfgHistoryManager._makeUpdatedUrl(this._aggregatedQsKeyValues);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Listen for updated URL:s. This doesn't have to mean the URL in the
|
|
46
|
-
* browser has been updated.
|
|
47
|
-
*/
|
|
48
|
-
listenForUrl(listener) {
|
|
49
|
-
this._urlUpdateObservable.listen(listener);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Stop listen.
|
|
53
|
-
*/
|
|
54
|
-
stopListenForUrl(listener) {
|
|
55
|
-
this._urlUpdateObservable.stopListen(listener);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Write to the history
|
|
59
|
-
*/
|
|
60
|
-
send(messageKey, data) {
|
|
61
|
-
const { qsKeyValues, message, mode } = data;
|
|
62
|
-
for (const keyValue of qsKeyValues) {
|
|
63
|
-
this._aggregatedQsKeyValues.set(keyValue[0], keyValue[1]);
|
|
64
|
-
}
|
|
65
|
-
this._urlUpdateObservable.notifyAll(this.getUrl());
|
|
66
|
-
if (mode === HistoryMode.DoNotWrite) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
// Initial data is before user interaction has happened
|
|
70
|
-
const initial = message.initial;
|
|
71
|
-
const url = CfgHistoryManager._makeUpdatedUrl(qsKeyValues);
|
|
72
|
-
// At initial we do not replace the URL as we presumable have the defaults
|
|
73
|
-
const writeUrl = initial ||
|
|
74
|
-
!(mode === HistoryMode.PushAndUpdateUrl || mode === HistoryMode.ReplaceAndUpdateUrl)
|
|
75
|
-
? null
|
|
76
|
-
: url;
|
|
77
|
-
// ...but we do replace the state so that we can in the future browse back to here
|
|
78
|
-
const newState = CfgHistoryManager._makeUpdatedState(window.history.state, message, messageKey);
|
|
79
|
-
if (initial ||
|
|
80
|
-
mode === HistoryMode.Replace ||
|
|
81
|
-
mode === HistoryMode.ReplaceAndUpdateUrl ||
|
|
82
|
-
this.receiveInProgress) {
|
|
83
|
-
window.history.replaceState(newState, "", writeUrl);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
window.history.pushState(newState, "", writeUrl);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Takes the current in browser URL and updates it with the provided Query String values.
|
|
91
|
-
* Old Query String is replaced.
|
|
92
|
-
*/
|
|
93
|
-
static _makeUpdatedUrl(qsKeyValues) {
|
|
94
|
-
const qs = this._makeUpdatedQueryString(qsKeyValues);
|
|
95
|
-
return `${window.location.origin}${window.location.pathname}${qs ? "?" : ""}${qs}${window.location.hash}`;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Returns the current in browser Query String updated with the key values provided.
|
|
99
|
-
* If a value is undefined in the passed map it will be deleted from the Query String.
|
|
100
|
-
*/
|
|
101
|
-
static _makeUpdatedQueryString(qsKeyValues) {
|
|
102
|
-
const currentKeyValues = this.currentQsKeyValues();
|
|
103
|
-
for (const [key, value] of qsKeyValues) {
|
|
104
|
-
if (value === undefined) {
|
|
105
|
-
currentKeyValues.delete(key);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
currentKeyValues.set(key, value);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return unmapQueryString(currentKeyValues);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* @returns The current in browser Query String as a Map
|
|
115
|
-
*/
|
|
116
|
-
static currentQsKeyValues() {
|
|
117
|
-
return mapQueryString(window.location.search);
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* If the passed currentState is a CfgIOContainer it will update it with the
|
|
121
|
-
* passed message. If not it will create a new CfgIOContainer with the message.
|
|
122
|
-
*/
|
|
123
|
-
static _makeUpdatedState(currentState, message, messageKey) {
|
|
124
|
-
let messages = {};
|
|
125
|
-
if (CfgIOManager.isIOContainer(currentState)) {
|
|
126
|
-
messages = currentState.messages;
|
|
127
|
-
}
|
|
128
|
-
messages[messageKey] = message;
|
|
129
|
-
return CfgIOManager.makeContainer(messages);
|
|
130
|
-
}
|
|
131
|
-
getDataFromEvent(event) {
|
|
132
|
-
return event.state;
|
|
133
|
-
}
|
|
134
|
-
static getMessageFromCurrentHistoryState(messageKey) {
|
|
135
|
-
const state = window.history.state;
|
|
136
|
-
if (!CfgIOManager.isIOContainer(state)) {
|
|
137
|
-
return undefined;
|
|
138
|
-
}
|
|
139
|
-
if (!CfgIOManager.hasIOContainerMessageKey(state, messageKey)) {
|
|
140
|
-
return undefined;
|
|
141
|
-
}
|
|
142
|
-
return CfgIOManager.getMessageFromIOContainer(state, messageKey);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
1
|
+
import { mapQueryString, Observable, unmapQueryString } from "@configura/web-utilities";
|
|
2
|
+
import { CfgIOManager } from "./CfgIOManager.js";
|
|
3
|
+
import { CfgWindowEventManager } from "./CfgWindowEventManager.js";
|
|
4
|
+
/**
|
|
5
|
+
* How the history is updated.
|
|
6
|
+
* @param DoNotWrite Only listens to initial URL-values.
|
|
7
|
+
* @param Replace Replaces the current history frame at updates.
|
|
8
|
+
* @param Push Adds history frames at updates.
|
|
9
|
+
* @param ReplaceAndUpdateUrl Replaces the current history frame at updates and updates the browser URL
|
|
10
|
+
* @param PushAndUpdateUrl Adds history frames at updates and updates the browser URL
|
|
11
|
+
*/
|
|
12
|
+
export var HistoryMode;
|
|
13
|
+
(function (HistoryMode) {
|
|
14
|
+
HistoryMode[HistoryMode["DoNotWrite"] = 0] = "DoNotWrite";
|
|
15
|
+
HistoryMode[HistoryMode["Replace"] = 1] = "Replace";
|
|
16
|
+
HistoryMode[HistoryMode["Push"] = 2] = "Push";
|
|
17
|
+
HistoryMode[HistoryMode["ReplaceAndUpdateUrl"] = 3] = "ReplaceAndUpdateUrl";
|
|
18
|
+
HistoryMode[HistoryMode["PushAndUpdateUrl"] = 4] = "PushAndUpdateUrl";
|
|
19
|
+
})(HistoryMode || (HistoryMode = {}));
|
|
20
|
+
/**
|
|
21
|
+
* This class is used to coordinate writing and reading to the browser history.
|
|
22
|
+
* It handles messages sent from the connectors.
|
|
23
|
+
*/
|
|
24
|
+
export class CfgHistoryManager extends CfgWindowEventManager {
|
|
25
|
+
constructor() {
|
|
26
|
+
super();
|
|
27
|
+
this._aggregatedQsKeyValues = new Map();
|
|
28
|
+
this._urlUpdateObservable = new Observable();
|
|
29
|
+
this.eventType = "popstate";
|
|
30
|
+
}
|
|
31
|
+
static get instance() {
|
|
32
|
+
if (this._instance === undefined) {
|
|
33
|
+
this._instance = new CfgHistoryManager();
|
|
34
|
+
}
|
|
35
|
+
return this._instance;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @returns The current browser URL updated with the latest updates from
|
|
39
|
+
* the Connectors.
|
|
40
|
+
*/
|
|
41
|
+
getUrl() {
|
|
42
|
+
return CfgHistoryManager._makeUpdatedUrl(this._aggregatedQsKeyValues);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Listen for updated URL:s. This doesn't have to mean the URL in the
|
|
46
|
+
* browser has been updated.
|
|
47
|
+
*/
|
|
48
|
+
listenForUrl(listener) {
|
|
49
|
+
this._urlUpdateObservable.listen(listener);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Stop listen.
|
|
53
|
+
*/
|
|
54
|
+
stopListenForUrl(listener) {
|
|
55
|
+
this._urlUpdateObservable.stopListen(listener);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Write to the history
|
|
59
|
+
*/
|
|
60
|
+
send(messageKey, data) {
|
|
61
|
+
const { qsKeyValues, message, mode } = data;
|
|
62
|
+
for (const keyValue of qsKeyValues) {
|
|
63
|
+
this._aggregatedQsKeyValues.set(keyValue[0], keyValue[1]);
|
|
64
|
+
}
|
|
65
|
+
this._urlUpdateObservable.notifyAll(this.getUrl());
|
|
66
|
+
if (mode === HistoryMode.DoNotWrite) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// Initial data is before user interaction has happened
|
|
70
|
+
const initial = message.initial;
|
|
71
|
+
const url = CfgHistoryManager._makeUpdatedUrl(qsKeyValues);
|
|
72
|
+
// At initial we do not replace the URL as we presumable have the defaults
|
|
73
|
+
const writeUrl = initial ||
|
|
74
|
+
!(mode === HistoryMode.PushAndUpdateUrl || mode === HistoryMode.ReplaceAndUpdateUrl)
|
|
75
|
+
? null
|
|
76
|
+
: url;
|
|
77
|
+
// ...but we do replace the state so that we can in the future browse back to here
|
|
78
|
+
const newState = CfgHistoryManager._makeUpdatedState(window.history.state, message, messageKey);
|
|
79
|
+
if (initial ||
|
|
80
|
+
mode === HistoryMode.Replace ||
|
|
81
|
+
mode === HistoryMode.ReplaceAndUpdateUrl ||
|
|
82
|
+
this.receiveInProgress) {
|
|
83
|
+
window.history.replaceState(newState, "", writeUrl);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
window.history.pushState(newState, "", writeUrl);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Takes the current in browser URL and updates it with the provided Query String values.
|
|
91
|
+
* Old Query String is replaced.
|
|
92
|
+
*/
|
|
93
|
+
static _makeUpdatedUrl(qsKeyValues) {
|
|
94
|
+
const qs = this._makeUpdatedQueryString(qsKeyValues);
|
|
95
|
+
return `${window.location.origin}${window.location.pathname}${qs ? "?" : ""}${qs}${window.location.hash}`;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Returns the current in browser Query String updated with the key values provided.
|
|
99
|
+
* If a value is undefined in the passed map it will be deleted from the Query String.
|
|
100
|
+
*/
|
|
101
|
+
static _makeUpdatedQueryString(qsKeyValues) {
|
|
102
|
+
const currentKeyValues = this.currentQsKeyValues();
|
|
103
|
+
for (const [key, value] of qsKeyValues) {
|
|
104
|
+
if (value === undefined) {
|
|
105
|
+
currentKeyValues.delete(key);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
currentKeyValues.set(key, value);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return unmapQueryString(currentKeyValues);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* @returns The current in browser Query String as a Map
|
|
115
|
+
*/
|
|
116
|
+
static currentQsKeyValues() {
|
|
117
|
+
return mapQueryString(window.location.search);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* If the passed currentState is a CfgIOContainer it will update it with the
|
|
121
|
+
* passed message. If not it will create a new CfgIOContainer with the message.
|
|
122
|
+
*/
|
|
123
|
+
static _makeUpdatedState(currentState, message, messageKey) {
|
|
124
|
+
let messages = {};
|
|
125
|
+
if (CfgIOManager.isIOContainer(currentState)) {
|
|
126
|
+
messages = currentState.messages;
|
|
127
|
+
}
|
|
128
|
+
messages[messageKey] = message;
|
|
129
|
+
return CfgIOManager.makeContainer(messages);
|
|
130
|
+
}
|
|
131
|
+
getDataFromEvent(event) {
|
|
132
|
+
return event.state;
|
|
133
|
+
}
|
|
134
|
+
static getMessageFromCurrentHistoryState(messageKey) {
|
|
135
|
+
const state = window.history.state;
|
|
136
|
+
if (!CfgIOManager.isIOContainer(state)) {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
if (!CfgIOManager.hasIOContainerMessageKey(state, messageKey)) {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
return CfgIOManager.getMessageFromIOContainer(state, messageKey);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { DtoProductConf } from "../CatalogueAPI.js";
|
|
2
|
-
import { CfgHistoryManager, CfgHistoryManagerSendData, HistoryMode } from "./CfgHistoryManager.js";
|
|
3
|
-
import { CfgIOProdConfConnector, CfgProdConfMessage } from "./CfgIOProdConfConnector.js";
|
|
4
|
-
/**
|
|
5
|
-
* Instantiating this will make the browser history (and URL) update with the product configuration.
|
|
6
|
-
*/
|
|
7
|
-
export declare class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector<CfgHistoryManagerSendData<CfgProdConfMessage>> {
|
|
8
|
-
private readonly _mode;
|
|
9
|
-
private readonly _qsKey;
|
|
10
|
-
private static getInitialProdConf;
|
|
11
|
-
static make(manager: CfgHistoryManager, mode: HistoryMode, qsKey?: string): {
|
|
12
|
-
instance: CfgHistoryToProdConfConnector;
|
|
13
|
-
initial: DtoProductConf | undefined;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* @param _mode
|
|
17
|
-
* @param _qsKey The Query String key for product configuration.
|
|
18
|
-
*/
|
|
19
|
-
private constructor();
|
|
20
|
-
protected makeSendData(conf: DtoProductConf, initial: boolean): CfgHistoryManagerSendData<CfgProdConfMessage>;
|
|
21
|
-
}
|
|
1
|
+
import { DtoProductConf } from "../CatalogueAPI.js";
|
|
2
|
+
import { CfgHistoryManager, CfgHistoryManagerSendData, HistoryMode } from "./CfgHistoryManager.js";
|
|
3
|
+
import { CfgIOProdConfConnector, CfgProdConfMessage } from "./CfgIOProdConfConnector.js";
|
|
4
|
+
/**
|
|
5
|
+
* Instantiating this will make the browser history (and URL) update with the product configuration.
|
|
6
|
+
*/
|
|
7
|
+
export declare class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector<CfgHistoryManagerSendData<CfgProdConfMessage>> {
|
|
8
|
+
private readonly _mode;
|
|
9
|
+
private readonly _qsKey;
|
|
10
|
+
private static getInitialProdConf;
|
|
11
|
+
static make(manager: CfgHistoryManager, mode: HistoryMode, qsKey?: string): {
|
|
12
|
+
instance: CfgHistoryToProdConfConnector;
|
|
13
|
+
initial: DtoProductConf | undefined;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* @param _mode
|
|
17
|
+
* @param _qsKey The Query String key for product configuration.
|
|
18
|
+
*/
|
|
19
|
+
private constructor();
|
|
20
|
+
protected makeSendData(conf: DtoProductConf, initial: boolean): CfgHistoryManagerSendData<CfgProdConfMessage>;
|
|
21
|
+
}
|
|
22
22
|
//# sourceMappingURL=CfgHistoryToProdConfConnector.d.ts.map
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { augmentErrorMessage } from "@configura/web-utilities";
|
|
2
|
-
import { compactStringToDtoProductConf, dtoProductConfigurationToCompactString, } from "../ConfigurationConverter.js";
|
|
3
|
-
import { CfgHistoryManager } from "./CfgHistoryManager.js";
|
|
4
|
-
import { CfgIOProdConfConnector, CfgProdConfMessageVersions, CfgProdConfParts, getHighestVersionProdConfMessage, isCfgProdConfMessageV2, STAGE_PROD_CONF_MESSAGE_KEY, } from "./CfgIOProdConfConnector.js";
|
|
5
|
-
/**
|
|
6
|
-
* Instantiating this will make the browser history (and URL) update with the product configuration.
|
|
7
|
-
*/
|
|
8
|
-
export class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector {
|
|
9
|
-
/**
|
|
10
|
-
* @param _mode
|
|
11
|
-
* @param _qsKey The Query String key for product configuration.
|
|
12
|
-
*/
|
|
13
|
-
constructor(manager, _mode, _qsKey) {
|
|
14
|
-
super(manager, CfgProdConfParts.SyncGroupState);
|
|
15
|
-
this._mode = _mode;
|
|
16
|
-
this._qsKey = _qsKey;
|
|
17
|
-
}
|
|
18
|
-
static getInitialProdConf(qsKey) {
|
|
19
|
-
// First try to use the state, if that doesn't work use the query string
|
|
20
|
-
const initialMessage = CfgHistoryManager.getMessageFromCurrentHistoryState(STAGE_PROD_CONF_MESSAGE_KEY);
|
|
21
|
-
if (initialMessage !== undefined) {
|
|
22
|
-
const highestVersionMessage = getHighestVersionProdConfMessage(initialMessage.subMessages);
|
|
23
|
-
if (isCfgProdConfMessageV2(highestVersionMessage)) {
|
|
24
|
-
return highestVersionMessage.conf;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
try {
|
|
28
|
-
const s = CfgHistoryManager.currentQsKeyValues().get(qsKey);
|
|
29
|
-
if (s === undefined) {
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
32
|
-
return compactStringToDtoProductConf(s);
|
|
33
|
-
}
|
|
34
|
-
catch (err) {
|
|
35
|
-
throw augmentErrorMessage(err, "Failed read configuration from query string");
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
static make(manager, mode, qsKey = STAGE_PROD_CONF_MESSAGE_KEY) {
|
|
39
|
-
const initial = this.getInitialProdConf(qsKey);
|
|
40
|
-
const instance = new CfgHistoryToProdConfConnector(manager, mode, qsKey);
|
|
41
|
-
return { instance, initial };
|
|
42
|
-
}
|
|
43
|
-
makeSendData(conf, initial) {
|
|
44
|
-
return {
|
|
45
|
-
message: CfgIOProdConfConnector.makeMessage(conf, initial, CfgProdConfMessageVersions.V2dot0),
|
|
46
|
-
qsKeyValues: new Map([[this._qsKey, dtoProductConfigurationToCompactString(conf)]]),
|
|
47
|
-
mode: this._mode,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
}
|
|
1
|
+
import { augmentErrorMessage } from "@configura/web-utilities";
|
|
2
|
+
import { compactStringToDtoProductConf, dtoProductConfigurationToCompactString, } from "../ConfigurationConverter.js";
|
|
3
|
+
import { CfgHistoryManager } from "./CfgHistoryManager.js";
|
|
4
|
+
import { CfgIOProdConfConnector, CfgProdConfMessageVersions, CfgProdConfParts, getHighestVersionProdConfMessage, isCfgProdConfMessageV2, STAGE_PROD_CONF_MESSAGE_KEY, } from "./CfgIOProdConfConnector.js";
|
|
5
|
+
/**
|
|
6
|
+
* Instantiating this will make the browser history (and URL) update with the product configuration.
|
|
7
|
+
*/
|
|
8
|
+
export class CfgHistoryToProdConfConnector extends CfgIOProdConfConnector {
|
|
9
|
+
/**
|
|
10
|
+
* @param _mode
|
|
11
|
+
* @param _qsKey The Query String key for product configuration.
|
|
12
|
+
*/
|
|
13
|
+
constructor(manager, _mode, _qsKey) {
|
|
14
|
+
super(manager, CfgProdConfParts.SyncGroupState);
|
|
15
|
+
this._mode = _mode;
|
|
16
|
+
this._qsKey = _qsKey;
|
|
17
|
+
}
|
|
18
|
+
static getInitialProdConf(qsKey) {
|
|
19
|
+
// First try to use the state, if that doesn't work use the query string
|
|
20
|
+
const initialMessage = CfgHistoryManager.getMessageFromCurrentHistoryState(STAGE_PROD_CONF_MESSAGE_KEY);
|
|
21
|
+
if (initialMessage !== undefined) {
|
|
22
|
+
const highestVersionMessage = getHighestVersionProdConfMessage(initialMessage.subMessages);
|
|
23
|
+
if (isCfgProdConfMessageV2(highestVersionMessage)) {
|
|
24
|
+
return highestVersionMessage.conf;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const s = CfgHistoryManager.currentQsKeyValues().get(qsKey);
|
|
29
|
+
if (s === undefined) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
return compactStringToDtoProductConf(s);
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
throw augmentErrorMessage(err, "Failed read configuration from query string");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
static make(manager, mode, qsKey = STAGE_PROD_CONF_MESSAGE_KEY) {
|
|
39
|
+
const initial = this.getInitialProdConf(qsKey);
|
|
40
|
+
const instance = new CfgHistoryToProdConfConnector(manager, mode, qsKey);
|
|
41
|
+
return { instance, initial };
|
|
42
|
+
}
|
|
43
|
+
makeSendData(conf, initial) {
|
|
44
|
+
return {
|
|
45
|
+
message: CfgIOProdConfConnector.makeMessage(conf, initial, CfgProdConfMessageVersions.V2dot0),
|
|
46
|
+
qsKeyValues: new Map([[this._qsKey, dtoProductConfigurationToCompactString(conf)]]),
|
|
47
|
+
mode: this._mode,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|