@c8y/ngx-components 1023.14.203 → 1023.14.206

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.
@@ -3,7 +3,7 @@ import { Input, Directive, createEnvironmentInjector, InjectionToken, Optional,
3
3
  import * as i1$3 from 'ngx-bootstrap/dropdown';
4
4
  import { BsDropdownModule, BsDropdownDirective } from 'ngx-bootstrap/dropdown';
5
5
  import { CdkTrapFocus, A11yModule } from '@angular/cdk/a11y';
6
- import { castArray, flatten, uniq, sortBy, groupBy, camelCase, isEqual, isUndefined, throttle as throttle$1, each, mapValues, mapKeys, keys, get, isNaN as isNaN$1, isFinite, forEach, assign, min, every, first, map as map$1, find, negate, upperFirst, memoize as memoize$1, isEmpty, property, some, entries, omitBy, isDate, pick, flatMap, orderBy, filter as filter$2, snakeCase, matches, escape, escapeRegExp, assignWith, set, toNumber, isEqualWith, clone, omit, cloneDeep, uniqBy, has, transform, identity, unset, flow, findIndex as findIndex$1, isNil, chunk, values, union, without, indexOf, kebabCase, forOwn } from 'lodash-es';
6
+ import { castArray, flatten, uniq, sortBy, groupBy, camelCase, isEqual, isUndefined, throttle as throttle$1, each, mapValues, mapKeys, keys, get, isNaN as isNaN$1, isFinite, forEach, assign, min, every, first, map as map$1, find, negate, upperFirst, memoize as memoize$1, isEmpty, property, some, entries, omitBy, isDate, pick, flatMap, orderBy, filter as filter$2, snakeCase, matches, isNil, escape, escapeRegExp, assignWith, set, toNumber, isEqualWith, clone, omit, cloneDeep, uniqBy, has, transform, identity, unset, flow, findIndex as findIndex$1, chunk, values, union, without, indexOf, kebabCase, forOwn } from 'lodash-es';
7
7
  import { merge, of, defer, combineLatest, race, isObservable, from, Subject, BehaviorSubject, ReplaySubject, firstValueFrom, lastValueFrom, NEVER, Observable, startWith as startWith$1, filter as filter$1, tap as tap$1, mergeMap, fromEvent, pipe, throwError, concat, map as map$2, fromEventPattern, withLatestFrom, distinctUntilChanged as distinctUntilChanged$1, takeUntil as takeUntil$1, catchError as catchError$1, empty, timer, forkJoin, interval, shareReplay as shareReplay$1, switchMap as switchMap$1 } from 'rxjs';
8
8
  import { map, distinctUntilChanged, filter, startWith, switchMap, shareReplay, take, scan, takeUntil, tap, catchError, debounceTime, share, first as first$1, retryWhen, delay, concatMap, debounce, sample, withLatestFrom as withLatestFrom$1, mergeMap as mergeMap$1, every as every$1, toArray, merge as merge$1, expand, mapTo, skip, reduce, finalize, combineLatestWith } from 'rxjs/operators';
9
9
  import * as i1 from '@c8y/client';
@@ -13294,8 +13294,24 @@ class DocsService extends ExtensionPointWithoutStateForPlugins {
13294
13294
  this.DEFAULT_DOCS_BASE_URL = 'https://cumulocity.com';
13295
13295
  this.items$ = this.setupItemsObservable();
13296
13296
  }
13297
+ /**
13298
+ * Indicates whether documentation links should be displayed at all. Setting `docsBaseUrl` to
13299
+ * `null` or to an empty string switches the links off, whereas `'/'` keeps them enabled and
13300
+ * resolves to links relative to the host the application is served from.
13301
+ */
13302
+ isDocsEnabled() {
13303
+ const docsBaseUrl = this.options.get('docsBaseUrl', this.DEFAULT_DOCS_BASE_URL);
13304
+ return !isNil(docsBaseUrl) && docsBaseUrl !== '';
13305
+ }
13306
+ /**
13307
+ * Returns the base URL for documentation links, or `null` if the links are switched off with
13308
+ * `docsBaseUrl: null`.
13309
+ */
13297
13310
  getBaseUrl(uiVersion) {
13298
13311
  const docsBaseUrl = this.options.get('docsBaseUrl', this.DEFAULT_DOCS_BASE_URL);
13312
+ if (isNil(docsBaseUrl)) {
13313
+ return null;
13314
+ }
13299
13315
  return this.getUrlWithDocsVersion(docsBaseUrl, uiVersion);
13300
13316
  }
13301
13317
  /**
@@ -13316,11 +13332,15 @@ class DocsService extends ExtensionPointWithoutStateForPlugins {
13316
13332
  get templateStr() {
13317
13333
  return this.options.get('guideHrefTemplate', '${docsBaseUrl}${partialUrl}');
13318
13334
  }
13335
+ /**
13336
+ * Builds a link to a documentation page, or returns `null` if documentation links are switched
13337
+ * off. Absolute links are returned as they are.
13338
+ */
13319
13339
  getUserGuideLink(link) {
13320
13340
  if (/^https?:/.test(link)) {
13321
13341
  return link;
13322
13342
  }
13323
- if (this.getBaseUrl === null) {
13343
+ if (!this.isDocsEnabled()) {
13324
13344
  return null;
13325
13345
  }
13326
13346
  return this.getLink(this.templateStr, link);
@@ -13337,7 +13357,7 @@ class DocsService extends ExtensionPointWithoutStateForPlugins {
13337
13357
  ? []
13338
13358
  : documentationItems
13339
13359
  .map((item) => ({ ...item, url: this.getUserGuideLink(item.url) }))
13340
- .filter(({ url }) => !excludeDefault.some(e => new RegExp(e).test(url)));
13360
+ .filter(({ url }) => !!url && !excludeDefault.some(e => new RegExp(e).test(url)));
13341
13361
  if (links) {
13342
13362
  // backwards compatibility
13343
13363
  links.map((lnk) => {
@@ -25806,19 +25826,26 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.25", ngImpo
25806
25826
  }], ctorParameters: () => [{ type: RouterService }] });
25807
25827
 
25808
25828
  class GuideHrefDirective {
25809
- set baseHref(href) {
25810
- this.htmlAnchor.href = `${href}/${this.c8yGuideHref}`;
25811
- }
25812
- constructor(elementRef) {
25829
+ constructor(elementRef, docsService) {
25813
25830
  this.elementRef = elementRef;
25831
+ this.docsService = docsService;
25814
25832
  this.htmlAnchor = this.elementRef.nativeElement;
25815
25833
  if (!this.htmlAnchor.hasAttribute('target')) {
25816
25834
  this.htmlAnchor.setAttribute('target', '_blank');
25817
25835
  this.htmlAnchor.setAttribute('rel', 'noopener noreferrer');
25818
25836
  }
25819
25837
  }
25820
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: GuideHrefDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); }
25821
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.25", type: GuideHrefDirective, isStandalone: true, selector: "[c8y-guide-href]", inputs: { c8yGuideHref: ["c8y-guide-href", "c8yGuideHref"] }, ngImport: i0 }); }
25838
+ ngOnChanges() {
25839
+ const guideHref = this.docsService.getUserGuideLink(this.c8yGuideHref);
25840
+ if (!guideHref) {
25841
+ // documentation links are switched off, or no link can be built from `guideHrefTemplate`
25842
+ this.htmlAnchor.removeAttribute('href');
25843
+ return;
25844
+ }
25845
+ this.htmlAnchor.href = guideHref;
25846
+ }
25847
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: GuideHrefDirective, deps: [{ token: i0.ElementRef }, { token: DocsService }], target: i0.ɵɵFactoryTarget.Directive }); }
25848
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.25", type: GuideHrefDirective, isStandalone: true, selector: "[c8y-guide-href]", inputs: { c8yGuideHref: ["c8y-guide-href", "c8yGuideHref"] }, usesOnChanges: true, ngImport: i0 }); }
25822
25849
  }
