ng-easycommerce 1.1.3 → 1.1.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/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ # Version 1.1.4
2
+ - Navegación: `AddActionRedirectDirective` normaliza URLs absolutas del mismo origen para el Angular Router, respeta el `base href` y conserva query parameters y fragmentos.
3
+ - Navegación: se mantiene el comportamiento nativo para clics modificados, botón central y enlaces con `target` explícito.
4
+
1
5
  # Version 1.1.3
2
6
  - Carrito: se incorpora la recuperación ante `409 CART_NOT_ACTIVE`; la mutación rechazada se cancela, el carrito activo se recupera automáticamente y la operación original no se reintenta.
3
7
  - Carrito: las pestañas del mismo navegador actualizan el resumen desde backend mediante señales de invalidación, con protección frente a eventos y respuestas obsoletas.
@@ -27130,19 +27130,20 @@
27130
27130
  return ParamsContext;
27131
27131
  }());
27132
27132
  var AddActionRedirectDirective = /** @class */ (function () {
27133
- function AddActionRedirectDirective(document, elementRef, renderer, blocksService, router) {
27134
- var _this = this;
27133
+ function AddActionRedirectDirective(document, elementRef, renderer, blocksService, router, locationStrategy) {
27135
27134
  this.document = document;
27136
27135
  this.elementRef = elementRef;
27137
27136
  this.renderer = renderer;
27138
27137
  this.blocksService = blocksService;
27139
27138
  this.router = router;
27139
+ this.locationStrategy = locationStrategy;
27140
27140
  this.redirectUrl = '';
27141
27141
  this.linstenEvent = null;
27142
27142
  this.transparent = true;
27143
- this.redirectFromUrl = function (evt) {
27144
- _this.router.navigateByUrl(_this.redirectUrl);
27145
- };
27143
+ this.targetManaged = false;
27144
+ this.originalTarget = null;
27145
+ this.relManaged = false;
27146
+ this.originalRel = null;
27146
27147
  }
27147
27148
  Object.defineProperty(AddActionRedirectDirective.prototype, "ecAddActionRedirect", {
27148
27149
  set: function (value) {
@@ -27169,10 +27170,19 @@
27169
27170
  AddActionRedirectDirective.prototype.ngOnChanges = function (changes) {
27170
27171
  var _this = this;
27171
27172
  var _a;
27173
+ var element = this.elementRef.nativeElement;
27174
+ var target = this.targetManaged ? this.originalTarget : element.getAttribute('target');
27175
+ var rel = this.relManaged ? this.originalRel : element.getAttribute('rel');
27172
27176
  if (this.linstenEvent) {
27173
27177
  this.linstenEvent();
27174
27178
  this.linstenEvent = null;
27175
27179
  }
27180
+ this.restoreManagedAttribute('target', this.targetManaged, this.originalTarget);
27181
+ this.restoreManagedAttribute('rel', this.relManaged, this.originalRel);
27182
+ this.targetManaged = false;
27183
+ this.originalTarget = null;
27184
+ this.relManaged = false;
27185
+ this.originalRel = null;
27176
27186
  this.transparent && this.renderer.setStyle(this.elementRef.nativeElement, 'color', 'transparent');
27177
27187
  (_a = this.classStr) === null || _a === void 0 ? void 0 : _a.split(" ").forEach(function (cl) {
27178
27188
  try {
@@ -27187,18 +27197,101 @@
27187
27197
  if (accessibleLabel) {
27188
27198
  this.renderer.setAttribute(this.elementRef.nativeElement, 'aria-label', accessibleLabel);
27189
27199
  }
27190
- this.renderer.setProperty(this.elementRef.nativeElement, "href", this.redirectUrl);
27191
27200
  if (this.isExternalUrl(this.redirectUrl)) {
27192
- this.renderer.setAttribute(this.elementRef.nativeElement, "target", "_blank");
27193
- this.renderer.setAttribute(this.elementRef.nativeElement, "rel", "noopener noreferrer");
27201
+ this.renderer.setProperty(element, "href", this.redirectUrl);
27202
+ var effectiveTarget = target === null ? '_blank' : target;
27203
+ if (target === null) {
27204
+ this.renderer.setAttribute(element, "target", "_blank");
27205
+ this.targetManaged = true;
27206
+ this.originalTarget = null;
27207
+ }
27208
+ if (effectiveTarget.trim().toLowerCase() === '_blank') {
27209
+ var relTokens = (rel || '').split(/\s+/).filter(Boolean);
27210
+ var existingRelTokens = relTokens.map(function (token) { return token.toLowerCase(); });
27211
+ if (existingRelTokens.indexOf('noopener') === -1)
27212
+ relTokens.push('noopener');
27213
+ if (existingRelTokens.indexOf('noreferrer') === -1)
27214
+ relTokens.push('noreferrer');
27215
+ var secureRel = relTokens.join(' ');
27216
+ if (secureRel !== rel) {
27217
+ this.renderer.setAttribute(element, "rel", secureRel);
27218
+ this.relManaged = true;
27219
+ this.originalRel = rel;
27220
+ }
27221
+ }
27194
27222
  }
27195
27223
  else {
27196
- this.renderer.removeAttribute(this.elementRef.nativeElement, "target");
27197
- this.renderer.removeAttribute(this.elementRef.nativeElement, "rel");
27198
- this.linstenEvent = this.renderer.listen(this.elementRef.nativeElement, 'click', function (evt) {
27199
- evt.preventDefault();
27200
- _this.redirectFromUrl(evt);
27201
- });
27224
+ var routerUrl_1 = this.toRouterUrl(this.redirectUrl);
27225
+ this.renderer.setProperty(element, "href", this.locationStrategy.prepareExternalUrl(routerUrl_1));
27226
+ if (target === null) {
27227
+ this.linstenEvent = this.renderer.listen(element, 'click', function (evt) {
27228
+ if (!_this.shouldHandleSpaClick(evt))
27229
+ return;
27230
+ evt.preventDefault();
27231
+ _this.router.navigateByUrl(routerUrl_1);
27232
+ });
27233
+ }
27234
+ }
27235
+ };
27236
+ AddActionRedirectDirective.prototype.shouldHandleSpaClick = function (event) {
27237
+ return !event.defaultPrevented && event.button === 0 &&
27238
+ !event.ctrlKey && !event.metaKey && !event.shiftKey && !event.altKey;
27239
+ };
27240
+ AddActionRedirectDirective.prototype.toRouterUrl = function (url) {
27241
+ var routerUrl;
27242
+ if (this.isAbsoluteUrl(url) || url.startsWith('#') || url.startsWith('?')) {
27243
+ var target = new URL(url, this.getDocumentHref());
27244
+ routerUrl = target.pathname + target.search + target.hash;
27245
+ }
27246
+ else {
27247
+ routerUrl = this.router.serializeUrl(this.router.parseUrl(url));
27248
+ }
27249
+ return this.stripBaseHref(routerUrl);
27250
+ };
27251
+ AddActionRedirectDirective.prototype.stripBaseHref = function (url) {
27252
+ var pathEnd = url.search(/[?#]/);
27253
+ var path = pathEnd === -1 ? url : url.substring(0, pathEnd);
27254
+ var suffix = pathEnd === -1 ? '' : url.substring(pathEnd);
27255
+ var baseHref = this.locationStrategy.getBaseHref();
27256
+ if (!baseHref)
27257
+ return url;
27258
+ try {
27259
+ var current = new URL(this.getDocumentHref());
27260
+ var base = new URL(baseHref, current.href);
27261
+ var basePath = base.origin === current.origin ? base.pathname : '';
27262
+ basePath = basePath.replace(/\/index\.html$/i, '').replace(/\/+$/, '');
27263
+ if (!basePath || basePath === '/')
27264
+ return url;
27265
+ if (path === basePath)
27266
+ return '/' + suffix;
27267
+ if (path.indexOf(basePath + '/') === 0) {
27268
+ return path.substring(basePath.length) + suffix;
27269
+ }
27270
+ }
27271
+ catch (e) {
27272
+ // Keep the URL unchanged when the browser cannot resolve the base href.
27273
+ }
27274
+ return url;
27275
+ };
27276
+ AddActionRedirectDirective.prototype.getDocumentHref = function () {
27277
+ var location = this.document && this.document.location;
27278
+ if (location && location.href)
27279
+ return location.href;
27280
+ if (location && location.origin)
27281
+ return location.origin + '/';
27282
+ return 'http://localhost/';
27283
+ };
27284
+ AddActionRedirectDirective.prototype.isAbsoluteUrl = function (url) {
27285
+ return /^[a-z][a-z\d+.-]*:/i.test(url) || url.indexOf('//') === 0;
27286
+ };
27287
+ AddActionRedirectDirective.prototype.restoreManagedAttribute = function (name, managed, originalValue) {
27288
+ if (!managed)
27289
+ return;
27290
+ if (originalValue === null) {
27291
+ this.renderer.removeAttribute(this.elementRef.nativeElement, name);
27292
+ }
27293
+ else {
27294
+ this.renderer.setAttribute(this.elementRef.nativeElement, name, originalValue);
27202
27295
  }
27203
27296
  };
27204
27297
  AddActionRedirectDirective.prototype.getAccessibleLabel = function () {
@@ -27218,22 +27311,36 @@
27218
27311
  return ((_k = (_j = this.banner) === null || _j === void 0 ? void 0 : _j.name) === null || _k === void 0 ? void 0 : _k.trim()) || 'Ver más';
27219
27312
  };
27220
27313
  AddActionRedirectDirective.prototype.isExternalUrl = function (url) {
27221
- var _a, _b;
27222
- if (!url)
27223
- return false;
27224
- if (url.startsWith('/') || url.startsWith('#'))
27314
+ if (!url || !this.isAbsoluteUrl(url))
27225
27315
  return false;
27226
27316
  try {
27227
- var base = ((_b = (_a = this.document) === null || _a === void 0 ? void 0 : _a.location) === null || _b === void 0 ? void 0 : _b.origin) || '';
27228
- var target = new URL(url, base);
27229
- if (!base)
27317
+ var current = new URL(this.getDocumentHref());
27318
+ var target = new URL(url, current.href);
27319
+ if (target.origin !== current.origin)
27230
27320
  return true;
27231
- return target.origin !== base;
27321
+ return this.isOutsideBaseHref(target.pathname, current);
27232
27322
  }
27233
27323
  catch (e) {
27234
27324
  return true;
27235
27325
  }
27236
27326
  };
27327
+ AddActionRedirectDirective.prototype.isOutsideBaseHref = function (pathname, current) {
27328
+ var baseHref = this.locationStrategy.getBaseHref();
27329
+ if (!baseHref)
27330
+ return false;
27331
+ try {
27332
+ var base = new URL(baseHref, current.href);
27333
+ if (base.origin !== current.origin)
27334
+ return false;
27335
+ var basePath = base.pathname.replace(/\/index\.html$/i, '').replace(/\/+$/, '');
27336
+ if (!basePath || basePath === '/')
27337
+ return false;
27338
+ return pathname !== basePath && pathname.indexOf(basePath + '/') !== 0;
27339
+ }
27340
+ catch (e) {
27341
+ return false;
27342
+ }
27343
+ };
27237
27344
  AddActionRedirectDirective.prototype.ngOnDestroy = function () {
27238
27345
  this.linstenEvent && this.linstenEvent();
27239
27346
  };
@@ -27242,7 +27349,8 @@
27242
27349
  { type: core.ElementRef },
27243
27350
  { type: core.Renderer2 },
27244
27351
  { type: BlocksService },
27245
- { type: router.Router }
27352
+ { type: router.Router },
27353
+ { type: common.LocationStrategy }
27246
27354
  ]; };
27247
27355
  __decorate$2a([
27248
27356
  core.Input()