Ignore:
Timestamp:
10/16/21 18:10:51 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
eed0bf8
Parents:
6a3a178
Message:

adding new components

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/node_modules/@angular/material/bundles/material-badge.umd.js

    r6a3a178 rfa375fe  
    331331        return class_1;
    332332    }()));
    333     var BADGE_CONTENT_CLASS = 'mat-badge-content';
    334333    /** Directive to display a text badge. */
    335334    var MatBadge = /** @class */ (function (_super) {
     
    342341            _this._renderer = _renderer;
    343342            _this._animationMode = _animationMode;
     343            /** Whether the badge has any content. */
     344            _this._hasContent = false;
    344345            _this._color = 'primary';
    345346            _this._overlap = true;
     
    353354            /** Unique id for the badge */
    354355            _this._id = nextId++;
    355             /** Whether the OnInit lifecycle hook has run yet */
    356             _this._isInitialized = false;
    357356            if (typeof ngDevMode === 'undefined' || ngDevMode) {
    358357                var nativeElement = _elementRef.nativeElement;
     
    382381            configurable: true
    383382        });
    384         Object.defineProperty(MatBadge.prototype, "content", {
    385             /** The content for the badge */
    386             get: function () {
    387                 return this._content;
    388             },
    389             set: function (newContent) {
    390                 this._updateRenderedContent(newContent);
    391             },
    392             enumerable: false,
    393             configurable: true
    394         });
    395383        Object.defineProperty(MatBadge.prototype, "description", {
    396384            /** Message used to describe the decorated element via aria-describedby */
    397385            get: function () { return this._description; },
    398386            set: function (newDescription) {
    399                 this._updateHostAriaDescription(newDescription);
     387                if (newDescription !== this._description) {
     388                    var badgeElement = this._badgeElement;
     389                    this._updateHostAriaDescription(newDescription, this._description);
     390                    this._description = newDescription;
     391                    if (badgeElement) {
     392                        newDescription ? badgeElement.setAttribute('aria-label', newDescription) :
     393                            badgeElement.removeAttribute('aria-label');
     394                    }
     395                }
    400396            },
    401397            enumerable: false,
     
    419415            return this.position.indexOf('before') === -1;
    420416        };
     417        MatBadge.prototype.ngOnChanges = function (changes) {
     418            var contentChange = changes['content'];
     419            if (contentChange) {
     420                var value = contentChange.currentValue;
     421                this._hasContent = value != null && ("" + value).trim().length > 0;
     422                this._updateTextContent();
     423            }
     424        };
     425        MatBadge.prototype.ngOnDestroy = function () {
     426            var badgeElement = this._badgeElement;
     427            if (badgeElement) {
     428                if (this.description) {
     429                    this._ariaDescriber.removeDescription(badgeElement, this.description);
     430                }
     431                // When creating a badge through the Renderer, Angular will keep it in an index.
     432                // We have to destroy it ourselves, otherwise it'll be retained in memory.
     433                if (this._renderer.destroyNode) {
     434                    this._renderer.destroyNode(badgeElement);
     435                }
     436            }
     437        };
    421438        /**
    422          * Gets the element into which the badge's content is being rendered. Undefined if the element
    423          * hasn't been created (e.g. if the badge doesn't have content).
     439         * Gets the element into which the badge's content is being rendered.
     440         * Undefined if the element hasn't been created (e.g. if the badge doesn't have content).
    424441         */
    425442        MatBadge.prototype.getBadgeElement = function () {
    426443            return this._badgeElement;
    427444        };
    428         MatBadge.prototype.ngOnInit = function () {
    429             // We may have server-side rendered badge that we need to clear.
    430             // We need to do this in ngOnInit because the full content of the component
    431             // on which the badge is attached won't necessarily be in the DOM until this point.
    432             this._clearExistingBadges();
    433             if (this.content && !this._badgeElement) {
     445        /** Injects a span element into the DOM with the content. */
     446        MatBadge.prototype._updateTextContent = function () {
     447            if (!this._badgeElement) {
    434448                this._badgeElement = this._createBadgeElement();
    435                 this._updateRenderedContent(this.content);
    436             }
    437             this._isInitialized = true;
    438         };
    439         MatBadge.prototype.ngOnDestroy = function () {
    440             // ViewEngine only: when creating a badge through the Renderer, Angular remembers its index.
    441             // We have to destroy it ourselves, otherwise it'll be retained in memory.
    442             if (this._renderer.destroyNode) {
    443                 this._renderer.destroyNode(this._badgeElement);
    444             }
    445             this._ariaDescriber.removeDescription(this._elementRef.nativeElement, this.description);
     449            }
     450            else {
     451                this._badgeElement.textContent = this._stringifyContent();
     452            }
     453            return this._badgeElement;
    446454        };
    447455        /** Creates the badge element */
     
    449457            var badgeElement = this._renderer.createElement('span');
    450458            var activeClass = 'mat-badge-active';
     459            var contentClass = 'mat-badge-content';
     460            // Clear any existing badges which may have persisted from a server-side render.
     461            this._clearExistingBadges(contentClass);
    451462            badgeElement.setAttribute('id', "mat-badge-content-" + this._id);
    452             // The badge is aria-hidden because we don't want it to appear in the page's navigation
    453             // flow. Instead, we use the badge to describe the decorated element with aria-describedby.
    454             badgeElement.setAttribute('aria-hidden', 'true');
    455             badgeElement.classList.add(BADGE_CONTENT_CLASS);
     463            badgeElement.classList.add(contentClass);
     464            badgeElement.textContent = this._stringifyContent();
    456465            if (this._animationMode === 'NoopAnimations') {
    457466                badgeElement.classList.add('_mat-animation-noopable');
     467            }
     468            if (this.description) {
     469                badgeElement.setAttribute('aria-label', this.description);
    458470            }
    459471            this._elementRef.nativeElement.appendChild(badgeElement);
     
    471483            return badgeElement;
    472484        };
    473         /** Update the text content of the badge element in the DOM, creating the element if necessary. */
    474         MatBadge.prototype._updateRenderedContent = function (newContent) {
    475             var newContentNormalized = ("" + (newContent !== null && newContent !== void 0 ? newContent : '')).trim();
    476             // Don't create the badge element if the directive isn't initialized because we want to
    477             // append the badge element to the *end* of the host element's content for backwards
    478             // compatibility.
    479             if (this._isInitialized && newContentNormalized && !this._badgeElement) {
    480                 this._badgeElement = this._createBadgeElement();
    481             }
    482             if (this._badgeElement) {
    483                 this._badgeElement.textContent = newContentNormalized;
    484             }
    485             this._content = newContentNormalized;
    486         };
    487         /** Updates the host element's aria description via AriaDescriber. */
    488         MatBadge.prototype._updateHostAriaDescription = function (newDescription) {
    489             this._ariaDescriber.removeDescription(this._elementRef.nativeElement, this.description);
     485        /** Sets the aria-label property on the element */
     486        MatBadge.prototype._updateHostAriaDescription = function (newDescription, oldDescription) {
     487            // ensure content available before setting label
     488            var content = this._updateTextContent();
     489            if (oldDescription) {
     490                this._ariaDescriber.removeDescription(content, oldDescription);
     491            }
    490492            if (newDescription) {
    491                 this._ariaDescriber.describe(this._elementRef.nativeElement, newDescription);
    492             }
    493             this._description = newDescription;
     493                this._ariaDescriber.describe(content, newDescription);
     494            }
    494495        };
    495496        /** Adds css theme class given the color to the component host */
    496497        MatBadge.prototype._setColor = function (colorPalette) {
    497             var classList = this._elementRef.nativeElement.classList;
    498             classList.remove("mat-badge-" + this._color);
    499             if (colorPalette) {
    500                 classList.add("mat-badge-" + colorPalette);
     498            if (colorPalette !== this._color) {
     499                var classList = this._elementRef.nativeElement.classList;
     500                if (this._color) {
     501                    classList.remove("mat-badge-" + this._color);
     502                }
     503                if (colorPalette) {
     504                    classList.add("mat-badge-" + colorPalette);
     505                }
    501506            }
    502507        };
    503508        /** Clears any existing badges that might be left over from server-side rendering. */
    504         MatBadge.prototype._clearExistingBadges = function () {
    505             var e_1, _a;
    506             // Only check direct children of this host element in order to avoid deleting
    507             // any badges that might exist in descendant elements.
    508             var badges = this._elementRef.nativeElement.querySelectorAll(":scope > ." + BADGE_CONTENT_CLASS);
    509             try {
    510                 for (var _b = __values(Array.from(badges)), _c = _b.next(); !_c.done; _c = _b.next()) {
    511                     var badgeElement = _c.value;
    512                     if (badgeElement !== this._badgeElement) {
    513                         badgeElement.remove();
    514                     }
    515                 }
    516             }
    517             catch (e_1_1) { e_1 = { error: e_1_1 }; }
    518             finally {
    519                 try {
    520                     if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
    521                 }
    522                 finally { if (e_1) throw e_1.error; }
    523             }
     509        MatBadge.prototype._clearExistingBadges = function (cssClass) {
     510            var element = this._elementRef.nativeElement;
     511            var childCount = element.children.length;
     512            // Use a reverse while, because we'll be removing elements from the list as we're iterating.
     513            while (childCount--) {
     514                var currentChild = element.children[childCount];
     515                if (currentChild.classList.contains(cssClass)) {
     516                    element.removeChild(currentChild);
     517                }
     518            }
     519        };
     520        /** Gets the string representation of the badge content. */
     521        MatBadge.prototype._stringifyContent = function () {
     522            // Convert null and undefined to an empty string which is consistent
     523            // with how Angular handles them in inside template interpolations.
     524            var content = this.content;
     525            return content == null ? '' : "" + content;
    524526        };
    525527        return MatBadge;
     
    539541                        '[class.mat-badge-medium]': 'size === "medium"',
    540542                        '[class.mat-badge-large]': 'size === "large"',
    541                         '[class.mat-badge-hidden]': 'hidden || !content',
     543                        '[class.mat-badge-hidden]': 'hidden || !_hasContent',
    542544                        '[class.mat-badge-disabled]': 'disabled',
    543545                    },
Note: See TracChangeset for help on using the changeset viewer.