25823
25850
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: GuideHrefDirective, decorators: [{
25824
25851
  type: Directive,
@@ -25826,7 +25853,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.25", ngImpo
25826
25853
  selector: '[c8y-guide-href]',
25827
25854
  standalone: true
25828
25855
  }]
25829
- }], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { c8yGuideHref: [{
25856
+ }], ctorParameters: () => [{ type: i0.ElementRef }, { type: DocsService }], propDecorators: { c8yGuideHref: [{
25830
25857
  type: Input,
25831
25858
  args: ['c8y-guide-href']
25832
25859
  }] } });
@@ -25845,12 +25872,14 @@ class GuideDocsComponent {
25845
25872
  this.docs = docs;
25846
25873
  this.el = el;
25847
25874
  this.renderer = renderer;
25875
+ /**
25876
+ * Whether the projected content should be displayed. It only becomes `true` once the anchor
25877
+ * attributes have been resolved, and stays `false` if documentation links are switched off.
25878
+ */
25879
+ this.ready = false;
25848
25880
  this.destroyed$ = new ReplaySubject(1);
25849
25881
  this.translateDirective = translateDirective;
25850
25882
  }
25851
- ngOnInit() {
25852
- this.baseUrl = this.docs.getBaseUrl();
25853
- }
25854
25883
  /**
25855
25884
  * After content is initialized we subscribe for translation events, then we are able to modify
25856
25885
  * anchor just as C8yGuideHrefDirective does.
@@ -25864,9 +25893,7 @@ class GuideDocsComponent {
25864
25893
  else {
25865
25894
  this.replaceAnchorAttributes();
25866
25895
  }
25867
- this.links.forEach(guide => {
25868
- guide.baseHref = this.baseUrl;
25869
- });
25896
+ this.ready = this.docs.isDocsEnabled();
25870
25897
  }
25871
25898
  /**
25872
25899
  * Find and modify anchor elements
@@ -25874,7 +25901,12 @@ class GuideDocsComponent {
25874
25901
  replaceAnchorAttributes() {
25875
25902
  const anchors = this.findGuideAnchors(this.el.nativeElement);
25876
25903
  anchors.forEach(a => {
25877
- const guideHref = `${this.baseUrl}/${a.getAttribute('c8y-guide-href')}`;
25904
+ const guideHref = this.docs.getUserGuideLink(a.getAttribute('c8y-guide-href'));
25905
+ if (!guideHref) {
25906
+ // e.g. `guideHrefTemplate` is empty, so no link can be built: keep the text, drop the link
25907
+ this.renderer.removeAttribute(a, 'href');
25908
+ return;
25909
+ }
25878
25910
  this.renderer.setAttribute(a, 'href', guideHref);
25879
25911
  if (!a.hasAttribute('target')) {
25880
25912
  this.renderer.setAttribute(a, 'target', '_blank');
@@ -25908,17 +25940,14 @@ class GuideDocsComponent {
25908
25940
  this.destroyed$.complete();
25909
25941
  }
25910
25942
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: GuideDocsComponent, deps: [{ token: DocsService }, { token: i0.ElementRef }, { token: i0.Renderer2 }, { token: C8yTranslateDirective, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
25911
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.25", type: GuideDocsComponent, isStandalone: true, selector: "[c8y-guide-docs]", queries: [{ propertyName: "translateDirective", first: true, predicate: C8yTranslateDirective, descendants: true, static: true }, { propertyName: "links", predicate: GuideHrefDirective, descendants: true }], ngImport: i0, template: "<ng-container *ngIf=\"!!baseUrl\">\n <ng-content></ng-content>\n</ng-container>\n", dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] }); }
25943
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.3.25", type: GuideDocsComponent, isStandalone: true, selector: "[c8y-guide-docs]", queries: [{ propertyName: "translateDirective", first: true, predicate: C8yTranslateDirective, descendants: true, static: true }], ngImport: i0, template: "@if (ready) {\n <ng-content></ng-content>\n}\n" }); }
25912
25944
  }
25913
25945
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.25", ngImport: i0, type: GuideDocsComponent, decorators: [{
25914
25946
  type: Component,
25915
- args: [{ selector: '[c8y-guide-docs]', standalone: true, imports: [NgIf], template: "<ng-container *ngIf=\"!!baseUrl\">\n <ng-content></ng-content>\n</ng-container>\n" }]
25947
+ args: [{ selector: '[c8y-guide-docs]', standalone: true, template: "@if (ready) {\n <ng-content></ng-content>\n}\n" }]
25916
25948
  }], ctorParameters: () => [{ type: DocsService }, { type: i0.ElementRef }, { type: i0.Renderer2 }, { type: C8yTranslateDirective, decorators: [{
25917
25949
  type: Optional
25918
- }] }], propDecorators: { links: [{
25919
- type: ContentChildren,
25920
- args: [GuideHrefDirective, { descendants: true }]
25921
- }], translateDirective: [{
25950
+ }] }], propDecorators: { translateDirective: [{
25922
25951
  type: ContentChild,
25923
25952
  args: [C8yTranslateDirective, { static: true }]
25924
25953
  }] } });