@coolon/angular-ui-powerups 12.4.0-alpha.0 → 12.4.0-alpha.1
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/bundles/coolon-angular-ui-powerups-cypress.umd.js +9 -7
- package/bundles/coolon-angular-ui-powerups-cypress.umd.js.map +1 -1
- package/bundles/coolon-angular-ui-powerups.umd.js +245 -250
- package/bundles/coolon-angular-ui-powerups.umd.js.map +1 -1
- package/coolon-angular-ui-powerups.metadata.json +1 -1
- package/cypress/page.d.ts +6 -2
- package/cypress/path.d.ts +1 -1
- package/esm2015/cypress/page.js +7 -5
- package/esm2015/cypress/page.js.map +1 -1
- package/esm2015/cypress/path.js +2 -2
- package/esm2015/cypress/path.js.map +1 -1
- package/esm2015/lib/place/navigation/place-component-deactivation-handler.js +3 -9
- package/esm2015/lib/place/navigation/place-component-deactivation-handler.js.map +1 -1
- package/esm2015/lib/place/navigation/place-component-deactivation-handler.metadata.json +1 -1
- package/fesm2015/coolon-angular-ui-powerups-cypress.js +9 -7
- package/fesm2015/coolon-angular-ui-powerups-cypress.js.map +1 -1
- package/fesm2015/coolon-angular-ui-powerups.js +229 -234
- package/fesm2015/coolon-angular-ui-powerups.js.map +1 -1
- package/package.json +1 -1
|
@@ -5979,234 +5979,6 @@ __decorate([
|
|
|
5979
5979
|
PlaceComponent.injectDefinition = injectDefinition;
|
|
5980
5980
|
})(PlaceComponent || (PlaceComponent = {}));
|
|
5981
5981
|
|
|
5982
|
-
/**
|
|
5983
|
-
* This a work around for the fact that an activated route with multiple segments doesn't
|
|
5984
|
-
* include the segment params in the paramMap as well as each segment returns an empty
|
|
5985
|
-
* param map even when `parameter`s has content.
|
|
5986
|
-
*/
|
|
5987
|
-
class ConsolidatedParameterMap {
|
|
5988
|
-
constructor(urlSegments, paramMap) {
|
|
5989
|
-
this.paramMaps = [];
|
|
5990
|
-
// TODO: can we get all our params from teh url segments? If so we can drop the paramMap altogether.
|
|
5991
|
-
const segmentParams = (urlSegments || []).map(s => new ParamMapAdapter(s.parameters));
|
|
5992
|
-
this.paramMaps = segmentParams
|
|
5993
|
-
.concat(paramMap)
|
|
5994
|
-
.filter(m => !!m); // the activated route param map can be null
|
|
5995
|
-
}
|
|
5996
|
-
get(name) {
|
|
5997
|
-
const paramMap = this.paramMaps.find(m => m.has(name));
|
|
5998
|
-
return paramMap.get(name);
|
|
5999
|
-
}
|
|
6000
|
-
getAll(name) {
|
|
6001
|
-
const paramMap = this.paramMaps.find(m => m.has(name));
|
|
6002
|
-
return paramMap.getAll(name);
|
|
6003
|
-
}
|
|
6004
|
-
has(name) {
|
|
6005
|
-
return !!this.paramMaps.find(m => m.has(name));
|
|
6006
|
-
}
|
|
6007
|
-
get keys() {
|
|
6008
|
-
return this.paramMaps.reduce((result, params) => result.concat(params.keys), []);
|
|
6009
|
-
}
|
|
6010
|
-
}
|
|
6011
|
-
__decorate([
|
|
6012
|
-
Memoize(),
|
|
6013
|
-
__metadata("design:type", Array),
|
|
6014
|
-
__metadata("design:paramtypes", [])
|
|
6015
|
-
], ConsolidatedParameterMap.prototype, "keys", null);
|
|
6016
|
-
class ParamMapAdapter {
|
|
6017
|
-
constructor(params) {
|
|
6018
|
-
this.params = params;
|
|
6019
|
-
}
|
|
6020
|
-
get(name) {
|
|
6021
|
-
return this.params[name];
|
|
6022
|
-
}
|
|
6023
|
-
getAll(name) {
|
|
6024
|
-
const value = this.get(name);
|
|
6025
|
-
return Array.isArray(value) ? value : [value];
|
|
6026
|
-
}
|
|
6027
|
-
has(name) {
|
|
6028
|
-
return this.keys.includes(name);
|
|
6029
|
-
}
|
|
6030
|
-
get keys() {
|
|
6031
|
-
return Object.keys(this.params);
|
|
6032
|
-
}
|
|
6033
|
-
}
|
|
6034
|
-
|
|
6035
|
-
class Visit {
|
|
6036
|
-
constructor(placeDefinition, visitParameters = {}) {
|
|
6037
|
-
this.placeDefinition = placeDefinition;
|
|
6038
|
-
this.visitParameters = visitParameters;
|
|
6039
|
-
}
|
|
6040
|
-
// @Trace()
|
|
6041
|
-
getRouteId() {
|
|
6042
|
-
return this.placeDefinition.getRouteIdFrom(this);
|
|
6043
|
-
}
|
|
6044
|
-
// @Trace()
|
|
6045
|
-
hasRouteId() {
|
|
6046
|
-
return !_.isNil(this.getRouteId());
|
|
6047
|
-
}
|
|
6048
|
-
/**
|
|
6049
|
-
* Returns the value of the place parameter with the specified name. The parameter
|
|
6050
|
-
* name is taken from the `as` option, e.g. {as: 'aCustomName'} otherwise it is the
|
|
6051
|
-
* same as the the ValueModel property name.
|
|
6052
|
-
* @param parameterDef the visit parameter definition
|
|
6053
|
-
*/
|
|
6054
|
-
getParameterValue(parameterDef) {
|
|
6055
|
-
return this.visitParameters[parameterDef.name];
|
|
6056
|
-
}
|
|
6057
|
-
// @Trace()
|
|
6058
|
-
hasParameter(parameterDef) {
|
|
6059
|
-
return Object.keys(this.visitParameters).includes(parameterDef.name);
|
|
6060
|
-
}
|
|
6061
|
-
replace(parameter, value) {
|
|
6062
|
-
return new Visit(this.placeDefinition, Object.assign(Object.assign({}, this.visitParameters), { [parameter.name]: value }));
|
|
6063
|
-
}
|
|
6064
|
-
mergeRouteParameters(routeParams) {
|
|
6065
|
-
// todo: whitelist parameters.
|
|
6066
|
-
const routeParameterKeys = Object.keys(routeParams);
|
|
6067
|
-
const params = {};
|
|
6068
|
-
this.placeDefinition.getVisitParameterDefs().forEach(def => {
|
|
6069
|
-
if (def.isRouteId || def.isRouteParameter) {
|
|
6070
|
-
if (routeParameterKeys.includes(def.name)) {
|
|
6071
|
-
params[def.name] = routeParams[def.name];
|
|
6072
|
-
}
|
|
6073
|
-
}
|
|
6074
|
-
else {
|
|
6075
|
-
// copy non route params as is, but only if they already exist otherwise we'll inject nil values and break the
|
|
6076
|
-
// defaults and remember sanitisation process.
|
|
6077
|
-
const value = this.getParameterValue(def);
|
|
6078
|
-
if (this.hasParameter(def)) {
|
|
6079
|
-
params[def.name] = value;
|
|
6080
|
-
}
|
|
6081
|
-
}
|
|
6082
|
-
});
|
|
6083
|
-
return new Visit(this.placeDefinition, params);
|
|
6084
|
-
}
|
|
6085
|
-
hasRoutingChangedFrom(other) {
|
|
6086
|
-
const samePlace = other.placeDefinition === this.placeDefinition;
|
|
6087
|
-
const sameRouteParameters = _.isEqual(this.placeDefinition.getFormattedRouteParameters(this, true), this.placeDefinition.getFormattedRouteParameters(other, true));
|
|
6088
|
-
return !samePlace || !sameRouteParameters;
|
|
6089
|
-
}
|
|
6090
|
-
hasChangedFrom(other) {
|
|
6091
|
-
const sameNonRouteParameters = _.isEqual(this.placeDefinition.getNonRouteParameters(this), this.placeDefinition.getNonRouteParameters(other));
|
|
6092
|
-
return !sameNonRouteParameters || this.hasRoutingChangedFrom(other);
|
|
6093
|
-
}
|
|
6094
|
-
toDebugString() {
|
|
6095
|
-
return Object.keys(this.visitParameters).map(k => `${k}=${this.visitParameters[k]}`).join(',');
|
|
6096
|
-
}
|
|
6097
|
-
}
|
|
6098
|
-
|
|
6099
|
-
function extractPrimarySegments(urlTree) {
|
|
6100
|
-
return urlTree.root.children.primary.segments;
|
|
6101
|
-
}
|
|
6102
|
-
class UrlSnapshot {
|
|
6103
|
-
// TODO: Update this accept a url Parser so it can be immutable and generate new trees on mutation using toString() are parseUrl.
|
|
6104
|
-
constructor(urlSerializer, url) {
|
|
6105
|
-
this.urlSerializer = urlSerializer;
|
|
6106
|
-
this.url = url;
|
|
6107
|
-
this.urlTree = urlSerializer.parse(url);
|
|
6108
|
-
}
|
|
6109
|
-
updateVisitSegments(visit) {
|
|
6110
|
-
const newUrlTree = this.urlSerializer.parse(this.url);
|
|
6111
|
-
// Ugly, but it works for now.
|
|
6112
|
-
const segments = [...extractPrimarySegments(newUrlTree)];
|
|
6113
|
-
const visitSegments = this.getSegmentsFor(visit);
|
|
6114
|
-
const replaceAt = segments.findIndex(segment => segment.path === visitSegments[0].path);
|
|
6115
|
-
// do not use the return value, it's the items that were removed!
|
|
6116
|
-
segments.splice(replaceAt, visitSegments.length, ...visitSegments);
|
|
6117
|
-
newUrlTree.root.children.primary.segments = segments;
|
|
6118
|
-
return new UrlSnapshot(this.urlSerializer, newUrlTree.toString());
|
|
6119
|
-
}
|
|
6120
|
-
getPrimarySegments() {
|
|
6121
|
-
return extractPrimarySegments(this.urlTree);
|
|
6122
|
-
}
|
|
6123
|
-
/**
|
|
6124
|
-
* Converts the visit into segments. Please not that these segments are not e
|
|
6125
|
-
* @param visit
|
|
6126
|
-
*/
|
|
6127
|
-
getSegmentsFor(visit) {
|
|
6128
|
-
return visit.placeDefinition.hasRouteId() ?
|
|
6129
|
-
[
|
|
6130
|
-
// NOTE:
|
|
6131
|
-
// It's important to attach the params to the root path and not the id. If we attach them
|
|
6132
|
-
// to an empty id then the angular router won't match the pattern.
|
|
6133
|
-
new UrlSegment(visit.placeDefinition.path, visit.placeDefinition.getFormattedRouteParameters(visit)),
|
|
6134
|
-
new UrlSegment(visit.placeDefinition.getFormattedRouteId(visit), {})
|
|
6135
|
-
]
|
|
6136
|
-
:
|
|
6137
|
-
[
|
|
6138
|
-
new UrlSegment(visit.placeDefinition.path, visit.placeDefinition.getFormattedRouteParameters(visit))
|
|
6139
|
-
];
|
|
6140
|
-
}
|
|
6141
|
-
includesPathOf(placeDef) {
|
|
6142
|
-
return this.getPrimarySegments().find(s => s.path === placeDef.path);
|
|
6143
|
-
}
|
|
6144
|
-
createVisitFor(placeDef) {
|
|
6145
|
-
return new Visit(placeDef, new ConsolidatedParameterMap(this.getPrimarySegments()));
|
|
6146
|
-
}
|
|
6147
|
-
getInteractionIds() {
|
|
6148
|
-
const queryParam = this.urlTree.queryParams[UrlSnapshot.INTERACTION_QUERY_PARAM];
|
|
6149
|
-
if (queryParam) {
|
|
6150
|
-
return UrlSnapshot.parseInteractionIds(queryParam);
|
|
6151
|
-
}
|
|
6152
|
-
else {
|
|
6153
|
-
return [];
|
|
6154
|
-
}
|
|
6155
|
-
}
|
|
6156
|
-
hasInteractions() {
|
|
6157
|
-
return this.getInteractionIds().length > 0;
|
|
6158
|
-
}
|
|
6159
|
-
hasInteractionIds(ids) {
|
|
6160
|
-
return ___default.isEqual(this.getInteractionIds(), ids);
|
|
6161
|
-
}
|
|
6162
|
-
// @Trace()
|
|
6163
|
-
updateInteractionIds(ids) {
|
|
6164
|
-
if (ids.length === 0) {
|
|
6165
|
-
return this.removeInteractionIds();
|
|
6166
|
-
}
|
|
6167
|
-
else {
|
|
6168
|
-
const urlTree = this.urlSerializer.parse(this.url);
|
|
6169
|
-
urlTree.queryParams[UrlSnapshot.INTERACTION_QUERY_PARAM] = UrlSnapshot.createPathIdFor(ids);
|
|
6170
|
-
return new UrlSnapshot(this.urlSerializer, urlTree.toString());
|
|
6171
|
-
}
|
|
6172
|
-
}
|
|
6173
|
-
// @Trace()
|
|
6174
|
-
removeInteractionIds() {
|
|
6175
|
-
const urlTree = this.urlSerializer.parse(this.url);
|
|
6176
|
-
if (urlTree.queryParams && urlTree.queryParams[UrlSnapshot.INTERACTION_QUERY_PARAM]) {
|
|
6177
|
-
urlTree.queryParams = {}; //[UrlSnapshot.INTERACTION_ROUTER_OUTLET]
|
|
6178
|
-
}
|
|
6179
|
-
return new UrlSnapshot(this.urlSerializer, urlTree.toString());
|
|
6180
|
-
}
|
|
6181
|
-
toString() {
|
|
6182
|
-
return `UrlSnapshot(${this.url})`;
|
|
6183
|
-
}
|
|
6184
|
-
}
|
|
6185
|
-
__decorate([
|
|
6186
|
-
Trace(),
|
|
6187
|
-
__metadata("design:type", Function),
|
|
6188
|
-
__metadata("design:paramtypes", [Visit]),
|
|
6189
|
-
__metadata("design:returntype", UrlSnapshot)
|
|
6190
|
-
], UrlSnapshot.prototype, "updateVisitSegments", null);
|
|
6191
|
-
__decorate([
|
|
6192
|
-
Memoize(),
|
|
6193
|
-
__metadata("design:type", Function),
|
|
6194
|
-
__metadata("design:paramtypes", []),
|
|
6195
|
-
__metadata("design:returntype", Array)
|
|
6196
|
-
], UrlSnapshot.prototype, "getPrimarySegments", null);
|
|
6197
|
-
(function (UrlSnapshot) {
|
|
6198
|
-
UrlSnapshot.INTERACTION_QUERY_PARAM = 'aup-interactions';
|
|
6199
|
-
UrlSnapshot.INTERACTION_ID_SEPARATOR = '--';
|
|
6200
|
-
function parseInteractionIds(path) {
|
|
6201
|
-
return path.split(UrlSnapshot.INTERACTION_ID_SEPARATOR);
|
|
6202
|
-
}
|
|
6203
|
-
UrlSnapshot.parseInteractionIds = parseInteractionIds;
|
|
6204
|
-
function createPathIdFor(interactionIds) {
|
|
6205
|
-
return interactionIds.join(UrlSnapshot.INTERACTION_ID_SEPARATOR);
|
|
6206
|
-
}
|
|
6207
|
-
UrlSnapshot.createPathIdFor = createPathIdFor;
|
|
6208
|
-
})(UrlSnapshot || (UrlSnapshot = {}));
|
|
6209
|
-
|
|
6210
5982
|
/**
|
|
6211
5983
|
* This class handles the logic around canDeactivate for a given router state transition. It's core responsibilities are:
|
|
6212
5984
|
* 1. Ensure we only ask the component to deactivate once on a given navigation cycle (since visit sanitisation can result in multiple round trips to through the router.)
|
|
@@ -6243,6 +6015,7 @@ class PlaceComponentDeactivationHandler {
|
|
|
6243
6015
|
return this.canDeactivatePromise;
|
|
6244
6016
|
});
|
|
6245
6017
|
}
|
|
6018
|
+
// @Trace()
|
|
6246
6019
|
canDeactivateComponent(currentUrl, nextState) {
|
|
6247
6020
|
return __awaiter(this, void 0, void 0, function* () {
|
|
6248
6021
|
// Automatically cancel any active activities if the navigation session was triggered by the back button.
|
|
@@ -6290,12 +6063,6 @@ class PlaceComponentDeactivationHandler {
|
|
|
6290
6063
|
return !nextState.includesPathOf(this.component.placeDefinition);
|
|
6291
6064
|
}
|
|
6292
6065
|
}
|
|
6293
|
-
__decorate([
|
|
6294
|
-
Trace(),
|
|
6295
|
-
__metadata("design:type", Function),
|
|
6296
|
-
__metadata("design:paramtypes", [UrlSnapshot, UrlSnapshot]),
|
|
6297
|
-
__metadata("design:returntype", Promise)
|
|
6298
|
-
], PlaceComponentDeactivationHandler.prototype, "canDeactivateComponent", null);
|
|
6299
6066
|
|
|
6300
6067
|
/**
|
|
6301
6068
|
* Transient states
|
|
@@ -7125,6 +6892,234 @@ PlaceHistory.ctorParameters = () => [];
|
|
|
7125
6892
|
// }
|
|
7126
6893
|
})(PlaceHistory || (PlaceHistory = {}));
|
|
7127
6894
|
|
|
6895
|
+
/**
|
|
6896
|
+
* This a work around for the fact that an activated route with multiple segments doesn't
|
|
6897
|
+
* include the segment params in the paramMap as well as each segment returns an empty
|
|
6898
|
+
* param map even when `parameter`s has content.
|
|
6899
|
+
*/
|
|
6900
|
+
class ConsolidatedParameterMap {
|
|
6901
|
+
constructor(urlSegments, paramMap) {
|
|
6902
|
+
this.paramMaps = [];
|
|
6903
|
+
// TODO: can we get all our params from teh url segments? If so we can drop the paramMap altogether.
|
|
6904
|
+
const segmentParams = (urlSegments || []).map(s => new ParamMapAdapter(s.parameters));
|
|
6905
|
+
this.paramMaps = segmentParams
|
|
6906
|
+
.concat(paramMap)
|
|
6907
|
+
.filter(m => !!m); // the activated route param map can be null
|
|
6908
|
+
}
|
|
6909
|
+
get(name) {
|
|
6910
|
+
const paramMap = this.paramMaps.find(m => m.has(name));
|
|
6911
|
+
return paramMap.get(name);
|
|
6912
|
+
}
|
|
6913
|
+
getAll(name) {
|
|
6914
|
+
const paramMap = this.paramMaps.find(m => m.has(name));
|
|
6915
|
+
return paramMap.getAll(name);
|
|
6916
|
+
}
|
|
6917
|
+
has(name) {
|
|
6918
|
+
return !!this.paramMaps.find(m => m.has(name));
|
|
6919
|
+
}
|
|
6920
|
+
get keys() {
|
|
6921
|
+
return this.paramMaps.reduce((result, params) => result.concat(params.keys), []);
|
|
6922
|
+
}
|
|
6923
|
+
}
|
|
6924
|
+
__decorate([
|
|
6925
|
+
Memoize(),
|
|
6926
|
+
__metadata("design:type", Array),
|
|
6927
|
+
__metadata("design:paramtypes", [])
|
|
6928
|
+
], ConsolidatedParameterMap.prototype, "keys", null);
|
|
6929
|
+
class ParamMapAdapter {
|
|
6930
|
+
constructor(params) {
|
|
6931
|
+
this.params = params;
|
|
6932
|
+
}
|
|
6933
|
+
get(name) {
|
|
6934
|
+
return this.params[name];
|
|
6935
|
+
}
|
|
6936
|
+
getAll(name) {
|
|
6937
|
+
const value = this.get(name);
|
|
6938
|
+
return Array.isArray(value) ? value : [value];
|
|
6939
|
+
}
|
|
6940
|
+
has(name) {
|
|
6941
|
+
return this.keys.includes(name);
|
|
6942
|
+
}
|
|
6943
|
+
get keys() {
|
|
6944
|
+
return Object.keys(this.params);
|
|
6945
|
+
}
|
|
6946
|
+
}
|
|
6947
|
+
|
|
6948
|
+
class Visit {
|
|
6949
|
+
constructor(placeDefinition, visitParameters = {}) {
|
|
6950
|
+
this.placeDefinition = placeDefinition;
|
|
6951
|
+
this.visitParameters = visitParameters;
|
|
6952
|
+
}
|
|
6953
|
+
// @Trace()
|
|
6954
|
+
getRouteId() {
|
|
6955
|
+
return this.placeDefinition.getRouteIdFrom(this);
|
|
6956
|
+
}
|
|
6957
|
+
// @Trace()
|
|
6958
|
+
hasRouteId() {
|
|
6959
|
+
return !_.isNil(this.getRouteId());
|
|
6960
|
+
}
|
|
6961
|
+
/**
|
|
6962
|
+
* Returns the value of the place parameter with the specified name. The parameter
|
|
6963
|
+
* name is taken from the `as` option, e.g. {as: 'aCustomName'} otherwise it is the
|
|
6964
|
+
* same as the the ValueModel property name.
|
|
6965
|
+
* @param parameterDef the visit parameter definition
|
|
6966
|
+
*/
|
|
6967
|
+
getParameterValue(parameterDef) {
|
|
6968
|
+
return this.visitParameters[parameterDef.name];
|
|
6969
|
+
}
|
|
6970
|
+
// @Trace()
|
|
6971
|
+
hasParameter(parameterDef) {
|
|
6972
|
+
return Object.keys(this.visitParameters).includes(parameterDef.name);
|
|
6973
|
+
}
|
|
6974
|
+
replace(parameter, value) {
|
|
6975
|
+
return new Visit(this.placeDefinition, Object.assign(Object.assign({}, this.visitParameters), { [parameter.name]: value }));
|
|
6976
|
+
}
|
|
6977
|
+
mergeRouteParameters(routeParams) {
|
|
6978
|
+
// todo: whitelist parameters.
|
|
6979
|
+
const routeParameterKeys = Object.keys(routeParams);
|
|
6980
|
+
const params = {};
|
|
6981
|
+
this.placeDefinition.getVisitParameterDefs().forEach(def => {
|
|
6982
|
+
if (def.isRouteId || def.isRouteParameter) {
|
|
6983
|
+
if (routeParameterKeys.includes(def.name)) {
|
|
6984
|
+
params[def.name] = routeParams[def.name];
|
|
6985
|
+
}
|
|
6986
|
+
}
|
|
6987
|
+
else {
|
|
6988
|
+
// copy non route params as is, but only if they already exist otherwise we'll inject nil values and break the
|
|
6989
|
+
// defaults and remember sanitisation process.
|
|
6990
|
+
const value = this.getParameterValue(def);
|
|
6991
|
+
if (this.hasParameter(def)) {
|
|
6992
|
+
params[def.name] = value;
|
|
6993
|
+
}
|
|
6994
|
+
}
|
|
6995
|
+
});
|
|
6996
|
+
return new Visit(this.placeDefinition, params);
|
|
6997
|
+
}
|
|
6998
|
+
hasRoutingChangedFrom(other) {
|
|
6999
|
+
const samePlace = other.placeDefinition === this.placeDefinition;
|
|
7000
|
+
const sameRouteParameters = _.isEqual(this.placeDefinition.getFormattedRouteParameters(this, true), this.placeDefinition.getFormattedRouteParameters(other, true));
|
|
7001
|
+
return !samePlace || !sameRouteParameters;
|
|
7002
|
+
}
|
|
7003
|
+
hasChangedFrom(other) {
|
|
7004
|
+
const sameNonRouteParameters = _.isEqual(this.placeDefinition.getNonRouteParameters(this), this.placeDefinition.getNonRouteParameters(other));
|
|
7005
|
+
return !sameNonRouteParameters || this.hasRoutingChangedFrom(other);
|
|
7006
|
+
}
|
|
7007
|
+
toDebugString() {
|
|
7008
|
+
return Object.keys(this.visitParameters).map(k => `${k}=${this.visitParameters[k]}`).join(',');
|
|
7009
|
+
}
|
|
7010
|
+
}
|
|
7011
|
+
|
|
7012
|
+
function extractPrimarySegments(urlTree) {
|
|
7013
|
+
return urlTree.root.children.primary.segments;
|
|
7014
|
+
}
|
|
7015
|
+
class UrlSnapshot {
|
|
7016
|
+
// TODO: Update this accept a url Parser so it can be immutable and generate new trees on mutation using toString() are parseUrl.
|
|
7017
|
+
constructor(urlSerializer, url) {
|
|
7018
|
+
this.urlSerializer = urlSerializer;
|
|
7019
|
+
this.url = url;
|
|
7020
|
+
this.urlTree = urlSerializer.parse(url);
|
|
7021
|
+
}
|
|
7022
|
+
updateVisitSegments(visit) {
|
|
7023
|
+
const newUrlTree = this.urlSerializer.parse(this.url);
|
|
7024
|
+
// Ugly, but it works for now.
|
|
7025
|
+
const segments = [...extractPrimarySegments(newUrlTree)];
|
|
7026
|
+
const visitSegments = this.getSegmentsFor(visit);
|
|
7027
|
+
const replaceAt = segments.findIndex(segment => segment.path === visitSegments[0].path);
|
|
7028
|
+
// do not use the return value, it's the items that were removed!
|
|
7029
|
+
segments.splice(replaceAt, visitSegments.length, ...visitSegments);
|
|
7030
|
+
newUrlTree.root.children.primary.segments = segments;
|
|
7031
|
+
return new UrlSnapshot(this.urlSerializer, newUrlTree.toString());
|
|
7032
|
+
}
|
|
7033
|
+
getPrimarySegments() {
|
|
7034
|
+
return extractPrimarySegments(this.urlTree);
|
|
7035
|
+
}
|
|
7036
|
+
/**
|
|
7037
|
+
* Converts the visit into segments. Please not that these segments are not e
|
|
7038
|
+
* @param visit
|
|
7039
|
+
*/
|
|
7040
|
+
getSegmentsFor(visit) {
|
|
7041
|
+
return visit.placeDefinition.hasRouteId() ?
|
|
7042
|
+
[
|
|
7043
|
+
// NOTE:
|
|
7044
|
+
// It's important to attach the params to the root path and not the id. If we attach them
|
|
7045
|
+
// to an empty id then the angular router won't match the pattern.
|
|
7046
|
+
new UrlSegment(visit.placeDefinition.path, visit.placeDefinition.getFormattedRouteParameters(visit)),
|
|
7047
|
+
new UrlSegment(visit.placeDefinition.getFormattedRouteId(visit), {})
|
|
7048
|
+
]
|
|
7049
|
+
:
|
|
7050
|
+
[
|
|
7051
|
+
new UrlSegment(visit.placeDefinition.path, visit.placeDefinition.getFormattedRouteParameters(visit))
|
|
7052
|
+
];
|
|
7053
|
+
}
|
|
7054
|
+
includesPathOf(placeDef) {
|
|
7055
|
+
return this.getPrimarySegments().find(s => s.path === placeDef.path);
|
|
7056
|
+
}
|
|
7057
|
+
createVisitFor(placeDef) {
|
|
7058
|
+
return new Visit(placeDef, new ConsolidatedParameterMap(this.getPrimarySegments()));
|
|
7059
|
+
}
|
|
7060
|
+
getInteractionIds() {
|
|
7061
|
+
const queryParam = this.urlTree.queryParams[UrlSnapshot.INTERACTION_QUERY_PARAM];
|
|
7062
|
+
if (queryParam) {
|
|
7063
|
+
return UrlSnapshot.parseInteractionIds(queryParam);
|
|
7064
|
+
}
|
|
7065
|
+
else {
|
|
7066
|
+
return [];
|
|
7067
|
+
}
|
|
7068
|
+
}
|
|
7069
|
+
hasInteractions() {
|
|
7070
|
+
return this.getInteractionIds().length > 0;
|
|
7071
|
+
}
|
|
7072
|
+
hasInteractionIds(ids) {
|
|
7073
|
+
return ___default.isEqual(this.getInteractionIds(), ids);
|
|
7074
|
+
}
|
|
7075
|
+
// @Trace()
|
|
7076
|
+
updateInteractionIds(ids) {
|
|
7077
|
+
if (ids.length === 0) {
|
|
7078
|
+
return this.removeInteractionIds();
|
|
7079
|
+
}
|
|
7080
|
+
else {
|
|
7081
|
+
const urlTree = this.urlSerializer.parse(this.url);
|
|
7082
|
+
urlTree.queryParams[UrlSnapshot.INTERACTION_QUERY_PARAM] = UrlSnapshot.createPathIdFor(ids);
|
|
7083
|
+
return new UrlSnapshot(this.urlSerializer, urlTree.toString());
|
|
7084
|
+
}
|
|
7085
|
+
}
|
|
7086
|
+
// @Trace()
|
|
7087
|
+
removeInteractionIds() {
|
|
7088
|
+
const urlTree = this.urlSerializer.parse(this.url);
|
|
7089
|
+
if (urlTree.queryParams && urlTree.queryParams[UrlSnapshot.INTERACTION_QUERY_PARAM]) {
|
|
7090
|
+
urlTree.queryParams = {}; //[UrlSnapshot.INTERACTION_ROUTER_OUTLET]
|
|
7091
|
+
}
|
|
7092
|
+
return new UrlSnapshot(this.urlSerializer, urlTree.toString());
|
|
7093
|
+
}
|
|
7094
|
+
toString() {
|
|
7095
|
+
return `UrlSnapshot(${this.url})`;
|
|
7096
|
+
}
|
|
7097
|
+
}
|
|
7098
|
+
__decorate([
|
|
7099
|
+
Trace(),
|
|
7100
|
+
__metadata("design:type", Function),
|
|
7101
|
+
__metadata("design:paramtypes", [Visit]),
|
|
7102
|
+
__metadata("design:returntype", UrlSnapshot)
|
|
7103
|
+
], UrlSnapshot.prototype, "updateVisitSegments", null);
|
|
7104
|
+
__decorate([
|
|
7105
|
+
Memoize(),
|
|
7106
|
+
__metadata("design:type", Function),
|
|
7107
|
+
__metadata("design:paramtypes", []),
|
|
7108
|
+
__metadata("design:returntype", Array)
|
|
7109
|
+
], UrlSnapshot.prototype, "getPrimarySegments", null);
|
|
7110
|
+
(function (UrlSnapshot) {
|
|
7111
|
+
UrlSnapshot.INTERACTION_QUERY_PARAM = 'aup-interactions';
|
|
7112
|
+
UrlSnapshot.INTERACTION_ID_SEPARATOR = '--';
|
|
7113
|
+
function parseInteractionIds(path) {
|
|
7114
|
+
return path.split(UrlSnapshot.INTERACTION_ID_SEPARATOR);
|
|
7115
|
+
}
|
|
7116
|
+
UrlSnapshot.parseInteractionIds = parseInteractionIds;
|
|
7117
|
+
function createPathIdFor(interactionIds) {
|
|
7118
|
+
return interactionIds.join(UrlSnapshot.INTERACTION_ID_SEPARATOR);
|
|
7119
|
+
}
|
|
7120
|
+
UrlSnapshot.createPathIdFor = createPathIdFor;
|
|
7121
|
+
})(UrlSnapshot || (UrlSnapshot = {}));
|
|
7122
|
+
|
|
7128
7123
|
class UrlService {
|
|
7129
7124
|
constructor(angularRouter, angularLocation, urlSerializer) {
|
|
7130
7125
|
this.angularRouter = angularRouter;
|